@mistriwork/engine 1.0.0-rc.11 → 1.0.0-rc.13
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/postgres.js +28 -3
- package/dist/adapters/scoped/postgresScopeCatalog.d.ts +22 -1
- package/dist/adapters/scoped/postgresScopeCatalog.js +66 -2
- package/dist/adapters/scoped/scopedReads.js +6 -4
- package/dist/adapters/scoped/scopedTransaction.d.ts +21 -2
- package/dist/adapters/scoped/scopedTransaction.js +37 -7
- package/dist/adapters/sqlite.js +1 -1
- package/dist/server/cli/bin.js +2 -2
- package/dist/server/cli/startup.js +2 -2
- package/dist/server/cli/usage.d.ts +2 -2
- package/dist/server/cli/usage.js +2 -2
- package/dist/server/demo.js +2 -2
- package/dist/server/http/baselineHeaders.d.ts +2 -0
- package/dist/server/http/baselineHeaders.js +2 -0
- package/dist/server/http/crawlerText.d.ts +4 -1
- package/dist/server/http/crawlerText.js +4 -1
- package/dist/server/http/httpOperationRoutes.d.ts +4 -1
- package/dist/server/http/httpOperationRoutes.js +4 -1
- package/dist/server/http/reply.d.ts +1 -0
- package/dist/server/http/reply.js +1 -0
- package/dist/server/http/router.d.ts +11 -22
- package/dist/server/http/router.js +0 -15
- package/dist/server/http/trust.d.ts +1 -0
- package/dist/server/http/trust.js +1 -0
- package/dist/server/product.d.ts +1 -1
- package/dist/server/recordWriteOperations.d.ts +2 -1
- package/dist/server/recordWriteOperations.js +2 -1
- package/dist/server/resourceReadHttp.d.ts +1 -0
- package/dist/server/resourceReadHttp.js +1 -0
- package/dist/shared/addressParams.d.ts +2 -0
- package/dist/shared/addressParams.js +2 -0
- package/dist/shared/breakdown.js +2 -2
- package/dist/shared/filter.d.ts +18 -1
- package/dist/shared/filter.js +62 -8
- package/dist/shared/listPresentations.d.ts +2 -0
- package/dist/shared/listQuestion.d.ts +3 -1
- package/dist/shared/moneyEntry.d.ts +6 -3
- package/dist/shared/moneyEntry.js +14 -7
- package/dist/shared/recordview.d.ts +1 -1
- package/dist/shared/rowScope.js +12 -4
- package/dist/shared/schematext.d.ts +22 -6
- package/dist/shared/schematext.js +18 -2
- package/dist/shared/servedApp.d.ts +8 -2
- 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 +4 -2
- package/schema/model.d.ts +1 -1
- package/dist/shared/order.d.ts +0 -59
- package/dist/shared/order.js +0 -133
package/schema/model.d.ts
CHANGED
|
@@ -157,7 +157,7 @@ export type AppCommandField = (CommandValueBase & (
|
|
|
157
157
|
| { type: 'richText'; minLength?: number; maxLength?: number; mentions?: CommandRichTextMentions; images?: string }
|
|
158
158
|
| { type: 'number'; min?: number; max?: number; integer?: boolean; step?: number; below?: string; above?: string; live?: CommandLiveLines }
|
|
159
159
|
/** An amount of money in the App's currency (`ui.currency`), from 0 unless `min` says less, on cents unless `step` says otherwise. */
|
|
160
|
-
| { type: 'money'; min?: number; max?: number; step?: number; below?: string; above?: string; live?: CommandLiveLines }
|
|
160
|
+
| { type: 'money'; min?: number; max?: number; step?: number; minor?: boolean; currency?: string; below?: string; above?: string; live?: CommandLiveLines }
|
|
161
161
|
/** `statement`: the long words a consent box stands beside (at most 2,000 characters), drawn as one paragraph. */
|
|
162
162
|
| { type: 'boolean'; accept?: true; statement?: string }
|
|
163
163
|
| { type: 'date'; min?: string; max?: string; below?: string; above?: string }
|
package/dist/shared/order.d.ts
DELETED
|
@@ -1,59 +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 { type DatabaseSchema } from './schema.js';
|
|
27
|
-
interface Requirement {
|
|
28
|
-
/** The table that must have the row already. */
|
|
29
|
-
table: string;
|
|
30
|
-
/** The columns pointing at it. */
|
|
31
|
-
via: string[];
|
|
32
|
-
/**
|
|
33
|
-
* Whether every one of those columns may be null.
|
|
34
|
-
*
|
|
35
|
-
* A nullable reference is a requirement you can postpone: insert the row
|
|
36
|
-
* without it, then update. That is the only way out of a cycle, so it is
|
|
37
|
-
* worth saying even where the order came out fine.
|
|
38
|
-
*/
|
|
39
|
-
optional: boolean;
|
|
40
|
-
}
|
|
41
|
-
interface OrderPlan {
|
|
42
|
-
/** Parents first: insert in this order and no reference dangles. */
|
|
43
|
-
insert: string[];
|
|
44
|
-
/** Children first: the reverse, which is what teardown needs. */
|
|
45
|
-
remove: string[];
|
|
46
|
-
/** Per table, what must exist before it. */
|
|
47
|
-
requires: Record<string, Requirement[]>;
|
|
48
|
-
/** Tables whose order could not be decided, grouped by the cycle they are in. */
|
|
49
|
-
cycles: string[][];
|
|
50
|
-
/** Tables that point at themselves: an order *within* the table. */
|
|
51
|
-
selfReferencing: string[];
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* @param tables The tables to order. Omitted means every table in the schema.
|
|
55
|
-
* Names are resolved through `findTable`, so a bare name works where the
|
|
56
|
-
* schema qualifies it.
|
|
57
|
-
*/
|
|
58
|
-
export declare function insertOrder(schema: DatabaseSchema, tables?: string[]): OrderPlan;
|
|
59
|
-
export {};
|
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
|
-
}
|