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