@prisma-next/family-sql 0.3.0-dev.34 → 0.3.0-dev.37

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 (98) hide show
  1. package/README.md +11 -6
  2. package/dist/assembly-BVS641kd.mjs +106 -0
  3. package/dist/assembly-BVS641kd.mjs.map +1 -0
  4. package/dist/control-adapter.d.mts +60 -0
  5. package/dist/control-adapter.d.mts.map +1 -0
  6. package/dist/control-adapter.mjs +1 -0
  7. package/dist/control-instance-Cvmn5zpn.d.mts +292 -0
  8. package/dist/control-instance-Cvmn5zpn.d.mts.map +1 -0
  9. package/dist/control.d.mts +64 -0
  10. package/dist/control.d.mts.map +1 -0
  11. package/dist/control.mjs +534 -0
  12. package/dist/control.mjs.map +1 -0
  13. package/dist/runtime.d.mts +27 -0
  14. package/dist/runtime.d.mts.map +1 -0
  15. package/dist/runtime.mjs +38 -0
  16. package/dist/runtime.mjs.map +1 -0
  17. package/dist/schema-verify.d.mts +48 -0
  18. package/dist/schema-verify.d.mts.map +1 -0
  19. package/dist/schema-verify.mjs +4 -0
  20. package/dist/test-utils.d.mts +2 -0
  21. package/dist/test-utils.mjs +3 -0
  22. package/dist/verify-BfMETJcM.mjs +108 -0
  23. package/dist/verify-BfMETJcM.mjs.map +1 -0
  24. package/dist/verify-sql-schema-B4T5MEuz.mjs +934 -0
  25. package/dist/verify-sql-schema-B4T5MEuz.mjs.map +1 -0
  26. package/dist/verify-sql-schema-CvQoGm2Q.d.mts +67 -0
  27. package/dist/verify-sql-schema-CvQoGm2Q.d.mts.map +1 -0
  28. package/dist/verify.d.mts +31 -0
  29. package/dist/verify.d.mts.map +1 -0
  30. package/dist/verify.mjs +3 -0
  31. package/package.json +33 -44
  32. package/src/core/assembly.ts +120 -96
  33. package/src/core/control-adapter.ts +15 -0
  34. package/src/core/{descriptor.ts → control-descriptor.ts} +15 -11
  35. package/src/core/{instance.ts → control-instance.ts} +72 -231
  36. package/src/core/migrations/types.ts +62 -163
  37. package/src/core/runtime-descriptor.ts +19 -41
  38. package/src/core/runtime-instance.ts +11 -133
  39. package/src/core/schema-verify/verify-sql-schema.ts +820 -397
  40. package/src/core/verify.ts +4 -13
  41. package/src/exports/control.ts +9 -6
  42. package/src/exports/runtime.ts +2 -6
  43. package/src/exports/schema-verify.ts +4 -1
  44. package/src/exports/test-utils.ts +0 -1
  45. package/dist/chunk-EHYNXF4K.js +0 -627
  46. package/dist/chunk-EHYNXF4K.js.map +0 -1
  47. package/dist/chunk-SU7LN2UH.js +0 -96
  48. package/dist/chunk-SU7LN2UH.js.map +0 -1
  49. package/dist/chunk-XH2Y5NTD.js +0 -715
  50. package/dist/chunk-XH2Y5NTD.js.map +0 -1
  51. package/dist/core/assembly.d.ts +0 -43
  52. package/dist/core/assembly.d.ts.map +0 -1
  53. package/dist/core/control-adapter.d.ts +0 -42
  54. package/dist/core/control-adapter.d.ts.map +0 -1
  55. package/dist/core/descriptor.d.ts +0 -28
  56. package/dist/core/descriptor.d.ts.map +0 -1
  57. package/dist/core/instance.d.ts +0 -140
  58. package/dist/core/instance.d.ts.map +0 -1
  59. package/dist/core/migrations/plan-helpers.d.ts +0 -20
  60. package/dist/core/migrations/plan-helpers.d.ts.map +0 -1
  61. package/dist/core/migrations/policies.d.ts +0 -6
  62. package/dist/core/migrations/policies.d.ts.map +0 -1
  63. package/dist/core/migrations/types.d.ts +0 -280
  64. package/dist/core/migrations/types.d.ts.map +0 -1
  65. package/dist/core/runtime-descriptor.d.ts +0 -19
  66. package/dist/core/runtime-descriptor.d.ts.map +0 -1
  67. package/dist/core/runtime-instance.d.ts +0 -54
  68. package/dist/core/runtime-instance.d.ts.map +0 -1
  69. package/dist/core/schema-verify/verify-helpers.d.ts +0 -96
  70. package/dist/core/schema-verify/verify-helpers.d.ts.map +0 -1
  71. package/dist/core/schema-verify/verify-sql-schema.d.ts +0 -45
  72. package/dist/core/schema-verify/verify-sql-schema.d.ts.map +0 -1
  73. package/dist/core/verify.d.ts +0 -39
  74. package/dist/core/verify.d.ts.map +0 -1
  75. package/dist/exports/control-adapter.d.ts +0 -2
  76. package/dist/exports/control-adapter.d.ts.map +0 -1
  77. package/dist/exports/control-adapter.js +0 -1
  78. package/dist/exports/control-adapter.js.map +0 -1
  79. package/dist/exports/control.d.ts +0 -13
  80. package/dist/exports/control.d.ts.map +0 -1
  81. package/dist/exports/control.js +0 -149
  82. package/dist/exports/control.js.map +0 -1
  83. package/dist/exports/runtime.d.ts +0 -8
  84. package/dist/exports/runtime.d.ts.map +0 -1
  85. package/dist/exports/runtime.js +0 -64
  86. package/dist/exports/runtime.js.map +0 -1
  87. package/dist/exports/schema-verify.d.ts +0 -11
  88. package/dist/exports/schema-verify.d.ts.map +0 -1
  89. package/dist/exports/schema-verify.js +0 -15
  90. package/dist/exports/schema-verify.js.map +0 -1
  91. package/dist/exports/test-utils.d.ts +0 -7
  92. package/dist/exports/test-utils.d.ts.map +0 -1
  93. package/dist/exports/test-utils.js +0 -17
  94. package/dist/exports/test-utils.js.map +0 -1
  95. package/dist/exports/verify.d.ts +0 -2
  96. package/dist/exports/verify.d.ts.map +0 -1
  97. package/dist/exports/verify.js +0 -11
  98. package/dist/exports/verify.js.map +0 -1
