@prisma-next/sql-contract-ts 0.14.0-dev.7 → 0.14.0-dev.71

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.
@@ -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/enum-type.d.ts
10
+ //#region src/contract-definition.d.ts
11
11
  /**
12
- * A single enum member produced by `member()`. The `Name` and `Value` generics
13
- * are preserved as literal types so `enumType()` can carry the ordered value
14
- * tuple in its return type. `Value` is whatever the codec dictates — its type
15
- * is constrained at `enumType` against the codec's input type, not here.
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
- interface EnumMember<Name extends string, Value> {
18
- readonly name: Name;
19
- readonly value: Value;
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
- * Declare an enum member. The `value` defaults to `name` when omitted. The
23
- * value is an unconstrained literal here; `enumType` constrains it against the
24
- * codec's input type. Both generics are preserved as literals so downstream
25
- * `enumType` carries the value union in its type; the value is serialized to its
26
- * codec string form only at lowering.
27
- */
28
- declare function member<const Name extends string>(name: Name): EnumMember<Name, Name>;
29
- declare function member<const Name extends string, const Value>(name: Name, value: Value): EnumMember<Name, Value>;
30
- type MembersToValues<Members extends readonly EnumMember<string, unknown>[]> = { readonly [K in keyof Members]: Members[K] extends EnumMember<string, infer V> ? V : never };
31
- type MembersToNames<Members extends readonly EnumMember<string, unknown>[]> = { readonly [K in keyof Members]: Members[K] extends EnumMember<infer N, unknown> ? N : never };
32
- type MembersAccessorMap<Members extends readonly EnumMember<string, unknown>[]> = { readonly [M in Members[number] as M['name']]: M['value'] };
33
- /**
34
- * Internal brand that identifies an EnumTypeHandle in the lowering pipeline.
35
- * Not exported — callers only interact with `EnumTypeHandle`.
36
- */
37
- declare const ENUM_TYPE_HANDLE_BRAND: unique symbol;
38
- /**
39
- * Authoring handle returned by `enumType()`. Carries:
40
- *
41
- * - The ordered literal value tuple (`.values`) and name tuple (`.names`)
42
- * so downstream type-tests can assert literal preservation.
43
- * - A namespaced member accessor map (`.members`) to avoid collisions with
44
- * `.values` / `.has` / `.nameOf` / `.ordinalOf`.
45
- * - Runtime helpers `.has()`, `.nameOf()`, `.ordinalOf()`.
46
- * - Internal metadata (`enumName`, `codecId`, `nativeType`,
47
- * `enumMembers`) for the lowering pipeline.
48
- *
49
- * The type is generic over the ordered value tuple so callers that assign
50
- * `const Role = enumType(...)` retain the literal tuple on `.values`.
51
- */
52
- interface EnumTypeHandle<Name extends string = string, Values extends readonly unknown[] = readonly unknown[], Names extends readonly string[] = readonly string[], MembersMap extends Record<string, unknown> = Record<string, unknown>> {
53
- /** Internal brand for lowering-pipeline detection. */
54
- readonly [ENUM_TYPE_HANDLE_BRAND]: true;
55
- /** The enum's declared name (used as the key in domain `enum` / storage `valueSet`). */
56
- readonly enumName: Name;
57
- /** codecId from the codec passed to `enumType`. */
58
- readonly codecId: string;
59
- /** nativeType from the codec passed to `enumType`. */
60
- readonly nativeType: string;
61
- /** Ordered member list for lowering (name + value pairs). */
62
- readonly enumMembers: readonly {
63
- readonly name: string;
64
- readonly value: Values[number];
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
- * Namespaced accessor map: `Role.members.User === 'user'`.
72
- * Namespaced under `.members` to avoid collisions with `.values` / `.has`.
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 members: MembersMap;
75
- /** Returns `true` if `v` is a declared member value. */
76
- has(v: Values[number]): boolean;
77
- /** Returns the member name for a value, or `undefined` if not found. */
78
- nameOf(v: Values[number]): string | undefined;
79
- /** Returns the zero-based declaration index of a value, or `-1` if not found. */
80
- ordinalOf(v: Values[number]): number;
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,16 +200,15 @@ 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<Descriptor extends ColumnTypeDescriptor = ColumnTypeDescriptor, 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
- readonly descriptor?: (ColumnTypeDescriptor & {
160
- readonly codecId: CodecId;
161
- }) | undefined;
205
+ readonly descriptor?: Descriptor | undefined;
162
206
  readonly typeRef?: TypeRef | undefined;
163
207
  readonly nullable: Nullable;
164
208
  readonly columnName?: ColumnName | undefined;
165
209
  readonly default?: ColumnDefault | undefined;
166
210
  readonly executionDefaults?: ExecutionMutationDefaultPhases | undefined;
211
+ readonly many?: Many extends true ? true : undefined;
167
212
  } & (IdSpec extends NamedConstraintSpec ? {
168
213
  readonly id: IdSpec;
169
214
  } : {
@@ -175,19 +220,18 @@ type ScalarFieldState<CodecId extends string = string, TypeRef extends NamedStor
175
220
  });
176
221
  type AnyScalarFieldState = {
177
222
  readonly kind: 'scalar';
178
- readonly descriptor?: (ColumnTypeDescriptor & {
179
- readonly codecId: string;
180
- }) | undefined;
223
+ readonly descriptor?: ColumnTypeDescriptor | undefined;
181
224
  readonly typeRef?: NamedStorageTypeRef | undefined;
182
225
  readonly nullable: boolean;
183
226
  readonly columnName?: string | undefined;
184
227
  readonly default?: ColumnDefault | undefined;
185
228
  readonly executionDefaults?: ExecutionMutationDefaultPhases | undefined;
229
+ readonly many?: boolean | undefined;
186
230
  readonly id?: NamedConstraintSpec | undefined;
187
231
  readonly unique?: NamedConstraintSpec | undefined;
188
232
  };
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;
233
+ type HasNamedConstraintId<State extends AnyScalarFieldState> = State extends ScalarFieldState<ColumnTypeDescriptor, NamedStorageTypeRef | undefined, boolean, string | undefined, infer IdSpec, NamedConstraintSpec | undefined, boolean> ? IdSpec extends NamedConstraintSpec ? true : false : false;
234
+ type HasNamedConstraintUnique<State extends AnyScalarFieldState> = State extends ScalarFieldState<ColumnTypeDescriptor, NamedStorageTypeRef | undefined, boolean, string | undefined, NamedConstraintSpec | undefined, infer UniqueSpec, boolean> ? UniqueSpec extends NamedConstraintSpec ? true : false : false;
191
235
  type FieldSqlSpecForState<State extends AnyScalarFieldState> = {
192
236
  readonly column?: string;
193
237
  } & (HasNamedConstraintId<State> extends true ? {
@@ -195,7 +239,7 @@ type FieldSqlSpecForState<State extends AnyScalarFieldState> = {
195
239
  } : Record<never, never>) & (HasNamedConstraintUnique<State> extends true ? {
196
240
  readonly unique?: NamedConstraintNameSpec;
197
241
  } : 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 {
242
+ type ApplyFieldSqlSpec<State extends AnyScalarFieldState, Spec extends FieldSqlSpecForState<State>> = State extends ScalarFieldState<infer Descriptor, infer TypeRef, infer Nullable, infer ColumnName, infer IdSpec, infer UniqueSpec, infer Many> ? ScalarFieldState<Descriptor, TypeRef, Nullable, Spec extends {
199
243
  readonly column: infer NextColumn extends string;
200
244
  } ? NextColumn : ColumnName, Spec extends {
201
245
  readonly id: {
@@ -205,7 +249,7 @@ type ApplyFieldSqlSpec<State extends AnyScalarFieldState, Spec extends FieldSqlS
205
249
  readonly unique: {
206
250
  readonly name: infer UniqueName extends string;
207
251
  };
208
- } ? UniqueSpec extends NamedConstraintSpec ? NamedConstraintSpec<UniqueName> : UniqueSpec : UniqueSpec> : never;
252
+ } ? UniqueSpec extends NamedConstraintSpec ? NamedConstraintSpec<UniqueName> : UniqueSpec : UniqueSpec, Many> : AnyScalarFieldState;
209
253
  type GeneratedFieldSpec = {
210
254
  readonly type: ColumnTypeDescriptor;
211
255
  readonly typeParams?: Record<string, unknown>;
@@ -222,27 +266,28 @@ declare class ScalarFieldBuilder<State extends AnyScalarFieldState = AnyScalarFi
222
266
  * `TargetFieldRef.columnName` so FK target columns are resolved correctly.
223
267
  */
224
268
  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> : never>;
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> : never>;
269
+ optional(): ScalarFieldBuilder<State extends ScalarFieldState<infer Descriptor, infer TypeRef, boolean, infer ColumnName, infer IdSpec, infer UniqueSpec, infer Many> ? ScalarFieldState<Descriptor, TypeRef, true, ColumnName, IdSpec, UniqueSpec, Many> : AnyScalarFieldState>;
270
+ column<ColumnName extends string>(name: ColumnName): ScalarFieldBuilder<State extends ScalarFieldState<infer Descriptor, infer TypeRef, infer Nullable, string | undefined, infer IdSpec, infer UniqueSpec, infer Many> ? ScalarFieldState<Descriptor, TypeRef, Nullable, ColumnName, IdSpec, UniqueSpec, Many> : AnyScalarFieldState>;
271
+ many(): ScalarFieldBuilder<State extends ScalarFieldState<infer Descriptor, infer TypeRef, infer Nullable, infer ColumnName, infer IdSpec, infer UniqueSpec, boolean> ? ScalarFieldState<Descriptor, TypeRef, Nullable, ColumnName, IdSpec, UniqueSpec, true> : AnyScalarFieldState>;
227
272
  default(value: ColumnDefaultLiteralInputValue | ColumnDefault): ScalarFieldBuilder<State>;
228
273
  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> : never>;
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>> : never>;
274
+ id<const Name extends string | undefined = undefined>(options?: NamedConstraintSpec<Name>): ScalarFieldBuilder<State extends ScalarFieldState<infer Descriptor, infer TypeRef, infer Nullable, infer ColumnName, NamedConstraintSpec | undefined, infer UniqueSpec, infer Many> ? ScalarFieldState<Descriptor, TypeRef, Nullable, ColumnName, NamedConstraintSpec<Name>, UniqueSpec, Many> : AnyScalarFieldState>;
275
+ unique<const Name extends string | undefined = undefined>(options?: NamedConstraintSpec<Name>): ScalarFieldBuilder<State extends ScalarFieldState<infer Descriptor, infer TypeRef, infer Nullable, infer ColumnName, infer IdSpec, NamedConstraintSpec | undefined, infer Many> ? ScalarFieldState<Descriptor, TypeRef, Nullable, ColumnName, IdSpec, NamedConstraintSpec<Name>, Many> : AnyScalarFieldState>;
231
276
  sql<const Spec extends FieldSqlSpecForState<State>>(spec: Spec): ScalarFieldBuilder<ApplyFieldSqlSpec<State, Spec>>;
232
277
  build(): State;
233
278
  }
234
- declare class EnumScalarFieldBuilder<Handle extends EnumTypeHandle, State extends AnyScalarFieldState = ScalarFieldState<Handle['codecId'], Handle, false, undefined>> extends ScalarFieldBuilder<State> {
279
+ declare class EnumScalarFieldBuilder<Handle extends EnumTypeHandle, State extends AnyScalarFieldState = ScalarFieldState<ColumnTypeDescriptor, Handle, false, undefined>> extends ScalarFieldBuilder<State> {
235
280
  #private;
236
281
  constructor(state: State, handle: Handle);
237
282
  default(value: Handle['values'][number]): EnumScalarFieldBuilder<Handle, State>;
238
283
  defaultSql(_expression: never): never;
239
284
  }
240
- declare function columnField<Descriptor extends ColumnTypeDescriptor>(descriptor: Descriptor): ScalarFieldBuilder<ScalarFieldState<Descriptor['codecId'], undefined, false, undefined>>;
285
+ declare function columnField<Descriptor extends ColumnTypeDescriptor>(descriptor: Descriptor): ScalarFieldBuilder<ScalarFieldState<Descriptor, undefined, false, undefined>>;
241
286
  declare function generatedField<Descriptor extends ColumnTypeDescriptor>(spec: GeneratedFieldSpec & {
242
287
  readonly type: Descriptor;
243
- }): ScalarFieldBuilder<ScalarFieldState<Descriptor['codecId'], undefined, false, undefined>>;
244
- declare function namedTypeField<TypeRef extends string>(typeRef: TypeRef): ScalarFieldBuilder<ScalarFieldState<string, TypeRef, false, undefined>>;
245
- declare function namedTypeField<TypeRef extends StorageTypeInstance>(typeRef: TypeRef): ScalarFieldBuilder<ScalarFieldState<TypeRef['codecId'], TypeRef, false, undefined>>;
288
+ }): ScalarFieldBuilder<ScalarFieldState<Descriptor, undefined, false, undefined>>;
289
+ declare function namedTypeField<TypeRef extends string>(typeRef: TypeRef): ScalarFieldBuilder<ScalarFieldState<ColumnTypeDescriptor, TypeRef, false, undefined>>;
290
+ declare function namedTypeField<TypeRef extends StorageTypeInstance>(typeRef: TypeRef): ScalarFieldBuilder<ScalarFieldState<ColumnTypeDescriptor<TypeRef['codecId']>, TypeRef, false, undefined>>;
246
291
  declare function namedTypeField<Handle extends EnumTypeHandle>(typeRef: Handle): EnumScalarFieldBuilder<Handle>;
247
292
  type RelationModelRefSource = 'string' | 'token' | 'lazyToken';
248
293
  type TargetFieldRefSource = 'string' | 'token';
@@ -571,7 +616,7 @@ type ContractInput<Family extends FamilyPackRef<string> = FamilyPackRef<string>,
571
616
  */
572
617
  readonly namespaces?: readonly string[];
573
618
  /**
574
- * Target-supplied factory that materialises a `Namespace` concretion
619
+ * Target-supplied factory that materialises a `SqlNamespaceBase` concretion
575
620
  * for a declared namespace coordinate. The SQL family layer is
576
621
  * target-agnostic and cannot import concretions like
577
622
  * `PostgresSchema` or `SqliteUnboundDatabase`; the factory is the
@@ -583,14 +628,8 @@ type ContractInput<Family extends FamilyPackRef<string> = FamilyPackRef<string>,
583
628
  * `StorageTable.namespaceId` referenced by a model, and the
584
629
  * framework `UNBOUND_NAMESPACE_ID` sentinel (always present so the
585
630
  * 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
631
  */
593
- readonly createNamespace?: (input: SqlNamespaceTablesInput) => Namespace;
632
+ readonly createNamespace: (input: SqlNamespaceInput) => SqlNamespaceBase;
594
633
  readonly types?: Types;
595
634
  readonly models?: Models;
596
635
  readonly codecLookup?: CodecLookup;
@@ -600,6 +639,15 @@ type ContractInput<Family extends FamilyPackRef<string> = FamilyPackRef<string>,
600
639
  * default namespace. Fields reference the enum via `field.namedType(handle)`.
601
640
  */
602
641
  readonly enums?: Record<string, EnumTypeHandle>;
642
+ /**
643
+ * Author-declared pack entities, keyed by namespace id then entity kind
644
+ * then name — e.g. `{ auth: { native_enum: { AalLevel: <entity> } } }`.
645
+ * Each entity lowers into `storage.namespaces[ns].entries.<kind>`; when its
646
+ * registered entity-type descriptor derives a value-set, that also folds
647
+ * into `entries.valueSet`, mirroring how `enums` flows there. Generic on
648
+ * purpose — neither this type nor the assembler names a specific kind.
649
+ */
650
+ readonly packEntities?: PackEntitiesInput;
603
651
  };
604
652
  declare function model<const ModelName extends string, Fields extends Record<string, ScalarFieldBuilder>, Relations extends Record<string, AnyRelationBuilder> = Record<never, never>>(modelName: ModelName, input: {
605
653
  readonly fields: Fields;
@@ -715,7 +763,7 @@ type ResolveTemplateValue<Template, Args extends readonly unknown[]> = Template
715
763
  type ResolveTemplatePathValue<Value, Path extends readonly string[] | undefined> = Path extends readonly [infer Segment extends string, ...infer Rest extends readonly string[]] ? Segment extends keyof NonNullable<Value> ? ResolveTemplatePathValue<NonNullable<Value>[Segment], Rest> : never : Value;
716
764
  type ResolveTemplateDefaultValue<Value, Default, Args extends readonly unknown[]> = Default extends undefined ? Value : [Value] extends [never] ? ResolveTemplateValue<Default, Args> : undefined extends Value ? Exclude<Value, undefined> | ResolveTemplateValue<Default, Args> : Value;
717
765
  type ResolveTemplateArgValue<Value, Path extends readonly string[] | undefined, Default, Args extends readonly unknown[]> = ResolveTemplateDefaultValue<ResolveTemplatePathValue<Value, Path>, Default, Args>;
718
- type FieldBuilderFromPresetDescriptor<Descriptor extends AuthoringFieldPresetDescriptor, Args extends readonly unknown[] = readonly [], ConstraintName extends string | undefined = undefined> = ScalarFieldBuilder<ScalarFieldState<ResolveTemplateValue<Descriptor['output']['codecId'], Args> extends string ? ResolveTemplateValue<Descriptor['output']['codecId'], Args> : string, undefined, ResolveTemplateValue<Descriptor['output']['nullable'], Args> extends true ? true : false, undefined, NamedConstraintState<ResolveTemplateValue<Descriptor['output']['id'], Args> extends true ? true : false, ConstraintName>, NamedConstraintState<ResolveTemplateValue<Descriptor['output']['unique'], Args> extends true ? true : false, ConstraintName>>>;
766
+ type FieldBuilderFromPresetDescriptor<Descriptor extends AuthoringFieldPresetDescriptor, Args extends readonly unknown[] = readonly [], ConstraintName extends string | undefined = undefined> = ScalarFieldBuilder<ScalarFieldState<ColumnTypeDescriptor<ResolveTemplateValue<Descriptor['output']['codecId'], Args> extends string ? ResolveTemplateValue<Descriptor['output']['codecId'], Args> : string>, undefined, ResolveTemplateValue<Descriptor['output']['nullable'], Args> extends true ? true : false, undefined, NamedConstraintState<ResolveTemplateValue<Descriptor['output']['id'], Args> extends true ? true : false, ConstraintName>, NamedConstraintState<ResolveTemplateValue<Descriptor['output']['unique'], Args> extends true ? true : false, ConstraintName>>>;
719
767
  type FieldHelperFunctionWithoutNamedConstraint<Descriptor extends AuthoringFieldPresetDescriptor> = Descriptor extends {
720
768
  readonly args: infer Args extends readonly AuthoringArgumentDescriptor[];
721
769
  } ? <const Params extends TupleFromArgumentDescriptors<Args>>(...args: Params) => FieldBuilderFromPresetDescriptor<Descriptor, Params> : () => FieldBuilderFromPresetDescriptor<Descriptor, readonly []>;
@@ -727,10 +775,10 @@ type FieldHelpersFromNamespace<Namespace> = { readonly [K in keyof Namespace]: N
727
775
  //#endregion
728
776
  //#region src/contract-types.d.ts
729
777
  type ExtractCodecTypesFromPack<P> = P extends {
730
- __codecTypes?: infer C;
731
- } ? C extends Record<string, {
732
- output: unknown;
733
- }> ? C : Record<string, never> : Record<string, never>;
778
+ __codecTypes?: infer C extends Record<string, {
779
+ output: unknown;
780
+ }>;
781
+ } ? C : Record<string, never>;
734
782
  type MergeExtensionCodecTypes<Packs extends Record<string, unknown>> = UnionToIntersection<{ [K in keyof Packs]: ExtractCodecTypesFromPack<Packs[K]> }[keyof Packs]>;
735
783
  type MergeExtensionCodecTypesSafe<Packs> = Packs extends Record<string, unknown> ? keyof Packs extends never ? Record<string, never> : MergeExtensionCodecTypes<Packs> : Record<string, never>;
736
784
  type ExtractIndexTypesFromPack<P> = P extends {
@@ -813,6 +861,9 @@ type FieldTypeRefOf<FieldState> = Present<FieldState extends {
813
861
  type FieldNullableOf<FieldState> = FieldState extends {
814
862
  readonly nullable: infer Nullable extends boolean;
815
863
  } ? Nullable : boolean;
864
+ type FieldManyOf<FieldState> = FieldState extends {
865
+ readonly many?: true;
866
+ } ? true : false;
816
867
  type FieldColumnOverrideOf<FieldState> = Present<FieldState extends {
817
868
  readonly columnName?: infer ColumnName;
818
869
  } ? ColumnName : never>;
@@ -865,17 +916,19 @@ type AttributeIdName<Definition, ModelName extends ModelNames<Definition>> = Pre
865
916
  } ? Name : never>;
866
917
  type ModelIdFieldNames<Definition, ModelName extends ModelNames<Definition>> = [AttributeIdFieldNames<Definition, ModelName>] extends [undefined] ? InlineIdFieldNames<Definition, ModelName> : AttributeIdFieldNames<Definition, ModelName>;
867
918
  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> = {
919
+ 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
920
  readonly nativeType: NativeType;
870
921
  readonly codecId: CodecId;
871
922
  readonly nullable: Nullable;
872
923
  readonly default?: ColumnDefault;
873
924
  } & (TypeRef extends string ? {
874
925
  readonly typeRef: TypeRef;
875
- } : Record<string, never>) & (TypeParams extends Record<string, unknown> ? {
926
+ } : Record<never, never>) & (TypeParams extends Record<string, unknown> ? {
876
927
  readonly typeParams: TypeParams;
877
- } : Record<string, never>);
878
- 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>>> : never;
928
+ } : Record<never, never>) & (Many extends true ? {
929
+ readonly many: true;
930
+ } : Record<never, never>);
931
+ 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
932
  type BuiltModels<Definition> = { readonly [ModelName in ModelNames<Definition>]: {
880
933
  readonly storage: {
881
934
  readonly table: ModelTableName<Definition, ModelName>;
@@ -967,10 +1020,23 @@ type BuiltStorage<Definition> = {
967
1020
  };
968
1021
  } };
969
1022
  };
1023
+ type StorageColumnManyOf<Col> = Col extends {
1024
+ readonly many: true;
1025
+ } ? true : false;
970
1026
  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);
1027
+ type DescriptorEntityMembers<Descriptor> = Descriptor extends {
1028
+ readonly entityRef: {
1029
+ readonly entity: {
1030
+ readonly members: infer Members extends readonly string[];
1031
+ };
1032
+ };
1033
+ } ? Members : never;
1034
+ type DescriptorValueSetUnion<FieldState> = [FieldDescriptorOf<FieldState>] extends [never] ? never : readonly string[] extends DescriptorEntityMembers<FieldDescriptorOf<FieldState>> ? never : DescriptorEntityMembers<FieldDescriptorOf<FieldState>>[number];
1035
+ 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;
1036
+ type FieldValueUnion<FieldState> = [EnumValueUnion<FieldState>] extends [never] ? DescriptorValueSetUnion<FieldState> : EnumValueUnion<FieldState>;
1037
+ type FieldChannelType<Definition, ModelName extends ModelNames<Definition>, FieldName extends ModelFieldNames<Definition, ModelName>, Channel extends 'output' | 'input'> = ([FieldValueUnion<ModelFieldState<Definition, ModelName, FieldName>>] extends [never] ? CodecChannelType<Definition, ModelName, FieldName, Channel> : StorageColumnManyOf<ModelStorageColumn<Definition, ModelName, FieldName>> extends true ? ReadonlyArray<FieldValueUnion<ModelFieldState<Definition, ModelName, FieldName>>> : FieldValueUnion<ModelFieldState<Definition, ModelName, FieldName>>) | (FieldNullableOf<ModelFieldState<Definition, ModelName, FieldName>> extends true ? null : never);
973
1038
  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> } } };
