@plures/praxis 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (263) hide show
  1. package/FRAMEWORK.md +420 -0
  2. package/LICENSE +21 -0
  3. package/README.md +1310 -0
  4. package/dist/adapters/cli.d.ts +43 -0
  5. package/dist/adapters/cli.d.ts.map +1 -0
  6. package/dist/adapters/cli.js +126 -0
  7. package/dist/adapters/cli.js.map +1 -0
  8. package/dist/cli/commands/auth.d.ts +26 -0
  9. package/dist/cli/commands/auth.d.ts.map +1 -0
  10. package/dist/cli/commands/auth.js +233 -0
  11. package/dist/cli/commands/auth.js.map +1 -0
  12. package/dist/cli/commands/cloud.d.ts +27 -0
  13. package/dist/cli/commands/cloud.d.ts.map +1 -0
  14. package/dist/cli/commands/cloud.js +232 -0
  15. package/dist/cli/commands/cloud.js.map +1 -0
  16. package/dist/cli/commands/generate.d.ts +25 -0
  17. package/dist/cli/commands/generate.d.ts.map +1 -0
  18. package/dist/cli/commands/generate.js +168 -0
  19. package/dist/cli/commands/generate.js.map +1 -0
  20. package/dist/cli/index.d.ts +8 -0
  21. package/dist/cli/index.d.ts.map +1 -0
  22. package/dist/cli/index.js +179 -0
  23. package/dist/cli/index.js.map +1 -0
  24. package/dist/cloud/auth.d.ts +51 -0
  25. package/dist/cloud/auth.d.ts.map +1 -0
  26. package/dist/cloud/auth.js +194 -0
  27. package/dist/cloud/auth.js.map +1 -0
  28. package/dist/cloud/billing.d.ts +184 -0
  29. package/dist/cloud/billing.d.ts.map +1 -0
  30. package/dist/cloud/billing.js +179 -0
  31. package/dist/cloud/billing.js.map +1 -0
  32. package/dist/cloud/client.d.ts +39 -0
  33. package/dist/cloud/client.d.ts.map +1 -0
  34. package/dist/cloud/client.js +176 -0
  35. package/dist/cloud/client.js.map +1 -0
  36. package/dist/cloud/index.d.ts +44 -0
  37. package/dist/cloud/index.d.ts.map +1 -0
  38. package/dist/cloud/index.js +44 -0
  39. package/dist/cloud/index.js.map +1 -0
  40. package/dist/cloud/marketplace.d.ts +166 -0
  41. package/dist/cloud/marketplace.d.ts.map +1 -0
  42. package/dist/cloud/marketplace.js +159 -0
  43. package/dist/cloud/marketplace.js.map +1 -0
  44. package/dist/cloud/provisioning.d.ts +110 -0
  45. package/dist/cloud/provisioning.d.ts.map +1 -0
  46. package/dist/cloud/provisioning.js +148 -0
  47. package/dist/cloud/provisioning.js.map +1 -0
  48. package/dist/cloud/relay/endpoints.d.ts +62 -0
  49. package/dist/cloud/relay/endpoints.d.ts.map +1 -0
  50. package/dist/cloud/relay/endpoints.js +217 -0
  51. package/dist/cloud/relay/endpoints.js.map +1 -0
  52. package/dist/cloud/relay/health/index.d.ts +5 -0
  53. package/dist/cloud/relay/health/index.d.ts.map +1 -0
  54. package/dist/cloud/relay/health/index.js +9 -0
  55. package/dist/cloud/relay/health/index.js.map +1 -0
  56. package/dist/cloud/relay/stats/index.d.ts +5 -0
  57. package/dist/cloud/relay/stats/index.d.ts.map +1 -0
  58. package/dist/cloud/relay/stats/index.js +9 -0
  59. package/dist/cloud/relay/stats/index.js.map +1 -0
  60. package/dist/cloud/relay/sync/index.d.ts +5 -0
  61. package/dist/cloud/relay/sync/index.d.ts.map +1 -0
  62. package/dist/cloud/relay/sync/index.js +9 -0
  63. package/dist/cloud/relay/sync/index.js.map +1 -0
  64. package/dist/cloud/relay/usage/index.d.ts +5 -0
  65. package/dist/cloud/relay/usage/index.d.ts.map +1 -0
  66. package/dist/cloud/relay/usage/index.js +9 -0
  67. package/dist/cloud/relay/usage/index.js.map +1 -0
  68. package/dist/cloud/sponsors.d.ts +81 -0
  69. package/dist/cloud/sponsors.d.ts.map +1 -0
  70. package/dist/cloud/sponsors.js +130 -0
  71. package/dist/cloud/sponsors.js.map +1 -0
  72. package/dist/cloud/types.d.ts +169 -0
  73. package/dist/cloud/types.d.ts.map +1 -0
  74. package/dist/cloud/types.js +7 -0
  75. package/dist/cloud/types.js.map +1 -0
  76. package/dist/components/index.d.ts +43 -0
  77. package/dist/components/index.d.ts.map +1 -0
  78. package/dist/components/index.js +17 -0
  79. package/dist/components/index.js.map +1 -0
  80. package/dist/core/actors.d.ts +95 -0
  81. package/dist/core/actors.d.ts.map +1 -0
  82. package/dist/core/actors.js +158 -0
  83. package/dist/core/actors.js.map +1 -0
  84. package/dist/core/component/generator.d.ts +122 -0
  85. package/dist/core/component/generator.d.ts.map +1 -0
  86. package/dist/core/component/generator.js +307 -0
  87. package/dist/core/component/generator.js.map +1 -0
  88. package/dist/core/engine.d.ts +92 -0
  89. package/dist/core/engine.d.ts.map +1 -0
  90. package/dist/core/engine.js +199 -0
  91. package/dist/core/engine.js.map +1 -0
  92. package/dist/core/introspection.d.ts +141 -0
  93. package/dist/core/introspection.d.ts.map +1 -0
  94. package/dist/core/introspection.js +208 -0
  95. package/dist/core/introspection.js.map +1 -0
  96. package/dist/core/logic/generator.d.ts +76 -0
  97. package/dist/core/logic/generator.d.ts.map +1 -0
  98. package/dist/core/logic/generator.js +339 -0
  99. package/dist/core/logic/generator.js.map +1 -0
  100. package/dist/core/pluresdb/generator.d.ts +58 -0
  101. package/dist/core/pluresdb/generator.d.ts.map +1 -0
  102. package/dist/core/pluresdb/generator.js +162 -0
  103. package/dist/core/pluresdb/generator.js.map +1 -0
  104. package/dist/core/protocol.d.ts +121 -0
  105. package/dist/core/protocol.d.ts.map +1 -0
  106. package/dist/core/protocol.js +46 -0
  107. package/dist/core/protocol.js.map +1 -0
  108. package/dist/core/rules.d.ts +120 -0
  109. package/dist/core/rules.d.ts.map +1 -0
  110. package/dist/core/rules.js +81 -0
  111. package/dist/core/rules.js.map +1 -0
  112. package/dist/core/schema/loader.d.ts +47 -0
  113. package/dist/core/schema/loader.d.ts.map +1 -0
  114. package/dist/core/schema/loader.js +189 -0
  115. package/dist/core/schema/loader.js.map +1 -0
  116. package/dist/core/schema/normalize.d.ts +72 -0
  117. package/dist/core/schema/normalize.d.ts.map +1 -0
  118. package/dist/core/schema/normalize.js +190 -0
  119. package/dist/core/schema/normalize.js.map +1 -0
  120. package/dist/core/schema/types.d.ts +370 -0
  121. package/dist/core/schema/types.d.ts.map +1 -0
  122. package/dist/core/schema/types.js +161 -0
  123. package/dist/core/schema/types.js.map +1 -0
  124. package/dist/dsl/index.d.ts +152 -0
  125. package/dist/dsl/index.d.ts.map +1 -0
  126. package/dist/dsl/index.js +132 -0
  127. package/dist/dsl/index.js.map +1 -0
  128. package/dist/dsl.d.ts +124 -0
  129. package/dist/dsl.d.ts.map +1 -0
  130. package/dist/dsl.js +130 -0
  131. package/dist/dsl.js.map +1 -0
  132. package/dist/examples/advanced-todo/index.d.ts +55 -0
  133. package/dist/examples/advanced-todo/index.d.ts.map +1 -0
  134. package/dist/examples/advanced-todo/index.js +222 -0
  135. package/dist/examples/advanced-todo/index.js.map +1 -0
  136. package/dist/examples/auth-basic/index.d.ts +17 -0
  137. package/dist/examples/auth-basic/index.d.ts.map +1 -0
  138. package/dist/examples/auth-basic/index.js +122 -0
  139. package/dist/examples/auth-basic/index.js.map +1 -0
  140. package/dist/examples/cart/index.d.ts +19 -0
  141. package/dist/examples/cart/index.d.ts.map +1 -0
  142. package/dist/examples/cart/index.js +202 -0
  143. package/dist/examples/cart/index.js.map +1 -0
  144. package/dist/examples/hero-ecommerce/index.d.ts +39 -0
  145. package/dist/examples/hero-ecommerce/index.d.ts.map +1 -0
  146. package/dist/examples/hero-ecommerce/index.js +506 -0
  147. package/dist/examples/hero-ecommerce/index.js.map +1 -0
  148. package/dist/examples/svelte-counter/index.d.ts +31 -0
  149. package/dist/examples/svelte-counter/index.d.ts.map +1 -0
  150. package/dist/examples/svelte-counter/index.js +123 -0
  151. package/dist/examples/svelte-counter/index.js.map +1 -0
  152. package/dist/flows.d.ts +125 -0
  153. package/dist/flows.d.ts.map +1 -0
  154. package/dist/flows.js +160 -0
  155. package/dist/flows.js.map +1 -0
  156. package/dist/index.d.ts +67 -0
  157. package/dist/index.d.ts.map +1 -0
  158. package/dist/index.js +59 -0
  159. package/dist/index.js.map +1 -0
  160. package/dist/integrations/pluresdb.d.ts +56 -0
  161. package/dist/integrations/pluresdb.d.ts.map +1 -0
  162. package/dist/integrations/pluresdb.js +46 -0
  163. package/dist/integrations/pluresdb.js.map +1 -0
  164. package/dist/integrations/svelte.d.ts +306 -0
  165. package/dist/integrations/svelte.d.ts.map +1 -0
  166. package/dist/integrations/svelte.js +447 -0
  167. package/dist/integrations/svelte.js.map +1 -0
  168. package/dist/registry.d.ts +94 -0
  169. package/dist/registry.d.ts.map +1 -0
  170. package/dist/registry.js +181 -0
  171. package/dist/registry.js.map +1 -0
  172. package/dist/runtime/terminal-adapter.d.ts +105 -0
  173. package/dist/runtime/terminal-adapter.d.ts.map +1 -0
  174. package/dist/runtime/terminal-adapter.js +113 -0
  175. package/dist/runtime/terminal-adapter.js.map +1 -0
  176. package/dist/step.d.ts +34 -0
  177. package/dist/step.d.ts.map +1 -0
  178. package/dist/step.js +111 -0
  179. package/dist/step.js.map +1 -0
  180. package/dist/types.d.ts +63 -0
  181. package/dist/types.d.ts.map +1 -0
  182. package/dist/types.js +6 -0
  183. package/dist/types.js.map +1 -0
  184. package/docs/MONETIZATION.md +394 -0
  185. package/docs/TERMINAL_NODE.md +588 -0
  186. package/docs/guides/canvas.md +389 -0
  187. package/docs/guides/getting-started.md +347 -0
  188. package/docs/guides/history-state-pattern.md +618 -0
  189. package/docs/guides/orchestration.md +617 -0
  190. package/docs/guides/parallel-state-pattern.md +767 -0
  191. package/docs/guides/svelte-integration.md +691 -0
  192. package/package.json +96 -0
  193. package/src/__tests__/actors.test.ts +270 -0
  194. package/src/__tests__/billing.test.ts +175 -0
  195. package/src/__tests__/cloud.test.ts +247 -0
  196. package/src/__tests__/dsl.test.ts +154 -0
  197. package/src/__tests__/edge-cases.test.ts +475 -0
  198. package/src/__tests__/engine.test.ts +137 -0
  199. package/src/__tests__/generators.test.ts +270 -0
  200. package/src/__tests__/introspection.test.ts +321 -0
  201. package/src/__tests__/protocol.test.ts +40 -0
  202. package/src/__tests__/provisioning.test.ts +162 -0
  203. package/src/__tests__/schema.test.ts +241 -0
  204. package/src/__tests__/svelte-integration.test.ts +431 -0
  205. package/src/__tests__/terminal-node.test.ts +352 -0
  206. package/src/adapters/cli.ts +175 -0
  207. package/src/cli/commands/auth.ts +271 -0
  208. package/src/cli/commands/cloud.ts +281 -0
  209. package/src/cli/commands/generate.ts +225 -0
  210. package/src/cli/index.ts +190 -0
  211. package/src/cloud/README.md +383 -0
  212. package/src/cloud/auth.ts +245 -0
  213. package/src/cloud/billing.ts +336 -0
  214. package/src/cloud/client.ts +221 -0
  215. package/src/cloud/index.ts +121 -0
  216. package/src/cloud/marketplace.ts +303 -0
  217. package/src/cloud/provisioning.ts +254 -0
  218. package/src/cloud/relay/endpoints.ts +307 -0
  219. package/src/cloud/relay/health/function.json +17 -0
  220. package/src/cloud/relay/health/index.ts +10 -0
  221. package/src/cloud/relay/host.json +15 -0
  222. package/src/cloud/relay/local.settings.json +8 -0
  223. package/src/cloud/relay/stats/function.json +17 -0
  224. package/src/cloud/relay/stats/index.ts +10 -0
  225. package/src/cloud/relay/sync/function.json +17 -0
  226. package/src/cloud/relay/sync/index.ts +10 -0
  227. package/src/cloud/relay/usage/function.json +17 -0
  228. package/src/cloud/relay/usage/index.ts +10 -0
  229. package/src/cloud/sponsors.ts +213 -0
  230. package/src/cloud/types.ts +198 -0
  231. package/src/components/README.md +125 -0
  232. package/src/components/TerminalNode.svelte +457 -0
  233. package/src/components/index.ts +46 -0
  234. package/src/core/actors.ts +205 -0
  235. package/src/core/component/generator.ts +432 -0
  236. package/src/core/engine.ts +243 -0
  237. package/src/core/introspection.ts +329 -0
  238. package/src/core/logic/generator.ts +420 -0
  239. package/src/core/pluresdb/generator.ts +229 -0
  240. package/src/core/protocol.ts +132 -0
  241. package/src/core/rules.ts +167 -0
  242. package/src/core/schema/loader.ts +247 -0
  243. package/src/core/schema/normalize.ts +322 -0
  244. package/src/core/schema/types.ts +557 -0
  245. package/src/dsl/index.ts +218 -0
  246. package/src/dsl.ts +214 -0
  247. package/src/examples/advanced-todo/App.svelte +506 -0
  248. package/src/examples/advanced-todo/README.md +371 -0
  249. package/src/examples/advanced-todo/index.ts +309 -0
  250. package/src/examples/auth-basic/index.ts +163 -0
  251. package/src/examples/cart/index.ts +259 -0
  252. package/src/examples/hero-ecommerce/index.ts +657 -0
  253. package/src/examples/svelte-counter/index.ts +168 -0
  254. package/src/flows.ts +268 -0
  255. package/src/index.ts +154 -0
  256. package/src/integrations/pluresdb.ts +93 -0
  257. package/src/integrations/svelte.ts +617 -0
  258. package/src/registry.ts +223 -0
  259. package/src/runtime/terminal-adapter.ts +175 -0
  260. package/src/step.ts +151 -0
  261. package/src/types.ts +70 -0
  262. package/templates/basic-app/README.md +147 -0
  263. package/templates/fullstack-app/README.md +279 -0
