@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/history.js
ADDED
|
@@ -0,0 +1,620 @@
|
|
|
1
|
+
// Versions: a store with history keeps every version of every component row
|
|
2
|
+
// (D-130964). The live tables stay exactly the tables a store without history
|
|
3
|
+
// has. Beside each one, `<comp>$versions` holds its versions, each the span of
|
|
4
|
+
// transactions it was true for, `[$from, $to)`: the open one, `$to = 0`, is a
|
|
5
|
+
// copy of the live row, and a write closes it and opens the next. Current
|
|
6
|
+
// reads, their plans and every trigger on a live table (text and vector
|
|
7
|
+
// indexes, archetypes, numbering) are untouched; a write pays for its versions,
|
|
8
|
+
// and a read as of a transaction or on a branch reads them alone.
|
|
9
|
+
//
|
|
10
|
+
// A transaction id is an integer local to the store, in commit order. The
|
|
11
|
+
// store does not mint it: the history plugin hands the store a statement that
|
|
12
|
+
// takes one (`History.clock`, @yaks/journal's row of `journal_tx`), and the
|
|
13
|
+
// first versioned write of a unit runs it, so a unit that writes only exempt
|
|
14
|
+
// components takes none. A version kept from before the store kept history has
|
|
15
|
+
// no `$from`, and stands for every transaction before its `$to`.
|
|
16
|
+
//
|
|
17
|
+
// A component its vocabulary declares `journal: false` keeps no versions on
|
|
18
|
+
// main. `tombstone` keeps them always: presence and death are what an as-of
|
|
19
|
+
// read is about first.
|
|
20
|
+
//
|
|
21
|
+
// A branch lives entirely beside: its rows are `<comp>$versions` rows of that
|
|
22
|
+
// branch, for every component table, exempt ones included, since a branch's
|
|
23
|
+
// writes must never reach main. The first write to an entity's component on a
|
|
24
|
+
// branch copies what the branch sees of it, then changes the copy. A removal on
|
|
25
|
+
// a branch closes its row, which goes on hiding main's.
|
|
26
|
+
//
|
|
27
|
+
// Reading the past is a driver of its own (./mode.ts): each statement it runs
|
|
28
|
+
// names, in front of each table it reads, a common table expression of the
|
|
29
|
+
// same name holding the mode's rows, so every statement this package builds
|
|
30
|
+
// reads the mode without knowing it. Each is one select over one table, which
|
|
31
|
+
// SQLite folds into any read, a join's right side included; a compound one it
|
|
32
|
+
// would materialize whole wherever a read left-joins it.
|
|
33
|
+
import { among, and, as, col, eq, exists, field, fn, from, isNull, lit, ne, not, op, or, select, stored as storageName, table, unionAll, val } from "@yaks/sql";
|
|
34
|
+
import { TOMBSTONE } from "@yaks/graph/bundle";
|
|
35
|
+
import { tables } from "./layout.js";
|
|
36
|
+
import { indexed } from "./ddl.js";
|
|
37
|
+
import { branched } from "./history-branch.js";
|
|
38
|
+
import { BESIDE, beside, BRANCH, FROM, shaped, shapeDdl, SHAPES, shapeSeeds, TO } from "./history-shapes.js";
|
|
39
|
+
export { BESIDE, beside, BRANCH, FROM, TO } from "./history-shapes.js";
|
|
40
|
+
/** The table of branches. */ export let BRANCHES = '$branch';
|
|
41
|
+
/** Branches held in trash, with every version still in place. */ export let BRANCH_TRASH = '$branch$trash';
|
|
42
|
+
/** Whether main keeps a component's versions: every component table but those
|
|
43
|
+
* declared `journal: false`. */ export let keeps = (vocab, comp)=>comp == TOMBSTONE || vocab.comp(comp)?.journal !== false;
|
|
44
|
+
// What a component stores, in the order its table carries it: the tombstone's
|
|
45
|
+
// is the spine's (./ddl.ts SPINE), every other one its vocabulary's.
|
|
46
|
+
export let stored = (vocab, comp)=>comp == TOMBSTONE ? [
|
|
47
|
+
'deleted_at'
|
|
48
|
+
] : vocab.props(comp).map((p)=>vocab.prop(comp, p)).filter((c)=>!c.computed).map((c)=>field(c.prop));
|
|
49
|
+
let affinity = (vocab, comp, name)=>comp == TOMBSTONE ? 'text' : vocab.props(comp).map((p)=>vocab.prop(comp, p)).find((c)=>field(c.prop) == name)?.affinity || undefined;
|
|
50
|
+
// Every table a write may name that history covers: each component's, and the
|
|
51
|
+
// tombstones, which a vocabulary need not declare.
|
|
52
|
+
let held = new WeakMap();
|
|
53
|
+
export let covered = (vocab)=>{
|
|
54
|
+
let found = held.get(vocab);
|
|
55
|
+
if (!found) {
|
|
56
|
+
held.set(vocab, found = new Set([
|
|
57
|
+
...tables(vocab),
|
|
58
|
+
TOMBSTONE
|
|
59
|
+
]));
|
|
60
|
+
found.delete('entity');
|
|
61
|
+
}
|
|
62
|
+
return found;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* The tables beside each component table: copies of its columns, typed as the
|
|
66
|
+
* live table declares them (`typed`, else the vocabulary), so a version holds
|
|
67
|
+
* a value exactly as its live row did, and the three store-reserved ones.
|
|
68
|
+
* Keyed `(entity, $branch, $to)`, `$to` indexed over closed rows for the
|
|
69
|
+
* retention floor, `$branch` over the branches' rows, and each of the live table's vocabulary indexes kept over
|
|
70
|
+
* its versions too, none of them unique, so a read of the past seeks as a read
|
|
71
|
+
* of the present does.
|
|
72
|
+
*/ export let besideDdl = (vocab, typed = ()=>undefined)=>{
|
|
73
|
+
let indexes = indexed(vocab);
|
|
74
|
+
return [
|
|
75
|
+
...covered(vocab)
|
|
76
|
+
].flatMap((comp)=>{
|
|
77
|
+
let name = beside(comp);
|
|
78
|
+
let physical = storageName(vocab, name);
|
|
79
|
+
let made = {
|
|
80
|
+
t: 'create table',
|
|
81
|
+
name,
|
|
82
|
+
ifNot: true,
|
|
83
|
+
cols: [
|
|
84
|
+
{
|
|
85
|
+
name: 'entity',
|
|
86
|
+
type: 'integer',
|
|
87
|
+
notNull: true,
|
|
88
|
+
ref: {
|
|
89
|
+
table: 'entity',
|
|
90
|
+
cols: [
|
|
91
|
+
'id'
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
...stored(vocab, comp).map((c)=>({
|
|
96
|
+
name: c,
|
|
97
|
+
type: typed(comp, c) ?? affinity(vocab, comp, c)
|
|
98
|
+
})),
|
|
99
|
+
{
|
|
100
|
+
name: BRANCH,
|
|
101
|
+
type: 'integer',
|
|
102
|
+
notNull: true,
|
|
103
|
+
default: lit(0)
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: FROM,
|
|
107
|
+
type: 'integer'
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: TO,
|
|
111
|
+
type: 'integer',
|
|
112
|
+
notNull: true,
|
|
113
|
+
default: lit(0)
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
};
|
|
117
|
+
let key = {
|
|
118
|
+
t: 'create index',
|
|
119
|
+
name: `${physical}.key`,
|
|
120
|
+
on: name,
|
|
121
|
+
cols: [
|
|
122
|
+
col('entity'),
|
|
123
|
+
col(BRANCH),
|
|
124
|
+
col(TO)
|
|
125
|
+
],
|
|
126
|
+
unique: true,
|
|
127
|
+
ifNot: true
|
|
128
|
+
};
|
|
129
|
+
let closed = {
|
|
130
|
+
t: 'create index',
|
|
131
|
+
name: `${physical}.to`,
|
|
132
|
+
on: name,
|
|
133
|
+
cols: [
|
|
134
|
+
col(TO)
|
|
135
|
+
],
|
|
136
|
+
ifNot: true,
|
|
137
|
+
where: ne(col(TO), lit(0))
|
|
138
|
+
};
|
|
139
|
+
// A branch's rows are few beside main's: what reads or drops one finds
|
|
140
|
+
// them here rather than in every version main keeps.
|
|
141
|
+
let few = {
|
|
142
|
+
t: 'create index',
|
|
143
|
+
name: `${physical}.branch`,
|
|
144
|
+
on: name,
|
|
145
|
+
cols: [
|
|
146
|
+
col(BRANCH),
|
|
147
|
+
col('entity')
|
|
148
|
+
],
|
|
149
|
+
ifNot: true,
|
|
150
|
+
where: ne(col(BRANCH), lit(0))
|
|
151
|
+
};
|
|
152
|
+
let mirrored = indexes.filter((i)=>i.on == comp).map((i)=>({
|
|
153
|
+
...i,
|
|
154
|
+
name: `${i.name}${BESIDE}`,
|
|
155
|
+
on: name,
|
|
156
|
+
unique: false
|
|
157
|
+
}));
|
|
158
|
+
return [
|
|
159
|
+
made,
|
|
160
|
+
key,
|
|
161
|
+
closed,
|
|
162
|
+
few,
|
|
163
|
+
...mirrored
|
|
164
|
+
];
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
/** Everything a store with history needs beside its own schema: the tables of
|
|
168
|
+
* versions, typed as `typed` says the live ones stand, and the branch table.
|
|
169
|
+
* The live tables are not restated: history changes none of them. */ export let historySchema = (vocab, typed)=>[
|
|
170
|
+
...besideDdl(vocab, typed),
|
|
171
|
+
...shapeDdl,
|
|
172
|
+
BRANCH_DDL,
|
|
173
|
+
{
|
|
174
|
+
t: 'create table',
|
|
175
|
+
name: BRANCH_TRASH,
|
|
176
|
+
ifNot: true,
|
|
177
|
+
cols: [
|
|
178
|
+
{
|
|
179
|
+
name: 'id',
|
|
180
|
+
type: 'integer',
|
|
181
|
+
pk: true
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
name: 'at',
|
|
185
|
+
type: 'text',
|
|
186
|
+
notNull: true
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
}
|
|
190
|
+
];
|
|
191
|
+
/** The versions of what main holds as history begins: each live row of every
|
|
192
|
+
* component that keeps versions, whose table of versions `made` says was just
|
|
193
|
+
* made, as its open version from no transaction. */ export let seeds = (vocab, made)=>[
|
|
194
|
+
...[
|
|
195
|
+
...covered(vocab)
|
|
196
|
+
].filter((comp)=>keeps(vocab, comp) && made(beside(comp))).map((comp)=>{
|
|
197
|
+
let cols = stored(vocab, comp);
|
|
198
|
+
return {
|
|
199
|
+
t: 'insert',
|
|
200
|
+
into: beside(comp),
|
|
201
|
+
cols: [
|
|
202
|
+
'entity',
|
|
203
|
+
...cols,
|
|
204
|
+
BRANCH,
|
|
205
|
+
FROM,
|
|
206
|
+
TO
|
|
207
|
+
],
|
|
208
|
+
q: select({
|
|
209
|
+
cols: [
|
|
210
|
+
col('entity'),
|
|
211
|
+
...cols.map((c)=>col(c)),
|
|
212
|
+
lit(0),
|
|
213
|
+
lit(null),
|
|
214
|
+
lit(0)
|
|
215
|
+
],
|
|
216
|
+
from: table(comp)
|
|
217
|
+
})
|
|
218
|
+
};
|
|
219
|
+
}),
|
|
220
|
+
...shapeSeeds([
|
|
221
|
+
...covered(vocab)
|
|
222
|
+
], made)
|
|
223
|
+
];
|
|
224
|
+
/** The key of what a store whose history began paced (`Opts.paced`) still
|
|
225
|
+
* owes, in `server_meta`: the components whose live rows are not yet their
|
|
226
|
+
* first versions, oldest first, and the last entity taken of the first. */ export let SEEDING = 'history:seeding';
|
|
227
|
+
/** The components of `seeds` whose first versions are owed a page at a
|
|
228
|
+
* time: each that keeps versions, whose table of versions `made` says was
|
|
229
|
+
* just made. */ export let unseeded = (vocab, made)=>[
|
|
230
|
+
...covered(vocab)
|
|
231
|
+
].filter((comp)=>keeps(vocab, comp) && made(beside(comp)));
|
|
232
|
+
/** The memberships a store repairs at once where its table of them was
|
|
233
|
+
* made beside tables of versions that stood: what {@link seeds} copies of
|
|
234
|
+
* them, less the components a paced beginning seeds itself. */ export let reshapes = (vocab, made)=>shapeSeeds([
|
|
235
|
+
...covered(vocab)
|
|
236
|
+
].filter((comp)=>!made(beside(comp))), made);
|
|
237
|
+
/**
|
|
238
|
+
* One page of a paced beginning's first versions: the live rows of `comp`
|
|
239
|
+
* past entity `after`, up to `limit`, each as its open version from no
|
|
240
|
+
* transaction, with its membership, where main has neither yet. History is
|
|
241
|
+
* kept from the beginning on, so a row a write changed or removed before its
|
|
242
|
+
* page was taken keeps only what that write made: its past begins there.
|
|
243
|
+
* Answers how many rows it took, and the last entity, or null where it took
|
|
244
|
+
* the last of them.
|
|
245
|
+
*/ export let seedPage = (driver, vocab, comp, after, limit)=>{
|
|
246
|
+
let [last] = driver.query(select({
|
|
247
|
+
cols: [
|
|
248
|
+
as(fn('max', col('entity')), 'last'),
|
|
249
|
+
as(fn('count', lit(1)), 'n')
|
|
250
|
+
],
|
|
251
|
+
from: from(select({
|
|
252
|
+
cols: [
|
|
253
|
+
col('entity')
|
|
254
|
+
],
|
|
255
|
+
from: table(comp),
|
|
256
|
+
where: op('>', col('entity'), val(after)),
|
|
257
|
+
order: [
|
|
258
|
+
col('entity')
|
|
259
|
+
],
|
|
260
|
+
limit: lit(limit)
|
|
261
|
+
}), 'page')
|
|
262
|
+
}));
|
|
263
|
+
if (last?.last == null) return {
|
|
264
|
+
taken: 0,
|
|
265
|
+
last: null
|
|
266
|
+
};
|
|
267
|
+
let upto = Number(last.last), taken = Number(last.n);
|
|
268
|
+
let page = and(op('>', col('entity', 'live'), val(after)), op('<=', col('entity', 'live'), val(upto)));
|
|
269
|
+
let none = (name, also = [])=>not(exists(select({
|
|
270
|
+
cols: [
|
|
271
|
+
lit(1)
|
|
272
|
+
],
|
|
273
|
+
from: table(name, 'held'),
|
|
274
|
+
where: and(eq(col('entity', 'held'), col('entity', 'live')), eq(col(BRANCH, 'held'), lit(0)), ...also)
|
|
275
|
+
})));
|
|
276
|
+
let cols = stored(vocab, comp);
|
|
277
|
+
driver.query({
|
|
278
|
+
t: 'insert',
|
|
279
|
+
into: beside(comp),
|
|
280
|
+
cols: [
|
|
281
|
+
'entity',
|
|
282
|
+
...cols,
|
|
283
|
+
BRANCH,
|
|
284
|
+
FROM,
|
|
285
|
+
TO
|
|
286
|
+
],
|
|
287
|
+
q: select({
|
|
288
|
+
cols: [
|
|
289
|
+
col('entity', 'live'),
|
|
290
|
+
...cols.map((c)=>col(c, 'live')),
|
|
291
|
+
lit(0),
|
|
292
|
+
lit(null),
|
|
293
|
+
lit(0)
|
|
294
|
+
],
|
|
295
|
+
from: table(comp, 'live'),
|
|
296
|
+
where: and(page, none(beside(comp)))
|
|
297
|
+
})
|
|
298
|
+
});
|
|
299
|
+
driver.query({
|
|
300
|
+
t: 'insert',
|
|
301
|
+
into: SHAPES,
|
|
302
|
+
cols: [
|
|
303
|
+
'entity',
|
|
304
|
+
'component',
|
|
305
|
+
BRANCH,
|
|
306
|
+
FROM,
|
|
307
|
+
TO
|
|
308
|
+
],
|
|
309
|
+
q: select({
|
|
310
|
+
cols: [
|
|
311
|
+
col('entity', 'live'),
|
|
312
|
+
lit(comp),
|
|
313
|
+
lit(0),
|
|
314
|
+
lit(null),
|
|
315
|
+
lit(0)
|
|
316
|
+
],
|
|
317
|
+
from: table(comp, 'live'),
|
|
318
|
+
where: and(page, none(SHAPES, [
|
|
319
|
+
eq(col('component', 'held'), lit(comp))
|
|
320
|
+
]))
|
|
321
|
+
})
|
|
322
|
+
});
|
|
323
|
+
return {
|
|
324
|
+
taken,
|
|
325
|
+
last: taken == limit ? upto : null
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
/** The branch table: a branch's parent (0 is main), the transaction it forked
|
|
329
|
+
* at, and when. Making one writes a row and copies nothing. A dropped
|
|
330
|
+
* branch's id is never given again, so an id names one branch for good. */ export let BRANCH_DDL = {
|
|
331
|
+
t: 'create table',
|
|
332
|
+
name: BRANCHES,
|
|
333
|
+
ifNot: true,
|
|
334
|
+
cols: [
|
|
335
|
+
{
|
|
336
|
+
name: 'id',
|
|
337
|
+
type: 'integer',
|
|
338
|
+
pk: true,
|
|
339
|
+
autoincrement: true
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
name: 'parent',
|
|
343
|
+
type: 'integer',
|
|
344
|
+
notNull: true,
|
|
345
|
+
default: lit(0)
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
name: 'fork',
|
|
349
|
+
type: 'integer',
|
|
350
|
+
notNull: true
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
name: 'at',
|
|
354
|
+
type: 'text',
|
|
355
|
+
notNull: true
|
|
356
|
+
}
|
|
357
|
+
]
|
|
358
|
+
};
|
|
359
|
+
let keeping = new WeakMap();
|
|
360
|
+
/** Bind a driver's writes to history: what `storage()` does for a store
|
|
361
|
+
* opened with one. */ export let keep = (driver, vocab, history, mode)=>void keeping.set(driver, {
|
|
362
|
+
vocab,
|
|
363
|
+
history,
|
|
364
|
+
mode,
|
|
365
|
+
units: []
|
|
366
|
+
});
|
|
367
|
+
/** Run `body` as one unit of history on this driver: its versioned writes
|
|
368
|
+
* name one transaction, taken when the first of them asks. */ export let within = (driver, body)=>{
|
|
369
|
+
let k = keeping.get(driver);
|
|
370
|
+
if (!k) return body(()=>NaN);
|
|
371
|
+
let unit = {};
|
|
372
|
+
k.units.push(unit);
|
|
373
|
+
let clock = ()=>unit.id ??= taken(driver, k);
|
|
374
|
+
try {
|
|
375
|
+
return body(clock);
|
|
376
|
+
} finally{
|
|
377
|
+
k.units.splice(k.units.lastIndexOf(unit), 1);
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
let taken = (driver, k)=>{
|
|
381
|
+
if (k.mode && 'at' in k.mode) {
|
|
382
|
+
throw new Error(`a read as of transaction ${k.mode.at} cannot write`);
|
|
383
|
+
}
|
|
384
|
+
let [row] = driver.query(k.history.clock);
|
|
385
|
+
let id = Number(row?.id);
|
|
386
|
+
if (!Number.isInteger(id)) {
|
|
387
|
+
throw new Error('the history clock answered no transaction id');
|
|
388
|
+
}
|
|
389
|
+
return id;
|
|
390
|
+
};
|
|
391
|
+
/** The id this driver's innermost unit's versions name, where it has taken
|
|
392
|
+
* one: what the history plugin writes its transaction row as. */ export let ticked = (driver)=>keeping.get(driver)?.units.at(-1)?.id;
|
|
393
|
+
// The live table a write names.
|
|
394
|
+
let target = (w)=>w.t == 'insert' ? w.into : w.t == 'update' ? w.table : w.from;
|
|
395
|
+
/**
|
|
396
|
+
* One write, kept: on main, the write itself, with the versions of the rows it
|
|
397
|
+
* changes closed and opened beside it; on a branch, a write to the branch's
|
|
398
|
+
* rows instead (`branched`). A write to a table history does not cover, or on
|
|
399
|
+
* main to an exempt component, is itself alone.
|
|
400
|
+
*/ let keep1 = (driver, w)=>{
|
|
401
|
+
let k = keeping.get(driver);
|
|
402
|
+
let alone = {
|
|
403
|
+
before: [],
|
|
404
|
+
write: w
|
|
405
|
+
};
|
|
406
|
+
if (!k) return alone;
|
|
407
|
+
let comp = target(w);
|
|
408
|
+
let { vocab } = k;
|
|
409
|
+
if (!covered(vocab).has(comp)) return alone;
|
|
410
|
+
if (k.mode && 'at' in k.mode) {
|
|
411
|
+
throw new Error(`a read as of transaction ${k.mode.at} cannot write`);
|
|
412
|
+
}
|
|
413
|
+
if (k.mode && 'branch' in k.mode) {
|
|
414
|
+
return branched(vocab, comp, w, k.mode.branch, clockOf(driver, k));
|
|
415
|
+
}
|
|
416
|
+
if (!keeps(vocab, comp)) return alone;
|
|
417
|
+
let tx = clockOf(driver, k);
|
|
418
|
+
let cols = stored(vocab, comp);
|
|
419
|
+
if (w.t == 'insert') {
|
|
420
|
+
return {
|
|
421
|
+
before: [],
|
|
422
|
+
write: w,
|
|
423
|
+
after: (owners)=>synced(comp, cols, owners.map((o)=>val(o)), tx)
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
let where = w.where ?? lit(true);
|
|
427
|
+
if (w.t == 'delete') {
|
|
428
|
+
return {
|
|
429
|
+
before: closed(comp, owned(comp, where), tx),
|
|
430
|
+
write: w
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
if (w.from) throw new Error('a versioned update from another table');
|
|
434
|
+
// Only the rows the update changes get a version.
|
|
435
|
+
let set = Object.entries(w.set).filter(([c])=>cols.includes(c));
|
|
436
|
+
let changes = and(where, or(...set.map(([c, e])=>op('is not', col(c), e))));
|
|
437
|
+
return {
|
|
438
|
+
before: [
|
|
439
|
+
...closed(comp, owned(comp, changes), tx),
|
|
440
|
+
opened(comp, cols, changes, tx, Object.fromEntries(set))
|
|
441
|
+
],
|
|
442
|
+
write: w
|
|
443
|
+
};
|
|
444
|
+
};
|
|
445
|
+
export let kept = (driver, w)=>{
|
|
446
|
+
let result = keep1(driver, w);
|
|
447
|
+
let k = keeping.get(driver);
|
|
448
|
+
let comp = target(w);
|
|
449
|
+
if (!k || !covered(k.vocab).has(comp) || !k.mode && !keeps(k.vocab, comp)) {
|
|
450
|
+
return result;
|
|
451
|
+
}
|
|
452
|
+
let tx = clockOf(driver, k);
|
|
453
|
+
let branch = k.mode && 'branch' in k.mode ? k.mode.branch : 0;
|
|
454
|
+
return {
|
|
455
|
+
...result,
|
|
456
|
+
after: (owners)=>[
|
|
457
|
+
...result.after?.(owners) ?? [],
|
|
458
|
+
...shaped(comp, owners, branch, tx, w.t != 'delete')
|
|
459
|
+
]
|
|
460
|
+
};
|
|
461
|
+
};
|
|
462
|
+
let clockOf = (driver, k)=>{
|
|
463
|
+
let unit = k.units.at(-1);
|
|
464
|
+
if (!unit) {
|
|
465
|
+
throw new Error('a versioned write outside a unit of the store');
|
|
466
|
+
}
|
|
467
|
+
return unit.id ??= taken(driver, k);
|
|
468
|
+
};
|
|
469
|
+
// Main's open version.
|
|
470
|
+
let MAIN_OPEN = and(eq(col(BRANCH), lit(0)), eq(col(TO), lit(0)));
|
|
471
|
+
// The entities whose rows of `comp` match `where`.
|
|
472
|
+
let owned = (comp, where)=>select({
|
|
473
|
+
cols: [
|
|
474
|
+
col('entity')
|
|
475
|
+
],
|
|
476
|
+
from: table(comp),
|
|
477
|
+
where
|
|
478
|
+
});
|
|
479
|
+
// Main's open versions of `owners`, ended at `tx`: one this same transaction
|
|
480
|
+
// opened goes, since nobody else ever saw it; any other is closed.
|
|
481
|
+
let closed = (comp, owners, tx)=>{
|
|
482
|
+
let to = beside(comp);
|
|
483
|
+
let mine = and(MAIN_OPEN, among(col('entity'), owners));
|
|
484
|
+
return [
|
|
485
|
+
{
|
|
486
|
+
t: 'delete',
|
|
487
|
+
from: to,
|
|
488
|
+
where: and(mine, eq(col(FROM), val(tx)))
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
t: 'update',
|
|
492
|
+
table: to,
|
|
493
|
+
set: {
|
|
494
|
+
[TO]: val(tx)
|
|
495
|
+
},
|
|
496
|
+
where: mine
|
|
497
|
+
}
|
|
498
|
+
];
|
|
499
|
+
};
|
|
500
|
+
// A version opened at `tx` for each live row `where` matches, holding what the
|
|
501
|
+
// row holds with `set` applied: an update's values, read before it runs.
|
|
502
|
+
let opened = (comp, cols, where, tx, set = {})=>({
|
|
503
|
+
t: 'insert',
|
|
504
|
+
into: beside(comp),
|
|
505
|
+
cols: [
|
|
506
|
+
'entity',
|
|
507
|
+
...cols,
|
|
508
|
+
BRANCH,
|
|
509
|
+
FROM,
|
|
510
|
+
TO
|
|
511
|
+
],
|
|
512
|
+
q: select({
|
|
513
|
+
cols: [
|
|
514
|
+
col('entity'),
|
|
515
|
+
...cols.map((c)=>set[c] ?? col(c)),
|
|
516
|
+
lit(0),
|
|
517
|
+
val(tx),
|
|
518
|
+
lit(0)
|
|
519
|
+
],
|
|
520
|
+
from: table(comp),
|
|
521
|
+
where
|
|
522
|
+
})
|
|
523
|
+
});
|
|
524
|
+
// After an insert, main's open versions of the `owners` it wrote made to match
|
|
525
|
+
// their live rows again: one that no longer does is ended, and a live row
|
|
526
|
+
// without one gets one. An upsert that changed nothing keeps none.
|
|
527
|
+
let synced = (comp, cols, owners, tx)=>{
|
|
528
|
+
let to = beside(comp);
|
|
529
|
+
let same = exists(select({
|
|
530
|
+
cols: [
|
|
531
|
+
lit(1)
|
|
532
|
+
],
|
|
533
|
+
from: table(comp, '__live'),
|
|
534
|
+
where: and(eq(col('entity', '__live'), col('entity', to)), ...cols.map((c)=>op('is', col(c, '__live'), col(c, to))))
|
|
535
|
+
}));
|
|
536
|
+
let stale = and(MAIN_OPEN, among(col('entity'), owners), not(same));
|
|
537
|
+
let none = not(exists(select({
|
|
538
|
+
cols: [
|
|
539
|
+
lit(1)
|
|
540
|
+
],
|
|
541
|
+
from: table(to, '__open'),
|
|
542
|
+
where: and(eq(col('entity', '__open'), col('entity', comp)), eq(col(BRANCH, '__open'), lit(0)), eq(col(TO, '__open'), lit(0)))
|
|
543
|
+
})));
|
|
544
|
+
return [
|
|
545
|
+
{
|
|
546
|
+
t: 'delete',
|
|
547
|
+
from: to,
|
|
548
|
+
where: and(stale, eq(col(FROM), val(tx)))
|
|
549
|
+
},
|
|
550
|
+
{
|
|
551
|
+
t: 'update',
|
|
552
|
+
table: to,
|
|
553
|
+
set: {
|
|
554
|
+
[TO]: val(tx)
|
|
555
|
+
},
|
|
556
|
+
where: stale
|
|
557
|
+
},
|
|
558
|
+
opened(comp, cols, and(among(col('entity'), owners), none), tx)
|
|
559
|
+
];
|
|
560
|
+
};
|
|
561
|
+
/** The way a mode reads. */ export let kind = (mode)=>'at' in mode ? 'at' : 'branch';
|
|
562
|
+
// A table in the file itself, past any relation of the same name the
|
|
563
|
+
// statement reading it stands in front of it (./mode.ts).
|
|
564
|
+
let main = (name, as)=>({
|
|
565
|
+
t: 'table',
|
|
566
|
+
name,
|
|
567
|
+
schema: 'main',
|
|
568
|
+
as
|
|
569
|
+
});
|
|
570
|
+
// The transaction main is read as of, a branch's fork, and the branch, or 0
|
|
571
|
+
// for none: integers written into the text, so a mode binds no value of its
|
|
572
|
+
// own beside the statement's (a Durable Object binds at most 100).
|
|
573
|
+
let atOf = (mode)=>lit('at' in mode ? mode.at : mode.fork);
|
|
574
|
+
let branchOf = (mode)=>lit('branch' in mode ? mode.branch : 0);
|
|
575
|
+
// No row of the mode's branch for the entity a row of `of` belongs to.
|
|
576
|
+
let unshadowed = (comp, of, mode)=>not(exists(select({
|
|
577
|
+
cols: [
|
|
578
|
+
lit(1)
|
|
579
|
+
],
|
|
580
|
+
from: main(beside(comp), '__mine'),
|
|
581
|
+
where: and(eq(col('entity', '__mine'), col('entity', of)), eq(col(BRANCH, '__mine'), branchOf(mode)))
|
|
582
|
+
})));
|
|
583
|
+
/**
|
|
584
|
+
* What `mode` reads `comp` as. Where main keeps its versions, one select over
|
|
585
|
+
* them: main's as of the mode's transaction and, on a branch, the branch's
|
|
586
|
+
* open rows over main's for every entity the branch has not written. Where it
|
|
587
|
+
* keeps none, as of a transaction, the live table as it stands; on a branch,
|
|
588
|
+
* the branch's open rows and the live rows it has not written.
|
|
589
|
+
*/ export let seen = (vocab, comp, mode)=>{
|
|
590
|
+
let names = [
|
|
591
|
+
'entity',
|
|
592
|
+
...stored(vocab, comp)
|
|
593
|
+
];
|
|
594
|
+
let v = '__v';
|
|
595
|
+
let picked = (of)=>names.map((c)=>col(c, of));
|
|
596
|
+
let at = atOf(mode), b = branchOf(mode);
|
|
597
|
+
let past = kind(mode) == 'at';
|
|
598
|
+
if (keeps(vocab, comp)) {
|
|
599
|
+
let then = and(eq(col(BRANCH, v), lit(0)), or(isNull(col(FROM, v)), op('<=', col(FROM, v), at)), or(eq(col(TO, v), lit(0)), op('>', col(TO, v), at)));
|
|
600
|
+
return select({
|
|
601
|
+
cols: picked(v),
|
|
602
|
+
from: main(beside(comp), v),
|
|
603
|
+
where: past ? then : or(and(eq(col(BRANCH, v), b), eq(col(TO, v), lit(0))), and(then, unshadowed(comp, v, mode)))
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
if (past) return select({
|
|
607
|
+
cols: picked(),
|
|
608
|
+
from: main(comp)
|
|
609
|
+
});
|
|
610
|
+
return unionAll(select({
|
|
611
|
+
cols: picked(),
|
|
612
|
+
from: main(beside(comp)),
|
|
613
|
+
where: and(eq(col(BRANCH), b), eq(col(TO), lit(0)))
|
|
614
|
+
}), select({
|
|
615
|
+
cols: picked('__live'),
|
|
616
|
+
from: main(comp, '__live'),
|
|
617
|
+
where: unshadowed(comp, '__live', mode)
|
|
618
|
+
}));
|
|
619
|
+
};
|
|
620
|
+
//# sourceMappingURL=history.js.map
|
package/history.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.js","sources":["./history.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,8EAA8E;AAC9E,+EAA+E;AAC/E,8EAA8E;AAC9E,0EAA0E;AAC1E,wEAAwE;AACxE,gFAAgF;AAChF,kEAAkE;AAClE,EAAE;AACF,0EAA0E;AAC1E,8EAA8E;AAC9E,4EAA4E;AAC5E,6EAA6E;AAC7E,+EAA+E;AAC/E,iEAAiE;AACjE,EAAE;AACF,4EAA4E;AAC5E,4EAA4E;AAC5E,uBAAuB;AACvB,EAAE;AACF,8EAA8E;AAC9E,4EAA4E;AAC5E,8EAA8E;AAC9E,gFAAgF;AAChF,wDAAwD;AACxD,EAAE;AACF,8EAA8E;AAC9E,2EAA2E;AAC3E,4EAA4E;AAC5E,8EAA8E;AAC9E,8EAA8E;AAC9E,yDAAyD;AAEzD,SACE,KAAK,EACL,GAAG,EACH,EAAE,EACF,GAAG,EAIH,EAAE,EACF,MAAM,EAEN,KAAK,EACL,EAAE,EACF,IAAI,EAEJ,MAAM,EACN,GAAG,EAEH,EAAE,EACF,GAAG,EACH,EAAE,EACF,EAAE,EAEF,MAAM,EAGN,UAAU,WAAW,EACrB,KAAK,EACL,QAAQ,EACR,GAAG,yBACwB;AAE7B,SAAS,SAAS,kCAAuC;AACzD,SAAS,MAAM,sBAAqB;AACpC,SAAS,OAAO,mBA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