1039
+ 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
1040
  type SqlContractResult<Definition> = ContractWithTypeMaps<Omit<Contract<BuiltStorage<Definition>>, 'domain'> & {
975
1041
  readonly target: DefinitionTargetId<Definition>;
976
1042
  readonly targetFamily: 'sql';
@@ -982,7 +1048,7 @@ type SqlContractResult<Definition> = ContractWithTypeMaps<Omit<Contract<BuiltSto
982
1048
  readonly extensionPacks: keyof DefinitionExtensionPacks<Definition> extends never ? Record<string, never> : DefinitionExtensionPacks<Definition>;
983
1049
  readonly capabilities: DerivedCapabilities<Definition>;
984
1050
  readonly enumAccessors: BuiltEnumAccessors<Definition>;
985
- }, TypeMaps<CodecTypesFromDefinition<Definition>, Record<string, never>, FieldChannelTypes<Definition, 'output'>, FieldChannelTypes<Definition, 'input'>>>;
1051
+ }, TypeMaps<CodecTypesFromDefinition<Definition>, Record<string, never>, FieldChannelTypes<Definition, 'output'>, FieldChannelTypes<Definition, 'input'>, StorageColumnChannelTypes<Definition, 'output'>, StorageColumnChannelTypes<Definition, 'input'>>>;
986
1052
  //#endregion
