@prisma-next/family-sql 0.3.0-dev.55 → 0.3.0-dev.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE 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,8 @@ 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
19
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
20
22
  - **Codec Ownership**: Enforces a single owner per `codecId` for parameterized renderers and control-plane hooks to prevent ambiguous conflicts during assembly
21
23
  - **Parameterized Type Verification**: Expands contract `typeParams` into expected native type strings during schema verification and flags missing parameters as type mismatches
@@ -104,6 +106,7 @@ The descriptor is "pure data + factory" - it only provides the hook and factory
104
106
  - **`src/core/verify.ts`**: Verification helpers (`readMarker`, `collectSupportedCodecTypeIds`)
105
107
  - **`src/core/control-adapter.ts`**: SQL control adapter interface (`SqlControlAdapter`) for control-plane operations
106
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.
107
110
 
108
111
  ### Migration Runner Error Codes
109
112
 
@@ -1,8 +1,10 @@
1
1
  import { A as SqlMigrationRunnerFailure, C as SqlMigrationPlanOperationTarget, D as SqlMigrationRunnerErrorCode, E as SqlMigrationRunner, F as SqlPlannerConflictLocation, I as SqlPlannerFailureResult, L as SqlPlannerResult, M as SqlMigrationRunnerSuccessValue, N as SqlPlannerConflict, O as SqlMigrationRunnerExecuteCallbacks, P as SqlPlannerConflictKind, R as SqlPlannerSuccessResult, S as SqlMigrationPlanOperationStep, T as SqlMigrationPlannerPlanOptions, _ as SqlControlStaticContributions, a as extractCodecControlHooks, b as SqlMigrationPlanContractInfo, d as ComponentDatabaseDependencies, f as ComponentDatabaseDependency, g as SqlControlExtensionDescriptor, h as SqlControlAdapterDescriptor, j as SqlMigrationRunnerResult, k as SqlMigrationRunnerExecuteOptions, l as AnyRecord, m as ExpandNativeTypeInput, n as SqlControlFamilyInstance, p as CreateSqlMigrationPlanOptions, r as SqlControlDescriptorWithContributions, t as SchemaVerifyOptions, u as CodecControlHooks, v as SqlControlTargetDescriptor, w as SqlMigrationPlanner, x as SqlMigrationPlanOperation, y as SqlMigrationPlan, z as StorageTypePlanResult } from "./control-instance-62RsSxEp.mjs";
2
2
  import * as _prisma_next_contract_types0 from "@prisma-next/contract/types";
3
3
  import { NotOk, Ok } from "@prisma-next/utils/result";
4
- import { ControlFamilyDescriptor, ControlPlaneStack, MigrationOperationClass, MigrationOperationPolicy, MigrationOperationPolicy as MigrationOperationPolicy$1, MigrationPlan, MigrationPlanOperation, MigrationPlanner, MigrationPlannerConflict, MigrationPlannerResult, TargetMigrationsCapability } from "@prisma-next/core-control-plane/types";
4
+ import { ControlFamilyDescriptor, ControlPlaneStack, MigrationOperationClass, MigrationOperationPolicy, MigrationOperationPolicy as MigrationOperationPolicy$1, MigrationPlan, MigrationPlanOperation, MigrationPlanner, MigrationPlannerConflict, MigrationPlannerConflict as MigrationPlannerConflict$1, MigrationPlannerResult, TargetMigrationsCapability } from "@prisma-next/core-control-plane/types";
5
+ import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
5
6
  import * as _prisma_next_sql_contract_types0 from "@prisma-next/sql-contract/types";
7
+ import { SqlStorage } from "@prisma-next/sql-contract/types";
6
8
  import * as _prisma_next_contract_ir0 from "@prisma-next/contract/ir";
7
9
 
8
10
  //#region src/core/control-descriptor.d.ts
@@ -32,6 +34,46 @@ declare class SqlFamilyDescriptor implements ControlFamilyDescriptor<'sql', SqlC
32
34
  create<TTargetId extends string>(stack: ControlPlaneStack<'sql', TTargetId>): SqlControlFamilyInstance;
33
35
  }
34
36
  //#endregion
37
+ //#region src/core/migrations/contract-to-schema-ir.d.ts
38
+ /**
39
+ * Target-specific callback that expands a column's base `nativeType` and optional
40
+ * `typeParams` into the fully-qualified type string used by the database
41
+ * (e.g. `character` + `{ length: 36 }` → `character(36)`).
42
+ *
43
+ * This lives in the family layer as a callback rather than importing a concrete
44
+ * implementation because each target (Postgres, MySQL, SQLite, …) has its own
45
+ * parameterization syntax. The target wires its expander when calling
46
+ * `contractToSchemaIR`, keeping the family layer target-agnostic.
47
+ */
48
+ type NativeTypeExpander = (input: {
49
+ readonly nativeType: string;
50
+ readonly codecId?: string;
51
+ readonly typeParams?: Record<string, unknown>;
52
+ }) => string;
53
+ /**
54
+ * Detects destructive changes between two contract storages.
55
+ *
56
+ * The additive-only planner silently ignores removals (tables, columns).
57
+ * This function detects those removals so callers can report them as conflicts
58
+ * rather than silently producing an empty plan.
59
+ *
60
+ * Returns an empty array if no destructive changes are found.
61
+ */
62
+ declare function detectDestructiveChanges(from: SqlStorage | null, to: SqlStorage): readonly MigrationPlannerConflict$1[];
63
+ /**
64
+ * Converts a contract's `SqlStorage` to `SqlSchemaIR`.
65
+ *
66
+ * Drops codec metadata (`codecId`, `typeRef`) since the schema IR only represents structural
67
+ * information. When `expandNativeType` is provided, parameterized types are expanded
68
+ * (e.g. `character` + `{ length: 36 }` → `character(36)`) so the resulting IR compares
69
+ * correctly against the "to" contract during planning.
70
+ *
71
+ * `extensions` is always `[]` — the planner resolves extension dependencies from framework
72
+ * components, and an empty array means "nothing installed yet" which is correct for the
73
+ * "from" side of a diff.
74
+ */
75
+ declare function contractToSchemaIR(storage: SqlStorage, expandNativeType?: NativeTypeExpander): SqlSchemaIR;
76
+ //#endregion
35
77
  //#region src/core/migrations/plan-helpers.d.ts
36
78
  declare function createMigrationPlan<TTargetDetails>(options: CreateSqlMigrationPlanOptions<TTargetDetails>): SqlMigrationPlan<TTargetDetails>;
37
79
  declare function plannerSuccess<TTargetDetails>(plan: SqlMigrationPlan<TTargetDetails>): SqlPlannerSuccessResult<TTargetDetails>;
@@ -60,5 +102,5 @@ declare const INIT_ADDITIVE_POLICY: MigrationOperationPolicy$1;
60
102
  //#region src/exports/control.d.ts
61
103
  declare const _default: SqlFamilyDescriptor;
62
104
  //#endregion
63
- export { type CodecControlHooks, type ComponentDatabaseDependencies, type ComponentDatabaseDependency, type CreateSqlMigrationPlanOptions, type ExpandNativeTypeInput, INIT_ADDITIVE_POLICY, type MigrationOperationClass, type MigrationOperationPolicy, type MigrationPlan, type MigrationPlanOperation, type MigrationPlanner, type MigrationPlannerConflict, type MigrationPlannerResult, type SchemaVerifyOptions, type SqlControlAdapterDescriptor, type SqlControlDescriptorWithContributions, type SqlControlExtensionDescriptor, type SqlControlFamilyInstance, type SqlControlStaticContributions, type SqlControlTargetDescriptor, type SqlMigrationPlan, type SqlMigrationPlanContractInfo, type SqlMigrationPlanOperation, type SqlMigrationPlanOperationStep, type SqlMigrationPlanOperationTarget, type SqlMigrationPlanner, type SqlMigrationPlannerPlanOptions, type SqlMigrationRunner, type SqlMigrationRunnerErrorCode, type SqlMigrationRunnerExecuteCallbacks, type SqlMigrationRunnerExecuteOptions, type SqlMigrationRunnerFailure, type SqlMigrationRunnerResult, type SqlMigrationRunnerSuccessValue, type SqlPlannerConflict, type SqlPlannerConflictKind, type SqlPlannerConflictLocation, type SqlPlannerFailureResult, type SqlPlannerResult, type SqlPlannerSuccessResult, type StorageTypePlanResult, type TargetMigrationsCapability, createMigrationPlan, _default as default, extractCodecControlHooks, plannerFailure, plannerSuccess, runnerFailure, runnerSuccess };
105
+ export { type CodecControlHooks, type ComponentDatabaseDependencies, type ComponentDatabaseDependency, type CreateSqlMigrationPlanOptions, type ExpandNativeTypeInput, INIT_ADDITIVE_POLICY, type MigrationOperationClass, type MigrationOperationPolicy, type MigrationPlan, type MigrationPlanOperation, type MigrationPlanner, type MigrationPlannerConflict, type MigrationPlannerResult, type NativeTypeExpander, type SchemaVerifyOptions, type SqlControlAdapterDescriptor, type SqlControlDescriptorWithContributions, type SqlControlExtensionDescriptor, type SqlControlFamilyInstance, type SqlControlStaticContributions, type SqlControlTargetDescriptor, type SqlMigrationPlan, type SqlMigrationPlanContractInfo, type SqlMigrationPlanOperation, type SqlMigrationPlanOperationStep, type SqlMigrationPlanOperationTarget, type SqlMigrationPlanner, type SqlMigrationPlannerPlanOptions, type SqlMigrationRunner, type SqlMigrationRunnerErrorCode, type SqlMigrationRunnerExecuteCallbacks, type SqlMigrationRunnerExecuteOptions, type SqlMigrationRunnerFailure, type SqlMigrationRunnerResult, type SqlMigrationRunnerSuccessValue, type SqlPlannerConflict, type SqlPlannerConflictKind, type SqlPlannerConflictLocation, type SqlPlannerFailureResult, type SqlPlannerResult, type SqlPlannerSuccessResult, type StorageTypePlanResult, type TargetMigrationsCapability, contractToSchemaIR, createMigrationPlan, _default as default, detectDestructiveChanges, extractCodecControlHooks, plannerFailure, plannerSuccess, runnerFailure, runnerSuccess };
64
106
  //# sourceMappingURL=control.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-descriptor.ts","../src/core/migrations/plan-helpers.ts","../src/core/migrations/policies.ts","../src/exports/control.ts"],"sourcesContent":[],"mappings":";;;;;;;;cAaa,mBAAA,YACA,+BAA+B;;;;;;IAD/B,SAAA,EAAA,EAAA,KACX;IAA0C,SAAA,aAAA,EAAA,CAAA,EAAA,EAAwB,yBAAA,CAAA,UAAxB,EAAA,IAAA,gDAAA,EAAA,GAAA,IAAA;IAAwB,SAAA,iBAAA,EAAA,CAAA,EAAA,sCAAA,EAAA,GAAA,IAAA;;;;;8CAM5C;4CAAA,gCAAA,CAAA;;uCAAA,EAAA,CAAA,MAAA,QAAA,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,GAAA,MAAA;IAAA,SAAA,cAAA,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GAAA,MAAA;uMAiBuO,yCAAA,eAAA;0CAAA,gCAAA,CAAA;;;;iCAAA,CAAA,CAAA,KAAA,EAdpP,iBAcoP,CAAA,KAAA,EAd3N,SAc2N,CAAA,CAAA,EAb1P,wBAa0P;;;;iBCwD/O,6CACL,8BAA8B,kBACtC,iBAAiB;iBAYJ,qCACR,iBAAiB,kBACtB,wBAAwB;iBAOX,cAAA,qBAAmC,uBAAuB;;;;ADvG7D,iBC2HG,aAAA,CD1Hd,KAAA,EAAA;EAA0C,iBAAA,EAAA,MAAA;EAAwB,kBAAA,EAAA,MAAA;IC6HhE,GAAG;;;;iBAYS,aAAA,OACR;;SAE2B;IAChC,MAAM,yBDvIe,CAAA;;;;;;cEfX,sBAAsB;;;AFQnC,cG2CkC,QH3CrB,EG2CqB,mBH1ChC"}
1
+ {"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-descriptor.ts","../src/core/migrations/contract-to-schema-ir.ts","../src/core/migrations/plan-helpers.ts","../src/core/migrations/policies.ts","../src/exports/control.ts"],"sourcesContent":[],"mappings":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ChC,MAAM;;;;;;cCtJI,sBAAsB;;;AHQnC,cIiDkC,QJjDrB,EIiDqB,mBJhDhC"}
package/dist/control.mjs CHANGED
@@ -428,6 +428,110 @@ var SqlFamilyDescriptor = class {
428
428
  }
429
429
  };
430
430
 
