@orkestrel/workflow 0.0.16 → 0.0.18

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.
@@ -2,11 +2,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let _src_core = require("../core/index.cjs");
3
3
  //#region src/server/NodeScheduler.ts
4
4
  /**
5
- * The Node {@link SchedulerInterface} — the server-native cooperative-yield backend.
5
+ * Implements the Node {@link SchedulerInterface} — the server-native cooperative-yield backend
6
+ * whose `yield` waits on `setImmediate` and whose abort rejects with the caller's own reason.
7
+ * A `priority` hint is accepted and does nothing, because Node has no priority primitive.
6
8
  *
7
9
  * @remarks
8
10
  * - **`yield` is a `setImmediate` host-turn.** `yield()` waits on `setImmediate`, the
9
- * canonical Node "give the host a turn" — it runs AFTER the current operation and
11
+ * canonical Node "give the host a turn" — it runs after the current operation and
10
12
  * any pending I/O callbacks, so the event loop genuinely regains control before
11
13
  * resuming (unlike a microtask, which drains within the current task). `delay(ms)`
12
14
  * waits on a real `setTimeout`.
@@ -14,7 +16,7 @@ let _src_core = require("../core/index.cjs");
14
16
  * `signal.reason` exactly. The shared `scheduleHost` lifecycle links an owned composite
15
17
  * before arming either Node handle, so caller signal method mutation is harmless and the
16
18
  * first completion, abort, or setup failure owns settlement and cleanup. It deliberately
17
- * does NOT use `node:timers/promises`, whose `{ signal }` option replaces the caller reason
19
+ * does not use `node:timers/promises`, whose `{ signal }` option replaces the caller reason
18
20
  * with a Node `AbortError` (`code: 'ABORT_ERR'`).
19
21
  * - **Priority is accepted but a no-op.** Node has no priority primitive (no equivalent
20
22
  * of the browser's `scheduler.postTask` priorities), so `options.priority` is accepted
@@ -36,24 +38,23 @@ let _src_core = require("../core/index.cjs");
36
38
  */
37
39
  var NodeScheduler = class {
38
40
  /**
39
- * Yield control back to the event loop via `setImmediate` so pending I/O and timers
40
- * can run, then resume; abort rejects with `signal.reason`.
41
+ * Yields control back to the event loop through `setImmediate` so pending I/O and timers
42
+ * can run, then resumes; abort rejects with `signal.reason`.
41
43
  */
42
44
  yield(options) {
43
45
  return this.#immediate(options?.signal);
44
46
  }
45
47
  /**
46
- * Resume after at least `ms` milliseconds via `setTimeout`; abort rejects with
48
+ * Resumes after at least `ms` milliseconds through `setTimeout`; abort rejects with
47
49
  * `signal.reason`.
48
50
  *
49
51
  * @remarks
50
- * `ms` should be a non-negative finite number. The primitive does no validation: it
51
- * passes `ms` straight to the host `setTimeout`, which clamps a negative value or
52
- * `NaN` to ~0 — so an out-of-domain `ms` resolves on the next host turn rather than
53
- * throwing.
52
+ * Pass a non-negative finite `ms`. The primitive does no validation: it passes `ms`
53
+ * straight to the host `setTimeout`, which clamps a negative value or `NaN` to ~0 — so an
54
+ * out-of-domain `ms` resolves on the next host turn rather than throwing.
54
55
  */
55
56
  delay(ms, options) {
56
- return this.#sleep(ms, options?.signal);
57
+ return (0, _src_core.delayHost)(ms, options?.signal);
57
58
  }
58
59
  #immediate(signal) {
59
60
  return (0, _src_core.scheduleHost)((complete) => {
@@ -61,24 +62,18 @@ var NodeScheduler = class {
61
62
  return () => clearImmediate(handle);
62
63
  }, signal);
63
64
  }
64
- #sleep(ms, signal) {
65
- return (0, _src_core.scheduleHost)((complete) => {
66
- const handle = setTimeout(complete, ms);
67
- return () => clearTimeout(handle);
68
- }, signal);
69
- }
70
65
  };
71
66
  //#endregion
72
67
  //#region src/server/factories.ts