987
1053
  //#region src/composed-authoring-helpers.d.ts
988
1054
  type ExtractTypeNamespaceFromPack<Pack> = ExtractAuthoringNamespaceFromPack<Pack, 'type', Record<never, never>>;
@@ -1030,169 +1096,6 @@ type ComposedAuthoringHelpers<Family extends FamilyPackRef<string>, Target exten
1030
1096
  readonly type: TypeHelpersFromNamespace<ExtractTypeNamespaceFromPack<Family> & ExtractTypeNamespaceFromPack<Target> & MergeExtensionTypeNamespaces<ExtensionPacks>>;
1031
1097
  };
1032
1098
  //#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
1099
  //#region src/build-contract.d.ts
1197
1100
  declare function buildSqlContractFromDefinition(definition: ContractDefinition, codecLookup?: CodecLookup): Contract<SqlStorage>;
1198
1101
  //#endregion
@@ -1218,11 +1121,12 @@ type ContractDefinition$1<Family extends FamilyPackRef<string>, Target extends T
1218
1121
  readonly foreignKeyDefaults?: ForeignKeyDefaults;
1219
1122
  readonly defaultControlPolicy?: ControlPolicy;
1220
1123
  readonly namespaces?: Namespaces;
1221
- readonly createNamespace?: (input: SqlNamespaceTablesInput) => Namespace;
1124
+ readonly createNamespace: (input: SqlNamespaceInput) => SqlNamespaceBase;
1222
1125
  readonly types?: Types;
