@plures/praxis 1.1.1 → 1.1.3

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 (33) hide show
  1. package/README.md +68 -7
  2. package/dist/browser/chunk-R45WXWKH.js +345 -0
  3. package/dist/browser/index.d.ts +171 -11
  4. package/dist/browser/index.js +279 -277
  5. package/dist/browser/integrations/svelte.d.ts +3 -1
  6. package/dist/browser/integrations/svelte.js +7 -0
  7. package/dist/browser/{engine-BjdqxeXG.d.ts → reactive-engine.svelte-C9OpcTHf.d.ts} +87 -1
  8. package/dist/node/chunk-R45WXWKH.js +345 -0
  9. package/dist/node/components/index.d.cts +2 -2
  10. package/dist/node/components/index.d.ts +2 -2
  11. package/dist/node/index.cjs +343 -8
  12. package/dist/node/index.d.cts +108 -15
  13. package/dist/node/index.d.ts +108 -15
  14. package/dist/node/index.js +279 -278
  15. package/dist/node/integrations/svelte.cjs +357 -2
  16. package/dist/node/integrations/svelte.d.cts +3 -1
  17. package/dist/node/integrations/svelte.d.ts +3 -1
  18. package/dist/node/integrations/svelte.js +6 -0
  19. package/dist/node/{engine-CVJobhHm.d.cts → reactive-engine.svelte-1M4m_C_v.d.cts} +87 -1
  20. package/dist/node/{engine-1iqLe6_P.d.ts → reactive-engine.svelte-ChNFn4Hj.d.ts} +87 -1
  21. package/dist/node/{terminal-adapter-XLtCjjb_.d.cts → terminal-adapter-CDzxoLKR.d.cts} +68 -1
  22. package/dist/node/{terminal-adapter-07HGftGQ.d.ts → terminal-adapter-CWka-yL8.d.ts} +68 -1
  23. package/package.json +3 -2
  24. package/src/__tests__/reactive-engine.test.ts +516 -0
  25. package/src/core/pluresdb/README.md +156 -0
  26. package/src/core/pluresdb/adapter.ts +165 -0
  27. package/src/core/pluresdb/index.ts +3 -3
  28. package/src/core/reactive-engine.svelte.ts +88 -19
  29. package/src/core/reactive-engine.ts +283 -30
  30. package/src/index.browser.ts +12 -0
  31. package/src/index.ts +12 -0
  32. package/src/integrations/pluresdb.ts +2 -2
  33. package/src/integrations/svelte.ts +8 -0
@@ -1,42 +1,91 @@
1
1
  import { P as PraxisState, a as PraxisEvent, b as PraxisFact } from './protocol-Qek7ebBl.js';
2
2
  export { g as PRAXIS_PROTOCOL_VERSION, e as PraxisDiagnostics, d as PraxisStepConfig, f as PraxisStepFn, c as PraxisStepResult } from './protocol-Qek7ebBl.js';
3
- import { L as LogicEngine, P as PraxisRegistry, R as RuleDescriptor, C as ConstraintDescriptor, a as RuleFn, b as ConstraintFn, c as PraxisModule } from './engine-1iqLe6_P.js';
4
- export { e as ConstraintId, f as PraxisEngineOptions, d as RuleId, g as createPraxisEngine } from './engine-1iqLe6_P.js';
5
- import { P as PraxisDB, U as UnsubscribeFn } from './terminal-adapter-07HGftGQ.js';
6
- export { C as CommandExecutor, I as InMemoryPraxisDB, T as TerminalAdapter, d as TerminalAdapterOptions, a as TerminalExecutionResult, b as TerminalNodeState, f as createInMemoryDB, e as createMockExecutor, c as createTerminalAdapter, r as runTerminalCommand } from './terminal-adapter-07HGftGQ.js';
3
+ import { L as LogicEngine, P as PraxisRegistry, b as RuleDescriptor, C as ConstraintDescriptor, d as RuleFn, e as ConstraintFn, f as PraxisModule } from './reactive-engine.svelte-ChNFn4Hj.js';
4
+ export { h as ConstraintId, i as PraxisEngineOptions, a as ReactiveEngineOptions, R as ReactiveLogicEngine, g as RuleId, j as createPraxisEngine, c as createReactiveEngine } from './reactive-engine.svelte-ChNFn4Hj.js';
5
+ import { P as PraxisDB, U as UnsubscribeFn$1 } from './terminal-adapter-CWka-yL8.js';
6
+ export { C as CommandExecutor, I as InMemoryPraxisDB, g as PluresDBAdapterConfig, f as PluresDBInstance, i as PluresDBPraxisAdapter, T as TerminalAdapter, d as TerminalAdapterOptions, a as TerminalExecutionResult, b as TerminalNodeState, h as createInMemoryDB, e as createMockExecutor, j as createPluresDB, c as createTerminalAdapter, r as runTerminalCommand } from './terminal-adapter-CWka-yL8.js';
7
7
  import { PraxisSchema, ValidationResult, ModelDefinition, FieldDefinition, ComponentDefinition, LogicDefinition } from './schema.js';
