@prisma-next/migration-tools 0.11.0-dev.56 → 0.11.0-dev.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{errors-4YabujxZ.mjs → errors-vFROOhCR.mjs} +33 -2
- package/dist/{errors-4YabujxZ.mjs.map → errors-vFROOhCR.mjs.map} +1 -1
- package/dist/exports/aggregate.d.mts +37 -9
- package/dist/exports/aggregate.d.mts.map +1 -1
- package/dist/exports/aggregate.mjs +133 -17
- package/dist/exports/aggregate.mjs.map +1 -1
- package/dist/exports/enumerate-migration-spaces.d.mts +1 -1
- package/dist/exports/enumerate-migration-spaces.mjs +3 -3
- package/dist/exports/errors.mjs +1 -1
- package/dist/exports/graph.d.mts +1 -1
- package/dist/exports/hash.d.mts +2 -2
- package/dist/exports/invariants.d.mts +1 -1
- package/dist/exports/invariants.mjs +1 -1
- package/dist/exports/io.d.mts +1 -1
- package/dist/exports/io.mjs +1 -1
- package/dist/exports/metadata.d.mts +1 -1
- package/dist/exports/migration-graph.d.mts +2 -2
- package/dist/exports/migration-graph.mjs +2 -15
- package/dist/exports/migration-list-graph-topology.d.mts +1 -1
- package/dist/exports/migration-list-types.d.mts +1 -1
- package/dist/exports/migration.d.mts +1 -1
- package/dist/exports/migration.mjs +2 -2
- package/dist/exports/package.d.mts +1 -1
- package/dist/exports/ref-resolution.d.mts +2 -2
- package/dist/exports/ref-resolution.mjs +1 -1
- package/dist/exports/refs.d.mts +1 -1
- package/dist/exports/refs.mjs +2 -136
- package/dist/exports/spaces.d.mts +2 -2
- package/dist/exports/spaces.mjs +5 -5
- package/dist/{graph-BUZuUeBC.d.mts → graph-BwjwIZmb.d.mts} +1 -1
- package/dist/{graph-BUZuUeBC.d.mts.map → graph-BwjwIZmb.d.mts.map} +1 -1
- package/dist/graph-membership-BV23F1IV.mjs +15 -0
- package/dist/graph-membership-BV23F1IV.mjs.map +1 -0
- package/dist/{invariants-CCOAyg6c.mjs → invariants-C23nXy1c.mjs} +2 -2
- package/dist/{invariants-CCOAyg6c.mjs.map → invariants-C23nXy1c.mjs.map} +1 -1
- package/dist/{io-BHl0amF0.mjs → io-BGlPOt9b.mjs} +3 -3
- package/dist/{io-BHl0amF0.mjs.map → io-BGlPOt9b.mjs.map} +1 -1
- package/dist/{io-nqFXSSTN.d.mts → io-g7fQCYNJ.d.mts} +2 -2
- package/dist/{io-nqFXSSTN.d.mts.map → io-g7fQCYNJ.d.mts.map} +1 -1
- package/dist/{migration-graph-kGBkIZDa.mjs → migration-graph-BMAqSfv9.mjs} +2 -2
- package/dist/{migration-graph-kGBkIZDa.mjs.map → migration-graph-BMAqSfv9.mjs.map} +1 -1
- package/dist/{migration-graph-DtNT-cqc.d.mts → migration-graph-CC7PSXw0.d.mts} +3 -3
- package/dist/{migration-graph-DtNT-cqc.d.mts.map → migration-graph-CC7PSXw0.d.mts.map} +1 -1
- package/dist/{migration-list-types-BRTuXR8i.d.mts → migration-list-types-B8NY0jQ1.d.mts} +1 -1
- package/dist/{migration-list-types-BRTuXR8i.d.mts.map → migration-list-types-B8NY0jQ1.d.mts.map} +1 -1
- package/dist/{package-DIttKL7X.d.mts → package-C31VGBCK.d.mts} +1 -1
- package/dist/{package-DIttKL7X.d.mts.map → package-C31VGBCK.d.mts.map} +1 -1
- package/dist/{read-contract-space-contract-BS5Oxbgw.mjs → read-contract-space-contract-BbcST3Lm.mjs} +3 -3
- package/dist/{read-contract-space-contract-BS5Oxbgw.mjs.map → read-contract-space-contract-BbcST3Lm.mjs.map} +1 -1
- package/dist/{refs-C8f2IGM8.d.mts → refs-BPYU-r14.d.mts} +1 -1
- package/dist/{refs-C8f2IGM8.d.mts.map → refs-BPYU-r14.d.mts.map} +1 -1
- package/dist/{refs-BBKNL45K.mjs → refs-Ditzcs06.mjs} +2 -2
- package/dist/{refs-BBKNL45K.mjs.map → refs-Ditzcs06.mjs.map} +1 -1
- package/dist/snapshot-CVg78oBp.mjs +137 -0
- package/dist/snapshot-CVg78oBp.mjs.map +1 -0
- package/dist/{verify-contract-spaces-BJX5gqtD.mjs → verify-contract-spaces-3u7gzhqT.mjs} +3 -3
- package/dist/{verify-contract-spaces-BJX5gqtD.mjs.map → verify-contract-spaces-3u7gzhqT.mjs.map} +1 -1
- package/dist/{verify-contract-spaces-T0aiJlBS.d.mts → verify-contract-spaces-C7EZktZP.d.mts} +1 -1
- package/dist/{verify-contract-spaces-T0aiJlBS.d.mts.map → verify-contract-spaces-C7EZktZP.d.mts.map} +1 -1
- package/package.json +6 -6
- package/src/aggregate/aggregate.ts +184 -8
- package/src/aggregate/loader.ts +6 -1
- package/src/aggregate/types.ts +27 -0
- package/src/errors.ts +41 -0
- package/src/exports/aggregate.ts +6 -1
- package/dist/exports/migration-graph.mjs.map +0 -1
- package/dist/exports/refs.mjs.map +0 -1
- /package/dist/{metadata-Bp9X04gM.d.mts → metadata-CH3tNNkp.d.mts} +0 -0
|
@@ -261,6 +261,37 @@ function errorMigrationHashMismatch(dir, storedHash, computedHash) {
|
|
|
261
261
|
}
|
|
262
262
|
});
|
|
263
263
|
}
|
|
264
|
+
function errorSnapshotMissing(refName) {
|
|
265
|
+
return new MigrationToolsError("MIGRATION.SNAPSHOT_MISSING", `Ref "${refName}" has no paired contract snapshot`, {
|
|
266
|
+
why: `Ref "${refName}" exists but its paired snapshot files are missing.`,
|
|
267
|
+
fix: `Run "prisma-next db update --advance-ref ${refName}" to repopulate the snapshot, or "prisma-next ref delete ${refName}" to clear the orphan pointer.`,
|
|
268
|
+
details: {
|
|
269
|
+
refName,
|
|
270
|
+
identifier: refName,
|
|
271
|
+
viaRef: true
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
function errorBundleNotFoundForGraphNode(hash, explicitLabel) {
|
|
276
|
+
return new MigrationToolsError("MIGRATION.BUNDLE_NOT_FOUND_FOR_GRAPH_NODE", explicitLabel ? `No migration bundle found for reference "${explicitLabel}" (resolved hash: ${hash})` : `No migration bundle found for graph node ${hash}`, {
|
|
277
|
+
why: `The hash ${hash} is a graph node but no on-disk migration package has an end-contract hash matching it.`,
|
|
278
|
+
fix: "Provide a ref or hash that corresponds to an existing migration package, or run `migration list` to see available migrations.",
|
|
279
|
+
details: {
|
|
280
|
+
hash,
|
|
281
|
+
...explicitLabel ? { explicitLabel } : {}
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
function errorContractDeserializationFailed(filePath, message) {
|
|
286
|
+
return new MigrationToolsError("MIGRATION.CONTRACT_DESERIALIZATION_FAILED", "Contract failed to deserialize", {
|
|
287
|
+
why: `Contract at "${filePath}" failed to deserialize: ${message}`,
|
|
288
|
+
fix: reemitHint(dirname(filePath), "or restore the directory from version control."),
|
|
289
|
+
details: {
|
|
290
|
+
filePath,
|
|
291
|
+
message
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}
|
|
264
295
|
function errorHashNotInGraph(hash, graph) {
|
|
265
296
|
const reachableHashes = [...graph.nodes].sort();
|
|
266
297
|
const reachableList = reachableHashes.length > 0 ? reachableHashes.join(", ") : "(none)";
|
|
@@ -274,6 +305,6 @@ function errorHashNotInGraph(hash, graph) {
|
|
|
274
305
|
});
|
|
275
306
|
}
|
|
276
307
|
//#endregion
|
|
277
|
-
export {
|
|
308
|
+
export { errorNoInvariantPath as C, errorUnknownInvariant as D, errorSnapshotMissing as E, errorNoInitialMigration as S, errorProvidedInvariantsMismatch as T, errorInvalidRefValue as _, errorDescriptorHeadHashMismatch as a, errorMigrationHashMismatch as b, errorDuplicateSpaceId as c, errorInvalidInvariantId as d, errorInvalidJson as f, errorInvalidRefName as g, errorInvalidRefFile as h, errorContractDeserializationFailed as i, errorHashNotInGraph as l, errorInvalidOperationEntry as m, errorAmbiguousTarget as n, errorDirectoryExists as o, errorInvalidManifest as p, errorBundleNotFoundForGraphNode as r, errorDuplicateInvariantInEdge as s, MigrationToolsError as t, errorInvalidDestName as u, errorInvalidSlug as v, errorNoTarget as w, errorMissingFile as x, errorInvalidSpaceId as y };
|
|
278
309
|
|
|
279
|
-
//# sourceMappingURL=errors-
|
|
310
|
+
//# sourceMappingURL=errors-vFROOhCR.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-4YabujxZ.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import { ifDefined } from '@prisma-next/utils/defined';\nimport { basename, dirname, relative } from 'pathe';\nimport type { MigrationGraph } from './graph';\n\n/**\n * Build the canonical \"re-emit this package\" remediation hint.\n *\n * Every on-disk migration package ships its own `migration.ts` author-time\n * file. Running it regenerates `migration.json` and `ops.json` with the\n * correct hash + metadata, so it is the right primitive whenever a single\n * package's on-disk artifacts are missing, malformed, or otherwise corrupt.\n * Pointing users at `migration plan` would emit a *new* package rather than\n * heal the broken one.\n */\nfunction reemitHint(dir: string, fallback?: string): string {\n const relativeDir = relative(process.cwd(), dir);\n const reemit = `Re-emit the package by running \\`node \"${relativeDir}/migration.ts\"\\``;\n return fallback ? `${reemit}, ${fallback}` : `${reemit}.`;\n}\n\n/**\n * Structured error for migration tooling operations.\n *\n * Follows the NAMESPACE.SUBCODE convention from ADR 027. All codes live under\n * the MIGRATION namespace. These are tooling-time errors (file I/O, hash\n * verification, migration history reconstruction), distinct from the runtime\n * MIGRATION.* codes for apply-time failures (PRECHECK_FAILED, POSTCHECK_FAILED,\n * etc.).\n *\n * Fields:\n * - code: Stable machine-readable code (MIGRATION.SUBCODE)\n * - category: Always 'MIGRATION'\n * - why: Explains the cause in plain language\n * - fix: Actionable remediation step\n * - details: Machine-readable structured data for agents\n */\nexport class MigrationToolsError extends Error {\n readonly code: string;\n readonly category = 'MIGRATION' as const;\n readonly why: string;\n readonly fix: string;\n readonly details: Record<string, unknown> | undefined;\n\n constructor(\n code: string,\n summary: string,\n options: {\n readonly why: string;\n readonly fix: string;\n readonly details?: Record<string, unknown>;\n },\n ) {\n super(summary);\n this.name = 'MigrationToolsError';\n this.code = code;\n this.why = options.why;\n this.fix = options.fix;\n this.details = options.details;\n }\n\n static is(error: unknown): error is MigrationToolsError {\n if (!(error instanceof Error)) return false;\n const candidate = error as MigrationToolsError;\n return candidate.name === 'MigrationToolsError' && typeof candidate.code === 'string';\n }\n}\n\nexport function errorDirectoryExists(dir: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.DIR_EXISTS', 'Migration directory already exists', {\n why: `The directory \"${dir}\" already exists. Each migration must have a unique directory.`,\n fix: 'Use --name to pick a different name, or delete the existing directory and re-run.',\n details: { dir },\n });\n}\n\nexport function errorMissingFile(file: string, dir: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.FILE_MISSING', `Missing ${file}`, {\n why: `Expected \"${file}\" in \"${dir}\" but the file does not exist.`,\n fix: reemitHint(\n dir,\n 'or delete the directory if the migration is unwanted and the source TypeScript is gone.',\n ),\n details: { file, dir },\n });\n}\n\nexport function errorInvalidJson(filePath: string, parseError: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_JSON', 'Invalid JSON in migration file', {\n why: `Failed to parse \"${filePath}\": ${parseError}`,\n fix: reemitHint(dirname(filePath), 'or restore the directory from version control.'),\n details: { filePath, parseError },\n });\n}\n\nexport function errorInvalidManifest(filePath: string, reason: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_MANIFEST', 'Invalid migration manifest', {\n why: `Migration manifest at \"${filePath}\" is invalid: ${reason}`,\n fix: reemitHint(dirname(filePath), 'or restore the directory from version control.'),\n details: { filePath, reason },\n });\n}\n\nexport function errorInvalidOperationEntry(index: number, reason: string): MigrationToolsError {\n return new MigrationToolsError(\n 'MIGRATION.INVALID_OPERATION_ENTRY',\n 'Migration operation entry is malformed',\n {\n why: `Operation at index ${index} returned by the migration class failed schema validation: ${reason}.`,\n fix: \"Update the migration class so each entry of `operations` carries `id` (string), `label` (string), and `operationClass` (one of 'additive' | 'widening' | 'destructive' | 'data').\",\n details: { index, reason },\n },\n );\n}\n\nexport function errorInvalidSlug(slug: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_NAME', 'Invalid migration name', {\n why: `The slug \"${slug}\" contains no valid characters after sanitization (only a-z, 0-9 are kept).`,\n fix: 'Provide a name with at least one alphanumeric character, e.g. --name add_users.',\n details: { slug },\n });\n}\n\nexport function errorInvalidDestName(destName: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_DEST_NAME', 'Invalid copy destination name', {\n why: `The destination name \"${destName}\" must be a single path segment (no \"..\" or directory separators).`,\n fix: 'Use a simple file name such as \"contract.json\" for each destination in the copy list.',\n details: { destName },\n });\n}\n\nexport function errorInvalidSpaceId(spaceId: string): MigrationToolsError {\n return new MigrationToolsError(\n 'MIGRATION.INVALID_SPACE_ID',\n 'Invalid contract space identifier',\n {\n why: `The space id \"${spaceId}\" does not match the required pattern /^[a-z][a-z0-9_-]{0,63}$/. Space ids are used as filesystem directory names under \\`migrations/\\`, so the pattern is conservative on purpose.`,\n fix: 'Pick a lowercase identifier that begins with a letter and contains only lowercase letters, digits, hyphens, or underscores; max 64 characters total.',\n details: { spaceId },\n },\n );\n}\n\nexport function errorDescriptorHeadHashMismatch(args: {\n readonly extensionId: string;\n readonly recomputedHash: string;\n readonly headRefHash: string;\n}): MigrationToolsError {\n const { extensionId, recomputedHash, headRefHash } = args;\n return new MigrationToolsError(\n 'MIGRATION.DESCRIPTOR_HEAD_HASH_MISMATCH',\n \"Extension descriptor's headRef.hash does not match its contractJson\",\n {\n why: `Extension \"${extensionId}\" publishes a \\`contractSpace\\` whose \\`headRef.hash\\` (${headRefHash}) does not match the canonical hash recomputed from \\`contractSpace.contractJson\\` (${recomputedHash}). This means the extension descriptor was published with stale \\`headRef.hash\\` — typically because the contract was bumped without rerunning the extension's emit pipeline.`,\n fix: 'Re-run the extension authoring pipeline so `contractJson.storage.storageHash` and `headRef.hash` agree, then republish the extension. If you are the extension author and you intentionally bumped `contractJson`, recompute and update `headRef.hash` (and refresh any on-disk migration metadata that derives from it).',\n details: { extensionId, recomputedHash, headRefHash },\n },\n );\n}\n\nexport function errorDuplicateSpaceId(spaceId: string): MigrationToolsError {\n return new MigrationToolsError(\n 'MIGRATION.DUPLICATE_SPACE_ID',\n 'Duplicate contract space identifier',\n {\n why: `The space id \"${spaceId}\" appears more than once in the per-space planner input. Each space id must be unique across the inputs (the per-space planner emits one output entry per id).`,\n fix: 'Deduplicate the inputs before passing them to `planAllSpaces` — typically by checking your `extensionPacks` declaration for repeated entries.',\n details: { spaceId },\n },\n );\n}\n\nexport function errorSameSourceAndTarget(dir: string, hash: string): MigrationToolsError {\n const dirName = basename(dir);\n return new MigrationToolsError(\n 'MIGRATION.SAME_SOURCE_AND_TARGET',\n 'Migration without data-transform operations has same source and target',\n {\n why: `Migration \"${dirName}\" has from === to === \"${hash}\" and declares no data-transform operations. Self-edges are only allowed when the migration runs at least one dataTransform — otherwise the migration is a no-op.`,\n fix: reemitHint(\n dir,\n 'and either change the contract so from ≠ to, add a dataTransform op, or delete the directory if the migration is unwanted.',\n ),\n details: { dirName, hash },\n },\n );\n}\n\nexport function errorAmbiguousTarget(\n branchTips: readonly string[],\n context?: {\n divergencePoint: string;\n branches: readonly {\n tip: string;\n edges: readonly { dirName: string; from: string; to: string }[];\n }[];\n },\n): MigrationToolsError {\n const divergenceInfo = context\n ? `\\nDivergence point: ${context.divergencePoint}\\nBranches:\\n${context.branches.map((b) => ` → ${b.tip} (${b.edges.length} edge(s): ${b.edges.map((e) => e.dirName).join(' → ') || 'direct'})`).join('\\n')}`\n : '';\n return new MigrationToolsError('MIGRATION.AMBIGUOUS_TARGET', 'Ambiguous migration target', {\n why: `The migration history has diverged into multiple branches: ${branchTips.join(', ')}. This typically happens when two developers plan migrations from the same starting point.${divergenceInfo}`,\n fix: 'Use `ref set <name> <hash>` to target a specific branch, delete one of the conflicting migration directories and re-run `migration plan`, or use --from <hash> to explicitly select a starting point.',\n details: {\n branchTips,\n ...(context ? { divergencePoint: context.divergencePoint, branches: context.branches } : {}),\n },\n });\n}\n\nexport function errorNoInitialMigration(nodes: readonly string[]): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.NO_INITIAL_MIGRATION', 'No initial migration found', {\n why: `No migration starts from the empty contract state (known hashes: ${nodes.join(', ')}). At least one migration must originate from the empty state.`,\n fix: 'Inspect the migrations directory for corrupted migration.json files. At least one migration must start from the empty contract hash.',\n details: { nodes },\n });\n}\n\nexport function errorInvalidRefs(refsPath: string, reason: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_REFS', 'Invalid refs.json', {\n why: `refs.json at \"${refsPath}\" is invalid: ${reason}`,\n fix: 'Ensure refs.json is a flat object mapping valid ref names to contract hash strings.',\n details: { path: refsPath, reason },\n });\n}\n\nexport function errorInvalidRefFile(filePath: string, reason: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_REF_FILE', 'Invalid ref file', {\n why: `Ref file at \"${filePath}\" is invalid: ${reason}`,\n fix: 'Ensure the ref file contains valid JSON with { \"hash\": \"sha256:<64 hex chars>\", \"invariants\": [\"...\"] }.',\n details: { path: filePath, reason },\n });\n}\n\nexport function errorInvalidRefName(refName: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_REF_NAME', 'Invalid ref name', {\n why: `Ref name \"${refName}\" is invalid. Names must be lowercase alphanumeric with hyphens or forward slashes (no \".\" or \"..\" segments).`,\n fix: `Use a valid ref name (e.g., \"staging\", \"envs/production\").`,\n details: { refName },\n });\n}\n\nexport function errorNoTarget(reachableHashes: readonly string[]): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.NO_TARGET', 'No migration target could be resolved', {\n why: `The migration history contains cycles and no target can be resolved automatically (reachable hashes: ${reachableHashes.join(', ')}). This typically happens after rollback migrations (e.g., C1→C2→C1).`,\n fix: 'Use --from <hash> to specify the planning origin explicitly.',\n details: { reachableHashes },\n });\n}\n\nexport function errorInvalidRefValue(value: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_REF_VALUE', 'Invalid ref value', {\n why: `Ref value \"${value}\" is not a valid contract hash. Values must be in the format \"sha256:<64 hex chars>\" or \"sha256:empty\".`,\n fix: 'Use a valid storage hash from `prisma-next contract emit` output or an existing migration.',\n details: { value },\n });\n}\n\nexport function errorDuplicateMigrationHash(migrationHash: string): MigrationToolsError {\n return new MigrationToolsError(\n 'MIGRATION.DUPLICATE_MIGRATION_HASH',\n 'Duplicate migrationHash in migration graph',\n {\n why: `Multiple migrations share migrationHash \"${migrationHash}\". Each migration must have a unique content-addressed identity.`,\n fix: 'Regenerate one of the conflicting migrations so each migrationHash is unique, then re-run migration commands.',\n details: { migrationHash },\n },\n );\n}\n\nexport function errorInvalidInvariantId(invariantId: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_INVARIANT_ID', 'Invalid invariantId', {\n why: `invariantId ${JSON.stringify(invariantId)} is invalid. Ids must be non-empty and contain no whitespace or control characters (including Unicode whitespace like NBSP); other content (kebab-case, camelCase, namespaced, Unicode letters) is allowed.`,\n fix: 'Pick an invariantId without spaces, tabs, newlines, or control characters — e.g. \"backfill-user-phone\", \"users/backfill-phone\", or \"BackfillUserPhone\".',\n details: { invariantId },\n });\n}\n\nexport function errorDuplicateInvariantInEdge(invariantId: string): MigrationToolsError {\n return new MigrationToolsError(\n 'MIGRATION.DUPLICATE_INVARIANT_IN_EDGE',\n 'Duplicate invariantId on a single migration',\n {\n why: `invariantId \"${invariantId}\" is declared by more than one dataTransform on the same migration. The marker stores invariants as a set and the routing layer treats them as edge-level, so two ops cannot share a routing identity.`,\n fix: 'Rename one of the conflicting dataTransform invariantIds, or drop invariantId on the op that does not need to be routing-visible.',\n details: { invariantId },\n },\n );\n}\n\nexport function errorProvidedInvariantsMismatch(\n filePath: string,\n stored: readonly string[],\n derived: readonly string[],\n): MigrationToolsError {\n const storedSet = new Set(stored);\n const derivedSet = new Set(derived);\n const missing = [...derivedSet].filter((id) => !storedSet.has(id));\n const extra = [...storedSet].filter((id) => !derivedSet.has(id));\n // When sets agree but arrays don't, the only difference is ordering — call\n // it out so the reader doesn't stare at two visually-identical arrays.\n // Canonical providedInvariants is sorted ascending; a manifest with the\n // same ids in a different order is still a mismatch (the hash check would\n // also fail), but the human-readable diagnostic is otherwise unhelpful.\n const orderingOnly = missing.length === 0 && extra.length === 0;\n const why = orderingOnly\n ? `migration.json at \"${filePath}\" stores providedInvariants ${JSON.stringify(stored)}, but the canonical value derived from ops.json is ${JSON.stringify(derived)} — same ids, different order. Canonical providedInvariants is sorted ascending.`\n : `migration.json at \"${filePath}\" stores providedInvariants ${JSON.stringify(stored)}, but the value derived from ops.json is ${JSON.stringify(derived)}. The manifest copy was likely hand-edited without re-emitting.`;\n return new MigrationToolsError(\n 'MIGRATION.PROVIDED_INVARIANTS_MISMATCH',\n 'providedInvariants on migration.json disagrees with ops.json',\n {\n why,\n fix: reemitHint(dirname(filePath), 'or restore the directory from version control.'),\n details: { filePath, stored, derived, difference: { missing, extra } },\n },\n );\n}\n\n/**\n * Wire-shape edge surfaced through the JSON envelope's\n * `meta.structuralPath` of `MIGRATION.NO_INVARIANT_PATH`. Slim by design —\n * authoring metadata (`createdAt`) lives on `MigrationEdge` but is\n * intentionally dropped here so the envelope stays stable across\n * graph-internal refactors.\n *\n * Stability: any field added here is part of the public CLI JSON contract.\n * Callers (CLI consumers, agents) must be able to treat\n * `(dirName, migrationHash, from, to, invariants)` as the canonical shape.\n */\nexport interface NoInvariantPathStructuralEdge {\n readonly dirName: string;\n readonly migrationHash: string;\n readonly from: string;\n readonly to: string;\n readonly invariants: readonly string[];\n}\n\nexport function errorNoInvariantPath(args: {\n readonly refName?: string;\n readonly required: readonly string[];\n readonly missing: readonly string[];\n readonly structuralPath: readonly NoInvariantPathStructuralEdge[];\n}): MigrationToolsError {\n const { refName, required, missing, structuralPath } = args;\n const refClause = refName ? `Ref \"${refName}\"` : 'Target';\n const missingList = missing.map((id) => JSON.stringify(id)).join(', ');\n const requiredList = required.map((id) => JSON.stringify(id)).join(', ');\n return new MigrationToolsError(\n 'MIGRATION.NO_INVARIANT_PATH',\n 'No path covers the required invariants',\n {\n why: `${refClause} requires invariants the reachable path doesn't cover. required=[${requiredList}], missing=[${missingList}].`,\n fix: 'Add a migration on the path that runs `dataTransform({ invariantId: \"<id>\", … })` for each missing invariant, or retarget the ref to a hash whose path already provides them.',\n details: {\n required,\n missing,\n structuralPath,\n ...ifDefined('refName', refName),\n },\n },\n );\n}\n\nexport function errorUnknownInvariant(args: {\n readonly refName?: string;\n readonly unknown: readonly string[];\n readonly declared: readonly string[];\n}): MigrationToolsError {\n const { refName, unknown, declared } = args;\n const refClause = refName ? `Ref \"${refName}\" declares` : 'Declares';\n const unknownList = unknown.map((id) => JSON.stringify(id)).join(', ');\n return new MigrationToolsError(\n 'MIGRATION.UNKNOWN_INVARIANT',\n 'Ref declares invariants no migration in the graph provides',\n {\n why: `${refClause} invariants no migration in the graph provides. unknown=[${unknownList}].`,\n fix: 'Either the ref has a typo, or the declaring migration has not been authored/attested yet. Re-check the ref file and the migrations directory.',\n details: {\n unknown,\n declared,\n ...ifDefined('refName', refName),\n },\n },\n );\n}\n\nexport function errorMigrationHashMismatch(\n dir: string,\n storedHash: string,\n computedHash: string,\n): MigrationToolsError {\n // Render a cwd-relative path in the human-readable diagnostic so users\n // running CLI commands from the project root see a familiar short path.\n // Keep the absolute path in `details.dir` for machine consumers.\n const relativeDir = relative(process.cwd(), dir);\n return new MigrationToolsError('MIGRATION.HASH_MISMATCH', 'Migration package is corrupt', {\n why: `Stored migrationHash \"${storedHash}\" does not match the recomputed hash \"${computedHash}\" for \"${relativeDir}\". The migration.json or ops.json has been edited or partially written since emit.`,\n fix: reemitHint(dir, 'or restore the directory from version control.'),\n details: { dir, storedHash, computedHash },\n });\n}\n\nexport function errorHashNotInGraph(hash: string, graph: MigrationGraph): MigrationToolsError {\n const reachableHashes = [...graph.nodes].sort();\n const reachableList = reachableHashes.length > 0 ? reachableHashes.join(', ') : '(none)';\n return new MigrationToolsError(\n 'MIGRATION.HASH_NOT_IN_GRAPH',\n `Hash \"${hash}\" is not a node in the migration graph`,\n {\n why: `The migration graph contains nodes ${reachableList}; \"${hash}\" isn't one of them.`,\n fix: `Pass a hash that's the from-or-to of an on-disk migration bundle, use --from with a graph-node hash, or run \"prisma-next migration plan\" to introduce it.`,\n details: { hash, reachableHashes },\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAS,WAAW,KAAa,UAA2B;CAE1D,MAAM,SAAS,0CADK,SAAS,QAAQ,IAAI,GAAG,GACuB,EAAE;CACrE,OAAO,WAAW,GAAG,OAAO,IAAI,aAAa,GAAG,OAAO;AACzD;;;;;;;;;;;;;;;;;AAkBA,IAAa,sBAAb,cAAyC,MAAM;CAC7C;CACA,WAAoB;CACpB;CACA;CACA;CAEA,YACE,MACA,SACA,SAKA;EACA,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,MAAM,QAAQ;EACnB,KAAK,MAAM,QAAQ;EACnB,KAAK,UAAU,QAAQ;CACzB;CAEA,OAAO,GAAG,OAA8C;EACtD,IAAI,EAAE,iBAAiB,QAAQ,OAAO;EACtC,MAAM,YAAY;EAClB,OAAO,UAAU,SAAS,yBAAyB,OAAO,UAAU,SAAS;CAC/E;AACF;AAEA,SAAgB,qBAAqB,KAAkC;CACrE,OAAO,IAAI,oBAAoB,wBAAwB,sCAAsC;EAC3F,KAAK,kBAAkB,IAAI;EAC3B,KAAK;EACL,SAAS,EAAE,IAAI;CACjB,CAAC;AACH;AAEA,SAAgB,iBAAiB,MAAc,KAAkC;CAC/E,OAAO,IAAI,oBAAoB,0BAA0B,WAAW,QAAQ;EAC1E,KAAK,aAAa,KAAK,QAAQ,IAAI;EACnC,KAAK,WACH,KACA,yFACF;EACA,SAAS;GAAE;GAAM;EAAI;CACvB,CAAC;AACH;AAEA,SAAgB,iBAAiB,UAAkB,YAAyC;CAC1F,OAAO,IAAI,oBAAoB,0BAA0B,kCAAkC;EACzF,KAAK,oBAAoB,SA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errors.ts"],"sourcesContent":["import { ifDefined } from '@prisma-next/utils/defined';\nimport { basename, dirname, relative } from 'pathe';\nimport type { MigrationGraph } from './graph';\n\n/**\n * Build the canonical \"re-emit this package\" remediation hint.\n *\n * Every on-disk migration package ships its own `migration.ts` author-time\n * file. Running it regenerates `migration.json` and `ops.json` with the\n * correct hash + metadata, so it is the right primitive whenever a single\n * package's on-disk artifacts are missing, malformed, or otherwise corrupt.\n * Pointing users at `migration plan` would emit a *new* package rather than\n * heal the broken one.\n */\nfunction reemitHint(dir: string, fallback?: string): string {\n const relativeDir = relative(process.cwd(), dir);\n const reemit = `Re-emit the package by running \\`node \"${relativeDir}/migration.ts\"\\``;\n return fallback ? `${reemit}, ${fallback}` : `${reemit}.`;\n}\n\n/**\n * Structured error for migration tooling operations.\n *\n * Follows the NAMESPACE.SUBCODE convention from ADR 027. All codes live under\n * the MIGRATION namespace. These are tooling-time errors (file I/O, hash\n * verification, migration history reconstruction), distinct from the runtime\n * MIGRATION.* codes for apply-time failures (PRECHECK_FAILED, POSTCHECK_FAILED,\n * etc.).\n *\n * Fields:\n * - code: Stable machine-readable code (MIGRATION.SUBCODE)\n * - category: Always 'MIGRATION'\n * - why: Explains the cause in plain language\n * - fix: Actionable remediation step\n * - details: Machine-readable structured data for agents\n */\nexport class MigrationToolsError extends Error {\n readonly code: string;\n readonly category = 'MIGRATION' as const;\n readonly why: string;\n readonly fix: string;\n readonly details: Record<string, unknown> | undefined;\n\n constructor(\n code: string,\n summary: string,\n options: {\n readonly why: string;\n readonly fix: string;\n readonly details?: Record<string, unknown>;\n },\n ) {\n super(summary);\n this.name = 'MigrationToolsError';\n this.code = code;\n this.why = options.why;\n this.fix = options.fix;\n this.details = options.details;\n }\n\n static is(error: unknown): error is MigrationToolsError {\n if (!(error instanceof Error)) return false;\n const candidate = error as MigrationToolsError;\n return candidate.name === 'MigrationToolsError' && typeof candidate.code === 'string';\n }\n}\n\nexport function errorDirectoryExists(dir: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.DIR_EXISTS', 'Migration directory already exists', {\n why: `The directory \"${dir}\" already exists. Each migration must have a unique directory.`,\n fix: 'Use --name to pick a different name, or delete the existing directory and re-run.',\n details: { dir },\n });\n}\n\nexport function errorMissingFile(file: string, dir: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.FILE_MISSING', `Missing ${file}`, {\n why: `Expected \"${file}\" in \"${dir}\" but the file does not exist.`,\n fix: reemitHint(\n dir,\n 'or delete the directory if the migration is unwanted and the source TypeScript is gone.',\n ),\n details: { file, dir },\n });\n}\n\nexport function errorInvalidJson(filePath: string, parseError: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_JSON', 'Invalid JSON in migration file', {\n why: `Failed to parse \"${filePath}\": ${parseError}`,\n fix: reemitHint(dirname(filePath), 'or restore the directory from version control.'),\n details: { filePath, parseError },\n });\n}\n\nexport function errorInvalidManifest(filePath: string, reason: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_MANIFEST', 'Invalid migration manifest', {\n why: `Migration manifest at \"${filePath}\" is invalid: ${reason}`,\n fix: reemitHint(dirname(filePath), 'or restore the directory from version control.'),\n details: { filePath, reason },\n });\n}\n\nexport function errorInvalidOperationEntry(index: number, reason: string): MigrationToolsError {\n return new MigrationToolsError(\n 'MIGRATION.INVALID_OPERATION_ENTRY',\n 'Migration operation entry is malformed',\n {\n why: `Operation at index ${index} returned by the migration class failed schema validation: ${reason}.`,\n fix: \"Update the migration class so each entry of `operations` carries `id` (string), `label` (string), and `operationClass` (one of 'additive' | 'widening' | 'destructive' | 'data').\",\n details: { index, reason },\n },\n );\n}\n\nexport function errorInvalidSlug(slug: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_NAME', 'Invalid migration name', {\n why: `The slug \"${slug}\" contains no valid characters after sanitization (only a-z, 0-9 are kept).`,\n fix: 'Provide a name with at least one alphanumeric character, e.g. --name add_users.',\n details: { slug },\n });\n}\n\nexport function errorInvalidDestName(destName: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_DEST_NAME', 'Invalid copy destination name', {\n why: `The destination name \"${destName}\" must be a single path segment (no \"..\" or directory separators).`,\n fix: 'Use a simple file name such as \"contract.json\" for each destination in the copy list.',\n details: { destName },\n });\n}\n\nexport function errorInvalidSpaceId(spaceId: string): MigrationToolsError {\n return new MigrationToolsError(\n 'MIGRATION.INVALID_SPACE_ID',\n 'Invalid contract space identifier',\n {\n why: `The space id \"${spaceId}\" does not match the required pattern /^[a-z][a-z0-9_-]{0,63}$/. Space ids are used as filesystem directory names under \\`migrations/\\`, so the pattern is conservative on purpose.`,\n fix: 'Pick a lowercase identifier that begins with a letter and contains only lowercase letters, digits, hyphens, or underscores; max 64 characters total.',\n details: { spaceId },\n },\n );\n}\n\nexport function errorDescriptorHeadHashMismatch(args: {\n readonly extensionId: string;\n readonly recomputedHash: string;\n readonly headRefHash: string;\n}): MigrationToolsError {\n const { extensionId, recomputedHash, headRefHash } = args;\n return new MigrationToolsError(\n 'MIGRATION.DESCRIPTOR_HEAD_HASH_MISMATCH',\n \"Extension descriptor's headRef.hash does not match its contractJson\",\n {\n why: `Extension \"${extensionId}\" publishes a \\`contractSpace\\` whose \\`headRef.hash\\` (${headRefHash}) does not match the canonical hash recomputed from \\`contractSpace.contractJson\\` (${recomputedHash}). This means the extension descriptor was published with stale \\`headRef.hash\\` — typically because the contract was bumped without rerunning the extension's emit pipeline.`,\n fix: 'Re-run the extension authoring pipeline so `contractJson.storage.storageHash` and `headRef.hash` agree, then republish the extension. If you are the extension author and you intentionally bumped `contractJson`, recompute and update `headRef.hash` (and refresh any on-disk migration metadata that derives from it).',\n details: { extensionId, recomputedHash, headRefHash },\n },\n );\n}\n\nexport function errorDuplicateSpaceId(spaceId: string): MigrationToolsError {\n return new MigrationToolsError(\n 'MIGRATION.DUPLICATE_SPACE_ID',\n 'Duplicate contract space identifier',\n {\n why: `The space id \"${spaceId}\" appears more than once in the per-space planner input. Each space id must be unique across the inputs (the per-space planner emits one output entry per id).`,\n fix: 'Deduplicate the inputs before passing them to `planAllSpaces` — typically by checking your `extensionPacks` declaration for repeated entries.',\n details: { spaceId },\n },\n );\n}\n\nexport function errorSameSourceAndTarget(dir: string, hash: string): MigrationToolsError {\n const dirName = basename(dir);\n return new MigrationToolsError(\n 'MIGRATION.SAME_SOURCE_AND_TARGET',\n 'Migration without data-transform operations has same source and target',\n {\n why: `Migration \"${dirName}\" has from === to === \"${hash}\" and declares no data-transform operations. Self-edges are only allowed when the migration runs at least one dataTransform — otherwise the migration is a no-op.`,\n fix: reemitHint(\n dir,\n 'and either change the contract so from ≠ to, add a dataTransform op, or delete the directory if the migration is unwanted.',\n ),\n details: { dirName, hash },\n },\n );\n}\n\nexport function errorAmbiguousTarget(\n branchTips: readonly string[],\n context?: {\n divergencePoint: string;\n branches: readonly {\n tip: string;\n edges: readonly { dirName: string; from: string; to: string }[];\n }[];\n },\n): MigrationToolsError {\n const divergenceInfo = context\n ? `\\nDivergence point: ${context.divergencePoint}\\nBranches:\\n${context.branches.map((b) => ` → ${b.tip} (${b.edges.length} edge(s): ${b.edges.map((e) => e.dirName).join(' → ') || 'direct'})`).join('\\n')}`\n : '';\n return new MigrationToolsError('MIGRATION.AMBIGUOUS_TARGET', 'Ambiguous migration target', {\n why: `The migration history has diverged into multiple branches: ${branchTips.join(', ')}. This typically happens when two developers plan migrations from the same starting point.${divergenceInfo}`,\n fix: 'Use `ref set <name> <hash>` to target a specific branch, delete one of the conflicting migration directories and re-run `migration plan`, or use --from <hash> to explicitly select a starting point.',\n details: {\n branchTips,\n ...(context ? { divergencePoint: context.divergencePoint, branches: context.branches } : {}),\n },\n });\n}\n\nexport function errorNoInitialMigration(nodes: readonly string[]): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.NO_INITIAL_MIGRATION', 'No initial migration found', {\n why: `No migration starts from the empty contract state (known hashes: ${nodes.join(', ')}). At least one migration must originate from the empty state.`,\n fix: 'Inspect the migrations directory for corrupted migration.json files. At least one migration must start from the empty contract hash.',\n details: { nodes },\n });\n}\n\nexport function errorInvalidRefs(refsPath: string, reason: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_REFS', 'Invalid refs.json', {\n why: `refs.json at \"${refsPath}\" is invalid: ${reason}`,\n fix: 'Ensure refs.json is a flat object mapping valid ref names to contract hash strings.',\n details: { path: refsPath, reason },\n });\n}\n\nexport function errorInvalidRefFile(filePath: string, reason: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_REF_FILE', 'Invalid ref file', {\n why: `Ref file at \"${filePath}\" is invalid: ${reason}`,\n fix: 'Ensure the ref file contains valid JSON with { \"hash\": \"sha256:<64 hex chars>\", \"invariants\": [\"...\"] }.',\n details: { path: filePath, reason },\n });\n}\n\nexport function errorInvalidRefName(refName: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_REF_NAME', 'Invalid ref name', {\n why: `Ref name \"${refName}\" is invalid. Names must be lowercase alphanumeric with hyphens or forward slashes (no \".\" or \"..\" segments).`,\n fix: `Use a valid ref name (e.g., \"staging\", \"envs/production\").`,\n details: { refName },\n });\n}\n\nexport function errorNoTarget(reachableHashes: readonly string[]): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.NO_TARGET', 'No migration target could be resolved', {\n why: `The migration history contains cycles and no target can be resolved automatically (reachable hashes: ${reachableHashes.join(', ')}). This typically happens after rollback migrations (e.g., C1→C2→C1).`,\n fix: 'Use --from <hash> to specify the planning origin explicitly.',\n details: { reachableHashes },\n });\n}\n\nexport function errorInvalidRefValue(value: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_REF_VALUE', 'Invalid ref value', {\n why: `Ref value \"${value}\" is not a valid contract hash. Values must be in the format \"sha256:<64 hex chars>\" or \"sha256:empty\".`,\n fix: 'Use a valid storage hash from `prisma-next contract emit` output or an existing migration.',\n details: { value },\n });\n}\n\nexport function errorDuplicateMigrationHash(migrationHash: string): MigrationToolsError {\n return new MigrationToolsError(\n 'MIGRATION.DUPLICATE_MIGRATION_HASH',\n 'Duplicate migrationHash in migration graph',\n {\n why: `Multiple migrations share migrationHash \"${migrationHash}\". Each migration must have a unique content-addressed identity.`,\n fix: 'Regenerate one of the conflicting migrations so each migrationHash is unique, then re-run migration commands.',\n details: { migrationHash },\n },\n );\n}\n\nexport function errorInvalidInvariantId(invariantId: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_INVARIANT_ID', 'Invalid invariantId', {\n why: `invariantId ${JSON.stringify(invariantId)} is invalid. Ids must be non-empty and contain no whitespace or control characters (including Unicode whitespace like NBSP); other content (kebab-case, camelCase, namespaced, Unicode letters) is allowed.`,\n fix: 'Pick an invariantId without spaces, tabs, newlines, or control characters — e.g. \"backfill-user-phone\", \"users/backfill-phone\", or \"BackfillUserPhone\".',\n details: { invariantId },\n });\n}\n\nexport function errorDuplicateInvariantInEdge(invariantId: string): MigrationToolsError {\n return new MigrationToolsError(\n 'MIGRATION.DUPLICATE_INVARIANT_IN_EDGE',\n 'Duplicate invariantId on a single migration',\n {\n why: `invariantId \"${invariantId}\" is declared by more than one dataTransform on the same migration. The marker stores invariants as a set and the routing layer treats them as edge-level, so two ops cannot share a routing identity.`,\n fix: 'Rename one of the conflicting dataTransform invariantIds, or drop invariantId on the op that does not need to be routing-visible.',\n details: { invariantId },\n },\n );\n}\n\nexport function errorProvidedInvariantsMismatch(\n filePath: string,\n stored: readonly string[],\n derived: readonly string[],\n): MigrationToolsError {\n const storedSet = new Set(stored);\n const derivedSet = new Set(derived);\n const missing = [...derivedSet].filter((id) => !storedSet.has(id));\n const extra = [...storedSet].filter((id) => !derivedSet.has(id));\n // When sets agree but arrays don't, the only difference is ordering — call\n // it out so the reader doesn't stare at two visually-identical arrays.\n // Canonical providedInvariants is sorted ascending; a manifest with the\n // same ids in a different order is still a mismatch (the hash check would\n // also fail), but the human-readable diagnostic is otherwise unhelpful.\n const orderingOnly = missing.length === 0 && extra.length === 0;\n const why = orderingOnly\n ? `migration.json at \"${filePath}\" stores providedInvariants ${JSON.stringify(stored)}, but the canonical value derived from ops.json is ${JSON.stringify(derived)} — same ids, different order. Canonical providedInvariants is sorted ascending.`\n : `migration.json at \"${filePath}\" stores providedInvariants ${JSON.stringify(stored)}, but the value derived from ops.json is ${JSON.stringify(derived)}. The manifest copy was likely hand-edited without re-emitting.`;\n return new MigrationToolsError(\n 'MIGRATION.PROVIDED_INVARIANTS_MISMATCH',\n 'providedInvariants on migration.json disagrees with ops.json',\n {\n why,\n fix: reemitHint(dirname(filePath), 'or restore the directory from version control.'),\n details: { filePath, stored, derived, difference: { missing, extra } },\n },\n );\n}\n\n/**\n * Wire-shape edge surfaced through the JSON envelope's\n * `meta.structuralPath` of `MIGRATION.NO_INVARIANT_PATH`. Slim by design —\n * authoring metadata (`createdAt`) lives on `MigrationEdge` but is\n * intentionally dropped here so the envelope stays stable across\n * graph-internal refactors.\n *\n * Stability: any field added here is part of the public CLI JSON contract.\n * Callers (CLI consumers, agents) must be able to treat\n * `(dirName, migrationHash, from, to, invariants)` as the canonical shape.\n */\nexport interface NoInvariantPathStructuralEdge {\n readonly dirName: string;\n readonly migrationHash: string;\n readonly from: string;\n readonly to: string;\n readonly invariants: readonly string[];\n}\n\nexport function errorNoInvariantPath(args: {\n readonly refName?: string;\n readonly required: readonly string[];\n readonly missing: readonly string[];\n readonly structuralPath: readonly NoInvariantPathStructuralEdge[];\n}): MigrationToolsError {\n const { refName, required, missing, structuralPath } = args;\n const refClause = refName ? `Ref \"${refName}\"` : 'Target';\n const missingList = missing.map((id) => JSON.stringify(id)).join(', ');\n const requiredList = required.map((id) => JSON.stringify(id)).join(', ');\n return new MigrationToolsError(\n 'MIGRATION.NO_INVARIANT_PATH',\n 'No path covers the required invariants',\n {\n why: `${refClause} requires invariants the reachable path doesn't cover. required=[${requiredList}], missing=[${missingList}].`,\n fix: 'Add a migration on the path that runs `dataTransform({ invariantId: \"<id>\", … })` for each missing invariant, or retarget the ref to a hash whose path already provides them.',\n details: {\n required,\n missing,\n structuralPath,\n ...ifDefined('refName', refName),\n },\n },\n );\n}\n\nexport function errorUnknownInvariant(args: {\n readonly refName?: string;\n readonly unknown: readonly string[];\n readonly declared: readonly string[];\n}): MigrationToolsError {\n const { refName, unknown, declared } = args;\n const refClause = refName ? `Ref \"${refName}\" declares` : 'Declares';\n const unknownList = unknown.map((id) => JSON.stringify(id)).join(', ');\n return new MigrationToolsError(\n 'MIGRATION.UNKNOWN_INVARIANT',\n 'Ref declares invariants no migration in the graph provides',\n {\n why: `${refClause} invariants no migration in the graph provides. unknown=[${unknownList}].`,\n fix: 'Either the ref has a typo, or the declaring migration has not been authored/attested yet. Re-check the ref file and the migrations directory.',\n details: {\n unknown,\n declared,\n ...ifDefined('refName', refName),\n },\n },\n );\n}\n\nexport function errorMigrationHashMismatch(\n dir: string,\n storedHash: string,\n computedHash: string,\n): MigrationToolsError {\n // Render a cwd-relative path in the human-readable diagnostic so users\n // running CLI commands from the project root see a familiar short path.\n // Keep the absolute path in `details.dir` for machine consumers.\n const relativeDir = relative(process.cwd(), dir);\n return new MigrationToolsError('MIGRATION.HASH_MISMATCH', 'Migration package is corrupt', {\n why: `Stored migrationHash \"${storedHash}\" does not match the recomputed hash \"${computedHash}\" for \"${relativeDir}\". The migration.json or ops.json has been edited or partially written since emit.`,\n fix: reemitHint(dir, 'or restore the directory from version control.'),\n details: { dir, storedHash, computedHash },\n });\n}\n\nexport function errorSnapshotMissing(refName: string): MigrationToolsError {\n return new MigrationToolsError(\n 'MIGRATION.SNAPSHOT_MISSING',\n `Ref \"${refName}\" has no paired contract snapshot`,\n {\n why: `Ref \"${refName}\" exists but its paired snapshot files are missing.`,\n fix: `Run \"prisma-next db update --advance-ref ${refName}\" to repopulate the snapshot, or \"prisma-next ref delete ${refName}\" to clear the orphan pointer.`,\n details: { refName, identifier: refName, viaRef: true },\n },\n );\n}\n\nexport function errorBundleNotFoundForGraphNode(\n hash: string,\n explicitLabel?: string,\n): MigrationToolsError {\n const summary = explicitLabel\n ? `No migration bundle found for reference \"${explicitLabel}\" (resolved hash: ${hash})`\n : `No migration bundle found for graph node ${hash}`;\n return new MigrationToolsError('MIGRATION.BUNDLE_NOT_FOUND_FOR_GRAPH_NODE', summary, {\n why: `The hash ${hash} is a graph node but no on-disk migration package has an end-contract hash matching it.`,\n fix: 'Provide a ref or hash that corresponds to an existing migration package, or run `migration list` to see available migrations.',\n details: { hash, ...(explicitLabel ? { explicitLabel } : {}) },\n });\n}\n\nexport function errorContractDeserializationFailed(\n filePath: string,\n message: string,\n): MigrationToolsError {\n return new MigrationToolsError(\n 'MIGRATION.CONTRACT_DESERIALIZATION_FAILED',\n 'Contract failed to deserialize',\n {\n why: `Contract at \"${filePath}\" failed to deserialize: ${message}`,\n fix: reemitHint(dirname(filePath), 'or restore the directory from version control.'),\n details: { filePath, message },\n },\n );\n}\n\nexport function errorHashNotInGraph(hash: string, graph: MigrationGraph): MigrationToolsError {\n const reachableHashes = [...graph.nodes].sort();\n const reachableList = reachableHashes.length > 0 ? reachableHashes.join(', ') : '(none)';\n return new MigrationToolsError(\n 'MIGRATION.HASH_NOT_IN_GRAPH',\n `Hash \"${hash}\" is not a node in the migration graph`,\n {\n why: `The migration graph contains nodes ${reachableList}; \"${hash}\" isn't one of them.`,\n fix: `Pass a hash that's the from-or-to of an on-disk migration bundle, use --from with a graph-node hash, or run \"prisma-next migration plan\" to introduce it.`,\n details: { hash, reachableHashes },\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAS,WAAW,KAAa,UAA2B;CAE1D,MAAM,SAAS,0CADK,SAAS,QAAQ,IAAI,GAAG,GACuB,EAAE;CACrE,OAAO,WAAW,GAAG,OAAO,IAAI,aAAa,GAAG,OAAO;AACzD;;;;;;;;;;;;;;;;;AAkBA,IAAa,sBAAb,cAAyC,MAAM;CAC7C;CACA,WAAoB;CACpB;CACA;CACA;CAEA,YACE,MACA,SACA,SAKA;EACA,MAAM,OAAO;EACb,KAAK,OAAO;E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;EACnE,KAAK;EACL,SAAS;GAAE;GAAM;EAAgB;CACnC,CACF;AACF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { n as OnDiskMigrationPackage } from "../package-
|
|
2
|
-
import { n as RefLoadProblem, r as Refs } from "../refs-
|
|
3
|
-
import { t as ContractSpaceHeadRecord } from "../verify-contract-spaces-
|
|
4
|
-
import { n as MigrationGraph } from "../graph-
|
|
5
|
-
import { t as PackageLoadProblem } from "../io-
|
|
6
|
-
import { t as PathDecision } from "../migration-graph-
|
|
1
|
+
import { n as OnDiskMigrationPackage } from "../package-C31VGBCK.mjs";
|
|
2
|
+
import { n as RefLoadProblem, r as Refs } from "../refs-BPYU-r14.mjs";
|
|
3
|
+
import { t as ContractSpaceHeadRecord } from "../verify-contract-spaces-C7EZktZP.mjs";
|
|
4
|
+
import { n as MigrationGraph } from "../graph-BwjwIZmb.mjs";
|
|
5
|
+
import { t as PackageLoadProblem } from "../io-g7fQCYNJ.mjs";
|
|
6
|
+
import { t as PathDecision } from "../migration-graph-CC7PSXw0.mjs";
|
|
7
7
|
import { ControlFamilyInstance, MigrationOperationPolicy, MigrationPlan, MigrationPlanOperation, MigrationPlannerConflict, TargetMigrationsCapability } from "@prisma-next/framework-components/control";
|
|
8
8
|
import { Result } from "@prisma-next/utils/result";
|
|
9
9
|
import { Contract } from "@prisma-next/contract/types";
|
|
@@ -125,6 +125,23 @@ interface IntegrityQueryOptions {
|
|
|
125
125
|
}
|
|
126
126
|
//#endregion
|
|
127
127
|
//#region src/aggregate/types.d.ts
|
|
128
|
+
interface ContractAtOptions {
|
|
129
|
+
readonly refName?: string;
|
|
130
|
+
}
|
|
131
|
+
type ContractAtResult = {
|
|
132
|
+
readonly provenance: 'snapshot';
|
|
133
|
+
readonly hash: string;
|
|
134
|
+
readonly contractJson: unknown;
|
|
135
|
+
readonly contractDts: string;
|
|
136
|
+
readonly contract: Contract;
|
|
137
|
+
} | {
|
|
138
|
+
readonly provenance: 'graph-node';
|
|
139
|
+
readonly sourceDir: string;
|
|
140
|
+
readonly hash: string;
|
|
141
|
+
readonly contractJson: unknown;
|
|
142
|
+
readonly contractDts: string;
|
|
143
|
+
readonly contract: Contract;
|
|
144
|
+
};
|
|
128
145
|
/**
|
|
129
146
|
* One contract space — app or extension — as a member of a
|
|
130
147
|
* {@link ContractSpaceAggregate}. Every member has the same shape.
|
|
@@ -155,6 +172,11 @@ interface IntegrityQueryOptions {
|
|
|
155
172
|
* `deserializeContract`. Throws if the on-disk contract is missing or
|
|
156
173
|
* undeserializable (surfaced as `contractUnreadable` by `checkIntegrity`
|
|
157
174
|
* under `checkContracts`); callers gate before querying it.
|
|
175
|
+
* - `contractAt(hash, opts?)`: materializes the contract at an arbitrary
|
|
176
|
+
* graph node — when `opts.refName` is set, prefer the ref's paired
|
|
177
|
+
* snapshot; else find the package whose `metadata.to === hash` and read
|
|
178
|
+
* its `end-contract.*`. Lazy per `(hash, refName?)` memoisation; throws
|
|
179
|
+
* typed {@link MigrationToolsError} values compatible with CLI mappers.
|
|
158
180
|
*/
|
|
159
181
|
interface ContractSpaceMember {
|
|
160
182
|
readonly spaceId: string;
|
|
@@ -163,6 +185,7 @@ interface ContractSpaceMember {
|
|
|
163
185
|
readonly headRef: ContractSpaceHeadRecord | null;
|
|
164
186
|
graph(): MigrationGraph;
|
|
165
187
|
contract(): Contract;
|
|
188
|
+
contractAt(hash: string, opts?: ContractAtOptions): Promise<ContractAtResult>;
|
|
166
189
|
}
|
|
167
190
|
/**
|
|
168
191
|
* Tolerant, queryable snapshot of a project's on-disk migration state:
|
|
@@ -210,21 +233,26 @@ interface ContractSpaceAggregate {
|
|
|
210
233
|
*/
|
|
211
234
|
declare function requireHeadRef(member: ContractSpaceMember): ContractSpaceHeadRecord;
|
|
212
235
|
/**
|
|
213
|
-
* Build a {@link ContractSpaceMember} with lazily-memoised `graph()
|
|
214
|
-
* `contract()` facets.
|
|
236
|
+
* Build a {@link ContractSpaceMember} with lazily-memoised `graph()`,
|
|
237
|
+
* `contract()`, and `contractAt()` facets.
|
|
215
238
|
*
|
|
216
239
|
* `graph()` reconstructs the migration graph from `packages` on first
|
|
217
240
|
* call and caches it. `contract()` calls `resolveContract` on first call
|
|
218
241
|
* and caches the result; a throwing `resolveContract` (e.g. a missing or
|
|
219
242
|
* undeserializable on-disk contract) re-throws on each call rather than
|
|
220
243
|
* caching a value — `checkIntegrity` surfaces that as `contractUnreadable`.
|
|
244
|
+
* `contractAt()` materializes the contract at an arbitrary graph node with
|
|
245
|
+
* the same resolution order as plan-time ref resolution: ref snapshot first
|
|
246
|
+
* (when `opts.refName` is set), else the matching package's `end-contract.*`.
|
|
221
247
|
*/
|
|
222
248
|
declare function createContractSpaceMember(args: {
|
|
223
249
|
readonly spaceId: string;
|
|
224
250
|
readonly packages: readonly OnDiskMigrationPackage[];
|
|
225
251
|
readonly refs: Refs;
|
|
226
252
|
readonly headRef: ContractSpaceHeadRecord | null;
|
|
253
|
+
readonly refsDir: string;
|
|
227
254
|
readonly resolveContract: () => Contract;
|
|
255
|
+
readonly deserializeContract: (raw: unknown) => Contract;
|
|
228
256
|
}): ContractSpaceMember;
|
|
229
257
|
/**
|
|
230
258
|
* Assemble a {@link ContractSpaceAggregate} value from its members and a
|
|
@@ -716,5 +744,5 @@ type AggregateVerifierOutput<TSchemaResult> = Result<AggregateVerifierSuccess<TS
|
|
|
716
744
|
*/
|
|
717
745
|
declare function verifyAggregate<TSchemaResult>(input: AggregateVerifierInput<TSchemaResult>): AggregateVerifierOutput<TSchemaResult>;
|
|
718
746
|
//#endregion
|
|
719
|
-
export { type AggregateCurrentDBState, type AggregateMigrationEdgeRef, type AggregatePerSpacePlan, type AggregatePlannerError, type AggregatePlannerInput, type AggregatePlannerOutput, type AggregatePlannerSuccess, type AggregateVerifierError, type AggregateVerifierInput, type AggregateVerifierOutput, type AggregateVerifierSuccess, type CallerPolicy, type ContractMarkerRecordLike, type ContractSpaceAggregate, type ContractSpaceMember, type DeclaredExtensionEntry, type GraphWalkOutcome, type GraphWalkStrategyInputs, type IntegrityComputationInput, type IntegrityQueryOptions, type IntegritySpaceState, type IntegrityViolation, type LoadAggregateInput, type MarkerCheckResult, type MarkerCheckSection, type OrphanElement, type SchemaCheckSection, computeIntegrityViolations, createContractSpaceAggregate, createContractSpaceMember, graphWalkStrategy, loadContractSpaceAggregate, loadProblemToViolation, planAggregate, projectSchemaToSpace, requireHeadRef, verifyAggregate };
|
|
747
|
+
export { type AggregateCurrentDBState, type AggregateMigrationEdgeRef, type AggregatePerSpacePlan, type AggregatePlannerError, type AggregatePlannerInput, type AggregatePlannerOutput, type AggregatePlannerSuccess, type AggregateVerifierError, type AggregateVerifierInput, type AggregateVerifierOutput, type AggregateVerifierSuccess, type CallerPolicy, type ContractAtOptions, type ContractAtResult, type ContractMarkerRecordLike, type ContractSpaceAggregate, type ContractSpaceMember, type DeclaredExtensionEntry, type GraphWalkOutcome, type GraphWalkStrategyInputs, type IntegrityComputationInput, type IntegrityQueryOptions, type IntegritySpaceState, type IntegrityViolation, type LoadAggregateInput, type MarkerCheckResult, type MarkerCheckSection, type OrphanElement, type SchemaCheckSection, computeIntegrityViolations, createContractSpaceAggregate, createContractSpaceMember, graphWalkStrategy, loadContractSpaceAggregate, loadProblemToViolation, planAggregate, projectSchemaToSpace, requireHeadRef, verifyAggregate };
|
|
720
748
|
//# sourceMappingURL=aggregate.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregate.d.mts","names":[],"sources":["../../src/integrity-violation.ts","../../src/aggregate/types.ts","../../src/aggregate/aggregate.ts","../../src/aggregate/check-integrity.ts","../../src/aggregate/loader.ts","../../src/aggregate/marker-types.ts","../../src/aggregate/planner-types.ts","../../src/aggregate/planner.ts","../../src/aggregate/project-schema-to-space.ts","../../src/aggregate/strategies/graph-walk.ts","../../src/aggregate/verifier.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkBA;;;;;;KAAY,kBAAA;EAAA,SAGG,IAAA;EAAA,SACA,OAAA;EAAA,SACA,OAAA;EAAA,SACA,IAAA;AAAA;EAAA,SAGA,IAAA;EAAA,SACA,OAAA;EAAA,SACA,OAAA;EAAA,SACA,MAAA;EAAA,SACA,QAAA;AAAA;EAAA,SAGA,IAAA;EAAA,SACA,OAAA;EAAA,SACA,OAAA;AAAA;EAAA,SAEA,IAAA;EAAA,SAAiC,OAAA;AAAA;EAAA,SACjC,IAAA;EAAA,SAAoC,OAAA;EAAA,SAA0B,IAAA;AAAA;EAAA,SAE9D,IAAA;EAAA,SACA,OAAA;EAAA,SACA,aAAA;EAAA,SACA,QAAA;AAAA;EAAA,SAGA,IAAA;EAAA,SACA,OAAA;EAAA,SACA,OAAA;EAAA,SACA,MAAA;AAAA;EAAA,SAGA,IAAA;EAAA,SAAiC,OAAA;AAAA;EAAA,SACjC,IAAA;EAAA,SAAwC,OAAA;AAAA;EAAA,SAExC,IAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA;EAAA,SACA,MAAA;AAAA;EAAA,SAGA,IAAA;EAAA,SACA,OAAA;EAAA,SACA,SAAA;AAAA;EAAA,SAEA,IAAA;EAAA,SAAqC,OAAA;EAAA,SAA0B,MAAA;AAAA;EAAA,SAG/D,IAAA;EAAA,SACA,OAAA;EAAA,SACA,OAAA;EAAA,SACA,MAAA;AAAA;;;;
|
|
1
|
+
{"version":3,"file":"aggregate.d.mts","names":[],"sources":["../../src/integrity-violation.ts","../../src/aggregate/types.ts","../../src/aggregate/aggregate.ts","../../src/aggregate/check-integrity.ts","../../src/aggregate/loader.ts","../../src/aggregate/marker-types.ts","../../src/aggregate/planner-types.ts","../../src/aggregate/planner.ts","../../src/aggregate/project-schema-to-space.ts","../../src/aggregate/strategies/graph-walk.ts","../../src/aggregate/verifier.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkBA;;;;;;KAAY,kBAAA;EAAA,SAGG,IAAA;EAAA,SACA,OAAA;EAAA,SACA,OAAA;EAAA,SACA,IAAA;AAAA;EA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ATtE+B;AAuCjC;;;;iBSwDgB,eAAA,eAAA,CACd,KAAA,EAAO,sBAAA,CAAuB,aAAA,IAC7B,uBAAA,CAAwB,aAAA"}
|
|
@@ -1,13 +1,105 @@
|
|
|
1
|
-
import { t as MigrationToolsError } from "../errors-
|
|
2
|
-
import { s as readMigrationsDir } from "../io-
|
|
1
|
+
import { E as errorSnapshotMissing, f as errorInvalidJson, i as errorContractDeserializationFailed, l as errorHashNotInGraph, r as errorBundleNotFoundForGraphNode, t as MigrationToolsError, x as errorMissingFile } from "../errors-vFROOhCR.mjs";
|
|
2
|
+
import { s as readMigrationsDir } from "../io-BGlPOt9b.mjs";
|
|
3
3
|
import { t as EMPTY_CONTRACT_HASH } from "../constants-DWV9_o2Z.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { n as isGraphNode } from "../graph-membership-BV23F1IV.mjs";
|
|
5
|
+
import { l as reconstructGraph, o as findPathWithDecision } from "../migration-graph-BMAqSfv9.mjs";
|
|
6
|
+
import { a as readRefsTolerant, t as HEAD_REF_NAME } from "../refs-Ditzcs06.mjs";
|
|
7
|
+
import { c as spaceMigrationDirectory, i as RESERVED_SPACE_SUBDIR_NAMES, l as spaceRefsDirectory, r as APP_SPACE_ID, s as isValidSpaceId, t as listContractSpaceDirectories } from "../verify-contract-spaces-3u7gzhqT.mjs";
|
|
8
|
+
import { r as readRefSnapshot } from "../snapshot-CVg78oBp.mjs";
|
|
9
|
+
import { n as readContractSpaceHeadRef, t as readContractSpaceContract } from "../read-contract-space-contract-BbcST3Lm.mjs";
|
|
10
|
+
import { join } from "pathe";
|
|
11
|
+
import { readFile } from "node:fs/promises";
|
|
8
12
|
import { notOk, ok } from "@prisma-next/utils/result";
|
|
9
13
|
import { elementCoordinates } from "@prisma-next/framework-components/ir";
|
|
10
14
|
//#region src/aggregate/aggregate.ts
|
|
15
|
+
function hasErrnoCode(error, code) {
|
|
16
|
+
return error instanceof Error && error.code === code;
|
|
17
|
+
}
|
|
18
|
+
function contractAtMemoKey(hash, refName) {
|
|
19
|
+
return `${hash}\0${refName ?? ""}`;
|
|
20
|
+
}
|
|
21
|
+
function deserializeContractAtPath(filePath, contractJson, deserializeContract) {
|
|
22
|
+
try {
|
|
23
|
+
return deserializeContract(contractJson);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
if (MigrationToolsError.is(error)) throw error;
|
|
26
|
+
throw errorContractDeserializationFailed(filePath, error instanceof Error ? error.message : String(error));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function readGraphNodeEndContract(packageDir, deserializeContract) {
|
|
30
|
+
const jsonPath = join(packageDir, "end-contract.json");
|
|
31
|
+
const dtsPath = join(packageDir, "end-contract.d.ts");
|
|
32
|
+
let rawJson;
|
|
33
|
+
try {
|
|
34
|
+
rawJson = await readFile(jsonPath, "utf-8");
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (hasErrnoCode(error, "ENOENT")) throw errorMissingFile("end-contract.json", packageDir);
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
let contractJson;
|
|
40
|
+
try {
|
|
41
|
+
contractJson = JSON.parse(rawJson);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
throw errorInvalidJson(jsonPath, error instanceof Error ? error.message : String(error));
|
|
44
|
+
}
|
|
45
|
+
let contractDts;
|
|
46
|
+
try {
|
|
47
|
+
contractDts = await readFile(dtsPath, "utf-8");
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (hasErrnoCode(error, "ENOENT")) throw errorMissingFile("end-contract.d.ts", packageDir);
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
const contract = deserializeContractAtPath(jsonPath, contractJson, deserializeContract);
|
|
53
|
+
return {
|
|
54
|
+
contractJson,
|
|
55
|
+
contractDts,
|
|
56
|
+
contract
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async function resolveContractAt(args) {
|
|
60
|
+
const { hash, opts, refsDir, packages, graph, deserializeContract } = args;
|
|
61
|
+
const refName = opts?.refName;
|
|
62
|
+
if (refName !== void 0) {
|
|
63
|
+
const snapshot = await readRefSnapshot(refsDir, refName);
|
|
64
|
+
if (snapshot) {
|
|
65
|
+
const jsonPath = join(refsDir, `${refName}.contract.json`);
|
|
66
|
+
return {
|
|
67
|
+
hash,
|
|
68
|
+
contractJson: snapshot.contract,
|
|
69
|
+
contractDts: snapshot.contractDts,
|
|
70
|
+
contract: deserializeContractAtPath(jsonPath, snapshot.contract, deserializeContract),
|
|
71
|
+
provenance: "snapshot"
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (isGraphNode(hash, graph)) return resolveGraphNodeContractAt({
|
|
75
|
+
hash,
|
|
76
|
+
packages,
|
|
77
|
+
deserializeContract,
|
|
78
|
+
explicitLabel: refName
|
|
79
|
+
});
|
|
80
|
+
throw errorSnapshotMissing(refName);
|
|
81
|
+
}
|
|
82
|
+
if (isGraphNode(hash, graph)) return resolveGraphNodeContractAt({
|
|
83
|
+
hash,
|
|
84
|
+
packages,
|
|
85
|
+
deserializeContract
|
|
86
|
+
});
|
|
87
|
+
throw errorHashNotInGraph(hash, graph);
|
|
88
|
+
}
|
|
89
|
+
async function resolveGraphNodeContractAt(args) {
|
|
90
|
+
const { hash, packages, deserializeContract, explicitLabel } = args;
|
|
91
|
+
const matchingBundle = packages.find((pkg) => pkg.metadata.to === hash);
|
|
92
|
+
if (!matchingBundle) throw errorBundleNotFoundForGraphNode(hash, explicitLabel);
|
|
93
|
+
const { contractJson, contractDts, contract } = await readGraphNodeEndContract(matchingBundle.dirPath, deserializeContract);
|
|
94
|
+
return {
|
|
95
|
+
hash,
|
|
96
|
+
contractJson,
|
|
97
|
+
contractDts,
|
|
98
|
+
contract,
|
|
99
|
+
provenance: "graph-node",
|
|
100
|
+
sourceDir: matchingBundle.dirPath
|
|
101
|
+
};
|
|
102
|
+
}
|
|
11
103
|
/**
|
|
12
104
|
* Resolve a member's head ref, asserting it is present. The apply/verify
|
|
13
105
|
* engine only runs after `checkIntegrity` has refused on `headRefMissing`,
|
|
@@ -21,31 +113,51 @@ function requireHeadRef(member) {
|
|
|
21
113
|
return member.headRef;
|
|
22
114
|
}
|
|
23
115
|
/**
|
|
24
|
-
* Build a {@link ContractSpaceMember} with lazily-memoised `graph()
|
|
25
|
-
* `contract()` facets.
|
|
116
|
+
* Build a {@link ContractSpaceMember} with lazily-memoised `graph()`,
|
|
117
|
+
* `contract()`, and `contractAt()` facets.
|
|
26
118
|
*
|
|
27
119
|
* `graph()` reconstructs the migration graph from `packages` on first
|
|
28
120
|
* call and caches it. `contract()` calls `resolveContract` on first call
|
|
29
121
|
* and caches the result; a throwing `resolveContract` (e.g. a missing or
|
|
30
122
|
* undeserializable on-disk contract) re-throws on each call rather than
|
|
31
123
|
* caching a value — `checkIntegrity` surfaces that as `contractUnreadable`.
|
|
124
|
+
* `contractAt()` materializes the contract at an arbitrary graph node with
|
|
125
|
+
* the same resolution order as plan-time ref resolution: ref snapshot first
|
|
126
|
+
* (when `opts.refName` is set), else the matching package's `end-contract.*`.
|
|
32
127
|
*/
|
|
33
128
|
function createContractSpaceMember(args) {
|
|
34
|
-
const { spaceId, packages, refs, headRef, resolveContract } = args;
|
|
129
|
+
const { spaceId, packages, refs, headRef, refsDir, resolveContract, deserializeContract } = args;
|
|
35
130
|
let graphMemo;
|
|
36
131
|
let contractMemo;
|
|
132
|
+
const contractAtMemo = /* @__PURE__ */ new Map();
|
|
133
|
+
function memberGraph() {
|
|
134
|
+
graphMemo ??= reconstructGraph(packages);
|
|
135
|
+
return graphMemo;
|
|
136
|
+
}
|
|
37
137
|
return {
|
|
38
138
|
spaceId,
|
|
39
139
|
packages,
|
|
40
140
|
refs,
|
|
41
141
|
headRef,
|
|
42
|
-
graph
|
|
43
|
-
graphMemo ??= reconstructGraph(packages);
|
|
44
|
-
return graphMemo;
|
|
45
|
-
},
|
|
142
|
+
graph: memberGraph,
|
|
46
143
|
contract() {
|
|
47
144
|
contractMemo ??= resolveContract();
|
|
48
145
|
return contractMemo;
|
|
146
|
+
},
|
|
147
|
+
async contractAt(hash, opts) {
|
|
148
|
+
const key = contractAtMemoKey(hash, opts?.refName);
|
|
149
|
+
const cached = contractAtMemo.get(key);
|
|
150
|
+
if (cached) return cached;
|
|
151
|
+
const result = await resolveContractAt({
|
|
152
|
+
hash,
|
|
153
|
+
opts,
|
|
154
|
+
refsDir,
|
|
155
|
+
packages,
|
|
156
|
+
graph: memberGraph(),
|
|
157
|
+
deserializeContract
|
|
158
|
+
});
|
|
159
|
+
contractAtMemo.set(key, result);
|
|
160
|
+
return result;
|
|
49
161
|
}
|
|
50
162
|
};
|
|
51
163
|
}
|
|
@@ -253,7 +365,7 @@ function detailOf$1(error) {
|
|
|
253
365
|
async function loadContractSpaceAggregate(input) {
|
|
254
366
|
const { migrationsDir, deserializeContract, appContract } = input;
|
|
255
367
|
const targetId = appContract.target;
|
|
256
|
-
const appState = await loadAppSpace(migrationsDir, appContract);
|
|
368
|
+
const appState = await loadAppSpace(migrationsDir, appContract, deserializeContract);
|
|
257
369
|
const extensionStates = await loadExtensionSpaces(migrationsDir, deserializeContract);
|
|
258
370
|
const spaces = [appState, ...extensionStates];
|
|
259
371
|
return createContractSpaceAggregate({
|
|
@@ -266,7 +378,7 @@ async function loadContractSpaceAggregate(input) {
|
|
|
266
378
|
}, opts)
|
|
267
379
|
});
|
|
268
380
|
}
|
|
269
|
-
async function loadAppSpace(migrationsDir, appContract) {
|
|
381
|
+
async function loadAppSpace(migrationsDir, appContract, deserializeContract) {
|
|
270
382
|
const spaceDir = spaceMigrationDirectory(migrationsDir, APP_SPACE_ID);
|
|
271
383
|
const { packages, problems } = await readMigrationsDir(spaceDir);
|
|
272
384
|
const { refs, problems: refProblems } = await readRefsTolerant(spaceRefsDirectory(spaceDir));
|
|
@@ -279,7 +391,9 @@ async function loadAppSpace(migrationsDir, appContract) {
|
|
|
279
391
|
hash: appContract.storage.storageHash,
|
|
280
392
|
invariants: []
|
|
281
393
|
},
|
|
282
|
-
|
|
394
|
+
refsDir: spaceRefsDirectory(spaceDir),
|
|
395
|
+
resolveContract: () => appContract,
|
|
396
|
+
deserializeContract
|
|
283
397
|
}),
|
|
284
398
|
problems,
|
|
285
399
|
refProblems,
|
|
@@ -305,7 +419,9 @@ async function loadExtensionSpace(migrationsDir, spaceId, deserializeContract) {
|
|
|
305
419
|
packages,
|
|
306
420
|
refs,
|
|
307
421
|
headRef,
|
|
308
|
-
|
|
422
|
+
refsDir: spaceRefsDirectory(spaceDir),
|
|
423
|
+
resolveContract: () => deserializeContract(rawContract()),
|
|
424
|
+
deserializeContract
|
|
309
425
|
}),
|
|
310
426
|
problems,
|
|
311
427
|
refProblems,
|