@@ -0,0 +1,447 @@
1
+ /**
2
+ * Svelte v5 Integration
3
+ *
4
+ * Provides reactive bindings for Praxis logic engines in Svelte v5 applications.
5
+ * Supports both traditional stores and modern Svelte 5 runes ($state, $derived, $effect).
6
+ *
7
+ * Features:
8
+ * - Store-based API for backward compatibility
9
+ * - Runes-based composables for Svelte 5
10
+ * - Snapshot support for time-travel debugging
11
+ * - History state pattern implementation
12
+ * - Automatic cleanup and subscription management
13
+ */
14
+ /**
15
+ * Create a reactive Svelte store from a Praxis engine.
16
+ *
17
+ * The store tracks the engine's state and provides methods to dispatch events.
18
+ *
19
+ * @example
20
+ * const engine = createPraxisEngine({ ... });
21
+ * const store = createPraxisStore(engine);
22
+ *
23
+ * // In Svelte component:
24
+ * $: state = $store;
25
+ *
26
+ * // Dispatch events:
27
+ * store.dispatch([Login.create({ username: "alice", password: "secret" })]);
28
+ */
29
+ export function createPraxisStore(engine) {
30
+ let currentState = engine.getState();
31
+ const subscribers = new Set();
32
+ const notify = () => {
33
+ currentState = engine.getState();
34
+ subscribers.forEach((sub) => sub(currentState));
35
+ };
36
+ return {
37
+ subscribe(run) {
38
+ subscribers.add(run);
39
+ run(currentState); // Call immediately with current value
40
+ return () => {
41
+ subscribers.delete(run);
42
+ };
43
+ },
44
+ dispatch(events) {
45
+ engine.step(events);
46
+ notify();
47
+ },
48
+ };
49
+ }
50
+ /**
51
+ * Create a derived store that extracts the context from the engine state.
52
+ *
53
+ * @example
54
+ * const engine = createPraxisEngine({ ... });
55
+ * const contextStore = createContextStore(engine);
56
+ *
57
+ * // In Svelte component:
58
+ * $: context = $contextStore;
59
+ */
60
+ export function createContextStore(engine) {
61
+ let currentContext = engine.getContext();
62
+ const subscribers = new Set();
63
+ const notify = () => {
64
+ currentContext = engine.getContext();
65
+ subscribers.forEach((sub) => sub(currentContext));
66
+ };
67
+ return {
68
+ subscribe(run) {
69
+ subscribers.add(run);
70
+ run(currentContext); // Call immediately with current value
71
+ return () => {
72
+ subscribers.delete(run);
73
+ };
74
+ },
75
+ dispatch(events) {
76
+ engine.step(events);
77
+ notify();
78
+ },
79
+ };
80
+ }
81
+ /**
82
+ * Create a derived store that extracts specific data from the context.
83
+ *
84
+ * @example
85
+ * const engine = createPraxisEngine<{ count: number }>({ ... });
86
+ * const countStore = createDerivedStore(engine, (ctx) => ctx.count);
87
+ *
88
+ * // In Svelte component:
89
+ * $: count = $countStore;
90
+ */
91
+ export function createDerivedStore(engine, selector) {
92
+ let currentValue = selector(engine.getContext());
93
+ const subscribers = new Set();
94
+ const notify = () => {
95
+ const newValue = selector(engine.getContext());
96
+ if (newValue !== currentValue) {
97
+ currentValue = newValue;
98
+ subscribers.forEach((sub) => sub(currentValue));
99
+ }
100
+ };
101
+ return {
102
+ subscribe(run) {
103
+ subscribers.add(run);
104
+ run(currentValue); // Call immediately with current value
105
+ return () => {
106
+ subscribers.delete(run);
107
+ };
108
+ },
109
+ dispatch(events) {
110
+ engine.step(events);
111
+ notify();
112
+ },
113
+ };
114
+ }
115
+ /**
116
+ * Create a reactive binding to a Praxis engine with Svelte 5 runes support.
117
+ *
118
+ * This composable provides a runes-compatible API for integrating Praxis
119
+ * with Svelte 5 components. The returned state is reactive and will
120
+ * automatically update the component when the engine state changes.
121
+ *
122
+ * Note: The history/snapshot feature tracks state snapshots but doesn't
123
+ * restore the engine to previous states. When you navigate history (undo/redo),
124
+ * you're viewing past snapshots, but new events are still applied to the
125
+ * current engine state. For true undo/redo, use createHistoryEngine or
126
+ * implement state restoration in your application logic.
127
+ *
128
+ * @example
129
+ * <script>
130
+ * import { usePraxisEngine } from '@plures/praxis/svelte';
131
+ * import { createMyEngine } from './my-engine';
132
+ *
133
+ * const engine = createMyEngine();
134
+ * const { context, dispatch, undo, canUndo } = usePraxisEngine(engine, {
135
+ * enableHistory: true
136
+ * });
137
+ * </script>
138
+ *
139
+ * <div>
140
+ * <p>Count: {context.count}</p>
141
+ * <button onclick={() => dispatch([Increment.create({})])}>+</button>
142
+ * <button onclick={() => undo()} disabled={!canUndo}>Undo</button>
143
+ * </div>
144
+ *
145
+ * @param engine The Praxis logic engine
146
+ * @param options Configuration options
147
+ * @returns Reactive binding with state, context, and control methods
148
+ */
149
+ export function usePraxisEngine(engine, options = {}) {
150
+ const { enableHistory = false, maxHistorySize = 50 } = options;
151
+ // Create reactive state holders
152
+ let currentState = engine.getState();
153
+ let snapshots = [];
154
+ let historyIndex = -1;
155
+ // Initialize with first snapshot if history is enabled
156
+ if (enableHistory) {
157
+ snapshots.push({
158
+ timestamp: Date.now(),
159
+ state: currentState,
160
+ events: [],
161
+ });
162
+ historyIndex = 0;
163
+ }
164
+ const dispatch = (events) => {
165
+ // If we're not at the end of history, truncate future snapshots
166
+ if (enableHistory && historyIndex < snapshots.length - 1) {
167
+ snapshots = snapshots.slice(0, historyIndex + 1);
168
+ }
169
+ // Apply events to engine
170
+ engine.step(events);
171
+ currentState = engine.getState();
172
+ // Record snapshot if history is enabled
173
+ if (enableHistory) {
174
+ snapshots.push({
175
+ timestamp: Date.now(),
176
+ state: currentState,
177
+ events,
178
+ });
179
+ // Limit history size
180
+ if (snapshots.length > maxHistorySize) {
181
+ snapshots.shift();
182
+ }
183
+ else {
184
+ historyIndex++;
185
+ }
186
+ }
187
+ };
188
+ const goToSnapshot = (index) => {
189
+ if (!enableHistory) {
190
+ console.warn('History is not enabled for this engine');
191
+ return;
192
+ }
193
+ if (index < 0 || index >= snapshots.length) {
194
+ console.warn(`Invalid snapshot index: ${index}`);
195
+ return;
196
+ }
197
+ historyIndex = index;
198
+ currentState = snapshots[index].state;
199
+ };
200
+ const undo = () => {
201
+ if (historyIndex > 0) {
202
+ goToSnapshot(historyIndex - 1);
203
+ }
204
+ };
205
+ const redo = () => {
206
+ if (historyIndex < snapshots.length - 1) {
207
+ goToSnapshot(historyIndex + 1);
208
+ }
209
+ };
210
+ return {
211
+ get state() {
212
+ return currentState;
213
+ },
214
+ get context() {
215
+ return currentState.context;
216
+ },
217
+ get facts() {
218
+ return currentState.facts;
219
+ },
220
+ dispatch,
221
+ get snapshots() {
222
+ return snapshots;
223
+ },
224
+ goToSnapshot,
225
+ undo,
226
+ redo,
227
+ get canUndo() {
228
+ return enableHistory && historyIndex > 0;
229
+ },
230
+ get canRedo() {
231
+ return enableHistory && historyIndex < snapshots.length - 1;
232
+ },
233
+ get historyIndex() {
234
+ return historyIndex;
235
+ },
236
+ };
237
+ }
238
+ /**
239
+ * Create a reactive derived value from engine context with Svelte 5 runes.
240
+ *
241
+ * This composable extracts and tracks a specific value from the engine context.
242
+ * The returned value is reactive and will update when the selected value changes.
243
+ *
244
+ * @example
245
+ * <script>
246
+ * import { usePraxisContext } from '@plures/praxis/svelte';
247
+ *
248
+ * const engine = createMyEngine();
249
+ * const count = usePraxisContext(engine, (ctx) => ctx.count);
250
+ * </script>
251
+ *
252
+ * <p>Count: {count}</p>
253
+ *
254
+ * @param engine The Praxis logic engine
255
+ * @param selector Function to extract value from context
256
+ * @returns Reactive derived value
257
+ */
258
+ export function usePraxisContext(engine, selector) {
259
+ let currentValue = selector(engine.getContext());
260
+ return currentValue;
261
+ }
262
+ /**
263
+ * Subscribe to engine state changes with automatic cleanup.
264
+ *
265
+ * This composable sets up a subscription to engine state changes and
266
+ * automatically cleans up when the component is destroyed.
267
+ *
268
+ * @example
269
+ * <script>
270
+ * import { usePraxisSubscription } from '@plures/praxis/svelte';
271
+ *
272
+ * const engine = createMyEngine();
273
+ *
274
+ * usePraxisSubscription(engine, (state) => {
275
+ * console.log('State changed:', state);
276
+ * });
277
+ * </script>
278
+ *
279
+ * @param engine The Praxis logic engine
280
+ * @param callback Function to call when state changes
281
+ */
282
+ export function usePraxisSubscription(engine, callback) {
283
+ const store = createPraxisStore(engine);
284
+ const unsubscribe = store.subscribe(callback);
285
+ return unsubscribe;
286
+ }
287
+ /**
288
+ * History state manager for Praxis engines
289
+ */
290
+ export class HistoryStateManager {
291
+ history = [];
292
+ currentIndex = -1;
293
+ maxSize;
294
+ idCounter = 0;
295
+ constructor(maxSize = 50) {
296
+ this.maxSize = maxSize;
297
+ }
298
+ /**
299
+ * Record a new history entry
300
+ */
301
+ record(state, events, label) {
302
+ // If we're not at the end, truncate future history
303
+ if (this.currentIndex < this.history.length - 1) {
304
+ this.history = this.history.slice(0, this.currentIndex + 1);
305
+ }
306
+ // Add new entry
307
+ this.history.push({
308
+ id: `history-${++this.idCounter}`,
309
+ timestamp: Date.now(),
310
+ state,
311
+ events,
312
+ label,
313
+ });
314
+ // Limit history size
315
+ if (this.history.length > this.maxSize) {
316
+ this.history.shift();
317
+ }
318
+ else {
319
+ this.currentIndex++;
320
+ }
321
+ }
322
+ /**
323
+ * Navigate to a specific history entry
324
+ */
325
+ goTo(index) {
326
+ if (index < 0 || index >= this.history.length) {
327
+ return null;
328
+ }
329
+ this.currentIndex = index;
330
+ return this.history[index];
331
+ }
332
+ /**
333
+ * Go back to previous state
334
+ */
335
+ back() {
336
+ if (!this.canGoBack()) {
337
+ return null;
338
+ }
339
+ return this.goTo(this.currentIndex - 1);
340
+ }
341
+ /**
342
+ * Go forward to next state
343
+ */
344
+ forward() {
345
+ if (!this.canGoForward()) {
346
+ return null;
347
+ }
348
+ return this.goTo(this.currentIndex + 1);
349
+ }
350
+ /**
351
+ * Check if can go back
352
+ */
353
+ canGoBack() {
354
+ return this.currentIndex > 0;
355
+ }
356
+ /**
357
+ * Check if can go forward
358
+ */
359
+ canGoForward() {
360
+ return this.currentIndex < this.history.length - 1;
361
+ }
362
+ /**
363
+ * Get current history entry
364
+ */
365
+ current() {
366
+ if (this.currentIndex < 0 || this.currentIndex >= this.history.length) {
367
+ return null;
368
+ }
369
+ return this.history[this.currentIndex];
370
+ }
371
+ /**
372
+ * Get all history entries
373
+ */
374
+ getHistory() {
375
+ return [...this.history];
376
+ }
377
+ /**
378
+ * Get current index in history
379
+ */
380
+ getCurrentIndex() {
381
+ return this.currentIndex;
382
+ }
383
+ /**
384
+ * Clear all history
385
+ */
386
+ clear() {
387
+ this.history = [];
388
+ this.currentIndex = -1;
389
+ }
390
+ }
391
+ /**
392
+ * Create a Praxis engine with history tracking.
393
+ *
394
+ * This utility wraps an engine with automatic history recording,
395
+ * providing undo/redo functionality.
396
+ *
397
+ * @example
398
+ * const engine = createPraxisEngine({ ... });
399
+ * const { dispatch, undo, redo, canUndo, canRedo } = createHistoryEngine(engine);
400
+ *
401
+ * // Use normally
402
+ * dispatch([Login.create({ username: "alice" })]);
403
+ *
404
+ * // Undo the login
405
+ * undo();
406
+ *
407
+ * @param engine The base Praxis engine
408
+ * @param options History configuration
409
+ * @returns Enhanced engine with history methods
410
+ */
411
+ export function createHistoryEngine(engine, options = {}) {
412
+ const history = new HistoryStateManager(options.maxHistorySize);
413
+ // Record initial state
414
+ history.record(engine.getState(), [], options.initialLabel || 'Initial');
415
+ const dispatch = (events, label) => {
416
+ engine.step(events);
417
+ history.record(engine.getState(), events, label);
418
+ };
419
+ const undo = () => {
420
+ const entry = history.back();
421
+ if (entry) {
422
+ // Note: This is a simplified undo - in practice you might need to
423
+ // restore the state by replaying events or storing full snapshots
424
+ return true;
425
+ }
426
+ return false;
427
+ };
428
+ const redo = () => {
429
+ const entry = history.forward();
430
+ if (entry) {
431
+ return true;
432
+ }
433
+ return false;
434
+ };
435
+ return {
436
+ engine,
437
+ dispatch,
438
+ undo,
439
+ redo,
440
+ canUndo: () => history.canGoBack(),
441
+ canRedo: () => history.canGoForward(),
442
+ getHistory: () => history.getHistory(),
443
+ goToHistory: (index) => history.goTo(index) !== null,
444
+ clearHistory: () => history.clear(),
445
+ };
446
+ }
447
+ //# sourceMappingURL=svelte.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"svelte.js","sourceRoot":"","sources":["../../src/integrations/svelte.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAqBH;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,iBAAiB,CAC/B,MAA6B;IAI7B,IAAI,YAAY,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IACrC,MAAM,WAAW,GAAG,IAAI,GAAG,EAAkE,CAAC;IAE9F,MAAM,MAAM,GAAG,GAAG,EAAE;QAClB,YAAY,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;QACjC,WAAW,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC;IAClD,CAAC,CAAC;IAEF,OAAO;QACL,SAAS,CAAC,GAAmE;YAC3E,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACrB,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,sCAAsC;YACzD,OAAO,GAAG,EAAE;gBACV,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC1B,CAAC,CAAC;QACJ,CAAC;QACD,QAAQ,CAAC,MAAqB;YAC5B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACpB,MAAM,EAAE,CAAC;QACX,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAA6B;IAI7B,IAAI,cAAc,GAAG,MAAM,CAAC,UAAU,EAA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,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACnD,CAAC,CAAC;IAEF,MAAM,IAAI,GAAG,GAAY,EAAE;QACzB,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAC7B,IAAI,KAAK,EAAE,CAAC;YACV,kEAAkE;YAClE,kEAAkE;YAClE,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IAEF,MAAM,IAAI,GAAG,GAAY,EAAE;QACzB,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;QAChC,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IAEF,OAAO;QACL,MAAM;QACN,QAAQ;QACR,IAAI;QACJ,IAAI;QACJ,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE;QAClC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE;QACrC,UAAU,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,UAAU,EAAE;QACtC,WAAW,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI;QAC5D,YAAY,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE;KACpC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Registry for managing rules and constraints in Praxis.
3
+ * Provides registration, retrieval, and execution capabilities.
4
+ */
5
+ import type { PraxisState, PraxisEvent, Effect } from './types.js';
6
+ import type { Rule, Constraint, ConstraintViolation } from './dsl.js';
7
+ /**
8
+ * Registry for managing rules and constraints.
9
+ */
10
+ export declare class Registry<S extends PraxisState = PraxisState, E extends PraxisEvent = PraxisEvent> {
11
+ private rules;
12
+ private constraints;
13
+ /**
14
+ * Register a new rule.
15
+ * @throws Error if a rule with the same ID already exists
16
+ */
17
+ registerRule(rule: Rule<S, E>): void;
18
+ /**
19
+ * Register multiple rules at once.
20
+ */
21
+ registerRules(rules: Rule<S, E>[]): void;
22
+ /**
23
+ * Unregister a rule by ID.
24
+ */
25
+ unregisterRule(id: string): boolean;
26
+ /**
27
+ * Get a rule by ID.
28
+ */
29
+ getRule(id: string): Rule<S, E> | undefined;
30
+ /**
31
+ * Get all registered rules.
32
+ */
33
+ getAllRules(): Rule<S, E>[];
34
+ /**
35
+ * Get rules that match a specific event type.
36
+ */
37
+ getRulesForEvent(eventType: string): Rule<S, E>[];
38
+ /**
39
+ * Register a new constraint.
40
+ * @throws Error if a constraint with the same ID already exists
41
+ */
42
+ registerConstraint(constraint: Constraint<S>): void;
43
+ /**
44
+ * Register multiple constraints at once.
45
+ */
46
+ registerConstraints(constraints: Constraint<S>[]): void;
47
+ /**
48
+ * Unregister a constraint by ID.
49
+ */
50
+ unregisterConstraint(id: string): boolean;
51
+ /**
52
+ * Get a constraint by ID.
53
+ */
54
+ getConstraint(id: string): Constraint<S> | undefined;
55
+ /**
56
+ * Get all registered constraints.
57
+ */
58
+ getAllConstraints(): Constraint<S>[];
59
+ /**
60
+ * Evaluate all rules for a given state and event.
61
+ * Returns all effects produced by rules that fire.
62
+ */
63
+ evaluateRules(state: S, event: E): Effect[];
64
+ /**
65
+ * Check all constraints for a given state.
66
+ * Returns an array of violations (empty if all constraints pass).
67
+ */
68
+ checkConstraints(state: S): ConstraintViolation[];
69
+ /**
70
+ * Clear all rules from the registry.
71
+ */
72
+ clearRules(): void;
73
+ /**
74
+ * Clear all constraints from the registry.
75
+ */
76
+ clearConstraints(): void;
77
+ /**
78
+ * Clear all rules and constraints from the registry.
79
+ */
80
+ clear(): void;
81
+ /**
82
+ * Get statistics about the registry.
83
+ */
84
+ getStats(): {
85
+ ruleCount: number;
86
+ constraintCount: number;
87
+ rulesByEventType: Record<string, number>;
88
+ };
89
+ }
90
+ /**
91
+ * Create a new registry instance.
92
+ */
93
+ export declare function createRegistry<S extends PraxisState = PraxisState, E extends PraxisEvent = PraxisEvent>(): Registry<S, E>;
94
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEtE;;GAEG;AACH,qBAAa,QAAQ,CACnB,CAAC,SAAS,WAAW,GAAG,WAAW,EACnC,CAAC,SAAS,WAAW,GAAG,WAAW;IAEnC,OAAO,CAAC,KAAK,CAAsC;IACnD,OAAO,CAAC,WAAW,CAAyC;IAE5D;;;OAGG;IACH,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI;IAOpC;;OAEG;IACH,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI;IAMxC;;OAEG;IACH,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAInC;;OAEG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS;IAI3C;;OAEG;IACH,WAAW,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;IAI3B;;OAEG;IACH,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;IAMjD;;;OAGG;IACH,kBAAkB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI;IAOnD;;OAEG;IACH,mBAAmB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI;IAMvD;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