@prisma-next/migration-tools 0.5.0-dev.6 → 0.5.0-dev.60

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 (91) hide show
  1. package/README.md +34 -22
  2. package/dist/{constants-BRi0X7B_.mjs → constants-BQEHsaEx.mjs} +1 -1
  3. package/dist/{constants-BRi0X7B_.mjs.map → constants-BQEHsaEx.mjs.map} +1 -1
  4. package/dist/errors-CfmjBeK0.mjs +272 -0
  5. package/dist/errors-CfmjBeK0.mjs.map +1 -0
  6. package/dist/exports/constants.mjs +1 -1
  7. package/dist/exports/errors.d.mts +63 -0
  8. package/dist/exports/errors.d.mts.map +1 -0
  9. package/dist/exports/errors.mjs +3 -0
  10. package/dist/exports/graph.d.mts +2 -0
  11. package/dist/exports/graph.mjs +1 -0
  12. package/dist/exports/hash.d.mts +52 -0
  13. package/dist/exports/hash.d.mts.map +1 -0
  14. package/dist/exports/hash.mjs +3 -0
  15. package/dist/exports/invariants.d.mts +24 -0
  16. package/dist/exports/invariants.d.mts.map +1 -0
  17. package/dist/exports/invariants.mjs +4 -0
  18. package/dist/exports/io.d.mts +7 -6
  19. package/dist/exports/io.d.mts.map +1 -1
  20. package/dist/exports/io.mjs +162 -2
  21. package/dist/exports/io.mjs.map +1 -0
  22. package/dist/exports/metadata.d.mts +2 -0
  23. package/dist/exports/metadata.mjs +1 -0
  24. package/dist/exports/migration-graph.d.mts +124 -0
  25. package/dist/exports/migration-graph.d.mts.map +1 -0
  26. package/dist/exports/migration-graph.mjs +526 -0
  27. package/dist/exports/migration-graph.mjs.map +1 -0
  28. package/dist/exports/migration-ts.mjs +1 -1
  29. package/dist/exports/migration.d.mts +15 -14
  30. package/dist/exports/migration.d.mts.map +1 -1
  31. package/dist/exports/migration.mjs +69 -41
  32. package/dist/exports/migration.mjs.map +1 -1
  33. package/dist/exports/package.d.mts +2 -0
  34. package/dist/exports/package.mjs +1 -0
  35. package/dist/exports/refs.mjs +2 -2
  36. package/dist/graph-BHPv-9Gl.d.mts +28 -0
  37. package/dist/graph-BHPv-9Gl.d.mts.map +1 -0
  38. package/dist/hash-BARZdVgW.mjs +76 -0
  39. package/dist/hash-BARZdVgW.mjs.map +1 -0
  40. package/dist/invariants-30VA65sB.mjs +42 -0
  41. package/dist/invariants-30VA65sB.mjs.map +1 -0
  42. package/dist/metadata-BP1cmU7Z.d.mts +50 -0
  43. package/dist/metadata-BP1cmU7Z.d.mts.map +1 -0
  44. package/dist/op-schema-DZKFua46.mjs +14 -0
  45. package/dist/op-schema-DZKFua46.mjs.map +1 -0
  46. package/dist/package-5HCCg0z-.d.mts +21 -0
  47. package/dist/package-5HCCg0z-.d.mts.map +1 -0
  48. package/package.json +31 -14
  49. package/src/errors.ts +210 -17
  50. package/src/exports/errors.ts +7 -0
  51. package/src/exports/graph.ts +1 -0
  52. package/src/exports/hash.ts +2 -0
  53. package/src/exports/invariants.ts +1 -0
  54. package/src/exports/io.ts +1 -1
  55. package/src/exports/metadata.ts +1 -0
  56. package/src/exports/{dag.ts → migration-graph.ts} +3 -2
  57. package/src/exports/migration.ts +0 -1
  58. package/src/exports/package.ts +1 -0
  59. package/src/graph-ops.ts +57 -30
  60. package/src/graph.ts +25 -0
  61. package/src/hash.ts +91 -0
  62. package/src/invariants.ts +45 -0
  63. package/src/io.ts +57 -31
  64. package/src/metadata.ts +41 -0
  65. package/src/migration-base.ts +97 -56
  66. package/src/migration-graph.ts +676 -0
  67. package/src/op-schema.ts +11 -0
  68. package/src/package.ts +18 -0
  69. package/dist/attestation-BnzTb0Qp.mjs +0 -65
  70. package/dist/attestation-BnzTb0Qp.mjs.map +0 -1
  71. package/dist/errors-BmiSgz1j.mjs +0 -160
  72. package/dist/errors-BmiSgz1j.mjs.map +0 -1
  73. package/dist/exports/attestation.d.mts +0 -37
  74. package/dist/exports/attestation.d.mts.map +0 -1
  75. package/dist/exports/attestation.mjs +0 -4
  76. package/dist/exports/dag.d.mts +0 -51
  77. package/dist/exports/dag.d.mts.map +0 -1
  78. package/dist/exports/dag.mjs +0 -386
  79. package/dist/exports/dag.mjs.map +0 -1
  80. package/dist/exports/types.d.mts +0 -35
  81. package/dist/exports/types.d.mts.map +0 -1
  82. package/dist/exports/types.mjs +0 -3
  83. package/dist/io-Cd6GLyjK.mjs +0 -153
  84. package/dist/io-Cd6GLyjK.mjs.map +0 -1
  85. package/dist/types-DyGXcWWp.d.mts +0 -71
  86. package/dist/types-DyGXcWWp.d.mts.map +0 -1
  87. package/src/attestation.ts +0 -81
  88. package/src/dag.ts +0 -426
  89. package/src/exports/attestation.ts +0 -2
  90. package/src/exports/types.ts +0 -10
  91. package/src/types.ts +0 -66
