@prisma-next/migration-tools 0.11.0-dev.24 → 0.11.0-dev.25

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 (48) hide show
  1. package/dist/exports/aggregate.d.mts +4 -4
  2. package/dist/exports/aggregate.mjs +2 -1
  3. package/dist/exports/aggregate.mjs.map +1 -1
  4. package/dist/exports/enumerate-migration-spaces.d.mts +53 -0
  5. package/dist/exports/enumerate-migration-spaces.d.mts.map +1 -0
  6. package/dist/exports/enumerate-migration-spaces.mjs +107 -0
  7. package/dist/exports/enumerate-migration-spaces.mjs.map +1 -0
  8. package/dist/exports/graph.d.mts +1 -1
  9. package/dist/exports/hash.d.mts +2 -2
  10. package/dist/exports/invariants.d.mts +1 -1
  11. package/dist/exports/io.d.mts +1 -1
  12. package/dist/exports/metadata.d.mts +1 -1
  13. package/dist/exports/migration-graph.d.mts +2 -2
  14. package/dist/exports/migration-list-types.d.mts +2 -0
  15. package/dist/exports/migration-list-types.mjs +1 -0
  16. package/dist/exports/migration.d.mts +1 -1
  17. package/dist/exports/package.d.mts +1 -1
  18. package/dist/exports/ref-resolution.d.mts +2 -2
  19. package/dist/exports/refs.d.mts +1 -1
  20. package/dist/exports/spaces.d.mts +27 -2
  21. package/dist/exports/spaces.d.mts.map +1 -1
  22. package/dist/exports/spaces.mjs +6 -4
  23. package/dist/exports/spaces.mjs.map +1 -1
  24. package/dist/{graph-BrLXqoUc.d.mts → graph-C7AJPGV5.d.mts} +1 -1
  25. package/dist/{graph-BrLXqoUc.d.mts.map → graph-C7AJPGV5.d.mts.map} +1 -1
  26. package/dist/{migration-graph-De0dUZoC.d.mts → migration-graph-ABYqVsmv.d.mts} +3 -3
  27. package/dist/{migration-graph-De0dUZoC.d.mts.map → migration-graph-ABYqVsmv.d.mts.map} +1 -1
  28. package/dist/migration-list-types-B-qimPet.d.mts +23 -0
  29. package/dist/migration-list-types-B-qimPet.d.mts.map +1 -0
  30. package/dist/{package-DZj8YvD0.d.mts → package-DIttKL7X.d.mts} +1 -1
  31. package/dist/{package-DZj8YvD0.d.mts.map → package-DIttKL7X.d.mts.map} +1 -1
  32. package/dist/read-contract-space-contract-CwwlqKl_.mjs +82 -0
  33. package/dist/read-contract-space-contract-CwwlqKl_.mjs.map +1 -0
  34. package/dist/{refs-CDaNerhT.d.mts → refs-BaygQaFD.d.mts} +1 -1
  35. package/dist/{refs-CDaNerhT.d.mts.map → refs-BaygQaFD.d.mts.map} +1 -1
  36. package/dist/{read-contract-space-contract-Cglige7P.mjs → verify-contract-spaces-DxXWxGR0.mjs} +31 -79
  37. package/dist/verify-contract-spaces-DxXWxGR0.mjs.map +1 -0
  38. package/package.json +14 -6
  39. package/src/emit-contract-space-artefacts.ts +4 -3
  40. package/src/enumerate-migration-spaces.ts +127 -0
  41. package/src/exports/enumerate-migration-spaces.ts +4 -0
  42. package/src/exports/migration-list-types.ts +5 -0
  43. package/src/exports/spaces.ts +3 -0
  44. package/src/migration-list-types.ts +21 -0
  45. package/src/read-contract-space-head-ref.ts +5 -2
  46. package/src/space-layout.ts +30 -0
  47. package/dist/read-contract-space-contract-Cglige7P.mjs.map +0 -1
  48. /package/dist/{metadata-BFX0xdz8.d.mts → metadata-B4Wy6zor.d.mts} +0 -0
@@ -1,8 +1,8 @@
1
- import { n as OnDiskMigrationPackage } from "../package-DZj8YvD0.mjs";
2
- import { n as MigrationGraph } from "../graph-BrLXqoUc.mjs";
3
- import { t as PathDecision } from "../migration-graph-De0dUZoC.mjs";
4
- import { Result } from "@prisma-next/utils/result";
1
+ import { n as OnDiskMigrationPackage } from "../package-DIttKL7X.mjs";
2
+ import { n as MigrationGraph } from "../graph-C7AJPGV5.mjs";
3
+ import { t as PathDecision } from "../migration-graph-ABYqVsmv.mjs";
5
4
  import { ControlFamilyInstance, MigrationOperationPolicy, MigrationPlan, MigrationPlanOperation, MigrationPlannerConflict, TargetMigrationsCapability } from "@prisma-next/framework-components/control";
5
+ import { Result } from "@prisma-next/utils/result";
6
6
  import { Contract } from "@prisma-next/contract/types";
7
7
  import { TargetBoundComponentDescriptor } from "@prisma-next/framework-components/components";
8
8
 
@@ -2,7 +2,8 @@ import { t as MigrationToolsError } from "../errors-CoEN114u.mjs";
2
2
  import { s as readMigrationsDir } from "../io-gHmDrSjQ.mjs";
3
3
  import "../constants-DWV9_o2Z.mjs";
4
4
  import { l as reconstructGraph, o as findPathWithDecision } from "../migration-graph-C2iNX8dk.mjs";
5
- import { a as APP_SPACE_ID, c as spaceMigrationDirectory, i as readContractSpaceHeadRef, n as listContractSpaceDirectories, t as readContractSpaceContract } from "../read-contract-space-contract-Cglige7P.mjs";
5
+ import { c as spaceMigrationDirectory, r as APP_SPACE_ID, t as listContractSpaceDirectories } from "../verify-contract-spaces-DxXWxGR0.mjs";
6
+ import { n as readContractSpaceHeadRef, t as readContractSpaceContract } from "../read-contract-space-contract-CwwlqKl_.mjs";
6
7
  import { notOk, ok } from "@prisma-next/utils/result";
7
8
  //#region src/aggregate/extract-storage-element-names.ts
