@niscorp/strata 0.1.6 → 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.
Files changed (56) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/DESIGN.md +11 -5
  3. package/README.md +56 -14
  4. package/dist/check/index.cjs +7 -7
  5. package/dist/check/index.js +2 -2
  6. package/dist/{chunk-IHYBGLNW.cjs → chunk-564JCO6Q.cjs} +8 -8
  7. package/dist/chunk-564JCO6Q.cjs.map +1 -0
  8. package/dist/{chunk-ATHZ7HT5.cjs → chunk-7PBIGCLL.cjs} +2 -2
  9. package/dist/chunk-7PBIGCLL.cjs.map +1 -0
  10. package/dist/{chunk-WU3OJHVZ.js → chunk-DGS4XJQQ.js} +4 -4
  11. package/dist/chunk-DGS4XJQQ.js.map +1 -0
  12. package/dist/{chunk-OLDORFOQ.js → chunk-FNMGVPSA.js} +4 -4
  13. package/dist/chunk-FNMGVPSA.js.map +1 -0
  14. package/dist/{chunk-YXFEJJMC.cjs → chunk-FSEUYRLN.cjs} +15 -15
  15. package/dist/chunk-FSEUYRLN.cjs.map +1 -0
  16. package/dist/{chunk-CL5DF2IQ.cjs → chunk-KYNER7UU.cjs} +18 -7
  17. package/dist/chunk-KYNER7UU.cjs.map +1 -0
  18. package/dist/{chunk-5KTXEN43.js → chunk-PAMQMFBK.js} +15 -4
  19. package/dist/chunk-PAMQMFBK.js.map +1 -0
  20. package/dist/{chunk-4BLHBVSC.js → chunk-SH6BBA2X.js} +3 -3
  21. package/dist/chunk-SH6BBA2X.js.map +1 -0
  22. package/dist/{chunk-AKKWEXO2.js → chunk-STNFHBNR.js} +2 -2
  23. package/dist/chunk-STNFHBNR.js.map +1 -0
  24. package/dist/{chunk-KNBS3AJZ.cjs → chunk-SYU7NKZR.cjs} +4 -4
  25. package/dist/chunk-SYU7NKZR.cjs.map +1 -0
  26. package/dist/index.cjs +21 -21
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +1 -1
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.js +3 -3
  31. package/dist/index.js.map +1 -1
  32. package/dist/node/index.cjs +11 -11
  33. package/dist/node/index.cjs.map +1 -1
  34. package/dist/node/index.js +5 -5
  35. package/dist/node/index.js.map +1 -1
  36. package/dist/{plan-mFmdh0qT.d.ts → plan-BMZJUCZ1.d.ts} +6 -3
  37. package/dist/{plan-CxuteSH1.d.cts → plan-Bq_Q2x5r.d.cts} +6 -3
  38. package/dist/postgres/index.cjs +36 -23
  39. package/dist/postgres/index.cjs.map +1 -1
  40. package/dist/postgres/index.d.cts +7 -3
  41. package/dist/postgres/index.d.ts +7 -3
  42. package/dist/postgres/index.js +25 -12
  43. package/dist/postgres/index.js.map +1 -1
  44. package/dist/upgrade/index.cjs +7 -7
  45. package/dist/upgrade/index.js +3 -3
  46. package/package.json +1 -1
  47. package/dist/chunk-4BLHBVSC.js.map +0 -1
  48. package/dist/chunk-5KTXEN43.js.map +0 -1
  49. package/dist/chunk-AKKWEXO2.js.map +0 -1
  50. package/dist/chunk-ATHZ7HT5.cjs.map +0 -1
  51. package/dist/chunk-CL5DF2IQ.cjs.map +0 -1
  52. package/dist/chunk-IHYBGLNW.cjs.map +0 -1
  53. package/dist/chunk-KNBS3AJZ.cjs.map +0 -1
  54. package/dist/chunk-OLDORFOQ.js.map +0 -1
  55. package/dist/chunk-WU3OJHVZ.js.map +0 -1
  56. package/dist/chunk-YXFEJJMC.cjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
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
+
17
+ ## 0.1.7
18
+
19
+ ### Patch Changes
20
+
21
+ - 2e73b96: The README states what its API tables left to source comments.
22
+
23
+ It now gives the grammar of a sequence id and of a kind name, what `planMigrations` and `migrate` return, the refusals that had no name in the docs (`PENDING`, `STEP_FAILED`, `WRONG_OWNER` from `migrate`, `UNKNOWN_KIND`, a duplicate sequence id), what `upgrader.upgrade`, `upgrader.locate` and `upgradeStore` take and return, and rows for `refuseProblems` and `diffJson`.
24
+
25
+ No behaviour changed.
26
+
27
+ **What to change:** nothing.
28
+
3
29
  ## 0.1.6
