@mistriwork/engine 1.0.0-rc.10 → 1.0.0-rc.12
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/dist/adapters/adapter.d.ts +33 -0
- package/dist/adapters/postgres.d.ts +21 -16
- package/dist/adapters/postgres.js +199 -223
- package/dist/adapters/postgresCatalog.d.ts +12 -1
- package/dist/adapters/postgresCatalog.js +57 -23
- package/dist/adapters/postgresCatalogDigest.js +40 -34
- package/dist/adapters/postgresCatalogRows.d.ts +2 -0
- package/dist/adapters/postgresWriteAhead.d.ts +47 -0
- package/dist/adapters/postgresWriteAhead.js +209 -0
- package/dist/adapters/scoped/keyRows.js +9 -3
- package/dist/adapters/scoped/keyTypes.d.ts +34 -0
- package/dist/adapters/scoped/keyTypes.js +66 -0
- package/dist/adapters/scoped/postgresScopeCatalog.d.ts +40 -1
- package/dist/adapters/scoped/postgresScopeCatalog.js +417 -13
- package/dist/adapters/scoped/postgresTriggers.d.ts +137 -0
- package/dist/adapters/scoped/postgresTriggers.js +1545 -0
- package/dist/adapters/scoped/scopeTriggers.d.ts +122 -0
- package/dist/adapters/scoped/scopeTriggers.js +131 -0
- package/dist/adapters/scoped/scopedReads.d.ts +3 -1
- package/dist/adapters/scoped/scopedReads.js +28 -8
- package/dist/adapters/scoped/scopedTransaction.d.ts +95 -6
- package/dist/adapters/scoped/scopedTransaction.js +308 -34
- package/dist/adapters/scoped/sqliteScopeCatalog.d.ts +17 -1
- package/dist/adapters/scoped/sqliteScopeCatalog.js +197 -18
- package/dist/adapters/scoped/sqliteTriggerSession.d.ts +64 -0
- package/dist/adapters/scoped/sqliteTriggerSession.js +245 -0
- package/dist/adapters/scoped/sqliteTriggers.d.ts +20 -0
- package/dist/adapters/scoped/sqliteTriggers.js +822 -0
- package/dist/adapters/scoped/storedText.d.ts +45 -0
- package/dist/adapters/scoped/storedText.js +61 -0
- package/dist/adapters/scoped/triggerEffects.d.ts +98 -0
- package/dist/adapters/scoped/triggerEffects.js +189 -0
- package/dist/adapters/scoped/triggerProof.d.ts +124 -0
- package/dist/adapters/scoped/triggerProof.js +366 -0
- package/dist/adapters/snapshotRead.d.ts +8 -0
- package/dist/adapters/snapshotRead.js +37 -0
- package/dist/adapters/sqlite.d.ts +13 -2
- package/dist/adapters/sqlite.js +139 -16
- package/dist/adapters/sqliteDecimals.d.ts +2 -2
- package/dist/adapters/sqliteDecimals.js +2 -8
- package/dist/adapters/storeHost.d.ts +4 -1
- package/dist/adapters/writeCapture.d.ts +7 -0
- package/dist/server/cli/args.d.ts +6 -0
- package/dist/server/cli/args.js +6 -0
- package/dist/server/columnGrants.d.ts +3 -0
- package/dist/server/columnGrants.js +12 -1
- package/dist/server/config/profile.d.ts +123 -0
- package/dist/server/config/profile.js +236 -0
- package/dist/server/connections.d.ts +5 -0
- package/dist/server/connections.js +11 -1
- package/dist/server/hiddenColumns.js +6 -0
- package/dist/server/http/refusalReport.js +16 -4
- package/dist/server/http/router.d.ts +11 -22
- package/dist/server/http/router.js +0 -15
- package/dist/server/migrate/cli.d.ts +50 -3
- package/dist/server/migrate/cli.js +199 -14
- package/dist/server/migrate/runner.js +5 -1
- package/dist/server/shapeonly.js +5 -0
- package/dist/shared/addressParams.d.ts +2 -0
- package/dist/shared/addressParams.js +2 -0
- package/dist/shared/aggregate.d.ts +49 -0
- package/dist/shared/aggregate.js +107 -0
- package/dist/shared/breakdown.js +19 -6
- package/dist/shared/decimals.d.ts +37 -0
- package/dist/shared/decimals.js +148 -0
- package/dist/shared/displayDefaults.js +15 -1
- package/dist/shared/filter.d.ts +39 -1
- package/dist/shared/filter.js +96 -15
- package/dist/shared/listPresentations.d.ts +2 -0
- package/dist/shared/listQuestion.d.ts +3 -1
- package/dist/shared/money.d.ts +9 -0
- package/dist/shared/money.js +17 -0
- package/dist/shared/moneyEntry.d.ts +6 -3
- package/dist/shared/moneyEntry.js +14 -7
- package/dist/shared/pageModel.d.ts +1 -1
- package/dist/shared/recordview.d.ts +1 -1
- package/dist/shared/refusal.d.ts +16 -0
- package/dist/shared/refusal.js +40 -0
- package/dist/shared/rowScope.js +12 -4
- package/dist/shared/schema.d.ts +6 -0
- package/dist/shared/schematext.d.ts +22 -6
- package/dist/shared/schematext.js +18 -2
- package/dist/shared/scopeCatalog.js +4 -0
- package/dist/shared/servedApp.d.ts +15 -4
- package/dist/shared/view.js +4 -4
- package/dist/shared/viewLabels.d.ts +1 -0
- package/dist/shared/viewLabels.js +8 -2
- package/dist/shared/viewPaths.d.ts +3 -0
- package/dist/shared/viewPaths.js +8 -0
- package/package.json +5 -2
- package/schema/model.d.ts +1 -1
- package/dist/shared/order.d.ts +0 -59
- package/dist/shared/order.js +0 -133
package/dist/shared/order.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* What has to exist first, and what comes apart in which order.
|
|
3
|
-
*
|
|
4
|
-
* Every foreign key is a statement about time: a row cannot point at a row
|
|
5
|
-
* that is not there yet, and a row that is pointed at cannot leave before the
|
|
6
|
-
* rows pointing at it. Building test data means knowing that order, and
|
|
7
|
-
* deriving it by hand from a catalog is exactly the work this tool already
|
|
8
|
-
* did to draw the graph.
|
|
9
|
-
*
|
|
10
|
-
* A topological sort, with the two things a topological sort usually leaves
|
|
11
|
-
* out said out loud:
|
|
12
|
-
*
|
|
13
|
-
* - **Cycles.** Two tables that point at each other have no order. Rather
|
|
14
|
-
* than picking one and pretending, the cycle is named — and where one of
|
|
15
|
-
* its edges is nullable, the way through is named too: insert with the
|
|
16
|
-
* column null, then update it once the other row exists.
|
|
17
|
-
* - **Self-references.** `work_order.parent_id → work_order` is not a
|
|
18
|
-
* cycle between tables and does not affect the order at all, but it does
|
|
19
|
-
* mean the rows inside that table have an order of their own. Reported
|
|
20
|
-
* separately, because it is a different problem with a different answer.
|
|
21
|
-
*
|
|
22
|
-
* Ties break alphabetically. A stable answer is worth more than a marginally
|
|
23
|
-
* shorter one: an order that changes between runs makes a fixture that
|
|
24
|
-
* "sometimes works", which is the failure this exists to prevent.
|
|
25
|
-
*/
|
|
26
|
-
import { findTable } from './schema.js';
|
|
27
|
-
/**
|
|
28
|
-
* @param tables The tables to order. Omitted means every table in the schema.
|
|
29
|
-
* Names are resolved through `findTable`, so a bare name works where the
|
|
30
|
-
* schema qualifies it.
|
|
31
|
-
*/
|
|
32
|
-
export function insertOrder(schema, tables) {
|
|
33
|
-
const wanted = tables?.length
|
|
34
|
-
? tables.map((name) => findTable(schema, name)?.id ?? name)
|
|
35
|
-
: schema.tables.filter((t) => !t.isView).map((t) => t.id);
|
|
36
|
-
const inSet = new Set(wanted);
|
|
37
|
-
const requires = {};
|
|
38
|
-
const selfReferencing = [];
|
|
39
|
-
/* `after.get(a)` holds the tables that must come *after* a — the edges of
|
|
40
|
-
the sort, pointing the way an insert travels. */
|
|
41
|
-
const after = new Map(wanted.map((id) => [id, new Set()]));
|
|
42
|
-
const waitingOn = new Map(wanted.map((id) => [id, 0]));
|
|
43
|
-
for (const fk of schema.foreignKeys) {
|
|
44
|
-
const from = fk.from.table;
|
|
45
|
-
const to = fk.to.table;
|
|
46
|
-
if (!inSet.has(from))
|
|
47
|
-
continue;
|
|
48
|
-
if (from === to) {
|
|
49
|
-
if (!selfReferencing.includes(from))
|
|
50
|
-
selfReferencing.push(from);
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
/* A reference out of the set is still a requirement — the row it points
|
|
54
|
-
at has to exist — but it cannot be ordered, because it is not part of
|
|
55
|
-
what was asked about. It belongs in `requires` and not in the sort. */
|
|
56
|
-
const columns = findTable(schema, from)?.columns ?? [];
|
|
57
|
-
const optional = fk.from.columns.every((name) => columns.find((c) => c.name === name)?.nullable !== false);
|
|
58
|
-
(requires[from] ??= []).push({ table: to, via: fk.from.columns, optional });
|
|
59
|
-
if (!inSet.has(to))
|
|
60
|
-
continue;
|
|
61
|
-
if (after.get(to).has(from))
|
|
62
|
-
continue;
|
|
63
|
-
after.get(to).add(from);
|
|
64
|
-
waitingOn.set(from, (waitingOn.get(from) ?? 0) + 1);
|
|
65
|
-
}
|
|
66
|
-
const insert = [];
|
|
67
|
-
const ready = wanted.filter((id) => !waitingOn.get(id)).sort();
|
|
68
|
-
while (ready.length) {
|
|
69
|
-
const id = ready.shift();
|
|
70
|
-
insert.push(id);
|
|
71
|
-
/* Sorted on the way in, so the answer does not depend on the order the
|
|
72
|
-
catalog happened to list the keys in. */
|
|
73
|
-
for (const next of [...after.get(id)].sort()) {
|
|
74
|
-
const left = (waitingOn.get(next) ?? 0) - 1;
|
|
75
|
-
waitingOn.set(next, left);
|
|
76
|
-
if (left === 0) {
|
|
77
|
-
ready.push(next);
|
|
78
|
-
ready.sort();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
/* Whatever is left is in a cycle, or behind one. Grouped so the answer
|
|
83
|
-
names the knot rather than listing its members. */
|
|
84
|
-
const stuck = wanted.filter((id) => !insert.includes(id));
|
|
85
|
-
const cycles = groupCycles(stuck, after);
|
|
86
|
-
for (const list of Object.values(requires)) {
|
|
87
|
-
list.sort((a, b) => a.table.localeCompare(b.table));
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
insert,
|
|
91
|
-
remove: [...insert].reverse(),
|
|
92
|
-
requires,
|
|
93
|
-
cycles,
|
|
94
|
-
selfReferencing: selfReferencing.sort(),
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* The knots, as knots.
|
|
99
|
-
*
|
|
100
|
-
* Two tables pointing at each other and a third waiting behind them are one
|
|
101
|
-
* problem with one fix, and three lines saying "could not be ordered" is
|
|
102
|
-
* three problems to work out are the same one.
|
|
103
|
-
*/
|
|
104
|
-
function groupCycles(stuck, after) {
|
|
105
|
-
const left = new Set(stuck);
|
|
106
|
-
const groups = [];
|
|
107
|
-
while (left.size) {
|
|
108
|
-
const start = [...left].sort()[0];
|
|
109
|
-
const group = new Set([start]);
|
|
110
|
-
const queue = [start];
|
|
111
|
-
while (queue.length) {
|
|
112
|
-
const id = queue.shift();
|
|
113
|
-
for (const next of after.get(id) ?? []) {
|
|
114
|
-
if (!left.has(next) || group.has(next))
|
|
115
|
-
continue;
|
|
116
|
-
group.add(next);
|
|
117
|
-
queue.push(next);
|
|
118
|
-
}
|
|
119
|
-
/* Both directions: a cycle is only visible if the walk can go back the
|
|
120
|
-
way the arrows came. */
|
|
121
|
-
for (const [other, targets] of after) {
|
|
122
|
-
if (!left.has(other) || group.has(other) || !targets.has(id))
|
|
123
|
-
continue;
|
|
124
|
-
group.add(other);
|
|
125
|
-
queue.push(other);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
for (const id of group)
|
|
129
|
-
left.delete(id);
|
|
130
|
-
groups.push([...group].sort());
|
|
131
|
-
}
|
|
132
|
-
return groups;
|
|
133
|
-
}
|