@prisma-next/migration-tools 0.5.0-dev.9 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/README.md +34 -22
  2. package/dist/{constants-BRi0X7B_.mjs → constants-DWV9_o2Z.mjs} +2 -2
  3. package/dist/{constants-BRi0X7B_.mjs.map → constants-DWV9_o2Z.mjs.map} +1 -1
  4. package/dist/errors-EPL_9p9f.mjs +297 -0
  5. package/dist/errors-EPL_9p9f.mjs.map +1 -0
  6. package/dist/exports/aggregate.d.mts +599 -0
  7. package/dist/exports/aggregate.d.mts.map +1 -0
  8. package/dist/exports/aggregate.mjs +599 -0
  9. package/dist/exports/aggregate.mjs.map +1 -0
  10. package/dist/exports/constants.d.mts.map +1 -1
  11. package/dist/exports/constants.mjs +2 -3
  12. package/dist/exports/errors.d.mts +68 -0
  13. package/dist/exports/errors.d.mts.map +1 -0
  14. package/dist/exports/errors.mjs +2 -0
  15. package/dist/exports/graph.d.mts +2 -0
  16. package/dist/exports/graph.mjs +1 -0
  17. package/dist/exports/hash.d.mts +52 -0
  18. package/dist/exports/hash.d.mts.map +1 -0
  19. package/dist/exports/hash.mjs +2 -0
  20. package/dist/exports/invariants.d.mts +39 -0
  21. package/dist/exports/invariants.d.mts.map +1 -0
  22. package/dist/exports/invariants.mjs +2 -0
  23. package/dist/exports/io.d.mts +66 -6
  24. package/dist/exports/io.d.mts.map +1 -1
  25. package/dist/exports/io.mjs +2 -3
  26. package/dist/exports/metadata.d.mts +2 -0
  27. package/dist/exports/metadata.mjs +1 -0
  28. package/dist/exports/migration-graph.d.mts +2 -0
  29. package/dist/exports/migration-graph.mjs +2 -0
  30. package/dist/exports/migration-ts.d.mts.map +1 -1
  31. package/dist/exports/migration-ts.mjs +2 -4
  32. package/dist/exports/migration-ts.mjs.map +1 -1
  33. package/dist/exports/migration.d.mts +15 -14
  34. package/dist/exports/migration.d.mts.map +1 -1
  35. package/dist/exports/migration.mjs +70 -43
  36. package/dist/exports/migration.mjs.map +1 -1
  37. package/dist/exports/package.d.mts +3 -0
  38. package/dist/exports/package.mjs +1 -0
  39. package/dist/exports/refs.d.mts.map +1 -1
  40. package/dist/exports/refs.mjs +3 -4
  41. package/dist/exports/refs.mjs.map +1 -1
  42. package/dist/exports/spaces.d.mts +526 -0
  43. package/dist/exports/spaces.d.mts.map +1 -0
  44. package/dist/exports/spaces.mjs +266 -0
  45. package/dist/exports/spaces.mjs.map +1 -0
  46. package/dist/graph-HMWAldoR.d.mts +28 -0
  47. package/dist/graph-HMWAldoR.d.mts.map +1 -0
  48. package/dist/hash-By50zM_E.mjs +74 -0
  49. package/dist/hash-By50zM_E.mjs.map +1 -0
  50. package/dist/invariants-qgQGlsrV.mjs +57 -0
  51. package/dist/invariants-qgQGlsrV.mjs.map +1 -0
  52. package/dist/io-D5YYptRO.mjs +239 -0
  53. package/dist/io-D5YYptRO.mjs.map +1 -0
  54. package/dist/metadata-CFvm3ayn.d.mts +2 -0
  55. package/dist/migration-graph-DGNnKDY5.mjs +523 -0
  56. package/dist/migration-graph-DGNnKDY5.mjs.map +1 -0
  57. package/dist/migration-graph-DulOITvG.d.mts +124 -0
  58. package/dist/migration-graph-DulOITvG.d.mts.map +1 -0
  59. package/dist/op-schema-D5qkXfEf.mjs +13 -0
  60. package/dist/op-schema-D5qkXfEf.mjs.map +1 -0
  61. package/dist/package-BjiZ7KDy.d.mts +21 -0
  62. package/dist/package-BjiZ7KDy.d.mts.map +1 -0
  63. package/dist/read-contract-space-contract-Cme8KZk_.mjs +259 -0
  64. package/dist/read-contract-space-contract-Cme8KZk_.mjs.map +1 -0
  65. package/package.json +42 -17
  66. package/src/aggregate/loader.ts +379 -0
  67. package/src/aggregate/marker-types.ts +16 -0
  68. package/src/aggregate/planner-types.ts +171 -0
  69. package/src/aggregate/planner.ts +159 -0
  70. package/src/aggregate/project-schema-to-space.ts +64 -0
  71. package/src/aggregate/strategies/graph-walk.ts +118 -0
  72. package/src/aggregate/strategies/synth.ts +122 -0
  73. package/src/aggregate/types.ts +89 -0
  74. package/src/aggregate/verifier.ts +230 -0
  75. package/src/assert-descriptor-self-consistency.ts +70 -0
  76. package/src/compute-extension-space-apply-path.ts +152 -0
  77. package/src/concatenate-space-apply-inputs.ts +90 -0
  78. package/src/contract-space-from-json.ts +63 -0
  79. package/src/emit-contract-space-artefacts.ts +70 -0
  80. package/src/errors.ts +251 -17
  81. package/src/exports/aggregate.ts +42 -0
  82. package/src/exports/errors.ts +8 -0
  83. package/src/exports/graph.ts +1 -0
  84. package/src/exports/hash.ts +2 -0
  85. package/src/exports/invariants.ts +1 -0
  86. package/src/exports/io.ts +3 -1
  87. package/src/exports/metadata.ts +1 -0
  88. package/src/exports/{dag.ts → migration-graph.ts} +3 -2
  89. package/src/exports/migration.ts +0 -1
  90. package/src/exports/package.ts +2 -0
  91. package/src/exports/spaces.ts +45 -0
  92. package/src/gather-disk-contract-space-state.ts +62 -0
  93. package/src/graph-ops.ts +57 -30
  94. package/src/graph.ts +25 -0
  95. package/src/hash.ts +91 -0
  96. package/src/invariants.ts +61 -0
  97. package/src/io.ts +163 -40
  98. package/src/metadata.ts +1 -0
  99. package/src/migration-base.ts +97 -56
  100. package/src/migration-graph.ts +676 -0
  101. package/src/op-schema.ts +11 -0
  102. package/src/package.ts +21 -0
  103. package/src/plan-all-spaces.ts +76 -0
  104. package/src/read-contract-space-contract.ts +44 -0
  105. package/src/read-contract-space-head-ref.ts +63 -0
  106. package/src/space-layout.ts +48 -0
  107. package/src/verify-contract-spaces.ts +272 -0
  108. package/dist/attestation-BnzTb0Qp.mjs +0 -65
  109. package/dist/attestation-BnzTb0Qp.mjs.map +0 -1
  110. package/dist/errors-BmiSgz1j.mjs +0 -160
  111. package/dist/errors-BmiSgz1j.mjs.map +0 -1
  112. package/dist/exports/attestation.d.mts +0 -37
  113. package/dist/exports/attestation.d.mts.map +0 -1
  114. package/dist/exports/attestation.mjs +0 -4
  115. package/dist/exports/dag.d.mts +0 -51
  116. package/dist/exports/dag.d.mts.map +0 -1
  117. package/dist/exports/dag.mjs +0 -386
  118. package/dist/exports/dag.mjs.map +0 -1
  119. package/dist/exports/types.d.mts +0 -35
  120. package/dist/exports/types.d.mts.map +0 -1
  121. package/dist/exports/types.mjs +0 -3
  122. package/dist/io-Cd6GLyjK.mjs +0 -153
  123. package/dist/io-Cd6GLyjK.mjs.map +0 -1
  124. package/dist/types-DyGXcWWp.d.mts +0 -71
  125. package/dist/types-DyGXcWWp.d.mts.map +0 -1
  126. package/src/attestation.ts +0 -81
  127. package/src/dag.ts +0 -426
  128. package/src/exports/attestation.ts +0 -2
  129. package/src/exports/types.ts +0 -10
  130. package/src/types.ts +0 -66
