@prisma-next/sql-contract-ts 0.14.0-dev.6 → 0.14.0-dev.61
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/dist/{build-contract-CQ4u83jx.mjs → build-contract-CSyrbCoJ.mjs} +239 -30
- package/dist/build-contract-CSyrbCoJ.mjs.map +1 -0
- package/dist/config-types.d.mts +2 -0
- package/dist/config-types.d.mts.map +1 -1
- package/dist/config-types.mjs +2 -1
- package/dist/config-types.mjs.map +1 -1
- package/dist/contract-builder.d.mts +231 -328
- package/dist/contract-builder.d.mts.map +1 -1
- package/dist/contract-builder.mjs +43 -75
- package/dist/contract-builder.mjs.map +1 -1
- package/package.json +10 -10
- package/src/authoring-helper-runtime.ts +2 -6
- package/src/build-contract.ts +402 -49
- package/src/composed-authoring-helpers.ts +3 -6
- package/src/config-types.ts +7 -1
- package/src/contract-builder.ts +71 -5
- package/src/contract-definition.ts +27 -4
- package/src/contract-dsl.ts +117 -41
- package/src/contract-lowering.ts +5 -1
- package/src/contract-types.ts +34 -10
- package/src/enum-type.ts +14 -306
- package/dist/build-contract-CQ4u83jx.mjs.map +0 -1
|
@@ -1,148 +1,194 @@
|
|
|
1
1
|
import { ColumnDefault, ColumnDefaultLiteralInputValue, Contract, ContractEnum, ContractRelation, ContractValueObject, ControlPolicy, ExecutionMutationDefaultPhases, ExecutionMutationDefaultPhases as ExecutionMutationDefaultPhases$1, ExecutionMutationDefaultValue, NamespaceId, StorageHashBase } from "@prisma-next/contract/types";
|
|
2
|
-
import { EntityHelpersFromNamespace, ExtractAuthoringNamespaceFromPack, ForeignKeyDefaultsState, MergeExtensionAuthoringNamespaces } from "@prisma-next/contract-authoring";
|
|
3
|
-
import { Namespace, StorageType } from "@prisma-next/framework-components/ir";
|
|
4
|
-
import { IndexTypeRegistration } from "@prisma-next/sql-contract/index-types";
|
|
5
|
-
import { ContractWithTypeMaps, Index as Index$1, ReferentialAction, SqlNamespaceTablesInput, SqlStorage, StorageTypeInstance, TypeMaps } from "@prisma-next/sql-contract/types";
|
|
2
|
+
import { BoundEnumType, CodecInput, CodecTypeMap, EntityHelpersFromNamespace, EnumMember, EnumTypeHandle, ExtractAuthoringNamespaceFromPack, ForeignKeyDefaultsState, MergeExtensionAuthoringNamespaces, bindEnumType, enumType, member } from "@prisma-next/contract-authoring";
|
|
6
3
|
import { AuthoringArgumentDescriptor, AuthoringFieldPresetDescriptor, AuthoringTypeConstructorDescriptor } from "@prisma-next/framework-components/authoring";
|
|
4
|
+
import { StorageType } from "@prisma-next/framework-components/ir";
|
|
5
|
+
import { IndexTypeRegistration } from "@prisma-next/sql-contract/index-types";
|
|
6
|
+
import { ContractWithTypeMaps, Index as Index$1, ReferentialAction, SqlNamespaceBase, SqlNamespaceInput, SqlStorage, StorageTypeInstance, TypeMaps } from "@prisma-next/sql-contract/types";
|
|
7
7
|
import { ExtensionPackRef, FamilyPackRef, TargetPackRef } from "@prisma-next/framework-components/components";
|
|
8
8
|
import { CodecLookup, ColumnTypeDescriptor } from "@prisma-next/framework-components/codec";
|
|
9
9
|
|
|
10
|
-
//#region src/
|
|
10
|
+
//#region src/contract-definition.d.ts
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* An author-declared, namespace-scoped pack entity attachment: namespace id →
|
|
13
|
+
* entity kind (the discriminator the target/extension pack registered its
|
|
14
|
+
* `AuthoringContributions.entityTypes` descriptor under, e.g. `native_enum`)
|
|
15
|
+
* → entity name → the lowered entity instance. Generic on purpose — neither
|
|
16
|
+
* the framework nor `contract-ts` names a specific entity kind here; the
|
|
17
|
+
* shape mirrors `SqlNamespaceInput.entries` (`entries.<kind>[name]`), just
|
|
18
|
+
* namespace-nested so an author can target any declared namespace (default
|
|
19
|
+
* or named), not only the contract's default namespace.
|
|
16
20
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
readonly
|
|
21
|
+
type PackEntitiesInput = Readonly<Record<string, Readonly<Record<string, Readonly<Record<string, unknown>>>>>>;
|
|
22
|
+
interface FieldNode {
|
|
23
|
+
readonly fieldName: string;
|
|
24
|
+
readonly columnName: string;
|
|
25
|
+
readonly descriptor: ColumnTypeDescriptor;
|
|
26
|
+
readonly nullable: boolean;
|
|
27
|
+
readonly default?: ColumnDefault;
|
|
28
|
+
readonly executionDefaults?: ExecutionMutationDefaultPhases$1;
|
|
29
|
+
readonly many?: boolean;
|
|
30
|
+
/** Present when the field was authored with `field.namedType(enumHandle)`. */
|
|
31
|
+
readonly enumTypeHandle?: EnumTypeHandle;
|
|
20
32
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
type
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
readonly
|
|
57
|
-
|
|
58
|
-
readonly
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
readonly
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}[];
|
|
66
|
-
/** Ordered literal value tuple. Declaration order is preserved. */
|
|
67
|
-
readonly values: Values;
|
|
68
|
-
/** Ordered literal name tuple. Declaration order is preserved. */
|
|
69
|
-
readonly names: Names;
|
|
33
|
+
interface PrimaryKeyNode {
|
|
34
|
+
readonly columns: readonly string[];
|
|
35
|
+
readonly name?: string;
|
|
36
|
+
}
|
|
37
|
+
interface UniqueConstraintNode {
|
|
38
|
+
readonly columns: readonly string[];
|
|
39
|
+
readonly name?: string;
|
|
40
|
+
}
|
|
41
|
+
interface IndexNode {
|
|
42
|
+
readonly columns: readonly string[];
|
|
43
|
+
readonly name?: string;
|
|
44
|
+
readonly type?: string;
|
|
45
|
+
readonly options?: Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
interface ForeignKeyNode {
|
|
48
|
+
readonly columns: readonly string[];
|
|
49
|
+
readonly references: {
|
|
50
|
+
readonly model: string;
|
|
51
|
+
readonly table: string;
|
|
52
|
+
readonly columns: readonly string[];
|
|
53
|
+
/**
|
|
54
|
+
* Namespace coordinate of the referenced table. When omitted the
|
|
55
|
+
* assembler resolves the coordinate from the referenced model node's
|
|
56
|
+
* own `namespaceId`; the field exists so authoring paths that already
|
|
57
|
+
* know the target namespace can stamp it explicitly.
|
|
58
|
+
*/
|
|
59
|
+
readonly namespaceId?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Contract-space identity of the referenced table. When present, the
|
|
62
|
+
* table lives in a different contract space (identified by this value)
|
|
63
|
+
* rather than the current contract. Absent for local FKs.
|
|
64
|
+
*/
|
|
65
|
+
readonly spaceId?: string;
|
|
66
|
+
};
|
|
67
|
+
readonly name?: string;
|
|
68
|
+
readonly onDelete?: ReferentialAction;
|
|
69
|
+
readonly onUpdate?: ReferentialAction;
|
|
70
|
+
readonly constraint?: boolean;
|
|
71
|
+
readonly index?: boolean;
|
|
72
|
+
}
|
|
73
|
+
interface RelationNode {
|
|
74
|
+
readonly fieldName: string;
|
|
75
|
+
readonly toModel: string;
|
|
76
|
+
readonly toTable: string;
|
|
70
77
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
78
|
+
* Namespace coordinate of the related model. When omitted the assembler
|
|
79
|
+
* resolves the coordinate from the referenced model node's own
|
|
80
|
+
* `namespaceId`; the field exists so authoring paths that already know the
|
|
81
|
+
* target namespace can stamp it explicitly — required to disambiguate a
|
|
82
|
+
* relation to a model whose bare name also exists in another namespace.
|
|
73
83
|
*/
|
|
74
|
-
readonly
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
readonly toNamespaceId?: string;
|
|
85
|
+
readonly cardinality: '1:1' | '1:N' | 'N:1' | 'N:M';
|
|
86
|
+
/**
|
|
87
|
+
* Contract-space identity of the related model. When present, the
|
|
88
|
+
* related model lives in a different contract space. Absent for local
|
|
89
|
+
* (same-space) relations.
|
|
90
|
+
*/
|
|
91
|
+
readonly spaceId?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Namespace coordinate of the related model in the foreign space.
|
|
94
|
+
* Only set when `spaceId` is present.
|
|
95
|
+
*/
|
|
96
|
+
readonly namespaceId?: string;
|
|
97
|
+
readonly on: {
|
|
98
|
+
readonly parentTable: string;
|
|
99
|
+
readonly parentColumns: readonly string[];
|
|
100
|
+
readonly childTable: string;
|
|
101
|
+
readonly childColumns: readonly string[];
|
|
102
|
+
};
|
|
103
|
+
readonly through?: {
|
|
104
|
+
readonly table: string;
|
|
105
|
+
/**
|
|
106
|
+
* Namespace the junction table lives in. Set from the junction model's
|
|
107
|
+
* declared namespace at lowering time; junction table names are unique per
|
|
108
|
+
* namespace, not globally, so this disambiguates a junction whose bare table
|
|
109
|
+
* name also exists in another namespace. Omitted for a junction in the
|
|
110
|
+
* default namespace (resolved to the target's default at build time).
|
|
111
|
+
*/
|
|
112
|
+
readonly namespaceId?: string;
|
|
113
|
+
readonly parentColumns: readonly string[];
|
|
114
|
+
readonly childColumns: readonly string[];
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
interface ValueObjectFieldNode {
|
|
118
|
+
readonly fieldName: string;
|
|
119
|
+
readonly columnName: string;
|
|
120
|
+
readonly valueObjectName: string;
|
|
121
|
+
readonly nullable: boolean;
|
|
122
|
+
readonly default?: ColumnDefault;
|
|
123
|
+
readonly executionDefaults?: ExecutionMutationDefaultPhases$1;
|
|
124
|
+
readonly many?: boolean;
|
|
125
|
+
}
|
|
126
|
+
interface ValueObjectNode {
|
|
127
|
+
readonly name: string;
|
|
128
|
+
readonly fields: readonly (FieldNode | ValueObjectFieldNode)[];
|
|
129
|
+
}
|
|
130
|
+
interface ModelNode {
|
|
131
|
+
readonly modelName: string;
|
|
132
|
+
readonly tableName: string;
|
|
133
|
+
/**
|
|
134
|
+
* Resolved namespace coordinate for this model — the key into the
|
|
135
|
+
* parent contract's `SqlStorage.namespaces` map. Omitting the field
|
|
136
|
+
* (or setting it to the framework's `UNBOUND_NAMESPACE_ID` sentinel)
|
|
137
|
+
* selects the late-bound slot, which renders as unqualified DDL.
|
|
138
|
+
*
|
|
139
|
+
* Populated by per-target PSL interpreters from the resolved
|
|
140
|
+
* `namespace { … }` AST bucket; the TS builder also sets it from the
|
|
141
|
+
* per-model `namespace` field once that authoring surface lands.
|
|
142
|
+
*/
|
|
143
|
+
readonly namespaceId?: string;
|
|
144
|
+
readonly fields: readonly (FieldNode | ValueObjectFieldNode)[];
|
|
145
|
+
readonly id?: PrimaryKeyNode;
|
|
146
|
+
readonly uniques?: readonly UniqueConstraintNode[];
|
|
147
|
+
readonly indexes?: readonly IndexNode[];
|
|
148
|
+
readonly foreignKeys?: readonly ForeignKeyNode[];
|
|
149
|
+
readonly relations?: readonly RelationNode[];
|
|
150
|
+
readonly control?: ControlPolicy;
|
|
151
|
+
/**
|
|
152
|
+
* Single-table-inheritance variants share their base model's storage table:
|
|
153
|
+
* the variant's columns are materialised onto the base `ModelNode`, and this
|
|
154
|
+
* model contributes a domain model but no storage table of its own. When set,
|
|
155
|
+
* the assembler builds the domain model but skips creating a (shadow) storage
|
|
156
|
+
* table and a root for this model — the base owns both.
|
|
157
|
+
*/
|
|
158
|
+
readonly sharesBaseTable?: boolean;
|
|
159
|
+
}
|
|
160
|
+
interface ContractDefinition {
|
|
161
|
+
readonly target: TargetPackRef<'sql', string>;
|
|
162
|
+
readonly defaultControlPolicy?: ControlPolicy;
|
|
163
|
+
readonly extensionPacks?: Record<string, ExtensionPackRef<'sql', string>>;
|
|
164
|
+
readonly storageHash?: string;
|
|
165
|
+
readonly foreignKeyDefaults?: ForeignKeyDefaultsState;
|
|
166
|
+
readonly storageTypes?: Record<string, StorageTypeInstance>;
|
|
167
|
+
/**
|
|
168
|
+
* Declared namespace coordinates for this contract — populates
|
|
169
|
+
* `SqlStorage.namespaces` together with `createNamespace`.
|
|
170
|
+
*/
|
|
171
|
+
readonly namespaces?: readonly string[];
|
|
172
|
+
/** Target-supplied factory that materialises a `SqlNamespaceBase` concretion for a declared namespace coordinate. */
|
|
173
|
+
readonly createNamespace: (input: SqlNamespaceInput) => SqlNamespaceBase;
|
|
174
|
+
readonly models: readonly ModelNode[];
|
|
175
|
+
readonly valueObjects?: readonly ValueObjectNode[];
|
|
176
|
+
/**
|
|
177
|
+
* Domain enum handles authored via `enumType()`. Each entry lowers to a
|
|
178
|
+
* domain `enum` entry and a storage `valueSet` entry in the contract's
|
|
179
|
+
* default namespace.
|
|
180
|
+
*/
|
|
181
|
+
readonly enums?: Record<string, EnumTypeHandle>;
|
|
182
|
+
/**
|
|
183
|
+
* Author-declared pack entities, keyed by namespace then entity kind then
|
|
184
|
+
* name. Each entity lowers into `storage.namespaces[ns].entries.<kind>`;
|
|
185
|
+
* when the registered entity-type descriptor's factory output implements
|
|
186
|
+
* the `SqlValueSetDerivingEntityTypeOutput.deriveValueSet` hook, the
|
|
187
|
+
* derived value-set also folds into `entries.valueSet`, mirroring how
|
|
188
|
+
* `enums` flows there.
|
|
189
|
+
*/
|
|
190
|
+
readonly packEntities?: PackEntitiesInput;
|
|
81
191
|
}
|
|
82
|
-
/**
|
|
83
|
-
* A codec typemap: codecId → `{ input, output }`, the same shape the query
|
|
84
|
-
* lanes consume (e.g. `{ 'pg/text@1': { input: string }, 'pg/int4@1': { input: number } }`).
|
|
85
|
-
* The bound `enumType` wrappers supply the target pack's typemap; the core
|
|
86
|
-
* defaults to an empty map (no codec is known), so member values stay
|
|
87
|
-
* unconstrained.
|
|
88
|
-
*/
|
|
89
|
-
type CodecTypeMap = Record<string, {
|
|
90
|
-
readonly input?: unknown;
|
|
91
|
-
}>;
|
|
92
|
-
/**
|
|
93
|
-
* The application input type the codec dictates for an enum's member values:
|
|
94
|
-
* looks `Codec['codecId']` up in the supplied codec typemap. When the codecId
|
|
95
|
-
* isn't in the map (the core's empty default, or an unknown codec) the input is
|
|
96
|
-
* unconstrained, so any member-value literal is accepted and inferred verbatim.
|
|
97
|
-
*/
|
|
98
|
-
type CodecInput<CodecTypes extends CodecTypeMap, Codec extends {
|
|
99
|
-
readonly codecId: string;
|
|
100
|
-
}> = Codec['codecId'] extends keyof CodecTypes ? CodecTypes[Codec['codecId']] extends {
|
|
101
|
-
readonly input: infer In;
|
|
102
|
-
} ? In : unknown : unknown;
|
|
103
|
-
/**
|
|
104
|
-
* Declare a domain enum for use in TS-authoring contracts.
|
|
105
|
-
*
|
|
106
|
-
* - The codec is an explicit required argument — the `codecId` and
|
|
107
|
-
* `nativeType` are taken from the passed `ColumnTypeDescriptor` (e.g.
|
|
108
|
-
* `{ codecId: 'pg/text@1', nativeType: 'text' }` from a field preset
|
|
109
|
-
* output or a direct inline object).
|
|
110
|
-
* - `const` generics on the members spread preserve the ordered literal
|
|
111
|
-
* value tuple so `Role.values` is `readonly ['user','admin']`, not
|
|
112
|
-
* `string[]`.
|
|
113
|
-
* - Well-formedness assertions at construction: non-empty member list;
|
|
114
|
-
* unique names; unique values.
|
|
115
|
-
*
|
|
116
|
-
* The returned handle wires into `field.namedType(handle)` to set
|
|
117
|
-
* `valueSet` refs on both the domain field and the storage column.
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* ```ts
|
|
121
|
-
* const Role = enumType('Role', { codecId: 'pg/text@1', nativeType: 'text' },
|
|
122
|
-
* member('User', 'user'),
|
|
123
|
-
* member('Admin', 'admin'),
|
|
124
|
-
* );
|
|
125
|
-
* // Role.values → readonly ['user', 'admin']
|
|
126
|
-
* // Role.members.User → 'user'
|
|
127
|
-
* ```
|
|
128
|
-
*/
|
|
129
|
-
declare function enumType<CodecTypes extends CodecTypeMap = Record<string, never>, const Name extends string = string, const Codec extends Pick<ColumnTypeDescriptor, 'codecId' | 'nativeType'> = Pick<ColumnTypeDescriptor, 'codecId' | 'nativeType'>, const Members extends readonly [EnumMember<string, CodecInput<CodecTypes, Codec>>, ...EnumMember<string, CodecInput<CodecTypes, Codec>>[]] = readonly [EnumMember<string, CodecInput<CodecTypes, Codec>>]>(name: Name, codec: Codec, ...members: Members): EnumTypeHandle<Name, MembersToValues<[...Members]>, MembersToNames<[...Members]>, MembersAccessorMap<[...Members]>>;
|
|
130
|
-
declare function enumType(name: string, codec: Pick<ColumnTypeDescriptor, 'codecId' | 'nativeType'>, ...members: EnumMember<string, unknown>[]): EnumTypeHandle;
|
|
131
|
-
/**
|
|
132
|
-
* The signature of an `enumType` whose codec typemap is already bound — the
|
|
133
|
-
* shape a target-bound wrapper (e.g. `@prisma-next/postgres/contract-builder`)
|
|
134
|
-
* exposes. The member values are constrained to the codec's input type drawn
|
|
135
|
-
* from `CodecTypes` (so a `pg/text@1` codec rejects numeric members, etc.),
|
|
136
|
-
* while `Name`, `Codec`, and the member tuple still infer from the call.
|
|
137
|
-
*/
|
|
138
|
-
type BoundEnumType<CodecTypes extends CodecTypeMap> = <const Name extends string, const Codec extends Pick<ColumnTypeDescriptor, 'codecId' | 'nativeType'>, const Members extends readonly [EnumMember<string, CodecInput<CodecTypes, Codec>>, ...EnumMember<string, CodecInput<CodecTypes, Codec>>[]]>(name: Name, codec: Codec, ...members: Members) => EnumTypeHandle<Name, MembersToValues<[...Members]>, MembersToNames<[...Members]>, MembersAccessorMap<[...Members]>>;
|
|
139
|
-
/**
|
|
140
|
-
* Bind `enumType` to a target's codec typemap. The returned function is the
|
|
141
|
-
* same runtime `enumType`, retyped so member values are constrained to the
|
|
142
|
-
* codec's input type. Target packages call this with their pack's
|
|
143
|
-
* `ExtractCodecTypesFromPack<Pack>` to expose a codec-aware `enumType`.
|
|
144
|
-
*/
|
|
145
|
-
declare function bindEnumType<CodecTypes extends CodecTypeMap>(): BoundEnumType<CodecTypes>;
|
|
146
192
|
//#endregion
|
|
147
193
|
//#region src/contract-dsl.d.ts
|
|
148
194
|
type NamingStrategy = 'identity' | 'snake_case';
|
|
@@ -154,7 +200,7 @@ type NamedStorageTypeRef = string | StorageTypeInstance | EnumTypeHandle;
|
|
|
154
200
|
type NamedConstraintNameSpec<Name extends string = string> = {
|
|
155
201
|
readonly name: Name;
|
|
156
202
|
};
|
|
157
|
-
type ScalarFieldState<CodecId extends string = string, TypeRef extends NamedStorageTypeRef | undefined = undefined, Nullable extends boolean = boolean, ColumnName extends string | undefined = string | undefined, IdSpec extends NamedConstraintSpec | undefined = undefined, UniqueSpec extends NamedConstraintSpec | undefined = undefined> = {
|
|
203
|
+
type ScalarFieldState<CodecId extends string = string, TypeRef extends NamedStorageTypeRef | undefined = undefined, Nullable extends boolean = boolean, ColumnName extends string | undefined = string | undefined, IdSpec extends NamedConstraintSpec | undefined = undefined, UniqueSpec extends NamedConstraintSpec | undefined = undefined, Many extends boolean = false> = {
|
|
158
204
|
readonly kind: 'scalar';
|
|
159
205
|
readonly descriptor?: (ColumnTypeDescriptor & {
|
|
160
206
|
readonly codecId: CodecId;
|
|
@@ -164,6 +210,7 @@ type ScalarFieldState<CodecId extends string = string, TypeRef extends NamedStor
|
|
|
164
210
|
readonly columnName?: ColumnName | undefined;
|
|
165
211
|
readonly default?: ColumnDefault | undefined;
|
|
166
212
|
readonly executionDefaults?: ExecutionMutationDefaultPhases | undefined;
|
|
213
|
+
readonly many?: Many extends true ? true : undefined;
|
|
167
214
|
} & (IdSpec extends NamedConstraintSpec ? {
|
|
168
215
|
readonly id: IdSpec;
|
|
169
216
|
} : {
|
|
@@ -183,11 +230,12 @@ type AnyScalarFieldState = {
|
|
|
183
230
|
readonly columnName?: string | undefined;
|
|
184
231
|
readonly default?: ColumnDefault | undefined;
|
|
185
232
|
readonly executionDefaults?: ExecutionMutationDefaultPhases | undefined;
|
|
233
|
+
readonly many?: boolean | undefined;
|
|
186
234
|
readonly id?: NamedConstraintSpec | undefined;
|
|
187
235
|
readonly unique?: NamedConstraintSpec | undefined;
|
|
188
236
|
};
|
|
189
|
-
type HasNamedConstraintId<State extends AnyScalarFieldState> = State extends ScalarFieldState<string, NamedStorageTypeRef | undefined, boolean, string | undefined, infer IdSpec, NamedConstraintSpec | undefined> ? IdSpec extends NamedConstraintSpec ? true : false : false;
|
|
190
|
-
type HasNamedConstraintUnique<State extends AnyScalarFieldState> = State extends ScalarFieldState<string, NamedStorageTypeRef | undefined, boolean, string | undefined, NamedConstraintSpec | undefined, infer UniqueSpec> ? UniqueSpec extends NamedConstraintSpec ? true : false : false;
|
|
237
|
+
type HasNamedConstraintId<State extends AnyScalarFieldState> = State extends ScalarFieldState<string, NamedStorageTypeRef | undefined, boolean, string | undefined, infer IdSpec, NamedConstraintSpec | undefined, boolean> ? IdSpec extends NamedConstraintSpec ? true : false : false;
|
|
238
|
+
type HasNamedConstraintUnique<State extends AnyScalarFieldState> = State extends ScalarFieldState<string, NamedStorageTypeRef | undefined, boolean, string | undefined, NamedConstraintSpec | undefined, infer UniqueSpec, boolean> ? UniqueSpec extends NamedConstraintSpec ? true : false : false;
|
|
191
239
|
type FieldSqlSpecForState<State extends AnyScalarFieldState> = {
|
|
192
240
|
readonly column?: string;
|
|
193
241
|
} & (HasNamedConstraintId<State> extends true ? {
|
|
@@ -195,7 +243,7 @@ type FieldSqlSpecForState<State extends AnyScalarFieldState> = {
|
|
|
195
243
|
} : Record<never, never>) & (HasNamedConstraintUnique<State> extends true ? {
|
|
196
244
|
readonly unique?: NamedConstraintNameSpec;
|
|
197
245
|
} : Record<never, never>);
|
|
198
|
-
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 {
|
|
246
|
+
type ApplyFieldSqlSpec<State extends AnyScalarFieldState, Spec extends FieldSqlSpecForState<State>> = State extends ScalarFieldState<infer CodecId, infer TypeRef, infer Nullable, infer ColumnName, infer IdSpec, infer UniqueSpec, infer Many> ? ScalarFieldState<CodecId, TypeRef, Nullable, Spec extends {
|
|
199
247
|
readonly column: infer NextColumn extends string;
|
|
200
248
|
} ? NextColumn : ColumnName, Spec extends {
|
|
201
249
|
readonly id: {
|
|
@@ -205,7 +253,7 @@ type ApplyFieldSqlSpec<State extends AnyScalarFieldState, Spec extends FieldSqlS
|
|
|
205
253
|
readonly unique: {
|
|
206
254
|
readonly name: infer UniqueName extends string;
|
|
207
255
|
};
|
|
208
|
-
} ? UniqueSpec extends NamedConstraintSpec ? NamedConstraintSpec<UniqueName> : UniqueSpec : UniqueSpec> :
|
|
256
|
+
} ? UniqueSpec extends NamedConstraintSpec ? NamedConstraintSpec<UniqueName> : UniqueSpec : UniqueSpec, Many> : AnyScalarFieldState;
|
|
209
257
|
type GeneratedFieldSpec = {
|
|
210
258
|
readonly type: ColumnTypeDescriptor;
|
|
211
259
|
readonly typeParams?: Record<string, unknown>;
|
|
@@ -222,12 +270,13 @@ declare class ScalarFieldBuilder<State extends AnyScalarFieldState = AnyScalarFi
|
|
|
222
270
|
* `TargetFieldRef.columnName` so FK target columns are resolved correctly.
|
|
223
271
|
*/
|
|
224
272
|
get physicalColumnName(): string | undefined;
|
|
225
|
-
optional(): ScalarFieldBuilder<State extends ScalarFieldState<infer CodecId, infer TypeRef, boolean, infer ColumnName, infer IdSpec, infer UniqueSpec> ? ScalarFieldState<CodecId, TypeRef, true, ColumnName, IdSpec, UniqueSpec> :
|
|
226
|
-
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> :
|
|
273
|
+
optional(): ScalarFieldBuilder<State extends ScalarFieldState<infer CodecId, infer TypeRef, boolean, infer ColumnName, infer IdSpec, infer UniqueSpec, infer Many> ? ScalarFieldState<CodecId, TypeRef, true, ColumnName, IdSpec, UniqueSpec, Many> : AnyScalarFieldState>;
|
|
274
|
+
column<ColumnName extends string>(name: ColumnName): ScalarFieldBuilder<State extends ScalarFieldState<infer CodecId, infer TypeRef, infer Nullable, string | undefined, infer IdSpec, infer UniqueSpec, infer Many> ? ScalarFieldState<CodecId, TypeRef, Nullable, ColumnName, IdSpec, UniqueSpec, Many> : AnyScalarFieldState>;
|
|
275
|
+
many(): ScalarFieldBuilder<State extends ScalarFieldState<infer CodecId, infer TypeRef, infer Nullable, infer ColumnName, infer IdSpec, infer UniqueSpec, boolean> ? ScalarFieldState<CodecId, TypeRef, Nullable, ColumnName, IdSpec, UniqueSpec, true> : AnyScalarFieldState>;
|
|
227
276
|
default(value: ColumnDefaultLiteralInputValue | ColumnDefault): ScalarFieldBuilder<State>;
|
|
228
277
|
defaultSql(expression: string): ScalarFieldBuilder<State>;
|
|
229
|
-
id<const Name extends string | undefined = undefined>(options?: NamedConstraintSpec<Name>): ScalarFieldBuilder<State extends ScalarFieldState<infer CodecId, infer TypeRef, infer Nullable, infer ColumnName, NamedConstraintSpec | undefined, infer UniqueSpec> ? ScalarFieldState<CodecId, TypeRef, Nullable, ColumnName, NamedConstraintSpec<Name>, UniqueSpec> :
|
|
230
|
-
unique<const Name extends string | undefined = undefined>(options?: NamedConstraintSpec<Name>): ScalarFieldBuilder<State extends ScalarFieldState<infer CodecId, infer TypeRef, infer Nullable, infer ColumnName, infer IdSpec, NamedConstraintSpec | undefined> ? ScalarFieldState<CodecId, TypeRef, Nullable, ColumnName, IdSpec, NamedConstraintSpec<Name
|
|
278
|
+
id<const Name extends string | undefined = undefined>(options?: NamedConstraintSpec<Name>): ScalarFieldBuilder<State extends ScalarFieldState<infer CodecId, infer TypeRef, infer Nullable, infer ColumnName, NamedConstraintSpec | undefined, infer UniqueSpec, infer Many> ? ScalarFieldState<CodecId, TypeRef, Nullable, ColumnName, NamedConstraintSpec<Name>, UniqueSpec, Many> : AnyScalarFieldState>;
|
|
279
|
+
unique<const Name extends string | undefined = undefined>(options?: NamedConstraintSpec<Name>): ScalarFieldBuilder<State extends ScalarFieldState<infer CodecId, infer TypeRef, infer Nullable, infer ColumnName, infer IdSpec, NamedConstraintSpec | undefined, infer Many> ? ScalarFieldState<CodecId, TypeRef, Nullable, ColumnName, IdSpec, NamedConstraintSpec<Name>, Many> : AnyScalarFieldState>;
|
|
231
280
|
sql<const Spec extends FieldSqlSpecForState<State>>(spec: Spec): ScalarFieldBuilder<ApplyFieldSqlSpec<State, Spec>>;
|
|
232
281
|
build(): State;
|
|
233
282
|
}
|
|
@@ -571,7 +620,7 @@ type ContractInput<Family extends FamilyPackRef<string> = FamilyPackRef<string>,
|
|
|
571
620
|
*/
|
|
572
621
|
readonly namespaces?: readonly string[];
|
|
573
622
|
/**
|
|
574
|
-
* Target-supplied factory that materialises a `
|
|
623
|
+
* Target-supplied factory that materialises a `SqlNamespaceBase` concretion
|
|
575
624
|
* for a declared namespace coordinate. The SQL family layer is
|
|
576
625
|
* target-agnostic and cannot import concretions like
|
|
577
626
|
* `PostgresSchema` or `SqliteUnboundDatabase`; the factory is the
|
|
@@ -583,14 +632,8 @@ type ContractInput<Family extends FamilyPackRef<string> = FamilyPackRef<string>,
|
|
|
583
632
|
* `StorageTable.namespaceId` referenced by a model, and the
|
|
584
633
|
* framework `UNBOUND_NAMESPACE_ID` sentinel (always present so the
|
|
585
634
|
* late-bound slot stays available regardless of authoring choices).
|
|
586
|
-
*
|
|
587
|
-
* When omitted, the family layer falls back to its placeholder
|
|
588
|
-
* `SqlUnboundNamespace` singleton for the unbound slot and rejects
|
|
589
|
-
* any non-unbound coordinate — single-namespace contracts authored
|
|
590
|
-
* before targets ship their factory stay byte-stable; multi-namespace
|
|
591
|
-
* contracts must pass the factory through.
|
|
592
635
|
*/
|
|
593
|
-
readonly createNamespace
|
|
636
|
+
readonly createNamespace: (input: SqlNamespaceInput) => SqlNamespaceBase;
|
|
594
637
|
readonly types?: Types;
|
|
595
638
|
readonly models?: Models;
|
|
596
639
|
readonly codecLookup?: CodecLookup;
|
|
@@ -600,6 +643,15 @@ type ContractInput<Family extends FamilyPackRef<string> = FamilyPackRef<string>,
|
|
|
600
643
|
* default namespace. Fields reference the enum via `field.namedType(handle)`.
|
|
601
644
|
*/
|
|
602
645
|
readonly enums?: Record<string, EnumTypeHandle>;
|
|
646
|
+
/**
|
|
647
|
+
* Author-declared pack entities, keyed by namespace id then entity kind
|
|
648
|
+
* then name — e.g. `{ auth: { native_enum: { AalLevel: <entity> } } }`.
|
|
649
|
+
* Each entity lowers into `storage.namespaces[ns].entries.<kind>`; when its
|
|
650
|
+
* registered entity-type descriptor derives a value-set, that also folds
|
|
651
|
+
* into `entries.valueSet`, mirroring how `enums` flows there. Generic on
|
|
652
|
+
* purpose — neither this type nor the assembler names a specific kind.
|
|
653
|
+
*/
|
|
654
|
+
readonly packEntities?: PackEntitiesInput;
|
|
603
655
|
};
|
|
604
656
|
declare function model<const ModelName extends string, Fields extends Record<string, ScalarFieldBuilder>, Relations extends Record<string, AnyRelationBuilder> = Record<never, never>>(modelName: ModelName, input: {
|
|
605
657
|
readonly fields: Fields;
|
|
@@ -727,10 +779,10 @@ type FieldHelpersFromNamespace<Namespace> = { readonly [K in keyof Namespace]: N
|
|
|
727
779
|
//#endregion
|
|
728
780
|
//#region src/contract-types.d.ts
|
|
729
781
|
type ExtractCodecTypesFromPack<P> = P extends {
|
|
730
|
-
__codecTypes?: infer C
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
}
|
|
782
|
+
__codecTypes?: infer C extends Record<string, {
|
|
783
|
+
output: unknown;
|
|
784
|
+
}>;
|
|
785
|
+
} ? C : Record<string, never>;
|
|
734
786
|
type MergeExtensionCodecTypes<Packs extends Record<string, unknown>> = UnionToIntersection<{ [K in keyof Packs]: ExtractCodecTypesFromPack<Packs[K]> }[keyof Packs]>;
|
|
735
787
|
type MergeExtensionCodecTypesSafe<Packs> = Packs extends Record<string, unknown> ? keyof Packs extends never ? Record<string, never> : MergeExtensionCodecTypes<Packs> : Record<string, never>;
|
|
736
788
|
type ExtractIndexTypesFromPack<P> = P extends {
|
|
@@ -813,6 +865,9 @@ type FieldTypeRefOf<FieldState> = Present<FieldState extends {
|
|
|
813
865
|
type FieldNullableOf<FieldState> = FieldState extends {
|
|
814
866
|
readonly nullable: infer Nullable extends boolean;
|
|
815
867
|
} ? Nullable : boolean;
|
|
868
|
+
type FieldManyOf<FieldState> = FieldState extends {
|
|
869
|
+
readonly many?: true;
|
|
870
|
+
} ? true : false;
|
|
816
871
|
type FieldColumnOverrideOf<FieldState> = Present<FieldState extends {
|
|
817
872
|
readonly columnName?: infer ColumnName;
|
|
818
873
|
} ? ColumnName : never>;
|
|
@@ -865,17 +920,19 @@ type AttributeIdName<Definition, ModelName extends ModelNames<Definition>> = Pre
|
|
|
865
920
|
} ? Name : never>;
|
|
866
921
|
type ModelIdFieldNames<Definition, ModelName extends ModelNames<Definition>> = [AttributeIdFieldNames<Definition, ModelName>] extends [undefined] ? InlineIdFieldNames<Definition, ModelName> : AttributeIdFieldNames<Definition, ModelName>;
|
|
867
922
|
type ModelIdName<Definition, ModelName extends ModelNames<Definition>> = [AttributeIdName<Definition, ModelName>] extends [never] ? Present<InlineIdName<Definition, ModelName>> : AttributeIdName<Definition, ModelName>;
|
|
868
|
-
type StorageColumn<CodecId extends string, Nullable extends boolean, NativeType extends string, TypeRef extends string | undefined = undefined, TypeParams extends Record<string, unknown> | undefined = undefined> = {
|
|
923
|
+
type StorageColumn<CodecId extends string, Nullable extends boolean, NativeType extends string, TypeRef extends string | undefined = undefined, TypeParams extends Record<string, unknown> | undefined = undefined, Many extends boolean = false> = {
|
|
869
924
|
readonly nativeType: NativeType;
|
|
870
925
|
readonly codecId: CodecId;
|
|
871
926
|
readonly nullable: Nullable;
|
|
872
927
|
readonly default?: ColumnDefault;
|
|
873
928
|
} & (TypeRef extends string ? {
|
|
874
929
|
readonly typeRef: TypeRef;
|
|
875
|
-
} : Record<
|
|
930
|
+
} : Record<never, never>) & (TypeParams extends Record<string, unknown> ? {
|
|
876
931
|
readonly typeParams: TypeParams;
|
|
877
|
-
} : Record<
|
|
878
|
-
|
|
932
|
+
} : Record<never, never>) & (Many extends true ? {
|
|
933
|
+
readonly many: true;
|
|
934
|
+
} : Record<never, never>);
|
|
935
|
+
type ModelStorageColumn<Definition, ModelName extends ModelNames<Definition>, FieldName extends string> = FieldName extends ModelFieldNames<Definition, ModelName> ? StorageColumn<DescriptorCodecId<ResolveFieldDescriptor<Definition, ModelFieldState<Definition, ModelName, FieldName>>>, FieldNullableOf<ModelFieldState<Definition, ModelName, FieldName>>, DescriptorNativeType<ResolveFieldDescriptor<Definition, ModelFieldState<Definition, ModelName, FieldName>>>, ResolveFieldColumnTypeRef<Definition, ModelFieldState<Definition, ModelName, FieldName>>, ResolveFieldColumnTypeParams<Definition, ModelFieldState<Definition, ModelName, FieldName>>, FieldManyOf<ModelFieldState<Definition, ModelName, FieldName>>> : never;
|
|
879
936
|
type BuiltModels<Definition> = { readonly [ModelName in ModelNames<Definition>]: {
|
|
880
937
|
readonly storage: {
|
|
881
938
|
readonly table: ModelTableName<Definition, ModelName>;
|
|
@@ -967,10 +1024,14 @@ type BuiltStorage<Definition> = {
|
|
|
967
1024
|
};
|
|
968
1025
|
} };
|
|
969
1026
|
};
|
|
1027
|
+
type StorageColumnManyOf<Col> = Col extends {
|
|
1028
|
+
readonly many: true;
|
|
1029
|
+
} ? true : false;
|
|
970
1030
|
type EnumValueUnion<FieldState> = [FieldTypeRefOf<FieldState>] extends [EnumTypeHandle<string, infer Values>] ? readonly unknown[] extends Values ? never : Values[number] : never;
|
|
971
|
-
type CodecChannelType<Definition, ModelName extends ModelNames<Definition>, FieldName extends ModelFieldNames<Definition, ModelName>, Channel extends 'output' | 'input'> = ModelStorageColumn<Definition, ModelName, FieldName>['codecId'] extends infer Id extends keyof CodecTypesFromDefinition<Definition> ? CodecTypesFromDefinition<Definition>[Id] extends { readonly [K in Channel]: infer T } ? T : unknown : unknown;
|
|
972
|
-
type FieldChannelType<Definition, ModelName extends ModelNames<Definition>, FieldName extends ModelFieldNames<Definition, ModelName>, Channel extends 'output' | 'input'> = ([EnumValueUnion<ModelFieldState<Definition, ModelName, FieldName>>] extends [never] ? CodecChannelType<Definition, ModelName, FieldName, Channel> : EnumValueUnion<ModelFieldState<Definition, ModelName, FieldName>>) | (FieldNullableOf<ModelFieldState<Definition, ModelName, FieldName>> extends true ? null : never);
|
|
1031
|
+
type CodecChannelType<Definition, ModelName extends ModelNames<Definition>, FieldName extends ModelFieldNames<Definition, ModelName>, Channel extends 'output' | 'input'> = ModelStorageColumn<Definition, ModelName, FieldName>['codecId'] extends infer Id extends keyof CodecTypesFromDefinition<Definition> ? CodecTypesFromDefinition<Definition>[Id] extends { readonly [K in Channel]: infer T } ? StorageColumnManyOf<ModelStorageColumn<Definition, ModelName, FieldName>> extends true ? ReadonlyArray<T> : T : unknown : unknown;
|
|
1032
|
+
type FieldChannelType<Definition, ModelName extends ModelNames<Definition>, FieldName extends ModelFieldNames<Definition, ModelName>, Channel extends 'output' | 'input'> = ([EnumValueUnion<ModelFieldState<Definition, ModelName, FieldName>>] extends [never] ? CodecChannelType<Definition, ModelName, FieldName, Channel> : StorageColumnManyOf<ModelStorageColumn<Definition, ModelName, FieldName>> extends true ? ReadonlyArray<EnumValueUnion<ModelFieldState<Definition, ModelName, FieldName>>> : EnumValueUnion<ModelFieldState<Definition, ModelName, FieldName>>) | (FieldNullableOf<ModelFieldState<Definition, ModelName, FieldName>> extends true ? null : never);
|
|
973
1033
|
type FieldChannelTypes<Definition, Channel extends 'output' | 'input'> = { readonly [Ns in DefaultStorageNamespaceId<Definition>]: { readonly [ModelName in ModelNames<Definition>]: { readonly [FieldName in ModelFieldNames<Definition, ModelName>]: FieldChannelType<Definition, ModelName, FieldName, Channel> } } };
|
|
1034
|
+
type StorageColumnChannelTypes<Definition, Channel extends 'output' | 'input'> = { readonly [Ns in DefaultStorageNamespaceId<Definition>]: { readonly [ModelName in ModelNames<Definition> as BuiltModelTableName<Definition, ModelName>]: { readonly [FieldName in ModelFieldNames<Definition, ModelName> as BuiltModelColumnMappings<Definition, ModelName>[FieldName]['column']]: FieldChannelType<Definition, ModelName, FieldName, Channel> } } };
|
|
974
1035
|
type SqlContractResult<Definition> = ContractWithTypeMaps<Omit<Contract<BuiltStorage<Definition>>, 'domain'> & {
|
|
975
1036
|
readonly target: DefinitionTargetId<Definition>;
|
|
976
1037
|
readonly targetFamily: 'sql';
|
|
@@ -982,7 +1043,7 @@ type SqlContractResult<Definition> = ContractWithTypeMaps<Omit<Contract<BuiltSto
|
|
|
982
1043
|
readonly extensionPacks: keyof DefinitionExtensionPacks<Definition> extends never ? Record<string, never> : DefinitionExtensionPacks<Definition>;
|
|
983
1044
|
readonly capabilities: DerivedCapabilities<Definition>;
|
|
984
1045
|
readonly enumAccessors: BuiltEnumAccessors<Definition>;
|
|
985
|
-
}, TypeMaps<CodecTypesFromDefinition<Definition>, Record<string, never>, FieldChannelTypes<Definition, 'output'>, FieldChannelTypes<Definition, 'input'>>>;
|
|
1046
|
+
}, TypeMaps<CodecTypesFromDefinition<Definition>, Record<string, never>, FieldChannelTypes<Definition, 'output'>, FieldChannelTypes<Definition, 'input'>, StorageColumnChannelTypes<Definition, 'output'>, StorageColumnChannelTypes<Definition, 'input'>>>;
|
|
986
1047
|
//#endregion
|
|
987
1048
|
//#region src/composed-authoring-helpers.d.ts
|
|
988
1049
|
type ExtractTypeNamespaceFromPack<Pack> = ExtractAuthoringNamespaceFromPack<Pack, 'type', Record<never, never>>;
|
|
@@ -1030,169 +1091,6 @@ type ComposedAuthoringHelpers<Family extends FamilyPackRef<string>, Target exten
|
|
|
1030
1091
|
readonly type: TypeHelpersFromNamespace<ExtractTypeNamespaceFromPack<Family> & ExtractTypeNamespaceFromPack<Target> & MergeExtensionTypeNamespaces<ExtensionPacks>>;
|
|
1031
1092
|
};
|
|
1032
1093
|
//#endregion
|
|
1033
|
-
//#region src/contract-definition.d.ts
|
|
1034
|
-
interface FieldNode {
|
|
1035
|
-
readonly fieldName: string;
|
|
1036
|
-
readonly columnName: string;
|
|
1037
|
-
readonly descriptor: ColumnTypeDescriptor;
|
|
1038
|
-
readonly nullable: boolean;
|
|
1039
|
-
readonly default?: ColumnDefault;
|
|
1040
|
-
readonly executionDefaults?: ExecutionMutationDefaultPhases$1;
|
|
1041
|
-
readonly many?: boolean;
|
|
1042
|
-
/** Present when the field was authored with `field.namedType(enumHandle)`. */
|
|
1043
|
-
readonly enumTypeHandle?: EnumTypeHandle;
|
|
1044
|
-
}
|
|
1045
|
-
interface PrimaryKeyNode {
|
|
1046
|
-
readonly columns: readonly string[];
|
|
1047
|
-
readonly name?: string;
|
|
1048
|
-
}
|
|
1049
|
-
interface UniqueConstraintNode {
|
|
1050
|
-
readonly columns: readonly string[];
|
|
1051
|
-
readonly name?: string;
|
|
1052
|
-
}
|
|
1053
|
-
interface IndexNode {
|
|
1054
|
-
readonly columns: readonly string[];
|
|
1055
|
-
readonly name?: string;
|
|
1056
|
-
readonly type?: string;
|
|
1057
|
-
readonly options?: Record<string, unknown>;
|
|
1058
|
-
}
|
|
1059
|
-
interface ForeignKeyNode {
|
|
1060
|
-
readonly columns: readonly string[];
|
|
1061
|
-
readonly references: {
|
|
1062
|
-
readonly model: string;
|
|
1063
|
-
readonly table: string;
|
|
1064
|
-
readonly columns: readonly string[];
|
|
1065
|
-
/**
|
|
1066
|
-
* Namespace coordinate of the referenced table. When omitted the
|
|
1067
|
-
* assembler resolves the coordinate from the referenced model node's
|
|
1068
|
-
* own `namespaceId`; the field exists so authoring paths that already
|
|
1069
|
-
* know the target namespace can stamp it explicitly.
|
|
1070
|
-
*/
|
|
1071
|
-
readonly namespaceId?: string;
|
|
1072
|
-
/**
|
|
1073
|
-
* Contract-space identity of the referenced table. When present, the
|
|
1074
|
-
* table lives in a different contract space (identified by this value)
|
|
1075
|
-
* rather than the current contract. Absent for local FKs.
|
|
1076
|
-
*/
|
|
1077
|
-
readonly spaceId?: string;
|
|
1078
|
-
};
|
|
1079
|
-
readonly name?: string;
|
|
1080
|
-
readonly onDelete?: ReferentialAction;
|
|
1081
|
-
readonly onUpdate?: ReferentialAction;
|
|
1082
|
-
readonly constraint?: boolean;
|
|
1083
|
-
readonly index?: boolean;
|
|
1084
|
-
}
|
|
1085
|
-
interface RelationNode {
|
|
1086
|
-
readonly fieldName: string;
|
|
1087
|
-
readonly toModel: string;
|
|
1088
|
-
readonly toTable: string;
|
|
1089
|
-
/**
|
|
1090
|
-
* Namespace coordinate of the related model. When omitted the assembler
|
|
1091
|
-
* resolves the coordinate from the referenced model node's own
|
|
1092
|
-
* `namespaceId`; the field exists so authoring paths that already know the
|
|
1093
|
-
* target namespace can stamp it explicitly — required to disambiguate a
|
|
1094
|
-
* relation to a model whose bare name also exists in another namespace.
|
|
1095
|
-
*/
|
|
1096
|
-
readonly toNamespaceId?: string;
|
|
1097
|
-
readonly cardinality: '1:1' | '1:N' | 'N:1' | 'N:M';
|
|
1098
|
-
/**
|
|
1099
|
-
* Contract-space identity of the related model. When present, the
|
|
1100
|
-
* related model lives in a different contract space. Absent for local
|
|
1101
|
-
* (same-space) relations.
|
|
1102
|
-
*/
|
|
1103
|
-
readonly spaceId?: string;
|
|
1104
|
-
/**
|
|
1105
|
-
* Namespace coordinate of the related model in the foreign space.
|
|
1106
|
-
* Only set when `spaceId` is present.
|
|
1107
|
-
*/
|
|
1108
|
-
readonly namespaceId?: string;
|
|
1109
|
-
readonly on: {
|
|
1110
|
-
readonly parentTable: string;
|
|
1111
|
-
readonly parentColumns: readonly string[];
|
|
1112
|
-
readonly childTable: string;
|
|
1113
|
-
readonly childColumns: readonly string[];
|
|
1114
|
-
};
|
|
1115
|
-
readonly through?: {
|
|
1116
|
-
readonly table: string;
|
|
1117
|
-
/**
|
|
1118
|
-
* Namespace the junction table lives in. Set from the junction model's
|
|
1119
|
-
* declared namespace at lowering time; junction table names are unique per
|
|
1120
|
-
* namespace, not globally, so this disambiguates a junction whose bare table
|
|
1121
|
-
* name also exists in another namespace. Omitted for a junction in the
|
|
1122
|
-
* default namespace (resolved to the target's default at build time).
|
|
1123
|
-
*/
|
|
1124
|
-
readonly namespaceId?: string;
|
|
1125
|
-
readonly parentColumns: readonly string[];
|
|
1126
|
-
readonly childColumns: readonly string[];
|
|
1127
|
-
};
|
|
1128
|
-
}
|
|
1129
|
-
interface ValueObjectFieldNode {
|
|
1130
|
-
readonly fieldName: string;
|
|
1131
|
-
readonly columnName: string;
|
|
1132
|
-
readonly valueObjectName: string;
|
|
1133
|
-
readonly nullable: boolean;
|
|
1134
|
-
readonly default?: ColumnDefault;
|
|
1135
|
-
readonly executionDefaults?: ExecutionMutationDefaultPhases$1;
|
|
1136
|
-
readonly many?: boolean;
|
|
1137
|
-
}
|
|
1138
|
-
interface ValueObjectNode {
|
|
1139
|
-
readonly name: string;
|
|
1140
|
-
readonly fields: readonly (FieldNode | ValueObjectFieldNode)[];
|
|
1141
|
-
}
|
|
1142
|
-
interface ModelNode {
|
|
1143
|
-
readonly modelName: string;
|
|
1144
|
-
readonly tableName: string;
|
|
1145
|
-
/**
|
|
1146
|
-
* Resolved namespace coordinate for this model — the key into the
|
|
1147
|
-
* parent contract's `SqlStorage.namespaces` map. Omitting the field
|
|
1148
|
-
* (or setting it to the framework's `UNBOUND_NAMESPACE_ID` sentinel)
|
|
1149
|
-
* selects the late-bound slot, which renders as unqualified DDL.
|
|
1150
|
-
*
|
|
1151
|
-
* Populated by per-target PSL interpreters from the resolved
|
|
1152
|
-
* `namespace { … }` AST bucket; the TS builder also sets it from the
|
|
1153
|
-
* per-model `namespace` field once that authoring surface lands.
|
|
1154
|
-
*/
|
|
1155
|
-
readonly namespaceId?: string;
|
|
1156
|
-
readonly fields: readonly (FieldNode | ValueObjectFieldNode)[];
|
|
1157
|
-
readonly id?: PrimaryKeyNode;
|
|
1158
|
-
readonly uniques?: readonly UniqueConstraintNode[];
|
|
1159
|
-
readonly indexes?: readonly IndexNode[];
|
|
1160
|
-
readonly foreignKeys?: readonly ForeignKeyNode[];
|
|
1161
|
-
readonly relations?: readonly RelationNode[];
|
|
1162
|
-
readonly control?: ControlPolicy;
|
|
1163
|
-
/**
|
|
1164
|
-
* Single-table-inheritance variants share their base model's storage table:
|
|
1165
|
-
* the variant's columns are materialised onto the base `ModelNode`, and this
|
|
1166
|
-
* model contributes a domain model but no storage table of its own. When set,
|
|
1167
|
-
* the assembler builds the domain model but skips creating a (shadow) storage
|
|
1168
|
-
* table and a root for this model — the base owns both.
|
|
1169
|
-
*/
|
|
1170
|
-
readonly sharesBaseTable?: boolean;
|
|
1171
|
-
}
|
|
1172
|
-
interface ContractDefinition {
|
|
1173
|
-
readonly target: TargetPackRef<'sql', string>;
|
|
1174
|
-
readonly defaultControlPolicy?: ControlPolicy;
|
|
1175
|
-
readonly extensionPacks?: Record<string, ExtensionPackRef<'sql', string>>;
|
|
1176
|
-
readonly storageHash?: string;
|
|
1177
|
-
readonly foreignKeyDefaults?: ForeignKeyDefaultsState;
|
|
1178
|
-
readonly storageTypes?: Record<string, StorageTypeInstance>;
|
|
1179
|
-
/**
|
|
1180
|
-
* Declared namespace coordinates for this contract — populates
|
|
1181
|
-
* `SqlStorage.namespaces` together with `createNamespace`.
|
|
1182
|
-
*/
|
|
1183
|
-
readonly namespaces?: readonly string[];
|
|
1184
|
-
/** Target-supplied factory that materialises a `Namespace` concretion for a declared namespace coordinate. */
|
|
1185
|
-
readonly createNamespace?: (input: SqlNamespaceTablesInput) => Namespace;
|
|
1186
|
-
readonly models: readonly ModelNode[];
|
|
1187
|
-
readonly valueObjects?: readonly ValueObjectNode[];
|
|
1188
|
-
/**
|
|
1189
|
-
* Domain enum handles authored via `enumType()`. Each entry lowers to a
|
|
1190
|
-
* domain `enum` entry and a storage `valueSet` entry in the contract's
|
|
1191
|
-
* default namespace.
|
|
1192
|
-
*/
|
|
1193
|
-
readonly enums?: Record<string, EnumTypeHandle>;
|
|
1194
|
-
}
|
|
1195
|
-
//#endregion
|
|
1196
1094
|
//#region src/build-contract.d.ts
|
|
1197
1095
|
declare function buildSqlContractFromDefinition(definition: ContractDefinition, codecLookup?: CodecLookup): Contract<SqlStorage>;
|
|
1198
1096
|
//#endregion
|
|
@@ -1218,11 +1116,12 @@ type ContractDefinition$1<Family extends FamilyPackRef<string>, Target extends T
|
|
|
1218
1116
|
readonly foreignKeyDefaults?: ForeignKeyDefaults;
|
|
1219
1117
|
readonly defaultControlPolicy?: ControlPolicy;
|
|
1220
1118
|
readonly namespaces?: Namespaces;
|
|
1221
|
-
readonly createNamespace
|
|
1119
|
+
readonly createNamespace: (input: SqlNamespaceInput) => SqlNamespaceBase;
|
|
1222
1120
|
readonly types?: Types;
|
|
1223
1121
|
readonly models?: Models;
|
|
1224
1122
|
readonly codecLookup?: CodecLookup;
|
|
1225
1123
|
readonly enums?: Enums;
|
|
1124
|
+
readonly packEntities?: PackEntitiesInput;
|
|
1226
1125
|
};
|
|
1227
1126
|
type ContractScaffold<Family extends FamilyPackRef<string>, Target extends TargetPackRef<'sql', string>, ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined, Naming extends ContractInput['naming'] | undefined, StorageHash extends string | undefined, ForeignKeyDefaults extends ForeignKeyDefaultsState | undefined, Namespaces extends readonly string[] | undefined = undefined, Enums extends Record<string, EnumTypeHandle> = Record<string, EnumTypeHandle>> = {
|
|
1228
1127
|
readonly family: Family;
|
|
@@ -1233,16 +1132,18 @@ type ContractScaffold<Family extends FamilyPackRef<string>, Target extends Targe
|
|
|
1233
1132
|
readonly foreignKeyDefaults?: ForeignKeyDefaults;
|
|
1234
1133
|
readonly defaultControlPolicy?: ControlPolicy;
|
|
1235
1134
|
readonly namespaces?: Namespaces;
|
|
1236
|
-
readonly createNamespace
|
|
1135
|
+
readonly createNamespace: (input: SqlNamespaceInput) => SqlNamespaceBase;
|
|
1237
1136
|
readonly types?: never;
|
|
1238
1137
|
readonly models?: never;
|
|
1239
1138
|
readonly codecLookup?: CodecLookup;
|
|
1240
1139
|
readonly enums?: Enums;
|
|
1140
|
+
readonly packEntities?: PackEntitiesInput;
|
|
1241
1141
|
};
|
|
1242
1142
|
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, Enums extends Record<string, EnumTypeHandle> = Record<string, EnumTypeHandle>> = (helpers: ComposedAuthoringHelpers<Family, Target, ExtensionPacks>) => {
|
|
1243
1143
|
readonly types?: Types;
|
|
1244
1144
|
readonly models?: Models;
|
|
1245
1145
|
readonly enums?: Enums;
|
|
1146
|
+
readonly packEntities?: PackEntitiesInput;
|
|
1246
1147
|
};
|
|
1247
1148
|
type BoundDefinitionInput<Types extends Record<string, StorageTypeInstance> = Record<never, never>, Models extends Record<string, ModelLike> = Record<never, never>, ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined = undefined, Naming extends ContractInput['naming'] | undefined = undefined, StorageHash extends string | undefined = undefined, ForeignKeyDefaults extends ForeignKeyDefaultsState | undefined = undefined, Namespaces extends readonly string[] | undefined = undefined> = {
|
|
1248
1149
|
readonly extensionPacks?: ExtensionPacks;
|
|
@@ -1251,11 +1152,12 @@ type BoundDefinitionInput<Types extends Record<string, StorageTypeInstance> = Re
|
|
|
1251
1152
|
readonly foreignKeyDefaults?: ForeignKeyDefaults;
|
|
1252
1153
|
readonly defaultControlPolicy?: ControlPolicy;
|
|
1253
1154
|
readonly namespaces?: Namespaces;
|
|
1254
|
-
readonly createNamespace
|
|
1155
|
+
readonly createNamespace: (input: SqlNamespaceInput) => SqlNamespaceBase;
|
|
1255
1156
|
readonly types?: Types;
|
|
1256
1157
|
readonly models?: Models;
|
|
1257
1158
|
readonly codecLookup?: CodecLookup;
|
|
1258
1159
|
readonly enums?: Record<string, EnumTypeHandle>;
|
|
1160
|
+
readonly packEntities?: PackEntitiesInput;
|
|
1259
1161
|
};
|
|
1260
1162
|
type LiteralEnums<E extends Record<string, EnumTypeHandle>> = string extends keyof E ? Record<never, never> : E;
|
|
1261
1163
|
type MergeEnums<ScaffoldEnums extends Record<string, EnumTypeHandle>, FactoryEnums extends Record<string, EnumTypeHandle>> = LiteralEnums<ScaffoldEnums> & LiteralEnums<FactoryEnums>;
|
|
@@ -1279,6 +1181,7 @@ declare function buildBoundContract<const F extends FamilyPackRef<string>, const
|
|
|
1279
1181
|
readonly types?: Record<string, StorageTypeInstance>;
|
|
1280
1182
|
readonly models?: Record<string, ModelLike>;
|
|
1281
1183
|
readonly enums?: Record<string, EnumTypeHandle>;
|
|
1184
|
+
readonly packEntities?: PackEntitiesInput;
|
|
1282
1185
|
}>(family: F, target: T, definition: Definition, factory: (helpers: ComposedAuthoringHelpers<F, T, NonNullable<Definition['extensionPacks']>>) => Built): SqlContractResult<WithFamilyTarget<Definition & Built, F, T>>;
|
|
1283
1186
|
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 Naming extends ContractInput['naming'] | undefined = undefined, const StorageHash extends string | undefined = undefined, const ForeignKeyDefaults extends ForeignKeyDefaultsState | undefined = undefined, const Namespaces extends readonly string[] | undefined = undefined, const Enums extends Record<string, EnumTypeHandle> = Record<string, EnumTypeHandle>>(definition: ContractDefinition$1<Family, Target, Types, Models, ExtensionPacks, Naming, StorageHash, ForeignKeyDefaults, Namespaces, Enums>): SqlContractResult<ContractDefinition$1<Family, Target, Types, Models, ExtensionPacks, Naming, StorageHash, ForeignKeyDefaults, Namespaces, Enums>>;
|
|
1284
1187
|
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 Naming extends ContractInput['naming'] | undefined = undefined, const StorageHash extends string | undefined = undefined, const ForeignKeyDefaults extends ForeignKeyDefaultsState | undefined = undefined, const Namespaces extends readonly string[] | undefined = undefined, const ScaffoldEnums extends Record<string, EnumTypeHandle> = Record<string, EnumTypeHandle>, const FactoryEnums extends Record<string, EnumTypeHandle> = Record<string, EnumTypeHandle>>(definition: ContractScaffold<Family, Target, ExtensionPacks, Naming, StorageHash, ForeignKeyDefaults, Namespaces, ScaffoldEnums>, factory: ContractFactory<Family, Target, Types, Models, ExtensionPacks, FactoryEnums>): SqlContractResult<ContractDefinition$1<Family, Target, Types, Models, ExtensionPacks, Naming, StorageHash, ForeignKeyDefaults, Namespaces, MergeEnums<ScaffoldEnums, FactoryEnums>>>;
|