@prisma-next/family-sql 0.3.0-dev.3 → 0.3.0-dev.30
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/{exports/chunk-6P44BVZ4.js → chunk-GYEG3I7U.js} +48 -4
- package/dist/chunk-GYEG3I7U.js.map +1 -0
- package/dist/{exports/chunk-C3GKWCKA.js → chunk-SU7LN2UH.js} +1 -1
- package/dist/chunk-SU7LN2UH.js.map +1 -0
- package/dist/{exports/chunk-F252JMEU.js → chunk-XH2Y5NTD.js} +59 -116
- package/dist/chunk-XH2Y5NTD.js.map +1 -0
- package/dist/core/assembly.d.ts +43 -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 +28 -0
- package/dist/core/descriptor.d.ts.map +1 -0
- package/dist/{exports/instance-DiZi2k_2.d.ts → core/instance.d.ts} +28 -15
- 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/{exports/types-Bh7ftf0Q.d.ts → core/migrations/types.d.ts} +41 -36
- 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 -44
- package/dist/exports/control-adapter.d.ts.map +1 -0
- package/dist/exports/control.d.ts +8 -160
- package/dist/exports/control.d.ts.map +1 -0
- package/dist/exports/control.js +7 -7
- package/dist/exports/control.js.map +1 -1
- package/dist/exports/runtime.d.ts +3 -61
- package/dist/exports/runtime.d.ts.map +1 -0
- package/dist/exports/schema-verify.d.ts +8 -72
- package/dist/exports/schema-verify.d.ts.map +1 -0
- package/dist/exports/schema-verify.js +5 -1
- package/dist/exports/test-utils.d.ts +5 -31
- package/dist/exports/test-utils.d.ts.map +1 -0
- package/dist/exports/test-utils.js +3 -3
- package/dist/exports/verify.d.ts +2 -28
- package/dist/exports/verify.d.ts.map +1 -0
- package/dist/exports/verify.js +1 -1
- package/package.json +26 -26
- package/src/core/assembly.ts +189 -0
- package/src/core/control-adapter.ts +52 -0
- package/src/core/descriptor.ts +33 -0
- package/src/core/instance.ts +909 -0
- package/src/core/migrations/plan-helpers.ts +164 -0
- package/src/core/migrations/policies.ts +8 -0
- package/src/core/migrations/types.ts +380 -0
- package/src/core/runtime-descriptor.ts +45 -0
- package/src/core/runtime-instance.ts +144 -0
- package/src/core/schema-verify/verify-helpers.ts +532 -0
- package/src/core/schema-verify/verify-sql-schema.ts +588 -0
- package/src/core/verify.ts +177 -0
- package/src/exports/control-adapter.ts +1 -0
- package/src/exports/control.ts +56 -0
- package/src/exports/runtime.ts +7 -0
- package/src/exports/schema-verify.ts +16 -0
- package/src/exports/test-utils.ts +11 -0
- package/src/exports/verify.ts +1 -0
- package/dist/exports/chunk-6P44BVZ4.js.map +0 -1
- package/dist/exports/chunk-C3GKWCKA.js.map +0 -1
- package/dist/exports/chunk-F252JMEU.js.map +0 -1
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
NormalizedTypeRenderer,
|
|
3
|
+
TypeRenderer,
|
|
4
|
+
} from '@prisma-next/contract/framework-components';
|
|
5
|
+
import { normalizeRenderer } from '@prisma-next/contract/framework-components';
|
|
6
|
+
import type { OperationManifest } from '@prisma-next/contract/pack-manifest-types';
|
|
7
|
+
import type { TypesImportSpec } from '@prisma-next/contract/types';
|
|
8
|
+
import type {
|
|
9
|
+
ControlAdapterDescriptor,
|
|
10
|
+
ControlExtensionDescriptor,
|
|
11
|
+
ControlTargetDescriptor,
|
|
12
|
+
} from '@prisma-next/core-control-plane/types';
|
|
13
|
+
import type { OperationRegistry, OperationSignature } from '@prisma-next/operations';
|
|
14
|
+
import { createOperationRegistry } from '@prisma-next/operations';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Assembles an operation registry from descriptors (adapter, target, extensions).
|
|
18
|
+
* Loops over descriptors, extracts operations, converts them using the provided
|
|
19
|
+
* conversion function, and registers them in a new registry.
|
|
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
|
+
}
|
|
38
|
+
|
|
39
|
+
return registry;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Extracts codec type imports from descriptors for contract.d.ts generation.
|
|
44
|
+
*/
|
|
45
|
+
export function extractCodecTypeImports(
|
|
46
|
+
descriptors: ReadonlyArray<
|
|
47
|
+
| ControlTargetDescriptor<'sql', string>
|
|
48
|
+
| ControlAdapterDescriptor<'sql', string>
|
|
49
|
+
| ControlExtensionDescriptor<'sql', string>
|
|
50
|
+
>,
|
|
51
|
+
): ReadonlyArray<TypesImportSpec> {
|
|
52
|
+
const imports: TypesImportSpec[] = [];
|
|
53
|
+
|
|
54
|
+
for (const descriptor of descriptors) {
|
|
55
|
+
const types = descriptor.types;
|
|
56
|
+
const codecTypes = types?.codecTypes;
|
|
57
|
+
if (codecTypes?.import) {
|
|
58
|
+
imports.push(codecTypes.import);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return imports;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Extracts operation type imports from descriptors for contract.d.ts generation.
|
|
67
|
+
*/
|
|
68
|
+
export function extractOperationTypeImports(
|
|
69
|
+
descriptors: ReadonlyArray<
|
|
70
|
+
| ControlTargetDescriptor<'sql', string>
|
|
71
|
+
| ControlAdapterDescriptor<'sql', string>
|
|
72
|
+
| ControlExtensionDescriptor<'sql', string>
|
|
73
|
+
>,
|
|
74
|
+
): ReadonlyArray<TypesImportSpec> {
|
|
75
|
+
const imports: TypesImportSpec[] = [];
|
|
76
|
+
|
|
77
|
+
for (const descriptor of descriptors) {
|
|
78
|
+
const types = descriptor.types;
|
|
79
|
+
const operationTypes = types?.operationTypes;
|
|
80
|
+
if (operationTypes?.import) {
|
|
81
|
+
imports.push(operationTypes.import);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return imports;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Extracts extension IDs from descriptors in deterministic order:
|
|
90
|
+
* [adapter.id, target.id, ...extensions.map(e => e.id)]
|
|
91
|
+
* Deduplicates while preserving stable order.
|
|
92
|
+
*/
|
|
93
|
+
export function extractExtensionIds(
|
|
94
|
+
adapter: ControlAdapterDescriptor<'sql', string>,
|
|
95
|
+
target: ControlTargetDescriptor<'sql', string>,
|
|
96
|
+
extensions: ReadonlyArray<ControlExtensionDescriptor<'sql', string>>,
|
|
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);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return ids;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Extracts and normalizes parameterized codec renderers from descriptors.
|
|
126
|
+
* Templates are compiled to functions at this layer.
|
|
127
|
+
*
|
|
128
|
+
* Throws an error if multiple descriptors provide a renderer for the same codecId.
|
|
129
|
+
* This is intentional - duplicate codecId is a hard error, not a silent override.
|
|
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
|
|
142
|
+
|
|
143
|
+
for (const descriptor of descriptors) {
|
|
144
|
+
const codecTypes = descriptor.types?.codecTypes;
|
|
145
|
+
if (!codecTypes?.parameterized) continue;
|
|
146
|
+
|
|
147
|
+
const parameterized: Record<string, TypeRenderer> = codecTypes.parameterized;
|
|
148
|
+
for (const [codecId, renderer] of Object.entries(parameterized)) {
|
|
149
|
+
const existingOwner = owners.get(codecId);
|
|
150
|
+
if (existingOwner !== undefined) {
|
|
151
|
+
throw new Error(
|
|
152
|
+
`Duplicate parameterized renderer for codecId "${codecId}". ` +
|
|
153
|
+
`Descriptor "${descriptor.id}" conflicts with "${existingOwner}". ` +
|
|
154
|
+
'Each codecId can only have one renderer.',
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
renderers.set(codecId, normalizeRenderer(codecId, renderer));
|
|
159
|
+
owners.set(codecId, descriptor.id);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return renderers;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Extracts parameterized type imports from descriptors for contract.d.ts generation.
|
|
168
|
+
* These are type imports needed by parameterized codec renderers.
|
|
169
|
+
*
|
|
170
|
+
* @returns Array of type import specs (may contain duplicates; caller should deduplicate)
|
|
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[] = [];
|
|
180
|
+
|
|
181
|
+
for (const descriptor of descriptors) {
|
|
182
|
+
const parameterizedImports = descriptor.types?.codecTypes?.parameterizedImports;
|
|
183
|
+
if (parameterizedImports) {
|
|
184
|
+
imports.push(...parameterizedImports);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return imports;
|
|
189
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ControlAdapterInstance,
|
|
3
|
+
ControlDriverInstance,
|
|
4
|
+
} from '@prisma-next/core-control-plane/types';
|
|
5
|
+
import type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* SQL control adapter interface for control-plane operations.
|
|
9
|
+
* Implemented by target-specific adapters (e.g., Postgres, MySQL).
|
|
10
|
+
*
|
|
11
|
+
* @template TTarget - The target ID (e.g., 'postgres', 'mysql')
|
|
12
|
+
*/
|
|
13
|
+
export interface SqlControlAdapter<TTarget extends string = string>
|
|
14
|
+
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
|
+
/**
|
|
23
|
+
* Introspects a database schema and returns a raw SqlSchemaIR.
|
|
24
|
+
*
|
|
25
|
+
* This is a pure schema discovery operation that queries the database catalog
|
|
26
|
+
* and returns the schema structure without type mapping or contract enrichment.
|
|
27
|
+
* Type mapping and enrichment are handled separately by enrichment helpers.
|
|
28
|
+
*
|
|
29
|
+
* @param driver - ControlDriverInstance instance for executing queries (target-specific)
|
|
30
|
+
* @param contractIR - Optional contract IR for contract-guided introspection (filtering, optimization)
|
|
31
|
+
* @param schema - Schema name to introspect (defaults to 'public')
|
|
32
|
+
* @returns Promise resolving to SqlSchemaIR representing the live database schema
|
|
33
|
+
*/
|
|
34
|
+
introspect(
|
|
35
|
+
driver: ControlDriverInstance<'sql', TTarget>,
|
|
36
|
+
contractIR?: unknown,
|
|
37
|
+
schema?: string,
|
|
38
|
+
): Promise<SqlSchemaIR>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* SQL control adapter descriptor interface.
|
|
43
|
+
* Provides a factory method to create control adapter instances.
|
|
44
|
+
*
|
|
45
|
+
* @template TTarget - The target ID (e.g., 'postgres', 'mysql')
|
|
46
|
+
*/
|
|
47
|
+
export interface SqlControlAdapterDescriptor<TTarget extends string = string> {
|
|
48
|
+
/**
|
|
49
|
+
* Creates a SQL control adapter instance for control-plane operations.
|
|
50
|
+
*/
|
|
51
|
+
create(): SqlControlAdapter<TTarget>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ControlFamilyDescriptor,
|
|
3
|
+
ControlPlaneStack,
|
|
4
|
+
} from '@prisma-next/core-control-plane/types';
|
|
5
|
+
import { sqlTargetFamilyHook } from '@prisma-next/sql-contract-emitter';
|
|
6
|
+
import { createSqlFamilyInstance, type SqlControlFamilyInstance } from './instance';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* SQL family descriptor implementation.
|
|
10
|
+
* Provides the SQL family hook and factory method.
|
|
11
|
+
*/
|
|
12
|
+
export class SqlFamilyDescriptor
|
|
13
|
+
implements ControlFamilyDescriptor<'sql', SqlControlFamilyInstance>
|
|
14
|
+
{
|
|
15
|
+
readonly kind = 'family' as const;
|
|
16
|
+
readonly id = 'sql';
|
|
17
|
+
readonly familyId = 'sql' as const;
|
|
18
|
+
readonly version = '0.0.1';
|
|
19
|
+
readonly hook = sqlTargetFamilyHook;
|
|
20
|
+
|
|
21
|
+
create<TTargetId extends string>(
|
|
22
|
+
stack: ControlPlaneStack<'sql', TTargetId>,
|
|
23
|
+
): SqlControlFamilyInstance {
|
|
24
|
+
// Note: driver is not passed here because SqlFamilyInstance operations
|
|
25
|
+
// (validate, emit, etc.) don't require DB connectivity. Commands that
|
|
26
|
+
// need the driver (verify, introspect) get it directly from the stack.
|
|
27
|
+
return createSqlFamilyInstance({
|
|
28
|
+
target: stack.target,
|
|
29
|
+
adapter: stack.adapter,
|
|
30
|
+
extensionPacks: stack.extensionPacks,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|