@prisma-next/migration-tools 0.6.0-dev.3 → 0.6.0-dev.5

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.
@@ -92,17 +92,6 @@ interface ContractSpaceAggregate {
92
92
  }
93
93
  //#endregion
94
94
  //#region src/aggregate/loader.d.ts
95
- /**
96
- * Hash function used by drift detection. Defaults to a canonical-JSON +
97
- * SHA-256 pipeline that mirrors the framework's contract-hash convention,
98
- * but the loader accepts a callback so SQL-family callers can pass their
99
- * `coreHash` / `storageHash` derivation through unchanged.
100
- *
101
- * The contract value passed in is the framework-neutral `unknown` form;
102
- * callers that have already validated typed contracts can simply hand
103
- * the validated value back through.
104
- */
105
- type AggregateContractHasher = (contract: unknown) => string;
106
95
  /**
107
96
  * Single declared extension entry the loader needs from `Config.extensionPacks`.
108
97
  *
@@ -112,20 +101,20 @@ type AggregateContractHasher = (contract: unknown) => string;
112
101
  * - `targetId` — the configured `Config.adapter.targetId` value the
113
102
  * declaring extension declared. The loader rejects mismatches against
114
103
  * the aggregate's `targetId` with `targetMismatch`.
115
- * - `contractSpace` — present iff the descriptor declares a contract
116
- * space (extensions can ship without one and remain runtime-only /
117
- * codec-only). Drift detection compares the descriptor's
118
- * `contractJson` hash against the on-disk on-disk head hash; the loader
119
- * rejects drift fatally.
104
+ *
105
+ * Whether the descriptor declares a contract space is decided by whether
106
+ * its corresponding `migrations/<id>/` directory exists on disk
107
+ * (materialised by the seed phase before the loader runs); the loader
108
+ * never reads the descriptor's `contractJson` itself. That makes the
109
+ * aggregate's apply / verify paths byte-for-byte independent of the
110
+ * descriptor module — `db verify` succeeds even if the descriptor's
111
+ * `contractJson` is a throwing getter.
120
112
  *
121
113
  * Typed structurally so the migration-tools layer stays framework-neutral.
122
114
  */
123
115
  interface DeclaredExtensionEntry {
124
116
  readonly id: string;
125
117
  readonly targetId: string;
126
- readonly contractSpace?: {
127
- readonly contractJson: unknown;
128
- };
129
118
  }
130
119
  /**
131
120
  * Inputs for {@link loadContractSpaceAggregate}.
@@ -142,7 +131,6 @@ interface LoadAggregateInput {
142
131
  readonly appContract: Contract;
143
132
  readonly declaredExtensions: ReadonlyArray<DeclaredExtensionEntry>;
144
133
  readonly validateContract: (contractJson: unknown) => Contract;
145
- readonly hashContract: AggregateContractHasher;
146
134
  /**
147
135
  * Hydrated migration graph for the **app member**.
148
136
  *
@@ -175,11 +163,6 @@ type LoadAggregateError = {
175
163
  readonly kind: 'validationFailure';
176
164
  readonly spaceId: string;
177
165
  readonly detail: string;
178
- } | {
179
- readonly kind: 'driftViolation';
180
- readonly spaceId: string;
181
- readonly priorHeadHash: string;
182
- readonly liveHash: string;
183
166
  } | {
184
167
  readonly kind: 'disjointnessViolation';
185
168
  readonly element: string;
@@ -214,20 +197,22 @@ type LoadAggregateOutput = Result<{
214
197
  }, LoadAggregateError>;
215
198
  /**
216
199
  * Hydrate a {@link ContractSpaceAggregate} from on-disk state and
217
- * caller-provided descriptor data.
218
- *
219
- * This is the **only** descriptor-import boundary in the post-M2.5
220
- * pipeline: callers read `extensionPacks` from `Config`, validate the
221
- * app contract, and pass everything through. The loader composes
222
- * existing migration-tools primitives layout precheck (via
200
+ * the app contract value the caller supplies.
201
+ *
202
+ * The loader is the **only** descriptor-import boundary at apply /
203
+ * verify time, but it intentionally does **not** read the extension
204
+ * descriptor's `contractJson` value. Each extension space's contract
205
+ * is read from its on-disk `migrations/<id>/contract.json` mirror; the
206
+ * descriptor's role is exhausted by the seed phase that wrote that
207
+ * mirror in the first place. The loader composes existing
208
+ * migration-tools primitives — layout precheck (via
223
209
  * {@link listContractSpaceDirectories}), integrity checks (via
224
210
  * {@link readMigrationsDir} / {@link readContractSpaceHeadRef} /
225
- * {@link readContractSpaceContract} / `validateContract`), drift detection
226
- * (via {@link detectSpaceContractDrift}), and disjointness — into a
227
- * single typed value.
211
+ * {@link readContractSpaceContract} / `validateContract`), and
212
+ * disjointness — into a single typed value.
228
213
  *
229
214
  * Failure semantics: every failure variant in {@link LoadAggregateError}
230
- * short-circuits the load. Drift is fatal (M2.5 spec § Loader, step 5).
215
+ * short-circuits the load.
231
216
  */
232
217
  declare function loadContractSpaceAggregate(input: LoadAggregateInput): Promise<LoadAggregateOutput>;
233
218
  //#endregion
@@ -610,5 +595,5 @@ type AggregateVerifierOutput<TSchemaResult> = Result<AggregateVerifierSuccess<TS
610
595
  */
611
596
  declare function verifyAggregate<TSchemaResult>(input: AggregateVerifierInput<TSchemaResult>): AggregateVerifierOutput<TSchemaResult>;
612
597
  //#endregion
613
- export { type AggregateContractHasher, type AggregateCurrentDBState, type AggregatePerSpacePlan, type AggregatePlannerError, type AggregatePlannerInput, type AggregatePlannerOutput, type AggregatePlannerSuccess, type AggregateVerifierError, type AggregateVerifierInput, type AggregateVerifierOutput, type AggregateVerifierSuccess, type CallerPolicy, type ContractMarkerRecordLike, type ContractSpaceAggregate, type ContractSpaceMember, type DeclaredExtensionEntry, type GraphWalkOutcome, type GraphWalkStrategyInputs, type HydratedMigrationGraph, type LayoutViolation, type LoadAggregateError, type LoadAggregateInput, type LoadAggregateOutput, type MarkerCheckResult, type MarkerCheckSection, type OrphanElement, type SchemaCheckSection, graphWalkStrategy, loadContractSpaceAggregate, planAggregate, projectSchemaToSpace, verifyAggregate };
598
+ export { type AggregateCurrentDBState, type AggregateMigrationEdgeRef, type AggregatePerSpacePlan, type AggregatePlannerError, type AggregatePlannerInput, type AggregatePlannerOutput, type AggregatePlannerSuccess, type AggregateVerifierError, type AggregateVerifierInput, type AggregateVerifierOutput, type AggregateVerifierSuccess, type CallerPolicy, type ContractMarkerRecordLike, type ContractSpaceAggregate, type ContractSpaceMember, type DeclaredExtensionEntry, type GraphWalkOutcome, type GraphWalkStrategyInputs, type HydratedMigrationGraph, type LayoutViolation, type LoadAggregateError, type LoadAggregateInput, type LoadAggregateOutput, type MarkerCheckResult, type MarkerCheckSection, type OrphanElement, type SchemaCheckSection, graphWalkStrategy, loadContractSpaceAggregate, planAggregate, projectSchemaToSpace, verifyAggregate };
614
599
  //# sourceMappingURL=aggregate.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"aggregate.d.mts","names":[],"sources":["../../src/aggregate/types.ts","../../src/aggregate/loader.ts","../../src/aggregate/marker-types.ts","../../src/aggregate/planner-types.ts","../../src/aggregate/planner.ts","../../src/aggregate/project-schema-to-space.ts","../../src/aggregate/strategies/graph-walk.ts","../../src/aggregate/verifier.ts"],"mappings":";;;;;;;;;;;;;;;AAkBA;;;;;;;;UAAiB,sBAAA;EAAA,SACN,KAAA,EAAO,cAAA;EAAA,SACP,uBAAA,EAAyB,WAAA,SAAoB,sBAAA;AAAA;;;;AAwBxD;;;;;;;;;;;;;;AAwCA;;;;UAxCiB,mBAAA;EAAA,SACN,OAAA;EAAA,SACA,QAAA,EAAU,QAAA;EAAA,SACV,OAAA;IAAA,SACE,IAAA;IAAA,SACA,UAAA;EAAA;EAAA,SAEF,UAAA,EAAY,sBAAA;AAAA;;AC5BvB;;;;;AAmBA;;;;;;;;;;AAiBA;;;;;;;;;;;;;;UDyBiB,sBAAA;EAAA,SACN,QAAA;EAAA,SACA,GAAA,EAAK,mBAAA;EAAA,SACL,UAAA,WAAqB,mBAAA;AAAA;;;;;;;;AArEhC;;;;;KCKY,uBAAA,IAA2B,QAAA;;;;;;;;;;ADqBvC;;;;;;;;UCFiB,sBAAA;EAAA,SACN,EAAA;EAAA,SACA,QAAA;EAAA,SACA,aAAA;IAAA,SACE,YAAA;EAAA;AAAA;;;;;;;;;;UAaI,kBAAA;EAAA,SACN,QAAA;EAAA,SACA,aAAA;EAAA,SACA,WAAA,EAAa,QAAA;EAAA,SACb,kBAAA,EAAoB,aAAA,CAAc,sBAAA;EAAA,SAClC,gBAAA,GAAmB,YAAA,cAA0B,QAAA;EAAA,SAC7C,YAAA,EAAc,uBAAA;EA1Cc;;AAmBvC;;;;;;;;;;EAnBuC,SAuD5B,oBAAA,EAAsB,aAAA,CAAc,sBAAA;AAAA;;;;;;;;KAUnC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,KAGC,uBAAA,kBAAyC,MAAA,CACnD,wBAAA,CAAyB,aAAA,GACzB,sBAAA;;;;;;;;;;;;;ANLF;;;;;;;;;;iBM8BgB,eAAA,eAAA,CACd,KAAA,EAAO,sBAAA,CAAuB,aAAA,IAC7B,uBAAA,CAAwB,aAAA"}
1
+ {"version":3,"file":"aggregate.d.mts","names":[],"sources":["../../src/aggregate/types.ts","../../src/aggregate/loader.ts","../../src/aggregate/marker-types.ts","../../src/aggregate/planner-types.ts","../../src/aggregate/planner.ts","../../src/aggregate/project-schema-to-space.ts","../../src/aggregate/strategies/graph-walk.ts","../../src/aggregate/verifier.ts"],"mappings":";;;;;;;;;;;;;;;AAkBA;;;;;;;;UAAiB,sBAAA;EAAA,SACN,KAAA,EAAO,cAAA;EAAA,SACP,uBAAA,EAAyB,WAAA,SAAoB,sBAAA;AAAA;;;;AAwBxD;;;;;;;;;;;;;;AAwCA;;;;UAxCiB,mBAAA;EAAA,SACN,OAAA;EAAA,SACA,QAAA,EAAU,QAAA;EAAA,SACV,OAAA;IAAA,SACE,IAAA;IAAA,SACA,UAAA;EAAA;EAAA,SAEF,UAAA,EAAY,sBAAA;AAAA;;ACnBvB;;;;;AAcA;;;;;;;;;;;;;;;;;;;;;;;;UDsCiB,sBAAA;EAAA,SACN,QAAA;EAAA,SACA,GAAA,EAAK,mBAAA;EAAA,SACL,UAAA,WAAqB,mBAAA;AAAA;;;;;;;;AArEhC;;;;;;;;;;;;;;;UCciB,sBAAA;EAAA,SACN,EAAA;EAAA,SACA,QAAA;AAAA;;;;;;;;;;UAYM,kBAAA;EAAA,SACN,QAAA;EAAA,SACA,aAAA;EAAA,SACA,WAAA,EAAa,QAAA;EAAA,SACb,kBAAA,EAAoB,aAAA,CAAc,sBAAA;EAAA,SAClC,gBAAA,GAAmB,YAAA,cAA0B,QAAA;EDmC7C;;;;;;;;;ACtDX;;;EDsDW,SCtBA,oBAAA,EAAsB,aAAA,CAAc,sBAAA;AAAA;AAlB/C;;;;;;;A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yC,MAAA,CACnD,wBAAA,CAAyB,aAAA,GACzB,sBAAA;;;;;;;;;;;;;;;;;;;;;;ANSF;iBMgBgB,eAAA,eAAA,CACd,KAAA,EAAO,sBAAA,CAAuB,aAAA,IAC7B,uBAAA,CAAwB,aAAA"}
@@ -1,25 +1,27 @@
1
1
  import { s as readMigrationsDir } from "../io-D5YYptRO.mjs";
2
2
  import "../constants-DWV9_o2Z.mjs";
3
3
  import { l as reconstructGraph, o as findPathWithDecision } from "../migration-graph-DGNnKDY5.mjs";
4
- import { a as readContractSpaceHeadRef, i as detectSpaceContractDrift, l as spaceMigrationDirectory, n as listContractSpaceDirectories, o as APP_SPACE_ID, t as readContractSpaceContract } from "../read-contract-space-contract-Bj_EMYSC.mjs";
4
+ import { a as APP_SPACE_ID, c as spaceMigrationDirectory, i as readContractSpaceHeadRef, n as listContractSpaceDirectories, t as readContractSpaceContract } from "../read-contract-space-contract-Cme8KZk_.mjs";
5
5
  import { notOk, ok } from "@prisma-next/utils/result";
6
6
  //#region src/aggregate/loader.ts
7
7
  /**
8
8
  * Hydrate a {@link ContractSpaceAggregate} from on-disk state and
9
- * caller-provided descriptor data.
9
+ * the app contract value the caller supplies.
10
10
  *
11
- * This is the **only** descriptor-import boundary in the post-M2.5
12
- * pipeline: callers read `extensionPacks` from `Config`, validate the
13
- * app contract, and pass everything through. The loader composes
14
- * existing migration-tools primitives layout precheck (via
11
+ * The loader is the **only** descriptor-import boundary at apply /
12
+ * verify time, but it intentionally does **not** read the extension
13
+ * descriptor's `contractJson` value. Each extension space's contract
14
+ * is read from its on-disk `migrations/<id>/contract.json` mirror; the
15
+ * descriptor's role is exhausted by the seed phase that wrote that
16
+ * mirror in the first place. The loader composes existing
17
+ * migration-tools primitives — layout precheck (via
15
18
  * {@link listContractSpaceDirectories}), integrity checks (via
16
19
  * {@link readMigrationsDir} / {@link readContractSpaceHeadRef} /
17
- * {@link readContractSpaceContract} / `validateContract`), drift detection
18
- * (via {@link detectSpaceContractDrift}), and disjointness — into a
19
- * single typed value.
20
+ * {@link readContractSpaceContract} / `validateContract`), and
21
+ * disjointness — into a single typed value.
20
22
  *
21
23
  * Failure semantics: every failure variant in {@link LoadAggregateError}
22
- * short-circuits the load. Drift is fatal (M2.5 spec § Loader, step 5).
24
+ * short-circuits the load.
23
25
  */
24
26
  async function loadContractSpaceAggregate(input) {
25
27
  const appContractTarget = input.appContract.target;
@@ -35,8 +37,7 @@ async function loadContractSpaceAggregate(input) {
35
37
  expected: input.targetId,
36
38
  actual: entry.targetId
37
39
  });
38
- const declaredWithSpace = input.declaredExtensions.filter((e) => e.contractSpace !== void 0);
39
- const declaredSpaceIds = new Set(declaredWithSpace.map((e) => e.id));
40
+ const declaredSpaceIds = new Set(input.declaredExtensions.map((e) => e.id));
40
41
  const extensionDirsOnDisk = (await listContractSpaceDirectories(input.migrationsDir)).filter((d) => d !== APP_SPACE_ID);
41
42
  const spaceDirSet = new Set(extensionDirsOnDisk);
42
43
  const layoutViolations = [];
@@ -53,7 +54,7 @@ async function loadContractSpaceAggregate(input) {
53
54
  violations: layoutViolations
54
55
  });
55
56
  const loadedExtensions = [];
