@prisma-next/sql-contract-ts 0.14.0 → 0.15.0-dev.10
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-CAX6inbk.mjs} +260 -43
- package/dist/build-contract-CAX6inbk.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 +16 -8
- package/dist/config-types.mjs.map +1 -1
- package/dist/contract-builder.d.mts +104 -187
- package/dist/contract-builder.d.mts.map +1 -1
- package/dist/contract-builder.mjs +144 -87
- package/dist/contract-builder.mjs.map +1 -1
- package/package.json +14 -14
- package/src/authoring-helper-runtime.ts +2 -6
- package/src/authoring-type-utils.ts +6 -3
- package/src/build-contract.ts +439 -66
- package/src/composed-authoring-helpers.ts +3 -6
- package/src/config-types.ts +10 -1
- package/src/contract-builder.ts +17 -5
- package/src/contract-definition.ts +32 -4
- package/src/contract-dsl.ts +215 -108
- package/src/contract-lowering.ts +155 -1
- package/src/contract-types.ts +70 -13
- package/src/enum-type.ts +14 -306
- package/src/exports/contract-builder.ts +2 -0
- package/dist/build-contract-CQ4u83jx.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-types.mjs","names":[],"sources":["../src/config-types.ts"],"sourcesContent":["import { pathToFileURL } from 'node:url';\nimport type { ContractConfig } from '@prisma-next/config/config-types';\nimport { applySpecifierDefaultControlPolicy } from '@prisma-next/contract/apply-specifier-default-control-policy';\nimport type { Contract, ControlPolicy } from '@prisma-next/contract/types';\nimport type { TargetPackRef } from '@prisma-next/framework-components/components';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { ok } from '@prisma-next/utils/result';\nimport { extname } from 'pathe';\nimport { buildSqlContractFromDefinition } from './build-contract';\n\n/**\n * Derives the emit output path from the TS contract input so artefacts land\n * colocated with the source (e.g. `prisma/contract.ts` →\n * `prisma/contract.json`). Mirrors the same default-derivation logic in\n * `@prisma-next/sql-contract-psl/provider`.\n */\nfunction defaultOutputFromContractPath(contractPath: string): string {\n const ext = extname(contractPath);\n if (ext.length === 0) return `${contractPath}.json`;\n return `${contractPath.slice(0, -ext.length)}.json`;\n}\n\nexport interface TypeScriptContractSpecifierOptions {\n readonly defaultControlPolicy?: ControlPolicy;\n}\n\nexport function emptyContract(options: {\n readonly output?: string;\n readonly target: TargetPackRef<'sql', string>;\n readonly defaultControlPolicy?: ControlPolicy;\n}): ContractConfig {\n return {\n source: {\n load: async () => {\n const built = buildSqlContractFromDefinition({
|
|
1
|
+
{"version":3,"file":"config-types.mjs","names":[],"sources":["../src/config-types.ts"],"sourcesContent":["import { pathToFileURL } from 'node:url';\nimport type { ContractConfig } from '@prisma-next/config/config-types';\nimport { applySpecifierDefaultControlPolicy } from '@prisma-next/contract/apply-specifier-default-control-policy';\nimport type { Contract, ControlPolicy } from '@prisma-next/contract/types';\nimport type { TargetPackRef } from '@prisma-next/framework-components/components';\nimport type { SqlNamespaceBase, SqlNamespaceInput } from '@prisma-next/sql-contract/types';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { ok } from '@prisma-next/utils/result';\nimport { extname } from 'pathe';\nimport { buildSqlContractFromDefinition } from './build-contract';\n\n/**\n * Derives the emit output path from the TS contract input so artefacts land\n * colocated with the source (e.g. `prisma/contract.ts` →\n * `prisma/contract.json`). Mirrors the same default-derivation logic in\n * `@prisma-next/sql-contract-psl/provider`.\n */\nfunction defaultOutputFromContractPath(contractPath: string): string {\n const ext = extname(contractPath);\n if (ext.length === 0) return `${contractPath}.json`;\n return `${contractPath.slice(0, -ext.length)}.json`;\n}\n\nexport interface TypeScriptContractSpecifierOptions {\n readonly defaultControlPolicy?: ControlPolicy;\n}\n\nexport function emptyContract(options: {\n readonly output?: string;\n readonly target: TargetPackRef<'sql', string>;\n readonly createNamespace: (input: SqlNamespaceInput) => SqlNamespaceBase;\n readonly defaultControlPolicy?: ControlPolicy;\n}): ContractConfig {\n return {\n source: {\n sourceFormat: 'typescript',\n load: async () => {\n const built = buildSqlContractFromDefinition({\n target: options.target,\n createNamespace: options.createNamespace,\n models: [],\n });\n return ok(applySpecifierDefaultControlPolicy(built, options.defaultControlPolicy));\n },\n },\n ...ifDefined('output', options.output),\n };\n}\n\nexport function typescriptContract(\n contract: Contract,\n output?: string,\n options?: TypeScriptContractSpecifierOptions,\n): ContractConfig {\n return {\n source: {\n sourceFormat: 'typescript',\n load: async () =>\n ok(applySpecifierDefaultControlPolicy(contract, options?.defaultControlPolicy)),\n },\n // The in-memory variant has no input path to anchor on; fall through to\n // the global default in `normalizeContractConfig` when caller doesn't pin it.\n ...ifDefined('output', output),\n };\n}\n\nexport function typescriptContractFromPath(\n contractPath: string,\n output?: string,\n options?: TypeScriptContractSpecifierOptions,\n): ContractConfig {\n return {\n source: {\n sourceFormat: 'typescript',\n inputs: [contractPath],\n load: async (context) => {\n const [absolutePath] = context.resolvedInputs;\n if (absolutePath === undefined) {\n throw new Error(\n 'typescriptContractFromPath: context.resolvedInputs is empty. The CLI config loader should populate it positional-matched with source.inputs.',\n );\n }\n const mod = await import(pathToFileURL(absolutePath).href);\n const contract: Contract | undefined = mod.default ?? mod.contract;\n if (contract === undefined) {\n throw new Error(\n `typescriptContractFromPath: module at \"${absolutePath}\" has no \"default\" or \"contract\" export.`,\n );\n }\n return ok(applySpecifierDefaultControlPolicy(contract, options?.defaultControlPolicy));\n },\n },\n output: output ?? defaultOutputFromContractPath(contractPath),\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAiBA,SAAS,8BAA8B,cAA8B;CACnE,MAAM,MAAM,QAAQ,YAAY;CAChC,IAAI,IAAI,WAAW,GAAG,OAAO,GAAG,aAAa;CAC7C,OAAO,GAAG,aAAa,MAAM,GAAG,CAAC,IAAI,MAAM,EAAE;AAC/C;AAMA,SAAgB,cAAc,SAKX;CACjB,OAAO;EACL,QAAQ;GACN,cAAc;GACd,MAAM,YAAY;IAMhB,OAAO,GAAG,mCALI,+BAA+B;KAC3C,QAAQ,QAAQ;KAChB,iBAAiB,QAAQ;KACzB,QAAQ,CAAC;IACX,CACiD,GAAG,QAAQ,oBAAoB,CAAC;GACnF;EACF;EACA,GAAG,UAAU,UAAU,QAAQ,MAAM;CACvC;AACF;AAEA,SAAgB,mBACd,UACA,QACA,SACgB;CAChB,OAAO;EACL,QAAQ;GACN,cAAc;GACd,MAAM,YACJ,GAAG,mCAAmC,UAAU,SAAS,oBAAoB,CAAC;EAClF;EAGA,GAAG,UAAU,UAAU,MAAM;CAC/B;AACF;AAEA,SAAgB,2BACd,cACA,QACA,SACgB;CAChB,OAAO;EACL,QAAQ;GACN,cAAc;GACd,QAAQ,CAAC,YAAY;GACrB,MAAM,OAAO,YAAY;IACvB,MAAM,CAAC,gBAAgB,QAAQ;IAC/B,IAAI,iBAAiB,KAAA,GACnB,MAAM,IAAI,MACR,8IACF;IAEF,MAAM,MAAM,MAAM,OAAO,cAAc,YAAY,CAAC,CAAC;IACrD,MAAM,WAAiC,IAAI,WAAW,IAAI;IAC1D,IAAI,aAAa,KAAA,GACf,MAAM,IAAI,MACR,0CAA0C,aAAa,yCACzD;IAEF,OAAO,GAAG,mCAAmC,UAAU,SAAS,oBAAoB,CAAC;GACvF;EACF;EACA,QAAQ,UAAU,8BAA8B,YAAY;CAC9D;AACF"}
|
|
@@ -1,149 +1,13 @@
|
|
|
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
|
+
import { PackEntityHandle } from "@prisma-next/sql-contract/entity-handle-lowering-hook";
|
|
7
8
|
import { ExtensionPackRef, FamilyPackRef, TargetPackRef } from "@prisma-next/framework-components/components";
|
|
8
9
|
import { CodecLookup, ColumnTypeDescriptor } from "@prisma-next/framework-components/codec";
|
|
9
10
|
|
|
10
|
-
//#region src/enum-type.d.ts
|
|
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.
|
|
16
|
-
*/
|
|
17
|
-
interface EnumMember<Name extends string, Value> {
|
|
18
|
-
readonly name: Name;
|
|
19
|
-
readonly value: Value;
|
|
20
|
-
}
|
|
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;
|
|
70
|
-
/**
|
|
71
|
-
* Namespaced accessor map: `Role.members.User === 'user'`.
|
|
72
|
-
* Namespaced under `.members` to avoid collisions with `.values` / `.has`.
|
|
73
|
-
*/
|
|
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;
|
|
81
|
-
}
|
|
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
|
-
//#endregion
|
|
147
11
|
//#region src/contract-dsl.d.ts
|
|
148
12
|
type NamingStrategy = 'identity' | 'snake_case';
|
|
149
13
|
type NamingConfig = {
|
|
@@ -154,16 +18,15 @@ type NamedStorageTypeRef = string | StorageTypeInstance | EnumTypeHandle;
|
|
|
154
18
|
type NamedConstraintNameSpec<Name extends string = string> = {
|
|
155
19
|
readonly name: Name;
|
|
156
20
|
};
|
|
157
|
-
type ScalarFieldState<
|
|
21
|
+
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
22
|
readonly kind: 'scalar';
|
|
159
|
-
readonly descriptor?:
|
|
160
|
-
readonly codecId: CodecId;
|
|
161
|
-
}) | undefined;
|
|
23
|
+
readonly descriptor?: Descriptor | undefined;
|
|
162
24
|
readonly typeRef?: TypeRef | undefined;
|
|
163
25
|
readonly nullable: Nullable;
|
|
164
26
|
readonly columnName?: ColumnName | undefined;
|
|
165
27
|
readonly default?: ColumnDefault | undefined;
|
|
166
28
|
readonly executionDefaults?: ExecutionMutationDefaultPhases | undefined;
|
|
29
|
+
readonly many?: Many extends true ? true : undefined;
|
|
167
30
|
} & (IdSpec extends NamedConstraintSpec ? {
|
|
168
31
|
readonly id: IdSpec;
|
|
169
32
|
} : {
|
|
@@ -175,19 +38,18 @@ type ScalarFieldState<CodecId extends string = string, TypeRef extends NamedStor
|
|
|
175
38
|
});
|
|
176
39
|
type AnyScalarFieldState = {
|
|
177
40
|
readonly kind: 'scalar';
|
|
178
|
-
readonly descriptor?:
|
|
179
|
-
readonly codecId: string;
|
|
180
|
-
}) | undefined;
|
|
41
|
+
readonly descriptor?: ColumnTypeDescriptor | undefined;
|
|
181
42
|
readonly typeRef?: NamedStorageTypeRef | undefined;
|
|
182
43
|
readonly nullable: boolean;
|
|
183
44
|
readonly columnName?: string | undefined;
|
|
184
45
|
readonly default?: ColumnDefault | undefined;
|
|
185
46
|
readonly executionDefaults?: ExecutionMutationDefaultPhases | undefined;
|
|
47
|
+
readonly many?: boolean | undefined;
|
|
186
48
|
readonly id?: NamedConstraintSpec | undefined;
|
|
187
49
|
readonly unique?: NamedConstraintSpec | undefined;
|
|
188
50
|
};
|
|
189
|
-
type HasNamedConstraintId<State extends AnyScalarFieldState> = State extends ScalarFieldState<
|
|
190
|
-
type HasNamedConstraintUnique<State extends AnyScalarFieldState> = State extends ScalarFieldState<
|
|
51
|
+
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;
|
|
52
|
+
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
53
|
type FieldSqlSpecForState<State extends AnyScalarFieldState> = {
|
|
192
54
|
readonly column?: string;
|
|
193
55
|
} & (HasNamedConstraintId<State> extends true ? {
|
|
@@ -195,7 +57,7 @@ type FieldSqlSpecForState<State extends AnyScalarFieldState> = {
|
|
|
195
57
|
} : Record<never, never>) & (HasNamedConstraintUnique<State> extends true ? {
|
|
196
58
|
readonly unique?: NamedConstraintNameSpec;
|
|
197
59
|
} : Record<never, never>);
|
|
198
|
-
type ApplyFieldSqlSpec<State extends AnyScalarFieldState, Spec extends FieldSqlSpecForState<State>> = State extends ScalarFieldState<infer
|
|
60
|
+
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
61
|
readonly column: infer NextColumn extends string;
|
|
200
62
|
} ? NextColumn : ColumnName, Spec extends {
|
|
201
63
|
readonly id: {
|
|
@@ -205,7 +67,7 @@ type ApplyFieldSqlSpec<State extends AnyScalarFieldState, Spec extends FieldSqlS
|
|
|
205
67
|
readonly unique: {
|
|
206
68
|
readonly name: infer UniqueName extends string;
|
|
207
69
|
};
|
|
208
|
-
} ? UniqueSpec extends NamedConstraintSpec ? NamedConstraintSpec<UniqueName> : UniqueSpec : UniqueSpec> :
|
|
70
|
+
} ? UniqueSpec extends NamedConstraintSpec ? NamedConstraintSpec<UniqueName> : UniqueSpec : UniqueSpec, Many> : AnyScalarFieldState;
|
|
209
71
|
type GeneratedFieldSpec = {
|
|
210
72
|
readonly type: ColumnTypeDescriptor;
|
|
211
73
|
readonly typeParams?: Record<string, unknown>;
|
|
@@ -222,27 +84,28 @@ declare class ScalarFieldBuilder<State extends AnyScalarFieldState = AnyScalarFi
|
|
|
222
84
|
* `TargetFieldRef.columnName` so FK target columns are resolved correctly.
|
|
223
85
|
*/
|
|
224
86
|
get physicalColumnName(): string | undefined;
|
|
225
|
-
optional(): ScalarFieldBuilder<State extends ScalarFieldState<infer
|
|
226
|
-
column<ColumnName extends string>(name: ColumnName): ScalarFieldBuilder<State extends ScalarFieldState<infer
|
|
87
|
+
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>;
|
|
88
|
+
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>;
|
|
89
|
+
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
90
|
default(value: ColumnDefaultLiteralInputValue | ColumnDefault): ScalarFieldBuilder<State>;
|
|
228
91
|
defaultSql(expression: string): ScalarFieldBuilder<State>;
|
|
229
|
-
id<const Name extends string | undefined = undefined>(options?: NamedConstraintSpec<Name>): ScalarFieldBuilder<State extends ScalarFieldState<infer
|
|
230
|
-
unique<const Name extends string | undefined = undefined>(options?: NamedConstraintSpec<Name>): ScalarFieldBuilder<State extends ScalarFieldState<infer
|
|
92
|
+
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>;
|
|
93
|
+
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
94
|
sql<const Spec extends FieldSqlSpecForState<State>>(spec: Spec): ScalarFieldBuilder<ApplyFieldSqlSpec<State, Spec>>;
|
|
232
95
|
build(): State;
|
|
233
96
|
}
|
|
234
|
-
declare class EnumScalarFieldBuilder<Handle extends EnumTypeHandle, State extends AnyScalarFieldState = ScalarFieldState<
|
|
97
|
+
declare class EnumScalarFieldBuilder<Handle extends EnumTypeHandle, State extends AnyScalarFieldState = ScalarFieldState<ColumnTypeDescriptor, Handle, false, undefined>> extends ScalarFieldBuilder<State> {
|
|
235
98
|
#private;
|
|
236
99
|
constructor(state: State, handle: Handle);
|
|
237
100
|
default(value: Handle['values'][number]): EnumScalarFieldBuilder<Handle, State>;
|
|
238
101
|
defaultSql(_expression: never): never;
|
|
239
102
|
}
|
|
240
|
-
declare function columnField<Descriptor extends ColumnTypeDescriptor>(descriptor: Descriptor): ScalarFieldBuilder<ScalarFieldState<Descriptor
|
|
103
|
+
declare function columnField<Descriptor extends ColumnTypeDescriptor>(descriptor: Descriptor): ScalarFieldBuilder<ScalarFieldState<Descriptor, undefined, false, undefined>>;
|
|
241
104
|
declare function generatedField<Descriptor extends ColumnTypeDescriptor>(spec: GeneratedFieldSpec & {
|
|
242
105
|
readonly type: Descriptor;
|
|
243
|
-
}): ScalarFieldBuilder<ScalarFieldState<Descriptor
|
|
244
|
-
declare function namedTypeField<TypeRef extends string>(typeRef: TypeRef): ScalarFieldBuilder<ScalarFieldState<
|
|
245
|
-
declare function namedTypeField<TypeRef extends StorageTypeInstance>(typeRef: TypeRef): ScalarFieldBuilder<ScalarFieldState<TypeRef['codecId']
|
|
106
|
+
}): ScalarFieldBuilder<ScalarFieldState<Descriptor, undefined, false, undefined>>;
|
|
107
|
+
declare function namedTypeField<TypeRef extends string>(typeRef: TypeRef): ScalarFieldBuilder<ScalarFieldState<ColumnTypeDescriptor, TypeRef, false, undefined>>;
|
|
108
|
+
declare function namedTypeField<TypeRef extends StorageTypeInstance>(typeRef: TypeRef): ScalarFieldBuilder<ScalarFieldState<ColumnTypeDescriptor<TypeRef['codecId']>, TypeRef, false, undefined>>;
|
|
246
109
|
declare function namedTypeField<Handle extends EnumTypeHandle>(typeRef: Handle): EnumScalarFieldBuilder<Handle>;
|
|
247
110
|
type RelationModelRefSource = 'string' | 'token' | 'lazyToken';
|
|
248
111
|
type TargetFieldRefSource = 'string' | 'token';
|
|
@@ -571,7 +434,7 @@ type ContractInput<Family extends FamilyPackRef<string> = FamilyPackRef<string>,
|
|
|
571
434
|
*/
|
|
572
435
|
readonly namespaces?: readonly string[];
|
|
573
436
|
/**
|
|
574
|
-
* Target-supplied factory that materialises a `
|
|
437
|
+
* Target-supplied factory that materialises a `SqlNamespaceBase` concretion
|
|
575
438
|
* for a declared namespace coordinate. The SQL family layer is
|
|
576
439
|
* target-agnostic and cannot import concretions like
|
|
577
440
|
* `PostgresSchema` or `SqliteUnboundDatabase`; the factory is the
|
|
@@ -583,14 +446,8 @@ type ContractInput<Family extends FamilyPackRef<string> = FamilyPackRef<string>,
|
|
|
583
446
|
* `StorageTable.namespaceId` referenced by a model, and the
|
|
584
447
|
* framework `UNBOUND_NAMESPACE_ID` sentinel (always present so the
|
|
585
448
|
* 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
449
|
*/
|
|
593
|
-
readonly createNamespace
|
|
450
|
+
readonly createNamespace: (input: SqlNamespaceInput) => SqlNamespaceBase;
|
|
594
451
|
readonly types?: Types;
|
|
595
452
|
readonly models?: Models;
|
|
596
453
|
readonly codecLookup?: CodecLookup;
|
|
@@ -600,6 +457,15 @@ type ContractInput<Family extends FamilyPackRef<string> = FamilyPackRef<string>,
|
|
|
600
457
|
* default namespace. Fields reference the enum via `field.namedType(handle)`.
|
|
601
458
|
*/
|
|
602
459
|
readonly enums?: Record<string, EnumTypeHandle>;
|
|
460
|
+
/**
|
|
461
|
+
* Author-declared pack-entity handles, lowered by the pack that registered
|
|
462
|
+
* each handle's `entityKind` (through the SQL-family batch lowering hook)
|
|
463
|
+
* into namespace-scoped entry attachments at build time. Generic on
|
|
464
|
+
* purpose — neither this type nor the walk names a specific kind; a handle
|
|
465
|
+
* whose kind no composed pack registers is a build error. This is the only
|
|
466
|
+
* public channel for attaching pack entities.
|
|
467
|
+
*/
|
|
468
|
+
readonly entities?: readonly import('@prisma-next/sql-contract/entity-handle-lowering-hook').PackEntityHandle[];
|
|
603
469
|
};
|
|
604
470
|
declare function model<const ModelName extends string, Fields extends Record<string, ScalarFieldBuilder>, Relations extends Record<string, AnyRelationBuilder> = Record<never, never>>(modelName: ModelName, input: {
|
|
605
471
|
readonly fields: Fields;
|
|
@@ -715,7 +581,7 @@ type ResolveTemplateValue<Template, Args extends readonly unknown[]> = Template
|
|
|
715
581
|
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
582
|
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
583
|
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
|
|
584
|
+
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
585
|
type FieldHelperFunctionWithoutNamedConstraint<Descriptor extends AuthoringFieldPresetDescriptor> = Descriptor extends {
|
|
720
586
|
readonly args: infer Args extends readonly AuthoringArgumentDescriptor[];
|
|
721
587
|
} ? <const Params extends TupleFromArgumentDescriptors<Args>>(...args: Params) => FieldBuilderFromPresetDescriptor<Descriptor, Params> : () => FieldBuilderFromPresetDescriptor<Descriptor, readonly []>;
|
|
@@ -727,10 +593,10 @@ type FieldHelpersFromNamespace<Namespace> = { readonly [K in keyof Namespace]: N
|
|
|
727
593
|
//#endregion
|
|
728
594
|
//#region src/contract-types.d.ts
|
|
729
595
|
type ExtractCodecTypesFromPack<P> = P extends {
|
|
730
|
-
__codecTypes?: infer C
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
}
|
|
596
|
+
__codecTypes?: infer C extends Record<string, {
|
|
597
|
+
output: unknown;
|
|
598
|
+
}>;
|
|
599
|
+
} ? C : Record<string, never>;
|
|
734
600
|
type MergeExtensionCodecTypes<Packs extends Record<string, unknown>> = UnionToIntersection<{ [K in keyof Packs]: ExtractCodecTypesFromPack<Packs[K]> }[keyof Packs]>;
|
|
735
601
|
type MergeExtensionCodecTypesSafe<Packs> = Packs extends Record<string, unknown> ? keyof Packs extends never ? Record<string, never> : MergeExtensionCodecTypes<Packs> : Record<string, never>;
|
|
736
602
|
type ExtractIndexTypesFromPack<P> = P extends {
|
|
@@ -813,6 +679,9 @@ type FieldTypeRefOf<FieldState> = Present<FieldState extends {
|
|
|
813
679
|
type FieldNullableOf<FieldState> = FieldState extends {
|
|
814
680
|
readonly nullable: infer Nullable extends boolean;
|
|
815
681
|
} ? Nullable : boolean;
|
|
682
|
+
type FieldManyOf<FieldState> = FieldState extends {
|
|
683
|
+
readonly many?: true;
|
|
684
|
+
} ? true : false;
|
|
816
685
|
type FieldColumnOverrideOf<FieldState> = Present<FieldState extends {
|
|
817
686
|
readonly columnName?: infer ColumnName;
|
|
818
687
|
} ? ColumnName : never>;
|
|
@@ -865,17 +734,19 @@ type AttributeIdName<Definition, ModelName extends ModelNames<Definition>> = Pre
|
|
|
865
734
|
} ? Name : never>;
|
|
866
735
|
type ModelIdFieldNames<Definition, ModelName extends ModelNames<Definition>> = [AttributeIdFieldNames<Definition, ModelName>] extends [undefined] ? InlineIdFieldNames<Definition, ModelName> : AttributeIdFieldNames<Definition, ModelName>;
|
|
867
736
|
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> = {
|
|
737
|
+
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
738
|
readonly nativeType: NativeType;
|
|
870
739
|
readonly codecId: CodecId;
|
|
871
740
|
readonly nullable: Nullable;
|
|
872
741
|
readonly default?: ColumnDefault;
|
|
873
742
|
} & (TypeRef extends string ? {
|
|
874
743
|
readonly typeRef: TypeRef;
|
|
875
|
-
} : Record<
|
|
744
|
+
} : Record<never, never>) & (TypeParams extends Record<string, unknown> ? {
|
|
876
745
|
readonly typeParams: TypeParams;
|
|
877
|
-
} : Record<
|
|
878
|
-
|
|
746
|
+
} : Record<never, never>) & (Many extends true ? {
|
|
747
|
+
readonly many: true;
|
|
748
|
+
} : Record<never, never>);
|
|
749
|
+
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
750
|
type BuiltModels<Definition> = { readonly [ModelName in ModelNames<Definition>]: {
|
|
880
751
|
readonly storage: {
|
|
881
752
|
readonly table: ModelTableName<Definition, ModelName>;
|
|
@@ -967,10 +838,23 @@ type BuiltStorage<Definition> = {
|
|
|
967
838
|
};
|
|
968
839
|
} };
|
|
969
840
|
};
|
|
841
|
+
type StorageColumnManyOf<Col> = Col extends {
|
|
842
|
+
readonly many: true;
|
|
843
|
+
} ? true : false;
|
|
970
844
|
type EnumValueUnion<FieldState> = [FieldTypeRefOf<FieldState>] extends [EnumTypeHandle<string, infer Values>] ? readonly unknown[] extends Values ? never : Values[number] : never;
|
|
971
|
-
type
|
|
972
|
-
|
|
845
|
+
type DescriptorEntityMembers<Descriptor> = Descriptor extends {
|
|
846
|
+
readonly entityRef: {
|
|
847
|
+
readonly entity: {
|
|
848
|
+
readonly members: infer Members extends readonly string[];
|
|
849
|
+
};
|
|
850
|
+
};
|
|
851
|
+
} ? Members : never;
|
|
852
|
+
type DescriptorValueSetUnion<FieldState> = [FieldDescriptorOf<FieldState>] extends [never] ? never : readonly string[] extends DescriptorEntityMembers<FieldDescriptorOf<FieldState>> ? never : DescriptorEntityMembers<FieldDescriptorOf<FieldState>>[number];
|
|
853
|
+
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;
|
|
854
|
+
type FieldValueUnion<FieldState> = [EnumValueUnion<FieldState>] extends [never] ? DescriptorValueSetUnion<FieldState> : EnumValueUnion<FieldState>;
|
|
855
|
+
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
856
|
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> } } };
|
|
857
|
+
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
858
|
type SqlContractResult<Definition> = ContractWithTypeMaps<Omit<Contract<BuiltStorage<Definition>>, 'domain'> & {
|
|
975
859
|
readonly target: DefinitionTargetId<Definition>;
|
|
976
860
|
readonly targetFamily: 'sql';
|
|
@@ -982,7 +866,7 @@ type SqlContractResult<Definition> = ContractWithTypeMaps<Omit<Contract<BuiltSto
|
|
|
982
866
|
readonly extensionPacks: keyof DefinitionExtensionPacks<Definition> extends never ? Record<string, never> : DefinitionExtensionPacks<Definition>;
|
|
983
867
|
readonly capabilities: DerivedCapabilities<Definition>;
|
|
984
868
|
readonly enumAccessors: BuiltEnumAccessors<Definition>;
|
|
985
|
-
}, TypeMaps<CodecTypesFromDefinition<Definition>, Record<string, never>, FieldChannelTypes<Definition, 'output'>, FieldChannelTypes<Definition, 'input'>>>;
|
|
869
|
+
}, TypeMaps<CodecTypesFromDefinition<Definition>, Record<string, never>, FieldChannelTypes<Definition, 'output'>, FieldChannelTypes<Definition, 'input'>, StorageColumnChannelTypes<Definition, 'output'>, StorageColumnChannelTypes<Definition, 'input'>>>;
|
|
986
870
|
//#endregion
|
|
987
871
|
//#region src/composed-authoring-helpers.d.ts
|
|
988
872
|
type ExtractTypeNamespaceFromPack<Pack> = ExtractAuthoringNamespaceFromPack<Pack, 'type', Record<never, never>>;
|
|
@@ -1031,6 +915,20 @@ type ComposedAuthoringHelpers<Family extends FamilyPackRef<string>, Target exten
|
|
|
1031
915
|
};
|
|
1032
916
|
//#endregion
|
|
1033
917
|
//#region src/contract-definition.d.ts
|
|
918
|
+
/**
|
|
919
|
+
* Namespace-scoped pack-entity attachments, the internal build IR carrying
|
|
920
|
+
* the lowered `entities` handle list: namespace id → entity kind (the
|
|
921
|
+
* discriminator the target/extension pack registered its
|
|
922
|
+
* `AuthoringContributions.entityTypes` descriptor under, e.g. `native_enum`)
|
|
923
|
+
* → entity name → the lowered entity instance. Generic on purpose — neither
|
|
924
|
+
* the framework nor `contract-ts` names a specific entity kind here; the
|
|
925
|
+
* shape mirrors `SqlNamespaceInput.entries` (`entries.<kind>[name]`), just
|
|
926
|
+
* namespace-nested so an attachment can target any declared namespace
|
|
927
|
+
* (default or named), not only the contract's default namespace. Produced by
|
|
928
|
+
* the generic entity-handle walk in `buildContractDefinition`; never an
|
|
929
|
+
* author-facing input.
|
|
930
|
+
*/
|
|
931
|
+
type AttachedEntities = Readonly<Record<string, Readonly<Record<string, Readonly<Record<string, unknown>>>>>>;
|
|
1034
932
|
interface FieldNode {
|
|
1035
933
|
readonly fieldName: string;
|
|
1036
934
|
readonly columnName: string;
|
|
@@ -1181,8 +1079,8 @@ interface ContractDefinition {
|
|
|
1181
1079
|
* `SqlStorage.namespaces` together with `createNamespace`.
|
|
1182
1080
|
*/
|
|
1183
1081
|
readonly namespaces?: readonly string[];
|
|
1184
|
-
/** Target-supplied factory that materialises a `
|
|
1185
|
-
readonly createNamespace
|
|
1082
|
+
/** Target-supplied factory that materialises a `SqlNamespaceBase` concretion for a declared namespace coordinate. */
|
|
1083
|
+
readonly createNamespace: (input: SqlNamespaceInput) => SqlNamespaceBase;
|
|
1186
1084
|
readonly models: readonly ModelNode[];
|
|
1187
1085
|
readonly valueObjects?: readonly ValueObjectNode[];
|
|
1188
1086
|
/**
|
|
@@ -1191,6 +1089,17 @@ interface ContractDefinition {
|
|
|
1191
1089
|
* default namespace.
|
|
1192
1090
|
*/
|
|
1193
1091
|
readonly enums?: Record<string, EnumTypeHandle>;
|
|
1092
|
+
/**
|
|
1093
|
+
* Pack-entity attachments lowered from the `entities` handle list, keyed by
|
|
1094
|
+
* namespace then entity kind then name. Each entity lands in
|
|
1095
|
+
* `storage.namespaces[ns].entries.<kind>`; when the registered entity-type
|
|
1096
|
+
* descriptor's factory output implements the
|
|
1097
|
+
* `SqlValueSetDerivingEntityTypeOutput.deriveValueSet` hook, the derived
|
|
1098
|
+
* value-set also folds into `entries.valueSet`, mirroring how `enums` flows
|
|
1099
|
+
* there. Internal build IR — populated by `buildContractDefinition`, not an
|
|
1100
|
+
* author input.
|
|
1101
|
+
*/
|
|
1102
|
+
readonly attachedEntities?: AttachedEntities;
|
|
1194
1103
|
}
|
|
1195
1104
|
//#endregion
|
|
1196
1105
|
//#region src/build-contract.d.ts
|
|
@@ -1218,11 +1127,12 @@ type ContractDefinition$1<Family extends FamilyPackRef<string>, Target extends T
|
|
|
1218
1127
|
readonly foreignKeyDefaults?: ForeignKeyDefaults;
|
|
1219
1128
|
readonly defaultControlPolicy?: ControlPolicy;
|
|
1220
1129
|
readonly namespaces?: Namespaces;
|
|
1221
|
-
readonly createNamespace
|
|
1130
|
+
readonly createNamespace: (input: SqlNamespaceInput) => SqlNamespaceBase;
|
|
1222
1131
|
readonly types?: Types;
|
|
1223
1132
|
readonly models?: Models;
|
|
1224
1133
|
readonly codecLookup?: CodecLookup;
|
|
1225
1134
|
readonly enums?: Enums;
|
|
1135
|
+
readonly entities?: readonly PackEntityHandle[];
|
|
1226
1136
|
};
|
|
1227
1137
|
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
1138
|
readonly family: Family;
|
|
@@ -1233,16 +1143,18 @@ type ContractScaffold<Family extends FamilyPackRef<string>, Target extends Targe
|
|
|
1233
1143
|
readonly foreignKeyDefaults?: ForeignKeyDefaults;
|
|
1234
1144
|
readonly defaultControlPolicy?: ControlPolicy;
|
|
1235
1145
|
readonly namespaces?: Namespaces;
|
|
1236
|
-
readonly createNamespace
|
|
1146
|
+
readonly createNamespace: (input: SqlNamespaceInput) => SqlNamespaceBase;
|
|
1237
1147
|
readonly types?: never;
|
|
1238
1148
|
readonly models?: never;
|
|
1239
1149
|
readonly codecLookup?: CodecLookup;
|
|
1240
1150
|
readonly enums?: Enums;
|
|
1151
|
+
readonly entities?: readonly PackEntityHandle[];
|
|
1241
1152
|
};
|
|
1242
1153
|
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
1154
|
readonly types?: Types;
|
|
1244
1155
|
readonly models?: Models;
|
|
1245
1156
|
readonly enums?: Enums;
|
|
1157
|
+
readonly entities?: readonly PackEntityHandle[];
|
|
1246
1158
|
};
|
|
1247
1159
|
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
1160
|
readonly extensionPacks?: ExtensionPacks;
|
|
@@ -1251,11 +1163,12 @@ type BoundDefinitionInput<Types extends Record<string, StorageTypeInstance> = Re
|
|
|
1251
1163
|
readonly foreignKeyDefaults?: ForeignKeyDefaults;
|
|
1252
1164
|
readonly defaultControlPolicy?: ControlPolicy;
|
|
1253
1165
|
readonly namespaces?: Namespaces;
|
|
1254
|
-
readonly createNamespace
|
|
1166
|
+
readonly createNamespace: (input: SqlNamespaceInput) => SqlNamespaceBase;
|
|
1255
1167
|
readonly types?: Types;
|
|
1256
1168
|
readonly models?: Models;
|
|
1257
1169
|
readonly codecLookup?: CodecLookup;
|
|
1258
1170
|
readonly enums?: Record<string, EnumTypeHandle>;
|
|
1171
|
+
readonly entities?: readonly PackEntityHandle[];
|
|
1259
1172
|
};
|
|
1260
1173
|
type LiteralEnums<E extends Record<string, EnumTypeHandle>> = string extends keyof E ? Record<never, never> : E;
|
|
1261
1174
|
type MergeEnums<ScaffoldEnums extends Record<string, EnumTypeHandle>, FactoryEnums extends Record<string, EnumTypeHandle>> = LiteralEnums<ScaffoldEnums> & LiteralEnums<FactoryEnums>;
|
|
@@ -1279,9 +1192,13 @@ declare function buildBoundContract<const F extends FamilyPackRef<string>, const
|
|
|
1279
1192
|
readonly types?: Record<string, StorageTypeInstance>;
|
|
1280
1193
|
readonly models?: Record<string, ModelLike>;
|
|
1281
1194
|
readonly enums?: Record<string, EnumTypeHandle>;
|
|
1195
|
+
readonly entities?: readonly PackEntityHandle[];
|
|
1282
1196
|
}>(family: F, target: T, definition: Definition, factory: (helpers: ComposedAuthoringHelpers<F, T, NonNullable<Definition['extensionPacks']>>) => Built): SqlContractResult<WithFamilyTarget<Definition & Built, F, T>>;
|
|
1283
1197
|
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
1198
|
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>>>;
|
|
1285
1199
|
//#endregion
|
|
1286
|
-
|
|
1200
|
+
//#region src/contract-lowering.d.ts
|
|
1201
|
+
declare function buildContractDefinition(definition: ContractInput): ContractDefinition;
|
|
1202
|
+
//#endregion
|
|
1203
|
+
export { type AttachedEntities, type BoundEnumType, type CodecInput, type CodecTypeMap, type ComposedAuthoringHelpers, type ContractDefinition, type ContractInput, type ContractModelBuilder, type EnumMember, type EnumTypeHandle, type ExtractCodecTypesFromPack, type FieldNode, type ForeignKeyNode, type IndexNode, type MergeEnums, type ModelLike, type ModelNode, type PrimaryKeyNode, type RelationNode, type ScalarFieldBuilder, type TargetFieldRef, type UniqueConstraintNode, bindEnumType, buildBoundContract, buildContractDefinition, buildSqlContractFromDefinition, defineContract, enumType, extensionModel, field, member, model, rel };
|
|
1287
1204
|
//# sourceMappingURL=contract-builder.d.mts.map
|