8
9
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"aggregate.mjs","names":[],"sources":["../../src/aggregate/extract-storage-element-names.ts","../../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":["/**\n * Extract the set of top-level storage element names a contract claims.\n *\n * Used by the aggregate loader's disjointness check and by\n * `projectSchemaToSpace`'s \"names owned by other members\" walk.\n *\n * **Stopgap — known layering violation.** This helper duck-types the\n * storage shape from framework-domain code that has no business naming\n * family-specific storage idioms. The framework lacks a typed primitive\n * for storage *topology* — the structural backbone of \"what named things\n * does this contract claim?\" independent of what those things are.\n *\n * Behavioural notes for the lifetime of this helper:\n *\n * - SQL contracts contribute table names from every\n * `storage.namespaces[namespaceId].tables` map.\n * - Mongo contracts contribute names from each namespace's `tables`\n * (or `collections`, depending on the per-target Namespace's slot\n * choice). Per-namespace `collections` may appear as a record or as\n * an array of `{ name }` entries; both are accepted defensively.\n * - Root-level `tables` / `collections` records (when present) are\n * also unioned. These root-level walks are belt-and-suspenders for a\n * defensive helper operating on `unknown`; no in-tree contract emits\n * the root shape post-namespace flip.\n * - Unrecognised shapes contribute nothing beyond the walks above.\n * - Record-shape detection excludes arrays so array-shaped values aren't\n * walked as records via numeric keys.\n * - Names that appear in multiple places are deduplicated by the returned\n * `Set`.\n */\nexport function extractStorageElementNames(contract: unknown): Set<string> {\n const names = new Set<string>();\n if (typeof contract !== 'object' || contract === null) return names;\n const storage = (contract as { readonly storage?: unknown }).storage;\n if (typeof storage !== 'object' || storage === null) return names;\n const storageObj = storage as {\n readonly namespaces?: unknown;\n readonly tables?: unknown;\n readonly collections?: unknown;\n };\n\n if (\n typeof storageObj.namespaces === 'object' &&\n storageObj.namespaces !== null &&\n !Array.isArray(storageObj.namespaces)\n ) {\n for (const ns of Object.values(storageObj.namespaces as Record<string, unknown>)) {\n if (typeof ns !== 'object' || ns === null) continue;\n const nsObj = ns as { readonly tables?: unknown; readonly collections?: unknown };\n addRecordKeys(nsObj.tables, names);\n if (Array.isArray(nsObj.collections)) {\n for (const entry of nsObj.collections) {\n if (typeof entry === 'object' && entry !== null) {\n const name = (entry as { readonly name?: unknown }).name;\n if (typeof name === 'string') names.add(name);\n }\n }\n } else {\n addRecordKeys(nsObj.collections, names);\n }\n }\n }\n\n addRecordKeys(storageObj.tables, names);\n addRecordKeys(storageObj.collections, names);\n return names;\n}\n\nfunction addRecordKeys(value: unknown, names: Set<string>): void {\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n for (const name of Object.keys(value as Record<string, unknown>)) {\n names.add(name);\n }\n }\n}\n","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 { MigrationToolsError } from '../errors';\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 { extractStorageElementNames } from './extract-storage-element-names';\nimport type { ContractSpaceAggregate, ContractSpaceMember, HydratedMigrationGraph } from './types';\n\nfunction integrityDetail(error: unknown): string {\n if (MigrationToolsError.is(error)) {\n return error.why;\n }\n if (error instanceof Error) {\n return error.message;\n }\n return String(error);\n}\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 *\n * Whether the descriptor declares a contract space is decided by whether\n * its corresponding `migrations/<id>/` directory exists on disk\n * (materialised by the seed phase before the loader runs); the loader\n * never reads the descriptor's `contractJson` itself. That makes the\n * aggregate's apply / verify paths byte-for-byte independent of the\n * descriptor module — `db verify` succeeds even if the descriptor's\n * `contractJson` is a throwing getter.\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}\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 deserializeContract: (contractJson: unknown) => Contract;\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: '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 * the app contract value the caller supplies.\n *\n * The loader is the **only** descriptor-import boundary at apply /\n * verify time, but it intentionally does **not** read the extension\n * descriptor's `contractJson` value. Each extension space's contract\n * is read from its on-disk `migrations/<id>/contract.json` mirror; the\n * descriptor's role is exhausted by the seed phase that wrote that\n * mirror in the first place. The loader composes existing\n * migration-tools primitives — layout precheck (via\n * {@link listContractSpaceDirectories}), integrity checks (via\n * {@link readMigrationsDir} / {@link readContractSpaceHeadRef} /\n * {@link readContractSpaceContract} / `deserializeContract`), and\n * disjointness — into a single typed value.\n *\n * Failure semantics: every failure variant in {@link LoadAggregateError}\n * short-circuits the load.\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 //\n // Every declared extension contributes an entry to the aggregate when\n // a corresponding `migrations/<id>/` directory exists on disk. The\n // loader treats the directory's presence as the membership signal —\n // the descriptor itself is not read — so codec-only extensions (no\n // on-disk dir) and contract-space extensions (dir present) are\n // distinguished structurally.\n const declaredSpaceIds = new Set(input.declaredExtensions.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.\n const loadedExtensions: LoadedExtensionState[] = [];\n for (const entry of [...input.declaredExtensions].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: integrityDetail(error),\n });\n }\n\n let spaceContract: Contract;\n try {\n spaceContract = input.deserializeContract(spaceContractRaw);\n } catch (error) {\n return notOk({\n kind: 'validationFailure',\n spaceId: entry.id,\n detail: integrityDetail(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 // 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: integrityDetail(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: integrityDetail(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 elements = extractStorageElementNames(member.contract);\n for (const elementName of elements) {\n const claimers = elementClaimedBy.get(elementName);\n if (claimers) claimers.push(member.spaceId);\n else elementClaimedBy.set(elementName, [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","import 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 * `migrate` to surface the user-supplied `--to <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,\n strategy: 'graph-walk',\n migrationEdges: edgeRefs,\n pathDecision: outcome.decision,\n },\n };\n}\n","import { extractStorageElementNames } from './extract-storage-element-names';\nimport type { ContractSpaceMember } from './types';\n\n/**\n * Project the **introspected live schema** to the slice claimed by a\n * single contract-space member.\n *\n * \"Schema\" here means the live introspected database state — the\n * planner / verifier sees this object as a `MongoSchemaIR` (Mongo) or\n * `SqlSchemaIR` (SQL). It is **not** a database schema in the SQL\n * `CREATE SCHEMA` sense, nor a contract-space namespace. The\n * function's job is to filter that introspected state down to the\n * elements claimed by one space, so a per-space verify pass doesn't\n * see another space's storage as \"extras\".\n *\n * Returns the same `schema` value with every top-level storage element\n * (table or collection) claimed by **other** members of the aggregate\n * removed. Elements not claimed by any member flow through unchanged —\n * the planner / verifier sees them as 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 elements claimed\n * by other members as \"extras\" and emit destructive ops to drop them.\n * - The aggregate verifier's **schemaCheck**: projects per member so the\n * single-contract verify only sees the slice claimed by the member it\n * is checking. Closes the architectural concern that a multi-member\n * deployment makes each member's elements look like extras to every\n * 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 * Two storage shapes are recognised today:\n *\n * - SQL families expose `storage.tables: Record<string, ...>` on\n * contracts and the introspected schema mirrors the same record shape.\n * Pruning iterates the record entries.\n * - Mongo exposes `storage.collections: Record<string, ...>` on\n * contracts; the introspected `MongoSchemaIR` exposes\n * `collections: ReadonlyArray<{name: string, ...}>`. Pruning iterates\n * the array on the schema side and the record's keys on the\n * other-member side.\n *\n * Schemas of unrecognised shape are returned unchanged. The function\n * never imports family classes (`SqlSchemaIR`, `MongoSchemaIR`); the\n * projected schema is a plain object — `{...schema, tables: pruned}` or\n * `{...schema, collections: pruned}` — that downstream consumers\n * duck-type. A future family with a different storage shape gets the\n * schema returned unchanged rather than blowing up the aggregate\n * planner.\n *\n * Record-shape detection guards against arrays (`!Array.isArray`) so\n * an unrecognised array-shaped value falls through unchanged rather\n * than being pruned by numeric keys.\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\n const ownedByOthers = collectOwnedNames(member, otherMembers);\n if (ownedByOthers.size === 0) return schema;\n\n const schemaObj = schema as { readonly tables?: unknown; readonly collections?: unknown };\n\n if (\n typeof schemaObj.tables === 'object' &&\n schemaObj.tables !== null &&\n !Array.isArray(schemaObj.tables)\n ) {\n return pruneRecord(schemaObj, 'tables', ownedByOthers);\n }\n\n if (Array.isArray(schemaObj.collections)) {\n return pruneCollectionsArray(schemaObj, ownedByOthers);\n }\n\n if (\n typeof schemaObj.collections === 'object' &&\n schemaObj.collections !== null &&\n !Array.isArray(schemaObj.collections)\n ) {\n return pruneRecord(schemaObj, 'collections', ownedByOthers);\n }\n\n return schema;\n}\n\n/**\n * Collect the set of storage element names claimed by other members.\n * Reuses the loader's `extractStorageElementNames` helper so the\n * tables/collections walk lives in exactly one place.\n */\nfunction collectOwnedNames(\n member: ContractSpaceMember,\n otherMembers: ReadonlyArray<ContractSpaceMember>,\n): Set<string> {\n const owned = new Set<string>();\n for (const other of otherMembers) {\n if (other.spaceId === member.spaceId) continue;\n for (const name of extractStorageElementNames(other.contract)) {\n owned.add(name);\n }\n }\n return owned;\n}\n\nfunction pruneRecord(\n schemaObj: { readonly tables?: unknown; readonly collections?: unknown },\n field: 'tables' | 'collections',\n ownedByOthers: ReadonlySet<string>,\n): unknown {\n const source = schemaObj[field] as Record<string, unknown>;\n let removed = false;\n const pruned: Record<string, unknown> = {};\n for (const [name, value] of Object.entries(source)) {\n if (ownedByOthers.has(name)) {\n removed = true;\n } else {\n pruned[name] = value;\n }\n }\n if (!removed) return schemaObj;\n return { ...schemaObj, [field]: pruned };\n}\n\nfunction pruneCollectionsArray(\n schemaObj: { readonly collections?: unknown },\n ownedByOthers: ReadonlySet<string>,\n): unknown {\n const source = schemaObj.collections as ReadonlyArray<unknown>;\n let removed = false;\n const pruned: unknown[] = [];\n for (const entry of source) {\n if (typeof entry === 'object' && entry !== null) {\n const name = (entry as { readonly name?: unknown }).name;\n if (typeof name === 'string' && ownedByOthers.has(name)) {\n removed = true;\n continue;\n }\n }\n pruned.push(entry);\n }\n if (!removed) return schemaObj;\n return { ...schemaObj, collections: pruned };\n}\n","import 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,\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 AggregateMigrationEdgeRef,\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 { extractStorageElementNames } from './extract-storage-element-names';\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 for (const name of extractStorageElementNames(member.contract)) {\n claimedTables.add(name);\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,2BAA2B,UAAgC;CACzE,MAAM,wBAAQ,IAAI,IAAY;CAC9B,IAAI,OAAO,aAAa,YAAY,aAAa,MAAM,OAAO;CAC9D,MAAM,UAAW,SAA4C;CAC7D,IAAI,OAAO,YAAY,YAAY,YAAY,MAAM,OAAO;CAC5D,MAAM,aAAa;CAMnB,IACE,OAAO,WAAW,eAAe,YACjC,WAAW,eAAe,QAC1B,CAAC,MAAM,QAAQ,WAAW,UAAU,GAEpC,KAAK,MAAM,MAAM,OAAO,OAAO,WAAW,UAAqC,GAAG;EAChF,IAAI,OAAO,OAAO,YAAY,OAAO,MAAM;EAC3C,MAAM,QAAQ;EACd,cAAc,MAAM,QAAQ,KAAK;EACjC,IAAI,MAAM,QAAQ,MAAM,WAAW;QAC5B,MAAM,SAAS,MAAM,aACxB,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM;IAC/C,MAAM,OAAQ,MAAsC;IACpD,IAAI,OAAO,SAAS,UAAU,MAAM,IAAI,IAAI;GAC9C;SAGF,cAAc,MAAM,aAAa,KAAK;CAE1C;CAGF,cAAc,WAAW,QAAQ,KAAK;CACtC,cAAc,WAAW,aAAa,KAAK;CAC3C,OAAO;AACT;AAEA,SAAS,cAAc,OAAgB,OAA0B;CAC/D,IAAI,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IAA2B;CACtD,KAAK,MAAM,UAAU,YAAY;EAE/B,MAAM,YAAY,qBAAqB,qBAAqB,QAD7C,WAAW,QAAQ,MAAM,EAAE,YAAY,OAAO,OACY,CAAC;EAC1E,eAAe,IAAI,OAAO,SAAS,sBAAsB,WAAW,QAAQ,IAAI,CAAC;CACnF;CAEA,OAAO,GAAG;EACR,aAAa;GACX,UAAU;GACV;EACF;EACA,aAAa;GACX,UAAU;GACV,gBAAgB,qBAAqB,qBAAqB,UAAU;EACtE;CACF,CAAC;AACH;;;;;;;AAQA,SAAS,qBACP,qBACA,SAC0B;CAC1B,IAAI,OAAO,wBAAwB,YAAY,wBAAwB,MAAM,OAAO,CAAC;CACrF,MAAM,aAAc,oBAAsD;CAC1E,IAAI,OAAO,eAAe,YAAY,eAAe,MAAM,OAAO,CAAC;CAEnE,MAAM,gCAAgB,IAAI,IAAY;CACtC,KAAK,MAAM,UAAU,SACnB,KAAK,MAAM,QAAQ,2BAA2B,OAAO,QAAQ,GAC3D,cAAc,IAAI,IAAI;CAI1B,MAAM,UAA2B,CAAC;CAClC,KAAK,MAAM,aAAa,OAAO,KAAK,UAAqC,GACvE,IAAI,CAAC,cAAc,IAAI,SAAS,GAC9B,QAAQ,KAAK;EAAE,MAAM;EAAS,MAAM;CAAU,CAAC;CAGnD,QAAQ,MAAM,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,IAAI,CAAC;CACnD,OAAO;AACT"}
1
+ {"version":3,"file":"aggregate.mjs","names":[],"sources":["../../src/aggregate/extract-storage-element-names.ts","../../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":["/**\n * Extract the set of top-level storage element names a contract claims.\n *\n * Used by the aggregate loader's disjointness check and by\n * `projectSchemaToSpace`'s \"names owned by other members\" walk.\n *\n * **Stopgap — known layering violation.** This helper duck-types the\n * storage shape from framework-domain code that has no business naming\n * family-specific storage idioms. The framework lacks a typed primitive\n * for storage *topology* — the structural backbone of \"what named things\n * does this contract claim?\" independent of what those things are.\n *\n * Behavioural notes for the lifetime of this helper:\n *\n * - SQL contracts contribute table names from every\n * `storage.namespaces[namespaceId].tables` map.\n * - Mongo contracts contribute names from each namespace's `tables`\n * (or `collections`, depending on the per-target Namespace's slot\n * choice). Per-namespace `collections` may appear as a record or as\n * an array of `{ name }` entries; both are accepted defensively.\n * - Root-level `tables` / `collections` records (when present) are\n * also unioned. These root-level walks are belt-and-suspenders for a\n * defensive helper operating on `unknown`; no in-tree contract emits\n * the root shape post-namespace flip.\n * - Unrecognised shapes contribute nothing beyond the walks above.\n * - Record-shape detection excludes arrays so array-shaped values aren't\n * walked as records via numeric keys.\n * - Names that appear in multiple places are deduplicated by the returned\n * `Set`.\n */\nexport function extractStorageElementNames(contract: unknown): Set<string> {\n const names = new Set<string>();\n if (typeof contract !== 'object' || contract === null) return names;\n const storage = (contract as { readonly storage?: unknown }).storage;\n if (typeof storage !== 'object' || storage === null) return names;\n const storageObj = storage as {\n readonly namespaces?: unknown;\n readonly tables?: unknown;\n readonly collections?: unknown;\n };\n\n if (\n typeof storageObj.namespaces === 'object' &&\n storageObj.namespaces !== null &&\n !Array.isArray(storageObj.namespaces)\n ) {\n for (const ns of Object.values(storageObj.namespaces as Record<string, unknown>)) {\n if (typeof ns !== 'object' || ns === null) continue;\n const nsObj = ns as { readonly tables?: unknown; readonly collections?: unknown };\n addRecordKeys(nsObj.tables, names);\n if (Array.isArray(nsObj.collections)) {\n for (const entry of nsObj.collections) {\n if (typeof entry === 'object' && entry !== null) {\n const name = (entry as { readonly name?: unknown }).name;\n if (typeof name === 'string') names.add(name);\n }\n }\n } else {\n addRecordKeys(nsObj.collections, names);\n }\n }\n }\n\n addRecordKeys(storageObj.tables, names);\n addRecordKeys(storageObj.collections, names);\n return names;\n}\n\nfunction addRecordKeys(value: unknown, names: Set<string>): void {\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n for (const name of Object.keys(value as Record<string, unknown>)) {\n names.add(name);\n }\n }\n}\n","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 { MigrationToolsError } from '../errors';\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 { extractStorageElementNames } from './extract-storage-element-names';\nimport type { ContractSpaceAggregate, ContractSpaceMember, HydratedMigrationGraph } from './types';\n\nfunction integrityDetail(error: unknown): string {\n if (MigrationToolsError.is(error)) {\n return error.why;\n }\n if (error instanceof Error) {\n return error.message;\n }\n return String(error);\n}\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 *\n * Whether the descriptor declares a contract space is decided by whether\n * its corresponding `migrations/<id>/` directory exists on disk\n * (materialised by the seed phase before the loader runs); the loader\n * never reads the descriptor's `contractJson` itself. That makes the\n * aggregate's apply / verify paths byte-for-byte independent of the\n * descriptor module — `db verify` succeeds even if the descriptor's\n * `contractJson` is a throwing getter.\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}\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 deserializeContract: (contractJson: unknown) => Contract;\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: '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 * the app contract value the caller supplies.\n *\n * The loader is the **only** descriptor-import boundary at apply /\n * verify time, but it intentionally does **not** read the extension\n * descriptor's `contractJson` value. Each extension space's contract\n * is read from its on-disk `migrations/<id>/contract.json` mirror; the\n * descriptor's role is exhausted by the seed phase that wrote that\n * mirror in the first place. The loader composes existing\n * migration-tools primitives — layout precheck (via\n * {@link listContractSpaceDirectories}), integrity checks (via\n * {@link readMigrationsDir} / {@link readContractSpaceHeadRef} /\n * {@link readContractSpaceContract} / `deserializeContract`), and\n * disjointness — into a single typed value.\n *\n * Failure semantics: every failure variant in {@link LoadAggregateError}\n * short-circuits the load.\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 //\n // Every declared extension contributes an entry to the aggregate when\n // a corresponding `migrations/<id>/` directory exists on disk. The\n // loader treats the directory's presence as the membership signal —\n // the descriptor itself is not read — so codec-only extensions (no\n // on-disk dir) and contract-space extensions (dir present) are\n // distinguished structurally.\n const declaredSpaceIds = new Set(input.declaredExtensions.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.\n const loadedExtensions: LoadedExtensionState[] = [];\n for (const entry of [...input.declaredExtensions].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: integrityDetail(error),\n });\n }\n\n let spaceContract: Contract;\n try {\n spaceContract = input.deserializeContract(spaceContractRaw);\n } catch (error) {\n return notOk({\n kind: 'validationFailure',\n spaceId: entry.id,\n detail: integrityDetail(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 // 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: integrityDetail(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: integrityDetail(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 elements = extractStorageElementNames(member.contract);\n for (const elementName of elements) {\n const claimers = elementClaimedBy.get(elementName);\n if (claimers) claimers.push(member.spaceId);\n else elementClaimedBy.set(elementName, [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","import 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 * `migrate` to surface the user-supplied `--to <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,\n strategy: 'graph-walk',\n migrationEdges: edgeRefs,\n pathDecision: outcome.decision,\n },\n };\n}\n","import { extractStorageElementNames } from './extract-storage-element-names';\nimport type { ContractSpaceMember } from './types';\n\n/**\n * Project the **introspected live schema** to the slice claimed by a\n * single contract-space member.\n *\n * \"Schema\" here means the live introspected database state — the\n * planner / verifier sees this object as a `MongoSchemaIR` (Mongo) or\n * `SqlSchemaIR` (SQL). It is **not** a database schema in the SQL\n * `CREATE SCHEMA` sense, nor a contract-space namespace. The\n * function's job is to filter that introspected state down to the\n * elements claimed by one space, so a per-space verify pass doesn't\n * see another space's storage as \"extras\".\n *\n * Returns the same `schema` value with every top-level storage element\n * (table or collection) claimed by **other** members of the aggregate\n * removed. Elements not claimed by any member flow through unchanged —\n * the planner / verifier sees them as 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 elements claimed\n * by other members as \"extras\" and emit destructive ops to drop them.\n * - The aggregate verifier's **schemaCheck**: projects per member so the\n * single-contract verify only sees the slice claimed by the member it\n * is checking. Closes the architectural concern that a multi-member\n * deployment makes each member's elements look like extras to every\n * 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 * Two storage shapes are recognised today:\n *\n * - SQL families expose `storage.tables: Record<string, ...>` on\n * contracts and the introspected schema mirrors the same record shape.\n * Pruning iterates the record entries.\n * - Mongo exposes `storage.collections: Record<string, ...>` on\n * contracts; the introspected `MongoSchemaIR` exposes\n * `collections: ReadonlyArray<{name: string, ...}>`. Pruning iterates\n * the array on the schema side and the record's keys on the\n * other-member side.\n *\n * Schemas of unrecognised shape are returned unchanged. The function\n * never imports family classes (`SqlSchemaIR`, `MongoSchemaIR`); the\n * projected schema is a plain object — `{...schema, tables: pruned}` or\n * `{...schema, collections: pruned}` — that downstream consumers\n * duck-type. A future family with a different storage shape gets the\n * schema returned unchanged rather than blowing up the aggregate\n * planner.\n *\n * Record-shape detection guards against arrays (`!Array.isArray`) so\n * an unrecognised array-shaped value falls through unchanged rather\n * than being pruned by numeric keys.\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\n const ownedByOthers = collectOwnedNames(member, otherMembers);\n if (ownedByOthers.size === 0) return schema;\n\n const schemaObj = schema as { readonly tables?: unknown; readonly collections?: unknown };\n\n if (\n typeof schemaObj.tables === 'object' &&\n schemaObj.tables !== null &&\n !Array.isArray(schemaObj.tables)\n ) {\n return pruneRecord(schemaObj, 'tables', ownedByOthers);\n }\n\n if (Array.isArray(schemaObj.collections)) {\n return pruneCollectionsArray(schemaObj, ownedByOthers);\n }\n\n if (\n typeof schemaObj.collections === 'object' &&\n schemaObj.collections !== null &&\n !Array.isArray(schemaObj.collections)\n ) {\n return pruneRecord(schemaObj, 'collections', ownedByOthers);\n }\n\n return schema;\n}\n\n/**\n * Collect the set of storage element names claimed by other members.\n * Reuses the loader's `extractStorageElementNames` helper so the\n * tables/collections walk lives in exactly one place.\n */\nfunction collectOwnedNames(\n member: ContractSpaceMember,\n otherMembers: ReadonlyArray<ContractSpaceMember>,\n): Set<string> {\n const owned = new Set<string>();\n for (const other of otherMembers) {\n if (other.spaceId === member.spaceId) continue;\n for (const name of extractStorageElementNames(other.contract)) {\n owned.add(name);\n }\n }\n return owned;\n}\n\nfunction pruneRecord(\n schemaObj: { readonly tables?: unknown; readonly collections?: unknown },\n field: 'tables' | 'collections',\n ownedByOthers: ReadonlySet<string>,\n): unknown {\n const source = schemaObj[field] as Record<string, unknown>;\n let removed = false;\n const pruned: Record<string, unknown> = {};\n for (const [name, value] of Object.entries(source)) {\n if (ownedByOthers.has(name)) {\n removed = true;\n } else {\n pruned[name] = value;\n }\n }\n if (!removed) return schemaObj;\n return { ...schemaObj, [field]: pruned };\n}\n\nfunction pruneCollectionsArray(\n schemaObj: { readonly collections?: unknown },\n ownedByOthers: ReadonlySet<string>,\n): unknown {\n const source = schemaObj.collections as ReadonlyArray<unknown>;\n let removed = false;\n const pruned: unknown[] = [];\n for (const entry of source) {\n if (typeof entry === 'object' && entry !== null) {\n const name = (entry as { readonly name?: unknown }).name;\n if (typeof name === 'string' && ownedByOthers.has(name)) {\n removed = true;\n continue;\n }\n }\n pruned.push(entry);\n }\n if (!removed) return schemaObj;\n return { ...schemaObj, collections: pruned };\n}\n","import 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,\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 AggregateMigrationEdgeRef,\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 { extractStorageElementNames } from './extract-storage-element-names';\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 for (const name of extractStorageElementNames(member.contract)) {\n claimedTables.add(name);\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,2BAA2B,UAAgC;CACzE,MAAM,wBAAQ,IAAI,IAAY;CAC9B,IAAI,OAAO,aAAa,YAAY,aAAa,MAAM,OAAO;CAC9D,MAAM,UAAW,SAA4C;CAC7D,IAAI,OAAO,YAAY,YAAY,YAAY,MAAM,OAAO;CAC5D,MAAM,aAAa;CAMnB,IACE,OAAO,WAAW,eAAe,YACjC,WAAW,eAAe,QAC1B,CAAC,MAAM,QAAQ,WAAW,UAAU,GAEpC,KAAK,MAAM,MAAM,OAAO,OAAO,WAAW,UAAqC,GAAG;EAChF,IAAI,OAAO,OAAO,YAAY,OAAO,MAAM;EAC3C,MAAM,QAAQ;EACd,cAAc,MAAM,QAAQ,KAAK;EACjC,IAAI,MAAM,QAAQ,MAAM,WAAW;QAC5B,MAAM,SAAS,MAAM,aACxB,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM;IAC/C,MAAM,O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/**
5
+ * Index `migrations/<space>/refs/*.json` by the contract hash each ref
6
+ * points at, so callers can attach `(ref names)` decorations to every
7
+ * row whose destination contract hash matches.
8
+ *
9
+ * Each bucket is sorted lex-asc to keep rendered output deterministic
10
+ * (adjacent rows pointing at the same hash render their ref decorations
11
+ * in the same order).
12
+ *
13
+ * Refs whose hash matches no migration on disk are still indexed; the
14
+ * caller decides whether to surface them. Migration rows only carry
15
+ * `(refs)` decorations when a matching destination contract hash exists
16
+ * on disk — orphan refs are not rendered on any row.
17
+ *
18
+ * Returns an empty map when the refs directory does not exist
19
+ * ({@link readRefs} treats `ENOENT` as "no refs").
20
+ */
21
+ declare function resolveRefsByContractHash(refsDir: string): Promise<ReadonlyMap<string, readonly string[]>>;
22
+ /**
23
+ * Enumerate every contract space's on-disk migrations under
24
+ * `<projectMigrationsDir>/`. For each valid space directory:
25
+ *
26
+ * - Loads on-disk packages via {@link readMigrationsDir}.
27
+ * - Attaches ref decorations: each migration's `refs[]` lists every ref
28
+ * name from `migrations/<spaceId>/refs/*.json` whose hash equals the
29
+ * migration's destination contract hash.
30
+ * - Sorts migrations within the space by `dirName` descending
31
+ * (reverse-filename, latest first).
32
+ *
33
+ * Contract spaces are returned with {@link APP_SPACE_ID} first when
34
+ * present, then the remaining ids lex-asc. A contract-space directory
35
+ * that contains no migrations becomes `{ spaceId, migrations: [] }` so
36
+ * the renderer's empty-state path can surface it.
37
+ *
38
+ * Directory entries that are not valid {@link isValidSpaceId} names are
39
+ * skipped (a stray non-space directory under `migrations/` does not
40
+ * spawn a phantom space entry). Entries whose name appears in
41
+ * {@link RESERVED_SPACE_SUBDIR_NAMES} are also skipped — the per-space
42
+ * `refs/` subdirectory name shape would otherwise satisfy
43
+ * {@link isValidSpaceId} and surface as a phantom contract space.
44
+ *
45
+ * Returns `[]` when `<projectMigrationsDir>` does not exist — a fresh
46
+ * project that has not authored any migration yet.
47
+ */
48
+ declare function enumerateMigrationSpaces(args: {
49
+ readonly projectMigrationsDir: string;
50
+ }): Promise<readonly MigrationSpaceListEntry[]>;
51
+ //#endregion
52
+ export { enumerateMigrationSpaces, resolveRefsByContractHash };
53
+ //# sourceMappingURL=enumerate-migration-spaces.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enumerate-migration-spaces.d.mts","names":[],"sources":["../../src/enumerate-migration-spaces.ts"],"mappings":";;;;;AA6BA;;;;;;;;AAEsB;AA8DtB;;;;;;iBAhEsB,yBAAA,CACpB,OAAA,WACC,OAAO,CAAC,WAAA;;;AAgEiC;;;;;;;;;;;;;;;;;;;;;;;;iBAFtB,wBAAA,CAAyB,IAAA;EAAA,SACpC,oBAAA;AAAA,IACP,OAAO,UAAU,uBAAA"}
@@ -0,0 +1,107 @@
1
+ import { s as readMigrationsDir } from "../io-gHmDrSjQ.mjs";
2
+ import { r as readRefs } from "../refs-HhOkD8BT.mjs";
3
+ import { c as spaceMigrationDirectory, i as RESERVED_SPACE_SUBDIR_NAMES, l as spaceRefsDirectory, r as APP_SPACE_ID, s as isValidSpaceId, t as listContractSpaceDirectories } from "../verify-contract-spaces-DxXWxGR0.mjs";
4
+ //#region src/enumerate-migration-spaces.ts
5
+ /**
6
+ * Index `migrations/<space>/refs/*.json` by the contract hash each ref
7
+ * points at, so callers can attach `(ref names)` decorations to every
8
+ * row whose destination contract hash matches.
9
+ *
10
+ * Each bucket is sorted lex-asc to keep rendered output deterministic
11
+ * (adjacent rows pointing at the same hash render their ref decorations
12
+ * in the same order).
13
+ *
14
+ * Refs whose hash matches no migration on disk are still indexed; the
15
+ * caller decides whether to surface them. Migration rows only carry
16
+ * `(refs)` decorations when a matching destination contract hash exists
17
+ * on disk — orphan refs are not rendered on any row.
18
+ *
19
+ * Returns an empty map when the refs directory does not exist
20
+ * ({@link readRefs} treats `ENOENT` as "no refs").
21
+ */
22
+ async function resolveRefsByContractHash(refsDir) {
23
+ const refs = await readRefs(refsDir);
24
+ const byHash = /* @__PURE__ */ new Map();
25
+ for (const [name, entry] of Object.entries(refs)) {
26
+ const bucket = byHash.get(entry.hash);
27
+ if (bucket) bucket.push(name);
28
+ else byHash.set(entry.hash, [name]);
29
+ }
30
+ for (const bucket of byHash.values()) bucket.sort();
31
+ return byHash;
32
+ }
33
+ /**
34
+ * Compare two contract-space IDs for the inter-space ordering rule:
35
+ * {@link APP_SPACE_ID} first if present, then lex-asc on the rest.
36
+ */
37
+ function compareSpaceIds(a, b) {
38
+ if (a === APP_SPACE_ID) return b === APP_SPACE_ID ? 0 : -1;
39
+ if (b === APP_SPACE_ID) return 1;
40
+ if (a < b) return -1;
41
+ if (a > b) return 1;
42
+ return 0;
43
+ }
44
+ /**
45
+ * Sort `dirName` descending so the rendered output reads latest-first,
46
+ * matching the `git log` latest-first convention.
47
+ */
48
+ function compareDirNamesDescending(a, b) {
49
+ if (a.dirName < b.dirName) return 1;
50
+ if (a.dirName > b.dirName) return -1;
51
+ return 0;
52
+ }
53
+ /**
54
+ * Enumerate every contract space's on-disk migrations under
55
+ * `<projectMigrationsDir>/`. For each valid space directory:
56
+ *
57
+ * - Loads on-disk packages via {@link readMigrationsDir}.
58
+ * - Attaches ref decorations: each migration's `refs[]` lists every ref
59
+ * name from `migrations/<spaceId>/refs/*.json` whose hash equals the
60
+ * migration's destination contract hash.
61
+ * - Sorts migrations within the space by `dirName` descending
62
+ * (reverse-filename, latest first).
63
+ *
64
+ * Contract spaces are returned with {@link APP_SPACE_ID} first when
65
+ * present, then the remaining ids lex-asc. A contract-space directory
66
+ * that contains no migrations becomes `{ spaceId, migrations: [] }` so
67
+ * the renderer's empty-state path can surface it.
68
+ *
69
+ * Directory entries that are not valid {@link isValidSpaceId} names are
70
+ * skipped (a stray non-space directory under `migrations/` does not
71
+ * spawn a phantom space entry). Entries whose name appears in
72
+ * {@link RESERVED_SPACE_SUBDIR_NAMES} are also skipped — the per-space
73
+ * `refs/` subdirectory name shape would otherwise satisfy
74
+ * {@link isValidSpaceId} and surface as a phantom contract space.
75
+ *
76
+ * Returns `[]` when `<projectMigrationsDir>` does not exist — a fresh
77
+ * project that has not authored any migration yet.
78
+ */
79
+ async function enumerateMigrationSpaces(args) {
80
+ const { projectMigrationsDir } = args;
81
+ const spaceIds = (await listContractSpaceDirectories(projectMigrationsDir)).filter((name) => !RESERVED_SPACE_SUBDIR_NAMES.has(name)).filter(isValidSpaceId).sort(compareSpaceIds);
82
+ const spaces = [];
83
+ for (const spaceId of spaceIds) {
84
+ const spaceDir = spaceMigrationDirectory(projectMigrationsDir, spaceId);
85
+ const packages = await readMigrationsDir(spaceDir);
86
+ const refsByHash = await resolveRefsByContractHash(spaceRefsDirectory(spaceDir));
87
+ const migrations = packages.map((pkg) => ({
88
+ dirName: pkg.dirName,
89
+ from: pkg.metadata.from,
90
+ to: pkg.metadata.to,
91
+ migrationHash: pkg.metadata.migrationHash,
92
+ operationCount: pkg.ops.length,
93
+ createdAt: pkg.metadata.createdAt,
94
+ refs: refsByHash.get(pkg.metadata.to) ?? [],
95
+ providedInvariants: pkg.metadata.providedInvariants
96
+ })).sort(compareDirNamesDescending);
97
+ spaces.push({
98
+ spaceId,
99
+ migrations
100
+ });
101
+ }
102
+ return spaces;
103
+ }
104
+ //#endregion
105
+ export { enumerateMigrationSpaces, resolveRefsByContractHash };
106
+
107
+ //# sourceMappingURL=enumerate-migration-spaces.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enumerate-migration-spaces.mjs","names":[],"sources":["../../src/enumerate-migration-spaces.ts"],"sourcesContent":["import { readMigrationsDir } from './io';\nimport type { MigrationListEntry, MigrationSpaceListEntry } from './migration-list-types';\nimport { readRefs } from './refs';\nimport {\n APP_SPACE_ID,\n isValidSpaceId,\n RESERVED_SPACE_SUBDIR_NAMES,\n spaceMigrationDirectory,\n spaceRefsDirectory,\n} from './space-layout';\nimport { listContractSpaceDirectories } from './verify-contract-spaces';\n\n/**\n * Index `migrations/<space>/refs/*.json` by the contract hash each ref\n * points at, so callers can attach `(ref names)` decorations to every\n * row whose destination contract hash matches.\n *\n * Each bucket is sorted lex-asc to keep rendered output deterministic\n * (adjacent rows pointing at the same hash render their ref decorations\n * in the same order).\n *\n * Refs whose hash matches no migration on disk are still indexed; the\n * caller decides whether to surface them. Migration rows only carry\n * `(refs)` decorations when a matching destination contract hash exists\n * on disk — orphan refs are not rendered on any row.\n *\n * Returns an empty map when the refs directory does not exist\n * ({@link readRefs} treats `ENOENT` as \"no refs\").\n */\nexport async function resolveRefsByContractHash(\n refsDir: string,\n): Promise<ReadonlyMap<string, readonly string[]>> {\n const refs = await readRefs(refsDir);\n const byHash = new Map<string, string[]>();\n for (const [name, entry] of Object.entries(refs)) {\n const bucket = byHash.get(entry.hash);\n if (bucket) bucket.push(name);\n else byHash.set(entry.hash, [name]);\n }\n for (const bucket of byHash.values()) {\n bucket.sort();\n }\n return byHash;\n}\n\n/**\n * Compare two contract-space IDs for the inter-space ordering rule:\n * {@link APP_SPACE_ID} first if present, then lex-asc on the rest.\n */\nfunction compareSpaceIds(a: string, b: string): number {\n if (a === APP_SPACE_ID) return b === APP_SPACE_ID ? 0 : -1;\n if (b === APP_SPACE_ID) return 1;\n if (a < b) return -1;\n if (a > b) return 1;\n return 0;\n}\n\n/**\n * Sort `dirName` descending so the rendered output reads latest-first,\n * matching the `git log` latest-first convention.\n */\nfunction compareDirNamesDescending(a: MigrationListEntry, b: MigrationListEntry): number {\n if (a.dirName < b.dirName) return 1;\n if (a.dirName > b.dirName) return -1;\n return 0;\n}\n\n/**\n * Enumerate every contract space's on-disk migrations under\n * `<projectMigrationsDir>/`. For each valid space directory:\n *\n * - Loads on-disk packages via {@link readMigrationsDir}.\n * - Attaches ref decorations: each migration's `refs[]` lists every ref\n * name from `migrations/<spaceId>/refs/*.json` whose hash equals the\n * migration's destination contract hash.\n * - Sorts migrations within the space by `dirName` descending\n * (reverse-filename, latest first).\n *\n * Contract spaces are returned with {@link APP_SPACE_ID} first when\n * present, then the remaining ids lex-asc. A contract-space directory\n * that contains no migrations becomes `{ spaceId, migrations: [] }` so\n * the renderer's empty-state path can surface it.\n *\n * Directory entries that are not valid {@link isValidSpaceId} names are\n * skipped (a stray non-space directory under `migrations/` does not\n * spawn a phantom space entry). Entries whose name appears in\n * {@link RESERVED_SPACE_SUBDIR_NAMES} are also skipped — the per-space\n * `refs/` subdirectory name shape would otherwise satisfy\n * {@link isValidSpaceId} and surface as a phantom contract space.\n *\n * Returns `[]` when `<projectMigrationsDir>` does not exist — a fresh\n * project that has not authored any migration yet.\n */\nexport async function enumerateMigrationSpaces(args: {\n readonly projectMigrationsDir: string;\n}): Promise<readonly MigrationSpaceListEntry[]> {\n const { projectMigrationsDir } = args;\n const candidateDirs = await listContractSpaceDirectories(projectMigrationsDir);\n const spaceIds = candidateDirs\n .filter((name) => !RESERVED_SPACE_SUBDIR_NAMES.has(name))\n .filter(isValidSpaceId)\n .sort(compareSpaceIds);\n\n const spaces: MigrationSpaceListEntry[] = [];\n for (const spaceId of spaceIds) {\n const spaceDir = spaceMigrationDirectory(projectMigrationsDir, spaceId);\n const packages = await readMigrationsDir(spaceDir);\n const refsByHash = await resolveRefsByContractHash(spaceRefsDirectory(spaceDir));\n\n const migrations: MigrationListEntry[] = packages\n .map((pkg) => ({\n dirName: pkg.dirName,\n from: pkg.metadata.from,\n to: pkg.metadata.to,\n migrationHash: pkg.metadata.migrationHash,\n operationCount: pkg.ops.length,\n createdAt: pkg.metadata.createdAt,\n refs: refsByHash.get(pkg.metadata.to) ?? [],\n providedInvariants: pkg.metadata.providedInvariants,\n }))\n .sort(compareDirNamesDescending);\n\n spaces.push({ spaceId, migrations });\n }\n\n return spaces;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA6BA,eAAsB,0BACpB,SACiD;CACjD,MAAM,OAAO,MAAM,SAAS,OAAO;CACnC,MAAM,yBAAS,IAAI,IAAsB;CACzC,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,IAAI,GAAG;EAChD,MAAM,SAAS,OAAO,IAAI,MAAM,IAAI;EACpC,IAAI,QAAQ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AEA,OAAO;AACT"}
@@ -1,2 +1,2 @@
1
- import { n as MigrationGraph, t as MigrationEdge } from "../graph-BrLXqoUc.mjs";
1
+ import { n as MigrationGraph, t as MigrationEdge } from "../graph-C7AJPGV5.mjs";
2
2
  export { type MigrationEdge, type MigrationGraph };
@@ -1,5 +1,5 @@
1
- import { n as OnDiskMigrationPackage, t as MigrationOps } from "../package-DZj8YvD0.mjs";
2
- import { n as MigrationMetadata } from "../metadata-BFX0xdz8.mjs";
1
+ import { n as OnDiskMigrationPackage, t as MigrationOps } from "../package-DIttKL7X.mjs";
2
+ import { n as MigrationMetadata } from "../metadata-B4Wy6zor.mjs";
3
3
 
4
4
  //#region src/hash.d.ts
5
5
  interface VerifyResult {
@@ -1,4 +1,4 @@
1
- import { t as MigrationOps } from "../package-DZj8YvD0.mjs";
1
+ import { t as MigrationOps } from "../package-DIttKL7X.mjs";
2
2
 
3
3
  //#region src/invariants.d.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { n as OnDiskMigrationPackage, t as MigrationOps } from "../package-DZj8YvD0.mjs";
1
+ import { n as OnDiskMigrationPackage, t as MigrationOps } from "../package-DIttKL7X.mjs";
2
2
  import { MigrationMetadata, MigrationPackage } from "@prisma-next/framework-components/control";
3
3
 
4
4
  //#region src/io.d.ts
@@ -1,2 +1,2 @@
1
- import { n as MigrationMetadata, t as MigrationHints } from "../metadata-BFX0xdz8.mjs";
1
+ import { n as MigrationMetadata, t as MigrationHints } from "../metadata-B4Wy6zor.mjs";
2
2
  export { type MigrationHints, type MigrationMetadata };
@@ -1,5 +1,5 @@
1
- import { n as MigrationGraph } from "../graph-BrLXqoUc.mjs";
2
- import { a as findLeaf, c as findPathWithInvariants, i as findLatestMigration, l as findReachableLeaves, n as detectCycles, o as findPath, r as detectOrphans, s as findPathWithDecision, t as PathDecision, u as reconstructGraph } from "../migration-graph-De0dUZoC.mjs";
1
+ import { n as MigrationGraph } from "../graph-C7AJPGV5.mjs";
2
+ import { a as findLeaf, c as findPathWithInvariants, i as findLatestMigration, l as findReachableLeaves, n as detectCycles, o as findPath, r as detectOrphans, s as findPathWithDecision, t as PathDecision, u as reconstructGraph } from "../migration-graph-ABYqVsmv.mjs";
3
3
 
4
4
  //#region src/graph-membership.d.ts
5
5
  declare function isGraphNode(hash: string, graph: MigrationGraph): boolean;
@@ -0,0 +1,2 @@
1
+ import { n as MigrationListResult, r as MigrationSpaceListEntry, t as MigrationListEntry } from "../migration-list-types-B-qimPet.mjs";
2
+ export { type MigrationListEntry, type MigrationListResult, type MigrationSpaceListEntry };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- import { n as MigrationMetadata$1 } from "../metadata-BFX0xdz8.mjs";
1
+ import { n as MigrationMetadata$1 } from "../metadata-B4Wy6zor.mjs";
2
2
  import { ControlStack, MigrationPlan, MigrationPlanOperation } from "@prisma-next/framework-components/control";
3
3
 
4
4
  //#region src/migration-base.d.ts
@@ -1,3 +1,3 @@
1
- import { n as OnDiskMigrationPackage, t as MigrationOps } from "../package-DZj8YvD0.mjs";
1
+ import { n as OnDiskMigrationPackage, t as MigrationOps } from "../package-DIttKL7X.mjs";
2
2
  import { MigrationPackage } from "@prisma-next/framework-components/control";
3
3
  export { type MigrationOps, type MigrationPackage, type OnDiskMigrationPackage };
@@ -1,5 +1,5 @@
1
- import { n as MigrationGraph, t as MigrationEdge } from "../graph-BrLXqoUc.mjs";
2
- import { n as Refs } from "../refs-CDaNerhT.mjs";
1
+ import { n as MigrationGraph, t as MigrationEdge } from "../graph-C7AJPGV5.mjs";
2
+ import { n as Refs } from "../refs-BaygQaFD.mjs";
3
3
  import { Result } from "@prisma-next/utils/result";
4
4
 
5
5
  //#region src/refs/types.d.ts
@@ -1,4 +1,4 @@
1
- import { a as readRefs, c as validateRefValue, i as readRef, l as writeRef, n as Refs, o as resolveRef, r as deleteRef, s as validateRefName, t as RefEntry } from "../refs-CDaNerhT.mjs";
1
+ import { a as readRefs, c as validateRefValue, i as readRef, l as writeRef, n as Refs, o as resolveRef, r as deleteRef, s as validateRefName, t as RefEntry } from "../refs-BaygQaFD.mjs";
2
2
 
3
3
  //#region src/refs/snapshot.d.ts
4
4
  interface ContractIR {