1223
1126
  readonly models?: Models;
1224
1127
  readonly codecLookup?: CodecLookup;
1225
1128
  readonly enums?: Enums;
1129
+ readonly packEntities?: PackEntitiesInput;
1226
1130
  };
1227
1131
  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
1132
  readonly family: Family;
@@ -1233,16 +1137,18 @@ type ContractScaffold<Family extends FamilyPackRef<string>, Target extends Targe
1233
1137
  readonly foreignKeyDefaults?: ForeignKeyDefaults;
1234
1138
  readonly defaultControlPolicy?: ControlPolicy;
1235
1139
  readonly namespaces?: Namespaces;
1236
- readonly createNamespace?: (input: SqlNamespaceTablesInput) => Namespace;
1140
+ readonly createNamespace: (input: SqlNamespaceInput) => SqlNamespaceBase;
1237
1141
  readonly types?: never;
1238
1142
  readonly models?: never;
1239
1143
  readonly codecLookup?: CodecLookup;
1240
1144
  readonly enums?: Enums;
1145
+ readonly packEntities?: PackEntitiesInput;
1241
1146
  };
1242
1147
  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
1148
  readonly types?: Types;
1244
1149
  readonly models?: Models;
1245
1150
  readonly enums?: Enums;
1151
+ readonly packEntities?: PackEntitiesInput;
1246
1152
  };
