@directive-run/core 1.20.2 → 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.
- package/README.md +33 -0
- package/dist/adapter-utils.cjs +1 -1
- package/dist/adapter-utils.d.cts +2 -2
- package/dist/adapter-utils.d.ts +2 -2
- package/dist/adapter-utils.js +1 -1
- package/dist/chunk-4OXCKDKS.cjs +16 -0
- package/dist/chunk-4OXCKDKS.cjs.map +1 -0
- package/dist/chunk-6PF2FRBG.js +7 -0
- package/dist/chunk-6PF2FRBG.js.map +1 -0
- package/dist/chunk-6QAUJFQH.js +3 -0
- package/dist/chunk-6QAUJFQH.js.map +1 -0
- package/dist/chunk-E53A4NHM.js +16 -0
- package/dist/chunk-E53A4NHM.js.map +1 -0
- package/dist/{chunk-RWFKUNF7.cjs → chunk-GACC2DMS.cjs} +2 -2
- package/dist/{chunk-RWFKUNF7.cjs.map → chunk-GACC2DMS.cjs.map} +1 -1
- package/dist/{chunk-4MNQDXH7.cjs → chunk-GBCWXTXW.cjs} +3 -3
- package/dist/chunk-GBCWXTXW.cjs.map +1 -0
- package/dist/chunk-GKMJ7NMP.cjs +7 -0
- package/dist/chunk-GKMJ7NMP.cjs.map +1 -0
- package/dist/{chunk-WKCMOU2F.js → chunk-KGTBTGOY.js} +2 -2
- package/dist/{chunk-WKCMOU2F.js.map → chunk-KGTBTGOY.js.map} +1 -1
- package/dist/chunk-M5PEB553.cjs +3 -0
- package/dist/chunk-M5PEB553.cjs.map +1 -0
- package/dist/{chunk-4QCKAJCX.cjs → chunk-MARZI3EY.cjs} +2 -2
- package/dist/{chunk-4QCKAJCX.cjs.map → chunk-MARZI3EY.cjs.map} +1 -1
- package/dist/{chunk-O4GQEV4G.js → chunk-RBF653NR.js} +2 -2
- package/dist/{chunk-O4GQEV4G.js.map → chunk-RBF653NR.js.map} +1 -1
- package/dist/{chunk-PXRV64PA.js → chunk-SFUVPP4L.js} +3 -3
- package/dist/chunk-SFUVPP4L.js.map +1 -0
- package/dist/{index-DApsqJ0h.d.cts → index-CvQuu0tu.d.cts} +1 -1
- package/dist/{index-D_K7eEOF.d.ts → index-DUbpbGw8.d.ts} +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +1 -1
- package/dist/internals.d.cts +25 -7
- package/dist/internals.d.ts +25 -7
- package/dist/internals.js +1 -1
- package/dist/plugins/index.cjs +2 -2
- package/dist/plugins/index.cjs.map +1 -1
- package/dist/plugins/index.d.cts +2 -2
- package/dist/plugins/index.d.ts +2 -2
- package/dist/plugins/index.js +2 -2
- package/dist/plugins/index.js.map +1 -1
- package/dist/{plugins-C6MxOvot.d.cts → plugins-4IfhJV32.d.cts} +96 -13
- package/dist/{plugins-C6MxOvot.d.ts → plugins-4IfhJV32.d.ts} +96 -13
- package/dist/{predicate-C92yT5IR.d.ts → predicate-BW05x5el.d.ts} +1 -1
- package/dist/{predicate-CV3YJDup.d.cts → predicate-DBTPnlg6.d.cts} +1 -1
- package/dist/system-SB7JYMRB.cjs +2 -0
- package/dist/{system-BXCEQBBS.cjs.map → system-SB7JYMRB.cjs.map} +1 -1
- package/dist/system-SJBP4TO5.js +2 -0
- package/dist/{system-AWEKWMNI.js.map → system-SJBP4TO5.js.map} +1 -1
- package/dist/testing.cjs +1 -1
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/dist/{utils-BZBBwS5A.d.cts → utils-DY8KTiD6.d.cts} +20 -7
- package/dist/{utils-BZBBwS5A.d.ts → utils-DY8KTiD6.d.ts} +20 -7
- package/dist/worker.cjs +1 -1
- package/dist/worker.d.cts +1 -1
- package/dist/worker.d.ts +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-3ETCZLAY.js +0 -7
- package/dist/chunk-3ETCZLAY.js.map +0 -1
- package/dist/chunk-4MNQDXH7.cjs.map +0 -1
- package/dist/chunk-CLJMEU2A.js +0 -3
- package/dist/chunk-CLJMEU2A.js.map +0 -1
- package/dist/chunk-JGPPJV5P.cjs +0 -7
- package/dist/chunk-JGPPJV5P.cjs.map +0 -1
- package/dist/chunk-MDMMMZUZ.cjs +0 -3
- package/dist/chunk-MDMMMZUZ.cjs.map +0 -1
- package/dist/chunk-PNB73G3E.cjs +0 -16
- package/dist/chunk-PNB73G3E.cjs.map +0 -1
- package/dist/chunk-PXRV64PA.js.map +0 -1
- package/dist/chunk-QQEXRNAI.js +0 -16
- package/dist/chunk-QQEXRNAI.js.map +0 -1
- package/dist/system-AWEKWMNI.js +0 -2
- package/dist/system-BXCEQBBS.cjs +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
|
|
728
|
-
*
|
|
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
|
|
@@ -2061,7 +2091,7 @@ interface ModuleHooks<M extends ModuleSchema> {
|
|
|
2061
2091
|
*
|
|
2062
2092
|
* @param error - The error the resolver threw (already normalized to `Error`).
|
|
2063
2093
|
* @param requirement - The requirement object that the failing resolver was handling.
|
|
2064
|
-
* @param
|
|
2094
|
+
* @param context - Hook context, including a typed snapshot of this module's facts.
|
|
2065
2095
|
*/
|
|
2066
2096
|
onResolverError?: (error: Error, requirement: {
|
|
2067
2097
|
type: string;
|
|
@@ -2386,10 +2416,6 @@ interface ModuleDef<M extends ModuleSchema = ModuleSchema> {
|
|
|
2386
2416
|
crossModuleDeps?: CrossModuleDeps;
|
|
2387
2417
|
}
|
|
2388
2418
|
|
|
2389
|
-
/**
|
|
2390
|
-
* System Types - Type definitions for the system
|
|
2391
|
-
*/
|
|
2392
|
-
|
|
2393
2419
|
/**
|
|
2394
2420
|
* Derive accessor from module schema.
|
|
2395
2421
|
*/
|
|
@@ -2424,6 +2450,35 @@ interface HistoryConfig {
|
|
|
2424
2450
|
maxSnapshots?: number;
|
|
2425
2451
|
/** Only snapshot events from these modules. Omit to snapshot all modules. Multi-module only. */
|
|
2426
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>;
|
|
2427
2482
|
}
|
|
2428
2483
|
/** History option: boolean shorthand or full config (presence implies enabled) */
|
|
2429
2484
|
type HistoryOption = boolean | HistoryConfig;
|
|
@@ -2664,7 +2719,7 @@ interface SystemInspection {
|
|
|
2664
2719
|
* - `"coalesced"` — manager debounced a same-event-name publish
|
|
2665
2720
|
* when `SourceDef.coalesce === "lastWriteWins"`
|
|
2666
2721
|
*/
|
|
2667
|
-
lastDropReason:
|
|
2722
|
+
lastDropReason: SourceDropReason | null;
|
|
2668
2723
|
/** Wall-clock ms of the most recent rejected publish, or `null`. */
|
|
2669
2724
|
lastDropAt: number | null;
|
|
2670
2725
|
/** Total attach + cleanup errors since the last attachAll. */
|
|
@@ -3136,6 +3191,22 @@ type ObservationEvent = {
|
|
|
3136
3191
|
moduleId: string;
|
|
3137
3192
|
eventName: string;
|
|
3138
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
|
+
}
|
|
3139
3210
|
/** Source detached at `system.stop()` (reverse-registration order). */
|
|
3140
3211
|
| {
|
|
3141
3212
|
type: "source.detach";
|
|
@@ -3452,10 +3523,6 @@ interface SystemConfig<M extends ModuleSchema = ModuleSchema> {
|
|
|
3452
3523
|
cloud?: boolean | string;
|
|
3453
3524
|
}
|
|
3454
3525
|
|
|
3455
|
-
/**
|
|
3456
|
-
* Plugin Types - Type definitions for plugins
|
|
3457
|
-
*/
|
|
3458
|
-
|
|
3459
3526
|
/** Reconcile result */
|
|
3460
3527
|
interface ReconcileResult {
|
|
3461
3528
|
unmet: RequirementWithId[];
|
|
@@ -3696,6 +3763,22 @@ interface Plugin<M extends ModuleSchema = ModuleSchema> {
|
|
|
3696
3763
|
* @param eventName - The dispatched event name (the first arg to `publish`).
|
|
3697
3764
|
*/
|
|
3698
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;
|
|
3699
3782
|
/**
|
|
3700
3783
|
* Called when a source detaches at `system.stop()` (reverse-registration
|
|
3701
3784
|
* order across all modules).
|
|
@@ -3801,4 +3884,4 @@ interface Plugin<M extends ModuleSchema = ModuleSchema> {
|
|
|
3801
3884
|
onTraceComplete?: (entry: TraceEntry) => void;
|
|
3802
3885
|
}
|
|
3803
3886
|
|
|
3804
|
-
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
|
|
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
|
|
728
|
-
*
|
|
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
|
|
@@ -2061,7 +2091,7 @@ interface ModuleHooks<M extends ModuleSchema> {
|
|
|
2061
2091
|
*
|
|
2062
2092
|
* @param error - The error the resolver threw (already normalized to `Error`).
|
|
2063
2093
|
* @param requirement - The requirement object that the failing resolver was handling.
|
|
2064
|
-
* @param
|
|
2094
|
+
* @param context - Hook context, including a typed snapshot of this module's facts.
|
|
2065
2095
|
*/
|
|
2066
2096
|
onResolverError?: (error: Error, requirement: {
|
|
2067
2097
|
type: string;
|
|
@@ -2386,10 +2416,6 @@ interface ModuleDef<M extends ModuleSchema = ModuleSchema> {
|
|
|
2386
2416
|
crossModuleDeps?: CrossModuleDeps;
|
|
2387
2417
|
}
|
|
2388
2418
|
|
|
2389
|
-
/**
|
|
2390
|
-
* System Types - Type definitions for the system
|
|
2391
|
-
*/
|
|
2392
|
-
|
|
2393
2419
|
/**
|
|
2394
2420
|
* Derive accessor from module schema.
|
|
2395
2421
|
*/
|
|
@@ -2424,6 +2450,35 @@ interface HistoryConfig {
|
|
|
2424
2450
|
maxSnapshots?: number;
|
|
2425
2451
|
/** Only snapshot events from these modules. Omit to snapshot all modules. Multi-module only. */
|
|
2426
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>;
|
|
2427
2482
|
}
|
|
2428
2483
|
/** History option: boolean shorthand or full config (presence implies enabled) */
|
|
2429
2484
|
type HistoryOption = boolean | HistoryConfig;
|
|
@@ -2664,7 +2719,7 @@ interface SystemInspection {
|
|
|
2664
2719
|
* - `"coalesced"` — manager debounced a same-event-name publish
|
|
2665
2720
|
* when `SourceDef.coalesce === "lastWriteWins"`
|
|
2666
2721
|
*/
|
|
2667
|
-
lastDropReason:
|
|
2722
|
+
lastDropReason: SourceDropReason | null;
|
|
2668
2723
|
/** Wall-clock ms of the most recent rejected publish, or `null`. */
|
|
2669
2724
|
lastDropAt: number | null;
|
|
2670
2725
|
/** Total attach + cleanup errors since the last attachAll. */
|
|
@@ -3136,6 +3191,22 @@ type ObservationEvent = {
|
|
|
3136
3191
|
moduleId: string;
|
|
3137
3192
|
eventName: string;
|
|
3138
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
|
+
}
|
|
3139
3210
|
/** Source detached at `system.stop()` (reverse-registration order). */
|
|
3140
3211
|
| {
|
|
3141
3212
|
type: "source.detach";
|
|
@@ -3452,10 +3523,6 @@ interface SystemConfig<M extends ModuleSchema = ModuleSchema> {
|
|
|
3452
3523
|
cloud?: boolean | string;
|
|
3453
3524
|
}
|
|
3454
3525
|
|
|
3455
|
-
/**
|
|
3456
|
-
* Plugin Types - Type definitions for plugins
|
|
3457
|
-
*/
|
|
3458
|
-
|
|
3459
3526
|
/** Reconcile result */
|
|
3460
3527
|
interface ReconcileResult {
|
|
3461
3528
|
unmet: RequirementWithId[];
|
|
@@ -3696,6 +3763,22 @@ interface Plugin<M extends ModuleSchema = ModuleSchema> {
|
|
|
3696
3763
|
* @param eventName - The dispatched event name (the first arg to `publish`).
|
|
3697
3764
|
*/
|
|
3698
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;
|
|
3699
3782
|
/**
|
|
3700
3783
|
* Called when a source detaches at `system.stop()` (reverse-registration
|
|
3701
3784
|
* order across all modules).
|
|
@@ -3801,4 +3884,4 @@ interface Plugin<M extends ModuleSchema = ModuleSchema> {
|
|
|
3801
3884
|
onTraceComplete?: (entry: TraceEntry) => void;
|
|
3802
3885
|
}
|
|
3803
3886
|
|
|
3804
|
-
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
|
|
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,
|
|
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,
|
|
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-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"system-SB7JYMRB.cjs"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"system-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"system-SJBP4TO5.js"}
|
package/dist/testing.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
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
|
package/dist/testing.d.cts
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,
|
|
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,
|
|
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-
|
|
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
|
|
@@ -207,28 +207,41 @@ declare function signSnapshot<T>(snapshot: DistributableSnapshotLike<T>, secret:
|
|
|
207
207
|
* **Important:** Always verify signatures before trusting snapshot data,
|
|
208
208
|
* especially if the snapshot was received from an untrusted source (client, cache).
|
|
209
209
|
*
|
|
210
|
+
* The default verification enforces `expiresAt` — a captured-and-replayed
|
|
211
|
+
* snapshot stops verifying once its `expiresAt` is in the past. Callers
|
|
212
|
+
* that legitimately need signature-only validation (testing infrastructure,
|
|
213
|
+
* archival validation) can pass `{ ignoreExpiry: true }`.
|
|
214
|
+
*
|
|
210
215
|
* @example
|
|
211
216
|
* ```typescript
|
|
212
217
|
* // Receive signed snapshot from client or cache
|
|
213
218
|
* const snapshot = JSON.parse(cachedData);
|
|
214
219
|
*
|
|
215
|
-
* // Verify before using
|
|
220
|
+
* // Verify before using. `verifySnapshotSignature` returns false for an
|
|
221
|
+
* // expired snapshot even when the HMAC is valid; treat it as the
|
|
222
|
+
* // single attestation gate.
|
|
216
223
|
* const isValid = await verifySnapshotSignature(snapshot, process.env.SNAPSHOT_SECRET);
|
|
217
224
|
* if (!isValid) {
|
|
218
|
-
* throw new Error('Invalid
|
|
225
|
+
* throw new Error('Invalid or expired snapshot');
|
|
219
226
|
* }
|
|
220
227
|
*
|
|
221
228
|
* // Now safe to use snapshot.data
|
|
222
|
-
*
|
|
223
|
-
* // Grant access
|
|
224
|
-
* }
|
|
229
|
+
* processSnapshotData(snapshot.data);
|
|
225
230
|
* ```
|
|
226
231
|
*
|
|
227
232
|
* @param signedSnapshot - The signed snapshot to verify
|
|
228
233
|
* @param secret - The HMAC secret (must match the signing secret)
|
|
229
|
-
* @
|
|
234
|
+
* @param options - Optional flags:
|
|
235
|
+
* - `ignoreExpiry`: skip the `expiresAt` check (signature-only mode)
|
|
236
|
+
* - `now`: override the current time used for expiry comparison
|
|
237
|
+
* (test helper)
|
|
238
|
+
* @returns True if signature is valid AND (unless `ignoreExpiry`) not
|
|
239
|
+
* expired; false otherwise
|
|
230
240
|
*/
|
|
231
|
-
declare function verifySnapshotSignature<T>(signedSnapshot: SignedSnapshot<T>, secret: string | Uint8Array
|
|
241
|
+
declare function verifySnapshotSignature<T>(signedSnapshot: SignedSnapshot<T>, secret: string | Uint8Array, options?: {
|
|
242
|
+
ignoreExpiry?: boolean;
|
|
243
|
+
now?: number;
|
|
244
|
+
}): Promise<boolean>;
|
|
232
245
|
/**
|
|
233
246
|
* Safely stringify any value for display. Handles circular references,
|
|
234
247
|
* BigInt, throwing toJSON, and optional truncation.
|
|
@@ -207,28 +207,41 @@ declare function signSnapshot<T>(snapshot: DistributableSnapshotLike<T>, secret:
|
|
|
207
207
|
* **Important:** Always verify signatures before trusting snapshot data,
|
|
208
208
|
* especially if the snapshot was received from an untrusted source (client, cache).
|
|
209
209
|
*
|
|
210
|
+
* The default verification enforces `expiresAt` — a captured-and-replayed
|
|
211
|
+
* snapshot stops verifying once its `expiresAt` is in the past. Callers
|
|
212
|
+
* that legitimately need signature-only validation (testing infrastructure,
|
|
213
|
+
* archival validation) can pass `{ ignoreExpiry: true }`.
|
|
214
|
+
*
|
|
210
215
|
* @example
|
|
211
216
|
* ```typescript
|
|
212
217
|
* // Receive signed snapshot from client or cache
|
|
213
218
|
* const snapshot = JSON.parse(cachedData);
|
|
214
219
|
*
|
|
215
|
-
* // Verify before using
|
|
220
|
+
* // Verify before using. `verifySnapshotSignature` returns false for an
|
|
221
|
+
* // expired snapshot even when the HMAC is valid; treat it as the
|
|
222
|
+
* // single attestation gate.
|
|
216
223
|
* const isValid = await verifySnapshotSignature(snapshot, process.env.SNAPSHOT_SECRET);
|
|
217
224
|
* if (!isValid) {
|
|
218
|
-
* throw new Error('Invalid
|
|
225
|
+
* throw new Error('Invalid or expired snapshot');
|
|
219
226
|
* }
|
|
220
227
|
*
|
|
221
228
|
* // Now safe to use snapshot.data
|
|
222
|
-
*
|
|
223
|
-
* // Grant access
|
|
224
|
-
* }
|
|
229
|
+
* processSnapshotData(snapshot.data);
|
|
225
230
|
* ```
|
|
226
231
|
*
|
|
227
232
|
* @param signedSnapshot - The signed snapshot to verify
|
|
228
233
|
* @param secret - The HMAC secret (must match the signing secret)
|
|
229
|
-
* @
|
|
234
|
+
* @param options - Optional flags:
|
|
235
|
+
* - `ignoreExpiry`: skip the `expiresAt` check (signature-only mode)
|
|
236
|
+
* - `now`: override the current time used for expiry comparison
|
|
237
|
+
* (test helper)
|
|
238
|
+
* @returns True if signature is valid AND (unless `ignoreExpiry`) not
|
|
239
|
+
* expired; false otherwise
|
|
230
240
|
*/
|
|
231
|
-
declare function verifySnapshotSignature<T>(signedSnapshot: SignedSnapshot<T>, secret: string | Uint8Array
|
|
241
|
+
declare function verifySnapshotSignature<T>(signedSnapshot: SignedSnapshot<T>, secret: string | Uint8Array, options?: {
|
|
242
|
+
ignoreExpiry?: boolean;
|
|
243
|
+
now?: number;
|
|
244
|
+
}): Promise<boolean>;
|
|
232
245
|
/**
|
|
233
246
|
* Safely stringify any value for display. Handles circular references,
|
|
234
247
|
* BigInt, throwing toJSON, and optional truncation.
|