@prisma-next/migration-tools 0.5.0-dev.3 → 0.5.0-dev.30

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 (92) 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-Bl3cKiM8.mjs +244 -0
  5. package/dist/errors-Bl3cKiM8.mjs.map +1 -0
  6. package/dist/exports/constants.mjs +1 -1
  7. package/dist/exports/{types.d.mts → errors.d.mts} +7 -8
  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/{dag.d.mts → migration-graph.d.mts} +31 -10
  25. package/dist/exports/migration-graph.d.mts.map +1 -0
  26. package/dist/exports/{dag.mjs → migration-graph.mjs} +143 -63
  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 +68 -40
  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.d.mts +11 -5
  36. package/dist/exports/refs.d.mts.map +1 -1
  37. package/dist/exports/refs.mjs +106 -30
  38. package/dist/exports/refs.mjs.map +1 -1
  39. package/dist/graph-BHPv-9Gl.d.mts +28 -0
  40. package/dist/graph-BHPv-9Gl.d.mts.map +1 -0
  41. package/dist/hash-BARZdVgW.mjs +76 -0
  42. package/dist/hash-BARZdVgW.mjs.map +1 -0
  43. package/dist/invariants-BmrTBQ0A.mjs +42 -0
  44. package/dist/invariants-BmrTBQ0A.mjs.map +1 -0
  45. package/dist/metadata-BP1cmU7Z.d.mts +50 -0
  46. package/dist/metadata-BP1cmU7Z.d.mts.map +1 -0
  47. package/dist/op-schema-DZKFua46.mjs +14 -0
  48. package/dist/op-schema-DZKFua46.mjs.map +1 -0
  49. package/dist/package-5HCCg0z-.d.mts +21 -0
  50. package/dist/package-5HCCg0z-.d.mts.map +1 -0
  51. package/package.json +30 -14
  52. package/src/errors.ts +139 -15
  53. package/src/exports/errors.ts +1 -0
  54. package/src/exports/graph.ts +1 -0
  55. package/src/exports/hash.ts +2 -0
  56. package/src/exports/invariants.ts +1 -0
  57. package/src/exports/io.ts +1 -1
  58. package/src/exports/metadata.ts +1 -0
  59. package/src/exports/{dag.ts → migration-graph.ts} +3 -2
  60. package/src/exports/migration.ts +0 -1
  61. package/src/exports/package.ts +1 -0
  62. package/src/exports/refs.ts +10 -2
  63. package/src/graph-ops.ts +57 -30
  64. package/src/graph.ts +25 -0
  65. package/src/hash.ts +91 -0
  66. package/src/invariants.ts +45 -0
  67. package/src/io.ts +57 -31
  68. package/src/metadata.ts +41 -0
  69. package/src/migration-base.ts +97 -56
  70. package/src/{dag.ts → migration-graph.ts} +156 -54
  71. package/src/op-schema.ts +11 -0
  72. package/src/package.ts +18 -0
  73. package/src/refs.ts +148 -37
  74. package/dist/attestation-DtF8tEOM.mjs +0 -65
  75. package/dist/attestation-DtF8tEOM.mjs.map +0 -1
  76. package/dist/errors-BKbRGCJM.mjs +0 -160
  77. package/dist/errors-BKbRGCJM.mjs.map +0 -1
  78. package/dist/exports/attestation.d.mts +0 -37
  79. package/dist/exports/attestation.d.mts.map +0 -1
  80. package/dist/exports/attestation.mjs +0 -4
  81. package/dist/exports/dag.d.mts.map +0 -1
  82. package/dist/exports/dag.mjs.map +0 -1
  83. package/dist/exports/types.d.mts.map +0 -1
  84. package/dist/exports/types.mjs +0 -3
  85. package/dist/io-CCnYsUHU.mjs +0 -153
  86. package/dist/io-CCnYsUHU.mjs.map +0 -1
  87. package/dist/types-DyGXcWWp.d.mts +0 -71
  88. package/dist/types-DyGXcWWp.d.mts.map +0 -1
  89. package/src/attestation.ts +0 -81
  90. package/src/exports/attestation.ts +0 -2
  91. package/src/exports/types.ts +0 -10
  92. package/src/types.ts +0 -66
