@prisma-next/family-sql 0.3.0-pr.94.2 → 0.3.0-pr.95.2
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/chunk-H7CGY6OH.js +611 -0
- package/dist/chunk-H7CGY6OH.js.map +1 -0
- package/dist/chunk-SU7LN2UH.js +96 -0
- package/dist/chunk-SU7LN2UH.js.map +1 -0
- package/dist/chunk-XH2Y5NTD.js +715 -0
- package/dist/chunk-XH2Y5NTD.js.map +1 -0
- package/dist/core/assembly.d.ts +36 -0
- package/dist/core/assembly.d.ts.map +1 -0
- package/dist/core/control-adapter.d.ts +42 -0
- package/dist/core/control-adapter.d.ts.map +1 -0
- package/dist/core/descriptor.d.ts +25 -0
- package/dist/core/descriptor.d.ts.map +1 -0
- package/dist/core/instance.d.ts +140 -0
- package/dist/core/instance.d.ts.map +1 -0
- package/dist/core/migrations/plan-helpers.d.ts +20 -0
- package/dist/core/migrations/plan-helpers.d.ts.map +1 -0
- package/dist/core/migrations/policies.d.ts +6 -0
- package/dist/core/migrations/policies.d.ts.map +1 -0
- package/dist/core/migrations/types.d.ts +280 -0
- package/dist/core/migrations/types.d.ts.map +1 -0
- package/dist/core/runtime-descriptor.d.ts +19 -0
- package/dist/core/runtime-descriptor.d.ts.map +1 -0
- package/dist/core/runtime-instance.d.ts +54 -0
- package/dist/core/runtime-instance.d.ts.map +1 -0
- package/dist/core/schema-verify/verify-helpers.d.ts +96 -0
- package/dist/core/schema-verify/verify-helpers.d.ts.map +1 -0
- package/dist/core/schema-verify/verify-sql-schema.d.ts +45 -0
- package/dist/core/schema-verify/verify-sql-schema.d.ts.map +1 -0
- package/dist/core/verify.d.ts +39 -0
- package/dist/core/verify.d.ts.map +1 -0
- package/dist/exports/control-adapter.d.ts +2 -0
- package/dist/exports/control-adapter.d.ts.map +1 -0
- package/dist/exports/control-adapter.js +1 -0
- package/dist/exports/control-adapter.js.map +1 -0
- package/dist/exports/control.d.ts +13 -0
- package/dist/exports/control.d.ts.map +1 -0
- package/dist/exports/control.js +149 -0
- package/dist/exports/control.js.map +1 -0
- package/dist/exports/runtime.d.ts +8 -0
- package/dist/exports/runtime.d.ts.map +1 -0
- package/dist/exports/runtime.js +64 -0
- package/dist/exports/runtime.js.map +1 -0
- package/dist/exports/schema-verify.d.ts +11 -0
- package/dist/exports/schema-verify.d.ts.map +1 -0
- package/dist/exports/schema-verify.js +15 -0
- package/dist/exports/schema-verify.js.map +1 -0
- package/dist/exports/test-utils.d.ts +7 -0
- package/dist/exports/test-utils.d.ts.map +1 -0
- package/dist/exports/test-utils.js +17 -0
- package/dist/exports/test-utils.js.map +1 -0
- package/dist/exports/verify.d.ts +2 -0
- package/dist/exports/verify.d.ts.map +1 -0
- package/dist/exports/verify.js +11 -0
- package/dist/exports/verify.js.map +1 -0
- package/package.json +44 -31
- package/src/core/assembly.ts +48 -0
- package/src/core/instance.ts +4 -1
- package/dist/control-adapter.d.mts +0 -47
- package/dist/control-adapter.d.mts.map +0 -1
- package/dist/control-adapter.mjs +0 -1
- package/dist/control.d.mts +0 -65
- package/dist/control.d.mts.map +0 -1
- package/dist/control.mjs +0 -136
- package/dist/control.mjs.map +0 -1
- package/dist/instance-B_PdDN4y.mjs +0 -525
- package/dist/instance-B_PdDN4y.mjs.map +0 -1
- package/dist/instance-wm4TrZN0.d.mts +0 -130
- package/dist/instance-wm4TrZN0.d.mts.map +0 -1
- package/dist/runtime.d.mts +0 -70
- package/dist/runtime.d.mts.map +0 -1
- package/dist/runtime.mjs +0 -74
- package/dist/runtime.mjs.map +0 -1
- package/dist/schema-verify.d.mts +0 -85
- package/dist/schema-verify.d.mts.map +0 -1
- package/dist/schema-verify.mjs +0 -3
- package/dist/test-utils.d.mts +0 -31
- package/dist/test-utils.d.mts.map +0 -1
- package/dist/test-utils.mjs +0 -5
- package/dist/types-D5CPT9N4.d.mts +0 -270
- package/dist/types-D5CPT9N4.d.mts.map +0 -1
- package/dist/verify-DhFytkFC.mjs +0 -108
- package/dist/verify-DhFytkFC.mjs.map +0 -1
- package/dist/verify-sql-schema-BnLVoeWI.mjs +0 -686
- package/dist/verify-sql-schema-BnLVoeWI.mjs.map +0 -1
- package/dist/verify.d.mts +0 -31
- package/dist/verify.d.mts.map +0 -1
- package/dist/verify.mjs +0 -3
|
@@ -0,0 +1,611 @@
|
|
|
1
|
+
import {
|
|
2
|
+
collectSupportedCodecTypeIds,
|
|
3
|
+
readMarker
|
|
4
|
+
} from "./chunk-SU7LN2UH.js";
|
|
5
|
+
import {
|
|
6
|
+
verifySqlSchema
|
|
7
|
+
} from "./chunk-XH2Y5NTD.js";
|
|
8
|
+
|
|
9
|
+
// src/core/assembly.ts
|
|
10
|
+
import { normalizeRenderer } from "@prisma-next/contract/framework-components";
|
|
11
|
+
import { createOperationRegistry } from "@prisma-next/operations";
|
|
12
|
+
function assembleOperationRegistry(descriptors, convertOperationManifest2) {
|
|
13
|
+
const registry = createOperationRegistry();
|
|
14
|
+
for (const descriptor of descriptors) {
|
|
15
|
+
const operations = descriptor.operations ?? [];
|
|
16
|
+
for (const operationManifest of operations) {
|
|
17
|
+
const signature = convertOperationManifest2(operationManifest);
|
|
18
|
+
registry.register(signature);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return registry;
|
|
22
|
+
}
|
|
23
|
+
function extractCodecTypeImports(descriptors) {
|
|
24
|
+
const imports = [];
|
|
25
|
+
for (const descriptor of descriptors) {
|
|
26
|
+
const types = descriptor.types;
|
|
27
|
+
const codecTypes = types?.codecTypes;
|
|
28
|
+
if (codecTypes?.import) {
|
|
29
|
+
imports.push(codecTypes.import);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return imports;
|
|
33
|
+
}
|
|
34
|
+
function extractOperationTypeImports(descriptors) {
|
|
35
|
+
const imports = [];
|
|
36
|
+
for (const descriptor of descriptors) {
|
|
37
|
+
const types = descriptor.types;
|
|
38
|
+
const operationTypes = types?.operationTypes;
|
|
39
|
+
if (operationTypes?.import) {
|
|
40
|
+
imports.push(operationTypes.import);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return imports;
|
|
44
|
+
}
|
|
45
|
+
function extractExtensionIds(adapter, target, extensions) {
|
|
46
|
+
const ids = [];
|
|
47
|
+
const seen = /* @__PURE__ */ new Set();
|
|
48
|
+
if (!seen.has(adapter.id)) {
|
|
49
|
+
ids.push(adapter.id);
|
|
50
|
+
seen.add(adapter.id);
|
|
51
|
+
}
|
|
52
|
+
if (!seen.has(target.id)) {
|
|
53
|
+
ids.push(target.id);
|
|
54
|
+
seen.add(target.id);
|
|
55
|
+
}
|
|
56
|
+
for (const ext of extensions) {
|
|
57
|
+
if (!seen.has(ext.id)) {
|
|
58
|
+
ids.push(ext.id);
|
|
59
|
+
seen.add(ext.id);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return ids;
|
|
63
|
+
}
|
|
64
|
+
function extractParameterizedRenderers(descriptors) {
|
|
65
|
+
const renderers = /* @__PURE__ */ new Map();
|
|
66
|
+
const owners = /* @__PURE__ */ new Map();
|
|
67
|
+
for (const descriptor of descriptors) {
|
|
68
|
+
const parameterized = descriptor.types?.codecTypes?.parameterized;
|
|
69
|
+
if (!parameterized) continue;
|
|
70
|
+
for (const [codecId, renderer] of Object.entries(parameterized)) {
|
|
71
|
+
const existingOwner = owners.get(codecId);
|
|
72
|
+
if (existingOwner !== void 0) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`Duplicate parameterized renderer for codecId "${codecId}". Descriptor "${descriptor.id}" conflicts with "${existingOwner}". Each codecId can only have one renderer.`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
renderers.set(codecId, normalizeRenderer(codecId, renderer));
|
|
78
|
+
owners.set(codecId, descriptor.id);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return renderers;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// src/core/instance.ts
|
|
85
|
+
import { emit } from "@prisma-next/core-control-plane/emission";
|
|
86
|
+
import { sqlTargetFamilyHook } from "@prisma-next/sql-contract-emitter";
|
|
87
|
+
import { validateContract } from "@prisma-next/sql-contract-ts/contract";
|
|
88
|
+
import {
|
|
89
|
+
ensureSchemaStatement,
|
|
90
|
+
ensureTableStatement,
|
|
91
|
+
writeContractMarker
|
|
92
|
+
} from "@prisma-next/sql-runtime";
|
|
93
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
94
|
+
function convertOperationManifest(manifest) {
|
|
95
|
+
return {
|
|
96
|
+
forTypeId: manifest.for,
|
|
97
|
+
method: manifest.method,
|
|
98
|
+
args: manifest.args.map((arg) => {
|
|
99
|
+
if (arg.kind === "typeId") {
|
|
100
|
+
if (!arg.type) {
|
|
101
|
+
throw new Error("typeId arg must have type property");
|
|
102
|
+
}
|
|
103
|
+
return { kind: "typeId", type: arg.type };
|
|
104
|
+
}
|
|
105
|
+
if (arg.kind === "param") {
|
|
106
|
+
return { kind: "param" };
|
|
107
|
+
}
|
|
108
|
+
if (arg.kind === "literal") {
|
|
109
|
+
return { kind: "literal" };
|
|
110
|
+
}
|
|
111
|
+
throw new Error(`Invalid arg kind: ${arg.kind}`);
|
|
112
|
+
}),
|
|
113
|
+
returns: (() => {
|
|
114
|
+
if (manifest.returns.kind === "typeId") {
|
|
115
|
+
return { kind: "typeId", type: manifest.returns.type };
|
|
116
|
+
}
|
|
117
|
+
if (manifest.returns.kind === "builtin") {
|
|
118
|
+
return {
|
|
119
|
+
kind: "builtin",
|
|
120
|
+
type: manifest.returns.type
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
throw new Error(`Invalid return kind: ${manifest.returns.kind}`);
|
|
124
|
+
})(),
|
|
125
|
+
lowering: {
|
|
126
|
+
targetFamily: "sql",
|
|
127
|
+
strategy: manifest.lowering.strategy,
|
|
128
|
+
template: manifest.lowering.template
|
|
129
|
+
},
|
|
130
|
+
...manifest.capabilities ? { capabilities: manifest.capabilities } : {}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function extractCodecTypeIdsFromContract(contract) {
|
|
134
|
+
const typeIds = /* @__PURE__ */ new Set();
|
|
135
|
+
if (typeof contract === "object" && contract !== null && "storage" in contract && typeof contract.storage === "object" && contract.storage !== null && "tables" in contract.storage) {
|
|
136
|
+
const storage = contract.storage;
|
|
137
|
+
if (storage.tables && typeof storage.tables === "object") {
|
|
138
|
+
for (const table of Object.values(storage.tables)) {
|
|
139
|
+
if (typeof table === "object" && table !== null && "columns" in table && typeof table.columns === "object" && table.columns !== null) {
|
|
140
|
+
const columns = table.columns;
|
|
141
|
+
for (const column of Object.values(columns)) {
|
|
142
|
+
if (column && typeof column === "object" && "codecId" in column && typeof column.codecId === "string") {
|
|
143
|
+
typeIds.add(column.codecId);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return Array.from(typeIds).sort();
|
|
151
|
+
}
|
|
152
|
+
function createVerifyResult(options) {
|
|
153
|
+
const contract = {
|
|
154
|
+
coreHash: options.contractCoreHash
|
|
155
|
+
};
|
|
156
|
+
if (options.contractProfileHash) {
|
|
157
|
+
contract.profileHash = options.contractProfileHash;
|
|
158
|
+
}
|
|
159
|
+
const target = {
|
|
160
|
+
expected: options.expectedTargetId
|
|
161
|
+
};
|
|
162
|
+
if (options.actualTargetId) {
|
|
163
|
+
target.actual = options.actualTargetId;
|
|
164
|
+
}
|
|
165
|
+
const meta = {
|
|
166
|
+
contractPath: options.contractPath
|
|
167
|
+
};
|
|
168
|
+
if (options.configPath) {
|
|
169
|
+
meta.configPath = options.configPath;
|
|
170
|
+
}
|
|
171
|
+
const result = {
|
|
172
|
+
ok: options.ok,
|
|
173
|
+
summary: options.summary,
|
|
174
|
+
contract,
|
|
175
|
+
target,
|
|
176
|
+
meta,
|
|
177
|
+
timings: {
|
|
178
|
+
total: options.totalTime
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
if (options.code) {
|
|
182
|
+
result.code = options.code;
|
|
183
|
+
}
|
|
184
|
+
if (options.marker) {
|
|
185
|
+
result.marker = {
|
|
186
|
+
coreHash: options.marker.coreHash,
|
|
187
|
+
profileHash: options.marker.profileHash
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
if (options.missingCodecs) {
|
|
191
|
+
result.missingCodecs = options.missingCodecs;
|
|
192
|
+
}
|
|
193
|
+
if (options.codecCoverageSkipped) {
|
|
194
|
+
result.codecCoverageSkipped = options.codecCoverageSkipped;
|
|
195
|
+
}
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
function isSqlControlAdapter(value) {
|
|
199
|
+
return typeof value === "object" && value !== null && "introspect" in value && typeof value.introspect === "function";
|
|
200
|
+
}
|
|
201
|
+
function buildSqlTypeMetadataRegistry(options) {
|
|
202
|
+
const { target, adapter, extensionPacks: extensions } = options;
|
|
203
|
+
const registry = /* @__PURE__ */ new Map();
|
|
204
|
+
const targetId = adapter.targetId;
|
|
205
|
+
const descriptors = [target, adapter, ...extensions];
|
|
206
|
+
for (const descriptor of descriptors) {
|
|
207
|
+
const types = descriptor.types;
|
|
208
|
+
const storageTypes = types?.storage;
|
|
209
|
+
if (!storageTypes) {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
for (const storageType of storageTypes) {
|
|
213
|
+
if (storageType.familyId === "sql" && storageType.targetId === targetId) {
|
|
214
|
+
registry.set(storageType.typeId, {
|
|
215
|
+
typeId: storageType.typeId,
|
|
216
|
+
familyId: "sql",
|
|
217
|
+
targetId: storageType.targetId,
|
|
218
|
+
...storageType.nativeType !== void 0 ? { nativeType: storageType.nativeType } : {}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return registry;
|
|
224
|
+
}
|
|
225
|
+
function createSqlFamilyInstance(options) {
|
|
226
|
+
const { target, adapter, extensionPacks: extensions = [] } = options;
|
|
227
|
+
const descriptors = [target, adapter, ...extensions];
|
|
228
|
+
const operationRegistry = assembleOperationRegistry(descriptors, convertOperationManifest);
|
|
229
|
+
const codecTypeImports = extractCodecTypeImports(descriptors);
|
|
230
|
+
const operationTypeImports = extractOperationTypeImports(descriptors);
|
|
231
|
+
const extensionIds = extractExtensionIds(adapter, target, extensions);
|
|
232
|
+
const parameterizedRenderers = extractParameterizedRenderers(descriptors);
|
|
233
|
+
const typeMetadataRegistry = buildSqlTypeMetadataRegistry({
|
|
234
|
+
target,
|
|
235
|
+
adapter,
|
|
236
|
+
extensionPacks: extensions
|
|
237
|
+
});
|
|
238
|
+
function stripMappings(contract) {
|
|
239
|
+
if (typeof contract === "object" && contract !== null && "mappings" in contract) {
|
|
240
|
+
const { mappings: _mappings, ...contractIR } = contract;
|
|
241
|
+
return contractIR;
|
|
242
|
+
}
|
|
243
|
+
return contract;
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
familyId: "sql",
|
|
247
|
+
operationRegistry,
|
|
248
|
+
codecTypeImports,
|
|
249
|
+
operationTypeImports,
|
|
250
|
+
extensionIds,
|
|
251
|
+
typeMetadataRegistry,
|
|
252
|
+
validateContractIR(contractJson) {
|
|
253
|
+
const validated = validateContract(contractJson);
|
|
254
|
+
const { mappings: _mappings, ...contractIR } = validated;
|
|
255
|
+
return contractIR;
|
|
256
|
+
},
|
|
257
|
+
async verify(verifyOptions) {
|
|
258
|
+
const { driver, contractIR, expectedTargetId, contractPath, configPath } = verifyOptions;
|
|
259
|
+
const startTime = Date.now();
|
|
260
|
+
if (typeof contractIR !== "object" || contractIR === null || !("coreHash" in contractIR) || !("target" in contractIR) || typeof contractIR.coreHash !== "string" || typeof contractIR.target !== "string") {
|
|
261
|
+
throw new Error("Contract is missing required fields: coreHash or target");
|
|
262
|
+
}
|
|
263
|
+
const contractCoreHash = contractIR.coreHash;
|
|
264
|
+
const contractProfileHash = "profileHash" in contractIR && typeof contractIR.profileHash === "string" ? contractIR.profileHash : void 0;
|
|
265
|
+
const contractTarget = contractIR.target;
|
|
266
|
+
const marker = await readMarker(driver);
|
|
267
|
+
let missingCodecs;
|
|
268
|
+
let codecCoverageSkipped = false;
|
|
269
|
+
const supportedTypeIds = collectSupportedCodecTypeIds([
|
|
270
|
+
adapter,
|
|
271
|
+
target,
|
|
272
|
+
...extensions
|
|
273
|
+
]);
|
|
274
|
+
if (supportedTypeIds.length === 0) {
|
|
275
|
+
codecCoverageSkipped = true;
|
|
276
|
+
} else {
|
|
277
|
+
const supportedSet = new Set(supportedTypeIds);
|
|
278
|
+
const usedTypeIds = extractCodecTypeIdsFromContract(contractIR);
|
|
279
|
+
const missing = usedTypeIds.filter((id) => !supportedSet.has(id));
|
|
280
|
+
if (missing.length > 0) {
|
|
281
|
+
missingCodecs = missing;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if (!marker) {
|
|
285
|
+
const totalTime2 = Date.now() - startTime;
|
|
286
|
+
return createVerifyResult({
|
|
287
|
+
ok: false,
|
|
288
|
+
code: "PN-RTM-3001",
|
|
289
|
+
summary: "Marker missing",
|
|
290
|
+
contractCoreHash,
|
|
291
|
+
expectedTargetId,
|
|
292
|
+
contractPath,
|
|
293
|
+
totalTime: totalTime2,
|
|
294
|
+
...contractProfileHash ? { contractProfileHash } : {},
|
|
295
|
+
...missingCodecs ? { missingCodecs } : {},
|
|
296
|
+
...codecCoverageSkipped ? { codecCoverageSkipped } : {},
|
|
297
|
+
...configPath ? { configPath } : {}
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
if (contractTarget !== expectedTargetId) {
|
|
301
|
+
const totalTime2 = Date.now() - startTime;
|
|
302
|
+
return createVerifyResult({
|
|
303
|
+
ok: false,
|
|
304
|
+
code: "PN-RTM-3003",
|
|
305
|
+
summary: "Target mismatch",
|
|
306
|
+
contractCoreHash,
|
|
307
|
+
marker,
|
|
308
|
+
expectedTargetId,
|
|
309
|
+
actualTargetId: contractTarget,
|
|
310
|
+
contractPath,
|
|
311
|
+
totalTime: totalTime2,
|
|
312
|
+
...contractProfileHash ? { contractProfileHash } : {},
|
|
313
|
+
...missingCodecs ? { missingCodecs } : {},
|
|
314
|
+
...codecCoverageSkipped ? { codecCoverageSkipped } : {},
|
|
315
|
+
...configPath ? { configPath } : {}
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
if (marker.coreHash !== contractCoreHash) {
|
|
319
|
+
const totalTime2 = Date.now() - startTime;
|
|
320
|
+
return createVerifyResult({
|
|
321
|
+
ok: false,
|
|
322
|
+
code: "PN-RTM-3002",
|
|
323
|
+
summary: "Hash mismatch",
|
|
324
|
+
contractCoreHash,
|
|
325
|
+
marker,
|
|
326
|
+
expectedTargetId,
|
|
327
|
+
contractPath,
|
|
328
|
+
totalTime: totalTime2,
|
|
329
|
+
...contractProfileHash ? { contractProfileHash } : {},
|
|
330
|
+
...missingCodecs ? { missingCodecs } : {},
|
|
331
|
+
...codecCoverageSkipped ? { codecCoverageSkipped } : {},
|
|
332
|
+
...configPath ? { configPath } : {}
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
if (contractProfileHash && marker.profileHash !== contractProfileHash) {
|
|
336
|
+
const totalTime2 = Date.now() - startTime;
|
|
337
|
+
return createVerifyResult({
|
|
338
|
+
ok: false,
|
|
339
|
+
code: "PN-RTM-3002",
|
|
340
|
+
summary: "Hash mismatch",
|
|
341
|
+
contractCoreHash,
|
|
342
|
+
contractProfileHash,
|
|
343
|
+
marker,
|
|
344
|
+
expectedTargetId,
|
|
345
|
+
contractPath,
|
|
346
|
+
totalTime: totalTime2,
|
|
347
|
+
...missingCodecs ? { missingCodecs } : {},
|
|
348
|
+
...codecCoverageSkipped ? { codecCoverageSkipped } : {},
|
|
349
|
+
...configPath ? { configPath } : {}
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
const totalTime = Date.now() - startTime;
|
|
353
|
+
return createVerifyResult({
|
|
354
|
+
ok: true,
|
|
355
|
+
summary: "Database matches contract",
|
|
356
|
+
contractCoreHash,
|
|
357
|
+
marker,
|
|
358
|
+
expectedTargetId,
|
|
359
|
+
contractPath,
|
|
360
|
+
totalTime,
|
|
361
|
+
...contractProfileHash ? { contractProfileHash } : {},
|
|
362
|
+
...missingCodecs ? { missingCodecs } : {},
|
|
363
|
+
...codecCoverageSkipped ? { codecCoverageSkipped } : {},
|
|
364
|
+
...configPath ? { configPath } : {}
|
|
365
|
+
});
|
|
366
|
+
},
|
|
367
|
+
async schemaVerify(options2) {
|
|
368
|
+
const { driver, contractIR, strict, context, frameworkComponents } = options2;
|
|
369
|
+
const contract = validateContract(contractIR);
|
|
370
|
+
const controlAdapter = adapter.create();
|
|
371
|
+
if (!isSqlControlAdapter(controlAdapter)) {
|
|
372
|
+
throw new Error("Adapter does not implement SqlControlAdapter.introspect()");
|
|
373
|
+
}
|
|
374
|
+
const schemaIR = await controlAdapter.introspect(driver, contractIR);
|
|
375
|
+
return verifySqlSchema({
|
|
376
|
+
contract,
|
|
377
|
+
schema: schemaIR,
|
|
378
|
+
strict,
|
|
379
|
+
...ifDefined("context", context),
|
|
380
|
+
typeMetadataRegistry,
|
|
381
|
+
frameworkComponents
|
|
382
|
+
});
|
|
383
|
+
},
|
|
384
|
+
async sign(options2) {
|
|
385
|
+
const { driver, contractIR, contractPath, configPath } = options2;
|
|
386
|
+
const startTime = Date.now();
|
|
387
|
+
const contract = validateContract(contractIR);
|
|
388
|
+
const contractCoreHash = contract.coreHash;
|
|
389
|
+
const contractProfileHash = "profileHash" in contract && typeof contract.profileHash === "string" ? contract.profileHash : contractCoreHash;
|
|
390
|
+
const contractTarget = contract.target;
|
|
391
|
+
await driver.query(ensureSchemaStatement.sql, ensureSchemaStatement.params);
|
|
392
|
+
await driver.query(ensureTableStatement.sql, ensureTableStatement.params);
|
|
393
|
+
const existingMarker = await readMarker(driver);
|
|
394
|
+
let markerCreated = false;
|
|
395
|
+
let markerUpdated = false;
|
|
396
|
+
let previousHashes;
|
|
397
|
+
if (!existingMarker) {
|
|
398
|
+
const write = writeContractMarker({
|
|
399
|
+
coreHash: contractCoreHash,
|
|
400
|
+
profileHash: contractProfileHash,
|
|
401
|
+
contractJson: contractIR,
|
|
402
|
+
canonicalVersion: 1
|
|
403
|
+
});
|
|
404
|
+
await driver.query(write.insert.sql, write.insert.params);
|
|
405
|
+
markerCreated = true;
|
|
406
|
+
} else {
|
|
407
|
+
const existingCoreHash = existingMarker.coreHash;
|
|
408
|
+
const existingProfileHash = existingMarker.profileHash;
|
|
409
|
+
const coreHashMatches = existingCoreHash === contractCoreHash;
|
|
410
|
+
const profileHashMatches = existingProfileHash === contractProfileHash;
|
|
411
|
+
if (!coreHashMatches || !profileHashMatches) {
|
|
412
|
+
previousHashes = {
|
|
413
|
+
coreHash: existingCoreHash,
|
|
414
|
+
profileHash: existingProfileHash
|
|
415
|
+
};
|
|
416
|
+
const write = writeContractMarker({
|
|
417
|
+
coreHash: contractCoreHash,
|
|
418
|
+
profileHash: contractProfileHash,
|
|
419
|
+
contractJson: contractIR,
|
|
420
|
+
canonicalVersion: existingMarker.canonicalVersion ?? 1
|
|
421
|
+
});
|
|
422
|
+
await driver.query(write.update.sql, write.update.params);
|
|
423
|
+
markerUpdated = true;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
let summary;
|
|
427
|
+
if (markerCreated) {
|
|
428
|
+
summary = "Database signed (marker created)";
|
|
429
|
+
} else if (markerUpdated) {
|
|
430
|
+
summary = `Database signed (marker updated from ${previousHashes?.coreHash ?? "unknown"})`;
|
|
431
|
+
} else {
|
|
432
|
+
summary = "Database already signed with this contract";
|
|
433
|
+
}
|
|
434
|
+
const totalTime = Date.now() - startTime;
|
|
435
|
+
return {
|
|
436
|
+
ok: true,
|
|
437
|
+
summary,
|
|
438
|
+
contract: {
|
|
439
|
+
coreHash: contractCoreHash,
|
|
440
|
+
profileHash: contractProfileHash
|
|
441
|
+
},
|
|
442
|
+
target: {
|
|
443
|
+
expected: contractTarget,
|
|
444
|
+
actual: contractTarget
|
|
445
|
+
},
|
|
446
|
+
marker: {
|
|
447
|
+
created: markerCreated,
|
|
448
|
+
updated: markerUpdated,
|
|
449
|
+
...previousHashes ? { previous: previousHashes } : {}
|
|
450
|
+
},
|
|
451
|
+
meta: {
|
|
452
|
+
contractPath,
|
|
453
|
+
...configPath ? { configPath } : {}
|
|
454
|
+
},
|
|
455
|
+
timings: {
|
|
456
|
+
total: totalTime
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
},
|
|
460
|
+
async readMarker(options2) {
|
|
461
|
+
return readMarker(options2.driver);
|
|
462
|
+
},
|
|
463
|
+
async introspect(options2) {
|
|
464
|
+
const { driver, contractIR } = options2;
|
|
465
|
+
const controlAdapter = adapter.create();
|
|
466
|
+
if (!isSqlControlAdapter(controlAdapter)) {
|
|
467
|
+
throw new Error("Adapter does not implement SqlControlAdapter.introspect()");
|
|
468
|
+
}
|
|
469
|
+
return controlAdapter.introspect(driver, contractIR);
|
|
470
|
+
},
|
|
471
|
+
toSchemaView(schema) {
|
|
472
|
+
const rootLabel = "contract";
|
|
473
|
+
const tableNodes = Object.entries(schema.tables).map(
|
|
474
|
+
([tableName, table]) => {
|
|
475
|
+
const children = [];
|
|
476
|
+
const columnNodes = [];
|
|
477
|
+
for (const [columnName, column] of Object.entries(table.columns)) {
|
|
478
|
+
const nullableText = column.nullable ? "(nullable)" : "(not nullable)";
|
|
479
|
+
const typeDisplay = column.nativeType;
|
|
480
|
+
const label = `${columnName}: ${typeDisplay} ${nullableText}`;
|
|
481
|
+
columnNodes.push({
|
|
482
|
+
kind: "field",
|
|
483
|
+
id: `column-${tableName}-${columnName}`,
|
|
484
|
+
label,
|
|
485
|
+
meta: {
|
|
486
|
+
nativeType: column.nativeType,
|
|
487
|
+
nullable: column.nullable
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
if (columnNodes.length > 0) {
|
|
492
|
+
children.push({
|
|
493
|
+
kind: "collection",
|
|
494
|
+
id: `columns-${tableName}`,
|
|
495
|
+
label: "columns",
|
|
496
|
+
children: columnNodes
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
if (table.primaryKey) {
|
|
500
|
+
const pkColumns = table.primaryKey.columns.join(", ");
|
|
501
|
+
children.push({
|
|
502
|
+
kind: "index",
|
|
503
|
+
id: `primary-key-${tableName}`,
|
|
504
|
+
label: `primary key: ${pkColumns}`,
|
|
505
|
+
meta: {
|
|
506
|
+
columns: table.primaryKey.columns,
|
|
507
|
+
...table.primaryKey.name ? { name: table.primaryKey.name } : {}
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
for (const unique of table.uniques) {
|
|
512
|
+
const name = unique.name ?? `${tableName}_${unique.columns.join("_")}_unique`;
|
|
513
|
+
const label = `unique ${name}`;
|
|
514
|
+
children.push({
|
|
515
|
+
kind: "index",
|
|
516
|
+
id: `unique-${tableName}-${name}`,
|
|
517
|
+
label,
|
|
518
|
+
meta: {
|
|
519
|
+
columns: unique.columns,
|
|
520
|
+
unique: true
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
for (const index of table.indexes) {
|
|
525
|
+
const name = index.name ?? `${tableName}_${index.columns.join("_")}_idx`;
|
|
526
|
+
const label = index.unique ? `unique index ${name}` : `index ${name}`;
|
|
527
|
+
children.push({
|
|
528
|
+
kind: "index",
|
|
529
|
+
id: `index-${tableName}-${name}`,
|
|
530
|
+
label,
|
|
531
|
+
meta: {
|
|
532
|
+
columns: index.columns,
|
|
533
|
+
unique: index.unique
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
const tableMeta = {};
|
|
538
|
+
if (table.primaryKey) {
|
|
539
|
+
tableMeta["primaryKey"] = table.primaryKey.columns;
|
|
540
|
+
if (table.primaryKey.name) {
|
|
541
|
+
tableMeta["primaryKeyName"] = table.primaryKey.name;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
if (table.foreignKeys.length > 0) {
|
|
545
|
+
tableMeta["foreignKeys"] = table.foreignKeys.map((fk) => ({
|
|
546
|
+
columns: fk.columns,
|
|
547
|
+
referencedTable: fk.referencedTable,
|
|
548
|
+
referencedColumns: fk.referencedColumns,
|
|
549
|
+
...fk.name ? { name: fk.name } : {}
|
|
550
|
+
}));
|
|
551
|
+
}
|
|
552
|
+
const node = {
|
|
553
|
+
kind: "entity",
|
|
554
|
+
id: `table-${tableName}`,
|
|
555
|
+
label: `table ${tableName}`,
|
|
556
|
+
...Object.keys(tableMeta).length > 0 ? { meta: tableMeta } : {},
|
|
557
|
+
...children.length > 0 ? { children } : {}
|
|
558
|
+
};
|
|
559
|
+
return node;
|
|
560
|
+
}
|
|
561
|
+
);
|
|
562
|
+
const extensionNodes = schema.extensions.map((extName) => ({
|
|
563
|
+
kind: "extension",
|
|
564
|
+
id: `extension-${extName}`,
|
|
565
|
+
label: `${extName} extension is enabled`
|
|
566
|
+
}));
|
|
567
|
+
const rootChildren = [...tableNodes, ...extensionNodes];
|
|
568
|
+
const rootNode = {
|
|
569
|
+
kind: "root",
|
|
570
|
+
id: "sql-schema",
|
|
571
|
+
label: rootLabel,
|
|
572
|
+
...rootChildren.length > 0 ? { children: rootChildren } : {}
|
|
573
|
+
};
|
|
574
|
+
return {
|
|
575
|
+
root: rootNode
|
|
576
|
+
};
|
|
577
|
+
},
|
|
578
|
+
async emitContract({ contractIR }) {
|
|
579
|
+
const contractWithoutMappings = stripMappings(contractIR);
|
|
580
|
+
const validatedIR = this.validateContractIR(contractWithoutMappings);
|
|
581
|
+
const result = await emit(
|
|
582
|
+
validatedIR,
|
|
583
|
+
{
|
|
584
|
+
outputDir: "",
|
|
585
|
+
operationRegistry,
|
|
586
|
+
codecTypeImports,
|
|
587
|
+
operationTypeImports,
|
|
588
|
+
extensionIds,
|
|
589
|
+
parameterizedRenderers
|
|
590
|
+
},
|
|
591
|
+
sqlTargetFamilyHook
|
|
592
|
+
);
|
|
593
|
+
return {
|
|
594
|
+
contractJson: result.contractJson,
|
|
595
|
+
contractDts: result.contractDts,
|
|
596
|
+
coreHash: result.coreHash,
|
|
597
|
+
profileHash: result.profileHash
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
export {
|
|
604
|
+
assembleOperationRegistry,
|
|
605
|
+
extractCodecTypeImports,
|
|
606
|
+
extractOperationTypeImports,
|
|
607
|
+
extractExtensionIds,
|
|
608
|
+
convertOperationManifest,
|
|
609
|
+
createSqlFamilyInstance
|
|
610
|
+
};
|
|
611
|
+
//# sourceMappingURL=chunk-H7CGY6OH.js.map
|