@prisma-next/emitter 0.3.0-dev.6 → 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
@@ -6,7 +6,7 @@ Contract emission engine that transforms authored data models into canonical JSO
6
6
 
7
7
  The emitter is the core of Prisma Next's contract-first architecture. It takes authored data models (from PSL or TypeScript builders) and produces two deterministic artifacts:
8
8
 
9
- 1. **`contract.json`** — Canonical JSON representation of the data contract with embedded `coreHash` and `profileHash`. Callers may add `_generated` metadata field to indicate it's a generated artifact (excluded from canonicalization/hashing).
9
+ 1. **`contract.json`** — Canonical JSON representation of the data contract with embedded `storageHash` and optional `executionHash`/`profileHash`. Callers may add `_generated` metadata field to indicate it's a generated artifact (excluded from canonicalization/hashing).
10
10
  2. **`contract.d.ts`** — TypeScript type definitions used by query builders and tooling (types-only, no runtime code). Includes warning header comments generated by target family hooks to indicate it's a generated file.
11
11
 
12
12
  The emitter is target-family-agnostic and uses a pluggable hook system (`TargetFamilyHook`) to handle family-specific validation and type generation. This keeps the core thin while allowing SQL, Document, and other target families to extend emission behavior.
@@ -19,7 +19,7 @@ Provide a deterministic, verifiable representation of the application's data con
19
19
 
20
20
  - **Parse**: Accept contract IR (Intermediate Representation) from authoring surfaces
21
21
  - **Validate**: Core structure validation plus family-specific type and structure validation via hooks
22
- - **Canonicalize**: Compute `coreHash` (schema meaning) and `profileHash` (capabilities/pins) from canonical JSON
22
+ - **Canonicalize**: Compute `storageHash` (schema meaning), `executionHash` (execution defaults), and `profileHash` (capabilities/pins) from canonical JSON
23
23
  - **Emit**: Generate `contract.json` and `contract.d.ts` with family-specific type generation
24
24
  - **Descriptor-Agnostic**: The emitter is completely agnostic to how descriptors are produced. It receives pre-assembled `OperationRegistry`, `codecTypeImports`, `operationTypeImports`, and `extensionIds` from the CLI or family helpers—no pack manifest parsing happens inside the emitter.
25
25
 
@@ -90,7 +90,8 @@ flowchart TD
90
90
  - **Note**: `TargetFamilyHook`, `ValidationContext`, and `TypesImportSpec` types are defined in `@prisma-next/contract/types` (shared plane) and re-exported from this package for backward compatibility.
91
91
 
92
92
  ### Hashing (`hashing.ts`)
93
- - `computeCoreHash`: SHA-256 of schema structure (models, storage, relations)
93
+ - `computeStorageHash`: SHA-256 of schema structure (models, storage, relations)
94
+ - `computeExecutionHash`: SHA-256 of execution defaults
94
95
  - `computeProfileHash`: SHA-256 of capabilities and adapter pins
95
96
 
96
97
  ### Canonicalization (`canonicalization.ts`)
@@ -121,7 +122,7 @@ This package is part of the **framework domain**, **tooling layer**, **migration
121
122
 
122
123
  ## Related ADRs
123
124
 
124
- - [ADR 004 - Core Hash vs Profile Hash](../../../../docs/architecture%20docs/adrs/ADR%20004%20-%20Core%20Hash%20vs%20Profile%20Hash.md)
125
+ - [ADR 004 - Storage Hash vs Profile Hash](../../../../docs/architecture%20docs/adrs/ADR%20004%20-%20Storage%20Hash%20vs%20Profile%20Hash.md)
125
126
  - [ADR 006 - Dual Authoring Modes](../../../../docs/architecture%20docs/adrs/ADR%20006%20-%20Dual%20Authoring%20Modes.md)
126
127
  - [ADR 007 - Types Only Emission](../../../../docs/architecture%20docs/adrs/ADR%20007%20-%20Types%20Only%20Emission.md)
127
128
  - [ADR 010 - Canonicalization Rules](../../../../docs/architecture%20docs/adrs/ADR%20010%20-%20Canonicalization%20Rules.md)
