@cavelang/store 0.5.0 → 0.13.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 +24 -6
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/store.d.ts +55 -5
- package/dist/src/store.d.ts.map +1 -1
- package/dist/src/store.js +104 -15
- package/dist/src/store.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +1 -1
- package/src/store.ts +135 -16
package/README.md
CHANGED
|
@@ -38,17 +38,32 @@ store.exportText({ current: true }) // canonical CAVE text back out
|
|
|
38
38
|
(`@ 0%`) rows; opt back in with `{ negated: true, retracted: true }`.
|
|
39
39
|
Contradictions still coexist as rows (§9.4) — resolution belongs to the
|
|
40
40
|
query layer.
|
|
41
|
+
- **Alias closure is opt-in** (§13.6): `{ aliases: true }` on traversal
|
|
42
|
+
(and on `claimsAbout`) matches the entity through every name linked by
|
|
43
|
+
current positive `ALIAS` claims, read as undirected edges;
|
|
44
|
+
`aliasesOf(entity)` returns the closure itself. Union-of-rows semantics:
|
|
45
|
+
matching widens, stored names come back untouched, and disagreeing
|
|
46
|
+
belief series surface side by side rather than merging silently. Unmerge
|
|
47
|
+
is retraction — `dupe ALIAS canonical @ 0%`.
|
|
48
|
+
- **Actor provenance is caller-supplied** (§9.5): `ingest`/`insertResult`
|
|
49
|
+
accept `{ source }` and stamp `@src:<source>` on every appended claim
|
|
50
|
+
that carries no `src:` context — *before* the claim key is computed, so
|
|
51
|
+
the stamp is part of claim identity and the same fact asserted by
|
|
52
|
+
different actors keeps separate belief series (§9.4). A written `@src:`
|
|
53
|
+
always wins; `raw_line` stays as authored. Interchange replay (`cave
|
|
54
|
+
import`) passes no source, preserving exported keys.
|
|
41
55
|
|
|
42
56
|
## API
|
|
43
57
|
|
|
44
58
|
| Method | Spec | Purpose |
|
|
45
59
|
|---|---|---|
|
|
46
|
-
| `ingest(text, {strict})` | §13.4 | parse → canonicalize → append; lenient by default |
|
|
47
|
-
| `insertResult(result)` | | append a pre-canonicalized `@cavelang/canonical` result |
|
|
60
|
+
| `ingest(text, {strict, source})` | §13.4 | parse → canonicalize → append; lenient by default |
|
|
61
|
+
| `insertResult(result, {source})` | | append a pre-canonicalized `@cavelang/canonical` result |
|
|
48
62
|
| `currentBeliefs({minConf})` | §13.5 | latest row per key |
|
|
49
63
|
| `currentBelief(key)` / `history(key)` | §9.1 | one fact's belief series |
|
|
50
|
-
| `claimsAbout(entity)` | §13.5 | both directions, all rows |
|
|
64
|
+
| `claimsAbout(entity, {aliases})` | §13.5 | both directions, all rows |
|
|
51
65
|
| `forward(entity)` / `reverse(entity)` | §13.3 | named traversal, inverse-aware |
|
|
66
|
+
| `aliasesOf(entity)` | §13.6 | the entity's alias closure |
|
|
52
67
|
| `byTag(key, value?)` | §13.5 | flat (`value` omitted → `IS NULL`) or scoped |
|
|
53
68
|
| `byContext(ctx)` | §13.5 | context filter |
|
|
54
69
|
| `topicMembers(t)` / `topicsOf(e)` | §11.2 | topic layer over `CONTAINS` |
|
|
@@ -86,6 +101,9 @@ pnpm --filter @cavelang/store test
|
|
|
86
101
|
|
|
87
102
|
Covers the §9.1 belief series, §5.5 one-fact-two-names invariants
|
|
88
103
|
(unified belief through either name, negation riding the row, no
|
|
89
|
-
materialized inverses), every §13.5 query, the §
|
|
90
|
-
|
|
91
|
-
|
|
104
|
+
materialized inverses), every §13.5 query, the §13.6 alias closure
|
|
105
|
+
(merge, unmerge by retraction, opt-in traversal, union semantics), the
|
|
106
|
+
§9.5 provenance stamping (written `@src:` wins, per-actor series,
|
|
107
|
+
cross-actor retraction, stamped round-trips), the §11.2 topic reads,
|
|
108
|
+
edge persistence, registry rebuild across reopen, transactional strict
|
|
109
|
+
ingest and export round-trips.
|
package/dist/src/index.d.ts
CHANGED
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
export * as Row from './row.ts';
|
|
15
15
|
export * as Schema from './schema.ts';
|
|
16
16
|
export { defaultDbPath, open } from './store.ts';
|
|
17
|
-
export type { ForwardFact, IngestResult, ReverseFact, Store, TraverseOptions } from './store.ts';
|
|
17
|
+
export type { AppendOptions, ForwardFact, IngestResult, ReverseFact, Store, TraverseOptions } from './store.ts';
|
|
18
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAC/B,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAChD,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAC/B,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAChD,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/src/store.d.ts
CHANGED
|
@@ -8,7 +8,10 @@
|
|
|
8
8
|
* - the verb registry is rebuilt from stored in-band declaration claims on
|
|
9
9
|
* open, so a reopened database keeps its inverse vocabulary;
|
|
10
10
|
* - full-text search over subjects, objects, values, comments and raw
|
|
11
|
-
* lines via FTS5
|
|
11
|
+
* lines via FTS5;
|
|
12
|
+
* - appends can stamp actor provenance (spec §9.5): pass `source` and every
|
|
13
|
+
* claim without a `src:` context gets `@src:<actor>` — applied before the
|
|
14
|
+
* claim key is computed, so different actors keep separate belief series.
|
|
12
15
|
*/
|
|
13
16
|
import { DatabaseSync } from 'node:sqlite';
|
|
14
17
|
import { Claim } from '@cavelang/core';
|
|
@@ -20,6 +23,17 @@ export type IngestResult = {
|
|
|
20
23
|
readonly edges: number;
|
|
21
24
|
readonly problems: readonly Canonical.Problem[];
|
|
22
25
|
};
|
|
26
|
+
export type AppendOptions = {
|
|
27
|
+
/**
|
|
28
|
+
* Actor provenance (spec §9.5): stamp `@src:<source>` on every appended
|
|
29
|
+
* claim that carries no `src:` context — e.g. `cli`, `agent/claude-code`,
|
|
30
|
+
* `ingest/93a01c626b3f`. Applied before the claim key is computed, so the
|
|
31
|
+
* stamp is part of claim identity; claims that already name a source keep
|
|
32
|
+
* it untouched. Omit for interchange replay (`cave import`), which must
|
|
33
|
+
* preserve claim keys as exported.
|
|
34
|
+
*/
|
|
35
|
+
readonly source?: string;
|
|
36
|
+
};
|
|
23
37
|
export type ForwardFact = {
|
|
24
38
|
/** Canonical (primary) verb. */
|
|
25
39
|
readonly verb: string;
|
|
@@ -39,6 +53,12 @@ export type TraverseOptions = {
|
|
|
39
53
|
readonly negated?: boolean;
|
|
40
54
|
/** Include rows whose current belief is `@ 0%` (default `false`). */
|
|
41
55
|
readonly retracted?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Match the entity through its alias closure — every name linked by
|
|
58
|
+
* current positive `ALIAS` claims (spec §13.6, default `false`).
|
|
59
|
+
* Union-of-rows: matching widens, returned rows keep their stored names.
|
|
60
|
+
*/
|
|
61
|
+
readonly aliases?: boolean;
|
|
42
62
|
};
|
|
43
63
|
export type Store = ReturnType<typeof open>;
|
|
44
64
|
/**
|
|
@@ -61,16 +81,24 @@ export declare const open: (path?: string, options?: {
|
|
|
61
81
|
db: DatabaseSync;
|
|
62
82
|
/** Current verb registry (input registry + stored + ingested declarations). */
|
|
63
83
|
registry: () => Canonical.Registry.t;
|
|
84
|
+
/**
|
|
85
|
+
* Runs `body` atomically; throwing rolls everything back, including
|
|
86
|
+
* nested appends and their registry declarations. Nestable
|
|
87
|
+
* (savepoints) — the write gate wraps ingest + check in one of these
|
|
88
|
+
* (spec §20.3).
|
|
89
|
+
*/
|
|
90
|
+
transaction: <T>(body: () => T) => T;
|
|
64
91
|
/**
|
|
65
92
|
* Parses, canonicalizes and appends CAVE text. Lenient by default —
|
|
66
93
|
* problems are returned, valid lines still land (spec §1.6); pass
|
|
67
|
-
* `strict` to throw instead
|
|
94
|
+
* `strict` to throw instead, `source` to stamp actor provenance
|
|
95
|
+
* (spec §9.5).
|
|
68
96
|
*/
|
|
69
97
|
ingest(text: string, options_?: {
|
|
70
98
|
strict?: boolean;
|
|
71
|
-
}): IngestResult;
|
|
99
|
+
} & AppendOptions): IngestResult;
|
|
72
100
|
/** Appends an already-canonicalized result. */
|
|
73
|
-
insertResult: (result: Canonical.Result) => IngestResult;
|
|
101
|
+
insertResult: (result: Canonical.Result, options_?: AppendOptions) => IngestResult;
|
|
74
102
|
/** Latest row per claim key (spec §13.5), oldest first. */
|
|
75
103
|
currentBeliefs(options_?: {
|
|
76
104
|
minConf?: number;
|
|
@@ -79,8 +107,17 @@ export declare const open: (path?: string, options?: {
|
|
|
79
107
|
currentBelief(claimKey: string): undefined | Row.t;
|
|
80
108
|
/** Full belief series of one claim key, oldest first (spec §9.1). */
|
|
81
109
|
history(claimKey: string): Row.t[];
|
|
110
|
+
/**
|
|
111
|
+
* The alias closure of an entity (spec §13.6): the entity itself plus
|
|
112
|
+
* every name reachable through current positive `ALIAS` claims, read as
|
|
113
|
+
* undirected edges. Unmerge is retraction — appending `a ALIAS b @ 0%`
|
|
114
|
+
* removes that link. The queried name first, the rest sorted.
|
|
115
|
+
*/
|
|
116
|
+
aliasesOf(entity: string): string[];
|
|
82
117
|
/** All rows about an entity, both directions, newest first (spec §13.5). */
|
|
83
|
-
claimsAbout(entity: string
|
|
118
|
+
claimsAbout(entity: string, options_?: {
|
|
119
|
+
aliases?: boolean;
|
|
120
|
+
}): Row.t[];
|
|
84
121
|
/** Forward reads: current relational facts with `entity` as subject (spec §13.3). */
|
|
85
122
|
forward(entity: string, options_?: TraverseOptions): ForwardFact[];
|
|
86
123
|
/**
|
|
@@ -106,6 +143,19 @@ export declare const open: (path?: string, options?: {
|
|
|
106
143
|
search(query: string, options_?: {
|
|
107
144
|
raw?: boolean;
|
|
108
145
|
}): Row.t[];
|
|
146
|
+
/**
|
|
147
|
+
* Appends edges between *existing* claim rows (spec §13.2) — the
|
|
148
|
+
* derivation-lineage path (§24.3): a derived row points `BECAUSE` at
|
|
149
|
+
* the specific premise rows that fired and `VIA` at the rule's
|
|
150
|
+
* declaration row. `insertResult` covers edges within one appended
|
|
151
|
+
* batch; this covers edges into rows that are already stored. Foreign
|
|
152
|
+
* keys reject unknown ids.
|
|
153
|
+
*/
|
|
154
|
+
appendEdges(edges: readonly {
|
|
155
|
+
parentId: string;
|
|
156
|
+
role: Canonical.EdgeRole;
|
|
157
|
+
childId: string;
|
|
158
|
+
}[]): void;
|
|
109
159
|
/** Qualifier/grouping edges of a claim row (spec §13.2). */
|
|
110
160
|
edgesOf(parentId: string): {
|
|
111
161
|
role: string;
|
package/dist/src/store.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,KAAK,EAA8B,MAAM,gBAAgB,CAAA;AAClE,OAAO,KAAK,SAAS,MAAM,qBAAqB,CAAA;AAChD,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAgC/B,MAAM,MAAM,YAAY,GAAG;IACzB,qDAAqD;IACrD,QAAQ,CAAC,GAAG,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AAI,EAAE,SAAS,CAAC,QAAQ,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,GAAG,IAAI;IAQpG,4DAA4D;sBAC1C,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAA;KAAE,EAAE;IAO3D,6EAA6E;mBA9LzD,GAAG,CAAC,CAAC,KAAG,KAAK,CAAC,CAAC;IAiMnC;;;;;;;;;OASG;0BACkB;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GAAQ,MAAM;aAmC/C,IAAI;CAIhB,CAAA"}
|
package/dist/src/store.js
CHANGED
|
@@ -8,10 +8,13 @@
|
|
|
8
8
|
* - the verb registry is rebuilt from stored in-band declaration claims on
|
|
9
9
|
* open, so a reopened database keeps its inverse vocabulary;
|
|
10
10
|
* - full-text search over subjects, objects, values, comments and raw
|
|
11
|
-
* lines via FTS5
|
|
11
|
+
* lines via FTS5;
|
|
12
|
+
* - appends can stamp actor provenance (spec §9.5): pass `source` and every
|
|
13
|
+
* claim without a `src:` context gets `@src:<actor>` — applied before the
|
|
14
|
+
* claim key is computed, so different actors keep separate belief series.
|
|
12
15
|
*/
|
|
13
16
|
import { DatabaseSync } from 'node:sqlite';
|
|
14
|
-
import { Claim, Key, Uuidv7, Verb } from '@cavelang/core';
|
|
17
|
+
import { Claim, Context, Key, Uuidv7, Verb } from '@cavelang/core';
|
|
15
18
|
import * as Canonical from '@cavelang/canonical';
|
|
16
19
|
import * as Row from "./row.js";
|
|
17
20
|
import * as Schema from "./schema.js";
|
|
@@ -22,6 +25,30 @@ JOIN (
|
|
|
22
25
|
FROM cave_claim GROUP BY claim_key
|
|
23
26
|
) latest ON c.claim_key = latest.claim_key AND c.tx = latest.max_tx
|
|
24
27
|
`;
|
|
28
|
+
/**
|
|
29
|
+
* Alias closure (spec §13.6): current positive `ALIAS` claims as undirected
|
|
30
|
+
* edges (`ALIAS` has no `REVERSE`, so each written direction is its own
|
|
31
|
+
* claim key — both assert the same link), walked recursively from a seed
|
|
32
|
+
* entity. Retraction unmerges: `a ALIAS b @ 0%` drops that direction's edge.
|
|
33
|
+
* The seed is the query's single positional parameter.
|
|
34
|
+
*/
|
|
35
|
+
const aliasClosureSql = `
|
|
36
|
+
WITH RECURSIVE alias_edge(a, b) AS (
|
|
37
|
+
SELECT c.subject, c.object FROM (${currentSql}) c
|
|
38
|
+
WHERE c.verb = 'ALIAS' AND c.negated = 0 AND c.conf > 0 AND c.object IS NOT NULL
|
|
39
|
+
UNION
|
|
40
|
+
SELECT c.object, c.subject FROM (${currentSql}) c
|
|
41
|
+
WHERE c.verb = 'ALIAS' AND c.negated = 0 AND c.conf > 0 AND c.object IS NOT NULL
|
|
42
|
+
), alias_closure(name) AS (
|
|
43
|
+
SELECT ?
|
|
44
|
+
UNION
|
|
45
|
+
SELECT e.b FROM alias_closure s JOIN alias_edge e ON e.a = s.name
|
|
46
|
+
)
|
|
47
|
+
`;
|
|
48
|
+
/** Stamps `@src:<source>` on a claim without a source context (spec §9.5). */
|
|
49
|
+
const stampSource = (claim, source) => source === undefined || Context.hasSource(claim.contexts) ?
|
|
50
|
+
claim :
|
|
51
|
+
{ ...claim, contexts: [...claim.contexts, Context.source(source)] };
|
|
25
52
|
/**
|
|
26
53
|
* Database path used by CLI surfaces when `--db` is omitted: the `CAVE_DB`
|
|
27
54
|
* environment variable, falling back to `cave.db` in the current directory.
|
|
@@ -83,23 +110,39 @@ export const open = (path = ':memory:', options = {}) => {
|
|
|
83
110
|
}
|
|
84
111
|
};
|
|
85
112
|
rebuildRegistry();
|
|
113
|
+
/**
|
|
114
|
+
* Savepoint-based, so transactions nest: a caller can wrap several
|
|
115
|
+
* appends — or an append plus checks against the appended state — and
|
|
116
|
+
* roll the whole group back by throwing (spec §20.3 write gating).
|
|
117
|
+
* Rollback also restores the in-memory verb registry, so declarations
|
|
118
|
+
* from rolled-back claims don't outlive their rows.
|
|
119
|
+
*/
|
|
120
|
+
let transactionDepth = 0;
|
|
86
121
|
const transaction = (body) => {
|
|
87
|
-
|
|
122
|
+
const savepoint = `cave_tx_${transactionDepth}`;
|
|
123
|
+
transactionDepth += 1;
|
|
124
|
+
const savedRegistry = registry;
|
|
125
|
+
db.exec(`SAVEPOINT ${savepoint}`);
|
|
88
126
|
try {
|
|
89
127
|
const result = body();
|
|
90
|
-
db.exec(
|
|
128
|
+
db.exec(`RELEASE ${savepoint}`);
|
|
91
129
|
return result;
|
|
92
130
|
}
|
|
93
131
|
catch (error) {
|
|
94
|
-
db.exec(
|
|
132
|
+
db.exec(`ROLLBACK TO ${savepoint}`);
|
|
133
|
+
db.exec(`RELEASE ${savepoint}`);
|
|
134
|
+
registry = savedRegistry;
|
|
95
135
|
throw error;
|
|
96
136
|
}
|
|
137
|
+
finally {
|
|
138
|
+
transactionDepth -= 1;
|
|
139
|
+
}
|
|
97
140
|
};
|
|
98
141
|
/** Appends a canonicalization result — one row per claim, per-row tx. */
|
|
99
|
-
const insertResult = (result) => transaction(() => {
|
|
142
|
+
const insertResult = (result, options_ = {}) => transaction(() => {
|
|
100
143
|
const ids = [];
|
|
101
144
|
for (const entry of result.claims) {
|
|
102
|
-
const claim = entry.claim;
|
|
145
|
+
const claim = stampSource(entry.claim, options_.source);
|
|
103
146
|
const id = Uuidv7.next();
|
|
104
147
|
const columns = Row.toColumns(claim);
|
|
105
148
|
const rawLine = columns.rawLine === '' ? Canonical.emitClaim(claim) : columns.rawLine;
|
|
@@ -126,15 +169,31 @@ export const open = (path = ':memory:', options = {}) => {
|
|
|
126
169
|
const toClaim = (row) => Row.toClaim(row, contextsOf(row.id), tagsOf(row.id));
|
|
127
170
|
const traversalFilter = (options) => (options.negated === true ? '' : ' AND negated = 0') +
|
|
128
171
|
(options.retracted === true ? '' : ' AND conf > 0');
|
|
172
|
+
/**
|
|
173
|
+
* Entity-matching fragment for one traversal endpoint: exact by default,
|
|
174
|
+
* `IN` the alias closure when opted in. Either form consumes exactly one
|
|
175
|
+
* positional parameter — the closure seeds from it (`aliasClosureSql`
|
|
176
|
+
* must be prepended when `aliases` is set).
|
|
177
|
+
*/
|
|
178
|
+
const entityMatch = (column, options) => options.aliases === true ? `${column} IN (SELECT name FROM alias_closure)` : `${column} = ?`;
|
|
179
|
+
const withAliases = (options) => options.aliases === true ? aliasClosureSql : '';
|
|
129
180
|
return {
|
|
130
181
|
/** Raw database handle — used by `@cavelang/query`; treat as read-only. */
|
|
131
182
|
db,
|
|
132
183
|
/** Current verb registry (input registry + stored + ingested declarations). */
|
|
133
184
|
registry: () => registry,
|
|
185
|
+
/**
|
|
186
|
+
* Runs `body` atomically; throwing rolls everything back, including
|
|
187
|
+
* nested appends and their registry declarations. Nestable
|
|
188
|
+
* (savepoints) — the write gate wraps ingest + check in one of these
|
|
189
|
+
* (spec §20.3).
|
|
190
|
+
*/
|
|
191
|
+
transaction,
|
|
134
192
|
/**
|
|
135
193
|
* Parses, canonicalizes and appends CAVE text. Lenient by default —
|
|
136
194
|
* problems are returned, valid lines still land (spec §1.6); pass
|
|
137
|
-
* `strict` to throw instead
|
|
195
|
+
* `strict` to throw instead, `source` to stamp actor provenance
|
|
196
|
+
* (spec §9.5).
|
|
138
197
|
*/
|
|
139
198
|
ingest(text, options_ = {}) {
|
|
140
199
|
const result = Canonical.canonicalizeText(text, registry);
|
|
@@ -142,7 +201,7 @@ export const open = (path = ':memory:', options = {}) => {
|
|
|
142
201
|
const detail = result.problems.map(problem => ` line ${problem.line}: ${problem.message}`).join('\n');
|
|
143
202
|
throw new Error(`CAVE ingest failed with ${result.problems.length} problem(s):\n${detail}`);
|
|
144
203
|
}
|
|
145
|
-
return insertResult(result);
|
|
204
|
+
return insertResult(result, options_);
|
|
146
205
|
},
|
|
147
206
|
/** Appends an already-canonicalized result. */
|
|
148
207
|
insertResult,
|
|
@@ -161,13 +220,28 @@ export const open = (path = ':memory:', options = {}) => {
|
|
|
161
220
|
history(claimKey) {
|
|
162
221
|
return rows('SELECT * FROM cave_claim WHERE claim_key = ? ORDER BY tx', claimKey);
|
|
163
222
|
},
|
|
223
|
+
/**
|
|
224
|
+
* The alias closure of an entity (spec §13.6): the entity itself plus
|
|
225
|
+
* every name reachable through current positive `ALIAS` claims, read as
|
|
226
|
+
* undirected edges. Unmerge is retraction — appending `a ALIAS b @ 0%`
|
|
227
|
+
* removes that link. The queried name first, the rest sorted.
|
|
228
|
+
*/
|
|
229
|
+
aliasesOf(entity) {
|
|
230
|
+
const names = db.prepare(`${aliasClosureSql} SELECT name FROM alias_closure WHERE name <> ? ORDER BY name`)
|
|
231
|
+
.all(entity, entity);
|
|
232
|
+
return [entity, ...names.map(row => row.name)];
|
|
233
|
+
},
|
|
164
234
|
/** All rows about an entity, both directions, newest first (spec §13.5). */
|
|
165
|
-
claimsAbout(entity) {
|
|
166
|
-
return
|
|
235
|
+
claimsAbout(entity, options_ = {}) {
|
|
236
|
+
return options_.aliases === true ?
|
|
237
|
+
rows(`${aliasClosureSql} SELECT * FROM cave_claim
|
|
238
|
+
WHERE subject IN (SELECT name FROM alias_closure) OR object IN (SELECT name FROM alias_closure)
|
|
239
|
+
ORDER BY tx DESC`, entity) :
|
|
240
|
+
rows('SELECT * FROM cave_claim WHERE subject = ? OR object = ? ORDER BY tx DESC', entity, entity);
|
|
167
241
|
},
|
|
168
242
|
/** Forward reads: current relational facts with `entity` as subject (spec §13.3). */
|
|
169
243
|
forward(entity, options_ = {}) {
|
|
170
|
-
return rows(
|
|
244
|
+
return rows(`${withAliases(options_)} SELECT * FROM (${currentSql}) WHERE ${entityMatch('subject', options_)} AND object IS NOT NULL${traversalFilter(options_)} ORDER BY tx`, entity).map(row => ({ verb: row.verb, target: row.object, row }));
|
|
171
245
|
},
|
|
172
246
|
/**
|
|
173
247
|
* Inverse reads (spec §13.3): current relational facts
|
|
@@ -175,7 +249,7 @@ export const open = (path = ':memory:', options = {}) => {
|
|
|
175
249
|
* when one is declared.
|
|
176
250
|
*/
|
|
177
251
|
reverse(entity, options_ = {}) {
|
|
178
|
-
return rows(
|
|
252
|
+
return rows(`${withAliases(options_)} SELECT * FROM (${currentSql}) WHERE ${entityMatch('object', options_)} AND object IS NOT NULL${traversalFilter(options_)} ORDER BY tx`, entity).map(row => {
|
|
179
253
|
const rel = Canonical.Registry.inverseOf(registry, row.verb);
|
|
180
254
|
return { verb: row.verb, ...rel === undefined ? {} : { rel }, source: row.subject, row };
|
|
181
255
|
});
|
|
@@ -198,11 +272,11 @@ export const open = (path = ':memory:', options = {}) => {
|
|
|
198
272
|
},
|
|
199
273
|
/** Members of a topic — forward `CONTAINS` traversal (spec §11.2). */
|
|
200
274
|
topicMembers(topic, options_ = {}) {
|
|
201
|
-
return rows(
|
|
275
|
+
return rows(`${withAliases(options_)} SELECT * FROM (${currentSql}) WHERE ${entityMatch('subject', options_)} AND verb = 'CONTAINS' AND object IS NOT NULL${traversalFilter(options_)} ORDER BY tx`, topic).map(row => row.object);
|
|
202
276
|
},
|
|
203
277
|
/** Topics containing an entity — the inverse `CONTAINS` read (spec §11.2). */
|
|
204
278
|
topicsOf(entity, options_ = {}) {
|
|
205
|
-
return rows(
|
|
279
|
+
return rows(`${withAliases(options_)} SELECT * FROM (${currentSql}) WHERE ${entityMatch('object', options_)} AND verb = 'CONTAINS'${traversalFilter(options_)} ORDER BY tx`, entity).map(row => row.subject);
|
|
206
280
|
},
|
|
207
281
|
/**
|
|
208
282
|
* Full-text search, newest first. The query is treated as a literal
|
|
@@ -216,6 +290,21 @@ export const open = (path = ':memory:', options = {}) => {
|
|
|
216
290
|
SELECT c.* FROM cave_claim c JOIN cave_fts f ON c.id = f.claim_id
|
|
217
291
|
WHERE cave_fts MATCH ? ORDER BY c.tx DESC`, match);
|
|
218
292
|
},
|
|
293
|
+
/**
|
|
294
|
+
* Appends edges between *existing* claim rows (spec §13.2) — the
|
|
295
|
+
* derivation-lineage path (§24.3): a derived row points `BECAUSE` at
|
|
296
|
+
* the specific premise rows that fired and `VIA` at the rule's
|
|
297
|
+
* declaration row. `insertResult` covers edges within one appended
|
|
298
|
+
* batch; this covers edges into rows that are already stored. Foreign
|
|
299
|
+
* keys reject unknown ids.
|
|
300
|
+
*/
|
|
301
|
+
appendEdges(edges) {
|
|
302
|
+
transaction(() => {
|
|
303
|
+
for (const edge of edges) {
|
|
304
|
+
insertEdge.run(edge.parentId, edge.role, edge.childId);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
},
|
|
219
308
|
/** Qualifier/grouping edges of a claim row (spec §13.2). */
|
|
220
309
|
edgesOf(parentId) {
|
|
221
310
|
return db.prepare(`
|
package/dist/src/store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,KAAK,SAAS,MAAM,qBAAqB,CAAA;AAChD,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAC/B,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,MAAM,UAAU,GAAG;;;;;;CAMlB,CAAA;AAkCD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,GAAW,EAAE,CACxC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,SAAS,CAAA;AAErC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,OAAe,UAAU,EAAE,UAA+C,EAAE,EAAE,EAAE;IACnG,MAAM,EAAE,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,CAAA;IACjC,EAAE,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAA;IACnC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAEf,IAAI,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,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IAAI,IAAI,CAAC,IAAI,IAAI,KAAK,EAAE,CAAA;gBAChD,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;oBACrB,OAAO,EAAE,CAAA;gBACX,CAAC;gBACD,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;gBAChB,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;YAC7C,CAAC,CAAC,CAAA;YACF,OAAO,SAAS,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAA;QAC1C,CAAC;QAED,KAAK;YACH,EAAE,CAAC,KAAK,EAAE,CAAA;QACZ,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cavelang/store",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "CAVE persistence on node:sqlite — §13 storage model, append-only belief series, inverse-aware reads.",
|
|
6
6
|
"license": "CC0-1.0",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@cavelang/canonical": "0.
|
|
36
|
-
"@cavelang/core": "0.
|
|
35
|
+
"@cavelang/canonical": "0.13.0",
|
|
36
|
+
"@cavelang/core": "0.13.0"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsc -b",
|
package/src/index.ts
CHANGED
|
@@ -15,4 +15,4 @@
|
|
|
15
15
|
export * as Row from './row.ts'
|
|
16
16
|
export * as Schema from './schema.ts'
|
|
17
17
|
export { defaultDbPath, open } from './store.ts'
|
|
18
|
-
export type { ForwardFact, IngestResult, ReverseFact, Store, TraverseOptions } from './store.ts'
|
|
18
|
+
export type { AppendOptions, ForwardFact, IngestResult, ReverseFact, Store, TraverseOptions } from './store.ts'
|
package/src/store.ts
CHANGED
|
@@ -8,11 +8,14 @@
|
|
|
8
8
|
* - the verb registry is rebuilt from stored in-band declaration claims on
|
|
9
9
|
* open, so a reopened database keeps its inverse vocabulary;
|
|
10
10
|
* - full-text search over subjects, objects, values, comments and raw
|
|
11
|
-
* lines via FTS5
|
|
11
|
+
* lines via FTS5;
|
|
12
|
+
* - appends can stamp actor provenance (spec §9.5): pass `source` and every
|
|
13
|
+
* claim without a `src:` context gets `@src:<actor>` — applied before the
|
|
14
|
+
* claim key is computed, so different actors keep separate belief series.
|
|
12
15
|
*/
|
|
13
16
|
|
|
14
17
|
import { DatabaseSync } from 'node:sqlite'
|
|
15
|
-
import { Claim, Key, Uuidv7, Verb } from '@cavelang/core'
|
|
18
|
+
import { Claim, Context, Key, Uuidv7, Verb } from '@cavelang/core'
|
|
16
19
|
import * as Canonical from '@cavelang/canonical'
|
|
17
20
|
import * as Row from './row.ts'
|
|
18
21
|
import * as Schema from './schema.ts'
|
|
@@ -25,6 +28,27 @@ JOIN (
|
|
|
25
28
|
) latest ON c.claim_key = latest.claim_key AND c.tx = latest.max_tx
|
|
26
29
|
`
|
|
27
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Alias closure (spec §13.6): current positive `ALIAS` claims as undirected
|
|
33
|
+
* edges (`ALIAS` has no `REVERSE`, so each written direction is its own
|
|
34
|
+
* claim key — both assert the same link), walked recursively from a seed
|
|
35
|
+
* entity. Retraction unmerges: `a ALIAS b @ 0%` drops that direction's edge.
|
|
36
|
+
* The seed is the query's single positional parameter.
|
|
37
|
+
*/
|
|
38
|
+
const aliasClosureSql = `
|
|
39
|
+
WITH RECURSIVE alias_edge(a, b) AS (
|
|
40
|
+
SELECT c.subject, c.object FROM (${currentSql}) c
|
|
41
|
+
WHERE c.verb = 'ALIAS' AND c.negated = 0 AND c.conf > 0 AND c.object IS NOT NULL
|
|
42
|
+
UNION
|
|
43
|
+
SELECT c.object, c.subject FROM (${currentSql}) c
|
|
44
|
+
WHERE c.verb = 'ALIAS' AND c.negated = 0 AND c.conf > 0 AND c.object IS NOT NULL
|
|
45
|
+
), alias_closure(name) AS (
|
|
46
|
+
SELECT ?
|
|
47
|
+
UNION
|
|
48
|
+
SELECT e.b FROM alias_closure s JOIN alias_edge e ON e.a = s.name
|
|
49
|
+
)
|
|
50
|
+
`
|
|
51
|
+
|
|
28
52
|
export type IngestResult = {
|
|
29
53
|
/** ids of inserted claim rows, in document order. */
|
|
30
54
|
readonly ids: readonly string[]
|
|
@@ -32,6 +56,24 @@ export type IngestResult = {
|
|
|
32
56
|
readonly problems: readonly Canonical.Problem[]
|
|
33
57
|
}
|
|
34
58
|
|
|
59
|
+
export type AppendOptions = {
|
|
60
|
+
/**
|
|
61
|
+
* Actor provenance (spec §9.5): stamp `@src:<source>` on every appended
|
|
62
|
+
* claim that carries no `src:` context — e.g. `cli`, `agent/claude-code`,
|
|
63
|
+
* `ingest/93a01c626b3f`. Applied before the claim key is computed, so the
|
|
64
|
+
* stamp is part of claim identity; claims that already name a source keep
|
|
65
|
+
* it untouched. Omit for interchange replay (`cave import`), which must
|
|
66
|
+
* preserve claim keys as exported.
|
|
67
|
+
*/
|
|
68
|
+
readonly source?: string
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Stamps `@src:<source>` on a claim without a source context (spec §9.5). */
|
|
72
|
+
const stampSource = (claim: Claim.t, source: undefined | string): Claim.t =>
|
|
73
|
+
source === undefined || Context.hasSource(claim.contexts) ?
|
|
74
|
+
claim :
|
|
75
|
+
{ ...claim, contexts: [...claim.contexts, Context.source(source)] }
|
|
76
|
+
|
|
35
77
|
export type ForwardFact = {
|
|
36
78
|
/** Canonical (primary) verb. */
|
|
37
79
|
readonly verb: string
|
|
@@ -53,6 +95,12 @@ export type TraverseOptions = {
|
|
|
53
95
|
readonly negated?: boolean
|
|
54
96
|
/** Include rows whose current belief is `@ 0%` (default `false`). */
|
|
55
97
|
readonly retracted?: boolean
|
|
98
|
+
/**
|
|
99
|
+
* Match the entity through its alias closure — every name linked by
|
|
100
|
+
* current positive `ALIAS` claims (spec §13.6, default `false`).
|
|
101
|
+
* Union-of-rows: matching widens, returned rows keep their stored names.
|
|
102
|
+
*/
|
|
103
|
+
readonly aliases?: boolean
|
|
56
104
|
}
|
|
57
105
|
|
|
58
106
|
export type Store = ReturnType<typeof open>
|
|
@@ -123,24 +171,39 @@ export const open = (path: string = ':memory:', options: { registry?: Canonical.
|
|
|
123
171
|
}
|
|
124
172
|
rebuildRegistry()
|
|
125
173
|
|
|
174
|
+
/**
|
|
175
|
+
* Savepoint-based, so transactions nest: a caller can wrap several
|
|
176
|
+
* appends — or an append plus checks against the appended state — and
|
|
177
|
+
* roll the whole group back by throwing (spec §20.3 write gating).
|
|
178
|
+
* Rollback also restores the in-memory verb registry, so declarations
|
|
179
|
+
* from rolled-back claims don't outlive their rows.
|
|
180
|
+
*/
|
|
181
|
+
let transactionDepth = 0
|
|
126
182
|
const transaction = <T>(body: () => T): T => {
|
|
127
|
-
|
|
183
|
+
const savepoint = `cave_tx_${transactionDepth}`
|
|
184
|
+
transactionDepth += 1
|
|
185
|
+
const savedRegistry = registry
|
|
186
|
+
db.exec(`SAVEPOINT ${savepoint}`)
|
|
128
187
|
try {
|
|
129
188
|
const result = body()
|
|
130
|
-
db.exec(
|
|
189
|
+
db.exec(`RELEASE ${savepoint}`)
|
|
131
190
|
return result
|
|
132
191
|
} catch (error) {
|
|
133
|
-
db.exec(
|
|
192
|
+
db.exec(`ROLLBACK TO ${savepoint}`)
|
|
193
|
+
db.exec(`RELEASE ${savepoint}`)
|
|
194
|
+
registry = savedRegistry
|
|
134
195
|
throw error
|
|
196
|
+
} finally {
|
|
197
|
+
transactionDepth -= 1
|
|
135
198
|
}
|
|
136
199
|
}
|
|
137
200
|
|
|
138
201
|
/** Appends a canonicalization result — one row per claim, per-row tx. */
|
|
139
|
-
const insertResult = (result: Canonical.Result): IngestResult =>
|
|
202
|
+
const insertResult = (result: Canonical.Result, options_: AppendOptions = {}): IngestResult =>
|
|
140
203
|
transaction(() => {
|
|
141
204
|
const ids: string[] = []
|
|
142
205
|
for (const entry of result.claims) {
|
|
143
|
-
const claim = entry.claim
|
|
206
|
+
const claim = stampSource(entry.claim, options_.source)
|
|
144
207
|
const id = Uuidv7.next()
|
|
145
208
|
const columns = Row.toColumns(claim)
|
|
146
209
|
const rawLine = columns.rawLine === '' ? Canonical.emitClaim(claim) : columns.rawLine
|
|
@@ -189,6 +252,18 @@ export const open = (path: string = ':memory:', options: { registry?: Canonical.
|
|
|
189
252
|
(options.negated === true ? '' : ' AND negated = 0') +
|
|
190
253
|
(options.retracted === true ? '' : ' AND conf > 0')
|
|
191
254
|
|
|
255
|
+
/**
|
|
256
|
+
* Entity-matching fragment for one traversal endpoint: exact by default,
|
|
257
|
+
* `IN` the alias closure when opted in. Either form consumes exactly one
|
|
258
|
+
* positional parameter — the closure seeds from it (`aliasClosureSql`
|
|
259
|
+
* must be prepended when `aliases` is set).
|
|
260
|
+
*/
|
|
261
|
+
const entityMatch = (column: string, options: TraverseOptions): string =>
|
|
262
|
+
options.aliases === true ? `${column} IN (SELECT name FROM alias_closure)` : `${column} = ?`
|
|
263
|
+
|
|
264
|
+
const withAliases = (options: TraverseOptions): string =>
|
|
265
|
+
options.aliases === true ? aliasClosureSql : ''
|
|
266
|
+
|
|
192
267
|
return {
|
|
193
268
|
/** Raw database handle — used by `@cavelang/query`; treat as read-only. */
|
|
194
269
|
db,
|
|
@@ -196,18 +271,27 @@ export const open = (path: string = ':memory:', options: { registry?: Canonical.
|
|
|
196
271
|
/** Current verb registry (input registry + stored + ingested declarations). */
|
|
197
272
|
registry: (): Canonical.Registry.t => registry,
|
|
198
273
|
|
|
274
|
+
/**
|
|
275
|
+
* Runs `body` atomically; throwing rolls everything back, including
|
|
276
|
+
* nested appends and their registry declarations. Nestable
|
|
277
|
+
* (savepoints) — the write gate wraps ingest + check in one of these
|
|
278
|
+
* (spec §20.3).
|
|
279
|
+
*/
|
|
280
|
+
transaction,
|
|
281
|
+
|
|
199
282
|
/**
|
|
200
283
|
* Parses, canonicalizes and appends CAVE text. Lenient by default —
|
|
201
284
|
* problems are returned, valid lines still land (spec §1.6); pass
|
|
202
|
-
* `strict` to throw instead
|
|
285
|
+
* `strict` to throw instead, `source` to stamp actor provenance
|
|
286
|
+
* (spec §9.5).
|
|
203
287
|
*/
|
|
204
|
-
ingest(text: string, options_: { strict?: boolean } = {}): IngestResult {
|
|
288
|
+
ingest(text: string, options_: { strict?: boolean } & AppendOptions = {}): IngestResult {
|
|
205
289
|
const result = Canonical.canonicalizeText(text, registry)
|
|
206
290
|
if (options_.strict === true && result.problems.length > 0) {
|
|
207
291
|
const detail = result.problems.map(problem => ` line ${problem.line}: ${problem.message}`).join('\n')
|
|
208
292
|
throw new Error(`CAVE ingest failed with ${result.problems.length} problem(s):\n${detail}`)
|
|
209
293
|
}
|
|
210
|
-
return insertResult(result)
|
|
294
|
+
return insertResult(result, options_)
|
|
211
295
|
},
|
|
212
296
|
|
|
213
297
|
/** Appends an already-canonicalized result. */
|
|
@@ -233,15 +317,34 @@ export const open = (path: string = ':memory:', options: { registry?: Canonical.
|
|
|
233
317
|
return rows('SELECT * FROM cave_claim WHERE claim_key = ? ORDER BY tx', claimKey)
|
|
234
318
|
},
|
|
235
319
|
|
|
320
|
+
/**
|
|
321
|
+
* The alias closure of an entity (spec §13.6): the entity itself plus
|
|
322
|
+
* every name reachable through current positive `ALIAS` claims, read as
|
|
323
|
+
* undirected edges. Unmerge is retraction — appending `a ALIAS b @ 0%`
|
|
324
|
+
* removes that link. The queried name first, the rest sorted.
|
|
325
|
+
*/
|
|
326
|
+
aliasesOf(entity: string): string[] {
|
|
327
|
+
const names = db.prepare(`${aliasClosureSql} SELECT name FROM alias_closure WHERE name <> ? ORDER BY name`)
|
|
328
|
+
.all(entity, entity) as { name: string }[]
|
|
329
|
+
return [entity, ...names.map(row => row.name)]
|
|
330
|
+
},
|
|
331
|
+
|
|
236
332
|
/** All rows about an entity, both directions, newest first (spec §13.5). */
|
|
237
|
-
claimsAbout(entity: string): Row.t[] {
|
|
238
|
-
return
|
|
333
|
+
claimsAbout(entity: string, options_: { aliases?: boolean } = {}): Row.t[] {
|
|
334
|
+
return options_.aliases === true ?
|
|
335
|
+
rows(
|
|
336
|
+
`${aliasClosureSql} SELECT * FROM cave_claim
|
|
337
|
+
WHERE subject IN (SELECT name FROM alias_closure) OR object IN (SELECT name FROM alias_closure)
|
|
338
|
+
ORDER BY tx DESC`,
|
|
339
|
+
entity
|
|
340
|
+
) :
|
|
341
|
+
rows('SELECT * FROM cave_claim WHERE subject = ? OR object = ? ORDER BY tx DESC', entity, entity)
|
|
239
342
|
},
|
|
240
343
|
|
|
241
344
|
/** Forward reads: current relational facts with `entity` as subject (spec §13.3). */
|
|
242
345
|
forward(entity: string, options_: TraverseOptions = {}): ForwardFact[] {
|
|
243
346
|
return rows(
|
|
244
|
-
|
|
347
|
+
`${withAliases(options_)} SELECT * FROM (${currentSql}) WHERE ${entityMatch('subject', options_)} AND object IS NOT NULL${traversalFilter(options_)} ORDER BY tx`,
|
|
245
348
|
entity
|
|
246
349
|
).map(row => ({ verb: row.verb, target: row.object!, row }))
|
|
247
350
|
},
|
|
@@ -253,7 +356,7 @@ export const open = (path: string = ':memory:', options: { registry?: Canonical.
|
|
|
253
356
|
*/
|
|
254
357
|
reverse(entity: string, options_: TraverseOptions = {}): ReverseFact[] {
|
|
255
358
|
return rows(
|
|
256
|
-
|
|
359
|
+
`${withAliases(options_)} SELECT * FROM (${currentSql}) WHERE ${entityMatch('object', options_)} AND object IS NOT NULL${traversalFilter(options_)} ORDER BY tx`,
|
|
257
360
|
entity
|
|
258
361
|
).map(row => {
|
|
259
362
|
const rel = Canonical.Registry.inverseOf(registry, row.verb)
|
|
@@ -282,7 +385,7 @@ export const open = (path: string = ':memory:', options: { registry?: Canonical.
|
|
|
282
385
|
/** Members of a topic — forward `CONTAINS` traversal (spec §11.2). */
|
|
283
386
|
topicMembers(topic: string, options_: TraverseOptions = {}): string[] {
|
|
284
387
|
return rows(
|
|
285
|
-
|
|
388
|
+
`${withAliases(options_)} SELECT * FROM (${currentSql}) WHERE ${entityMatch('subject', options_)} AND verb = 'CONTAINS' AND object IS NOT NULL${traversalFilter(options_)} ORDER BY tx`,
|
|
286
389
|
topic
|
|
287
390
|
).map(row => row.object!)
|
|
288
391
|
},
|
|
@@ -290,7 +393,7 @@ export const open = (path: string = ':memory:', options: { registry?: Canonical.
|
|
|
290
393
|
/** Topics containing an entity — the inverse `CONTAINS` read (spec §11.2). */
|
|
291
394
|
topicsOf(entity: string, options_: TraverseOptions = {}): string[] {
|
|
292
395
|
return rows(
|
|
293
|
-
|
|
396
|
+
`${withAliases(options_)} SELECT * FROM (${currentSql}) WHERE ${entityMatch('object', options_)} AND verb = 'CONTAINS'${traversalFilter(options_)} ORDER BY tx`,
|
|
294
397
|
entity
|
|
295
398
|
).map(row => row.subject)
|
|
296
399
|
},
|
|
@@ -308,6 +411,22 @@ export const open = (path: string = ':memory:', options: { registry?: Canonical.
|
|
|
308
411
|
WHERE cave_fts MATCH ? ORDER BY c.tx DESC`, match)
|
|
309
412
|
},
|
|
310
413
|
|
|
414
|
+
/**
|
|
415
|
+
* Appends edges between *existing* claim rows (spec §13.2) — the
|
|
416
|
+
* derivation-lineage path (§24.3): a derived row points `BECAUSE` at
|
|
417
|
+
* the specific premise rows that fired and `VIA` at the rule's
|
|
418
|
+
* declaration row. `insertResult` covers edges within one appended
|
|
419
|
+
* batch; this covers edges into rows that are already stored. Foreign
|
|
420
|
+
* keys reject unknown ids.
|
|
421
|
+
*/
|
|
422
|
+
appendEdges(edges: readonly { parentId: string, role: Canonical.EdgeRole, childId: string }[]): void {
|
|
423
|
+
transaction(() => {
|
|
424
|
+
for (const edge of edges) {
|
|
425
|
+
insertEdge.run(edge.parentId, edge.role, edge.childId)
|
|
426
|
+
}
|
|
427
|
+
})
|
|
428
|
+
},
|
|
429
|
+
|
|
311
430
|
/** Qualifier/grouping edges of a claim row (spec §13.2). */
|
|
312
431
|
edgesOf(parentId: string): { role: string, child: Row.t }[] {
|
|
313
432
|
return (db.prepare(`
|