@demlik/tea 0.21.0 → 0.22.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.
Files changed (126) hide show
  1. package/dist/agent/index.d.ts +32 -19
  2. package/dist/agent/index.js +12 -10
  3. package/dist/{chunk-VM7PMFV5.js → chunk-2A5XTKQQ.js} +142 -19
  4. package/dist/chunk-2A5XTKQQ.js.map +1 -0
  5. package/dist/{chunk-EB5OMOXX.js → chunk-7K7SEYCH.js} +16 -15
  6. package/dist/chunk-7K7SEYCH.js.map +1 -0
  7. package/dist/{chunk-GAVLND5C.js → chunk-A3QPMX5M.js} +17 -10
  8. package/dist/chunk-A3QPMX5M.js.map +1 -0
  9. package/dist/{chunk-VHKDUBXC.js → chunk-BVFS3ICC.js} +3 -3
  10. package/dist/{chunk-VHKDUBXC.js.map → chunk-BVFS3ICC.js.map} +1 -1
  11. package/dist/{chunk-4I2LCQKB.js → chunk-CPE5ZQXQ.js} +3 -3
  12. package/dist/{chunk-4I2LCQKB.js.map → chunk-CPE5ZQXQ.js.map} +1 -1
  13. package/dist/chunk-DEAPNMKO.js +11 -0
  14. package/dist/chunk-DEAPNMKO.js.map +1 -0
  15. package/dist/{chunk-BFSZ4L6Y.js → chunk-ETRNSJCR.js} +4 -4
  16. package/dist/{chunk-BFSZ4L6Y.js.map → chunk-ETRNSJCR.js.map} +1 -1
  17. package/dist/chunk-FXWDDNGD.js +98 -0
  18. package/dist/chunk-FXWDDNGD.js.map +1 -0
  19. package/dist/chunk-GFGOQIEC.js +10 -0
  20. package/dist/chunk-GFGOQIEC.js.map +1 -0
  21. package/dist/{chunk-YDF6P74H.js → chunk-IAHEYPYJ.js} +3 -3
  22. package/dist/{chunk-YDF6P74H.js.map → chunk-IAHEYPYJ.js.map} +1 -1
  23. package/dist/{chunk-YCJPLPQQ.js → chunk-J5JNLXO7.js} +3 -3
  24. package/dist/{chunk-YCJPLPQQ.js.map → chunk-J5JNLXO7.js.map} +1 -1
  25. package/dist/{chunk-MBQR3LFW.js → chunk-NFOGYDRS.js} +5 -5
  26. package/dist/{chunk-MBQR3LFW.js.map → chunk-NFOGYDRS.js.map} +1 -1
  27. package/dist/{chunk-Z7IL735U.js → chunk-R2YNDRGL.js} +3 -3
  28. package/dist/{chunk-Z7IL735U.js.map → chunk-R2YNDRGL.js.map} +1 -1
  29. package/dist/{chunk-ZV4WGW74.js → chunk-R5NXOPL2.js} +3 -3
  30. package/dist/{chunk-ZV4WGW74.js.map → chunk-R5NXOPL2.js.map} +1 -1
  31. package/dist/chunk-RMBZ7YH7.js +52 -0
  32. package/dist/chunk-RMBZ7YH7.js.map +1 -0
  33. package/dist/{chunk-HU3Y2AZY.js → chunk-SHXUSTHM.js} +62 -15
  34. package/dist/chunk-SHXUSTHM.js.map +1 -0
  35. package/dist/{chunk-QIE4Y6BK.js → chunk-UGTC33VH.js} +4 -4
  36. package/dist/{chunk-QIE4Y6BK.js.map → chunk-UGTC33VH.js.map} +1 -1
  37. package/dist/{chunk-6NIQIUGR.js → chunk-VH5MYJ2K.js} +4 -4
  38. package/dist/{chunk-6NIQIUGR.js.map → chunk-VH5MYJ2K.js.map} +1 -1
  39. package/dist/{chunk-W6XWI6QE.js → chunk-WZEDIUWR.js} +8 -7
  40. package/dist/chunk-WZEDIUWR.js.map +1 -0
  41. package/dist/{chunk-TMYUDZLE.js → chunk-ZRRET3RP.js} +11 -11
  42. package/dist/chunk-ZRRET3RP.js.map +1 -0
  43. package/dist/{core-BKJW1Kmq.d.ts → core-DNDAEhO2.d.ts} +7 -10
  44. package/dist/devtools/index.d.ts +4 -4
  45. package/dist/do/index.d.ts +98 -35
  46. package/dist/do/index.js +40 -21
  47. package/dist/do/index.js.map +1 -1
  48. package/dist/{drive-loop-Dc6Z8Vbs.d.ts → drive-loop-DlOEv49c.d.ts} +2 -2
  49. package/dist/{durable-effects-CgrLNccA.d.ts → durable-effects-wLWEdy9H.d.ts} +1 -1
  50. package/dist/effect/index.d.ts +52 -26
  51. package/dist/effect/index.js +7 -31
  52. package/dist/effect/index.js.map +1 -1
  53. package/dist/extension/index.d.ts +3 -3
  54. package/dist/extension/index.js +2 -2
  55. package/dist/flow/index.d.ts +13 -13
  56. package/dist/flow/index.js +13 -11
  57. package/dist/flow/index.js.map +1 -1
  58. package/dist/idempotency/index.d.ts +3 -3
  59. package/dist/idempotency/index.js +3 -3
  60. package/dist/{index-1hit3dJ9.d.ts → index-9P1PaXIV.d.ts} +2 -2
  61. package/dist/{index-Cuy1_xTh.d.ts → index-BBLI2WWN.d.ts} +1 -1
  62. package/dist/{index-Z6Uw7C9t.d.ts → index-C1WhBZ6a.d.ts} +4 -5
  63. package/dist/{index-B-VC4qjx.d.ts → index-C92SgNWz.d.ts} +2 -2
  64. package/dist/{index-CYrUWi1c.d.ts → index-CAsUE_d1.d.ts} +4 -4
  65. package/dist/{index-BjwRcjBi.d.ts → index-CO34esWT.d.ts} +2 -2
  66. package/dist/{index-DB8Yn0-K.d.ts → index-COeX9Bmz.d.ts} +11 -9
  67. package/dist/{index-Diyo8WBO.d.ts → index-Cg0QXnzf.d.ts} +2 -2
  68. package/dist/index.d.ts +5 -5
  69. package/dist/index.js +2 -2
  70. package/dist/jev/index.d.ts +8 -8
  71. package/dist/jev/index.js +5 -5
  72. package/dist/laws-DTtCDDlU.d.ts +135 -0
  73. package/dist/loop-DReKGV1X.d.ts +70 -0
  74. package/dist/{machine-BuPTS1QH.d.ts → machine-C0WhOAyB.d.ts} +5 -5
  75. package/dist/machine-viz/index.d.ts +1 -1
  76. package/dist/machine-viz/index.js +2 -2
  77. package/dist/mem/index.d.ts +4 -3
  78. package/dist/mem/index.js +2 -2
  79. package/dist/mem/index.js.map +1 -1
  80. package/dist/node/index.d.ts +57 -9
  81. package/dist/node/index.js +175 -68
  82. package/dist/node/index.js.map +1 -1
  83. package/dist/otel/index.d.ts +28 -12
  84. package/dist/otel/index.js +25 -21
  85. package/dist/otel/index.js.map +1 -1
  86. package/dist/paginate/index.d.ts +4 -4
  87. package/dist/paginate/index.js +5 -5
  88. package/dist/parity/index.d.ts +11 -15
  89. package/dist/parity/index.js +4 -9
  90. package/dist/parity/index.js.map +1 -1
  91. package/dist/pbt/index.d.ts +279 -67
  92. package/dist/pbt/index.js +299 -58
  93. package/dist/pbt/index.js.map +1 -1
  94. package/dist/persistence/index.d.ts +10 -12
  95. package/dist/persistence/index.js +4 -4
  96. package/dist/promise/index.d.ts +95 -13
  97. package/dist/promise/index.js +6 -4
  98. package/dist/react/index.d.ts +34 -22
  99. package/dist/react/index.js +271 -42
  100. package/dist/react/index.js.map +1 -1
  101. package/dist/resilience/index.d.ts +6 -6
  102. package/dist/resilience/index.js +5 -5
  103. package/dist/{run-D0sxbyno.d.ts → run-Cnw4qXj2.d.ts} +86 -17
  104. package/dist/{runtime-types-BPKp2bGo.d.ts → runtime-types-CP-ykwgf.d.ts} +120 -31
  105. package/dist/testing/effect/index.d.ts +162 -9
  106. package/dist/testing/effect/index.js +110 -10
  107. package/dist/testing/effect/index.js.map +1 -1
  108. package/dist/testing/index.d.ts +6 -8
  109. package/dist/testing/index.js +4 -24
  110. package/dist/testing/index.js.map +1 -1
  111. package/dist/testing/promise/index.d.ts +4 -4
  112. package/dist/testing/promise/index.js +5 -5
  113. package/dist/timing/index.d.ts +4 -4
  114. package/dist/timing/index.js +4 -4
  115. package/dist/{types-BiXj7k_k.d.ts → types-S53WDy_h.d.ts} +1 -1
  116. package/dist/work-queue/index.d.ts +4 -4
  117. package/dist/work-queue/index.js +2 -2
  118. package/package.json +18 -18
  119. package/dist/chunk-7Z2IDZ7R.js +0 -34
  120. package/dist/chunk-7Z2IDZ7R.js.map +0 -1
  121. package/dist/chunk-EB5OMOXX.js.map +0 -1
  122. package/dist/chunk-GAVLND5C.js.map +0 -1
  123. package/dist/chunk-HU3Y2AZY.js.map +0 -1
  124. package/dist/chunk-TMYUDZLE.js.map +0 -1
  125. package/dist/chunk-VM7PMFV5.js.map +0 -1
  126. package/dist/chunk-W6XWI6QE.js.map +0 -1
