@prisma-next/core-control-plane 0.3.0-pr.93.5 → 0.3.0-pr.94.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/config-types-h9ifypQ0.d.mts +79 -0
- package/dist/config-types-h9ifypQ0.d.mts.map +1 -0
- package/dist/config-types.d.mts +2 -0
- package/dist/config-types.mjs +65 -0
- package/dist/config-types.mjs.map +1 -0
- package/dist/config-validation.d.mts +15 -0
- package/dist/config-validation.d.mts.map +1 -0
- package/dist/config-validation.mjs +79 -0
- package/dist/config-validation.mjs.map +1 -0
- package/dist/emission.d.mts +47 -0
- package/dist/emission.d.mts.map +1 -0
- package/dist/emission.mjs +255 -0
- package/dist/emission.mjs.map +1 -0
- package/dist/errors-Qlh0sdcb.mjs +276 -0
- package/dist/errors-Qlh0sdcb.mjs.map +1 -0
- package/dist/errors.d.mts +191 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +3 -0
- package/dist/{schema-view.d.ts → schema-view-BG_ebqoV.d.mts} +13 -10
- package/dist/schema-view-BG_ebqoV.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-CsaU_uQP.d.mts +595 -0
- package/dist/types-CsaU_uQP.d.mts.map +1 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +1 -0
- package/package.json +19 -35
- package/dist/chunk-YT6YGR3N.js +0 -240
- package/dist/chunk-YT6YGR3N.js.map +0 -1
- package/dist/config-types.d.ts +0 -79
- 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 -188
- 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 -13
- package/dist/exports/stack.js.map +0 -1
- package/dist/exports/types.d.ts +0 -2
- package/dist/exports/types.d.ts.map +0 -1
- package/dist/exports/types.js +0 -1
- 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 -416
- package/dist/types.d.ts.map +0 -1
package/dist/exports/emission.js
DELETED
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
// src/emission/canonicalization.ts
|
|
2
|
-
import { isArrayEqual } from "@prisma-next/utils/array-equal";
|
|
3
|
-
var TOP_LEVEL_ORDER = [
|
|
4
|
-
"schemaVersion",
|
|
5
|
-
"canonicalVersion",
|
|
6
|
-
"targetFamily",
|
|
7
|
-
"target",
|
|
8
|
-
"coreHash",
|
|
9
|
-
"profileHash",
|
|
10
|
-
"models",
|
|
11
|
-
"storage",
|
|
12
|
-
"capabilities",
|
|
13
|
-
"extensionPacks",
|
|
14
|
-
"meta",
|
|
15
|
-
"sources"
|
|
16
|
-
];
|
|
17
|
-
function isDefaultValue(value) {
|
|
18
|
-
if (value === false) return true;
|
|
19
|
-
if (value === null) return false;
|
|
20
|
-
if (Array.isArray(value) && value.length === 0) return true;
|
|
21
|
-
if (typeof value === "object" && value !== null) {
|
|
22
|
-
const keys = Object.keys(value);
|
|
23
|
-
return keys.length === 0;
|
|
24
|
-
}
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
function omitDefaults(obj, path) {
|
|
28
|
-
if (obj === null || typeof obj !== "object") {
|
|
29
|
-
return obj;
|
|
30
|
-
}
|
|
31
|
-
if (Array.isArray(obj)) {
|
|
32
|
-
return obj.map((item) => omitDefaults(item, path));
|
|
33
|
-
}
|
|
34
|
-
const result = {};
|
|
35
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
36
|
-
const currentPath = [...path, key];
|
|
37
|
-
if (key === "_generated") {
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
if (key === "nullable" && value === false) {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
if (key === "generated" && value === false) {
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
if (isDefaultValue(value)) {
|
|
47
|
-
const isRequiredModels = isArrayEqual(currentPath, ["models"]);
|
|
48
|
-
const isRequiredTables = isArrayEqual(currentPath, ["storage", "tables"]);
|
|
49
|
-
const isRequiredRelations = isArrayEqual(currentPath, ["relations"]);
|
|
50
|
-
const isRequiredExtensionPacks = isArrayEqual(currentPath, ["extensionPacks"]);
|
|
51
|
-
const isRequiredCapabilities = isArrayEqual(currentPath, ["capabilities"]);
|
|
52
|
-
const isRequiredMeta = isArrayEqual(currentPath, ["meta"]);
|
|
53
|
-
const isRequiredSources = isArrayEqual(currentPath, ["sources"]);
|
|
54
|
-
const isExtensionNamespace = currentPath.length === 2 && currentPath[0] === "extensionPacks";
|
|
55
|
-
const isModelRelations = currentPath.length === 3 && isArrayEqual([currentPath[0], currentPath[2]], ["models", "relations"]);
|
|
56
|
-
const isTableUniques = currentPath.length === 4 && isArrayEqual(
|
|
57
|
-
[currentPath[0], currentPath[1], currentPath[3]],
|
|
58
|
-
["storage", "tables", "uniques"]
|
|
59
|
-
);
|
|
60
|
-
const isTableIndexes = currentPath.length === 4 && isArrayEqual(
|
|
61
|
-
[currentPath[0], currentPath[1], currentPath[3]],
|
|
62
|
-
["storage", "tables", "indexes"]
|
|
63
|
-
);
|
|
64
|
-
const isTableForeignKeys = currentPath.length === 4 && isArrayEqual(
|
|
65
|
-
[currentPath[0], currentPath[1], currentPath[3]],
|
|
66
|
-
["storage", "tables", "foreignKeys"]
|
|
67
|
-
);
|
|
68
|
-
if (!isRequiredModels && !isRequiredTables && !isRequiredRelations && !isRequiredExtensionPacks && !isRequiredCapabilities && !isRequiredMeta && !isRequiredSources && !isExtensionNamespace && !isModelRelations && !isTableUniques && !isTableIndexes && !isTableForeignKeys) {
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
result[key] = omitDefaults(value, currentPath);
|
|
73
|
-
}
|
|
74
|
-
return result;
|
|
75
|
-
}
|
|
76
|
-
function sortObjectKeys(obj) {
|
|
77
|
-
if (obj === null || typeof obj !== "object") {
|
|
78
|
-
return obj;
|
|
79
|
-
}
|
|
80
|
-
if (Array.isArray(obj)) {
|
|
81
|
-
return obj.map((item) => sortObjectKeys(item));
|
|
82
|
-
}
|
|
83
|
-
const sorted = {};
|
|
84
|
-
const keys = Object.keys(obj).sort();
|
|
85
|
-
for (const key of keys) {
|
|
86
|
-
sorted[key] = sortObjectKeys(obj[key]);
|
|
87
|
-
}
|
|
88
|
-
return sorted;
|
|
89
|
-
}
|
|
90
|
-
function sortIndexesAndUniques(storage) {
|
|
91
|
-
if (!storage || typeof storage !== "object") {
|
|
92
|
-
return storage;
|
|
93
|
-
}
|
|
94
|
-
const storageObj = storage;
|
|
95
|
-
if (!storageObj.tables || typeof storageObj.tables !== "object") {
|
|
96
|
-
return storage;
|
|
97
|
-
}
|
|
98
|
-
const tables = storageObj.tables;
|
|
99
|
-
const result = { ...storageObj };
|
|
100
|
-
result.tables = {};
|
|
101
|
-
const sortedTableNames = Object.keys(tables).sort();
|
|
102
|
-
for (const tableName of sortedTableNames) {
|
|
103
|
-
const table = tables[tableName];
|
|
104
|
-
if (!table || typeof table !== "object") {
|
|
105
|
-
result.tables[tableName] = table;
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
const tableObj = table;
|
|
109
|
-
const sortedTable = { ...tableObj };
|
|
110
|
-
if (Array.isArray(tableObj.indexes)) {
|
|
111
|
-
sortedTable.indexes = [...tableObj.indexes].sort((a, b) => {
|
|
112
|
-
const nameA = a?.name || "";
|
|
113
|
-
const nameB = b?.name || "";
|
|
114
|
-
return nameA.localeCompare(nameB);
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
if (Array.isArray(tableObj.uniques)) {
|
|
118
|
-
sortedTable.uniques = [...tableObj.uniques].sort((a, b) => {
|
|
119
|
-
const nameA = a?.name || "";
|
|
120
|
-
const nameB = b?.name || "";
|
|
121
|
-
return nameA.localeCompare(nameB);
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
result.tables[tableName] = sortedTable;
|
|
125
|
-
}
|
|
126
|
-
return result;
|
|
127
|
-
}
|
|
128
|
-
function orderTopLevel(obj) {
|
|
129
|
-
const ordered = {};
|
|
130
|
-
const remaining = new Set(Object.keys(obj));
|
|
131
|
-
for (const key of TOP_LEVEL_ORDER) {
|
|
132
|
-
if (remaining.has(key)) {
|
|
133
|
-
ordered[key] = obj[key];
|
|
134
|
-
remaining.delete(key);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
for (const key of Array.from(remaining).sort()) {
|
|
138
|
-
ordered[key] = obj[key];
|
|
139
|
-
}
|
|
140
|
-
return ordered;
|
|
141
|
-
}
|
|
142
|
-
function canonicalizeContract(ir) {
|
|
143
|
-
const normalized = {
|
|
144
|
-
schemaVersion: ir.schemaVersion,
|
|
145
|
-
targetFamily: ir.targetFamily,
|
|
146
|
-
target: ir.target,
|
|
147
|
-
models: ir.models,
|
|
148
|
-
relations: ir.relations,
|
|
149
|
-
storage: ir.storage,
|
|
150
|
-
extensionPacks: ir.extensionPacks,
|
|
151
|
-
capabilities: ir.capabilities,
|
|
152
|
-
meta: ir.meta,
|
|
153
|
-
sources: ir.sources
|
|
154
|
-
};
|
|
155
|
-
if (ir.coreHash !== void 0) {
|
|
156
|
-
normalized.coreHash = ir.coreHash;
|
|
157
|
-
}
|
|
158
|
-
if (ir.profileHash !== void 0) {
|
|
159
|
-
normalized.profileHash = ir.profileHash;
|
|
160
|
-
}
|
|
161
|
-
const withDefaultsOmitted = omitDefaults(normalized, []);
|
|
162
|
-
const withSortedIndexes = sortIndexesAndUniques(withDefaultsOmitted.storage);
|
|
163
|
-
const withSortedStorage = { ...withDefaultsOmitted, storage: withSortedIndexes };
|
|
164
|
-
const withSortedKeys = sortObjectKeys(withSortedStorage);
|
|
165
|
-
const withOrderedTopLevel = orderTopLevel(withSortedKeys);
|
|
166
|
-
return JSON.stringify(withOrderedTopLevel, null, 2);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// src/emission/emit.ts
|
|
170
|
-
import { format } from "prettier";
|
|
171
|
-
|
|
172
|
-
// src/emission/hashing.ts
|
|
173
|
-
import { createHash } from "crypto";
|
|
174
|
-
function computeHash(content) {
|
|
175
|
-
const hash = createHash("sha256");
|
|
176
|
-
hash.update(content);
|
|
177
|
-
return `sha256:${hash.digest("hex")}`;
|
|
178
|
-
}
|
|
179
|
-
function computeCoreHash(contract) {
|
|
180
|
-
const coreContract = {
|
|
181
|
-
schemaVersion: contract.schemaVersion,
|
|
182
|
-
targetFamily: contract.targetFamily,
|
|
183
|
-
target: contract.target,
|
|
184
|
-
models: contract.models,
|
|
185
|
-
relations: contract.relations,
|
|
186
|
-
storage: contract.storage,
|
|
187
|
-
extensionPacks: contract.extensionPacks,
|
|
188
|
-
sources: contract.sources,
|
|
189
|
-
capabilities: contract.capabilities,
|
|
190
|
-
meta: contract.meta
|
|
191
|
-
};
|
|
192
|
-
const canonical = canonicalizeContract(coreContract);
|
|
193
|
-
return computeHash(canonical);
|
|
194
|
-
}
|
|
195
|
-
function computeProfileHash(contract) {
|
|
196
|
-
const profileContract = {
|
|
197
|
-
schemaVersion: contract.schemaVersion,
|
|
198
|
-
targetFamily: contract.targetFamily,
|
|
199
|
-
target: contract.target,
|
|
200
|
-
models: {},
|
|
201
|
-
relations: {},
|
|
202
|
-
storage: {},
|
|
203
|
-
extensionPacks: {},
|
|
204
|
-
capabilities: contract.capabilities,
|
|
205
|
-
meta: {},
|
|
206
|
-
sources: {}
|
|
207
|
-
};
|
|
208
|
-
const canonical = canonicalizeContract(profileContract);
|
|
209
|
-
return computeHash(canonical);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// src/emission/emit.ts
|
|
213
|
-
function validateCoreStructure(ir) {
|
|
214
|
-
if (!ir.targetFamily) {
|
|
215
|
-
throw new Error("ContractIR must have targetFamily");
|
|
216
|
-
}
|
|
217
|
-
if (!ir.target) {
|
|
218
|
-
throw new Error("ContractIR must have target");
|
|
219
|
-
}
|
|
220
|
-
if (!ir.schemaVersion) {
|
|
221
|
-
throw new Error("ContractIR must have schemaVersion");
|
|
222
|
-
}
|
|
223
|
-
if (!ir.models || typeof ir.models !== "object") {
|
|
224
|
-
throw new Error("ContractIR must have models");
|
|
225
|
-
}
|
|
226
|
-
if (!ir.storage || typeof ir.storage !== "object") {
|
|
227
|
-
throw new Error("ContractIR must have storage");
|
|
228
|
-
}
|
|
229
|
-
if (!ir.relations || typeof ir.relations !== "object") {
|
|
230
|
-
throw new Error("ContractIR must have relations");
|
|
231
|
-
}
|
|
232
|
-
if (!ir.extensionPacks || typeof ir.extensionPacks !== "object") {
|
|
233
|
-
throw new Error("ContractIR must have extensionPacks");
|
|
234
|
-
}
|
|
235
|
-
if (!ir.capabilities || typeof ir.capabilities !== "object") {
|
|
236
|
-
throw new Error("ContractIR must have capabilities");
|
|
237
|
-
}
|
|
238
|
-
if (!ir.meta || typeof ir.meta !== "object") {
|
|
239
|
-
throw new Error("ContractIR must have meta");
|
|
240
|
-
}
|
|
241
|
-
if (!ir.sources || typeof ir.sources !== "object") {
|
|
242
|
-
throw new Error("ContractIR must have sources");
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
async function emit(ir, options, targetFamily) {
|
|
246
|
-
const { operationRegistry, codecTypeImports, operationTypeImports, extensionIds } = options;
|
|
247
|
-
validateCoreStructure(ir);
|
|
248
|
-
const ctx = {
|
|
249
|
-
...operationRegistry ? { operationRegistry } : {},
|
|
250
|
-
...codecTypeImports ? { codecTypeImports } : {},
|
|
251
|
-
...operationTypeImports ? { operationTypeImports } : {},
|
|
252
|
-
...extensionIds ? { extensionIds } : {}
|
|
253
|
-
};
|
|
254
|
-
targetFamily.validateTypes(ir, ctx);
|
|
255
|
-
targetFamily.validateStructure(ir);
|
|
256
|
-
const contractJson = {
|
|
257
|
-
schemaVersion: ir.schemaVersion,
|
|
258
|
-
targetFamily: ir.targetFamily,
|
|
259
|
-
target: ir.target,
|
|
260
|
-
models: ir.models,
|
|
261
|
-
relations: ir.relations,
|
|
262
|
-
storage: ir.storage,
|
|
263
|
-
extensionPacks: ir.extensionPacks,
|
|
264
|
-
capabilities: ir.capabilities,
|
|
265
|
-
meta: ir.meta,
|
|
266
|
-
sources: ir.sources
|
|
267
|
-
};
|
|
268
|
-
const coreHash = computeCoreHash(contractJson);
|
|
269
|
-
const profileHash = computeProfileHash(contractJson);
|
|
270
|
-
const contractWithHashes = {
|
|
271
|
-
...ir,
|
|
272
|
-
schemaVersion: contractJson.schemaVersion,
|
|
273
|
-
coreHash,
|
|
274
|
-
profileHash
|
|
275
|
-
};
|
|
276
|
-
const contractJsonObj = JSON.parse(canonicalizeContract(contractWithHashes));
|
|
277
|
-
const contractJsonWithMeta = {
|
|
278
|
-
...contractJsonObj,
|
|
279
|
-
_generated: {
|
|
280
|
-
warning: "\u26A0\uFE0F GENERATED FILE - DO NOT EDIT",
|
|
281
|
-
message: 'This file is automatically generated by "prisma-next contract emit".',
|
|
282
|
-
regenerate: "To regenerate, run: prisma-next contract emit"
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
const contractJsonString = JSON.stringify(contractJsonWithMeta, null, 2);
|
|
286
|
-
const contractDtsRaw = targetFamily.generateContractTypes(
|
|
287
|
-
ir,
|
|
288
|
-
codecTypeImports ?? [],
|
|
289
|
-
operationTypeImports ?? []
|
|
290
|
-
);
|
|
291
|
-
const contractDts = await format(contractDtsRaw, {
|
|
292
|
-
parser: "typescript",
|
|
293
|
-
singleQuote: true,
|
|
294
|
-
semi: true,
|
|
295
|
-
printWidth: 100
|
|
296
|
-
});
|
|
297
|
-
return {
|
|
298
|
-
contractJson: contractJsonString,
|
|
299
|
-
contractDts,
|
|
300
|
-
coreHash,
|
|
301
|
-
profileHash
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
export {
|
|
305
|
-
canonicalizeContract,
|
|
306
|
-
computeCoreHash,
|
|
307
|
-
computeProfileHash,
|
|
308
|
-
emit
|
|
309
|
-
};
|
|
310
|
-
//# sourceMappingURL=emission.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/emission/canonicalization.ts","../../src/emission/emit.ts","../../src/emission/hashing.ts"],"sourcesContent":["import type { ContractIR } from '@prisma-next/contract/ir';\nimport { isArrayEqual } from '@prisma-next/utils/array-equal';\n\ntype NormalizedContract = {\n schemaVersion: string;\n targetFamily: string;\n target: string;\n coreHash?: string;\n profileHash?: string;\n models: Record<string, unknown>;\n relations: Record<string, unknown>;\n storage: Record<string, unknown>;\n extensionPacks: Record<string, unknown>;\n capabilities: Record<string, Record<string, boolean>>;\n meta: Record<string, unknown>;\n sources: Record<string, unknown>;\n};\n\nconst TOP_LEVEL_ORDER = [\n 'schemaVersion',\n 'canonicalVersion',\n 'targetFamily',\n 'target',\n 'coreHash',\n 'profileHash',\n 'models',\n 'storage',\n 'capabilities',\n 'extensionPacks',\n 'meta',\n 'sources',\n] as const;\n\nfunction isDefaultValue(value: unknown): boolean {\n if (value === false) return true;\n if (value === null) 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 (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 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 isRequiredSources = isArrayEqual(currentPath, ['sources']);\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 if (\n !isRequiredModels &&\n !isRequiredTables &&\n !isRequiredRelations &&\n !isRequiredExtensionPacks &&\n !isRequiredCapabilities &&\n !isRequiredMeta &&\n !isRequiredSources &&\n !isExtensionNamespace &&\n !isModelRelations &&\n !isTableUniques &&\n !isTableIndexes &&\n !isTableForeignKeys\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 (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(\n ir: ContractIR & { coreHash?: string; profileHash?: string },\n): 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 extensionPacks: ir.extensionPacks,\n capabilities: ir.capabilities,\n meta: ir.meta,\n sources: ir.sources,\n };\n\n if (ir.coreHash !== undefined) {\n normalized.coreHash = ir.coreHash;\n }\n\n if (ir.profileHash !== undefined) {\n normalized.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, null, 2);\n}\n","import type { ContractIR } from '@prisma-next/contract/ir';\nimport type { TargetFamilyHook, ValidationContext } from '@prisma-next/contract/types';\nimport { format } from 'prettier';\nimport { canonicalizeContract } from './canonicalization';\nimport { computeCoreHash, computeProfileHash } from './hashing';\nimport type { EmitOptions, EmitResult } from './types';\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 if (!ir.sources || typeof ir.sources !== 'object') {\n throw new Error('ContractIR must have sources');\n }\n}\n\nexport async function emit(\n ir: ContractIR,\n options: EmitOptions,\n targetFamily: TargetFamilyHook,\n): Promise<EmitResult> {\n const { operationRegistry, codecTypeImports, operationTypeImports, extensionIds } = options;\n\n validateCoreStructure(ir);\n\n const ctx: ValidationContext = {\n ...(operationRegistry ? { operationRegistry } : {}),\n ...(codecTypeImports ? { codecTypeImports } : {}),\n ...(operationTypeImports ? { operationTypeImports } : {}),\n ...(extensionIds ? { extensionIds } : {}),\n };\n targetFamily.validateTypes(ir, ctx);\n\n targetFamily.validateStructure(ir);\n\n const contractJson = {\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 extensionPacks: ir.extensionPacks,\n capabilities: ir.capabilities,\n meta: ir.meta,\n sources: ir.sources,\n } as const;\n\n const coreHash = computeCoreHash(contractJson);\n const profileHash = computeProfileHash(contractJson);\n\n const contractWithHashes: ContractIR & { coreHash?: string; profileHash?: string } = {\n ...ir,\n schemaVersion: contractJson.schemaVersion,\n coreHash,\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 contractDtsRaw = targetFamily.generateContractTypes(\n ir,\n codecTypeImports ?? [],\n operationTypeImports ?? [],\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 coreHash,\n profileHash,\n };\n}\n","import { createHash } from 'node:crypto';\nimport type { ContractIR } from '@prisma-next/contract/ir';\nimport { canonicalizeContract } from './canonicalization';\n\ntype ContractInput = {\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 extensionPacks: Record<string, unknown>;\n sources: Record<string, unknown>;\n capabilities: Record<string, Record<string, boolean>>;\n meta: Record<string, unknown>;\n [key: string]: unknown;\n};\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 computeCoreHash(contract: ContractInput): string {\n const coreContract: ContractIR = {\n schemaVersion: contract.schemaVersion,\n targetFamily: contract.targetFamily,\n target: contract.target,\n models: contract.models,\n relations: contract.relations,\n storage: contract.storage,\n extensionPacks: contract.extensionPacks,\n sources: contract.sources,\n capabilities: contract.capabilities,\n meta: contract.meta,\n };\n const canonical = canonicalizeContract(coreContract);\n return computeHash(canonical);\n}\n\nexport function computeProfileHash(contract: ContractInput): string {\n const profileContract: ContractIR = {\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 sources: {},\n };\n const canonical = canonicalizeContract(profileContract);\n return computeHash(canonical);\n}\n"],"mappings":";AACA,SAAS,oBAAoB;AAiB7B,IAAM,kBAAkB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,SAAS,eAAe,OAAyB;AAC/C,MAAI,UAAU,MAAO,QAAO;AAC5B,MAAI,UAAU,KAAM,QAAO;AAC3B,MAAI,MAAM,QAAQ,KAAK,KAAK,MAAM,WAAW,EAAG,QAAO;AACvD,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,UAAM,OAAO,OAAO,KAAK,KAAK;AAC9B,WAAO,KAAK,WAAW;AAAA,EACzB;AACA,SAAO;AACT;AAEA,SAAS,aAAa,KAAc,MAAkC;AACpE,MAAI,QAAQ,QAAQ,OAAO,QAAQ,UAAU;AAC3C,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,WAAO,IAAI,IAAI,CAAC,SAAS,aAAa,MAAM,IAAI,CAAC;AAAA,EACnD;AAEA,QAAM,SAAkC,CAAC;AAEzC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,UAAM,cAAc,CAAC,GAAG,MAAM,GAAG;AAGjC,QAAI,QAAQ,cAAc;AACxB;AAAA,IACF;AAEA,QAAI,QAAQ,cA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AG;AAElC,eAAa,kBAAkB,EAAE;AAEjC,QAAM,eAAe;AAAA,IACnB,eAAe,GAAG;AAAA,IAClB,cAAc,GAAG;AAAA,IACjB,QAAQ,GAAG;AAAA,IACX,QAAQ,GAAG;AAAA,IACX,WAAW,GAAG;AAAA,IACd,SAAS,GAAG;AAAA,IACZ,gBAAgB,GAAG;AAAA,IACnB,cAAc,GAAG;AAAA,IACjB,MAAM,GAAG;AAAA,IACT,SAAS,GAAG;AAAA,EACd;AAEA,QAAM,WAAW,gBAAgB,YAAY;AAC7C,QAAM,cAAc,mBAAmB,YAAY;AAEnD,QAAM,qBAA+E;AAAA,IACnF,GAAG;AAAA,IACH,eAAe,aAAa;AAAA,IAC5B;AAAA,IACA;AAAA,EACF;AAKA,QAAM,kBAAkB,KAAK,MAAM,qBAAqB,kBAAkB,CAAC;AAI3E,QAAM,uBAAuB;AAAA,IAC3B,GAAG;AAAA,IACH,YAAY;AAAA,MACV,SAAS;AAAA,MACT,SAAS;AAAA,MACT,YAAY;AAAA,IACd;AAAA,EACF;AACA,QAAM,qBAAqB,KAAK,UAAU,sBAAsB,MAAM,CAAC;AAEvE,QAAM,iBAAiB,aAAa;AAAA,IAClC;AAAA,IACA,oBAAoB,CAAC;AAAA,IACrB,wBAAwB,CAAC;AAAA,EAC3B;AACA,QAAM,cAAc,MAAM,OAAO,gBAAgB;AAAA,IAC/C,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,MAAM;AAAA,IACN,YAAY;AAAA,EACd,CAAC;AAED,SAAO;AAAA,IACL,cAAc;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
package/dist/exports/errors.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export type { CliErrorConflict, CliErrorEnvelope } from '../errors';
|
|
2
|
-
export { CliStructuredError, errorConfigFileNotFound, errorConfigValidation, errorContractConfigMissing, errorContractMissingExtensionPacks, errorContractValidationFailed, errorDatabaseConnectionRequired, errorDriverRequired, errorFamilyReadMarkerSqlRequired, errorFileNotFound, errorHashMismatch, errorJsonFormatNotSupported, errorMarkerMissing, errorMigrationPlanningFailed, errorQueryRunnerFactoryRequired, errorRuntime, errorTargetMigrationNotSupported, errorTargetMismatch, errorUnexpected, } from '../errors';
|
|
3
|
-
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/exports/errors.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,EACrB,0BAA0B,EAC1B,kCAAkC,EAClC,6BAA6B,EAC7B,+BAA+B,EAC/B,mBAAmB,EACnB,gCAAgC,EAChC,iBAAiB,EACjB,iBAAiB,EACjB,2BAA2B,EAC3B,kBAAkB,EAClB,4BAA4B,EAC5B,+BAA+B,EAC/B,YAAY,EACZ,gCAAgC,EAChC,mBAAmB,EACnB,eAAe,GAChB,MAAM,WAAW,CAAC"}
|
package/dist/exports/errors.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CliStructuredError,
|
|
3
|
-
errorConfigFileNotFound,
|
|
4
|
-
errorConfigValidation,
|
|
5
|
-
errorContractConfigMissing,
|
|
6
|
-
errorContractMissingExtensionPacks,
|
|
7
|
-
errorContractValidationFailed,
|
|
8
|
-
errorDatabaseConnectionRequired,
|
|
9
|
-
errorDriverRequired,
|
|
10
|
-
errorFamilyReadMarkerSqlRequired,
|
|
11
|
-
errorFileNotFound,
|
|
12
|
-
errorHashMismatch,
|
|
13
|
-
errorJsonFormatNotSupported,
|
|
14
|
-
errorMarkerMissing,
|
|
15
|
-
errorMigrationPlanningFailed,
|
|
16
|
-
errorQueryRunnerFactoryRequired,
|
|
17
|
-
errorRuntime,
|
|
18
|
-
errorTargetMigrationNotSupported,
|
|
19
|
-
errorTargetMismatch,
|
|
20
|
-
errorUnexpected
|
|
21
|
-
} from "../chunk-YT6YGR3N.js";
|
|
22
|
-
export {
|
|
23
|
-
CliStructuredError,
|
|
24
|
-
errorConfigFileNotFound,
|
|
25
|
-
errorConfigValidation,
|
|
26
|
-
errorContractConfigMissing,
|
|
27
|
-
errorContractMissingExtensionPacks,
|
|
28
|
-
errorContractValidationFailed,
|
|
29
|
-
errorDatabaseConnectionRequired,
|
|
30
|
-
errorDriverRequired,
|
|
31
|
-
errorFamilyReadMarkerSqlRequired,
|
|
32
|
-
errorFileNotFound,
|
|
33
|
-
errorHashMismatch,
|
|
34
|
-
errorJsonFormatNotSupported,
|
|
35
|
-
errorMarkerMissing,
|
|
36
|
-
errorMigrationPlanningFailed,
|
|
37
|
-
errorQueryRunnerFactoryRequired,
|
|
38
|
-
errorRuntime,
|
|
39
|
-
errorTargetMigrationNotSupported,
|
|
40
|
-
errorTargetMismatch,
|
|
41
|
-
errorUnexpected
|
|
42
|
-
};
|
|
43
|
-
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema-view.d.ts","sourceRoot":"","sources":["../../src/exports/schema-view.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=schema-view.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/exports/stack.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stack.d.ts","sourceRoot":"","sources":["../../src/exports/stack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/exports/stack.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// src/stack.ts
|
|
2
|
-
function createControlPlaneStack(input) {
|
|
3
|
-
return {
|
|
4
|
-
target: input.target,
|
|
5
|
-
adapter: input.adapter,
|
|
6
|
-
driver: input.driver,
|
|
7
|
-
extensionPacks: input.extensionPacks ?? []
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
export {
|
|
11
|
-
createControlPlaneStack
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=stack.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/stack.ts"],"sourcesContent":["import type {\n ControlAdapterDescriptor,\n ControlDriverDescriptor,\n ControlExtensionDescriptor,\n ControlPlaneStack,\n ControlTargetDescriptor,\n} from './types';\n\n/**\n * Creates a ControlPlaneStack from component descriptors.\n *\n * Provides sensible defaults:\n * - `driver` defaults to `undefined` (optional for commands that don't need DB connection)\n * - `extensionPacks` defaults to `[]` (empty array)\n *\n * @example\n * ```ts\n * const stack = createControlPlaneStack({\n * target: postgresTarget,\n * adapter: postgresAdapter,\n * driver: postgresDriver, // optional\n * extensionPacks: [pgvector], // optional\n * });\n * ```\n */\nexport function createControlPlaneStack<TFamilyId extends string, TTargetId extends string>(input: {\n readonly target: ControlTargetDescriptor<TFamilyId, TTargetId>;\n readonly adapter: ControlAdapterDescriptor<TFamilyId, TTargetId>;\n readonly driver?: ControlDriverDescriptor<TFamilyId, TTargetId> | undefined;\n readonly extensionPacks?: readonly ControlExtensionDescriptor<TFamilyId, TTargetId>[] | undefined;\n}): ControlPlaneStack<TFamilyId, TTargetId> {\n return {\n target: input.target,\n adapter: input.adapter,\n driver: input.driver,\n extensionPacks: input.extensionPacks ?? [],\n };\n}\n"],"mappings":";AAyBO,SAAS,wBAA4E,OAKhD;AAC1C,SAAO;AAAA,IACL,QAAQ,MAAM;AAAA,IACd,SAAS,MAAM;AAAA,IACf,QAAQ,MAAM;AAAA,IACd,gBAAgB,MAAM,kBAAkB,CAAC;AAAA,EAC3C;AACF;","names":[]}
|
package/dist/exports/types.d.ts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export type { ControlAdapterDescriptor, ControlAdapterInstance, ControlDriverDescriptor, ControlDriverInstance, ControlExtensionDescriptor, ControlExtensionInstance, ControlFamilyDescriptor, ControlFamilyInstance, ControlPlaneStack, ControlTargetDescriptor, ControlTargetInstance, EmitContractResult, IntrospectSchemaResult, MigrationOperationClass, MigrationOperationPolicy, MigrationPlan, MigrationPlanner, MigrationPlannerConflict, MigrationPlannerFailureResult, MigrationPlannerResult, MigrationPlannerSuccessResult, MigrationPlanOperation, MigrationRunner, MigrationRunnerExecutionChecks, MigrationRunnerFailure, MigrationRunnerResult, MigrationRunnerSuccessValue, OperationContext, SchemaIssue, SchemaVerificationNode, SignDatabaseResult, TargetMigrationsCapability, VerifyDatabaseResult, VerifyDatabaseSchemaResult, } from '../types';
|
|
2
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/exports/types.ts"],"names":[],"mappings":"AAAA,YAAY,EAEV,wBAAwB,EACxB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,0BAA0B,EAC1B,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,EACrB,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EAEtB,uBAAuB,EACvB,wBAAwB,EACxB,aAAa,EACb,gBAAgB,EAChB,wBAAwB,EACxB,6BAA6B,EAC7B,sBAAsB,EACtB,6BAA6B,EAC7B,sBAAsB,EACtB,eAAe,EACf,8BAA8B,EAC9B,sBAAsB,EACtB,qBAAqB,EACrB,2BAA2B,EAC3B,gBAAgB,EAChB,WAAW,EACX,sBAAsB,EACtB,kBAAkB,EAClB,0BAA0B,EAC1B,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,UAAU,CAAC"}
|
package/dist/exports/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/migrations.d.ts
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core migration types for the framework control plane.
|
|
3
|
-
*
|
|
4
|
-
* These are family-agnostic, display-oriented types that provide a stable
|
|
5
|
-
* vocabulary for CLI commands to work with migration planners and runners
|
|
6
|
-
* without importing family-specific types.
|
|
7
|
-
*
|
|
8
|
-
* Family-specific types (e.g., SqlMigrationPlan) extend these base types
|
|
9
|
-
* with additional fields for execution (precheck SQL, execute SQL, etc.).
|
|
10
|
-
*/
|
|
11
|
-
import type { TargetBoundComponentDescriptor } from '@prisma-next/contract/framework-components';
|
|
12
|
-
import type { Result } from '@prisma-next/utils/result';
|
|
13
|
-
import type { ControlDriverInstance, ControlFamilyInstance } from './types';
|
|
14
|
-
/**
|
|
15
|
-
* Migration operation classes define the safety level of an operation.
|
|
16
|
-
* - 'additive': Adds new structures without modifying existing ones (safe)
|
|
17
|
-
* - 'widening': Relaxes constraints or expands types (generally safe)
|
|
18
|
-
* - 'destructive': Removes or alters existing structures (potentially unsafe)
|
|
19
|
-
*/
|
|
20
|
-
export type MigrationOperationClass = 'additive' | 'widening' | 'destructive';
|
|
21
|
-
/**
|
|
22
|
-
* Policy defining which operation classes are allowed during a migration.
|
|
23
|
-
*/
|
|
24
|
-
export interface MigrationOperationPolicy {
|
|
25
|
-
readonly allowedOperationClasses: readonly MigrationOperationClass[];
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* A single migration operation for display purposes.
|
|
29
|
-
* Contains only the fields needed for CLI output (tree view, JSON envelope).
|
|
30
|
-
*/
|
|
31
|
-
export interface MigrationPlanOperation {
|
|
32
|
-
/** Unique identifier for this operation (e.g., "table.users.create"). */
|
|
33
|
-
readonly id: string;
|
|
34
|
-
/** Human-readable label for display in UI/CLI (e.g., "Create table users"). */
|
|
35
|
-
readonly label: string;
|
|
36
|
-
/** The class of operation (additive, widening, destructive). */
|
|
37
|
-
readonly operationClass: MigrationOperationClass;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* A migration plan for display purposes.
|
|
41
|
-
* Contains only the fields needed for CLI output (summary, JSON envelope).
|
|
42
|
-
*/
|
|
43
|
-
export interface MigrationPlan {
|
|
44
|
-
/** The target ID this plan is for (e.g., 'postgres'). */
|
|
45
|
-
readonly targetId: string;
|
|
46
|
-
/** Destination contract identity that the plan intends to reach. */
|
|
47
|
-
readonly destination: {
|
|
48
|
-
readonly coreHash: string;
|
|
49
|
-
readonly profileHash?: string;
|
|
50
|
-
};
|
|
51
|
-
/** Ordered list of operations to execute. */
|
|
52
|
-
readonly operations: readonly MigrationPlanOperation[];
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* A conflict detected during migration planning.
|
|
56
|
-
*/
|
|
57
|
-
export interface MigrationPlannerConflict {
|
|
58
|
-
/** Kind of conflict (e.g., 'typeMismatch', 'nullabilityConflict'). */
|
|
59
|
-
readonly kind: string;
|
|
60
|
-
/** Human-readable summary of the conflict. */
|
|
61
|
-
readonly summary: string;
|
|
62
|
-
/** Optional explanation of why this conflict occurred. */
|
|
63
|
-
readonly why?: string;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Successful planner result with the migration plan.
|
|
67
|
-
*/
|
|
68
|
-
export interface MigrationPlannerSuccessResult {
|
|
69
|
-
readonly kind: 'success';
|
|
70
|
-
readonly plan: MigrationPlan;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Failed planner result with the list of conflicts.
|
|
74
|
-
*/
|
|
75
|
-
export interface MigrationPlannerFailureResult {
|
|
76
|
-
readonly kind: 'failure';
|
|
77
|
-
readonly conflicts: readonly MigrationPlannerConflict[];
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Union type for planner results.
|
|
81
|
-
*/
|
|
82
|
-
export type MigrationPlannerResult = MigrationPlannerSuccessResult | MigrationPlannerFailureResult;
|
|
83
|
-
/**
|
|
84
|
-
* Success value for migration runner execution.
|
|
85
|
-
*/
|
|
86
|
-
export interface MigrationRunnerSuccessValue {
|
|
87
|
-
readonly operationsPlanned: number;
|
|
88
|
-
readonly operationsExecuted: number;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Failure details for migration runner execution.
|
|
92
|
-
*/
|
|
93
|
-
export interface MigrationRunnerFailure {
|
|
94
|
-
/** Error code for the failure. */
|
|
95
|
-
readonly code: string;
|
|
96
|
-
/** Human-readable summary of the failure. */
|
|
97
|
-
readonly summary: string;
|
|
98
|
-
/** Optional explanation of why the failure occurred. */
|
|
99
|
-
readonly why?: string;
|
|
100
|
-
/** Optional metadata for debugging and UX (e.g., schema issues, SQL state). */
|
|
101
|
-
readonly meta?: Record<string, unknown>;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Result type for migration runner execution.
|
|
105
|
-
*/
|
|
106
|
-
export type MigrationRunnerResult = Result<MigrationRunnerSuccessValue, MigrationRunnerFailure>;
|
|
107
|
-
/**
|
|
108
|
-
* Execution-time checks configuration for migration runners.
|
|
109
|
-
* All checks default to `true` (enabled) when omitted.
|
|
110
|
-
*/
|
|
111
|
-
export interface MigrationRunnerExecutionChecks {
|
|
112
|
-
/**
|
|
113
|
-
* Whether to run prechecks before executing operations.
|
|
114
|
-
* Defaults to `true` (prechecks are run).
|
|
115
|
-
*/
|
|
116
|
-
readonly prechecks?: boolean;
|
|
117
|
-
/**
|
|
118
|
-
* Whether to run postchecks after executing operations.
|
|
119
|
-
* Defaults to `true` (postchecks are run).
|
|
120
|
-
*/
|
|
121
|
-
readonly postchecks?: boolean;
|
|
122
|
-
/**
|
|
123
|
-
* Whether to run idempotency probe (check if postcheck is already satisfied before execution).
|
|
124
|
-
* Defaults to `true` (idempotency probe is run).
|
|
125
|
-
*/
|
|
126
|
-
readonly idempotencyChecks?: boolean;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Migration planner interface for planning schema changes.
|
|
130
|
-
* This is the minimal interface that CLI commands use.
|
|
131
|
-
*
|
|
132
|
-
* @template TFamilyId - The family ID (e.g., 'sql', 'document')
|
|
133
|
-
* @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
|
|
134
|
-
*/
|
|
135
|
-
export interface MigrationPlanner<TFamilyId extends string = string, TTargetId extends string = string> {
|
|
136
|
-
plan(options: {
|
|
137
|
-
readonly contract: unknown;
|
|
138
|
-
readonly schema: unknown;
|
|
139
|
-
readonly policy: MigrationOperationPolicy;
|
|
140
|
-
/**
|
|
141
|
-
* Active framework components participating in this composition.
|
|
142
|
-
* Families/targets can interpret this list to derive family-specific metadata.
|
|
143
|
-
* All components must have matching familyId and targetId.
|
|
144
|
-
*/
|
|
145
|
-
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, TTargetId>>;
|
|
146
|
-
}): MigrationPlannerResult;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Migration runner interface for executing migration plans.
|
|
150
|
-
* This is the minimal interface that CLI commands use.
|
|
151
|
-
*
|
|
152
|
-
* @template TFamilyId - The family ID (e.g., 'sql', 'document')
|
|
153
|
-
* @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
|
|
154
|
-
*/
|
|
155
|
-
export interface MigrationRunner<TFamilyId extends string = string, TTargetId extends string = string> {
|
|
156
|
-
execute(options: {
|
|
157
|
-
readonly plan: MigrationPlan;
|
|
158
|
-
readonly driver: ControlDriverInstance<TFamilyId, TTargetId>;
|
|
159
|
-
readonly destinationContract: unknown;
|
|
160
|
-
readonly policy: MigrationOperationPolicy;
|
|
161
|
-
readonly callbacks?: {
|
|
162
|
-
onOperationStart?(op: MigrationPlanOperation): void;
|
|
163
|
-
onOperationComplete?(op: MigrationPlanOperation): void;
|
|
164
|
-
};
|
|
165
|
-
/**
|
|
166
|
-
* Execution-time checks configuration.
|
|
167
|
-
* All checks default to `true` (enabled) when omitted.
|
|
168
|
-
*/
|
|
169
|
-
readonly executionChecks?: MigrationRunnerExecutionChecks;
|
|
170
|
-
/**
|
|
171
|
-
* Active framework components participating in this composition.
|
|
172
|
-
* Families/targets can interpret this list to derive family-specific metadata.
|
|
173
|
-
* All components must have matching familyId and targetId.
|
|
174
|
-
*/
|
|
175
|
-
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, TTargetId>>;
|
|
176
|
-
}): Promise<MigrationRunnerResult>;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Optional capability interface for targets that support migrations.
|
|
180
|
-
* Targets that implement migrations expose this via their descriptor.
|
|
181
|
-
*
|
|
182
|
-
* @template TFamilyId - The family ID (e.g., 'sql', 'document')
|
|
183
|
-
* @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
|
|
184
|
-
* @template TFamilyInstance - The family instance type (e.g., SqlControlFamilyInstance)
|
|
185
|
-
*/
|
|
186
|
-
export interface TargetMigrationsCapability<TFamilyId extends string = string, TTargetId extends string = string, TFamilyInstance extends ControlFamilyInstance<TFamilyId> = ControlFamilyInstance<TFamilyId>> {
|
|
187
|
-
createPlanner(family: TFamilyInstance): MigrationPlanner<TFamilyId, TTargetId>;
|
|
188
|
-
createRunner(family: TFamilyInstance): MigrationRunner<TFamilyId, TTargetId>;
|
|
189
|
-
}
|
|
190
|
-
//# sourceMappingURL=migrations.d.ts.map
|