8
8
  export { NodeBindings, NodeDefinition, OrchestrationDefinition, TerminalNodeProps, ValidationError, createSchemaTemplate, validateSchema } from './schema.js';
9
9
 
10
10
  /**
11
11
  * Praxis Reactive Logic Engine
12
12
  *
13
- * A Svelte 5 native implementation of the Praxis Logic Engine.
14
- * Uses Runes ($state, $derived, $effect) for fine-grained reactivity.
13
+ * A framework-agnostic reactive implementation of the Praxis Logic Engine.
14
+ * Uses JavaScript Proxies to provide reactivity without Svelte-specific primitives.
15
+ *
16
+ * This implementation provides:
17
+ * - Proxy-based state tracking for automatic reactivity
18
+ * - Subscription-based change notifications
19
+ * - Computed/derived values support
20
+ * - Compatible API with Svelte-based implementation
15
21
  */
16
22
  interface ReactiveEngineOptions<TContext> {
17
23
  initialContext: TContext;
18
24
  initialFacts?: any[];
19
25
  initialMeta?: Record<string, unknown>;
20
26
  }
27
+ /**
28
+ * Callback type for state change subscribers
29
+ */
30
+ type StateChangeCallback<TContext> = (state: {
31
+ context: TContext;
32
+ facts: any[];
33
+ meta: Record<string, unknown>;
34
+ }) => void;
35
+ /**
36
+ * Callback type for unsubscribe function
37
+ */
38
+ type UnsubscribeFn = () => void;
39
+ /**
40
+ * Framework-agnostic reactive logic engine using JavaScript Proxies
41
+ */
21
42
  declare class ReactiveLogicEngine<TContext extends object> {
22
- state: {
43
+ private _state;
44
+ private _subscribers;
45
+ private _contextProxy;
46
+ private _factsProxy;
47
+ private _metaProxy;
48
+ private _batchDepth;
49
+ private _pendingNotification;
50
+ private _proxyCache;
51
+ private static readonly ARRAY_MUTATORS;
52
+ constructor(options: ReactiveEngineOptions<TContext>);
53
+ /**
54
+ * Create a reactive proxy that notifies subscribers on changes.
55
+ * Uses a WeakMap cache to avoid creating multiple proxies for the same object.
56
+ */
57
+ private _createReactiveProxy;
58
+ /**
59
+ * Notify all subscribers of state changes
60
+ */
61
+ private _notify;
62
+ /**
63
+ * Get the full state object
64
+ */
65
+ get state(): {
23
66
  context: TContext;
24
67
  facts: any[];
25
68
  meta: Record<string, unknown>;
26
69
  };
27
- constructor(options: ReactiveEngineOptions<TContext>);
28
70
  /**
29
- * Access the reactive context directly.
30
- * Consumers can use this in $derived() or $effect().
71
+ * Access the reactive context.
72
+ * Changes to this object will trigger subscriber notifications.
31
73
  */
32
74
  get context(): TContext;
33
75
  /**
34
76
  * Access the reactive facts list.
77
+ * Changes to this array will trigger subscriber notifications.
35
78
  */
36
79
  get facts(): any[];
80
+ /**
81
+ * Access the reactive metadata.
82
+ * Changes to this object will trigger subscriber notifications.
83
+ */
84
+ get meta(): Record<string, unknown>;
37
85
  /**
38
86
  * Apply a mutation to the state.
39
87
  * This is the "Action" or "Rule" equivalent.
88
+ * Mutations are batched - notifications only happen once per apply call.
40
89
  *
41
90
  * @param mutator A function that receives the state and modifies it.
42
91
  */
@@ -46,10 +95,54 @@ declare class ReactiveLogicEngine<TContext extends object> {
46
95
  meta: Record<string, unknown>;
47
96
  }) => void): void;