1247
1153
  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
1154
  readonly extensionPacks?: ExtensionPacks;
@@ -1251,11 +1157,12 @@ type BoundDefinitionInput<Types extends Record<string, StorageTypeInstance> = Re
1251
1157
  readonly foreignKeyDefaults?: ForeignKeyDefaults;
1252
1158
  readonly defaultControlPolicy?: ControlPolicy;
1253
1159
  readonly namespaces?: Namespaces;
1254
- readonly createNamespace?: (input: SqlNamespaceTablesInput) => Namespace;
1160
+ readonly createNamespace: (input: SqlNamespaceInput) => SqlNamespaceBase;
1255
1161
  readonly types?: Types;
1256
1162
  readonly models?: Models;
1257
1163
  readonly codecLookup?: CodecLookup;
1258
1164
  readonly enums?: Record<string, EnumTypeHandle>;
1165
+ readonly packEntities?: PackEntitiesInput;
1259
1166
  };
1260
1167
  type LiteralEnums<E extends Record<string, EnumTypeHandle>> = string extends keyof E ? Record<never, never> : E;
1261
1168
  type MergeEnums<ScaffoldEnums extends Record<string, EnumTypeHandle>, FactoryEnums extends Record<string, EnumTypeHandle>> = LiteralEnums<ScaffoldEnums> & LiteralEnums<FactoryEnums>;
@@ -1279,6 +1186,7 @@ declare function buildBoundContract<const F extends FamilyPackRef<string>, const
1279
1186
  readonly types?: Record<string, StorageTypeInstance>;
1280
1187
  readonly models?: Record<string, ModelLike>;
1281
1188
  readonly enums?: Record<string, EnumTypeHandle>;
1189
+ readonly packEntities?: PackEntitiesInput;
1282
1190
  }>(family: F, target: T, definition: Definition, factory: (helpers: ComposedAuthoringHelpers<F, T, NonNullable<Definition['extensionPacks']>>) => Built): SqlContractResult<WithFamilyTarget<Definition & Built, F, T>>;
1283
1191
  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
1192
  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>>>;