@prisma-next/sql-relational-core 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ddl-types-D3vlEjMA.d.mts → ddl-types-BVO002FS.d.mts} +6 -2
- package/dist/ddl-types-BVO002FS.d.mts.map +1 -0
- package/dist/{ddl-types-X9_XHUl0.mjs → ddl-types-DAox2c8w.mjs} +4 -1
- package/dist/ddl-types-DAox2c8w.mjs.map +1 -0
- package/dist/{errors-CPLfzKkw.d.mts → errors-COyZClzw.d.mts} +2 -2
- package/dist/{errors-CPLfzKkw.d.mts.map → errors-COyZClzw.d.mts.map} +1 -1
- package/dist/exports/ast.d.mts +11 -3
- package/dist/exports/ast.d.mts.map +1 -1
- package/dist/exports/ast.mjs +3 -3
- package/dist/exports/codec-descriptor-registry.d.mts +1 -1
- package/dist/exports/codec-descriptor-registry.d.mts.map +1 -1
- package/dist/exports/codec-descriptor-registry.mjs +2 -13
- package/dist/exports/codec-descriptor-registry.mjs.map +1 -1
- package/dist/exports/contract-free.d.mts +60 -3
- package/dist/exports/contract-free.d.mts.map +1 -1
- package/dist/exports/contract-free.mjs +123 -3
- package/dist/exports/contract-free.mjs.map +1 -1
- package/dist/exports/errors.d.mts +1 -1
- package/dist/exports/expression.d.mts +1 -1
- package/dist/exports/expression.mjs +1 -1
- package/dist/exports/middleware.d.mts +1 -1
- package/dist/exports/plan.d.mts +2 -2
- package/dist/exports/query-lane-context.d.mts +1 -1
- package/dist/exports/types.d.mts +3 -3
- package/dist/index.d.mts +10 -10
- package/dist/index.mjs +3 -3
- package/dist/{middleware-BXSFukKU.d.mts → middleware-Dyyo4IP1.d.mts} +2 -2
- package/dist/{middleware-BXSFukKU.d.mts.map → middleware-Dyyo4IP1.d.mts.map} +1 -1
- package/dist/{plan-DObuWSWi.d.mts → plan-DUjdGLY3.d.mts} +2 -2
- package/dist/{plan-DObuWSWi.d.mts.map → plan-DUjdGLY3.d.mts.map} +1 -1
- package/dist/{query-lane-context-CY0-e8Qo.d.mts → query-lane-context-DFnJVqUH.d.mts} +9 -1
- package/dist/query-lane-context-DFnJVqUH.d.mts.map +1 -0
- package/dist/{sql-execution-plan-JwVeAzXt.d.mts → sql-execution-plan-DjMEAjKK.d.mts} +2 -2
- package/dist/{sql-execution-plan-JwVeAzXt.d.mts.map → sql-execution-plan-DjMEAjKK.d.mts.map} +1 -1
- package/dist/{types-LGikJRYV.d.mts → types-CUHnDsdV.d.mts} +3 -3
- package/dist/{types-LGikJRYV.d.mts.map → types-CUHnDsdV.d.mts.map} +1 -1
- package/dist/{types-BbGUx5Bi.d.mts → types-DQrmgP8Y.d.mts} +17 -5
- package/dist/{types-BbGUx5Bi.d.mts.map → types-DQrmgP8Y.d.mts.map} +1 -1
- package/dist/{types-D72v8s92.mjs → types-lJUc6cY-.mjs} +78 -18
- package/dist/types-lJUc6cY-.mjs.map +1 -0
- package/dist/types-lWs6p0ny.d.mts +233 -0
- package/dist/types-lWs6p0ny.d.mts.map +1 -0
- package/package.json +11 -11
- package/src/ast/ddl-types.ts +5 -0
- package/src/ast/driver-types.ts +8 -0
- package/src/ast/types.ts +98 -19
- package/src/codec-ref-for-column.ts +2 -35
- package/src/contract-free/column.ts +2 -0
- package/src/contract-free/dml.ts +5 -0
- package/src/contract-free/table.ts +191 -1
- package/src/exports/contract-free.ts +5 -0
- package/src/query-lane-context.ts +8 -0
- package/src/types.ts +134 -22
- package/dist/ddl-types-D3vlEjMA.d.mts.map +0 -1
- package/dist/ddl-types-X9_XHUl0.mjs.map +0 -1
- package/dist/query-lane-context-CY0-e8Qo.d.mts.map +0 -1
- package/dist/types-CQVke4QO.d.mts +0 -181
- package/dist/types-CQVke4QO.d.mts.map +0 -1
- package/dist/types-D72v8s92.mjs.map +0 -1
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { Y as ParamRef, g as ColumnRef } from "./types-DQrmgP8Y.mjs";
|
|
2
|
+
import { r as ExecutionContext } from "./query-lane-context-DFnJVqUH.mjs";
|
|
3
|
+
import { t as SqlExecutionPlan } from "./sql-execution-plan-DjMEAjKK.mjs";
|
|
4
|
+
import { Contract } from "@prisma-next/contract/types";
|
|
5
|
+
import { ExtractFieldOutputTypes, SqlStorage, StorageColumn } from "@prisma-next/sql-contract/types";
|
|
6
|
+
import { ParamSpec } from "@prisma-next/operations";
|
|
7
|
+
import { SqlLoweringSpec } from "@prisma-next/sql-operations";
|
|
8
|
+
|
|
9
|
+
//#region src/types.d.ts
|
|
10
|
+
type Expr = ColumnRef | ParamRef;
|
|
11
|
+
/**
|
|
12
|
+
* The minimal contract shape the per-namespace column resolver needs: the
|
|
13
|
+
* application-domain models and the storage tables, both keyed by namespace
|
|
14
|
+
* coordinate, plus (via the optional TypeMaps phantom key, read structurally by
|
|
15
|
+
* {@link ExtractFieldOutputTypes}) the refined field-output map. Every emitted
|
|
16
|
+
* `Contract<SqlStorage>` satisfies it, as does `sql-builder`'s `TableProxyContract`
|
|
17
|
+
* — so the resolver indexes the coordinate directly without forcing callers to
|
|
18
|
+
* carry the full `Contract`.
|
|
19
|
+
*/
|
|
20
|
+
type ColumnResolutionContract = {
|
|
21
|
+
readonly domain: {
|
|
22
|
+
readonly namespaces: Readonly<Record<string, {
|
|
23
|
+
readonly models: Readonly<Record<string, unknown>>;
|
|
24
|
+
}>>;
|
|
25
|
+
};
|
|
26
|
+
readonly storage: {
|
|
27
|
+
readonly namespaces: Readonly<Record<string, {
|
|
28
|
+
readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
29
|
+
}>>;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
type NamespaceModels<TContract extends ColumnResolutionContract, NsId extends string> = TContract['domain']['namespaces'][NsId] extends {
|
|
33
|
+
readonly models: infer Models extends Record<string, unknown>;
|
|
34
|
+
} ? Models : never;
|
|
35
|
+
type ExtractTableToModel<TContract extends ColumnResolutionContract, NsId extends string, TableName extends string> = NamespaceModels<TContract, NsId> extends infer Models extends Record<string, unknown> ? { [M in keyof Models & string]: Models[M] extends {
|
|
36
|
+
readonly storage: {
|
|
37
|
+
readonly table: TableName;
|
|
38
|
+
};
|
|
39
|
+
} ? M : never }[keyof Models & string] : never;
|
|
40
|
+
type ExtractColumnToField<TContract extends ColumnResolutionContract, NsId extends string, TableName extends string, ColumnName extends string> = ExtractTableToModel<TContract, NsId, TableName> extends infer ModelName extends string ? NamespaceModels<TContract, NsId> extends infer Models extends Record<string, unknown> ? ModelName & keyof Models extends infer MKey extends string ? Models[MKey] extends {
|
|
41
|
+
readonly storage: {
|
|
42
|
+
readonly fields: infer Fields extends Record<string, unknown>;
|
|
43
|
+
};
|
|
44
|
+
} ? { [F in keyof Fields & string]: Fields[F] extends {
|
|
45
|
+
readonly column: ColumnName;
|
|
46
|
+
} ? F : never }[keyof Fields & string] : never : never : never : never;
|
|
47
|
+
/** Resolves to `never` when the table or column is absent in the namespace. */
|
|
48
|
+
type NamespaceStorageColumn<TContract extends ColumnResolutionContract, NsId extends string, TableName extends string, ColumnName extends string> = TContract['storage']['namespaces'][NsId] extends {
|
|
49
|
+
readonly entries: {
|
|
50
|
+
readonly table: infer Tables extends Record<string, unknown>;
|
|
51
|
+
};
|
|
52
|
+
} ? TableName extends keyof Tables ? Tables[TableName] extends {
|
|
53
|
+
readonly columns: infer Columns extends Record<string, unknown>;
|
|
54
|
+
} ? ColumnName extends keyof Columns ? Columns[ColumnName] extends StorageColumn ? Columns[ColumnName] : never : never : never : never : never;
|
|
55
|
+
type FallbackCodecLookup<ColumnMeta extends StorageColumn, CodecTypes extends Record<string, {
|
|
56
|
+
readonly output: unknown;
|
|
57
|
+
}>> = ColumnMeta extends {
|
|
58
|
+
codecId: infer CodecId extends string;
|
|
59
|
+
} ? CodecId extends keyof CodecTypes ? CodecTypes[CodecId] extends {
|
|
60
|
+
readonly output: infer O;
|
|
61
|
+
} ? ColumnMeta extends {
|
|
62
|
+
nullable: true;
|
|
63
|
+
} ? O | null : O : unknown : unknown : unknown;
|
|
64
|
+
/**
|
|
65
|
+
* The refined (typeParam-applied) JS output type for a field within a namespace
|
|
66
|
+
* coordinate, read from the emitter's namespace-nested `FieldOutputTypes` map at
|
|
67
|
+
* `FieldOutputTypes[NsId][Model][Field]`. This preserves parameterized codec
|
|
68
|
+
* refinements (e.g. `Vector<N>`, `Char<N>`) that a bare codec-output lookup
|
|
69
|
+
* would drop. Resolves to `never` when the coordinate is absent from the map.
|
|
70
|
+
*/
|
|
71
|
+
type NamespaceFieldOutput<TContract extends ColumnResolutionContract, NsId extends string, ModelName extends string, FieldName extends string> = ExtractFieldOutputTypes<TContract> extends infer Outputs ? NsId extends keyof Outputs ? Outputs[NsId] extends infer NamespaceOutputs ? ModelName extends keyof NamespaceOutputs ? NamespaceOutputs[ModelName] extends infer ModelOutputs ? FieldName extends keyof ModelOutputs ? ModelOutputs[FieldName] : never : never : never : never : never : never;
|
|
72
|
+
/**
|
|
73
|
+
* The secondary resolution path, taken for a storage column not backed by a
|
|
74
|
+
* domain model field in the namespace (e.g. a column with no corresponding
|
|
75
|
+
* field); refined model fields resolve via {@link NamespaceFieldOutput}.
|
|
76
|
+
*/
|
|
77
|
+
type ColumnCodecFallback<TContract extends ColumnResolutionContract, NsId extends string, TableName extends string, ColumnName extends string, CodecTypes extends Record<string, {
|
|
78
|
+
readonly output: unknown;
|
|
79
|
+
}>> = NamespaceStorageColumn<TContract, NsId, TableName, ColumnName> extends infer ColumnMeta ? [ColumnMeta] extends [never] ? never : ColumnMeta extends StorageColumn ? FallbackCodecLookup<ColumnMeta, CodecTypes> : never : never;
|
|
80
|
+
/**
|
|
81
|
+
* Type-level operation signature.
|
|
82
|
+
* Represents an operation at the type level for use in contract type maps.
|
|
83
|
+
*/
|
|
84
|
+
type OperationTypeSignature = {
|
|
85
|
+
readonly args: ReadonlyArray<ParamSpec>;
|
|
86
|
+
readonly returns: ParamSpec;
|
|
87
|
+
readonly lowering: SqlLoweringSpec;
|
|
88
|
+
readonly capabilities?: ReadonlyArray<string>;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Type-level operation registry.
|
|
92
|
+
* Maps typeId → operations, where operations is a record of method name → operation signature.
|
|
93
|
+
*
|
|
94
|
+
* Example:
|
|
95
|
+
* ```typescript
|
|
96
|
+
* type MyOperations: OperationTypes = {
|
|
97
|
+
* 'pg/vector@1': {
|
|
98
|
+
* cosineDistance: {
|
|
99
|
+
* args: [{ codecId: 'pg/vector@1'; nullable: false }];
|
|
100
|
+
* returns: { codecId: 'core/float8'; nullable: false };
|
|
101
|
+
* lowering: { targetFamily: 'sql'; strategy: 'function'; template: '...' };
|
|
102
|
+
* };
|
|
103
|
+
* };
|
|
104
|
+
* };
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
type OperationTypes = Record<string, Record<string, OperationTypeSignature>>;
|
|
108
|
+
/**
|
|
109
|
+
* CodecTypes represents a map of typeId to codec definitions.
|
|
110
|
+
* Each codec definition must have an `output` property indicating the JavaScript type.
|
|
111
|
+
*
|
|
112
|
+
* Example:
|
|
113
|
+
* ```typescript
|
|
114
|
+
* type MyCodecTypes: CodecTypes = {
|
|
115
|
+
* 'pg/int4@1': { output: number };
|
|
116
|
+
* 'pg/text@1': { output: string };
|
|
117
|
+
* };
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
type CodecTypes = Record<string, {
|
|
121
|
+
readonly output: unknown;
|
|
122
|
+
}>;
|
|
123
|
+
/**
|
|
124
|
+
* Extracts operations for a given typeId from the operation registry.
|
|
125
|
+
* Returns an empty record if the typeId is not found.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* type Ops = OperationsForTypeId<'pg/vector@1', MyOperations>;
|
|
130
|
+
* // Ops = { cosineDistance: { ... }, l2Distance: { ... } }
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
type OperationsForTypeId<TypeId extends string, Operations extends OperationTypes> = Operations extends Record<string, never> ? Record<string, never> : TypeId extends keyof Operations ? Operations[TypeId] : Record<string, never>;
|
|
134
|
+
/**
|
|
135
|
+
* Resolves the JavaScript output type of a column addressed by an explicit
|
|
136
|
+
* namespace coordinate.
|
|
137
|
+
*
|
|
138
|
+
* The table→model and column→field mapping is resolved per-namespace from
|
|
139
|
+
* `domain.namespaces[NsId]['models']`, and the refined output type from the
|
|
140
|
+
* emitter's namespace-nested `FieldOutputTypes[NsId][Model][Field]` — so a bare
|
|
141
|
+
* table name shared across namespaces resolves to each namespace's own field,
|
|
142
|
+
* and parameterized codec refinements (e.g. `Vector<N>`) are preserved. A
|
|
143
|
+
* storage column not backed by a model field in the namespace falls back to a
|
|
144
|
+
* codec-output lookup; a column absent in the namespace resolves to `never`.
|
|
145
|
+
*/
|
|
146
|
+
type ComputeColumnJsType<TContract extends ColumnResolutionContract, NsId extends string, TableName extends string, ColumnName extends string, CodecTypes extends Record<string, {
|
|
147
|
+
readonly output: unknown;
|
|
148
|
+
}>> = ExtractTableToModel<TContract, NsId, TableName> extends infer ModelName ? [ModelName] extends [never] ? ColumnCodecFallback<TContract, NsId, TableName, ColumnName, CodecTypes> : ModelName extends string ? ExtractColumnToField<TContract, NsId, TableName, ColumnName> extends infer FieldName ? [FieldName] extends [never] ? ColumnCodecFallback<TContract, NsId, TableName, ColumnName, CodecTypes> : FieldName extends string ? NamespaceFieldOutput<TContract, NsId, ModelName, FieldName> extends infer Out ? [Out] extends [never] ? ColumnCodecFallback<TContract, NsId, TableName, ColumnName, CodecTypes> : Out : never : never : never : never : never;
|
|
149
|
+
/**
|
|
150
|
+
* Alias for the SQL-domain executable plan, exposed under the legacy
|
|
151
|
+
* `SqlPlan` name for compatibility with SQL builder/utility call sites.
|
|
152
|
+
* The canonical name is `SqlExecutionPlan` (`./sql-execution-plan`).
|
|
153
|
+
*/
|
|
154
|
+
type SqlPlan<Row = unknown> = SqlExecutionPlan<Row>;
|
|
155
|
+
/**
|
|
156
|
+
* Helper types for extracting contract structure.
|
|
157
|
+
*/
|
|
158
|
+
type TablesOf<TContract> = TContract extends {
|
|
159
|
+
storage: {
|
|
160
|
+
tables: infer U;
|
|
161
|
+
};
|
|
162
|
+
} ? U : never;
|
|
163
|
+
type TableKey<TContract> = Extract<keyof TablesOf<TContract>, string>;
|
|
164
|
+
/**
|
|
165
|
+
* Unique symbol for metadata property to avoid collisions with user-defined properties
|
|
166
|
+
*/
|
|
167
|
+
declare const META: unique symbol;
|
|
168
|
+
/**
|
|
169
|
+
* Extracts metadata from a type that has a META property
|
|
170
|
+
*/
|
|
171
|
+
type Meta<T extends {
|
|
172
|
+
[META]: unknown;
|
|
173
|
+
}> = T[typeof META];
|
|
174
|
+
/**
|
|
175
|
+
* Metadata interface for table definitions
|
|
176
|
+
*/
|
|
177
|
+
interface TableMetadata<Name extends string> {
|
|
178
|
+
name: Name;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Metadata interface for model definitions
|
|
182
|
+
*/
|
|
183
|
+
interface ModelMetadata<Name extends string> {
|
|
184
|
+
name: Name;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Base interface for table definitions with metadata
|
|
188
|
+
* Used in contract.d.ts to define storage-level table types
|
|
189
|
+
*/
|
|
190
|
+
interface TableDef<Name extends string> {
|
|
191
|
+
readonly [META]: TableMetadata<Name>;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Base interface for model definitions with metadata
|
|
195
|
+
* Used in contract.d.ts to define application-level model types
|
|
196
|
+
*/
|
|
197
|
+
interface ModelDef<Name extends string> {
|
|
198
|
+
readonly [META]: ModelMetadata<Name>;
|
|
199
|
+
}
|
|
200
|
+
type ColumnsOf<TContract, K extends TableKey<TContract>> = K extends keyof TablesOf<TContract> ? TablesOf<TContract>[K] extends {
|
|
201
|
+
columns: infer C;
|
|
202
|
+
} ? C : never : never;
|
|
203
|
+
interface RawTemplateOptions {
|
|
204
|
+
readonly annotations?: Record<string, unknown>;
|
|
205
|
+
}
|
|
206
|
+
interface RawFunctionOptions extends RawTemplateOptions {
|
|
207
|
+
readonly params: ReadonlyArray<unknown>;
|
|
208
|
+
}
|
|
209
|
+
type RawTemplateFactory = (strings: TemplateStringsArray, ...values: readonly unknown[]) => SqlExecutionPlan;
|
|
210
|
+
interface RawFactory extends RawTemplateFactory {
|
|
211
|
+
(text: string, options: RawFunctionOptions): SqlExecutionPlan;
|
|
212
|
+
with(options: RawTemplateOptions): RawTemplateFactory;
|
|
213
|
+
}
|
|
214
|
+
interface RuntimeError extends Error {
|
|
215
|
+
readonly code: string;
|
|
216
|
+
readonly category: 'PLAN';
|
|
217
|
+
readonly severity: 'error';
|
|
218
|
+
readonly details?: Record<string, unknown>;
|
|
219
|
+
readonly hints?: readonly string[];
|
|
220
|
+
readonly docs?: readonly string[];
|
|
221
|
+
}
|
|
222
|
+
interface BuildParamsMap {
|
|
223
|
+
readonly [name: string]: unknown;
|
|
224
|
+
}
|
|
225
|
+
interface BuildOptions {
|
|
226
|
+
readonly params?: BuildParamsMap;
|
|
227
|
+
}
|
|
228
|
+
interface SqlBuilderOptions<TContract extends Contract<SqlStorage> = Contract<SqlStorage>> {
|
|
229
|
+
readonly context: ExecutionContext<TContract>;
|
|
230
|
+
}
|
|
231
|
+
//#endregion
|
|
232
|
+
export { TableKey as C, TableDef as S, TablesOf as T, RawTemplateFactory as _, ColumnsOf as a, SqlBuilderOptions as b, META as c, ModelMetadata as d, OperationTypeSignature as f, RawFunctionOptions as g, RawFactory as h, ColumnResolutionContract as i, Meta as l, OperationsForTypeId as m, BuildParamsMap as n, ComputeColumnJsType as o, OperationTypes as p, CodecTypes as r, Expr as s, BuildOptions as t, ModelDef as u, RawTemplateOptions as v, TableMetadata as w, SqlPlan as x, RuntimeError as y };
|
|
233
|
+
//# sourceMappingURL=types-lWs6p0ny.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-lWs6p0ny.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;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A,UAGd,kBAAA,SAA2B,kBAAkB;EAAA,SACnD,MAAA,EAAQ,aAAA;AAAA;AAAA,KAGP,kBAAA,IACV,OAAA,EAAS,oBAAA,KACN,MAAA,yBACA,gBAAgB;AAAA,UAEJ,UAAA,SAAmB,kBAAA;EAAA,CACjC,IAAA,UAAc,OAAA,EAAS,kBAAA,GAAqB,gBAAA;EAC7C,IAAA,CAAK,OAAA,EAAS,kBAAA,GAAqB,kBAAA;AAAA;AAAA,UAGpB,YAAA,SAAqB,KAAK;EAAA,SAChC,IAAA;EAAA,SACA,QAAA;EAAA,SACA,QAAA;EAAA,SACA,OAAA,GAAU,MAAA;EAAA,SACV,KAAA;EAAA,SACA,IAAA;AAAA;AAAA,UAGM,cAAA;EAAA,UACL,IAAY;AAAA;AAAA,UAGP,YAAA;EAAA,SACN,MAAA,GAAS,cAAc;AAAA;AAAA,UAGjB,iBAAA,mBAAoC,QAAA,CAAS,UAAA,IAAc,QAAA,CAAS,UAAA;EAAA,SAC1E,OAAA,EAAS,gBAAA,CAAiB,SAAA;AAAA"}
|
package/package.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-relational-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "AST types, query lane context, and type utilities for Prisma Next SQL lanes",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/contract": "0.
|
|
10
|
-
"@prisma-next/framework-components": "0.
|
|
11
|
-
"@prisma-next/operations": "0.
|
|
12
|
-
"@prisma-next/sql-contract": "0.
|
|
13
|
-
"@prisma-next/sql-operations": "0.
|
|
14
|
-
"@prisma-next/utils": "0.
|
|
9
|
+
"@prisma-next/contract": "0.14.0",
|
|
10
|
+
"@prisma-next/framework-components": "0.14.0",
|
|
11
|
+
"@prisma-next/operations": "0.14.0",
|
|
12
|
+
"@prisma-next/sql-contract": "0.14.0",
|
|
13
|
+
"@prisma-next/sql-operations": "0.14.0",
|
|
14
|
+
"@prisma-next/utils": "0.14.0",
|
|
15
15
|
"@standard-schema/spec": "^1.1.0",
|
|
16
16
|
"arktype": "^2.2.0",
|
|
17
17
|
"ts-toolbelt": "^9.6.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@prisma-next/sql-contract-ts": "0.
|
|
21
|
-
"@prisma-next/test-utils": "0.
|
|
22
|
-
"@prisma-next/tsconfig": "0.
|
|
23
|
-
"@prisma-next/tsdown": "0.
|
|
20
|
+
"@prisma-next/sql-contract-ts": "0.14.0",
|
|
21
|
+
"@prisma-next/test-utils": "0.14.0",
|
|
22
|
+
"@prisma-next/tsconfig": "0.14.0",
|
|
23
|
+
"@prisma-next/tsdown": "0.14.0",
|
|
24
24
|
"tsdown": "0.22.1",
|
|
25
25
|
"typescript": "5.9.3",
|
|
26
26
|
"vitest": "4.1.8"
|
package/src/ast/ddl-types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ColumnDefaultLiteralInputValue } from '@prisma-next/contract/types';
|
|
2
2
|
import { isColumnDefaultLiteralInputValue } from '@prisma-next/contract/types';
|
|
3
3
|
import type { ReferentialAction } from '@prisma-next/sql-contract/types';
|
|
4
|
+
import type { CodecRef } from './codec-types';
|
|
4
5
|
import type { AnyParamRef } from './types';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -71,6 +72,8 @@ export class DdlColumn {
|
|
|
71
72
|
readonly notNull?: boolean | undefined;
|
|
72
73
|
readonly primaryKey?: boolean | undefined;
|
|
73
74
|
readonly default?: AnyDdlColumnDefault | undefined;
|
|
75
|
+
/** Codec identity for this column. When present, the DDL walker resolves the codec via `codecLookup.get(codecRef.codecId)` and calls `codec.encode(default.value, {})` to obtain the wire value before inlining the literal default into the DDL string. When absent, literal defaults follow RawSqlLiteral wire-scalar semantics (string / number / boolean / bigint / null / Uint8Array / Date inlined directly). */
|
|
76
|
+
readonly codecRef?: CodecRef | undefined;
|
|
74
77
|
|
|
75
78
|
constructor(options: {
|
|
76
79
|
readonly name: string;
|
|
@@ -78,12 +81,14 @@ export class DdlColumn {
|
|
|
78
81
|
readonly notNull?: boolean;
|
|
79
82
|
readonly primaryKey?: boolean;
|
|
80
83
|
readonly default?: AnyDdlColumnDefault;
|
|
84
|
+
readonly codecRef?: CodecRef;
|
|
81
85
|
}) {
|
|
82
86
|
this.name = options.name;
|
|
83
87
|
this.type = options.type;
|
|
84
88
|
this.notNull = options.notNull;
|
|
85
89
|
this.primaryKey = options.primaryKey;
|
|
86
90
|
this.default = options.default;
|
|
91
|
+
this.codecRef = options.codecRef;
|
|
87
92
|
Object.freeze(this);
|
|
88
93
|
}
|
|
89
94
|
}
|
package/src/ast/driver-types.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A fully lowered SQL statement ready for a driver to execute: SQL text plus
|
|
3
|
+
* driver-ready (codec-encoded) parameter values. The output of the control
|
|
4
|
+
* adapter's `lowerToExecuteRequest`, handed to a driver via `SqlQueryable.query`
|
|
5
|
+
* or `execute`. Inline-substituted positions (e.g. DDL `DEFAULT`
|
|
6
|
+
* clauses) carry no param; `params` holds the wire values for the `$N`/`?`
|
|
7
|
+
* positions, in order.
|
|
8
|
+
*/
|
|
1
9
|
export interface SqlExecuteRequest {
|
|
2
10
|
readonly sql: string;
|
|
3
11
|
readonly params?: readonly unknown[];
|
package/src/ast/types.ts
CHANGED
|
@@ -378,6 +378,35 @@ export class DerivedTableSource extends FromSource {
|
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
380
|
|
|
381
|
+
export class FunctionSource extends FromSource {
|
|
382
|
+
readonly kind = 'function-source' as const;
|
|
383
|
+
readonly fn: string;
|
|
384
|
+
readonly args: ReadonlyArray<AnyExpression>;
|
|
385
|
+
readonly alias: string | undefined;
|
|
386
|
+
|
|
387
|
+
protected constructor(fn: string, args: ReadonlyArray<AnyExpression>, alias?: string) {
|
|
388
|
+
super();
|
|
389
|
+
this.fn = fn;
|
|
390
|
+
this.args = frozenArrayCopy(args);
|
|
391
|
+
this.alias = alias;
|
|
392
|
+
this.freeze();
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
static of(fn: string, args: ReadonlyArray<AnyExpression>, alias?: string): FunctionSource {
|
|
396
|
+
return new FunctionSource(fn, args, alias);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
override rewrite(rewriter: AstRewriter): AnyFromSource {
|
|
400
|
+
const rewrittenArgs = this.args.map((arg) => rewriteComparable(arg, rewriter));
|
|
401
|
+
if (rewrittenArgs.every((arg, i) => arg === this.args[i])) return this;
|
|
402
|
+
return new FunctionSource(this.fn, rewrittenArgs, this.alias);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
override toFromSource(): AnyFromSource {
|
|
406
|
+
return this;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
381
410
|
export class ColumnRef extends Expression {
|
|
382
411
|
readonly kind = 'column-ref' as const;
|
|
383
412
|
readonly table: string;
|
|
@@ -1299,7 +1328,7 @@ export class ProjectionItem extends AstNode {
|
|
|
1299
1328
|
export type LimitOffsetValue = number | AnyExpression;
|
|
1300
1329
|
|
|
1301
1330
|
export interface SelectAstOptions {
|
|
1302
|
-
readonly from
|
|
1331
|
+
readonly from?: AnyFromSource;
|
|
1303
1332
|
readonly joins: ReadonlyArray<JoinAst> | undefined;
|
|
1304
1333
|
readonly projection: ReadonlyArray<ProjectionItem>;
|
|
1305
1334
|
readonly where: AnyExpression | undefined;
|
|
@@ -1315,7 +1344,7 @@ export interface SelectAstOptions {
|
|
|
1315
1344
|
|
|
1316
1345
|
export class SelectAst extends QueryAst {
|
|
1317
1346
|
readonly kind = 'select' as const;
|
|
1318
|
-
readonly from: AnyFromSource;
|
|
1347
|
+
readonly from: AnyFromSource | undefined;
|
|
1319
1348
|
readonly joins: ReadonlyArray<JoinAst> | undefined;
|
|
1320
1349
|
readonly projection: ReadonlyArray<ProjectionItem>;
|
|
1321
1350
|
readonly where: AnyExpression | undefined;
|
|
@@ -1368,79 +1397,113 @@ export class SelectAst extends QueryAst {
|
|
|
1368
1397
|
});
|
|
1369
1398
|
}
|
|
1370
1399
|
|
|
1400
|
+
static noFrom(): SelectAst {
|
|
1401
|
+
return new SelectAst({
|
|
1402
|
+
joins: undefined,
|
|
1403
|
+
projection: [],
|
|
1404
|
+
where: undefined,
|
|
1405
|
+
orderBy: undefined,
|
|
1406
|
+
distinct: undefined,
|
|
1407
|
+
distinctOn: undefined,
|
|
1408
|
+
groupBy: undefined,
|
|
1409
|
+
having: undefined,
|
|
1410
|
+
limit: undefined,
|
|
1411
|
+
offset: undefined,
|
|
1412
|
+
selectAllIntent: undefined,
|
|
1413
|
+
});
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
private toOptions(): SelectAstOptions {
|
|
1417
|
+
return {
|
|
1418
|
+
...(this.from !== undefined ? { from: this.from } : {}),
|
|
1419
|
+
joins: this.joins,
|
|
1420
|
+
projection: this.projection,
|
|
1421
|
+
where: this.where,
|
|
1422
|
+
orderBy: this.orderBy,
|
|
1423
|
+
distinct: this.distinct,
|
|
1424
|
+
distinctOn: this.distinctOn,
|
|
1425
|
+
groupBy: this.groupBy,
|
|
1426
|
+
having: this.having,
|
|
1427
|
+
limit: this.limit,
|
|
1428
|
+
offset: this.offset,
|
|
1429
|
+
selectAllIntent: this.selectAllIntent,
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1371
1433
|
withFrom(from: AnyFromSource): SelectAst {
|
|
1372
|
-
return new SelectAst({ ...this, from });
|
|
1434
|
+
return new SelectAst({ ...this.toOptions(), from });
|
|
1373
1435
|
}
|
|
1374
1436
|
|
|
1375
1437
|
withJoins(joins: ReadonlyArray<JoinAst>): SelectAst {
|
|
1376
1438
|
return new SelectAst({
|
|
1377
|
-
...this,
|
|
1439
|
+
...this.toOptions(),
|
|
1378
1440
|
joins: joins.length > 0 ? joins : undefined,
|
|
1379
1441
|
});
|
|
1380
1442
|
}
|
|
1381
1443
|
|
|
1382
1444
|
withProjection(projection: ReadonlyArray<ProjectionItem>): SelectAst {
|
|
1383
|
-
return new SelectAst({ ...this, projection });
|
|
1445
|
+
return new SelectAst({ ...this.toOptions(), projection });
|
|
1384
1446
|
}
|
|
1385
1447
|
|
|
1386
1448
|
addProjection(alias: string, expr: ProjectionExpr): SelectAst {
|
|
1387
1449
|
return new SelectAst({
|
|
1388
|
-
...this,
|
|
1450
|
+
...this.toOptions(),
|
|
1389
1451
|
projection: [...this.projection, new ProjectionItem(alias, expr)],
|
|
1390
1452
|
});
|
|
1391
1453
|
}
|
|
1392
1454
|
|
|
1393
1455
|
withWhere(where: AnyExpression | undefined): SelectAst {
|
|
1394
|
-
return new SelectAst({ ...this, where });
|
|
1456
|
+
return new SelectAst({ ...this.toOptions(), where });
|
|
1395
1457
|
}
|
|
1396
1458
|
|
|
1397
1459
|
withOrderBy(orderBy: ReadonlyArray<OrderByItem>): SelectAst {
|
|
1398
1460
|
return new SelectAst({
|
|
1399
|
-
...this,
|
|
1461
|
+
...this.toOptions(),
|
|
1400
1462
|
orderBy: orderBy.length > 0 ? orderBy : undefined,
|
|
1401
1463
|
});
|
|
1402
1464
|
}
|
|
1403
1465
|
|
|
1404
1466
|
withDistinct(enabled = true): SelectAst {
|
|
1405
1467
|
return new SelectAst({
|
|
1406
|
-
...this,
|
|
1468
|
+
...this.toOptions(),
|
|
1407
1469
|
distinct: enabled ? true : undefined,
|
|
1408
1470
|
});
|
|
1409
1471
|
}
|
|
1410
1472
|
|
|
1411
1473
|
withDistinctOn(distinctOn: ReadonlyArray<AnyExpression>): SelectAst {
|
|
1412
1474
|
return new SelectAst({
|
|
1413
|
-
...this,
|
|
1475
|
+
...this.toOptions(),
|
|
1414
1476
|
distinctOn: distinctOn.length > 0 ? distinctOn : undefined,
|
|
1415
1477
|
});
|
|
1416
1478
|
}
|
|
1417
1479
|
|
|
1418
1480
|
withGroupBy(groupBy: ReadonlyArray<AnyExpression>): SelectAst {
|
|
1419
1481
|
return new SelectAst({
|
|
1420
|
-
...this,
|
|
1482
|
+
...this.toOptions(),
|
|
1421
1483
|
groupBy: groupBy.length > 0 ? groupBy : undefined,
|
|
1422
1484
|
});
|
|
1423
1485
|
}
|
|
1424
1486
|
|
|
1425
1487
|
withHaving(having: AnyExpression | undefined): SelectAst {
|
|
1426
|
-
return new SelectAst({ ...this, having });
|
|
1488
|
+
return new SelectAst({ ...this.toOptions(), having });
|
|
1427
1489
|
}
|
|
1428
1490
|
|
|
1429
1491
|
withLimit(limit: LimitOffsetValue | undefined): SelectAst {
|
|
1430
|
-
return new SelectAst({ ...this, limit });
|
|
1492
|
+
return new SelectAst({ ...this.toOptions(), limit });
|
|
1431
1493
|
}
|
|
1432
1494
|
|
|
1433
1495
|
withOffset(offset: LimitOffsetValue | undefined): SelectAst {
|
|
1434
|
-
return new SelectAst({ ...this, offset });
|
|
1496
|
+
return new SelectAst({ ...this.toOptions(), offset });
|
|
1435
1497
|
}
|
|
1436
1498
|
|
|
1437
1499
|
withSelectAllIntent(selectAllIntent: { readonly table?: string } | undefined): SelectAst {
|
|
1438
|
-
return new SelectAst({ ...this, selectAllIntent });
|
|
1500
|
+
return new SelectAst({ ...this.toOptions(), selectAllIntent });
|
|
1439
1501
|
}
|
|
1440
1502
|
|
|
1441
1503
|
rewrite(rewriter: AstRewriter): SelectAst {
|
|
1504
|
+
const rewrittenFrom = this.from?.rewrite(rewriter);
|
|
1442
1505
|
const rewritten = new SelectAst({
|
|
1443
|
-
from:
|
|
1506
|
+
...(rewrittenFrom !== undefined ? { from: rewrittenFrom } : {}),
|
|
1444
1507
|
joins: this.joins?.map((join) => join.rewrite(rewriter)),
|
|
1445
1508
|
projection: this.projection.map(
|
|
1446
1509
|
(projection) =>
|
|
@@ -1474,8 +1537,12 @@ export class SelectAst extends QueryAst {
|
|
|
1474
1537
|
refs.push(...columns);
|
|
1475
1538
|
};
|
|
1476
1539
|
|
|
1477
|
-
if (this.from
|
|
1540
|
+
if (this.from?.kind === 'derived-table-source') {
|
|
1478
1541
|
pushRefs(this.from.query.collectColumnRefs());
|
|
1542
|
+
} else if (this.from?.kind === 'function-source') {
|
|
1543
|
+
for (const arg of this.from.args) {
|
|
1544
|
+
pushRefs(arg.collectColumnRefs());
|
|
1545
|
+
}
|
|
1479
1546
|
}
|
|
1480
1547
|
|
|
1481
1548
|
for (const projection of this.projection) {
|
|
@@ -1502,6 +1569,10 @@ export class SelectAst extends QueryAst {
|
|
|
1502
1569
|
for (const join of this.joins ?? []) {
|
|
1503
1570
|
if (join.source.kind === 'derived-table-source') {
|
|
1504
1571
|
pushRefs(join.source.query.collectColumnRefs());
|
|
1572
|
+
} else if (join.source.kind === 'function-source') {
|
|
1573
|
+
for (const arg of join.source.args) {
|
|
1574
|
+
pushRefs(arg.collectColumnRefs());
|
|
1575
|
+
}
|
|
1505
1576
|
}
|
|
1506
1577
|
if (join.on.kind === 'eq-col-join-on') {
|
|
1507
1578
|
refs.push(join.on.left, join.on.right);
|
|
@@ -1525,8 +1596,12 @@ export class SelectAst extends QueryAst {
|
|
|
1525
1596
|
refs.push(...params);
|
|
1526
1597
|
};
|
|
1527
1598
|
|
|
1528
|
-
if (this.from
|
|
1599
|
+
if (this.from?.kind === 'derived-table-source') {
|
|
1529
1600
|
pushRefs(this.from.query.collectParamRefs());
|
|
1601
|
+
} else if (this.from?.kind === 'function-source') {
|
|
1602
|
+
for (const arg of this.from.args) {
|
|
1603
|
+
pushRefs(arg.collectParamRefs());
|
|
1604
|
+
}
|
|
1530
1605
|
}
|
|
1531
1606
|
|
|
1532
1607
|
for (const projection of this.projection) {
|
|
@@ -1553,6 +1628,10 @@ export class SelectAst extends QueryAst {
|
|
|
1553
1628
|
for (const join of this.joins ?? []) {
|
|
1554
1629
|
if (join.source.kind === 'derived-table-source') {
|
|
1555
1630
|
pushRefs(join.source.query.collectParamRefs());
|
|
1631
|
+
} else if (join.source.kind === 'function-source') {
|
|
1632
|
+
for (const arg of join.source.args) {
|
|
1633
|
+
pushRefs(arg.collectParamRefs());
|
|
1634
|
+
}
|
|
1556
1635
|
}
|
|
1557
1636
|
if (!(join.on.kind === 'eq-col-join-on')) {
|
|
1558
1637
|
pushRefs(join.on.collectParamRefs());
|
|
@@ -1899,7 +1978,7 @@ export class RawSqlExpr extends QueryAst {
|
|
|
1899
1978
|
}
|
|
1900
1979
|
|
|
1901
1980
|
export type AnyQueryAst = SelectAst | InsertAst | UpdateAst | DeleteAst | RawSqlExpr;
|
|
1902
|
-
export type AnyFromSource = TableSource | DerivedTableSource;
|
|
1981
|
+
export type AnyFromSource = TableSource | DerivedTableSource | FunctionSource;
|
|
1903
1982
|
export type AnyExpression =
|
|
1904
1983
|
| ColumnRef
|
|
1905
1984
|
| IdentifierRef
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import type { JsonValue } from '@prisma-next/contract/types';
|
|
2
2
|
import type { CodecRef } from '@prisma-next/framework-components/codec';
|
|
3
3
|
import { resolveStorageTable } from '@prisma-next/sql-contract/resolve-storage-table';
|
|
4
|
-
import {
|
|
5
|
-
isPostgresEnumStorageEntry,
|
|
6
|
-
isStorageTypeInstance,
|
|
7
|
-
type SqlStorage,
|
|
8
|
-
} from '@prisma-next/sql-contract/types';
|
|
4
|
+
import { isStorageTypeInstance, type SqlStorage } from '@prisma-next/sql-contract/types';
|
|
9
5
|
|
|
10
6
|
/**
|
|
11
7
|
* Derive the canonical {@link CodecRef} for a `(table, column)` pair against a {@link SqlStorage}. This is the build-time path every column-bound `ParamRef` / `ProjectionItem` uses to stamp its `codec` slot before the AST is handed to the runtime — the runtime resolver then materialises a memoised {@link import('@prisma-next/sql-relational-core/ast').Codec} for the same `CodecRef` via `forCodecRef`.
|
|
@@ -34,38 +30,9 @@ export function codecRefForStorageColumn(
|
|
|
34
30
|
const columnDef = tableDef.columns[columnName];
|
|
35
31
|
if (!columnDef) return undefined;
|
|
36
32
|
if (columnDef.typeRef !== undefined) {
|
|
37
|
-
|
|
38
|
-
if (!instance) {
|
|
39
|
-
for (const ns of Object.values(storage.namespaces)) {
|
|
40
|
-
const typeSlot = (ns.entries as { type?: Record<string, unknown> }).type;
|
|
41
|
-
const nsEntry = typeSlot?.[columnDef.typeRef];
|
|
42
|
-
if (nsEntry !== undefined) {
|
|
43
|
-
instance = nsEntry;
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
33
|
+
const instance = storage.types?.[columnDef.typeRef];
|
|
48
34
|
if (!instance) return undefined;
|
|
49
|
-
if (isPostgresEnumStorageEntry(instance)) {
|
|
50
|
-
// Canonical path: the entry is a live `PostgresEnumType` IR
|
|
51
|
-
// instance reached through the per-target serializer's
|
|
52
|
-
// hydration. Raw JSON envelopes carrying `kind: 'postgres-enum'`
|
|
53
|
-
// never reach this site — `SqlStorage.normaliseTypeEntry`
|
|
54
|
-
// rejects them upstream (F09). Read `codecId` and `values` off
|
|
55
|
-
// the structural shape (enumerable own properties on the live
|
|
56
|
-
// instance) so the dispatch stays layered against the family
|
|
57
|
-
// alphabet rather than a target-specific class import.
|
|
58
|
-
return {
|
|
59
|
-
codecId: instance.codecId,
|
|
60
|
-
typeParams: { values: instance.values } as unknown as JsonValue,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
35
|
if (isStorageTypeInstance(instance)) {
|
|
64
|
-
// Empty-state canonicalization: a `StorageTypeInstance` with absent
|
|
65
|
-
// (or empty) `typeParams` produces a `CodecRef` with no `typeParams`
|
|
66
|
-
// field. Equivalent to the non-parameterized-column branch below.
|
|
67
|
-
// Carrying `{}` here would break content-keyed memoisation and trip
|
|
68
|
-
// the runtime validator against non-parameterized codec descriptors.
|
|
69
36
|
const instanceParams = instance.typeParams;
|
|
70
37
|
const hasParamKeys = instanceParams !== undefined && Object.keys(instanceParams).length > 0;
|
|
71
38
|
return hasParamKeys
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ColumnDefaultLiteralInputValue } from '@prisma-next/contract/types';
|
|
2
2
|
import type { ReferentialAction } from '@prisma-next/sql-contract/types';
|
|
3
|
+
import type { CodecRef } from '../ast/codec-types';
|
|
3
4
|
import type { AnyDdlColumnDefault } from '../ast/ddl-types';
|
|
4
5
|
import {
|
|
5
6
|
DdlColumn,
|
|
@@ -14,6 +15,7 @@ export interface DdlColumnOptions {
|
|
|
14
15
|
readonly notNull?: boolean;
|
|
15
16
|
readonly primaryKey?: boolean;
|
|
16
17
|
readonly default?: AnyDdlColumnDefault;
|
|
18
|
+
readonly codecRef?: CodecRef;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
export function lit(value: ColumnDefaultLiteralInputValue): LiteralColumnDefault {
|
package/src/contract-free/dml.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export {
|
|
2
2
|
CfConflictClause,
|
|
3
3
|
CfExpr,
|
|
4
|
+
CfExprSelectQuery,
|
|
5
|
+
type CfFnOptions,
|
|
4
6
|
CfInsertQuery,
|
|
5
7
|
CfSelectQuery,
|
|
6
8
|
CfUpdateQuery,
|
|
@@ -9,7 +11,10 @@ export {
|
|
|
9
11
|
type ColumnDescriptor,
|
|
10
12
|
type ColumnProxy,
|
|
11
13
|
type ColumnSchema,
|
|
14
|
+
cfExpr,
|
|
15
|
+
cfTable,
|
|
12
16
|
type ExcludedProxy,
|
|
17
|
+
exprSelect,
|
|
13
18
|
type TableHandle,
|
|
14
19
|
type TableInsertRow,
|
|
15
20
|
type TableSetValues,
|