@prisma-next/family-sql 0.3.0-dev.7 → 0.3.0-dev.71

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 (102) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +15 -6
  3. package/dist/assembly-BVS641kd.mjs +106 -0
  4. package/dist/assembly-BVS641kd.mjs.map +1 -0
  5. package/dist/control-adapter.d.mts +60 -0
  6. package/dist/control-adapter.d.mts.map +1 -0
  7. package/dist/control-adapter.mjs +1 -0
  8. package/dist/control-instance-62RsSxEp.d.mts +291 -0
  9. package/dist/control-instance-62RsSxEp.d.mts.map +1 -0
  10. package/dist/control.d.mts +106 -0
  11. package/dist/control.d.mts.map +1 -0
  12. package/dist/control.mjs +640 -0
  13. package/dist/control.mjs.map +1 -0
  14. package/dist/runtime.d.mts +27 -0
  15. package/dist/runtime.d.mts.map +1 -0
  16. package/dist/runtime.mjs +38 -0
  17. package/dist/runtime.mjs.map +1 -0
  18. package/dist/schema-verify.d.mts +48 -0
  19. package/dist/schema-verify.d.mts.map +1 -0
  20. package/dist/schema-verify.mjs +4 -0
  21. package/dist/test-utils.d.mts +2 -0
  22. package/dist/test-utils.mjs +3 -0
  23. package/dist/verify-BfMETJcM.mjs +108 -0
  24. package/dist/verify-BfMETJcM.mjs.map +1 -0
  25. package/dist/verify-sql-schema-CpAVEi8A.mjs +1058 -0
  26. package/dist/verify-sql-schema-CpAVEi8A.mjs.map +1 -0
  27. package/dist/verify-sql-schema-DhHnkpPa.d.mts +67 -0
  28. package/dist/verify-sql-schema-DhHnkpPa.d.mts.map +1 -0
  29. package/dist/verify.d.mts +31 -0
  30. package/dist/verify.d.mts.map +1 -0
  31. package/dist/verify.mjs +3 -0
  32. package/package.json +36 -47
  33. package/src/core/assembly.ts +158 -59
  34. package/src/core/control-adapter.ts +15 -0
  35. package/src/core/control-descriptor.ts +37 -0
  36. package/src/core/{instance.ts → control-instance.ts} +108 -241
  37. package/src/core/migrations/contract-to-schema-ir.ts +181 -0
  38. package/src/core/migrations/types.ts +63 -165
  39. package/src/core/runtime-descriptor.ts +19 -41
  40. package/src/core/runtime-instance.ts +11 -133
  41. package/src/core/schema-verify/verify-helpers.ts +187 -97
  42. package/src/core/schema-verify/verify-sql-schema.ts +910 -392
  43. package/src/core/verify.ts +4 -13
  44. package/src/exports/control.ts +15 -6
  45. package/src/exports/runtime.ts +2 -6
  46. package/src/exports/schema-verify.ts +10 -2
  47. package/src/exports/test-utils.ts +0 -1
  48. package/dist/chunk-6K3RPBDP.js +0 -580
  49. package/dist/chunk-6K3RPBDP.js.map +0 -1
  50. package/dist/chunk-BHEGVBY7.js +0 -772
  51. package/dist/chunk-BHEGVBY7.js.map +0 -1
  52. package/dist/chunk-SU7LN2UH.js +0 -96
  53. package/dist/chunk-SU7LN2UH.js.map +0 -1
  54. package/dist/core/assembly.d.ts +0 -25
  55. package/dist/core/assembly.d.ts.map +0 -1
  56. package/dist/core/control-adapter.d.ts +0 -42
  57. package/dist/core/control-adapter.d.ts.map +0 -1
  58. package/dist/core/descriptor.d.ts +0 -31
  59. package/dist/core/descriptor.d.ts.map +0 -1
  60. package/dist/core/instance.d.ts +0 -142
  61. package/dist/core/instance.d.ts.map +0 -1
  62. package/dist/core/migrations/plan-helpers.d.ts +0 -20
  63. package/dist/core/migrations/plan-helpers.d.ts.map +0 -1
  64. package/dist/core/migrations/policies.d.ts +0 -6
  65. package/dist/core/migrations/policies.d.ts.map +0 -1
  66. package/dist/core/migrations/types.d.ts +0 -280
  67. package/dist/core/migrations/types.d.ts.map +0 -1
  68. package/dist/core/runtime-descriptor.d.ts +0 -19
  69. package/dist/core/runtime-descriptor.d.ts.map +0 -1
  70. package/dist/core/runtime-instance.d.ts +0 -54
  71. package/dist/core/runtime-instance.d.ts.map +0 -1
  72. package/dist/core/schema-verify/verify-helpers.d.ts +0 -50
  73. package/dist/core/schema-verify/verify-helpers.d.ts.map +0 -1
  74. package/dist/core/schema-verify/verify-sql-schema.d.ts +0 -45
  75. package/dist/core/schema-verify/verify-sql-schema.d.ts.map +0 -1
  76. package/dist/core/verify.d.ts +0 -39
  77. package/dist/core/verify.d.ts.map +0 -1
  78. package/dist/exports/control-adapter.d.ts +0 -2
  79. package/dist/exports/control-adapter.d.ts.map +0 -1
  80. package/dist/exports/control-adapter.js +0 -1
  81. package/dist/exports/control-adapter.js.map +0 -1
  82. package/dist/exports/control.d.ts +0 -13
  83. package/dist/exports/control.d.ts.map +0 -1
  84. package/dist/exports/control.js +0 -149
  85. package/dist/exports/control.js.map +0 -1
  86. package/dist/exports/runtime.d.ts +0 -8
  87. package/dist/exports/runtime.d.ts.map +0 -1
  88. package/dist/exports/runtime.js +0 -64
  89. package/dist/exports/runtime.js.map +0 -1
  90. package/dist/exports/schema-verify.d.ts +0 -11
  91. package/dist/exports/schema-verify.d.ts.map +0 -1
  92. package/dist/exports/schema-verify.js +0 -11
  93. package/dist/exports/schema-verify.js.map +0 -1
  94. package/dist/exports/test-utils.d.ts +0 -7
  95. package/dist/exports/test-utils.d.ts.map +0 -1
  96. package/dist/exports/test-utils.js +0 -17
  97. package/dist/exports/test-utils.js.map +0 -1
  98. package/dist/exports/verify.d.ts +0 -2
  99. package/dist/exports/verify.d.ts.map +0 -1
  100. package/dist/exports/verify.js +0 -11
  101. package/dist/exports/verify.js.map +0 -1
  102. package/src/core/descriptor.ts +0 -37
