@directive-run/core 1.20.1 → 1.21.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 (82) hide show
  1. package/README.md +33 -0
  2. package/dist/adapter-utils.cjs +1 -1
  3. package/dist/adapter-utils.d.cts +2 -2
  4. package/dist/adapter-utils.d.ts +2 -2
  5. package/dist/adapter-utils.js +1 -1
  6. package/dist/chunk-4OXCKDKS.cjs +16 -0
  7. package/dist/chunk-4OXCKDKS.cjs.map +1 -0
  8. package/dist/chunk-6PF2FRBG.js +7 -0
  9. package/dist/chunk-6PF2FRBG.js.map +1 -0
  10. package/dist/chunk-6QAUJFQH.js +3 -0
  11. package/dist/chunk-6QAUJFQH.js.map +1 -0
  12. package/dist/chunk-E53A4NHM.js +16 -0
  13. package/dist/chunk-E53A4NHM.js.map +1 -0
  14. package/dist/{chunk-RWFKUNF7.cjs → chunk-GACC2DMS.cjs} +2 -2
  15. package/dist/{chunk-RWFKUNF7.cjs.map → chunk-GACC2DMS.cjs.map} +1 -1
  16. package/dist/{chunk-4MNQDXH7.cjs → chunk-GBCWXTXW.cjs} +3 -3
  17. package/dist/chunk-GBCWXTXW.cjs.map +1 -0
  18. package/dist/chunk-GKMJ7NMP.cjs +7 -0
  19. package/dist/chunk-GKMJ7NMP.cjs.map +1 -0
  20. package/dist/{chunk-WKCMOU2F.js → chunk-KGTBTGOY.js} +2 -2
  21. package/dist/{chunk-WKCMOU2F.js.map → chunk-KGTBTGOY.js.map} +1 -1
  22. package/dist/chunk-M5PEB553.cjs +3 -0
  23. package/dist/chunk-M5PEB553.cjs.map +1 -0
  24. package/dist/{chunk-4QCKAJCX.cjs → chunk-MARZI3EY.cjs} +2 -2
  25. package/dist/{chunk-4QCKAJCX.cjs.map → chunk-MARZI3EY.cjs.map} +1 -1
  26. package/dist/{chunk-O4GQEV4G.js → chunk-RBF653NR.js} +2 -2
  27. package/dist/{chunk-O4GQEV4G.js.map → chunk-RBF653NR.js.map} +1 -1
  28. package/dist/{chunk-PXRV64PA.js → chunk-SFUVPP4L.js} +3 -3
  29. package/dist/chunk-SFUVPP4L.js.map +1 -0
  30. package/dist/{index-lWCLfJfw.d.cts → index-CvQuu0tu.d.cts} +1 -1
  31. package/dist/{index-BMqDVv_d.d.ts → index-DUbpbGw8.d.ts} +1 -1
  32. package/dist/index.cjs +2 -2
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +6 -6
  35. package/dist/index.d.ts +6 -6
  36. package/dist/index.js +2 -2
  37. package/dist/index.js.map +1 -1
  38. package/dist/internals.cjs +1 -1
  39. package/dist/internals.d.cts +25 -7
  40. package/dist/internals.d.ts +25 -7
  41. package/dist/internals.js +1 -1
  42. package/dist/plugins/index.cjs +2 -2
  43. package/dist/plugins/index.cjs.map +1 -1
  44. package/dist/plugins/index.d.cts +2 -2
  45. package/dist/plugins/index.d.ts +2 -2
  46. package/dist/plugins/index.js +2 -2
  47. package/dist/plugins/index.js.map +1 -1
  48. package/dist/{plugins-Bs7Aidtt.d.ts → plugins-4IfhJV32.d.cts} +120 -13
  49. package/dist/{plugins-Bs7Aidtt.d.cts → plugins-4IfhJV32.d.ts} +120 -13
  50. package/dist/{predicate-Cw_lKU8y.d.ts → predicate-BW05x5el.d.ts} +1 -1
  51. package/dist/{predicate-DUgEw8j6.d.cts → predicate-DBTPnlg6.d.cts} +1 -1
  52. package/dist/system-SB7JYMRB.cjs +2 -0
  53. package/dist/{system-2WYCPIEG.cjs.map → system-SB7JYMRB.cjs.map} +1 -1
  54. package/dist/system-SJBP4TO5.js +2 -0
  55. package/dist/{system-6M36TQXF.js.map → system-SJBP4TO5.js.map} +1 -1
  56. package/dist/testing.cjs +1 -1
  57. package/dist/testing.d.cts +1 -1
  58. package/dist/testing.d.ts +1 -1
  59. package/dist/testing.js +1 -1
  60. package/dist/{utils-BZBBwS5A.d.cts → utils-DY8KTiD6.d.cts} +20 -7
  61. package/dist/{utils-BZBBwS5A.d.ts → utils-DY8KTiD6.d.ts} +20 -7
  62. package/dist/worker.cjs +1 -1
  63. package/dist/worker.d.cts +1 -1
  64. package/dist/worker.d.ts +1 -1
  65. package/dist/worker.js +1 -1
  66. package/package.json +1 -1
  67. package/dist/chunk-3ETCZLAY.js +0 -7
  68. package/dist/chunk-3ETCZLAY.js.map +0 -1
  69. package/dist/chunk-4MNQDXH7.cjs.map +0 -1
  70. package/dist/chunk-C3S6EG4Q.cjs +0 -3
  71. package/dist/chunk-C3S6EG4Q.cjs.map +0 -1
  72. package/dist/chunk-IMMKDLTV.js +0 -16
  73. package/dist/chunk-IMMKDLTV.js.map +0 -1
  74. package/dist/chunk-JGPPJV5P.cjs +0 -7
  75. package/dist/chunk-JGPPJV5P.cjs.map +0 -1
  76. package/dist/chunk-KSKFDTDA.js +0 -3
  77. package/dist/chunk-KSKFDTDA.js.map +0 -1
  78. package/dist/chunk-MF33A4BC.cjs +0 -16
  79. package/dist/chunk-MF33A4BC.cjs.map +0 -1
  80. package/dist/chunk-PXRV64PA.js.map +0 -1
  81. package/dist/system-2WYCPIEG.cjs +0 -2
  82. package/dist/system-6M36TQXF.js +0 -2
@@ -724,8 +724,8 @@ type EffectsDef<S extends Schema> = Record<string, EffectDef<S>>;
724
724
  *
725
725
  * The "hook-as-bridge" pattern — a `useEffect` that owns an external
726
726
  * subscription, maps incoming payloads, and dispatches `sys.events.X()` —
727
- * shows up in 7+ call sites across the Sizls workspace (Minglingo's
728
- * `useActiveRoundSystem`, `useBattleRoyaleSystem`, `eventClaims.realtime.ts`,
727
+ * shows up in 7+ call sites in the production app we dogfood Directive
728
+ * on (multiple realtime hooks plus a per-event-stream realtime adapter,
729
729
  * etc.). Each site re-derives the lifecycle plumbing.
730
730
  *
731
731
  * A `source` declares that plumbing as a first-class module field. The
@@ -813,6 +813,18 @@ type EffectsDef<S extends Schema> = Record<string, EffectDef<S>>;
813
813
  * an external stream).
814
814
  */
815
815
  type SourceUnsubscribe = () => void | Promise<void>;
816
+ /**
817
+ * Why a source publish was rejected. Mirrored across the three
818
+ * surfaces that report drops:
819
+ *
820
+ * - `SourceInspectionRow.lastDropReason` (operator-facing, on inspect())
821
+ * - `Plugin.onSourceDrop` (plugin hook)
822
+ * - `ObservationEvent` `source.drop` variant (system.observe())
823
+ *
824
+ * Centralizing the union here keeps the three from drifting when a
825
+ * new drop path is added to the engine.
826
+ */
827
+ type SourceDropReason = "post-destroy" | "post-stop" | "blocked-event-name" | "invalid-event-name" | "coalesced";
816
828
  /**
817
829
  * Typed event dispatcher passed to a source's `attach`. Calls into the same
818
830
  * dispatch queue used by `system.events.X(payload)`.
@@ -966,6 +978,24 @@ interface SourceDef {
966
978
  * 0009 documents the full DO-eviction recipe.
967
979
  */
968
980
  onEvict?: () => void | Promise<void>;
981
+ /**
982
+ * Per-source lifecycle timeout in milliseconds. Caps how long the
983
+ * manager waits for THIS source's `unsubscribe()` or `onEvict()`
984
+ * during teardown / eviction before declaring it hung and moving on.
985
+ *
986
+ * Defaults to 5000ms — comfortable for healthy transports, short
987
+ * enough for ops to recognize a hang. Override per source for
988
+ * legitimate long-tail teardowns:
989
+ *
990
+ * - Supabase channel that flushes a backlog before closing → 15000
991
+ * - OpenTelemetry batch span exporter draining a queue → 10000
992
+ * - Cloudflare DO storage flush awaiting D1 commit → 8000
993
+ *
994
+ * Sources that timeout still have their underlying work continue in
995
+ * the background — the manager just unblocks the rest of teardown.
996
+ * Setting this to `Infinity` disables the cap for this source only.
997
+ */
998
+ evictTimeoutMs?: number;
969
999
  }
970
1000
  /**
971
1001
  * Map of source definitions, keyed by source name. Collision rules match
@@ -1510,6 +1540,14 @@ interface NamespacedSystem<Modules extends ModulesMap> {
1510
1540
  readonly meta: MetaAccessor;
1511
1541
  /** Observe all lifecycle events as a typed stream. Returns an unsubscribe function. */
1512
1542
  observe(observer: (event: ObservationEvent) => void): () => void;
1543
+ /**
1544
+ * RFC 0010 — plugin authoring surface for emitting the
1545
+ * `"guardrail.blocked"` ObservationEvent. See `System.notify` for the
1546
+ * full contract.
1547
+ */
1548
+ readonly notify: {
1549
+ guardrailBlocked(plugin: string, key: string, kind: "redact" | "alert" | "detect", count: number, category?: string): void;
1550
+ };
1513
1551
  /** Per-run trace entries (null if trace is not enabled) */
1514
1552
  readonly trace: TraceEntry[] | null;
1515
1553
  /** Initialize facts and derivations without starting reconciliation. Safe for SSR. */