48
97
  /**
49
- * Access the reactive meta.
98
+ * Subscribe to state changes.
99
+ * Returns an unsubscribe function.
100
+ *
101
+ * @param callback Function to call when state changes
102
+ * @returns Unsubscribe function
103
+ */
104
+ subscribe(callback: StateChangeCallback<TContext>): UnsubscribeFn;
105
+ /**
106
+ * Create a derived/computed value from the state.
107
+ * The selector function will be called whenever the state changes.
108
+ *
109
+ * @param selector Function to extract derived value from state
110
+ * @returns Object with subscribe method for reactive updates
50
111
  */
51
- get meta(): Record<string, unknown>;
112
+ $derived<TDerived>(selector: (state: {
113
+ context: TContext;
114
+ facts: any[];
115
+ meta: Record<string, unknown>;
116
+ }) => TDerived): {
117
+ subscribe: (callback: (value: TDerived) => void) => UnsubscribeFn;
118
+ };
52
119
  }
120
+ /**
121
+ * Create a new reactive logic engine instance.
122
+ *
123
+ * @param options Configuration options for the reactive engine
124
+ * @returns A new ReactiveLogicEngine instance
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * const engine = createReactiveEngine({
129
+ * initialContext: { count: 0 },
130
+ * initialFacts: [],
131
+ * initialMeta: {}
132
+ * });
133
+ *
134
+ * // Subscribe to changes
135
+ * engine.subscribe((state) => {
136
+ * console.log('State changed:', state);
137
+ * });
138
+ *
139
+ * // Mutate state (will trigger subscribers)
140
+ * engine.apply((state) => {
141
+ * state.context.count++;
142
+ * });
143
+ * ```
144
+ */
145
+ declare function createReactiveEngine<TContext extends object>(options: ReactiveEngineOptions<TContext>): ReactiveLogicEngine<TContext>;
53
146
 
54
147
  /**
55
148
  * Actors System
@@ -634,7 +727,7 @@ declare class PraxisDBStore<TContext = unknown> {
634
727
  * @param callback Called when facts of this type change
635
728
  * @returns Unsubscribe function
636
729
  */
637
- watchFacts(factTag: string, callback: (facts: PraxisFact[]) => void): UnsubscribeFn;
730
+ watchFacts(factTag: string, callback: (facts: PraxisFact[]) => void): UnsubscribeFn$1;
638
731
  /**
639
732
  * Check constraints against the current state with new facts
640
733
  */
