@plures/praxis 1.1.2 → 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.
- package/README.md +67 -6
- package/dist/browser/chunk-R45WXWKH.js +345 -0
- package/dist/browser/index.d.ts +171 -11
- package/dist/browser/index.js +279 -277
- package/dist/browser/integrations/svelte.d.ts +3 -1
- package/dist/browser/integrations/svelte.js +7 -0
- package/dist/browser/{engine-BjdqxeXG.d.ts → reactive-engine.svelte-C9OpcTHf.d.ts} +87 -1
- package/dist/node/chunk-R45WXWKH.js +345 -0
- package/dist/node/components/index.d.cts +2 -2
- package/dist/node/components/index.d.ts +2 -2
- package/dist/node/index.cjs +343 -8
- package/dist/node/index.d.cts +108 -15
- package/dist/node/index.d.ts +108 -15
- package/dist/node/index.js +279 -278
- package/dist/node/integrations/svelte.cjs +357 -2
- package/dist/node/integrations/svelte.d.cts +3 -1
- package/dist/node/integrations/svelte.d.ts +3 -1
- package/dist/node/integrations/svelte.js +6 -0
- package/dist/node/{engine-CVJobhHm.d.cts → reactive-engine.svelte-1M4m_C_v.d.cts} +87 -1
- package/dist/node/{engine-1iqLe6_P.d.ts → reactive-engine.svelte-ChNFn4Hj.d.ts} +87 -1
- package/dist/node/{terminal-adapter-XLtCjjb_.d.cts → terminal-adapter-CDzxoLKR.d.cts} +68 -1
- package/dist/node/{terminal-adapter-07HGftGQ.d.ts → terminal-adapter-CWka-yL8.d.ts} +68 -1
- package/package.json +3 -2
- package/src/__tests__/reactive-engine.test.ts +516 -0
- package/src/core/pluresdb/README.md +156 -0
- package/src/core/pluresdb/adapter.ts +165 -0
- package/src/core/pluresdb/index.ts +3 -3
- package/src/core/reactive-engine.svelte.ts +88 -19
- package/src/core/reactive-engine.ts +284 -22
- package/src/index.browser.ts +12 -0
- package/src/index.ts +12 -0
- package/src/integrations/pluresdb.ts +2 -2
- package/src/integrations/svelte.ts +8 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,21 +17,372 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/integrations/svelte.ts
|
|
21
31
|
var svelte_exports = {};
|
|
22
32
|
__export(svelte_exports, {
|
|
23
33
|
HistoryStateManager: () => HistoryStateManager,
|
|
34
|
+
ReactiveLogicEngine: () => ReactiveLogicEngine,
|
|
24
35
|
createContextStore: () => createContextStore,
|
|
25
36
|
createDerivedStore: () => createDerivedStore,
|
|
26
37
|
createHistoryEngine: () => createHistoryEngine,
|
|
27
38
|
createPraxisStore: () => createPraxisStore,
|
|
39
|
+
createReactiveEngine: () => createReactiveEngine,
|
|
28
40
|
usePraxisContext: () => usePraxisContext,
|
|
29
41
|
usePraxisEngine: () => usePraxisEngine,
|
|
30
42
|
usePraxisSubscription: () => usePraxisSubscription
|
|
31
43
|
});
|
|
32
44
|
module.exports = __toCommonJS(svelte_exports);
|
|
45
|
+
|
|
46
|
+
// src/core/reactive-engine.svelte.ts
|
|
47
|
+
var $ = __toESM(require("svelte/internal/client"), 1);
|
|
48
|
+
|
|
49
|
+
// src/core/rules.ts
|
|
50
|
+
var PraxisRegistry = class {
|
|
51
|
+
rules = /* @__PURE__ */ new Map();
|
|
52
|
+
constraints = /* @__PURE__ */ new Map();
|
|
53
|
+
/**
|
|
54
|
+
* Register a rule
|
|
55
|
+
*/
|
|
56
|
+
registerRule(descriptor) {
|
|
57
|
+
if (this.rules.has(descriptor.id)) {
|
|
58
|
+
throw new Error(`Rule with id "${descriptor.id}" already registered`);
|
|
59
|
+
}
|
|
60
|
+
this.rules.set(descriptor.id, descriptor);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Register a constraint
|
|
64
|
+
*/
|
|
65
|
+
registerConstraint(descriptor) {
|
|
66
|
+
if (this.constraints.has(descriptor.id)) {
|
|
67
|
+
throw new Error(`Constraint with id "${descriptor.id}" already registered`);
|
|
68
|
+
}
|
|
69
|
+
this.constraints.set(descriptor.id, descriptor);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Register a module (all its rules and constraints)
|
|
73
|
+
*/
|
|
74
|
+
registerModule(module2) {
|
|
75
|
+
for (const rule of module2.rules) {
|
|
76
|
+
this.registerRule(rule);
|
|
77
|
+
}
|
|
78
|
+
for (const constraint of module2.constraints) {
|
|
79
|
+
this.registerConstraint(constraint);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get a rule by ID
|
|
84
|
+
*/
|
|
85
|
+
getRule(id) {
|
|
86
|
+
return this.rules.get(id);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get a constraint by ID
|
|
90
|
+
*/
|
|
91
|
+
getConstraint(id) {
|
|
92
|
+
return this.constraints.get(id);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get all registered rule IDs
|
|
96
|
+
*/
|
|
97
|
+
getRuleIds() {
|
|
98
|
+
return Array.from(this.rules.keys());
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get all registered constraint IDs
|
|
102
|
+
*/
|
|
103
|
+
getConstraintIds() {
|
|
104
|
+
return Array.from(this.constraints.keys());
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get all rules
|
|
108
|
+
*/
|
|
109
|
+
getAllRules() {
|
|
110
|
+
return Array.from(this.rules.values());
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get all constraints
|
|
114
|
+
*/
|
|
115
|
+
getAllConstraints() {
|
|
116
|
+
return Array.from(this.constraints.values());
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// src/core/protocol.ts
|
|
121
|
+
var PRAXIS_PROTOCOL_VERSION = "1.0.0";
|
|
122
|
+
|
|
123
|
+
// src/core/engine.ts
|
|
124
|
+
function safeClone(value) {
|
|
125
|
+
if (value === null || typeof value !== "object") {
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
if (typeof globalThis.structuredClone === "function") {
|
|
129
|
+
try {
|
|
130
|
+
return globalThis.structuredClone(value);
|
|
131
|
+
} catch {
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (Array.isArray(value)) {
|
|
135
|
+
return [...value];
|
|
136
|
+
}
|
|
137
|
+
return { ...value };
|
|
138
|
+
}
|
|
139
|
+
var LogicEngine = class {
|
|
140
|
+
state;
|
|
141
|
+
registry;
|
|
142
|
+
constructor(options) {
|
|
143
|
+
this.registry = options.registry;
|
|
144
|
+
this.state = {
|
|
145
|
+
context: options.initialContext,
|
|
146
|
+
facts: options.initialFacts ?? [],
|
|
147
|
+
meta: options.initialMeta ?? {},
|
|
148
|
+
protocolVersion: PRAXIS_PROTOCOL_VERSION
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get the current state (immutable copy)
|
|
153
|
+
*/
|
|
154
|
+
getState() {
|
|
155
|
+
return {
|
|
156
|
+
context: safeClone(this.state.context),
|
|
157
|
+
facts: [...this.state.facts],
|
|
158
|
+
meta: this.state.meta ? safeClone(this.state.meta) : void 0,
|
|
159
|
+
protocolVersion: this.state.protocolVersion
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Get the current context
|
|
164
|
+
*/
|
|
165
|
+
getContext() {
|
|
166
|
+
return safeClone(this.state.context);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Get current facts
|
|
170
|
+
*/
|
|
171
|
+
getFacts() {
|
|
172
|
+
return [...this.state.facts];
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Process events through the engine.
|
|
176
|
+
* Applies all registered rules and checks all registered constraints.
|
|
177
|
+
*
|
|
178
|
+
* @param events Events to process
|
|
179
|
+
* @returns Result with new state and diagnostics
|
|
180
|
+
*/
|
|
181
|
+
step(events) {
|
|
182
|
+
const config = {
|
|
183
|
+
ruleIds: this.registry.getRuleIds(),
|
|
184
|
+
constraintIds: this.registry.getConstraintIds()
|
|
185
|
+
};
|
|
186
|
+
return this.stepWithConfig(events, config);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Process events with specific rule and constraint configuration.
|
|
190
|
+
*
|
|
191
|
+
* @param events Events to process
|
|
192
|
+
* @param config Step configuration
|
|
193
|
+
* @returns Result with new state and diagnostics
|
|
194
|
+
*/
|
|
195
|
+
stepWithConfig(events, config) {
|
|
196
|
+
const diagnostics = [];
|
|
197
|
+
let newState = { ...this.state };
|
|
198
|
+
const newFacts = [];
|
|
199
|
+
for (const ruleId of config.ruleIds) {
|
|
200
|
+
const rule = this.registry.getRule(ruleId);
|
|
201
|
+
if (!rule) {
|
|
202
|
+
diagnostics.push({
|
|
203
|
+
kind: "rule-error",
|
|
204
|
+
message: `Rule "${ruleId}" not found in registry`,
|
|
205
|
+
data: { ruleId }
|
|
206
|
+
});
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
const ruleFacts = rule.impl(newState, events);
|
|
211
|
+
newFacts.push(...ruleFacts);
|
|
212
|
+
} catch (error) {
|
|
213
|
+
diagnostics.push({
|
|
214
|
+
kind: "rule-error",
|
|
215
|
+
message: `Error executing rule "${ruleId}": ${error instanceof Error ? error.message : String(error)}`,
|
|
216
|
+
data: { ruleId, error }
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
newState = {
|
|
221
|
+
...newState,
|
|
222
|
+
facts: [...newState.facts, ...newFacts]
|
|
223
|
+
};
|
|
224
|
+
for (const constraintId of config.constraintIds) {
|
|
225
|
+
const constraint = this.registry.getConstraint(constraintId);
|
|
226
|
+
if (!constraint) {
|
|
227
|
+
diagnostics.push({
|
|
228
|
+
kind: "constraint-violation",
|
|
229
|
+
message: `Constraint "${constraintId}" not found in registry`,
|
|
230
|
+
data: { constraintId }
|
|
231
|
+
});
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
const result = constraint.impl(newState);
|
|
236
|
+
if (result === false) {
|
|
237
|
+
diagnostics.push({
|
|
238
|
+
kind: "constraint-violation",
|
|
239
|
+
message: `Constraint "${constraintId}" violated`,
|
|
240
|
+
data: { constraintId, description: constraint.description }
|
|
241
|
+
});
|
|
242
|
+
} else if (typeof result === "string") {
|
|
243
|
+
diagnostics.push({
|
|
244
|
+
kind: "constraint-violation",
|
|
245
|
+
message: result,
|
|
246
|
+
data: { constraintId, description: constraint.description }
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
} catch (error) {
|
|
250
|
+
diagnostics.push({
|
|
251
|
+
kind: "constraint-violation",
|
|
252
|
+
message: `Error checking constraint "${constraintId}": ${error instanceof Error ? error.message : String(error)}`,
|
|
253
|
+
data: { constraintId, error }
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
this.state = newState;
|
|
258
|
+
return {
|
|
259
|
+
state: newState,
|
|
260
|
+
diagnostics
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Update the context directly (for exceptional cases).
|
|
265
|
+
* Generally, context should be updated through rules.
|
|
266
|
+
*
|
|
267
|
+
* @param updater Function that produces new context from old context
|
|
268
|
+
*/
|
|
269
|
+
updateContext(updater) {
|
|
270
|
+
this.state = {
|
|
271
|
+
...this.state,
|
|
272
|
+
context: updater(this.state.context)
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Add facts directly (for exceptional cases).
|
|
277
|
+
* Generally, facts should be added through rules.
|
|
278
|
+
*
|
|
279
|
+
* @param facts Facts to add
|
|
280
|
+
*/
|
|
281
|
+
addFacts(facts) {
|
|
282
|
+
this.state = {
|
|
283
|
+
...this.state,
|
|
284
|
+
facts: [...this.state.facts, ...facts]
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Clear all facts
|
|
289
|
+
*/
|
|
290
|
+
clearFacts() {
|
|
291
|
+
this.state = {
|
|
292
|
+
...this.state,
|
|
293
|
+
facts: []
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Reset the engine to initial state
|
|
298
|
+
*/
|
|
299
|
+
reset(options) {
|
|
300
|
+
this.state = {
|
|
301
|
+
context: options.initialContext,
|
|
302
|
+
facts: options.initialFacts ?? [],
|
|
303
|
+
meta: options.initialMeta ?? {},
|
|
304
|
+
protocolVersion: PRAXIS_PROTOCOL_VERSION
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
function createPraxisEngine(options) {
|
|
309
|
+
return new LogicEngine(options);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// src/core/reactive-engine.svelte.ts
|
|
313
|
+
var ReactiveLogicEngine = class {
|
|
314
|
+
#state = (
|
|
315
|
+
// Use Svelte's $state rune for automatic reactivity
|
|
316
|
+
$.state($.proxy({ context: {}, facts: [], meta: {} }))
|
|
317
|
+
);
|
|
318
|
+
get state() {
|
|
319
|
+
return $.get(this.#state);
|
|
320
|
+
}
|
|
321
|
+
set state(value) {
|
|
322
|
+
$.set(this.#state, value, true);
|
|
323
|
+
}
|
|
324
|
+
_engine;
|
|
325
|
+
constructor(options) {
|
|
326
|
+
this.state.context = options.initialContext;
|
|
327
|
+
this.state.facts = options.initialFacts ?? [];
|
|
328
|
+
this.state.meta = options.initialMeta ?? {};
|
|
329
|
+
if (options.registry) {
|
|
330
|
+
this._engine = createPraxisEngine({
|
|
331
|
+
initialContext: options.initialContext,
|
|
332
|
+
registry: options.registry
|
|
333
|
+
});
|
|
334
|
+
} else {
|
|
335
|
+
this._engine = createPraxisEngine({
|
|
336
|
+
initialContext: options.initialContext,
|
|
337
|
+
registry: new PraxisRegistry()
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Access the reactive context.
|
|
343
|
+
* In Svelte 5 components, changes to this object will automatically trigger updates.
|
|
344
|
+
*/
|
|
345
|
+
get context() {
|
|
346
|
+
return this.state.context;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Access the reactive facts list.
|
|
350
|
+
*/
|
|
351
|
+
get facts() {
|
|
352
|
+
return this.state.facts;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Access the reactive metadata.
|
|
356
|
+
*/
|
|
357
|
+
get meta() {
|
|
358
|
+
return this.state.meta;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Apply a mutation to the state.
|
|
362
|
+
* Changes will automatically trigger Svelte reactivity.
|
|
363
|
+
*
|
|
364
|
+
* @param mutator A function that receives the state and modifies it.
|
|
365
|
+
*/
|
|
366
|
+
apply(mutator) {
|
|
367
|
+
mutator(this.state);
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Process events through the logic engine and update reactive state.
|
|
371
|
+
*
|
|
372
|
+
* @param events Events to process
|
|
373
|
+
*/
|
|
374
|
+
step(events) {
|
|
375
|
+
const result = this._engine.step(events);
|
|
376
|
+
this.state.context = result.state.context;
|
|
377
|
+
this.state.facts = result.state.facts;
|
|
378
|
+
this.state.meta = result.state.meta ?? {};
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
function createReactiveEngine(options) {
|
|
382
|
+
return new ReactiveLogicEngine(options);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// src/integrations/svelte.ts
|
|
33
386
|
function createPraxisStore(engine) {
|
|
34
387
|
let currentState = engine.getState();
|
|
35
388
|
const subscribers = /* @__PURE__ */ new Set();
|
|
@@ -198,14 +551,14 @@ var HistoryStateManager = class {
|
|
|
198
551
|
/**
|
|
199
552
|
* Record a new history entry
|
|
200
553
|
*/
|
|
201
|
-
record(
|
|
554
|
+
record(state2, events, label) {
|
|
202
555
|
if (this.currentIndex < this.history.length - 1) {
|
|
203
556
|
this.history = this.history.slice(0, this.currentIndex + 1);
|
|
204
557
|
}
|
|
205
558
|
this.history.push({
|
|
206
559
|
id: `history-${++this.idCounter}`,
|
|
207
560
|
timestamp: Date.now(),
|
|
208
|
-
state,
|
|
561
|
+
state: state2,
|
|
209
562
|
events,
|
|
210
563
|
label
|
|
211
564
|
});
|
|
@@ -320,10 +673,12 @@ function createHistoryEngine(engine, options = {}) {
|
|
|
320
673
|
// Annotate the CommonJS export names for ESM import in node:
|
|
321
674
|
0 && (module.exports = {
|
|
322
675
|
HistoryStateManager,
|
|
676
|
+
ReactiveLogicEngine,
|
|
323
677
|
createContextStore,
|
|
324
678
|
createDerivedStore,
|
|
325
679
|
createHistoryEngine,
|
|
326
680
|
createPraxisStore,
|
|
681
|
+
createReactiveEngine,
|
|
327
682
|
usePraxisContext,
|
|
328
683
|
usePraxisEngine,
|
|
329
684
|
usePraxisSubscription
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { L as LogicEngine } from '../engine-
|
|
1
|
+
import { L as LogicEngine } from '../reactive-engine.svelte-1M4m_C_v.cjs';
|
|
2
|
+
export { a as ReactiveEngineOptions, R as ReactiveLogicEngine, c as createReactiveEngine } from '../reactive-engine.svelte-1M4m_C_v.cjs';
|
|
2
3
|
import { P as PraxisState, a as PraxisEvent } from '../protocol-Qek7ebBl.cjs';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -10,6 +11,7 @@ import { P as PraxisState, a as PraxisEvent } from '../protocol-Qek7ebBl.cjs';
|
|
|
10
11
|
* Features:
|
|
11
12
|
* - Store-based API for backward compatibility
|
|
12
13
|
* - Runes-based composables for Svelte 5
|
|
14
|
+
* - createReactiveEngine for easy reactive engine setup
|
|
13
15
|
* - Snapshot support for time-travel debugging
|
|
14
16
|
* - History state pattern implementation
|
|
15
17
|
* - Automatic cleanup and subscription management
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { L as LogicEngine } from '../engine-
|
|
1
|
+
import { L as LogicEngine } from '../reactive-engine.svelte-ChNFn4Hj.js';
|
|
2
|
+
export { a as ReactiveEngineOptions, R as ReactiveLogicEngine, c as createReactiveEngine } from '../reactive-engine.svelte-ChNFn4Hj.js';
|
|
2
3
|
import { P as PraxisState, a as PraxisEvent } from '../protocol-Qek7ebBl.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -10,6 +11,7 @@ import { P as PraxisState, a as PraxisEvent } from '../protocol-Qek7ebBl.js';
|
|
|
10
11
|
* Features:
|
|
11
12
|
* - Store-based API for backward compatibility
|
|
12
13
|
* - Runes-based composables for Svelte 5
|
|
14
|
+
* - createReactiveEngine for easy reactive engine setup
|
|
13
15
|
* - Snapshot support for time-travel debugging
|
|
14
16
|
* - History state pattern implementation
|
|
15
17
|
* - Automatic cleanup and subscription management
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ReactiveLogicEngine,
|
|
3
|
+
createReactiveEngine
|
|
4
|
+
} from "../chunk-R45WXWKH.js";
|
|
1
5
|
import "../chunk-QGM4M3NI.js";
|
|
2
6
|
|
|
3
7
|
// src/integrations/svelte.ts
|
|
@@ -290,10 +294,12 @@ function createHistoryEngine(engine, options = {}) {
|
|
|
290
294
|
}
|
|
291
295
|
export {
|
|
292
296
|
HistoryStateManager,
|
|
297
|
+
ReactiveLogicEngine,
|
|
293
298
|
createContextStore,
|
|
294
299
|
createDerivedStore,
|
|
295
300
|
createHistoryEngine,
|
|
296
301
|
createPraxisStore,
|
|
302
|
+
createReactiveEngine,
|
|
297
303
|
usePraxisContext,
|
|
298
304
|
usePraxisEngine,
|
|
299
305
|
usePraxisSubscription
|
|
@@ -211,4 +211,90 @@ declare class LogicEngine<TContext = unknown> {
|
|
|
211
211
|
*/
|
|
212
212
|
declare function createPraxisEngine<TContext = unknown>(options: PraxisEngineOptions<TContext>): LogicEngine<TContext>;
|
|
213
213
|
|
|
214
|
-
|
|
214
|
+
/**
|
|
215
|
+
* Praxis Reactive Logic Engine - Svelte 5 Implementation
|
|
216
|
+
*
|
|
217
|
+
* This version uses Svelte 5 runes ($state) for built-in reactivity.
|
|
218
|
+
* The state object is automatically reactive when used in Svelte components.
|
|
219
|
+
*/
|
|
220
|
+
|
|
221
|
+
interface ReactiveEngineOptions<TContext> {
|
|
222
|
+
initialContext: TContext;
|
|
223
|
+
initialFacts?: any[];
|
|
224
|
+
initialMeta?: Record<string, unknown>;
|
|
225
|
+
registry?: PraxisRegistry<TContext>;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Reactive Logic Engine using Svelte 5 runes.
|
|
229
|
+
* Combines the standard LogicEngine with reactive state management.
|
|
230
|
+
*/
|
|
231
|
+
declare class ReactiveLogicEngine<TContext extends object> {
|
|
232
|
+
state: {
|
|
233
|
+
context: TContext;
|
|
234
|
+
facts: any[];
|
|
235
|
+
meta: Record<string, unknown>;
|
|
236
|
+
};
|
|
237
|
+
private _engine;
|
|
238
|
+
constructor(options: ReactiveEngineOptions<TContext>);
|
|
239
|
+
/**
|
|
240
|
+
* Access the reactive context.
|
|
241
|
+
* In Svelte 5 components, changes to this object will automatically trigger updates.
|
|
242
|
+
*/
|
|
243
|
+
get context(): TContext;
|
|
244
|
+
/**
|
|
245
|
+
* Access the reactive facts list.
|
|
246
|
+
*/
|
|
247
|
+
get facts(): any[];
|
|
248
|
+
/**
|
|
249
|
+
* Access the reactive metadata.
|
|
250
|
+
*/
|
|
251
|
+
get meta(): Record<string, unknown>;
|
|
252
|
+
/**
|
|
253
|
+
* Apply a mutation to the state.
|
|
254
|
+
* Changes will automatically trigger Svelte reactivity.
|
|
255
|
+
*
|
|
256
|
+
* @param mutator A function that receives the state and modifies it.
|
|
257
|
+
*/
|
|
258
|
+
apply(mutator: (state: {
|
|
259
|
+
context: TContext;
|
|
260
|
+
facts: any[];
|
|
261
|
+
meta: Record<string, unknown>;
|
|
262
|
+
}) => void): void;
|
|
263
|
+
/**
|
|
264
|
+
* Process events through the logic engine and update reactive state.
|
|
265
|
+
*
|
|
266
|
+
* @param events Events to process
|
|
267
|
+
*/
|
|
268
|
+
step(events: PraxisEvent[]): void;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Create a reactive logic engine with Svelte 5 runes.
|
|
272
|
+
*
|
|
273
|
+
* @param options Configuration options
|
|
274
|
+
* @returns A reactive logic engine instance
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```svelte
|
|
278
|
+
* <script lang="ts">
|
|
279
|
+
* import { createReactiveEngine } from '@plures/praxis/svelte';
|
|
280
|
+
*
|
|
281
|
+
* const engine = createReactiveEngine({
|
|
282
|
+
* initialContext: { count: 0 },
|
|
283
|
+
* registry
|
|
284
|
+
* });
|
|
285
|
+
*
|
|
286
|
+
* // Use $derived for computed values
|
|
287
|
+
* const count = $derived(engine.context.count);
|
|
288
|
+
* const doubled = $derived(engine.context.count * 2);
|
|
289
|
+
*
|
|
290
|
+
* function increment() {
|
|
291
|
+
* engine.step([Increment.create({ amount: 1 })]);
|
|
292
|
+
* }
|
|
293
|
+
* </script>
|
|
294
|
+
*
|
|
295
|
+
* <button on:click={increment}>Count: {count}, Doubled: {doubled}</button>
|
|
296
|
+
* ```
|
|
297
|
+
*/
|
|
298
|
+
declare function createReactiveEngine<TContext extends object>(options: ReactiveEngineOptions<TContext>): ReactiveLogicEngine<TContext>;
|
|
299
|
+
|
|
300
|
+
export { type ConstraintDescriptor as C, LogicEngine as L, PraxisRegistry as P, ReactiveLogicEngine as R, type ReactiveEngineOptions as a, type RuleDescriptor as b, createReactiveEngine as c, type RuleFn as d, type ConstraintFn as e, type PraxisModule as f, type RuleId as g, type ConstraintId as h, type PraxisEngineOptions as i, createPraxisEngine as j };
|
|
@@ -211,4 +211,90 @@ declare class LogicEngine<TContext = unknown> {
|
|
|
211
211
|
*/
|
|
212
212
|
declare function createPraxisEngine<TContext = unknown>(options: PraxisEngineOptions<TContext>): LogicEngine<TContext>;
|
|
213
213
|
|
|
214
|
-
|
|
214
|
+
/**
|
|
215
|
+
* Praxis Reactive Logic Engine - Svelte 5 Implementation
|
|
216
|
+
*
|
|
217
|
+
* This version uses Svelte 5 runes ($state) for built-in reactivity.
|
|
218
|
+
* The state object is automatically reactive when used in Svelte components.
|
|
219
|
+
*/
|
|
220
|
+
|
|
221
|
+
interface ReactiveEngineOptions<TContext> {
|
|
222
|
+
initialContext: TContext;
|
|
223
|
+
initialFacts?: any[];
|
|
224
|
+
initialMeta?: Record<string, unknown>;
|
|
225
|
+
registry?: PraxisRegistry<TContext>;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Reactive Logic Engine using Svelte 5 runes.
|
|
229
|
+
* Combines the standard LogicEngine with reactive state management.
|
|
230
|
+
*/
|
|
231
|
+
declare class ReactiveLogicEngine<TContext extends object> {
|
|
232
|
+
state: {
|
|
233
|
+
context: TContext;
|
|
234
|
+
facts: any[];
|
|
235
|
+
meta: Record<string, unknown>;
|
|
236
|
+
};
|
|
237
|
+
private _engine;
|
|
238
|
+
constructor(options: ReactiveEngineOptions<TContext>);
|
|
239
|
+
/**
|
|
240
|
+
* Access the reactive context.
|
|
241
|
+
* In Svelte 5 components, changes to this object will automatically trigger updates.
|
|
242
|
+
*/
|
|
243
|
+
get context(): TContext;
|
|
244
|
+
/**
|
|
245
|
+
* Access the reactive facts list.
|
|
246
|
+
*/
|
|
247
|
+
get facts(): any[];
|
|
248
|
+
/**
|
|
249
|
+
* Access the reactive metadata.
|
|
250
|
+
*/
|
|
251
|
+
get meta(): Record<string, unknown>;
|
|
252
|
+
/**
|
|
253
|
+
* Apply a mutation to the state.
|
|
254
|
+
* Changes will automatically trigger Svelte reactivity.
|
|
255
|
+
*
|
|
256
|
+
* @param mutator A function that receives the state and modifies it.
|
|
257
|
+
*/
|
|
258
|
+
apply(mutator: (state: {
|
|
259
|
+
context: TContext;
|
|
260
|
+
facts: any[];
|
|
261
|
+
meta: Record<string, unknown>;
|
|
262
|
+
}) => void): void;
|
|
263
|
+
/**
|
|
264
|
+
* Process events through the logic engine and update reactive state.
|
|
265
|
+
*
|
|
266
|
+
* @param events Events to process
|
|
267
|
+
*/
|
|
268
|
+
step(events: PraxisEvent[]): void;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Create a reactive logic engine with Svelte 5 runes.
|
|
272
|
+
*
|
|
273
|
+
* @param options Configuration options
|
|
274
|
+
* @returns A reactive logic engine instance
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```svelte
|
|
278
|
+
* <script lang="ts">
|
|
279
|
+
* import { createReactiveEngine } from '@plures/praxis/svelte';
|
|
280
|
+
*
|
|
281
|
+
* const engine = createReactiveEngine({
|
|
282
|
+
* initialContext: { count: 0 },
|
|
283
|
+
* registry
|
|
284
|
+
* });
|
|
285
|
+
*
|
|
286
|
+
* // Use $derived for computed values
|
|
287
|
+
* const count = $derived(engine.context.count);
|
|
288
|
+
* const doubled = $derived(engine.context.count * 2);
|
|
289
|
+
*
|
|
290
|
+
* function increment() {
|
|
291
|
+
* engine.step([Increment.create({ amount: 1 })]);
|
|
292
|
+
* }
|
|
293
|
+
* </script>
|
|
294
|
+
*
|
|
295
|
+
* <button on:click={increment}>Count: {count}, Doubled: {doubled}</button>
|
|
296
|
+
* ```
|
|
297
|
+
*/
|
|
298
|
+
declare function createReactiveEngine<TContext extends object>(options: ReactiveEngineOptions<TContext>): ReactiveLogicEngine<TContext>;
|
|
299
|
+
|
|
300
|
+
export { type ConstraintDescriptor as C, LogicEngine as L, PraxisRegistry as P, ReactiveLogicEngine as R, type ReactiveEngineOptions as a, type RuleDescriptor as b, createReactiveEngine as c, type RuleFn as d, type ConstraintFn as e, type PraxisModule as f, type RuleId as g, type ConstraintId as h, type PraxisEngineOptions as i, createPraxisEngine as j };
|