@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
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [2026] [Prisma Data, Inc]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -16,6 +16,14 @@ Provides the SQL family descriptor (`ControlFamilyDescriptor`) that includes:
16
16
  - **Family Hook Integration**: Integrates the SQL target family hook (`sqlTargetFamilyHook`) from `@prisma-next/sql-contract-emitter`
17
17
  - **Control Plane Entry Point**: Serves as the control plane entry point for the SQL family, enabling the CLI to select the family hook and create family instances
18
18
  - **Component Database Dependencies**: Consumes database dependencies declared by framework components (target/adapter/extension packs). Callers pass the active `frameworkComponents` list into planning/execution/verification; SQL layers structurally narrow to components that declare `databaseDependencies` and use their pure verification hooks (no fuzzy matching against `contract.extensionPacks`).
19
+ - **Contract-to-SchemaIR Conversion**: Converts `SqlStorage` from a contract into `SqlSchemaIR` for offline migration planning, enabling `migration plan` to work without a database connection
20
+ - **Destructive Change Detection**: Compares two `SqlStorage` values and identifies destructive changes (dropped tables/columns) for migration policy enforcement
21
+ - **Storage Type Control Hooks**: Extracts codec-owned control hooks for planning/verification/introspection of `storage.types` without adding enum-specific fields to shared IR
22
+ - **Codec Ownership**: Enforces a single owner per `codecId` for parameterized renderers and control-plane hooks to prevent ambiguous conflicts during assembly
23
+ - **Parameterized Type Verification**: Expands contract `typeParams` into expected native type strings during schema verification and flags missing parameters as type mismatches
24
+ - **Schema Defaults Policy**: Ignores execution mutation defaults during schema verification since they are applied before DB writes
25
+ - **Foreign Key Config Awareness**: Schema verification respects the contract's `foreignKeys` configuration — when `foreignKeys.constraints` is `false`, FK constraint checks are skipped during verification (see [ADR 161](../../../docs/architecture%20docs/adrs/ADR%20161%20-%20Explicit%20foreign%20key%20constraint%20and%20index%20configuration.md))
26
+ - **Referential Action Verification**: When a contract FK specifies `onDelete` or `onUpdate`, the verifier compares them against the introspected schema and reports `foreign_key_mismatch` on mismatch (see [ADR 166](../../../docs/architecture%20docs/adrs/ADR%20166%20-%20Referential%20actions%20for%20foreign%20keys.md))
19
27
 
20
28
  ## Usage
21
29
 
@@ -82,7 +90,7 @@ The framework CLI uses this descriptor to:
82
90
 
83
91
  Family instances implement domain actions:
84
92
  - **`validateContractIR(contractJson)`**: Validates and normalizes contract, returns ContractIR without mappings
85
- - **`verify()`**: Verifies database marker against contract (compares target, coreHash, profileHash)
93
+ - **`verify()`**: Verifies database marker against contract (compares target, storageHash, profileHash)
86
94
  - **`schemaVerify()`**: Verifies database schema against contract (compares contract requirements vs live schema)
87
95
  - **`introspect()`**: Introspects database schema and returns `SqlSchemaIR`
88
96
  - **`toSchemaView(schema)`**: Projects `SqlSchemaIR` into `CoreSchemaView` for human-readable display. Always displays native database types (e.g., `int4`, `text`) rather than mapped codec IDs (e.g., `pg/int4@1`) to reflect actual database state.
@@ -92,12 +100,13 @@ The descriptor is "pure data + factory" - it only provides the hook and factory
92
100
 
93
101
  ## Package Structure
94
102
 
