@prisma-next/migration-tools 0.5.0-dev.67 → 0.5.0-dev.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{errors-5KVuWV_5.mjs → errors-EPL_9p9f.mjs} +12 -6
- package/dist/errors-EPL_9p9f.mjs.map +1 -0
- package/dist/exports/aggregate.d.mts +534 -0
- package/dist/exports/aggregate.d.mts.map +1 -0
- package/dist/exports/aggregate.mjs +598 -0
- package/dist/exports/aggregate.mjs.map +1 -0
- package/dist/exports/errors.d.mts +6 -1
- package/dist/exports/errors.d.mts.map +1 -1
- package/dist/exports/errors.mjs +2 -2
- package/dist/exports/graph.d.mts +1 -1
- package/dist/exports/hash.d.mts +1 -1
- package/dist/exports/invariants.d.mts +13 -2
- package/dist/exports/invariants.d.mts.map +1 -1
- package/dist/exports/invariants.mjs +1 -1
- package/dist/exports/io.d.mts +25 -1
- package/dist/exports/io.d.mts.map +1 -1
- package/dist/exports/io.mjs +2 -2
- package/dist/exports/metadata.d.mts +1 -1
- package/dist/exports/migration-graph.d.mts +1 -1
- package/dist/exports/migration-graph.mjs +1 -522
- package/dist/exports/migration.d.mts +1 -1
- package/dist/exports/migration.mjs +2 -2
- package/dist/exports/refs.mjs +1 -1
- package/dist/exports/spaces.d.mts +341 -237
- package/dist/exports/spaces.d.mts.map +1 -1
- package/dist/exports/spaces.mjs +137 -339
- package/dist/exports/spaces.mjs.map +1 -1
- package/dist/{graph-4dIUm90i.d.mts → graph-HMWAldoR.d.mts} +1 -1
- package/dist/{graph-4dIUm90i.d.mts.map → graph-HMWAldoR.d.mts.map} +1 -1
- package/dist/{invariants-CkLSBcMu.mjs → invariants-Duc8f9NM.mjs} +16 -5
- package/dist/invariants-Duc8f9NM.mjs.map +1 -0
- package/dist/{io-TX8RPDeh.mjs → io-D13dLvUh.mjs} +38 -4
- package/dist/io-D13dLvUh.mjs.map +1 -0
- package/dist/migration-graph-DGNnKDY5.mjs +523 -0
- package/dist/{exports/migration-graph.mjs.map → migration-graph-DGNnKDY5.mjs.map} +1 -1
- package/dist/read-contract-space-contract-C3-1eyaI.mjs +298 -0
- package/dist/read-contract-space-contract-C3-1eyaI.mjs.map +1 -0
- package/package.json +10 -6
- package/src/aggregate/loader.ts +409 -0
- package/src/aggregate/marker-types.ts +16 -0
- package/src/aggregate/planner-types.ts +137 -0
- package/src/aggregate/planner.ts +158 -0
- package/src/aggregate/project-schema-to-space.ts +64 -0
- package/src/aggregate/strategies/graph-walk.ts +92 -0
- package/src/aggregate/strategies/synth.ts +122 -0
- package/src/aggregate/types.ts +89 -0
- package/src/aggregate/verifier.ts +230 -0
- package/src/assert-descriptor-self-consistency.ts +70 -0
- package/src/compute-extension-space-apply-path.ts +152 -0
- package/src/concatenate-space-apply-inputs.ts +2 -2
- package/src/detect-space-contract-drift.ts +22 -26
- package/src/{emit-pinned-space-artefacts.ts → emit-contract-space-artefacts.ts} +14 -33
- package/src/errors.ts +11 -5
- package/src/exports/aggregate.ts +37 -0
- package/src/exports/errors.ts +1 -0
- package/src/exports/io.ts +1 -0
- package/src/exports/spaces.ts +23 -10
- package/src/gather-disk-contract-space-state.ts +62 -0
- package/src/invariants.ts +14 -3
- package/src/io.ts +42 -0
- package/src/plan-all-spaces.ts +3 -7
- package/src/read-contract-space-contract.ts +44 -0
- package/src/read-contract-space-head-ref.ts +63 -0
- package/src/space-layout.ts +4 -11
- package/src/verify-contract-spaces.ts +45 -49
- package/dist/errors-5KVuWV_5.mjs.map +0 -1
- package/dist/invariants-CkLSBcMu.mjs.map +0 -1
- package/dist/io-TX8RPDeh.mjs.map +0 -1
- package/src/read-pinned-contract-hash.ts +0 -77
- /package/dist/{metadata-th_MvOTT.d.mts → metadata-BnLFiI6B.d.mts} +0 -0
|
@@ -1,5 +1,147 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as MigrationOps } from "../package-BjiZ7KDy.mjs";
|
|
2
|
+
import { APP_SPACE_ID, ContractSpaceHeadRef } from "@prisma-next/framework-components/control";
|
|
2
3
|
|
|
4
|
+
//#region src/assert-descriptor-self-consistency.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Inputs the helper needs to recompute the descriptor's storage hash and
|
|
7
|
+
* compare it to the published `headRef.hash`. Kept structural so the SQL
|
|
8
|
+
* family (and any future target family) can compose the check without
|
|
9
|
+
* coupling to its own descriptor types.
|
|
10
|
+
*/
|
|
11
|
+
interface DescriptorSelfConsistencyInputs {
|
|
12
|
+
readonly extensionId: string;
|
|
13
|
+
readonly target: string;
|
|
14
|
+
readonly targetFamily: string;
|
|
15
|
+
/**
|
|
16
|
+
* Family-specific storage object. Typed as `unknown` so callers can
|
|
17
|
+
* pass their own narrow storage shape (e.g. `SqlStorage`) without an
|
|
18
|
+
* inline cast — the helper canonicalises through `JSON.stringify`
|
|
19
|
+
* inside {@link computeStorageHash} and only requires a plain
|
|
20
|
+
* record-shaped value at runtime.
|
|
21
|
+
*/
|
|
22
|
+
readonly storage: unknown;
|
|
23
|
+
readonly headRefHash: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Assert that an extension descriptor is self-consistent: the
|
|
27
|
+
* `headRef.hash` it publishes must match the canonical hash recomputed
|
|
28
|
+
* from its `contractSpace.contractJson`.
|
|
29
|
+
*
|
|
30
|
+
* Recomputes via {@link computeStorageHash} — the same canonical-JSON
|
|
31
|
+
* pipeline the descriptor's own emit pipeline produced the hash with —
|
|
32
|
+
* over `(target, targetFamily, storage)`. Mismatch indicates the
|
|
33
|
+
* extension author bumped `contractJson` without rerunning emit, leaving
|
|
34
|
+
* the descriptor's `headRef.hash` stale; the consumer-side helpers
|
|
35
|
+
* (drift detection, on-disk artefact emission, runner marker writes) all
|
|
36
|
+
* trust `headRef.hash` as the canonical identity, so a stale value would
|
|
37
|
+
* silently corrupt every downstream boundary.
|
|
38
|
+
*
|
|
39
|
+
* Synchronous, pure, no I/O. Throws
|
|
40
|
+
* `MIGRATION.DESCRIPTOR_HEAD_HASH_MISMATCH` on failure with both the
|
|
41
|
+
* recomputed and published hashes in `details` so callers can surface a
|
|
42
|
+
* clear remediation hint without re-deriving them.
|
|
43
|
+
*/
|
|
44
|
+
declare function assertDescriptorSelfConsistency(inputs: DescriptorSelfConsistencyInputs): void;
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/read-contract-space-head-ref.d.ts
|
|
47
|
+
/**
|
|
48
|
+
* Read the head ref (`hash` + `invariants`) for a contract space from
|
|
49
|
+
* `<projectMigrationsDir>/<spaceId>/refs/head.json`.
|
|
50
|
+
*
|
|
51
|
+
* Returns `null` when the file does not exist (first emit). Surfaces
|
|
52
|
+
* `MIGRATION.INVALID_JSON` / `MIGRATION.INVALID_REF_FILE` on a corrupt
|
|
53
|
+
* `refs/head.json` so callers can distinguish "no head ref on disk"
|
|
54
|
+
* (returns `null`) from "head ref present but unreadable" (throws).
|
|
55
|
+
*
|
|
56
|
+
* Validates the space id against `[a-z][a-z0-9_-]{0,63}` for the same
|
|
57
|
+
* filesystem-safety reasons as the rest of the per-space helpers. The
|
|
58
|
+
* helper is uniform across the app and extension spaces.
|
|
59
|
+
*/
|
|
60
|
+
declare function readContractSpaceHeadRef(projectMigrationsDir: string, spaceId: string): Promise<ContractSpaceHeadRef | null>;
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/compute-extension-space-apply-path.d.ts
|
|
63
|
+
/**
|
|
64
|
+
* Outcome of {@link computeExtensionSpaceApplyPath} — a discriminated union
|
|
65
|
+
* mirroring {@link import('./migration-graph').FindPathOutcome} so callers
|
|
66
|
+
* can map structural / invariant failures to their preferred CLI envelope
|
|
67
|
+
* without re-running pathfinding.
|
|
68
|
+
*/
|
|
69
|
+
type ExtensionSpaceApplyPathOutcome = {
|
|
70
|
+
readonly kind: 'ok';
|
|
71
|
+
readonly contractSpaceHeadRef: ContractSpaceHeadRef;
|
|
72
|
+
/**
|
|
73
|
+
* Sorted, deduplicated invariant ids covered by the walked path.
|
|
74
|
+
* Mirrors the on-disk `providedInvariants` summed across edges and
|
|
75
|
+
* canonicalised — what the runner stamps on the marker after apply.
|
|
76
|
+
*/
|
|
77
|
+
readonly providedInvariants: readonly string[];
|
|
78
|
+
/**
|
|
79
|
+
* Path operations in apply order. Empty when the marker is already
|
|
80
|
+
* at the recorded head (no-op).
|
|
81
|
+
*/
|
|
82
|
+
readonly pathOps: MigrationOps;
|
|
83
|
+
/**
|
|
84
|
+
* Migration directory names walked, in order. Mirrors `pathOps`'s
|
|
85
|
+
* structure but at the package granularity — useful for surfacing
|
|
86
|
+
* "applied N migration(s)" messages.
|
|
87
|
+
*/
|
|
88
|
+
readonly walkedMigrationDirs: readonly string[];
|
|
89
|
+
} | {
|
|
90
|
+
readonly kind: 'unreachable';
|
|
91
|
+
readonly contractSpaceHeadRef: ContractSpaceHeadRef;
|
|
92
|
+
} | {
|
|
93
|
+
readonly kind: 'unsatisfiable';
|
|
94
|
+
readonly contractSpaceHeadRef: ContractSpaceHeadRef;
|
|
95
|
+
readonly missing: readonly string[];
|
|
96
|
+
readonly structuralPath: readonly {
|
|
97
|
+
readonly dirName: string;
|
|
98
|
+
readonly to: string;
|
|
99
|
+
}[];
|
|
100
|
+
} | {
|
|
101
|
+
readonly kind: 'contractSpaceHeadRefMissing';
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Inputs to {@link computeExtensionSpaceApplyPath}. The helper is
|
|
105
|
+
* deliberately framework-neutral and consumes only on-disk state:
|
|
106
|
+
*
|
|
107
|
+
* - `projectMigrationsDir` is the project's top-level `migrations/` dir.
|
|
108
|
+
* - `spaceId` selects the per-space subdirectory under it.
|
|
109
|
+
* - `currentMarkerHash` / `currentMarkerInvariants` come from the live
|
|
110
|
+
* marker row keyed by `space = <spaceId>`. `null` hash = no marker yet
|
|
111
|
+
* (the pathfinder treats this as the empty-contract sentinel per ADR
|
|
112
|
+
* 208).
|
|
113
|
+
*/
|
|
114
|
+
interface ComputeExtensionSpaceApplyPathInputs {
|
|
115
|
+
readonly projectMigrationsDir: string;
|
|
116
|
+
readonly spaceId: string;
|
|
117
|
+
readonly currentMarkerHash: string | null;
|
|
118
|
+
readonly currentMarkerInvariants: readonly string[];
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Compute the apply path for an extension contract space — the shortest
|
|
122
|
+
* sequence of on-disk migration packages that walks the live marker
|
|
123
|
+
* forward to the on-disk head ref hash, covering every required
|
|
124
|
+
* invariant.
|
|
125
|
+
*
|
|
126
|
+
* Reads only on-disk artefacts (`migrations/<spaceId>/refs/head.json`
|
|
127
|
+
* and the per-space migration packages). **Does not import any
|
|
128
|
+
* extension descriptor module** — `db init` / `db update` must remain
|
|
129
|
+
* runnable without the descriptor source on disk.
|
|
130
|
+
*
|
|
131
|
+
* Behaviour:
|
|
132
|
+
* - Returns `{ kind: 'ok', pathOps: [], … }` when the marker is already
|
|
133
|
+
* at the recorded head and no required invariants are missing.
|
|
134
|
+
* - Returns `{ kind: 'unreachable' }` when the marker hash is not
|
|
135
|
+
* structurally connected to the recorded head in the graph.
|
|
136
|
+
* - Returns `{ kind: 'unsatisfiable', missing, … }` when the marker is
|
|
137
|
+
* reachable but no path covers the required invariants.
|
|
138
|
+
* - Returns `{ kind: 'contractSpaceHeadRefMissing' }` when the per-space
|
|
139
|
+
* `refs/head.json` is absent — the precheck verifier should already
|
|
140
|
+
* have rejected this case, but the helper is defensive so callers can
|
|
141
|
+
* surface a coherent error rather than throw.
|
|
142
|
+
*/
|
|
143
|
+
declare function computeExtensionSpaceApplyPath(inputs: ComputeExtensionSpaceApplyPathInputs): Promise<ExtensionSpaceApplyPathOutcome>;
|
|
144
|
+
//#endregion
|
|
3
145
|
//#region src/concatenate-space-apply-inputs.d.ts
|
|
4
146
|
/**
|
|
5
147
|
* Per-space input the runner consumes when applying a migration.
|
|
@@ -10,8 +152,8 @@ import { APP_SPACE_ID } from "@prisma-next/framework-components/control";
|
|
|
10
152
|
* and the helper preserves it through the concatenation.
|
|
11
153
|
*
|
|
12
154
|
* - `migrationDirectory` is the on-disk migration directory for the
|
|
13
|
-
* space — `<projectRoot>/migrations
|
|
14
|
-
*
|
|
155
|
+
* space — `<projectRoot>/migrations/<space-id>` (uniform; the app
|
|
156
|
+
* subspaces under its own `<APP_SPACE_ID>/` directory).
|
|
15
157
|
* - `currentMarkerHash` and `currentMarkerInvariants` are the values
|
|
16
158
|
* read from the `prisma_contract.marker` row keyed by `space = <space-id>`
|
|
17
159
|
* (T1.1). `null` hash = no marker row yet.
|
|
@@ -28,37 +170,6 @@ interface SpaceApplyInput<TOp> {
|
|
|
28
170
|
readonly currentMarkerInvariants: readonly string[];
|
|
29
171
|
readonly path: readonly TOp[];
|
|
30
172
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Order a set of per-space apply inputs into the canonical cross-space
|
|
33
|
-
* sequence the runner applies under a single transaction.
|
|
34
|
-
*
|
|
35
|
-
* Cross-space ordering convention (sub-spec § 4):
|
|
36
|
-
*
|
|
37
|
-
* 1. **Extension spaces first**, alphabetically by `spaceId`.
|
|
38
|
-
* 2. **App space last** — only one `'app'` entry expected, at most.
|
|
39
|
-
*
|
|
40
|
-
* Rationale: extensions install their own structural objects (types,
|
|
41
|
-
* functions, helper tables) before the app's structural ops reference
|
|
42
|
-
* them. Putting app-space last lets app-space ops freely depend on any
|
|
43
|
-
* extension-space declaration in the same transaction.
|
|
44
|
-
*
|
|
45
|
-
* Determinism (NFR6): the output order is independent of the input
|
|
46
|
-
* order, so two callers with the same set of `extensionPacks` produce
|
|
47
|
-
* identical apply sequences.
|
|
48
|
-
*
|
|
49
|
-
* Atomicity: rejects duplicate `spaceId`s with
|
|
50
|
-
* `MIGRATION.DUPLICATE_SPACE_ID` before producing any output. This
|
|
51
|
-
* mirrors {@link import('./plan-all-spaces').planAllSpaces} so the
|
|
52
|
-
* planner-side and runner-side helpers reject malformed inputs the same
|
|
53
|
-
* way (callers don't need a separate dedup pass).
|
|
54
|
-
*
|
|
55
|
-
* Synchronous, pure, no I/O: callers resolve marker rows and `path`
|
|
56
|
-
* before invoking this helper. The actual DB application — driving the
|
|
57
|
-
* transaction, committing marker writes, recording the per-space marker
|
|
58
|
-
* rows — happens at the SQL-family consumption site (per the
|
|
59
|
-
* helper-location convention from R3).
|
|
60
|
-
*/
|
|
61
|
-
declare function concatenateSpaceApplyInputs<TOp>(inputs: readonly SpaceApplyInput<TOp>[]): readonly SpaceApplyInput<TOp>[];
|
|
62
173
|
//#endregion
|
|
63
174
|
//#region src/detect-space-contract-drift.d.ts
|
|
64
175
|
/**
|
|
@@ -71,42 +182,40 @@ declare function concatenateSpaceApplyInputs<TOp>(inputs: readonly SpaceApplyInp
|
|
|
71
182
|
* family speaks its own contract type, and both reduce to a hash string
|
|
72
183
|
* before drift detection runs.
|
|
73
184
|
*
|
|
74
|
-
* `
|
|
185
|
+
* `priorHeadHash` is `null` when no `contract.json` exists yet on disk for
|
|
75
186
|
* the space (the descriptor declares an extension that has never been
|
|
76
187
|
* emitted into the user's repo). That's the "first emit" case — no
|
|
77
|
-
* drift to surface; the migrate emit will create the
|
|
78
|
-
*
|
|
79
|
-
* @see specs/framework-mechanism.spec.md § 3 — Drift detection (T1.9).
|
|
188
|
+
* drift to surface; the migrate emit will create the on-disk artefacts.
|
|
80
189
|
*/
|
|
81
190
|
interface DetectSpaceContractDriftInputs {
|
|
82
191
|
readonly descriptorHash: string;
|
|
83
|
-
readonly
|
|
192
|
+
readonly priorHeadHash: string | null;
|
|
84
193
|
}
|
|
85
194
|
/**
|
|
86
195
|
* Result discriminant for {@link detectSpaceContractDrift}.
|
|
87
196
|
*
|
|
88
|
-
* - `noDrift`: descriptor hash and
|
|
197
|
+
* - `noDrift`: descriptor hash and on-disk head hash agree byte-for-byte.
|
|
89
198
|
* The migrate emit can proceed with no warning.
|
|
90
|
-
* - `firstEmit`: no
|
|
199
|
+
* - `firstEmit`: no on-disk `contract.json` on disk yet. The extension
|
|
91
200
|
* was just added to `extensionPacks`; this run will create the
|
|
92
|
-
*
|
|
93
|
-
* the extension, not to "drift" from a state they haven't
|
|
94
|
-
* - `drift`: descriptor hash differs from
|
|
201
|
+
* on-disk artefacts. No warning either — the user's intent is to install
|
|
202
|
+
* the extension, not to "drift" from a state they haven't recorded.
|
|
203
|
+
* - `drift`: descriptor hash differs from on-disk head hash. The caller
|
|
95
204
|
* surfaces a non-fatal warning naming the extension and the
|
|
96
|
-
* diff direction (descriptor →
|
|
205
|
+
* diff direction (descriptor → on-disk head). The migrate emit proceeds
|
|
97
206
|
* normally so the bump is materialised this run; the warning just
|
|
98
207
|
* confirms the bump is being captured.
|
|
99
208
|
*
|
|
100
|
-
* `spaceId`, `descriptorHash`, and `
|
|
209
|
+
* `spaceId`, `descriptorHash`, and `priorHeadHash` are threaded through
|
|
101
210
|
* verbatim so the caller (logger / TerminalUI / strict-mode envelope)
|
|
102
211
|
* has everything it needs to format the warning message without
|
|
103
|
-
* re-reading the descriptor or the
|
|
212
|
+
* re-reading the descriptor or the on-disk artefact.
|
|
104
213
|
*/
|
|
105
214
|
type SpaceContractDriftResult = {
|
|
106
215
|
readonly kind: 'noDrift' | 'firstEmit' | 'drift';
|
|
107
216
|
readonly spaceId: string;
|
|
108
217
|
readonly descriptorHash: string;
|
|
109
|
-
readonly
|
|
218
|
+
readonly priorHeadHash: string | null;
|
|
110
219
|
};
|
|
111
220
|
/**
|
|
112
221
|
* Pure drift-detection primitive for a single contract space.
|
|
@@ -117,30 +226,19 @@ type SpaceContractDriftResult = {
|
|
|
117
226
|
* already canonical hashes produced by the same pipeline, so any
|
|
118
227
|
* difference is meaningful drift.
|
|
119
228
|
*
|
|
120
|
-
* Synchronous, pure, no I/O. The caller (SQL family
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
229
|
+
* Synchronous, pure, no I/O. The caller (SQL family) reads the on-disk
|
|
230
|
+
* `contract.json` and computes its hash, then invokes this helper
|
|
231
|
+
* alongside the descriptor's `headRef.hash`. Composes naturally with
|
|
232
|
+
* {@link import('./read-contract-space-head-ref').readContractSpaceHeadRef}
|
|
124
233
|
* which provides the read-side primitive.
|
|
125
234
|
*
|
|
126
|
-
*
|
|
127
|
-
* @see specs/framework-mechanism.spec.md AM7 — drift warning surfaces
|
|
128
|
-
* the extension name and the diff direction.
|
|
235
|
+
* The drift warning surfaces the extension name and the diff direction.
|
|
129
236
|
*/
|
|
130
237
|
declare function detectSpaceContractDrift(spaceId: string, inputs: DetectSpaceContractDriftInputs): SpaceContractDriftResult;
|
|
131
238
|
//#endregion
|
|
132
|
-
//#region src/emit-
|
|
239
|
+
//#region src/emit-contract-space-artefacts.d.ts
|
|
133
240
|
/**
|
|
134
|
-
*
|
|
135
|
-
* Mirrors {@link import('./refs').RefEntry} but is redeclared locally so
|
|
136
|
-
* callers can construct the input without depending on the refs module.
|
|
137
|
-
*/
|
|
138
|
-
interface PinnedSpaceHeadRef {
|
|
139
|
-
readonly hash: string;
|
|
140
|
-
readonly invariants: readonly string[];
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Inputs for {@link emitPinnedSpaceArtefacts}.
|
|
241
|
+
* Inputs for {@link emitContractSpaceArtefacts}.
|
|
144
242
|
*
|
|
145
243
|
* - `contract` is the canonical contract value the framework just emitted
|
|
146
244
|
* for the space; it is serialised through {@link canonicalizeJson}, so
|
|
@@ -154,18 +252,18 @@ interface PinnedSpaceHeadRef {
|
|
|
154
252
|
* needs), so this helper accepts the text verbatim and writes it out
|
|
155
253
|
* without further transformation.
|
|
156
254
|
*
|
|
157
|
-
* - `headRef` is the
|
|
255
|
+
* - `headRef` is the head reference for the space.
|
|
158
256
|
* `invariants` are sorted alphabetically before serialisation so two
|
|
159
257
|
* callers passing the same set in different orders produce
|
|
160
258
|
* byte-identical `refs/head.json`.
|
|
161
259
|
*/
|
|
162
|
-
interface
|
|
260
|
+
interface ContractSpaceArtefactInputs {
|
|
163
261
|
readonly contract: unknown;
|
|
164
262
|
readonly contractDts: string;
|
|
165
|
-
readonly headRef:
|
|
263
|
+
readonly headRef: ContractSpaceHeadRef;
|
|
166
264
|
}
|
|
167
265
|
/**
|
|
168
|
-
* Emit the
|
|
266
|
+
* Emit the per-space artefacts (`contract.json`, `contract.d.ts`,
|
|
169
267
|
* `refs/head.json`) under `<projectMigrationsDir>/<spaceId>/`.
|
|
170
268
|
*
|
|
171
269
|
* Always-overwrite: the framework owns these files; running `migrate`
|
|
@@ -173,144 +271,20 @@ interface PinnedSpaceArtefactInputs {
|
|
|
173
271
|
* helper does not check pre-existing contents — re-emit always wins.
|
|
174
272
|
*
|
|
175
273
|
* Path layout matches the convention in
|
|
176
|
-
* [`spaceMigrationDirectory`](./space-layout.ts)
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* `migrations/`. Callers that want to emit it use the app-space
|
|
182
|
-
* contract emit pipeline.
|
|
183
|
-
* - Validates `spaceId` against `[a-z][a-z0-9_-]{0,63}` via
|
|
184
|
-
* {@link assertValidSpaceId} for the same filesystem-safety reasons.
|
|
274
|
+
* [`spaceMigrationDirectory`](./space-layout.ts). The space id is
|
|
275
|
+
* validated against `[a-z][a-z0-9_-]{0,63}` via
|
|
276
|
+
* {@link assertValidSpaceId} for filesystem-safety reasons; the helper
|
|
277
|
+
* accepts every space uniformly (including the app space, default
|
|
278
|
+
* `'app'`).
|
|
185
279
|
*
|
|
186
280
|
* The migrations directory and space subdirectory are created if they
|
|
187
281
|
* do not yet exist (`mkdir { recursive: true }`).
|
|
188
|
-
*
|
|
189
|
-
* @see specs/framework-mechanism.spec.md § 3 — Pinned artefact emission (T1.8).
|
|
190
282
|
*/
|
|
191
|
-
declare function
|
|
192
|
-
//#endregion
|
|
193
|
-
//#region src/plan-all-spaces.d.ts
|
|
194
|
-
/**
|
|
195
|
-
* Per-space input for {@link planAllSpaces}. One entry per loaded
|
|
196
|
-
* contract space (the application's `'app'` plus each extension that
|
|
197
|
-
* exposes a `contractSpace`).
|
|
198
|
-
*
|
|
199
|
-
* - `priorContract` is `null` for a space that has never been emitted
|
|
200
|
-
* (no `migrations/<space-id>/contract.json` on disk yet); otherwise it
|
|
201
|
-
* is the canonical contract value pinned for that space.
|
|
202
|
-
* - `newContract` is the canonical contract value the planner is about
|
|
203
|
-
* to emit for that space — for app-space, the just-emitted root
|
|
204
|
-
* `contract.json`; for an extension space, the descriptor's
|
|
205
|
-
* `contractSpace.contractJson`.
|
|
206
|
-
*
|
|
207
|
-
* @see specs/framework-mechanism.spec.md § 3.
|
|
208
|
-
*/
|
|
209
|
-
interface SpacePlanInput<TContract> {
|
|
210
|
-
readonly spaceId: string;
|
|
211
|
-
readonly priorContract: TContract | null;
|
|
212
|
-
readonly newContract: TContract;
|
|
213
|
-
}
|
|
214
|
-
interface SpacePlanOutput<TPackage> {
|
|
215
|
-
readonly spaceId: string;
|
|
216
|
-
readonly migrationPackages: readonly TPackage[];
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Iterate the per-space planner across a set of loaded contract spaces
|
|
220
|
-
* and return a deterministic shape regardless of declaration order.
|
|
221
|
-
*
|
|
222
|
-
* Behaviour:
|
|
223
|
-
*
|
|
224
|
-
* - The output is sorted alphabetically by `spaceId` (AM3). Two callers
|
|
225
|
-
* passing the same set of inputs in different orders observe
|
|
226
|
-
* byte-identical outputs.
|
|
227
|
-
* - The per-space planner (`planSpace`) is called exactly once per
|
|
228
|
-
* input, in alphabetical-by-spaceId order. Its return value is
|
|
229
|
-
* attached to the corresponding output entry verbatim.
|
|
230
|
-
* - Duplicate `spaceId`s in the input array throw
|
|
231
|
-
* `MIGRATION.DUPLICATE_SPACE_ID` before any `planSpace` call runs,
|
|
232
|
-
* keeping the planner pure when the input is malformed.
|
|
233
|
-
*
|
|
234
|
-
* The signature is generic over `TContract` and `TPackage` because the
|
|
235
|
-
* shape is framework-neutral (SQL family today, Mongo family
|
|
236
|
-
* eventually). Callers wire in whatever contract value and migration
|
|
237
|
-
* package shape their family already speaks.
|
|
238
|
-
*
|
|
239
|
-
* Synchronous: the underlying per-space planner (target's
|
|
240
|
-
* `MigrationPlanner.plan(...)`) is synchronous; callers that need to
|
|
241
|
-
* resolve async I/O (e.g. reading pinned `contract.json` from disk)
|
|
242
|
-
* resolve it before calling `planAllSpaces` and pass the materialised
|
|
243
|
-
* inputs through.
|
|
244
|
-
*
|
|
245
|
-
* @see specs/framework-mechanism.spec.md § 3 — Per-space planner (T1.3).
|
|
246
|
-
*/
|
|
247
|
-
declare function planAllSpaces<TContract, TPackage>(inputs: readonly SpacePlanInput<TContract>[], planSpace: (input: SpacePlanInput<TContract>) => readonly TPackage[]): readonly SpacePlanOutput<TPackage>[];
|
|
248
|
-
//#endregion
|
|
249
|
-
//#region src/read-pinned-contract-hash.d.ts
|
|
250
|
-
/**
|
|
251
|
-
* Read the pinned head hash for an extension space.
|
|
252
|
-
*
|
|
253
|
-
* Returns the `hash` field of `<projectMigrationsDir>/<spaceId>/refs/head.json`
|
|
254
|
-
* — i.e. the canonical contract hash the framework wrote on the last
|
|
255
|
-
* `migrate` for this space. Returns `null` when the file does not exist
|
|
256
|
-
* (or the migrations directory is missing entirely), which is the
|
|
257
|
-
* "first emit" signal {@link import('./detect-space-contract-drift').detectSpaceContractDrift}
|
|
258
|
-
* uses to distinguish a brand-new extension from drift.
|
|
259
|
-
*
|
|
260
|
-
* Pure I/O (read + parse). The "comparison hash" is stored on disk by
|
|
261
|
-
* {@link import('./emit-pinned-space-artefacts').emitPinnedSpaceArtefacts}
|
|
262
|
-
* via the descriptor's `headRef.hash`, so reading it back here matches
|
|
263
|
-
* the descriptor's hashing pipeline by construction — neither side
|
|
264
|
-
* recomputes anything.
|
|
265
|
-
*
|
|
266
|
-
* Validation:
|
|
267
|
-
*
|
|
268
|
-
* - Rejects the app space — pinned head refs are an extension-space
|
|
269
|
-
* concept; the app space's contract-of-record lives at the project
|
|
270
|
-
* root, not under `migrations/`.
|
|
271
|
-
* - Validates the space id against the same `[a-z][a-z0-9_-]{0,63}`
|
|
272
|
-
* pattern as the rest of the per-space helpers.
|
|
273
|
-
* - Surfaces `MIGRATION.INVALID_JSON` / `MIGRATION.INVALID_REF_FILE`
|
|
274
|
-
* on a corrupt `refs/head.json` so callers can distinguish "no
|
|
275
|
-
* pinned file" (returns `null`) from "pinned file but unreadable"
|
|
276
|
-
* (throws).
|
|
277
|
-
*
|
|
278
|
-
* @see specs/framework-mechanism.spec.md § 3 — Drift detection (T1.9).
|
|
279
|
-
*/
|
|
280
|
-
declare function readPinnedContractHash(projectMigrationsDir: string, spaceId: string): Promise<string | null>;
|
|
281
|
-
//#endregion
|
|
282
|
-
//#region src/space-layout.d.ts
|
|
283
|
-
/**
|
|
284
|
-
* Branded string carrying a compile-time guarantee that the value has
|
|
285
|
-
* been validated by {@link assertValidSpaceId}. Downstream filesystem
|
|
286
|
-
* helpers (e.g. {@link spaceMigrationDirectory}) accept this type to
|
|
287
|
-
* make "validated" tracking visible at the type level rather than
|
|
288
|
-
* relying purely on a runtime check.
|
|
289
|
-
*/
|
|
290
|
-
type ValidSpaceId = string & {
|
|
291
|
-
readonly __brand: 'ValidSpaceId';
|
|
292
|
-
};
|
|
293
|
-
declare function isValidSpaceId(spaceId: string): spaceId is ValidSpaceId;
|
|
294
|
-
declare function assertValidSpaceId(spaceId: string): asserts spaceId is ValidSpaceId;
|
|
295
|
-
/**
|
|
296
|
-
* Resolve the migrations subdirectory for a given contract space.
|
|
297
|
-
*
|
|
298
|
-
* - **App space** (`spaceId === APP_SPACE_ID`) keeps today's layout: the
|
|
299
|
-
* project's `migrations/` directory is the migrations directory, no
|
|
300
|
-
* subdirectory.
|
|
301
|
-
* - **Extension space** lands under `<projectMigrationsDir>/<spaceId>/`.
|
|
302
|
-
* The space id is validated against {@link SPACE_ID_PATTERN} because
|
|
303
|
-
* it becomes a filesystem directory name verbatim.
|
|
304
|
-
*
|
|
305
|
-
* `projectMigrationsDir` is the project's top-level `migrations/`
|
|
306
|
-
* directory; the helper does not assume anything about its absolute /
|
|
307
|
-
* relative shape and is symmetric with `pathe.join`.
|
|
308
|
-
*/
|
|
309
|
-
declare function spaceMigrationDirectory(projectMigrationsDir: string, spaceId: string): string;
|
|
283
|
+
declare function emitContractSpaceArtefacts(projectMigrationsDir: string, spaceId: string, inputs: ContractSpaceArtefactInputs): Promise<void>;
|
|
310
284
|
//#endregion
|
|
311
285
|
//#region src/verify-contract-spaces.d.ts
|
|
312
286
|
/**
|
|
313
|
-
* List the per-space
|
|
287
|
+
* List the per-space subdirectories under
|
|
314
288
|
* `<projectRoot>/migrations/`. Returns space-id directory names (sorted
|
|
315
289
|
* alphabetically) — i.e. any non-dot-prefixed subdirectory whose root
|
|
316
290
|
* does **not** contain a `migration.json` manifest. The manifest is the
|
|
@@ -324,24 +298,22 @@ declare function spaceMigrationDirectory(projectMigrationsDir: string, spaceId:
|
|
|
324
298
|
* Reads only the user's repo. **No descriptor import.** The caller
|
|
325
299
|
* (verifier) feeds the result into {@link verifyContractSpaces} alongside
|
|
326
300
|
* the loaded-space set and the marker rows.
|
|
327
|
-
*
|
|
328
|
-
* @see specs/framework-mechanism.spec.md § 4 — Verifier (steps 5–6).
|
|
329
301
|
*/
|
|
330
|
-
declare function
|
|
302
|
+
declare function listContractSpaceDirectories(projectMigrationsDir: string): Promise<readonly string[]>;
|
|
331
303
|
/**
|
|
332
|
-
*
|
|
304
|
+
* On-disk head value (`(hash, invariants)`) for one contract space.
|
|
333
305
|
* The verifier compares this against the marker row for the same space
|
|
334
306
|
* to detect drift between the user-emitted artefacts and the live DB
|
|
335
307
|
* marker.
|
|
336
308
|
*/
|
|
337
|
-
interface
|
|
309
|
+
interface ContractSpaceHeadRecord {
|
|
338
310
|
readonly hash: string;
|
|
339
311
|
readonly invariants: readonly string[];
|
|
340
312
|
}
|
|
341
313
|
/**
|
|
342
314
|
* Marker row read from `prisma_contract.marker` (one per `space`).
|
|
343
|
-
* Caller resolves these via the family runtime's marker reader
|
|
344
|
-
*
|
|
315
|
+
* Caller resolves these via the family runtime's marker reader before
|
|
316
|
+
* invoking {@link verifyContractSpaces}.
|
|
345
317
|
*/
|
|
346
318
|
interface SpaceMarkerRecord {
|
|
347
319
|
readonly hash: string;
|
|
@@ -357,19 +329,19 @@ interface VerifyContractSpacesInputs {
|
|
|
357
329
|
*/
|
|
358
330
|
readonly loadedSpaces: ReadonlySet<string>;
|
|
359
331
|
/**
|
|
360
|
-
*
|
|
332
|
+
* Per-space subdirectories observed under
|
|
361
333
|
* `<projectRoot>/migrations/`. Resolved via
|
|
362
|
-
* {@link
|
|
334
|
+
* {@link listContractSpaceDirectories}.
|
|
363
335
|
*/
|
|
364
|
-
readonly
|
|
336
|
+
readonly spaceDirsOnDisk: readonly string[];
|
|
365
337
|
/**
|
|
366
|
-
*
|
|
338
|
+
* Head ref per space, keyed by space id. Caller reads
|
|
367
339
|
* `<projectRoot>/migrations/<space-id>/contract.json` and
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
340
|
+
* `<projectRoot>/migrations/<space-id>/refs/head.json` to construct
|
|
341
|
+
* this map. Spaces with no contract-space dir on disk simply omit a
|
|
342
|
+
* map entry.
|
|
371
343
|
*/
|
|
372
|
-
readonly
|
|
344
|
+
readonly headRefsBySpace: ReadonlyMap<string, ContractSpaceHeadRecord>;
|
|
373
345
|
/**
|
|
374
346
|
* Marker rows keyed by `space`. Caller reads them from the
|
|
375
347
|
* `prisma_contract.marker` table.
|
|
@@ -385,19 +357,19 @@ type SpaceVerifierViolation = {
|
|
|
385
357
|
readonly spaceId: string;
|
|
386
358
|
readonly remediation: string;
|
|
387
359
|
} | {
|
|
388
|
-
readonly kind: '
|
|
360
|
+
readonly kind: 'orphanSpaceDir';
|
|
389
361
|
readonly spaceId: string;
|
|
390
362
|
readonly remediation: string;
|
|
391
363
|
} | {
|
|
392
364
|
readonly kind: 'hashMismatch';
|
|
393
365
|
readonly spaceId: string;
|
|
394
|
-
readonly
|
|
366
|
+
readonly priorHeadHash: string;
|
|
395
367
|
readonly markerHash: string;
|
|
396
368
|
readonly remediation: string;
|
|
397
369
|
} | {
|
|
398
370
|
readonly kind: 'invariantsMismatch';
|
|
399
371
|
readonly spaceId: string;
|
|
400
|
-
readonly
|
|
372
|
+
readonly onDiskInvariants: readonly string[];
|
|
401
373
|
readonly markerInvariants: readonly string[];
|
|
402
374
|
readonly remediation: string;
|
|
403
375
|
};
|
|
@@ -409,38 +381,170 @@ type VerifyContractSpacesResult = {
|
|
|
409
381
|
};
|
|
410
382
|
/**
|
|
411
383
|
* Pure structural verifier for the per-space mechanism. Aggregates the
|
|
412
|
-
* three orphan / missing checks
|
|
413
|
-
*
|
|
384
|
+
* three orphan / missing checks plus per-space hash and invariant
|
|
385
|
+
* comparison.
|
|
414
386
|
*
|
|
415
|
-
* Algorithm
|
|
387
|
+
* Algorithm:
|
|
416
388
|
*
|
|
417
389
|
* - For every extension space declared in `loadedSpaces` (`'app'`
|
|
418
|
-
* excluded —
|
|
419
|
-
*
|
|
390
|
+
* excluded — the per-space verifier is scoped to extension members;
|
|
391
|
+
* the app is verified through the aggregate path):
|
|
392
|
+
* - If no contract-space dir on disk → `declaredButUnmigrated`.
|
|
420
393
|
* - Else if `markerRowsBySpace` lacks an entry → no violation here;
|
|
421
|
-
* the live-DB compare
|
|
422
|
-
*
|
|
423
|
-
* - Else compare marker hash / invariants vs.
|
|
394
|
+
* the live-DB compare done outside this helper is where the
|
|
395
|
+
* absence shows up.
|
|
396
|
+
* - Else compare marker hash / invariants vs. on-disk head hash /
|
|
424
397
|
* invariants → `hashMismatch` / `invariantsMismatch` on drift.
|
|
425
|
-
* - For every
|
|
426
|
-
* `
|
|
398
|
+
* - For every contract-space dir on disk that is not in `loadedSpaces` →
|
|
399
|
+
* `orphanSpaceDir`.
|
|
427
400
|
* - For every marker row whose `space` is not in `loadedSpaces` →
|
|
428
401
|
* `orphanMarker`. The app-space marker is always loaded (`'app'` is
|
|
429
402
|
* in `loadedSpaces` by definition).
|
|
430
403
|
*
|
|
431
|
-
* Output is deterministic
|
|
432
|
-
* (`declaredButUnmigrated` → `orphanMarker` → `
|
|
404
|
+
* Output is deterministic: violations are sorted first by `kind`
|
|
405
|
+
* (`declaredButUnmigrated` → `orphanMarker` → `orphanSpaceDir` →
|
|
433
406
|
* `hashMismatch` → `invariantsMismatch`) then by `spaceId`. Two callers
|
|
434
407
|
* passing equivalent inputs see byte-identical violation lists.
|
|
435
408
|
*
|
|
436
409
|
* Synchronous, pure, no I/O. **Does not import the extension descriptor**
|
|
437
|
-
* (the inputs are pre-resolved by the caller)
|
|
438
|
-
*
|
|
439
|
-
* `node_modules`") locks in.
|
|
440
|
-
*
|
|
441
|
-
* @see specs/framework-mechanism.spec.md § 4 — Verifier (T1.5).
|
|
410
|
+
* (the inputs are pre-resolved by the caller); the verifier reads only
|
|
411
|
+
* the user repo, not `node_modules`.
|
|
442
412
|
*/
|
|
443
413
|
declare function verifyContractSpaces(inputs: VerifyContractSpacesInputs): VerifyContractSpacesResult;
|
|
444
414
|
//#endregion
|
|
445
|
-
|
|
415
|
+
//#region src/gather-disk-contract-space-state.d.ts
|
|
416
|
+
/**
|
|
417
|
+
* Disk-side inputs to {@link import('./verify-contract-spaces').verifyContractSpaces}
|
|
418
|
+
* — gathered without touching the live database. The caller composes
|
|
419
|
+
* this with the marker rows it reads from the runtime to invoke the
|
|
420
|
+
* verifier.
|
|
421
|
+
*/
|
|
422
|
+
interface DiskContractSpaceState {
|
|
423
|
+
/** Contract-space directory names observed under `<projectMigrationsDir>/`. */
|
|
424
|
+
readonly spaceDirsOnDisk: readonly string[];
|
|
425
|
+
/** Head-ref `(hash, invariants)` per extension space. */
|
|
426
|
+
readonly headRefsBySpace: ReadonlyMap<string, ContractSpaceHeadRecord>;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Read the on-disk state the per-space verifier needs:
|
|
430
|
+
*
|
|
431
|
+
* - The list of contract-space directories under
|
|
432
|
+
* `<projectMigrationsDir>/` (via
|
|
433
|
+
* {@link import('./verify-contract-spaces').listContractSpaceDirectories}).
|
|
434
|
+
* - The on-disk head ref `(hash, invariants)` for each declared extension space
|
|
435
|
+
* (via {@link readContractSpaceHeadRef}; missing on-disk artefacts are simply
|
|
436
|
+
* omitted — the verifier reports them as `declaredButUnmigrated`).
|
|
437
|
+
*
|
|
438
|
+
* Synchronous in spirit but async due to filesystem reads. Reads only
|
|
439
|
+
* the user's repo. **Does not import any extension descriptor module.**
|
|
440
|
+
*
|
|
441
|
+
* Composition convention: pure target-agnostic primitive in
|
|
442
|
+
* `1-framework`; the SQL family (and any future target family) wires
|
|
443
|
+
* it into its `dbInit` / `verify` flows alongside its own marker-row
|
|
444
|
+
* read before invoking `verifyContractSpaces`.
|
|
445
|
+
*/
|
|
446
|
+
declare function gatherDiskContractSpaceState(args: {
|
|
447
|
+
readonly projectMigrationsDir: string;
|
|
448
|
+
/**
|
|
449
|
+
* Set of space ids the project declares: `'app'` plus each entry in
|
|
450
|
+
* `extensionPacks` whose descriptor exposes a `contractSpace`. The
|
|
451
|
+
* helper reads on-disk head data only for the extension members.
|
|
452
|
+
*/
|
|
453
|
+
readonly loadedSpaceIds: ReadonlySet<string>;
|
|
454
|
+
}): Promise<DiskContractSpaceState>;
|
|
455
|
+
//#endregion
|
|
456
|
+
//#region src/plan-all-spaces.d.ts
|
|
457
|
+
/**
|
|
458
|
+
* Per-space input for {@link planAllSpaces}. One entry per loaded
|
|
459
|
+
* contract space (the application's `'app'` plus each extension that
|
|
460
|
+
* exposes a `contractSpace`).
|
|
461
|
+
*
|
|
462
|
+
* - `priorContract` is `null` for a space that has never been emitted
|
|
463
|
+
* (no `migrations/<space-id>/contract.json` on disk yet); otherwise it
|
|
464
|
+
* is the canonical contract value emitted for that space.
|
|
465
|
+
* - `newContract` is the canonical contract value the planner is about
|
|
466
|
+
* to emit for that space — for app-space, the just-emitted root
|
|
467
|
+
* `contract.json`; for an extension space, the descriptor's
|
|
468
|
+
* `contractSpace.contractJson`.
|
|
469
|
+
*/
|
|
470
|
+
interface SpacePlanInput<TContract> {
|
|
471
|
+
readonly spaceId: string;
|
|
472
|
+
readonly priorContract: TContract | null;
|
|
473
|
+
readonly newContract: TContract;
|
|
474
|
+
}
|
|
475
|
+
interface SpacePlanOutput<TPackage> {
|
|
476
|
+
readonly spaceId: string;
|
|
477
|
+
readonly migrationPackages: readonly TPackage[];
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Iterate the per-space planner across a set of loaded contract spaces
|
|
481
|
+
* and return a deterministic shape regardless of declaration order.
|
|
482
|
+
*
|
|
483
|
+
* Behaviour:
|
|
484
|
+
*
|
|
485
|
+
* - The output is sorted alphabetically by `spaceId`. Two callers
|
|
486
|
+
* passing the same set of inputs in different orders observe
|
|
487
|
+
* byte-identical outputs.
|
|
488
|
+
* - The per-space planner (`planSpace`) is called exactly once per
|
|
489
|
+
* input, in alphabetical-by-spaceId order. Its return value is
|
|
490
|
+
* attached to the corresponding output entry verbatim.
|
|
491
|
+
* - Duplicate `spaceId`s in the input array throw
|
|
492
|
+
* `MIGRATION.DUPLICATE_SPACE_ID` before any `planSpace` call runs,
|
|
493
|
+
* keeping the planner pure when the input is malformed.
|
|
494
|
+
*
|
|
495
|
+
* The signature is generic over `TContract` and `TPackage` because the
|
|
496
|
+
* shape is framework-neutral (SQL family today, Mongo family
|
|
497
|
+
* eventually). Callers wire in whatever contract value and migration
|
|
498
|
+
* package shape their family already speaks.
|
|
499
|
+
*
|
|
500
|
+
* Synchronous: the underlying per-space planner (target's
|
|
501
|
+
* `MigrationPlanner.plan(...)`) is synchronous; callers that need to
|
|
502
|
+
* resolve async I/O (e.g. reading on-disk `contract.json` from disk)
|
|
503
|
+
* resolve it before calling `planAllSpaces` and pass the materialised
|
|
504
|
+
* inputs through.
|
|
505
|
+
*/
|
|
506
|
+
declare function planAllSpaces<TContract, TPackage>(inputs: readonly SpacePlanInput<TContract>[], planSpace: (input: SpacePlanInput<TContract>) => readonly TPackage[]): readonly SpacePlanOutput<TPackage>[];
|
|
507
|
+
//#endregion
|
|
508
|
+
//#region src/read-contract-space-contract.d.ts
|
|
509
|
+
/**
|
|
510
|
+
* Read the on-disk contract value for a contract space
|
|
511
|
+
* (`<projectMigrationsDir>/<spaceId>/contract.json`). Returns the parsed
|
|
512
|
+
* JSON value as `unknown` — callers that need a typed contract validate
|
|
513
|
+
* via their family's `validateContract` to surface schema issues.
|
|
514
|
+
*
|
|
515
|
+
* Companion to {@link import('./read-contract-space-head-ref').readContractSpaceHeadRef}
|
|
516
|
+
* — same ENOENT-throws / corrupt-file-error semantics. Returns the
|
|
517
|
+
* canonical-JSON value the framework wrote during emit, so re-running
|
|
518
|
+
* this helper across machines / runs yields a byte-identical value.
|
|
519
|
+
*/
|
|
520
|
+
declare function readContractSpaceContract(projectMigrationsDir: string, spaceId: string): Promise<unknown>;
|
|
521
|
+
//#endregion
|
|
522
|
+
//#region src/space-layout.d.ts
|
|
523
|
+
/**
|
|
524
|
+
* Branded string carrying a compile-time guarantee that the value has
|
|
525
|
+
* been validated by {@link assertValidSpaceId}. Downstream filesystem
|
|
526
|
+
* helpers (e.g. {@link spaceMigrationDirectory}) accept this type to
|
|
527
|
+
* make "validated" tracking visible at the type level rather than
|
|
528
|
+
* relying purely on a runtime check.
|
|
529
|
+
*/
|
|
530
|
+
type ValidSpaceId = string & {
|
|
531
|
+
readonly __brand: 'ValidSpaceId';
|
|
532
|
+
};
|
|
533
|
+
declare function isValidSpaceId(spaceId: string): spaceId is ValidSpaceId;
|
|
534
|
+
declare function assertValidSpaceId(spaceId: string): asserts spaceId is ValidSpaceId;
|
|
535
|
+
/**
|
|
536
|
+
* Resolve the migrations subdirectory for a given contract space.
|
|
537
|
+
*
|
|
538
|
+
* Every contract space — including the app space (default `'app'`) —
|
|
539
|
+
* lands under `<projectMigrationsDir>/<spaceId>/`. The space id is
|
|
540
|
+
* validated against {@link SPACE_ID_PATTERN} because it becomes a
|
|
541
|
+
* filesystem directory name verbatim.
|
|
542
|
+
*
|
|
543
|
+
* `projectMigrationsDir` is the project's top-level `migrations/`
|
|
544
|
+
* directory; the helper does not assume anything about its absolute /
|
|
545
|
+
* relative shape and is symmetric with `pathe.join`.
|
|
546
|
+
*/
|
|
547
|
+
declare function spaceMigrationDirectory(projectMigrationsDir: string, spaceId: string): string;
|
|
548
|
+
//#endregion
|
|
549
|
+
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, detectSpaceContractDrift, emitContractSpaceArtefacts, gatherDiskContractSpaceState, isValidSpaceId, listContractSpaceDirectories, planAllSpaces, readContractSpaceContract, readContractSpaceHeadRef, spaceMigrationDirectory, verifyContractSpaces };
|
|
446
550
|
//# sourceMappingURL=spaces.d.mts.map
|