73
68
  /**
74
- * Create the Node-native cooperative-yield {@link SchedulerInterface} — `yield()` is a
69
+ * Creates the Node-native cooperative-yield {@link SchedulerInterface} — `yield()` is a
75
70
  * `setImmediate` host-turn (the canonical Node "give the event loop a turn"), `delay(ms)`
76
71
  * a real `setTimeout`.
77
72
  *
78
73
  * @remarks
79
- * Use it on a server instead of the cross-environment `createScheduler` when a yield
80
- * should hand the event loop a full turn (after pending I/O) via `setImmediate` rather
81
- * than a zero-delay timer. Both methods are abort-aware: pass `options.signal` and a
74
+ * Use it on a server instead of the cross-environment `createScheduler` when a yield must
75
+ * hand the event loop a full turn (after pending I/O) through `setImmediate` rather than a
76
+ * zero-delay timer. Both methods are abort-aware: pass `options.signal` and a
82
77
  * pending yield/delay rejects with the signal's exact `reason`; the shared owned-signal
83
78
  * lifecycle clears the native handle without invoking caller listener methods.
84
79
  * `options.priority` is accepted for contract compliance but a
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../../../src/server/NodeScheduler.ts","../../../src/server/factories.ts"],"sourcesContent":["import type { SchedulerInterface, SchedulerOptions } from '@src/core'\nimport { scheduleHost } from '@src/core'\n\n/**\n * The Node {@link SchedulerInterface} — the server-native cooperative-yield backend.\n *\n * @remarks\n * - **`yield` is a `setImmediate` host-turn.** `yield()` waits on `setImmediate`, the\n * canonical Node \"give the host a turn\" — it runs AFTER the current operation and\n * any pending I/O callbacks, so the event loop genuinely regains control before\n * resuming (unlike a microtask, which drains within the current task). `delay(ms)`\n * waits on a real `setTimeout`.\n * - **Abort fidelity is verbatim.** A pending `yield` / `delay` rejects with\n * `signal.reason` exactly. The shared `scheduleHost` lifecycle links an owned composite\n * before arming either Node handle, so caller signal method mutation is harmless and the\n * first completion, abort, or setup failure owns settlement and cleanup. It deliberately\n * does NOT use `node:timers/promises`, whose `{ signal }` option replaces the caller reason\n * with a Node `AbortError` (`code: 'ABORT_ERR'`).\n * - **Priority is accepted but a no-op.** Node has no priority primitive (no equivalent\n * of the browser's `scheduler.postTask` priorities), so `options.priority` is accepted\n * for contract compliance and ignored — every yield/delay is uniform.\n * - **Event-free.** A pure functional primitive — no Emitter, no events.\n *\n * @example\n * ```ts\n * import { createAbort } from '@orkestrel/abort'\n * import { NodeScheduler } from '@orkestrel/workflow/server'\n *\n * const abort = createAbort()\n * const scheduler = new NodeScheduler()\n * while (!abort.signal.aborted) {\n * \tdoSomeWork()\n * \tawait scheduler.yield({ signal: abort.signal }) // a setImmediate host-turn\n * }\n * ```\n */\nexport class NodeScheduler implements SchedulerInterface {\n\t/**\n\t * Yield control back to the event loop via `setImmediate` so pending I/O and timers\n\t * can run, then resume; abort rejects with `signal.reason`.\n\t */\n\tyield(options?: SchedulerOptions): Promise<void> {\n\t\treturn this.#immediate(options?.signal)\n\t}\n\n\t/**\n\t * Resume after at least `ms` milliseconds via `setTimeout`; abort rejects with\n\t * `signal.reason`.\n\t *\n\t * @remarks\n\t * `ms` should be a non-negative finite number. The primitive does no validation: it\n\t * passes `ms` straight to the host `setTimeout`, which clamps a negative value or\n\t * `NaN` to ~0 — so an out-of-domain `ms` resolves on the next host turn rather than\n\t * throwing.\n\t */\n\tdelay(ms: number, options?: SchedulerOptions): Promise<void> {\n\t\treturn this.#sleep(ms, options?.signal)\n\t}\n\n\t// === Private\n\n\t// The Node-native immediate boundary; `scheduleHost` owns cancellation lifecycle.\n\t#immediate(signal?: AbortSignal): Promise<void> {\n\t\treturn scheduleHost((complete) => {\n\t\t\tconst handle = setImmediate(complete)\n\t\t\treturn () => clearImmediate(handle)\n\t\t}, signal)\n\t}\n\n\t// The Node timer boundary; `scheduleHost` owns cancellation lifecycle.\n\t#sleep(ms: number, signal?: AbortSignal): Promise<void> {\n\t\treturn scheduleHost((complete) => {\n\t\t\tconst handle = setTimeout(complete, ms)\n\t\t\treturn () => clearTimeout(handle)\n\t\t}, signal)\n\t}\n}\n","import type { SchedulerInterface } from '@src/core'\nimport { NodeScheduler } from './NodeScheduler.js'\n\n/**\n * Create the Node-native cooperative-yield {@link SchedulerInterface} — `yield()` is a\n * `setImmediate` host-turn (the canonical Node \"give the event loop a turn\"), `delay(ms)`\n * a real `setTimeout`.\n *\n * @remarks\n * Use it on a server instead of the cross-environment `createScheduler` when a yield\n * should hand the event loop a full turn (after pending I/O) via `setImmediate` rather\n * than a zero-delay timer. Both methods are abort-aware: pass `options.signal` and a\n * pending yield/delay rejects with the signal's exact `reason`; the shared owned-signal\n * lifecycle clears the native handle without invoking caller listener methods.\n * `options.priority` is accepted for contract compliance but a\n * no-op — Node has no priority primitive.\n *\n * @returns A {@link SchedulerInterface} backed by Node's `setImmediate` / `setTimeout`\n *\n * @example\n * ```ts\n * import { createAbort } from '@orkestrel/abort'\n * import { createNodeScheduler } from '@orkestrel/workflow/server'\n *\n * const abort = createAbort()\n * const scheduler = createNodeScheduler()\n * while (!abort.signal.aborted) {\n * \tdoSomeWork()\n * \tawait scheduler.yield({ signal: abort.signal })\n * }\n * ```\n */\nexport function createNodeScheduler(): SchedulerInterface {\n\treturn new NodeScheduler()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,IAAa,gBAAb,MAAyD;;;;;CAKxD,MAAM,SAA2C;EAChD,OAAO,KAAK,WAAW,SAAS,MAAM;CACvC;;;;;;;;;;;CAYA,MAAM,IAAY,SAA2C;EAC5D,OAAO,KAAK,OAAO,IAAI,SAAS,MAAM;CACvC;CAKA,WAAW,QAAqC;EAC/C,QAAA,GAAO,UAAA,aAAA,EAAc,aAAa;GACjC,MAAM,SAAS,aAAa,QAAQ;GACpC,aAAa,eAAe,MAAM;EACnC,GAAG,MAAM;CACV;CAGA,OAAO,IAAY,QAAqC;EACvD,QAAA,GAAO,UAAA,aAAA,EAAc,aAAa;GACjC,MAAM,SAAS,WAAW,UAAU,EAAE;GACtC,aAAa,aAAa,MAAM;EACjC,GAAG,MAAM;CACV;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC5CA,SAAgB,sBAA0C;CACzD,OAAO,IAAI,cAAc;AAC1B"}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../../src/server/NodeScheduler.ts","../../../src/server/factories.ts"],"sourcesContent":["import type { SchedulerInterface, SchedulerOptions } from '@src/core'\nimport { delayHost, scheduleHost } from '@src/core'\n\n/**\n * Implements the Node {@link SchedulerInterface} — the server-native cooperative-yield backend\n * whose `yield` waits on `setImmediate` and whose abort rejects with the caller's own reason.\n * A `priority` hint is accepted and does nothing, because Node has no priority primitive.\n *\n * @remarks\n * - **`yield` is a `setImmediate` host-turn.** `yield()` waits on `setImmediate`, the\n * canonical Node \"give the host a turn\" — it runs after the current operation and\n * any pending I/O callbacks, so the event loop genuinely regains control before\n * resuming (unlike a microtask, which drains within the current task). `delay(ms)`\n * waits on a real `setTimeout`.\n * - **Abort fidelity is verbatim.** A pending `yield` / `delay` rejects with\n * `signal.reason` exactly. The shared `scheduleHost` lifecycle links an owned composite\n * before arming either Node handle, so caller signal method mutation is harmless and the\n * first completion, abort, or setup failure owns settlement and cleanup. It deliberately\n * does not use `node:timers/promises`, whose `{ signal }` option replaces the caller reason\n * with a Node `AbortError` (`code: 'ABORT_ERR'`).\n * - **Priority is accepted but a no-op.** Node has no priority primitive (no equivalent\n * of the browser's `scheduler.postTask` priorities), so `options.priority` is accepted\n * for contract compliance and ignored — every yield/delay is uniform.\n * - **Event-free.** A pure functional primitive — no Emitter, no events.\n *\n * @example\n * ```ts\n * import { createAbort } from '@orkestrel/abort'\n * import { NodeScheduler } from '@orkestrel/workflow/server'\n *\n * const abort = createAbort()\n * const scheduler = new NodeScheduler()\n * while (!abort.signal.aborted) {\n * \tdoSomeWork()\n * \tawait scheduler.yield({ signal: abort.signal }) // a setImmediate host-turn\n * }\n * ```\n */\nexport class NodeScheduler implements SchedulerInterface {\n\t/**\n\t * Yields control back to the event loop through `setImmediate` so pending I/O and timers\n\t * can run, then resumes; abort rejects with `signal.reason`.\n\t */\n\tyield(options?: SchedulerOptions): Promise<void> {\n\t\treturn this.#immediate(options?.signal)\n\t}\n\n\t/**\n\t * Resumes after at least `ms` milliseconds through `setTimeout`; abort rejects with\n\t * `signal.reason`.\n\t *\n\t * @remarks\n\t * Pass a non-negative finite `ms`. The primitive does no validation: it passes `ms`\n\t * straight to the host `setTimeout`, which clamps a negative value or `NaN` to ~0 — so an\n\t * out-of-domain `ms` resolves on the next host turn rather than throwing.\n\t */\n\tdelay(ms: number, options?: SchedulerOptions): Promise<void> {\n\t\treturn delayHost(ms, options?.signal)\n\t}\n\n\t// === Private\n\n\t// The Node-native immediate boundary; `scheduleHost` owns cancellation lifecycle.\n\t#immediate(signal?: AbortSignal): Promise<void> {\n\t\treturn scheduleHost((complete) => {\n\t\t\tconst handle = setImmediate(complete)\n\t\t\treturn () => clearImmediate(handle)\n\t\t}, signal)\n\t}\n}\n","import type { SchedulerInterface } from '@src/core'\nimport { NodeScheduler } from './NodeScheduler.js'\n\n/**\n * Creates the Node-native cooperative-yield {@link SchedulerInterface} — `yield()` is a\n * `setImmediate` host-turn (the canonical Node \"give the event loop a turn\"), `delay(ms)`\n * a real `setTimeout`.\n *\n * @remarks\n * Use it on a server instead of the cross-environment `createScheduler` when a yield must\n * hand the event loop a full turn (after pending I/O) through `setImmediate` rather than a\n * zero-delay timer. Both methods are abort-aware: pass `options.signal` and a\n * pending yield/delay rejects with the signal's exact `reason`; the shared owned-signal\n * lifecycle clears the native handle without invoking caller listener methods.\n * `options.priority` is accepted for contract compliance but a\n * no-op — Node has no priority primitive.\n *\n * @returns A {@link SchedulerInterface} backed by Node's `setImmediate` / `setTimeout`\n *\n * @example\n * ```ts\n * import { createAbort } from '@orkestrel/abort'\n * import { createNodeScheduler } from '@orkestrel/workflow/server'\n *\n * const abort = createAbort()\n * const scheduler = createNodeScheduler()\n * while (!abort.signal.aborted) {\n * \tdoSomeWork()\n * \tawait scheduler.yield({ signal: abort.signal })\n * }\n * ```\n */\nexport function createNodeScheduler(): SchedulerInterface {\n\treturn new NodeScheduler()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,IAAa,gBAAb,MAAyD;;;;;CAKxD,MAAM,SAA2C;EAChD,OAAO,KAAK,WAAW,SAAS,MAAM;CACvC;;;;;;;;;;CAWA,MAAM,IAAY,SAA2C;EAC5D,QAAA,GAAO,UAAA,UAAA,CAAU,IAAI,SAAS,MAAM;CACrC;CAKA,WAAW,QAAqC;EAC/C,QAAA,GAAO,UAAA,aAAA,EAAc,aAAa;GACjC,MAAM,SAAS,aAAa,QAAQ;GACpC,aAAa,eAAe,MAAM;EACnC,GAAG,MAAM;CACV;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACrCA,SAAgB,sBAA0C;CACzD,OAAO,IAAI,cAAc;AAC1B"}
@@ -1,15 +1,15 @@
1
- import { SchedulerInterface } from '@orkestrel/workflow';
2
- import { SchedulerOptions } from '@orkestrel/workflow';
1
+ import type { SchedulerInterface } from '@orkestrel/workflow';
2
+ import type { SchedulerOptions } from '@orkestrel/workflow';
3
3
 
4
4
  /**
5
- * Create the Node-native cooperative-yield {@link SchedulerInterface} — `yield()` is a
5
+ * Creates the Node-native cooperative-yield {@link SchedulerInterface} — `yield()` is a
6
6
  * `setImmediate` host-turn (the canonical Node "give the event loop a turn"), `delay(ms)`
7
7
  * a real `setTimeout`.
8
8
  *
9
9
  * @remarks
10
- * Use it on a server instead of the cross-environment `createScheduler` when a yield
11
- * should hand the event loop a full turn (after pending I/O) via `setImmediate` rather
12
- * than a zero-delay timer. Both methods are abort-aware: pass `options.signal` and a
10
+ * Use it on a server instead of the cross-environment `createScheduler` when a yield must
11
+ * hand the event loop a full turn (after pending I/O) through `setImmediate` rather than a
12
+ * zero-delay timer. Both methods are abort-aware: pass `options.signal` and a
13
13
  * pending yield/delay rejects with the signal's exact `reason`; the shared owned-signal
14
14
  * lifecycle clears the native handle without invoking caller listener methods.
15
15
  * `options.priority` is accepted for contract compliance but a
@@ -33,11 +33,13 @@ import { SchedulerOptions } from '@orkestrel/workflow';
33
33
  export declare function createNodeScheduler(): SchedulerInterface;
34
34
 
35
35
  /**
36
- * The Node {@link SchedulerInterface} — the server-native cooperative-yield backend.
36
+ * Implements the Node {@link SchedulerInterface} — the server-native cooperative-yield backend
37
+ * whose `yield` waits on `setImmediate` and whose abort rejects with the caller's own reason.
38
+ * A `priority` hint is accepted and does nothing, because Node has no priority primitive.
37
39
  *
38
40
  * @remarks
39
41
  * - **`yield` is a `setImmediate` host-turn.** `yield()` waits on `setImmediate`, the
40
- * canonical Node "give the host a turn" — it runs AFTER the current operation and
42
+ * canonical Node "give the host a turn" — it runs after the current operation and
41
43
  * any pending I/O callbacks, so the event loop genuinely regains control before
42
44
  * resuming (unlike a microtask, which drains within the current task). `delay(ms)`
43
45
  * waits on a real `setTimeout`.
@@ -45,7 +47,7 @@ export declare function createNodeScheduler(): SchedulerInterface;
45
47
  * `signal.reason` exactly. The shared `scheduleHost` lifecycle links an owned composite
46
48
  * before arming either Node handle, so caller signal method mutation is harmless and the
47
49
  * first completion, abort, or setup failure owns settlement and cleanup. It deliberately
48
- * does NOT use `node:timers/promises`, whose `{ signal }` option replaces the caller reason
50
+ * does not use `node:timers/promises`, whose `{ signal }` option replaces the caller reason
49
51
  * with a Node `AbortError` (`code: 'ABORT_ERR'`).
50
52
  * - **Priority is accepted but a no-op.** Node has no priority primitive (no equivalent
51
53
  * of the browser's `scheduler.postTask` priorities), so `options.priority` is accepted
@@ -68,19 +70,18 @@ export declare function createNodeScheduler(): SchedulerInterface;
68
70
  export declare class NodeScheduler implements SchedulerInterface {
69
71
  #private;
70
72
  /**
71
- * Yield control back to the event loop via `setImmediate` so pending I/O and timers
72
- * can run, then resume; abort rejects with `signal.reason`.
73
+ * Yields control back to the event loop through `setImmediate` so pending I/O and timers
74
+ * can run, then resumes; abort rejects with `signal.reason`.
73
75
  */
74
76
  yield(options?: SchedulerOptions): Promise<void>;
75
77
  /**
76
- * Resume after at least `ms` milliseconds via `setTimeout`; abort rejects with
78
+ * Resumes after at least `ms` milliseconds through `setTimeout`; abort rejects with
77
79
  * `signal.reason`.
78
80
  *
79
81
  * @remarks
80
- * `ms` should be a non-negative finite number. The primitive does no validation: it
81
- * passes `ms` straight to the host `setTimeout`, which clamps a negative value or
82
- * `NaN` to ~0 — so an out-of-domain `ms` resolves on the next host turn rather than
83
- * throwing.
82
+ * Pass a non-negative finite `ms`. The primitive does no validation: it passes `ms`
83
+ * straight to the host `setTimeout`, which clamps a negative value or `NaN` to ~0 — so an
84
+ * out-of-domain `ms` resolves on the next host turn rather than throwing.
84
85
  */
85
86
  delay(ms: number, options?: SchedulerOptions): Promise<void>;
86
87
  }
@@ -1,15 +1,15 @@
1
- import { SchedulerInterface } from '@orkestrel/workflow';
2
- import { SchedulerOptions } from '@orkestrel/workflow';
1
+ import type { SchedulerInterface } from '@orkestrel/workflow';
2
+ import type { SchedulerOptions } from '@orkestrel/workflow';
3
3
 
4
4
  /**
5
- * Create the Node-native cooperative-yield {@link SchedulerInterface} — `yield()` is a
5
+ * Creates the Node-native cooperative-yield {@link SchedulerInterface} — `yield()` is a
6
6
  * `setImmediate` host-turn (the canonical Node "give the event loop a turn"), `delay(ms)`
7
7
  * a real `setTimeout`.
8
8
  *
9
9
  * @remarks
10
- * Use it on a server instead of the cross-environment `createScheduler` when a yield
11
- * should hand the event loop a full turn (after pending I/O) via `setImmediate` rather
12
- * than a zero-delay timer. Both methods are abort-aware: pass `options.signal` and a
10
+ * Use it on a server instead of the cross-environment `createScheduler` when a yield must
11
+ * hand the event loop a full turn (after pending I/O) through `setImmediate` rather than a
12
+ * zero-delay timer. Both methods are abort-aware: pass `options.signal` and a
13
13
  * pending yield/delay rejects with the signal's exact `reason`; the shared owned-signal
14
14
  * lifecycle clears the native handle without invoking caller listener methods.
15
15
  * `options.priority` is accepted for contract compliance but a
@@ -33,11 +33,13 @@ import { SchedulerOptions } from '@orkestrel/workflow';
33
33
  export declare function createNodeScheduler(): SchedulerInterface;
34
34
 
35
35
  /**
36
- * The Node {@link SchedulerInterface} — the server-native cooperative-yield backend.
36
+ * Implements the Node {@link SchedulerInterface} — the server-native cooperative-yield backend
37
+ * whose `yield` waits on `setImmediate` and whose abort rejects with the caller's own reason.
38
+ * A `priority` hint is accepted and does nothing, because Node has no priority primitive.
37
39
  *
38
40
  * @remarks
39
41
  * - **`yield` is a `setImmediate` host-turn.** `yield()` waits on `setImmediate`, the
40
- * canonical Node "give the host a turn" — it runs AFTER the current operation and
42
+ * canonical Node "give the host a turn" — it runs after the current operation and
41
43
  * any pending I/O callbacks, so the event loop genuinely regains control before
42
44
  * resuming (unlike a microtask, which drains within the current task). `delay(ms)`
43
45
  * waits on a real `setTimeout`.
@@ -45,7 +47,7 @@ export declare function createNodeScheduler(): SchedulerInterface;
45
47
  * `signal.reason` exactly. The shared `scheduleHost` lifecycle links an owned composite
46
48
  * before arming either Node handle, so caller signal method mutation is harmless and the
47
49
  * first completion, abort, or setup failure owns settlement and cleanup. It deliberately
48
- * does NOT use `node:timers/promises`, whose `{ signal }` option replaces the caller reason
50
+ * does not use `node:timers/promises`, whose `{ signal }` option replaces the caller reason
49
51
  * with a Node `AbortError` (`code: 'ABORT_ERR'`).
50
52
  * - **Priority is accepted but a no-op.** Node has no priority primitive (no equivalent
51
53
  * of the browser's `scheduler.postTask` priorities), so `options.priority` is accepted
@@ -68,19 +70,18 @@ export declare function createNodeScheduler(): SchedulerInterface;
68
70
  export declare class NodeScheduler implements SchedulerInterface {
69
71
  #private;
70
72
  /**
71
- * Yield control back to the event loop via `setImmediate` so pending I/O and timers
72
- * can run, then resume; abort rejects with `signal.reason`.
73
+ * Yields control back to the event loop through `setImmediate` so pending I/O and timers
74
+ * can run, then resumes; abort rejects with `signal.reason`.
73
75
  */
74
76
  yield(options?: SchedulerOptions): Promise<void>;
75
77
  /**
76
- * Resume after at least `ms` milliseconds via `setTimeout`; abort rejects with
78
+ * Resumes after at least `ms` milliseconds through `setTimeout`; abort rejects with
77
79
  * `signal.reason`.
78
80
  *
79
81
  * @remarks
80
- * `ms` should be a non-negative finite number. The primitive does no validation: it
81
- * passes `ms` straight to the host `setTimeout`, which clamps a negative value or
82
- * `NaN` to ~0 — so an out-of-domain `ms` resolves on the next host turn rather than
83
- * throwing.
82
+ * Pass a non-negative finite `ms`. The primitive does no validation: it passes `ms`
83
+ * straight to the host `setTimeout`, which clamps a negative value or `NaN` to ~0 — so an
84
+ * out-of-domain `ms` resolves on the next host turn rather than throwing.
84
85
  */
85
86
  delay(ms: number, options?: SchedulerOptions): Promise<void>;
86
87
  }
