@prisma-next/migration-tools 0.5.0-dev.8 → 0.5.0-dev.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/README.md +34 -22
  2. package/dist/{constants-BRi0X7B_.mjs → constants-DWV9_o2Z.mjs} +2 -2
  3. package/dist/{constants-BRi0X7B_.mjs.map → constants-DWV9_o2Z.mjs.map} +1 -1
  4. package/dist/errors-EPL_9p9f.mjs +297 -0
  5. package/dist/errors-EPL_9p9f.mjs.map +1 -0
  6. package/dist/exports/aggregate.d.mts +614 -0
  7. package/dist/exports/aggregate.d.mts.map +1 -0
  8. package/dist/exports/aggregate.mjs +611 -0
  9. package/dist/exports/aggregate.mjs.map +1 -0
  10. package/dist/exports/constants.d.mts.map +1 -1
  11. package/dist/exports/constants.mjs +2 -3
  12. package/dist/exports/errors.d.mts +68 -0
  13. package/dist/exports/errors.d.mts.map +1 -0
  14. package/dist/exports/errors.mjs +2 -0
  15. package/dist/exports/graph.d.mts +2 -0
  16. package/dist/exports/graph.mjs +1 -0
  17. package/dist/exports/hash.d.mts +52 -0
  18. package/dist/exports/hash.d.mts.map +1 -0
  19. package/dist/exports/hash.mjs +2 -0
  20. package/dist/exports/invariants.d.mts +34 -0
  21. package/dist/exports/invariants.d.mts.map +1 -0
  22. package/dist/exports/invariants.mjs +2 -0
  23. package/dist/exports/io.d.mts +66 -6
  24. package/dist/exports/io.d.mts.map +1 -1
  25. package/dist/exports/io.mjs +2 -3
  26. package/dist/exports/metadata.d.mts +2 -0
  27. package/dist/exports/metadata.mjs +1 -0
  28. package/dist/exports/migration-graph.d.mts +2 -0
  29. package/dist/exports/migration-graph.mjs +2 -0
  30. package/dist/exports/migration-ts.d.mts.map +1 -1
  31. package/dist/exports/migration-ts.mjs +2 -4
  32. package/dist/exports/migration-ts.mjs.map +1 -1
  33. package/dist/exports/migration.d.mts +15 -14
  34. package/dist/exports/migration.d.mts.map +1 -1
  35. package/dist/exports/migration.mjs +70 -43
  36. package/dist/exports/migration.mjs.map +1 -1
  37. package/dist/exports/package.d.mts +3 -0
  38. package/dist/exports/package.mjs +1 -0
  39. package/dist/exports/refs.d.mts.map +1 -1
  40. package/dist/exports/refs.mjs +3 -4
  41. package/dist/exports/refs.mjs.map +1 -1
  42. package/dist/exports/spaces.d.mts +550 -0
  43. package/dist/exports/spaces.d.mts.map +1 -0
  44. package/dist/exports/spaces.mjs +223 -0
  45. package/dist/exports/spaces.mjs.map +1 -0
  46. package/dist/graph-HMWAldoR.d.mts +28 -0
  47. package/dist/graph-HMWAldoR.d.mts.map +1 -0
  48. package/dist/hash-By50zM_E.mjs +74 -0
  49. package/dist/hash-By50zM_E.mjs.map +1 -0
  50. package/dist/invariants-Duc8f9NM.mjs +52 -0
  51. package/dist/invariants-Duc8f9NM.mjs.map +1 -0
  52. package/dist/io-D13dLvUh.mjs +239 -0
  53. package/dist/io-D13dLvUh.mjs.map +1 -0
  54. package/dist/metadata-CFvm3ayn.d.mts +2 -0
  55. package/dist/migration-graph-DGNnKDY5.mjs +523 -0
  56. package/dist/migration-graph-DGNnKDY5.mjs.map +1 -0
  57. package/dist/migration-graph-DulOITvG.d.mts +124 -0
  58. package/dist/migration-graph-DulOITvG.d.mts.map +1 -0
  59. package/dist/op-schema-D5qkXfEf.mjs +13 -0
  60. package/dist/op-schema-D5qkXfEf.mjs.map +1 -0
  61. package/dist/package-BjiZ7KDy.d.mts +21 -0
  62. package/dist/package-BjiZ7KDy.d.mts.map +1 -0
  63. package/dist/read-contract-space-contract-C3-1eyaI.mjs +298 -0
  64. package/dist/read-contract-space-contract-C3-1eyaI.mjs.map +1 -0
  65. package/package.json +42 -17
  66. package/src/aggregate/loader.ts +409 -0
  67. package/src/aggregate/marker-types.ts +16 -0
  68. package/src/aggregate/planner-types.ts +171 -0
  69. package/src/aggregate/planner.ts +158 -0
  70. package/src/aggregate/project-schema-to-space.ts +64 -0
  71. package/src/aggregate/strategies/graph-walk.ts +118 -0
  72. package/src/aggregate/strategies/synth.ts +122 -0
  73. package/src/aggregate/types.ts +89 -0
  74. package/src/aggregate/verifier.ts +230 -0
  75. package/src/assert-descriptor-self-consistency.ts +70 -0
  76. package/src/compute-extension-space-apply-path.ts +152 -0
  77. package/src/concatenate-space-apply-inputs.ts +90 -0
  78. package/src/detect-space-contract-drift.ts +91 -0
  79. package/src/emit-contract-space-artefacts.ts +70 -0
  80. package/src/errors.ts +251 -17
  81. package/src/exports/aggregate.ts +42 -0
  82. package/src/exports/errors.ts +8 -0
  83. package/src/exports/graph.ts +1 -0
  84. package/src/exports/hash.ts +2 -0
  85. package/src/exports/invariants.ts +1 -0
  86. package/src/exports/io.ts +3 -1
  87. package/src/exports/metadata.ts +1 -0
  88. package/src/exports/{dag.ts → migration-graph.ts} +3 -2
  89. package/src/exports/migration.ts +0 -1
  90. package/src/exports/package.ts +2 -0
  91. package/src/exports/spaces.ts +49 -0
  92. package/src/gather-disk-contract-space-state.ts +62 -0
  93. package/src/graph-ops.ts +57 -30
  94. package/src/graph.ts +25 -0
  95. package/src/hash.ts +91 -0
  96. package/src/invariants.ts +56 -0
  97. package/src/io.ts +163 -40
  98. package/src/metadata.ts +1 -0
  99. package/src/migration-base.ts +97 -56
  100. package/src/migration-graph.ts +676 -0
  101. package/src/op-schema.ts +11 -0
  102. package/src/package.ts +21 -0
  103. package/src/plan-all-spaces.ts +76 -0
  104. package/src/read-contract-space-contract.ts +44 -0
  105. package/src/read-contract-space-head-ref.ts +63 -0
  106. package/src/space-layout.ts +48 -0
  107. package/src/verify-contract-spaces.ts +272 -0
  108. package/dist/attestation-BnzTb0Qp.mjs +0 -65
  109. package/dist/attestation-BnzTb0Qp.mjs.map +0 -1
  110. package/dist/errors-BmiSgz1j.mjs +0 -160
  111. package/dist/errors-BmiSgz1j.mjs.map +0 -1
  112. package/dist/exports/attestation.d.mts +0 -37
  113. package/dist/exports/attestation.d.mts.map +0 -1
  114. package/dist/exports/attestation.mjs +0 -4
  115. package/dist/exports/dag.d.mts +0 -51
  116. package/dist/exports/dag.d.mts.map +0 -1
  117. package/dist/exports/dag.mjs +0 -386
  118. package/dist/exports/dag.mjs.map +0 -1
  119. package/dist/exports/types.d.mts +0 -35
  120. package/dist/exports/types.d.mts.map +0 -1
  121. package/dist/exports/types.mjs +0 -3
  122. package/dist/io-Cd6GLyjK.mjs +0 -153
  123. package/dist/io-Cd6GLyjK.mjs.map +0 -1
  124. package/dist/types-DyGXcWWp.d.mts +0 -71
  125. package/dist/types-DyGXcWWp.d.mts.map +0 -1
  126. package/src/attestation.ts +0 -81
  127. package/src/dag.ts +0 -426
  128. package/src/exports/attestation.ts +0 -2
  129. package/src/exports/types.ts +0 -10
  130. package/src/types.ts +0 -66
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aggregate.mjs","names":[],"sources":["../../src/aggregate/loader.ts","../../src/aggregate/strategies/graph-walk.ts","../../src/aggregate/project-schema-to-space.ts","../../src/aggregate/strategies/synth.ts","../../src/aggregate/planner.ts","../../src/aggregate/verifier.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { EMPTY_CONTRACT_HASH } from '../constants';\nimport { detectSpaceContractDrift } from '../detect-space-contract-drift';\nimport { readMigrationsDir } from '../io';\nimport { reconstructGraph } from '../migration-graph';\nimport type { OnDiskMigrationPackage } from '../package';\nimport { readContractSpaceContract } from '../read-contract-space-contract';\nimport { readContractSpaceHeadRef } from '../read-contract-space-head-ref';\nimport { APP_SPACE_ID, spaceMigrationDirectory } from '../space-layout';\nimport { listContractSpaceDirectories } from '../verify-contract-spaces';\nimport type { ContractSpaceAggregate, ContractSpaceMember, HydratedMigrationGraph } from './types';\n\n/**\n * Hash function used by drift detection. Defaults to a canonical-JSON +\n * SHA-256 pipeline that mirrors the framework's contract-hash convention,\n * but the loader accepts a callback so SQL-family callers can pass their\n * `coreHash` / `storageHash` derivation through unchanged.\n *\n * The contract value passed in is the framework-neutral `unknown` form;\n * callers that have already validated typed contracts can simply hand\n * the validated value back through.\n */\nexport type AggregateContractHasher = (contract: unknown) => string;\n\n/**\n * Single declared extension entry the loader needs from `Config.extensionPacks`.\n *\n * Only the subset of fields the loader operates on:\n *\n * - `id` — the space id (also the directory name under `migrations/`).\n * - `targetId` — the configured `Config.adapter.targetId` value the\n * declaring extension declared. The loader rejects mismatches against\n * the aggregate's `targetId` with `targetMismatch`.\n * - `contractSpace` — present iff the descriptor declares a contract\n * space (extensions can ship without one and remain runtime-only /\n * codec-only). Drift detection compares the descriptor's\n * `contractJson` hash against the on-disk on-disk head hash; the loader\n * rejects drift fatally.\n *\n * Typed structurally so the migration-tools layer stays framework-neutral.\n */\nexport interface DeclaredExtensionEntry {\n readonly id: string;\n readonly targetId: string;\n readonly contractSpace?: {\n readonly contractJson: unknown;\n };\n}\n\n/**\n * Inputs for {@link loadContractSpaceAggregate}.\n *\n * The loader is the **sole** descriptor-import boundary in the M2.5\n * pipeline: callers gather the descriptor data (already-validated app\n * contract, declared extension entries) and pass it through. Once the\n * loader returns, no descriptor module is imported again for this\n * aggregate's lifetime.\n */\nexport interface LoadAggregateInput {\n readonly targetId: string;\n readonly migrationsDir: string;\n readonly appContract: Contract;\n readonly declaredExtensions: ReadonlyArray<DeclaredExtensionEntry>;\n readonly validateContract: (contractJson: unknown) => Contract;\n readonly hashContract: AggregateContractHasher;\n /**\n * Hydrated migration graph for the **app member**.\n *\n * The framework-neutral migration-tools layer doesn't know how to read\n * the user's authored `migrations/` directory (the app member's\n * migration-package layout is family-aware: ops.json shape, manifest\n * keys, etc.). Callers — the SQL family today — read the user's\n * `migrations/` and hand the resulting `OnDiskMigrationPackage[]` through.\n *\n * Passing `[]` is valid (greenfield project, no authored migrations).\n * Equivalent to `migrations/` not existing or being empty.\n */\n readonly appMigrationPackages: ReadonlyArray<OnDiskMigrationPackage>;\n}\n\n/**\n * Discriminated failure variants the loader emits.\n *\n * Every variant short-circuits at first hit; the loader does not keep\n * collecting after the first violation in any phase except for layout\n * (where every layout offence is bundled into one `layoutViolation`).\n */\nexport type LoadAggregateError =\n | { readonly kind: 'layoutViolation'; readonly violations: readonly LayoutViolation[] }\n | { readonly kind: 'integrityFailure'; readonly spaceId: string; readonly detail: string }\n | { readonly kind: 'validationFailure'; readonly spaceId: string; readonly detail: string }\n | {\n readonly kind: 'driftViolation';\n readonly spaceId: string;\n readonly priorHeadHash: string;\n readonly liveHash: string;\n }\n | {\n readonly kind: 'disjointnessViolation';\n readonly element: string;\n readonly claimedBy: readonly string[];\n }\n | {\n readonly kind: 'targetMismatch';\n readonly spaceId: string;\n readonly expected: string;\n readonly actual: string;\n };\n\n/**\n * Single layout violation; bundled into a `layoutViolation` error so\n * users see every layout offence at once rather than fixing them one\n * at a time across re-runs.\n *\n * - `declaredButUnmigrated`: extension declared in `extensionPacks` with\n * a `contractSpace` but no contract-space dir on disk. Remediation:\n * `prisma-next migrate`.\n * - `orphanSpaceDir`: contract-space dir under `migrations/` for an extension\n * not in `extensionPacks`. Remediation: remove the directory, or\n * re-add the extension to `extensionPacks`.\n */\nexport type LayoutViolation =\n | { readonly kind: 'declaredButUnmigrated'; readonly spaceId: string }\n | { readonly kind: 'orphanSpaceDir'; readonly spaceId: string };\n\nexport type LoadAggregateOutput = Result<\n { readonly aggregate: ContractSpaceAggregate },\n LoadAggregateError\n>;\n\ninterface LoadedExtensionState {\n readonly entry: DeclaredExtensionEntry;\n readonly contract: Contract;\n readonly headRefHash: string;\n readonly headRefInvariants: readonly string[];\n readonly migrations: HydratedMigrationGraph;\n}\n\n/**\n * Hydrate a {@link ContractSpaceAggregate} from on-disk state and\n * caller-provided descriptor data.\n *\n * This is the **only** descriptor-import boundary in the post-M2.5\n * pipeline: callers read `extensionPacks` from `Config`, validate the\n * app contract, and pass everything through. The loader composes\n * existing migration-tools primitives — layout precheck (via\n * {@link listContractSpaceDirectories}), integrity checks (via\n * {@link readMigrationsDir} / {@link readContractSpaceHeadRef} /\n * {@link readContractSpaceContract} / `validateContract`), drift detection\n * (via {@link detectSpaceContractDrift}), and disjointness — into a\n * single typed value.\n *\n * Failure semantics: every failure variant in {@link LoadAggregateError}\n * short-circuits the load. Drift is fatal (M2.5 spec § Loader, step 5).\n */\nexport async function loadContractSpaceAggregate(\n input: LoadAggregateInput,\n): Promise<LoadAggregateOutput> {\n // 1. Validate target consistency on the app contract.\n const appContractTarget = input.appContract.target;\n if (appContractTarget !== input.targetId) {\n return notOk({\n kind: 'targetMismatch',\n spaceId: APP_SPACE_ID,\n expected: input.targetId,\n actual: appContractTarget,\n });\n }\n\n for (const entry of input.declaredExtensions) {\n if (entry.targetId !== input.targetId) {\n return notOk({\n kind: 'targetMismatch',\n spaceId: entry.id,\n expected: input.targetId,\n actual: entry.targetId,\n });\n }\n }\n\n // 2. Layout precheck: bundle every layout offence at once.\n const declaredWithSpace = input.declaredExtensions.filter((e) => e.contractSpace !== undefined);\n const declaredSpaceIds = new Set(declaredWithSpace.map((e) => e.id));\n const allDirs = await listContractSpaceDirectories(input.migrationsDir);\n // The app member is implicitly declared (it is always part of the\n // aggregate); its `migrations/<APP_SPACE_ID>/` directory may exist or\n // not (greenfield projects start with neither). Filter it out of the\n // orphan / declared-but-unmigrated checks so the layout precheck is\n // about extensions only.\n const extensionDirsOnDisk = allDirs.filter((d) => d !== APP_SPACE_ID);\n const spaceDirSet = new Set(extensionDirsOnDisk);\n\n const layoutViolations: LayoutViolation[] = [];\n for (const dir of extensionDirsOnDisk) {\n if (!declaredSpaceIds.has(dir)) {\n layoutViolations.push({ kind: 'orphanSpaceDir', spaceId: dir });\n }\n }\n for (const id of [...declaredSpaceIds].sort()) {\n if (!spaceDirSet.has(id)) {\n layoutViolations.push({ kind: 'declaredButUnmigrated', spaceId: id });\n }\n }\n if (layoutViolations.length > 0) {\n return notOk({ kind: 'layoutViolation', violations: layoutViolations });\n }\n\n // 3-5. Per-extension: read + validate + integrity-check + drift.\n const loadedExtensions: LoadedExtensionState[] = [];\n for (const entry of [...declaredWithSpace].sort((a, b) => a.id.localeCompare(b.id))) {\n const headRef = await readContractSpaceHeadRef(input.migrationsDir, entry.id);\n if (headRef === null) {\n return notOk({\n kind: 'integrityFailure',\n spaceId: entry.id,\n detail: `Head ref \\`refs/head.json\\` is missing for extension space \"${entry.id}\".`,\n });\n }\n\n let spaceContractRaw: unknown;\n try {\n spaceContractRaw = await readContractSpaceContract(input.migrationsDir, entry.id);\n } catch (error) {\n return notOk({\n kind: 'integrityFailure',\n spaceId: entry.id,\n detail: error instanceof Error ? error.message : String(error),\n });\n }\n\n let spaceContract: Contract;\n try {\n spaceContract = input.validateContract(spaceContractRaw);\n } catch (error) {\n return notOk({\n kind: 'validationFailure',\n spaceId: entry.id,\n detail: error instanceof Error ? error.message : String(error),\n });\n }\n\n if (spaceContract.target !== input.targetId) {\n return notOk({\n kind: 'targetMismatch',\n spaceId: entry.id,\n expected: input.targetId,\n actual: spaceContract.target,\n });\n }\n\n // Drift: compare descriptor's live `contractJson` to on-disk\n // `refs/head.json.hash`.\n if (entry.contractSpace) {\n const liveHash = input.hashContract(entry.contractSpace.contractJson);\n const drift = detectSpaceContractDrift(entry.id, {\n descriptorHash: liveHash,\n priorHeadHash: headRef.hash,\n });\n if (drift.kind === 'drift') {\n return notOk({\n kind: 'driftViolation',\n spaceId: entry.id,\n priorHeadHash: drift.priorHeadHash ?? '',\n liveHash: drift.descriptorHash,\n });\n }\n }\n\n // Read + integrity-check the migration packages. `readMigrationsDir`\n // re-derives `providedInvariants` and verifies migrationHash for\n // every package.\n let packages: readonly OnDiskMigrationPackage[];\n try {\n packages = await readMigrationsDir(spaceMigrationDirectory(input.migrationsDir, entry.id));\n } catch (error) {\n return notOk({\n kind: 'integrityFailure',\n spaceId: entry.id,\n detail: error instanceof Error ? error.message : String(error),\n });\n }\n\n let graph: ReturnType<typeof reconstructGraph>;\n try {\n graph = reconstructGraph(packages);\n } catch (error) {\n return notOk({\n kind: 'integrityFailure',\n spaceId: entry.id,\n detail: error instanceof Error ? error.message : String(error),\n });\n }\n\n // The on-disk head ref must be reachable in the graph. Empty graphs\n // are tolerated only when the head ref points at the empty-contract\n // sentinel (a never-emitted extension space; not a typical scenario\n // because the layout precheck would have flagged the missing\n // dir, but defensible).\n if (graph.nodes.size === 0) {\n if (headRef.hash !== EMPTY_CONTRACT_HASH) {\n return notOk({\n kind: 'integrityFailure',\n spaceId: entry.id,\n detail: `Head ref \"${headRef.hash}\" is not present in the (empty) on-disk migration graph.`,\n });\n }\n } else if (!graph.nodes.has(headRef.hash)) {\n return notOk({\n kind: 'integrityFailure',\n spaceId: entry.id,\n detail: `Head ref \"${headRef.hash}\" is not present in the on-disk migration graph.`,\n });\n }\n\n const packagesByMigrationHash = new Map<string, OnDiskMigrationPackage>(\n packages.map((p) => [p.metadata.migrationHash, p]),\n );\n\n loadedExtensions.push({\n entry,\n contract: spaceContract,\n headRefHash: headRef.hash,\n headRefInvariants: [...headRef.invariants].sort(),\n migrations: { graph, packagesByMigrationHash },\n });\n }\n\n // 6. Build app member with hydrated graph from caller-supplied packages.\n let appGraph: ReturnType<typeof reconstructGraph>;\n try {\n appGraph = reconstructGraph(input.appMigrationPackages);\n } catch (error) {\n return notOk({\n kind: 'integrityFailure',\n spaceId: APP_SPACE_ID,\n detail: error instanceof Error ? error.message : String(error),\n });\n }\n const appPackagesByMigrationHash = new Map<string, OnDiskMigrationPackage>(\n input.appMigrationPackages.map((p) => [p.metadata.migrationHash, p]),\n );\n\n const appMember: ContractSpaceMember = {\n spaceId: APP_SPACE_ID,\n contract: input.appContract,\n headRef: {\n hash: input.appContract.storage.storageHash,\n invariants: [],\n },\n migrations: {\n graph: appGraph,\n packagesByMigrationHash: appPackagesByMigrationHash,\n },\n };\n\n const extensionMembers: ContractSpaceMember[] = loadedExtensions.map((s) => ({\n spaceId: s.entry.id,\n contract: s.contract,\n headRef: {\n hash: s.headRefHash,\n invariants: s.headRefInvariants,\n },\n migrations: s.migrations,\n }));\n\n // 7. Disjointness: no two members claim the same storage element.\n const elementClaimedBy = new Map<string, string[]>();\n for (const member of [appMember, ...extensionMembers]) {\n const tables = extractTableNames(member.contract);\n for (const tableName of tables) {\n const claimers = elementClaimedBy.get(tableName);\n if (claimers) claimers.push(member.spaceId);\n else elementClaimedBy.set(tableName, [member.spaceId]);\n }\n }\n for (const [element, claimedBy] of elementClaimedBy) {\n if (claimedBy.length > 1) {\n return notOk({\n kind: 'disjointnessViolation',\n element,\n claimedBy: [...claimedBy].sort(),\n });\n }\n }\n\n return ok({\n aggregate: {\n targetId: input.targetId,\n app: appMember,\n extensions: extensionMembers,\n },\n });\n}\n\n/**\n * Extract the set of top-level storage table names from a contract.\n * Duck-typed: returns `[]` if the contract's storage shape doesn't\n * match the canonical `storage.tables: Record<string, ...>` form. A\n * future family with a different storage shape gets disjointness\n * effectively disabled (not enforced) rather than a hard failure.\n */\nfunction extractTableNames(contract: Contract): readonly string[] {\n const storage = (contract as { readonly storage?: unknown }).storage;\n if (typeof storage !== 'object' || storage === null) return [];\n const tables = (storage as { readonly tables?: unknown }).tables;\n if (typeof tables !== 'object' || tables === null) return [];\n return Object.keys(tables as Record<string, unknown>);\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport type { MigrationPlan } from '@prisma-next/framework-components/control';\nimport { EMPTY_CONTRACT_HASH } from '../../constants';\nimport { findPathWithDecision } from '../../migration-graph';\nimport type { MigrationOps } from '../../package';\nimport type { ContractMarkerRecordLike } from '../marker-types';\nimport type { AggregatePerSpacePlan } from '../planner-types';\nimport type { ContractSpaceMember } from '../types';\n\n/**\n * Outcome variants for the graph-walk strategy. Mirrors\n * {@link import('../../compute-extension-space-apply-path').ExtensionSpaceApplyPathOutcome}\n * but operates against the **already-hydrated** `member.migrations.graph`\n * instead of re-reading from disk. The aggregate planner converts\n * these into {@link import('../planner-types').AggregatePlannerError}\n * variants.\n */\nexport type GraphWalkOutcome =\n | { readonly kind: 'ok'; readonly result: AggregatePerSpacePlan }\n | { readonly kind: 'unreachable' }\n | { readonly kind: 'unsatisfiable'; readonly missing: readonly string[] };\n\nexport interface GraphWalkStrategyInputs {\n readonly aggregateTargetId: string;\n readonly member: ContractSpaceMember;\n readonly currentMarker: ContractMarkerRecordLike | null;\n /**\n * Optional ref name to decorate the resulting `PathDecision`. Used by\n * `migration apply` to surface the user-supplied `--ref <name>` in\n * structured-progress events and invariant-path error envelopes. The\n * strategy itself does not interpret it.\n */\n readonly refName?: string;\n}\n\n/**\n * Walk a member's hydrated migration graph from the live marker to\n * `member.headRef.hash`, covering every required invariant.\n *\n * Pure synchronous function — no I/O. The aggregate's loader has\n * already integrity-checked every package and reconstructed the graph;\n * this strategy just looks up ops by `migrationHash` and assembles a\n * `MigrationPlan` with `targetId` set from the aggregate (no\n * placeholder cast).\n *\n * Required invariants are computed as `headRef.invariants \\ marker.invariants`\n * — the marker already declares some invariants satisfied; the path\n * only needs to provide the remainder. Mirrors today's\n * `computeExtensionSpaceApplyPath` semantics.\n */\nexport function graphWalkStrategy(input: GraphWalkStrategyInputs): GraphWalkOutcome {\n const { aggregateTargetId, member, currentMarker, refName } = input;\n const { graph, packagesByMigrationHash } = member.migrations;\n\n const fromHash = currentMarker?.storageHash ?? EMPTY_CONTRACT_HASH;\n const markerInvariants = new Set(currentMarker?.invariants ?? []);\n const required = new Set(member.headRef.invariants.filter((id) => !markerInvariants.has(id)));\n\n const outcome = findPathWithDecision(graph, fromHash, member.headRef.hash, {\n required,\n ...(refName !== undefined ? { refName } : {}),\n });\n\n if (outcome.kind === 'unreachable') {\n return { kind: 'unreachable' };\n }\n if (outcome.kind === 'unsatisfiable') {\n return { kind: 'unsatisfiable', missing: outcome.missing };\n }\n\n const pathOps: MigrationOps[number][] = [];\n const providedInvariantsSet = new Set<string>();\n const edgeRefs: Array<{\n migrationHash: string;\n dirName: string;\n from: string;\n to: string;\n operationCount: number;\n }> = [];\n for (const edge of outcome.decision.selectedPath) {\n const pkg = packagesByMigrationHash.get(edge.migrationHash);\n if (!pkg) {\n throw new Error(\n `Migration package missing for edge ${edge.migrationHash} in space \"${member.spaceId}\". The hydrated migration graph and packagesByMigrationHash map are out of sync — this should be unreachable; report.`,\n );\n }\n for (const op of pkg.ops) pathOps.push(op);\n for (const invariant of pkg.metadata.providedInvariants) providedInvariantsSet.add(invariant);\n edgeRefs.push({\n migrationHash: edge.migrationHash,\n dirName: edge.dirName,\n from: edge.from,\n to: edge.to,\n operationCount: pkg.ops.length,\n });\n }\n\n const plan: MigrationPlan = {\n targetId: aggregateTargetId,\n spaceId: member.spaceId,\n origin: currentMarker === null ? null : { storageHash: currentMarker.storageHash },\n destination: { storageHash: member.headRef.hash },\n operations: pathOps,\n providedInvariants: [...providedInvariantsSet].sort(),\n };\n\n return {\n kind: 'ok',\n result: {\n plan,\n displayOps: pathOps,\n destinationContract: member.contract as Contract,\n strategy: 'graph-walk',\n migrationEdges: edgeRefs,\n pathDecision: outcome.decision,\n },\n };\n}\n","import type { ContractSpaceMember } from './types';\n\n/**\n * Project the introspected live schema to the slice claimed by a single\n * contract-space member.\n *\n * Returns the same `schema` value with every top-level table claimed by\n * **other** members of the aggregate removed. Tables not claimed by any\n * member flow through unchanged — the planner / verifier sees them as\n * orphans (extras in strict mode).\n *\n * Used by:\n *\n * - The aggregate planner's **synth strategy**: when synthesising a\n * plan against a member's contract, the live schema must be projected\n * to that member's slice so the planner doesn't treat tables claimed\n * by other members as \"extras\" and emit destructive ops to drop\n * them.\n * - The aggregate verifier's **schemaCheck**: projects per member so the\n * single-contract `verifySqlSchema` only sees the slice claimed by\n * the member it is checking. Closes the F23 architectural concern\n * (multi-member deployments where each member's tables look like\n * extras to every other member's verify pass).\n *\n * **Duck-typing semantics**: the helper operates on `unknown` for the\n * schema and falls through structurally if the shape doesn't match.\n * Every family today exposes `storage.tables: Record<string, ...>` and\n * the introspected schema mirrors the same shape; a future family with\n * a different storage shape gets the schema returned unchanged rather\n * than blowing up the aggregate planner.\n */\nexport function projectSchemaToSpace(\n schema: unknown,\n member: ContractSpaceMember,\n otherMembers: ReadonlyArray<ContractSpaceMember>,\n): unknown {\n if (typeof schema !== 'object' || schema === null) return schema;\n const schemaObj = schema as { readonly tables?: unknown };\n if (typeof schemaObj.tables !== 'object' || schemaObj.tables === null) return schema;\n const schemaTables = schemaObj.tables as Record<string, unknown>;\n\n const ownedByOthers = new Set<string>();\n for (const other of otherMembers) {\n if (other.spaceId === member.spaceId) continue;\n const storage = (other.contract as { readonly storage?: unknown }).storage;\n if (typeof storage !== 'object' || storage === null) continue;\n const tables = (storage as { readonly tables?: unknown }).tables;\n if (typeof tables !== 'object' || tables === null) continue;\n for (const tableName of Object.keys(tables as Record<string, unknown>)) {\n ownedByOthers.add(tableName);\n }\n }\n\n if (ownedByOthers.size === 0) return schema;\n\n const prunedTables: Record<string, unknown> = {};\n for (const [name, table] of Object.entries(schemaTables)) {\n if (!ownedByOthers.has(name)) {\n prunedTables[name] = table;\n }\n }\n\n return { ...schemaObj, tables: prunedTables };\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';\nimport type {\n ControlFamilyInstance,\n MigrationOperationPolicy,\n MigrationPlan,\n MigrationPlannerConflict,\n MigrationPlannerResult,\n TargetMigrationsCapability,\n} from '@prisma-next/framework-components/control';\nimport type { AggregatePerSpacePlan } from '../planner-types';\nimport { projectSchemaToSpace } from '../project-schema-to-space';\nimport type { ContractSpaceMember } from '../types';\n\nexport interface SynthStrategyInputs<TFamilyId extends string, TTargetId extends string> {\n readonly aggregateTargetId: string;\n readonly member: ContractSpaceMember;\n readonly otherMembers: ReadonlyArray<ContractSpaceMember>;\n readonly schemaIntrospection: unknown;\n readonly familyInstance: ControlFamilyInstance<TFamilyId, unknown>;\n readonly migrations: TargetMigrationsCapability<\n TFamilyId,\n TTargetId,\n ControlFamilyInstance<TFamilyId, unknown>\n >;\n readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, TTargetId>>;\n readonly operationPolicy: MigrationOperationPolicy;\n}\n\nexport type SynthStrategyOutcome =\n | { readonly kind: 'ok'; readonly result: AggregatePerSpacePlan }\n | { readonly kind: 'failure'; readonly conflicts: readonly MigrationPlannerConflict[] };\n\n/**\n * The {@link MigrationPlanner.plan} interface is declared as synchronous,\n * but historical and test fixture call sites have always invoked it\n * with `await` (see prior `db-apply-per-space.ts`). Tolerating a\n * Promise here keeps existing test mocks working without changing the\n * declared family SPI.\n */\ntype MaybeAsyncPlannerResult = MigrationPlannerResult | Promise<MigrationPlannerResult>;\n\n/**\n * Synthesise a migration plan for a single member by projecting the\n * live schema down to that member's claimed slice and delegating to\n * the family's `createPlanner(...).plan(...)`.\n *\n * Pre-projection (via {@link projectSchemaToSpace}) closes the F23\n * concern: without it, the family's planner sees other members'\n * tables as \"extras\" and emits destructive ops to drop them. With it,\n * the planner only sees the slice this member claims.\n *\n * The synthesised plan's `targetId` is set from `aggregateTargetId`\n * (the aggregate's ambient target). The family's planner does not\n * stamp `targetId` on the produced plan; the aggregate planner is\n * the single point that knows the target.\n *\n * Used by:\n *\n * - The app member by default (CLI policy\n * `ignoreGraphFor: { app.spaceId }`).\n * - Any extension member whose `headRef.invariants` is empty (the\n * strategy selector falls back to synth when graph-walk isn't\n * required).\n */\nexport async function synthStrategy<TFamilyId extends string, TTargetId extends string>(\n input: SynthStrategyInputs<TFamilyId, TTargetId>,\n): Promise<SynthStrategyOutcome> {\n const projectedSchema = projectSchemaToSpace(\n input.schemaIntrospection,\n input.member,\n input.otherMembers,\n );\n\n const planner = input.migrations.createPlanner(input.familyInstance);\n const plannerResult: MigrationPlannerResult = await (planner.plan({\n contract: input.member.contract,\n schema: projectedSchema,\n policy: input.operationPolicy,\n fromContract: null,\n frameworkComponents: input.frameworkComponents,\n spaceId: input.member.spaceId,\n }) as MaybeAsyncPlannerResult);\n\n if (plannerResult.kind === 'failure') {\n return { kind: 'failure', conflicts: plannerResult.conflicts };\n }\n\n const synthedPlan = plannerResult.plan;\n // The family planner returns a class-instance-shaped plan whose\n // `destination` / `operations` are accessors on the prototype, often\n // backed by private fields. A naive spread (`{ ...synthedPlan }`)\n // would lose those accessors and produce a plan with\n // `destination: undefined`; rebinding the prototype on a plain\n // object would break private-field access. We instead wrap the plan\n // in a Proxy that forwards every read except `targetId`, which is\n // stamped from the aggregate's ambient target. This preserves the\n // planner's class semantics while keeping the aggregate the single\n // source of truth for `targetId`.\n const plan: MigrationPlan = new Proxy(synthedPlan, {\n get(target, prop) {\n if (prop === 'targetId') return input.aggregateTargetId;\n // Forward `this` as the original target so prototype-bound\n // private fields (#destination, #operations, …) resolve.\n return Reflect.get(target, prop, target);\n },\n has(target, prop) {\n if (prop === 'targetId') return true;\n return Reflect.has(target, prop);\n },\n });\n\n return {\n kind: 'ok',\n result: {\n plan,\n displayOps: synthedPlan.operations,\n destinationContract: input.member.contract as Contract,\n strategy: 'synth',\n },\n };\n}\n","import { notOk, ok } from '@prisma-next/utils/result';\nimport type {\n AggregatePerSpacePlan,\n AggregatePlannerError,\n AggregatePlannerInput,\n AggregatePlannerOutput,\n} from './planner-types';\nimport { graphWalkStrategy } from './strategies/graph-walk';\nimport { synthStrategy } from './strategies/synth';\nimport type { ContractSpaceMember } from './types';\n\nexport type {\n AggregateCurrentDBState,\n AggregatePerSpacePlan,\n AggregatePlannerError,\n AggregatePlannerInput,\n AggregatePlannerOutput,\n AggregatePlannerSuccess,\n CallerPolicy,\n} from './planner-types';\n\n/**\n * Plan a migration across every member of a {@link ContractSpaceAggregate}.\n *\n * Strategy selection per member, in order; first match wins:\n *\n * 1. If `callerPolicy.ignoreGraphFor.has(member.spaceId)`:\n * - If `member.headRef.invariants` is empty → synth.\n * - Else → `policyConflict` (synth cannot satisfy authored invariants).\n * 2. Else if `member.migrations.graph` is non-empty AND graph-walk\n * succeeds → graph-walk.\n * 3. Else if `member.headRef.invariants` is empty → synth.\n * 4. Else → graph-walk failure → `extensionPathUnreachable` /\n * `extensionPathUnsatisfiable`.\n *\n * Output `applyOrder` is `[...aggregate.extensions.map(spaceId), aggregate.app.spaceId]`\n * — extensions alphabetical, then app — matching today's\n * `concatenateSpaceApplyInputs` ordering. This preserves\n * `MultiSpaceRunnerFailure.failingSpace` attribution byte-for-byte.\n *\n * Every emitted `MigrationPlan` has `targetId = aggregate.targetId`.\n * No placeholder cast; no patch step.\n */\nexport async function planAggregate<TFamilyId extends string, TTargetId extends string>(\n input: AggregatePlannerInput<TFamilyId, TTargetId>,\n): Promise<AggregatePlannerOutput> {\n const { aggregate, currentDBState, callerPolicy } = input;\n const allMembers: ReadonlyArray<ContractSpaceMember> = [aggregate.app, ...aggregate.extensions];\n\n const perSpace = new Map<string, AggregatePerSpacePlan>();\n\n // Iterate in apply order so a per-member error short-circuits the\n // walk in the same order the runner would walk inputs.\n const orderedMembers: ReadonlyArray<ContractSpaceMember> = [\n ...aggregate.extensions,\n aggregate.app,\n ];\n\n for (const member of orderedMembers) {\n const otherMembers = allMembers.filter((m) => m.spaceId !== member.spaceId);\n const currentMarker = currentDBState.markersBySpaceId.get(member.spaceId) ?? null;\n\n const ignoreGraph = callerPolicy.ignoreGraphFor.has(member.spaceId);\n const invariantsRequired = member.headRef.invariants.length > 0;\n\n if (ignoreGraph && invariantsRequired) {\n const conflict: AggregatePlannerError = {\n kind: 'policyConflict',\n spaceId: member.spaceId,\n detail: `\\`callerPolicy.ignoreGraphFor\\` requested for space \"${member.spaceId}\", but the member declares non-empty head-ref invariants (${member.headRef.invariants.join(', ')}). Synthesising a plan from the contract IR cannot satisfy authored invariants — the graph must be walked. Either remove \"${member.spaceId}\" from \\`ignoreGraphFor\\` or amend the on-disk head ref to declare zero invariants.`,\n };\n return notOk(conflict);\n }\n\n if (ignoreGraph) {\n const synthOutcome = await synthStrategy({\n aggregateTargetId: aggregate.targetId,\n member,\n otherMembers,\n schemaIntrospection: currentDBState.schemaIntrospection,\n familyInstance: input.familyInstance,\n migrations: input.migrations,\n frameworkComponents: input.frameworkComponents,\n operationPolicy: input.operationPolicy,\n });\n if (synthOutcome.kind === 'failure') {\n return notOk({\n kind: 'appSynthFailure',\n spaceId: member.spaceId,\n conflicts: synthOutcome.conflicts,\n });\n }\n perSpace.set(member.spaceId, synthOutcome.result);\n continue;\n }\n\n // Try graph-walk first when the graph has nodes; fall back to synth\n // when the graph is empty AND no invariants are required.\n if (member.migrations.graph.nodes.size > 0) {\n const walked = graphWalkStrategy({\n aggregateTargetId: aggregate.targetId,\n member,\n currentMarker,\n });\n if (walked.kind === 'ok') {\n perSpace.set(member.spaceId, walked.result);\n continue;\n }\n if (walked.kind === 'unreachable') {\n return notOk({\n kind: 'extensionPathUnreachable',\n spaceId: member.spaceId,\n target: member.headRef.hash,\n });\n }\n // unsatisfiable — surface\n return notOk({\n kind: 'extensionPathUnsatisfiable',\n spaceId: member.spaceId,\n missingInvariants: walked.missing,\n });\n }\n\n // Empty graph: synth is the only option, and it can only satisfy\n // empty-invariant members.\n if (invariantsRequired) {\n return notOk({\n kind: 'extensionPathUnsatisfiable',\n spaceId: member.spaceId,\n missingInvariants: [...member.headRef.invariants].sort(),\n });\n }\n\n const synthOutcome = await synthStrategy({\n aggregateTargetId: aggregate.targetId,\n member,\n otherMembers,\n schemaIntrospection: currentDBState.schemaIntrospection,\n familyInstance: input.familyInstance,\n migrations: input.migrations,\n frameworkComponents: input.frameworkComponents,\n operationPolicy: input.operationPolicy,\n });\n if (synthOutcome.kind === 'failure') {\n return notOk({\n kind: 'appSynthFailure',\n spaceId: member.spaceId,\n conflicts: synthOutcome.conflicts,\n });\n }\n perSpace.set(member.spaceId, synthOutcome.result);\n }\n\n return ok({\n perSpace,\n applyOrder: [...aggregate.extensions.map((m) => m.spaceId), aggregate.app.spaceId],\n });\n}\n","import type { Result } from '@prisma-next/utils/result';\nimport { notOk, ok } from '@prisma-next/utils/result';\nimport type { ContractMarkerRecordLike } from './marker-types';\nimport { projectSchemaToSpace } from './project-schema-to-space';\nimport type { ContractSpaceAggregate, ContractSpaceMember } from './types';\n\n/**\n * Caller policy for the aggregate verifier. Today's only knob is\n * `mode`: `strict` treats orphan elements (live tables not claimed by\n * any aggregate member) as errors; `lenient` treats them as\n * informational. Maps directly to `db verify --strict`.\n */\nexport interface AggregateVerifierInput<TSchemaResult> {\n readonly aggregate: ContractSpaceAggregate;\n readonly markersBySpaceId: ReadonlyMap<string, ContractMarkerRecordLike | null>;\n readonly schemaIntrospection: unknown;\n readonly mode: 'strict' | 'lenient';\n /**\n * Caller-supplied per-space schema verifier. The CLI wires this to\n * the family's `verifySqlSchema` (SQL) / equivalent (other\n * families). The aggregate verifier projects the schema to the\n * member's slice via {@link projectSchemaToSpace} before invoking\n * the callback, so single-contract semantics are preserved.\n *\n * Typed structurally with a generic `TSchemaResult` so the\n * migration-tools layer doesn't depend on the SQL family's\n * `VerifySqlSchemaResult`. CLI callers pass the family's type\n * through unchanged.\n */\n readonly verifySchemaForMember: (\n projectedSchema: unknown,\n member: ContractSpaceMember,\n mode: 'strict' | 'lenient',\n ) => TSchemaResult;\n}\n\n/**\n * Marker-check result per member. Mirrors the four cases the\n * `verifyContractSpaces` primitive surfaces today, plus an `'absent'`\n * case for greenfield spaces (no marker row written yet — `db init`\n * not run).\n */\nexport type MarkerCheckResult =\n | { readonly kind: 'ok' }\n | { readonly kind: 'absent' }\n | {\n readonly kind: 'hashMismatch';\n readonly markerHash: string;\n readonly expected: string;\n }\n | { readonly kind: 'missingInvariants'; readonly missing: readonly string[] };\n\nexport interface MarkerCheckSection {\n readonly perSpace: ReadonlyMap<string, MarkerCheckResult>;\n readonly orphanMarkers: readonly {\n readonly spaceId: string;\n readonly row: ContractMarkerRecordLike;\n }[];\n}\n\n/**\n * A live storage element (today: a top-level table) not claimed by any\n * member of the aggregate. The aggregate verifier always reports these;\n * the caller decides what to do — `db verify --strict` treats them as\n * errors, the lenient default treats them as informational.\n *\n * Today only `kind: 'table'` exists. The discriminated shape leaves\n * room for orphan columns / indexes / sequences in the future without\n * breaking the type contract.\n */\nexport type OrphanElement = { readonly kind: 'table'; readonly name: string };\n\nexport interface SchemaCheckSection<TSchemaResult> {\n readonly perSpace: ReadonlyMap<string, TSchemaResult>;\n /**\n * Live elements present in the introspected schema that are not\n * claimed by **any** aggregate member. Sorted alphabetically by name.\n */\n readonly orphanElements: readonly OrphanElement[];\n}\n\nexport interface AggregateVerifierSuccess<TSchemaResult> {\n readonly markerCheck: MarkerCheckSection;\n readonly schemaCheck: SchemaCheckSection<TSchemaResult>;\n}\n\nexport type AggregateVerifierError = {\n readonly kind: 'introspectionFailure';\n readonly detail: string;\n};\n\nexport type AggregateVerifierOutput<TSchemaResult> = Result<\n AggregateVerifierSuccess<TSchemaResult>,\n AggregateVerifierError\n>;\n\n/**\n * Verify a {@link ContractSpaceAggregate} against the live database\n * state. Bundles two checks:\n *\n * - `markerCheck` per member: compare the live marker row against the\n * member's `headRef.hash` + `headRef.invariants`. Absence is a\n * distinct kind, not an error (callers — `db verify` strict vs\n * `db init` precondition — choose how to interpret it).\n * - `schemaCheck` per member: project the live schema to the slice\n * the member claims via {@link projectSchemaToSpace}, then delegate\n * to the caller-supplied `verifySchemaForMember`. The pre-projection\n * means the family's single-contract verifier no longer sees other\n * members' tables as `extras`, so a multi-member deployment never\n * surfaces cross-member tables as orphaned schema elements.\n *\n * `markerCheck.orphanMarkers` lists every marker row whose `space` is\n * not a member of the aggregate. `db verify` callers reject orphans;\n * future tooling may not.\n *\n * Pure synchronous function; no I/O. The caller (CLI) gathers\n * `markersBySpaceId` and `schemaIntrospection` ahead of the call.\n */\nexport function verifyAggregate<TSchemaResult>(\n input: AggregateVerifierInput<TSchemaResult>,\n): AggregateVerifierOutput<TSchemaResult> {\n try {\n return runVerifyAggregate(input);\n } catch (error) {\n return notOk({\n kind: 'introspectionFailure',\n detail: error instanceof Error ? error.message : String(error),\n });\n }\n}\n\nfunction runVerifyAggregate<TSchemaResult>(\n input: AggregateVerifierInput<TSchemaResult>,\n): AggregateVerifierOutput<TSchemaResult> {\n const { aggregate, markersBySpaceId, schemaIntrospection, mode, verifySchemaForMember } = input;\n const allMembers: ReadonlyArray<ContractSpaceMember> = [aggregate.app, ...aggregate.extensions];\n const memberSpaceIds = new Set(allMembers.map((m) => m.spaceId));\n\n // Marker check per member.\n const markerPerSpace = new Map<string, MarkerCheckResult>();\n for (const member of allMembers) {\n const marker = markersBySpaceId.get(member.spaceId) ?? null;\n if (marker === null) {\n markerPerSpace.set(member.spaceId, { kind: 'absent' });\n continue;\n }\n if (marker.storageHash !== member.headRef.hash) {\n markerPerSpace.set(member.spaceId, {\n kind: 'hashMismatch',\n markerHash: marker.storageHash,\n expected: member.headRef.hash,\n });\n continue;\n }\n const markerInvariants = new Set(marker.invariants);\n const missing = member.headRef.invariants.filter((id) => !markerInvariants.has(id));\n if (missing.length > 0) {\n markerPerSpace.set(member.spaceId, {\n kind: 'missingInvariants',\n missing: [...missing].sort(),\n });\n continue;\n }\n markerPerSpace.set(member.spaceId, { kind: 'ok' });\n }\n\n // Orphan markers: entries in markersBySpaceId whose spaceId is not a\n // member of the aggregate.\n const orphanMarkers: { spaceId: string; row: ContractMarkerRecordLike }[] = [];\n for (const [spaceId, row] of markersBySpaceId) {\n if (row !== null && !memberSpaceIds.has(spaceId)) {\n orphanMarkers.push({ spaceId, row });\n }\n }\n orphanMarkers.sort((a, b) => a.spaceId.localeCompare(b.spaceId));\n\n // Schema check per member (with per-space pre-projection).\n const schemaPerSpace = new Map<string, TSchemaResult>();\n for (const member of allMembers) {\n const others = allMembers.filter((m) => m.spaceId !== member.spaceId);\n const projected = projectSchemaToSpace(schemaIntrospection, member, others);\n schemaPerSpace.set(member.spaceId, verifySchemaForMember(projected, member, mode));\n }\n\n return ok({\n markerCheck: {\n perSpace: markerPerSpace,\n orphanMarkers,\n },\n schemaCheck: {\n perSpace: schemaPerSpace,\n orphanElements: detectOrphanElements(schemaIntrospection, allMembers),\n },\n });\n}\n\n/**\n * Live tables not claimed by any aggregate member. Duck-typed against\n * the introspected schema's `tables` map; schemas whose shape doesn't\n * match return an empty list (consistent with\n * {@link projectSchemaToSpace}'s fall-through).\n */\nfunction detectOrphanElements(\n schemaIntrospection: unknown,\n members: ReadonlyArray<ContractSpaceMember>,\n): readonly OrphanElement[] {\n if (typeof schemaIntrospection !== 'object' || schemaIntrospection === null) return [];\n const liveTables = (schemaIntrospection as { readonly tables?: unknown }).tables;\n if (typeof liveTables !== 'object' || liveTables === null) return [];\n\n const claimedTables = new Set<string>();\n for (const member of members) {\n const storage = (member.contract as { readonly storage?: unknown }).storage;\n if (typeof storage !== 'object' || storage === null) continue;\n const tables = (storage as { readonly tables?: unknown }).tables;\n if (typeof tables !== 'object' || tables === null) continue;\n for (const tableName of Object.keys(tables as Record<string, unknown>)) {\n claimedTables.add(tableName);\n }\n }\n\n const orphans: OrphanElement[] = [];\n for (const tableName of Object.keys(liveTables as Record<string, unknown>)) {\n if (!claimedTables.has(tableName)) {\n orphans.push({ kind: 'table', name: tableName });\n }\n }\n orphans.sort((a, b) => a.name.localeCompare(b.name));\n return orphans;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA4JA,eAAsB,2BACpB,OAC8B;CAE9B,MAAM,oBAAoB,MAAM,YAAY;CAC5C,IAAI,sBAAsB,MAAM,UAC9B,OAAO,MAAM;EACX,MAAM;EACN,SAAS;EACT,UAAU,MAAM;EAChB,QAAQ;EACT,CAAC;CAGJ,KAAK,MAAM,SAAS,MAAM,oBACxB,IAAI,MAAM,aAAa,MAAM,UAC3B,OAAO,MAAM;EACX,MAAM;EACN,SAAS,MAAM;EACf,UAAU,MAAM;EAChB,QAAQ,MAAM;EACf,CAAC;CAKN,MAAM,oBAAoB,MAAM,mBAAmB,QAAQ,MAAM,EAAE,kBAAkB,KAAA,EAAU;CAC/F,MAAM,mBAAmB,IAAI,IAAI,kBAAkB,KAAK,MAAM,EAAE,GAAG,CAAC;CAOpE,MAAM,uBAAsB,MANN,6BAA6B,MAAM,cAAc,EAMnC,QAAQ,MAAM,MAAM,aAAa;CACrE,MAAM,cAAc,IAAI,IAAI,oBAAoB;CAEhD,MAAM,m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../src/constants.ts"],"sourcesContent":[],"mappings":";;AAIA;;;cAAa"}
1
+ {"version":3,"file":"constants.d.mts","names":[],"sources":["../../src/constants.ts"],"mappings":";;AAIA;;;cAAa,mBAAA"}
@@ -1,3 +1,2 @@
1
- import { t as EMPTY_CONTRACT_HASH } from "../constants-BRi0X7B_.mjs";
2
-
3
- export { EMPTY_CONTRACT_HASH };
1
+ import { t as EMPTY_CONTRACT_HASH } from "../constants-DWV9_o2Z.mjs";
2
+ export { EMPTY_CONTRACT_HASH };
@@ -0,0 +1,68 @@
1
+ //#region src/errors.d.ts
2
+ /**
3
+ * Structured error for migration tooling operations.
4
+ *
5
+ * Follows the NAMESPACE.SUBCODE convention from ADR 027. All codes live under
6
+ * the MIGRATION namespace. These are tooling-time errors (file I/O, hash
7
+ * verification, migration history reconstruction), distinct from the runtime
8
+ * MIGRATION.* codes for apply-time failures (PRECHECK_FAILED, POSTCHECK_FAILED,
9
+ * etc.).
10
+ *
11
+ * Fields:
12
+ * - code: Stable machine-readable code (MIGRATION.SUBCODE)
13
+ * - category: Always 'MIGRATION'
14
+ * - why: Explains the cause in plain language
15
+ * - fix: Actionable remediation step
16
+ * - details: Machine-readable structured data for agents
17
+ */
18
+ declare class MigrationToolsError extends Error {
19
+ readonly code: string;
20
+ readonly category: "MIGRATION";
21
+ readonly why: string;
22
+ readonly fix: string;
23
+ readonly details: Record<string, unknown> | undefined;
24
+ constructor(code: string, summary: string, options: {
25
+ readonly why: string;
26
+ readonly fix: string;
27
+ readonly details?: Record<string, unknown>;
28
+ });
29
+ static is(error: unknown): error is MigrationToolsError;
30
+ }
31
+ declare function errorInvalidJson(filePath: string, parseError: string): MigrationToolsError;
32
+ declare function errorDescriptorHeadHashMismatch(args: {
33
+ readonly extensionId: string;
34
+ readonly recomputedHash: string;
35
+ readonly headRefHash: string;
36
+ }): MigrationToolsError;
37
+ /**
38
+ * Wire-shape edge surfaced through the JSON envelope's
39
+ * `meta.structuralPath` of `MIGRATION.NO_INVARIANT_PATH`. Slim by design —
40
+ * authoring metadata (`createdAt`, `labels`) lives on `MigrationEdge` but
41
+ * is intentionally dropped here so the envelope stays stable across
42
+ * graph-internal refactors.
43
+ *
44
+ * Stability: any field added here is part of the public CLI JSON contract.
45
+ * Callers (CLI consumers, agents) must be able to treat
46
+ * `(dirName, migrationHash, from, to, invariants)` as the canonical shape.
47
+ */
48
+ interface NoInvariantPathStructuralEdge {
49
+ readonly dirName: string;
50
+ readonly migrationHash: string;
51
+ readonly from: string;
52
+ readonly to: string;
53
+ readonly invariants: readonly string[];
54
+ }
55
+ declare function errorNoInvariantPath(args: {
56
+ readonly refName?: string;
57
+ readonly required: readonly string[];
58
+ readonly missing: readonly string[];
59
+ readonly structuralPath: readonly NoInvariantPathStructuralEdge[];
60
+ }): MigrationToolsError;
61
+ declare function errorUnknownInvariant(args: {
62
+ readonly refName?: string;
63
+ readonly unknown: readonly string[];
64
+ readonly declared: readonly string[];
65
+ }): MigrationToolsError;
66
+ //#endregion
67
+ export { MigrationToolsError, type NoInvariantPathStructuralEdge, errorDescriptorHeadHashMismatch, errorInvalidJson, errorNoInvariantPath, errorUnknownInvariant };
68
+ //# sourceMappingURL=errors.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.mts","names":[],"sources":["../../src/errors.ts"],"mappings":";;AAmCA;;;;;;;;;;;;;;;cAAa,mBAAA,SAA4B,KAAA;EAAA,SAC9B,IAAA;EAAA,SACA,QAAA;EAAA,SACA,GAAA;EAAA,SACA,GAAA;EAAA,SACA,OAAA,EAAS,MAAA;cAGhB,IAAA,UACA,OAAA,UACA,OAAA;IAAA,SACW,GAAA;IAAA,SACA,GAAA;IAAA,SACA,OAAA,GAAU,MAAA;EAAA;EAAA,OAWhB,EAAA,CAAG,KAAA,YAAiB,KAAA,IAAS,mBAAA;AAAA;AAAA,iBA0BtB,gBAAA,CAAiB,QAAA,UAAkB,UAAA,WAAqB,mBAAA;AAAA,iBA6ExD,+BAAA,CAAgC,IAAA;EAAA,SACrC,WAAA;EAAA,SACA,cAAA;EAAA,SACA,WAAA;AAAA,IACP,mBAAA;;;;;;AA0NJ;;;;;;UAlCiB,6BAAA;EAAA,SACN,OAAA;EAAA,SACA,aAAA;EAAA,SACA,IAAA;EAAA,SACA,EAAA;EAAA,SACA,UAAA;AAAA;AAAA,iBAGK,oBAAA,CAAqB,IAAA;EAAA,SAC1B,OAAA;EAAA,SACA,QAAA;EAAA,SACA,OAAA;EAAA,SACA,cAAA,WAAyB,6BAAA;AAAA,IAChC,mBAAA;AAAA,iBAqBY,qBAAA,CAAsB,IAAA;EAAA,SAC3B,OAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA;AAAA,IACP,mBAAA"}
@@ -0,0 +1,2 @@
1
+ import { E as errorUnknownInvariant, r as errorDescriptorHeadHashMismatch, t as MigrationToolsError, u as errorInvalidJson, x as errorNoInvariantPath } from "../errors-EPL_9p9f.mjs";
2
+ export { MigrationToolsError, errorDescriptorHeadHashMismatch, errorInvalidJson, errorNoInvariantPath, errorUnknownInvariant };
@@ -0,0 +1,2 @@
1
+ import { n as MigrationGraph, t as MigrationEdge } from "../graph-HMWAldoR.mjs";
2
+ export { type MigrationEdge, type MigrationGraph };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,52 @@
1
+ import { n as OnDiskMigrationPackage, t as MigrationOps } from "../package-BjiZ7KDy.mjs";
2
+ import { n as MigrationMetadata } from "../metadata-CFvm3ayn.mjs";
3
+
4
+ //#region src/hash.d.ts
5
+ interface VerifyResult {
6
+ readonly ok: boolean;
7
+ readonly reason?: 'mismatch';
8
+ readonly storedHash: string;
9
+ readonly computedHash: string;
10
+ }
11
+ /**
12
+ * Content-addressed migration hash over (metadata envelope sans
13
+ * contracts/hints/signature, ops). See ADR 199 — Storage-only migration
14
+ * identity for the rationale: contracts are anchored separately by the
15
+ * storage-hash bookends inside the envelope; planner hints are advisory
16
+ * and must not affect identity.
17
+ *
18
+ * The integrity check is purely structural, not semantic. The function
19
+ * canonicalizes its inputs via `sortKeys` (recursive) + `JSON.stringify`
20
+ * and hashes the result. Target-specific operation payloads (`step.sql`,
21
+ * Mongo's pipeline AST, …) are hashed verbatim — no per-target
22
+ * normalization is required, because what's being verified is "do the
23
+ * on-disk bytes still produce their recorded hash", not "do two
24
+ * semantically-equivalent migrations hash the same". The latter is an
25
+ * emit-drift concern (ADR 192 step 2).
26
+ *
27
+ * The symmetry across write and read holds because `JSON.parse(
28
+ * JSON.stringify(x))` round-trips JSON-safe values losslessly and
29
+ * `sortKeys` is idempotent and deterministic — write-time and read-time
30
+ * canonicalization produce the same canonical bytes regardless of
31
+ * source-side key ordering or whitespace.
32
+ *
33
+ * The `migrationHash` field on the metadata is stripped before hashing
34
+ * so the function can be used both at write time (when no hash exists
35
+ * yet) and at verify time (rehashing an already-attested record).
36
+ */
37
+ declare function computeMigrationHash(metadata: Omit<MigrationMetadata, 'migrationHash'> & {
38
+ readonly migrationHash?: string;
39
+ }, ops: MigrationOps): string;
40
+ /**
41
+ * Re-hash an in-memory migration package and compare against the stored
42
+ * `migrationHash`. See `computeMigrationHash` for the canonicalization rules.
43
+ *
44
+ * Returns `{ ok: true }` when the package is internally consistent, or
45
+ * `{ ok: false, reason: 'mismatch', storedHash, computedHash }` when it is
46
+ * not — typically a sign of FS corruption, partial writes, or a post-emit
47
+ * hand edit.
48
+ */
49
+ declare function verifyMigrationHash(pkg: OnDiskMigrationPackage): VerifyResult;
50
+ //#endregion
51
+ export { type VerifyResult, computeMigrationHash, verifyMigrationHash };
52
+ //# sourceMappingURL=hash.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.d.mts","names":[],"sources":["../../src/hash.ts"],"mappings":";;;;UAKiB,YAAA;EAAA,SACN,EAAA;EAAA,SACA,MAAA;EAAA,SACA,UAAA;EAAA,SACA,YAAA;AAAA;;;;;;;AAiCX;;;;;;;;;;;;;;;;AA+BA;;;;iBA/BgB,oBAAA,CACd,QAAA,EAAU,IAAA,CAAK,iBAAA;EAAA,SAAiD,aAAA;AAAA,GAChE,GAAA,EAAK,YAAA;;;;;;;;;;iBA6BS,mBAAA,CAAoB,GAAA,EAAK,sBAAA,GAAyB,YAAA"}
@@ -0,0 +1,2 @@
1
+ import { n as verifyMigrationHash, t as computeMigrationHash } from "../hash-By50zM_E.mjs";
2
+ export { computeMigrationHash, verifyMigrationHash };
@@ -0,0 +1,34 @@
1
+ import { t as MigrationOps } from "../package-BjiZ7KDy.mjs";
2
+
3
+ //#region src/invariants.d.ts
4
+ /**
5
+ * Hygiene check for `invariantId`. Rejects empty values plus any
6
+ * whitespace or control character (including Unicode whitespace like
7
+ * NBSP and em space, which are visually identical to ASCII space and
8
+ * routinely sneak in via paste).
9
+ */
10
+ declare function validateInvariantId(invariantId: string): boolean;
11
+ /**
12
+ * Walk a migration's operations and produce its `providedInvariants`
13
+ * aggregate: the sorted, deduplicated list of `invariantId`s declared
14
+ * by ops in the migration. Ops without an `invariantId` are skipped.
15
+ *
16
+ * Both `data`-class ops (data-transforms, e.g. backfills) and
17
+ * `additive`-class opaque DDL (e.g. cipherstash's vendored EQL bundle
18
+ * via `installEqlBundleOp`) may declare invariantIds: the
19
+ * `operationClass` axis classifies *policy gating* (which kinds of ops
20
+ * a `db init` / `db update` policy permits), while `invariantId`
21
+ * classifies *marker bookkeeping* (which named bundles of work a
22
+ * future regeneration knows to skip). The two concerns are
23
+ * intentionally orthogonal — an extension can ship additive
24
+ * non-IR-derivable DDL (the only way the planner can know the bundle
25
+ * is already applied is via the invariantId on the marker) without
26
+ * needing to mis-classify it as `data`-class.
27
+ *
28
+ * Throws `MIGRATION.INVALID_INVARIANT_ID` on a malformed id and
29
+ * `MIGRATION.DUPLICATE_INVARIANT_IN_EDGE` on duplicates.
30
+ */
31
+ declare function deriveProvidedInvariants(ops: MigrationOps): readonly string[];
32
+ //#endregion
33
+ export { deriveProvidedInvariants, validateInvariantId };
34
+ //# sourceMappingURL=invariants.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invariants.d.mts","names":[],"sources":["../../src/invariants.ts"],"mappings":";;;;;AAUA;;;;iBAAgB,mBAAA,CAAoB,WAAA;AAyBpC;;;;;;;;;;;;;;;;;;;;AAAA,iBAAgB,wBAAA,CAAyB,GAAA,EAAK,YAAA"}
@@ -0,0 +1,2 @@
1
+ import { n as validateInvariantId, t as deriveProvidedInvariants } from "../invariants-Duc8f9NM.mjs";
2
+ export { deriveProvidedInvariants, validateInvariantId };
@@ -1,7 +1,67 @@
1
- import { a as MigrationManifest, o as MigrationOps, t as MigrationBundle } from "../types-DyGXcWWp.mjs";
1
+ import { n as OnDiskMigrationPackage, t as MigrationOps } from "../package-BjiZ7KDy.mjs";
2
+ import { MigrationMetadata, MigrationPackage } from "@prisma-next/framework-components/control";
2
3
 
3
4
  //#region src/io.d.ts
4
- declare function writeMigrationPackage(dir: string, manifest: MigrationManifest, ops: MigrationOps): Promise<void>;
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>;
41
+ /**
42
+ * Idempotent variant of {@link materialiseMigrationPackage}: writes the
43
+ * package only if `<targetDir>/<pkg.dirName>/` does not already exist on
44
+ * disk as a directory; returns `{ written: false }` when the package
45
+ * directory is present (no rewrite, no comparison — by-existence skip).
46
+ *
47
+ * Concretely:
48
+ * - existing directory → skip silently, return `{ written: false }`.
49
+ * - missing path → write three files via {@link materialiseMigrationPackage},
50
+ * return `{ written: true }`.
51
+ * - path exists but is not a directory (file/symlink) → treated as
52
+ * missing; {@link materialiseMigrationPackage} will attempt creation
53
+ * and fail with an appropriate OS error.
54
+ * - any other I/O error from `stat` → propagated unchanged.
55
+ *
56
+ * Used by the CLI's `runContractSpaceExtensionMigrationsPass` to
57
+ * materialise extension migration packages into a project's
58
+ * `migrations/<spaceId>/` directory, and by extension-package tests
59
+ * that mirror the same idempotent-rematerialise property locally
60
+ * without taking a CLI dependency.
61
+ */
62
+ declare function materialiseExtensionMigrationPackageIfMissing(targetDir: string, pkg: MigrationPackage): Promise<{
63
+ readonly written: boolean;
64
+ }>;
5
65
  /**
6
66
  * Copy a list of files into `destDir`, optionally renaming each one.
7
67
  *
@@ -17,11 +77,11 @@ declare function copyFilesWithRename(destDir: string, files: readonly {
17
77
  readonly sourcePath: string;
18
78
  readonly destName: string;
19
79
  }[]): Promise<void>;
20
- declare function writeMigrationManifest(dir: string, manifest: MigrationManifest): Promise<void>;
80
+ declare function writeMigrationMetadata(dir: string, metadata: MigrationMetadata): Promise<void>;
21
81
  declare function writeMigrationOps(dir: string, ops: MigrationOps): Promise<void>;
22
- declare function readMigrationPackage(dir: string): Promise<MigrationBundle>;
23
- declare function readMigrationsDir(migrationsRoot: string): Promise<readonly MigrationBundle[]>;
82
+ declare function readMigrationPackage(dir: string): Promise<OnDiskMigrationPackage>;
83
+ declare function readMigrationsDir(migrationsRoot: string): Promise<readonly OnDiskMigrationPackage[]>;
24
84
  declare function formatMigrationDirName(timestamp: Date, slug: string): string;
25
85
  //#endregion
26
- export { copyFilesWithRename, formatMigrationDirName, readMigrationPackage, readMigrationsDir, writeMigrationManifest, writeMigrationOps, writeMigrationPackage };
86
+ export { copyFilesWithRename, formatMigrationDirName, materialiseExtensionMigrationPackageIfMissing, materialiseMigrationPackage, readMigrationPackage, readMigrationsDir, writeMigrationMetadata, writeMigrationOps, writeMigrationPackage };
27
87
  //# sourceMappingURL=io.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"io.d.mts","names":[],"sources":["../../src/io.ts"],"sourcesContent":[],"mappings":";;;iBAwDsB,qBAAA,wBAEV,wBACL,eACJ;;AAJH;;;;;AA+BA;AAaA;AAOA;AAIA;AAkEA;AAiCgB,iBA3HM,mBAAA,CA2H4B,OAAI,EAAA,MAAA,EAAA,KAAA,EAAA,SAAA;;;MAxHnD;iBAUmB,sBAAA,wBAEV,oBACT;iBAImB,iBAAA,mBAAoC,eAAe;iBAInD,oBAAA,eAAmC,QAAQ;iBAkE3C,iBAAA,0BAEnB,iBAAiB;iBA+BJ,sBAAA,YAAkC"}
1
+ {"version":3,"file":"io.d.mts","names":[],"sources":["../../src/io.ts"],"mappings":";;;;iBA0DsB,qBAAA,CACpB,GAAA,UACA,QAAA,EAAU,iBAAA,EACV,GAAA,EAAK,YAAA,GACJ,OAAA;AAJH;;;;;;;;;;;;;;;;AAwDA;;;;;;;;;;AAiCA;;;;;;;;AAzFA,iBAwDsB,2BAAA,CACpB,SAAA,UACA,GAAA,EAAK,gBAAA,GACJ,OAAA;;;AA8DH;;;;;;;;;;;AAaA;;;;;;;;iBA7CsB,6CAAA,CACpB,SAAA,UACA,GAAA,EAAK,gBAAA,GACJ,OAAA;EAAA,SAAmB,OAAA;AAAA;;;;;;;;;;AAqDtB;;iBAxBsB,mBAAA,CACpB,OAAA,UACA,KAAA;EAAA,SAA2B,UAAA;EAAA,SAA6B,QAAA;AAAA,MACvD,OAAA;AAAA,iBAUmB,sBAAA,CACpB,GAAA,UACA,QAAA,EAAU,iBAAA,GACT,OAAA;AAAA,iBAImB,iBAAA,CAAkB,GAAA,UAAa,GAAA,EAAK,YAAA,GAAe,OAAA;AAAA,iBAInD,oBAAA,CAAqB,GAAA,WAAc,OAAA,CAAQ,sBAAA;AAAA,iBAiG3C,iBAAA,CACpB,cAAA,WACC,OAAA,UAAiB,sBAAA;AAAA,iBA+BJ,sBAAA,CAAuB,SAAA,EAAW,IAAA,EAAM,IAAA"}
@@ -1,3 +1,2 @@
1
- import { a as writeMigrationManifest, i as readMigrationsDir, n as formatMigrationDirName, o as writeMigrationOps, r as readMigrationPackage, s as writeMigrationPackage, t as copyFilesWithRename } from "../io-Cd6GLyjK.mjs";
2
-
3
- export { copyFilesWithRename, formatMigrationDirName, readMigrationPackage, readMigrationsDir, writeMigrationManifest, writeMigrationOps, writeMigrationPackage };
1
+ import { a as materialiseMigrationPackage, c as writeMigrationMetadata, i as materialiseExtensionMigrationPackageIfMissing, l as writeMigrationOps, n as copyFilesWithRename, o as readMigrationPackage, r as formatMigrationDirName, s as readMigrationsDir, u as writeMigrationPackage } from "../io-D13dLvUh.mjs";
2
+ export { copyFilesWithRename, formatMigrationDirName, materialiseExtensionMigrationPackageIfMissing, materialiseMigrationPackage, readMigrationPackage, readMigrationsDir, writeMigrationMetadata, writeMigrationOps, writeMigrationPackage };
@@ -0,0 +1,2 @@
1
+ import { n as MigrationMetadata, t as MigrationHints } from "../metadata-CFvm3ayn.mjs";
2
+ export { type MigrationHints, type MigrationMetadata };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { a as findLeaf, c as findPathWithInvariants, i as findLatestMigration, l as findReachableLeaves, n as detectCycles, o as findPath, r as detectOrphans, s as findPathWithDecision, t as PathDecision, u as reconstructGraph } from "../migration-graph-DulOITvG.mjs";
2
+ export { type PathDecision, detectCycles, detectOrphans, findLatestMigration, findLeaf, findPath, findPathWithDecision, findPathWithInvariants, findReachableLeaves, reconstructGraph };
@@ -0,0 +1,2 @@
1
+ import { a as findPath, c as findReachableLeaves, i as findLeaf, l as reconstructGraph, n as detectOrphans, o as findPathWithDecision, r as findLatestMigration, s as findPathWithInvariants, t as detectCycles } from "../migration-graph-DGNnKDY5.mjs";
2
+ export { detectCycles, detectOrphans, findLatestMigration, findLeaf, findPath, findPathWithDecision, findPathWithInvariants, findReachableLeaves, reconstructGraph };
@@ -1 +1 @@
1
- {"version":3,"file":"migration-ts.d.mts","names":[],"sources":["../../src/migration-ts.ts","../../src/runtime-detection.ts"],"sourcesContent":[],"mappings":";;AA8BA;AAsBA;;;;ACpDA;AAEA;AAMA;;;;;;;;;;;;;;;iBDsBsB,gBAAA,uCAAuD;;;;iBAsBvD,cAAA,sBAAoC;;;KCpD9C,eAAA;AD8BU,iBC5BN,qBAAA,CAAA,CD4BoE,EC5B3C,eD4B2C;AAsB9D,iBC5CN,cAAA,CD4C0C,OAAO,EC5CzB,eD4CyB,CAAA,EAAA,MAAA"}
1
+ {"version":3,"file":"migration-ts.d.mts","names":[],"sources":["../../src/migration-ts.ts","../../src/runtime-detection.ts"],"mappings":";;AA8BA;;;;;;;;;AAsBA;;;;;;;;ACpDA;;;;;iBD8BsB,gBAAA,CAAiB,UAAA,UAAoB,OAAA,WAAkB,OAAA;;;;iBAsBvD,cAAA,CAAe,UAAA,WAAqB,OAAA;;;KCpD9C,eAAA;AAAA,iBAEI,qBAAA,CAAA,GAAyB,eAAA;AAAA,iBAMzB,cAAA,CAAe,OAAA,EAAS,eAAA"}
@@ -1,7 +1,6 @@
1
- import { stat, writeFile } from "node:fs/promises";
2
1
  import { join } from "pathe";
2
+ import { stat, writeFile } from "node:fs/promises";
3
3
  import { format } from "prettier";
4
-
5
4
  //#region src/migration-ts.ts
6
5
  /**
7
6
  * Utilities for reading/writing `migration.ts` files.
@@ -50,7 +49,6 @@ async function hasMigrationTs(packageDir) {
50
49
  return false;
51
50
  }
52
51
  }
53
-
54
52
  //#endregion
55
53
  //#region src/runtime-detection.ts
56
54
  function detectScaffoldRuntime() {
@@ -65,7 +63,7 @@ function shebangLineFor(runtime) {
65
63
  case "node": return "#!/usr/bin/env -S node";
66
64
  }
67
65
  }
68
-
69
66
  //#endregion
70
67
  export { detectScaffoldRuntime, hasMigrationTs, shebangLineFor, writeMigrationTs };
68
+
71
69
  //# sourceMappingURL=migration-ts.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"migration-ts.mjs","names":[],"sources":["../../src/migration-ts.ts","../../src/runtime-detection.ts"],"sourcesContent":["/**\n * Utilities for reading/writing `migration.ts` files.\n *\n * Rendering migration.ts source is the target's responsibility — the CLI\n * obtains source strings from a planner's `plan.renderTypeScript()`. The\n * helper here is limited to file I/O: writing the returned source with the\n * right executable bit and probing for existence.\n */\n\nimport { stat, writeFile } from 'node:fs/promises';\nimport { join } from 'pathe';\nimport { format } from 'prettier';\n\nconst MIGRATION_TS_FILE = 'migration.ts';\n\n/**\n * Writes a pre-rendered `migration.ts` source string to the given package\n * directory. If the source begins with a shebang, the file is written with\n * executable permissions (0o755) so it can be run directly via\n * `./migration.ts` — the rendered scaffold ends with\n * `MigrationCLI.run(import.meta.url, M)` from\n * `@prisma-next/cli/migration-cli` (re-exported by the postgres facade),\n * which guards on the entrypoint and serializes when the file is the main\n * module.\n *\n * The source is run through prettier before writing so migration renderers\n * can produce structurally-correct but loosely-indented source and rely on\n * a single canonical format on disk. Matches what `@prisma-next/emitter`\n * already does for generated `contract.d.ts`.\n */\nexport async function writeMigrationTs(packageDir: string, content: string): Promise<void> {\n const formatted = await formatMigrationTsSource(content);\n const isExecutable = formatted.startsWith('#!');\n await writeFile(\n join(packageDir, MIGRATION_TS_FILE),\n formatted,\n isExecutable ? { mode: 0o755 } : undefined,\n );\n}\n\nasync function formatMigrationTsSource(source: string): Promise<string> {\n return format(source, {\n parser: 'typescript',\n singleQuote: true,\n semi: true,\n printWidth: 100,\n });\n}\n\n/**\n * Checks whether a migration.ts file exists in the package directory.\n */\nexport async function hasMigrationTs(packageDir: string): Promise<boolean> {\n try {\n const s = await stat(join(packageDir, MIGRATION_TS_FILE));\n return s.isFile();\n } catch {\n return false;\n }\n}\n","export type ScaffoldRuntime = 'node' | 'bun' | 'deno';\n\nexport function detectScaffoldRuntime(): ScaffoldRuntime {\n if (typeof (globalThis as { Bun?: unknown }).Bun !== 'undefined') return 'bun';\n if (typeof (globalThis as { Deno?: unknown }).Deno !== 'undefined') return 'deno';\n return 'node';\n}\n\nexport function shebangLineFor(runtime: ScaffoldRuntime): string {\n switch (runtime) {\n case 'bun':\n return '#!/usr/bin/env -S bun';\n case 'deno':\n return '#!/usr/bin/env -S deno run -A';\n case 'node':\n return '#!/usr/bin/env -S node';\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAM,oBAAoB;;;;;;;;;;;;;;;;AAiB1B,eAAsB,iBAAiB,YAAoB,SAAgC;CACzF,MAAM,YAAY,MAAM,wBAAwB,QAAQ;CACxD,MAAM,eAAe,UAAU,WAAW,KAAK;AAC/C,OAAM,UACJ,KAAK,YAAY,kBAAkB,EACnC,WACA,eAAe,EAAE,MAAM,KAAO,GAAG,OAClC;;AAGH,eAAe,wBAAwB,QAAiC;AACtE,QAAO,OAAO,QAAQ;EACpB,QAAQ;EACR,aAAa;EACb,MAAM;EACN,YAAY;EACb,CAAC;;;;;AAMJ,eAAsB,eAAe,YAAsC;AACzE,KAAI;AAEF,UADU,MAAM,KAAK,KAAK,YAAY,kBAAkB,CAAC,EAChD,QAAQ;SACX;AACN,SAAO;;;;;;ACvDX,SAAgB,wBAAyC;AACvD,KAAI,OAAQ,WAAiC,QAAQ,YAAa,QAAO;AACzE,KAAI,OAAQ,WAAkC,SAAS,YAAa,QAAO;AAC3E,QAAO;;AAGT,SAAgB,eAAe,SAAkC;AAC/D,SAAQ,SAAR;EACE,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,OACH,QAAO"}
1
+ {"version":3,"file":"migration-ts.mjs","names":[],"sources":["../../src/migration-ts.ts","../../src/runtime-detection.ts"],"sourcesContent":["/**\n * Utilities for reading/writing `migration.ts` files.\n *\n * Rendering migration.ts source is the target's responsibility — the CLI\n * obtains source strings from a planner's `plan.renderTypeScript()`. The\n * helper here is limited to file I/O: writing the returned source with the\n * right executable bit and probing for existence.\n */\n\nimport { stat, writeFile } from 'node:fs/promises';\nimport { join } from 'pathe';\nimport { format } from 'prettier';\n\nconst MIGRATION_TS_FILE = 'migration.ts';\n\n/**\n * Writes a pre-rendered `migration.ts` source string to the given package\n * directory. If the source begins with a shebang, the file is written with\n * executable permissions (0o755) so it can be run directly via\n * `./migration.ts` — the rendered scaffold ends with\n * `MigrationCLI.run(import.meta.url, M)` from\n * `@prisma-next/cli/migration-cli` (re-exported by the postgres facade),\n * which guards on the entrypoint and serializes when the file is the main\n * module.\n *\n * The source is run through prettier before writing so migration renderers\n * can produce structurally-correct but loosely-indented source and rely on\n * a single canonical format on disk. Matches what `@prisma-next/emitter`\n * already does for generated `contract.d.ts`.\n */\nexport async function writeMigrationTs(packageDir: string, content: string): Promise<void> {\n const formatted = await formatMigrationTsSource(content);\n const isExecutable = formatted.startsWith('#!');\n await writeFile(\n join(packageDir, MIGRATION_TS_FILE),\n formatted,\n isExecutable ? { mode: 0o755 } : undefined,\n );\n}\n\nasync function formatMigrationTsSource(source: string): Promise<string> {\n return format(source, {\n parser: 'typescript',\n singleQuote: true,\n semi: true,\n printWidth: 100,\n });\n}\n\n/**\n * Checks whether a migration.ts file exists in the package directory.\n */\nexport async function hasMigrationTs(packageDir: string): Promise<boolean> {\n try {\n const s = await stat(join(packageDir, MIGRATION_TS_FILE));\n return s.isFile();\n } catch {\n return false;\n }\n}\n","export type ScaffoldRuntime = 'node' | 'bun' | 'deno';\n\nexport function detectScaffoldRuntime(): ScaffoldRuntime {\n if (typeof (globalThis as { Bun?: unknown }).Bun !== 'undefined') return 'bun';\n if (typeof (globalThis as { Deno?: unknown }).Deno !== 'undefined') return 'deno';\n return 'node';\n}\n\nexport function shebangLineFor(runtime: ScaffoldRuntime): string {\n switch (runtime) {\n case 'bun':\n return '#!/usr/bin/env -S bun';\n case 'deno':\n return '#!/usr/bin/env -S deno run -A';\n case 'node':\n return '#!/usr/bin/env -S node';\n }\n}\n"],"mappings":";;;;;;;;;;;;AAaA,MAAM,oBAAoB;;;;;;;;;;;;;;;;AAiB1B,eAAsB,iBAAiB,YAAoB,SAAgC;CACzF,MAAM,YAAY,MAAM,wBAAwB,QAAQ;CACxD,MAAM,eAAe,UAAU,WAAW,KAAK;CAC/C,MAAM,UACJ,KAAK,YAAY,kBAAkB,EACnC,WACA,eAAe,EAAE,MAAM,KAAO,GAAG,KAAA,EAClC;;AAGH,eAAe,wBAAwB,QAAiC;CACtE,OAAO,OAAO,QAAQ;EACpB,QAAQ;EACR,aAAa;EACb,MAAM;EACN,YAAY;EACb,CAAC;;;;;AAMJ,eAAsB,eAAe,YAAsC;CACzE,IAAI;EAEF,QAAO,MADS,KAAK,KAAK,YAAY,kBAAkB,CAAC,EAChD,QAAQ;SACX;EACN,OAAO;;;;;ACvDX,SAAgB,wBAAyC;CACvD,IAAI,OAAQ,WAAiC,QAAQ,aAAa,OAAO;CACzE,IAAI,OAAQ,WAAkC,SAAS,aAAa,OAAO;CAC3E,OAAO;;AAGT,SAAgB,eAAe,SAAkC;CAC/D,QAAQ,SAAR;EACE,KAAK,OACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,KAAK,QACH,OAAO"}
@@ -1,11 +1,10 @@
1
- import { a as MigrationManifest } from "../types-DyGXcWWp.mjs";
1
+ import { n as MigrationMetadata$1 } from "../metadata-CFvm3ayn.mjs";
2
2
  import { ControlStack, MigrationPlan, MigrationPlanOperation } from "@prisma-next/framework-components/control";
3
3
 
4
4
  //#region src/migration-base.d.ts
5
5
  interface MigrationMeta {
6
- readonly from: string;
6
+ readonly from: string | null;
7
7
  readonly to: string;
8
- readonly kind?: 'regular' | 'baseline';
9
8
  readonly labels?: readonly string[];
10
9
  }
11
10
  /**
@@ -13,7 +12,7 @@ interface MigrationMeta {
13
12
  *
14
13
  * A `Migration` subclass is itself a `MigrationPlan`: CLI commands and the
15
14
  * runner can consume it directly via `targetId`, `operations`, `origin`, and
16
- * `destination`. The manifest-shaped inputs come from `describe()`, which
15
+ * `destination`. The metadata-shaped inputs come from `describe()`, which
17
16
  * every migration must implement — `migration.json` is required for a
18
17
  * migration to be valid.
19
18
  */
@@ -58,30 +57,32 @@ declare abstract class Migration<TOperation extends MigrationPlanOperation = Mig
58
57
  * than executed directly.
59
58
  */
60
59
  declare function isDirectEntrypoint(importMetaUrl: string): boolean;
61
- declare function printMigrationHelp(): void;
62
60
  /**
63
61
  * In-memory artifacts produced from a `Migration` instance: the
64
- * serialized `ops.json` body, the `migration.json` manifest object, and
62
+ * serialized `ops.json` body, the `migration.json` metadata object, and
65
63
  * its serialized form. Returned by `buildMigrationArtifacts` so callers
66
64
  * (today: `MigrationCLI.run` in `@prisma-next/cli/migration-cli`) can
67
65
  * decide how to persist them — write to disk, print in dry-run, ship
68
66
  * over the wire — without coupling artifact construction to file I/O.
67
+ *
68
+ * `metadataJson` is `JSON.stringify(metadata, null, 2)` — the canonical
69
+ * on-disk shape that the arktype loader-schema in `./io` validates.
69
70
  */
70
71
  interface MigrationArtifacts {
71
72
  readonly opsJson: string;
72
- readonly manifest: MigrationManifest;
73
- readonly manifestJson: string;
73
+ readonly metadata: MigrationMetadata$1;
74
+ readonly metadataJson: string;
74
75
  }
75
76
  /**
76
77
  * Pure conversion from a `Migration` instance (plus the previously
77
- * scaffolded manifest, when one exists on disk) to the in-memory
78
+ * scaffolded metadata, when one exists on disk) to the in-memory
78
79
  * artifacts that downstream tooling persists. Owns metadata validation,
79
- * manifest synthesis/preservation, hint normalization, and the
80
- * content-addressed `migrationId` computation, but performs no file I/O
80
+ * metadata synthesis/preservation, hint normalization, and the
81
+ * content-addressed `migrationHash` computation, but performs no file I/O
81
82
  * — callers handle reads (to source `existing`) and writes (to persist
82
- * `opsJson` / `manifestJson`).
83
+ * `opsJson` / `metadataJson`).
83
84
  */
84
- declare function buildMigrationArtifacts(instance: Migration, existing: Partial<MigrationManifest> | null): MigrationArtifacts;
85
+ declare function buildMigrationArtifacts(instance: Migration, existing: Partial<MigrationMetadata$1> | null): MigrationArtifacts;
85
86
  //#endregion
86
- export { Migration, type MigrationArtifacts, type MigrationMeta, buildMigrationArtifacts, isDirectEntrypoint, printMigrationHelp };
87
+ export { Migration, type MigrationArtifacts, type MigrationMeta, buildMigrationArtifacts, isDirectEntrypoint };
87
88
  //# sourceMappingURL=migration.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"migration.d.mts","names":[],"sources":["../../src/migration-base.ts"],"sourcesContent":[],"mappings":";;;;UAaiB,aAAA;;EAAA,SAAA,EAAA,EAAA,MAAa;EAuBR,SAAA,IAAS,CAAA,EAAA,SAAA,GAAA,UAAA;EACV,SAAA,MAAA,CAAA,EAAA,SAAA,MAAA,EAAA;;;;;;;;;;;AAGK,uBAJJ,SAII,CAAA,mBAHL,sBAGK,GAHoB,sBAGpB,EAAA,kBAAA,MAAA,GAAA,MAAA,EAAA,kBAAA,MAAA,GAAA,MAAA,CAAA,YAAb,aAAa,CAAA;EAuDV,kBAAA,QAAkB,EAAA,MAAA;EAWlB;AAyBhB;AAyEA;;;;;;;4BAvJ4B,aAAa,WAAW;sBAE9B,aAAa,WAAW;;;;;;;sCAUR;;;;;;uBAOf;;;;;;;;;;;;;;;iBAuBP,kBAAA;iBAWA,kBAAA,CAAA;;;;;;;;;UAy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