@directive-run/core 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter-utils.cjs +1 -1
- package/dist/adapter-utils.cjs.map +1 -1
- package/dist/adapter-utils.d.cts +6 -6
- package/dist/adapter-utils.d.ts +6 -6
- package/dist/adapter-utils.js +1 -1
- package/dist/adapter-utils.js.map +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -457
- package/dist/index.d.ts +38 -457
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/plugins/index.cjs +2 -2
- package/dist/plugins/index.cjs.map +1 -1
- package/dist/plugins/index.d.cts +2 -70
- package/dist/plugins/index.d.ts +2 -70
- package/dist/plugins/index.js +2 -2
- package/dist/plugins/index.js.map +1 -1
- package/dist/{plugins-Co2_xohI.d.cts → plugins-DaglUQVX.d.cts} +147 -78
- package/dist/{plugins-Co2_xohI.d.ts → plugins-DaglUQVX.d.ts} +147 -78
- package/dist/testing.cjs +4 -4
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +4 -4
- package/dist/testing.js.map +1 -1
- package/dist/worker.cjs +4 -4
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.cts +3 -4
- package/dist/worker.d.ts +3 -4
- package/dist/worker.js +4 -4
- package/dist/worker.js.map +1 -1
- package/package.json +2 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as Schema, F as Facts, R as Requirement, a as RequirementOutput, b as RetryPolicy, B as BatchConfig, c as ResolverContext, d as SchemaType, M as ModuleSchema, T as TypedDerivationsDef, e as TypedEventsDef, E as EffectsDef, f as TypedConstraintsDef, g as TypedResolversDef, h as ModuleHooks, C as CrossModuleDeps, i as CrossModuleDerivationsDef, j as CrossModuleEffectsDef, k as CrossModuleConstraintsDef, l as ModuleDef, m as CreateSystemOptionsSingle, n as SingleModuleSystem, o as ModulesMap, p as CreateSystemOptionsNamed, N as NamespacedSystem,
|
|
2
|
-
export {
|
|
1
|
+
import { S as Schema, F as Facts, R as Requirement, a as RequirementOutput, b as RetryPolicy, B as BatchConfig, c as ResolverContext, d as SchemaType, M as ModuleSchema, T as TypedDerivationsDef, e as TypedEventsDef, E as EffectsDef, f as TypedConstraintsDef, g as TypedResolversDef, h as ModuleHooks, C as CrossModuleDeps, i as CrossModuleDerivationsDef, j as CrossModuleEffectsDef, k as CrossModuleConstraintsDef, l as ModuleDef, m as CreateSystemOptionsSingle, n as SingleModuleSystem, o as ModulesMap, p as CreateSystemOptionsNamed, N as NamespacedSystem, P as Plugin, q as TraceOption, r as ErrorBoundaryConfig, s as RequirementWithId, t as RequirementKeyFn, u as FactsStore, v as ConstraintsDef, w as ConstraintState, x as ResolversDef, y as ResolverStatus, z as System, A as FactChange, D as FactsSnapshot, G as ReconcileResult, H as Snapshot, I as DirectiveError, J as RecoveryStrategy, K as TraceEntry, L as ErrorSource, O as RetryLaterConfig, Q as HistoryAPI, U as HistoryOption, V as SystemConfig } from './plugins-DaglUQVX.js';
|
|
2
|
+
export { W as AnySystem, X as BatchItemResult, Y as BatchResolveResults, Z as ConstraintsControl, _ as CrossModuleConstraintDef, $ as CrossModuleDerivationFn, a0 as CrossModuleEffectDef, a1 as CrossModuleFactsWithSelf, a2 as DerivationKeys, a3 as DerivationReturnType, a4 as DerivationsControl, a5 as DerivationsSchema, a6 as DeriveAccessor, a7 as DispatchEventsFromSchema, a8 as DistributableSnapshot, a9 as DistributableSnapshotOptions, aa as DynamicConstraintDef, ab as DynamicEffectDef, ac as DynamicResolverDef, ad as EffectCleanup, ae as EffectsControl, af as EventPayloadSchema, ag as EventsAccessor, ah as EventsAccessorFromSchema, ai as EventsDef, aj as EventsSchema, ak as FactKeys, al as FactReturnType, am as FlexibleEventHandler, an as HistoryConfig, ao as HistoryState, ap as InferDerivations, aq as InferEventPayloadFromSchema, ar as InferEvents, as as InferFacts, at as InferRequirementPayloadFromSchema, au as InferRequirementTypes, av as InferRequirements, aw as InferSchema, ax as InferSchemaType, ay as InferSelectorState, az as MutableNamespacedFacts, aA as NamespacedDerivations, aB as NamespacedEventsAccessor, aC as NamespacedFacts, aD as ObservableKeys, aE as RequirementExplanation, aF as RequirementOutput, aG as RequirementPayloadSchema, aH as RequirementsSchema, aI as ResolversControl, aJ as SnapshotMeta, aK as SystemEvent, aL as SystemInspection, aM as SystemMode, aN as SystemSnapshot, aO as TraceConfig, aP as TypedConstraintDef, aQ as TypedResolverContext, aR as TypedResolverDef, aS as UnionEvents, aT as isNamespacedSystem, aU as isSingleModuleSystem } from './plugins-DaglUQVX.js';
|
|
3
3
|
export { D as DistributableSnapshotLike, S as SignedSnapshot, a as SnapshotDiff, b as SnapshotDiffEntry, d as diffSnapshots, i as isSignedSnapshot, c as isSnapshotExpired, s as shallowEqual, e as signSnapshot, v as validateSnapshot, f as verifySnapshotSignature } from './utils-4JrY5fk9.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -515,8 +515,11 @@ interface ModuleConfig<M extends ModuleSchema> {
|
|
|
515
515
|
constraints?: TypedConstraintsDef<M>;
|
|
516
516
|
resolvers?: TypedResolversDef<M>;
|
|
517
517
|
hooks?: ModuleHooks<M>;
|
|
518
|
-
/**
|
|
519
|
-
|
|
518
|
+
/** History configuration — controls which events create snapshots for undo/redo. */
|
|
519
|
+
history?: {
|
|
520
|
+
/** Events that create history snapshots. Omit to snapshot all events. */
|
|
521
|
+
snapshotEvents?: Array<keyof (M["events"] extends Record<string, unknown> ? M["events"] : Record<string, never>) & string>;
|
|
522
|
+
};
|
|
520
523
|
}
|
|
521
524
|
/**
|
|
522
525
|
* Module configuration with cross-module dependencies for type-safe access
|
|
@@ -586,8 +589,11 @@ interface ModuleConfigWithDeps<M extends ModuleSchema, Deps extends CrossModuleD
|
|
|
586
589
|
/** Resolvers. Uses flat access (`ctx.facts.myFact`) to keep async mutations scoped to own module. */
|
|
587
590
|
resolvers?: TypedResolversDef<M>;
|
|
588
591
|
hooks?: ModuleHooks<M>;
|
|
589
|
-
/**
|
|
590
|
-
|
|
592
|
+
/** History configuration — controls which events create snapshots for undo/redo. */
|
|
593
|
+
history?: {
|
|
594
|
+
/** Events that create history snapshots. Omit to snapshot all events. */
|
|
595
|
+
snapshotEvents?: Array<keyof (M["events"] extends Record<string, unknown> ? M["events"] : Record<string, never>) & string>;
|
|
596
|
+
};
|
|
591
597
|
}
|
|
592
598
|
/**
|
|
593
599
|
* Create a module definition with full type inference.
|
|
@@ -767,431 +773,6 @@ declare function createModuleFactory<const M extends ModuleSchema, const Deps ex
|
|
|
767
773
|
declare function createSystem<S extends ModuleSchema>(options: CreateSystemOptionsSingle<S>): SingleModuleSystem<S>;
|
|
768
774
|
declare function createSystem<const Modules extends ModulesMap>(options: CreateSystemOptionsNamed<Modules>): NamespacedSystem<Modules>;
|
|
769
775
|
|
|
770
|
-
/**
|
|
771
|
-
* Builder Pattern API for Directive Modules
|
|
772
|
-
*
|
|
773
|
-
* An alternative, fluent API for creating modules that provides
|
|
774
|
-
* a more declarative style for module definition.
|
|
775
|
-
*
|
|
776
|
-
* @example
|
|
777
|
-
* ```typescript
|
|
778
|
-
* import { module, t } from '@directive-run/core';
|
|
779
|
-
*
|
|
780
|
-
* const counter = module("counter")
|
|
781
|
-
* .schema({
|
|
782
|
-
* facts: { count: t.number(), lastAction: t.string() },
|
|
783
|
-
* derivations: { doubled: t.number(), isPositive: t.boolean() },
|
|
784
|
-
* events: { increment: {}, decrement: {} },
|
|
785
|
-
* requirements: {},
|
|
786
|
-
* })
|
|
787
|
-
* .init((facts) => {
|
|
788
|
-
* facts.count = 0;
|
|
789
|
-
* facts.lastAction = "";
|
|
790
|
-
* })
|
|
791
|
-
* .derive({
|
|
792
|
-
* doubled: (facts) => facts.count * 2,
|
|
793
|
-
* isPositive: (facts) => facts.count > 0,
|
|
794
|
-
* })
|
|
795
|
-
* .events({
|
|
796
|
-
* increment: (facts) => {
|
|
797
|
-
* facts.count += 1;
|
|
798
|
-
* facts.lastAction = "increment";
|
|
799
|
-
* },
|
|
800
|
-
* decrement: (facts) => {
|
|
801
|
-
* facts.count -= 1;
|
|
802
|
-
* facts.lastAction = "decrement";
|
|
803
|
-
* },
|
|
804
|
-
* })
|
|
805
|
-
* .build();
|
|
806
|
-
* ```
|
|
807
|
-
*/
|
|
808
|
-
|
|
809
|
-
/**
|
|
810
|
-
* Fluent builder interface for constructing {@link ModuleDef} instances step by step.
|
|
811
|
-
*
|
|
812
|
-
* Chain methods like `.schema()`, `.init()`, `.derive()`, `.events()`, and others
|
|
813
|
-
* to configure the module, then call `.build()` to produce the final definition.
|
|
814
|
-
* The builder validates that all schema-declared derivations and events have
|
|
815
|
-
* corresponding implementations before returning.
|
|
816
|
-
*
|
|
817
|
-
* @typeParam M - The module schema type, narrowed after calling `.schema()`.
|
|
818
|
-
* @public
|
|
819
|
-
*/
|
|
820
|
-
interface ModuleBuilder<M extends ModuleSchema = ModuleSchema> {
|
|
821
|
-
/**
|
|
822
|
-
* Define the schema for this module (facts, derivations, events, requirements).
|
|
823
|
-
*/
|
|
824
|
-
schema<NewM extends ModuleSchema>(schema: NewM): ModuleBuilder<NewM>;
|
|
825
|
-
/**
|
|
826
|
-
* Define the initialization function for this module.
|
|
827
|
-
*/
|
|
828
|
-
init(initFn: (facts: Facts<M["facts"]>) => void): ModuleBuilder<M>;
|
|
829
|
-
/**
|
|
830
|
-
* Define derivation implementations for this module.
|
|
831
|
-
* Keys must match those declared in schema.derivations.
|
|
832
|
-
*/
|
|
833
|
-
derive<D extends Record<string, (facts: Facts<M["facts"]>, derived: DeriveAccessor<M>) => unknown>>(derivations: D): ModuleBuilder<M>;
|
|
834
|
-
/**
|
|
835
|
-
* Define event handler implementations for this module.
|
|
836
|
-
* Keys must match those declared in schema.events.
|
|
837
|
-
*/
|
|
838
|
-
events<E extends Record<string, (facts: Facts<M["facts"]>, payload: unknown) => void>>(events: E): ModuleBuilder<M>;
|
|
839
|
-
/**
|
|
840
|
-
* Define effects (side effects) for this module.
|
|
841
|
-
*/
|
|
842
|
-
effects(effects: EffectsDef<M["facts"]>): ModuleBuilder<M>;
|
|
843
|
-
/**
|
|
844
|
-
* Define constraints for this module.
|
|
845
|
-
*/
|
|
846
|
-
constraints<C extends Record<string, ConstraintDef<M>>>(constraints: C): ModuleBuilder<M>;
|
|
847
|
-
/**
|
|
848
|
-
* Define resolvers for this module.
|
|
849
|
-
*/
|
|
850
|
-
resolvers<R extends Record<string, ResolverDef<M>>>(resolvers: R): ModuleBuilder<M>;
|
|
851
|
-
/**
|
|
852
|
-
* Define lifecycle hooks for this module.
|
|
853
|
-
*/
|
|
854
|
-
hooks(hooks: ModuleHooks<M>): ModuleBuilder<M>;
|
|
855
|
-
/**
|
|
856
|
-
* Build the module definition.
|
|
857
|
-
*/
|
|
858
|
-
build(): ModuleDef<M>;
|
|
859
|
-
}
|
|
860
|
-
/**
|
|
861
|
-
* Accessor for reading other derivations within a derivation function.
|
|
862
|
-
*/
|
|
863
|
-
type DeriveAccessor<M extends ModuleSchema> = M["derivations"] extends DerivationsSchema ? {
|
|
864
|
-
readonly [K in keyof M["derivations"]]: InferSchemaType<M["derivations"][K]>;
|
|
865
|
-
} : Record<string, never>;
|
|
866
|
-
/**
|
|
867
|
-
* Infer the TypeScript type from a schema type definition.
|
|
868
|
-
*/
|
|
869
|
-
type InferSchemaType<T> = T extends {
|
|
870
|
-
_type: infer U;
|
|
871
|
-
} ? U : any;
|
|
872
|
-
/**
|
|
873
|
-
* Constraint definition for the builder.
|
|
874
|
-
*/
|
|
875
|
-
interface ConstraintDef<M extends ModuleSchema> {
|
|
876
|
-
when: (facts: Facts<M["facts"]>) => boolean;
|
|
877
|
-
require: {
|
|
878
|
-
type: string;
|
|
879
|
-
[key: string]: unknown;
|
|
880
|
-
} | ((facts: Facts<M["facts"]>) => {
|
|
881
|
-
type: string;
|
|
882
|
-
[key: string]: unknown;
|
|
883
|
-
} | null);
|
|
884
|
-
priority?: number;
|
|
885
|
-
}
|
|
886
|
-
/**
|
|
887
|
-
* Resolver definition for the builder.
|
|
888
|
-
*/
|
|
889
|
-
interface ResolverDef<M extends ModuleSchema> {
|
|
890
|
-
requirement: string | ((req: {
|
|
891
|
-
type: string;
|
|
892
|
-
[key: string]: unknown;
|
|
893
|
-
}) => boolean);
|
|
894
|
-
resolve: (req: {
|
|
895
|
-
type: string;
|
|
896
|
-
[key: string]: unknown;
|
|
897
|
-
}, ctx: {
|
|
898
|
-
facts: Facts<M["facts"]>;
|
|
899
|
-
signal?: AbortSignal;
|
|
900
|
-
}) => void | Promise<void>;
|
|
901
|
-
retry?: {
|
|
902
|
-
attempts?: number;
|
|
903
|
-
backoff?: "linear" | "exponential";
|
|
904
|
-
delay?: number;
|
|
905
|
-
};
|
|
906
|
-
timeout?: number;
|
|
907
|
-
key?: (req: {
|
|
908
|
-
type: string;
|
|
909
|
-
[key: string]: unknown;
|
|
910
|
-
}) => string;
|
|
911
|
-
}
|
|
912
|
-
/**
|
|
913
|
-
* Create a new module using the fluent builder pattern.
|
|
914
|
-
*
|
|
915
|
-
* Returns a {@link ModuleBuilder} that lets you declaratively define a module's
|
|
916
|
-
* schema, initialization, derivations, events, effects, constraints, resolvers,
|
|
917
|
-
* and lifecycle hooks via method chaining. Call `.build()` at the end to produce
|
|
918
|
-
* the final {@link ModuleDef}.
|
|
919
|
-
*
|
|
920
|
-
* @remarks
|
|
921
|
-
* The builder validates at build time that every derivation and event declared
|
|
922
|
-
* in the schema has a corresponding implementation. Missing implementations
|
|
923
|
-
* cause a descriptive error.
|
|
924
|
-
*
|
|
925
|
-
* @param id - Unique identifier for this module, used for namespacing in multi-module systems.
|
|
926
|
-
* @returns A {@link ModuleBuilder} ready for configuration via method chaining.
|
|
927
|
-
*
|
|
928
|
-
* @example
|
|
929
|
-
* ```typescript
|
|
930
|
-
* import { module, t } from '@directive-run/core';
|
|
931
|
-
*
|
|
932
|
-
* const counter = module("counter")
|
|
933
|
-
* .schema({
|
|
934
|
-
* facts: { count: t.number() },
|
|
935
|
-
* derivations: { doubled: t.number() },
|
|
936
|
-
* events: { increment: {} },
|
|
937
|
-
* requirements: {},
|
|
938
|
-
* })
|
|
939
|
-
* .init((facts) => {
|
|
940
|
-
* facts.count = 0;
|
|
941
|
-
* })
|
|
942
|
-
* .derive({
|
|
943
|
-
* doubled: (facts) => facts.count * 2,
|
|
944
|
-
* })
|
|
945
|
-
* .events({
|
|
946
|
-
* increment: (facts) => {
|
|
947
|
-
* facts.count += 1;
|
|
948
|
-
* },
|
|
949
|
-
* })
|
|
950
|
-
* .build();
|
|
951
|
-
* ```
|
|
952
|
-
*
|
|
953
|
-
* @public
|
|
954
|
-
*/
|
|
955
|
-
declare function module$1(id: string): ModuleBuilder<ModuleSchema>;
|
|
956
|
-
|
|
957
|
-
/**
|
|
958
|
-
* Constraint Builder API
|
|
959
|
-
*
|
|
960
|
-
* Fluent builders for creating typed constraint definitions.
|
|
961
|
-
*
|
|
962
|
-
* @example Full builder
|
|
963
|
-
* ```typescript
|
|
964
|
-
* import { constraint } from '@directive-run/core';
|
|
965
|
-
*
|
|
966
|
-
* const escalate = constraint<typeof schema>()
|
|
967
|
-
* .when(f => f.confidence < 0.7)
|
|
968
|
-
* .require({ type: 'ESCALATE' })
|
|
969
|
-
* .priority(50)
|
|
970
|
-
* .build();
|
|
971
|
-
* ```
|
|
972
|
-
*
|
|
973
|
-
* @example Quick shorthand
|
|
974
|
-
* ```typescript
|
|
975
|
-
* import { when } from '@directive-run/core';
|
|
976
|
-
*
|
|
977
|
-
* const pause = when<typeof schema>(f => f.errors > 3)
|
|
978
|
-
* .require({ type: 'PAUSE' });
|
|
979
|
-
* ```
|
|
980
|
-
*/
|
|
981
|
-
|
|
982
|
-
type WhenFn<M extends ModuleSchema> = (facts: Facts<M["facts"]>) => boolean | Promise<boolean>;
|
|
983
|
-
type RequireValue<M extends ModuleSchema> = RequirementOutput$1<InferRequirements<M>> | ((facts: Facts<M["facts"]>) => RequirementOutput$1<InferRequirements<M>>);
|
|
984
|
-
/** Builder after constraint() — must call .when() first */
|
|
985
|
-
interface ConstraintBuilderStart<M extends ModuleSchema> {
|
|
986
|
-
when(condition: WhenFn<M>): ConstraintBuilderWithWhen<M>;
|
|
987
|
-
}
|
|
988
|
-
/** Builder after .when() — must call .require() next */
|
|
989
|
-
interface ConstraintBuilderWithWhen<M extends ModuleSchema> {
|
|
990
|
-
require(req: RequireValue<M>): ConstraintBuilderComplete<M>;
|
|
991
|
-
}
|
|
992
|
-
/** Builder after .require() — optional chaining + .build() */
|
|
993
|
-
interface ConstraintBuilderComplete<M extends ModuleSchema> {
|
|
994
|
-
priority(n: number): ConstraintBuilderComplete<M>;
|
|
995
|
-
after(...ids: string[]): ConstraintBuilderComplete<M>;
|
|
996
|
-
deps(...keys: string[]): ConstraintBuilderComplete<M>;
|
|
997
|
-
timeout(ms: number): ConstraintBuilderComplete<M>;
|
|
998
|
-
async(value: boolean): ConstraintBuilderComplete<M>;
|
|
999
|
-
build(): TypedConstraintDef<M>;
|
|
1000
|
-
}
|
|
1001
|
-
/** Result from when().require() — a valid constraint with optional immutable chaining */
|
|
1002
|
-
type WhenConstraint<M extends ModuleSchema> = TypedConstraintDef<M> & {
|
|
1003
|
-
withPriority(n: number): WhenConstraint<M>;
|
|
1004
|
-
withAfter(...ids: string[]): WhenConstraint<M>;
|
|
1005
|
-
withDeps(...keys: string[]): WhenConstraint<M>;
|
|
1006
|
-
withTimeout(ms: number): WhenConstraint<M>;
|
|
1007
|
-
withAsync(value: boolean): WhenConstraint<M>;
|
|
1008
|
-
};
|
|
1009
|
-
/** Result from when() — must call .require() */
|
|
1010
|
-
interface WhenBuilder<M extends ModuleSchema> {
|
|
1011
|
-
require(req: RequireValue<M>): WhenConstraint<M>;
|
|
1012
|
-
}
|
|
1013
|
-
/**
|
|
1014
|
-
* Create a constraint using the full builder pattern.
|
|
1015
|
-
* Requires `.when()`, `.require()`, and `.build()`.
|
|
1016
|
-
*
|
|
1017
|
-
* @example
|
|
1018
|
-
* ```typescript
|
|
1019
|
-
* const c = constraint<typeof schema>()
|
|
1020
|
-
* .when(f => f.phase === "red")
|
|
1021
|
-
* .require({ type: "TRANSITION", to: "green" })
|
|
1022
|
-
* .priority(50)
|
|
1023
|
-
* .after("healthCheck")
|
|
1024
|
-
* .build();
|
|
1025
|
-
* ```
|
|
1026
|
-
*/
|
|
1027
|
-
declare function constraint<M extends ModuleSchema>(): ConstraintBuilderStart<M>;
|
|
1028
|
-
/**
|
|
1029
|
-
* Quick shorthand for creating constraints.
|
|
1030
|
-
* Returns a valid constraint directly (no `.build()` needed).
|
|
1031
|
-
*
|
|
1032
|
-
* @example
|
|
1033
|
-
* ```typescript
|
|
1034
|
-
* const pause = when<typeof schema>(f => f.errors > 3)
|
|
1035
|
-
* .require({ type: 'PAUSE' });
|
|
1036
|
-
*
|
|
1037
|
-
* // With optional chaining (immutable — returns new constraint)
|
|
1038
|
-
* const halt = when<typeof schema>(f => f.errors > 10)
|
|
1039
|
-
* .require({ type: 'HALT' })
|
|
1040
|
-
* .withPriority(100)
|
|
1041
|
-
* .withAfter('healthCheck');
|
|
1042
|
-
* ```
|
|
1043
|
-
*/
|
|
1044
|
-
declare function when<M extends ModuleSchema>(condition: WhenFn<M>): WhenBuilder<M>;
|
|
1045
|
-
|
|
1046
|
-
/**
|
|
1047
|
-
* System Builder API
|
|
1048
|
-
*
|
|
1049
|
-
* Fluent builder for creating Directive systems.
|
|
1050
|
-
*
|
|
1051
|
-
* @example Single module
|
|
1052
|
-
* ```typescript
|
|
1053
|
-
* import { system } from '@directive-run/core';
|
|
1054
|
-
*
|
|
1055
|
-
* const sys = system()
|
|
1056
|
-
* .module(counterModule)
|
|
1057
|
-
* .plugins([loggingPlugin()])
|
|
1058
|
-
* .debug({ timeTravel: true })
|
|
1059
|
-
* .build();
|
|
1060
|
-
* ```
|
|
1061
|
-
*
|
|
1062
|
-
* @example Multiple modules
|
|
1063
|
-
* ```typescript
|
|
1064
|
-
* const sys = system()
|
|
1065
|
-
* .modules({ auth: authModule, cart: cartModule })
|
|
1066
|
-
* .plugins([loggingPlugin()])
|
|
1067
|
-
* .build();
|
|
1068
|
-
* ```
|
|
1069
|
-
*/
|
|
1070
|
-
|
|
1071
|
-
/**
|
|
1072
|
-
* Entry point of the system builder, returned by {@link system}.
|
|
1073
|
-
*
|
|
1074
|
-
* Choose `.module()` for a single-module {@link SingleModuleSystem} with direct
|
|
1075
|
-
* fact/derivation access, or `.modules()` for a namespaced {@link NamespacedSystem}
|
|
1076
|
-
* that composes multiple modules.
|
|
1077
|
-
*
|
|
1078
|
-
* @public
|
|
1079
|
-
*/
|
|
1080
|
-
interface SystemBuilderStart {
|
|
1081
|
-
/**
|
|
1082
|
-
* Configure the system with a single module definition.
|
|
1083
|
-
*
|
|
1084
|
-
* @param mod - The module definition to use as the system's sole module.
|
|
1085
|
-
* @returns A {@link SingleModuleSystemBuilder} for further configuration.
|
|
1086
|
-
*/
|
|
1087
|
-
module<S extends ModuleSchema>(mod: ModuleDef<S>): SingleModuleSystemBuilder<S>;
|
|
1088
|
-
/**
|
|
1089
|
-
* Configure the system with multiple named modules.
|
|
1090
|
-
*
|
|
1091
|
-
* @param mods - A map of namespace keys to module definitions.
|
|
1092
|
-
* @returns A {@link NamespacedSystemBuilder} for further configuration.
|
|
1093
|
-
*/
|
|
1094
|
-
modules<const Modules extends ModulesMap>(mods: Modules): NamespacedSystemBuilder<Modules>;
|
|
1095
|
-
}
|
|
1096
|
-
/**
|
|
1097
|
-
* Builder for a single-module system with direct access to facts, derivations, and events.
|
|
1098
|
-
*
|
|
1099
|
-
* @remarks
|
|
1100
|
-
* Use this builder when your system contains exactly one module. The resulting
|
|
1101
|
-
* {@link SingleModuleSystem} exposes facts, derivations, and dispatch without
|
|
1102
|
-
* namespace prefixes.
|
|
1103
|
-
*
|
|
1104
|
-
* @typeParam S - The module schema type.
|
|
1105
|
-
* @public
|
|
1106
|
-
*/
|
|
1107
|
-
interface SingleModuleSystemBuilder<S extends ModuleSchema> {
|
|
1108
|
-
/** Register plugins that hook into system lifecycle events. */
|
|
1109
|
-
plugins(plugins: Array<Plugin<ModuleSchema>>): SingleModuleSystemBuilder<S>;
|
|
1110
|
-
/** Enable debug features such as time-travel debugging and snapshot limits. */
|
|
1111
|
-
debug(config: DebugConfig): SingleModuleSystemBuilder<S>;
|
|
1112
|
-
/** Configure error boundary behavior including recovery strategies. */
|
|
1113
|
-
errorBoundary(config: ErrorBoundaryConfig): SingleModuleSystemBuilder<S>;
|
|
1114
|
-
/** Set the reconciliation tick interval in milliseconds. */
|
|
1115
|
-
tickMs(ms: number): SingleModuleSystemBuilder<S>;
|
|
1116
|
-
/** Enable zero-config mode which auto-generates constraints from schema metadata. */
|
|
1117
|
-
zeroConfig(enabled?: boolean): SingleModuleSystemBuilder<S>;
|
|
1118
|
-
/** Provide initial fact values to hydrate the system on startup. */
|
|
1119
|
-
initialFacts(facts: Partial<InferFacts<S>>): SingleModuleSystemBuilder<S>;
|
|
1120
|
-
/** Finalize configuration and create the running {@link SingleModuleSystem}. */
|
|
1121
|
-
build(): SingleModuleSystem<S>;
|
|
1122
|
-
}
|
|
1123
|
-
/**
|
|
1124
|
-
* Builder for a namespaced multi-module system.
|
|
1125
|
-
*
|
|
1126
|
-
* @remarks
|
|
1127
|
-
* Use this builder when composing multiple modules. The resulting
|
|
1128
|
-
* {@link NamespacedSystem} prefixes facts and derivations with the module
|
|
1129
|
-
* namespace key (e.g., `system.facts.auth.token`).
|
|
1130
|
-
*
|
|
1131
|
-
* @typeParam Modules - The modules map type mapping namespace keys to module definitions.
|
|
1132
|
-
* @public
|
|
1133
|
-
*/
|
|
1134
|
-
interface NamespacedSystemBuilder<Modules extends ModulesMap> {
|
|
1135
|
-
/** Register plugins that hook into system lifecycle events. */
|
|
1136
|
-
plugins(plugins: Array<Plugin<ModuleSchema>>): NamespacedSystemBuilder<Modules>;
|
|
1137
|
-
/** Enable debug features such as time-travel debugging and snapshot limits. */
|
|
1138
|
-
debug(config: DebugConfig): NamespacedSystemBuilder<Modules>;
|
|
1139
|
-
/** Configure error boundary behavior including recovery strategies. */
|
|
1140
|
-
errorBoundary(config: ErrorBoundaryConfig): NamespacedSystemBuilder<Modules>;
|
|
1141
|
-
/** Set the reconciliation tick interval in milliseconds. */
|
|
1142
|
-
tickMs(ms: number): NamespacedSystemBuilder<Modules>;
|
|
1143
|
-
/** Enable zero-config mode which auto-generates constraints from schema metadata. */
|
|
1144
|
-
zeroConfig(enabled?: boolean): NamespacedSystemBuilder<Modules>;
|
|
1145
|
-
/** Provide initial fact values keyed by module namespace for hydration on startup. */
|
|
1146
|
-
initialFacts(facts: Partial<{
|
|
1147
|
-
[K in keyof Modules]: Partial<InferFacts<ExtractSchema<Modules[K]>>>;
|
|
1148
|
-
}>): NamespacedSystemBuilder<Modules>;
|
|
1149
|
-
/** Control the order in which modules are initialized: automatic, declaration order, or explicit. */
|
|
1150
|
-
initOrder(order: "auto" | "declaration" | Array<keyof Modules & string>): NamespacedSystemBuilder<Modules>;
|
|
1151
|
-
/** Finalize configuration and create the running {@link NamespacedSystem}. */
|
|
1152
|
-
build(): NamespacedSystem<Modules>;
|
|
1153
|
-
}
|
|
1154
|
-
/**
|
|
1155
|
-
* Create a Directive system using the fluent builder pattern.
|
|
1156
|
-
*
|
|
1157
|
-
* Returns a {@link SystemBuilderStart} that branches into either a
|
|
1158
|
-
* single-module path (`.module()`) or a namespaced multi-module path
|
|
1159
|
-
* (`.modules()`). Chain configuration methods like `.plugins()`, `.debug()`,
|
|
1160
|
-
* and `.errorBoundary()`, then call `.build()` to produce the running system.
|
|
1161
|
-
*
|
|
1162
|
-
* @remarks
|
|
1163
|
-
* This is a convenience wrapper around {@link createSystem}. Both produce
|
|
1164
|
-
* identical systems; the builder simply offers a more discoverable,
|
|
1165
|
-
* chainable API.
|
|
1166
|
-
*
|
|
1167
|
-
* @returns A {@link SystemBuilderStart} ready to receive a module or modules map.
|
|
1168
|
-
*
|
|
1169
|
-
* @example Single-module system
|
|
1170
|
-
* ```typescript
|
|
1171
|
-
* import { system } from '@directive-run/core';
|
|
1172
|
-
*
|
|
1173
|
-
* const sys = system()
|
|
1174
|
-
* .module(counterModule)
|
|
1175
|
-
* .plugins([loggingPlugin()])
|
|
1176
|
-
* .debug({ timeTravel: true })
|
|
1177
|
-
* .build();
|
|
1178
|
-
* ```
|
|
1179
|
-
*
|
|
1180
|
-
* @example Multi-module namespaced system
|
|
1181
|
-
* ```typescript
|
|
1182
|
-
* import { system } from '@directive-run/core';
|
|
1183
|
-
*
|
|
1184
|
-
* const sys = system()
|
|
1185
|
-
* .modules({ auth: authModule, cart: cartModule })
|
|
1186
|
-
* .plugins([loggingPlugin()])
|
|
1187
|
-
* .initOrder(["auth", "cart"])
|
|
1188
|
-
* .build();
|
|
1189
|
-
* ```
|
|
1190
|
-
*
|
|
1191
|
-
* @public
|
|
1192
|
-
*/
|
|
1193
|
-
declare function system(): SystemBuilderStart;
|
|
1194
|
-
|
|
1195
776
|
/**
|
|
1196
777
|
* Requirement Status Utilities
|
|
1197
778
|
*
|
|
@@ -1278,8 +859,8 @@ interface CreateSystemWithStatusOptions<M extends ModuleSchema> {
|
|
|
1278
859
|
module: ModuleDef<M>;
|
|
1279
860
|
/** Additional plugins to include alongside the status plugin */
|
|
1280
861
|
plugins?: Plugin<any>[];
|
|
1281
|
-
/**
|
|
1282
|
-
|
|
862
|
+
/** Trace: per-run reconciliation changelog */
|
|
863
|
+
trace?: TraceOption;
|
|
1283
864
|
/** Error boundary configuration */
|
|
1284
865
|
errorBoundary?: ErrorBoundaryConfig;
|
|
1285
866
|
/** Tick interval in milliseconds */
|
|
@@ -2300,9 +1881,9 @@ declare function createResolversManager<S extends Schema>(options: CreateResolve
|
|
|
2300
1881
|
* - **Requirements:** `emitRequirementCreated`, `emitRequirementMet`, `emitRequirementCanceled`
|
|
2301
1882
|
* - **Resolvers:** `emitResolverStart`, `emitResolverComplete`, `emitResolverError`, `emitResolverRetry`, `emitResolverCancel`
|
|
2302
1883
|
* - **Effects:** `emitEffectRun`, `emitEffectError`
|
|
2303
|
-
* - **
|
|
1884
|
+
* - **History:** `emitSnapshot`, `emitHistoryNavigate`
|
|
2304
1885
|
* - **Errors:** `emitError`, `emitErrorRecovery`
|
|
2305
|
-
* - **
|
|
1886
|
+
* - **Trace:** `emitTraceComplete`
|
|
2306
1887
|
*
|
|
2307
1888
|
* @typeParam _S - The flat schema type (unused at runtime).
|
|
2308
1889
|
*
|
|
@@ -2339,14 +1920,14 @@ interface PluginManager<_S extends Schema = any> {
|
|
|
2339
1920
|
emitEffectRun(id: string): void;
|
|
2340
1921
|
emitEffectError(id: string, error: unknown): void;
|
|
2341
1922
|
emitSnapshot(snapshot: Snapshot): void;
|
|
2342
|
-
|
|
1923
|
+
emitHistoryNavigate(from: number, to: number): void;
|
|
2343
1924
|
emitError(error: DirectiveError): void;
|
|
2344
1925
|
emitErrorRecovery(error: DirectiveError, strategy: RecoveryStrategy): void;
|
|
2345
1926
|
emitDefinitionRegister(type: string, id: string, def: unknown): void;
|
|
2346
1927
|
emitDefinitionAssign(type: string, id: string, def: unknown, original: unknown): void;
|
|
2347
1928
|
emitDefinitionUnregister(type: string, id: string): void;
|
|
2348
1929
|
emitDefinitionCall(type: string, id: string, props?: unknown): void;
|
|
2349
|
-
|
|
1930
|
+
emitTraceComplete(run: TraceEntry): void;
|
|
2350
1931
|
}
|
|
2351
1932
|
/**
|
|
2352
1933
|
* Create a {@link PluginManager} that broadcasts lifecycle events to registered plugins.
|
|
@@ -2504,7 +2085,7 @@ interface CreateErrorBoundaryOptions {
|
|
|
2504
2085
|
declare function createErrorBoundaryManager(options?: CreateErrorBoundaryOptions): ErrorBoundaryManager;
|
|
2505
2086
|
|
|
2506
2087
|
/**
|
|
2507
|
-
*
|
|
2088
|
+
* History — Snapshot-based state history
|
|
2508
2089
|
*
|
|
2509
2090
|
* Features:
|
|
2510
2091
|
* - Ring buffer of state snapshots
|
|
@@ -2514,7 +2095,7 @@ declare function createErrorBoundaryManager(options?: CreateErrorBoundaryOptions
|
|
|
2514
2095
|
*/
|
|
2515
2096
|
|
|
2516
2097
|
/**
|
|
2517
|
-
* Internal
|
|
2098
|
+
* Internal history manager that extends the public {@link HistoryAPI}
|
|
2518
2099
|
* with snapshot capture, restoration, and pause/resume controls.
|
|
2519
2100
|
*
|
|
2520
2101
|
* @remarks
|
|
@@ -2530,12 +2111,12 @@ declare function createErrorBoundaryManager(options?: CreateErrorBoundaryOptions
|
|
|
2530
2111
|
*
|
|
2531
2112
|
* @internal
|
|
2532
2113
|
*/
|
|
2533
|
-
interface
|
|
2114
|
+
interface HistoryManager<_S extends Schema> extends HistoryAPI {
|
|
2534
2115
|
/** Take a snapshot of current state */
|
|
2535
2116
|
takeSnapshot(trigger: string): Snapshot;
|
|
2536
2117
|
/** Restore facts from a snapshot */
|
|
2537
2118
|
restore(snapshot: Snapshot): void;
|
|
2538
|
-
/** Check if
|
|
2119
|
+
/** Check if history is enabled */
|
|
2539
2120
|
readonly isEnabled: boolean;
|
|
2540
2121
|
/** True while restoring a snapshot (engine should skip reconciliation) */
|
|
2541
2122
|
readonly isRestoring: boolean;
|
|
@@ -2545,23 +2126,23 @@ interface TimeTravelManager<_S extends Schema> extends TimeTravelAPI {
|
|
|
2545
2126
|
resume(): void;
|
|
2546
2127
|
}
|
|
2547
2128
|
/**
|
|
2548
|
-
* Options for creating a
|
|
2129
|
+
* Options for creating a history manager via {@link createHistoryManager}.
|
|
2549
2130
|
*
|
|
2550
2131
|
* @typeParam S - The facts schema type.
|
|
2551
2132
|
*
|
|
2552
2133
|
* @internal
|
|
2553
2134
|
*/
|
|
2554
|
-
interface
|
|
2555
|
-
|
|
2135
|
+
interface CreateHistoryOptions<S extends Schema> {
|
|
2136
|
+
historyOption: HistoryOption;
|
|
2556
2137
|
facts: Facts<S>;
|
|
2557
2138
|
store: FactsStore<S>;
|
|
2558
2139
|
/** Callback when a snapshot is taken */
|
|
2559
2140
|
onSnapshot?: (snapshot: Snapshot) => void;
|
|
2560
|
-
/** Callback when
|
|
2561
|
-
|
|
2141
|
+
/** Callback when history navigation occurs */
|
|
2142
|
+
onHistoryChange?: (from: number, to: number) => void;
|
|
2562
2143
|
}
|
|
2563
2144
|
/**
|
|
2564
|
-
* Create a snapshot-based
|
|
2145
|
+
* Create a snapshot-based history manager backed by a ring buffer.
|
|
2565
2146
|
*
|
|
2566
2147
|
* @remarks
|
|
2567
2148
|
* Snapshots are taken automatically after fact changes (during reconciliation)
|
|
@@ -2573,25 +2154,25 @@ interface CreateTimeTravelOptions<S extends Schema> {
|
|
|
2573
2154
|
* Call `pause()` to temporarily stop recording snapshots (e.g., during bulk
|
|
2574
2155
|
* fact imports) and `resume()` to re-enable recording.
|
|
2575
2156
|
*
|
|
2576
|
-
* @param options -
|
|
2577
|
-
* @returns A {@link
|
|
2157
|
+
* @param options - History config, facts proxy, store, and optional snapshot/history callbacks.
|
|
2158
|
+
* @returns A {@link HistoryManager} with snapshot capture, navigation, changeset, and export/import methods.
|
|
2578
2159
|
*
|
|
2579
2160
|
* @internal
|
|
2580
2161
|
*/
|
|
2581
|
-
declare function
|
|
2162
|
+
declare function createHistoryManager<S extends Schema>(options: CreateHistoryOptions<S>): HistoryManager<S>;
|
|
2582
2163
|
/**
|
|
2583
|
-
* Create a no-op
|
|
2164
|
+
* Create a no-op history manager for use when history is disabled.
|
|
2584
2165
|
*
|
|
2585
2166
|
* @remarks
|
|
2586
2167
|
* All methods are safe to call but perform no work. This avoids null-checks
|
|
2587
|
-
* throughout the engine -- callers can use the same {@link
|
|
2588
|
-
* interface regardless of whether
|
|
2168
|
+
* throughout the engine -- callers can use the same {@link HistoryManager}
|
|
2169
|
+
* interface regardless of whether history is enabled.
|
|
2589
2170
|
*
|
|
2590
|
-
* @returns A {@link
|
|
2171
|
+
* @returns A {@link HistoryManager} where every method is a no-op and `isEnabled` is `false`.
|
|
2591
2172
|
*
|
|
2592
2173
|
* @internal
|
|
2593
2174
|
*/
|
|
2594
|
-
declare function
|
|
2175
|
+
declare function createDisabledHistory<S extends Schema>(): HistoryManager<S>;
|
|
2595
2176
|
|
|
2596
2177
|
/**
|
|
2597
2178
|
* Engine - The core reconciliation loop
|
|
@@ -2606,7 +2187,7 @@ declare function createDisabledTimeTravel<S extends Schema>(): TimeTravelManager
|
|
|
2606
2187
|
|
|
2607
2188
|
/**
|
|
2608
2189
|
* Create the core Directive reconciliation engine that wires facts, derivations,
|
|
2609
|
-
* effects, constraints, resolvers, plugins, error boundaries, and
|
|
2190
|
+
* effects, constraints, resolvers, plugins, error boundaries, and history
|
|
2610
2191
|
* into a single reactive system.
|
|
2611
2192
|
*
|
|
2612
2193
|
* @remarks
|
|
@@ -2714,4 +2295,4 @@ declare const Backoff: {
|
|
|
2714
2295
|
readonly Exponential: "exponential";
|
|
2715
2296
|
};
|
|
2716
2297
|
|
|
2717
|
-
export { Backoff, BatchConfig, type Branded, type ChainableSchemaType, ConstraintState, ConstraintsDef, CreateSystemOptionsNamed, CreateSystemOptionsSingle, CrossModuleConstraintsDef, CrossModuleDeps, CrossModuleDerivationsDef, CrossModuleEffectsDef,
|
|
2298
|
+
export { Backoff, BatchConfig, type Branded, type ChainableSchemaType, ConstraintState, ConstraintsDef, CreateSystemOptionsNamed, CreateSystemOptionsSingle, CrossModuleConstraintsDef, CrossModuleDeps, CrossModuleDerivationsDef, CrossModuleEffectsDef, type DerivationState, type DerivationsDef, type DerivedValues, DirectiveError, EffectsDef, ErrorBoundaryConfig, ErrorSource, type ExtendedSchemaType, FactChange, Facts, FactsSnapshot, FactsStore, HistoryAPI, HistoryOption, type InflightInfo, type ModuleConfig, type ModuleConfigWithDeps, ModuleDef, ModuleHooks, ModuleSchema, ModulesMap, NamespacedSystem, type PendingRetry, Plugin, ReconcileResult, RecoveryStrategy, Requirement, RequirementKeyFn, RequirementSet, type RequirementTypeStatus, RequirementWithId, ResolverContext, ResolverStatus, ResolversDef, RetryLaterConfig, RetryPolicy, Schema, SchemaType, SingleModuleSystem, Snapshot, System, SystemConfig, TraceEntry, TraceOption, type TypedConstraint, TypedConstraintsDef, TypedDerivationsDef, TypedEventsDef, type TypedResolver, TypedResolversDef, createConstraintFactory, createConstraintsManager, createDerivationsManager, createDisabledHistory, createEffectsManager, createEngine, createErrorBoundaryManager, createFacts, createFactsProxy, createFactsStore, createHistoryManager, createModule, createModuleFactory, createPluginManager, createRequirementStatusPlugin, createResolverFactory, createResolversManager, createRetryLaterManager, createStatusHook, createSystem, createSystemWithStatus, forType, generateRequirementId, getCurrentTracker, isRequirementType, isTracking, req, t, trackAccess, typedConstraint, typedResolver, withTracking, withoutTracking };
|