@yaks/sqlite 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +1596 -2
- package/_dist/archetype.d.ts +75 -0
- package/_dist/archetype.d.ts.map +1 -0
- package/_dist/branches.d.ts +23 -0
- package/_dist/branches.d.ts.map +1 -0
- package/_dist/budget.d.ts +52 -0
- package/_dist/budget.d.ts.map +1 -0
- package/_dist/bundle.d.ts +2 -0
- package/_dist/bundle.d.ts.map +1 -0
- package/_dist/cache.d.ts +24 -0
- package/_dist/cache.d.ts.map +1 -0
- package/_dist/catalog.d.ts +9 -0
- package/_dist/catalog.d.ts.map +1 -0
- package/_dist/check.d.ts +4 -0
- package/_dist/check.d.ts.map +1 -0
- package/_dist/db.d.ts +36 -0
- package/_dist/db.d.ts.map +1 -0
- package/_dist/ddl.d.ts +143 -0
- package/_dist/ddl.d.ts.map +1 -0
- package/_dist/doom.d.ts +22 -0
- package/_dist/doom.d.ts.map +1 -0
- package/_dist/follow.d.ts +74 -0
- package/_dist/follow.d.ts.map +1 -0
- package/_dist/history-shapes.d.ts +3 -0
- package/_dist/history-shapes.d.ts.map +1 -0
- package/_dist/history.d.ts +18 -0
- package/_dist/history.d.ts.map +1 -0
- package/_dist/inspect.d.ts +43 -0
- package/_dist/inspect.d.ts.map +1 -0
- package/_dist/jsonb.d.ts +17 -0
- package/_dist/jsonb.d.ts.map +1 -0
- package/_dist/layout.d.ts +7 -0
- package/_dist/layout.d.ts.map +1 -0
- package/_dist/ledger.d.ts +41 -0
- package/_dist/ledger.d.ts.map +1 -0
- package/_dist/meta.d.ts +89 -0
- package/_dist/meta.d.ts.map +1 -0
- package/_dist/migration.d.ts +41 -0
- package/_dist/migration.d.ts.map +1 -0
- package/_dist/mod.d.ts +201 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/mode.d.ts +14 -0
- package/_dist/mode.d.ts.map +1 -0
- package/_dist/overlay.d.ts +30 -0
- package/_dist/overlay.d.ts.map +1 -0
- package/_dist/owe.d.ts +180 -0
- package/_dist/owe.d.ts.map +1 -0
- package/_dist/physical.d.ts +89 -0
- package/_dist/physical.d.ts.map +1 -0
- package/_dist/point.d.ts +10 -0
- package/_dist/point.d.ts.map +1 -0
- package/_dist/raise.d.ts +22 -0
- package/_dist/raise.d.ts.map +1 -0
- package/_dist/read-db.d.ts +9 -0
- package/_dist/read-db.d.ts.map +1 -0
- package/_dist/read-store.d.ts +10 -0
- package/_dist/read-store.d.ts.map +1 -0
- package/_dist/read.d.ts +59 -0
- package/_dist/read.d.ts.map +1 -0
- package/_dist/reader.d.ts +11 -0
- package/_dist/reader.d.ts.map +1 -0
- package/_dist/rules.d.ts +19 -0
- package/_dist/rules.d.ts.map +1 -0
- package/_dist/service.d.ts +12 -0
- package/_dist/service.d.ts.map +1 -0
- package/_dist/shape.d.ts +12 -0
- package/_dist/shape.d.ts.map +1 -0
- package/_dist/statements.d.ts +4 -0
- package/_dist/statements.d.ts.map +1 -0
- package/_dist/survey.d.ts +31 -0
- package/_dist/survey.d.ts.map +1 -0
- package/_dist/tools.d.ts +15 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/trash.d.ts +18 -0
- package/_dist/trash.d.ts.map +1 -0
- package/_dist/unit.d.ts +11 -0
- package/_dist/unit.d.ts.map +1 -0
- package/_dist/vocab.d.ts +6 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/_dist/write.d.ts +169 -0
- package/_dist/write.d.ts.map +1 -0
- package/answer.js +110 -0
- package/answer.js.map +1 -0
- package/answer.ts +122 -0
- package/archetype.js +730 -0
- package/archetype.js.map +1 -0
- package/archetype.ts +790 -0
- package/binary_cases.ts +240 -0
- package/branches.js +195 -0
- package/branches.js.map +1 -0
- package/branches.ts +257 -0
- package/budget.js +89 -0
- package/budget.js.map +1 -0
- package/budget.ts +117 -0
- package/builtin.js +34 -0
- package/builtin.js.map +1 -0
- package/builtin.ts +31 -0
- package/bundle.js +21 -0
- package/bundle.js.map +1 -0
- package/bundle.ts +22 -0
- package/buried.js +95 -0
- package/buried.js.map +1 -0
- package/buried.ts +124 -0
- package/cache.js +153 -0
- package/cache.js.map +1 -0
- package/cache.ts +154 -0
- package/cache_worker.ts +16 -0
- package/catalog.js +173 -0
- package/catalog.js.map +1 -0
- package/catalog.ts +224 -0
- package/check.js +80 -0
- package/check.js.map +1 -0
- package/check.ts +92 -0
- package/checkpoint.js +98 -0
- package/checkpoint.js.map +1 -0
- package/checkpoint.ts +129 -0
- package/checkpoint_worker.ts +37 -0
- package/db.js +170 -0
- package/db.js.map +1 -0
- package/db.ts +173 -0
- package/ddl.js +1441 -0
- package/ddl.js.map +1 -0
- package/ddl.ts +1508 -0
- package/deno.json +1 -0
- package/doom.js +59 -0
- package/doom.js.map +1 -0
- package/doom.ts +75 -0
- package/driver.js +69 -0
- package/driver.js.map +1 -0
- package/driver.ts +101 -0
- package/error.js +30 -0
- package/error.js.map +1 -0
- package/error.ts +46 -0
- package/ffi/LICENSE +202 -0
- package/ffi/blob.js +99 -0
- package/ffi/blob.js.map +1 -0
- package/ffi/blob.ts +156 -0
- package/ffi/constants.js +65 -0
- package/ffi/constants.js.map +1 -0
- package/ffi/constants.ts +67 -0
- package/ffi/database.js +613 -0
- package/ffi/database.js.map +1 -0
- package/ffi/database.ts +931 -0
- package/ffi/ffi.js +535 -0
- package/ffi/ffi.js.map +1 -0
- package/ffi/ffi.ts +604 -0
- package/ffi/mod.js +15 -0
- package/ffi/mod.js.map +1 -0
- package/ffi/mod.ts +28 -0
- package/ffi/statement.js +555 -0
- package/ffi/statement.js.map +1 -0
- package/ffi/statement.ts +788 -0
- package/ffi/util.js +32 -0
- package/ffi/util.js.map +1 -0
- package/ffi/util.ts +48 -0
- package/follow.js +342 -0
- package/follow.js.map +1 -0
- package/follow.ts +401 -0
- package/history-branch.js +166 -0
- package/history-branch.js.map +1 -0
- package/history-branch.ts +140 -0
- package/history-shapes.js +254 -0
- package/history-shapes.js.map +1 -0
- package/history-shapes.ts +268 -0
- package/history.js +620 -0
- package/history.js.map +1 -0
- package/history.ts +674 -0
- package/inspect.js +120 -0
- package/inspect.js.map +1 -0
- package/inspect.ts +164 -0
- package/jsonb.js +73 -0
- package/jsonb.js.map +1 -0
- package/jsonb.ts +108 -0
- package/layout.js +22 -0
- package/layout.js.map +1 -0
- package/layout.ts +26 -0
- package/ledger.js +210 -0
- package/ledger.js.map +1 -0
- package/ledger.ts +210 -0
- package/legacy.js +4 -0
- package/legacy.js.map +1 -0
- package/legacy.ts +3 -0
- package/maintenance.js +148 -0
- package/maintenance.js.map +1 -0
- package/maintenance.ts +154 -0
- package/measure.js +133 -0
- package/measure.js.map +1 -0
- package/measure.ts +167 -0
- package/measure_worker.ts +18 -0
- package/memo.js +1250 -0
- package/memo.js.map +1 -0
- package/memo.ts +1480 -0
- package/meta.js +265 -0
- package/meta.js.map +1 -0
- package/meta.ts +321 -0
- package/migration.js +272 -0
- package/migration.js.map +1 -0
- package/migration.ts +286 -0
- package/mod.js +1103 -0
- package/mod.js.map +1 -0
- package/mod.ts +1762 -0
- package/mode.js +192 -0
- package/mode.js.map +1 -0
- package/mode.ts +207 -0
- package/native.js +544 -0
- package/native.js.map +1 -0
- package/native.ts +544 -0
- package/overlay.js +408 -0
- package/overlay.js.map +1 -0
- package/overlay.ts +485 -0
- package/owe.js +719 -0
- package/owe.js.map +1 -0
- package/owe.ts +873 -0
- package/package.json +99 -4
- package/physical.js +350 -0
- package/physical.js.map +1 -0
- package/physical.ts +434 -0
- package/plan.js +78 -0
- package/plan.js.map +1 -0
- package/plan.ts +104 -0
- package/point.js +81 -0
- package/point.js.map +1 -0
- package/point.ts +52 -0
- package/population.js +639 -0
- package/population.js.map +1 -0
- package/population.ts +630 -0
- package/purge.js +117 -0
- package/purge.js.map +1 -0
- package/purge.ts +127 -0
- package/raise.js +270 -0
- package/raise.js.map +1 -0
- package/raise.ts +316 -0
- package/read-db.js +381 -0
- package/read-db.js.map +1 -0
- package/read-db.ts +282 -0
- package/read-store.js +74 -0
- package/read-store.js.map +1 -0
- package/read-store.ts +86 -0
- package/read.js +1100 -0
- package/read.js.map +1 -0
- package/read.ts +1441 -0
- package/reader.js +141 -0
- package/reader.js.map +1 -0
- package/reader.ts +159 -0
- package/rules.js +88 -0
- package/rules.js.map +1 -0
- package/rules.ts +113 -0
- package/service.js +27 -0
- package/service.js.map +1 -0
- package/service.ts +41 -0
- package/shape.js +76 -0
- package/shape.js.map +1 -0
- package/shape.ts +108 -0
- package/sparse_presence_fixture.ts +45 -0
- package/sqlitepath.js +24 -0
- package/sqlitepath.js.map +1 -0
- package/sqlitepath.ts +29 -0
- package/statements.js +78 -0
- package/statements.js.map +1 -0
- package/statements.ts +96 -0
- package/survey.js +135 -0
- package/survey.js.map +1 -0
- package/survey.ts +196 -0
- package/tools.js +17 -0
- package/tools.js.map +1 -0
- package/tools.ts +50 -0
- package/trash.js +144 -0
- package/trash.js.map +1 -0
- package/trash.ts +187 -0
- package/unit.js +215 -0
- package/unit.js.map +1 -0
- package/unit.ts +211 -0
- package/versions.js +115 -0
- package/versions.js.map +1 -0
- package/versions.ts +110 -0
- package/vocab.js +19 -0
- package/vocab.js.map +1 -0
- package/vocab.json +27 -0
- package/vocab.ts +19 -0
- package/watch.js +33 -0
- package/watch.js.map +1 -0
- package/watch.ts +42 -0
- package/write.js +1164 -0
- package/write.js.map +1 -0
- package/write.ts +1356 -0
- package/written.js +200 -0
- package/written.js.map +1 -0
- package/written.ts +202 -0
package/ledger.js
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { TOMBSTONE } from "@yaks/graph/bundle";
|
|
2
|
+
let books = new WeakMap();
|
|
3
|
+
let followed = new WeakSet();
|
|
4
|
+
// A connection's book follows its transactions as the statements say them, the
|
|
5
|
+
// way its memory does (./memo.ts): a savepoint rolled back takes back what the
|
|
6
|
+
// ledger heard inside it, with the rows and pointers it took back, and the end
|
|
7
|
+
// of the transaction empties it.
|
|
8
|
+
let follow = (driver, book)=>{
|
|
9
|
+
if (followed.has(driver)) return;
|
|
10
|
+
followed.add(driver);
|
|
11
|
+
let back = (to)=>{
|
|
12
|
+
if (book.undo.length > to) book.revision++;
|
|
13
|
+
while(book.undo.length > to){
|
|
14
|
+
let [eid, was] = book.undo.pop();
|
|
15
|
+
if (was) book.entries.set(eid, was);
|
|
16
|
+
else book.entries.delete(eid);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
let ended = ()=>{
|
|
20
|
+
book.revision++;
|
|
21
|
+
book.entries.clear();
|
|
22
|
+
book.undo = [];
|
|
23
|
+
book.scopes = [];
|
|
24
|
+
};
|
|
25
|
+
let observe = (s)=>{
|
|
26
|
+
if (s.t == 'raw') return s.origin && observe(s.origin);
|
|
27
|
+
if (s.t == 'begin') book.scopes.push({
|
|
28
|
+
at: book.undo.length
|
|
29
|
+
});
|
|
30
|
+
else if (s.t == 'savepoint') {
|
|
31
|
+
book.scopes.push({
|
|
32
|
+
name: s.name,
|
|
33
|
+
at: book.undo.length
|
|
34
|
+
});
|
|
35
|
+
} else if (s.t == 'commit') ended();
|
|
36
|
+
else if (s.t == 'rollback') {
|
|
37
|
+
let at = s.to ? book.scopes.findLastIndex((v)=>v.name == s.to) : -1;
|
|
38
|
+
if (at < 0) return ended();
|
|
39
|
+
back(book.scopes[at].at);
|
|
40
|
+
book.scopes.splice(at + 1);
|
|
41
|
+
} else if (s.t == 'release') {
|
|
42
|
+
let at = book.scopes.findLastIndex((v)=>v.name == s.name);
|
|
43
|
+
if (at >= 0) book.scopes.splice(at);
|
|
44
|
+
if (at == 0) ended();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
let query = driver.query.bind(driver);
|
|
48
|
+
driver.query = (s)=>{
|
|
49
|
+
let rows = query(s);
|
|
50
|
+
observe(s);
|
|
51
|
+
return rows;
|
|
52
|
+
};
|
|
53
|
+
if (driver.run) {
|
|
54
|
+
let run = driver.run.bind(driver);
|
|
55
|
+
driver.run = (s)=>{
|
|
56
|
+
let n = run(s);
|
|
57
|
+
observe(s);
|
|
58
|
+
return n;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
// A driver's own transaction is synchronous, and one nested in another
|
|
62
|
+
// rolls back to where it began.
|
|
63
|
+
if (driver.tx) {
|
|
64
|
+
let tx = driver.tx.bind(driver);
|
|
65
|
+
driver.tx = (body)=>{
|
|
66
|
+
let at = book.scopes.length;
|
|
67
|
+
book.scopes.push({
|
|
68
|
+
at: book.undo.length
|
|
69
|
+
});
|
|
70
|
+
let committed = false;
|
|
71
|
+
try {
|
|
72
|
+
let out = tx(body);
|
|
73
|
+
committed = true;
|
|
74
|
+
return out;
|
|
75
|
+
} finally{
|
|
76
|
+
if (!committed) back(book.scopes[at]?.at ?? 0);
|
|
77
|
+
book.scopes.splice(at);
|
|
78
|
+
if (!at) ended();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* A connection's account of what its open transaction did to each entity's
|
|
85
|
+
* archetype since that entity's pointer was written, shared by every store
|
|
86
|
+
* over the connection (./mod.ts `storage`). `moved` hears a row come or go
|
|
87
|
+
* (./write.ts `patch`), `born` a spine minted, `removed` an entity removed,
|
|
88
|
+
* `pointed` a pointer written.
|
|
89
|
+
*
|
|
90
|
+
* `held` is the tables an entity holds now, given the ones its stored pointer
|
|
91
|
+
* names: the pointer's, or none for a birth (minted in the class its shape
|
|
92
|
+
* last finished in, which it may not hold yet), or its tombstone for a
|
|
93
|
+
* removal, with each row that came or went since. So a read or a removal
|
|
94
|
+
* inside the transaction knows what an entity holds without reading a table.
|
|
95
|
+
* It is undefined for an entity with no pointer that the transaction neither
|
|
96
|
+
* minted nor removed: nothing says what that one holds.
|
|
97
|
+
*
|
|
98
|
+
* `owed` is every entity whose rows stand other than its pointer says, or
|
|
99
|
+
* that was born, with no pointer written since: the ones a unit classifies as
|
|
100
|
+
* it closes. `buried` is every entity removed with no pointer written since:
|
|
101
|
+
* each holds its tombstone and nothing else, and a read passes it by as dead
|
|
102
|
+
* whatever its pointer says. A batch that adds a component and drops it again
|
|
103
|
+
* owes nothing, and neither does anything @yaks/graph wrote, since its
|
|
104
|
+
* tracker points every entity it moved after the rows are written. `wrote`
|
|
105
|
+
* is whether the transaction heard anything of an entity since its pointer.
|
|
106
|
+
*
|
|
107
|
+
* The ledger follows the connection's savepoints: what a unit wrote and then
|
|
108
|
+
* rolled back is taken back here too, so a unit opened inside another, kept
|
|
109
|
+
* or not, leaves the account exact.
|
|
110
|
+
*/ export let ledger = (driver)=>{
|
|
111
|
+
let at = driver.connection ?? driver;
|
|
112
|
+
let book = books.get(at);
|
|
113
|
+
if (!book) {
|
|
114
|
+
books.set(at, book = {
|
|
115
|
+
revision: 0,
|
|
116
|
+
entries: new Map(),
|
|
117
|
+
undo: [],
|
|
118
|
+
scopes: []
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
follow(driver, book);
|
|
122
|
+
let { entries } = book;
|
|
123
|
+
// An entry about to change, with how to take the change back.
|
|
124
|
+
let change = (eid, fresh)=>{
|
|
125
|
+
book.revision++;
|
|
126
|
+
let was = entries.get(eid);
|
|
127
|
+
book.undo.push([
|
|
128
|
+
eid,
|
|
129
|
+
was && {
|
|
130
|
+
...was,
|
|
131
|
+
rows: new Map(was.rows)
|
|
132
|
+
}
|
|
133
|
+
]);
|
|
134
|
+
let e = fresh ?? was ?? {
|
|
135
|
+
rows: new Map(),
|
|
136
|
+
born: false,
|
|
137
|
+
dead: false
|
|
138
|
+
};
|
|
139
|
+
entries.set(eid, e);
|
|
140
|
+
return e;
|
|
141
|
+
};
|
|
142
|
+
let moving = (e)=>e.born || [
|
|
143
|
+
...e.rows.values()
|
|
144
|
+
].some(([was, now])=>was != now);
|
|
145
|
+
return {
|
|
146
|
+
revision: ()=>book.revision,
|
|
147
|
+
moved: (eid, table, held)=>{
|
|
148
|
+
// A row moving again (a revival, a patch after it) leaves the dead
|
|
149
|
+
// holding more than their tombstone.
|
|
150
|
+
let e = change(eid);
|
|
151
|
+
e.dead = false;
|
|
152
|
+
e.rows.set(table, [
|
|
153
|
+
e.rows.get(table)?.[0] ?? !held,
|
|
154
|
+
held
|
|
155
|
+
]);
|
|
156
|
+
},
|
|
157
|
+
born: (eid)=>void change(eid, {
|
|
158
|
+
base: [],
|
|
159
|
+
rows: new Map(),
|
|
160
|
+
born: true,
|
|
161
|
+
dead: false
|
|
162
|
+
}),
|
|
163
|
+
removed: (eid)=>void change(eid, {
|
|
164
|
+
base: [
|
|
165
|
+
TOMBSTONE
|
|
166
|
+
],
|
|
167
|
+
rows: new Map(),
|
|
168
|
+
born: false,
|
|
169
|
+
dead: true
|
|
170
|
+
}),
|
|
171
|
+
// A pointer says everything written before it.
|
|
172
|
+
pointed: (eid)=>{
|
|
173
|
+
if (!entries.has(eid)) return;
|
|
174
|
+
book.revision++;
|
|
175
|
+
book.undo.push([
|
|
176
|
+
eid,
|
|
177
|
+
entries.get(eid)
|
|
178
|
+
]);
|
|
179
|
+
entries.delete(eid);
|
|
180
|
+
},
|
|
181
|
+
owed: ()=>[
|
|
182
|
+
...entries
|
|
183
|
+
].flatMap(([eid, e])=>!e.dead && moving(e) ? [
|
|
184
|
+
eid
|
|
185
|
+
] : []),
|
|
186
|
+
buried: ()=>[
|
|
187
|
+
...entries
|
|
188
|
+
].flatMap(([eid, e])=>e.dead ? [
|
|
189
|
+
eid
|
|
190
|
+
] : []),
|
|
191
|
+
wrote: (eid)=>entries.has(eid),
|
|
192
|
+
held: (eid, pointed)=>{
|
|
193
|
+
let e = entries.get(eid);
|
|
194
|
+
let base = e?.base ?? pointed;
|
|
195
|
+
if (!base) return undefined;
|
|
196
|
+
if (!e) return [
|
|
197
|
+
...base
|
|
198
|
+
];
|
|
199
|
+
let held = new Set(base);
|
|
200
|
+
for (let [table, [, now]] of e.rows){
|
|
201
|
+
if (now) held.add(table);
|
|
202
|
+
else held.delete(table);
|
|
203
|
+
}
|
|
204
|
+
return [
|
|
205
|
+
...held
|
|
206
|
+
];
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
//# sourceMappingURL=ledger.js.map
|
package/ledger.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.js","sources":["./ledger.ts"],"names":[],"mappings":"AACA,SAAS,SAAS,kCAAuC;AAmCzD,IAAI,QAAQ,IAAI;AAChB,IAAI,WAAW,IAAI;AAEnB,+EAA+E;AAC/E,+EAA+E;AAC/E,+EAA+E;AAC/E,iCAAiC;AACjC,IAAI,SAAS,CAAC,QAAgB;EAC5B,IAAI,SAAS,GAAG,CAAC,SAAS;EAC1B,SAAS,GAAG,CAAC;EACb,IAAI,OAAO,CAAC;IACV,IAAI,KAAK,IAAI,CAAC,MAAM,GAAG,IAAI,KAAK,QAAQ;IACxC,MAAO,KAAK,IAAI,CAAC,MAAM,GAAG,GAAI;MAC5B,IAAI,CAAC,KAAK,IAAI,GAAG,KAAK,IAAI,CAAC,GAAG;MAC9B,IAAI,KAAK,KAAK,OAAO,CAAC,GAAG,CAAC,KAAK;WAC1B,KAAK,OAAO,CAAC,MAAM,CAAC;IAC3B;EACF;EACA,IAAI,QAAQ;IACV,KAAK,QAAQ;IACb,KAAK,OAAO,CAAC,KAAK;IAClB,KAAK,IAAI,GAAG,EAAE;IACd,KAAK,MAAM,GAAG,EAAE;EAClB;EACA,IAAI,UAAU,CAAC;IACb,IAAI,EAAE,CAAC,IAAI,OAAO,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM;IACrD,IAAI,EAAE,CAAC,IAAI,SAAS,KAAK,MAAM,CAAC,IAAI,CAAC;MAAE,IAAI,KAAK,IAAI,CAAC,MAAM;IAAC;SACvD,IAAI,EAAE,CAAC,IAAI,aAAa;MAC3B,KAAK,MAAM,CAAC,IAAI,CAAC;QAAE,MAAM,EAAE,IAAI;QAAE,IAAI,KAAK,IAAI,CAAC,MAAM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ledger of archetype moves ({@link ledger}). */
|
|
5
|
+
export type Ledger = {
|
|
6
|
+
/** A monotonic token for changes to this transaction's pending shapes. */
|
|
7
|
+
revision: () => number
|
|
8
|
+
moved: (eid: string, table: string, held: boolean) => void
|
|
9
|
+
born: (eid: string) => void
|
|
10
|
+
removed: (eid: string) => void
|
|
11
|
+
pointed: (eid: string) => void
|
|
12
|
+
owed: () => string[]
|
|
13
|
+
buried: () => string[]
|
|
14
|
+
wrote: (eid: string) => boolean
|
|
15
|
+
held: (eid: string, pointed: readonly string[] | null) => string[] | undefined
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// What the open transaction wrote to one entity since its pointer was: the
|
|
19
|
+
// tables it holds whatever its pointer says (`base`: none for a birth, its
|
|
20
|
+
// tombstone for a removal), each table a row came to or went from since, as
|
|
21
|
+
// whether it held one before and holds one now, and whether it is dead.
|
|
22
|
+
type Entry = {
|
|
23
|
+
base?: readonly string[]
|
|
24
|
+
rows: Map<string, [boolean, boolean]>
|
|
25
|
+
born: boolean
|
|
26
|
+
dead: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// One connection's entries, and how to take back each change made to them
|
|
30
|
+
// since a savepoint, newest last.
|
|
31
|
+
type Book = {
|
|
32
|
+
revision: number
|
|
33
|
+
entries: Map<string, Entry>
|
|
34
|
+
undo: [string, Entry | undefined][]
|
|
35
|
+
scopes: { name?: string; at: number }[]
|
|
36
|
+
}
|
|
37
|
+
let books = new WeakMap<object, Book>()
|
|
38
|
+
let followed = new WeakSet<Driver>()
|
|
39
|
+
|
|
40
|
+
// A connection's book follows its transactions as the statements say them, the
|
|
41
|
+
// way its memory does (./memo.ts): a savepoint rolled back takes back what the
|
|
42
|
+
// ledger heard inside it, with the rows and pointers it took back, and the end
|
|
43
|
+
// of the transaction empties it.
|
|
44
|
+
let follow = (driver: Driver, book: Book) => {
|
|
45
|
+
if (followed.has(driver)) return
|
|
46
|
+
followed.add(driver)
|
|
47
|
+
let back = (to: number) => {
|
|
48
|
+
if (book.undo.length > to) book.revision++
|
|
49
|
+
while (book.undo.length > to) {
|
|
50
|
+
let [eid, was] = book.undo.pop()!
|
|
51
|
+
if (was) book.entries.set(eid, was)
|
|
52
|
+
else book.entries.delete(eid)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
let ended = () => {
|
|
56
|
+
book.revision++
|
|
57
|
+
book.entries.clear()
|
|
58
|
+
book.undo = []
|
|
59
|
+
book.scopes = []
|
|
60
|
+
}
|
|
61
|
+
let observe = (s: Stmt): void => {
|
|
62
|
+
if (s.t == 'raw') return s.origin && observe(s.origin)
|
|
63
|
+
if (s.t == 'begin') book.scopes.push({ at: book.undo.length })
|
|
64
|
+
else if (s.t == 'savepoint') {
|
|
65
|
+
book.scopes.push({ name: s.name, at: book.undo.length })
|
|
66
|
+
} else if (s.t == 'commit') ended()
|
|
67
|
+
else if (s.t == 'rollback') {
|
|
68
|
+
let at = s.to ? book.scopes.findLastIndex((v) => v.name == s.to) : -1
|
|
69
|
+
if (at < 0) return ended()
|
|
70
|
+
back(book.scopes[at].at)
|
|
71
|
+
book.scopes.splice(at + 1)
|
|
72
|
+
} else if (s.t == 'release') {
|
|
73
|
+
let at = book.scopes.findLastIndex((v) => v.name == s.name)
|
|
74
|
+
if (at >= 0) book.scopes.splice(at)
|
|
75
|
+
if (at == 0) ended()
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
let query = driver.query.bind(driver)
|
|
79
|
+
driver.query = (s) => {
|
|
80
|
+
let rows = query(s)
|
|
81
|
+
observe(s)
|
|
82
|
+
return rows
|
|
83
|
+
}
|
|
84
|
+
if (driver.run) {
|
|
85
|
+
let run = driver.run.bind(driver)
|
|
86
|
+
driver.run = (s) => {
|
|
87
|
+
let n = run(s)
|
|
88
|
+
observe(s)
|
|
89
|
+
return n
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// A driver's own transaction is synchronous, and one nested in another
|
|
93
|
+
// rolls back to where it began.
|
|
94
|
+
if (driver.tx) {
|
|
95
|
+
let tx = driver.tx.bind(driver)
|
|
96
|
+
driver.tx = (body) => {
|
|
97
|
+
let at = book.scopes.length
|
|
98
|
+
book.scopes.push({ at: book.undo.length })
|
|
99
|
+
let committed = false
|
|
100
|
+
try {
|
|
101
|
+
let out = tx(body)
|
|
102
|
+
committed = true
|
|
103
|
+
return out
|
|
104
|
+
} finally {
|
|
105
|
+
if (!committed) back(book.scopes[at]?.at ?? 0)
|
|
106
|
+
book.scopes.splice(at)
|
|
107
|
+
if (!at) ended()
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* A connection's account of what its open transaction did to each entity's
|
|
115
|
+
* archetype since that entity's pointer was written, shared by every store
|
|
116
|
+
* over the connection (./mod.ts `storage`). `moved` hears a row come or go
|
|
117
|
+
* (./write.ts `patch`), `born` a spine minted, `removed` an entity removed,
|
|
118
|
+
* `pointed` a pointer written.
|
|
119
|
+
*
|
|
120
|
+
* `held` is the tables an entity holds now, given the ones its stored pointer
|
|
121
|
+
* names: the pointer's, or none for a birth (minted in the class its shape
|
|
122
|
+
* last finished in, which it may not hold yet), or its tombstone for a
|
|
123
|
+
* removal, with each row that came or went since. So a read or a removal
|
|
124
|
+
* inside the transaction knows what an entity holds without reading a table.
|
|
125
|
+
* It is undefined for an entity with no pointer that the transaction neither
|
|
126
|
+
* minted nor removed: nothing says what that one holds.
|
|
127
|
+
*
|
|
128
|
+
* `owed` is every entity whose rows stand other than its pointer says, or
|
|
129
|
+
* that was born, with no pointer written since: the ones a unit classifies as
|
|
130
|
+
* it closes. `buried` is every entity removed with no pointer written since:
|
|
131
|
+
* each holds its tombstone and nothing else, and a read passes it by as dead
|
|
132
|
+
* whatever its pointer says. A batch that adds a component and drops it again
|
|
133
|
+
* owes nothing, and neither does anything @yaks/graph wrote, since its
|
|
134
|
+
* tracker points every entity it moved after the rows are written. `wrote`
|
|
135
|
+
* is whether the transaction heard anything of an entity since its pointer.
|
|
136
|
+
*
|
|
137
|
+
* The ledger follows the connection's savepoints: what a unit wrote and then
|
|
138
|
+
* rolled back is taken back here too, so a unit opened inside another, kept
|
|
139
|
+
* or not, leaves the account exact.
|
|
140
|
+
*/
|
|
141
|
+
export let ledger = (driver: Driver): Ledger => {
|
|
142
|
+
let at = driver.connection ?? driver
|
|
143
|
+
let book = books.get(at)
|
|
144
|
+
if (!book) {
|
|
145
|
+
books.set(
|
|
146
|
+
at,
|
|
147
|
+
book = {
|
|
148
|
+
revision: 0,
|
|
149
|
+
entries: new Map(),
|
|
150
|
+
undo: [],
|
|
151
|
+
scopes: [],
|
|
152
|
+
},
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
follow(driver, book)
|
|
156
|
+
let { entries } = book
|
|
157
|
+
// An entry about to change, with how to take the change back.
|
|
158
|
+
let change = (eid: string, fresh?: Entry): Entry => {
|
|
159
|
+
book.revision++
|
|
160
|
+
let was = entries.get(eid)
|
|
161
|
+
book.undo.push([eid, was && { ...was, rows: new Map(was.rows) }])
|
|
162
|
+
let e = fresh ?? was ?? { rows: new Map(), born: false, dead: false }
|
|
163
|
+
entries.set(eid, e)
|
|
164
|
+
return e
|
|
165
|
+
}
|
|
166
|
+
let moving = (e: Entry) =>
|
|
167
|
+
e.born || [...e.rows.values()].some(([was, now]) => was != now)
|
|
168
|
+
return {
|
|
169
|
+
revision: () => book.revision,
|
|
170
|
+
moved: (eid, table, held) => {
|
|
171
|
+
// A row moving again (a revival, a patch after it) leaves the dead
|
|
172
|
+
// holding more than their tombstone.
|
|
173
|
+
let e = change(eid)
|
|
174
|
+
e.dead = false
|
|
175
|
+
e.rows.set(table, [e.rows.get(table)?.[0] ?? !held, held])
|
|
176
|
+
},
|
|
177
|
+
born: (eid) =>
|
|
178
|
+
void change(eid, { base: [], rows: new Map(), born: true, dead: false }),
|
|
179
|
+
removed: (eid) =>
|
|
180
|
+
void change(eid, {
|
|
181
|
+
base: [TOMBSTONE],
|
|
182
|
+
rows: new Map(),
|
|
183
|
+
born: false,
|
|
184
|
+
dead: true,
|
|
185
|
+
}),
|
|
186
|
+
// A pointer says everything written before it.
|
|
187
|
+
pointed: (eid) => {
|
|
188
|
+
if (!entries.has(eid)) return
|
|
189
|
+
book.revision++
|
|
190
|
+
book.undo.push([eid, entries.get(eid)])
|
|
191
|
+
entries.delete(eid)
|
|
192
|
+
},
|
|
193
|
+
owed: () =>
|
|
194
|
+
[...entries].flatMap(([eid, e]) => !e.dead && moving(e) ? [eid] : []),
|
|
195
|
+
buried: () => [...entries].flatMap(([eid, e]) => e.dead ? [eid] : []),
|
|
196
|
+
wrote: (eid) => entries.has(eid),
|
|
197
|
+
held: (eid, pointed) => {
|
|
198
|
+
let e = entries.get(eid)
|
|
199
|
+
let base = e?.base ?? pointed
|
|
200
|
+
if (!base) return undefined
|
|
201
|
+
if (!e) return [...base]
|
|
202
|
+
let held = new Set(base)
|
|
203
|
+
for (let [table, [, now]] of e.rows) {
|
|
204
|
+
if (now) held.add(table)
|
|
205
|
+
else held.delete(table)
|
|
206
|
+
}
|
|
207
|
+
return [...held]
|
|
208
|
+
},
|
|
209
|
+
}
|
|
210
|
+
}
|
package/legacy.js
ADDED
package/legacy.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy.js","sources":["./legacy.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,qEAAqE;AACrE,SAAS,QAAQ,EAAE,SAAS,uBAAsB"}
|
package/legacy.ts
ADDED
package/maintenance.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// Row-dependent installation is a sequence of units, separate from opening.
|
|
2
|
+
// The persisted cursor makes a reset resume primary-key pages, even before the
|
|
3
|
+
// pointer index exists. Ordinary reads use the component tables until it ends.
|
|
4
|
+
// Once that index stands, a pass reads only the owners it names as strays
|
|
5
|
+
// (./archetype.ts `strays`), and a cursor already part way through the spine
|
|
6
|
+
// stops there: a schema change leaves a classified spine alone. A store whose
|
|
7
|
+
// history began paced takes its live rows as their first versions here, a
|
|
8
|
+
// page of entities a unit (./history.ts `seedPage`).
|
|
9
|
+
import { as, col, fn, gt, lit, oneOf, select, table, val } from "@yaks/sql";
|
|
10
|
+
import { backfill, classify, pointable, presence, strays } from "./archetype.js";
|
|
11
|
+
import { beside, SEEDING, seedPage } from "./history.js";
|
|
12
|
+
import { needless } from "./ddl.js";
|
|
13
|
+
import { meta } from "./meta.js";
|
|
14
|
+
import { componentTables, objects } from "./physical.js";
|
|
15
|
+
import { OWED, owed } from "./owe.js";
|
|
16
|
+
import { unit } from "./unit.js";
|
|
17
|
+
export let CLASSIFYING = 'archetype:pending';
|
|
18
|
+
let PAGE = 512;
|
|
19
|
+
// How many rows a table holds at most: its last rowid, one row read. A
|
|
20
|
+
// Durable Object bills `count(*)` every row it counts, so a look at an owed
|
|
21
|
+
// index on a 940,000-row spine read the spine whole, twice an alarm, and
|
|
22
|
+
// 221 million rows in 13 minutes (2026-11-13).
|
|
23
|
+
let most = (driver, name)=>Number(driver.query(select({
|
|
24
|
+
cols: [
|
|
25
|
+
as(fn('max', col('rowid')), 'n')
|
|
26
|
+
],
|
|
27
|
+
from: table(name)
|
|
28
|
+
}))[0]?.n ?? 0);
|
|
29
|
+
export let maintenance = (driver, vocab)=>{
|
|
30
|
+
let marks = meta(driver);
|
|
31
|
+
let classifying = ()=>marks.get(CLASSIFYING) != null;
|
|
32
|
+
// Asked before every read the store plans, and answered from what the
|
|
33
|
+
// connection holds of `server_meta` (./meta.ts), which a write to another
|
|
34
|
+
// key there leaves standing.
|
|
35
|
+
let pending = ()=>classifying() || owed(driver).some((w)=>w.kind == 'index' && w.stmt.on == 'entity' && w.stmt.cols.some((c)=>c.t == 'col' && c.name == 'archetype'));
|
|
36
|
+
let page = (after = 0, limit = PAGE)=>driver.query(select({
|
|
37
|
+
cols: [
|
|
38
|
+
col('id'),
|
|
39
|
+
col('eid'),
|
|
40
|
+
col('archetype')
|
|
41
|
+
],
|
|
42
|
+
from: table('entity'),
|
|
43
|
+
where: gt(col('id'), val(after)),
|
|
44
|
+
order: [
|
|
45
|
+
col('id')
|
|
46
|
+
],
|
|
47
|
+
limit: lit(limit)
|
|
48
|
+
}));
|
|
49
|
+
// A pass is owed by a spine the pointer index does not cover yet, or by the
|
|
50
|
+
// strays it names: every install whose schema moved prepares, and one that
|
|
51
|
+
// only added a table leaves a classified spine unread.
|
|
52
|
+
let prepare = ()=>{
|
|
53
|
+
if (classifying() || !page(0, 1).length) return;
|
|
54
|
+
if (!pointable(driver) || strays(driver, 1).length) {
|
|
55
|
+
marks.set(CLASSIFYING, 'metadata');
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
let held = (ids)=>presence((s)=>driver.query(s), componentTables(driver), new Map(ids.map((id)=>[
|
|
59
|
+
id,
|
|
60
|
+
[]
|
|
61
|
+
])), (c)=>({
|
|
62
|
+
where: oneOf(c, ids)
|
|
63
|
+
}));
|
|
64
|
+
let work = (admit, seedRows = PAGE)=>{
|
|
65
|
+
if (classifying()) {
|
|
66
|
+
let at = marks.get(CLASSIFYING);
|
|
67
|
+
let indexes = objects(driver, {
|
|
68
|
+
type: 'index',
|
|
69
|
+
tbl_name: 'entity'
|
|
70
|
+
}).length;
|
|
71
|
+
if (at == 'metadata') {
|
|
72
|
+
let n = most(driver, 'archetype');
|
|
73
|
+
if (!admit((n + 2) * (indexes * 3 + 8))) return false;
|
|
74
|
+
unit(driver, ()=>{
|
|
75
|
+
backfill(driver, false);
|
|
76
|
+
marks.set(CLASSIFYING, '0');
|
|
77
|
+
});
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
// Under the pointer index a page is the strays it names, which
|
|
81
|
+
// classifying moves out; without it, the primary-key page past the
|
|
82
|
+
// cursor.
|
|
83
|
+
let pointed = pointable(driver);
|
|
84
|
+
let rows = pointed ? strays(driver, PAGE) : page(Number(at));
|
|
85
|
+
let tables = new Set(componentTables(driver));
|
|
86
|
+
// Worst case: every owner has a distinct set, requiring a descriptor,
|
|
87
|
+
// its spine and pointer, as well as the owner's indexed pointer write.
|
|
88
|
+
if (!admit((rows.length + 2) * (indexes * 3 + 8))) return false;
|
|
89
|
+
unit(driver, ()=>{
|
|
90
|
+
classify(driver, rows.map((r)=>String(r.eid)), (_, pointed)=>pointed?.every((t)=>tables.has(t)) ? [
|
|
91
|
+
...pointed
|
|
92
|
+
] : undefined);
|
|
93
|
+
if (rows.length < PAGE) marks.del(CLASSIFYING);
|
|
94
|
+
else if (!pointed) marks.set(CLASSIFYING, String(rows.at(-1).id));
|
|
95
|
+
});
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
let owing = marks.get(SEEDING);
|
|
99
|
+
if (owing) {
|
|
100
|
+
let { comps, after } = JSON.parse(owing);
|
|
101
|
+
// Each row's version and its membership, with every index of both: a
|
|
102
|
+
// unit takes a page of rows, across as many components as it reaches.
|
|
103
|
+
let indexes = objects(driver, {
|
|
104
|
+
type: 'index',
|
|
105
|
+
tbl_name: beside(comps[0])
|
|
106
|
+
}).length;
|
|
107
|
+
if (!admit((seedRows + 2) * (indexes + 3))) return false;
|
|
108
|
+
unit(driver, ()=>{
|
|
109
|
+
let left = seedRows;
|
|
110
|
+
while(left > 0 && comps.length){
|
|
111
|
+
let { taken, last } = seedPage(driver, vocab, comps[0], after, left);
|
|
112
|
+
left -= taken;
|
|
113
|
+
if (last == null) [comps, after] = [
|
|
114
|
+
comps.slice(1),
|
|
115
|
+
0
|
|
116
|
+
];
|
|
117
|
+
else after = last;
|
|
118
|
+
}
|
|
119
|
+
if (comps.length) marks.set(SEEDING, JSON.stringify({
|
|
120
|
+
comps,
|
|
121
|
+
after
|
|
122
|
+
}));
|
|
123
|
+
else marks.del(SEEDING);
|
|
124
|
+
});
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
// An index owed before the install stopped building it (./ddl.ts
|
|
128
|
+
// `needless`) is forgotten unbuilt: built, it writes a row per entity.
|
|
129
|
+
for (let w of owed(driver)){
|
|
130
|
+
if (w.kind != 'index') continue;
|
|
131
|
+
let needed = !needless(driver, w.stmt);
|
|
132
|
+
if (needed && !admit(most(driver, w.stmt.on) + 4)) continue;
|
|
133
|
+
unit(driver, ()=>{
|
|
134
|
+
if (needed) driver.query(w.stmt);
|
|
135
|
+
marks.del(`${OWED}${w.kind}:${w.name}`);
|
|
136
|
+
});
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
return false;
|
|
140
|
+
};
|
|
141
|
+
return {
|
|
142
|
+
pending,
|
|
143
|
+
prepare,
|
|
144
|
+
held,
|
|
145
|
+
work
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
//# sourceMappingURL=maintenance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"maintenance.js","sources":["./maintenance.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,+EAA+E;AAC/E,+EAA+E;AAC/E,0EAA0E;AAC1E,6EAA6E;AAC7E,8EAA8E;AAC9E,0EAA0E;AAC1E,qDAAqD;AACrD,SACE,EAAE,EACF,GAAG,EAEH,EAAE,EACF,EAAE,EACF,GAAG,EACH,KAAK,EACL,MAAM,EACN,KAAK,EACL,GAAG,yBACwB;AAE7B,SAAS,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,yBAAwB;AAChF,SAAS,MAAM,EAAE,OAAO,EAAgB,QAAQ,uBAAsB;AACtE,SAAS,QAAQ,mBAAkB;AACnC,SAAS,IAAI,oBAAmB;AAChC,SAAS,eAAe,EAAE,OAAO,wBAAuB;AACxD,SAAS,IAAI,EAAE,IAAI,mBAAkB;AACrC,SAAS,IAAI,oBAAmB;AAEhC,OAAO,IAAI,cAAc,oBAAmB;AAC5C,IAAI,OAAO;AAEX,uEAAuE;AACvE,4EAA4E;AAC5E,yEAAyE;AACzE,+CAA+C;AAC/C,IAAI,OAAO,CAAC,QAAgB,OAC1B,OACE,OA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