@@ -1,65 +0,0 @@
1
- import { r as readMigrationPackage } from "./io-Cd6GLyjK.mjs";
2
- import { createHash } from "node:crypto";
3
-
4
- //#region src/canonicalize-json.ts
5
- function sortKeys(value) {
6
- if (value === null || typeof value !== "object") return value;
7
- if (Array.isArray(value)) return value.map(sortKeys);
8
- const sorted = {};
9
- for (const key of Object.keys(value).sort()) sorted[key] = sortKeys(value[key]);
10
- return sorted;
11
- }
12
- function canonicalizeJson(value) {
13
- return JSON.stringify(sortKeys(value));
14
- }
15
-
16
- //#endregion
17
- //#region src/attestation.ts
18
- function sha256Hex(input) {
19
- return createHash("sha256").update(input).digest("hex");
20
- }
21
- /**
22
- * Content-addressed migration identity over (manifest envelope sans
23
- * contracts/hints, ops). See ADR 199 "Storage-only migration identity"
24
- * for the rationale: contracts are anchored separately by the
25
- * storage-hash bookends inside the envelope; planner hints are advisory
26
- * and must not affect identity.
27
- *
28
- * The `migrationId` field on the manifest is stripped before hashing so
29
- * the function can be used both at write time (when no id exists yet)
30
- * and at verify time (rehashing an already-attested manifest).
31
- */
32
- function computeMigrationId(manifest, ops) {
33
- const { migrationId: _migrationId, signature: _signature, fromContract: _fromContract, toContract: _toContract, hints: _hints, ...strippedMeta } = manifest;
34
- return `sha256:${sha256Hex(canonicalizeJson([canonicalizeJson(strippedMeta), canonicalizeJson(ops)].map(sha256Hex)))}`;
35
- }
36
- /**
37
- * Re-hash an on-disk migration bundle and compare against the stored
38
- * `migrationId`. Returns `{ ok: true }` when the package is internally
39
- * consistent (manifest + ops still produce the recorded id), or
40
- * `{ ok: false, reason: 'mismatch', stored, computed }` when they do
41
- * not — typically a sign of FS corruption, partial writes, or a
42
- * post-emit hand edit.
43
- */
44
- function verifyMigrationBundle(bundle) {
45
- const computed = computeMigrationId(bundle.manifest, bundle.ops);
46
- if (bundle.manifest.migrationId === computed) return {
47
- ok: true,
48
- storedMigrationId: bundle.manifest.migrationId,
49
- computedMigrationId: computed
50
- };
51
- return {
52
- ok: false,
53
- reason: "mismatch",
54
- storedMigrationId: bundle.manifest.migrationId,
55
- computedMigrationId: computed
56
- };
57
- }
58
- /** Convenience wrapper: read the package from disk then verify it. */
59
- async function verifyMigration(dir) {
60
- return verifyMigrationBundle(await readMigrationPackage(dir));
61
- }
62
-
63
- //#endregion
64
- export { verifyMigration as n, verifyMigrationBundle as r, computeMigrationId as t };
65
- //# sourceMappingURL=attestation-BnzTb0Qp.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"attestation-BnzTb0Qp.mjs","names":["sorted: Record<string, unknown>"],"sources":["../src/canonicalize-json.ts","../src/attestation.ts"],"sourcesContent":["function sortKeys(value: unknown): unknown {\n if (value === null || typeof value !== 'object') {\n return value;\n }\n if (Array.isArray(value)) {\n return value.map(sortKeys);\n }\n const sorted: Record<string, unknown> = {};\n for (const key of Object.keys(value).sort()) {\n sorted[key] = sortKeys((value as Record<string, unknown>)[key]);\n }\n return sorted;\n}\n\nexport function canonicalizeJson(value: unknown): string {\n return JSON.stringify(sortKeys(value));\n}\n","import { createHash } from 'node:crypto';\nimport { canonicalizeJson } from './canonicalize-json';\nimport { readMigrationPackage } from './io';\nimport type { MigrationBundle, MigrationManifest, MigrationOps } from './types';\n\nexport interface VerifyResult {\n readonly ok: boolean;\n readonly reason?: 'mismatch';\n readonly storedMigrationId?: string;\n readonly computedMigrationId?: string;\n}\n\nfunction sha256Hex(input: string): string {\n return createHash('sha256').update(input).digest('hex');\n}\n\n/**\n * Content-addressed migration identity over (manifest envelope sans\n * contracts/hints, ops). See ADR 199 \"Storage-only migration identity\"\n * for the rationale: contracts are anchored separately by the\n * storage-hash bookends inside the envelope; planner hints are advisory\n * and must not affect identity.\n *\n * The `migrationId` field on the manifest is stripped before hashing so\n * the function can be used both at write time (when no id exists yet)\n * and at verify time (rehashing an already-attested manifest).\n */\nexport function computeMigrationId(\n manifest: Omit<MigrationManifest, 'migrationId'> & { readonly migrationId?: string },\n ops: MigrationOps,\n): string {\n const {\n migrationId: _migrationId,\n signature: _signature,\n fromContract: _fromContract,\n toContract: _toContract,\n hints: _hints,\n ...strippedMeta\n } = manifest;\n\n const canonicalManifest = canonicalizeJson(strippedMeta);\n const canonicalOps = canonicalizeJson(ops);\n\n const partHashes = [canonicalManifest, canonicalOps].map(sha256Hex);\n const hash = sha256Hex(canonicalizeJson(partHashes));\n\n return `sha256:${hash}`;\n}\n\n/**\n * Re-hash an on-disk migration bundle and compare against the stored\n * `migrationId`. Returns `{ ok: true }` when the package is internally\n * consistent (manifest + ops still produce the recorded id), or\n * `{ ok: false, reason: 'mismatch', stored, computed }` when they do\n * not — typically a sign of FS corruption, partial writes, or a\n * post-emit hand edit.\n */\nexport function verifyMigrationBundle(bundle: MigrationBundle): VerifyResult {\n const computed = computeMigrationId(bundle.manifest, bundle.ops);\n\n if (bundle.manifest.migrationId === computed) {\n return {\n ok: true,\n storedMigrationId: bundle.manifest.migrationId,\n computedMigrationId: computed,\n };\n }\n\n return {\n ok: false,\n reason: 'mismatch',\n storedMigrationId: bundle.manifest.migrationId,\n computedMigrationId: computed,\n };\n}\n\n/** Convenience wrapper: read the package from disk then verify it. */\nexport async function verifyMigration(dir: string): Promise<VerifyResult> {\n const pkg = await readMigrationPackage(dir);\n return verifyMigrationBundle(pkg);\n}\n"],"mappings":";;;;AAAA,SAAS,SAAS,OAAyB;AACzC,KAAI,UAAU,QAAQ,OAAO,UAAU,SACrC,QAAO;AAET,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,MAAM,IAAI,SAAS;CAE5B,MAAMA,SAAkC,EAAE;AAC1C,MAAK,MAAM,OAAO,OAAO,KAAK,MAAM,CAAC,MAAM,CACzC,QAAO,OAAO,SAAU,MAAkC,KAAK;AAEjE,QAAO;;AAGT,SAAgB,iBAAiB,OAAwB;AACvD,QAAO,KAAK,UAAU,SAAS,MAAM,CAAC;;;;;ACHxC,SAAS,UAAU,OAAuB;AACxC,QAAO,WAAW,SAAS,CAAC,OAAO,MAAM,CAAC,OAAO,MAAM;;;;;;;;;;;;;AAczD,SAAgB,mBACd,UACA,KACQ;CACR,MAAM,EACJ,aAAa,cACb,WAAW,YACX,cAAc,eACd,YAAY,aACZ,OAAO,QACP,GAAG,iBACD;AAQJ,QAAO,UAFM,UAAU,iBADJ,CAHO,iBAAiB,aAAa,EACnC,iBAAiB,IAAI,CAEU,CAAC,IAAI,UAAU,CAChB,CAAC;;;;;;;;;;AAatD,SAAgB,sBAAsB,QAAuC;CAC3E,MAAM,WAAW,mBAAmB,OAAO,UAAU,OAAO,IAAI;AAEhE,KAAI,OAAO,SAAS,gBAAgB,SAClC,QAAO;EACL,IAAI;EACJ,mBAAmB,OAAO,SAAS;EACnC,qBAAqB;EACtB;AAGH,QAAO;EACL,IAAI;EACJ,QAAQ;EACR,mBAAmB,OAAO,SAAS;EACnC,qBAAqB;EACtB;;;AAIH,eAAsB,gBAAgB,KAAoC;AAExE,QAAO,sBADK,MAAM,qBAAqB,IAAI,CACV"}
@@ -1,160 +0,0 @@
1
- //#region src/errors.ts
2
- /**
3
- * Structured error for migration tooling operations.
4
- *
5
- * Follows the NAMESPACE.SUBCODE convention from ADR 027. All codes live under
6
- * the MIGRATION namespace. These are tooling-time errors (file I/O, attestation,
7
- * migration history reconstruction), distinct from the runtime MIGRATION.* codes for apply-time
8
- * failures (PRECHECK_FAILED, POSTCHECK_FAILED, etc.).
9
- *
10
- * Fields:
11
- * - code: Stable machine-readable code (MIGRATION.SUBCODE)
12
- * - category: Always 'MIGRATION'
13
- * - why: Explains the cause in plain language
14
- * - fix: Actionable remediation step
15
- * - details: Machine-readable structured data for agents
16
- */
17
- var MigrationToolsError = class extends Error {
18
- code;
19
- category = "MIGRATION";
20
- why;
21
- fix;
22
- details;
23
- constructor(code, summary, options) {
24
- super(summary);
25
- this.name = "MigrationToolsError";
26
- this.code = code;
27
- this.why = options.why;
28
- this.fix = options.fix;
29
- this.details = options.details;
30
- }
31
- static is(error) {
32
- if (!(error instanceof Error)) return false;
33
- const candidate = error;
34
- return candidate.name === "MigrationToolsError" && typeof candidate.code === "string";
35
- }
36
- };
37
- function errorDirectoryExists(dir) {
38
- return new MigrationToolsError("MIGRATION.DIR_EXISTS", "Migration directory already exists", {
39
- why: `The directory "${dir}" already exists. Each migration must have a unique directory.`,
40
- fix: "Use --name to pick a different name, or delete the existing directory and re-run.",
41
- details: { dir }
42
- });
43
- }
44
- function errorMissingFile(file, dir) {
45
- return new MigrationToolsError("MIGRATION.FILE_MISSING", `Missing ${file}`, {
46
- why: `Expected "${file}" in "${dir}" but the file does not exist.`,
47
- fix: "Ensure the migration directory contains both migration.json and ops.json. If the directory is corrupt, delete it and re-run migration plan.",
48
- details: {
49
- file,
50
- dir
51
- }
52
- });
53
- }
54
- function errorInvalidJson(filePath, parseError) {
55
- return new MigrationToolsError("MIGRATION.INVALID_JSON", "Invalid JSON in migration file", {
56
- why: `Failed to parse "${filePath}": ${parseError}`,
57
- fix: "Fix the JSON syntax error, or delete the migration directory and re-run migration plan.",
58
- details: {
59
- filePath,
60
- parseError
61
- }
62
- });
63
- }
64
- function errorInvalidManifest(filePath, reason) {
65
- return new MigrationToolsError("MIGRATION.INVALID_MANIFEST", "Invalid migration manifest", {
66
- why: `Manifest at "${filePath}" is invalid: ${reason}`,
67
- fix: "Ensure the manifest has all required fields (from, to, kind, toContract). If corrupt, delete and re-plan.",
68
- details: {
69
- filePath,
70
- reason
71
- }
72
- });
73
- }
74
- function errorInvalidSlug(slug) {
75
- return new MigrationToolsError("MIGRATION.INVALID_NAME", "Invalid migration name", {
76
- why: `The slug "${slug}" contains no valid characters after sanitization (only a-z, 0-9 are kept).`,
77
- fix: "Provide a name with at least one alphanumeric character, e.g. --name add_users.",
78
- details: { slug }
79
- });
80
- }
81
- function errorInvalidDestName(destName) {
82
- return new MigrationToolsError("MIGRATION.INVALID_DEST_NAME", "Invalid copy destination name", {
83
- why: `The destination name "${destName}" must be a single path segment (no ".." or directory separators).`,
84
- fix: "Use a simple file name such as \"contract.json\" for each destination in the copy list.",
85
- details: { destName }
86
- });
87
- }
88
- function errorSameSourceAndTarget(dirName, hash) {
89
- return new MigrationToolsError("MIGRATION.SAME_SOURCE_AND_TARGET", "Migration has same source and target", {
90
- why: `Migration "${dirName}" has from === to === "${hash}". A migration must transition between two different contract states.`,
91
- fix: "Delete the invalid migration directory and re-run migration plan.",
92
- details: {
93
- dirName,
94
- hash
95
- }
96
- });
97
- }
98
- function errorAmbiguousTarget(branchTips, context) {
99
- const divergenceInfo = context ? `\nDivergence point: ${context.divergencePoint}\nBranches:\n${context.branches.map((b) => ` → ${b.tip} (${b.edges.length} edge(s): ${b.edges.map((e) => e.dirName).join(" → ") || "direct"})`).join("\n")}` : "";
100
- return new MigrationToolsError("MIGRATION.AMBIGUOUS_TARGET", "Ambiguous migration target", {
101
- why: `The migration history has diverged into multiple branches: ${branchTips.join(", ")}. This typically happens when two developers plan migrations from the same starting point.${divergenceInfo}`,
102
- fix: "Use `migration ref set <name> <hash>` to target a specific branch, delete one of the conflicting migration directories and re-run `migration plan`, or use --from <hash> to explicitly select a starting point.",
103
- details: {
104
- branchTips,
105
- ...context ? {
106
- divergencePoint: context.divergencePoint,
107
- branches: context.branches
108
- } : {}
109
- }
110
- });
111
- }
112
- function errorNoInitialMigration(nodes) {
113
- return new MigrationToolsError("MIGRATION.NO_INITIAL_MIGRATION", "No initial migration found", {
114
- why: `No migration starts from the empty contract state (known hashes: ${nodes.join(", ")}). At least one migration must originate from the empty state.`,
115
- fix: "Inspect the migrations directory for corrupted migration.json files. At least one migration must start from the empty contract hash.",
116
- details: { nodes }
117
- });
118
- }
119
- function errorInvalidRefFile(filePath, reason) {
120
- return new MigrationToolsError("MIGRATION.INVALID_REF_FILE", "Invalid ref file", {
121
- why: `Ref file at "${filePath}" is invalid: ${reason}`,
122
- fix: "Ensure the ref file contains valid JSON with { \"hash\": \"sha256:<64 hex chars>\", \"invariants\": [\"...\"] }.",
123
- details: {
124
- path: filePath,
125
- reason
126
- }
127
- });
128
- }
129
- function errorInvalidRefName(refName) {
130
- return new MigrationToolsError("MIGRATION.INVALID_REF_NAME", "Invalid ref name", {
131
- why: `Ref name "${refName}" is invalid. Names must be lowercase alphanumeric with hyphens or forward slashes (no "." or ".." segments).`,
132
- fix: `Use a valid ref name (e.g., "staging", "envs/production").`,
133
- details: { refName }
134
- });
135
- }
136
- function errorNoTarget(reachableHashes) {
137
- return new MigrationToolsError("MIGRATION.NO_TARGET", "No migration target could be resolved", {
138
- why: `The migration history contains cycles and no target can be resolved automatically (reachable hashes: ${reachableHashes.join(", ")}). This typically happens after rollback migrations (e.g., C1→C2→C1).`,
139
- fix: "Use --from <hash> to specify the planning origin explicitly.",
140
- details: { reachableHashes }
141
- });
142
- }
143
- function errorInvalidRefValue(value) {
144
- return new MigrationToolsError("MIGRATION.INVALID_REF_VALUE", "Invalid ref value", {
145
- why: `Ref value "${value}" is not a valid contract hash. Values must be in the format "sha256:<64 hex chars>" or "sha256:empty".`,
146
- fix: "Use a valid storage hash from `prisma-next contract emit` output or an existing migration.",
147
- details: { value }
148
- });
149
- }
150
- function errorDuplicateMigrationId(migrationId) {
151
- return new MigrationToolsError("MIGRATION.DUPLICATE_MIGRATION_ID", "Duplicate migrationId in migration graph", {
152
- why: `Multiple migrations share migrationId "${migrationId}". Each migration must have a unique content-addressed identity.`,
153
- fix: "Regenerate one of the conflicting migrations so each migrationId is unique, then re-run migration commands.",
154
- details: { migrationId }
155
- });
156
- }
157
-
158
- //#endregion
159
- export { errorInvalidDestName as a, errorInvalidRefFile as c, errorInvalidSlug as d, errorMissingFile as f, errorSameSourceAndTarget as h, errorDuplicateMigrationId as i, errorInvalidRefName as l, errorNoTarget as m, errorAmbiguousTarget as n, errorInvalidJson as o, errorNoInitialMigration as p, errorDirectoryExists as r, errorInvalidManifest as s, MigrationToolsError as t, errorInvalidRefValue as u };
160
- //# sourceMappingURL=errors-BmiSgz1j.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors-BmiSgz1j.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Structured error for migration tooling operations.\n *\n * Follows the NAMESPACE.SUBCODE convention from ADR 027. All codes live under\n * the MIGRATION namespace. These are tooling-time errors (file I/O, attestation,\n * migration history reconstruction), distinct from the runtime MIGRATION.* codes for apply-time\n * failures (PRECHECK_FAILED, POSTCHECK_FAILED, etc.).\n *\n * Fields:\n * - code: Stable machine-readable code (MIGRATION.SUBCODE)\n * - category: Always 'MIGRATION'\n * - why: Explains the cause in plain language\n * - fix: Actionable remediation step\n * - details: Machine-readable structured data for agents\n */\nexport class MigrationToolsError extends Error {\n readonly code: string;\n readonly category = 'MIGRATION' as const;\n readonly why: string;\n readonly fix: string;\n readonly details: Record<string, unknown> | undefined;\n\n constructor(\n code: string,\n summary: string,\n options: {\n readonly why: string;\n readonly fix: string;\n readonly details?: Record<string, unknown>;\n },\n ) {\n super(summary);\n this.name = 'MigrationToolsError';\n this.code = code;\n this.why = options.why;\n this.fix = options.fix;\n this.details = options.details;\n }\n\n static is(error: unknown): error is MigrationToolsError {\n if (!(error instanceof Error)) return false;\n const candidate = error as MigrationToolsError;\n return candidate.name === 'MigrationToolsError' && typeof candidate.code === 'string';\n }\n}\n\nexport function errorDirectoryExists(dir: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.DIR_EXISTS', 'Migration directory already exists', {\n why: `The directory \"${dir}\" already exists. Each migration must have a unique directory.`,\n fix: 'Use --name to pick a different name, or delete the existing directory and re-run.',\n details: { dir },\n });\n}\n\nexport function errorMissingFile(file: string, dir: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.FILE_MISSING', `Missing ${file}`, {\n why: `Expected \"${file}\" in \"${dir}\" but the file does not exist.`,\n fix: 'Ensure the migration directory contains both migration.json and ops.json. If the directory is corrupt, delete it and re-run migration plan.',\n details: { file, dir },\n });\n}\n\nexport function errorInvalidJson(filePath: string, parseError: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_JSON', 'Invalid JSON in migration file', {\n why: `Failed to parse \"${filePath}\": ${parseError}`,\n fix: 'Fix the JSON syntax error, or delete the migration directory and re-run migration plan.',\n details: { filePath, parseError },\n });\n}\n\nexport function errorInvalidManifest(filePath: string, reason: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_MANIFEST', 'Invalid migration manifest', {\n why: `Manifest at \"${filePath}\" is invalid: ${reason}`,\n fix: 'Ensure the manifest has all required fields (from, to, kind, toContract). If corrupt, delete and re-plan.',\n details: { filePath, reason },\n });\n}\n\nexport function errorInvalidSlug(slug: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_NAME', 'Invalid migration name', {\n why: `The slug \"${slug}\" contains no valid characters after sanitization (only a-z, 0-9 are kept).`,\n fix: 'Provide a name with at least one alphanumeric character, e.g. --name add_users.',\n details: { slug },\n });\n}\n\nexport function errorInvalidDestName(destName: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_DEST_NAME', 'Invalid copy destination name', {\n why: `The destination name \"${destName}\" must be a single path segment (no \"..\" or directory separators).`,\n fix: 'Use a simple file name such as \"contract.json\" for each destination in the copy list.',\n details: { destName },\n });\n}\n\nexport function errorSameSourceAndTarget(dirName: string, hash: string): MigrationToolsError {\n return new MigrationToolsError(\n 'MIGRATION.SAME_SOURCE_AND_TARGET',\n 'Migration has same source and target',\n {\n why: `Migration \"${dirName}\" has from === to === \"${hash}\". A migration must transition between two different contract states.`,\n fix: 'Delete the invalid migration directory and re-run migration plan.',\n details: { dirName, hash },\n },\n );\n}\n\nexport function errorAmbiguousTarget(\n branchTips: readonly string[],\n context?: {\n divergencePoint: string;\n branches: readonly {\n tip: string;\n edges: readonly { dirName: string; from: string; to: string }[];\n }[];\n },\n): MigrationToolsError {\n const divergenceInfo = context\n ? `\\nDivergence point: ${context.divergencePoint}\\nBranches:\\n${context.branches.map((b) => ` → ${b.tip} (${b.edges.length} edge(s): ${b.edges.map((e) => e.dirName).join(' → ') || 'direct'})`).join('\\n')}`\n : '';\n return new MigrationToolsError('MIGRATION.AMBIGUOUS_TARGET', 'Ambiguous migration target', {\n why: `The migration history has diverged into multiple branches: ${branchTips.join(', ')}. This typically happens when two developers plan migrations from the same starting point.${divergenceInfo}`,\n fix: 'Use `migration ref set <name> <hash>` to target a specific branch, delete one of the conflicting migration directories and re-run `migration plan`, or use --from <hash> to explicitly select a starting point.',\n details: {\n branchTips,\n ...(context ? { divergencePoint: context.divergencePoint, branches: context.branches } : {}),\n },\n });\n}\n\nexport function errorNoInitialMigration(nodes: readonly string[]): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.NO_INITIAL_MIGRATION', 'No initial migration found', {\n why: `No migration starts from the empty contract state (known hashes: ${nodes.join(', ')}). At least one migration must originate from the empty state.`,\n fix: 'Inspect the migrations directory for corrupted migration.json files. At least one migration must start from the empty contract hash.',\n details: { nodes },\n });\n}\n\nexport function errorInvalidRefs(refsPath: string, reason: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_REFS', 'Invalid refs.json', {\n why: `refs.json at \"${refsPath}\" is invalid: ${reason}`,\n fix: 'Ensure refs.json is a flat object mapping valid ref names to contract hash strings.',\n details: { path: refsPath, reason },\n });\n}\n\nexport function errorInvalidRefFile(filePath: string, reason: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_REF_FILE', 'Invalid ref file', {\n why: `Ref file at \"${filePath}\" is invalid: ${reason}`,\n fix: 'Ensure the ref file contains valid JSON with { \"hash\": \"sha256:<64 hex chars>\", \"invariants\": [\"...\"] }.',\n details: { path: filePath, reason },\n });\n}\n\nexport function errorInvalidRefName(refName: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_REF_NAME', 'Invalid ref name', {\n why: `Ref name \"${refName}\" is invalid. Names must be lowercase alphanumeric with hyphens or forward slashes (no \".\" or \"..\" segments).`,\n fix: `Use a valid ref name (e.g., \"staging\", \"envs/production\").`,\n details: { refName },\n });\n}\n\nexport function errorNoTarget(reachableHashes: readonly string[]): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.NO_TARGET', 'No migration target could be resolved', {\n why: `The migration history contains cycles and no target can be resolved automatically (reachable hashes: ${reachableHashes.join(', ')}). This typically happens after rollback migrations (e.g., C1→C2→C1).`,\n fix: 'Use --from <hash> to specify the planning origin explicitly.',\n details: { reachableHashes },\n });\n}\n\nexport function errorInvalidRefValue(value: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_REF_VALUE', 'Invalid ref value', {\n why: `Ref value \"${value}\" is not a valid contract hash. Values must be in the format \"sha256:<64 hex chars>\" or \"sha256:empty\".`,\n fix: 'Use a valid storage hash from `prisma-next contract emit` output or an existing migration.',\n details: { value },\n });\n}\n\nexport function errorDuplicateMigrationId(migrationId: string): MigrationToolsError {\n return new MigrationToolsError(\n 'MIGRATION.DUPLICATE_MIGRATION_ID',\n 'Duplicate migrationId in migration graph',\n {\n why: `Multiple migrations share migrationId \"${migrationId}\". Each migration must have a unique content-addressed identity.`,\n fix: 'Regenerate one of the conflicting migrations so each migrationId is unique, then re-run migration commands.',\n details: { migrationId },\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,IAAa,sBAAb,cAAyC,MAAM;CAC7C,AAAS;CACT,AAAS,WAAW;CACpB,AAAS;CACT,AAAS;CACT,AAAS;CAET,YACE,MACA,SACA,SAKA;AACA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AwG,gBAAgB,KAAK,KAAK,CAAC;EACxI,KAAK;EACL,SAAS,EAAE,iBAAiB;EAC7B,CAAC;;AAGJ,SAAgB,qBAAqB,OAAoC;AACvE,QAAO,IAAI,oBAAoB,+BAA+B,qBAAqB;EACjF,KAAK,cAAc,MAAM;EACzB,KAAK;EACL,SAAS,EAAE,OAAO;EACnB,CAAC;;AAGJ,SAAgB,0BAA0B,aAA0C;AAClF,QAAO,IAAI,oBACT,oCACA,4CACA;EACE,KAAK,0CAA0C,YAAY;EAC3D,KAAK;EACL,SAAS,EAAE,aAAa;EACzB,CACF"}
@@ -1,37 +0,0 @@
1
- import { a as MigrationManifest, o as MigrationOps, t as MigrationBundle } from "../types-DyGXcWWp.mjs";
2
-
3
- //#region src/attestation.d.ts
4
- interface VerifyResult {
5
- readonly ok: boolean;
6
- readonly reason?: 'mismatch';
7
- readonly storedMigrationId?: string;
8
- readonly computedMigrationId?: string;
9
- }
10
- /**
11
- * Content-addressed migration identity over (manifest envelope sans
12
- * contracts/hints, ops). See ADR 199 "Storage-only migration identity"
13
- * for the rationale: contracts are anchored separately by the
14
- * storage-hash bookends inside the envelope; planner hints are advisory
15
- * and must not affect identity.
16
- *
17
- * The `migrationId` field on the manifest is stripped before hashing so
18
- * the function can be used both at write time (when no id exists yet)
19
- * and at verify time (rehashing an already-attested manifest).
20
- */
21
- declare function computeMigrationId(manifest: Omit<MigrationManifest, 'migrationId'> & {
22
- readonly migrationId?: string;
23
- }, ops: MigrationOps): string;
24
- /**
25
- * Re-hash an on-disk migration bundle and compare against the stored
26
- * `migrationId`. Returns `{ ok: true }` when the package is internally
27
- * consistent (manifest + ops still produce the recorded id), or
28
- * `{ ok: false, reason: 'mismatch', stored, computed }` when they do
29
- * not — typically a sign of FS corruption, partial writes, or a
30
- * post-emit hand edit.
31
- */
32
- declare function verifyMigrationBundle(bundle: MigrationBundle): VerifyResult;
33
- /** Convenience wrapper: read the package from disk then verify it. */
34
- declare function verifyMigration(dir: string): Promise<VerifyResult>;
35
- //#endregion
36
- export { type VerifyResult, computeMigrationId, verifyMigration, verifyMigrationBundle };
37
- //# sourceMappingURL=attestation.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"attestation.d.mts","names":[],"sources":["../../src/attestation.ts"],"sourcesContent":[],"mappings":";;;UAKiB,YAAA;;EAAA,SAAA,MAAY,CAAA,EAAA,UAAA;EAsBb,SAAA,iBAAkB,CAAA,EAAA,MAAA;EACjB,SAAA,mBAAA,CAAA,EAAA,MAAA;;;;AA6BjB;AAoBA;;;;;;;;iBAlDgB,kBAAA,WACJ,KAAK;;QACV;;;;;;;;;iBA4BS,qBAAA,SAA8B,kBAAkB;;iBAoB1C,eAAA,eAA8B,QAAQ"}
@@ -1,4 +0,0 @@
1
- import "../io-Cd6GLyjK.mjs";
2
- import { n as verifyMigration, r as verifyMigrationBundle, t as computeMigrationId } from "../attestation-BnzTb0Qp.mjs";
3
-
4
- export { computeMigrationId, verifyMigration, verifyMigrationBundle };
@@ -1,51 +0,0 @@
1
- import { n as MigrationChainEntry, r as MigrationGraph, t as MigrationBundle } from "../types-DyGXcWWp.mjs";
2
-
3
- //#region src/dag.d.ts
4
- declare function reconstructGraph(packages: readonly MigrationBundle[]): MigrationGraph;
5
- /**
6
- * Find the shortest path from `fromHash` to `toHash` using BFS over the
7
- * contract-hash graph. Returns the ordered list of edges, or null if no path
8
- * exists. Returns an empty array when `fromHash === toHash` (no-op).
9
- *
10
- * Neighbor ordering is deterministic via the tie-break sort key:
11
- * label priority → createdAt → to → migrationId.
12
- */
13
- declare function findPath(graph: MigrationGraph, fromHash: string, toHash: string): readonly MigrationChainEntry[] | null;
14
- interface PathDecision {
15
- readonly selectedPath: readonly MigrationChainEntry[];
16
- readonly fromHash: string;
17
- readonly toHash: string;
18
- readonly alternativeCount: number;
19
- readonly tieBreakReasons: readonly string[];
20
- readonly refName?: string;
21
- }
22
- /**
23
- * Find the shortest path from `fromHash` to `toHash` and return structured
24
- * path-decision metadata for machine-readable output.
25
- */
26
- declare function findPathWithDecision(graph: MigrationGraph, fromHash: string, toHash: string, refName?: string): PathDecision | null;
27
- /**
28
- * Find all branch tips (nodes with no outgoing edges) reachable from
29
- * `fromHash` via forward edges.
30
- */
31
- declare function findReachableLeaves(graph: MigrationGraph, fromHash: string): readonly string[];
32
- /**
33
- * Find the target contract hash of the migration graph reachable from
34
- * EMPTY_CONTRACT_HASH. Returns `null` for a graph that has no target
35
- * state (either empty, or containing only the root with no outgoing
36
- * edges). Throws NO_INITIAL_MIGRATION if the graph has nodes but none
37
- * originate from the empty hash, and AMBIGUOUS_TARGET if multiple
38
- * branch tips exist.
39
- */
40
- declare function findLeaf(graph: MigrationGraph): string | null;
41
- /**
42
- * Find the latest migration entry by traversing from EMPTY_CONTRACT_HASH
43
- * to the single target. Returns null for an empty graph.
44
- * Throws AMBIGUOUS_TARGET if the graph has multiple branch tips.
45
- */
46
- declare function findLatestMigration(graph: MigrationGraph): MigrationChainEntry | null;
47
- declare function detectCycles(graph: MigrationGraph): readonly string[][];
48
- declare function detectOrphans(graph: MigrationGraph): readonly MigrationChainEntry[];
49
- //#endregion
50
- export { type PathDecision, detectCycles, detectOrphans, findLatestMigration, findLeaf, findPath, findPathWithDecision, findReachableLeaves, reconstructGraph };
51
- //# sourceMappingURL=dag.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dag.d.mts","names":[],"sources":["../../src/dag.ts"],"sourcesContent":[],"mappings":";;;iBAgCgB,gBAAA,oBAAoC,oBAAoB;;AAAxE;AAmFA;AAyCA;AAaA;AA8FA;AAkBA;AAwCA;AAQgB,iBAtNA,QAAA,CAsNoB,KAAA,EArN3B,cAqNyC,EAAA,QAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EAAA,SAlNtC,mBAkNsC,EAAA,GAAA,IAAA;AA8DlC,UA3OC,YAAA,CA2OY;kCA1OK;;;;;;;;;;;iBAYlB,oBAAA,QACP,qEAIN;;;;;iBAyFa,mBAAA,QAA2B;;;;;;;;;iBAkB3B,QAAA,QAAgB;;;;;;iBAwChB,mBAAA,QAA2B,iBAAiB;iBAQ5C,YAAA,QAAoB;iBA8DpB,aAAA,QAAqB,0BAA0B"}