431
+ //#endregion
432
+ //#region src/core/migrations/contract-to-schema-ir.ts
433
+ function convertDefault(def) {
434
+ if (def.kind === "function") return def.expression;
435
+ if (typeof def.value === "string") return `'${def.value.replaceAll("'", "''")}'`;
436
+ return String(def.value);
437
+ }
438
+ function convertColumn(name, column, expandNativeType) {
439
+ return {
440
+ name,
441
+ nativeType: expandNativeType ? expandNativeType({
442
+ nativeType: column.nativeType,
443
+ codecId: column.codecId,
444
+ ...ifDefined("typeParams", column.typeParams)
445
+ }) : column.nativeType,
446
+ nullable: column.nullable,
447
+ ...column.default != null ? { default: convertDefault(column.default) } : {}
448
+ };
449
+ }
450
+ function convertUnique(unique) {
451
+ return {
452
+ columns: unique.columns,
453
+ ...unique.name != null ? { name: unique.name } : {}
454
+ };
455
+ }
456
+ function convertIndex(index) {
457
+ return {
458
+ columns: index.columns,
459
+ unique: false,
460
+ ...index.name != null ? { name: index.name } : {}
461
+ };
462
+ }
463
+ function convertForeignKey(fk) {
464
+ return {
465
+ columns: fk.columns,
466
+ referencedTable: fk.references.table,
467
+ referencedColumns: fk.references.columns,
468
+ ...fk.name != null ? { name: fk.name } : {}
469
+ };
470
+ }
471
+ function convertTable(name, table, expandNativeType) {
472
+ const columns = {};
473
+ for (const [colName, colDef] of Object.entries(table.columns)) columns[colName] = convertColumn(colName, colDef, expandNativeType);
474
+ return {
475
+ name,
476
+ columns,
477
+ ...table.primaryKey != null ? { primaryKey: table.primaryKey } : {},
478
+ foreignKeys: table.foreignKeys.map(convertForeignKey),
479
+ uniques: table.uniques.map(convertUnique),
480
+ indexes: table.indexes.map(convertIndex)
481
+ };
482
+ }
483
+ /**
484
+ * Detects destructive changes between two contract storages.
485
+ *
486
+ * The additive-only planner silently ignores removals (tables, columns).
487
+ * This function detects those removals so callers can report them as conflicts
488
+ * rather than silently producing an empty plan.
489
+ *
490
+ * Returns an empty array if no destructive changes are found.
491
+ */
492
+ function detectDestructiveChanges(from, to) {
493
+ if (!from) return [];
494
+ const hasOwn = (value, key) => Object.hasOwn(value, key);
495
+ const conflicts = [];
496
+ for (const tableName of Object.keys(from.tables)) {
497
+ if (!hasOwn(to.tables, tableName)) {
498
+ conflicts.push({
499
+ kind: "tableRemoved",
500
+ summary: `Table "${tableName}" was removed`
501
+ });
502
+ continue;
503
+ }
504
+ const toTable = to.tables[tableName];
505
+ const fromTable = from.tables[tableName];
506
+ if (!fromTable) continue;
507
+ for (const columnName of Object.keys(fromTable.columns)) if (!hasOwn(toTable.columns, columnName)) conflicts.push({
508
+ kind: "columnRemoved",
509
+ summary: `Column "${tableName}"."${columnName}" was removed`
510
+ });
511
+ }
512
+ return conflicts;
513
+ }
514
+ /**
515
+ * Converts a contract's `SqlStorage` to `SqlSchemaIR`.
516
+ *
517
+ * Drops codec metadata (`codecId`, `typeRef`) since the schema IR only represents structural
518
+ * information. When `expandNativeType` is provided, parameterized types are expanded
519
+ * (e.g. `character` + `{ length: 36 }` → `character(36)`) so the resulting IR compares
520
+ * correctly against the "to" contract during planning.
521
+ *
522
+ * `extensions` is always `[]` — the planner resolves extension dependencies from framework
523
+ * components, and an empty array means "nothing installed yet" which is correct for the
524
+ * "from" side of a diff.
525
+ */
526
+ function contractToSchemaIR(storage, expandNativeType) {
527
+ const tables = {};
528
+ for (const [tableName, tableDef] of Object.entries(storage.tables)) tables[tableName] = convertTable(tableName, tableDef, expandNativeType);
529
+ return {
530
+ tables,
531
+ extensions: []
532
+ };
533
+ }
534
+
431
535
  //#endregion
432
536
  //#region src/core/migrations/plan-helpers.ts
433
537
  const readOnlyEmptyObject = Object.freeze({});
