fyflow-orchestration 0.8.0 → 0.9.0

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.
@@ -143,7 +143,7 @@ import {
143
143
  violatedRules,
144
144
  witness,
145
145
  workersOf
146
- } from "./chunks/chunk-EUU44PHD.js";
146
+ } from "./chunks/chunk-3U4UZC34.js";
147
147
 
148
148
  // src/definition/assist.ts
149
149
  var TYPES = ["object", "array", "string", "number", "integer", "boolean", "null"];
@@ -1,4 +1,5 @@
1
1
  import {
2
+ Accumulator,
2
3
  BUILT_IN_NODE_TYPES,
3
4
  ConfigRefused,
4
5
  Driver,
@@ -22,10 +23,9 @@ import {
22
23
  resolveRegistry,
23
24
  resumeRefusal,
24
25
  retryPolicyProblem,
25
- step,
26
26
  validateDefinition,
27
27
  workersOf
28
- } from "../chunks/chunk-EUU44PHD.js";
28
+ } from "../chunks/chunk-3U4UZC34.js";
29
29
 
30
30
  // src/scheduler/bootstrap.ts
31
31
  import { WorkerManager } from "fyflow-scheduler";
@@ -281,14 +281,50 @@ function createRuntime(document, code = {}, options = {}) {
281
281
  const done = new Promise((resolve) => {
282
282
  settle = resolve;
283
283
  });
284
- let state = emptyState();
284
+ const acc = Accumulator.load(emptyState());
285
+ let cached = null;
286
+ const frozen = /* @__PURE__ */ new WeakSet();
285
287
  let settled = false;
286
288
  let seed = from === null ? null : from.events;
289
+ const own = (input) => {
290
+ if (input.kind !== "outcome" && input.kind !== "resolution") return input;
291
+ const r = input.record;
292
+ return typeof r.result === "object" && r.result !== null ? { kind: input.kind, record: structuredClone(r) } : input;
293
+ };
294
+ const take = (input) => {
295
+ if (acc.apply(own(input))) cached = null;
296
+ };
297
+ const catchUp = () => {
298
+ if (seed === null) return;
299
+ for (const stored of seed) take(stored);
300
+ seed = null;
301
+ };
302
+ const freezeDeep = (root) => {
303
+ const stack = [root];
304
+ while (stack.length > 0) {
305
+ const v = stack.pop();
306
+ if (typeof v !== "object" || v === null || frozen.has(v)) continue;
307
+ frozen.add(v);
308
+ if (ArrayBuffer.isView(v)) continue;
309
+ if (v instanceof Map) for (const [k, x] of v) stack.push(k, x);
310
+ else if (v instanceof Set) for (const x of v) stack.push(x);
311
+ for (const k of Reflect.ownKeys(v)) {
312
+ const d = Object.getOwnPropertyDescriptor(v, k);
313
+ if (d !== void 0 && "value" in d) stack.push(d.value);
314
+ }
315
+ Object.freeze(v);
316
+ }
317
+ return root;
318
+ };
319
+ const current = () => {
320
+ catchUp();
321
+ return cached ??= freezeDeep(acc.materialise());
322
+ };
287
323
  const settleIfTerminal = () => {
288
- if (settled || !isTerminal(state)) return;
324
+ if (settled || !isTerminal({ outcome: acc.outcomeNow() })) return;
289
325
  settled = true;
290
- if (state.outcome === "interrupted" && stopping.size > 0) {
291
- const at = state;
326
+ const at = current();
327
+ if (at.outcome === "interrupted" && stopping.size > 0) {
292
328
  const fin = () => {
293
329
  settle(at);
294
330
  router.release(runId);
@@ -296,7 +332,7 @@ function createRuntime(document, code = {}, options = {}) {
296
332
  void Promise.allSettled([...stopping]).then(fin);
297
333
  return;
298
334
  }
299
- settle(state);
335
+ settle(at);
300
336
  router.release(runId);
301
337
  };
302
338
  const view = router.forRun(runId);
@@ -333,11 +369,8 @@ function createRuntime(document, code = {}, options = {}) {
333
369
  // of a run from its first, and it is the well-formed wrong answer the first time a driver's
334
370
  // sequence does not start at this callback's first call.
335
371
  onFoldInput: (input, seq) => {
336
- if (seed !== null) {
337
- for (const stored of seed) state = step(state, stored);
338
- seed = null;
339
- }
340
- state = step(state, input);
372
+ catchUp();
373
+ take(input);
341
374
  queueMicrotask(settleIfTerminal);
342
375
  startOptions.onFoldInput?.(input, seq);
343
376
  },
@@ -361,7 +394,22 @@ function createRuntime(document, code = {}, options = {}) {
361
394
  router.release(runId);
362
395
  throw e;
363
396
  }
364
- return { driver, done, header: driver.checkpoint().header, stop: (stopOptions) => driver.stop(stopOptions) };
397
+ return {
398
+ driver,
399
+ done,
400
+ header: driver.checkpoint().header,
401
+ stop: (stopOptions) => driver.stop(stopOptions),
402
+ state: current,
403
+ outcome: () => {
404
+ catchUp();
405
+ return acc.outcomeNow();
406
+ },
407
+ node: (taskId) => {
408
+ catchUp();
409
+ const entry = acc.entry(taskId);
410
+ return entry === void 0 ? null : freezeDeep(entry);
411
+ }
412
+ };
365
413
  }
366
414
  }
367
415
  function settlementRouter(scheduler) {