@prisma/orm-mysql 8.0.0-rc.21-dev.23 → 8.0.0-rc.22-dev.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.
- package/dist/{mysql-static-Dv4HuJDi-CoURZL0Y.mjs → mysql-static-BL8oiRXR-Bejb2Pii.mjs} +3 -3
- package/dist/mysql-static-BL8oiRXR-Bejb2Pii.mjs.map +1 -0
- package/dist/runtime.mjs +1 -1
- package/dist/runtime.mjs.map +1 -1
- package/dist/static.mjs +1 -1
- package/package.json +8 -8
- package/skills/prisma-8/SKILL.md +1 -1
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/instructions.md +555 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/scripts/value-objects-in-storage/value-objects-in-storage.ts +1184 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/instructions.md +432 -0
- package/dist/mysql-static-Dv4HuJDi-CoURZL0Y.mjs.map +0 -1
|
@@ -0,0 +1,1184 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Moves the value objects of every SQL and MongoDB contract from the domain plane into storage. Contracts emitted before this release keep value objects at `domain.namespaces.<ns>.valueObjects` and type a field holding one as `{ kind: 'valueObject', name }`; this release keeps them at `storage.namespaces.<ns>.entries.valueObject` and types the field by the value object's storage coordinate. In each contract the script moves every value object into the storage namespace of the same id, points every field at it by coordinate, and points a member typed by an enum at the enum's storage value set. In a SQL contract it also writes the value set of each discriminator, keyed `<Base>.<field>` and holding the variants' values, and points the discriminator column at it, unless an enum already types that column. It makes the same changes in `contract.d.ts`.
|
|
4
|
+
*
|
|
5
|
+
* Storage now holds the value objects, so each rewritten contract has a new storage hash. The script renames each snapshot directory to its new hash and rewrites every migration, ref, `migration.ts` and `contract.d.ts` that names an old hash, and each migration's `migrationHash`. It does not add the checks PostgreSQL now derives for value object and discriminator columns: a snapshot records what its migrations created, and they created no such check. The next `prisma migration plan` adds them.
|
|
6
|
+
*
|
|
7
|
+
* Usage: node value-objects-in-storage.ts [project-root]
|
|
8
|
+
*
|
|
9
|
+
* The project root defaults to the working directory. The script reads and writes files only. It needs no database, network or configured stack, and a project whose contracts keep no value object in the domain plane is left unchanged. When it stops (a file it must read is not valid JSON, a contract whose stored hash does not match its content, a field naming a value object the contract does not declare, a value object whose namespace storage does not have, a member enum without a storage value set, a discriminator value set that already exists, a snapshot directory that already exists with different content, or a directory it cannot read) it changes no file, prints one line per case and exits 1. When it finishes it prints how many files and snapshot directories it changed and each storage hash it replaced.
|
|
10
|
+
*
|
|
11
|
+
* The storage hash and migration hash rules are copied from `@internal/contract`, `@internal/sql-contract`, `@internal/mongo-contract` and `@internal/migration-tools` because a project's strict `node_modules` does not expose them.
|
|
12
|
+
*/
|
|
13
|
+
import { createHash } from 'node:crypto';
|
|
14
|
+
import {
|
|
15
|
+
chmodSync,
|
|
16
|
+
type Dirent,
|
|
17
|
+
existsSync,
|
|
18
|
+
mkdirSync,
|
|
19
|
+
readdirSync,
|
|
20
|
+
readFileSync,
|
|
21
|
+
realpathSync,
|
|
22
|
+
renameSync,
|
|
23
|
+
rmSync,
|
|
24
|
+
statSync,
|
|
25
|
+
writeFileSync,
|
|
26
|
+
} from 'node:fs';
|
|
27
|
+
import { basename, dirname, join, relative, resolve, sep } from 'node:path';
|
|
28
|
+
|
|
29
|
+
type Json = null | boolean | number | string | Json[] | JsonRecord;
|
|
30
|
+
interface JsonRecord {
|
|
31
|
+
[key: string]: Json;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type Family = 'sql' | 'mongo';
|
|
35
|
+
|
|
36
|
+
const SKIPPED_DIRECTORIES = new Set(['node_modules', 'dist', 'build']);
|
|
37
|
+
const HASH = /^[0-9a-f]{64}$/;
|
|
38
|
+
const TEMPORARY_SUFFIX = '.value-objects-in-storage-tmp';
|
|
39
|
+
const BYTE_ORDER_MARK = '\uFEFF';
|
|
40
|
+
|
|
41
|
+
function isRecord(value: unknown): value is JsonRecord {
|
|
42
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) return false;
|
|
43
|
+
const prototype: unknown = Object.getPrototypeOf(value);
|
|
44
|
+
return prototype === Object.prototype || prototype === null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function withoutByteOrderMark(text: string): string {
|
|
48
|
+
return text.startsWith(BYTE_ORDER_MARK) ? text.slice(BYTE_ORDER_MARK.length) : text;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function parseJson(text: string): Json | undefined {
|
|
52
|
+
try {
|
|
53
|
+
const value: Json = JSON.parse(withoutByteOrderMark(text));
|
|
54
|
+
return value;
|
|
55
|
+
} catch {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function sha256(text: string): string {
|
|
61
|
+
return createHash('sha256').update(text).digest('hex');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function compareCodeUnits(a: string, b: string): number {
|
|
65
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function sortKeys(value: Json): Json {
|
|
69
|
+
if (Array.isArray(value)) return value.map(sortKeys);
|
|
70
|
+
if (!isRecord(value)) return value;
|
|
71
|
+
const sorted: JsonRecord = {};
|
|
72
|
+
for (const key of Object.keys(value).sort(compareCodeUnits)) {
|
|
73
|
+
const child = value[key];
|
|
74
|
+
if (child !== undefined) sorted[key] = sortKeys(child);
|
|
75
|
+
}
|
|
76
|
+
return sorted;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function canonicalizeJson(value: Json): string {
|
|
80
|
+
return JSON.stringify(sortKeys(value));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
type PathSegment = string | readonly string[];
|
|
84
|
+
|
|
85
|
+
function matchesPath(path: readonly string[], pattern: readonly PathSegment[]): boolean {
|
|
86
|
+
if (path.length !== pattern.length) return false;
|
|
87
|
+
return pattern.every((segment, index) => {
|
|
88
|
+
const value = path[index];
|
|
89
|
+
if (value === undefined) return false;
|
|
90
|
+
if (segment === '*') return true;
|
|
91
|
+
return typeof segment === 'string' ? value === segment : segment.includes(value);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const SQL_PRESERVED_EMPTY: readonly (readonly PathSegment[])[] = [
|
|
96
|
+
['storage', 'namespaces', '*', 'entries', 'table'],
|
|
97
|
+
['storage', 'namespaces', '*', 'entries', 'table', '*'],
|
|
98
|
+
['storage', 'namespaces', '*', 'entries', 'table', '*', ['uniques', 'indexes', 'foreignKeys']],
|
|
99
|
+
['storage', 'namespaces', '*', 'entries', 'table', '*', 'indexes', 'unique'],
|
|
100
|
+
['storage', 'namespaces', '*', 'entries', 'table', '*', 'columns', '*', 'default', 'value'],
|
|
101
|
+
];
|
|
102
|
+
const COLUMN_DEFAULT_VALUE: readonly PathSegment[] = [
|
|
103
|
+
'storage',
|
|
104
|
+
'namespaces',
|
|
105
|
+
'*',
|
|
106
|
+
'entries',
|
|
107
|
+
'table',
|
|
108
|
+
'*',
|
|
109
|
+
'columns',
|
|
110
|
+
'*',
|
|
111
|
+
'default',
|
|
112
|
+
'value',
|
|
113
|
+
];
|
|
114
|
+
const MONGO_PRESERVED_EMPTY: readonly (readonly PathSegment[])[] = [
|
|
115
|
+
['storage', 'namespaces', '*', 'entries', 'collection'],
|
|
116
|
+
['storage', 'namespaces', '*', 'entries', 'collection', '*'],
|
|
117
|
+
];
|
|
118
|
+
const FRAMEWORK_PRESERVED_EMPTY: readonly (readonly PathSegment[])[] = [
|
|
119
|
+
['domain', 'namespaces'],
|
|
120
|
+
['domain', 'namespaces', '*'],
|
|
121
|
+
['domain', 'namespaces', '*', 'models'],
|
|
122
|
+
['domain', 'namespaces', '*', 'models', '*', 'relations'],
|
|
123
|
+
['domain', 'namespaces', '*', 'models', '*', 'storage'],
|
|
124
|
+
['storage', 'namespaces'],
|
|
125
|
+
['storage', 'namespaces', '*', 'entries'],
|
|
126
|
+
['roots'],
|
|
127
|
+
['extensions'],
|
|
128
|
+
['extensions', '*'],
|
|
129
|
+
['capabilities'],
|
|
130
|
+
['meta'],
|
|
131
|
+
['execution', 'mutations', 'defaults'],
|
|
132
|
+
];
|
|
133
|
+
const TOP_LEVEL_ORDER = [
|
|
134
|
+
'schemaVersion',
|
|
135
|
+
'canonicalVersion',
|
|
136
|
+
'targetFamily',
|
|
137
|
+
'target',
|
|
138
|
+
'profileHash',
|
|
139
|
+
'roots',
|
|
140
|
+
'domain',
|
|
141
|
+
'storage',
|
|
142
|
+
'execution',
|
|
143
|
+
'capabilities',
|
|
144
|
+
'extensions',
|
|
145
|
+
'defaultControlPolicy',
|
|
146
|
+
'meta',
|
|
147
|
+
];
|
|
148
|
+
|
|
149
|
+
function isDefaultValue(value: Json): boolean {
|
|
150
|
+
if (value === false) return true;
|
|
151
|
+
if (Array.isArray(value)) return value.length === 0;
|
|
152
|
+
return isRecord(value) && Object.keys(value).length === 0;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function isFamilyPreservedEmpty(family: Family, path: readonly string[]): boolean {
|
|
156
|
+
if (family === 'mongo') {
|
|
157
|
+
return (
|
|
158
|
+
path.at(-1) === 'additionalProperties' ||
|
|
159
|
+
(path.includes('jsonSchema') && (path.at(-2) === 'properties' || path.at(-1) === 'items')) ||
|
|
160
|
+
MONGO_PRESERVED_EMPTY.some((pattern) => matchesPath(path, pattern))
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
if (
|
|
164
|
+
path.length >= COLUMN_DEFAULT_VALUE.length &&
|
|
165
|
+
matchesPath(path.slice(0, COLUMN_DEFAULT_VALUE.length), COLUMN_DEFAULT_VALUE)
|
|
166
|
+
)
|
|
167
|
+
return true;
|
|
168
|
+
return SQL_PRESERVED_EMPTY.some((pattern) => matchesPath(path, pattern));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function isPreservedEmpty(family: Family, path: readonly string[], key: string): boolean {
|
|
172
|
+
if (key === 'nullable') return true;
|
|
173
|
+
if (key === 'elementNullable' && path.at(-2) === 'many') return true;
|
|
174
|
+
if (FRAMEWORK_PRESERVED_EMPTY.some((pattern) => matchesPath(path, pattern))) return true;
|
|
175
|
+
return isFamilyPreservedEmpty(family, path);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function omitDefaults(family: Family, value: Json, path: readonly string[]): Json {
|
|
179
|
+
if (Array.isArray(value)) return value.map((item) => omitDefaults(family, item, path));
|
|
180
|
+
if (!isRecord(value)) return value;
|
|
181
|
+
const result: JsonRecord = {};
|
|
182
|
+
for (const [key, child] of Object.entries(value)) {
|
|
183
|
+
const childPath = [...path, key];
|
|
184
|
+
if (key === '_generated') continue;
|
|
185
|
+
if (key === 'generated' && child === false) continue;
|
|
186
|
+
if ((key === 'onDelete' || key === 'onUpdate') && child === 'noAction') continue;
|
|
187
|
+
if (isDefaultValue(child) && !isPreservedEmpty(family, childPath, key)) continue;
|
|
188
|
+
result[key] = omitDefaults(family, child, childPath);
|
|
189
|
+
}
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function compareByName(a: Json, b: Json): number {
|
|
194
|
+
const nameA = isRecord(a) && typeof a['name'] === 'string' ? a['name'] : '';
|
|
195
|
+
const nameB = isRecord(b) && typeof b['name'] === 'string' ? b['name'] : '';
|
|
196
|
+
return compareCodeUnits(nameA, nameB);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function sortTableArrays(storage: Json): Json {
|
|
200
|
+
if (!isRecord(storage)) return storage;
|
|
201
|
+
const namespaces = storage['namespaces'];
|
|
202
|
+
if (!isRecord(namespaces)) return storage;
|
|
203
|
+
const sortedNamespaces: JsonRecord = {};
|
|
204
|
+
for (const [namespaceId, namespace] of Object.entries(namespaces)) {
|
|
205
|
+
const entries = isRecord(namespace) ? namespace['entries'] : undefined;
|
|
206
|
+
const tables = isRecord(entries) ? entries['table'] : undefined;
|
|
207
|
+
if (!isRecord(namespace) || !isRecord(entries) || !isRecord(tables)) {
|
|
208
|
+
sortedNamespaces[namespaceId] = namespace;
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
const sortedTables: JsonRecord = {};
|
|
212
|
+
for (const [tableName, table] of Object.entries(tables)) {
|
|
213
|
+
if (!isRecord(table)) {
|
|
214
|
+
sortedTables[tableName] = table;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
const sortedTable: JsonRecord = { ...table };
|
|
218
|
+
for (const key of ['checks', 'indexes', 'uniques']) {
|
|
219
|
+
const list = table[key];
|
|
220
|
+
if (Array.isArray(list)) sortedTable[key] = [...list].sort(compareByName);
|
|
221
|
+
}
|
|
222
|
+
sortedTables[tableName] = sortedTable;
|
|
223
|
+
}
|
|
224
|
+
sortedNamespaces[namespaceId] = { ...namespace, entries: { ...entries, table: sortedTables } };
|
|
225
|
+
}
|
|
226
|
+
return { ...storage, namespaces: sortedNamespaces };
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function orderTopLevel(value: JsonRecord): JsonRecord {
|
|
230
|
+
const ordered: JsonRecord = {};
|
|
231
|
+
const remaining = new Set(Object.keys(value));
|
|
232
|
+
for (const key of TOP_LEVEL_ORDER) {
|
|
233
|
+
const child = value[key];
|
|
234
|
+
if (child !== undefined) {
|
|
235
|
+
ordered[key] = child;
|
|
236
|
+
remaining.delete(key);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
for (const key of [...remaining].sort(compareCodeUnits)) {
|
|
240
|
+
const child = value[key];
|
|
241
|
+
if (child !== undefined) ordered[key] = child;
|
|
242
|
+
}
|
|
243
|
+
return ordered;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function omitNamespaceKinds(storage: JsonRecord): JsonRecord {
|
|
247
|
+
const namespaces = storage['namespaces'];
|
|
248
|
+
if (!isRecord(namespaces)) return storage;
|
|
249
|
+
const stripped: JsonRecord = {};
|
|
250
|
+
for (const [namespaceId, namespace] of Object.entries(namespaces)) {
|
|
251
|
+
if (isRecord(namespace)) {
|
|
252
|
+
const { kind: _kind, ...rest } = namespace;
|
|
253
|
+
stripped[namespaceId] = rest;
|
|
254
|
+
} else {
|
|
255
|
+
stripped[namespaceId] = namespace;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return { ...storage, namespaces: stripped };
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function computeStorageHash(family: Family, contract: JsonRecord): string {
|
|
262
|
+
const storage = isRecord(contract['storage']) ? contract['storage'] : {};
|
|
263
|
+
const { storageHash: _published, ...withoutHash } = storage;
|
|
264
|
+
const hashed: JsonRecord = {
|
|
265
|
+
schemaVersion: '1',
|
|
266
|
+
targetFamily: typeof contract['targetFamily'] === 'string' ? contract['targetFamily'] : '',
|
|
267
|
+
target: typeof contract['target'] === 'string' ? contract['target'] : '',
|
|
268
|
+
profileHash: '',
|
|
269
|
+
roots: {},
|
|
270
|
+
domain: { namespaces: {} },
|
|
271
|
+
storage: omitNamespaceKinds(withoutHash),
|
|
272
|
+
extensions: {},
|
|
273
|
+
capabilities: {},
|
|
274
|
+
meta: {},
|
|
275
|
+
};
|
|
276
|
+
const withoutDefaults = omitDefaults(family, hashed, []);
|
|
277
|
+
if (!isRecord(withoutDefaults)) return '';
|
|
278
|
+
const withSortedStorage =
|
|
279
|
+
family === 'sql'
|
|
280
|
+
? { ...withoutDefaults, storage: sortTableArrays(withoutDefaults['storage'] ?? {}) }
|
|
281
|
+
: withoutDefaults;
|
|
282
|
+
const sorted = sortKeys(withSortedStorage);
|
|
283
|
+
return isRecord(sorted) ? sha256(JSON.stringify(orderTopLevel(sorted), null, 2)) : '';
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function computeMigrationHash(metadata: JsonRecord, ops: Json): string {
|
|
287
|
+
const { migrationHash: _migrationHash, ...withoutHash } = metadata;
|
|
288
|
+
const parts = [canonicalizeJson(withoutHash), canonicalizeJson(ops)].map(sha256);
|
|
289
|
+
return sha256(canonicalizeJson(parts));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
interface ProjectFiles {
|
|
293
|
+
readonly json: readonly string[];
|
|
294
|
+
readonly migrationJson: readonly string[];
|
|
295
|
+
readonly refs: readonly string[];
|
|
296
|
+
readonly migrationTs: readonly string[];
|
|
297
|
+
readonly leftovers: readonly string[];
|
|
298
|
+
readonly unreadable: readonly { readonly dir: string; readonly code: string }[];
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function isDirectory(path: string): boolean {
|
|
302
|
+
try {
|
|
303
|
+
return statSync(path).isDirectory();
|
|
304
|
+
} catch {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function isFile(path: string): boolean {
|
|
310
|
+
try {
|
|
311
|
+
return statSync(path).isFile();
|
|
312
|
+
} catch {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** A file, or a link to one: the script reads and writes through links to files. */
|
|
318
|
+
function isFileEntry(dir: string, entry: Dirent): boolean {
|
|
319
|
+
return entry.isFile() || (entry.isSymbolicLink() && isFile(join(dir, entry.name)));
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** A file the script reads, by the path it was reached through: its own path rather than a link's. */
|
|
323
|
+
interface FoundFile {
|
|
324
|
+
readonly path: string;
|
|
325
|
+
readonly linked: boolean;
|
|
326
|
+
readonly inMigrationPackage: boolean;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function listFiles(root: string): ProjectFiles {
|
|
330
|
+
const leftovers: string[] = [];
|
|
331
|
+
const visited = new Set<string>();
|
|
332
|
+
const found = new Map<string, FoundFile>();
|
|
333
|
+
const unreadable: { dir: string; code: string }[] = [];
|
|
334
|
+
const visit = (dir: string): void => {
|
|
335
|
+
const realDir = realpathSync(dir);
|
|
336
|
+
if (visited.has(realDir)) return;
|
|
337
|
+
visited.add(realDir);
|
|
338
|
+
const listed = listDirectory(dir);
|
|
339
|
+
if (!listed.ok) {
|
|
340
|
+
unreadable.push({ dir, code: listed.code });
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
const entries = listed.entries.sort((a, b) => compareCodeUnits(a.name, b.name));
|
|
344
|
+
const inMigrationPackage = entries.some(
|
|
345
|
+
(entry) => entry.name === 'migration.json' && isFileEntry(dir, entry),
|
|
346
|
+
);
|
|
347
|
+
for (const entry of entries) {
|
|
348
|
+
const path = join(dir, entry.name);
|
|
349
|
+
if (entry.name.endsWith(TEMPORARY_SUFFIX)) {
|
|
350
|
+
leftovers.push(path);
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
if (entry.isDirectory() || (entry.isSymbolicLink() && isDirectory(path))) {
|
|
354
|
+
if (!SKIPPED_DIRECTORIES.has(entry.name) && !entry.name.startsWith('.')) visit(path);
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
if (!isFileEntry(dir, entry)) continue;
|
|
358
|
+
const realFile = realpathSync(path);
|
|
359
|
+
const linked = entry.isSymbolicLink();
|
|
360
|
+
const known = found.get(realFile);
|
|
361
|
+
if (known === undefined || (known.linked && !linked))
|
|
362
|
+
found.set(realFile, { path, linked, inMigrationPackage });
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
visit(root);
|
|
366
|
+
const files = [...found.values()];
|
|
367
|
+
const named = (test: (file: FoundFile, name: string) => boolean): string[] =>
|
|
368
|
+
files.filter((file) => test(file, basename(file.path))).map((file) => file.path);
|
|
369
|
+
return {
|
|
370
|
+
json: named((_file, name) => name.endsWith('.json')),
|
|
371
|
+
migrationJson: named((_file, name) => name === 'migration.json'),
|
|
372
|
+
refs: named((file, name) => name.endsWith('.json') && basename(dirname(file.path)) === 'refs'),
|
|
373
|
+
migrationTs: named((file, name) => name === 'migration.ts' && file.inMigrationPackage),
|
|
374
|
+
leftovers,
|
|
375
|
+
unreadable,
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
type DirectoryListing =
|
|
380
|
+
| { readonly ok: true; readonly entries: Dirent[] }
|
|
381
|
+
| { readonly ok: false; readonly code: string };
|
|
382
|
+
|
|
383
|
+
function listDirectory(dir: string): DirectoryListing {
|
|
384
|
+
try {
|
|
385
|
+
return { ok: true, entries: readdirSync(dir, { withFileTypes: true }) };
|
|
386
|
+
} catch (error) {
|
|
387
|
+
const code = error instanceof Error && 'code' in error ? String(error.code) : 'unknown error';
|
|
388
|
+
return { ok: false, code };
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function isSnapshotContract(path: string): boolean {
|
|
393
|
+
const snapshotDir = dirname(path);
|
|
394
|
+
return (
|
|
395
|
+
basename(path) === 'contract.json' &&
|
|
396
|
+
HASH.test(basename(snapshotDir)) &&
|
|
397
|
+
basename(dirname(snapshotDir)) === 'snapshots'
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function replaceQuotedHashes(text: string, hashes: ReadonlyMap<string, string>): string {
|
|
402
|
+
return text.replace(/"([0-9a-f]{64})"/g, (match: string, hash: string) => {
|
|
403
|
+
const next = hashes.get(hash);
|
|
404
|
+
return next === undefined ? match : `"${next}"`;
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function replaceHashTokens(text: string, hashes: ReadonlyMap<string, string>): string {
|
|
409
|
+
return text.replace(
|
|
410
|
+
/(?<![0-9a-f])[0-9a-f]{64}(?![0-9a-f])/g,
|
|
411
|
+
(hash: string) => hashes.get(hash) ?? hash,
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function readDirectory(dir: string): Map<string, string> {
|
|
416
|
+
const files = new Map<string, string>();
|
|
417
|
+
if (!existsSync(dir)) return files;
|
|
418
|
+
for (const entry of readdirSync(dir, { withFileTypes: true }))
|
|
419
|
+
if (isFileEntry(dir, entry) && !entry.name.endsWith(TEMPORARY_SUFFIX))
|
|
420
|
+
files.set(entry.name, readFileSync(join(dir, entry.name), 'utf8'));
|
|
421
|
+
return files;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function sameFiles(a: ReadonlyMap<string, string>, b: ReadonlyMap<string, string>): boolean {
|
|
425
|
+
return a.size === b.size && [...a].every(([name, content]) => b.get(name) === content);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function temporaryPath(path: string): string {
|
|
429
|
+
return join(dirname(path), `.${basename(path)}${TEMPORARY_SUFFIX}`);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function writeWithModeOf(path: string, text: string, modeSource: string): void {
|
|
433
|
+
writeFileSync(path, text);
|
|
434
|
+
if (existsSync(modeSource)) chmodSync(path, statSync(modeSource).mode & 0o7777);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
function writeFile(path: string, text: string): void {
|
|
438
|
+
const target = realpathSync(path);
|
|
439
|
+
const temporary = temporaryPath(target);
|
|
440
|
+
writeWithModeOf(temporary, text, target);
|
|
441
|
+
renameSync(temporary, target);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function writeDirectory(dir: string, files: ReadonlyMap<string, string>, sourceDir: string): void {
|
|
445
|
+
const temporary = temporaryPath(dir);
|
|
446
|
+
mkdirSync(temporary);
|
|
447
|
+
for (const [name, text] of files)
|
|
448
|
+
writeWithModeOf(join(temporary, name), text, join(sourceDir, name));
|
|
449
|
+
renameSync(temporary, dir);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function removeDirectory(dir: string): void {
|
|
453
|
+
const temporary = temporaryPath(dir);
|
|
454
|
+
renameSync(dir, temporary);
|
|
455
|
+
rmSync(temporary, { recursive: true, force: true });
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
function count(amount: number, singular: string, plural: string): string {
|
|
459
|
+
return `${amount} ${amount === 1 ? singular : plural}`;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function recordsOf(value: Json | undefined): [string, JsonRecord][] {
|
|
463
|
+
return isRecord(value)
|
|
464
|
+
? Object.entries(value).filter((entry): entry is [string, JsonRecord] => isRecord(entry[1]))
|
|
465
|
+
: [];
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
function coordinate(namespaceId: string, entityKind: string, entityName: string): JsonRecord {
|
|
469
|
+
return { plane: 'storage', namespaceId, entityKind, entityName };
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
interface Rewrite {
|
|
473
|
+
readonly contract: JsonRecord;
|
|
474
|
+
readonly changed: boolean;
|
|
475
|
+
/** The storage namespace each moved value object now lives in, by name. */
|
|
476
|
+
readonly valueObjectNamespaces: ReadonlyMap<string, string>;
|
|
477
|
+
readonly problems: readonly string[];
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/** Whether the contract keeps value objects in the domain plane, or refers to one by name. */
|
|
481
|
+
function holdsOldValueObjects(contract: JsonRecord): boolean {
|
|
482
|
+
const domain = isRecord(contract['domain']) ? contract['domain'] : {};
|
|
483
|
+
for (const [, namespace] of recordsOf(domain['namespaces'])) {
|
|
484
|
+
if (Object.hasOwn(namespace, 'valueObjects')) return true;
|
|
485
|
+
for (const [, model] of recordsOf(namespace['models']))
|
|
486
|
+
for (const [, field] of recordsOf(model['fields'])) {
|
|
487
|
+
const type = field['type'];
|
|
488
|
+
if (isRecord(type) && type['kind'] === 'valueObject' && typeof type['name'] === 'string')
|
|
489
|
+
return true;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return false;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/** A field that names a value object by `name`, pointed at it by its storage coordinate. */
|
|
496
|
+
function withValueObjectCoordinate(
|
|
497
|
+
field: JsonRecord,
|
|
498
|
+
namespaceOf: (name: string) => string | undefined,
|
|
499
|
+
where: string,
|
|
500
|
+
problems: string[],
|
|
501
|
+
): JsonRecord {
|
|
502
|
+
const type = field['type'];
|
|
503
|
+
if (!isRecord(type) || type['kind'] !== 'valueObject' || typeof type['name'] !== 'string')
|
|
504
|
+
return field;
|
|
505
|
+
const namespaceId = namespaceOf(type['name']);
|
|
506
|
+
if (namespaceId === undefined) {
|
|
507
|
+
problems.push(
|
|
508
|
+
`${where} holds the value object ${type['name']}, which the contract does not declare`,
|
|
509
|
+
);
|
|
510
|
+
return field;
|
|
511
|
+
}
|
|
512
|
+
return {
|
|
513
|
+
...field,
|
|
514
|
+
type: { kind: 'valueObject', ...coordinate(namespaceId, 'valueObject', type['name']) },
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
function valueSetsOf(storageNamespace: JsonRecord): JsonRecord {
|
|
519
|
+
const entries = isRecord(storageNamespace['entries']) ? storageNamespace['entries'] : {};
|
|
520
|
+
return isRecord(entries['valueSet']) ? entries['valueSet'] : {};
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/** The old MongoDB schema let a member leave `nullable` out, meaning `false`, and say `dict: false`; storage requires `nullable` and keeps `dict` only when it is `true`. */
|
|
524
|
+
function withStorageModifiers(member: JsonRecord): JsonRecord {
|
|
525
|
+
const { dict, ...rest } = member;
|
|
526
|
+
return {
|
|
527
|
+
...rest,
|
|
528
|
+
nullable: member['nullable'] === undefined ? false : member['nullable'],
|
|
529
|
+
...(dict === undefined || dict === false ? {} : { dict }),
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/** A value object member, with an enum reference pointed at the enum's storage value set. */
|
|
534
|
+
function rewrittenMember(
|
|
535
|
+
stored: JsonRecord,
|
|
536
|
+
storageNamespaces: JsonRecord,
|
|
537
|
+
where: string,
|
|
538
|
+
problems: string[],
|
|
539
|
+
): JsonRecord {
|
|
540
|
+
const member = withStorageModifiers(stored);
|
|
541
|
+
const valueSet = member['valueSet'];
|
|
542
|
+
if (!isRecord(valueSet) || valueSet['plane'] === 'storage') return member;
|
|
543
|
+
const namespaceId = valueSet['namespaceId'];
|
|
544
|
+
const name = valueSet['entityName'];
|
|
545
|
+
const storageNamespace =
|
|
546
|
+
typeof namespaceId === 'string' ? storageNamespaces[namespaceId] : undefined;
|
|
547
|
+
if (
|
|
548
|
+
typeof namespaceId !== 'string' ||
|
|
549
|
+
typeof name !== 'string' ||
|
|
550
|
+
!isRecord(storageNamespace) ||
|
|
551
|
+
!Object.hasOwn(valueSetsOf(storageNamespace), name)
|
|
552
|
+
) {
|
|
553
|
+
problems.push(
|
|
554
|
+
`${where} is typed by the enum ${String(name)}, which has no value set in storage namespace ${String(namespaceId)}`,
|
|
555
|
+
);
|
|
556
|
+
return member;
|
|
557
|
+
}
|
|
558
|
+
return { ...member, valueSet: { ...valueSet, ...coordinate(namespaceId, 'valueSet', name) } };
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/** Writes each discriminator's value set, `<Base>.<field>`, in its base table's namespace, and points the column at it, unless an enum already types the column. */
|
|
562
|
+
function writeDiscriminatorValueSets(
|
|
563
|
+
domainNamespaces: JsonRecord,
|
|
564
|
+
storageNamespaces: JsonRecord,
|
|
565
|
+
problems: string[],
|
|
566
|
+
): boolean {
|
|
567
|
+
let changed = false;
|
|
568
|
+
for (const [modelNamespaceId, namespace] of recordsOf(domainNamespaces)) {
|
|
569
|
+
for (const [modelName, model] of recordsOf(namespace['models'])) {
|
|
570
|
+
const discriminator = model['discriminator'];
|
|
571
|
+
const variants = model['variants'];
|
|
572
|
+
const storage = model['storage'];
|
|
573
|
+
if (!isRecord(discriminator) || !isRecord(variants) || !isRecord(storage)) continue;
|
|
574
|
+
const field = discriminator['field'];
|
|
575
|
+
const fields = isRecord(storage['fields']) ? storage['fields'] : {};
|
|
576
|
+
const fieldStorage = typeof field === 'string' ? fields[field] : undefined;
|
|
577
|
+
const columnName = isRecord(fieldStorage) ? fieldStorage['column'] : undefined;
|
|
578
|
+
const tableName = storage['table'];
|
|
579
|
+
const namespaceId =
|
|
580
|
+
typeof storage['namespaceId'] === 'string' ? storage['namespaceId'] : modelNamespaceId;
|
|
581
|
+
const storageNamespace = storageNamespaces[namespaceId];
|
|
582
|
+
const entries = isRecord(storageNamespace) ? storageNamespace['entries'] : undefined;
|
|
583
|
+
const tables = isRecord(entries) ? entries['table'] : undefined;
|
|
584
|
+
const table =
|
|
585
|
+
isRecord(tables) && typeof tableName === 'string' ? tables[tableName] : undefined;
|
|
586
|
+
const columns = isRecord(table) ? table['columns'] : undefined;
|
|
587
|
+
const column =
|
|
588
|
+
isRecord(columns) && typeof columnName === 'string' ? columns[columnName] : undefined;
|
|
589
|
+
if (
|
|
590
|
+
typeof field !== 'string' ||
|
|
591
|
+
typeof columnName !== 'string' ||
|
|
592
|
+
!isRecord(entries) ||
|
|
593
|
+
!isRecord(columns) ||
|
|
594
|
+
!isRecord(column) ||
|
|
595
|
+
column['valueSet'] !== undefined
|
|
596
|
+
)
|
|
597
|
+
continue;
|
|
598
|
+
const name = `${modelName}.${field}`;
|
|
599
|
+
const valueSets = isRecord(entries['valueSet']) ? entries['valueSet'] : {};
|
|
600
|
+
if (Object.hasOwn(valueSets, name)) {
|
|
601
|
+
problems.push(
|
|
602
|
+
`the discriminator ${name} writes the value set ${name} in storage namespace ${namespaceId}, which already holds a value set of that name; rename the enum`,
|
|
603
|
+
);
|
|
604
|
+
continue;
|
|
605
|
+
}
|
|
606
|
+
entries['valueSet'] = {
|
|
607
|
+
...valueSets,
|
|
608
|
+
[name]: { kind: 'valueSet', values: Object.keys(variants).sort(compareCodeUnits) },
|
|
609
|
+
};
|
|
610
|
+
columns[columnName] = { ...column, valueSet: coordinate(namespaceId, 'valueSet', name) };
|
|
611
|
+
changed = true;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
return changed;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
/** The contract with its value objects moved into storage, and on SQL each discriminator's value set written. */
|
|
618
|
+
function rewriteContract(contract: JsonRecord, family: Family): Rewrite {
|
|
619
|
+
const unchanged: Rewrite = {
|
|
620
|
+
contract,
|
|
621
|
+
changed: false,
|
|
622
|
+
valueObjectNamespaces: new Map(),
|
|
623
|
+
problems: [],
|
|
624
|
+
};
|
|
625
|
+
if (!holdsOldValueObjects(contract)) return unchanged;
|
|
626
|
+
const copy = parseJson(JSON.stringify(contract));
|
|
627
|
+
if (!isRecord(copy) || !isRecord(copy['domain']) || !isRecord(copy['storage'])) return unchanged;
|
|
628
|
+
const domainNamespaces = isRecord(copy['domain']['namespaces'])
|
|
629
|
+
? copy['domain']['namespaces']
|
|
630
|
+
: {};
|
|
631
|
+
const storageNamespaces = isRecord(copy['storage']['namespaces'])
|
|
632
|
+
? copy['storage']['namespaces']
|
|
633
|
+
: {};
|
|
634
|
+
const problems: string[] = [];
|
|
635
|
+
const valueObjectNamespaces = new Map<string, string>();
|
|
636
|
+
const declaredIn = new Map<string, Set<string>>();
|
|
637
|
+
for (const [namespaceId, namespace] of recordsOf(domainNamespaces))
|
|
638
|
+
for (const [name] of recordsOf(namespace['valueObjects']))
|
|
639
|
+
declaredIn.set(name, new Set([...(declaredIn.get(name) ?? []), namespaceId]));
|
|
640
|
+
const namespaceFor =
|
|
641
|
+
(ownNamespaceId: string) =>
|
|
642
|
+
(name: string): string | undefined => {
|
|
643
|
+
const namespaces = declaredIn.get(name);
|
|
644
|
+
if (namespaces === undefined) return undefined;
|
|
645
|
+
if (namespaces.has(ownNamespaceId)) return ownNamespaceId;
|
|
646
|
+
return namespaces.size === 1 ? [...namespaces][0] : undefined;
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
for (const [namespaceId, namespace] of recordsOf(domainNamespaces)) {
|
|
650
|
+
const valueObjects = namespace['valueObjects'];
|
|
651
|
+
delete namespace['valueObjects'];
|
|
652
|
+
for (const [modelName, model] of recordsOf(namespace['models'])) {
|
|
653
|
+
const fields = model['fields'];
|
|
654
|
+
for (const [fieldName, field] of recordsOf(fields))
|
|
655
|
+
if (isRecord(fields))
|
|
656
|
+
fields[fieldName] = withValueObjectCoordinate(
|
|
657
|
+
field,
|
|
658
|
+
namespaceFor(namespaceId),
|
|
659
|
+
`field ${modelName}.${fieldName}`,
|
|
660
|
+
problems,
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
if (!isRecord(valueObjects)) continue;
|
|
664
|
+
const storageNamespace = storageNamespaces[namespaceId];
|
|
665
|
+
if (!isRecord(storageNamespace)) {
|
|
666
|
+
problems.push(
|
|
667
|
+
`the value objects of domain namespace ${namespaceId} have no storage namespace ${namespaceId} to move to`,
|
|
668
|
+
);
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
const moved: JsonRecord = {};
|
|
672
|
+
for (const [name, valueObject] of recordsOf(valueObjects)) {
|
|
673
|
+
valueObjectNamespaces.set(name, namespaceId);
|
|
674
|
+
const members: JsonRecord = {};
|
|
675
|
+
for (const [memberName, member] of recordsOf(valueObject['fields'])) {
|
|
676
|
+
const where = `value object member ${name}.${memberName}`;
|
|
677
|
+
members[memberName] = rewrittenMember(
|
|
678
|
+
withValueObjectCoordinate(member, namespaceFor(namespaceId), where, problems),
|
|
679
|
+
storageNamespaces,
|
|
680
|
+
where,
|
|
681
|
+
problems,
|
|
682
|
+
);
|
|
683
|
+
}
|
|
684
|
+
moved[name] = { ...valueObject, fields: members };
|
|
685
|
+
}
|
|
686
|
+
const entries = isRecord(storageNamespace['entries']) ? storageNamespace['entries'] : {};
|
|
687
|
+
storageNamespace['entries'] = { ...entries, valueObject: moved };
|
|
688
|
+
}
|
|
689
|
+
if (family === 'sql') writeDiscriminatorValueSets(domainNamespaces, storageNamespaces, problems);
|
|
690
|
+
if (Object.hasOwn(copy, 'valueObjects')) delete copy['valueObjects'];
|
|
691
|
+
return { contract: copy, changed: true, valueObjectNamespaces, problems };
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
function withStorageHash(contract: JsonRecord, hash: string): JsonRecord {
|
|
695
|
+
const storage = contract['storage'];
|
|
696
|
+
if (!isRecord(storage) || typeof storage['storageHash'] !== 'string') return contract;
|
|
697
|
+
return { ...contract, storage: { ...storage, storageHash: hash } };
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
function lineEndingOf(text: string): string {
|
|
701
|
+
return text.includes('\r\n') ? '\r\n' : '\n';
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
/** The contract written the way the file held it: a snapshot's canonical line, or indented JSON, with the file's byte order mark and line ending. */
|
|
705
|
+
function writtenForm(contract: JsonRecord, original: JsonRecord, text: string): string {
|
|
706
|
+
const mark = text.startsWith(BYTE_ORDER_MARK) ? BYTE_ORDER_MARK : '';
|
|
707
|
+
const body = withoutByteOrderMark(text);
|
|
708
|
+
const lineEnding = lineEndingOf(body);
|
|
709
|
+
const finalNewline = body.endsWith('\n') ? lineEnding : '';
|
|
710
|
+
if (body === `${canonicalizeJson(original)}${finalNewline}`)
|
|
711
|
+
return `${mark}${canonicalizeJson(contract)}${finalNewline}`;
|
|
712
|
+
const indented = JSON.stringify(contract, null, 2).replaceAll('\n', lineEnding);
|
|
713
|
+
return `${mark}${indented}${finalNewline}`;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
interface Block {
|
|
717
|
+
readonly start: number;
|
|
718
|
+
end: number;
|
|
719
|
+
readonly label: string;
|
|
720
|
+
readonly parent: Block | undefined;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
function scanBlocks(text: string): Block[] {
|
|
724
|
+
const blocks: Block[] = [];
|
|
725
|
+
const open: Block[] = [];
|
|
726
|
+
let quote: string | undefined;
|
|
727
|
+
for (let index = 0; index < text.length; index++) {
|
|
728
|
+
const char = text[index];
|
|
729
|
+
if (quote !== undefined) {
|
|
730
|
+
if (char === '\\') index++;
|
|
731
|
+
else if (char === quote) quote = undefined;
|
|
732
|
+
continue;
|
|
733
|
+
}
|
|
734
|
+
if (char === '/' && text[index + 1] === '/') {
|
|
735
|
+
const end = text.indexOf('\n', index);
|
|
736
|
+
index = end === -1 ? text.length : end;
|
|
737
|
+
continue;
|
|
738
|
+
}
|
|
739
|
+
if (char === '/' && text[index + 1] === '*') {
|
|
740
|
+
const end = text.indexOf('*/', index + 2);
|
|
741
|
+
index = end === -1 ? text.length : end + 1;
|
|
742
|
+
continue;
|
|
743
|
+
}
|
|
744
|
+
if (char === "'" || char === '"' || char === '`') {
|
|
745
|
+
quote = char;
|
|
746
|
+
continue;
|
|
747
|
+
}
|
|
748
|
+
if (char === '{') {
|
|
749
|
+
const key =
|
|
750
|
+
/(?:readonly\s+)?([\p{ID_Start}_$][\p{ID_Continue}$]*|'[^']*'|"[^"]*")\s*\??\s*:\s*$/u.exec(
|
|
751
|
+
text.slice(Math.max(0, index - 200), index),
|
|
752
|
+
);
|
|
753
|
+
const block: Block = {
|
|
754
|
+
start: index,
|
|
755
|
+
end: text.length,
|
|
756
|
+
label: key?.[1]?.replace(/^['"]|['"]$/g, '') ?? '',
|
|
757
|
+
parent: open.at(-1),
|
|
758
|
+
};
|
|
759
|
+
open.push(block);
|
|
760
|
+
blocks.push(block);
|
|
761
|
+
} else if (char === '}') {
|
|
762
|
+
const block = open.pop();
|
|
763
|
+
if (block !== undefined) block.end = index;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
return blocks;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
function lineStart(text: string, position: number): number {
|
|
770
|
+
return text.lastIndexOf('\n', position - 1) + 1;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/** The end of the member a block closes: past its `;` and the line break after it. */
|
|
774
|
+
function memberEnd(text: string, block: Block): number {
|
|
775
|
+
const rest = /^\s*;?[ \t]*(?:\r?\n)?/.exec(text.slice(block.end + 1));
|
|
776
|
+
return block.end + 1 + (rest?.[0].length ?? 0);
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
function indentOf(text: string, position: number): string {
|
|
780
|
+
return /^[ \t]*/.exec(text.slice(lineStart(text, position)))?.[0] ?? '';
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
function childBlocks(blocks: readonly Block[], parent: Block): Block[] {
|
|
784
|
+
return blocks.filter((block) => block.parent === parent);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
function isUnder(block: Block, labels: readonly string[]): boolean {
|
|
788
|
+
let current = block.parent;
|
|
789
|
+
for (const label of labels) {
|
|
790
|
+
if (current?.label !== label) return false;
|
|
791
|
+
current = current.parent;
|
|
792
|
+
}
|
|
793
|
+
return true;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/** A block re-indented from `from` to `to`, its first line left as it starts. */
|
|
797
|
+
function reindent(literal: string, from: string, to: string): string {
|
|
798
|
+
return literal
|
|
799
|
+
.split('\n')
|
|
800
|
+
.map((line, index) =>
|
|
801
|
+
index === 0 || !line.startsWith(from) ? line : `${to}${line.slice(from.length)}`,
|
|
802
|
+
)
|
|
803
|
+
.join('\n');
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
interface Edit {
|
|
807
|
+
readonly start: number;
|
|
808
|
+
readonly end: number;
|
|
809
|
+
readonly text: string;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
const STORAGE_NAMESPACES = "ContractBase['storage']['namespaces']";
|
|
813
|
+
|
|
814
|
+
function dtsPathOf(contractPath: string, snapshot: boolean): string {
|
|
815
|
+
return snapshot
|
|
816
|
+
? join(dirname(contractPath), 'contract.d.ts')
|
|
817
|
+
: `${contractPath.slice(0, -'.json'.length)}.d.ts`;
|
|
818
|
+
}
|
|
819
|
+
const DTS_LINE_WIDTH = 100;
|
|
820
|
+
|
|
821
|
+
/**
|
|
822
|
+
* The same move in `contract.d.ts`: each `valueObjects` type of a domain namespace goes into its storage namespace's `entries` as `valueObject`, a member's enum reference names the storage value set, a field's value object type names its coordinate, the top-level `valueObjects` type goes, and the value object and field type aliases read storage. The discriminator value sets are not typed: a re-emit types them.
|
|
823
|
+
*/
|
|
824
|
+
function rewriteDts(
|
|
825
|
+
text: string,
|
|
826
|
+
valueObjectNamespaces: ReadonlyMap<string, string>,
|
|
827
|
+
hashes: ReadonlyMap<string, string>,
|
|
828
|
+
): string {
|
|
829
|
+
const lineEnding = lineEndingOf(text);
|
|
830
|
+
const blocks = scanBlocks(text);
|
|
831
|
+
const edits: Edit[] = [];
|
|
832
|
+
const moved = new Map<string, string>();
|
|
833
|
+
for (const block of blocks) {
|
|
834
|
+
if (block.label !== 'valueObjects') continue;
|
|
835
|
+
const namespace = block.parent;
|
|
836
|
+
if (namespace !== undefined && isUnder(namespace, ['namespaces', 'domain'])) {
|
|
837
|
+
const literal = text
|
|
838
|
+
.slice(block.start, block.end + 1)
|
|
839
|
+
.replace(/readonly plane: (['"])domain\1/g, "readonly plane: 'storage'")
|
|
840
|
+
.replace(/readonly entityKind: (['"])enum\1/g, "readonly entityKind: 'valueSet'");
|
|
841
|
+
moved.set(namespace.label, reindent(literal, indentOf(text, block.start), ''));
|
|
842
|
+
edits.push({ start: lineStart(text, block.start), end: memberEnd(text, block), text: '' });
|
|
843
|
+
} else if (
|
|
844
|
+
namespace !== undefined &&
|
|
845
|
+
childBlocks(blocks, namespace).some((sibling) => sibling.label === 'domain')
|
|
846
|
+
) {
|
|
847
|
+
edits.push({ start: lineStart(text, block.start), end: memberEnd(text, block), text: '' });
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
for (const block of blocks) {
|
|
851
|
+
if (block.label !== 'entries' || block.parent === undefined) continue;
|
|
852
|
+
if (!isUnder(block.parent, ['namespaces']) || isUnder(block.parent, ['namespaces', 'domain']))
|
|
853
|
+
continue;
|
|
854
|
+
const literal = moved.get(block.parent.label);
|
|
855
|
+
if (literal === undefined) continue;
|
|
856
|
+
const indent = `${indentOf(text, block.start)} `;
|
|
857
|
+
const closing = lineStart(text, block.end);
|
|
858
|
+
edits.push({
|
|
859
|
+
start: closing,
|
|
860
|
+
end: closing,
|
|
861
|
+
text: `${indent}readonly valueObject: ${reindent(literal, '', indent)};${lineEnding}`,
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
let result = text;
|
|
865
|
+
for (const edit of edits.sort((a, b) => b.start - a.start))
|
|
866
|
+
result = `${result.slice(0, edit.start)}${edit.text}${result.slice(edit.end)}`;
|
|
867
|
+
result = result
|
|
868
|
+
.replace(
|
|
869
|
+
/\{\s*readonly kind: (['"])valueObject\1;\s*readonly name: (['"])([^'"]*)\2;?\s*\}/g,
|
|
870
|
+
(
|
|
871
|
+
match: string,
|
|
872
|
+
_quote: string,
|
|
873
|
+
_nameQuote: string,
|
|
874
|
+
name: string,
|
|
875
|
+
offset: number,
|
|
876
|
+
whole: string,
|
|
877
|
+
) => {
|
|
878
|
+
const namespaceId = valueObjectNamespaces.get(name);
|
|
879
|
+
return namespaceId === undefined
|
|
880
|
+
? match
|
|
881
|
+
: coordinateTypeLiteral(namespaceId, name, whole, offset, lineEnding);
|
|
882
|
+
},
|
|
883
|
+
)
|
|
884
|
+
.replace(
|
|
885
|
+
/ValueObjectTypesFromDomain<(\s*)ContractBase\['domain'\]\['namespaces'\]/g,
|
|
886
|
+
`ValueObjectTypesFromStorage<$1${STORAGE_NAMESPACES}`,
|
|
887
|
+
)
|
|
888
|
+
.replace(/\bValueObjectTypesFromDomain\b/g, 'ValueObjectTypesFromStorage');
|
|
889
|
+
return replaceHashTokens(withStorageNamespacesArgument(result), hashes);
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
/** `FieldTypesFromDomain` with the storage namespaces as its sixth argument, which it now requires of every contract. */
|
|
893
|
+
function withStorageNamespacesArgument(text: string): string {
|
|
894
|
+
const lineEnding = lineEndingOf(text);
|
|
895
|
+
return text.replace(
|
|
896
|
+
/(FieldTypesFromDomain<[^<>]*?(['"])(?:output|input)\2)(\s*)>/g,
|
|
897
|
+
(_match: string, head: string, _quote: string, space: string) =>
|
|
898
|
+
space.includes('\n')
|
|
899
|
+
? `${head},${lineEnding} ${STORAGE_NAMESPACES}${lineEnding}>`
|
|
900
|
+
: `${head}, ${STORAGE_NAMESPACES}>`,
|
|
901
|
+
);
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
/** A value object field's coordinate type, on one line when it fits the emitter's line width, else one member per line. */
|
|
905
|
+
function coordinateTypeLiteral(
|
|
906
|
+
namespaceId: string,
|
|
907
|
+
name: string,
|
|
908
|
+
text: string,
|
|
909
|
+
offset: number,
|
|
910
|
+
lineEnding: string,
|
|
911
|
+
): string {
|
|
912
|
+
const members = [
|
|
913
|
+
"readonly kind: 'valueObject'",
|
|
914
|
+
"readonly plane: 'storage'",
|
|
915
|
+
`readonly namespaceId: '${namespaceId}'`,
|
|
916
|
+
"readonly entityKind: 'valueObject'",
|
|
917
|
+
`readonly entityName: '${name}'`,
|
|
918
|
+
];
|
|
919
|
+
const single = `{ ${members.join('; ')} }`;
|
|
920
|
+
if (offset - lineStart(text, offset) + single.length + 1 <= DTS_LINE_WIDTH) return single;
|
|
921
|
+
const indent = indentOf(text, offset);
|
|
922
|
+
const lines = members.map((member) => `${indent} ${member};`);
|
|
923
|
+
return `{${lineEnding}${lines.join(lineEnding)}${lineEnding}${indent}}`;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
interface ContractPlan {
|
|
927
|
+
readonly path: string;
|
|
928
|
+
readonly snapshot: boolean;
|
|
929
|
+
readonly oldHash: string;
|
|
930
|
+
readonly newHash: string;
|
|
931
|
+
readonly content: string;
|
|
932
|
+
readonly valueObjectNamespaces: ReadonlyMap<string, string>;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
interface MigrationOps {
|
|
936
|
+
readonly path: string;
|
|
937
|
+
/** `undefined` when the package has no `ops.json` or it is not valid JSON. */
|
|
938
|
+
readonly ops: Json | undefined;
|
|
939
|
+
readonly unreadable: boolean;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
function readOps(migrationDir: string): MigrationOps {
|
|
943
|
+
const path = join(migrationDir, 'ops.json');
|
|
944
|
+
if (!existsSync(path)) return { path, ops: undefined, unreadable: false };
|
|
945
|
+
const ops = parseJson(readFileSync(path, 'utf8'));
|
|
946
|
+
return { path, ops, unreadable: ops === undefined };
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
function familyOf(contract: JsonRecord): Family | undefined {
|
|
950
|
+
const family = contract['targetFamily'];
|
|
951
|
+
return family === 'sql' || family === 'mongo' ? family : undefined;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
function summary(
|
|
955
|
+
root: string,
|
|
956
|
+
contractsFound: number,
|
|
957
|
+
files: number,
|
|
958
|
+
directories: number,
|
|
959
|
+
hashes: ReadonlyMap<string, string>,
|
|
960
|
+
): readonly string[] {
|
|
961
|
+
if (contractsFound === 0)
|
|
962
|
+
return [`No SQL or MongoDB contract was found under ${root}; nothing changed.`];
|
|
963
|
+
if (files === 0 && directories === 0)
|
|
964
|
+
return ['No contract keeps value objects in the domain plane; nothing changed.'];
|
|
965
|
+
const renamed = count(directories, 'snapshot directory', 'snapshot directories');
|
|
966
|
+
const changes = `Rewrote ${count(files, 'file', 'files')} and renamed ${renamed}.`;
|
|
967
|
+
if (hashes.size === 0) return [changes];
|
|
968
|
+
return [
|
|
969
|
+
`${changes} Storage hashes changed (old -> new):`,
|
|
970
|
+
...[...hashes]
|
|
971
|
+
.sort(([a], [b]) => compareCodeUnits(a, b))
|
|
972
|
+
.map(([oldHash, newHash]) => ` ${oldHash} -> ${newHash}`),
|
|
973
|
+
];
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
const JSON_FILES_THAT_MUST_PARSE = new Set(['contract.json', 'migration.json']);
|
|
977
|
+
|
|
978
|
+
function main({
|
|
979
|
+
root,
|
|
980
|
+
errors,
|
|
981
|
+
}: {
|
|
982
|
+
readonly root: string;
|
|
983
|
+
readonly errors: readonly string[];
|
|
984
|
+
}): number {
|
|
985
|
+
if (errors.length > 0) {
|
|
986
|
+
process.stderr.write(`${errors.join('\n')}\n`);
|
|
987
|
+
return 1;
|
|
988
|
+
}
|
|
989
|
+
const display = (path: string): string => relative(root, path).split(sep).join('/');
|
|
990
|
+
const files = listFiles(root);
|
|
991
|
+
if (files.unreadable.length > 0) {
|
|
992
|
+
process.stderr.write(
|
|
993
|
+
`${files.unreadable
|
|
994
|
+
.map(
|
|
995
|
+
({ dir, code }) =>
|
|
996
|
+
`${display(dir)}: cannot read the directory (${code}); give the script read access to it, or move it out of the project, and run the script again`,
|
|
997
|
+
)
|
|
998
|
+
.join('\n')}\n`,
|
|
999
|
+
);
|
|
1000
|
+
return 1;
|
|
1001
|
+
}
|
|
1002
|
+
const plans: ContractPlan[] = [];
|
|
1003
|
+
const argumentWrites = new Map<string, string>();
|
|
1004
|
+
const stops: string[] = [];
|
|
1005
|
+
let contractsFound = 0;
|
|
1006
|
+
|
|
1007
|
+
for (const path of files.json) {
|
|
1008
|
+
const text = readFileSync(path, 'utf8');
|
|
1009
|
+
const contract = parseJson(text);
|
|
1010
|
+
if (
|
|
1011
|
+
contract === undefined &&
|
|
1012
|
+
(JSON_FILES_THAT_MUST_PARSE.has(basename(path)) || files.refs.includes(path))
|
|
1013
|
+
) {
|
|
1014
|
+
stops.push(`${display(path)}: not valid JSON`);
|
|
1015
|
+
continue;
|
|
1016
|
+
}
|
|
1017
|
+
if (!isRecord(contract) || typeof contract['target'] !== 'string') continue;
|
|
1018
|
+
const family = familyOf(contract);
|
|
1019
|
+
if (family === undefined || !isRecord(contract['storage'])) continue;
|
|
1020
|
+
contractsFound++;
|
|
1021
|
+
const rewrite = rewriteContract(contract, family);
|
|
1022
|
+
const snapshot = isSnapshotContract(path);
|
|
1023
|
+
if (!rewrite.changed) {
|
|
1024
|
+
const dtsPath = dtsPathOf(path, snapshot);
|
|
1025
|
+
if (existsSync(dtsPath)) {
|
|
1026
|
+
const dts = readFileSync(dtsPath, 'utf8');
|
|
1027
|
+
const next = withStorageNamespacesArgument(dts);
|
|
1028
|
+
if (next !== dts) argumentWrites.set(dtsPath, next);
|
|
1029
|
+
}
|
|
1030
|
+
continue;
|
|
1031
|
+
}
|
|
1032
|
+
const stored = contract['storage']['storageHash'];
|
|
1033
|
+
const oldHash = snapshot ? basename(dirname(path)) : typeof stored === 'string' ? stored : '';
|
|
1034
|
+
const computed = computeStorageHash(family, contract);
|
|
1035
|
+
if (computed !== oldHash || (typeof stored === 'string' && stored !== oldHash)) {
|
|
1036
|
+
stops.push(
|
|
1037
|
+
`${display(path)}: the stored storage hash ${oldHash} does not match the contract's content, which hashes to ${computed}; restore the file from version control, or re-emit it, and run the script again`,
|
|
1038
|
+
);
|
|
1039
|
+
continue;
|
|
1040
|
+
}
|
|
1041
|
+
if (rewrite.problems.length > 0) {
|
|
1042
|
+
for (const problem of rewrite.problems)
|
|
1043
|
+
stops.push(
|
|
1044
|
+
`${display(path)}: ${problem}; restore the file from version control, or re-emit it, and run the script again`,
|
|
1045
|
+
);
|
|
1046
|
+
continue;
|
|
1047
|
+
}
|
|
1048
|
+
const newHash = computeStorageHash(family, rewrite.contract);
|
|
1049
|
+
plans.push({
|
|
1050
|
+
path,
|
|
1051
|
+
snapshot,
|
|
1052
|
+
oldHash,
|
|
1053
|
+
newHash,
|
|
1054
|
+
content: writtenForm(withStorageHash(rewrite.contract, newHash), contract, text),
|
|
1055
|
+
valueObjectNamespaces: rewrite.valueObjectNamespaces,
|
|
1056
|
+
});
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
const hashes = new Map<string, string>();
|
|
1060
|
+
for (const plan of [...plans].sort((a, b) => Number(b.snapshot) - Number(a.snapshot)))
|
|
1061
|
+
if (plan.oldHash !== plan.newHash && !hashes.has(plan.oldHash))
|
|
1062
|
+
hashes.set(plan.oldHash, plan.newHash);
|
|
1063
|
+
|
|
1064
|
+
const newDirectories = new Map<string, Map<string, string>>();
|
|
1065
|
+
const directorySources = new Map<string, string>();
|
|
1066
|
+
const sourceDirectories = new Set<string>();
|
|
1067
|
+
const removals = new Set<string>();
|
|
1068
|
+
const snapshotRewrites: [string, string][] = [];
|
|
1069
|
+
const referenceWrites = new Map<string, string>();
|
|
1070
|
+
const contractWrites = new Map<string, string>();
|
|
1071
|
+
for (const plan of plans) {
|
|
1072
|
+
const dtsPath = dtsPathOf(plan.path, plan.snapshot);
|
|
1073
|
+
const dtsHashes = new Map([...hashes, [plan.oldHash, plan.newHash]]);
|
|
1074
|
+
const dts = existsSync(dtsPath)
|
|
1075
|
+
? rewriteDts(readFileSync(dtsPath, 'utf8'), plan.valueObjectNamespaces, dtsHashes)
|
|
1076
|
+
: undefined;
|
|
1077
|
+
if (!plan.snapshot) {
|
|
1078
|
+
if (dts !== undefined) referenceWrites.set(dtsPath, dts);
|
|
1079
|
+
contractWrites.set(plan.path, plan.content);
|
|
1080
|
+
continue;
|
|
1081
|
+
}
|
|
1082
|
+
const oldDir = dirname(plan.path);
|
|
1083
|
+
const newDir = join(dirname(oldDir), plan.newHash);
|
|
1084
|
+
sourceDirectories.add(oldDir);
|
|
1085
|
+
if (newDir === oldDir) {
|
|
1086
|
+
if (dts !== undefined) snapshotRewrites.push([dtsPath, dts]);
|
|
1087
|
+
snapshotRewrites.push([plan.path, plan.content]);
|
|
1088
|
+
continue;
|
|
1089
|
+
}
|
|
1090
|
+
removals.add(oldDir);
|
|
1091
|
+
const content = readDirectory(oldDir);
|
|
1092
|
+
content.set('contract.json', plan.content);
|
|
1093
|
+
if (dts !== undefined) content.set('contract.d.ts', dts);
|
|
1094
|
+
const planned = newDirectories.get(newDir);
|
|
1095
|
+
if (planned !== undefined && !sameFiles(planned, content)) {
|
|
1096
|
+
stops.push(`${display(newDir)}: snapshot directory already exists with different content`);
|
|
1097
|
+
continue;
|
|
1098
|
+
}
|
|
1099
|
+
newDirectories.set(newDir, content);
|
|
1100
|
+
directorySources.set(newDir, oldDir);
|
|
1101
|
+
}
|
|
1102
|
+
for (const [dir, content] of newDirectories) {
|
|
1103
|
+
if (sourceDirectories.has(dir) || !existsSync(dir)) continue;
|
|
1104
|
+
if (sameFiles(readDirectory(dir), content)) newDirectories.delete(dir);
|
|
1105
|
+
else stops.push(`${display(dir)}: snapshot directory already exists with different content`);
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
for (const path of files.migrationJson) {
|
|
1109
|
+
const text = readFileSync(path, 'utf8');
|
|
1110
|
+
const metadata = parseJson(text);
|
|
1111
|
+
if (!isRecord(metadata)) continue;
|
|
1112
|
+
const from = metadata['from'];
|
|
1113
|
+
const to = metadata['to'];
|
|
1114
|
+
const nextFrom = typeof from === 'string' ? (hashes.get(from) ?? from) : from;
|
|
1115
|
+
const nextTo = typeof to === 'string' ? (hashes.get(to) ?? to) : to;
|
|
1116
|
+
if (nextFrom === from && nextTo === to) continue;
|
|
1117
|
+
const { path: opsPath, ops, unreadable } = readOps(dirname(path));
|
|
1118
|
+
if (unreadable) {
|
|
1119
|
+
stops.push(`${display(opsPath)}: not valid JSON`);
|
|
1120
|
+
continue;
|
|
1121
|
+
}
|
|
1122
|
+
const oldMigrationHash = metadata['migrationHash'];
|
|
1123
|
+
let next = replaceQuotedHashes(text, hashes);
|
|
1124
|
+
if (
|
|
1125
|
+
ops !== undefined &&
|
|
1126
|
+
typeof oldMigrationHash === 'string' &&
|
|
1127
|
+
nextFrom !== undefined &&
|
|
1128
|
+
nextTo !== undefined
|
|
1129
|
+
) {
|
|
1130
|
+
const migrationHash = computeMigrationHash({ ...metadata, from: nextFrom, to: nextTo }, ops);
|
|
1131
|
+
next = next.replace(`"${oldMigrationHash}"`, `"${migrationHash}"`);
|
|
1132
|
+
}
|
|
1133
|
+
referenceWrites.set(path, next);
|
|
1134
|
+
}
|
|
1135
|
+
for (const path of files.refs) {
|
|
1136
|
+
const text = readFileSync(path, 'utf8');
|
|
1137
|
+
const next = replaceQuotedHashes(text, hashes);
|
|
1138
|
+
if (next !== text) referenceWrites.set(path, next);
|
|
1139
|
+
}
|
|
1140
|
+
for (const path of files.migrationTs) {
|
|
1141
|
+
const text = readFileSync(path, 'utf8');
|
|
1142
|
+
const next = replaceHashTokens(text, hashes);
|
|
1143
|
+
if (next !== text) referenceWrites.set(path, next);
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
if (stops.length > 0) {
|
|
1147
|
+
process.stderr.write(`${[...new Set(stops)].join('\n')}\n`);
|
|
1148
|
+
return 1;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
try {
|
|
1152
|
+
for (const path of files.leftovers) rmSync(path, { recursive: true, force: true });
|
|
1153
|
+
for (const [dir, content] of newDirectories)
|
|
1154
|
+
writeDirectory(dir, content, directorySources.get(dir) ?? dir);
|
|
1155
|
+
for (const [path, text] of snapshotRewrites) writeFile(path, text);
|
|
1156
|
+
for (const [path, text] of referenceWrites) writeFile(path, text);
|
|
1157
|
+
for (const [path, text] of contractWrites) writeFile(path, text);
|
|
1158
|
+
for (const [path, text] of argumentWrites) writeFile(path, text);
|
|
1159
|
+
for (const dir of removals) removeDirectory(dir);
|
|
1160
|
+
} catch (error) {
|
|
1161
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1162
|
+
process.stderr.write(
|
|
1163
|
+
`${message}; the upgrade stopped partway, run the script again to finish it\n`,
|
|
1164
|
+
);
|
|
1165
|
+
return 1;
|
|
1166
|
+
}
|
|
1167
|
+
const rewrittenFiles =
|
|
1168
|
+
snapshotRewrites.length + referenceWrites.size + contractWrites.size + argumentWrites.size;
|
|
1169
|
+
const lines = summary(root, contractsFound, rewrittenFiles, removals.size, hashes);
|
|
1170
|
+
process.stdout.write(`${lines.join('\n')}\n`);
|
|
1171
|
+
return 0;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
function parseRoot(args: readonly string[]): { readonly root: string; readonly errors: string[] } {
|
|
1175
|
+
const errors = args.filter((arg) => arg.startsWith('-')).map((arg) => `${arg}: unknown option`);
|
|
1176
|
+
const positional = args.filter((arg) => !arg.startsWith('-'));
|
|
1177
|
+
if (positional.length > 1) errors.push(`expected one project root, got ${positional.length}`);
|
|
1178
|
+
const root = resolve(positional[0] ?? process.cwd());
|
|
1179
|
+
if (errors.length === 0 && !isDirectory(root)) errors.push(`${root}: not a directory`);
|
|
1180
|
+
if (errors.length > 0) errors.push('Usage: node value-objects-in-storage.ts [project-root]');
|
|
1181
|
+
return { root, errors };
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
process.exitCode = main(parseRoot(process.argv.slice(2)));
|