@directive-run/core 0.4.1 → 0.5.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.
@@ -730,13 +730,15 @@ interface NamespacedSystem<Modules extends ModulesMap> {
730
730
  /** Time-travel debugging API (if enabled) */
731
731
  readonly debug: TimeTravelAPI | null;
732
732
  /** Namespaced derivations accessor: system.derive.auth.status */
733
- readonly derive: NamespacedDerivations<Modules>;
733
+ readonly derive: NamespacedDerivations<Modules> & DerivationsControl;
734
734
  /** Events accessor (union of all module events) */
735
735
  readonly events: NamespacedEventsAccessor<Modules>;
736
- /** Runtime control for constraints (disable/enable/isDisabled) */
736
+ /** Runtime control for constraints (disable/enable/isDisabled + dynamic CRUD) */
737
737
  readonly constraints: ConstraintsControl;
738
- /** Runtime control for effects (disable/enable/isEnabled) */
738
+ /** Runtime control for effects (disable/enable/isEnabled + dynamic CRUD) */
739
739
  readonly effects: EffectsControl;
740
+ /** Runtime control for resolvers (dynamic CRUD) */
741
+ readonly resolvers: ResolversControl;
740
742
  /** Per-run changelog entries (null if debug.runHistory is not enabled) */
741
743
  readonly runHistory: RunChangelogEntry[] | null;
742
744
  /** Initialize facts and derivations without starting reconciliation. Safe for SSR. */
@@ -957,13 +959,15 @@ interface SingleModuleSystem<S extends ModuleSchema> {
957
959
  /** Time-travel debugging API (if enabled) */
958
960
  readonly debug: TimeTravelAPI | null;
959
961
  /** Direct derivations accessor: system.derive.doubled */
960
- readonly derive: InferDerivations<S>;
962
+ readonly derive: InferDerivations<S> & DerivationsControl;
961
963
  /** Direct events accessor: system.events.increment() */
962
964
  readonly events: SingleModuleEvents<S>;
963
965
  /** Runtime control for constraints (disable/enable/isDisabled) */
964
966
  readonly constraints: ConstraintsControl;
965
967
  /** Runtime control for effects (disable/enable/isEnabled) */
966
968
  readonly effects: EffectsControl;
969
+ /** Runtime control for resolvers (register/assign/unregister/call) */
970
+ readonly resolvers: ResolversControl;
967
971
  /** Per-run changelog entries (null if debug.runHistory is not enabled) */
968
972
  readonly runHistory: RunChangelogEntry[] | null;
969
973
  /** Initialize facts and derivations without starting reconciliation. Safe for SSR. */
@@ -1165,7 +1169,7 @@ type GetRequirementsSchema<M extends ModuleSchema> = M["requirements"] extends R
1165
1169
  * The derive accessor is typed from schema.derivations.
1166
1170
  * Supports both t.*() builders and type assertion {} as {} patterns.
1167
1171
  */
1168
- type TypedDerivationFn<M extends ModuleSchema, K extends keyof GetDerivationsSchema<M>> = (facts: Facts<M["facts"]>, derive: InferDerivations<M>) => InferSchemaType<GetDerivationsSchema<M>[K]>;
1172
+ type TypedDerivationFn<M extends ModuleSchema, K extends keyof GetDerivationsSchema<M>> = (facts: Facts<M["facts"]>, derived: InferDerivations<M>) => InferSchemaType<GetDerivationsSchema<M>[K]>;
1169
1173
  /**
1170
1174
  * Typed derivations definition using the module schema.
1171
1175
  * Each derivation key must match schema.derivations and return the declared type.
@@ -1286,7 +1290,7 @@ type CrossModuleEffectsDef<M extends ModuleSchema, Deps extends CrossModuleDeps>
1286
1290
  * - `facts.self.*` for own module's facts
1287
1291
  * - `facts.{dep}.*` for cross-module facts (read-only)
1288
1292
  */
1289
- type CrossModuleDerivationFn<M extends ModuleSchema, Deps extends CrossModuleDeps, K extends keyof GetDerivationsSchema<M>> = (facts: CrossModuleFactsWithSelf<M, Deps>, derive: InferDerivations<M>) => InferSchemaType<GetDerivationsSchema<M>[K]>;
1293
+ type CrossModuleDerivationFn<M extends ModuleSchema, Deps extends CrossModuleDeps, K extends keyof GetDerivationsSchema<M>> = (facts: CrossModuleFactsWithSelf<M, Deps>, derived: InferDerivations<M>) => InferSchemaType<GetDerivationsSchema<M>[K]>;
1290
1294
  /**
1291
1295
  * Cross-module derivations definition.
1292
1296
  */
@@ -1635,6 +1639,36 @@ interface ConstraintsControl {
1635
1639
  enable(id: string): void;
1636
1640
  /** Check if a constraint is currently disabled */
1637
1641
  isDisabled(id: string): boolean;
1642
+ /**
1643
+ * Register a new constraint at runtime.
1644
+ * @throws If a constraint with this ID already exists (use `assign` to override)
1645
+ * @remarks During reconciliation, the registration is deferred and applied after the current cycle completes.
1646
+ */
1647
+ register(id: string, def: Record<string, unknown>): void;
1648
+ /**
1649
+ * Override an existing constraint (static or dynamic).
1650
+ * Stores the original definition for potential inspection.
1651
+ * @throws If no constraint with this ID exists (use `register` to create)
1652
+ * @remarks During reconciliation, the assignment is deferred and applied after the current cycle completes.
1653
+ */
1654
+ assign(id: string, def: Record<string, unknown>): void;
1655
+ /**
1656
+ * Remove a dynamically registered constraint.
1657
+ * Static (module-defined) constraints cannot be unregistered — logs a dev warning and no-ops.
1658
+ * @remarks During reconciliation, the unregistration is deferred and applied after the current cycle completes.
1659
+ */
1660
+ unregister(id: string): void;
1661
+ /**
1662
+ * Invoke a constraint's `when()` predicate. If true, evaluates its `require()` and returns the requirements
1663
+ * (with optional props merged). The requirements are returned for inspection but NOT automatically dispatched
1664
+ * to the resolver system.
1665
+ * @throws If no constraint with this ID exists
1666
+ */
1667
+ call(id: string, props?: Record<string, unknown>): Promise<Record<string, unknown>[]>;
1668
+ /** Check if a constraint was dynamically registered (not from a module definition) */
1669
+ isDynamic(id: string): boolean;
1670
+ /** List all dynamically registered constraint IDs */
1671
+ listDynamic(): string[];
1638
1672
  }
1639
1673
  /** Runtime control for effects */
1640
1674
  interface EffectsControl {
@@ -1644,14 +1678,107 @@ interface EffectsControl {
1644
1678
  enable(id: string): void;
1645
1679
  /** Check if an effect is currently enabled */
1646
1680
  isEnabled(id: string): boolean;
1681
+ /**
1682
+ * Register a new effect at runtime.
1683
+ * @throws If an effect with this ID already exists (use `assign` to override)
1684
+ * @remarks During reconciliation, the registration is deferred and applied after the current cycle completes.
1685
+ */
1686
+ register(id: string, def: Record<string, unknown>): void;
1687
+ /**
1688
+ * Override an existing effect (static or dynamic).
1689
+ * Runs cleanup of the old effect before replacing.
1690
+ * @throws If no effect with this ID exists (use `register` to create)
1691
+ * @remarks During reconciliation, the assignment is deferred and applied after the current cycle completes.
1692
+ */
1693
+ assign(id: string, def: Record<string, unknown>): void;
1694
+ /**
1695
+ * Remove a dynamically registered effect.
1696
+ * Static (module-defined) effects cannot be unregistered — logs a dev warning and no-ops.
1697
+ * @remarks During reconciliation, the unregistration is deferred and applied after the current cycle completes.
1698
+ */
1699
+ unregister(id: string): void;
1700
+ /**
1701
+ * Execute an effect's `run()` function immediately.
1702
+ * @throws If no effect with this ID exists
1703
+ */
1704
+ call(id: string): Promise<void>;
1705
+ /** Check if an effect was dynamically registered (not from a module definition) */
1706
+ isDynamic(id: string): boolean;
1707
+ /** List all dynamically registered effect IDs */
1708
+ listDynamic(): string[];
1709
+ }
1710
+ /** Runtime control for derivations (dynamic registration + value access) */
1711
+ interface DerivationsControl {
1712
+ /**
1713
+ * Register a new derivation at runtime.
1714
+ * @throws If a derivation with this ID already exists (use `assign` to override)
1715
+ * @remarks During reconciliation, the registration is deferred and applied after the current cycle completes.
1716
+ */
1717
+ register(id: string, fn: (facts: Record<string, unknown>, derive: Record<string, unknown>) => unknown): void;
1718
+ /**
1719
+ * Override an existing derivation (static or dynamic).
1720
+ * @throws If no derivation with this ID exists (use `register` to create)
1721
+ * @remarks During reconciliation, the assignment is deferred and applied after the current cycle completes.
1722
+ */
1723
+ assign(id: string, fn: (facts: Record<string, unknown>, derive: Record<string, unknown>) => unknown): void;
1724
+ /**
1725
+ * Remove a dynamically registered derivation.
1726
+ * Static (module-defined) derivations cannot be unregistered — logs a dev warning and no-ops.
1727
+ * @remarks During reconciliation, the unregistration is deferred and applied after the current cycle completes.
1728
+ */
1729
+ unregister(id: string): void;
1730
+ /**
1731
+ * Recompute and return a derivation's current value.
1732
+ * @throws If no derivation with this ID exists
1733
+ */
1734
+ call(id: string): unknown;
1735
+ /** Check if a derivation was dynamically registered (not from a module definition) */
1736
+ isDynamic(id: string): boolean;
1737
+ /** List all dynamically registered derivation IDs */
1738
+ listDynamic(): string[];
1739
+ }
1740
+ /** Runtime control for resolvers */
1741
+ interface ResolversControl {
1742
+ /**
1743
+ * Register a new resolver at runtime.
1744
+ * @throws If a resolver with this ID already exists (use `assign` to override)
1745
+ * @remarks During reconciliation, the registration is deferred and applied after the current cycle completes.
1746
+ */
1747
+ register(id: string, def: Record<string, unknown>): void;
1748
+ /**
1749
+ * Override an existing resolver (static or dynamic).
1750
+ * Clears the resolver-by-type cache.
1751
+ * @throws If no resolver with this ID exists (use `register` to create)
1752
+ * @remarks During reconciliation, the assignment is deferred and applied after the current cycle completes.
1753
+ */
1754
+ assign(id: string, def: Record<string, unknown>): void;
1755
+ /**
1756
+ * Remove a dynamically registered resolver.
1757
+ * Static (module-defined) resolvers cannot be unregistered — logs a dev warning and no-ops.
1758
+ * @remarks During reconciliation, the unregistration is deferred and applied after the current cycle completes.
1759
+ */
1760
+ unregister(id: string): void;
1761
+ /**
1762
+ * Execute a resolver's `resolve()` with a requirement object.
1763
+ * @throws If no resolver with this ID exists
1764
+ */
1765
+ call(id: string, requirement: {
1766
+ type: string;
1767
+ [key: string]: unknown;
1768
+ }): Promise<void>;
1769
+ /** Check if a resolver was dynamically registered (not from a module definition) */
1770
+ isDynamic(id: string): boolean;
1771
+ /** List all dynamically registered resolver IDs */
1772
+ listDynamic(): string[];
1647
1773
  }
1648
1774
  interface System<M extends ModuleSchema = ModuleSchema> {
1649
1775
  readonly facts: Facts<M["facts"]>;
1650
1776
  readonly debug: TimeTravelAPI | null;
1651
- readonly derive: InferDerivations<M>;
1777
+ readonly derive: InferDerivations<M> & DerivationsControl;
1652
1778
  readonly events: EventsAccessorFromSchema<M>;
1653
1779
  readonly constraints: ConstraintsControl;
1654
1780
  readonly effects: EffectsControl;
1781
+ readonly resolvers: ResolversControl;
1655
1782
  /** Per-run changelog entries (null if debug.runHistory is not enabled) */
1656
1783
  readonly runHistory: RunChangelogEntry[] | null;
1657
1784
  /** Initialize facts and derivations without starting reconciliation. Safe for SSR. */
@@ -1682,8 +1809,9 @@ interface System<M extends ModuleSchema = ModuleSchema> {
1682
1809
  * Returns an unsubscribe function.
1683
1810
  */
1684
1811
  onTimeTravelChange(listener: () => void): () => void;
1685
- read<K extends DerivationKeys<M>>(derivationId: K): DerivationReturnType<M, K>;
1686
- read<T = unknown>(derivationId: string): T;
1812
+ read<K extends DerivationKeys<M>>(id: K): DerivationReturnType<M, K>;
1813
+ read<K extends FactKeys<M>>(id: K): FactReturnType<M, K>;
1814
+ read<T = unknown>(id: string): T;
1687
1815
  /**
1688
1816
  * Subscribe to fact or derivation changes.
1689
1817
  * Keys are auto-detected -- pass any mix of fact keys and derivation keys.
@@ -1724,6 +1852,17 @@ interface System<M extends ModuleSchema = ModuleSchema> {
1724
1852
  explain(requirementId: string): string | null;
1725
1853
  getSnapshot(): SystemSnapshot;
1726
1854
  restore(snapshot: SystemSnapshot): void;
1855
+ /**
1856
+ * Get the original definition that was overridden by `assign()`.
1857
+ * Returns undefined if no original exists for this type/id.
1858
+ */
1859
+ getOriginal(type: "constraint" | "resolver" | "derivation" | "effect", id: string): unknown | undefined;
1860
+ /**
1861
+ * Restore the original definition that was overridden by `assign()`.
1862
+ * Re-assigns the original definition and removes the override tracking.
1863
+ * Returns true if restoration succeeded, false if no original exists.
1864
+ */
1865
+ restoreOriginal(type: "constraint" | "resolver" | "derivation" | "effect", id: string): boolean;
1727
1866
  /**
1728
1867
  * Get a distributable snapshot of computed derivations.
1729
1868
  * This creates a serializable object that can be stored in Redis, JWT, etc.
@@ -1974,6 +2113,34 @@ interface Plugin<M extends ModuleSchema = ModuleSchema> {
1974
2113
  * @param strategy - The recovery strategy used
1975
2114
  */
1976
2115
  onErrorRecovery?: (error: DirectiveError, strategy: RecoveryStrategy) => void;
2116
+ /**
2117
+ * Called when a definition is dynamically registered at runtime.
2118
+ * @param type - The definition type: "constraint", "resolver", "derivation", or "effect"
2119
+ * @param id - The definition ID
2120
+ * @param def - The definition object
2121
+ */
2122
+ onDefinitionRegister?: (type: string, id: string, def: unknown) => void;
2123
+ /**
2124
+ * Called when a definition is assigned (overridden) at runtime.
2125
+ * @param type - The definition type: "constraint", "resolver", "derivation", or "effect"
2126
+ * @param id - The definition ID
2127
+ * @param def - The new definition object
2128
+ * @param original - The previous definition that was overridden
2129
+ */
2130
+ onDefinitionAssign?: (type: string, id: string, def: unknown, original: unknown) => void;
2131
+ /**
2132
+ * Called when a dynamically registered definition is removed.
2133
+ * @param type - The definition type: "constraint", "resolver", "derivation", or "effect"
2134
+ * @param id - The definition ID
2135
+ */
2136
+ onDefinitionUnregister?: (type: string, id: string) => void;
2137
+ /**
2138
+ * Called when a definition is manually invoked via `call()`.
2139
+ * @param type - The definition type: "constraint", "resolver", "derivation", or "effect"
2140
+ * @param id - The definition ID
2141
+ * @param props - Optional props passed to the call
2142
+ */
2143
+ onDefinitionCall?: (type: string, id: string, props?: unknown) => void;
1977
2144
  /**
1978
2145
  * Called when a run finalizes (all resolvers settled or no resolvers started).
1979
2146
  * Only fires when debug.runHistory is enabled.
@@ -1982,4 +2149,4 @@ interface Plugin<M extends ModuleSchema = ModuleSchema> {
1982
2149
  onRunComplete?: (run: RunChangelogEntry) => void;
1983
2150
  }
1984
2151
 
1985
- export { type AnySystem as $, type ConstraintState as A, type BatchConfig as B, type CrossModuleDeps as C, type DerivationsSchema as D, type EffectsDef as E, type Facts as F, type ResolversDef as G, type ResolverStatus as H, type InferRequirements as I, type System as J, type FactChange as K, type FactsSnapshot as L, type ModuleSchema as M, type NamespacedSystem as N, type ReconcileResult as O, type Plugin as P, type Snapshot as Q, type Requirement as R, type Schema as S, type TypedDerivationsDef as T, DirectiveError as U, type RecoveryStrategy as V, type RunChangelogEntry as W, type ErrorSource as X, type RetryLaterConfig as Y, type TimeTravelAPI as Z, type SystemConfig as _, type RequirementOutput$1 as a, type BatchItemResult as a0, type BatchResolveResults as a1, type CrossModuleConstraintDef as a2, type CrossModuleDerivationFn as a3, type CrossModuleEffectDef as a4, type CrossModuleFactsWithSelf as a5, type DerivationKeys as a6, type DerivationReturnType as a7, type DeriveAccessor as a8, type DispatchEventsFromSchema as a9, type RequirementsSchema as aA, type SnapshotMeta as aB, type SystemEvent as aC, type SystemInspection as aD, type SystemMode as aE, type SystemSnapshot as aF, type TimeTravelState as aG, type TypedResolverContext as aH, type TypedResolverDef as aI, type UnionEvents as aJ, isNamespacedSystem as aK, isSingleModuleSystem as aL, type DistributableSnapshot as aa, type DistributableSnapshotOptions as ab, type EffectCleanup as ac, type EventPayloadSchema as ad, type EventsAccessor as ae, type EventsAccessorFromSchema as af, type EventsDef as ag, type EventsSchema as ah, type FactKeys as ai, type FactReturnType as aj, type FlexibleEventHandler as ak, type InferDerivations as al, type InferEventPayloadFromSchema as am, type InferEvents as an, type InferRequirementPayloadFromSchema as ao, type InferRequirementTypes as ap, type InferSchema as aq, type InferSchemaType as ar, type InferSelectorState as as, type MutableNamespacedFacts as at, type NamespacedDerivations as au, type NamespacedEventsAccessor as av, type NamespacedFacts as aw, type ObservableKeys as ax, type RequirementExplanation as ay, type RequirementPayloadSchema$1 as az, type RetryPolicy as b, type ResolverContext as c, type SchemaType as d, type FactsStore as e, type TypedEventsDef as f, type TypedConstraintsDef as g, type TypedResolversDef as h, type ModuleHooks as i, type CrossModuleDerivationsDef as j, type CrossModuleEffectsDef as k, type CrossModuleConstraintsDef as l, type ModuleDef as m, type CreateSystemOptionsSingle as n, type SingleModuleSystem as o, type ModulesMap as p, type CreateSystemOptionsNamed as q, type TypedConstraintDef as r, type RequirementOutput as s, type DebugConfig as t, type ErrorBoundaryConfig as u, type InferFacts as v, type ExtractSchema as w, type RequirementWithId as x, type RequirementKeyFn as y, type ConstraintsDef as z };
2152
+ export { type AnySystem as $, type ConstraintState as A, type BatchConfig as B, type CrossModuleDeps as C, type DerivationsSchema as D, type EffectsDef as E, type Facts as F, type ResolversDef as G, type ResolverStatus as H, type InferRequirements as I, type System as J, type FactChange as K, type FactsSnapshot as L, type ModuleSchema as M, type NamespacedSystem as N, type ReconcileResult as O, type Plugin as P, type Snapshot as Q, type Requirement as R, type Schema as S, type TypedDerivationsDef as T, DirectiveError as U, type RecoveryStrategy as V, type RunChangelogEntry as W, type ErrorSource as X, type RetryLaterConfig as Y, type TimeTravelAPI as Z, type SystemConfig as _, type RequirementOutput$1 as a, type BatchItemResult as a0, type BatchResolveResults as a1, type ConstraintsControl as a2, type CrossModuleConstraintDef as a3, type CrossModuleDerivationFn as a4, type CrossModuleEffectDef as a5, type CrossModuleFactsWithSelf as a6, type DerivationKeys as a7, type DerivationReturnType as a8, type DerivationsControl as a9, type ObservableKeys as aA, type RequirementExplanation as aB, type RequirementPayloadSchema$1 as aC, type RequirementsSchema as aD, type ResolversControl as aE, type SnapshotMeta as aF, type SystemEvent as aG, type SystemInspection as aH, type SystemMode as aI, type SystemSnapshot as aJ, type TimeTravelState as aK, type TypedResolverContext as aL, type TypedResolverDef as aM, type UnionEvents as aN, isNamespacedSystem as aO, isSingleModuleSystem as aP, type DeriveAccessor as aa, type DispatchEventsFromSchema as ab, type DistributableSnapshot as ac, type DistributableSnapshotOptions as ad, type EffectCleanup as ae, type EffectsControl as af, type EventPayloadSchema as ag, type EventsAccessor as ah, type EventsAccessorFromSchema as ai, type EventsDef as aj, type EventsSchema as ak, type FactKeys as al, type FactReturnType as am, type FlexibleEventHandler as an, type InferDerivations as ao, type InferEventPayloadFromSchema as ap, type InferEvents as aq, type InferRequirementPayloadFromSchema as ar, type InferRequirementTypes as as, type InferSchema as at, type InferSchemaType as au, type InferSelectorState as av, type MutableNamespacedFacts as aw, type NamespacedDerivations as ax, type NamespacedEventsAccessor as ay, type NamespacedFacts as az, type RetryPolicy as b, type ResolverContext as c, type SchemaType as d, type TypedEventsDef as e, type TypedConstraintsDef as f, type TypedResolversDef as g, type ModuleHooks as h, type CrossModuleDerivationsDef as i, type CrossModuleEffectsDef as j, type CrossModuleConstraintsDef as k, type ModuleDef as l, type CreateSystemOptionsSingle as m, type SingleModuleSystem as n, type ModulesMap as o, type CreateSystemOptionsNamed as p, type TypedConstraintDef as q, type RequirementOutput as r, type DebugConfig as s, type ErrorBoundaryConfig as t, type InferFacts as u, type ExtractSchema as v, type RequirementWithId as w, type RequirementKeyFn as x, type FactsStore as y, type ConstraintsDef as z };
@@ -730,13 +730,15 @@ interface NamespacedSystem<Modules extends ModulesMap> {
730
730
  /** Time-travel debugging API (if enabled) */
731
731
  readonly debug: TimeTravelAPI | null;
732
732
  /** Namespaced derivations accessor: system.derive.auth.status */
733
- readonly derive: NamespacedDerivations<Modules>;
733
+ readonly derive: NamespacedDerivations<Modules> & DerivationsControl;
734
734
  /** Events accessor (union of all module events) */
735
735
  readonly events: NamespacedEventsAccessor<Modules>;
736
- /** Runtime control for constraints (disable/enable/isDisabled) */
736
+ /** Runtime control for constraints (disable/enable/isDisabled + dynamic CRUD) */
737
737
  readonly constraints: ConstraintsControl;
738
- /** Runtime control for effects (disable/enable/isEnabled) */
738
+ /** Runtime control for effects (disable/enable/isEnabled + dynamic CRUD) */
739
739
  readonly effects: EffectsControl;
740
+ /** Runtime control for resolvers (dynamic CRUD) */
741
+ readonly resolvers: ResolversControl;
740
742
  /** Per-run changelog entries (null if debug.runHistory is not enabled) */
741
743
  readonly runHistory: RunChangelogEntry[] | null;
742
744
  /** Initialize facts and derivations without starting reconciliation. Safe for SSR. */
@@ -957,13 +959,15 @@ interface SingleModuleSystem<S extends ModuleSchema> {
957
959
  /** Time-travel debugging API (if enabled) */
958
960
  readonly debug: TimeTravelAPI | null;
959
961
  /** Direct derivations accessor: system.derive.doubled */
960
- readonly derive: InferDerivations<S>;
962
+ readonly derive: InferDerivations<S> & DerivationsControl;
961
963
  /** Direct events accessor: system.events.increment() */
962
964
  readonly events: SingleModuleEvents<S>;
963
965
  /** Runtime control for constraints (disable/enable/isDisabled) */
964
966
  readonly constraints: ConstraintsControl;
965
967
  /** Runtime control for effects (disable/enable/isEnabled) */
966
968
  readonly effects: EffectsControl;
969
+ /** Runtime control for resolvers (register/assign/unregister/call) */
970
+ readonly resolvers: ResolversControl;
967
971
  /** Per-run changelog entries (null if debug.runHistory is not enabled) */
968
972
  readonly runHistory: RunChangelogEntry[] | null;
969
973
  /** Initialize facts and derivations without starting reconciliation. Safe for SSR. */
@@ -1165,7 +1169,7 @@ type GetRequirementsSchema<M extends ModuleSchema> = M["requirements"] extends R
1165
1169
  * The derive accessor is typed from schema.derivations.
1166
1170
  * Supports both t.*() builders and type assertion {} as {} patterns.
1167
1171
  */
1168
- type TypedDerivationFn<M extends ModuleSchema, K extends keyof GetDerivationsSchema<M>> = (facts: Facts<M["facts"]>, derive: InferDerivations<M>) => InferSchemaType<GetDerivationsSchema<M>[K]>;
1172
+ type TypedDerivationFn<M extends ModuleSchema, K extends keyof GetDerivationsSchema<M>> = (facts: Facts<M["facts"]>, derived: InferDerivations<M>) => InferSchemaType<GetDerivationsSchema<M>[K]>;
1169
1173
  /**
1170
1174
  * Typed derivations definition using the module schema.
1171
1175
  * Each derivation key must match schema.derivations and return the declared type.
@@ -1286,7 +1290,7 @@ type CrossModuleEffectsDef<M extends ModuleSchema, Deps extends CrossModuleDeps>
1286
1290
  * - `facts.self.*` for own module's facts
1287
1291
  * - `facts.{dep}.*` for cross-module facts (read-only)
1288
1292
  */
1289
- type CrossModuleDerivationFn<M extends ModuleSchema, Deps extends CrossModuleDeps, K extends keyof GetDerivationsSchema<M>> = (facts: CrossModuleFactsWithSelf<M, Deps>, derive: InferDerivations<M>) => InferSchemaType<GetDerivationsSchema<M>[K]>;
1293
+ type CrossModuleDerivationFn<M extends ModuleSchema, Deps extends CrossModuleDeps, K extends keyof GetDerivationsSchema<M>> = (facts: CrossModuleFactsWithSelf<M, Deps>, derived: InferDerivations<M>) => InferSchemaType<GetDerivationsSchema<M>[K]>;
1290
1294
  /**
1291
1295
  * Cross-module derivations definition.
1292
1296
  */
@@ -1635,6 +1639,36 @@ interface ConstraintsControl {
1635
1639
  enable(id: string): void;
1636
1640
  /** Check if a constraint is currently disabled */
1637
1641
  isDisabled(id: string): boolean;
1642
+ /**
1643
+ * Register a new constraint at runtime.
1644
+ * @throws If a constraint with this ID already exists (use `assign` to override)
1645
+ * @remarks During reconciliation, the registration is deferred and applied after the current cycle completes.
1646
+ */
1647
+ register(id: string, def: Record<string, unknown>): void;
1648
+ /**
1649
+ * Override an existing constraint (static or dynamic).
1650
+ * Stores the original definition for potential inspection.
1651
+ * @throws If no constraint with this ID exists (use `register` to create)
1652
+ * @remarks During reconciliation, the assignment is deferred and applied after the current cycle completes.
1653
+ */
1654
+ assign(id: string, def: Record<string, unknown>): void;
1655
+ /**
1656
+ * Remove a dynamically registered constraint.
1657
+ * Static (module-defined) constraints cannot be unregistered — logs a dev warning and no-ops.
1658
+ * @remarks During reconciliation, the unregistration is deferred and applied after the current cycle completes.
1659
+ */
1660
+ unregister(id: string): void;
1661
+ /**
1662
+ * Invoke a constraint's `when()` predicate. If true, evaluates its `require()` and returns the requirements
1663
+ * (with optional props merged). The requirements are returned for inspection but NOT automatically dispatched
1664
+ * to the resolver system.
1665
+ * @throws If no constraint with this ID exists
1666
+ */
1667
+ call(id: string, props?: Record<string, unknown>): Promise<Record<string, unknown>[]>;
1668
+ /** Check if a constraint was dynamically registered (not from a module definition) */
1669
+ isDynamic(id: string): boolean;
1670
+ /** List all dynamically registered constraint IDs */
1671
+ listDynamic(): string[];
1638
1672
  }
1639
1673
  /** Runtime control for effects */
1640
1674
  interface EffectsControl {
@@ -1644,14 +1678,107 @@ interface EffectsControl {
1644
1678
  enable(id: string): void;
1645
1679
  /** Check if an effect is currently enabled */
1646
1680
  isEnabled(id: string): boolean;
1681
+ /**
1682
+ * Register a new effect at runtime.
1683
+ * @throws If an effect with this ID already exists (use `assign` to override)
1684
+ * @remarks During reconciliation, the registration is deferred and applied after the current cycle completes.
1685
+ */
1686
+ register(id: string, def: Record<string, unknown>): void;
1687
+ /**
1688
+ * Override an existing effect (static or dynamic).
1689
+ * Runs cleanup of the old effect before replacing.
1690
+ * @throws If no effect with this ID exists (use `register` to create)
1691
+ * @remarks During reconciliation, the assignment is deferred and applied after the current cycle completes.
1692
+ */
1693
+ assign(id: string, def: Record<string, unknown>): void;
1694
+ /**
1695
+ * Remove a dynamically registered effect.
1696
+ * Static (module-defined) effects cannot be unregistered — logs a dev warning and no-ops.
1697
+ * @remarks During reconciliation, the unregistration is deferred and applied after the current cycle completes.
1698
+ */
1699
+ unregister(id: string): void;
1700
+ /**
1701
+ * Execute an effect's `run()` function immediately.
1702
+ * @throws If no effect with this ID exists
1703
+ */
1704
+ call(id: string): Promise<void>;
1705
+ /** Check if an effect was dynamically registered (not from a module definition) */
1706
+ isDynamic(id: string): boolean;
1707
+ /** List all dynamically registered effect IDs */
1708
+ listDynamic(): string[];
1709
+ }
1710
+ /** Runtime control for derivations (dynamic registration + value access) */
1711
+ interface DerivationsControl {
1712
+ /**
1713
+ * Register a new derivation at runtime.
1714
+ * @throws If a derivation with this ID already exists (use `assign` to override)
1715
+ * @remarks During reconciliation, the registration is deferred and applied after the current cycle completes.
1716
+ */
1717
+ register(id: string, fn: (facts: Record<string, unknown>, derive: Record<string, unknown>) => unknown): void;
1718
+ /**
1719
+ * Override an existing derivation (static or dynamic).
1720
+ * @throws If no derivation with this ID exists (use `register` to create)
1721
+ * @remarks During reconciliation, the assignment is deferred and applied after the current cycle completes.
1722
+ */
1723
+ assign(id: string, fn: (facts: Record<string, unknown>, derive: Record<string, unknown>) => unknown): void;
1724
+ /**
1725
+ * Remove a dynamically registered derivation.
1726
+ * Static (module-defined) derivations cannot be unregistered — logs a dev warning and no-ops.
1727
+ * @remarks During reconciliation, the unregistration is deferred and applied after the current cycle completes.
1728
+ */
1729
+ unregister(id: string): void;
1730
+ /**
1731
+ * Recompute and return a derivation's current value.
1732
+ * @throws If no derivation with this ID exists
1733
+ */
1734
+ call(id: string): unknown;
1735
+ /** Check if a derivation was dynamically registered (not from a module definition) */
1736
+ isDynamic(id: string): boolean;
1737
+ /** List all dynamically registered derivation IDs */
1738
+ listDynamic(): string[];
1739
+ }
1740
+ /** Runtime control for resolvers */
1741
+ interface ResolversControl {
1742
+ /**
1743
+ * Register a new resolver at runtime.
1744
+ * @throws If a resolver with this ID already exists (use `assign` to override)
1745
+ * @remarks During reconciliation, the registration is deferred and applied after the current cycle completes.
1746
+ */
1747
+ register(id: string, def: Record<string, unknown>): void;
1748
+ /**
1749
+ * Override an existing resolver (static or dynamic).
1750
+ * Clears the resolver-by-type cache.
1751
+ * @throws If no resolver with this ID exists (use `register` to create)
1752
+ * @remarks During reconciliation, the assignment is deferred and applied after the current cycle completes.
1753
+ */
1754
+ assign(id: string, def: Record<string, unknown>): void;
1755
+ /**
1756
+ * Remove a dynamically registered resolver.
1757
+ * Static (module-defined) resolvers cannot be unregistered — logs a dev warning and no-ops.
1758
+ * @remarks During reconciliation, the unregistration is deferred and applied after the current cycle completes.
1759
+ */
1760
+ unregister(id: string): void;
1761
+ /**
1762
+ * Execute a resolver's `resolve()` with a requirement object.
1763
+ * @throws If no resolver with this ID exists
1764
+ */
1765
+ call(id: string, requirement: {
1766
+ type: string;
1767
+ [key: string]: unknown;
1768
+ }): Promise<void>;
1769
+ /** Check if a resolver was dynamically registered (not from a module definition) */
1770
+ isDynamic(id: string): boolean;
1771
+ /** List all dynamically registered resolver IDs */
1772
+ listDynamic(): string[];
1647
1773
  }
1648
1774
  interface System<M extends ModuleSchema = ModuleSchema> {
1649
1775
  readonly facts: Facts<M["facts"]>;
1650
1776
  readonly debug: TimeTravelAPI | null;
1651
- readonly derive: InferDerivations<M>;
1777
+ readonly derive: InferDerivations<M> & DerivationsControl;
1652
1778
  readonly events: EventsAccessorFromSchema<M>;
1653
1779
  readonly constraints: ConstraintsControl;
1654
1780
  readonly effects: EffectsControl;
1781
+ readonly resolvers: ResolversControl;
1655
1782
  /** Per-run changelog entries (null if debug.runHistory is not enabled) */
1656
1783
  readonly runHistory: RunChangelogEntry[] | null;
1657
1784
  /** Initialize facts and derivations without starting reconciliation. Safe for SSR. */
@@ -1682,8 +1809,9 @@ interface System<M extends ModuleSchema = ModuleSchema> {
1682
1809
  * Returns an unsubscribe function.
1683
1810
  */
1684
1811
  onTimeTravelChange(listener: () => void): () => void;
1685
- read<K extends DerivationKeys<M>>(derivationId: K): DerivationReturnType<M, K>;
1686
- read<T = unknown>(derivationId: string): T;
1812
+ read<K extends DerivationKeys<M>>(id: K): DerivationReturnType<M, K>;
1813
+ read<K extends FactKeys<M>>(id: K): FactReturnType<M, K>;
1814
+ read<T = unknown>(id: string): T;
1687
1815
  /**
1688
1816
  * Subscribe to fact or derivation changes.
1689
1817
  * Keys are auto-detected -- pass any mix of fact keys and derivation keys.
@@ -1724,6 +1852,17 @@ interface System<M extends ModuleSchema = ModuleSchema> {
1724
1852
  explain(requirementId: string): string | null;
1725
1853
  getSnapshot(): SystemSnapshot;
1726
1854
  restore(snapshot: SystemSnapshot): void;
1855
+ /**
1856
+ * Get the original definition that was overridden by `assign()`.
1857
+ * Returns undefined if no original exists for this type/id.
1858
+ */
1859
+ getOriginal(type: "constraint" | "resolver" | "derivation" | "effect", id: string): unknown | undefined;
1860
+ /**
1861
+ * Restore the original definition that was overridden by `assign()`.
1862
+ * Re-assigns the original definition and removes the override tracking.
1863
+ * Returns true if restoration succeeded, false if no original exists.
1864
+ */
1865
+ restoreOriginal(type: "constraint" | "resolver" | "derivation" | "effect", id: string): boolean;
1727
1866
  /**
1728
1867
  * Get a distributable snapshot of computed derivations.
1729
1868
  * This creates a serializable object that can be stored in Redis, JWT, etc.
@@ -1974,6 +2113,34 @@ interface Plugin<M extends ModuleSchema = ModuleSchema> {
1974
2113
  * @param strategy - The recovery strategy used
1975
2114
  */
1976
2115
  onErrorRecovery?: (error: DirectiveError, strategy: RecoveryStrategy) => void;
2116
+ /**
2117
+ * Called when a definition is dynamically registered at runtime.
2118
+ * @param type - The definition type: "constraint", "resolver", "derivation", or "effect"
2119
+ * @param id - The definition ID
2120
+ * @param def - The definition object
2121
+ */
2122
+ onDefinitionRegister?: (type: string, id: string, def: unknown) => void;
2123
+ /**
2124
+ * Called when a definition is assigned (overridden) at runtime.
2125
+ * @param type - The definition type: "constraint", "resolver", "derivation", or "effect"
2126
+ * @param id - The definition ID
2127
+ * @param def - The new definition object
2128
+ * @param original - The previous definition that was overridden
2129
+ */
2130
+ onDefinitionAssign?: (type: string, id: string, def: unknown, original: unknown) => void;
2131
+ /**
2132
+ * Called when a dynamically registered definition is removed.
2133
+ * @param type - The definition type: "constraint", "resolver", "derivation", or "effect"
2134
+ * @param id - The definition ID
2135
+ */
2136
+ onDefinitionUnregister?: (type: string, id: string) => void;
2137
+ /**
2138
+ * Called when a definition is manually invoked via `call()`.
2139
+ * @param type - The definition type: "constraint", "resolver", "derivation", or "effect"
2140
+ * @param id - The definition ID
2141
+ * @param props - Optional props passed to the call
2142
+ */
2143
+ onDefinitionCall?: (type: string, id: string, props?: unknown) => void;
1977
2144
  /**
1978
2145
  * Called when a run finalizes (all resolvers settled or no resolvers started).
1979
2146
  * Only fires when debug.runHistory is enabled.
@@ -1982,4 +2149,4 @@ interface Plugin<M extends ModuleSchema = ModuleSchema> {
1982
2149
  onRunComplete?: (run: RunChangelogEntry) => void;
1983
2150
  }
1984
2151
 
1985
- export { type AnySystem as $, type ConstraintState as A, type BatchConfig as B, type CrossModuleDeps as C, type DerivationsSchema as D, type EffectsDef as E, type Facts as F, type ResolversDef as G, type ResolverStatus as H, type InferRequirements as I, type System as J, type FactChange as K, type FactsSnapshot as L, type ModuleSchema as M, type NamespacedSystem as N, type ReconcileResult as O, type Plugin as P, type Snapshot as Q, type Requirement as R, type Schema as S, type TypedDerivationsDef as T, DirectiveError as U, type RecoveryStrategy as V, type RunChangelogEntry as W, type ErrorSource as X, type RetryLaterConfig as Y, type TimeTravelAPI as Z, type SystemConfig as _, type RequirementOutput$1 as a, type BatchItemResult as a0, type BatchResolveResults as a1, type CrossModuleConstraintDef as a2, type CrossModuleDerivationFn as a3, type CrossModuleEffectDef as a4, type CrossModuleFactsWithSelf as a5, type DerivationKeys as a6, type DerivationReturnType as a7, type DeriveAccessor as a8, type DispatchEventsFromSchema as a9, type RequirementsSchema as aA, type SnapshotMeta as aB, type SystemEvent as aC, type SystemInspection as aD, type SystemMode as aE, type SystemSnapshot as aF, type TimeTravelState as aG, type TypedResolverContext as aH, type TypedResolverDef as aI, type UnionEvents as aJ, isNamespacedSystem as aK, isSingleModuleSystem as aL, type DistributableSnapshot as aa, type DistributableSnapshotOptions as ab, type EffectCleanup as ac, type EventPayloadSchema as ad, type EventsAccessor as ae, type EventsAccessorFromSchema as af, type EventsDef as ag, type EventsSchema as ah, type FactKeys as ai, type FactReturnType as aj, type FlexibleEventHandler as ak, type InferDerivations as al, type InferEventPayloadFromSchema as am, type InferEvents as an, type InferRequirementPayloadFromSchema as ao, type InferRequirementTypes as ap, type InferSchema as aq, type InferSchemaType as ar, type InferSelectorState as as, type MutableNamespacedFacts as at, type NamespacedDerivations as au, type NamespacedEventsAccessor as av, type NamespacedFacts as aw, type ObservableKeys as ax, type RequirementExplanation as ay, type RequirementPayloadSchema$1 as az, type RetryPolicy as b, type ResolverContext as c, type SchemaType as d, type FactsStore as e, type TypedEventsDef as f, type TypedConstraintsDef as g, type TypedResolversDef as h, type ModuleHooks as i, type CrossModuleDerivationsDef as j, type CrossModuleEffectsDef as k, type CrossModuleConstraintsDef as l, type ModuleDef as m, type CreateSystemOptionsSingle as n, type SingleModuleSystem as o, type ModulesMap as p, type CreateSystemOptionsNamed as q, type TypedConstraintDef as r, type RequirementOutput as s, type DebugConfig as t, type ErrorBoundaryConfig as u, type InferFacts as v, type ExtractSchema as w, type RequirementWithId as x, type RequirementKeyFn as y, type ConstraintsDef as z };
2152
+ export { type AnySystem as $, type ConstraintState as A, type BatchConfig as B, type CrossModuleDeps as C, type DerivationsSchema as D, type EffectsDef as E, type Facts as F, type ResolversDef as G, type ResolverStatus as H, type InferRequirements as I, type System as J, type FactChange as K, type FactsSnapshot as L, type ModuleSchema as M, type NamespacedSystem as N, type ReconcileResult as O, type Plugin as P, type Snapshot as Q, type Requirement as R, type Schema as S, type TypedDerivationsDef as T, DirectiveError as U, type RecoveryStrategy as V, type RunChangelogEntry as W, type ErrorSource as X, type RetryLaterConfig as Y, type TimeTravelAPI as Z, type SystemConfig as _, type RequirementOutput$1 as a, type BatchItemResult as a0, type BatchResolveResults as a1, type ConstraintsControl as a2, type CrossModuleConstraintDef as a3, type CrossModuleDerivationFn as a4, type CrossModuleEffectDef as a5, type CrossModuleFactsWithSelf as a6, type DerivationKeys as a7, type DerivationReturnType as a8, type DerivationsControl as a9, type ObservableKeys as aA, type RequirementExplanation as aB, type RequirementPayloadSchema$1 as aC, type RequirementsSchema as aD, type ResolversControl as aE, type SnapshotMeta as aF, type SystemEvent as aG, type SystemInspection as aH, type SystemMode as aI, type SystemSnapshot as aJ, type TimeTravelState as aK, type TypedResolverContext as aL, type TypedResolverDef as aM, type UnionEvents as aN, isNamespacedSystem as aO, isSingleModuleSystem as aP, type DeriveAccessor as aa, type DispatchEventsFromSchema as ab, type DistributableSnapshot as ac, type DistributableSnapshotOptions as ad, type EffectCleanup as ae, type EffectsControl as af, type EventPayloadSchema as ag, type EventsAccessor as ah, type EventsAccessorFromSchema as ai, type EventsDef as aj, type EventsSchema as ak, type FactKeys as al, type FactReturnType as am, type FlexibleEventHandler as an, type InferDerivations as ao, type InferEventPayloadFromSchema as ap, type InferEvents as aq, type InferRequirementPayloadFromSchema as ar, type InferRequirementTypes as as, type InferSchema as at, type InferSchemaType as au, type InferSelectorState as av, type MutableNamespacedFacts as aw, type NamespacedDerivations as ax, type NamespacedEventsAccessor as ay, type NamespacedFacts as az, type RetryPolicy as b, type ResolverContext as c, type SchemaType as d, type TypedEventsDef as e, type TypedConstraintsDef as f, type TypedResolversDef as g, type ModuleHooks as h, type CrossModuleDerivationsDef as i, type CrossModuleEffectsDef as j, type CrossModuleConstraintsDef as k, type ModuleDef as l, type CreateSystemOptionsSingle as m, type SingleModuleSystem as n, type ModulesMap as o, type CreateSystemOptionsNamed as p, type TypedConstraintDef as q, type RequirementOutput as r, type DebugConfig as s, type ErrorBoundaryConfig as t, type InferFacts as u, type ExtractSchema as v, type RequirementWithId as w, type RequirementKeyFn as x, type FactsStore as y, type ConstraintsDef as z };