@@ -1773,6 +1811,14 @@ interface SingleModuleSystem<S extends ModuleSchema> {
1773
1811
  readonly meta: MetaAccessor;
1774
1812
  /** Observe all lifecycle events as a typed stream. Returns an unsubscribe function. */
1775
1813
  observe(observer: (event: ObservationEvent) => void): () => void;
1814
+ /**
1815
+ * RFC 0010 — plugin authoring surface for emitting the
1816
+ * `"guardrail.blocked"` ObservationEvent. See `System.notify` for the
1817
+ * full contract.
1818
+ */
1819
+ readonly notify: {
1820
+ guardrailBlocked(plugin: string, key: string, kind: "redact" | "alert" | "detect", count: number, category?: string): void;
1821
+ };
1776
1822
  /** Per-run trace entries (null if trace is not enabled) */
1777
1823
  readonly trace: TraceEntry[] | null;
1778
1824
  /** Initialize facts and derivations without starting reconciliation. Safe for SSR. */
@@ -2045,7 +2091,7 @@ interface ModuleHooks<M extends ModuleSchema> {
2045
2091
  *
2046
2092
  * @param error - The error the resolver threw (already normalized to `Error`).
2047
2093
  * @param requirement - The requirement object that the failing resolver was handling.
2048
- * @param ctx - Hook context, including a typed snapshot of this module's facts.
2094
+ * @param context - Hook context, including a typed snapshot of this module's facts.
2049
2095
  */
2050
2096
  onResolverError?: (error: Error, requirement: {
2051
2097
  type: string;
@@ -2370,10 +2416,6 @@ interface ModuleDef<M extends ModuleSchema = ModuleSchema> {
2370
2416
  crossModuleDeps?: CrossModuleDeps;
2371
2417
  }
2372
2418
 
2373
- /**
2374
- * System Types - Type definitions for the system
2375
- */
2376
-
2377
2419
  /**
2378
2420
  * Derive accessor from module schema.
2379
2421
  */
@@ -2408,6 +2450,35 @@ interface HistoryConfig {
2408
2450
  maxSnapshots?: number;
2409
2451
  /** Only snapshot events from these modules. Omit to snapshot all modules. Multi-module only. */
2410
2452
  snapshotModules?: string[];
2453
+ /**
2454
+ * Optional transform applied to the facts snapshot BEFORE it's
2455
+ * cloned into the ring buffer. The default (`undefined`) stores
2456
+ * facts verbatim — including any PII a source published into a
2457
+ * fact since the last snapshot.
2458
+ *
2459
+ * Wire a redactor to strip PII from the ring buffer (and from
2460
+ * `export()` payloads) for GDPR Art.17 erasure / SOC2 audit hygiene.
2461
+ * Pair with `createFactPIIGuardrail` on the input boundary for
2462
+ * end-to-end coverage — the guardrail redacts on writes,
2463
+ * `redactSnapshot` redacts whatever still escapes into history.
2464
+ *
2465
+ * Throws inside the redactor are caught and the snapshot falls
2466
+ * back to the raw facts with a structured `console.warn`; the
2467
+ * redactor must be defensive (return a safe fallback rather than
2468
+ * throwing) if redaction is load-bearing for compliance.
2469
+ *
2470
+ * @example
2471
+ * ```ts
2472
+ * createSystem({
2473
+ * module,
2474
+ * history: {
2475
+ * maxSnapshots: 100,
2476
+ * redactSnapshot: (facts) => ({ ...facts, email: "[REDACTED]" }),
2477
+ * },
2478
+ * });
2479
+ * ```
2480
+ */
2481
+ redactSnapshot?: (facts: Record<string, unknown>) => Record<string, unknown>;
2411
2482
  }
2412
2483
  /** History option: boolean shorthand or full config (presence implies enabled) */
2413
2484
  type HistoryOption = boolean | HistoryConfig;
@@ -2648,7 +2719,7 @@ interface SystemInspection {
2648
2719
  * - `"coalesced"` — manager debounced a same-event-name publish
2649
2720
  * when `SourceDef.coalesce === "lastWriteWins"`
2650
2721
  */
2651
- lastDropReason: "post-destroy" | "post-stop" | "blocked-event-name" | "invalid-event-name" | "coalesced" | null;
2722
+ lastDropReason: SourceDropReason | null;
2652
2723
  /** Wall-clock ms of the most recent rejected publish, or `null`. */
2653
2724
  lastDropAt: number | null;
2654
2725
  /** Total attach + cleanup errors since the last attachAll. */
@@ -3120,6 +3191,22 @@ type ObservationEvent = {
3120
3191
  moduleId: string;
3121
3192
  eventName: string;
3122
3193
  }
3194
+ /**
3195
+ * Engine- or manager-rejected publish. Pairs with `source.publish`
3196
+ * so observers see both halves of the publish path without polling
3197
+ * `inspect().sources[i].dropCount`. `reason` mirrors what the inspect
3198
+ * row records:
3199
+ * - `"post-destroy"` / `"post-stop"` — leaked transport firing after teardown
3200
+ * - `"blocked-event-name"` / `"invalid-event-name"` — engine guard probe
3201
+ * - `"coalesced"` — manager debounced a same-event publish within one microtask
3202
+ */
3203
+ | {
3204
+ type: "source.drop";
3205
+ id: string;
3206
+ moduleId: string;
3207
+ eventName: string;
3208
+ reason: SourceDropReason;
3209
+ }
3123
3210
  /** Source detached at `system.stop()` (reverse-registration order). */
3124
3211
  | {
3125
3212
  type: "source.detach";
@@ -3436,10 +3523,6 @@ interface SystemConfig<M extends ModuleSchema = ModuleSchema> {
3436
3523
  cloud?: boolean | string;
3437
3524
  }
3438
3525
 
3439
- /**
3440
- * Plugin Types - Type definitions for plugins
3441
- */
3442
-
3443
3526
  /** Reconcile result */
3444
3527
  interface ReconcileResult {
3445
3528
  unmet: RequirementWithId[];
@@ -3680,6 +3763,22 @@ interface Plugin<M extends ModuleSchema = ModuleSchema> {
3680
3763
  * @param eventName - The dispatched event name (the first arg to `publish`).
3681
3764
  */
3682
3765
  onSourcePublish?: (id: string, moduleId: string, eventName: string) => void;
3766
+ /**
3767
+ * Called when the engine OR the manager rejects a source publish.
3768
+ * Pairs with `onSourcePublish` so observers see both halves of the
3769
+ * publish path without polling `inspect().sources[i].dropCount`.
3770
+ *
3771
+ * `reason` mirrors `SourceInspectionRow.lastDropReason`:
3772
+ * - `"post-destroy"` / `"post-stop"` — leaked transport firing after teardown
3773
+ * - `"blocked-event-name"` / `"invalid-event-name"` — engine guard probe
3774
+ * - `"coalesced"` — manager debounced an in-tick same-event publish
3775
+ *
3776
+ * @param id - The source ID.
3777
+ * @param moduleId - The owning module's id.
3778
+ * @param eventName - The dispatched event name (the first arg to `publish`).
3779
+ * @param reason - Why the publish was rejected.
3780
+ */
3781
+ onSourceDrop?: (id: string, moduleId: string, eventName: string, reason: SourceDropReason) => void;
3683
3782
  /**
3684
3783
  * Called when a source detaches at `system.stop()` (reverse-registration
3685
3784
  * order across all modules).
@@ -3713,6 +3812,14 @@ interface Plugin<M extends ModuleSchema = ModuleSchema> {
3713
3812
  * `"alert"` (observed but did not mutate), or
3714
3813
  * `"detect"` (observed but could not mutate — e.g. read-only
3715
3814
  * structured types like `Error`).
3815
+ *
3816
+ * **Note:** `Error`-typed fact values always surface as `"detect"`
3817
+ * regardless of the guardrail's configured mode — the walker
3818
+ * matches `Error.message`/`.cause` but cannot mint a redacted
3819
+ * Error with guaranteed `.stack` parity. A subscriber counting
3820
+ * PII redactions should treat `kind === "redact"` and
3821
+ * `kind === "detect"` equivalently for compliance-incident
3822
+ * counts.
3716
3823
  * @param count - Number of pattern matches in this batch.
3717
3824
  * @param category - Optional coarse classifier the guardrail
3718
3825
  * provides so OTel exporters can label spans without parsing
@@ -3777,4 +3884,4 @@ interface Plugin<M extends ModuleSchema = ModuleSchema> {
3777
3884
  onTraceComplete?: (entry: TraceEntry) => void;
3778
3885
  }
3779
3886
 
3780
- export { type InferSchemaType as $, type AnySystem as A, type BatchConfig as B, type ClauseResult as C, type DefinitionMeta as D, type EffectsDef as E, type FactPredicate as F, type DynamicConstraintDef as G, type DynamicEffectDef as H, type DynamicResolverDef as I, type EffectDef as J, type EventsDef as K, type FactTemplate as L, type ModuleSchema as M, type NamespacedSystem as N, type FactsSnapshot as O, type Plugin as P, type HistoryAPI as Q, type RequirementWithId as R, type SchemaType as S, type TypedDerivationsDef as T, type HistoryOption as U, type HistoryState as V, type InferDerivations as W, type InferEvents as X, type InferFacts as Y, type InferRequirementTypes as Z, type InferRequirements as _, type Facts as a, type FlexibleEventHandler as a$, type InferSelectorState as a0, type KeySelector as a1, type MetaAccessor as a2, type MetaMatch as a3, type ObservationEvent as a4, type OperatorObject as a5, type PatchSpec as a6, type PatchValue as a7, type PayloadRef as a8, type PredicateClause as a9, type FactsStore as aA, type ConstraintState as aB, type ResolverStatus as aC, type FactChange as aD, type ReconcileResult as aE, type RecoveryStrategy as aF, type ErrorSource as aG, type RetryLaterConfig as aH, type BatchItemResult as aI, type BatchResolveResults as aJ, type ConstraintsControl as aK, type CrossModuleDerivationFn as aL, type CrossModuleFactsWithSelf as aM, type DerivationKeys as aN, type DerivationReturnType as aO, type DerivationsControl as aP, type DerivationsSchema as aQ, type DeriveAccessor as aR, type DispatchEventsFromSchema as aS, type EffectCleanup as aT, type EffectsControl as aU, type EventPayloadSchema as aV, type EventsAccessor as aW, type EventsAccessorFromSchema as aX, type EventsSchema as aY, type FactKeys as aZ, type FactReturnType as a_, type PredicateCombinator as aa, type PredicateCombinatorKey as ab, type PredicateObject as ac, type PredicateOp as ad, type ResolverDef as ae, type ResolversDef as af, type RetryPolicy as ag, type Schema as ah, type SchemaTypedResolversDef as ai, type Snapshot as aj, type SourceDef as ak, type SourcePublish as al, type SourceReportError as am, type SourceUnsubscribe as an, type System as ao, type SystemConfig as ap, type SystemDerived as aq, type SystemFacts as ar, type SystemInspection as as, type SystemMode as at, type SystemSnapshot as au, type TraceEntry as av, type TypedConstraintDef as aw, type TypedResolverDef as ax, isNamespacedSystem as ay, isSingleModuleSystem as az, type TypedEventsDef as b, type HistoryConfig as b0, type InferEventPayloadFromSchema as b1, type InferRequirementPayloadFromSchema as b2, type InferSchema as b3, type MutableNamespacedFacts as b4, type NamespacedDerivations as b5, type NamespacedEventsAccessor as b6, type NamespacedFacts as b7, type ObservableKeys as b8, type RequirementExplanation as b9, type RequirementOutput as ba, type RequirementPayloadSchema$1 as bb, type RequirementsSchema as bc, type ResolverContext as bd, type ResolversControl as be, type SnapshotMeta as bf, type SystemEvent as bg, type TraceConfig as bh, type TypedResolverContext as bi, type UnionEvents as bj, type RequirementOutput$1 as bk, type SourcesDef as c, type TypedConstraintsDef as d, type TypedResolversDef as e, type ModuleHooks as f, type CrossModuleDeps as g, type CrossModuleDerivationsDef as h, type CrossModuleEffectsDef as i, type CrossModuleConstraintsDef as j, type ModuleDef as k, type CreateSystemOptionsSingle as l, type SingleModuleSystem as m, type ModulesMap as n, type CreateSystemOptionsNamed as o, type TraceOption as p, type ErrorBoundaryConfig as q, type Requirement as r, type RequirementKeyFn as s, type ConstraintDef as t, type ConstraintsDef as u, type CrossModuleConstraintDef as v, type CrossModuleEffectDef as w, DirectiveError as x, type DistributableSnapshot as y, type DistributableSnapshotOptions as z };
3887
+ export { type InferSchemaType as $, type AnySystem as A, type BatchConfig as B, type ClauseResult as C, type DefinitionMeta as D, type EffectsDef as E, type FactPredicate as F, type DynamicConstraintDef as G, type DynamicEffectDef as H, type DynamicResolverDef as I, type EffectDef as J, type EventsDef as K, type FactTemplate as L, type ModuleSchema as M, type NamespacedSystem as N, type FactsSnapshot as O, type Plugin as P, type HistoryAPI as Q, type RequirementWithId as R, type SchemaType as S, type TypedDerivationsDef as T, type HistoryOption as U, type HistoryState as V, type InferDerivations as W, type InferEvents as X, type InferFacts as Y, type InferRequirementTypes as Z, type InferRequirements as _, type Facts as a, type FactReturnType as a$, type InferSelectorState as a0, type KeySelector as a1, type MetaAccessor as a2, type MetaMatch as a3, type ObservationEvent as a4, type OperatorObject as a5, type PatchSpec as a6, type PatchValue as a7, type PayloadRef as a8, type PredicateClause as a9, isSingleModuleSystem as aA, type FactsStore as aB, type ConstraintState as aC, type ResolverStatus as aD, type FactChange as aE, type ReconcileResult as aF, type RecoveryStrategy as aG, type ErrorSource as aH, type RetryLaterConfig as aI, type BatchItemResult as aJ, type BatchResolveResults as aK, type ConstraintsControl as aL, type CrossModuleDerivationFn as aM, type CrossModuleFactsWithSelf as aN, type DerivationKeys as aO, type DerivationReturnType as aP, type DerivationsControl as aQ, type DerivationsSchema as aR, type DeriveAccessor as aS, type DispatchEventsFromSchema as aT, type EffectCleanup as aU, type EffectsControl as aV, type EventPayloadSchema as aW, type EventsAccessor as aX, type EventsAccessorFromSchema as aY, type EventsSchema as aZ, type FactKeys as a_, type PredicateCombinator as aa, type PredicateCombinatorKey as ab, type PredicateObject as ac, type PredicateOp as ad, type ResolverDef as ae, type ResolversDef as af, type RetryPolicy as ag, type Schema as ah, type SchemaTypedResolversDef as ai, type Snapshot as aj, type SourceDef as ak, type SourceDropReason as al, type SourcePublish as am, type SourceReportError as an, type SourceUnsubscribe as ao, type System as ap, type SystemConfig as aq, type SystemDerived as ar, type SystemFacts as as, type SystemInspection as at, type SystemMode as au, type SystemSnapshot as av, type TraceEntry as aw, type TypedConstraintDef as ax, type TypedResolverDef as ay, isNamespacedSystem as az, type TypedEventsDef as b, type FlexibleEventHandler as b0, type HistoryConfig as b1, type InferEventPayloadFromSchema as b2, type InferRequirementPayloadFromSchema as b3, type InferSchema as b4, type MutableNamespacedFacts as b5, type NamespacedDerivations as b6, type NamespacedEventsAccessor as b7, type NamespacedFacts as b8, type ObservableKeys as b9, type RequirementExplanation as ba, type RequirementOutput as bb, type RequirementPayloadSchema$1 as bc, type RequirementsSchema as bd, type ResolverContext as be, type ResolversControl as bf, type SnapshotMeta as bg, type SystemEvent as bh, type TraceConfig as bi, type TypedResolverContext as bj, type UnionEvents as bk, type RequirementOutput$1 as bl, type SourcesDef as c, type TypedConstraintsDef as d, type TypedResolversDef as e, type ModuleHooks as f, type CrossModuleDeps as g, type CrossModuleDerivationsDef as h, type CrossModuleEffectsDef as i, type CrossModuleConstraintsDef as j, type ModuleDef as k, type CreateSystemOptionsSingle as l, type SingleModuleSystem as m, type ModulesMap as n, type CreateSystemOptionsNamed as o, type TraceOption as p, type ErrorBoundaryConfig as q, type Requirement as r, type RequirementKeyFn as s, type ConstraintDef as t, type ConstraintsDef as u, type CrossModuleConstraintDef as v, type CrossModuleEffectDef as w, DirectiveError as x, type DistributableSnapshot as y, type DistributableSnapshotOptions as z };
@@ -724,8 +724,8 @@ type EffectsDef<S extends Schema> = Record<string, EffectDef<S>>;
724
724
  *
725
725
  * The "hook-as-bridge" pattern — a `useEffect` that owns an external
726
726
  * subscription, maps incoming payloads, and dispatches `sys.events.X()` —
727
- * shows up in 7+ call sites across the Sizls workspace (Minglingo's
728
- * `useActiveRoundSystem`, `useBattleRoyaleSystem`, `eventClaims.realtime.ts`,
727
+ * shows up in 7+ call sites in the production app we dogfood Directive
728
+ * on (multiple realtime hooks plus a per-event-stream realtime adapter,
729
729
  * etc.). Each site re-derives the lifecycle plumbing.
730
730
  *
731
731
  * A `source` declares that plumbing as a first-class module field. The
@@ -813,6 +813,18 @@ type EffectsDef<S extends Schema> = Record<string, EffectDef<S>>;
813
813
  * an external stream).
814
814
  */
815
815
  type SourceUnsubscribe = () => void | Promise<void>;
816
+ /**
817
+ * Why a source publish was rejected. Mirrored across the three
818
+ * surfaces that report drops:
819
+ *
820
+ * - `SourceInspectionRow.lastDropReason` (operator-facing, on inspect())
821
+ * - `Plugin.onSourceDrop` (plugin hook)
822
+ * - `ObservationEvent` `source.drop` variant (system.observe())
823
+ *
824
+ * Centralizing the union here keeps the three from drifting when a
825
+ * new drop path is added to the engine.
826
+ */
827
+ type SourceDropReason = "post-destroy" | "post-stop" | "blocked-event-name" | "invalid-event-name" | "coalesced";
816
828
  /**
817
829
  * Typed event dispatcher passed to a source's `attach`. Calls into the same
818
830
  * dispatch queue used by `system.events.X(payload)`.
@@ -966,6 +978,24 @@ interface SourceDef {
966
978
  * 0009 documents the full DO-eviction recipe.
967
979
  */
968
980
  onEvict?: () => void | Promise<void>;
981
+ /**
982
+ * Per-source lifecycle timeout in milliseconds. Caps how long the
983
+ * manager waits for THIS source's `unsubscribe()` or `onEvict()`
984
+ * during teardown / eviction before declaring it hung and moving on.
985
+ *
986
+ * Defaults to 5000ms — comfortable for healthy transports, short
987
+ * enough for ops to recognize a hang. Override per source for
988
+ * legitimate long-tail teardowns:
989
+ *
990
+ * - Supabase channel that flushes a backlog before closing → 15000
991
+ * - OpenTelemetry batch span exporter draining a queue → 10000
992
+ * - Cloudflare DO storage flush awaiting D1 commit → 8000
993
+ *
994
+ * Sources that timeout still have their underlying work continue in
995
+ * the background — the manager just unblocks the rest of teardown.
996
+ * Setting this to `Infinity` disables the cap for this source only.
997
+ */
998
+ evictTimeoutMs?: number;
969
999
  }
970
1000
  /**
971
1001
  * Map of source definitions, keyed by source name. Collision rules match
@@ -1510,6 +1540,14 @@ interface NamespacedSystem<Modules extends ModulesMap> {
1510
1540
  readonly meta: MetaAccessor;
1511
1541
  /** Observe all lifecycle events as a typed stream. Returns an unsubscribe function. */
1512
1542
  observe(observer: (event: ObservationEvent) => void): () => void;
1543
+ /**
1544
+ * RFC 0010 — plugin authoring surface for emitting the
1545
+ * `"guardrail.blocked"` ObservationEvent. See `System.notify` for the
1546
+ * full contract.
1547
+ */
1548
+ readonly notify: {
1549
+ guardrailBlocked(plugin: string, key: string, kind: "redact" | "alert" | "detect", count: number, category?: string): void;
1550
+ };
1513
1551
  /** Per-run trace entries (null if trace is not enabled) */
1514
1552
  readonly trace: TraceEntry[] | null;
1515
1553
  /** Initialize facts and derivations without starting reconciliation. Safe for SSR. */
@@ -1773,6 +1811,14 @@ interface SingleModuleSystem<S extends ModuleSchema> {
1773
1811
  readonly meta: MetaAccessor;
1774
1812
  /** Observe all lifecycle events as a typed stream. Returns an unsubscribe function. */
1775
1813
  observe(observer: (event: ObservationEvent) => void): () => void;
1814
+ /**
1815
+ * RFC 0010 — plugin authoring surface for emitting the
1816
+ * `"guardrail.blocked"` ObservationEvent. See `System.notify` for the
1817
+ * full contract.
1818
+ */
1819
+ readonly notify: {
1820
+ guardrailBlocked(plugin: string, key: string, kind: "redact" | "alert" | "detect", count: number, category?: string): void;
1821
+ };
1776
1822
  /** Per-run trace entries (null if trace is not enabled) */
1777
1823
  readonly trace: TraceEntry[] | null;
1778
1824
  /** Initialize facts and derivations without starting reconciliation. Safe for SSR. */
@@ -2045,7 +2091,7 @@ interface ModuleHooks<M extends ModuleSchema> {
2045
2091
  *
2046
2092
  * @param error - The error the resolver threw (already normalized to `Error`).
2047
2093
  * @param requirement - The requirement object that the failing resolver was handling.
2048
- * @param ctx - Hook context, including a typed snapshot of this module's facts.
2094
+ * @param context - Hook context, including a typed snapshot of this module's facts.
2049
2095
  */
2050
2096
  onResolverError?: (error: Error, requirement: {
2051
2097
  type: string;
@@ -2370,10 +2416,6 @@ interface ModuleDef<M extends ModuleSchema = ModuleSchema> {
2370
2416
  crossModuleDeps?: CrossModuleDeps;
2371
2417
  }
2372
2418
 
2373
- /**
2374
- * System Types - Type definitions for the system
2375
- */
2376
-
2377
2419
  /**
2378
2420
  * Derive accessor from module schema.
2379
2421
  */
@@ -2408,6 +2450,35 @@ interface HistoryConfig {
2408
2450
  maxSnapshots?: number;
2409
2451
  /** Only snapshot events from these modules. Omit to snapshot all modules. Multi-module only. */
2410
2452
  snapshotModules?: string[];
2453
+ /**
2454
+ * Optional transform applied to the facts snapshot BEFORE it's
2455
+ * cloned into the ring buffer. The default (`undefined`) stores
2456
+ * facts verbatim — including any PII a source published into a
2457
+ * fact since the last snapshot.
2458
+ *
2459
+ * Wire a redactor to strip PII from the ring buffer (and from
2460
+ * `export()` payloads) for GDPR Art.17 erasure / SOC2 audit hygiene.
2461
+ * Pair with `createFactPIIGuardrail` on the input boundary for
2462
+ * end-to-end coverage — the guardrail redacts on writes,
2463
+ * `redactSnapshot` redacts whatever still escapes into history.
2464
+ *
2465
+ * Throws inside the redactor are caught and the snapshot falls
2466
+ * back to the raw facts with a structured `console.warn`; the
2467
+ * redactor must be defensive (return a safe fallback rather than
2468
+ * throwing) if redaction is load-bearing for compliance.
2469
+ *
2470
+ * @example
2471
+ * ```ts
2472
+ * createSystem({
2473
+ * module,
2474
+ * history: {
2475
+ * maxSnapshots: 100,
2476
+ * redactSnapshot: (facts) => ({ ...facts, email: "[REDACTED]" }),
2477
+ * },
2478
+ * });
2479
+ * ```
2480
+ */
2481
+ redactSnapshot?: (facts: Record<string, unknown>) => Record<string, unknown>;
2411
2482
  }
2412
2483
  /** History option: boolean shorthand or full config (presence implies enabled) */
2413
2484
  type HistoryOption = boolean | HistoryConfig;
@@ -2648,7 +2719,7 @@ interface SystemInspection {
2648
2719
  * - `"coalesced"` — manager debounced a same-event-name publish
2649
2720
  * when `SourceDef.coalesce === "lastWriteWins"`
2650
2721
  */
2651
- lastDropReason: "post-destroy" | "post-stop" | "blocked-event-name" | "invalid-event-name" | "coalesced" | null;
2722
+ lastDropReason: SourceDropReason | null;
2652
2723
  /** Wall-clock ms of the most recent rejected publish, or `null`. */
2653
2724
  lastDropAt: number | null;
2654
2725
  /** Total attach + cleanup errors since the last attachAll. */
@@ -3120,6 +3191,22 @@ type ObservationEvent = {
3120
3191
  moduleId: string;
3121
3192
  eventName: string;
3122
3193
  }
3194
+ /**
3195
+ * Engine- or manager-rejected publish. Pairs with `source.publish`
3196
+ * so observers see both halves of the publish path without polling
3197
+ * `inspect().sources[i].dropCount`. `reason` mirrors what the inspect
3198
+ * row records:
3199
+ * - `"post-destroy"` / `"post-stop"` — leaked transport firing after teardown
3200
+ * - `"blocked-event-name"` / `"invalid-event-name"` — engine guard probe
3201
+ * - `"coalesced"` — manager debounced a same-event publish within one microtask
3202
+ */
3203
+ | {
3204
+ type: "source.drop";
3205
+ id: string;
3206
+ moduleId: string;
3207
+ eventName: string;
3208
+ reason: SourceDropReason;
3209
+ }
3123
3210
  /** Source detached at `system.stop()` (reverse-registration order). */
3124
3211
  | {
3125
3212
  type: "source.detach";
@@ -3436,10 +3523,6 @@ interface SystemConfig<M extends ModuleSchema = ModuleSchema> {
3436
3523
  cloud?: boolean | string;
3437
3524
  }
3438
3525
 
3439
- /**
3440
- * Plugin Types - Type definitions for plugins
3441
- */
3442
-
3443
3526
  /** Reconcile result */
3444
3527
  interface ReconcileResult {
3445
3528
  unmet: RequirementWithId[];
@@ -3680,6 +3763,22 @@ interface Plugin<M extends ModuleSchema = ModuleSchema> {
3680
3763
  * @param eventName - The dispatched event name (the first arg to `publish`).
3681
3764
  */
3682
3765
  onSourcePublish?: (id: string, moduleId: string, eventName: string) => void;
3766
+ /**
3767
+ * Called when the engine OR the manager rejects a source publish.
3768
+ * Pairs with `onSourcePublish` so observers see both halves of the
3769
+ * publish path without polling `inspect().sources[i].dropCount`.
3770
+ *
3771
+ * `reason` mirrors `SourceInspectionRow.lastDropReason`:
3772
+ * - `"post-destroy"` / `"post-stop"` — leaked transport firing after teardown
3773
+ * - `"blocked-event-name"` / `"invalid-event-name"` — engine guard probe
3774
+ * - `"coalesced"` — manager debounced an in-tick same-event publish
3775
+ *
3776
+ * @param id - The source ID.
3777
+ * @param moduleId - The owning module's id.
3778
+ * @param eventName - The dispatched event name (the first arg to `publish`).
3779
+ * @param reason - Why the publish was rejected.
3780
+ */
3781
+ onSourceDrop?: (id: string, moduleId: string, eventName: string, reason: SourceDropReason) => void;
3683
3782
  /**
3684
3783
  * Called when a source detaches at `system.stop()` (reverse-registration
3685
3784
  * order across all modules).
@@ -3713,6 +3812,14 @@ interface Plugin<M extends ModuleSchema = ModuleSchema> {
3713
3812
  * `"alert"` (observed but did not mutate), or
3714
3813
  * `"detect"` (observed but could not mutate — e.g. read-only
3715
3814
  * structured types like `Error`).
3815
+ *
3816
+ * **Note:** `Error`-typed fact values always surface as `"detect"`
3817
+ * regardless of the guardrail's configured mode — the walker
3818
+ * matches `Error.message`/`.cause` but cannot mint a redacted
3819
+ * Error with guaranteed `.stack` parity. A subscriber counting
3820
+ * PII redactions should treat `kind === "redact"` and
3821
+ * `kind === "detect"` equivalently for compliance-incident
3822
+ * counts.
3716
3823
  * @param count - Number of pattern matches in this batch.
3717
3824
  * @param category - Optional coarse classifier the guardrail
3718
3825
  * provides so OTel exporters can label spans without parsing
@@ -3777,4 +3884,4 @@ interface Plugin<M extends ModuleSchema = ModuleSchema> {
3777
3884
  onTraceComplete?: (entry: TraceEntry) => void;
3778
3885
  }
3779
3886
 
3780
- export { type InferSchemaType as $, type AnySystem as A, type BatchConfig as B, type ClauseResult as C, type DefinitionMeta as D, type EffectsDef as E, type FactPredicate as F, type DynamicConstraintDef as G, type DynamicEffectDef as H, type DynamicResolverDef as I, type EffectDef as J, type EventsDef as K, type FactTemplate as L, type ModuleSchema as M, type NamespacedSystem as N, type FactsSnapshot as O, type Plugin as P, type HistoryAPI as Q, type RequirementWithId as R, type SchemaType as S, type TypedDerivationsDef as T, type HistoryOption as U, type HistoryState as V, type InferDerivations as W, type InferEvents as X, type InferFacts as Y, type InferRequirementTypes as Z, type InferRequirements as _, type Facts as a, type FlexibleEventHandler as a$, type InferSelectorState as a0, type KeySelector as a1, type MetaAccessor as a2, type MetaMatch as a3, type ObservationEvent as a4, type OperatorObject as a5, type PatchSpec as a6, type PatchValue as a7, type PayloadRef as a8, type PredicateClause as a9, type FactsStore as aA, type ConstraintState as aB, type ResolverStatus as aC, type FactChange as aD, type ReconcileResult as aE, type RecoveryStrategy as aF, type ErrorSource as aG, type RetryLaterConfig as aH, type BatchItemResult as aI, type BatchResolveResults as aJ, type ConstraintsControl as aK, type CrossModuleDerivationFn as aL, type CrossModuleFactsWithSelf as aM, type DerivationKeys as aN, type DerivationReturnType as aO, type DerivationsControl as aP, type DerivationsSchema as aQ, type DeriveAccessor as aR, type DispatchEventsFromSchema as aS, type EffectCleanup as aT, type EffectsControl as aU, type EventPayloadSchema as aV, type EventsAccessor as aW, type EventsAccessorFromSchema as aX, type EventsSchema as aY, type FactKeys as aZ, type FactReturnType as a_, type PredicateCombinator as aa, type PredicateCombinatorKey as ab, type PredicateObject as ac, type PredicateOp as ad, type ResolverDef as ae, type ResolversDef as af, type RetryPolicy as ag, type Schema as ah, type SchemaTypedResolversDef as ai, type Snapshot as aj, type SourceDef as ak, type SourcePublish as al, type SourceReportError as am, type SourceUnsubscribe as an, type System as ao, type SystemConfig as ap, type SystemDerived as aq, type SystemFacts as ar, type SystemInspection as as, type SystemMode as at, type SystemSnapshot as au, type TraceEntry as av, type TypedConstraintDef as aw, type TypedResolverDef as ax, isNamespacedSystem as ay, isSingleModuleSystem as az, type TypedEventsDef as b, type HistoryConfig as b0, type InferEventPayloadFromSchema as b1, type InferRequirementPayloadFromSchema as b2, type InferSchema as b3, type MutableNamespacedFacts as b4, type NamespacedDerivations as b5, type NamespacedEventsAccessor as b6, type NamespacedFacts as b7, type ObservableKeys as b8, type RequirementExplanation as b9, type RequirementOutput as ba, type RequirementPayloadSchema$1 as bb, type RequirementsSchema as bc, type ResolverContext as bd, type ResolversControl as be, type SnapshotMeta as bf, type SystemEvent as bg, type TraceConfig as bh, type TypedResolverContext as bi, type UnionEvents as bj, type RequirementOutput$1 as bk, type SourcesDef as c, type TypedConstraintsDef as d, type TypedResolversDef as e, type ModuleHooks as f, type CrossModuleDeps as g, type CrossModuleDerivationsDef as h, type CrossModuleEffectsDef as i, type CrossModuleConstraintsDef as j, type ModuleDef as k, type CreateSystemOptionsSingle as l, type SingleModuleSystem as m, type ModulesMap as n, type CreateSystemOptionsNamed as o, type TraceOption as p, type ErrorBoundaryConfig as q, type Requirement as r, type RequirementKeyFn as s, type ConstraintDef as t, type ConstraintsDef as u, type CrossModuleConstraintDef as v, type CrossModuleEffectDef as w, DirectiveError as x, type DistributableSnapshot as y, type DistributableSnapshotOptions as z };
3887
+ export { type InferSchemaType as $, type AnySystem as A, type BatchConfig as B, type ClauseResult as C, type DefinitionMeta as D, type EffectsDef as E, type FactPredicate as F, type DynamicConstraintDef as G, type DynamicEffectDef as H, type DynamicResolverDef as I, type EffectDef as J, type EventsDef as K, type FactTemplate as L, type ModuleSchema as M, type NamespacedSystem as N, type FactsSnapshot as O, type Plugin as P, type HistoryAPI as Q, type RequirementWithId as R, type SchemaType as S, type TypedDerivationsDef as T, type HistoryOption as U, type HistoryState as V, type InferDerivations as W, type InferEvents as X, type InferFacts as Y, type InferRequirementTypes as Z, type InferRequirements as _, type Facts as a, type FactReturnType as a$, type InferSelectorState as a0, type KeySelector as a1, type MetaAccessor as a2, type MetaMatch as a3, type ObservationEvent as a4, type OperatorObject as a5, type PatchSpec as a6, type PatchValue as a7, type PayloadRef as a8, type PredicateClause as a9, isSingleModuleSystem as aA, type FactsStore as aB, type ConstraintState as aC, type ResolverStatus as aD, type FactChange as aE, type ReconcileResult as aF, type RecoveryStrategy as aG, type ErrorSource as aH, type RetryLaterConfig as aI, type BatchItemResult as aJ, type BatchResolveResults as aK, type ConstraintsControl as aL, type CrossModuleDerivationFn as aM, type CrossModuleFactsWithSelf as aN, type DerivationKeys as aO, type DerivationReturnType as aP, type DerivationsControl as aQ, type DerivationsSchema as aR, type DeriveAccessor as aS, type DispatchEventsFromSchema as aT, type EffectCleanup as aU, type EffectsControl as aV, type EventPayloadSchema as aW, type EventsAccessor as aX, type EventsAccessorFromSchema as aY, type EventsSchema as aZ, type FactKeys as a_, type PredicateCombinator as aa, type PredicateCombinatorKey as ab, type PredicateObject as ac, type PredicateOp as ad, type ResolverDef as ae, type ResolversDef as af, type RetryPolicy as ag, type Schema as ah, type SchemaTypedResolversDef as ai, type Snapshot as aj, type SourceDef as ak, type SourceDropReason as al, type SourcePublish as am, type SourceReportError as an, type SourceUnsubscribe as ao, type System as ap, type SystemConfig as aq, type SystemDerived as ar, type SystemFacts as as, type SystemInspection as at, type SystemMode as au, type SystemSnapshot as av, type TraceEntry as aw, type TypedConstraintDef as ax, type TypedResolverDef as ay, isNamespacedSystem as az, type TypedEventsDef as b, type FlexibleEventHandler as b0, type HistoryConfig as b1, type InferEventPayloadFromSchema as b2, type InferRequirementPayloadFromSchema as b3, type InferSchema as b4, type MutableNamespacedFacts as b5, type NamespacedDerivations as b6, type NamespacedEventsAccessor as b7, type NamespacedFacts as b8, type ObservableKeys as b9, type RequirementExplanation as ba, type RequirementOutput as bb, type RequirementPayloadSchema$1 as bc, type RequirementsSchema as bd, type ResolverContext as be, type ResolversControl as bf, type SnapshotMeta as bg, type SystemEvent as bh, type TraceConfig as bi, type TypedResolverContext as bj, type UnionEvents as bk, type RequirementOutput$1 as bl, type SourcesDef as c, type TypedConstraintsDef as d, type TypedResolversDef as e, type ModuleHooks as f, type CrossModuleDeps as g, type CrossModuleDerivationsDef as h, type CrossModuleEffectsDef as i, type CrossModuleConstraintsDef as j, type ModuleDef as k, type CreateSystemOptionsSingle as l, type SingleModuleSystem as m, type ModulesMap as n, type CreateSystemOptionsNamed as o, type TraceOption as p, type ErrorBoundaryConfig as q, type Requirement as r, type RequirementKeyFn as s, type ConstraintDef as t, type ConstraintsDef as u, type CrossModuleConstraintDef as v, type CrossModuleEffectDef as w, DirectiveError as x, type DistributableSnapshot as y, type DistributableSnapshotOptions as z };
@@ -1,4 +1,4 @@
1
- import { ah as Schema, a as Facts, F as FactPredicate, b3 as InferSchema, L as FactTemplate, D as DefinitionMeta, r as Requirement, bk as RequirementOutput, ag as RetryPolicy, B as BatchConfig, bd as ResolverContext, ad as PredicateOp, a6 as PatchSpec, C as ClauseResult } from './plugins-Bs7Aidtt.js';
1
+ import { ah as Schema, a as Facts, F as FactPredicate, b4 as InferSchema, L as FactTemplate, D as DefinitionMeta, r as Requirement, bl as RequirementOutput, ag as RetryPolicy, B as BatchConfig, be as ResolverContext, ad as PredicateOp, a6 as PatchSpec, C as ClauseResult } from './plugins-4IfhJV32.js';
2
2
 
3
3
  /**
4
4
  * Derivation Types - Type definitions for derivations
@@ -1,4 +1,4 @@
1
- import { ah as Schema, a as Facts, F as FactPredicate, b3 as InferSchema, L as FactTemplate, D as DefinitionMeta, r as Requirement, bk as RequirementOutput, ag as RetryPolicy, B as BatchConfig, bd as ResolverContext, ad as PredicateOp, a6 as PatchSpec, C as ClauseResult } from './plugins-Bs7Aidtt.cjs';
1
+ import { ah as Schema, a as Facts, F as FactPredicate, b4 as InferSchema, L as FactTemplate, D as DefinitionMeta, r as Requirement, bl as RequirementOutput, ag as RetryPolicy, B as BatchConfig, be as ResolverContext, ad as PredicateOp, a6 as PatchSpec, C as ClauseResult } from './plugins-4IfhJV32.cjs';
2
2
 
3
3
  /**
4
4
  * Derivation Types - Type definitions for derivations
@@ -0,0 +1,2 @@
1
+ 'use strict';var chunk4OXCKDKS_cjs=require('./chunk-4OXCKDKS.cjs');require('./chunk-M5PEB553.cjs'),require('./chunk-GACC2DMS.cjs'),require('./chunk-GKMJ7NMP.cjs'),require('./chunk-GBCWXTXW.cjs');Object.defineProperty(exports,"createSystem",{enumerable:true,get:function(){return chunk4OXCKDKS_cjs.a}});//# sourceMappingURL=system-SB7JYMRB.cjs.map
2
+ //# sourceMappingURL=system-SB7JYMRB.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"system-2WYCPIEG.cjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"system-SB7JYMRB.cjs"}
@@ -0,0 +1,2 @@
1
+ export{a as createSystem}from'./chunk-E53A4NHM.js';import'./chunk-6QAUJFQH.js';import'./chunk-RBF653NR.js';import'./chunk-6PF2FRBG.js';import'./chunk-SFUVPP4L.js';//# sourceMappingURL=system-SJBP4TO5.js.map
2
+ //# sourceMappingURL=system-SJBP4TO5.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"system-6M36TQXF.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"system-SJBP4TO5.js"}
package/dist/testing.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var chunkMF33A4BC_cjs=require('./chunk-MF33A4BC.cjs');require('./chunk-C3S6EG4Q.cjs'),require('./chunk-RWFKUNF7.cjs'),require('./chunk-JGPPJV5P.cjs'),require('./chunk-4MNQDXH7.cjs');async function R(){for(let e=0;e<10;e++)await Promise.resolve();}async function T(){for(let e=0;e<10;e++)await Promise.resolve();await new Promise(e=>setTimeout(e,0));for(let e=0;e<10;e++)await Promise.resolve();await new Promise(e=>setTimeout(e,0));for(let e=0;e<10;e++)await Promise.resolve();}async function D(e,s,r={}){let{totalTime:o=5e3,stepSize:c=10,maxIterations:l=1e3}=r,m=0,d=0;for(;m<o&&d<l;){if(await R(),e.inspect().inflight.length===0){await R();return}s(c),m+=c,d++;}let v=e.inspect();if(v.inflight.length>0){let f=v.inflight.map(p=>p.resolverId).join(", ");throw new Error(`[Directive] settleWithFakeTimers did not settle after ${o}ms. ${v.inflight.length} resolvers still inflight: ${f}`)}}function C(){let e=0,s=[];return {async advance(r){let o=e+r;for(;s.length>0&&s[0].time<=o;){let c=s.shift();e=c.time,c.callback(),await Promise.resolve();}e=o;},async next(){if(s.length===0)return;let r=s.shift();e=r.time,r.callback(),await Promise.resolve();},async runAll(){for(;s.length>0;)await this.next();},now(){return e},reset(){e=0,s.length=0;}}}function b(e){let s=typeof e=="string"?{requirement:(o=>o.type===e)}:e,r=s.calls??[];return {requirement:s.requirement??(o=>true),async resolve(o,c){if(r.push(o),s.delay&&await new Promise(l=>setTimeout(l,s.delay)),s.error)throw typeof s.error=="string"?new Error(s.error):s.error;s.resolve&&await s.resolve(o,c);}}}function E(e){let s=[],r=[];return {...{get calls(){return s},get pending(){return r},resolve(l){let m=r.shift();m&&m.resolve(l);},reject(l){let m=r.shift();m&&m.reject(l);},resolveAll(l){for(;r.length>0;)this.resolve(l);},rejectAll(l){for(;r.length>0;)this.reject(l);},reset(){s.length=0,r.length=0;}},handler:(l,m)=>(s.push(l),new Promise((d,v)=>{r.push({requirement:l,resolve:f=>d(f),reject:v});}))}}function P(e){return "module"in e?x(e):M(e)}function x(e){let s=[],r=new Map,o=[],c=[],l={};if(e.mocks?.resolvers)for(let[i,t]of Object.entries(e.mocks.resolvers)){let n=[];r.set(i,n),l[i]=b({...t,calls:n});}let m={...e.module,resolvers:{...e.module.resolvers,...l}},v=chunkMF33A4BC_cjs.a({...e,module:m,plugins:[{name:"__test-tracking__",onFactSet:(i,t,n)=>{c.push({key:i,fullKey:i,namespace:void 0,previousValue:n,newValue:t,timestamp:Date.now()});},onRequirementCreated:i=>{o.push(i);}},...e.plugins??[]]}),f=v.dispatch.bind(v);return v.dispatch=i=>{s.push(i),f(i);},{...v,eventHistory:s,resolverCalls:r,get allRequirements(){return o},getFactsHistory(){return [...c]},resetFactsHistory(){c.length=0;},async waitForIdle(i=5e3){let t=Date.now(),n=async()=>{await new Promise(u=>setTimeout(u,0));let a=v.inspect();if(a.inflight.length>0){if(Date.now()-t>i){let u=a.inflight.map(g=>g.id).join(", ");throw new Error(`[Directive] waitForIdle timed out after ${i}ms. ${a.inflight.length} resolvers still inflight: ${u}`)}return await new Promise(u=>setTimeout(u,10)),n()}};return n()},assertRequirement(i){if(!o.some(n=>n.requirement.type===i))throw new Error(`[Directive] Expected requirement of type "${i}" but none found`)},assertResolverCalled(i,t){let n=r.get(i)??[];if(t!==void 0){if(n.length!==t)throw new Error(`[Directive] Expected resolver "${i}" to be called ${t} times but was called ${n.length} times`)}else if(n.length===0)throw new Error(`[Directive] Expected resolver "${i}" to be called but it was not`)},assertFactSet(i,t){let n=c.filter(a=>a.key===i);if(n.length===0)throw new Error(`[Directive] Expected fact "${i}" to be set but it was not`);if(t!==void 0&&!n.some(u=>u.newValue===t)){let u=n.map(g=>JSON.stringify(g.newValue)).join(", ");throw new Error(`[Directive] Expected fact "${i}" to be set to ${JSON.stringify(t)} but got: ${u}`)}},assertFactChanges(i,t){let n=c.filter(a=>a.key===i);if(n.length!==t)throw new Error(`[Directive] Expected fact "${i}" to change ${t} times but it changed ${n.length} times`)}}}function M(e){let s=[],r=new Map,o=[],c=[],l={};if(e.mocks?.resolvers)for(let[t,n]of Object.entries(e.mocks.resolvers)){let a=[];r.set(t,a),l[t]=b({...n,calls:a});}let m={};for(let[t,n]of Object.entries(e.modules))m[t]={...n,resolvers:{...n.resolvers,...l}};let d=new Set(Object.keys(e.modules)),f=chunkMF33A4BC_cjs.a({...e,modules:m,plugins:[{name:"__test-tracking__",onFactSet:(t,n,a)=>{let g=t.indexOf("::"),y,h;if(g>0){let S=t.substring(0,g);d.has(S)?(y=S,h=t.substring(g+2)):h=t;}else h=t;c.push({key:h,fullKey:t,namespace:y,previousValue:a,newValue:n,timestamp:Date.now()});},onRequirementCreated:t=>{o.push(t);}},...e.plugins??[]]}),p=f.dispatch.bind(f);return f.dispatch=t=>{s.push(t),p(t);},{...f,eventHistory:s,resolverCalls:r,get allRequirements(){return o},getFactsHistory(){return [...c]},resetFactsHistory(){c.length=0;},async waitForIdle(t=5e3){let n=Date.now(),a=async()=>{await new Promise(g=>setTimeout(g,0));let u=f.inspect();if(u.inflight.length>0){if(Date.now()-n>t){let g=u.inflight.map(y=>y.id).join(", ");throw new Error(`[Directive] waitForIdle timed out after ${t}ms. ${u.inflight.length} resolvers still inflight: ${g}`)}return await new Promise(g=>setTimeout(g,10)),a()}};return a()},assertRequirement(t){if(!o.some(a=>a.requirement.type===t))throw new Error(`[Directive] Expected requirement of type "${t}" but none found`)},assertResolverCalled(t,n){let a=r.get(t)??[];if(n!==void 0){if(a.length!==n)throw new Error(`[Directive] Expected resolver "${t}" to be called ${n} times but was called ${a.length} times`)}else if(a.length===0)throw new Error(`[Directive] Expected resolver "${t}" to be called but it was not`)},assertFactSet(t,n){let a=c.filter(u=>u.key===t);if(a.length===0)throw new Error(`[Directive] Expected fact "${t}" to be set but it was not`);if(n!==void 0&&!a.some(g=>g.newValue===n)){let g=a.map(y=>JSON.stringify(y.newValue)).join(", ");throw new Error(`[Directive] Expected fact "${t}" to be set to ${JSON.stringify(n)} but got: ${g}`)}},assertFactChanges(t,n){let a=c.filter(u=>u.key===t);if(a.length!==n)throw new Error(`[Directive] Expected fact "${t}" to change ${n} times but it changed ${a.length} times`)}}}function O(e,s,r){if(!k(e,s,r))throw new Error(`[Directive] Expected ${s} "${r}" to be dynamic, but it is not.`)}function $(e,s,r){if(k(e,s,r))throw new Error(`[Directive] Expected ${s} "${r}" to NOT be dynamic, but it is.`)}function k(e,s,r){switch(s){case "constraint":return e.constraints.isDynamic(r);case "resolver":return e.resolvers.isDynamic(r);case "derivation":return e.derive.isDynamic(r);case "effect":return e.effects.isDynamic(r)}}function F(e){let s=new Set,r=new Set,o=new Set,c=new Set,l=null;return {async run(m){l=e.observe(d=>{switch(d.type){case "constraint.evaluate":d.active&&s.add(d.id);break;case "resolver.start":r.add(d.resolver);break;case "effect.run":o.add(d.id);break;case "derivation.compute":c.add(d.id);break}});try{await m();}finally{l?.(),l=null;}},report(){let m=e.inspect(),d=new Set(m.constraints.map(i=>i.id)),v=new Set(m.resolverDefs.map(i=>i.id)),f=new Set;for(let i of d)s.has(i)||f.add(i);let p=new Set;for(let i of v)r.has(i)||p.add(i);return {constraintsHit:s,constraintsMissed:f,resolversRun:r,resolversMissed:p,effectsRun:o,derivationsComputed:c,constraintCoverage:d.size===0?1:s.size/d.size,resolverCoverage:v.size===0?1:r.size/v.size,effectCoverage:m.effects.length===0?1:o.size/m.effects.length,derivationCoverage:m.derivations.length===0?1:c.size/m.derivations.length}}}}function I(e){let s=[],r=e.observe(o=>s.push(o));return {events:s,ofType(o){return s.filter(c=>c.type===o)},clear(){s.length=0;},dispose(){r();}}}exports.assertDynamic=O;exports.assertNotDynamic=$;exports.createCoverageTracker=F;exports.createFakeTimers=C;exports.createMockResolver=b;exports.createTestObserver=I;exports.createTestSystem=P;exports.flushAsync=T;exports.flushMicrotasks=R;exports.mockResolver=E;exports.settleWithFakeTimers=D;//# sourceMappingURL=testing.cjs.map
1
+ 'use strict';var chunk4OXCKDKS_cjs=require('./chunk-4OXCKDKS.cjs');require('./chunk-M5PEB553.cjs'),require('./chunk-GACC2DMS.cjs'),require('./chunk-GKMJ7NMP.cjs'),require('./chunk-GBCWXTXW.cjs');async function R(){for(let e=0;e<10;e++)await Promise.resolve();}async function T(){for(let e=0;e<10;e++)await Promise.resolve();await new Promise(e=>setTimeout(e,0));for(let e=0;e<10;e++)await Promise.resolve();await new Promise(e=>setTimeout(e,0));for(let e=0;e<10;e++)await Promise.resolve();}async function D(e,s,r={}){let{totalTime:o=5e3,stepSize:c=10,maxIterations:l=1e3}=r,m=0,d=0;for(;m<o&&d<l;){if(await R(),e.inspect().inflight.length===0){await R();return}s(c),m+=c,d++;}let v=e.inspect();if(v.inflight.length>0){let f=v.inflight.map(p=>p.resolverId).join(", ");throw new Error(`[Directive] settleWithFakeTimers did not settle after ${o}ms. ${v.inflight.length} resolvers still inflight: ${f}`)}}function C(){let e=0,s=[];return {async advance(r){let o=e+r;for(;s.length>0&&s[0].time<=o;){let c=s.shift();e=c.time,c.callback(),await Promise.resolve();}e=o;},async next(){if(s.length===0)return;let r=s.shift();e=r.time,r.callback(),await Promise.resolve();},async runAll(){for(;s.length>0;)await this.next();},now(){return e},reset(){e=0,s.length=0;}}}function b(e){let s=typeof e=="string"?{requirement:(o=>o.type===e)}:e,r=s.calls??[];return {requirement:s.requirement??(o=>true),async resolve(o,c){if(r.push(o),s.delay&&await new Promise(l=>setTimeout(l,s.delay)),s.error)throw typeof s.error=="string"?new Error(s.error):s.error;s.resolve&&await s.resolve(o,c);}}}function E(e){let s=[],r=[];return {...{get calls(){return s},get pending(){return r},resolve(l){let m=r.shift();m&&m.resolve(l);},reject(l){let m=r.shift();m&&m.reject(l);},resolveAll(l){for(;r.length>0;)this.resolve(l);},rejectAll(l){for(;r.length>0;)this.reject(l);},reset(){s.length=0,r.length=0;}},handler:(l,m)=>(s.push(l),new Promise((d,v)=>{r.push({requirement:l,resolve:f=>d(f),reject:v});}))}}function P(e){return "module"in e?x(e):M(e)}function x(e){let s=[],r=new Map,o=[],c=[],l={};if(e.mocks?.resolvers)for(let[i,t]of Object.entries(e.mocks.resolvers)){let n=[];r.set(i,n),l[i]=b({...t,calls:n});}let m={...e.module,resolvers:{...e.module.resolvers,...l}},v=chunk4OXCKDKS_cjs.a({...e,module:m,plugins:[{name:"__test-tracking__",onFactSet:(i,t,n)=>{c.push({key:i,fullKey:i,namespace:void 0,previousValue:n,newValue:t,timestamp:Date.now()});},onRequirementCreated:i=>{o.push(i);}},...e.plugins??[]]}),f=v.dispatch.bind(v);return v.dispatch=i=>{s.push(i),f(i);},{...v,eventHistory:s,resolverCalls:r,get allRequirements(){return o},getFactsHistory(){return [...c]},resetFactsHistory(){c.length=0;},async waitForIdle(i=5e3){let t=Date.now(),n=async()=>{await new Promise(u=>setTimeout(u,0));let a=v.inspect();if(a.inflight.length>0){if(Date.now()-t>i){let u=a.inflight.map(g=>g.id).join(", ");throw new Error(`[Directive] waitForIdle timed out after ${i}ms. ${a.inflight.length} resolvers still inflight: ${u}`)}return await new Promise(u=>setTimeout(u,10)),n()}};return n()},assertRequirement(i){if(!o.some(n=>n.requirement.type===i))throw new Error(`[Directive] Expected requirement of type "${i}" but none found`)},assertResolverCalled(i,t){let n=r.get(i)??[];if(t!==void 0){if(n.length!==t)throw new Error(`[Directive] Expected resolver "${i}" to be called ${t} times but was called ${n.length} times`)}else if(n.length===0)throw new Error(`[Directive] Expected resolver "${i}" to be called but it was not`)},assertFactSet(i,t){let n=c.filter(a=>a.key===i);if(n.length===0)throw new Error(`[Directive] Expected fact "${i}" to be set but it was not`);if(t!==void 0&&!n.some(u=>u.newValue===t)){let u=n.map(g=>JSON.stringify(g.newValue)).join(", ");throw new Error(`[Directive] Expected fact "${i}" to be set to ${JSON.stringify(t)} but got: ${u}`)}},assertFactChanges(i,t){let n=c.filter(a=>a.key===i);if(n.length!==t)throw new Error(`[Directive] Expected fact "${i}" to change ${t} times but it changed ${n.length} times`)}}}function M(e){let s=[],r=new Map,o=[],c=[],l={};if(e.mocks?.resolvers)for(let[t,n]of Object.entries(e.mocks.resolvers)){let a=[];r.set(t,a),l[t]=b({...n,calls:a});}let m={};for(let[t,n]of Object.entries(e.modules))m[t]={...n,resolvers:{...n.resolvers,...l}};let d=new Set(Object.keys(e.modules)),f=chunk4OXCKDKS_cjs.a({...e,modules:m,plugins:[{name:"__test-tracking__",onFactSet:(t,n,a)=>{let g=t.indexOf("::"),y,h;if(g>0){let S=t.substring(0,g);d.has(S)?(y=S,h=t.substring(g+2)):h=t;}else h=t;c.push({key:h,fullKey:t,namespace:y,previousValue:a,newValue:n,timestamp:Date.now()});},onRequirementCreated:t=>{o.push(t);}},...e.plugins??[]]}),p=f.dispatch.bind(f);return f.dispatch=t=>{s.push(t),p(t);},{...f,eventHistory:s,resolverCalls:r,get allRequirements(){return o},getFactsHistory(){return [...c]},resetFactsHistory(){c.length=0;},async waitForIdle(t=5e3){let n=Date.now(),a=async()=>{await new Promise(g=>setTimeout(g,0));let u=f.inspect();if(u.inflight.length>0){if(Date.now()-n>t){let g=u.inflight.map(y=>y.id).join(", ");throw new Error(`[Directive] waitForIdle timed out after ${t}ms. ${u.inflight.length} resolvers still inflight: ${g}`)}return await new Promise(g=>setTimeout(g,10)),a()}};return a()},assertRequirement(t){if(!o.some(a=>a.requirement.type===t))throw new Error(`[Directive] Expected requirement of type "${t}" but none found`)},assertResolverCalled(t,n){let a=r.get(t)??[];if(n!==void 0){if(a.length!==n)throw new Error(`[Directive] Expected resolver "${t}" to be called ${n} times but was called ${a.length} times`)}else if(a.length===0)throw new Error(`[Directive] Expected resolver "${t}" to be called but it was not`)},assertFactSet(t,n){let a=c.filter(u=>u.key===t);if(a.length===0)throw new Error(`[Directive] Expected fact "${t}" to be set but it was not`);if(n!==void 0&&!a.some(g=>g.newValue===n)){let g=a.map(y=>JSON.stringify(y.newValue)).join(", ");throw new Error(`[Directive] Expected fact "${t}" to be set to ${JSON.stringify(n)} but got: ${g}`)}},assertFactChanges(t,n){let a=c.filter(u=>u.key===t);if(a.length!==n)throw new Error(`[Directive] Expected fact "${t}" to change ${n} times but it changed ${a.length} times`)}}}function O(e,s,r){if(!k(e,s,r))throw new Error(`[Directive] Expected ${s} "${r}" to be dynamic, but it is not.`)}function $(e,s,r){if(k(e,s,r))throw new Error(`[Directive] Expected ${s} "${r}" to NOT be dynamic, but it is.`)}function k(e,s,r){switch(s){case "constraint":return e.constraints.isDynamic(r);case "resolver":return e.resolvers.isDynamic(r);case "derivation":return e.derive.isDynamic(r);case "effect":return e.effects.isDynamic(r)}}function F(e){let s=new Set,r=new Set,o=new Set,c=new Set,l=null;return {async run(m){l=e.observe(d=>{switch(d.type){case "constraint.evaluate":d.active&&s.add(d.id);break;case "resolver.start":r.add(d.resolver);break;case "effect.run":o.add(d.id);break;case "derivation.compute":c.add(d.id);break}});try{await m();}finally{l?.(),l=null;}},report(){let m=e.inspect(),d=new Set(m.constraints.map(i=>i.id)),v=new Set(m.resolverDefs.map(i=>i.id)),f=new Set;for(let i of d)s.has(i)||f.add(i);let p=new Set;for(let i of v)r.has(i)||p.add(i);return {constraintsHit:s,constraintsMissed:f,resolversRun:r,resolversMissed:p,effectsRun:o,derivationsComputed:c,constraintCoverage:d.size===0?1:s.size/d.size,resolverCoverage:v.size===0?1:r.size/v.size,effectCoverage:m.effects.length===0?1:o.size/m.effects.length,derivationCoverage:m.derivations.length===0?1:c.size/m.derivations.length}}}}function I(e){let s=[],r=e.observe(o=>s.push(o));return {events:s,ofType(o){return s.filter(c=>c.type===o)},clear(){s.length=0;},dispose(){r();}}}exports.assertDynamic=O;exports.assertNotDynamic=$;exports.createCoverageTracker=F;exports.createFakeTimers=C;exports.createMockResolver=b;exports.createTestObserver=I;exports.createTestSystem=P;exports.flushAsync=T;exports.flushMicrotasks=R;exports.mockResolver=E;exports.settleWithFakeTimers=D;//# sourceMappingURL=testing.cjs.map
2
2
  //# sourceMappingURL=testing.cjs.map
@@ -1,4 +1,4 @@
1
- import { n as ModulesMap, o as CreateSystemOptionsNamed, r as Requirement, M as ModuleSchema, l as CreateSystemOptionsSingle, N as NamespacedSystem, R as RequirementWithId, m as SingleModuleSystem, a4 as ObservationEvent, as as SystemInspection } from './plugins-Bs7Aidtt.cjs';
1
+ import { n as ModulesMap, o as CreateSystemOptionsNamed, r as Requirement, M as ModuleSchema, l as CreateSystemOptionsSingle, N as NamespacedSystem, R as RequirementWithId, m as SingleModuleSystem, a4 as ObservationEvent, at as SystemInspection } from './plugins-4IfhJV32.cjs';
2
2
 
3
3
  /**
4
4
  * Flush all pending microtasks by awaiting multiple rounds of `Promise.resolve()`.
package/dist/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as ModulesMap, o as CreateSystemOptionsNamed, r as Requirement, M as ModuleSchema, l as CreateSystemOptionsSingle, N as NamespacedSystem, R as RequirementWithId, m as SingleModuleSystem, a4 as ObservationEvent, as as SystemInspection } from './plugins-Bs7Aidtt.js';
1
+ import { n as ModulesMap, o as CreateSystemOptionsNamed, r as Requirement, M as ModuleSchema, l as CreateSystemOptionsSingle, N as NamespacedSystem, R as RequirementWithId, m as SingleModuleSystem, a4 as ObservationEvent, at as SystemInspection } from './plugins-4IfhJV32.js';
2
2
 
3
3
  /**
4
4
  * Flush all pending microtasks by awaiting multiple rounds of `Promise.resolve()`.
package/dist/testing.js CHANGED
@@ -1,2 +1,2 @@
1
- import {a}from'./chunk-IMMKDLTV.js';import'./chunk-KSKFDTDA.js';import'./chunk-O4GQEV4G.js';import'./chunk-3ETCZLAY.js';import'./chunk-PXRV64PA.js';async function R(){for(let e=0;e<10;e++)await Promise.resolve();}async function T(){for(let e=0;e<10;e++)await Promise.resolve();await new Promise(e=>setTimeout(e,0));for(let e=0;e<10;e++)await Promise.resolve();await new Promise(e=>setTimeout(e,0));for(let e=0;e<10;e++)await Promise.resolve();}async function D(e,s,r={}){let{totalTime:o=5e3,stepSize:c=10,maxIterations:l=1e3}=r,m=0,d=0;for(;m<o&&d<l;){if(await R(),e.inspect().inflight.length===0){await R();return}s(c),m+=c,d++;}let v=e.inspect();if(v.inflight.length>0){let f=v.inflight.map(p=>p.resolverId).join(", ");throw new Error(`[Directive] settleWithFakeTimers did not settle after ${o}ms. ${v.inflight.length} resolvers still inflight: ${f}`)}}function C(){let e=0,s=[];return {async advance(r){let o=e+r;for(;s.length>0&&s[0].time<=o;){let c=s.shift();e=c.time,c.callback(),await Promise.resolve();}e=o;},async next(){if(s.length===0)return;let r=s.shift();e=r.time,r.callback(),await Promise.resolve();},async runAll(){for(;s.length>0;)await this.next();},now(){return e},reset(){e=0,s.length=0;}}}function b(e){let s=typeof e=="string"?{requirement:(o=>o.type===e)}:e,r=s.calls??[];return {requirement:s.requirement??(o=>true),async resolve(o,c){if(r.push(o),s.delay&&await new Promise(l=>setTimeout(l,s.delay)),s.error)throw typeof s.error=="string"?new Error(s.error):s.error;s.resolve&&await s.resolve(o,c);}}}function E(e){let s=[],r=[];return {...{get calls(){return s},get pending(){return r},resolve(l){let m=r.shift();m&&m.resolve(l);},reject(l){let m=r.shift();m&&m.reject(l);},resolveAll(l){for(;r.length>0;)this.resolve(l);},rejectAll(l){for(;r.length>0;)this.reject(l);},reset(){s.length=0,r.length=0;}},handler:(l,m)=>(s.push(l),new Promise((d,v)=>{r.push({requirement:l,resolve:f=>d(f),reject:v});}))}}function P(e){return "module"in e?x(e):M(e)}function x(e){let s=[],r=new Map,o=[],c=[],l={};if(e.mocks?.resolvers)for(let[i,t]of Object.entries(e.mocks.resolvers)){let n=[];r.set(i,n),l[i]=b({...t,calls:n});}let m={...e.module,resolvers:{...e.module.resolvers,...l}},v=a({...e,module:m,plugins:[{name:"__test-tracking__",onFactSet:(i,t,n)=>{c.push({key:i,fullKey:i,namespace:void 0,previousValue:n,newValue:t,timestamp:Date.now()});},onRequirementCreated:i=>{o.push(i);}},...e.plugins??[]]}),f=v.dispatch.bind(v);return v.dispatch=i=>{s.push(i),f(i);},{...v,eventHistory:s,resolverCalls:r,get allRequirements(){return o},getFactsHistory(){return [...c]},resetFactsHistory(){c.length=0;},async waitForIdle(i=5e3){let t=Date.now(),n=async()=>{await new Promise(u=>setTimeout(u,0));let a=v.inspect();if(a.inflight.length>0){if(Date.now()-t>i){let u=a.inflight.map(g=>g.id).join(", ");throw new Error(`[Directive] waitForIdle timed out after ${i}ms. ${a.inflight.length} resolvers still inflight: ${u}`)}return await new Promise(u=>setTimeout(u,10)),n()}};return n()},assertRequirement(i){if(!o.some(n=>n.requirement.type===i))throw new Error(`[Directive] Expected requirement of type "${i}" but none found`)},assertResolverCalled(i,t){let n=r.get(i)??[];if(t!==void 0){if(n.length!==t)throw new Error(`[Directive] Expected resolver "${i}" to be called ${t} times but was called ${n.length} times`)}else if(n.length===0)throw new Error(`[Directive] Expected resolver "${i}" to be called but it was not`)},assertFactSet(i,t){let n=c.filter(a=>a.key===i);if(n.length===0)throw new Error(`[Directive] Expected fact "${i}" to be set but it was not`);if(t!==void 0&&!n.some(u=>u.newValue===t)){let u=n.map(g=>JSON.stringify(g.newValue)).join(", ");throw new Error(`[Directive] Expected fact "${i}" to be set to ${JSON.stringify(t)} but got: ${u}`)}},assertFactChanges(i,t){let n=c.filter(a=>a.key===i);if(n.length!==t)throw new Error(`[Directive] Expected fact "${i}" to change ${t} times but it changed ${n.length} times`)}}}function M(e){let s=[],r=new Map,o=[],c=[],l={};if(e.mocks?.resolvers)for(let[t,n]of Object.entries(e.mocks.resolvers)){let a=[];r.set(t,a),l[t]=b({...n,calls:a});}let m={};for(let[t,n]of Object.entries(e.modules))m[t]={...n,resolvers:{...n.resolvers,...l}};let d=new Set(Object.keys(e.modules)),f=a({...e,modules:m,plugins:[{name:"__test-tracking__",onFactSet:(t,n,a)=>{let g=t.indexOf("::"),y,h;if(g>0){let S=t.substring(0,g);d.has(S)?(y=S,h=t.substring(g+2)):h=t;}else h=t;c.push({key:h,fullKey:t,namespace:y,previousValue:a,newValue:n,timestamp:Date.now()});},onRequirementCreated:t=>{o.push(t);}},...e.plugins??[]]}),p=f.dispatch.bind(f);return f.dispatch=t=>{s.push(t),p(t);},{...f,eventHistory:s,resolverCalls:r,get allRequirements(){return o},getFactsHistory(){return [...c]},resetFactsHistory(){c.length=0;},async waitForIdle(t=5e3){let n=Date.now(),a=async()=>{await new Promise(g=>setTimeout(g,0));let u=f.inspect();if(u.inflight.length>0){if(Date.now()-n>t){let g=u.inflight.map(y=>y.id).join(", ");throw new Error(`[Directive] waitForIdle timed out after ${t}ms. ${u.inflight.length} resolvers still inflight: ${g}`)}return await new Promise(g=>setTimeout(g,10)),a()}};return a()},assertRequirement(t){if(!o.some(a=>a.requirement.type===t))throw new Error(`[Directive] Expected requirement of type "${t}" but none found`)},assertResolverCalled(t,n){let a=r.get(t)??[];if(n!==void 0){if(a.length!==n)throw new Error(`[Directive] Expected resolver "${t}" to be called ${n} times but was called ${a.length} times`)}else if(a.length===0)throw new Error(`[Directive] Expected resolver "${t}" to be called but it was not`)},assertFactSet(t,n){let a=c.filter(u=>u.key===t);if(a.length===0)throw new Error(`[Directive] Expected fact "${t}" to be set but it was not`);if(n!==void 0&&!a.some(g=>g.newValue===n)){let g=a.map(y=>JSON.stringify(y.newValue)).join(", ");throw new Error(`[Directive] Expected fact "${t}" to be set to ${JSON.stringify(n)} but got: ${g}`)}},assertFactChanges(t,n){let a=c.filter(u=>u.key===t);if(a.length!==n)throw new Error(`[Directive] Expected fact "${t}" to change ${n} times but it changed ${a.length} times`)}}}function O(e,s,r){if(!k(e,s,r))throw new Error(`[Directive] Expected ${s} "${r}" to be dynamic, but it is not.`)}function $(e,s,r){if(k(e,s,r))throw new Error(`[Directive] Expected ${s} "${r}" to NOT be dynamic, but it is.`)}function k(e,s,r){switch(s){case "constraint":return e.constraints.isDynamic(r);case "resolver":return e.resolvers.isDynamic(r);case "derivation":return e.derive.isDynamic(r);case "effect":return e.effects.isDynamic(r)}}function F(e){let s=new Set,r=new Set,o=new Set,c=new Set,l=null;return {async run(m){l=e.observe(d=>{switch(d.type){case "constraint.evaluate":d.active&&s.add(d.id);break;case "resolver.start":r.add(d.resolver);break;case "effect.run":o.add(d.id);break;case "derivation.compute":c.add(d.id);break}});try{await m();}finally{l?.(),l=null;}},report(){let m=e.inspect(),d=new Set(m.constraints.map(i=>i.id)),v=new Set(m.resolverDefs.map(i=>i.id)),f=new Set;for(let i of d)s.has(i)||f.add(i);let p=new Set;for(let i of v)r.has(i)||p.add(i);return {constraintsHit:s,constraintsMissed:f,resolversRun:r,resolversMissed:p,effectsRun:o,derivationsComputed:c,constraintCoverage:d.size===0?1:s.size/d.size,resolverCoverage:v.size===0?1:r.size/v.size,effectCoverage:m.effects.length===0?1:o.size/m.effects.length,derivationCoverage:m.derivations.length===0?1:c.size/m.derivations.length}}}}function I(e){let s=[],r=e.observe(o=>s.push(o));return {events:s,ofType(o){return s.filter(c=>c.type===o)},clear(){s.length=0;},dispose(){r();}}}export{O as assertDynamic,$ as assertNotDynamic,F as createCoverageTracker,C as createFakeTimers,b as createMockResolver,I as createTestObserver,P as createTestSystem,T as flushAsync,R as flushMicrotasks,E as mockResolver,D as settleWithFakeTimers};//# sourceMappingURL=testing.js.map
1
+ import {a}from'./chunk-E53A4NHM.js';import'./chunk-6QAUJFQH.js';import'./chunk-RBF653NR.js';import'./chunk-6PF2FRBG.js';import'./chunk-SFUVPP4L.js';async function R(){for(let e=0;e<10;e++)await Promise.resolve();}async function T(){for(let e=0;e<10;e++)await Promise.resolve();await new Promise(e=>setTimeout(e,0));for(let e=0;e<10;e++)await Promise.resolve();await new Promise(e=>setTimeout(e,0));for(let e=0;e<10;e++)await Promise.resolve();}async function D(e,s,r={}){let{totalTime:o=5e3,stepSize:c=10,maxIterations:l=1e3}=r,m=0,d=0;for(;m<o&&d<l;){if(await R(),e.inspect().inflight.length===0){await R();return}s(c),m+=c,d++;}let v=e.inspect();if(v.inflight.length>0){let f=v.inflight.map(p=>p.resolverId).join(", ");throw new Error(`[Directive] settleWithFakeTimers did not settle after ${o}ms. ${v.inflight.length} resolvers still inflight: ${f}`)}}function C(){let e=0,s=[];return {async advance(r){let o=e+r;for(;s.length>0&&s[0].time<=o;){let c=s.shift();e=c.time,c.callback(),await Promise.resolve();}e=o;},async next(){if(s.length===0)return;let r=s.shift();e=r.time,r.callback(),await Promise.resolve();},async runAll(){for(;s.length>0;)await this.next();},now(){return e},reset(){e=0,s.length=0;}}}function b(e){let s=typeof e=="string"?{requirement:(o=>o.type===e)}:e,r=s.calls??[];return {requirement:s.requirement??(o=>true),async resolve(o,c){if(r.push(o),s.delay&&await new Promise(l=>setTimeout(l,s.delay)),s.error)throw typeof s.error=="string"?new Error(s.error):s.error;s.resolve&&await s.resolve(o,c);}}}function E(e){let s=[],r=[];return {...{get calls(){return s},get pending(){return r},resolve(l){let m=r.shift();m&&m.resolve(l);},reject(l){let m=r.shift();m&&m.reject(l);},resolveAll(l){for(;r.length>0;)this.resolve(l);},rejectAll(l){for(;r.length>0;)this.reject(l);},reset(){s.length=0,r.length=0;}},handler:(l,m)=>(s.push(l),new Promise((d,v)=>{r.push({requirement:l,resolve:f=>d(f),reject:v});}))}}function P(e){return "module"in e?x(e):M(e)}function x(e){let s=[],r=new Map,o=[],c=[],l={};if(e.mocks?.resolvers)for(let[i,t]of Object.entries(e.mocks.resolvers)){let n=[];r.set(i,n),l[i]=b({...t,calls:n});}let m={...e.module,resolvers:{...e.module.resolvers,...l}},v=a({...e,module:m,plugins:[{name:"__test-tracking__",onFactSet:(i,t,n)=>{c.push({key:i,fullKey:i,namespace:void 0,previousValue:n,newValue:t,timestamp:Date.now()});},onRequirementCreated:i=>{o.push(i);}},...e.plugins??[]]}),f=v.dispatch.bind(v);return v.dispatch=i=>{s.push(i),f(i);},{...v,eventHistory:s,resolverCalls:r,get allRequirements(){return o},getFactsHistory(){return [...c]},resetFactsHistory(){c.length=0;},async waitForIdle(i=5e3){let t=Date.now(),n=async()=>{await new Promise(u=>setTimeout(u,0));let a=v.inspect();if(a.inflight.length>0){if(Date.now()-t>i){let u=a.inflight.map(g=>g.id).join(", ");throw new Error(`[Directive] waitForIdle timed out after ${i}ms. ${a.inflight.length} resolvers still inflight: ${u}`)}return await new Promise(u=>setTimeout(u,10)),n()}};return n()},assertRequirement(i){if(!o.some(n=>n.requirement.type===i))throw new Error(`[Directive] Expected requirement of type "${i}" but none found`)},assertResolverCalled(i,t){let n=r.get(i)??[];if(t!==void 0){if(n.length!==t)throw new Error(`[Directive] Expected resolver "${i}" to be called ${t} times but was called ${n.length} times`)}else if(n.length===0)throw new Error(`[Directive] Expected resolver "${i}" to be called but it was not`)},assertFactSet(i,t){let n=c.filter(a=>a.key===i);if(n.length===0)throw new Error(`[Directive] Expected fact "${i}" to be set but it was not`);if(t!==void 0&&!n.some(u=>u.newValue===t)){let u=n.map(g=>JSON.stringify(g.newValue)).join(", ");throw new Error(`[Directive] Expected fact "${i}" to be set to ${JSON.stringify(t)} but got: ${u}`)}},assertFactChanges(i,t){let n=c.filter(a=>a.key===i);if(n.length!==t)throw new Error(`[Directive] Expected fact "${i}" to change ${t} times but it changed ${n.length} times`)}}}function M(e){let s=[],r=new Map,o=[],c=[],l={};if(e.mocks?.resolvers)for(let[t,n]of Object.entries(e.mocks.resolvers)){let a=[];r.set(t,a),l[t]=b({...n,calls:a});}let m={};for(let[t,n]of Object.entries(e.modules))m[t]={...n,resolvers:{...n.resolvers,...l}};let d=new Set(Object.keys(e.modules)),f=a({...e,modules:m,plugins:[{name:"__test-tracking__",onFactSet:(t,n,a)=>{let g=t.indexOf("::"),y,h;if(g>0){let S=t.substring(0,g);d.has(S)?(y=S,h=t.substring(g+2)):h=t;}else h=t;c.push({key:h,fullKey:t,namespace:y,previousValue:a,newValue:n,timestamp:Date.now()});},onRequirementCreated:t=>{o.push(t);}},...e.plugins??[]]}),p=f.dispatch.bind(f);return f.dispatch=t=>{s.push(t),p(t);},{...f,eventHistory:s,resolverCalls:r,get allRequirements(){return o},getFactsHistory(){return [...c]},resetFactsHistory(){c.length=0;},async waitForIdle(t=5e3){let n=Date.now(),a=async()=>{await new Promise(g=>setTimeout(g,0));let u=f.inspect();if(u.inflight.length>0){if(Date.now()-n>t){let g=u.inflight.map(y=>y.id).join(", ");throw new Error(`[Directive] waitForIdle timed out after ${t}ms. ${u.inflight.length} resolvers still inflight: ${g}`)}return await new Promise(g=>setTimeout(g,10)),a()}};return a()},assertRequirement(t){if(!o.some(a=>a.requirement.type===t))throw new Error(`[Directive] Expected requirement of type "${t}" but none found`)},assertResolverCalled(t,n){let a=r.get(t)??[];if(n!==void 0){if(a.length!==n)throw new Error(`[Directive] Expected resolver "${t}" to be called ${n} times but was called ${a.length} times`)}else if(a.length===0)throw new Error(`[Directive] Expected resolver "${t}" to be called but it was not`)},assertFactSet(t,n){let a=c.filter(u=>u.key===t);if(a.length===0)throw new Error(`[Directive] Expected fact "${t}" to be set but it was not`);if(n!==void 0&&!a.some(g=>g.newValue===n)){let g=a.map(y=>JSON.stringify(y.newValue)).join(", ");throw new Error(`[Directive] Expected fact "${t}" to be set to ${JSON.stringify(n)} but got: ${g}`)}},assertFactChanges(t,n){let a=c.filter(u=>u.key===t);if(a.length!==n)throw new Error(`[Directive] Expected fact "${t}" to change ${n} times but it changed ${a.length} times`)}}}function O(e,s,r){if(!k(e,s,r))throw new Error(`[Directive] Expected ${s} "${r}" to be dynamic, but it is not.`)}function $(e,s,r){if(k(e,s,r))throw new Error(`[Directive] Expected ${s} "${r}" to NOT be dynamic, but it is.`)}function k(e,s,r){switch(s){case "constraint":return e.constraints.isDynamic(r);case "resolver":return e.resolvers.isDynamic(r);case "derivation":return e.derive.isDynamic(r);case "effect":return e.effects.isDynamic(r)}}function F(e){let s=new Set,r=new Set,o=new Set,c=new Set,l=null;return {async run(m){l=e.observe(d=>{switch(d.type){case "constraint.evaluate":d.active&&s.add(d.id);break;case "resolver.start":r.add(d.resolver);break;case "effect.run":o.add(d.id);break;case "derivation.compute":c.add(d.id);break}});try{await m();}finally{l?.(),l=null;}},report(){let m=e.inspect(),d=new Set(m.constraints.map(i=>i.id)),v=new Set(m.resolverDefs.map(i=>i.id)),f=new Set;for(let i of d)s.has(i)||f.add(i);let p=new Set;for(let i of v)r.has(i)||p.add(i);return {constraintsHit:s,constraintsMissed:f,resolversRun:r,resolversMissed:p,effectsRun:o,derivationsComputed:c,constraintCoverage:d.size===0?1:s.size/d.size,resolverCoverage:v.size===0?1:r.size/v.size,effectCoverage:m.effects.length===0?1:o.size/m.effects.length,derivationCoverage:m.derivations.length===0?1:c.size/m.derivations.length}}}}function I(e){let s=[],r=e.observe(o=>s.push(o));return {events:s,ofType(o){return s.filter(c=>c.type===o)},clear(){s.length=0;},dispose(){r();}}}export{O as assertDynamic,$ as assertNotDynamic,F as createCoverageTracker,C as createFakeTimers,b as createMockResolver,I as createTestObserver,P as createTestSystem,T as flushAsync,R as flushMicrotasks,E as mockResolver,D as settleWithFakeTimers};//# sourceMappingURL=testing.js.map
2
2
  //# sourceMappingURL=testing.js.map