@niscorp/strata 0.1.9 → 0.2.0
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 +34 -0
- package/DESIGN.md +4 -0
- package/README.md +47 -8
- package/dist/check/index.cjs +6 -6
- package/dist/check/index.js +1 -1
- package/dist/{chunk-SH6BBA2X.js → chunk-2G3DFR6P.js} +13 -11
- package/dist/chunk-2G3DFR6P.js.map +1 -0
- package/dist/{chunk-FSEUYRLN.cjs → chunk-FMXFHYU2.cjs} +15 -6
- package/dist/chunk-FMXFHYU2.cjs.map +1 -0
- package/dist/{chunk-SYU7NKZR.cjs → chunk-HTW4IEBC.cjs} +13 -11
- package/dist/chunk-HTW4IEBC.cjs.map +1 -0
- package/dist/{chunk-564JCO6Q.cjs → chunk-I2CR5CBI.cjs} +17 -13
- package/dist/chunk-I2CR5CBI.cjs.map +1 -0
- package/dist/{chunk-FNMGVPSA.js → chunk-LJAB5G5Y.js} +13 -4
- package/dist/chunk-LJAB5G5Y.js.map +1 -0
- package/dist/{chunk-DGS4XJQQ.js → chunk-QDZYRBRP.js} +14 -11
- package/dist/chunk-QDZYRBRP.js.map +1 -0
- package/dist/{chunk-KYNER7UU.cjs → chunk-SJNHLIKR.cjs} +4 -3
- package/dist/chunk-SJNHLIKR.cjs.map +1 -0
- package/dist/{chunk-PAMQMFBK.js → chunk-YCQ6LS7X.js} +4 -3
- package/dist/chunk-YCQ6LS7X.js.map +1 -0
- package/dist/index.cjs +19 -19
- package/dist/index.js +2 -2
- package/dist/node/index.cjs +178 -89
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +180 -91
- package/dist/node/index.js.map +1 -1
- package/dist/postgres/index.cjs +26 -11
- package/dist/postgres/index.cjs.map +1 -1
- package/dist/postgres/index.d.cts +1 -0
- package/dist/postgres/index.d.ts +1 -0
- package/dist/postgres/index.js +20 -5
- package/dist/postgres/index.js.map +1 -1
- package/dist/upgrade/index.cjs +6 -6
- package/dist/upgrade/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-564JCO6Q.cjs.map +0 -1
- package/dist/chunk-DGS4XJQQ.js.map +0 -1
- package/dist/chunk-FNMGVPSA.js.map +0 -1
- package/dist/chunk-FSEUYRLN.cjs.map +0 -1
- package/dist/chunk-KYNER7UU.cjs.map +0 -1
- package/dist/chunk-PAMQMFBK.js.map +0 -1
- package/dist/chunk-SH6BBA2X.js.map +0 -1
- package/dist/chunk-SYU7NKZR.cjs.map +0 -1
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkHTW4IEBC_cjs = require('./chunk-HTW4IEBC.cjs');
|
|
4
4
|
var chunk7PBIGCLL_cjs = require('./chunk-7PBIGCLL.cjs');
|
|
5
5
|
|
|
6
|
+
// src/upgrade/fits.ts
|
|
7
|
+
var schemaMisfit = async (schemas, kind, document) => {
|
|
8
|
+
const schema = schemas?.[kind];
|
|
9
|
+
if (schema === void 0) return void 0;
|
|
10
|
+
const checked = await schema["~standard"].validate(document);
|
|
11
|
+
return checked.issues === void 0 ? void 0 : checked.issues.slice(0, 2).map((i) => i.message).join("; ");
|
|
12
|
+
};
|
|
13
|
+
|
|
6
14
|
// src/upgrade/index.ts
|
|
7
15
|
var keyOf = (doc) => `${doc.kind}:${doc.id}`;
|
|
8
16
|
var sortKeys = (value) => {
|
|
@@ -50,16 +58,11 @@ var planSourceUpgrade = async (options) => {
|
|
|
50
58
|
id: doc.id,
|
|
51
59
|
...doc.file === void 0 ? {} : { file: doc.file },
|
|
52
60
|
applied: result.applied,
|
|
53
|
-
changes:
|
|
61
|
+
changes: chunkHTW4IEBC_cjs.diffJson(doc.document, result.document),
|
|
54
62
|
expected: result.document
|
|
55
63
|
});
|
|
56
|
-
const
|
|
57
|
-
if (
|
|
58
|
-
const checked = await schema["~standard"].validate(result.document);
|
|
59
|
-
if (checked.issues !== void 0) {
|
|
60
|
-
problems.push(`${key}: the migrated artifact does not pass ${doc.kind}'s current schema \u2014 ${checked.issues.slice(0, 2).map((i) => i.message).join("; ")}`);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
64
|
+
const misfit = await schemaMisfit(schemas, doc.kind, result.document);
|
|
65
|
+
if (misfit !== void 0) problems.push(`${key}: the migrated artifact does not pass ${doc.kind}'s current schema \u2014 ${misfit}`);
|
|
63
66
|
}
|
|
64
67
|
const from = stamp;
|
|
65
68
|
const to = upgrader.stamp;
|
|
@@ -87,7 +90,7 @@ var verifySourceUpgrade = (options) => {
|
|
|
87
90
|
} else if (sameJson(got.document, want.expected)) {
|
|
88
91
|
lines.push({ ok: true, text: `${key} matches its migrated JSON` });
|
|
89
92
|
} else {
|
|
90
|
-
lines.push({ ok: false, text: `${key} does not match its migrated JSON yet`, detail:
|
|
93
|
+
lines.push({ ok: false, text: `${key} does not match its migrated JSON yet`, detail: chunkHTW4IEBC_cjs.diffJson(got.document, want.expected, 12) });
|
|
91
94
|
}
|
|
92
95
|
}
|
|
93
96
|
for (const key of plan.untouched) {
|
|
@@ -98,7 +101,7 @@ var verifySourceUpgrade = (options) => {
|
|
|
98
101
|
}
|
|
99
102
|
const again = upgrader.upgrade(got.document, { kind: got.kind, stamp: plan.from });
|
|
100
103
|
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:
|
|
104
|
+
lines.push({ ok: false, text: `${key} was not in the plan, but the migrations would change it now`, detail: chunkHTW4IEBC_cjs.diffJson(got.document, again.document, 12) });
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
107
|
const known = /* @__PURE__ */ new Set([...plan.documents.map(keyOf), ...plan.untouched]);
|
|
@@ -156,6 +159,7 @@ var renderReport = (plan, expectedPathOf) => {
|
|
|
156
159
|
exports.changedStrings = changedStrings;
|
|
157
160
|
exports.planSourceUpgrade = planSourceUpgrade;
|
|
158
161
|
exports.renderReport = renderReport;
|
|
162
|
+
exports.schemaMisfit = schemaMisfit;
|
|
159
163
|
exports.verifySourceUpgrade = verifySourceUpgrade;
|
|
160
|
-
//# sourceMappingURL=chunk-
|
|
161
|
-
//# sourceMappingURL=chunk-
|
|
164
|
+
//# sourceMappingURL=chunk-I2CR5CBI.cjs.map
|
|
165
|
+
//# sourceMappingURL=chunk-I2CR5CBI.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/upgrade/fits.ts","../src/upgrade/index.ts"],"names":["StrataError","diffJson"],"mappings":";;;;;;AAEO,IAAM,YAAA,GAAe,OAAO,OAAA,EAA8D,IAAA,EAAc,QAAA,KAAmD;AAChK,EAAA,MAAM,MAAA,GAAS,UAAU,IAAI,CAAA;AAC7B,EAAA,IAAI,MAAA,KAAW,QAAW,OAAO,MAAA;AACjC,EAAA,MAAM,UAAU,MAAM,MAAA,CAAO,WAAW,CAAA,CAAE,SAAS,QAAQ,CAAA;AAC3D,EAAA,OAAO,QAAQ,MAAA,KAAW,MAAA,GAAY,MAAA,GAAY,OAAA,CAAQ,OAAO,KAAA,CAAM,CAAA,EAAG,CAAC,CAAA,CAAE,IAAI,CAAC,CAAA,KAAM,EAAE,OAAO,CAAA,CAAE,KAAK,IAAI,CAAA;AAC9G;;;ACmBA,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,CA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C,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-I2CR5CBI.cjs","sourcesContent":["import type { GrammarSchema } from '../check';\n\nexport const schemaMisfit = async (schemas: Readonly<Record<string, GrammarSchema>> | undefined, kind: string, document: unknown): Promise<string | undefined> => {\n const schema = schemas?.[kind];\n if (schema === undefined) return undefined;\n const checked = await schema['~standard'].validate(document);\n return checked.issues === undefined ? undefined : checked.issues.slice(0, 2).map((i) => i.message).join('; ');\n};\n","import type { Stamp, Upgrader } from '../documents';\nimport { diffJson, type GrammarSchema } from '../check';\nimport { StrataError } from '../errors';\nimport { schemaMisfit } from './fits';\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 misfit = await schemaMisfit(schemas, doc.kind, result.document);\n if (misfit !== undefined) problems.push(`${key}: the migrated artifact does not pass ${doc.kind}'s current schema — ${misfit}`);\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,4 +1,4 @@
|
|
|
1
|
-
import { prepare, orderPending } from './chunk-
|
|
1
|
+
import { prepare, orderPending } from './chunk-YCQ6LS7X.js';
|
|
2
2
|
import { StrataError } from './chunk-STNFHBNR.js';
|
|
3
3
|
|
|
4
4
|
// src/documents.ts
|
|
@@ -72,7 +72,16 @@ var createUpgrader = async (sequences, options) => {
|
|
|
72
72
|
visit(document, kind, []);
|
|
73
73
|
return found;
|
|
74
74
|
};
|
|
75
|
-
const positionOf = (given, id) =>
|
|
75
|
+
const positionOf = (given, id) => {
|
|
76
|
+
const entry = given?.[id];
|
|
77
|
+
if (entry === void 0) return 0;
|
|
78
|
+
const position = Number(entry);
|
|
79
|
+
if (Number.isNaN(position)) {
|
|
80
|
+
const named = typeof entry === "number" ? String(entry) : JSON.stringify(entry);
|
|
81
|
+
throw new StrataError("INVALID_SEQUENCE", `The stamp's entry for ${id} is ${named}: not a number of migrations.`);
|
|
82
|
+
}
|
|
83
|
+
return position;
|
|
84
|
+
};
|
|
76
85
|
const behind = (given) => {
|
|
77
86
|
const ahead = grammars.filter((s) => positionOf(given, s.id) > s.migrations.length);
|
|
78
87
|
if (ahead.length > 0) {
|
|
@@ -130,5 +139,5 @@ var createUpgrader = async (sequences, options) => {
|
|
|
130
139
|
};
|
|
131
140
|
|
|
132
141
|
export { createUpgrader };
|
|
133
|
-
//# sourceMappingURL=chunk-
|
|
134
|
-
//# sourceMappingURL=chunk-
|
|
142
|
+
//# sourceMappingURL=chunk-LJAB5G5Y.js.map
|
|
143
|
+
//# sourceMappingURL=chunk-LJAB5G5Y.js.map
|
|
@@ -0,0 +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,E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AA,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-LJAB5G5Y.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 // An entry is read with `Number`: digits and `null` read; one that reads as no number is refused rather\n // than read as current. A number is named as itself: JSON would print `NaN` as `null`.\n const positionOf = (given: Stamp | null | undefined, id: string): number => {\n const entry: unknown = given?.[id];\n if (entry === undefined) return 0;\n const position = Number(entry);\n if (Number.isNaN(position)) {\n const named = typeof entry === 'number' ? String(entry) : JSON.stringify(entry);\n throw new StrataError('INVALID_SEQUENCE', `The stamp's entry for ${id} is ${named}: not a number of migrations.`);\n }\n return position;\n };\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,6 +1,14 @@
|
|
|
1
|
-
import { diffJson } from './chunk-
|
|
1
|
+
import { diffJson } from './chunk-2G3DFR6P.js';
|
|
2
2
|
import { StrataError } from './chunk-STNFHBNR.js';
|
|
3
3
|
|
|
4
|
+
// src/upgrade/fits.ts
|
|
5
|
+
var schemaMisfit = async (schemas, kind, document) => {
|
|
6
|
+
const schema = schemas?.[kind];
|
|
7
|
+
if (schema === void 0) return void 0;
|
|
8
|
+
const checked = await schema["~standard"].validate(document);
|
|
9
|
+
return checked.issues === void 0 ? void 0 : checked.issues.slice(0, 2).map((i) => i.message).join("; ");
|
|
10
|
+
};
|
|
11
|
+
|
|
4
12
|
// src/upgrade/index.ts
|
|
5
13
|
var keyOf = (doc) => `${doc.kind}:${doc.id}`;
|
|
6
14
|
var sortKeys = (value) => {
|
|
@@ -51,13 +59,8 @@ var planSourceUpgrade = async (options) => {
|
|
|
51
59
|
changes: diffJson(doc.document, result.document),
|
|
52
60
|
expected: result.document
|
|
53
61
|
});
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
56
|
-
const checked = await schema["~standard"].validate(result.document);
|
|
57
|
-
if (checked.issues !== void 0) {
|
|
58
|
-
problems.push(`${key}: the migrated artifact does not pass ${doc.kind}'s current schema \u2014 ${checked.issues.slice(0, 2).map((i) => i.message).join("; ")}`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
62
|
+
const misfit = await schemaMisfit(schemas, doc.kind, result.document);
|
|
63
|
+
if (misfit !== void 0) problems.push(`${key}: the migrated artifact does not pass ${doc.kind}'s current schema \u2014 ${misfit}`);
|
|
61
64
|
}
|
|
62
65
|
const from = stamp;
|
|
63
66
|
const to = upgrader.stamp;
|
|
@@ -151,6 +154,6 @@ var renderReport = (plan, expectedPathOf) => {
|
|
|
151
154
|
return out.filter((line, i, all) => !(line === "" && all[i - 1] === "")).join("\n");
|
|
152
155
|
};
|
|
153
156
|
|
|
154
|
-
export { changedStrings, planSourceUpgrade, renderReport, verifySourceUpgrade };
|
|
155
|
-
//# sourceMappingURL=chunk-
|
|
156
|
-
//# sourceMappingURL=chunk-
|
|
157
|
+
export { changedStrings, planSourceUpgrade, renderReport, schemaMisfit, verifySourceUpgrade };
|
|
158
|
+
//# sourceMappingURL=chunk-QDZYRBRP.js.map
|
|
159
|
+
//# sourceMappingURL=chunk-QDZYRBRP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/upgrade/fits.ts","../src/upgrade/index.ts"],"names":[],"mappings":";;;;AAEO,IAAM,YAAA,GAAe,OAAO,OAAA,EAA8D,IAAA,EAAc,QAAA,KAAmD;AAChK,EAAA,MAAM,MAAA,GAAS,UAAU,IAAI,CAAA;AAC7B,EAAA,IAAI,MAAA,KAAW,QAAW,OAAO,MAAA;AACjC,EAAA,MAAM,UAAU,MAAM,MAAA,CAAO,WAAW,CAAA,CAAE,SAAS,QAAQ,CAAA;AAC3D,EAAA,OAAO,QAAQ,MAAA,KAAW,MAAA,GAAY,MAAA,GAAY,OAAA,CAAQ,OAAO,KAAA,CAAM,CAAA,EAAG,CAAC,CAAA,CAAE,IAAI,CAAC,CAAA,KAAM,EAAE,OAAO,CAAA,CAAE,KAAK,IAAI,CAAA;AAC9G;;;ACmBA,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,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AAA,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-QDZYRBRP.js","sourcesContent":["import type { GrammarSchema } from '../check';\n\nexport const schemaMisfit = async (schemas: Readonly<Record<string, GrammarSchema>> | undefined, kind: string, document: unknown): Promise<string | undefined> => {\n const schema = schemas?.[kind];\n if (schema === undefined) return undefined;\n const checked = await schema['~standard'].validate(document);\n return checked.issues === undefined ? undefined : checked.issues.slice(0, 2).map((i) => i.message).join('; ');\n};\n","import type { Stamp, Upgrader } from '../documents';\nimport { diffJson, type GrammarSchema } from '../check';\nimport { StrataError } from '../errors';\nimport { schemaMisfit } from './fits';\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 misfit = await schemaMisfit(schemas, doc.kind, result.document);\n if (misfit !== undefined) problems.push(`${key}: the migrated artifact does not pass ${doc.kind}'s current schema — ${misfit}`);\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"]}
|
|
@@ -72,7 +72,8 @@ var prepare = async (sequences) => {
|
|
|
72
72
|
const parsed = SequenceSchema.safeParse(input);
|
|
73
73
|
if (!parsed.success) {
|
|
74
74
|
const issues = parsed.error.issues.map((i) => `${i.path.join(".") || "(root)"}: ${i.message}`);
|
|
75
|
-
|
|
75
|
+
const id = typeof input === "object" && input !== null ? input.id : void 0;
|
|
76
|
+
throw new chunk7PBIGCLL_cjs.StrataError("INVALID_SEQUENCE", `A sequence does not parse${typeof id === "string" ? ` ("${id}")` : ""}.`, issues);
|
|
76
77
|
}
|
|
77
78
|
const sequence = parsed.data;
|
|
78
79
|
if (seen.has(sequence.id)) {
|
|
@@ -199,5 +200,5 @@ exports.orderPending = orderPending;
|
|
|
199
200
|
exports.planMigrations = planMigrations;
|
|
200
201
|
exports.prepare = prepare;
|
|
201
202
|
exports.refuseProblems = refuseProblems;
|
|
202
|
-
//# sourceMappingURL=chunk-
|
|
203
|
-
//# sourceMappingURL=chunk-
|
|
203
|
+
//# sourceMappingURL=chunk-SJNHLIKR.cjs.map
|
|
204
|
+
//# sourceMappingURL=chunk-SJNHLIKR.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schema.ts","../src/checksum.ts","../src/plan.ts"],"names":["z","StrataError"],"mappings":";;;;;AAEO,IAAM,WAAA,GAAc;AAEpB,IAAM,aAAA,GAAgB;AAEtB,IAAM,SAAA,GAAY;AAClB,IAAM,QAAA,GAAW;AAKjB,IAAM,UAAA,GAAa;AAEnB,IAAM,aAAA,GAAgBA,MAC1B,MAAA,CAAO;AAAA,EACN,IAAA,EAAMA,KAAA,CAAE,OAAA,CAAQ,KAAK,CAAA;AAAA,EACrB,KAAKA,KAAA,CACF,MAAA,EAAO,CACP,GAAA,CAAI,CAAC,CAAA,CACL,QAAA;AAAA,IACC;AAAA;AAGN,CAAC,CAAA,CACA,MAAA,EAAO,CACP,QAAA,CAAS,yEAAyE;AAE9E,IAAM,kBAAA,GAAqBA,MAC/B,MAAA,CAAO;AAAA,EACN,IAAA,EAAMA,KAAA,CAAE,OAAA,CAAQ,UAAU,CAAA;AAAA,EAC1B,EAAA,EAAIA,MACD,MAAA,EAAO,CACP,MAAM,QAAQ,CAAA,CACd,SAAS,0GAAqG,CAAA;AAAA,EACjH,SAAA,EAAWA,KAAA,CACR,OAAA,EAAQ,CACR,QAAA;AAAA,IACC;AAAA;AAIN,CAAC,CAAA,CACA,MAAA,EAAO,CACP,QAAA,CAAS,iDAAiD;AAEtD,IAAM,aAAaA,KAAA,CAAE,kBAAA,CAAmB,QAAQ,CAAC,aAAA,E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-z][a-z0-9-]*(\\.[a-z][a-z0-9-]*)+\\/[a-z][a-z0-9-]*$/;\n\n// `children[]` crosses the array at `children`, `endpoints.*` the record at\n// `endpoints`. Two wildcards, not one: nova's `children` is a single node or an\n// array, and one for both would read a lone node's `props` as layouts.\nexport const EMBED_PATH = /^([A-Za-z_$][\\w$]*|\\*)(\\[\\])?(\\.([A-Za-z_$][\\w$]*|\\*)(\\[\\])?)*$/;\n\nexport const SqlStepSchema = z\n .object({\n kind: z.literal('sql'),\n sql: z\n .string()\n .min(1)\n .describe(\n 'ONE SQL statement. A driver that prepares statements (PGlite, pg with parameters) refuses a string ' +\n 'carrying several — split them into steps rather than joining them with semicolons.',\n ),\n })\n .strict()\n .describe('A statement run against the database, inside the migration transaction.');\n\nexport const DocumentStepSchema = z\n .object({\n kind: z.literal('document'),\n at: z\n .string()\n .regex(KIND_REF)\n .describe('The kind of document this step rewrites, e.g. \"nisc.nova/layout\" — wherever one sits, at any depth.'),\n transform: z\n .unknown()\n .describe(\n 'A transform config (Prism) run by the injected evaluator over { document, path }: `document` is ONE document of ' +\n 'the `at` kind, `path` where it sits. It returns that document rewritten. Nested documents are found by the ' +\n 'grammar\\'s embeddings and rewritten on their own, deepest first — a transform only ever sees one flat node.',\n ),\n })\n .strict()\n .describe('A rewrite of stored JSON documents of one kind.');\n\nexport const StepSchema = z.discriminatedUnion('kind', [SqlStepSchema, DocumentStepSchema]);\n\nexport const DocumentKindSchema = z\n .object({\n embeds: z\n .record(z.string().regex(EMBED_PATH), z.string().regex(KIND_REF))\n .optional()\n .describe('Where other documents sit inside this one: path → the kind found there (possibly this kind itself).'),\n })\n .strict();\n\nexport const MigrationSchema = z\n .object({\n description: z\n .string()\n .min(1)\n .describe('One sentence: what this migration does. It is the changelog line and the ledger\\'s description.'),\n steps: z\n .array(StepSchema)\n .describe(\n 'Applied in order, in the same transaction as every other pending migration. Empty is a MARKER: ' +\n 'the version moves and nothing runs — how an addition to a strict grammar tells older readers to refuse.',\n ),\n dependsOn: z\n .array(z.string().regex(MIGRATION_REF))\n .optional()\n .describe('Migrations of OTHER sequences that must be applied first, each as \"<sequence>/<n>\".'),\n })\n .strict();\n\nexport const SequenceSchema = z\n .object({\n id: z.string().regex(SEQUENCE_ID).describe('Namespaced and lowercase, e.g. \"nisc.vex.cache\" or \"midas.app\".'),\n documents: z\n .record(z.string().regex(KIND_NAME), DocumentKindSchema)\n .optional()\n .describe('The document kinds this sequence owns (a GRAMMAR sequence), each named \"<id>/<kind>\" elsewhere.'),\n migrations: z\n .array(MigrationSchema)\n .describe('Append-only. A migration is numbered by its position (from 1); the sequence\\'s version is its length.'),\n })\n .strict()\n // Not both: a table sequence's version is recorded per database, a grammar\n // sequence's per document (its stamp), and one number cannot be both.\n .superRefine((sequence, ctx) => {\n const kinds = new Set(sequence.migrations.flatMap((m) => m.steps.map((s) => s.kind)));\n if (kinds.has('sql') && (kinds.has('document') || sequence.documents !== undefined)) {\n ctx.addIssue({\n code: 'custom',\n message: 'A sequence either owns tables (sql steps) or documents (document steps and `documents`), not both.',\n });\n }\n });\n\nexport type SqlStep = z.infer<typeof SqlStepSchema>;\nexport type DocumentStep = z.infer<typeof DocumentStepSchema>;\nexport type DocumentKind = z.infer<typeof DocumentKindSchema>;\nexport type Step = z.infer<typeof StepSchema>;\nexport type Migration = z.infer<typeof MigrationSchema>;\nexport type Sequence = z.infer<typeof SequenceSchema>;\n","import type { Migration } from './schema';\n\nconst canonical = (value: unknown): string => {\n if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`;\n if (value !== null && typeof value === 'object') {\n const entries = Object.entries(value)\n .filter(([, v]) => v !== undefined)\n .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));\n return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`).join(',')}}`;\n }\n return JSON.stringify(value);\n};\n\nconst effectOf = (sql: string): string =>\n sql\n .split('\\n')\n .filter((line) => !line.trimStart().startsWith('--'))\n .map((line) => line.trimEnd())\n .join('\\n')\n .trim();\n\nexport const checksumOf = async (migration: Migration): Promise<string> => {\n const steps = migration.steps.map((step) => (step.kind === 'sql' ? { ...step, sql: effectOf(step.sql) } : step));\n const bytes = new TextEncoder().encode(canonical(steps));\n const digest = await crypto.subtle.digest('SHA-256', bytes);\n return Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, '0')).join('');\n};\n","import { SequenceSchema, type DocumentKind, type Sequence, type Step } from './schema';\nimport { checksumOf } from './checksum';\nimport { StrataError, type StrataErrorCode } from './errors';\n\nexport type PreparedMigration = {\n sequence: string;\n n: number;\n ref: string;\n description: string;\n checksum: string;\n steps: readonly Step[];\n dependsOn: readonly string[];\n};\n\nexport type PreparedSequence = {\n id: string;\n grammar: boolean;\n documents: Readonly<Record<string, DocumentKind>>;\n migrations: readonly PreparedMigration[];\n};\n\nexport type LedgerRow = { sequence: string; n: number; checksum: string; description: string; appliedAt: string };\n\nexport type Problem = { code: Exclude<StrataErrorCode, 'PENDING' | 'STEP_FAILED' | 'DOES_NOT_FIT' | 'NO_TRANSACTION' | 'UNKNOWN_KIND' | 'WRONG_OWNER'>; detail: string };\n\nexport type Plan = {\n applied: Readonly<Record<string, number>>;\n pending: readonly PreparedMigration[];\n problems: readonly Problem[];\n};\n\nconst refOf = (sequence: string, n: number): string => `${sequence}/${n}`;\n\nexport const prepare = async (sequences: readonly Sequence[]): Promise<readonly PreparedSequence[]> => {\n const seen = new Set<string>();\n const prepared: PreparedSequence[] = [];\n for (const input of sequences) {\n const parsed = SequenceSchema.safeParse(input);\n if (!parsed.success) {\n const issues = parsed.error.issues.map((i) => `${i.path.join('.') || '(root)'}: ${i.message}`);\n const id: unknown = typeof input === 'object' && input !== null ? input.id : undefined;\n throw new StrataError('INVALID_SEQUENCE', `A sequence does not parse${typeof id === 'string' ? ` (\"${id}\")` : ''}.`, issues);\n }\n const sequence = parsed.data;\n if (seen.has(sequence.id)) {\n throw new StrataError('INVALID_SEQUENCE', `Two sequences are both called \"${sequence.id}\" — a sequence id names one owner.`);\n }\n seen.add(sequence.id);\n const migrations: PreparedMigration[] = [];\n for (const [index, migration] of sequence.migrations.entries()) {\n const n = index + 1;\n migrations.push({\n sequence: sequence.id,\n n,\n ref: refOf(sequence.id, n),\n description: migration.description,\n checksum: await checksumOf(migration),\n steps: migration.steps,\n dependsOn: migration.dependsOn ?? [],\n });\n }\n const grammar = sequence.documents !== undefined || sequence.migrations.some((m) => m.steps.some((s) => s.kind === 'document'));\n prepared.push({ id: sequence.id, grammar, documents: sequence.documents ?? {}, migrations });\n }\n return prepared;\n};\n\nexport const orderPending = (\n queues: readonly { waiting: readonly PreparedMigration[] }[],\n alreadyDone: ReadonlySet<string>,\n): { pending: PreparedMigration[]; stuck: PreparedMigration[] } => {\n const done = new Set(alreadyDone);\n const waiting = queues.map((q) => [...q.waiting]);\n const pending: PreparedMigration[] = [];\n let moved = true;\n while (moved) {\n moved = false;\n for (const queue of waiting) {\n for (let head = queue[0]; head !== undefined; head = queue[0]) {\n if (!head.dependsOn.every((d) => done.has(d))) break;\n pending.push(head);\n done.add(head.ref);\n queue.shift();\n moved = true;\n }\n }\n }\n return { pending, stuck: waiting.flat() };\n};\n\nexport type PlanOptions = {\n // The sequences given are every sequence the ledger may record.\n complete?: boolean;\n};\n\nexport const planMigrations = (sequences: readonly PreparedSequence[], ledger: readonly LedgerRow[], options: PlanOptions = {}): Plan => {\n const problems: Problem[] = [];\n const applied: Record<string, number> = {};\n const done = new Set(ledger.map((row) => refOf(row.sequence, row.n)));\n const byRef = new Map(ledger.map((row) => [refOf(row.sequence, row.n), row]));\n\n const queues: { id: string; waiting: PreparedMigration[] }[] = [];\n for (const sequence of sequences) {\n const rows = ledger.filter((row) => row.sequence === sequence.id);\n applied[sequence.id] = rows.length;\n\n const beyond = rows.filter((row) => row.n > sequence.migrations.length);\n if (beyond.length > 0) {\n problems.push({\n code: 'TOO_NEW',\n detail: `${sequence.id}: the database is at ${Math.max(...rows.map((r) => r.n))}, this code knows ${sequence.migrations.length} — it was migrated by newer code.`,\n });\n }\n\n const waiting: PreparedMigration[] = [];\n for (const migration of sequence.migrations) {\n const row = byRef.get(migration.ref);\n if (row === undefined) {\n waiting.push(migration);\n } else if (row.checksum !== migration.checksum) {\n problems.push({\n code: 'EDITED',\n detail: `${migration.ref} (\"${migration.description}\") was applied ${row.appliedAt} and its steps have changed since. An applied migration is history — append a new one.`,\n });\n }\n }\n const firstWaiting = waiting[0];\n if (firstWaiting !== undefined && rows.some((row) => row.n > firstWaiting.n)) {\n problems.push({ code: 'EDITED', detail: `${sequence.id}: ${firstWaiting.ref} never ran, but a later migration of the sequence did.` });\n }\n queues.push({ id: sequence.id, waiting });\n }\n\n if (options.complete === true) {\n const named = new Set(sequences.map((s) => s.id));\n const unknown = [...new Set(ledger.map((row) => row.sequence))].filter((id) => !named.has(id));\n for (const id of unknown) {\n const count = ledger.filter((row) => row.sequence === id).length;\n problems.push({\n code: 'UNKNOWN_SEQUENCE',\n detail:\n `${id}: the database records ${count} of its migration${count === 1 ? '' : 's'} and no code names it. ` +\n 'A sequence that has run stays in the code — to remove its tables, append a migration that drops them. ' +\n 'One app per database schema: two apps sharing a schema share one ledger.',\n });\n }\n }\n\n const provided = new Set(sequences.flatMap((s) => s.migrations.map((m) => m.ref)));\n for (const { waiting } of queues) {\n for (const migration of waiting) {\n for (const dependency of migration.dependsOn) {\n if (!done.has(dependency) && !provided.has(dependency)) {\n problems.push({ code: 'UNKNOWN_DEPENDENCY', detail: `${migration.ref} depends on ${dependency}, which nothing provides and the database has not run.` });\n }\n }\n }\n }\n\n const { pending, stuck } = orderPending(queues, done);\n if (stuck.length > 0 && !problems.some((p) => p.code === 'UNKNOWN_DEPENDENCY')) {\n problems.push({ code: 'CYCLE', detail: `These wait on each other and can never run: ${stuck.map((m) => m.ref).join(', ')}.` });\n }\n\n return { applied, pending, problems };\n};\n\nexport const refuseProblems = (plan: Plan): void => {\n const first = plan.problems[0];\n if (first === undefined) return;\n throw new StrataError(first.code, 'The migrations cannot be applied safely.', plan.problems.map((p) => `${p.code}: ${p.detail}`));\n};\n"]}
|
|
@@ -70,7 +70,8 @@ var prepare = async (sequences) => {
|
|
|
70
70
|
const parsed = SequenceSchema.safeParse(input);
|
|
71
71
|
if (!parsed.success) {
|
|
72
72
|
const issues = parsed.error.issues.map((i) => `${i.path.join(".") || "(root)"}: ${i.message}`);
|
|
73
|
-
|
|
73
|
+
const id = typeof input === "object" && input !== null ? input.id : void 0;
|
|
74
|
+
throw new StrataError("INVALID_SEQUENCE", `A sequence does not parse${typeof id === "string" ? ` ("${id}")` : ""}.`, issues);
|
|
74
75
|
}
|
|
75
76
|
const sequence = parsed.data;
|
|
76
77
|
if (seen.has(sequence.id)) {
|
|
@@ -182,5 +183,5 @@ var refuseProblems = (plan) => {
|
|
|
182
183
|
};
|
|
183
184
|
|
|
184
185
|
export { DocumentKindSchema, DocumentStepSchema, EMBED_PATH, KIND_NAME, KIND_REF, MIGRATION_REF, MigrationSchema, SEQUENCE_ID, SequenceSchema, SqlStepSchema, StepSchema, checksumOf, orderPending, planMigrations, prepare, refuseProblems };
|
|
185
|
-
//# sourceMappingURL=chunk-
|
|
186
|
-
//# sourceMappingURL=chunk-
|
|
186
|
+
//# sourceMappingURL=chunk-YCQ6LS7X.js.map
|
|
187
|
+
//# sourceMappingURL=chunk-YCQ6LS7X.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schema.ts","../src/checksum.ts","../src/plan.ts"],"names":[],"mappings":";;;AAEO,IAAM,WAAA,GAAc;AAEpB,IAAM,aAAA,GAAgB;AAEtB,IAAM,SAAA,GAAY;AAClB,IAAM,QAAA,GAAW;AAKjB,IAAM,UAAA,GAAa;AAEnB,IAAM,aAAA,GAAgB,EAC1B,MAAA,CAAO;AAAA,EACN,IAAA,EAAM,CAAA,CAAE,OAAA,CAAQ,KAAK,CAAA;AAAA,EACrB,KAAK,CAAA,CACF,MAAA,EAAO,CACP,GAAA,CAAI,CAAC,CAAA,C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MAAA,EAAW;AACzB,EAAA,MAAM,IAAI,WAAA,CAAY,KAAA,CAAM,IAAA,EAAM,0CAAA,EAA4C,KAAK,QAAA,CAAS,GAAA,CAAI,CAAC,CAAA,KAAM,GAAG,CAAA,CAAE,IAAI,KAAK,CAAA,CAAE,MAAM,EAAE,CAAC,CAAA;AAClI","file":"chunk-YCQ6LS7X.js","sourcesContent":["import { z } from 'zod';\n\nexport const SEQUENCE_ID = /^[a-z][a-z0-9-]*(\\.[a-z][a-z0-9-]*)+$/;\n\nexport const MIGRATION_REF = /^[a-z][a-z0-9-]*(\\.[a-z][a-z0-9-]*)+\\/[1-9][0-9]*$/;\n\nexport const KIND_NAME = /^[a-z][a-z0-9-]*$/;\nexport const KIND_REF = /^[a-z][a-z0-9-]*(\\.[a-z][a-z0-9-]*)+\\/[a-z][a-z0-9-]*$/;\n\n// `children[]` crosses the array at `children`, `endpoints.*` the record at\n// `endpoints`. Two wildcards, not one: nova's `children` is a single node or an\n// array, and one for both would read a lone node's `props` as layouts.\nexport const EMBED_PATH = /^([A-Za-z_$][\\w$]*|\\*)(\\[\\])?(\\.([A-Za-z_$][\\w$]*|\\*)(\\[\\])?)*$/;\n\nexport const SqlStepSchema = z\n .object({\n kind: z.literal('sql'),\n sql: z\n .string()\n .min(1)\n .describe(\n 'ONE SQL statement. A driver that prepares statements (PGlite, pg with parameters) refuses a string ' +\n 'carrying several — split them into steps rather than joining them with semicolons.',\n ),\n })\n .strict()\n .describe('A statement run against the database, inside the migration transaction.');\n\nexport const DocumentStepSchema = z\n .object({\n kind: z.literal('document'),\n at: z\n .string()\n .regex(KIND_REF)\n .describe('The kind of document this step rewrites, e.g. \"nisc.nova/layout\" — wherever one sits, at any depth.'),\n transform: z\n .unknown()\n .describe(\n 'A transform config (Prism) run by the injected evaluator over { document, path }: `document` is ONE document of ' +\n 'the `at` kind, `path` where it sits. It returns that document rewritten. Nested documents are found by the ' +\n 'grammar\\'s embeddings and rewritten on their own, deepest first — a transform only ever sees one flat node.',\n ),\n })\n .strict()\n .describe('A rewrite of stored JSON documents of one kind.');\n\nexport const StepSchema = z.discriminatedUnion('kind', [SqlStepSchema, DocumentStepSchema]);\n\nexport const DocumentKindSchema = z\n .object({\n embeds: z\n .record(z.string().regex(EMBED_PATH), z.string().regex(KIND_REF))\n .optional()\n .describe('Where other documents sit inside this one: path → the kind found there (possibly this kind itself).'),\n })\n .strict();\n\nexport const MigrationSchema = z\n .object({\n description: z\n .string()\n .min(1)\n .describe('One sentence: what this migration does. It is the changelog line and the ledger\\'s description.'),\n steps: z\n .array(StepSchema)\n .describe(\n 'Applied in order, in the same transaction as every other pending migration. Empty is a MARKER: ' +\n 'the version moves and nothing runs — how an addition to a strict grammar tells older readers to refuse.',\n ),\n dependsOn: z\n .array(z.string().regex(MIGRATION_REF))\n .optional()\n .describe('Migrations of OTHER sequences that must be applied first, each as \"<sequence>/<n>\".'),\n })\n .strict();\n\nexport const SequenceSchema = z\n .object({\n id: z.string().regex(SEQUENCE_ID).describe('Namespaced and lowercase, e.g. \"nisc.vex.cache\" or \"midas.app\".'),\n documents: z\n .record(z.string().regex(KIND_NAME), DocumentKindSchema)\n .optional()\n .describe('The document kinds this sequence owns (a GRAMMAR sequence), each named \"<id>/<kind>\" elsewhere.'),\n migrations: z\n .array(MigrationSchema)\n .describe('Append-only. A migration is numbered by its position (from 1); the sequence\\'s version is its length.'),\n })\n .strict()\n // Not both: a table sequence's version is recorded per database, a grammar\n // sequence's per document (its stamp), and one number cannot be both.\n .superRefine((sequence, ctx) => {\n const kinds = new Set(sequence.migrations.flatMap((m) => m.steps.map((s) => s.kind)));\n if (kinds.has('sql') && (kinds.has('document') || sequence.documents !== undefined)) {\n ctx.addIssue({\n code: 'custom',\n message: 'A sequence either owns tables (sql steps) or documents (document steps and `documents`), not both.',\n });\n }\n });\n\nexport type SqlStep = z.infer<typeof SqlStepSchema>;\nexport type DocumentStep = z.infer<typeof DocumentStepSchema>;\nexport type DocumentKind = z.infer<typeof DocumentKindSchema>;\nexport type Step = z.infer<typeof StepSchema>;\nexport type Migration = z.infer<typeof MigrationSchema>;\nexport type Sequence = z.infer<typeof SequenceSchema>;\n","import type { Migration } from './schema';\n\nconst canonical = (value: unknown): string => {\n if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`;\n if (value !== null && typeof value === 'object') {\n const entries = Object.entries(value)\n .filter(([, v]) => v !== undefined)\n .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));\n return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`).join(',')}}`;\n }\n return JSON.stringify(value);\n};\n\nconst effectOf = (sql: string): string =>\n sql\n .split('\\n')\n .filter((line) => !line.trimStart().startsWith('--'))\n .map((line) => line.trimEnd())\n .join('\\n')\n .trim();\n\nexport const checksumOf = async (migration: Migration): Promise<string> => {\n const steps = migration.steps.map((step) => (step.kind === 'sql' ? { ...step, sql: effectOf(step.sql) } : step));\n const bytes = new TextEncoder().encode(canonical(steps));\n const digest = await crypto.subtle.digest('SHA-256', bytes);\n return Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, '0')).join('');\n};\n","import { SequenceSchema, type DocumentKind, type Sequence, type Step } from './schema';\nimport { checksumOf } from './checksum';\nimport { StrataError, type StrataErrorCode } from './errors';\n\nexport type PreparedMigration = {\n sequence: string;\n n: number;\n ref: string;\n description: string;\n checksum: string;\n steps: readonly Step[];\n dependsOn: readonly string[];\n};\n\nexport type PreparedSequence = {\n id: string;\n grammar: boolean;\n documents: Readonly<Record<string, DocumentKind>>;\n migrations: readonly PreparedMigration[];\n};\n\nexport type LedgerRow = { sequence: string; n: number; checksum: string; description: string; appliedAt: string };\n\nexport type Problem = { code: Exclude<StrataErrorCode, 'PENDING' | 'STEP_FAILED' | 'DOES_NOT_FIT' | 'NO_TRANSACTION' | 'UNKNOWN_KIND' | 'WRONG_OWNER'>; detail: string };\n\nexport type Plan = {\n applied: Readonly<Record<string, number>>;\n pending: readonly PreparedMigration[];\n problems: readonly Problem[];\n};\n\nconst refOf = (sequence: string, n: number): string => `${sequence}/${n}`;\n\nexport const prepare = async (sequences: readonly Sequence[]): Promise<readonly PreparedSequence[]> => {\n const seen = new Set<string>();\n const prepared: PreparedSequence[] = [];\n for (const input of sequences) {\n const parsed = SequenceSchema.safeParse(input);\n if (!parsed.success) {\n const issues = parsed.error.issues.map((i) => `${i.path.join('.') || '(root)'}: ${i.message}`);\n const id: unknown = typeof input === 'object' && input !== null ? input.id : undefined;\n throw new StrataError('INVALID_SEQUENCE', `A sequence does not parse${typeof id === 'string' ? ` (\"${id}\")` : ''}.`, issues);\n }\n const sequence = parsed.data;\n if (seen.has(sequence.id)) {\n throw new StrataError('INVALID_SEQUENCE', `Two sequences are both called \"${sequence.id}\" — a sequence id names one owner.`);\n }\n seen.add(sequence.id);\n const migrations: PreparedMigration[] = [];\n for (const [index, migration] of sequence.migrations.entries()) {\n const n = index + 1;\n migrations.push({\n sequence: sequence.id,\n n,\n ref: refOf(sequence.id, n),\n description: migration.description,\n checksum: await checksumOf(migration),\n steps: migration.steps,\n dependsOn: migration.dependsOn ?? [],\n });\n }\n const grammar = sequence.documents !== undefined || sequence.migrations.some((m) => m.steps.some((s) => s.kind === 'document'));\n prepared.push({ id: sequence.id, grammar, documents: sequence.documents ?? {}, migrations });\n }\n return prepared;\n};\n\nexport const orderPending = (\n queues: readonly { waiting: readonly PreparedMigration[] }[],\n alreadyDone: ReadonlySet<string>,\n): { pending: PreparedMigration[]; stuck: PreparedMigration[] } => {\n const done = new Set(alreadyDone);\n const waiting = queues.map((q) => [...q.waiting]);\n const pending: PreparedMigration[] = [];\n let moved = true;\n while (moved) {\n moved = false;\n for (const queue of waiting) {\n for (let head = queue[0]; head !== undefined; head = queue[0]) {\n if (!head.dependsOn.every((d) => done.has(d))) break;\n pending.push(head);\n done.add(head.ref);\n queue.shift();\n moved = true;\n }\n }\n }\n return { pending, stuck: waiting.flat() };\n};\n\nexport type PlanOptions = {\n // The sequences given are every sequence the ledger may record.\n complete?: boolean;\n};\n\nexport const planMigrations = (sequences: readonly PreparedSequence[], ledger: readonly LedgerRow[], options: PlanOptions = {}): Plan => {\n const problems: Problem[] = [];\n const applied: Record<string, number> = {};\n const done = new Set(ledger.map((row) => refOf(row.sequence, row.n)));\n const byRef = new Map(ledger.map((row) => [refOf(row.sequence, row.n), row]));\n\n const queues: { id: string; waiting: PreparedMigration[] }[] = [];\n for (const sequence of sequences) {\n const rows = ledger.filter((row) => row.sequence === sequence.id);\n applied[sequence.id] = rows.length;\n\n const beyond = rows.filter((row) => row.n > sequence.migrations.length);\n if (beyond.length > 0) {\n problems.push({\n code: 'TOO_NEW',\n detail: `${sequence.id}: the database is at ${Math.max(...rows.map((r) => r.n))}, this code knows ${sequence.migrations.length} — it was migrated by newer code.`,\n });\n }\n\n const waiting: PreparedMigration[] = [];\n for (const migration of sequence.migrations) {\n const row = byRef.get(migration.ref);\n if (row === undefined) {\n waiting.push(migration);\n } else if (row.checksum !== migration.checksum) {\n problems.push({\n code: 'EDITED',\n detail: `${migration.ref} (\"${migration.description}\") was applied ${row.appliedAt} and its steps have changed since. An applied migration is history — append a new one.`,\n });\n }\n }\n const firstWaiting = waiting[0];\n if (firstWaiting !== undefined && rows.some((row) => row.n > firstWaiting.n)) {\n problems.push({ code: 'EDITED', detail: `${sequence.id}: ${firstWaiting.ref} never ran, but a later migration of the sequence did.` });\n }\n queues.push({ id: sequence.id, waiting });\n }\n\n if (options.complete === true) {\n const named = new Set(sequences.map((s) => s.id));\n const unknown = [...new Set(ledger.map((row) => row.sequence))].filter((id) => !named.has(id));\n for (const id of unknown) {\n const count = ledger.filter((row) => row.sequence === id).length;\n problems.push({\n code: 'UNKNOWN_SEQUENCE',\n detail:\n `${id}: the database records ${count} of its migration${count === 1 ? '' : 's'} and no code names it. ` +\n 'A sequence that has run stays in the code — to remove its tables, append a migration that drops them. ' +\n 'One app per database schema: two apps sharing a schema share one ledger.',\n });\n }\n }\n\n const provided = new Set(sequences.flatMap((s) => s.migrations.map((m) => m.ref)));\n for (const { waiting } of queues) {\n for (const migration of waiting) {\n for (const dependency of migration.dependsOn) {\n if (!done.has(dependency) && !provided.has(dependency)) {\n problems.push({ code: 'UNKNOWN_DEPENDENCY', detail: `${migration.ref} depends on ${dependency}, which nothing provides and the database has not run.` });\n }\n }\n }\n }\n\n const { pending, stuck } = orderPending(queues, done);\n if (stuck.length > 0 && !problems.some((p) => p.code === 'UNKNOWN_DEPENDENCY')) {\n problems.push({ code: 'CYCLE', detail: `These wait on each other and can never run: ${stuck.map((m) => m.ref).join(', ')}.` });\n }\n\n return { applied, pending, problems };\n};\n\nexport const refuseProblems = (plan: Plan): void => {\n const first = plan.problems[0];\n if (first === undefined) return;\n throw new StrataError(first.code, 'The migrations cannot be applied safely.', plan.problems.map((p) => `${p.code}: ${p.detail}`));\n};\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkFMXFHYU2_cjs = require('./chunk-FMXFHYU2.cjs');
|
|
4
|
+
var chunkSJNHLIKR_cjs = require('./chunk-SJNHLIKR.cjs');
|
|
5
5
|
var chunk7PBIGCLL_cjs = require('./chunk-7PBIGCLL.cjs');
|
|
6
6
|
|
|
7
7
|
// src/sql.ts
|
|
@@ -41,71 +41,71 @@ var defineSequence = (sequence) => sequence;
|
|
|
41
41
|
|
|
42
42
|
Object.defineProperty(exports, "createUpgrader", {
|
|
43
43
|
enumerable: true,
|
|
44
|
-
get: function () { return
|
|
44
|
+
get: function () { return chunkFMXFHYU2_cjs.createUpgrader; }
|
|
45
45
|
});
|
|
46
46
|
Object.defineProperty(exports, "DocumentKindSchema", {
|
|
47
47
|
enumerable: true,
|
|
48
|
-
get: function () { return
|
|
48
|
+
get: function () { return chunkSJNHLIKR_cjs.DocumentKindSchema; }
|
|
49
49
|
});
|
|
50
50
|
Object.defineProperty(exports, "DocumentStepSchema", {
|
|
51
51
|
enumerable: true,
|
|
52
|
-
get: function () { return
|
|
52
|
+
get: function () { return chunkSJNHLIKR_cjs.DocumentStepSchema; }
|
|
53
53
|
});
|
|
54
54
|
Object.defineProperty(exports, "EMBED_PATH", {
|
|
55
55
|
enumerable: true,
|
|
56
|
-
get: function () { return
|
|
56
|
+
get: function () { return chunkSJNHLIKR_cjs.EMBED_PATH; }
|
|
57
57
|
});
|
|
58
58
|
Object.defineProperty(exports, "KIND_NAME", {
|
|
59
59
|
enumerable: true,
|
|
60
|
-
get: function () { return
|
|
60
|
+
get: function () { return chunkSJNHLIKR_cjs.KIND_NAME; }
|
|
61
61
|
});
|
|
62
62
|
Object.defineProperty(exports, "KIND_REF", {
|
|
63
63
|
enumerable: true,
|
|
64
|
-
get: function () { return
|
|
64
|
+
get: function () { return chunkSJNHLIKR_cjs.KIND_REF; }
|
|
65
65
|
});
|
|
66
66
|
Object.defineProperty(exports, "MIGRATION_REF", {
|
|
67
67
|
enumerable: true,
|
|
68
|
-
get: function () { return
|
|
68
|
+
get: function () { return chunkSJNHLIKR_cjs.MIGRATION_REF; }
|
|
69
69
|
});
|
|
70
70
|
Object.defineProperty(exports, "MigrationSchema", {
|
|
71
71
|
enumerable: true,
|
|
72
|
-
get: function () { return
|
|
72
|
+
get: function () { return chunkSJNHLIKR_cjs.MigrationSchema; }
|
|
73
73
|
});
|
|
74
74
|
Object.defineProperty(exports, "SEQUENCE_ID", {
|
|
75
75
|
enumerable: true,
|
|
76
|
-
get: function () { return
|
|
76
|
+
get: function () { return chunkSJNHLIKR_cjs.SEQUENCE_ID; }
|
|
77
77
|
});
|
|
78
78
|
Object.defineProperty(exports, "SequenceSchema", {
|
|
79
79
|
enumerable: true,
|
|
80
|
-
get: function () { return
|
|
80
|
+
get: function () { return chunkSJNHLIKR_cjs.SequenceSchema; }
|
|
81
81
|
});
|
|
82
82
|
Object.defineProperty(exports, "SqlStepSchema", {
|
|
83
83
|
enumerable: true,
|
|
84
|
-
get: function () { return
|
|
84
|
+
get: function () { return chunkSJNHLIKR_cjs.SqlStepSchema; }
|
|
85
85
|
});
|
|
86
86
|
Object.defineProperty(exports, "StepSchema", {
|
|
87
87
|
enumerable: true,
|
|
88
|
-
get: function () { return
|
|
88
|
+
get: function () { return chunkSJNHLIKR_cjs.StepSchema; }
|
|
89
89
|
});
|
|
90
90
|
Object.defineProperty(exports, "checksumOf", {
|
|
91
91
|
enumerable: true,
|
|
92
|
-
get: function () { return
|
|
92
|
+
get: function () { return chunkSJNHLIKR_cjs.checksumOf; }
|
|
93
93
|
});
|
|
94
94
|
Object.defineProperty(exports, "orderPending", {
|
|
95
95
|
enumerable: true,
|
|
96
|
-
get: function () { return
|
|
96
|
+
get: function () { return chunkSJNHLIKR_cjs.orderPending; }
|
|
97
97
|
});
|
|
98
98
|
Object.defineProperty(exports, "planMigrations", {
|
|
99
99
|
enumerable: true,
|
|
100
|
-
get: function () { return
|
|
100
|
+
get: function () { return chunkSJNHLIKR_cjs.planMigrations; }
|
|
101
101
|
});
|
|
102
102
|
Object.defineProperty(exports, "prepare", {
|
|
103
103
|
enumerable: true,
|
|
104
|
-
get: function () { return
|
|
104
|
+
get: function () { return chunkSJNHLIKR_cjs.prepare; }
|
|
105
105
|
});
|
|
106
106
|
Object.defineProperty(exports, "refuseProblems", {
|
|
107
107
|
enumerable: true,
|
|
108
|
-
get: function () { return
|
|
108
|
+
get: function () { return chunkSJNHLIKR_cjs.refuseProblems; }
|
|
109
109
|
});
|
|
110
110
|
Object.defineProperty(exports, "StrataError", {
|
|
111
111
|
enumerable: true,
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { createUpgrader } from './chunk-
|
|
2
|
-
export { DocumentKindSchema, DocumentStepSchema, EMBED_PATH, KIND_NAME, KIND_REF, MIGRATION_REF, MigrationSchema, SEQUENCE_ID, SequenceSchema, SqlStepSchema, StepSchema, checksumOf, orderPending, planMigrations, prepare, refuseProblems } from './chunk-
|
|
1
|
+
export { createUpgrader } from './chunk-LJAB5G5Y.js';
|
|
2
|
+
export { DocumentKindSchema, DocumentStepSchema, EMBED_PATH, KIND_NAME, KIND_REF, MIGRATION_REF, MigrationSchema, SEQUENCE_ID, SequenceSchema, SqlStepSchema, StepSchema, checksumOf, orderPending, planMigrations, prepare, refuseProblems } from './chunk-YCQ6LS7X.js';
|
|
3
3
|
export { StrataError } from './chunk-STNFHBNR.js';
|
|
4
4
|
|
|
5
5
|
// src/sql.ts
|