@@ -1,9 +1,9 @@
1
1
  import { I as IdempotencyStore } from '../index-Bc40JWVl.js';
2
2
  export { a as IdempotencyEntry, e as evictExpired, i as initStore, r as recall, b as remember, s as seen } from '../index-Bc40JWVl.js';
3
- import { a as CmdOf, b as CmdDef } from '../core-BKJW1Kmq.js';
4
- import { Q as QueueItem } from '../index-Cuy1_xTh.js';
3
+ import { a as CmdOf, b as CmdDef } from '../core-DNDAEhO2.js';
4
+ import { Q as QueueItem } from '../index-BBLI2WWN.js';
5
5
  import '@standard-schema/spec';
6
- import '../runtime-types-BPKp2bGo.js';
6
+ import '../runtime-types-CP-ykwgf.js';
7
7
 
8
8
  /**
9
9
  * A cached intake entry: either a key whose work is still in flight
@@ -1,8 +1,8 @@
1
- export { createIntake, intakeProcessDef, intakeReplayDef } from '../chunk-YCJPLPQQ.js';
1
+ export { createIntake, intakeProcessDef, intakeReplayDef } from '../chunk-J5JNLXO7.js';
2
2
  export { evictExpired, initStore, recall, remember, seen } from '../chunk-PR6TB3BL.js';
3
3
  import '../chunk-4LPY67E4.js';
4
4
  import '../chunk-TXN2KFHF.js';
5
- import '../chunk-VHKDUBXC.js';
6
- import '../chunk-GAVLND5C.js';
5
+ import '../chunk-BVFS3ICC.js';
6
+ import '../chunk-A3QPMX5M.js';
7
7
  //# sourceMappingURL=index.js.map
8
8
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
- import { C as Cmd, P as Port } from './core-BKJW1Kmq.js';
2
- import { Q as QueueItem } from './index-Cuy1_xTh.js';
1
+ import { C as Cmd, P as Port } from './core-DNDAEhO2.js';
2
+ import { Q as QueueItem } from './index-BBLI2WWN.js';
3
3
 
4
4
  /**
5
5
  * internal/flow/fan-out — scatter-gather over a bounded-concurrency work list.
@@ -1,4 +1,4 @@
1
- import { S as Store } from './runtime-types-BPKp2bGo.js';
1
+ import { b as Store } from './runtime-types-CP-ykwgf.js';
2
2
 
3
3
  /**
4
4
  * internal/work-queue — substrate-agnostic work-queue lifecycle on `Store<S>`.
@@ -1,4 +1,4 @@
1
- import { B as BootingRuntime } from './runtime-types-BPKp2bGo.js';
1
+ import { B as BootingRuntime } from './runtime-types-CP-ykwgf.js';
2
2
 
3
3
  /**
4
4
  * A recorded run, sufficient to reproduce it via `../trace-replay`.
@@ -11,10 +11,9 @@ import { B as BootingRuntime } from './runtime-types-BPKp2bGo.js';
11
11
  */