4
30
 
5
31
  ### 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
- **One transaction, one lock.** A run takes `pg_advisory_xact_lock` on the
45
- ledger's name, then creates the ledger if needed, reads it, plans and applies —
46
- all in one transaction. Postgres DDL is transactional, so a failed step leaves
47
- nothing behind. The lock comes first because two processes creating the ledger
48
- at once race in the catalog before either reaches a row.
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: the server runs every owner's sequence — moss's
36
- own tables, the sessions table, the vex cache — in one ledgered run at boot.
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,11 +53,26 @@ 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 booting
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`.
74
+ An id is lowercase, in at least two dot-separated parts (`<owner>.<name>`),
75
+ each a letter followed by letters, digits or hyphens.
60
76
  Order across sequences is the order you pass them, bent only by `dependsOn`
61
77
  (`"nisc.moss/1"`) — deterministic, the same every time.
62
78
 
@@ -67,8 +83,9 @@ own tables, the sessions table, the vex cache — in one ledgered run at boot.
67
83
  | | |
68
84
  |---|---|
69
85
  | `defineSequence(seq)` | Type-checks a sequence where it is written. |
70
- | `prepare(sequences)` | Parses (Zod, at the boundary), numbers and checksums. Throws `INVALID_SEQUENCE`. |
71
- | `planMigrations(prepared, ledger)` | Pure: what is pending, in order, and every problem (`EDITED`, `TOO_NEW`, `UNKNOWN_DEPENDENCY`, `CYCLE`). |
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. |
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. |
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. |
72
89
  | `checksumOf(migration)` | SHA-256 over the steps (WebCrypto — Node ≥ 22 and every browser). |
73
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. |
74
91
  | `SequenceSchema`, `MigrationSchema`, `StepSchema` | The grammar, as Zod. |
@@ -78,18 +95,36 @@ own tables, the sessions table, the vex cache — in one ledgered run at boot.
78
95
 
79
96
  | | |
80
97
  |---|---|
81
- | `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. |
82
- | `status(pool, sequences, options)` | The plan, read-only — creates nothing, not even the ledger. |
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. |
83
100
  | `readLedger(pool, options)` | The ledger's rows; empty for a database never migrated. |
84
101
  | `ledgerDdl(options)` | The ledger table's DDL — the one statement strata runs outside a ledger. |
85
102
 
86
103
  The pool is structural — `{ query, transaction }`, the shape vex's PGlite pool
87
104
  and a wrapped `pg` pool already have. A pool without `transaction` is refused
88
- (`NO_TRANSACTION`): a run must land whole or not at all.
105
+ (`NO_TRANSACTION`) when it has something to apply: a run must land whole or
106
+ not at all. `query` and
107
+ `transaction` are called on the object that has them, so a driver's own object
108
+ whose methods reach for `this` — a PGlite, a `pg` client handed through as the
109
+ transaction — works as it is.
89
110
 
90
111
  The ledger defaults to `strata_ledger` in the connection's schema, beside the
91
112
  app's tables; `table` and `schema` move it.
92
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
+
93
128
  ## Adopting a database from before strata
94
129
 
95
130
  Packages used to converge their tables on every boot with
@@ -103,6 +138,9 @@ so it never runs again. From then on changes are plain appended migrations.
103
138
  A **grammar** sequence owns document kinds instead of tables. It declares its
104
139
  kinds and where other documents nest inside them (its **embeddings**), and its
105
140
  migrations are **document steps** — a transform over one document of one kind.
141
+ A kind's name in `documents` is lowercase — a letter, then letters, digits or
142
+ hyphens — and everywhere else the kind is written `<sequence id>/<name>`
143
+ (`nisc.nova/layout`).
106
144
 