56
- for (const entry of [...declaredWithSpace].sort((a, b) => a.id.localeCompare(b.id))) {
57
+ for (const entry of [...input.declaredExtensions].sort((a, b) => a.id.localeCompare(b.id))) {
57
58
  const headRef = await readContractSpaceHeadRef(input.migrationsDir, entry.id);
58
59
  if (headRef === null) return notOk({
59
60
  kind: "integrityFailure",
@@ -86,19 +87,6 @@ async function loadContractSpaceAggregate(input) {
86
87
  expected: input.targetId,
87
88
  actual: spaceContract.target
88
89
  });
89
- if (entry.contractSpace) {
90
- const liveHash = input.hashContract(entry.contractSpace.contractJson);
91
- const drift = detectSpaceContractDrift(entry.id, {
92
- descriptorHash: liveHash,
93
- priorHeadHash: headRef.hash
94
- });
95
- if (drift.kind === "drift") return notOk({
96
- kind: "driftViolation",
97
- spaceId: entry.id,
98
- priorHeadHash: drift.priorHeadHash ?? "",
99
- liveHash: drift.descriptorHash
100
- });
101
- }
102
90
  let packages;
103
91
  try {
104
92
  packages = await readMigrationsDir(spaceMigrationDirectory(input.migrationsDir, entry.id));
@@ -1 +1 @@
1
- {"version":3,"file":"aggregate.mjs","names":[],"sources":["../../src/aggregate/loader.ts","../../src/aggregate/strategies/graph-walk.ts","../../src/aggregate/project-schema-to-space.ts","../../src/aggregate/strategies/synth.ts","../../src/aggregate/planner.ts","../../src/aggregate/verifier.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { EMPTY_CONTRACT_HASH } from '../constants';\nimport { detectSpaceContractDrift } from '../detect-space-contract-drift';\nimport { readMigrationsDir } from '../io';\nimport { reconstructGraph } from '../migration-graph';\nimport type { OnDiskMigrationPackage } from '../package';\nimport { readContractSpaceContract } from '../read-contract-space-contract';\nimport { readContractSpaceHeadRef } from '../read-contract-space-head-ref';\nimport { APP_SPACE_ID, spaceMigrationDirectory } from '../space-layout';\nimport { listContractSpaceDirectories } from '../verify-contract-spaces';\nimport type { ContractSpaceAggregate, ContractSpaceMember, HydratedMigrationGraph } from './types';\n\n/**\n * Hash function used by drift detection. Defaults to a canonical-JSON +\n * SHA-256 pipeline that mirrors the framework's contract-hash convention,\n * but the loader accepts a callback so SQL-family callers can pass their\n * `coreHash` / `storageHash` derivation through unchanged.\n *\n * The contract value passed in is the framework-neutral `unknown` form;\n * callers that have already validated typed contracts can simply hand\n * the validated value back through.\n */\nexport type AggregateContractHasher = (contract: unknown) => string;\n\n/**\n * Single declared extension entry the loader needs from `Config.extensionPacks`.\n *\n * Only the subset of fields the loader operates on:\n *\n * - `id` — the space id (also the directory name under `migrations/`).\n * - `targetId` — the configured `Config.adapter.targetId` value the\n * declaring extension declared. The loader rejects mismatches against\n * the aggregate's `targetId` with `targetMismatch`.\n * - `contractSpace` — present iff the descriptor declares a contract\n * space (extensions can ship without one and remain runtime-only /\n * codec-only). Drift detection compares the descriptor's\n * `contractJson` hash against the on-disk on-disk head hash; the loader\n * rejects drift fatally.\n *\n * Typed structurally so the migration-tools layer stays framework-neutral.\n */\nexport interface DeclaredExtensionEntry {\n readonly id: string;\n readonly targetId: string;\n readonly contractSpace?: {\n readonly contractJson: unknown;\n };\n}\n\n/**\n * Inputs for {@link loadContractSpaceAggregate}.\n *\n * The loader is the **sole** descriptor-import boundary in the M2.5\n * pipeline: callers gather the descriptor data (already-validated app\n * contract, declared extension entries) and pass it through. Once the\n * loader returns, no descriptor module is imported again for this\n * aggregate's lifetime.\n */\nexport interface LoadAggregateInput {\n readonly targetId: string;\n readonly migrationsDir: string;\n readonly appContract: Contract;\n readonly declaredExtensions: ReadonlyArray<DeclaredExtensionEntry>;\n readonly validateContract: (contractJson: unknown) => Contract;\n readonly hashContract: AggregateContractHasher;\n /**\n * Hydrated migration graph for the **app member**.\n *\n * The framework-neutral migration-tools layer doesn't know how to read\n * the user's authored `migrations/` directory (the app member's\n * migration-package layout is family-aware: ops.json shape, manifest\n * keys, etc.). Callers — the SQL family today — read the user's\n * `migrations/` and hand the resulting `OnDiskMigrationPackage[]` through.\n *\n * Passing `[]` is valid (greenfield project, no authored migrations).\n * Equivalent to `migrations/` not existing or being empty.\n */\n readonly appMigrationPackages: ReadonlyArray<OnDiskMigrationPackage>;\n}\n\n/**\n * Discriminated failure variants the loader emits.\n *\n * Every variant short-circuits at first hit; the loader does not keep\n * collecting after the first violation in any phase except for layout\n * (where every layout offence is bundled into one `layoutViolation`).\n */\nexport type LoadAggregateError =\n | { readonly kind: 'layoutViolation'; readonly violations: readonly LayoutViolation[] }\n | { readonly kind: 'integrityFailure'; readonly spaceId: string; readonly detail: string }\n | { readonly kind: 'validationFailure'; readonly spaceId: string; readonly detail: string }\n | {\n readonly kind: 'driftViolation';\n readonly spaceId: string;\n readonly priorHeadHash: string;\n readonly liveHash: string;\n }\n | {\n readonly kind: 'disjointnessViolation';\n readonly element: string;\n readonly claimedBy: readonly string[];\n }\n | {\n readonly kind: 'targetMismatch';\n readonly spaceId: string;\n readonly expected: string;\n readonly actual: string;\n };\n\n/**\n * Single layout violation; bundled into a `layoutViolation` error so\n * users see every layout offence at once rather than fixing them one\n * at a time across re-runs.\n *\n * - `declaredButUnmigrated`: extension declared in `extensionPacks` with\n * a `contractSpace` but no contract-space dir on disk. Remediation:\n * `prisma-next migrate`.\n * - `orphanSpaceDir`: contract-space dir under `migrations/` for an extension\n * not in `extensionPacks`. Remediation: remove the directory, or\n * re-add the extension to `extensionPacks`.\n */\nexport type LayoutViolation =\n | { readonly kind: 'declaredButUnmigrated'; readonly spaceId: string }\n | { readonly kind: 'orphanSpaceDir'; readonly spaceId: string };\n\nexport type LoadAggregateOutput = Result<\n { readonly aggregate: ContractSpaceAggregate },\n LoadAggregateError\n>;\n\ninterface LoadedExtensionState {\n readonly entry: DeclaredExtensionEntry;\n readonly contract: Contract;\n readonly headRefHash: string;\n readonly headRefInvariants: readonly string[];\n readonly migrations: HydratedMigrationGraph;\n}\n\n/**\n * Hydrate a {@link ContractSpaceAggregate} from on-disk state and\n * caller-provided descriptor data.\n *\n * This is the **only** descriptor-import boundary in the post-M2.5\n * pipeline: callers read `extensionPacks` from `Config`, validate the\n * app contract, and pass everything through. The loader composes\n * existing migration-tools primitives — layout precheck (via\n * {@link listContractSpaceDirectories}), integrity checks (via\n * {@link readMigrationsDir} / {@link readContractSpaceHeadRef} /\n * {@link readContractSpaceContract} / `validateContract`), drift detection\n * (via {@link detectSpaceContractDrift}), and disjointness — into a\n * single typed value.\n *\n * Failure semantics: every failure variant in {@link LoadAggregateError}\n * short-circuits the load. Drift is fatal (M2.5 spec § Loader, step 5).\n */\nexport async function loadContractSpaceAggregate(\n input: LoadAggregateInput,\n): Promise<LoadAggregateOutput> {\n // 1. Validate target consistency on the app contract.\n const appContractTarget = input.appContract.target;\n if (appContractTarget !== input.targetId) {\n return notOk({\n kind: 'targetMismatch',\n spaceId: APP_SPACE_ID,\n expected: input.targetId,\n actual: appContractTarget,\n });\n }\n\n for (const entry of input.declaredExtensions) {\n if (entry.targetId !== input.targetId) {\n return notOk({\n kind: 'targetMismatch',\n spaceId: entry.id,\n expected: input.targetId,\n actual: entry.targetId,\n });\n }\n }\n\n // 2. Layout precheck: bundle every layout offence at once.\n const declaredWithSpace = input.declaredExtensions.filter((e) => e.contractSpace !== undefined);\n const declaredSpaceIds = new Set(declaredWithSpace.map((e) => e.id));\n const allDirs = await listContractSpaceDirectories(input.migrationsDir);\n // The app member is implicitly declared (it is always part of the\n // aggregate); its `migrations/<APP_SPACE_ID>/` directory may exist or\n // not (greenfield projects start with neither). Filter it out of the\n // orphan / declared-but-unmigrated checks so the layout precheck is\n // about extensions only.\n const extensionDirsOnDisk = allDirs.filter((d) => d !== APP_SPACE_ID);\n const spaceDirSet = new Set(extensionDirsOnDisk);\n\n const layoutViolations: LayoutViolation[] = [];\n for (const dir of extensionDirsOnDisk) {\n if (!declaredSpaceIds.has(dir)) {\n layoutViolations.push({ kind: 'orphanSpaceDir', spaceId: dir });\n }\n }\n for (const id of [...declaredSpaceIds].sort()) {\n if (!spaceDirSet.has(id)) {\n layoutViolations.push({ kind: 'declaredButUnmigrated', spaceId: id });\n }\n }\n if (layoutViolations.length > 0) {\n return notOk({ kind: 'layoutViolation', violations: layoutViolations });\n }\n\n // 3-5. Per-extension: read + validate + integrity-check + drift.\n const loadedExtensions: LoadedExtensionState[] = [];\n for (const entry of [...declaredWithSpace].sort((a, b) => a.id.localeCompare(b.id))) {\n const headRef = await readContractSpaceHeadRef(input.migrationsDir, entry.id);\n if (headRef === null) {\n return notOk({\n kind: 'integrityFailure',\n spaceId: entry.id,\n detail: `Head ref \\`refs/head.json\\` is missing for extension space \"${entry.id}\".`,\n });\n }\n\n let spaceContractRaw: unknown;\n try {\n spaceContractRaw = await readContractSpaceContract(input.migrationsDir, entry.id);\n } catch (error) {\n return notOk({\n kind: 'integrityFailure',\n spaceId: entry.id,\n detail: error instanceof Error ? error.message : String(error),\n });\n }\n\n let spaceContract: Contract;\n try {\n spaceContract = input.validateContract(spaceContractRaw);\n } catch (error) {\n return notOk({\n kind: 'validationFailure',\n spaceId: entry.id,\n detail: error instanceof Error ? error.message : String(error),\n });\n }\n\n if (spaceContract.target !== input.targetId) {\n return notOk({\n kind: 'targetMismatch',\n spaceId: entry.id,\n expected: input.targetId,\n actual: spaceContract.target,\n });\n }\n\n // Drift: compare descriptor's live `contractJson` to on-disk\n // `refs/head.json.hash`.\n if (entry.contractSpace) {\n const liveHash = input.hashContract(entry.contractSpace.contractJson);\n const drift = detectSpaceContractDrift(entry.id, {\n descriptorHash: liveHash,\n priorHeadHash: headRef.hash,\n });\n if (drift.kind === 'drift') {\n return notOk({\n kind: 'driftViolation',\n spaceId: entry.id,\n priorHeadHash: drift.priorHeadHash ?? '',\n liveHash: drift.descriptorHash,\n });\n }\n }\n\n // Read + integrity-check the migration packages. `readMigrationsDir`\n // re-derives `providedInvariants` and verifies migrationHash for\n // every package.\n let packages: readonly OnDiskMigrationPackage[];\n try {\n packages = await readMigrationsDir(spaceMigrationDirectory(input.migrationsDir, entry.id));\n } catch (error) {\n return notOk({\n kind: 'integrityFailure',\n spaceId: entry.id,\n detail: error instanceof Error ? error.message : String(error),\n });\n }\n\n let graph: ReturnType<typeof reconstructGraph>;\n try {\n graph = reconstructGraph(packages);\n } catch (error) {\n return notOk({\n kind: 'integrityFailure',\n spaceId: entry.id,\n detail: error instanceof Error ? error.message : String(error),\n });\n }\n\n // The on-disk head ref must be reachable in the graph. Empty graphs\n // are tolerated only when the head ref points at the empty-contract\n // sentinel (a never-emitted extension space; not a typical scenario\n // because the layout precheck would have flagged the missing\n // dir, but defensible).\n if (graph.nodes.size === 0) {\n if (headRef.hash !== EMPTY_CONTRACT_HASH) {\n return notOk({\n kind: 'integrityFailure',\n spaceId: entry.id,\n detail: `Head ref \"${headRef.hash}\" is not present in the (empty) on-disk migration graph.`,\n });\n }\n } else if (!graph.nodes.has(headRef.hash)) {\n return notOk({\n kind: 'integrityFailure',\n spaceId: entry.id,\n detail: `Head ref \"${headRef.hash}\" is not present in the on-disk migration graph.`,\n });\n }\n\n const packagesByMigrationHash = new Map<string, OnDiskMigrationPackage>(\n packages.map((p) => [p.metadata.migrationHash, p]),\n );\n\n loadedExtensions.push({\n entry,\n contract: spaceContract,\n headRefHash: headRef.hash,\n headRefInvariants: [...headRef.invariants].sort(),\n migrations: { graph, packagesByMigrationHash },\n });\n }\n\n // 6. Build app member with hydrated graph from caller-supplied packages.\n let appGraph: ReturnType<typeof reconstructGraph>;\n try {\n appGraph = reconstructGraph(input.appMigrationPackages);\n } catch (error) {\n return notOk({\n kind: 'integrityFailure',\n spaceId: APP_SPACE_ID,\n detail: error instanceof Error ? error.message : String(error),\n });\n }\n const appPackagesByMigrationHash = new Map<string, OnDiskMigrationPackage>(\n input.appMigrationPackages.map((p) => [p.metadata.migrationHash, p]),\n );\n\n const appMember: ContractSpaceMember = {\n spaceId: APP_SPACE_ID,\n contract: input.appContract,\n headRef: {\n hash: input.appContract.storage.storageHash,\n invariants: [],\n },\n migrations: {\n graph: appGraph,\n packagesByMigrationHash: appPackagesByMigrationHash,\n },\n };\n\n const extensionMembers: ContractSpaceMember[] = loadedExtensions.map((s) => ({\n spaceId: s.entry.id,\n contract: s.contract,\n headRef: {\n hash: s.headRefHash,\n invariants: s.headRefInvariants,\n },\n migrations: s.migrations,\n }));\n\n // 7. Disjointness: no two members claim the same storage element.\n const elementClaimedBy = new Map<string, string[]>();\n for (const member of [appMember, ...extensionMembers]) {\n const tables = extractTableNames(member.contract);\n for (const tableName of tables) {\n const claimers = elementClaimedBy.get(tableName);\n if (claimers) claimers.push(member.spaceId);\n else elementClaimedBy.set(tableName, [member.spaceId]);\n }\n }\n for (const [element, claimedBy] of elementClaimedBy) {\n if (claimedBy.length > 1) {\n return notOk({\n kind: 'disjointnessViolation',\n element,\n claimedBy: [...claimedBy].sort(),\n });\n }\n }\n\n return ok({\n aggregate: {\n targetId: input.targetId,\n app: appMember,\n extensions: extensionMembers,\n },\n });\n}\n\n/**\n * Extract the set of top-level storage table names from a contract.\n * Duck-typed: returns `[]` if the contract's storage shape doesn't\n * match the canonical `storage.tables: Record<string, ...>` form. A\n * future family with a different storage shape gets disjointness\n * effectively disabled (not enforced) rather than a hard failure.\n */\nfunction extractTableNames(contract: Contract): readonly string[] {\n const storage = (contract as { readonly storage?: unknown }).storage;\n if (typeof storage !== 'object' || storage === null) return [];\n const tables = (storage as { readonly tables?: unknown }).tables;\n if (typeof tables !== 'object' || tables === null) return [];\n return Object.keys(tables as Record<string, unknown>);\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport type { MigrationPlan } from '@prisma-next/framework-components/control';\nimport { EMPTY_CONTRACT_HASH } from '../../constants';\nimport { findPathWithDecision } from '../../migration-graph';\nimport type { MigrationOps } from '../../package';\nimport type { ContractMarkerRecordLike } from '../marker-types';\nimport type { AggregatePerSpacePlan } from '../planner-types';\nimport type { ContractSpaceMember } from '../types';\n\n/**\n * Outcome variants for the graph-walk strategy. Mirrors\n * {@link import('../../compute-extension-space-apply-path').ExtensionSpaceApplyPathOutcome}\n * but operates against the **already-hydrated** `member.migrations.graph`\n * instead of re-reading from disk. The aggregate planner converts\n * these into {@link import('../planner-types').AggregatePlannerError}\n * variants.\n */\nexport type GraphWalkOutcome =\n | { readonly kind: 'ok'; readonly result: AggregatePerSpacePlan }\n | { readonly kind: 'unreachable' }\n | { readonly kind: 'unsatisfiable'; readonly missing: readonly string[] };\n\nexport interface GraphWalkStrategyInputs {\n readonly aggregateTargetId: string;\n readonly member: ContractSpaceMember;\n readonly currentMarker: ContractMarkerRecordLike | null;\n /**\n * Optional ref name to decorate the resulting `PathDecision`. Used by\n * `migration apply` to surface the user-supplied `--ref <name>` in\n * structured-progress events and invariant-path error envelopes. The\n * strategy itself does not interpret it.\n */\n readonly refName?: string;\n}\n\n/**\n * Walk a member's hydrated migration graph from the live marker to\n * `member.headRef.hash`, covering every required invariant.\n *\n * Pure synchronous function — no I/O. The aggregate's loader has\n * already integrity-checked every package and reconstructed the graph;\n * this strategy just looks up ops by `migrationHash` and assembles a\n * `MigrationPlan` with `targetId` set from the aggregate (no\n * placeholder cast).\n *\n * Required invariants are computed as `headRef.invariants \\ marker.invariants`\n * — the marker already declares some invariants satisfied; the path\n * only needs to provide the remainder. Mirrors today's\n * `computeExtensionSpaceApplyPath` semantics.\n */\nexport function graphWalkStrategy(input: GraphWalkStrategyInputs): GraphWalkOutcome {\n const { aggregateTargetId, member, currentMarker, refName } = input;\n const { graph, packagesByMigrationHash } = member.migrations;\n\n const fromHash = currentMarker?.storageHash ?? EMPTY_CONTRACT_HASH;\n const markerInvariants = new Set(currentMarker?.invariants ?? []);\n const required = new Set(member.headRef.invariants.filter((id) => !markerInvariants.has(id)));\n\n const outcome = findPathWithDecision(graph, fromHash, member.headRef.hash, {\n required,\n ...(refName !== undefined ? { refName } : {}),\n });\n\n if (outcome.kind === 'unreachable') {\n return { kind: 'unreachable' };\n }\n if (outcome.kind === 'unsatisfiable') {\n return { kind: 'unsatisfiable', missing: outcome.missing };\n }\n\n const pathOps: MigrationOps[number][] = [];\n const providedInvariantsSet = new Set<string>();\n const edgeRefs: Array<{\n migrationHash: string;\n dirName: string;\n from: string;\n to: string;\n operationCount: number;\n }> = [];\n for (const edge of outcome.decision.selectedPath) {\n const pkg = packagesByMigrationHash.get(edge.migrationHash);\n if (!pkg) {\n throw new Error(\n `Migration package missing for edge ${edge.migrationHash} in space \"${member.spaceId}\". The hydrated migration graph and packagesByMigrationHash map are out of sync — this should be unreachable; report.`,\n );\n }\n for (const op of pkg.ops) pathOps.push(op);\n for (const invariant of pkg.metadata.providedInvariants) providedInvariantsSet.add(invariant);\n edgeRefs.push({\n migrationHash: edge.migrationHash,\n dirName: edge.dirName,\n from: edge.from,\n to: edge.to,\n operationCount: pkg.ops.length,\n });\n }\n\n const plan: MigrationPlan = {\n targetId: aggregateTargetId,\n spaceId: member.spaceId,\n origin: currentMarker === null ? null : { storageHash: currentMarker.storageHash },\n destination: { storageHash: member.headRef.hash },\n operations: pathOps,\n providedInvariants: [...providedInvariantsSet].sort(),\n };\n\n return {\n kind: 'ok',\n result: {\n plan,\n displayOps: pathOps,\n destinationContract: member.contract as Contract,\n strategy: 'graph-walk',\n migrationEdges: edgeRefs,\n pathDecision: outcome.decision,\n },\n };\n}\n","import type { ContractSpaceMember } from './types';\n\n/**\n * Project the introspected live schema to the slice claimed by a single\n * contract-space member.\n *\n * Returns the same `schema` value with every top-level table claimed by\n * **other** members of the aggregate removed. Tables not claimed by any\n * member flow through unchanged — the planner / verifier sees them as\n * orphans (extras in strict mode).\n *\n * Used by:\n *\n * - The aggregate planner's **synth strategy**: when synthesising a\n * plan against a member's contract, the live schema must be projected\n * to that member's slice so the planner doesn't treat tables claimed\n * by other members as \"extras\" and emit destructive ops to drop\n * them.\n * - The aggregate verifier's **schemaCheck**: projects per member so the\n * single-contract `verifySqlSchema` only sees the slice claimed by\n * the member it is checking. Closes the F23 architectural concern\n * (multi-member deployments where each member's tables look like\n * extras to every other member's verify pass).\n *\n * **Duck-typing semantics**: the helper operates on `unknown` for the\n * schema and falls through structurally if the shape doesn't match.\n * Every family today exposes `storage.tables: Record<string, ...>` and\n * the introspected schema mirrors the same shape; a future family with\n * a different storage shape gets the schema returned unchanged rather\n * than blowing up the aggregate planner.\n */\nexport function projectSchemaToSpace(\n schema: unknown,\n member: ContractSpaceMember,\n otherMembers: ReadonlyArray<ContractSpaceMember>,\n): unknown {\n if (typeof schema !== 'object' || schema === null) return schema;\n const schemaObj = schema as { readonly tables?: unknown };\n if (typeof schemaObj.tables !== 'object' || schemaObj.tables === null) return schema;\n const schemaTables = schemaObj.tables as Record<string, unknown>;\n\n const ownedByOthers = new Set<string>();\n for (const other of otherMembers) {\n if (other.spaceId === member.spaceId) continue;\n const storage = (other.contract as { readonly storage?: unknown }).storage;\n if (typeof storage !== 'object' || storage === null) continue;\n const tables = (storage as { readonly tables?: unknown }).tables;\n if (typeof tables !== 'object' || tables === null) continue;\n for (const tableName of Object.keys(tables as Record<string, unknown>)) {\n ownedByOthers.add(tableName);\n }\n }\n\n if (ownedByOthers.size === 0) return schema;\n\n const prunedTables: Record<string, unknown> = {};\n for (const [name, table] of Object.entries(schemaTables)) {\n if (!ownedByOthers.has(name)) {\n prunedTables[name] = table;\n }\n }\n\n return { ...schemaObj, tables: prunedTables };\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';\nimport type {\n ControlFamilyInstance,\n MigrationOperationPolicy,\n MigrationPlan,\n MigrationPlannerConflict,\n MigrationPlannerResult,\n TargetMigrationsCapability,\n} from '@prisma-next/framework-components/control';\nimport type { AggregatePerSpacePlan } from '../planner-types';\nimport { projectSchemaToSpace } from '../project-schema-to-space';\nimport type { ContractSpaceMember } from '../types';\n\nexport interface SynthStrategyInputs<TFamilyId extends string, TTargetId extends string> {\n readonly aggregateTargetId: string;\n readonly member: ContractSpaceMember;\n readonly otherMembers: ReadonlyArray<ContractSpaceMember>;\n readonly schemaIntrospection: unknown;\n readonly familyInstance: ControlFamilyInstance<TFamilyId, unknown>;\n readonly migrations: TargetMigrationsCapability<\n TFamilyId,\n TTargetId,\n ControlFamilyInstance<TFamilyId, unknown>\n >;\n readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, TTargetId>>;\n readonly operationPolicy: MigrationOperationPolicy;\n}\n\nexport type SynthStrategyOutcome =\n | { readonly kind: 'ok'; readonly result: AggregatePerSpacePlan }\n | { readonly kind: 'failure'; readonly conflicts: readonly MigrationPlannerConflict[] };\n\n/**\n * The {@link MigrationPlanner.plan} interface is declared as synchronous,\n * but historical and test fixture call sites have always invoked it\n * with `await` (see prior `db-apply-per-space.ts`). Tolerating a\n * Promise here keeps existing test mocks working without changing the\n * declared family SPI.\n */\ntype MaybeAsyncPlannerResult = MigrationPlannerResult | Promise<MigrationPlannerResult>;\n\n/**\n * Synthesise a migration plan for a single member by projecting the\n * live schema down to that member's claimed slice and delegating to\n * the family's `createPlanner(...).plan(...)`.\n *\n * Pre-projection (via {@link projectSchemaToSpace}) closes the F23\n * concern: without it, the family's planner sees other members'\n * tables as \"extras\" and emits destructive ops to drop them. With it,\n * the planner only sees the slice this member claims.\n *\n * The synthesised plan's `targetId` is set from `aggregateTargetId`\n * (the aggregate's ambient target). The family's planner does not\n * stamp `targetId` on the produced plan; the aggregate planner is\n * the single point that knows the target.\n *\n * Used by:\n *\n * - The app member by default (CLI policy\n * `ignoreGraphFor: { app.spaceId }`).\n * - Any extension member whose `headRef.invariants` is empty (the\n * strategy selector falls back to synth when graph-walk isn't\n * required).\n */\nexport async function synthStrategy<TFamilyId extends string, TTargetId extends string>(\n input: SynthStrategyInputs<TFamilyId, TTargetId>,\n): Promise<SynthStrategyOutcome> {\n const projectedSchema = projectSchemaToSpace(\n input.schemaIntrospection,\n input.member,\n input.otherMembers,\n );\n\n const planner = input.migrations.createPlanner(input.familyInstance);\n const plannerResult: MigrationPlannerResult = await (planner.plan({\n contract: input.member.contract,\n schema: projectedSchema,\n policy: input.operationPolicy,\n fromContract: null,\n frameworkComponents: input.frameworkComponents,\n spaceId: input.member.spaceId,\n }) as MaybeAsyncPlannerResult);\n\n if (plannerResult.kind === 'failure') {\n return { kind: 'failure', conflicts: plannerResult.conflicts };\n }\n\n const synthedPlan = plannerResult.plan;\n // The family planner returns a class-instance-shaped plan whose\n // `destination` / `operations` are accessors on the prototype, often\n // backed by private fields. A naive spread (`{ ...synthedPlan }`)\n // would lose those accessors and produce a plan with\n // `destination: undefined`; rebinding the prototype on a plain\n // object would break private-field access. We instead wrap the plan\n // in a Proxy that forwards every read except `targetId`, which is\n // stamped from the aggregate's ambient target. This preserves the\n // planner's class semantics while keeping the aggregate the single\n // source of truth for `targetId`.\n const plan: MigrationPlan = new Proxy(synthedPlan, {\n get(target, prop) {\n if (prop === 'targetId') return input.aggregateTargetId;\n // Forward `this` as the original target so prototype-bound\n // private fields (#destination, #operations, …) resolve.\n return Reflect.get(target, prop, target);\n },\n has(target, prop) {\n if (prop === 'targetId') return true;\n return Reflect.has(target, prop);\n },\n });\n\n return {\n kind: 'ok',\n result: {\n plan,\n displayOps: synthedPlan.operations,\n destinationContract: input.member.contract as Contract,\n strategy: 'synth',\n },\n };\n}\n","import { notOk, ok } from '@prisma-next/utils/result';\nimport type {\n AggregatePerSpacePlan,\n AggregatePlannerError,\n AggregatePlannerInput,\n AggregatePlannerOutput,\n} from './planner-types';\nimport { graphWalkStrategy } from './strategies/graph-walk';\nimport { synthStrategy } from './strategies/synth';\nimport type { ContractSpaceMember } from './types';\n\nexport type {\n AggregateCurrentDBState,\n AggregatePerSpacePlan,\n AggregatePlannerError,\n AggregatePlannerInput,\n AggregatePlannerOutput,\n AggregatePlannerSuccess,\n CallerPolicy,\n} from './planner-types';\n\n/**\n * Plan a migration across every member of a {@link ContractSpaceAggregate}.\n *\n * Strategy selection per member, in order; first match wins:\n *\n * 1. If `callerPolicy.ignoreGraphFor.has(member.spaceId)`:\n * - If `member.headRef.invariants` is empty → synth.\n * - Else → `policyConflict` (synth cannot satisfy authored invariants).\n * 2. Else if `member.migrations.graph` is non-empty AND graph-walk\n * succeeds → graph-walk.\n * 3. Else if `member.headRef.invariants` is empty → synth.\n * 4. Else → graph-walk failure → `extensionPathUnreachable` /\n * `extensionPathUnsatisfiable`.\n *\n * Output `applyOrder` is `[...aggregate.extensions.map(spaceId), aggregate.app.spaceId]`\n * — extensions alphabetical, then app — matching today's\n * `concatenateSpaceApplyInputs` ordering. This preserves\n * `MultiSpaceRunnerFailure.failingSpace` attribution byte-for-byte.\n *\n * Every emitted `MigrationPlan` has `targetId = aggregate.targetId`.\n * No placeholder cast; no patch step.\n */\nexport async function planAggregate<TFamilyId extends string, TTargetId extends string>(\n input: AggregatePlannerInput<TFamilyId, TTargetId>,\n): Promise<AggregatePlannerOutput> {\n const { aggregate, currentDBState, callerPolicy } = input;\n const allMembers: ReadonlyArray<ContractSpaceMember> = [aggregate.app, ...aggregate.extensions];\n\n const perSpace = new Map<string, AggregatePerSpacePlan>();\n\n // Iterate in apply order so a per-member error short-circuits the\n // walk in the same order the runner would walk inputs.\n const orderedMembers: ReadonlyArray<ContractSpaceMember> = [\n ...aggregate.extensions,\n aggregate.app,\n ];\n\n for (const member of orderedMembers) {\n const otherMembers = allMembers.filter((m) => m.spaceId !== member.spaceId);\n const currentMarker = currentDBState.markersBySpaceId.get(member.spaceId) ?? null;\n\n const ignoreGraph = callerPolicy.ignoreGraphFor.has(member.spaceId);\n const invariantsRequired = member.headRef.invariants.length > 0;\n\n if (ignoreGraph && invariantsRequired) {\n const conflict: AggregatePlannerError = {\n kind: 'policyConflict',\n spaceId: member.spaceId,\n detail: `\\`callerPolicy.ignoreGraphFor\\` requested for space \"${member.spaceId}\", but the member declares non-empty head-ref invariants (${member.headRef.invariants.join(', ')}). Synthesising a plan from the contract IR cannot satisfy authored invariants — the graph must be walked. Either remove \"${member.spaceId}\" from \\`ignoreGraphFor\\` or amend the on-disk head ref to declare zero invariants.`,\n };\n return notOk(conflict);\n }\n\n if (ignoreGraph) {\n const synthOutcome = await synthStrategy({\n aggregateTargetId: aggregate.targetId,\n member,\n otherMembers,\n schemaIntrospection: currentDBState.schemaIntrospection,\n familyInstance: input.familyInstance,\n migrations: input.migrations,\n frameworkComponents: input.frameworkComponents,\n operationPolicy: input.operationPolicy,\n });\n if (synthOutcome.kind === 'failure') {\n return notOk({\n kind: 'appSynthFailure',\n spaceId: member.spaceId,\n conflicts: synthOutcome.conflicts,\n });\n }\n perSpace.set(member.spaceId, synthOutcome.result);\n continue;\n }\n\n // Try graph-walk first when the graph has nodes; fall back to synth\n // when the graph is empty AND no invariants are required.\n if (member.migrations.graph.nodes.size > 0) {\n const walked = graphWalkStrategy({\n aggregateTargetId: aggregate.targetId,\n member,\n currentMarker,\n });\n if (walked.kind === 'ok') {\n perSpace.set(member.spaceId, walked.result);\n continue;\n }\n if (walked.kind === 'unreachable') {\n return notOk({\n kind: 'extensionPathUnreachable',\n spaceId: member.spaceId,\n target: member.headRef.hash,\n });\n }\n // unsatisfiable — surface\n return notOk({\n kind: 'extensionPathUnsatisfiable',\n spaceId: member.spaceId,\n missingInvariants: walked.missing,\n });\n }\n\n // Empty graph: synth is the only option, and it can only satisfy\n // empty-invariant members.\n if (invariantsRequired) {\n return notOk({\n kind: 'extensionPathUnsatisfiable',\n spaceId: member.spaceId,\n missingInvariants: [...member.headRef.invariants].sort(),\n });\n }\n\n const synthOutcome = await synthStrategy({\n aggregateTargetId: aggregate.targetId,\n member,\n otherMembers,\n schemaIntrospection: currentDBState.schemaIntrospection,\n familyInstance: input.familyInstance,\n migrations: input.migrations,\n frameworkComponents: input.frameworkComponents,\n operationPolicy: input.operationPolicy,\n });\n if (synthOutcome.kind === 'failure') {\n return notOk({\n kind: 'appSynthFailure',\n spaceId: member.spaceId,\n conflicts: synthOutcome.conflicts,\n });\n }\n perSpace.set(member.spaceId, synthOutcome.result);\n }\n\n return ok({\n perSpace,\n applyOrder: [...aggregate.extensions.map((m) => m.spaceId), aggregate.app.spaceId],\n });\n}\n","import type { Result } from '@prisma-next/utils/result';\nimport { notOk, ok } from '@prisma-next/utils/result';\nimport type { ContractMarkerRecordLike } from './marker-types';\nimport { projectSchemaToSpace } from './project-schema-to-space';\nimport type { ContractSpaceAggregate, ContractSpaceMember } from './types';\n\n/**\n * Caller policy for the aggregate verifier. Today's only knob is\n * `mode`: `strict` treats orphan elements (live tables not claimed by\n * any aggregate member) as errors; `lenient` treats them as\n * informational. Maps directly to `db verify --strict`.\n */\nexport interface AggregateVerifierInput<TSchemaResult> {\n readonly aggregate: ContractSpaceAggregate;\n readonly markersBySpaceId: ReadonlyMap<string, ContractMarkerRecordLike | null>;\n readonly schemaIntrospection: unknown;\n readonly mode: 'strict' | 'lenient';\n /**\n * Caller-supplied per-space schema verifier. The CLI wires this to\n * the family's `verifySqlSchema` (SQL) / equivalent (other\n * families). The aggregate verifier projects the schema to the\n * member's slice via {@link projectSchemaToSpace} before invoking\n * the callback, so single-contract semantics are preserved.\n *\n * Typed structurally with a generic `TSchemaResult` so the\n * migration-tools layer doesn't depend on the SQL family's\n * `VerifySqlSchemaResult`. CLI callers pass the family's type\n * through unchanged.\n */\n readonly verifySchemaForMember: (\n projectedSchema: unknown,\n member: ContractSpaceMember,\n mode: 'strict' | 'lenient',\n ) => TSchemaResult;\n}\n\n/**\n * Marker-check result per member. Mirrors the four cases the\n * `verifyContractSpaces` primitive surfaces today, plus an `'absent'`\n * case for greenfield spaces (no marker row written yet — `db init`\n * not run).\n */\nexport type MarkerCheckResult =\n | { readonly kind: 'ok' }\n | { readonly kind: 'absent' }\n | {\n readonly kind: 'hashMismatch';\n readonly markerHash: string;\n readonly expected: string;\n }\n | { readonly kind: 'missingInvariants'; readonly missing: readonly string[] };\n\nexport interface MarkerCheckSection {\n readonly perSpace: ReadonlyMap<string, MarkerCheckResult>;\n readonly orphanMarkers: readonly {\n readonly spaceId: string;\n readonly row: ContractMarkerRecordLike;\n }[];\n}\n\n/**\n * A live storage element (today: a top-level table) not claimed by any\n * member of the aggregate. The aggregate verifier always reports these;\n * the caller decides what to do — `db verify --strict` treats them as\n * errors, the lenient default treats them as informational.\n *\n * Today only `kind: 'table'` exists. The discriminated shape leaves\n * room for orphan columns / indexes / sequences in the future without\n * breaking the type contract.\n */\nexport type OrphanElement = { readonly kind: 'table'; readonly name: string };\n\nexport interface SchemaCheckSection<TSchemaResult> {\n readonly perSpace: ReadonlyMap<string, TSchemaResult>;\n /**\n * Live elements present in the introspected schema that are not\n * claimed by **any** aggregate member. Sorted alphabetically by name.\n */\n readonly orphanElements: readonly OrphanElement[];\n}\n\nexport interface AggregateVerifierSuccess<TSchemaResult> {\n readonly markerCheck: MarkerCheckSection;\n readonly schemaCheck: SchemaCheckSection<TSchemaResult>;\n}\n\nexport type AggregateVerifierError = {\n readonly kind: 'introspectionFailure';\n readonly detail: string;\n};\n\nexport type AggregateVerifierOutput<TSchemaResult> = Result<\n AggregateVerifierSuccess<TSchemaResult>,\n AggregateVerifierError\n>;\n\n/**\n * Verify a {@link ContractSpaceAggregate} against the live database\n * state. Bundles two checks:\n *\n * - `markerCheck` per member: compare the live marker row against the\n * member's `headRef.hash` + `headRef.invariants`. Absence is a\n * distinct kind, not an error (callers — `db verify` strict vs\n * `db init` precondition — choose how to interpret it).\n * - `schemaCheck` per member: project the live schema to the slice\n * the member claims via {@link projectSchemaToSpace}, then delegate\n * to the caller-supplied `verifySchemaForMember`. The pre-projection\n * means the family's single-contract verifier no longer sees other\n * members' tables as `extras`, so a multi-member deployment never\n * surfaces cross-member tables as orphaned schema elements.\n *\n * `markerCheck.orphanMarkers` lists every marker row whose `space` is\n * not a member of the aggregate. `db verify` callers reject orphans;\n * future tooling may not.\n *\n * Pure synchronous function; no I/O. The caller (CLI) gathers\n * `markersBySpaceId` and `schemaIntrospection` ahead of the call.\n */\nexport function verifyAggregate<TSchemaResult>(\n input: AggregateVerifierInput<TSchemaResult>,\n): AggregateVerifierOutput<TSchemaResult> {\n try {\n return runVerifyAggregate(input);\n } catch (error) {\n return notOk({\n kind: 'introspectionFailure',\n detail: error instanceof Error ? error.message : String(error),\n });\n }\n}\n\nfunction runVerifyAggregate<TSchemaResult>(\n input: AggregateVerifierInput<TSchemaResult>,\n): AggregateVerifierOutput<TSchemaResult> {\n const { aggregate, markersBySpaceId, schemaIntrospection, mode, verifySchemaForMember } = input;\n const allMembers: ReadonlyArray<ContractSpaceMember> = [aggregate.app, ...aggregate.extensions];\n const memberSpaceIds = new Set(allMembers.map((m) => m.spaceId));\n\n // Marker check per member.\n const markerPerSpace = new Map<string, MarkerCheckResult>();\n for (const member of allMembers) {\n const marker = markersBySpaceId.get(member.spaceId) ?? null;\n if (marker === null) {\n markerPerSpace.set(member.spaceId, { kind: 'absent' });\n continue;\n }\n if (marker.storageHash !== member.headRef.hash) {\n markerPerSpace.set(member.spaceId, {\n kind: 'hashMismatch',\n markerHash: marker.storageHash,\n expected: member.headRef.hash,\n });\n continue;\n }\n const markerInvariants = new Set(marker.invariants);\n const missing = member.headRef.invariants.filter((id) => !markerInvariants.has(id));\n if (missing.length > 0) {\n markerPerSpace.set(member.spaceId, {\n kind: 'missingInvariants',\n missing: [...missing].sort(),\n });\n continue;\n }\n markerPerSpace.set(member.spaceId, { kind: 'ok' });\n }\n\n // Orphan markers: entries in markersBySpaceId whose spaceId is not a\n // member of the aggregate.\n const orphanMarkers: { spaceId: string; row: ContractMarkerRecordLike }[] = [];\n for (const [spaceId, row] of markersBySpaceId) {\n if (row !== null && !memberSpaceIds.has(spaceId)) {\n orphanMarkers.push({ spaceId, row });\n }\n }\n orphanMarkers.sort((a, b) => a.spaceId.localeCompare(b.spaceId));\n\n // Schema check per member (with per-space pre-projection).\n const schemaPerSpace = new Map<string, TSchemaResult>();\n for (const member of allMembers) {\n const others = allMembers.filter((m) => m.spaceId !== member.spaceId);\n const projected = projectSchemaToSpace(schemaIntrospection, member, others);\n schemaPerSpace.set(member.spaceId, verifySchemaForMember(projected, member, mode));\n }\n\n return ok({\n markerCheck: {\n perSpace: markerPerSpace,\n orphanMarkers,\n },\n schemaCheck: {\n perSpace: schemaPerSpace,\n orphanElements: detectOrphanElements(schemaIntrospection, allMembers),\n },\n });\n}\n\n/**\n * Live tables not claimed by any aggregate member. Duck-typed against\n * the introspected schema's `tables` map; schemas whose shape doesn't\n * match return an empty list (consistent with\n * {@link projectSchemaToSpace}'s fall-through).\n */\nfunction detectOrphanElements(\n schemaIntrospection: unknown,\n members: ReadonlyArray<ContractSpaceMember>,\n): readonly OrphanElement[] {\n if (typeof schemaIntrospection !== 'object' || schemaIntrospection === null) return [];\n const liveTables = (schemaIntrospection as { readonly tables?: unknown }).tables;\n if (typeof liveTables !== 'object' || liveTables === null) return [];\n\n const claimedTables = new Set<string>();\n for (const member of members) {\n const storage = (member.contract as { readonly storage?: unknown }).storage;\n if (typeof storage !== 'object' || storage === null) continue;\n const tables = (storage as { readonly tables?: unknown }).tables;\n if (typeof tables !== 'object' || tables === null) continue;\n for (const tableName of Object.keys(tables as Record<string, unknown>)) {\n claimedTables.add(tableName);\n }\n }\n\n const orphans: OrphanElement[] = [];\n for (const tableName of Object.keys(liveTables as Record<string, unknown>)) {\n if (!claimedTables.has(tableName)) {\n orphans.push({ kind: 'table', name: tableName });\n }\n }\n orphans.sort((a, b) => a.name.localeCompare(b.name));\n return orphans;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA4JA,eAAsB,2BACpB,OAC8B;CAE9B,MAAM,oBAAoB,MAAM,YAAY;CAC5C,IAAI,sBAAsB,MAAM,UAC9B,OAAO,MAAM;EACX,MAAM;EACN,SAAS;EACT,UAAU,MAAM;EAChB,QAAQ;EACT,CAAC;CAGJ,KAAK,MAAM,SAAS,MAAM,oBACxB,IAAI,MAAM,aAAa,MAAM,UAC3B,OAAO,MAAM;EACX,MAAM;EACN,SAAS,MAAM;EACf,UAAU,MAAM;EAChB,QAAQ,MAAM;EACf,CAAC;CAKN,MAAM,oBAAoB,MAAM,mBAAmB,QAAQ,MAAM,EAAE,kBAAkB,KAAA,EAAU;CAC/F,MAAM,mBAAmB,IAAI,IAAI,kBAAkB,KAAK,MAAM,EAAE,GAAG,CAAC;CAOpE,MAAM,uBAAsB,MANN,6BAA6B,MAAM,cAAc,EAMnC,QAAQ,MAAM,MAAM,aAAa;CACrE,MAAM,cAAc,IAAI,IAAI,oBAAoB;CAEhD,MAAM,mBAAsC,EAAE;CAC9C,KAAK,MAAM,OAAO,qBAChB,IAAI,CAAC,iBAAiB,IAAI,IAAI,EAC5B,iBAAiB,KAAK;EAAE,MAAM;EAAkB,SAAS;EAAK,CAAC;CAGnE,KAAK,MAAM,MAAM,CAAC,GAAG,iBAAiB,CAAC,MAAM,EAC3C,IAAI,CAAC,YAAY,IAAI,GAAG,EACtB,iBAAiB,KAAK;EAAE,MAAM;EAAyB,SAAS;EAAI,CAAC;CAGzE,IAAI,iBAAiB,SAAS,GAC5B,OAAO,MAAM;EAAE,MAAM;EAAmB,YAAY;EAAkB,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G;EACR,aAAa;GACX,UAAU;GACV;GACD;EACD,aAAa;GACX,UAAU;GACV,gBAAgB,qBAAqB,qBAAqB,WAAW;GACtE;EACF,CAAC;;;;;;;;AASJ,SAAS,qBACP,qBACA,SAC0B;CAC1B,IAAI,OAAO,wBAAwB,YAAY,wBAAwB,MAAM,OAAO,EAAE;CACtF,MAAM,aAAc,oBAAsD;CAC1E,IAAI,OAAO,eAAe,YAAY,eAAe,MAAM,OAAO,EAAE;CAEpE,MAAM,gCAAgB,IAAI,KAAa;CACvC,KAAK,MAAM,UAAU,SAAS;EAC5B,MAAM,UAAW,OAAO,SAA4C;EACpE,IAAI,OAAO,YAAY,YAAY,YAAY,MAAM;EACrD,MAAM,SAAU,QAA0C;EAC1D,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM;EACnD,KAAK,MAAM,aAAa,OAAO,KAAK,OAAkC,EACpE,cAAc,IAAI,UAAU;;CAIhC,MAAM,UAA2B,EAAE;CACnC,KAAK,MAAM,aAAa,OAAO,KAAK,WAAsC,EACxE,IAAI,CAAC,cAAc,IAAI,UAAU,EAC/B,QAAQ,KAAK;EAAE,MAAM;EAAS,MAAM;EAAW,CAAC;CAGpD,QAAQ,MAAM,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,KAAK,CAAC;CACpD,OAAO"}
1
+ {"version":3,"file":"aggregate.mjs","names":[],"sources":["../../src/aggregate/loader.ts","../../src/aggregate/strategies/graph-walk.ts","../../src/aggregate/project-schema-to-space.ts","../../src/aggregate/strategies/synth.ts","../../src/aggregate/planner.ts","../../src/aggregate/verifier.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { EMPTY_CONTRACT_HASH } from '../constants';\nimport { readMigrationsDir } from '../io';\nimport { reconstructGraph } from '../migration-graph';\nimport type { OnDiskMigrationPackage } from '../package';\nimport { readContractSpaceContract } from '../read-contract-space-contract';\nimport { readContractSpaceHeadRef } from '../read-contract-space-head-ref';\nimport { APP_SPACE_ID, spaceMigrationDirectory } from '../space-layout';\nimport { listContractSpaceDirectories } from '../verify-contract-spaces';\nimport type { ContractSpaceAggregate, ContractSpaceMember, HydratedMigrationGraph } from './types';\n\n/**\n * 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 validateContract: (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} / `validateContract`), 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: error instanceof Error ? error.message : String(error),\n });\n }\n\n let spaceContract: Contract;\n try {\n spaceContract = input.validateContract(spaceContractRaw);\n } catch (error) {\n return notOk({\n kind: 'validationFailure',\n spaceId: entry.id,\n detail: error instanceof Error ? error.message : String(error),\n });\n }\n\n if (spaceContract.target !== input.targetId) {\n return notOk({\n kind: 'targetMismatch',\n spaceId: entry.id,\n expected: input.targetId,\n actual: spaceContract.target,\n });\n }\n\n // Read + integrity-check the migration packages. `readMigrationsDir`\n // re-derives `providedInvariants` and verifies migrationHash for\n // every package.\n let packages: readonly OnDiskMigrationPackage[];\n try {\n packages = await readMigrationsDir(spaceMigrationDirectory(input.migrationsDir, entry.id));\n } catch (error) {\n return notOk({\n kind: 'integrityFailure',\n spaceId: entry.id,\n detail: error instanceof Error ? error.message : String(error),\n });\n }\n\n let graph: ReturnType<typeof reconstructGraph>;\n try {\n graph = reconstructGraph(packages);\n } catch (error) {\n return notOk({\n kind: 'integrityFailure',\n spaceId: entry.id,\n detail: error instanceof Error ? error.message : String(error),\n });\n }\n\n // The on-disk head ref must be reachable in the graph. Empty graphs\n // are tolerated only when the head ref points at the empty-contract\n // sentinel (a never-emitted extension space; not a typical scenario\n // because the layout precheck would have flagged the missing\n // dir, but defensible).\n if (graph.nodes.size === 0) {\n if (headRef.hash !== EMPTY_CONTRACT_HASH) {\n return notOk({\n kind: 'integrityFailure',\n spaceId: entry.id,\n detail: `Head ref \"${headRef.hash}\" is not present in the (empty) on-disk migration graph.`,\n });\n }\n } else if (!graph.nodes.has(headRef.hash)) {\n return notOk({\n kind: 'integrityFailure',\n spaceId: entry.id,\n detail: `Head ref \"${headRef.hash}\" is not present in the on-disk migration graph.`,\n });\n }\n\n const packagesByMigrationHash = new Map<string, OnDiskMigrationPackage>(\n packages.map((p) => [p.metadata.migrationHash, p]),\n );\n\n loadedExtensions.push({\n entry,\n contract: spaceContract,\n headRefHash: headRef.hash,\n headRefInvariants: [...headRef.invariants].sort(),\n migrations: { graph, packagesByMigrationHash },\n });\n }\n\n // 6. Build app member with hydrated graph from caller-supplied packages.\n let appGraph: ReturnType<typeof reconstructGraph>;\n try {\n appGraph = reconstructGraph(input.appMigrationPackages);\n } catch (error) {\n return notOk({\n kind: 'integrityFailure',\n spaceId: APP_SPACE_ID,\n detail: error instanceof Error ? error.message : String(error),\n });\n }\n const appPackagesByMigrationHash = new Map<string, OnDiskMigrationPackage>(\n input.appMigrationPackages.map((p) => [p.metadata.migrationHash, p]),\n );\n\n const appMember: ContractSpaceMember = {\n spaceId: APP_SPACE_ID,\n contract: input.appContract,\n headRef: {\n hash: input.appContract.storage.storageHash,\n invariants: [],\n },\n migrations: {\n graph: appGraph,\n packagesByMigrationHash: appPackagesByMigrationHash,\n },\n };\n\n const extensionMembers: ContractSpaceMember[] = loadedExtensions.map((s) => ({\n spaceId: s.entry.id,\n contract: s.contract,\n headRef: {\n hash: s.headRefHash,\n invariants: s.headRefInvariants,\n },\n migrations: s.migrations,\n }));\n\n // 7. Disjointness: no two members claim the same storage element.\n const elementClaimedBy = new Map<string, string[]>();\n for (const member of [appMember, ...extensionMembers]) {\n const tables = extractTableNames(member.contract);\n for (const tableName of tables) {\n const claimers = elementClaimedBy.get(tableName);\n if (claimers) claimers.push(member.spaceId);\n else elementClaimedBy.set(tableName, [member.spaceId]);\n }\n }\n for (const [element, claimedBy] of elementClaimedBy) {\n if (claimedBy.length > 1) {\n return notOk({\n kind: 'disjointnessViolation',\n element,\n claimedBy: [...claimedBy].sort(),\n });\n }\n }\n\n return ok({\n aggregate: {\n targetId: input.targetId,\n app: appMember,\n extensions: extensionMembers,\n },\n });\n}\n\n/**\n * Extract the set of top-level storage table names from a contract.\n * Duck-typed: returns `[]` if the contract's storage shape doesn't\n * match the canonical `storage.tables: Record<string, ...>` form. A\n * future family with a different storage shape gets disjointness\n * effectively disabled (not enforced) rather than a hard failure.\n */\nfunction extractTableNames(contract: Contract): readonly string[] {\n const storage = (contract as { readonly storage?: unknown }).storage;\n if (typeof storage !== 'object' || storage === null) return [];\n const tables = (storage as { readonly tables?: unknown }).tables;\n if (typeof tables !== 'object' || tables === null) return [];\n return Object.keys(tables as Record<string, unknown>);\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport type { MigrationPlan } from '@prisma-next/framework-components/control';\nimport { EMPTY_CONTRACT_HASH } from '../../constants';\nimport { findPathWithDecision } from '../../migration-graph';\nimport type { MigrationOps } from '../../package';\nimport type { ContractMarkerRecordLike } from '../marker-types';\nimport type { AggregatePerSpacePlan } from '../planner-types';\nimport type { ContractSpaceMember } from '../types';\n\n/**\n * Outcome variants for the graph-walk strategy. Mirrors\n * {@link import('../../compute-extension-space-apply-path').ExtensionSpaceApplyPathOutcome}\n * but operates against the **already-hydrated** `member.migrations.graph`\n * instead of re-reading from disk. The aggregate planner converts\n * these into {@link import('../planner-types').AggregatePlannerError}\n * variants.\n */\nexport type GraphWalkOutcome =\n | { readonly kind: 'ok'; readonly result: AggregatePerSpacePlan }\n | { readonly kind: 'unreachable' }\n | { readonly kind: 'unsatisfiable'; readonly missing: readonly string[] };\n\nexport interface GraphWalkStrategyInputs {\n readonly aggregateTargetId: string;\n readonly member: ContractSpaceMember;\n readonly currentMarker: ContractMarkerRecordLike | null;\n /**\n * Optional ref name to decorate the resulting `PathDecision`. Used by\n * `migration apply` to surface the user-supplied `--ref <name>` in\n * structured-progress events and invariant-path error envelopes. The\n * strategy itself does not interpret it.\n */\n readonly refName?: string;\n}\n\n/**\n * Walk a member's hydrated migration graph from the live marker to\n * `member.headRef.hash`, covering every required invariant.\n *\n * Pure synchronous function — no I/O. The aggregate's loader has\n * already integrity-checked every package and reconstructed the graph;\n * this strategy just looks up ops by `migrationHash` and assembles a\n * `MigrationPlan` with `targetId` set from the aggregate (no\n * placeholder cast).\n *\n * Required invariants are computed as `headRef.invariants \\ marker.invariants`\n * — the marker already declares some invariants satisfied; the path\n * only needs to provide the remainder. Mirrors today's\n * `computeExtensionSpaceApplyPath` semantics.\n */\nexport function graphWalkStrategy(input: GraphWalkStrategyInputs): GraphWalkOutcome {\n const { aggregateTargetId, member, currentMarker, refName } = input;\n const { graph, packagesByMigrationHash } = member.migrations;\n\n const fromHash = currentMarker?.storageHash ?? EMPTY_CONTRACT_HASH;\n const markerInvariants = new Set(currentMarker?.invariants ?? []);\n const required = new Set(member.headRef.invariants.filter((id) => !markerInvariants.has(id)));\n\n const outcome = findPathWithDecision(graph, fromHash, member.headRef.hash, {\n required,\n ...(refName !== undefined ? { refName } : {}),\n });\n\n if (outcome.kind === 'unreachable') {\n return { kind: 'unreachable' };\n }\n if (outcome.kind === 'unsatisfiable') {\n return { kind: 'unsatisfiable', missing: outcome.missing };\n }\n\n const pathOps: MigrationOps[number][] = [];\n const providedInvariantsSet = new Set<string>();\n const edgeRefs: Array<{\n migrationHash: string;\n dirName: string;\n from: string;\n to: string;\n operationCount: number;\n }> = [];\n for (const edge of outcome.decision.selectedPath) {\n const pkg = packagesByMigrationHash.get(edge.migrationHash);\n if (!pkg) {\n throw new Error(\n `Migration package missing for edge ${edge.migrationHash} in space \"${member.spaceId}\". The hydrated migration graph and packagesByMigrationHash map are out of sync — this should be unreachable; report.`,\n );\n }\n for (const op of pkg.ops) pathOps.push(op);\n for (const invariant of pkg.metadata.providedInvariants) providedInvariantsSet.add(invariant);\n edgeRefs.push({\n migrationHash: edge.migrationHash,\n dirName: edge.dirName,\n from: edge.from,\n to: edge.to,\n operationCount: pkg.ops.length,\n });\n }\n\n const plan: MigrationPlan = {\n targetId: aggregateTargetId,\n spaceId: member.spaceId,\n origin: currentMarker === null ? null : { storageHash: currentMarker.storageHash },\n destination: { storageHash: member.headRef.hash },\n operations: pathOps,\n providedInvariants: [...providedInvariantsSet].sort(),\n };\n\n return {\n kind: 'ok',\n result: {\n plan,\n displayOps: pathOps,\n destinationContract: member.contract as Contract,\n strategy: 'graph-walk',\n migrationEdges: edgeRefs,\n pathDecision: outcome.decision,\n },\n };\n}\n","import type { ContractSpaceMember } from './types';\n\n/**\n * Project the introspected live schema to the slice claimed by a single\n * contract-space member.\n *\n * Returns the same `schema` value with every top-level table claimed by\n * **other** members of the aggregate removed. Tables not claimed by any\n * member flow through unchanged — the planner / verifier sees them as\n * orphans (extras in strict mode).\n *\n * Used by:\n *\n * - The aggregate planner's **synth strategy**: when synthesising a\n * plan against a member's contract, the live schema must be projected\n * to that member's slice so the planner doesn't treat tables claimed\n * by other members as \"extras\" and emit destructive ops to drop\n * them.\n * - The aggregate verifier's **schemaCheck**: projects per member so the\n * single-contract `verifySqlSchema` only sees the slice claimed by\n * the member it is checking. Closes the F23 architectural concern\n * (multi-member deployments where each member's tables look like\n * extras to every other member's verify pass).\n *\n * **Duck-typing semantics**: the helper operates on `unknown` for the\n * schema and falls through structurally if the shape doesn't match.\n * Every family today exposes `storage.tables: Record<string, ...>` and\n * the introspected schema mirrors the same shape; a future family with\n * a different storage shape gets the schema returned unchanged rather\n * than blowing up the aggregate planner.\n */\nexport function projectSchemaToSpace(\n schema: unknown,\n member: ContractSpaceMember,\n otherMembers: ReadonlyArray<ContractSpaceMember>,\n): unknown {\n if (typeof schema !== 'object' || schema === null) return schema;\n const schemaObj = schema as { readonly tables?: unknown };\n if (typeof schemaObj.tables !== 'object' || schemaObj.tables === null) return schema;\n const schemaTables = schemaObj.tables as Record<string, unknown>;\n\n const ownedByOthers = new Set<string>();\n for (const other of otherMembers) {\n if (other.spaceId === member.spaceId) continue;\n const storage = (other.contract as { readonly storage?: unknown }).storage;\n if (typeof storage !== 'object' || storage === null) continue;\n const tables = (storage as { readonly tables?: unknown }).tables;\n if (typeof tables !== 'object' || tables === null) continue;\n for (const tableName of Object.keys(tables as Record<string, unknown>)) {\n ownedByOthers.add(tableName);\n }\n }\n\n if (ownedByOthers.size === 0) return schema;\n\n const prunedTables: Record<string, unknown> = {};\n for (const [name, table] of Object.entries(schemaTables)) {\n if (!ownedByOthers.has(name)) {\n prunedTables[name] = table;\n }\n }\n\n return { ...schemaObj, tables: prunedTables };\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';\nimport type {\n ControlFamilyInstance,\n MigrationOperationPolicy,\n MigrationPlan,\n MigrationPlannerConflict,\n MigrationPlannerResult,\n TargetMigrationsCapability,\n} from '@prisma-next/framework-components/control';\nimport type { AggregatePerSpacePlan } from '../planner-types';\nimport { projectSchemaToSpace } from '../project-schema-to-space';\nimport type { ContractSpaceMember } from '../types';\n\nexport interface SynthStrategyInputs<TFamilyId extends string, TTargetId extends string> {\n readonly aggregateTargetId: string;\n readonly member: ContractSpaceMember;\n readonly otherMembers: ReadonlyArray<ContractSpaceMember>;\n readonly schemaIntrospection: unknown;\n readonly familyInstance: ControlFamilyInstance<TFamilyId, unknown>;\n readonly migrations: TargetMigrationsCapability<\n TFamilyId,\n TTargetId,\n ControlFamilyInstance<TFamilyId, unknown>\n >;\n readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, TTargetId>>;\n readonly operationPolicy: MigrationOperationPolicy;\n}\n\nexport type SynthStrategyOutcome =\n | { readonly kind: 'ok'; readonly result: AggregatePerSpacePlan }\n | { readonly kind: 'failure'; readonly conflicts: readonly MigrationPlannerConflict[] };\n\n/**\n * The {@link MigrationPlanner.plan} interface is declared as synchronous,\n * but historical and test fixture call sites have always invoked it\n * with `await` (see prior `db-apply-per-space.ts`). Tolerating a\n * Promise here keeps existing test mocks working without changing the\n * declared family SPI.\n */\ntype MaybeAsyncPlannerResult = MigrationPlannerResult | Promise<MigrationPlannerResult>;\n\n/**\n * Synthesise a migration plan for a single member by projecting the\n * live schema down to that member's claimed slice and delegating to\n * the family's `createPlanner(...).plan(...)`.\n *\n * Pre-projection (via {@link projectSchemaToSpace}) closes the F23\n * concern: without it, the family's planner sees other members'\n * tables as \"extras\" and emits destructive ops to drop them. With it,\n * the planner only sees the slice this member claims.\n *\n * The synthesised plan's `targetId` is set from `aggregateTargetId`\n * (the aggregate's ambient target). The family's planner does not\n * stamp `targetId` on the produced plan; the aggregate planner is\n * the single point that knows the target.\n *\n * Used by:\n *\n * - The app member by default (CLI policy\n * `ignoreGraphFor: { app.spaceId }`).\n * - Any extension member whose `headRef.invariants` is empty (the\n * strategy selector falls back to synth when graph-walk isn't\n * required).\n */\nexport async function synthStrategy<TFamilyId extends string, TTargetId extends string>(\n input: SynthStrategyInputs<TFamilyId, TTargetId>,\n): Promise<SynthStrategyOutcome> {\n const projectedSchema = projectSchemaToSpace(\n input.schemaIntrospection,\n input.member,\n input.otherMembers,\n );\n\n const planner = input.migrations.createPlanner(input.familyInstance);\n const plannerResult: MigrationPlannerResult = await (planner.plan({\n contract: input.member.contract,\n schema: projectedSchema,\n policy: input.operationPolicy,\n fromContract: null,\n frameworkComponents: input.frameworkComponents,\n spaceId: input.member.spaceId,\n }) as MaybeAsyncPlannerResult);\n\n if (plannerResult.kind === 'failure') {\n return { kind: 'failure', conflicts: plannerResult.conflicts };\n }\n\n const synthedPlan = plannerResult.plan;\n // The family planner returns a class-instance-shaped plan whose\n // `destination` / `operations` are accessors on the prototype, often\n // backed by private fields. A naive spread (`{ ...synthedPlan }`)\n // would lose those accessors and produce a plan with\n // `destination: undefined`; rebinding the prototype on a plain\n // object would break private-field access. We instead wrap the plan\n // in a Proxy that forwards every read except `targetId`, which is\n // stamped from the aggregate's ambient target. This preserves the\n // planner's class semantics while keeping the aggregate the single\n // source of truth for `targetId`.\n const plan: MigrationPlan = new Proxy(synthedPlan, {\n get(target, prop) {\n if (prop === 'targetId') return input.aggregateTargetId;\n // Forward `this` as the original target so prototype-bound\n // private fields (#destination, #operations, …) resolve.\n return Reflect.get(target, prop, target);\n },\n has(target, prop) {\n if (prop === 'targetId') return true;\n return Reflect.has(target, prop);\n },\n });\n\n return {\n kind: 'ok',\n result: {\n plan,\n displayOps: synthedPlan.operations,\n destinationContract: input.member.contract as Contract,\n strategy: 'synth',\n },\n };\n}\n","import { notOk, ok } from '@prisma-next/utils/result';\nimport type {\n AggregatePerSpacePlan,\n AggregatePlannerError,\n AggregatePlannerInput,\n AggregatePlannerOutput,\n} from './planner-types';\nimport { graphWalkStrategy } from './strategies/graph-walk';\nimport { synthStrategy } from './strategies/synth';\nimport type { ContractSpaceMember } from './types';\n\nexport type {\n AggregateCurrentDBState,\n 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 type { ContractMarkerRecordLike } from './marker-types';\nimport { projectSchemaToSpace } from './project-schema-to-space';\nimport type { ContractSpaceAggregate, ContractSpaceMember } from './types';\n\n/**\n * Caller policy for the aggregate verifier. Today's only knob is\n * `mode`: `strict` treats orphan elements (live tables not claimed by\n * any aggregate member) as errors; `lenient` treats them as\n * informational. Maps directly to `db verify --strict`.\n */\nexport interface AggregateVerifierInput<TSchemaResult> {\n readonly aggregate: ContractSpaceAggregate;\n readonly markersBySpaceId: ReadonlyMap<string, ContractMarkerRecordLike | null>;\n readonly schemaIntrospection: unknown;\n readonly mode: 'strict' | 'lenient';\n /**\n * Caller-supplied per-space schema verifier. The CLI wires this to\n * the family's `verifySqlSchema` (SQL) / equivalent (other\n * families). The aggregate verifier projects the schema to the\n * member's slice via {@link projectSchemaToSpace} before invoking\n * the callback, so single-contract semantics are preserved.\n *\n * Typed structurally with a generic `TSchemaResult` so the\n * migration-tools layer doesn't depend on the SQL family's\n * `VerifySqlSchemaResult`. CLI callers pass the family's type\n * through unchanged.\n */\n readonly verifySchemaForMember: (\n projectedSchema: unknown,\n member: ContractSpaceMember,\n mode: 'strict' | 'lenient',\n ) => TSchemaResult;\n}\n\n/**\n * Marker-check result per member. Mirrors the four cases the\n * `verifyContractSpaces` primitive surfaces today, plus an `'absent'`\n * case for greenfield spaces (no marker row written yet — `db init`\n * not run).\n */\nexport type MarkerCheckResult =\n | { readonly kind: 'ok' }\n | { readonly kind: 'absent' }\n | {\n readonly kind: 'hashMismatch';\n readonly markerHash: string;\n readonly expected: string;\n }\n | { readonly kind: 'missingInvariants'; readonly missing: readonly string[] };\n\nexport interface MarkerCheckSection {\n readonly perSpace: ReadonlyMap<string, MarkerCheckResult>;\n readonly orphanMarkers: readonly {\n readonly spaceId: string;\n readonly row: ContractMarkerRecordLike;\n }[];\n}\n\n/**\n * A live storage element (today: a top-level table) not claimed by any\n * member of the aggregate. The aggregate verifier always reports these;\n * the caller decides what to do — `db verify --strict` treats them as\n * errors, the lenient default treats them as informational.\n *\n * Today only `kind: 'table'` exists. The discriminated shape leaves\n * room for orphan columns / indexes / sequences in the future without\n * breaking the type contract.\n */\nexport type OrphanElement = { readonly kind: 'table'; readonly name: string };\n\nexport interface SchemaCheckSection<TSchemaResult> {\n readonly perSpace: ReadonlyMap<string, TSchemaResult>;\n /**\n * Live elements present in the introspected schema that are not\n * claimed by **any** aggregate member. Sorted alphabetically by name.\n */\n readonly orphanElements: readonly OrphanElement[];\n}\n\nexport interface AggregateVerifierSuccess<TSchemaResult> {\n readonly markerCheck: MarkerCheckSection;\n readonly schemaCheck: SchemaCheckSection<TSchemaResult>;\n}\n\nexport type AggregateVerifierError = {\n readonly kind: 'introspectionFailure';\n readonly detail: string;\n};\n\nexport type AggregateVerifierOutput<TSchemaResult> = Result<\n AggregateVerifierSuccess<TSchemaResult>,\n AggregateVerifierError\n>;\n\n/**\n * Verify a {@link ContractSpaceAggregate} against the live database\n * state. Bundles two checks:\n *\n * - `markerCheck` per member: compare the live marker row against the\n * member's `headRef.hash` + `headRef.invariants`. Absence is a\n * distinct kind, not an error (callers — `db verify` strict vs\n * `db init` precondition — choose how to interpret it).\n * - `schemaCheck` per member: project the live schema to the slice\n * the member claims via {@link projectSchemaToSpace}, then delegate\n * to the caller-supplied `verifySchemaForMember`. The pre-projection\n * means the family's single-contract verifier no longer sees other\n * members' tables as `extras`, so a multi-member deployment never\n * surfaces cross-member tables as orphaned schema elements.\n *\n * `markerCheck.orphanMarkers` lists every marker row whose `space` is\n * not a member of the aggregate. `db verify` callers reject orphans;\n * future tooling may not.\n *\n * Pure synchronous function; no I/O. The caller (CLI) gathers\n * `markersBySpaceId` and `schemaIntrospection` ahead of the call.\n */\nexport function verifyAggregate<TSchemaResult>(\n input: AggregateVerifierInput<TSchemaResult>,\n): AggregateVerifierOutput<TSchemaResult> {\n try {\n return runVerifyAggregate(input);\n } catch (error) {\n return notOk({\n kind: 'introspectionFailure',\n detail: error instanceof Error ? error.message : String(error),\n });\n }\n}\n\nfunction runVerifyAggregate<TSchemaResult>(\n input: AggregateVerifierInput<TSchemaResult>,\n): AggregateVerifierOutput<TSchemaResult> {\n const { aggregate, markersBySpaceId, schemaIntrospection, mode, verifySchemaForMember } = input;\n const allMembers: ReadonlyArray<ContractSpaceMember> = [aggregate.app, ...aggregate.extensions];\n const memberSpaceIds = new Set(allMembers.map((m) => m.spaceId));\n\n // Marker check per member.\n const markerPerSpace = new Map<string, MarkerCheckResult>();\n for (const member of allMembers) {\n const marker = markersBySpaceId.get(member.spaceId) ?? null;\n if (marker === null) {\n markerPerSpace.set(member.spaceId, { kind: 'absent' });\n continue;\n }\n if (marker.storageHash !== member.headRef.hash) {\n markerPerSpace.set(member.spaceId, {\n kind: 'hashMismatch',\n markerHash: marker.storageHash,\n expected: member.headRef.hash,\n });\n continue;\n }\n const markerInvariants = new Set(marker.invariants);\n const missing = member.headRef.invariants.filter((id) => !markerInvariants.has(id));\n if (missing.length > 0) {\n markerPerSpace.set(member.spaceId, {\n kind: 'missingInvariants',\n missing: [...missing].sort(),\n });\n continue;\n }\n markerPerSpace.set(member.spaceId, { kind: 'ok' });\n }\n\n // Orphan markers: entries in markersBySpaceId whose spaceId is not a\n // member of the aggregate.\n const orphanMarkers: { spaceId: string; row: ContractMarkerRecordLike }[] = [];\n for (const [spaceId, row] of markersBySpaceId) {\n if (row !== null && !memberSpaceIds.has(spaceId)) {\n orphanMarkers.push({ spaceId, row });\n }\n }\n orphanMarkers.sort((a, b) => a.spaceId.localeCompare(b.spaceId));\n\n // Schema check per member (with per-space pre-projection).\n const schemaPerSpace = new Map<string, TSchemaResult>();\n for (const member of allMembers) {\n const others = allMembers.filter((m) => m.spaceId !== member.spaceId);\n const projected = projectSchemaToSpace(schemaIntrospection, member, others);\n schemaPerSpace.set(member.spaceId, verifySchemaForMember(projected, member, mode));\n }\n\n return ok({\n markerCheck: {\n perSpace: markerPerSpace,\n orphanMarkers,\n },\n schemaCheck: {\n perSpace: schemaPerSpace,\n orphanElements: detectOrphanElements(schemaIntrospection, allMembers),\n },\n });\n}\n\n/**\n * Live tables not claimed by any aggregate member. Duck-typed against\n * the introspected schema's `tables` map; schemas whose shape doesn't\n * match return an empty list (consistent with\n * {@link projectSchemaToSpace}'s fall-through).\n */\nfunction detectOrphanElements(\n schemaIntrospection: unknown,\n members: ReadonlyArray<ContractSpaceMember>,\n): readonly OrphanElement[] {\n if (typeof schemaIntrospection !== 'object' || schemaIntrospection === null) return [];\n const liveTables = (schemaIntrospection as { readonly tables?: unknown }).tables;\n if (typeof liveTables !== 'object' || liveTables === null) return [];\n\n const claimedTables = new Set<string>();\n for (const member of members) {\n const storage = (member.contract as { readonly storage?: unknown }).storage;\n if (typeof storage !== 'object' || storage === null) continue;\n const tables = (storage as { readonly tables?: unknown }).tables;\n if (typeof tables !== 'object' || tables === null) continue;\n for (const tableName of Object.keys(tables as Record<string, unknown>)) {\n claimedTables.add(tableName);\n }\n }\n\n const orphans: OrphanElement[] = [];\n for (const tableName of Object.keys(liveTables as Record<string, unknown>)) {\n if (!claimedTables.has(tableName)) {\n orphans.push({ kind: 'table', name: tableName });\n }\n }\n orphans.sort((a, b) => a.name.localeCompare(b.name));\n return orphans;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0IA,eAAsB,2BACpB,OAC8B;CAE9B,MAAM,oBAAoB,MAAM,YAAY;CAC5C,IAAI,sBAAsB,MAAM,UAC9B,OAAO,MAAM;EACX,MAAM;EACN,SAAS;EACT,UAAU,MAAM;EAChB,QAAQ;EACT,CAAC;CAGJ,KAAK,MAAM,SAAS,MAAM,oBACxB,IAAI,MAAM,aAAa,MAAM,UAC3B,OAAO,MAAM;EACX,MAAM;EACN,SAAS,MAAM;EACf,UAAU,MAAM;EAChB,QAAQ,MAAM;EACf,CAAC;CAYN,MAAM,mBAAmB,IAAI,IAAI,MAAM,mBAAmB,KAAK,MAAM,EAAE,GAAG,CAAC;CAO3E,MAAM,uBAAsB,MANN,6BAA6B,MAAM,cAAc,EAMnC,QAAQ,MAAM,MAAM,aAAa;CACrE,MAAM,cAAc,IAAI,IAAI,oBAAoB;CAEhD,MAAM,mBAAsC,EAAE;CAC9C,KAAK,MAAM,OAAO,qBAChB,IAAI,CAAC,iBAAiB,IAAI,IAAI,EAC5B,iBAAiB,KAAK;EAAE,MAAM;EAAkB,SAAS;EAAK,CAAC;CAGnE,KAAK,MAAM,MAAM,CAAC,GAAG,iBAAiB,CAAC,MAAM,EAC3C,IAAI,CAAC,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,SAAS,qBACP,qBACA,SAC0B;CAC1B,IAAI,OAAO,wBAAwB,YAAY,wBAAwB,MAAM,OAAO,EAAE;CACtF,MAAM,aAAc,oBAAsD;CAC1E,IAAI,OAAO,eAAe,YAAY,eAAe,MAAM,OAAO,EAAE;CAEpE,MAAM,gCAAgB,IAAI,KAAa;CACvC,KAAK,MAAM,UAAU,SAAS;EAC5B,MAAM,UAAW,OAAO,SAA4C;EACpE,IAAI,OAAO,YAAY,YAAY,YAAY,MAAM;EACrD,MAAM,SAAU,QAA0C;EAC1D,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM;EACnD,KAAK,MAAM,aAAa,OAAO,KAAK,OAAkC,EACpE,cAAc,IAAI,UAAU;;CAIhC,MAAM,UAA2B,EAAE;CACnC,KAAK,MAAM,aAAa,OAAO,KAAK,WAAsC,EACxE,IAAI,CAAC,cAAc,IAAI,UAAU,EAC/B,QAAQ,KAAK;EAAE,MAAM;EAAS,MAAM;EAAW,CAAC;CAGpD,QAAQ,MAAM,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,KAAK,CAAC;CACpD,OAAO"}
@@ -212,71 +212,6 @@ declare function contractSpaceFromJson<TContract extends Contract = Contract>(in
212
212
  readonly headRef: ContractSpaceHeadRef$1;
213
213
  }): ContractSpace<TContract>;
214
214
  //#endregion
215
- //#region src/detect-space-contract-drift.d.ts
216
- /**
217
- * Inputs for {@link detectSpaceContractDrift}.
218
- *
219
- * Both hashes are produced by the caller (the SQL-family wiring at the
220
- * consumption site) using the canonical contract hashing pipeline.
221
- * Keeping the helper pure lets `migration-tools` stay framework-neutral
222
- * — the SQL family already speaks `Contract<SqlStorage>`, the Mongo
223
- * family speaks its own contract type, and both reduce to a hash string
224
- * before drift detection runs.
225
- *
226
- * `priorHeadHash` is `null` when no `contract.json` exists yet on disk for
227
- * the space (the descriptor declares an extension that has never been
228
- * emitted into the user's repo). That's the "first emit" case — no
229
- * drift to surface; the migrate emit will create the on-disk artefacts.
230
- */
231
- interface DetectSpaceContractDriftInputs {
232
- readonly descriptorHash: string;
233
- readonly priorHeadHash: string | null;
234
- }
235
- /**
236
- * Result discriminant for {@link detectSpaceContractDrift}.
237
- *
238
- * - `noDrift`: descriptor hash and on-disk head hash agree byte-for-byte.
239
- * The migrate emit can proceed with no warning.
240
- * - `firstEmit`: no on-disk `contract.json` on disk yet. The extension
241
- * was just added to `extensionPacks`; this run will create the
242
- * on-disk artefacts. No warning either — the user's intent is to install
243
- * the extension, not to "drift" from a state they haven't recorded.
244
- * - `drift`: descriptor hash differs from on-disk head hash. The caller
245
- * surfaces a non-fatal warning naming the extension and the
246
- * diff direction (descriptor → on-disk head). The migrate emit proceeds
247
- * normally so the bump is materialised this run; the warning just
248
- * confirms the bump is being captured.
249
- *
250
- * `spaceId`, `descriptorHash`, and `priorHeadHash` are threaded through
251
- * verbatim so the caller (logger / TerminalUI / strict-mode envelope)
252
- * has everything it needs to format the warning message without
253
- * re-reading the descriptor or the on-disk artefact.
254
- */
255
- type SpaceContractDriftResult = {
256
- readonly kind: 'noDrift' | 'firstEmit' | 'drift';
257
- readonly spaceId: string;
258
- readonly descriptorHash: string;
259
- readonly priorHeadHash: string | null;
260
- };
261
- /**
262
- * Pure drift-detection primitive for a single contract space.
263
- *
264
- * Runs once per loaded extension space, just before computing the
265
- * `priorContract` that feeds {@link import('./plan-all-spaces').planAllSpaces}.
266
- * Hash equality is byte-for-byte (no normalisation) — both sides are
267
- * already canonical hashes produced by the same pipeline, so any
268
- * difference is meaningful drift.
269
- *
270
- * Synchronous, pure, no I/O. The caller (SQL family) reads the on-disk
271
- * `contract.json` and computes its hash, then invokes this helper
272
- * alongside the descriptor's `headRef.hash`. Composes naturally with
273
- * {@link import('./read-contract-space-head-ref').readContractSpaceHeadRef}
274
- * which provides the read-side primitive.
275
- *
276
- * The drift warning surfaces the extension name and the diff direction.
277
- */
278
- declare function detectSpaceContractDrift(spaceId: string, inputs: DetectSpaceContractDriftInputs): SpaceContractDriftResult;
279
- //#endregion
280
215
  //#region src/emit-contract-space-artefacts.d.ts
281
216
  /**
282
217
  * Inputs for {@link emitContractSpaceArtefacts}.
@@ -587,5 +522,5 @@ declare function assertValidSpaceId(spaceId: string): asserts spaceId is ValidSp
587
522
  */
588
523
  declare function spaceMigrationDirectory(projectMigrationsDir: string, spaceId: string): string;
589
524
  //#endregion
590
- export { APP_SPACE_ID, type ComputeExtensionSpaceApplyPathInputs, type ContractSpaceArtefactInputs, type ContractSpaceHeadRecord, type ContractSpaceHeadRef, type DescriptorSelfConsistencyInputs, type DetectSpaceContractDriftInputs, type DiskContractSpaceState, type ExtensionSpaceApplyPathOutcome, type SpaceApplyInput, type SpaceContractDriftResult, type SpaceMarkerRecord, type SpacePlanInput, type SpacePlanOutput, type SpaceVerifierViolation, type ValidSpaceId, type VerifyContractSpacesInputs, type VerifyContractSpacesResult, assertDescriptorSelfConsistency, assertValidSpaceId, computeExtensionSpaceApplyPath, contractSpaceFromJson, detectSpaceContractDrift, emitContractSpaceArtefacts, gatherDiskContractSpaceState, isValidSpaceId, listContractSpaceDirectories, planAllSpaces, readContractSpaceContract, readContractSpaceHeadRef, spaceMigrationDirectory, verifyContractSpaces };
525
+ export { APP_SPACE_ID, type ComputeExtensionSpaceApplyPathInputs, type ContractSpaceArtefactInputs, type ContractSpaceHeadRecord, type ContractSpaceHeadRef, type DescriptorSelfConsistencyInputs, type DiskContractSpaceState, type ExtensionSpaceApplyPathOutcome, type SpaceApplyInput, type SpaceMarkerRecord, type SpacePlanInput, type SpacePlanOutput, type SpaceVerifierViolation, type ValidSpaceId, type VerifyContractSpacesInputs, type VerifyContractSpacesResult, assertDescriptorSelfConsistency, assertValidSpaceId, computeExtensionSpaceApplyPath, contractSpaceFromJson, emitContractSpaceArtefacts, gatherDiskContractSpaceState, isValidSpaceId, listContractSpaceDirectories, planAllSpaces, readContractSpaceContract, readContractSpaceHeadRef, spaceMigrationDirectory, verifyContractSpaces };
591
526
  //# sourceMappingURL=spaces.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"spaces.d.mts","names":[],"sources":["../../src/assert-descriptor-self-consistency.ts","../../src/read-contract-space-head-ref.ts","../../src/compute-extension-space-apply-path.ts","../../src/concatenate-space-apply-inputs.ts","../../src/contract-space-from-json.ts","../../src/detect-space-contract-drift.ts","../../src/emit-contract-space-artefacts.ts","../../src/verify-contract-spaces.ts","../../src/gather-disk-contract-space-state.ts","../../src/plan-all-spaces.ts","../../src/read-contract-space-contract.ts","../../src/space-layout.ts"],"mappings":";;;;;;;;;;AASA;UAAiB,+BAAA;EAAA,SACN,WAAA;EAAA,SACA,MAAA;EAAA,SACA,YAAA;EADA;;;;;;AAgCX;EAhCW,SASA,OAAA;EAAA,SACA,WAAA;AAAA;;;;;ACIX;;;;;;;;;;;;;ACTA;;iBF2BgB,+BAAA,CAAgC,MAAA,EAAQ,+BAAA;;;;;;AAlCxD;;;;;;;;;;iBCgBsB,wBAAA,CACpB,oBAAA,UACA,OAAA,WACC,OAAA,CAAQ,oBAAA;;;;;;ADnBX;;;KEOY,8BAAA;EAAA,SAEG,IAAA;EAAA,SACA,oBAAA,EAAsB,oBAAA;EFP1B;;;;;EAAA,SEaI,kBAAA;EFkBgC;;;;EAAA,SEbhC,OAAA,EAAS,YAAA;;;ADLxB;;;WCWe,mBAAA;AAAA;EAAA,SAEA,IAAA;EAAA,SAA8B,oBAAA,EAAsB,oBAAA;AAAA;EAAA,SAEpD,IAAA;EAAA,SACA,oBAAA,EAAsB,oBAAA;EAAA,SACtB,OAAA;EAAA,SACA,cAAA;IAAA,SAAoC,OAAA;IAAA,SAA0B,EAAA;EAAA;AAAA;EAAA,SAE9D,IAAA;AAAA;;;;;;;;;;;;UAaE,oCAAA;EAAA,SACN,oBAAA;EAAA,SACA,OAAA;EAAA,SACA,iBAAA;EAAA,SACA,uBAAA;AAAA;;;;;;;;AAJX;;;;;;;;;;AA8BA;;;;;;iBAAsB,8BAAA,CACpB,MAAA,EAAQ,oCAAA,GACP,OAAA,CAAQ,8BA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;iBOqCgB,aAAA,qBAAA,CACd,MAAA,WAAiB,cAAA,CAAe,SAAA,KAChC,SAAA,GAAY,KAAA,EAAO,cAAA,CAAe,SAAA,eAAwB,QAAA,cAChD,eAAA,CAAgB,QAAA;;;;;;;;AT/C5B;;;;;;iBUWsB,yBAAA,CACpB,oBAAA,UACA,OAAA,WACC,OAAA;;;;;;AVdH;;;;KWIY,YAAA;EAAA,SAAmC,OAAA;AAAA;AAAA,iBAS/B,cAAA,CAAe,OAAA,WAAkB,OAAA,IAAW,YAAA;AAAA,iBAI5C,kBAAA,CAAmB,OAAA,mBAA0B,OAAA,IAAW,YAAA;;;AXiBxE;;;;;;;;AClBA;;iBUmBgB,uBAAA,CAAwB,oBAAA,UAA8B,OAAA"}
1
+ {"version":3,"file":"spaces.d.mts","names":[],"sources":["../../src/assert-descriptor-self-consistency.ts","../../src/read-contract-space-head-ref.ts","../../src/compute-extension-space-apply-path.ts","../../src/concatenate-space-apply-inputs.ts","../../src/contract-space-from-json.ts","../../src/emit-contract-space-artefacts.ts","../../src/verify-contract-spaces.ts","../../src/gather-disk-contract-space-state.ts","../../src/plan-all-spaces.ts","../../src/read-contract-space-contract.ts","../../src/space-layout.ts"],"mappings":";;;;;;;;;;AASA;UAAiB,+BAAA;EAAA,SACN,WAAA;EAAA,SACA,MAAA;EAAA,SACA,YAAA;EADA;;;;;;AAgCX;EAhCW,SASA,OAAA;EAAA,SACA,WAAA;AAAA;;;;;ACIX;;;;;;;;;;;;;ACTA;;iBF2BgB,+BAAA,CAAgC,MAAA,EAAQ,+BAAA;;;;;;AAlCxD;;;;;;;;;;iBCgBsB,wBAAA,CACpB,oBAAA,UACA,OAAA,WACC,OAAA,CAAQ,oBAAA;;;;;;ADnBX;;;KEOY,8BAAA;EAAA,SAEG,IAAA;EAAA,SACA,oBAAA,EAAsB,oBAAA;EFP1B;;;;;EAAA,SEaI,kBAAA;EFkBgC;;;;EAAA,SEbhC,OAAA,EAAS,YAAA;;;ADLxB;;;WCWe,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SAAA;EAAA,SACf,WAAA,EAAa,SAAA;AAAA;AAAA,UAGP,eAAA;EAAA,SACN,OAAA;EAAA,SACA,iBAAA,WAA4B,QAAA;AAAA;;;APEvC;;;;;;;;;;;;;ACTA;;;;;;;;;;;;iBMqCgB,aAAA,qBAAA,CACd,MAAA,WAAiB,cAAA,CAAe,SAAA,KAChC,SAAA,GAAY,KAAA,EAAO,cAAA,CAAe,SAAA,eAAwB,QAAA,cAChD,eAAA,CAAgB,QAAA;;;;;;;;AR/C5B;;;;;;iBSWsB,yBAAA,CACpB,oBAAA,UACA,OAAA,WACC,OAAA;;;;;;ATdH;;;;KUIY,YAAA;EAAA,SAAmC,OAAA;AAAA;AAAA,iBAS/B,cAAA,CAAe,OAAA,WAAkB,OAAA,IAAW,YAAA;AAAA,iBAI5C,kBAAA,CAAmB,OAAA,mBAA0B,OAAA,IAAW,YAAA;;;AViBxE;;;;;;;;AClBA;;iBSmBgB,uBAAA,CAAwB,oBAAA,UAA8B,OAAA"}
@@ -3,7 +3,7 @@ import { r as canonicalizeJson } from "../hash-By50zM_E.mjs";
3
3
  import { s as readMigrationsDir } from "../io-D5YYptRO.mjs";
4
4
  import "../constants-DWV9_o2Z.mjs";
5
5
  import { l as reconstructGraph, o as findPathWithDecision } from "../migration-graph-DGNnKDY5.mjs";
6
- import { a as readContractSpaceHeadRef, c as isValidSpaceId, i as detectSpaceContractDrift, l as spaceMigrationDirectory, n as listContractSpaceDirectories, o as APP_SPACE_ID, r as verifyContractSpaces, s as assertValidSpaceId, t as readContractSpaceContract } from "../read-contract-space-contract-Bj_EMYSC.mjs";
6
+ import { a as APP_SPACE_ID, c as spaceMigrationDirectory, i as readContractSpaceHeadRef, n as listContractSpaceDirectories, o as assertValidSpaceId, r as verifyContractSpaces, s as isValidSpaceId, t as readContractSpaceContract } from "../read-contract-space-contract-Cme8KZk_.mjs";
7
7
  import { join } from "pathe";
8
8
  import { mkdir, writeFile } from "node:fs/promises";
9
9
  import { computeStorageHash } from "@prisma-next/contract/hashing";
@@ -261,6 +261,6 @@ function planAllSpaces(inputs, planSpace) {
261
261
  }));
262
262
  }
263
263
  //#endregion
264
- export { APP_SPACE_ID, assertDescriptorSelfConsistency, assertValidSpaceId, computeExtensionSpaceApplyPath, contractSpaceFromJson, detectSpaceContractDrift, emitContractSpaceArtefacts, gatherDiskContractSpaceState, isValidSpaceId, listContractSpaceDirectories, planAllSpaces, readContractSpaceContract, readContractSpaceHeadRef, spaceMigrationDirectory, verifyContractSpaces };
264
+ export { APP_SPACE_ID, assertDescriptorSelfConsistency, assertValidSpaceId, computeExtensionSpaceApplyPath, contractSpaceFromJson, emitContractSpaceArtefacts, gatherDiskContractSpaceState, isValidSpaceId, listContractSpaceDirectories, planAllSpaces, readContractSpaceContract, readContractSpaceHeadRef, spaceMigrationDirectory, verifyContractSpaces };
265
265
 
266
266
  //# sourceMappingURL=spaces.mjs.map
@@ -76,45 +76,6 @@ async function readContractSpaceHeadRef(projectMigrationsDir, spaceId) {
76
76
  };
77
77
  }
78
78
  //#endregion
79
- //#region src/detect-space-contract-drift.ts
80
- /**
81
- * Pure drift-detection primitive for a single contract space.
82
- *
83
- * Runs once per loaded extension space, just before computing the
84
- * `priorContract` that feeds {@link import('./plan-all-spaces').planAllSpaces}.
85
- * Hash equality is byte-for-byte (no normalisation) — both sides are
86
- * already canonical hashes produced by the same pipeline, so any
87
- * difference is meaningful drift.
88
- *
89
- * Synchronous, pure, no I/O. The caller (SQL family) reads the on-disk
90
- * `contract.json` and computes its hash, then invokes this helper
91
- * alongside the descriptor's `headRef.hash`. Composes naturally with
92
- * {@link import('./read-contract-space-head-ref').readContractSpaceHeadRef}
93
- * which provides the read-side primitive.
94
- *
95
- * The drift warning surfaces the extension name and the diff direction.
96
- */
97
- function detectSpaceContractDrift(spaceId, inputs) {
98
- if (inputs.priorHeadHash === null) return {
99
- kind: "firstEmit",
100
- spaceId,
101
- descriptorHash: inputs.descriptorHash,
102
- priorHeadHash: null
103
- };
104
- if (inputs.descriptorHash === inputs.priorHeadHash) return {
105
- kind: "noDrift",
106
- spaceId,
107
- descriptorHash: inputs.descriptorHash,
108
- priorHeadHash: inputs.priorHeadHash
109
- };
110
- return {
111
- kind: "drift",
112
- spaceId,
113
- descriptorHash: inputs.descriptorHash,
114
- priorHeadHash: inputs.priorHeadHash
115
- };
116
- }
117
- //#endregion
118
79
  //#region src/verify-contract-spaces.ts
119
80
  function hasErrnoCode$1(error, code) {
120
81
  return error instanceof Error && error.code === code;
@@ -293,6 +254,6 @@ async function readContractSpaceContract(projectMigrationsDir, spaceId) {
293
254
  }
294
255
  }
295
256
  //#endregion
296
- export { readContractSpaceHeadRef as a, isValidSpaceId as c, detectSpaceContractDrift as i, spaceMigrationDirectory as l, listContractSpaceDirectories as n, APP_SPACE_ID as o, verifyContractSpaces as r, assertValidSpaceId as s, readContractSpaceContract as t };
257
+ export { APP_SPACE_ID as a, spaceMigrationDirectory as c, readContractSpaceHeadRef as i, listContractSpaceDirectories as n, assertValidSpaceId as o, verifyContractSpaces as r, isValidSpaceId as s, readContractSpaceContract as t };
297
258
 
298
- //# sourceMappingURL=read-contract-space-contract-Bj_EMYSC.mjs.map
259
+ //# sourceMappingURL=read-contract-space-contract-Cme8KZk_.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-contract-space-contract-Cme8KZk_.mjs","names":["hasErrnoCode","hasErrnoCode"],"sources":["../src/space-layout.ts","../src/read-contract-space-head-ref.ts","../src/verify-contract-spaces.ts","../src/read-contract-space-contract.ts"],"sourcesContent":["import { APP_SPACE_ID } from '@prisma-next/framework-components/control';\nimport { join } from 'pathe';\nimport { errorInvalidSpaceId } from './errors';\n\nexport { APP_SPACE_ID };\n\n/**\n * Branded string carrying a compile-time guarantee that the value has\n * been validated by {@link assertValidSpaceId}. Downstream filesystem\n * helpers (e.g. {@link spaceMigrationDirectory}) accept this type to\n * make \"validated\" tracking visible at the type level rather than\n * relying purely on a runtime check.\n */\nexport type ValidSpaceId = string & { readonly __brand: 'ValidSpaceId' };\n\n/**\n * Pattern a contract-space identifier must match. The constraint is\n * filesystem-friendly: lowercase letters / digits / hyphen / underscore,\n * starts with a letter, max 64 characters.\n */\nconst SPACE_ID_PATTERN = /^[a-z][a-z0-9_-]{0,63}$/;\n\nexport function isValidSpaceId(spaceId: string): spaceId is ValidSpaceId {\n return SPACE_ID_PATTERN.test(spaceId);\n}\n\nexport function assertValidSpaceId(spaceId: string): asserts spaceId is ValidSpaceId {\n if (!isValidSpaceId(spaceId)) {\n throw errorInvalidSpaceId(spaceId);\n }\n}\n\n/**\n * Resolve the migrations subdirectory for a given contract space.\n *\n * Every contract space — including the app space (default `'app'`) —\n * lands under `<projectMigrationsDir>/<spaceId>/`. The space id is\n * validated against {@link SPACE_ID_PATTERN} because it becomes a\n * filesystem directory name verbatim.\n *\n * `projectMigrationsDir` is the project's top-level `migrations/`\n * directory; the helper does not assume anything about its absolute /\n * relative shape and is symmetric with `pathe.join`.\n */\nexport function spaceMigrationDirectory(projectMigrationsDir: string, spaceId: string): string {\n assertValidSpaceId(spaceId);\n return join(projectMigrationsDir, spaceId);\n}\n","import { readFile } from 'node:fs/promises';\nimport type { ContractSpaceHeadRef } from '@prisma-next/framework-components/control';\nimport { join } from 'pathe';\nimport { errorInvalidJson, errorInvalidRefFile } from './errors';\nimport { assertValidSpaceId } from './space-layout';\n\nexport type { ContractSpaceHeadRef };\n\nfunction hasErrnoCode(error: unknown, code: string): boolean {\n return error instanceof Error && (error as { code?: string }).code === code;\n}\n\n/**\n * Read the head ref (`hash` + `invariants`) for a contract space from\n * `<projectMigrationsDir>/<spaceId>/refs/head.json`.\n *\n * Returns `null` when the file does not exist (first emit). Surfaces\n * `MIGRATION.INVALID_JSON` / `MIGRATION.INVALID_REF_FILE` on a corrupt\n * `refs/head.json` so callers can distinguish \"no head ref on disk\"\n * (returns `null`) from \"head ref present but unreadable\" (throws).\n *\n * Validates the space id against `[a-z][a-z0-9_-]{0,63}` for the same\n * filesystem-safety reasons as the rest of the per-space helpers. The\n * helper is uniform across the app and extension spaces.\n */\nexport async function readContractSpaceHeadRef(\n projectMigrationsDir: string,\n spaceId: string,\n): Promise<ContractSpaceHeadRef | null> {\n assertValidSpaceId(spaceId);\n\n const filePath = join(projectMigrationsDir, spaceId, 'refs', 'head.json');\n\n let raw: string;\n try {\n raw = await readFile(filePath, 'utf-8');\n } catch (error) {\n if (hasErrnoCode(error, 'ENOENT')) {\n return null;\n }\n throw error;\n }\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch (e) {\n throw errorInvalidJson(filePath, e instanceof Error ? e.message : String(e));\n }\n\n if (typeof parsed !== 'object' || parsed === null) {\n throw errorInvalidRefFile(filePath, 'expected an object');\n }\n const obj = parsed as { hash?: unknown; invariants?: unknown };\n if (typeof obj.hash !== 'string') {\n throw errorInvalidRefFile(filePath, 'expected an object with a string `hash` field');\n }\n if (!Array.isArray(obj.invariants) || obj.invariants.some((value) => typeof value !== 'string')) {\n throw errorInvalidRefFile(filePath, 'expected an object with an `invariants` array of strings');\n }\n\n return { hash: obj.hash, invariants: obj.invariants as readonly string[] };\n}\n","import { readdir, stat } from 'node:fs/promises';\nimport { join } from 'pathe';\nimport { MANIFEST_FILE } from './io';\nimport { APP_SPACE_ID } from './space-layout';\n\nfunction hasErrnoCode(error: unknown, code: string): boolean {\n return error instanceof Error && (error as { code?: string }).code === code;\n}\n\n/**\n * List the per-space subdirectories under\n * `<projectRoot>/migrations/`. Returns space-id directory names (sorted\n * alphabetically) — i.e. any non-dot-prefixed subdirectory whose root\n * does **not** contain a `migration.json` manifest. The manifest is the\n * structural marker of a user-authored migration directory (see\n * `readMigrationsDir` in `./io`); directory names themselves belong to\n * the user and are not part of the contract.\n *\n * Returns `[]` if the migrations directory does not exist (greenfield\n * project).\n *\n * Reads only the user's repo. **No descriptor import.** The caller\n * (verifier) feeds the result into {@link verifyContractSpaces} alongside\n * the loaded-space set and the marker rows.\n */\nexport async function listContractSpaceDirectories(\n projectMigrationsDir: string,\n): Promise<readonly string[]> {\n let entries: { readonly name: string; readonly isDirectory: boolean }[];\n try {\n const dirents = await readdir(projectMigrationsDir, { withFileTypes: true });\n entries = dirents.map((d) => ({ name: d.name, isDirectory: d.isDirectory() }));\n } catch (error) {\n if (hasErrnoCode(error, 'ENOENT')) {\n return [];\n }\n throw error;\n }\n\n const namedCandidates = entries\n .filter((e) => e.isDirectory)\n .map((e) => e.name)\n .filter((name) => !name.startsWith('.'))\n .sort();\n\n const manifestChecks = await Promise.all(\n namedCandidates.map(async (name) => {\n try {\n await stat(join(projectMigrationsDir, name, MANIFEST_FILE));\n return { name, isMigrationDir: true };\n } catch (error) {\n if (hasErrnoCode(error, 'ENOENT')) {\n return { name, isMigrationDir: false };\n }\n throw error;\n }\n }),\n );\n\n return manifestChecks.filter((c) => !c.isMigrationDir).map((c) => c.name);\n}\n\n/**\n * On-disk head value (`(hash, invariants)`) for one contract space.\n * The verifier compares this against the marker row for the same space\n * to detect drift between the user-emitted artefacts and the live DB\n * marker.\n */\nexport interface ContractSpaceHeadRecord {\n readonly hash: string;\n readonly invariants: readonly string[];\n}\n\n/**\n * Marker row read from `prisma_contract.marker` (one per `space`).\n * Caller resolves these via the family runtime's marker reader before\n * invoking {@link verifyContractSpaces}.\n */\nexport interface SpaceMarkerRecord {\n readonly hash: string;\n readonly invariants: readonly string[];\n}\n\nexport interface VerifyContractSpacesInputs {\n /**\n * Set of contract spaces the project declares: `'app'` plus each\n * extension space in `extensionPacks`. The caller's discovery path\n * never reads the extension descriptor module — it walks the\n * `extensionPacks` configuration in `prisma-next.config.ts` for the\n * space ids.\n */\n readonly loadedSpaces: ReadonlySet<string>;\n\n /**\n * Per-space subdirectories observed under\n * `<projectRoot>/migrations/`. Resolved via\n * {@link listContractSpaceDirectories}.\n */\n readonly spaceDirsOnDisk: readonly string[];\n\n /**\n * Head ref per space, keyed by space id. Caller reads\n * `<projectRoot>/migrations/<space-id>/contract.json` and\n * `<projectRoot>/migrations/<space-id>/refs/head.json` to construct\n * this map. Spaces with no contract-space dir on disk simply omit a\n * map entry.\n */\n readonly headRefsBySpace: ReadonlyMap<string, ContractSpaceHeadRecord>;\n\n /**\n * Marker rows keyed by `space`. Caller reads them from the\n * `prisma_contract.marker` table.\n */\n readonly markerRowsBySpace: ReadonlyMap<string, SpaceMarkerRecord>;\n}\n\nexport type SpaceVerifierViolation =\n | {\n readonly kind: 'declaredButUnmigrated';\n readonly spaceId: string;\n readonly remediation: string;\n }\n | {\n readonly kind: 'orphanMarker';\n readonly spaceId: string;\n readonly remediation: string;\n }\n | {\n readonly kind: 'orphanSpaceDir';\n readonly spaceId: string;\n readonly remediation: string;\n }\n | {\n readonly kind: 'hashMismatch';\n readonly spaceId: string;\n readonly priorHeadHash: string;\n readonly markerHash: string;\n readonly remediation: string;\n }\n | {\n readonly kind: 'invariantsMismatch';\n readonly spaceId: string;\n readonly onDiskInvariants: readonly string[];\n readonly markerInvariants: readonly string[];\n readonly remediation: string;\n };\n\nexport type VerifyContractSpacesResult =\n | { readonly ok: true }\n | { readonly ok: false; readonly violations: readonly SpaceVerifierViolation[] };\n\n/**\n * Pure structural verifier for the per-space mechanism. Aggregates the\n * three orphan / missing checks plus per-space hash and invariant\n * comparison.\n *\n * Algorithm:\n *\n * - For every extension space declared in `loadedSpaces` (`'app'`\n * excluded — the per-space verifier is scoped to extension members;\n * the app is verified through the aggregate path):\n * - If no contract-space dir on disk → `declaredButUnmigrated`.\n * - Else if `markerRowsBySpace` lacks an entry → no violation here;\n * the live-DB compare done outside this helper is where the\n * absence shows up.\n * - Else compare marker hash / invariants vs. on-disk head hash /\n * invariants → `hashMismatch` / `invariantsMismatch` on drift.\n * - For every contract-space dir on disk that is not in `loadedSpaces` →\n * `orphanSpaceDir`.\n * - For every marker row whose `space` is not in `loadedSpaces` →\n * `orphanMarker`. The app-space marker is always loaded (`'app'` is\n * in `loadedSpaces` by definition).\n *\n * Output is deterministic: violations are sorted first by `kind`\n * (`declaredButUnmigrated` → `orphanMarker` → `orphanSpaceDir` →\n * `hashMismatch` → `invariantsMismatch`) then by `spaceId`. Two callers\n * passing equivalent inputs see byte-identical violation lists.\n *\n * Synchronous, pure, no I/O. **Does not import the extension descriptor**\n * (the inputs are pre-resolved by the caller); the verifier reads only\n * the user repo, not `node_modules`.\n */\nexport function verifyContractSpaces(\n inputs: VerifyContractSpacesInputs,\n): VerifyContractSpacesResult {\n const violations: SpaceVerifierViolation[] = [];\n\n for (const spaceId of [...inputs.loadedSpaces].sort()) {\n if (spaceId === APP_SPACE_ID) continue;\n\n if (!inputs.spaceDirsOnDisk.includes(spaceId)) {\n violations.push({\n kind: 'declaredButUnmigrated',\n spaceId,\n remediation: `Extension '${spaceId}' is declared in extensionPacks but has not been emitted; run \\`prisma-next migrate\\`.`,\n });\n continue;\n }\n\n const head = inputs.headRefsBySpace.get(spaceId);\n const marker = inputs.markerRowsBySpace.get(spaceId);\n if (!head || !marker) {\n continue;\n }\n\n if (head.hash !== marker.hash) {\n violations.push({\n kind: 'hashMismatch',\n spaceId,\n priorHeadHash: head.hash,\n markerHash: marker.hash,\n remediation: `Marker row for space '${spaceId}' is keyed at ${marker.hash}, but the on-disk ${join('migrations', spaceId, 'contract.json')} resolves to ${head.hash}. Run \\`prisma-next db update\\` to advance the database, or \\`prisma-next migrate\\` if the descriptor was bumped without re-emitting.`,\n });\n continue;\n }\n\n const onDiskInvariants = [...head.invariants].sort();\n const markerInvariants = new Set(marker.invariants);\n const missing = onDiskInvariants.filter((id) => !markerInvariants.has(id));\n if (missing.length > 0) {\n violations.push({\n kind: 'invariantsMismatch',\n spaceId,\n onDiskInvariants,\n markerInvariants: [...marker.invariants].sort(),\n remediation: `Marker row for space '${spaceId}' is missing invariants [${missing.map((s) => JSON.stringify(s)).join(', ')}]. Run \\`prisma-next db update\\` to apply the corresponding data-transform migrations.`,\n });\n }\n }\n\n for (const dir of [...inputs.spaceDirsOnDisk].sort()) {\n if (!inputs.loadedSpaces.has(dir)) {\n violations.push({\n kind: 'orphanSpaceDir',\n spaceId: dir,\n remediation: `Orphan contract-space directory \\`${join('migrations', dir)}/\\` for an extension not in extensionPacks; remove the directory or re-add the extension.`,\n });\n }\n }\n\n for (const space of [...inputs.markerRowsBySpace.keys()].sort()) {\n if (!inputs.loadedSpaces.has(space)) {\n violations.push({\n kind: 'orphanMarker',\n spaceId: space,\n remediation: `Orphan marker row for space '${space}' (no longer in extensionPacks); remediation: manually delete the row from \\`prisma_contract.marker\\`.`,\n });\n }\n }\n\n if (violations.length === 0) {\n return { ok: true };\n }\n\n const kindOrder: Record<SpaceVerifierViolation['kind'], number> = {\n declaredButUnmigrated: 0,\n orphanMarker: 1,\n orphanSpaceDir: 2,\n hashMismatch: 3,\n invariantsMismatch: 4,\n };\n\n violations.sort((a, b) => {\n const k = kindOrder[a.kind] - kindOrder[b.kind];\n if (k !== 0) return k;\n if (a.spaceId < b.spaceId) return -1;\n if (a.spaceId > b.spaceId) return 1;\n return 0;\n });\n\n return { ok: false, violations };\n}\n","import { readFile } from 'node:fs/promises';\nimport { join } from 'pathe';\nimport { errorInvalidJson, errorMissingFile } from './errors';\nimport { assertValidSpaceId } from './space-layout';\n\nfunction hasErrnoCode(error: unknown, code: string): boolean {\n return error instanceof Error && (error as { code?: string }).code === code;\n}\n\n/**\n * Read the on-disk contract value for a contract space\n * (`<projectMigrationsDir>/<spaceId>/contract.json`). Returns the parsed\n * JSON value as `unknown` — callers that need a typed contract validate\n * via their family's `validateContract` to surface schema issues.\n *\n * Companion to {@link import('./read-contract-space-head-ref').readContractSpaceHeadRef}\n * — same ENOENT-throws / corrupt-file-error semantics. Returns the\n * canonical-JSON value the framework wrote during emit, so re-running\n * this helper across machines / runs yields a byte-identical value.\n */\nexport async function readContractSpaceContract(\n projectMigrationsDir: string,\n spaceId: string,\n): Promise<unknown> {\n assertValidSpaceId(spaceId);\n\n const filePath = join(projectMigrationsDir, spaceId, 'contract.json');\n\n let raw: string;\n try {\n raw = await readFile(filePath, 'utf-8');\n } catch (error) {\n if (hasErrnoCode(error, 'ENOENT')) {\n throw errorMissingFile('contract.json', join(projectMigrationsDir, spaceId));\n }\n throw error;\n }\n\n try {\n return JSON.parse(raw);\n } catch (e) {\n throw errorInvalidJson(filePath, e instanceof Error ? e.message : String(e));\n }\n}\n"],"mappings":";;;;;;;;;;;AAoBA,MAAM,mBAAmB;AAEzB,SAAgB,eAAe,SAA0C;CACvE,OAAO,iBAAiB,KAAK,QAAQ;;AAGvC,SAAgB,mBAAmB,SAAkD;CACnF,IAAI,CAAC,eAAe,QAAQ,EAC1B,MAAM,oBAAoB,QAAQ;;;;;;;;;;;;;;AAgBtC,SAAgB,wBAAwB,sBAA8B,SAAyB;CAC7F,mBAAmB,QAAQ;CAC3B,OAAO,KAAK,sBAAsB,QAAQ;;;;ACtC5C,SAASA,eAAa,OAAgB,MAAuB;CAC3D,OAAO,iBAAiB,SAAU,MAA4B,SAAS;;;;;;;;;;;;;;;AAgBzE,eAAsB,yBACpB,sBACA,SACsC;CACtC,mBAAmB,QAAQ;CAE3B,MAAM,WAAW,KAAK,sBAAsB,SAAS,QAAQ,YAAY;CAEzE,IAAI;CACJ,IAAI;EACF,MAAM,MAAM,SAAS,UAAU,QAAQ;UAChC,OAAO;EACd,IAAIA,eAAa,OAAO,SAAS,EAC/B,OAAO;EAET,MAAM;;CAGR,IAAI;CACJ,IAAI;EACF,SAAS,KAAK,MAAM,IAAI;UACjB,GAAG;EACV,MAAM,iBAAiB,UAAU,aAAa,QAAQ,EAAE,UAAU,OAAO,EAAE,CAAC;;CAG9E,IAAI,OAAO,WAAW,YAAY,WAAW,MAC3C,MAAM,oBAAoB,UAAU,qBAAqB;CAE3D,MAAM,MAAM;CACZ,IAAI,OAAO,IAAI,SAAS,UACtB,MAAM,oBAAoB,UAAU,gDAAgD;CAEtF,IAAI,CAAC,MAAM,QAAQ,IAAI,WAAW,IAAI,IAAI,WAAW,MAAM,UAAU,OAAO,UAAU,SAAS,EAC7F,MAAM,oBAAoB,UAAU,2DAA2D;CA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ACvB,cAAc;EACd,gBAAgB;EAChB,cAAc;EACd,oBAAoB;EACrB;CAED,WAAW,MAAM,GAAG,MAAM;EACxB,MAAM,IAAI,UAAU,EAAE,QAAQ,UAAU,EAAE;EAC1C,IAAI,MAAM,GAAG,OAAO;EACpB,IAAI,EAAE,UAAU,EAAE,SAAS,OAAO;EAClC,IAAI,EAAE,UAAU,EAAE,SAAS,OAAO;EAClC,OAAO;GACP;CAEF,OAAO;EAAE,IAAI;EAAO;EAAY;;;;ACzQlC,SAAS,aAAa,OAAgB,MAAuB;CAC3D,OAAO,iBAAiB,SAAU,MAA4B,SAAS;;;;;;;;;;;;;AAczE,eAAsB,0BACpB,sBACA,SACkB;CAClB,mBAAmB,QAAQ;CAE3B,MAAM,WAAW,KAAK,sBAAsB,SAAS,gBAAgB;CAErE,IAAI;CACJ,IAAI;EACF,MAAM,MAAM,SAAS,UAAU,QAAQ;UAChC,OAAO;EACd,IAAI,aAAa,OAAO,SAAS,EAC/B,MAAM,iBAAiB,iBAAiB,KAAK,sBAAsB,QAAQ,CAAC;EAE9E,MAAM;;CAGR,IAAI;EACF,OAAO,KAAK,MAAM,IAAI;UACf,GAAG;EACV,MAAM,iBAAiB,UAAU,aAAa,QAAQ,EAAE,UAAU,OAAO,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma-next/migration-tools",
3
- "version": "0.6.0-dev.3",
3
+ "version": "0.6.0-dev.5",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -9,16 +9,16 @@
9
9
  "arktype": "^2.1.29",
10
10
  "pathe": "^2.0.3",
11
11
  "prettier": "^3.8.3",
12
- "@prisma-next/contract": "0.6.0-dev.3",
13
- "@prisma-next/framework-components": "0.6.0-dev.3",
14
- "@prisma-next/utils": "0.6.0-dev.3"
12
+ "@prisma-next/contract": "0.6.0-dev.5",
13
+ "@prisma-next/framework-components": "0.6.0-dev.5",
14
+ "@prisma-next/utils": "0.6.0-dev.5"
15
15
  },
