@prisma-next/migration-tools 0.8.0-dev.1 → 0.8.0-dev.10

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 (74) hide show
  1. package/README.md +6 -6
  2. package/dist/{errors-EPL_9p9f.mjs → errors-DGYwcwXs.mjs} +3 -15
  3. package/dist/errors-DGYwcwXs.mjs.map +1 -0
  4. package/dist/exports/aggregate.d.mts +7 -7
  5. package/dist/exports/aggregate.mjs +3 -3
  6. package/dist/exports/aggregate.mjs.map +1 -1
  7. package/dist/exports/errors.d.mts.map +1 -1
  8. package/dist/exports/errors.mjs +1 -1
  9. package/dist/exports/graph.d.mts +1 -1
  10. package/dist/exports/hash.d.mts +9 -7
  11. package/dist/exports/hash.d.mts.map +1 -1
  12. package/dist/exports/hash.mjs +1 -1
  13. package/dist/exports/invariants.d.mts +1 -1
  14. package/dist/exports/invariants.mjs +1 -1
  15. package/dist/exports/io.d.mts +13 -17
  16. package/dist/exports/io.d.mts.map +1 -1
  17. package/dist/exports/io.mjs +1 -1
  18. package/dist/exports/metadata.d.mts +1 -1
  19. package/dist/exports/migration-graph.d.mts +1 -1
  20. package/dist/exports/migration-graph.mjs +1 -1
  21. package/dist/exports/migration.d.mts +1 -1
  22. package/dist/exports/migration.d.mts.map +1 -1
  23. package/dist/exports/migration.mjs +3 -41
  24. package/dist/exports/migration.mjs.map +1 -1
  25. package/dist/exports/package.d.mts +1 -1
  26. package/dist/exports/ref-resolution.d.mts +100 -0
  27. package/dist/exports/ref-resolution.d.mts.map +1 -0
  28. package/dist/exports/ref-resolution.mjs +239 -0
  29. package/dist/exports/ref-resolution.mjs.map +1 -0
  30. package/dist/exports/refs.d.mts +2 -16
  31. package/dist/exports/refs.mjs +1 -147
  32. package/dist/exports/spaces.d.mts +1 -1
  33. package/dist/exports/spaces.mjs +4 -4
  34. package/dist/exports/spaces.mjs.map +1 -1
  35. package/dist/{graph-HMWAldoR.d.mts → graph-BrLXqoUc.d.mts} +1 -1
  36. package/dist/{graph-HMWAldoR.d.mts.map → graph-BrLXqoUc.d.mts.map} +1 -1
  37. package/dist/{hash-C6bpZczT.mjs → hash-Cr4WIr4Z.mjs} +10 -8
  38. package/dist/hash-Cr4WIr4Z.mjs.map +1 -0
  39. package/dist/{invariants-qgQGlsrV.mjs → invariants-0daYEzyo.mjs} +2 -2
  40. package/dist/{invariants-qgQGlsrV.mjs.map → invariants-0daYEzyo.mjs.map} +1 -1
  41. package/dist/{io-Dw620b51.mjs → io-BPLfzvZe.mjs} +16 -24
  42. package/dist/io-BPLfzvZe.mjs.map +1 -0
  43. package/dist/{migration-graph-DulOITvG.d.mts → migration-graph-De0dUZoC.d.mts} +3 -3
  44. package/dist/{migration-graph-DulOITvG.d.mts.map → migration-graph-De0dUZoC.d.mts.map} +1 -1
  45. package/dist/{migration-graph-DGNnKDY5.mjs → migration-graph-nlS4TRpn.mjs} +2 -2
  46. package/dist/{migration-graph-DGNnKDY5.mjs.map → migration-graph-nlS4TRpn.mjs.map} +1 -1
  47. package/dist/{package-BjiZ7KDy.d.mts → package-DZj8YvD0.d.mts} +1 -1
  48. package/dist/package-DZj8YvD0.d.mts.map +1 -0
  49. package/dist/{read-contract-space-contract-COyz4tZn.mjs → read-contract-space-contract-C4_goX0c.mjs} +3 -3
  50. package/dist/{read-contract-space-contract-COyz4tZn.mjs.map → read-contract-space-contract-C4_goX0c.mjs.map} +1 -1
  51. package/dist/refs-BDHo5l_g.mjs +148 -0
  52. package/dist/refs-BDHo5l_g.mjs.map +1 -0
  53. package/dist/refs-CDaNerhT.d.mts +16 -0
  54. package/dist/refs-CDaNerhT.d.mts.map +1 -0
  55. package/package.json +10 -6
  56. package/src/aggregate/planner-types.ts +2 -2
  57. package/src/aggregate/strategies/graph-walk.ts +1 -1
  58. package/src/compute-extension-space-apply-path.ts +1 -1
  59. package/src/errors.ts +1 -22
  60. package/src/exports/ref-resolution.ts +15 -0
  61. package/src/hash.ts +8 -12
  62. package/src/io.ts +12 -22
  63. package/src/migration-base.ts +1 -54
  64. package/src/refs/contract-ref.ts +103 -0
  65. package/src/refs/migration-ref.ts +121 -0
  66. package/src/refs/types.ts +93 -0
  67. package/src/refs.ts +3 -3
  68. package/dist/errors-EPL_9p9f.mjs.map +0 -1
  69. package/dist/exports/refs.d.mts.map +0 -1
  70. package/dist/exports/refs.mjs.map +0 -1
  71. package/dist/hash-C6bpZczT.mjs.map +0 -1
  72. package/dist/io-Dw620b51.mjs.map +0 -1
  73. package/dist/package-BjiZ7KDy.d.mts.map +0 -1
  74. /package/dist/{metadata-CFvm3ayn.d.mts → metadata-BFX0xdz8.d.mts} +0 -0
