1mod github_context;
7mod spec;
8
9pub use github_context::GhOutput;
10pub use github_context::GhToRust;
11pub use github_context::RustToGh;
12
13use self::steps::ado::AdoRuntimeVar;
14use self::steps::ado::AdoStepServices;
15use self::steps::github::GhStepBuilder;
16use self::steps::rust::RustRuntimeServices;
17use self::user_facing::ClaimedGhParam;
18use self::user_facing::GhPermission;
19use self::user_facing::GhPermissionValue;
20use crate::node::github_context::GhContextVarReader;
21use github_context::state::Root;
22use serde::Deserialize;
23use serde::Serialize;
24use serde::de::DeserializeOwned;
25use std::cell::RefCell;
26use std::collections::BTreeMap;
27use std::path::PathBuf;
28use std::rc::Rc;
29use user_facing::GhParam;
30
31pub mod user_facing {
34 pub use super::ClaimVar;
35 pub use super::ClaimedReadVar;
36 pub use super::ClaimedWriteVar;
37 pub use super::FlowArch;
38 pub use super::FlowBackend;
39 pub use super::FlowNode;
40 pub use super::FlowPlatform;
41 pub use super::FlowPlatformKind;
42 pub use super::GhUserSecretVar;
43 pub use super::ImportCtx;
44 pub use super::IntoRequest;
45 pub use super::NodeCtx;
46 pub use super::ReadVar;
47 pub use super::SideEffect;
48 pub use super::SimpleFlowNode;
49 pub use super::StepCtx;
50 pub use super::VarClaimed;
51 pub use super::VarEqBacking;
52 pub use super::VarNotClaimed;
53 pub use super::WriteVar;
54 pub use super::steps::ado::AdoResourcesRepositoryId;
55 pub use super::steps::ado::AdoRuntimeVar;
56 pub use super::steps::ado::AdoStepServices;
57 pub use super::steps::github::ClaimedGhParam;
58 pub use super::steps::github::GhParam;
59 pub use super::steps::github::GhPermission;
60 pub use super::steps::github::GhPermissionValue;
61 pub use super::steps::rust::RustRuntimeServices;
62 pub use crate::flowey_request;
63 pub use crate::new_flow_node;
64 pub use crate::new_simple_flow_node;
65 pub use crate::node::FlowPlatformLinuxDistro;
66 pub use crate::pipeline::Artifact;
67
68 pub fn same_across_all_reqs<T: PartialEq>(
100 req_name: &str,
101 var: &mut Option<T>,
102 new: T,
103 ) -> anyhow::Result<()> {
104 match (var.as_ref(), new) {
105 (None, v) => *var = Some(v),
106 (Some(old), new) => {
107 if *old != new {
108 anyhow::bail!("`{}` must be consistent across requests", req_name);
109 }
110 }
111 }
112
113 Ok(())
114 }
115
116 pub fn same_across_all_reqs_backing_var<V: VarEqBacking>(
120 req_name: &str,
121 var: &mut Option<V>,
122 new: V,
123 ) -> anyhow::Result<()> {
124 match (var.as_ref(), new) {
125 (None, v) => *var = Some(v),
126 (Some(old), new) => {
127 if !old.eq(&new) {
128 anyhow::bail!("`{}` must be consistent across requests", req_name);
129 }
130 }
131 }
132
133 Ok(())
134 }
135
136 #[macro_export]
140 macro_rules! match_arch {
141 ($host_arch:expr, $match_arch:pat, $expr:expr) => {
142 if matches!($host_arch, $match_arch) {
143 $expr
144 } else {
145 anyhow::bail!("Linux distro not supported on host arch {}", $host_arch);
146 }
147 };
148 }
149}
150
151pub trait VarEqBacking {
175 fn eq(&self, other: &Self) -> bool;
177}
178
179impl<T> VarEqBacking for WriteVar<T>
180where
181 T: Serialize + DeserializeOwned,
182{
183 fn eq(&self, other: &Self) -> bool {
184 self.backing_var == other.backing_var
185 }
186}
187
188impl<T> VarEqBacking for ReadVar<T>
189where
190 T: Serialize + DeserializeOwned + PartialEq + Eq + Clone,
191{
192 fn eq(&self, other: &Self) -> bool {
193 self.backing_var == other.backing_var
194 }
195}
196
197impl<T, U> VarEqBacking for (T, U)
199where
200 T: VarEqBacking,
201 U: VarEqBacking,
202{
203 fn eq(&self, other: &Self) -> bool {
204 (self.0.eq(&other.0)) && (self.1.eq(&other.1))
205 }
206}
207
208pub type SideEffect = ();
215
216#[derive(Clone, Debug, Serialize, Deserialize)]
219pub enum VarNotClaimed {}
220
221#[derive(Clone, Debug, Serialize, Deserialize)]
224pub enum VarClaimed {}
225
226#[derive(Debug, Serialize, Deserialize)]
246pub struct WriteVar<T: Serialize + DeserializeOwned, C = VarNotClaimed> {
247 backing_var: String,
248 is_side_effect: bool,
251
252 #[serde(skip)]
253 _kind: core::marker::PhantomData<(T, C)>,
254}
255
256pub type ClaimedWriteVar<T> = WriteVar<T, VarClaimed>;
259
260impl<T: Serialize + DeserializeOwned> WriteVar<T, VarNotClaimed> {
261 fn into_claimed(self) -> WriteVar<T, VarClaimed> {
263 let Self {
264 backing_var,
265 is_side_effect,
266 _kind,
267 } = self;
268
269 WriteVar {
270 backing_var,
271 is_side_effect,
272 _kind: std::marker::PhantomData,
273 }
274 }
275
276 #[track_caller]
278 pub fn write_static(self, ctx: &mut NodeCtx<'_>, val: T)
279 where
280 T: 'static,
281 {
282 let val = ReadVar::from_static(val);
283 val.write_into(ctx, self, |v| v);
284 }
285
286 pub(crate) fn into_json(self) -> WriteVar<serde_json::Value> {
287 WriteVar {
288 backing_var: self.backing_var,
289 is_side_effect: self.is_side_effect,
290 _kind: std::marker::PhantomData,
291 }
292 }
293}
294
295impl WriteVar<SideEffect, VarNotClaimed> {
296 pub fn discard_result<T: Serialize + DeserializeOwned>(self) -> WriteVar<T> {
301 WriteVar {
302 backing_var: self.backing_var,
303 is_side_effect: true,
304 _kind: std::marker::PhantomData,
305 }
306 }
307}
308
309pub trait ClaimVar {
317 type Claimed;
319 fn claim(self, ctx: &mut StepCtx<'_>) -> Self::Claimed;
321}
322
323pub trait ReadVarValue {
329 type Value;
331 fn read_value(self, rt: &mut RustRuntimeServices<'_>) -> Self::Value;
333}
334
335impl<T: Serialize + DeserializeOwned> ClaimVar for ReadVar<T> {
336 type Claimed = ClaimedReadVar<T>;
337
338 fn claim(self, ctx: &mut StepCtx<'_>) -> ClaimedReadVar<T> {
339 if let ReadVarBacking::RuntimeVar {
340 var,
341 is_side_effect: _,
342 } = &self.backing_var
343 {
344 ctx.backend.borrow_mut().on_claimed_runtime_var(var, true);
345 }
346 self.into_claimed()
347 }
348}
349
350impl<T: Serialize + DeserializeOwned> ClaimVar for WriteVar<T> {
351 type Claimed = ClaimedWriteVar<T>;
352
353 fn claim(self, ctx: &mut StepCtx<'_>) -> ClaimedWriteVar<T> {
354 ctx.backend
355 .borrow_mut()
356 .on_claimed_runtime_var(&self.backing_var, false);
357 self.into_claimed()
358 }
359}
360
361impl<T: Serialize + DeserializeOwned> ReadVarValue for ClaimedReadVar<T> {
362 type Value = T;
363
364 fn read_value(self, rt: &mut RustRuntimeServices<'_>) -> Self::Value {
365 match self.backing_var {
366 ReadVarBacking::RuntimeVar {
367 var,
368 is_side_effect,
369 } => {
370 let data = rt.get_var(&var, is_side_effect);
372 if is_side_effect {
373 serde_json::from_slice(b"null").expect("should be deserializing into ()")
377 } else {
378 serde_json::from_slice(&data).expect("improve this error path")
380 }
381 }
382 ReadVarBacking::Inline(val) => val,
383 }
384 }
385}
386
387impl<T: ClaimVar> ClaimVar for Vec<T> {
388 type Claimed = Vec<T::Claimed>;
389
390 fn claim(self, ctx: &mut StepCtx<'_>) -> Vec<T::Claimed> {
391 self.into_iter().map(|v| v.claim(ctx)).collect()
392 }
393}
394
395impl<T: ReadVarValue> ReadVarValue for Vec<T> {
396 type Value = Vec<T::Value>;
397
398 fn read_value(self, rt: &mut RustRuntimeServices<'_>) -> Self::Value {
399 self.into_iter().map(|v| v.read_value(rt)).collect()
400 }
401}
402
403impl<T: ClaimVar> ClaimVar for Option<T> {
404 type Claimed = Option<T::Claimed>;
405
406 fn claim(self, ctx: &mut StepCtx<'_>) -> Option<T::Claimed> {
407 self.map(|x| x.claim(ctx))
408 }
409}
410
411impl<T: ReadVarValue> ReadVarValue for Option<T> {
412 type Value = Option<T::Value>;
413
414 fn read_value(self, rt: &mut RustRuntimeServices<'_>) -> Self::Value {
415 self.map(|x| x.read_value(rt))
416 }
417}
418
419impl<U: Ord, T: ClaimVar> ClaimVar for BTreeMap<U, T> {
420 type Claimed = BTreeMap<U, T::Claimed>;
421
422 fn claim(self, ctx: &mut StepCtx<'_>) -> BTreeMap<U, T::Claimed> {
423 self.into_iter().map(|(k, v)| (k, v.claim(ctx))).collect()
424 }
425}
426
427impl<U: Ord, T: ReadVarValue> ReadVarValue for BTreeMap<U, T> {
428 type Value = BTreeMap<U, T::Value>;
429
430 fn read_value(self, rt: &mut RustRuntimeServices<'_>) -> Self::Value {
431 self.into_iter()
432 .map(|(k, v)| (k, v.read_value(rt)))
433 .collect()
434 }
435}
436
437macro_rules! impl_tuple_claim {
438 ($($T:tt)*) => {
439 impl<$($T,)*> $crate::node::ClaimVar for ($($T,)*)
440 where
441 $($T: $crate::node::ClaimVar,)*
442 {
443 type Claimed = ($($T::Claimed,)*);
444
445 #[expect(non_snake_case)]
446 fn claim(self, ctx: &mut $crate::node::StepCtx<'_>) -> Self::Claimed {
447 let ($($T,)*) = self;
448 ($($T.claim(ctx),)*)
449 }
450 }
451
452 impl<$($T,)*> $crate::node::ReadVarValue for ($($T,)*)
453 where
454 $($T: $crate::node::ReadVarValue,)*
455 {
456 type Value = ($($T::Value,)*);
457
458 #[expect(non_snake_case)]
459 fn read_value(self, rt: &mut $crate::node::RustRuntimeServices<'_>) -> Self::Value {
460 let ($($T,)*) = self;
461 ($($T.read_value(rt),)*)
462 }
463 }
464 };
465}
466
467impl_tuple_claim!(A B C D E F G H I J);
468impl_tuple_claim!(A B C D E F G H I);
469impl_tuple_claim!(A B C D E F G H);
470impl_tuple_claim!(A B C D E F G);
471impl_tuple_claim!(A B C D E F);
472impl_tuple_claim!(A B C D E);
473impl_tuple_claim!(A B C D);
474impl_tuple_claim!(A B C);
475impl_tuple_claim!(A B);
476impl_tuple_claim!(A);
477
478impl ClaimVar for () {
479 type Claimed = ();
480
481 fn claim(self, _ctx: &mut StepCtx<'_>) -> Self::Claimed {}
482}
483
484impl ReadVarValue for () {
485 type Value = ();
486
487 fn read_value(self, _rt: &mut RustRuntimeServices<'_>) -> Self::Value {}
488}
489
490#[derive(Serialize, Deserialize, Clone)]
495pub struct GhUserSecretVar(pub(crate) String);
496
497#[derive(Debug, Serialize, Deserialize)]
516pub struct ReadVar<T, C = VarNotClaimed> {
517 backing_var: ReadVarBacking<T>,
518 #[serde(skip)]
519 _kind: std::marker::PhantomData<C>,
520}
521
522pub type ClaimedReadVar<T> = ReadVar<T, VarClaimed>;
525
526impl<T: Serialize + DeserializeOwned, C> Clone for ReadVar<T, C> {
528 fn clone(&self) -> Self {
529 ReadVar {
530 backing_var: self.backing_var.clone(),
531 _kind: std::marker::PhantomData,
532 }
533 }
534}
535
536#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
537enum ReadVarBacking<T> {
538 RuntimeVar {
539 var: String,
540 is_side_effect: bool,
547 },
548 Inline(T),
549}
550
551impl<T: Serialize + DeserializeOwned> Clone for ReadVarBacking<T> {
553 fn clone(&self) -> Self {
554 match self {
555 Self::RuntimeVar {
556 var,
557 is_side_effect,
558 } => Self::RuntimeVar {
559 var: var.clone(),
560 is_side_effect: *is_side_effect,
561 },
562 Self::Inline(v) => {
563 Self::Inline(serde_json::from_value(serde_json::to_value(v).unwrap()).unwrap())
564 }
565 }
566 }
567}
568
569impl<T: Serialize + DeserializeOwned> ReadVar<T> {
570 fn into_claimed(self) -> ReadVar<T, VarClaimed> {
572 let Self { backing_var, _kind } = self;
573
574 ReadVar {
575 backing_var,
576 _kind: std::marker::PhantomData,
577 }
578 }
579
580 #[must_use]
589 pub fn into_side_effect(self) -> ReadVar<SideEffect> {
590 ReadVar {
591 backing_var: match self.backing_var {
592 ReadVarBacking::RuntimeVar {
593 var,
594 is_side_effect: _,
595 } => ReadVarBacking::RuntimeVar {
596 var,
597 is_side_effect: true,
598 },
599 ReadVarBacking::Inline(_) => ReadVarBacking::Inline(()),
600 },
601 _kind: std::marker::PhantomData,
602 }
603 }
604
605 #[track_caller]
608 #[must_use]
609 pub fn map<F, U>(&self, ctx: &mut NodeCtx<'_>, f: F) -> ReadVar<U>
610 where
611 T: 'static,
612 U: Serialize + DeserializeOwned + 'static,
613 F: FnOnce(T) -> U + 'static,
614 {
615 let (read_from, write_into) = ctx.new_var();
616 self.write_into(ctx, write_into, f);
617 read_from
618 }
619
620 #[track_caller]
623 pub fn write_into<F, U>(&self, ctx: &mut NodeCtx<'_>, write_into: WriteVar<U>, f: F)
624 where
625 T: 'static,
626 U: Serialize + DeserializeOwned + 'static,
627 F: FnOnce(T) -> U + 'static,
628 {
629 let this = self.clone();
630 ctx.emit_minor_rust_step("🌼 write_into Var", move |ctx| {
631 let this = this.claim(ctx);
632 let write_into = write_into.claim(ctx);
633 move |rt| {
634 let this = rt.read(this);
635 rt.write(write_into, &f(this));
636 }
637 });
638 }
639
640 #[track_caller]
643 #[must_use]
644 pub fn zip<U>(&self, ctx: &mut NodeCtx<'_>, other: ReadVar<U>) -> ReadVar<(T, U)>
645 where
646 T: 'static,
647 U: Serialize + DeserializeOwned + 'static,
648 {
649 let (read_from, write_into) = ctx.new_var();
650 let this = self.clone();
651 ctx.emit_minor_rust_step("🌼 Zip Vars", move |ctx| {
652 let this = this.claim(ctx);
653 let other = other.claim(ctx);
654 let write_into = write_into.claim(ctx);
655 move |rt| {
656 let this = rt.read(this);
657 let other = rt.read(other);
658 rt.write(write_into, &(this, other));
659 }
660 });
661 read_from
662 }
663
664 #[track_caller]
669 #[must_use]
670 pub fn from_static(val: T) -> ReadVar<T>
671 where
672 T: 'static,
673 {
674 ReadVar {
675 backing_var: ReadVarBacking::Inline(val),
676 _kind: std::marker::PhantomData,
677 }
678 }
679
680 pub fn get_static(&self) -> Option<T> {
689 match self.clone().backing_var {
690 ReadVarBacking::Inline(v) => Some(v),
691 _ => None,
692 }
693 }
694
695 #[track_caller]
697 #[must_use]
698 pub fn transpose_vec(ctx: &mut NodeCtx<'_>, vec: Vec<ReadVar<T>>) -> ReadVar<Vec<T>>
699 where
700 T: 'static,
701 {
702 let (read_from, write_into) = ctx.new_var();
703 ctx.emit_minor_rust_step("🌼 Transpose Vec<ReadVar<T>>", move |ctx| {
704 let vec = vec.claim(ctx);
705 let write_into = write_into.claim(ctx);
706 move |rt| {
707 let mut v = Vec::new();
708 for var in vec {
709 v.push(rt.read(var));
710 }
711 rt.write(write_into, &v);
712 }
713 });
714 read_from
715 }
716
717 #[must_use]
733 pub fn depending_on<U>(&self, ctx: &mut NodeCtx<'_>, other: &ReadVar<U>) -> Self
734 where
735 T: 'static,
736 U: Serialize + DeserializeOwned + 'static,
737 {
738 ctx.emit_minor_rust_stepv("🌼 Add dependency", |ctx| {
741 let this = self.clone().claim(ctx);
742 other.clone().claim(ctx);
743 move |rt| rt.read(this)
744 })
745 }
746
747 pub fn claim_unused(self, ctx: &mut NodeCtx<'_>) {
750 match self.backing_var {
751 ReadVarBacking::RuntimeVar {
752 var,
753 is_side_effect: _,
754 } => ctx.backend.borrow_mut().on_unused_read_var(&var),
755 ReadVarBacking::Inline(_) => {}
756 }
757 }
758
759 pub(crate) fn into_json(self) -> ReadVar<serde_json::Value> {
760 match self.backing_var {
761 ReadVarBacking::RuntimeVar {
762 var,
763 is_side_effect,
764 } => ReadVar {
765 backing_var: ReadVarBacking::RuntimeVar {
766 var,
767 is_side_effect,
768 },
769 _kind: std::marker::PhantomData,
770 },
771 ReadVarBacking::Inline(v) => ReadVar {
772 backing_var: ReadVarBacking::Inline(serde_json::to_value(v).unwrap()),
773 _kind: std::marker::PhantomData,
774 },
775 }
776 }
777}
778
779#[must_use]
785pub fn thin_air_read_runtime_var<T>(backing_var: String) -> ReadVar<T>
786where
787 T: Serialize + DeserializeOwned,
788{
789 ReadVar {
790 backing_var: ReadVarBacking::RuntimeVar {
791 var: backing_var,
792 is_side_effect: false,
793 },
794 _kind: std::marker::PhantomData,
795 }
796}
797
798#[must_use]
804pub fn thin_air_write_runtime_var<T>(backing_var: String) -> WriteVar<T>
805where
806 T: Serialize + DeserializeOwned,
807{
808 WriteVar {
809 backing_var,
810 is_side_effect: false,
811 _kind: std::marker::PhantomData,
812 }
813}
814
815pub fn read_var_internals<T: Serialize + DeserializeOwned, C>(
821 var: &ReadVar<T, C>,
822) -> (Option<String>, bool) {
823 match var.backing_var {
824 ReadVarBacking::RuntimeVar {
825 var: ref s,
826 is_side_effect,
827 } => (Some(s.clone()), is_side_effect),
828 ReadVarBacking::Inline(_) => (None, false),
829 }
830}
831
832pub trait ImportCtxBackend {
833 fn on_possible_dep(&mut self, node_handle: NodeHandle);
834}
835
836pub struct ImportCtx<'a> {
838 backend: &'a mut dyn ImportCtxBackend,
839}
840
841impl ImportCtx<'_> {
842 pub fn import<N: FlowNodeBase + 'static>(&mut self) {
844 self.backend.on_possible_dep(NodeHandle::from_type::<N>())
845 }
846}
847
848pub fn new_import_ctx(backend: &mut dyn ImportCtxBackend) -> ImportCtx<'_> {
849 ImportCtx { backend }
850}
851
852#[derive(Debug)]
853pub enum CtxAnchor {
854 PostJob,
855}
856
857pub trait NodeCtxBackend {
858 fn current_node(&self) -> NodeHandle;
860
861 fn on_new_var(&mut self) -> String;
866
867 fn on_claimed_runtime_var(&mut self, var: &str, is_read: bool);
869
870 fn on_unused_read_var(&mut self, var: &str);
872
873 fn on_request(&mut self, node_handle: NodeHandle, req: anyhow::Result<Box<[u8]>>);
881
882 fn on_emit_rust_step(
883 &mut self,
884 label: &str,
885 can_merge: bool,
886 code: Box<dyn for<'a> FnOnce(&'a mut RustRuntimeServices<'_>) -> anyhow::Result<()>>,
887 );
888
889 fn on_emit_ado_step(
890 &mut self,
891 label: &str,
892 yaml_snippet: Box<dyn for<'a> FnOnce(&'a mut AdoStepServices<'_>) -> String>,
893 inline_script: Option<
894 Box<dyn for<'a> FnOnce(&'a mut RustRuntimeServices<'_>) -> anyhow::Result<()>>,
895 >,
896 condvar: Option<String>,
897 );
898
899 fn on_emit_gh_step(
900 &mut self,
901 label: &str,
902 uses: &str,
903 with: BTreeMap<String, ClaimedGhParam>,
904 condvar: Option<String>,
905 outputs: BTreeMap<String, Vec<GhOutput>>,
906 permissions: BTreeMap<GhPermission, GhPermissionValue>,
907 gh_to_rust: Vec<GhToRust>,
908 rust_to_gh: Vec<RustToGh>,
909 );
910
911 fn on_emit_side_effect_step(&mut self);
912
913 fn backend(&mut self) -> FlowBackend;
914 fn platform(&mut self) -> FlowPlatform;
915 fn arch(&mut self) -> FlowArch;
916
917 fn persistent_dir_path_var(&mut self) -> Option<String>;
921}
922
923pub fn new_node_ctx(backend: &mut dyn NodeCtxBackend) -> NodeCtx<'_> {
924 NodeCtx {
925 backend: Rc::new(RefCell::new(backend)),
926 }
927}
928
929#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
931pub enum FlowBackend {
932 Local,
934 Ado,
936 Github,
938}
939
940#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
942pub enum FlowPlatformKind {
943 Windows,
944 Unix,
945}
946
947#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
949pub enum FlowPlatformLinuxDistro {
950 Fedora,
952 Ubuntu,
954 Arch,
956 Nix,
958 Unknown,
960}
961
962#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
964#[non_exhaustive]
965pub enum FlowPlatform {
966 Windows,
968 Linux(FlowPlatformLinuxDistro),
970 MacOs,
972}
973
974impl FlowPlatform {
975 pub fn kind(&self) -> FlowPlatformKind {
976 match self {
977 Self::Windows => FlowPlatformKind::Windows,
978 Self::Linux(_) | Self::MacOs => FlowPlatformKind::Unix,
979 }
980 }
981
982 fn as_str(&self) -> &'static str {
983 match self {
984 Self::Windows => "windows",
985 Self::Linux(_) => "linux",
986 Self::MacOs => "macos",
987 }
988 }
989
990 pub fn exe_suffix(&self) -> &'static str {
992 if self == &Self::Windows { ".exe" } else { "" }
993 }
994
995 pub fn binary(&self, name: &str) -> String {
997 format!("{}{}", name, self.exe_suffix())
998 }
999}
1000
1001impl std::fmt::Display for FlowPlatform {
1002 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1003 f.pad(self.as_str())
1004 }
1005}
1006
1007#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1009#[non_exhaustive]
1010pub enum FlowArch {
1011 X86_64,
1012 Aarch64,
1013}
1014
1015impl FlowArch {
1016 fn as_str(&self) -> &'static str {
1017 match self {
1018 Self::X86_64 => "x86_64",
1019 Self::Aarch64 => "aarch64",
1020 }
1021 }
1022}
1023
1024impl std::fmt::Display for FlowArch {
1025 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1026 f.pad(self.as_str())
1027 }
1028}
1029
1030pub struct StepCtx<'a> {
1032 backend: Rc<RefCell<&'a mut dyn NodeCtxBackend>>,
1033}
1034
1035impl StepCtx<'_> {
1036 pub fn backend(&self) -> FlowBackend {
1039 self.backend.borrow_mut().backend()
1040 }
1041
1042 pub fn platform(&self) -> FlowPlatform {
1045 self.backend.borrow_mut().platform()
1046 }
1047}
1048
1049const NO_ADO_INLINE_SCRIPT: Option<
1050 for<'a> fn(&'a mut RustRuntimeServices<'_>) -> anyhow::Result<()>,
1051> = None;
1052
1053pub struct NodeCtx<'a> {
1055 backend: Rc<RefCell<&'a mut dyn NodeCtxBackend>>,
1056}
1057
1058impl<'ctx> NodeCtx<'ctx> {
1059 pub fn emit_rust_step<F, G>(&mut self, label: impl AsRef<str>, code: F) -> ReadVar<SideEffect>
1065 where
1066 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> G,
1067 G: for<'a> FnOnce(&'a mut RustRuntimeServices<'_>) -> anyhow::Result<()> + 'static,
1068 {
1069 self.emit_rust_step_inner(label.as_ref(), false, code)
1070 }
1071
1072 pub fn emit_minor_rust_step<F, G>(
1082 &mut self,
1083 label: impl AsRef<str>,
1084 code: F,
1085 ) -> ReadVar<SideEffect>
1086 where
1087 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> G,
1088 G: for<'a> FnOnce(&'a mut RustRuntimeServices<'_>) + 'static,
1089 {
1090 self.emit_rust_step_inner(label.as_ref(), true, |ctx| {
1091 let f = code(ctx);
1092 |rt| {
1093 f(rt);
1094 Ok(())
1095 }
1096 })
1097 }
1098
1099 #[must_use]
1120 #[track_caller]
1121 pub fn emit_rust_stepv<T, F, G>(&mut self, label: impl AsRef<str>, code: F) -> ReadVar<T>
1122 where
1123 T: Serialize + DeserializeOwned + 'static,
1124 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> G,
1125 G: for<'a> FnOnce(&'a mut RustRuntimeServices<'_>) -> anyhow::Result<T> + 'static,
1126 {
1127 self.emit_rust_stepv_inner(label.as_ref(), false, code)
1128 }
1129
1130 #[must_use]
1154 #[track_caller]
1155 pub fn emit_minor_rust_stepv<T, F, G>(&mut self, label: impl AsRef<str>, code: F) -> ReadVar<T>
1156 where
1157 T: Serialize + DeserializeOwned + 'static,
1158 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> G,
1159 G: for<'a> FnOnce(&'a mut RustRuntimeServices<'_>) -> T + 'static,
1160 {
1161 self.emit_rust_stepv_inner(label.as_ref(), true, |ctx| {
1162 let f = code(ctx);
1163 |rt| Ok(f(rt))
1164 })
1165 }
1166
1167 fn emit_rust_step_inner<F, G>(
1168 &mut self,
1169 label: &str,
1170 can_merge: bool,
1171 code: F,
1172 ) -> ReadVar<SideEffect>
1173 where
1174 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> G,
1175 G: for<'a> FnOnce(&'a mut RustRuntimeServices<'_>) -> anyhow::Result<()> + 'static,
1176 {
1177 let (read, write) = self.new_prefixed_var("auto_se");
1178
1179 let ctx = &mut StepCtx {
1180 backend: self.backend.clone(),
1181 };
1182 write.claim(ctx);
1183
1184 let code = code(ctx);
1185 self.backend
1186 .borrow_mut()
1187 .on_emit_rust_step(label.as_ref(), can_merge, Box::new(code));
1188 read
1189 }
1190
1191 #[must_use]
1192 #[track_caller]
1193 fn emit_rust_stepv_inner<T, F, G>(
1194 &mut self,
1195 label: impl AsRef<str>,
1196 can_merge: bool,
1197 code: F,
1198 ) -> ReadVar<T>
1199 where
1200 T: Serialize + DeserializeOwned + 'static,
1201 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> G,
1202 G: for<'a> FnOnce(&'a mut RustRuntimeServices<'_>) -> anyhow::Result<T> + 'static,
1203 {
1204 let (read, write) = self.new_var();
1205
1206 let ctx = &mut StepCtx {
1207 backend: self.backend.clone(),
1208 };
1209 let write = write.claim(ctx);
1210
1211 let code = code(ctx);
1212 self.backend.borrow_mut().on_emit_rust_step(
1213 label.as_ref(),
1214 can_merge,
1215 Box::new(|rt| {
1216 let val = code(rt)?;
1217 rt.write(write, &val);
1218 Ok(())
1219 }),
1220 );
1221 read
1222 }
1223
1224 #[track_caller]
1226 #[must_use]
1227 pub fn get_ado_variable(&mut self, ado_var: AdoRuntimeVar) -> ReadVar<String> {
1228 let (var, write_var) = self.new_var();
1229 self.emit_ado_step(format!("🌼 read {}", ado_var.as_raw_var_name()), |ctx| {
1230 let write_var = write_var.claim(ctx);
1231 |rt| {
1232 rt.set_var(write_var, ado_var);
1233 "".into()
1234 }
1235 });
1236 var
1237 }
1238
1239 pub fn emit_ado_step<F, G>(&mut self, display_name: impl AsRef<str>, yaml_snippet: F)
1241 where
1242 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> G,
1243 G: for<'a> FnOnce(&'a mut AdoStepServices<'_>) -> String + 'static,
1244 {
1245 self.emit_ado_step_inner(display_name, None, |ctx| {
1246 (yaml_snippet(ctx), NO_ADO_INLINE_SCRIPT)
1247 })
1248 }
1249
1250 pub fn emit_ado_step_with_condition<F, G>(
1253 &mut self,
1254 display_name: impl AsRef<str>,
1255 cond: ReadVar<bool>,
1256 yaml_snippet: F,
1257 ) where
1258 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> G,
1259 G: for<'a> FnOnce(&'a mut AdoStepServices<'_>) -> String + 'static,
1260 {
1261 self.emit_ado_step_inner(display_name, Some(cond), |ctx| {
1262 (yaml_snippet(ctx), NO_ADO_INLINE_SCRIPT)
1263 })
1264 }
1265
1266 pub fn emit_ado_step_with_condition_optional<F, G>(
1269 &mut self,
1270 display_name: impl AsRef<str>,
1271 cond: Option<ReadVar<bool>>,
1272 yaml_snippet: F,
1273 ) where
1274 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> G,
1275 G: for<'a> FnOnce(&'a mut AdoStepServices<'_>) -> String + 'static,
1276 {
1277 self.emit_ado_step_inner(display_name, cond, |ctx| {
1278 (yaml_snippet(ctx), NO_ADO_INLINE_SCRIPT)
1279 })
1280 }
1281
1282 pub fn emit_ado_step_with_inline_script<F, G, H>(
1311 &mut self,
1312 display_name: impl AsRef<str>,
1313 yaml_snippet: F,
1314 ) where
1315 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> (G, H),
1316 G: for<'a> FnOnce(&'a mut AdoStepServices<'_>) -> String + 'static,
1317 H: for<'a> FnOnce(&'a mut RustRuntimeServices<'_>) -> anyhow::Result<()> + 'static,
1318 {
1319 self.emit_ado_step_inner(display_name, None, |ctx| {
1320 let (f, g) = yaml_snippet(ctx);
1321 (f, Some(g))
1322 })
1323 }
1324
1325 fn emit_ado_step_inner<F, G, H>(
1326 &mut self,
1327 display_name: impl AsRef<str>,
1328 cond: Option<ReadVar<bool>>,
1329 yaml_snippet: F,
1330 ) where
1331 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> (G, Option<H>),
1332 G: for<'a> FnOnce(&'a mut AdoStepServices<'_>) -> String + 'static,
1333 H: for<'a> FnOnce(&'a mut RustRuntimeServices<'_>) -> anyhow::Result<()> + 'static,
1334 {
1335 let condvar = match cond.map(|c| c.backing_var) {
1336 Some(ReadVarBacking::Inline(cond)) => {
1338 if !cond {
1339 return;
1340 } else {
1341 None
1342 }
1343 }
1344 Some(ReadVarBacking::RuntimeVar {
1345 var,
1346 is_side_effect,
1347 }) => {
1348 assert!(!is_side_effect);
1349 self.backend.borrow_mut().on_claimed_runtime_var(&var, true);
1350 Some(var)
1351 }
1352 None => None,
1353 };
1354
1355 let (yaml_snippet, inline_script) = yaml_snippet(&mut StepCtx {
1356 backend: self.backend.clone(),
1357 });
1358 self.backend.borrow_mut().on_emit_ado_step(
1359 display_name.as_ref(),
1360 Box::new(yaml_snippet),
1361 if let Some(inline_script) = inline_script {
1362 Some(Box::new(inline_script))
1363 } else {
1364 None
1365 },
1366 condvar,
1367 );
1368 }
1369
1370 #[track_caller]
1372 #[must_use]
1373 pub fn get_gh_context_var(&mut self) -> GhContextVarReader<'ctx, Root> {
1374 GhContextVarReader {
1375 ctx: NodeCtx {
1376 backend: self.backend.clone(),
1377 },
1378 _state: std::marker::PhantomData,
1379 }
1380 }
1381
1382 pub fn emit_gh_step(
1384 &mut self,
1385 display_name: impl AsRef<str>,
1386 uses: impl AsRef<str>,
1387 ) -> GhStepBuilder {
1388 GhStepBuilder::new(display_name, uses)
1389 }
1390
1391 fn emit_gh_step_inner(
1392 &mut self,
1393 display_name: impl AsRef<str>,
1394 cond: Option<ReadVar<bool>>,
1395 uses: impl AsRef<str>,
1396 with: Option<BTreeMap<String, GhParam>>,
1397 outputs: BTreeMap<String, Vec<WriteVar<String>>>,
1398 run_after: Vec<ReadVar<SideEffect>>,
1399 permissions: BTreeMap<GhPermission, GhPermissionValue>,
1400 ) {
1401 let condvar = match cond.map(|c| c.backing_var) {
1402 Some(ReadVarBacking::Inline(cond)) => {
1404 if !cond {
1405 return;
1406 } else {
1407 None
1408 }
1409 }
1410 Some(ReadVarBacking::RuntimeVar {
1411 var,
1412 is_side_effect,
1413 }) => {
1414 assert!(!is_side_effect);
1415 self.backend.borrow_mut().on_claimed_runtime_var(&var, true);
1416 Some(var)
1417 }
1418 None => None,
1419 };
1420
1421 let with = with
1422 .unwrap_or_default()
1423 .into_iter()
1424 .map(|(k, v)| {
1425 (
1426 k.clone(),
1427 v.claim(&mut StepCtx {
1428 backend: self.backend.clone(),
1429 }),
1430 )
1431 })
1432 .collect();
1433
1434 for var in run_after {
1435 var.claim(&mut StepCtx {
1436 backend: self.backend.clone(),
1437 });
1438 }
1439
1440 let outputvars = outputs
1441 .into_iter()
1442 .map(|(name, vars)| {
1443 (
1444 name,
1445 vars.into_iter()
1446 .map(|var| {
1447 let var = var.claim(&mut StepCtx {
1448 backend: self.backend.clone(),
1449 });
1450 GhOutput {
1451 backing_var: var.backing_var,
1452 is_secret: false,
1453 is_object: false,
1454 }
1455 })
1456 .collect(),
1457 )
1458 })
1459 .collect();
1460
1461 self.backend.borrow_mut().on_emit_gh_step(
1462 display_name.as_ref(),
1463 uses.as_ref(),
1464 with,
1465 condvar,
1466 outputvars,
1467 permissions,
1468 Vec::new(),
1469 Vec::new(),
1470 );
1471 }
1472
1473 pub fn emit_side_effect_step(
1481 &mut self,
1482 use_side_effects: impl IntoIterator<Item = ReadVar<SideEffect>>,
1483 resolve_side_effects: impl IntoIterator<Item = WriteVar<SideEffect>>,
1484 ) {
1485 let mut backend = self.backend.borrow_mut();
1486 for var in use_side_effects.into_iter() {
1487 if let ReadVarBacking::RuntimeVar {
1488 var,
1489 is_side_effect: _,
1490 } = &var.backing_var
1491 {
1492 backend.on_claimed_runtime_var(var, true);
1493 }
1494 }
1495
1496 for var in resolve_side_effects.into_iter() {
1497 backend.on_claimed_runtime_var(&var.backing_var, false);
1498 }
1499
1500 backend.on_emit_side_effect_step();
1501 }
1502
1503 pub fn backend(&self) -> FlowBackend {
1506 self.backend.borrow_mut().backend()
1507 }
1508
1509 pub fn platform(&self) -> FlowPlatform {
1512 self.backend.borrow_mut().platform()
1513 }
1514
1515 pub fn arch(&self) -> FlowArch {
1517 self.backend.borrow_mut().arch()
1518 }
1519
1520 pub fn req<R>(&mut self, req: R)
1522 where
1523 R: IntoRequest + 'static,
1524 {
1525 let mut backend = self.backend.borrow_mut();
1526 backend.on_request(
1527 NodeHandle::from_type::<R::Node>(),
1528 serde_json::to_vec(&req.into_request())
1529 .map(Into::into)
1530 .map_err(Into::into),
1531 );
1532 }
1533
1534 #[track_caller]
1537 #[must_use]
1538 pub fn reqv<T, R>(&mut self, f: impl FnOnce(WriteVar<T>) -> R) -> ReadVar<T>
1539 where
1540 T: Serialize + DeserializeOwned,
1541 R: IntoRequest + 'static,
1542 {
1543 let (read, write) = self.new_var();
1544 self.req::<R>(f(write));
1545 read
1546 }
1547
1548 pub fn requests<N>(&mut self, reqs: impl IntoIterator<Item = N::Request>)
1550 where
1551 N: FlowNodeBase + 'static,
1552 {
1553 let mut backend = self.backend.borrow_mut();
1554 for req in reqs.into_iter() {
1555 backend.on_request(
1556 NodeHandle::from_type::<N>(),
1557 serde_json::to_vec(&req).map(Into::into).map_err(Into::into),
1558 );
1559 }
1560 }
1561
1562 #[track_caller]
1565 #[must_use]
1566 pub fn new_var<T>(&self) -> (ReadVar<T>, WriteVar<T>)
1567 where
1568 T: Serialize + DeserializeOwned,
1569 {
1570 self.new_prefixed_var("")
1571 }
1572
1573 #[track_caller]
1574 #[must_use]
1575 fn new_prefixed_var<T>(&self, prefix: &'static str) -> (ReadVar<T>, WriteVar<T>)
1576 where
1577 T: Serialize + DeserializeOwned,
1578 {
1579 let caller = std::panic::Location::caller()
1581 .to_string()
1582 .replace('\\', "/");
1583
1584 let caller = caller
1600 .split_once("flowey/")
1601 .expect("due to a known limitation with flowey, all flowey code must have an ancestor dir called 'flowey/' somewhere in its full path")
1602 .1;
1603
1604 let colon = if prefix.is_empty() { "" } else { ":" };
1605 let ordinal = self.backend.borrow_mut().on_new_var();
1606 let backing_var = format!("{prefix}{colon}{ordinal}:{caller}");
1607
1608 (
1609 ReadVar {
1610 backing_var: ReadVarBacking::RuntimeVar {
1611 var: backing_var.clone(),
1612 is_side_effect: false,
1613 },
1614 _kind: std::marker::PhantomData,
1615 },
1616 WriteVar {
1617 backing_var,
1618 is_side_effect: false,
1619 _kind: std::marker::PhantomData,
1620 },
1621 )
1622 }
1623
1624 #[track_caller]
1635 #[must_use]
1636 pub fn new_post_job_side_effect(&self) -> (ReadVar<SideEffect>, WriteVar<SideEffect>) {
1637 self.new_prefixed_var("post_job")
1638 }
1639
1640 #[track_caller]
1653 #[must_use]
1654 pub fn persistent_dir(&mut self) -> Option<ReadVar<PathBuf>> {
1655 let path: ReadVar<PathBuf> = ReadVar {
1656 backing_var: ReadVarBacking::RuntimeVar {
1657 var: self.backend.borrow_mut().persistent_dir_path_var()?,
1658 is_side_effect: false,
1659 },
1660 _kind: std::marker::PhantomData,
1661 };
1662
1663 let folder_name = self
1664 .backend
1665 .borrow_mut()
1666 .current_node()
1667 .modpath()
1668 .replace("::", "__");
1669
1670 Some(
1671 self.emit_rust_stepv("🌼 Create persistent store dir", |ctx| {
1672 let path = path.claim(ctx);
1673 |rt| {
1674 let dir = rt.read(path).join(folder_name);
1675 fs_err::create_dir_all(&dir)?;
1676 Ok(dir)
1677 }
1678 }),
1679 )
1680 }
1681
1682 pub fn supports_persistent_dir(&mut self) -> bool {
1684 self.backend
1685 .borrow_mut()
1686 .persistent_dir_path_var()
1687 .is_some()
1688 }
1689}
1690
1691pub trait RuntimeVarDb {
1694 fn get_var(&mut self, var_name: &str) -> (Vec<u8>, bool) {
1695 self.try_get_var(var_name)
1696 .unwrap_or_else(|| panic!("db is missing var {}", var_name))
1697 }
1698
1699 fn try_get_var(&mut self, var_name: &str) -> Option<(Vec<u8>, bool)>;
1700 fn set_var(&mut self, var_name: &str, is_secret: bool, value: Vec<u8>);
1701}
1702
1703impl RuntimeVarDb for Box<dyn RuntimeVarDb> {
1704 fn try_get_var(&mut self, var_name: &str) -> Option<(Vec<u8>, bool)> {
1705 (**self).try_get_var(var_name)
1706 }
1707
1708 fn set_var(&mut self, var_name: &str, is_secret: bool, value: Vec<u8>) {
1709 (**self).set_var(var_name, is_secret, value)
1710 }
1711}
1712
1713pub mod steps {
1714 pub mod ado {
1715 use crate::node::ClaimedReadVar;
1716 use crate::node::ClaimedWriteVar;
1717 use crate::node::ReadVarBacking;
1718 use serde::Deserialize;
1719 use serde::Serialize;
1720 use std::borrow::Cow;
1721
1722 #[derive(Debug, Clone, Serialize, Deserialize)]
1728 pub struct AdoResourcesRepositoryId {
1729 pub(crate) repo_id: String,
1730 }
1731
1732 impl AdoResourcesRepositoryId {
1733 pub fn new_self() -> Self {
1739 Self {
1740 repo_id: "self".into(),
1741 }
1742 }
1743
1744 pub fn dangerous_get_raw_id(&self) -> &str {
1750 &self.repo_id
1751 }
1752
1753 pub fn dangerous_new(repo_id: &str) -> Self {
1759 Self {
1760 repo_id: repo_id.into(),
1761 }
1762 }
1763 }
1764
1765 #[derive(Clone, Debug, Serialize, Deserialize)]
1770 pub struct AdoRuntimeVar {
1771 is_secret: bool,
1772 ado_var: Cow<'static, str>,
1773 }
1774
1775 #[allow(non_upper_case_globals)]
1776 impl AdoRuntimeVar {
1777 pub const BUILD__SOURCE_BRANCH: AdoRuntimeVar =
1783 AdoRuntimeVar::new("build.SourceBranch");
1784
1785 pub const BUILD__BUILD_NUMBER: AdoRuntimeVar = AdoRuntimeVar::new("build.BuildNumber");
1787
1788 pub const SYSTEM__ACCESS_TOKEN: AdoRuntimeVar =
1790 AdoRuntimeVar::new_secret("System.AccessToken");
1791
1792 pub const SYSTEM__JOB_ATTEMPT: AdoRuntimeVar =
1794 AdoRuntimeVar::new_secret("System.JobAttempt");
1795 }
1796
1797 impl AdoRuntimeVar {
1798 const fn new(s: &'static str) -> Self {
1799 Self {
1800 is_secret: false,
1801 ado_var: Cow::Borrowed(s),
1802 }
1803 }
1804
1805 const fn new_secret(s: &'static str) -> Self {
1806 Self {
1807 is_secret: true,
1808 ado_var: Cow::Borrowed(s),
1809 }
1810 }
1811
1812 pub fn is_secret(&self) -> bool {
1814 self.is_secret
1815 }
1816
1817 pub fn as_raw_var_name(&self) -> String {
1819 self.ado_var.as_ref().into()
1820 }
1821
1822 pub fn dangerous_from_global(ado_var_name: impl AsRef<str>, is_secret: bool) -> Self {
1830 Self {
1831 is_secret,
1832 ado_var: ado_var_name.as_ref().to_owned().into(),
1833 }
1834 }
1835 }
1836
1837 pub fn new_ado_step_services(
1838 fresh_ado_var: &mut dyn FnMut() -> String,
1839 ) -> AdoStepServices<'_> {
1840 AdoStepServices {
1841 fresh_ado_var,
1842 ado_to_rust: Vec::new(),
1843 rust_to_ado: Vec::new(),
1844 }
1845 }
1846
1847 pub struct CompletedAdoStepServices {
1848 pub ado_to_rust: Vec<(String, String, bool)>,
1849 pub rust_to_ado: Vec<(String, String)>,
1850 }
1851
1852 impl CompletedAdoStepServices {
1853 pub fn from_ado_step_services(access: AdoStepServices<'_>) -> Self {
1854 let AdoStepServices {
1855 fresh_ado_var: _,
1856 ado_to_rust,
1857 rust_to_ado,
1858 } = access;
1859
1860 Self {
1861 ado_to_rust,
1862 rust_to_ado,
1863 }
1864 }
1865 }
1866
1867 pub struct AdoStepServices<'a> {
1868 fresh_ado_var: &'a mut dyn FnMut() -> String,
1869 ado_to_rust: Vec<(String, String, bool)>,
1870 rust_to_ado: Vec<(String, String)>,
1871 }
1872
1873 impl AdoStepServices<'_> {
1874 pub fn resolve_repository_id(&self, repo_id: AdoResourcesRepositoryId) -> String {
1877 repo_id.repo_id
1878 }
1879
1880 pub fn set_var(&mut self, var: ClaimedWriteVar<String>, from_ado_var: AdoRuntimeVar) {
1886 self.ado_to_rust.push((
1887 from_ado_var.ado_var.into(),
1888 var.backing_var,
1889 from_ado_var.is_secret,
1890 ))
1891 }
1892
1893 pub fn get_var(&mut self, var: ClaimedReadVar<String>) -> AdoRuntimeVar {
1895 let backing_var = if let ReadVarBacking::RuntimeVar {
1896 var,
1897 is_side_effect,
1898 } = &var.backing_var
1899 {
1900 assert!(!is_side_effect);
1901 var
1902 } else {
1903 todo!("support inline ado read vars")
1904 };
1905
1906 let new_ado_var_name = (self.fresh_ado_var)();
1907
1908 self.rust_to_ado
1909 .push((backing_var.clone(), new_ado_var_name.clone()));
1910 AdoRuntimeVar::dangerous_from_global(new_ado_var_name, false)
1911 }
1912 }
1913 }
1914
1915 pub mod github {
1916 use crate::node::ClaimVar;
1917 use crate::node::NodeCtx;
1918 use crate::node::ReadVar;
1919 use crate::node::ReadVarBacking;
1920 use crate::node::SideEffect;
1921 use crate::node::StepCtx;
1922 use crate::node::VarClaimed;
1923 use crate::node::VarNotClaimed;
1924 use crate::node::WriteVar;
1925 use std::collections::BTreeMap;
1926
1927 pub struct GhStepBuilder {
1928 display_name: String,
1929 cond: Option<ReadVar<bool>>,
1930 uses: String,
1931 with: Option<BTreeMap<String, GhParam>>,
1932 outputs: BTreeMap<String, Vec<WriteVar<String>>>,
1933 run_after: Vec<ReadVar<SideEffect>>,
1934 permissions: BTreeMap<GhPermission, GhPermissionValue>,
1935 }
1936
1937 impl GhStepBuilder {
1938 pub fn new(display_name: impl AsRef<str>, uses: impl AsRef<str>) -> Self {
1953 Self {
1954 display_name: display_name.as_ref().into(),
1955 cond: None,
1956 uses: uses.as_ref().into(),
1957 with: None,
1958 outputs: BTreeMap::new(),
1959 run_after: Vec::new(),
1960 permissions: BTreeMap::new(),
1961 }
1962 }
1963
1964 pub fn condition(mut self, cond: ReadVar<bool>) -> Self {
1971 self.cond = Some(cond);
1972 self
1973 }
1974
1975 pub fn with(mut self, k: impl AsRef<str>, v: impl Into<GhParam>) -> Self {
2001 self.with.get_or_insert_with(BTreeMap::new);
2002 if let Some(with) = &mut self.with {
2003 with.insert(k.as_ref().to_string(), v.into());
2004 }
2005 self
2006 }
2007
2008 pub fn output(mut self, k: impl AsRef<str>, v: WriteVar<String>) -> Self {
2017 self.outputs
2018 .entry(k.as_ref().to_string())
2019 .or_default()
2020 .push(v);
2021 self
2022 }
2023
2024 pub fn run_after(mut self, side_effect: ReadVar<SideEffect>) -> Self {
2026 self.run_after.push(side_effect);
2027 self
2028 }
2029
2030 pub fn requires_permission(
2035 mut self,
2036 perm: GhPermission,
2037 value: GhPermissionValue,
2038 ) -> Self {
2039 self.permissions.insert(perm, value);
2040 self
2041 }
2042
2043 #[track_caller]
2045 pub fn finish(self, ctx: &mut NodeCtx<'_>) -> ReadVar<SideEffect> {
2046 let (side_effect, claim_side_effect) = ctx.new_prefixed_var("auto_se");
2047 ctx.backend
2048 .borrow_mut()
2049 .on_claimed_runtime_var(&claim_side_effect.backing_var, false);
2050
2051 ctx.emit_gh_step_inner(
2052 self.display_name,
2053 self.cond,
2054 self.uses,
2055 self.with,
2056 self.outputs,
2057 self.run_after,
2058 self.permissions,
2059 );
2060
2061 side_effect
2062 }
2063 }
2064
2065 #[derive(Clone, Debug)]
2066 pub enum GhParam<C = VarNotClaimed> {
2067 Static(String),
2068 FloweyVar(ReadVar<String, C>),
2069 }
2070
2071 impl From<String> for GhParam {
2072 fn from(param: String) -> GhParam {
2073 GhParam::Static(param)
2074 }
2075 }
2076
2077 impl From<&str> for GhParam {
2078 fn from(param: &str) -> GhParam {
2079 GhParam::Static(param.to_string())
2080 }
2081 }
2082
2083 impl From<ReadVar<String>> for GhParam {
2084 fn from(param: ReadVar<String>) -> GhParam {
2085 GhParam::FloweyVar(param)
2086 }
2087 }
2088
2089 pub type ClaimedGhParam = GhParam<VarClaimed>;
2090
2091 impl ClaimVar for GhParam {
2092 type Claimed = ClaimedGhParam;
2093
2094 fn claim(self, ctx: &mut StepCtx<'_>) -> ClaimedGhParam {
2095 match self {
2096 GhParam::Static(s) => ClaimedGhParam::Static(s),
2097 GhParam::FloweyVar(var) => match &var.backing_var {
2098 ReadVarBacking::RuntimeVar { is_side_effect, .. } => {
2099 assert!(!is_side_effect);
2100 ClaimedGhParam::FloweyVar(var.claim(ctx))
2101 }
2102 ReadVarBacking::Inline(var) => ClaimedGhParam::Static(var.clone()),
2103 },
2104 }
2105 }
2106 }
2107
2108 #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
2113 pub enum GhPermissionValue {
2114 Read,
2115 Write,
2116 None,
2117 }
2118
2119 #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
2125 pub enum GhPermission {
2126 Actions,
2127 Attestations,
2128 Checks,
2129 Contents,
2130 Deployments,
2131 Discussions,
2132 IdToken,
2133 Issues,
2134 Packages,
2135 Pages,
2136 PullRequests,
2137 RepositoryProjects,
2138 SecurityEvents,
2139 Statuses,
2140 }
2141 }
2142
2143 pub mod rust {
2144 use crate::node::ClaimedWriteVar;
2145 use crate::node::FlowArch;
2146 use crate::node::FlowBackend;
2147 use crate::node::FlowPlatform;
2148 use crate::node::ReadVarValue;
2149 use crate::node::RuntimeVarDb;
2150 use serde::Serialize;
2151 use serde::de::DeserializeOwned;
2152
2153 pub fn new_rust_runtime_services(
2154 runtime_var_db: &mut dyn RuntimeVarDb,
2155 backend: FlowBackend,
2156 platform: FlowPlatform,
2157 arch: FlowArch,
2158 ) -> RustRuntimeServices<'_> {
2159 RustRuntimeServices {
2160 runtime_var_db,
2161 backend,
2162 platform,
2163 arch,
2164 has_read_secret: false,
2165 }
2166 }
2167
2168 pub struct RustRuntimeServices<'a> {
2169 runtime_var_db: &'a mut dyn RuntimeVarDb,
2170 backend: FlowBackend,
2171 platform: FlowPlatform,
2172 arch: FlowArch,
2173 has_read_secret: bool,
2174 }
2175
2176 impl RustRuntimeServices<'_> {
2177 pub fn backend(&self) -> FlowBackend {
2180 self.backend
2181 }
2182
2183 pub fn platform(&self) -> FlowPlatform {
2186 self.platform
2187 }
2188
2189 pub fn arch(&self) -> FlowArch {
2191 self.arch
2192 }
2193
2194 pub fn write<T>(&mut self, var: ClaimedWriteVar<T>, val: &T)
2202 where
2203 T: Serialize + DeserializeOwned,
2204 {
2205 self.write_maybe_secret(var, val, self.has_read_secret)
2206 }
2207
2208 pub fn write_secret<T>(&mut self, var: ClaimedWriteVar<T>, val: &T)
2214 where
2215 T: Serialize + DeserializeOwned,
2216 {
2217 self.write_maybe_secret(var, val, true)
2218 }
2219
2220 pub fn write_not_secret<T>(&mut self, var: ClaimedWriteVar<T>, val: &T)
2227 where
2228 T: Serialize + DeserializeOwned,
2229 {
2230 self.write_maybe_secret(var, val, false)
2231 }
2232
2233 fn write_maybe_secret<T>(&mut self, var: ClaimedWriteVar<T>, val: &T, is_secret: bool)
2234 where
2235 T: Serialize + DeserializeOwned,
2236 {
2237 let val = if var.is_side_effect {
2238 b"null".to_vec()
2239 } else {
2240 serde_json::to_vec(val).expect("improve this error path")
2241 };
2242 self.runtime_var_db
2243 .set_var(&var.backing_var, is_secret, val);
2244 }
2245
2246 pub fn write_all<T>(
2247 &mut self,
2248 vars: impl IntoIterator<Item = ClaimedWriteVar<T>>,
2249 val: &T,
2250 ) where
2251 T: Serialize + DeserializeOwned,
2252 {
2253 for var in vars {
2254 self.write(var, val)
2255 }
2256 }
2257
2258 pub fn read<T: ReadVarValue>(&mut self, var: T) -> T::Value {
2259 var.read_value(self)
2260 }
2261
2262 pub(crate) fn get_var(&mut self, var: &str, is_side_effect: bool) -> Vec<u8> {
2263 let (v, is_secret) = self.runtime_var_db.get_var(var);
2264 self.has_read_secret |= is_secret && !is_side_effect;
2265 v
2266 }
2267
2268 pub fn dangerous_gh_set_global_env_var(
2275 &mut self,
2276 var: String,
2277 gh_env_var: String,
2278 ) -> anyhow::Result<()> {
2279 if !matches!(self.backend, FlowBackend::Github) {
2280 return Err(anyhow::anyhow!(
2281 "dangerous_set_gh_env_var can only be used on GitHub Actions"
2282 ));
2283 }
2284
2285 let gh_env_file_path = std::env::var("GITHUB_ENV")?;
2286 let mut gh_env_file = fs_err::OpenOptions::new()
2287 .append(true)
2288 .open(gh_env_file_path)?;
2289 let gh_env_var_assignment = format!(
2290 r#"{}<<EOF
2291{}
2292EOF
2293"#,
2294 gh_env_var, var
2295 );
2296 std::io::Write::write_all(&mut gh_env_file, gh_env_var_assignment.as_bytes())?;
2297
2298 Ok(())
2299 }
2300 }
2301 }
2302}
2303
2304pub trait FlowNodeBase {
2309 type Request: Serialize + DeserializeOwned;
2310
2311 fn imports(&mut self, ctx: &mut ImportCtx<'_>);
2312 fn emit(&mut self, requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()>;
2313
2314 fn i_know_what_im_doing_with_this_manual_impl(&mut self);
2320}
2321
2322pub mod erased {
2323 use crate::node::FlowNodeBase;
2324 use crate::node::NodeCtx;
2325 use crate::node::user_facing::*;
2326
2327 pub struct ErasedNode<N: FlowNodeBase>(pub N);
2328
2329 impl<N: FlowNodeBase> ErasedNode<N> {
2330 pub fn from_node(node: N) -> Self {
2331 Self(node)
2332 }
2333 }
2334
2335 impl<N> FlowNodeBase for ErasedNode<N>
2336 where
2337 N: FlowNodeBase,
2338 {
2339 type Request = Box<[u8]>;
2341
2342 fn imports(&mut self, ctx: &mut ImportCtx<'_>) {
2343 self.0.imports(ctx)
2344 }
2345
2346 fn emit(&mut self, requests: Vec<Box<[u8]>>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
2347 let mut converted_requests = Vec::new();
2348 for req in requests {
2349 converted_requests.push(serde_json::from_slice(&req)?)
2350 }
2351
2352 self.0.emit(converted_requests, ctx)
2353 }
2354
2355 fn i_know_what_im_doing_with_this_manual_impl(&mut self) {}
2356 }
2357}
2358
2359#[derive(Clone, Copy, PartialEq, Eq, Hash)]
2361pub struct NodeHandle(std::any::TypeId);
2362
2363impl Ord for NodeHandle {
2364 fn cmp(&self, other: &Self) -> std::cmp::Ordering {
2365 self.modpath().cmp(other.modpath())
2366 }
2367}
2368
2369impl PartialOrd for NodeHandle {
2370 fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
2371 Some(self.cmp(other))
2372 }
2373}
2374
2375impl std::fmt::Debug for NodeHandle {
2376 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2377 std::fmt::Debug::fmt(&self.try_modpath(), f)
2378 }
2379}
2380
2381impl NodeHandle {
2382 pub fn from_type<N: FlowNodeBase + 'static>() -> NodeHandle {
2383 NodeHandle(std::any::TypeId::of::<N>())
2384 }
2385
2386 pub fn from_modpath(modpath: &str) -> NodeHandle {
2387 node_luts::erased_node_by_modpath().get(modpath).unwrap().0
2388 }
2389
2390 pub fn try_from_modpath(modpath: &str) -> Option<NodeHandle> {
2391 node_luts::erased_node_by_modpath()
2392 .get(modpath)
2393 .map(|(s, _)| *s)
2394 }
2395
2396 pub fn new_erased_node(&self) -> Box<dyn FlowNodeBase<Request = Box<[u8]>>> {
2397 let ctor = node_luts::erased_node_by_typeid().get(self).unwrap();
2398 ctor()
2399 }
2400
2401 pub fn modpath(&self) -> &'static str {
2402 node_luts::modpath_by_node_typeid().get(self).unwrap()
2403 }
2404
2405 pub fn try_modpath(&self) -> Option<&'static str> {
2406 node_luts::modpath_by_node_typeid().get(self).cloned()
2407 }
2408
2409 pub fn dummy() -> NodeHandle {
2412 NodeHandle(std::any::TypeId::of::<()>())
2413 }
2414}
2415
2416pub fn list_all_registered_nodes() -> impl Iterator<Item = NodeHandle> {
2417 node_luts::modpath_by_node_typeid().keys().cloned()
2418}
2419
2420mod node_luts {
2435 use super::FlowNodeBase;
2436 use super::NodeHandle;
2437 use std::collections::HashMap;
2438 use std::sync::OnceLock;
2439
2440 pub(super) fn modpath_by_node_typeid() -> &'static HashMap<NodeHandle, &'static str> {
2441 static TYPEID_TO_MODPATH: OnceLock<HashMap<NodeHandle, &'static str>> = OnceLock::new();
2442
2443 TYPEID_TO_MODPATH.get_or_init(|| {
2444 let mut lookup = HashMap::new();
2445 for crate::node::private::FlowNodeMeta {
2446 module_path,
2447 ctor: _,
2448 typeid,
2449 } in crate::node::private::FLOW_NODES
2450 {
2451 let existing = lookup.insert(
2452 NodeHandle(*typeid),
2453 module_path
2454 .strip_suffix("::_only_one_call_to_flowey_node_per_module")
2455 .unwrap(),
2456 );
2457 assert!(existing.is_none())
2460 }
2461
2462 lookup
2463 })
2464 }
2465
2466 pub(super) fn erased_node_by_typeid()
2467 -> &'static HashMap<NodeHandle, fn() -> Box<dyn FlowNodeBase<Request = Box<[u8]>>>> {
2468 static LOOKUP: OnceLock<
2469 HashMap<NodeHandle, fn() -> Box<dyn FlowNodeBase<Request = Box<[u8]>>>>,
2470 > = OnceLock::new();
2471
2472 LOOKUP.get_or_init(|| {
2473 let mut lookup = HashMap::new();
2474 for crate::node::private::FlowNodeMeta {
2475 module_path: _,
2476 ctor,
2477 typeid,
2478 } in crate::node::private::FLOW_NODES
2479 {
2480 let existing = lookup.insert(NodeHandle(*typeid), *ctor);
2481 assert!(existing.is_none())
2484 }
2485
2486 lookup
2487 })
2488 }
2489
2490 pub(super) fn erased_node_by_modpath() -> &'static HashMap<
2491 &'static str,
2492 (
2493 NodeHandle,
2494 fn() -> Box<dyn FlowNodeBase<Request = Box<[u8]>>>,
2495 ),
2496 > {
2497 static MODPATH_LOOKUP: OnceLock<
2498 HashMap<
2499 &'static str,
2500 (
2501 NodeHandle,
2502 fn() -> Box<dyn FlowNodeBase<Request = Box<[u8]>>>,
2503 ),
2504 >,
2505 > = OnceLock::new();
2506
2507 MODPATH_LOOKUP.get_or_init(|| {
2508 let mut lookup = HashMap::new();
2509 for crate::node::private::FlowNodeMeta { module_path, ctor, typeid } in crate::node::private::FLOW_NODES {
2510 let existing = lookup.insert(module_path.strip_suffix("::_only_one_call_to_flowey_node_per_module").unwrap(), (NodeHandle(*typeid), *ctor));
2511 if existing.is_some() {
2512 panic!("conflicting node registrations at {module_path}! please ensure there is a single node per module!")
2513 }
2514 }
2515 lookup
2516 })
2517 }
2518}
2519
2520#[doc(hidden)]
2521pub mod private {
2522 pub use linkme;
2523
2524 pub struct FlowNodeMeta {
2525 pub module_path: &'static str,
2526 pub ctor: fn() -> Box<dyn super::FlowNodeBase<Request = Box<[u8]>>>,
2527 pub typeid: std::any::TypeId,
2528 }
2529
2530 #[linkme::distributed_slice]
2531 pub static FLOW_NODES: [FlowNodeMeta] = [..];
2532
2533 #[expect(unsafe_code)]
2535 #[linkme::distributed_slice(FLOW_NODES)]
2536 static DUMMY_FLOW_NODE: FlowNodeMeta = FlowNodeMeta {
2537 module_path: "<dummy>::_only_one_call_to_flowey_node_per_module",
2538 ctor: || unreachable!(),
2539 typeid: std::any::TypeId::of::<()>(),
2540 };
2541}
2542
2543#[doc(hidden)]
2544#[macro_export]
2545macro_rules! new_flow_node_base {
2546 (struct Node) => {
2547 #[non_exhaustive]
2549 pub struct Node;
2550
2551 mod _only_one_call_to_flowey_node_per_module {
2552 const _: () = {
2553 use $crate::node::private::linkme;
2554
2555 fn new_erased() -> Box<dyn $crate::node::FlowNodeBase<Request = Box<[u8]>>> {
2556 Box::new($crate::node::erased::ErasedNode(super::Node))
2557 }
2558
2559 #[linkme::distributed_slice($crate::node::private::FLOW_NODES)]
2560 #[linkme(crate = linkme)]
2561 static FLOW_NODE: $crate::node::private::FlowNodeMeta =
2562 $crate::node::private::FlowNodeMeta {
2563 module_path: module_path!(),
2564 ctor: new_erased,
2565 typeid: std::any::TypeId::of::<super::Node>(),
2566 };
2567 };
2568 }
2569 };
2570}
2571
2572pub trait FlowNode {
2659 type Request: Serialize + DeserializeOwned;
2663
2664 fn imports(ctx: &mut ImportCtx<'_>);
2676
2677 fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()>;
2680}
2681
2682#[macro_export]
2683macro_rules! new_flow_node {
2684 (struct Node) => {
2685 $crate::new_flow_node_base!(struct Node);
2686
2687 impl $crate::node::FlowNodeBase for Node
2688 where
2689 Node: FlowNode,
2690 {
2691 type Request = <Node as FlowNode>::Request;
2692
2693 fn imports(&mut self, dep: &mut $crate::node::ImportCtx<'_>) {
2694 <Node as FlowNode>::imports(dep)
2695 }
2696
2697 fn emit(
2698 &mut self,
2699 requests: Vec<Self::Request>,
2700 ctx: &mut $crate::node::NodeCtx<'_>,
2701 ) -> anyhow::Result<()> {
2702 <Node as FlowNode>::emit(requests, ctx)
2703 }
2704
2705 fn i_know_what_im_doing_with_this_manual_impl(&mut self) {}
2706 }
2707 };
2708}
2709
2710pub trait SimpleFlowNode {
2731 type Request: Serialize + DeserializeOwned;
2732
2733 fn imports(ctx: &mut ImportCtx<'_>);
2745
2746 fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()>;
2748}
2749
2750#[macro_export]
2751macro_rules! new_simple_flow_node {
2752 (struct Node) => {
2753 $crate::new_flow_node_base!(struct Node);
2754
2755 impl $crate::node::FlowNodeBase for Node
2756 where
2757 Node: $crate::node::SimpleFlowNode,
2758 {
2759 type Request = <Node as $crate::node::SimpleFlowNode>::Request;
2760
2761 fn imports(&mut self, dep: &mut $crate::node::ImportCtx<'_>) {
2762 <Node as $crate::node::SimpleFlowNode>::imports(dep)
2763 }
2764
2765 fn emit(&mut self, requests: Vec<Self::Request>, ctx: &mut $crate::node::NodeCtx<'_>) -> anyhow::Result<()> {
2766 for req in requests {
2767 <Node as $crate::node::SimpleFlowNode>::process_request(req, ctx)?
2768 }
2769
2770 Ok(())
2771 }
2772
2773 fn i_know_what_im_doing_with_this_manual_impl(&mut self) {}
2774 }
2775 };
2776}
2777
2778pub trait IntoRequest {
2786 type Node: FlowNodeBase;
2787 fn into_request(self) -> <Self::Node as FlowNodeBase>::Request;
2788
2789 #[doc(hidden)]
2792 #[expect(nonstandard_style)]
2793 fn do_not_manually_impl_this_trait__use_the_flowey_request_macro_instead(&mut self);
2794}
2795
2796#[doc(hidden)]
2797#[macro_export]
2798macro_rules! __flowey_request_inner {
2799 (@emit_struct [$req:ident]
2803 $(#[$a:meta])*
2804 $variant:ident($($tt:tt)*),
2805 $($rest:tt)*
2806 ) => {
2807 $(#[$a])*
2808 #[derive($crate::reexports::Serialize, $crate::reexports::Deserialize)]
2809 pub struct $variant($($tt)*);
2810
2811 impl IntoRequest for $variant {
2812 type Node = Node;
2813 fn into_request(self) -> $req {
2814 $req::$variant(self)
2815 }
2816 fn do_not_manually_impl_this_trait__use_the_flowey_request_macro_instead(&mut self) {}
2817 }
2818
2819 $crate::__flowey_request_inner!(@emit_struct [$req] $($rest)*);
2820 };
2821 (@emit_struct [$req:ident]
2822 $(#[$a:meta])*
2823 $variant:ident { $($tt:tt)* },
2824 $($rest:tt)*
2825 ) => {
2826 $(#[$a])*
2827 #[derive($crate::reexports::Serialize, $crate::reexports::Deserialize)]
2828 pub struct $variant {
2829 $($tt)*
2830 }
2831
2832 impl IntoRequest for $variant {
2833 type Node = Node;
2834 fn into_request(self) -> $req {
2835 $req::$variant(self)
2836 }
2837 fn do_not_manually_impl_this_trait__use_the_flowey_request_macro_instead(&mut self) {}
2838 }
2839
2840 $crate::__flowey_request_inner!(@emit_struct [$req] $($rest)*);
2841 };
2842 (@emit_struct [$req:ident]
2843 $(#[$a:meta])*
2844 $variant:ident,
2845 $($rest:tt)*
2846 ) => {
2847 $(#[$a])*
2848 #[derive(Serialize, Deserialize)]
2849 pub struct $variant;
2850
2851 impl IntoRequest for $variant {
2852 type Node = Node;
2853 fn into_request(self) -> $req {
2854 $req::$variant(self)
2855 }
2856 fn do_not_manually_impl_this_trait__use_the_flowey_request_macro_instead(&mut self) {}
2857 }
2858
2859 $crate::__flowey_request_inner!(@emit_struct [$req] $($rest)*);
2860 };
2861 (@emit_struct [$req:ident]
2862 ) => {};
2863
2864 (@emit_req_enum [$req:ident($($root_a:meta,)*), $($prev:ident[$($prev_a:meta,)*])*]
2868 $(#[$a:meta])*
2869 $variant:ident($($tt:tt)*),
2870 $($rest:tt)*
2871 ) => {
2872 $crate::__flowey_request_inner!(@emit_req_enum [$req($($root_a,)*), $($prev[$($prev_a,)*])* $variant[$($a,)*]] $($rest)*);
2873 };
2874 (@emit_req_enum [$req:ident($($root_a:meta,)*), $($prev:ident[$($prev_a:meta,)*])*]
2875 $(#[$a:meta])*
2876 $variant:ident { $($tt:tt)* },
2877 $($rest:tt)*
2878 ) => {
2879 $crate::__flowey_request_inner!(@emit_req_enum [$req($($root_a,)*), $($prev[$($prev_a,)*])* $variant[$($a,)*]] $($rest)*);
2880 };
2881 (@emit_req_enum [$req:ident($($root_a:meta,)*), $($prev:ident[$($prev_a:meta,)*])*]
2882 $(#[$a:meta])*
2883 $variant:ident,
2884 $($rest:tt)*
2885 ) => {
2886 $crate::__flowey_request_inner!(@emit_req_enum [$req($($root_a,)*), $($prev[$($prev_a,)*])* $variant[$($a,)*]] $($rest)*);
2887 };
2888 (@emit_req_enum [$req:ident($($root_a:meta,)*), $($prev:ident[$($prev_a:meta,)*])*]
2889 ) => {
2890 #[derive(Serialize, Deserialize)]
2891 pub enum $req {$(
2892 $(#[$prev_a])*
2893 $prev(self::req::$prev),
2894 )*}
2895
2896 impl IntoRequest for $req {
2897 type Node = Node;
2898 fn into_request(self) -> $req {
2899 self
2900 }
2901 fn do_not_manually_impl_this_trait__use_the_flowey_request_macro_instead(&mut self) {}
2902 }
2903 };
2904}
2905
2906#[macro_export]
2954macro_rules! flowey_request {
2955 (
2956 $(#[$root_a:meta])*
2957 pub enum_struct $req:ident {
2958 $($tt:tt)*
2959 }
2960 ) => {
2961 $crate::__flowey_request_inner!(@emit_req_enum [$req($($root_a,)*),] $($tt)*);
2962 pub mod req {
2963 use super::*;
2964 $crate::__flowey_request_inner!(@emit_struct [$req] $($tt)*);
2965 }
2966 };
2967
2968 (
2969 $(#[$a:meta])*
2970 pub enum $req:ident {
2971 $($tt:tt)*
2972 }
2973 ) => {
2974 $(#[$a])*
2975 #[derive($crate::reexports::Serialize, $crate::reexports::Deserialize)]
2976 pub enum $req {
2977 $($tt)*
2978 }
2979
2980 impl $crate::node::IntoRequest for $req {
2981 type Node = Node;
2982 fn into_request(self) -> $req {
2983 self
2984 }
2985 fn do_not_manually_impl_this_trait__use_the_flowey_request_macro_instead(&mut self) {}
2986 }
2987 };
2988
2989 (
2990 $(#[$a:meta])*
2991 pub struct $req:ident {
2992 $($tt:tt)*
2993 }
2994 ) => {
2995 $(#[$a])*
2996 #[derive($crate::reexports::Serialize, $crate::reexports::Deserialize)]
2997 pub struct $req {
2998 $($tt)*
2999 }
3000
3001 impl $crate::node::IntoRequest for $req {
3002 type Node = Node;
3003 fn into_request(self) -> $req {
3004 self
3005 }
3006 fn do_not_manually_impl_this_trait__use_the_flowey_request_macro_instead(&mut self) {}
3007 }
3008 };
3009
3010 (
3011 $(#[$a:meta])*
3012 pub struct $req:ident($($tt:tt)*);
3013 ) => {
3014 $(#[$a])*
3015 #[derive($crate::reexports::Serialize, $crate::reexports::Deserialize)]
3016 pub struct $req($($tt)*);
3017
3018 impl $crate::node::IntoRequest for $req {
3019 type Node = Node;
3020 fn into_request(self) -> $req {
3021 self
3022 }
3023 fn do_not_manually_impl_this_trait__use_the_flowey_request_macro_instead(&mut self) {}
3024 }
3025 };
3026}