@@ -1,153 +0,0 @@
1
- import { a as errorInvalidDestName, d as errorInvalidSlug, f as errorMissingFile, o as errorInvalidJson, r as errorDirectoryExists, s as errorInvalidManifest } from "./errors-BKbRGCJM.mjs";
2
- import { copyFile, mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
3
- import { type } from "arktype";
4
- import { basename, dirname, join } from "pathe";
5
-
6
- //#region src/io.ts
7
- const MANIFEST_FILE = "migration.json";
8
- const OPS_FILE = "ops.json";
9
- const MAX_SLUG_LENGTH = 64;
10
- function hasErrnoCode(error, code) {
11
- return error instanceof Error && error.code === code;
12
- }
13
- const MigrationManifestSchema = type({
14
- from: "string",
15
- to: "string",
16
- migrationId: "string",
17
- kind: "'regular' | 'baseline'",
18
- fromContract: "object | null",
19
- toContract: "object",
20
- hints: type({
21
- used: "string[]",
22
- applied: "string[]",
23
- plannerVersion: "string"
24
- }),
25
- labels: "string[]",
26
- "authorship?": type({
27
- "author?": "string",
28
- "email?": "string"
29
- }),
30
- "signature?": type({
31
- keyId: "string",
32
- value: "string"
33
- }).or("null"),
34
- createdAt: "string"
35
- });
36
- const MigrationOpsSchema = type({
37
- id: "string",
38
- label: "string",
39
- operationClass: "'additive' | 'widening' | 'destructive' | 'data'"
40
- }).array();
41
- async function writeMigrationPackage(dir, manifest, ops) {
42
- await mkdir(dirname(dir), { recursive: true });
43
- try {
44
- await mkdir(dir);
45
- } catch (error) {
46
- if (hasErrnoCode(error, "EEXIST")) throw errorDirectoryExists(dir);
47
- throw error;
48
- }
49
- await writeFile(join(dir, MANIFEST_FILE), JSON.stringify(manifest, null, 2), { flag: "wx" });
50
- await writeFile(join(dir, OPS_FILE), JSON.stringify(ops, null, 2), { flag: "wx" });
51
- }
52
- /**
53
- * Copy a list of files into `destDir`, optionally renaming each one.
54
- *
55
- * The destination directory is created (with `recursive: true`) if it
56
- * does not already exist. Each source path is copied byte-for-byte into
57
- * `destDir/<destName>`; missing sources throw `ENOENT`. The helper is
58
- * intentionally generic: callers own the list of files (e.g. a contract
59
- * emitter's emitted output) and the naming convention (e.g. renaming
60
- * the destination contract to `end-contract.*` and the source contract
61
- * to `start-contract.*`).
62
- */
63
- async function copyFilesWithRename(destDir, files) {
64
- await mkdir(destDir, { recursive: true });
65
- for (const file of files) {
66
- if (basename(file.destName) !== file.destName) throw errorInvalidDestName(file.destName);
67
- await copyFile(file.sourcePath, join(destDir, file.destName));
68
- }
69
- }
70
- async function writeMigrationManifest(dir, manifest) {
71
- await writeFile(join(dir, MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\n`);
72
- }
73
- async function writeMigrationOps(dir, ops) {
74
- await writeFile(join(dir, OPS_FILE), `${JSON.stringify(ops, null, 2)}\n`);
75
- }
76
- async function readMigrationPackage(dir) {
77
- const manifestPath = join(dir, MANIFEST_FILE);
78
- const opsPath = join(dir, OPS_FILE);
79
- let manifestRaw;
80
- try {
81
- manifestRaw = await readFile(manifestPath, "utf-8");
82
- } catch (error) {
83
- if (hasErrnoCode(error, "ENOENT")) throw errorMissingFile(MANIFEST_FILE, dir);
84
- throw error;
85
- }
86
- let opsRaw;
87
- try {
88
- opsRaw = await readFile(opsPath, "utf-8");
89
- } catch (error) {
90
- if (hasErrnoCode(error, "ENOENT")) throw errorMissingFile(OPS_FILE, dir);
91
- throw error;
92
- }
93
- let manifest;
94
- try {
95
- manifest = JSON.parse(manifestRaw);
96
- } catch (e) {
97
- throw errorInvalidJson(manifestPath, e instanceof Error ? e.message : String(e));
98
- }
99
- let ops;
100
- try {
101
- ops = JSON.parse(opsRaw);
102
- } catch (e) {
103
- throw errorInvalidJson(opsPath, e instanceof Error ? e.message : String(e));
104
- }
105
- validateManifest(manifest, manifestPath);
106
- validateOps(ops, opsPath);
107
- return {
108
- dirName: basename(dir),
109
- dirPath: dir,
110
- manifest,
111
- ops
112
- };
113
- }
114
- function validateManifest(manifest, filePath) {
115
- const result = MigrationManifestSchema(manifest);
116
- if (result instanceof type.errors) throw errorInvalidManifest(filePath, result.summary);
117
- }
118
- function validateOps(ops, filePath) {
119
- const result = MigrationOpsSchema(ops);
120
- if (result instanceof type.errors) throw errorInvalidManifest(filePath, result.summary);
121
- }
122
- async function readMigrationsDir(migrationsRoot) {
123
- let entries;
124
- try {
125
- entries = await readdir(migrationsRoot);
126
- } catch (error) {
127
- if (hasErrnoCode(error, "ENOENT")) return [];
128
- throw error;
129
- }
130
- const packages = [];
131
- for (const entry of entries.sort()) {
132
- const entryPath = join(migrationsRoot, entry);
133
- if (!(await stat(entryPath)).isDirectory()) continue;
134
- const manifestPath = join(entryPath, MANIFEST_FILE);
135
- try {
136
- await stat(manifestPath);
137
- } catch {
138
- continue;
139
- }
140
- packages.push(await readMigrationPackage(entryPath));
141
- }
142
- return packages;
143
- }
144
- function formatMigrationDirName(timestamp, slug) {
145
- const sanitized = slug.toLowerCase().replace(/[^a-z0-9]/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "");
146
- if (sanitized.length === 0) throw errorInvalidSlug(slug);
147
- const truncated = sanitized.slice(0, MAX_SLUG_LENGTH);
148
- return `${timestamp.getUTCFullYear()}${String(timestamp.getUTCMonth() + 1).padStart(2, "0")}${String(timestamp.getUTCDate()).padStart(2, "0")}T${String(timestamp.getUTCHours()).padStart(2, "0")}${String(timestamp.getUTCMinutes()).padStart(2, "0")}_${truncated}`;
149
- }
150
-
151
- //#endregion
152
- export { writeMigrationManifest as a, readMigrationsDir as i, formatMigrationDirName as n, writeMigrationOps as o, readMigrationPackage as r, writeMigrationPackage as s, copyFilesWithRename as t };
153
- //# sourceMappingURL=io-CCnYsUHU.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"io-CCnYsUHU.mjs","names":["manifestRaw: string","opsRaw: string","manifest: MigrationManifest","ops: MigrationOps","entries: string[]","packages: MigrationBundle[]"],"sources":["../src/io.ts"],"sourcesContent":["import { copyFile, mkdir, readdir, readFile, stat, writeFile } from 'node:fs/promises';\nimport { type } from 'arktype';\nimport { basename, dirname, join } from 'pathe';\nimport {\n errorDirectoryExists,\n errorInvalidDestName,\n errorInvalidJson,\n errorInvalidManifest,\n errorInvalidSlug,\n errorMissingFile,\n} from './errors';\nimport type { MigrationBundle, MigrationManifest, MigrationOps } from './types';\n\nconst MANIFEST_FILE = 'migration.json';\nconst OPS_FILE = 'ops.json';\nconst MAX_SLUG_LENGTH = 64;\n\nfunction hasErrnoCode(error: unknown, code: string): boolean {\n return error instanceof Error && (error as { code?: string }).code === code;\n}\n\nconst MigrationHintsSchema = type({\n used: 'string[]',\n applied: 'string[]',\n plannerVersion: 'string',\n});\n\nconst MigrationManifestSchema = type({\n from: 'string',\n to: 'string',\n migrationId: 'string',\n kind: \"'regular' | 'baseline'\",\n fromContract: 'object | null',\n toContract: 'object',\n hints: MigrationHintsSchema,\n labels: 'string[]',\n 'authorship?': type({\n 'author?': 'string',\n 'email?': 'string',\n }),\n 'signature?': type({\n keyId: 'string',\n value: 'string',\n }).or('null'),\n createdAt: 'string',\n});\n\nconst MigrationOpSchema = type({\n id: 'string',\n label: 'string',\n operationClass: \"'additive' | 'widening' | 'destructive' | 'data'\",\n});\n\n// Intentionally shallow: operation-specific payload validation is owned by planner/runner layers.\nconst MigrationOpsSchema = MigrationOpSchema.array();\n\nexport async function writeMigrationPackage(\n dir: string,\n manifest: MigrationManifest,\n ops: MigrationOps,\n): Promise<void> {\n await mkdir(dirname(dir), { recursive: true });\n\n try {\n await mkdir(dir);\n } catch (error) {\n if (hasErrnoCode(error, 'EEXIST')) {\n throw errorDirectoryExists(dir);\n }\n throw error;\n }\n\n await writeFile(join(dir, MANIFEST_FILE), JSON.stringify(manifest, null, 2), { flag: 'wx' });\n await writeFile(join(dir, OPS_FILE), JSON.stringify(ops, null, 2), { flag: 'wx' });\n}\n\n/**\n * Copy a list of files into `destDir`, optionally renaming each one.\n *\n * The destination directory is created (with `recursive: true`) if it\n * does not already exist. Each source path is copied byte-for-byte into\n * `destDir/<destName>`; missing sources throw `ENOENT`. The helper is\n * intentionally generic: callers own the list of files (e.g. a contract\n * emitter's emitted output) and the naming convention (e.g. renaming\n * the destination contract to `end-contract.*` and the source contract\n * to `start-contract.*`).\n */\nexport async function copyFilesWithRename(\n destDir: string,\n files: readonly { readonly sourcePath: string; readonly destName: string }[],\n): Promise<void> {\n await mkdir(destDir, { recursive: true });\n for (const file of files) {\n if (basename(file.destName) !== file.destName) {\n throw errorInvalidDestName(file.destName);\n }\n await copyFile(file.sourcePath, join(destDir, file.destName));\n }\n}\n\nexport async function writeMigrationManifest(\n dir: string,\n manifest: MigrationManifest,\n): Promise<void> {\n await writeFile(join(dir, MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\\n`);\n}\n\nexport async function writeMigrationOps(dir: string, ops: MigrationOps): Promise<void> {\n await writeFile(join(dir, OPS_FILE), `${JSON.stringify(ops, null, 2)}\\n`);\n}\n\nexport async function readMigrationPackage(dir: string): Promise<MigrationBundle> {\n const manifestPath = join(dir, MANIFEST_FILE);\n const opsPath = join(dir, OPS_FILE);\n\n let manifestRaw: string;\n try {\n manifestRaw = await readFile(manifestPath, 'utf-8');\n } catch (error) {\n if (hasErrnoCode(error, 'ENOENT')) {\n throw errorMissingFile(MANIFEST_FILE, dir);\n }\n throw error;\n }\n\n let opsRaw: string;\n try {\n opsRaw = await readFile(opsPath, 'utf-8');\n } catch (error) {\n if (hasErrnoCode(error, 'ENOENT')) {\n throw errorMissingFile(OPS_FILE, dir);\n }\n throw error;\n }\n\n let manifest: MigrationManifest;\n try {\n manifest = JSON.parse(manifestRaw);\n } catch (e) {\n throw errorInvalidJson(manifestPath, e instanceof Error ? e.message : String(e));\n }\n\n let ops: MigrationOps;\n try {\n ops = JSON.parse(opsRaw);\n } catch (e) {\n throw errorInvalidJson(opsPath, e instanceof Error ? e.message : String(e));\n }\n\n validateManifest(manifest, manifestPath);\n validateOps(ops, opsPath);\n\n return {\n dirName: basename(dir),\n dirPath: dir,\n manifest,\n ops,\n };\n}\n\nfunction validateManifest(\n manifest: unknown,\n filePath: string,\n): asserts manifest is MigrationManifest {\n const result = MigrationManifestSchema(manifest);\n if (result instanceof type.errors) {\n throw errorInvalidManifest(filePath, result.summary);\n }\n}\n\nfunction validateOps(ops: unknown, filePath: string): asserts ops is MigrationOps {\n const result = MigrationOpsSchema(ops);\n if (result instanceof type.errors) {\n throw errorInvalidManifest(filePath, result.summary);\n }\n}\n\nexport async function readMigrationsDir(\n migrationsRoot: string,\n): Promise<readonly MigrationBundle[]> {\n let entries: string[];\n try {\n entries = await readdir(migrationsRoot);\n } catch (error) {\n if (hasErrnoCode(error, 'ENOENT')) {\n return [];\n }\n throw error;\n }\n\n const packages: MigrationBundle[] = [];\n\n for (const entry of entries.sort()) {\n const entryPath = join(migrationsRoot, entry);\n const entryStat = await stat(entryPath);\n if (!entryStat.isDirectory()) continue;\n\n const manifestPath = join(entryPath, MANIFEST_FILE);\n try {\n await stat(manifestPath);\n } catch {\n continue; // skip non-migration directories\n }\n\n packages.push(await readMigrationPackage(entryPath));\n }\n\n return packages;\n}\n\nexport function formatMigrationDirName(timestamp: Date, slug: string): string {\n const sanitized = slug\n .toLowerCase()\n .replace(/[^a-z0-9]/g, '_')\n .replace(/_+/g, '_')\n .replace(/^_|_$/g, '');\n\n if (sanitized.length === 0) {\n throw errorInvalidSlug(slug);\n }\n\n const truncated = sanitized.slice(0, MAX_SLUG_LENGTH);\n\n const y = timestamp.getUTCFullYear();\n const mo = String(timestamp.getUTCMonth() + 1).padStart(2, '0');\n const d = String(timestamp.getUTCDate()).padStart(2, '0');\n const h = String(timestamp.getUTCHours()).padStart(2, '0');\n const mi = String(timestamp.getUTCMinutes()).padStart(2, '0');\n\n return `${y}${mo}${d}T${h}${mi}_${truncated}`;\n}\n"],"mappings":";;;;;;AAaA,MAAM,gBAAgB;AACtB,MAAM,WAAW;AACjB,MAAM,kBAAkB;AAExB,SAAS,aAAa,OAAgB,MAAuB;AAC3D,QAAO,iBAAiB,SAAU,MAA4B,SAAS;;AASzE,MAAM,0BAA0B,KAAK;CACnC,MAAM;CACN,IAAI;CACJ,aAAa;CACb,MAAM;CACN,cAAc;CACd,YAAY;CACZ,OAb2B,KAAK;EAChC,MAAM;EACN,SAAS;EACT,gBAAgB;EACjB,CAAC;CAUA,QAAQ;CACR,eAAe,KAAK;EAClB,WAAW;EACX,UAAU;EACX,CAAC;CACF,cAAc,KAAK;EACjB,OAAO;EACP,OAAO;EACR,CAAC,CAAC,GAAG,OAAO;CACb,WAAW;CACZ,CAAC;AASF,MAAM,qBAPoB,KAAK;CAC7B,IAAI;CACJ,OAAO;CACP,gBAAgB;CACjB,CAAC,CAG2C,OAAO;AAEpD,eAAsB,sBACpB,KACA,UACA,KACe;AACf,OAAM,MAAM,QAAQ,IAAI,EAAE,EAAE,WAAW,MAAM,CAAC;AAE9C,KAAI;AACF,QAAM,MAAM,IAAI;UACT,OAAO;AACd,MAAI,aAAa,OAAO,SAAS,CAC/B,OAAM,qBAAqB,IAAI;AAEjC,QAAM;;AAGR,OAAM,UAAU,KAAK,KAAK,cAAc,EAAE,KAAK,UAAU,UAAU,MAAM,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC5F,OAAM,UAAU,KAAK,KAAK,SAAS,EAAE,KAAK,UAAU,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IAAI,CAIpC,GAHX,OAAO,UAAU,aAAa,CAAC,CAAC,SAAS,GAAG,IAAI,GAC/C,OAAO,UAAU,eAAe,CAAC,CAAC,SAAS,GAAG,IAAI,CAE9B,GAAG"}
@@ -1,71 +0,0 @@
1
- import { Contract } from "@prisma-next/contract/types";
2
- import { MigrationPlanOperation } from "@prisma-next/framework-components/control";
3
-
4
- //#region src/types.d.ts
5
- interface MigrationHints {
6
- readonly used: readonly string[];
7
- readonly applied: readonly string[];
8
- readonly plannerVersion: string;
9
- }
10
- /**
11
- * On-disk migration manifest. Every migration is content-addressed: the
12
- * `migrationId` is a hash over the manifest envelope plus the operations
13
- * list, computed at write time. There is no draft state — a migration
14
- * directory either exists with a fully attested manifest or it does not.
15
- *
16
- * When the planner cannot lower an operation because of an unfilled
17
- * `placeholder(...)` slot, the migration is still written with
18
- * `migrationId` hashed over `ops: []`. Re-running self-emit after the
19
- * user fills the placeholder produces a *different* `migrationId`
20
- * (committed to the real ops); this is intentional.
21
- */
22
- interface MigrationManifest {
23
- readonly migrationId: string;
24
- readonly from: string;
25
- readonly to: string;
26
- readonly kind: 'regular' | 'baseline';
27
- readonly fromContract: Contract | null;
28
- readonly toContract: Contract;
29
- readonly hints: MigrationHints;
30
- readonly labels: readonly string[];
31
- readonly authorship?: {
32
- readonly author?: string;
33
- readonly email?: string;
34
- };
35
- readonly signature?: {
36
- readonly keyId: string;
37
- readonly value: string;
38
- } | null;
39
- readonly createdAt: string;
40
- }
41
- type MigrationOps = readonly MigrationPlanOperation[];
42
- /**
43
- * An on-disk migration directory containing a manifest and operations.
44
- */
45
- interface MigrationBundle {
46
- readonly dirName: string;
47
- readonly dirPath: string;
48
- readonly manifest: MigrationManifest;
49
- readonly ops: MigrationOps;
50
- }
51
- /**
52
- * An entry in the migration graph. All on-disk migrations are attested,
53
- * so `migrationId` is always a string.
54
- */
55
- interface MigrationChainEntry {
56
- readonly from: string;
57
- readonly to: string;
58
- readonly migrationId: string;
59
- readonly dirName: string;
60
- readonly createdAt: string;
61
- readonly labels: readonly string[];
62
- }
63
- interface MigrationGraph {
64
- readonly nodes: ReadonlySet<string>;
65
- readonly forwardChain: ReadonlyMap<string, readonly MigrationChainEntry[]>;
66
- readonly reverseChain: ReadonlyMap<string, readonly MigrationChainEntry[]>;
67
- readonly migrationById: ReadonlyMap<string, MigrationChainEntry>;
68
- }
69
- //#endregion
70
- export { MigrationManifest as a, MigrationHints as i, MigrationChainEntry as n, MigrationOps as o, MigrationGraph as r, MigrationBundle as t };
71
- //# sourceMappingURL=types-DyGXcWWp.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-DyGXcWWp.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;UAGiB,cAAA;;EAAA,SAAA,OAAA,EAAc,SAAA,MAAA,EAAA;EAkBd,SAAA,cAAiB,EAAA,MAAA;;;;;AAclC;AAKA;AAWA;AASA;;;;;;AAI8C,UA3C7B,iBAAA,CA2C6B;EAApB,SAAA,WAAA,EAAA,MAAA;EAAW,SAAA,IAAA,EAAA,MAAA;;;yBAtCZ;uBACF;kBACL;;;;;;;;;;;;KAON,YAAA,YAAwB;;;;UAKnB,eAAA;;;qBAGI;gBACL;;;;;;UAOC,mBAAA;;;;;;;;UASA,cAAA;kBACC;yBACO,6BAA6B;yBAC7B,6BAA6B;0BAC5B,oBAAoB"}
@@ -1,81 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import { canonicalizeJson } from './canonicalize-json';
3
- import { readMigrationPackage } from './io';
4
- import type { MigrationBundle, MigrationManifest, MigrationOps } from './types';
5
-
6
- export interface VerifyResult {
7
- readonly ok: boolean;
8
- readonly reason?: 'mismatch';
9
- readonly storedMigrationId?: string;
10
- readonly computedMigrationId?: string;
11
- }
12
-
13
- function sha256Hex(input: string): string {
14
- return createHash('sha256').update(input).digest('hex');
15
- }
16
-
17
- /**
18
- * Content-addressed migration identity over (manifest envelope sans
19
- * contracts/hints, ops). See ADR 199 "Storage-only migration identity"
20
- * for the rationale: contracts are anchored separately by the
21
- * storage-hash bookends inside the envelope; planner hints are advisory
22
- * and must not affect identity.
23
- *
24
- * The `migrationId` field on the manifest is stripped before hashing so
25
- * the function can be used both at write time (when no id exists yet)
26
- * and at verify time (rehashing an already-attested manifest).
27
- */
28
- export function computeMigrationId(
29
- manifest: Omit<MigrationManifest, 'migrationId'> & { readonly migrationId?: string },
30
- ops: MigrationOps,
31
- ): string {
32
- const {
33
- migrationId: _migrationId,
34
- signature: _signature,
35
- fromContract: _fromContract,
36
- toContract: _toContract,
37
- hints: _hints,
38
- ...strippedMeta
39
- } = manifest;
40
-
41
- const canonicalManifest = canonicalizeJson(strippedMeta);
42
- const canonicalOps = canonicalizeJson(ops);
43
-
44
- const partHashes = [canonicalManifest, canonicalOps].map(sha256Hex);
45
- const hash = sha256Hex(canonicalizeJson(partHashes));
46
-
47
- return `sha256:${hash}`;
48
- }
49
-
50
- /**
51
- * Re-hash an on-disk migration bundle and compare against the stored
52
- * `migrationId`. Returns `{ ok: true }` when the package is internally
53
- * consistent (manifest + ops still produce the recorded id), or
54
- * `{ ok: false, reason: 'mismatch', stored, computed }` when they do
55
- * not — typically a sign of FS corruption, partial writes, or a
56
- * post-emit hand edit.
57
- */
58
- export function verifyMigrationBundle(bundle: MigrationBundle): VerifyResult {
59
- const computed = computeMigrationId(bundle.manifest, bundle.ops);
60
-
61
- if (bundle.manifest.migrationId === computed) {
62
- return {
63
- ok: true,
64
- storedMigrationId: bundle.manifest.migrationId,
65
- computedMigrationId: computed,
66
- };
67
- }
68
-
69
- return {
70
- ok: false,
71
- reason: 'mismatch',
72
- storedMigrationId: bundle.manifest.migrationId,
73
- computedMigrationId: computed,
74
- };
75
- }
76
-
77
- /** Convenience wrapper: read the package from disk then verify it. */
78
- export async function verifyMigration(dir: string): Promise<VerifyResult> {
79
- const pkg = await readMigrationPackage(dir);
80
- return verifyMigrationBundle(pkg);
81
- }
@@ -1,2 +0,0 @@
1
- export type { VerifyResult } from '../attestation';
2
- export { computeMigrationId, verifyMigration, verifyMigrationBundle } from '../attestation';
@@ -1,10 +0,0 @@
1
- export { MigrationToolsError } from '../errors';
2
- export type {
3
- MigrationBundle,
4
- MigrationBundle as MigrationPackage,
5
- MigrationChainEntry,
6
- MigrationGraph,
7
- MigrationHints,
8
- MigrationManifest,
9
- MigrationOps,
10
- } from '../types';
package/src/types.ts DELETED
@@ -1,66 +0,0 @@
1
- import type { Contract } from '@prisma-next/contract/types';
2
- import type { MigrationPlanOperation } from '@prisma-next/framework-components/control';
3
-
4
- export interface MigrationHints {
5
- readonly used: readonly string[];
6
- readonly applied: readonly string[];
7
- readonly plannerVersion: string;
8
- }
9
-
10
- /**
11
- * On-disk migration manifest. Every migration is content-addressed: the
12
- * `migrationId` is a hash over the manifest envelope plus the operations
13
- * list, computed at write time. There is no draft state — a migration
14
- * directory either exists with a fully attested manifest or it does not.
15
- *
16
- * When the planner cannot lower an operation because of an unfilled
17
- * `placeholder(...)` slot, the migration is still written with
18
- * `migrationId` hashed over `ops: []`. Re-running self-emit after the
19
- * user fills the placeholder produces a *different* `migrationId`
20
- * (committed to the real ops); this is intentional.
21
- */
22
- export interface MigrationManifest {
23
- readonly migrationId: string;
24
- readonly from: string;
25
- readonly to: string;
26
- readonly kind: 'regular' | 'baseline';
27
- readonly fromContract: Contract | null;
28
- readonly toContract: Contract;
29
- readonly hints: MigrationHints;
30
- readonly labels: readonly string[];
31
- readonly authorship?: { readonly author?: string; readonly email?: string };
32
- readonly signature?: { readonly keyId: string; readonly value: string } | null;
33
- readonly createdAt: string;
34
- }
35
-
36
- export type MigrationOps = readonly MigrationPlanOperation[];
37
-
38
- /**
39
- * An on-disk migration directory containing a manifest and operations.
40
- */
41
- export interface MigrationBundle {
42
- readonly dirName: string;
43
- readonly dirPath: string;
44
- readonly manifest: MigrationManifest;
45
- readonly ops: MigrationOps;
46
- }
47
-
48
- /**
49
- * An entry in the migration graph. All on-disk migrations are attested,
50
- * so `migrationId` is always a string.
51
- */
52
- export interface MigrationChainEntry {
53
- readonly from: string;
54
- readonly to: string;
55
- readonly migrationId: string;
56
- readonly dirName: string;
57
- readonly createdAt: string;
58
- readonly labels: readonly string[];
59
- }
60
-
61
- export interface MigrationGraph {
62
- readonly nodes: ReadonlySet<string>;
63
- readonly forwardChain: ReadonlyMap<string, readonly MigrationChainEntry[]>;
64
- readonly reverseChain: ReadonlyMap<string, readonly MigrationChainEntry[]>;
65
- readonly migrationById: ReadonlyMap<string, MigrationChainEntry>;
66
- }