@directive-run/core 1.21.0 → 1.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +2 -2
  2. package/dist/adapter-utils.d.cts +1 -1
  3. package/dist/adapter-utils.d.ts +1 -1
  4. package/dist/chunk-6NCC6RBC.js +3 -0
  5. package/dist/chunk-6NCC6RBC.js.map +1 -0
  6. package/dist/{chunk-4OXCKDKS.cjs → chunk-OAPD3HIG.cjs} +3 -3
  7. package/dist/{chunk-4OXCKDKS.cjs.map → chunk-OAPD3HIG.cjs.map} +1 -1
  8. package/dist/chunk-QTY2FXZY.cjs +3 -0
  9. package/dist/chunk-QTY2FXZY.cjs.map +1 -0
  10. package/dist/{chunk-E53A4NHM.js → chunk-YJEDX2JX.js} +3 -3
  11. package/dist/{chunk-E53A4NHM.js.map → chunk-YJEDX2JX.js.map} +1 -1
  12. package/dist/{index-DUbpbGw8.d.ts → index-BgKC_ZT_.d.ts} +1 -1
  13. package/dist/{index-CvQuu0tu.d.cts → index-DRPkZ8HE.d.cts} +1 -1
  14. package/dist/index.cjs +2 -2
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +46 -42
  17. package/dist/index.d.ts +46 -42
  18. package/dist/index.js +2 -2
  19. package/dist/index.js.map +1 -1
  20. package/dist/internals.cjs +1 -1
  21. package/dist/internals.d.cts +39 -25
  22. package/dist/internals.d.ts +39 -25
  23. package/dist/internals.js +1 -1
  24. package/dist/plugins/index.cjs +2 -2
  25. package/dist/plugins/index.cjs.map +1 -1
  26. package/dist/plugins/index.d.cts +159 -3
  27. package/dist/plugins/index.d.ts +159 -3
  28. package/dist/plugins/index.js +2 -2
  29. package/dist/plugins/index.js.map +1 -1
  30. package/dist/{plugins-4IfhJV32.d.cts → plugins-5Supk7it.d.cts} +78 -30
  31. package/dist/{plugins-4IfhJV32.d.ts → plugins-5Supk7it.d.ts} +78 -30
  32. package/dist/{predicate-BW05x5el.d.ts → predicate-C9oMO_ny.d.ts} +1 -1
  33. package/dist/{predicate-DBTPnlg6.d.cts → predicate-DYb-3Mvl.d.cts} +1 -1
  34. package/dist/system-5FKUBLLV.cjs +2 -0
  35. package/dist/{system-SB7JYMRB.cjs.map → system-5FKUBLLV.cjs.map} +1 -1
  36. package/dist/system-6YWCXQOQ.js +2 -0
  37. package/dist/{system-SJBP4TO5.js.map → system-6YWCXQOQ.js.map} +1 -1
  38. package/dist/testing.cjs +1 -1
  39. package/dist/testing.d.cts +1 -1
  40. package/dist/testing.d.ts +1 -1
  41. package/dist/testing.js +1 -1
  42. package/dist/worker.cjs +1 -1
  43. package/dist/worker.d.cts +1 -1
  44. package/dist/worker.d.ts +1 -1
  45. package/dist/worker.js +1 -1
  46. package/package.json +1 -1
  47. package/dist/chunk-6QAUJFQH.js +0 -3
  48. package/dist/chunk-6QAUJFQH.js.map +0 -1
  49. package/dist/chunk-M5PEB553.cjs +0 -3
  50. package/dist/chunk-M5PEB553.cjs.map +0 -1
  51. package/dist/system-SB7JYMRB.cjs +0 -2
  52. package/dist/system-SJBP4TO5.js +0 -2