@@ -532,5 +636,5 @@ const INIT_ADDITIVE_POLICY = Object.freeze({ allowedOperationClasses: Object.fre
532
636
  var control_default = new SqlFamilyDescriptor();
533
637
 
534
638
  //#endregion
535
- export { INIT_ADDITIVE_POLICY, createMigrationPlan, control_default as default, extractCodecControlHooks, plannerFailure, plannerSuccess, runnerFailure, runnerSuccess };
639
+ export { INIT_ADDITIVE_POLICY, contractToSchemaIR, createMigrationPlan, control_default as default, detectDestructiveChanges, extractCodecControlHooks, plannerFailure, plannerSuccess, runnerFailure, runnerSuccess };
536
640
  //# sourceMappingURL=control.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"control.mjs","names":["contract: { storageHash: string; profileHash?: string }","target: { expected: string; actual?: string }","meta: { contractPath: string; configPath?: string }","result: VerifyDatabaseResult","descriptors: SqlControlDescriptorWithContributions[]","missingCodecs: readonly string[] | undefined","options","previousHashes: { storageHash?: string; profileHash?: string } | undefined","summary: string","tableNodes: readonly SchemaTreeNode[]","children: SchemaTreeNode[]","columnNodes: SchemaTreeNode[]","tableMeta: Record<string, unknown>","extensionNodes: readonly SchemaTreeNode[]","readOnlyEmptyObject: Record<string, never>","INIT_ADDITIVE_POLICY: MigrationOperationPolicy"],"sources":["../src/core/control-instance.ts","../src/core/control-descriptor.ts","../src/core/migrations/plan-helpers.ts","../src/core/migrations/policies.ts","../src/exports/control.ts"],"sourcesContent":["import type {\n TargetBoundComponentDescriptor,\n TargetDescriptor,\n} from '@prisma-next/contract/framework-components';\nimport type { ContractIR } from '@prisma-next/contract/ir';\nimport type { ContractMarkerRecord, TypesImportSpec } from '@prisma-next/contract/types';\nimport { emit } from '@prisma-next/core-control-plane/emission';\nimport type { CoreSchemaView, SchemaTreeNode } from '@prisma-next/core-control-plane/schema-view';\nimport type {\n ControlDriverInstance,\n ControlFamilyInstance,\n EmitContractResult,\n OperationContext,\n SignDatabaseResult,\n VerifyDatabaseResult,\n VerifyDatabaseSchemaResult,\n} from '@prisma-next/core-control-plane/types';\nimport type { OperationRegistry } from '@prisma-next/operations';\nimport type { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';\nimport { validateContract } from '@prisma-next/sql-contract/validate';\nimport { sqlTargetFamilyHook } from '@prisma-next/sql-contract-emitter';\nimport {\n ensureSchemaStatement,\n ensureTableStatement,\n writeContractMarker,\n} from '@prisma-next/sql-runtime';\nimport type { SqlSchemaIR, SqlTableIR } from '@prisma-next/sql-schema-ir/types';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport {\n assembleOperationRegistry,\n extractCodecTypeImports,\n extractExtensionIds,\n extractOperationTypeImports,\n extractParameterizedRenderers,\n extractParameterizedTypeImports,\n type SqlControlDescriptorWithContributions,\n} from './assembly';\nimport type { SqlControlAdapter } from './control-adapter';\nimport type {\n SqlControlAdapterDescriptor,\n SqlControlExtensionDescriptor,\n} from './migrations/types';\nimport { verifySqlSchema } from './schema-verify/verify-sql-schema';\nimport { collectSupportedCodecTypeIds, readMarker } from './verify';\n\nfunction extractCodecTypeIdsFromContract(contract: unknown): readonly string[] {\n const typeIds = new Set<string>();\n\n // Type guard for SQL contract structure\n if (\n typeof contract === 'object' &&\n contract !== null &&\n 'storage' in contract &&\n typeof contract.storage === 'object' &&\n contract.storage !== null &&\n 'tables' in contract.storage\n ) {\n const storage = contract.storage as { tables?: Record<string, unknown> };\n if (storage.tables && typeof storage.tables === 'object') {\n for (const table of Object.values(storage.tables)) {\n if (\n typeof table === 'object' &&\n table !== null &&\n 'columns' in table &&\n typeof table.columns === 'object' &&\n table.columns !== null\n ) {\n const columns = table.columns as Record<string, { codecId: string } | undefined>;\n for (const column of Object.values(columns)) {\n if (\n column &&\n typeof column === 'object' &&\n 'codecId' in column &&\n typeof column.codecId === 'string'\n ) {\n typeIds.add(column.codecId);\n }\n }\n }\n }\n }\n }\n\n return Array.from(typeIds).sort();\n}\n\nfunction createVerifyResult(options: {\n ok: boolean;\n code?: string;\n summary: string;\n contractStorageHash: string;\n contractProfileHash?: string;\n marker?: ContractMarkerRecord;\n expectedTargetId: string;\n actualTargetId?: string;\n missingCodecs?: readonly string[];\n codecCoverageSkipped?: boolean;\n configPath?: string;\n contractPath: string;\n totalTime: number;\n}): VerifyDatabaseResult {\n const contract: { storageHash: string; profileHash?: string } = {\n storageHash: options.contractStorageHash,\n };\n if (options.contractProfileHash) {\n contract.profileHash = options.contractProfileHash;\n }\n\n const target: { expected: string; actual?: string } = {\n expected: options.expectedTargetId,\n };\n if (options.actualTargetId) {\n target.actual = options.actualTargetId;\n }\n\n const meta: { contractPath: string; configPath?: string } = {\n contractPath: options.contractPath,\n };\n if (options.configPath) {\n meta.configPath = options.configPath;\n }\n\n const result: VerifyDatabaseResult = {\n ok: options.ok,\n summary: options.summary,\n contract,\n target,\n meta,\n timings: {\n total: options.totalTime,\n },\n };\n\n if (options.code) {\n (result as { code?: string }).code = options.code;\n }\n\n if (options.marker) {\n (result as { marker?: { storageHash: string; profileHash: string } }).marker = {\n storageHash: options.marker.storageHash,\n profileHash: options.marker.profileHash,\n };\n }\n\n if (options.missingCodecs) {\n (result as { missingCodecs?: readonly string[] }).missingCodecs = options.missingCodecs;\n }\n\n if (options.codecCoverageSkipped) {\n (result as { codecCoverageSkipped?: boolean }).codecCoverageSkipped =\n options.codecCoverageSkipped;\n }\n\n return result;\n}\n\ninterface SqlTypeMetadata {\n readonly typeId: string;\n readonly familyId: 'sql';\n readonly targetId: string;\n readonly nativeType?: string;\n}\n\ntype SqlTypeMetadataRegistry = Map<string, SqlTypeMetadata>;\n\ninterface SqlFamilyInstanceState {\n readonly operationRegistry: OperationRegistry;\n readonly codecTypeImports: ReadonlyArray<TypesImportSpec>;\n readonly operationTypeImports: ReadonlyArray<TypesImportSpec>;\n readonly extensionIds: ReadonlyArray<string>;\n readonly typeMetadataRegistry: SqlTypeMetadataRegistry;\n}\n\nexport interface SchemaVerifyOptions {\n readonly driver: ControlDriverInstance<'sql', string>;\n readonly contractIR: unknown;\n readonly strict: boolean;\n readonly context?: OperationContext;\n /**\n * Active framework components participating in this composition.\n * All components must have matching familyId ('sql') and targetId.\n */\n readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;\n}\n\nexport interface SqlControlFamilyInstance\n extends ControlFamilyInstance<'sql'>,\n SqlFamilyInstanceState {\n validateContractIR(contractJson: unknown): ContractIR;\n\n verify(options: {\n readonly driver: ControlDriverInstance<'sql', string>;\n readonly contractIR: unknown;\n readonly expectedTargetId: string;\n readonly contractPath: string;\n readonly configPath?: string;\n }): Promise<VerifyDatabaseResult>;\n\n schemaVerify(options: SchemaVerifyOptions): Promise<VerifyDatabaseSchemaResult>;\n\n sign(options: {\n readonly driver: ControlDriverInstance<'sql', string>;\n readonly contractIR: unknown;\n readonly contractPath: string;\n readonly configPath?: string;\n }): Promise<SignDatabaseResult>;\n\n introspect(options: {\n readonly driver: ControlDriverInstance<'sql', string>;\n readonly contractIR?: unknown;\n }): Promise<SqlSchemaIR>;\n\n toSchemaView(schema: SqlSchemaIR): CoreSchemaView;\n\n emitContract(options: { readonly contractIR: ContractIR | unknown }): Promise<EmitContractResult>;\n}\n\nexport type SqlFamilyInstance = SqlControlFamilyInstance;\n\ninterface CreateSqlFamilyInstanceOptions<TTargetId extends string> {\n readonly target: TargetDescriptor<'sql', TTargetId> &\n SqlControlDescriptorWithContributions &\n DescriptorWithStorageTypes;\n readonly adapter: SqlControlAdapterDescriptor<TTargetId> & DescriptorWithStorageTypes;\n readonly extensionPacks: readonly (SqlControlExtensionDescriptor<TTargetId> &\n DescriptorWithStorageTypes)[];\n}\n\nfunction isSqlControlAdapter<TTargetId extends string>(\n value: unknown,\n): value is SqlControlAdapter<TTargetId> {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'introspect' in value &&\n typeof (value as { introspect: unknown }).introspect === 'function'\n );\n}\n\ninterface DescriptorWithStorageTypes {\n readonly targetId?: string | undefined;\n readonly types?:\n | {\n readonly storage?:\n | ReadonlyArray<{\n readonly typeId: string;\n readonly familyId: string;\n readonly targetId: string;\n readonly nativeType?: string | undefined;\n }>\n | undefined;\n }\n | undefined;\n}\n\nfunction buildSqlTypeMetadataRegistry(options: {\n readonly target: DescriptorWithStorageTypes;\n readonly adapter: DescriptorWithStorageTypes & { readonly targetId: string };\n readonly extensionPacks: readonly DescriptorWithStorageTypes[];\n}): SqlTypeMetadataRegistry {\n const { target, adapter, extensionPacks: extensions } = options;\n const registry = new Map<string, SqlTypeMetadata>();\n const targetId = adapter.targetId;\n const descriptors = [target, adapter, ...extensions];\n\n for (const descriptor of descriptors) {\n const types = descriptor.types;\n const storageTypes = types?.storage;\n\n if (!storageTypes) {\n continue;\n }\n\n for (const storageType of storageTypes) {\n if (storageType.familyId === 'sql' && storageType.targetId === targetId) {\n registry.set(storageType.typeId, {\n typeId: storageType.typeId,\n familyId: 'sql',\n targetId: storageType.targetId,\n ...(storageType.nativeType !== undefined ? { nativeType: storageType.nativeType } : {}),\n });\n }\n }\n }\n\n return registry;\n}\n\nexport function createSqlFamilyInstance<TTargetId extends string>(\n options: CreateSqlFamilyInstanceOptions<TTargetId>,\n): SqlFamilyInstance {\n const { target, adapter, extensionPacks: extensions = [] } = options;\n\n const descriptors: SqlControlDescriptorWithContributions[] = [target, adapter, ...extensions];\n\n const operationRegistry = assembleOperationRegistry(descriptors);\n const codecTypeImports = extractCodecTypeImports(descriptors);\n const operationTypeImports = extractOperationTypeImports(descriptors);\n const extensionIds = extractExtensionIds(adapter, target, extensions);\n const parameterizedRenderers = extractParameterizedRenderers(descriptors);\n const parameterizedTypeImports = extractParameterizedTypeImports(descriptors);\n\n const typeMetadataRegistry = buildSqlTypeMetadataRegistry({\n target,\n adapter,\n extensionPacks: extensions,\n });\n\n function stripMappings(contract: unknown): unknown {\n if (typeof contract === 'object' && contract !== null && 'mappings' in contract) {\n const { mappings: _mappings, ...contractIR } = contract as {\n mappings?: unknown;\n [key: string]: unknown;\n };\n return contractIR;\n }\n return contract;\n }\n\n function normalizeProviderContractIR(contract: unknown): ContractIR {\n const contractWithoutMappings = stripMappings(contract);\n const validated = validateContract<SqlContract<SqlStorage>>(contractWithoutMappings);\n const { mappings: _mappings, ...contractIR } = validated;\n return contractIR as ContractIR;\n }\n\n return {\n familyId: 'sql',\n operationRegistry,\n codecTypeImports,\n operationTypeImports,\n extensionIds,\n typeMetadataRegistry,\n\n validateContractIR(contractJson: unknown): ContractIR {\n return normalizeProviderContractIR(contractJson);\n },\n\n async verify(verifyOptions: {\n readonly driver: ControlDriverInstance<'sql', string>;\n readonly contractIR: unknown;\n readonly expectedTargetId: string;\n readonly contractPath: string;\n readonly configPath?: string;\n }): Promise<VerifyDatabaseResult> {\n const { driver, contractIR, expectedTargetId, contractPath, configPath } = verifyOptions;\n const startTime = Date.now();\n\n if (\n typeof contractIR !== 'object' ||\n contractIR === null ||\n !('storageHash' in contractIR) ||\n !('target' in contractIR) ||\n typeof contractIR.storageHash !== 'string' ||\n typeof contractIR.target !== 'string'\n ) {\n throw new Error('Contract is missing required fields: storageHash or target');\n }\n\n const contractStorageHash = contractIR.storageHash;\n const contractProfileHash =\n 'profileHash' in contractIR && typeof contractIR.profileHash === 'string'\n ? contractIR.profileHash\n : undefined;\n const contractTarget = contractIR.target;\n\n const marker = await readMarker(driver);\n\n let missingCodecs: readonly string[] | undefined;\n let codecCoverageSkipped = false;\n const supportedTypeIds = collectSupportedCodecTypeIds([adapter, target, ...extensions]);\n if (supportedTypeIds.length === 0) {\n codecCoverageSkipped = true;\n } else {\n const supportedSet = new Set(supportedTypeIds);\n const usedTypeIds = extractCodecTypeIdsFromContract(contractIR);\n const missing = usedTypeIds.filter((id) => !supportedSet.has(id));\n if (missing.length > 0) {\n missingCodecs = missing;\n }\n }\n\n if (!marker) {\n const totalTime = Date.now() - startTime;\n return createVerifyResult({\n ok: false,\n code: 'PN-RTM-3001',\n summary: 'Marker missing',\n contractStorageHash,\n expectedTargetId,\n contractPath,\n totalTime,\n ...(contractProfileHash ? { contractProfileHash } : {}),\n ...(missingCodecs ? { missingCodecs } : {}),\n ...(codecCoverageSkipped ? { codecCoverageSkipped } : {}),\n ...(configPath ? { configPath } : {}),\n });\n }\n\n if (contractTarget !== expectedTargetId) {\n const totalTime = Date.now() - startTime;\n return createVerifyResult({\n ok: false,\n code: 'PN-RTM-3003',\n summary: 'Target mismatch',\n contractStorageHash,\n marker,\n expectedTargetId,\n actualTargetId: contractTarget,\n contractPath,\n totalTime,\n ...(contractProfileHash ? { contractProfileHash } : {}),\n ...(missingCodecs ? { missingCodecs } : {}),\n ...(codecCoverageSkipped ? { codecCoverageSkipped } : {}),\n ...(configPath ? { configPath } : {}),\n });\n }\n\n if (marker.storageHash !== contractStorageHash) {\n const totalTime = Date.now() - startTime;\n return createVerifyResult({\n ok: false,\n code: 'PN-RTM-3002',\n summary: 'Hash mismatch',\n contractStorageHash,\n marker,\n expectedTargetId,\n contractPath,\n totalTime,\n ...(contractProfileHash ? { contractProfileHash } : {}),\n ...(missingCodecs ? { missingCodecs } : {}),\n ...(codecCoverageSkipped ? { codecCoverageSkipped } : {}),\n ...(configPath ? { configPath } : {}),\n });\n }\n\n if (contractProfileHash && marker.profileHash !== contractProfileHash) {\n const totalTime = Date.now() - startTime;\n return createVerifyResult({\n ok: false,\n code: 'PN-RTM-3002',\n summary: 'Hash mismatch',\n contractStorageHash,\n contractProfileHash,\n marker,\n expectedTargetId,\n contractPath,\n totalTime,\n ...(missingCodecs ? { missingCodecs } : {}),\n ...(codecCoverageSkipped ? { codecCoverageSkipped } : {}),\n ...(configPath ? { configPath } : {}),\n });\n }\n\n const totalTime = Date.now() - startTime;\n return createVerifyResult({\n ok: true,\n summary: 'Database matches contract',\n contractStorageHash,\n marker,\n expectedTargetId,\n contractPath,\n totalTime,\n ...(contractProfileHash ? { contractProfileHash } : {}),\n ...(missingCodecs ? { missingCodecs } : {}),\n ...(codecCoverageSkipped ? { codecCoverageSkipped } : {}),\n ...(configPath ? { configPath } : {}),\n });\n },\n\n async schemaVerify(options: SchemaVerifyOptions): Promise<VerifyDatabaseSchemaResult> {\n const { driver, contractIR, strict, context, frameworkComponents } = options;\n\n const contract = validateContract<SqlContract<SqlStorage>>(contractIR);\n\n const controlAdapter = adapter.create();\n if (!isSqlControlAdapter(controlAdapter)) {\n throw new Error('Adapter does not implement SqlControlAdapter.introspect()');\n }\n const schemaIR = await controlAdapter.introspect(driver, contractIR);\n\n return verifySqlSchema({\n contract,\n schema: schemaIR,\n strict,\n ...ifDefined('context', context),\n typeMetadataRegistry,\n frameworkComponents,\n // Wire up target-specific normalizers if available\n ...ifDefined('normalizeDefault', controlAdapter.normalizeDefault),\n ...ifDefined('normalizeNativeType', controlAdapter.normalizeNativeType),\n });\n },\n async sign(options: {\n readonly driver: ControlDriverInstance<'sql', string>;\n readonly contractIR: unknown;\n readonly contractPath: string;\n readonly configPath?: string;\n }): Promise<SignDatabaseResult> {\n const { driver, contractIR, contractPath, configPath } = options;\n const startTime = Date.now();\n\n const contract = validateContract<SqlContract<SqlStorage>>(contractIR);\n\n const contractStorageHash = contract.storageHash;\n const contractProfileHash =\n 'profileHash' in contract && typeof contract.profileHash === 'string'\n ? contract.profileHash\n : contractStorageHash;\n const contractTarget = contract.target;\n\n await driver.query(ensureSchemaStatement.sql, ensureSchemaStatement.params);\n await driver.query(ensureTableStatement.sql, ensureTableStatement.params);\n\n const existingMarker = await readMarker(driver);\n\n let markerCreated = false;\n let markerUpdated = false;\n let previousHashes: { storageHash?: string; profileHash?: string } | undefined;\n\n if (!existingMarker) {\n const write = writeContractMarker({\n storageHash: contractStorageHash,\n profileHash: contractProfileHash,\n contractJson: contractIR,\n canonicalVersion: 1,\n });\n await driver.query(write.insert.sql, write.insert.params);\n markerCreated = true;\n } else {\n const existingStorageHash = existingMarker.storageHash;\n const existingProfileHash = existingMarker.profileHash;\n\n const storageHashMatches = existingStorageHash === contractStorageHash;\n const profileHashMatches = existingProfileHash === contractProfileHash;\n\n if (!storageHashMatches || !profileHashMatches) {\n previousHashes = {\n storageHash: existingStorageHash,\n profileHash: existingProfileHash,\n };\n const write = writeContractMarker({\n storageHash: contractStorageHash,\n profileHash: contractProfileHash,\n contractJson: contractIR,\n canonicalVersion: existingMarker.canonicalVersion ?? 1,\n });\n await driver.query(write.update.sql, write.update.params);\n markerUpdated = true;\n }\n }\n\n let summary: string;\n if (markerCreated) {\n summary = 'Database signed (marker created)';\n } else if (markerUpdated) {\n summary = `Database signed (marker updated from ${previousHashes?.storageHash ?? 'unknown'})`;\n } else {\n summary = 'Database already signed with this contract';\n }\n\n const totalTime = Date.now() - startTime;\n\n return {\n ok: true,\n summary,\n contract: {\n storageHash: contractStorageHash,\n profileHash: contractProfileHash,\n },\n target: {\n expected: contractTarget,\n actual: contractTarget,\n },\n marker: {\n created: markerCreated,\n updated: markerUpdated,\n ...(previousHashes ? { previous: previousHashes } : {}),\n },\n meta: {\n contractPath,\n ...(configPath ? { configPath } : {}),\n },\n timings: {\n total: totalTime,\n },\n };\n },\n async readMarker(options: {\n readonly driver: ControlDriverInstance<'sql', string>;\n }): Promise<ContractMarkerRecord | null> {\n return readMarker(options.driver);\n },\n async introspect(options: {\n readonly driver: ControlDriverInstance<'sql', string>;\n readonly contractIR?: unknown;\n }): Promise<SqlSchemaIR> {\n const { driver, contractIR } = options;\n\n const controlAdapter = adapter.create();\n if (!isSqlControlAdapter(controlAdapter)) {\n throw new Error('Adapter does not implement SqlControlAdapter.introspect()');\n }\n return controlAdapter.introspect(driver, contractIR);\n },\n\n toSchemaView(schema: SqlSchemaIR): CoreSchemaView {\n const rootLabel = 'contract';\n\n const tableNodes: readonly SchemaTreeNode[] = Object.entries(schema.tables).map(\n ([tableName, table]: [string, SqlTableIR]) => {\n const children: SchemaTreeNode[] = [];\n\n const columnNodes: SchemaTreeNode[] = [];\n for (const [columnName, column] of Object.entries(table.columns)) {\n const typeDisplay = column.nativeType;\n const nullability = column.nullable ? 'nullable' : 'not nullable';\n const label = `${columnName}: ${typeDisplay} (${nullability})`;\n columnNodes.push({\n kind: 'field',\n id: `column-${tableName}-${columnName}`,\n label,\n meta: {\n nativeType: column.nativeType,\n nullable: column.nullable,\n ...ifDefined('default', column.default),\n },\n });\n }\n\n if (columnNodes.length > 0) {\n children.push({\n kind: 'collection',\n id: `columns-${tableName}`,\n label: 'columns',\n children: columnNodes,\n });\n }\n\n if (table.primaryKey) {\n const pkColumns = table.primaryKey.columns.join(', ');\n children.push({\n kind: 'index',\n id: `primary-key-${tableName}`,\n label: `primary key: ${pkColumns}`,\n meta: {\n columns: table.primaryKey.columns,\n ...(table.primaryKey.name ? { name: table.primaryKey.name } : {}),\n },\n });\n }\n\n for (const unique of table.uniques) {\n const name = unique.name ?? `${tableName}_${unique.columns.join('_')}_unique`;\n const label = `unique ${name}`;\n children.push({\n kind: 'index',\n id: `unique-${tableName}-${name}`,\n label,\n meta: {\n columns: unique.columns,\n unique: true,\n },\n });\n }\n\n for (const index of table.indexes) {\n const name = index.name ?? `${tableName}_${index.columns.join('_')}_idx`;\n const label = index.unique ? `unique index ${name}` : `index ${name}`;\n children.push({\n kind: 'index',\n id: `index-${tableName}-${name}`,\n label,\n meta: {\n columns: index.columns,\n unique: index.unique,\n },\n });\n }\n\n const tableMeta: Record<string, unknown> = {};\n if (table.primaryKey) {\n tableMeta['primaryKey'] = table.primaryKey.columns;\n if (table.primaryKey.name) {\n tableMeta['primaryKeyName'] = table.primaryKey.name;\n }\n }\n if (table.foreignKeys.length > 0) {\n tableMeta['foreignKeys'] = table.foreignKeys.map((fk) => ({\n columns: fk.columns,\n referencedTable: fk.referencedTable,\n referencedColumns: fk.referencedColumns,\n ...(fk.name ? { name: fk.name } : {}),\n }));\n }\n\n const node: SchemaTreeNode = {\n kind: 'entity',\n id: `table-${tableName}`,\n label: `table ${tableName}`,\n ...(Object.keys(tableMeta).length > 0 ? { meta: tableMeta } : {}),\n ...(children.length > 0 ? { children: children as readonly SchemaTreeNode[] } : {}),\n };\n return node;\n },\n );\n\n const extensionNodes: readonly SchemaTreeNode[] = schema.extensions.map((extName) => ({\n kind: 'extension',\n id: `extension-${extName}`,\n label: `${extName} extension is enabled`,\n }));\n\n const rootChildren = [...tableNodes, ...extensionNodes];\n\n const rootNode: SchemaTreeNode = {\n kind: 'root',\n id: 'sql-schema',\n label: rootLabel,\n ...(rootChildren.length > 0 ? { children: rootChildren } : {}),\n };\n\n return {\n root: rootNode,\n };\n },\n\n async emitContract({ contractIR }): Promise<EmitContractResult> {\n const normalizedIR = normalizeProviderContractIR(contractIR);\n\n const result = await emit(\n normalizedIR,\n {\n outputDir: '',\n operationRegistry,\n codecTypeImports,\n operationTypeImports,\n extensionIds,\n parameterizedRenderers,\n parameterizedTypeImports,\n },\n sqlTargetFamilyHook,\n );\n\n return {\n contractJson: result.contractJson,\n contractDts: result.contractDts,\n storageHash: result.storageHash,\n ...(result.executionHash ? { executionHash: result.executionHash } : {}),\n profileHash: result.profileHash,\n };\n },\n };\n}\n","import type { TargetDescriptor } from '@prisma-next/contract/framework-components';\nimport type {\n ControlFamilyDescriptor,\n ControlPlaneStack,\n} from '@prisma-next/core-control-plane/types';\nimport { sqlTargetFamilyHook } from '@prisma-next/sql-contract-emitter';\nimport type { SqlControlDescriptorWithContributions } from './assembly';\nimport { createSqlFamilyInstance, type SqlControlFamilyInstance } from './control-instance';\nimport type {\n SqlControlAdapterDescriptor,\n SqlControlExtensionDescriptor,\n} from './migrations/types';\n\nexport class SqlFamilyDescriptor\n implements ControlFamilyDescriptor<'sql', SqlControlFamilyInstance>\n{\n readonly kind = 'family' as const;\n readonly id = 'sql';\n readonly familyId = 'sql' as const;\n readonly version = '0.0.1';\n readonly hook = sqlTargetFamilyHook;\n\n create<TTargetId extends string>(\n stack: ControlPlaneStack<'sql', TTargetId>,\n ): SqlControlFamilyInstance {\n const target = stack.target as unknown as TargetDescriptor<'sql', TTargetId> &\n SqlControlDescriptorWithContributions;\n const adapter = stack.adapter as unknown as SqlControlAdapterDescriptor<TTargetId>;\n const extensionPacks =\n stack.extensionPacks as unknown as readonly SqlControlExtensionDescriptor<TTargetId>[];\n return createSqlFamilyInstance({\n target,\n adapter,\n extensionPacks,\n });\n }\n}\n","import type { NotOk, Ok } from '@prisma-next/utils/result';\nimport { notOk, ok } from '@prisma-next/utils/result';\nimport type {\n AnyRecord,\n CreateSqlMigrationPlanOptions,\n SqlMigrationPlan,\n SqlMigrationPlanOperation,\n SqlMigrationPlanOperationStep,\n SqlMigrationPlanOperationTarget,\n SqlMigrationRunnerErrorCode,\n SqlMigrationRunnerFailure,\n SqlMigrationRunnerSuccessValue,\n SqlPlannerConflict,\n SqlPlannerFailureResult,\n SqlPlannerSuccessResult,\n} from './types';\n\nconst readOnlyEmptyObject: Record<string, never> = Object.freeze({});\n\nfunction cloneRecord<T extends AnyRecord>(value: T): T {\n if (value === readOnlyEmptyObject) {\n return value;\n }\n return Object.freeze({ ...value }) as T;\n}\n\nfunction freezeSteps(\n steps: readonly SqlMigrationPlanOperationStep[],\n): readonly SqlMigrationPlanOperationStep[] {\n if (steps.length === 0) {\n return Object.freeze([]);\n }\n return Object.freeze(\n steps.map((step) =>\n Object.freeze({\n description: step.description,\n sql: step.sql,\n ...(step.meta ? { meta: cloneRecord(step.meta) } : {}),\n }),\n ),\n );\n}\n\nfunction freezeDetailsValue<T>(value: T): T {\n // Primitives and null/undefined are already immutable, return as-is\n if (value === null || value === undefined) {\n return value;\n }\n if (typeof value !== 'object') {\n return value;\n }\n // Arrays: shallow clone and freeze\n if (Array.isArray(value)) {\n return Object.freeze([...value]) as T;\n }\n // Objects: shallow clone and freeze (matching cloneRecord pattern)\n return Object.freeze({ ...value }) as T;\n}\n\nfunction freezeTargetDetails<TTargetDetails>(\n target: SqlMigrationPlanOperationTarget<TTargetDetails>,\n): SqlMigrationPlanOperationTarget<TTargetDetails> {\n return Object.freeze({\n id: target.id,\n ...(target.details !== undefined ? { details: freezeDetailsValue(target.details) } : {}),\n });\n}\n\nfunction freezeOperation<TTargetDetails>(\n operation: SqlMigrationPlanOperation<TTargetDetails>,\n): SqlMigrationPlanOperation<TTargetDetails> {\n return Object.freeze({\n id: operation.id,\n label: operation.label,\n ...(operation.summary ? { summary: operation.summary } : {}),\n operationClass: operation.operationClass,\n target: freezeTargetDetails(operation.target),\n precheck: freezeSteps(operation.precheck),\n execute: freezeSteps(operation.execute),\n postcheck: freezeSteps(operation.postcheck),\n ...(operation.meta ? { meta: cloneRecord(operation.meta) } : {}),\n });\n}\n\nfunction freezeOperations<TTargetDetails>(\n operations: readonly SqlMigrationPlanOperation<TTargetDetails>[],\n): readonly SqlMigrationPlanOperation<TTargetDetails>[] {\n if (operations.length === 0) {\n return Object.freeze([]);\n }\n return Object.freeze(operations.map((operation) => freezeOperation(operation)));\n}\n\nexport function createMigrationPlan<TTargetDetails>(\n options: CreateSqlMigrationPlanOptions<TTargetDetails>,\n): SqlMigrationPlan<TTargetDetails> {\n return Object.freeze({\n targetId: options.targetId,\n ...(options.origin !== undefined\n ? { origin: options.origin ? Object.freeze({ ...options.origin }) : null }\n : {}),\n destination: Object.freeze({ ...options.destination }),\n operations: freezeOperations(options.operations),\n ...(options.meta ? { meta: cloneRecord(options.meta) } : {}),\n });\n}\n\nexport function plannerSuccess<TTargetDetails>(\n plan: SqlMigrationPlan<TTargetDetails>,\n): SqlPlannerSuccessResult<TTargetDetails> {\n return Object.freeze({\n kind: 'success',\n plan,\n });\n}\n\nexport function plannerFailure(conflicts: readonly SqlPlannerConflict[]): SqlPlannerFailureResult {\n return Object.freeze({\n kind: 'failure' as const,\n conflicts: Object.freeze(\n conflicts.map((conflict) =>\n Object.freeze({\n kind: conflict.kind,\n summary: conflict.summary,\n ...(conflict.why ? { why: conflict.why } : {}),\n ...(conflict.location ? { location: Object.freeze({ ...conflict.location }) } : {}),\n ...(conflict.meta ? { meta: cloneRecord(conflict.meta) } : {}),\n }),\n ),\n ),\n });\n}\n\n/**\n * Creates a successful migration runner result.\n */\nexport function runnerSuccess(value: {\n operationsPlanned: number;\n operationsExecuted: number;\n}): Ok<SqlMigrationRunnerSuccessValue> {\n return ok(\n Object.freeze({\n operationsPlanned: value.operationsPlanned,\n operationsExecuted: value.operationsExecuted,\n }),\n );\n}\n\n/**\n * Creates a failed migration runner result.\n */\nexport function runnerFailure(\n code: SqlMigrationRunnerErrorCode,\n summary: string,\n options?: { why?: string; meta?: AnyRecord },\n): NotOk<SqlMigrationRunnerFailure> {\n const failure: SqlMigrationRunnerFailure = Object.freeze({\n code,\n summary,\n ...(options?.why ? { why: options.why } : {}),\n ...(options?.meta ? { meta: cloneRecord(options.meta) } : {}),\n });\n return notOk(failure);\n}\n","import type { MigrationOperationPolicy } from '@prisma-next/core-control-plane/types';\n\n/**\n * Policy used by `db init`: additive-only operations, no widening/destructive steps.\n */\nexport const INIT_ADDITIVE_POLICY: MigrationOperationPolicy = Object.freeze({\n allowedOperationClasses: Object.freeze(['additive'] as const),\n});\n","import { SqlFamilyDescriptor } from '../core/control-descriptor';\n\n// Re-export core types from canonical source\nexport type {\n MigrationOperationClass,\n MigrationOperationPolicy,\n MigrationPlan,\n MigrationPlanner,\n MigrationPlannerConflict,\n MigrationPlannerResult,\n MigrationPlanOperation,\n TargetMigrationsCapability,\n} from '@prisma-next/core-control-plane/types';\nexport type { SqlControlDescriptorWithContributions } from '../core/assembly';\nexport { extractCodecControlHooks } from '../core/assembly';\nexport type { SchemaVerifyOptions, SqlControlFamilyInstance } from '../core/control-instance';\nexport {\n createMigrationPlan,\n plannerFailure,\n plannerSuccess,\n runnerFailure,\n runnerSuccess,\n} from '../core/migrations/plan-helpers';\nexport { INIT_ADDITIVE_POLICY } from '../core/migrations/policies';\n// SQL-specific types\nexport type {\n CodecControlHooks,\n ComponentDatabaseDependencies,\n ComponentDatabaseDependency,\n CreateSqlMigrationPlanOptions,\n ExpandNativeTypeInput,\n SqlControlAdapterDescriptor,\n SqlControlExtensionDescriptor,\n SqlControlStaticContributions,\n SqlControlTargetDescriptor,\n SqlMigrationPlan,\n SqlMigrationPlanContractInfo,\n SqlMigrationPlanner,\n SqlMigrationPlannerPlanOptions,\n SqlMigrationPlanOperation,\n SqlMigrationPlanOperationStep,\n SqlMigrationPlanOperationTarget,\n SqlMigrationRunner,\n SqlMigrationRunnerErrorCode,\n SqlMigrationRunnerExecuteCallbacks,\n SqlMigrationRunnerExecuteOptions,\n SqlMigrationRunnerFailure,\n SqlMigrationRunnerResult,\n SqlMigrationRunnerSuccessValue,\n SqlPlannerConflict,\n SqlPlannerConflictKind,\n SqlPlannerConflictLocation,\n SqlPlannerFailureResult,\n SqlPlannerResult,\n SqlPlannerSuccessResult,\n StorageTypePlanResult,\n} from '../core/migrations/types';\n\nexport default new SqlFamilyDescriptor();\n"],"mappings":";;;;;;;;;;;AA6CA,SAAS,gCAAgC,UAAsC;CAC7E,MAAM,0BAAU,IAAI,KAAa;AAGjC,KACE,OAAO,aAAa,YACpB,aAAa,QACb,aAAa,YACb,OAAO,SAAS,YAAY,YAC5B,SAAS,YAAY,QACrB,YAAY,SAAS,SACrB;EACA,MAAM,UAAU,SAAS;AACzB,MAAI,QAAQ,UAAU,OAAO,QAAQ,WAAW,UAC9C;QAAK,MAAM,SAAS,OAAO,OAAO,QAAQ,OAAO,CAC/C,KACE,OAAO,UAAU,YACjB,UAAU,QACV,aAAa,SACb,OAAO,MAAM,YAAY,YACzB,MAAM,YAAY,MAClB;IACA,MAAM,UAAU,MAAM;AACtB,SAAK,MAAM,UAAU,OAAO,OAAO,QAAQ,CACzC,KACE,UACA,OAAO,WAAW,YAClB,aAAa,UACb,OAAO,OAAO,YAAY,SAE1B,SAAQ,IAAI,OAAO,QAAQ;;;;AAQvC,QAAO,MAAM,KAAK,QAAQ,CAAC,MAAM;;AAGnC,SAAS,mBAAmB,SAcH;CACvB,MAAMA,WAA0D,EAC9D,aAAa,QAAQ,qBACtB;AACD,KAAI,QAAQ,oBACV,UAAS,cAAc,QAAQ;CAGjC,MAAMC,SAAgD,EACpD,UAAU,QAAQ,kBACnB;AACD,KAAI,QAAQ,eACV,QAAO,SAAS,QAAQ;CAG1B,MAAMC,OAAsD,EAC1D,cAAc,QAAQ,cACvB;AACD,KAAI,QAAQ,WACV,MAAK,aAAa,QAAQ;CAG5B,MAAMC,SAA+B;EACnC,IAAI,QAAQ;EACZ,SAAS,QAAQ;EACjB;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AClF,GAAI,SAAS,OAAO,EAAE,MAAM,YAAY,SAAS,KAAK,EAAE,GAAG,EAAE;GAC9D,CAAC,CACH,CACF;EACF,CAAC;;;;;AAMJ,SAAgB,cAAc,OAGS;AACrC,QAAO,GACL,OAAO,OAAO;EACZ,mBAAmB,MAAM;EACzB,oBAAoB,MAAM;EAC3B,CAAC,CACH;;;;;AAMH,SAAgB,cACd,MACA,SACA,SACkC;AAOlC,QAAO,MANoC,OAAO,OAAO;EACvD;EACA;EACA,GAAI,SAAS,MAAM,EAAE,KAAK,QAAQ,KAAK,GAAG,EAAE;EAC5C,GAAI,SAAS,OAAO,EAAE,MAAM,YAAY,QAAQ,KAAK,EAAE,GAAG,EAAE;EAC7D,CAAC,CACmB;;;;;;;;AC7JvB,MAAaC,uBAAiD,OAAO,OAAO,EAC1E,yBAAyB,OAAO,OAAO,CAAC,WAAW,CAAU,EAC9D,CAAC;;;;ACmDF,sBAAe,IAAI,qBAAqB"}
1
+ {"version":3,"file":"control.mjs","names":["contract: { storageHash: string; profileHash?: string }","target: { expected: string; actual?: string }","meta: { contractPath: string; configPath?: string }","result: VerifyDatabaseResult","descriptors: SqlControlDescriptorWithContributions[]","missingCodecs: readonly string[] | undefined","options","previousHashes: { storageHash?: string; profileHash?: string } | undefined","summary: string","tableNodes: readonly SchemaTreeNode[]","children: SchemaTreeNode[]","columnNodes: SchemaTreeNode[]","tableMeta: Record<string, unknown>","extensionNodes: readonly SchemaTreeNode[]","columns: Record<string, SqlColumnIR>","conflicts: MigrationPlannerConflict[]","tables: Record<string, SqlTableIR>","readOnlyEmptyObject: Record<string, never>","INIT_ADDITIVE_POLICY: MigrationOperationPolicy"],"sources":["../src/core/control-instance.ts","../src/core/control-descriptor.ts","../src/core/migrations/contract-to-schema-ir.ts","../src/core/migrations/plan-helpers.ts","../src/core/migrations/policies.ts","../src/exports/control.ts"],"sourcesContent":["import type {\n TargetBoundComponentDescriptor,\n TargetDescriptor,\n} from '@prisma-next/contract/framework-components';\nimport type { ContractIR } from '@prisma-next/contract/ir';\nimport type { ContractMarkerRecord, TypesImportSpec } from '@prisma-next/contract/types';\nimport { emit } from '@prisma-next/core-control-plane/emission';\nimport type { CoreSchemaView, SchemaTreeNode } from '@prisma-next/core-control-plane/schema-view';\nimport type {\n ControlDriverInstance,\n ControlFamilyInstance,\n EmitContractResult,\n OperationContext,\n SignDatabaseResult,\n VerifyDatabaseResult,\n VerifyDatabaseSchemaResult,\n} from '@prisma-next/core-control-plane/types';\nimport type { OperationRegistry } from '@prisma-next/operations';\nimport type { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';\nimport { validateContract } from '@prisma-next/sql-contract/validate';\nimport { sqlTargetFamilyHook } from '@prisma-next/sql-contract-emitter';\nimport {\n ensureSchemaStatement,\n ensureTableStatement,\n writeContractMarker,\n} from '@prisma-next/sql-runtime';\nimport type { SqlSchemaIR, SqlTableIR } from '@prisma-next/sql-schema-ir/types';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport {\n assembleOperationRegistry,\n extractCodecTypeImports,\n extractExtensionIds,\n extractOperationTypeImports,\n extractParameterizedRenderers,\n extractParameterizedTypeImports,\n type SqlControlDescriptorWithContributions,\n} from './assembly';\nimport type { SqlControlAdapter } from './control-adapter';\nimport type {\n SqlControlAdapterDescriptor,\n SqlControlExtensionDescriptor,\n} from './migrations/types';\nimport { verifySqlSchema } from './schema-verify/verify-sql-schema';\nimport { collectSupportedCodecTypeIds, readMarker } from './verify';\n\nfunction extractCodecTypeIdsFromContract(contract: unknown): readonly string[] {\n const typeIds = new Set<string>();\n\n // Type guard for SQL contract structure\n if (\n typeof contract === 'object' &&\n contract !== null &&\n 'storage' in contract &&\n typeof contract.storage === 'object' &&\n contract.storage !== null &&\n 'tables' in contract.storage\n ) {\n const storage = contract.storage as { tables?: Record<string, unknown> };\n if (storage.tables && typeof storage.tables === 'object') {\n for (const table of Object.values(storage.tables)) {\n if (\n typeof table === 'object' &&\n table !== null &&\n 'columns' in table &&\n typeof table.columns === 'object' &&\n table.columns !== null\n ) {\n const columns = table.columns as Record<string, { codecId: string } | undefined>;\n for (const column of Object.values(columns)) {\n if (\n column &&\n typeof column === 'object' &&\n 'codecId' in column &&\n typeof column.codecId === 'string'\n ) {\n typeIds.add(column.codecId);\n }\n }\n }\n }\n }\n }\n\n return Array.from(typeIds).sort();\n}\n\nfunction createVerifyResult(options: {\n ok: boolean;\n code?: string;\n summary: string;\n contractStorageHash: string;\n contractProfileHash?: string;\n marker?: ContractMarkerRecord;\n expectedTargetId: string;\n actualTargetId?: string;\n missingCodecs?: readonly string[];\n codecCoverageSkipped?: boolean;\n configPath?: string;\n contractPath: string;\n totalTime: number;\n}): VerifyDatabaseResult {\n const contract: { storageHash: string; profileHash?: string } = {\n storageHash: options.contractStorageHash,\n };\n if (options.contractProfileHash) {\n contract.profileHash = options.contractProfileHash;\n }\n\n const target: { expected: string; actual?: string } = {\n expected: options.expectedTargetId,\n };\n if (options.actualTargetId) {\n target.actual = options.actualTargetId;\n }\n\n const meta: { contractPath: string; configPath?: string } = {\n contractPath: options.contractPath,\n };\n if (options.configPath) {\n meta.configPath = options.configPath;\n }\n\n const result: VerifyDatabaseResult = {\n ok: options.ok,\n summary: options.summary,\n contract,\n target,\n meta,\n timings: {\n total: options.totalTime,\n },\n };\n\n if (options.code) {\n (result as { code?: string }).code = options.code;\n }\n\n if (options.marker) {\n (result as { marker?: { storageHash: string; profileHash: string } }).marker = {\n storageHash: options.marker.storageHash,\n profileHash: options.marker.profileHash,\n };\n }\n\n if (options.missingCodecs) {\n (result as { missingCodecs?: readonly string[] }).missingCodecs = options.missingCodecs;\n }\n\n if (options.codecCoverageSkipped) {\n (result as { codecCoverageSkipped?: boolean }).codecCoverageSkipped =\n options.codecCoverageSkipped;\n }\n\n return result;\n}\n\ninterface SqlTypeMetadata {\n readonly typeId: string;\n readonly familyId: 'sql';\n readonly targetId: string;\n readonly nativeType?: string;\n}\n\ntype SqlTypeMetadataRegistry = Map<string, SqlTypeMetadata>;\n\ninterface SqlFamilyInstanceState {\n readonly operationRegistry: OperationRegistry;\n readonly codecTypeImports: ReadonlyArray<TypesImportSpec>;\n readonly operationTypeImports: ReadonlyArray<TypesImportSpec>;\n readonly extensionIds: ReadonlyArray<string>;\n readonly typeMetadataRegistry: SqlTypeMetadataRegistry;\n}\n\nexport interface SchemaVerifyOptions {\n readonly driver: ControlDriverInstance<'sql', string>;\n readonly contractIR: unknown;\n readonly strict: boolean;\n readonly context?: OperationContext;\n /**\n * Active framework components participating in this composition.\n * All components must have matching familyId ('sql') and targetId.\n */\n readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;\n}\n\nexport interface SqlControlFamilyInstance\n extends ControlFamilyInstance<'sql'>,\n SqlFamilyInstanceState {\n validateContractIR(contractJson: unknown): ContractIR;\n\n verify(options: {\n readonly driver: ControlDriverInstance<'sql', string>;\n readonly contractIR: unknown;\n readonly expectedTargetId: string;\n readonly contractPath: string;\n readonly configPath?: string;\n }): Promise<VerifyDatabaseResult>;\n\n schemaVerify(options: SchemaVerifyOptions): Promise<VerifyDatabaseSchemaResult>;\n\n sign(options: {\n readonly driver: ControlDriverInstance<'sql', string>;\n readonly contractIR: unknown;\n readonly contractPath: string;\n readonly configPath?: string;\n }): Promise<SignDatabaseResult>;\n\n introspect(options: {\n readonly driver: ControlDriverInstance<'sql', string>;\n readonly contractIR?: unknown;\n }): Promise<SqlSchemaIR>;\n\n toSchemaView(schema: SqlSchemaIR): CoreSchemaView;\n\n emitContract(options: { readonly contractIR: ContractIR | unknown }): Promise<EmitContractResult>;\n}\n\nexport type SqlFamilyInstance = SqlControlFamilyInstance;\n\ninterface CreateSqlFamilyInstanceOptions<TTargetId extends string> {\n readonly target: TargetDescriptor<'sql', TTargetId> &\n SqlControlDescriptorWithContributions &\n DescriptorWithStorageTypes;\n readonly adapter: SqlControlAdapterDescriptor<TTargetId> & DescriptorWithStorageTypes;\n readonly extensionPacks: readonly (SqlControlExtensionDescriptor<TTargetId> &\n DescriptorWithStorageTypes)[];\n}\n\nfunction isSqlControlAdapter<TTargetId extends string>(\n value: unknown,\n): value is SqlControlAdapter<TTargetId> {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'introspect' in value &&\n typeof (value as { introspect: unknown }).introspect === 'function'\n );\n}\n\ninterface DescriptorWithStorageTypes {\n readonly targetId?: string | undefined;\n readonly types?:\n | {\n readonly storage?:\n | ReadonlyArray<{\n readonly typeId: string;\n readonly familyId: string;\n readonly targetId: string;\n readonly nativeType?: string | undefined;\n }>\n | undefined;\n }\n | undefined;\n}\n\nfunction buildSqlTypeMetadataRegistry(options: {\n readonly target: DescriptorWithStorageTypes;\n readonly adapter: DescriptorWithStorageTypes & { readonly targetId: string };\n readonly extensionPacks: readonly DescriptorWithStorageTypes[];\n}): SqlTypeMetadataRegistry {\n const { target, adapter, extensionPacks: extensions } = options;\n const registry = new Map<string, SqlTypeMetadata>();\n const targetId = adapter.targetId;\n const descriptors = [target, adapter, ...extensions];\n\n for (const descriptor of descriptors) {\n const types = descriptor.types;\n const storageTypes = types?.storage;\n\n if (!storageTypes) {\n continue;\n }\n\n for (const storageType of storageTypes) {\n if (storageType.familyId === 'sql' && storageType.targetId === targetId) {\n registry.set(storageType.typeId, {\n typeId: storageType.typeId,\n familyId: 'sql',\n targetId: storageType.targetId,\n ...(storageType.nativeType !== undefined ? { nativeType: storageType.nativeType } : {}),\n });\n }\n }\n }\n\n return registry;\n}\n\nexport function createSqlFamilyInstance<TTargetId extends string>(\n options: CreateSqlFamilyInstanceOptions<TTargetId>,\n): SqlFamilyInstance {\n const { target, adapter, extensionPacks: extensions = [] } = options;\n\n const descriptors: SqlControlDescriptorWithContributions[] = [target, adapter, ...extensions];\n\n const operationRegistry = assembleOperationRegistry(descriptors);\n const codecTypeImports = extractCodecTypeImports(descriptors);\n const operationTypeImports = extractOperationTypeImports(descriptors);\n const extensionIds = extractExtensionIds(adapter, target, extensions);\n const parameterizedRenderers = extractParameterizedRenderers(descriptors);\n const parameterizedTypeImports = extractParameterizedTypeImports(descriptors);\n\n const typeMetadataRegistry = buildSqlTypeMetadataRegistry({\n target,\n adapter,\n extensionPacks: extensions,\n });\n\n function stripMappings(contract: unknown): unknown {\n if (typeof contract === 'object' && contract !== null && 'mappings' in contract) {\n const { mappings: _mappings, ...contractIR } = contract as {\n mappings?: unknown;\n [key: string]: unknown;\n };\n return contractIR;\n }\n return contract;\n }\n\n function normalizeProviderContractIR(contract: unknown): ContractIR {\n const contractWithoutMappings = stripMappings(contract);\n const validated = validateContract<SqlContract<SqlStorage>>(contractWithoutMappings);\n const { mappings: _mappings, ...contractIR } = validated;\n return contractIR as ContractIR;\n }\n\n return {\n familyId: 'sql',\n operationRegistry,\n codecTypeImports,\n operationTypeImports,\n extensionIds,\n typeMetadataRegistry,\n\n validateContractIR(contractJson: unknown): ContractIR {\n return normalizeProviderContractIR(contractJson);\n },\n\n async verify(verifyOptions: {\n readonly driver: ControlDriverInstance<'sql', string>;\n readonly contractIR: unknown;\n readonly expectedTargetId: string;\n readonly contractPath: string;\n readonly configPath?: string;\n }): Promise<VerifyDatabaseResult> {\n const { driver, contractIR, expectedTargetId, contractPath, configPath } = verifyOptions;\n const startTime = Date.now();\n\n if (\n typeof contractIR !== 'object' ||\n contractIR === null ||\n !('storageHash' in contractIR) ||\n !('target' in contractIR) ||\n typeof contractIR.storageHash !== 'string' ||\n typeof contractIR.target !== 'string'\n ) {\n throw new Error('Contract is missing required fields: storageHash or target');\n }\n\n const contractStorageHash = contractIR.storageHash;\n const contractProfileHash =\n 'profileHash' in contractIR && typeof contractIR.profileHash === 'string'\n ? contractIR.profileHash\n : undefined;\n const contractTarget = contractIR.target;\n\n const marker = await readMarker(driver);\n\n let missingCodecs: readonly string[] | undefined;\n let codecCoverageSkipped = false;\n const supportedTypeIds = collectSupportedCodecTypeIds([adapter, target, ...extensions]);\n if (supportedTypeIds.length === 0) {\n codecCoverageSkipped = true;\n } else {\n const supportedSet = new Set(supportedTypeIds);\n const usedTypeIds = extractCodecTypeIdsFromContract(contractIR);\n const missing = usedTypeIds.filter((id) => !supportedSet.has(id));\n if (missing.length > 0) {\n missingCodecs = missing;\n }\n }\n\n if (!marker) {\n const totalTime = Date.now() - startTime;\n return createVerifyResult({\n ok: false,\n code: 'PN-RTM-3001',\n summary: 'Marker missing',\n contractStorageHash,\n expectedTargetId,\n contractPath,\n totalTime,\n ...(contractProfileHash ? { contractProfileHash } : {}),\n ...(missingCodecs ? { missingCodecs } : {}),\n ...(codecCoverageSkipped ? { codecCoverageSkipped } : {}),\n ...(configPath ? { configPath } : {}),\n });\n }\n\n if (contractTarget !== expectedTargetId) {\n const totalTime = Date.now() - startTime;\n return createVerifyResult({\n ok: false,\n code: 'PN-RTM-3003',\n summary: 'Target mismatch',\n contractStorageHash,\n marker,\n expectedTargetId,\n actualTargetId: contractTarget,\n contractPath,\n totalTime,\n ...(contractProfileHash ? { contractProfileHash } : {}),\n ...(missingCodecs ? { missingCodecs } : {}),\n ...(codecCoverageSkipped ? { codecCoverageSkipped } : {}),\n ...(configPath ? { configPath } : {}),\n });\n }\n\n if (marker.storageHash !== contractStorageHash) {\n const totalTime = Date.now() - startTime;\n return createVerifyResult({\n ok: false,\n code: 'PN-RTM-3002',\n summary: 'Hash mismatch',\n contractStorageHash,\n marker,\n expectedTargetId,\n contractPath,\n totalTime,\n ...(contractProfileHash ? { contractProfileHash } : {}),\n ...(missingCodecs ? { missingCodecs } : {}),\n ...(codecCoverageSkipped ? { codecCoverageSkipped } : {}),\n ...(configPath ? { configPath } : {}),\n });\n }\n\n if (contractProfileHash && marker.profileHash !== contractProfileHash) {\n const totalTime = Date.now() - startTime;\n return createVerifyResult({\n ok: false,\n code: 'PN-RTM-3002',\n summary: 'Hash mismatch',\n contractStorageHash,\n contractProfileHash,\n marker,\n expectedTargetId,\n contractPath,\n totalTime,\n ...(missingCodecs ? { missingCodecs } : {}),\n ...(codecCoverageSkipped ? { codecCoverageSkipped } : {}),\n ...(configPath ? { configPath } : {}),\n });\n }\n\n const totalTime = Date.now() - startTime;\n return createVerifyResult({\n ok: true,\n summary: 'Database matches contract',\n contractStorageHash,\n marker,\n expectedTargetId,\n contractPath,\n totalTime,\n ...(contractProfileHash ? { contractProfileHash } : {}),\n ...(missingCodecs ? { missingCodecs } : {}),\n ...(codecCoverageSkipped ? { codecCoverageSkipped } : {}),\n ...(configPath ? { configPath } : {}),\n });\n },\n\n async schemaVerify(options: SchemaVerifyOptions): Promise<VerifyDatabaseSchemaResult> {\n const { driver, contractIR, strict, context, frameworkComponents } = options;\n\n const contract = validateContract<SqlContract<SqlStorage>>(contractIR);\n\n const controlAdapter = adapter.create();\n if (!isSqlControlAdapter(controlAdapter)) {\n throw new Error('Adapter does not implement SqlControlAdapter.introspect()');\n }\n const schemaIR = await controlAdapter.introspect(driver, contractIR);\n\n return verifySqlSchema({\n contract,\n schema: schemaIR,\n strict,\n ...ifDefined('context', context),\n typeMetadataRegistry,\n frameworkComponents,\n // Wire up target-specific normalizers if available\n ...ifDefined('normalizeDefault', controlAdapter.normalizeDefault),\n ...ifDefined('normalizeNativeType', controlAdapter.normalizeNativeType),\n });\n },\n async sign(options: {\n readonly driver: ControlDriverInstance<'sql', string>;\n readonly contractIR: unknown;\n readonly contractPath: string;\n readonly configPath?: string;\n }): Promise<SignDatabaseResult> {\n const { driver, contractIR, contractPath, configPath } = options;\n const startTime = Date.now();\n\n const contract = validateContract<SqlContract<SqlStorage>>(contractIR);\n\n const contractStorageHash = contract.storageHash;\n const contractProfileHash =\n 'profileHash' in contract && typeof contract.profileHash === 'string'\n ? contract.profileHash\n : contractStorageHash;\n const contractTarget = contract.target;\n\n await driver.query(ensureSchemaStatement.sql, ensureSchemaStatement.params);\n await driver.query(ensureTableStatement.sql, ensureTableStatement.params);\n\n const existingMarker = await readMarker(driver);\n\n let markerCreated = false;\n let markerUpdated = false;\n let previousHashes: { storageHash?: string; profileHash?: string } | undefined;\n\n if (!existingMarker) {\n const write = writeContractMarker({\n storageHash: contractStorageHash,\n profileHash: contractProfileHash,\n contractJson: contractIR,\n canonicalVersion: 1,\n });\n await driver.query(write.insert.sql, write.insert.params);\n markerCreated = true;\n } else {\n const existingStorageHash = existingMarker.storageHash;\n const existingProfileHash = existingMarker.profileHash;\n\n const storageHashMatches = existingStorageHash === contractStorageHash;\n const profileHashMatches = existingProfileHash === contractProfileHash;\n\n if (!storageHashMatches || !profileHashMatches) {\n previousHashes = {\n storageHash: existingStorageHash,\n profileHash: existingProfileHash,\n };\n const write = writeContractMarker({\n storageHash: contractStorageHash,\n profileHash: contractProfileHash,\n contractJson: contractIR,\n canonicalVersion: existingMarker.canonicalVersion ?? 1,\n });\n await driver.query(write.update.sql, write.update.params);\n markerUpdated = true;\n }\n }\n\n let summary: string;\n if (markerCreated) {\n summary = 'Database signed (marker created)';\n } else if (markerUpdated) {\n summary = `Database signed (marker updated from ${previousHashes?.storageHash ?? 'unknown'})`;\n } else {\n summary = 'Database already signed with this contract';\n }\n\n const totalTime = Date.now() - startTime;\n\n return {\n ok: true,\n summary,\n contract: {\n storageHash: contractStorageHash,\n profileHash: contractProfileHash,\n },\n target: {\n expected: contractTarget,\n actual: contractTarget,\n },\n marker: {\n created: markerCreated,\n updated: markerUpdated,\n ...(previousHashes ? { previous: previousHashes } : {}),\n },\n meta: {\n contractPath,\n ...(configPath ? { configPath } : {}),\n },\n timings: {\n total: totalTime,\n },\n };\n },\n async readMarker(options: {\n readonly driver: ControlDriverInstance<'sql', string>;\n }): Promise<ContractMarkerRecord | null> {\n return readMarker(options.driver);\n },\n async introspect(options: {\n readonly driver: ControlDriverInstance<'sql', string>;\n readonly contractIR?: unknown;\n }): Promise<SqlSchemaIR> {\n const { driver, contractIR } = options;\n\n const controlAdapter = adapter.create();\n if (!isSqlControlAdapter(controlAdapter)) {\n throw new Error('Adapter does not implement SqlControlAdapter.introspect()');\n }\n return controlAdapter.introspect(driver, contractIR);\n },\n\n toSchemaView(schema: SqlSchemaIR): CoreSchemaView {\n const rootLabel = 'contract';\n\n const tableNodes: readonly SchemaTreeNode[] = Object.entries(schema.tables).map(\n ([tableName, table]: [string, SqlTableIR]) => {\n const children: SchemaTreeNode[] = [];\n\n const columnNodes: SchemaTreeNode[] = [];\n for (const [columnName, column] of Object.entries(table.columns)) {\n const typeDisplay = column.nativeType;\n const nullability = column.nullable ? 'nullable' : 'not nullable';\n const label = `${columnName}: ${typeDisplay} (${nullability})`;\n columnNodes.push({\n kind: 'field',\n id: `column-${tableName}-${columnName}`,\n label,\n meta: {\n nativeType: column.nativeType,\n nullable: column.nullable,\n ...ifDefined('default', column.default),\n },\n });\n }\n\n if (columnNodes.length > 0) {\n children.push({\n kind: 'collection',\n id: `columns-${tableName}`,\n label: 'columns',\n children: columnNodes,\n });\n }\n\n if (table.primaryKey) {\n const pkColumns = table.primaryKey.columns.join(', ');\n children.push({\n kind: 'index',\n id: `primary-key-${tableName}`,\n label: `primary key: ${pkColumns}`,\n meta: {\n columns: table.primaryKey.columns,\n ...(table.primaryKey.name ? { name: table.primaryKey.name } : {}),\n },\n });\n }\n\n for (const unique of table.uniques) {\n const name = unique.name ?? `${tableName}_${unique.columns.join('_')}_unique`;\n const label = `unique ${name}`;\n children.push({\n kind: 'index',\n id: `unique-${tableName}-${name}`,\n label,\n meta: {\n columns: unique.columns,\n unique: true,\n },\n });\n }\n\n for (const index of table.indexes) {\n const name = index.name ?? `${tableName}_${index.columns.join('_')}_idx`;\n const label = index.unique ? `unique index ${name}` : `index ${name}`;\n children.push({\n kind: 'index',\n id: `index-${tableName}-${name}`,\n label,\n meta: {\n columns: index.columns,\n unique: index.unique,\n },\n });\n }\n\n const tableMeta: Record<string, unknown> = {};\n if (table.primaryKey) {\n tableMeta['primaryKey'] = table.primaryKey.columns;\n if (table.primaryKey.name) {\n tableMeta['primaryKeyName'] = table.primaryKey.name;\n }\n }\n if (table.foreignKeys.length > 0) {\n tableMeta['foreignKeys'] = table.foreignKeys.map((fk) => ({\n columns: fk.columns,\n referencedTable: fk.referencedTable,\n referencedColumns: fk.referencedColumns,\n ...(fk.name ? { name: fk.name } : {}),\n }));\n }\n\n const node: SchemaTreeNode = {\n kind: 'entity',\n id: `table-${tableName}`,\n label: `table ${tableName}`,\n ...(Object.keys(tableMeta).length > 0 ? { meta: tableMeta } : {}),\n ...(children.length > 0 ? { children: children as readonly SchemaTreeNode[] } : {}),\n };\n return node;\n },\n );\n\n const extensionNodes: readonly SchemaTreeNode[] = schema.extensions.map((extName) => ({\n kind: 'extension',\n id: `extension-${extName}`,\n label: `${extName} extension is enabled`,\n }));\n\n const rootChildren = [...tableNodes, ...extensionNodes];\n\n const rootNode: SchemaTreeNode = {\n kind: 'root',\n id: 'sql-schema',\n label: rootLabel,\n ...(rootChildren.length > 0 ? { children: rootChildren } : {}),\n };\n\n return {\n root: rootNode,\n };\n },\n\n async emitContract({ contractIR }): Promise<EmitContractResult> {\n const normalizedIR = normalizeProviderContractIR(contractIR);\n\n const result = await emit(\n normalizedIR,\n {\n outputDir: '',\n operationRegistry,\n codecTypeImports,\n operationTypeImports,\n extensionIds,\n parameterizedRenderers,\n parameterizedTypeImports,\n },\n sqlTargetFamilyHook,\n );\n\n return {\n contractJson: result.contractJson,\n contractDts: result.contractDts,\n storageHash: result.storageHash,\n ...(result.executionHash ? { executionHash: result.executionHash } : {}),\n profileHash: result.profileHash,\n };\n },\n };\n}\n","import type { TargetDescriptor } from '@prisma-next/contract/framework-components';\nimport type {\n ControlFamilyDescriptor,\n ControlPlaneStack,\n} from '@prisma-next/core-control-plane/types';\nimport { sqlTargetFamilyHook } from '@prisma-next/sql-contract-emitter';\nimport type { SqlControlDescriptorWithContributions } from './assembly';\nimport { createSqlFamilyInstance, type SqlControlFamilyInstance } from './control-instance';\nimport type {\n SqlControlAdapterDescriptor,\n SqlControlExtensionDescriptor,\n} from './migrations/types';\n\nexport class SqlFamilyDescriptor\n implements ControlFamilyDescriptor<'sql', SqlControlFamilyInstance>\n{\n readonly kind = 'family' as const;\n readonly id = 'sql';\n readonly familyId = 'sql' as const;\n readonly version = '0.0.1';\n readonly hook = sqlTargetFamilyHook;\n\n create<TTargetId extends string>(\n stack: ControlPlaneStack<'sql', TTargetId>,\n ): SqlControlFamilyInstance {\n const target = stack.target as unknown as TargetDescriptor<'sql', TTargetId> &\n SqlControlDescriptorWithContributions;\n const adapter = stack.adapter as unknown as SqlControlAdapterDescriptor<TTargetId>;\n const extensionPacks =\n stack.extensionPacks as unknown as readonly SqlControlExtensionDescriptor<TTargetId>[];\n return createSqlFamilyInstance({\n target,\n adapter,\n extensionPacks,\n });\n }\n}\n","import type { ColumnDefault } from '@prisma-next/contract/types';\nimport type { MigrationPlannerConflict } from '@prisma-next/core-control-plane/types';\nimport type {\n ForeignKey,\n Index,\n SqlStorage,\n StorageColumn,\n StorageTable,\n UniqueConstraint,\n} from '@prisma-next/sql-contract/types';\nimport type {\n SqlColumnIR,\n SqlForeignKeyIR,\n SqlIndexIR,\n SqlSchemaIR,\n SqlTableIR,\n SqlUniqueIR,\n} from '@prisma-next/sql-schema-ir/types';\nimport { ifDefined } from '@prisma-next/utils/defined';\n\nfunction convertDefault(def: ColumnDefault): string {\n if (def.kind === 'function') {\n return def.expression;\n }\n if (typeof def.value === 'string') {\n return `'${def.value.replaceAll(\"'\", \"''\")}'`;\n }\n return String(def.value);\n}\n\n/**\n * Target-specific callback that expands a column's base `nativeType` and optional\n * `typeParams` into the fully-qualified type string used by the database\n * (e.g. `character` + `{ length: 36 }` → `character(36)`).\n *\n * This lives in the family layer as a callback rather than importing a concrete\n * implementation because each target (Postgres, MySQL, SQLite, …) has its own\n * parameterization syntax. The target wires its expander when calling\n * `contractToSchemaIR`, keeping the family layer target-agnostic.\n */\nexport type NativeTypeExpander = (input: {\n readonly nativeType: string;\n readonly codecId?: string;\n readonly typeParams?: Record<string, unknown>;\n}) => string;\n\nfunction convertColumn(\n name: string,\n column: StorageColumn,\n expandNativeType?: NativeTypeExpander,\n): SqlColumnIR {\n const nativeType = expandNativeType\n ? expandNativeType({\n nativeType: column.nativeType,\n codecId: column.codecId,\n ...ifDefined('typeParams', column.typeParams),\n })\n : column.nativeType;\n return {\n name,\n nativeType,\n nullable: column.nullable,\n ...(column.default != null ? { default: convertDefault(column.default) } : {}),\n };\n}\n\nfunction convertUnique(unique: UniqueConstraint): SqlUniqueIR {\n return {\n columns: unique.columns,\n ...(unique.name != null ? { name: unique.name } : {}),\n };\n}\n\nfunction convertIndex(index: Index): SqlIndexIR {\n return {\n columns: index.columns,\n unique: false,\n ...(index.name != null ? { name: index.name } : {}),\n };\n}\n\nfunction convertForeignKey(fk: ForeignKey): SqlForeignKeyIR {\n return {\n columns: fk.columns,\n referencedTable: fk.references.table,\n referencedColumns: fk.references.columns,\n ...(fk.name != null ? { name: fk.name } : {}),\n };\n}\n\nfunction convertTable(\n name: string,\n table: StorageTable,\n expandNativeType?: NativeTypeExpander,\n): SqlTableIR {\n const columns: Record<string, SqlColumnIR> = {};\n for (const [colName, colDef] of Object.entries(table.columns)) {\n columns[colName] = convertColumn(colName, colDef, expandNativeType);\n }\n\n return {\n name,\n columns,\n ...(table.primaryKey != null ? { primaryKey: table.primaryKey } : {}),\n foreignKeys: table.foreignKeys.map(convertForeignKey),\n uniques: table.uniques.map(convertUnique),\n indexes: table.indexes.map(convertIndex),\n };\n}\n\n/**\n * Detects destructive changes between two contract storages.\n *\n * The additive-only planner silently ignores removals (tables, columns).\n * This function detects those removals so callers can report them as conflicts\n * rather than silently producing an empty plan.\n *\n * Returns an empty array if no destructive changes are found.\n */\nexport function detectDestructiveChanges(\n from: SqlStorage | null,\n to: SqlStorage,\n): readonly MigrationPlannerConflict[] {\n if (!from) return [];\n\n const hasOwn = (value: object, key: string): boolean => Object.hasOwn(value, key);\n\n const conflicts: MigrationPlannerConflict[] = [];\n\n for (const tableName of Object.keys(from.tables)) {\n if (!hasOwn(to.tables, tableName)) {\n conflicts.push({\n kind: 'tableRemoved',\n summary: `Table \"${tableName}\" was removed`,\n });\n continue;\n }\n\n const toTable = to.tables[tableName] as StorageTable;\n const fromTable = from.tables[tableName];\n if (!fromTable) continue;\n\n for (const columnName of Object.keys(fromTable.columns)) {\n if (!hasOwn(toTable.columns, columnName)) {\n conflicts.push({\n kind: 'columnRemoved',\n summary: `Column \"${tableName}\".\"${columnName}\" was removed`,\n });\n }\n }\n }\n\n return conflicts;\n}\n\n/**\n * Converts a contract's `SqlStorage` to `SqlSchemaIR`.\n *\n * Drops codec metadata (`codecId`, `typeRef`) since the schema IR only represents structural\n * information. When `expandNativeType` is provided, parameterized types are expanded\n * (e.g. `character` + `{ length: 36 }` → `character(36)`) so the resulting IR compares\n * correctly against the \"to\" contract during planning.\n *\n * `extensions` is always `[]` — the planner resolves extension dependencies from framework\n * components, and an empty array means \"nothing installed yet\" which is correct for the\n * \"from\" side of a diff.\n */\nexport function contractToSchemaIR(\n storage: SqlStorage,\n expandNativeType?: NativeTypeExpander,\n): SqlSchemaIR {\n const tables: Record<string, SqlTableIR> = {};\n for (const [tableName, tableDef] of Object.entries(storage.tables)) {\n tables[tableName] = convertTable(tableName, tableDef, expandNativeType);\n }\n\n return {\n tables,\n extensions: [],\n };\n}\n","import type { NotOk, Ok } from '@prisma-next/utils/result';\nimport { notOk, ok } from '@prisma-next/utils/result';\nimport type {\n AnyRecord,\n CreateSqlMigrationPlanOptions,\n SqlMigrationPlan,\n SqlMigrationPlanOperation,\n SqlMigrationPlanOperationStep,\n SqlMigrationPlanOperationTarget,\n SqlMigrationRunnerErrorCode,\n SqlMigrationRunnerFailure,\n SqlMigrationRunnerSuccessValue,\n SqlPlannerConflict,\n SqlPlannerFailureResult,\n SqlPlannerSuccessResult,\n} from './types';\n\nconst readOnlyEmptyObject: Record<string, never> = Object.freeze({});\n\nfunction cloneRecord<T extends AnyRecord>(value: T): T {\n if (value === readOnlyEmptyObject) {\n return value;\n }\n return Object.freeze({ ...value }) as T;\n}\n\nfunction freezeSteps(\n steps: readonly SqlMigrationPlanOperationStep[],\n): readonly SqlMigrationPlanOperationStep[] {\n if (steps.length === 0) {\n return Object.freeze([]);\n }\n return Object.freeze(\n steps.map((step) =>\n Object.freeze({\n description: step.description,\n sql: step.sql,\n ...(step.meta ? { meta: cloneRecord(step.meta) } : {}),\n }),\n ),\n );\n}\n\nfunction freezeDetailsValue<T>(value: T): T {\n // Primitives and null/undefined are already immutable, return as-is\n if (value === null || value === undefined) {\n return value;\n }\n if (typeof value !== 'object') {\n return value;\n }\n // Arrays: shallow clone and freeze\n if (Array.isArray(value)) {\n return Object.freeze([...value]) as T;\n }\n // Objects: shallow clone and freeze (matching cloneRecord pattern)\n return Object.freeze({ ...value }) as T;\n}\n\nfunction freezeTargetDetails<TTargetDetails>(\n target: SqlMigrationPlanOperationTarget<TTargetDetails>,\n): SqlMigrationPlanOperationTarget<TTargetDetails> {\n return Object.freeze({\n id: target.id,\n ...(target.details !== undefined ? { details: freezeDetailsValue(target.details) } : {}),\n });\n}\n\nfunction freezeOperation<TTargetDetails>(\n operation: SqlMigrationPlanOperation<TTargetDetails>,\n): SqlMigrationPlanOperation<TTargetDetails> {\n return Object.freeze({\n id: operation.id,\n label: operation.label,\n ...(operation.summary ? { summary: operation.summary } : {}),\n operationClass: operation.operationClass,\n target: freezeTargetDetails(operation.target),\n precheck: freezeSteps(operation.precheck),\n execute: freezeSteps(operation.execute),\n postcheck: freezeSteps(operation.postcheck),\n ...(operation.meta ? { meta: cloneRecord(operation.meta) } : {}),\n });\n}\n\nfunction freezeOperations<TTargetDetails>(\n operations: readonly SqlMigrationPlanOperation<TTargetDetails>[],\n): readonly SqlMigrationPlanOperation<TTargetDetails>[] {\n if (operations.length === 0) {\n return Object.freeze([]);\n }\n return Object.freeze(operations.map((operation) => freezeOperation(operation)));\n}\n\nexport function createMigrationPlan<TTargetDetails>(\n options: CreateSqlMigrationPlanOptions<TTargetDetails>,\n): SqlMigrationPlan<TTargetDetails> {\n return Object.freeze({\n targetId: options.targetId,\n ...(options.origin !== undefined\n ? { origin: options.origin ? Object.freeze({ ...options.origin }) : null }\n : {}),\n destination: Object.freeze({ ...options.destination }),\n operations: freezeOperations(options.operations),\n ...(options.meta ? { meta: cloneRecord(options.meta) } : {}),\n });\n}\n\nexport function plannerSuccess<TTargetDetails>(\n plan: SqlMigrationPlan<TTargetDetails>,\n): SqlPlannerSuccessResult<TTargetDetails> {\n return Object.freeze({\n kind: 'success',\n plan,\n });\n}\n\nexport function plannerFailure(conflicts: readonly SqlPlannerConflict[]): SqlPlannerFailureResult {\n return Object.freeze({\n kind: 'failure' as const,\n conflicts: Object.freeze(\n conflicts.map((conflict) =>\n Object.freeze({\n kind: conflict.kind,\n summary: conflict.summary,\n ...(conflict.why ? { why: conflict.why } : {}),\n ...(conflict.location ? { location: Object.freeze({ ...conflict.location }) } : {}),\n ...(conflict.meta ? { meta: cloneRecord(conflict.meta) } : {}),\n }),\n ),\n ),\n });\n}\n\n/**\n * Creates a successful migration runner result.\n */\nexport function runnerSuccess(value: {\n operationsPlanned: number;\n operationsExecuted: number;\n}): Ok<SqlMigrationRunnerSuccessValue> {\n return ok(\n Object.freeze({\n operationsPlanned: value.operationsPlanned,\n operationsExecuted: value.operationsExecuted,\n }),\n );\n}\n\n/**\n * Creates a failed migration runner result.\n */\nexport function runnerFailure(\n code: SqlMigrationRunnerErrorCode,\n summary: string,\n options?: { why?: string; meta?: AnyRecord },\n): NotOk<SqlMigrationRunnerFailure> {\n const failure: SqlMigrationRunnerFailure = Object.freeze({\n code,\n summary,\n ...(options?.why ? { why: options.why } : {}),\n ...(options?.meta ? { meta: cloneRecord(options.meta) } : {}),\n });\n return notOk(failure);\n}\n","import type { MigrationOperationPolicy } from '@prisma-next/core-control-plane/types';\n\n/**\n * Policy used by `db init`: additive-only operations, no widening/destructive steps.\n */\nexport const INIT_ADDITIVE_POLICY: MigrationOperationPolicy = Object.freeze({\n allowedOperationClasses: Object.freeze(['additive'] as const),\n});\n","import { SqlFamilyDescriptor } from '../core/control-descriptor';\n\n// Re-export core types from canonical source\nexport type {\n MigrationOperationClass,\n MigrationOperationPolicy,\n MigrationPlan,\n MigrationPlanner,\n MigrationPlannerConflict,\n MigrationPlannerResult,\n MigrationPlanOperation,\n TargetMigrationsCapability,\n} from '@prisma-next/core-control-plane/types';\nexport type { SqlControlDescriptorWithContributions } from '../core/assembly';\nexport { extractCodecControlHooks } from '../core/assembly';\nexport type { SchemaVerifyOptions, SqlControlFamilyInstance } from '../core/control-instance';\nexport type { NativeTypeExpander } from '../core/migrations/contract-to-schema-ir';\n// Contract → SchemaIR conversion for offline migration planning\nexport {\n contractToSchemaIR,\n detectDestructiveChanges,\n} from '../core/migrations/contract-to-schema-ir';\nexport {\n createMigrationPlan,\n plannerFailure,\n plannerSuccess,\n runnerFailure,\n runnerSuccess,\n} from '../core/migrations/plan-helpers';\nexport { INIT_ADDITIVE_POLICY } from '../core/migrations/policies';\n// SQL-specific types\nexport type {\n CodecControlHooks,\n ComponentDatabaseDependencies,\n ComponentDatabaseDependency,\n CreateSqlMigrationPlanOptions,\n ExpandNativeTypeInput,\n SqlControlAdapterDescriptor,\n SqlControlExtensionDescriptor,\n SqlControlStaticContributions,\n SqlControlTargetDescriptor,\n SqlMigrationPlan,\n SqlMigrationPlanContractInfo,\n SqlMigrationPlanner,\n SqlMigrationPlannerPlanOptions,\n SqlMigrationPlanOperation,\n SqlMigrationPlanOperationStep,\n SqlMigrationPlanOperationTarget,\n SqlMigrationRunner,\n SqlMigrationRunnerErrorCode,\n SqlMigrationRunnerExecuteCallbacks,\n SqlMigrationRunnerExecuteOptions,\n SqlMigrationRunnerFailure,\n SqlMigrationRunnerResult,\n SqlMigrationRunnerSuccessValue,\n SqlPlannerConflict,\n SqlPlannerConflictKind,\n SqlPlannerConflictLocation,\n SqlPlannerFailureResult,\n SqlPlannerResult,\n SqlPlannerSuccessResult,\n StorageTypePlanResult,\n} from '../core/migrations/types';\n\nexport default new SqlFamilyDescriptor();\n"],"mappings":";;;;;;;;;;;AA6CA,SAAS,gCAAgC,UAAsC;CAC7E,MAAM,0BAAU,IAAI,KAAa;AAGjC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as isUniqueConstraintSatisfied, n as arraysEqual, r as isIndexSatisfied, t as verifySqlSchema } from "./verify-sql-schema-CpAVEi8A.mjs";
2
3
 
3
4
  export { arraysEqual, isIndexSatisfied, isUniqueConstraintSatisfied, verifyDatabaseDependencies, verifySqlSchema };
package/package.json CHANGED
@@ -1,31 +1,31 @@
1
1
  {
2
2
  "name": "@prisma-next/family-sql",
3
- "version": "0.3.0-dev.55",
3
+ "version": "0.3.0-dev.63",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "SQL family descriptor for Prisma Next",
7
7
  "dependencies": {
8
8
  "arktype": "^2.0.0",
9
- "@prisma-next/cli": "0.3.0-dev.55",
10
- "@prisma-next/contract": "0.3.0-dev.55",
11
- "@prisma-next/core-control-plane": "0.3.0-dev.55",
12
- "@prisma-next/operations": "0.3.0-dev.55",
13
- "@prisma-next/core-execution-plane": "0.3.0-dev.55",
14
- "@prisma-next/sql-contract": "0.3.0-dev.55",
15
- "@prisma-next/sql-contract-emitter": "0.3.0-dev.55",
16
- "@prisma-next/sql-contract-ts": "0.3.0-dev.55",
17
- "@prisma-next/sql-operations": "0.3.0-dev.55",
18
- "@prisma-next/runtime-executor": "0.3.0-dev.55",
19
- "@prisma-next/sql-relational-core": "0.3.0-dev.55",
20
- "@prisma-next/sql-runtime": "0.3.0-dev.55",
21
- "@prisma-next/utils": "0.3.0-dev.55",
22
- "@prisma-next/sql-schema-ir": "0.3.0-dev.55"
9
+ "@prisma-next/cli": "0.3.0-dev.63",
10
+ "@prisma-next/contract": "0.3.0-dev.63",
11
+ "@prisma-next/core-control-plane": "0.3.0-dev.63",
12
+ "@prisma-next/core-execution-plane": "0.3.0-dev.63",
13
+ "@prisma-next/runtime-executor": "0.3.0-dev.63",
14
+ "@prisma-next/sql-contract": "0.3.0-dev.63",
15
+ "@prisma-next/sql-contract-emitter": "0.3.0-dev.63",
16
+ "@prisma-next/sql-contract-ts": "0.3.0-dev.63",
17
+ "@prisma-next/operations": "0.3.0-dev.63",
18
+ "@prisma-next/sql-operations": "0.3.0-dev.63",
19
+ "@prisma-next/sql-relational-core": "0.3.0-dev.63",
20
+ "@prisma-next/sql-runtime": "0.3.0-dev.63",
21
+ "@prisma-next/sql-schema-ir": "0.3.0-dev.63",
22
+ "@prisma-next/utils": "0.3.0-dev.63"
23
23
  },
24
24
  "devDependencies": {
25
25
  "tsdown": "0.18.4",
26
26
  "typescript": "5.9.3",
27
27
  "vitest": "4.0.17",
28
- "@prisma-next/driver-postgres": "0.3.0-dev.55",
28
+ "@prisma-next/driver-postgres": "0.3.0-dev.63",
29
29
  "@prisma-next/test-utils": "0.0.1",
30
30
  "@prisma-next/tsconfig": "0.0.0",
31
31
  "@prisma-next/tsdown": "0.0.0"
@@ -0,0 +1,181 @@
1
+ import type { ColumnDefault } from '@prisma-next/contract/types';
2
+ import type { MigrationPlannerConflict } from '@prisma-next/core-control-plane/types';
3
+ import type {
4
+ ForeignKey,
5
+ Index,
6
+ SqlStorage,
7
+ StorageColumn,
8
+ StorageTable,
9
+ UniqueConstraint,
10
+ } from '@prisma-next/sql-contract/types';
11
+ import type {
12
+ SqlColumnIR,
13
+ SqlForeignKeyIR,
14
+ SqlIndexIR,
15
+ SqlSchemaIR,
16
+ SqlTableIR,
17
+ SqlUniqueIR,
18
+ } from '@prisma-next/sql-schema-ir/types';
19
+ import { ifDefined } from '@prisma-next/utils/defined';
20
+
21
+ function convertDefault(def: ColumnDefault): string {
22
+ if (def.kind === 'function') {
23
+ return def.expression;
24
+ }
25
+ if (typeof def.value === 'string') {
26
+ return `'${def.value.replaceAll("'", "''")}'`;
27
+ }
28
+ return String(def.value);
29
+ }
30
+
31
+ /**
32
+ * Target-specific callback that expands a column's base `nativeType` and optional
33
+ * `typeParams` into the fully-qualified type string used by the database
34
+ * (e.g. `character` + `{ length: 36 }` → `character(36)`).
35
+ *
36
+ * This lives in the family layer as a callback rather than importing a concrete
37
+ * implementation because each target (Postgres, MySQL, SQLite, …) has its own
38
+ * parameterization syntax. The target wires its expander when calling
39
+ * `contractToSchemaIR`, keeping the family layer target-agnostic.
40
+ */
41
+ export type NativeTypeExpander = (input: {
42
+ readonly nativeType: string;
43
+ readonly codecId?: string;
44
+ readonly typeParams?: Record<string, unknown>;
45
+ }) => string;
46
+
47
+ function convertColumn(
48
+ name: string,
49
+ column: StorageColumn,
50
+ expandNativeType?: NativeTypeExpander,
51
+ ): SqlColumnIR {
52
+ const nativeType = expandNativeType
53
+ ? expandNativeType({
54
+ nativeType: column.nativeType,
55
+ codecId: column.codecId,
56
+ ...ifDefined('typeParams', column.typeParams),
57
+ })
58
+ : column.nativeType;
59
+ return {
60
+ name,
61
+ nativeType,
62
+ nullable: column.nullable,
63
+ ...(column.default != null ? { default: convertDefault(column.default) } : {}),
64
+ };
65
+ }
66
+
67
+ function convertUnique(unique: UniqueConstraint): SqlUniqueIR {
68
+ return {
69
+ columns: unique.columns,
70
+ ...(unique.name != null ? { name: unique.name } : {}),
71
+ };
72
+ }
73
+
74
+ function convertIndex(index: Index): SqlIndexIR {
75
+ return {
76
+ columns: index.columns,
77
+ unique: false,
78
+ ...(index.name != null ? { name: index.name } : {}),
79
+ };
80
+ }
81
+
82
+ function convertForeignKey(fk: ForeignKey): SqlForeignKeyIR {
83
+ return {
84
+ columns: fk.columns,
85
+ referencedTable: fk.references.table,
86
+ referencedColumns: fk.references.columns,
87
+ ...(fk.name != null ? { name: fk.name } : {}),
88
+ };
89
+ }
90
+
91
+ function convertTable(
92
+ name: string,
93
+ table: StorageTable,
94
+ expandNativeType?: NativeTypeExpander,
95
+ ): SqlTableIR {
96
+ const columns: Record<string, SqlColumnIR> = {};
97
+ for (const [colName, colDef] of Object.entries(table.columns)) {
98
+ columns[colName] = convertColumn(colName, colDef, expandNativeType);
99
+ }
100
+
101
+ return {
102
+ name,
103
+ columns,
104
+ ...(table.primaryKey != null ? { primaryKey: table.primaryKey } : {}),
105
+ foreignKeys: table.foreignKeys.map(convertForeignKey),
106
+ uniques: table.uniques.map(convertUnique),
107
+ indexes: table.indexes.map(convertIndex),
108
+ };
109
+ }
110
+
111
+ /**
112
+ * Detects destructive changes between two contract storages.
113
+ *
114
+ * The additive-only planner silently ignores removals (tables, columns).
115
+ * This function detects those removals so callers can report them as conflicts
116
+ * rather than silently producing an empty plan.
117
+ *
118
+ * Returns an empty array if no destructive changes are found.
119
+ */
120
+ export function detectDestructiveChanges(
121
+ from: SqlStorage | null,
122
+ to: SqlStorage,
123
+ ): readonly MigrationPlannerConflict[] {
124
+ if (!from) return [];
125
+
126
+ const hasOwn = (value: object, key: string): boolean => Object.hasOwn(value, key);
127
+
128
+ const conflicts: MigrationPlannerConflict[] = [];
129
+
130
+ for (const tableName of Object.keys(from.tables)) {
131
+ if (!hasOwn(to.tables, tableName)) {
132
+ conflicts.push({
133
+ kind: 'tableRemoved',
134
+ summary: `Table "${tableName}" was removed`,
135
+ });
136
+ continue;
137
+ }
138
+
139
+ const toTable = to.tables[tableName] as StorageTable;
140
+ const fromTable = from.tables[tableName];
141
+ if (!fromTable) continue;
142
+
143
+ for (const columnName of Object.keys(fromTable.columns)) {
144
+ if (!hasOwn(toTable.columns, columnName)) {
145
+ conflicts.push({
146
+ kind: 'columnRemoved',
147
+ summary: `Column "${tableName}"."${columnName}" was removed`,
148
+ });
149
+ }
150
+ }
151
+ }
152
+
153
+ return conflicts;
154
+ }
155
+
156
+ /**
157
+ * Converts a contract's `SqlStorage` to `SqlSchemaIR`.
158
+ *
159
+ * Drops codec metadata (`codecId`, `typeRef`) since the schema IR only represents structural
160
+ * information. When `expandNativeType` is provided, parameterized types are expanded
161
+ * (e.g. `character` + `{ length: 36 }` → `character(36)`) so the resulting IR compares
162
+ * correctly against the "to" contract during planning.
163
+ *
164
+ * `extensions` is always `[]` — the planner resolves extension dependencies from framework
165
+ * components, and an empty array means "nothing installed yet" which is correct for the
166
+ * "from" side of a diff.
167
+ */
168
+ export function contractToSchemaIR(
169
+ storage: SqlStorage,
170
+ expandNativeType?: NativeTypeExpander,
171
+ ): SqlSchemaIR {
172
+ const tables: Record<string, SqlTableIR> = {};
173
+ for (const [tableName, tableDef] of Object.entries(storage.tables)) {
174
+ tables[tableName] = convertTable(tableName, tableDef, expandNativeType);
175
+ }
176
+
177
+ return {
178
+ tables,
179
+ extensions: [],
180
+ };
181
+ }
@@ -14,6 +14,12 @@ export type {
14
14
  export type { SqlControlDescriptorWithContributions } from '../core/assembly';
15
15
  export { extractCodecControlHooks } from '../core/assembly';
16
16
  export type { SchemaVerifyOptions, SqlControlFamilyInstance } from '../core/control-instance';
17
+ export type { NativeTypeExpander } from '../core/migrations/contract-to-schema-ir';
18
+ // Contract → SchemaIR conversion for offline migration planning
19
+ export {
20
+ contractToSchemaIR,
21
+ detectDestructiveChanges,
22
+ } from '../core/migrations/contract-to-schema-ir';
17
23
  export {
18
24
  createMigrationPlan,
19
25
  plannerFailure,