@prisma-next/contract-authoring 0.3.0-dev.34 → 0.3.0-dev.35
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/README.md +2 -0
- package/dist/index.d.mts +283 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +221 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +18 -10
- package/src/builder-state.ts +46 -9
- package/src/contract-builder.ts +14 -14
- package/src/table-builder.ts +118 -13
- package/src/types.ts +2 -0
- package/dist/builder-state.d.ts +0 -95
- package/dist/builder-state.d.ts.map +0 -1
- package/dist/contract-builder.d.ts +0 -15
- package/dist/contract-builder.d.ts.map +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -243
- package/dist/index.js.map +0 -1
- package/dist/model-builder.d.ts +0 -38
- package/dist/model-builder.d.ts.map +0 -1
- package/dist/table-builder.d.ts +0 -33
- package/dist/table-builder.d.ts.map +0 -1
- package/dist/types.d.ts +0 -46
- package/dist/types.d.ts.map +0 -1
package/src/builder-state.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ColumnDefault, ExecutionMutationDefaultValue } from '@prisma-next/contract/types';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Column type descriptor containing both codec ID and native type.
|
|
3
5
|
* Used when defining columns with descriptor objects instead of string IDs.
|
|
@@ -10,19 +12,53 @@ export type ColumnTypeDescriptor = {
|
|
|
10
12
|
readonly codecId: string;
|
|
11
13
|
readonly nativeType: string;
|
|
12
14
|
readonly typeParams?: Record<string, unknown>;
|
|
15
|
+
readonly typeRef?: string;
|
|
13
16
|
};
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
> {
|
|
18
|
+
/**
|
|
19
|
+
* Base column properties shared by all column states.
|
|
20
|
+
*/
|
|
21
|
+
type ColumnBuilderStateBase<Name extends string, Type extends string> = {
|
|
20
22
|
readonly name: Name;
|
|
21
|
-
readonly nullable: Nullable;
|
|
22
23
|
readonly type: Type;
|
|
23
24
|
readonly nativeType: string;
|
|
24
25
|
readonly typeParams?: Record<string, unknown>;
|
|
25
|
-
|
|
26
|
+
readonly typeRef?: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type StorageTypeInstanceState = {
|
|
30
|
+
readonly codecId: string;
|
|
31
|
+
readonly nativeType: string;
|
|
32
|
+
readonly typeParams: Record<string, unknown>;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Descriptive error type shown when attempting to use both nullable and default.
|
|
37
|
+
* This string literal appears in TypeScript error messages for better DX.
|
|
38
|
+
*/
|
|
39
|
+
export type NullableColumnCannotHaveDefault =
|
|
40
|
+
"Error: A nullable column cannot have a default value. Remove 'nullable: true' or remove 'default'.";
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Column builder state with enforced nullable/default mutual exclusivity.
|
|
44
|
+
*
|
|
45
|
+
* Invariant: A column with a default value is always NOT NULL.
|
|
46
|
+
* This is enforced at the type level via conditional types:
|
|
47
|
+
* - Nullable columns (`nullable: true`) cannot have a `default` property
|
|
48
|
+
* - Non-nullable columns (`nullable: false`) can optionally have a `default` property
|
|
49
|
+
*/
|
|
50
|
+
export type ColumnBuilderState<
|
|
51
|
+
Name extends string,
|
|
52
|
+
Nullable extends boolean,
|
|
53
|
+
Type extends string,
|
|
54
|
+
> = ColumnBuilderStateBase<Name, Type> &
|
|
55
|
+
(Nullable extends true
|
|
56
|
+
? { readonly nullable: true; readonly default?: NullableColumnCannotHaveDefault }
|
|
57
|
+
: {
|
|
58
|
+
readonly nullable: false;
|
|
59
|
+
readonly default?: ColumnDefault;
|
|
60
|
+
readonly executionDefault?: ExecutionMutationDefaultValue;
|
|
61
|
+
});
|
|
26
62
|
|
|
27
63
|
/**
|
|
28
64
|
* Unique constraint definition for table builder.
|
|
@@ -116,16 +152,17 @@ export interface ContractBuilderState<
|
|
|
116
152
|
never,
|
|
117
153
|
ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>
|
|
118
154
|
>,
|
|
119
|
-
|
|
155
|
+
StorageHash extends string | undefined = string | undefined,
|
|
120
156
|
ExtensionPacks extends Record<string, unknown> | undefined = undefined,
|
|
121
157
|
Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined,
|
|
122
158
|
> {
|
|
123
159
|
readonly target?: Target;
|
|
124
160
|
readonly tables: Tables;
|
|
125
161
|
readonly models: Models;
|
|
126
|
-
readonly
|
|
162
|
+
readonly storageHash?: StorageHash;
|
|
127
163
|
readonly extensionPacks?: ExtensionPacks;
|
|
128
164
|
readonly capabilities?: Capabilities;
|
|
165
|
+
readonly storageTypes?: Record<string, StorageTypeInstanceState>;
|
|
129
166
|
/**
|
|
130
167
|
* Array of extension pack namespace identifiers (e.g., ['pgvector', 'postgis']).
|
|
131
168
|
* Populated when extension packs are registered during contract building.
|
package/src/contract-builder.ts
CHANGED
|
@@ -23,7 +23,7 @@ export class ContractBuilder<
|
|
|
23
23
|
string,
|
|
24
24
|
ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>
|
|
25
25
|
> = Record<never, never>,
|
|
26
|
-
|
|
26
|
+
StorageHash extends string | undefined = undefined,
|
|
27
27
|
ExtensionPacks extends Record<string, unknown> | undefined = undefined,
|
|
28
28
|
Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined,
|
|
29
29
|
> {
|
|
@@ -31,26 +31,26 @@ export class ContractBuilder<
|
|
|
31
31
|
Target,
|
|
32
32
|
Tables,
|
|
33
33
|
Models,
|
|
34
|
-
|
|
34
|
+
StorageHash,
|
|
35
35
|
ExtensionPacks,
|
|
36
36
|
Capabilities
|
|
37
37
|
>;
|
|
38
38
|
|
|
39
39
|
constructor(
|
|
40
|
-
state?: ContractBuilderState<Target, Tables, Models,
|
|
40
|
+
state?: ContractBuilderState<Target, Tables, Models, StorageHash, ExtensionPacks, Capabilities>,
|
|
41
41
|
) {
|
|
42
42
|
this.state =
|
|
43
43
|
state ??
|
|
44
44
|
({
|
|
45
45
|
tables: {},
|
|
46
46
|
models: {},
|
|
47
|
-
} as ContractBuilderState<Target, Tables, Models,
|
|
47
|
+
} as ContractBuilderState<Target, Tables, Models, StorageHash, ExtensionPacks, Capabilities>);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
target<T extends string>(
|
|
51
51
|
packRef: TargetPackRef<string, T>,
|
|
52
|
-
): ContractBuilder<T, Tables, Models,
|
|
53
|
-
return new ContractBuilder<T, Tables, Models,
|
|
52
|
+
): ContractBuilder<T, Tables, Models, StorageHash, ExtensionPacks, Capabilities> {
|
|
53
|
+
return new ContractBuilder<T, Tables, Models, StorageHash, ExtensionPacks, Capabilities>({
|
|
54
54
|
...this.state,
|
|
55
55
|
target: packRef.targetId,
|
|
56
56
|
});
|
|
@@ -58,8 +58,8 @@ export class ContractBuilder<
|
|
|
58
58
|
|
|
59
59
|
capabilities<C extends Record<string, Record<string, boolean>>>(
|
|
60
60
|
capabilities: C,
|
|
61
|
-
): ContractBuilder<Target, Tables, Models,
|
|
62
|
-
return new ContractBuilder<Target, Tables, Models,
|
|
61
|
+
): ContractBuilder<Target, Tables, Models, StorageHash, ExtensionPacks, C> {
|
|
62
|
+
return new ContractBuilder<Target, Tables, Models, StorageHash, ExtensionPacks, C>({
|
|
63
63
|
...this.state,
|
|
64
64
|
capabilities,
|
|
65
65
|
});
|
|
@@ -79,7 +79,7 @@ export class ContractBuilder<
|
|
|
79
79
|
Target,
|
|
80
80
|
Tables & Record<TableName, ReturnType<T['build']>>,
|
|
81
81
|
Models,
|
|
82
|
-
|
|
82
|
+
StorageHash,
|
|
83
83
|
ExtensionPacks,
|
|
84
84
|
Capabilities
|
|
85
85
|
> {
|
|
@@ -92,7 +92,7 @@ export class ContractBuilder<
|
|
|
92
92
|
Target,
|
|
93
93
|
Tables & Record<TableName, ReturnType<T['build']>>,
|
|
94
94
|
Models,
|
|
95
|
-
|
|
95
|
+
StorageHash,
|
|
96
96
|
ExtensionPacks,
|
|
97
97
|
Capabilities
|
|
98
98
|
>({
|
|
@@ -121,7 +121,7 @@ export class ContractBuilder<
|
|
|
121
121
|
Target,
|
|
122
122
|
Tables,
|
|
123
123
|
Models & Record<ModelName, ReturnType<M['build']>>,
|
|
124
|
-
|
|
124
|
+
StorageHash,
|
|
125
125
|
ExtensionPacks,
|
|
126
126
|
Capabilities
|
|
127
127
|
> {
|
|
@@ -134,7 +134,7 @@ export class ContractBuilder<
|
|
|
134
134
|
Target,
|
|
135
135
|
Tables,
|
|
136
136
|
Models & Record<ModelName, ReturnType<M['build']>>,
|
|
137
|
-
|
|
137
|
+
StorageHash,
|
|
138
138
|
ExtensionPacks,
|
|
139
139
|
Capabilities
|
|
140
140
|
>({
|
|
@@ -144,12 +144,12 @@ export class ContractBuilder<
|
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
|
|
147
|
+
storageHash<H extends string>(
|
|
148
148
|
hash: H,
|
|
149
149
|
): ContractBuilder<Target, Tables, Models, H, ExtensionPacks, Capabilities> {
|
|
150
150
|
return new ContractBuilder<Target, Tables, Models, H, ExtensionPacks, Capabilities>({
|
|
151
151
|
...this.state,
|
|
152
|
-
|
|
152
|
+
storageHash: hash,
|
|
153
153
|
});
|
|
154
154
|
}
|
|
155
155
|
}
|
package/src/table-builder.ts
CHANGED
|
@@ -1,12 +1,62 @@
|
|
|
1
|
+
import type { ColumnDefault, ExecutionMutationDefaultValue } from '@prisma-next/contract/types';
|
|
2
|
+
import { ifDefined } from '@prisma-next/utils/defined';
|
|
1
3
|
import type {
|
|
2
4
|
ColumnBuilderState,
|
|
3
5
|
ColumnTypeDescriptor,
|
|
4
6
|
ForeignKeyDef,
|
|
5
7
|
IndexDef,
|
|
8
|
+
NullableColumnCannotHaveDefault,
|
|
6
9
|
TableBuilderState,
|
|
7
10
|
UniqueConstraintDef,
|
|
8
11
|
} from './builder-state';
|
|
9
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Column options for nullable columns.
|
|
15
|
+
* Nullable columns cannot have a default value.
|
|
16
|
+
*/
|
|
17
|
+
interface NullableColumnOptions<Descriptor extends ColumnTypeDescriptor> {
|
|
18
|
+
type: Descriptor;
|
|
19
|
+
nullable: true;
|
|
20
|
+
typeParams?: Record<string, unknown>;
|
|
21
|
+
default?: NullableColumnCannotHaveDefault;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Column options for non-nullable columns.
|
|
26
|
+
* Non-nullable columns can optionally have a default value.
|
|
27
|
+
*/
|
|
28
|
+
interface NonNullableColumnOptions<Descriptor extends ColumnTypeDescriptor> {
|
|
29
|
+
type: Descriptor;
|
|
30
|
+
nullable?: false;
|
|
31
|
+
typeParams?: Record<string, unknown>;
|
|
32
|
+
default?: ColumnDefault;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type GeneratedColumnOptions<Descriptor extends ColumnTypeDescriptor> = Omit<
|
|
36
|
+
NonNullableColumnOptions<Descriptor>,
|
|
37
|
+
'default' | 'nullable'
|
|
38
|
+
> & {
|
|
39
|
+
/**
|
|
40
|
+
* Generated columns are always non-nullable and use mutation-time defaults
|
|
41
|
+
* that the runtime injects when the column is omitted from insert input.
|
|
42
|
+
*/
|
|
43
|
+
nullable?: false;
|
|
44
|
+
generated: ExecutionMutationDefaultValue;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Column options that enforce nullable/default mutual exclusivity.
|
|
49
|
+
*
|
|
50
|
+
* Invariant: A column with a default value is always NOT NULL.
|
|
51
|
+
* - If `nullable: true`, the `default` property is forbidden
|
|
52
|
+
* - If `nullable` is `false` or omitted, the `default` property is allowed
|
|
53
|
+
*/
|
|
54
|
+
type ColumnOptions<Descriptor extends ColumnTypeDescriptor> =
|
|
55
|
+
| NullableColumnOptions<Descriptor>
|
|
56
|
+
| NonNullableColumnOptions<Descriptor>;
|
|
57
|
+
|
|
58
|
+
type NullableFromOptions<TOptions> = TOptions extends { nullable: true } ? true : false;
|
|
59
|
+
|
|
10
60
|
interface TableBuilderInternalState<
|
|
11
61
|
Name extends string,
|
|
12
62
|
Columns extends Record<string, ColumnBuilderState<string, boolean, string>>,
|
|
@@ -77,41 +127,96 @@ export class TableBuilder<
|
|
|
77
127
|
return this._state.primaryKey;
|
|
78
128
|
}
|
|
79
129
|
|
|
80
|
-
|
|
130
|
+
/**
|
|
131
|
+
* Add a nullable column to the table.
|
|
132
|
+
* Nullable columns cannot have a default value.
|
|
133
|
+
*/
|
|
134
|
+
column<ColName extends string, Descriptor extends ColumnTypeDescriptor>(
|
|
135
|
+
name: ColName,
|
|
136
|
+
options: NullableColumnOptions<Descriptor>,
|
|
137
|
+
): TableBuilder<
|
|
138
|
+
Name,
|
|
139
|
+
Columns & Record<ColName, ColumnBuilderState<ColName, true, Descriptor['codecId']>>,
|
|
140
|
+
PrimaryKey
|
|
141
|
+
>;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Add a non-nullable column to the table.
|
|
145
|
+
* Non-nullable columns can optionally have a default value.
|
|
146
|
+
*/
|
|
147
|
+
column<ColName extends string, Descriptor extends ColumnTypeDescriptor>(
|
|
148
|
+
name: ColName,
|
|
149
|
+
options: NonNullableColumnOptions<Descriptor>,
|
|
150
|
+
): TableBuilder<
|
|
151
|
+
Name,
|
|
152
|
+
Columns & Record<ColName, ColumnBuilderState<ColName, false, Descriptor['codecId']>>,
|
|
153
|
+
PrimaryKey
|
|
154
|
+
>;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Implementation of the column method.
|
|
158
|
+
*/
|
|
159
|
+
column<ColName extends string, Descriptor extends ColumnTypeDescriptor>(
|
|
160
|
+
name: ColName,
|
|
161
|
+
options: ColumnOptions<Descriptor>,
|
|
162
|
+
): TableBuilder<
|
|
163
|
+
Name,
|
|
164
|
+
Columns & Record<ColName, ColumnBuilderState<ColName, boolean, Descriptor['codecId']>>,
|
|
165
|
+
PrimaryKey
|
|
166
|
+
> {
|
|
167
|
+
return this.columnInternal(name, options);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
generated<ColName extends string, Descriptor extends ColumnTypeDescriptor>(
|
|
171
|
+
name: ColName,
|
|
172
|
+
options: GeneratedColumnOptions<Descriptor>,
|
|
173
|
+
): TableBuilder<
|
|
174
|
+
Name,
|
|
175
|
+
Columns & Record<ColName, ColumnBuilderState<ColName, false, Descriptor['codecId']>>,
|
|
176
|
+
PrimaryKey
|
|
177
|
+
> {
|
|
178
|
+
const { generated, ...columnOptions } = options;
|
|
179
|
+
return this.columnInternal(name, columnOptions, generated);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
private columnInternal<
|
|
81
183
|
ColName extends string,
|
|
82
184
|
Descriptor extends ColumnTypeDescriptor,
|
|
83
|
-
|
|
185
|
+
Options extends ColumnOptions<Descriptor>,
|
|
84
186
|
>(
|
|
85
187
|
name: ColName,
|
|
86
|
-
options:
|
|
87
|
-
|
|
88
|
-
nullable?: Nullable;
|
|
89
|
-
typeParams?: Record<string, unknown>;
|
|
90
|
-
},
|
|
188
|
+
options: Options,
|
|
189
|
+
executionDefault?: ExecutionMutationDefaultValue,
|
|
91
190
|
): TableBuilder<
|
|
92
191
|
Name,
|
|
93
192
|
Columns &
|
|
94
193
|
Record<
|
|
95
194
|
ColName,
|
|
96
|
-
ColumnBuilderState<ColName,
|
|
195
|
+
ColumnBuilderState<ColName, NullableFromOptions<Options>, Descriptor['codecId']>
|
|
97
196
|
>,
|
|
98
197
|
PrimaryKey
|
|
99
198
|
> {
|
|
100
|
-
const nullable =
|
|
101
|
-
const { codecId, nativeType, typeParams: descriptorTypeParams } = options.type;
|
|
199
|
+
const nullable = options.nullable ?? false;
|
|
200
|
+
const { codecId, nativeType, typeParams: descriptorTypeParams, typeRef } = options.type;
|
|
102
201
|
const typeParams = options.typeParams ?? descriptorTypeParams;
|
|
103
202
|
|
|
203
|
+
// The type safety is enforced at the call site via overloads:
|
|
204
|
+
// - NullableColumnOptions forbids `default` when `nullable: true`
|
|
205
|
+
// - NonNullableColumnOptions allows `default` when `nullable` is false/omitted
|
|
104
206
|
const columnState = {
|
|
105
207
|
name,
|
|
106
208
|
nullable,
|
|
107
209
|
type: codecId,
|
|
108
210
|
nativeType,
|
|
109
|
-
...(typeParams
|
|
110
|
-
|
|
211
|
+
...ifDefined('typeParams', typeParams),
|
|
212
|
+
...ifDefined('typeRef', typeRef),
|
|
213
|
+
...ifDefined('default', 'default' in options ? options.default : undefined),
|
|
214
|
+
...ifDefined('executionDefault', executionDefault),
|
|
215
|
+
} as ColumnBuilderState<ColName, NullableFromOptions<Options>, Descriptor['codecId']>;
|
|
111
216
|
const newColumns = { ...this._columns, [name]: columnState } as Columns &
|
|
112
217
|
Record<
|
|
113
218
|
ColName,
|
|
114
|
-
ColumnBuilderState<ColName,
|
|
219
|
+
ColumnBuilderState<ColName, NullableFromOptions<Options>, Descriptor['codecId']>
|
|
115
220
|
>;
|
|
116
221
|
return new TableBuilder(
|
|
117
222
|
this._state.name,
|
package/src/types.ts
CHANGED
|
@@ -9,6 +9,8 @@ export type BuildStorageColumn<Nullable extends boolean, Type extends string> =
|
|
|
9
9
|
readonly nativeType: string;
|
|
10
10
|
readonly codecId: Type;
|
|
11
11
|
readonly nullable: Nullable;
|
|
12
|
+
readonly typeParams?: Record<string, unknown>;
|
|
13
|
+
readonly typeRef?: string;
|
|
12
14
|
};
|
|
13
15
|
|
|
14
16
|
export type ExtractColumns<
|
package/dist/builder-state.d.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Column type descriptor containing both codec ID and native type.
|
|
3
|
-
* Used when defining columns with descriptor objects instead of string IDs.
|
|
4
|
-
*
|
|
5
|
-
* For parameterized types (e.g., `vector(1536)`), the `typeParams` field
|
|
6
|
-
* carries codec-owned parameters that affect both TypeScript type generation
|
|
7
|
-
* and native DDL output.
|
|
8
|
-
*/
|
|
9
|
-
export type ColumnTypeDescriptor = {
|
|
10
|
-
readonly codecId: string;
|
|
11
|
-
readonly nativeType: string;
|
|
12
|
-
readonly typeParams?: Record<string, unknown>;
|
|
13
|
-
};
|
|
14
|
-
export interface ColumnBuilderState<Name extends string, Nullable extends boolean, Type extends string> {
|
|
15
|
-
readonly name: Name;
|
|
16
|
-
readonly nullable: Nullable;
|
|
17
|
-
readonly type: Type;
|
|
18
|
-
readonly nativeType: string;
|
|
19
|
-
readonly typeParams?: Record<string, unknown>;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Unique constraint definition for table builder.
|
|
23
|
-
*/
|
|
24
|
-
export interface UniqueConstraintDef {
|
|
25
|
-
readonly columns: readonly string[];
|
|
26
|
-
readonly name?: string;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Index definition for table builder.
|
|
30
|
-
*/
|
|
31
|
-
export interface IndexDef {
|
|
32
|
-
readonly columns: readonly string[];
|
|
33
|
-
readonly name?: string;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Foreign key definition for table builder.
|
|
37
|
-
*/
|
|
38
|
-
export interface ForeignKeyDef {
|
|
39
|
-
readonly columns: readonly string[];
|
|
40
|
-
readonly references: {
|
|
41
|
-
readonly table: string;
|
|
42
|
-
readonly columns: readonly string[];
|
|
43
|
-
};
|
|
44
|
-
readonly name?: string;
|
|
45
|
-
}
|
|
46
|
-
export interface TableBuilderState<Name extends string, Columns extends Record<string, ColumnBuilderState<string, boolean, string>>, PrimaryKey extends readonly string[] | undefined> {
|
|
47
|
-
readonly name: Name;
|
|
48
|
-
readonly columns: Columns;
|
|
49
|
-
readonly primaryKey?: PrimaryKey;
|
|
50
|
-
readonly primaryKeyName?: string;
|
|
51
|
-
readonly uniques: readonly UniqueConstraintDef[];
|
|
52
|
-
readonly indexes: readonly IndexDef[];
|
|
53
|
-
readonly foreignKeys: readonly ForeignKeyDef[];
|
|
54
|
-
}
|
|
55
|
-
export type RelationDefinition = {
|
|
56
|
-
readonly to: string;
|
|
57
|
-
readonly cardinality: '1:1' | '1:N' | 'N:1' | 'N:M';
|
|
58
|
-
readonly on: {
|
|
59
|
-
readonly parentCols: readonly string[];
|
|
60
|
-
readonly childCols: readonly string[];
|
|
61
|
-
};
|
|
62
|
-
readonly through?: {
|
|
63
|
-
readonly table: string;
|
|
64
|
-
readonly parentCols: readonly string[];
|
|
65
|
-
readonly childCols: readonly string[];
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
export interface ModelBuilderState<Name extends string, Table extends string, Fields extends Record<string, string>, Relations extends Record<string, RelationDefinition>> {
|
|
69
|
-
readonly name: Name;
|
|
70
|
-
readonly table: Table;
|
|
71
|
-
readonly fields: Fields;
|
|
72
|
-
readonly relations: Relations;
|
|
73
|
-
}
|
|
74
|
-
export interface ContractBuilderState<Target extends string | undefined = string | undefined, Tables extends Record<string, TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>> = Record<never, TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>>, Models extends Record<string, ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>> = Record<never, ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>>, CoreHash extends string | undefined = string | undefined, ExtensionPacks extends Record<string, unknown> | undefined = undefined, Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined> {
|
|
75
|
-
readonly target?: Target;
|
|
76
|
-
readonly tables: Tables;
|
|
77
|
-
readonly models: Models;
|
|
78
|
-
readonly coreHash?: CoreHash;
|
|
79
|
-
readonly extensionPacks?: ExtensionPacks;
|
|
80
|
-
readonly capabilities?: Capabilities;
|
|
81
|
-
/**
|
|
82
|
-
* Array of extension pack namespace identifiers (e.g., ['pgvector', 'postgis']).
|
|
83
|
-
* Populated when extension packs are registered during contract building.
|
|
84
|
-
* Used to track which extension packs are included in the contract.
|
|
85
|
-
* Can be undefined or empty if no extension packs are registered.
|
|
86
|
-
* Namespace format matches the extension pack ID (e.g., 'pgvector', not 'pgvector@1.0.0').
|
|
87
|
-
*/
|
|
88
|
-
readonly extensionNamespaces?: readonly string[];
|
|
89
|
-
}
|
|
90
|
-
export interface ColumnBuilder<Name extends string, Nullable extends boolean, Type extends string> {
|
|
91
|
-
nullable<Value extends boolean>(value?: Value): ColumnBuilder<Name, Value, Type>;
|
|
92
|
-
type<Id extends string>(id: Id): ColumnBuilder<Name, Nullable, Id>;
|
|
93
|
-
build(): ColumnBuilderState<Name, Nullable, Type>;
|
|
94
|
-
}
|
|
95
|
-
//# sourceMappingURL=builder-state.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"builder-state.d.ts","sourceRoot":"","sources":["../src/builder-state.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,WAAW,kBAAkB,CACjC,IAAI,SAAS,MAAM,EACnB,QAAQ,SAAS,OAAO,EACxB,IAAI,SAAS,MAAM;IAEnB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/C;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,IAAI,CAA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B,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;CACnD"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { TargetPackRef } from '@prisma-next/contract/framework-components';
|
|
2
|
-
import type { ColumnBuilderState, ContractBuilderState, ModelBuilderState, RelationDefinition, TableBuilderState } from './builder-state';
|
|
3
|
-
import { ModelBuilder } from './model-builder';
|
|
4
|
-
import { TableBuilder } from './table-builder';
|
|
5
|
-
export declare class ContractBuilder<Target extends string | undefined = undefined, Tables extends Record<string, TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>> = Record<never, never>, Models extends Record<string, ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>> = Record<never, never>, CoreHash extends string | undefined = undefined, ExtensionPacks extends Record<string, unknown> | undefined = undefined, Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined> {
|
|
6
|
-
protected readonly state: ContractBuilderState<Target, Tables, Models, CoreHash, ExtensionPacks, Capabilities>;
|
|
7
|
-
constructor(state?: ContractBuilderState<Target, Tables, Models, CoreHash, ExtensionPacks, Capabilities>);
|
|
8
|
-
target<T extends string>(packRef: TargetPackRef<string, T>): ContractBuilder<T, Tables, Models, CoreHash, ExtensionPacks, Capabilities>;
|
|
9
|
-
capabilities<C extends Record<string, Record<string, boolean>>>(capabilities: C): ContractBuilder<Target, Tables, Models, CoreHash, ExtensionPacks, C>;
|
|
10
|
-
table<TableName extends string, T extends TableBuilder<TableName, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>>(name: TableName, callback: (t: TableBuilder<TableName>) => T | undefined): ContractBuilder<Target, Tables & Record<TableName, ReturnType<T['build']>>, Models, CoreHash, ExtensionPacks, Capabilities>;
|
|
11
|
-
model<ModelName extends string, TableName extends string, M extends ModelBuilder<ModelName, TableName, Record<string, string>, Record<string, RelationDefinition>>>(name: ModelName, table: TableName, callback: (m: ModelBuilder<ModelName, TableName, Record<string, string>, Record<never, never>>) => M | undefined): ContractBuilder<Target, Tables, Models & Record<ModelName, ReturnType<M['build']>>, CoreHash, ExtensionPacks, Capabilities>;
|
|
12
|
-
coreHash<H extends string>(hash: H): ContractBuilder<Target, Tables, Models, H, ExtensionPacks, Capabilities>;
|
|
13
|
-
}
|
|
14
|
-
export declare function defineContract(): ContractBuilder;
|
|
15
|
-
//# sourceMappingURL=contract-builder.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"contract-builder.d.ts","sourceRoot":"","sources":["../src/contract-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAe,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE5D,qBAAa,eAAe,CAC1B,MAAM,SAAS,MAAM,GAAG,SAAS,GAAG,SAAS,EAC7C,MAAM,SAAS,MAAM,CACnB,MAAM,EACN,iBAAiB,CACf,MAAM,EACN,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,EAC3D,SAAS,MAAM,EAAE,GAAG,SAAS,CAC9B,CACF,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EACxB,MAAM,SAAS,MAAM,CACnB,MAAM,EACN,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAC9F,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EACxB,QAAQ,SAAS,MAAM,GAAG,SAAS,GAAG,SAAS,EAC/C,cAAc,SAAS,MAAM,CAAC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,EACN,QAAQ,EACR,cAAc,EACd,YAAY,CACb;IAoBD,KAAK,CACH,SAAS,SAAS,MAAM,EACxB,SAAS,SAAS,MAAM,EACxB,CAAC,SAAS,YAAY,CACpB,SAAS,EACT,SAAS,EACT,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACtB,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CACnC,EAED,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,SAAS,EAChB,QAAQ,EAAE,CACR,CAAC,EAAE,YAAY,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,KAChF,CAAC,GAAG,SAAS,GACjB,eAAe,CAChB,MAAM,EACN,MAAM,EACN,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAClD,QAAQ,EACR,cAAc,EACd,YAAY,CACb;IAoBD,QAAQ,CAAC,CAAC,SAAS,MAAM,EACvB,IAAI,EAAE,CAAC,GACN,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,cAAc,EAAE,YAAY,CAAC;CAM5E;AAED,wBAAgB,cAAc,IAAI,eAAe,CAEhD"}
|
package/dist/index.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export type { ColumnBuilder, ColumnBuilderState, ColumnTypeDescriptor, ContractBuilderState, ForeignKeyDef, IndexDef, ModelBuilderState, RelationDefinition, TableBuilderState, UniqueConstraintDef, } from './builder-state';
|
|
2
|
-
export { ContractBuilder, defineContract } from './contract-builder';
|
|
3
|
-
export { ModelBuilder } from './model-builder';
|
|
4
|
-
export { createTable, TableBuilder } from './table-builder';
|
|
5
|
-
export type { BuildModelFields, BuildModels, BuildRelations, BuildStorage, BuildStorageColumn, BuildStorageTables, ExtractColumns, ExtractModelFields, ExtractModelRelations, ExtractPrimaryKey, Mutable, } from './types';
|
|
6
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,EACb,QAAQ,EACR,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE5D,YAAY,EACV,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,OAAO,GACR,MAAM,SAAS,CAAC"}
|