@@ -1,11 +1,13 @@
1
- import { scheduleHost } from "../core/index.js";
1
+ import { delayHost, scheduleHost } from "../core/index.js";
2
2
  //#region src/server/NodeScheduler.ts
3
3
  /**
4
- * The Node {@link SchedulerInterface} — the server-native cooperative-yield backend.
4
+ * Implements the Node {@link SchedulerInterface} — the server-native cooperative-yield backend
5
+ * whose `yield` waits on `setImmediate` and whose abort rejects with the caller's own reason.
6
+ * A `priority` hint is accepted and does nothing, because Node has no priority primitive.
5
7
  *
6
8
  * @remarks
7
9
  * - **`yield` is a `setImmediate` host-turn.** `yield()` waits on `setImmediate`, the
8
- * canonical Node "give the host a turn" — it runs AFTER the current operation and
10
+ * canonical Node "give the host a turn" — it runs after the current operation and
9
11
  * any pending I/O callbacks, so the event loop genuinely regains control before
10
12
  * resuming (unlike a microtask, which drains within the current task). `delay(ms)`
11
13
  * waits on a real `setTimeout`.
@@ -13,7 +15,7 @@ import { scheduleHost } from "../core/index.js";
13
15
  * `signal.reason` exactly. The shared `scheduleHost` lifecycle links an owned composite
14
16
  * before arming either Node handle, so caller signal method mutation is harmless and the
15
17
  * first completion, abort, or setup failure owns settlement and cleanup. It deliberately
16
- * does NOT use `node:timers/promises`, whose `{ signal }` option replaces the caller reason
18
+ * does not use `node:timers/promises`, whose `{ signal }` option replaces the caller reason
17
19
  * with a Node `AbortError` (`code: 'ABORT_ERR'`).
18
20
  * - **Priority is accepted but a no-op.** Node has no priority primitive (no equivalent
19
21
  * of the browser's `scheduler.postTask` priorities), so `options.priority` is accepted
@@ -35,24 +37,23 @@ import { scheduleHost } from "../core/index.js";
35
37
  */