12
12
  interface Trace<S, M> {
13
13
  /**
14
- * The initial state captured at the boot observe (the transition where
15
- * `msg === null`). Fed back to replay as `loaded` so `init(loaded, ctx)`
16
- * reproduces the exact starting point. `null` only if the recorder attached
17
- * AFTER boot (it missed the boot observe) — replay then re-runs fresh `init`.
14
+ * The post-init State captured by `onBoot`, used directly as the recorded
15
+ * replay's starting State. No init call is repeated. `null` marks a missing
16
+ * anchor in an older or incomplete trace; `replayTrace` refuses it.
18
17
  */
19
18
  readonly loaded: S | null;
20
19
  /** The ordered, non-null msgs as observed. The replay input sequence. */
@@ -1,6 +1,6 @@
1
- import { a as CmdOf, b as CmdDef, f as TaggedError, o as MalformedResult, T as TimerDeps, C as Cmd } from './core-BKJW1Kmq.js';
1
+ import { a as CmdOf, b as CmdDef, f as TaggedError, o as MalformedResult, T as TimerDeps, C as Cmd } from './core-DNDAEhO2.js';
2
2
  import { RetryState, AnyRetryPolicy } from './retry-backoff/index.js';
3
- import { T as TtlCache, D as DeadlineExceeded, a as DeadlineSub } from './index-Diyo8WBO.js';
3
+ import { T as TtlCache, D as DeadlineExceeded, a as DeadlineSub } from './index-Cg0QXnzf.js';
4
4
 
5
5
  /**
6
6
  * @packageDocumentation
@@ -1,7 +1,7 @@
1
- import { b as CmdDef, T as TimerDeps, C as Cmd } from './core-BKJW1Kmq.js';
2
- import { S as SnapshotWriteCmd, a as SnapshotState, b as SnapshotSavedMsg } from './index-DB8Yn0-K.js';
3
- import { D as DeadlineExceeded, a as DeadlineSub } from './index-Diyo8WBO.js';
4
- import { Q as QueueItem } from './index-Cuy1_xTh.js';
1
+ import { b as CmdDef, T as TimerDeps, C as Cmd } from './core-DNDAEhO2.js';
2
+ import { S as SnapshotWriteCmd, a as SnapshotState, b as SnapshotSavedMsg } from './index-COeX9Bmz.js';
3
+ import { D as DeadlineExceeded, a as DeadlineSub } from './index-Cg0QXnzf.js';
4
+ import { Q as QueueItem } from './index-BBLI2WWN.js';
5
5
 
6
6
  /**
7
7
  * The monitored-run knob. EVERY field is optional:
@@ -1,5 +1,5 @@
1
- import { C as Cmd, T as TimerDeps, S as Subscribe } from './core-BKJW1Kmq.js';
2
- import { D as DeadlineExceeded, a as DeadlineSub, b as DeadlinesSub } from './index-Diyo8WBO.js';
1
+ import { C as Cmd, T as TimerDeps, S as Subscribe } from './core-DNDAEhO2.js';
2
+ import { D as DeadlineExceeded, a as DeadlineSub, b as DeadlinesSub } from './index-Cg0QXnzf.js';
3
3
 
4
4
  /**
5
5
  * internal/flow/batch-window — coalesce a stream of items into size- or
@@ -1,4 +1,4 @@
1
- import { a as CmdOf, b as CmdDef, d as SettledOk, e as SettledErr, f as TaggedError, C as Cmd } from './core-BKJW1Kmq.js';
1
+ import { a as CmdOf, b as CmdDef, d as SettledOk, e as SettledErr, f as TaggedError, C as Cmd } from './core-DNDAEhO2.js';
2
2
 
3
3
  /**
4
4
  * The snapshot knob.
@@ -92,9 +92,10 @@ type SnapshotWriteCmd<V> = CmdOf<ReturnType<typeof snapshotWriteDef<V>>>;
92
92
  * `err({ _tag: "snapshot_load_failed", … })`.
93
93
  *
94
94
  * Distinct from `snapshot_write`: a write carries a payload OUT to the store; a
95
- * load asks the store to hand a payload BACK. The consumer dispatches the
96
- * triggering Msg once on resume (a `boot` Msg, never `init`'s rehydrate branch —
97
- * invariant 2), folds the recovered payload into its run slice, then continues.
95
+ * load asks the store to hand a payload BACK. A pure restored `init` may return
96
+ * resume State and Cmds, including a load Cmd from `requestLoad`. A host `boot`
97
+ * Msg after `run(...)` is an optional protocol; Subs are already open then.
98
+ * Fold the recovered payload into the run slice, then continue.
98
99
  */
99
100
  declare function snapshotLoadDef<V>(): CmdDef<"snapshot_load", {
100
101
  readonly key: string;
@@ -182,9 +183,9 @@ interface SnapshotKnob<V> {
182
183
  * un-checkpointed progress accumulated before the crash is moot — recovery
183
184
  * resumes from the last DURABLE checkpoint, so the cadence counter starts
184
185
  * fresh from there. `seq` / `lastSavedSeq` / `lastSavedAt` are preserved
185
- * (they describe what is durable, which a reload does not change). Call from
186
- * a `boot` Msg the host dispatches once after `run(...)`, never from `init`'s
187
- * rehydrate branch (invariant 2).
186
+ * (they describe what is durable, which a reload does not change). A pure
187
+ * restored `init` may use this to return resume State and Cmds. A host `boot`
188
+ * Msg after `run(...)` is an optional protocol; Subs are already open then.
188
189
  *
189
190
  * Returns the reducer-cell shape `readonly [SnapshotState, readonly Cmd[]]`
190
191
  * (with `Cmd.none` — a resume emits nothing) so it drops straight into a
@@ -196,8 +197,9 @@ interface SnapshotKnob<V> {
196
197
  * `snapshot_load` Cmd carrying the configured `key`; returns the slice
197
198
  * UNCHANGED (a read decides nothing about the cadence bookkeeping — only the
198
199
  * later `snapshot_load_ok` fold, via `boot`, touches the slice). This is the
199
- * entry point of the recovery loop: the consumer dispatches a `boot` Msg once
200
- * after `run(...)` and folds `requestLoad` there.
200
+ * entry point of the recovery loop: call from pure restored `init` to return
201
+ * resume State and the load Cmd, or from an optional host `boot` Msg after
202
+ * `run(...)`, when Subs are already open.
201
203
  */
202
204
  requestLoad(state: SnapshotState): readonly [SnapshotState, readonly SnapshotLoadCmd<V>[]];
203
205
  }
@@ -1,5 +1,5 @@
1
- import { l as SubId, c as Sub, m as DepKeyedSub, D as Dispose, T as TimerDeps } from './core-BKJW1Kmq.js';
2
- import { S as SubscribeHandler } from './types-BiXj7k_k.js';
1
+ import { l as SubId, c as Sub, m as DepKeyedSub, D as Dispose, T as TimerDeps } from './core-DNDAEhO2.js';
2
+ import { S as SubscribeHandler } from './types-S53WDy_h.js';
3
3
 
4
4
  /**
5
5
  * internal/resilience/deadline — a one-shot Sub that fires when an ABSOLUTE wall-clock
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { B as BootingRuntime, R as Runtime } from './runtime-types-BPKp2bGo.js';
2
- export { b as BootedRunHandle, e as Branded, C as CtxArg, D as DeletableStore, f as DispatchDiscardedError, c as DispatchSettle, g as DisposeTimeoutNotice, h as DrainTimeoutNotice, i as DriveFailedError, j as DriveStalledError, E as EngineRun, k as FencedRead, F as FencedStore, l as FoldRefusal, I as IdentityDropNotice, m as MachineTypes, M as Migrated, O as OnError, P as PortNameCollisionError, Q as QuiescenceTimeoutError, n as Refusal, d as RunHandle, o as RunOptions, p as RuntimeDiscardNotice, q as RuntimeDiscardedError, r as RuntimeErrorContext, s as RuntimeErrorPhase, t as RuntimeRef, u as Schema, S as Store, v as StoreConflictError, w as StoreRefusedError, a as Supervision, x as SupervisionStrategy, y as TelemetryEvent, T as TelemetrySink, _ as __resetPortRegistry, z as absurd, A as asReducer, G as defineMachine, H as definePort, J as isFencedStore, K as noop, L as refuse, N as replay, U as schemaMigrate, V as tryApplyCell, W as tryFoldMsgs, X as tryInterpret, Y as wrapDetached } from './runtime-types-BPKp2bGo.js';
3
- import { C as Cmd, c as Sub, M as Machine, P as Port, m as DepKeyedSub, D as Dispose } from './core-BKJW1Kmq.js';
4
- export { A as AnyCmdDef, w as AsyncSchemaError, B as BuiltinSub, r as BuiltinSubType, b as CmdDef, k as CmdInput, a as CmdOf, v as CmdValue, q as DeclaredErrorsOf, u as ErrOf, E as ErrorsOf, x as ExhaustiveTransitions, y as Identity, I as Interpret, z as InterpretArg, F as InterpretCell, j as InterpretDetached, G as MachineShape, o as MalformedResult, N as NoCellError, J as NoCtx, t as OkOf, p as OkOfCmd, O as Outcome, K as OutcomeContractError, L as OutcomeHelpers, Q as PortEmitter, g as Reducer, R as RunHandlers, h as Settled, e as SettledErr, d as SettledOk, l as SubId, S as Subscribe, V as SubscribeArg, X as SyncReturn, s as Tagged, f as TaggedError, T as TimerDeps, n as TimerSub, i as Transitions, Y as UndeclaredFailureError, U as UpdateForm, W as Wired, Z as acceptedTypes, _ as acceptsOf, $ as applyCell, a0 as applyCellChecked, a1 as describeMachine, a2 as detectUpdateForm, a3 as foldMsgs, a4 as foldUpdates, a5 as formOf, a6 as msgKeysOf, a7 as structuralHash, a8 as subId, a9 as subIdOf } from './core-BKJW1Kmq.js';
5
- import { S as SubscribeHandler } from './types-BiXj7k_k.js';
1
+ import { B as BootingRuntime, R as Runtime } from './runtime-types-CP-ykwgf.js';
2
+ export { a as BootedRunHandle, f as Branded, C as CtxArg, D as DeletableStore, g as DispatchDiscardedError, d as DispatchSettle, h as DisposeTimeoutNotice, i as DrainTimeoutNotice, j as DriveFailedError, k as DriveStalledError, E as EngineRun, l as FencedRead, F as FencedStore, m as FoldRefusal, I as IdentityDropNotice, n as MachineTypes, M as Migrated, O as OnError, P as PortNameCollisionError, Q as QuiescenceTimeoutError, o as Refusal, e as RunHandle, p as RunOptions, q as RuntimeDiscardNotice, r as RuntimeDiscardedError, s as RuntimeErrorContext, t as RuntimeErrorPhase, u as RuntimeRef, v as Schema, b as Store, S as StoreAndOnError, w as StoreConflictError, x as StoreRefusedError, y as SubFailedError, c as Supervision, z as SupervisionStrategy, A as TelemetryEvent, T as TelemetrySink, U as UnfencedStore, _ as __resetPortRegistry, G as absurd, H as asReducer, J as defineMachine, K as definePort, L as isFencedStore, N as noop, V as refuse, W as replay, X as schemaMigrate, Y as tryApplyCell, Z as tryFoldMsgs, $ as tryInterpret, a0 as wrapDetached } from './runtime-types-CP-ykwgf.js';
3
+ import { C as Cmd, c as Sub, M as Machine, P as Port, m as DepKeyedSub, D as Dispose } from './core-DNDAEhO2.js';
4
+ export { A as AnyCmdDef, w as AsyncSchemaError, B as BuiltinSub, r as BuiltinSubType, b as CmdDef, k as CmdInput, a as CmdOf, v as CmdValue, q as DeclaredErrorsOf, u as ErrOf, E as ErrorsOf, x as ExhaustiveTransitions, y as Identity, I as Interpret, z as InterpretArg, F as InterpretCell, j as InterpretDetached, G as MachineShape, o as MalformedResult, N as NoCellError, J as NoCtx, t as OkOf, p as OkOfCmd, O as Outcome, K as OutcomeContractError, L as OutcomeHelpers, Q as PortEmitter, g as Reducer, R as RunHandlers, h as Settled, e as SettledErr, d as SettledOk, l as SubId, S as Subscribe, V as SubscribeArg, X as SyncReturn, s as Tagged, f as TaggedError, T as TimerDeps, n as TimerSub, i as Transitions, Y as UndeclaredFailureError, U as UpdateForm, W as Wired, Z as acceptedTypes, _ as acceptsOf, $ as applyCell, a0 as applyCellChecked, a1 as describeMachine, a2 as detectUpdateForm, a3 as foldMsgs, a4 as foldUpdates, a5 as formOf, a6 as msgKeysOf, a7 as structuralHash, a8 as subId, a9 as subIdOf } from './core-DNDAEhO2.js';
5
+ import { S as SubscribeHandler } from './types-S53WDy_h.js';
6
6
  import '@standard-schema/spec';
7
7
 
8
8
  /**
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { NO_ACK, ack, defineListener, defineManagedResource, fromBroadcastChannel, fromEventSource, fromEventTarget, fromInterval, fromPort, fromReconnectingWebSocket, fromTimeout, fromTransport, fromWebSocket, historyTracker, initAck, liftSlice, nextSeq, partitionByAck, readInOrder, reconcile, tagSeq } from './chunk-VHKDUBXC.js';
2
- export { AsyncSchemaError, Cmd, DispatchDiscardedError, DisposeTimeoutNotice, DrainTimeoutNotice, DriveFailedError, DriveStalledError, IdentityDropNotice, NoCellError, Outcome, OutcomeContractError, PortNameCollisionError, QuiescenceTimeoutError, Refusal, RuntimeDiscardNotice, RuntimeDiscardedError, StoreConflictError, StoreRefusedError, UndeclaredFailureError, __resetPortRegistry, absurd, acceptedTypes, acceptsOf, applyCell, applyCellChecked, asReducer, defineMachine, definePort, describeMachine, detectUpdateForm, foldMsgs, foldUpdates, formOf, isFencedStore, msgKeysOf, noop, refuse, replay, schemaMigrate, structuralHash, subId, subIdOf, tryApplyCell, tryFoldMsgs, tryInterpret, wrapDetached } from './chunk-GAVLND5C.js';
1
+ export { NO_ACK, ack, defineListener, defineManagedResource, fromBroadcastChannel, fromEventSource, fromEventTarget, fromInterval, fromPort, fromReconnectingWebSocket, fromTimeout, fromTransport, fromWebSocket, historyTracker, initAck, liftSlice, nextSeq, partitionByAck, readInOrder, reconcile, tagSeq } from './chunk-BVFS3ICC.js';
2
+ export { AsyncSchemaError, Cmd, DispatchDiscardedError, DisposeTimeoutNotice, DrainTimeoutNotice, DriveFailedError, DriveStalledError, IdentityDropNotice, NoCellError, Outcome, OutcomeContractError, PortNameCollisionError, QuiescenceTimeoutError, Refusal, RuntimeDiscardNotice, RuntimeDiscardedError, StoreConflictError, StoreRefusedError, SubFailedError, UndeclaredFailureError, __resetPortRegistry, absurd, acceptedTypes, acceptsOf, applyCell, applyCellChecked, asReducer, defineMachine, definePort, describeMachine, detectUpdateForm, foldMsgs, foldUpdates, formOf, isFencedStore, msgKeysOf, noop, refuse, replay, schemaMigrate, structuralHash, subId, subIdOf, tryApplyCell, tryFoldMsgs, tryInterpret, wrapDetached } from './chunk-A3QPMX5M.js';
3
3
  //# sourceMappingURL=index.js.map
4
4
  //# sourceMappingURL=index.js.map
@@ -1,13 +1,13 @@
1
- import { O as Outcome, b as CmdDef, T as TimerDeps, C as Cmd, m as DepKeyedSub, n as TimerSub } from '../core-BKJW1Kmq.js';
1
+ import { O as Outcome, b as CmdDef, T as TimerDeps, C as Cmd, m as DepKeyedSub, n as TimerSub } from '../core-DNDAEhO2.js';
2
2
  import { RetryPolicy } from '../retry-backoff/index.js';
3
- import { a as DeadlineSub, T as TtlCache, C as CacheEvictionSub, c as CacheEvictMsg } from '../index-Diyo8WBO.js';
4
- import { D as DefaultResilientName, R as RunCmd, F as FailMsg, S as SucceedMsg, a as ResilientTimerMsg, b as ResilientState, c as DeadlineNameOf } from '../index-B-VC4qjx.js';
5
- import { S as SubscribeHandler } from '../types-BiXj7k_k.js';
6
- import { B as BatchWindow, a as BatchWindowSub, b as BatchWindowExpired } from '../index-BjwRcjBi.js';
7
- import { F as FanOutState } from '../index-1hit3dJ9.js';
3
+ import { a as DeadlineSub, T as TtlCache, C as CacheEvictionSub, c as CacheEvictMsg } from '../index-Cg0QXnzf.js';
4
+ import { D as DefaultResilientName, R as RunCmd, F as FailMsg, S as SucceedMsg, a as ResilientTimerMsg, b as ResilientState, c as DeadlineNameOf } from '../index-C92SgNWz.js';
5
+ import { S as SubscribeHandler } from '../types-S53WDy_h.js';
6
+ import { B as BatchWindow, a as BatchWindowSub, b as BatchWindowExpired } from '../index-CO34esWT.js';
7
+ import { F as FanOutState } from '../index-9P1PaXIV.js';
8
8
  import '@standard-schema/spec';
9
- import '../index-Cuy1_xTh.js';
10
- import '../runtime-types-BPKp2bGo.js';
9
+ import '../index-BBLI2WWN.js';
10
+ import '../runtime-types-CP-ykwgf.js';
11
11
 
12
12
  /**
13
13
  * @packageDocumentation
package/dist/jev/index.js CHANGED
@@ -1,13 +1,13 @@
1
- import { createBatchWindow } from '../chunk-ZV4WGW74.js';
1
+ import { createBatchWindow } from '../chunk-R5NXOPL2.js';
2
2
  import '../chunk-LFZUK6J2.js';
3
3
  import { createFanOut } from '../chunk-QNGYQMZB.js';
4
- import { runCmdDef, createResilientCall } from '../chunk-MBQR3LFW.js';
5
- import { initCache, has, set, evictExpired, cacheEvictionSub, cacheEvictionSubscribe, get } from '../chunk-QIE4Y6BK.js';
4
+ import { runCmdDef, createResilientCall } from '../chunk-NFOGYDRS.js';
5
+ import { initCache, has, set, evictExpired, cacheEvictionSub, cacheEvictionSubscribe, get } from '../chunk-UGTC33VH.js';
6
6
  import '../chunk-VBDU4JL6.js';
7
7
  import '../chunk-4LPY67E4.js';
8
8
  import '../chunk-TXN2KFHF.js';
9
- import { liftSlice, readInOrder } from '../chunk-VHKDUBXC.js';
10
- import { describeError, Outcome } from '../chunk-GAVLND5C.js';
9
+ import { liftSlice, readInOrder } from '../chunk-BVFS3ICC.js';
10
+ import { describeError, Outcome } from '../chunk-A3QPMX5M.js';
11
11
 
12
12
  // src/internal/jev/protocol/index.ts
13
13
  var jevQuestions = (questions) => questions;
@@ -0,0 +1,135 @@
1
+ import { C as Cmd, c as Sub, M as Machine } from './core-DNDAEhO2.js';
2
+
3
+ /**
4
+ * One unit in a fold trace — the four pieces of data a property
5
+ * invariant typically asserts on. `prev` is the state before the msg
6
+ * applied; `next` is the state after; `cmds` is the cmds emitted by this
7
+ * single step (NOT the running total).
8
+ */
9
+ interface Step<S, M, C> {
10
+ readonly prev: S;
11
+ readonly msg: M;
12
+ readonly next: S;
13
+ readonly cmds: readonly C[];
14
+ }
15
+ /**
16
+ * What {@link foldEvents} hands back: every state in order, one {@link Step} per
17
+ * Msg, the final state, and the Cmds `init` sent. A law reads one of these.
18
+ */
19
+ interface Fold<S, M, C> {
20
+ readonly states: readonly S[];
21
+ readonly steps: readonly Step<S, M, C>[];
22
+ readonly finalState: S;
23
+ readonly initCmds: readonly C[];
24
+ }
25
+ /**
26
+ * Fold a Msg sequence through a machine's pure reducer, returning the
27
+ * per-step trace, every state in order, the final state, and the Cmds `init`
28
+ * sent. Initial state comes from `replay(machine, { msgs: [], ctx, loaded })`
29
+ * — i.e. `machine.init(loaded ?? null, ctx)` faithfully. Init's emitted cmds
30
+ * are NOT included in any `Step` (they're the boot moment, not a Msg): they
31
+ * come back as `initCmds`, on a fresh start and on a loaded state alike.
32
+ *
33
+ * @param machine The machine under test.
34
+ * @param ctx The Ctx — typically `stubCtxThrowingProxy<Ctx>()` when
35
+ * init is pure. Pass a real ctx if init reads from it.
36
+ * @param loaded Optional pre-init snapshot (the `loaded` arg to
37
+ * `machine.init`). Defaults to `null` (fresh boot).
38
+ * @param msgs The Msg sequence to fold.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * import type { Machine } from "@demlik/tea";
43
+ * import { foldEvents } from "@demlik/tea/pbt";
44
+ *
45
+ * type State = { type: "idle" } | { type: "counting"; n: number } | { type: "stopped" };
46
+ * type Msg = { type: "start" } | { type: "tick" } | { type: "stop" };
47
+ * interface Ctx { readonly tabId: number }
48
+ * declare const machine: Machine<State, Msg, never, never, Ctx>;
49
+ * declare const ctx: Ctx;
50
+ *
51
+ * const { states, steps, finalState } = foldEvents(machine, ctx, null, [
52
+ * { type: "start" }, { type: "tick" }, { type: "stop" },
53
+ * ]);
54
+ * // steps[1] = { prev: { type: "counting", n: 0 }, msg: { type: "tick" }, ... }
55
+ * ```
56
+ */
57
+ declare function foldEvents<S, M extends {
58
+ type: string;
59
+ }, C extends Cmd, U extends Sub, Ctx>(machine: Machine<S, M, C, U, Ctx>, ctx: NoInfer<Ctx>, loaded: NoInfer<S> | null, msgs: readonly NoInfer<M>[]): Fold<S, M, C>;
60
+
61
+ /**
62
+ * What a broken law says. `report` names the fold that broke it. `reason` is the
63
+ * string the check returned to say why, or `null` when it returned `false`.
64
+ *
65
+ * @experimental
66
+ */
67
+ interface LawBreak {
68
+ readonly report: string;
69
+ readonly reason: string | null;
70
+ }
71
+ /**
72
+ * The law `propertyTerminates` runs: the fold's final state is one `terminal`
73
+ * accepts. `terminal` also gets the Cmds `init` sent.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * import type { Machine } from "@demlik/tea";
78
+ * import { foldEvents, lawTerminates } from "@demlik/tea/pbt";
79
+ *
80
+ * type State = { type: "idle" } | { type: "done" };
81
+ * type Msg = { type: "finish" };
82
+ * declare const machine: Machine<State, Msg, never, never, object>;
83
+ *
84
+ * const fold = foldEvents(machine, {}, null, [{ type: "finish" }]);
85
+ * lawTerminates(fold, (s) => s.type === "done"); // null when it holds
86
+ * ```
87
+ *
88
+ * @experimental
89
+ */
90
+ declare function lawTerminates<S, M, C>(fold: Fold<S, M, C>, terminal: (state: NoInfer<S>, initCmds: readonly NoInfer<C>[]) => boolean): LawBreak | null;
91
+ /**
92
+ * The law `propertyInvariant` runs: `invariant` holds on every step of the fold.
93
+ * Return `true` or `null` to accept, `false` or a string saying why to break. It
94
+ * stops at the first step that breaks, and the report names that step. The second
95
+ * argument is the Cmds `init` sent.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * import type { Machine } from "@demlik/tea";
100
+ * import { foldEvents, lawInvariant } from "@demlik/tea/pbt";
101
+ *
102
+ * type State = { readonly n: number };
103
+ * type Msg = { type: "inc" };
104
+ * declare const machine: Machine<State, Msg, never, never, object>;
105
+ *
106
+ * const fold = foldEvents(machine, {}, null, [{ type: "inc" }]);
107
+ * lawInvariant(fold, ({ prev, next }) => next.n > prev.n || "n did not grow");
108
+ * ```
109
+ *
110
+ * @experimental
111
+ */
112
+ declare function lawInvariant<S, M, C>(fold: Fold<S, M, C>, invariant: (step: Step<NoInfer<S>, NoInfer<M>, NoInfer<C>>, initCmds: readonly NoInfer<C>[]) => boolean | string | null): LawBreak | null;
113
+ /**
114
+ * The law `propertyTrace` runs: `predicate` holds on the fold's steps and final
115
+ * state together. Return `true` or `null` to accept, `false` or a string saying
116
+ * why to break. The last argument is the Cmds `init` sent.
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * import type { Machine } from "@demlik/tea";
121
+ * import { foldEvents, lawTrace } from "@demlik/tea/pbt";
122
+ *
123
+ * type State = { type: "open" } | { type: "done" };
124
+ * type Msg = { type: "close" };
125
+ * declare const machine: Machine<State, Msg, never, never, object>;
126
+ *
127
+ * const fold = foldEvents(machine, {}, null, [{ type: "close" }]);
128
+ * lawTrace(fold, (steps, final) => final.type !== "done" || steps.length > 0);
129
+ * ```
130
+ *
131
+ * @experimental
132
+ */
133
+ declare function lawTrace<S, M, C>(fold: Fold<S, M, C>, predicate: (steps: readonly Step<NoInfer<S>, NoInfer<M>, NoInfer<C>>[], finalState: NoInfer<S>, initCmds: readonly NoInfer<C>[]) => boolean | string | null): LawBreak | null;
134
+
135
+ export { type Fold as F, type LawBreak as L, type Step as S, lawTerminates as a, lawTrace as b, foldEvents as f, lawInvariant as l };
@@ -0,0 +1,70 @@
1
+ /**
2
+ * The core loop both engines run (#280, spike #264). It does five things and
3
+ * nothing else: it keeps one serial tail, folds a Msg into a transition, saves
4
+ * before any effect, reconciles the running Subs, and runs the transition's
5
+ * Cmds, dispatching what they return. It has no special case for any built-in.
6
+ *
7
+ * One loop, not one per engine (#283). The loop calls a handler and a runner
8
+ * through erased signatures and awaits a Promise either way, so an engine's
9
+ * own types never pass through it. The Effect engine turns each handler and
10
+ * runner into a fiber at its own edge, run with the services the caller
11
+ * provided, so Effect services (`R`) reach every handler without the loop
12
+ * carrying a type slot for them — the gap spike #260's generic loop left open.
13
+ * Sharing the loop is also what makes the two engines' traces identical: the
14
+ * fold, the save order and the built-ins are the same code.
15
+ *
16
+ * Everything else `run` offers is an {@link Extension} built on ten points:
17
+ *
18
+ * 1. `update` — middleware over the fold. Returning `null` means "no
19
+ * transition": no save, no effects, no commit.
20
+ * 2. `interpret` — middleware over one Cmd's handler call; it maps what the
21
+ * handler returned to the Msgs to dispatch, if any.
22
+ * 3. `store` — a wrapper over the store the caller handed `run`.
23
+ * 4. `installed` — called once a transition's State is past its save and its
24
+ * Subs are reconciled, before its first Cmd's handler starts.
25
+ * This is Elm's `view`: it never waits on a Cmd (#695).
26
+ * 5. `commit` — called after a transition's effects, with the Msg and the
27
+ * committed State, even when a Cmd handler threw. Boot
28
+ * passes `undefined` for the Msg.
29
+ * 6. `saveFailed` — called when a transition's save rejects, before that
30
+ * rejection reaches the dispatch caller.
31
+ * 7. `subFailed` — called when a Sub's failure stops the run, before the
32
+ * engine is told to stop it.
33
+ * 8. `halted` — called when an extension halts the run with an error.
34
+ * 9. `drained` — called once no Msg can fold any more, so the State is the
35
+ * run's last: `stop()` has finished with the queue, the
36
+ * host's or the one a failure started.
37
+ * 10. `ctx` — keys added to the ctx every Cmd handler receives, so a
38
+ * handler that runs another handler inside its own can reach
39
+ * the same machinery the loop applies to it.
40
+ *
41
+ * An extension may also add methods to the run handle (`handle`). Array order
42
+ * is nesting order: the first extension's middleware is the outermost, and
43
+ * `installed` and commit callbacks run first to last. `builtinExtensions`
44
+ * (`./builtins`) fixes that order for every engine; it is not a user-facing
45
+ * plugin API (#268).
46
+ *
47
+ * `stop()` is the core's own lifecycle, because the gate it drives is what every
48
+ * dispatch passes through: open → draining → closed, or → abandoned when
49
+ * `stop()` gives up on the queue (ADR 0025), never backwards.
50
+ */
51
+
52
+ declare const post: unique symbol;
53
+ /**
54
+ * What `tell` answers, at once, about the Msg it was handed. It says where the
55
+ * Msg stands at that moment and nothing about how it ends.
56
+ *
57
+ * - `"queued"`: the Msg is on the receiver's line. It has not been handled.
58
+ * - `"stopped"`: the receiver is stopping or has stopped, so the Msg is not on
59
+ * its line and never will be.
60
+ * - `"no_cell"`: the receiver's current State has no cell for the Msg, so the
61
+ * Msg is not on its line. That reads the State as it is now, not the State
62
+ * the Msgs already in line will leave.
63
+ */
64
+ type TellAnswer = "queued" | "stopped" | "no_cell";
65
+ /** A run handle `tell` can reach the line of. */
66
+ interface Postable<S, M> {
67
+ readonly [post]: (msg: M, takes: (state: S) => boolean) => TellAnswer;
68
+ }
69
+
70
+ export type { Postable as P, TellAnswer as T };
@@ -1,9 +1,9 @@
1
- import { C as Cmd, s as Tagged, I as Interpret, A as AnyCmdDef, a as CmdOf, b as CmdDef, h as Settled, t as OkOf, u as ErrOf, o as MalformedResult, O as Outcome, v as CmdValue, H as HandlerCtx, f as TaggedError, M as Machine, S as Subscribe } from './core-BKJW1Kmq.js';
2
- import { b as MonitoredRunState, R as RunFailure, M as MonitoredRunCmd } from './index-CYrUWi1c.js';
3
- import { R as RunCmd, S as SucceedMsg, F as FailMsg, b as ResilientState, r as RunCmdDef } from './index-B-VC4qjx.js';
4
- import { D as DeadlineExceeded, a as DeadlineSub, b as DeadlinesSub } from './index-Diyo8WBO.js';
1
+ import { C as Cmd, s as Tagged, I as Interpret, A as AnyCmdDef, a as CmdOf, b as CmdDef, h as Settled, t as OkOf, u as ErrOf, o as MalformedResult, O as Outcome, v as CmdValue, H as HandlerCtx, f as TaggedError, M as Machine, S as Subscribe } from './core-DNDAEhO2.js';
2
+ import { b as MonitoredRunState, R as RunFailure, M as MonitoredRunCmd } from './index-CAsUE_d1.js';
3
+ import { R as RunCmd, S as SucceedMsg, F as FailMsg, b as ResilientState, r as RunCmdDef } from './index-C92SgNWz.js';
4
+ import { D as DeadlineExceeded, a as DeadlineSub, b as DeadlinesSub } from './index-Cg0QXnzf.js';
5
5
  import { M as MsgType, a as MsgTypeValue } from './protocol-ClRZBhHQ.js';
6
- import { F as FanOutState } from './index-1hit3dJ9.js';
6
+ import { F as FanOutState } from './index-9P1PaXIV.js';
7
7
  import { RetryPolicy, AnyRetryPolicy } from './retry-backoff/index.js';
8
8
  import { StandardSchemaV1 } from '@standard-schema/spec';
9
9
 
@@ -1,4 +1,4 @@
1
- import { C as Cmd, c as Sub, M as Machine } from '../core-BKJW1Kmq.js';
1
+ import { C as Cmd, c as Sub, M as Machine } from '../core-DNDAEhO2.js';
2
2
  import '@standard-schema/spec';
3
3
 
4
4
  /**
@@ -1,5 +1,5 @@
1
- import '../chunk-VHKDUBXC.js';
2
- import { formOf, subEntriesOf, desiredSub } from '../chunk-GAVLND5C.js';
1
+ import '../chunk-BVFS3ICC.js';
2
+ import { formOf, subEntriesOf, desiredSub } from '../chunk-A3QPMX5M.js';
3
3
 
4
4
  // src/machine-viz/mermaid-id.ts
5
5
  function safeId(raw) {
@@ -1,5 +1,5 @@
1
- import { M as Migrated, D as DeletableStore, F as FencedStore } from '../runtime-types-BPKp2bGo.js';
2
- import '../core-BKJW1Kmq.js';
1
+ import { M as Migrated, D as DeletableStore, F as FencedStore } from '../runtime-types-CP-ykwgf.js';
2
+ import '../core-DNDAEhO2.js';
3
3
  import '@standard-schema/spec';
4
4
 
5
5
  /**
@@ -39,7 +39,8 @@ interface MemoryStoreOptions {
39
39
  * store is a `FencedStore<S>` whose version is an in-process counter — honest
40
40
  * for this adapter, since the cell it guards is in this process too. Two
41
41
  * `run`s handed the SAME `memoryStore` are the case it catches, and it is the
42
- * cheapest way to exercise the fenced path in a test.
42
+ * cheapest way to exercise the fenced path in a test. A run on a fenced store
43
+ * must be given an `onError` (see `StoreAndOnError`).
43
44
  */
44
45
  readonly fenced?: true;
45
46
  }
package/dist/mem/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import '../chunk-VHKDUBXC.js';
2
- import { StoreConflictError } from '../chunk-GAVLND5C.js';
1
+ import '../chunk-BVFS3ICC.js';
2
+ import { StoreConflictError } from '../chunk-A3QPMX5M.js';
3
3
 
4
4
  // src/mem/index.ts
5
5
  function memoryStore(initial, parse = (raw) => raw, options = {}) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/mem/index.ts"],"names":[],"mappings":";;;;AAsEO,SAAS,WAAA,CACd,SACA,KAAA,GAAuC,CAAC,QAAQ,GAAA,EAChD,OAAA,GAA8B,EAAC,EAC2B;AAG1D,EAAA,IAAI,OAAiB,OAAA,IAAW,IAAA;AAGhC,EAAA,IAAI,OAAA,GAAU,CAAA;AAEd,EAAA,MAAM,IAAA,GAA0B;AAAA,IAC9B,MAAM,IAAA,GAAyB;AAC7B,MAAA,OAAO,IAAA;AAAA,IACT,CAAA;AAAA,IACA,MAAM,KAAK,KAAA,EAAyB;AAClC,MAAA,IAAA,GAAO,KAAA;AACP,MAAA,OAAA,IAAW,CAAA;AAAA,IACb,CAAA;AAAA,IACA,QAAQ,GAAA,EAA2B;AACjC,MAAA,OAAO,MAAM,GAAG,CAAA;AAAA,IAClB,CAAA;AAAA,IACA,MAAM,MAAA,GAAwB;AAG5B,MAAA,IAAA,GAAO,IAAA;AACP,MAAA,OAAA,GAAU,CAAA;AAAA,IACZ;AAAA,GACF;AACA,EAAA,IAAI,OAAA,CAAQ,MAAA,KAAW,IAAA,EAAM,OAAO,IAAA;AAEpC,EAAA,OAAO;AAAA,IACL,GAAG,IAAA;AAAA,IACH,MAAA,EAAQ,IAAA;AAAA,IACR,MAAM,UAAA,GAAyD;AAC7D,MAAA,OAAO,EAAE,GAAA,EAAK,IAAA,EAAM,OAAA,EAAQ;AAAA,IAC9B,CAAA;AAAA,IACA,MAAM,UAAA,CAAW,KAAA,EAAU,eAAA,EAA0C;AAInE,MAAA,IAAI,YAAY,eAAA,EAAiB;AAC/B,QAAA,MAAM,IAAI,kBAAA,CAAmB,eAAA,EAAiB,OAAO,CAAA;AAAA,MACvD;AACA,MAAA,IAAA,GAAO,KAAA;AACP,MAAA,OAAA,IAAW,CAAA;AACX,MAAA,OAAO,OAAA;AAAA,IACT;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\n * @packageDocumentation\n * @demlik/tea/mem — in-memory `Store<S>` adapter for `@demlik/tea`.\n *\n * The standard test adapter — used everywhere a Worker or DO would be\n * overkill. Mirrors the source-only convention from `packages/widget-engine`\n * and `packages/tea` (no build step).\n *\n * Reference semantics, NOT deep-clone semantics:\n * - `save(state)` stores the reference; subsequent mutations to that\n * reference by the caller are observable through later `load()` calls.\n * - `load()` returns the stored reference; mutations made through it are\n * observable on the next `load()`.\n *\n * This matches what a real KV/DO `get()` would NOT do (those serialize +\n * deserialize), but it also matches what an in-memory cache obviously does.\n * Adding a deep clone here would lie about the boundary and impose a JSON\n * round-trip on every test. Tests that need fresh copies should clone at the\n * call site.\n *\n * Boundary parse (invariant 8): `Store<S>` requires `migrate(raw)`. For\n * `memoryStore` we ship a permissive identity-default — `(raw) => raw as\n * S | null` — because this adapter is a degenerate same-process boundary:\n * there is no serialization, the reference we read is structurally the\n * reference we wrote. The `as` cast here is the documented exception to the\n * invariant-8 no-`as` rule, scoped to the parameter default. Callers that\n * want strict parsing (e.g. a test that hand-seeds the cell from outside)\n * may pass an explicit `parse` to override.\n */\n\nimport type { DeletableStore, FencedStore, Migrated } from \"../index\";\nimport { StoreConflictError } from \"../index\";\n\n/** Options for {@link memoryStore}. */\nexport interface MemoryStoreOptions {\n /**\n * Refuse a second live writer (#143). With `{ fenced: true }` the returned\n * store is a `FencedStore<S>` whose version is an in-process counter — honest\n * for this adapter, since the cell it guards is in this process too. Two\n * `run`s handed the SAME `memoryStore` are the case it catches, and it is the\n * cheapest way to exercise the fenced path in a test.\n */\n readonly fenced?: true;\n}\n\n/**\n * Build an in-memory `Store<S>`.\n *\n * @param initial - optional seed value. `undefined` and explicit `null` both\n * mean \"no seed\"; `load()` resolves with `null` until the first `save()`.\n * A concrete `S` seed is returned by `load()` until overwritten.\n * @param parse - optional boundary parse for the `Store<S>.migrate` contract.\n * Defaults to identity (`(raw) => raw as S | null`) — honest for this\n * adapter's degenerate same-process boundary. Pass an explicit parser when\n * the test wants to reject seeded shapes that don't match `S`.\n */\nexport function memoryStore<S>(\n initial?: S | null,\n parse?: (raw: unknown) => Migrated<S>,\n): DeletableStore<S>;\nexport function memoryStore<S>(\n initial: S | null | undefined,\n parse: ((raw: unknown) => Migrated<S>) | undefined,\n options: MemoryStoreOptions & { readonly fenced: true },\n): FencedStore<S> & DeletableStore<S>;\nexport function memoryStore<S>(\n initial?: S | null,\n parse?: (raw: unknown) => Migrated<S>,\n options?: MemoryStoreOptions,\n): DeletableStore<S> | (FencedStore<S> & DeletableStore<S>);\nexport function memoryStore<S>(\n initial?: S | null,\n parse: (raw: unknown) => Migrated<S> = (raw) => raw as S | null,\n options: MemoryStoreOptions = {},\n): DeletableStore<S> | (FencedStore<S> & DeletableStore<S>) {\n // Single internal cell — `undefined` and `null` collapse to one\n // representation so the load site is branchless.\n let cell: S | null = initial ?? null;\n // The version the cell was last written at. A never-written cell reads `0`,\n // matching `fileStore`'s absent stamp.\n let version = 0;\n\n const base: DeletableStore<S> = {\n async load(): Promise<unknown> {\n return cell;\n },\n async save(state: S): Promise<void> {\n cell = state;\n version += 1;\n },\n migrate(raw: unknown): Migrated<S> {\n return parse(raw);\n },\n async delete(): Promise<void> {\n // Back to never-written: an empty cell at version `0`. The seed is gone\n // too — `load()` answers what an unseeded store answers.\n cell = null;\n version = 0;\n },\n };\n if (options.fenced !== true) return base;\n\n return {\n ...base,\n fenced: true,\n async loadFenced(): Promise<{ raw: unknown; version: number }> {\n return { raw: cell, version };\n },\n async saveFenced(state: S, expectedVersion: number): Promise<number> {\n // No lock: the whole store is one process's memory, and this body has no\n // await before the compare, so nothing can interleave between the check\n // and the write.\n if (version !== expectedVersion) {\n throw new StoreConflictError(expectedVersion, version);\n }\n cell = state;\n version += 1;\n return version;\n },\n };\n}\n"]}