package/src/dag.ts DELETED
@@ -1,426 +0,0 @@
1
- import { ifDefined } from '@prisma-next/utils/defined';
2
- import { EMPTY_CONTRACT_HASH } from './constants';
3
- import {
4
- errorAmbiguousTarget,
5
- errorDuplicateMigrationId,
6
- errorNoInitialMigration,
7
- errorNoTarget,
8
- errorSameSourceAndTarget,
9
- } from './errors';
10
- import { bfs } from './graph-ops';
11
- import type { MigrationBundle, MigrationChainEntry, MigrationGraph } from './types';
12
-
13
- /** Forward-edge neighbours for BFS: edge `e` from `n` visits `e.to` next. */
14
- function forwardNeighbours(graph: MigrationGraph, node: string) {
15
- return (graph.forwardChain.get(node) ?? []).map((edge) => ({ next: edge.to, edge }));
16
- }
17
-
18
- /** Reverse-edge neighbours for BFS: edge `e` from `n` visits `e.from` next. */
19
- function reverseNeighbours(graph: MigrationGraph, node: string) {
20
- return (graph.reverseChain.get(node) ?? []).map((edge) => ({ next: edge.from, edge }));
21
- }
22
-
23
- function appendEdge(
24
- map: Map<string, MigrationChainEntry[]>,
25
- key: string,
26
- entry: MigrationChainEntry,
27
- ): void {
28
- const bucket = map.get(key);
29
- if (bucket) bucket.push(entry);
30
- else map.set(key, [entry]);
31
- }
32
-
33
- export function reconstructGraph(packages: readonly MigrationBundle[]): MigrationGraph {
34
- const nodes = new Set<string>();
35
- const forwardChain = new Map<string, MigrationChainEntry[]>();
36
- const reverseChain = new Map<string, MigrationChainEntry[]>();
37
- const migrationById = new Map<string, MigrationChainEntry>();
38
-
39
- for (const pkg of packages) {
40
- const { from, to } = pkg.manifest;
41
-
42
- if (from === to) {
43
- throw errorSameSourceAndTarget(pkg.dirName, from);
44
- }
45
-
46
- nodes.add(from);
47
- nodes.add(to);
48
-
49
- const migration: MigrationChainEntry = {
50
- from,
51
- to,
52
- migrationId: pkg.manifest.migrationId,
53
- dirName: pkg.dirName,
54
- createdAt: pkg.manifest.createdAt,
55
- labels: pkg.manifest.labels,
56
- };
57
-
58
- if (migrationById.has(migration.migrationId)) {
59
- throw errorDuplicateMigrationId(migration.migrationId);
60
- }
61
- migrationById.set(migration.migrationId, migration);
62
-
63
- appendEdge(forwardChain, from, migration);
64
- appendEdge(reverseChain, to, migration);
65
- }
66
-
67
- return { nodes, forwardChain, reverseChain, migrationById };
68
- }
69
-
70
- // ---------------------------------------------------------------------------
71
- // Deterministic tie-breaking for BFS neighbour order.
72
- // Used by `findPath` and `findPathWithDecision` only; not a general-purpose
73
- // utility. Ordering: label priority → createdAt → to → migrationId.
74
- // ---------------------------------------------------------------------------
75
-
76
- const LABEL_PRIORITY: Record<string, number> = { main: 0, default: 1, feature: 2 };
77
-
78
- function labelPriority(labels: readonly string[]): number {
79
- let best = 3;
80
- for (const l of labels) {
81
- const p = LABEL_PRIORITY[l];
82
- if (p !== undefined && p < best) best = p;
83
- }
84
- return best;
85
- }
86
-
87
- function compareTieBreak(a: MigrationChainEntry, b: MigrationChainEntry): number {
88
- const lp = labelPriority(a.labels) - labelPriority(b.labels);
89
- if (lp !== 0) return lp;
90
- const ca = a.createdAt.localeCompare(b.createdAt);
91
- if (ca !== 0) return ca;
92
- const tc = a.to.localeCompare(b.to);
93
- if (tc !== 0) return tc;
94
- return a.migrationId.localeCompare(b.migrationId);
95
- }
96
-
97
- function sortedNeighbors(edges: readonly MigrationChainEntry[]): readonly MigrationChainEntry[] {
98
- return [...edges].sort(compareTieBreak);
99
- }
100
-
101
- /** Ordering adapter for `bfs` — sorts `{next, edge}` pairs by tie-break. */
102
- function bfsOrdering(
103
- items: readonly { next: string; edge: MigrationChainEntry }[],
104
- ): readonly { next: string; edge: MigrationChainEntry }[] {
105
- return items.slice().sort((a, b) => compareTieBreak(a.edge, b.edge));
106
- }
107
-
108
- /**
109
- * Find the shortest path from `fromHash` to `toHash` using BFS over the
110
- * contract-hash graph. Returns the ordered list of edges, or null if no path
111
- * exists. Returns an empty array when `fromHash === toHash` (no-op).
112
- *
113
- * Neighbor ordering is deterministic via the tie-break sort key:
114
- * label priority → createdAt → to → migrationId.
115
- */
116
- export function findPath(
117
- graph: MigrationGraph,
118
- fromHash: string,
119
- toHash: string,
120
- ): readonly MigrationChainEntry[] | null {
121
- if (fromHash === toHash) return [];
122
-
123
- const parents = new Map<string, { parent: string; edge: MigrationChainEntry }>();
124
- for (const step of bfs([fromHash], (n) => forwardNeighbours(graph, n), bfsOrdering)) {
125
- if (step.parent !== null && step.incomingEdge !== null) {
126
- parents.set(step.node, { parent: step.parent, edge: step.incomingEdge });
127
- }
128
- if (step.node === toHash) {
129
- const path: MigrationChainEntry[] = [];
130
- let cur = toHash;
131
- let p = parents.get(cur);
132
- while (p) {
133
- path.push(p.edge);
134
- cur = p.parent;
135
- p = parents.get(cur);
136
- }
137
- path.reverse();
138
- return path;
139
- }
140
- }
141
-
142
- return null;
143
- }
144
-
145
- /**
146
- * Reverse-BFS from `toHash` over `reverseChain` to collect every node from
147
- * which `toHash` is reachable (inclusive of `toHash` itself).
148
- */
149
- function collectNodesReachingTarget(graph: MigrationGraph, toHash: string): Set<string> {
150
- const reached = new Set<string>();
151
- for (const step of bfs([toHash], (n) => reverseNeighbours(graph, n))) {
152
- reached.add(step.node);
153
- }
154
- return reached;
155
- }
156
-
157
- export interface PathDecision {
158
- readonly selectedPath: readonly MigrationChainEntry[];
159
- readonly fromHash: string;
160
- readonly toHash: string;
161
- readonly alternativeCount: number;
162
- readonly tieBreakReasons: readonly string[];
163
- readonly refName?: string;
164
- }
165
-
166
- /**
167
- * Find the shortest path from `fromHash` to `toHash` and return structured
168
- * path-decision metadata for machine-readable output.
169
- */
170
- export function findPathWithDecision(
171
- graph: MigrationGraph,
172
- fromHash: string,
173
- toHash: string,
174
- refName?: string,
175
- ): PathDecision | null {
176
- if (fromHash === toHash) {
177
- return {
178
- selectedPath: [],
179
- fromHash,
180
- toHash,
181
- alternativeCount: 0,
182
- tieBreakReasons: [],
183
- ...ifDefined('refName', refName),
184
- };
185
- }
186
-
187
- const path = findPath(graph, fromHash, toHash);
188
- if (!path) return null;
189
-
190
- // Single reverse BFS marks every node from which `toHash` is reachable.
191
- // Replaces a per-edge `findPath(e.to, toHash)` call inside the loop below,
192
- // which made the whole function O(|path| · (V + E)) instead of O(V + E).
193
- const reachesTarget = collectNodesReachingTarget(graph, toHash);
194
-
195
- const tieBreakReasons: string[] = [];
196
- let alternativeCount = 0;
197
-
198
- for (const edge of path) {
199
- const outgoing = graph.forwardChain.get(edge.from);
200
- if (outgoing && outgoing.length > 1) {
201
- const reachable = outgoing.filter((e) => reachesTarget.has(e.to));
202
- if (reachable.length > 1) {
203
- alternativeCount += reachable.length - 1;
204
- const sorted = sortedNeighbors(reachable);
205
- if (sorted[0] && sorted[0].migrationId === edge.migrationId) {
206
- if (reachable.some((e) => e.migrationId !== edge.migrationId)) {
207
- tieBreakReasons.push(
208
- `at ${edge.from}: ${reachable.length} candidates, selected by tie-break`,
209
- );
210
- }
211
- }
212
- }
213
- }
214
- }
215
-
216
- return {
217
- selectedPath: path,
218
- fromHash,
219
- toHash,
220
- alternativeCount,
221
- tieBreakReasons,
222
- ...ifDefined('refName', refName),
223
- };
224
- }
225
-
226
- /**
227
- * Walk ancestors of each branch tip back to find the last node
228
- * that appears on all paths. Returns `fromHash` if no shared ancestor is found.
229
- */
230
- function findDivergencePoint(
231
- graph: MigrationGraph,
232
- fromHash: string,
233
- leaves: readonly string[],
234
- ): string {
235
- const ancestorSets = leaves.map((leaf) => {
236
- const ancestors = new Set<string>();
237
- for (const step of bfs([leaf], (n) => reverseNeighbours(graph, n))) {
238
- ancestors.add(step.node);
239
- }
240
- return ancestors;
241
- });
242
-
243
- const commonAncestors = [...(ancestorSets[0] ?? [])].filter((node) =>
244
- ancestorSets.every((s) => s.has(node)),
245
- );
246
-
247
- let deepest = fromHash;
248
- let deepestDepth = -1;
249
- for (const ancestor of commonAncestors) {
250
- const path = findPath(graph, fromHash, ancestor);
251
- const depth = path ? path.length : 0;
252
- if (depth > deepestDepth) {
253
- deepestDepth = depth;
254
- deepest = ancestor;
255
- }
256
- }
257
- return deepest;
258
- }
259
-
260
- /**
261
- * Find all branch tips (nodes with no outgoing edges) reachable from
262
- * `fromHash` via forward edges.
263
- */
264
- export function findReachableLeaves(graph: MigrationGraph, fromHash: string): readonly string[] {
265
- const leaves: string[] = [];
266
- for (const step of bfs([fromHash], (n) => forwardNeighbours(graph, n))) {
267
- if (!graph.forwardChain.get(step.node)?.length) {
268
- leaves.push(step.node);
269
- }
270
- }
271
- return leaves;
272
- }
273
-
274
- /**
275
- * Find the target contract hash of the migration graph reachable from
276
- * EMPTY_CONTRACT_HASH. Returns `null` for a graph that has no target
277
- * state (either empty, or containing only the root with no outgoing
278
- * edges). Throws NO_INITIAL_MIGRATION if the graph has nodes but none
279
- * originate from the empty hash, and AMBIGUOUS_TARGET if multiple
280
- * branch tips exist.
281
- */
282
- export function findLeaf(graph: MigrationGraph): string | null {
283
- if (graph.nodes.size === 0) {
284
- return null;
285
- }
286
-
287
- if (!graph.nodes.has(EMPTY_CONTRACT_HASH)) {
288
- throw errorNoInitialMigration([...graph.nodes]);
289
- }
290
-
291
- const leaves = findReachableLeaves(graph, EMPTY_CONTRACT_HASH);
292
-
293
- if (leaves.length === 0) {
294
- const reachable = [...graph.nodes].filter((n) => n !== EMPTY_CONTRACT_HASH);
295
- if (reachable.length > 0) {
296
- throw errorNoTarget(reachable);
297
- }
298
- return null;
299
- }
300
-
301
- if (leaves.length > 1) {
302
- const divergencePoint = findDivergencePoint(graph, EMPTY_CONTRACT_HASH, leaves);
303
- const branches = leaves.map((tip) => {
304
- const path = findPath(graph, divergencePoint, tip);
305
- return {
306
- tip,
307
- edges: (path ?? []).map((e) => ({ dirName: e.dirName, from: e.from, to: e.to })),
308
- };
309
- });
310
- throw errorAmbiguousTarget(leaves, { divergencePoint, branches });
311
- }
312
-
313
- // biome-ignore lint/style/noNonNullAssertion: leaves.length is neither 0 nor >1 per the branches above, so exactly one leaf remains
314
- return leaves[0]!;
315
- }
316
-
317
- /**
318
- * Find the latest migration entry by traversing from EMPTY_CONTRACT_HASH
319
- * to the single target. Returns null for an empty graph.
320
- * Throws AMBIGUOUS_TARGET if the graph has multiple branch tips.
321
- */
322
- export function findLatestMigration(graph: MigrationGraph): MigrationChainEntry | null {
323
- const leafHash = findLeaf(graph);
324
- if (leafHash === null) return null;
325
-
326
- const path = findPath(graph, EMPTY_CONTRACT_HASH, leafHash);
327
- return path?.at(-1) ?? null;
328
- }
329
-
330
- export function detectCycles(graph: MigrationGraph): readonly string[][] {
331
- const WHITE = 0;
332
- const GRAY = 1;
333
- const BLACK = 2;
334
-
335
- const color = new Map<string, number>();
336
- const parentMap = new Map<string, string | null>();
337
- const cycles: string[][] = [];
338
-
339
- for (const node of graph.nodes) {
340
- color.set(node, WHITE);
341
- }
342
-
343
- // Iterative three-color DFS. A frame is (node, outgoing edges, next-index).
344
- interface Frame {
345
- node: string;
346
- outgoing: readonly MigrationChainEntry[];
347
- index: number;
348
- }
349
- const stack: Frame[] = [];
350
-
351
- function pushFrame(u: string): void {
352
- color.set(u, GRAY);
353
- stack.push({ node: u, outgoing: graph.forwardChain.get(u) ?? [], index: 0 });
354
- }
355
-
356
- for (const root of graph.nodes) {
357
- if (color.get(root) !== WHITE) continue;
358
- parentMap.set(root, null);
359
- pushFrame(root);
360
-
361
- while (stack.length > 0) {
362
- // biome-ignore lint/style/noNonNullAssertion: stack.length > 0 should guarantee that this cannot be undefined
363
- const frame = stack[stack.length - 1]!;
364
- if (frame.index >= frame.outgoing.length) {
365
- color.set(frame.node, BLACK);
366
- stack.pop();
367
- continue;
368
- }
369
- // biome-ignore lint/style/noNonNullAssertion: the early-continue above guarantees frame.index < frame.outgoing.length here, so this is defined
370
- const edge = frame.outgoing[frame.index++]!;
371
- const v = edge.to;
372
- const vColor = color.get(v);
373
- if (vColor === GRAY) {
374
- const cycle: string[] = [v];
375
- let cur = frame.node;
376
- while (cur !== v) {
377
- cycle.push(cur);
378
- cur = parentMap.get(cur) ?? v;
379
- }
380
- cycle.reverse();
381
- cycles.push(cycle);
382
- } else if (vColor === WHITE) {
383
- parentMap.set(v, frame.node);
384
- pushFrame(v);
385
- }
386
- }
387
- }
388
-
389
- return cycles;
390
- }
391
-
392
- export function detectOrphans(graph: MigrationGraph): readonly MigrationChainEntry[] {
393
- if (graph.nodes.size === 0) return [];
394
-
395
- const reachable = new Set<string>();
396
- const startNodes: string[] = [];
397
-
398
- if (graph.forwardChain.has(EMPTY_CONTRACT_HASH)) {
399
- startNodes.push(EMPTY_CONTRACT_HASH);
400
- } else {
401
- const allTargets = new Set<string>();
402
- for (const edges of graph.forwardChain.values()) {
403
- for (const edge of edges) {
404
- allTargets.add(edge.to);
405
- }
406
- }
407
- for (const node of graph.nodes) {
408
- if (!allTargets.has(node)) {
409
- startNodes.push(node);
410
- }
411
- }
412
- }
413
-
414
- for (const step of bfs(startNodes, (n) => forwardNeighbours(graph, n))) {
415
- reachable.add(step.node);
416
- }
417
-
418
- const orphans: MigrationChainEntry[] = [];
419
- for (const [from, migrations] of graph.forwardChain) {
420
- if (!reachable.has(from)) {
421
- orphans.push(...migrations);
422
- }
423
- }
424
-
425
- return orphans;
426
- }
@@ -1,2 +0,0 @@
1
- export type { VerifyResult } from '../attestation';
2
- export { computeMigrationId, verifyMigration, verifyMigrationBundle } from '../attestation';
@@ -1,10 +0,0 @@
1
- export { MigrationToolsError } from '../errors';
2
- export type {
3
- MigrationBundle,
4
- MigrationBundle as MigrationPackage,
5
- MigrationChainEntry,
6
- MigrationGraph,
7
- MigrationHints,
8
- MigrationManifest,
9
- MigrationOps,
10
- } from '../types';
package/src/types.ts DELETED
@@ -1,66 +0,0 @@
1
- import type { Contract } from '@prisma-next/contract/types';
2
- import type { MigrationPlanOperation } from '@prisma-next/framework-components/control';
3
-
4
- export interface MigrationHints {
5
- readonly used: readonly string[];
6
- readonly applied: readonly string[];
7
- readonly plannerVersion: string;
8
- }
9
-
10
- /**
11
- * On-disk migration manifest. Every migration is content-addressed: the
12
- * `migrationId` is a hash over the manifest envelope plus the operations
13
- * list, computed at write time. There is no draft state — a migration
14
- * directory either exists with a fully attested manifest or it does not.
15
- *
16
- * When the planner cannot lower an operation because of an unfilled
17
- * `placeholder(...)` slot, the migration is still written with
18
- * `migrationId` hashed over `ops: []`. Re-running self-emit after the
19
- * user fills the placeholder produces a *different* `migrationId`
20
- * (committed to the real ops); this is intentional.
21
- */
22
- export interface MigrationManifest {
23
- readonly migrationId: string;
24
- readonly from: string;
25
- readonly to: string;
26
- readonly kind: 'regular' | 'baseline';
27
- readonly fromContract: Contract | null;
28
- readonly toContract: Contract;
29
- readonly hints: MigrationHints;
30
- readonly labels: readonly string[];
31
- readonly authorship?: { readonly author?: string; readonly email?: string };
32
- readonly signature?: { readonly keyId: string; readonly value: string } | null;
33
- readonly createdAt: string;
34
- }
35
-
36
- export type MigrationOps = readonly MigrationPlanOperation[];
37
-
38
- /**
39
- * An on-disk migration directory containing a manifest and operations.
40
- */
41
- export interface MigrationBundle {
42
- readonly dirName: string;
43
- readonly dirPath: string;
44
- readonly manifest: MigrationManifest;
45
- readonly ops: MigrationOps;
46
- }
47
-
48
- /**
49
- * An entry in the migration graph. All on-disk migrations are attested,
50
- * so `migrationId` is always a string.
51
- */
52
- export interface MigrationChainEntry {
53
- readonly from: string;
54
- readonly to: string;
55
- readonly migrationId: string;
56
- readonly dirName: string;
57
- readonly createdAt: string;
58
- readonly labels: readonly string[];
59
- }
60
-
61
- export interface MigrationGraph {
62
- readonly nodes: ReadonlySet<string>;
63
- readonly forwardChain: ReadonlyMap<string, readonly MigrationChainEntry[]>;
64
- readonly reverseChain: ReadonlyMap<string, readonly MigrationChainEntry[]>;
65
- readonly migrationById: ReadonlyMap<string, MigrationChainEntry>;
66
- }