@@ -568,26 +568,29 @@ interface ConstraintDef<S extends Schema, R extends Requirement = Requirement> {
568
568
  /** Timeout for async constraints (ms) */
569
569
  timeout?: number;
570
570
  /**
571
- * Fact keys whose **value the resolver compare-and-swaps**. Writes to
572
- * these facts land only if they still hold the snapshot value taken at
573
- * resolver dispatch; otherwise the write is dropped and the resolver
574
- * aborted.
575
- *
576
- * This is value-based per-fact compare-and-swap with one-shot
577
- * fact-level poisoning not a lock, not document versioning. Writes
578
- * to facts not listed always land; `when()` is not consulted. Omit for
579
- * no binding (default). Ignored on async constraints.
571
+ * Fact keys this resolver **aborts on** when they change mid-flight.
572
+ * The engine snapshots their values at resolver dispatch; if any of
573
+ * them changes before the resolver writes, the resolver's writes are
574
+ * dropped and the resolver aborted.
575
+ *
576
+ * Reads aloud as "abort on changes to these facts." This is the
577
+ * opposite shape of a lock the resolver yields to whoever wrote
578
+ * first; it does NOT prevent other writers. Value-based per-fact
579
+ * compare-and-swap with one-shot fact-level poisoning, not document
580
+ * versioning. Writes to facts not listed always land; `when()` is not
581
+ * consulted. Omit for no binding (default). Ignored on async
582
+ * constraints.
580
583
  *
581
584
  * @example
582
585
  * ```ts
583
586
  * executeAction: {
584
587
  * when: (f) => f.status === 'mutating',
585
588
  * require: { type: 'EXECUTE_ACTION' },
586
- * owns: ['status'], // the resolver owns `status`
589
+ * abortOn: ['status'], // abort if `status` changes mid-flight
587
590
  * }
588
591
  * ```
589
592
  */
590
- owns?: readonly string[];
593
+ abortOn?: readonly string[];
591
594
  /**
592
595
  * Constraint IDs whose resolvers must complete before this constraint is evaluated.
593
596
  * If a dependency's `when()` returns false (no requirements), this constraint proceeds.
@@ -2172,12 +2175,13 @@ interface TypedConstraintDef<M extends ModuleSchema> {
2172
2175
  /** Timeout for async constraints (ms) */
2173
2176
  timeout?: number;
2174
2177
  /**
2175
- * Fact keys whose **value the resolver compare-and-swaps**. Writes to
2176
- * these facts land only if they still hold the snapshot value taken at
2177
- * resolver dispatch; otherwise the write is dropped and the resolver
2178
- * aborted. Omit for no binding (default). Ignored on async constraints.
2178
+ * Fact keys this resolver aborts on when they change mid-flight. The
2179
+ * engine snapshots their values at resolver dispatch; if any of them
2180
+ * changes before the resolver writes, the resolver's writes are
2181
+ * dropped and the resolver aborted. Omit for no binding (default).
2182
+ * Ignored on async constraints.
2179
2183
  */
2180
- owns?: readonly string[];
2184
+ abortOn?: readonly string[];
2181
2185
  /**
2182
2186
  * Constraint IDs whose resolvers must complete before this constraint is evaluated.
2183
2187
  * If a dependency's `when()` returns false (no requirements), this constraint proceeds.
@@ -2223,12 +2227,13 @@ interface CrossModuleConstraintDef<M extends ModuleSchema, Deps extends CrossMod
2223
2227
  /** Timeout for async constraints (ms) */
2224
2228
  timeout?: number;
2225
2229
  /**
2226
- * Fact keys whose **value the resolver compare-and-swaps**. Writes to
2227
- * these facts land only if they still hold the snapshot value taken at
2228
- * resolver dispatch; otherwise the write is dropped and the resolver
2229
- * aborted. Omit for no binding (default). Ignored on async constraints.
2230
+ * Fact keys this resolver aborts on when they change mid-flight. The
2231
+ * engine snapshots their values at resolver dispatch; if any of them
2232
+ * changes before the resolver writes, the resolver's writes are
2233
+ * dropped and the resolver aborted. Omit for no binding (default).
2234
+ * Ignored on async constraints.
2230
2235
  */
2231
- owns?: readonly string[];
2236
+ abortOn?: readonly string[];
2232
2237
  /**
2233
2238
  * Constraint IDs whose resolvers must complete before this constraint is evaluated.
2234
2239
  * If a dependency's `when()` returns false (no requirements), this constraint proceeds.
@@ -2644,16 +2649,17 @@ interface SystemInspection {
2644
2649
  */
2645
2650
  whenSpec?: FactPredicate<Record<string, unknown>>;
2646
2651
  /**
2647
- * Owned-fact list for RFC-0003 binding. Populated from the
2648
- * constraint definition's `owns:` field. Exposed for `doctor.checkOwns()`
2649
- * so it can flag candidates that would race or shadow these writes.
2650
- * Absent when the constraint declares no `owns`.
2652
+ * Abort-binding fact list for RFC-0003 constraint binding. Populated
2653
+ * from the constraint definition's `abortOn:` field. Exposed for
2654
+ * `doctor.checkAbortOn()` so it can flag candidates that would race
2655
+ * or shadow these writes. Absent when the constraint declares no
2656
+ * `abortOn`.
2651
2657
  */
2652
- readonly owns?: readonly string[];
2658
+ readonly abortOn?: readonly string[];
2653
2659
  /**
2654
2660
  * Fact paths the constraint `bind:`s to. v2 promise — the runtime
2655
2661
  * does not yet emit a `bind` field on inspect snapshots, but the
2656
- * type slot is reserved so `doctor.checkOwns()` is stable across
2662
+ * type slot is reserved so `doctor.checkAbortOn()` is stable across
2657
2663
  * the rollout. (F1)
2658
2664
  */
2659
2665
  readonly bind?: readonly string[];
@@ -3090,6 +3096,26 @@ type ObservationEvent = {
3090
3096
  type: "constraint.error";
3091
3097
  id: string;
3092
3098
  error: unknown;
3099
+ }
3100
+ /**
3101
+ * Fired when the engine silently disables a constraint's `abortOn:`
3102
+ * binding because the constraint is async (declared `async: true` OR
3103
+ * runtime-promoted because its `when()` returned a Promise). The
3104
+ * dev-mode `console.warn` is the human-facing signal; this event is
3105
+ * the SIEM-facing one. Without it, a production constraint loses its
3106
+ * clobber-protection with no plugin / observer trail.
3107
+ *
3108
+ * - `reason: "async-declared"` — the constraint def has `async: true`.
3109
+ * The author opted in; the warning + event are advisory.
3110
+ * - `reason: "async-promoted"` — the constraint's `when()` returned
3111
+ * a Promise at runtime. The author probably did not realize. This
3112
+ * is the more dangerous case — the binding silently disables and
3113
+ * the clobber check no-ops.
3114
+ */
3115
+ | {
3116
+ type: "constraint.binding.disabled";
3117
+ id: string;
3118
+ reason: "async-declared" | "async-promoted";
3093
3119
  } | {
3094
3120
  type: "requirement.created";
3095
3121
  id: string;
@@ -3117,7 +3143,7 @@ type ObservationEvent = {
3117
3143
  error: unknown;
3118
3144
  } | {
3119
3145
  /**
3120
- * A real per-write rejection. A bound resolver's owned-fact write was
3146
+ * A real per-write rejection. A bound resolver's abort-bound write was
3121
3147
  * dropped because the fact was changed by something outside the
3122
3148
  * resolver between the resolver's baseline and its next write (RFC-0003
3123
3149
  * optimistic-concurrency check). `reason` keeps the observation protocol
@@ -3639,6 +3665,27 @@ interface Plugin<M extends ModuleSchema = ModuleSchema> {
3639
3665
  * @param error - The error that was thrown
3640
3666
  */
3641
3667
  onConstraintError?: (id: string, error: unknown) => void;
3668
+ /**
3669
+ * Called when the engine silently disables a constraint's `abortOn:`
3670
+ * binding because the constraint is async. Pairs with the dev-mode
3671
+ * `console.warn` for SIEM-side visibility — without this signal, a
3672
+ * production constraint loses its clobber-protection with no
3673
+ * plugin / observer trail.
3674
+ *
3675
+ * - `"async-declared"` — the constraint def has `async: true`. The
3676
+ * author opted in; treat as advisory.
3677
+ * - `"async-promoted"` — the constraint's `when()` returned a Promise
3678
+ * at runtime, even though `async: true` was not set. The author
3679
+ * probably did not realize. This is the dangerous case — escalate.
3680
+ *
3681
+ * Fired at most once per `getConstraintBinding` lookup; deduping
3682
+ * across reconcile ticks is the consumer's responsibility (the
3683
+ * audit-ledger plugin does this with a per-id sticky bit).
3684
+ *
3685
+ * @param id - The constraint ID whose binding was disabled
3686
+ * @param reason - Whether the async state was author-declared or runtime-promoted
3687
+ */
3688
+ onConstraintBindingDisabled?: (id: string, reason: "async-declared" | "async-promoted") => void;
3642
3689
  /**
3643
3690
  * Called when a new requirement is created by a constraint.
3644
3691
  * @param req - The requirement with its computed ID
@@ -3691,8 +3738,9 @@ interface Plugin<M extends ModuleSchema = ModuleSchema> {
3691
3738
  /**
3692
3739
  * Called when a resolver's write is rejected by the runtime. The only
3693
3740
  * `reason` today is `"clobbered"`: a bound resolver (RFC-0003) dropped a
3694
- * write to an owned fact because the fact was changed by something outside
3695
- * the resolver between the resolver's baseline and its next write the
3741
+ * write to an abort-bound fact (one listed in the constraint's
3742
+ * `abortOn:`) because the fact was changed by something outside the
3743
+ * resolver between the resolver's baseline and its next write — the
3696
3744
  * resolver's `AbortController` is aborted in the same step. See
3697
3745
  * {@link createBoundFacts} for the per-fact optimistic-concurrency model.
3698
3746
  * `reason` keeps the hook backend-neutral.
@@ -568,26 +568,29 @@ interface ConstraintDef<S extends Schema, R extends Requirement = Requirement> {
568
568
  /** Timeout for async constraints (ms) */
569
569
  timeout?: number;
570
570
  /**
571
- * Fact keys whose **value the resolver compare-and-swaps**. Writes to
572
- * these facts land only if they still hold the snapshot value taken at
573
- * resolver dispatch; otherwise the write is dropped and the resolver
574
- * aborted.
575
- *
576
- * This is value-based per-fact compare-and-swap with one-shot
577
- * fact-level poisoning not a lock, not document versioning. Writes
578
- * to facts not listed always land; `when()` is not consulted. Omit for
579
- * no binding (default). Ignored on async constraints.
571
+ * Fact keys this resolver **aborts on** when they change mid-flight.
572
+ * The engine snapshots their values at resolver dispatch; if any of
573
+ * them changes before the resolver writes, the resolver's writes are
574
+ * dropped and the resolver aborted.
575
+ *
576
+ * Reads aloud as "abort on changes to these facts." This is the
577
+ * opposite shape of a lock the resolver yields to whoever wrote
578
+ * first; it does NOT prevent other writers. Value-based per-fact
579
+ * compare-and-swap with one-shot fact-level poisoning, not document
580
+ * versioning. Writes to facts not listed always land; `when()` is not
581
+ * consulted. Omit for no binding (default). Ignored on async
582
+ * constraints.
580
583
  *
581
584
  * @example
582
585
  * ```ts
583
586
  * executeAction: {
584
587
  * when: (f) => f.status === 'mutating',
585
588
  * require: { type: 'EXECUTE_ACTION' },
586
- * owns: ['status'], // the resolver owns `status`
589
+ * abortOn: ['status'], // abort if `status` changes mid-flight
587
590
  * }
588
591
  * ```
589
592
  */
590
- owns?: readonly string[];
593
+ abortOn?: readonly string[];
591
594
  /**
592
595
  * Constraint IDs whose resolvers must complete before this constraint is evaluated.
593
596
  * If a dependency's `when()` returns false (no requirements), this constraint proceeds.
@@ -2172,12 +2175,13 @@ interface TypedConstraintDef<M extends ModuleSchema> {
2172
2175
  /** Timeout for async constraints (ms) */
2173
2176
  timeout?: number;
2174
2177
  /**
2175
- * Fact keys whose **value the resolver compare-and-swaps**. Writes to
2176
- * these facts land only if they still hold the snapshot value taken at
2177
- * resolver dispatch; otherwise the write is dropped and the resolver
2178
- * aborted. Omit for no binding (default). Ignored on async constraints.
2178
+ * Fact keys this resolver aborts on when they change mid-flight. The
2179
+ * engine snapshots their values at resolver dispatch; if any of them
2180
+ * changes before the resolver writes, the resolver's writes are
2181
+ * dropped and the resolver aborted. Omit for no binding (default).
2182
+ * Ignored on async constraints.
2179
2183
  */
2180
- owns?: readonly string[];
2184
+ abortOn?: readonly string[];
2181
2185
  /**
2182
2186
  * Constraint IDs whose resolvers must complete before this constraint is evaluated.
2183
2187
  * If a dependency's `when()` returns false (no requirements), this constraint proceeds.
@@ -2223,12 +2227,13 @@ interface CrossModuleConstraintDef<M extends ModuleSchema, Deps extends CrossMod
2223
2227
  /** Timeout for async constraints (ms) */
2224
2228
  timeout?: number;
2225
2229
  /**
2226
- * Fact keys whose **value the resolver compare-and-swaps**. Writes to
2227
- * these facts land only if they still hold the snapshot value taken at
2228
- * resolver dispatch; otherwise the write is dropped and the resolver
2229
- * aborted. Omit for no binding (default). Ignored on async constraints.
2230
+ * Fact keys this resolver aborts on when they change mid-flight. The
2231
+ * engine snapshots their values at resolver dispatch; if any of them
2232
+ * changes before the resolver writes, the resolver's writes are
2233
+ * dropped and the resolver aborted. Omit for no binding (default).
2234
+ * Ignored on async constraints.
2230
2235
  */
2231
- owns?: readonly string[];
2236
+ abortOn?: readonly string[];
2232
2237
  /**
2233
2238
  * Constraint IDs whose resolvers must complete before this constraint is evaluated.
2234
2239
  * If a dependency's `when()` returns false (no requirements), this constraint proceeds.
@@ -2644,16 +2649,17 @@ interface SystemInspection {
2644
2649
  */
2645
2650
  whenSpec?: FactPredicate<Record<string, unknown>>;
2646
2651
  /**
2647
- * Owned-fact list for RFC-0003 binding. Populated from the
2648
- * constraint definition's `owns:` field. Exposed for `doctor.checkOwns()`
2649
- * so it can flag candidates that would race or shadow these writes.
2650
- * Absent when the constraint declares no `owns`.
2652
+ * Abort-binding fact list for RFC-0003 constraint binding. Populated
2653
+ * from the constraint definition's `abortOn:` field. Exposed for
2654
+ * `doctor.checkAbortOn()` so it can flag candidates that would race
2655
+ * or shadow these writes. Absent when the constraint declares no
2656
+ * `abortOn`.
2651
2657
  */
2652
- readonly owns?: readonly string[];
2658
+ readonly abortOn?: readonly string[];
2653
2659
  /**
2654
2660
  * Fact paths the constraint `bind:`s to. v2 promise — the runtime
2655
2661
  * does not yet emit a `bind` field on inspect snapshots, but the
2656
- * type slot is reserved so `doctor.checkOwns()` is stable across
2662
+ * type slot is reserved so `doctor.checkAbortOn()` is stable across
2657
2663
  * the rollout. (F1)
2658
2664
  */
2659
2665
  readonly bind?: readonly string[];
@@ -3090,6 +3096,26 @@ type ObservationEvent = {
3090
3096
  type: "constraint.error";
3091
3097
  id: string;
3092
3098
  error: unknown;
3099
+ }
3100
+ /**
3101
+ * Fired when the engine silently disables a constraint's `abortOn:`
3102
+ * binding because the constraint is async (declared `async: true` OR
3103
+ * runtime-promoted because its `when()` returned a Promise). The
3104
+ * dev-mode `console.warn` is the human-facing signal; this event is
3105
+ * the SIEM-facing one. Without it, a production constraint loses its
3106
+ * clobber-protection with no plugin / observer trail.
3107
+ *
3108
+ * - `reason: "async-declared"` — the constraint def has `async: true`.
3109
+ * The author opted in; the warning + event are advisory.
3110
+ * - `reason: "async-promoted"` — the constraint's `when()` returned
3111
+ * a Promise at runtime. The author probably did not realize. This
3112
+ * is the more dangerous case — the binding silently disables and
3113
+ * the clobber check no-ops.
3114
+ */
3115
+ | {
3116
+ type: "constraint.binding.disabled";
3117
+ id: string;
3118
+ reason: "async-declared" | "async-promoted";
3093
3119
  } | {
3094
3120
  type: "requirement.created";
3095
3121
  id: string;
@@ -3117,7 +3143,7 @@ type ObservationEvent = {
3117
3143
  error: unknown;
3118
3144
  } | {
3119
3145
  /**
3120
- * A real per-write rejection. A bound resolver's owned-fact write was
3146
+ * A real per-write rejection. A bound resolver's abort-bound write was
3121
3147
  * dropped because the fact was changed by something outside the
3122
3148
  * resolver between the resolver's baseline and its next write (RFC-0003
3123
3149
  * optimistic-concurrency check). `reason` keeps the observation protocol
@@ -3639,6 +3665,27 @@ interface Plugin<M extends ModuleSchema = ModuleSchema> {
3639
3665
  * @param error - The error that was thrown
3640
3666
  */
3641
3667
  onConstraintError?: (id: string, error: unknown) => void;
3668
+ /**
3669
+ * Called when the engine silently disables a constraint's `abortOn:`
3670
+ * binding because the constraint is async. Pairs with the dev-mode
3671
+ * `console.warn` for SIEM-side visibility — without this signal, a
3672
+ * production constraint loses its clobber-protection with no
3673
+ * plugin / observer trail.
3674
+ *
3675
+ * - `"async-declared"` — the constraint def has `async: true`. The
3676
+ * author opted in; treat as advisory.
3677
+ * - `"async-promoted"` — the constraint's `when()` returned a Promise
3678
+ * at runtime, even though `async: true` was not set. The author
3679
+ * probably did not realize. This is the dangerous case — escalate.
3680
+ *
3681
+ * Fired at most once per `getConstraintBinding` lookup; deduping
3682
+ * across reconcile ticks is the consumer's responsibility (the
3683
+ * audit-ledger plugin does this with a per-id sticky bit).
3684
+ *
3685
+ * @param id - The constraint ID whose binding was disabled
3686
+ * @param reason - Whether the async state was author-declared or runtime-promoted
3687
+ */
3688
+ onConstraintBindingDisabled?: (id: string, reason: "async-declared" | "async-promoted") => void;
3642
3689
  /**
3643
3690
  * Called when a new requirement is created by a constraint.
3644
3691
  * @param req - The requirement with its computed ID
@@ -3691,8 +3738,9 @@ interface Plugin<M extends ModuleSchema = ModuleSchema> {
3691
3738
  /**
3692
3739
  * Called when a resolver's write is rejected by the runtime. The only
3693
3740
  * `reason` today is `"clobbered"`: a bound resolver (RFC-0003) dropped a
3694
- * write to an owned fact because the fact was changed by something outside
3695
- * the resolver between the resolver's baseline and its next write the
3741
+ * write to an abort-bound fact (one listed in the constraint's
3742
+ * `abortOn:`) because the fact was changed by something outside the
3743
+ * resolver between the resolver's baseline and its next write — the
3696
3744
  * resolver's `AbortController` is aborted in the same step. See
3697
3745
  * {@link createBoundFacts} for the per-fact optimistic-concurrency model.
3698
3746
  * `reason` keeps the hook backend-neutral.
@@ -1,4 +1,4 @@
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';
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-5Supk7it.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, 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';
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-5Supk7it.cjs';
2
2
 
3
3
  /**
4
4
  * Derivation Types - Type definitions for derivations
@@ -0,0 +1,2 @@
1
+ 'use strict';var chunkOAPD3HIG_cjs=require('./chunk-OAPD3HIG.cjs');require('./chunk-QTY2FXZY.cjs'),require('./chunk-GACC2DMS.cjs'),require('./chunk-GKMJ7NMP.cjs'),require('./chunk-GBCWXTXW.cjs');Object.defineProperty(exports,"createSystem",{enumerable:true,get:function(){return chunkOAPD3HIG_cjs.a}});//# sourceMappingURL=system-5FKUBLLV.cjs.map
2
+ //# sourceMappingURL=system-5FKUBLLV.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"system-SB7JYMRB.cjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"system-5FKUBLLV.cjs"}
@@ -0,0 +1,2 @@
1
+ export{a as createSystem}from'./chunk-YJEDX2JX.js';import'./chunk-6NCC6RBC.js';import'./chunk-RBF653NR.js';import'./chunk-6PF2FRBG.js';import'./chunk-SFUVPP4L.js';//# sourceMappingURL=system-6YWCXQOQ.js.map
2
+ //# sourceMappingURL=system-6YWCXQOQ.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"system-SJBP4TO5.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"system-6YWCXQOQ.js"}
package/dist/testing.cjs CHANGED
@@ -1,2 +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');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
1
+ 'use strict';var chunkOAPD3HIG_cjs=require('./chunk-OAPD3HIG.cjs');require('./chunk-QTY2FXZY.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=chunkOAPD3HIG_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=chunkOAPD3HIG_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, at as SystemInspection } from './plugins-4IfhJV32.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-5Supk7it.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, at as SystemInspection } from './plugins-4IfhJV32.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-5Supk7it.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-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
1
+ import {a}from'./chunk-YJEDX2JX.js';import'./chunk-6NCC6RBC.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
package/dist/worker.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';function H(o){let{worker:c,onFactChange:T,onDerivationChange:y,onRequirementCreated:g,onRequirementMet:u,onError:n}=o,s=new Map,a=0,t=3e4;function i(e){let r=s.get(e);r?.timeoutHandle!==void 0&&clearTimeout(r.timeoutHandle);}let d=null,S=null,f=null,v=null;function k(e){return e?.(),null}function M(e,r){let p=s.get(e);p&&(i(e),p.resolve(r),s.delete(e));}function h(){d=k(d);}function O(){S=k(S);}function W(){f=k(f);}function C(){v=k(v);}function w(e){T?.(e.key,e.value,e.prev);}function D(e){y?.(e.key,e.value);}function P(e){g?.(e.requirement);}function q(e){u?.(e.requirementId,e.resolverId);}function _(e){n?.(e.error,e.source);}function A(e){M(e.requestId,e.snapshot);}function N(e){M(e.requestId,e.inspection);}function x(e){let r=s.get(e.requestId);r&&(i(e.requestId),e.success?r.resolve(void 0):r.reject(new Error(e.error||"Settle failed")),s.delete(e.requestId));}c.onmessage=e=>{let r=e.data;switch(r.type){case "READY":return h();case "STARTED":return O();case "STOPPED":return W();case "DESTROYED":return C();case "FACT_CHANGED":return w(r);case "DERIVATION_CHANGED":return D(r);case "REQUIREMENT_CREATED":return P(r);case "REQUIREMENT_MET":return q(r);case "ERROR":return _(r);case "SNAPSHOT_RESULT":return A(r);case "INSPECT_RESULT":return N(r);case "SETTLE_RESULT":return x(r)}},c.onerror=e=>{let r=e&&typeof e=="object"&&"message"in e?String(e.message??"unknown error"):"unknown error";if(s.size>0){let p=new Error(`[Directive] worker errored: ${r}`);for(let[,E]of s)E.timeoutHandle!==void 0&&clearTimeout(E.timeoutHandle),E.reject(p);s.clear();}n?.(r,"worker");};function l(e){c.postMessage(e);}function m(e,r=t){return new Promise((p,E)=>{let I={resolve:p,reject:E};Number.isFinite(r)&&r>0&&(I.timeoutHandle=setTimeout(()=>{s.has(e.requestId)&&(s.delete(e.requestId),E(new Error(`[Directive] worker request timed out after ${r}ms`)));},r)),s.set(e.requestId,I),l(e);})}return {init(e){return new Promise(r=>{d=r,l({type:"INIT",config:e});})},start(){return new Promise(e=>{S=e,l({type:"START"});})},stop(){return new Promise(e=>{f=e,l({type:"STOP"});})},destroy(){return new Promise(e=>{v=e,l({type:"DESTROY"});})},setFact(e,r){l({type:"SET_FACT",key:e,value:r});},setFacts(e){l({type:"SET_FACTS",facts:e});},dispatch(e){l({type:"DISPATCH",event:e});},getSnapshot(e,r){let p=`snapshot-${++a}`;return m({type:"GET_SNAPSHOT",options:e,requestId:p},r??t)},inspect(e){let r=`inspect-${++a}`;return m({type:"INSPECT",requestId:r},e??t)},settle(e,r){let p=`settle-${++a}`;return m({type:"SETTLE",timeout:e,requestId:p},r??t)},terminate(){c.terminate();}}}var R=null;function b(){return R||(R=new Map),R}function L(o,c){b().set(o,c);}function U(){let o=null;async function c(t){let i=await F(t.config);return postMessage({type:"READY"}),i}function T(t){t.start(),postMessage({type:"STARTED"});}function y(t){t.stop(),postMessage({type:"STOPPED"});}function g(t){t.destroy(),postMessage({type:"DESTROYED"});}function u(t,i){let d=t.getSnapshot(i.options);postMessage({type:"SNAPSHOT_RESULT",requestId:i.requestId,snapshot:d});}function n(t,i){let d=t.inspect();postMessage({type:"INSPECT_RESULT",requestId:i.requestId,inspection:d});}async function s(t,i){try{await t.settle(i.timeout),postMessage({type:"SETTLE_RESULT",requestId:i.requestId,success:!0});}catch(d){postMessage({type:"SETTLE_RESULT",requestId:i.requestId,success:false,error:d instanceof Error?d.message:String(d)});}}async function a(t){if(t.type==="INIT"){o=await c(t);return}if(o)switch(t.type){case "START":T(o);break;case "STOP":y(o);break;case "DESTROY":g(o),o=null;break;case "SET_FACT":o.setFact(t.key,t.value);break;case "SET_FACTS":o.setFacts(t.facts);break;case "DISPATCH":o.dispatch(t.event);break;case "GET_SNAPSHOT":u(o,t);break;case "INSPECT":n(o,t);break;case "SETTLE":await s(o,t);break}}self.onmessage=async t=>{try{await a(t.data);}catch(i){postMessage({type:"ERROR",error:i instanceof Error?i.message:String(i),source:t.data.type});}};}async function F(o){let{createSystem:c}=await import('./system-SB7JYMRB.cjs'),T=b(),y={};for(let n of o.moduleNames){let s=T.get(n);if(!s)throw new Error(`[Directive Worker] Module "${n}" not registered. Call registerWorkerModule('${n}', module) before handling messages.`);y[n]=s;}let u=c({modules:y,plugins:[{name:"__worker-tracking__",onFactSet:(n,s,a)=>{postMessage({type:"FACT_CHANGED",key:n,value:s,prev:a});},onDerivationCompute:(n,s)=>{postMessage({type:"DERIVATION_CHANGED",key:n,value:s});},onRequirementCreated:n=>{postMessage({type:"REQUIREMENT_CREATED",requirement:{...n.requirement,id:n.id}});},onRequirementMet:(n,s)=>{postMessage({type:"REQUIREMENT_MET",requirementId:n.id,resolverId:s});}}],history:o.history});return {start:()=>u.start(),stop:()=>u.stop(),destroy:()=>u.destroy(),setFact:(n,s)=>{u.facts[n]=s;},setFacts:n=>{let s=u.facts;if(s.$store?.batch)s.$store.batch(()=>{for(let[a,t]of Object.entries(n))s[a]=t;});else for(let[a,t]of Object.entries(n))s[a]=t;},dispatch:n=>{u.dispatch(n);},getSnapshot:n=>u.getDistributableSnapshot(n),inspect:()=>u.inspect(),settle:n=>u.settle(n)}}exports.createWorkerClient=H;exports.getWorkerModuleRegistry=b;exports.handleWorkerMessages=U;exports.registerWorkerModule=L;//# sourceMappingURL=worker.cjs.map
1
+ 'use strict';function H(o){let{worker:c,onFactChange:T,onDerivationChange:y,onRequirementCreated:g,onRequirementMet:u,onError:n}=o,s=new Map,a=0,t=3e4;function i(e){let r=s.get(e);r?.timeoutHandle!==void 0&&clearTimeout(r.timeoutHandle);}let d=null,S=null,f=null,v=null;function k(e){return e?.(),null}function M(e,r){let p=s.get(e);p&&(i(e),p.resolve(r),s.delete(e));}function h(){d=k(d);}function O(){S=k(S);}function W(){f=k(f);}function C(){v=k(v);}function w(e){T?.(e.key,e.value,e.prev);}function D(e){y?.(e.key,e.value);}function P(e){g?.(e.requirement);}function q(e){u?.(e.requirementId,e.resolverId);}function _(e){n?.(e.error,e.source);}function A(e){M(e.requestId,e.snapshot);}function N(e){M(e.requestId,e.inspection);}function x(e){let r=s.get(e.requestId);r&&(i(e.requestId),e.success?r.resolve(void 0):r.reject(new Error(e.error||"Settle failed")),s.delete(e.requestId));}c.onmessage=e=>{let r=e.data;switch(r.type){case "READY":return h();case "STARTED":return O();case "STOPPED":return W();case "DESTROYED":return C();case "FACT_CHANGED":return w(r);case "DERIVATION_CHANGED":return D(r);case "REQUIREMENT_CREATED":return P(r);case "REQUIREMENT_MET":return q(r);case "ERROR":return _(r);case "SNAPSHOT_RESULT":return A(r);case "INSPECT_RESULT":return N(r);case "SETTLE_RESULT":return x(r)}},c.onerror=e=>{let r=e&&typeof e=="object"&&"message"in e?String(e.message??"unknown error"):"unknown error";if(s.size>0){let p=new Error(`[Directive] worker errored: ${r}`);for(let[,E]of s)E.timeoutHandle!==void 0&&clearTimeout(E.timeoutHandle),E.reject(p);s.clear();}n?.(r,"worker");};function l(e){c.postMessage(e);}function m(e,r=t){return new Promise((p,E)=>{let I={resolve:p,reject:E};Number.isFinite(r)&&r>0&&(I.timeoutHandle=setTimeout(()=>{s.has(e.requestId)&&(s.delete(e.requestId),E(new Error(`[Directive] worker request timed out after ${r}ms`)));},r)),s.set(e.requestId,I),l(e);})}return {init(e){return new Promise(r=>{d=r,l({type:"INIT",config:e});})},start(){return new Promise(e=>{S=e,l({type:"START"});})},stop(){return new Promise(e=>{f=e,l({type:"STOP"});})},destroy(){return new Promise(e=>{v=e,l({type:"DESTROY"});})},setFact(e,r){l({type:"SET_FACT",key:e,value:r});},setFacts(e){l({type:"SET_FACTS",facts:e});},dispatch(e){l({type:"DISPATCH",event:e});},getSnapshot(e,r){let p=`snapshot-${++a}`;return m({type:"GET_SNAPSHOT",options:e,requestId:p},r??t)},inspect(e){let r=`inspect-${++a}`;return m({type:"INSPECT",requestId:r},e??t)},settle(e,r){let p=`settle-${++a}`;return m({type:"SETTLE",timeout:e,requestId:p},r??t)},terminate(){c.terminate();}}}var R=null;function b(){return R||(R=new Map),R}function L(o,c){b().set(o,c);}function U(){let o=null;async function c(t){let i=await F(t.config);return postMessage({type:"READY"}),i}function T(t){t.start(),postMessage({type:"STARTED"});}function y(t){t.stop(),postMessage({type:"STOPPED"});}function g(t){t.destroy(),postMessage({type:"DESTROYED"});}function u(t,i){let d=t.getSnapshot(i.options);postMessage({type:"SNAPSHOT_RESULT",requestId:i.requestId,snapshot:d});}function n(t,i){let d=t.inspect();postMessage({type:"INSPECT_RESULT",requestId:i.requestId,inspection:d});}async function s(t,i){try{await t.settle(i.timeout),postMessage({type:"SETTLE_RESULT",requestId:i.requestId,success:!0});}catch(d){postMessage({type:"SETTLE_RESULT",requestId:i.requestId,success:false,error:d instanceof Error?d.message:String(d)});}}async function a(t){if(t.type==="INIT"){o=await c(t);return}if(o)switch(t.type){case "START":T(o);break;case "STOP":y(o);break;case "DESTROY":g(o),o=null;break;case "SET_FACT":o.setFact(t.key,t.value);break;case "SET_FACTS":o.setFacts(t.facts);break;case "DISPATCH":o.dispatch(t.event);break;case "GET_SNAPSHOT":u(o,t);break;case "INSPECT":n(o,t);break;case "SETTLE":await s(o,t);break}}self.onmessage=async t=>{try{await a(t.data);}catch(i){postMessage({type:"ERROR",error:i instanceof Error?i.message:String(i),source:t.data.type});}};}async function F(o){let{createSystem:c}=await import('./system-5FKUBLLV.cjs'),T=b(),y={};for(let n of o.moduleNames){let s=T.get(n);if(!s)throw new Error(`[Directive Worker] Module "${n}" not registered. Call registerWorkerModule('${n}', module) before handling messages.`);y[n]=s;}let u=c({modules:y,plugins:[{name:"__worker-tracking__",onFactSet:(n,s,a)=>{postMessage({type:"FACT_CHANGED",key:n,value:s,prev:a});},onDerivationCompute:(n,s)=>{postMessage({type:"DERIVATION_CHANGED",key:n,value:s});},onRequirementCreated:n=>{postMessage({type:"REQUIREMENT_CREATED",requirement:{...n.requirement,id:n.id}});},onRequirementMet:(n,s)=>{postMessage({type:"REQUIREMENT_MET",requirementId:n.id,resolverId:s});}}],history:o.history});return {start:()=>u.start(),stop:()=>u.stop(),destroy:()=>u.destroy(),setFact:(n,s)=>{u.facts[n]=s;},setFacts:n=>{let s=u.facts;if(s.$store?.batch)s.$store.batch(()=>{for(let[a,t]of Object.entries(n))s[a]=t;});else for(let[a,t]of Object.entries(n))s[a]=t;},dispatch:n=>{u.dispatch(n);},getSnapshot:n=>u.getDistributableSnapshot(n),inspect:()=>u.inspect(),settle:n=>u.settle(n)}}exports.createWorkerClient=H;exports.getWorkerModuleRegistry=b;exports.handleWorkerMessages=U;exports.registerWorkerModule=L;//# sourceMappingURL=worker.cjs.map
2
2
  //# sourceMappingURL=worker.cjs.map
package/dist/worker.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { M as ModuleSchema, z as DistributableSnapshotOptions, y as DistributableSnapshot, at as SystemInspection, r as Requirement } from './plugins-4IfhJV32.cjs';
1
+ import { M as ModuleSchema, z as DistributableSnapshotOptions, y as DistributableSnapshot, at as SystemInspection, r as Requirement } from './plugins-5Supk7it.cjs';
2
2
 
3
3
  /**
4
4
  * Web Worker Adapter - Run Directive engine off the main thread
package/dist/worker.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { M as ModuleSchema, z as DistributableSnapshotOptions, y as DistributableSnapshot, at as SystemInspection, r as Requirement } from './plugins-4IfhJV32.js';
1
+ import { M as ModuleSchema, z as DistributableSnapshotOptions, y as DistributableSnapshot, at as SystemInspection, r as Requirement } from './plugins-5Supk7it.js';
2
2
 
3
3
  /**
4
4
  * Web Worker Adapter - Run Directive engine off the main thread
package/dist/worker.js CHANGED
@@ -1,2 +1,2 @@
1
- function H(o){let{worker:c,onFactChange:T,onDerivationChange:y,onRequirementCreated:g,onRequirementMet:u,onError:n}=o,s=new Map,a=0,t=3e4;function i(e){let r=s.get(e);r?.timeoutHandle!==void 0&&clearTimeout(r.timeoutHandle);}let d=null,S=null,f=null,v=null;function k(e){return e?.(),null}function M(e,r){let p=s.get(e);p&&(i(e),p.resolve(r),s.delete(e));}function h(){d=k(d);}function O(){S=k(S);}function W(){f=k(f);}function C(){v=k(v);}function w(e){T?.(e.key,e.value,e.prev);}function D(e){y?.(e.key,e.value);}function P(e){g?.(e.requirement);}function q(e){u?.(e.requirementId,e.resolverId);}function _(e){n?.(e.error,e.source);}function A(e){M(e.requestId,e.snapshot);}function N(e){M(e.requestId,e.inspection);}function x(e){let r=s.get(e.requestId);r&&(i(e.requestId),e.success?r.resolve(void 0):r.reject(new Error(e.error||"Settle failed")),s.delete(e.requestId));}c.onmessage=e=>{let r=e.data;switch(r.type){case "READY":return h();case "STARTED":return O();case "STOPPED":return W();case "DESTROYED":return C();case "FACT_CHANGED":return w(r);case "DERIVATION_CHANGED":return D(r);case "REQUIREMENT_CREATED":return P(r);case "REQUIREMENT_MET":return q(r);case "ERROR":return _(r);case "SNAPSHOT_RESULT":return A(r);case "INSPECT_RESULT":return N(r);case "SETTLE_RESULT":return x(r)}},c.onerror=e=>{let r=e&&typeof e=="object"&&"message"in e?String(e.message??"unknown error"):"unknown error";if(s.size>0){let p=new Error(`[Directive] worker errored: ${r}`);for(let[,E]of s)E.timeoutHandle!==void 0&&clearTimeout(E.timeoutHandle),E.reject(p);s.clear();}n?.(r,"worker");};function l(e){c.postMessage(e);}function m(e,r=t){return new Promise((p,E)=>{let I={resolve:p,reject:E};Number.isFinite(r)&&r>0&&(I.timeoutHandle=setTimeout(()=>{s.has(e.requestId)&&(s.delete(e.requestId),E(new Error(`[Directive] worker request timed out after ${r}ms`)));},r)),s.set(e.requestId,I),l(e);})}return {init(e){return new Promise(r=>{d=r,l({type:"INIT",config:e});})},start(){return new Promise(e=>{S=e,l({type:"START"});})},stop(){return new Promise(e=>{f=e,l({type:"STOP"});})},destroy(){return new Promise(e=>{v=e,l({type:"DESTROY"});})},setFact(e,r){l({type:"SET_FACT",key:e,value:r});},setFacts(e){l({type:"SET_FACTS",facts:e});},dispatch(e){l({type:"DISPATCH",event:e});},getSnapshot(e,r){let p=`snapshot-${++a}`;return m({type:"GET_SNAPSHOT",options:e,requestId:p},r??t)},inspect(e){let r=`inspect-${++a}`;return m({type:"INSPECT",requestId:r},e??t)},settle(e,r){let p=`settle-${++a}`;return m({type:"SETTLE",timeout:e,requestId:p},r??t)},terminate(){c.terminate();}}}var R=null;function b(){return R||(R=new Map),R}function L(o,c){b().set(o,c);}function U(){let o=null;async function c(t){let i=await F(t.config);return postMessage({type:"READY"}),i}function T(t){t.start(),postMessage({type:"STARTED"});}function y(t){t.stop(),postMessage({type:"STOPPED"});}function g(t){t.destroy(),postMessage({type:"DESTROYED"});}function u(t,i){let d=t.getSnapshot(i.options);postMessage({type:"SNAPSHOT_RESULT",requestId:i.requestId,snapshot:d});}function n(t,i){let d=t.inspect();postMessage({type:"INSPECT_RESULT",requestId:i.requestId,inspection:d});}async function s(t,i){try{await t.settle(i.timeout),postMessage({type:"SETTLE_RESULT",requestId:i.requestId,success:!0});}catch(d){postMessage({type:"SETTLE_RESULT",requestId:i.requestId,success:false,error:d instanceof Error?d.message:String(d)});}}async function a(t){if(t.type==="INIT"){o=await c(t);return}if(o)switch(t.type){case "START":T(o);break;case "STOP":y(o);break;case "DESTROY":g(o),o=null;break;case "SET_FACT":o.setFact(t.key,t.value);break;case "SET_FACTS":o.setFacts(t.facts);break;case "DISPATCH":o.dispatch(t.event);break;case "GET_SNAPSHOT":u(o,t);break;case "INSPECT":n(o,t);break;case "SETTLE":await s(o,t);break}}self.onmessage=async t=>{try{await a(t.data);}catch(i){postMessage({type:"ERROR",error:i instanceof Error?i.message:String(i),source:t.data.type});}};}async function F(o){let{createSystem:c}=await import('./system-SJBP4TO5.js'),T=b(),y={};for(let n of o.moduleNames){let s=T.get(n);if(!s)throw new Error(`[Directive Worker] Module "${n}" not registered. Call registerWorkerModule('${n}', module) before handling messages.`);y[n]=s;}let u=c({modules:y,plugins:[{name:"__worker-tracking__",onFactSet:(n,s,a)=>{postMessage({type:"FACT_CHANGED",key:n,value:s,prev:a});},onDerivationCompute:(n,s)=>{postMessage({type:"DERIVATION_CHANGED",key:n,value:s});},onRequirementCreated:n=>{postMessage({type:"REQUIREMENT_CREATED",requirement:{...n.requirement,id:n.id}});},onRequirementMet:(n,s)=>{postMessage({type:"REQUIREMENT_MET",requirementId:n.id,resolverId:s});}}],history:o.history});return {start:()=>u.start(),stop:()=>u.stop(),destroy:()=>u.destroy(),setFact:(n,s)=>{u.facts[n]=s;},setFacts:n=>{let s=u.facts;if(s.$store?.batch)s.$store.batch(()=>{for(let[a,t]of Object.entries(n))s[a]=t;});else for(let[a,t]of Object.entries(n))s[a]=t;},dispatch:n=>{u.dispatch(n);},getSnapshot:n=>u.getDistributableSnapshot(n),inspect:()=>u.inspect(),settle:n=>u.settle(n)}}export{H as createWorkerClient,b as getWorkerModuleRegistry,U as handleWorkerMessages,L as registerWorkerModule};//# sourceMappingURL=worker.js.map
1
+ function H(o){let{worker:c,onFactChange:T,onDerivationChange:y,onRequirementCreated:g,onRequirementMet:u,onError:n}=o,s=new Map,a=0,t=3e4;function i(e){let r=s.get(e);r?.timeoutHandle!==void 0&&clearTimeout(r.timeoutHandle);}let d=null,S=null,f=null,v=null;function k(e){return e?.(),null}function M(e,r){let p=s.get(e);p&&(i(e),p.resolve(r),s.delete(e));}function h(){d=k(d);}function O(){S=k(S);}function W(){f=k(f);}function C(){v=k(v);}function w(e){T?.(e.key,e.value,e.prev);}function D(e){y?.(e.key,e.value);}function P(e){g?.(e.requirement);}function q(e){u?.(e.requirementId,e.resolverId);}function _(e){n?.(e.error,e.source);}function A(e){M(e.requestId,e.snapshot);}function N(e){M(e.requestId,e.inspection);}function x(e){let r=s.get(e.requestId);r&&(i(e.requestId),e.success?r.resolve(void 0):r.reject(new Error(e.error||"Settle failed")),s.delete(e.requestId));}c.onmessage=e=>{let r=e.data;switch(r.type){case "READY":return h();case "STARTED":return O();case "STOPPED":return W();case "DESTROYED":return C();case "FACT_CHANGED":return w(r);case "DERIVATION_CHANGED":return D(r);case "REQUIREMENT_CREATED":return P(r);case "REQUIREMENT_MET":return q(r);case "ERROR":return _(r);case "SNAPSHOT_RESULT":return A(r);case "INSPECT_RESULT":return N(r);case "SETTLE_RESULT":return x(r)}},c.onerror=e=>{let r=e&&typeof e=="object"&&"message"in e?String(e.message??"unknown error"):"unknown error";if(s.size>0){let p=new Error(`[Directive] worker errored: ${r}`);for(let[,E]of s)E.timeoutHandle!==void 0&&clearTimeout(E.timeoutHandle),E.reject(p);s.clear();}n?.(r,"worker");};function l(e){c.postMessage(e);}function m(e,r=t){return new Promise((p,E)=>{let I={resolve:p,reject:E};Number.isFinite(r)&&r>0&&(I.timeoutHandle=setTimeout(()=>{s.has(e.requestId)&&(s.delete(e.requestId),E(new Error(`[Directive] worker request timed out after ${r}ms`)));},r)),s.set(e.requestId,I),l(e);})}return {init(e){return new Promise(r=>{d=r,l({type:"INIT",config:e});})},start(){return new Promise(e=>{S=e,l({type:"START"});})},stop(){return new Promise(e=>{f=e,l({type:"STOP"});})},destroy(){return new Promise(e=>{v=e,l({type:"DESTROY"});})},setFact(e,r){l({type:"SET_FACT",key:e,value:r});},setFacts(e){l({type:"SET_FACTS",facts:e});},dispatch(e){l({type:"DISPATCH",event:e});},getSnapshot(e,r){let p=`snapshot-${++a}`;return m({type:"GET_SNAPSHOT",options:e,requestId:p},r??t)},inspect(e){let r=`inspect-${++a}`;return m({type:"INSPECT",requestId:r},e??t)},settle(e,r){let p=`settle-${++a}`;return m({type:"SETTLE",timeout:e,requestId:p},r??t)},terminate(){c.terminate();}}}var R=null;function b(){return R||(R=new Map),R}function L(o,c){b().set(o,c);}function U(){let o=null;async function c(t){let i=await F(t.config);return postMessage({type:"READY"}),i}function T(t){t.start(),postMessage({type:"STARTED"});}function y(t){t.stop(),postMessage({type:"STOPPED"});}function g(t){t.destroy(),postMessage({type:"DESTROYED"});}function u(t,i){let d=t.getSnapshot(i.options);postMessage({type:"SNAPSHOT_RESULT",requestId:i.requestId,snapshot:d});}function n(t,i){let d=t.inspect();postMessage({type:"INSPECT_RESULT",requestId:i.requestId,inspection:d});}async function s(t,i){try{await t.settle(i.timeout),postMessage({type:"SETTLE_RESULT",requestId:i.requestId,success:!0});}catch(d){postMessage({type:"SETTLE_RESULT",requestId:i.requestId,success:false,error:d instanceof Error?d.message:String(d)});}}async function a(t){if(t.type==="INIT"){o=await c(t);return}if(o)switch(t.type){case "START":T(o);break;case "STOP":y(o);break;case "DESTROY":g(o),o=null;break;case "SET_FACT":o.setFact(t.key,t.value);break;case "SET_FACTS":o.setFacts(t.facts);break;case "DISPATCH":o.dispatch(t.event);break;case "GET_SNAPSHOT":u(o,t);break;case "INSPECT":n(o,t);break;case "SETTLE":await s(o,t);break}}self.onmessage=async t=>{try{await a(t.data);}catch(i){postMessage({type:"ERROR",error:i instanceof Error?i.message:String(i),source:t.data.type});}};}async function F(o){let{createSystem:c}=await import('./system-6YWCXQOQ.js'),T=b(),y={};for(let n of o.moduleNames){let s=T.get(n);if(!s)throw new Error(`[Directive Worker] Module "${n}" not registered. Call registerWorkerModule('${n}', module) before handling messages.`);y[n]=s;}let u=c({modules:y,plugins:[{name:"__worker-tracking__",onFactSet:(n,s,a)=>{postMessage({type:"FACT_CHANGED",key:n,value:s,prev:a});},onDerivationCompute:(n,s)=>{postMessage({type:"DERIVATION_CHANGED",key:n,value:s});},onRequirementCreated:n=>{postMessage({type:"REQUIREMENT_CREATED",requirement:{...n.requirement,id:n.id}});},onRequirementMet:(n,s)=>{postMessage({type:"REQUIREMENT_MET",requirementId:n.id,resolverId:s});}}],history:o.history});return {start:()=>u.start(),stop:()=>u.stop(),destroy:()=>u.destroy(),setFact:(n,s)=>{u.facts[n]=s;},setFacts:n=>{let s=u.facts;if(s.$store?.batch)s.$store.batch(()=>{for(let[a,t]of Object.entries(n))s[a]=t;});else for(let[a,t]of Object.entries(n))s[a]=t;},dispatch:n=>{u.dispatch(n);},getSnapshot:n=>u.getDistributableSnapshot(n),inspect:()=>u.inspect(),settle:n=>u.settle(n)}}export{H as createWorkerClient,b as getWorkerModuleRegistry,U as handleWorkerMessages,L as registerWorkerModule};//# sourceMappingURL=worker.js.map
2
2
  //# sourceMappingURL=worker.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@directive-run/core",
3
- "version": "1.21.0",
3
+ "version": "1.22.0",
4
4
  "imports": {
5
5
  "#is-development": {
6
6
  "production": "./src/dev-false.ts",