@prisma-next/core-control-plane 0.3.0-dev.9 → 0.3.0-dev.90
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/LICENSE +201 -0
- package/README.md +31 -99
- package/dist/constants.d.mts +9 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/constants.mjs +10 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/emission.d.mts +58 -0
- package/dist/emission.d.mts.map +1 -0
- package/dist/emission.mjs +315 -0
- package/dist/emission.mjs.map +1 -0
- package/dist/errors.d.mts +232 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +330 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/{schema-view.d.ts → schema-view-DObwT8x9.d.mts} +17 -14
- package/dist/schema-view-DObwT8x9.d.mts.map +1 -0
- package/dist/schema-view.d.mts +2 -0
- package/dist/schema-view.mjs +1 -0
- package/dist/stack.d.mts +30 -0
- package/dist/stack.d.mts.map +1 -0
- package/dist/stack.mjs +30 -0
- package/dist/stack.mjs.map +1 -0
- package/dist/types-BArIWumw.d.mts +615 -0
- package/dist/types-BArIWumw.d.mts.map +1 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +1 -0
- package/package.json +31 -43
- package/src/constants.ts +5 -0
- package/src/emission/canonicalization.ts +68 -21
- package/src/emission/emit.ts +82 -21
- package/src/emission/hashing.ts +29 -27
- package/src/emission/types.ts +13 -2
- package/src/errors.ts +127 -20
- package/src/exports/constants.ts +1 -0
- package/src/exports/emission.ts +1 -1
- package/src/exports/errors.ts +6 -1
- package/src/exports/types.ts +0 -1
- package/src/migrations.ts +27 -1
- package/src/schema-view.ts +5 -5
- package/src/types.ts +24 -12
- package/dist/chunk-473ODD3P.js +0 -14
- package/dist/chunk-473ODD3P.js.map +0 -1
- package/dist/chunk-U5RYT6PT.js +0 -229
- package/dist/chunk-U5RYT6PT.js.map +0 -1
- package/dist/config-types.d.ts +0 -68
- package/dist/config-types.d.ts.map +0 -1
- package/dist/config-validation.d.ts +0 -10
- package/dist/config-validation.d.ts.map +0 -1
- package/dist/emission/canonicalization.d.ts +0 -6
- package/dist/emission/canonicalization.d.ts.map +0 -1
- package/dist/emission/emit.d.ts +0 -5
- package/dist/emission/emit.d.ts.map +0 -1
- package/dist/emission/hashing.d.ts +0 -17
- package/dist/emission/hashing.d.ts.map +0 -1
- package/dist/emission/types.d.ts +0 -16
- package/dist/emission/types.d.ts.map +0 -1
- package/dist/errors.d.ts +0 -183
- package/dist/errors.d.ts.map +0 -1
- package/dist/exports/config-types.d.ts +0 -3
- package/dist/exports/config-types.d.ts.map +0 -1
- package/dist/exports/config-types.js +0 -53
- package/dist/exports/config-types.js.map +0 -1
- package/dist/exports/config-validation.d.ts +0 -2
- package/dist/exports/config-validation.d.ts.map +0 -1
- package/dist/exports/config-validation.js +0 -252
- package/dist/exports/config-validation.js.map +0 -1
- package/dist/exports/emission.d.ts +0 -5
- package/dist/exports/emission.d.ts.map +0 -1
- package/dist/exports/emission.js +0 -310
- package/dist/exports/emission.js.map +0 -1
- package/dist/exports/errors.d.ts +0 -3
- package/dist/exports/errors.d.ts.map +0 -1
- package/dist/exports/errors.js +0 -43
- package/dist/exports/errors.js.map +0 -1
- package/dist/exports/schema-view.d.ts +0 -2
- package/dist/exports/schema-view.d.ts.map +0 -1
- package/dist/exports/schema-view.js +0 -1
- package/dist/exports/schema-view.js.map +0 -1
- package/dist/exports/stack.d.ts +0 -2
- package/dist/exports/stack.d.ts.map +0 -1
- package/dist/exports/stack.js +0 -7
- package/dist/exports/stack.js.map +0 -1
- package/dist/exports/types.d.ts +0 -3
- package/dist/exports/types.d.ts.map +0 -1
- package/dist/exports/types.js +0 -7
- package/dist/exports/types.js.map +0 -1
- package/dist/migrations.d.ts +0 -190
- package/dist/migrations.d.ts.map +0 -1
- package/dist/schema-view.d.ts.map +0 -1
- package/dist/stack.d.ts +0 -25
- package/dist/stack.d.ts.map +0 -1
- package/dist/types.d.ts +0 -411
- package/dist/types.d.ts.map +0 -1
- package/src/config-types.ts +0 -157
- package/src/config-validation.ts +0 -270
- package/src/exports/config-types.ts +0 -5
- package/src/exports/config-validation.ts +0 -1
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
2
|
+
import { bigintJsonReplacer } from "@prisma-next/contract/types";
|
|
3
|
+
import { isArrayEqual } from "@prisma-next/utils/array-equal";
|
|
4
|
+
import { type } from "arktype";
|
|
5
|
+
import { format } from "prettier";
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
|
|
8
|
+
//#region src/emission/canonicalization.ts
|
|
9
|
+
const TOP_LEVEL_ORDER = [
|
|
10
|
+
"schemaVersion",
|
|
11
|
+
"canonicalVersion",
|
|
12
|
+
"targetFamily",
|
|
13
|
+
"target",
|
|
14
|
+
"storageHash",
|
|
15
|
+
"executionHash",
|
|
16
|
+
"profileHash",
|
|
17
|
+
"models",
|
|
18
|
+
"relations",
|
|
19
|
+
"storage",
|
|
20
|
+
"execution",
|
|
21
|
+
"capabilities",
|
|
22
|
+
"extensionPacks",
|
|
23
|
+
"meta"
|
|
24
|
+
];
|
|
25
|
+
function isDefaultValue(value) {
|
|
26
|
+
if (value === false) return true;
|
|
27
|
+
if (value === null) return false;
|
|
28
|
+
if (value instanceof Date) return false;
|
|
29
|
+
if (Array.isArray(value) && value.length === 0) return true;
|
|
30
|
+
if (typeof value === "object" && value !== null) return Object.keys(value).length === 0;
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
function omitDefaults(obj, path) {
|
|
34
|
+
if (obj === null || typeof obj !== "object") return obj;
|
|
35
|
+
if (obj instanceof Date) return obj;
|
|
36
|
+
if (Array.isArray(obj)) return obj.map((item) => omitDefaults(item, path));
|
|
37
|
+
const result = {};
|
|
38
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
39
|
+
const currentPath = [...path, key];
|
|
40
|
+
if (key === "_generated") continue;
|
|
41
|
+
if (key === "nullable" && value === false) continue;
|
|
42
|
+
if (key === "generated" && value === false) continue;
|
|
43
|
+
if ((key === "onDelete" || key === "onUpdate") && value === "noAction") continue;
|
|
44
|
+
if (isDefaultValue(value)) {
|
|
45
|
+
const isRequiredModels = isArrayEqual(currentPath, ["models"]);
|
|
46
|
+
const isRequiredTables = isArrayEqual(currentPath, ["storage", "tables"]);
|
|
47
|
+
const isRequiredRelations = isArrayEqual(currentPath, ["relations"]);
|
|
48
|
+
const isRequiredExtensionPacks = isArrayEqual(currentPath, ["extensionPacks"]);
|
|
49
|
+
const isRequiredCapabilities = isArrayEqual(currentPath, ["capabilities"]);
|
|
50
|
+
const isRequiredMeta = isArrayEqual(currentPath, ["meta"]);
|
|
51
|
+
const isRequiredExecutionDefaults = isArrayEqual(currentPath, [
|
|
52
|
+
"execution",
|
|
53
|
+
"mutations",
|
|
54
|
+
"defaults"
|
|
55
|
+
]);
|
|
56
|
+
const isExtensionNamespace = currentPath.length === 2 && currentPath[0] === "extensionPacks";
|
|
57
|
+
const isModelRelations = currentPath.length === 3 && isArrayEqual([currentPath[0], currentPath[2]], ["models", "relations"]);
|
|
58
|
+
const isTableUniques = currentPath.length === 4 && isArrayEqual([
|
|
59
|
+
currentPath[0],
|
|
60
|
+
currentPath[1],
|
|
61
|
+
currentPath[3]
|
|
62
|
+
], [
|
|
63
|
+
"storage",
|
|
64
|
+
"tables",
|
|
65
|
+
"uniques"
|
|
66
|
+
]);
|
|
67
|
+
const isTableIndexes = currentPath.length === 4 && isArrayEqual([
|
|
68
|
+
currentPath[0],
|
|
69
|
+
currentPath[1],
|
|
70
|
+
currentPath[3]
|
|
71
|
+
], [
|
|
72
|
+
"storage",
|
|
73
|
+
"tables",
|
|
74
|
+
"indexes"
|
|
75
|
+
]);
|
|
76
|
+
const isTableForeignKeys = currentPath.length === 4 && isArrayEqual([
|
|
77
|
+
currentPath[0],
|
|
78
|
+
currentPath[1],
|
|
79
|
+
currentPath[3]
|
|
80
|
+
], [
|
|
81
|
+
"storage",
|
|
82
|
+
"tables",
|
|
83
|
+
"foreignKeys"
|
|
84
|
+
]);
|
|
85
|
+
const isFkBooleanField = currentPath.length === 5 && currentPath[0] === "storage" && currentPath[1] === "tables" && currentPath[3] === "foreignKeys" && (key === "constraint" || key === "index");
|
|
86
|
+
if (!isRequiredModels && !isRequiredTables && !isRequiredRelations && !isRequiredExtensionPacks && !isRequiredCapabilities && !isRequiredMeta && !isRequiredExecutionDefaults && !isExtensionNamespace && !isModelRelations && !isTableUniques && !isTableIndexes && !isTableForeignKeys && !isFkBooleanField) continue;
|
|
87
|
+
}
|
|
88
|
+
result[key] = omitDefaults(value, currentPath);
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
function sortObjectKeys(obj) {
|
|
93
|
+
if (obj === null || typeof obj !== "object") return obj;
|
|
94
|
+
if (obj instanceof Date) return obj;
|
|
95
|
+
if (Array.isArray(obj)) return obj.map((item) => sortObjectKeys(item));
|
|
96
|
+
const sorted = {};
|
|
97
|
+
const keys = Object.keys(obj).sort();
|
|
98
|
+
for (const key of keys) sorted[key] = sortObjectKeys(obj[key]);
|
|
99
|
+
return sorted;
|
|
100
|
+
}
|
|
101
|
+
function sortIndexesAndUniques(storage) {
|
|
102
|
+
if (!storage || typeof storage !== "object") return storage;
|
|
103
|
+
const storageObj = storage;
|
|
104
|
+
if (!storageObj.tables || typeof storageObj.tables !== "object") return storage;
|
|
105
|
+
const tables = storageObj.tables;
|
|
106
|
+
const result = { ...storageObj };
|
|
107
|
+
result.tables = {};
|
|
108
|
+
const sortedTableNames = Object.keys(tables).sort();
|
|
109
|
+
for (const tableName of sortedTableNames) {
|
|
110
|
+
const table = tables[tableName];
|
|
111
|
+
if (!table || typeof table !== "object") {
|
|
112
|
+
result.tables[tableName] = table;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const tableObj = table;
|
|
116
|
+
const sortedTable = { ...tableObj };
|
|
117
|
+
if (Array.isArray(tableObj.indexes)) sortedTable.indexes = [...tableObj.indexes].sort((a, b) => {
|
|
118
|
+
const nameA = a?.name || "";
|
|
119
|
+
const nameB = b?.name || "";
|
|
120
|
+
return nameA.localeCompare(nameB);
|
|
121
|
+
});
|
|
122
|
+
if (Array.isArray(tableObj.uniques)) sortedTable.uniques = [...tableObj.uniques].sort((a, b) => {
|
|
123
|
+
const nameA = a?.name || "";
|
|
124
|
+
const nameB = b?.name || "";
|
|
125
|
+
return nameA.localeCompare(nameB);
|
|
126
|
+
});
|
|
127
|
+
result.tables[tableName] = sortedTable;
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
function orderTopLevel(obj) {
|
|
132
|
+
const ordered = {};
|
|
133
|
+
const remaining = new Set(Object.keys(obj));
|
|
134
|
+
for (const key of TOP_LEVEL_ORDER) if (remaining.has(key)) {
|
|
135
|
+
ordered[key] = obj[key];
|
|
136
|
+
remaining.delete(key);
|
|
137
|
+
}
|
|
138
|
+
for (const key of Array.from(remaining).sort()) ordered[key] = obj[key];
|
|
139
|
+
return ordered;
|
|
140
|
+
}
|
|
141
|
+
function canonicalizeContract(ir) {
|
|
142
|
+
const normalized = {
|
|
143
|
+
schemaVersion: ir.schemaVersion,
|
|
144
|
+
targetFamily: ir.targetFamily,
|
|
145
|
+
target: ir.target,
|
|
146
|
+
models: ir.models,
|
|
147
|
+
relations: ir.relations,
|
|
148
|
+
storage: ir.storage,
|
|
149
|
+
...ifDefined("execution", ir.execution),
|
|
150
|
+
extensionPacks: ir.extensionPacks,
|
|
151
|
+
capabilities: ir.capabilities,
|
|
152
|
+
meta: ir.meta
|
|
153
|
+
};
|
|
154
|
+
Object.assign(normalized, ifDefined("storageHash", ir.storageHash), ifDefined("executionHash", ir.executionHash), ifDefined("profileHash", ir.profileHash));
|
|
155
|
+
const withDefaultsOmitted = omitDefaults(normalized, []);
|
|
156
|
+
const withSortedIndexes = sortIndexesAndUniques(withDefaultsOmitted.storage);
|
|
157
|
+
const withOrderedTopLevel = orderTopLevel(sortObjectKeys({
|
|
158
|
+
...withDefaultsOmitted,
|
|
159
|
+
storage: withSortedIndexes
|
|
160
|
+
}));
|
|
161
|
+
return JSON.stringify(withOrderedTopLevel, bigintJsonReplacer, 2);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/emission/hashing.ts
|
|
166
|
+
function computeHash(content) {
|
|
167
|
+
const hash = createHash("sha256");
|
|
168
|
+
hash.update(content);
|
|
169
|
+
return `sha256:${hash.digest("hex")}`;
|
|
170
|
+
}
|
|
171
|
+
function computeStorageHash(contract) {
|
|
172
|
+
return computeHash(canonicalizeContract({
|
|
173
|
+
schemaVersion: contract.schemaVersion,
|
|
174
|
+
targetFamily: contract.targetFamily,
|
|
175
|
+
target: contract.target,
|
|
176
|
+
storage: contract.storage,
|
|
177
|
+
models: {},
|
|
178
|
+
relations: {},
|
|
179
|
+
extensionPacks: {},
|
|
180
|
+
capabilities: {},
|
|
181
|
+
meta: {}
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
function computeProfileHash(contract) {
|
|
185
|
+
return computeHash(canonicalizeContract({
|
|
186
|
+
schemaVersion: contract.schemaVersion,
|
|
187
|
+
targetFamily: contract.targetFamily,
|
|
188
|
+
target: contract.target,
|
|
189
|
+
models: {},
|
|
190
|
+
relations: {},
|
|
191
|
+
storage: {},
|
|
192
|
+
extensionPacks: {},
|
|
193
|
+
capabilities: contract.capabilities,
|
|
194
|
+
meta: {}
|
|
195
|
+
}));
|
|
196
|
+
}
|
|
197
|
+
function computeExecutionHash(contract) {
|
|
198
|
+
return computeHash(canonicalizeContract({
|
|
199
|
+
schemaVersion: contract.schemaVersion,
|
|
200
|
+
targetFamily: contract.targetFamily,
|
|
201
|
+
target: contract.target,
|
|
202
|
+
models: {},
|
|
203
|
+
relations: {},
|
|
204
|
+
storage: {},
|
|
205
|
+
extensionPacks: {},
|
|
206
|
+
capabilities: {},
|
|
207
|
+
meta: {},
|
|
208
|
+
...ifDefined("execution", contract.execution)
|
|
209
|
+
}));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/emission/emit.ts
|
|
214
|
+
const CanonicalMetaSchema = type({ "[string]": "unknown" });
|
|
215
|
+
const CanonicalContractSchema = type({
|
|
216
|
+
"+": "reject",
|
|
217
|
+
schemaVersion: "string",
|
|
218
|
+
targetFamily: "string",
|
|
219
|
+
target: "string",
|
|
220
|
+
models: type({ "[string]": "unknown" }),
|
|
221
|
+
relations: type({ "[string]": "unknown" }),
|
|
222
|
+
storage: type({ "[string]": "unknown" }),
|
|
223
|
+
"execution?": type({ "[string]": "unknown" }),
|
|
224
|
+
extensionPacks: type({ "[string]": "unknown" }),
|
|
225
|
+
capabilities: type({ "[string]": type({ "[string]": "boolean" }) }),
|
|
226
|
+
meta: CanonicalMetaSchema
|
|
227
|
+
});
|
|
228
|
+
function assertCanonicalArtifactShape(value) {
|
|
229
|
+
const result = CanonicalContractSchema(value);
|
|
230
|
+
if (result instanceof type.errors) {
|
|
231
|
+
const issues = result.map((error) => {
|
|
232
|
+
return `${error.path?.toString() ?? "<root>"}: ${error.message}`;
|
|
233
|
+
}).join("; ");
|
|
234
|
+
throw new Error(`ContractIR canonical artifact validation failed: ${issues}`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function validateCoreStructure(ir) {
|
|
238
|
+
if (!ir.targetFamily) throw new Error("ContractIR must have targetFamily");
|
|
239
|
+
if (!ir.target) throw new Error("ContractIR must have target");
|
|
240
|
+
if (!ir.schemaVersion) throw new Error("ContractIR must have schemaVersion");
|
|
241
|
+
if (!ir.models || typeof ir.models !== "object") throw new Error("ContractIR must have models");
|
|
242
|
+
if (!ir.storage || typeof ir.storage !== "object") throw new Error("ContractIR must have storage");
|
|
243
|
+
if (!ir.relations || typeof ir.relations !== "object") throw new Error("ContractIR must have relations");
|
|
244
|
+
if (!ir.extensionPacks || typeof ir.extensionPacks !== "object") throw new Error("ContractIR must have extensionPacks");
|
|
245
|
+
if (!ir.capabilities || typeof ir.capabilities !== "object") throw new Error("ContractIR must have capabilities");
|
|
246
|
+
if (!ir.meta || typeof ir.meta !== "object") throw new Error("ContractIR must have meta");
|
|
247
|
+
}
|
|
248
|
+
async function emit(ir, options, targetFamily) {
|
|
249
|
+
const { operationRegistry, codecTypeImports, operationTypeImports, extensionIds, parameterizedRenderers, parameterizedTypeImports } = options;
|
|
250
|
+
validateCoreStructure(ir);
|
|
251
|
+
const ctx = {
|
|
252
|
+
...ifDefined("operationRegistry", operationRegistry),
|
|
253
|
+
...ifDefined("codecTypeImports", codecTypeImports),
|
|
254
|
+
...ifDefined("operationTypeImports", operationTypeImports),
|
|
255
|
+
...ifDefined("extensionIds", extensionIds)
|
|
256
|
+
};
|
|
257
|
+
targetFamily.validateTypes(ir, ctx);
|
|
258
|
+
targetFamily.validateStructure(ir);
|
|
259
|
+
const canonicalContract = {
|
|
260
|
+
schemaVersion: ir.schemaVersion,
|
|
261
|
+
targetFamily: ir.targetFamily,
|
|
262
|
+
target: ir.target,
|
|
263
|
+
models: ir.models,
|
|
264
|
+
relations: ir.relations,
|
|
265
|
+
storage: ir.storage,
|
|
266
|
+
...ifDefined("execution", ir.execution),
|
|
267
|
+
extensionPacks: ir.extensionPacks,
|
|
268
|
+
capabilities: ir.capabilities,
|
|
269
|
+
meta: ir.meta
|
|
270
|
+
};
|
|
271
|
+
assertCanonicalArtifactShape(canonicalContract);
|
|
272
|
+
const storageHash = computeStorageHash(canonicalContract);
|
|
273
|
+
const executionHash = canonicalContract.execution ? computeExecutionHash(canonicalContract) : void 0;
|
|
274
|
+
const profileHash = computeProfileHash(canonicalContract);
|
|
275
|
+
const contractWithHashes = {
|
|
276
|
+
...canonicalContract,
|
|
277
|
+
storageHash,
|
|
278
|
+
...ifDefined("executionHash", executionHash),
|
|
279
|
+
profileHash
|
|
280
|
+
};
|
|
281
|
+
const contractJsonWithMeta = {
|
|
282
|
+
...JSON.parse(canonicalizeContract(contractWithHashes)),
|
|
283
|
+
_generated: {
|
|
284
|
+
warning: "⚠️ GENERATED FILE - DO NOT EDIT",
|
|
285
|
+
message: "This file is automatically generated by \"prisma-next contract emit\".",
|
|
286
|
+
regenerate: "To regenerate, run: prisma-next contract emit"
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
const contractJsonString = JSON.stringify(contractJsonWithMeta, null, 2);
|
|
290
|
+
const generateOptions = parameterizedRenderers || parameterizedTypeImports ? {
|
|
291
|
+
...ifDefined("parameterizedRenderers", parameterizedRenderers),
|
|
292
|
+
...ifDefined("parameterizedTypeImports", parameterizedTypeImports)
|
|
293
|
+
} : void 0;
|
|
294
|
+
const contractTypeHashes = {
|
|
295
|
+
storageHash,
|
|
296
|
+
...ifDefined("executionHash", executionHash),
|
|
297
|
+
profileHash
|
|
298
|
+
};
|
|
299
|
+
return {
|
|
300
|
+
contractJson: contractJsonString,
|
|
301
|
+
contractDts: await format(targetFamily.generateContractTypes(ir, codecTypeImports ?? [], operationTypeImports ?? [], contractTypeHashes, generateOptions), {
|
|
302
|
+
parser: "typescript",
|
|
303
|
+
singleQuote: true,
|
|
304
|
+
semi: true,
|
|
305
|
+
printWidth: 100
|
|
306
|
+
}),
|
|
307
|
+
storageHash,
|
|
308
|
+
...ifDefined("executionHash", executionHash),
|
|
309
|
+
profileHash
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
//#endregion
|
|
314
|
+
export { canonicalizeContract, computeExecutionHash, computeProfileHash, computeStorageHash, emit };
|
|
315
|
+
//# sourceMappingURL=emission.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emission.mjs","names":["result: Record<string, unknown>","sorted: Record<string, unknown>","result: StorageObject","sortedTable: TableObject","ordered: Record<string, unknown>","normalized: NormalizedContract","ctx: ValidationContext"],"sources":["../src/emission/canonicalization.ts","../src/emission/hashing.ts","../src/emission/emit.ts"],"sourcesContent":["import { bigintJsonReplacer } from '@prisma-next/contract/types';\nimport { isArrayEqual } from '@prisma-next/utils/array-equal';\nimport { ifDefined } from '@prisma-next/utils/defined';\n\ntype NormalizedContract = {\n schemaVersion: string;\n targetFamily: string;\n target: string;\n storageHash?: string;\n executionHash?: string;\n profileHash?: string;\n models: Record<string, unknown>;\n relations: Record<string, unknown>;\n storage: Record<string, unknown>;\n execution?: Record<string, unknown>;\n extensionPacks: Record<string, unknown>;\n capabilities: Record<string, Record<string, boolean>>;\n meta: Record<string, unknown>;\n};\n\nexport type CanonicalContractInput = {\n schemaVersion: string;\n targetFamily: string;\n target: string;\n models: Record<string, unknown>;\n relations: Record<string, unknown>;\n storage: Record<string, unknown>;\n execution?: Record<string, unknown>;\n extensionPacks: Record<string, unknown>;\n capabilities: Record<string, Record<string, boolean>>;\n meta: Record<string, unknown>;\n storageHash?: string;\n executionHash?: string;\n profileHash?: string;\n};\n\nconst TOP_LEVEL_ORDER = [\n 'schemaVersion',\n 'canonicalVersion',\n 'targetFamily',\n 'target',\n 'storageHash',\n 'executionHash',\n 'profileHash',\n 'models',\n 'relations',\n 'storage',\n 'execution',\n 'capabilities',\n 'extensionPacks',\n 'meta',\n] as const;\n\nfunction isDefaultValue(value: unknown): boolean {\n if (value === false) return true;\n if (value === null) return false;\n if (value instanceof Date) return false;\n if (Array.isArray(value) && value.length === 0) return true;\n if (typeof value === 'object' && value !== null) {\n const keys = Object.keys(value);\n return keys.length === 0;\n }\n return false;\n}\n\nfunction omitDefaults(obj: unknown, path: readonly string[]): unknown {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (obj instanceof Date) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => omitDefaults(item, path));\n }\n\n const result: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n const currentPath = [...path, key];\n\n // Exclude metadata fields from canonicalization\n if (key === '_generated') {\n continue;\n }\n\n if (key === 'nullable' && value === false) {\n continue;\n }\n\n if (key === 'generated' && value === false) {\n continue;\n }\n\n // Strip 'noAction' referential actions (the database default) for hash stability.\n // A contract with explicit `onDelete: 'noAction'` is semantically identical to\n // one that omits `onDelete` entirely, so they should produce the same hash.\n if ((key === 'onDelete' || key === 'onUpdate') && value === 'noAction') {\n continue;\n }\n\n if (isDefaultValue(value)) {\n const isRequiredModels = isArrayEqual(currentPath, ['models']);\n const isRequiredTables = isArrayEqual(currentPath, ['storage', 'tables']);\n const isRequiredRelations = isArrayEqual(currentPath, ['relations']);\n const isRequiredExtensionPacks = isArrayEqual(currentPath, ['extensionPacks']);\n const isRequiredCapabilities = isArrayEqual(currentPath, ['capabilities']);\n const isRequiredMeta = isArrayEqual(currentPath, ['meta']);\n const isRequiredExecutionDefaults = isArrayEqual(currentPath, [\n 'execution',\n 'mutations',\n 'defaults',\n ]);\n const isExtensionNamespace = currentPath.length === 2 && currentPath[0] === 'extensionPacks';\n const isModelRelations =\n currentPath.length === 3 &&\n isArrayEqual([currentPath[0], currentPath[2]], ['models', 'relations']);\n const isTableUniques =\n currentPath.length === 4 &&\n isArrayEqual(\n [currentPath[0], currentPath[1], currentPath[3]],\n ['storage', 'tables', 'uniques'],\n );\n const isTableIndexes =\n currentPath.length === 4 &&\n isArrayEqual(\n [currentPath[0], currentPath[1], currentPath[3]],\n ['storage', 'tables', 'indexes'],\n );\n const isTableForeignKeys =\n currentPath.length === 4 &&\n isArrayEqual(\n [currentPath[0], currentPath[1], currentPath[3]],\n ['storage', 'tables', 'foreignKeys'],\n );\n\n // Preserve per-FK `constraint` and `index` booleans (even when `false`)\n // so that hash distinguishes `false` from absent.\n // Path: ['storage', 'tables', <tableName>, 'foreignKeys', 'constraint' | 'index']\n const isFkBooleanField =\n currentPath.length === 5 &&\n currentPath[0] === 'storage' &&\n currentPath[1] === 'tables' &&\n currentPath[3] === 'foreignKeys' &&\n (key === 'constraint' || key === 'index');\n\n if (\n !isRequiredModels &&\n !isRequiredTables &&\n !isRequiredRelations &&\n !isRequiredExtensionPacks &&\n !isRequiredCapabilities &&\n !isRequiredMeta &&\n !isRequiredExecutionDefaults &&\n !isExtensionNamespace &&\n !isModelRelations &&\n !isTableUniques &&\n !isTableIndexes &&\n !isTableForeignKeys &&\n !isFkBooleanField\n ) {\n continue;\n }\n }\n\n result[key] = omitDefaults(value, currentPath);\n }\n\n return result;\n}\n\nfunction sortObjectKeys(obj: unknown): unknown {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (obj instanceof Date) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => sortObjectKeys(item));\n }\n\n const sorted: Record<string, unknown> = {};\n const keys = Object.keys(obj).sort();\n for (const key of keys) {\n sorted[key] = sortObjectKeys((obj as Record<string, unknown>)[key]);\n }\n\n return sorted;\n}\n\ntype StorageObject = {\n tables?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\ntype TableObject = {\n indexes?: unknown[];\n uniques?: unknown[];\n [key: string]: unknown;\n};\n\nfunction sortIndexesAndUniques(storage: unknown): unknown {\n if (!storage || typeof storage !== 'object') {\n return storage;\n }\n\n const storageObj = storage as StorageObject;\n if (!storageObj.tables || typeof storageObj.tables !== 'object') {\n return storage;\n }\n\n const tables = storageObj.tables;\n const result: StorageObject = { ...storageObj };\n\n result.tables = {};\n // Sort table names to ensure deterministic ordering\n const sortedTableNames = Object.keys(tables).sort();\n for (const tableName of sortedTableNames) {\n const table = tables[tableName];\n if (!table || typeof table !== 'object') {\n result.tables[tableName] = table;\n continue;\n }\n\n const tableObj = table as TableObject;\n const sortedTable: TableObject = { ...tableObj };\n\n if (Array.isArray(tableObj.indexes)) {\n sortedTable.indexes = [...tableObj.indexes].sort((a, b) => {\n const nameA = (a as { name?: string })?.name || '';\n const nameB = (b as { name?: string })?.name || '';\n return nameA.localeCompare(nameB);\n });\n }\n\n if (Array.isArray(tableObj.uniques)) {\n sortedTable.uniques = [...tableObj.uniques].sort((a, b) => {\n const nameA = (a as { name?: string })?.name || '';\n const nameB = (b as { name?: string })?.name || '';\n return nameA.localeCompare(nameB);\n });\n }\n\n result.tables[tableName] = sortedTable;\n }\n\n return result;\n}\n\nfunction orderTopLevel(obj: Record<string, unknown>): Record<string, unknown> {\n const ordered: Record<string, unknown> = {};\n const remaining = new Set(Object.keys(obj));\n\n for (const key of TOP_LEVEL_ORDER) {\n if (remaining.has(key)) {\n ordered[key] = obj[key];\n remaining.delete(key);\n }\n }\n\n for (const key of Array.from(remaining).sort()) {\n ordered[key] = obj[key];\n }\n\n return ordered;\n}\n\nexport function canonicalizeContract(ir: CanonicalContractInput): string {\n const normalized: NormalizedContract = {\n schemaVersion: ir.schemaVersion,\n targetFamily: ir.targetFamily,\n target: ir.target,\n models: ir.models,\n relations: ir.relations,\n storage: ir.storage,\n ...ifDefined('execution', ir.execution),\n extensionPacks: ir.extensionPacks,\n capabilities: ir.capabilities,\n meta: ir.meta,\n };\n Object.assign(\n normalized,\n ifDefined('storageHash', ir.storageHash),\n ifDefined('executionHash', ir.executionHash),\n ifDefined('profileHash', ir.profileHash),\n );\n\n const withDefaultsOmitted = omitDefaults(normalized, []) as NormalizedContract;\n const withSortedIndexes = sortIndexesAndUniques(withDefaultsOmitted.storage);\n const withSortedStorage = { ...withDefaultsOmitted, storage: withSortedIndexes };\n const withSortedKeys = sortObjectKeys(withSortedStorage) as Record<string, unknown>;\n const withOrderedTopLevel = orderTopLevel(withSortedKeys);\n\n return JSON.stringify(withOrderedTopLevel, bigintJsonReplacer, 2);\n}\n","import { createHash } from 'node:crypto';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { CanonicalContractInput } from './canonicalization';\nimport { canonicalizeContract } from './canonicalization';\n\nfunction computeHash(content: string): string {\n const hash = createHash('sha256');\n hash.update(content);\n return `sha256:${hash.digest('hex')}`;\n}\n\nexport function computeStorageHash(contract: CanonicalContractInput): string {\n const storageContract = {\n schemaVersion: contract.schemaVersion,\n targetFamily: contract.targetFamily,\n target: contract.target,\n storage: contract.storage,\n models: {},\n relations: {},\n extensionPacks: {},\n capabilities: {},\n meta: {},\n };\n const canonical = canonicalizeContract(storageContract);\n return computeHash(canonical);\n}\n\nexport function computeProfileHash(contract: CanonicalContractInput): string {\n const profileContract = {\n schemaVersion: contract.schemaVersion,\n targetFamily: contract.targetFamily,\n target: contract.target,\n models: {},\n relations: {},\n storage: {},\n extensionPacks: {},\n capabilities: contract.capabilities,\n meta: {},\n };\n const canonical = canonicalizeContract(profileContract);\n return computeHash(canonical);\n}\n\nexport function computeExecutionHash(contract: CanonicalContractInput): string {\n const executionContract = {\n schemaVersion: contract.schemaVersion,\n targetFamily: contract.targetFamily,\n target: contract.target,\n models: {},\n relations: {},\n storage: {},\n extensionPacks: {},\n capabilities: {},\n meta: {},\n ...ifDefined('execution', contract.execution),\n };\n const canonical = canonicalizeContract(executionContract);\n return computeHash(canonical);\n}\n","import type { ContractIR } from '@prisma-next/contract/ir';\nimport type { TargetFamilyHook, ValidationContext } from '@prisma-next/contract/types';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { type } from 'arktype';\nimport { format } from 'prettier';\nimport { canonicalizeContract } from './canonicalization';\nimport { computeExecutionHash, computeProfileHash, computeStorageHash } from './hashing';\nimport type { EmitOptions, EmitResult } from './types';\n\nconst CanonicalMetaSchema = type({\n '[string]': 'unknown',\n});\n\nconst CanonicalContractSchema = type({\n '+': 'reject',\n schemaVersion: 'string',\n targetFamily: 'string',\n target: 'string',\n models: type({ '[string]': 'unknown' }),\n relations: type({ '[string]': 'unknown' }),\n storage: type({ '[string]': 'unknown' }),\n 'execution?': type({ '[string]': 'unknown' }),\n extensionPacks: type({ '[string]': 'unknown' }),\n capabilities: type({\n '[string]': type({\n '[string]': 'boolean',\n }),\n }),\n meta: CanonicalMetaSchema,\n});\n\nfunction assertCanonicalArtifactShape(value: unknown): void {\n const result = CanonicalContractSchema(value);\n if (result instanceof type.errors) {\n const issues = result\n .map((error) => {\n const path = error.path?.toString() ?? '<root>';\n return `${path}: ${error.message}`;\n })\n .join('; ');\n throw new Error(`ContractIR canonical artifact validation failed: ${issues}`);\n }\n}\n\nfunction validateCoreStructure(ir: ContractIR): void {\n if (!ir.targetFamily) {\n throw new Error('ContractIR must have targetFamily');\n }\n if (!ir.target) {\n throw new Error('ContractIR must have target');\n }\n if (!ir.schemaVersion) {\n throw new Error('ContractIR must have schemaVersion');\n }\n if (!ir.models || typeof ir.models !== 'object') {\n throw new Error('ContractIR must have models');\n }\n if (!ir.storage || typeof ir.storage !== 'object') {\n throw new Error('ContractIR must have storage');\n }\n if (!ir.relations || typeof ir.relations !== 'object') {\n throw new Error('ContractIR must have relations');\n }\n if (!ir.extensionPacks || typeof ir.extensionPacks !== 'object') {\n throw new Error('ContractIR must have extensionPacks');\n }\n if (!ir.capabilities || typeof ir.capabilities !== 'object') {\n throw new Error('ContractIR must have capabilities');\n }\n if (!ir.meta || typeof ir.meta !== 'object') {\n throw new Error('ContractIR must have meta');\n }\n}\n\nexport async function emit(\n ir: ContractIR,\n options: EmitOptions,\n targetFamily: TargetFamilyHook,\n): Promise<EmitResult> {\n const {\n operationRegistry,\n codecTypeImports,\n operationTypeImports,\n extensionIds,\n parameterizedRenderers,\n parameterizedTypeImports,\n } = options;\n\n validateCoreStructure(ir);\n\n const ctx: ValidationContext = {\n ...ifDefined('operationRegistry', operationRegistry),\n ...ifDefined('codecTypeImports', codecTypeImports),\n ...ifDefined('operationTypeImports', operationTypeImports),\n ...ifDefined('extensionIds', extensionIds),\n };\n targetFamily.validateTypes(ir, ctx);\n\n targetFamily.validateStructure(ir);\n\n const canonicalContract = {\n schemaVersion: ir.schemaVersion,\n targetFamily: ir.targetFamily,\n target: ir.target,\n models: ir.models,\n relations: ir.relations,\n storage: ir.storage,\n ...ifDefined('execution', ir.execution),\n extensionPacks: ir.extensionPacks,\n capabilities: ir.capabilities,\n meta: ir.meta,\n };\n assertCanonicalArtifactShape(canonicalContract);\n\n const storageHash = computeStorageHash(canonicalContract);\n const executionHash = canonicalContract.execution\n ? computeExecutionHash(canonicalContract)\n : undefined;\n const profileHash = computeProfileHash(canonicalContract);\n\n const contractWithHashes = {\n ...canonicalContract,\n storageHash,\n ...ifDefined('executionHash', executionHash),\n profileHash,\n };\n\n // Add _generated metadata to indicate this is a generated artifact\n // This ensures consistency between CLI emit and programmatic emit\n // Always add/update _generated with standard content for consistency\n const contractJsonObj = JSON.parse(canonicalizeContract(contractWithHashes)) as Record<\n string,\n unknown\n >;\n const contractJsonWithMeta = {\n ...contractJsonObj,\n _generated: {\n warning: '⚠️ GENERATED FILE - DO NOT EDIT',\n message: 'This file is automatically generated by \"prisma-next contract emit\".',\n regenerate: 'To regenerate, run: prisma-next contract emit',\n },\n };\n const contractJsonString = JSON.stringify(contractJsonWithMeta, null, 2);\n\n const generateOptions =\n parameterizedRenderers || parameterizedTypeImports\n ? {\n ...ifDefined('parameterizedRenderers', parameterizedRenderers),\n ...ifDefined('parameterizedTypeImports', parameterizedTypeImports),\n }\n : undefined;\n\n const contractTypeHashes = {\n storageHash,\n ...ifDefined('executionHash', executionHash),\n profileHash,\n };\n const contractDtsRaw = targetFamily.generateContractTypes(\n ir,\n codecTypeImports ?? [],\n operationTypeImports ?? [],\n contractTypeHashes,\n generateOptions,\n );\n const contractDts = await format(contractDtsRaw, {\n parser: 'typescript',\n singleQuote: true,\n semi: true,\n printWidth: 100,\n });\n\n return {\n contractJson: contractJsonString,\n contractDts,\n storageHash,\n ...ifDefined('executionHash', executionHash),\n profileHash,\n };\n}\n"],"mappings":";;;;;;;;AAoCA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,SAAS,eAAe,OAAyB;AAC/C,KAAI,UAAU,MAAO,QAAO;AAC5B,KAAI,UAAU,KAAM,QAAO;AAC3B,KAAI,iBAAiB,KAAM,QAAO;AAClC,KAAI,MAAM,QAAQ,MAAM,IAAI,MAAM,WAAW,EAAG,QAAO;AACvD,KAAI,OAAO,UAAU,YAAY,UAAU,KAE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;AAeD,QAAO;EACL,cAAc;EACd,aATkB,MAAM,OAPH,aAAa,sBAClC,IACA,oBAAoB,EAAE,EACtB,wBAAwB,EAAE,EAC1B,oBACA,gBACD,EACgD;GAC/C,QAAQ;GACR,aAAa;GACb,MAAM;GACN,YAAY;GACb,CAAC;EAKA;EACA,GAAG,UAAU,iBAAiB,cAAc;EAC5C;EACD"}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { h as SchemaIssue, y as VerifyDatabaseSchemaResult } from "./types-BArIWumw.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/errors.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* CLI error envelope for output formatting.
|
|
7
|
+
* This is the serialized form of a CliStructuredError.
|
|
8
|
+
*/
|
|
9
|
+
interface CliErrorEnvelope {
|
|
10
|
+
readonly ok: false;
|
|
11
|
+
readonly code: string;
|
|
12
|
+
readonly domain: string;
|
|
13
|
+
readonly severity: 'error' | 'warn' | 'info';
|
|
14
|
+
readonly summary: string;
|
|
15
|
+
readonly why: string | undefined;
|
|
16
|
+
readonly fix: string | undefined;
|
|
17
|
+
readonly where: {
|
|
18
|
+
readonly path: string | undefined;
|
|
19
|
+
readonly line: number | undefined;
|
|
20
|
+
} | undefined;
|
|
21
|
+
readonly meta: Record<string, unknown> | undefined;
|
|
22
|
+
readonly docsUrl: string | undefined;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Minimal conflict data structure expected by CLI output.
|
|
26
|
+
*/
|
|
27
|
+
interface CliErrorConflict {
|
|
28
|
+
readonly kind: string;
|
|
29
|
+
readonly summary: string;
|
|
30
|
+
readonly why?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Structured CLI error that contains all information needed for error envelopes.
|
|
34
|
+
* Call sites throw these errors with full context.
|
|
35
|
+
*/
|
|
36
|
+
declare class CliStructuredError extends Error {
|
|
37
|
+
readonly code: string;
|
|
38
|
+
readonly domain: 'CLI' | 'RUN';
|
|
39
|
+
readonly severity: 'error' | 'warn' | 'info';
|
|
40
|
+
readonly why: string | undefined;
|
|
41
|
+
readonly fix: string | undefined;
|
|
42
|
+
readonly where: {
|
|
43
|
+
readonly path: string | undefined;
|
|
44
|
+
readonly line: number | undefined;
|
|
45
|
+
} | undefined;
|
|
46
|
+
readonly meta: Record<string, unknown> | undefined;
|
|
47
|
+
readonly docsUrl: string | undefined;
|
|
48
|
+
constructor(code: string, summary: string, options?: {
|
|
49
|
+
readonly domain?: 'CLI' | 'RUN';
|
|
50
|
+
readonly severity?: 'error' | 'warn' | 'info';
|
|
51
|
+
readonly why?: string;
|
|
52
|
+
readonly fix?: string;
|
|
53
|
+
readonly where?: {
|
|
54
|
+
readonly path?: string;
|
|
55
|
+
readonly line?: number;
|
|
56
|
+
};
|
|
57
|
+
readonly meta?: Record<string, unknown>;
|
|
58
|
+
readonly docsUrl?: string;
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* Converts this error to a CLI error envelope for output formatting.
|
|
62
|
+
*/
|
|
63
|
+
toEnvelope(): CliErrorEnvelope;
|
|
64
|
+
/**
|
|
65
|
+
* Type guard to check if an error is a CliStructuredError.
|
|
66
|
+
* Uses duck-typing to work across module boundaries where instanceof may fail.
|
|
67
|
+
*/
|
|
68
|
+
static is(error: unknown): error is CliStructuredError;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Config file not found or missing.
|
|
72
|
+
*/
|
|
73
|
+
declare function errorConfigFileNotFound(configPath?: string, options?: {
|
|
74
|
+
readonly why?: string;
|
|
75
|
+
}): CliStructuredError;
|
|
76
|
+
/**
|
|
77
|
+
* Contract configuration missing from config.
|
|
78
|
+
*/
|
|
79
|
+
declare function errorContractConfigMissing(options?: {
|
|
80
|
+
readonly why?: string;
|
|
81
|
+
}): CliStructuredError;
|
|
82
|
+
/**
|
|
83
|
+
* Contract validation failed.
|
|
84
|
+
*/
|
|
85
|
+
declare function errorContractValidationFailed(reason: string, options?: {
|
|
86
|
+
readonly where?: {
|
|
87
|
+
readonly path?: string;
|
|
88
|
+
readonly line?: number;
|
|
89
|
+
};
|
|
90
|
+
}): CliStructuredError;
|
|
91
|
+
/**
|
|
92
|
+
* File not found.
|
|
93
|
+
*/
|
|
94
|
+
declare function errorFileNotFound(filePath: string, options?: {
|
|
95
|
+
readonly why?: string;
|
|
96
|
+
readonly fix?: string;
|
|
97
|
+
readonly docsUrl?: string;
|
|
98
|
+
}): CliStructuredError;
|
|
99
|
+
/**
|
|
100
|
+
* Database connection is required but not provided.
|
|
101
|
+
*/
|
|
102
|
+
declare function errorDatabaseConnectionRequired(options?: {
|
|
103
|
+
readonly why?: string;
|
|
104
|
+
readonly commandName?: string;
|
|
105
|
+
readonly retryCommand?: string;
|
|
106
|
+
}): CliStructuredError;
|
|
107
|
+
/**
|
|
108
|
+
* Query runner factory is required but not provided in config.
|
|
109
|
+
*/
|
|
110
|
+
declare function errorQueryRunnerFactoryRequired(options?: {
|
|
111
|
+
readonly why?: string;
|
|
112
|
+
}): CliStructuredError;
|
|
113
|
+
/**
|
|
114
|
+
* Family verify.readMarker is required but not provided.
|
|
115
|
+
*/
|
|
116
|
+
declare function errorFamilyReadMarkerSqlRequired(options?: {
|
|
117
|
+
readonly why?: string;
|
|
118
|
+
}): CliStructuredError;
|
|
119
|
+
/**
|
|
120
|
+
* JSON output format not supported.
|
|
121
|
+
*/
|
|
122
|
+
declare function errorJsonFormatNotSupported(options: {
|
|
123
|
+
readonly command: string;
|
|
124
|
+
readonly format: string;
|
|
125
|
+
readonly supportedFormats: readonly string[];
|
|
126
|
+
}): CliStructuredError;
|
|
127
|
+
/**
|
|
128
|
+
* Driver is required for DB-connected commands but not provided.
|
|
129
|
+
*/
|
|
130
|
+
declare function errorDriverRequired(options?: {
|
|
131
|
+
readonly why?: string;
|
|
132
|
+
}): CliStructuredError;
|
|
133
|
+
/**
|
|
134
|
+
* Contract requires extension packs that are not provided by config descriptors.
|
|
135
|
+
*/
|
|
136
|
+
declare function errorContractMissingExtensionPacks(options: {
|
|
137
|
+
readonly missingExtensionPacks: readonly string[];
|
|
138
|
+
readonly providedComponentIds: readonly string[];
|
|
139
|
+
}): CliStructuredError;
|
|
140
|
+
/**
|
|
141
|
+
* Migration planning failed due to conflicts.
|
|
142
|
+
*/
|
|
143
|
+
declare function errorMigrationPlanningFailed(options: {
|
|
144
|
+
readonly conflicts: readonly CliErrorConflict[];
|
|
145
|
+
readonly why?: string;
|
|
146
|
+
}): CliStructuredError;
|
|
147
|
+
/**
|
|
148
|
+
* Target does not support migrations (missing createPlanner/createRunner).
|
|
149
|
+
*/
|
|
150
|
+
declare function errorTargetMigrationNotSupported(options?: {
|
|
151
|
+
readonly why?: string;
|
|
152
|
+
}): CliStructuredError;
|
|
153
|
+
/**
|
|
154
|
+
* Config validation error (missing required fields).
|
|
155
|
+
*/
|
|
156
|
+
declare function errorConfigValidation(field: string, options?: {
|
|
157
|
+
readonly why?: string;
|
|
158
|
+
}): CliStructuredError;
|
|
159
|
+
/**
|
|
160
|
+
* Contract marker not found in database.
|
|
161
|
+
*/
|
|
162
|
+
declare function errorMarkerMissing(options?: {
|
|
163
|
+
readonly why?: string;
|
|
164
|
+
readonly dbUrl?: string;
|
|
165
|
+
}): CliStructuredError;
|
|
166
|
+
/**
|
|
167
|
+
* Contract hash does not match database marker.
|
|
168
|
+
*/
|
|
169
|
+
declare function errorHashMismatch(options?: {
|
|
170
|
+
readonly why?: string;
|
|
171
|
+
readonly expected?: string;
|
|
172
|
+
readonly actual?: string;
|
|
173
|
+
}): CliStructuredError;
|
|
174
|
+
/**
|
|
175
|
+
* Contract target does not match config target.
|
|
176
|
+
*/
|
|
177
|
+
declare function errorTargetMismatch(expected: string, actual: string, options?: {
|
|
178
|
+
readonly why?: string;
|
|
179
|
+
}): CliStructuredError;
|
|
180
|
+
/**
|
|
181
|
+
* Database marker is required but not found.
|
|
182
|
+
* Used by commands that require a pre-existing marker as a precondition.
|
|
183
|
+
*/
|
|
184
|
+
declare function errorMarkerRequired(options?: {
|
|
185
|
+
readonly why?: string;
|
|
186
|
+
readonly fix?: string;
|
|
187
|
+
}): CliStructuredError;
|
|
188
|
+
/**
|
|
189
|
+
* Schema verification found mismatches between the database and the contract.
|
|
190
|
+
* The full verification tree is preserved in `meta.verificationResult`.
|
|
191
|
+
*/
|
|
192
|
+
declare function errorSchemaVerificationFailed(options: {
|
|
193
|
+
readonly summary: string;
|
|
194
|
+
readonly verificationResult: VerifyDatabaseSchemaResult;
|
|
195
|
+
readonly issues?: readonly SchemaIssue[];
|
|
196
|
+
}): CliStructuredError;
|
|
197
|
+
/**
|
|
198
|
+
* Migration runner failed during execution.
|
|
199
|
+
*/
|
|
200
|
+
declare function errorRunnerFailed(summary: string, options?: {
|
|
201
|
+
readonly why?: string;
|
|
202
|
+
readonly fix?: string;
|
|
203
|
+
readonly meta?: Record<string, unknown>;
|
|
204
|
+
}): CliStructuredError;
|
|
205
|
+
/** Error code for destructive changes that require explicit confirmation. */
|
|
206
|
+
declare const ERROR_CODE_DESTRUCTIVE_CHANGES = "3030";
|
|
207
|
+
/**
|
|
208
|
+
* Destructive operations require explicit confirmation via -y/--yes.
|
|
209
|
+
*/
|
|
210
|
+
declare function errorDestructiveChanges(summary: string, options?: {
|
|
211
|
+
readonly why?: string;
|
|
212
|
+
readonly fix?: string;
|
|
213
|
+
readonly meta?: Record<string, unknown>;
|
|
214
|
+
}): CliStructuredError;
|
|
215
|
+
/**
|
|
216
|
+
* Generic runtime error.
|
|
217
|
+
*/
|
|
218
|
+
declare function errorRuntime(summary: string, options?: {
|
|
219
|
+
readonly why?: string;
|
|
220
|
+
readonly fix?: string;
|
|
221
|
+
readonly meta?: Record<string, unknown>;
|
|
222
|
+
}): CliStructuredError;
|
|
223
|
+
/**
|
|
224
|
+
* Generic unexpected error.
|
|
225
|
+
*/
|
|
226
|
+
declare function errorUnexpected(message: string, options?: {
|
|
227
|
+
readonly why?: string;
|
|
228
|
+
readonly fix?: string;
|
|
229
|
+
}): CliStructuredError;
|
|
230
|
+
//#endregion
|
|
231
|
+
export { type CliErrorConflict, type CliErrorEnvelope, CliStructuredError, ERROR_CODE_DESTRUCTIVE_CHANGES, errorConfigFileNotFound, errorConfigValidation, errorContractConfigMissing, errorContractMissingExtensionPacks, errorContractValidationFailed, errorDatabaseConnectionRequired, errorDestructiveChanges, errorDriverRequired, errorFamilyReadMarkerSqlRequired, errorFileNotFound, errorHashMismatch, errorJsonFormatNotSupported, errorMarkerMissing, errorMarkerRequired, errorMigrationPlanningFailed, errorQueryRunnerFactoryRequired, errorRunnerFailed, errorRuntime, errorSchemaVerificationFailed, errorTargetMigrationNotSupported, errorTargetMismatch, errorUnexpected };
|
|
232
|
+
//# sourceMappingURL=errors.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.mts","names":[],"sources":["../src/errors.ts"],"sourcesContent":[],"mappings":";;;;;;AAOA;AAqBA;AAUa,UA/BI,gBAAA,CA+Be;EAYf,SAAA,EAAA,EAAA,KAAA;EAYK,SAAA,IAAA,EAAA,MAAA;EAwBN,SAAA,MAAA,EAAA,MAAA;EAoBsB,SAAA,QAAA,EAAA,OAAA,GAAA,MAAA,GAAA,MAAA;EApEE,SAAA,OAAA,EAAA,MAAA;EAAK,SAAA,GAAA,EAAA,MAAA,GAAA,SAAA;EAyF7B,SAAA,GAAA,EAAA,MAAA,GAAA,SAAuB;EAkBvB,SAAA,KAAA,EAAA;IAcA,SAAA,IAAA,EAAA,MAAA,GAAA,SAA6B;IAkB7B,SAAA,IAAA,EAAA,MAAiB,GAAA,SAO9B;EAaa,CAAA,GAAA,SAAA;EAoBA,SAAA,IAAA,EApMC,MAoMD,CAAA,MAAA,EAAA,OAA+B,CAAA,GAAA,SAE3C;EAYY,SAAA,OAAA,EAAA,MAAA,GAAA,SAAgC;AAchD;AAoBA;AAYA;AAuBA;AA6BgB,UA7SC,gBAAA,CA6SD;EAcA,SAAA,IAAA,EAAA,MAAA;EAqBA,SA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