@@ -156,7 +157,8 @@ const result = await emit(ir, {
156
157
 
157
158
  // result.contractJson: string (JSON) - canonical JSON without _generated metadata
158
159
  // result.contractDts: string (TypeScript definitions) - includes warning header
159
- // result.coreHash: string
160
+ // result.storageHash: string
161
+ // result.executionHash?: string
160
162
  // result.profileHash?: string
161
163
  ```
162
164
 
@@ -0,0 +1,3 @@
1
+ import { EmitOptions, EmitResult, emit } from "@prisma-next/core-control-plane/emission";
2
+ import { TargetFamilyHook, TypesImportSpec, ValidationContext } from "@prisma-next/contract/types";
3
+ export { type EmitOptions, type EmitResult, type TargetFamilyHook, type TypesImportSpec, type ValidationContext, emit };
@@ -0,0 +1,3 @@
1
+ import { emit } from "@prisma-next/core-control-plane/emission";
2
+
3
+ export { emit };
@@ -1,4 +1,7 @@
1
- import { type ContractIR } from '@prisma-next/contract/ir';
1
+ import { ContractIR } from "@prisma-next/contract/ir";
2
+
3
+ //#region test/utils.d.ts
4
+
2
5
  /**
3
6
  * Factory function for creating ContractIR objects in tests.
4
7
  * Provides sensible defaults and allows overriding specific fields.
@@ -7,8 +10,10 @@ import { type ContractIR } from '@prisma-next/contract/ir';
7
10
  * If a field is explicitly set to `undefined` in overrides, it will be omitted
8
11
  * from the result (useful for testing validation of missing fields).
9
12
  */
10
- export declare function createContractIR(overrides?: Partial<ContractIR> & {
11
- coreHash?: string;
12
- profileHash?: string;
13
+ declare function createContractIR(overrides?: Partial<ContractIR> & {
14
+ storageHash?: string;
15
+ profileHash?: string;
13
16
  }): ContractIR;
14
- //# sourceMappingURL=utils.d.ts.map
17
+ //#endregion
18
+ export { createContractIR };
19
+ //# sourceMappingURL=utils.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.mts","names":[],"sources":["../../test/utils.ts"],"sourcesContent":[],"mappings":";;;;;;AAUA;;;;;;iBAAgB,gBAAA,aACH,QAAQ;;;IAClB"}
@@ -0,0 +1,59 @@
1
+ import { irHeader, irMeta } from "@prisma-next/contract/ir";
2
+
3
+ //#region test/utils.ts
4
+ /**
5
+ * Factory function for creating ContractIR objects in tests.
6
+ * Provides sensible defaults and allows overriding specific fields.
7
+ * Uses the emitter factories internally for consistency.
8
+ *
9
+ * If a field is explicitly set to `undefined` in overrides, it will be omitted
10
+ * from the result (useful for testing validation of missing fields).
11
+ */
12
+ function createContractIR(overrides = {}) {
13
+ const hasTarget = "target" in overrides;
14
+ const hasTargetFamily = "targetFamily" in overrides;
15
+ const hasStorageHash = "storageHash" in overrides;
16
+ const hasSchemaVersion = "schemaVersion" in overrides;
17
+ const hasModels = "models" in overrides;
18
+ const hasRelations = "relations" in overrides;
19
+ const hasStorage = "storage" in overrides;
20
+ const hasCapabilities = "capabilities" in overrides;
21
+ const hasExtensionPacks = "extensionPacks" in overrides;
22
+ const hasMeta = "meta" in overrides;
23
+ const hasSources = "sources" in overrides;
24
+ const headerOpts = {};
25
+ if (hasTarget && overrides.target !== void 0) headerOpts.target = overrides.target;
26
+ else if (!hasTarget) headerOpts.target = "postgres";
27
+ if (hasTargetFamily && overrides.targetFamily !== void 0) headerOpts.targetFamily = overrides.targetFamily;
28
+ else if (!hasTargetFamily) headerOpts.targetFamily = "sql";
29
+ if (hasStorageHash && overrides.storageHash !== void 0) headerOpts.storageHash = overrides.storageHash;
30
+ else if (!hasStorageHash) headerOpts.storageHash = "sha256:test";
31
+ if (overrides.profileHash !== void 0) headerOpts.profileHash = overrides.profileHash;
32
+ const header = irHeader(headerOpts);
33
+ const metaOpts = {};
34
+ if (hasCapabilities && overrides.capabilities !== void 0) metaOpts.capabilities = overrides.capabilities;
35
+ else if (!hasCapabilities) metaOpts.capabilities = {};
36
+ if (hasExtensionPacks && overrides.extensionPacks !== void 0) metaOpts.extensionPacks = overrides.extensionPacks;
37
+ else if (!hasExtensionPacks) metaOpts.extensionPacks = {};
38
+ if (hasMeta && overrides.meta !== void 0) metaOpts.meta = overrides.meta;
39
+ else if (!hasMeta) metaOpts.meta = {};
40
+ if (hasSources && overrides.sources !== void 0) metaOpts.sources = overrides.sources;
41
+ else if (!hasSources) metaOpts.sources = {};
42
+ const meta = irMeta(Object.keys(metaOpts).length > 0 ? metaOpts : void 0);
43
+ return {
44
+ schemaVersion: hasSchemaVersion && overrides.schemaVersion !== void 0 ? overrides.schemaVersion : hasSchemaVersion && overrides.schemaVersion === void 0 ? void 0 : header.schemaVersion,
45
+ target: header.target,
46
+ targetFamily: header.targetFamily,
47
+ capabilities: hasCapabilities && overrides.capabilities === void 0 ? void 0 : !hasCapabilities || overrides.capabilities !== void 0 ? meta.capabilities : {},
48
+ extensionPacks: hasExtensionPacks && overrides.extensionPacks === void 0 ? void 0 : !hasExtensionPacks || overrides.extensionPacks !== void 0 ? meta.extensionPacks : {},
49
+ meta: hasMeta && overrides.meta === void 0 ? void 0 : !hasMeta || overrides.meta !== void 0 ? meta.meta : {},
50
+ sources: hasSources && overrides.sources === void 0 ? void 0 : !hasSources || overrides.sources !== void 0 ? meta.sources : {},
51
+ storage: hasStorage && overrides.storage === void 0 ? void 0 : hasStorage && overrides.storage !== void 0 ? overrides.storage : !hasStorage ? { tables: {} } : {},
52
+ models: hasModels && overrides.models === void 0 ? void 0 : hasModels && overrides.models !== void 0 ? overrides.models : !hasModels ? {} : {},
53
+ relations: hasRelations && overrides.relations === void 0 ? void 0 : hasRelations && overrides.relations !== void 0 ? overrides.relations : !hasRelations ? {} : {}
54
+ };
55
+ }
56
+
57
+ //#endregion
58
+ export { createContractIR };
59
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","names":["headerOpts: {\n target?: string;\n targetFamily?: string;\n storageHash?: string;\n profileHash?: string;\n }","metaOpts: {\n capabilities?: Record<string, Record<string, boolean>>;\n extensionPacks?: Record<string, unknown>;\n meta?: Record<string, unknown>;\n sources?: Record<string, unknown>;\n }"],"sources":["../../test/utils.ts"],"sourcesContent":["import { type ContractIR, irHeader, irMeta } from '@prisma-next/contract/ir';\n\n/**\n * Factory function for creating ContractIR objects in tests.\n * Provides sensible defaults and allows overriding specific fields.\n * Uses the emitter factories internally for consistency.\n *\n * If a field is explicitly set to `undefined` in overrides, it will be omitted\n * from the result (useful for testing validation of missing fields).\n */\nexport function createContractIR(\n overrides: Partial<ContractIR> & { storageHash?: string; profileHash?: string } = {},\n): ContractIR {\n // Check if fields are explicitly undefined (not just missing)\n const hasTarget = 'target' in overrides;\n const hasTargetFamily = 'targetFamily' in overrides;\n const hasStorageHash = 'storageHash' in overrides;\n const hasSchemaVersion = 'schemaVersion' in overrides;\n const hasModels = 'models' in overrides;\n const hasRelations = 'relations' in overrides;\n const hasStorage = 'storage' in overrides;\n const hasCapabilities = 'capabilities' in overrides;\n const hasExtensionPacks = 'extensionPacks' in overrides;\n const hasMeta = 'meta' in overrides;\n const hasSources = 'sources' in overrides;\n\n // Build header, omitting fields that are explicitly undefined\n const headerOpts: {\n target?: string;\n targetFamily?: string;\n storageHash?: string;\n profileHash?: string;\n } = {};\n\n if (hasTarget && overrides.target !== undefined) {\n headerOpts.target = overrides.target;\n } else if (!hasTarget) {\n headerOpts.target = 'postgres';\n }\n\n if (hasTargetFamily && overrides.targetFamily !== undefined) {\n headerOpts.targetFamily = overrides.targetFamily;\n } else if (!hasTargetFamily) {\n headerOpts.targetFamily = 'sql';\n }\n\n if (hasStorageHash && overrides.storageHash !== undefined) {\n headerOpts.storageHash = overrides.storageHash;\n } else if (!hasStorageHash) {\n headerOpts.storageHash = 'sha256:test';\n }\n\n // profileHash is not part of ContractIR, but we can accept it for header creation\n if (overrides.profileHash !== undefined) {\n headerOpts.profileHash = overrides.profileHash;\n }\n\n const header = irHeader(\n headerOpts as {\n target: string;\n targetFamily: string;\n storageHash: string;\n profileHash?: string;\n },\n );\n\n // Build meta, handling explicitly undefined fields\n // If a field is explicitly undefined, we'll omit it from the result later\n const metaOpts: {\n capabilities?: Record<string, Record<string, boolean>>;\n extensionPacks?: Record<string, unknown>;\n meta?: Record<string, unknown>;\n sources?: Record<string, unknown>;\n } = {};\n\n if (hasCapabilities && overrides.capabilities !== undefined) {\n metaOpts.capabilities = overrides.capabilities;\n } else if (!hasCapabilities) {\n metaOpts.capabilities = {};\n }\n\n if (hasExtensionPacks && overrides.extensionPacks !== undefined) {\n metaOpts.extensionPacks = overrides.extensionPacks;\n } else if (!hasExtensionPacks) {\n metaOpts.extensionPacks = {};\n }\n\n if (hasMeta && overrides.meta !== undefined) {\n metaOpts.meta = overrides.meta;\n } else if (!hasMeta) {\n metaOpts.meta = {};\n }\n\n if (hasSources && overrides.sources !== undefined) {\n metaOpts.sources = overrides.sources;\n } else if (!hasSources) {\n metaOpts.sources = {};\n }\n\n const meta = irMeta(Object.keys(metaOpts).length > 0 ? metaOpts : undefined);\n\n // Build result by constructing the object directly (ContractIR doesn't include storageHash/profileHash)\n // When fields are explicitly undefined, include them as undefined (tests use type assertions to bypass TS)\n const result = {\n schemaVersion:\n hasSchemaVersion && overrides.schemaVersion !== undefined\n ? overrides.schemaVersion\n : hasSchemaVersion && overrides.schemaVersion === undefined\n ? (undefined as unknown as string)\n : header.schemaVersion,\n target: header.target,\n targetFamily: header.targetFamily,\n // Only include meta fields if they're not explicitly undefined\n capabilities:\n hasCapabilities && overrides.capabilities === undefined\n ? (undefined as unknown as Record<string, Record<string, boolean>>)\n : !hasCapabilities || overrides.capabilities !== undefined\n ? meta.capabilities\n : ({} as Record<string, Record<string, boolean>>),\n extensionPacks:\n hasExtensionPacks && overrides.extensionPacks === undefined\n ? (undefined as unknown as Record<string, unknown>)\n : !hasExtensionPacks || overrides.extensionPacks !== undefined\n ? meta.extensionPacks\n : ({} as Record<string, unknown>),\n meta:\n hasMeta && overrides.meta === undefined\n ? (undefined as unknown as Record<string, unknown>)\n : !hasMeta || overrides.meta !== undefined\n ? meta.meta\n : ({} as Record<string, unknown>),\n sources:\n hasSources && overrides.sources === undefined\n ? (undefined as unknown as Record<string, unknown>)\n : !hasSources || overrides.sources !== undefined\n ? meta.sources\n : ({} as Record<string, unknown>),\n // Only include family sections if they're not explicitly undefined\n storage:\n hasStorage && overrides.storage === undefined\n ? (undefined as unknown as Record<string, unknown>)\n : hasStorage && overrides.storage !== undefined\n ? (overrides.storage as Record<string, unknown>)\n : !hasStorage\n ? ({ tables: {} } as Record<string, unknown>)\n : ({} as Record<string, unknown>),\n models:\n hasModels && overrides.models === undefined\n ? (undefined as unknown as Record<string, unknown>)\n : hasModels && overrides.models !== undefined\n ? (overrides.models as Record<string, unknown>)\n : !hasModels\n ? {}\n : ({} as Record<string, unknown>),\n relations:\n hasRelations && overrides.relations === undefined\n ? (undefined as unknown as Record<string, unknown>)\n : hasRelations && overrides.relations !== undefined\n ? (overrides.relations as Record<string, unknown>)\n : !hasRelations\n ? {}\n : ({} as Record<string, unknown>),\n } as ContractIR;\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;AAUA,SAAgB,iBACd,YAAkF,EAAE,EACxE;CAEZ,MAAM,YAAY,YAAY;CAC9B,MAAM,kBAAkB,kBAAkB;CAC1C,MAAM,iBAAiB,iBAAiB;CACxC,MAAM,mBAAmB,mBAAmB;CAC5C,MAAM,YAAY,YAAY;CAC9B,MAAM,eAAe,eAAe;CACpC,MAAM,aAAa,aAAa;CAChC,MAAM,kBAAkB,kBAAkB;CAC1C,MAAM,oBAAoB,oBAAoB;CAC9C,MAAM,UAAU,UAAU;CAC1B,MAAM,aAAa,aAAa;CAGhC,MAAMA,aAKF,EAAE;AAEN,KAAI,aAAa,UAAU,WAAW,OACpC,YAAW,SAAS,UAAU;UACrB,CAAC,UACV,YAAW,SAAS;AAGtB,KAAI,mBAAmB,UAAU,iBAAiB,OAChD,YAAW,eAAe,UAAU;UAC3B,CAAC,gBACV,YAAW,eAAe;AAG5B,KAAI,kBAAkB,UAAU,gBAAgB,OAC9C,YAAW,cAAc,UAAU;UAC1B,CAAC,eACV,YAAW,cAAc;AAI3B,KAAI,UAAU,gBAAgB,OAC5B,YAAW,cAAc,UAAU;CAGrC,MAAM,SAAS,SACb,WAMD;CAID,MAAMC,WAKF,EAAE;AAEN,KAAI,mBAAmB,UAAU,iBAAiB,OAChD,UAAS,eAAe,UAAU;UACzB,CAAC,gBACV,UAAS,eAAe,EAAE;AAG5B,KAAI,qBAAqB,UAAU,mBAAmB,OACpD,UAAS,iBAAiB,UAAU;UAC3B,CAAC,kBACV,UAAS,iBAAiB,EAAE;AAG9B,KAAI,WAAW,UAAU,SAAS,OAChC,UAAS,OAAO,UAAU;UACjB,CAAC,QACV,UAAS,OAAO,EAAE;AAGpB,KAAI,cAAc,UAAU,YAAY,OACtC,UAAS,UAAU,UAAU;UACpB,CAAC,WACV,UAAS,UAAU,EAAE;CAGvB,MAAM,OAAO,OAAO,OAAO,KAAK,SAAS,CAAC,SAAS,IAAI,WAAW,OAAU;AAiE5E,QA7De;EACb,eACE,oBAAoB,UAAU,kBAAkB,SAC5C,UAAU,gBACV,oBAAoB,UAAU,kBAAkB,SAC7C,SACD,OAAO;EACf,QAAQ,OAAO;EACf,cAAc,OAAO;EAErB,cACE,mBAAmB,UAAU,iBAAiB,SACzC,SACD,CAAC,mBAAmB,UAAU,iBAAiB,SAC7C,KAAK,eACJ,EAAE;EACX,gBACE,qBAAqB,UAAU,mBAAmB,SAC7C,SACD,CAAC,qBAAqB,UAAU,mBAAmB,SACjD,KAAK,iBACJ,EAAE;EACX,MACE,WAAW,UAAU,SAAS,SACzB,SACD,CAAC,WAAW,UAAU,SAAS,SAC7B,KAAK,OACJ,EAAE;EACX,SACE,cAAc,UAAU,YAAY,SAC/B,SACD,CAAC,cAAc,UAAU,YAAY,SACnC,KAAK,UACJ,EAAE;EAEX,SACE,cAAc,UAAU,YAAY,SAC/B,SACD,cAAc,UAAU,YAAY,SACjC,UAAU,UACX,CAAC,aACE,EAAE,QAAQ,EAAE,EAAE,GACd,EAAE;EACb,QACE,aAAa,UAAU,WAAW,SAC7B,SACD,aAAa,UAAU,WAAW,SAC/B,UAAU,SACX,CAAC,YACC,EAAE,GACD,EAAE;EACb,WACE,gBAAgB,UAAU,cAAc,SACnC,SACD,gBAAgB,UAAU,cAAc,SACrC,UAAU,YACX,CAAC,eACC,EAAE,GACD,EAAE;EACd"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma-next/emitter",
3
- "version": "0.3.0-dev.6",
3
+ "version": "0.3.0-dev.63",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [
@@ -10,36 +10,42 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "arktype": "^2.0.0",
13
- "@prisma-next/contract": "0.3.0-dev.6",
14
- "@prisma-next/core-control-plane": "0.3.0-dev.6"
13
+ "@prisma-next/core-control-plane": "0.3.0-dev.63",
14
+ "@prisma-next/contract": "0.3.0-dev.63"
15
15
  },
16
16
  "devDependencies": {
17
17
  "@types/node": "24.10.4",
18
- "@vitest/coverage-v8": "4.0.16",
19
- "tsup": "8.5.1",
18
+ "tsdown": "0.18.4",
20
19
  "typescript": "5.9.3",
21
- "vitest": "4.0.16",
22
- "@prisma-next/operations": "0.3.0-dev.6",
23
- "@prisma-next/test-utils": "0.0.1"
20
+ "vitest": "4.0.17",
21
+ "@prisma-next/test-utils": "0.0.1",
22
+ "@prisma-next/tsconfig": "0.0.0",
23
+ "@prisma-next/operations": "0.3.0-dev.63",
24
+ "@prisma-next/tsdown": "0.0.0"
24
25
  },
25
26
  "exports": {
26
27
  ".": {
27
- "types": "./dist/src/exports/index.d.ts",
28
- "import": "./dist/exports/index.js"
28
+ "types": "./dist/exports/index.d.mts",
29
+ "import": "./dist/exports/index.mjs"
29
30
  },
30
31
  "./test/utils": {
31
- "types": "./dist/test/utils.d.ts",
32
- "import": "./dist/test/utils.js"
32
+ "types": "./dist/test/utils.d.mts",
33
+ "import": "./dist/test/utils.mjs"
33
34
  }
34
35
  },
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/prisma/prisma-next.git",
39
+ "directory": "packages/1-framework/3-tooling/emitter"
40
+ },
35
41
  "scripts": {
36
- "build": "tsup --config tsup.config.ts && tsc --project tsconfig.build.json",
42
+ "build": "tsdown",
37
43
  "test": "vitest run",
38
44
  "test:coverage": "vitest run --coverage",
39
45
  "typecheck": "tsc --project tsconfig.json --noEmit",
40
- "lint": "biome check . --config-path ../../../../biome.json --error-on-warnings",
41
- "lint:fix": "biome check --write . --config-path ../../../../biome.json",
42
- "lint:fix:unsafe": "biome check --write --unsafe . --config-path ../../../../biome.json",
43
- "clean": "node ../../../../scripts/clean.mjs"
46
+ "lint": "biome check . --error-on-warnings",
47
+ "lint:fix": "biome check --write .",
48
+ "lint:fix:unsafe": "biome check --write --unsafe .",
49
+ "clean": "rm -rf dist dist-tsc dist-tsc-prod coverage .tmp-output"
44
50
  }
45
51
  }
@@ -6,7 +6,7 @@ describe('canonicalization', () => {
6
6
  it('orders top-level sections correctly', () => {
7
7
  const ir = createContractIR({
8
8
  capabilities: { postgres: { jsonAgg: true } },
9
- meta: { source: 'test' },
9
+ meta: { emitterVersion: 'test' },
10
10
  });
11
11
 
12
12
  const result = canonicalizeContract(ir);
@@ -17,6 +17,7 @@ describe('canonicalization', () => {
17
17
  const targetFamilyIndex = keys.indexOf('targetFamily');
18
18
  const targetIndex = keys.indexOf('target');
19
19
  const modelsIndex = keys.indexOf('models');
20
+ const relationsIndex = keys.indexOf('relations');
20
21
  const storageIndex = keys.indexOf('storage');
21
22
  const capabilitiesIndex = keys.indexOf('capabilities');
22
23
  const metaIndex = keys.indexOf('meta');
@@ -24,6 +25,8 @@ describe('canonicalization', () => {
24
25
  expect(schemaVersionIndex).toBeLessThan(targetFamilyIndex);
25
26
  expect(targetFamilyIndex).toBeLessThan(targetIndex);
26
27
  expect(targetIndex).toBeLessThan(modelsIndex);
28
+ expect(modelsIndex).toBeLessThan(relationsIndex);
29
+ expect(relationsIndex).toBeLessThan(storageIndex);
27
30
  expect(modelsIndex).toBeLessThan(storageIndex);
28
31
  expect(storageIndex).toBeLessThan(capabilitiesIndex);
29
32
  expect(capabilitiesIndex).toBeLessThan(metaIndex);
@@ -55,6 +58,73 @@ describe('canonicalization', () => {
55
58
  expect(email['nullable']).toBe(true);
56
59
  });
57
60
 
61
+ it.each([
62
+ { nullable: false },
63
+ { nullable: undefined },
64
+ ])('omits nullable:false for columns with defaults (nullable=$nullable)', ({ nullable }) => {
65
+ const ir = createContractIR({
66
+ storage: {
67
+ tables: {
68
+ user: {
69
+ columns: {
70
+ created_at: {
71
+ codecId: 'pg/timestamptz@1',
72
+ nativeType: 'timestamptz',
73
+ nullable,
74
+ default: { kind: 'function', expression: 'now()' },
75
+ },
76
+ updated_at: {
77
+ codecId: 'pg/timestamptz@1',
78
+ nativeType: 'timestamptz',
79
+ nullable: true,
80
+ },
81
+ },
82
+ },
83
+ },
84
+ },
85
+ });
86
+
87
+ const result = canonicalizeContract(ir);
88
+ const parsed = JSON.parse(result) as Record<string, unknown>;
89
+ const storage = parsed['storage'] as Record<string, unknown>;
90
+ const tables = storage['tables'] as Record<string, unknown>;
91
+ const user = tables['user'] as Record<string, unknown>;
92
+ const columns = user['columns'] as Record<string, unknown>;
93
+ const createdAt = columns['created_at'] as Record<string, unknown>;
94
+ const updatedAt = columns['updated_at'] as Record<string, unknown>;
95
+ expect(createdAt['nullable']).toBeUndefined();
96
+ expect(updatedAt['nullable']).toBe(true);
97
+ });
98
+
99
+ it('preserves nullable:true for columns with defaults', () => {
100
+ const ir = createContractIR({
101
+ storage: {
102
+ tables: {
103
+ user: {
104
+ columns: {
105
+ bio: {
106
+ codecId: 'pg/text@1',
107
+ nativeType: 'text',
108
+ nullable: true,
109
+ default: { kind: 'literal', value: '' },
110
+ },
111
+ },
112
+ },
113
+ },
114
+ },
115
+ });
116
+
117
+ const result = canonicalizeContract(ir);
118
+ const parsed = JSON.parse(result) as Record<string, unknown>;
119
+ const storage = parsed['storage'] as Record<string, unknown>;
120
+ const tables = storage['tables'] as Record<string, unknown>;
121
+ const user = tables['user'] as Record<string, unknown>;
122
+ const columns = user['columns'] as Record<string, unknown>;
123
+ const bio = columns['bio'] as Record<string, unknown>;
124
+ expect(bio['nullable']).toBe(true);
125
+ expect(bio['default']).toEqual({ kind: 'literal', value: '' });
126
+ });
127
+
58
128
  it('omits empty arrays and objects except required ones', () => {
59
129
  const ir = createContractIR();
60
130
 
@@ -66,14 +136,12 @@ describe('canonicalization', () => {
66
136
  tables: expect.anything(),
67
137
  },
68
138
  });
69
- // Required top-level fields (capabilities, extensionPacks, meta, relations, sources) are preserved even when empty
70
- // because they are required by ContractIR and needed for round-trip tests
139
+ // Required top-level fields (capabilities, extensionPacks, meta, relations) are preserved even when empty.
71
140
  expect(parsed).toMatchObject({
72
141
  capabilities: expect.anything(),
73
142
  extensionPacks: expect.anything(),
74
143
  meta: expect.anything(),
75
144
  relations: expect.anything(),
76
- sources: expect.anything(),
77
145
  });
78
146
  });
79
147
 
@@ -117,7 +185,7 @@ describe('canonicalization', () => {
117
185
  expect(result1).not.toBe(result2);
118
186
  });
119
187
 
120
- it('sorts non-semantic arrays by canonical name', () => {
188
+ it('sorts indexes by canonical name', () => {
121
189
  const ir = createContractIR({
122
190
  storage: {
123
191
  tables: {
@@ -144,6 +212,60 @@ describe('canonicalization', () => {
144
212
  expect(indexNames).toEqual(['user_email_idx', 'user_name_idx']);
145
213
  });
146
214
 
215
+ it('sorts uniques by canonical name', () => {
216
+ const ir = createContractIR({
217
+ storage: {
218
+ tables: {
219
+ user: {
220
+ columns: {
221
+ id: { codecId: 'pg/int4@1', nativeType: 'int4', nullable: false },
222
+ email: { codecId: 'pg/text@1', nativeType: 'text', nullable: false },
223
+ username: { codecId: 'pg/text@1', nativeType: 'text', nullable: false },
224
+ },
225
+ uniques: [
226
+ { columns: ['username'], name: 'user_username_key' },
227
+ { columns: ['email'], name: 'user_email_key' },
228
+ ],
229
+ },
230
+ },
231
+ },
232
+ });
233
+
234
+ const result = canonicalizeContract(ir);
235
+ const parsed = JSON.parse(result) as Record<string, unknown>;
236
+ const storage = parsed['storage'] as Record<string, unknown>;
237
+ const tables = storage['tables'] as Record<string, unknown>;
238
+ const user = tables['user'] as Record<string, unknown>;
239
+ const uniques = user['uniques'] as Array<{ name: string }>;
240
+ const uniqueNames = uniques.map((u) => u.name);
241
+ expect(uniqueNames).toEqual(['user_email_key', 'user_username_key']);
242
+ });
243
+
244
+ it('preserves column order in composite unique constraints', () => {
245
+ const ir = createContractIR({
246
+ storage: {
247
+ tables: {
248
+ user: {
249
+ columns: {
250
+ id: { codecId: 'pg/int4@1', nativeType: 'int4', nullable: false },
251
+ first_name: { codecId: 'pg/text@1', nativeType: 'text', nullable: false },
252
+ last_name: { codecId: 'pg/text@1', nativeType: 'text', nullable: false },
253
+ },
254
+ uniques: [{ columns: ['last_name', 'first_name'], name: 'user_name_key' }],
255
+ },
256
+ },
257
+ },
258
+ });
259
+
260
+ const result = canonicalizeContract(ir);
261
+ const parsed = JSON.parse(result) as Record<string, unknown>;
262
+ const storage = parsed['storage'] as Record<string, unknown>;
263
+ const tables = storage['tables'] as Record<string, unknown>;
264
+ const user = tables['user'] as Record<string, unknown>;
265
+ const uniques = user['uniques'] as Array<{ columns: string[] }>;
266
+ expect(uniques[0]!.columns).toEqual(['last_name', 'first_name']);
267
+ });
268
+
147
269
  it('sorts nested object keys lexicographically', () => {
148
270
  const ir = createContractIR({
149
271
  storage: {