@prisma/orm-mongo 8.0.0-rc.25-dev.29 → 8.0.0-rc.26
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/README.md +6 -5
- package/dist/bson.d.mts +2 -1
- package/dist/components__runtime.d.mts +3 -1
- package/dist/config.d.mts +2 -1
- package/dist/config.d.mts.map +1 -1
- package/dist/contract-builder.d.mts +11 -12
- package/dist/contract-builder.d.mts.map +1 -1
- package/dist/contract-types.d.mts +5 -3
- package/dist/contract__types.d.mts +3 -1
- package/dist/control.d.mts +2 -1
- package/dist/control.d.mts.map +1 -1
- package/dist/family-contract.d.mts +3 -1
- package/dist/family-runtime.d.mts +3 -1
- package/dist/family.d.mts +2 -1
- package/dist/family__control.d.mts +3 -1
- package/dist/init-quick-reference.md +1 -1
- package/dist/init.d.mts +2 -1
- package/dist/init.d.mts.map +1 -1
- package/dist/migration-tools__aggregate.d.mts +3 -1
- package/dist/migration-tools__hash.d.mts +3 -1
- package/dist/migration-tools__io.d.mts +3 -1
- package/dist/migration-tools__spaces.d.mts +3 -1
- package/dist/migration.d.mts +3 -1
- package/dist/{mongo-static-CZlnpepm-DnjIfx0L.mjs → mongo-static-DnxWWp96-D-vo6-SA.mjs} +4 -4
- package/dist/mongo-static-DnxWWp96-D-vo6-SA.mjs.map +1 -0
- package/dist/orm.d.mts +3 -1
- package/dist/query-ast__execution.d.mts +3 -1
- package/dist/query-builder.d.mts +3 -1
- package/dist/runtime.d.mts +3 -1
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +6 -6
- package/dist/runtime.mjs.map +1 -1
- package/dist/static.d.mts +2 -1
- package/dist/static.d.mts.map +1 -1
- package/dist/static.mjs +1 -1
- package/dist/target.d.mts +2 -1
- package/dist/target__codec-ids.d.mts +3 -1
- package/dist/target__codec-types.d.mts +3 -1
- package/dist/target__migration.d.mts +3 -1
- package/dist/target__runtime.d.mts +2 -1
- package/dist/value.d.mts +3 -1
- package/dist/vite-plugin-contract-emit.d.mts +3 -1
- package/package.json +12 -81
- package/skills/prisma-8/SKILL.md +8 -8
- package/skills/prisma-8/references/contract.md +8 -8
- package/skills/prisma-8/references/debug.md +11 -11
- package/skills/prisma-8/references/migration-model.md +17 -17
- package/skills/prisma-8/references/migration-review.md +21 -21
- package/skills/prisma-8/references/migrations.md +58 -42
- package/skills/prisma-8/references/queries-postgres.md +51 -8
- package/skills/prisma-8/references/queries.md +2 -2
- package/skills/prisma-8/references/quickstart.md +11 -11
- package/skills/prisma-8/references/runtime.md +3 -3
- package/skills/prisma-8/references/supabase.md +2 -2
- package/skills/prisma-8/references/upgrade-app.md +56 -23
- package/skills/prisma-8/references/upgrade-extension.md +35 -14
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/instructions.md +2385 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-hash-inputs/contract-hash-inputs.ts +2048 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-signature-names/contract-signature-names.ts +667 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/facade-paths-an-application-uses/facade-paths-an-application-uses.ts +667 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/platform-paths-an-extension-uses/platform-paths-an-extension-uses.ts +1996 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/stored-files-format-version/stored-files-format-version.ts +586 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.11-to-0.12/instructions.md +1 -1
- package/skills/prisma-8/upgrading/extension/upgrades/0.8-to-0.9/instructions.md +1 -1
- package/skills/prisma-8/upgrading/extension/upgrades/0.9-to-0.10/instructions.md +1 -1
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/instructions.md +2043 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-hash-inputs/contract-hash-inputs.ts +2048 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-signature-names/contract-signature-names.ts +667 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/facade-paths-an-application-uses/facade-paths-an-application-uses.ts +667 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/platform-paths-an-extension-uses/platform-paths-an-extension-uses.ts +1996 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/stored-files-format-version/stored-files-format-version.ts +586 -0
- package/dist/adapter.d.mts +0 -1
- package/dist/adapter.mjs +0 -2
- package/dist/adapter__control.d.mts +0 -3
- package/dist/adapter__control.mjs +0 -3
- package/dist/adapter__runtime.d.mts +0 -3
- package/dist/adapter__runtime.mjs +0 -3
- package/dist/components.d.mts +0 -1
- package/dist/components.mjs +0 -2
- package/dist/components__authoring.d.mts +0 -1
- package/dist/components__authoring.mjs +0 -2
- package/dist/components__codec.d.mts +0 -1
- package/dist/components__codec.mjs +0 -2
- package/dist/components__components.d.mts +0 -1
- package/dist/components__components.mjs +0 -2
- package/dist/components__control.d.mts +0 -1
- package/dist/components__control.mjs +0 -2
- package/dist/components__emission.d.mts +0 -1
- package/dist/components__emission.mjs +0 -2
- package/dist/components__execution.d.mts +0 -1
- package/dist/components__execution.mjs +0 -2
- package/dist/components__ir.d.mts +0 -1
- package/dist/components__ir.mjs +0 -2
- package/dist/components__psl-ast.d.mts +0 -1
- package/dist/components__psl-ast.mjs +0 -2
- package/dist/components__utils.d.mts +0 -1
- package/dist/components__utils.mjs +0 -2
- package/dist/contract.d.mts +0 -1
- package/dist/contract.mjs +0 -2
- package/dist/contract__apply-specifier-default-control-policy.d.mts +0 -1
- package/dist/contract__apply-specifier-default-control-policy.mjs +0 -2
- package/dist/contract__contract-validation-error.d.mts +0 -1
- package/dist/contract__contract-validation-error.mjs +0 -2
- package/dist/contract__default-namespace.d.mts +0 -1
- package/dist/contract__default-namespace.mjs +0 -2
- package/dist/contract__enum-accessor.d.mts +0 -1
- package/dist/contract__enum-accessor.mjs +0 -2
- package/dist/contract__format-version.d.mts +0 -1
- package/dist/contract__format-version.mjs +0 -2
- package/dist/contract__hashing-utils.d.mts +0 -1
- package/dist/contract__hashing-utils.mjs +0 -2
- package/dist/contract__hashing.d.mts +0 -1
- package/dist/contract__hashing.mjs +0 -2
- package/dist/contract__internal__format-version.d.mts +0 -1
- package/dist/contract__internal__format-version.mjs +0 -2
- package/dist/contract__is-plain-record.d.mts +0 -1
- package/dist/contract__is-plain-record.mjs +0 -2
- package/dist/contract__resolve-domain-model.d.mts +0 -1
- package/dist/contract__resolve-domain-model.mjs +0 -2
- package/dist/contract__validate-domain.d.mts +0 -1
- package/dist/contract__validate-domain.mjs +0 -2
- package/dist/contract__validate-once.d.mts +0 -1
- package/dist/contract__validate-once.mjs +0 -2
- package/dist/contract__validate-storage.d.mts +0 -1
- package/dist/contract__validate-storage.mjs +0 -2
- package/dist/driver.d.mts +0 -1
- package/dist/driver.mjs +0 -2
- package/dist/driver__control.d.mts +0 -3
- package/dist/driver__control.mjs +0 -3
- package/dist/driver__runtime.d.mts +0 -3
- package/dist/driver__runtime.mjs +0 -3
- package/dist/family-contract__canonicalization-hooks.d.mts +0 -1
- package/dist/family-contract__canonicalization-hooks.mjs +0 -2
- package/dist/family-contract__data-type.d.mts +0 -1
- package/dist/family-contract__data-type.mjs +0 -2
- package/dist/family-contract__entity-kinds.d.mts +0 -1
- package/dist/family-contract__entity-kinds.mjs +0 -2
- package/dist/family__control-adapter.d.mts +0 -1
- package/dist/family__control-adapter.mjs +0 -2
- package/dist/family__ir.d.mts +0 -1
- package/dist/family__ir.mjs +0 -2
- package/dist/family__migration.d.mts +0 -1
- package/dist/family__migration.mjs +0 -2
- package/dist/family__pack.d.mts +0 -3
- package/dist/family__pack.mjs +0 -3
- package/dist/family__runtime.d.mts +0 -1
- package/dist/family__runtime.mjs +0 -2
- package/dist/family__schema-verify.d.mts +0 -1
- package/dist/family__schema-verify.mjs +0 -2
- package/dist/migration-tools__contract-snapshot-store.d.mts +0 -1
- package/dist/migration-tools__contract-snapshot-store.mjs +0 -2
- package/dist/mongo-static-CZlnpepm-DnjIfx0L.mjs.map +0 -1
- package/dist/query-ast.d.mts +0 -1
- package/dist/query-ast.mjs +0 -2
- package/dist/query-ast__control.d.mts +0 -1
- package/dist/query-ast__control.mjs +0 -2
- package/dist/query-builder__contract-free.d.mts +0 -1
- package/dist/query-builder__contract-free.mjs +0 -2
- package/dist/target__codecs.d.mts +0 -1
- package/dist/target__codecs.mjs +0 -2
- package/dist/target__control.d.mts +0 -1
- package/dist/target__control.mjs +0 -2
- package/dist/target__data-types.d.mts +0 -1
- package/dist/target__data-types.mjs +0 -2
- package/dist/target__pack.d.mts +0 -3
- package/dist/target__pack.mjs +0 -3
- package/dist/target__server-version.d.mts +0 -1
- package/dist/target__server-version.mjs +0 -2
- package/dist/utils.d.mts +0 -1
- package/dist/utils.mjs +0 -2
- package/dist/utils__abortable.d.mts +0 -1
- package/dist/utils__abortable.mjs +0 -2
- package/dist/utils__array-equal.d.mts +0 -1
- package/dist/utils__array-equal.mjs +0 -2
- package/dist/utils__assertions.d.mts +0 -1
- package/dist/utils__assertions.mjs +0 -2
- package/dist/utils__canonical-stringify.d.mts +0 -1
- package/dist/utils__canonical-stringify.mjs +0 -2
- package/dist/utils__casts.d.mts +0 -1
- package/dist/utils__casts.mjs +0 -2
- package/dist/utils__defined.d.mts +0 -1
- package/dist/utils__defined.mjs +0 -2
- package/dist/utils__guards.d.mts +0 -1
- package/dist/utils__guards.mjs +0 -2
- package/dist/utils__hash-content.d.mts +0 -1
- package/dist/utils__hash-content.mjs +0 -2
- package/dist/utils__internal-error.d.mts +0 -1
- package/dist/utils__internal-error.mjs +0 -2
- package/dist/utils__json.d.mts +0 -1
- package/dist/utils__json.mjs +0 -2
- package/dist/utils__promise.d.mts +0 -1
- package/dist/utils__promise.mjs +0 -2
- package/dist/utils__redact-db-url.d.mts +0 -1
- package/dist/utils__redact-db-url.mjs +0 -2
- package/dist/utils__result.d.mts +0 -1
- package/dist/utils__result.mjs +0 -2
- package/dist/utils__simplify-deep.d.mts +0 -1
- package/dist/utils__simplify-deep.mjs +0 -2
- package/dist/utils__structured-error.d.mts +0 -1
- package/dist/utils__structured-error.mjs +0 -2
- package/dist/utils__suppress-idle-connection-errors.d.mts +0 -1
- package/dist/utils__suppress-idle-connection-errors.mjs +0 -2
- package/dist/utils__text.d.mts +0 -1
- package/dist/utils__text.mjs +0 -2
- package/dist/utils__types.d.mts +0 -1
- package/dist/utils__types.mjs +0 -2
- package/dist/utils__upgrade-guides.d.mts +0 -1
- package/dist/utils__upgrade-guides.mjs +0 -2
- package/dist/value__mongodb-types.d.mts +0 -1
- package/dist/value__mongodb-types.mjs +0 -2
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Gives every file Prisma stores in a project its format version. A `contract.json` (emitted next to the contract source, bundled by an extension, or a copy under `migrations/snapshots/<hash>/`) had `"schemaVersion": "1"`; it now has `"formatVersion": 1`. A `migration.json` and a ref file (`refs/<name>.json`, including an extension's `refs/head.json`) had no version; they now start with `"formatVersion": 1`. Until `8.0.0` a release reads a file without it as the format a release candidate wrote; `8.0.0` refuses it.
|
|
4
|
+
*
|
|
5
|
+
* Usage: node stored-files-format-version.ts [project-root]
|
|
6
|
+
*
|
|
7
|
+
* The project root defaults to the working directory. The script walks it, skipping `node_modules`, `dist`, `build` and directories whose name starts with a dot. It recognises a contract by its content (`targetFamily`, `storage` and `schemaVersion` at the top level) in any `*.json` file, a `migration.json` by its fields and by the `ops.json` next to it, and a ref file by where Prisma writes refs or by its content. Every `*.json` file in `<migrations>/<space>/refs/` (in an application) or `<migrations>/refs/` (in an extension's own repository) is a ref, where a migrations directory is one holding the contract snapshot store (`snapshots/<hash>/contract.json`) or a migration package, whatever it is named. A `*.json` file in any other `refs` directory is a ref when its content is one: a `hash` that is `empty` or a storage hash, and an `invariants` list of strings. This finds the refs of a space with no migrations after `snapshots/` was deleted. Any other JSON file in a `refs` directory is not Prisma's and is left alone. It edits each file's text in place, so the rest of the file keeps its bytes: the version goes first, except in a contract whose top-level keys are sorted (a snapshot), where it goes in sorted position, as Prisma writes them. No hash covers the version, so no hash changes.
|
|
8
|
+
*
|
|
9
|
+
* A ref file may have fields the format does not have; earlier releases ignored them when they read a ref and dropped them when they wrote one again. The script drops them too, and lists each one it dropped.
|
|
10
|
+
*
|
|
11
|
+
* It prints each file it changed. These are reported, left unchanged, and make it exit 1, while it still changes every other file: a `contract.json`, `migration.json` or ref file it cannot read or parse; a ref file or `migration.json` whose content is not one that a release of Prisma read (a missing or extra field, or a value of the wrong type); a contract with both `formatVersion` and `schemaVersion`, or a `contract.json` holding a contract with neither; a contract whose `schemaVersion` is not `"1"`; a stored file whose `formatVersion` is not `1`; a directory it cannot list; and a symbolic link, to a file or folder outside the project root or inside it where the walk skips, that holds a stored file it would change or report, or a link inside the root to a place the walk reads as another kind of file than at the link, since it does not follow links. A second run changes nothing.
|
|
12
|
+
*/
|
|
13
|
+
import {
|
|
14
|
+
chmodSync,
|
|
15
|
+
type Dirent,
|
|
16
|
+
existsSync,
|
|
17
|
+
readdirSync,
|
|
18
|
+
readFileSync,
|
|
19
|
+
realpathSync,
|
|
20
|
+
renameSync,
|
|
21
|
+
rmSync,
|
|
22
|
+
statSync,
|
|
23
|
+
writeFileSync,
|
|
24
|
+
} from 'node:fs';
|
|
25
|
+
import { basename, dirname, join, relative, resolve, sep } from 'node:path';
|
|
26
|
+
|
|
27
|
+
type Json = null | boolean | number | string | Json[] | JsonRecord;
|
|
28
|
+
interface JsonRecord {
|
|
29
|
+
[key: string]: Json;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type StoredFileKind = 'contract' | 'snapshot' | 'migration' | 'ref';
|
|
33
|
+
|
|
34
|
+
const SKIPPED_DIRECTORIES = new Set(['node_modules', 'dist', 'build']);
|
|
35
|
+
const SPACE_ID = /^[a-z][a-z0-9_-]{0,63}$/;
|
|
36
|
+
const STORAGE_HASH = /^[0-9a-f]{64}$/;
|
|
37
|
+
const REF_HASH = /^(empty|[0-9a-f]{64})$/;
|
|
38
|
+
const BYTE_ORDER_MARK = '';
|
|
39
|
+
const MIGRATION_FIELDS = ['from', 'to', 'migrationHash', 'providedInvariants', 'createdAt'];
|
|
40
|
+
const MIGRATION_KEYS = new Set(MIGRATION_FIELDS);
|
|
41
|
+
const REF_KEYS = new Set(['hash', 'invariants', 'policies']);
|
|
42
|
+
|
|
43
|
+
interface Member {
|
|
44
|
+
readonly key: string;
|
|
45
|
+
readonly keyStart: number;
|
|
46
|
+
readonly keyEnd: number;
|
|
47
|
+
readonly valueStart: number;
|
|
48
|
+
readonly valueEnd: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface ObjectLayout {
|
|
52
|
+
readonly open: number;
|
|
53
|
+
readonly members: readonly Member[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface Outcome {
|
|
57
|
+
readonly changed: string[];
|
|
58
|
+
readonly problems: string[];
|
|
59
|
+
readonly dropped: string[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function emptyOutcome(): Outcome {
|
|
63
|
+
return { changed: [], problems: [], dropped: [] };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function isRecord(value: unknown): value is JsonRecord {
|
|
67
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function isStringArray(value: unknown): boolean {
|
|
71
|
+
return Array.isArray(value) && value.every((item) => typeof item === 'string');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function compareCodeUnits(a: string, b: string): number {
|
|
75
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function skipWhitespace(text: string, index: number): number {
|
|
79
|
+
let i = index;
|
|
80
|
+
while (i < text.length && ' \t\n\r'.includes(text.charAt(i))) i++;
|
|
81
|
+
return i;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function endOfString(text: string, start: number): number {
|
|
85
|
+
let i = start + 1;
|
|
86
|
+
while (text.charAt(i) !== '"') i += text.charAt(i) === '\\' ? 2 : 1;
|
|
87
|
+
return i + 1;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function endOfValue(text: string, start: number): number {
|
|
91
|
+
const first = text.charAt(start);
|
|
92
|
+
if (first === '"') return endOfString(text, start);
|
|
93
|
+
if (first === '{' || first === '[') {
|
|
94
|
+
let depth = 0;
|
|
95
|
+
let i = start;
|
|
96
|
+
while (i < text.length) {
|
|
97
|
+
const char = text.charAt(i);
|
|
98
|
+
if (char === '"') {
|
|
99
|
+
i = endOfString(text, i);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (char === '{' || char === '[') depth++;
|
|
103
|
+
else if (char === '}' || char === ']') {
|
|
104
|
+
depth--;
|
|
105
|
+
if (depth === 0) return i + 1;
|
|
106
|
+
}
|
|
107
|
+
i++;
|
|
108
|
+
}
|
|
109
|
+
return i;
|
|
110
|
+
}
|
|
111
|
+
let i = start;
|
|
112
|
+
while (i < text.length && !',}] \t\n\r'.includes(text.charAt(i))) i++;
|
|
113
|
+
return i;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The top-level members of a JSON object text that `JSON.parse` accepted, with their positions. */
|
|
117
|
+
function objectLayout(text: string): ObjectLayout {
|
|
118
|
+
const open = skipWhitespace(text, 0);
|
|
119
|
+
const members: Member[] = [];
|
|
120
|
+
let i = skipWhitespace(text, open + 1);
|
|
121
|
+
while (text.charAt(i) === '"') {
|
|
122
|
+
const keyStart = i;
|
|
123
|
+
const keyEnd = endOfString(text, keyStart);
|
|
124
|
+
const key: string = JSON.parse(text.slice(keyStart, keyEnd));
|
|
125
|
+
const valueStart = skipWhitespace(text, skipWhitespace(text, keyEnd) + 1);
|
|
126
|
+
const valueEnd = endOfValue(text, valueStart);
|
|
127
|
+
members.push({ key, keyStart, keyEnd, valueStart, valueEnd });
|
|
128
|
+
i = skipWhitespace(text, valueEnd);
|
|
129
|
+
if (text.charAt(i) === ',') i = skipWhitespace(text, i + 1);
|
|
130
|
+
}
|
|
131
|
+
return { open, members };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function separatorBefore(text: string, layout: ObjectLayout, index: number): string {
|
|
135
|
+
const member = layout.members[index];
|
|
136
|
+
if (member === undefined) return '';
|
|
137
|
+
const previous = layout.members[index - 1];
|
|
138
|
+
if (previous === undefined) return text.slice(layout.open + 1, member.keyStart);
|
|
139
|
+
return text.slice(text.indexOf(',', previous.valueEnd) + 1, member.keyStart);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function withoutMember(text: string, key: string): string {
|
|
143
|
+
const { members } = objectLayout(text);
|
|
144
|
+
const index = members.findIndex((member) => member.key === key);
|
|
145
|
+
const member = members[index];
|
|
146
|
+
if (member === undefined) return text;
|
|
147
|
+
const next = members[index + 1];
|
|
148
|
+
if (next !== undefined) return text.slice(0, member.keyStart) + text.slice(next.keyStart);
|
|
149
|
+
const previous = members[index - 1];
|
|
150
|
+
const start = previous === undefined ? member.keyStart : previous.valueEnd;
|
|
151
|
+
return text.slice(0, start) + text.slice(member.valueEnd);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function keysAreSorted(keys: readonly string[]): boolean {
|
|
155
|
+
return (
|
|
156
|
+
keys.length > 1 &&
|
|
157
|
+
keys.every((key, i) => i === 0 || compareCodeUnits(keys[i - 1] ?? '', key) < 0)
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** `text` with `"formatVersion": 1` added as a top-level member, written in the file's own spacing. */
|
|
162
|
+
function withFormatVersion(text: string, placement: 'first' | 'sorted-when-sorted'): string {
|
|
163
|
+
const layout = objectLayout(text);
|
|
164
|
+
const { members } = layout;
|
|
165
|
+
const first = members[0];
|
|
166
|
+
if (first === undefined) return text;
|
|
167
|
+
const keys = members.map((member) => member.key);
|
|
168
|
+
const position =
|
|
169
|
+
placement === 'sorted-when-sorted' && keysAreSorted(keys)
|
|
170
|
+
? keys.filter((key) => compareCodeUnits(key, 'formatVersion') < 0).length
|
|
171
|
+
: 0;
|
|
172
|
+
const colon = text.slice(first.keyEnd, first.valueStart);
|
|
173
|
+
const entry = `"formatVersion"${colon}1`;
|
|
174
|
+
const between = separatorBefore(text, layout, members.length > 1 ? Math.max(position, 1) : 0);
|
|
175
|
+
const before = members[position];
|
|
176
|
+
if (before !== undefined)
|
|
177
|
+
return `${text.slice(0, before.keyStart)}${entry},${between}${text.slice(before.keyStart)}`;
|
|
178
|
+
const last = members[members.length - 1] ?? first;
|
|
179
|
+
return `${text.slice(0, last.valueEnd)},${between}${entry}${text.slice(last.valueEnd)}`;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function sameMembersBesidesVersion(
|
|
183
|
+
original: JsonRecord,
|
|
184
|
+
rewritten: Json,
|
|
185
|
+
dropped: readonly string[],
|
|
186
|
+
): boolean {
|
|
187
|
+
if (!isRecord(rewritten) || rewritten['formatVersion'] !== 1 || 'schemaVersion' in rewritten)
|
|
188
|
+
return false;
|
|
189
|
+
const removed = new Set(['schemaVersion', ...dropped]);
|
|
190
|
+
const rest = Object.fromEntries(Object.entries(original).filter(([key]) => !removed.has(key)));
|
|
191
|
+
const { formatVersion: _, ...rewrittenRest } = rewritten;
|
|
192
|
+
return JSON.stringify(rest) === JSON.stringify(rewrittenRest);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function quotedList(keys: readonly string[]): string {
|
|
196
|
+
return keys.map((key) => JSON.stringify(key)).join(', ');
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function isContract(value: JsonRecord): boolean {
|
|
200
|
+
return typeof value['targetFamily'] === 'string' && isRecord(value['storage']);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function migrationFieldHolds(field: string, value: Json): boolean {
|
|
204
|
+
if (field === 'from') return value === null || typeof value === 'string';
|
|
205
|
+
if (field === 'providedInvariants') return isStringArray(value);
|
|
206
|
+
return typeof value === 'string';
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** What keeps `value` from being a `migration.json` that a release of Prisma read, or undefined when nothing does. */
|
|
210
|
+
function migrationMetadataProblem(value: JsonRecord): string | undefined {
|
|
211
|
+
const unknown = Object.keys(value).filter((key) => !MIGRATION_KEYS.has(key));
|
|
212
|
+
if (unknown.length > 0) {
|
|
213
|
+
const fields = unknown.length === 1 ? 'the field' : 'the fields';
|
|
214
|
+
const them = unknown.length === 1 ? 'the field' : 'them';
|
|
215
|
+
return `it has ${fields} ${quotedList(unknown)}, which a migration.json does not have, so no release read it. Remove ${them} and run the script again`;
|
|
216
|
+
}
|
|
217
|
+
for (const field of MIGRATION_FIELDS) {
|
|
218
|
+
const fieldValue = value[field];
|
|
219
|
+
if (fieldValue === undefined || !migrationFieldHolds(field, fieldValue)) {
|
|
220
|
+
const what =
|
|
221
|
+
fieldValue === undefined
|
|
222
|
+
? `it has no "${field}", which every migration.json has`
|
|
223
|
+
: `its "${field}" is ${JSON.stringify(fieldValue)}, which is not what a migration.json holds there`;
|
|
224
|
+
return `${what}, so no release read it. Plan the migration again, or restore the file from version control`;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return undefined;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** What keeps `value` from being a ref file that a release of Prisma read, or undefined when nothing does. Fields a ref file does not have are not a problem: earlier releases ignored them. */
|
|
231
|
+
function refProblem(value: JsonRecord): string | undefined {
|
|
232
|
+
const shape = 'a ref file has "hash" and "invariants", and this one';
|
|
233
|
+
if (typeof value['hash'] !== 'string')
|
|
234
|
+
return `${shape} has no "hash" string. Write the hash the ref should name, or delete the file, and run the script again`;
|
|
235
|
+
if (!isStringArray(value['invariants']))
|
|
236
|
+
return `${shape} has no "invariants" list. Add "invariants": [] (or the invariants the ref should carry) and run the script again`;
|
|
237
|
+
return undefined;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function isDirectory(path: string): boolean {
|
|
241
|
+
try {
|
|
242
|
+
return statSync(path).isDirectory();
|
|
243
|
+
} catch {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function isMigrationPackage(dir: string): boolean {
|
|
249
|
+
return existsSync(join(dir, 'migration.json')) && existsSync(join(dir, 'ops.json'));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function hasSubdirectory(dir: string, holds: (path: string, name: string) => boolean): boolean {
|
|
253
|
+
const entries = listDirectory(dir);
|
|
254
|
+
return (
|
|
255
|
+
typeof entries !== 'string' &&
|
|
256
|
+
entries.some((entry) => {
|
|
257
|
+
const path = join(dir, entry.name);
|
|
258
|
+
return isDirectory(path) && holds(path, entry.name);
|
|
259
|
+
})
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function isSnapshotStore(dir: string): boolean {
|
|
264
|
+
return hasSubdirectory(
|
|
265
|
+
dir,
|
|
266
|
+
(path, name) => STORAGE_HASH.test(name) && existsSync(join(path, 'contract.json')),
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** Whether `dir` holds what Prisma writes to a migrations directory: its contract snapshot store, or a migration package. */
|
|
271
|
+
function isMigrationsDirectory(dir: string): boolean {
|
|
272
|
+
return isSnapshotStore(join(dir, 'snapshots')) || hasSubdirectory(dir, isMigrationPackage);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** Whether `path` is where Prisma writes a ref: `refs/` in an application's space directory under the migrations directory, or directly in an extension's migrations directory. */
|
|
276
|
+
function isRefLocation(root: string, path: string): boolean {
|
|
277
|
+
const segments = relative(root, dirname(path)).split(sep);
|
|
278
|
+
for (let i = segments.length - 1; i >= 0; i--) {
|
|
279
|
+
if (segments[i] !== 'refs') continue;
|
|
280
|
+
const owner = join(root, ...segments.slice(0, i));
|
|
281
|
+
if (isMigrationsDirectory(owner)) return true;
|
|
282
|
+
if (i > 0 && SPACE_ID.test(segments[i - 1] ?? '') && isMigrationsDirectory(dirname(owner)))
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function isInRefsDirectory(root: string, path: string): boolean {
|
|
289
|
+
return relative(root, dirname(path)).split(sep).includes('refs');
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** Whether `value` holds what Prisma writes to a ref file, besides fields a ref file does not have. */
|
|
293
|
+
function hasRefContent(value: JsonRecord): boolean {
|
|
294
|
+
const hash = value['hash'];
|
|
295
|
+
return typeof hash === 'string' && REF_HASH.test(hash) && isStringArray(value['invariants']);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** The kind of stored file `path` is by its name and place, before its content is read. */
|
|
299
|
+
function expectedKind(root: string, path: string): StoredFileKind | undefined {
|
|
300
|
+
const name = basename(path);
|
|
301
|
+
if (name === 'migration.json' && isMigrationPackage(dirname(path))) return 'migration';
|
|
302
|
+
if (!name.endsWith('.contract.json') && isRefLocation(root, path)) return 'ref';
|
|
303
|
+
if (name === 'contract.json') return isSnapshot(path) ? 'snapshot' : 'contract';
|
|
304
|
+
return undefined;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function isSnapshot(path: string): boolean {
|
|
308
|
+
const hashDir = dirname(path);
|
|
309
|
+
return STORAGE_HASH.test(basename(hashDir)) && basename(dirname(hashDir)) === 'snapshots';
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
type Rewrite =
|
|
313
|
+
| { readonly kind: 'unchanged' }
|
|
314
|
+
| { readonly kind: 'rewritten'; readonly text: string; readonly dropped: readonly string[] }
|
|
315
|
+
| { readonly kind: 'problem'; readonly reason: string };
|
|
316
|
+
|
|
317
|
+
function rewriteRef(text: string, value: JsonRecord): Rewrite {
|
|
318
|
+
const problem = refProblem(value);
|
|
319
|
+
if (problem !== undefined) return { kind: 'problem', reason: problem };
|
|
320
|
+
const dropped = Object.keys(value).filter((key) => !REF_KEYS.has(key));
|
|
321
|
+
const kept = dropped.reduce((current, key) => withoutMember(current, key), text);
|
|
322
|
+
return { kind: 'rewritten', text: withFormatVersion(kept, 'first'), dropped };
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function rewrite(text: string, value: JsonRecord, expected: StoredFileKind | undefined): Rewrite {
|
|
326
|
+
if ('formatVersion' in value) {
|
|
327
|
+
if (
|
|
328
|
+
(isContract(value) || (expected !== undefined && expected !== 'contract')) &&
|
|
329
|
+
value['formatVersion'] !== 1
|
|
330
|
+
)
|
|
331
|
+
return {
|
|
332
|
+
kind: 'problem',
|
|
333
|
+
reason: `its "formatVersion" is ${JSON.stringify(value['formatVersion'])}, which no release of Prisma wrote. Restore it from version control`,
|
|
334
|
+
};
|
|
335
|
+
if ('schemaVersion' in value && isContract(value))
|
|
336
|
+
return {
|
|
337
|
+
kind: 'problem',
|
|
338
|
+
reason: 'it has both "formatVersion" and "schemaVersion". Delete the "schemaVersion" field',
|
|
339
|
+
};
|
|
340
|
+
return { kind: 'unchanged' };
|
|
341
|
+
}
|
|
342
|
+
if (expected === 'migration') {
|
|
343
|
+
const problem = migrationMetadataProblem(value);
|
|
344
|
+
if (problem !== undefined) return { kind: 'problem', reason: problem };
|
|
345
|
+
return { kind: 'rewritten', text: withFormatVersion(text, 'first'), dropped: [] };
|
|
346
|
+
}
|
|
347
|
+
if (expected === 'ref') return rewriteRef(text, value);
|
|
348
|
+
if (!isContract(value)) return { kind: 'unchanged' };
|
|
349
|
+
if (!('schemaVersion' in value)) {
|
|
350
|
+
if (expected !== 'contract' && expected !== 'snapshot') return { kind: 'unchanged' };
|
|
351
|
+
const remedy =
|
|
352
|
+
expected === 'snapshot'
|
|
353
|
+
? 'Restore it from version control'
|
|
354
|
+
: 'Emit it again with `prisma contract emit`, or restore it from version control';
|
|
355
|
+
return {
|
|
356
|
+
kind: 'problem',
|
|
357
|
+
reason: `it has neither "formatVersion" nor "schemaVersion", so no release of Prisma wrote it. ${remedy}`,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
if (value['schemaVersion'] !== '1')
|
|
361
|
+
return {
|
|
362
|
+
kind: 'problem',
|
|
363
|
+
reason: `its "schemaVersion" is ${JSON.stringify(value['schemaVersion'])}, which no release of Prisma wrote`,
|
|
364
|
+
};
|
|
365
|
+
return {
|
|
366
|
+
kind: 'rewritten',
|
|
367
|
+
text: withFormatVersion(withoutMember(text, 'schemaVersion'), 'sorted-when-sorted'),
|
|
368
|
+
dropped: [],
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const NOT_AN_OBJECT: Partial<Record<StoredFileKind, string>> = {
|
|
373
|
+
migration: 'a migration.json is a JSON object, and this one is not an object',
|
|
374
|
+
ref: 'a ref file is a JSON object with "hash" and "invariants", and this one is not an object',
|
|
375
|
+
snapshot:
|
|
376
|
+
'a contract snapshot is a JSON object, and this one is not an object. Restore it from version control',
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
/** Rewrites the stored file at `path`, or, when `write` is false, only records what a rewrite would do. */
|
|
380
|
+
function handleFile(root: string, path: string, outcome: Outcome, write = true): void {
|
|
381
|
+
const expected = expectedKind(root, path);
|
|
382
|
+
const shown = relative(root, path);
|
|
383
|
+
let raw: string;
|
|
384
|
+
try {
|
|
385
|
+
raw = readFileSync(path, 'utf8');
|
|
386
|
+
} catch (error) {
|
|
387
|
+
if (expected !== undefined)
|
|
388
|
+
outcome.problems.push(`${shown}: cannot be read (${errorText(error)})`);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
const bom = raw.startsWith(BYTE_ORDER_MARK) ? BYTE_ORDER_MARK : '';
|
|
392
|
+
const text = raw.slice(bom.length);
|
|
393
|
+
let value: Json;
|
|
394
|
+
try {
|
|
395
|
+
value = JSON.parse(text);
|
|
396
|
+
} catch (error) {
|
|
397
|
+
if (expected !== undefined)
|
|
398
|
+
outcome.problems.push(`${shown}: is not valid JSON (${errorText(error)})`);
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
if (!isRecord(value)) {
|
|
402
|
+
const reason = expected === undefined ? undefined : NOT_AN_OBJECT[expected];
|
|
403
|
+
if (reason !== undefined) outcome.problems.push(`${shown}: ${reason}`);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
const kind =
|
|
407
|
+
expected ?? (isInRefsDirectory(root, path) && hasRefContent(value) ? 'ref' : undefined);
|
|
408
|
+
const result = rewrite(text, value, kind);
|
|
409
|
+
if (result.kind === 'unchanged') return;
|
|
410
|
+
if (result.kind === 'problem') {
|
|
411
|
+
outcome.problems.push(`${shown}: ${result.reason}`);
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
if (!sameMembersBesidesVersion(value, JSON.parse(result.text), result.dropped)) {
|
|
415
|
+
outcome.problems.push(`${shown}: could not be rewritten without changing other content`);
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
try {
|
|
419
|
+
if (write) writeAtomically(path, bom + result.text);
|
|
420
|
+
outcome.changed.push(shown);
|
|
421
|
+
if (result.dropped.length > 0) outcome.dropped.push(`${shown}: ${quotedList(result.dropped)}`);
|
|
422
|
+
} catch (error) {
|
|
423
|
+
outcome.problems.push(`${shown}: cannot be written (${errorText(error)})`);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/** Writes `text` to a temporary file beside `path` with its mode, then renames it over `path`, so a failed write leaves `path` as it was. */
|
|
428
|
+
function writeAtomically(path: string, text: string): void {
|
|
429
|
+
const temporary = `${path}.${process.pid}.format-version.tmp`;
|
|
430
|
+
try {
|
|
431
|
+
const mode = statSync(path).mode & 0o7777;
|
|
432
|
+
writeFileSync(temporary, text);
|
|
433
|
+
// The umask filters the mode `writeFileSync` creates a file with; `chmodSync` does not.
|
|
434
|
+
chmodSync(temporary, mode);
|
|
435
|
+
renameSync(temporary, path);
|
|
436
|
+
} catch (error) {
|
|
437
|
+
rmSync(temporary, { force: true });
|
|
438
|
+
throw error;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function errorText(error: unknown): string {
|
|
443
|
+
if (error instanceof Error && 'code' in error) return String(error.code);
|
|
444
|
+
return error instanceof Error ? error.message : String(error);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function listDirectory(dir: string): Dirent[] | string {
|
|
448
|
+
try {
|
|
449
|
+
return readdirSync(dir, { withFileTypes: true }).sort((a, b) =>
|
|
450
|
+
compareCodeUnits(a.name, b.name),
|
|
451
|
+
);
|
|
452
|
+
} catch (error) {
|
|
453
|
+
return errorText(error);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function isWalked(name: string): boolean {
|
|
458
|
+
return !SKIPPED_DIRECTORIES.has(name) && !name.startsWith('.');
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function isInside(dir: string, path: string): boolean {
|
|
462
|
+
return path === dir || path.startsWith(`${dir}${sep}`);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Reports a symbolic link to a file or folder outside the project root, or inside it where the walk skips, that holds a stored file the script would change or report, and a link inside the root to a place the walk reads as another kind of file than at the link. The script does not follow links: any other link inside the root leads to files the walk handles anyway, and a link to the root or a folder above it leads back to the project itself.
|
|
467
|
+
*/
|
|
468
|
+
function handleLink(root: string, path: string, name: string, outcome: Outcome): void {
|
|
469
|
+
let target: string;
|
|
470
|
+
try {
|
|
471
|
+
target = realpathSync(path);
|
|
472
|
+
} catch {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
const realRoot = realpathSync(root);
|
|
476
|
+
if (isInside(target, realRoot)) return;
|
|
477
|
+
const inside = isInside(realRoot, target);
|
|
478
|
+
const reached =
|
|
479
|
+
relative(realRoot, target).split(sep).every(isWalked) &&
|
|
480
|
+
(statSync(target).isDirectory() || target.endsWith('.json'));
|
|
481
|
+
const shown = relative(root, path);
|
|
482
|
+
const targetShown = relative(realRoot, target);
|
|
483
|
+
if (inside && reached) {
|
|
484
|
+
if (readsAlike(root, path, realRoot, target, name)) return;
|
|
485
|
+
outcome.problems.push(
|
|
486
|
+
`${shown}: is a symbolic link to ${targetShown}, where the script does not handle what it holds as it would at the link, such as a ref file it finds only in a refs folder; the script does not follow links. Replace the link with what it points to`,
|
|
487
|
+
);
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
const probe = emptyOutcome();
|
|
491
|
+
const isDirectory = statSync(target).isDirectory();
|
|
492
|
+
if (isDirectory) {
|
|
493
|
+
if (!isWalked(name)) return;
|
|
494
|
+
visit(root, path, probe, false);
|
|
495
|
+
} else if (name.endsWith('.json')) {
|
|
496
|
+
handleFile(root, path, probe, false);
|
|
497
|
+
}
|
|
498
|
+
if (probe.changed.length === 0 && probe.problems.length === 0) return;
|
|
499
|
+
outcome.problems.push(
|
|
500
|
+
inside
|
|
501
|
+
? `${shown}: is a symbolic link to ${targetShown}, which the script skips, and which holds stored files the script would change or report; the script does not follow links. Replace the link with what it points to, or move ${targetShown} where the script walks`
|
|
502
|
+
: isDirectory
|
|
503
|
+
? `${shown}: is a symbolic link to ${targetShown}, a folder outside the project that holds stored files the script would change or report; the script does not follow links. Run it on ${targetShown} as well`
|
|
504
|
+
: `${shown}: is a symbolic link to ${targetShown}, a file outside the project that the script would change or report; the script does not follow links. Replace the link with the file, or add the format version to ${targetShown} by hand`,
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/** Whether the walk, which reaches the target of the link at `path`, handles the stored files there as it would at the link's own place. */
|
|
509
|
+
function readsAlike(
|
|
510
|
+
root: string,
|
|
511
|
+
path: string,
|
|
512
|
+
realRoot: string,
|
|
513
|
+
target: string,
|
|
514
|
+
name: string,
|
|
515
|
+
): boolean {
|
|
516
|
+
const atLink = emptyOutcome();
|
|
517
|
+
const atTarget = emptyOutcome();
|
|
518
|
+
if (statSync(target).isDirectory()) {
|
|
519
|
+
if (!isWalked(name)) return true;
|
|
520
|
+
visit(root, path, atLink, false);
|
|
521
|
+
visit(realRoot, target, atTarget, false);
|
|
522
|
+
} else if (name.endsWith('.json')) {
|
|
523
|
+
handleFile(root, path, atLink, false);
|
|
524
|
+
handleFile(realRoot, target, atTarget, false);
|
|
525
|
+
}
|
|
526
|
+
const linkShown = relative(root, path);
|
|
527
|
+
const targetShown = relative(realRoot, target);
|
|
528
|
+
const seen = (outcome: Outcome, prefix: string) =>
|
|
529
|
+
[...outcome.changed, ...outcome.problems].map((line) => line.slice(prefix.length));
|
|
530
|
+
return JSON.stringify(seen(atLink, linkShown)) === JSON.stringify(seen(atTarget, targetShown));
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/** Walks `dir`, rewriting stored files, or, when `write` is false, only recording what it would do. A walk that only records follows no link. */
|
|
534
|
+
function visit(root: string, dir: string, outcome: Outcome, write = true): void {
|
|
535
|
+
const entries = listDirectory(dir);
|
|
536
|
+
if (typeof entries === 'string') {
|
|
537
|
+
outcome.problems.push(`${relative(root, dir) || '.'}: directory cannot be read (${entries})`);
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
for (const entry of entries) {
|
|
541
|
+
const path = join(dir, entry.name);
|
|
542
|
+
if (entry.isDirectory()) {
|
|
543
|
+
if (isWalked(entry.name)) visit(root, path, outcome, write);
|
|
544
|
+
} else if (entry.isFile() && entry.name.endsWith('.json')) {
|
|
545
|
+
handleFile(root, path, outcome, write);
|
|
546
|
+
} else if (entry.isSymbolicLink() && write) {
|
|
547
|
+
handleLink(root, path, entry.name, outcome);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
function main(args: readonly string[]): number {
|
|
553
|
+
if (args.length > 1 || args.some((arg) => arg.startsWith('-'))) {
|
|
554
|
+
process.stderr.write('Usage: node stored-files-format-version.ts [project-root]\n');
|
|
555
|
+
return 1;
|
|
556
|
+
}
|
|
557
|
+
const root = resolve(args[0] ?? process.cwd());
|
|
558
|
+
if (!existsSync(root) || !statSync(root).isDirectory()) {
|
|
559
|
+
process.stderr.write(`${root}: not a directory\n`);
|
|
560
|
+
return 1;
|
|
561
|
+
}
|
|
562
|
+
const outcome = emptyOutcome();
|
|
563
|
+
visit(root, root, outcome);
|
|
564
|
+
if (outcome.changed.length > 0) {
|
|
565
|
+
const files = outcome.changed.length === 1 ? 'file' : 'files';
|
|
566
|
+
process.stdout.write(
|
|
567
|
+
`Added the format version to ${outcome.changed.length} ${files}:\n${outcome.changed.map((path) => ` ${path}\n`).join('')}`,
|
|
568
|
+
);
|
|
569
|
+
} else if (outcome.problems.length === 0) {
|
|
570
|
+
process.stdout.write('Every stored file already has a format version; nothing changed.\n');
|
|
571
|
+
} else {
|
|
572
|
+
process.stdout.write('Added the format version to no file.\n');
|
|
573
|
+
}
|
|
574
|
+
if (outcome.dropped.length > 0) {
|
|
575
|
+
process.stdout.write(
|
|
576
|
+
`Removed the fields a ref file does not have, which earlier releases ignored and dropped when they wrote the ref again:\n${outcome.dropped.map((line) => ` ${line}\n`).join('')}`,
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
if (outcome.problems.length === 0) return 0;
|
|
580
|
+
process.stderr.write(
|
|
581
|
+
`Left unchanged:\n${outcome.problems.map((problem) => ` ${problem}\n`).join('')}`,
|
|
582
|
+
);
|
|
583
|
+
return 1;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
process.exitCode = main(process.argv.slice(2));
|
package/dist/adapter.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "@prisma/orm-target-mongo/adapter";
|
package/dist/adapter.mjs
DELETED
package/dist/components.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "@prisma/orm-framework/components";
|
package/dist/components.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "@prisma/orm-framework/components/authoring";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "@prisma/orm-framework/components/codec";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "@prisma/orm-framework/components/components";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "@prisma/orm-framework/components/control";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "@prisma/orm-framework/components/emission";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "@prisma/orm-framework/components/execution";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "@prisma/orm-framework/components/ir";
|
package/dist/components__ir.mjs
DELETED