16
16
  "devDependencies": {
17
17
  "tsdown": "0.22.0",
18
18
  "typescript": "5.9.3",
19
19
  "vitest": "4.1.5",
20
- "@prisma-next/tsdown": "0.0.0",
21
- "@prisma-next/tsconfig": "0.0.0"
20
+ "@prisma-next/tsconfig": "0.0.0",
21
+ "@prisma-next/tsdown": "0.0.0"
22
22
  },
23
23
  "files": [
24
24
  "dist",
@@ -1,7 +1,6 @@
1
1
  import type { Contract } from '@prisma-next/contract/types';
2
2
  import { notOk, ok, type Result } from '@prisma-next/utils/result';
3
3
  import { EMPTY_CONTRACT_HASH } from '../constants';
4
- import { detectSpaceContractDrift } from '../detect-space-contract-drift';
5
4
  import { readMigrationsDir } from '../io';
6
5
  import { reconstructGraph } from '../migration-graph';
7
6
  import type { OnDiskMigrationPackage } from '../package';
@@ -11,18 +10,6 @@ import { APP_SPACE_ID, spaceMigrationDirectory } from '../space-layout';
11
10
  import { listContractSpaceDirectories } from '../verify-contract-spaces';
12
11
  import type { ContractSpaceAggregate, ContractSpaceMember, HydratedMigrationGraph } from './types';
13
12
 
14
- /**
15
- * Hash function used by drift detection. Defaults to a canonical-JSON +
16
- * SHA-256 pipeline that mirrors the framework's contract-hash convention,
17
- * but the loader accepts a callback so SQL-family callers can pass their
18
- * `coreHash` / `storageHash` derivation through unchanged.
19
- *
20
- * The contract value passed in is the framework-neutral `unknown` form;
21
- * callers that have already validated typed contracts can simply hand
22
- * the validated value back through.
23
- */
24
- export type AggregateContractHasher = (contract: unknown) => string;
25
-
26
13
  /**
27
14
  * Single declared extension entry the loader needs from `Config.extensionPacks`.
28
15
  *
@@ -32,20 +19,20 @@ export type AggregateContractHasher = (contract: unknown) => string;
32
19
  * - `targetId` — the configured `Config.adapter.targetId` value the
33
20
  * declaring extension declared. The loader rejects mismatches against
34
21
  * the aggregate's `targetId` with `targetMismatch`.
35
- * - `contractSpace` — present iff the descriptor declares a contract
36
- * space (extensions can ship without one and remain runtime-only /
37
- * codec-only). Drift detection compares the descriptor's
38
- * `contractJson` hash against the on-disk on-disk head hash; the loader
39
- * rejects drift fatally.
22
+ *
23
+ * Whether the descriptor declares a contract space is decided by whether
24
+ * its corresponding `migrations/<id>/` directory exists on disk
25
+ * (materialised by the seed phase before the loader runs); the loader
26
+ * never reads the descriptor's `contractJson` itself. That makes the
27
+ * aggregate's apply / verify paths byte-for-byte independent of the
28
+ * descriptor module — `db verify` succeeds even if the descriptor's
29
+ * `contractJson` is a throwing getter.
40
30
  *
41
31
  * Typed structurally so the migration-tools layer stays framework-neutral.
42
32
  */
43
33
  export interface DeclaredExtensionEntry {
44
34
  readonly id: string;
45
35
  readonly targetId: string;
46
- readonly contractSpace?: {
47
- readonly contractJson: unknown;
48
- };
49
36
  }
50
37
 
51
38
  /**
@@ -63,7 +50,6 @@ export interface LoadAggregateInput {
63
50
  readonly appContract: Contract;
64
51
  readonly declaredExtensions: ReadonlyArray<DeclaredExtensionEntry>;
65
52
  readonly validateContract: (contractJson: unknown) => Contract;
66
- readonly hashContract: AggregateContractHasher;
67
53
  /**
68
54
  * Hydrated migration graph for the **app member**.
69
55
  *
@@ -90,12 +76,6 @@ export type LoadAggregateError =
90
76
  | { readonly kind: 'layoutViolation'; readonly violations: readonly LayoutViolation[] }
91
77
  | { readonly kind: 'integrityFailure'; readonly spaceId: string; readonly detail: string }
92
78
  | { readonly kind: 'validationFailure'; readonly spaceId: string; readonly detail: string }
93
- | {
94
- readonly kind: 'driftViolation';
95
- readonly spaceId: string;
96
- readonly priorHeadHash: string;
97
- readonly liveHash: string;
98
- }
99
79
  | {
100
80
  readonly kind: 'disjointnessViolation';
101
81
  readonly element: string;
@@ -139,20 +119,22 @@ interface LoadedExtensionState {
139
119
 
140
120
  /**
141
121
  * Hydrate a {@link ContractSpaceAggregate} from on-disk state and
142
- * caller-provided descriptor data.
122
+ * the app contract value the caller supplies.
143
123
  *
144
- * This is the **only** descriptor-import boundary in the post-M2.5
145
- * pipeline: callers read `extensionPacks` from `Config`, validate the
146
- * app contract, and pass everything through. The loader composes
147
- * existing migration-tools primitives layout precheck (via
124
+ * The loader is the **only** descriptor-import boundary at apply /
125
+ * verify time, but it intentionally does **not** read the extension
126
+ * descriptor's `contractJson` value. Each extension space's contract
127
+ * is read from its on-disk `migrations/<id>/contract.json` mirror; the
128
+ * descriptor's role is exhausted by the seed phase that wrote that
129
+ * mirror in the first place. The loader composes existing
130
+ * migration-tools primitives — layout precheck (via
148
131
  * {@link listContractSpaceDirectories}), integrity checks (via
149
132
  * {@link readMigrationsDir} / {@link readContractSpaceHeadRef} /
150
- * {@link readContractSpaceContract} / `validateContract`), drift detection
151
- * (via {@link detectSpaceContractDrift}), and disjointness — into a
152
- * single typed value.
133
+ * {@link readContractSpaceContract} / `validateContract`), and
134
+ * disjointness — into a single typed value.
153
135
  *
154
136
  * Failure semantics: every failure variant in {@link LoadAggregateError}
155
- * short-circuits the load. Drift is fatal (M2.5 spec § Loader, step 5).
137
+ * short-circuits the load.
156
138
  */
157
139
  export async function loadContractSpaceAggregate(
158
140
  input: LoadAggregateInput,
@@ -180,8 +162,14 @@ export async function loadContractSpaceAggregate(
180
162
  }
181
163
 
182
164
  // 2. Layout precheck: bundle every layout offence at once.
183
- const declaredWithSpace = input.declaredExtensions.filter((e) => e.contractSpace !== undefined);
184
- const declaredSpaceIds = new Set(declaredWithSpace.map((e) => e.id));
165
+ //
166
+ // Every declared extension contributes an entry to the aggregate when
167
+ // a corresponding `migrations/<id>/` directory exists on disk. The
168
+ // loader treats the directory's presence as the membership signal —
169
+ // the descriptor itself is not read — so codec-only extensions (no
170
+ // on-disk dir) and contract-space extensions (dir present) are
171
+ // distinguished structurally.
172
+ const declaredSpaceIds = new Set(input.declaredExtensions.map((e) => e.id));
185
173
  const allDirs = await listContractSpaceDirectories(input.migrationsDir);
186
174
  // The app member is implicitly declared (it is always part of the
187
175
  // aggregate); its `migrations/<APP_SPACE_ID>/` directory may exist or
@@ -206,9 +194,9 @@ export async function loadContractSpaceAggregate(
206
194
  return notOk({ kind: 'layoutViolation', violations: layoutViolations });
207
195
  }
208
196
 
209
- // 3-5. Per-extension: read + validate + integrity-check + drift.
197
+ // 3-5. Per-extension: read + validate + integrity-check.
210
198
  const loadedExtensions: LoadedExtensionState[] = [];
211
- for (const entry of [...declaredWithSpace].sort((a, b) => a.id.localeCompare(b.id))) {
199
+ for (const entry of [...input.declaredExtensions].sort((a, b) => a.id.localeCompare(b.id))) {
212
200
  const headRef = await readContractSpaceHeadRef(input.migrationsDir, entry.id);
213
201
  if (headRef === null) {
214
202
  return notOk({
@@ -249,24 +237,6 @@ export async function loadContractSpaceAggregate(
249
237
  });
250
238
  }
251
239
 
252
- // Drift: compare descriptor's live `contractJson` to on-disk
253
- // `refs/head.json.hash`.
254
- if (entry.contractSpace) {
255
- const liveHash = input.hashContract(entry.contractSpace.contractJson);
256
- const drift = detectSpaceContractDrift(entry.id, {
257
- descriptorHash: liveHash,
258
- priorHeadHash: headRef.hash,
259
- });
260
- if (drift.kind === 'drift') {
261
- return notOk({
262
- kind: 'driftViolation',
263
- spaceId: entry.id,
264
- priorHeadHash: drift.priorHeadHash ?? '',
265
- liveHash: drift.descriptorHash,
266
- });
267
- }
268
- }
269
-
270
240
  // Read + integrity-check the migration packages. `readMigrationsDir`
271
241
  // re-derives `providedInvariants` and verifies migrationHash for
272
242
  // every package.
@@ -11,6 +11,7 @@ import type { ContractSpaceMember } from './types';
11
11
 
12
12
  export type {
13
13
  AggregateCurrentDBState,
14
+ AggregateMigrationEdgeRef,
14
15
  AggregatePerSpacePlan,
15
16
  AggregatePlannerError,
16
17
  AggregatePlannerInput,
@@ -1,5 +1,4 @@
1
1
  export {
2
- type AggregateContractHasher,
3
2
  type DeclaredExtensionEntry,
4
3
  type LayoutViolation,
5
4
  type LoadAggregateError,
@@ -10,6 +9,7 @@ export {
10
9
  export type { ContractMarkerRecordLike } from '../aggregate/marker-types';
11
10
  export {
12
11
  type AggregateCurrentDBState,
12
+ type AggregateMigrationEdgeRef,
13
13
  type AggregatePerSpacePlan,
14
14
  type AggregatePlannerError,
15
15
  type AggregatePlannerInput,
@@ -9,11 +9,6 @@ export {
9
9
  } from '../compute-extension-space-apply-path';
10
10
  export type { SpaceApplyInput } from '../concatenate-space-apply-inputs';
11
11
  export { contractSpaceFromJson } from '../contract-space-from-json';
12
- export {
13
- type DetectSpaceContractDriftInputs,
14
- detectSpaceContractDrift,
15
- type SpaceContractDriftResult,
16
- } from '../detect-space-contract-drift';
17
12
  export {
18
13
  type ContractSpaceArtefactInputs,
19
14
  emitContractSpaceArtefacts,
@@ -1 +0,0 @@
1
- {"version":3,"file":"read-contract-space-contract-Bj_EMYSC.mjs","names":["hasErrnoCode","hasErrnoCode"],"sources":["../src/space-layout.ts","../src/read-contract-space-head-ref.ts","../src/detect-space-contract-drift.ts","../src/verify-contract-spaces.ts","../src/read-contract-space-contract.ts"],"sourcesContent":["import { APP_SPACE_ID } from '@prisma-next/framework-components/control';\nimport { join } from 'pathe';\nimport { errorInvalidSpaceId } from './errors';\n\nexport { APP_SPACE_ID };\n\n/**\n * Branded string carrying a compile-time guarantee that the value has\n * been validated by {@link assertValidSpaceId}. Downstream filesystem\n * helpers (e.g. {@link spaceMigrationDirectory}) accept this type to\n * make \"validated\" tracking visible at the type level rather than\n * relying purely on a runtime check.\n */\nexport type ValidSpaceId = string & { readonly __brand: 'ValidSpaceId' };\n\n/**\n * Pattern a contract-space identifier must match. The constraint is\n * filesystem-friendly: lowercase letters / digits / hyphen / underscore,\n * starts with a letter, max 64 characters.\n */\nconst SPACE_ID_PATTERN = /^[a-z][a-z0-9_-]{0,63}$/;\n\nexport function isValidSpaceId(spaceId: string): spaceId is ValidSpaceId {\n return SPACE_ID_PATTERN.test(spaceId);\n}\n\nexport function assertValidSpaceId(spaceId: string): asserts spaceId is ValidSpaceId {\n if (!isValidSpaceId(spaceId)) {\n throw errorInvalidSpaceId(spaceId);\n }\n}\n\n/**\n * Resolve the migrations subdirectory for a given contract space.\n *\n * Every contract space — including the app space (default `'app'`) —\n * lands under `<projectMigrationsDir>/<spaceId>/`. The space id is\n * validated against {@link SPACE_ID_PATTERN} because it becomes a\n * filesystem directory name verbatim.\n *\n * `projectMigrationsDir` is the project's top-level `migrations/`\n * directory; the helper does not assume anything about its absolute /\n * relative shape and is symmetric with `pathe.join`.\n */\nexport function spaceMigrationDirectory(projectMigrationsDir: string, spaceId: string): string {\n assertValidSpaceId(spaceId);\n return join(projectMigrationsDir, spaceId);\n}\n","import { readFile } from 'node:fs/promises';\nimport type { ContractSpaceHeadRef } from '@prisma-next/framework-components/control';\nimport { join } from 'pathe';\nimport { errorInvalidJson, errorInvalidRefFile } from './errors';\nimport { assertValidSpaceId } from './space-layout';\n\nexport type { ContractSpaceHeadRef };\n\nfunction hasErrnoCode(error: unknown, code: string): boolean {\n return error instanceof Error && (error as { code?: string }).code === code;\n}\n\n/**\n * Read the head ref (`hash` + `invariants`) for a contract space from\n * `<projectMigrationsDir>/<spaceId>/refs/head.json`.\n *\n * Returns `null` when the file does not exist (first emit). Surfaces\n * `MIGRATION.INVALID_JSON` / `MIGRATION.INVALID_REF_FILE` on a corrupt\n * `refs/head.json` so callers can distinguish \"no head ref on disk\"\n * (returns `null`) from \"head ref present but unreadable\" (throws).\n *\n * Validates the space id against `[a-z][a-z0-9_-]{0,63}` for the same\n * filesystem-safety reasons as the rest of the per-space helpers. The\n * helper is uniform across the app and extension spaces.\n */\nexport async function readContractSpaceHeadRef(\n projectMigrationsDir: string,\n spaceId: string,\n): Promise<ContractSpaceHeadRef | null> {\n assertValidSpaceId(spaceId);\n\n const filePath = join(projectMigrationsDir, spaceId, 'refs', 'head.json');\n\n let raw: string;\n try {\n raw = await readFile(filePath, 'utf-8');\n } catch (error) {\n if (hasErrnoCode(error, 'ENOENT')) {\n return null;\n }\n throw error;\n }\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch (e) {\n throw errorInvalidJson(filePath, e instanceof Error ? e.message : String(e));\n }\n\n if (typeof parsed !== 'object' || parsed === null) {\n throw errorInvalidRefFile(filePath, 'expected an object');\n }\n const obj = parsed as { hash?: unknown; invariants?: unknown };\n if (typeof obj.hash !== 'string') {\n throw errorInvalidRefFile(filePath, 'expected an object with a string `hash` field');\n }\n if (!Array.isArray(obj.invariants) || obj.invariants.some((value) => typeof value !== 'string')) {\n throw errorInvalidRefFile(filePath, 'expected an object with an `invariants` array of strings');\n }\n\n return { hash: obj.hash, invariants: obj.invariants as readonly string[] };\n}\n","/**\n * Inputs for {@link detectSpaceContractDrift}.\n *\n * Both hashes are produced by the caller (the SQL-family wiring at the\n * consumption site) using the canonical contract hashing pipeline.\n * Keeping the helper pure lets `migration-tools` stay framework-neutral\n * — the SQL family already speaks `Contract<SqlStorage>`, the Mongo\n * family speaks its own contract type, and both reduce to a hash string\n * before drift detection runs.\n *\n * `priorHeadHash` is `null` when no `contract.json` exists yet on disk for\n * the space (the descriptor declares an extension that has never been\n * emitted into the user's repo). That's the \"first emit\" case — no\n * drift to surface; the migrate emit will create the on-disk artefacts.\n */\nexport interface DetectSpaceContractDriftInputs {\n readonly descriptorHash: string;\n readonly priorHeadHash: string | null;\n}\n\n/**\n * Result discriminant for {@link detectSpaceContractDrift}.\n *\n * - `noDrift`: descriptor hash and on-disk head hash agree byte-for-byte.\n * The migrate emit can proceed with no warning.\n * - `firstEmit`: no on-disk `contract.json` on disk yet. The extension\n * was just added to `extensionPacks`; this run will create the\n * on-disk artefacts. No warning either — the user's intent is to install\n * the extension, not to \"drift\" from a state they haven't recorded.\n * - `drift`: descriptor hash differs from on-disk head hash. The caller\n * surfaces a non-fatal warning naming the extension and the\n * diff direction (descriptor → on-disk head). The migrate emit proceeds\n * normally so the bump is materialised this run; the warning just\n * confirms the bump is being captured.\n *\n * `spaceId`, `descriptorHash`, and `priorHeadHash` are threaded through\n * verbatim so the caller (logger / TerminalUI / strict-mode envelope)\n * has everything it needs to format the warning message without\n * re-reading the descriptor or the on-disk artefact.\n */\nexport type SpaceContractDriftResult = {\n readonly kind: 'noDrift' | 'firstEmit' | 'drift';\n readonly spaceId: string;\n readonly descriptorHash: string;\n readonly priorHeadHash: string | null;\n};\n\n/**\n * Pure drift-detection primitive for a single contract space.\n *\n * Runs once per loaded extension space, just before computing the\n * `priorContract` that feeds {@link import('./plan-all-spaces').planAllSpaces}.\n * Hash equality is byte-for-byte (no normalisation) — both sides are\n * already canonical hashes produced by the same pipeline, so any\n * difference is meaningful drift.\n *\n * Synchronous, pure, no I/O. The caller (SQL family) reads the on-disk\n * `contract.json` and computes its hash, then invokes this helper\n * alongside the descriptor's `headRef.hash`. Composes naturally with\n * {@link import('./read-contract-space-head-ref').readContractSpaceHeadRef}\n * which provides the read-side primitive.\n *\n * The drift warning surfaces the extension name and the diff direction.\n */\nexport function detectSpaceContractDrift(\n spaceId: string,\n inputs: DetectSpaceContractDriftInputs,\n): SpaceContractDriftResult {\n if (inputs.priorHeadHash === null) {\n return {\n kind: 'firstEmit',\n spaceId,\n descriptorHash: inputs.descriptorHash,\n priorHeadHash: null,\n };\n }\n if (inputs.descriptorHash === inputs.priorHeadHash) {\n return {\n kind: 'noDrift',\n spaceId,\n descriptorHash: inputs.descriptorHash,\n priorHeadHash: inputs.priorHeadHash,\n };\n }\n return {\n kind: 'drift',\n spaceId,\n descriptorHash: inputs.descriptorHash,\n priorHeadHash: inputs.priorHeadHash,\n };\n}\n","import { readdir, stat } from 'node:fs/promises';\nimport { join } from 'pathe';\nimport { MANIFEST_FILE } from './io';\nimport { APP_SPACE_ID } from './space-layout';\n\nfunction hasErrnoCode(error: unknown, code: string): boolean {\n return error instanceof Error && (error as { code?: string }).code === code;\n}\n\n/**\n * List the per-space subdirectories under\n * `<projectRoot>/migrations/`. Returns space-id directory names (sorted\n * alphabetically) — i.e. any non-dot-prefixed subdirectory whose root\n * does **not** contain a `migration.json` manifest. The manifest is the\n * structural marker of a user-authored migration directory (see\n * `readMigrationsDir` in `./io`); directory names themselves belong to\n * the user and are not part of the contract.\n *\n * Returns `[]` if the migrations directory does not exist (greenfield\n * project).\n *\n * Reads only the user's repo. **No descriptor import.** The caller\n * (verifier) feeds the result into {@link verifyContractSpaces} alongside\n * the loaded-space set and the marker rows.\n */\nexport async function listContractSpaceDirectories(\n projectMigrationsDir: string,\n): Promise<readonly string[]> {\n let entries: { readonly name: string; readonly isDirectory: boolean }[];\n try {\n const dirents = await readdir(projectMigrationsDir, { withFileTypes: true });\n entries = dirents.map((d) => ({ name: d.name, isDirectory: d.isDirectory() }));\n } catch (error) {\n if (hasErrnoCode(error, 'ENOENT')) {\n return [];\n }\n throw error;\n }\n\n const namedCandidates = entries\n .filter((e) => e.isDirectory)\n .map((e) => e.name)\n .filter((name) => !name.startsWith('.'))\n .sort();\n\n const manifestChecks = await Promise.all(\n namedCandidates.map(async (name) => {\n try {\n await stat(join(projectMigrationsDir, name, MANIFEST_FILE));\n return { name, isMigrationDir: true };\n } catch (error) {\n if (hasErrnoCode(error, 'ENOENT')) {\n return { name, isMigrationDir: false };\n }\n throw error;\n }\n }),\n );\n\n return manifestChecks.filter((c) => !c.isMigrationDir).map((c) => c.name);\n}\n\n/**\n * On-disk head value (`(hash, invariants)`) for one contract space.\n * The verifier compares this against the marker row for the same space\n * to detect drift between the user-emitted artefacts and the live DB\n * marker.\n */\nexport interface ContractSpaceHeadRecord {\n readonly hash: string;\n readonly invariants: readonly string[];\n}\n\n/**\n * Marker row read from `prisma_contract.marker` (one per `space`).\n * Caller resolves these via the family runtime's marker reader before\n * invoking {@link verifyContractSpaces}.\n */\nexport interface SpaceMarkerRecord {\n readonly hash: string;\n readonly invariants: readonly string[];\n}\n\nexport interface VerifyContractSpacesInputs {\n /**\n * Set of contract spaces the project declares: `'app'` plus each\n * extension space in `extensionPacks`. The caller's discovery path\n * never reads the extension descriptor module — it walks the\n * `extensionPacks` configuration in `prisma-next.config.ts` for the\n * space ids.\n */\n readonly loadedSpaces: ReadonlySet<string>;\n\n /**\n * Per-space subdirectories observed under\n * `<projectRoot>/migrations/`. Resolved via\n * {@link listContractSpaceDirectories}.\n */\n readonly spaceDirsOnDisk: readonly string[];\n\n /**\n * Head ref per space, keyed by space id. Caller reads\n * `<projectRoot>/migrations/<space-id>/contract.json` and\n * `<projectRoot>/migrations/<space-id>/refs/head.json` to construct\n * this map. Spaces with no contract-space dir on disk simply omit a\n * map entry.\n */\n readonly headRefsBySpace: ReadonlyMap<string, ContractSpaceHeadRecord>;\n\n /**\n * Marker rows keyed by `space`. Caller reads them from the\n * `prisma_contract.marker` table.\n */\n readonly markerRowsBySpace: ReadonlyMap<string, SpaceMarkerRecord>;\n}\n\nexport type SpaceVerifierViolation =\n | {\n readonly kind: 'declaredButUnmigrated';\n readonly spaceId: string;\n readonly remediation: string;\n }\n | {\n readonly kind: 'orphanMarker';\n readonly spaceId: string;\n readonly remediation: string;\n }\n | {\n readonly kind: 'orphanSpaceDir';\n readonly spaceId: string;\n readonly remediation: string;\n }\n | {\n readonly kind: 'hashMismatch';\n readonly spaceId: string;\n readonly priorHeadHash: string;\n readonly markerHash: string;\n readonly remediation: string;\n }\n | {\n readonly kind: 'invariantsMismatch';\n readonly spaceId: string;\n readonly onDiskInvariants: readonly string[];\n readonly markerInvariants: readonly string[];\n readonly remediation: string;\n };\n\nexport type VerifyContractSpacesResult =\n | { readonly ok: true }\n | { readonly ok: false; readonly violations: readonly SpaceVerifierViolation[] };\n\n/**\n * Pure structural verifier for the per-space mechanism. Aggregates the\n * three orphan / missing checks plus per-space hash and invariant\n * comparison.\n *\n * Algorithm:\n *\n * - For every extension space declared in `loadedSpaces` (`'app'`\n * excluded — the per-space verifier is scoped to extension members;\n * the app is verified through the aggregate path):\n * - If no contract-space dir on disk → `declaredButUnmigrated`.\n * - Else if `markerRowsBySpace` lacks an entry → no violation here;\n * the live-DB compare done outside this helper is where the\n * absence shows up.\n * - Else compare marker hash / invariants vs. on-disk head hash /\n * invariants → `hashMismatch` / `invariantsMismatch` on drift.\n * - For every contract-space dir on disk that is not in `loadedSpaces` →\n * `orphanSpaceDir`.\n * - For every marker row whose `space` is not in `loadedSpaces` →\n * `orphanMarker`. The app-space marker is always loaded (`'app'` is\n * in `loadedSpaces` by definition).\n *\n * Output is deterministic: violations are sorted first by `kind`\n * (`declaredButUnmigrated` → `orphanMarker` → `orphanSpaceDir` →\n * `hashMismatch` → `invariantsMismatch`) then by `spaceId`. Two callers\n * passing equivalent inputs see byte-identical violation lists.\n *\n * Synchronous, pure, no I/O. **Does not import the extension descriptor**\n * (the inputs are pre-resolved by the caller); the verifier reads only\n * the user repo, not `node_modules`.\n */\nexport function verifyContractSpaces(\n inputs: VerifyContractSpacesInputs,\n): VerifyContractSpacesResult {\n const violations: SpaceVerifierViolation[] = [];\n\n for (const spaceId of [...inputs.loadedSpaces].sort()) {\n if (spaceId === APP_SPACE_ID) continue;\n\n if (!inputs.spaceDirsOnDisk.includes(spaceId)) {\n violations.push({\n kind: 'declaredButUnmigrated',\n spaceId,\n remediation: `Extension '${spaceId}' is declared in extensionPacks but has not been emitted; run \\`prisma-next migrate\\`.`,\n });\n continue;\n }\n\n const head = inputs.headRefsBySpace.get(spaceId);\n const marker = inputs.markerRowsBySpace.get(spaceId);\n if (!head || !marker) {\n continue;\n }\n\n if (head.hash !== marker.hash) {\n violations.push({\n kind: 'hashMismatch',\n spaceId,\n priorHeadHash: head.hash,\n markerHash: marker.hash,\n remediation: `Marker row for space '${spaceId}' is keyed at ${marker.hash}, but the on-disk ${join('migrations', spaceId, 'contract.json')} resolves to ${head.hash}. Run \\`prisma-next db update\\` to advance the database, or \\`prisma-next migrate\\` if the descriptor was bumped without re-emitting.`,\n });\n continue;\n }\n\n const onDiskInvariants = [...head.invariants].sort();\n const markerInvariants = new Set(marker.invariants);\n const missing = onDiskInvariants.filter((id) => !markerInvariants.has(id));\n if (missing.length > 0) {\n violations.push({\n kind: 'invariantsMismatch',\n spaceId,\n onDiskInvariants,\n markerInvariants: [...marker.invariants].sort(),\n remediation: `Marker row for space '${spaceId}' is missing invariants [${missing.map((s) => JSON.stringify(s)).join(', ')}]. Run \\`prisma-next db update\\` to apply the corresponding data-transform migrations.`,\n });\n }\n }\n\n for (const dir of [...inputs.spaceDirsOnDisk].sort()) {\n if (!inputs.loadedSpaces.has(dir)) {\n violations.push({\n kind: 'orphanSpaceDir',\n spaceId: dir,\n remediation: `Orphan contract-space directory \\`${join('migrations', dir)}/\\` for an extension not in extensionPacks; remove the directory or re-add the extension.`,\n });\n }\n }\n\n for (const space of [...inputs.markerRowsBySpace.keys()].sort()) {\n if (!inputs.loadedSpaces.has(space)) {\n violations.push({\n kind: 'orphanMarker',\n spaceId: space,\n remediation: `Orphan marker row for space '${space}' (no longer in extensionPacks); remediation: manually delete the row from \\`prisma_contract.marker\\`.`,\n });\n }\n }\n\n if (violations.length === 0) {\n return { ok: true };\n }\n\n const kindOrder: Record<SpaceVerifierViolation['kind'], number> = {\n declaredButUnmigrated: 0,\n orphanMarker: 1,\n orphanSpaceDir: 2,\n hashMismatch: 3,\n invariantsMismatch: 4,\n };\n\n violations.sort((a, b) => {\n const k = kindOrder[a.kind] - kindOrder[b.kind];\n if (k !== 0) return k;\n if (a.spaceId < b.spaceId) return -1;\n if (a.spaceId > b.spaceId) return 1;\n return 0;\n });\n\n return { ok: false, violations };\n}\n","import { readFile } from 'node:fs/promises';\nimport { join } from 'pathe';\nimport { errorInvalidJson, errorMissingFile } from './errors';\nimport { assertValidSpaceId } from './space-layout';\n\nfunction hasErrnoCode(error: unknown, code: string): boolean {\n return error instanceof Error && (error as { code?: string }).code === code;\n}\n\n/**\n * Read the on-disk contract value for a contract space\n * (`<projectMigrationsDir>/<spaceId>/contract.json`). Returns the parsed\n * JSON value as `unknown` — callers that need a typed contract validate\n * via their family's `validateContract` to surface schema issues.\n *\n * Companion to {@link import('./read-contract-space-head-ref').readContractSpaceHeadRef}\n * — same ENOENT-throws / corrupt-file-error semantics. Returns the\n * canonical-JSON value the framework wrote during emit, so re-running\n * this helper across machines / runs yields a byte-identical value.\n */\nexport async function readContractSpaceContract(\n projectMigrationsDir: string,\n spaceId: string,\n): Promise<unknown> {\n assertValidSpaceId(spaceId);\n\n const filePath = join(projectMigrationsDir, spaceId, 'contract.json');\n\n let raw: string;\n try {\n raw = await readFile(filePath, 'utf-8');\n } catch (error) {\n if (hasErrnoCode(error, 'ENOENT')) {\n throw errorMissingFile('contract.json', join(projectMigrationsDir, spaceId));\n }\n throw error;\n }\n\n try {\n return JSON.parse(raw);\n } catch (e) {\n throw errorInvalidJson(filePath, e instanceof Error ? e.message : String(e));\n }\n}\n"],"mappings":";;;;;;;;;;;AAoBA,MAAM,mBAAmB;AAEzB,SAAgB,eAAe,SAA0C;CACvE,OAAO,iBAAiB,KAAK,QAAQ;;AAGvC,SAAgB,mBAAmB,SAAkD;CACnF,IAAI,CAAC,eAAe,QAAQ,EAC1B,MAAM,oBAAoB,QAAQ;;;;;;;;;;;;;;AAgBtC,SAAgB,wBAAwB,sBAA8B,SAAyB;CAC7F,mBAAmB,QAAQ;CAC3B,OAAO,KAAK,sBAAsB,QAAQ;;;;ACtC5C,SAASA,eAAa,OAAgB,MAAuB;CAC3D,OAAO,iBAAiB,SAAU,MAA4B,SAAS;;;;;;;;;;;;;;;AAgBzE,eAAsB,yBACpB,sBACA,SACsC;CACtC,mBAAmB,QAAQ;CAE3B,MAAM,WAAW,KAAK,sBAAsB,SAAS,QAAQ,YAAY;CAEzE,IAAI;CACJ,IAAI;EACF,MAAM,MAAM,SAAS,UAAU,QAAQ;UAChC,OAAO;EACd,IAAIA,eAAa,OAAO,SAAS,EAC/B,OAAO;EAET,MAAM;;CAGR,IAAI;CACJ,IAAI;EACF,SAAS,KAAK,MAAM,IAAI;UACjB,GAAG;EACV,MAAM,iBAAiB,UAAU,aAAa,QAAQ,EAAE,UAAU,OAAO,EAAE,CAAC;;CAG9E,IAAI,OAAO,WAAW,YAAY,WAAW,MAC3C,MAAM,oBAAoB,UAAU,qBAAqB;CAE3D,MAAM,MAAM;CACZ,IAAI,OAAO,IAAI,SAAS,UACtB,MAAM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,QAAQ,EAAE,UAAU,OAAO,EAAE,CAAC"}
@@ -1,91 +0,0 @@
1
- /**
2
- * Inputs for {@link detectSpaceContractDrift}.
3
- *
4
- * Both hashes are produced by the caller (the SQL-family wiring at the
5
- * consumption site) using the canonical contract hashing pipeline.
6
- * Keeping the helper pure lets `migration-tools` stay framework-neutral
7
- * — the SQL family already speaks `Contract<SqlStorage>`, the Mongo
8
- * family speaks its own contract type, and both reduce to a hash string
9
- * before drift detection runs.
10
- *
11
- * `priorHeadHash` is `null` when no `contract.json` exists yet on disk for
12
- * the space (the descriptor declares an extension that has never been
13
- * emitted into the user's repo). That's the "first emit" case — no
14
- * drift to surface; the migrate emit will create the on-disk artefacts.
15
- */
16
- export interface DetectSpaceContractDriftInputs {
17
- readonly descriptorHash: string;
18
- readonly priorHeadHash: string | null;
19
- }
20
-
21
- /**
22
- * Result discriminant for {@link detectSpaceContractDrift}.
23
- *
24
- * - `noDrift`: descriptor hash and on-disk head hash agree byte-for-byte.
25
- * The migrate emit can proceed with no warning.
26
- * - `firstEmit`: no on-disk `contract.json` on disk yet. The extension
27
- * was just added to `extensionPacks`; this run will create the
28
- * on-disk artefacts. No warning either — the user's intent is to install
29
- * the extension, not to "drift" from a state they haven't recorded.
30
- * - `drift`: descriptor hash differs from on-disk head hash. The caller
31
- * surfaces a non-fatal warning naming the extension and the
32
- * diff direction (descriptor → on-disk head). The migrate emit proceeds
33
- * normally so the bump is materialised this run; the warning just
34
- * confirms the bump is being captured.
35
- *
36
- * `spaceId`, `descriptorHash`, and `priorHeadHash` are threaded through
37
- * verbatim so the caller (logger / TerminalUI / strict-mode envelope)
38
- * has everything it needs to format the warning message without
39
- * re-reading the descriptor or the on-disk artefact.
40
- */
41
- export type SpaceContractDriftResult = {
42
- readonly kind: 'noDrift' | 'firstEmit' | 'drift';
43
- readonly spaceId: string;
44
- readonly descriptorHash: string;
45
- readonly priorHeadHash: string | null;
46
- };
47
-
48
- /**
49
- * Pure drift-detection primitive for a single contract space.
50
- *
51
- * Runs once per loaded extension space, just before computing the
52
- * `priorContract` that feeds {@link import('./plan-all-spaces').planAllSpaces}.
53
- * Hash equality is byte-for-byte (no normalisation) — both sides are
54
- * already canonical hashes produced by the same pipeline, so any
55
- * difference is meaningful drift.
56
- *
57
- * Synchronous, pure, no I/O. The caller (SQL family) reads the on-disk
58
- * `contract.json` and computes its hash, then invokes this helper
59
- * alongside the descriptor's `headRef.hash`. Composes naturally with
60
- * {@link import('./read-contract-space-head-ref').readContractSpaceHeadRef}
61
- * which provides the read-side primitive.
62
- *
63
- * The drift warning surfaces the extension name and the diff direction.
64
- */
65
- export function detectSpaceContractDrift(
66
- spaceId: string,
67
- inputs: DetectSpaceContractDriftInputs,
68
- ): SpaceContractDriftResult {
69
- if (inputs.priorHeadHash === null) {
70
- return {
71
- kind: 'firstEmit',
72
- spaceId,
73
- descriptorHash: inputs.descriptorHash,
74
- priorHeadHash: null,
75
- };
76
- }
77
- if (inputs.descriptorHash === inputs.priorHeadHash) {
78
- return {
79
- kind: 'noDrift',
80
- spaceId,
81
- descriptorHash: inputs.descriptorHash,
82
- priorHeadHash: inputs.priorHeadHash,
83
- };
84
- }
85
- return {
86
- kind: 'drift',
87
- spaceId,
88
- descriptorHash: inputs.descriptorHash,
89
- priorHeadHash: inputs.priorHeadHash,
90
- };
91
- }