@prisma-next/sql-contract-ts 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 +206 -73
- package/dist/config-types.d.mts +8 -0
- package/dist/config-types.d.mts.map +1 -0
- package/dist/config-types.mjs +14 -0
- package/dist/config-types.mjs.map +1 -0
- package/dist/contract-builder.d.mts +769 -0
- package/dist/contract-builder.d.mts.map +1 -0
- package/dist/contract-builder.mjs +1288 -0
- package/dist/contract-builder.mjs.map +1 -0
- package/package.json +20 -17
- package/schemas/data-contract-sql-v1.json +189 -23
- package/src/authoring-helper-runtime.ts +139 -0
- package/src/authoring-type-utils.ts +168 -0
- package/src/build-contract.ts +463 -0
- package/src/composed-authoring-helpers.ts +256 -0
- package/src/config-types.ts +11 -0
- package/src/contract-builder.ts +232 -551
- package/src/contract-definition.ts +103 -0
- package/src/contract-dsl.ts +1492 -0
- package/src/contract-lowering.ts +703 -0
- package/src/contract-types.ts +534 -0
- package/src/contract-warnings.ts +242 -0
- package/src/exports/config-types.ts +2 -0
- package/src/exports/contract-builder.ts +23 -2
- package/dist/chunk-HTNUNGA2.js +0 -346
- package/dist/chunk-HTNUNGA2.js.map +0 -1
- package/dist/contract-builder.d.ts +0 -101
- package/dist/contract-builder.d.ts.map +0 -1
- package/dist/contract.d.ts +0 -50
- package/dist/contract.d.ts.map +0 -1
- package/dist/exports/contract-builder.d.ts +0 -3
- package/dist/exports/contract-builder.d.ts.map +0 -1
- package/dist/exports/contract-builder.js +0 -231
- package/dist/exports/contract-builder.js.map +0 -1
- package/dist/exports/contract.d.ts +0 -2
- package/dist/exports/contract.d.ts.map +0 -1
- package/dist/exports/contract.js +0 -9
- package/dist/exports/contract.js.map +0 -1
- package/src/contract.ts +0 -582
- package/src/exports/contract.ts +0 -1
|
@@ -0,0 +1,769 @@
|
|
|
1
|
+
import { ColumnDefault, ColumnDefaultLiteralInputValue, Contract, ContractRelation, ExecutionMutationDefaultValue, StorageHashBase } from "@prisma-next/contract/types";
|
|
2
|
+
import { ContractWithTypeMaps, Index as Index$1, ReferentialAction, SqlStorage, StorageTypeInstance, TypeMaps } from "@prisma-next/sql-contract/types";
|
|
3
|
+
import { AuthoringArgumentDescriptor, AuthoringFieldNamespace, AuthoringFieldPresetDescriptor, AuthoringTypeConstructorDescriptor, AuthoringTypeNamespace } from "@prisma-next/framework-components/authoring";
|
|
4
|
+
import { ColumnTypeDescriptor, ForeignKeyDefaultsState } from "@prisma-next/contract-authoring";
|
|
5
|
+
import { CodecLookup } from "@prisma-next/framework-components/codec";
|
|
6
|
+
import { ExtensionPackRef, FamilyPackRef, TargetPackRef } from "@prisma-next/framework-components/components";
|
|
7
|
+
|
|
8
|
+
//#region src/contract-dsl.d.ts
|
|
9
|
+
type NamingStrategy = 'identity' | 'snake_case';
|
|
10
|
+
type NamingConfig = {
|
|
11
|
+
readonly tables?: NamingStrategy;
|
|
12
|
+
readonly columns?: NamingStrategy;
|
|
13
|
+
};
|
|
14
|
+
type NamedStorageTypeRef = string | StorageTypeInstance;
|
|
15
|
+
type NamedConstraintNameSpec<Name$1 extends string = string> = {
|
|
16
|
+
readonly name: Name$1;
|
|
17
|
+
};
|
|
18
|
+
type ScalarFieldState<CodecId$1 extends string = string, TypeRef$1 extends NamedStorageTypeRef | undefined = undefined, Nullable$1 extends boolean = boolean, ColumnName extends string | undefined = string | undefined, IdSpec$1 extends NamedConstraintSpec | undefined = undefined, UniqueSpec$1 extends NamedConstraintSpec | undefined = undefined> = {
|
|
19
|
+
readonly kind: 'scalar';
|
|
20
|
+
readonly descriptor?: (ColumnTypeDescriptor & {
|
|
21
|
+
readonly codecId: CodecId$1;
|
|
22
|
+
}) | undefined;
|
|
23
|
+
readonly typeRef?: TypeRef$1 | undefined;
|
|
24
|
+
readonly nullable: Nullable$1;
|
|
25
|
+
readonly columnName?: ColumnName | undefined;
|
|
26
|
+
readonly default?: ColumnDefault | undefined;
|
|
27
|
+
readonly executionDefault?: ExecutionMutationDefaultValue | undefined;
|
|
28
|
+
} & (IdSpec$1 extends NamedConstraintSpec ? {
|
|
29
|
+
readonly id: IdSpec$1;
|
|
30
|
+
} : {
|
|
31
|
+
readonly id?: undefined;
|
|
32
|
+
}) & (UniqueSpec$1 extends NamedConstraintSpec ? {
|
|
33
|
+
readonly unique: UniqueSpec$1;
|
|
34
|
+
} : {
|
|
35
|
+
readonly unique?: undefined;
|
|
36
|
+
});
|
|
37
|
+
type AnyScalarFieldState = {
|
|
38
|
+
readonly kind: 'scalar';
|
|
39
|
+
readonly descriptor?: (ColumnTypeDescriptor & {
|
|
40
|
+
readonly codecId: string;
|
|
41
|
+
}) | undefined;
|
|
42
|
+
readonly typeRef?: NamedStorageTypeRef | undefined;
|
|
43
|
+
readonly nullable: boolean;
|
|
44
|
+
readonly columnName?: string | undefined;
|
|
45
|
+
readonly default?: ColumnDefault | undefined;
|
|
46
|
+
readonly executionDefault?: ExecutionMutationDefaultValue | undefined;
|
|
47
|
+
readonly id?: NamedConstraintSpec | undefined;
|
|
48
|
+
readonly unique?: NamedConstraintSpec | undefined;
|
|
49
|
+
};
|
|
50
|
+
type HasNamedConstraintId<State extends AnyScalarFieldState> = State extends ScalarFieldState<string, NamedStorageTypeRef | undefined, boolean, string | undefined, infer IdSpec, NamedConstraintSpec | undefined> ? IdSpec extends NamedConstraintSpec ? true : false : false;
|
|
51
|
+
type HasNamedConstraintUnique<State extends AnyScalarFieldState> = State extends ScalarFieldState<string, NamedStorageTypeRef | undefined, boolean, string | undefined, NamedConstraintSpec | undefined, infer UniqueSpec> ? UniqueSpec extends NamedConstraintSpec ? true : false : false;
|
|
52
|
+
type FieldSqlSpecForState<State extends AnyScalarFieldState> = {
|
|
53
|
+
readonly column?: string;
|
|
54
|
+
} & (HasNamedConstraintId<State> extends true ? {
|
|
55
|
+
readonly id?: NamedConstraintNameSpec;
|
|
56
|
+
} : Record<never, never>) & (HasNamedConstraintUnique<State> extends true ? {
|
|
57
|
+
readonly unique?: NamedConstraintNameSpec;
|
|
58
|
+
} : Record<never, never>);
|
|
59
|
+
type ApplyFieldSqlSpec<State extends AnyScalarFieldState, Spec extends FieldSqlSpecForState<State>> = State extends ScalarFieldState<infer CodecId, infer TypeRef, infer Nullable, infer ColumnName, infer IdSpec, infer UniqueSpec> ? ScalarFieldState<CodecId, TypeRef, Nullable, Spec extends {
|
|
60
|
+
readonly column: infer NextColumn extends string;
|
|
61
|
+
} ? NextColumn : ColumnName, Spec extends {
|
|
62
|
+
readonly id: {
|
|
63
|
+
readonly name: infer IdName extends string;
|
|
64
|
+
};
|
|
65
|
+
} ? IdSpec extends NamedConstraintSpec ? NamedConstraintSpec<IdName> : IdSpec : IdSpec, Spec extends {
|
|
66
|
+
readonly unique: {
|
|
67
|
+
readonly name: infer UniqueName extends string;
|
|
68
|
+
};
|
|
69
|
+
} ? UniqueSpec extends NamedConstraintSpec ? NamedConstraintSpec<UniqueName> : UniqueSpec : UniqueSpec> : never;
|
|
70
|
+
type GeneratedFieldSpec = {
|
|
71
|
+
readonly type: ColumnTypeDescriptor;
|
|
72
|
+
readonly typeParams?: Record<string, unknown>;
|
|
73
|
+
readonly generated: ExecutionMutationDefaultValue;
|
|
74
|
+
};
|
|
75
|
+
declare class ScalarFieldBuilder<State extends AnyScalarFieldState = AnyScalarFieldState> {
|
|
76
|
+
private readonly state;
|
|
77
|
+
readonly __state: State;
|
|
78
|
+
constructor(state: State);
|
|
79
|
+
optional(): ScalarFieldBuilder<State extends ScalarFieldState<infer CodecId, infer TypeRef, boolean, infer ColumnName, infer IdSpec, infer UniqueSpec> ? ScalarFieldState<CodecId, TypeRef, true, ColumnName, IdSpec, UniqueSpec> : never>;
|
|
80
|
+
column<ColumnName extends string>(name: ColumnName): ScalarFieldBuilder<State extends ScalarFieldState<infer CodecId, infer TypeRef, infer Nullable, string | undefined, infer IdSpec, infer UniqueSpec> ? ScalarFieldState<CodecId, TypeRef, Nullable, ColumnName, IdSpec, UniqueSpec> : never>;
|
|
81
|
+
default(value: ColumnDefaultLiteralInputValue | ColumnDefault): ScalarFieldBuilder<State>;
|
|
82
|
+
defaultSql(expression: string): ScalarFieldBuilder<State>;
|
|
83
|
+
id<const Name$1 extends string | undefined = undefined>(options?: NamedConstraintSpec<Name$1>): ScalarFieldBuilder<State extends ScalarFieldState<infer CodecId, infer TypeRef, infer Nullable, infer ColumnName, NamedConstraintSpec | undefined, infer UniqueSpec> ? ScalarFieldState<CodecId, TypeRef, Nullable, ColumnName, NamedConstraintSpec<Name$1>, UniqueSpec> : never>;
|
|
84
|
+
unique<const Name$1 extends string | undefined = undefined>(options?: NamedConstraintSpec<Name$1>): ScalarFieldBuilder<State extends ScalarFieldState<infer CodecId, infer TypeRef, infer Nullable, infer ColumnName, infer IdSpec, NamedConstraintSpec | undefined> ? ScalarFieldState<CodecId, TypeRef, Nullable, ColumnName, IdSpec, NamedConstraintSpec<Name$1>> : never>;
|
|
85
|
+
sql<const Spec extends FieldSqlSpecForState<State>>(spec: Spec): ScalarFieldBuilder<ApplyFieldSqlSpec<State, Spec>>;
|
|
86
|
+
build(): State;
|
|
87
|
+
}
|
|
88
|
+
declare function columnField<Descriptor extends ColumnTypeDescriptor>(descriptor: Descriptor): ScalarFieldBuilder<ScalarFieldState<Descriptor['codecId'], undefined, false, undefined>>;
|
|
89
|
+
declare function generatedField<Descriptor extends ColumnTypeDescriptor>(spec: GeneratedFieldSpec & {
|
|
90
|
+
readonly type: Descriptor;
|
|
91
|
+
}): ScalarFieldBuilder<ScalarFieldState<Descriptor['codecId'], undefined, false, undefined>>;
|
|
92
|
+
declare function namedTypeField<TypeRef$1 extends string>(typeRef: TypeRef$1): ScalarFieldBuilder<ScalarFieldState<string, TypeRef$1, false, undefined>>;
|
|
93
|
+
declare function namedTypeField<TypeRef$1 extends StorageTypeInstance>(typeRef: TypeRef$1): ScalarFieldBuilder<ScalarFieldState<TypeRef$1['codecId'], TypeRef$1, false, undefined>>;
|
|
94
|
+
type RelationModelRefSource = 'string' | 'token' | 'lazyToken';
|
|
95
|
+
type TargetFieldRefSource = 'string' | 'token';
|
|
96
|
+
type EagerRelationModelName<ModelName$1 extends string = string, Source extends Exclude<RelationModelRefSource, 'lazyToken'> = Exclude<RelationModelRefSource, 'lazyToken'>> = {
|
|
97
|
+
readonly kind: 'relationModelName';
|
|
98
|
+
readonly source: Source;
|
|
99
|
+
readonly modelName: ModelName$1;
|
|
100
|
+
};
|
|
101
|
+
type LazyRelationModelName<ModelName$1 extends string = string> = {
|
|
102
|
+
readonly kind: 'lazyRelationModelName';
|
|
103
|
+
readonly source: 'lazyToken';
|
|
104
|
+
readonly resolve: () => ModelName$1;
|
|
105
|
+
};
|
|
106
|
+
type RelationModelSource<ModelName$1 extends string = string> = EagerRelationModelName<ModelName$1> | LazyRelationModelName<ModelName$1>;
|
|
107
|
+
type BelongsToRelation<ToModel$1 extends string = string, FromField$1 extends string | readonly string[] = string | readonly string[], ToField$1 extends string | readonly string[] = string | readonly string[], SqlSpec extends BelongsToRelationSqlSpec | undefined = undefined> = {
|
|
108
|
+
readonly kind: 'belongsTo';
|
|
109
|
+
readonly toModel: RelationModelSource<ToModel$1>;
|
|
110
|
+
readonly from: FromField$1;
|
|
111
|
+
readonly to: ToField$1;
|
|
112
|
+
readonly sql?: SqlSpec;
|
|
113
|
+
};
|
|
114
|
+
type HasManyRelation<ToModel$1 extends string = string, ByField extends string | readonly string[] = string | readonly string[]> = {
|
|
115
|
+
readonly kind: 'hasMany';
|
|
116
|
+
readonly toModel: RelationModelSource<ToModel$1>;
|
|
117
|
+
readonly by: ByField;
|
|
118
|
+
};
|
|
119
|
+
type HasOneRelation<ToModel$1 extends string = string, ByField extends string | readonly string[] = string | readonly string[]> = {
|
|
120
|
+
readonly kind: 'hasOne';
|
|
121
|
+
readonly toModel: RelationModelSource<ToModel$1>;
|
|
122
|
+
readonly by: ByField;
|
|
123
|
+
};
|
|
124
|
+
type ManyToManyRelation<ToModel$1 extends string = string, ThroughModel extends string = string, FromField$1 extends string | readonly string[] = string | readonly string[], ToField$1 extends string | readonly string[] = string | readonly string[]> = {
|
|
125
|
+
readonly kind: 'manyToMany';
|
|
126
|
+
readonly toModel: RelationModelSource<ToModel$1>;
|
|
127
|
+
readonly through: RelationModelSource<ThroughModel>;
|
|
128
|
+
readonly from: FromField$1;
|
|
129
|
+
readonly to: ToField$1;
|
|
130
|
+
};
|
|
131
|
+
type RelationState = BelongsToRelation<string, string | readonly string[], string | readonly string[], BelongsToRelationSqlSpec | undefined> | HasManyRelation | HasOneRelation | ManyToManyRelation;
|
|
132
|
+
type AnyRelationState = RelationState;
|
|
133
|
+
type AnyRelationBuilder = RelationBuilder<AnyRelationState>;
|
|
134
|
+
type ApplyBelongsToRelationSqlSpec<State extends RelationState, SqlSpec extends BelongsToRelationSqlSpec> = State extends BelongsToRelation<infer ToModel, infer FromField, infer ToField, BelongsToRelationSqlSpec | undefined> ? BelongsToRelation<ToModel, FromField, ToField, SqlSpec> : never;
|
|
135
|
+
declare class RelationBuilder<State extends RelationState = AnyRelationState> {
|
|
136
|
+
private readonly state;
|
|
137
|
+
readonly __state: State;
|
|
138
|
+
constructor(state: State);
|
|
139
|
+
sql<const SqlSpec extends BelongsToRelationSqlSpec>(this: State extends BelongsToRelation<string, string | readonly string[], string | readonly string[], BelongsToRelationSqlSpec | undefined> ? RelationBuilder<State> : never, spec: SqlSpec): RelationBuilder<ApplyBelongsToRelationSqlSpec<State, SqlSpec>>;
|
|
140
|
+
build(): State;
|
|
141
|
+
}
|
|
142
|
+
type ColumnRef<FieldName$1 extends string = string> = {
|
|
143
|
+
readonly kind: 'columnRef';
|
|
144
|
+
readonly fieldName: FieldName$1;
|
|
145
|
+
};
|
|
146
|
+
type TargetFieldRef<ModelName$1 extends string = string, FieldName$1 extends string = string, Source extends TargetFieldRefSource = TargetFieldRefSource> = {
|
|
147
|
+
readonly kind: 'targetFieldRef';
|
|
148
|
+
readonly source: Source;
|
|
149
|
+
readonly modelName: ModelName$1;
|
|
150
|
+
readonly fieldName: FieldName$1;
|
|
151
|
+
};
|
|
152
|
+
type ModelTokenRefs<ModelName$1 extends string, Fields$1 extends Record<string, ScalarFieldBuilder>> = { readonly [K in keyof Fields$1]: TargetFieldRef<ModelName$1, K & string> };
|
|
153
|
+
type ConstraintOptions<Name$1 extends string | undefined = string | undefined> = {
|
|
154
|
+
readonly name?: Name$1;
|
|
155
|
+
};
|
|
156
|
+
type IndexOptions<Name$1 extends string | undefined = string | undefined> = ConstraintOptions<Name$1> & {
|
|
157
|
+
readonly using?: string;
|
|
158
|
+
readonly config?: Record<string, unknown>;
|
|
159
|
+
};
|
|
160
|
+
type ForeignKeyOptions<Name$1 extends string | undefined = string | undefined> = ConstraintOptions<Name$1> & {
|
|
161
|
+
readonly onDelete?: 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';
|
|
162
|
+
readonly onUpdate?: 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';
|
|
163
|
+
readonly constraint?: boolean;
|
|
164
|
+
readonly index?: boolean;
|
|
165
|
+
};
|
|
166
|
+
type BelongsToRelationSqlSpec<Name$1 extends string | undefined = string | undefined> = {
|
|
167
|
+
readonly fk?: ForeignKeyOptions<Name$1>;
|
|
168
|
+
};
|
|
169
|
+
type IdConstraint<FieldNames extends readonly string[] = readonly string[], Name$1 extends string | undefined = string | undefined> = {
|
|
170
|
+
readonly kind: 'id';
|
|
171
|
+
readonly fields: FieldNames;
|
|
172
|
+
readonly name?: Name$1;
|
|
173
|
+
};
|
|
174
|
+
type UniqueConstraint<FieldNames extends readonly string[] = readonly string[]> = {
|
|
175
|
+
readonly kind: 'unique';
|
|
176
|
+
readonly fields: FieldNames;
|
|
177
|
+
readonly name?: string;
|
|
178
|
+
};
|
|
179
|
+
type IndexConstraint<FieldNames extends readonly string[] = readonly string[], Name$1 extends string | undefined = string | undefined> = {
|
|
180
|
+
readonly kind: 'index';
|
|
181
|
+
readonly fields: FieldNames;
|
|
182
|
+
readonly name?: Name$1;
|
|
183
|
+
readonly using?: string;
|
|
184
|
+
readonly config?: Record<string, unknown>;
|
|
185
|
+
};
|
|
186
|
+
type ForeignKeyConstraint<SourceFieldNames extends readonly string[] = readonly string[], TargetModelName extends string = string, TargetFieldNames extends readonly string[] = readonly string[], Name$1 extends string | undefined = string | undefined> = {
|
|
187
|
+
readonly kind: 'fk';
|
|
188
|
+
readonly fields: SourceFieldNames;
|
|
189
|
+
readonly targetModel: TargetModelName;
|
|
190
|
+
readonly targetFields: TargetFieldNames;
|
|
191
|
+
readonly targetSource?: TargetFieldRefSource;
|
|
192
|
+
readonly name?: Name$1;
|
|
193
|
+
readonly onDelete?: 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';
|
|
194
|
+
readonly onUpdate?: 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';
|
|
195
|
+
readonly constraint?: boolean;
|
|
196
|
+
readonly index?: boolean;
|
|
197
|
+
};
|
|
198
|
+
declare function createConstraintsDsl(): {
|
|
199
|
+
ref: <ModelName$1 extends string, FieldName$1 extends string>(modelName: ModelName$1, fieldName: FieldName$1) => TargetFieldRef<ModelName$1, FieldName$1>;
|
|
200
|
+
id: {
|
|
201
|
+
<FieldName$1 extends string, Name$1 extends string | undefined = undefined>(field: ColumnRef<FieldName$1>, options?: NamedConstraintSpec<Name$1>): IdConstraint<readonly [FieldName$1], Name$1>;
|
|
202
|
+
<FieldNames extends readonly string[], Name$1 extends string | undefined = undefined>(fields: { readonly [K in keyof FieldNames]: ColumnRef<FieldNames[K] & string> }, options?: NamedConstraintSpec<Name$1>): IdConstraint<FieldNames, Name$1>;
|
|
203
|
+
};
|
|
204
|
+
unique: {
|
|
205
|
+
<FieldName$1 extends string>(field: ColumnRef<FieldName$1>, options?: ConstraintOptions): UniqueConstraint<readonly [FieldName$1]>;
|
|
206
|
+
<FieldNames extends readonly string[]>(fields: { readonly [K in keyof FieldNames]: ColumnRef<FieldNames[K] & string> }, options?: ConstraintOptions): UniqueConstraint<FieldNames>;
|
|
207
|
+
};
|
|
208
|
+
index: {
|
|
209
|
+
<FieldName$1 extends string, Name$1 extends string | undefined = undefined>(field: ColumnRef<FieldName$1>, options?: IndexOptions<Name$1>): IndexConstraint<readonly [FieldName$1], Name$1>;
|
|
210
|
+
<FieldNames extends readonly string[], Name$1 extends string | undefined = undefined>(fields: { readonly [K in keyof FieldNames]: ColumnRef<FieldNames[K] & string> }, options?: IndexOptions<Name$1>): IndexConstraint<FieldNames, Name$1>;
|
|
211
|
+
};
|
|
212
|
+
foreignKey: {
|
|
213
|
+
<SourceFieldName extends string, TargetModelName extends string, TargetFieldName extends string, Name$1 extends string | undefined = undefined>(field: ColumnRef<SourceFieldName>, target: TargetFieldRef<TargetModelName, TargetFieldName>, options?: ForeignKeyOptions<Name$1>): ForeignKeyConstraint<readonly [SourceFieldName], TargetModelName, readonly [TargetFieldName], Name$1>;
|
|
214
|
+
<SourceFieldNames extends readonly string[], TargetModelName extends string, TargetFieldNames extends readonly string[], Name$1 extends string | undefined = undefined>(fields: { readonly [K in keyof SourceFieldNames]: ColumnRef<SourceFieldNames[K] & string> }, target: { readonly [K in keyof TargetFieldNames]: TargetFieldRef<TargetModelName, TargetFieldNames[K] & string> }, options?: ForeignKeyOptions<Name$1>): ForeignKeyConstraint<SourceFieldNames, TargetModelName, TargetFieldNames, Name$1>;
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
type ConstraintsDsl = ReturnType<typeof createConstraintsDsl>;
|
|
218
|
+
type ModelAttributesSpec = {
|
|
219
|
+
readonly id?: IdConstraint;
|
|
220
|
+
readonly uniques?: readonly UniqueConstraint[];
|
|
221
|
+
};
|
|
222
|
+
type SqlStageSpec = {
|
|
223
|
+
readonly table?: string;
|
|
224
|
+
readonly indexes?: readonly IndexConstraint[];
|
|
225
|
+
readonly foreignKeys?: readonly ForeignKeyConstraint[];
|
|
226
|
+
};
|
|
227
|
+
type FieldRefs<Fields$1 extends Record<string, ScalarFieldBuilder>> = { readonly [K in keyof Fields$1]: ColumnRef<K & string> };
|
|
228
|
+
type AttributeContext<Fields$1 extends Record<string, ScalarFieldBuilder>> = {
|
|
229
|
+
readonly fields: FieldRefs<Fields$1>;
|
|
230
|
+
readonly constraints: Pick<ConstraintsDsl, 'id' | 'unique'>;
|
|
231
|
+
};
|
|
232
|
+
type SqlContext<Fields$1 extends Record<string, ScalarFieldBuilder>> = {
|
|
233
|
+
readonly cols: FieldRefs<Fields$1>;
|
|
234
|
+
readonly constraints: Pick<ConstraintsDsl, 'index' | 'foreignKey' | 'ref'>;
|
|
235
|
+
};
|
|
236
|
+
type StageInput<Context, Spec> = Spec | ((context: Context) => Spec);
|
|
237
|
+
type StaticLiteralName<Name$1> = Name$1 extends string ? (string extends Name$1 ? never : Name$1) : never;
|
|
238
|
+
type NamedConstraintLiteralName<Constraint> = Constraint extends {
|
|
239
|
+
readonly name?: infer Name;
|
|
240
|
+
} ? StaticLiteralName<Name> : never;
|
|
241
|
+
type DuplicateLiteralNames<Items extends readonly unknown[], Seen extends string = never, Duplicates extends string = never> = Items extends readonly [infer First, ...infer Rest extends readonly unknown[]] ? NamedConstraintLiteralName<First> extends infer Name extends string ? Name extends Seen ? DuplicateLiteralNames<Rest, Seen, Duplicates | Name> : DuplicateLiteralNames<Rest, Seen | Name, Duplicates> : DuplicateLiteralNames<Rest, Seen, Duplicates> : Duplicates;
|
|
242
|
+
type InlineIdLiteralName<Fields$1 extends Record<string, ScalarFieldBuilder>> = { readonly [FieldName in keyof Fields$1]: FieldStateOf<Fields$1[FieldName]> extends {
|
|
243
|
+
readonly id: {
|
|
244
|
+
readonly name?: infer Name;
|
|
245
|
+
};
|
|
246
|
+
} ? StaticLiteralName<Name> : never }[keyof Fields$1];
|
|
247
|
+
type AttributeIdLiteralName<AttributesSpec extends ModelAttributesSpec | undefined> = AttributesSpec extends {
|
|
248
|
+
readonly id?: {
|
|
249
|
+
readonly name?: infer Name;
|
|
250
|
+
};
|
|
251
|
+
} ? StaticLiteralName<Name> : never;
|
|
252
|
+
type ModelIdLiteralName<Fields$1 extends Record<string, ScalarFieldBuilder>, AttributesSpec extends ModelAttributesSpec | undefined> = [AttributeIdLiteralName<AttributesSpec>] extends [never] ? InlineIdLiteralName<Fields$1> : AttributeIdLiteralName<AttributesSpec>;
|
|
253
|
+
type SqlIndexes<SqlSpec extends SqlStageSpec> = SqlSpec extends {
|
|
254
|
+
readonly indexes?: infer Indexes extends readonly unknown[];
|
|
255
|
+
} ? Indexes : readonly [];
|
|
256
|
+
type SqlForeignKeys<SqlSpec extends SqlStageSpec> = SqlSpec extends {
|
|
257
|
+
readonly foreignKeys?: infer ForeignKeys extends readonly unknown[];
|
|
258
|
+
} ? ForeignKeys : readonly [];
|
|
259
|
+
type SqlNamedObjects<SqlSpec extends SqlStageSpec> = [...SqlIndexes<SqlSpec>, ...SqlForeignKeys<SqlSpec>];
|
|
260
|
+
type ValidateSqlStageSpec<Fields$1 extends Record<string, ScalarFieldBuilder>, AttributesSpec extends ModelAttributesSpec | undefined, SqlSpec extends SqlStageSpec> = [DuplicateLiteralNames<SqlNamedObjects<SqlSpec>>] extends [never] ? [Extract<ModelIdLiteralName<Fields$1, AttributesSpec>, NamedConstraintLiteralName<SqlNamedObjects<SqlSpec>[number]>>] extends [never] ? SqlSpec : never : never;
|
|
261
|
+
type ValidateAttributesStageSpec<Fields$1 extends Record<string, ScalarFieldBuilder>, SqlSpec extends SqlStageSpec | undefined, AttributesSpec extends ModelAttributesSpec> = SqlSpec extends SqlStageSpec ? [Extract<ModelIdLiteralName<Fields$1, AttributesSpec>, NamedConstraintLiteralName<SqlNamedObjects<SqlSpec>[number]>>] extends [never] ? AttributesSpec : never : AttributesSpec;
|
|
262
|
+
declare class ContractModelBuilder<ModelName$1 extends string | undefined, Fields$1 extends Record<string, ScalarFieldBuilder>, Relations extends Record<string, AnyRelationBuilder> = Record<never, never>, AttributesSpec extends ModelAttributesSpec | undefined = undefined, SqlSpec extends SqlStageSpec | undefined = undefined> {
|
|
263
|
+
readonly stageOne: {
|
|
264
|
+
readonly modelName?: ModelName$1;
|
|
265
|
+
readonly fields: Fields$1;
|
|
266
|
+
readonly relations: Relations;
|
|
267
|
+
};
|
|
268
|
+
readonly attributesFactory?: StageInput<AttributeContext<Fields$1>, AttributesSpec> | undefined;
|
|
269
|
+
readonly sqlFactory?: StageInput<SqlContext<Fields$1>, SqlSpec> | undefined;
|
|
270
|
+
readonly __name: ModelName$1;
|
|
271
|
+
readonly __fields: Fields$1;
|
|
272
|
+
readonly __relations: Relations;
|
|
273
|
+
readonly __attributes: AttributesSpec;
|
|
274
|
+
readonly __sql: SqlSpec;
|
|
275
|
+
readonly refs: ModelName$1 extends string ? ModelTokenRefs<ModelName$1, Fields$1> : never;
|
|
276
|
+
constructor(stageOne: {
|
|
277
|
+
readonly modelName?: ModelName$1;
|
|
278
|
+
readonly fields: Fields$1;
|
|
279
|
+
readonly relations: Relations;
|
|
280
|
+
}, attributesFactory?: StageInput<AttributeContext<Fields$1>, AttributesSpec> | undefined, sqlFactory?: StageInput<SqlContext<Fields$1>, SqlSpec> | undefined);
|
|
281
|
+
ref<FieldName$1 extends keyof Fields$1 & string>(this: ModelName$1 extends string ? ContractModelBuilder<ModelName$1, Fields$1, Relations, AttributesSpec, SqlSpec> : never, fieldName: FieldName$1): TargetFieldRef<ModelName$1 & string, FieldName$1>;
|
|
282
|
+
relations<const NextRelations extends Record<string, AnyRelationBuilder>>(relations: NextRelations): ContractModelBuilder<ModelName$1, Fields$1, Relations & NextRelations, AttributesSpec, SqlSpec>;
|
|
283
|
+
attributes<const NextAttributesSpec extends ModelAttributesSpec>(specOrFactory: StageInput<AttributeContext<Fields$1>, ValidateAttributesStageSpec<Fields$1, SqlSpec, NextAttributesSpec>>): ContractModelBuilder<ModelName$1, Fields$1, Relations, NextAttributesSpec, SqlSpec>;
|
|
284
|
+
sql<const NextSqlSpec extends SqlStageSpec>(specOrFactory: StageInput<SqlContext<Fields$1>, NextSqlSpec>): [ValidateSqlStageSpec<Fields$1, AttributesSpec, NextSqlSpec>] extends [never] ? ContractModelBuilder<ModelName$1, Fields$1, Relations, AttributesSpec, never> : ContractModelBuilder<ModelName$1, Fields$1, Relations, AttributesSpec, NextSqlSpec>;
|
|
285
|
+
buildAttributesSpec(): AttributesSpec;
|
|
286
|
+
buildSqlSpec(): SqlSpec;
|
|
287
|
+
}
|
|
288
|
+
type NamedModelTokenShape<ModelName$1 extends string = string, Fields$1 extends Record<string, ScalarFieldBuilder> = Record<string, ScalarFieldBuilder>> = {
|
|
289
|
+
readonly stageOne: {
|
|
290
|
+
readonly modelName?: ModelName$1;
|
|
291
|
+
readonly fields: Fields$1;
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
type AnyNamedModelToken = NamedModelTokenShape<string, Record<string, ScalarFieldBuilder>>;
|
|
295
|
+
type LazyNamedModelToken<Token$1 extends AnyNamedModelToken = AnyNamedModelToken> = () => Token$1;
|
|
296
|
+
type RelationFieldSelection<FieldName$1 extends string> = FieldName$1 | readonly FieldName$1[];
|
|
297
|
+
type RelationModelName<Target> = Target extends NamedModelTokenShape<infer ModelName extends string, Record<string, ScalarFieldBuilder>> ? ModelName : Target extends (() => infer Token) ? RelationModelName<Token> : never;
|
|
298
|
+
type RelationModelFieldNames<Target> = Target extends NamedModelTokenShape<string, infer Fields> ? keyof Fields & string : Target extends (() => infer Token) ? RelationModelFieldNames<Token> : never;
|
|
299
|
+
type ContractInput<Family extends FamilyPackRef<string> = FamilyPackRef<string>, Target extends TargetPackRef<'sql', string> = TargetPackRef<'sql', string>, Types extends Record<string, StorageTypeInstance> = Record<never, never>, Models extends Record<string, ContractModelBuilder<string | undefined, Record<string, ScalarFieldBuilder>, Record<string, AnyRelationBuilder>, ModelAttributesSpec | undefined, SqlStageSpec | undefined>> = Record<never, never>, ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined = undefined, Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined> = {
|
|
300
|
+
readonly family: Family;
|
|
301
|
+
readonly target: Target;
|
|
302
|
+
readonly extensionPacks?: ExtensionPacks;
|
|
303
|
+
readonly naming?: NamingConfig;
|
|
304
|
+
readonly storageHash?: string;
|
|
305
|
+
readonly foreignKeyDefaults?: ForeignKeyDefaultsState;
|
|
306
|
+
readonly capabilities?: Capabilities;
|
|
307
|
+
readonly types?: Types;
|
|
308
|
+
readonly models?: Models;
|
|
309
|
+
readonly codecLookup?: CodecLookup;
|
|
310
|
+
};
|
|
311
|
+
declare function model<const ModelName$1 extends string, Fields$1 extends Record<string, ScalarFieldBuilder>, Relations extends Record<string, AnyRelationBuilder> = Record<never, never>>(modelName: ModelName$1, input: {
|
|
312
|
+
readonly fields: Fields$1;
|
|
313
|
+
readonly relations?: Relations;
|
|
314
|
+
}): ContractModelBuilder<ModelName$1, Fields$1, Relations>;
|
|
315
|
+
declare function model<Fields$1 extends Record<string, ScalarFieldBuilder>, Relations extends Record<string, AnyRelationBuilder> = Record<never, never>>(input: {
|
|
316
|
+
readonly fields: Fields$1;
|
|
317
|
+
readonly relations?: Relations;
|
|
318
|
+
}): ContractModelBuilder<undefined, Fields$1, Relations>;
|
|
319
|
+
declare function belongsTo<Token$1 extends AnyNamedModelToken, FromField$1 extends string | readonly string[], ToField$1 extends RelationFieldSelection<RelationModelFieldNames<Token$1>>>(toModel: Token$1 | LazyNamedModelToken<Token$1>, options: {
|
|
320
|
+
readonly from: FromField$1;
|
|
321
|
+
readonly to: ToField$1;
|
|
322
|
+
}): RelationBuilder<BelongsToRelation<RelationModelName<Token$1>, FromField$1, ToField$1>>;
|
|
323
|
+
declare function belongsTo<ToModel$1 extends string, FromField$1 extends string | readonly string[], ToField$1 extends string | readonly string[]>(toModel: ToModel$1, options: {
|
|
324
|
+
readonly from: FromField$1;
|
|
325
|
+
readonly to: ToField$1;
|
|
326
|
+
}): RelationBuilder<BelongsToRelation<ToModel$1, FromField$1, ToField$1>>;
|
|
327
|
+
declare function hasMany<Token$1 extends AnyNamedModelToken, ByField extends RelationFieldSelection<RelationModelFieldNames<Token$1>>>(toModel: Token$1 | LazyNamedModelToken<Token$1>, options: {
|
|
328
|
+
readonly by: ByField;
|
|
329
|
+
}): RelationBuilder<HasManyRelation<RelationModelName<Token$1>, ByField>>;
|
|
330
|
+
declare function hasMany<ToModel$1 extends string, ByField extends string | readonly string[]>(toModel: ToModel$1, options: {
|
|
331
|
+
readonly by: ByField;
|
|
332
|
+
}): RelationBuilder<HasManyRelation<ToModel$1, ByField>>;
|
|
333
|
+
declare function hasOne<Token$1 extends AnyNamedModelToken, ByField extends RelationFieldSelection<RelationModelFieldNames<Token$1>>>(toModel: Token$1 | LazyNamedModelToken<Token$1>, options: {
|
|
334
|
+
readonly by: ByField;
|
|
335
|
+
}): RelationBuilder<HasOneRelation<RelationModelName<Token$1>, ByField>>;
|
|
336
|
+
declare function hasOne<ToModel$1 extends string, ByField extends string | readonly string[]>(toModel: ToModel$1, options: {
|
|
337
|
+
readonly by: ByField;
|
|
338
|
+
}): RelationBuilder<HasOneRelation<ToModel$1, ByField>>;
|
|
339
|
+
declare function manyToMany<ToToken extends AnyNamedModelToken, ThroughToken extends AnyNamedModelToken, FromField$1 extends RelationFieldSelection<RelationModelFieldNames<ThroughToken>>, ToField$1 extends RelationFieldSelection<RelationModelFieldNames<ThroughToken>>>(toModel: ToToken | LazyNamedModelToken<ToToken>, options: {
|
|
340
|
+
readonly through: ThroughToken | LazyNamedModelToken<ThroughToken>;
|
|
341
|
+
readonly from: FromField$1;
|
|
342
|
+
readonly to: ToField$1;
|
|
343
|
+
}): RelationBuilder<ManyToManyRelation<RelationModelName<ToToken>, RelationModelName<ThroughToken>, FromField$1, ToField$1>>;
|
|
344
|
+
declare function manyToMany<ToModel$1 extends string, ThroughModel extends string, FromField$1 extends string | readonly string[], ToField$1 extends string | readonly string[]>(toModel: ToModel$1, options: {
|
|
345
|
+
readonly through: ThroughModel;
|
|
346
|
+
readonly from: FromField$1;
|
|
347
|
+
readonly to: ToField$1;
|
|
348
|
+
}): RelationBuilder<ManyToManyRelation<ToModel$1, ThroughModel, FromField$1, ToField$1>>;
|
|
349
|
+
declare const rel: {
|
|
350
|
+
belongsTo: typeof belongsTo;
|
|
351
|
+
hasMany: typeof hasMany;
|
|
352
|
+
hasOne: typeof hasOne;
|
|
353
|
+
manyToMany: typeof manyToMany;
|
|
354
|
+
};
|
|
355
|
+
declare const field: {
|
|
356
|
+
column: typeof columnField;
|
|
357
|
+
generated: typeof generatedField;
|
|
358
|
+
namedType: typeof namedTypeField;
|
|
359
|
+
};
|
|
360
|
+
type FieldStateOf<T> = T extends ScalarFieldBuilder<infer State> ? State : never;
|
|
361
|
+
type IdFieldNames<T> = T extends IdConstraint<infer FieldNames> ? FieldNames : readonly string[];
|
|
362
|
+
type AttributeStageIdFieldNames<T> = T extends {
|
|
363
|
+
readonly id?: infer I;
|
|
364
|
+
} ? I extends IdConstraint ? IdFieldNames<I> : undefined : undefined;
|
|
365
|
+
//#endregion
|
|
366
|
+
//#region src/authoring-type-utils.d.ts
|
|
367
|
+
type UnionToIntersection<U> = (U extends unknown ? (value: U) => void : never) extends ((value: infer I) => void) ? I : never;
|
|
368
|
+
type NamedConstraintSpec<Name$1 extends string | undefined = string | undefined> = {
|
|
369
|
+
readonly name?: Name$1;
|
|
370
|
+
};
|
|
371
|
+
type NamedConstraintState<Enabled extends boolean, Name$1 extends string | undefined = undefined> = Enabled extends true ? NamedConstraintSpec<Name$1> : undefined;
|
|
372
|
+
type OptionalObjectArgumentKeys<Properties$1 extends Record<string, AuthoringArgumentDescriptor>> = { readonly [K in keyof Properties$1]: Properties$1[K] extends {
|
|
373
|
+
readonly optional: true;
|
|
374
|
+
} ? K : never }[keyof Properties$1];
|
|
375
|
+
type ObjectArgumentType<Properties$1 extends Record<string, AuthoringArgumentDescriptor>> = { readonly [K in Exclude<keyof Properties$1, OptionalObjectArgumentKeys<Properties$1>>]: ArgTypeFromDescriptor<Properties$1[K]> } & { readonly [K in OptionalObjectArgumentKeys<Properties$1>]?: ArgTypeFromDescriptor<Properties$1[K]> };
|
|
376
|
+
type ArgTypeFromDescriptor<Arg extends AuthoringArgumentDescriptor> = Arg extends {
|
|
377
|
+
readonly kind: 'string';
|
|
378
|
+
} ? string : Arg extends {
|
|
379
|
+
readonly kind: 'number';
|
|
380
|
+
} ? number : Arg extends {
|
|
381
|
+
readonly kind: 'stringArray';
|
|
382
|
+
} ? readonly string[] : Arg extends {
|
|
383
|
+
readonly kind: 'object';
|
|
384
|
+
readonly properties: infer Properties extends Record<string, AuthoringArgumentDescriptor>;
|
|
385
|
+
} ? ObjectArgumentType<Properties> : never;
|
|
386
|
+
type TupleFromArgumentDescriptors<Args$1 extends readonly AuthoringArgumentDescriptor[]> = { readonly [K in keyof Args$1]: Args$1[K] extends AuthoringArgumentDescriptor ? ArgTypeFromDescriptor<Args$1[K]> : never };
|
|
387
|
+
type SupportsNamedConstraintOptions<Descriptor extends AuthoringFieldPresetDescriptor> = Descriptor['output'] extends {
|
|
388
|
+
readonly id: true;
|
|
389
|
+
} ? true : Descriptor['output'] extends {
|
|
390
|
+
readonly unique: true;
|
|
391
|
+
} ? true : false;
|
|
392
|
+
type ResolveTemplateValue<Template, Args$1 extends readonly unknown[]> = Template extends {
|
|
393
|
+
readonly kind: 'arg';
|
|
394
|
+
readonly index: infer Index extends number;
|
|
395
|
+
readonly path?: infer Path extends readonly string[] | undefined;
|
|
396
|
+
readonly default?: infer Default;
|
|
397
|
+
} ? ResolveTemplateArgValue<Args$1[Index], Path, Default, Args$1> : Template extends readonly unknown[] ? { readonly [K in keyof Template]: ResolveTemplateValue<Template[K], Args$1> } : Template extends Record<string, unknown> ? { readonly [K in keyof Template]: ResolveTemplateValue<Template[K], Args$1> } : Template;
|
|
398
|
+
type ResolveTemplatePathValue<Value, Path$1 extends readonly string[] | undefined> = Path$1 extends readonly [infer Segment extends string, ...infer Rest extends readonly string[]] ? Segment extends keyof NonNullable<Value> ? ResolveTemplatePathValue<NonNullable<Value>[Segment], Rest> : never : Value;
|
|
399
|
+
type ResolveTemplateDefaultValue<Value, Default$1, Args$1 extends readonly unknown[]> = Default$1 extends undefined ? Value : [Value] extends [never] ? ResolveTemplateValue<Default$1, Args$1> : undefined extends Value ? Exclude<Value, undefined> | ResolveTemplateValue<Default$1, Args$1> : Value;
|
|
400
|
+
type ResolveTemplateArgValue<Value, Path$1 extends readonly string[] | undefined, Default$1, Args$1 extends readonly unknown[]> = ResolveTemplateDefaultValue<ResolveTemplatePathValue<Value, Path$1>, Default$1, Args$1>;
|
|
401
|
+
type FieldBuilderFromPresetDescriptor<Descriptor extends AuthoringFieldPresetDescriptor, Args$1 extends readonly unknown[] = readonly [], ConstraintName extends string | undefined = undefined> = ScalarFieldBuilder<ScalarFieldState<ResolveTemplateValue<Descriptor['output']['codecId'], Args$1> extends string ? ResolveTemplateValue<Descriptor['output']['codecId'], Args$1> : string, undefined, ResolveTemplateValue<Descriptor['output']['nullable'], Args$1> extends true ? true : false, undefined, NamedConstraintState<ResolveTemplateValue<Descriptor['output']['id'], Args$1> extends true ? true : false, ConstraintName>, NamedConstraintState<ResolveTemplateValue<Descriptor['output']['unique'], Args$1> extends true ? true : false, ConstraintName>>>;
|
|
402
|
+
type FieldHelperFunctionWithoutNamedConstraint<Descriptor extends AuthoringFieldPresetDescriptor> = Descriptor extends {
|
|
403
|
+
readonly args: infer Args extends readonly AuthoringArgumentDescriptor[];
|
|
404
|
+
} ? <const Params extends TupleFromArgumentDescriptors<Args>>(...args: Params) => FieldBuilderFromPresetDescriptor<Descriptor, Params> : () => FieldBuilderFromPresetDescriptor<Descriptor, readonly []>;
|
|
405
|
+
type FieldHelperFunctionWithNamedConstraint<Descriptor extends AuthoringFieldPresetDescriptor> = Descriptor extends {
|
|
406
|
+
readonly args: infer Args extends readonly AuthoringArgumentDescriptor[];
|
|
407
|
+
} ? <const Params extends TupleFromArgumentDescriptors<Args>, const Name$1 extends string | undefined = undefined>(...args: [...params: Params, options?: NamedConstraintSpec<Name$1>]) => FieldBuilderFromPresetDescriptor<Descriptor, Params, Name$1> : <const Name$1 extends string | undefined = undefined>(options?: NamedConstraintSpec<Name$1>) => FieldBuilderFromPresetDescriptor<Descriptor, readonly [], Name$1>;
|
|
408
|
+
type FieldHelperFunction<Descriptor extends AuthoringFieldPresetDescriptor> = SupportsNamedConstraintOptions<Descriptor> extends true ? FieldHelperFunctionWithNamedConstraint<Descriptor> : FieldHelperFunctionWithoutNamedConstraint<Descriptor>;
|
|
409
|
+
type FieldHelpersFromNamespace<Namespace> = { readonly [K in keyof Namespace]: Namespace[K] extends AuthoringFieldPresetDescriptor ? FieldHelperFunction<Namespace[K]> : Namespace[K] extends Record<string, unknown> ? FieldHelpersFromNamespace<Namespace[K]> : never };
|
|
410
|
+
//#endregion
|
|
411
|
+
//#region src/composed-authoring-helpers.d.ts
|
|
412
|
+
type ExtractTypeNamespaceFromPack<Pack> = Pack extends {
|
|
413
|
+
readonly authoring?: {
|
|
414
|
+
readonly type?: infer Namespace extends AuthoringTypeNamespace;
|
|
415
|
+
};
|
|
416
|
+
} ? Namespace : Record<never, never>;
|
|
417
|
+
type ExtractFieldNamespaceFromPack<Pack> = Pack extends {
|
|
418
|
+
readonly authoring?: {
|
|
419
|
+
readonly field?: infer Namespace extends AuthoringFieldNamespace;
|
|
420
|
+
};
|
|
421
|
+
} ? Namespace : Record<never, never>;
|
|
422
|
+
type MergeExtensionTypeNamespaces<ExtensionPacks> = ExtensionPacks extends Record<string, unknown> ? keyof ExtensionPacks extends never ? Record<never, never> : UnionToIntersection<{ [K in keyof ExtensionPacks]: ExtractTypeNamespaceFromPack<ExtensionPacks[K]> }[keyof ExtensionPacks]> : Record<never, never>;
|
|
423
|
+
type MergeExtensionFieldNamespaces<ExtensionPacks> = ExtensionPacks extends Record<string, unknown> ? keyof ExtensionPacks extends never ? Record<never, never> : UnionToIntersection<{ [K in keyof ExtensionPacks]: ExtractFieldNamespaceFromPack<ExtensionPacks[K]> }[keyof ExtensionPacks]> : Record<never, never>;
|
|
424
|
+
type StorageTypeFromDescriptor<Descriptor extends AuthoringTypeConstructorDescriptor, Args$1 extends readonly unknown[]> = {
|
|
425
|
+
readonly codecId: ResolveTemplateValue<Descriptor['output']['codecId'], Args$1>;
|
|
426
|
+
readonly nativeType: ResolveTemplateValue<Descriptor['output']['nativeType'], Args$1>;
|
|
427
|
+
} & (Descriptor['output'] extends {
|
|
428
|
+
readonly typeParams: infer TypeParams extends Record<string, unknown>;
|
|
429
|
+
} ? {
|
|
430
|
+
readonly typeParams: ResolveTemplateValue<TypeParams, Args$1>;
|
|
431
|
+
} : Record<never, never>);
|
|
432
|
+
type TypeHelperFunction<Descriptor extends AuthoringTypeConstructorDescriptor> = Descriptor extends {
|
|
433
|
+
readonly args: infer Args extends readonly AuthoringArgumentDescriptor[];
|
|
434
|
+
} ? <const Params extends TupleFromArgumentDescriptors<Args>>(...args: Params) => StorageTypeFromDescriptor<Descriptor, Params> : () => StorageTypeFromDescriptor<Descriptor, readonly []>;
|
|
435
|
+
type TypeHelpersFromNamespace<Namespace> = { readonly [K in keyof Namespace]: Namespace[K] extends AuthoringTypeConstructorDescriptor ? TypeHelperFunction<Namespace[K]> : Namespace[K] extends Record<string, unknown> ? TypeHelpersFromNamespace<Namespace[K]> : never };
|
|
436
|
+
type CoreFieldHelpers = Pick<typeof field, 'column' | 'generated' | 'namedType'>;
|
|
437
|
+
type ComposedAuthoringHelpers<Family extends FamilyPackRef<string>, Target extends TargetPackRef<'sql', string>, ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined> = {
|
|
438
|
+
readonly field: CoreFieldHelpers & FieldHelpersFromNamespace<ExtractFieldNamespaceFromPack<Family> & ExtractFieldNamespaceFromPack<Target> & MergeExtensionFieldNamespaces<ExtensionPacks>>;
|
|
439
|
+
readonly model: typeof model;
|
|
440
|
+
readonly rel: typeof rel;
|
|
441
|
+
readonly type: TypeHelpersFromNamespace<ExtractTypeNamespaceFromPack<Family> & ExtractTypeNamespaceFromPack<Target> & MergeExtensionTypeNamespaces<ExtensionPacks>>;
|
|
442
|
+
};
|
|
443
|
+
//#endregion
|
|
444
|
+
//#region src/contract-types.d.ts
|
|
445
|
+
type ExtractCodecTypesFromPack<P> = P extends {
|
|
446
|
+
__codecTypes?: infer C;
|
|
447
|
+
} ? C extends Record<string, {
|
|
448
|
+
output: unknown;
|
|
449
|
+
}> ? C : Record<string, never> : Record<string, never>;
|
|
450
|
+
type MergeExtensionCodecTypes<Packs extends Record<string, unknown>> = UnionToIntersection<{ [K in keyof Packs]: ExtractCodecTypesFromPack<Packs[K]> }[keyof Packs]>;
|
|
451
|
+
type MergeExtensionCodecTypesSafe<Packs> = Packs extends Record<string, unknown> ? keyof Packs extends never ? Record<string, never> : MergeExtensionCodecTypes<Packs> : Record<string, never>;
|
|
452
|
+
type DefinitionExtensionPacks<Definition> = Definition extends {
|
|
453
|
+
readonly extensionPacks?: infer Packs extends Record<string, ExtensionPackRef<'sql', string>>;
|
|
454
|
+
} ? Packs : Record<never, never>;
|
|
455
|
+
type DefinitionCapabilities<Definition> = Definition extends {
|
|
456
|
+
readonly capabilities?: infer Capabilities extends Record<string, Record<string, boolean>>;
|
|
457
|
+
} ? Capabilities : undefined;
|
|
458
|
+
type DefinitionTargetId<Definition> = Definition extends {
|
|
459
|
+
readonly target: TargetPackRef<'sql', infer Target>;
|
|
460
|
+
} ? Target : never;
|
|
461
|
+
type Present<T> = Exclude<T, undefined>;
|
|
462
|
+
type CodecTypesFromDefinition<Definition> = ExtractCodecTypesFromPack<Definition extends {
|
|
463
|
+
readonly target: infer Target;
|
|
464
|
+
} ? Target : never> & MergeExtensionCodecTypesSafe<DefinitionExtensionPacks<Definition>>;
|
|
465
|
+
type DefinitionModels<Definition> = Definition extends {
|
|
466
|
+
readonly models?: unknown;
|
|
467
|
+
} ? Present<Definition['models']> extends Record<string, unknown> ? Present<Definition['models']> : Record<never, never> : Record<never, never>;
|
|
468
|
+
type DefinitionTypes<Definition> = Definition extends {
|
|
469
|
+
readonly types?: unknown;
|
|
470
|
+
} ? Present<Definition['types']> extends Record<string, StorageTypeInstance> ? Present<Definition['types']> : Record<never, never> : Record<never, never>;
|
|
471
|
+
type DefinitionTableNaming<Definition> = Definition extends {
|
|
472
|
+
readonly naming?: {
|
|
473
|
+
readonly tables?: infer Strategy extends string;
|
|
474
|
+
};
|
|
475
|
+
} ? Strategy : undefined;
|
|
476
|
+
type DefinitionColumnNaming<Definition> = Definition extends {
|
|
477
|
+
readonly naming?: {
|
|
478
|
+
readonly columns?: infer Strategy extends string;
|
|
479
|
+
};
|
|
480
|
+
} ? Strategy : undefined;
|
|
481
|
+
type FirstChar<S extends string> = S extends `${infer First}${string}` ? First : '';
|
|
482
|
+
type CharKind<C extends string> = C extends '' ? 'end' : C extends Lowercase<C> ? C extends Uppercase<C> ? 'other' : 'lower' : 'upper';
|
|
483
|
+
type ShouldInsertSnakeUnderscore<PrevKind extends 'start' | 'lower' | 'upper' | 'other' | 'end', Current$1 extends string, Next extends string> = CharKind<Current$1> extends 'upper' ? PrevKind extends 'start' ? false : PrevKind extends 'lower' | 'other' ? true : CharKind<Next> extends 'lower' ? true : false : false;
|
|
484
|
+
type SnakeCaseInternal<S extends string, PrevKind extends 'start' | 'lower' | 'upper' | 'other' | 'end' = 'start'> = S extends `${infer Current}${infer Rest}` ? `${ShouldInsertSnakeUnderscore<PrevKind, Current, FirstChar<Rest>> extends true ? '_' : ''}${Lowercase<Current>}${SnakeCaseInternal<Rest, CharKind<Current>>}` : '';
|
|
485
|
+
type SnakeCase<S extends string> = string extends S ? string : SnakeCaseInternal<S>;
|
|
486
|
+
type ApplyNamingType<Name$1 extends string, Strategy extends string | undefined> = string extends Name$1 ? string : Strategy extends 'snake_case' ? SnakeCase<Name$1> : Name$1;
|
|
487
|
+
type ModelNames<Definition> = keyof DefinitionModels<Definition> & string;
|
|
488
|
+
type ModelFields<Definition, ModelName$1 extends ModelNames<Definition>> = DefinitionModels<Definition>[ModelName$1] extends {
|
|
489
|
+
readonly stageOne: {
|
|
490
|
+
readonly fields: Record<string, ScalarFieldBuilder>;
|
|
491
|
+
};
|
|
492
|
+
} ? DefinitionModels<Definition>[ModelName$1]['stageOne']['fields'] : Record<never, never>;
|
|
493
|
+
type ModelFieldNames<Definition, ModelName$1 extends ModelNames<Definition>> = keyof ModelFields<Definition, ModelName$1> & string;
|
|
494
|
+
type StagedModelRelations<Definition, ModelName$1 extends ModelNames<Definition>> = DefinitionModels<Definition>[ModelName$1] extends {
|
|
495
|
+
readonly stageOne: {
|
|
496
|
+
readonly relations: infer R;
|
|
497
|
+
};
|
|
498
|
+
} ? R extends Record<string, unknown> ? R : Record<never, never> : Record<never, never>;
|
|
499
|
+
type StagedModelRelationNames<Definition, ModelName$1 extends ModelNames<Definition>> = keyof StagedModelRelations<Definition, ModelName$1> & string;
|
|
500
|
+
type ModelFieldState<Definition, ModelName$1 extends ModelNames<Definition>, FieldName$1 extends ModelFieldNames<Definition, ModelName$1>> = FieldStateOf<ModelFields<Definition, ModelName$1>[FieldName$1]>;
|
|
501
|
+
type ModelSql<Definition, ModelName$1 extends ModelNames<Definition>> = DefinitionModels<Definition>[ModelName$1] extends {
|
|
502
|
+
readonly __sql: infer SqlSpec;
|
|
503
|
+
} ? SqlSpec : undefined;
|
|
504
|
+
type ModelAttributes<Definition, ModelName$1 extends ModelNames<Definition>> = DefinitionModels<Definition>[ModelName$1] extends {
|
|
505
|
+
readonly __attributes: infer AttributesSpec;
|
|
506
|
+
} ? AttributesSpec : undefined;
|
|
507
|
+
type FieldDescriptorOf<FieldState> = Present<FieldState extends {
|
|
508
|
+
readonly descriptor?: infer Descriptor;
|
|
509
|
+
} ? Descriptor : never>;
|
|
510
|
+
type FieldTypeRefOf<FieldState> = Present<FieldState extends {
|
|
511
|
+
readonly typeRef?: infer TypeRef;
|
|
512
|
+
} ? TypeRef : never>;
|
|
513
|
+
type FieldNullableOf<FieldState> = FieldState extends {
|
|
514
|
+
readonly nullable: infer Nullable extends boolean;
|
|
515
|
+
} ? Nullable : boolean;
|
|
516
|
+
type FieldColumnOverrideOf<FieldState> = Present<FieldState extends {
|
|
517
|
+
readonly columnName?: infer ColumnName;
|
|
518
|
+
} ? ColumnName : never>;
|
|
519
|
+
type FieldInlineIdSpecOf<FieldState> = Present<FieldState extends {
|
|
520
|
+
readonly id?: infer IdSpec;
|
|
521
|
+
} ? IdSpec : never>;
|
|
522
|
+
type DescriptorCodecId<Descriptor> = Descriptor extends {
|
|
523
|
+
readonly codecId: infer CodecId extends string;
|
|
524
|
+
} ? CodecId : string;
|
|
525
|
+
type DescriptorNativeType<Descriptor> = Descriptor extends {
|
|
526
|
+
readonly nativeType: infer NativeType extends string;
|
|
527
|
+
} ? NativeType : string;
|
|
528
|
+
type DescriptorTypeParams<Descriptor> = Descriptor extends {
|
|
529
|
+
readonly typeParams: infer TypeParams extends Record<string, unknown>;
|
|
530
|
+
} ? TypeParams : undefined;
|
|
531
|
+
type DescriptorTypeRef<Descriptor> = Descriptor extends {
|
|
532
|
+
readonly typeRef: infer TypeRef extends string;
|
|
533
|
+
} ? TypeRef : undefined;
|
|
534
|
+
type LookupNamedStorageTypeKeyByValue<Definition, TypeRef$1 extends StorageTypeInstance> = { [TypeName in keyof DefinitionTypes<Definition> & string]: [TypeRef$1] extends [DefinitionTypes<Definition>[TypeName]] ? [DefinitionTypes<Definition>[TypeName]] extends [TypeRef$1] ? TypeName : never : never }[keyof DefinitionTypes<Definition> & string];
|
|
535
|
+
type ResolveNamedStorageTypeKey<Definition, TypeRef$1> = TypeRef$1 extends string ? TypeRef$1 : TypeRef$1 extends StorageTypeInstance ? [LookupNamedStorageTypeKeyByValue<Definition, TypeRef$1>] extends [never] ? string : LookupNamedStorageTypeKeyByValue<Definition, TypeRef$1> : never;
|
|
536
|
+
type ResolveNamedStorageType<Definition, TypeRef$1> = ResolveNamedStorageTypeKey<Definition, TypeRef$1> extends infer TypeName extends string ? TypeName extends keyof DefinitionTypes<Definition> ? DefinitionTypes<Definition>[TypeName] : StorageTypeInstance : StorageTypeInstance;
|
|
537
|
+
type ResolveFieldDescriptor<Definition, FieldState> = [FieldDescriptorOf<FieldState>] extends [never] ? ResolveNamedStorageType<Definition, FieldTypeRefOf<FieldState>> : FieldDescriptorOf<FieldState>;
|
|
538
|
+
type ResolveFieldColumnTypeRef<Definition, FieldState> = [FieldTypeRefOf<FieldState>] extends [never] ? DescriptorTypeRef<FieldDescriptorOf<FieldState>> : ResolveNamedStorageTypeKey<Definition, FieldTypeRefOf<FieldState>>;
|
|
539
|
+
type ResolveFieldColumnTypeParams<Definition, FieldState> = [ResolveFieldColumnTypeRef<Definition, FieldState>] extends [string] ? undefined : DescriptorTypeParams<FieldDescriptorOf<FieldState>>;
|
|
540
|
+
type ModelTableName<Definition, ModelName$1 extends ModelNames<Definition>> = [Present<ModelSql<Definition, ModelName$1> extends {
|
|
541
|
+
readonly table?: infer TableName;
|
|
542
|
+
} ? TableName : never>] extends [never] ? ApplyNamingType<ModelName$1, DefinitionTableNaming<Definition>> : Present<ModelSql<Definition, ModelName$1> extends {
|
|
543
|
+
readonly table?: infer TableName;
|
|
544
|
+
} ? TableName : never> extends infer ExplicitTableName extends string ? ExplicitTableName : ApplyNamingType<ModelName$1, DefinitionTableNaming<Definition>>;
|
|
545
|
+
type ModelColumnName<Definition, ModelName$1 extends ModelNames<Definition>, FieldName$1 extends ModelFieldNames<Definition, ModelName$1>> = [FieldColumnOverrideOf<ModelFieldState<Definition, ModelName$1, FieldName$1>>] extends [never] ? ApplyNamingType<FieldName$1, DefinitionColumnNaming<Definition>> : FieldColumnOverrideOf<ModelFieldState<Definition, ModelName$1, FieldName$1>> extends infer ExplicitColumnName extends string ? ExplicitColumnName : ApplyNamingType<FieldName$1, DefinitionColumnNaming<Definition>>;
|
|
546
|
+
type FieldNamesToColumnNames<Definition, ModelName$1 extends ModelNames<Definition>, FieldNames extends readonly string[]> = FieldNames extends readonly [] ? readonly [] : FieldNames extends readonly [infer First extends ModelFieldNames<Definition, ModelName$1>, ...infer Rest extends readonly string[]] ? readonly [ModelColumnName<Definition, ModelName$1, First>, ...FieldNamesToColumnNames<Definition, ModelName$1, Rest>] : readonly string[];
|
|
547
|
+
type InlineIdFieldName<Definition, ModelName$1 extends ModelNames<Definition>> = { [FieldName in ModelFieldNames<Definition, ModelName$1>]: [FieldInlineIdSpecOf<ModelFieldState<Definition, ModelName$1, FieldName>>] extends [never] ? never : FieldName }[ModelFieldNames<Definition, ModelName$1>];
|
|
548
|
+
type InlineIdFieldNames<Definition, ModelName$1 extends ModelNames<Definition>> = [InlineIdFieldName<Definition, ModelName$1>] extends [never] ? undefined : readonly [InlineIdFieldName<Definition, ModelName$1>];
|
|
549
|
+
type InlineIdName<Definition, ModelName$1 extends ModelNames<Definition>> = { [FieldName in ModelFieldNames<Definition, ModelName$1>]: FieldInlineIdSpecOf<ModelFieldState<Definition, ModelName$1, FieldName>> extends {
|
|
550
|
+
readonly name?: infer Name extends string;
|
|
551
|
+
} ? Name : never }[ModelFieldNames<Definition, ModelName$1>];
|
|
552
|
+
type AttributeIdFieldNames<Definition, ModelName$1 extends ModelNames<Definition>> = AttributeStageIdFieldNames<ModelAttributes<Definition, ModelName$1>>;
|
|
553
|
+
type AttributeIdName<Definition, ModelName$1 extends ModelNames<Definition>> = Present<ModelAttributes<Definition, ModelName$1> extends {
|
|
554
|
+
readonly id?: {
|
|
555
|
+
readonly name?: infer Name extends string;
|
|
556
|
+
};
|
|
557
|
+
} ? Name : never>;
|
|
558
|
+
type ModelIdFieldNames<Definition, ModelName$1 extends ModelNames<Definition>> = [AttributeIdFieldNames<Definition, ModelName$1>] extends [undefined] ? InlineIdFieldNames<Definition, ModelName$1> : AttributeIdFieldNames<Definition, ModelName$1>;
|
|
559
|
+
type ModelIdName<Definition, ModelName$1 extends ModelNames<Definition>> = [AttributeIdName<Definition, ModelName$1>] extends [never] ? Present<InlineIdName<Definition, ModelName$1>> : AttributeIdName<Definition, ModelName$1>;
|
|
560
|
+
type StorageColumn<CodecId$1 extends string, Nullable$1 extends boolean, NativeType extends string, TypeRef$1 extends string | undefined = undefined, TypeParams$1 extends Record<string, unknown> | undefined = undefined> = {
|
|
561
|
+
readonly nativeType: NativeType;
|
|
562
|
+
readonly codecId: CodecId$1;
|
|
563
|
+
readonly nullable: Nullable$1;
|
|
564
|
+
readonly default?: ColumnDefault;
|
|
565
|
+
} & (TypeRef$1 extends string ? {
|
|
566
|
+
readonly typeRef: TypeRef$1;
|
|
567
|
+
} : Record<string, never>) & (TypeParams$1 extends Record<string, unknown> ? {
|
|
568
|
+
readonly typeParams: TypeParams$1;
|
|
569
|
+
} : Record<string, never>);
|
|
570
|
+
type ModelStorageColumn<Definition, ModelName$1 extends ModelNames<Definition>, FieldName$1 extends string> = FieldName$1 extends ModelFieldNames<Definition, ModelName$1> ? StorageColumn<DescriptorCodecId<ResolveFieldDescriptor<Definition, ModelFieldState<Definition, ModelName$1, FieldName$1>>>, FieldNullableOf<ModelFieldState<Definition, ModelName$1, FieldName$1>>, DescriptorNativeType<ResolveFieldDescriptor<Definition, ModelFieldState<Definition, ModelName$1, FieldName$1>>>, ResolveFieldColumnTypeRef<Definition, ModelFieldState<Definition, ModelName$1, FieldName$1>>, ResolveFieldColumnTypeParams<Definition, ModelFieldState<Definition, ModelName$1, FieldName$1>>> : never;
|
|
571
|
+
type BuiltModels<Definition> = { readonly [ModelName in ModelNames<Definition>]: {
|
|
572
|
+
readonly storage: {
|
|
573
|
+
readonly table: ModelTableName<Definition, ModelName>;
|
|
574
|
+
readonly fields: { readonly [FieldName in ModelFieldNames<Definition, ModelName>]: {
|
|
575
|
+
readonly column: ModelColumnName<Definition, ModelName, FieldName>;
|
|
576
|
+
} };
|
|
577
|
+
};
|
|
578
|
+
readonly fields: { readonly [FieldName in ModelFieldNames<Definition, ModelName>]: {
|
|
579
|
+
readonly nullable: ModelStorageColumn<Definition, ModelName, FieldName>['nullable'];
|
|
580
|
+
readonly type: {
|
|
581
|
+
readonly kind: 'scalar';
|
|
582
|
+
readonly codecId: ModelStorageColumn<Definition, ModelName, FieldName>['codecId'];
|
|
583
|
+
};
|
|
584
|
+
} };
|
|
585
|
+
readonly relations: { readonly [RelName in StagedModelRelationNames<Definition, ModelName>]: ContractRelation };
|
|
586
|
+
} };
|
|
587
|
+
type BuiltModelColumnMappings<Definition, ModelName$1 extends ModelNames<Definition>> = BuiltModels<Definition>[ModelName$1]['storage']['fields'];
|
|
588
|
+
type BuiltModelTableName<Definition, ModelName$1 extends ModelNames<Definition>> = BuiltModels<Definition>[ModelName$1]['storage']['table'];
|
|
589
|
+
type BuiltStorageTableColumns<Definition, ModelName$1 extends ModelNames<Definition>> = { readonly [FieldName in keyof BuiltModelColumnMappings<Definition, ModelName$1> & string as BuiltModelColumnMappings<Definition, ModelName$1>[FieldName]['column']]: ModelStorageColumn<Definition, ModelName$1, FieldName> };
|
|
590
|
+
type BuiltStorageTables<Definition> = { readonly [ModelName in ModelNames<Definition> as BuiltModelTableName<Definition, ModelName>]: {
|
|
591
|
+
readonly columns: BuiltStorageTableColumns<Definition, ModelName>;
|
|
592
|
+
readonly uniques: ReadonlyArray<{
|
|
593
|
+
readonly columns: readonly string[];
|
|
594
|
+
readonly name?: string;
|
|
595
|
+
}>;
|
|
596
|
+
readonly indexes: ReadonlyArray<Index$1>;
|
|
597
|
+
readonly foreignKeys: ReadonlyArray<{
|
|
598
|
+
readonly columns: readonly string[];
|
|
599
|
+
readonly references: {
|
|
600
|
+
readonly table: string;
|
|
601
|
+
readonly columns: readonly string[];
|
|
602
|
+
};
|
|
603
|
+
readonly name?: string;
|
|
604
|
+
readonly onDelete?: ReferentialAction;
|
|
605
|
+
readonly onUpdate?: ReferentialAction;
|
|
606
|
+
readonly constraint: boolean;
|
|
607
|
+
readonly index: boolean;
|
|
608
|
+
}>;
|
|
609
|
+
} & (ModelIdFieldNames<Definition, ModelName> extends readonly string[] ? {
|
|
610
|
+
readonly primaryKey: {
|
|
611
|
+
readonly columns: FieldNamesToColumnNames<Definition, ModelName, ModelIdFieldNames<Definition, ModelName>>;
|
|
612
|
+
readonly name?: ModelIdName<Definition, ModelName>;
|
|
613
|
+
};
|
|
614
|
+
} : Record<string, never>) };
|
|
615
|
+
type BuiltStorage<Definition> = {
|
|
616
|
+
readonly storageHash: StorageHashBase<string>;
|
|
617
|
+
readonly tables: BuiltStorageTables<Definition>;
|
|
618
|
+
readonly types: DefinitionTypes<Definition>;
|
|
619
|
+
};
|
|
620
|
+
type FieldOutputType<Definition, ModelName$1 extends ModelNames<Definition>, FieldName$1 extends ModelFieldNames<Definition, ModelName$1>> = ModelStorageColumn<Definition, ModelName$1, FieldName$1> extends infer Col ? Col extends {
|
|
621
|
+
readonly codecId: infer Id extends string;
|
|
622
|
+
} ? Id extends keyof CodecTypesFromDefinition<Definition> ? CodecTypesFromDefinition<Definition>[Id] extends {
|
|
623
|
+
readonly output: infer O;
|
|
624
|
+
} ? Col extends {
|
|
625
|
+
readonly nullable: true;
|
|
626
|
+
} ? O | null : O : unknown : unknown : unknown : unknown;
|
|
627
|
+
type FieldOutputTypes<Definition> = { readonly [ModelName in ModelNames<Definition>]: { readonly [FieldName in ModelFieldNames<Definition, ModelName>]: FieldOutputType<Definition, ModelName, FieldName> } };
|
|
628
|
+
type SqlContractResult<Definition> = ContractWithTypeMaps<Contract<BuiltStorage<Definition>, BuiltModels<Definition>> & {
|
|
629
|
+
readonly target: DefinitionTargetId<Definition>;
|
|
630
|
+
readonly targetFamily: 'sql';
|
|
631
|
+
} & {
|
|
632
|
+
readonly extensionPacks: keyof DefinitionExtensionPacks<Definition> extends never ? Record<string, never> : DefinitionExtensionPacks<Definition>;
|
|
633
|
+
readonly capabilities: DefinitionCapabilities<Definition> extends Record<string, Record<string, boolean>> ? DefinitionCapabilities<Definition> : Record<string, Record<string, boolean>>;
|
|
634
|
+
}, TypeMaps<CodecTypesFromDefinition<Definition>, Record<string, never>, Record<string, never>, FieldOutputTypes<Definition>>>;
|
|
635
|
+
//#endregion
|
|
636
|
+
//#region src/contract-definition.d.ts
|
|
637
|
+
interface FieldNode {
|
|
638
|
+
readonly fieldName: string;
|
|
639
|
+
readonly columnName: string;
|
|
640
|
+
readonly descriptor: ColumnTypeDescriptor;
|
|
641
|
+
readonly nullable: boolean;
|
|
642
|
+
readonly default?: ColumnDefault;
|
|
643
|
+
readonly executionDefault?: ExecutionMutationDefaultValue;
|
|
644
|
+
readonly many?: boolean;
|
|
645
|
+
}
|
|
646
|
+
interface PrimaryKeyNode {
|
|
647
|
+
readonly columns: readonly string[];
|
|
648
|
+
readonly name?: string;
|
|
649
|
+
}
|
|
650
|
+
interface UniqueConstraintNode {
|
|
651
|
+
readonly columns: readonly string[];
|
|
652
|
+
readonly name?: string;
|
|
653
|
+
}
|
|
654
|
+
interface IndexNode {
|
|
655
|
+
readonly columns: readonly string[];
|
|
656
|
+
readonly name?: string;
|
|
657
|
+
readonly using?: string;
|
|
658
|
+
readonly config?: Record<string, unknown>;
|
|
659
|
+
}
|
|
660
|
+
interface ForeignKeyNode {
|
|
661
|
+
readonly columns: readonly string[];
|
|
662
|
+
readonly references: {
|
|
663
|
+
readonly model: string;
|
|
664
|
+
readonly table: string;
|
|
665
|
+
readonly columns: readonly string[];
|
|
666
|
+
};
|
|
667
|
+
readonly name?: string;
|
|
668
|
+
readonly onDelete?: ReferentialAction;
|
|
669
|
+
readonly onUpdate?: ReferentialAction;
|
|
670
|
+
readonly constraint?: boolean;
|
|
671
|
+
readonly index?: boolean;
|
|
672
|
+
}
|
|
673
|
+
interface RelationNode {
|
|
674
|
+
readonly fieldName: string;
|
|
675
|
+
readonly toModel: string;
|
|
676
|
+
readonly toTable: string;
|
|
677
|
+
readonly cardinality: '1:1' | '1:N' | 'N:1' | 'N:M';
|
|
678
|
+
readonly on: {
|
|
679
|
+
readonly parentTable: string;
|
|
680
|
+
readonly parentColumns: readonly string[];
|
|
681
|
+
readonly childTable: string;
|
|
682
|
+
readonly childColumns: readonly string[];
|
|
683
|
+
};
|
|
684
|
+
readonly through?: {
|
|
685
|
+
readonly table: string;
|
|
686
|
+
readonly parentColumns: readonly string[];
|
|
687
|
+
readonly childColumns: readonly string[];
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
interface ValueObjectFieldNode {
|
|
691
|
+
readonly fieldName: string;
|
|
692
|
+
readonly columnName: string;
|
|
693
|
+
readonly valueObjectName: string;
|
|
694
|
+
readonly nullable: boolean;
|
|
695
|
+
readonly default?: ColumnDefault;
|
|
696
|
+
readonly executionDefault?: ExecutionMutationDefaultValue;
|
|
697
|
+
readonly many?: boolean;
|
|
698
|
+
}
|
|
699
|
+
interface ValueObjectNode {
|
|
700
|
+
readonly name: string;
|
|
701
|
+
readonly fields: readonly (FieldNode | ValueObjectFieldNode)[];
|
|
702
|
+
}
|
|
703
|
+
interface ModelNode {
|
|
704
|
+
readonly modelName: string;
|
|
705
|
+
readonly tableName: string;
|
|
706
|
+
readonly fields: readonly (FieldNode | ValueObjectFieldNode)[];
|
|
707
|
+
readonly id?: PrimaryKeyNode;
|
|
708
|
+
readonly uniques?: readonly UniqueConstraintNode[];
|
|
709
|
+
readonly indexes?: readonly IndexNode[];
|
|
710
|
+
readonly foreignKeys?: readonly ForeignKeyNode[];
|
|
711
|
+
readonly relations?: readonly RelationNode[];
|
|
712
|
+
}
|
|
713
|
+
interface ContractDefinition {
|
|
714
|
+
readonly target: TargetPackRef<'sql', string>;
|
|
715
|
+
readonly extensionPacks?: Record<string, ExtensionPackRef<'sql', string>>;
|
|
716
|
+
readonly capabilities?: Record<string, Record<string, boolean>>;
|
|
717
|
+
readonly storageHash?: string;
|
|
718
|
+
readonly foreignKeyDefaults?: ForeignKeyDefaultsState;
|
|
719
|
+
readonly storageTypes?: Record<string, StorageTypeInstance>;
|
|
720
|
+
readonly models: readonly ModelNode[];
|
|
721
|
+
readonly valueObjects?: readonly ValueObjectNode[];
|
|
722
|
+
}
|
|
723
|
+
//#endregion
|
|
724
|
+
//#region src/build-contract.d.ts
|
|
725
|
+
declare function buildSqlContractFromDefinition(definition: ContractDefinition, codecLookup?: CodecLookup): Contract<SqlStorage>;
|
|
726
|
+
//#endregion
|
|
727
|
+
//#region src/contract-builder.d.ts
|
|
728
|
+
type ModelLike = {
|
|
729
|
+
readonly stageOne: {
|
|
730
|
+
readonly modelName?: string;
|
|
731
|
+
readonly fields: Record<string, ScalarFieldBuilder>;
|
|
732
|
+
readonly relations: Record<string, RelationBuilder<RelationState>>;
|
|
733
|
+
};
|
|
734
|
+
readonly __attributes: ModelAttributesSpec | undefined;
|
|
735
|
+
readonly __sql: SqlStageSpec | undefined;
|
|
736
|
+
buildAttributesSpec(): ModelAttributesSpec | undefined;
|
|
737
|
+
buildSqlSpec(): SqlStageSpec | undefined;
|
|
738
|
+
};
|
|
739
|
+
type ContractDefinition$1<Family extends FamilyPackRef<string>, Target extends TargetPackRef<'sql', string>, Types extends Record<string, StorageTypeInstance>, Models extends Record<string, ModelLike>, ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined, Capabilities extends Record<string, Record<string, boolean>> | undefined, Naming extends ContractInput['naming'] | undefined, StorageHash extends string | undefined, ForeignKeyDefaults extends ForeignKeyDefaultsState | undefined> = {
|
|
740
|
+
readonly family: Family;
|
|
741
|
+
readonly target: Target;
|
|
742
|
+
readonly extensionPacks?: ExtensionPacks;
|
|
743
|
+
readonly naming?: Naming;
|
|
744
|
+
readonly storageHash?: StorageHash;
|
|
745
|
+
readonly foreignKeyDefaults?: ForeignKeyDefaults;
|
|
746
|
+
readonly capabilities?: Capabilities;
|
|
747
|
+
readonly types?: Types;
|
|
748
|
+
readonly models?: Models;
|
|
749
|
+
readonly codecLookup?: CodecLookup;
|
|
750
|
+
};
|
|
751
|
+
type ContractScaffold<Family extends FamilyPackRef<string>, Target extends TargetPackRef<'sql', string>, ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined, Capabilities extends Record<string, Record<string, boolean>> | undefined, Naming extends ContractInput['naming'] | undefined, StorageHash extends string | undefined, ForeignKeyDefaults extends ForeignKeyDefaultsState | undefined> = {
|
|
752
|
+
readonly family: Family;
|
|
753
|
+
readonly target: Target;
|
|
754
|
+
readonly extensionPacks?: ExtensionPacks;
|
|
755
|
+
readonly naming?: Naming;
|
|
756
|
+
readonly storageHash?: StorageHash;
|
|
757
|
+
readonly foreignKeyDefaults?: ForeignKeyDefaults;
|
|
758
|
+
readonly capabilities?: Capabilities;
|
|
759
|
+
readonly codecLookup?: CodecLookup;
|
|
760
|
+
};
|
|
761
|
+
type ContractFactory<Family extends FamilyPackRef<string>, Target extends TargetPackRef<'sql', string>, Types extends Record<string, StorageTypeInstance>, Models extends Record<string, ModelLike>, ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined> = (helpers: ComposedAuthoringHelpers<Family, Target, ExtensionPacks>) => {
|
|
762
|
+
readonly types?: Types;
|
|
763
|
+
readonly models?: Models;
|
|
764
|
+
};
|
|
765
|
+
declare function defineContract<const Family extends FamilyPackRef<string>, const Target extends TargetPackRef<'sql', string>, const Types extends Record<string, StorageTypeInstance> = Record<never, never>, const Models extends Record<string, ModelLike> = Record<never, never>, const ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined = undefined, const Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined, const Naming extends ContractInput['naming'] | undefined = undefined, const StorageHash extends string | undefined = undefined, const ForeignKeyDefaults extends ForeignKeyDefaultsState | undefined = undefined>(definition: ContractDefinition$1<Family, Target, Types, Models, ExtensionPacks, Capabilities, Naming, StorageHash, ForeignKeyDefaults>): SqlContractResult<ContractDefinition$1<Family, Target, Types, Models, ExtensionPacks, Capabilities, Naming, StorageHash, ForeignKeyDefaults>>;
|
|
766
|
+
declare function defineContract<const Family extends FamilyPackRef<string>, const Target extends TargetPackRef<'sql', string>, const Types extends Record<string, StorageTypeInstance> = Record<never, never>, const Models extends Record<string, ModelLike> = Record<never, never>, const ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined = undefined, const Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined, const Naming extends ContractInput['naming'] | undefined = undefined, const StorageHash extends string | undefined = undefined, const ForeignKeyDefaults extends ForeignKeyDefaultsState | undefined = undefined>(definition: ContractScaffold<Family, Target, ExtensionPacks, Capabilities, Naming, StorageHash, ForeignKeyDefaults>, factory: ContractFactory<Family, Target, Types, Models, ExtensionPacks>): SqlContractResult<ContractDefinition$1<Family, Target, Types, Models, ExtensionPacks, Capabilities, Naming, StorageHash, ForeignKeyDefaults>>;
|
|
767
|
+
//#endregion
|
|
768
|
+
export { type ComposedAuthoringHelpers, type ContractDefinition, type ContractInput, type ContractModelBuilder, type FieldNode, type ForeignKeyNode, type IndexNode, type ModelNode, type PrimaryKeyNode, type RelationNode, type ScalarFieldBuilder, type UniqueConstraintNode, buildSqlContractFromDefinition, defineContract, field, model, rel };
|
|
769
|
+
//# sourceMappingURL=contract-builder.d.mts.map
|