@prisma-next/migration-tools 0.11.0-dev.59 → 0.11.0-dev.60
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/exports/aggregate.d.mts +7 -7
- package/dist/exports/aggregate.mjs +3 -4
- package/dist/exports/aggregate.mjs.map +1 -1
- package/dist/exports/graph.d.mts +1 -1
- package/dist/exports/hash.d.mts +2 -2
- package/dist/exports/invariants.d.mts +1 -1
- package/dist/exports/io.d.mts +1 -1
- package/dist/exports/metadata.d.mts +1 -1
- package/dist/exports/migration-graph.d.mts +2 -2
- package/dist/exports/migration.d.mts +1 -1
- package/dist/exports/package.d.mts +1 -1
- package/dist/exports/ref-resolution.d.mts +2 -2
- package/dist/exports/ref-resolution.mjs +1 -1
- package/dist/exports/refs.d.mts +2 -2
- package/dist/exports/refs.mjs +3 -3
- package/dist/exports/spaces.d.mts +3 -3
- package/dist/exports/spaces.mjs +1 -2
- package/dist/exports/spaces.mjs.map +1 -1
- package/dist/{graph-BwjwIZmb.d.mts → graph-3dLMZp5l.d.mts} +1 -1
- package/dist/{graph-BwjwIZmb.d.mts.map → graph-3dLMZp5l.d.mts.map} +1 -1
- package/dist/{io-g7fQCYNJ.d.mts → io-BH4G3F-i.d.mts} +2 -2
- package/dist/{io-g7fQCYNJ.d.mts.map → io-BH4G3F-i.d.mts.map} +1 -1
- package/dist/{migration-graph-CC7PSXw0.d.mts → migration-graph-CWEM2SLR.d.mts} +3 -3
- package/dist/{migration-graph-CC7PSXw0.d.mts.map → migration-graph-CWEM2SLR.d.mts.map} +1 -1
- package/dist/{package-C31VGBCK.d.mts → package-Ca-J_z_0.d.mts} +1 -1
- package/dist/{package-C31VGBCK.d.mts.map → package-Ca-J_z_0.d.mts.map} +1 -1
- package/dist/{verify-contract-spaces-3u7gzhqT.mjs → read-contract-space-contract-TbeXuJXL.mjs} +82 -7
- package/dist/read-contract-space-contract-TbeXuJXL.mjs.map +1 -0
- package/dist/{refs-Ditzcs06.mjs → refs-C-_WUrPw.mjs} +23 -2
- package/dist/{refs-Ditzcs06.mjs.map → refs-C-_WUrPw.mjs.map} +1 -1
- package/dist/{refs-BPYU-r14.d.mts → refs-C7wuYFqZ.d.mts} +18 -2
- package/dist/refs-C7wuYFqZ.d.mts.map +1 -0
- package/dist/{snapshot-CVg78oBp.mjs → snapshot-38tKJ9o9.mjs} +2 -2
- package/dist/{snapshot-CVg78oBp.mjs.map → snapshot-38tKJ9o9.mjs.map} +1 -1
- package/dist/{verify-contract-spaces-C7EZktZP.d.mts → verify-contract-spaces-BdysZdQk.d.mts} +1 -1
- package/dist/{verify-contract-spaces-C7EZktZP.d.mts.map → verify-contract-spaces-BdysZdQk.d.mts.map} +1 -1
- package/package.json +6 -18
- package/src/exports/refs.ts +3 -0
- package/src/refs.ts +27 -0
- package/dist/exports/enumerate-migration-spaces.d.mts +0 -53
- package/dist/exports/enumerate-migration-spaces.d.mts.map +0 -1
- package/dist/exports/enumerate-migration-spaces.mjs +0 -107
- package/dist/exports/enumerate-migration-spaces.mjs.map +0 -1
- package/dist/exports/migration-list-graph-topology.d.mts +0 -13
- package/dist/exports/migration-list-graph-topology.d.mts.map +0 -1
- package/dist/exports/migration-list-graph-topology.mjs +0 -105
- package/dist/exports/migration-list-graph-topology.mjs.map +0 -1
- package/dist/exports/migration-list-types.d.mts +0 -2
- package/dist/exports/migration-list-types.mjs +0 -1
- package/dist/migration-list-types-B8NY0jQ1.d.mts +0 -23
- package/dist/migration-list-types-B8NY0jQ1.d.mts.map +0 -1
- package/dist/read-contract-space-contract-BbcST3Lm.mjs +0 -82
- package/dist/read-contract-space-contract-BbcST3Lm.mjs.map +0 -1
- package/dist/refs-BPYU-r14.d.mts.map +0 -1
- package/dist/verify-contract-spaces-3u7gzhqT.mjs.map +0 -1
- package/src/enumerate-migration-spaces.ts +0 -127
- package/src/exports/enumerate-migration-spaces.ts +0 -4
- package/src/exports/migration-list-graph-topology.ts +0 -5
- package/src/exports/migration-list-types.ts +0 -5
- package/src/migration-list-graph-topology.ts +0 -158
- package/src/migration-list-types.ts +0 -21
- /package/dist/{metadata-CH3tNNkp.d.mts → metadata-Bp9X04gM.d.mts} +0 -0
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { readMigrationsDir } from './io';
|
|
2
|
-
import type { MigrationListEntry, MigrationSpaceListEntry } from './migration-list-types';
|
|
3
|
-
import { readRefs } from './refs';
|
|
4
|
-
import {
|
|
5
|
-
APP_SPACE_ID,
|
|
6
|
-
isValidSpaceId,
|
|
7
|
-
RESERVED_SPACE_SUBDIR_NAMES,
|
|
8
|
-
spaceMigrationDirectory,
|
|
9
|
-
spaceRefsDirectory,
|
|
10
|
-
} from './space-layout';
|
|
11
|
-
import { listContractSpaceDirectories } from './verify-contract-spaces';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Index `migrations/<space>/refs/*.json` by the contract hash each ref
|
|
15
|
-
* points at, so callers can attach `(ref names)` decorations to every
|
|
16
|
-
* row whose destination contract hash matches.
|
|
17
|
-
*
|
|
18
|
-
* Each bucket is sorted lex-asc to keep rendered output deterministic
|
|
19
|
-
* (adjacent rows pointing at the same hash render their ref decorations
|
|
20
|
-
* in the same order).
|
|
21
|
-
*
|
|
22
|
-
* Refs whose hash matches no migration on disk are still indexed; the
|
|
23
|
-
* caller decides whether to surface them. Migration rows only carry
|
|
24
|
-
* `(refs)` decorations when a matching destination contract hash exists
|
|
25
|
-
* on disk — orphan refs are not rendered on any row.
|
|
26
|
-
*
|
|
27
|
-
* Returns an empty map when the refs directory does not exist
|
|
28
|
-
* ({@link readRefs} treats `ENOENT` as "no refs").
|
|
29
|
-
*/
|
|
30
|
-
export async function resolveRefsByContractHash(
|
|
31
|
-
refsDir: string,
|
|
32
|
-
): Promise<ReadonlyMap<string, readonly string[]>> {
|
|
33
|
-
const refs = await readRefs(refsDir);
|
|
34
|
-
const byHash = new Map<string, string[]>();
|
|
35
|
-
for (const [name, entry] of Object.entries(refs)) {
|
|
36
|
-
const bucket = byHash.get(entry.hash);
|
|
37
|
-
if (bucket) bucket.push(name);
|
|
38
|
-
else byHash.set(entry.hash, [name]);
|
|
39
|
-
}
|
|
40
|
-
for (const bucket of byHash.values()) {
|
|
41
|
-
bucket.sort();
|
|
42
|
-
}
|
|
43
|
-
return byHash;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Compare two contract-space IDs for the inter-space ordering rule:
|
|
48
|
-
* {@link APP_SPACE_ID} first if present, then lex-asc on the rest.
|
|
49
|
-
*/
|
|
50
|
-
function compareSpaceIds(a: string, b: string): number {
|
|
51
|
-
if (a === APP_SPACE_ID) return b === APP_SPACE_ID ? 0 : -1;
|
|
52
|
-
if (b === APP_SPACE_ID) return 1;
|
|
53
|
-
if (a < b) return -1;
|
|
54
|
-
if (a > b) return 1;
|
|
55
|
-
return 0;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Sort `dirName` descending so the rendered output reads latest-first,
|
|
60
|
-
* matching the `git log` latest-first convention.
|
|
61
|
-
*/
|
|
62
|
-
function compareDirNamesDescending(a: MigrationListEntry, b: MigrationListEntry): number {
|
|
63
|
-
if (a.dirName < b.dirName) return 1;
|
|
64
|
-
if (a.dirName > b.dirName) return -1;
|
|
65
|
-
return 0;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Enumerate every contract space's on-disk migrations under
|
|
70
|
-
* `<projectMigrationsDir>/`. For each valid space directory:
|
|
71
|
-
*
|
|
72
|
-
* - Loads on-disk packages via {@link readMigrationsDir}.
|
|
73
|
-
* - Attaches ref decorations: each migration's `refs[]` lists every ref
|
|
74
|
-
* name from `migrations/<spaceId>/refs/*.json` whose hash equals the
|
|
75
|
-
* migration's destination contract hash.
|
|
76
|
-
* - Sorts migrations within the space by `dirName` descending
|
|
77
|
-
* (reverse-filename, latest first).
|
|
78
|
-
*
|
|
79
|
-
* Contract spaces are returned with {@link APP_SPACE_ID} first when
|
|
80
|
-
* present, then the remaining ids lex-asc. A contract-space directory
|
|
81
|
-
* that contains no migrations becomes `{ spaceId, migrations: [] }` so
|
|
82
|
-
* the renderer's empty-state path can surface it.
|
|
83
|
-
*
|
|
84
|
-
* Directory entries that are not valid {@link isValidSpaceId} names are
|
|
85
|
-
* skipped (a stray non-space directory under `migrations/` does not
|
|
86
|
-
* spawn a phantom space entry). Entries whose name appears in
|
|
87
|
-
* {@link RESERVED_SPACE_SUBDIR_NAMES} are also skipped — the per-space
|
|
88
|
-
* `refs/` subdirectory name shape would otherwise satisfy
|
|
89
|
-
* {@link isValidSpaceId} and surface as a phantom contract space.
|
|
90
|
-
*
|
|
91
|
-
* Returns `[]` when `<projectMigrationsDir>` does not exist — a fresh
|
|
92
|
-
* project that has not authored any migration yet.
|
|
93
|
-
*/
|
|
94
|
-
export async function enumerateMigrationSpaces(args: {
|
|
95
|
-
readonly projectMigrationsDir: string;
|
|
96
|
-
}): Promise<readonly MigrationSpaceListEntry[]> {
|
|
97
|
-
const { projectMigrationsDir } = args;
|
|
98
|
-
const candidateDirs = await listContractSpaceDirectories(projectMigrationsDir);
|
|
99
|
-
const spaceIds = candidateDirs
|
|
100
|
-
.filter((name) => !RESERVED_SPACE_SUBDIR_NAMES.has(name))
|
|
101
|
-
.filter(isValidSpaceId)
|
|
102
|
-
.sort(compareSpaceIds);
|
|
103
|
-
|
|
104
|
-
const spaces: MigrationSpaceListEntry[] = [];
|
|
105
|
-
for (const spaceId of spaceIds) {
|
|
106
|
-
const spaceDir = spaceMigrationDirectory(projectMigrationsDir, spaceId);
|
|
107
|
-
const { packages } = await readMigrationsDir(spaceDir);
|
|
108
|
-
const refsByHash = await resolveRefsByContractHash(spaceRefsDirectory(spaceDir));
|
|
109
|
-
|
|
110
|
-
const migrations: MigrationListEntry[] = packages
|
|
111
|
-
.map((pkg) => ({
|
|
112
|
-
dirName: pkg.dirName,
|
|
113
|
-
from: pkg.metadata.from,
|
|
114
|
-
to: pkg.metadata.to,
|
|
115
|
-
migrationHash: pkg.metadata.migrationHash,
|
|
116
|
-
operationCount: pkg.ops.length,
|
|
117
|
-
createdAt: pkg.metadata.createdAt,
|
|
118
|
-
refs: refsByHash.get(pkg.metadata.to) ?? [],
|
|
119
|
-
providedInvariants: pkg.metadata.providedInvariants,
|
|
120
|
-
}))
|
|
121
|
-
.sort(compareDirNamesDescending);
|
|
122
|
-
|
|
123
|
-
spaces.push({ spaceId, migrations });
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return spaces;
|
|
127
|
-
}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { EMPTY_CONTRACT_HASH } from './constants';
|
|
2
|
-
import type { MigrationListEntry } from './migration-list-types';
|
|
3
|
-
|
|
4
|
-
export type MigrationEdgeKind = 'forward' | 'rollback' | 'self';
|
|
5
|
-
|
|
6
|
-
export interface MigrationListGraphTopology {
|
|
7
|
-
readonly kindByMigrationHash: ReadonlyMap<string, MigrationEdgeKind>;
|
|
8
|
-
readonly forwardInDegree: ReadonlyMap<string, number>;
|
|
9
|
-
readonly forwardOutDegree: ReadonlyMap<string, number>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface NonSelfEdge {
|
|
13
|
-
readonly entry: MigrationListEntry;
|
|
14
|
-
readonly from: string;
|
|
15
|
-
readonly to: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function canonicalFrom(from: string | null): string {
|
|
19
|
-
return from ?? EMPTY_CONTRACT_HASH;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function compareDirNameDesc(a: MigrationListEntry, b: MigrationListEntry): number {
|
|
23
|
-
return b.dirName.localeCompare(a.dirName);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function bumpDegree(map: Map<string, number>, key: string): void {
|
|
27
|
-
map.set(key, (map.get(key) ?? 0) + 1);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function classifyMigrationListGraphTopology(
|
|
31
|
-
entries: readonly MigrationListEntry[],
|
|
32
|
-
): MigrationListGraphTopology {
|
|
33
|
-
const nodes = new Set<string>();
|
|
34
|
-
const kindByMigrationHash = new Map<string, MigrationEdgeKind>();
|
|
35
|
-
const outgoingByFrom = new Map<string, NonSelfEdge[]>();
|
|
36
|
-
|
|
37
|
-
for (const entry of entries) {
|
|
38
|
-
const from = canonicalFrom(entry.from);
|
|
39
|
-
const to = entry.to;
|
|
40
|
-
nodes.add(from);
|
|
41
|
-
nodes.add(to);
|
|
42
|
-
|
|
43
|
-
if (from === to) {
|
|
44
|
-
kindByMigrationHash.set(entry.migrationHash, 'self');
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const bucket = outgoingByFrom.get(from);
|
|
49
|
-
const edge: NonSelfEdge = { entry, from, to };
|
|
50
|
-
if (bucket) bucket.push(edge);
|
|
51
|
-
else outgoingByFrom.set(from, [edge]);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
for (const bucket of outgoingByFrom.values()) {
|
|
55
|
-
bucket.sort((a, b) => compareDirNameDesc(a.entry, b.entry));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const nonSelfInDegree = new Map<string, number>();
|
|
59
|
-
for (const node of nodes) {
|
|
60
|
-
nonSelfInDegree.set(node, 0);
|
|
61
|
-
}
|
|
62
|
-
for (const bucket of outgoingByFrom.values()) {
|
|
63
|
-
for (const edge of bucket) {
|
|
64
|
-
bumpDegree(nonSelfInDegree, edge.to);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const dfsRoots: string[] = [];
|
|
69
|
-
for (const node of nodes) {
|
|
70
|
-
if ((nonSelfInDegree.get(node) ?? 0) === 0) {
|
|
71
|
-
dfsRoots.push(node);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
dfsRoots.sort((a, b) => {
|
|
75
|
-
if (a === EMPTY_CONTRACT_HASH) return -1;
|
|
76
|
-
if (b === EMPTY_CONTRACT_HASH) return 1;
|
|
77
|
-
return a.localeCompare(b);
|
|
78
|
-
});
|
|
79
|
-
if (dfsRoots.length === 0) {
|
|
80
|
-
dfsRoots.push(...[...nodes].sort((a, b) => a.localeCompare(b)));
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const WHITE = 0;
|
|
84
|
-
const GRAY = 1;
|
|
85
|
-
const BLACK = 2;
|
|
86
|
-
const color = new Map<string, number>();
|
|
87
|
-
for (const node of nodes) {
|
|
88
|
-
color.set(node, WHITE);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
interface Frame {
|
|
92
|
-
node: string;
|
|
93
|
-
outgoing: readonly NonSelfEdge[];
|
|
94
|
-
index: number;
|
|
95
|
-
}
|
|
96
|
-
const stack: Frame[] = [];
|
|
97
|
-
|
|
98
|
-
function pushFrame(node: string): void {
|
|
99
|
-
color.set(node, GRAY);
|
|
100
|
-
stack.push({ node, outgoing: outgoingByFrom.get(node) ?? [], index: 0 });
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function runDfsFrom(root: string): void {
|
|
104
|
-
if (color.get(root) !== WHITE) return;
|
|
105
|
-
pushFrame(root);
|
|
106
|
-
|
|
107
|
-
while (stack.length > 0) {
|
|
108
|
-
const frame = stack[stack.length - 1];
|
|
109
|
-
if (frame === undefined) break;
|
|
110
|
-
if (frame.index >= frame.outgoing.length) {
|
|
111
|
-
color.set(frame.node, BLACK);
|
|
112
|
-
stack.pop();
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const edge = frame.outgoing[frame.index];
|
|
117
|
-
frame.index += 1;
|
|
118
|
-
if (edge === undefined) continue;
|
|
119
|
-
|
|
120
|
-
const v = edge.to;
|
|
121
|
-
const vColor = color.get(v);
|
|
122
|
-
if (vColor === GRAY) {
|
|
123
|
-
kindByMigrationHash.set(edge.entry.migrationHash, 'rollback');
|
|
124
|
-
} else {
|
|
125
|
-
kindByMigrationHash.set(edge.entry.migrationHash, 'forward');
|
|
126
|
-
if (vColor === WHITE) {
|
|
127
|
-
pushFrame(v);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
for (const root of dfsRoots) {
|
|
134
|
-
runDfsFrom(root);
|
|
135
|
-
}
|
|
136
|
-
const remainingWhite = [...nodes].filter((node) => color.get(node) === WHITE);
|
|
137
|
-
remainingWhite.sort((a, b) => a.localeCompare(b));
|
|
138
|
-
for (const root of remainingWhite) {
|
|
139
|
-
runDfsFrom(root);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const forwardInDegree = new Map<string, number>();
|
|
143
|
-
const forwardOutDegree = new Map<string, number>();
|
|
144
|
-
|
|
145
|
-
for (const entry of entries) {
|
|
146
|
-
if (kindByMigrationHash.get(entry.migrationHash) !== 'forward') continue;
|
|
147
|
-
const from = canonicalFrom(entry.from);
|
|
148
|
-
const to = entry.to;
|
|
149
|
-
bumpDegree(forwardOutDegree, from);
|
|
150
|
-
bumpDegree(forwardInDegree, to);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return {
|
|
154
|
-
kindByMigrationHash,
|
|
155
|
-
forwardInDegree,
|
|
156
|
-
forwardOutDegree,
|
|
157
|
-
};
|
|
158
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export interface MigrationListEntry {
|
|
2
|
-
readonly dirName: string;
|
|
3
|
-
readonly from: string | null;
|
|
4
|
-
readonly to: string;
|
|
5
|
-
readonly migrationHash: string;
|
|
6
|
-
readonly operationCount: number;
|
|
7
|
-
readonly createdAt: string;
|
|
8
|
-
readonly refs: readonly string[];
|
|
9
|
-
readonly providedInvariants: readonly string[];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface MigrationSpaceListEntry {
|
|
13
|
-
readonly spaceId: string;
|
|
14
|
-
readonly migrations: readonly MigrationListEntry[];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface MigrationListResult {
|
|
18
|
-
readonly ok: true;
|
|
19
|
-
readonly spaces: readonly MigrationSpaceListEntry[];
|
|
20
|
-
readonly summary: string;
|
|
21
|
-
}
|
|
File without changes
|