107
145
  ```ts
108
146
  export const NOVA_SEQUENCE = {
@@ -131,7 +169,8 @@ const { document, stamp, applied } = upgrader.upgrade(storedAction, { kind: 'nis
131
169
  along each grammar its writer was — and is upgraded where it is read. Grammars
132
170
  are never recorded in a ledger: documents travel (an add-on built on older
133
171
  code submits older documents), so their version travels with them. One
134
- sequence owns tables or documents, never both.
172
+ sequence owns tables or documents, never both. `migrate` refuses a grammar
173
+ sequence (`WRONG_OWNER`).
135
174
  - **A grammar declares `documents`**, from its first release — `{}` if it has
136
175
  no kinds of its own. That is how strata tells the two owners apart: a sequence
137
176
  is a grammar when it declares `documents` or has a document step, and anything
@@ -153,8 +192,10 @@ const { document, stamp, applied } = upgrader.upgrade(storedAction, { kind: 'nis
153
192
 
154
193
  | | |
155
194
  |---|---|
156
- | `createUpgrader(grammars, { transform })` | `{ stamp, upgrade, locate, behind }` — the stamp a document written now carries; upgrade one; every document inside one, by kind; is a stamp behind (throws if ahead). |
157
- | `upgradeStore(pool, store, upgrader)` | `@niscorp/strata/postgres`. Rewrites every row of a table holding documents that is behind, in one transaction; a row from newer code refuses the pass. |
195
+ | `createUpgrader(grammars, { transform })` | `{ stamp, upgrade, locate, behind }` — the stamp a document written now carries; upgrade one; every document inside one, by kind; is a stamp behind (throws if ahead). A kind no sequence given declares is refused (`UNKNOWN_KIND`): a step's `at` or an embedding's target when the upgrader is created, the `kind` passed to `upgrade` or `locate` when it is called. |
196
+ | `upgrader.upgrade(document, { kind, stamp })` | Returns `{ document, stamp, applied }`: `stamp` is what to store with the document, `applied` the refs of the migrations that ran, in order — empty when the document was already current. |
197
+ | `upgrader.locate(document, kind)` | Given the root's kind, `{ path, kind, value }` for the root itself and every document embedded in it; `path` is the keys and indexes from the root. |
198
+ | `upgradeStore(pool, store, upgrader)` | `@niscorp/strata/postgres`. Rewrites every row of a table holding documents that is behind, in one transaction; a row from newer code refuses the pass. `store` is `{ table, schema?, column, stamp, kind, key }`: `column` and `stamp` name the jsonb columns holding the document and its stamp, `kind` is the kind of every document in the store (`"nisc.nova/action"`), `key` lists the columns that identify a row. Returns `{ total, upgraded, applied }`: rows read, rows that were behind and rewritten, and per migration ref the number of rows it was applied to. |
158
199
 
159
200
  ## The check
160
201
 
@@ -164,9 +205,10 @@ host keeps the files.
164
205
  | | |
165
206
  |---|---|
166
207
  | `snapshotOf(sequence, schemas)` | Each kind's JSON Schema, through the schema's own Standard JSON Schema hook (Zod ≥ 4.2, Valibot, ArkType), as the validator wrote it — keys sorted, nothing removed. `schemas` must cover exactly the grammar's kinds. |
167
- | `compareSnapshot(recorded, current)` | `same`, `missing`, or `changed` with short diff lines (`+ properties.retry`, `- required["id"]`, `+ required["key"]`). Changed at the same version = a migration is owed. Both sides are compared without prose (the `description` keyword — a field named `description` is grammar) and in one spelling (definitions inlined unless recursive, `allOf: [{ $ref }]` as `$ref`, a union of bare types as a type list), so a reworded `.describe()` or a validator's respelling is not a change. |
208
+ | `compareSnapshot(recorded, current)` | `same`, `missing`, or `changed` with short diff lines (`+ properties.retry`, `- required["id"]`, `+ required["key"]`). Changed at the same version = a migration is owed. Both sides are compared without prose (the `description` keyword — a field named `description` is grammar) and in one spelling (definitions inlined unless recursive, `allOf: [{ $ref }]` as `$ref`, a union of bare types as a type list), so a reworded `.describe()` or a validator's respelling is not a change. `recorded` is the snapshot kept for the grammar's current version, `undefined` when none was kept (`missing`). |
168
209
  | `snapshotText(snapshot)` | Stable file text: sorted keys. |
169
210
  | `checkCorpus(upgrader, schemas, documents)` | Every captured document, upgraded from its stamp, must pass its kind's current schema. |
211
+ | `diffJson(a, b, limit)` | What differs between two JSON values, as short lines: `+ a.b` (added), `- c` (removed), `~ d: 1 → 2` (changed). At most `limit` lines, 20 by default. |
170
212
 
171
213
  A snapshot only says *something moved*; the corpus of real documents is the
172
214
  judge of whether old ones survive. nisc runs both on its own grammars in CI
@@ -201,8 +243,8 @@ lock for a source that has never had one.
201
243
 
202
244
  | | |
203
245
  |---|---|
204
- | `@niscorp/strata/upgrade` | Pure: `planSourceUpgrade`, `verifySourceUpgrade`, `renderReport`, `changedStrings`. |
205
- | `@niscorp/strata/node` | `runSourceUpgrade(options, argv)` — the lock, the work directory, the report, "look in" hints from the source. |
246
+ | `@niscorp/strata/upgrade` | Pure: `planSourceUpgrade`, `verifySourceUpgrade`, `renderReport`, `changedStrings`. `planSourceUpgrade`'s `describe(ref)` returns the description of the migration `ref` names, for the report; it is asked for every migration between the source's stamp and the upgrader's. |
247
+ | `@niscorp/strata/node` | `runSourceUpgrade(options, argv)` — the lock, the work directory, the report, "look in" hints from the source. `sources` is the directory under `root` that is searched for the files an artifact is written in (default `src`). |
206
248
 
207
249
  See [DESIGN.md](./DESIGN.md) and [the plan](../../docs/plans/versioning.md).
208
250
 
@@ -1,29 +1,29 @@
1
1
  'use strict';
2
2
 
3
- var chunkKNBS3AJZ_cjs = require('../chunk-KNBS3AJZ.cjs');
4
- require('../chunk-ATHZ7HT5.cjs');
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 chunkKNBS3AJZ_cjs.checkCorpus; }
10
+ get: function () { return chunkSYU7NKZR_cjs.checkCorpus; }
11
11
  });
12
12
  Object.defineProperty(exports, "compareSnapshot", {
13
13
  enumerable: true,
14
- get: function () { return chunkKNBS3AJZ_cjs.compareSnapshot; }
14
+ get: function () { return chunkSYU7NKZR_cjs.compareSnapshot; }
15
15
  });
16
16
  Object.defineProperty(exports, "diffJson", {
17
17
  enumerable: true,
18
- get: function () { return chunkKNBS3AJZ_cjs.diffJson; }
18
+ get: function () { return chunkSYU7NKZR_cjs.diffJson; }
19
19
  });
20
20
  Object.defineProperty(exports, "snapshotOf", {
21
21
  enumerable: true,
22
- get: function () { return chunkKNBS3AJZ_cjs.snapshotOf; }
22
+ get: function () { return chunkSYU7NKZR_cjs.snapshotOf; }
23
23
  });
24
24
  Object.defineProperty(exports, "snapshotText", {
25
25
  enumerable: true,
26
- get: function () { return chunkKNBS3AJZ_cjs.snapshotText; }
26
+ get: function () { return chunkSYU7NKZR_cjs.snapshotText; }
27
27
  });
28
28
  //# sourceMappingURL=index.cjs.map
29
29
  //# sourceMappingURL=index.cjs.map
@@ -1,4 +1,4 @@
1
- export { checkCorpus, compareSnapshot, diffJson, snapshotOf, snapshotText } from '../chunk-4BLHBVSC.js';
2
- import '../chunk-AKKWEXO2.js';
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 chunkKNBS3AJZ_cjs = require('./chunk-KNBS3AJZ.cjs');
4
- var chunkATHZ7HT5_cjs = require('./chunk-ATHZ7HT5.cjs');
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 chunkATHZ7HT5_cjs.StrataError("INVALID_SEQUENCE", `Two artifacts are both ${key} \u2014 an artifact needs one identity to be planned.`);
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: chunkKNBS3AJZ_cjs.diffJson(doc.document, result.document),
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: chunkKNBS3AJZ_cjs.diffJson(got.document, want.expected, 12) });
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: chunkKNBS3AJZ_cjs.diffJson(got.document, again.document, 12) });
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-IHYBGLNW.cjs.map
161
- //# sourceMappingURL=chunk-IHYBGLNW.cjs.map
160
+ //# sourceMappingURL=chunk-564JCO6Q.cjs.map
161
+ //# sourceMappingURL=chunk-564JCO6Q.cjs.map
@@ -0,0 +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;AA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AA,QAAI,IAAI,IAAA,KAAS,MAAA,GAAY,EAAA,GAAK,CAAA,cAAA,EAAiB,IAAI,IAAI,CAAA,EAAA,CAAA;AAAA,QACrG,GAAA,CAAI,WAAW,MAAA,IAAa,GAAA,CAAI,OAAO,MAAA,KAAW,CAAA,GAAI,KAAK,CAAA,eAAA,EAAkB,GAAA,CAAI,OAAO,GAAA,CAAI,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-ATHZ7HT5.cjs.map
18
- //# sourceMappingURL=chunk-ATHZ7HT5.cjs.map
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-4BLHBVSC.js';
2
- import { StrataError } from './chunk-AKKWEXO2.js';
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-WU3OJHVZ.js.map
156
- //# sourceMappingURL=chunk-WU3OJHVZ.js.map
155
+ //# sourceMappingURL=chunk-DGS4XJQQ.js.map
156
+ //# sourceMappingURL=chunk-DGS4XJQQ.js.map
@@ -0,0 +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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AA,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-5KTXEN43.js';
2
- import { StrataError } from './chunk-AKKWEXO2.js';
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-OLDORFOQ.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AAA,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"]}
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkCL5DF2IQ_cjs = require('./chunk-CL5DF2IQ.cjs');
4
- var chunkATHZ7HT5_cjs = require('./chunk-ATHZ7HT5.cjs');
3
+ var chunkKYNER7UU_cjs = require('./chunk-KYNER7UU.cjs');
4
+ var chunk7PBIGCLL_cjs = require('./chunk-7PBIGCLL.cjs');
5
5
 
6
6
  // src/documents.ts
7
7
  var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
@@ -36,10 +36,10 @@ var setAt = (root, path, value) => {
36
36
  return root;
37
37
  };
38
38
  var createUpgrader = async (sequences, options) => {
39
- const prepared = await chunkCL5DF2IQ_cjs.prepare(sequences);
39
+ const prepared = await chunkKYNER7UU_cjs.prepare(sequences);
40
40
  const tables = prepared.filter((s) => !s.grammar);
41
41
  if (tables.length > 0) {
42
- throw new chunkATHZ7HT5_cjs.StrataError(
42
+ throw new chunk7PBIGCLL_cjs.StrataError(
43
43
  "WRONG_OWNER",
44
44
  "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` \u2014 a sequence with no `documents` and no document step is read as owning tables.",