36
38
  var NodeScheduler = class {
37
39
  /**
38
- * Yield control back to the event loop via `setImmediate` so pending I/O and timers
39
- * can run, then resume; abort rejects with `signal.reason`.
40
+ * Yields control back to the event loop through `setImmediate` so pending I/O and timers
41
+ * can run, then resumes; abort rejects with `signal.reason`.
40
42
  */
41
43
  yield(options) {
42
44
  return this.#immediate(options?.signal);
43
45
  }
44
46
  /**
45
- * Resume after at least `ms` milliseconds via `setTimeout`; abort rejects with
47
+ * Resumes after at least `ms` milliseconds through `setTimeout`; abort rejects with
46
48
  * `signal.reason`.
47
49
  *
48
50
  * @remarks
49
- * `ms` should be a non-negative finite number. The primitive does no validation: it
50
- * passes `ms` straight to the host `setTimeout`, which clamps a negative value or
51
- * `NaN` to ~0 — so an out-of-domain `ms` resolves on the next host turn rather than
52
- * throwing.
51
+ * Pass a non-negative finite `ms`. The primitive does no validation: it passes `ms`
52
+ * straight to the host `setTimeout`, which clamps a negative value or `NaN` to ~0 — so an
53
+ * out-of-domain `ms` resolves on the next host turn rather than throwing.
53
54
  */
54
55
  delay(ms, options) {
55
- return this.#sleep(ms, options?.signal);
56
+ return delayHost(ms, options?.signal);
56
57
  }
57
58
  #immediate(signal) {
58
59
  return scheduleHost((complete) => {
@@ -60,24 +61,18 @@ var NodeScheduler = class {
60
61
  return () => clearImmediate(handle);
61
62
  }, signal);
62
63
  }
63
- #sleep(ms, signal) {
64
- return scheduleHost((complete) => {
65
- const handle = setTimeout(complete, ms);
66
- return () => clearTimeout(handle);
67
- }, signal);
68
- }
69
64
  };
