@cascade-flow/runner 0.2.6 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAMA,OAAO,EAA0C,KAAK,UAAU,EAAyB,KAAK,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAG1J;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CACtC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,cAAc,CAAC,CA0BzB;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,aAAa,SAA4B,GACxC,OAAO,CAAC,qBAAqB,EAAE,CAAC,CA+ElC;AA4CD;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,IAAI,SAAwB,GAC3B,OAAO,CAAC,UAAU,EAAE,CAAC,CAkFvB"}
1
+ {"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAMA,OAAO,EAA0C,KAAK,UAAU,EAAyB,KAAK,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAG1J;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CACtC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,cAAc,CAAC,CA0BzB;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,aAAa,SAA4B,GACxC,OAAO,CAAC,qBAAqB,EAAE,CAAC,CA+ElC;AA4CD;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,IAAI,SAAwB,GAC3B,OAAO,CAAC,UAAU,EAAE,CAAC,CAmFvB"}
package/dist/index.js CHANGED
@@ -33,6 +33,7 @@ function getFailurePath(dir, requestId) {
33
33
  var EMBEDDED_STEP_EXECUTOR = `
34
34
  import { pathToFileURL } from "node:url";
35
35
  import { join } from "node:path";
36
+ import { AsyncLocalStorage } from "async_hooks";
36
37
 
37
38
  function serializeError(err) {
38
39
  if (err instanceof Error) {
@@ -41,6 +42,9 @@ function serializeError(err) {
41
42
  return { message: String(err), name: "Error" };
42
43
  }
43
44
 
45
+ // AsyncLocalStorage for checkpoint context
46
+ const checkpointStorage = new AsyncLocalStorage();
47
+
44
48
  function createCheckpointFunction(checkpointDir) {
45
49
  const checkpointSequences = new Map();
46
50
 
@@ -72,9 +76,16 @@ function createCheckpointFunction(checkpointDir) {
72
76
  return JSON.parse(response.data);
73
77
  }
74
78
 
75
- // Cache miss: execute function
79
+ // Cache miss: execute function with parent injection
76
80
  try {
77
- const result = await fn();
81
+ const ctx = checkpointStorage.getStore();
82
+ let result = await fn();
83
+
84
+ // Inject parent checkpoint info if in a scope
85
+ if (ctx?.parent && typeof result === "object" && result !== null) {
86
+ result = { _parentCheckpoint: ctx.parent, ...result };
87
+ }
88
+
78
89
  await Bun.write(
79
90
  join(checkpointDir, "result-" + requestId + ".json"),
80
91
  JSON.stringify({ requestId, data: JSON.stringify(result) })
@@ -96,6 +107,11 @@ function createCheckpointFunction(checkpointDir) {
96
107
  };
97
108
  }
98
109
 
110
+ // Run with checkpoint context
111
+ function runWithCheckpoint(checkpointFn, fn) {
112
+ return checkpointStorage.run({ checkpoint: checkpointFn }, fn);
113
+ }
114
+
99
115
  async function main() {
100
116
  try {
101
117
  const inputFile = process.env.CF_STEP_INPUT_FILE;
@@ -123,7 +139,10 @@ async function main() {
123
139
  throw new Error("Invalid step module at " + stepPath);
124
140
  }
125
141
 
126
- const result = await stepDef.fn({ dependencies, ctx: reconstructedCtx });
142
+ // Execute step with checkpoint context
143
+ const result = await runWithCheckpoint(checkpoint, () =>
144
+ stepDef.fn({ dependencies, ctx: reconstructedCtx })
145
+ );
127
146
  await Bun.write(outputFile, JSON.stringify(result, null, 2));
128
147
  process.exit(0);
129
148
  } catch (error) {
@@ -12859,10 +12878,34 @@ config(en_default());
12859
12878
  var workflowConfigSchema = exports_external.object({
12860
12879
  name: exports_external.string().min(1, "Workflow name cannot be empty")
12861
12880
  });
12881
+ var backoffConfigSchema = exports_external.discriminatedUnion("type", [
12882
+ exports_external.object({
12883
+ type: exports_external.literal("constant"),
12884
+ delayMs: exports_external.number().int().nonnegative()
12885
+ }),
12886
+ exports_external.object({
12887
+ type: exports_external.literal("exponential"),
12888
+ initialDelayMs: exports_external.number().int().nonnegative(),
12889
+ maxDelayMs: exports_external.number().int().positive(),
12890
+ multiplier: exports_external.number().positive().optional()
12891
+ }),
12892
+ exports_external.object({
12893
+ type: exports_external.literal("linear"),
12894
+ initialDelayMs: exports_external.number().int().nonnegative(),
12895
+ incrementMs: exports_external.number().int().nonnegative(),
12896
+ maxDelayMs: exports_external.number().int().positive()
12897
+ })
12898
+ ]);
12899
+ var retryPolicySchema = exports_external.object({
12900
+ maxAttempts: exports_external.number().int().min(1),
12901
+ backoff: backoffConfigSchema
12902
+ });
12903
+ var retryPoliciesSchema = exports_external.array(retryPolicySchema).max(10, "Cannot have more than 10 retry policies").refine((policies) => policies.reduce((sum, p) => sum + p.maxAttempts, 0) <= 100, "Total attempts across all policies cannot exceed 100");
12862
12904
  var stepConfigSchema = exports_external.object({
12863
12905
  name: exports_external.string().optional(),
12864
12906
  dependencies: exports_external.any().optional(),
12865
12907
  exportOutput: exports_external.boolean().optional(),
12908
+ retry: retryPoliciesSchema.optional(),
12866
12909
  maxRetries: exports_external.number().int().nonnegative().max(100, "maxRetries cannot exceed 100").optional(),
12867
12910
  retryDelayMs: exports_external.number().int().nonnegative().max(3600000, "retryDelayMs cannot exceed 1 hour").optional(),
12868
12911
  timeoutMs: exports_external.number().int().positive().max(3600000, "timeoutMs cannot exceed 1 hour").optional(),
@@ -12988,6 +13031,7 @@ async function discoverSteps(root = path.resolve("steps")) {
12988
13031
  dir,
12989
13032
  fn: mod.step.fn,
12990
13033
  exportOutput: mod.step.exportOutput,
13034
+ retry: mod.step.retry,
12991
13035
  maxRetries: mod.step.maxRetries,
12992
13036
  retryDelayMs: mod.step.retryDelayMs,
12993
13037
  timeoutMs: mod.step.timeoutMs,
@@ -13163,4 +13207,4 @@ export {
13163
13207
  calculateWorkflowHash
13164
13208
  };
13165
13209
 
13166
- //# debugId=922C5B57E7B7118364756E2164756E21
13210
+ //# debugId=4438863A7AB7D73964756E2164756E21