@prisma-next/sql-contract-ts 0.3.0-dev.135 → 0.3.0-dev.146
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 +107 -154
- package/dist/config-types.d.mts +2 -2
- package/dist/config-types.d.mts.map +1 -1
- package/dist/config-types.mjs +2 -2
- package/dist/config-types.mjs.map +1 -1
- package/dist/contract-builder.d.mts +192 -236
- package/dist/contract-builder.d.mts.map +1 -1
- package/dist/contract-builder.mjs +317 -422
- package/dist/contract-builder.mjs.map +1 -1
- package/package.json +8 -6
- package/schemas/data-contract-sql-v1.json +6 -6
- package/src/authoring-helper-runtime.ts +2 -2
- package/src/authoring-type-utils.ts +2 -2
- package/src/build-contract.ts +463 -0
- package/src/composed-authoring-helpers.ts +8 -6
- package/src/config-types.ts +3 -3
- package/src/contract-builder.ts +122 -636
- package/src/{semantic-contract.ts → contract-definition.ts} +33 -16
- package/src/{staged-contract-dsl.ts → contract-dsl.ts} +30 -28
- package/src/{staged-contract-lowering.ts → contract-lowering.ts} +46 -48
- package/src/{staged-contract-types.ts → contract-types.ts} +185 -145
- package/src/{staged-contract-warnings.ts → contract-warnings.ts} +18 -21
- package/src/exports/contract-builder.ts +12 -13
- package/src/contract-ir-builder.ts +0 -475
- package/src/contract.ts +0 -475
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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";
|
|
6
7
|
|
|
7
|
-
//#region src/
|
|
8
|
+
//#region src/contract-dsl.d.ts
|
|
8
9
|
type NamingStrategy = 'identity' | 'snake_case';
|
|
9
10
|
type NamingConfig = {
|
|
10
11
|
readonly tables?: NamingStrategy;
|
|
@@ -258,7 +259,7 @@ type SqlForeignKeys<SqlSpec extends SqlStageSpec> = SqlSpec extends {
|
|
|
258
259
|
type SqlNamedObjects<SqlSpec extends SqlStageSpec> = [...SqlIndexes<SqlSpec>, ...SqlForeignKeys<SqlSpec>];
|
|
259
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;
|
|
260
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;
|
|
261
|
-
declare class
|
|
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> {
|
|
262
263
|
readonly stageOne: {
|
|
263
264
|
readonly modelName?: ModelName$1;
|
|
264
265
|
readonly fields: Fields$1;
|
|
@@ -277,10 +278,10 @@ declare class StagedModelBuilder<ModelName$1 extends string | undefined, Fields$
|
|
|
277
278
|
readonly fields: Fields$1;
|
|
278
279
|
readonly relations: Relations;
|
|
279
280
|
}, attributesFactory?: StageInput<AttributeContext<Fields$1>, AttributesSpec> | undefined, sqlFactory?: StageInput<SqlContext<Fields$1>, SqlSpec> | undefined);
|
|
280
|
-
ref<FieldName$1 extends keyof Fields$1 & string>(this: ModelName$1 extends string ?
|
|
281
|
-
relations<const NextRelations extends Record<string, AnyRelationBuilder>>(relations: NextRelations):
|
|
282
|
-
attributes<const NextAttributesSpec extends ModelAttributesSpec>(specOrFactory: StageInput<AttributeContext<Fields$1>, ValidateAttributesStageSpec<Fields$1, SqlSpec, NextAttributesSpec>>):
|
|
283
|
-
sql<const NextSqlSpec extends SqlStageSpec>(specOrFactory: StageInput<SqlContext<Fields$1>, NextSqlSpec>): [ValidateSqlStageSpec<Fields$1, AttributesSpec, NextSqlSpec>] extends [never] ?
|
|
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>;
|
|
284
285
|
buildAttributesSpec(): AttributesSpec;
|
|
285
286
|
buildSqlSpec(): SqlSpec;
|
|
286
287
|
}
|
|
@@ -295,7 +296,7 @@ type LazyNamedModelToken<Token$1 extends AnyNamedModelToken = AnyNamedModelToken
|
|
|
295
296
|
type RelationFieldSelection<FieldName$1 extends string> = FieldName$1 | readonly FieldName$1[];
|
|
296
297
|
type RelationModelName<Target> = Target extends NamedModelTokenShape<infer ModelName extends string, Record<string, ScalarFieldBuilder>> ? ModelName : Target extends (() => infer Token) ? RelationModelName<Token> : never;
|
|
297
298
|
type RelationModelFieldNames<Target> = Target extends NamedModelTokenShape<string, infer Fields> ? keyof Fields & string : Target extends (() => infer Token) ? RelationModelFieldNames<Token> : never;
|
|
298
|
-
type
|
|
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> = {
|
|
299
300
|
readonly family: Family;
|
|
300
301
|
readonly target: Target;
|
|
301
302
|
readonly extensionPacks?: ExtensionPacks;
|
|
@@ -305,15 +306,16 @@ type StagedContractInput<Family extends FamilyPackRef<string> = FamilyPackRef<st
|
|
|
305
306
|
readonly capabilities?: Capabilities;
|
|
306
307
|
readonly types?: Types;
|
|
307
308
|
readonly models?: Models;
|
|
309
|
+
readonly codecLookup?: CodecLookup;
|
|
308
310
|
};
|
|
309
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: {
|
|
310
312
|
readonly fields: Fields$1;
|
|
311
313
|
readonly relations?: Relations;
|
|
312
|
-
}):
|
|
314
|
+
}): ContractModelBuilder<ModelName$1, Fields$1, Relations>;
|
|
313
315
|
declare function model<Fields$1 extends Record<string, ScalarFieldBuilder>, Relations extends Record<string, AnyRelationBuilder> = Record<never, never>>(input: {
|
|
314
316
|
readonly fields: Fields$1;
|
|
315
317
|
readonly relations?: Relations;
|
|
316
|
-
}):
|
|
318
|
+
}): ContractModelBuilder<undefined, Fields$1, Relations>;
|
|
317
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: {
|
|
318
320
|
readonly from: FromField$1;
|
|
319
321
|
readonly to: ToField$1;
|
|
@@ -439,83 +441,7 @@ type ComposedAuthoringHelpers<Family extends FamilyPackRef<string>, Target exten
|
|
|
439
441
|
readonly type: TypeHelpersFromNamespace<ExtractTypeNamespaceFromPack<Family> & ExtractTypeNamespaceFromPack<Target> & MergeExtensionTypeNamespaces<ExtensionPacks>>;
|
|
440
442
|
};
|
|
441
443
|
//#endregion
|
|
442
|
-
//#region src/
|
|
443
|
-
interface SqlSemanticFieldNode {
|
|
444
|
-
readonly fieldName: string;
|
|
445
|
-
readonly columnName: string;
|
|
446
|
-
readonly descriptor: ColumnTypeDescriptor;
|
|
447
|
-
readonly nullable: boolean;
|
|
448
|
-
readonly default?: ColumnDefault;
|
|
449
|
-
readonly executionDefault?: ExecutionMutationDefaultValue;
|
|
450
|
-
}
|
|
451
|
-
interface SqlSemanticPrimaryKeyNode {
|
|
452
|
-
readonly columns: readonly string[];
|
|
453
|
-
readonly name?: string;
|
|
454
|
-
}
|
|
455
|
-
interface SqlSemanticUniqueConstraintNode {
|
|
456
|
-
readonly columns: readonly string[];
|
|
457
|
-
readonly name?: string;
|
|
458
|
-
}
|
|
459
|
-
interface SqlSemanticIndexNode {
|
|
460
|
-
readonly columns: readonly string[];
|
|
461
|
-
readonly name?: string;
|
|
462
|
-
readonly using?: string;
|
|
463
|
-
readonly config?: Record<string, unknown>;
|
|
464
|
-
}
|
|
465
|
-
interface SqlSemanticForeignKeyNode {
|
|
466
|
-
readonly columns: readonly string[];
|
|
467
|
-
readonly references: {
|
|
468
|
-
readonly model: string;
|
|
469
|
-
readonly table: string;
|
|
470
|
-
readonly columns: readonly string[];
|
|
471
|
-
};
|
|
472
|
-
readonly name?: string;
|
|
473
|
-
readonly onDelete?: ReferentialAction;
|
|
474
|
-
readonly onUpdate?: ReferentialAction;
|
|
475
|
-
readonly constraint?: boolean;
|
|
476
|
-
readonly index?: boolean;
|
|
477
|
-
}
|
|
478
|
-
interface SqlSemanticRelationNode {
|
|
479
|
-
readonly fieldName: string;
|
|
480
|
-
readonly toModel: string;
|
|
481
|
-
readonly toTable: string;
|
|
482
|
-
readonly cardinality: '1:1' | '1:N' | 'N:1' | 'N:M';
|
|
483
|
-
readonly on: {
|
|
484
|
-
readonly parentTable: string;
|
|
485
|
-
readonly parentColumns: readonly string[];
|
|
486
|
-
readonly childTable: string;
|
|
487
|
-
readonly childColumns: readonly string[];
|
|
488
|
-
};
|
|
489
|
-
readonly through?: {
|
|
490
|
-
readonly table: string;
|
|
491
|
-
readonly parentColumns: readonly string[];
|
|
492
|
-
readonly childColumns: readonly string[];
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
interface SqlSemanticModelNode {
|
|
496
|
-
readonly modelName: string;
|
|
497
|
-
readonly tableName: string;
|
|
498
|
-
readonly fields: readonly SqlSemanticFieldNode[];
|
|
499
|
-
readonly id?: SqlSemanticPrimaryKeyNode;
|
|
500
|
-
readonly uniques?: readonly SqlSemanticUniqueConstraintNode[];
|
|
501
|
-
readonly indexes?: readonly SqlSemanticIndexNode[];
|
|
502
|
-
readonly foreignKeys?: readonly SqlSemanticForeignKeyNode[];
|
|
503
|
-
readonly relations?: readonly SqlSemanticRelationNode[];
|
|
504
|
-
}
|
|
505
|
-
interface SqlSemanticContractDefinition {
|
|
506
|
-
readonly target: TargetPackRef<'sql', string>;
|
|
507
|
-
readonly extensionPacks?: Record<string, ExtensionPackRef<'sql', string>>;
|
|
508
|
-
readonly capabilities?: Record<string, Record<string, boolean>>;
|
|
509
|
-
readonly storageHash?: string;
|
|
510
|
-
readonly foreignKeyDefaults?: ForeignKeyDefaultsState;
|
|
511
|
-
readonly storageTypes?: Record<string, StorageTypeInstance>;
|
|
512
|
-
readonly models: readonly SqlSemanticModelNode[];
|
|
513
|
-
}
|
|
514
|
-
//#endregion
|
|
515
|
-
//#region src/contract-ir-builder.d.ts
|
|
516
|
-
declare function buildSqlContractFromSemanticDefinition(definition: SqlSemanticContractDefinition): ContractIR;
|
|
517
|
-
//#endregion
|
|
518
|
-
//#region src/staged-contract-types.d.ts
|
|
444
|
+
//#region src/contract-types.d.ts
|
|
519
445
|
type ExtractCodecTypesFromPack<P> = P extends {
|
|
520
446
|
__codecTypes?: infer C;
|
|
521
447
|
} ? C extends Record<string, {
|
|
@@ -523,35 +449,31 @@ type ExtractCodecTypesFromPack<P> = P extends {
|
|
|
523
449
|
}> ? C : Record<string, never> : Record<string, never>;
|
|
524
450
|
type MergeExtensionCodecTypes<Packs extends Record<string, unknown>> = UnionToIntersection<{ [K in keyof Packs]: ExtractCodecTypesFromPack<Packs[K]> }[keyof Packs]>;
|
|
525
451
|
type MergeExtensionCodecTypesSafe<Packs> = Packs extends Record<string, unknown> ? keyof Packs extends never ? Record<string, never> : MergeExtensionCodecTypes<Packs> : Record<string, never>;
|
|
526
|
-
type
|
|
527
|
-
type StagedDefinitionExtensionPacks<Definition> = Definition extends {
|
|
452
|
+
type DefinitionExtensionPacks<Definition> = Definition extends {
|
|
528
453
|
readonly extensionPacks?: infer Packs extends Record<string, ExtensionPackRef<'sql', string>>;
|
|
529
454
|
} ? Packs : Record<never, never>;
|
|
530
|
-
type
|
|
455
|
+
type DefinitionCapabilities<Definition> = Definition extends {
|
|
531
456
|
readonly capabilities?: infer Capabilities extends Record<string, Record<string, boolean>>;
|
|
532
457
|
} ? Capabilities : undefined;
|
|
533
|
-
type
|
|
458
|
+
type DefinitionTargetId<Definition> = Definition extends {
|
|
534
459
|
readonly target: TargetPackRef<'sql', infer Target>;
|
|
535
460
|
} ? Target : never;
|
|
536
|
-
type StagedDefinitionStorageHash<Definition> = Definition extends {
|
|
537
|
-
readonly storageHash?: infer StorageHash extends string;
|
|
538
|
-
} ? StorageHash : undefined;
|
|
539
461
|
type Present<T> = Exclude<T, undefined>;
|
|
540
|
-
type
|
|
462
|
+
type CodecTypesFromDefinition<Definition> = ExtractCodecTypesFromPack<Definition extends {
|
|
541
463
|
readonly target: infer Target;
|
|
542
|
-
} ? Target : never> & MergeExtensionCodecTypesSafe<
|
|
543
|
-
type
|
|
464
|
+
} ? Target : never> & MergeExtensionCodecTypesSafe<DefinitionExtensionPacks<Definition>>;
|
|
465
|
+
type DefinitionModels<Definition> = Definition extends {
|
|
544
466
|
readonly models?: unknown;
|
|
545
467
|
} ? Present<Definition['models']> extends Record<string, unknown> ? Present<Definition['models']> : Record<never, never> : Record<never, never>;
|
|
546
|
-
type
|
|
468
|
+
type DefinitionTypes<Definition> = Definition extends {
|
|
547
469
|
readonly types?: unknown;
|
|
548
470
|
} ? Present<Definition['types']> extends Record<string, StorageTypeInstance> ? Present<Definition['types']> : Record<never, never> : Record<never, never>;
|
|
549
|
-
type
|
|
471
|
+
type DefinitionTableNaming<Definition> = Definition extends {
|
|
550
472
|
readonly naming?: {
|
|
551
473
|
readonly tables?: infer Strategy extends string;
|
|
552
474
|
};
|
|
553
475
|
} ? Strategy : undefined;
|
|
554
|
-
type
|
|
476
|
+
type DefinitionColumnNaming<Definition> = Definition extends {
|
|
555
477
|
readonly naming?: {
|
|
556
478
|
readonly columns?: infer Strategy extends string;
|
|
557
479
|
};
|
|
@@ -562,18 +484,24 @@ type ShouldInsertSnakeUnderscore<PrevKind extends 'start' | 'lower' | 'upper' |
|
|
|
562
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>>}` : '';
|
|
563
485
|
type SnakeCase<S extends string> = string extends S ? string : SnakeCaseInternal<S>;
|
|
564
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;
|
|
565
|
-
type
|
|
566
|
-
type
|
|
487
|
+
type ModelNames<Definition> = keyof DefinitionModels<Definition> & string;
|
|
488
|
+
type ModelFields<Definition, ModelName$1 extends ModelNames<Definition>> = DefinitionModels<Definition>[ModelName$1] extends {
|
|
567
489
|
readonly stageOne: {
|
|
568
490
|
readonly fields: Record<string, ScalarFieldBuilder>;
|
|
569
491
|
};
|
|
570
|
-
} ?
|
|
571
|
-
type
|
|
572
|
-
type
|
|
573
|
-
|
|
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 {
|
|
574
502
|
readonly __sql: infer SqlSpec;
|
|
575
503
|
} ? SqlSpec : undefined;
|
|
576
|
-
type
|
|
504
|
+
type ModelAttributes<Definition, ModelName$1 extends ModelNames<Definition>> = DefinitionModels<Definition>[ModelName$1] extends {
|
|
577
505
|
readonly __attributes: infer AttributesSpec;
|
|
578
506
|
} ? AttributesSpec : undefined;
|
|
579
507
|
type FieldDescriptorOf<FieldState> = Present<FieldState extends {
|
|
@@ -603,33 +531,33 @@ type DescriptorTypeParams<Descriptor> = Descriptor extends {
|
|
|
603
531
|
type DescriptorTypeRef<Descriptor> = Descriptor extends {
|
|
604
532
|
readonly typeRef: infer TypeRef extends string;
|
|
605
533
|
} ? TypeRef : undefined;
|
|
606
|
-
type LookupNamedStorageTypeKeyByValue<Definition, TypeRef$1 extends StorageTypeInstance> = { [TypeName in keyof
|
|
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];
|
|
607
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;
|
|
608
|
-
type ResolveNamedStorageType<Definition, TypeRef$1> = ResolveNamedStorageTypeKey<Definition, TypeRef$1> extends infer TypeName extends string ? TypeName extends keyof
|
|
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;
|
|
609
537
|
type ResolveFieldDescriptor<Definition, FieldState> = [FieldDescriptorOf<FieldState>] extends [never] ? ResolveNamedStorageType<Definition, FieldTypeRefOf<FieldState>> : FieldDescriptorOf<FieldState>;
|
|
610
538
|
type ResolveFieldColumnTypeRef<Definition, FieldState> = [FieldTypeRefOf<FieldState>] extends [never] ? DescriptorTypeRef<FieldDescriptorOf<FieldState>> : ResolveNamedStorageTypeKey<Definition, FieldTypeRefOf<FieldState>>;
|
|
611
539
|
type ResolveFieldColumnTypeParams<Definition, FieldState> = [ResolveFieldColumnTypeRef<Definition, FieldState>] extends [string] ? undefined : DescriptorTypeParams<FieldDescriptorOf<FieldState>>;
|
|
612
|
-
type
|
|
540
|
+
type ModelTableName<Definition, ModelName$1 extends ModelNames<Definition>> = [Present<ModelSql<Definition, ModelName$1> extends {
|
|
613
541
|
readonly table?: infer TableName;
|
|
614
|
-
} ? TableName : never>] extends [never] ? ApplyNamingType<ModelName$1,
|
|
542
|
+
} ? TableName : never>] extends [never] ? ApplyNamingType<ModelName$1, DefinitionTableNaming<Definition>> : Present<ModelSql<Definition, ModelName$1> extends {
|
|
615
543
|
readonly table?: infer TableName;
|
|
616
|
-
} ? TableName : never> extends infer ExplicitTableName extends string ? ExplicitTableName : ApplyNamingType<ModelName$1,
|
|
617
|
-
type
|
|
618
|
-
type
|
|
619
|
-
type
|
|
620
|
-
type
|
|
621
|
-
type
|
|
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 {
|
|
622
550
|
readonly name?: infer Name extends string;
|
|
623
|
-
} ? Name : never }[
|
|
624
|
-
type
|
|
625
|
-
type
|
|
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 {
|
|
626
554
|
readonly id?: {
|
|
627
555
|
readonly name?: infer Name extends string;
|
|
628
556
|
};
|
|
629
557
|
} ? Name : never>;
|
|
630
|
-
type
|
|
631
|
-
type
|
|
632
|
-
type
|
|
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> = {
|
|
633
561
|
readonly nativeType: NativeType;
|
|
634
562
|
readonly codecId: CodecId$1;
|
|
635
563
|
readonly nullable: Nullable$1;
|
|
@@ -639,20 +567,28 @@ type StagedStorageColumn<CodecId$1 extends string, Nullable$1 extends boolean, N
|
|
|
639
567
|
} : Record<string, never>) & (TypeParams$1 extends Record<string, unknown> ? {
|
|
640
568
|
readonly typeParams: TypeParams$1;
|
|
641
569
|
} : Record<string, never>);
|
|
642
|
-
type
|
|
643
|
-
type
|
|
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>]: {
|
|
644
572
|
readonly storage: {
|
|
645
|
-
readonly table:
|
|
573
|
+
readonly table: ModelTableName<Definition, ModelName>;
|
|
574
|
+
readonly fields: { readonly [FieldName in ModelFieldNames<Definition, ModelName>]: {
|
|
575
|
+
readonly column: ModelColumnName<Definition, ModelName, FieldName>;
|
|
576
|
+
} };
|
|
646
577
|
};
|
|
647
|
-
readonly fields: { readonly [FieldName in
|
|
648
|
-
readonly
|
|
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
|
+
};
|
|
649
584
|
} };
|
|
585
|
+
readonly relations: { readonly [RelName in StagedModelRelationNames<Definition, ModelName>]: ContractRelation };
|
|
650
586
|
} };
|
|
651
|
-
type
|
|
652
|
-
type
|
|
653
|
-
type
|
|
654
|
-
type
|
|
655
|
-
readonly columns:
|
|
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>;
|
|
656
592
|
readonly uniques: ReadonlyArray<{
|
|
657
593
|
readonly columns: readonly string[];
|
|
658
594
|
readonly name?: string;
|
|
@@ -670,62 +606,126 @@ type StagedBuiltStorageTables<Definition> = { readonly [ModelName in StagedModel
|
|
|
670
606
|
readonly constraint: boolean;
|
|
671
607
|
readonly index: boolean;
|
|
672
608
|
}>;
|
|
673
|
-
} & (
|
|
609
|
+
} & (ModelIdFieldNames<Definition, ModelName> extends readonly string[] ? {
|
|
674
610
|
readonly primaryKey: {
|
|
675
|
-
readonly columns:
|
|
676
|
-
readonly name?:
|
|
611
|
+
readonly columns: FieldNamesToColumnNames<Definition, ModelName, ModelIdFieldNames<Definition, ModelName>>;
|
|
612
|
+
readonly name?: ModelIdName<Definition, ModelName>;
|
|
677
613
|
};
|
|
678
614
|
} : Record<string, never>) };
|
|
679
|
-
type
|
|
680
|
-
readonly
|
|
681
|
-
readonly
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
readonly
|
|
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>;
|
|
686
630
|
readonly targetFamily: 'sql';
|
|
687
|
-
readonly storageHash: StagedDefinitionStorageHash<Definition> extends string ? StagedDefinitionStorageHash<Definition> : string;
|
|
688
631
|
} & {
|
|
689
|
-
readonly extensionPacks: keyof
|
|
690
|
-
readonly capabilities:
|
|
691
|
-
}, TypeMaps<
|
|
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>>>;
|
|
692
635
|
//#endregion
|
|
693
|
-
//#region src/contract-
|
|
694
|
-
|
|
695
|
-
readonly
|
|
696
|
-
readonly
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
readonly
|
|
701
|
-
readonly
|
|
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;
|
|
702
665
|
readonly columns: readonly string[];
|
|
703
|
-
readonly references: {
|
|
704
|
-
readonly table: string;
|
|
705
|
-
readonly columns: readonly string[];
|
|
706
|
-
};
|
|
707
|
-
readonly name?: string;
|
|
708
|
-
readonly onDelete?: ReferentialAction;
|
|
709
|
-
readonly onUpdate?: ReferentialAction;
|
|
710
|
-
readonly constraint: boolean;
|
|
711
|
-
readonly index: boolean;
|
|
712
|
-
}>;
|
|
713
|
-
} & (PK extends readonly string[] ? {
|
|
714
|
-
readonly primaryKey: {
|
|
715
|
-
readonly columns: PK;
|
|
716
|
-
readonly name?: string;
|
|
717
666
|
};
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
readonly
|
|
721
|
-
readonly
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
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;
|
|
727
698
|
}
|
|
728
|
-
|
|
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
729
|
readonly stageOne: {
|
|
730
730
|
readonly modelName?: string;
|
|
731
731
|
readonly fields: Record<string, ScalarFieldBuilder>;
|
|
@@ -736,50 +736,7 @@ type StagedModelLike = {
|
|
|
736
736
|
buildAttributesSpec(): ModelAttributesSpec | undefined;
|
|
737
737
|
buildSqlSpec(): SqlStageSpec | undefined;
|
|
738
738
|
};
|
|
739
|
-
|
|
740
|
-
output: unknown;
|
|
741
|
-
}> = Record<string, never>, 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>, Types extends Record<string, StorageTypeInstance> = Record<never, never>, StorageHash extends string | undefined = undefined, ExtensionPacks extends Record<string, unknown> | undefined = undefined, Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined> extends ContractBuilder<Target, Tables, Models, StorageHash, ExtensionPacks, Capabilities> {
|
|
742
|
-
protected readonly state: ContractBuilderState<Target, Tables, Models, StorageHash, ExtensionPacks, Capabilities> & {
|
|
743
|
-
readonly storageTypes?: Types;
|
|
744
|
-
};
|
|
745
|
-
/**
|
|
746
|
-
* This method is responsible for normalizing the contract IR by setting default values
|
|
747
|
-
* for all required fields:
|
|
748
|
-
* - `nullable`: defaults to `false` if not provided
|
|
749
|
-
* - `uniques`: defaults to `[]` (empty array)
|
|
750
|
-
* - `indexes`: defaults to `[]` (empty array)
|
|
751
|
-
* - `foreignKeys`: defaults to `[]` (empty array)
|
|
752
|
-
* - model `relations`: defaults to `{}` (empty object) when not populated by the builder
|
|
753
|
-
* - `nativeType`: required field set from column type descriptor when columns are defined
|
|
754
|
-
*
|
|
755
|
-
* The contract builder is the **only** place where normalization should occur.
|
|
756
|
-
* Validators, parsers, and emitters should assume the contract is already normalized.
|
|
757
|
-
*
|
|
758
|
-
* **Required**: Use column type descriptors (e.g., `int4Column`, `textColumn`) when defining columns.
|
|
759
|
-
* This ensures `nativeType` is set correctly at build time.
|
|
760
|
-
*
|
|
761
|
-
* @returns A normalized SqlContract with all required fields present
|
|
762
|
-
*/
|
|
763
|
-
build(): Target extends string ? ContractWithTypeMaps<SqlContract<BuildStorage<Tables, Types>, BuildModels<Models>> & {
|
|
764
|
-
readonly schemaVersion: '1';
|
|
765
|
-
readonly target: Target;
|
|
766
|
-
readonly targetFamily: 'sql';
|
|
767
|
-
readonly storageHash: StorageHash extends string ? StorageHash : string;
|
|
768
|
-
} & (ExtensionPacks extends Record<string, unknown> ? {
|
|
769
|
-
readonly extensionPacks: ExtensionPacks;
|
|
770
|
-
} : Record<string, never>) & (Capabilities extends Record<string, Record<string, boolean>> ? {
|
|
771
|
-
readonly capabilities: Capabilities;
|
|
772
|
-
} : Record<string, never>), TypeMaps<CodecTypes, Record<string, never>>> : never;
|
|
773
|
-
target<T extends string, TPack extends TargetPackRef<string, T> = TargetPackRef<string, T>>(packRef: TPack & TargetPackRef<string, T>): SqlContractBuilder<ExtractCodecTypesFromPack<TPack> extends Record<string, never> ? CodecTypes : ExtractCodecTypesFromPack<TPack>, T, Tables, Models, Types, StorageHash, ExtensionPacks, Capabilities>;
|
|
774
|
-
extensionPacks<const Packs extends Record<string, ExtensionPackRef<'sql', string>>>(packs: Packs): SqlContractBuilder<CodecTypes & MergeExtensionCodecTypes<Packs>, Target, Tables, Models, Types, StorageHash, MergeExtensionPackRefs<ExtensionPacks, Packs>, Capabilities>;
|
|
775
|
-
capabilities<C extends Record<string, Record<string, boolean>>>(capabilities: C): SqlContractBuilder<CodecTypes, Target, Tables, Models, Types, StorageHash, ExtensionPacks, C>;
|
|
776
|
-
storageHash<H extends string>(hash: H): SqlContractBuilder<CodecTypes, Target, Tables, Models, Types, H, ExtensionPacks, Capabilities>;
|
|
777
|
-
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): SqlContractBuilder<CodecTypes, Target, Tables & Record<TableName, ReturnType<T['build']>>, Models, Types, StorageHash, ExtensionPacks, Capabilities>;
|
|
778
|
-
model<ModelName$1 extends string, TableName extends string, M extends ModelBuilder<ModelName$1, TableName, Record<string, string>, Record<string, RelationDefinition>>>(name: ModelName$1, table: TableName, callback: (m: ModelBuilder<ModelName$1, TableName, Record<never, never>, Record<never, never>>) => M | undefined): SqlContractBuilder<CodecTypes, Target, Tables, Models & Record<ModelName$1, ReturnType<M['build']>>, Types, StorageHash, ExtensionPacks, Capabilities>;
|
|
779
|
-
foreignKeyDefaults(config: ForeignKeyDefaultsState): SqlContractBuilder<CodecTypes, Target, Tables, Models, Types, StorageHash, ExtensionPacks, Capabilities>;
|
|
780
|
-
storageType<Name$1 extends string, Type extends StorageTypeInstance>(name: Name$1, typeInstance: Type): SqlContractBuilder<CodecTypes, Target, Tables, Models, Types & Record<Name$1, Type>, StorageHash, ExtensionPacks, Capabilities>;
|
|
781
|
-
}
|
|
782
|
-
type StagedContractDefinition<Family extends FamilyPackRef<string>, Target extends TargetPackRef<'sql', string>, Types extends Record<string, StorageTypeInstance>, Models extends Record<string, StagedModelLike>, ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined, Capabilities extends Record<string, Record<string, boolean>> | undefined, Naming extends StagedContractInput['naming'] | undefined, StorageHash extends string | undefined, ForeignKeyDefaults extends ForeignKeyDefaultsState | undefined> = {
|
|
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> = {
|
|
783
740
|
readonly family: Family;
|
|
784
741
|
readonly target: Target;
|
|
785
742
|
readonly extensionPacks?: ExtensionPacks;
|
|
@@ -789,8 +746,9 @@ type StagedContractDefinition<Family extends FamilyPackRef<string>, Target exten
|
|
|
789
746
|
readonly capabilities?: Capabilities;
|
|
790
747
|
readonly types?: Types;
|
|
791
748
|
readonly models?: Models;
|
|
749
|
+
readonly codecLookup?: CodecLookup;
|
|
792
750
|
};
|
|
793
|
-
type
|
|
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> = {
|
|
794
752
|
readonly family: Family;
|
|
795
753
|
readonly target: Target;
|
|
796
754
|
readonly extensionPacks?: ExtensionPacks;
|
|
@@ -798,16 +756,14 @@ type StagedContractScaffold<Family extends FamilyPackRef<string>, Target extends
|
|
|
798
756
|
readonly storageHash?: StorageHash;
|
|
799
757
|
readonly foreignKeyDefaults?: ForeignKeyDefaults;
|
|
800
758
|
readonly capabilities?: Capabilities;
|
|
759
|
+
readonly codecLookup?: CodecLookup;
|
|
801
760
|
};
|
|
802
|
-
type
|
|
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>) => {
|
|
803
762
|
readonly types?: Types;
|
|
804
763
|
readonly models?: Models;
|
|
805
764
|
};
|
|
806
|
-
declare function defineContract<
|
|
807
|
-
|
|
808
|
-
}> = Record<string, never>>(): SqlContractBuilder<CodecTypes>;
|
|
809
|
-
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, StagedModelLike> = 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 StagedContractInput['naming'] | undefined = undefined, const StorageHash extends string | undefined = undefined, const ForeignKeyDefaults extends ForeignKeyDefaultsState | undefined = undefined>(definition: StagedContractDefinition<Family, Target, Types, Models, ExtensionPacks, Capabilities, Naming, StorageHash, ForeignKeyDefaults>): SqlContractResult<StagedContractDefinition<Family, Target, Types, Models, ExtensionPacks, Capabilities, Naming, StorageHash, ForeignKeyDefaults>>;
|
|
810
|
-
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, StagedModelLike> = 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 StagedContractInput['naming'] | undefined = undefined, const StorageHash extends string | undefined = undefined, const ForeignKeyDefaults extends ForeignKeyDefaultsState | undefined = undefined>(definition: StagedContractScaffold<Family, Target, ExtensionPacks, Capabilities, Naming, StorageHash, ForeignKeyDefaults>, factory: StagedContractFactory<Family, Target, Types, Models, ExtensionPacks>): SqlContractResult<StagedContractDefinition<Family, Target, Types, Models, ExtensionPacks, Capabilities, Naming, StorageHash, ForeignKeyDefaults>>;
|
|
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>>;
|
|
811
767
|
//#endregion
|
|
812
|
-
export { type
|
|
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 };
|
|
813
769
|
//# sourceMappingURL=contract-builder.d.mts.map
|