process-graph 1.1.1 → 1.3.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/README.md +22 -19
- package/dist/bin.js +4 -3
- package/dist/cli.d.ts +100 -14
- package/dist/cli.js +3 -2
- package/dist/{control-aDk9560d.js → control-DiygoEhm.js} +163 -1
- package/dist/data-file-BVMxkTug.js +95 -0
- package/dist/dist-81kTKnMq.js +3 -0
- package/dist/{dist-HLlW8vgT.js → dist-BI01yxFA.js} +256 -103
- package/dist/{dist-BpCBmnMl.js → dist-arkejVz2.js} +2 -112
- package/dist/{graphql-C1j5wQFz.d.ts → graphql-BE7xm5dB.d.ts} +3 -2
- package/dist/{index-DricKcyl.d.ts → index-9Au8pAmP.d.ts} +4 -4
- package/dist/{index-CrM5qWUA.d.ts → index-BC4tmAuQ.d.ts} +2 -2
- package/dist/{index-DhbvDgK4.d.ts → index-CR8xUK3S.d.ts} +388 -580
- package/dist/{index-CoA6vXqe.d.ts → index-D06bcdfw.d.ts} +1 -1
- package/dist/{index-CCfe0csl.d.ts → index-D4CnOhNf.d.ts} +34 -3
- package/dist/{index-CmZOswkx.d.ts → index-Dvz_I_uQ.d.ts} +17 -8
- package/dist/{index-CptUHq6F.d.ts → index-hri2a13-.d.ts} +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +5 -5
- package/dist/layout.d.ts +1 -1
- package/dist/{parse-CuipC_2K.js → parse-C1Q1zsGt.js} +1 -1
- package/dist/{queries-CCexJAE2.js → queries-C8kIDRiY.js} +2 -93
- package/dist/react-flow.d.ts +5 -5
- package/dist/react-flow.js +3 -3
- package/dist/react.d.ts +1 -1
- package/dist/react.js +2 -2
- package/dist/{router-D4gtTlXm.js → router-Dk91O_9p.js} +27 -2
- package/dist/{schema-CVnS6HiX.js → schema-BPT8fmfa.js} +2 -2
- package/dist/{selection-BW_xXWOy.js → selection-iet5RAlP.js} +1 -1
- package/dist/source/github/node.d.ts +1 -1
- package/dist/source/github.d.ts +2 -2
- package/dist/source/github.js +1 -1
- package/dist/{source-DRDpEA8Q.js → source-D51N7K3A.js} +23 -3
- package/dist/store/node.d.ts +27 -2
- package/dist/store/node.js +2 -2
- package/dist/store/wasm/worker.js +2 -2
- package/dist/store/wasm.d.ts +1 -1
- package/dist/{store-BcR70CaO.js → store-DKzvLGgl.js} +252 -37
- package/dist/store.d.ts +115 -3
- package/dist/store.js +43 -9
- package/dist/theme-values-BJJhAkUn-ORyRUrPf.js +114 -0
- package/dist/theme-values-BybZ-cle.d.ts +116 -0
- package/dist/ui/theme.d.ts +2 -0
- package/dist/ui/theme.js +2 -0
- package/dist/ui.d.ts +6 -120
- package/dist/ui.js +2 -1
- package/dist/version-Dagrkvwt.js +5 -0
- package/package.json +28 -23
- package/dist/dist-IjrgWhHQ.js +0 -3
- package/dist/open-CyRXJ4bt.js +0 -29
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
|
-
import { a as validateOverlay, c as fragmentOperators, d as overlayStatuses, f as participantKinds, l as messageModes, p as pseudoRoles, r as overlaySchema, s as elementKinds, t as modelSchema, u as notations } from "./schema-
|
|
2
|
+
import { a as validateOverlay, c as fragmentOperators, d as overlayStatuses, f as participantKinds, l as messageModes, p as pseudoRoles, r as overlaySchema, s as elementKinds, t as modelSchema, u as notations } from "./schema-BPT8fmfa.js";
|
|
3
3
|
import { t as validate } from "./validate-DF3mQZww.js";
|
|
4
|
-
import { r as loopTransitions } from "./control-
|
|
4
|
+
import { r as loopTransitions, s as emptyFactRecord } from "./control-DiygoEhm.js";
|
|
5
5
|
import { z } from "zod";
|
|
6
|
+
import { ComputedValueSchema } from "trilean";
|
|
6
7
|
import { and, asc, eq, inArray, sql } from "drizzle-orm";
|
|
7
8
|
import { index, integer, primaryKey, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
8
9
|
//#region ../../core/graph/store-contract/dist/schema.js
|
|
@@ -49,13 +50,43 @@ const boundItemsSchema = z.strictObject({
|
|
|
49
50
|
overlay: overlaySchema,
|
|
50
51
|
relations: z.array(relationSchema).readonly().exactOptional()
|
|
51
52
|
}).readonly();
|
|
52
|
-
/**
|
|
53
|
+
/** The name of a fact a condition reads: the string key of its `reference` node. */
|
|
54
|
+
const factNameSchema = z.string().min(1);
|
|
55
|
+
/**
|
|
56
|
+
* What is known from outside the process about one model's run, kept beside its overlay: which artefacts are provided (`true`) or known not to be (`false`), by artefact id, and the trilean value of each named fact, by name. What the record does not name is unknown. It is graph-domain's `FactRecord`, which `factsFrom` adapts to the `Facts` port the reasoning reads.
|
|
57
|
+
*/
|
|
58
|
+
const factRecordSchema = z.strictObject({
|
|
59
|
+
artefacts: z.record(z.string().min(1), z.boolean()).readonly(),
|
|
60
|
+
values: z.record(factNameSchema, ComputedValueSchema).readonly()
|
|
61
|
+
}).readonly();
|
|
62
|
+
/** One stored model, the run state laid over it and the facts known about its run, at the revision of its last change. */
|
|
53
63
|
const storedModelSchema = z.strictObject({
|
|
54
64
|
modelId: modelIdSchema,
|
|
55
65
|
revision: revisionSchema,
|
|
56
66
|
model: modelSchema,
|
|
57
|
-
overlay: overlaySchema
|
|
67
|
+
overlay: overlaySchema,
|
|
68
|
+
facts: factRecordSchema
|
|
58
69
|
}).readonly();
|
|
70
|
+
/** A model's fact record at the revision of the model's last change. */
|
|
71
|
+
const storedFactsSchema = z.strictObject({
|
|
72
|
+
modelId: modelIdSchema,
|
|
73
|
+
revision: revisionSchema,
|
|
74
|
+
facts: factRecordSchema
|
|
75
|
+
}).readonly();
|
|
76
|
+
/**
|
|
77
|
+
* Facts to record for a model: each artefact's provision and each named fact's value replaces what the record held for it, and everything the change does not name is kept. Every artefact must be one the model declares.
|
|
78
|
+
*/
|
|
79
|
+
const factChangeSchema = z.strictObject({
|
|
80
|
+
artefacts: z.record(z.string().min(1), z.boolean()).readonly().exactOptional(),
|
|
81
|
+
values: z.record(factNameSchema, ComputedValueSchema).readonly().exactOptional()
|
|
82
|
+
}).readonly();
|
|
83
|
+
/**
|
|
84
|
+
* Facts to forget, so they are unknown again: either the named artefacts and named facts, or, with `all`, the whole record. A name the record does not hold is ignored.
|
|
85
|
+
*/
|
|
86
|
+
const factClearingSchema = z.union([z.strictObject({
|
|
87
|
+
artefacts: z.array(z.string().min(1)).readonly().exactOptional(),
|
|
88
|
+
values: z.array(factNameSchema).readonly().exactOptional()
|
|
89
|
+
}).readonly(), z.strictObject({ all: z.literal(true) }).readonly()]);
|
|
59
90
|
/** A stored model's name and the revision of its last change. */
|
|
60
91
|
const modelSummarySchema = z.strictObject({
|
|
61
92
|
modelId: modelIdSchema,
|
|
@@ -71,6 +102,7 @@ const changeKinds = [
|
|
|
71
102
|
"saved",
|
|
72
103
|
"overlay",
|
|
73
104
|
"items",
|
|
105
|
+
"facts",
|
|
74
106
|
"deleted"
|
|
75
107
|
];
|
|
76
108
|
/**
|
|
@@ -273,6 +305,70 @@ const checkStored = (model, overlay) => {
|
|
|
273
305
|
});
|
|
274
306
|
};
|
|
275
307
|
//#endregion
|
|
308
|
+
//#region ../../core/graph/store-contract/dist/facts.js
|
|
309
|
+
/**
|
|
310
|
+
* The write rules for a model's fact record, shared by every store so each keeps facts the same way. Each function returns a new record and never changes the one it is given.
|
|
311
|
+
*/
|
|
312
|
+
/** The entries of a record whose key passes a test. */
|
|
313
|
+
const entriesWhere = (record, keep) => Object.fromEntries(Object.entries(record).filter(([key]) => keep(key)));
|
|
314
|
+
/**
|
|
315
|
+
* Keeps only the artefact entries of a record that name an artefact the model declares, so replacing a model drops what was known about artefacts it no longer has. Named facts belong to the run rather than to any record of the model, so they are all kept.
|
|
316
|
+
* @param model - The model the record is for.
|
|
317
|
+
* @param facts - The record to narrow.
|
|
318
|
+
* @returns The record with its artefacts narrowed to the model's.
|
|
319
|
+
*/
|
|
320
|
+
const factsWithin = (model, facts) => {
|
|
321
|
+
const declared = new Set(model.artefacts.map(({ id }) => id));
|
|
322
|
+
return {
|
|
323
|
+
artefacts: entriesWhere(facts.artefacts, (id) => declared.has(id)),
|
|
324
|
+
values: facts.values
|
|
325
|
+
};
|
|
326
|
+
};
|
|
327
|
+
/**
|
|
328
|
+
* Applies a change to a record: each artefact and named fact the change gives replaces what the record held for it, and the rest is kept. The result is not checked; see `factIssues`.
|
|
329
|
+
* @param facts - The stored record.
|
|
330
|
+
* @param change - The facts to record.
|
|
331
|
+
* @returns The merged record.
|
|
332
|
+
*/
|
|
333
|
+
const mergeFacts = (facts, change) => ({
|
|
334
|
+
artefacts: {
|
|
335
|
+
...facts.artefacts,
|
|
336
|
+
...change.artefacts
|
|
337
|
+
},
|
|
338
|
+
values: {
|
|
339
|
+
...facts.values,
|
|
340
|
+
...change.values
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
/**
|
|
344
|
+
* Forgets facts, so what they named is unknown again: the whole record with `all`, otherwise the named artefacts and named facts. A name the record does not hold is ignored.
|
|
345
|
+
* @param facts - The stored record.
|
|
346
|
+
* @param clearing - What to forget.
|
|
347
|
+
* @returns The record without what was forgotten.
|
|
348
|
+
*/
|
|
349
|
+
const withoutFacts = (facts, clearing) => {
|
|
350
|
+
if ("all" in clearing) return emptyFactRecord;
|
|
351
|
+
const artefacts = new Set(clearing.artefacts);
|
|
352
|
+
const values = new Set(clearing.values);
|
|
353
|
+
return {
|
|
354
|
+
artefacts: entriesWhere(facts.artefacts, (id) => !artefacts.has(id)),
|
|
355
|
+
values: entriesWhere(facts.values, (name) => !values.has(name))
|
|
356
|
+
};
|
|
357
|
+
};
|
|
358
|
+
/**
|
|
359
|
+
* The issues with a change to a model's facts: an artefact the model does not declare is an `unknown-reference`, as an unknown reference anywhere else in a model is. Named facts are free names, since any `reference` key in a condition may read one.
|
|
360
|
+
* @param model - The model the facts are for.
|
|
361
|
+
* @param change - The facts to record.
|
|
362
|
+
* @returns One issue per undeclared artefact, empty when every artefact resolves.
|
|
363
|
+
*/
|
|
364
|
+
const factIssues = (model, change) => {
|
|
365
|
+
const declared = new Set(model.artefacts.map(({ id }) => id));
|
|
366
|
+
return Object.keys(change.artefacts ?? {}).flatMap((id) => declared.has(id) ? [] : [{
|
|
367
|
+
code: "unknown-reference",
|
|
368
|
+
message: `facts refer to unknown artefact id "${id}"`
|
|
369
|
+
}]);
|
|
370
|
+
};
|
|
371
|
+
//#endregion
|
|
276
372
|
//#region ../../core/graph/store-contract/dist/hierarchy.js
|
|
277
373
|
/** Which identifier space each end of a relation of each kind names: a sub-task and its parent are elements, an assignee and a containing organisation are participants. */
|
|
278
374
|
const endpoints = {
|
|
@@ -441,33 +537,43 @@ const serialised = () => {
|
|
|
441
537
|
};
|
|
442
538
|
//#endregion
|
|
443
539
|
//#region ../../adapters/graph/store-sqlite/dist/generated/migrations.js
|
|
444
|
-
const migrations = [
|
|
445
|
-
|
|
446
|
-
"
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
540
|
+
const migrations = [
|
|
541
|
+
{
|
|
542
|
+
"sql": [
|
|
543
|
+
"CREATE TABLE `actions` (\n `model_id` text NOT NULL,\n `id` text NOT NULL,\n `position` integer NOT NULL,\n `name` text NOT NULL,\n CONSTRAINT `actions_pk` PRIMARY KEY(`model_id`, `id`)\n);\n",
|
|
544
|
+
"\nCREATE TABLE `artefacts` (\n `model_id` text NOT NULL,\n `id` text NOT NULL,\n `position` integer NOT NULL,\n `name` text NOT NULL,\n `deliverable` integer,\n CONSTRAINT `artefacts_pk` PRIMARY KEY(`model_id`, `id`)\n);\n",
|
|
545
|
+
"\nCREATE TABLE `elements` (\n `model_id` text NOT NULL,\n `id` text NOT NULL,\n `position` integer NOT NULL,\n `kind` text NOT NULL,\n `label` text,\n `actor` text,\n `action` text,\n `source` text,\n `affects` text,\n `consumes` text,\n `produces` text,\n `parent` text,\n `entry` text,\n `exit` text,\n `role` text,\n `from_actor` text,\n `to_actor` text,\n `mode` text,\n `event` text,\n `extensions` text,\n CONSTRAINT `elements_pk` PRIMARY KEY(`model_id`, `id`)\n);\n",
|
|
546
|
+
"\nCREATE TABLE `events` (\n `model_id` text NOT NULL,\n `id` text NOT NULL,\n `position` integer NOT NULL,\n `name` text NOT NULL,\n `payload` text,\n CONSTRAINT `events_pk` PRIMARY KEY(`model_id`, `id`)\n);\n",
|
|
547
|
+
"\nCREATE TABLE `fragments` (\n `model_id` text NOT NULL,\n `id` text NOT NULL,\n `position` integer NOT NULL,\n `operator` text NOT NULL,\n `operands` text NOT NULL,\n CONSTRAINT `fragments_pk` PRIMARY KEY(`model_id`, `id`)\n);\n",
|
|
548
|
+
"\nCREATE TABLE `models` (\n `id` text PRIMARY KEY,\n `revision` integer NOT NULL,\n `views` text\n);\n",
|
|
549
|
+
"\nCREATE TABLE `overlay` (\n `model_id` text NOT NULL,\n `element` text NOT NULL,\n `status` text NOT NULL,\n CONSTRAINT `overlay_pk` PRIMARY KEY(`model_id`, `element`)\n);\n",
|
|
550
|
+
"\nCREATE TABLE `participants` (\n `model_id` text NOT NULL,\n `id` text NOT NULL,\n `position` integer NOT NULL,\n `label` text NOT NULL,\n `kind` text NOT NULL,\n CONSTRAINT `participants_pk` PRIMARY KEY(`model_id`, `id`)\n);\n",
|
|
551
|
+
"\nCREATE TABLE `projections` (\n `model_id` text NOT NULL,\n `position` integer NOT NULL,\n `id` text NOT NULL,\n `notation` text NOT NULL,\n `subject` text,\n `scenario` text,\n CONSTRAINT `projections_pk` PRIMARY KEY(`model_id`, `position`)\n);\n",
|
|
552
|
+
"\nCREATE TABLE `sequences` (\n `name` text PRIMARY KEY,\n `value` integer NOT NULL\n);\n",
|
|
553
|
+
"\nCREATE TABLE `transitions` (\n `model_id` text NOT NULL,\n `id` text NOT NULL,\n `position` integer NOT NULL,\n `source` text NOT NULL,\n `target` text NOT NULL,\n `trigger` text,\n `guard` text,\n `condition` text,\n `effect` text,\n `loop` integer NOT NULL,\n CONSTRAINT `transitions_pk` PRIMARY KEY(`model_id`, `id`)\n);\n",
|
|
554
|
+
"\nCREATE INDEX `transitions_by_target` ON `transitions` (`model_id`,`target`);",
|
|
555
|
+
"\nCREATE INDEX `transitions_by_source` ON `transitions` (`model_id`,`source`);"
|
|
556
|
+
],
|
|
557
|
+
"bps": true,
|
|
558
|
+
"folderMillis": 1791646949e3,
|
|
559
|
+
"hash": "78b8523685396fc94dd78dccb22bc64697fc985a1be4e398b34e86af9f2b9bd3",
|
|
560
|
+
"name": "20261010154229_init"
|
|
561
|
+
},
|
|
562
|
+
{
|
|
563
|
+
"sql": ["CREATE TABLE `relations` (\n `model_id` text NOT NULL,\n `kind` text NOT NULL,\n `from_id` text NOT NULL,\n `to_id` text NOT NULL,\n `position` integer NOT NULL,\n CONSTRAINT `relations_pk` PRIMARY KEY(`model_id`, `kind`, `from_id`, `to_id`)\n);\n", "\nCREATE INDEX `relations_by_to` ON `relations` (`model_id`,`kind`,`to_id`);"],
|
|
564
|
+
"bps": true,
|
|
565
|
+
"folderMillis": 1791685834e3,
|
|
566
|
+
"hash": "441d05be00056c89f041364a03d9068c26d7a277538cf0561ae0fe198daecafc",
|
|
567
|
+
"name": "20261011023034_relations"
|
|
568
|
+
},
|
|
569
|
+
{
|
|
570
|
+
"sql": ["CREATE TABLE `artefact_facts` (\n `model_id` text NOT NULL,\n `artefact` text NOT NULL,\n `provided` integer NOT NULL,\n CONSTRAINT `artefact_facts_pk` PRIMARY KEY(`model_id`, `artefact`)\n);\n", "\nCREATE TABLE `named_facts` (\n `model_id` text NOT NULL,\n `name` text NOT NULL,\n `value` text NOT NULL,\n CONSTRAINT `named_facts_pk` PRIMARY KEY(`model_id`, `name`)\n);\n"],
|
|
571
|
+
"bps": true,
|
|
572
|
+
"folderMillis": 1791711779e3,
|
|
573
|
+
"hash": "426a8ef070c9d114fea34d6cf2e4c410ec3e04c5c1b7151890471c4c1895d75d",
|
|
574
|
+
"name": "20261011094259_facts"
|
|
575
|
+
}
|
|
576
|
+
];
|
|
471
577
|
//#endregion
|
|
472
578
|
//#region ../../adapters/graph/store-sqlite/dist/migrate.js
|
|
473
579
|
/** The journal table drizzle's own migrators keep, so a database migrated here is one drizzle-kit recognises, and the reverse. */
|
|
@@ -874,15 +980,45 @@ const fromRows = (rows) => modelSchema.parse({
|
|
|
874
980
|
* @returns The overlay.
|
|
875
981
|
*/
|
|
876
982
|
const overlayFromRows = (rows) => overlaySchema.parse(Object.fromEntries(rows.map(({ element, status }) => [element, status])));
|
|
983
|
+
/**
|
|
984
|
+
* Reassembles a fact record from its rows, parsing it with the contract's `factRecordSchema`, so every stored value is checked to be a trilean value.
|
|
985
|
+
* @param artefactRows - The model's artefact fact rows.
|
|
986
|
+
* @param valueRows - The model's named fact rows.
|
|
987
|
+
* @returns The fact record.
|
|
988
|
+
*/
|
|
989
|
+
const factsFromRows = (artefactRows, valueRows) => factRecordSchema.parse({
|
|
990
|
+
artefacts: Object.fromEntries(artefactRows.map(({ artefact, provided }) => [artefact, provided])),
|
|
991
|
+
values: Object.fromEntries(valueRows.map(({ name, value }) => [name, value]))
|
|
992
|
+
});
|
|
993
|
+
/**
|
|
994
|
+
* Flattens a fact record into rows for one model.
|
|
995
|
+
* @param modelId - The model the facts are about.
|
|
996
|
+
* @param facts - The record.
|
|
997
|
+
* @returns The artefact fact rows and the named fact rows.
|
|
998
|
+
*/
|
|
999
|
+
const factRows = (modelId, facts) => ({
|
|
1000
|
+
artefacts: Object.entries(facts.artefacts).map(([artefact, provided]) => ({
|
|
1001
|
+
modelId,
|
|
1002
|
+
artefact,
|
|
1003
|
+
provided
|
|
1004
|
+
})),
|
|
1005
|
+
values: Object.entries(facts.values).map(([name, value]) => ({
|
|
1006
|
+
modelId,
|
|
1007
|
+
name,
|
|
1008
|
+
value
|
|
1009
|
+
}))
|
|
1010
|
+
});
|
|
877
1011
|
//#endregion
|
|
878
1012
|
//#region ../../adapters/graph/store-sqlite/dist/tables.js
|
|
879
1013
|
var tables_exports = /* @__PURE__ */ __exportAll({
|
|
880
1014
|
actions: () => actions,
|
|
1015
|
+
artefactFacts: () => artefactFacts,
|
|
881
1016
|
artefacts: () => artefacts,
|
|
882
1017
|
elements: () => elements,
|
|
883
1018
|
events: () => events,
|
|
884
1019
|
fragments: () => fragments,
|
|
885
1020
|
models: () => models,
|
|
1021
|
+
namedFacts: () => namedFacts,
|
|
886
1022
|
overlay: () => overlay,
|
|
887
1023
|
participants: () => participants,
|
|
888
1024
|
projections: () => projections,
|
|
@@ -1012,6 +1148,18 @@ const relations = sqliteTable("relations", {
|
|
|
1012
1148
|
table.from,
|
|
1013
1149
|
table.to
|
|
1014
1150
|
] }), index("relations_by_to").on(table.modelId, table.kind, table.to)]);
|
|
1151
|
+
/** What is known about whether an artefact is provided, one row per artefact the model's fact record names: `provided` is true when it is provided and false when it is known not to be. An artefact with no row is unknown. */
|
|
1152
|
+
const artefactFacts = sqliteTable("artefact_facts", {
|
|
1153
|
+
modelId: text("model_id").notNull(),
|
|
1154
|
+
artefact: text("artefact").notNull(),
|
|
1155
|
+
provided: integer("provided", { mode: "boolean" }).notNull()
|
|
1156
|
+
}, (table) => [primaryKey({ columns: [table.modelId, table.artefact] })]);
|
|
1157
|
+
/** The value of each named fact a model's fact record holds, as JSON text, typed `unknown` because `rows.ts` checks it with trilean's value schema on every read. A name with no row is unknown. */
|
|
1158
|
+
const namedFacts = sqliteTable("named_facts", {
|
|
1159
|
+
modelId: text("model_id").notNull(),
|
|
1160
|
+
name: text("name").notNull(),
|
|
1161
|
+
value: text("value", { mode: "json" }).notNull()
|
|
1162
|
+
}, (table) => [primaryKey({ columns: [table.modelId, table.name] })]);
|
|
1015
1163
|
//#endregion
|
|
1016
1164
|
//#region ../../adapters/graph/store-sqlite/dist/store.js
|
|
1017
1165
|
/** The tables that hold a model's own records and the relations kept beside it, every one keyed by `modelId`. */
|
|
@@ -1026,6 +1174,8 @@ const recordTables = [
|
|
|
1026
1174
|
projections,
|
|
1027
1175
|
relations
|
|
1028
1176
|
];
|
|
1177
|
+
/** The tables that hold a model's fact record, both keyed by `modelId`. */
|
|
1178
|
+
const factTables = [artefactFacts, namedFacts];
|
|
1029
1179
|
/** The name of the store-wide revision sequence's row in `sequences`. */
|
|
1030
1180
|
const revisionSequence = "revision";
|
|
1031
1181
|
/**
|
|
@@ -1079,6 +1229,14 @@ const createSqliteGraphStore = (options) => {
|
|
|
1079
1229
|
from: relations.from,
|
|
1080
1230
|
to: relations.to
|
|
1081
1231
|
}).from(relations).where(eq(relations.modelId, modelId)).orderBy(asc(relations.position));
|
|
1232
|
+
const readFacts = async (modelId) => factsFromRows(await db.select().from(artefactFacts).where(eq(artefactFacts.modelId, modelId)).orderBy(asc(artefactFacts.artefact)), await db.select().from(namedFacts).where(eq(namedFacts.modelId, modelId)).orderBy(asc(namedFacts.name)));
|
|
1233
|
+
/** Replaces a model's fact rows with a record's; run inside the caller's transaction. */
|
|
1234
|
+
const replaceFacts = async (modelId, facts) => {
|
|
1235
|
+
await sequentially(factTables.map((table) => async () => db.delete(table).where(eq(table.modelId, modelId))));
|
|
1236
|
+
const rows = factRows(modelId, facts);
|
|
1237
|
+
if (rows.artefacts.length > 0) await db.insert(artefactFacts).values([...rows.artefacts]);
|
|
1238
|
+
if (rows.values.length > 0) await db.insert(namedFacts).values([...rows.values]);
|
|
1239
|
+
};
|
|
1082
1240
|
const read = async (modelId) => {
|
|
1083
1241
|
const [model] = await db.select().from(models).where(eq(models.id, modelId));
|
|
1084
1242
|
if (model === void 0) throw new GraphStoreError({
|
|
@@ -1100,7 +1258,8 @@ const createSqliteGraphStore = (options) => {
|
|
|
1100
1258
|
modelId,
|
|
1101
1259
|
revision: model.revision,
|
|
1102
1260
|
model: fromRows(rows),
|
|
1103
|
-
overlay: await readOverlay(modelId)
|
|
1261
|
+
overlay: await readOverlay(modelId),
|
|
1262
|
+
facts: await readFacts(modelId)
|
|
1104
1263
|
};
|
|
1105
1264
|
};
|
|
1106
1265
|
const removeRecords = async (modelId) => sequentially(recordTables.map((table) => async () => db.delete(table).where(eq(table.modelId, modelId))));
|
|
@@ -1115,10 +1274,10 @@ const createSqliteGraphStore = (options) => {
|
|
|
1115
1274
|
...rows.fragments.length > 0 ? [async () => db.insert(fragments).values([...rows.fragments])] : [],
|
|
1116
1275
|
...rows.projections.length > 0 ? [async () => db.insert(projections).values([...rows.projections])] : []
|
|
1117
1276
|
]);
|
|
1118
|
-
/** Replaces a model's rows, overlay and
|
|
1119
|
-
const write = async ({ modelId, kind, model, overlay: overlay$1, relations: relations$1, signal }) => {
|
|
1277
|
+
/** Replaces a model's rows, overlay, relations and facts in one transaction and publishes the change once it commits. */
|
|
1278
|
+
const write = async ({ modelId, kind, model, overlay: overlay$1, relations: relations$1, facts, signal }) => {
|
|
1120
1279
|
checkStored(model, overlay$1);
|
|
1121
|
-
const issues = relationIssues(model, relations$1);
|
|
1280
|
+
const issues = [...relationIssues(model, relations$1), ...factIssues(model, facts)];
|
|
1122
1281
|
if (issues.length > 0) throw new GraphStoreError({
|
|
1123
1282
|
kind: "invalid",
|
|
1124
1283
|
issues
|
|
@@ -1147,6 +1306,7 @@ const createSqliteGraphStore = (options) => {
|
|
|
1147
1306
|
...relation,
|
|
1148
1307
|
position
|
|
1149
1308
|
})));
|
|
1309
|
+
await replaceFacts(modelId, facts);
|
|
1150
1310
|
signal?.throwIfAborted();
|
|
1151
1311
|
return taken;
|
|
1152
1312
|
});
|
|
@@ -1157,6 +1317,27 @@ const createSqliteGraphStore = (options) => {
|
|
|
1157
1317
|
});
|
|
1158
1318
|
return revision;
|
|
1159
1319
|
};
|
|
1320
|
+
/** Replaces a model's fact record in one transaction, after checking it names only artefacts the model declares, and publishes the change once it commits. */
|
|
1321
|
+
const writeFacts = async ({ modelId, model, facts, signal }) => {
|
|
1322
|
+
const issues = factIssues(model, facts);
|
|
1323
|
+
if (issues.length > 0) throw new GraphStoreError({
|
|
1324
|
+
kind: "invalid",
|
|
1325
|
+
issues
|
|
1326
|
+
});
|
|
1327
|
+
const revision = await inTransaction(db, async () => {
|
|
1328
|
+
const taken = await nextRevision();
|
|
1329
|
+
await db.update(models).set({ revision: taken }).where(eq(models.id, modelId));
|
|
1330
|
+
await replaceFacts(modelId, facts);
|
|
1331
|
+
signal?.throwIfAborted();
|
|
1332
|
+
return taken;
|
|
1333
|
+
});
|
|
1334
|
+
feed.publish({
|
|
1335
|
+
modelId,
|
|
1336
|
+
kind: "facts",
|
|
1337
|
+
revision
|
|
1338
|
+
});
|
|
1339
|
+
return revision;
|
|
1340
|
+
};
|
|
1160
1341
|
return {
|
|
1161
1342
|
feed,
|
|
1162
1343
|
listModels: async () => operation(async () => db.select({
|
|
@@ -1171,6 +1352,7 @@ const createSqliteGraphStore = (options) => {
|
|
|
1171
1352
|
model,
|
|
1172
1353
|
overlay: overlayWithin(model, stored ? await readOverlay(modelId) : {}),
|
|
1173
1354
|
relations: relationsWithin(model, stored ? await readRelations(modelId) : []),
|
|
1355
|
+
facts: factsWithin(model, stored ? await readFacts(modelId) : emptyFactRecord),
|
|
1174
1356
|
signal
|
|
1175
1357
|
});
|
|
1176
1358
|
}),
|
|
@@ -1181,6 +1363,7 @@ const createSqliteGraphStore = (options) => {
|
|
|
1181
1363
|
const taken = await nextRevision();
|
|
1182
1364
|
await removeRecords(modelId);
|
|
1183
1365
|
await db.delete(overlay).where(eq(overlay.modelId, modelId));
|
|
1366
|
+
await replaceFacts(modelId, emptyFactRecord);
|
|
1184
1367
|
await db.delete(models).where(eq(models.id, modelId));
|
|
1185
1368
|
signal?.throwIfAborted();
|
|
1186
1369
|
return taken;
|
|
@@ -1220,11 +1403,42 @@ const createSqliteGraphStore = (options) => {
|
|
|
1220
1403
|
});
|
|
1221
1404
|
return revision;
|
|
1222
1405
|
}),
|
|
1406
|
+
readFacts: async ({ modelId }) => operation(async () => {
|
|
1407
|
+
const revision = await revisionOf(modelId);
|
|
1408
|
+
if (revision === void 0) throw new GraphStoreError({
|
|
1409
|
+
kind: "not-found",
|
|
1410
|
+
modelId
|
|
1411
|
+
});
|
|
1412
|
+
return {
|
|
1413
|
+
modelId,
|
|
1414
|
+
revision,
|
|
1415
|
+
facts: await readFacts(modelId)
|
|
1416
|
+
};
|
|
1417
|
+
}),
|
|
1418
|
+
setFacts: async ({ modelId, facts, signal }) => operation(async () => {
|
|
1419
|
+
const stored = await read(modelId);
|
|
1420
|
+
return writeFacts({
|
|
1421
|
+
modelId,
|
|
1422
|
+
model: stored.model,
|
|
1423
|
+
facts: mergeFacts(stored.facts, facts),
|
|
1424
|
+
signal
|
|
1425
|
+
});
|
|
1426
|
+
}),
|
|
1427
|
+
clearFacts: async ({ modelId, facts, signal }) => operation(async () => {
|
|
1428
|
+
const stored = await read(modelId);
|
|
1429
|
+
return writeFacts({
|
|
1430
|
+
modelId,
|
|
1431
|
+
model: stored.model,
|
|
1432
|
+
facts: withoutFacts(stored.facts, facts),
|
|
1433
|
+
signal
|
|
1434
|
+
});
|
|
1435
|
+
}),
|
|
1223
1436
|
upsertItems: async ({ modelId, items, signal }) => operation(async () => {
|
|
1224
1437
|
const stored = await revisionOf(modelId) === void 0 ? {
|
|
1225
1438
|
model: emptyModel,
|
|
1226
1439
|
overlay: {},
|
|
1227
|
-
relations: []
|
|
1440
|
+
relations: [],
|
|
1441
|
+
facts: emptyFactRecord
|
|
1228
1442
|
} : {
|
|
1229
1443
|
...await read(modelId),
|
|
1230
1444
|
relations: await readRelations(modelId)
|
|
@@ -1234,6 +1448,7 @@ const createSqliteGraphStore = (options) => {
|
|
|
1234
1448
|
kind: "items",
|
|
1235
1449
|
...mergeBoundItems(stored.model, stored.overlay, items),
|
|
1236
1450
|
relations: mergeRelations(stored.relations, items.relations ?? []),
|
|
1451
|
+
facts: stored.facts,
|
|
1237
1452
|
signal
|
|
1238
1453
|
});
|
|
1239
1454
|
}),
|
|
@@ -1284,4 +1499,4 @@ const createSqliteGraphStore = (options) => {
|
|
|
1284
1499
|
};
|
|
1285
1500
|
};
|
|
1286
1501
|
//#endregion
|
|
1287
|
-
export {
|
|
1502
|
+
export { modelIdSchema as A, boundItemsSchema as C, factNameSchema as D, factClearingSchema as E, revisionSchema as F, storeChangeSchema as I, storedFactsSchema as L, reachSchema as M, relationKinds as N, factRecordSchema as O, relationSchema as P, storedModelSchema as R, boundActivitySchema as S, factChangeSchema as T, mergeBoundItems as _, ancestorsOf as a, defaultSubscriptionCapacity as b, mergeRelations as c, factIssues as d, factsWithin as f, emptyModel as g, checkStored as h, serialised as i, modelSummarySchema as j, issueSchema as k, relationIssues as l, withoutFacts as m, tables_exports as n, childrenOf as o, mergeFacts as p, migrate as r, descendantsOf as s, createSqliteGraphStore as t, relationsWithin as u, overlayWithin as v, changeKinds as w, GraphStoreError as x, ChangeFeed as y };
|
package/dist/store.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as factRecordSchema, A as defaultSubscriptionCapacity, B as Reach, C as ElementRequest, D as ChangeFeedOptions, E as ChangeFeed, F as ChangeKind, G as StoredFacts, H as RelationKind, I as FactChange, J as boundItemsSchema, K as StoredModel, L as FactClearing, M as GraphStoreFailure, N as BoundActivity, O as ChangeSubscription, P as BoundItems, Q as factNameSchema, R as ModelId, S as overlayWithin, T as ModelRequest, U as Revision, V as Relation, W as StoreChange, X as factChangeSchema, Y as changeKinds, Z as factClearingSchema, _ as mergeFacts, a as blockedChainOf, at as relationSchema, b as emptyModel, c as structureOf, ct as storedFactsSchema, d as descendantsOf, dt as graphStoreContract, et as issueSchema, f as mergeRelations, g as factsWithin, h as factIssues, i as Structure, it as relationKinds, j as GraphStoreError, k as SubscribeOptions, l as ancestorsOf, lt as storedModelSchema, m as relationsWithin, n as GraphStoreRouter, nt as modelSummarySchema, o as impactOf, ot as revisionSchema, p as relationIssues, q as boundActivitySchema, r as createGraphStoreRouter, rt as reachSchema, s as readyOf, st as storeChangeSchema, t as createFakeGraphStore, tt as modelIdSchema, u as childrenOf, ut as GraphStoreClient, v as withoutFacts, w as GraphStore, x as mergeBoundItems, y as checkStored, z as ModelSummary } from "./index-CR8xUK3S.js";
|
|
2
2
|
import { SQLiteAsyncDatabase } from "drizzle-orm/sqlite-core";
|
|
3
3
|
import { MigrationMeta } from "drizzle-orm/migrator";
|
|
4
4
|
//#region ../../adapters/graph/store-sqlite/dist/database.d.ts
|
|
@@ -54,7 +54,7 @@ interface MigrateOptions {
|
|
|
54
54
|
*/
|
|
55
55
|
export declare const migrate: (db: SqliteDatabase, options?: MigrateOptions) => Promise<void>;
|
|
56
56
|
declare namespace tables_d_exports {
|
|
57
|
-
export { actions, artefacts, elements, events, fragments, models, overlay, participants, projections, relations, sequences, transitions };
|
|
57
|
+
export { actions, artefactFacts, artefacts, elements, events, fragments, models, namedFacts, overlay, participants, projections, relations, sequences, transitions };
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
60
|
* The storage projection of the process model. Every record a model declares is one row keyed by its model and its id, with `position` keeping the model's declared order, so a model loads back exactly as it was saved. Enumerated columns take their values from graph-schema's own vocabulary, and nested values (lists, extensions, conditions) are JSON text, typed `unknown` here because `rows.ts` checks them with the model schema on every read. Rows are never the contract's shape: `rows.ts` maps them to the model and back.
|
|
@@ -1324,5 +1324,117 @@ declare const relations: import("drizzle-orm/sqlite-core").SQLiteTableWithColumn
|
|
|
1324
1324
|
};
|
|
1325
1325
|
dialect: "sqlite";
|
|
1326
1326
|
}>;
|
|
1327
|
+
/** What is known about whether an artefact is provided, one row per artefact the model's fact record names: `provided` is true when it is provided and false when it is known not to be. An artefact with no row is unknown. */
|
|
1328
|
+
declare const artefactFacts: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
1329
|
+
name: "artefact_facts";
|
|
1330
|
+
schema: undefined;
|
|
1331
|
+
columns: {
|
|
1332
|
+
modelId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
1333
|
+
name: string;
|
|
1334
|
+
tableName: "artefact_facts";
|
|
1335
|
+
dataType: "string";
|
|
1336
|
+
data: string;
|
|
1337
|
+
driverParam: string;
|
|
1338
|
+
notNull: true;
|
|
1339
|
+
hasDefault: false;
|
|
1340
|
+
isPrimaryKey: false;
|
|
1341
|
+
isAutoincrement: false;
|
|
1342
|
+
hasRuntimeDefault: false;
|
|
1343
|
+
enumValues: [string, ...string[]];
|
|
1344
|
+
baseColumn: never;
|
|
1345
|
+
identity: undefined;
|
|
1346
|
+
generated: undefined;
|
|
1347
|
+
}, {}>;
|
|
1348
|
+
artefact: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
1349
|
+
name: string;
|
|
1350
|
+
tableName: "artefact_facts";
|
|
1351
|
+
dataType: "string";
|
|
1352
|
+
data: string;
|
|
1353
|
+
driverParam: string;
|
|
1354
|
+
notNull: true;
|
|
1355
|
+
hasDefault: false;
|
|
1356
|
+
isPrimaryKey: false;
|
|
1357
|
+
isAutoincrement: false;
|
|
1358
|
+
hasRuntimeDefault: false;
|
|
1359
|
+
enumValues: [string, ...string[]];
|
|
1360
|
+
baseColumn: never;
|
|
1361
|
+
identity: undefined;
|
|
1362
|
+
generated: undefined;
|
|
1363
|
+
}, {}>;
|
|
1364
|
+
provided: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
1365
|
+
name: string;
|
|
1366
|
+
tableName: "artefact_facts";
|
|
1367
|
+
dataType: "boolean";
|
|
1368
|
+
data: boolean;
|
|
1369
|
+
driverParam: number;
|
|
1370
|
+
notNull: true;
|
|
1371
|
+
hasDefault: false;
|
|
1372
|
+
isPrimaryKey: false;
|
|
1373
|
+
isAutoincrement: false;
|
|
1374
|
+
hasRuntimeDefault: false;
|
|
1375
|
+
enumValues: undefined;
|
|
1376
|
+
baseColumn: never;
|
|
1377
|
+
identity: undefined;
|
|
1378
|
+
generated: undefined;
|
|
1379
|
+
}, {}>;
|
|
1380
|
+
};
|
|
1381
|
+
dialect: "sqlite";
|
|
1382
|
+
}>;
|
|
1383
|
+
/** The value of each named fact a model's fact record holds, as JSON text, typed `unknown` because `rows.ts` checks it with trilean's value schema on every read. A name with no row is unknown. */
|
|
1384
|
+
declare const namedFacts: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
1385
|
+
name: "named_facts";
|
|
1386
|
+
schema: undefined;
|
|
1387
|
+
columns: {
|
|
1388
|
+
modelId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
1389
|
+
name: string;
|
|
1390
|
+
tableName: "named_facts";
|
|
1391
|
+
dataType: "string";
|
|
1392
|
+
data: string;
|
|
1393
|
+
driverParam: string;
|
|
1394
|
+
notNull: true;
|
|
1395
|
+
hasDefault: false;
|
|
1396
|
+
isPrimaryKey: false;
|
|
1397
|
+
isAutoincrement: false;
|
|
1398
|
+
hasRuntimeDefault: false;
|
|
1399
|
+
enumValues: [string, ...string[]];
|
|
1400
|
+
baseColumn: never;
|
|
1401
|
+
identity: undefined;
|
|
1402
|
+
generated: undefined;
|
|
1403
|
+
}, {}>;
|
|
1404
|
+
name: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
1405
|
+
name: string;
|
|
1406
|
+
tableName: "named_facts";
|
|
1407
|
+
dataType: "string";
|
|
1408
|
+
data: string;
|
|
1409
|
+
driverParam: string;
|
|
1410
|
+
notNull: true;
|
|
1411
|
+
hasDefault: false;
|
|
1412
|
+
isPrimaryKey: false;
|
|
1413
|
+
isAutoincrement: false;
|
|
1414
|
+
hasRuntimeDefault: false;
|
|
1415
|
+
enumValues: [string, ...string[]];
|
|
1416
|
+
baseColumn: never;
|
|
1417
|
+
identity: undefined;
|
|
1418
|
+
generated: undefined;
|
|
1419
|
+
}, {}>;
|
|
1420
|
+
value: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
1421
|
+
name: string;
|
|
1422
|
+
tableName: "named_facts";
|
|
1423
|
+
dataType: "object json";
|
|
1424
|
+
data: unknown;
|
|
1425
|
+
driverParam: string;
|
|
1426
|
+
notNull: true;
|
|
1427
|
+
hasDefault: false;
|
|
1428
|
+
isPrimaryKey: false;
|
|
1429
|
+
isAutoincrement: false;
|
|
1430
|
+
hasRuntimeDefault: false;
|
|
1431
|
+
enumValues: undefined;
|
|
1432
|
+
baseColumn: never;
|
|
1433
|
+
identity: undefined;
|
|
1434
|
+
generated: undefined;
|
|
1435
|
+
}, {}>;
|
|
1436
|
+
};
|
|
1437
|
+
dialect: "sqlite";
|
|
1438
|
+
}>;
|
|
1327
1439
|
//#endregion
|
|
1328
|
-
export { type BoundActivity, type BoundItems, ChangeFeed, type ChangeFeedOptions, type ChangeKind, type ChangeSubscription, type ElementRequest, type Exclusive, type GraphStore, type GraphStoreClient, GraphStoreError, type GraphStoreFailure, type GraphStoreRouter, type ModelId, type ModelRequest, type ModelSummary, type Reach, type Relation, type RelationKind, type Revision, type SqliteDatabase, type SqliteGraphStoreOptions, type StoreChange, type StoredModel, type Structure, type SubscribeOptions, ancestorsOf, blockedChainOf, boundActivitySchema, boundItemsSchema, changeKinds, checkStored, childrenOf, createFakeGraphStore, createGraphStoreRouter, defaultSubscriptionCapacity, descendantsOf, emptyModel, graphStoreContract, impactOf, issueSchema, mergeBoundItems, mergeRelations, modelIdSchema, modelSummarySchema, overlayWithin, reachSchema, readyOf, relationIssues, relationKinds, relationSchema, relationsWithin, revisionSchema, storeChangeSchema, storedModelSchema, structureOf, tables_d_exports as tables };
|
|
1440
|
+
export { type BoundActivity, type BoundItems, ChangeFeed, type ChangeFeedOptions, type ChangeKind, type ChangeSubscription, type ElementRequest, type Exclusive, type FactChange, type FactClearing, type GraphStore, type GraphStoreClient, GraphStoreError, type GraphStoreFailure, type GraphStoreRouter, type ModelId, type ModelRequest, type ModelSummary, type Reach, type Relation, type RelationKind, type Revision, type SqliteDatabase, type SqliteGraphStoreOptions, type StoreChange, type StoredFacts, type StoredModel, type Structure, type SubscribeOptions, ancestorsOf, blockedChainOf, boundActivitySchema, boundItemsSchema, changeKinds, checkStored, childrenOf, createFakeGraphStore, createGraphStoreRouter, defaultSubscriptionCapacity, descendantsOf, emptyModel, factChangeSchema, factClearingSchema, factIssues, factNameSchema, factRecordSchema, factsWithin, graphStoreContract, impactOf, issueSchema, mergeBoundItems, mergeFacts, mergeRelations, modelIdSchema, modelSummarySchema, overlayWithin, reachSchema, readyOf, relationIssues, relationKinds, relationSchema, relationsWithin, revisionSchema, storeChangeSchema, storedFactsSchema, storedModelSchema, structureOf, tables_d_exports as tables, withoutFacts };
|