95
- - **`src/core/descriptor.ts`**: `SqlFamilyDescriptor` class implementing `ControlFamilyDescriptor` interface (pure data + factory)
96
- - **`src/core/instance.ts`**: `createSqlFamilyInstance` function that creates `SqlFamilyInstance` with domain action methods (`validateContractIR`, `verify`, `schemaVerify`, `introspect`, `toSchemaView`, `emitContract`). Contains `convertOperationManifest` function used internally by instance creation and test utilities in the same package.
97
- - **`src/core/assembly.ts`**: Assembly helpers for building operation registries and extracting type imports from descriptors. Test utilities import `convertOperationManifest` from the same package via relative path.
103
+ - **`src/core/control-descriptor.ts`**: `SqlFamilyDescriptor` class implementing `ControlFamilyDescriptor` interface (pure data + factory)
104
+ - **`src/core/control-instance.ts`**: `createSqlFamilyInstance` function that creates `SqlFamilyInstance` with domain action methods (`validateContractIR`, `verify`, `schemaVerify`, `introspect`, `toSchemaView`, `emitContract`). Contains `convertOperationManifest` function used internally by instance creation and test utilities in the same package.
105
+ - **`src/core/assembly.ts`**: Assembly helpers for building operation registries, extracting type imports, and collecting codec-owned storage type control hooks. Test utilities import `convertOperationManifest` from the same package via relative path.
98
106
  - **`src/core/verify.ts`**: Verification helpers (`readMarker`, `collectSupportedCodecTypeIds`)
99
107
  - **`src/core/control-adapter.ts`**: SQL control adapter interface (`SqlControlAdapter`) for control-plane operations
100
108
  - **`src/core/migrations/`**: Migration IR helpers plus planner and runner SPI types (`MigrationPlanner`, `MigrationRunner`, `SqlControlTargetDescriptor`). Runners return `MigrationRunnerResult` which is a union of success/failure.
109
+ - **`src/core/migrations/contract-to-schema-ir.ts`**: `contractToSchemaIR(storage)` converts a contract's `SqlStorage` to `SqlSchemaIR` for offline migration planning (used by `migration plan` to synthesize the "from" schema without a database connection). Also exports `detectDestructiveChanges(from, to)` which compares two `SqlStorage` values and returns a list of destructive changes (dropped tables, dropped columns) for migration policy enforcement.
101
110
 
102
111
  ### Migration Runner Error Codes
103
112
 
@@ -111,13 +120,13 @@ The runner returns structured errors with the following codes:
111
120
  - **`SCHEMA_VERIFY_FAILED`**: Resulting schema doesn't satisfy the destination contract
112
121
  - **`EXECUTION_FAILED`**: SQL execution error during operation execution
113
122
  - **`src/exports/control.ts`**: Control plane entry point (exports `SqlFamilyDescriptor` instance)
114
- - **`src/exports/runtime.ts`**: Runtime entry point (placeholder for future functionality)
123
+ - **`src/exports/runtime.ts`**: Runtime plane entry point
115
124
 
116
125
  ## Entrypoints
117
126
 
118
127
  - **`./control`**: Control plane entry point for CLI/config usage (exports `SqlFamilyDescriptor`)
119
128
  - **`./control-adapter`**: SQL control adapter interface (`SqlControlAdapter`, `SqlControlAdapterDescriptor`) for target-specific adapters
120
- - **`./runtime`**: Runtime entry point (placeholder for future functionality)
129
+ - **`./runtime`**: Runtime plane identity exports only (family ID, types, descriptor identity). Does **not** export runtime creation helpers—use `createExecutionStack`, `instantiateExecutionStack` from `@prisma-next/core-execution-plane/stack` and `createExecutionContext`, `createRuntime` from `@prisma-next/sql-runtime`. See [ADR 152](../../../docs/architecture%20docs/adrs/ADR%20152%20-%20Execution%20Plane%20Descriptors%20and%20Instances.md).
121
130
  - **`./verify`**: Verification utilities (`readMarker`, `readMarkerSql`, `parseContractMarkerRow`) for reading contract markers from databases
122
131
 
123
132
  ## Dependencies