1
+ {"version":3,"sources":["../../src/mem/index.ts"],"names":[],"mappings":";;;;AAuEO,SAAS,WAAA,CACd,SACA,KAAA,GAAuC,CAAC,QAAQ,GAAA,EAChD,OAAA,GAA8B,EAAC,EAC2B;AAG1D,EAAA,IAAI,OAAiB,OAAA,IAAW,IAAA;AAGhC,EAAA,IAAI,OAAA,GAAU,CAAA;AAEd,EAAA,MAAM,IAAA,GAA0B;AAAA,IAC9B,MAAM,IAAA,GAAyB;AAC7B,MAAA,OAAO,IAAA;AAAA,IACT,CAAA;AAAA,IACA,MAAM,KAAK,KAAA,EAAyB;AAClC,MAAA,IAAA,GAAO,KAAA;AACP,MAAA,OAAA,IAAW,CAAA;AAAA,IACb,CAAA;AAAA,IACA,QAAQ,GAAA,EAA2B;AACjC,MAAA,OAAO,MAAM,GAAG,CAAA;AAAA,IAClB,CAAA;AAAA,IACA,MAAM,MAAA,GAAwB;AAG5B,MAAA,IAAA,GAAO,IAAA;AACP,MAAA,OAAA,GAAU,CAAA;AAAA,IACZ;AAAA,GACF;AACA,EAAA,IAAI,OAAA,CAAQ,MAAA,KAAW,IAAA,EAAM,OAAO,IAAA;AAEpC,EAAA,OAAO;AAAA,IACL,GAAG,IAAA;AAAA,IACH,MAAA,EAAQ,IAAA;AAAA,IACR,MAAM,UAAA,GAAyD;AAC7D,MAAA,OAAO,EAAE,GAAA,EAAK,IAAA,EAAM,OAAA,EAAQ;AAAA,IAC9B,CAAA;AAAA,IACA,MAAM,UAAA,CAAW,KAAA,EAAU,eAAA,EAA0C;AAInE,MAAA,IAAI,YAAY,eAAA,EAAiB;AAC/B,QAAA,MAAM,IAAI,kBAAA,CAAmB,eAAA,EAAiB,OAAO,CAAA;AAAA,MACvD;AACA,MAAA,IAAA,GAAO,KAAA;AACP,MAAA,OAAA,IAAW,CAAA;AACX,MAAA,OAAO,OAAA;AAAA,IACT;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\n * @packageDocumentation\n * @demlik/tea/mem — in-memory `Store<S>` adapter for `@demlik/tea`.\n *\n * The standard test adapter — used everywhere a Worker or DO would be\n * overkill. Mirrors the source-only convention from `packages/widget-engine`\n * and `packages/tea` (no build step).\n *\n * Reference semantics, NOT deep-clone semantics:\n * - `save(state)` stores the reference; subsequent mutations to that\n * reference by the caller are observable through later `load()` calls.\n * - `load()` returns the stored reference; mutations made through it are\n * observable on the next `load()`.\n *\n * This matches what a real KV/DO `get()` would NOT do (those serialize +\n * deserialize), but it also matches what an in-memory cache obviously does.\n * Adding a deep clone here would lie about the boundary and impose a JSON\n * round-trip on every test. Tests that need fresh copies should clone at the\n * call site.\n *\n * Boundary parse (invariant 8): `Store<S>` requires `migrate(raw)`. For\n * `memoryStore` we ship a permissive identity-default — `(raw) => raw as\n * S | null` — because this adapter is a degenerate same-process boundary:\n * there is no serialization, the reference we read is structurally the\n * reference we wrote. The `as` cast here is the documented exception to the\n * invariant-8 no-`as` rule, scoped to the parameter default. Callers that\n * want strict parsing (e.g. a test that hand-seeds the cell from outside)\n * may pass an explicit `parse` to override.\n */\n\nimport type { DeletableStore, FencedStore, Migrated } from \"../index\";\nimport { StoreConflictError } from \"../index\";\n\n/** Options for {@link memoryStore}. */\nexport interface MemoryStoreOptions {\n /**\n * Refuse a second live writer (#143). With `{ fenced: true }` the returned\n * store is a `FencedStore<S>` whose version is an in-process counter — honest\n * for this adapter, since the cell it guards is in this process too. Two\n * `run`s handed the SAME `memoryStore` are the case it catches, and it is the\n * cheapest way to exercise the fenced path in a test. A run on a fenced store\n * must be given an `onError` (see `StoreAndOnError`).\n */\n readonly fenced?: true;\n}\n\n/**\n * Build an in-memory `Store<S>`.\n *\n * @param initial - optional seed value. `undefined` and explicit `null` both\n * mean \"no seed\"; `load()` resolves with `null` until the first `save()`.\n * A concrete `S` seed is returned by `load()` until overwritten.\n * @param parse - optional boundary parse for the `Store<S>.migrate` contract.\n * Defaults to identity (`(raw) => raw as S | null`) — honest for this\n * adapter's degenerate same-process boundary. Pass an explicit parser when\n * the test wants to reject seeded shapes that don't match `S`.\n */\nexport function memoryStore<S>(\n initial?: S | null,\n parse?: (raw: unknown) => Migrated<S>,\n): DeletableStore<S>;\nexport function memoryStore<S>(\n initial: S | null | undefined,\n parse: ((raw: unknown) => Migrated<S>) | undefined,\n options: MemoryStoreOptions & { readonly fenced: true },\n): FencedStore<S> & DeletableStore<S>;\nexport function memoryStore<S>(\n initial?: S | null,\n parse?: (raw: unknown) => Migrated<S>,\n options?: MemoryStoreOptions,\n): DeletableStore<S> | (FencedStore<S> & DeletableStore<S>);\nexport function memoryStore<S>(\n initial?: S | null,\n parse: (raw: unknown) => Migrated<S> = (raw) => raw as S | null,\n options: MemoryStoreOptions = {},\n): DeletableStore<S> | (FencedStore<S> & DeletableStore<S>) {\n // Single internal cell — `undefined` and `null` collapse to one\n // representation so the load site is branchless.\n let cell: S | null = initial ?? null;\n // The version the cell was last written at. A never-written cell reads `0`,\n // matching `fileStore`'s absent stamp.\n let version = 0;\n\n const base: DeletableStore<S> = {\n async load(): Promise<unknown> {\n return cell;\n },\n async save(state: S): Promise<void> {\n cell = state;\n version += 1;\n },\n migrate(raw: unknown): Migrated<S> {\n return parse(raw);\n },\n async delete(): Promise<void> {\n // Back to never-written: an empty cell at version `0`. The seed is gone\n // too — `load()` answers what an unseeded store answers.\n cell = null;\n version = 0;\n },\n };\n if (options.fenced !== true) return base;\n\n return {\n ...base,\n fenced: true,\n async loadFenced(): Promise<{ raw: unknown; version: number }> {\n return { raw: cell, version };\n },\n async saveFenced(state: S, expectedVersion: number): Promise<number> {\n // No lock: the whole store is one process's memory, and this body has no\n // await before the compare, so nothing can interleave between the check\n // and the write.\n if (version !== expectedVersion) {\n throw new StoreConflictError(expectedVersion, version);\n }\n cell = state;\n version += 1;\n return version;\n },\n };\n}\n"]}