@prisma-next/migration-tools 0.5.0-dev.66 → 0.5.0-dev.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/{constants-B87kJAGj.mjs → constants-DWV9_o2Z.mjs} +2 -2
  2. package/dist/{constants-B87kJAGj.mjs.map → constants-DWV9_o2Z.mjs.map} +1 -1
  3. package/dist/{errors-DQsXvidG.mjs → errors-EPL_9p9f.mjs} +13 -8
  4. package/dist/errors-EPL_9p9f.mjs.map +1 -0
  5. package/dist/exports/aggregate.d.mts +534 -0
  6. package/dist/exports/aggregate.d.mts.map +1 -0
  7. package/dist/exports/aggregate.mjs +598 -0
  8. package/dist/exports/aggregate.mjs.map +1 -0
  9. package/dist/exports/constants.d.mts.map +1 -1
  10. package/dist/exports/constants.mjs +2 -3
  11. package/dist/exports/errors.d.mts +6 -1
  12. package/dist/exports/errors.d.mts.map +1 -1
  13. package/dist/exports/errors.mjs +2 -3
  14. package/dist/exports/graph.d.mts +1 -1
  15. package/dist/exports/graph.mjs +1 -1
  16. package/dist/exports/hash.d.mts +2 -2
  17. package/dist/exports/hash.d.mts.map +1 -1
  18. package/dist/exports/hash.mjs +2 -3
  19. package/dist/exports/invariants.d.mts +14 -4
  20. package/dist/exports/invariants.d.mts.map +1 -1
  21. package/dist/exports/invariants.mjs +2 -4
  22. package/dist/exports/io.d.mts +26 -2
  23. package/dist/exports/io.d.mts.map +1 -1
  24. package/dist/exports/io.mjs +2 -5
  25. package/dist/exports/metadata.d.mts +1 -1
  26. package/dist/exports/metadata.mjs +1 -1
  27. package/dist/exports/migration-graph.d.mts +2 -2
  28. package/dist/exports/migration-graph.d.mts.map +1 -1
  29. package/dist/exports/migration-graph.mjs +1 -525
  30. package/dist/exports/migration-ts.d.mts.map +1 -1
  31. package/dist/exports/migration-ts.mjs +1 -3
  32. package/dist/exports/migration-ts.mjs.map +1 -1
  33. package/dist/exports/migration.d.mts +1 -1
  34. package/dist/exports/migration.d.mts.map +1 -1
  35. package/dist/exports/migration.mjs +5 -6
  36. package/dist/exports/migration.mjs.map +1 -1
  37. package/dist/exports/package.d.mts +1 -1
  38. package/dist/exports/package.mjs +1 -1
  39. package/dist/exports/refs.d.mts.map +1 -1
  40. package/dist/exports/refs.mjs +2 -3
  41. package/dist/exports/refs.mjs.map +1 -1
  42. package/dist/exports/spaces.d.mts +341 -238
  43. package/dist/exports/spaces.d.mts.map +1 -1
  44. package/dist/exports/spaces.mjs +138 -348
  45. package/dist/exports/spaces.mjs.map +1 -1
  46. package/dist/{graph-Czaj8O2q.d.mts → graph-HMWAldoR.d.mts} +1 -1
  47. package/dist/graph-HMWAldoR.d.mts.map +1 -0
  48. package/dist/{hash-G0bAfIGh.mjs → hash-By50zM_E.mjs} +2 -4
  49. package/dist/hash-By50zM_E.mjs.map +1 -0
  50. package/dist/{invariants-4Avb_Yhy.mjs → invariants-Duc8f9NM.mjs} +17 -7
  51. package/dist/invariants-Duc8f9NM.mjs.map +1 -0
  52. package/dist/{io-CDJaWGbt.mjs → io-D13dLvUh.mjs} +46 -14
  53. package/dist/io-D13dLvUh.mjs.map +1 -0
  54. package/dist/migration-graph-DGNnKDY5.mjs +523 -0
  55. package/dist/migration-graph-DGNnKDY5.mjs.map +1 -0
  56. package/dist/{op-schema-BiF1ZYqH.mjs → op-schema-D5qkXfEf.mjs} +2 -3
  57. package/dist/{op-schema-BiF1ZYqH.mjs.map → op-schema-D5qkXfEf.mjs.map} +1 -1
  58. package/dist/{package-B3Yl6DTr.d.mts → package-BjiZ7KDy.d.mts} +1 -1
  59. package/dist/package-BjiZ7KDy.d.mts.map +1 -0
  60. package/dist/read-contract-space-contract-C3-1eyaI.mjs +298 -0
  61. package/dist/read-contract-space-contract-C3-1eyaI.mjs.map +1 -0
  62. package/package.json +13 -9
  63. package/src/aggregate/loader.ts +409 -0
  64. package/src/aggregate/marker-types.ts +16 -0
  65. package/src/aggregate/planner-types.ts +137 -0
  66. package/src/aggregate/planner.ts +158 -0
  67. package/src/aggregate/project-schema-to-space.ts +64 -0
  68. package/src/aggregate/strategies/graph-walk.ts +92 -0
  69. package/src/aggregate/strategies/synth.ts +122 -0
  70. package/src/aggregate/types.ts +89 -0
  71. package/src/aggregate/verifier.ts +230 -0
  72. package/src/assert-descriptor-self-consistency.ts +70 -0
  73. package/src/compute-extension-space-apply-path.ts +152 -0
  74. package/src/concatenate-space-apply-inputs.ts +2 -2
  75. package/src/detect-space-contract-drift.ts +22 -26
  76. package/src/{emit-pinned-space-artefacts.ts → emit-contract-space-artefacts.ts} +14 -33
  77. package/src/errors.ts +11 -5
  78. package/src/exports/aggregate.ts +37 -0
  79. package/src/exports/errors.ts +1 -0
  80. package/src/exports/io.ts +1 -0
  81. package/src/exports/spaces.ts +23 -10
  82. package/src/gather-disk-contract-space-state.ts +62 -0
  83. package/src/invariants.ts +14 -3
  84. package/src/io.ts +42 -0
  85. package/src/plan-all-spaces.ts +3 -7
  86. package/src/read-contract-space-contract.ts +44 -0
  87. package/src/read-contract-space-head-ref.ts +63 -0
  88. package/src/space-layout.ts +4 -11
  89. package/src/verify-contract-spaces.ts +45 -49
  90. package/dist/errors-DQsXvidG.mjs.map +0 -1
  91. package/dist/exports/migration-graph.mjs.map +0 -1
  92. package/dist/graph-Czaj8O2q.d.mts.map +0 -1
  93. package/dist/hash-G0bAfIGh.mjs.map +0 -1
  94. package/dist/invariants-4Avb_Yhy.mjs.map +0 -1
  95. package/dist/io-CDJaWGbt.mjs.map +0 -1
  96. package/dist/package-B3Yl6DTr.d.mts.map +0 -1
  97. package/src/read-pinned-contract-hash.ts +0 -77
  98. /package/dist/{metadata-CSjwljJx.d.mts → metadata-BnLFiI6B.d.mts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"spaces.d.mts","names":[],"sources":["../../src/concatenate-space-apply-inputs.ts","../../src/detect-space-contract-drift.ts","../../src/emit-pinned-space-artefacts.ts","../../src/plan-all-spaces.ts","../../src/read-pinned-contract-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0BA;;;;ACzDA;AAyBA;AA8BA;;;;ACjDA;AAMA;AAkCA;AACkC,iBEVlB,uBAAA,CFUkB,oBAAA,EAAA,MAAA,EAAA,OAAA,EAAA,MAAA,CAAA,EAAA,MAAA;;;;;;AHnClC;AAsCA;;;;;;;;;AC5CA;AAyBA;AA0BA;;;iBKzCsB,0BAAA,gCAEnB;AJlBH;AAyBA;AA8BA;;;;ACjDiB,UGqDA,qBAAA,CHrDc;EAMd,SAAA,IAAA,EAAA,MAAe;EAkChB,SAAA,UAAa,EAAA,SAAA,MAAA,EAAA;;;;;;;AAGjB,UGoBK,iBAAA,CHpBL;EAAe,SAAA,IAAA,EAAA,MAAA;;;UGyBV,0BAAA;EF9CK;;;;AC1BtB;AAWA;AAIA;EAoBgB,SAAA,YAAA,EC6CS,WD7Cc,CAAA,MAAA,CAAA;;;;ACrBvC;AA2CA;EAUiB,SAAA,gBAAiB,EAAA,SAAA,MAAA,EAAA;EAKjB;;;;;;;EAiCL,SAAA,mBAAsB,EATF,WASE,CAAA,MAAA,EATkB,qBASlB,CAAA;EA+BtB;AAqCZ;;;8BAvE8B,oBAAoB;;KAGtC,sBAAA;;;;;;;;;;;;;;;;;;;;;;;;;KA+BA,0BAAA;;;;gCAE4C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmCxC,oBAAA,SACN,6BACP"}
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/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;EAAA;;;;;AA+BX;;EA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BAAA,CACd,MAAA,EAAQ,0BAAA,GACP,0BAAA;;;;;;AN/KH;;;UOIiB,sBAAA;EPHN;EAAA,SOKA,eAAA;EPHA;EAAA,SOKA,eAAA,EAAiB,WAAA,SAAoB,uBAAA;AAAA;;;AP0BhD;;;;;;;;AClBA;;;;;;;;iBMasB,4BAAA,CAA6B,IAAA;EAAA,SACxC,oBAAA;;;;ALvBX;;WK6BW,cAAA,EAAgB,WAAA;AAAA,IACvB,OAAA,CAAQ,sBAAA;;;;;;;APrCZ;;;;;;;;;UQMiB,cAAA;EAAA,SACN,OAAA;EAAA,SACA,aAAA,EAAe,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"}
@@ -1,142 +1,115 @@
1
- import { S as errorPinnedArtefactsAppSpace, f as errorInvalidRefFile, g as errorInvalidSpaceId, l as errorInvalidJson, o as errorDuplicateSpaceId } from "../errors-DQsXvidG.mjs";
2
- import { r as canonicalizeJson } from "../hash-G0bAfIGh.mjs";
3
- import "../invariants-4Avb_Yhy.mjs";
4
- import { t as MANIFEST_FILE } from "../io-CDJaWGbt.mjs";
1
+ import { r as errorDescriptorHeadHashMismatch, s as errorDuplicateSpaceId } from "../errors-EPL_9p9f.mjs";
2
+ import { r as canonicalizeJson } from "../hash-By50zM_E.mjs";
3
+ import { s as readMigrationsDir } from "../io-D13dLvUh.mjs";
4
+ import "../constants-DWV9_o2Z.mjs";
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-C3-1eyaI.mjs";
5
7
  import { join } from "pathe";
6
- import { mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
7
- import { APP_SPACE_ID } from "@prisma-next/framework-components/control";
8
-
9
- //#region src/space-layout.ts
10
- /**
11
- * Pattern a contract-space identifier must match. The constraint is
12
- * filesystem-friendly: lowercase letters / digits / hyphen / underscore,
13
- * starts with a letter, max 64 characters.
14
- *
15
- * @see specs/framework-mechanism.spec.md § 3.
16
- */
17
- const SPACE_ID_PATTERN = /^[a-z][a-z0-9_-]{0,63}$/;
18
- function isValidSpaceId(spaceId) {
19
- return SPACE_ID_PATTERN.test(spaceId);
20
- }
21
- function assertValidSpaceId(spaceId) {
22
- if (!isValidSpaceId(spaceId)) throw errorInvalidSpaceId(spaceId);
23
- }
8
+ import { mkdir, writeFile } from "node:fs/promises";
9
+ import { computeStorageHash } from "@prisma-next/contract/hashing";
10
+ //#region src/assert-descriptor-self-consistency.ts
24
11
  /**
25
- * Resolve the migrations subdirectory for a given contract space.
26
- *
27
- * - **App space** (`spaceId === APP_SPACE_ID`) keeps today's layout: the
28
- * project's `migrations/` directory is the migrations directory, no
29
- * subdirectory.
30
- * - **Extension space** lands under `<projectMigrationsDir>/<spaceId>/`.
31
- * The space id is validated against {@link SPACE_ID_PATTERN} because
32
- * it becomes a filesystem directory name verbatim.
33
- *
34
- * `projectMigrationsDir` is the project's top-level `migrations/`
35
- * directory; the helper does not assume anything about its absolute /
36
- * relative shape and is symmetric with `pathe.join`.
12
+ * Assert that an extension descriptor is self-consistent: the
13
+ * `headRef.hash` it publishes must match the canonical hash recomputed
14
+ * from its `contractSpace.contractJson`.
15
+ *
16
+ * Recomputes via {@link computeStorageHash} — the same canonical-JSON
17
+ * pipeline the descriptor's own emit pipeline produced the hash with —
18
+ * over `(target, targetFamily, storage)`. Mismatch indicates the
19
+ * extension author bumped `contractJson` without rerunning emit, leaving
20
+ * the descriptor's `headRef.hash` stale; the consumer-side helpers
21
+ * (drift detection, on-disk artefact emission, runner marker writes) all
22
+ * trust `headRef.hash` as the canonical identity, so a stale value would
23
+ * silently corrupt every downstream boundary.
24
+ *
25
+ * Synchronous, pure, no I/O. Throws
26
+ * `MIGRATION.DESCRIPTOR_HEAD_HASH_MISMATCH` on failure with both the
27
+ * recomputed and published hashes in `details` so callers can surface a
28
+ * clear remediation hint without re-deriving them.
37
29
  */
38
- function spaceMigrationDirectory(projectMigrationsDir, spaceId) {
39
- if (spaceId === APP_SPACE_ID) return projectMigrationsDir;
40
- assertValidSpaceId(spaceId);
41
- return join(projectMigrationsDir, spaceId);
42
- }
43
-
44
- //#endregion
45
- //#region src/concatenate-space-apply-inputs.ts
46
- /**
47
- * Order a set of per-space apply inputs into the canonical cross-space
48
- * sequence the runner applies under a single transaction.
49
- *
50
- * Cross-space ordering convention (sub-spec § 4):
51
- *
52
- * 1. **Extension spaces first**, alphabetically by `spaceId`.
53
- * 2. **App space last** — only one `'app'` entry expected, at most.
54
- *
55
- * Rationale: extensions install their own structural objects (types,
56
- * functions, helper tables) before the app's structural ops reference
57
- * them. Putting app-space last lets app-space ops freely depend on any
58
- * extension-space declaration in the same transaction.
59
- *
60
- * Determinism (NFR6): the output order is independent of the input
61
- * order, so two callers with the same set of `extensionPacks` produce
62
- * identical apply sequences.
63
- *
64
- * Atomicity: rejects duplicate `spaceId`s with
65
- * `MIGRATION.DUPLICATE_SPACE_ID` before producing any output. This
66
- * mirrors {@link import('./plan-all-spaces').planAllSpaces} so the
67
- * planner-side and runner-side helpers reject malformed inputs the same
68
- * way (callers don't need a separate dedup pass).
69
- *
70
- * Synchronous, pure, no I/O: callers resolve marker rows and `path`
71
- * before invoking this helper. The actual DB application — driving the
72
- * transaction, committing marker writes, recording the per-space marker
73
- * rows — happens at the SQL-family consumption site (per the
74
- * helper-location convention from R3).
75
- */
76
- function concatenateSpaceApplyInputs(inputs) {
77
- const seen = /* @__PURE__ */ new Set();
78
- for (const input of inputs) {
79
- if (seen.has(input.spaceId)) throw errorDuplicateSpaceId(input.spaceId);
80
- seen.add(input.spaceId);
81
- }
82
- const extensions = [];
83
- let appSpace;
84
- for (const input of inputs) if (input.spaceId === APP_SPACE_ID) appSpace = input;
85
- else extensions.push(input);
86
- extensions.sort((a, b) => {
87
- if (a.spaceId < b.spaceId) return -1;
88
- if (a.spaceId > b.spaceId) return 1;
89
- return 0;
30
+ function assertDescriptorSelfConsistency(inputs) {
31
+ const { storageHash: _stripped, ...storageWithoutHash } = inputs.storage;
32
+ const recomputed = computeStorageHash({
33
+ target: inputs.target,
34
+ targetFamily: inputs.targetFamily,
35
+ storage: storageWithoutHash
36
+ });
37
+ if (recomputed !== inputs.headRefHash) throw errorDescriptorHeadHashMismatch({
38
+ extensionId: inputs.extensionId,
39
+ recomputedHash: recomputed,
40
+ headRefHash: inputs.headRefHash
90
41
  });
91
- return appSpace ? [...extensions, appSpace] : extensions;
92
42
  }
93
-
94
43
  //#endregion
95
- //#region src/detect-space-contract-drift.ts
44
+ //#region src/compute-extension-space-apply-path.ts
96
45
  /**
97
- * Pure drift-detection primitive for a single contract space.
98
- *
99
- * Runs once per loaded extension space, just before computing the
100
- * `priorContract` that feeds {@link import('./plan-all-spaces').planAllSpaces}.
101
- * Hash equality is byte-for-byte (no normalisation) — both sides are
102
- * already canonical hashes produced by the same pipeline, so any
103
- * difference is meaningful drift.
46
+ * Compute the apply path for an extension contract space — the shortest
47
+ * sequence of on-disk migration packages that walks the live marker
48
+ * forward to the on-disk head ref hash, covering every required
49
+ * invariant.
104
50
  *
105
- * Synchronous, pure, no I/O. The caller (SQL family in M2 R1) reads
106
- * the pinned `contract.json` and computes its hash, then invokes this
107
- * helper alongside the descriptor's `headRef.hash`. Composes naturally
108
- * with {@link import('./read-pinned-contract-hash').readPinnedContractHash}
109
- * which provides the read-side primitive.
51
+ * Reads only on-disk artefacts (`migrations/<spaceId>/refs/head.json`
52
+ * and the per-space migration packages). **Does not import any
53
+ * extension descriptor module** `db init` / `db update` must remain
54
+ * runnable without the descriptor source on disk.
110
55
  *
111
- * @see specs/framework-mechanism.spec.md § 3 — Drift detection (T1.9).
112
- * @see specs/framework-mechanism.spec.md AM7 drift warning surfaces
113
- * the extension name and the diff direction.
56
+ * Behaviour:
57
+ * - Returns `{ kind: 'ok', pathOps: [], … }` when the marker is already
58
+ * at the recorded head and no required invariants are missing.
59
+ * - Returns `{ kind: 'unreachable' }` when the marker hash is not
60
+ * structurally connected to the recorded head in the graph.
61
+ * - Returns `{ kind: 'unsatisfiable', missing, … }` when the marker is
62
+ * reachable but no path covers the required invariants.
63
+ * - Returns `{ kind: 'contractSpaceHeadRefMissing' }` when the per-space
64
+ * `refs/head.json` is absent — the precheck verifier should already
65
+ * have rejected this case, but the helper is defensive so callers can
66
+ * surface a coherent error rather than throw.
114
67
  */
115
- function detectSpaceContractDrift(spaceId, inputs) {
116
- if (inputs.pinnedHash === null) return {
117
- kind: "firstEmit",
118
- spaceId,
119
- descriptorHash: inputs.descriptorHash,
120
- pinnedHash: null
68
+ async function computeExtensionSpaceApplyPath(inputs) {
69
+ const { projectMigrationsDir, spaceId, currentMarkerHash, currentMarkerInvariants } = inputs;
70
+ const contractSpaceHeadRef = await readContractSpaceHeadRef(projectMigrationsDir, spaceId);
71
+ if (contractSpaceHeadRef === null) return { kind: "contractSpaceHeadRefMissing" };
72
+ const packages = await readMigrationsDir(spaceMigrationDirectory(projectMigrationsDir, spaceId));
73
+ const graph = reconstructGraph(packages);
74
+ const fromHash = currentMarkerHash ?? "sha256:empty";
75
+ const required = new Set(contractSpaceHeadRef.invariants.filter((id) => !currentMarkerInvariants.includes(id)));
76
+ const outcome = findPathWithDecision(graph, fromHash, contractSpaceHeadRef.hash, { required });
77
+ if (outcome.kind === "unreachable") return {
78
+ kind: "unreachable",
79
+ contractSpaceHeadRef
121
80
  };
122
- if (inputs.descriptorHash === inputs.pinnedHash) return {
123
- kind: "noDrift",
124
- spaceId,
125
- descriptorHash: inputs.descriptorHash,
126
- pinnedHash: inputs.pinnedHash
81
+ if (outcome.kind === "unsatisfiable") return {
82
+ kind: "unsatisfiable",
83
+ contractSpaceHeadRef,
84
+ missing: outcome.missing,
85
+ structuralPath: outcome.structuralPath.map(({ dirName, to }) => ({
86
+ dirName,
87
+ to
88
+ }))
127
89
  };
90
+ const packagesByHash = new Map(packages.map((pkg) => [pkg.metadata.migrationHash, pkg]));
91
+ const pathOps = [];
92
+ const walkedMigrationDirs = [];
93
+ const providedInvariantsSet = /* @__PURE__ */ new Set();
94
+ for (const edge of outcome.decision.selectedPath) {
95
+ const pkg = packagesByHash.get(edge.migrationHash);
96
+ if (!pkg) throw new Error(`Migration package missing for edge ${edge.migrationHash} in space "${spaceId}"`);
97
+ walkedMigrationDirs.push(pkg.dirName);
98
+ for (const op of pkg.ops) pathOps.push(op);
99
+ for (const invariant of pkg.metadata.providedInvariants) providedInvariantsSet.add(invariant);
100
+ }
128
101
  return {
129
- kind: "drift",
130
- spaceId,
131
- descriptorHash: inputs.descriptorHash,
132
- pinnedHash: inputs.pinnedHash
102
+ kind: "ok",
103
+ contractSpaceHeadRef,
104
+ providedInvariants: [...providedInvariantsSet].sort(),
105
+ pathOps,
106
+ walkedMigrationDirs
133
107
  };
134
108
  }
135
-
136
109
  //#endregion
137
- //#region src/emit-pinned-space-artefacts.ts
110
+ //#region src/emit-contract-space-artefacts.ts
138
111
  /**
139
- * Emit the pinned per-space artefacts (`contract.json`, `contract.d.ts`,
112
+ * Emit the per-space artefacts (`contract.json`, `contract.d.ts`,
140
113
  * `refs/head.json`) under `<projectMigrationsDir>/<spaceId>/`.
141
114
  *
142
115
  * Always-overwrite: the framework owns these files; running `migrate`
@@ -144,23 +117,16 @@ function detectSpaceContractDrift(spaceId, inputs) {
144
117
  * helper does not check pre-existing contents — re-emit always wins.
145
118
  *
146
119
  * Path layout matches the convention in
147
- * [`spaceMigrationDirectory`](./space-layout.ts), with two restrictions
148
- * specific to pinned artefacts:
149
- *
150
- * - Rejects the app space (`spaceId === APP_SPACE_ID`): the app space's
151
- * canonical `contract.json` lives at the project root, not under
152
- * `migrations/`. Callers that want to emit it use the app-space
153
- * contract emit pipeline.
154
- * - Validates `spaceId` against `[a-z][a-z0-9_-]{0,63}` via
155
- * {@link assertValidSpaceId} for the same filesystem-safety reasons.
120
+ * [`spaceMigrationDirectory`](./space-layout.ts). The space id is
121
+ * validated against `[a-z][a-z0-9_-]{0,63}` via
122
+ * {@link assertValidSpaceId} for filesystem-safety reasons; the helper
123
+ * accepts every space uniformly (including the app space, default
124
+ * `'app'`).
156
125
  *
157
126
  * The migrations directory and space subdirectory are created if they
158
127
  * do not yet exist (`mkdir { recursive: true }`).
159
- *
160
- * @see specs/framework-mechanism.spec.md § 3 — Pinned artefact emission (T1.8).
161
128
  */
162
- async function emitPinnedSpaceArtefacts(projectMigrationsDir, spaceId, inputs) {
163
- if (spaceId === APP_SPACE_ID) throw errorPinnedArtefactsAppSpace();
129
+ async function emitContractSpaceArtefacts(projectMigrationsDir, spaceId, inputs) {
164
130
  assertValidSpaceId(spaceId);
165
131
  const dir = join(projectMigrationsDir, spaceId);
166
132
  await mkdir(join(dir, "refs"), { recursive: true });
@@ -173,7 +139,40 @@ async function emitPinnedSpaceArtefacts(projectMigrationsDir, spaceId, inputs) {
173
139
  });
174
140
  await writeFile(join(dir, "refs", "head.json"), `${headJson}\n`);
175
141
  }
176
-
142
+ //#endregion
143
+ //#region src/gather-disk-contract-space-state.ts
144
+ /**
145
+ * Read the on-disk state the per-space verifier needs:
146
+ *
147
+ * - The list of contract-space directories under
148
+ * `<projectMigrationsDir>/` (via
149
+ * {@link import('./verify-contract-spaces').listContractSpaceDirectories}).
150
+ * - The on-disk head ref `(hash, invariants)` for each declared extension space
151
+ * (via {@link readContractSpaceHeadRef}; missing on-disk artefacts are simply
152
+ * omitted — the verifier reports them as `declaredButUnmigrated`).
153
+ *
154
+ * Synchronous in spirit but async due to filesystem reads. Reads only
155
+ * the user's repo. **Does not import any extension descriptor module.**
156
+ *
157
+ * Composition convention: pure target-agnostic primitive in
158
+ * `1-framework`; the SQL family (and any future target family) wires
159
+ * it into its `dbInit` / `verify` flows alongside its own marker-row
160
+ * read before invoking `verifyContractSpaces`.
161
+ */
162
+ async function gatherDiskContractSpaceState(args) {
163
+ const { projectMigrationsDir, loadedSpaceIds } = args;
164
+ const spaceDirsOnDisk = await listContractSpaceDirectories(projectMigrationsDir);
165
+ const headRefsBySpace = /* @__PURE__ */ new Map();
166
+ for (const spaceId of loadedSpaceIds) {
167
+ if (spaceId === APP_SPACE_ID) continue;
168
+ const head = await readContractSpaceHeadRef(projectMigrationsDir, spaceId);
169
+ if (head !== null) headRefsBySpace.set(spaceId, head);
170
+ }
171
+ return {
172
+ spaceDirsOnDisk,
173
+ headRefsBySpace
174
+ };
175
+ }
177
176
  //#endregion
178
177
  //#region src/plan-all-spaces.ts
179
178
  /**
@@ -182,7 +181,7 @@ async function emitPinnedSpaceArtefacts(projectMigrationsDir, spaceId, inputs) {
182
181
  *
183
182
  * Behaviour:
184
183
  *
185
- * - The output is sorted alphabetically by `spaceId` (AM3). Two callers
184
+ * - The output is sorted alphabetically by `spaceId`. Two callers
186
185
  * passing the same set of inputs in different orders observe
187
186
  * byte-identical outputs.
188
187
  * - The per-space planner (`planSpace`) is called exactly once per
@@ -199,11 +198,9 @@ async function emitPinnedSpaceArtefacts(projectMigrationsDir, spaceId, inputs) {
199
198
  *
200
199
  * Synchronous: the underlying per-space planner (target's
201
200
  * `MigrationPlanner.plan(...)`) is synchronous; callers that need to
202
- * resolve async I/O (e.g. reading pinned `contract.json` from disk)
201
+ * resolve async I/O (e.g. reading on-disk `contract.json` from disk)
203
202
  * resolve it before calling `planAllSpaces` and pass the materialised
204
203
  * inputs through.
205
- *
206
- * @see specs/framework-mechanism.spec.md § 3 — Per-space planner (T1.3).
207
204
  */
208
205
  function planAllSpaces(inputs, planSpace) {
209
206
  const seen = /* @__PURE__ */ new Set();
@@ -220,214 +217,7 @@ function planAllSpaces(inputs, planSpace) {
220
217
  migrationPackages: planSpace(input)
221
218
  }));
222
219
  }
223
-
224
- //#endregion
225
- //#region src/read-pinned-contract-hash.ts
226
- function hasErrnoCode$1(error, code) {
227
- return error instanceof Error && error.code === code;
228
- }
229
- /**
230
- * Read the pinned head hash for an extension space.
231
- *
232
- * Returns the `hash` field of `<projectMigrationsDir>/<spaceId>/refs/head.json`
233
- * — i.e. the canonical contract hash the framework wrote on the last
234
- * `migrate` for this space. Returns `null` when the file does not exist
235
- * (or the migrations directory is missing entirely), which is the
236
- * "first emit" signal {@link import('./detect-space-contract-drift').detectSpaceContractDrift}
237
- * uses to distinguish a brand-new extension from drift.
238
- *
239
- * Pure I/O (read + parse). The "comparison hash" is stored on disk by
240
- * {@link import('./emit-pinned-space-artefacts').emitPinnedSpaceArtefacts}
241
- * via the descriptor's `headRef.hash`, so reading it back here matches
242
- * the descriptor's hashing pipeline by construction — neither side
243
- * recomputes anything.
244
- *
245
- * Validation:
246
- *
247
- * - Rejects the app space — pinned head refs are an extension-space
248
- * concept; the app space's contract-of-record lives at the project
249
- * root, not under `migrations/`.
250
- * - Validates the space id against the same `[a-z][a-z0-9_-]{0,63}`
251
- * pattern as the rest of the per-space helpers.
252
- * - Surfaces `MIGRATION.INVALID_JSON` / `MIGRATION.INVALID_REF_FILE`
253
- * on a corrupt `refs/head.json` so callers can distinguish "no
254
- * pinned file" (returns `null`) from "pinned file but unreadable"
255
- * (throws).
256
- *
257
- * @see specs/framework-mechanism.spec.md § 3 — Drift detection (T1.9).
258
- */
259
- async function readPinnedContractHash(projectMigrationsDir, spaceId) {
260
- if (spaceId === APP_SPACE_ID) throw errorPinnedArtefactsAppSpace();
261
- assertValidSpaceId(spaceId);
262
- const filePath = join(projectMigrationsDir, spaceId, "refs", "head.json");
263
- let raw;
264
- try {
265
- raw = await readFile(filePath, "utf-8");
266
- } catch (error) {
267
- if (hasErrnoCode$1(error, "ENOENT")) return null;
268
- throw error;
269
- }
270
- let parsed;
271
- try {
272
- parsed = JSON.parse(raw);
273
- } catch (e) {
274
- throw errorInvalidJson(filePath, e instanceof Error ? e.message : String(e));
275
- }
276
- if (typeof parsed !== "object" || parsed === null || typeof parsed.hash !== "string") throw errorInvalidRefFile(filePath, "expected an object with a string `hash` field");
277
- return parsed.hash;
278
- }
279
-
280
220
  //#endregion
281
- //#region src/verify-contract-spaces.ts
282
- function hasErrnoCode(error, code) {
283
- return error instanceof Error && error.code === code;
284
- }
285
- /**
286
- * List the per-space pinned subdirectories under
287
- * `<projectRoot>/migrations/`. Returns space-id directory names (sorted
288
- * alphabetically) — i.e. any non-dot-prefixed subdirectory whose root
289
- * does **not** contain a `migration.json` manifest. The manifest is the
290
- * structural marker of a user-authored migration directory (see
291
- * `readMigrationsDir` in `./io`); directory names themselves belong to
292
- * the user and are not part of the contract.
293
- *
294
- * Returns `[]` if the migrations directory does not exist (greenfield
295
- * project).
296
- *
297
- * Reads only the user's repo. **No descriptor import.** The caller
298
- * (verifier) feeds the result into {@link verifyContractSpaces} alongside
299
- * the loaded-space set and the marker rows.
300
- *
301
- * @see specs/framework-mechanism.spec.md § 4 — Verifier (steps 5–6).
302
- */
303
- async function listPinnedSpaceDirectories(projectMigrationsDir) {
304
- let entries;
305
- try {
306
- entries = (await readdir(projectMigrationsDir, { withFileTypes: true })).map((d) => ({
307
- name: d.name,
308
- isDirectory: d.isDirectory()
309
- }));
310
- } catch (error) {
311
- if (hasErrnoCode(error, "ENOENT")) return [];
312
- throw error;
313
- }
314
- const namedCandidates = entries.filter((e) => e.isDirectory).map((e) => e.name).filter((name) => !name.startsWith(".")).sort();
315
- return (await Promise.all(namedCandidates.map(async (name) => {
316
- try {
317
- await stat(join(projectMigrationsDir, name, MANIFEST_FILE));
318
- return {
319
- name,
320
- isMigrationDir: true
321
- };
322
- } catch (error) {
323
- if (hasErrnoCode(error, "ENOENT")) return {
324
- name,
325
- isMigrationDir: false
326
- };
327
- throw error;
328
- }
329
- }))).filter((c) => !c.isMigrationDir).map((c) => c.name);
330
- }
331
- /**
332
- * Pure structural verifier for the per-space mechanism. Aggregates the
333
- * three orphan / missing checks (FR6 cases a–c) plus per-space hash and
334
- * invariant comparison.
335
- *
336
- * Algorithm (sub-spec § 4):
337
- *
338
- * - For every extension space declared in `loadedSpaces` (`'app'`
339
- * excluded — its pinned `contract.json` lives at the project root):
340
- * - If no pinned dir on disk → `declaredButUnmigrated`.
341
- * - Else if `markerRowsBySpace` lacks an entry → no violation here;
342
- * the live-DB compare in step 8 (out of scope of this helper) is
343
- * where the absence shows up.
344
- * - Else compare marker hash / invariants vs. pinned hash /
345
- * invariants → `hashMismatch` / `invariantsMismatch` on drift.
346
- * - For every pinned dir on disk that is not in `loadedSpaces` →
347
- * `orphanPinnedDir`.
348
- * - For every marker row whose `space` is not in `loadedSpaces` →
349
- * `orphanMarker`. The app-space marker is always loaded (`'app'` is
350
- * in `loadedSpaces` by definition).
351
- *
352
- * Output is deterministic (NFR6): violations are sorted first by `kind`
353
- * (`declaredButUnmigrated` → `orphanMarker` → `orphanPinnedDir` →
354
- * `hashMismatch` → `invariantsMismatch`) then by `spaceId`. Two callers
355
- * passing equivalent inputs see byte-identical violation lists.
356
- *
357
- * Synchronous, pure, no I/O. **Does not import the extension descriptor**
358
- * (the inputs are pre-resolved by the caller). This is the property
359
- * AC-15 / AC-26 ("verifier reads only the user repo, not
360
- * `node_modules`") locks in.
361
- *
362
- * @see specs/framework-mechanism.spec.md § 4 — Verifier (T1.5).
363
- */
364
- function verifyContractSpaces(inputs) {
365
- const violations = [];
366
- for (const spaceId of [...inputs.loadedSpaces].sort()) {
367
- if (spaceId === APP_SPACE_ID) continue;
368
- if (!inputs.pinnedDirsOnDisk.includes(spaceId)) {
369
- violations.push({
370
- kind: "declaredButUnmigrated",
371
- spaceId,
372
- remediation: `Extension '${spaceId}' is declared in extensionPacks but has not been emitted; run \`prisma-next migrate\`.`
373
- });
374
- continue;
375
- }
376
- const pinned = inputs.pinnedHashesBySpace.get(spaceId);
377
- const marker = inputs.markerRowsBySpace.get(spaceId);
378
- if (!pinned || !marker) continue;
379
- if (pinned.hash !== marker.hash) {
380
- violations.push({
381
- kind: "hashMismatch",
382
- spaceId,
383
- pinnedHash: pinned.hash,
384
- markerHash: marker.hash,
385
- remediation: `Marker row for space '${spaceId}' is keyed at ${marker.hash}, but the pinned ${join("migrations", spaceId, "contract.json")} resolves to ${pinned.hash}. Run \`prisma-next db update\` to advance the database, or \`prisma-next migrate\` if the descriptor was bumped without re-emitting.`
386
- });
387
- continue;
388
- }
389
- const pinnedInvariants = [...pinned.invariants].sort();
390
- const markerInvariants = new Set(marker.invariants);
391
- const missing = pinnedInvariants.filter((id) => !markerInvariants.has(id));
392
- if (missing.length > 0) violations.push({
393
- kind: "invariantsMismatch",
394
- spaceId,
395
- pinnedInvariants,
396
- markerInvariants: [...marker.invariants].sort(),
397
- 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.`
398
- });
399
- }
400
- for (const dir of [...inputs.pinnedDirsOnDisk].sort()) if (!inputs.loadedSpaces.has(dir)) violations.push({
401
- kind: "orphanPinnedDir",
402
- spaceId: dir,
403
- remediation: `Orphan pinned directory \`${join("migrations", dir)}/\` for an extension not in extensionPacks; remove the directory or re-add the extension.`
404
- });
405
- for (const space of [...inputs.markerRowsBySpace.keys()].sort()) if (!inputs.loadedSpaces.has(space)) violations.push({
406
- kind: "orphanMarker",
407
- spaceId: space,
408
- remediation: `Orphan marker row for space '${space}' (no longer in extensionPacks); remediation: manually delete the row from \`prisma_contract.marker\`.`
409
- });
410
- if (violations.length === 0) return { ok: true };
411
- const kindOrder = {
412
- declaredButUnmigrated: 0,
413
- orphanMarker: 1,
414
- orphanPinnedDir: 2,
415
- hashMismatch: 3,
416
- invariantsMismatch: 4
417
- };
418
- violations.sort((a, b) => {
419
- const k = kindOrder[a.kind] - kindOrder[b.kind];
420
- if (k !== 0) return k;
421
- if (a.spaceId < b.spaceId) return -1;
422
- if (a.spaceId > b.spaceId) return 1;
423
- return 0;
424
- });
425
- return {
426
- ok: false,
427
- violations
428
- };
429
- }
221
+ export { APP_SPACE_ID, assertDescriptorSelfConsistency, assertValidSpaceId, computeExtensionSpaceApplyPath, detectSpaceContractDrift, emitContractSpaceArtefacts, gatherDiskContractSpaceState, isValidSpaceId, listContractSpaceDirectories, planAllSpaces, readContractSpaceContract, readContractSpaceHeadRef, spaceMigrationDirectory, verifyContractSpaces };
430
222
 
431
- //#endregion
432
- export { APP_SPACE_ID, assertValidSpaceId, concatenateSpaceApplyInputs, detectSpaceContractDrift, emitPinnedSpaceArtefacts, isValidSpaceId, listPinnedSpaceDirectories, planAllSpaces, readPinnedContractHash, spaceMigrationDirectory, verifyContractSpaces };
433
223
  //# sourceMappingURL=spaces.mjs.map