@@ -0,0 +1,106 @@
1
+ import { normalizeRenderer } from "@prisma-next/contract/framework-components";
2
+ import { createOperationRegistry } from "@prisma-next/operations";
3
+
4
+ //#region src/core/assembly.ts
5
+ function addUniqueId(ids, seen, id) {
6
+ if (!seen.has(id)) {
7
+ ids.push(id);
8
+ seen.add(id);
9
+ }
10
+ }
11
+ function assertUniqueCodecOwner(options) {
12
+ const existingOwner = options.owners.get(options.codecId);
13
+ if (existingOwner !== void 0) throw new Error(`Duplicate ${options.entityLabel} for codecId "${options.codecId}". Descriptor "${options.descriptorId}" conflicts with "${existingOwner}". Each codecId can only have one ${options.entityOwnershipLabel}.`);
14
+ }
15
+ function assembleOperationRegistry(descriptors) {
16
+ const registry = createOperationRegistry();
17
+ for (const descriptor of descriptors) {
18
+ const signatures = descriptor.operationSignatures();
19
+ for (const signature of signatures) registry.register(signature);
20
+ }
21
+ return registry;
22
+ }
23
+ function extractCodecTypeImports(descriptors) {
24
+ const imports = [];
25
+ for (const descriptor of descriptors) {
26
+ const codecTypes = descriptor.types?.codecTypes;
27
+ if (codecTypes?.import) imports.push(codecTypes.import);
28
+ if (codecTypes?.typeImports) imports.push(...codecTypes.typeImports);
29
+ }
30
+ return imports;
31
+ }
32
+ function extractOperationTypeImports(descriptors) {
33
+ const imports = [];
34
+ for (const descriptor of descriptors) {
35
+ const operationTypes = descriptor.types?.operationTypes;
36
+ if (operationTypes?.import) imports.push(operationTypes.import);
37
+ }
38
+ return imports;
39
+ }
40
+ function extractExtensionIds(adapter, target, extensions) {
41
+ const ids = [];
42
+ const seen = /* @__PURE__ */ new Set();
43
+ addUniqueId(ids, seen, adapter.id);
44
+ addUniqueId(ids, seen, target.id);
45
+ for (const ext of extensions) addUniqueId(ids, seen, ext.id);
46
+ return ids;
47
+ }
48
+ function extractParameterizedRenderers(descriptors) {
49
+ const renderers = /* @__PURE__ */ new Map();
50
+ const owners = /* @__PURE__ */ new Map();
51
+ for (const descriptor of descriptors) {
52
+ const codecTypes = descriptor.types?.codecTypes;
53
+ if (!codecTypes?.parameterized) continue;
54
+ const parameterized = codecTypes.parameterized;
55
+ for (const [codecId, renderer] of Object.entries(parameterized)) {
56
+ assertUniqueCodecOwner({
57
+ codecId,
58
+ owners,
59
+ descriptorId: descriptor.id,
60
+ entityLabel: "parameterized renderer",
61
+ entityOwnershipLabel: "renderer"
62
+ });
63
+ renderers.set(codecId, normalizeRenderer(codecId, renderer));
64
+ owners.set(codecId, descriptor.id);
65
+ }
66
+ }
67
+ return renderers;
68
+ }
69
+ function hasCodecControlHooks(descriptor) {
70
+ if (typeof descriptor !== "object" || descriptor === null) return false;
71
+ const hooks = descriptor.types?.codecTypes?.controlPlaneHooks;
72
+ return hooks !== null && hooks !== void 0 && typeof hooks === "object";
73
+ }
74
+ function extractCodecControlHooks(descriptors) {
75
+ const hooks = /* @__PURE__ */ new Map();
76
+ const owners = /* @__PURE__ */ new Map();
77
+ for (const descriptor of descriptors) {
78
+ if (typeof descriptor !== "object" || descriptor === null) continue;
79
+ if (!hasCodecControlHooks(descriptor)) continue;
80
+ const controlPlaneHooks = descriptor.types.codecTypes.controlPlaneHooks;
81
+ for (const [codecId, hook] of Object.entries(controlPlaneHooks)) {
82
+ assertUniqueCodecOwner({
83
+ codecId,
84
+ owners,
85
+ descriptorId: descriptor.id,
86
+ entityLabel: "control hooks",
87
+ entityOwnershipLabel: "owner"
88
+ });
89
+ hooks.set(codecId, hook);
90
+ owners.set(codecId, descriptor.id);
91
+ }
92
+ }
93
+ return hooks;
94
+ }
95
+ function extractParameterizedTypeImports(descriptors) {
96
+ const imports = [];
97
+ for (const descriptor of descriptors) {
98
+ const typeImports = descriptor.types?.codecTypes?.typeImports;
99
+ if (typeImports) imports.push(...typeImports);
100
+ }
101
+ return imports;
102
+ }
103
+
104
+ //#endregion
105
+ export { extractOperationTypeImports as a, extractExtensionIds as i, extractCodecControlHooks as n, extractParameterizedRenderers as o, extractCodecTypeImports as r, extractParameterizedTypeImports as s, assembleOperationRegistry as t };
106
+ //# sourceMappingURL=assembly-BVS641kd.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assembly-BVS641kd.mjs","names":["imports: TypesImportSpec[]","ids: string[]","parameterized: Record<string, TypeRenderer>"],"sources":["../src/core/assembly.ts"],"sourcesContent":["import type {\n NormalizedTypeRenderer,\n TargetBoundComponentDescriptor,\n TypeRenderer,\n} from '@prisma-next/contract/framework-components';\nimport { normalizeRenderer } from '@prisma-next/contract/framework-components';\nimport type { TypesImportSpec } from '@prisma-next/contract/types';\nimport type { OperationRegistry } from '@prisma-next/operations';\nimport { createOperationRegistry } from '@prisma-next/operations';\nimport type { CodecControlHooks, SqlControlStaticContributions } from './migrations/types';\n\nfunction addUniqueId(ids: string[], seen: Set<string>, id: string): void {\n if (!seen.has(id)) {\n ids.push(id);\n seen.add(id);\n }\n}\n\nfunction assertUniqueCodecOwner(options: {\n readonly codecId: string;\n readonly owners: Map<string, string>;\n readonly descriptorId: string;\n readonly entityLabel: string;\n readonly entityOwnershipLabel: string;\n}): void {\n const existingOwner = options.owners.get(options.codecId);\n if (existingOwner !== undefined) {\n throw new Error(\n `Duplicate ${options.entityLabel} for codecId \"${options.codecId}\". ` +\n `Descriptor \"${options.descriptorId}\" conflicts with \"${existingOwner}\". ` +\n `Each codecId can only have one ${options.entityOwnershipLabel}.`,\n );\n }\n}\n\nexport interface SqlControlDescriptorWithContributions extends SqlControlStaticContributions {\n readonly id: string;\n readonly types?: {\n readonly codecTypes?: {\n readonly import?: TypesImportSpec;\n readonly parameterized?: Record<string, TypeRenderer>;\n readonly typeImports?: ReadonlyArray<TypesImportSpec>;\n };\n readonly operationTypes?: { readonly import: TypesImportSpec };\n };\n}\n\nexport function assembleOperationRegistry(\n descriptors: ReadonlyArray<SqlControlDescriptorWithContributions>,\n): OperationRegistry {\n const registry = createOperationRegistry();\n\n for (const descriptor of descriptors) {\n const signatures = descriptor.operationSignatures();\n for (const signature of signatures) {\n registry.register(signature);\n }\n }\n\n return registry;\n}\n\ninterface DescriptorWithTypes {\n readonly id: string;\n readonly types?: {\n readonly codecTypes?: {\n readonly import?: TypesImportSpec;\n readonly parameterized?: Record<string, TypeRenderer>;\n readonly typeImports?: ReadonlyArray<TypesImportSpec>;\n };\n readonly operationTypes?: { readonly import: TypesImportSpec };\n };\n}\n\nexport function extractCodecTypeImports(\n descriptors: ReadonlyArray<DescriptorWithTypes>,\n): ReadonlyArray<TypesImportSpec> {\n const imports: TypesImportSpec[] = [];\n\n for (const descriptor of descriptors) {\n const types = descriptor.types;\n const codecTypes = types?.codecTypes;\n if (codecTypes?.import) {\n imports.push(codecTypes.import);\n }\n if (codecTypes?.typeImports) {\n imports.push(...codecTypes.typeImports);\n }\n }\n\n return imports;\n}\n\nexport function extractOperationTypeImports(\n descriptors: ReadonlyArray<DescriptorWithTypes>,\n): ReadonlyArray<TypesImportSpec> {\n const imports: TypesImportSpec[] = [];\n\n for (const descriptor of descriptors) {\n const types = descriptor.types;\n const operationTypes = types?.operationTypes;\n if (operationTypes?.import) {\n imports.push(operationTypes.import);\n }\n }\n\n return imports;\n}\n\nexport function extractExtensionIds(\n adapter: { readonly id: string },\n target: { readonly id: string },\n extensions: ReadonlyArray<{ readonly id: string }>,\n): ReadonlyArray<string> {\n const ids: string[] = [];\n const seen = new Set<string>();\n\n addUniqueId(ids, seen, adapter.id);\n addUniqueId(ids, seen, target.id);\n\n for (const ext of extensions) {\n addUniqueId(ids, seen, ext.id);\n }\n\n return ids;\n}\n\nexport function extractParameterizedRenderers(\n descriptors: ReadonlyArray<DescriptorWithTypes>,\n): Map<string, NormalizedTypeRenderer> {\n const renderers = new Map<string, NormalizedTypeRenderer>();\n const owners = new Map<string, string>();\n\n for (const descriptor of descriptors) {\n const codecTypes = descriptor.types?.codecTypes;\n if (!codecTypes?.parameterized) continue;\n\n const parameterized: Record<string, TypeRenderer> = codecTypes.parameterized;\n for (const [codecId, renderer] of Object.entries(parameterized)) {\n assertUniqueCodecOwner({\n codecId,\n owners,\n descriptorId: descriptor.id,\n entityLabel: 'parameterized renderer',\n entityOwnershipLabel: 'renderer',\n });\n renderers.set(codecId, normalizeRenderer(codecId, renderer));\n owners.set(codecId, descriptor.id);\n }\n }\n\n return renderers;\n}\n\ntype CodecControlHooksMap = Record<string, CodecControlHooks>;\n\nfunction hasCodecControlHooks(descriptor: unknown): descriptor is {\n readonly id: string;\n readonly types: {\n readonly codecTypes: {\n readonly controlPlaneHooks: CodecControlHooksMap;\n };\n };\n} {\n if (typeof descriptor !== 'object' || descriptor === null) {\n return false;\n }\n const d = descriptor as { types?: { codecTypes?: { controlPlaneHooks?: unknown } } };\n const hooks = d.types?.codecTypes?.controlPlaneHooks;\n return hooks !== null && hooks !== undefined && typeof hooks === 'object';\n}\n\nexport function extractCodecControlHooks(\n descriptors: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>,\n): Map<string, CodecControlHooks> {\n const hooks = new Map<string, CodecControlHooks>();\n const owners = new Map<string, string>();\n\n for (const descriptor of descriptors) {\n if (typeof descriptor !== 'object' || descriptor === null) {\n continue;\n }\n if (!hasCodecControlHooks(descriptor)) {\n continue;\n }\n const controlPlaneHooks = descriptor.types.codecTypes.controlPlaneHooks;\n for (const [codecId, hook] of Object.entries(controlPlaneHooks)) {\n assertUniqueCodecOwner({\n codecId,\n owners,\n descriptorId: descriptor.id,\n entityLabel: 'control hooks',\n entityOwnershipLabel: 'owner',\n });\n hooks.set(codecId, hook);\n owners.set(codecId, descriptor.id);\n }\n }\n\n return hooks;\n}\n\nexport function extractParameterizedTypeImports(\n descriptors: ReadonlyArray<DescriptorWithTypes>,\n): ReadonlyArray<TypesImportSpec> {\n const imports: TypesImportSpec[] = [];\n\n for (const descriptor of descriptors) {\n const typeImports = descriptor.types?.codecTypes?.typeImports;\n if (typeImports) {\n imports.push(...typeImports);\n }\n }\n\n return imports;\n}\n"],"mappings":";;;;AAWA,SAAS,YAAY,KAAe,MAAmB,IAAkB;AACvE,KAAI,CAAC,KAAK,IAAI,GAAG,EAAE;AACjB,MAAI,KAAK,GAAG;AACZ,OAAK,IAAI,GAAG;;;AAIhB,SAAS,uBAAuB,SAMvB;CACP,MAAM,gBAAgB,QAAQ,OAAO,IAAI,QAAQ,QAAQ;AACzD,KAAI,kBAAkB,OACpB,OAAM,IAAI,MACR,aAAa,QAAQ,YAAY,gBAAgB,QAAQ,QAAQ,iBAChD,QAAQ,aAAa,oBAAoB,cAAc,oCACpC,QAAQ,qBAAqB,GAClE;;AAgBL,SAAgB,0BACd,aACmB;CACnB,MAAM,WAAW,yBAAyB;AAE1C,MAAK,MAAM,cAAc,aAAa;EACpC,MAAM,aAAa,WAAW,qBAAqB;AACnD,OAAK,MAAM,aAAa,WACtB,UAAS,SAAS,UAAU;;AAIhC,QAAO;;AAeT,SAAgB,wBACd,aACgC;CAChC,MAAMA,UAA6B,EAAE;AAErC,MAAK,MAAM,cAAc,aAAa;EAEpC,MAAM,aADQ,WAAW,OACC;AAC1B,MAAI,YAAY,OACd,SAAQ,KAAK,WAAW,OAAO;AAEjC,MAAI,YAAY,YACd,SAAQ,KAAK,GAAG,WAAW,YAAY;;AAI3C,QAAO;;AAGT,SAAgB,4BACd,aACgC;CAChC,MAAMA,UAA6B,EAAE;AAErC,MAAK,MAAM,cAAc,aAAa;EAEpC,MAAM,iBADQ,WAAW,OACK;AAC9B,MAAI,gBAAgB,OAClB,SAAQ,KAAK,eAAe,OAAO;;AAIvC,QAAO;;AAGT,SAAgB,oBACd,SACA,QACA,YACuB;CACvB,MAAMC,MAAgB,EAAE;CACxB,MAAM,uBAAO,IAAI,KAAa;AAE9B,aAAY,KAAK,MAAM,QAAQ,GAAG;AAClC,aAAY,KAAK,MAAM,OAAO,GAAG;AAEjC,MAAK,MAAM,OAAO,WAChB,aAAY,KAAK,MAAM,IAAI,GAAG;AAGhC,QAAO;;AAGT,SAAgB,8BACd,aACqC;CACrC,MAAM,4BAAY,IAAI,KAAqC;CAC3D,MAAM,yBAAS,IAAI,KAAqB;AAExC,MAAK,MAAM,cAAc,aAAa;EACpC,MAAM,aAAa,WAAW,OAAO;AACrC,MAAI,CAAC,YAAY,cAAe;EAEhC,MAAMC,gBAA8C,WAAW;AAC/D,OAAK,MAAM,CAAC,SAAS,aAAa,OAAO,QAAQ,cAAc,EAAE;AAC/D,0BAAuB;IACrB;IACA;IACA,cAAc,WAAW;IACzB,aAAa;IACb,sBAAsB;IACvB,CAAC;AACF,aAAU,IAAI,SAAS,kBAAkB,SAAS,SAAS,CAAC;AAC5D,UAAO,IAAI,SAAS,WAAW,GAAG;;;AAItC,QAAO;;AAKT,SAAS,qBAAqB,YAO5B;AACA,KAAI,OAAO,eAAe,YAAY,eAAe,KACnD,QAAO;CAGT,MAAM,QADI,WACM,OAAO,YAAY;AACnC,QAAO,UAAU,QAAQ,UAAU,UAAa,OAAO,UAAU;;AAGnE,SAAgB,yBACd,aACgC;CAChC,MAAM,wBAAQ,IAAI,KAAgC;CAClD,MAAM,yBAAS,IAAI,KAAqB;AAExC,MAAK,MAAM,cAAc,aAAa;AACpC,MAAI,OAAO,eAAe,YAAY,eAAe,KACnD;AAEF,MAAI,CAAC,qBAAqB,WAAW,CACnC;EAEF,MAAM,oBAAoB,WAAW,MAAM,WAAW;AACtD,OAAK,MAAM,CAAC,SAAS,SAAS,OAAO,QAAQ,kBAAkB,EAAE;AAC/D,0BAAuB;IACrB;IACA;IACA,cAAc,WAAW;IACzB,aAAa;IACb,sBAAsB;IACvB,CAAC;AACF,SAAM,IAAI,SAAS,KAAK;AACxB,UAAO,IAAI,SAAS,WAAW,GAAG;;;AAItC,QAAO;;AAGT,SAAgB,gCACd,aACgC;CAChC,MAAMF,UAA6B,EAAE;AAErC,MAAK,MAAM,cAAc,aAAa;EACpC,MAAM,cAAc,WAAW,OAAO,YAAY;AAClD,MAAI,YACF,SAAQ,KAAK,GAAG,YAAY;;AAIhC,QAAO"}
@@ -0,0 +1,60 @@
1
+ import { n as NativeTypeNormalizer, t as DefaultNormalizer } from "./verify-sql-schema-DhHnkpPa.mjs";
2
+ import { ControlAdapterInstance, ControlDriverInstance } from "@prisma-next/core-control-plane/types";
3
+ import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
4
+
5
+ //#region src/core/control-adapter.d.ts
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
+ interface SqlControlAdapter<TTarget extends string = string> extends ControlAdapterInstance<'sql', TTarget> {
14
+ /**
15
+ * The target ID this adapter implements.
16
+ * Used for type tracking and runtime validation.
17
+ * @deprecated Use targetId from ControlAdapterInstance instead
18
+ */
19
+ readonly target: TTarget;
20
+ /**
21
+ * Introspects a database schema and returns a raw SqlSchemaIR.
22
+ *
23
+ * This is a pure schema discovery operation that queries the database catalog
24
+ * and returns the schema structure without type mapping or contract enrichment.
25
+ * Type mapping and enrichment are handled separately by enrichment helpers.
26
+ *
27
+ * @param driver - ControlDriverInstance instance for executing queries (target-specific)
28
+ * @param contractIR - Optional contract IR for contract-guided introspection (filtering, optimization)
29
+ * @param schema - Schema name to introspect (defaults to 'public')
30
+ * @returns Promise resolving to SqlSchemaIR representing the live database schema
31
+ */
32
+ introspect(driver: ControlDriverInstance<'sql', TTarget>, contractIR?: unknown, schema?: string): Promise<SqlSchemaIR>;
33
+ /**
34
+ * Optional target-specific normalizer for raw database default expressions.
35
+ * When provided, schema defaults (raw strings) are normalized before comparison
36
+ * with contract defaults (ColumnDefault objects) during schema verification.
37
+ */
38
+ readonly normalizeDefault?: DefaultNormalizer;
39
+ /**
40
+ * Optional target-specific normalizer for schema native type names.
41
+ * When provided, schema native types (from introspection) are normalized
42
+ * before comparison with contract native types during schema verification.
43
+ */
44
+ readonly normalizeNativeType?: NativeTypeNormalizer;
45
+ }
46
+ /**
47
+ * SQL control adapter descriptor interface.
48
+ * Provides a factory method to create control adapter instances.
49
+ *
50
+ * @template TTarget - The target ID (e.g., 'postgres', 'mysql')
51
+ */
52
+ interface SqlControlAdapterDescriptor<TTarget extends string = string> {
53
+ /**
54
+ * Creates a SQL control adapter instance for control-plane operations.
55
+ */
56
+ create(): SqlControlAdapter<TTarget>;
57
+ }
58
+ //#endregion
59
+ export { type SqlControlAdapter, type SqlControlAdapterDescriptor };
60
+ //# sourceMappingURL=control-adapter.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control-adapter.d.mts","names":[],"sources":["../src/core/control-adapter.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAaA;;;;AAsBY,UAtBK,iBAsBL,CAAA,gBAAA,MAAA,GAAA,MAAA,CAAA,SArBF,sBAqBE,CAAA,KAAA,EArB4B,OAqB5B,CAAA,CAAA;EAGC;;;;;EAxBmB,SAAA,MAAA,EAMb,OANa;EA+Cf;;;;;;;;;;;;qBA1BL,6BAA6B,kDAGpC,QAAQ;;;;;;8BAOiB;;;;;;iCAOG;;;;;;;;UAShB;;;;YAIL,kBAAkB"}
@@ -0,0 +1 @@
1
+ export { };