@@ -997,7 +1090,7 @@ declare function createPluresDBAdapter<TContext = unknown>(options: PluresDBAdap
997
1090
  * detach();
998
1091
  * ```
999
1092
  */
1000
- declare function attachToEngine<TContext = unknown>(store: PraxisDBStore<TContext>, engine: LogicEngine<TContext>): UnsubscribeFn;
1093
+ declare function attachToEngine<TContext = unknown>(store: PraxisDBStore<TContext>, engine: LogicEngine<TContext>): UnsubscribeFn$1;
1001
1094
 
1002
1095
  /**
1003
1096
  * Unum Integration
@@ -2576,4 +2669,4 @@ declare function attachTauriToEngine<TContext>(engine: LogicEngine<TContext>, ad
2576
2669
  */
2577
2670
  declare function generateTauriConfig(config: TauriAppConfig): Record<string, unknown>;
2578
2671
 
2579
- export { type ActivityState, type Actor, ActorManager, type CanvasDocument, type CanvasEdge, type CanvasEdgeStyle, type CanvasEditorConfig, type CanvasNode, type CanvasNodeStyle, ComponentDefinition, ConstraintDescriptor, ConstraintFn, type ConstraintNode, type ConstraintSchema, type DefineConstraintOptions, type DefineModuleOptions, type DefineRuleOptions, type EventDefinition, type EventStreamEntry, type FactDefinition, type GeneratedDoc, type GeneratedPluresDBFile, type GraphEdge, type GuardianError, type GuardianResult, type GuardianWarning, type LifecycleState, type LoaderOptions, type LoaderResult, LogicDefinition, LogicEngine, ModelDefinition, PRAXIS_PATHS, type PluresDBAdapter, type PluresDBAdapterOptions, PluresDBGenerator, type PluresDBGeneratorOptions, PraxisDB, PraxisDBStore, type PraxisDBStoreOptions, PraxisEvent, PraxisFact, PraxisModule, PraxisRegistry, PraxisSchema, PraxisSchemaRegistry, PraxisState, type ReactiveEngineOptions, ReactiveLogicEngine, type RegistryGraph, RegistryIntrospector, type RegistrySchema, type RegistryStats, RuleDescriptor, RuleFn, type RuleNode, type RuleSchema, type StateDoc, type StateDocsConfig, StateDocsGenerator, type StateMachineDoc, type StoredSchema, type TauriAppConfig, type TauriBridge, type TauriCommand, type TauriEvent, type TauriFS, type TauriFileEntry, type TauriMenuItem, type TauriNotification, type TauriNotificationOptions, type TauriPlugin, type TauriPraxisAdapter, type TauriSecurityConfig, type TauriTray, type TauriUpdateConfig, type TauriUpdateInfo, type TauriWindowConfig, type TransitionDoc, UnsubscribeFn, type UnumAdapter, type UnumAdapterConfig, type UnumChannel, type UnumIdentity, type UnumMessage, type UnumStore, ValidationResult, attachTauriToEngine, attachToEngine, attachUnumToEngine, canvasToMermaid, canvasToSchema, canvasToYaml, createCanvasEditor, createIntrospector, createMockTauriBridge, createPluresDBAdapter, createPluresDBGenerator, createPraxisDBStore, createSchemaRegistry, createStateDocsGenerator, createTauriPraxisAdapter, createTimerActor, createUnumAdapter, defineConstraint, defineEvent, defineFact, defineModule, defineRule, filterEvents, filterFacts, findEvent, findFact, generateDocs, generateId, generateTauriConfig, getEventPath, getFactPath, getSchemaPath, loadSchema, loadSchemaFromFile, loadSchemaFromJson, loadSchemaFromYaml, registerSchema, schemaToCanvas, validateForGeneration, validateWithGuardian };
2672
+ export { type ActivityState, type Actor, ActorManager, type CanvasDocument, type CanvasEdge, type CanvasEdgeStyle, type CanvasEditorConfig, type CanvasNode, type CanvasNodeStyle, ComponentDefinition, ConstraintDescriptor, ConstraintFn, type ConstraintNode, type ConstraintSchema, type DefineConstraintOptions, type DefineModuleOptions, type DefineRuleOptions, type EventDefinition, type EventStreamEntry, type FactDefinition, ReactiveLogicEngine as FrameworkAgnosticReactiveEngine, type ReactiveEngineOptions as FrameworkAgnosticReactiveEngineOptions, type GeneratedDoc, type GeneratedPluresDBFile, type GraphEdge, type GuardianError, type GuardianResult, type GuardianWarning, type LifecycleState, type LoaderOptions, type LoaderResult, LogicDefinition, LogicEngine, ModelDefinition, PRAXIS_PATHS, type PluresDBAdapter, type PluresDBAdapterOptions, PluresDBGenerator, type PluresDBGeneratorOptions, PraxisDB, PraxisDBStore, type PraxisDBStoreOptions, PraxisEvent, PraxisFact, PraxisModule, PraxisRegistry, PraxisSchema, PraxisSchemaRegistry, PraxisState, type RegistryGraph, RegistryIntrospector, type RegistrySchema, type RegistryStats, RuleDescriptor, RuleFn, type RuleNode, type RuleSchema, type StateChangeCallback, type StateDoc, type StateDocsConfig, StateDocsGenerator, type StateMachineDoc, type StoredSchema, type TauriAppConfig, type TauriBridge, type TauriCommand, type TauriEvent, type TauriFS, type TauriFileEntry, type TauriMenuItem, type TauriNotification, type TauriNotificationOptions, type TauriPlugin, type TauriPraxisAdapter, type TauriSecurityConfig, type TauriTray, type TauriUpdateConfig, type TauriUpdateInfo, type TauriWindowConfig, type TransitionDoc, UnsubscribeFn$1 as UnsubscribeFn, type UnumAdapter, type UnumAdapterConfig, type UnumChannel, type UnumIdentity, type UnumMessage, type UnumStore, ValidationResult, attachTauriToEngine, attachToEngine, attachUnumToEngine, canvasToMermaid, canvasToSchema, canvasToYaml, createCanvasEditor, createReactiveEngine as createFrameworkAgnosticReactiveEngine, createIntrospector, createMockTauriBridge, createPluresDBAdapter, createPluresDBGenerator, createPraxisDBStore, createSchemaRegistry, createStateDocsGenerator, createTauriPraxisAdapter, createTimerActor, createUnumAdapter, defineConstraint, defineEvent, defineFact, defineModule, defineRule, filterEvents, filterFacts, findEvent, findFact, generateDocs, generateId, generateTauriConfig, getEventPath, getFactPath, getSchemaPath, loadSchema, loadSchemaFromFile, loadSchemaFromJson, loadSchemaFromYaml, registerSchema, schemaToCanvas, validateForGeneration, validateWithGuardian };