@prisma-next/contract 0.3.0-pr.99.6 → 0.3.0
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 +201 -0
- package/README.md +43 -254
- package/dist/contract-types-MYdoYIIh.d.mts +314 -0
- package/dist/contract-types-MYdoYIIh.d.mts.map +1 -0
- package/dist/hashing-CyaA_Qvf.mjs +196 -0
- package/dist/hashing-CyaA_Qvf.mjs.map +1 -0
- package/dist/hashing.d.mts +29 -0
- package/dist/hashing.d.mts.map +1 -0
- package/dist/hashing.mjs +3 -0
- package/dist/testing.d.mts +29 -0
- package/dist/testing.d.mts.map +1 -0
- package/dist/testing.mjs +58 -0
- package/dist/testing.mjs.map +1 -0
- package/dist/types-aMyNgejf.mjs +14 -0
- package/dist/types-aMyNgejf.mjs.map +1 -0
- package/dist/types.d.mts +2 -2
- package/dist/types.mjs +2 -10
- package/dist/validate-contract.d.mts +37 -0
- package/dist/validate-contract.d.mts.map +1 -0
- package/dist/validate-contract.mjs +3 -0
- package/dist/validate-domain-CpCcTlqJ.mjs +165 -0
- package/dist/validate-domain-CpCcTlqJ.mjs.map +1 -0
- package/dist/validate-domain.d.mts +24 -0
- package/dist/validate-domain.d.mts.map +1 -0
- package/dist/validate-domain.mjs +3 -0
- package/package.json +15 -8
- package/schemas/data-contract-document-v1.json +5 -5
- package/src/canonicalization.ts +263 -0
- package/src/contract-types.ts +55 -0
- package/src/domain-types.ts +95 -0
- package/src/exports/hashing.ts +2 -0
- package/src/exports/testing.ts +1 -0
- package/src/exports/types.ts +36 -20
- package/src/exports/validate-contract.ts +6 -0
- package/src/exports/validate-domain.ts +5 -0
- package/src/hashing.ts +53 -0
- package/src/testing-factories.ts +101 -0
- package/src/types.ts +102 -248
- package/src/validate-contract.ts +101 -0
- package/src/validate-domain.ts +227 -0
- package/dist/framework-components-B-XOtXw3.d.mts +0 -854
- package/dist/framework-components-B-XOtXw3.d.mts.map +0 -1
- package/dist/framework-components.d.mts +0 -2
- package/dist/framework-components.mjs +0 -70
- package/dist/framework-components.mjs.map +0 -1
- package/dist/ir-B8zNqals.d.mts +0 -79
- package/dist/ir-B8zNqals.d.mts.map +0 -1
- package/dist/ir.d.mts +0 -2
- package/dist/ir.mjs +0 -46
- package/dist/ir.mjs.map +0 -1
- package/dist/pack-manifest-types.d.mts +0 -2
- package/dist/pack-manifest-types.mjs +0 -1
- package/dist/types.mjs.map +0 -1
- package/src/exports/framework-components.ts +0 -36
- package/src/exports/ir.ts +0 -1
- package/src/exports/pack-manifest-types.ts +0 -6
- package/src/framework-components.ts +0 -717
- package/src/ir.ts +0 -113
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
|
@@ -1,147 +1,39 @@
|
|
|
1
1
|
# @prisma-next/contract
|
|
2
2
|
|
|
3
|
-
Core contract types
|
|
3
|
+
Core contract data types and JSON schemas for Prisma Next.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
This package provides the foundational type definitions for Prisma Next
|
|
8
|
-
- **Data contracts**: The canonical description of an application's data model and storage layout
|
|
9
|
-
- **Framework component descriptors**: Base interfaces for the modular component system (families, targets, adapters, drivers, extensions)
|
|
10
|
-
- **JSON Schemas**: Validation schemas for contract files
|
|
11
|
-
|
|
12
|
-
## Responsibilities
|
|
13
|
-
|
|
14
|
-
- **Core Contract Types**: Defines framework-level contract types (`ContractBase`, `Source`, `FamilyInstance`) that are shared across all target families
|
|
15
|
-
- **Framework Component Model**: Provides base descriptor interfaces (`FamilyDescriptor`, `TargetDescriptor`, `AdapterDescriptor`, `DriverDescriptor`, `ExtensionDescriptor`) and identity instance bases (`FamilyInstance`, `TargetInstance`, `AdapterInstance`, `DriverInstance`, `ExtensionInstance`) that plane-specific types extend
|
|
16
|
-
- **Document Family Types**: Provides TypeScript types for document target family contracts (`DocumentContract`)
|
|
17
|
-
- **JSON Schema Validation**: Provides JSON Schemas for validating contract structure in IDEs and tooling
|
|
18
|
-
- **Type Guards**: Provides runtime type guards for narrowing contract types (`isDocumentContract`)
|
|
19
|
-
- **Emitter Types**: Defines emitter SPI types (`TargetFamilyHook`, `ValidationContext`, `TypesImportSpec`) that are shared between emitter and control plane
|
|
20
|
-
|
|
21
|
-
The contract supports document target families:
|
|
22
|
-
- **Document**: For document databases (MongoDB, Firestore, etc.)
|
|
7
|
+
This package provides the foundational type definitions for Prisma Next data contracts:
|
|
23
8
|
|
|
24
|
-
|
|
9
|
+
- **Contract data types**: The canonical description of an application's data model and storage layout (`ContractBase`, `DocumentContract`, `Source`, `FieldType`)
|
|
10
|
+
- **Plan types**: Target-family-agnostic execution plan types (`ExecutionPlan`, `PlanMeta`, `ParamDescriptor`)
|
|
11
|
+
- **Hash types**: Branded hash types for storage, execution, and profile hashing (`StorageHashBase`, `ExecutionHashBase`, `ProfileHashBase`)
|
|
12
|
+
- **JSON Schemas**: Validation schemas for contract files
|
|
13
|
+
- **Type guards**: Runtime type guards for narrowing contract types (`isDocumentContract`)
|
|
25
14
|
|
|
26
|
-
- **
|
|
27
|
-
- **Emitter Types**: SPI types for emitter hooks (`TargetFamilyHook`, `ValidationContext`, `TypesImportSpec`)
|
|
28
|
-
- **JSON Schemas**: Schema definitions for validating `contract.json` files in IDEs and tooling
|
|
29
|
-
- `data-contract-document-v1.json` (Document family)
|
|
15
|
+
This package is a **foundation-layer leaf** — it has no framework-domain dependencies and is consumed by all layers above it.
|
|
30
16
|
|
|
31
17
|
## Usage
|
|
32
18
|
|
|
33
|
-
### TypeScript Types
|
|
34
|
-
|
|
35
|
-
Import contract types in your TypeScript code:
|
|
36
|
-
|
|
37
19
|
```typescript
|
|
38
20
|
import type {
|
|
21
|
+
Contract,
|
|
39
22
|
ContractMarkerRecord,
|
|
40
23
|
DocumentContract,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
ValidationContext,
|
|
24
|
+
ExecutionPlan,
|
|
25
|
+
PlanMeta,
|
|
44
26
|
} from '@prisma-next/contract/types';
|
|
45
|
-
import { isDocumentContract } from '@prisma-next/contract/types';
|
|
46
|
-
|
|
47
|
-
// Use type guards to narrow the contract type
|
|
48
|
-
function processContract(contract: DocumentContract) {
|
|
49
|
-
if (isDocumentContract(contract)) {
|
|
50
|
-
// contract is DocumentContract
|
|
51
|
-
console.log(contract.storage.document.collections);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Use ContractMarkerRecord for database marker operations
|
|
56
|
-
function processMarker(marker: ContractMarkerRecord) {
|
|
57
|
-
console.log(marker.coreHash, marker.profileHash);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Use emitter types for implementing family hooks
|
|
61
|
-
const myFamilyHook: TargetFamilyHook = {
|
|
62
|
-
id: 'my-family',
|
|
63
|
-
validateTypes: (ir, ctx: ValidationContext) => {
|
|
64
|
-
// Validation logic
|
|
65
|
-
},
|
|
66
|
-
validateStructure: (ir) => {
|
|
67
|
-
// Structure validation
|
|
68
|
-
},
|
|
69
|
-
generateContractTypes: (ir, codecTypeImports: TypesImportSpec[], operationTypeImports: TypesImportSpec[]) => {
|
|
70
|
-
// Type generation
|
|
71
|
-
return '// Generated types...';
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
### Framework Component Model
|
|
77
|
-
|
|
78
|
-
Import base descriptor and instance interfaces to define or type-check framework components:
|
|
27
|
+
import { isDocumentContract, coreHash, profileHash } from '@prisma-next/contract/types';
|
|
79
28
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
// Descriptors
|
|
83
|
-
ComponentDescriptor,
|
|
84
|
-
FamilyDescriptor,
|
|
85
|
-
TargetDescriptor,
|
|
86
|
-
AdapterDescriptor,
|
|
87
|
-
DriverDescriptor,
|
|
88
|
-
ExtensionDescriptor,
|
|
89
|
-
// Instances
|
|
90
|
-
FamilyInstance,
|
|
91
|
-
TargetInstance,
|
|
92
|
-
AdapterInstance,
|
|
93
|
-
DriverInstance,
|
|
94
|
-
ExtensionInstance,
|
|
95
|
-
} from '@prisma-next/contract/framework-components';
|
|
96
|
-
|
|
97
|
-
// Component descriptors share common properties
|
|
98
|
-
interface MyDescriptor extends ComponentDescriptor<'custom'> {
|
|
99
|
-
readonly customField: string;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Use FamilyDescriptor for family components
|
|
103
|
-
const sqlFamily: FamilyDescriptor<'sql'> = {
|
|
104
|
-
kind: 'family',
|
|
105
|
-
id: 'sql',
|
|
106
|
-
familyId: 'sql',
|
|
107
|
-
version: '0.0.1',
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
// Use TargetDescriptor for target components
|
|
111
|
-
const postgresTarget: TargetDescriptor<'sql', 'postgres'> = {
|
|
112
|
-
kind: 'target',
|
|
113
|
-
id: 'postgres',
|
|
114
|
-
familyId: 'sql',
|
|
115
|
-
targetId: 'postgres',
|
|
116
|
-
version: '0.0.1',
|
|
117
|
-
capabilities: { postgres: { returning: true } },
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
// Identity instance bases are extended by plane-specific instances
|
|
121
|
-
interface MySqlInstance extends FamilyInstance<'sql'> {
|
|
122
|
-
// Plane-specific methods...
|
|
29
|
+
if (isDocumentContract(contract)) {
|
|
30
|
+
const collections = contract.storage.document.collections;
|
|
123
31
|
}
|
|
124
32
|
```
|
|
125
33
|
|
|
126
|
-
The component hierarchy is:
|
|
127
|
-
|
|
128
|
-
```
|
|
129
|
-
Family (e.g., 'sql', 'document')
|
|
130
|
-
└── Target (e.g., 'postgres', 'mysql', 'mongodb')
|
|
131
|
-
├── Adapter (protocol/dialect implementation)
|
|
132
|
-
├── Driver (connection/execution layer)
|
|
133
|
-
└── Extension (optional capabilities like pgvector)
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
Plane-specific descriptors (`ControlFamilyDescriptor`, `RuntimeTargetDescriptor`, etc.) extend these bases with plane-specific factory methods and capabilities.
|
|
137
|
-
|
|
138
34
|
### JSON Schema Validation
|
|
139
35
|
|
|
140
|
-
Reference the appropriate JSON schema in your `contract.json` files to enable IDE validation
|
|
141
|
-
|
|
142
|
-
#### Document Family
|
|
143
|
-
|
|
144
|
-
For document targets (MongoDB, Firestore, etc.):
|
|
36
|
+
Reference the appropriate JSON schema in your `contract.json` files to enable IDE validation:
|
|
145
37
|
|
|
146
38
|
```json
|
|
147
39
|
{
|
|
@@ -149,154 +41,51 @@ For document targets (MongoDB, Firestore, etc.):
|
|
|
149
41
|
"schemaVersion": "1",
|
|
150
42
|
"target": "mongodb",
|
|
151
43
|
"targetFamily": "document",
|
|
152
|
-
"
|
|
153
|
-
"storage": {
|
|
154
|
-
"document": {
|
|
155
|
-
"collections": {
|
|
156
|
-
"users": {
|
|
157
|
-
"name": "users",
|
|
158
|
-
"fields": {
|
|
159
|
-
"id": { "type": "objectId", "nullable": false },
|
|
160
|
-
"email": { "type": "string", "nullable": false }
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
**Note:** For SQL contracts, use `@prisma-next/sql-query/schema-sql` instead:
|
|
170
|
-
|
|
171
|
-
```json
|
|
172
|
-
{
|
|
173
|
-
"$schema": "node_modules/@prisma-next/sql-query/schemas/data-contract-sql-v1.json",
|
|
174
|
-
"schemaVersion": "1",
|
|
175
|
-
"target": "postgres",
|
|
176
|
-
"targetFamily": "sql",
|
|
177
|
-
"coreHash": "sha256:...",
|
|
178
|
-
"storage": {
|
|
179
|
-
"tables": {
|
|
180
|
-
"user": {
|
|
181
|
-
"columns": {
|
|
182
|
-
"id": { "type": "int4", "nullable": false },
|
|
183
|
-
"email": { "type": "text", "nullable": false }
|
|
184
|
-
},
|
|
185
|
-
"primaryKey": {
|
|
186
|
-
"columns": ["id"],
|
|
187
|
-
"name": "user_pkey"
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
44
|
+
"storageHash": "sha256:..."
|
|
192
45
|
}
|
|
193
46
|
```
|
|
194
47
|
|
|
195
|
-
|
|
196
|
-
- Validate your contract structure
|
|
197
|
-
- Provide autocomplete for properties
|
|
198
|
-
- Show descriptions and constraints in tooltips
|
|
199
|
-
- Highlight errors for invalid configurations
|
|
48
|
+
For SQL contracts, use `@prisma-next/sql-contract-ts/schema-sql` instead.
|
|
200
49
|
|
|
201
|
-
##
|
|
202
|
-
|
|
203
|
-
### Common Header Fields
|
|
204
|
-
|
|
205
|
-
All contracts share these common fields:
|
|
206
|
-
|
|
207
|
-
- **`schemaVersion`** (required): Contract schema version (currently `"1"`)
|
|
208
|
-
- **`target`** (required): Database target identifier (e.g., `"postgres"`, `"mongo"`, `"firestore"`)
|
|
209
|
-
- **`targetFamily`** (required): Target family classification (`"document"` for document contracts)
|
|
210
|
-
- **`coreHash`** (required): SHA-256 hash of the core schema structure
|
|
211
|
-
- **`profileHash`** (optional): SHA-256 hash of the capability profile
|
|
212
|
-
- **`capabilities`** (optional): Capability flags declared by the contract
|
|
213
|
-
- **`extensionPacks`** (optional): Extension packs and their configuration
|
|
214
|
-
- **`meta`** (optional): Non-semantic metadata (excluded from hashing)
|
|
215
|
-
- **`sources`** (optional): Read-only sources (views, etc.) available for querying
|
|
216
|
-
|
|
217
|
-
### Document Family Structure
|
|
50
|
+
## Exports
|
|
218
51
|
|
|
219
|
-
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
- **`indexes`** (optional): Array of index definitions with keys and optional predicates
|
|
225
|
-
- **`readOnly`** (optional): Whether mutations are disallowed
|
|
52
|
+
- `./types`: Contract data types, hash types, plan types, type guards
|
|
53
|
+
- `./hashing`: Contract hashing utilities
|
|
54
|
+
- `./testing`: Test helpers for creating contract fixtures
|
|
55
|
+
- `./validate-contract`: Contract structure validation
|
|
56
|
+
- `./validate-domain`: Domain model validation
|
|
226
57
|
|
|
227
58
|
## Type System
|
|
228
59
|
|
|
229
|
-
###
|
|
230
|
-
|
|
231
|
-
Use type guards to narrow the contract type:
|
|
232
|
-
|
|
233
|
-
```typescript
|
|
234
|
-
import { isDocumentContract } from '@prisma-next/contract/types';
|
|
60
|
+
### Plan Types
|
|
235
61
|
|
|
236
|
-
|
|
237
|
-
// TypeScript knows contract is DocumentContract
|
|
238
|
-
const collections = contract.storage.document.collections;
|
|
239
|
-
}
|
|
240
|
-
```
|
|
62
|
+
`ParamDescriptor` describes a single parameter in an execution plan:
|
|
241
63
|
|
|
242
|
-
|
|
64
|
+
- **`source`**: Origin of the parameter (`'dsl'`, `'raw'`, or `'lane'`)
|
|
65
|
+
- **`index`** (optional): 1-based position into `plan.params`
|
|
66
|
+
- **`name`** (optional): Parameter name for codec resolution
|
|
67
|
+
- **`codecId`**, **`nativeType`**, **`nullable`** (optional): Type metadata from contract
|
|
68
|
+
- **`refs`** (optional): `{ table, column }` when the param is used against a known column
|
|
243
69
|
|
|
244
|
-
|
|
245
|
-
- `./framework-components`: Framework component model (descriptors + identity instance bases)
|
|
246
|
-
- `./pack-manifest-types`: Extension pack manifest types
|
|
247
|
-
- `./ir`: Contract IR types
|
|
248
|
-
- `./schema-document`: Document family JSON Schema (`schemas/data-contract-document-v1.json`)
|
|
70
|
+
### Column Defaults
|
|
249
71
|
|
|
250
|
-
|
|
72
|
+
- When adding column defaults, re-emit the contract and verify the emitted JSON includes the full default payload.
|
|
73
|
+
- Keep `nullable: false` explicit for columns with defaults in emitted contracts.
|
|
74
|
+
- Add the corresponding `defaults.*` capability when using function defaults like `autoincrement()` or `now()`.
|
|
251
75
|
|
|
252
|
-
|
|
253
|
-
flowchart TD
|
|
254
|
-
subgraph "Contract Package"
|
|
255
|
-
TYPES[Type Definitions]
|
|
256
|
-
SCHEMA[JSON Schemas]
|
|
257
|
-
GUARDS[Type Guards]
|
|
258
|
-
end
|
|
76
|
+
## Dependencies
|
|
259
77
|
|
|
260
|
-
|
|
261
|
-
EMITTER[Emitter]
|
|
262
|
-
RUNTIME[Runtime]
|
|
263
|
-
QUERY[Query Builder]
|
|
264
|
-
end
|
|
265
|
-
|
|
266
|
-
TYPES --> EMITTER
|
|
267
|
-
TYPES --> RUNTIME
|
|
268
|
-
TYPES --> QUERY
|
|
269
|
-
SCHEMA --> EMITTER
|
|
270
|
-
GUARDS --> RUNTIME
|
|
271
|
-
GUARDS --> QUERY
|
|
272
|
-
```
|
|
78
|
+
- **`@prisma-next/utils`**: Shared utility functions
|
|
273
79
|
|
|
274
80
|
## Related Subsystems
|
|
275
81
|
|
|
276
|
-
-
|
|
277
|
-
-
|
|
82
|
+
- [Data Contract](../../../../../docs/architecture%20docs/subsystems/1.%20Data%20Contract.md)
|
|
83
|
+
- [Contract Emitter & Types](../../../../../docs/architecture%20docs/subsystems/2.%20Contract%20Emitter%20&%20Types.md)
|
|
278
84
|
|
|
279
85
|
## Related ADRs
|
|
280
86
|
|
|
281
|
-
- [ADR 001 - Migrations as Edges](
|
|
282
|
-
- [ADR 004 -
|
|
283
|
-
- [ADR
|
|
284
|
-
- [ADR
|
|
285
|
-
- [ADR
|
|
286
|
-
|
|
287
|
-
## Dependencies
|
|
288
|
-
|
|
289
|
-
- **`@prisma-next/operations`**: For `OperationRegistry` type used in `ValidationContext` and `TargetFamilyHook`
|
|
290
|
-
- **Note**: This package depends on `@prisma-next/operations`, but `@prisma-next/operations` does not depend on this package (no cycle). The `OperationRegistry` type is used in emitter SPI types that are shared between migration-plane and shared-plane packages.
|
|
291
|
-
|
|
292
|
-
**Dependents:**
|
|
293
|
-
- **`@prisma-next/contract-authoring`**: Uses core contract types for authoring
|
|
294
|
-
- **`@prisma-next/sql-contract`**: Extends core contract types for SQL family
|
|
295
|
-
- **`@prisma-next/emitter`**: Uses contract types for emission
|
|
296
|
-
- **`@prisma-next/runtime`**: Uses contract types for runtime execution
|
|
297
|
-
- **`@prisma-next/sql-query`**: Uses contract types for query building
|
|
298
|
-
|
|
299
|
-
## Related Packages
|
|
300
|
-
|
|
301
|
-
- `@prisma-next/sql-query`: SQL query builder and plan types
|
|
302
|
-
- `@prisma-next/runtime`: Runtime execution engine that consumes contracts
|
|
87
|
+
- [ADR 001 - Migrations as Edges](../../../../../docs/architecture%20docs/adrs/ADR%20001%20-%20Migrations%20as%20Edges.md)
|
|
88
|
+
- [ADR 004 - Storage Hash vs Profile Hash](../../../../../docs/architecture%20docs/adrs/ADR%20004%20-%20Storage%20Hash%20vs%20Profile%20Hash.md)
|
|
89
|
+
- [ADR 010 - Canonicalization Rules](../../../../../docs/architecture%20docs/adrs/ADR%20010%20-%20Canonicalization%20Rules.md)
|
|
90
|
+
- [ADR 021 - Contract Marker Storage](../../../../../docs/architecture%20docs/adrs/ADR%20021%20-%20Contract%20Marker%20Storage.md)
|
|
91
|
+
- [ADR 185 - SPI types live at the lowest consuming layer](../../../../../docs/architecture%20docs/adrs/ADR%20185%20-%20SPI%20types%20live%20at%20the%20lowest%20consuming%20layer.md)
|