@prisma-next/migration-tools 0.11.0-dev.3 → 0.11.0-dev.31

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 (94) hide show
  1. package/dist/{errors-DGYwcwXs.mjs → errors-CoEN114u.mjs} +14 -2
  2. package/dist/errors-CoEN114u.mjs.map +1 -0
  3. package/dist/exports/aggregate.d.mts +4 -4
  4. package/dist/exports/aggregate.d.mts.map +1 -1
  5. package/dist/exports/aggregate.mjs +5 -4
  6. package/dist/exports/aggregate.mjs.map +1 -1
  7. package/dist/exports/enumerate-migration-spaces.d.mts +53 -0
  8. package/dist/exports/enumerate-migration-spaces.d.mts.map +1 -0
  9. package/dist/exports/enumerate-migration-spaces.mjs +107 -0
  10. package/dist/exports/enumerate-migration-spaces.mjs.map +1 -0
  11. package/dist/exports/errors.d.mts.map +1 -1
  12. package/dist/exports/errors.mjs +1 -1
  13. package/dist/exports/graph.d.mts +1 -1
  14. package/dist/exports/hash.d.mts +2 -2
  15. package/dist/exports/hash.d.mts.map +1 -1
  16. package/dist/exports/invariants.d.mts +1 -1
  17. package/dist/exports/invariants.d.mts.map +1 -1
  18. package/dist/exports/invariants.mjs +1 -1
  19. package/dist/exports/io.d.mts +1 -1
  20. package/dist/exports/io.d.mts.map +1 -1
  21. package/dist/exports/io.mjs +1 -1
  22. package/dist/exports/metadata.d.mts +1 -1
  23. package/dist/exports/migration-graph.d.mts +9 -2
  24. package/dist/exports/migration-graph.d.mts.map +1 -0
  25. package/dist/exports/migration-graph.mjs +16 -2
  26. package/dist/exports/migration-graph.mjs.map +1 -0
  27. package/dist/exports/migration-list-types.d.mts +2 -0
  28. package/dist/exports/migration-list-types.mjs +1 -0
  29. package/dist/exports/migration-ts.d.mts.map +1 -1
  30. package/dist/exports/migration-ts.mjs.map +1 -1
  31. package/dist/exports/migration.d.mts +1 -1
  32. package/dist/exports/migration.d.mts.map +1 -1
  33. package/dist/exports/migration.mjs +2 -2
  34. package/dist/exports/migration.mjs.map +1 -1
  35. package/dist/exports/package.d.mts +1 -1
  36. package/dist/exports/ref-resolution.d.mts +2 -2
  37. package/dist/exports/ref-resolution.d.mts.map +1 -1
  38. package/dist/exports/ref-resolution.mjs +1 -1
  39. package/dist/exports/ref-resolution.mjs.map +1 -1
  40. package/dist/exports/refs.d.mts +15 -2
  41. package/dist/exports/refs.d.mts.map +1 -0
  42. package/dist/exports/refs.mjs +137 -2
  43. package/dist/exports/refs.mjs.map +1 -0
  44. package/dist/exports/spaces.d.mts +27 -2
  45. package/dist/exports/spaces.d.mts.map +1 -1
  46. package/dist/exports/spaces.mjs +9 -7
  47. package/dist/exports/spaces.mjs.map +1 -1
  48. package/dist/{graph-BrLXqoUc.d.mts → graph-C7AJPGV5.d.mts} +1 -1
  49. package/dist/graph-C7AJPGV5.d.mts.map +1 -0
  50. package/dist/hash-Cr4WIr4Z.mjs.map +1 -1
  51. package/dist/{invariants-0daYEzyo.mjs → invariants-lbJddL-S.mjs} +2 -2
  52. package/dist/{invariants-0daYEzyo.mjs.map → invariants-lbJddL-S.mjs.map} +1 -1
  53. package/dist/{io-BPLfzvZe.mjs → io-gHmDrSjQ.mjs} +3 -3
  54. package/dist/{io-BPLfzvZe.mjs.map → io-gHmDrSjQ.mjs.map} +1 -1
  55. package/dist/{migration-graph-De0dUZoC.d.mts → migration-graph-ABYqVsmv.d.mts} +3 -3
  56. package/dist/migration-graph-ABYqVsmv.d.mts.map +1 -0
  57. package/dist/{migration-graph-nlS4TRpn.mjs → migration-graph-C2iNX8dk.mjs} +2 -2
  58. package/dist/{migration-graph-nlS4TRpn.mjs.map → migration-graph-C2iNX8dk.mjs.map} +1 -1
  59. package/dist/migration-list-types-B-qimPet.d.mts +23 -0
  60. package/dist/migration-list-types-B-qimPet.d.mts.map +1 -0
  61. package/dist/op-schema-D5qkXfEf.mjs.map +1 -1
  62. package/dist/{package-DZj8YvD0.d.mts → package-DIttKL7X.d.mts} +1 -1
  63. package/dist/package-DIttKL7X.d.mts.map +1 -0
  64. package/dist/read-contract-space-contract-CwwlqKl_.mjs +82 -0
  65. package/dist/read-contract-space-contract-CwwlqKl_.mjs.map +1 -0
  66. package/dist/{refs-CDaNerhT.d.mts → refs-BaygQaFD.d.mts} +1 -1
  67. package/dist/refs-BaygQaFD.d.mts.map +1 -0
  68. package/dist/{refs-BDHo5l_g.mjs → refs-HhOkD8BT.mjs} +3 -3
  69. package/dist/refs-HhOkD8BT.mjs.map +1 -0
  70. package/dist/{read-contract-space-contract-DRueB4Aa.mjs → verify-contract-spaces-DxXWxGR0.mjs} +32 -80
  71. package/dist/verify-contract-spaces-DxXWxGR0.mjs.map +1 -0
  72. package/package.json +14 -6
  73. package/src/emit-contract-space-artefacts.ts +4 -3
  74. package/src/enumerate-migration-spaces.ts +127 -0
  75. package/src/errors.ts +15 -0
  76. package/src/exports/enumerate-migration-spaces.ts +4 -0
  77. package/src/exports/migration-graph.ts +1 -0
  78. package/src/exports/migration-list-types.ts +5 -0
  79. package/src/exports/refs.ts +8 -0
  80. package/src/exports/spaces.ts +3 -0
  81. package/src/graph-membership.ts +17 -0
  82. package/src/migration-list-types.ts +21 -0
  83. package/src/read-contract-space-head-ref.ts +5 -2
  84. package/src/refs/snapshot.ts +197 -0
  85. package/src/refs.ts +3 -1
  86. package/src/space-layout.ts +30 -0
  87. package/dist/errors-DGYwcwXs.mjs.map +0 -1
  88. package/dist/graph-BrLXqoUc.d.mts.map +0 -1
  89. package/dist/migration-graph-De0dUZoC.d.mts.map +0 -1
  90. package/dist/package-DZj8YvD0.d.mts.map +0 -1
  91. package/dist/read-contract-space-contract-DRueB4Aa.mjs.map +0 -1
  92. package/dist/refs-BDHo5l_g.mjs.map +0 -1
  93. package/dist/refs-CDaNerhT.d.mts.map +0 -1
  94. /package/dist/{metadata-BFX0xdz8.d.mts → metadata-B4Wy6zor.d.mts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enumerate-migration-spaces.mjs","names":[],"sources":["../../src/enumerate-migration-spaces.ts"],"sourcesContent":["import { readMigrationsDir } from './io';\nimport type { MigrationListEntry, MigrationSpaceListEntry } from './migration-list-types';\nimport { readRefs } from './refs';\nimport {\n APP_SPACE_ID,\n isValidSpaceId,\n RESERVED_SPACE_SUBDIR_NAMES,\n spaceMigrationDirectory,\n spaceRefsDirectory,\n} from './space-layout';\nimport { listContractSpaceDirectories } from './verify-contract-spaces';\n\n/**\n * Index `migrations/<space>/refs/*.json` by the contract hash each ref\n * points at, so callers can attach `(ref names)` decorations to every\n * row whose destination contract hash matches.\n *\n * Each bucket is sorted lex-asc to keep rendered output deterministic\n * (adjacent rows pointing at the same hash render their ref decorations\n * in the same order).\n *\n * Refs whose hash matches no migration on disk are still indexed; the\n * caller decides whether to surface them. Migration rows only carry\n * `(refs)` decorations when a matching destination contract hash exists\n * on disk — orphan refs are not rendered on any row.\n *\n * Returns an empty map when the refs directory does not exist\n * ({@link readRefs} treats `ENOENT` as \"no refs\").\n */\nexport async function resolveRefsByContractHash(\n refsDir: string,\n): Promise<ReadonlyMap<string, readonly string[]>> {\n const refs = await readRefs(refsDir);\n const byHash = new Map<string, string[]>();\n for (const [name, entry] of Object.entries(refs)) {\n const bucket = byHash.get(entry.hash);\n if (bucket) bucket.push(name);\n else byHash.set(entry.hash, [name]);\n }\n for (const bucket of byHash.values()) {\n bucket.sort();\n }\n return byHash;\n}\n\n/**\n * Compare two contract-space IDs for the inter-space ordering rule:\n * {@link APP_SPACE_ID} first if present, then lex-asc on the rest.\n */\nfunction compareSpaceIds(a: string, b: string): number {\n if (a === APP_SPACE_ID) return b === APP_SPACE_ID ? 0 : -1;\n if (b === APP_SPACE_ID) return 1;\n if (a < b) return -1;\n if (a > b) return 1;\n return 0;\n}\n\n/**\n * Sort `dirName` descending so the rendered output reads latest-first,\n * matching the `git log` latest-first convention.\n */\nfunction compareDirNamesDescending(a: MigrationListEntry, b: MigrationListEntry): number {\n if (a.dirName < b.dirName) return 1;\n if (a.dirName > b.dirName) return -1;\n return 0;\n}\n\n/**\n * Enumerate every contract space's on-disk migrations under\n * `<projectMigrationsDir>/`. For each valid space directory:\n *\n * - Loads on-disk packages via {@link readMigrationsDir}.\n * - Attaches ref decorations: each migration's `refs[]` lists every ref\n * name from `migrations/<spaceId>/refs/*.json` whose hash equals the\n * migration's destination contract hash.\n * - Sorts migrations within the space by `dirName` descending\n * (reverse-filename, latest first).\n *\n * Contract spaces are returned with {@link APP_SPACE_ID} first when\n * present, then the remaining ids lex-asc. A contract-space directory\n * that contains no migrations becomes `{ spaceId, migrations: [] }` so\n * the renderer's empty-state path can surface it.\n *\n * Directory entries that are not valid {@link isValidSpaceId} names are\n * skipped (a stray non-space directory under `migrations/` does not\n * spawn a phantom space entry). Entries whose name appears in\n * {@link RESERVED_SPACE_SUBDIR_NAMES} are also skipped — the per-space\n * `refs/` subdirectory name shape would otherwise satisfy\n * {@link isValidSpaceId} and surface as a phantom contract space.\n *\n * Returns `[]` when `<projectMigrationsDir>` does not exist — a fresh\n * project that has not authored any migration yet.\n */\nexport async function enumerateMigrationSpaces(args: {\n readonly projectMigrationsDir: string;\n}): Promise<readonly MigrationSpaceListEntry[]> {\n const { projectMigrationsDir } = args;\n const candidateDirs = await listContractSpaceDirectories(projectMigrationsDir);\n const spaceIds = candidateDirs\n .filter((name) => !RESERVED_SPACE_SUBDIR_NAMES.has(name))\n .filter(isValidSpaceId)\n .sort(compareSpaceIds);\n\n const spaces: MigrationSpaceListEntry[] = [];\n for (const spaceId of spaceIds) {\n const spaceDir = spaceMigrationDirectory(projectMigrationsDir, spaceId);\n const packages = await readMigrationsDir(spaceDir);\n const refsByHash = await resolveRefsByContractHash(spaceRefsDirectory(spaceDir));\n\n const migrations: MigrationListEntry[] = packages\n .map((pkg) => ({\n dirName: pkg.dirName,\n from: pkg.metadata.from,\n to: pkg.metadata.to,\n migrationHash: pkg.metadata.migrationHash,\n operationCount: pkg.ops.length,\n createdAt: pkg.metadata.createdAt,\n refs: refsByHash.get(pkg.metadata.to) ?? [],\n providedInvariants: pkg.metadata.providedInvariants,\n }))\n .sort(compareDirNamesDescending);\n\n spaces.push({ spaceId, migrations });\n }\n\n return spaces;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA6BA,eAAsB,0BACpB,SACiD;CACjD,MAAM,OAAO,MAAM,SAAS,OAAO;CACnC,MAAM,yBAAS,IAAI,IAAsB;CACzC,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,IAAI,GAAG;EAChD,MAAM,SAAS,OAAO,IAAI,MAAM,IAAI;EACpC,IAAI,QAAQ,OAAO,KAAK,IAAI;OACvB,OAAO,IAAI,MAAM,MAAM,CAAC,IAAI,CAAC;CACpC;CACA,KAAK,MAAM,UAAU,OAAO,OAAO,GACjC,OAAO,KAAK;CAEd,OAAO;AACT;;;;;AAMA,SAAS,gBAAgB,GAAW,GAAmB;CACrD,IAAI,MAAM,cAAc,OAAO,MAAM,eAAe,IAAI;CACxD,IAAI,MAAM,cAAc,OAAO;CAC/B,IAAI,IAAI,GAAG,OAAO;CAClB,IAAI,IAAI,GAAG,OAAO;CAClB,OAAO;AACT;;;;;AAMA,SAAS,0BAA0B,GAAuB,GAA+B;CACvF,IAAI,EAAE,UAAU,EAAE,SAAS,OAAO;CAClC,IAAI,EAAE,UAAU,EAAE,SAAS,OAAO;CAClC,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,eAAsB,yBAAyB,MAEC;CAC9C,MAAM,EAAE,yBAAyB;CAEjC,MAAM,YAAW,MADW,6BAA6B,oBAAoB,GAE1E,QAAQ,SAAS,CAAC,4BAA4B,IAAI,IAAI,CAAC,EACvD,OAAO,cAAc,EACrB,KAAK,eAAe;CAEvB,MAAM,SAAoC,CAAC;CAC3C,KAAK,MAAM,WAAW,UAAU;EAC9B,MAAM,WAAW,wBAAwB,sBAAsB,OAAO;EACtE,MAAM,WAAW,MAAM,kBAAkB,QAAQ;EACjD,MAAM,aAAa,MAAM,0BAA0B,mBAAmB,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AA,SAC3B,OAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA;AAAA,IACP,mBAAA"}
1
+ {"version":3,"file":"errors.d.mts","names":[],"sources":["../../src/errors.ts"],"mappings":";AAoCA;;;;;;;;;;;;;;;;AAAA,cAAa,mBAAA,SAA4B,KAAA;EAAA,SAC9B,IAAA;EAAA,SACA,QAAA;EAAA,SACA,GAAA;EAAA,SACA,GAAA;EAAA,SACA,OAAA,EAAS,MAAA;cAGhB,IAAA,UACA,OAAA,UACA,OAAA;IAAA,SACW,GAAA;IAAA,SACA,GAAA;IAAA,SACA,OAAA,GAAU,MAAA;EAAA;EAAA,OAWhB,EAAA,CAAG,KAAA,YAAiB,KAAA,IAAS,mBAAA;AAAA;AAAA,iBA0BtB,gBAAA,CAAiB,QAAA,UAAkB,UAAA,WAAqB,mBAAmB;AAAA,iBAwD3E,+BAAA,CAAgC,IAAA;EAAA,SACrC,WAAA;EAAA,SACA,cAAA;EAAA,SACA,WAAA;AAAA,IACP,mBAAmB;;;;;;;;;AAqMA;AAqBvB;;UAlCiB,6BAAA;EAAA,SACN,OAAA;EAAA,SACA,aAAA;EAAA,SACA,IAAA;EAAA,SACA,EAAA;EAAA,SACA,UAAA;AAAA;AAAA,iBAGK,oBAAA,CAAqB,IAAA;EAAA,SAC1B,OAAA;EAAA,SACA,QAAA;EAAA,SACA,OAAA;EAAA,SACA,cAAA,WAAyB,6BAAA;AAAA,IAChC,mBAAmB;AAAA,iBAqBP,qBAAA,CAAsB,IAAA;EAAA,SAC3B,OAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA;AAAA,IACP,mBAAmB"}
@@ -1,2 +1,2 @@
1
- import { T as errorUnknownInvariant, r as errorDescriptorHeadHashMismatch, t as MigrationToolsError, u as errorInvalidJson, x as errorNoInvariantPath } from "../errors-DGYwcwXs.mjs";
1
+ import { E as errorUnknownInvariant, S as errorNoInvariantPath, d as errorInvalidJson, r as errorDescriptorHeadHashMismatch, t as MigrationToolsError } from "../errors-CoEN114u.mjs";
2
2
  export { MigrationToolsError, errorDescriptorHeadHashMismatch, errorInvalidJson, errorNoInvariantPath, errorUnknownInvariant };
@@ -1,2 +1,2 @@
1
- import { n as MigrationGraph, t as MigrationEdge } from "../graph-BrLXqoUc.mjs";
1
+ import { n as MigrationGraph, t as MigrationEdge } from "../graph-C7AJPGV5.mjs";
2
2
  export { type MigrationEdge, type MigrationGraph };
@@ -1,5 +1,5 @@
1
- import { n as OnDiskMigrationPackage, t as MigrationOps } from "../package-DZj8YvD0.mjs";
2
- import { n as MigrationMetadata } from "../metadata-BFX0xdz8.mjs";
1
+ import { n as OnDiskMigrationPackage, t as MigrationOps } from "../package-DIttKL7X.mjs";
2
+ import { n as MigrationMetadata } from "../metadata-B4Wy6zor.mjs";
3
3
 
4
4
  //#region src/hash.d.ts
5
5
  interface VerifyResult {
@@ -1 +1 @@
1
- {"version":3,"file":"hash.d.mts","names":[],"sources":["../../src/hash.ts"],"mappings":";;;;UAKiB,YAAA;EAAA,SACN,EAAA;EAAA,SACA,MAAA;EAAA,SACA,UAAA;EAAA,SACA,YAAA;AAAA;;;;;;;AAmCX;;;;;;;;;;;;;;;;AAwBA;;;;;;iBAxBgB,oBAAA,CACd,QAAA,EAAU,IAAA,CAAK,iBAAA;EAAA,SAAiD,aAAA;AAAA,GAChE,GAAA,EAAK,YAAA;;;;;;;;;;iBAsBS,mBAAA,CAAoB,GAAA,EAAK,sBAAA,GAAyB,YAAA"}
1
+ {"version":3,"file":"hash.d.mts","names":[],"sources":["../../src/hash.ts"],"mappings":";;;;UAKiB,YAAA;EAAA,SACN,EAAA;EAAA,SACA,MAAA;EAAA,SACA,UAAA;EAAA,SACA,YAAA;AAAA;;;;;;AAAY;AAmCvB;;;;;;;;;;;;;;;AAEmB;AAsBnB;;;;;;iBAxBgB,oBAAA,CACd,QAAA,EAAU,IAAA,CAAK,iBAAA;EAAA,SAAiD,aAAA;AAAA,GAChE,GAAA,EAAK,YAAA;;;;;;;;;;iBAsBS,mBAAA,CAAoB,GAAA,EAAK,sBAAA,GAAyB,YAAY"}
@@ -1,4 +1,4 @@
1
- import { t as MigrationOps } from "../package-DZj8YvD0.mjs";
1
+ import { t as MigrationOps } from "../package-DIttKL7X.mjs";
2
2
 
3
3
  //#region src/invariants.d.ts
4
4
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"invariants.d.mts","names":[],"sources":["../../src/invariants.ts"],"mappings":";;;;;AAUA;;;;iBAAgB,mBAAA,CAAoB,WAAA;AA8BpC;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAAgB,wBAAA,CAAyB,GAAA,EAAK,YAAA"}
1
+ {"version":3,"file":"invariants.d.mts","names":[],"sources":["../../src/invariants.ts"],"mappings":";;;;;AAUA;;;;iBAAgB,mBAAA,CAAoB,WAAmB;AA8BvD;;;;AAA0D;;;;;;;;;;;;;;;;;;;;;AAA1D,iBAAgB,wBAAA,CAAyB,GAAiB,EAAZ,YAAY"}
@@ -1,2 +1,2 @@
1
- import { n as validateInvariantId, t as deriveProvidedInvariants } from "../invariants-0daYEzyo.mjs";
1
+ import { n as validateInvariantId, t as deriveProvidedInvariants } from "../invariants-lbJddL-S.mjs";
2
2
  export { deriveProvidedInvariants, validateInvariantId };
@@ -1,4 +1,4 @@
1
- import { n as OnDiskMigrationPackage, t as MigrationOps } from "../package-DZj8YvD0.mjs";
1
+ import { n as OnDiskMigrationPackage, t as MigrationOps } from "../package-DIttKL7X.mjs";
2
2
  import { MigrationMetadata, MigrationPackage } from "@prisma-next/framework-components/control";
3
3
 
4
4
  //#region src/io.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"io.d.mts","names":[],"sources":["../../src/io.ts"],"mappings":";;;;iBA+CsB,qBAAA,CACpB,GAAA,UACA,QAAA,EAAU,iBAAA,EACV,GAAA,EAAK,YAAA,GACJ,OAAA;AAJH;;;;;;;;;;;;;;;;AAoDA;;;;;;;;;;AA8BA;;;;AAlFA,iBAoDsB,2BAAA,CACpB,SAAA,UACA,GAAA,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Aa,GAAA,EAAK,YAAA,GAAe,OAAO;AAAA,iBAI1D,oBAAA,CAAqB,GAAA,WAAc,OAAO,CAAC,sBAAA;AAAA,iBAiG3C,iBAAA,CACpB,cAAA,WACC,OAAO,UAAU,sBAAA;AAAA,iBA+BJ,sBAAA,CAAuB,SAAA,EAAW,IAAI,EAAE,IAAA"}
@@ -1,2 +1,2 @@
1
- import { a as materialiseMigrationPackage, c as writeMigrationMetadata, i as materialiseExtensionMigrationPackageIfMissing, l as writeMigrationOps, n as copyFilesWithRename, o as readMigrationPackage, r as formatMigrationDirName, s as readMigrationsDir, u as writeMigrationPackage } from "../io-BPLfzvZe.mjs";
1
+ import { a as materialiseMigrationPackage, c as writeMigrationMetadata, i as materialiseExtensionMigrationPackageIfMissing, l as writeMigrationOps, n as copyFilesWithRename, o as readMigrationPackage, r as formatMigrationDirName, s as readMigrationsDir, u as writeMigrationPackage } from "../io-gHmDrSjQ.mjs";
2
2
  export { copyFilesWithRename, formatMigrationDirName, materialiseExtensionMigrationPackageIfMissing, materialiseMigrationPackage, readMigrationPackage, readMigrationsDir, writeMigrationMetadata, writeMigrationOps, writeMigrationPackage };
@@ -1,2 +1,2 @@
1
- import { n as MigrationMetadata, t as MigrationHints } from "../metadata-BFX0xdz8.mjs";
1
+ import { n as MigrationMetadata, t as MigrationHints } from "../metadata-B4Wy6zor.mjs";
2
2
  export { type MigrationHints, type MigrationMetadata };
@@ -1,2 +1,9 @@
1
- import { a as findLeaf, c as findPathWithInvariants, i as findLatestMigration, l as findReachableLeaves, n as detectCycles, o as findPath, r as detectOrphans, s as findPathWithDecision, t as PathDecision, u as reconstructGraph } from "../migration-graph-De0dUZoC.mjs";
2
- export { type PathDecision, detectCycles, detectOrphans, findLatestMigration, findLeaf, findPath, findPathWithDecision, findPathWithInvariants, findReachableLeaves, reconstructGraph };
1
+ import { n as MigrationGraph } from "../graph-C7AJPGV5.mjs";
2
+ import { a as findLeaf, c as findPathWithInvariants, i as findLatestMigration, l as findReachableLeaves, n as detectCycles, o as findPath, r as detectOrphans, s as findPathWithDecision, t as PathDecision, u as reconstructGraph } from "../migration-graph-ABYqVsmv.mjs";
3
+
4
+ //#region src/graph-membership.d.ts
5
+ declare function isGraphNode(hash: string, graph: MigrationGraph): boolean;
6
+ declare function assertHashIsGraphNode(hash: string, graph: MigrationGraph): asserts hash is string;
7
+ //#endregion
8
+ export { type PathDecision, assertHashIsGraphNode, detectCycles, detectOrphans, findLatestMigration, findLeaf, findPath, findPathWithDecision, findPathWithInvariants, findReachableLeaves, isGraphNode, reconstructGraph };
9
+ //# sourceMappingURL=migration-graph.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-graph.d.mts","names":[],"sources":["../../src/graph-membership.ts"],"mappings":";;;;iBAIgB,WAAA,CAAY,IAAA,UAAc,KAAA,EAAO,cAAc;AAAA,iBAO/C,qBAAA,CAAsB,IAAA,UAAc,KAAA,EAAO,cAAc,WAAW,IAAA"}
@@ -1,2 +1,16 @@
1
- import { a as findPath, c as findReachableLeaves, i as findLeaf, l as reconstructGraph, n as detectOrphans, o as findPathWithDecision, r as findLatestMigration, s as findPathWithInvariants, t as detectCycles } from "../migration-graph-nlS4TRpn.mjs";
2
- export { detectCycles, detectOrphans, findLatestMigration, findLeaf, findPath, findPathWithDecision, findPathWithInvariants, findReachableLeaves, reconstructGraph };
1
+ import { c as errorHashNotInGraph } from "../errors-CoEN114u.mjs";
2
+ import "../constants-DWV9_o2Z.mjs";
3
+ import { a as findPath, c as findReachableLeaves, i as findLeaf, l as reconstructGraph, n as detectOrphans, o as findPathWithDecision, r as findLatestMigration, s as findPathWithInvariants, t as detectCycles } from "../migration-graph-C2iNX8dk.mjs";
4
+ //#region src/graph-membership.ts
5
+ function isGraphNode(hash, graph) {
6
+ if (hash === "sha256:empty") return true;
7
+ return graph.nodes.has(hash);
8
+ }
9
+ function assertHashIsGraphNode(hash, graph) {
10
+ if (isGraphNode(hash, graph)) return;
11
+ throw errorHashNotInGraph(hash, graph);
12
+ }
13
+ //#endregion
14
+ export { assertHashIsGraphNode, detectCycles, detectOrphans, findLatestMigration, findLeaf, findPath, findPathWithDecision, findPathWithInvariants, findReachableLeaves, isGraphNode, reconstructGraph };
15
+
16
+ //# sourceMappingURL=migration-graph.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-graph.mjs","names":[],"sources":["../../src/graph-membership.ts"],"sourcesContent":["import { EMPTY_CONTRACT_HASH } from './constants';\nimport { errorHashNotInGraph } from './errors';\nimport type { MigrationGraph } from './graph';\n\nexport function isGraphNode(hash: string, graph: MigrationGraph): boolean {\n if (hash === EMPTY_CONTRACT_HASH) {\n return true;\n }\n return graph.nodes.has(hash);\n}\n\nexport function assertHashIsGraphNode(hash: string, graph: MigrationGraph): asserts hash is string {\n if (isGraphNode(hash, graph)) {\n return;\n }\n throw errorHashNotInGraph(hash, graph);\n}\n"],"mappings":";;;;AAIA,SAAgB,YAAY,MAAc,OAAgC;CACxE,IAAI,SAAA,gBACF,OAAO;CAET,OAAO,MAAM,MAAM,IAAI,IAAI;AAC7B;AAEA,SAAgB,sBAAsB,MAAc,OAA+C;CACjG,IAAI,YAAY,MAAM,KAAK,GACzB;CAEF,MAAM,oBAAoB,MAAM,KAAK;AACvC"}
@@ -0,0 +1,2 @@
1
+ import { n as MigrationListResult, r as MigrationSpaceListEntry, t as MigrationListEntry } from "../migration-list-types-B-qimPet.mjs";
2
+ export { type MigrationListEntry, type MigrationListResult, type MigrationSpaceListEntry };
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1 @@
1
- {"version":3,"file":"migration-ts.d.mts","names":[],"sources":["../../src/migration-ts.ts","../../src/runtime-detection.ts"],"mappings":";;AA8BA;;;;;;;;;AAsBA;;;;;;;;ACpDA;;;;;iBD8BsB,gBAAA,CAAiB,UAAA,UAAoB,OAAA,WAAkB,OAAA;;;;iBAsBvD,cAAA,CAAe,UAAA,WAAqB,OAAA;;;KCpD9C,eAAA;AAAA,iBAEI,qBAAA,CAAA,GAAyB,eAAA;AAAA,iBAMzB,cAAA,CAAe,OAAA,EAAS,eAAA"}
1
+ {"version":3,"file":"migration-ts.d.mts","names":[],"sources":["../../src/migration-ts.ts","../../src/runtime-detection.ts"],"mappings":";;AA8BA;;;;;;;;AAAoF;AAsBpF;;;;AAAiE;;;;ACpDjE;;;;AAA2B;iBD8BL,gBAAA,CAAiB,UAAA,UAAoB,OAAA,WAAkB,OAAO;;;;iBAsB9D,cAAA,CAAe,UAAA,WAAqB,OAAO;;;KCpDrD,eAAA;AAAA,iBAEI,qBAAA,CAAA,GAAyB,eAAe;AAAA,iBAMxC,cAAA,CAAe,OAAwB,EAAf,eAAe"}
@@ -1 +1 @@
1
- {"version":3,"file":"migration-ts.mjs","names":[],"sources":["../../src/migration-ts.ts","../../src/runtime-detection.ts"],"sourcesContent":["/**\n * Utilities for reading/writing `migration.ts` files.\n *\n * Rendering migration.ts source is the target's responsibility — the CLI\n * obtains source strings from a planner's `plan.renderTypeScript()`. The\n * helper here is limited to file I/O: writing the returned source with the\n * right executable bit and probing for existence.\n */\n\nimport { stat, writeFile } from 'node:fs/promises';\nimport { join } from 'pathe';\nimport { format } from 'prettier';\n\nconst MIGRATION_TS_FILE = 'migration.ts';\n\n/**\n * Writes a pre-rendered `migration.ts` source string to the given package\n * directory. If the source begins with a shebang, the file is written with\n * executable permissions (0o755) so it can be run directly via\n * `./migration.ts` — the rendered scaffold ends with\n * `MigrationCLI.run(import.meta.url, M)` from\n * `@prisma-next/cli/migration-cli` (re-exported by the postgres facade),\n * which guards on the entrypoint and serializes when the file is the main\n * module.\n *\n * The source is run through prettier before writing so migration renderers\n * can produce structurally-correct but loosely-indented source and rely on\n * a single canonical format on disk. Matches what `@prisma-next/emitter`\n * already does for generated `contract.d.ts`.\n */\nexport async function writeMigrationTs(packageDir: string, content: string): Promise<void> {\n const formatted = await formatMigrationTsSource(content);\n const isExecutable = formatted.startsWith('#!');\n await writeFile(\n join(packageDir, MIGRATION_TS_FILE),\n formatted,\n isExecutable ? { mode: 0o755 } : undefined,\n );\n}\n\nasync function formatMigrationTsSource(source: string): Promise<string> {\n return format(source, {\n parser: 'typescript',\n singleQuote: true,\n semi: true,\n printWidth: 100,\n });\n}\n\n/**\n * Checks whether a migration.ts file exists in the package directory.\n */\nexport async function hasMigrationTs(packageDir: string): Promise<boolean> {\n try {\n const s = await stat(join(packageDir, MIGRATION_TS_FILE));\n return s.isFile();\n } catch {\n return false;\n }\n}\n","export type ScaffoldRuntime = 'node' | 'bun' | 'deno';\n\nexport function detectScaffoldRuntime(): ScaffoldRuntime {\n if (typeof (globalThis as { Bun?: unknown }).Bun !== 'undefined') return 'bun';\n if (typeof (globalThis as { Deno?: unknown }).Deno !== 'undefined') return 'deno';\n return 'node';\n}\n\nexport function shebangLineFor(runtime: ScaffoldRuntime): string {\n switch (runtime) {\n case 'bun':\n return '#!/usr/bin/env -S bun';\n case 'deno':\n return '#!/usr/bin/env -S deno run -A';\n case 'node':\n return '#!/usr/bin/env -S node';\n }\n}\n"],"mappings":";;;;;;;;;;;;AAaA,MAAM,oBAAoB;;;;;;;;;;;;;;;;AAiB1B,eAAsB,iBAAiB,YAAoB,SAAgC;CACzF,MAAM,YAAY,MAAM,wBAAwB,QAAQ;CACxD,MAAM,eAAe,UAAU,WAAW,KAAK;CAC/C,MAAM,UACJ,KAAK,YAAY,kBAAkB,EACnC,WACA,eAAe,EAAE,MAAM,KAAO,GAAG,KAAA,EAClC;;AAGH,eAAe,wBAAwB,QAAiC;CACtE,OAAO,OAAO,QAAQ;EACpB,QAAQ;EACR,aAAa;EACb,MAAM;EACN,YAAY;EACb,CAAC;;;;;AAMJ,eAAsB,eAAe,YAAsC;CACzE,IAAI;EAEF,QAAO,MADS,KAAK,KAAK,YAAY,kBAAkB,CAAC,EAChD,QAAQ;SACX;EACN,OAAO;;;;;ACvDX,SAAgB,wBAAyC;CACvD,IAAI,OAAQ,WAAiC,QAAQ,aAAa,OAAO;CACzE,IAAI,OAAQ,WAAkC,SAAS,aAAa,OAAO;CAC3E,OAAO;;AAGT,SAAgB,eAAe,SAAkC;CAC/D,QAAQ,SAAR;EACE,KAAK,OACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,KAAK,QACH,OAAO"}
1
+ {"version":3,"file":"migration-ts.mjs","names":[],"sources":["../../src/migration-ts.ts","../../src/runtime-detection.ts"],"sourcesContent":["/**\n * Utilities for reading/writing `migration.ts` files.\n *\n * Rendering migration.ts source is the target's responsibility — the CLI\n * obtains source strings from a planner's `plan.renderTypeScript()`. The\n * helper here is limited to file I/O: writing the returned source with the\n * right executable bit and probing for existence.\n */\n\nimport { stat, writeFile } from 'node:fs/promises';\nimport { join } from 'pathe';\nimport { format } from 'prettier';\n\nconst MIGRATION_TS_FILE = 'migration.ts';\n\n/**\n * Writes a pre-rendered `migration.ts` source string to the given package\n * directory. If the source begins with a shebang, the file is written with\n * executable permissions (0o755) so it can be run directly via\n * `./migration.ts` — the rendered scaffold ends with\n * `MigrationCLI.run(import.meta.url, M)` from\n * `@prisma-next/cli/migration-cli` (re-exported by the postgres facade),\n * which guards on the entrypoint and serializes when the file is the main\n * module.\n *\n * The source is run through prettier before writing so migration renderers\n * can produce structurally-correct but loosely-indented source and rely on\n * a single canonical format on disk. Matches what `@prisma-next/emitter`\n * already does for generated `contract.d.ts`.\n */\nexport async function writeMigrationTs(packageDir: string, content: string): Promise<void> {\n const formatted = await formatMigrationTsSource(content);\n const isExecutable = formatted.startsWith('#!');\n await writeFile(\n join(packageDir, MIGRATION_TS_FILE),\n formatted,\n isExecutable ? { mode: 0o755 } : undefined,\n );\n}\n\nasync function formatMigrationTsSource(source: string): Promise<string> {\n return format(source, {\n parser: 'typescript',\n singleQuote: true,\n semi: true,\n printWidth: 100,\n });\n}\n\n/**\n * Checks whether a migration.ts file exists in the package directory.\n */\nexport async function hasMigrationTs(packageDir: string): Promise<boolean> {\n try {\n const s = await stat(join(packageDir, MIGRATION_TS_FILE));\n return s.isFile();\n } catch {\n return false;\n }\n}\n","export type ScaffoldRuntime = 'node' | 'bun' | 'deno';\n\nexport function detectScaffoldRuntime(): ScaffoldRuntime {\n if (typeof (globalThis as { Bun?: unknown }).Bun !== 'undefined') return 'bun';\n if (typeof (globalThis as { Deno?: unknown }).Deno !== 'undefined') return 'deno';\n return 'node';\n}\n\nexport function shebangLineFor(runtime: ScaffoldRuntime): string {\n switch (runtime) {\n case 'bun':\n return '#!/usr/bin/env -S bun';\n case 'deno':\n return '#!/usr/bin/env -S deno run -A';\n case 'node':\n return '#!/usr/bin/env -S node';\n }\n}\n"],"mappings":";;;;;;;;;;;;AAaA,MAAM,oBAAoB;;;;;;;;;;;;;;;;AAiB1B,eAAsB,iBAAiB,YAAoB,SAAgC;CACzF,MAAM,YAAY,MAAM,wBAAwB,OAAO;CACvD,MAAM,eAAe,UAAU,WAAW,IAAI;CAC9C,MAAM,UACJ,KAAK,YAAY,iBAAiB,GAClC,WACA,eAAe,EAAE,MAAM,IAAM,IAAI,KAAA,CACnC;AACF;AAEA,eAAe,wBAAwB,QAAiC;CACtE,OAAO,OAAO,QAAQ;EACpB,QAAQ;EACR,aAAa;EACb,MAAM;EACN,YAAY;CACd,CAAC;AACH;;;;AAKA,eAAsB,eAAe,YAAsC;CACzE,IAAI;EAEF,QAAO,MADS,KAAK,KAAK,YAAY,iBAAiB,CAAC,GAC/C,OAAO;CAClB,QAAQ;EACN,OAAO;CACT;AACF;;;ACzDA,SAAgB,wBAAyC;CACvD,IAAI,OAAQ,WAAiC,QAAQ,aAAa,OAAO;CACzE,IAAI,OAAQ,WAAkC,SAAS,aAAa,OAAO;CAC3E,OAAO;AACT;AAEA,SAAgB,eAAe,SAAkC;CAC/D,QAAQ,SAAR;EACE,KAAK,OACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,KAAK,QACH,OAAO;CACX;AACF"}
@@ -1,4 +1,4 @@
1
- import { n as MigrationMetadata$1 } from "../metadata-BFX0xdz8.mjs";
1
+ import { n as MigrationMetadata$1 } from "../metadata-B4Wy6zor.mjs";
2
2
  import { ControlStack, MigrationPlan, MigrationPlanOperation } from "@prisma-next/framework-components/control";
3
3
 
4
4
  //#region src/migration-base.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"migration.d.mts","names":[],"sources":["../../src/migration-base.ts"],"mappings":";;;;UAeiB,aAAA;EAAA,SACN,IAAA;EAAA,SACA,EAAA;EAAA,SACA,MAAA;AAAA;;;;;;;AAuBX;;;uBAAsB,SAAA,oBACD,sBAAA,GAAyB,sBAAA,mFAGjC,aAAA;EAAA,kBAEO,QAAA;EAWqB;;;;;;;;;EAAA,mBAApB,KAAA,EAAO,YAAA,CAAa,SAAA,EAAW,SAAA;cAEtC,KAAA,GAAQ,YAAA,CAAa,SAAA,EAAW,SAAA;EAlB5C;;;;;;EAAA,aA4Ba,UAAA,CAAA,YAAuB,UAAA;EAZjB;;;;;EAAA,SAmBV,QAAA,CAAA,GAAY,aAAA;EAAA,IAEjB,MAAA,CAAA;IAAA,SAAqB,WAAA;EAAA;EAAA,IAKrB,WAAA,CAAA;IAAA,SAA0B,WAAA;EAAA;AAAA;;;;;;;AAYhC;iBAAgB,kBAAA,CAAmB,aAAA;;;;AAsBnC;;;;;;;;UAAiB,kBAAA;EAAA,SACN,OAAA;EAAA,SACA,QAAA,EAAU,mBAAA;EAAA,SACV,YAAA;AAAA;;;;;;;;;;iBA8DK,uBAAA,CACd,QAAA,EAAU,SAAA,EACV,QAAA,EAAU,OAAA,CAAQ,mBAAA,WACjB,kBAAA"}
1
+ {"version":3,"file":"migration.d.mts","names":[],"sources":["../../src/migration-base.ts"],"mappings":";;;;UAeiB,aAAA;EAAA,SACN,IAAA;EAAA,SACA,EAAA;EAAA,SACA,MAAA;AAAA;;;;;;AAAM;AAuBjB;;;uBAAsB,SAAA,oBACD,sBAAA,GAAyB,sBAAA,mFAGjC,aAAA;EAAA,kBAEO,QAAA;EAWqB;;;;;;;;;EAAA,mBAApB,KAAA,EAAO,YAAA,CAAa,SAAA,EAAW,SAAA;cAEtC,KAAA,GAAQ,YAAA,CAAa,SAAA,EAAW,SAAA;EAlB5C;;;;;;EAAA,aA4Ba,UAAA,CAAA,YAAuB,UAAA;EAZjB;;;;;EAAA,SAmBV,QAAA,CAAA,GAAY,aAAA;EAAA,IAEjB,MAAA,CAAA;IAAA,SAAqB,WAAA;EAAA;EAAA,IAKrB,WAAA,CAAA;IAAA,SAA0B,WAAA;EAAA;AAAA;;;;;;AAAW;AAY3C;iBAAgB,kBAAA,CAAmB,aAAqB;;;AAAA;AAsBxD;;;;;;;;UAAiB,kBAAA;EAAA,SACN,OAAA;EAAA,SACA,QAAA,EAAU,mBAAiB;EAAA,SAC3B,YAAA;AAAA;;;;;;;;;;iBA8DK,uBAAA,CACd,QAAA,EAAU,SAAA,EACV,QAAA,EAAU,OAAA,CAAQ,mBAAA,WACjB,kBAAA"}
@@ -1,6 +1,6 @@
1
- import { f as errorInvalidOperationEntry } from "../errors-DGYwcwXs.mjs";
1
+ import { p as errorInvalidOperationEntry } from "../errors-CoEN114u.mjs";
2
2
  import { t as computeMigrationHash } from "../hash-Cr4WIr4Z.mjs";
3
- import { t as deriveProvidedInvariants } from "../invariants-0daYEzyo.mjs";
3
+ import { t as deriveProvidedInvariants } from "../invariants-lbJddL-S.mjs";
4
4
  import { t as MigrationOpSchema } from "../op-schema-D5qkXfEf.mjs";
5
5
  import { type } from "arktype";
6
6
  import { realpathSync } from "node:fs";
@@ -1 +1 @@
1
- {"version":3,"file":"migration.mjs","names":[],"sources":["../../src/migration-base.ts"],"sourcesContent":["import { realpathSync } from 'node:fs';\nimport { fileURLToPath } from 'node:url';\nimport type {\n ControlStack,\n MigrationPlan,\n MigrationPlanOperation,\n} from '@prisma-next/framework-components/control';\nimport { type } from 'arktype';\nimport { errorInvalidOperationEntry } from './errors';\nimport { computeMigrationHash } from './hash';\nimport { deriveProvidedInvariants } from './invariants';\nimport type { MigrationHints, MigrationMetadata } from './metadata';\nimport { MigrationOpSchema } from './op-schema';\nimport type { MigrationOps } from './package';\n\nexport interface MigrationMeta {\n readonly from: string | null;\n readonly to: string;\n readonly labels?: readonly string[];\n}\n\n// `from` rejects empty strings to mirror `MigrationMetadataSchema` in\n// `./io.ts`. Without this match, an authored migration could `describe()` with\n// `from: ''` and pass `buildMigrationArtifacts`'s validation, only to have\n// `readMigrationPackage` reject the resulting `migration.json` later — the\n// two validators must agree on the legal value space.\nconst MigrationMetaSchema = type({\n from: 'string > 0 | null',\n to: 'string',\n 'labels?': type('string').array(),\n});\n\n/**\n * Base class for migrations.\n *\n * A `Migration` subclass is itself a `MigrationPlan`: CLI commands and the\n * runner can consume it directly via `targetId`, `operations`, `origin`, and\n * `destination`. The metadata-shaped inputs come from `describe()`, which\n * every migration must implement — `migration.json` is required for a\n * migration to be valid.\n */\nexport abstract class Migration<\n TOperation extends MigrationPlanOperation = MigrationPlanOperation,\n TFamilyId extends string = string,\n TTargetId extends string = string,\n> implements MigrationPlan\n{\n abstract readonly targetId: string;\n\n /**\n * Assembled `ControlStack` injected by the orchestrator (`runMigration`).\n *\n * Subclasses (e.g. `PostgresMigration`) read the stack to materialize their\n * adapter once per instance. Optional at the abstract level so unit tests can\n * construct `Migration` instances purely for `operations` / `describe`\n * assertions without needing a real stack; concrete subclasses that need the\n * stack at runtime should narrow the parameter to required.\n */\n protected readonly stack: ControlStack<TFamilyId, TTargetId> | undefined;\n\n constructor(stack?: ControlStack<TFamilyId, TTargetId>) {\n this.stack = stack;\n }\n\n /**\n * Ordered list of operations this migration performs.\n *\n * Implemented as a getter so that subclasses can either precompute the list\n * in their constructor or build it lazily per access.\n */\n abstract get operations(): readonly TOperation[];\n\n /**\n * Metadata inputs used to build `migration.json` and to derive the plan's\n * origin/destination identities. Every migration must provide this —\n * omitting it would produce an invalid on-disk migration package.\n */\n abstract describe(): MigrationMeta;\n\n get origin(): { readonly storageHash: string } | null {\n const from = this.describe().from;\n return from === null ? null : { storageHash: from };\n }\n\n get destination(): { readonly storageHash: string } {\n return { storageHash: this.describe().to };\n }\n}\n\n/**\n * Returns true when `import.meta.url` resolves to the same file that was\n * invoked as the node entrypoint (`process.argv[1]`). Used by\n * `MigrationCLI.run` (in `@prisma-next/cli/migration-cli`) to no-op when\n * the migration module is being imported (e.g. by another script) rather\n * than executed directly.\n */\nexport function isDirectEntrypoint(importMetaUrl: string): boolean {\n const metaFilename = fileURLToPath(importMetaUrl);\n const argv1 = process.argv[1];\n if (!argv1) return false;\n try {\n return realpathSync(metaFilename) === realpathSync(argv1);\n } catch {\n return false;\n }\n}\n\n/**\n * In-memory artifacts produced from a `Migration` instance: the\n * serialized `ops.json` body, the `migration.json` metadata object, and\n * its serialized form. Returned by `buildMigrationArtifacts` so callers\n * (today: `MigrationCLI.run` in `@prisma-next/cli/migration-cli`) can\n * decide how to persist them — write to disk, print in dry-run, ship\n * over the wire — without coupling artifact construction to file I/O.\n *\n * `metadataJson` is `JSON.stringify(metadata, null, 2)` — the canonical\n * on-disk shape that the arktype loader-schema in `./io` validates.\n */\nexport interface MigrationArtifacts {\n readonly opsJson: string;\n readonly metadata: MigrationMetadata;\n readonly metadataJson: string;\n}\n\n/**\n * Build the attested metadata from `describe()`-derived metadata, the\n * operations list, and the previously-scaffolded metadata (if any).\n *\n * When a `migration.json` already exists for this package (the common\n * case: it was scaffolded by `migration plan`), preserve the contract\n * bookends, hints, labels, and `createdAt` set there — those fields are\n * owned by the CLI scaffolder, not the authored class. Only the\n * `describe()`-derived fields (`from`, `to`) and the operations\n * change as the author iterates. When no metadata exists yet (a bare\n * `migration.ts` run from scratch), synthesize a minimal but\n * schema-conformant record so the resulting package can still be read,\n * verified, and applied.\n *\n * The `migrationHash` is recomputed against the current metadata + ops so\n * the on-disk artifacts are always fully attested.\n */\nfunction buildAttestedMetadata(\n meta: MigrationMeta,\n ops: MigrationOps,\n existing: Partial<MigrationMetadata> | null,\n): MigrationMetadata {\n const baseMetadata: Omit<MigrationMetadata, 'migrationHash'> = {\n from: meta.from,\n to: meta.to,\n labels: meta.labels ?? existing?.labels ?? [],\n providedInvariants: deriveProvidedInvariants(ops),\n createdAt: existing?.createdAt ?? new Date().toISOString(),\n hints: normalizeHints(existing?.hints),\n };\n\n const migrationHash = computeMigrationHash(baseMetadata, ops);\n return { ...baseMetadata, migrationHash };\n}\n\n/**\n * Project `existing.hints` down to the known `MigrationHints` shape, dropping\n * any legacy keys that may linger in metadata scaffolded by older CLI\n * versions (e.g. `planningStrategy`). Picking fields explicitly instead of\n * spreading keeps refreshed `migration.json` files schema-clean regardless\n * of what was on disk before.\n */\nfunction normalizeHints(existing: MigrationHints | undefined): MigrationHints {\n return {\n used: existing?.used ?? [],\n applied: existing?.applied ?? [],\n plannerVersion: existing?.plannerVersion ?? '2.0.0',\n };\n}\n\n/**\n * Pure conversion from a `Migration` instance (plus the previously\n * scaffolded metadata, when one exists on disk) to the in-memory\n * artifacts that downstream tooling persists. Owns metadata validation,\n * metadata synthesis/preservation, hint normalization, and the\n * content-addressed `migrationHash` computation, but performs no file I/O\n * — callers handle reads (to source `existing`) and writes (to persist\n * `opsJson` / `metadataJson`).\n */\nexport function buildMigrationArtifacts(\n instance: Migration,\n existing: Partial<MigrationMetadata> | null,\n): MigrationArtifacts {\n const ops = instance.operations;\n if (!Array.isArray(ops)) {\n throw new Error('operations must be an array');\n }\n\n for (let index = 0; index < ops.length; index++) {\n const result = MigrationOpSchema(ops[index]);\n if (result instanceof type.errors) {\n throw errorInvalidOperationEntry(index, result.summary);\n }\n }\n\n const rawMeta: unknown = instance.describe();\n const parsed = MigrationMetaSchema(rawMeta);\n if (parsed instanceof type.errors) {\n throw new Error(`describe() returned invalid metadata: ${parsed.summary}`);\n }\n\n const metadata = buildAttestedMetadata(parsed, ops, existing);\n\n return {\n opsJson: JSON.stringify(ops, null, 2),\n metadata,\n metadataJson: JSON.stringify(metadata, null, 2),\n };\n}\n"],"mappings":";;;;;;;;AA0BA,MAAM,sBAAsB,KAAK;CAC/B,MAAM;CACN,IAAI;CACJ,WAAW,KAAK,SAAS,CAAC,OAAO;CAClC,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KAAK,QACzB,MAAM,2BAA2B,OAAO,OAAO,QAAQ;;CAK3D,MAAM,SAAS,oBADU,SAAS,UACQ,CAAC;CAC3C,IAAI,kBAAkB,KAAK,QACzB,MAAM,IAAI,MAAM,yCAAyC,OAAO,UAAU;CAG5E,MAAM,WAAW,sBAAsB,QAAQ,KAAK,SAAS;CAE7D,OAAO;EACL,SAAS,KAAK,UAAU,KAAK,MAAM,EAAE;EACrC;EACA,cAAc,KAAK,UAAU,UAAU,MAAM,EAAE;EAChD"}
1
+ {"version":3,"file":"migration.mjs","names":[],"sources":["../../src/migration-base.ts"],"sourcesContent":["import { realpathSync } from 'node:fs';\nimport { fileURLToPath } from 'node:url';\nimport type {\n ControlStack,\n MigrationPlan,\n MigrationPlanOperation,\n} from '@prisma-next/framework-components/control';\nimport { type } from 'arktype';\nimport { errorInvalidOperationEntry } from './errors';\nimport { computeMigrationHash } from './hash';\nimport { deriveProvidedInvariants } from './invariants';\nimport type { MigrationHints, MigrationMetadata } from './metadata';\nimport { MigrationOpSchema } from './op-schema';\nimport type { MigrationOps } from './package';\n\nexport interface MigrationMeta {\n readonly from: string | null;\n readonly to: string;\n readonly labels?: readonly string[];\n}\n\n// `from` rejects empty strings to mirror `MigrationMetadataSchema` in\n// `./io.ts`. Without this match, an authored migration could `describe()` with\n// `from: ''` and pass `buildMigrationArtifacts`'s validation, only to have\n// `readMigrationPackage` reject the resulting `migration.json` later — the\n// two validators must agree on the legal value space.\nconst MigrationMetaSchema = type({\n from: 'string > 0 | null',\n to: 'string',\n 'labels?': type('string').array(),\n});\n\n/**\n * Base class for migrations.\n *\n * A `Migration` subclass is itself a `MigrationPlan`: CLI commands and the\n * runner can consume it directly via `targetId`, `operations`, `origin`, and\n * `destination`. The metadata-shaped inputs come from `describe()`, which\n * every migration must implement — `migration.json` is required for a\n * migration to be valid.\n */\nexport abstract class Migration<\n TOperation extends MigrationPlanOperation = MigrationPlanOperation,\n TFamilyId extends string = string,\n TTargetId extends string = string,\n> implements MigrationPlan\n{\n abstract readonly targetId: string;\n\n /**\n * Assembled `ControlStack` injected by the orchestrator (`runMigration`).\n *\n * Subclasses (e.g. `PostgresMigration`) read the stack to materialize their\n * adapter once per instance. Optional at the abstract level so unit tests can\n * construct `Migration` instances purely for `operations` / `describe`\n * assertions without needing a real stack; concrete subclasses that need the\n * stack at runtime should narrow the parameter to required.\n */\n protected readonly stack: ControlStack<TFamilyId, TTargetId> | undefined;\n\n constructor(stack?: ControlStack<TFamilyId, TTargetId>) {\n this.stack = stack;\n }\n\n /**\n * Ordered list of operations this migration performs.\n *\n * Implemented as a getter so that subclasses can either precompute the list\n * in their constructor or build it lazily per access.\n */\n abstract get operations(): readonly TOperation[];\n\n /**\n * Metadata inputs used to build `migration.json` and to derive the plan's\n * origin/destination identities. Every migration must provide this —\n * omitting it would produce an invalid on-disk migration package.\n */\n abstract describe(): MigrationMeta;\n\n get origin(): { readonly storageHash: string } | null {\n const from = this.describe().from;\n return from === null ? null : { storageHash: from };\n }\n\n get destination(): { readonly storageHash: string } {\n return { storageHash: this.describe().to };\n }\n}\n\n/**\n * Returns true when `import.meta.url` resolves to the same file that was\n * invoked as the node entrypoint (`process.argv[1]`). Used by\n * `MigrationCLI.run` (in `@prisma-next/cli/migration-cli`) to no-op when\n * the migration module is being imported (e.g. by another script) rather\n * than executed directly.\n */\nexport function isDirectEntrypoint(importMetaUrl: string): boolean {\n const metaFilename = fileURLToPath(importMetaUrl);\n const argv1 = process.argv[1];\n if (!argv1) return false;\n try {\n return realpathSync(metaFilename) === realpathSync(argv1);\n } catch {\n return false;\n }\n}\n\n/**\n * In-memory artifacts produced from a `Migration` instance: the\n * serialized `ops.json` body, the `migration.json` metadata object, and\n * its serialized form. Returned by `buildMigrationArtifacts` so callers\n * (today: `MigrationCLI.run` in `@prisma-next/cli/migration-cli`) can\n * decide how to persist them — write to disk, print in dry-run, ship\n * over the wire — without coupling artifact construction to file I/O.\n *\n * `metadataJson` is `JSON.stringify(metadata, null, 2)` — the canonical\n * on-disk shape that the arktype loader-schema in `./io` validates.\n */\nexport interface MigrationArtifacts {\n readonly opsJson: string;\n readonly metadata: MigrationMetadata;\n readonly metadataJson: string;\n}\n\n/**\n * Build the attested metadata from `describe()`-derived metadata, the\n * operations list, and the previously-scaffolded metadata (if any).\n *\n * When a `migration.json` already exists for this package (the common\n * case: it was scaffolded by `migration plan`), preserve the contract\n * bookends, hints, labels, and `createdAt` set there — those fields are\n * owned by the CLI scaffolder, not the authored class. Only the\n * `describe()`-derived fields (`from`, `to`) and the operations\n * change as the author iterates. When no metadata exists yet (a bare\n * `migration.ts` run from scratch), synthesize a minimal but\n * schema-conformant record so the resulting package can still be read,\n * verified, and applied.\n *\n * The `migrationHash` is recomputed against the current metadata + ops so\n * the on-disk artifacts are always fully attested.\n */\nfunction buildAttestedMetadata(\n meta: MigrationMeta,\n ops: MigrationOps,\n existing: Partial<MigrationMetadata> | null,\n): MigrationMetadata {\n const baseMetadata: Omit<MigrationMetadata, 'migrationHash'> = {\n from: meta.from,\n to: meta.to,\n labels: meta.labels ?? existing?.labels ?? [],\n providedInvariants: deriveProvidedInvariants(ops),\n createdAt: existing?.createdAt ?? new Date().toISOString(),\n hints: normalizeHints(existing?.hints),\n };\n\n const migrationHash = computeMigrationHash(baseMetadata, ops);\n return { ...baseMetadata, migrationHash };\n}\n\n/**\n * Project `existing.hints` down to the known `MigrationHints` shape, dropping\n * any legacy keys that may linger in metadata scaffolded by older CLI\n * versions (e.g. `planningStrategy`). Picking fields explicitly instead of\n * spreading keeps refreshed `migration.json` files schema-clean regardless\n * of what was on disk before.\n */\nfunction normalizeHints(existing: MigrationHints | undefined): MigrationHints {\n return {\n used: existing?.used ?? [],\n applied: existing?.applied ?? [],\n plannerVersion: existing?.plannerVersion ?? '2.0.0',\n };\n}\n\n/**\n * Pure conversion from a `Migration` instance (plus the previously\n * scaffolded metadata, when one exists on disk) to the in-memory\n * artifacts that downstream tooling persists. Owns metadata validation,\n * metadata synthesis/preservation, hint normalization, and the\n * content-addressed `migrationHash` computation, but performs no file I/O\n * — callers handle reads (to source `existing`) and writes (to persist\n * `opsJson` / `metadataJson`).\n */\nexport function buildMigrationArtifacts(\n instance: Migration,\n existing: Partial<MigrationMetadata> | null,\n): MigrationArtifacts {\n const ops = instance.operations;\n if (!Array.isArray(ops)) {\n throw new Error('operations must be an array');\n }\n\n for (let index = 0; index < ops.length; index++) {\n const result = MigrationOpSchema(ops[index]);\n if (result instanceof type.errors) {\n throw errorInvalidOperationEntry(index, result.summary);\n }\n }\n\n const rawMeta: unknown = instance.describe();\n const parsed = MigrationMetaSchema(rawMeta);\n if (parsed instanceof type.errors) {\n throw new Error(`describe() returned invalid metadata: ${parsed.summary}`);\n }\n\n const metadata = buildAttestedMetadata(parsed, ops, existing);\n\n return {\n opsJson: JSON.stringify(ops, null, 2),\n metadata,\n metadataJson: JSON.stringify(metadata, null, 2),\n };\n}\n"],"mappings":";;;;;;;;AA0BA,MAAM,sBAAsB,KAAK;CAC/B,MAAM;CACN,IAAI;CACJ,WAAW,KAAK,QAAQ,EAAE,MAAM;AAClC,CAAC;;;;;;;;;;AAWD,IAAsB,YAAtB,MAKA;;;;;;;;;;CAYE;CAEA,YAAY,OAA4C;EACtD,KAAK,QAAQ;CACf;CAiBA,IAAI,SAAkD;EACpD,MAAM,OAAO,KAAK,SAAS,EAAE;EAC7B,OAAO,SAAS,OAAO,OAAO,EAAE,aAAa,KAAK;CACpD;CAEA,IAAI,cAAgD;EAClD,OAAO,EAAE,aAAa,KAAK,SAAS,EAAE,GAAG;CAC3C;AACF;;;;;;;;AASA,SAAgB,mBAAmB,eAAgC;CACjE,MAAM,eAAe,cAAc,aAAa;CAChD,MAAM,QAAQ,QAAQ,KAAK;CAC3B,IAAI,CAAC,OAAO,OAAO;CACnB,IAAI;EACF,OAAO,aAAa,YAAY,MAAM,aAAa,KAAK;CAC1D,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;;;;;;;;;;;;AAoCA,SAAS,sBACP,MACA,KACA,UACmB;CACnB,MAAM,eAAyD;EAC7D,MAAM,KAAK;EACX,IAAI,KAAK;EACT,QAAQ,KAAK,UAAU,UAAU,UAAU,CAAC;EAC5C,oBAAoB,yBAAyB,GAAG;EAChD,WAAW,UAAU,8BAAa,IAAI,KAAK,GAAE,YAAY;EACzD,OAAO,eAAe,UAAU,KAAK;CACvC;CAEA,MAAM,gBAAgB,qBAAqB,cAAc,GAAG;CAC5D,OAAO;EAAE,GAAG;EAAc;CAAc;AAC1C;;;;;;;;AASA,SAAS,eAAe,UAAsD;CAC5E,OAAO;EACL,MAAM,UAAU,QAAQ,CAAC;EACzB,SAAS,UAAU,WAAW,CAAC;EAC/B,gBAAgB,UAAU,kBAAkB;CAC9C;AACF;;;;;;;;;;AAWA,SAAgB,wBACd,UACA,UACoB;CACpB,MAAM,MAAM,SAAS;CACrB,IAAI,CAAC,MAAM,QAAQ,GAAG,GACpB,MAAM,IAAI,MAAM,6BAA6B;CAG/C,KAAK,IAAI,QAAQ,GAAG,QAAQ,IAAI,QAAQ,SAAS;EAC/C,MAAM,SAAS,kBAAkB,IAAI,MAAM;EAC3C,IAAI,kBAAkB,KAAK,QACzB,MAAM,2BAA2B,OAAO,OAAO,OAAO;CAE1D;CAGA,MAAM,SAAS,oBADU,SAAS,SACO,CAAC;CAC1C,IAAI,kBAAkB,KAAK,QACzB,MAAM,IAAI,MAAM,yCAAyC,OAAO,SAAS;CAG3E,MAAM,WAAW,sBAAsB,QAAQ,KAAK,QAAQ;CAE5D,OAAO;EACL,SAAS,KAAK,UAAU,KAAK,MAAM,CAAC;EACpC;EACA,cAAc,KAAK,UAAU,UAAU,MAAM,CAAC;CAChD;AACF"}
@@ -1,3 +1,3 @@
1
- import { n as OnDiskMigrationPackage, t as MigrationOps } from "../package-DZj8YvD0.mjs";
1
+ import { n as OnDiskMigrationPackage, t as MigrationOps } from "../package-DIttKL7X.mjs";
2
2
  import { MigrationPackage } from "@prisma-next/framework-components/control";
3
3
  export { type MigrationOps, type MigrationPackage, type OnDiskMigrationPackage };
@@ -1,5 +1,5 @@
1
- import { n as MigrationGraph, t as MigrationEdge } from "../graph-BrLXqoUc.mjs";
2
- import { n as Refs } from "../refs-CDaNerhT.mjs";
1
+ import { n as MigrationGraph, t as MigrationEdge } from "../graph-C7AJPGV5.mjs";
2
+ import { n as Refs } from "../refs-BaygQaFD.mjs";
3
3
  import { Result } from "@prisma-next/utils/result";
4
4
 
5
5
  //#region src/refs/types.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"ref-resolution.d.mts","names":[],"sources":["../../src/refs/types.ts","../../src/refs/contract-ref.ts","../../src/refs/migration-ref.ts"],"mappings":";;;;;;UAIiB,oBAAA;EAAA,SACN,KAAA,EAAO,cAAA;EAAA,SACP,IAAA,EAAM,IAAA;AAAA;AAAA,KAGL,qBAAA;EAAA,SACG,IAAA;EAAA,SAAuB,KAAA;AAAA;EAAA,SACvB,IAAA;EAAA,SAAsB,OAAA;AAAA;EAAA,SACtB,IAAA;EAAA,SAA+B,OAAA;AAAA;EAAA,SAC/B,IAAA;EAAA,SAAiC,OAAA;AAAA;;UAG/B,WAAA;EAAA,SACN,IAAA;EAAA,SACA,UAAA,EAAY,qBAAA;AAAA;AAAA,KAGX,sBAAA;EAAA,SACG,IAAA;EAAA,SAA2B,OAAA;AAAA;EAAA,SAC3B,IAAA;EAAA,SAAuB,KAAA;AAAA;;UAGrB,YAAA;EAAA,SACN,OAAA;EAAA,SACA,aAAA;EAAA,SACA,IAAA;EAAA,SACA,EAAA;EAAA,SACA,UAAA,EAAY,sBAAA;AAAA;AAAA,UAGN,qBAAA;EAAA,SACN,IAAA;EAAA,SACA,KAAA;EAAA,SACA,OAAA;AAAA;AAAA,UAGM,sBAAA;EAAA,SACN,IAAA;EAAA,SACA,KAAA;EAAA,SACA,UAAA;EAAA,SACA,OAAA;AAAA;AAAA,UAGM,yBAAA;EAAA,SACN,IAAA;EAAA,SACA,KAAA;EAAA,SACA,eAAA;EAAA,SACA,OAAA;EAAA,SACA,GAAA;AAAA;AAAA,UAGM,0BAAA;EAAA,SACN,IAAA;EAAA,SACA,KAAA;EAAA,SACA,MAAA;AAAA;AAAA,KAGC,kBAAA,GACR,qBAAA,GACA,sBAAA,GACA,yBAAA,GACA,0BAAA;AAAA,iBAiBY,iBAAA,CACd,KAAA,EAAO,cAAA,EACP,OAAA,WACC,aAAA;;;;;;AAjFH;;;;;;;;iBCkBgB,gBAAA,CACd,KAAA,UACA,GAAA,EAAK,oBAAA,GACJ,MAAA,CAAO,WAAA,EAAa,kBAAA;;;;;;ADrBvB;;;;;;;;;iBEcgB,iBAAA,CACd,KAAA,UACA,GAAA,EAAK,oBAAA,GACJ,MAAA,CAAO,YAAA,EAAc,kBAAA"}
1
+ {"version":3,"file":"ref-resolution.d.mts","names":[],"sources":["../../src/refs/types.ts","../../src/refs/contract-ref.ts","../../src/refs/migration-ref.ts"],"mappings":";;;;;;UAIiB,oBAAA;EAAA,SACN,KAAA,EAAO,cAAA;EAAA,SACP,IAAA,EAAM,IAAI;AAAA;AAAA,KAGT,qBAAA;EAAA,SACG,IAAA;EAAA,SAAuB,KAAA;AAAA;EAAA,SACvB,IAAA;EAAA,SAAsB,OAAA;AAAA;EAAA,SACtB,IAAA;EAAA,SAA+B,OAAA;AAAA;EAAA,SAC/B,IAAA;EAAA,SAAiC,OAAA;AAAA;;UAG/B,WAAA;EAAA,SACN,IAAA;EAAA,SACA,UAAA,EAAY,qBAAqB;AAAA;AAAA,KAGhC,sBAAA;EAAA,SACG,IAAA;EAAA,SAA2B,OAAA;AAAA;EAAA,SAC3B,IAAA;EAAA,SAAuB,KAAA;AAAA;;UAGrB,YAAA;EAAA,SACN,OAAA;EAAA,SACA,aAAA;EAAA,SACA,IAAA;EAAA,SACA,EAAA;EAAA,SACA,UAAA,EAAY,sBAAsB;AAAA;AAAA,UAG5B,qBAAA;EAAA,SACN,IAAA;EAAA,SACA,KAAA;EAAA,SACA,OAAA;AAAA;AAAA,UAGM,sBAAA;EAAA,SACN,IAAA;EAAA,SACA,KAAA;EAAA,SACA,UAAA;EAAA,SACA,OAAA;AAAA;AAAA,UAGM,yBAAA;EAAA,SACN,IAAA;EAAA,SACA,KAAA;EAAA,SACA,eAAA;EAAA,SACA,OAAA;EAAA,SACA,GAAA;AAAA;AAAA,UAGM,0BAAA;EAAA,SACN,IAAA;EAAA,SACA,KAAA;EAAA,SACA,MAAA;AAAA;AAAA,KAGC,kBAAA,GACR,qBAAA,GACA,sBAAA,GACA,yBAAA,GACA,0BAAA;AAAA,iBAiBY,iBAAA,CACd,KAAA,EAAO,cAAA,EACP,OAAA,WACC,aAAa;;;;;;AAjFhB;;;;;;;;iBCkBgB,gBAAA,CACd,KAAA,UACA,GAAA,EAAK,oBAAA,GACJ,MAAA,CAAO,WAAA,EAAa,kBAAA;;;;;;ADrBvB;;;;;;;;;iBEcgB,iBAAA,CACd,KAAA,UACA,GAAA,EAAK,oBAAA,GACJ,MAAA,CAAO,YAAA,EAAc,kBAAA"}
@@ -1,4 +1,4 @@
1
- import { a as validateRefName } from "../refs-BDHo5l_g.mjs";
1
+ import { a as validateRefName } from "../refs-HhOkD8BT.mjs";
2
2
  import { notOk, ok } from "@prisma-next/utils/result";
3
3
  //#region src/refs/types.ts
4
4
  const FULL_HASH_PATTERN = /^sha256:([0-9a-f]{64}|empty)$/;
@@ -1 +1 @@
1
- {"version":3,"file":"ref-resolution.mjs","names":[],"sources":["../../src/refs/types.ts","../../src/refs/contract-ref.ts","../../src/refs/migration-ref.ts"],"sourcesContent":["import type { MigrationEdge, MigrationGraph } from '../graph';\nimport type { Refs } from '../refs';\n\n/** Context required to resolve a contract or migration reference. */\nexport interface RefResolutionContext {\n readonly graph: MigrationGraph;\n readonly refs: Refs;\n}\n\nexport type ContractRefProvenance =\n | { readonly kind: 'hash'; readonly input: string }\n | { readonly kind: 'ref'; readonly refName: string }\n | { readonly kind: 'migration-to'; readonly dirName: string }\n | { readonly kind: 'migration-from'; readonly dirName: string };\n\n/** A resolved contract reference: the target hash and how it was derived. */\nexport interface ContractRef {\n readonly hash: string;\n readonly provenance: ContractRefProvenance;\n}\n\nexport type MigrationRefProvenance =\n | { readonly kind: 'dir-name'; readonly dirName: string }\n | { readonly kind: 'hash'; readonly input: string };\n\n/** A resolved migration reference. */\nexport interface MigrationRef {\n readonly dirName: string;\n readonly migrationHash: string;\n readonly from: string;\n readonly to: string;\n readonly provenance: MigrationRefProvenance;\n}\n\nexport interface RefResolutionNotFound {\n readonly kind: 'not-found';\n readonly input: string;\n readonly grammar: 'contract' | 'migration';\n}\n\nexport interface RefResolutionAmbiguous {\n readonly kind: 'ambiguous';\n readonly input: string;\n readonly candidates: readonly string[];\n readonly grammar: 'contract' | 'migration';\n}\n\nexport interface RefResolutionWrongGrammar {\n readonly kind: 'wrong-grammar';\n readonly input: string;\n readonly expectedGrammar: 'contract' | 'migration';\n readonly message: string;\n readonly fix: string;\n}\n\nexport interface RefResolutionInvalidFormat {\n readonly kind: 'invalid-format';\n readonly input: string;\n readonly reason: string;\n}\n\nexport type RefResolutionError =\n | RefResolutionNotFound\n | RefResolutionAmbiguous\n | RefResolutionWrongGrammar\n | RefResolutionInvalidFormat;\n\nconst FULL_HASH_PATTERN = /^sha256:([0-9a-f]{64}|empty)$/;\nconst HEX_PREFIX_PATTERN = /^(sha256:)?[0-9a-f]{6,}$/;\n\nexport function isFullHash(input: string): boolean {\n return FULL_HASH_PATTERN.test(input);\n}\n\nexport function isHexPrefix(input: string): boolean {\n return HEX_PREFIX_PATTERN.test(input);\n}\n\nexport function normalizeHashPrefix(input: string): string {\n return input.startsWith('sha256:') ? input : `sha256:${input}`;\n}\n\nexport function findEdgeByDirName(\n graph: MigrationGraph,\n dirName: string,\n): MigrationEdge | undefined {\n for (const edges of graph.forwardChain.values()) {\n for (const edge of edges) {\n if (edge.dirName === dirName) return edge;\n }\n }\n return undefined;\n}\n","import type { Result } from '@prisma-next/utils/result';\nimport { notOk, ok } from '@prisma-next/utils/result';\nimport { validateRefName } from '../refs';\nimport type {\n ContractRef,\n ContractRefProvenance,\n RefResolutionContext,\n RefResolutionError,\n} from './types';\nimport { findEdgeByDirName, isFullHash, isHexPrefix, normalizeHashPrefix } from './types';\n\n/**\n * Resolve a user-supplied string to a contract hash using the unified\n * contract-reference grammar.\n *\n * Accepted forms:\n * - Full storage hash (`sha256:<64 hex>` or `sha256:empty`)\n * - Hex prefix (6+ hex chars, must uniquely identify one contract)\n * - Ref name (looked up in the refs index)\n * - Migration directory name (resolves to the migration's `to`-contract)\n * - `<dir>^` (resolves to the migration's `from`-contract)\n */\nexport function parseContractRef(\n input: string,\n ctx: RefResolutionContext,\n): Result<ContractRef, RefResolutionError> {\n if (!input) {\n return notOk({ kind: 'invalid-format', input, reason: 'Reference cannot be empty' });\n }\n\n if (isFullHash(input)) {\n if (ctx.graph.nodes.has(input)) {\n return ok({ hash: input, provenance: { kind: 'hash', input } });\n }\n return notOk({ kind: 'not-found', input, grammar: 'contract' });\n }\n\n if (input.endsWith('^')) {\n const dirName = input.slice(0, -1);\n if (!dirName) {\n return notOk({ kind: 'invalid-format', input, reason: 'Missing directory name before ^' });\n }\n const edge = findEdgeByDirName(ctx.graph, dirName);\n if (edge) {\n return ok({ hash: edge.from, provenance: { kind: 'migration-from', dirName } });\n }\n return notOk({ kind: 'not-found', input, grammar: 'contract' });\n }\n\n type Candidate = { hash: string; provenance: ContractRefProvenance; label: string };\n const candidates: Candidate[] = [];\n\n if (validateRefName(input) && Object.hasOwn(ctx.refs, input)) {\n const ref = ctx.refs[input];\n if (ref) {\n candidates.push({\n hash: ref.hash,\n provenance: { kind: 'ref', refName: input },\n label: `ref \"${input}\"`,\n });\n }\n }\n\n const edge = findEdgeByDirName(ctx.graph, input);\n if (edge) {\n candidates.push({\n hash: edge.to,\n provenance: { kind: 'migration-to', dirName: input },\n label: `migration directory \"${input}\"`,\n });\n }\n\n if (isHexPrefix(input)) {\n const prefix = normalizeHashPrefix(input);\n const matches = [...ctx.graph.nodes].filter((n) => n.startsWith(prefix));\n const [firstMatch] = matches;\n if (matches.length === 1 && firstMatch !== undefined) {\n candidates.push({\n hash: firstMatch,\n provenance: { kind: 'hash', input },\n label: `hash prefix \"${input}\"`,\n });\n } else if (matches.length > 1) {\n return notOk({ kind: 'ambiguous', input, candidates: matches, grammar: 'contract' });\n }\n }\n\n const [firstCandidate] = candidates;\n if (candidates.length === 1 && firstCandidate !== undefined) {\n return ok({ hash: firstCandidate.hash, provenance: firstCandidate.provenance });\n }\n\n if (candidates.length > 1) {\n return notOk({\n kind: 'ambiguous',\n input,\n candidates: candidates.map((c) => c.label),\n grammar: 'contract',\n });\n }\n\n return notOk({ kind: 'not-found', input, grammar: 'contract' });\n}\n","import type { Result } from '@prisma-next/utils/result';\nimport { notOk, ok } from '@prisma-next/utils/result';\nimport { validateRefName } from '../refs';\nimport type { MigrationRef, RefResolutionContext, RefResolutionError } from './types';\nimport { findEdgeByDirName, isFullHash, isHexPrefix, normalizeHashPrefix } from './types';\n\n/**\n * Resolve a user-supplied string to a migration using the migration-reference\n * grammar.\n *\n * Accepted forms:\n * - Migration directory name (e.g. `20260101-add-users`)\n * - Migration hash (full or 6+ hex prefix)\n *\n * Wrong-grammar diagnostics are produced when the input matches a\n * contract-grammar form (ref name, `<dir>^`, contract-only hash) so the\n * user gets a targeted hint rather than a generic \"not found\".\n */\nexport function parseMigrationRef(\n input: string,\n ctx: RefResolutionContext,\n): Result<MigrationRef, RefResolutionError> {\n if (!input) {\n return notOk({ kind: 'invalid-format', input, reason: 'Reference cannot be empty' });\n }\n\n if (input.endsWith('^')) {\n return notOk({\n kind: 'wrong-grammar',\n input,\n expectedGrammar: 'migration',\n message: '`^` syntax addresses contracts, not migrations',\n fix: 'Pass the migration directory name without `^`, or use a contract-accepting flag like `--to` or `--from`.',\n });\n }\n\n if (validateRefName(input) && Object.hasOwn(ctx.refs, input)) {\n return notOk({\n kind: 'wrong-grammar',\n input,\n expectedGrammar: 'migration',\n message: `\"${input}\" is a ref name, not a migration`,\n fix: 'Refs point at contracts, not migrations. Use a migration directory name or migration hash.',\n });\n }\n\n const edge = findEdgeByDirName(ctx.graph, input);\n if (edge) {\n return ok({\n dirName: edge.dirName,\n migrationHash: edge.migrationHash,\n from: edge.from,\n to: edge.to,\n provenance: { kind: 'dir-name', dirName: input },\n });\n }\n\n if (isFullHash(input)) {\n const migEdge = ctx.graph.migrationByHash.get(input);\n if (migEdge) {\n return ok({\n dirName: migEdge.dirName,\n migrationHash: migEdge.migrationHash,\n from: migEdge.from,\n to: migEdge.to,\n provenance: { kind: 'hash', input },\n });\n }\n if (ctx.graph.nodes.has(input)) {\n return notOk({\n kind: 'wrong-grammar',\n input,\n expectedGrammar: 'migration',\n message: 'Hash matched a contract but not a migration',\n fix: 'Use a contract-accepting flag like `--to` or `--from` to reference contracts by hash. Pass `migration show <dir>` for a specific migration.',\n });\n }\n return notOk({ kind: 'not-found', input, grammar: 'migration' });\n }\n\n if (isHexPrefix(input)) {\n const prefix = normalizeHashPrefix(input);\n const migMatches = [...ctx.graph.migrationByHash.entries()].filter(([hash]) =>\n hash.startsWith(prefix),\n );\n\n const [firstMigMatch] = migMatches;\n if (migMatches.length === 1 && firstMigMatch !== undefined) {\n const [, matchedEdge] = firstMigMatch;\n return ok({\n dirName: matchedEdge.dirName,\n migrationHash: matchedEdge.migrationHash,\n from: matchedEdge.from,\n to: matchedEdge.to,\n provenance: { kind: 'hash', input },\n });\n }\n\n if (migMatches.length > 1) {\n return notOk({\n kind: 'ambiguous',\n input,\n candidates: migMatches.map(([hash]) => hash),\n grammar: 'migration',\n });\n }\n\n const contractMatches = [...ctx.graph.nodes].filter((n) => n.startsWith(prefix));\n if (contractMatches.length > 0) {\n return notOk({\n kind: 'wrong-grammar',\n input,\n expectedGrammar: 'migration',\n message: 'Hash matched a contract but not a migration',\n fix: 'Use a contract-accepting flag like `--to` or `--from` to reference contracts by hash. Pass `migration show <dir>` for a specific migration.',\n });\n }\n }\n\n return notOk({ kind: 'not-found', input, grammar: 'migration' });\n}\n"],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AQ;KAAO;IACpC,CAAC;;EAGJ,IAAI,WAAW,SAAS,GACtB,OAAO,MAAM;GACX,MAAM;GACN;GACA,YAAY,WAAW,KAAK,CAAC,UAAU,KAAK;GAC5C,SAAS;GACV,CAAC;EAIJ,IADwB,CAAC,GAAG,IAAI,MAAM,MAAM,CAAC,QAAQ,MAAM,EAAE,WAAW,OAAO,CAC5D,CAAC,SAAS,GAC3B,OAAO,MAAM;GACX,MAAM;GACN;GACA,iBAAiB;GACjB,SAAS;GACT,KAAK;GACN,CAAC;;CAIN,OAAO,MAAM;EAAE,MAAM;EAAa;EAAO,SAAS;EAAa,CAAC"}
1
+ {"version":3,"file":"ref-resolution.mjs","names":[],"sources":["../../src/refs/types.ts","../../src/refs/contract-ref.ts","../../src/refs/migration-ref.ts"],"sourcesContent":["import type { MigrationEdge, MigrationGraph } from '../graph';\nimport type { Refs } from '../refs';\n\n/** Context required to resolve a contract or migration reference. */\nexport interface RefResolutionContext {\n readonly graph: MigrationGraph;\n readonly refs: Refs;\n}\n\nexport type ContractRefProvenance =\n | { readonly kind: 'hash'; readonly input: string }\n | { readonly kind: 'ref'; readonly refName: string }\n | { readonly kind: 'migration-to'; readonly dirName: string }\n | { readonly kind: 'migration-from'; readonly dirName: string };\n\n/** A resolved contract reference: the target hash and how it was derived. */\nexport interface ContractRef {\n readonly hash: string;\n readonly provenance: ContractRefProvenance;\n}\n\nexport type MigrationRefProvenance =\n | { readonly kind: 'dir-name'; readonly dirName: string }\n | { readonly kind: 'hash'; readonly input: string };\n\n/** A resolved migration reference. */\nexport interface MigrationRef {\n readonly dirName: string;\n readonly migrationHash: string;\n readonly from: string;\n readonly to: string;\n readonly provenance: MigrationRefProvenance;\n}\n\nexport interface RefResolutionNotFound {\n readonly kind: 'not-found';\n readonly input: string;\n readonly grammar: 'contract' | 'migration';\n}\n\nexport interface RefResolutionAmbiguous {\n readonly kind: 'ambiguous';\n readonly input: string;\n readonly candidates: readonly string[];\n readonly grammar: 'contract' | 'migration';\n}\n\nexport interface RefResolutionWrongGrammar {\n readonly kind: 'wrong-grammar';\n readonly input: string;\n readonly expectedGrammar: 'contract' | 'migration';\n readonly message: string;\n readonly fix: string;\n}\n\nexport interface RefResolutionInvalidFormat {\n readonly kind: 'invalid-format';\n readonly input: string;\n readonly reason: string;\n}\n\nexport type RefResolutionError =\n | RefResolutionNotFound\n | RefResolutionAmbiguous\n | RefResolutionWrongGrammar\n | RefResolutionInvalidFormat;\n\nconst FULL_HASH_PATTERN = /^sha256:([0-9a-f]{64}|empty)$/;\nconst HEX_PREFIX_PATTERN = /^(sha256:)?[0-9a-f]{6,}$/;\n\nexport function isFullHash(input: string): boolean {\n return FULL_HASH_PATTERN.test(input);\n}\n\nexport function isHexPrefix(input: string): boolean {\n return HEX_PREFIX_PATTERN.test(input);\n}\n\nexport function normalizeHashPrefix(input: string): string {\n return input.startsWith('sha256:') ? input : `sha256:${input}`;\n}\n\nexport function findEdgeByDirName(\n graph: MigrationGraph,\n dirName: string,\n): MigrationEdge | undefined {\n for (const edges of graph.forwardChain.values()) {\n for (const edge of edges) {\n if (edge.dirName === dirName) return edge;\n }\n }\n return undefined;\n}\n","import type { Result } from '@prisma-next/utils/result';\nimport { notOk, ok } from '@prisma-next/utils/result';\nimport { validateRefName } from '../refs';\nimport type {\n ContractRef,\n ContractRefProvenance,\n RefResolutionContext,\n RefResolutionError,\n} from './types';\nimport { findEdgeByDirName, isFullHash, isHexPrefix, normalizeHashPrefix } from './types';\n\n/**\n * Resolve a user-supplied string to a contract hash using the unified\n * contract-reference grammar.\n *\n * Accepted forms:\n * - Full storage hash (`sha256:<64 hex>` or `sha256:empty`)\n * - Hex prefix (6+ hex chars, must uniquely identify one contract)\n * - Ref name (looked up in the refs index)\n * - Migration directory name (resolves to the migration's `to`-contract)\n * - `<dir>^` (resolves to the migration's `from`-contract)\n */\nexport function parseContractRef(\n input: string,\n ctx: RefResolutionContext,\n): Result<ContractRef, RefResolutionError> {\n if (!input) {\n return notOk({ kind: 'invalid-format', input, reason: 'Reference cannot be empty' });\n }\n\n if (isFullHash(input)) {\n if (ctx.graph.nodes.has(input)) {\n return ok({ hash: input, provenance: { kind: 'hash', input } });\n }\n return notOk({ kind: 'not-found', input, grammar: 'contract' });\n }\n\n if (input.endsWith('^')) {\n const dirName = input.slice(0, -1);\n if (!dirName) {\n return notOk({ kind: 'invalid-format', input, reason: 'Missing directory name before ^' });\n }\n const edge = findEdgeByDirName(ctx.graph, dirName);\n if (edge) {\n return ok({ hash: edge.from, provenance: { kind: 'migration-from', dirName } });\n }\n return notOk({ kind: 'not-found', input, grammar: 'contract' });\n }\n\n type Candidate = { hash: string; provenance: ContractRefProvenance; label: string };\n const candidates: Candidate[] = [];\n\n if (validateRefName(input) && Object.hasOwn(ctx.refs, input)) {\n const ref = ctx.refs[input];\n if (ref) {\n candidates.push({\n hash: ref.hash,\n provenance: { kind: 'ref', refName: input },\n label: `ref \"${input}\"`,\n });\n }\n }\n\n const edge = findEdgeByDirName(ctx.graph, input);\n if (edge) {\n candidates.push({\n hash: edge.to,\n provenance: { kind: 'migration-to', dirName: input },\n label: `migration directory \"${input}\"`,\n });\n }\n\n if (isHexPrefix(input)) {\n const prefix = normalizeHashPrefix(input);\n const matches = [...ctx.graph.nodes].filter((n) => n.startsWith(prefix));\n const [firstMatch] = matches;\n if (matches.length === 1 && firstMatch !== undefined) {\n candidates.push({\n hash: firstMatch,\n provenance: { kind: 'hash', input },\n label: `hash prefix \"${input}\"`,\n });\n } else if (matches.length > 1) {\n return notOk({ kind: 'ambiguous', input, candidates: matches, grammar: 'contract' });\n }\n }\n\n const [firstCandidate] = candidates;\n if (candidates.length === 1 && firstCandidate !== undefined) {\n return ok({ hash: firstCandidate.hash, provenance: firstCandidate.provenance });\n }\n\n if (candidates.length > 1) {\n return notOk({\n kind: 'ambiguous',\n input,\n candidates: candidates.map((c) => c.label),\n grammar: 'contract',\n });\n }\n\n return notOk({ kind: 'not-found', input, grammar: 'contract' });\n}\n","import type { Result } from '@prisma-next/utils/result';\nimport { notOk, ok } from '@prisma-next/utils/result';\nimport { validateRefName } from '../refs';\nimport type { MigrationRef, RefResolutionContext, RefResolutionError } from './types';\nimport { findEdgeByDirName, isFullHash, isHexPrefix, normalizeHashPrefix } from './types';\n\n/**\n * Resolve a user-supplied string to a migration using the migration-reference\n * grammar.\n *\n * Accepted forms:\n * - Migration directory name (e.g. `20260101-add-users`)\n * - Migration hash (full or 6+ hex prefix)\n *\n * Wrong-grammar diagnostics are produced when the input matches a\n * contract-grammar form (ref name, `<dir>^`, contract-only hash) so the\n * user gets a targeted hint rather than a generic \"not found\".\n */\nexport function parseMigrationRef(\n input: string,\n ctx: RefResolutionContext,\n): Result<MigrationRef, RefResolutionError> {\n if (!input) {\n return notOk({ kind: 'invalid-format', input, reason: 'Reference cannot be empty' });\n }\n\n if (input.endsWith('^')) {\n return notOk({\n kind: 'wrong-grammar',\n input,\n expectedGrammar: 'migration',\n message: '`^` syntax addresses contracts, not migrations',\n fix: 'Pass the migration directory name without `^`, or use a contract-accepting flag like `--to` or `--from`.',\n });\n }\n\n if (validateRefName(input) && Object.hasOwn(ctx.refs, input)) {\n return notOk({\n kind: 'wrong-grammar',\n input,\n expectedGrammar: 'migration',\n message: `\"${input}\" is a ref name, not a migration`,\n fix: 'Refs point at contracts, not migrations. Use a migration directory name or migration hash.',\n });\n }\n\n const edge = findEdgeByDirName(ctx.graph, input);\n if (edge) {\n return ok({\n dirName: edge.dirName,\n migrationHash: edge.migrationHash,\n from: edge.from,\n to: edge.to,\n provenance: { kind: 'dir-name', dirName: input },\n });\n }\n\n if (isFullHash(input)) {\n const migEdge = ctx.graph.migrationByHash.get(input);\n if (migEdge) {\n return ok({\n dirName: migEdge.dirName,\n migrationHash: migEdge.migrationHash,\n from: migEdge.from,\n to: migEdge.to,\n provenance: { kind: 'hash', input },\n });\n }\n if (ctx.graph.nodes.has(input)) {\n return notOk({\n kind: 'wrong-grammar',\n input,\n expectedGrammar: 'migration',\n message: 'Hash matched a contract but not a migration',\n fix: 'Use a contract-accepting flag like `--to` or `--from` to reference contracts by hash. Pass `migration show <dir>` for a specific migration.',\n });\n }\n return notOk({ kind: 'not-found', input, grammar: 'migration' });\n }\n\n if (isHexPrefix(input)) {\n const prefix = normalizeHashPrefix(input);\n const migMatches = [...ctx.graph.migrationByHash.entries()].filter(([hash]) =>\n hash.startsWith(prefix),\n );\n\n const [firstMigMatch] = migMatches;\n if (migMatches.length === 1 && firstMigMatch !== undefined) {\n const [, matchedEdge] = firstMigMatch;\n return ok({\n dirName: matchedEdge.dirName,\n migrationHash: matchedEdge.migrationHash,\n from: matchedEdge.from,\n to: matchedEdge.to,\n provenance: { kind: 'hash', input },\n });\n }\n\n if (migMatches.length > 1) {\n return notOk({\n kind: 'ambiguous',\n input,\n candidates: migMatches.map(([hash]) => hash),\n grammar: 'migration',\n });\n }\n\n const contractMatches = [...ctx.graph.nodes].filter((n) => n.startsWith(prefix));\n if (contractMatches.length > 0) {\n return notOk({\n kind: 'wrong-grammar',\n input,\n expectedGrammar: 'migration',\n message: 'Hash matched a contract but not a migration',\n fix: 'Use a contract-accepting flag like `--to` or `--from` to reference contracts by hash. Pass `migration show <dir>` for a specific migration.',\n });\n }\n }\n\n return notOk({ kind: 'not-found', input, grammar: 'migration' });\n}\n"],"mappings":";;;AAmEA,MAAM,oBAAoB;AAC1B,MAAM,qBAAqB;AAE3B,SAAgB,WAAW,OAAwB;CACjD,OAAO,kBAAkB,KAAK,KAAK;AACrC;AAEA,SAAgB,YAAY,OAAwB;CAClD,OAAO,mBAAmB,KAAK,KAAK;AACtC;AAEA,SAAgB,oBAAoB,OAAuB;CACzD,OAAO,MAAM,WAAW,SAAS,IAAI,QAAQ,UAAU;AACzD;AAEA,SAAgB,kBACd,OACA,SAC2B;CAC3B,KAAK,MAAM,SAAS,MAAM,aAAa,OAAO,GAC5C,KAAK,MAAM,QAAQ,OACjB,IAAI,KAAK,YAAY,SAAS,OAAO;AAI3C;;;;;;;;;;;;;;ACtEA,SA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}
@@ -1,2 +1,15 @@
1
- import { a as readRefs, c as validateRefValue, i as readRef, l as writeRef, n as Refs, o as resolveRef, r as deleteRef, s as validateRefName, t as RefEntry } from "../refs-CDaNerhT.mjs";
2
- export { type RefEntry, type Refs, deleteRef, readRef, readRefs, resolveRef, validateRefName, validateRefValue, writeRef };
1
+ import { a as readRefs, c as validateRefValue, i as readRef, l as writeRef, n as Refs, o as resolveRef, r as deleteRef, s as validateRefName, t as RefEntry } from "../refs-BaygQaFD.mjs";
2
+
3
+ //#region src/refs/snapshot.d.ts
4
+ interface ContractIR {
5
+ readonly contract: unknown;
6
+ readonly contractDts: string;
7
+ }
8
+ declare function writeRefSnapshot(refsDir: string, name: string, snapshot: ContractIR): Promise<void>;
9
+ declare function readRefSnapshot(refsDir: string, name: string): Promise<ContractIR | null>;
10
+ declare function deleteRefSnapshot(refsDir: string, name: string): Promise<void>;
11
+ declare function writeRefPaired(refsDir: string, name: string, entry: RefEntry, snapshot: ContractIR): Promise<void>;
12
+ declare function deleteRefPaired(refsDir: string, name: string): Promise<void>;
13
+ //#endregion
14
+ export { type ContractIR, type RefEntry, type Refs, deleteRef, deleteRefPaired, deleteRefSnapshot, readRef, readRefSnapshot, readRefs, resolveRef, validateRefName, validateRefValue, writeRef, writeRefPaired, writeRefSnapshot };
15
+ //# sourceMappingURL=refs.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refs.d.mts","names":[],"sources":["../../src/refs/snapshot.ts"],"mappings":";;;UAQiB,UAAA;EAAA,SACN,QAAA;EAAA,SACA,WAAW;AAAA;AAAA,iBAgEA,gBAAA,CACpB,OAAA,UACA,IAAA,UACA,QAAA,EAAU,UAAA,GACT,OAAO;AAAA,iBA4BY,eAAA,CAAgB,OAAA,UAAiB,IAAA,WAAe,OAAO,CAAC,UAAA;AAAA,iBAiCxD,iBAAA,CAAkB,OAAA,UAAiB,IAAA,WAAe,OAAO;AAAA,iBASzD,cAAA,CACpB,OAAA,UACA,IAAA,UACA,KAAA,EAAO,QAAA,EACP,QAAA,EAAU,UAAA,GACT,OAAA;AAAA,iBA4BmB,eAAA,CAAgB,OAAA,UAAiB,IAAA,WAAe,OAAO"}
@@ -1,2 +1,137 @@
1
- import { a as validateRefName, i as resolveRef, n as readRef, o as validateRefValue, r as readRefs, s as writeRef, t as deleteRef } from "../refs-BDHo5l_g.mjs";
2
- export { deleteRef, readRef, readRefs, resolveRef, validateRefName, validateRefValue, writeRef };
1
+ import { h as errorInvalidRefName, m as errorInvalidRefFile, t as MigrationToolsError } from "../errors-CoEN114u.mjs";
2
+ import { a as validateRefName, i as resolveRef, n as readRef, o as validateRefValue, r as readRefs, s as writeRef, t as deleteRef } from "../refs-HhOkD8BT.mjs";
3
+ import { basename, dirname, join } from "pathe";
4
+ import { access, mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
5
+ import { type } from "arktype";
6
+ import { randomBytes } from "node:crypto";
7
+ import { canonicalizeJson } from "@prisma-next/framework-components/utils";
8
+ //#region src/refs/snapshot.ts
9
+ const ContractIrSchema = type({
10
+ targetFamily: "string",
11
+ target: "string",
12
+ profileHash: "string",
13
+ storage: type({ storageHash: "string" }),
14
+ models: "object"
15
+ });
16
+ function hasErrnoCode(error, code) {
17
+ return error instanceof Error && error.code === code;
18
+ }
19
+ function snapshotJsonPath(refsDir, name) {
20
+ return join(refsDir, `${name}.contract.json`);
21
+ }
22
+ function snapshotDtsPath(refsDir, name) {
23
+ return join(refsDir, `${name}.contract.d.ts`);
24
+ }
25
+ function tmpPathFor(finalPath) {
26
+ return join(dirname(finalPath), `.${basename(finalPath)}.${Date.now()}-${randomBytes(4).toString("hex")}.tmp`);
27
+ }
28
+ async function atomicWriteFile(finalPath, content) {
29
+ await mkdir(dirname(finalPath), { recursive: true });
30
+ const tmpPath = tmpPathFor(finalPath);
31
+ await writeFile(tmpPath, content);
32
+ await rename(tmpPath, finalPath);
33
+ }
34
+ async function unlinkIfExists(filePath) {
35
+ try {
36
+ await unlink(filePath);
37
+ } catch (error) {
38
+ if (hasErrnoCode(error, "ENOENT")) return;
39
+ throw error;
40
+ }
41
+ }
42
+ function parseContractSnapshotJson(filePath, raw) {
43
+ let parsed;
44
+ try {
45
+ parsed = JSON.parse(raw);
46
+ } catch {
47
+ throw errorInvalidRefFile(filePath, "Failed to parse as JSON");
48
+ }
49
+ const result = ContractIrSchema(parsed);
50
+ if (result instanceof type.errors) throw errorInvalidRefFile(filePath, result.summary);
51
+ return result;
52
+ }
53
+ async function writeRefSnapshot(refsDir, name, snapshot) {
54
+ if (!validateRefName(name)) throw errorInvalidRefName(name);
55
+ const jsonPath = snapshotJsonPath(refsDir, name);
56
+ const dtsPath = snapshotDtsPath(refsDir, name);
57
+ const jsonContent = `${canonicalizeJson(snapshot.contract)}\n`;
58
+ const dtsContent = snapshot.contractDts.endsWith("\n") ? snapshot.contractDts : `${snapshot.contractDts}\n`;
59
+ try {
60
+ await atomicWriteFile(jsonPath, jsonContent);
61
+ } catch (error) {
62
+ await unlinkIfExists(jsonPath);
63
+ throw error;
64
+ }
65
+ try {
66
+ await atomicWriteFile(dtsPath, dtsContent);
67
+ } catch (error) {
68
+ await unlinkIfExists(jsonPath);
69
+ await unlinkIfExists(dtsPath);
70
+ throw error;
71
+ }
72
+ }
73
+ async function readRefSnapshot(refsDir, name) {
74
+ if (!validateRefName(name)) throw errorInvalidRefName(name);
75
+ const jsonPath = snapshotJsonPath(refsDir, name);
76
+ const dtsPath = snapshotDtsPath(refsDir, name);
77
+ let raw;
78
+ try {
79
+ raw = await readFile(jsonPath, "utf-8");
80
+ } catch (error) {
81
+ if (hasErrnoCode(error, "ENOENT")) return null;
82
+ throw error;
83
+ }
84
+ const contract = parseContractSnapshotJson(jsonPath, raw);
85
+ let contractDts;
86
+ try {
87
+ contractDts = await readFile(dtsPath, "utf-8");
88
+ } catch (error) {
89
+ if (hasErrnoCode(error, "ENOENT")) throw errorInvalidRefFile(dtsPath, "Missing paired contract.d.ts snapshot file");
90
+ throw error;
91
+ }
92
+ return {
93
+ contract,
94
+ contractDts
95
+ };
96
+ }
97
+ async function deleteRefSnapshot(refsDir, name) {
98
+ if (!validateRefName(name)) throw errorInvalidRefName(name);
99
+ await unlinkIfExists(snapshotJsonPath(refsDir, name));
100
+ await unlinkIfExists(snapshotDtsPath(refsDir, name));
101
+ }
102
+ async function writeRefPaired(refsDir, name, entry, snapshot) {
103
+ await writeRefSnapshot(refsDir, name, snapshot);
104
+ try {
105
+ await writeRef(refsDir, name, entry);
106
+ } catch (writeError) {
107
+ try {
108
+ await deleteRefSnapshot(refsDir, name);
109
+ } catch {}
110
+ throw writeError;
111
+ }
112
+ }
113
+ function isUnknownRefError(error) {
114
+ return MigrationToolsError.is(error) && error.code === "MIGRATION.UNKNOWN_REF";
115
+ }
116
+ async function snapshotFilesExist(refsDir, name) {
117
+ if (!validateRefName(name)) throw errorInvalidRefName(name);
118
+ const paths = [snapshotJsonPath(refsDir, name), snapshotDtsPath(refsDir, name)];
119
+ return (await Promise.allSettled(paths.map((filePath) => access(filePath)))).some((result) => result.status === "fulfilled");
120
+ }
121
+ async function deleteRefPaired(refsDir, name) {
122
+ if (await snapshotFilesExist(refsDir, name)) {
123
+ try {
124
+ await deleteRef(refsDir, name);
125
+ } catch (error) {
126
+ if (!isUnknownRefError(error)) throw error;
127
+ }
128
+ await deleteRefSnapshot(refsDir, name);
129
+ return;
130
+ }
131
+ await deleteRef(refsDir, name);
132
+ await deleteRefSnapshot(refsDir, name);
133
+ }
134
+ //#endregion
135
+ export { deleteRef, deleteRefPaired, deleteRefSnapshot, readRef, readRefSnapshot, readRefs, resolveRef, validateRefName, validateRefValue, writeRef, writeRefPaired, writeRefSnapshot };
136
+
137
+ //# sourceMappingURL=refs.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refs.mjs","names":[],"sources":["../../src/refs/snapshot.ts"],"sourcesContent":["import { randomBytes } from 'node:crypto';\nimport { access, mkdir, readFile, rename, unlink, writeFile } from 'node:fs/promises';\nimport { canonicalizeJson } from '@prisma-next/framework-components/utils';\nimport { type } from 'arktype';\nimport { basename, dirname, join } from 'pathe';\nimport { errorInvalidRefFile, errorInvalidRefName, MigrationToolsError } from '../errors';\nimport { deleteRef, type RefEntry, validateRefName, writeRef } from '../refs';\n\nexport interface ContractIR {\n readonly contract: unknown;\n readonly contractDts: string;\n}\n\nconst ContractIrSchema = type({\n targetFamily: 'string',\n target: 'string',\n profileHash: 'string',\n storage: type({\n storageHash: 'string',\n }),\n models: 'object',\n});\n\nfunction hasErrnoCode(error: unknown, code: string): boolean {\n return error instanceof Error && (error as { code?: string }).code === code;\n}\n\nfunction snapshotJsonPath(refsDir: string, name: string): string {\n return join(refsDir, `${name}.contract.json`);\n}\n\nfunction snapshotDtsPath(refsDir: string, name: string): string {\n return join(refsDir, `${name}.contract.d.ts`);\n}\n\nfunction tmpPathFor(finalPath: string): string {\n const dir = dirname(finalPath);\n const fileName = basename(finalPath);\n return join(dir, `.${fileName}.${Date.now()}-${randomBytes(4).toString('hex')}.tmp`);\n}\n\nasync function atomicWriteFile(finalPath: string, content: string): Promise<void> {\n const dir = dirname(finalPath);\n await mkdir(dir, { recursive: true });\n const tmpPath = tmpPathFor(finalPath);\n await writeFile(tmpPath, content);\n await rename(tmpPath, finalPath);\n}\n\nasync function unlinkIfExists(filePath: string): Promise<void> {\n try {\n await unlink(filePath);\n } catch (error) {\n if (hasErrnoCode(error, 'ENOENT')) return;\n throw error;\n }\n}\n\nfunction parseContractSnapshotJson(filePath: string, raw: string): unknown {\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n throw errorInvalidRefFile(filePath, 'Failed to parse as JSON');\n }\n\n const result = ContractIrSchema(parsed);\n if (result instanceof type.errors) {\n throw errorInvalidRefFile(filePath, result.summary);\n }\n\n return result;\n}\n\nexport async function writeRefSnapshot(\n refsDir: string,\n name: string,\n snapshot: ContractIR,\n): Promise<void> {\n if (!validateRefName(name)) {\n throw errorInvalidRefName(name);\n }\n\n const jsonPath = snapshotJsonPath(refsDir, name);\n const dtsPath = snapshotDtsPath(refsDir, name);\n const jsonContent = `${canonicalizeJson(snapshot.contract)}\\n`;\n const dtsContent = snapshot.contractDts.endsWith('\\n')\n ? snapshot.contractDts\n : `${snapshot.contractDts}\\n`;\n\n try {\n await atomicWriteFile(jsonPath, jsonContent);\n } catch (error) {\n await unlinkIfExists(jsonPath);\n throw error;\n }\n\n try {\n await atomicWriteFile(dtsPath, dtsContent);\n } catch (error) {\n await unlinkIfExists(jsonPath);\n await unlinkIfExists(dtsPath);\n throw error;\n }\n}\n\nexport async function readRefSnapshot(refsDir: string, name: string): Promise<ContractIR | null> {\n if (!validateRefName(name)) {\n throw errorInvalidRefName(name);\n }\n\n const jsonPath = snapshotJsonPath(refsDir, name);\n const dtsPath = snapshotDtsPath(refsDir, name);\n\n let raw: string;\n try {\n raw = await readFile(jsonPath, 'utf-8');\n } catch (error) {\n if (hasErrnoCode(error, 'ENOENT')) {\n return null;\n }\n throw error;\n }\n\n const contract = parseContractSnapshotJson(jsonPath, raw);\n\n let contractDts: string;\n try {\n contractDts = await readFile(dtsPath, 'utf-8');\n } catch (error) {\n if (hasErrnoCode(error, 'ENOENT')) {\n throw errorInvalidRefFile(dtsPath, 'Missing paired contract.d.ts snapshot file');\n }\n throw error;\n }\n\n return { contract, contractDts };\n}\n\nexport async function deleteRefSnapshot(refsDir: string, name: string): Promise<void> {\n if (!validateRefName(name)) {\n throw errorInvalidRefName(name);\n }\n\n await unlinkIfExists(snapshotJsonPath(refsDir, name));\n await unlinkIfExists(snapshotDtsPath(refsDir, name));\n}\n\nexport async function writeRefPaired(\n refsDir: string,\n name: string,\n entry: RefEntry,\n snapshot: ContractIR,\n): Promise<void> {\n await writeRefSnapshot(refsDir, name, snapshot);\n try {\n await writeRef(refsDir, name, entry);\n } catch (writeError) {\n try {\n await deleteRefSnapshot(refsDir, name);\n } catch {\n // Rollback failure is secondary; preserve the original writeRef error.\n }\n throw writeError;\n }\n}\n\nfunction isUnknownRefError(error: unknown): boolean {\n return MigrationToolsError.is(error) && error.code === 'MIGRATION.UNKNOWN_REF';\n}\n\nasync function snapshotFilesExist(refsDir: string, name: string): Promise<boolean> {\n if (!validateRefName(name)) {\n throw errorInvalidRefName(name);\n }\n\n const paths = [snapshotJsonPath(refsDir, name), snapshotDtsPath(refsDir, name)];\n const checks = await Promise.allSettled(paths.map((filePath) => access(filePath)));\n return checks.some((result) => result.status === 'fulfilled');\n}\n\nexport async function deleteRefPaired(refsDir: string, name: string): Promise<void> {\n if (await snapshotFilesExist(refsDir, name)) {\n try {\n await deleteRef(refsDir, name);\n } catch (error) {\n if (!isUnknownRefError(error)) {\n throw error;\n }\n }\n await deleteRefSnapshot(refsDir, name);\n return;\n }\n\n await deleteRef(refsDir, name);\n await deleteRefSnapshot(refsDir, name);\n}\n"],"mappings":";;;;;;;;AAaA,MAAM,mBAAmB,KAAK;CAC5B,cAAc;CACd,QAAQ;CACR,aAAa;CACb,SAAS,KAAK,EACZ,aAAa,SACf,CAAC;CACD,QAAQ;AACV,CAAC;AAED,SAAS,aAAa,OAAgB,MAAuB;CAC3D,OAAO,iBAAiB,SAAU,MAA4B,SAAS;AACzE;AAEA,SAAS,iBAAiB,SAAiB,MAAsB;CAC/D,OAAO,KAAK,SAAS,GAAG,KAAK,eAAe;AAC9C;AAEA,SAAS,gBAAgB,SAAiB,MAAsB;CAC9D,OAAO,KAAK,SAAS,GAAG,KAAK,eAAe;AAC9C;AAEA,SAAS,WAAW,WAA2B;CAG7C,OAAO,KAFK,QAAQ,SAEN,GAAG,IADA,SAAS,SACE,EAAE,GAAG,KAAK,IAAI,EAAE,GAAG,YAAY,CAAC,EAAE,SAAS,KAAK,EAAE,KAAK;AACrF;AAEA,eAAe,gBAAgB,WAAmB,SAAgC;CAEhF,MAAM,MADM,QAAQ,SACN,GAAG,EAAE,WAAW,KAAK,CAAC;CACpC,MAAM,UAAU,WAAW,SAAS;CACpC,MAAM,UAAU,SAAS,OAAO;CAChC,MAAM,OAAO,SAA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AAK,GAC1B,MAAM;EAEV;EACA,MAAM,kBAAkB,SAAS,IAAI;EACrC;CACF;CAEA,MAAM,UAAU,SAAS,IAAI;CAC7B,MAAM,kBAAkB,SAAS,IAAI;AACvC"}
@@ -1,4 +1,4 @@
1
- import { t as MigrationOps } from "../package-DZj8YvD0.mjs";
1
+ import { t as MigrationOps } from "../package-DIttKL7X.mjs";
2
2
  import { APP_SPACE_ID, ContractSpace, ContractSpaceHeadRef, ContractSpaceHeadRef as ContractSpaceHeadRef$1 } from "@prisma-next/framework-components/control";
3
3
  import { Contract } from "@prisma-next/contract/types";
4
4
 
@@ -521,6 +521,31 @@ declare function assertValidSpaceId(spaceId: string): asserts spaceId is ValidSp
521
521
  * relative shape and is symmetric with `pathe.join`.
522
522
  */
523
523
  declare function spaceMigrationDirectory(projectMigrationsDir: string, spaceId: string): string;
524
+ /**
525
+ * Per-space subdirectory name reserved for the ref store
526
+ * (`migrations/<space>/<SPACE_REFS_DIRNAME>/*.json`). Single source of
527
+ * truth: every helper that composes a per-space refs path imports this
528
+ * constant, and the enumerator uses it (via
529
+ * {@link RESERVED_SPACE_SUBDIR_NAMES}) to exclude reserved names from
530
+ * the contract-space candidate list.
531
+ */
532
+ declare const SPACE_REFS_DIRNAME = "refs";
533
+ /**
534
+ * Names reserved as per-space subdirectories of `migrations/<space>/`.
535
+ * Used by the enumerator to filter contract-space candidates so a
536
+ * reserved name (e.g. a top-level `migrations/refs/` left in the wrong
537
+ * place) is never enumerated as a phantom contract space. Currently
538
+ * holds `SPACE_REFS_DIRNAME`; extend if future per-space layouts add
539
+ * more reserved subdirectories.
540
+ */
541
+ declare const RESERVED_SPACE_SUBDIR_NAMES: ReadonlySet<string>;
542
+ /**
543
+ * Resolve the per-space refs directory for `spaceMigrationsDir`
544
+ * (typically the value returned by {@link spaceMigrationDirectory}).
545
+ * Composes the canonical {@link SPACE_REFS_DIRNAME} so callers do not
546
+ * hard-code the literal.
547
+ */
548
+ declare function spaceRefsDirectory(spaceMigrationsDir: string): string;
524
549
  //#endregion
525
- export { APP_SPACE_ID, type ComputeExtensionSpaceApplyPathInputs, type ContractSpaceArtefactInputs, type ContractSpaceHeadRecord, type ContractSpaceHeadRef, type DescriptorSelfConsistencyInputs, type DiskContractSpaceState, type ExtensionSpaceApplyPathOutcome, type SpaceApplyInput, type SpaceMarkerRecord, type SpacePlanInput, type SpacePlanOutput, type SpaceVerifierViolation, type ValidSpaceId, type VerifyContractSpacesInputs, type VerifyContractSpacesResult, assertDescriptorSelfConsistency, assertValidSpaceId, computeExtensionSpaceApplyPath, contractSpaceFromJson, emitContractSpaceArtefacts, gatherDiskContractSpaceState, isValidSpaceId, listContractSpaceDirectories, planAllSpaces, readContractSpaceContract, readContractSpaceHeadRef, spaceMigrationDirectory, verifyContractSpaces };
550
+ export { APP_SPACE_ID, type ComputeExtensionSpaceApplyPathInputs, type ContractSpaceArtefactInputs, type ContractSpaceHeadRecord, type ContractSpaceHeadRef, type DescriptorSelfConsistencyInputs, type DiskContractSpaceState, type ExtensionSpaceApplyPathOutcome, RESERVED_SPACE_SUBDIR_NAMES, SPACE_REFS_DIRNAME, type SpaceApplyInput, type SpaceMarkerRecord, type SpacePlanInput, type SpacePlanOutput, type SpaceVerifierViolation, type ValidSpaceId, type VerifyContractSpacesInputs, type VerifyContractSpacesResult, assertDescriptorSelfConsistency, assertValidSpaceId, computeExtensionSpaceApplyPath, contractSpaceFromJson, emitContractSpaceArtefacts, gatherDiskContractSpaceState, isValidSpaceId, listContractSpaceDirectories, planAllSpaces, readContractSpaceContract, readContractSpaceHeadRef, spaceMigrationDirectory, spaceRefsDirectory, verifyContractSpaces };
526
551
  //# sourceMappingURL=spaces.d.mts.map