45
45
  tables.map((s) => s.id)
@@ -54,7 +54,7 @@ var createUpgrader = async (sequences, options) => {
54
54
  ...grammars.flatMap((s) => s.migrations.flatMap((m) => m.steps.flatMap((step) => step.kind === "document" && !kinds.has(step.at) ? [`${m.ref} rewrites ${step.at}`] : []))),
55
55
  ...[...kinds].flatMap(([ref, kind]) => Object.entries(kind.embeds ?? {}).flatMap(([path, target]) => kinds.has(target) ? [] : [`${ref} embeds ${target} at ${path}`]))
56
56
  ];
57
- if (unknown.length > 0) throw new chunkATHZ7HT5_cjs.StrataError("UNKNOWN_KIND", "A document kind is named that no sequence declares.", unknown);
57
+ if (unknown.length > 0) throw new chunk7PBIGCLL_cjs.StrataError("UNKNOWN_KIND", "A document kind is named that no sequence declares.", unknown);
58
58
  const stamp = Object.fromEntries(grammars.map((s) => [s.id, s.migrations.length]));
59
59
  const ownIds = new Set(grammars.map((s) => s.id));
60
60
  const stampAfter = (given) => {
@@ -62,7 +62,7 @@ var createUpgrader = async (sequences, options) => {
62
62
  return others.length === 0 ? stamp : { ...stamp, ...Object.fromEntries(others) };
63
63
  };
64
64
  const locate = (document, kind) => {
65
- if (!kinds.has(kind)) throw new chunkATHZ7HT5_cjs.StrataError("UNKNOWN_KIND", `No sequence declares the document kind "${kind}".`, [...kinds.keys()]);
65
+ if (!kinds.has(kind)) throw new chunk7PBIGCLL_cjs.StrataError("UNKNOWN_KIND", `No sequence declares the document kind "${kind}".`, [...kinds.keys()]);
66
66
  const found = [];
67
67
  const visit = (value, at, path) => {
68
68
  if (!isRecord(value)) return;
@@ -78,7 +78,7 @@ var createUpgrader = async (sequences, options) => {
78
78
  const behind = (given) => {
79
79
  const ahead = grammars.filter((s) => positionOf(given, s.id) > s.migrations.length);
80
80
  if (ahead.length > 0) {
81
- throw new chunkATHZ7HT5_cjs.StrataError(
81
+ throw new chunk7PBIGCLL_cjs.StrataError(
82
82
  "TOO_NEW",
83
83
  "This document was written by newer code than this \u2014 reading it would be guessing.",
84
84
  ahead.map((s) => `${s.id}: the document is at ${positionOf(given, s.id)}, this code knows ${s.migrations.length}`)
@@ -87,15 +87,15 @@ var createUpgrader = async (sequences, options) => {
87
87
  return grammars.some((s) => positionOf(given, s.id) < s.migrations.length);
88
88
  };
89
89
  const upgrade = (document, { kind, stamp: given }) => {
90
- if (!isRecord(document)) throw new chunkATHZ7HT5_cjs.StrataError("STEP_FAILED", `A ${kind} document must be a JSON object.`);
91
- if (!kinds.has(kind)) throw new chunkATHZ7HT5_cjs.StrataError("UNKNOWN_KIND", `No sequence declares the document kind "${kind}".`, [...kinds.keys()]);
90
+ if (!isRecord(document)) throw new chunk7PBIGCLL_cjs.StrataError("STEP_FAILED", `A ${kind} document must be a JSON object.`);
91
+ if (!kinds.has(kind)) throw new chunk7PBIGCLL_cjs.StrataError("UNKNOWN_KIND", `No sequence declares the document kind "${kind}".`, [...kinds.keys()]);
92
92
  if (!behind(given)) return { document, stamp: stampAfter(given), applied: [] };
93
93
  const done = new Set(grammars.flatMap((s) => s.migrations.filter((m) => m.n <= positionOf(given, s.id)).map((m) => m.ref)));
94
- const { pending, stuck } = chunkCL5DF2IQ_cjs.orderPending(
94
+ const { pending, stuck } = chunkKYNER7UU_cjs.orderPending(
95
95
  grammars.map((s) => ({ waiting: s.migrations.filter((m) => !done.has(m.ref)) })),
96
96
  done
97
97
  );
98
- if (stuck.length > 0) throw new chunkATHZ7HT5_cjs.StrataError("CYCLE", "Document migrations wait on each other and can never run.", stuck.map((m) => m.ref));
98
+ if (stuck.length > 0) throw new chunk7PBIGCLL_cjs.StrataError("CYCLE", "Document migrations wait on each other and can never run.", stuck.map((m) => m.ref));
99
99
  let current = document;
100
100
  const applied = [];
101
101
  const runStep = (migration, at, transform) => {
@@ -106,7 +106,7 @@ var createUpgrader = async (sequences, options) => {
106
106
  try {
107
107
  rewritten = options.transform(transform, { document: value, path: pathText(target.path) });
108
108
  } catch (cause) {
109
- throw new chunkATHZ7HT5_cjs.StrataError(
109
+ throw new chunk7PBIGCLL_cjs.StrataError(
110
110
  "STEP_FAILED",
111
111
  `${migration.ref} ("${migration.description}") failed on the ${at} at ${pathText(target.path) || "(root)"}.`,
112
112
  [cause instanceof Error ? cause.message : String(cause)],
@@ -114,7 +114,7 @@ var createUpgrader = async (sequences, options) => {
114
114
  );
115
115
  }
116
116
  if (!isRecord(rewritten)) {
117
- throw new chunkATHZ7HT5_cjs.StrataError("STEP_FAILED", `${migration.ref} turned the ${at} at ${pathText(target.path) || "(root)"} into something that is not a document.`, [
117
+ throw new chunk7PBIGCLL_cjs.StrataError("STEP_FAILED", `${migration.ref} turned the ${at} at ${pathText(target.path) || "(root)"} into something that is not a document.`, [
118
118
  JSON.stringify(rewritten)?.slice(0, 200) ?? String(rewritten)
119
119
  ]);
120
120
  }
@@ -132,5 +132,5 @@ var createUpgrader = async (sequences, options) => {
132
132
  };
133
133
 
134
134
  exports.createUpgrader = createUpgrader;
135
- //# sourceMappingURL=chunk-YXFEJJMC.cjs.map
136
- //# sourceMappingURL=chunk-YXFEJJMC.cjs.map
135
+ //# sourceMappingURL=chunk-FSEUYRLN.cjs.map
136
+ //# sourceMappingURL=chunk-FSEUYRLN.cjs.map