@@ -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-Dw620b51.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-BPLfzvZe.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-CFvm3ayn.mjs";
1
+ import { n as MigrationMetadata, t as MigrationHints } from "../metadata-BFX0xdz8.mjs";
2
2
  export { type MigrationHints, type MigrationMetadata };
@@ -1,2 +1,2 @@
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-DulOITvG.mjs";
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
2
  export { type PathDecision, detectCycles, detectOrphans, findLatestMigration, findLeaf, findPath, findPathWithDecision, findPathWithInvariants, findReachableLeaves, reconstructGraph };
@@ -1,2 +1,2 @@
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-DGNnKDY5.mjs";
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
2
  export { detectCycles, detectOrphans, findLatestMigration, findLeaf, findPath, findPathWithDecision, findPathWithInvariants, findReachableLeaves, reconstructGraph };
@@ -1,4 +1,4 @@
1
- import { n as MigrationMetadata$1 } from "../metadata-CFvm3ayn.mjs";
1
+ import { n as MigrationMetadata$1 } from "../metadata-BFX0xdz8.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":";;;;UAgBiB,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,YA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1,6 +1,6 @@
1
- import { T as errorStaleContractBookends, f as errorInvalidOperationEntry } from "../errors-EPL_9p9f.mjs";
2
- import { t as computeMigrationHash } from "../hash-C6bpZczT.mjs";
3
- import { t as deriveProvidedInvariants } from "../invariants-qgQGlsrV.mjs";
1
+ import { f as errorInvalidOperationEntry } from "../errors-DGYwcwXs.mjs";
2
+ import { t as computeMigrationHash } from "../hash-Cr4WIr4Z.mjs";
3
+ import { t as deriveProvidedInvariants } from "../invariants-0daYEzyo.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";
@@ -77,15 +77,12 @@ function isDirectEntrypoint(importMetaUrl) {
77
77
  * the on-disk artifacts are always fully attested.
78
78
  */
79
79
  function buildAttestedMetadata(meta, ops, existing) {
80
- assertBookendsMatchMeta(meta, existing);
81
80
  const baseMetadata = {
82
81
  from: meta.from,
83
82
  to: meta.to,
84
83
  labels: meta.labels ?? existing?.labels ?? [],
85
84
  providedInvariants: deriveProvidedInvariants(ops),
86
85
  createdAt: existing?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
87
- fromContract: existing?.fromContract ?? null,
88
- toContract: existing?.toContract ?? { storage: { storageHash: meta.to } },
89
86
  hints: normalizeHints(existing?.hints)
90
87
  };
91
88
  const migrationHash = computeMigrationHash(baseMetadata, ops);
@@ -95,41 +92,6 @@ function buildAttestedMetadata(meta, ops, existing) {
95
92
  };
96
93
  }
97
94
  /**
98
- * Verify each preserved contract bookend in `existing` agrees with the
99
- * corresponding side of `describe()`'s output. A mismatch indicates the
100
- * migration's `describe()` was edited after `migration plan` scaffolded
101
- * the package, leaving a self-inconsistent manifest. Failing fast at
102
- * write-time turns a silent foot-gun into an actionable diagnostic.
103
- *
104
- * Skipped when a side's `existing.<side>Contract` is null/absent (the
105
- * synthesis path stays open for origin-less initial migrations and for
106
- * bare `migration.ts` runs from scratch). When a bookend is *present*
107
- * but its `storage.storageHash` is missing, that's treated as a
108
- * mismatch — a malformed bookend is not equivalent to "no bookend".
109
- *
110
- * This check is paired with TML-2274, which removes `fromContract` /
111
- * `toContract` from the manifest entirely; once that lands, this
112
- * function and its error code are deleted.
113
- */
114
- function assertBookendsMatchMeta(meta, existing) {
115
- if (existing?.fromContract != null) {
116
- const contractHash = existing.fromContract.storage?.storageHash ?? "";
117
- if (contractHash !== meta.from) throw errorStaleContractBookends({
118
- side: "from",
119
- metaHash: meta.from,
120
- contractHash
121
- });
122
- }
123
- if (existing?.toContract != null) {
124
- const contractHash = existing.toContract.storage?.storageHash ?? "";
125
- if (contractHash !== meta.to) throw errorStaleContractBookends({
126
- side: "to",
127
- metaHash: meta.to,
128
- contractHash
129
- });
130
- }
131
- }
132
- /**
133
95
  * Project `existing.hints` down to the known `MigrationHints` shape, dropping
134
96
  * any legacy keys that may linger in metadata scaffolded by older CLI
135
97
  * versions (e.g. `planningStrategy`). Picking fields explicitly instead of
@@ -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 { Contract } from '@prisma-next/contract/types';\nimport type {\n ControlStack,\n MigrationPlan,\n MigrationPlanOperation,\n} from '@prisma-next/framework-components/control';\nimport { type } from 'arktype';\nimport { errorInvalidOperationEntry, errorStaleContractBookends } 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 assertBookendsMatchMeta(meta, existing);\n\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 fromContract: existing?.fromContract ?? null,\n // When no scaffolded metadata exists we synthesize a minimal contract\n // stub so the package is still readable end-to-end. The cast is\n // intentional: only the storage bookend matters for hash computation\n // (everything else is stripped by `computeMigrationHash`), and a real\n // contract bookend would only be available after `migration plan`.\n toContract: existing?.toContract ?? ({ storage: { storageHash: meta.to } } as Contract),\n hints: normalizeHints(existing?.hints),\n };\n\n const migrationHash = computeMigrationHash(baseMetadata, ops);\n return { ...baseMetadata, migrationHash };\n}\n\n/**\n * Verify each preserved contract bookend in `existing` agrees with the\n * corresponding side of `describe()`'s output. A mismatch indicates the\n * migration's `describe()` was edited after `migration plan` scaffolded\n * the package, leaving a self-inconsistent manifest. Failing fast at\n * write-time turns a silent foot-gun into an actionable diagnostic.\n *\n * Skipped when a side's `existing.<side>Contract` is null/absent (the\n * synthesis path stays open for origin-less initial migrations and for\n * bare `migration.ts` runs from scratch). When a bookend is *present*\n * but its `storage.storageHash` is missing, that's treated as a\n * mismatch — a malformed bookend is not equivalent to \"no bookend\".\n *\n * This check is paired with TML-2274, which removes `fromContract` /\n * `toContract` from the manifest entirely; once that lands, this\n * function and its error code are deleted.\n */\nfunction assertBookendsMatchMeta(\n meta: MigrationMeta,\n existing: Partial<MigrationMetadata> | null,\n): void {\n if (existing?.fromContract != null) {\n const contractHash = existing.fromContract.storage?.storageHash ?? '';\n if (contractHash !== meta.from) {\n throw errorStaleContractBookends({\n side: 'from',\n metaHash: meta.from,\n contractHash,\n });\n }\n }\n if (existing?.toContract != null) {\n const contractHash = existing.toContract.storage?.storageHash ?? '';\n if (contractHash !== meta.to) {\n throw errorStaleContractBookends({\n side: 'to',\n metaHash: meta.to,\n contractHash,\n });\n }\n }\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":";;;;;;;;AA2BA,MAAM,sBAAsB,KAAK;CAC/B,MAAM;CACN,IAAI;CACJ,WAAW,KAAK,SAAS,CAAC,OAAO;CAClC,CAAC;;;;;;;;;;AAWF,IAAsB,YAAtB,MAKA;;;;;;;;;;CAYE;CAEA,YAAY,OAA4C;EACtD,KAAK,QAAQ;;CAkBf,IAAI,SAAkD;EACpD,MAAM,OAAO,KAAK,UAAU,CAAC;EAC7B,OAAO,SAAS,OAAO,OAAO,EAAE,aAAa,MAAM;;CAGrD,IAAI,cAAgD;EAClD,OAAO,EAAE,aAAa,KAAK,UAAU,CAAC,IAAI;;;;;;;;;;AAW9C,SAAgB,mBAAmB,eAAgC;CACjE,MAAM,eAAe,cAAc,cAAc;CACjD,MAAM,QAAQ,QAAQ,KAAK;CAC3B,IAAI,CAAC,OAAO,OAAO;CACnB,IAAI;EACF,OAAO,aAAa,aAAa,KAAK,aAAa,MAAM;SACnD;EACN,OAA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,OAAO;EAC5C,IAAI,kBAAkB,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,SAAS,CAAC,OAAO;CAClC,CAAC;;;;;;;;;;AAWF,IAAsB,YAAtB,MAKA;;;;;;;;;;CAYE;CAEA,YAAY,OAA4C;EACtD,KAAK,QAAQ;;CAkBf,IAAI,SAAkD;EACpD,MAAM,OAAO,KAAK,UAAU,CAAC;EAC7B,OAAO,SAAS,OAAO,OAAO,EAAE,aAAa,MAAM;;CAGrD,IAAI,cAAgD;EAClD,OAAO,EAAE,aAAa,KAAK,UAAU,CAAC,IAAI;;;;;;;;;;AAW9C,SAAgB,mBAAmB,eAAgC;CACjE,MAAM,eAAe,cAAc,cAAc;CACjD,MAAM,QAAQ,QAAQ,KAAK;CAC3B,IAAI,CAAC,OAAO,OAAO;CACnB,IAAI;EACF,OAAO,aAAa,aAAa,KAAK,aAAa,MAAM;SACnD;EACN,OAAO;;;;;;;;;;;;;;;;;;;;AAsCX,SAAS,sBACP,MACA,KACA,UACmB;CACnB,MAAM,eAAyD;EAC7D,MAAM,KAAK;EACX,IAAI,KAAK;EACT,QAAQ,KAAK,UAAU,UAAU,UAAU,EAAE;EAC7C,oBAAoB,yBAAyB,IAAI;EACjD,WAAW,UAAU,8BAAa,IAAI,MAAM,EAAC,aAAa;EAC1D,OAAO,eAAe,UAAU,MAAM;EACvC;CAED,MAAM,gBAAgB,qBAAqB,cAAc,IAAI;CAC7D,OAAO;EAAE,GAAG;EAAc;EAAe;;;;;;;;;AAU3C,SAAS,eAAe,UAAsD;CAC5E,OAAO;EACL,MAAM,UAAU,QAAQ,EAAE;EAC1B,SAAS,UAAU,WAAW,EAAE;EAChC,gBAAgB,UAAU,kBAAkB;EAC7C;;;;;;;;;;;AAYH,SAAgB,wBACd,UACA,UACoB;CACpB,MAAM,MAAM,SAAS;CACrB,IAAI,CAAC,MAAM,QAAQ,IAAI,EACrB,MAAM,IAAI,MAAM,8BAA8B;CAGhD,KAAK,IAAI,QAAQ,GAAG,QAAQ,IAAI,QAAQ,SAAS;EAC/C,MAAM,SAAS,kBAAkB,IAAI,OAAO;EAC5C,IAAI,kBAAkB,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,3 +1,3 @@
1
- import { n as OnDiskMigrationPackage, t as MigrationOps } from "../package-BjiZ7KDy.mjs";
1
+ import { n as OnDiskMigrationPackage, t as MigrationOps } from "../package-DZj8YvD0.mjs";
2
2
  import { MigrationPackage } from "@prisma-next/framework-components/control";
3
3
  export { type MigrationOps, type MigrationPackage, type OnDiskMigrationPackage };
@@ -0,0 +1,100 @@
1
+ import { n as MigrationGraph, t as MigrationEdge } from "../graph-BrLXqoUc.mjs";
2
+ import { n as Refs } from "../refs-CDaNerhT.mjs";
3
+ import { Result } from "@prisma-next/utils/result";
4
+
5
+ //#region src/refs/types.d.ts
6
+ /** Context required to resolve a contract or migration reference. */
7
+ interface RefResolutionContext {
8
+ readonly graph: MigrationGraph;
9
+ readonly refs: Refs;
10
+ }
11
+ type ContractRefProvenance = {
12
+ readonly kind: 'hash';
13
+ readonly input: string;
14
+ } | {
15
+ readonly kind: 'ref';
16
+ readonly refName: string;
17
+ } | {
18
+ readonly kind: 'migration-to';
19
+ readonly dirName: string;
20
+ } | {
21
+ readonly kind: 'migration-from';
22
+ readonly dirName: string;
23
+ };
24
+ /** A resolved contract reference: the target hash and how it was derived. */
25
+ interface ContractRef {
26
+ readonly hash: string;
27
+ readonly provenance: ContractRefProvenance;
28
+ }
29
+ type MigrationRefProvenance = {
30
+ readonly kind: 'dir-name';
31
+ readonly dirName: string;
32
+ } | {
33
+ readonly kind: 'hash';
34
+ readonly input: string;
35
+ };
36
+ /** A resolved migration reference. */
37
+ interface MigrationRef {
38
+ readonly dirName: string;
39
+ readonly migrationHash: string;
40
+ readonly from: string;
41
+ readonly to: string;
42
+ readonly provenance: MigrationRefProvenance;
43
+ }
44
+ interface RefResolutionNotFound {
45
+ readonly kind: 'not-found';
46
+ readonly input: string;
47
+ readonly grammar: 'contract' | 'migration';
48
+ }
49
+ interface RefResolutionAmbiguous {
50
+ readonly kind: 'ambiguous';
51
+ readonly input: string;
52
+ readonly candidates: readonly string[];
53
+ readonly grammar: 'contract' | 'migration';
54
+ }
55
+ interface RefResolutionWrongGrammar {
56
+ readonly kind: 'wrong-grammar';
57
+ readonly input: string;
58
+ readonly expectedGrammar: 'contract' | 'migration';
59
+ readonly message: string;
60
+ readonly fix: string;
61
+ }
62
+ interface RefResolutionInvalidFormat {
63
+ readonly kind: 'invalid-format';
64
+ readonly input: string;
65
+ readonly reason: string;
66
+ }
67
+ type RefResolutionError = RefResolutionNotFound | RefResolutionAmbiguous | RefResolutionWrongGrammar | RefResolutionInvalidFormat;
68
+ declare function findEdgeByDirName(graph: MigrationGraph, dirName: string): MigrationEdge | undefined;
69
+ //#endregion
70
+ //#region src/refs/contract-ref.d.ts
71
+ /**
72
+ * Resolve a user-supplied string to a contract hash using the unified
73
+ * contract-reference grammar.
74
+ *
75
+ * Accepted forms:
76
+ * - Full storage hash (`sha256:<64 hex>` or `sha256:empty`)
77
+ * - Hex prefix (6+ hex chars, must uniquely identify one contract)
78
+ * - Ref name (looked up in the refs index)
79
+ * - Migration directory name (resolves to the migration's `to`-contract)
80
+ * - `<dir>^` (resolves to the migration's `from`-contract)
81
+ */
82
+ declare function parseContractRef(input: string, ctx: RefResolutionContext): Result<ContractRef, RefResolutionError>;
83
+ //#endregion
84
+ //#region src/refs/migration-ref.d.ts
85
+ /**
86
+ * Resolve a user-supplied string to a migration using the migration-reference
87
+ * grammar.
88
+ *
89
+ * Accepted forms:
90
+ * - Migration directory name (e.g. `20260101-add-users`)
91
+ * - Migration hash (full or 6+ hex prefix)
92
+ *
93
+ * Wrong-grammar diagnostics are produced when the input matches a
94
+ * contract-grammar form (ref name, `<dir>^`, contract-only hash) so the
95
+ * user gets a targeted hint rather than a generic "not found".
96
+ */
97
+ declare function parseMigrationRef(input: string, ctx: RefResolutionContext): Result<MigrationRef, RefResolutionError>;
98
+ //#endregion
99
+ export { type ContractRef, type ContractRefProvenance, type MigrationRef, type MigrationRefProvenance, type RefResolutionAmbiguous, type RefResolutionContext, type RefResolutionError, type RefResolutionInvalidFormat, type RefResolutionNotFound, type RefResolutionWrongGrammar, findEdgeByDirName, parseContractRef, parseMigrationRef };
100
+ //# sourceMappingURL=ref-resolution.d.mts.map
@@ -0,0 +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":";;;;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AAA,GACJ,MAAA,CAAO,YAAA,EAAc,kBAAA"}
@@ -0,0 +1,239 @@
1
+ import { a as validateRefName } from "../refs-BDHo5l_g.mjs";
2
+ import { notOk, ok } from "@prisma-next/utils/result";
3
+ //#region src/refs/types.ts
4
+ const FULL_HASH_PATTERN = /^sha256:([0-9a-f]{64}|empty)$/;
5
+ const HEX_PREFIX_PATTERN = /^(sha256:)?[0-9a-f]{6,}$/;
6
+ function isFullHash(input) {
7
+ return FULL_HASH_PATTERN.test(input);
8
+ }
9
+ function isHexPrefix(input) {
10
+ return HEX_PREFIX_PATTERN.test(input);
11
+ }
12
+ function normalizeHashPrefix(input) {
13
+ return input.startsWith("sha256:") ? input : `sha256:${input}`;
14
+ }
15
+ function findEdgeByDirName(graph, dirName) {
16
+ for (const edges of graph.forwardChain.values()) for (const edge of edges) if (edge.dirName === dirName) return edge;
17
+ }
18
+ //#endregion
19
+ //#region src/refs/contract-ref.ts
20
+ /**
21
+ * Resolve a user-supplied string to a contract hash using the unified
22
+ * contract-reference grammar.
23
+ *
24
+ * Accepted forms:
25
+ * - Full storage hash (`sha256:<64 hex>` or `sha256:empty`)
26
+ * - Hex prefix (6+ hex chars, must uniquely identify one contract)
27
+ * - Ref name (looked up in the refs index)
28
+ * - Migration directory name (resolves to the migration's `to`-contract)
29
+ * - `<dir>^` (resolves to the migration's `from`-contract)
30
+ */
31
+ function parseContractRef(input, ctx) {
32
+ if (!input) return notOk({
33
+ kind: "invalid-format",
34
+ input,
35
+ reason: "Reference cannot be empty"
36
+ });
37
+ if (isFullHash(input)) {
38
+ if (ctx.graph.nodes.has(input)) return ok({
39
+ hash: input,
40
+ provenance: {
41
+ kind: "hash",
42
+ input
43
+ }
44
+ });
45
+ return notOk({
46
+ kind: "not-found",
47
+ input,
48
+ grammar: "contract"
49
+ });
50
+ }
51
+ if (input.endsWith("^")) {
52
+ const dirName = input.slice(0, -1);
53
+ if (!dirName) return notOk({
54
+ kind: "invalid-format",
55
+ input,
56
+ reason: "Missing directory name before ^"
57
+ });
58
+ const edge = findEdgeByDirName(ctx.graph, dirName);
59
+ if (edge) return ok({
60
+ hash: edge.from,
61
+ provenance: {
62
+ kind: "migration-from",
63
+ dirName
64
+ }
65
+ });
66
+ return notOk({
67
+ kind: "not-found",
68
+ input,
69
+ grammar: "contract"
70
+ });
71
+ }
72
+ const candidates = [];
73
+ if (validateRefName(input) && Object.hasOwn(ctx.refs, input)) {
74
+ const ref = ctx.refs[input];
75
+ if (ref) candidates.push({
76
+ hash: ref.hash,
77
+ provenance: {
78
+ kind: "ref",
79
+ refName: input
80
+ },
81
+ label: `ref "${input}"`
82
+ });
83
+ }
84
+ const edge = findEdgeByDirName(ctx.graph, input);
85
+ if (edge) candidates.push({
86
+ hash: edge.to,
87
+ provenance: {
88
+ kind: "migration-to",
89
+ dirName: input
90
+ },
91
+ label: `migration directory "${input}"`
92
+ });
93
+ if (isHexPrefix(input)) {
94
+ const prefix = normalizeHashPrefix(input);
95
+ const matches = [...ctx.graph.nodes].filter((n) => n.startsWith(prefix));
96
+ const [firstMatch] = matches;
97
+ if (matches.length === 1 && firstMatch !== void 0) candidates.push({
98
+ hash: firstMatch,
99
+ provenance: {
100
+ kind: "hash",
101
+ input
102
+ },
103
+ label: `hash prefix "${input}"`
104
+ });
105
+ else if (matches.length > 1) return notOk({
106
+ kind: "ambiguous",
107
+ input,
108
+ candidates: matches,
109
+ grammar: "contract"
110
+ });
111
+ }
112
+ const [firstCandidate] = candidates;
113
+ if (candidates.length === 1 && firstCandidate !== void 0) return ok({
114
+ hash: firstCandidate.hash,
115
+ provenance: firstCandidate.provenance
116
+ });
117
+ if (candidates.length > 1) return notOk({
118
+ kind: "ambiguous",
119
+ input,
120
+ candidates: candidates.map((c) => c.label),
121
+ grammar: "contract"
122
+ });
123
+ return notOk({
124
+ kind: "not-found",
125
+ input,
126
+ grammar: "contract"
127
+ });
128
+ }
129
+ //#endregion
130
+ //#region src/refs/migration-ref.ts
131
+ /**
132
+ * Resolve a user-supplied string to a migration using the migration-reference
133
+ * grammar.
134
+ *
135
+ * Accepted forms:
136
+ * - Migration directory name (e.g. `20260101-add-users`)
137
+ * - Migration hash (full or 6+ hex prefix)
138
+ *
139
+ * Wrong-grammar diagnostics are produced when the input matches a
140
+ * contract-grammar form (ref name, `<dir>^`, contract-only hash) so the
141
+ * user gets a targeted hint rather than a generic "not found".
142
+ */
143
+ function parseMigrationRef(input, ctx) {
144
+ if (!input) return notOk({
145
+ kind: "invalid-format",
146
+ input,
147
+ reason: "Reference cannot be empty"
148
+ });
149
+ if (input.endsWith("^")) return notOk({
150
+ kind: "wrong-grammar",
151
+ input,
152
+ expectedGrammar: "migration",
153
+ message: "`^` syntax addresses contracts, not migrations",
154
+ fix: "Pass the migration directory name without `^`, or use a contract-accepting flag like `--to` or `--from`."
155
+ });
156
+ if (validateRefName(input) && Object.hasOwn(ctx.refs, input)) return notOk({
157
+ kind: "wrong-grammar",
158
+ input,
159
+ expectedGrammar: "migration",
160
+ message: `"${input}" is a ref name, not a migration`,
161
+ fix: "Refs point at contracts, not migrations. Use a migration directory name or migration hash."
162
+ });
163
+ const edge = findEdgeByDirName(ctx.graph, input);
164
+ if (edge) return ok({
165
+ dirName: edge.dirName,
166
+ migrationHash: edge.migrationHash,
167
+ from: edge.from,
168
+ to: edge.to,
169
+ provenance: {
170
+ kind: "dir-name",
171
+ dirName: input
172
+ }
173
+ });
174
+ if (isFullHash(input)) {
175
+ const migEdge = ctx.graph.migrationByHash.get(input);
176
+ if (migEdge) return ok({
177
+ dirName: migEdge.dirName,
178
+ migrationHash: migEdge.migrationHash,
179
+ from: migEdge.from,
180
+ to: migEdge.to,
181
+ provenance: {
182
+ kind: "hash",
183
+ input
184
+ }
185
+ });
186
+ if (ctx.graph.nodes.has(input)) return notOk({
187
+ kind: "wrong-grammar",
188
+ input,
189
+ expectedGrammar: "migration",
190
+ message: "Hash matched a contract but not a migration",
191
+ fix: "Use a contract-accepting flag like `--to` or `--from` to reference contracts by hash. Pass `migration show <dir>` for a specific migration."
192
+ });
193
+ return notOk({
194
+ kind: "not-found",
195
+ input,
196
+ grammar: "migration"
197
+ });
198
+ }
199
+ if (isHexPrefix(input)) {
200
+ const prefix = normalizeHashPrefix(input);
201
+ const migMatches = [...ctx.graph.migrationByHash.entries()].filter(([hash]) => hash.startsWith(prefix));
202
+ const [firstMigMatch] = migMatches;
203
+ if (migMatches.length === 1 && firstMigMatch !== void 0) {
204
+ const [, matchedEdge] = firstMigMatch;
205
+ return ok({
206
+ dirName: matchedEdge.dirName,
207
+ migrationHash: matchedEdge.migrationHash,
208
+ from: matchedEdge.from,
209
+ to: matchedEdge.to,
210
+ provenance: {
211
+ kind: "hash",
212
+ input
213
+ }
214
+ });
215
+ }
216
+ if (migMatches.length > 1) return notOk({
217
+ kind: "ambiguous",
218
+ input,
219
+ candidates: migMatches.map(([hash]) => hash),
220
+ grammar: "migration"
221
+ });
222
+ if ([...ctx.graph.nodes].filter((n) => n.startsWith(prefix)).length > 0) return notOk({
223
+ kind: "wrong-grammar",
224
+ input,
225
+ expectedGrammar: "migration",
226
+ message: "Hash matched a contract but not a migration",
227
+ fix: "Use a contract-accepting flag like `--to` or `--from` to reference contracts by hash. Pass `migration show <dir>` for a specific migration."
228
+ });
229
+ }
230
+ return notOk({
231
+ kind: "not-found",
232
+ input,
233
+ grammar: "migration"
234
+ });
235
+ }
236
+ //#endregion
237
+ export { findEdgeByDirName, parseContractRef, parseMigrationRef };
238
+
239
+ //# sourceMappingURL=ref-resolution.mjs.map
@@ -0,0 +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"],"mappings":";;;AAmEA,MAAM,oBAAoB;AAC1B,MAAM,qBAAqB;AAE3B,SAAgB,WAAW,OAAwB;CACjD,OAAO,kBAAkB,KAAK,MAAM;;AAGtC,SAAgB,YAAY,OAAwB;CAClD,OAAO,mBAAmB,KAAK,MAAM;;AAGvC,SAAgB,oBAAoB,OAAuB;CACzD,OAAO,MAAM,WAAW,UAAU,GAAG,QAAQ,UAAU;;AAGzD,SAAgB,kBACd,OACA,SAC2B;CAC3B,KAAK,MAAM,SAAS,MAAM,aAAa,QAAQ,EAC7C,KAAK,MAAM,QAAQ,OACjB,IAAI,KAAK,YAAY,SAAS,OAAO;;;;;;;;;;;;;;;AClE3C,SAAgB,iBACd,OACA,KACyC;CACzC,IAAI,CAAC,OACH,OAAO,MAAM;EAAE,MAAM;EAAkB;EAAO,QAAQ;EAA6B,CAAC;CAGtF,IAAI,WAAW,MAAM,EAAE;EACrB,IAAI,IAAI,MAAM,MAAM,IAAI,MAAM,EAC5B,OAAO,GAAG;GAAE,MAAM;GAAO,YAAY;IAAE,MAAM;IAAQ;IAAO;GAAE,CAAC;EAEjE,OAAO,MAAM;GAAE,MAAM;GAAa;GAAO,SAAS;GAAY,CAAC;;CAGjE,IAAI,MAAM,SAAS,IAAI,EAAE;EACvB,MAAM,UAAU,MAAM,MAAM,GAAG,GAAG;EAClC,IAAI,CAAC,SACH,OAAO,MAAM;GAAE,MAAM;GAAkB;GAAO,QAAQ;GAAmC,CAAC;EAE5F,MAAM,OAAO,kBAAkB,IAAI,OAAO,QAAQ;EAClD,IAAI,MACF,OAAO,GAAG;GAAE,MAAM,KAAK;GAAM,YAAY;IAAE,MAAM;IAAkB;IAAS;GAAE,CAAC;EAEjF,OAAO,MAAM;GAAE,MAAM;GAAa;GAAO,SAAS;GAAY,CAAC;;CAIjE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e;GACxB,OAAO,GAAG;IACR,SAAS,YAAY;IACrB,eAAe,YAAY;IAC3B,MAAM,YAAY;IAClB,IAAI,YAAY;IAChB,YAAY;KAAE,MAAM;KAAQ;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,16 +1,2 @@
1
- //#region src/refs.d.ts
2
- interface RefEntry {
3
- readonly hash: string;
4
- readonly invariants: readonly string[];
5
- }
6
- type Refs = Readonly<Record<string, RefEntry>>;
7
- declare function validateRefName(name: string): boolean;
8
- declare function validateRefValue(value: string): boolean;
9
- declare function readRef(refsDir: string, name: string): Promise<RefEntry>;
10
- declare function readRefs(refsDir: string): Promise<Refs>;
11
- declare function writeRef(refsDir: string, name: string, entry: RefEntry): Promise<void>;
12
- declare function deleteRef(refsDir: string, name: string): Promise<void>;
13
- declare function resolveRef(refs: Refs, name: string): RefEntry;
14
- //#endregion
15
- export { type RefEntry, type Refs, deleteRef, readRef, readRefs, resolveRef, validateRefName, validateRefValue, writeRef };
16
- //# sourceMappingURL=refs.d.mts.map
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 };