@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.
- package/FRAMEWORK.md +106 -15
- package/README.md +209 -48
- package/dist/browser/adapter-TM4IS5KT.js +12 -0
- package/dist/browser/chunk-JQ64KMLN.js +141 -0
- package/dist/browser/chunk-LE2ZJYFC.js +154 -0
- package/dist/browser/{chunk-R45WXWKH.js → chunk-VOMLVI6V.js} +1 -149
- package/dist/browser/engine-YJZV4SLD.js +8 -0
- package/dist/browser/index.d.ts +130 -1
- package/dist/browser/index.js +146 -139
- package/dist/browser/integrations/svelte.js +2 -1
- package/dist/node/adapter-K6DOX6XS.js +13 -0
- package/dist/node/chunk-JQ64KMLN.js +141 -0
- package/dist/node/chunk-LE2ZJYFC.js +154 -0
- package/dist/node/chunk-S54337I5.js +446 -0
- package/dist/node/{chunk-R45WXWKH.js → chunk-VOMLVI6V.js} +1 -149
- package/dist/node/cli/index.cjs +1444 -889
- package/dist/node/cli/index.js +9 -0
- package/dist/node/docs-JFNYTOJA.js +102 -0
- package/dist/node/engine-2DQBKBJC.js +9 -0
- package/dist/node/index.cjs +503 -325
- package/dist/node/index.d.cts +130 -1
- package/dist/node/index.d.ts +130 -1
- package/dist/node/index.js +151 -580
- package/dist/node/integrations/svelte.js +2 -1
- package/package.json +1 -1
- package/src/cli/commands/docs.ts +147 -0
- package/src/cli/index.ts +21 -0
- package/src/core/pluresdb/adapter.ts +1 -1
- package/src/core/reactive-engine.svelte.ts +6 -1
- package/src/core/reactive-engine.ts +1 -1
- package/src/index.browser.ts +4 -0
- package/src/index.ts +4 -0
- package/src/integrations/unified.ts +350 -0
package/dist/node/index.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
InMemoryPraxisDB,
|
|
3
|
+
PluresDBPraxisAdapter,
|
|
4
|
+
createInMemoryDB,
|
|
5
|
+
createPluresDB
|
|
6
|
+
} from "./chunk-JQ64KMLN.js";
|
|
7
|
+
import {
|
|
8
|
+
StateDocsGenerator,
|
|
9
|
+
createStateDocsGenerator,
|
|
10
|
+
generateDocs
|
|
11
|
+
} from "./chunk-S54337I5.js";
|
|
1
12
|
import {
|
|
2
13
|
canvasToMermaid,
|
|
3
14
|
canvasToSchema,
|
|
@@ -7,13 +18,10 @@ import {
|
|
|
7
18
|
validateWithGuardian
|
|
8
19
|
} from "./chunk-SRM3OPPM.js";
|
|
9
20
|
import {
|
|
10
|
-
LogicEngine,
|
|
11
|
-
PRAXIS_PROTOCOL_VERSION,
|
|
12
21
|
PraxisRegistry,
|
|
13
22
|
ReactiveLogicEngine,
|
|
14
|
-
createPraxisEngine,
|
|
15
23
|
createReactiveEngine
|
|
16
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-LE2ZJYFC.js";
|
|
17
25
|
import {
|
|
18
26
|
TerminalAdapter,
|
|
19
27
|
createMockExecutor,
|
|
@@ -35,6 +43,11 @@ import {
|
|
|
35
43
|
createSchemaTemplate,
|
|
36
44
|
validateSchema
|
|
37
45
|
} from "./chunk-UATVJBNV.js";
|
|
46
|
+
import {
|
|
47
|
+
LogicEngine,
|
|
48
|
+
PRAXIS_PROTOCOL_VERSION,
|
|
49
|
+
createPraxisEngine
|
|
50
|
+
} from "./chunk-VOMLVI6V.js";
|
|
38
51
|
import "./chunk-QGM4M3NI.js";
|
|
39
52
|
|
|
40
53
|
// src/core/reactive-engine.ts
|
|
@@ -915,141 +928,6 @@ function createPraxisDBStore(db, registry, initialContext, onRuleError) {
|
|
|
915
928
|
return new PraxisDBStore({ db, registry, initialContext, onRuleError });
|
|
916
929
|
}
|
|
917
930
|
|
|
918
|
-
// src/core/pluresdb/adapter.ts
|
|
919
|
-
var InMemoryPraxisDB = class {
|
|
920
|
-
store = /* @__PURE__ */ new Map();
|
|
921
|
-
watchers = /* @__PURE__ */ new Map();
|
|
922
|
-
async get(key) {
|
|
923
|
-
return this.store.get(key);
|
|
924
|
-
}
|
|
925
|
-
async set(key, value) {
|
|
926
|
-
this.store.set(key, value);
|
|
927
|
-
const keyWatchers = this.watchers.get(key);
|
|
928
|
-
if (keyWatchers) {
|
|
929
|
-
for (const callback of keyWatchers) {
|
|
930
|
-
callback(value);
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
watch(key, callback) {
|
|
935
|
-
if (!this.watchers.has(key)) {
|
|
936
|
-
this.watchers.set(key, /* @__PURE__ */ new Set());
|
|
937
|
-
}
|
|
938
|
-
const watchers = this.watchers.get(key);
|
|
939
|
-
const wrappedCallback = (val) => callback(val);
|
|
940
|
-
watchers.add(wrappedCallback);
|
|
941
|
-
return () => {
|
|
942
|
-
watchers.delete(wrappedCallback);
|
|
943
|
-
if (watchers.size === 0) {
|
|
944
|
-
this.watchers.delete(key);
|
|
945
|
-
}
|
|
946
|
-
};
|
|
947
|
-
}
|
|
948
|
-
/**
|
|
949
|
-
* Get all keys (for testing/debugging)
|
|
950
|
-
*/
|
|
951
|
-
keys() {
|
|
952
|
-
return Array.from(this.store.keys());
|
|
953
|
-
}
|
|
954
|
-
/**
|
|
955
|
-
* Clear all data (for testing)
|
|
956
|
-
*/
|
|
957
|
-
clear() {
|
|
958
|
-
this.store.clear();
|
|
959
|
-
this.watchers.clear();
|
|
960
|
-
}
|
|
961
|
-
};
|
|
962
|
-
function createInMemoryDB() {
|
|
963
|
-
return new InMemoryPraxisDB();
|
|
964
|
-
}
|
|
965
|
-
var PluresDBPraxisAdapter = class {
|
|
966
|
-
db;
|
|
967
|
-
watchers = /* @__PURE__ */ new Map();
|
|
968
|
-
pollIntervals = /* @__PURE__ */ new Map();
|
|
969
|
-
lastValues = /* @__PURE__ */ new Map();
|
|
970
|
-
pollInterval;
|
|
971
|
-
constructor(config) {
|
|
972
|
-
if ("get" in config && "put" in config) {
|
|
973
|
-
this.db = config;
|
|
974
|
-
this.pollInterval = 1e3;
|
|
975
|
-
} else {
|
|
976
|
-
this.db = config.db;
|
|
977
|
-
this.pollInterval = config.pollInterval ?? 1e3;
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
async get(key) {
|
|
981
|
-
try {
|
|
982
|
-
const value = await this.db.get(key);
|
|
983
|
-
return value;
|
|
984
|
-
} catch (error) {
|
|
985
|
-
return void 0;
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
async set(key, value) {
|
|
989
|
-
await this.db.put(key, value);
|
|
990
|
-
this.lastValues.set(key, value);
|
|
991
|
-
const keyWatchers = this.watchers.get(key);
|
|
992
|
-
if (keyWatchers) {
|
|
993
|
-
for (const callback of keyWatchers) {
|
|
994
|
-
callback(value);
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
watch(key, callback) {
|
|
999
|
-
if (!this.watchers.has(key)) {
|
|
1000
|
-
this.watchers.set(key, /* @__PURE__ */ new Set());
|
|
1001
|
-
}
|
|
1002
|
-
const watchers = this.watchers.get(key);
|
|
1003
|
-
const wrappedCallback = (val) => callback(val);
|
|
1004
|
-
watchers.add(wrappedCallback);
|
|
1005
|
-
if (!this.pollIntervals.has(key)) {
|
|
1006
|
-
const interval = setInterval(async () => {
|
|
1007
|
-
try {
|
|
1008
|
-
const value = await this.db.get(key);
|
|
1009
|
-
const lastValue = this.lastValues.get(key);
|
|
1010
|
-
if (JSON.stringify(value) !== JSON.stringify(lastValue)) {
|
|
1011
|
-
this.lastValues.set(key, value);
|
|
1012
|
-
const currentWatchers = this.watchers.get(key);
|
|
1013
|
-
if (currentWatchers) {
|
|
1014
|
-
for (const cb of currentWatchers) {
|
|
1015
|
-
cb(value);
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
} catch (error) {
|
|
1020
|
-
}
|
|
1021
|
-
}, this.pollInterval);
|
|
1022
|
-
this.pollIntervals.set(key, interval);
|
|
1023
|
-
}
|
|
1024
|
-
return () => {
|
|
1025
|
-
watchers.delete(wrappedCallback);
|
|
1026
|
-
if (watchers.size === 0) {
|
|
1027
|
-
this.watchers.delete(key);
|
|
1028
|
-
const interval = this.pollIntervals.get(key);
|
|
1029
|
-
if (interval) {
|
|
1030
|
-
clearInterval(interval);
|
|
1031
|
-
this.pollIntervals.delete(key);
|
|
1032
|
-
}
|
|
1033
|
-
this.lastValues.delete(key);
|
|
1034
|
-
}
|
|
1035
|
-
};
|
|
1036
|
-
}
|
|
1037
|
-
/**
|
|
1038
|
-
* Clean up all resources
|
|
1039
|
-
*/
|
|
1040
|
-
dispose() {
|
|
1041
|
-
for (const interval of this.pollIntervals.values()) {
|
|
1042
|
-
clearInterval(interval);
|
|
1043
|
-
}
|
|
1044
|
-
this.pollIntervals.clear();
|
|
1045
|
-
this.watchers.clear();
|
|
1046
|
-
this.lastValues.clear();
|
|
1047
|
-
}
|
|
1048
|
-
};
|
|
1049
|
-
function createPluresDB(config) {
|
|
1050
|
-
return new PluresDBPraxisAdapter(config);
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
931
|
// src/core/pluresdb/schema-registry.ts
|
|
1054
932
|
function getSchemaPath(schemaName) {
|
|
1055
933
|
return `${PRAXIS_PATHS.SCHEMAS}/${schemaName}`;
|
|
@@ -1370,447 +1248,6 @@ function attachUnumToEngine(_engine, _adapter, _channelId) {
|
|
|
1370
1248
|
};
|
|
1371
1249
|
}
|
|
1372
1250
|
|
|
1373
|
-
// src/integrations/state-docs.ts
|
|
1374
|
-
var StateDocsGenerator = class {
|
|
1375
|
-
config;
|
|
1376
|
-
constructor(config) {
|
|
1377
|
-
this.config = {
|
|
1378
|
-
target: "./docs",
|
|
1379
|
-
globs: ["**/*.ts", "**/*.js"],
|
|
1380
|
-
visualization: {
|
|
1381
|
-
format: "mermaid",
|
|
1382
|
-
exportPng: false,
|
|
1383
|
-
theme: "default"
|
|
1384
|
-
},
|
|
1385
|
-
template: {
|
|
1386
|
-
toc: true,
|
|
1387
|
-
timestamp: true
|
|
1388
|
-
},
|
|
1389
|
-
...config
|
|
1390
|
-
};
|
|
1391
|
-
}
|
|
1392
|
-
/**
|
|
1393
|
-
* Generate documentation from a Praxis schema
|
|
1394
|
-
*/
|
|
1395
|
-
generateFromSchema(schema) {
|
|
1396
|
-
const docs = [];
|
|
1397
|
-
docs.push(this.generateSchemaReadme(schema));
|
|
1398
|
-
if (schema.models && schema.models.length > 0) {
|
|
1399
|
-
docs.push(this.generateModelsDoc(schema));
|
|
1400
|
-
}
|
|
1401
|
-
if (schema.components && schema.components.length > 0) {
|
|
1402
|
-
docs.push(this.generateComponentsDoc(schema));
|
|
1403
|
-
}
|
|
1404
|
-
if (schema.logic && schema.logic.length > 0) {
|
|
1405
|
-
for (const logic of schema.logic) {
|
|
1406
|
-
docs.push(this.generateLogicDoc(logic));
|
|
1407
|
-
docs.push(this.generateLogicDiagram(logic));
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
return docs;
|
|
1411
|
-
}
|
|
1412
|
-
/**
|
|
1413
|
-
* Generate documentation from a Praxis registry
|
|
1414
|
-
*/
|
|
1415
|
-
generateFromModule(module) {
|
|
1416
|
-
const docs = [];
|
|
1417
|
-
const rules = module.rules;
|
|
1418
|
-
const constraints = module.constraints;
|
|
1419
|
-
docs.push(this.generateRulesDoc(rules));
|
|
1420
|
-
docs.push(this.generateConstraintsDoc(constraints));
|
|
1421
|
-
docs.push(this.generateRegistryDiagram(rules, constraints));
|
|
1422
|
-
return docs;
|
|
1423
|
-
}
|
|
1424
|
-
/**
|
|
1425
|
-
* Generate the main schema README
|
|
1426
|
-
*/
|
|
1427
|
-
generateSchemaReadme(schema) {
|
|
1428
|
-
const lines = [];
|
|
1429
|
-
if (this.config.template?.header) {
|
|
1430
|
-
lines.push(this.config.template.header);
|
|
1431
|
-
lines.push("");
|
|
1432
|
-
}
|
|
1433
|
-
lines.push(`# ${schema.name || this.config.projectTitle}`);
|
|
1434
|
-
lines.push("");
|
|
1435
|
-
if (schema.description) {
|
|
1436
|
-
lines.push(schema.description);
|
|
1437
|
-
lines.push("");
|
|
1438
|
-
}
|
|
1439
|
-
if (this.config.template?.toc) {
|
|
1440
|
-
lines.push("## Table of Contents");
|
|
1441
|
-
lines.push("");
|
|
1442
|
-
lines.push("- [Overview](#overview)");
|
|
1443
|
-
if (schema.models && schema.models.length > 0) {
|
|
1444
|
-
lines.push("- [Models](#models)");
|
|
1445
|
-
}
|
|
1446
|
-
if (schema.components && schema.components.length > 0) {
|
|
1447
|
-
lines.push("- [Components](#components)");
|
|
1448
|
-
}
|
|
1449
|
-
if (schema.logic && schema.logic.length > 0) {
|
|
1450
|
-
lines.push("- [Logic](#logic)");
|
|
1451
|
-
}
|
|
1452
|
-
lines.push("");
|
|
1453
|
-
}
|
|
1454
|
-
lines.push("## Overview");
|
|
1455
|
-
lines.push("");
|
|
1456
|
-
lines.push(`**Version:** ${schema.version}`);
|
|
1457
|
-
lines.push("");
|
|
1458
|
-
lines.push("### Statistics");
|
|
1459
|
-
lines.push("");
|
|
1460
|
-
lines.push("| Category | Count |");
|
|
1461
|
-
lines.push("|----------|-------|");
|
|
1462
|
-
lines.push(`| Models | ${schema.models?.length || 0} |`);
|
|
1463
|
-
lines.push(`| Components | ${schema.components?.length || 0} |`);
|
|
1464
|
-
lines.push(`| Logic Modules | ${schema.logic?.length || 0} |`);
|
|
1465
|
-
lines.push("");
|
|
1466
|
-
if (schema.models && schema.models.length > 0) {
|
|
1467
|
-
lines.push("## Models");
|
|
1468
|
-
lines.push("");
|
|
1469
|
-
for (const model of schema.models) {
|
|
1470
|
-
lines.push(`### ${model.name}`);
|
|
1471
|
-
lines.push("");
|
|
1472
|
-
if (model.description) {
|
|
1473
|
-
lines.push(model.description);
|
|
1474
|
-
lines.push("");
|
|
1475
|
-
}
|
|
1476
|
-
lines.push("**Fields:**");
|
|
1477
|
-
lines.push("");
|
|
1478
|
-
lines.push("| Name | Type | Required |");
|
|
1479
|
-
lines.push("|------|------|----------|");
|
|
1480
|
-
for (const field of model.fields) {
|
|
1481
|
-
const required = field.optional ? "No" : "Yes";
|
|
1482
|
-
lines.push(`| ${field.name} | ${field.type} | ${required} |`);
|
|
1483
|
-
}
|
|
1484
|
-
lines.push("");
|
|
1485
|
-
}
|
|
1486
|
-
}
|
|
1487
|
-
if (schema.components && schema.components.length > 0) {
|
|
1488
|
-
lines.push("## Components");
|
|
1489
|
-
lines.push("");
|
|
1490
|
-
for (const component of schema.components) {
|
|
1491
|
-
lines.push(`### ${component.name}`);
|
|
1492
|
-
lines.push("");
|
|
1493
|
-
lines.push(`**Type:** ${component.type}`);
|
|
1494
|
-
lines.push("");
|
|
1495
|
-
if (component.description) {
|
|
1496
|
-
lines.push(component.description);
|
|
1497
|
-
lines.push("");
|
|
1498
|
-
}
|
|
1499
|
-
if (component.model) {
|
|
1500
|
-
lines.push(`**Model:** ${component.model}`);
|
|
1501
|
-
lines.push("");
|
|
1502
|
-
}
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
if (schema.logic && schema.logic.length > 0) {
|
|
1506
|
-
lines.push("## Logic");
|
|
1507
|
-
lines.push("");
|
|
1508
|
-
for (const logic of schema.logic) {
|
|
1509
|
-
lines.push(`### ${logic.id}`);
|
|
1510
|
-
lines.push("");
|
|
1511
|
-
if (logic.description) {
|
|
1512
|
-
lines.push(logic.description);
|
|
1513
|
-
lines.push("");
|
|
1514
|
-
}
|
|
1515
|
-
if (logic.events && logic.events.length > 0) {
|
|
1516
|
-
lines.push("**Events:**");
|
|
1517
|
-
lines.push("");
|
|
1518
|
-
for (const event of logic.events) {
|
|
1519
|
-
lines.push(`- \`${event.tag}\`: ${event.description || ""}`);
|
|
1520
|
-
}
|
|
1521
|
-
lines.push("");
|
|
1522
|
-
}
|
|
1523
|
-
if (logic.facts && logic.facts.length > 0) {
|
|
1524
|
-
lines.push("**Facts:**");
|
|
1525
|
-
lines.push("");
|
|
1526
|
-
for (const fact of logic.facts) {
|
|
1527
|
-
lines.push(`- \`${fact.tag}\`: ${fact.description || ""}`);
|
|
1528
|
-
}
|
|
1529
|
-
lines.push("");
|
|
1530
|
-
}
|
|
1531
|
-
if (logic.rules && logic.rules.length > 0) {
|
|
1532
|
-
lines.push("**Rules:**");
|
|
1533
|
-
lines.push("");
|
|
1534
|
-
for (const rule of logic.rules) {
|
|
1535
|
-
lines.push(`- \`${rule.id}\`: ${rule.description || ""}`);
|
|
1536
|
-
}
|
|
1537
|
-
lines.push("");
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
}
|
|
1541
|
-
if (this.config.template?.timestamp) {
|
|
1542
|
-
lines.push("---");
|
|
1543
|
-
lines.push("");
|
|
1544
|
-
lines.push(`*Generated on ${(/* @__PURE__ */ new Date()).toISOString()} by State-Docs*`);
|
|
1545
|
-
}
|
|
1546
|
-
if (this.config.template?.footer) {
|
|
1547
|
-
lines.push("");
|
|
1548
|
-
lines.push(this.config.template.footer);
|
|
1549
|
-
}
|
|
1550
|
-
return {
|
|
1551
|
-
path: `${this.config.target}/README.md`,
|
|
1552
|
-
content: lines.join("\n"),
|
|
1553
|
-
type: "markdown"
|
|
1554
|
-
};
|
|
1555
|
-
}
|
|
1556
|
-
/**
|
|
1557
|
-
* Generate models documentation
|
|
1558
|
-
*/
|
|
1559
|
-
generateModelsDoc(schema) {
|
|
1560
|
-
const lines = [
|
|
1561
|
-
"# Models",
|
|
1562
|
-
"",
|
|
1563
|
-
"This document describes all data models defined in the schema.",
|
|
1564
|
-
""
|
|
1565
|
-
];
|
|
1566
|
-
if (schema.models) {
|
|
1567
|
-
for (const model of schema.models) {
|
|
1568
|
-
lines.push(`## ${model.name}`);
|
|
1569
|
-
lines.push("");
|
|
1570
|
-
if (model.description) {
|
|
1571
|
-
lines.push(model.description);
|
|
1572
|
-
lines.push("");
|
|
1573
|
-
}
|
|
1574
|
-
lines.push("### Fields");
|
|
1575
|
-
lines.push("");
|
|
1576
|
-
lines.push("| Name | Type | Required | Description |");
|
|
1577
|
-
lines.push("|------|------|----------|-------------|");
|
|
1578
|
-
for (const field of model.fields) {
|
|
1579
|
-
const required = field.optional ? "No" : "Yes";
|
|
1580
|
-
const description = field.description || "-";
|
|
1581
|
-
lines.push(`| ${field.name} | \`${field.type}\` | ${required} | ${description} |`);
|
|
1582
|
-
}
|
|
1583
|
-
lines.push("");
|
|
1584
|
-
if (model.indexes && model.indexes.length > 0) {
|
|
1585
|
-
lines.push("### Indexes");
|
|
1586
|
-
lines.push("");
|
|
1587
|
-
for (const index of model.indexes) {
|
|
1588
|
-
lines.push(`- **${index.name}**: \`${index.fields.join(", ")}\``);
|
|
1589
|
-
}
|
|
1590
|
-
lines.push("");
|
|
1591
|
-
}
|
|
1592
|
-
}
|
|
1593
|
-
}
|
|
1594
|
-
return {
|
|
1595
|
-
path: `${this.config.target}/models.md`,
|
|
1596
|
-
content: lines.join("\n"),
|
|
1597
|
-
type: "markdown"
|
|
1598
|
-
};
|
|
1599
|
-
}
|
|
1600
|
-
/**
|
|
1601
|
-
* Generate components documentation
|
|
1602
|
-
*/
|
|
1603
|
-
generateComponentsDoc(schema) {
|
|
1604
|
-
const lines = [
|
|
1605
|
-
"# Components",
|
|
1606
|
-
"",
|
|
1607
|
-
"This document describes all UI components defined in the schema.",
|
|
1608
|
-
""
|
|
1609
|
-
];
|
|
1610
|
-
if (schema.components) {
|
|
1611
|
-
for (const component of schema.components) {
|
|
1612
|
-
lines.push(`## ${component.name}`);
|
|
1613
|
-
lines.push("");
|
|
1614
|
-
lines.push(`**Type:** ${component.type}`);
|
|
1615
|
-
lines.push("");
|
|
1616
|
-
if (component.description) {
|
|
1617
|
-
lines.push(component.description);
|
|
1618
|
-
lines.push("");
|
|
1619
|
-
}
|
|
1620
|
-
if (component.model) {
|
|
1621
|
-
lines.push(
|
|
1622
|
-
`**Associated Model:** [${component.model}](./models.md#${component.model.toLowerCase()})`
|
|
1623
|
-
);
|
|
1624
|
-
lines.push("");
|
|
1625
|
-
}
|
|
1626
|
-
}
|
|
1627
|
-
}
|
|
1628
|
-
return {
|
|
1629
|
-
path: `${this.config.target}/components.md`,
|
|
1630
|
-
content: lines.join("\n"),
|
|
1631
|
-
type: "markdown"
|
|
1632
|
-
};
|
|
1633
|
-
}
|
|
1634
|
-
/**
|
|
1635
|
-
* Generate logic documentation
|
|
1636
|
-
*/
|
|
1637
|
-
generateLogicDoc(logic) {
|
|
1638
|
-
const lines = [`# ${logic.id}`, ""];
|
|
1639
|
-
if (logic.description) {
|
|
1640
|
-
lines.push(logic.description);
|
|
1641
|
-
lines.push("");
|
|
1642
|
-
}
|
|
1643
|
-
if (logic.events && logic.events.length > 0) {
|
|
1644
|
-
lines.push("## Events");
|
|
1645
|
-
lines.push("");
|
|
1646
|
-
lines.push("| Event | Description | Payload |");
|
|
1647
|
-
lines.push("|-------|-------------|---------|");
|
|
1648
|
-
for (const event of logic.events) {
|
|
1649
|
-
const payload = event.payload ? Object.entries(event.payload).map(([k, v]) => `${k}: ${v}`).join(", ") : "-";
|
|
1650
|
-
lines.push(`| \`${event.tag}\` | ${event.description || "-"} | ${payload} |`);
|
|
1651
|
-
}
|
|
1652
|
-
lines.push("");
|
|
1653
|
-
}
|
|
1654
|
-
if (logic.facts && logic.facts.length > 0) {
|
|
1655
|
-
lines.push("## Facts");
|
|
1656
|
-
lines.push("");
|
|
1657
|
-
lines.push("| Fact | Description | Payload |");
|
|
1658
|
-
lines.push("|------|-------------|---------|");
|
|
1659
|
-
for (const fact of logic.facts) {
|
|
1660
|
-
const payload = fact.payload ? Object.entries(fact.payload).map(([k, v]) => `${k}: ${v}`).join(", ") : "-";
|
|
1661
|
-
lines.push(`| \`${fact.tag}\` | ${fact.description || "-"} | ${payload} |`);
|
|
1662
|
-
}
|
|
1663
|
-
lines.push("");
|
|
1664
|
-
}
|
|
1665
|
-
if (logic.rules && logic.rules.length > 0) {
|
|
1666
|
-
lines.push("## Rules");
|
|
1667
|
-
lines.push("");
|
|
1668
|
-
for (const rule of logic.rules) {
|
|
1669
|
-
lines.push(`### ${rule.id}`);
|
|
1670
|
-
lines.push("");
|
|
1671
|
-
if (rule.description) {
|
|
1672
|
-
lines.push(rule.description);
|
|
1673
|
-
lines.push("");
|
|
1674
|
-
}
|
|
1675
|
-
if (rule.priority !== void 0) {
|
|
1676
|
-
lines.push(`**Priority:** ${rule.priority}`);
|
|
1677
|
-
lines.push("");
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
}
|
|
1681
|
-
if (logic.constraints && logic.constraints.length > 0) {
|
|
1682
|
-
lines.push("## Constraints");
|
|
1683
|
-
lines.push("");
|
|
1684
|
-
for (const constraint of logic.constraints) {
|
|
1685
|
-
lines.push(`### ${constraint.id}`);
|
|
1686
|
-
lines.push("");
|
|
1687
|
-
if (constraint.description) {
|
|
1688
|
-
lines.push(constraint.description);
|
|
1689
|
-
lines.push("");
|
|
1690
|
-
}
|
|
1691
|
-
if (constraint.message) {
|
|
1692
|
-
lines.push(`**Error Message:** ${constraint.message}`);
|
|
1693
|
-
lines.push("");
|
|
1694
|
-
}
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1697
|
-
return {
|
|
1698
|
-
path: `${this.config.target}/logic/${logic.id}.md`,
|
|
1699
|
-
content: lines.join("\n"),
|
|
1700
|
-
type: "markdown"
|
|
1701
|
-
};
|
|
1702
|
-
}
|
|
1703
|
-
/**
|
|
1704
|
-
* Generate Mermaid diagram for logic
|
|
1705
|
-
*/
|
|
1706
|
-
generateLogicDiagram(logic) {
|
|
1707
|
-
const lines = ["stateDiagram-v2"];
|
|
1708
|
-
if (logic.events && logic.facts) {
|
|
1709
|
-
lines.push(" [*] --> Processing");
|
|
1710
|
-
for (const event of logic.events) {
|
|
1711
|
-
lines.push(` Processing --> ${event.tag.replace(/[^a-zA-Z0-9]/g, "")}: ${event.tag}`);
|
|
1712
|
-
}
|
|
1713
|
-
for (const fact of logic.facts) {
|
|
1714
|
-
lines.push(` ${fact.tag.replace(/[^a-zA-Z0-9]/g, "")} --> [*]`);
|
|
1715
|
-
}
|
|
1716
|
-
}
|
|
1717
|
-
return {
|
|
1718
|
-
path: `${this.config.target}/logic/${logic.id}.mmd`,
|
|
1719
|
-
content: lines.join("\n"),
|
|
1720
|
-
type: "mermaid"
|
|
1721
|
-
};
|
|
1722
|
-
}
|
|
1723
|
-
/**
|
|
1724
|
-
* Generate rules documentation
|
|
1725
|
-
*/
|
|
1726
|
-
generateRulesDoc(rules) {
|
|
1727
|
-
const lines = [
|
|
1728
|
-
"# Rules",
|
|
1729
|
-
"",
|
|
1730
|
-
"This document describes all rules registered in the Praxis engine.",
|
|
1731
|
-
""
|
|
1732
|
-
];
|
|
1733
|
-
for (const rule of rules) {
|
|
1734
|
-
lines.push(`## ${rule.id}`);
|
|
1735
|
-
lines.push("");
|
|
1736
|
-
if (rule.description) {
|
|
1737
|
-
lines.push(rule.description);
|
|
1738
|
-
lines.push("");
|
|
1739
|
-
}
|
|
1740
|
-
if (rule.meta?.eventType) {
|
|
1741
|
-
lines.push(`**Triggers on:** \`${rule.meta.eventType}\``);
|
|
1742
|
-
lines.push("");
|
|
1743
|
-
}
|
|
1744
|
-
if (rule.meta?.priority !== void 0) {
|
|
1745
|
-
lines.push(`**Priority:** ${rule.meta.priority}`);
|
|
1746
|
-
lines.push("");
|
|
1747
|
-
}
|
|
1748
|
-
}
|
|
1749
|
-
return {
|
|
1750
|
-
path: `${this.config.target}/rules.md`,
|
|
1751
|
-
content: lines.join("\n"),
|
|
1752
|
-
type: "markdown"
|
|
1753
|
-
};
|
|
1754
|
-
}
|
|
1755
|
-
/**
|
|
1756
|
-
* Generate constraints documentation
|
|
1757
|
-
*/
|
|
1758
|
-
generateConstraintsDoc(constraints) {
|
|
1759
|
-
const lines = [
|
|
1760
|
-
"# Constraints",
|
|
1761
|
-
"",
|
|
1762
|
-
"This document describes all constraints (invariants) registered in the Praxis engine.",
|
|
1763
|
-
""
|
|
1764
|
-
];
|
|
1765
|
-
for (const constraint of constraints) {
|
|
1766
|
-
lines.push(`## ${constraint.id}`);
|
|
1767
|
-
lines.push("");
|
|
1768
|
-
if (constraint.description) {
|
|
1769
|
-
lines.push(constraint.description);
|
|
1770
|
-
lines.push("");
|
|
1771
|
-
}
|
|
1772
|
-
if (constraint.meta?.errorMessage) {
|
|
1773
|
-
lines.push(`**Error Message:** ${constraint.meta.errorMessage}`);
|
|
1774
|
-
lines.push("");
|
|
1775
|
-
}
|
|
1776
|
-
}
|
|
1777
|
-
return {
|
|
1778
|
-
path: `${this.config.target}/constraints.md`,
|
|
1779
|
-
content: lines.join("\n"),
|
|
1780
|
-
type: "markdown"
|
|
1781
|
-
};
|
|
1782
|
-
}
|
|
1783
|
-
/**
|
|
1784
|
-
* Generate state diagram from registry
|
|
1785
|
-
*/
|
|
1786
|
-
generateRegistryDiagram(rules, constraints) {
|
|
1787
|
-
const lines = ["graph TD", " subgraph Rules"];
|
|
1788
|
-
for (const rule of rules) {
|
|
1789
|
-
const id = rule.id.replace(/[^a-zA-Z0-9]/g, "_");
|
|
1790
|
-
lines.push(` ${id}["${rule.id}"]`);
|
|
1791
|
-
}
|
|
1792
|
-
lines.push(" end");
|
|
1793
|
-
lines.push(" subgraph Constraints");
|
|
1794
|
-
for (const constraint of constraints) {
|
|
1795
|
-
const id = constraint.id.replace(/[^a-zA-Z0-9]/g, "_");
|
|
1796
|
-
lines.push(` ${id}["${constraint.id}"]`);
|
|
1797
|
-
}
|
|
1798
|
-
lines.push(" end");
|
|
1799
|
-
return {
|
|
1800
|
-
path: `${this.config.target}/state-diagram.mmd`,
|
|
1801
|
-
content: lines.join("\n"),
|
|
1802
|
-
type: "mermaid"
|
|
1803
|
-
};
|
|
1804
|
-
}
|
|
1805
|
-
};
|
|
1806
|
-
function createStateDocsGenerator(config) {
|
|
1807
|
-
return new StateDocsGenerator(config);
|
|
1808
|
-
}
|
|
1809
|
-
function generateDocs(schema, config) {
|
|
1810
|
-
const generator = createStateDocsGenerator(config);
|
|
1811
|
-
return generator.generateFromSchema(schema);
|
|
1812
|
-
}
|
|
1813
|
-
|
|
1814
1251
|
// src/integrations/tauri.ts
|
|
1815
1252
|
function createMockTauriBridge() {
|
|
1816
1253
|
const eventHandlers = /* @__PURE__ */ new Map();
|
|
@@ -2030,6 +1467,138 @@ function generateTauriConfig(config) {
|
|
|
2030
1467
|
plugins: Object.fromEntries((config.plugins || []).map((p) => [p.name, p.config || {}]))
|
|
2031
1468
|
};
|
|
2032
1469
|
}
|
|
1470
|
+
|
|
1471
|
+
// src/integrations/unified.ts
|
|
1472
|
+
async function createUnifiedApp(config) {
|
|
1473
|
+
const { createPraxisEngine: createPraxisEngine2 } = await import("./engine-2DQBKBJC.js");
|
|
1474
|
+
const { createInMemoryDB: createInMemoryDB2 } = await import("./adapter-K6DOX6XS.js");
|
|
1475
|
+
const db = config.db || createInMemoryDB2();
|
|
1476
|
+
const pluresdb = createPluresDBAdapter({
|
|
1477
|
+
db,
|
|
1478
|
+
registry: config.registry,
|
|
1479
|
+
initialContext: config.initialContext
|
|
1480
|
+
});
|
|
1481
|
+
const engine = createPraxisEngine2({
|
|
1482
|
+
initialContext: config.initialContext,
|
|
1483
|
+
registry: config.registry
|
|
1484
|
+
});
|
|
1485
|
+
pluresdb.attachEngine(engine);
|
|
1486
|
+
const disposers = [];
|
|
1487
|
+
let unum;
|
|
1488
|
+
let channel;
|
|
1489
|
+
if (config.enableUnum) {
|
|
1490
|
+
const fullIdentity = config.unumIdentity ? {
|
|
1491
|
+
...config.unumIdentity,
|
|
1492
|
+
id: generateId(),
|
|
1493
|
+
createdAt: Date.now()
|
|
1494
|
+
} : void 0;
|
|
1495
|
+
unum = await createUnumAdapter({
|
|
1496
|
+
db,
|
|
1497
|
+
identity: fullIdentity,
|
|
1498
|
+
realtime: true
|
|
1499
|
+
});
|
|
1500
|
+
channel = await unum.createChannel(
|
|
1501
|
+
config.unumIdentity?.name || "praxis-app",
|
|
1502
|
+
[]
|
|
1503
|
+
);
|
|
1504
|
+
const unumDisposer = attachUnumToEngine(engine, unum, channel.id);
|
|
1505
|
+
disposers.push(unumDisposer);
|
|
1506
|
+
}
|
|
1507
|
+
let docs;
|
|
1508
|
+
let generateDocs2;
|
|
1509
|
+
if (config.enableDocs && config.docsConfig) {
|
|
1510
|
+
docs = createStateDocsGenerator({
|
|
1511
|
+
projectTitle: config.docsConfig.projectTitle,
|
|
1512
|
+
target: config.docsConfig.target || "./docs"
|
|
1513
|
+
});
|
|
1514
|
+
generateDocs2 = () => {
|
|
1515
|
+
const module = {
|
|
1516
|
+
rules: config.registry.getAllRules(),
|
|
1517
|
+
constraints: config.registry.getAllConstraints()
|
|
1518
|
+
};
|
|
1519
|
+
return docs.generateFromModule(module);
|
|
1520
|
+
};
|
|
1521
|
+
}
|
|
1522
|
+
let canvas;
|
|
1523
|
+
if (config.schema) {
|
|
1524
|
+
canvas = schemaToCanvas(config.schema, { layout: "hierarchical" });
|
|
1525
|
+
}
|
|
1526
|
+
return {
|
|
1527
|
+
engine,
|
|
1528
|
+
pluresdb,
|
|
1529
|
+
unum,
|
|
1530
|
+
channel,
|
|
1531
|
+
docs,
|
|
1532
|
+
canvas,
|
|
1533
|
+
generateDocs: generateDocs2,
|
|
1534
|
+
dispose: () => {
|
|
1535
|
+
pluresdb.dispose();
|
|
1536
|
+
if (unum) {
|
|
1537
|
+
unum.disconnect().catch((err) => {
|
|
1538
|
+
console.warn("Warning: Error during Unum disconnect:", err);
|
|
1539
|
+
});
|
|
1540
|
+
}
|
|
1541
|
+
for (const disposer of disposers) {
|
|
1542
|
+
disposer();
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
};
|
|
1546
|
+
}
|
|
1547
|
+
async function attachAllIntegrations(engine, registry, options = {}) {
|
|
1548
|
+
const { createInMemoryDB: createInMemoryDB2 } = await import("./adapter-K6DOX6XS.js");
|
|
1549
|
+
const db = options.db || createInMemoryDB2();
|
|
1550
|
+
const pluresdb = createPluresDBAdapter({
|
|
1551
|
+
db,
|
|
1552
|
+
registry,
|
|
1553
|
+
initialContext: engine.getContext()
|
|
1554
|
+
});
|
|
1555
|
+
pluresdb.attachEngine(engine);
|
|
1556
|
+
const disposers = [];
|
|
1557
|
+
let unum;
|
|
1558
|
+
let channel;
|
|
1559
|
+
if (options.enableUnum) {
|
|
1560
|
+
const fullIdentity = options.unumIdentity ? {
|
|
1561
|
+
...options.unumIdentity,
|
|
1562
|
+
id: generateId(),
|
|
1563
|
+
createdAt: Date.now()
|
|
1564
|
+
} : void 0;
|
|
1565
|
+
unum = await createUnumAdapter({
|
|
1566
|
+
db,
|
|
1567
|
+
identity: fullIdentity,
|
|
1568
|
+
realtime: true
|
|
1569
|
+
});
|
|
1570
|
+
channel = await unum.createChannel(
|
|
1571
|
+
options.unumIdentity?.name || "praxis-app",
|
|
1572
|
+
[]
|
|
1573
|
+
);
|
|
1574
|
+
const unumDisposer = attachUnumToEngine(engine, unum, channel.id);
|
|
1575
|
+
disposers.push(unumDisposer);
|
|
1576
|
+
}
|
|
1577
|
+
let docs;
|
|
1578
|
+
if (options.enableDocs && options.docsConfig) {
|
|
1579
|
+
docs = createStateDocsGenerator({
|
|
1580
|
+
projectTitle: options.docsConfig.projectTitle,
|
|
1581
|
+
target: options.docsConfig.target || "./docs"
|
|
1582
|
+
});
|
|
1583
|
+
}
|
|
1584
|
+
return {
|
|
1585
|
+
pluresdb,
|
|
1586
|
+
unum,
|
|
1587
|
+
channel,
|
|
1588
|
+
docs,
|
|
1589
|
+
dispose: () => {
|
|
1590
|
+
pluresdb.dispose();
|
|
1591
|
+
if (unum) {
|
|
1592
|
+
unum.disconnect().catch((err) => {
|
|
1593
|
+
console.warn("Warning: Error during Unum disconnect:", err);
|
|
1594
|
+
});
|
|
1595
|
+
}
|
|
1596
|
+
for (const disposer of disposers) {
|
|
1597
|
+
disposer();
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
};
|
|
1601
|
+
}
|
|
2033
1602
|
export {
|
|
2034
1603
|
ActorManager,
|
|
2035
1604
|
ReactiveLogicEngine2 as FrameworkAgnosticReactiveEngine,
|
|
@@ -2046,6 +1615,7 @@ export {
|
|
|
2046
1615
|
RegistryIntrospector,
|
|
2047
1616
|
StateDocsGenerator,
|
|
2048
1617
|
TerminalAdapter,
|
|
1618
|
+
attachAllIntegrations,
|
|
2049
1619
|
attachTauriToEngine,
|
|
2050
1620
|
attachToEngine,
|
|
2051
1621
|
attachUnumToEngine,
|
|
@@ -2070,6 +1640,7 @@ export {
|
|
|
2070
1640
|
createTauriPraxisAdapter,
|
|
2071
1641
|
createTerminalAdapter,
|
|
2072
1642
|
createTimerActor,
|
|
1643
|
+
createUnifiedApp,
|
|
2073
1644
|
createUnumAdapter,
|
|
2074
1645
|
defineConstraint,
|
|
2075
1646
|
defineEvent,
|