@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.
- package/LICENSE +201 -0
- package/README.md +58 -22
- package/dist/authoring-type-constructors-DgU-RFaP.mjs +203 -0
- package/dist/authoring-type-constructors-DgU-RFaP.mjs.map +1 -0
- package/dist/control-adapter.d.mts +54 -0
- package/dist/control-adapter.d.mts.map +1 -0
- package/dist/control-adapter.mjs +1 -0
- package/dist/control.d.mts +386 -0
- package/dist/control.d.mts.map +1 -0
- package/dist/control.mjs +643 -0
- package/dist/control.mjs.map +1 -0
- package/dist/operation-descriptors.d.mts +380 -0
- package/dist/operation-descriptors.d.mts.map +1 -0
- package/dist/operation-descriptors.mjs +294 -0
- package/dist/operation-descriptors.mjs.map +1 -0
- package/dist/pack.d.mts +248 -0
- package/dist/pack.d.mts.map +1 -0
- package/dist/pack.mjs +18 -0
- package/dist/pack.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/types-BaUzKt6Q.d.mts +353 -0
- package/dist/types-BaUzKt6Q.d.mts.map +1 -0
- package/dist/verify-DZHtfcmj.mjs +108 -0
- package/dist/verify-DZHtfcmj.mjs.map +1 -0
- package/dist/verify-sql-schema-BBhkqEDo.d.mts +67 -0
- package/dist/verify-sql-schema-BBhkqEDo.d.mts.map +1 -0
- package/dist/verify-sql-schema-lR-tlboL.mjs +1174 -0
- package/dist/verify-sql-schema-lR-tlboL.mjs.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 +35 -43
- package/src/core/assembly.ts +123 -155
- package/src/core/authoring-field-presets.ts +207 -0
- package/src/core/authoring-type-constructors.ts +17 -0
- package/src/core/control-adapter.ts +18 -10
- package/src/core/control-descriptor.ts +28 -0
- package/src/core/control-instance.ts +700 -0
- package/src/core/migrations/contract-to-schema-ir.ts +269 -0
- package/src/core/migrations/descriptor-schemas.ts +172 -0
- package/src/core/migrations/operation-descriptors.ts +213 -0
- package/src/core/migrations/policies.ts +1 -1
- package/src/core/migrations/types.ts +199 -175
- package/src/core/runtime-descriptor.ts +19 -41
- package/src/core/runtime-instance.ts +11 -133
- package/src/core/schema-verify/verify-helpers.ts +104 -22
- package/src/core/schema-verify/verify-sql-schema.ts +964 -418
- package/src/core/verify.ts +4 -13
- package/src/exports/control.ts +31 -8
- package/src/exports/operation-descriptors.ts +52 -0
- package/src/exports/pack.ts +16 -0
- package/src/exports/runtime.ts +2 -6
- package/src/exports/schema-verify.ts +4 -1
- package/src/exports/test-utils.ts +3 -4
- package/dist/chunk-GYEG3I7U.js +0 -624
- package/dist/chunk-GYEG3I7U.js.map +0 -1
- package/dist/chunk-SU7LN2UH.js +0 -96
- package/dist/chunk-SU7LN2UH.js.map +0 -1
- package/dist/chunk-XH2Y5NTD.js +0 -715
- package/dist/chunk-XH2Y5NTD.js.map +0 -1
- package/dist/core/assembly.d.ts +0 -43
- 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 -28
- package/dist/core/descriptor.d.ts.map +0 -1
- package/dist/core/instance.d.ts +0 -140
- 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 -96
- 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 -15
- 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 -33
- package/src/core/instance.ts +0 -909
package/src/core/assembly.ts
CHANGED
|
@@ -1,189 +1,157 @@
|
|
|
1
|
+
import type { AuthoringContributions } from '@prisma-next/framework-components/authoring';
|
|
2
|
+
import type { Codec } from '@prisma-next/framework-components/codec';
|
|
3
|
+
import type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';
|
|
4
|
+
import { assertUniqueCodecOwner } from '@prisma-next/framework-components/control';
|
|
5
|
+
import type { TypesImportSpec } from '@prisma-next/framework-components/emission';
|
|
1
6
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export function assembleOperationRegistry(
|
|
22
|
-
descriptors: ReadonlyArray<
|
|
23
|
-
| ControlTargetDescriptor<'sql', string>
|
|
24
|
-
| ControlAdapterDescriptor<'sql', string>
|
|
25
|
-
| ControlExtensionDescriptor<'sql', string>
|
|
26
|
-
>,
|
|
27
|
-
convertOperationManifest: (manifest: OperationManifest) => OperationSignature,
|
|
28
|
-
): OperationRegistry {
|
|
29
|
-
const registry = createOperationRegistry();
|
|
30
|
-
|
|
31
|
-
for (const descriptor of descriptors) {
|
|
32
|
-
const operations = descriptor.operations ?? [];
|
|
33
|
-
for (const operationManifest of operations as ReadonlyArray<OperationManifest>) {
|
|
34
|
-
const signature = convertOperationManifest(operationManifest);
|
|
35
|
-
registry.register(signature);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
7
|
+
CodecControlHooks,
|
|
8
|
+
ControlMutationDefaultFunctionEntry,
|
|
9
|
+
ControlMutationDefaultGeneratorDescriptor,
|
|
10
|
+
PslScalarTypeDescriptor,
|
|
11
|
+
SqlControlStaticContributions,
|
|
12
|
+
} from './migrations/types';
|
|
13
|
+
|
|
14
|
+
export interface SqlControlDescriptorWithContributions extends SqlControlStaticContributions {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly authoring?: AuthoringContributions;
|
|
17
|
+
readonly types?: {
|
|
18
|
+
readonly codecTypes?: {
|
|
19
|
+
readonly import?: TypesImportSpec;
|
|
20
|
+
readonly codecInstances?: ReadonlyArray<Codec>;
|
|
21
|
+
readonly typeImports?: ReadonlyArray<TypesImportSpec>;
|
|
22
|
+
};
|
|
23
|
+
readonly operationTypes?: { readonly import: TypesImportSpec };
|
|
24
|
+
};
|
|
25
|
+
}
|
|
38
26
|
|
|
39
|
-
|
|
27
|
+
export interface AssembledControlMutationDefaultContributions {
|
|
28
|
+
readonly defaultFunctionRegistry: ReadonlyMap<string, ControlMutationDefaultFunctionEntry>;
|
|
29
|
+
readonly generatorDescriptors: readonly ControlMutationDefaultGeneratorDescriptor[];
|
|
40
30
|
}
|
|
41
31
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
descriptors: ReadonlyArray<
|
|
47
|
-
| ControlTargetDescriptor<'sql', string>
|
|
48
|
-
| ControlAdapterDescriptor<'sql', string>
|
|
49
|
-
| ControlExtensionDescriptor<'sql', string>
|
|
50
|
-
>,
|
|
51
|
-
): ReadonlyArray<TypesImportSpec> {
|
|
52
|
-
const imports: TypesImportSpec[] = [];
|
|
32
|
+
export interface AssembledPslInterpretationContributions
|
|
33
|
+
extends AssembledControlMutationDefaultContributions {
|
|
34
|
+
readonly scalarTypeDescriptors: ReadonlyMap<string, PslScalarTypeDescriptor>;
|
|
35
|
+
}
|
|
53
36
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
37
|
+
type CodecControlHooksMap = Record<string, CodecControlHooks>;
|
|
38
|
+
|
|
39
|
+
function hasCodecControlHooks(descriptor: unknown): descriptor is {
|
|
40
|
+
readonly id: string;
|
|
41
|
+
readonly types: {
|
|
42
|
+
readonly codecTypes: {
|
|
43
|
+
readonly controlPlaneHooks: CodecControlHooksMap;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
} {
|
|
47
|
+
if (typeof descriptor !== 'object' || descriptor === null) {
|
|
48
|
+
return false;
|
|
60
49
|
}
|
|
61
|
-
|
|
62
|
-
|
|
50
|
+
const d = descriptor as { types?: { codecTypes?: { controlPlaneHooks?: unknown } } };
|
|
51
|
+
const hooks = d.types?.codecTypes?.controlPlaneHooks;
|
|
52
|
+
return hooks !== null && hooks !== undefined && typeof hooks === 'object';
|
|
63
53
|
}
|
|
64
54
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
| ControlTargetDescriptor<'sql', string>
|
|
71
|
-
| ControlAdapterDescriptor<'sql', string>
|
|
72
|
-
| ControlExtensionDescriptor<'sql', string>
|
|
73
|
-
>,
|
|
74
|
-
): ReadonlyArray<TypesImportSpec> {
|
|
75
|
-
const imports: TypesImportSpec[] = [];
|
|
55
|
+
export function extractCodecControlHooks(
|
|
56
|
+
descriptors: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>,
|
|
57
|
+
): Map<string, CodecControlHooks> {
|
|
58
|
+
const hooks = new Map<string, CodecControlHooks>();
|
|
59
|
+
const owners = new Map<string, string>();
|
|
76
60
|
|
|
77
61
|
for (const descriptor of descriptors) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (operationTypes?.import) {
|
|
81
|
-
imports.push(operationTypes.import);
|
|
62
|
+
if (typeof descriptor !== 'object' || descriptor === null) {
|
|
63
|
+
continue;
|
|
82
64
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
): ReadonlyArray<string> {
|
|
98
|
-
const ids: string[] = [];
|
|
99
|
-
const seen = new Set<string>();
|
|
100
|
-
|
|
101
|
-
// Add adapter first
|
|
102
|
-
if (!seen.has(adapter.id)) {
|
|
103
|
-
ids.push(adapter.id);
|
|
104
|
-
seen.add(adapter.id);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Add target second
|
|
108
|
-
if (!seen.has(target.id)) {
|
|
109
|
-
ids.push(target.id);
|
|
110
|
-
seen.add(target.id);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Add extensions in order
|
|
114
|
-
for (const ext of extensions) {
|
|
115
|
-
if (!seen.has(ext.id)) {
|
|
116
|
-
ids.push(ext.id);
|
|
117
|
-
seen.add(ext.id);
|
|
65
|
+
if (!hasCodecControlHooks(descriptor)) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const controlPlaneHooks = descriptor.types.codecTypes.controlPlaneHooks;
|
|
69
|
+
for (const [codecId, hook] of Object.entries(controlPlaneHooks)) {
|
|
70
|
+
assertUniqueCodecOwner({
|
|
71
|
+
codecId,
|
|
72
|
+
owners,
|
|
73
|
+
descriptorId: descriptor.id,
|
|
74
|
+
entityLabel: 'control hooks',
|
|
75
|
+
entityOwnershipLabel: 'owner',
|
|
76
|
+
});
|
|
77
|
+
hooks.set(codecId, hook);
|
|
78
|
+
owners.set(codecId, descriptor.id);
|
|
118
79
|
}
|
|
119
80
|
}
|
|
120
81
|
|
|
121
|
-
return
|
|
82
|
+
return hooks;
|
|
122
83
|
}
|
|
123
84
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
* @returns Map from codecId to normalized renderer
|
|
132
|
-
*/
|
|
133
|
-
export function extractParameterizedRenderers(
|
|
134
|
-
descriptors: ReadonlyArray<
|
|
135
|
-
| ControlTargetDescriptor<'sql', string>
|
|
136
|
-
| ControlAdapterDescriptor<'sql', string>
|
|
137
|
-
| ControlExtensionDescriptor<'sql', string>
|
|
138
|
-
>,
|
|
139
|
-
): Map<string, NormalizedTypeRenderer> {
|
|
140
|
-
const renderers = new Map<string, NormalizedTypeRenderer>();
|
|
141
|
-
const owners = new Map<string, string>(); // codecId -> descriptor.id for error messages
|
|
85
|
+
export function assembleControlMutationDefaultContributions(
|
|
86
|
+
descriptors: ReadonlyArray<SqlControlDescriptorWithContributions>,
|
|
87
|
+
): AssembledControlMutationDefaultContributions {
|
|
88
|
+
const defaultFunctionRegistry = new Map<string, ControlMutationDefaultFunctionEntry>();
|
|
89
|
+
const functionOwners = new Map<string, string>();
|
|
90
|
+
const generatorMap = new Map<string, ControlMutationDefaultGeneratorDescriptor>();
|
|
91
|
+
const generatorOwners = new Map<string, string>();
|
|
142
92
|
|
|
143
93
|
for (const descriptor of descriptors) {
|
|
144
|
-
const
|
|
145
|
-
if (!
|
|
94
|
+
const contributions = descriptor.controlMutationDefaults?.();
|
|
95
|
+
if (!contributions) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
146
98
|
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if (existingOwner !== undefined) {
|
|
99
|
+
for (const generatorDescriptor of contributions.generatorDescriptors) {
|
|
100
|
+
const owner = generatorOwners.get(generatorDescriptor.id);
|
|
101
|
+
if (owner) {
|
|
151
102
|
throw new Error(
|
|
152
|
-
`Duplicate
|
|
153
|
-
`Descriptor "${descriptor.id}" conflicts with "${existingOwner}". ` +
|
|
154
|
-
'Each codecId can only have one renderer.',
|
|
103
|
+
`Duplicate mutation default generator id "${generatorDescriptor.id}". Descriptor "${descriptor.id}" conflicts with "${owner}".`,
|
|
155
104
|
);
|
|
156
105
|
}
|
|
106
|
+
generatorMap.set(generatorDescriptor.id, generatorDescriptor);
|
|
107
|
+
generatorOwners.set(generatorDescriptor.id, descriptor.id);
|
|
108
|
+
}
|
|
157
109
|
|
|
158
|
-
|
|
159
|
-
|
|
110
|
+
for (const [functionName, handler] of contributions.defaultFunctionRegistry) {
|
|
111
|
+
const owner = functionOwners.get(functionName);
|
|
112
|
+
if (owner) {
|
|
113
|
+
throw new Error(
|
|
114
|
+
`Duplicate mutation default function "${functionName}". Descriptor "${descriptor.id}" conflicts with "${owner}".`,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
defaultFunctionRegistry.set(functionName, handler);
|
|
118
|
+
functionOwners.set(functionName, descriptor.id);
|
|
160
119
|
}
|
|
161
120
|
}
|
|
162
121
|
|
|
163
|
-
return
|
|
122
|
+
return {
|
|
123
|
+
defaultFunctionRegistry,
|
|
124
|
+
generatorDescriptors: Array.from(generatorMap.values()),
|
|
125
|
+
};
|
|
164
126
|
}
|
|
165
127
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
export function extractParameterizedTypeImports(
|
|
173
|
-
descriptors: ReadonlyArray<
|
|
174
|
-
| ControlTargetDescriptor<'sql', string>
|
|
175
|
-
| ControlAdapterDescriptor<'sql', string>
|
|
176
|
-
| ControlExtensionDescriptor<'sql', string>
|
|
177
|
-
>,
|
|
178
|
-
): ReadonlyArray<TypesImportSpec> {
|
|
179
|
-
const imports: TypesImportSpec[] = [];
|
|
128
|
+
export function assemblePslInterpretationContributions(
|
|
129
|
+
descriptors: ReadonlyArray<SqlControlDescriptorWithContributions>,
|
|
130
|
+
): AssembledPslInterpretationContributions {
|
|
131
|
+
const mutationDefaults = assembleControlMutationDefaultContributions(descriptors);
|
|
132
|
+
const scalarTypeDescriptors = new Map<string, PslScalarTypeDescriptor>();
|
|
133
|
+
const scalarOwners = new Map<string, string>();
|
|
180
134
|
|
|
181
135
|
for (const descriptor of descriptors) {
|
|
182
|
-
const
|
|
183
|
-
if (
|
|
184
|
-
|
|
136
|
+
const pslTypeContributions = descriptor.pslTypeDescriptors?.();
|
|
137
|
+
if (!pslTypeContributions) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
for (const [typeName, scalarDescriptor] of pslTypeContributions.scalarTypeDescriptors) {
|
|
142
|
+
const owner = scalarOwners.get(typeName);
|
|
143
|
+
if (owner) {
|
|
144
|
+
throw new Error(
|
|
145
|
+
`Duplicate PSL scalar type descriptor "${typeName}". Descriptor "${descriptor.id}" conflicts with "${owner}".`,
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
scalarTypeDescriptors.set(typeName, scalarDescriptor);
|
|
149
|
+
scalarOwners.set(typeName, descriptor.id);
|
|
185
150
|
}
|
|
186
151
|
}
|
|
187
152
|
|
|
188
|
-
return
|
|
153
|
+
return {
|
|
154
|
+
...mutationDefaults,
|
|
155
|
+
scalarTypeDescriptors,
|
|
156
|
+
};
|
|
189
157
|
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import type { AuthoringFieldNamespace } from '@prisma-next/framework-components/authoring';
|
|
2
|
+
|
|
3
|
+
const CHARACTER_CODEC_ID = 'sql/char@1';
|
|
4
|
+
const CHARACTER_NATIVE_TYPE = 'character';
|
|
5
|
+
|
|
6
|
+
const nanoidOptionsArgument = {
|
|
7
|
+
kind: 'object',
|
|
8
|
+
optional: true,
|
|
9
|
+
properties: {
|
|
10
|
+
size: {
|
|
11
|
+
kind: 'number',
|
|
12
|
+
optional: true,
|
|
13
|
+
integer: true,
|
|
14
|
+
minimum: 2,
|
|
15
|
+
maximum: 255,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
} as const;
|
|
19
|
+
|
|
20
|
+
export const sqlFamilyAuthoringFieldPresets = {
|
|
21
|
+
text: {
|
|
22
|
+
kind: 'fieldPreset',
|
|
23
|
+
output: {
|
|
24
|
+
codecId: 'sql/text@1',
|
|
25
|
+
nativeType: 'text',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
timestamp: {
|
|
29
|
+
kind: 'fieldPreset',
|
|
30
|
+
output: {
|
|
31
|
+
codecId: 'sql/timestamp@1',
|
|
32
|
+
nativeType: 'timestamp',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
createdAt: {
|
|
36
|
+
kind: 'fieldPreset',
|
|
37
|
+
output: {
|
|
38
|
+
codecId: 'sql/timestamp@1',
|
|
39
|
+
nativeType: 'timestamp',
|
|
40
|
+
default: {
|
|
41
|
+
kind: 'function',
|
|
42
|
+
expression: 'CURRENT_TIMESTAMP',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
uuid: {
|
|
47
|
+
kind: 'fieldPreset',
|
|
48
|
+
output: {
|
|
49
|
+
codecId: CHARACTER_CODEC_ID,
|
|
50
|
+
nativeType: CHARACTER_NATIVE_TYPE,
|
|
51
|
+
typeParams: {
|
|
52
|
+
length: 36,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
ulid: {
|
|
57
|
+
kind: 'fieldPreset',
|
|
58
|
+
output: {
|
|
59
|
+
codecId: CHARACTER_CODEC_ID,
|
|
60
|
+
nativeType: CHARACTER_NATIVE_TYPE,
|
|
61
|
+
typeParams: {
|
|
62
|
+
length: 26,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
nanoid: {
|
|
67
|
+
kind: 'fieldPreset',
|
|
68
|
+
args: [nanoidOptionsArgument],
|
|
69
|
+
output: {
|
|
70
|
+
codecId: CHARACTER_CODEC_ID,
|
|
71
|
+
nativeType: CHARACTER_NATIVE_TYPE,
|
|
72
|
+
typeParams: {
|
|
73
|
+
length: {
|
|
74
|
+
kind: 'arg',
|
|
75
|
+
index: 0,
|
|
76
|
+
path: ['size'],
|
|
77
|
+
default: 21,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
cuid2: {
|
|
83
|
+
kind: 'fieldPreset',
|
|
84
|
+
output: {
|
|
85
|
+
codecId: CHARACTER_CODEC_ID,
|
|
86
|
+
nativeType: CHARACTER_NATIVE_TYPE,
|
|
87
|
+
typeParams: {
|
|
88
|
+
length: 24,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
ksuid: {
|
|
93
|
+
kind: 'fieldPreset',
|
|
94
|
+
output: {
|
|
95
|
+
codecId: CHARACTER_CODEC_ID,
|
|
96
|
+
nativeType: CHARACTER_NATIVE_TYPE,
|
|
97
|
+
typeParams: {
|
|
98
|
+
length: 27,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
id: {
|
|
103
|
+
uuidv4: {
|
|
104
|
+
kind: 'fieldPreset',
|
|
105
|
+
output: {
|
|
106
|
+
codecId: CHARACTER_CODEC_ID,
|
|
107
|
+
nativeType: CHARACTER_NATIVE_TYPE,
|
|
108
|
+
typeParams: {
|
|
109
|
+
length: 36,
|
|
110
|
+
},
|
|
111
|
+
executionDefault: {
|
|
112
|
+
kind: 'generator',
|
|
113
|
+
id: 'uuidv4',
|
|
114
|
+
},
|
|
115
|
+
id: true,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
uuidv7: {
|
|
119
|
+
kind: 'fieldPreset',
|
|
120
|
+
output: {
|
|
121
|
+
codecId: CHARACTER_CODEC_ID,
|
|
122
|
+
nativeType: CHARACTER_NATIVE_TYPE,
|
|
123
|
+
typeParams: {
|
|
124
|
+
length: 36,
|
|
125
|
+
},
|
|
126
|
+
executionDefault: {
|
|
127
|
+
kind: 'generator',
|
|
128
|
+
id: 'uuidv7',
|
|
129
|
+
},
|
|
130
|
+
id: true,
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
ulid: {
|
|
134
|
+
kind: 'fieldPreset',
|
|
135
|
+
output: {
|
|
136
|
+
codecId: CHARACTER_CODEC_ID,
|
|
137
|
+
nativeType: CHARACTER_NATIVE_TYPE,
|
|
138
|
+
typeParams: {
|
|
139
|
+
length: 26,
|
|
140
|
+
},
|
|
141
|
+
executionDefault: {
|
|
142
|
+
kind: 'generator',
|
|
143
|
+
id: 'ulid',
|
|
144
|
+
},
|
|
145
|
+
id: true,
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
nanoid: {
|
|
149
|
+
kind: 'fieldPreset',
|
|
150
|
+
args: [nanoidOptionsArgument],
|
|
151
|
+
output: {
|
|
152
|
+
codecId: CHARACTER_CODEC_ID,
|
|
153
|
+
nativeType: CHARACTER_NATIVE_TYPE,
|
|
154
|
+
typeParams: {
|
|
155
|
+
length: {
|
|
156
|
+
kind: 'arg',
|
|
157
|
+
index: 0,
|
|
158
|
+
path: ['size'],
|
|
159
|
+
default: 21,
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
executionDefault: {
|
|
163
|
+
kind: 'generator',
|
|
164
|
+
id: 'nanoid',
|
|
165
|
+
params: {
|
|
166
|
+
size: {
|
|
167
|
+
kind: 'arg',
|
|
168
|
+
index: 0,
|
|
169
|
+
path: ['size'],
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
id: true,
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
cuid2: {
|
|
177
|
+
kind: 'fieldPreset',
|
|
178
|
+
output: {
|
|
179
|
+
codecId: CHARACTER_CODEC_ID,
|
|
180
|
+
nativeType: CHARACTER_NATIVE_TYPE,
|
|
181
|
+
typeParams: {
|
|
182
|
+
length: 24,
|
|
183
|
+
},
|
|
184
|
+
executionDefault: {
|
|
185
|
+
kind: 'generator',
|
|
186
|
+
id: 'cuid2',
|
|
187
|
+
},
|
|
188
|
+
id: true,
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
ksuid: {
|
|
192
|
+
kind: 'fieldPreset',
|
|
193
|
+
output: {
|
|
194
|
+
codecId: CHARACTER_CODEC_ID,
|
|
195
|
+
nativeType: CHARACTER_NATIVE_TYPE,
|
|
196
|
+
typeParams: {
|
|
197
|
+
length: 27,
|
|
198
|
+
},
|
|
199
|
+
executionDefault: {
|
|
200
|
+
kind: 'generator',
|
|
201
|
+
id: 'ksuid',
|
|
202
|
+
},
|
|
203
|
+
id: true,
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
} as const satisfies AuthoringFieldNamespace;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AuthoringTypeNamespace } from '@prisma-next/framework-components/authoring';
|
|
2
|
+
|
|
3
|
+
export const sqlFamilyAuthoringTypes = {
|
|
4
|
+
sql: {
|
|
5
|
+
String: {
|
|
6
|
+
kind: 'typeConstructor',
|
|
7
|
+
args: [{ kind: 'number', name: 'length', integer: true, minimum: 1, maximum: 10485760 }],
|
|
8
|
+
output: {
|
|
9
|
+
codecId: 'sql/varchar@1',
|
|
10
|
+
nativeType: 'character varying',
|
|
11
|
+
typeParams: {
|
|
12
|
+
length: { kind: 'arg', index: 0 },
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
} as const satisfies AuthoringTypeNamespace;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
ControlAdapterInstance,
|
|
3
3
|
ControlDriverInstance,
|
|
4
|
-
} from '@prisma-next/
|
|
4
|
+
} from '@prisma-next/framework-components/control';
|
|
5
5
|
import type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';
|
|
6
|
+
import type { DefaultNormalizer, NativeTypeNormalizer } from './schema-verify/verify-sql-schema';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* SQL control adapter interface for control-plane operations.
|
|
@@ -12,13 +13,6 @@ import type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';
|
|
|
12
13
|
*/
|
|
13
14
|
export interface SqlControlAdapter<TTarget extends string = string>
|
|
14
15
|
extends ControlAdapterInstance<'sql', TTarget> {
|
|
15
|
-
/**
|
|
16
|
-
* The target ID this adapter implements.
|
|
17
|
-
* Used for type tracking and runtime validation.
|
|
18
|
-
* @deprecated Use targetId from ControlAdapterInstance instead
|
|
19
|
-
*/
|
|
20
|
-
readonly target: TTarget;
|
|
21
|
-
|
|
22
16
|
/**
|
|
23
17
|
* Introspects a database schema and returns a raw SqlSchemaIR.
|
|
24
18
|
*
|
|
@@ -27,15 +21,29 @@ export interface SqlControlAdapter<TTarget extends string = string>
|
|
|
27
21
|
* Type mapping and enrichment are handled separately by enrichment helpers.
|
|
28
22
|
*
|
|
29
23
|
* @param driver - ControlDriverInstance instance for executing queries (target-specific)
|
|
30
|
-
* @param
|
|
24
|
+
* @param contract - Optional contract for contract-guided introspection (filtering, optimization)
|
|
31
25
|
* @param schema - Schema name to introspect (defaults to 'public')
|
|
32
26
|
* @returns Promise resolving to SqlSchemaIR representing the live database schema
|
|
33
27
|
*/
|
|
34
28
|
introspect(
|
|
35
29
|
driver: ControlDriverInstance<'sql', TTarget>,
|
|
36
|
-
|
|
30
|
+
contract?: unknown,
|
|
37
31
|
schema?: string,
|
|
38
32
|
): Promise<SqlSchemaIR>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Optional target-specific normalizer for raw database default expressions.
|
|
36
|
+
* When provided, schema defaults (raw strings) are normalized before comparison
|
|
37
|
+
* with contract defaults (ColumnDefault objects) during schema verification.
|
|
38
|
+
*/
|
|
39
|
+
readonly normalizeDefault?: DefaultNormalizer;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Optional target-specific normalizer for schema native type names.
|
|
43
|
+
* When provided, schema native types (from introspection) are normalized
|
|
44
|
+
* before comparison with contract native types during schema verification.
|
|
45
|
+
*/
|
|
46
|
+
readonly normalizeNativeType?: NativeTypeNormalizer;
|
|
39
47
|
}
|
|
40
48
|
|
|
41
49
|
/**
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ControlFamilyDescriptor,
|
|
3
|
+
ControlStack,
|
|
4
|
+
} from '@prisma-next/framework-components/control';
|
|
5
|
+
import { sqlEmission } from '@prisma-next/sql-contract-emitter';
|
|
6
|
+
import { sqlFamilyAuthoringFieldPresets } from './authoring-field-presets';
|
|
7
|
+
import { sqlFamilyAuthoringTypes } from './authoring-type-constructors';
|
|
8
|
+
import { createSqlFamilyInstance, type SqlControlFamilyInstance } from './control-instance';
|
|
9
|
+
|
|
10
|
+
export class SqlFamilyDescriptor
|
|
11
|
+
implements ControlFamilyDescriptor<'sql', SqlControlFamilyInstance>
|
|
12
|
+
{
|
|
13
|
+
readonly kind = 'family' as const;
|
|
14
|
+
readonly id = 'sql';
|
|
15
|
+
readonly familyId = 'sql' as const;
|
|
16
|
+
readonly version = '0.0.1';
|
|
17
|
+
readonly emission = sqlEmission;
|
|
18
|
+
readonly authoring = {
|
|
19
|
+
field: sqlFamilyAuthoringFieldPresets,
|
|
20
|
+
type: sqlFamilyAuthoringTypes,
|
|
21
|
+
} as const;
|
|
22
|
+
|
|
23
|
+
create<TTargetId extends string>(
|
|
24
|
+
stack: ControlStack<'sql', TTargetId>,
|
|
25
|
+
): SqlControlFamilyInstance {
|
|
26
|
+
return createSqlFamilyInstance(stack);
|
|
27
|
+
}
|
|
28
|
+
}
|