@prisma-next/sql-contract 0.3.0-dev.7 → 0.3.0-dev.70
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 +79 -10
- package/dist/factories.d.mts +48 -0
- package/dist/factories.d.mts.map +1 -0
- package/dist/factories.mjs +84 -0
- package/dist/factories.mjs.map +1 -0
- package/dist/pack-types.d.mts +13 -0
- package/dist/pack-types.d.mts.map +1 -0
- package/dist/pack-types.mjs +1 -0
- package/dist/types-T6o5-ZB3.d.mts +145 -0
- package/dist/types-T6o5-ZB3.d.mts.map +1 -0
- package/dist/types-kacOgEya.mjs +17 -0
- package/dist/types-kacOgEya.mjs.map +1 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +3 -0
- package/dist/validate.d.mts +11 -0
- package/dist/validate.d.mts.map +1 -0
- package/dist/validate.mjs +244 -0
- package/dist/validate.mjs.map +1 -0
- package/dist/validators-Dz93b38w.mjs +214 -0
- package/dist/validators-Dz93b38w.mjs.map +1 -0
- package/dist/validators.d.mts +65 -0
- package/dist/validators.d.mts.map +1 -0
- package/dist/validators.mjs +3 -0
- package/package.json +24 -28
- package/src/exports/types.ts +5 -0
- package/src/exports/validate.ts +6 -0
- package/src/exports/validators.ts +1 -1
- package/src/factories.ts +41 -8
- package/src/index.ts +1 -0
- package/src/types.ts +88 -2
- package/src/validate.ts +448 -0
- package/src/validators.ts +161 -10
- package/dist/exports/factories.d.ts +0 -2
- package/dist/exports/factories.d.ts.map +0 -1
- package/dist/exports/factories.js +0 -83
- package/dist/exports/factories.js.map +0 -1
- package/dist/exports/pack-types.d.ts +0 -2
- package/dist/exports/pack-types.d.ts.map +0 -1
- package/dist/exports/pack-types.js +0 -1
- package/dist/exports/pack-types.js.map +0 -1
- package/dist/exports/types.d.ts +0 -2
- package/dist/exports/types.d.ts.map +0 -1
- package/dist/exports/types.js +0 -1
- package/dist/exports/types.js.map +0 -1
- package/dist/exports/validators.d.ts +0 -2
- package/dist/exports/validators.d.ts.map +0 -1
- package/dist/exports/validators.js +0 -96
- package/dist/exports/validators.js.map +0 -1
- package/dist/factories.d.ts +0 -38
- package/dist/factories.d.ts.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/pack-types.d.ts +0 -10
- package/dist/pack-types.d.ts.map +0 -1
- package/dist/types.d.ts +0 -68
- package/dist/types.d.ts.map +0 -1
- package/dist/validators.d.ts +0 -35
- package/dist/validators.d.ts.map +0 -1
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
|
@@ -8,8 +8,8 @@ This package provides TypeScript type definitions, Arktype validators, and facto
|
|
|
8
8
|
|
|
9
9
|
## Responsibilities
|
|
10
10
|
|
|
11
|
-
- **SQL Contract Types**: Defines SQL-specific contract types (`SqlContract`, `SqlStorage`, `StorageTable`, `ModelDefinition`, `SqlMappings`) that extend framework-level contract types
|
|
12
|
-
- **Contract Validation**: Provides Arktype-based validators
|
|
11
|
+
- **SQL Contract Types**: Defines SQL-specific contract types (`SqlContract`, `SqlStorage`, `StorageTable`, `ModelDefinition`, `SqlMappings`, `ForeignKeysConfig`) that extend framework-level contract types
|
|
12
|
+
- **Contract Validation**: Provides Arktype-based structural validators and the shared `validateContract` entrypoint for runtime-safe contract validation
|
|
13
13
|
- **IR Factories**: Provides pure factory functions for constructing contract IR structures in tests and authoring
|
|
14
14
|
- **Shared Plane Access**: Enables both migration-plane and runtime-plane packages to import SQL contract types without violating plane boundaries
|
|
15
15
|
|
|
@@ -19,12 +19,13 @@ Each `StorageColumn` in SQL contracts includes both:
|
|
|
19
19
|
- **`nativeType`** (required): Native database type identifier (e.g., `'int4'`, `'text'`, `'vector'`) - used for database structure verification and migration planning
|
|
20
20
|
- **`codecId`** (required): Codec identifier (e.g., `'pg/int4@1'`, `'pg/text@1'`, `'pg/vector@1'`) - used for query builders and runtime codecs
|
|
21
21
|
- **`nullable`** (required): Whether the column is nullable
|
|
22
|
+
- **`default`** (optional): Uses the shared `ColumnDefault` type from `@prisma-next/contract` for db-agnostic defaults (literal or function). Client-generated defaults live in `execution.mutations.defaults`.
|
|
22
23
|
|
|
23
24
|
Both `nativeType` and `codecId` are required to ensure contracts are consumable by both the application (via codec IDs) and the database (via native types). See `docs/briefs/Sql-Contract-Native-and-Codec-Types.md` for details.
|
|
24
25
|
|
|
25
26
|
## Package Contents
|
|
26
27
|
|
|
27
|
-
- **TypeScript Types**: Type definitions for `SqlContract`, `SqlStorage`, `StorageTable`, `ModelDefinition`, and related types
|
|
28
|
+
- **TypeScript Types**: Type definitions for `SqlContract`, `SqlStorage`, `StorageTable`, `ModelDefinition`, `ForeignKeysConfig`, and related types
|
|
28
29
|
- **Validators**: Arktype-based validators for structural validation of contracts, storage, and models
|
|
29
30
|
- **Factories**: Pure factory functions for constructing contract IR structures in tests and authoring
|
|
30
31
|
|
|
@@ -40,15 +41,68 @@ import type {
|
|
|
40
41
|
SqlStorage,
|
|
41
42
|
StorageTable,
|
|
42
43
|
ModelDefinition,
|
|
43
|
-
|
|
44
|
+
ForeignKeysConfig,
|
|
45
|
+
} from '@prisma-next/sql-contract/types';
|
|
44
46
|
```
|
|
45
47
|
|
|
48
|
+
### Foreign Keys Configuration
|
|
49
|
+
|
|
50
|
+
`SqlContract` includes an optional `foreignKeys` field of type `ForeignKeysConfig` that controls whether the planner emits foreign key constraints and their backing indexes:
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
type ForeignKeysConfig = {
|
|
54
|
+
readonly constraints: boolean; // Emit FOREIGN KEY constraints
|
|
55
|
+
readonly indexes: boolean; // Emit FK-backing indexes
|
|
56
|
+
};
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
When omitted, defaults to `{ constraints: true, indexes: true }`. See [ADR 161](../../../docs/architecture%20docs/adrs/ADR%20161%20-%20Explicit%20foreign%20key%20constraint%20and%20index%20configuration.md) for design rationale.
|
|
60
|
+
|
|
61
|
+
### Referential Actions
|
|
62
|
+
|
|
63
|
+
`ForeignKey` supports optional `onDelete` and `onUpdate` fields of type `ReferentialAction`:
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';
|
|
67
|
+
|
|
68
|
+
type ForeignKey = {
|
|
69
|
+
readonly columns: readonly string[];
|
|
70
|
+
readonly references: ForeignKeyReferences;
|
|
71
|
+
readonly name?: string;
|
|
72
|
+
readonly onDelete?: ReferentialAction;
|
|
73
|
+
readonly onUpdate?: ReferentialAction;
|
|
74
|
+
};
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
When omitted, the database applies its default behavior (Postgres: `NO ACTION`). See [ADR 166](../../../docs/architecture%20docs/adrs/ADR%20166%20-%20Referential%20actions%20for%20foreign%20keys.md) for design rationale.
|
|
78
|
+
|
|
79
|
+
The `fk()` factory accepts referential actions via an options object:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { fk } from '@prisma-next/sql-contract/factories';
|
|
83
|
+
|
|
84
|
+
// Simple FK (no referential actions)
|
|
85
|
+
const simple = fk(['userId'], 'user', ['id']);
|
|
86
|
+
|
|
87
|
+
// FK with onDelete cascade
|
|
88
|
+
const cascading = fk(['userId'], 'user', ['id'], { onDelete: 'cascade' });
|
|
89
|
+
|
|
90
|
+
// FK with name and both actions
|
|
91
|
+
const named = fk(['userId'], 'user', ['id'], {
|
|
92
|
+
name: 'post_userId_fkey',
|
|
93
|
+
onDelete: 'cascade',
|
|
94
|
+
onUpdate: 'noAction',
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Semantic validation:** `validateStorageSemantics()` rejects `setNull` when the FK column is `NOT NULL` (the database would fail at runtime).
|
|
99
|
+
|
|
46
100
|
### Validators
|
|
47
101
|
|
|
48
102
|
Validate contract structures using Arktype validators:
|
|
49
103
|
|
|
50
104
|
```typescript
|
|
51
|
-
import { validateSqlContract, validateStorage, validateModel } from '@prisma-next/sql-contract/
|
|
105
|
+
import { validateSqlContract, validateStorage, validateModel } from '@prisma-next/sql-contract/validators';
|
|
52
106
|
|
|
53
107
|
// Validate a complete contract
|
|
54
108
|
const contract = validateSqlContract<Contract>(contractJson);
|
|
@@ -60,12 +114,25 @@ const storage = validateStorage(storageJson);
|
|
|
60
114
|
const model = validateModel(modelJson);
|
|
61
115
|
```
|
|
62
116
|
|
|
117
|
+
Validate JSON-emitted contracts with mapping + logic checks:
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { validateContract } from '@prisma-next/sql-contract/validate';
|
|
121
|
+
|
|
122
|
+
const contract = validateContract<Contract>(contractJson);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Mapping overrides in `contract.mappings` follow strict pair semantics:
|
|
126
|
+
- `modelToTable` and `tableToModel` must either both be omitted (auto-computed) or both be provided as inverse maps.
|
|
127
|
+
- `fieldToColumn` and `columnToField` must either both be omitted (auto-computed) or both be provided as inverse maps.
|
|
128
|
+
- `codecTypes` and `operationTypes` are merged additively on top of defaults.
|
|
129
|
+
|
|
63
130
|
### Factories
|
|
64
131
|
|
|
65
132
|
Use factory functions to construct contract IR structures in tests:
|
|
66
133
|
|
|
67
134
|
```typescript
|
|
68
|
-
import { col, table, storage, model, contract, pk, unique, index, fk } from '@prisma-next/sql-contract/
|
|
135
|
+
import { col, table, storage, model, contract, pk, unique, index, fk } from '@prisma-next/sql-contract/factories';
|
|
69
136
|
|
|
70
137
|
// Create a column (nativeType, codecId, nullable)
|
|
71
138
|
const idColumn = col('int4', 'pg/int4@1', false);
|
|
@@ -95,7 +162,7 @@ const userModel = model('user', {
|
|
|
95
162
|
// Create a complete contract
|
|
96
163
|
const c = contract({
|
|
97
164
|
target: 'postgres',
|
|
98
|
-
|
|
165
|
+
storageHash: 'sha256:abc123',
|
|
99
166
|
storage: s,
|
|
100
167
|
models: { User: userModel },
|
|
101
168
|
});
|
|
@@ -103,9 +170,11 @@ const c = contract({
|
|
|
103
170
|
|
|
104
171
|
## Exports
|
|
105
172
|
|
|
106
|
-
- `./
|
|
107
|
-
- `./
|
|
108
|
-
- `./
|
|
173
|
+
- `./types`: TypeScript type definitions
|
|
174
|
+
- `./validators`: Arktype validators for structural validation
|
|
175
|
+
- `./validate`: Shared `validateContract` helper for JSON imports
|
|
176
|
+
- `./factories`: Factory functions for constructing contract IR
|
|
177
|
+
- `./pack-types`: Shared extension/pack typing helpers
|
|
109
178
|
|
|
110
179
|
## Architecture
|
|
111
180
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { _ as StorageColumn, a as ForeignKey, b as UniqueConstraint, c as Index, f as PrimaryKey, g as SqlStorage, h as SqlMappings, l as ModelDefinition, m as SqlContract, o as ForeignKeyOptions, u as ModelField, v as StorageTable } from "./types-T6o5-ZB3.mjs";
|
|
2
|
+
import { ExecutionHashBase, ProfileHashBase, StorageHashBase } from "@prisma-next/contract/types";
|
|
3
|
+
|
|
4
|
+
//#region src/factories.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a StorageColumn with nativeType and codecId.
|
|
8
|
+
*
|
|
9
|
+
* @param nativeType - Native database type identifier (e.g., 'int4', 'text', 'vector')
|
|
10
|
+
* @param codecId - Codec identifier (e.g., 'pg/int4@1', 'pg/text@1')
|
|
11
|
+
* @param nullable - Whether the column is nullable (default: false)
|
|
12
|
+
* @returns StorageColumn with nativeType and codecId
|
|
13
|
+
*/
|
|
14
|
+
declare function col(nativeType: string, codecId: string, nullable?: boolean): StorageColumn;
|
|
15
|
+
declare function pk(...columns: readonly string[]): PrimaryKey;
|
|
16
|
+
declare function unique(...columns: readonly string[]): UniqueConstraint;
|
|
17
|
+
declare function index(...columns: readonly string[]): Index;
|
|
18
|
+
declare function fk(columns: readonly string[], refTable: string, refColumns: readonly string[], opts?: ForeignKeyOptions & {
|
|
19
|
+
constraint?: boolean;
|
|
20
|
+
index?: boolean;
|
|
21
|
+
}): ForeignKey;
|
|
22
|
+
declare function table(columns: Record<string, StorageColumn>, opts?: {
|
|
23
|
+
pk?: PrimaryKey;
|
|
24
|
+
uniques?: readonly UniqueConstraint[];
|
|
25
|
+
indexes?: readonly Index[];
|
|
26
|
+
fks?: readonly ForeignKey[];
|
|
27
|
+
}): StorageTable;
|
|
28
|
+
declare function model(table: string, fields: Record<string, ModelField>, relations?: Record<string, unknown>): ModelDefinition;
|
|
29
|
+
declare function storage(tables: Record<string, StorageTable>): SqlStorage;
|
|
30
|
+
declare function contract<TStorageHash extends StorageHashBase<string> = StorageHashBase<string>, TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>, TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>>(opts: {
|
|
31
|
+
target: string;
|
|
32
|
+
storageHash: TStorageHash;
|
|
33
|
+
executionHash?: TExecutionHash;
|
|
34
|
+
storage: SqlStorage;
|
|
35
|
+
models?: Record<string, ModelDefinition>;
|
|
36
|
+
relations?: Record<string, unknown>;
|
|
37
|
+
mappings?: Partial<SqlMappings>;
|
|
38
|
+
schemaVersion?: '1';
|
|
39
|
+
targetFamily?: 'sql';
|
|
40
|
+
profileHash?: TProfileHash;
|
|
41
|
+
capabilities?: Record<string, Record<string, boolean>>;
|
|
42
|
+
extensionPacks?: Record<string, unknown>;
|
|
43
|
+
meta?: Record<string, unknown>;
|
|
44
|
+
sources?: Record<string, unknown>;
|
|
45
|
+
}): SqlContract<SqlStorage, Record<string, unknown>, Record<string, unknown>, SqlMappings, TStorageHash, TExecutionHash, TProfileHash>;
|
|
46
|
+
//#endregion
|
|
47
|
+
export { col, contract, fk, index, model, pk, storage, table, unique };
|
|
48
|
+
//# sourceMappingURL=factories.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factories.d.mts","names":[],"sources":["../src/factories.ts"],"sourcesContent":[],"mappings":";;;;;;;AA+BA;AAQA;AAMA;AAMA;AAMA;AAqBA;AAC0B,iBAhDV,GAAA,CAgDU,UAAA,EAAA,MAAA,EAAA,OAAA,EAAA,MAAA,EAAA,QAAA,CAAA,EAAA,OAAA,CAAA,EAhDkD,aAgDlD;AAAf,iBAxCK,EAAA,CAwCL,GAAA,OAAA,EAAA,SAAA,MAAA,EAAA,CAAA,EAxCwC,UAwCxC;AAEF,iBApCO,MAAA,CAoCP,GAAA,OAAA,EAAA,SAAA,MAAA,EAAA,CAAA,EApC8C,gBAoC9C;AACc,iBA/BP,KAAA,CA+BO,GAAA,OAAA,EAAA,SAAA,MAAA,EAAA,CAAA,EA/B+B,KA+B/B;AACA,iBA1BP,EAAA,CA0BO,OAAA,EAAA,SAAA,MAAA,EAAA,EAAA,QAAA,EAAA,MAAA,EAAA,UAAA,EAAA,SAAA,MAAA,EAAA,EAAA,IAGR,CAHQ,EAtBd,iBAsBc,GAAA;EACJ,UAAA,CAAA,EAAA,OAAA;EAEhB,KAAA,CAAA,EAAA,OAAA;CAAY,CAAA,EAxBZ,UAwBY;AAUC,iBAlBA,KAAA,CAkBK,OAAA,EAjBV,MAiBU,CAAA,MAAA,EAjBK,aAiBL,CAAA,EAAA,IAIH,CAJG,EAAA;EAEI,EAAA,CAAA,EAjBhB,UAiBgB;EAAf,OAAA,CAAA,EAAA,SAhBa,gBAgBb,EAAA;EACG,OAAA,CAAA,EAAA,SAhBU,KAgBV,EAAA;EACV,GAAA,CAAA,EAAA,SAhBgB,UAgBhB,EAAA;CAAe,CAAA,EAdf,YAce;AASF,iBAbA,KAAA,CAaO,KAAA,EAAA,MAAA,EAAA,MAAA,EAXb,MAWa,CAAA,MAAA,EAXE,UAWF,CAAA,EAAA,SAAA,CAAA,EAVV,MAUU,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,EATpB,eASoB;AAAwB,iBAA/B,OAAA,CAA+B,MAAA,EAAf,MAAe,CAAA,MAAA,EAAA,YAAA,CAAA,CAAA,EAAgB,UAAhB;AAAf,iBAIhB,QAJgB,CAAA,qBAKT,eALS,CAAA,MAAA,CAAA,GAKiB,eALjB,CAAA,MAAA,CAAA,EAAA,uBAMP,iBANO,CAAA,MAAA,CAAA,GAMqB,iBANrB,CAAA,MAAA,CAAA,EAAA,qBAOT,eAPS,CAAA,MAAA,CAAA,GAOiB,eAPjB,CAAA,MAAA,CAAA,CAAA,CAAA,IAAA,EAAA;EAA+B,MAAA,EAAA,MAAA;EAAU,WAAA,EAU1D,YAV0D;EAIzD,aAAQ,CAAA,EAON,cAPM;EACD,OAAA,EAOZ,UAPY;EAA0B,MAAA,CAAA,EAQtC,MARsC,CAAA,MAAA,EAQvB,eARuB,CAAA;EACxB,SAAA,CAAA,EAQX,MARW,CAAA,MAAA,EAAA,OAAA,CAAA;EAA4B,QAAA,CAAA,EASxC,OATwC,CAShC,WATgC,CAAA;EAC9B,aAAA,CAAA,EAAA,GAAA;EAA0B,YAAA,CAAA,EAAA,KAAA;EAGlC,WAAA,CAAA,EAQC,YARD;EACG,YAAA,CAAA,EAQD,MARC,CAAA,MAAA,EAQc,MARd,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA;EACP,cAAA,CAAA,EAQQ,MARR,CAAA,MAAA,EAAA,OAAA,CAAA;EACe,IAAA,CAAA,EAQjB,MARiB,CAAA,MAAA,EAAA,OAAA,CAAA;EAAf,OAAA,CAAA,EASC,MATD,CAAA,MAAA,EAAA,OAAA,CAAA;CACG,CAAA,EASV,WATU,CAUZ,UAVY,EAWZ,MAXY,CAAA,MAAA,EAAA,OAAA,CAAA,EAYZ,MAZY,CAAA,MAAA,EAAA,OAAA,CAAA,EAaZ,WAbY,EAcZ,YAdY,EAeZ,cAfY,EAgBZ,YAhBY,CAAA"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { r as applyFkDefaults } from "./types-kacOgEya.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/factories.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a StorageColumn with nativeType and codecId.
|
|
6
|
+
*
|
|
7
|
+
* @param nativeType - Native database type identifier (e.g., 'int4', 'text', 'vector')
|
|
8
|
+
* @param codecId - Codec identifier (e.g., 'pg/int4@1', 'pg/text@1')
|
|
9
|
+
* @param nullable - Whether the column is nullable (default: false)
|
|
10
|
+
* @returns StorageColumn with nativeType and codecId
|
|
11
|
+
*/
|
|
12
|
+
function col(nativeType, codecId, nullable = false) {
|
|
13
|
+
return {
|
|
14
|
+
nativeType,
|
|
15
|
+
codecId,
|
|
16
|
+
nullable
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function pk(...columns) {
|
|
20
|
+
return { columns };
|
|
21
|
+
}
|
|
22
|
+
function unique(...columns) {
|
|
23
|
+
return { columns };
|
|
24
|
+
}
|
|
25
|
+
function index(...columns) {
|
|
26
|
+
return { columns };
|
|
27
|
+
}
|
|
28
|
+
function fk(columns, refTable, refColumns, opts) {
|
|
29
|
+
return {
|
|
30
|
+
columns,
|
|
31
|
+
references: {
|
|
32
|
+
table: refTable,
|
|
33
|
+
columns: refColumns
|
|
34
|
+
},
|
|
35
|
+
...opts?.name !== void 0 && { name: opts.name },
|
|
36
|
+
...opts?.onDelete !== void 0 && { onDelete: opts.onDelete },
|
|
37
|
+
...opts?.onUpdate !== void 0 && { onUpdate: opts.onUpdate },
|
|
38
|
+
...applyFkDefaults({
|
|
39
|
+
constraint: opts?.constraint,
|
|
40
|
+
index: opts?.index
|
|
41
|
+
})
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function table(columns, opts) {
|
|
45
|
+
return {
|
|
46
|
+
columns,
|
|
47
|
+
...opts?.pk !== void 0 && { primaryKey: opts.pk },
|
|
48
|
+
uniques: opts?.uniques ?? [],
|
|
49
|
+
indexes: opts?.indexes ?? [],
|
|
50
|
+
foreignKeys: opts?.fks ?? []
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function model(table$1, fields, relations = {}) {
|
|
54
|
+
return {
|
|
55
|
+
storage: { table: table$1 },
|
|
56
|
+
fields,
|
|
57
|
+
relations
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function storage(tables) {
|
|
61
|
+
return { tables };
|
|
62
|
+
}
|
|
63
|
+
function contract(opts) {
|
|
64
|
+
return {
|
|
65
|
+
schemaVersion: opts.schemaVersion ?? "1",
|
|
66
|
+
target: opts.target,
|
|
67
|
+
targetFamily: opts.targetFamily ?? "sql",
|
|
68
|
+
storageHash: opts.storageHash,
|
|
69
|
+
...opts.executionHash !== void 0 && { executionHash: opts.executionHash },
|
|
70
|
+
storage: opts.storage,
|
|
71
|
+
models: opts.models ?? {},
|
|
72
|
+
relations: opts.relations ?? {},
|
|
73
|
+
mappings: opts.mappings ?? {},
|
|
74
|
+
...opts.profileHash !== void 0 && { profileHash: opts.profileHash },
|
|
75
|
+
...opts.capabilities !== void 0 && { capabilities: opts.capabilities },
|
|
76
|
+
...opts.extensionPacks !== void 0 && { extensionPacks: opts.extensionPacks },
|
|
77
|
+
...opts.meta !== void 0 && { meta: opts.meta },
|
|
78
|
+
...opts.sources !== void 0 && { sources: opts.sources }
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//#endregion
|
|
83
|
+
export { col, contract, fk, index, model, pk, storage, table, unique };
|
|
84
|
+
//# sourceMappingURL=factories.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factories.mjs","names":[],"sources":["../src/factories.ts"],"sourcesContent":["import type {\n ExecutionHashBase,\n ProfileHashBase,\n StorageHashBase,\n} from '@prisma-next/contract/types';\nimport type {\n ForeignKey,\n ForeignKeyOptions,\n ForeignKeyReferences,\n Index,\n ModelDefinition,\n ModelField,\n ModelStorage,\n PrimaryKey,\n SqlContract,\n SqlMappings,\n SqlStorage,\n StorageColumn,\n StorageTable,\n UniqueConstraint,\n} from './types';\nimport { applyFkDefaults } from './types';\n\n/**\n * Creates a StorageColumn with nativeType and codecId.\n *\n * @param nativeType - Native database type identifier (e.g., 'int4', 'text', 'vector')\n * @param codecId - Codec identifier (e.g., 'pg/int4@1', 'pg/text@1')\n * @param nullable - Whether the column is nullable (default: false)\n * @returns StorageColumn with nativeType and codecId\n */\nexport function col(nativeType: string, codecId: string, nullable = false): StorageColumn {\n return {\n nativeType,\n codecId,\n nullable,\n };\n}\n\nexport function pk(...columns: readonly string[]): PrimaryKey {\n return {\n columns,\n };\n}\n\nexport function unique(...columns: readonly string[]): UniqueConstraint {\n return {\n columns,\n };\n}\n\nexport function index(...columns: readonly string[]): Index {\n return {\n columns,\n };\n}\n\nexport function fk(\n columns: readonly string[],\n refTable: string,\n refColumns: readonly string[],\n opts?: ForeignKeyOptions & { constraint?: boolean; index?: boolean },\n): ForeignKey {\n const references: ForeignKeyReferences = {\n table: refTable,\n columns: refColumns,\n };\n\n return {\n columns,\n references,\n ...(opts?.name !== undefined && { name: opts.name }),\n ...(opts?.onDelete !== undefined && { onDelete: opts.onDelete }),\n ...(opts?.onUpdate !== undefined && { onUpdate: opts.onUpdate }),\n ...applyFkDefaults({ constraint: opts?.constraint, index: opts?.index }),\n };\n}\n\nexport function table(\n columns: Record<string, StorageColumn>,\n opts?: {\n pk?: PrimaryKey;\n uniques?: readonly UniqueConstraint[];\n indexes?: readonly Index[];\n fks?: readonly ForeignKey[];\n },\n): StorageTable {\n return {\n columns,\n ...(opts?.pk !== undefined && { primaryKey: opts.pk }),\n uniques: opts?.uniques ?? [],\n indexes: opts?.indexes ?? [],\n foreignKeys: opts?.fks ?? [],\n };\n}\n\nexport function model(\n table: string,\n fields: Record<string, ModelField>,\n relations: Record<string, unknown> = {},\n): ModelDefinition {\n const storage: ModelStorage = { table };\n return {\n storage,\n fields,\n relations,\n };\n}\n\nexport function storage(tables: Record<string, StorageTable>): SqlStorage {\n return { tables };\n}\n\nexport function contract<\n TStorageHash extends StorageHashBase<string> = StorageHashBase<string>,\n TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>,\n TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>,\n>(opts: {\n target: string;\n storageHash: TStorageHash;\n executionHash?: TExecutionHash;\n storage: SqlStorage;\n models?: Record<string, ModelDefinition>;\n relations?: Record<string, unknown>;\n mappings?: Partial<SqlMappings>;\n schemaVersion?: '1';\n targetFamily?: 'sql';\n profileHash?: TProfileHash;\n capabilities?: Record<string, Record<string, boolean>>;\n extensionPacks?: Record<string, unknown>;\n meta?: Record<string, unknown>;\n sources?: Record<string, unknown>;\n}): SqlContract<\n SqlStorage,\n Record<string, unknown>,\n Record<string, unknown>,\n SqlMappings,\n TStorageHash,\n TExecutionHash,\n TProfileHash\n> {\n return {\n schemaVersion: opts.schemaVersion ?? '1',\n target: opts.target,\n targetFamily: opts.targetFamily ?? 'sql',\n storageHash: opts.storageHash,\n ...(opts.executionHash !== undefined && { executionHash: opts.executionHash }),\n storage: opts.storage,\n models: opts.models ?? {},\n relations: opts.relations ?? {},\n mappings: (opts.mappings ?? {}) as SqlMappings,\n ...(opts.profileHash !== undefined && { profileHash: opts.profileHash }),\n ...(opts.capabilities !== undefined && { capabilities: opts.capabilities }),\n ...(opts.extensionPacks !== undefined && { extensionPacks: opts.extensionPacks }),\n ...(opts.meta !== undefined && { meta: opts.meta }),\n ...(opts.sources !== undefined && { sources: opts.sources as Record<string, unknown> }),\n } as SqlContract<\n SqlStorage,\n Record<string, unknown>,\n Record<string, unknown>,\n SqlMappings,\n TStorageHash,\n TExecutionHash,\n TProfileHash\n >;\n}\n"],"mappings":";;;;;;;;;;;AA+BA,SAAgB,IAAI,YAAoB,SAAiB,WAAW,OAAsB;AACxF,QAAO;EACL;EACA;EACA;EACD;;AAGH,SAAgB,GAAG,GAAG,SAAwC;AAC5D,QAAO,EACL,SACD;;AAGH,SAAgB,OAAO,GAAG,SAA8C;AACtE,QAAO,EACL,SACD;;AAGH,SAAgB,MAAM,GAAG,SAAmC;AAC1D,QAAO,EACL,SACD;;AAGH,SAAgB,GACd,SACA,UACA,YACA,MACY;AAMZ,QAAO;EACL;EACA,YAPuC;GACvC,OAAO;GACP,SAAS;GACV;EAKC,GAAI,MAAM,SAAS,UAAa,EAAE,MAAM,KAAK,MAAM;EACnD,GAAI,MAAM,aAAa,UAAa,EAAE,UAAU,KAAK,UAAU;EAC/D,GAAI,MAAM,aAAa,UAAa,EAAE,UAAU,KAAK,UAAU;EAC/D,GAAG,gBAAgB;GAAE,YAAY,MAAM;GAAY,OAAO,MAAM;GAAO,CAAC;EACzE;;AAGH,SAAgB,MACd,SACA,MAMc;AACd,QAAO;EACL;EACA,GAAI,MAAM,OAAO,UAAa,EAAE,YAAY,KAAK,IAAI;EACrD,SAAS,MAAM,WAAW,EAAE;EAC5B,SAAS,MAAM,WAAW,EAAE;EAC5B,aAAa,MAAM,OAAO,EAAE;EAC7B;;AAGH,SAAgB,MACd,SACA,QACA,YAAqC,EAAE,EACtB;AAEjB,QAAO;EACL,SAF4B,EAAE,gBAAO;EAGrC;EACA;EACD;;AAGH,SAAgB,QAAQ,QAAkD;AACxE,QAAO,EAAE,QAAQ;;AAGnB,SAAgB,SAId,MAuBA;AACA,QAAO;EACL,eAAe,KAAK,iBAAiB;EACrC,QAAQ,KAAK;EACb,cAAc,KAAK,gBAAgB;EACnC,aAAa,KAAK;EAClB,GAAI,KAAK,kBAAkB,UAAa,EAAE,eAAe,KAAK,eAAe;EAC7E,SAAS,KAAK;EACd,QAAQ,KAAK,UAAU,EAAE;EACzB,WAAW,KAAK,aAAa,EAAE;EAC/B,UAAW,KAAK,YAAY,EAAE;EAC9B,GAAI,KAAK,gBAAgB,UAAa,EAAE,aAAa,KAAK,aAAa;EACvE,GAAI,KAAK,iBAAiB,UAAa,EAAE,cAAc,KAAK,cAAc;EAC1E,GAAI,KAAK,mBAAmB,UAAa,EAAE,gBAAgB,KAAK,gBAAgB;EAChF,GAAI,KAAK,SAAS,UAAa,EAAE,MAAM,KAAK,MAAM;EAClD,GAAI,KAAK,YAAY,UAAa,EAAE,SAAS,KAAK,SAAoC;EACvF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/pack-types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Storage type metadata for pack refs.
|
|
4
|
+
*/
|
|
5
|
+
interface StorageTypeMetadata {
|
|
6
|
+
readonly typeId: string;
|
|
7
|
+
readonly familyId: string;
|
|
8
|
+
readonly targetId: string;
|
|
9
|
+
readonly nativeType?: string;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { type StorageTypeMetadata };
|
|
13
|
+
//# sourceMappingURL=pack-types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pack-types.d.mts","names":[],"sources":["../src/pack-types.ts"],"sourcesContent":[],"mappings":";;AAGA;;UAAiB,mBAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { ColumnDefault, ContractBase, ExecutionHashBase, ExecutionSection, ProfileHashBase, StorageHashBase } from "@prisma-next/contract/types";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A column definition in storage.
|
|
7
|
+
*
|
|
8
|
+
* `typeParams` is optional because most columns use non-parameterized types.
|
|
9
|
+
* Columns with parameterized types can either inline `typeParams` or reference
|
|
10
|
+
* a named {@link StorageTypeInstance} via `typeRef`.
|
|
11
|
+
*/
|
|
12
|
+
type StorageColumn = {
|
|
13
|
+
readonly nativeType: string;
|
|
14
|
+
readonly codecId: string;
|
|
15
|
+
readonly nullable: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Opaque, codec-owned JS/type parameters.
|
|
18
|
+
* The codec that owns `codecId` defines the shape and semantics.
|
|
19
|
+
* Mutually exclusive with `typeRef`.
|
|
20
|
+
*/
|
|
21
|
+
readonly typeParams?: Record<string, unknown>;
|
|
22
|
+
/**
|
|
23
|
+
* Reference to a named type instance in `storage.types`.
|
|
24
|
+
* Mutually exclusive with `typeParams`.
|
|
25
|
+
*/
|
|
26
|
+
readonly typeRef?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Default value for the column.
|
|
29
|
+
* Can be a literal value or database function.
|
|
30
|
+
*/
|
|
31
|
+
readonly default?: ColumnDefault;
|
|
32
|
+
};
|
|
33
|
+
type PrimaryKey = {
|
|
34
|
+
readonly columns: readonly string[];
|
|
35
|
+
readonly name?: string;
|
|
36
|
+
};
|
|
37
|
+
type UniqueConstraint = {
|
|
38
|
+
readonly columns: readonly string[];
|
|
39
|
+
readonly name?: string;
|
|
40
|
+
};
|
|
41
|
+
type Index = {
|
|
42
|
+
readonly columns: readonly string[];
|
|
43
|
+
readonly name?: string;
|
|
44
|
+
};
|
|
45
|
+
type ForeignKeyReferences = {
|
|
46
|
+
readonly table: string;
|
|
47
|
+
readonly columns: readonly string[];
|
|
48
|
+
};
|
|
49
|
+
type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';
|
|
50
|
+
type ForeignKeyOptions = {
|
|
51
|
+
readonly name?: string;
|
|
52
|
+
readonly onDelete?: ReferentialAction;
|
|
53
|
+
readonly onUpdate?: ReferentialAction;
|
|
54
|
+
};
|
|
55
|
+
type ForeignKey = {
|
|
56
|
+
readonly columns: readonly string[];
|
|
57
|
+
readonly references: ForeignKeyReferences;
|
|
58
|
+
readonly name?: string;
|
|
59
|
+
readonly onDelete?: ReferentialAction;
|
|
60
|
+
readonly onUpdate?: ReferentialAction;
|
|
61
|
+
/** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */
|
|
62
|
+
readonly constraint: boolean;
|
|
63
|
+
/** Whether to emit a backing index for the FK columns. */
|
|
64
|
+
readonly index: boolean;
|
|
65
|
+
};
|
|
66
|
+
type StorageTable = {
|
|
67
|
+
readonly columns: Record<string, StorageColumn>;
|
|
68
|
+
readonly primaryKey?: PrimaryKey;
|
|
69
|
+
readonly uniques: ReadonlyArray<UniqueConstraint>;
|
|
70
|
+
readonly indexes: ReadonlyArray<Index>;
|
|
71
|
+
readonly foreignKeys: ReadonlyArray<ForeignKey>;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* A named, parameterized type instance.
|
|
75
|
+
* These are registered in `storage.types` for reuse across columns
|
|
76
|
+
* and to enable ergonomic schema surfaces like `schema.types.MyType`.
|
|
77
|
+
*
|
|
78
|
+
* Unlike {@link StorageColumn}, `typeParams` is required here because
|
|
79
|
+
* `StorageTypeInstance` exists specifically to define reusable parameterized types.
|
|
80
|
+
* A type instance without parameters would be redundant—columns can reference
|
|
81
|
+
* the codec directly via `codecId`.
|
|
82
|
+
*/
|
|
83
|
+
type StorageTypeInstance = {
|
|
84
|
+
readonly codecId: string;
|
|
85
|
+
readonly nativeType: string;
|
|
86
|
+
readonly typeParams: Record<string, unknown>;
|
|
87
|
+
};
|
|
88
|
+
type SqlStorage = {
|
|
89
|
+
readonly tables: Record<string, StorageTable>;
|
|
90
|
+
/**
|
|
91
|
+
* Named type instances for parameterized/custom types.
|
|
92
|
+
* Columns can reference these via `typeRef`.
|
|
93
|
+
*/
|
|
94
|
+
readonly types?: Record<string, StorageTypeInstance>;
|
|
95
|
+
};
|
|
96
|
+
type ModelField = {
|
|
97
|
+
readonly column: string;
|
|
98
|
+
};
|
|
99
|
+
type ModelStorage = {
|
|
100
|
+
readonly table: string;
|
|
101
|
+
};
|
|
102
|
+
type ModelDefinition = {
|
|
103
|
+
readonly storage: ModelStorage;
|
|
104
|
+
readonly fields: Record<string, ModelField>;
|
|
105
|
+
readonly relations: Record<string, unknown>;
|
|
106
|
+
};
|
|
107
|
+
type SqlMappings = {
|
|
108
|
+
readonly modelToTable?: Record<string, string>;
|
|
109
|
+
readonly tableToModel?: Record<string, string>;
|
|
110
|
+
readonly fieldToColumn?: Record<string, Record<string, string>>;
|
|
111
|
+
readonly columnToField?: Record<string, Record<string, string>>;
|
|
112
|
+
readonly codecTypes: Record<string, {
|
|
113
|
+
readonly output: unknown;
|
|
114
|
+
}>;
|
|
115
|
+
readonly operationTypes: Record<string, Record<string, unknown>>;
|
|
116
|
+
};
|
|
117
|
+
declare const DEFAULT_FK_CONSTRAINT = true;
|
|
118
|
+
declare const DEFAULT_FK_INDEX = true;
|
|
119
|
+
/**
|
|
120
|
+
* Resolves foreign key `constraint` and `index` fields to their effective boolean values,
|
|
121
|
+
* falling back through optional override defaults, then to the global defaults.
|
|
122
|
+
*/
|
|
123
|
+
declare function applyFkDefaults(fk: {
|
|
124
|
+
constraint?: boolean | undefined;
|
|
125
|
+
index?: boolean | undefined;
|
|
126
|
+
}, overrideDefaults?: {
|
|
127
|
+
constraint?: boolean | undefined;
|
|
128
|
+
index?: boolean | undefined;
|
|
129
|
+
}): {
|
|
130
|
+
constraint: boolean;
|
|
131
|
+
index: boolean;
|
|
132
|
+
};
|
|
133
|
+
type SqlContract<S extends SqlStorage = SqlStorage, M extends Record<string, unknown> = Record<string, unknown>, R extends Record<string, unknown> = Record<string, unknown>, Map extends SqlMappings = SqlMappings, TStorageHash extends StorageHashBase<string> = StorageHashBase<string>, TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>, TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>> = ContractBase<TStorageHash, TExecutionHash, TProfileHash> & {
|
|
134
|
+
readonly targetFamily: string;
|
|
135
|
+
readonly storage: S;
|
|
136
|
+
readonly models: M;
|
|
137
|
+
readonly relations: R;
|
|
138
|
+
readonly mappings: Map;
|
|
139
|
+
readonly execution?: ExecutionSection;
|
|
140
|
+
};
|
|
141
|
+
type ExtractCodecTypes<TContract extends SqlContract<SqlStorage>> = TContract['mappings']['codecTypes'];
|
|
142
|
+
type ExtractOperationTypes<TContract extends SqlContract<SqlStorage>> = TContract['mappings']['operationTypes'];
|
|
143
|
+
//#endregion
|
|
144
|
+
export { StorageColumn as _, ForeignKey as a, UniqueConstraint as b, Index as c, ModelStorage as d, PrimaryKey as f, SqlStorage as g, SqlMappings as h, ExtractOperationTypes as i, ModelDefinition as l, SqlContract as m, DEFAULT_FK_INDEX as n, ForeignKeyOptions as o, ReferentialAction as p, ExtractCodecTypes as r, ForeignKeyReferences as s, DEFAULT_FK_CONSTRAINT as t, ModelField as u, StorageTable as v, applyFkDefaults as x, StorageTypeInstance as y };
|
|
145
|
+
//# sourceMappingURL=types-T6o5-ZB3.d.mts.map
|