@plures/praxis 1.1.3 → 1.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.
@@ -1,11 +1,19 @@
1
1
  import {
2
- LogicEngine,
3
- PRAXIS_PROTOCOL_VERSION,
4
2
  PraxisRegistry,
5
3
  ReactiveLogicEngine,
6
- createPraxisEngine,
7
4
  createReactiveEngine
8
- } from "./chunk-R45WXWKH.js";
5
+ } from "./chunk-LE2ZJYFC.js";
6
+ import {
7
+ LogicEngine,
8
+ PRAXIS_PROTOCOL_VERSION,
9
+ createPraxisEngine
10
+ } from "./chunk-VOMLVI6V.js";
11
+ import {
12
+ InMemoryPraxisDB,
13
+ PluresDBPraxisAdapter,
14
+ createInMemoryDB,
15
+ createPluresDB
16
+ } from "./chunk-JQ64KMLN.js";
9
17
 
10
18
  // src/core/reactive-engine.ts
11
19
  var ReactiveLogicEngine2 = class _ReactiveLogicEngine {
@@ -1148,141 +1156,6 @@ function createPraxisDBStore(db, registry, initialContext, onRuleError) {
1148
1156
  return new PraxisDBStore({ db, registry, initialContext, onRuleError });
1149
1157
  }
1150
1158
 
1151
- // src/core/pluresdb/adapter.ts
1152
- var InMemoryPraxisDB = class {
1153
- store = /* @__PURE__ */ new Map();
1154
- watchers = /* @__PURE__ */ new Map();
1155
- async get(key) {
1156
- return this.store.get(key);
1157
- }
1158
- async set(key, value) {
1159
- this.store.set(key, value);
1160
- const keyWatchers = this.watchers.get(key);
1161
- if (keyWatchers) {
1162
- for (const callback of keyWatchers) {
1163
- callback(value);
1164
- }
1165
- }
1166
- }
1167
- watch(key, callback) {
1168
- if (!this.watchers.has(key)) {
1169
- this.watchers.set(key, /* @__PURE__ */ new Set());
1170
- }
1171
- const watchers = this.watchers.get(key);
1172
- const wrappedCallback = (val) => callback(val);
1173
- watchers.add(wrappedCallback);
1174
- return () => {
1175
- watchers.delete(wrappedCallback);
1176
- if (watchers.size === 0) {
1177
- this.watchers.delete(key);
1178
- }
1179
- };
1180
- }
1181
- /**
1182
- * Get all keys (for testing/debugging)
1183
- */
1184
- keys() {
1185
- return Array.from(this.store.keys());
1186
- }
1187
- /**
1188
- * Clear all data (for testing)
1189
- */
1190
- clear() {
1191
- this.store.clear();
1192
- this.watchers.clear();
1193
- }
1194
- };
1195
- function createInMemoryDB() {
1196
- return new InMemoryPraxisDB();
1197
- }
1198
- var PluresDBPraxisAdapter = class {
1199
- db;
1200
- watchers = /* @__PURE__ */ new Map();
1201
- pollIntervals = /* @__PURE__ */ new Map();
1202
- lastValues = /* @__PURE__ */ new Map();
1203
- pollInterval;
1204
- constructor(config) {
1205
- if ("get" in config && "put" in config) {
1206
- this.db = config;
1207
- this.pollInterval = 1e3;
1208
- } else {
1209
- this.db = config.db;
1210
- this.pollInterval = config.pollInterval ?? 1e3;
1211
- }
1212
- }
1213
- async get(key) {
1214
- try {
1215
- const value = await this.db.get(key);
1216
- return value;
1217
- } catch (error) {
1218
- return void 0;
1219
- }
1220
- }
1221
- async set(key, value) {
1222
- await this.db.put(key, value);
1223
- this.lastValues.set(key, value);
1224
- const keyWatchers = this.watchers.get(key);
1225
- if (keyWatchers) {
1226
- for (const callback of keyWatchers) {
1227
- callback(value);
1228
- }
1229
- }
1230
- }
1231
- watch(key, callback) {
1232
- if (!this.watchers.has(key)) {
1233
- this.watchers.set(key, /* @__PURE__ */ new Set());
1234
- }
1235
- const watchers = this.watchers.get(key);
1236
- const wrappedCallback = (val) => callback(val);
1237
- watchers.add(wrappedCallback);
1238
- if (!this.pollIntervals.has(key)) {
1239
- const interval = setInterval(async () => {
1240
- try {
1241
- const value = await this.db.get(key);
1242
- const lastValue = this.lastValues.get(key);
1243
- if (JSON.stringify(value) !== JSON.stringify(lastValue)) {
1244
- this.lastValues.set(key, value);
1245
- const currentWatchers = this.watchers.get(key);
1246
- if (currentWatchers) {
1247
- for (const cb of currentWatchers) {
1248
- cb(value);
1249
- }
1250
- }
1251
- }
1252
- } catch (error) {
1253
- }
1254
- }, this.pollInterval);
1255
- this.pollIntervals.set(key, interval);
1256
- }
1257
- return () => {
1258
- watchers.delete(wrappedCallback);
1259
- if (watchers.size === 0) {
1260
- this.watchers.delete(key);
1261
- const interval = this.pollIntervals.get(key);
1262
- if (interval) {
1263
- clearInterval(interval);
1264
- this.pollIntervals.delete(key);
1265
- }
1266
- this.lastValues.delete(key);
1267
- }
1268
- };
1269
- }
1270
- /**
1271
- * Clean up all resources
1272
- */
1273
- dispose() {
1274
- for (const interval of this.pollIntervals.values()) {
1275
- clearInterval(interval);
1276
- }
1277
- this.pollIntervals.clear();
1278
- this.watchers.clear();
1279
- this.lastValues.clear();
1280
- }
1281
- };
1282
- function createPluresDB(config) {
1283
- return new PluresDBPraxisAdapter(config);
1284
- }
1285
-
1286
1159
  // src/core/pluresdb/schema-registry.ts
1287
1160
  function getSchemaPath(schemaName) {
1288
1161
  return `${PRAXIS_PATHS.SCHEMAS}/${schemaName}`;
@@ -2830,6 +2703,138 @@ function generateTauriConfig(config) {
2830
2703
  plugins: Object.fromEntries((config.plugins || []).map((p) => [p.name, p.config || {}]))
2831
2704
  };
2832
2705
  }
2706
+
2707
+ // src/integrations/unified.ts
2708
+ async function createUnifiedApp(config) {
2709
+ const { createPraxisEngine: createPraxisEngine2 } = await import("./engine-YJZV4SLD.js");
2710
+ const { createInMemoryDB: createInMemoryDB2 } = await import("./adapter-TM4IS5KT.js");
2711
+ const db = config.db || createInMemoryDB2();
2712
+ const pluresdb = createPluresDBAdapter({
2713
+ db,
2714
+ registry: config.registry,
2715
+ initialContext: config.initialContext
2716
+ });
2717
+ const engine = createPraxisEngine2({
2718
+ initialContext: config.initialContext,
2719
+ registry: config.registry
2720
+ });
2721
+ pluresdb.attachEngine(engine);
2722
+ const disposers = [];
2723
+ let unum;
2724
+ let channel;
2725
+ if (config.enableUnum) {
2726
+ const fullIdentity = config.unumIdentity ? {
2727
+ ...config.unumIdentity,
2728
+ id: generateId(),
2729
+ createdAt: Date.now()
2730
+ } : void 0;
2731
+ unum = await createUnumAdapter({
2732
+ db,
2733
+ identity: fullIdentity,
2734
+ realtime: true
2735
+ });
2736
+ channel = await unum.createChannel(
2737
+ config.unumIdentity?.name || "praxis-app",
2738
+ []
2739
+ );
2740
+ const unumDisposer = attachUnumToEngine(engine, unum, channel.id);
2741
+ disposers.push(unumDisposer);
2742
+ }
2743
+ let docs;
2744
+ let generateDocs2;
2745
+ if (config.enableDocs && config.docsConfig) {
2746
+ docs = createStateDocsGenerator({
2747
+ projectTitle: config.docsConfig.projectTitle,
2748
+ target: config.docsConfig.target || "./docs"
2749
+ });
2750
+ generateDocs2 = () => {
2751
+ const module = {
2752
+ rules: config.registry.getAllRules(),
2753
+ constraints: config.registry.getAllConstraints()
2754
+ };
2755
+ return docs.generateFromModule(module);
2756
+ };
2757
+ }
2758
+ let canvas;
2759
+ if (config.schema) {
2760
+ canvas = schemaToCanvas(config.schema, { layout: "hierarchical" });
2761
+ }
2762
+ return {
2763
+ engine,
2764
+ pluresdb,
2765
+ unum,
2766
+ channel,
2767
+ docs,
2768
+ canvas,
2769
+ generateDocs: generateDocs2,
2770
+ dispose: () => {
2771
+ pluresdb.dispose();
2772
+ if (unum) {
2773
+ unum.disconnect().catch((err) => {
2774
+ console.warn("Warning: Error during Unum disconnect:", err);
2775
+ });
2776
+ }
2777
+ for (const disposer of disposers) {
2778
+ disposer();
2779
+ }
2780
+ }
2781
+ };
2782
+ }
2783
+ async function attachAllIntegrations(engine, registry, options = {}) {
2784
+ const { createInMemoryDB: createInMemoryDB2 } = await import("./adapter-TM4IS5KT.js");
2785
+ const db = options.db || createInMemoryDB2();
2786
+ const pluresdb = createPluresDBAdapter({
2787
+ db,
2788
+ registry,
2789
+ initialContext: engine.getContext()
2790
+ });
2791
+ pluresdb.attachEngine(engine);
2792
+ const disposers = [];
2793
+ let unum;
2794
+ let channel;
2795
+ if (options.enableUnum) {
2796
+ const fullIdentity = options.unumIdentity ? {
2797
+ ...options.unumIdentity,
2798
+ id: generateId(),
2799
+ createdAt: Date.now()
2800
+ } : void 0;
2801
+ unum = await createUnumAdapter({
2802
+ db,
2803
+ identity: fullIdentity,
2804
+ realtime: true
2805
+ });
2806
+ channel = await unum.createChannel(
2807
+ options.unumIdentity?.name || "praxis-app",
2808
+ []
2809
+ );
2810
+ const unumDisposer = attachUnumToEngine(engine, unum, channel.id);
2811
+ disposers.push(unumDisposer);
2812
+ }
2813
+ let docs;
2814
+ if (options.enableDocs && options.docsConfig) {
2815
+ docs = createStateDocsGenerator({
2816
+ projectTitle: options.docsConfig.projectTitle,
2817
+ target: options.docsConfig.target || "./docs"
2818
+ });
2819
+ }
2820
+ return {
2821
+ pluresdb,
2822
+ unum,
2823
+ channel,
2824
+ docs,
2825
+ dispose: () => {
2826
+ pluresdb.dispose();
2827
+ if (unum) {
2828
+ unum.disconnect().catch((err) => {
2829
+ console.warn("Warning: Error during Unum disconnect:", err);
2830
+ });
2831
+ }
2832
+ for (const disposer of disposers) {
2833
+ disposer();
2834
+ }
2835
+ }
2836
+ };
2837
+ }
2833
2838
  export {
2834
2839
  ActorManager,
2835
2840
  ReactiveLogicEngine2 as FrameworkAgnosticReactiveEngine,
@@ -2845,6 +2850,7 @@ export {
2845
2850
  ReactiveLogicEngine,
2846
2851
  RegistryIntrospector,
2847
2852
  StateDocsGenerator,
2853
+ attachAllIntegrations,
2848
2854
  attachTauriToEngine,
2849
2855
  attachToEngine,
2850
2856
  attachUnumToEngine,
@@ -2868,6 +2874,7 @@ export {
2868
2874
  createStateDocsGenerator,
2869
2875
  createTauriPraxisAdapter,
2870
2876
  createTimerActor,
2877
+ createUnifiedApp,
2871
2878
  createUnumAdapter,
2872
2879
  defineConstraint,
2873
2880
  defineEvent,
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  ReactiveLogicEngine,
3
3
  createReactiveEngine
4
- } from "../chunk-R45WXWKH.js";
4
+ } from "../chunk-LE2ZJYFC.js";
5
+ import "../chunk-VOMLVI6V.js";
5
6
 
6
7
  // src/integrations/svelte.ts
7
8
  function createPraxisStore(engine) {
@@ -0,0 +1,13 @@
1
+ import {
2
+ InMemoryPraxisDB,
3
+ PluresDBPraxisAdapter,
4
+ createInMemoryDB,
5
+ createPluresDB
6
+ } from "./chunk-JQ64KMLN.js";
7
+ import "./chunk-QGM4M3NI.js";
8
+ export {
9
+ InMemoryPraxisDB,
10
+ PluresDBPraxisAdapter,
11
+ createInMemoryDB,
12
+ createPluresDB
13
+ };
@@ -0,0 +1,141 @@
1
+ // src/core/pluresdb/adapter.ts
2
+ var InMemoryPraxisDB = class {
3
+ store = /* @__PURE__ */ new Map();
4
+ watchers = /* @__PURE__ */ new Map();
5
+ async get(key) {
6
+ return this.store.get(key);
7
+ }
8
+ async set(key, value) {
9
+ this.store.set(key, value);
10
+ const keyWatchers = this.watchers.get(key);
11
+ if (keyWatchers) {
12
+ for (const callback of keyWatchers) {
13
+ callback(value);
14
+ }
15
+ }
16
+ }
17
+ watch(key, callback) {
18
+ if (!this.watchers.has(key)) {
19
+ this.watchers.set(key, /* @__PURE__ */ new Set());
20
+ }
21
+ const watchers = this.watchers.get(key);
22
+ const wrappedCallback = (val) => callback(val);
23
+ watchers.add(wrappedCallback);
24
+ return () => {
25
+ watchers.delete(wrappedCallback);
26
+ if (watchers.size === 0) {
27
+ this.watchers.delete(key);
28
+ }
29
+ };
30
+ }
31
+ /**
32
+ * Get all keys (for testing/debugging)
33
+ */
34
+ keys() {
35
+ return Array.from(this.store.keys());
36
+ }
37
+ /**
38
+ * Clear all data (for testing)
39
+ */
40
+ clear() {
41
+ this.store.clear();
42
+ this.watchers.clear();
43
+ }
44
+ };
45
+ function createInMemoryDB() {
46
+ return new InMemoryPraxisDB();
47
+ }
48
+ var PluresDBPraxisAdapter = class {
49
+ db;
50
+ watchers = /* @__PURE__ */ new Map();
51
+ pollIntervals = /* @__PURE__ */ new Map();
52
+ lastValues = /* @__PURE__ */ new Map();
53
+ pollInterval;
54
+ constructor(config) {
55
+ if ("get" in config && "put" in config) {
56
+ this.db = config;
57
+ this.pollInterval = 1e3;
58
+ } else {
59
+ this.db = config.db;
60
+ this.pollInterval = config.pollInterval ?? 1e3;
61
+ }
62
+ }
63
+ async get(key) {
64
+ try {
65
+ const value = await this.db.get(key);
66
+ return value;
67
+ } catch (error) {
68
+ return void 0;
69
+ }
70
+ }
71
+ async set(key, value) {
72
+ await this.db.put(key, value);
73
+ this.lastValues.set(key, value);
74
+ const keyWatchers = this.watchers.get(key);
75
+ if (keyWatchers) {
76
+ for (const callback of keyWatchers) {
77
+ callback(value);
78
+ }
79
+ }
80
+ }
81
+ watch(key, callback) {
82
+ if (!this.watchers.has(key)) {
83
+ this.watchers.set(key, /* @__PURE__ */ new Set());
84
+ }
85
+ const watchers = this.watchers.get(key);
86
+ const wrappedCallback = (val) => callback(val);
87
+ watchers.add(wrappedCallback);
88
+ if (!this.pollIntervals.has(key)) {
89
+ const interval = setInterval(async () => {
90
+ try {
91
+ const value = await this.db.get(key);
92
+ const lastValue = this.lastValues.get(key);
93
+ if (JSON.stringify(value) !== JSON.stringify(lastValue)) {
94
+ this.lastValues.set(key, value);
95
+ const currentWatchers = this.watchers.get(key);
96
+ if (currentWatchers) {
97
+ for (const cb of currentWatchers) {
98
+ cb(value);
99
+ }
100
+ }
101
+ }
102
+ } catch (error) {
103
+ }
104
+ }, this.pollInterval);
105
+ this.pollIntervals.set(key, interval);
106
+ }
107
+ return () => {
108
+ watchers.delete(wrappedCallback);
109
+ if (watchers.size === 0) {
110
+ this.watchers.delete(key);
111
+ const interval = this.pollIntervals.get(key);
112
+ if (interval) {
113
+ clearInterval(interval);
114
+ this.pollIntervals.delete(key);
115
+ }
116
+ this.lastValues.delete(key);
117
+ }
118
+ };
119
+ }
120
+ /**
121
+ * Clean up all resources
122
+ */
123
+ dispose() {
124
+ for (const interval of this.pollIntervals.values()) {
125
+ clearInterval(interval);
126
+ }
127
+ this.pollIntervals.clear();
128
+ this.watchers.clear();
129
+ this.lastValues.clear();
130
+ }
131
+ };
132
+ function createPluresDB(config) {
133
+ return new PluresDBPraxisAdapter(config);
134
+ }
135
+
136
+ export {
137
+ InMemoryPraxisDB,
138
+ createInMemoryDB,
139
+ PluresDBPraxisAdapter,
140
+ createPluresDB
141
+ };
@@ -0,0 +1,154 @@
1
+ import {
2
+ createPraxisEngine
3
+ } from "./chunk-VOMLVI6V.js";
4
+
5
+ // src/core/rules.ts
6
+ var PraxisRegistry = class {
7
+ rules = /* @__PURE__ */ new Map();
8
+ constraints = /* @__PURE__ */ new Map();
9
+ /**
10
+ * Register a rule
11
+ */
12
+ registerRule(descriptor) {
13
+ if (this.rules.has(descriptor.id)) {
14
+ throw new Error(`Rule with id "${descriptor.id}" already registered`);
15
+ }
16
+ this.rules.set(descriptor.id, descriptor);
17
+ }
18
+ /**
19
+ * Register a constraint
20
+ */
21
+ registerConstraint(descriptor) {
22
+ if (this.constraints.has(descriptor.id)) {
23
+ throw new Error(`Constraint with id "${descriptor.id}" already registered`);
24
+ }
25
+ this.constraints.set(descriptor.id, descriptor);
26
+ }
27
+ /**
28
+ * Register a module (all its rules and constraints)
29
+ */
30
+ registerModule(module) {
31
+ for (const rule of module.rules) {
32
+ this.registerRule(rule);
33
+ }
34
+ for (const constraint of module.constraints) {
35
+ this.registerConstraint(constraint);
36
+ }
37
+ }
38
+ /**
39
+ * Get a rule by ID
40
+ */
41
+ getRule(id) {
42
+ return this.rules.get(id);
43
+ }
44
+ /**
45
+ * Get a constraint by ID
46
+ */
47
+ getConstraint(id) {
48
+ return this.constraints.get(id);
49
+ }
50
+ /**
51
+ * Get all registered rule IDs
52
+ */
53
+ getRuleIds() {
54
+ return Array.from(this.rules.keys());
55
+ }
56
+ /**
57
+ * Get all registered constraint IDs
58
+ */
59
+ getConstraintIds() {
60
+ return Array.from(this.constraints.keys());
61
+ }
62
+ /**
63
+ * Get all rules
64
+ */
65
+ getAllRules() {
66
+ return Array.from(this.rules.values());
67
+ }
68
+ /**
69
+ * Get all constraints
70
+ */
71
+ getAllConstraints() {
72
+ return Array.from(this.constraints.values());
73
+ }
74
+ };
75
+
76
+ // src/core/reactive-engine.svelte.ts
77
+ import * as $ from "svelte/internal/client";
78
+ var ReactiveLogicEngine = class {
79
+ #state = (
80
+ // Use Svelte's $state rune for automatic reactivity
81
+ $.state($.proxy({ context: {}, facts: [], meta: {} }))
82
+ );
83
+ get state() {
84
+ return $.get(this.#state);
85
+ }
86
+ set state(value) {
87
+ $.set(this.#state, value, true);
88
+ }
89
+ _engine;
90
+ constructor(options) {
91
+ this.state.context = options.initialContext;
92
+ this.state.facts = options.initialFacts ?? [];
93
+ this.state.meta = options.initialMeta ?? {};
94
+ if (options.registry) {
95
+ this._engine = createPraxisEngine({
96
+ initialContext: options.initialContext,
97
+ registry: options.registry
98
+ });
99
+ } else {
100
+ this._engine = createPraxisEngine({
101
+ initialContext: options.initialContext,
102
+ registry: new PraxisRegistry()
103
+ });
104
+ }
105
+ }
106
+ /**
107
+ * Access the reactive context.
108
+ * In Svelte 5 components, changes to this object will automatically trigger updates.
109
+ */
110
+ get context() {
111
+ return this.state.context;
112
+ }
113
+ /**
114
+ * Access the reactive facts list.
115
+ */
116
+ get facts() {
117
+ return this.state.facts;
118
+ }
119
+ /**
120
+ * Access the reactive metadata.
121
+ */
122
+ get meta() {
123
+ return this.state.meta;
124
+ }
125
+ /**
126
+ * Apply a mutation to the state.
127
+ * Changes will automatically trigger Svelte reactivity.
128
+ *
129
+ * @param mutator A function that receives the state and modifies it.
130
+ */
131
+ apply(mutator) {
132
+ mutator(this.state);
133
+ }
134
+ /**
135
+ * Process events through the logic engine and update reactive state.
136
+ *
137
+ * @param events Events to process
138
+ */
139
+ step(events) {
140
+ const result = this._engine.step(events);
141
+ this.state.context = result.state.context;
142
+ this.state.facts = result.state.facts;
143
+ this.state.meta = result.state.meta ?? {};
144
+ }
145
+ };
146
+ function createReactiveEngine(options) {
147
+ return new ReactiveLogicEngine(options);
148
+ }
149
+
150
+ export {
151
+ PraxisRegistry,
152
+ ReactiveLogicEngine,
153
+ createReactiveEngine
154
+ };