70
65
  //#endregion
71
66
  //#region src/server/factories.ts
72
67
  /**
73
- * Create the Node-native cooperative-yield {@link SchedulerInterface} — `yield()` is a
68
+ * Creates the Node-native cooperative-yield {@link SchedulerInterface} — `yield()` is a
74
69
  * `setImmediate` host-turn (the canonical Node "give the event loop a turn"), `delay(ms)`
75
70
  * a real `setTimeout`.
76
71
  *
77
72
  * @remarks
78
- * Use it on a server instead of the cross-environment `createScheduler` when a yield
79
- * should hand the event loop a full turn (after pending I/O) via `setImmediate` rather
80
- * than a zero-delay timer. Both methods are abort-aware: pass `options.signal` and a
73
+ * Use it on a server instead of the cross-environment `createScheduler` when a yield must
74
+ * hand the event loop a full turn (after pending I/O) through `setImmediate` rather than a
75
+ * zero-delay timer. Both methods are abort-aware: pass `options.signal` and a
81
76
  * pending yield/delay rejects with the signal's exact `reason`; the shared owned-signal
82
77
  * lifecycle clears the native handle without invoking caller listener methods.
83
78
  * `options.priority` is accepted for contract compliance but a
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/server/NodeScheduler.ts","../../../src/server/factories.ts"],"sourcesContent":["import type { SchedulerInterface, SchedulerOptions } from '@src/core'\nimport { scheduleHost } from '@src/core'\n\n/**\n * The Node {@link SchedulerInterface} — the server-native cooperative-yield backend.\n *\n * @remarks\n * - **`yield` is a `setImmediate` host-turn.** `yield()` waits on `setImmediate`, the\n * canonical Node \"give the host a turn\" — it runs AFTER the current operation and\n * any pending I/O callbacks, so the event loop genuinely regains control before\n * resuming (unlike a microtask, which drains within the current task). `delay(ms)`\n * waits on a real `setTimeout`.\n * - **Abort fidelity is verbatim.** A pending `yield` / `delay` rejects with\n * `signal.reason` exactly. The shared `scheduleHost` lifecycle links an owned composite\n * before arming either Node handle, so caller signal method mutation is harmless and the\n * first completion, abort, or setup failure owns settlement and cleanup. It deliberately\n * does NOT use `node:timers/promises`, whose `{ signal }` option replaces the caller reason\n * with a Node `AbortError` (`code: 'ABORT_ERR'`).\n * - **Priority is accepted but a no-op.** Node has no priority primitive (no equivalent\n * of the browser's `scheduler.postTask` priorities), so `options.priority` is accepted\n * for contract compliance and ignored — every yield/delay is uniform.\n * - **Event-free.** A pure functional primitive — no Emitter, no events.\n *\n * @example\n * ```ts\n * import { createAbort } from '@orkestrel/abort'\n * import { NodeScheduler } from '@orkestrel/workflow/server'\n *\n * const abort = createAbort()\n * const scheduler = new NodeScheduler()\n * while (!abort.signal.aborted) {\n * \tdoSomeWork()\n * \tawait scheduler.yield({ signal: abort.signal }) // a setImmediate host-turn\n * }\n * ```\n */\nexport class NodeScheduler implements SchedulerInterface {\n\t/**\n\t * Yield control back to the event loop via `setImmediate` so pending I/O and timers\n\t * can run, then resume; abort rejects with `signal.reason`.\n\t */\n\tyield(options?: SchedulerOptions): Promise<void> {\n\t\treturn this.#immediate(options?.signal)\n\t}\n\n\t/**\n\t * Resume after at least `ms` milliseconds via `setTimeout`; abort rejects with\n\t * `signal.reason`.\n\t *\n\t * @remarks\n\t * `ms` should be a non-negative finite number. The primitive does no validation: it\n\t * passes `ms` straight to the host `setTimeout`, which clamps a negative value or\n\t * `NaN` to ~0 — so an out-of-domain `ms` resolves on the next host turn rather than\n\t * throwing.\n\t */\n\tdelay(ms: number, options?: SchedulerOptions): Promise<void> {\n\t\treturn this.#sleep(ms, options?.signal)\n\t}\n\n\t// === Private\n\n\t// The Node-native immediate boundary; `scheduleHost` owns cancellation lifecycle.\n\t#immediate(signal?: AbortSignal): Promise<void> {\n\t\treturn scheduleHost((complete) => {\n\t\t\tconst handle = setImmediate(complete)\n\t\t\treturn () => clearImmediate(handle)\n\t\t}, signal)\n\t}\n\n\t// The Node timer boundary; `scheduleHost` owns cancellation lifecycle.\n\t#sleep(ms: number, signal?: AbortSignal): Promise<void> {\n\t\treturn scheduleHost((complete) => {\n\t\t\tconst handle = setTimeout(complete, ms)\n\t\t\treturn () => clearTimeout(handle)\n\t\t}, signal)\n\t}\n}\n","import type { SchedulerInterface } from '@src/core'\nimport { NodeScheduler } from './NodeScheduler.js'\n\n/**\n * Create the Node-native cooperative-yield {@link SchedulerInterface} — `yield()` is a\n * `setImmediate` host-turn (the canonical Node \"give the event loop a turn\"), `delay(ms)`\n * a real `setTimeout`.\n *\n * @remarks\n * Use it on a server instead of the cross-environment `createScheduler` when a yield\n * should hand the event loop a full turn (after pending I/O) via `setImmediate` rather\n * than a zero-delay timer. Both methods are abort-aware: pass `options.signal` and a\n * pending yield/delay rejects with the signal's exact `reason`; the shared owned-signal\n * lifecycle clears the native handle without invoking caller listener methods.\n * `options.priority` is accepted for contract compliance but a\n * no-op — Node has no priority primitive.\n *\n * @returns A {@link SchedulerInterface} backed by Node's `setImmediate` / `setTimeout`\n *\n * @example\n * ```ts\n * import { createAbort } from '@orkestrel/abort'\n * import { createNodeScheduler } from '@orkestrel/workflow/server'\n *\n * const abort = createAbort()\n * const scheduler = createNodeScheduler()\n * while (!abort.signal.aborted) {\n * \tdoSomeWork()\n * \tawait scheduler.yield({ signal: abort.signal })\n * }\n * ```\n */\nexport function createNodeScheduler(): SchedulerInterface {\n\treturn new NodeScheduler()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,IAAa,gBAAb,MAAyD;;;;;CAKxD,MAAM,SAA2C;EAChD,OAAO,KAAK,WAAW,SAAS,MAAM;CACvC;;;;;;;;;;;CAYA,MAAM,IAAY,SAA2C;EAC5D,OAAO,KAAK,OAAO,IAAI,SAAS,MAAM;CACvC;CAKA,WAAW,QAAqC;EAC/C,OAAO,cAAc,aAAa;GACjC,MAAM,SAAS,aAAa,QAAQ;GACpC,aAAa,eAAe,MAAM;EACnC,GAAG,MAAM;CACV;CAGA,OAAO,IAAY,QAAqC;EACvD,OAAO,cAAc,aAAa;GACjC,MAAM,SAAS,WAAW,UAAU,EAAE;GACtC,aAAa,aAAa,MAAM;EACjC,GAAG,MAAM;CACV;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC5CA,SAAgB,sBAA0C;CACzD,OAAO,IAAI,cAAc;AAC1B"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/server/NodeScheduler.ts","../../../src/server/factories.ts"],"sourcesContent":["import type { SchedulerInterface, SchedulerOptions } from '@src/core'\nimport { delayHost, scheduleHost } from '@src/core'\n\n/**\n * Implements the Node {@link SchedulerInterface} — the server-native cooperative-yield backend\n * whose `yield` waits on `setImmediate` and whose abort rejects with the caller's own reason.\n * A `priority` hint is accepted and does nothing, because Node has no priority primitive.\n *\n * @remarks\n * - **`yield` is a `setImmediate` host-turn.** `yield()` waits on `setImmediate`, the\n * canonical Node \"give the host a turn\" — it runs after the current operation and\n * any pending I/O callbacks, so the event loop genuinely regains control before\n * resuming (unlike a microtask, which drains within the current task). `delay(ms)`\n * waits on a real `setTimeout`.\n * - **Abort fidelity is verbatim.** A pending `yield` / `delay` rejects with\n * `signal.reason` exactly. The shared `scheduleHost` lifecycle links an owned composite\n * before arming either Node handle, so caller signal method mutation is harmless and the\n * first completion, abort, or setup failure owns settlement and cleanup. It deliberately\n * does not use `node:timers/promises`, whose `{ signal }` option replaces the caller reason\n * with a Node `AbortError` (`code: 'ABORT_ERR'`).\n * - **Priority is accepted but a no-op.** Node has no priority primitive (no equivalent\n * of the browser's `scheduler.postTask` priorities), so `options.priority` is accepted\n * for contract compliance and ignored — every yield/delay is uniform.\n * - **Event-free.** A pure functional primitive — no Emitter, no events.\n *\n * @example\n * ```ts\n * import { createAbort } from '@orkestrel/abort'\n * import { NodeScheduler } from '@orkestrel/workflow/server'\n *\n * const abort = createAbort()\n * const scheduler = new NodeScheduler()\n * while (!abort.signal.aborted) {\n * \tdoSomeWork()\n * \tawait scheduler.yield({ signal: abort.signal }) // a setImmediate host-turn\n * }\n * ```\n */\nexport class NodeScheduler implements SchedulerInterface {\n\t/**\n\t * Yields control back to the event loop through `setImmediate` so pending I/O and timers\n\t * can run, then resumes; abort rejects with `signal.reason`.\n\t */\n\tyield(options?: SchedulerOptions): Promise<void> {\n\t\treturn this.#immediate(options?.signal)\n\t}\n\n\t/**\n\t * Resumes after at least `ms` milliseconds through `setTimeout`; abort rejects with\n\t * `signal.reason`.\n\t *\n\t * @remarks\n\t * Pass a non-negative finite `ms`. The primitive does no validation: it passes `ms`\n\t * straight to the host `setTimeout`, which clamps a negative value or `NaN` to ~0 — so an\n\t * out-of-domain `ms` resolves on the next host turn rather than throwing.\n\t */\n\tdelay(ms: number, options?: SchedulerOptions): Promise<void> {\n\t\treturn delayHost(ms, options?.signal)\n\t}\n\n\t// === Private\n\n\t// The Node-native immediate boundary; `scheduleHost` owns cancellation lifecycle.\n\t#immediate(signal?: AbortSignal): Promise<void> {\n\t\treturn scheduleHost((complete) => {\n\t\t\tconst handle = setImmediate(complete)\n\t\t\treturn () => clearImmediate(handle)\n\t\t}, signal)\n\t}\n}\n","import type { SchedulerInterface } from '@src/core'\nimport { NodeScheduler } from './NodeScheduler.js'\n\n/**\n * Creates the Node-native cooperative-yield {@link SchedulerInterface} — `yield()` is a\n * `setImmediate` host-turn (the canonical Node \"give the event loop a turn\"), `delay(ms)`\n * a real `setTimeout`.\n *\n * @remarks\n * Use it on a server instead of the cross-environment `createScheduler` when a yield must\n * hand the event loop a full turn (after pending I/O) through `setImmediate` rather than a\n * zero-delay timer. Both methods are abort-aware: pass `options.signal` and a\n * pending yield/delay rejects with the signal's exact `reason`; the shared owned-signal\n * lifecycle clears the native handle without invoking caller listener methods.\n * `options.priority` is accepted for contract compliance but a\n * no-op — Node has no priority primitive.\n *\n * @returns A {@link SchedulerInterface} backed by Node's `setImmediate` / `setTimeout`\n *\n * @example\n * ```ts\n * import { createAbort } from '@orkestrel/abort'\n * import { createNodeScheduler } from '@orkestrel/workflow/server'\n *\n * const abort = createAbort()\n * const scheduler = createNodeScheduler()\n * while (!abort.signal.aborted) {\n * \tdoSomeWork()\n * \tawait scheduler.yield({ signal: abort.signal })\n * }\n * ```\n */\nexport function createNodeScheduler(): SchedulerInterface {\n\treturn new NodeScheduler()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,IAAa,gBAAb,MAAyD;;;;;CAKxD,MAAM,SAA2C;EAChD,OAAO,KAAK,WAAW,SAAS,MAAM;CACvC;;;;;;;;;;CAWA,MAAM,IAAY,SAA2C;EAC5D,OAAO,UAAU,IAAI,SAAS,MAAM;CACrC;CAKA,WAAW,QAAqC;EAC/C,OAAO,cAAc,aAAa;GACjC,MAAM,SAAS,aAAa,QAAQ;GACpC,aAAa,eAAe,MAAM;EACnC,GAAG,MAAM;CACV;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACrCA,SAAgB,sBAA0C;CACzD,OAAO,IAAI,cAAc;AAC1B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orkestrel/workflow",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "A typed workflow engine for the @orkestrel line — a serializable Workflow → Phase → Task tree run by a composed runner on a cooperative scheduler. Part of the @orkestrel line.",
5
5
  "keywords": [
6
6
  "orchestration",
@@ -61,7 +61,7 @@
61
61
  "clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
62
62
  "copy": "node -e \"const fs=require('node:fs'),p=require('node:path'),a=process.argv[1],b=process.argv[2];fs.mkdirSync(p.dirname(b),{recursive:true});fs.cpSync(a,b,{force:true});console.log('Copied: '+a+' to '+b)\"",
63
63
  "scaffold": "scaffold",
64
- "lint": "oxlint --config .oxlintrc.json --fix --deny-warnings .",
64
+ "lint": "oxlint --config .oxlintrc.json --fix .",
65
65
  "check": "tsc --noEmit --project tsconfig.json && npm run check:src",
66
66
  "check:src": "npm run check:src:core && npm run check:src:browser && npm run check:src:server",
67
67
  "check:src:core": "tsc --noEmit -p configs/src/tsconfig.core.json",
@@ -77,7 +77,7 @@
77
77
  "test:src:server": "vitest run --config vite.config.ts --no-cache --reporter=dot --project src:server",
78
78
  "test:policy": "vitest run --config vite.config.ts --no-cache --reporter=dot --project policy",
79
79
  "test:config": "vitest run --config vite.config.ts --no-cache --reporter=dot --project config",
80
- "test:guides": "vitest run --config vite.config.ts --no-cache --reporter=dot --project guides",
80
+ "test:guides": "node --experimental-strip-types tests/guides.test.ts",
81
81
  "build": "npm run clean && npm run build:src",
82
82
  "build:src": "npm run build:src:core && npm run build:src:browser && npm run build:src:server",
83
83
  "build:src:core": "vite build --config configs/src/vite.core.config.ts && npm run copy dist/src/core/index.d.ts dist/src/core/index.d.cts",
@@ -91,28 +91,27 @@
91
91
  "test:setup": "vitest run --config vite.config.ts --no-cache --reporter=dot --project setup"
92
92
  },
93
93
  "dependencies": {
94
- "@orkestrel/abort": "^0.0.8",
95
- "@orkestrel/budget": "^0.0.8",
96
- "@orkestrel/contract": "^0.0.13",
97
- "@orkestrel/database": "^0.0.12",
98
- "@orkestrel/emitter": "^0.0.8",
99
- "@orkestrel/queue": "^0.0.11",
100
- "@orkestrel/timeout": "^0.0.8"
94
+ "@orkestrel/abort": "^0.0.10",
95
+ "@orkestrel/budget": "^0.0.10",
96
+ "@orkestrel/contract": "^0.0.17",
97
+ "@orkestrel/database": "^0.0.14",
98
+ "@orkestrel/emitter": "^0.0.10",
99
+ "@orkestrel/queue": "^0.0.13",
100
+ "@orkestrel/timeout": "^0.0.10"
101
101
  },
102
102
  "devDependencies": {
103
- "@microsoft/api-extractor": "^7.59.0",
104
- "@orkestrel/guide": "^0.0.15",
105
- "@orkestrel/probe": "^0.0.9",
106
- "@orkestrel/scaffold": "^0.0.57",
107
- "@orkestrel/test": "^0.0.11",
108
- "@types/node": "^26.4.0",
103
+ "@microsoft/api-extractor": "^7.59.1",
104
+ "@orkestrel/guide": "^0.0.18",
105
+ "@orkestrel/probe": "^0.0.12",
106
+ "@orkestrel/scaffold": "^0.0.64",
107
+ "@orkestrel/test": "^0.0.14",
108
+ "@types/node": "^26.5.1",
109
109
  "@vitest/browser-playwright": "^4.1.11",
110
- "oxfmt": "^0.65.0",
111
- "oxlint": "^1.80.0",
112
- "playwright": "^1.62.1",
110
+ "oxfmt": "^0.67.0",
111
+ "oxlint": "^1.82.0",
112
+ "playwright": "^1.63.0",
113
113
  "typescript": "^6.0.3",
114
- "vite": "^8.2.2",
115
- "vite-plugin-dts": "^5.0.3",
114
+ "vite": "^8.3.0",
116
115
  "vitest": "^4.1.11"
117
116
  },
118
117
  "engines": {