@@ -1,32 +1,58 @@
1
- import type { OperationManifest } from '@prisma-next/contract/pack-manifest-types';
2
- import type { TypesImportSpec } from '@prisma-next/contract/types';
3
1
  import type {
4
- ControlAdapterDescriptor,
5
- ControlExtensionDescriptor,
6
- ControlTargetDescriptor,
7
- } from '@prisma-next/core-control-plane/types';
8
- import type { OperationRegistry, OperationSignature } from '@prisma-next/operations';
2
+ NormalizedTypeRenderer,
3
+ TargetBoundComponentDescriptor,
4
+ TypeRenderer,
5
+ } from '@prisma-next/contract/framework-components';
6
+ import { normalizeRenderer } from '@prisma-next/contract/framework-components';
7
+ import type { TypesImportSpec } from '@prisma-next/contract/types';
8
+ import type { OperationRegistry } from '@prisma-next/operations';
9
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
+ }
10
47
 
11
- /**
12
- * Assembles an operation registry from descriptors (adapter, target, extensions).
13
- * Loops over descriptors, extracts operations, converts them using the provided
14
- * conversion function, and registers them in a new registry.
15
- */
16
48
  export function assembleOperationRegistry(
17
- descriptors: ReadonlyArray<
18
- | ControlTargetDescriptor<'sql', string>
19
- | ControlAdapterDescriptor<'sql', string>
20
- | ControlExtensionDescriptor<'sql', string>
21
- >,
22
- convertOperationManifest: (manifest: OperationManifest) => OperationSignature,
49
+ descriptors: ReadonlyArray<SqlControlDescriptorWithContributions>,
23
50
  ): OperationRegistry {
24
51
  const registry = createOperationRegistry();
25
52
 
26
53
  for (const descriptor of descriptors) {
27
- const operations = descriptor.operations ?? [];
28
- for (const operationManifest of operations as ReadonlyArray<OperationManifest>) {
29
- const signature = convertOperationManifest(operationManifest);
54
+ const signatures = descriptor.operationSignatures();
55
+ for (const signature of signatures) {
30
56
  registry.register(signature);
31
57
  }
32
58
  }
@@ -34,15 +60,20 @@ export function assembleOperationRegistry(
34
60
  return registry;
35
61
  }
36
62
 
37
- /**
38
- * Extracts codec type imports from descriptors for contract.d.ts generation.
39
- */
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
+
40
75
  export function extractCodecTypeImports(
41
- descriptors: ReadonlyArray<
42
- | ControlTargetDescriptor<'sql', string>
43
- | ControlAdapterDescriptor<'sql', string>
44
- | ControlExtensionDescriptor<'sql', string>
45
- >,
76
+ descriptors: ReadonlyArray<DescriptorWithTypes>,
46
77
  ): ReadonlyArray<TypesImportSpec> {
47
78
  const imports: TypesImportSpec[] = [];
48
79
 
@@ -52,20 +83,16 @@ export function extractCodecTypeImports(
52
83
  if (codecTypes?.import) {
53
84
  imports.push(codecTypes.import);
54
85
  }
86
+ if (codecTypes?.typeImports) {
87
+ imports.push(...codecTypes.typeImports);
88
+ }
55
89
  }
56
90
 
57
91
  return imports;
58
92
  }
59
93
 
60
- /**
61
- * Extracts operation type imports from descriptors for contract.d.ts generation.
62
- */
63
94
  export function extractOperationTypeImports(
64
- descriptors: ReadonlyArray<
65
- | ControlTargetDescriptor<'sql', string>
66
- | ControlAdapterDescriptor<'sql', string>
67
- | ControlExtensionDescriptor<'sql', string>
68
- >,
95
+ descriptors: ReadonlyArray<DescriptorWithTypes>,
69
96
  ): ReadonlyArray<TypesImportSpec> {
70
97
  const imports: TypesImportSpec[] = [];
71
98
 
@@ -80,38 +107,110 @@ export function extractOperationTypeImports(
80
107
  return imports;
81
108
  }
82
109
 
83
- /**
84
- * Extracts extension IDs from descriptors in deterministic order:
85
- * [adapter.id, target.id, ...extensions.map(e => e.id)]
86
- * Deduplicates while preserving stable order.
87
- */
88
110
  export function extractExtensionIds(
89
- adapter: ControlAdapterDescriptor<'sql', string>,
90
- target: ControlTargetDescriptor<'sql', string>,
91
- extensions: ReadonlyArray<ControlExtensionDescriptor<'sql', string>>,
111
+ adapter: { readonly id: string },
112
+ target: { readonly id: string },
113
+ extensions: ReadonlyArray<{ readonly id: string }>,
92
114
  ): ReadonlyArray<string> {
93
115
  const ids: string[] = [];
94
116
  const seen = new Set<string>();
95
117
 
96
- // Add adapter first
97
- if (!seen.has(adapter.id)) {
98
- ids.push(adapter.id);
99
- seen.add(adapter.id);
118
+ addUniqueId(ids, seen, adapter.id);
119
+ addUniqueId(ids, seen, target.id);
120
+
121
+ for (const ext of extensions) {
122
+ addUniqueId(ids, seen, ext.id);
123
+ }
124
+
125
+ return ids;
126
+ }
127
+
128
+ export function extractParameterizedRenderers(
129
+ descriptors: ReadonlyArray<DescriptorWithTypes>,
130
+ ): Map<string, NormalizedTypeRenderer> {
131
+ const renderers = new Map<string, NormalizedTypeRenderer>();
132
+ const owners = new Map<string, string>();
133
+
134
+ for (const descriptor of descriptors) {
135
+ const codecTypes = descriptor.types?.codecTypes;
136
+ if (!codecTypes?.parameterized) continue;
137
+
138
+ const parameterized: Record<string, TypeRenderer> = codecTypes.parameterized;
139
+ for (const [codecId, renderer] of Object.entries(parameterized)) {
140
+ assertUniqueCodecOwner({
141
+ codecId,
142
+ owners,
143
+ descriptorId: descriptor.id,
144
+ entityLabel: 'parameterized renderer',
145
+ entityOwnershipLabel: 'renderer',
146
+ });
147
+ renderers.set(codecId, normalizeRenderer(codecId, renderer));
148
+ owners.set(codecId, descriptor.id);
149
+ }
100
150
  }
101
151
 
102
- // Add target second
103
- if (!seen.has(target.id)) {
104
- ids.push(target.id);
105
- seen.add(target.id);
152
+ return renderers;
153
+ }
154
+
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;
106
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
+ }
107
172
 
108
- // Add extensions in order
109
- for (const ext of extensions) {
110
- if (!seen.has(ext.id)) {
111
- ids.push(ext.id);
112
- seen.add(ext.id);
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);
113
197
  }
114
198
  }
115
199
 
116
- return ids;
200
+ return hooks;
201
+ }
202
+
203
+ export function extractParameterizedTypeImports(
204
+ descriptors: ReadonlyArray<DescriptorWithTypes>,
205
+ ): ReadonlyArray<TypesImportSpec> {
206
+ const imports: TypesImportSpec[] = [];
207
+
208
+ for (const descriptor of descriptors) {
209
+ const typeImports = descriptor.types?.codecTypes?.typeImports;
210
+ if (typeImports) {
211
+ imports.push(...typeImports);
212
+ }
213
+ }
214
+
215
+ return imports;
117
216
  }
@@ -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
  /**
@@ -0,0 +1,37 @@
1
+ import type { TargetDescriptor } from '@prisma-next/contract/framework-components';
2
+ import type {
3
+ ControlFamilyDescriptor,
4
+ ControlPlaneStack,
5
+ } from '@prisma-next/core-control-plane/types';
6
+ import { sqlTargetFamilyHook } from '@prisma-next/sql-contract-emitter';
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';
13
+
14
+ export class SqlFamilyDescriptor
15
+ implements ControlFamilyDescriptor<'sql', SqlControlFamilyInstance>
16
+ {
17
+ readonly kind = 'family' as const;
18
+ readonly id = 'sql';
19
+ readonly familyId = 'sql' as const;
20
+ readonly version = '0.0.1';
21
+ readonly hook = sqlTargetFamilyHook;
22
+
23
+ create<TTargetId extends string>(
24
+ stack: ControlPlaneStack<'sql', TTargetId>,
25
+ ): SqlControlFamilyInstance {
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>[];
31
+ return createSqlFamilyInstance({
32
+ target,
33
+ adapter,
34
+ extensionPacks,
35
+ });
36
+ }
37
+ }