@prisma-next/migration-tools 0.5.0-dev.62 → 0.5.0-dev.63
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/{constants-BQEHsaEx.mjs → constants-B87kJAGj.mjs} +1 -1
- package/dist/{constants-BQEHsaEx.mjs.map → constants-B87kJAGj.mjs.map} +1 -1
- package/dist/{errors-CfmjBeK0.mjs → errors-DQsXvidG.mjs} +22 -2
- package/dist/errors-DQsXvidG.mjs.map +1 -0
- package/dist/exports/constants.mjs +1 -1
- package/dist/exports/errors.d.mts.map +1 -1
- package/dist/exports/errors.mjs +1 -1
- package/dist/exports/graph.d.mts +1 -1
- package/dist/exports/hash.d.mts +3 -3
- package/dist/exports/hash.d.mts.map +1 -1
- package/dist/exports/hash.mjs +1 -1
- package/dist/exports/invariants.d.mts +1 -1
- package/dist/exports/invariants.mjs +2 -2
- package/dist/exports/io.d.mts +40 -5
- package/dist/exports/io.d.mts.map +1 -1
- package/dist/exports/io.mjs +4 -162
- package/dist/exports/metadata.d.mts +1 -1
- package/dist/exports/migration-graph.d.mts +3 -3
- package/dist/exports/migration-graph.d.mts.map +1 -1
- package/dist/exports/migration-graph.mjs +2 -2
- package/dist/exports/migration-graph.mjs.map +1 -1
- package/dist/exports/migration.d.mts +3 -3
- package/dist/exports/migration.d.mts.map +1 -1
- package/dist/exports/migration.mjs +4 -4
- package/dist/exports/package.d.mts +3 -2
- package/dist/exports/refs.mjs +1 -1
- package/dist/exports/spaces.d.mts +447 -0
- package/dist/exports/spaces.d.mts.map +1 -0
- package/dist/exports/spaces.mjs +433 -0
- package/dist/exports/spaces.mjs.map +1 -0
- package/dist/{graph-BHPv-9Gl.d.mts → graph-Czaj8O2q.d.mts} +1 -1
- package/dist/{graph-BHPv-9Gl.d.mts.map → graph-Czaj8O2q.d.mts.map} +1 -1
- package/dist/{hash-BARZdVgW.mjs → hash-G0bAfIGh.mjs} +2 -2
- package/dist/hash-G0bAfIGh.mjs.map +1 -0
- package/dist/{invariants-30VA65sB.mjs → invariants-4Avb_Yhy.mjs} +2 -2
- package/dist/{invariants-30VA65sB.mjs.map → invariants-4Avb_Yhy.mjs.map} +1 -1
- package/dist/io-CDJaWGbt.mjs +207 -0
- package/dist/io-CDJaWGbt.mjs.map +1 -0
- package/dist/metadata-CSjwljJx.d.mts +2 -0
- package/dist/{op-schema-DZKFua46.mjs → op-schema-BiF1ZYqH.mjs} +1 -1
- package/dist/{op-schema-DZKFua46.mjs.map → op-schema-BiF1ZYqH.mjs.map} +1 -1
- package/dist/package-B3Yl6DTr.d.mts +21 -0
- package/dist/package-B3Yl6DTr.d.mts.map +1 -0
- package/package.json +8 -4
- package/src/concatenate-space-apply-inputs.ts +90 -0
- package/src/detect-space-contract-drift.ts +95 -0
- package/src/emit-pinned-space-artefacts.ts +89 -0
- package/src/errors.ts +35 -0
- package/src/exports/io.ts +1 -0
- package/src/exports/package.ts +2 -1
- package/src/exports/spaces.ts +36 -0
- package/src/hash.ts +2 -2
- package/src/io.ts +71 -16
- package/src/metadata.ts +1 -41
- package/src/migration-graph.ts +2 -2
- package/src/package.ts +14 -11
- package/src/plan-all-spaces.ts +80 -0
- package/src/read-pinned-contract-hash.ts +77 -0
- package/src/space-layout.ts +55 -0
- package/src/verify-contract-spaces.ts +276 -0
- package/dist/errors-CfmjBeK0.mjs.map +0 -1
- package/dist/exports/io.mjs.map +0 -1
- package/dist/hash-BARZdVgW.mjs.map +0 -1
- package/dist/metadata-BP1cmU7Z.d.mts +0 -50
- package/dist/metadata-BP1cmU7Z.d.mts.map +0 -1
- package/dist/package-5HCCg0z-.d.mts +0 -21
- package/dist/package-5HCCg0z-.d.mts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants-
|
|
1
|
+
{"version":3,"file":"constants-B87kJAGj.mjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["/**\n * Sentinel value representing the absence of a contract (empty/new project).\n * This is a human-readable marker, not a real SHA-256 hash.\n */\nexport const EMPTY_CONTRACT_HASH = 'sha256:empty' as const;\n"],"mappings":";;;;;AAIA,MAAa,sBAAsB"}
|
|
@@ -125,6 +125,26 @@ function errorInvalidDestName(destName) {
|
|
|
125
125
|
details: { destName }
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
|
+
function errorInvalidSpaceId(spaceId) {
|
|
129
|
+
return new MigrationToolsError("MIGRATION.INVALID_SPACE_ID", "Invalid contract space identifier", {
|
|
130
|
+
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.`,
|
|
131
|
+
fix: "Pick a lowercase identifier that begins with a letter and contains only lowercase letters, digits, hyphens, or underscores; max 64 characters total.",
|
|
132
|
+
details: { spaceId }
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
function errorPinnedArtefactsAppSpace() {
|
|
136
|
+
return new MigrationToolsError("MIGRATION.PINNED_ARTEFACTS_APP_SPACE", "Pinned per-space artefacts do not apply to the app space", {
|
|
137
|
+
why: "Pinned `contract.json`/`contract.d.ts`/`refs/head.json` files only exist for extension spaces under `migrations/<space-id>/`. The app space's canonical contract lives at the project root (`contract.json`) — `emitPinnedSpaceArtefacts` is the wrong helper for it.",
|
|
138
|
+
fix: "Pass an extension space id, or use the app-space contract emit pipeline for the project-root `contract.json` / `contract.d.ts`."
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function errorDuplicateSpaceId(spaceId) {
|
|
142
|
+
return new MigrationToolsError("MIGRATION.DUPLICATE_SPACE_ID", "Duplicate contract space identifier", {
|
|
143
|
+
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).`,
|
|
144
|
+
fix: "Deduplicate the inputs before passing them to `planAllSpaces` — typically by checking your `extensionPacks` declaration for repeated entries.",
|
|
145
|
+
details: { spaceId }
|
|
146
|
+
});
|
|
147
|
+
}
|
|
128
148
|
function errorSameSourceAndTarget(dir, hash) {
|
|
129
149
|
const dirName = basename(dir);
|
|
130
150
|
return new MigrationToolsError("MIGRATION.SAME_SOURCE_AND_TARGET", "Migration without data-transform operations has same source and target", {
|
|
@@ -268,5 +288,5 @@ function errorMigrationHashMismatch(dir, storedHash, computedHash) {
|
|
|
268
288
|
}
|
|
269
289
|
|
|
270
290
|
//#endregion
|
|
271
|
-
export {
|
|
272
|
-
//# sourceMappingURL=errors-
|
|
291
|
+
export { errorProvidedInvariantsMismatch as C, errorUnknownInvariant as E, errorPinnedArtefactsAppSpace as S, errorStaleContractBookends as T, errorMigrationHashMismatch as _, errorDuplicateMigrationHash as a, errorNoInvariantPath as b, errorInvalidInvariantId as c, errorInvalidOperationEntry as d, errorInvalidRefFile as f, errorInvalidSpaceId as g, errorInvalidSlug as h, errorDuplicateInvariantInEdge as i, errorInvalidJson as l, errorInvalidRefValue as m, errorAmbiguousTarget as n, errorDuplicateSpaceId as o, errorInvalidRefName as p, errorDirectoryExists as r, errorInvalidDestName as s, MigrationToolsError as t, errorInvalidManifest as u, errorMissingFile as v, errorSameSourceAndTarget as w, errorNoTarget as x, errorNoInitialMigration as y };
|
|
292
|
+
//# sourceMappingURL=errors-DQsXvidG.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors-DQsXvidG.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import { ifDefined } from '@prisma-next/utils/defined';\nimport { basename, dirname, relative } from 'pathe';\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 errorStaleContractBookends(args: {\n readonly side: 'from' | 'to';\n readonly metaHash: string | null;\n readonly contractHash: string;\n}): MigrationToolsError {\n const { side, metaHash, contractHash } = args;\n // `meta.from` is `string | null` (null = baseline). Render `null` as a\n // human-readable token in the diagnostic so the message stays clear when\n // the mismatch is a baseline-vs-non-baseline disagreement.\n const renderedMetaHash = metaHash === null ? 'null (baseline)' : `\"${metaHash}\"`;\n return new MigrationToolsError(\n 'MIGRATION.STALE_CONTRACT_BOOKENDS',\n 'Migration manifest contract bookends disagree with describe()',\n {\n why: `migration.json stores ${side}Contract.storage.storageHash \"${contractHash}\", but describe() returned meta.${side} = ${renderedMetaHash}. The bookend is stale — most likely the migration's describe() was edited after the package was scaffolded by \\`migration plan\\`.`,\n fix: 'Re-run `migration plan` to regenerate the package with fresh contract bookends, or restore the directory from version control.',\n details: { side, metaHash, contractHash },\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 errorPinnedArtefactsAppSpace(): MigrationToolsError {\n return new MigrationToolsError(\n 'MIGRATION.PINNED_ARTEFACTS_APP_SPACE',\n 'Pinned per-space artefacts do not apply to the app space',\n {\n why: \"Pinned `contract.json`/`contract.d.ts`/`refs/head.json` files only exist for extension spaces under `migrations/<space-id>/`. The app space's canonical contract lives at the project root (`contract.json`) — `emitPinnedSpaceArtefacts` is the wrong helper for it.\",\n fix: 'Pass an extension space id, or use the app-space contract emit pipeline for the project-root `contract.json` / `contract.d.ts`.',\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 `migration ref set <name> <hash>` to target a specific branch, delete one of the conflicting migration directories and re-run `migration plan`, or use --from <hash> to explicitly select a starting point.',\n details: {\n branchTips,\n ...(context ? { divergencePoint: context.divergencePoint, branches: context.branches } : {}),\n },\n });\n}\n\nexport function errorNoInitialMigration(nodes: readonly string[]): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.NO_INITIAL_MIGRATION', 'No initial migration found', {\n why: `No migration starts from the empty contract state (known hashes: ${nodes.join(', ')}). At least one migration must originate from the empty state.`,\n fix: 'Inspect the migrations directory for corrupted migration.json files. At least one migration must start from the empty contract hash.',\n details: { nodes },\n });\n}\n\nexport function errorInvalidRefs(refsPath: string, reason: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_REFS', 'Invalid refs.json', {\n why: `refs.json at \"${refsPath}\" is invalid: ${reason}`,\n fix: 'Ensure refs.json is a flat object mapping valid ref names to contract hash strings.',\n details: { path: refsPath, reason },\n });\n}\n\nexport function errorInvalidRefFile(filePath: string, reason: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_REF_FILE', 'Invalid ref file', {\n why: `Ref file at \"${filePath}\" is invalid: ${reason}`,\n fix: 'Ensure the ref file contains valid JSON with { \"hash\": \"sha256:<64 hex chars>\", \"invariants\": [\"...\"] }.',\n details: { path: filePath, reason },\n });\n}\n\nexport function errorInvalidRefName(refName: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_REF_NAME', 'Invalid ref name', {\n why: `Ref name \"${refName}\" is invalid. Names must be lowercase alphanumeric with hyphens or forward slashes (no \".\" or \"..\" segments).`,\n fix: `Use a valid ref name (e.g., \"staging\", \"envs/production\").`,\n details: { refName },\n });\n}\n\nexport function errorNoTarget(reachableHashes: readonly string[]): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.NO_TARGET', 'No migration target could be resolved', {\n why: `The migration history contains cycles and no target can be resolved automatically (reachable hashes: ${reachableHashes.join(', ')}). This typically happens after rollback migrations (e.g., C1→C2→C1).`,\n fix: 'Use --from <hash> to specify the planning origin explicitly.',\n details: { reachableHashes },\n });\n}\n\nexport function errorInvalidRefValue(value: string): MigrationToolsError {\n return new MigrationToolsError('MIGRATION.INVALID_REF_VALUE', 'Invalid ref value', {\n why: `Ref value \"${value}\" is not a valid contract hash. Values must be in the format \"sha256:<64 hex chars>\" or \"sha256:empty\".`,\n fix: 'Use a valid storage hash from `prisma-next contract emit` output or an existing migration.',\n details: { value },\n });\n}\n\nexport function 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`, `labels`) lives on `MigrationEdge` but\n * is 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"],"mappings":";;;;;;;;;;;;;;AAaA,SAAS,WAAW,KAAa,UAA2B;CAE1D,MAAM,SAAS,0CADK,SAAS,QAAQ,KAAK,EAAE,IAAI,CACqB;AACrE,QAAO,WAAW,GAAG,OAAO,IAAI,aAAa,GAAG,OAAO;;;;;;;;;;;;;;;;;;AAmBzD,IAAa,sBAAb,cAAyC,MAAM;CAC7C,AAAS;CACT,AAAS,WAAW;CACpB,AAAS;CACT,AAAS;CACT,AAAS;CAET,YACE,MACA,SACA,SAKA;AACA,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,OAAK,OAAO;AACZ,OAAK,MAAM,QAAQ;AACnB,OAAK,MAAM,QAAQ;A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AAC,CAAC,KAAK,KAAK,CAK8B,cAAc,YAAY;EAC5H,KAAK;EACL,SAAS;GACP;GACA;GACA;GACA,GAAG,UAAU,WAAW,QAAQ;GACjC;EACF,CACF;;AAGH,SAAgB,sBAAsB,MAId;CACtB,MAAM,EAAE,SAAS,SAAS,aAAa;AAGvC,QAAO,IAAI,oBACT,+BACA,8DACA;EACE,KAAK,GANS,UAAU,QAAQ,QAAQ,cAAc,WAMpC,2DALF,QAAQ,KAAK,OAAO,KAAK,UAAU,GAAG,CAAC,CAAC,KAAK,KAAK,CAKuB;EACzF,KAAK;EACL,SAAS;GACP;GACA;GACA,GAAG,UAAU,WAAW,QAAQ;GACjC;EACF,CACF;;AAGH,SAAgB,2BACd,KACA,YACA,cACqB;AAKrB,QAAO,IAAI,oBAAoB,2BAA2B,gCAAgC;EACxF,KAAK,yBAAyB,WAAW,wCAAwC,aAAa,SAF5E,SAAS,QAAQ,KAAK,EAAE,IAAI,CAEqE;EACnH,KAAK,WAAW,KAAK,iDAAiD;EACtE,SAAS;GAAE;GAAK;GAAY;GAAc;EAC3C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.mts","names":[],"sources":["../../src/errors.ts"],"sourcesContent":[],"mappings":";;AAmCA;;;;;;AAkDA;
|
|
1
|
+
{"version":3,"file":"errors.d.mts","names":[],"sources":["../../src/errors.ts"],"sourcesContent":[],"mappings":";;AAmCA;;;;;;AAkDA;AAmQA;AAQA;AA0BA;;;;;;cAvVa,mBAAA,SAA4B,KAAA;;;;;oBAKrB;;;;uBAQK;;sCAWa;;iBA0BtB,gBAAA,wCAAwD;;;;;;;;;;;;UAmQvD,6BAAA;;;;;;;iBAQD,oBAAA;;;;oCAIoB;IAChC;iBAqBY,qBAAA;;;;IAIZ"}
|
package/dist/exports/errors.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { E as errorUnknownInvariant, b as errorNoInvariantPath, l as errorInvalidJson, t as MigrationToolsError } from "../errors-DQsXvidG.mjs";
|
|
2
2
|
|
|
3
3
|
export { MigrationToolsError, errorInvalidJson, errorNoInvariantPath, errorUnknownInvariant };
|
package/dist/exports/graph.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as MigrationGraph, t as MigrationEdge } from "../graph-
|
|
1
|
+
import { n as MigrationGraph, t as MigrationEdge } from "../graph-Czaj8O2q.mjs";
|
|
2
2
|
export { type MigrationEdge, type MigrationGraph };
|
package/dist/exports/hash.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as MigrationMetadata } from "../metadata-
|
|
2
|
-
import { n as
|
|
1
|
+
import { n as MigrationMetadata } from "../metadata-CSjwljJx.mjs";
|
|
2
|
+
import { n as OnDiskMigrationPackage, t as MigrationOps } from "../package-B3Yl6DTr.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/hash.d.ts
|
|
5
5
|
interface VerifyResult {
|
|
@@ -46,7 +46,7 @@ declare function computeMigrationHash(metadata: Omit<MigrationMetadata, 'migrati
|
|
|
46
46
|
* not — typically a sign of FS corruption, partial writes, or a post-emit
|
|
47
47
|
* hand edit.
|
|
48
48
|
*/
|
|
49
|
-
declare function verifyMigrationHash(pkg:
|
|
49
|
+
declare function verifyMigrationHash(pkg: OnDiskMigrationPackage): VerifyResult;
|
|
50
50
|
//#endregion
|
|
51
51
|
export { type VerifyResult, computeMigrationHash, verifyMigrationHash };
|
|
52
52
|
//# sourceMappingURL=hash.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.mts","names":[],"sources":["../../src/hash.ts"],"sourcesContent":[],"mappings":";;;;UAKiB,YAAA;;EAAA,SAAA,MAAY,CAAA,EAAA,UAAA;EAqCb,SAAA,UAAA,EAAA,MAAoB;EACnB,SAAA,YAAA,EAAA,MAAA;;;;AA8BjB;;;;;;;;;;;;;;;;;;;;;;;;iBA/BgB,oBAAA,WACJ,KAAK;;QACV;;;;;;;;;;iBA6BS,mBAAA,MAAyB,
|
|
1
|
+
{"version":3,"file":"hash.d.mts","names":[],"sources":["../../src/hash.ts"],"sourcesContent":[],"mappings":";;;;UAKiB,YAAA;;EAAA,SAAA,MAAY,CAAA,EAAA,UAAA;EAqCb,SAAA,UAAA,EAAA,MAAoB;EACnB,SAAA,YAAA,EAAA,MAAA;;;;AA8BjB;;;;;;;;;;;;;;;;;;;;;;;;iBA/BgB,oBAAA,WACJ,KAAK;;QACV;;;;;;;;;;iBA6BS,mBAAA,MAAyB,yBAAyB"}
|
package/dist/exports/hash.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../errors-
|
|
2
|
-
import { n as validateInvariantId, t as deriveProvidedInvariants } from "../invariants-
|
|
1
|
+
import "../errors-DQsXvidG.mjs";
|
|
2
|
+
import { n as validateInvariantId, t as deriveProvidedInvariants } from "../invariants-4Avb_Yhy.mjs";
|
|
3
3
|
|
|
4
4
|
export { deriveProvidedInvariants, validateInvariantId };
|
package/dist/exports/io.d.mts
CHANGED
|
@@ -1,8 +1,43 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import {
|
|
1
|
+
import { n as OnDiskMigrationPackage, t as MigrationOps } from "../package-B3Yl6DTr.mjs";
|
|
2
|
+
import { MigrationMetadata, MigrationPackage } from "@prisma-next/framework-components/control";
|
|
3
3
|
|
|
4
4
|
//#region src/io.d.ts
|
|
5
5
|
declare function writeMigrationPackage(dir: string, metadata: MigrationMetadata, ops: MigrationOps): Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* Materialise an in-memory {@link MigrationPackage} to a per-space
|
|
8
|
+
* directory on disk.
|
|
9
|
+
*
|
|
10
|
+
* Writes three files under `<targetDir>/<pkg.dirName>/`:
|
|
11
|
+
*
|
|
12
|
+
* - `migration.json` — the manifest (pretty-printed, matches
|
|
13
|
+
* {@link writeMigrationPackage}'s output for byte-for-byte parity with
|
|
14
|
+
* app-space migrations).
|
|
15
|
+
* - `ops.json` — the operation list (pretty-printed).
|
|
16
|
+
* - `contract.json` — the canonical-JSON serialisation of
|
|
17
|
+
* `metadata.toContract`. This is the per-package post-state contract
|
|
18
|
+
* snapshot; the canonicalisation pass guarantees byte-determinism so
|
|
19
|
+
* re-emitting the same package across machines / runs produces an
|
|
20
|
+
* identical file.
|
|
21
|
+
*
|
|
22
|
+
* Distinct verb from the lower-level {@link writeMigrationPackage}
|
|
23
|
+
* (which takes constituent `(metadata, ops)`): callers reading
|
|
24
|
+
* `materialise…` know they are persisting a struct-typed package
|
|
25
|
+
* including its contract-snapshot side car.
|
|
26
|
+
*
|
|
27
|
+
* Overwrite-idempotent: the per-package directory is cleared before
|
|
28
|
+
* each emit, so re-running against the same `targetDir` produces
|
|
29
|
+
* byte-identical contents and never leaves stale files behind. The
|
|
30
|
+
* spec's "re-emitting the same package across runs / machines produces
|
|
31
|
+
* byte-identical files" guarantee (§ 3) covers both same-dir and
|
|
32
|
+
* fresh-dir re-emits. The lower-level {@link writeMigrationPackage}
|
|
33
|
+
* stays strict because the CLI authoring path (`migration plan` /
|
|
34
|
+
* `migration new`) deliberately refuses to clobber an existing
|
|
35
|
+
* authored migration; this helper is the re-emit path that is
|
|
36
|
+
* supposed to converge on a single canonical on-disk shape.
|
|
37
|
+
*
|
|
38
|
+
* @see specs/framework-mechanism.spec.md § 3 — Emission helper (T1.7).
|
|
39
|
+
*/
|
|
40
|
+
declare function materialiseMigrationPackage(targetDir: string, pkg: MigrationPackage): Promise<void>;
|
|
6
41
|
/**
|
|
7
42
|
* Copy a list of files into `destDir`, optionally renaming each one.
|
|
8
43
|
*
|
|
@@ -20,9 +55,9 @@ declare function copyFilesWithRename(destDir: string, files: readonly {
|
|
|
20
55
|
}[]): Promise<void>;
|
|
21
56
|
declare function writeMigrationMetadata(dir: string, metadata: MigrationMetadata): Promise<void>;
|
|
22
57
|
declare function writeMigrationOps(dir: string, ops: MigrationOps): Promise<void>;
|
|
23
|
-
declare function readMigrationPackage(dir: string): Promise<
|
|
24
|
-
declare function readMigrationsDir(migrationsRoot: string): Promise<readonly
|
|
58
|
+
declare function readMigrationPackage(dir: string): Promise<OnDiskMigrationPackage>;
|
|
59
|
+
declare function readMigrationsDir(migrationsRoot: string): Promise<readonly OnDiskMigrationPackage[]>;
|
|
25
60
|
declare function formatMigrationDirName(timestamp: Date, slug: string): string;
|
|
26
61
|
//#endregion
|
|
27
|
-
export { copyFilesWithRename, formatMigrationDirName, readMigrationPackage, readMigrationsDir, writeMigrationMetadata, writeMigrationOps, writeMigrationPackage };
|
|
62
|
+
export { copyFilesWithRename, formatMigrationDirName, materialiseMigrationPackage, readMigrationPackage, readMigrationsDir, writeMigrationMetadata, writeMigrationOps, writeMigrationPackage };
|
|
28
63
|
//# sourceMappingURL=io.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io.d.mts","names":[],"sources":["../../src/io.ts"],"sourcesContent":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"io.d.mts","names":[],"sources":["../../src/io.ts"],"sourcesContent":[],"mappings":";;;;iBA0DsB,qBAAA,wBAEV,wBACL,eACJ;AAJH;;;;;AAwDA;AAuBA;AAaA;AAOA;AAIA;AAiGA;AAiCA;;;;;;;;;;;;;;;;;;;;;;;iBAjLsB,2BAAA,yBAEf,mBACJ;;;;;;;;;;;;iBAoBmB,mBAAA;;;MAGnB;iBAUmB,sBAAA,wBAEV,oBACT;iBAImB,iBAAA,mBAAoC,eAAe;iBAInD,oBAAA,eAAmC,QAAQ;iBAiG3C,iBAAA,0BAEnB,iBAAiB;iBA+BJ,sBAAA,YAAkC"}
|
package/dist/exports/io.mjs
CHANGED
|
@@ -1,163 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { n as MigrationOpsSchema } from "../op-schema-DZKFua46.mjs";
|
|
5
|
-
import { basename, dirname, join } from "pathe";
|
|
6
|
-
import { copyFile, mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
|
|
7
|
-
import { type } from "arktype";
|
|
1
|
+
import "../errors-DQsXvidG.mjs";
|
|
2
|
+
import "../invariants-4Avb_Yhy.mjs";
|
|
3
|
+
import { a as readMigrationPackage, c as writeMigrationOps, i as materialiseMigrationPackage, l as writeMigrationPackage, n as copyFilesWithRename, o as readMigrationsDir, r as formatMigrationDirName, s as writeMigrationMetadata } from "../io-CDJaWGbt.mjs";
|
|
8
4
|
|
|
9
|
-
|
|
10
|
-
const MANIFEST_FILE = "migration.json";
|
|
11
|
-
const OPS_FILE = "ops.json";
|
|
12
|
-
const MAX_SLUG_LENGTH = 64;
|
|
13
|
-
function hasErrnoCode(error, code) {
|
|
14
|
-
return error instanceof Error && error.code === code;
|
|
15
|
-
}
|
|
16
|
-
const MigrationHintsSchema = type({
|
|
17
|
-
used: "string[]",
|
|
18
|
-
applied: "string[]",
|
|
19
|
-
plannerVersion: "string"
|
|
20
|
-
});
|
|
21
|
-
const MigrationMetadataSchema = type({
|
|
22
|
-
"+": "reject",
|
|
23
|
-
from: "string > 0 | null",
|
|
24
|
-
to: "string",
|
|
25
|
-
migrationHash: "string",
|
|
26
|
-
fromContract: "object | null",
|
|
27
|
-
toContract: "object",
|
|
28
|
-
hints: MigrationHintsSchema,
|
|
29
|
-
labels: "string[]",
|
|
30
|
-
providedInvariants: "string[]",
|
|
31
|
-
"authorship?": type({
|
|
32
|
-
"author?": "string",
|
|
33
|
-
"email?": "string"
|
|
34
|
-
}),
|
|
35
|
-
"signature?": type({
|
|
36
|
-
keyId: "string",
|
|
37
|
-
value: "string"
|
|
38
|
-
}).or("null"),
|
|
39
|
-
createdAt: "string"
|
|
40
|
-
});
|
|
41
|
-
async function writeMigrationPackage(dir, metadata, ops) {
|
|
42
|
-
await mkdir(dirname(dir), { recursive: true });
|
|
43
|
-
try {
|
|
44
|
-
await mkdir(dir);
|
|
45
|
-
} catch (error) {
|
|
46
|
-
if (hasErrnoCode(error, "EEXIST")) throw errorDirectoryExists(dir);
|
|
47
|
-
throw error;
|
|
48
|
-
}
|
|
49
|
-
await writeFile(join(dir, MANIFEST_FILE), JSON.stringify(metadata, null, 2), { flag: "wx" });
|
|
50
|
-
await writeFile(join(dir, OPS_FILE), JSON.stringify(ops, null, 2), { flag: "wx" });
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Copy a list of files into `destDir`, optionally renaming each one.
|
|
54
|
-
*
|
|
55
|
-
* The destination directory is created (with `recursive: true`) if it
|
|
56
|
-
* does not already exist. Each source path is copied byte-for-byte into
|
|
57
|
-
* `destDir/<destName>`; missing sources throw `ENOENT`. The helper is
|
|
58
|
-
* intentionally generic: callers own the list of files (e.g. a contract
|
|
59
|
-
* emitter's emitted output) and the naming convention (e.g. renaming
|
|
60
|
-
* the destination contract to `end-contract.*` and the source contract
|
|
61
|
-
* to `start-contract.*`).
|
|
62
|
-
*/
|
|
63
|
-
async function copyFilesWithRename(destDir, files) {
|
|
64
|
-
await mkdir(destDir, { recursive: true });
|
|
65
|
-
for (const file of files) {
|
|
66
|
-
if (basename(file.destName) !== file.destName) throw errorInvalidDestName(file.destName);
|
|
67
|
-
await copyFile(file.sourcePath, join(destDir, file.destName));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
async function writeMigrationMetadata(dir, metadata) {
|
|
71
|
-
await writeFile(join(dir, MANIFEST_FILE), `${JSON.stringify(metadata, null, 2)}\n`);
|
|
72
|
-
}
|
|
73
|
-
async function writeMigrationOps(dir, ops) {
|
|
74
|
-
await writeFile(join(dir, OPS_FILE), `${JSON.stringify(ops, null, 2)}\n`);
|
|
75
|
-
}
|
|
76
|
-
async function readMigrationPackage(dir) {
|
|
77
|
-
const manifestPath = join(dir, MANIFEST_FILE);
|
|
78
|
-
const opsPath = join(dir, OPS_FILE);
|
|
79
|
-
let manifestRaw;
|
|
80
|
-
try {
|
|
81
|
-
manifestRaw = await readFile(manifestPath, "utf-8");
|
|
82
|
-
} catch (error) {
|
|
83
|
-
if (hasErrnoCode(error, "ENOENT")) throw errorMissingFile(MANIFEST_FILE, dir);
|
|
84
|
-
throw error;
|
|
85
|
-
}
|
|
86
|
-
let opsRaw;
|
|
87
|
-
try {
|
|
88
|
-
opsRaw = await readFile(opsPath, "utf-8");
|
|
89
|
-
} catch (error) {
|
|
90
|
-
if (hasErrnoCode(error, "ENOENT")) throw errorMissingFile(OPS_FILE, dir);
|
|
91
|
-
throw error;
|
|
92
|
-
}
|
|
93
|
-
let metadata;
|
|
94
|
-
try {
|
|
95
|
-
metadata = JSON.parse(manifestRaw);
|
|
96
|
-
} catch (e) {
|
|
97
|
-
throw errorInvalidJson(manifestPath, e instanceof Error ? e.message : String(e));
|
|
98
|
-
}
|
|
99
|
-
let ops;
|
|
100
|
-
try {
|
|
101
|
-
ops = JSON.parse(opsRaw);
|
|
102
|
-
} catch (e) {
|
|
103
|
-
throw errorInvalidJson(opsPath, e instanceof Error ? e.message : String(e));
|
|
104
|
-
}
|
|
105
|
-
validateMetadata(metadata, manifestPath);
|
|
106
|
-
validateOps(ops, opsPath);
|
|
107
|
-
const derivedInvariants = deriveProvidedInvariants(ops);
|
|
108
|
-
if (!arraysEqual(metadata.providedInvariants, derivedInvariants)) throw errorProvidedInvariantsMismatch(manifestPath, metadata.providedInvariants, derivedInvariants);
|
|
109
|
-
const pkg = {
|
|
110
|
-
dirName: basename(dir),
|
|
111
|
-
dirPath: dir,
|
|
112
|
-
metadata,
|
|
113
|
-
ops
|
|
114
|
-
};
|
|
115
|
-
const verification = verifyMigrationHash(pkg);
|
|
116
|
-
if (!verification.ok) throw errorMigrationHashMismatch(dir, verification.storedHash, verification.computedHash);
|
|
117
|
-
return pkg;
|
|
118
|
-
}
|
|
119
|
-
function arraysEqual(a, b) {
|
|
120
|
-
if (a.length !== b.length) return false;
|
|
121
|
-
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
function validateMetadata(metadata, filePath) {
|
|
125
|
-
const result = MigrationMetadataSchema(metadata);
|
|
126
|
-
if (result instanceof type.errors) throw errorInvalidManifest(filePath, result.summary);
|
|
127
|
-
}
|
|
128
|
-
function validateOps(ops, filePath) {
|
|
129
|
-
const result = MigrationOpsSchema(ops);
|
|
130
|
-
if (result instanceof type.errors) throw errorInvalidManifest(filePath, result.summary);
|
|
131
|
-
}
|
|
132
|
-
async function readMigrationsDir(migrationsRoot) {
|
|
133
|
-
let entries;
|
|
134
|
-
try {
|
|
135
|
-
entries = await readdir(migrationsRoot);
|
|
136
|
-
} catch (error) {
|
|
137
|
-
if (hasErrnoCode(error, "ENOENT")) return [];
|
|
138
|
-
throw error;
|
|
139
|
-
}
|
|
140
|
-
const packages = [];
|
|
141
|
-
for (const entry of entries.sort()) {
|
|
142
|
-
const entryPath = join(migrationsRoot, entry);
|
|
143
|
-
if (!(await stat(entryPath)).isDirectory()) continue;
|
|
144
|
-
const manifestPath = join(entryPath, MANIFEST_FILE);
|
|
145
|
-
try {
|
|
146
|
-
await stat(manifestPath);
|
|
147
|
-
} catch {
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
packages.push(await readMigrationPackage(entryPath));
|
|
151
|
-
}
|
|
152
|
-
return packages;
|
|
153
|
-
}
|
|
154
|
-
function formatMigrationDirName(timestamp, slug) {
|
|
155
|
-
const sanitized = slug.toLowerCase().replace(/[^a-z0-9]/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "");
|
|
156
|
-
if (sanitized.length === 0) throw errorInvalidSlug(slug);
|
|
157
|
-
const truncated = sanitized.slice(0, MAX_SLUG_LENGTH);
|
|
158
|
-
return `${timestamp.getUTCFullYear()}${String(timestamp.getUTCMonth() + 1).padStart(2, "0")}${String(timestamp.getUTCDate()).padStart(2, "0")}T${String(timestamp.getUTCHours()).padStart(2, "0")}${String(timestamp.getUTCMinutes()).padStart(2, "0")}_${truncated}`;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
//#endregion
|
|
162
|
-
export { copyFilesWithRename, formatMigrationDirName, readMigrationPackage, readMigrationsDir, writeMigrationMetadata, writeMigrationOps, writeMigrationPackage };
|
|
163
|
-
//# sourceMappingURL=io.mjs.map
|
|
5
|
+
export { copyFilesWithRename, formatMigrationDirName, materialiseMigrationPackage, readMigrationPackage, readMigrationsDir, writeMigrationMetadata, writeMigrationOps, writeMigrationPackage };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as MigrationMetadata, t as MigrationHints } from "../metadata-
|
|
1
|
+
import { n as MigrationMetadata, t as MigrationHints } from "../metadata-CSjwljJx.mjs";
|
|
2
2
|
export { type MigrationHints, type MigrationMetadata };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { n as MigrationGraph, t as MigrationEdge } from "../graph-
|
|
2
|
-
import { n as
|
|
1
|
+
import { n as MigrationGraph, t as MigrationEdge } from "../graph-Czaj8O2q.mjs";
|
|
2
|
+
import { n as OnDiskMigrationPackage } from "../package-B3Yl6DTr.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/migration-graph.d.ts
|
|
5
|
-
declare function reconstructGraph(packages: readonly
|
|
5
|
+
declare function reconstructGraph(packages: readonly OnDiskMigrationPackage[]): MigrationGraph;
|
|
6
6
|
/**
|
|
7
7
|
* Find the shortest path from `fromHash` to `toHash` using BFS over the
|
|
8
8
|
* contract-hash graph. Returns the ordered list of edges, or null if no path
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration-graph.d.mts","names":[],"sources":["../../src/migration-graph.ts"],"sourcesContent":[],"mappings":";;;;iBAsCgB,gBAAA,oBAAoC,
|
|
1
|
+
{"version":3,"file":"migration-graph.d.mts","names":[],"sources":["../../src/migration-graph.ts"],"sourcesContent":[],"mappings":";;;;iBAsCgB,gBAAA,oBAAoC,2BAA2B;;AAA/E;AAqFA;AAgDA;;;;;AA2FiB,iBA3ID,QAAA,CA4IkB,KAAA,EA3IzB,cA2IsC,EAAA,QAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EAAA,SAxInC,aAwImC,EAAA,GAAA,IAAA;AAiC/C;AAgBA;AAeA;;;;;AA0LA;AAkBA;AAwCA;AAQA;AA8DA;;;;;;;;iBAtdgB,sBAAA,QACP,4DAGG,+BACA;UAsFK,YAAA;kCACiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAiCtB,eAAA;;qBACkC;;;;;oCAIN;;;;;;;;;;UAWvB,2BAAA;;sBAEK;;;;;;;;;;;;iBAaN,oBAAA,QACP,4DAGE,8BACR;;;;;iBAqLa,mBAAA,QAA2B;;;;;;;;;iBAkB3B,QAAA,QAAgB;;;;;;iBAwChB,mBAAA,QAA2B,iBAAiB;iBAQ5C,YAAA,QAAoB;iBA8DpB,aAAA,QAAqB,0BAA0B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as EMPTY_CONTRACT_HASH } from "../constants-
|
|
1
|
+
import { a as errorDuplicateMigrationHash, n as errorAmbiguousTarget, w as errorSameSourceAndTarget, x as errorNoTarget, y as errorNoInitialMigration } from "../errors-DQsXvidG.mjs";
|
|
2
|
+
import { t as EMPTY_CONTRACT_HASH } from "../constants-B87kJAGj.mjs";
|
|
3
3
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
4
4
|
|
|
5
5
|
//#region src/queue.ts
|