@demlik/tea 0.6.0 → 0.8.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.
- package/dist/agent/index.d.ts +6 -5
- package/dist/agent/index.js +10 -10
- package/dist/authed-call/index.d.ts +2 -2
- package/dist/authed-call/index.js +7 -7
- package/dist/await-terminal/index.d.ts +3 -2
- package/dist/await-terminal/index.js +2 -2
- package/dist/batch-window/index.d.ts +4 -3
- package/dist/batch-window/index.js +3 -3
- package/dist/cache/index.d.ts +2 -2
- package/dist/cache/index.js +4 -4
- package/dist/chart/index.d.ts +217 -0
- package/dist/chart/index.js +16 -0
- package/dist/chart/index.js.map +1 -0
- package/dist/chart/inspect/index.d.ts +85 -0
- package/dist/chart/inspect/index.js +5 -0
- package/dist/chart/inspect/index.js.map +1 -0
- package/dist/chart/inspect/react.d.ts +112 -0
- package/dist/chart/inspect/react.js +11 -0
- package/dist/chart/inspect/react.js.map +1 -0
- package/dist/chart/inspect/styles.css +286 -0
- package/dist/chart/lane/index.d.ts +361 -0
- package/dist/chart/lane/index.js +9 -0
- package/dist/chart/lane/index.js.map +1 -0
- package/dist/chart/lane/react.d.ts +83 -0
- package/dist/chart/lane/react.js +559 -0
- package/dist/chart/lane/react.js.map +1 -0
- package/dist/chart/lane/styles.css +498 -0
- package/dist/chart/report/index.d.ts +116 -0
- package/dist/chart/report/index.js +32 -0
- package/dist/chart/report/index.js.map +1 -0
- package/dist/{chunk-2UGTDYOK.js → chunk-3JU6657S.js} +3 -3
- package/dist/{chunk-2UGTDYOK.js.map → chunk-3JU6657S.js.map} +1 -1
- package/dist/{chunk-AZ3NHUPD.js → chunk-4KTWLPL5.js} +3 -3
- package/dist/{chunk-AZ3NHUPD.js.map → chunk-4KTWLPL5.js.map} +1 -1
- package/dist/{chunk-ZH454CR5.js → chunk-5EHLEUTL.js} +24 -4
- package/dist/chunk-5EHLEUTL.js.map +1 -0
- package/dist/chunk-5KJKJOFC.js +758 -0
- package/dist/chunk-5KJKJOFC.js.map +1 -0
- package/dist/{chunk-WF46FABO.js → chunk-7SVIRMC6.js} +3 -3
- package/dist/{chunk-WF46FABO.js.map → chunk-7SVIRMC6.js.map} +1 -1
- package/dist/{chunk-XMHZ44QC.js → chunk-7V4EVLZA.js} +4 -4
- package/dist/{chunk-XMHZ44QC.js.map → chunk-7V4EVLZA.js.map} +1 -1
- package/dist/{chunk-IVHQCVFX.js → chunk-A56OR5RF.js} +3 -3
- package/dist/{chunk-IVHQCVFX.js.map → chunk-A56OR5RF.js.map} +1 -1
- package/dist/{chunk-O7ED34JH.js → chunk-B5VXOFMZ.js} +47 -15
- package/dist/chunk-B5VXOFMZ.js.map +1 -0
- package/dist/chunk-E6GEDSF4.js +307 -0
- package/dist/chunk-E6GEDSF4.js.map +1 -0
- package/dist/{chunk-EC6FO42Q.js → chunk-EUF7XOEE.js} +6 -6
- package/dist/{chunk-EC6FO42Q.js.map → chunk-EUF7XOEE.js.map} +1 -1
- package/dist/{chunk-XOAP3LOT.js → chunk-I5OV65MS.js} +3 -3
- package/dist/{chunk-XOAP3LOT.js.map → chunk-I5OV65MS.js.map} +1 -1
- package/dist/chunk-JER5O7PQ.js +416 -0
- package/dist/chunk-JER5O7PQ.js.map +1 -0
- package/dist/{chunk-ASX7PL2K.js → chunk-JGVL3WPL.js} +3 -3
- package/dist/{chunk-ASX7PL2K.js.map → chunk-JGVL3WPL.js.map} +1 -1
- package/dist/{chunk-S6Y3RNX4.js → chunk-JP5D6GSL.js} +4 -4
- package/dist/{chunk-S6Y3RNX4.js.map → chunk-JP5D6GSL.js.map} +1 -1
- package/dist/{chunk-ERYY5P6W.js → chunk-ND3DH6KM.js} +3 -3
- package/dist/{chunk-ERYY5P6W.js.map → chunk-ND3DH6KM.js.map} +1 -1
- package/dist/{chunk-A7USKARI.js → chunk-SUST46KO.js} +3 -3
- package/dist/{chunk-A7USKARI.js.map → chunk-SUST46KO.js.map} +1 -1
- package/dist/{chunk-2KBEIGYP.js → chunk-TP5UPGLY.js} +3 -3
- package/dist/{chunk-2KBEIGYP.js.map → chunk-TP5UPGLY.js.map} +1 -1
- package/dist/chunk-UOC2PL46.js +13 -0
- package/dist/chunk-UOC2PL46.js.map +1 -0
- package/dist/{chunk-66S2KEQQ.js → chunk-WLGO64WC.js} +4 -4
- package/dist/{chunk-66S2KEQQ.js.map → chunk-WLGO64WC.js.map} +1 -1
- package/dist/chunk-WRAA7GVZ.js +209 -0
- package/dist/chunk-WRAA7GVZ.js.map +1 -0
- package/dist/chunk-ZCL7SCBK.js +685 -0
- package/dist/chunk-ZCL7SCBK.js.map +1 -0
- package/dist/chunk-ZD6PNZBK.js +457 -0
- package/dist/chunk-ZD6PNZBK.js.map +1 -0
- package/dist/{chunk-UV7VCTNC.js → chunk-ZF6WDK2D.js} +7 -7
- package/dist/{chunk-UV7VCTNC.js.map → chunk-ZF6WDK2D.js.map} +1 -1
- package/dist/{core-CUN5HDKL.d.ts → core-Bjc0bS8j.d.ts} +22 -1
- package/dist/deadline/index.d.ts +2 -2
- package/dist/deadline/index.js +3 -3
- package/dist/devtools/index.js +2 -207
- package/dist/devtools/index.js.map +1 -1
- package/dist/do/index.d.ts +7 -6
- package/dist/do/index.js +10 -10
- package/dist/{durable-effects-CXMOi-sp.d.ts → durable-effects-D8SqU_if.d.ts} +1 -1
- package/dist/extension/index.d.ts +3 -2
- package/dist/extension/index.js +3 -3
- package/dist/extension/react.js +3 -3
- package/dist/extension/subs/index.d.ts +2 -2
- package/dist/fan-out/index.d.ts +3 -2
- package/dist/fold-Blbhru48.d.ts +435 -0
- package/dist/graph-CcjWZVrd.d.ts +923 -0
- package/dist/idempotent-intake/index.d.ts +3 -2
- package/dist/index.d.ts +5 -4
- package/dist/index.js +2 -2
- package/dist/llm-call/index.d.ts +2 -2
- package/dist/llm-call/index.js +7 -7
- package/dist/{machine-CoWpvp8x.d.ts → machine-0OmPvsy_.d.ts} +1 -1
- package/dist/machine-viz/index.d.ts +19 -2
- package/dist/machine-viz/index.js +4 -10
- package/dist/machine-viz/index.js.map +1 -1
- package/dist/mem/index.d.ts +3 -2
- package/dist/monitored-run/index.d.ts +4 -3
- package/dist/monitored-run/index.js +5 -5
- package/dist/node/index.d.ts +3 -2
- package/dist/paginated-walk/index.d.ts +2 -2
- package/dist/paginated-walk/index.js +7 -7
- package/dist/parity/index.d.ts +3 -2
- package/dist/parity/index.js +3 -3
- package/dist/pbt/arbitraries/index.d.ts +1 -1
- package/dist/pbt/index.d.ts +1 -1
- package/dist/pbt/index.js +3 -3
- package/dist/pbt/runners/index.d.ts +1 -1
- package/dist/pbt/runners/index.js +3 -3
- package/dist/poller/index.d.ts +28 -7
- package/dist/poller/index.js +3 -3
- package/dist/poller/index.js.map +1 -1
- package/dist/prediction/index.d.ts +1 -1
- package/dist/prediction/index.js +2 -2
- package/dist/pure/index.d.ts +1 -1
- package/dist/pure/index.js +2 -2
- package/dist/react/index.d.ts +3 -2
- package/dist/react/index.js +2 -2
- package/dist/reconciler/index.d.ts +2 -2
- package/dist/reconciler/index.js +7 -7
- package/dist/recorder/index.d.ts +3 -2
- package/dist/reducer-BqyoVyBG.d.ts +447 -0
- package/dist/resilient-call/index.d.ts +2 -2
- package/dist/resilient-call/index.js +6 -6
- package/dist/run-BVeqJDBF.d.ts +713 -0
- package/dist/{runtime-types-BD3ZFfdw.d.ts → runtime-types-Bxc637bp.d.ts} +53 -2
- package/dist/saga/index.d.ts +3 -2
- package/dist/samples-DCt6nF8H.d.ts +59 -0
- package/dist/snapshot/index.d.ts +1 -1
- package/dist/snapshot/index.js +3 -3
- package/dist/subs/index.d.ts +4 -3
- package/dist/subs/index.js +3 -3
- package/dist/testing/index.d.ts +3 -2
- package/dist/testing/index.js +2 -2
- package/dist/throttled-input/index.d.ts +2 -2
- package/dist/throttled-input/index.js +6 -6
- package/dist/token-refresh/index.d.ts +1 -1
- package/dist/token-refresh/index.js +3 -3
- package/dist/trace-replay/index.d.ts +3 -2
- package/dist/trace-replay/index.js +3 -3
- package/dist/{types-CjAkI83U.d.ts → types-D7u9DkH7.d.ts} +1 -1
- package/dist/with-deadline/index.d.ts +1 -1
- package/dist/with-deadline/index.js +2 -2
- package/dist/with-resilience/index.d.ts +2 -2
- package/dist/with-resilience/index.js +6 -6
- package/dist/with-telemetry/index.d.ts +1 -1
- package/dist/with-telemetry/index.js +2 -2
- package/dist/work-queue/adapter.d.ts +3 -2
- package/dist/work-queue/index.d.ts +3 -2
- package/dist/work-queue/ops.d.ts +3 -2
- package/dist/workflow/index.d.ts +3 -3
- package/package.json +31 -1
- package/dist/chunk-O7ED34JH.js.map +0 -1
- package/dist/chunk-ZH454CR5.js.map +0 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { IdempotencyStore } from '../idempotency/index.js';
|
|
2
|
-
import { C as Cmd } from '../core-
|
|
2
|
+
import { C as Cmd } from '../core-Bjc0bS8j.js';
|
|
3
3
|
import { QueueItem } from '../work-queue/index.js';
|
|
4
|
-
import '../runtime-types-
|
|
4
|
+
import '../runtime-types-Bxc637bp.js';
|
|
5
|
+
import 'better-result';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @demlik/tea/idempotent-intake — receive-once intake for webhooks / queue
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { B as BootingRuntime, C as CtxArg, S as Store, O as OnError, a as Supervision } from './runtime-types-
|
|
2
|
-
export { b as Branded, D as DispatchDiscardedError, c as DispatchSettle, d as DisposeTimeoutNotice, I as IdentityDropNotice, P as PortNameCollisionError, Q as QuiescenceTimeoutError, R as Runtime, e as RuntimeDiscardNotice, f as RuntimeDiscardedError, g as RuntimeErrorContext, h as RuntimeErrorPhase, i as RuntimeRef, j as Schema, k as SubIdCollisionError, l as SupervisionStrategy, _ as __resetPortRegistry, m as absurd, n as asReducer, o as defineMachine, p as definePort, q as noop, r as replay, s as schemaMigrate, t as tryInterpret, w as wrapDetached } from './runtime-types-
|
|
3
|
-
import { C as Cmd, S as Sub, M as Machine } from './core-
|
|
4
|
-
export { d as ContextFree, D as DepKeyedSub, e as Dispose, f as Identity, I as Interpret, c as InterpretDetached, N as NoCellError,
|
|
1
|
+
import { B as BootingRuntime, C as CtxArg, S as Store, O as OnError, a as Supervision } from './runtime-types-Bxc637bp.js';
|
|
2
|
+
export { b as Branded, D as DispatchDiscardedError, c as DispatchSettle, d as DisposeTimeoutNotice, F as FoldRefusal, I as IdentityDropNotice, P as PortNameCollisionError, Q as QuiescenceTimeoutError, R as Runtime, e as RuntimeDiscardNotice, f as RuntimeDiscardedError, g as RuntimeErrorContext, h as RuntimeErrorPhase, i as RuntimeRef, j as Schema, k as SubIdCollisionError, l as SupervisionStrategy, _ as __resetPortRegistry, m as absurd, n as asReducer, o as defineMachine, p as definePort, q as noop, r as replay, s as schemaMigrate, t as tryApplyCell, u as tryFoldMsgs, v as tryInterpret, w as wrapDetached } from './runtime-types-Bxc637bp.js';
|
|
3
|
+
import { C as Cmd, S as Sub, M as Machine } from './core-Bjc0bS8j.js';
|
|
4
|
+
export { d as ContextFree, D as DepKeyedSub, e as Dispose, f as Identity, I as Interpret, c as InterpretDetached, g as MachineShape, N as NoCellError, h as NoCtx, a as Port, P as PortEmitter, R as Reducer, b as SubId, i as Subscribe, j as SyncReturn, T as Transitions, U as UpdateForm, k as acceptsOf, l as applyCell, m as applyCellChecked, n as describeMachine, o as detectUpdateForm, p as foldMsgs, q as foldUpdates, r as formOf, s as msgKeysOf, t as structuralHash, u as subId } from './core-Bjc0bS8j.js';
|
|
5
|
+
import 'better-result';
|
|
5
6
|
|
|
6
7
|
interface HistoryTracker<S, M extends {
|
|
7
8
|
type: string;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { DispatchDiscardedError, DisposeTimeoutNotice, IdentityDropNotice, PortNameCollisionError, QuiescenceTimeoutError, RuntimeDiscardNotice, RuntimeDiscardedError, SubIdCollisionError, __resetPortRegistry, absurd, asReducer, defineMachine, definePort, historyTracker, noop, replay, run, schemaMigrate, tryInterpret, wrapDetached } from './chunk-
|
|
2
|
-
export { Cmd, NoCellError, applyCell, applyCellChecked, detectUpdateForm, foldMsgs, foldUpdates, formOf, msgKeysOf, structuralHash, subId } from './chunk-
|
|
1
|
+
export { DispatchDiscardedError, DisposeTimeoutNotice, IdentityDropNotice, PortNameCollisionError, QuiescenceTimeoutError, RuntimeDiscardNotice, RuntimeDiscardedError, SubIdCollisionError, __resetPortRegistry, absurd, asReducer, defineMachine, definePort, historyTracker, noop, replay, run, schemaMigrate, tryApplyCell, tryFoldMsgs, tryInterpret, wrapDetached } from './chunk-5EHLEUTL.js';
|
|
2
|
+
export { Cmd, NoCellError, acceptsOf, applyCell, applyCellChecked, describeMachine, detectUpdateForm, foldMsgs, foldUpdates, formOf, msgKeysOf, structuralHash, subId } from './chunk-B5VXOFMZ.js';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/dist/llm-call/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { C as Cmd } from '../core-
|
|
1
|
+
import { C as Cmd } from '../core-Bjc0bS8j.js';
|
|
2
2
|
import { RunCmd, SucceedMsg, FailMsg, ResilientState } from '../resilient-call/index.js';
|
|
3
3
|
import { RetryPolicy } from '../retry-backoff/index.js';
|
|
4
4
|
import { DeadlineExceeded, DeadlineSub } from '../deadline/index.js';
|
|
5
5
|
export { deadlineSub, subscribeDeadline } from '../deadline/index.js';
|
|
6
6
|
import '../cache/index.js';
|
|
7
|
-
import '../types-
|
|
7
|
+
import '../types-D7u9DkH7.js';
|
|
8
8
|
import '../circuit-breaker/index.js';
|
|
9
9
|
import '../protocol-B5YmJr0d.js';
|
|
10
10
|
import '../rate-limit/index.js';
|
package/dist/llm-call/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export { createLlmCall, liftLlmCall } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
export { createLlmCall, liftLlmCall } from '../chunk-ND3DH6KM.js';
|
|
2
|
+
import '../chunk-EUF7XOEE.js';
|
|
3
3
|
import '../chunk-JELSZN25.js';
|
|
4
|
-
export { deadlineSub, subscribeDeadline } from '../chunk-
|
|
4
|
+
export { deadlineSub, subscribeDeadline } from '../chunk-JGVL3WPL.js';
|
|
5
5
|
import '../chunk-Q2UM7BXU.js';
|
|
6
6
|
import '../chunk-S2EGRPCM.js';
|
|
7
7
|
import '../chunk-UF4MZSLT.js';
|
|
8
|
-
import '../chunk-
|
|
9
|
-
import '../chunk-
|
|
8
|
+
import '../chunk-7SVIRMC6.js';
|
|
9
|
+
import '../chunk-3JU6657S.js';
|
|
10
10
|
import '../chunk-2YFLOCWX.js';
|
|
11
11
|
import '../chunk-ZJ5AOYBH.js';
|
|
12
12
|
import '../chunk-G5E74IJB.js';
|
|
13
|
-
import '../chunk-
|
|
14
|
-
import '../chunk-
|
|
13
|
+
import '../chunk-5EHLEUTL.js';
|
|
14
|
+
import '../chunk-B5VXOFMZ.js';
|
|
15
15
|
//# sourceMappingURL=index.js.map
|
|
16
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as Cmd, I as Interpret, M as Machine } from './core-
|
|
1
|
+
import { C as Cmd, I as Interpret, M as Machine } from './core-Bjc0bS8j.js';
|
|
2
2
|
import { ModelFactory, Schema, MessageLoader, LlmCall, LlmOk, LlmErr, LlmRunCmd, LlmSucceedMsg, LlmFailMsg, LlmTimerMsg, LlmCallPorts } from './llm-call/index.js';
|
|
3
3
|
import { MonitoredRunState, RunFailure, MonitoredRunCmd } from './monitored-run/index.js';
|
|
4
4
|
import { M as MsgType } from './protocol-B5YmJr0d.js';
|
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
import { C as Cmd, S as Sub, M as Machine } from '../core-
|
|
1
|
+
import { C as Cmd, S as Sub, M as Machine } from '../core-Bjc0bS8j.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sanitize a discriminant string into a Mermaid-safe node identifier.
|
|
5
|
+
*
|
|
6
|
+
* Any run of non-identifier characters becomes `_`; a leading digit is
|
|
7
|
+
* prefixed so the id is always a valid Mermaid token; the empty string gets a
|
|
8
|
+
* stable placeholder. Deterministic and idempotent — `safeId(safeId(x))` is
|
|
9
|
+
* `safeId(x)`, so a diagram may sanitize the same name at several sites.
|
|
10
|
+
*/
|
|
11
|
+
declare function safeId(raw: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Sanitize text used as a Mermaid edge/transition label (the part after `:`).
|
|
14
|
+
*
|
|
15
|
+
* Strips the characters that terminate or confuse a label: newlines, the `:`
|
|
16
|
+
* that separates label from target, and Mermaid's `"`/`;` delimiters.
|
|
17
|
+
*/
|
|
18
|
+
declare function safeLabel(raw: string): string;
|
|
2
19
|
|
|
3
20
|
/**
|
|
4
21
|
* @demlik/tea/machine-viz — turn a `Machine` into a Mermaid diagram string.
|
|
@@ -75,4 +92,4 @@ declare function toMermaid<S, M extends {
|
|
|
75
92
|
type: string;
|
|
76
93
|
}, C extends Cmd, U extends Sub, Ctx>(machine: Machine<S, M, C, U, Ctx>, opts?: MachineVizOptions<NoInfer<S>, NoInfer<M>>): string;
|
|
77
94
|
|
|
78
|
-
export { type MachineVizOptions, toMermaid };
|
|
95
|
+
export { type MachineVizOptions, safeId, safeLabel, toMermaid };
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import '../chunk-
|
|
2
|
-
|
|
1
|
+
import { safeId, safeLabel } from '../chunk-UOC2PL46.js';
|
|
2
|
+
export { safeId, safeLabel } from '../chunk-UOC2PL46.js';
|
|
3
|
+
import '../chunk-5EHLEUTL.js';
|
|
4
|
+
import { formOf } from '../chunk-B5VXOFMZ.js';
|
|
3
5
|
|
|
4
6
|
// src/machine-viz/index.ts
|
|
5
|
-
function safeId(raw) {
|
|
6
|
-
const cleaned = raw.replace(/[^A-Za-z0-9_]/g, "_");
|
|
7
|
-
if (cleaned === "") return "_empty";
|
|
8
|
-
return /^[0-9]/.test(cleaned) ? `s_${cleaned}` : cleaned;
|
|
9
|
-
}
|
|
10
|
-
function safeLabel(raw) {
|
|
11
|
-
return raw.replace(/["\n\r;:]/g, " ").trim();
|
|
12
|
-
}
|
|
13
7
|
function toMermaid(machine, opts = {}) {
|
|
14
8
|
const direction = opts.direction ?? "TB";
|
|
15
9
|
const stateSamples = opts.samples?.states ?? {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/machine-viz/index.ts"],"names":[],"mappings":";;;;AAoEA,SAAS,OAAO,GAAA,EAAqB;AAGnC,EAAA,MAAM,OAAA,GAAU,GAAA,CAAI,OAAA,CAAQ,gBAAA,EAAkB,GAAG,CAAA;AACjD,EAAA,IAAI,OAAA,KAAY,IAAI,OAAO,QAAA;AAC3B,EAAA,OAAO,SAAS,IAAA,CAAK,OAAO,CAAA,GAAI,CAAA,EAAA,EAAK,OAAO,CAAA,CAAA,GAAK,OAAA;AACnD;AAGA,SAAS,UAAU,GAAA,EAAqB;AAGtC,EAAA,OAAO,GAAA,CAAI,OAAA,CAAQ,YAAA,EAAc,GAAG,EAAE,IAAA,EAAK;AAC7C;AA8BO,SAAS,SAAA,CAOd,OAAA,EAKA,IAAA,GAAkD,EAAC,EAC3C;AACR,EAAA,MAAM,SAAA,GAAY,KAAK,SAAA,IAAa,IAAA;AACpC,EAAA,MAAM,YAAA,GAAe,IAAA,CAAK,OAAA,EAAS,MAAA,IAAU,EAAC;AAC9C,EAAA,MAAM,UAAA,GAAa,IAAA,CAAK,OAAA,EAAS,IAAA,IAAQ,EAAC;AAC1C,EAAA,MAAM,MAAA,GAAS,IAAA,CAAK,OAAA,KAAY,MAAA,IAAa,SAAS,IAAA,CAAK,OAAA;AAE3D,EAAA,MAAM,IAAA,GAAO,OAAO,OAAO,CAAA;AAC3B,EAAA,MAAM,QAAkB,EAAC;AAGzB,EAAA,IAAI,IAAA,CAAK,UAAU,MAAA,EAAW;AAC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AA,KAAA,CAAM,IAAA,CAAK,CAAA,eAAA,EAAkB,MAAA,CAAO,EAAE,CAAC,CAAA,CAAE,CAAA;AACzC,IAAA,KAAA,CAAM,IAAA,CAAK,CAAA,IAAA,EAAO,IAAI,CAAA,CAAE,CAAA;AACxB,IAAA,KAAA,CAAM,KAAK,YAAY,CAAA;AAAA,EACzB;AACF","file":"index.js","sourcesContent":["/**\n * @demlik/tea/machine-viz — turn a `Machine` into a Mermaid diagram string.\n *\n * PURE. No deps, no AST parsing, no file I/O. The function reads only the\n * `Machine` value it is handed plus optional sample states/msgs/ctx.\n *\n * The trick: TEA update cells are PURE (invariant 2 — they return\n * `[nextState, cmds]` as data, no effects). So we can SAFELY EXECUTE a cell to\n * discover its target state — exactly what `replay` does. That gives us REAL\n * edges (`red --> green : go`) without parsing source. When no sample is\n * provided for a `(state, msg)` pair we cannot resolve the target, so we fall\n * back to a STRUCTURAL self-edge annotated with `?` — visually distinct from a\n * resolved edge and documented in the diagram's legend.\n *\n * Form detection is `formOf(machine)` — the same reader `run`/`replay` use,\n * honoring the authoritative `__form` tag `defineMachine` stamps (falling back\n * to the structural heuristic for machines built without it; #275).\n *\n * What we MUST NOT do (these are the effectful paths, off-limits here):\n * - call `interpret[*]` handlers (perform I/O)\n * - call `subscribe[*]` handlers (install listeners)\n * - call `run` / the runtime\n * We MAY call `init`, `update[*]` cells, and `subscriptions(state)` — all pure\n * by the invariants (same set `replay` is allowed to touch).\n */\n\nimport type { Cmd, Machine, Sub } from \"../index\";\nimport { formOf } from \"../index\";\n\n// === Public options ===\n\n/**\n * Options controlling diagram emission.\n *\n * `samples` is the lever that turns STRUCTURAL edges into RESOLVED edges. For a\n * Transitions machine, providing a sample state for `stateType` AND a sample\n * msg for `msgType` lets us execute `update[stateType][msgType](state, msg)` and\n * read the real target `next.type`. Sample maps are keyed by the discriminant\n * string (`state.type` / `msg.type`).\n *\n * `samples.ctx` is the argument to `init(null, ctx)` — provide it to draw the\n * `[*] -->` initial-state edge. Omitted ⇒ no init edge (annotated as such),\n * because `init`'s signature requires a ctx and we will not invent one.\n */\nexport interface MachineVizOptions<S, M> {\n samples?: {\n /** Sample state per `state.type` — unlocks RESOLVED edges + sub annotations. */\n states?: Partial<Record<string, S>>;\n /** Sample msg per `msg.type` — unlocks RESOLVED edges. */\n msgs?: Partial<Record<string, M>>;\n /** Ctx for `init(null, ctx)` — unlocks the `[*] -->` initial-state edge. */\n ctx?: unknown;\n };\n /** Mermaid layout direction. Default `\"TB\"` (top-to-bottom). */\n direction?: \"TB\" | \"LR\";\n /** Optional diagram title, emitted as a Mermaid front-matter `title:` block. */\n title?: string;\n}\n\n// === Mermaid label escaping ===\n//\n// Mermaid state ids must be identifier-safe; arbitrary `type` strings (which\n// CAN contain `:`, spaces, `-`, etc.) are not. We sanitize the id used as the\n// node identifier and carry the human-readable original as a quoted label via\n// `stateId : \"Original\"` when they differ. Edge transition labels (after the\n// `:`) are sanitized to avoid breaking the arrow syntax.\n\n/** Sanitize a discriminant string into a Mermaid-safe node identifier. */\nfunction safeId(raw: string): string {\n // Replace any run of non-identifier chars with `_`; prefix a leading digit so\n // the id is always a valid Mermaid token. Empty ⇒ a stable placeholder.\n const cleaned = raw.replace(/[^A-Za-z0-9_]/g, \"_\");\n if (cleaned === \"\") return \"_empty\";\n return /^[0-9]/.test(cleaned) ? `s_${cleaned}` : cleaned;\n}\n\n/** Sanitize text used as a Mermaid edge/transition label (after the `:`). */\nfunction safeLabel(raw: string): string {\n // Strip the chars that terminate or confuse a transition label: newlines,\n // the `:` that separates label from target, and Mermaid's `\"`/`;` delimiters.\n return raw.replace(/[\"\\n\\r;:]/g, \" \").trim();\n}\n\n// === Edge model ===\n\ntype Edge =\n // Resolved: we executed the cell with samples and read the real target.\n | { kind: \"resolved\"; from: string; to: string; msg: string }\n // Structural: no samples for the pair → target unknown, drawn as a self-loop.\n | { kind: \"structural\"; from: string; msg: string };\n\n// === toMermaid ===\n\n/**\n * Render a `Machine` as a Mermaid `stateDiagram-v2` string.\n *\n * - **Transitions form** (`update` is a record-of-records): nodes are the\n * `state.type` keys; each `(stateType × msgType)` cell becomes an edge. With\n * samples for both, the edge is RESOLVED by executing the (pure) cell. Without\n * samples it is STRUCTURAL — a `from --> from : msg?` self-loop (the `?`\n * suffix marks \"target unresolved\"). A legend note documents the distinction.\n * The `[*] -->` init edge is drawn only when `samples.ctx` is provided.\n *\n * - **Reducer form** (`update` values are functions): there is no static phase\n * graph (state is not a discriminated union over phases). We emit a single\n * node listing the handled `msg.type`s and an honest note saying so. No edges\n * are invented.\n *\n * Output is deterministic for the same input (keys iterated in insertion order,\n * no clocks, no randomness).\n */\nexport function toMermaid<\n S,\n M extends { type: string },\n C extends Cmd,\n U extends Sub,\n Ctx,\n>(\n machine: Machine<S, M, C, U, Ctx>,\n // `NoInfer` pins S/M to the `machine` argument so sample object literals in\n // `opts` are CHECKED against the machine's State/Msg unions rather than\n // driving inference (which would widen `{ type: \"open\" }` to `{ type: string }`\n // and collide with the machine's discriminated union).\n opts: MachineVizOptions<NoInfer<S>, NoInfer<M>> = {},\n): string {\n const direction = opts.direction ?? \"TB\";\n const stateSamples = opts.samples?.states ?? {};\n const msgSamples = opts.samples?.msgs ?? {};\n const hasCtx = opts.samples !== undefined && \"ctx\" in opts.samples;\n\n const mode = formOf(machine);\n const lines: string[] = [];\n\n // Front matter — Mermaid reads a YAML `title:` block before the diagram.\n if (opts.title !== undefined) {\n lines.push(\"---\", `title: ${opts.title}`, \"---\");\n }\n lines.push(\"stateDiagram-v2\");\n lines.push(` direction ${direction}`);\n\n if (mode === \"reducer\") {\n emitReducer(machine, lines);\n } else {\n emitTransitions(machine, lines, {\n stateSamples,\n msgSamples,\n hasCtx,\n ctx: opts.samples?.ctx,\n });\n }\n\n // Subscriptions annotation — pure call to `subscriptions(sampleState)` per\n // sampled state. Skipped entirely when no state samples are provided (we\n // refuse to invent a state to feed it).\n emitSubscriptions(machine, lines, stateSamples);\n\n return lines.join(\"\\n\");\n}\n\n// === Reducer-form emission ===\n\n/**\n * Reducer form has no phase graph. Emit one node listing the handled msg types\n * plus an honest note. The msg set is the `update` record's keys (the Reducer\n * mapped type guarantees one cell per Msg variant).\n */\nfunction emitReducer(machine: { update: unknown }, lines: string[]): void {\n const msgTypes = Object.keys(machine.update as object);\n lines.push(\" state ReducerMachine {\");\n if (msgTypes.length === 0) {\n lines.push(\" [*] --> NoMsgs\");\n lines.push(' NoMsgs : \"(no msg variants — M is never)\"');\n } else {\n for (const m of msgTypes) {\n lines.push(` ${safeId(m)} : ${safeLabel(m)}`);\n }\n }\n lines.push(\" }\");\n // The note IS the design honesty: no edges, because reducer-form state is not\n // a discriminated union over phases — there is no static target to draw.\n lines.push(\" note right of ReducerMachine\");\n lines.push(\" Reducer-form machine: flat dispatch keyed by msg.type.\");\n lines.push(\n \" No phase graph — state is not a discriminated union over phases.\",\n );\n lines.push(` Handled msg types: ${msgTypes.length}`);\n lines.push(\" end note\");\n}\n\n// === Transitions-form emission ===\n\ninterface TransitionsCtx<S, M> {\n stateSamples: Partial<Record<string, S>>;\n msgSamples: Partial<Record<string, M>>;\n hasCtx: boolean;\n ctx: unknown;\n}\n\n/**\n * Transitions form: walk the `update[stateType][msgType]` table. Execute the\n * (pure) cell when both samples exist → RESOLVED edge; otherwise → STRUCTURAL\n * self-loop. Draw the `[*] -->` init edge only when a ctx sample is given.\n */\nfunction emitTransitions<\n S,\n M extends { type: string },\n C extends Cmd,\n U extends Sub,\n Ctx,\n>(\n machine: Machine<S, M, C, U, Ctx>,\n lines: string[],\n ctx: TransitionsCtx<S, M>,\n): void {\n type CellFn = (state: S, msg: M) => readonly [S, readonly C[]];\n type Table = Record<string, Record<string, CellFn>>;\n const table = machine.update as unknown as Table;\n const stateTypes = Object.keys(table);\n\n // Declare every node up front so even unreachable phases render.\n for (const st of stateTypes) {\n lines.push(` ${safeId(st)}`);\n }\n\n // Init edge — only resolvable with a ctx sample. `init(null, ctx)` is pure\n // (invariant 2: fresh-boot branch returns a starting state). Read `next.type`.\n if (ctx.hasCtx) {\n const [initState] = machine.init(null, ctx.ctx as Ctx);\n const initType = (initState as unknown as { type: string }).type;\n lines.push(` [*] --> ${safeId(initType)}`);\n } else {\n lines.push(\n \" %% init edge omitted: no samples.ctx provided to run init(null, ctx)\",\n );\n }\n\n let anyStructural = false;\n for (const st of stateTypes) {\n const row = table[st];\n if (row === undefined) continue;\n const msgTypes = Object.keys(row);\n for (const mt of msgTypes) {\n const edge = resolveEdge(row, st, mt, ctx);\n if (edge.kind === \"resolved\") {\n lines.push(\n ` ${safeId(edge.from)} --> ${safeId(edge.to)} : ${safeLabel(edge.msg)}`,\n );\n } else {\n anyStructural = true;\n // Structural self-loop with a `?` suffix — target unresolved. Visually\n // distinct from a resolved edge (self-loop + trailing `?`).\n lines.push(\n ` ${safeId(edge.from)} --> ${safeId(edge.from)} : ${safeLabel(edge.msg)}?`,\n );\n }\n }\n }\n\n // Legend — document the resolved-vs-structural distinction in the output.\n lines.push(` note right of ${safeId(stateTypes[0] ?? \"_empty\")}`);\n lines.push(\" Transitions-form machine.\");\n lines.push(\" Edge a --> b : msg = RESOLVED (cell executed with samples).\");\n if (anyStructural) {\n lines.push(\n \" Self-loop a --> a : msg? = STRUCTURAL (no sample; target unresolved).\",\n );\n }\n lines.push(\" end note\");\n}\n\n/**\n * Resolve a single `(stateType, msgType)` cell into an Edge. With both a sample\n * state and a sample msg, EXECUTE the pure cell to read the real target. Any\n * missing sample → structural. A thrown cell (e.g. a sample shaped wrong for\n * the cell) degrades to structural rather than crashing the whole diagram —\n * the diagram is a best-effort visualization, not a correctness gate.\n */\nfunction resolveEdge<S, M extends { type: string }, C extends Cmd>(\n row: Record<string, (state: S, msg: M) => readonly [S, readonly C[]]>,\n stateType: string,\n msgType: string,\n ctx: {\n stateSamples: Partial<Record<string, S>>;\n msgSamples: Partial<Record<string, M>>;\n },\n): Edge {\n const sampleState = ctx.stateSamples[stateType];\n const sampleMsg = ctx.msgSamples[msgType];\n const cell = row[msgType];\n if (\n sampleState === undefined ||\n sampleMsg === undefined ||\n cell === undefined\n ) {\n return { kind: \"structural\", from: stateType, msg: msgType };\n }\n try {\n const [next] = cell(sampleState, sampleMsg);\n const to = (next as unknown as { type: string }).type;\n return { kind: \"resolved\", from: stateType, to, msg: msgType };\n } catch {\n // Mismatched sample → cannot resolve. Fall back to structural.\n return { kind: \"structural\", from: stateType, msg: msgType };\n }\n}\n\n// === Subscriptions annotation ===\n\n/**\n * For each sampled state, call the (pure) `subscriptions(state)` description\n * function and annotate which Sub types are active in that state as a Mermaid\n * note. We call `subscriptions` (the description) but NEVER `subscribe[*]` (the\n * effectful installer) — same boundary `replay` honors. Skipped when no state\n * samples are provided or the machine declares no `subscriptions`.\n */\nfunction emitSubscriptions<\n S,\n M extends { type: string },\n C extends Cmd,\n U extends Sub,\n Ctx,\n>(\n machine: Machine<S, M, C, U, Ctx>,\n lines: string[],\n stateSamples: Partial<Record<string, S>>,\n): void {\n if (machine.subscriptions === undefined) return;\n const stateTypes = Object.keys(stateSamples);\n if (stateTypes.length === 0) return;\n\n for (const st of stateTypes) {\n const sample = stateSamples[st];\n if (sample === undefined) continue;\n const subs = machine.subscriptions(sample);\n const subTypes = subs.map((s) => s.type);\n const body =\n subTypes.length === 0\n ? \"(no active subs)\"\n : `subs: ${subTypes.map(safeLabel).join(\", \")}`;\n lines.push(` note left of ${safeId(st)}`);\n lines.push(` ${body}`);\n lines.push(\" end note\");\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/machine-viz/index.ts"],"names":[],"mappings":";;;;;;AA6FO,SAAS,SAAA,CAOd,OAAA,EAKA,IAAA,GAAkD,EAAC,EAC3C;AACR,EAAA,MAAM,SAAA,GAAY,KAAK,SAAA,IAAa,IAAA;AACpC,EAAA,MAAM,YAAA,GAAe,IAAA,CAAK,OAAA,EAAS,MAAA,IAAU,EAAC;AAC9C,EAAA,MAAM,UAAA,GAAa,IAAA,CAAK,OAAA,EAAS,IAAA,IAAQ,EAAC;AAC1C,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CAAC,CAAA,KAAM,EAAE,IAAI,CAAA;AACvC,IAAA,MAAM,IAAA,GACJ,QAAA,CAAS,MAAA,KAAW,CAAA,GAChB,kBAAA,GACA,CAAA,MAAA,EAAS,QAAA,CAAS,GAAA,CAAI,SAAS,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,CAAA;AACjD,IAAA,KAAA,CAAM,IAAA,CAAK,CAAA,eAAA,EAAkB,MAAA,CAAO,EAAE,CAAC,CAAA,CAAE,CAAA;AACzC,IAAA,KAAA,CAAM,IAAA,CAAK,CAAA,IAAA,EAAO,IAAI,CAAA,CAAE,CAAA;AACxB,IAAA,KAAA,CAAM,KAAK,YAAY,CAAA;AAAA,EACzB;AACF","file":"index.js","sourcesContent":["/**\n * @demlik/tea/machine-viz — turn a `Machine` into a Mermaid diagram string.\n *\n * PURE. No deps, no AST parsing, no file I/O. The function reads only the\n * `Machine` value it is handed plus optional sample states/msgs/ctx.\n *\n * The trick: TEA update cells are PURE (invariant 2 — they return\n * `[nextState, cmds]` as data, no effects). So we can SAFELY EXECUTE a cell to\n * discover its target state — exactly what `replay` does. That gives us REAL\n * edges (`red --> green : go`) without parsing source. When no sample is\n * provided for a `(state, msg)` pair we cannot resolve the target, so we fall\n * back to a STRUCTURAL self-edge annotated with `?` — visually distinct from a\n * resolved edge and documented in the diagram's legend.\n *\n * Form detection is `formOf(machine)` — the same reader `run`/`replay` use,\n * honoring the authoritative `__form` tag `defineMachine` stamps (falling back\n * to the structural heuristic for machines built without it; #275).\n *\n * What we MUST NOT do (these are the effectful paths, off-limits here):\n * - call `interpret[*]` handlers (perform I/O)\n * - call `subscribe[*]` handlers (install listeners)\n * - call `run` / the runtime\n * We MAY call `init`, `update[*]` cells, and `subscriptions(state)` — all pure\n * by the invariants (same set `replay` is allowed to touch).\n */\n\nimport type { Cmd, Machine, Sub } from \"../index\";\nimport { formOf } from \"../index\";\nimport { safeId, safeLabel } from \"./mermaid-id\";\n\n// The sanitizers are SHARED with `chart`'s `chartMermaid` — one copy, in a\n// dependency-free module, re-exported here because both drawings are public\n// and a consumer post-processing either one needs the same escaping.\nexport { safeId, safeLabel } from \"./mermaid-id\";\n\n// === Public options ===\n\n/**\n * Options controlling diagram emission.\n *\n * `samples` is the lever that turns STRUCTURAL edges into RESOLVED edges. For a\n * Transitions machine, providing a sample state for `stateType` AND a sample\n * msg for `msgType` lets us execute `update[stateType][msgType](state, msg)` and\n * read the real target `next.type`. Sample maps are keyed by the discriminant\n * string (`state.type` / `msg.type`).\n *\n * `samples.ctx` is the argument to `init(null, ctx)` — provide it to draw the\n * `[*] -->` initial-state edge. Omitted ⇒ no init edge (annotated as such),\n * because `init`'s signature requires a ctx and we will not invent one.\n */\nexport interface MachineVizOptions<S, M> {\n samples?: {\n /** Sample state per `state.type` — unlocks RESOLVED edges + sub annotations. */\n states?: Partial<Record<string, S>>;\n /** Sample msg per `msg.type` — unlocks RESOLVED edges. */\n msgs?: Partial<Record<string, M>>;\n /** Ctx for `init(null, ctx)` — unlocks the `[*] -->` initial-state edge. */\n ctx?: unknown;\n };\n /** Mermaid layout direction. Default `\"TB\"` (top-to-bottom). */\n direction?: \"TB\" | \"LR\";\n /** Optional diagram title, emitted as a Mermaid front-matter `title:` block. */\n title?: string;\n}\n\n// === Edge model ===\n\ntype Edge =\n // Resolved: we executed the cell with samples and read the real target.\n | { kind: \"resolved\"; from: string; to: string; msg: string }\n // Structural: no samples for the pair → target unknown, drawn as a self-loop.\n | { kind: \"structural\"; from: string; msg: string };\n\n// === toMermaid ===\n\n/**\n * Render a `Machine` as a Mermaid `stateDiagram-v2` string.\n *\n * - **Transitions form** (`update` is a record-of-records): nodes are the\n * `state.type` keys; each `(stateType × msgType)` cell becomes an edge. With\n * samples for both, the edge is RESOLVED by executing the (pure) cell. Without\n * samples it is STRUCTURAL — a `from --> from : msg?` self-loop (the `?`\n * suffix marks \"target unresolved\"). A legend note documents the distinction.\n * The `[*] -->` init edge is drawn only when `samples.ctx` is provided.\n *\n * - **Reducer form** (`update` values are functions): there is no static phase\n * graph (state is not a discriminated union over phases). We emit a single\n * node listing the handled `msg.type`s and an honest note saying so. No edges\n * are invented.\n *\n * Output is deterministic for the same input (keys iterated in insertion order,\n * no clocks, no randomness).\n */\nexport function toMermaid<\n S,\n M extends { type: string },\n C extends Cmd,\n U extends Sub,\n Ctx,\n>(\n machine: Machine<S, M, C, U, Ctx>,\n // `NoInfer` pins S/M to the `machine` argument so sample object literals in\n // `opts` are CHECKED against the machine's State/Msg unions rather than\n // driving inference (which would widen `{ type: \"open\" }` to `{ type: string }`\n // and collide with the machine's discriminated union).\n opts: MachineVizOptions<NoInfer<S>, NoInfer<M>> = {},\n): string {\n const direction = opts.direction ?? \"TB\";\n const stateSamples = opts.samples?.states ?? {};\n const msgSamples = opts.samples?.msgs ?? {};\n const hasCtx = opts.samples !== undefined && \"ctx\" in opts.samples;\n\n const mode = formOf(machine);\n const lines: string[] = [];\n\n // Front matter — Mermaid reads a YAML `title:` block before the diagram.\n if (opts.title !== undefined) {\n lines.push(\"---\", `title: ${opts.title}`, \"---\");\n }\n lines.push(\"stateDiagram-v2\");\n lines.push(` direction ${direction}`);\n\n if (mode === \"reducer\") {\n emitReducer(machine, lines);\n } else {\n emitTransitions(machine, lines, {\n stateSamples,\n msgSamples,\n hasCtx,\n ctx: opts.samples?.ctx,\n });\n }\n\n // Subscriptions annotation — pure call to `subscriptions(sampleState)` per\n // sampled state. Skipped entirely when no state samples are provided (we\n // refuse to invent a state to feed it).\n emitSubscriptions(machine, lines, stateSamples);\n\n return lines.join(\"\\n\");\n}\n\n// === Reducer-form emission ===\n\n/**\n * Reducer form has no phase graph. Emit one node listing the handled msg types\n * plus an honest note. The msg set is the `update` record's keys (the Reducer\n * mapped type guarantees one cell per Msg variant).\n */\nfunction emitReducer(machine: { update: unknown }, lines: string[]): void {\n const msgTypes = Object.keys(machine.update as object);\n lines.push(\" state ReducerMachine {\");\n if (msgTypes.length === 0) {\n lines.push(\" [*] --> NoMsgs\");\n lines.push(' NoMsgs : \"(no msg variants — M is never)\"');\n } else {\n for (const m of msgTypes) {\n lines.push(` ${safeId(m)} : ${safeLabel(m)}`);\n }\n }\n lines.push(\" }\");\n // The note IS the design honesty: no edges, because reducer-form state is not\n // a discriminated union over phases — there is no static target to draw.\n lines.push(\" note right of ReducerMachine\");\n lines.push(\" Reducer-form machine: flat dispatch keyed by msg.type.\");\n lines.push(\n \" No phase graph — state is not a discriminated union over phases.\",\n );\n lines.push(` Handled msg types: ${msgTypes.length}`);\n lines.push(\" end note\");\n}\n\n// === Transitions-form emission ===\n\ninterface TransitionsCtx<S, M> {\n stateSamples: Partial<Record<string, S>>;\n msgSamples: Partial<Record<string, M>>;\n hasCtx: boolean;\n ctx: unknown;\n}\n\n/**\n * Transitions form: walk the `update[stateType][msgType]` table. Execute the\n * (pure) cell when both samples exist → RESOLVED edge; otherwise → STRUCTURAL\n * self-loop. Draw the `[*] -->` init edge only when a ctx sample is given.\n */\nfunction emitTransitions<\n S,\n M extends { type: string },\n C extends Cmd,\n U extends Sub,\n Ctx,\n>(\n machine: Machine<S, M, C, U, Ctx>,\n lines: string[],\n ctx: TransitionsCtx<S, M>,\n): void {\n type CellFn = (state: S, msg: M) => readonly [S, readonly C[]];\n type Table = Record<string, Record<string, CellFn>>;\n const table = machine.update as unknown as Table;\n const stateTypes = Object.keys(table);\n\n // Declare every node up front so even unreachable phases render.\n for (const st of stateTypes) {\n lines.push(` ${safeId(st)}`);\n }\n\n // Init edge — only resolvable with a ctx sample. `init(null, ctx)` is pure\n // (invariant 2: fresh-boot branch returns a starting state). Read `next.type`.\n if (ctx.hasCtx) {\n const [initState] = machine.init(null, ctx.ctx as Ctx);\n const initType = (initState as unknown as { type: string }).type;\n lines.push(` [*] --> ${safeId(initType)}`);\n } else {\n lines.push(\n \" %% init edge omitted: no samples.ctx provided to run init(null, ctx)\",\n );\n }\n\n let anyStructural = false;\n for (const st of stateTypes) {\n const row = table[st];\n if (row === undefined) continue;\n const msgTypes = Object.keys(row);\n for (const mt of msgTypes) {\n const edge = resolveEdge(row, st, mt, ctx);\n if (edge.kind === \"resolved\") {\n lines.push(\n ` ${safeId(edge.from)} --> ${safeId(edge.to)} : ${safeLabel(edge.msg)}`,\n );\n } else {\n anyStructural = true;\n // Structural self-loop with a `?` suffix — target unresolved. Visually\n // distinct from a resolved edge (self-loop + trailing `?`).\n lines.push(\n ` ${safeId(edge.from)} --> ${safeId(edge.from)} : ${safeLabel(edge.msg)}?`,\n );\n }\n }\n }\n\n // Legend — document the resolved-vs-structural distinction in the output.\n lines.push(` note right of ${safeId(stateTypes[0] ?? \"_empty\")}`);\n lines.push(\" Transitions-form machine.\");\n lines.push(\" Edge a --> b : msg = RESOLVED (cell executed with samples).\");\n if (anyStructural) {\n lines.push(\n \" Self-loop a --> a : msg? = STRUCTURAL (no sample; target unresolved).\",\n );\n }\n lines.push(\" end note\");\n}\n\n/**\n * Resolve a single `(stateType, msgType)` cell into an Edge. With both a sample\n * state and a sample msg, EXECUTE the pure cell to read the real target. Any\n * missing sample → structural. A thrown cell (e.g. a sample shaped wrong for\n * the cell) degrades to structural rather than crashing the whole diagram —\n * the diagram is a best-effort visualization, not a correctness gate.\n */\nfunction resolveEdge<S, M extends { type: string }, C extends Cmd>(\n row: Record<string, (state: S, msg: M) => readonly [S, readonly C[]]>,\n stateType: string,\n msgType: string,\n ctx: {\n stateSamples: Partial<Record<string, S>>;\n msgSamples: Partial<Record<string, M>>;\n },\n): Edge {\n const sampleState = ctx.stateSamples[stateType];\n const sampleMsg = ctx.msgSamples[msgType];\n const cell = row[msgType];\n if (\n sampleState === undefined ||\n sampleMsg === undefined ||\n cell === undefined\n ) {\n return { kind: \"structural\", from: stateType, msg: msgType };\n }\n try {\n const [next] = cell(sampleState, sampleMsg);\n const to = (next as unknown as { type: string }).type;\n return { kind: \"resolved\", from: stateType, to, msg: msgType };\n } catch {\n // Mismatched sample → cannot resolve. Fall back to structural.\n return { kind: \"structural\", from: stateType, msg: msgType };\n }\n}\n\n// === Subscriptions annotation ===\n\n/**\n * For each sampled state, call the (pure) `subscriptions(state)` description\n * function and annotate which Sub types are active in that state as a Mermaid\n * note. We call `subscriptions` (the description) but NEVER `subscribe[*]` (the\n * effectful installer) — same boundary `replay` honors. Skipped when no state\n * samples are provided or the machine declares no `subscriptions`.\n */\nfunction emitSubscriptions<\n S,\n M extends { type: string },\n C extends Cmd,\n U extends Sub,\n Ctx,\n>(\n machine: Machine<S, M, C, U, Ctx>,\n lines: string[],\n stateSamples: Partial<Record<string, S>>,\n): void {\n if (machine.subscriptions === undefined) return;\n const stateTypes = Object.keys(stateSamples);\n if (stateTypes.length === 0) return;\n\n for (const st of stateTypes) {\n const sample = stateSamples[st];\n if (sample === undefined) continue;\n const subs = machine.subscriptions(sample);\n const subTypes = subs.map((s) => s.type);\n const body =\n subTypes.length === 0\n ? \"(no active subs)\"\n : `subs: ${subTypes.map(safeLabel).join(\", \")}`;\n lines.push(` note left of ${safeId(st)}`);\n lines.push(` ${body}`);\n lines.push(\" end note\");\n }\n}\n"]}
|
package/dist/mem/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { DeadlineExceeded, DeadlineSub } from '../deadline/index.js';
|
|
2
2
|
export { deadlineSub, subscribeDeadline } from '../deadline/index.js';
|
|
3
|
-
import { I as Interpret, C as Cmd } from '../core-
|
|
3
|
+
import { I as Interpret, C as Cmd } from '../core-Bjc0bS8j.js';
|
|
4
4
|
import { SnapshotWriteCmd, SnapshotState, SnapshotStore, SnapshotSavedMsg, SnapshotFailedMsg, SnapshotLoadedMsg, SnapshotLoadFailedMsg, SnapshotLoadCmd } from '../snapshot/index.js';
|
|
5
5
|
import { QueueItem } from '../work-queue/index.js';
|
|
6
|
-
import '../types-
|
|
7
|
-
import '../runtime-types-
|
|
6
|
+
import '../types-D7u9DkH7.js';
|
|
7
|
+
import '../runtime-types-Bxc637bp.js';
|
|
8
|
+
import 'better-result';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @demlik/tea/monitored-run — a long-running operation that is BOTH staged and
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export { createMonitoredRun, liftRun } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
3
|
-
export { deadlineSub, subscribeDeadline } from '../chunk-
|
|
1
|
+
export { createMonitoredRun, liftRun } from '../chunk-WLGO64WC.js';
|
|
2
|
+
import '../chunk-7V4EVLZA.js';
|
|
3
|
+
export { deadlineSub, subscribeDeadline } from '../chunk-JGVL3WPL.js';
|
|
4
4
|
import '../chunk-MU6MCIAC.js';
|
|
5
5
|
import '../chunk-FV3Z5MBE.js';
|
|
6
6
|
import '../chunk-2YFLOCWX.js';
|
|
7
|
-
import '../chunk-
|
|
8
|
-
import '../chunk-
|
|
7
|
+
import '../chunk-5EHLEUTL.js';
|
|
8
|
+
import '../chunk-B5VXOFMZ.js';
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
|
10
10
|
//# sourceMappingURL=index.js.map
|
package/dist/node/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import WebSocket from 'ws';
|
|
2
|
-
import { S as Store } from '../runtime-types-
|
|
3
|
-
import { S as Sub, b as SubId } from '../core-
|
|
2
|
+
import { S as Store } from '../runtime-types-Bxc637bp.js';
|
|
3
|
+
import { S as Sub, b as SubId } from '../core-Bjc0bS8j.js';
|
|
4
|
+
import 'better-result';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @packageDocumentation
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { C as Cmd } from '../core-
|
|
1
|
+
import { C as Cmd } from '../core-Bjc0bS8j.js';
|
|
2
2
|
import { PaginatorState } from '../paginator/index.js';
|
|
3
3
|
import { RunCmd, FailMsg, SucceedMsg, CircuitConfig, RateLimitConfig, DeadlineConfig, ResilientPorts, ResilientState, ResilientTimerMsg } from '../resilient-call/index.js';
|
|
4
4
|
import { RetryPolicy } from '../retry-backoff/index.js';
|
|
5
5
|
import { DeadlineSub } from '../deadline/index.js';
|
|
6
6
|
export { deadlineSub, subscribeDeadline } from '../deadline/index.js';
|
|
7
7
|
import '../cache/index.js';
|
|
8
|
-
import '../types-
|
|
8
|
+
import '../types-D7u9DkH7.js';
|
|
9
9
|
import '../circuit-breaker/index.js';
|
|
10
10
|
import '../protocol-B5YmJr0d.js';
|
|
11
11
|
import '../rate-limit/index.js';
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export { PAGE_KEY, createPaginatedWalk, liftWalk } from '../chunk-
|
|
1
|
+
export { PAGE_KEY, createPaginatedWalk, liftWalk } from '../chunk-I5OV65MS.js';
|
|
2
2
|
import '../chunk-SINXE47Y.js';
|
|
3
|
-
import '../chunk-
|
|
3
|
+
import '../chunk-EUF7XOEE.js';
|
|
4
4
|
import '../chunk-JELSZN25.js';
|
|
5
|
-
export { deadlineSub, subscribeDeadline } from '../chunk-
|
|
5
|
+
export { deadlineSub, subscribeDeadline } from '../chunk-JGVL3WPL.js';
|
|
6
6
|
import '../chunk-Q2UM7BXU.js';
|
|
7
7
|
import '../chunk-S2EGRPCM.js';
|
|
8
8
|
import '../chunk-UF4MZSLT.js';
|
|
9
|
-
import '../chunk-
|
|
10
|
-
import '../chunk-
|
|
9
|
+
import '../chunk-7SVIRMC6.js';
|
|
10
|
+
import '../chunk-3JU6657S.js';
|
|
11
11
|
import '../chunk-2YFLOCWX.js';
|
|
12
12
|
import '../chunk-ZJ5AOYBH.js';
|
|
13
|
-
import '../chunk-
|
|
14
|
-
import '../chunk-
|
|
13
|
+
import '../chunk-5EHLEUTL.js';
|
|
14
|
+
import '../chunk-B5VXOFMZ.js';
|
|
15
15
|
//# sourceMappingURL=index.js.map
|
|
16
16
|
//# sourceMappingURL=index.js.map
|
package/dist/parity/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { B as BootingRuntime } from '../runtime-types-
|
|
2
|
-
import { C as Cmd, S as Sub, M as Machine } from '../core-
|
|
1
|
+
import { B as BootingRuntime } from '../runtime-types-Bxc637bp.js';
|
|
2
|
+
import { C as Cmd, S as Sub, M as Machine } from '../core-Bjc0bS8j.js';
|
|
3
3
|
import { Trace, RecorderOptions } from '../recorder/index.js';
|
|
4
|
+
import 'better-result';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* the record → replay → normalized-diff go/no-go gate.
|
package/dist/parity/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { recorder } from '../chunk-MUUROGIH.js';
|
|
2
|
-
import { deepEqual } from '../chunk-
|
|
2
|
+
import { deepEqual } from '../chunk-SUST46KO.js';
|
|
3
3
|
import '../chunk-EWJP3YYP.js';
|
|
4
|
-
import { replay } from '../chunk-
|
|
5
|
-
import '../chunk-
|
|
4
|
+
import { replay } from '../chunk-5EHLEUTL.js';
|
|
5
|
+
import '../chunk-B5VXOFMZ.js';
|
|
6
6
|
|
|
7
7
|
// src/parity/index.ts
|
|
8
8
|
function recordRun(runtime, opts) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as fc from 'fast-check';
|
|
2
|
-
import { C as Cmd, S as Sub, M as Machine } from '../../core-
|
|
2
|
+
import { C as Cmd, S as Sub, M as Machine } from '../../core-Bjc0bS8j.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Build a Ctx value whose every property access throws. Use as the `ctx`
|
package/dist/pbt/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { MsgArbitraryTable, arbConstantMsg, arbGuidedSequence, arbMsg, arbMsgSequence, arbRecordMsg, stubCtxThrowingProxy } from './arbitraries/index.js';
|
|
2
2
|
export { Step, foldEvents, propertyInvariant, propertyTerminates, propertyTrace } from './runners/index.js';
|
|
3
|
-
import { C as Cmd, R as Reducer, T as Transitions, U as UpdateForm } from '../core-
|
|
3
|
+
import { C as Cmd, R as Reducer, T as Transitions, U as UpdateForm } from '../core-Bjc0bS8j.js';
|
|
4
4
|
import 'fast-check';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/pbt/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { arbConstantMsg, arbGuidedSequence, arbMsg, arbMsgSequence, arbRecordMsg, stubCtxThrowingProxy } from '../chunk-AZZLE7XR.js';
|
|
2
|
-
export { foldEvents, propertyInvariant, propertyTerminates, propertyTrace } from '../chunk-
|
|
3
|
-
import '../chunk-
|
|
4
|
-
import { msgKeysOf } from '../chunk-
|
|
2
|
+
export { foldEvents, propertyInvariant, propertyTerminates, propertyTrace } from '../chunk-JP5D6GSL.js';
|
|
3
|
+
import '../chunk-5EHLEUTL.js';
|
|
4
|
+
import { msgKeysOf } from '../chunk-B5VXOFMZ.js';
|
|
5
5
|
|
|
6
6
|
// src/pbt/util/msg-keys.ts
|
|
7
7
|
function msgTypeKeys(machine) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { foldEvents, propertyInvariant, propertyTerminates, propertyTrace } from '../../chunk-
|
|
2
|
-
import '../../chunk-
|
|
3
|
-
import '../../chunk-
|
|
1
|
+
export { foldEvents, propertyInvariant, propertyTerminates, propertyTrace } from '../../chunk-JP5D6GSL.js';
|
|
2
|
+
import '../../chunk-5EHLEUTL.js';
|
|
3
|
+
import '../../chunk-B5VXOFMZ.js';
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/dist/poller/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DeadlineSub } from '../deadline/index.js';
|
|
2
2
|
import { IdempotencyStore } from '../idempotency/index.js';
|
|
3
|
-
import { C as Cmd, S as Sub } from '../core-
|
|
3
|
+
import { C as Cmd, S as Sub } from '../core-Bjc0bS8j.js';
|
|
4
4
|
import { RetryState, AnyRetryPolicy } from '../retry-backoff/index.js';
|
|
5
|
-
import '../types-
|
|
5
|
+
import '../types-D7u9DkH7.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @demlik/tea/poller — "poll a source every N ms until a predicate holds, with
|
|
@@ -203,6 +203,27 @@ type PollerState<R> = (PollerCore<R> & {
|
|
|
203
203
|
}) | (PollerCore<R> & {
|
|
204
204
|
readonly phase: "gave_up";
|
|
205
205
|
});
|
|
206
|
+
/**
|
|
207
|
+
* The three arms, named — so a verb can DECLARE the phases it can actually
|
|
208
|
+
* reach instead of the whole union.
|
|
209
|
+
*
|
|
210
|
+
* A verb whose return type is the full `PollerState<R>` tells a caller nothing
|
|
211
|
+
* about where the poller went, and a caller that needs to know (a chart
|
|
212
|
+
* declaring an edge's fan-out; an exhaustive `switch`) has to re-derive it by
|
|
213
|
+
* reading the verb's body. Every one of these narrowings is already true of the
|
|
214
|
+
* implementation — `start` only ever builds a `polling` arm, `tickResult` never
|
|
215
|
+
* builds `gave_up`, `tickErr` never builds `done` — so naming them costs
|
|
216
|
+
* nothing at runtime and moves a fact out of the source and into the signature.
|
|
217
|
+
*/
|
|
218
|
+
type PollerPolling<R> = Extract<PollerState<R>, {
|
|
219
|
+
phase: "polling";
|
|
220
|
+
}>;
|
|
221
|
+
type PollerDone<R> = Extract<PollerState<R>, {
|
|
222
|
+
phase: "done";
|
|
223
|
+
}>;
|
|
224
|
+
type PollerGaveUp<R> = Extract<PollerState<R>, {
|
|
225
|
+
phase: "gave_up";
|
|
226
|
+
}>;
|
|
206
227
|
/**
|
|
207
228
|
* The poller Sub type — a `../deadline` Sub under a fixed id family. One id per
|
|
208
229
|
* knob instance keeps the reconcile pass from churning the timer: the same id
|
|
@@ -223,7 +244,7 @@ type PollerSub = DeadlineSub;
|
|
|
223
244
|
*/
|
|
224
245
|
interface Poller<State, R> {
|
|
225
246
|
/** Seed the Model slice. Idle until `start(...)` arms the first tick. */
|
|
226
|
-
init():
|
|
247
|
+
init(): PollerPolling<R>;
|
|
227
248
|
/**
|
|
228
249
|
* Arm the first tick. `at` is the current clock (carried in from the Msg /
|
|
229
250
|
* runtime that kicks the poller off — never read inside the verb). Returns
|
|
@@ -234,7 +255,7 @@ interface Poller<State, R> {
|
|
|
234
255
|
* fires when the deadline crosses `at + everyMs` and the consumer routes
|
|
235
256
|
* `deadline_exceeded` → `tick`.
|
|
236
257
|
*/
|
|
237
|
-
start(state: PollerState<R>, at: number): readonly [
|
|
258
|
+
start(state: PollerState<R>, at: number): readonly [PollerPolling<R>, readonly Cmd[]];
|
|
238
259
|
/**
|
|
239
260
|
* Perform one observation — the cadence verb. The consumer routes the
|
|
240
261
|
* deadline Sub's `deadline_exceeded` Msg here; `tick` emits the single
|
|
@@ -274,7 +295,7 @@ interface Poller<State, R> {
|
|
|
274
295
|
* passes the boolean. (`subs` re-checks `phase` to decide arming, so a
|
|
275
296
|
* mis-passed `untilHeld` cannot leave a "done" poller arming timers.)
|
|
276
297
|
*/
|
|
277
|
-
tickResult(state: PollerState<R>, result: R, at: number, untilHeld: boolean): readonly [
|
|
298
|
+
tickResult(state: PollerState<R>, result: R, at: number, untilHeld: boolean): readonly [PollerPolling<R> | PollerDone<R>, readonly Cmd[]];
|
|
278
299
|
/**
|
|
279
300
|
* Record a FAILED tick at clock `at`. Backs off instead of holding the
|
|
280
301
|
* steady cadence:
|
|
@@ -300,7 +321,7 @@ interface Poller<State, R> {
|
|
|
300
321
|
* body never names the global RNG, so a poller built with a fixed `rng`
|
|
301
322
|
* replays a failure-and-backoff run bit-for-bit.
|
|
302
323
|
*/
|
|
303
|
-
tickErr(state: PollerState<R>, error: unknown, at: number): readonly [
|
|
324
|
+
tickErr(state: PollerState<R>, error: unknown, at: number): readonly [PollerPolling<R> | PollerGaveUp<R>, readonly Cmd[]];
|
|
304
325
|
/**
|
|
305
326
|
* The pre-wired subscriptions cell. Returns the single tick-deadline Sub
|
|
306
327
|
* while the poller is `"polling"` with an armed `nextAtMs`; returns `[]`
|
|
@@ -327,4 +348,4 @@ interface Poller<State, R> {
|
|
|
327
348
|
*/
|
|
328
349
|
declare function createPoller<State, R>(config: PollerConfig<State, R>, rng?: () => number): Poller<State, R>;
|
|
329
350
|
|
|
330
|
-
export { type Poller, type PollerConfig, type PollerState, type PollerSub, createPoller };
|
|
351
|
+
export { type Poller, type PollerConfig, type PollerDone, type PollerGaveUp, type PollerPolling, type PollerState, type PollerSub, createPoller };
|
package/dist/poller/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { deadlineSub } from '../chunk-
|
|
1
|
+
import { deadlineSub } from '../chunk-JGVL3WPL.js';
|
|
2
2
|
import { asRng, defaultRetryPolicy, initRetry, recordFailure, shouldRetry, nextDelayMs } from '../chunk-Q2UM7BXU.js';
|
|
3
3
|
import { idempotencyMemory } from '../chunk-BYQUGDD3.js';
|
|
4
4
|
import '../chunk-K575PT4S.js';
|
|
5
5
|
import '../chunk-2YFLOCWX.js';
|
|
6
|
-
import '../chunk-
|
|
7
|
-
import '../chunk-
|
|
6
|
+
import '../chunk-5EHLEUTL.js';
|
|
7
|
+
import '../chunk-B5VXOFMZ.js';
|
|
8
8
|
|
|
9
9
|
// src/poller/index.ts
|
|
10
10
|
function pollerSubId(atMs) {
|