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 Unknown,
958}
959
960#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
962#[non_exhaustive]
963pub enum FlowPlatform {
964 Windows,
966 Linux(FlowPlatformLinuxDistro),
968 MacOs,
970}
971
972impl FlowPlatform {
973 pub fn kind(&self) -> FlowPlatformKind {
974 match self {
975 Self::Windows => FlowPlatformKind::Windows,
976 Self::Linux(_) | Self::MacOs => FlowPlatformKind::Unix,
977 }
978 }
979
980 fn as_str(&self) -> &'static str {
981 match self {
982 Self::Windows => "windows",
983 Self::Linux(_) => "linux",
984 Self::MacOs => "macos",
985 }
986 }
987
988 pub fn exe_suffix(&self) -> &'static str {
990 if self == &Self::Windows { ".exe" } else { "" }
991 }
992
993 pub fn binary(&self, name: &str) -> String {
995 format!("{}{}", name, self.exe_suffix())
996 }
997}
998
999impl std::fmt::Display for FlowPlatform {
1000 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1001 f.pad(self.as_str())
1002 }
1003}
1004
1005#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1007#[non_exhaustive]
1008pub enum FlowArch {
1009 X86_64,
1010 Aarch64,
1011}
1012
1013impl FlowArch {
1014 fn as_str(&self) -> &'static str {
1015 match self {
1016 Self::X86_64 => "x86_64",
1017 Self::Aarch64 => "aarch64",
1018 }
1019 }
1020}
1021
1022impl std::fmt::Display for FlowArch {
1023 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1024 f.pad(self.as_str())
1025 }
1026}
1027
1028pub struct StepCtx<'a> {
1030 backend: Rc<RefCell<&'a mut dyn NodeCtxBackend>>,
1031}
1032
1033impl StepCtx<'_> {
1034 pub fn backend(&self) -> FlowBackend {
1037 self.backend.borrow_mut().backend()
1038 }
1039
1040 pub fn platform(&self) -> FlowPlatform {
1043 self.backend.borrow_mut().platform()
1044 }
1045}
1046
1047const NO_ADO_INLINE_SCRIPT: Option<
1048 for<'a> fn(&'a mut RustRuntimeServices<'_>) -> anyhow::Result<()>,
1049> = None;
1050
1051pub struct NodeCtx<'a> {
1053 backend: Rc<RefCell<&'a mut dyn NodeCtxBackend>>,
1054}
1055
1056impl<'ctx> NodeCtx<'ctx> {
1057 pub fn emit_rust_step<F, G>(&mut self, label: impl AsRef<str>, code: F) -> ReadVar<SideEffect>
1063 where
1064 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> G,
1065 G: for<'a> FnOnce(&'a mut RustRuntimeServices<'_>) -> anyhow::Result<()> + 'static,
1066 {
1067 self.emit_rust_step_inner(label.as_ref(), false, code)
1068 }
1069
1070 pub fn emit_minor_rust_step<F, G>(
1080 &mut self,
1081 label: impl AsRef<str>,
1082 code: F,
1083 ) -> ReadVar<SideEffect>
1084 where
1085 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> G,
1086 G: for<'a> FnOnce(&'a mut RustRuntimeServices<'_>) + 'static,
1087 {
1088 self.emit_rust_step_inner(label.as_ref(), true, |ctx| {
1089 let f = code(ctx);
1090 |rt| {
1091 f(rt);
1092 Ok(())
1093 }
1094 })
1095 }
1096
1097 #[must_use]
1118 #[track_caller]
1119 pub fn emit_rust_stepv<T, F, G>(&mut self, label: impl AsRef<str>, code: F) -> ReadVar<T>
1120 where
1121 T: Serialize + DeserializeOwned + 'static,
1122 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> G,
1123 G: for<'a> FnOnce(&'a mut RustRuntimeServices<'_>) -> anyhow::Result<T> + 'static,
1124 {
1125 self.emit_rust_stepv_inner(label.as_ref(), false, code)
1126 }
1127
1128 #[must_use]
1152 #[track_caller]
1153 pub fn emit_minor_rust_stepv<T, F, G>(&mut self, label: impl AsRef<str>, code: F) -> ReadVar<T>
1154 where
1155 T: Serialize + DeserializeOwned + 'static,
1156 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> G,
1157 G: for<'a> FnOnce(&'a mut RustRuntimeServices<'_>) -> T + 'static,
1158 {
1159 self.emit_rust_stepv_inner(label.as_ref(), true, |ctx| {
1160 let f = code(ctx);
1161 |rt| Ok(f(rt))
1162 })
1163 }
1164
1165 fn emit_rust_step_inner<F, G>(
1166 &mut self,
1167 label: &str,
1168 can_merge: bool,
1169 code: F,
1170 ) -> ReadVar<SideEffect>
1171 where
1172 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> G,
1173 G: for<'a> FnOnce(&'a mut RustRuntimeServices<'_>) -> anyhow::Result<()> + 'static,
1174 {
1175 let (read, write) = self.new_prefixed_var("auto_se");
1176
1177 let ctx = &mut StepCtx {
1178 backend: self.backend.clone(),
1179 };
1180 write.claim(ctx);
1181
1182 let code = code(ctx);
1183 self.backend
1184 .borrow_mut()
1185 .on_emit_rust_step(label.as_ref(), can_merge, Box::new(code));
1186 read
1187 }
1188
1189 #[must_use]
1190 #[track_caller]
1191 fn emit_rust_stepv_inner<T, F, G>(
1192 &mut self,
1193 label: impl AsRef<str>,
1194 can_merge: bool,
1195 code: F,
1196 ) -> ReadVar<T>
1197 where
1198 T: Serialize + DeserializeOwned + 'static,
1199 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> G,
1200 G: for<'a> FnOnce(&'a mut RustRuntimeServices<'_>) -> anyhow::Result<T> + 'static,
1201 {
1202 let (read, write) = self.new_var();
1203
1204 let ctx = &mut StepCtx {
1205 backend: self.backend.clone(),
1206 };
1207 let write = write.claim(ctx);
1208
1209 let code = code(ctx);
1210 self.backend.borrow_mut().on_emit_rust_step(
1211 label.as_ref(),
1212 can_merge,
1213 Box::new(|rt| {
1214 let val = code(rt)?;
1215 rt.write(write, &val);
1216 Ok(())
1217 }),
1218 );
1219 read
1220 }
1221
1222 #[track_caller]
1224 #[must_use]
1225 pub fn get_ado_variable(&mut self, ado_var: AdoRuntimeVar) -> ReadVar<String> {
1226 let (var, write_var) = self.new_var();
1227 self.emit_ado_step(format!("🌼 read {}", ado_var.as_raw_var_name()), |ctx| {
1228 let write_var = write_var.claim(ctx);
1229 |rt| {
1230 rt.set_var(write_var, ado_var);
1231 "".into()
1232 }
1233 });
1234 var
1235 }
1236
1237 pub fn emit_ado_step<F, G>(&mut self, display_name: impl AsRef<str>, yaml_snippet: F)
1239 where
1240 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> G,
1241 G: for<'a> FnOnce(&'a mut AdoStepServices<'_>) -> String + 'static,
1242 {
1243 self.emit_ado_step_inner(display_name, None, |ctx| {
1244 (yaml_snippet(ctx), NO_ADO_INLINE_SCRIPT)
1245 })
1246 }
1247
1248 pub fn emit_ado_step_with_condition<F, G>(
1251 &mut self,
1252 display_name: impl AsRef<str>,
1253 cond: ReadVar<bool>,
1254 yaml_snippet: F,
1255 ) where
1256 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> G,
1257 G: for<'a> FnOnce(&'a mut AdoStepServices<'_>) -> String + 'static,
1258 {
1259 self.emit_ado_step_inner(display_name, Some(cond), |ctx| {
1260 (yaml_snippet(ctx), NO_ADO_INLINE_SCRIPT)
1261 })
1262 }
1263
1264 pub fn emit_ado_step_with_condition_optional<F, G>(
1267 &mut self,
1268 display_name: impl AsRef<str>,
1269 cond: Option<ReadVar<bool>>,
1270 yaml_snippet: F,
1271 ) where
1272 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> G,
1273 G: for<'a> FnOnce(&'a mut AdoStepServices<'_>) -> String + 'static,
1274 {
1275 self.emit_ado_step_inner(display_name, cond, |ctx| {
1276 (yaml_snippet(ctx), NO_ADO_INLINE_SCRIPT)
1277 })
1278 }
1279
1280 pub fn emit_ado_step_with_inline_script<F, G, H>(
1309 &mut self,
1310 display_name: impl AsRef<str>,
1311 yaml_snippet: F,
1312 ) where
1313 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> (G, H),
1314 G: for<'a> FnOnce(&'a mut AdoStepServices<'_>) -> String + 'static,
1315 H: for<'a> FnOnce(&'a mut RustRuntimeServices<'_>) -> anyhow::Result<()> + 'static,
1316 {
1317 self.emit_ado_step_inner(display_name, None, |ctx| {
1318 let (f, g) = yaml_snippet(ctx);
1319 (f, Some(g))
1320 })
1321 }
1322
1323 fn emit_ado_step_inner<F, G, H>(
1324 &mut self,
1325 display_name: impl AsRef<str>,
1326 cond: Option<ReadVar<bool>>,
1327 yaml_snippet: F,
1328 ) where
1329 F: for<'a> FnOnce(&'a mut StepCtx<'_>) -> (G, Option<H>),
1330 G: for<'a> FnOnce(&'a mut AdoStepServices<'_>) -> String + 'static,
1331 H: for<'a> FnOnce(&'a mut RustRuntimeServices<'_>) -> anyhow::Result<()> + 'static,
1332 {
1333 let condvar = match cond.map(|c| c.backing_var) {
1334 Some(ReadVarBacking::Inline(cond)) => {
1336 if !cond {
1337 return;
1338 } else {
1339 None
1340 }
1341 }
1342 Some(ReadVarBacking::RuntimeVar {
1343 var,
1344 is_side_effect,
1345 }) => {
1346 assert!(!is_side_effect);
1347 self.backend.borrow_mut().on_claimed_runtime_var(&var, true);
1348 Some(var)
1349 }
1350 None => None,
1351 };
1352
1353 let (yaml_snippet, inline_script) = yaml_snippet(&mut StepCtx {
1354 backend: self.backend.clone(),
1355 });
1356 self.backend.borrow_mut().on_emit_ado_step(
1357 display_name.as_ref(),
1358 Box::new(yaml_snippet),
1359 if let Some(inline_script) = inline_script {
1360 Some(Box::new(inline_script))
1361 } else {
1362 None
1363 },
1364 condvar,
1365 );
1366 }
1367
1368 #[track_caller]
1370 #[must_use]
1371 pub fn get_gh_context_var(&mut self) -> GhContextVarReader<'ctx, Root> {
1372 GhContextVarReader {
1373 ctx: NodeCtx {
1374 backend: self.backend.clone(),
1375 },
1376 _state: std::marker::PhantomData,
1377 }
1378 }
1379
1380 pub fn emit_gh_step(
1382 &mut self,
1383 display_name: impl AsRef<str>,
1384 uses: impl AsRef<str>,
1385 ) -> GhStepBuilder {
1386 GhStepBuilder::new(display_name, uses)
1387 }
1388
1389 fn emit_gh_step_inner(
1390 &mut self,
1391 display_name: impl AsRef<str>,
1392 cond: Option<ReadVar<bool>>,
1393 uses: impl AsRef<str>,
1394 with: Option<BTreeMap<String, GhParam>>,
1395 outputs: BTreeMap<String, Vec<WriteVar<String>>>,
1396 run_after: Vec<ReadVar<SideEffect>>,
1397 permissions: BTreeMap<GhPermission, GhPermissionValue>,
1398 ) {
1399 let condvar = match cond.map(|c| c.backing_var) {
1400 Some(ReadVarBacking::Inline(cond)) => {
1402 if !cond {
1403 return;
1404 } else {
1405 None
1406 }
1407 }
1408 Some(ReadVarBacking::RuntimeVar {
1409 var,
1410 is_side_effect,
1411 }) => {
1412 assert!(!is_side_effect);
1413 self.backend.borrow_mut().on_claimed_runtime_var(&var, true);
1414 Some(var)
1415 }
1416 None => None,
1417 };
1418
1419 let with = with
1420 .unwrap_or_default()
1421 .into_iter()
1422 .map(|(k, v)| {
1423 (
1424 k.clone(),
1425 v.claim(&mut StepCtx {
1426 backend: self.backend.clone(),
1427 }),
1428 )
1429 })
1430 .collect();
1431
1432 for var in run_after {
1433 var.claim(&mut StepCtx {
1434 backend: self.backend.clone(),
1435 });
1436 }
1437
1438 let outputvars = outputs
1439 .into_iter()
1440 .map(|(name, vars)| {
1441 (
1442 name,
1443 vars.into_iter()
1444 .map(|var| {
1445 let var = var.claim(&mut StepCtx {
1446 backend: self.backend.clone(),
1447 });
1448 GhOutput {
1449 backing_var: var.backing_var,
1450 is_secret: false,
1451 is_object: false,
1452 }
1453 })
1454 .collect(),
1455 )
1456 })
1457 .collect();
1458
1459 self.backend.borrow_mut().on_emit_gh_step(
1460 display_name.as_ref(),
1461 uses.as_ref(),
1462 with,
1463 condvar,
1464 outputvars,
1465 permissions,
1466 Vec::new(),
1467 Vec::new(),
1468 );
1469 }
1470
1471 pub fn emit_side_effect_step(
1479 &mut self,
1480 use_side_effects: impl IntoIterator<Item = ReadVar<SideEffect>>,
1481 resolve_side_effects: impl IntoIterator<Item = WriteVar<SideEffect>>,
1482 ) {
1483 let mut backend = self.backend.borrow_mut();
1484 for var in use_side_effects.into_iter() {
1485 if let ReadVarBacking::RuntimeVar {
1486 var,
1487 is_side_effect: _,
1488 } = &var.backing_var
1489 {
1490 backend.on_claimed_runtime_var(var, true);
1491 }
1492 }
1493
1494 for var in resolve_side_effects.into_iter() {
1495 backend.on_claimed_runtime_var(&var.backing_var, false);
1496 }
1497
1498 backend.on_emit_side_effect_step();
1499 }
1500
1501 pub fn backend(&self) -> FlowBackend {
1504 self.backend.borrow_mut().backend()
1505 }
1506
1507 pub fn platform(&self) -> FlowPlatform {
1510 self.backend.borrow_mut().platform()
1511 }
1512
1513 pub fn arch(&self) -> FlowArch {
1515 self.backend.borrow_mut().arch()
1516 }
1517
1518 pub fn req<R>(&mut self, req: R)
1520 where
1521 R: IntoRequest + 'static,
1522 {
1523 let mut backend = self.backend.borrow_mut();
1524 backend.on_request(
1525 NodeHandle::from_type::<R::Node>(),
1526 serde_json::to_vec(&req.into_request())
1527 .map(Into::into)
1528 .map_err(Into::into),
1529 );
1530 }
1531
1532 #[track_caller]
1535 #[must_use]
1536 pub fn reqv<T, R>(&mut self, f: impl FnOnce(WriteVar<T>) -> R) -> ReadVar<T>
1537 where
1538 T: Serialize + DeserializeOwned,
1539 R: IntoRequest + 'static,
1540 {
1541 let (read, write) = self.new_var();
1542 self.req::<R>(f(write));
1543 read
1544 }
1545
1546 pub fn requests<N>(&mut self, reqs: impl IntoIterator<Item = N::Request>)
1548 where
1549 N: FlowNodeBase + 'static,
1550 {
1551 let mut backend = self.backend.borrow_mut();
1552 for req in reqs.into_iter() {
1553 backend.on_request(
1554 NodeHandle::from_type::<N>(),
1555 serde_json::to_vec(&req).map(Into::into).map_err(Into::into),
1556 );
1557 }
1558 }
1559
1560 #[track_caller]
1563 #[must_use]
1564 pub fn new_var<T>(&self) -> (ReadVar<T>, WriteVar<T>)
1565 where
1566 T: Serialize + DeserializeOwned,
1567 {
1568 self.new_prefixed_var("")
1569 }
1570
1571 #[track_caller]
1572 #[must_use]
1573 fn new_prefixed_var<T>(&self, prefix: &'static str) -> (ReadVar<T>, WriteVar<T>)
1574 where
1575 T: Serialize + DeserializeOwned,
1576 {
1577 let caller = std::panic::Location::caller()
1579 .to_string()
1580 .replace('\\', "/");
1581
1582 let caller = caller
1598 .split_once("flowey/")
1599 .expect("due to a known limitation with flowey, all flowey code must have an ancestor dir called 'flowey/' somewhere in its full path")
1600 .1;
1601
1602 let colon = if prefix.is_empty() { "" } else { ":" };
1603 let ordinal = self.backend.borrow_mut().on_new_var();
1604 let backing_var = format!("{prefix}{colon}{ordinal}:{caller}");
1605
1606 (
1607 ReadVar {
1608 backing_var: ReadVarBacking::RuntimeVar {
1609 var: backing_var.clone(),
1610 is_side_effect: false,
1611 },
1612 _kind: std::marker::PhantomData,
1613 },
1614 WriteVar {
1615 backing_var,
1616 is_side_effect: false,
1617 _kind: std::marker::PhantomData,
1618 },
1619 )
1620 }
1621
1622 #[track_caller]
1633 #[must_use]
1634 pub fn new_post_job_side_effect(&self) -> (ReadVar<SideEffect>, WriteVar<SideEffect>) {
1635 self.new_prefixed_var("post_job")
1636 }
1637
1638 #[track_caller]
1651 #[must_use]
1652 pub fn persistent_dir(&mut self) -> Option<ReadVar<PathBuf>> {
1653 let path: ReadVar<PathBuf> = ReadVar {
1654 backing_var: ReadVarBacking::RuntimeVar {
1655 var: self.backend.borrow_mut().persistent_dir_path_var()?,
1656 is_side_effect: false,
1657 },
1658 _kind: std::marker::PhantomData,
1659 };
1660
1661 let folder_name = self
1662 .backend
1663 .borrow_mut()
1664 .current_node()
1665 .modpath()
1666 .replace("::", "__");
1667
1668 Some(
1669 self.emit_rust_stepv("🌼 Create persistent store dir", |ctx| {
1670 let path = path.claim(ctx);
1671 |rt| {
1672 let dir = rt.read(path).join(folder_name);
1673 fs_err::create_dir_all(&dir)?;
1674 Ok(dir)
1675 }
1676 }),
1677 )
1678 }
1679
1680 pub fn supports_persistent_dir(&mut self) -> bool {
1682 self.backend
1683 .borrow_mut()
1684 .persistent_dir_path_var()
1685 .is_some()
1686 }
1687}
1688
1689pub trait RuntimeVarDb {
1692 fn get_var(&mut self, var_name: &str) -> (Vec<u8>, bool) {
1693 self.try_get_var(var_name)
1694 .unwrap_or_else(|| panic!("db is missing var {}", var_name))
1695 }
1696
1697 fn try_get_var(&mut self, var_name: &str) -> Option<(Vec<u8>, bool)>;
1698 fn set_var(&mut self, var_name: &str, is_secret: bool, value: Vec<u8>);
1699}
1700
1701impl RuntimeVarDb for Box<dyn RuntimeVarDb> {
1702 fn try_get_var(&mut self, var_name: &str) -> Option<(Vec<u8>, bool)> {
1703 (**self).try_get_var(var_name)
1704 }
1705
1706 fn set_var(&mut self, var_name: &str, is_secret: bool, value: Vec<u8>) {
1707 (**self).set_var(var_name, is_secret, value)
1708 }
1709}
1710
1711pub mod steps {
1712 pub mod ado {
1713 use crate::node::ClaimedReadVar;
1714 use crate::node::ClaimedWriteVar;
1715 use crate::node::ReadVarBacking;
1716 use serde::Deserialize;
1717 use serde::Serialize;
1718 use std::borrow::Cow;
1719
1720 #[derive(Debug, Clone, Serialize, Deserialize)]
1726 pub struct AdoResourcesRepositoryId {
1727 pub(crate) repo_id: String,
1728 }
1729
1730 impl AdoResourcesRepositoryId {
1731 pub fn new_self() -> Self {
1737 Self {
1738 repo_id: "self".into(),
1739 }
1740 }
1741
1742 pub fn dangerous_get_raw_id(&self) -> &str {
1748 &self.repo_id
1749 }
1750
1751 pub fn dangerous_new(repo_id: &str) -> Self {
1757 Self {
1758 repo_id: repo_id.into(),
1759 }
1760 }
1761 }
1762
1763 #[derive(Clone, Debug, Serialize, Deserialize)]
1768 pub struct AdoRuntimeVar {
1769 is_secret: bool,
1770 ado_var: Cow<'static, str>,
1771 }
1772
1773 #[allow(non_upper_case_globals)]
1774 impl AdoRuntimeVar {
1775 pub const BUILD__SOURCE_BRANCH: AdoRuntimeVar =
1781 AdoRuntimeVar::new("build.SourceBranch");
1782
1783 pub const BUILD__BUILD_NUMBER: AdoRuntimeVar = AdoRuntimeVar::new("build.BuildNumber");
1785
1786 pub const SYSTEM__ACCESS_TOKEN: AdoRuntimeVar =
1788 AdoRuntimeVar::new_secret("System.AccessToken");
1789
1790 pub const SYSTEM__JOB_ATTEMPT: AdoRuntimeVar =
1792 AdoRuntimeVar::new_secret("System.JobAttempt");
1793 }
1794
1795 impl AdoRuntimeVar {
1796 const fn new(s: &'static str) -> Self {
1797 Self {
1798 is_secret: false,
1799 ado_var: Cow::Borrowed(s),
1800 }
1801 }
1802
1803 const fn new_secret(s: &'static str) -> Self {
1804 Self {
1805 is_secret: true,
1806 ado_var: Cow::Borrowed(s),
1807 }
1808 }
1809
1810 pub fn is_secret(&self) -> bool {
1812 self.is_secret
1813 }
1814
1815 pub fn as_raw_var_name(&self) -> String {
1817 self.ado_var.as_ref().into()
1818 }
1819
1820 pub fn dangerous_from_global(ado_var_name: impl AsRef<str>, is_secret: bool) -> Self {
1828 Self {
1829 is_secret,
1830 ado_var: ado_var_name.as_ref().to_owned().into(),
1831 }
1832 }
1833 }
1834
1835 pub fn new_ado_step_services(
1836 fresh_ado_var: &mut dyn FnMut() -> String,
1837 ) -> AdoStepServices<'_> {
1838 AdoStepServices {
1839 fresh_ado_var,
1840 ado_to_rust: Vec::new(),
1841 rust_to_ado: Vec::new(),
1842 }
1843 }
1844
1845 pub struct CompletedAdoStepServices {
1846 pub ado_to_rust: Vec<(String, String, bool)>,
1847 pub rust_to_ado: Vec<(String, String)>,
1848 }
1849
1850 impl CompletedAdoStepServices {
1851 pub fn from_ado_step_services(access: AdoStepServices<'_>) -> Self {
1852 let AdoStepServices {
1853 fresh_ado_var: _,
1854 ado_to_rust,
1855 rust_to_ado,
1856 } = access;
1857
1858 Self {
1859 ado_to_rust,
1860 rust_to_ado,
1861 }
1862 }
1863 }
1864
1865 pub struct AdoStepServices<'a> {
1866 fresh_ado_var: &'a mut dyn FnMut() -> String,
1867 ado_to_rust: Vec<(String, String, bool)>,
1868 rust_to_ado: Vec<(String, String)>,
1869 }
1870
1871 impl AdoStepServices<'_> {
1872 pub fn resolve_repository_id(&self, repo_id: AdoResourcesRepositoryId) -> String {
1875 repo_id.repo_id
1876 }
1877
1878 pub fn set_var(&mut self, var: ClaimedWriteVar<String>, from_ado_var: AdoRuntimeVar) {
1884 self.ado_to_rust.push((
1885 from_ado_var.ado_var.into(),
1886 var.backing_var,
1887 from_ado_var.is_secret,
1888 ))
1889 }
1890
1891 pub fn get_var(&mut self, var: ClaimedReadVar<String>) -> AdoRuntimeVar {
1893 let backing_var = if let ReadVarBacking::RuntimeVar {
1894 var,
1895 is_side_effect,
1896 } = &var.backing_var
1897 {
1898 assert!(!is_side_effect);
1899 var
1900 } else {
1901 todo!("support inline ado read vars")
1902 };
1903
1904 let new_ado_var_name = (self.fresh_ado_var)();
1905
1906 self.rust_to_ado
1907 .push((backing_var.clone(), new_ado_var_name.clone()));
1908 AdoRuntimeVar::dangerous_from_global(new_ado_var_name, false)
1909 }
1910 }
1911 }
1912
1913 pub mod github {
1914 use crate::node::ClaimVar;
1915 use crate::node::NodeCtx;
1916 use crate::node::ReadVar;
1917 use crate::node::ReadVarBacking;
1918 use crate::node::SideEffect;
1919 use crate::node::StepCtx;
1920 use crate::node::VarClaimed;
1921 use crate::node::VarNotClaimed;
1922 use crate::node::WriteVar;
1923 use std::collections::BTreeMap;
1924
1925 pub struct GhStepBuilder {
1926 display_name: String,
1927 cond: Option<ReadVar<bool>>,
1928 uses: String,
1929 with: Option<BTreeMap<String, GhParam>>,
1930 outputs: BTreeMap<String, Vec<WriteVar<String>>>,
1931 run_after: Vec<ReadVar<SideEffect>>,
1932 permissions: BTreeMap<GhPermission, GhPermissionValue>,
1933 }
1934
1935 impl GhStepBuilder {
1936 pub fn new(display_name: impl AsRef<str>, uses: impl AsRef<str>) -> Self {
1951 Self {
1952 display_name: display_name.as_ref().into(),
1953 cond: None,
1954 uses: uses.as_ref().into(),
1955 with: None,
1956 outputs: BTreeMap::new(),
1957 run_after: Vec::new(),
1958 permissions: BTreeMap::new(),
1959 }
1960 }
1961
1962 pub fn condition(mut self, cond: ReadVar<bool>) -> Self {
1969 self.cond = Some(cond);
1970 self
1971 }
1972
1973 pub fn with(mut self, k: impl AsRef<str>, v: impl Into<GhParam>) -> Self {
1999 self.with.get_or_insert_with(BTreeMap::new);
2000 if let Some(with) = &mut self.with {
2001 with.insert(k.as_ref().to_string(), v.into());
2002 }
2003 self
2004 }
2005
2006 pub fn output(mut self, k: impl AsRef<str>, v: WriteVar<String>) -> Self {
2015 self.outputs
2016 .entry(k.as_ref().to_string())
2017 .or_default()
2018 .push(v);
2019 self
2020 }
2021
2022 pub fn run_after(mut self, side_effect: ReadVar<SideEffect>) -> Self {
2024 self.run_after.push(side_effect);
2025 self
2026 }
2027
2028 pub fn requires_permission(
2033 mut self,
2034 perm: GhPermission,
2035 value: GhPermissionValue,
2036 ) -> Self {
2037 self.permissions.insert(perm, value);
2038 self
2039 }
2040
2041 #[track_caller]
2043 pub fn finish(self, ctx: &mut NodeCtx<'_>) -> ReadVar<SideEffect> {
2044 let (side_effect, claim_side_effect) = ctx.new_prefixed_var("auto_se");
2045 ctx.backend
2046 .borrow_mut()
2047 .on_claimed_runtime_var(&claim_side_effect.backing_var, false);
2048
2049 ctx.emit_gh_step_inner(
2050 self.display_name,
2051 self.cond,
2052 self.uses,
2053 self.with,
2054 self.outputs,
2055 self.run_after,
2056 self.permissions,
2057 );
2058
2059 side_effect
2060 }
2061 }
2062
2063 #[derive(Clone, Debug)]
2064 pub enum GhParam<C = VarNotClaimed> {
2065 Static(String),
2066 FloweyVar(ReadVar<String, C>),
2067 }
2068
2069 impl From<String> for GhParam {
2070 fn from(param: String) -> GhParam {
2071 GhParam::Static(param)
2072 }
2073 }
2074
2075 impl From<&str> for GhParam {
2076 fn from(param: &str) -> GhParam {
2077 GhParam::Static(param.to_string())
2078 }
2079 }
2080
2081 impl From<ReadVar<String>> for GhParam {
2082 fn from(param: ReadVar<String>) -> GhParam {
2083 GhParam::FloweyVar(param)
2084 }
2085 }
2086
2087 pub type ClaimedGhParam = GhParam<VarClaimed>;
2088
2089 impl ClaimVar for GhParam {
2090 type Claimed = ClaimedGhParam;
2091
2092 fn claim(self, ctx: &mut StepCtx<'_>) -> ClaimedGhParam {
2093 match self {
2094 GhParam::Static(s) => ClaimedGhParam::Static(s),
2095 GhParam::FloweyVar(var) => match &var.backing_var {
2096 ReadVarBacking::RuntimeVar { is_side_effect, .. } => {
2097 assert!(!is_side_effect);
2098 ClaimedGhParam::FloweyVar(var.claim(ctx))
2099 }
2100 ReadVarBacking::Inline(var) => ClaimedGhParam::Static(var.clone()),
2101 },
2102 }
2103 }
2104 }
2105
2106 #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
2111 pub enum GhPermissionValue {
2112 Read,
2113 Write,
2114 None,
2115 }
2116
2117 #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
2123 pub enum GhPermission {
2124 Actions,
2125 Attestations,
2126 Checks,
2127 Contents,
2128 Deployments,
2129 Discussions,
2130 IdToken,
2131 Issues,
2132 Packages,
2133 Pages,
2134 PullRequests,
2135 RepositoryProjects,
2136 SecurityEvents,
2137 Statuses,
2138 }
2139 }
2140
2141 pub mod rust {
2142 use crate::node::ClaimedWriteVar;
2143 use crate::node::FlowArch;
2144 use crate::node::FlowBackend;
2145 use crate::node::FlowPlatform;
2146 use crate::node::ReadVarValue;
2147 use crate::node::RuntimeVarDb;
2148 use serde::Serialize;
2149 use serde::de::DeserializeOwned;
2150
2151 pub fn new_rust_runtime_services(
2152 runtime_var_db: &mut dyn RuntimeVarDb,
2153 backend: FlowBackend,
2154 platform: FlowPlatform,
2155 arch: FlowArch,
2156 ) -> RustRuntimeServices<'_> {
2157 RustRuntimeServices {
2158 runtime_var_db,
2159 backend,
2160 platform,
2161 arch,
2162 has_read_secret: false,
2163 }
2164 }
2165
2166 pub struct RustRuntimeServices<'a> {
2167 runtime_var_db: &'a mut dyn RuntimeVarDb,
2168 backend: FlowBackend,
2169 platform: FlowPlatform,
2170 arch: FlowArch,
2171 has_read_secret: bool,
2172 }
2173
2174 impl RustRuntimeServices<'_> {
2175 pub fn backend(&self) -> FlowBackend {
2178 self.backend
2179 }
2180
2181 pub fn platform(&self) -> FlowPlatform {
2184 self.platform
2185 }
2186
2187 pub fn arch(&self) -> FlowArch {
2189 self.arch
2190 }
2191
2192 pub fn write<T>(&mut self, var: ClaimedWriteVar<T>, val: &T)
2200 where
2201 T: Serialize + DeserializeOwned,
2202 {
2203 self.write_maybe_secret(var, val, self.has_read_secret)
2204 }
2205
2206 pub fn write_secret<T>(&mut self, var: ClaimedWriteVar<T>, val: &T)
2212 where
2213 T: Serialize + DeserializeOwned,
2214 {
2215 self.write_maybe_secret(var, val, true)
2216 }
2217
2218 pub fn write_not_secret<T>(&mut self, var: ClaimedWriteVar<T>, val: &T)
2225 where
2226 T: Serialize + DeserializeOwned,
2227 {
2228 self.write_maybe_secret(var, val, false)
2229 }
2230
2231 fn write_maybe_secret<T>(&mut self, var: ClaimedWriteVar<T>, val: &T, is_secret: bool)
2232 where
2233 T: Serialize + DeserializeOwned,
2234 {
2235 let val = if var.is_side_effect {
2236 b"null".to_vec()
2237 } else {
2238 serde_json::to_vec(val).expect("improve this error path")
2239 };
2240 self.runtime_var_db
2241 .set_var(&var.backing_var, is_secret, val);
2242 }
2243
2244 pub fn write_all<T>(
2245 &mut self,
2246 vars: impl IntoIterator<Item = ClaimedWriteVar<T>>,
2247 val: &T,
2248 ) where
2249 T: Serialize + DeserializeOwned,
2250 {
2251 for var in vars {
2252 self.write(var, val)
2253 }
2254 }
2255
2256 pub fn read<T: ReadVarValue>(&mut self, var: T) -> T::Value {
2257 var.read_value(self)
2258 }
2259
2260 pub(crate) fn get_var(&mut self, var: &str, is_side_effect: bool) -> Vec<u8> {
2261 let (v, is_secret) = self.runtime_var_db.get_var(var);
2262 self.has_read_secret |= is_secret && !is_side_effect;
2263 v
2264 }
2265
2266 pub fn dangerous_gh_set_global_env_var(
2273 &mut self,
2274 var: String,
2275 gh_env_var: String,
2276 ) -> anyhow::Result<()> {
2277 if !matches!(self.backend, FlowBackend::Github) {
2278 return Err(anyhow::anyhow!(
2279 "dangerous_set_gh_env_var can only be used on GitHub Actions"
2280 ));
2281 }
2282
2283 let gh_env_file_path = std::env::var("GITHUB_ENV")?;
2284 let mut gh_env_file = fs_err::OpenOptions::new()
2285 .append(true)
2286 .open(gh_env_file_path)?;
2287 let gh_env_var_assignment = format!(
2288 r#"{}<<EOF
2289{}
2290EOF
2291"#,
2292 gh_env_var, var
2293 );
2294 std::io::Write::write_all(&mut gh_env_file, gh_env_var_assignment.as_bytes())?;
2295
2296 Ok(())
2297 }
2298 }
2299 }
2300}
2301
2302pub trait FlowNodeBase {
2307 type Request: Serialize + DeserializeOwned;
2308
2309 fn imports(&mut self, ctx: &mut ImportCtx<'_>);
2310 fn emit(&mut self, requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()>;
2311
2312 fn i_know_what_im_doing_with_this_manual_impl(&mut self);
2318}
2319
2320pub mod erased {
2321 use crate::node::FlowNodeBase;
2322 use crate::node::NodeCtx;
2323 use crate::node::user_facing::*;
2324
2325 pub struct ErasedNode<N: FlowNodeBase>(pub N);
2326
2327 impl<N: FlowNodeBase> ErasedNode<N> {
2328 pub fn from_node(node: N) -> Self {
2329 Self(node)
2330 }
2331 }
2332
2333 impl<N> FlowNodeBase for ErasedNode<N>
2334 where
2335 N: FlowNodeBase,
2336 {
2337 type Request = Box<[u8]>;
2339
2340 fn imports(&mut self, ctx: &mut ImportCtx<'_>) {
2341 self.0.imports(ctx)
2342 }
2343
2344 fn emit(&mut self, requests: Vec<Box<[u8]>>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
2345 let mut converted_requests = Vec::new();
2346 for req in requests {
2347 converted_requests.push(serde_json::from_slice(&req)?)
2348 }
2349
2350 self.0.emit(converted_requests, ctx)
2351 }
2352
2353 fn i_know_what_im_doing_with_this_manual_impl(&mut self) {}
2354 }
2355}
2356
2357#[derive(Clone, Copy, PartialEq, Eq, Hash)]
2359pub struct NodeHandle(std::any::TypeId);
2360
2361impl Ord for NodeHandle {
2362 fn cmp(&self, other: &Self) -> std::cmp::Ordering {
2363 self.modpath().cmp(other.modpath())
2364 }
2365}
2366
2367impl PartialOrd for NodeHandle {
2368 fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
2369 Some(self.cmp(other))
2370 }
2371}
2372
2373impl std::fmt::Debug for NodeHandle {
2374 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2375 std::fmt::Debug::fmt(&self.try_modpath(), f)
2376 }
2377}
2378
2379impl NodeHandle {
2380 pub fn from_type<N: FlowNodeBase + 'static>() -> NodeHandle {
2381 NodeHandle(std::any::TypeId::of::<N>())
2382 }
2383
2384 pub fn from_modpath(modpath: &str) -> NodeHandle {
2385 node_luts::erased_node_by_modpath().get(modpath).unwrap().0
2386 }
2387
2388 pub fn try_from_modpath(modpath: &str) -> Option<NodeHandle> {
2389 node_luts::erased_node_by_modpath()
2390 .get(modpath)
2391 .map(|(s, _)| *s)
2392 }
2393
2394 pub fn new_erased_node(&self) -> Box<dyn FlowNodeBase<Request = Box<[u8]>>> {
2395 let ctor = node_luts::erased_node_by_typeid().get(self).unwrap();
2396 ctor()
2397 }
2398
2399 pub fn modpath(&self) -> &'static str {
2400 node_luts::modpath_by_node_typeid().get(self).unwrap()
2401 }
2402
2403 pub fn try_modpath(&self) -> Option<&'static str> {
2404 node_luts::modpath_by_node_typeid().get(self).cloned()
2405 }
2406
2407 pub fn dummy() -> NodeHandle {
2410 NodeHandle(std::any::TypeId::of::<()>())
2411 }
2412}
2413
2414pub fn list_all_registered_nodes() -> impl Iterator<Item = NodeHandle> {
2415 node_luts::modpath_by_node_typeid().keys().cloned()
2416}
2417
2418mod node_luts {
2433 use super::FlowNodeBase;
2434 use super::NodeHandle;
2435 use std::collections::HashMap;
2436 use std::sync::OnceLock;
2437
2438 pub(super) fn modpath_by_node_typeid() -> &'static HashMap<NodeHandle, &'static str> {
2439 static TYPEID_TO_MODPATH: OnceLock<HashMap<NodeHandle, &'static str>> = OnceLock::new();
2440
2441 TYPEID_TO_MODPATH.get_or_init(|| {
2442 let mut lookup = HashMap::new();
2443 for crate::node::private::FlowNodeMeta {
2444 module_path,
2445 ctor: _,
2446 typeid,
2447 } in crate::node::private::FLOW_NODES
2448 {
2449 let existing = lookup.insert(
2450 NodeHandle(*typeid),
2451 module_path
2452 .strip_suffix("::_only_one_call_to_flowey_node_per_module")
2453 .unwrap(),
2454 );
2455 assert!(existing.is_none())
2458 }
2459
2460 lookup
2461 })
2462 }
2463
2464 pub(super) fn erased_node_by_typeid()
2465 -> &'static HashMap<NodeHandle, fn() -> Box<dyn FlowNodeBase<Request = Box<[u8]>>>> {
2466 static LOOKUP: OnceLock<
2467 HashMap<NodeHandle, fn() -> Box<dyn FlowNodeBase<Request = Box<[u8]>>>>,
2468 > = OnceLock::new();
2469
2470 LOOKUP.get_or_init(|| {
2471 let mut lookup = HashMap::new();
2472 for crate::node::private::FlowNodeMeta {
2473 module_path: _,
2474 ctor,
2475 typeid,
2476 } in crate::node::private::FLOW_NODES
2477 {
2478 let existing = lookup.insert(NodeHandle(*typeid), *ctor);
2479 assert!(existing.is_none())
2482 }
2483
2484 lookup
2485 })
2486 }
2487
2488 pub(super) fn erased_node_by_modpath() -> &'static HashMap<
2489 &'static str,
2490 (
2491 NodeHandle,
2492 fn() -> Box<dyn FlowNodeBase<Request = Box<[u8]>>>,
2493 ),
2494 > {
2495 static MODPATH_LOOKUP: OnceLock<
2496 HashMap<
2497 &'static str,
2498 (
2499 NodeHandle,
2500 fn() -> Box<dyn FlowNodeBase<Request = Box<[u8]>>>,
2501 ),
2502 >,
2503 > = OnceLock::new();
2504
2505 MODPATH_LOOKUP.get_or_init(|| {
2506 let mut lookup = HashMap::new();
2507 for crate::node::private::FlowNodeMeta { module_path, ctor, typeid } in crate::node::private::FLOW_NODES {
2508 let existing = lookup.insert(module_path.strip_suffix("::_only_one_call_to_flowey_node_per_module").unwrap(), (NodeHandle(*typeid), *ctor));
2509 if existing.is_some() {
2510 panic!("conflicting node registrations at {module_path}! please ensure there is a single node per module!")
2511 }
2512 }
2513 lookup
2514 })
2515 }
2516}
2517
2518#[doc(hidden)]
2519pub mod private {
2520 pub use linkme;
2521
2522 pub struct FlowNodeMeta {
2523 pub module_path: &'static str,
2524 pub ctor: fn() -> Box<dyn super::FlowNodeBase<Request = Box<[u8]>>>,
2525 pub typeid: std::any::TypeId,
2526 }
2527
2528 #[linkme::distributed_slice]
2529 pub static FLOW_NODES: [FlowNodeMeta] = [..];
2530
2531 #[expect(unsafe_code)]
2533 #[linkme::distributed_slice(FLOW_NODES)]
2534 static DUMMY_FLOW_NODE: FlowNodeMeta = FlowNodeMeta {
2535 module_path: "<dummy>::_only_one_call_to_flowey_node_per_module",
2536 ctor: || unreachable!(),
2537 typeid: std::any::TypeId::of::<()>(),
2538 };
2539}
2540
2541#[doc(hidden)]
2542#[macro_export]
2543macro_rules! new_flow_node_base {
2544 (struct Node) => {
2545 #[non_exhaustive]
2547 pub struct Node;
2548
2549 mod _only_one_call_to_flowey_node_per_module {
2550 const _: () = {
2551 use $crate::node::private::linkme;
2552
2553 fn new_erased() -> Box<dyn $crate::node::FlowNodeBase<Request = Box<[u8]>>> {
2554 Box::new($crate::node::erased::ErasedNode(super::Node))
2555 }
2556
2557 #[linkme::distributed_slice($crate::node::private::FLOW_NODES)]
2558 #[linkme(crate = linkme)]
2559 static FLOW_NODE: $crate::node::private::FlowNodeMeta =
2560 $crate::node::private::FlowNodeMeta {
2561 module_path: module_path!(),
2562 ctor: new_erased,
2563 typeid: std::any::TypeId::of::<super::Node>(),
2564 };
2565 };
2566 }
2567 };
2568}
2569
2570pub trait FlowNode {
2657 type Request: Serialize + DeserializeOwned;
2661
2662 fn imports(ctx: &mut ImportCtx<'_>);
2674
2675 fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()>;
2678}
2679
2680#[macro_export]
2681macro_rules! new_flow_node {
2682 (struct Node) => {
2683 $crate::new_flow_node_base!(struct Node);
2684
2685 impl $crate::node::FlowNodeBase for Node
2686 where
2687 Node: FlowNode,
2688 {
2689 type Request = <Node as FlowNode>::Request;
2690
2691 fn imports(&mut self, dep: &mut $crate::node::ImportCtx<'_>) {
2692 <Node as FlowNode>::imports(dep)
2693 }
2694
2695 fn emit(
2696 &mut self,
2697 requests: Vec<Self::Request>,
2698 ctx: &mut $crate::node::NodeCtx<'_>,
2699 ) -> anyhow::Result<()> {
2700 <Node as FlowNode>::emit(requests, ctx)
2701 }
2702
2703 fn i_know_what_im_doing_with_this_manual_impl(&mut self) {}
2704 }
2705 };
2706}
2707
2708pub trait SimpleFlowNode {
2729 type Request: Serialize + DeserializeOwned;
2730
2731 fn imports(ctx: &mut ImportCtx<'_>);
2743
2744 fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()>;
2746}
2747
2748#[macro_export]
2749macro_rules! new_simple_flow_node {
2750 (struct Node) => {
2751 $crate::new_flow_node_base!(struct Node);
2752
2753 impl $crate::node::FlowNodeBase for Node
2754 where
2755 Node: $crate::node::SimpleFlowNode,
2756 {
2757 type Request = <Node as $crate::node::SimpleFlowNode>::Request;
2758
2759 fn imports(&mut self, dep: &mut $crate::node::ImportCtx<'_>) {
2760 <Node as $crate::node::SimpleFlowNode>::imports(dep)
2761 }
2762
2763 fn emit(&mut self, requests: Vec<Self::Request>, ctx: &mut $crate::node::NodeCtx<'_>) -> anyhow::Result<()> {
2764 for req in requests {
2765 <Node as $crate::node::SimpleFlowNode>::process_request(req, ctx)?
2766 }
2767
2768 Ok(())
2769 }
2770
2771 fn i_know_what_im_doing_with_this_manual_impl(&mut self) {}
2772 }
2773 };
2774}
2775
2776pub trait IntoRequest {
2784 type Node: FlowNodeBase;
2785 fn into_request(self) -> <Self::Node as FlowNodeBase>::Request;
2786
2787 #[doc(hidden)]
2790 #[expect(nonstandard_style)]
2791 fn do_not_manually_impl_this_trait__use_the_flowey_request_macro_instead(&mut self);
2792}
2793
2794#[doc(hidden)]
2795#[macro_export]
2796macro_rules! __flowey_request_inner {
2797 (@emit_struct [$req:ident]
2801 $(#[$a:meta])*
2802 $variant:ident($($tt:tt)*),
2803 $($rest:tt)*
2804 ) => {
2805 $(#[$a])*
2806 #[derive($crate::reexports::Serialize, $crate::reexports::Deserialize)]
2807 pub struct $variant($($tt)*);
2808
2809 impl IntoRequest for $variant {
2810 type Node = Node;
2811 fn into_request(self) -> $req {
2812 $req::$variant(self)
2813 }
2814 fn do_not_manually_impl_this_trait__use_the_flowey_request_macro_instead(&mut self) {}
2815 }
2816
2817 $crate::__flowey_request_inner!(@emit_struct [$req] $($rest)*);
2818 };
2819 (@emit_struct [$req:ident]
2820 $(#[$a:meta])*
2821 $variant:ident { $($tt:tt)* },
2822 $($rest:tt)*
2823 ) => {
2824 $(#[$a])*
2825 #[derive($crate::reexports::Serialize, $crate::reexports::Deserialize)]
2826 pub struct $variant {
2827 $($tt)*
2828 }
2829
2830 impl IntoRequest for $variant {
2831 type Node = Node;
2832 fn into_request(self) -> $req {
2833 $req::$variant(self)
2834 }
2835 fn do_not_manually_impl_this_trait__use_the_flowey_request_macro_instead(&mut self) {}
2836 }
2837
2838 $crate::__flowey_request_inner!(@emit_struct [$req] $($rest)*);
2839 };
2840 (@emit_struct [$req:ident]
2841 $(#[$a:meta])*
2842 $variant:ident,
2843 $($rest:tt)*
2844 ) => {
2845 $(#[$a])*
2846 #[derive(Serialize, Deserialize)]
2847 pub struct $variant;
2848
2849 impl IntoRequest for $variant {
2850 type Node = Node;
2851 fn into_request(self) -> $req {
2852 $req::$variant(self)
2853 }
2854 fn do_not_manually_impl_this_trait__use_the_flowey_request_macro_instead(&mut self) {}
2855 }
2856
2857 $crate::__flowey_request_inner!(@emit_struct [$req] $($rest)*);
2858 };
2859 (@emit_struct [$req:ident]
2860 ) => {};
2861
2862 (@emit_req_enum [$req:ident($($root_a:meta,)*), $($prev:ident[$($prev_a:meta,)*])*]
2866 $(#[$a:meta])*
2867 $variant:ident($($tt:tt)*),
2868 $($rest:tt)*
2869 ) => {
2870 $crate::__flowey_request_inner!(@emit_req_enum [$req($($root_a,)*), $($prev[$($prev_a,)*])* $variant[$($a,)*]] $($rest)*);
2871 };
2872 (@emit_req_enum [$req:ident($($root_a:meta,)*), $($prev:ident[$($prev_a:meta,)*])*]
2873 $(#[$a:meta])*
2874 $variant:ident { $($tt:tt)* },
2875 $($rest:tt)*
2876 ) => {
2877 $crate::__flowey_request_inner!(@emit_req_enum [$req($($root_a,)*), $($prev[$($prev_a,)*])* $variant[$($a,)*]] $($rest)*);
2878 };
2879 (@emit_req_enum [$req:ident($($root_a:meta,)*), $($prev:ident[$($prev_a:meta,)*])*]
2880 $(#[$a:meta])*
2881 $variant:ident,
2882 $($rest:tt)*
2883 ) => {
2884 $crate::__flowey_request_inner!(@emit_req_enum [$req($($root_a,)*), $($prev[$($prev_a,)*])* $variant[$($a,)*]] $($rest)*);
2885 };
2886 (@emit_req_enum [$req:ident($($root_a:meta,)*), $($prev:ident[$($prev_a:meta,)*])*]
2887 ) => {
2888 #[derive(Serialize, Deserialize)]
2889 pub enum $req {$(
2890 $(#[$prev_a])*
2891 $prev(self::req::$prev),
2892 )*}
2893
2894 impl IntoRequest for $req {
2895 type Node = Node;
2896 fn into_request(self) -> $req {
2897 self
2898 }
2899 fn do_not_manually_impl_this_trait__use_the_flowey_request_macro_instead(&mut self) {}
2900 }
2901 };
2902}
2903
2904#[macro_export]
2952macro_rules! flowey_request {
2953 (
2954 $(#[$root_a:meta])*
2955 pub enum_struct $req:ident {
2956 $($tt:tt)*
2957 }
2958 ) => {
2959 $crate::__flowey_request_inner!(@emit_req_enum [$req($($root_a,)*),] $($tt)*);
2960 pub mod req {
2961 use super::*;
2962 $crate::__flowey_request_inner!(@emit_struct [$req] $($tt)*);
2963 }
2964 };
2965
2966 (
2967 $(#[$a:meta])*
2968 pub enum $req:ident {
2969 $($tt:tt)*
2970 }
2971 ) => {
2972 $(#[$a])*
2973 #[derive($crate::reexports::Serialize, $crate::reexports::Deserialize)]
2974 pub enum $req {
2975 $($tt)*
2976 }
2977
2978 impl $crate::node::IntoRequest for $req {
2979 type Node = Node;
2980 fn into_request(self) -> $req {
2981 self
2982 }
2983 fn do_not_manually_impl_this_trait__use_the_flowey_request_macro_instead(&mut self) {}
2984 }
2985 };
2986
2987 (
2988 $(#[$a:meta])*
2989 pub struct $req:ident {
2990 $($tt:tt)*
2991 }
2992 ) => {
2993 $(#[$a])*
2994 #[derive($crate::reexports::Serialize, $crate::reexports::Deserialize)]
2995 pub struct $req {
2996 $($tt)*
2997 }
2998
2999 impl $crate::node::IntoRequest for $req {
3000 type Node = Node;
3001 fn into_request(self) -> $req {
3002 self
3003 }
3004 fn do_not_manually_impl_this_trait__use_the_flowey_request_macro_instead(&mut self) {}
3005 }
3006 };
3007
3008 (
3009 $(#[$a:meta])*
3010 pub struct $req:ident($($tt:tt)*);
3011 ) => {
3012 $(#[$a])*
3013 #[derive($crate::reexports::Serialize, $crate::reexports::Deserialize)]
3014 pub struct $req($($tt)*);
3015
3016 impl $crate::node::IntoRequest for $req {
3017 type Node = Node;
3018 fn into_request(self) -> $req {
3019 self
3020 }
3021 fn do_not_manually_impl_this_trait__use_the_flowey_request_macro_instead(&mut self) {}
3022 }
3023 };
3024}