@@ -1,37 +1,58 @@
1
1
  import type {
2
2
  NormalizedTypeRenderer,
3
+ TargetBoundComponentDescriptor,
3
4
  TypeRenderer,
4
5
  } from '@prisma-next/contract/framework-components';
5
6
  import { normalizeRenderer } from '@prisma-next/contract/framework-components';
6
- import type { OperationManifest } from '@prisma-next/contract/pack-manifest-types';
7
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';
8
+ import type { OperationRegistry } from '@prisma-next/operations';
14
9
  import { createOperationRegistry } from '@prisma-next/operations';
10
+ import type { CodecControlHooks, SqlControlStaticContributions } from './migrations/types';
11
+
12
+ function addUniqueId(ids: string[], seen: Set<string>, id: string): void {
13
+ if (!seen.has(id)) {
14
+ ids.push(id);
15
+ seen.add(id);
16
+ }
17
+ }
18
+
19
+ function assertUniqueCodecOwner(options: {
20
+ readonly codecId: string;
21
+ readonly owners: Map<string, string>;
22
+ readonly descriptorId: string;
23
+ readonly entityLabel: string;
24
+ readonly entityOwnershipLabel: string;
25
+ }): void {
26
+ const existingOwner = options.owners.get(options.codecId);
27
+ if (existingOwner !== undefined) {
28
+ throw new Error(
29
+ `Duplicate ${options.entityLabel} for codecId "${options.codecId}". ` +
30
+ `Descriptor "${options.descriptorId}" conflicts with "${existingOwner}". ` +
31
+ `Each codecId can only have one ${options.entityOwnershipLabel}.`,
32
+ );
33
+ }
34
+ }
35
+
36
+ export interface SqlControlDescriptorWithContributions extends SqlControlStaticContributions {
37
+ readonly id: string;
38
+ readonly types?: {
39
+ readonly codecTypes?: {
40
+ readonly import?: TypesImportSpec;
41
+ readonly parameterized?: Record<string, TypeRenderer>;
42
+ readonly typeImports?: ReadonlyArray<TypesImportSpec>;
43
+ };
44
+ readonly operationTypes?: { readonly import: TypesImportSpec };
45
+ };
46
+ }
15
47
 
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
48
  export function assembleOperationRegistry(
22
- descriptors: ReadonlyArray<
23
- | ControlTargetDescriptor<'sql', string>
24
- | ControlAdapterDescriptor<'sql', string>
25
- | ControlExtensionDescriptor<'sql', string>
26
- >,
27
- convertOperationManifest: (manifest: OperationManifest) => OperationSignature,
49
+ descriptors: ReadonlyArray<SqlControlDescriptorWithContributions>,
28
50
  ): OperationRegistry {
29
51
  const registry = createOperationRegistry();
30
52
 
31
53
  for (const descriptor of descriptors) {
32
- const operations = descriptor.operations ?? [];
33
- for (const operationManifest of operations as ReadonlyArray<OperationManifest>) {
34
- const signature = convertOperationManifest(operationManifest);
54
+ const signatures = descriptor.operationSignatures();
55
+ for (const signature of signatures) {
35
56
  registry.register(signature);
36
57
  }
37
58
  }
@@ -39,15 +60,20 @@ export function assembleOperationRegistry(
39
60
  return registry;
40
61
  }
41
62
 
42
- /**
43
- * Extracts codec type imports from descriptors for contract.d.ts generation.
44
- */
63
+ interface DescriptorWithTypes {
64
+ readonly id: string;
65
+ readonly types?: {
66
+ readonly codecTypes?: {
67
+ readonly import?: TypesImportSpec;
68
+ readonly parameterized?: Record<string, TypeRenderer>;
69
+ readonly typeImports?: ReadonlyArray<TypesImportSpec>;
70
+ };
71
+ readonly operationTypes?: { readonly import: TypesImportSpec };
72
+ };
73
+ }
74
+
45
75
  export function extractCodecTypeImports(
46
- descriptors: ReadonlyArray<
47
- | ControlTargetDescriptor<'sql', string>
48
- | ControlAdapterDescriptor<'sql', string>
49
- | ControlExtensionDescriptor<'sql', string>
50
- >,
76
+ descriptors: ReadonlyArray<DescriptorWithTypes>,
51
77
  ): ReadonlyArray<TypesImportSpec> {
52
78
  const imports: TypesImportSpec[] = [];
53
79
 
@@ -65,15 +91,8 @@ export function extractCodecTypeImports(
65
91
  return imports;
66
92
  }
67
93
 
68
- /**
69
- * Extracts operation type imports from descriptors for contract.d.ts generation.
70
- */
71
94
  export function extractOperationTypeImports(
72
- descriptors: ReadonlyArray<
73
- | ControlTargetDescriptor<'sql', string>
74
- | ControlAdapterDescriptor<'sql', string>
75
- | ControlExtensionDescriptor<'sql', string>
76
- >,
95
+ descriptors: ReadonlyArray<DescriptorWithTypes>,
77
96
  ): ReadonlyArray<TypesImportSpec> {
78
97
  const imports: TypesImportSpec[] = [];
79
98
 
@@ -88,60 +107,29 @@ export function extractOperationTypeImports(
88
107
  return imports;
89
108
  }
90
109
 
91
- /**
92
- * Extracts extension IDs from descriptors in deterministic order:
93
- * [adapter.id, target.id, ...extensions.map(e => e.id)]
94
- * Deduplicates while preserving stable order.
95
- */
96
110
  export function extractExtensionIds(
97
- adapter: ControlAdapterDescriptor<'sql', string>,
98
- target: ControlTargetDescriptor<'sql', string>,
99
- extensions: ReadonlyArray<ControlExtensionDescriptor<'sql', string>>,
111
+ adapter: { readonly id: string },
112
+ target: { readonly id: string },
113
+ extensions: ReadonlyArray<{ readonly id: string }>,
100
114
  ): ReadonlyArray<string> {
101
115
  const ids: string[] = [];
102
116
  const seen = new Set<string>();
103
117
 
104
- // Add adapter first
105
- if (!seen.has(adapter.id)) {
106
- ids.push(adapter.id);
107
- seen.add(adapter.id);
108
- }
118
+ addUniqueId(ids, seen, adapter.id);
119
+ addUniqueId(ids, seen, target.id);
109
120
 
110
- // Add target second
111
- if (!seen.has(target.id)) {
112
- ids.push(target.id);
113
- seen.add(target.id);
114
- }
115
-
116
- // Add extensions in order
117
121
  for (const ext of extensions) {
118
- if (!seen.has(ext.id)) {
119
- ids.push(ext.id);
120
- seen.add(ext.id);
121
- }
122
+ addUniqueId(ids, seen, ext.id);
122
123
  }
123
124
 
124
125
  return ids;
125
126
  }
126
127
 
127
- /**
128
- * Extracts and normalizes parameterized codec renderers from descriptors.
129
- * Templates are compiled to functions at this layer.
130
- *
131
- * Throws an error if multiple descriptors provide a renderer for the same codecId.
132
- * This is intentional - duplicate codecId is a hard error, not a silent override.
133
- *
134
- * @returns Map from codecId to normalized renderer
135
- */
136
128
  export function extractParameterizedRenderers(
137
- descriptors: ReadonlyArray<
138
- | ControlTargetDescriptor<'sql', string>
139
- | ControlAdapterDescriptor<'sql', string>
140
- | ControlExtensionDescriptor<'sql', string>
141
- >,
129
+ descriptors: ReadonlyArray<DescriptorWithTypes>,
142
130
  ): Map<string, NormalizedTypeRenderer> {
143
131
  const renderers = new Map<string, NormalizedTypeRenderer>();
144
- const owners = new Map<string, string>(); // codecId -> descriptor.id for error messages
132
+ const owners = new Map<string, string>();
145
133
 
146
134
  for (const descriptor of descriptors) {
147
135
  const codecTypes = descriptor.types?.codecTypes;
@@ -149,15 +137,13 @@ export function extractParameterizedRenderers(
149
137
 
150
138
  const parameterized: Record<string, TypeRenderer> = codecTypes.parameterized;
151
139
  for (const [codecId, renderer] of Object.entries(parameterized)) {
152
- const existingOwner = owners.get(codecId);
153
- if (existingOwner !== undefined) {
154
- throw new Error(
155
- `Duplicate parameterized renderer for codecId "${codecId}". ` +
156
- `Descriptor "${descriptor.id}" conflicts with "${existingOwner}". ` +
157
- 'Each codecId can only have one renderer.',
158
- );
159
- }
160
-
140
+ assertUniqueCodecOwner({
141
+ codecId,
142
+ owners,
143
+ descriptorId: descriptor.id,
144
+ entityLabel: 'parameterized renderer',
145
+ entityOwnershipLabel: 'renderer',
146
+ });
161
147
  renderers.set(codecId, normalizeRenderer(codecId, renderer));
162
148
  owners.set(codecId, descriptor.id);
163
149
  }
@@ -166,18 +152,56 @@ export function extractParameterizedRenderers(
166
152
  return renderers;
167
153
  }
168
154
 
169
- /**
170
- * Extracts parameterized type imports from descriptors for contract.d.ts generation.
171
- * These are type imports needed by parameterized codec renderers.
172
- *
173
- * @returns Array of type import specs (may contain duplicates; caller should deduplicate)
174
- */
155
+ type CodecControlHooksMap = Record<string, CodecControlHooks>;
156
+
157
+ function hasCodecControlHooks(descriptor: unknown): descriptor is {
158
+ readonly id: string;
159
+ readonly types: {
160
+ readonly codecTypes: {
161
+ readonly controlPlaneHooks: CodecControlHooksMap;
162
+ };
163
+ };
164
+ } {
165
+ if (typeof descriptor !== 'object' || descriptor === null) {
166
+ return false;
167
+ }
168
+ const d = descriptor as { types?: { codecTypes?: { controlPlaneHooks?: unknown } } };
169
+ const hooks = d.types?.codecTypes?.controlPlaneHooks;
170
+ return hooks !== null && hooks !== undefined && typeof hooks === 'object';
171
+ }
172
+
173
+ export function extractCodecControlHooks(
174
+ descriptors: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>,
175
+ ): Map<string, CodecControlHooks> {
176
+ const hooks = new Map<string, CodecControlHooks>();
177
+ const owners = new Map<string, string>();
178
+
179
+ for (const descriptor of descriptors) {
180
+ if (typeof descriptor !== 'object' || descriptor === null) {
181
+ continue;
182
+ }
183
+ if (!hasCodecControlHooks(descriptor)) {
184
+ continue;
185
+ }
186
+ const controlPlaneHooks = descriptor.types.codecTypes.controlPlaneHooks;
187
+ for (const [codecId, hook] of Object.entries(controlPlaneHooks)) {
188
+ assertUniqueCodecOwner({
189
+ codecId,
190
+ owners,
191
+ descriptorId: descriptor.id,
192
+ entityLabel: 'control hooks',
193
+ entityOwnershipLabel: 'owner',
194
+ });
195
+ hooks.set(codecId, hook);
196
+ owners.set(codecId, descriptor.id);
197
+ }
198
+ }
199
+
200
+ return hooks;
201
+ }
202
+
175
203
  export function extractParameterizedTypeImports(
176
- descriptors: ReadonlyArray<
177
- | ControlTargetDescriptor<'sql', string>
178
- | ControlAdapterDescriptor<'sql', string>
179
- | ControlExtensionDescriptor<'sql', string>
180
- >,
204
+ descriptors: ReadonlyArray<DescriptorWithTypes>,
181
205
  ): ReadonlyArray<TypesImportSpec> {
182
206
  const imports: TypesImportSpec[] = [];
183
207
 
@@ -3,6 +3,7 @@ import type {
3
3
  ControlDriverInstance,
4
4
  } from '@prisma-next/core-control-plane/types';
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.
@@ -36,6 +37,20 @@ export interface SqlControlAdapter<TTarget extends string = string>
36
37
  contractIR?: unknown,
37
38
  schema?: string,
38
39
  ): Promise<SqlSchemaIR>;
40
+
41
+ /**
42
+ * Optional target-specific normalizer for raw database default expressions.
43
+ * When provided, schema defaults (raw strings) are normalized before comparison
44
+ * with contract defaults (ColumnDefault objects) during schema verification.
45
+ */
46
+ readonly normalizeDefault?: DefaultNormalizer;
47
+
48
+ /**
49
+ * Optional target-specific normalizer for schema native type names.
50
+ * When provided, schema native types (from introspection) are normalized
51
+ * before comparison with contract native types during schema verification.
52
+ */
53
+ readonly normalizeNativeType?: NativeTypeNormalizer;
39
54
  }
40
55
 
41
56
  /**
@@ -1,14 +1,16 @@
1
+ import type { TargetDescriptor } from '@prisma-next/contract/framework-components';
1
2
  import type {
2
3
  ControlFamilyDescriptor,
3
4
  ControlPlaneStack,
4
5
  } from '@prisma-next/core-control-plane/types';
5
6
  import { sqlTargetFamilyHook } from '@prisma-next/sql-contract-emitter';
6
- import { createSqlFamilyInstance, type SqlControlFamilyInstance } from './instance';
7
+ import type { SqlControlDescriptorWithContributions } from './assembly';
8
+ import { createSqlFamilyInstance, type SqlControlFamilyInstance } from './control-instance';
9
+ import type {
10
+ SqlControlAdapterDescriptor,
11
+ SqlControlExtensionDescriptor,
12
+ } from './migrations/types';
7
13
 
8
- /**
9
- * SQL family descriptor implementation.
10
- * Provides the SQL family hook and factory method.
11
- */
12
14
  export class SqlFamilyDescriptor
13
15
  implements ControlFamilyDescriptor<'sql', SqlControlFamilyInstance>
14
16
  {
@@ -21,13 +23,15 @@ export class SqlFamilyDescriptor
21
23
  create<TTargetId extends string>(
22
24
  stack: ControlPlaneStack<'sql', TTargetId>,
23
25
  ): 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.
26
+ const target = stack.target as unknown as TargetDescriptor<'sql', TTargetId> &
27
+ SqlControlDescriptorWithContributions;
28
+ const adapter = stack.adapter as unknown as SqlControlAdapterDescriptor<TTargetId>;
29
+ const extensionPacks =
30
+ stack.extensionPacks as unknown as readonly SqlControlExtensionDescriptor<TTargetId>[];
27
31
  return createSqlFamilyInstance({
28
- target: stack.target,
29
- adapter: stack.adapter,
30
- extensionPacks: stack.extensionPacks,
32
+ target,
33
+ adapter,
34
+ extensionPacks,
31
35
  });
32
36
  }
33
37
  }