@prisma-next/family-sql 0.3.0-pr.99.6 → 0.4.0-dev.1

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