@niscorp/strata 0.1.7 → 0.1.8
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/CHANGELOG.md +14 -0
- package/DESIGN.md +11 -5
- package/README.md +36 -7
- package/dist/check/index.cjs +7 -7
- package/dist/check/index.js +2 -2
- package/dist/{chunk-QIXZZZE6.cjs → chunk-564JCO6Q.cjs} +8 -8
- package/dist/{chunk-QIXZZZE6.cjs.map → chunk-564JCO6Q.cjs.map} +1 -1
- package/dist/{chunk-BW4CKKGE.cjs → chunk-7PBIGCLL.cjs} +2 -2
- package/dist/chunk-7PBIGCLL.cjs.map +1 -0
- package/dist/{chunk-PODP3F5N.js → chunk-DGS4XJQQ.js} +4 -4
- package/dist/{chunk-PODP3F5N.js.map → chunk-DGS4XJQQ.js.map} +1 -1
- package/dist/{chunk-D42CQI2X.js → chunk-FNMGVPSA.js} +4 -4
- package/dist/{chunk-D42CQI2X.js.map → chunk-FNMGVPSA.js.map} +1 -1
- package/dist/{chunk-IOS2DL6R.cjs → chunk-FSEUYRLN.cjs} +15 -15
- package/dist/{chunk-IOS2DL6R.cjs.map → chunk-FSEUYRLN.cjs.map} +1 -1
- package/dist/{chunk-HW6ON3LT.cjs → chunk-KYNER7UU.cjs} +18 -7
- package/dist/chunk-KYNER7UU.cjs.map +1 -0
- package/dist/{chunk-CI652R5O.js → chunk-PAMQMFBK.js} +15 -4
- package/dist/chunk-PAMQMFBK.js.map +1 -0
- package/dist/{chunk-LIWVOCKP.js → chunk-SH6BBA2X.js} +3 -3
- package/dist/{chunk-LIWVOCKP.js.map → chunk-SH6BBA2X.js.map} +1 -1
- package/dist/{chunk-VNF4KPVN.js → chunk-STNFHBNR.js} +2 -2
- package/dist/chunk-STNFHBNR.js.map +1 -0
- package/dist/{chunk-3DPZS52U.cjs → chunk-SYU7NKZR.cjs} +4 -4
- package/dist/{chunk-3DPZS52U.cjs.map → chunk-SYU7NKZR.cjs.map} +1 -1
- package/dist/index.cjs +21 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/node/index.cjs +11 -11
- package/dist/node/index.js +5 -5
- package/dist/{plan-mFmdh0qT.d.ts → plan-BMZJUCZ1.d.ts} +6 -3
- package/dist/{plan-CxuteSH1.d.cts → plan-Bq_Q2x5r.d.cts} +6 -3
- package/dist/postgres/index.cjs +36 -23
- package/dist/postgres/index.cjs.map +1 -1
- package/dist/postgres/index.d.cts +7 -3
- package/dist/postgres/index.d.ts +7 -3
- package/dist/postgres/index.js +25 -12
- package/dist/postgres/index.js.map +1 -1
- package/dist/upgrade/index.cjs +7 -7
- package/dist/upgrade/index.js +3 -3
- package/package.json +1 -1
- package/dist/chunk-BW4CKKGE.cjs.map +0 -1
- package/dist/chunk-CI652R5O.js.map +0 -1
- package/dist/chunk-HW6ON3LT.cjs.map +0 -1
- package/dist/chunk-VNF4KPVN.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @niscorp/strata
|
|
2
2
|
|
|
3
|
+
## 0.1.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2780c56: `migrate` reads the ledger before it locks or creates anything. On a database with nothing pending a run is that read and nothing else — no lock, no `CREATE TABLE IF NOT EXISTS strata_ledger`, no transaction — so a database role without the right to change tables can check them. `mode: 'verify'` is always that read: it needs `SELECT` on the ledger and no `transaction` on the pool.
|
|
8
|
+
|
|
9
|
+
A run sets its own timeouts for its transaction: `statementTimeoutMs` (default 3 600 000) bounds every step and the wait for another run; `lockTimeoutMs` (default 10 000) makes a step queued behind a busy table give up instead of queueing every later query on that table behind it. The pool's own `statement_timeout` no longer cuts a migration step, and is as it was after the run. A step that times out fails the run (`STEP_FAILED`), which is rolled back.
|
|
10
|
+
|
|
11
|
+
`complete: true` (on `migrate`, `status` and `planMigrations`) says the sequences given are every sequence the ledger may record: a ledger sequence nobody names is refused, `UNKNOWN_SEQUENCE`. Without it nothing changes.
|
|
12
|
+
|
|
13
|
+
A `guard` is told what the run applied: `guard(tx, { applied })`.
|
|
14
|
+
|
|
15
|
+
**What to change:** nothing. A migration step that waits longer than 10 s for a lock now fails instead of waiting; pass `lockTimeoutMs` to wait longer.
|
|
16
|
+
|
|
3
17
|
## 0.1.7
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/DESIGN.md
CHANGED
|
@@ -41,11 +41,17 @@ in the ledger, an unknown dependency, a cycle: each is a refusal with a
|
|
|
41
41
|
sentence, never a best effort. Verify mode refuses pending work, so a
|
|
42
42
|
production boot can require that a deploy step migrated first.
|
|
43
43
|
|
|
44
|
-
**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
**Read first, then one transaction, one lock.** A run reads the ledger before
|
|
45
|
+
anything else; with problems it refuses, in verify mode or with nothing pending
|
|
46
|
+
it ends there — a read that a role without DDL rights can make. Otherwise it
|
|
47
|
+
opens one transaction, sets its own statement timeout, takes
|
|
48
|
+
`pg_advisory_xact_lock` on the ledger's name, sets its lock timeout, creates
|
|
49
|
+
the ledger if needed, reads it again, plans and applies. Postgres DDL is
|
|
50
|
+
transactional, so a failed step leaves nothing behind. The lock comes before
|
|
51
|
+
the ledger's DDL because two processes creating the ledger at once race in the
|
|
52
|
+
catalog before either reaches a row; the statement timeout comes before the
|
|
53
|
+
lock and the lock timeout after it, so waiting for another run is bounded by
|
|
54
|
+
the first and a step queued behind a busy table by the second.
|
|
49
55
|
|
|
50
56
|
**Pure core, structural pool.** The plan is a pure function of sequences and
|
|
51
57
|
ledger rows; the runner is the only thing that touches a database, through the
|
package/README.md
CHANGED
|
@@ -32,8 +32,9 @@ await migrate(pool, [appSequence]); // applies what is pending, recor
|
|
|
32
32
|
await migrate(pool, [appSequence], { mode: 'verify' }); // refuses if anything is pending
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
Under moss you rarely call it:
|
|
36
|
-
own tables, the sessions table, the vex cache — in one
|
|
35
|
+
Under moss you rarely call it: `nisc migrate` runs every owner's sequence —
|
|
36
|
+
moss's own tables, the sessions table, the vex cache, the app's — in one
|
|
37
|
+
ledgered run, and the server checks them at boot.
|
|
37
38
|
|
|
38
39
|
## The rules
|
|
39
40
|
|
|
@@ -52,10 +53,23 @@ own tables, the sessions table, the vex cache — in one ledgered run at boot.
|
|
|
52
53
|
function body, a `/* */` comment or a trailing `--` comment cuts there too,
|
|
53
54
|
and two statements on one line, or a `;` followed by a trailing comment, stay
|
|
54
55
|
one step. Write those as their own steps.
|
|
56
|
+
- **A run reads before it writes.** The ledger is read first; a database with
|
|
57
|
+
nothing pending is answered from that read — no lock, no DDL, no transaction —
|
|
58
|
+
so an app whose database role cannot change tables can still check them.
|
|
55
59
|
- **A run is one transaction** under an advisory lock. A step throws, nothing
|
|
56
|
-
from the run happened — Postgres DDL is transactional. Two processes
|
|
60
|
+
from the run happened — Postgres DDL is transactional. Two processes migrating
|
|
57
61
|
at once serialize; the second finds the work done.
|
|
62
|
+
- **A run sets its own timeouts**, for its transaction only: a statement
|
|
63
|
+
timeout (1 hour) that also bounds the wait for another run, then a lock
|
|
64
|
+
timeout (10 s) so a step queued behind a busy table gives up instead of
|
|
65
|
+
queueing every later query on that table behind it. A step that times out
|
|
66
|
+
fails the run like any other (`STEP_FAILED`); nothing is retried.
|
|
58
67
|
- **A database migrated by newer code is refused** (`TOO_NEW`), never guessed at.
|
|
68
|
+
- **A sequence that has run stays in the code.** Given `complete: true`, a
|
|
69
|
+
ledger sequence nobody names is refused (`UNKNOWN_SEQUENCE`) — a renamed
|
|
70
|
+
sequence would otherwise run its first migration again. To remove a
|
|
71
|
+
sequence's tables, append a migration that drops them. One app per database
|
|
72
|
+
schema: two apps sharing a schema share one ledger.
|
|
59
73
|
- **Sequence ids are namespaced**: `nisc.vex.cache`, `nisc.moss`, `acme.app`.
|
|
60
74
|
An id is lowercase, in at least two dot-separated parts (`<owner>.<name>`),
|
|
61
75
|
each a letter followed by letters, digits or hyphens.
|
|
@@ -70,7 +84,7 @@ own tables, the sessions table, the vex cache — in one ledgered run at boot.
|
|
|
70
84
|
|---|---|
|
|
71
85
|
| `defineSequence(seq)` | Type-checks a sequence where it is written. |
|
|
72
86
|
| `prepare(sequences)` | Parses (Zod, at the boundary), numbers and checksums. Throws `INVALID_SEQUENCE`. Two sequences with the same id are refused the same way. |
|
|
73
|
-
| `planMigrations(prepared, ledger)` | Pure: what is pending, in order, and every problem (`EDITED`, `TOO_NEW`, `UNKNOWN_DEPENDENCY`, `CYCLE`). Returns `{ applied, pending, problems }`; `applied` is, per sequence given, how many of its migrations the ledger records. `UNKNOWN_DEPENDENCY` is a `dependsOn` naming a migration that no sequence given provides and the ledger does not record. |
|
|
87
|
+
| `planMigrations(prepared, ledger, { complete })` | Pure: what is pending, in order, and every problem (`EDITED`, `TOO_NEW`, `UNKNOWN_DEPENDENCY`, `CYCLE`, and with `complete` `UNKNOWN_SEQUENCE`). Returns `{ applied, pending, problems }`; `applied` is, per sequence given, how many of its migrations the ledger records. `UNKNOWN_DEPENDENCY` is a `dependsOn` naming a migration that no sequence given provides and the ledger does not record. |
|
|
74
88
|
| `refuseProblems(plan)` | Throws a plan's problems as one `StrataError`: its `code` is the first problem's, its `details` list them all. Returns when the plan has none. `migrate` refuses a plan this way. |
|
|
75
89
|
| `checksumOf(migration)` | SHA-256 over the steps (WebCrypto — Node ≥ 22 and every browser). |
|
|
76
90
|
| `sqlSteps(ddl)` | A DDL file as one step per statement, for a file where every statement ends its line with `;`. Cuts at each line that ends in `;`, full-line `--` comments excepted. Not a SQL parser. |
|
|
@@ -81,14 +95,15 @@ own tables, the sessions table, the vex cache — in one ledgered run at boot.
|
|
|
81
95
|
|
|
82
96
|
| | |
|
|
83
97
|
|---|---|
|
|
84
|
-
| `migrate(pool, sequences, { mode, guard, dryRun, table, schema })` | The run. `mode: 'apply'` (default) or `'verify'`. Returns `{ applied, plan }`. `guard(tx)` is asked inside the run, after the last pending step — when nothing was pending too: every sentence it returns refuses the run (`DOES_NOT_FIT`), and nothing was applied. `dryRun` does all of it, guard included, then rolls it back — the report says what would be applied, and it takes the locks a real run takes. `applied` is what this run applied, in order; `plan` is the plan it acted on, so `plan.applied` holds each sequence's position before the run. `'verify'` refuses with `PENDING` when anything is pending, and a step that throws refuses the run with `STEP_FAILED`. |
|
|
85
|
-
| `status(pool, sequences,
|
|
98
|
+
| `migrate(pool, sequences, { mode, complete, guard, dryRun, lockTimeoutMs, statementTimeoutMs, table, schema })` | The run. `mode: 'apply'` (default) or `'verify'` — which only reads: it needs `SELECT` on the ledger and nothing else, not even `transaction`. Returns `{ applied, plan }`. `lockTimeoutMs` (default 10 000) and `statementTimeoutMs` (default 3 600 000) hold for the run's transaction only. `guard(tx, { applied })` is asked inside the run, after the last pending step — when nothing was pending too, with `applied` empty: every sentence it returns refuses the run (`DOES_NOT_FIT`), and nothing was applied. `dryRun` does all of it, guard included, then rolls it back — the report says what would be applied, and it takes the locks a real run takes. `applied` is what this run applied, in order; `plan` is the plan it acted on, so `plan.applied` holds each sequence's position before the run. `'verify'` refuses with `PENDING` when anything is pending, and a step that throws refuses the run with `STEP_FAILED`. |
|
|
99
|
+
| `status(pool, sequences, { complete, table, schema })` | The plan, read-only — creates nothing, not even the ledger. |
|
|
86
100
|
| `readLedger(pool, options)` | The ledger's rows; empty for a database never migrated. |
|
|
87
101
|
| `ledgerDdl(options)` | The ledger table's DDL — the one statement strata runs outside a ledger. |
|
|
88
102
|
|
|
89
103
|
The pool is structural — `{ query, transaction }`, the shape vex's PGlite pool
|
|
90
104
|
and a wrapped `pg` pool already have. A pool without `transaction` is refused
|
|
91
|
-
(`NO_TRANSACTION`): a run must land whole or
|
|
105
|
+
(`NO_TRANSACTION`) when it has something to apply: a run must land whole or
|
|
106
|
+
not at all. `query` and
|
|
92
107
|
`transaction` are called on the object that has them, so a driver's own object
|
|
93
108
|
whose methods reach for `this` — a PGlite, a `pg` client handed through as the
|
|
94
109
|
transaction — works as it is.
|
|
@@ -96,6 +111,20 @@ transaction — works as it is.
|
|
|
96
111
|
The ledger defaults to `strata_ledger` in the connection's schema, beside the
|
|
97
112
|
app's tables; `table` and `schema` move it.
|
|
98
113
|
|
|
114
|
+
Because a check only reads, the database can enforce who changes tables: the
|
|
115
|
+
app connects as a role that may not, and the step that migrates connects as
|
|
116
|
+
one that may. The app's role needs `USAGE` on the schema, `SELECT` on the
|
|
117
|
+
ledger, and its rights on the tables the migrating role creates (`ALTER DEFAULT
|
|
118
|
+
PRIVILEGES FOR ROLE <migrator> IN SCHEMA <schema> GRANT … TO <app role>`). The
|
|
119
|
+
migrating step is given its own connection string — on Railway, a pre-deploy
|
|
120
|
+
command such as `DATABASE_URL=$MIGRATION_DATABASE_URL pnpm exec nisc migrate`.
|
|
121
|
+
A run that has to apply something as the app's role is refused by Postgres
|
|
122
|
+
("permission denied for schema").
|
|
123
|
+
|
|
124
|
+
The wait for another run is bounded by the statement timeout: the run clears
|
|
125
|
+
any `lock_timeout` the pool set before it takes the lock. A timeout during that
|
|
126
|
+
wait is Postgres's own error, not `STEP_FAILED`; nothing was applied.
|
|
127
|
+
|
|
99
128
|
## Adopting a database from before strata
|
|
100
129
|
|
|
101
130
|
Packages used to converge their tables on every boot with
|
package/dist/check/index.cjs
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
3
|
+
var chunkSYU7NKZR_cjs = require('../chunk-SYU7NKZR.cjs');
|
|
4
|
+
require('../chunk-7PBIGCLL.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "checkCorpus", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunkSYU7NKZR_cjs.checkCorpus; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "compareSnapshot", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkSYU7NKZR_cjs.compareSnapshot; }
|
|
15
15
|
});
|
|
16
16
|
Object.defineProperty(exports, "diffJson", {
|
|
17
17
|
enumerable: true,
|
|
18
|
-
get: function () { return
|
|
18
|
+
get: function () { return chunkSYU7NKZR_cjs.diffJson; }
|
|
19
19
|
});
|
|
20
20
|
Object.defineProperty(exports, "snapshotOf", {
|
|
21
21
|
enumerable: true,
|
|
22
|
-
get: function () { return
|
|
22
|
+
get: function () { return chunkSYU7NKZR_cjs.snapshotOf; }
|
|
23
23
|
});
|
|
24
24
|
Object.defineProperty(exports, "snapshotText", {
|
|
25
25
|
enumerable: true,
|
|
26
|
-
get: function () { return
|
|
26
|
+
get: function () { return chunkSYU7NKZR_cjs.snapshotText; }
|
|
27
27
|
});
|
|
28
28
|
//# sourceMappingURL=index.cjs.map
|
|
29
29
|
//# sourceMappingURL=index.cjs.map
|
package/dist/check/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { checkCorpus, compareSnapshot, diffJson, snapshotOf, snapshotText } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
export { checkCorpus, compareSnapshot, diffJson, snapshotOf, snapshotText } from '../chunk-SH6BBA2X.js';
|
|
2
|
+
import '../chunk-STNFHBNR.js';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkSYU7NKZR_cjs = require('./chunk-SYU7NKZR.cjs');
|
|
4
|
+
var chunk7PBIGCLL_cjs = require('./chunk-7PBIGCLL.cjs');
|
|
5
5
|
|
|
6
6
|
// src/upgrade/index.ts
|
|
7
7
|
var keyOf = (doc) => `${doc.kind}:${doc.id}`;
|
|
@@ -38,7 +38,7 @@ var planSourceUpgrade = async (options) => {
|
|
|
38
38
|
const problems = [];
|
|
39
39
|
for (const doc of documents) {
|
|
40
40
|
const key = keyOf(doc);
|
|
41
|
-
if (seen.has(key)) throw new
|
|
41
|
+
if (seen.has(key)) throw new chunk7PBIGCLL_cjs.StrataError("INVALID_SEQUENCE", `Two artifacts are both ${key} \u2014 an artifact needs one identity to be planned.`);
|
|
42
42
|
seen.add(key);
|
|
43
43
|
const result = upgrader.upgrade(doc.document, { kind: doc.kind, stamp });
|
|
44
44
|
if (sameJson(result.document, doc.document)) {
|
|
@@ -50,7 +50,7 @@ var planSourceUpgrade = async (options) => {
|
|
|
50
50
|
id: doc.id,
|
|
51
51
|
...doc.file === void 0 ? {} : { file: doc.file },
|
|
52
52
|
applied: result.applied,
|
|
53
|
-
changes:
|
|
53
|
+
changes: chunkSYU7NKZR_cjs.diffJson(doc.document, result.document),
|
|
54
54
|
expected: result.document
|
|
55
55
|
});
|
|
56
56
|
const schema = schemas?.[doc.kind];
|
|
@@ -87,7 +87,7 @@ var verifySourceUpgrade = (options) => {
|
|
|
87
87
|
} else if (sameJson(got.document, want.expected)) {
|
|
88
88
|
lines.push({ ok: true, text: `${key} matches its migrated JSON` });
|
|
89
89
|
} else {
|
|
90
|
-
lines.push({ ok: false, text: `${key} does not match its migrated JSON yet`, detail:
|
|
90
|
+
lines.push({ ok: false, text: `${key} does not match its migrated JSON yet`, detail: chunkSYU7NKZR_cjs.diffJson(got.document, want.expected, 12) });
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
for (const key of plan.untouched) {
|
|
@@ -98,7 +98,7 @@ var verifySourceUpgrade = (options) => {
|
|
|
98
98
|
}
|
|
99
99
|
const again = upgrader.upgrade(got.document, { kind: got.kind, stamp: plan.from });
|
|
100
100
|
if (!sameJson(again.document, got.document)) {
|
|
101
|
-
lines.push({ ok: false, text: `${key} was not in the plan, but the migrations would change it now`, detail:
|
|
101
|
+
lines.push({ ok: false, text: `${key} was not in the plan, but the migrations would change it now`, detail: chunkSYU7NKZR_cjs.diffJson(got.document, again.document, 12) });
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
const known = /* @__PURE__ */ new Set([...plan.documents.map(keyOf), ...plan.untouched]);
|
|
@@ -157,5 +157,5 @@ exports.changedStrings = changedStrings;
|
|
|
157
157
|
exports.planSourceUpgrade = planSourceUpgrade;
|
|
158
158
|
exports.renderReport = renderReport;
|
|
159
159
|
exports.verifySourceUpgrade = verifySourceUpgrade;
|
|
160
|
-
//# sourceMappingURL=chunk-
|
|
161
|
-
//# sourceMappingURL=chunk-
|
|
160
|
+
//# sourceMappingURL=chunk-564JCO6Q.cjs.map
|
|
161
|
+
//# sourceMappingURL=chunk-564JCO6Q.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/upgrade/index.ts"],"names":["StrataError","diffJson"],"mappings":";;;;;;AAyBA,IAAM,KAAA,GAAQ,CAAC,GAAA,KAA8C,CAAA,EAAG,IAAI,IAAI,CAAA,CAAA,EAAI,IAAI,EAAE,CAAA,CAAA;AAElF,IAAM,QAAA,GAAW,CAAC,KAAA,KAA4B;AAC5C,EAAA,IAAI,MAAM,OAAA,CAAQ,KAAK,GAAG,OAAO,KAAA,CAAM,IAAI,QAAQ,CAAA;AACnD,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,MAAM,OAAO,KAAA;AACxD,EAAA,OAAO,MAAA,CAAO,WAAA,CAAY,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,CAAE,IAAA,CAAK,CAAC,CAAC,CAAC,CAAA,EAAG,CAAC,CAAC,CAAA,KAAO,IAAI,CAAA,GAAI,EAAA,GAAK,CAAA,GAAI,CAAA,GAAI,CAAA,GAAI,CAAE,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,CAAA,EAAG,CAAC,CAAA,KAAM,CAAC,CAAA,EAAG,QAAA,CAAS,CAAC,CAAC,CAA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CAAC,CAAA,CAAA;AAAA,QAAI,CAAA,uBAAA,EAA0B,cAAA,CAAe,GAAG,CAAC,CAAA,EAAA,CAAA;AAAA,QAAM,gBAAA;AAAA,QAAkB,EAAA;AAAA,QAAI,KAAA;AAAA,QAAO,GAAG,GAAA,CAAI,OAAA;AAAA,QAAS,KAAA;AAAA,QAAO;AAAA,OAAE;AAAA,IACxV;AAAA,EACF;AACA,EAAA,OAAO,IAAI,MAAA,CAAO,CAAC,IAAA,EAAM,CAAA,EAAG,QAAQ,EAAE,IAAA,KAAS,EAAA,IAAM,GAAA,CAAI,IAAI,CAAC,CAAA,KAAM,EAAA,CAAG,CAAA,CAAE,KAAK,IAAI,CAAA;AACpF","file":"chunk-QIXZZZE6.cjs","sourcesContent":["import type { Stamp, Upgrader } from '../documents';\nimport { diffJson, type GrammarSchema } from '../check';\nimport { StrataError } from '../errors';\n\nexport type SourceDocument = { kind: string; id: string; document: unknown; file?: string };\n\nexport type PlannedDocument = {\n kind: string;\n id: string;\n file?: string;\n lookIn?: readonly string[];\n applied: readonly string[];\n changes: readonly string[];\n expected: unknown;\n};\n\nexport type SourcePlan = {\n from: Stamp;\n to: Stamp;\n migrations: readonly { ref: string; description: string }[];\n documents: readonly PlannedDocument[];\n untouched: readonly string[];\n problems: readonly string[];\n};\n\nconst keyOf = (doc: { kind: string; id: string }): string => `${doc.kind}:${doc.id}`;\n\nconst sortKeys = (value: unknown): unknown => {\n if (Array.isArray(value)) return value.map(sortKeys);\n if (typeof value !== 'object' || value === null) return value;\n return Object.fromEntries(Object.entries(value).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)).map(([k, v]) => [k, sortKeys(v)]));\n};\nconst sameJson = (a: unknown, b: unknown): boolean => JSON.stringify(sortKeys(a)) === JSON.stringify(sortKeys(b));\n\nexport const changedStrings = (before: unknown, after: unknown): string[] => {\n const found = new Set<string>();\n const visit = (a: unknown, b: unknown): void => {\n if (JSON.stringify(a) === JSON.stringify(b)) return;\n if (typeof a === 'string') {\n found.add(a);\n return;\n }\n if (Array.isArray(a)) {\n a.forEach((item, i) => visit(item, Array.isArray(b) ? b[i] : undefined));\n return;\n }\n if (typeof a === 'object' && a !== null) {\n for (const [k, v] of Object.entries(a)) visit(v, typeof b === 'object' && b !== null && !Array.isArray(b) ? Reflect.get(b, k) : undefined);\n }\n };\n visit(before, after);\n return [...found].filter((s) => s.length >= 4);\n};\n\nexport const planSourceUpgrade = async (options: {\n upgrader: Upgrader;\n stamp: Stamp;\n documents: readonly SourceDocument[];\n schemas?: Readonly<Record<string, GrammarSchema>>;\n describe: (ref: string) => string;\n}): Promise<SourcePlan> => {\n const { upgrader, stamp, documents, schemas, describe } = options;\n const seen = new Set<string>();\n const planned: PlannedDocument[] = [];\n const untouched: string[] = [];\n const problems: string[] = [];\n\n for (const doc of documents) {\n const key = keyOf(doc);\n if (seen.has(key)) throw new StrataError('INVALID_SEQUENCE', `Two artifacts are both ${key} — an artifact needs one identity to be planned.`);\n seen.add(key);\n const result = upgrader.upgrade(doc.document, { kind: doc.kind, stamp });\n if (sameJson(result.document, doc.document)) {\n untouched.push(key);\n continue;\n }\n planned.push({\n kind: doc.kind,\n id: doc.id,\n ...(doc.file === undefined ? {} : { file: doc.file }),\n applied: result.applied,\n changes: diffJson(doc.document, result.document),\n expected: result.document,\n });\n const schema = schemas?.[doc.kind];\n if (schema !== undefined) {\n const checked = await schema['~standard'].validate(result.document);\n if (checked.issues !== undefined) {\n problems.push(`${key}: the migrated artifact does not pass ${doc.kind}'s current schema — ${checked.issues.slice(0, 2).map((i) => i.message).join('; ')}`);\n }\n }\n }\n\n const from = stamp;\n const to = upgrader.stamp;\n const migrations = Object.entries(to).flatMap(([id, n]) =>\n Array.from({ length: Math.max(0, n - (from[id] ?? 0)) }, (_, i) => `${id}/${(from[id] ?? 0) + i + 1}`),\n );\n return {\n from,\n to,\n migrations: migrations.map((ref) => ({ ref, description: describe(ref) })),\n documents: planned.sort((a, b) => (keyOf(a) < keyOf(b) ? -1 : 1)),\n untouched: untouched.sort(),\n problems,\n };\n};\n\nexport type VerifyResult = {\n ok: boolean;\n lines: readonly { ok: boolean; text: string; detail?: readonly string[] }[];\n};\n\nexport const verifySourceUpgrade = (options: { plan: SourcePlan; upgrader: Upgrader; documents: readonly SourceDocument[] }): VerifyResult => {\n const { plan, upgrader, documents } = options;\n const now = new Map(documents.map((d) => [keyOf(d), d]));\n const lines: { ok: boolean; text: string; detail?: readonly string[] }[] = [];\n\n for (const want of plan.documents) {\n const key = keyOf(want);\n const got = now.get(key);\n if (got === undefined) {\n lines.push({ ok: false, text: `${key} is gone — the plan expected it rewritten, not removed` });\n } else if (sameJson(got.document, want.expected)) {\n lines.push({ ok: true, text: `${key} matches its migrated JSON` });\n } else {\n lines.push({ ok: false, text: `${key} does not match its migrated JSON yet`, detail: diffJson(got.document, want.expected, 12) });\n }\n }\n for (const key of plan.untouched) {\n const got = now.get(key);\n if (got === undefined) {\n lines.push({ ok: false, text: `${key} is gone — no migration asked for that` });\n continue;\n }\n const again = upgrader.upgrade(got.document, { kind: got.kind, stamp: plan.from });\n if (!sameJson(again.document, got.document)) {\n lines.push({ ok: false, text: `${key} was not in the plan, but the migrations would change it now`, detail: diffJson(got.document, again.document, 12) });\n }\n }\n const known = new Set([...plan.documents.map(keyOf), ...plan.untouched]);\n for (const key of now.keys()) {\n if (!known.has(key)) lines.push({ ok: false, text: `${key} is new since the plan — plan again so it is checked too` });\n }\n const ok = lines.every((l) => l.ok);\n if (ok) lines.push({ ok: true, text: `${plan.untouched.length} artifact(s) no migration touches, still untouched` });\n return { ok, lines };\n};\n\nexport const renderReport = (plan: SourcePlan, expectedPathOf: (doc: PlannedDocument) => string): string => {\n const stamp = (s: Stamp): string => Object.entries(s).map(([k, v]) => `${k} ${v}`).join(', ');\n const out: string[] = [\n '# strata upgrade',\n '',\n `The source is written at **${stamp(plan.from)}**; the installed grammars are at **${stamp(plan.to)}**.`,\n '',\n '## Migrations',\n '',\n ...plan.migrations.map((m) => `- \\`${m.ref}\\` — ${m.description}`),\n '',\n ];\n if (plan.problems.length > 0) {\n out.push('## Stop: a migration is wrong', '', 'These artifacts would not pass their current schema after migrating — no edit can make `verify` pass. Fix the migration, then plan again.', '', ...plan.problems.map((p) => `- ${p}`), '');\n }\n if (plan.documents.length === 0) {\n out.push('## Nothing to edit', '', `No artifact changes (${plan.untouched.length} checked). Run \\`verify\\` to move the lock.`, '');\n } else {\n out.push(\n `## ${plan.documents.length} artifact(s) to edit`,\n '',\n 'Edit each so that it serialises to EXACTLY its expected JSON (key order aside) — then run `verify`. Only what is listed changes; every other artifact must stay as it is.',\n '',\n );\n for (const doc of plan.documents) {\n out.push(`### \\`${doc.id}\\` (${doc.kind})`, '', doc.file === undefined ? '' : `- **File:** \\`${doc.file}\\``,\n doc.lookIn === undefined || doc.lookIn.length === 0 ? '' : `- **Look in:** ${doc.lookIn.map((f) => `\\`${f}\\``).join(', ')} — where the changing values are written`, `- **Migrations:** ${doc.applied.map((r) => `\\`${r}\\``).join(', ')}`, `- **Expected JSON:** \\`${expectedPathOf(doc)}\\``, '- **Changes:**', '', '```', ...doc.changes, '```', '');\n }\n }\n return out.filter((line, i, all) => !(line === '' && all[i - 1] === '')).join('\\n');\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/upgrade/index.ts"],"names":["StrataError","diffJson"],"mappings":";;;;;;AAyBA,IAAM,KAAA,GAAQ,CAAC,GAAA,KAA8C,CAAA,EAAG,IAAI,IAAI,CAAA,CAAA,EAAI,IAAI,EAAE,CAAA,CAAA;AAElF,IAAM,QAAA,GAAW,CAAC,KAAA,KAA4B;AAC5C,EAAA,IAAI,MAAM,OAAA,CAAQ,KAAK,GAAG,OAAO,KAAA,CAAM,IAAI,QAAQ,CAAA;AACnD,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,MAAM,OAAO,KAAA;AACxD,EAAA,OAAO,MAAA,CAAO,WAAA,CAAY,MAAA,CAAO,OAAA,CAAQ,KAAK,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AI,CAAC,MAAM,CAAA,EAAA,EAAK,CAAC,IAAI,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,6CAAA,CAAA;AAAA,QAA4C,CAAA,kBAAA,EAAqB,GAAA,CAAI,OAAA,CAAQ,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,EAAA,EAAK,CAAC,CAAA,EAAA,CAAI,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,CAAA;AAAA,QAAI,CAAA,uBAAA,EAA0B,cAAA,CAAe,GAAG,CAAC,CAAA,EAAA,CAAA;AAAA,QAAM,gBAAA;AAAA,QAAkB,EAAA;AAAA,QAAI,KAAA;AAAA,QAAO,GAAG,GAAA,CAAI,OAAA;AAAA,QAAS,KAAA;AAAA,QAAO;AAAA,OAAE;AAAA,IACxV;AAAA,EACF;AACA,EAAA,OAAO,IAAI,MAAA,CAAO,CAAC,IAAA,EAAM,CAAA,EAAG,QAAQ,EAAE,IAAA,KAAS,EAAA,IAAM,GAAA,CAAI,IAAI,CAAC,CAAA,KAAM,EAAA,CAAG,CAAA,CAAE,KAAK,IAAI,CAAA;AACpF","file":"chunk-564JCO6Q.cjs","sourcesContent":["import type { Stamp, Upgrader } from '../documents';\nimport { diffJson, type GrammarSchema } from '../check';\nimport { StrataError } from '../errors';\n\nexport type SourceDocument = { kind: string; id: string; document: unknown; file?: string };\n\nexport type PlannedDocument = {\n kind: string;\n id: string;\n file?: string;\n lookIn?: readonly string[];\n applied: readonly string[];\n changes: readonly string[];\n expected: unknown;\n};\n\nexport type SourcePlan = {\n from: Stamp;\n to: Stamp;\n migrations: readonly { ref: string; description: string }[];\n documents: readonly PlannedDocument[];\n untouched: readonly string[];\n problems: readonly string[];\n};\n\nconst keyOf = (doc: { kind: string; id: string }): string => `${doc.kind}:${doc.id}`;\n\nconst sortKeys = (value: unknown): unknown => {\n if (Array.isArray(value)) return value.map(sortKeys);\n if (typeof value !== 'object' || value === null) return value;\n return Object.fromEntries(Object.entries(value).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)).map(([k, v]) => [k, sortKeys(v)]));\n};\nconst sameJson = (a: unknown, b: unknown): boolean => JSON.stringify(sortKeys(a)) === JSON.stringify(sortKeys(b));\n\nexport const changedStrings = (before: unknown, after: unknown): string[] => {\n const found = new Set<string>();\n const visit = (a: unknown, b: unknown): void => {\n if (JSON.stringify(a) === JSON.stringify(b)) return;\n if (typeof a === 'string') {\n found.add(a);\n return;\n }\n if (Array.isArray(a)) {\n a.forEach((item, i) => visit(item, Array.isArray(b) ? b[i] : undefined));\n return;\n }\n if (typeof a === 'object' && a !== null) {\n for (const [k, v] of Object.entries(a)) visit(v, typeof b === 'object' && b !== null && !Array.isArray(b) ? Reflect.get(b, k) : undefined);\n }\n };\n visit(before, after);\n return [...found].filter((s) => s.length >= 4);\n};\n\nexport const planSourceUpgrade = async (options: {\n upgrader: Upgrader;\n stamp: Stamp;\n documents: readonly SourceDocument[];\n schemas?: Readonly<Record<string, GrammarSchema>>;\n describe: (ref: string) => string;\n}): Promise<SourcePlan> => {\n const { upgrader, stamp, documents, schemas, describe } = options;\n const seen = new Set<string>();\n const planned: PlannedDocument[] = [];\n const untouched: string[] = [];\n const problems: string[] = [];\n\n for (const doc of documents) {\n const key = keyOf(doc);\n if (seen.has(key)) throw new StrataError('INVALID_SEQUENCE', `Two artifacts are both ${key} — an artifact needs one identity to be planned.`);\n seen.add(key);\n const result = upgrader.upgrade(doc.document, { kind: doc.kind, stamp });\n if (sameJson(result.document, doc.document)) {\n untouched.push(key);\n continue;\n }\n planned.push({\n kind: doc.kind,\n id: doc.id,\n ...(doc.file === undefined ? {} : { file: doc.file }),\n applied: result.applied,\n changes: diffJson(doc.document, result.document),\n expected: result.document,\n });\n const schema = schemas?.[doc.kind];\n if (schema !== undefined) {\n const checked = await schema['~standard'].validate(result.document);\n if (checked.issues !== undefined) {\n problems.push(`${key}: the migrated artifact does not pass ${doc.kind}'s current schema — ${checked.issues.slice(0, 2).map((i) => i.message).join('; ')}`);\n }\n }\n }\n\n const from = stamp;\n const to = upgrader.stamp;\n const migrations = Object.entries(to).flatMap(([id, n]) =>\n Array.from({ length: Math.max(0, n - (from[id] ?? 0)) }, (_, i) => `${id}/${(from[id] ?? 0) + i + 1}`),\n );\n return {\n from,\n to,\n migrations: migrations.map((ref) => ({ ref, description: describe(ref) })),\n documents: planned.sort((a, b) => (keyOf(a) < keyOf(b) ? -1 : 1)),\n untouched: untouched.sort(),\n problems,\n };\n};\n\nexport type VerifyResult = {\n ok: boolean;\n lines: readonly { ok: boolean; text: string; detail?: readonly string[] }[];\n};\n\nexport const verifySourceUpgrade = (options: { plan: SourcePlan; upgrader: Upgrader; documents: readonly SourceDocument[] }): VerifyResult => {\n const { plan, upgrader, documents } = options;\n const now = new Map(documents.map((d) => [keyOf(d), d]));\n const lines: { ok: boolean; text: string; detail?: readonly string[] }[] = [];\n\n for (const want of plan.documents) {\n const key = keyOf(want);\n const got = now.get(key);\n if (got === undefined) {\n lines.push({ ok: false, text: `${key} is gone — the plan expected it rewritten, not removed` });\n } else if (sameJson(got.document, want.expected)) {\n lines.push({ ok: true, text: `${key} matches its migrated JSON` });\n } else {\n lines.push({ ok: false, text: `${key} does not match its migrated JSON yet`, detail: diffJson(got.document, want.expected, 12) });\n }\n }\n for (const key of plan.untouched) {\n const got = now.get(key);\n if (got === undefined) {\n lines.push({ ok: false, text: `${key} is gone — no migration asked for that` });\n continue;\n }\n const again = upgrader.upgrade(got.document, { kind: got.kind, stamp: plan.from });\n if (!sameJson(again.document, got.document)) {\n lines.push({ ok: false, text: `${key} was not in the plan, but the migrations would change it now`, detail: diffJson(got.document, again.document, 12) });\n }\n }\n const known = new Set([...plan.documents.map(keyOf), ...plan.untouched]);\n for (const key of now.keys()) {\n if (!known.has(key)) lines.push({ ok: false, text: `${key} is new since the plan — plan again so it is checked too` });\n }\n const ok = lines.every((l) => l.ok);\n if (ok) lines.push({ ok: true, text: `${plan.untouched.length} artifact(s) no migration touches, still untouched` });\n return { ok, lines };\n};\n\nexport const renderReport = (plan: SourcePlan, expectedPathOf: (doc: PlannedDocument) => string): string => {\n const stamp = (s: Stamp): string => Object.entries(s).map(([k, v]) => `${k} ${v}`).join(', ');\n const out: string[] = [\n '# strata upgrade',\n '',\n `The source is written at **${stamp(plan.from)}**; the installed grammars are at **${stamp(plan.to)}**.`,\n '',\n '## Migrations',\n '',\n ...plan.migrations.map((m) => `- \\`${m.ref}\\` — ${m.description}`),\n '',\n ];\n if (plan.problems.length > 0) {\n out.push('## Stop: a migration is wrong', '', 'These artifacts would not pass their current schema after migrating — no edit can make `verify` pass. Fix the migration, then plan again.', '', ...plan.problems.map((p) => `- ${p}`), '');\n }\n if (plan.documents.length === 0) {\n out.push('## Nothing to edit', '', `No artifact changes (${plan.untouched.length} checked). Run \\`verify\\` to move the lock.`, '');\n } else {\n out.push(\n `## ${plan.documents.length} artifact(s) to edit`,\n '',\n 'Edit each so that it serialises to EXACTLY its expected JSON (key order aside) — then run `verify`. Only what is listed changes; every other artifact must stay as it is.',\n '',\n );\n for (const doc of plan.documents) {\n out.push(`### \\`${doc.id}\\` (${doc.kind})`, '', doc.file === undefined ? '' : `- **File:** \\`${doc.file}\\``,\n doc.lookIn === undefined || doc.lookIn.length === 0 ? '' : `- **Look in:** ${doc.lookIn.map((f) => `\\`${f}\\``).join(', ')} — where the changing values are written`, `- **Migrations:** ${doc.applied.map((r) => `\\`${r}\\``).join(', ')}`, `- **Expected JSON:** \\`${expectedPathOf(doc)}\\``, '- **Changes:**', '', '```', ...doc.changes, '```', '');\n }\n }\n return out.filter((line, i, all) => !(line === '' && all[i - 1] === '')).join('\\n');\n};\n"]}
|
|
@@ -14,5 +14,5 @@ ${details.map((d) => ` ${d}`).join("\n")}` : message, options);
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
exports.StrataError = StrataError;
|
|
17
|
-
//# sourceMappingURL=chunk-
|
|
18
|
-
//# sourceMappingURL=chunk-
|
|
17
|
+
//# sourceMappingURL=chunk-7PBIGCLL.cjs.map
|
|
18
|
+
//# sourceMappingURL=chunk-7PBIGCLL.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts"],"names":[],"mappings":";;;AAcO,IAAM,WAAA,GAAN,cAA0B,KAAA,CAAM;AAAA,EAC5B,IAAA;AAAA,EACA,OAAA;AAAA,EAET,YAAY,IAAA,EAAuB,OAAA,EAAiB,OAAA,GAA6B,IAAI,OAAA,EAA+B;AAClH,IAAA,KAAA,CAAM,OAAA,CAAQ,MAAA,GAAS,CAAA,GAAI,CAAA,EAAG,OAAO;AAAA,EAAK,OAAA,CAAQ,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,CAAA,GAAK,SAAS,OAAO,CAAA;AACtG,IAAA,IAAA,CAAK,IAAA,GAAO,aAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AAAA,EACjB;AACF","file":"chunk-7PBIGCLL.cjs","sourcesContent":["export type StrataErrorCode =\n | 'INVALID_SEQUENCE'\n | 'EDITED'\n | 'TOO_NEW'\n | 'UNKNOWN_SEQUENCE'\n | 'UNKNOWN_DEPENDENCY'\n | 'CYCLE'\n | 'PENDING'\n | 'STEP_FAILED'\n | 'DOES_NOT_FIT'\n | 'NO_TRANSACTION'\n | 'UNKNOWN_KIND'\n | 'WRONG_OWNER';\n\nexport class StrataError extends Error {\n readonly code: StrataErrorCode;\n readonly details: readonly string[];\n\n constructor(code: StrataErrorCode, message: string, details: readonly string[] = [], options?: { cause?: unknown }) {\n super(details.length > 0 ? `${message}\\n${details.map((d) => ` ${d}`).join('\\n')}` : message, options);\n this.name = 'StrataError';\n this.code = code;\n this.details = details;\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { diffJson } from './chunk-
|
|
2
|
-
import { StrataError } from './chunk-
|
|
1
|
+
import { diffJson } from './chunk-SH6BBA2X.js';
|
|
2
|
+
import { StrataError } from './chunk-STNFHBNR.js';
|
|
3
3
|
|
|
4
4
|
// src/upgrade/index.ts
|
|
5
5
|
var keyOf = (doc) => `${doc.kind}:${doc.id}`;
|
|
@@ -152,5 +152,5 @@ var renderReport = (plan, expectedPathOf) => {
|
|
|
152
152
|
};
|
|
153
153
|
|
|
154
154
|
export { changedStrings, planSourceUpgrade, renderReport, verifySourceUpgrade };
|
|
155
|
-
//# sourceMappingURL=chunk-
|
|
156
|
-
//# sourceMappingURL=chunk-
|
|
155
|
+
//# sourceMappingURL=chunk-DGS4XJQQ.js.map
|
|
156
|
+
//# sourceMappingURL=chunk-DGS4XJQQ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/upgrade/index.ts"],"names":[],"mappings":";;;;AAyBA,IAAM,KAAA,GAAQ,CAAC,GAAA,KAA8C,CAAA,EAAG,IAAI,IAAI,CAAA,CAAA,EAAI,IAAI,EAAE,CAAA,CAAA;AAElF,IAAM,QAAA,GAAW,CAAC,KAAA,KAA4B;AAC5C,EAAA,IAAI,MAAM,OAAA,CAAQ,KAAK,GAAG,OAAO,KAAA,CAAM,IAAI,QAAQ,CAAA;AACnD,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,MAAM,OAAO,KAAA;AACxD,EAAA,OAAO,MAAA,CAAO,WAAA,CAAY,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,CAAE,IAAA,CAAK,CAAC,CAAC,CAAC,CAAA,EAAG,CAAC,CAAC,CAAA,KAAO,IAAI,CAAA,GAAI,EAAA,GAAK,CAAA,GAAI,CAAA,GAAI,CAAA,GAAI,CAAE,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,CAAA,EAAG,CAAC,CAAA,KAAM,CAAC,CAAA,EAAG,QAAA,CAAS,CAAC,CAAC,CAAC,CAAC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AAA;AAAA,QAAI,CAAA,uBAAA,EAA0B,cAAA,CAAe,GAAG,CAAC,CAAA,EAAA,CAAA;AAAA,QAAM,gBAAA;AAAA,QAAkB,EAAA;AAAA,QAAI,KAAA;AAAA,QAAO,GAAG,GAAA,CAAI,OAAA;AAAA,QAAS,KAAA;AAAA,QAAO;AAAA,OAAE;AAAA,IACxV;AAAA,EACF;AACA,EAAA,OAAO,IAAI,MAAA,CAAO,CAAC,IAAA,EAAM,CAAA,EAAG,QAAQ,EAAE,IAAA,KAAS,EAAA,IAAM,GAAA,CAAI,IAAI,CAAC,CAAA,KAAM,EAAA,CAAG,CAAA,CAAE,KAAK,IAAI,CAAA;AACpF","file":"chunk-PODP3F5N.js","sourcesContent":["import type { Stamp, Upgrader } from '../documents';\nimport { diffJson, type GrammarSchema } from '../check';\nimport { StrataError } from '../errors';\n\nexport type SourceDocument = { kind: string; id: string; document: unknown; file?: string };\n\nexport type PlannedDocument = {\n kind: string;\n id: string;\n file?: string;\n lookIn?: readonly string[];\n applied: readonly string[];\n changes: readonly string[];\n expected: unknown;\n};\n\nexport type SourcePlan = {\n from: Stamp;\n to: Stamp;\n migrations: readonly { ref: string; description: string }[];\n documents: readonly PlannedDocument[];\n untouched: readonly string[];\n problems: readonly string[];\n};\n\nconst keyOf = (doc: { kind: string; id: string }): string => `${doc.kind}:${doc.id}`;\n\nconst sortKeys = (value: unknown): unknown => {\n if (Array.isArray(value)) return value.map(sortKeys);\n if (typeof value !== 'object' || value === null) return value;\n return Object.fromEntries(Object.entries(value).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)).map(([k, v]) => [k, sortKeys(v)]));\n};\nconst sameJson = (a: unknown, b: unknown): boolean => JSON.stringify(sortKeys(a)) === JSON.stringify(sortKeys(b));\n\nexport const changedStrings = (before: unknown, after: unknown): string[] => {\n const found = new Set<string>();\n const visit = (a: unknown, b: unknown): void => {\n if (JSON.stringify(a) === JSON.stringify(b)) return;\n if (typeof a === 'string') {\n found.add(a);\n return;\n }\n if (Array.isArray(a)) {\n a.forEach((item, i) => visit(item, Array.isArray(b) ? b[i] : undefined));\n return;\n }\n if (typeof a === 'object' && a !== null) {\n for (const [k, v] of Object.entries(a)) visit(v, typeof b === 'object' && b !== null && !Array.isArray(b) ? Reflect.get(b, k) : undefined);\n }\n };\n visit(before, after);\n return [...found].filter((s) => s.length >= 4);\n};\n\nexport const planSourceUpgrade = async (options: {\n upgrader: Upgrader;\n stamp: Stamp;\n documents: readonly SourceDocument[];\n schemas?: Readonly<Record<string, GrammarSchema>>;\n describe: (ref: string) => string;\n}): Promise<SourcePlan> => {\n const { upgrader, stamp, documents, schemas, describe } = options;\n const seen = new Set<string>();\n const planned: PlannedDocument[] = [];\n const untouched: string[] = [];\n const problems: string[] = [];\n\n for (const doc of documents) {\n const key = keyOf(doc);\n if (seen.has(key)) throw new StrataError('INVALID_SEQUENCE', `Two artifacts are both ${key} — an artifact needs one identity to be planned.`);\n seen.add(key);\n const result = upgrader.upgrade(doc.document, { kind: doc.kind, stamp });\n if (sameJson(result.document, doc.document)) {\n untouched.push(key);\n continue;\n }\n planned.push({\n kind: doc.kind,\n id: doc.id,\n ...(doc.file === undefined ? {} : { file: doc.file }),\n applied: result.applied,\n changes: diffJson(doc.document, result.document),\n expected: result.document,\n });\n const schema = schemas?.[doc.kind];\n if (schema !== undefined) {\n const checked = await schema['~standard'].validate(result.document);\n if (checked.issues !== undefined) {\n problems.push(`${key}: the migrated artifact does not pass ${doc.kind}'s current schema — ${checked.issues.slice(0, 2).map((i) => i.message).join('; ')}`);\n }\n }\n }\n\n const from = stamp;\n const to = upgrader.stamp;\n const migrations = Object.entries(to).flatMap(([id, n]) =>\n Array.from({ length: Math.max(0, n - (from[id] ?? 0)) }, (_, i) => `${id}/${(from[id] ?? 0) + i + 1}`),\n );\n return {\n from,\n to,\n migrations: migrations.map((ref) => ({ ref, description: describe(ref) })),\n documents: planned.sort((a, b) => (keyOf(a) < keyOf(b) ? -1 : 1)),\n untouched: untouched.sort(),\n problems,\n };\n};\n\nexport type VerifyResult = {\n ok: boolean;\n lines: readonly { ok: boolean; text: string; detail?: readonly string[] }[];\n};\n\nexport const verifySourceUpgrade = (options: { plan: SourcePlan; upgrader: Upgrader; documents: readonly SourceDocument[] }): VerifyResult => {\n const { plan, upgrader, documents } = options;\n const now = new Map(documents.map((d) => [keyOf(d), d]));\n const lines: { ok: boolean; text: string; detail?: readonly string[] }[] = [];\n\n for (const want of plan.documents) {\n const key = keyOf(want);\n const got = now.get(key);\n if (got === undefined) {\n lines.push({ ok: false, text: `${key} is gone — the plan expected it rewritten, not removed` });\n } else if (sameJson(got.document, want.expected)) {\n lines.push({ ok: true, text: `${key} matches its migrated JSON` });\n } else {\n lines.push({ ok: false, text: `${key} does not match its migrated JSON yet`, detail: diffJson(got.document, want.expected, 12) });\n }\n }\n for (const key of plan.untouched) {\n const got = now.get(key);\n if (got === undefined) {\n lines.push({ ok: false, text: `${key} is gone — no migration asked for that` });\n continue;\n }\n const again = upgrader.upgrade(got.document, { kind: got.kind, stamp: plan.from });\n if (!sameJson(again.document, got.document)) {\n lines.push({ ok: false, text: `${key} was not in the plan, but the migrations would change it now`, detail: diffJson(got.document, again.document, 12) });\n }\n }\n const known = new Set([...plan.documents.map(keyOf), ...plan.untouched]);\n for (const key of now.keys()) {\n if (!known.has(key)) lines.push({ ok: false, text: `${key} is new since the plan — plan again so it is checked too` });\n }\n const ok = lines.every((l) => l.ok);\n if (ok) lines.push({ ok: true, text: `${plan.untouched.length} artifact(s) no migration touches, still untouched` });\n return { ok, lines };\n};\n\nexport const renderReport = (plan: SourcePlan, expectedPathOf: (doc: PlannedDocument) => string): string => {\n const stamp = (s: Stamp): string => Object.entries(s).map(([k, v]) => `${k} ${v}`).join(', ');\n const out: string[] = [\n '# strata upgrade',\n '',\n `The source is written at **${stamp(plan.from)}**; the installed grammars are at **${stamp(plan.to)}**.`,\n '',\n '## Migrations',\n '',\n ...plan.migrations.map((m) => `- \\`${m.ref}\\` — ${m.description}`),\n '',\n ];\n if (plan.problems.length > 0) {\n out.push('## Stop: a migration is wrong', '', 'These artifacts would not pass their current schema after migrating — no edit can make `verify` pass. Fix the migration, then plan again.', '', ...plan.problems.map((p) => `- ${p}`), '');\n }\n if (plan.documents.length === 0) {\n out.push('## Nothing to edit', '', `No artifact changes (${plan.untouched.length} checked). Run \\`verify\\` to move the lock.`, '');\n } else {\n out.push(\n `## ${plan.documents.length} artifact(s) to edit`,\n '',\n 'Edit each so that it serialises to EXACTLY its expected JSON (key order aside) — then run `verify`. Only what is listed changes; every other artifact must stay as it is.',\n '',\n );\n for (const doc of plan.documents) {\n out.push(`### \\`${doc.id}\\` (${doc.kind})`, '', doc.file === undefined ? '' : `- **File:** \\`${doc.file}\\``,\n doc.lookIn === undefined || doc.lookIn.length === 0 ? '' : `- **Look in:** ${doc.lookIn.map((f) => `\\`${f}\\``).join(', ')} — where the changing values are written`, `- **Migrations:** ${doc.applied.map((r) => `\\`${r}\\``).join(', ')}`, `- **Expected JSON:** \\`${expectedPathOf(doc)}\\``, '- **Changes:**', '', '```', ...doc.changes, '```', '');\n }\n }\n return out.filter((line, i, all) => !(line === '' && all[i - 1] === '')).join('\\n');\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/upgrade/index.ts"],"names":[],"mappings":";;;;AAyBA,IAAM,KAAA,GAAQ,CAAC,GAAA,KAA8C,CAAA,EAAG,IAAI,IAAI,CAAA,CAAA,EAAI,IAAI,EAAE,CAAA,CAAA;AAElF,IAAM,QAAA,GAAW,CAAC,KAAA,KAA4B;AAC5C,EAAA,IAAI,MAAM,OAAA,CAAQ,KAAK,GAAG,OAAO,KAAA,CAAM,IAAI,QAAQ,CAAA;AACnD,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,MAAM,OAAO,KAAA;AACxD,EAAA,OAAO,MAAA,CAAO,WAAA,CAAY,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,CAAE,IAAA,CAAK,CAAC,C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C,IAAI,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,6CAAA,CAAA;AAAA,QAA4C,CAAA,kBAAA,EAAqB,GAAA,CAAI,OAAA,CAAQ,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,EAAA,EAAK,CAAC,CAAA,EAAA,CAAI,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,CAAA;AAAA,QAAI,CAAA,uBAAA,EAA0B,cAAA,CAAe,GAAG,CAAC,CAAA,EAAA,CAAA;AAAA,QAAM,gBAAA;AAAA,QAAkB,EAAA;AAAA,QAAI,KAAA;AAAA,QAAO,GAAG,GAAA,CAAI,OAAA;AAAA,QAAS,KAAA;AAAA,QAAO;AAAA,OAAE;AAAA,IACxV;AAAA,EACF;AACA,EAAA,OAAO,IAAI,MAAA,CAAO,CAAC,IAAA,EAAM,CAAA,EAAG,QAAQ,EAAE,IAAA,KAAS,EAAA,IAAM,GAAA,CAAI,IAAI,CAAC,CAAA,KAAM,EAAA,CAAG,CAAA,CAAE,KAAK,IAAI,CAAA;AACpF","file":"chunk-DGS4XJQQ.js","sourcesContent":["import type { Stamp, Upgrader } from '../documents';\nimport { diffJson, type GrammarSchema } from '../check';\nimport { StrataError } from '../errors';\n\nexport type SourceDocument = { kind: string; id: string; document: unknown; file?: string };\n\nexport type PlannedDocument = {\n kind: string;\n id: string;\n file?: string;\n lookIn?: readonly string[];\n applied: readonly string[];\n changes: readonly string[];\n expected: unknown;\n};\n\nexport type SourcePlan = {\n from: Stamp;\n to: Stamp;\n migrations: readonly { ref: string; description: string }[];\n documents: readonly PlannedDocument[];\n untouched: readonly string[];\n problems: readonly string[];\n};\n\nconst keyOf = (doc: { kind: string; id: string }): string => `${doc.kind}:${doc.id}`;\n\nconst sortKeys = (value: unknown): unknown => {\n if (Array.isArray(value)) return value.map(sortKeys);\n if (typeof value !== 'object' || value === null) return value;\n return Object.fromEntries(Object.entries(value).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)).map(([k, v]) => [k, sortKeys(v)]));\n};\nconst sameJson = (a: unknown, b: unknown): boolean => JSON.stringify(sortKeys(a)) === JSON.stringify(sortKeys(b));\n\nexport const changedStrings = (before: unknown, after: unknown): string[] => {\n const found = new Set<string>();\n const visit = (a: unknown, b: unknown): void => {\n if (JSON.stringify(a) === JSON.stringify(b)) return;\n if (typeof a === 'string') {\n found.add(a);\n return;\n }\n if (Array.isArray(a)) {\n a.forEach((item, i) => visit(item, Array.isArray(b) ? b[i] : undefined));\n return;\n }\n if (typeof a === 'object' && a !== null) {\n for (const [k, v] of Object.entries(a)) visit(v, typeof b === 'object' && b !== null && !Array.isArray(b) ? Reflect.get(b, k) : undefined);\n }\n };\n visit(before, after);\n return [...found].filter((s) => s.length >= 4);\n};\n\nexport const planSourceUpgrade = async (options: {\n upgrader: Upgrader;\n stamp: Stamp;\n documents: readonly SourceDocument[];\n schemas?: Readonly<Record<string, GrammarSchema>>;\n describe: (ref: string) => string;\n}): Promise<SourcePlan> => {\n const { upgrader, stamp, documents, schemas, describe } = options;\n const seen = new Set<string>();\n const planned: PlannedDocument[] = [];\n const untouched: string[] = [];\n const problems: string[] = [];\n\n for (const doc of documents) {\n const key = keyOf(doc);\n if (seen.has(key)) throw new StrataError('INVALID_SEQUENCE', `Two artifacts are both ${key} — an artifact needs one identity to be planned.`);\n seen.add(key);\n const result = upgrader.upgrade(doc.document, { kind: doc.kind, stamp });\n if (sameJson(result.document, doc.document)) {\n untouched.push(key);\n continue;\n }\n planned.push({\n kind: doc.kind,\n id: doc.id,\n ...(doc.file === undefined ? {} : { file: doc.file }),\n applied: result.applied,\n changes: diffJson(doc.document, result.document),\n expected: result.document,\n });\n const schema = schemas?.[doc.kind];\n if (schema !== undefined) {\n const checked = await schema['~standard'].validate(result.document);\n if (checked.issues !== undefined) {\n problems.push(`${key}: the migrated artifact does not pass ${doc.kind}'s current schema — ${checked.issues.slice(0, 2).map((i) => i.message).join('; ')}`);\n }\n }\n }\n\n const from = stamp;\n const to = upgrader.stamp;\n const migrations = Object.entries(to).flatMap(([id, n]) =>\n Array.from({ length: Math.max(0, n - (from[id] ?? 0)) }, (_, i) => `${id}/${(from[id] ?? 0) + i + 1}`),\n );\n return {\n from,\n to,\n migrations: migrations.map((ref) => ({ ref, description: describe(ref) })),\n documents: planned.sort((a, b) => (keyOf(a) < keyOf(b) ? -1 : 1)),\n untouched: untouched.sort(),\n problems,\n };\n};\n\nexport type VerifyResult = {\n ok: boolean;\n lines: readonly { ok: boolean; text: string; detail?: readonly string[] }[];\n};\n\nexport const verifySourceUpgrade = (options: { plan: SourcePlan; upgrader: Upgrader; documents: readonly SourceDocument[] }): VerifyResult => {\n const { plan, upgrader, documents } = options;\n const now = new Map(documents.map((d) => [keyOf(d), d]));\n const lines: { ok: boolean; text: string; detail?: readonly string[] }[] = [];\n\n for (const want of plan.documents) {\n const key = keyOf(want);\n const got = now.get(key);\n if (got === undefined) {\n lines.push({ ok: false, text: `${key} is gone — the plan expected it rewritten, not removed` });\n } else if (sameJson(got.document, want.expected)) {\n lines.push({ ok: true, text: `${key} matches its migrated JSON` });\n } else {\n lines.push({ ok: false, text: `${key} does not match its migrated JSON yet`, detail: diffJson(got.document, want.expected, 12) });\n }\n }\n for (const key of plan.untouched) {\n const got = now.get(key);\n if (got === undefined) {\n lines.push({ ok: false, text: `${key} is gone — no migration asked for that` });\n continue;\n }\n const again = upgrader.upgrade(got.document, { kind: got.kind, stamp: plan.from });\n if (!sameJson(again.document, got.document)) {\n lines.push({ ok: false, text: `${key} was not in the plan, but the migrations would change it now`, detail: diffJson(got.document, again.document, 12) });\n }\n }\n const known = new Set([...plan.documents.map(keyOf), ...plan.untouched]);\n for (const key of now.keys()) {\n if (!known.has(key)) lines.push({ ok: false, text: `${key} is new since the plan — plan again so it is checked too` });\n }\n const ok = lines.every((l) => l.ok);\n if (ok) lines.push({ ok: true, text: `${plan.untouched.length} artifact(s) no migration touches, still untouched` });\n return { ok, lines };\n};\n\nexport const renderReport = (plan: SourcePlan, expectedPathOf: (doc: PlannedDocument) => string): string => {\n const stamp = (s: Stamp): string => Object.entries(s).map(([k, v]) => `${k} ${v}`).join(', ');\n const out: string[] = [\n '# strata upgrade',\n '',\n `The source is written at **${stamp(plan.from)}**; the installed grammars are at **${stamp(plan.to)}**.`,\n '',\n '## Migrations',\n '',\n ...plan.migrations.map((m) => `- \\`${m.ref}\\` — ${m.description}`),\n '',\n ];\n if (plan.problems.length > 0) {\n out.push('## Stop: a migration is wrong', '', 'These artifacts would not pass their current schema after migrating — no edit can make `verify` pass. Fix the migration, then plan again.', '', ...plan.problems.map((p) => `- ${p}`), '');\n }\n if (plan.documents.length === 0) {\n out.push('## Nothing to edit', '', `No artifact changes (${plan.untouched.length} checked). Run \\`verify\\` to move the lock.`, '');\n } else {\n out.push(\n `## ${plan.documents.length} artifact(s) to edit`,\n '',\n 'Edit each so that it serialises to EXACTLY its expected JSON (key order aside) — then run `verify`. Only what is listed changes; every other artifact must stay as it is.',\n '',\n );\n for (const doc of plan.documents) {\n out.push(`### \\`${doc.id}\\` (${doc.kind})`, '', doc.file === undefined ? '' : `- **File:** \\`${doc.file}\\``,\n doc.lookIn === undefined || doc.lookIn.length === 0 ? '' : `- **Look in:** ${doc.lookIn.map((f) => `\\`${f}\\``).join(', ')} — where the changing values are written`, `- **Migrations:** ${doc.applied.map((r) => `\\`${r}\\``).join(', ')}`, `- **Expected JSON:** \\`${expectedPathOf(doc)}\\``, '- **Changes:**', '', '```', ...doc.changes, '```', '');\n }\n }\n return out.filter((line, i, all) => !(line === '' && all[i - 1] === '')).join('\\n');\n};\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { prepare, orderPending } from './chunk-
|
|
2
|
-
import { StrataError } from './chunk-
|
|
1
|
+
import { prepare, orderPending } from './chunk-PAMQMFBK.js';
|
|
2
|
+
import { StrataError } from './chunk-STNFHBNR.js';
|
|
3
3
|
|
|
4
4
|
// src/documents.ts
|
|
5
5
|
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -130,5 +130,5 @@ var createUpgrader = async (sequences, options) => {
|
|
|
130
130
|
};
|
|
131
131
|
|
|
132
132
|
export { createUpgrader };
|
|
133
|
-
//# sourceMappingURL=chunk-
|
|
134
|
-
//# sourceMappingURL=chunk-
|
|
133
|
+
//# sourceMappingURL=chunk-FNMGVPSA.js.map
|
|
134
|
+
//# sourceMappingURL=chunk-FNMGVPSA.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/documents.ts"],"names":[],"mappings":";;;;AAuBA,IAAM,QAAA,GAAW,CAAC,KAAA,KAChB,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,IAAA,IAAQ,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA;AAErE,IAAM,QAAA,GAAW,CAAC,IAAA,KAChB,IAAA,CAAK,MAAA,CAAe,CAAC,IAAA,EAAM,GAAA,KAAS,OAAO,GAAA,KAAQ,QAAA,GAAW,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA,CAAA,GAAM,IAAA,KAAS,EAAA,GAAK,GAAA,GAAM,GAAG,IAAI,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA,EAAK,EAAE,CAAA;AAE7H,IAAM,KAAA,GAAQ,CAAC,KAAA,EAAgB,OAAA,KAAqE;AAClG,EAAA,IAAI,WAA4D,CAAC,EAAE,MAAM,EAAC,EAAG,OAAO,CAAA;AACpF,EAAA,KAAA,MAAW,OAAA,IAAW,OAAA,CAAQ,KAAA,CAAM,GAAG,CAAA,EAAG;AACxC,IAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,QAAA,CAAS,IAAI,CAAA;AACnC,IAAA,MAAM,MAAM,KAAA,GAAQ,OAAA,CAAQ,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA,GAAI,OAAA;AAC3C,IAAA,MAAM,OAAwD,EAAC;AAC/D,IAAA,KAAA,MAAW,MAAM,QAAA,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MAAA,CAAO,SAAS;AAAA,WAC7D,CAAA;AAAA,QACH;AACA,QAAA,MAAM,IAAA,GAAO,KAAA,CAAM,OAAA,EAAS,MAAA,CAAO,MAAM,SAAS,CAAA;AAClD,QAAA,IAAI,QAAA,CAAS,IAAI,CAAA,EAAG,OAAA,GAAU,IAAA;AAAA,MAChC;AAAA,IACF,CAAA;AACA,IAAA,KAAA,MAAW,aAAa,OAAA,EAAS;AAC/B,MAAA,KAAA,MAAW,IAAA,IAAQ,SAAA,CAAU,KAAA,EAAO,IAAI,IAAA,CAAK,IAAA,KAAS,UAAA,EAAY,OAAA,CAAQ,SAAA,EAAW,IAAA,CAAK,EAAA,EAAI,IAAA,CAAK,SAAS,CAAA;AAC5G,MAAA,OAAA,CAAQ,IAAA,CAAK,UAAU,GAAG,CAAA;AAAA,IAC5B;AACA,IAAA,OAAO,EAAE,QAAA,EAAU,OAAA,EAAS,OAAO,UAAA,CAAW,KAAK,GAAG,OAAA,EAAQ;AAAA,EAChE,CAAA;AAEA,EAAA,OAAO,EAAE,KAAA,EAAO,OAAA,EAAS,MAAA,EAAQ,MAAA,EAAO;AAC1C","file":"chunk-D42CQI2X.js","sourcesContent":["import { prepare, orderPending, type PreparedMigration, type PreparedSequence } from './plan';\nimport type { DocumentKind, Sequence } from './schema';\nimport { StrataError } from './errors';\n\nexport type Stamp = Readonly<Record<string, number>>;\n\nexport type Location = { path: readonly (string | number)[]; kind: string; value: Record<string, unknown> };\n\nexport type Transform = (config: unknown, source: unknown) => unknown;\n\nexport type UpgradeResult = {\n document: Record<string, unknown>;\n stamp: Stamp;\n applied: readonly string[];\n};\n\nexport type Upgrader = {\n stamp: Stamp;\n upgrade: (document: unknown, options: { kind: string; stamp?: Stamp | null }) => UpgradeResult;\n locate: (document: unknown, kind: string) => Location[];\n behind: (stamp: Stamp | null | undefined) => boolean;\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst pathText = (path: readonly (string | number)[]): string =>\n path.reduce<string>((text, key) => (typeof key === 'number' ? `${text}[${key}]` : text === '' ? key : `${text}.${key}`), '');\n\nconst reach = (value: unknown, pattern: string): { path: (string | number)[]; value: unknown }[] => {\n let frontier: { path: (string | number)[]; value: unknown }[] = [{ path: [], value }];\n for (const segment of pattern.split('.')) {\n const array = segment.endsWith('[]');\n const key = array ? segment.slice(0, -2) : segment;\n const next: { path: (string | number)[]; value: unknown }[] = [];\n for (const at of frontier) {\n if (!isRecord(at.value)) continue;\n const found: { path: (string | number)[]; value: unknown }[] =\n key === '*'\n ? Object.entries(at.value).map(([k, v]) => ({ path: [...at.path, k], value: v }))\n : key in at.value\n ? [{ path: [...at.path, key], value: at.value[key] }]\n : [];\n for (const f of found) {\n if (!array) next.push(f);\n else if (Array.isArray(f.value)) f.value.forEach((item, i) => next.push({ path: [...f.path, i], value: item }));\n }\n }\n frontier = next;\n }\n return frontier;\n};\n\nconst getAt = (root: unknown, path: readonly (string | number)[]): unknown =>\n path.reduce<unknown>((at, key) => {\n if (typeof key === 'number') return Array.isArray(at) ? at[key] : undefined;\n return isRecord(at) ? at[key] : undefined;\n }, root);\n\nconst setAt = (root: unknown, path: readonly (string | number)[], value: unknown): unknown => {\n const [head, ...rest] = path;\n if (head === undefined) return value;\n if (typeof head === 'number' && Array.isArray(root)) return root.map((item, i) => (i === head ? setAt(item, rest, value) : item));\n if (typeof head === 'string' && isRecord(root)) return { ...root, [head]: setAt(root[head], rest, value) };\n return root;\n};\n\nexport const createUpgrader = async (sequences: readonly Sequence[], options: { transform: Transform }): Promise<Upgrader> => {\n const prepared = await prepare(sequences);\n const tables = prepared.filter((s) => !s.grammar);\n if (tables.length > 0) {\n throw new StrataError(\n 'WRONG_OWNER',\n 'Documents are upgraded by grammar sequences; these own tables and belong to a database\\'s ledger (`migrate`). If one of them is a grammar, declare its `documents` — a sequence with no `documents` and no document step is read as owning tables.',\n tables.map((s) => s.id),\n );\n }\n const grammars: readonly PreparedSequence[] = prepared;\n\n const kinds = new Map<string, DocumentKind>();\n for (const sequence of grammars) {\n for (const [name, kind] of Object.entries(sequence.documents)) kinds.set(`${sequence.id}/${name}`, kind);\n }\n const unknown = [\n ...grammars.flatMap((s) => s.migrations.flatMap((m) => m.steps.flatMap((step) => (step.kind === 'document' && !kinds.has(step.at) ? [`${m.ref} rewrites ${step.at}`] : [])))),\n ...[...kinds].flatMap(([ref, kind]) => Object.entries(kind.embeds ?? {}).flatMap(([path, target]) => (kinds.has(target) ? [] : [`${ref} embeds ${target} at ${path}`]))),\n ];\n if (unknown.length > 0) throw new StrataError('UNKNOWN_KIND', 'A document kind is named that no sequence declares.', unknown);\n\n const stamp: Stamp = Object.fromEntries(grammars.map((s) => [s.id, s.migrations.length]));\n\n // The document's entries for grammars this code was not given are kept:\n // dropping them would let code that has the grammar run its migrations over\n // the document a second time.\n const ownIds = new Set(grammars.map((s) => s.id));\n const stampAfter = (given: Stamp | null | undefined): Stamp => {\n const others = Object.entries(given ?? {}).filter(([id]) => !ownIds.has(id));\n return others.length === 0 ? stamp : { ...stamp, ...Object.fromEntries(others) };\n };\n\n const locate = (document: unknown, kind: string): Location[] => {\n if (!kinds.has(kind)) throw new StrataError('UNKNOWN_KIND', `No sequence declares the document kind \"${kind}\".`, [...kinds.keys()]);\n const found: Location[] = [];\n const visit = (value: unknown, at: string, path: (string | number)[]): void => {\n if (!isRecord(value)) return;\n found.push({ path, kind: at, value });\n for (const [pattern, target] of Object.entries(kinds.get(at)?.embeds ?? {})) {\n for (const hit of reach(value, pattern)) visit(hit.value, target, [...path, ...hit.path]);\n }\n };\n visit(document, kind, []);\n return found;\n };\n\n const positionOf = (given: Stamp | null | undefined, id: string): number => given?.[id] ?? 0;\n\n const behind = (given: Stamp | null | undefined): boolean => {\n const ahead = grammars.filter((s) => positionOf(given, s.id) > s.migrations.length);\n if (ahead.length > 0) {\n throw new StrataError(\n 'TOO_NEW',\n 'This document was written by newer code than this — reading it would be guessing.',\n ahead.map((s) => `${s.id}: the document is at ${positionOf(given, s.id)}, this code knows ${s.migrations.length}`),\n );\n }\n return grammars.some((s) => positionOf(given, s.id) < s.migrations.length);\n };\n\n const upgrade = (document: unknown, { kind, stamp: given }: { kind: string; stamp?: Stamp | null }): UpgradeResult => {\n if (!isRecord(document)) throw new StrataError('STEP_FAILED', `A ${kind} document must be a JSON object.`);\n if (!kinds.has(kind)) throw new StrataError('UNKNOWN_KIND', `No sequence declares the document kind \"${kind}\".`, [...kinds.keys()]);\n if (!behind(given)) return { document, stamp: stampAfter(given), applied: [] };\n\n const done = new Set(grammars.flatMap((s) => s.migrations.filter((m) => m.n <= positionOf(given, s.id)).map((m) => m.ref)));\n const { pending, stuck } = orderPending(\n grammars.map((s) => ({ waiting: s.migrations.filter((m) => !done.has(m.ref)) })),\n done,\n );\n if (stuck.length > 0) throw new StrataError('CYCLE', 'Document migrations wait on each other and can never run.', stuck.map((m) => m.ref));\n\n let current: Record<string, unknown> = document;\n const applied: string[] = [];\n const runStep = (migration: PreparedMigration, at: string, transform: unknown): void => {\n // Deepest first: a parent's rewrite sees its children already rewritten,\n // and replacing a child never moves the path to its parent.\n const targets = locate(current, kind)\n .filter((l) => l.kind === at)\n .sort((a, b) => b.path.length - a.path.length);\n for (const target of targets) {\n // Read from `current`, not `target.value`: a child rewritten a moment\n // ago lives in `current`, and the parent must see and keep it.\n const value = getAt(current, target.path);\n let rewritten: unknown;\n try {\n rewritten = options.transform(transform, { document: value, path: pathText(target.path) });\n } catch (cause) {\n throw new StrataError(\n 'STEP_FAILED',\n `${migration.ref} (\"${migration.description}\") failed on the ${at} at ${pathText(target.path) || '(root)'}.`,\n [cause instanceof Error ? cause.message : String(cause)],\n { cause },\n );\n }\n if (!isRecord(rewritten)) {\n throw new StrataError('STEP_FAILED', `${migration.ref} turned the ${at} at ${pathText(target.path) || '(root)'} into something that is not a document.`, [\n JSON.stringify(rewritten)?.slice(0, 200) ?? String(rewritten),\n ]);\n }\n const next = setAt(current, target.path, rewritten);\n if (isRecord(next)) current = next;\n }\n };\n for (const migration of pending) {\n for (const step of migration.steps) if (step.kind === 'document') runStep(migration, step.at, step.transform);\n applied.push(migration.ref);\n }\n return { document: current, stamp: stampAfter(given), applied };\n };\n\n return { stamp, upgrade, locate, behind };\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/documents.ts"],"names":[],"mappings":";;;;AAuBA,IAAM,QAAA,GAAW,CAAC,KAAA,KAChB,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,IAAA,IAAQ,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA;AAErE,IAAM,QAAA,GAAW,CAAC,IAAA,KAChB,IAAA,CAAK,MAAA,CAAe,CAAC,IAAA,EAAM,GAAA,KAAS,OAAO,GAAA,KAAQ,QAAA,GAAW,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA,CAAA,GAAM,IAAA,KAAS,EAAA,GAAK,GAAA,GAAM,GAAG,IAAI,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA,EAAK,EAAE,CAAA;AAE7H,IAAM,KAAA,GAAQ,CAAC,KAAA,EAAgB,OAAA,KAAqE;AAClG,EAAA,IAAI,WAA4D,CAAC,EAAE,MAAM,EAAC,EAAG,OAAO,CAAA;AACpF,EAAA,KAAA,MAAW,OAAA,IAAW,OAAA,CAAQ,KAAA,CAAM,GAAG,CAAA,EAAG;AACxC,IAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,QAAA,CAAS,IAAI,CAAA;AACnC,IAAA,MAAM,MAAM,KAAA,GAAQ,OAAA,CAAQ,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA,GAAI,OAAA;AAC3C,IAAA,MAAM,OAAwD,EAAC;AAC/D,IAAA,KAAA,MAAW,MAAM,QAAA,EAAU;AACzB,MAAA,IAAI,CAAC,QAAA,CAAS,EAAA,CAAG,KAAK,CAAA,EAAG;AACzB,MAAA,MAAM,KAAA,GACJ,QAAQ,GAAA,GACJ,MAAA,C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A;AAClD,QAAA,IAAI,QAAA,CAAS,IAAI,CAAA,EAAG,OAAA,GAAU,IAAA;AAAA,MAChC;AAAA,IACF,CAAA;AACA,IAAA,KAAA,MAAW,aAAa,OAAA,EAAS;AAC/B,MAAA,KAAA,MAAW,IAAA,IAAQ,SAAA,CAAU,KAAA,EAAO,IAAI,IAAA,CAAK,IAAA,KAAS,UAAA,EAAY,OAAA,CAAQ,SAAA,EAAW,IAAA,CAAK,EAAA,EAAI,IAAA,CAAK,SAAS,CAAA;AAC5G,MAAA,OAAA,CAAQ,IAAA,CAAK,UAAU,GAAG,CAAA;AAAA,IAC5B;AACA,IAAA,OAAO,EAAE,QAAA,EAAU,OAAA,EAAS,OAAO,UAAA,CAAW,KAAK,GAAG,OAAA,EAAQ;AAAA,EAChE,CAAA;AAEA,EAAA,OAAO,EAAE,KAAA,EAAO,OAAA,EAAS,MAAA,EAAQ,MAAA,EAAO;AAC1C","file":"chunk-FNMGVPSA.js","sourcesContent":["import { prepare, orderPending, type PreparedMigration, type PreparedSequence } from './plan';\nimport type { DocumentKind, Sequence } from './schema';\nimport { StrataError } from './errors';\n\nexport type Stamp = Readonly<Record<string, number>>;\n\nexport type Location = { path: readonly (string | number)[]; kind: string; value: Record<string, unknown> };\n\nexport type Transform = (config: unknown, source: unknown) => unknown;\n\nexport type UpgradeResult = {\n document: Record<string, unknown>;\n stamp: Stamp;\n applied: readonly string[];\n};\n\nexport type Upgrader = {\n stamp: Stamp;\n upgrade: (document: unknown, options: { kind: string; stamp?: Stamp | null }) => UpgradeResult;\n locate: (document: unknown, kind: string) => Location[];\n behind: (stamp: Stamp | null | undefined) => boolean;\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst pathText = (path: readonly (string | number)[]): string =>\n path.reduce<string>((text, key) => (typeof key === 'number' ? `${text}[${key}]` : text === '' ? key : `${text}.${key}`), '');\n\nconst reach = (value: unknown, pattern: string): { path: (string | number)[]; value: unknown }[] => {\n let frontier: { path: (string | number)[]; value: unknown }[] = [{ path: [], value }];\n for (const segment of pattern.split('.')) {\n const array = segment.endsWith('[]');\n const key = array ? segment.slice(0, -2) : segment;\n const next: { path: (string | number)[]; value: unknown }[] = [];\n for (const at of frontier) {\n if (!isRecord(at.value)) continue;\n const found: { path: (string | number)[]; value: unknown }[] =\n key === '*'\n ? Object.entries(at.value).map(([k, v]) => ({ path: [...at.path, k], value: v }))\n : key in at.value\n ? [{ path: [...at.path, key], value: at.value[key] }]\n : [];\n for (const f of found) {\n if (!array) next.push(f);\n else if (Array.isArray(f.value)) f.value.forEach((item, i) => next.push({ path: [...f.path, i], value: item }));\n }\n }\n frontier = next;\n }\n return frontier;\n};\n\nconst getAt = (root: unknown, path: readonly (string | number)[]): unknown =>\n path.reduce<unknown>((at, key) => {\n if (typeof key === 'number') return Array.isArray(at) ? at[key] : undefined;\n return isRecord(at) ? at[key] : undefined;\n }, root);\n\nconst setAt = (root: unknown, path: readonly (string | number)[], value: unknown): unknown => {\n const [head, ...rest] = path;\n if (head === undefined) return value;\n if (typeof head === 'number' && Array.isArray(root)) return root.map((item, i) => (i === head ? setAt(item, rest, value) : item));\n if (typeof head === 'string' && isRecord(root)) return { ...root, [head]: setAt(root[head], rest, value) };\n return root;\n};\n\nexport const createUpgrader = async (sequences: readonly Sequence[], options: { transform: Transform }): Promise<Upgrader> => {\n const prepared = await prepare(sequences);\n const tables = prepared.filter((s) => !s.grammar);\n if (tables.length > 0) {\n throw new StrataError(\n 'WRONG_OWNER',\n 'Documents are upgraded by grammar sequences; these own tables and belong to a database\\'s ledger (`migrate`). If one of them is a grammar, declare its `documents` — a sequence with no `documents` and no document step is read as owning tables.',\n tables.map((s) => s.id),\n );\n }\n const grammars: readonly PreparedSequence[] = prepared;\n\n const kinds = new Map<string, DocumentKind>();\n for (const sequence of grammars) {\n for (const [name, kind] of Object.entries(sequence.documents)) kinds.set(`${sequence.id}/${name}`, kind);\n }\n const unknown = [\n ...grammars.flatMap((s) => s.migrations.flatMap((m) => m.steps.flatMap((step) => (step.kind === 'document' && !kinds.has(step.at) ? [`${m.ref} rewrites ${step.at}`] : [])))),\n ...[...kinds].flatMap(([ref, kind]) => Object.entries(kind.embeds ?? {}).flatMap(([path, target]) => (kinds.has(target) ? [] : [`${ref} embeds ${target} at ${path}`]))),\n ];\n if (unknown.length > 0) throw new StrataError('UNKNOWN_KIND', 'A document kind is named that no sequence declares.', unknown);\n\n const stamp: Stamp = Object.fromEntries(grammars.map((s) => [s.id, s.migrations.length]));\n\n // The document's entries for grammars this code was not given are kept:\n // dropping them would let code that has the grammar run its migrations over\n // the document a second time.\n const ownIds = new Set(grammars.map((s) => s.id));\n const stampAfter = (given: Stamp | null | undefined): Stamp => {\n const others = Object.entries(given ?? {}).filter(([id]) => !ownIds.has(id));\n return others.length === 0 ? stamp : { ...stamp, ...Object.fromEntries(others) };\n };\n\n const locate = (document: unknown, kind: string): Location[] => {\n if (!kinds.has(kind)) throw new StrataError('UNKNOWN_KIND', `No sequence declares the document kind \"${kind}\".`, [...kinds.keys()]);\n const found: Location[] = [];\n const visit = (value: unknown, at: string, path: (string | number)[]): void => {\n if (!isRecord(value)) return;\n found.push({ path, kind: at, value });\n for (const [pattern, target] of Object.entries(kinds.get(at)?.embeds ?? {})) {\n for (const hit of reach(value, pattern)) visit(hit.value, target, [...path, ...hit.path]);\n }\n };\n visit(document, kind, []);\n return found;\n };\n\n const positionOf = (given: Stamp | null | undefined, id: string): number => given?.[id] ?? 0;\n\n const behind = (given: Stamp | null | undefined): boolean => {\n const ahead = grammars.filter((s) => positionOf(given, s.id) > s.migrations.length);\n if (ahead.length > 0) {\n throw new StrataError(\n 'TOO_NEW',\n 'This document was written by newer code than this — reading it would be guessing.',\n ahead.map((s) => `${s.id}: the document is at ${positionOf(given, s.id)}, this code knows ${s.migrations.length}`),\n );\n }\n return grammars.some((s) => positionOf(given, s.id) < s.migrations.length);\n };\n\n const upgrade = (document: unknown, { kind, stamp: given }: { kind: string; stamp?: Stamp | null }): UpgradeResult => {\n if (!isRecord(document)) throw new StrataError('STEP_FAILED', `A ${kind} document must be a JSON object.`);\n if (!kinds.has(kind)) throw new StrataError('UNKNOWN_KIND', `No sequence declares the document kind \"${kind}\".`, [...kinds.keys()]);\n if (!behind(given)) return { document, stamp: stampAfter(given), applied: [] };\n\n const done = new Set(grammars.flatMap((s) => s.migrations.filter((m) => m.n <= positionOf(given, s.id)).map((m) => m.ref)));\n const { pending, stuck } = orderPending(\n grammars.map((s) => ({ waiting: s.migrations.filter((m) => !done.has(m.ref)) })),\n done,\n );\n if (stuck.length > 0) throw new StrataError('CYCLE', 'Document migrations wait on each other and can never run.', stuck.map((m) => m.ref));\n\n let current: Record<string, unknown> = document;\n const applied: string[] = [];\n const runStep = (migration: PreparedMigration, at: string, transform: unknown): void => {\n // Deepest first: a parent's rewrite sees its children already rewritten,\n // and replacing a child never moves the path to its parent.\n const targets = locate(current, kind)\n .filter((l) => l.kind === at)\n .sort((a, b) => b.path.length - a.path.length);\n for (const target of targets) {\n // Read from `current`, not `target.value`: a child rewritten a moment\n // ago lives in `current`, and the parent must see and keep it.\n const value = getAt(current, target.path);\n let rewritten: unknown;\n try {\n rewritten = options.transform(transform, { document: value, path: pathText(target.path) });\n } catch (cause) {\n throw new StrataError(\n 'STEP_FAILED',\n `${migration.ref} (\"${migration.description}\") failed on the ${at} at ${pathText(target.path) || '(root)'}.`,\n [cause instanceof Error ? cause.message : String(cause)],\n { cause },\n );\n }\n if (!isRecord(rewritten)) {\n throw new StrataError('STEP_FAILED', `${migration.ref} turned the ${at} at ${pathText(target.path) || '(root)'} into something that is not a document.`, [\n JSON.stringify(rewritten)?.slice(0, 200) ?? String(rewritten),\n ]);\n }\n const next = setAt(current, target.path, rewritten);\n if (isRecord(next)) current = next;\n }\n };\n for (const migration of pending) {\n for (const step of migration.steps) if (step.kind === 'document') runStep(migration, step.at, step.transform);\n applied.push(migration.ref);\n }\n return { document: current, stamp: stampAfter(given), applied };\n };\n\n return { stamp, upgrade, locate, behind };\n};\n"]}
|