@prisma-next/sql-relational-core 0.3.0-pr.99.6 → 0.3.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/LICENSE +201 -0
- package/README.md +20 -6
- package/dist/codec-types-DcEITed4.d.mts +144 -0
- package/dist/codec-types-DcEITed4.d.mts.map +1 -0
- package/dist/errors-Cs52upp3.d.mts +8 -0
- package/dist/errors-Cs52upp3.d.mts.map +1 -0
- package/dist/errors-D3xmG4h-.mjs +35 -0
- package/dist/errors-D3xmG4h-.mjs.map +1 -0
- package/dist/exports/ast.d.mts +158 -0
- package/dist/exports/ast.d.mts.map +1 -0
- package/dist/exports/ast.mjs +1358 -0
- package/dist/exports/ast.mjs.map +1 -0
- package/dist/exports/errors.d.mts +5 -0
- package/dist/exports/errors.mjs +3 -0
- package/dist/exports/plan.d.mts +2 -0
- package/dist/exports/plan.mjs +17 -0
- package/dist/exports/plan.mjs.map +1 -0
- package/dist/exports/query-lane-context.d.mts +3 -0
- package/dist/exports/query-lane-context.mjs +1 -0
- package/dist/exports/types.d.mts +4 -0
- package/dist/exports/types.mjs +1 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.mjs +7 -0
- package/dist/plan-5qUWdlJM.d.mts +28 -0
- package/dist/plan-5qUWdlJM.d.mts.map +1 -0
- package/dist/query-lane-context-UlR8vOkd.d.mts +89 -0
- package/dist/query-lane-context-UlR8vOkd.d.mts.map +1 -0
- package/dist/types-CLCtwVWx.d.mts +485 -0
- package/dist/types-CLCtwVWx.d.mts.map +1 -0
- package/dist/types-V1qiC5DO.d.mts +200 -0
- package/dist/types-V1qiC5DO.d.mts.map +1 -0
- package/package.json +29 -51
- package/src/ast/adapter-types.ts +11 -0
- package/src/ast/codec-types.ts +101 -53
- package/src/ast/driver-types.ts +20 -3
- package/src/ast/sql-codecs.ts +142 -0
- package/src/ast/types.ts +1678 -88
- package/src/errors.ts +47 -1
- package/src/exports/ast.ts +1 -8
- package/src/index.ts +0 -3
- package/src/plan.ts +4 -4
- package/src/query-lane-context.ts +74 -11
- package/src/types.ts +102 -404
- package/dist/ast/adapter-types.d.ts +0 -28
- package/dist/ast/adapter-types.d.ts.map +0 -1
- package/dist/ast/codec-types.d.ts +0 -141
- package/dist/ast/codec-types.d.ts.map +0 -1
- package/dist/ast/common.d.ts +0 -7
- package/dist/ast/common.d.ts.map +0 -1
- package/dist/ast/delete.d.ts +0 -8
- package/dist/ast/delete.d.ts.map +0 -1
- package/dist/ast/driver-types.d.ts +0 -20
- package/dist/ast/driver-types.d.ts.map +0 -1
- package/dist/ast/insert.d.ts +0 -8
- package/dist/ast/insert.d.ts.map +0 -1
- package/dist/ast/join.d.ts +0 -6
- package/dist/ast/join.d.ts.map +0 -1
- package/dist/ast/order.d.ts +0 -6
- package/dist/ast/order.d.ts.map +0 -1
- package/dist/ast/predicate.d.ts +0 -4
- package/dist/ast/predicate.d.ts.map +0 -1
- package/dist/ast/select.d.ts +0 -18
- package/dist/ast/select.d.ts.map +0 -1
- package/dist/ast/types.d.ts +0 -130
- package/dist/ast/types.d.ts.map +0 -1
- package/dist/ast/update.d.ts +0 -9
- package/dist/ast/update.d.ts.map +0 -1
- package/dist/ast/util.d.ts +0 -2
- package/dist/ast/util.d.ts.map +0 -1
- package/dist/chunk-2BWK6XEY.js +0 -13
- package/dist/chunk-2BWK6XEY.js.map +0 -1
- package/dist/chunk-2F7DSEOU.js +0 -8
- package/dist/chunk-2F7DSEOU.js.map +0 -1
- package/dist/chunk-2MAKNVCP.js +0 -86
- package/dist/chunk-2MAKNVCP.js.map +0 -1
- package/dist/chunk-36WJWNHT.js +0 -1
- package/dist/chunk-36WJWNHT.js.map +0 -1
- package/dist/chunk-3F4RFQIB.js +0 -169
- package/dist/chunk-3F4RFQIB.js.map +0 -1
- package/dist/chunk-7I3EMQID.js +0 -16
- package/dist/chunk-7I3EMQID.js.map +0 -1
- package/dist/chunk-G52ENULI.js +0 -1
- package/dist/chunk-G52ENULI.js.map +0 -1
- package/dist/chunk-HV334QHG.js +0 -320
- package/dist/chunk-HV334QHG.js.map +0 -1
- package/dist/chunk-KYSP7L5C.js +0 -16
- package/dist/chunk-KYSP7L5C.js.map +0 -1
- package/dist/chunk-U7AXAUJA.js +0 -1
- package/dist/chunk-U7AXAUJA.js.map +0 -1
- package/dist/chunk-YXD25S5I.js +0 -171
- package/dist/chunk-YXD25S5I.js.map +0 -1
- package/dist/errors.d.ts +0 -2
- package/dist/errors.d.ts.map +0 -1
- package/dist/exports/ast.d.ts +0 -14
- package/dist/exports/ast.d.ts.map +0 -1
- package/dist/exports/ast.js +0 -46
- package/dist/exports/ast.js.map +0 -1
- package/dist/exports/errors.d.ts +0 -2
- package/dist/exports/errors.d.ts.map +0 -1
- package/dist/exports/errors.js +0 -9
- package/dist/exports/errors.js.map +0 -1
- package/dist/exports/guards.d.ts +0 -2
- package/dist/exports/guards.d.ts.map +0 -1
- package/dist/exports/guards.js +0 -31
- package/dist/exports/guards.js.map +0 -1
- package/dist/exports/operations-registry.d.ts +0 -2
- package/dist/exports/operations-registry.d.ts.map +0 -1
- package/dist/exports/operations-registry.js +0 -9
- package/dist/exports/operations-registry.js.map +0 -1
- package/dist/exports/param.d.ts +0 -3
- package/dist/exports/param.d.ts.map +0 -1
- package/dist/exports/param.js +0 -7
- package/dist/exports/param.js.map +0 -1
- package/dist/exports/plan.d.ts +0 -2
- package/dist/exports/plan.d.ts.map +0 -1
- package/dist/exports/plan.js +0 -7
- package/dist/exports/plan.js.map +0 -1
- package/dist/exports/query-lane-context.d.ts +0 -2
- package/dist/exports/query-lane-context.d.ts.map +0 -1
- package/dist/exports/query-lane-context.js +0 -2
- package/dist/exports/query-lane-context.js.map +0 -1
- package/dist/exports/schema.d.ts +0 -3
- package/dist/exports/schema.d.ts.map +0 -1
- package/dist/exports/schema.js +0 -13
- package/dist/exports/schema.js.map +0 -1
- package/dist/exports/types.d.ts +0 -2
- package/dist/exports/types.d.ts.map +0 -1
- package/dist/exports/types.js +0 -10
- package/dist/exports/types.js.map +0 -1
- package/dist/index.d.ts +0 -9
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -81
- package/dist/index.js.map +0 -1
- package/dist/operations-registry.d.ts +0 -5
- package/dist/operations-registry.d.ts.map +0 -1
- package/dist/param.d.ts +0 -4
- package/dist/param.d.ts.map +0 -1
- package/dist/plan.d.ts +0 -23
- package/dist/plan.d.ts.map +0 -1
- package/dist/query-lane-context.d.ts +0 -27
- package/dist/query-lane-context.d.ts.map +0 -1
- package/dist/schema.d.ts +0 -83
- package/dist/schema.d.ts.map +0 -1
- package/dist/types.d.ts +0 -371
- package/dist/types.d.ts.map +0 -1
- package/dist/utils/guards.d.ts +0 -82
- package/dist/utils/guards.d.ts.map +0 -1
- package/src/ast/common.ts +0 -36
- package/src/ast/delete.ts +0 -17
- package/src/ast/insert.ts +0 -17
- package/src/ast/join.ts +0 -54
- package/src/ast/order.ts +0 -11
- package/src/ast/predicate.ts +0 -22
- package/src/ast/select.ts +0 -39
- package/src/ast/update.ts +0 -19
- package/src/exports/guards.ts +0 -15
- package/src/exports/operations-registry.ts +0 -1
- package/src/exports/param.ts +0 -2
- package/src/exports/schema.ts +0 -6
- package/src/operations-registry.ts +0 -276
- package/src/param.ts +0 -15
- package/src/schema.ts +0 -406
- package/src/utils/guards.ts +0 -193
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { G as ParamRef, d as AnyQueryAst, h as ColumnRef } from "./types-CLCtwVWx.mjs";
|
|
2
|
+
import { t as SqlQueryPlan } from "./plan-5qUWdlJM.mjs";
|
|
3
|
+
import { n as ExecutionContext } from "./query-lane-context-UlR8vOkd.mjs";
|
|
4
|
+
import { Contract, ExecutionPlan, PlanRefs, ResultType } from "@prisma-next/contract/types";
|
|
5
|
+
import { ParamSpec } from "@prisma-next/operations";
|
|
6
|
+
import { SqlLoweringSpec } from "@prisma-next/sql-operations";
|
|
7
|
+
import { ExtractFieldOutputTypes, SqlStorage, StorageColumn } from "@prisma-next/sql-contract/types";
|
|
8
|
+
|
|
9
|
+
//#region src/types.d.ts
|
|
10
|
+
type Expr = ColumnRef | ParamRef;
|
|
11
|
+
/**
|
|
12
|
+
* Extracts the model name for a given table by iterating models to find the one
|
|
13
|
+
* whose `storage.table` matches.
|
|
14
|
+
*/
|
|
15
|
+
type ExtractTableToModel<TContract extends Contract<SqlStorage>, TableName extends string> = TContract['models'] extends infer Models extends Record<string, unknown> ? { [M in keyof Models & string]: Models[M] extends {
|
|
16
|
+
readonly storage: {
|
|
17
|
+
readonly table: TableName;
|
|
18
|
+
};
|
|
19
|
+
} ? M : never }[keyof Models & string] : never;
|
|
20
|
+
/**
|
|
21
|
+
* Extracts the field name for a given column by finding the field in
|
|
22
|
+
* `model.storage.fields` whose `column` matches.
|
|
23
|
+
*/
|
|
24
|
+
type ExtractColumnToField<TContract extends Contract<SqlStorage>, TableName extends string, ColumnName extends string> = ExtractTableToModel<TContract, TableName> extends infer ModelName extends string ? TContract['models'] extends infer Models extends Record<string, unknown> ? ModelName & keyof Models extends infer MKey extends string ? Models[MKey] extends {
|
|
25
|
+
readonly storage: {
|
|
26
|
+
readonly fields: infer Fields extends Record<string, unknown>;
|
|
27
|
+
};
|
|
28
|
+
} ? { [F in keyof Fields & string]: Fields[F] extends {
|
|
29
|
+
readonly column: ColumnName;
|
|
30
|
+
} ? F : never }[keyof Fields & string] : never : never : never : never;
|
|
31
|
+
type FallbackCodecLookup<ColumnMeta extends StorageColumn, CodecTypes$1 extends Record<string, {
|
|
32
|
+
readonly output: unknown;
|
|
33
|
+
}>> = ColumnMeta extends {
|
|
34
|
+
codecId: infer CodecId extends string;
|
|
35
|
+
} ? CodecId extends keyof CodecTypes$1 ? CodecTypes$1[CodecId] extends {
|
|
36
|
+
readonly output: infer O;
|
|
37
|
+
} ? ColumnMeta extends {
|
|
38
|
+
nullable: true;
|
|
39
|
+
} ? O | null : O : unknown : unknown : unknown;
|
|
40
|
+
/**
|
|
41
|
+
* Type-level operation signature.
|
|
42
|
+
* Represents an operation at the type level for use in contract type maps.
|
|
43
|
+
*/
|
|
44
|
+
type OperationTypeSignature = {
|
|
45
|
+
readonly args: ReadonlyArray<ParamSpec>;
|
|
46
|
+
readonly returns: ParamSpec;
|
|
47
|
+
readonly lowering: SqlLoweringSpec;
|
|
48
|
+
readonly capabilities?: ReadonlyArray<string>;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Type-level operation registry.
|
|
52
|
+
* Maps typeId → operations, where operations is a record of method name → operation signature.
|
|
53
|
+
*
|
|
54
|
+
* Example:
|
|
55
|
+
* ```typescript
|
|
56
|
+
* type MyOperations: OperationTypes = {
|
|
57
|
+
* 'pg/vector@1': {
|
|
58
|
+
* cosineDistance: {
|
|
59
|
+
* args: [{ codecId: 'pg/vector@1'; nullable: false }];
|
|
60
|
+
* returns: { codecId: 'core/float8'; nullable: false };
|
|
61
|
+
* lowering: { targetFamily: 'sql'; strategy: 'function'; template: '...' };
|
|
62
|
+
* };
|
|
63
|
+
* };
|
|
64
|
+
* };
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
type OperationTypes = Record<string, Record<string, OperationTypeSignature>>;
|
|
68
|
+
/**
|
|
69
|
+
* CodecTypes represents a map of typeId to codec definitions.
|
|
70
|
+
* Each codec definition must have an `output` property indicating the JavaScript type.
|
|
71
|
+
*
|
|
72
|
+
* Example:
|
|
73
|
+
* ```typescript
|
|
74
|
+
* type MyCodecTypes: CodecTypes = {
|
|
75
|
+
* 'pg/int4@1': { output: number };
|
|
76
|
+
* 'pg/text@1': { output: string };
|
|
77
|
+
* };
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
type CodecTypes = Record<string, {
|
|
81
|
+
readonly output: unknown;
|
|
82
|
+
}>;
|
|
83
|
+
/**
|
|
84
|
+
* Extracts operations for a given typeId from the operation registry.
|
|
85
|
+
* Returns an empty record if the typeId is not found.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* type Ops = OperationsForTypeId<'pg/vector@1', MyOperations>;
|
|
90
|
+
* // Ops = { cosineDistance: { ... }, l2Distance: { ... } }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
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>;
|
|
94
|
+
type ComputeColumnJsType<TContract extends Contract<SqlStorage>, TableName extends string, ColumnName extends string, ColumnMeta extends StorageColumn, CodecTypes$1 extends Record<string, {
|
|
95
|
+
readonly output: unknown;
|
|
96
|
+
}>> = ExtractTableToModel<TContract, TableName> extends infer ModelName ? [ModelName] extends [never] ? FallbackCodecLookup<ColumnMeta, CodecTypes$1> : ModelName extends string ? ExtractColumnToField<TContract, TableName, ColumnName> extends infer FieldName ? [FieldName] extends [never] ? FallbackCodecLookup<ColumnMeta, CodecTypes$1> : FieldName extends string ? ModelName extends keyof ExtractFieldOutputTypes<TContract> ? FieldName extends keyof ExtractFieldOutputTypes<TContract>[ModelName] ? ExtractFieldOutputTypes<TContract>[ModelName][FieldName] : never : never : never : never : never : never;
|
|
97
|
+
/**
|
|
98
|
+
* Utility type to check if a contract has the required capabilities for includeMany.
|
|
99
|
+
* Requires both `lateral` and `jsonAgg` to be `true` in the contract's capabilities for the target.
|
|
100
|
+
* Capabilities are nested by target: `{ [target]: { lateral: true, jsonAgg: true } }`
|
|
101
|
+
*/
|
|
102
|
+
type HasIncludeManyCapabilities<TContract extends Contract<SqlStorage>> = TContract extends {
|
|
103
|
+
capabilities: infer C;
|
|
104
|
+
target: infer T;
|
|
105
|
+
} ? T extends string ? C extends Record<string, Record<string, boolean>> ? C extends { [K in T]: infer TargetCaps } ? TargetCaps extends {
|
|
106
|
+
lateral: true;
|
|
107
|
+
jsonAgg: true;
|
|
108
|
+
} ? true : false : false : false : false : false;
|
|
109
|
+
/**
|
|
110
|
+
* SQL-specific Plan type that refines the ast field to use AnyQueryAst.
|
|
111
|
+
* This is the type used by SQL query builders.
|
|
112
|
+
*/
|
|
113
|
+
type SqlPlan<Row = unknown> = ExecutionPlan<Row, AnyQueryAst>;
|
|
114
|
+
/**
|
|
115
|
+
* Helper types for extracting contract structure.
|
|
116
|
+
*/
|
|
117
|
+
type TablesOf<TContract> = TContract extends {
|
|
118
|
+
storage: {
|
|
119
|
+
tables: infer U;
|
|
120
|
+
};
|
|
121
|
+
} ? U : never;
|
|
122
|
+
type TableKey<TContract> = Extract<keyof TablesOf<TContract>, string>;
|
|
123
|
+
/**
|
|
124
|
+
* Unique symbol for metadata property to avoid collisions with user-defined properties
|
|
125
|
+
*/
|
|
126
|
+
declare const META: unique symbol;
|
|
127
|
+
/**
|
|
128
|
+
* Extracts metadata from a type that has a META property
|
|
129
|
+
*/
|
|
130
|
+
type Meta<T$1 extends {
|
|
131
|
+
[META]: unknown;
|
|
132
|
+
}> = T$1[typeof META];
|
|
133
|
+
/**
|
|
134
|
+
* Metadata interface for table definitions
|
|
135
|
+
*/
|
|
136
|
+
interface TableMetadata<Name extends string> {
|
|
137
|
+
name: Name;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Metadata interface for model definitions
|
|
141
|
+
*/
|
|
142
|
+
interface ModelMetadata<Name extends string> {
|
|
143
|
+
name: Name;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Base interface for table definitions with metadata
|
|
147
|
+
* Used in contract.d.ts to define storage-level table types
|
|
148
|
+
*/
|
|
149
|
+
interface TableDef<Name extends string> {
|
|
150
|
+
readonly [META]: TableMetadata<Name>;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Base interface for model definitions with metadata
|
|
154
|
+
* Used in contract.d.ts to define application-level model types
|
|
155
|
+
*/
|
|
156
|
+
interface ModelDef<Name extends string> {
|
|
157
|
+
readonly [META]: ModelMetadata<Name>;
|
|
158
|
+
}
|
|
159
|
+
type ColumnsOf<TContract, K extends TableKey<TContract>> = K extends keyof TablesOf<TContract> ? TablesOf<TContract>[K] extends {
|
|
160
|
+
columns: infer C;
|
|
161
|
+
} ? C : never : never;
|
|
162
|
+
interface RawTemplateOptions {
|
|
163
|
+
readonly refs?: PlanRefs;
|
|
164
|
+
readonly annotations?: Record<string, unknown>;
|
|
165
|
+
readonly projection?: ReadonlyArray<string>;
|
|
166
|
+
}
|
|
167
|
+
interface RawFunctionOptions extends RawTemplateOptions {
|
|
168
|
+
readonly params: ReadonlyArray<unknown>;
|
|
169
|
+
}
|
|
170
|
+
type RawTemplateFactory = (strings: TemplateStringsArray, ...values: readonly unknown[]) => ExecutionPlan;
|
|
171
|
+
interface RawFactory extends RawTemplateFactory {
|
|
172
|
+
(text: string, options: RawFunctionOptions): ExecutionPlan;
|
|
173
|
+
with(options: RawTemplateOptions): RawTemplateFactory;
|
|
174
|
+
}
|
|
175
|
+
interface RuntimeError extends Error {
|
|
176
|
+
readonly code: string;
|
|
177
|
+
readonly category: 'PLAN';
|
|
178
|
+
readonly severity: 'error';
|
|
179
|
+
readonly details?: Record<string, unknown>;
|
|
180
|
+
readonly hints?: readonly string[];
|
|
181
|
+
readonly docs?: readonly string[];
|
|
182
|
+
}
|
|
183
|
+
interface BuildParamsMap {
|
|
184
|
+
readonly [name: string]: unknown;
|
|
185
|
+
}
|
|
186
|
+
interface BuildOptions {
|
|
187
|
+
readonly params?: BuildParamsMap;
|
|
188
|
+
}
|
|
189
|
+
interface SqlBuilderOptions<TContract extends Contract<SqlStorage> = Contract<SqlStorage>> {
|
|
190
|
+
readonly context: ExecutionContext<TContract>;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* SQL-specific ResultType that works with both Plan and SqlQueryPlan.
|
|
194
|
+
* This extends the core ResultType to also handle SqlQueryPlan.
|
|
195
|
+
* Example: `type Row = ResultType<typeof plan>`
|
|
196
|
+
*/
|
|
197
|
+
type ResultType$1<P> = P extends SqlQueryPlan<infer R> ? R : ResultType<P>;
|
|
198
|
+
//#endregion
|
|
199
|
+
export { TableDef as C, TablesOf as E, SqlPlan as S, TableMetadata as T, RawTemplateFactory as _, ComputeColumnJsType as a, RuntimeError as b, META as c, ModelMetadata as d, OperationTypeSignature as f, RawFunctionOptions as g, RawFactory as h, ColumnsOf as i, Meta as l, OperationsForTypeId as m, BuildParamsMap as n, Expr as o, OperationTypes as p, CodecTypes as r, HasIncludeManyCapabilities as s, BuildOptions as t, ModelDef as u, RawTemplateOptions as v, TableKey as w, SqlBuilderOptions as x, ResultType$1 as y };
|
|
200
|
+
//# sourceMappingURL=types-V1qiC5DO.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-V1qiC5DO.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;KAiBY,IAAA,GAAO,YAAY;;AAA/B;AAAwC;;KAMnC,mBACe,CAAA,kBAAA,QAAA,CAAS,UAAT,CAAA,EAAA,kBAAA,MAAA,CAAA,GAEhB,SAFgB,CAAA,QAAA,CAAA,SAAA,KAAA,gBAEiC,MAFjC,CAAA,MAAA,EAAA,OAAA,CAAA,GAAA,QAEhB,MAEc,MAFd,GAAA,MAAA,GAEgC,MAFhC,CAEuC,CAFvC,CAAA,SAAA;EAAiD,SAAA,OAAA,EAAA;IAEnC,SAAA,KAAA,EAC0B,SAD1B;EAAkB,CAAA;AAAO,CAAA,GAGjC,CAHiC,GAAA,KAAA,EACC,CAAA,MAIhC,MAJgC,GAAA,MAAA,CAAA,GAAA,KAAA;;;;AAI1B;KAOb,oBACwB,CAAA,kBAAT,QAAS,CAAA,UAAA,CAAA,EAAA,kBAAA,MAAA,EAAA,mBAAA,MAAA,CAAA,GAGzB,mBAHyB,CAGL,SAHK,EAGM,SAHN,CAAA,SAAA,KAAA,mBAAA,MAAA,GAIzB,SAJyB,CAAA,QAAA,CAAA,SAAA,KAAA,gBAIwB,MAJxB,CAAA,MAAA,EAAA,OAAA,CAAA,GAKvB,SALuB,GAAA,MAKL,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AAA,OAAA;EAAf,SAAA,OAAA,CAAA,EAtB7C,MAsB6C,CAAA,MAAA,EAAA,OAAA,CAAA;EAAc,SAAA,KAAA,CAAA,EAAA,SAAA,MAAA,EAAA;;;UAjB/D,cAAA;;;UAIA,YAAA;oBACG;;UAGH,oCAAoC,SAAS,cAAc,SAAS;oBACjE,iBAAiB;;;;;;;KAQzB,kBAAgB,UAAU,4BAA4B,WAAe"}
|
package/package.json
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-relational-core",
|
|
3
|
-
"version": "0.3.0
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
|
-
"description": "
|
|
6
|
+
"description": "AST types, query lane context, and type utilities for Prisma Next SQL lanes",
|
|
7
7
|
"dependencies": {
|
|
8
|
+
"arktype": "^2.1.29",
|
|
8
9
|
"ts-toolbelt": "^9.6.0",
|
|
9
|
-
"@prisma-next/contract": "0.3.0
|
|
10
|
-
"@prisma-next/
|
|
11
|
-
"@prisma-next/sql-contract": "0.3.0
|
|
12
|
-
"@prisma-next/
|
|
13
|
-
"@prisma-next/sql-operations": "0.3.0
|
|
10
|
+
"@prisma-next/contract": "0.3.0",
|
|
11
|
+
"@prisma-next/operations": "0.3.0",
|
|
12
|
+
"@prisma-next/sql-contract": "0.3.0",
|
|
13
|
+
"@prisma-next/utils": "0.3.0",
|
|
14
|
+
"@prisma-next/sql-operations": "0.3.0",
|
|
15
|
+
"@prisma-next/framework-components": "0.3.0"
|
|
14
16
|
},
|
|
15
17
|
"devDependencies": {
|
|
16
|
-
"
|
|
18
|
+
"tsdown": "0.18.4",
|
|
17
19
|
"typescript": "5.9.3",
|
|
18
|
-
"vitest": "4.0.
|
|
19
|
-
"@prisma-next/sql-contract-ts": "0.3.0
|
|
20
|
+
"vitest": "4.0.17",
|
|
21
|
+
"@prisma-next/sql-contract-ts": "0.3.0",
|
|
20
22
|
"@prisma-next/test-utils": "0.0.1",
|
|
23
|
+
"@prisma-next/tsdown": "0.0.0",
|
|
21
24
|
"@prisma-next/tsconfig": "0.0.0"
|
|
22
25
|
},
|
|
23
26
|
"files": [
|
|
@@ -25,49 +28,24 @@
|
|
|
25
28
|
"src"
|
|
26
29
|
],
|
|
27
30
|
"exports": {
|
|
28
|
-
".":
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"./
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
},
|
|
44
|
-
"./operations-registry": {
|
|
45
|
-
"types": "./dist/exports/operations-registry.d.ts",
|
|
46
|
-
"import": "./dist/exports/operations-registry.js"
|
|
47
|
-
},
|
|
48
|
-
"./errors": {
|
|
49
|
-
"types": "./dist/exports/errors.d.ts",
|
|
50
|
-
"import": "./dist/exports/errors.js"
|
|
51
|
-
},
|
|
52
|
-
"./ast": {
|
|
53
|
-
"types": "./dist/exports/ast.d.ts",
|
|
54
|
-
"import": "./dist/exports/ast.js"
|
|
55
|
-
},
|
|
56
|
-
"./plan": {
|
|
57
|
-
"types": "./dist/exports/plan.d.ts",
|
|
58
|
-
"import": "./dist/exports/plan.js"
|
|
59
|
-
},
|
|
60
|
-
"./query-lane-context": {
|
|
61
|
-
"types": "./dist/exports/query-lane-context.d.ts",
|
|
62
|
-
"import": "./dist/exports/query-lane-context.js"
|
|
63
|
-
},
|
|
64
|
-
"./utils/guards": {
|
|
65
|
-
"types": "./dist/exports/guards.d.ts",
|
|
66
|
-
"import": "./dist/exports/guards.js"
|
|
67
|
-
}
|
|
31
|
+
".": "./dist/index.mjs",
|
|
32
|
+
"./ast": "./dist/exports/ast.mjs",
|
|
33
|
+
"./errors": "./dist/exports/errors.mjs",
|
|
34
|
+
"./plan": "./dist/exports/plan.mjs",
|
|
35
|
+
"./query-lane-context": "./dist/exports/query-lane-context.mjs",
|
|
36
|
+
"./types": "./dist/exports/types.mjs",
|
|
37
|
+
"./package.json": "./package.json"
|
|
38
|
+
},
|
|
39
|
+
"main": "./dist/index.mjs",
|
|
40
|
+
"module": "./dist/index.mjs",
|
|
41
|
+
"types": "./dist/index.d.mts",
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "https://github.com/prisma/prisma-next.git",
|
|
45
|
+
"directory": "packages/2-sql/4-lanes/relational-core"
|
|
68
46
|
},
|
|
69
47
|
"scripts": {
|
|
70
|
-
"build": "
|
|
48
|
+
"build": "tsdown",
|
|
71
49
|
"test": "vitest run",
|
|
72
50
|
"test:coverage": "vitest run --coverage",
|
|
73
51
|
"typecheck": "tsc --project tsconfig.json --noEmit",
|
package/src/ast/adapter-types.ts
CHANGED
|
@@ -2,6 +2,11 @@ import type { CodecRegistry } from './codec-types';
|
|
|
2
2
|
|
|
3
3
|
export type AdapterTarget = string;
|
|
4
4
|
|
|
5
|
+
export interface MarkerStatement {
|
|
6
|
+
readonly sql: string;
|
|
7
|
+
readonly params: readonly unknown[];
|
|
8
|
+
}
|
|
9
|
+
|
|
5
10
|
export interface AdapterProfile<TTarget extends AdapterTarget = AdapterTarget> {
|
|
6
11
|
readonly id: string;
|
|
7
12
|
readonly target: TTarget;
|
|
@@ -12,6 +17,12 @@ export interface AdapterProfile<TTarget extends AdapterTarget = AdapterTarget> {
|
|
|
12
17
|
* between wire types and JavaScript types.
|
|
13
18
|
*/
|
|
14
19
|
codecs(): CodecRegistry;
|
|
20
|
+
/**
|
|
21
|
+
* Returns the SQL statement to read the contract marker from the database.
|
|
22
|
+
* Each adapter provides target-specific SQL (e.g. schema-qualified table names,
|
|
23
|
+
* parameter placeholder style).
|
|
24
|
+
*/
|
|
25
|
+
readMarkerStatement(): MarkerStatement;
|
|
15
26
|
}
|
|
16
27
|
|
|
17
28
|
export interface LoweredPayload<TBody = unknown> {
|
package/src/ast/codec-types.ts
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
|
+
import type { JsonValue } from '@prisma-next/contract/types';
|
|
2
|
+
import type { Codec as BaseCodec, CodecTrait } from '@prisma-next/framework-components/codec';
|
|
3
|
+
import { ifDefined } from '@prisma-next/utils/defined';
|
|
4
|
+
import type { Type } from 'arktype';
|
|
1
5
|
import type { O } from 'ts-toolbelt';
|
|
2
6
|
|
|
7
|
+
export type { CodecTrait } from '@prisma-next/framework-components/codec';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Descriptor for parameterized codecs that require type parameter validation.
|
|
11
|
+
* Shared between adapter (compile-time) and runtime layers to avoid duplication.
|
|
12
|
+
*
|
|
13
|
+
* @template TParams - The shape of the type parameters (e.g., `{ length: number }`)
|
|
14
|
+
* @template THelper - The type returned by the optional `init` hook
|
|
15
|
+
*/
|
|
16
|
+
export interface CodecParamsDescriptor<TParams = Record<string, unknown>, THelper = unknown> {
|
|
17
|
+
/** The codec ID this descriptor applies to (e.g., 'pg/vector@1') */
|
|
18
|
+
readonly codecId: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Arktype schema for validating typeParams.
|
|
22
|
+
* Used to validate both storage.types entries and inline column typeParams.
|
|
23
|
+
*/
|
|
24
|
+
readonly paramsSchema: Type<TParams>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Optional init hook called during runtime context creation.
|
|
28
|
+
* Receives validated params and returns a helper object to be stored in context.types.
|
|
29
|
+
* If not provided, the validated params are stored directly.
|
|
30
|
+
*/
|
|
31
|
+
readonly init?: (params: TParams) => THelper;
|
|
32
|
+
}
|
|
33
|
+
|
|
3
34
|
/**
|
|
4
35
|
* Codec metadata for database-specific type information.
|
|
5
36
|
* Used for schema introspection and verification.
|
|
@@ -15,42 +46,23 @@ export interface CodecMeta {
|
|
|
15
46
|
}
|
|
16
47
|
|
|
17
48
|
/**
|
|
18
|
-
*
|
|
49
|
+
* SQL codec interface — extends the framework base with SQL-specific fields.
|
|
19
50
|
*
|
|
20
51
|
* Codecs are pure, synchronous functions with no side effects or IO.
|
|
21
|
-
* They provide deterministic conversion between database wire types and JS values
|
|
52
|
+
* They provide deterministic conversion between database wire types and JS values,
|
|
53
|
+
* and between JS values and contract JSON.
|
|
22
54
|
*/
|
|
23
|
-
export interface Codec<
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
* Contract scalar type IDs that this codec can handle.
|
|
32
|
-
* Examples: ['text'], ['int4', 'float8'], ['timestamp', 'timestamptz']
|
|
33
|
-
*/
|
|
34
|
-
readonly targetTypes: readonly string[];
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Optional metadata for database-specific type information.
|
|
38
|
-
* Used for schema introspection and verification.
|
|
39
|
-
*/
|
|
55
|
+
export interface Codec<
|
|
56
|
+
Id extends string = string,
|
|
57
|
+
TTraits extends readonly CodecTrait[] = readonly CodecTrait[],
|
|
58
|
+
TWire = unknown,
|
|
59
|
+
TJs = unknown,
|
|
60
|
+
TParams = Record<string, unknown>,
|
|
61
|
+
THelper = unknown,
|
|
62
|
+
> extends BaseCodec<Id, TTraits, TWire, TJs> {
|
|
40
63
|
readonly meta?: CodecMeta;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
* Decode a wire value (from database) to JavaScript type.
|
|
44
|
-
* Must be synchronous and pure (no side effects).
|
|
45
|
-
*/
|
|
46
|
-
decode(wire: TWire): TJs;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Encode a JavaScript value to wire format (for database).
|
|
50
|
-
* Optional - if not provided, values pass through unchanged.
|
|
51
|
-
* Must be synchronous and pure (no side effects).
|
|
52
|
-
*/
|
|
53
|
-
encode?(value: TJs): TWire;
|
|
64
|
+
readonly paramsSchema?: Type<TParams>;
|
|
65
|
+
readonly init?: (params: TParams) => THelper;
|
|
54
66
|
}
|
|
55
67
|
|
|
56
68
|
/**
|
|
@@ -67,6 +79,10 @@ export interface CodecRegistry {
|
|
|
67
79
|
getByScalar(scalar: string): readonly Codec<string>[];
|
|
68
80
|
getDefaultCodec(scalar: string): Codec<string> | undefined;
|
|
69
81
|
register(codec: Codec<string>): void;
|
|
82
|
+
/** Returns true if the codec with this ID has the given trait. */
|
|
83
|
+
hasTrait(codecId: string, trait: CodecTrait): boolean;
|
|
84
|
+
/** Returns all traits for a codec, or an empty array if not found. */
|
|
85
|
+
traitsOf(codecId: string): readonly CodecTrait[];
|
|
70
86
|
[Symbol.iterator](): Iterator<Codec<string>>;
|
|
71
87
|
values(): IterableIterator<Codec<string>>;
|
|
72
88
|
}
|
|
@@ -136,6 +152,15 @@ class CodecRegistryImpl implements CodecRegistry {
|
|
|
136
152
|
}
|
|
137
153
|
}
|
|
138
154
|
|
|
155
|
+
hasTrait(codecId: string, trait: CodecTrait): boolean {
|
|
156
|
+
const codec = this._byId.get(codecId);
|
|
157
|
+
return codec?.traits?.includes(trait) ?? false;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
traitsOf(codecId: string): readonly CodecTrait[] {
|
|
161
|
+
return this._byId.get(codecId)?.traits ?? [];
|
|
162
|
+
}
|
|
163
|
+
|
|
139
164
|
/**
|
|
140
165
|
* Returns an iterator over all registered codecs.
|
|
141
166
|
* Useful for iterating through codecs from another registry.
|
|
@@ -156,20 +181,44 @@ class CodecRegistryImpl implements CodecRegistry {
|
|
|
156
181
|
|
|
157
182
|
/**
|
|
158
183
|
* Codec factory - creates a codec with typeId and encode/decode functions.
|
|
184
|
+
* Provides identity defaults for encodeJson/decodeJson when not supplied.
|
|
159
185
|
*/
|
|
160
|
-
export function codec<
|
|
186
|
+
export function codec<
|
|
187
|
+
Id extends string,
|
|
188
|
+
const TTraits extends readonly CodecTrait[],
|
|
189
|
+
TWire,
|
|
190
|
+
TJs,
|
|
191
|
+
TParams = Record<string, unknown>,
|
|
192
|
+
THelper = unknown,
|
|
193
|
+
>(config: {
|
|
161
194
|
typeId: Id;
|
|
162
195
|
targetTypes: readonly string[];
|
|
163
196
|
encode: (value: TJs) => TWire;
|
|
164
197
|
decode: (wire: TWire) => TJs;
|
|
198
|
+
encodeJson?: (value: TJs) => JsonValue;
|
|
199
|
+
decodeJson?: (json: JsonValue) => TJs;
|
|
165
200
|
meta?: CodecMeta;
|
|
166
|
-
|
|
201
|
+
paramsSchema?: Type<TParams>;
|
|
202
|
+
init?: (params: TParams) => THelper;
|
|
203
|
+
traits?: TTraits;
|
|
204
|
+
renderOutputType?: (typeParams: Record<string, unknown>) => string | undefined;
|
|
205
|
+
}): Codec<Id, TTraits, TWire, TJs, TParams, THelper> {
|
|
206
|
+
const identity = (v: unknown) => v;
|
|
167
207
|
return {
|
|
168
208
|
id: config.typeId,
|
|
169
209
|
targetTypes: config.targetTypes,
|
|
170
|
-
...(
|
|
210
|
+
...ifDefined('meta', config.meta),
|
|
211
|
+
...ifDefined('paramsSchema', config.paramsSchema),
|
|
212
|
+
...ifDefined('init', config.init),
|
|
213
|
+
...ifDefined(
|
|
214
|
+
'traits',
|
|
215
|
+
config.traits ? (Object.freeze([...config.traits]) as TTraits) : undefined,
|
|
216
|
+
),
|
|
217
|
+
...ifDefined('renderOutputType', config.renderOutputType),
|
|
171
218
|
encode: config.encode,
|
|
172
219
|
decode: config.decode,
|
|
220
|
+
encodeJson: (config.encodeJson ?? identity) as (value: TJs) => JsonValue,
|
|
221
|
+
decodeJson: (config.decodeJson ?? identity) as (json: JsonValue) => TJs,
|
|
173
222
|
};
|
|
174
223
|
}
|
|
175
224
|
|
|
@@ -177,13 +226,13 @@ export function codec<Id extends string, TWire, TJs>(config: {
|
|
|
177
226
|
* Type helpers to extract codec types.
|
|
178
227
|
*/
|
|
179
228
|
export type CodecId<T> =
|
|
180
|
-
T extends Codec<infer Id
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
export type
|
|
186
|
-
|
|
229
|
+
T extends Codec<infer Id> ? Id : T extends { readonly id: infer Id } ? Id : never;
|
|
230
|
+
export type CodecInput<T> =
|
|
231
|
+
T extends Codec<string, readonly CodecTrait[], unknown, infer JsT> ? JsT : never;
|
|
232
|
+
export type CodecOutput<T> =
|
|
233
|
+
T extends Codec<string, readonly CodecTrait[], unknown, infer JsT> ? JsT : never;
|
|
234
|
+
export type CodecTraits<T> =
|
|
235
|
+
T extends Codec<string, infer TTraits> ? TTraits[number] & CodecTrait : never;
|
|
187
236
|
|
|
188
237
|
/**
|
|
189
238
|
* Type helper to extract codec types from builder instance.
|
|
@@ -191,11 +240,10 @@ export type CodecOutput<T> = T extends Codec<string, unknown, infer JsT> ? JsT :
|
|
|
191
240
|
export type ExtractCodecTypes<
|
|
192
241
|
ScalarNames extends { readonly [K in keyof ScalarNames]: Codec<string> } = Record<never, never>,
|
|
193
242
|
> = {
|
|
194
|
-
readonly [K in keyof ScalarNames as ScalarNames[K] extends Codec<infer Id
|
|
195
|
-
? Id
|
|
196
|
-
: never]: {
|
|
243
|
+
readonly [K in keyof ScalarNames as ScalarNames[K] extends Codec<infer Id> ? Id : never]: {
|
|
197
244
|
readonly input: CodecInput<ScalarNames[K]>;
|
|
198
245
|
readonly output: CodecOutput<ScalarNames[K]>;
|
|
246
|
+
readonly traits: CodecTraits<ScalarNames[K]>;
|
|
199
247
|
};
|
|
200
248
|
};
|
|
201
249
|
|
|
@@ -231,9 +279,7 @@ export interface CodecDefBuilder<
|
|
|
231
279
|
|
|
232
280
|
readonly codecDefinitions: {
|
|
233
281
|
readonly [K in keyof ScalarNames]: {
|
|
234
|
-
readonly typeId: ScalarNames[K] extends Codec<infer Id extends string
|
|
235
|
-
? Id
|
|
236
|
-
: never;
|
|
282
|
+
readonly typeId: ScalarNames[K] extends Codec<infer Id extends string> ? Id : never;
|
|
237
283
|
readonly scalar: K;
|
|
238
284
|
readonly codec: ScalarNames[K];
|
|
239
285
|
readonly input: CodecInput<ScalarNames[K]>;
|
|
@@ -269,12 +315,16 @@ class CodecDefBuilderImpl<
|
|
|
269
315
|
this._codecs = codecs;
|
|
270
316
|
|
|
271
317
|
// Populate CodecTypes from codecs
|
|
272
|
-
const codecTypes: Record<
|
|
318
|
+
const codecTypes: Record<
|
|
319
|
+
string,
|
|
320
|
+
{ readonly input: unknown; readonly output: unknown; readonly traits: unknown }
|
|
321
|
+
> = {};
|
|
273
322
|
for (const [, codecImpl] of Object.entries(this._codecs)) {
|
|
274
323
|
const codecImplTyped = codecImpl as Codec<string>;
|
|
275
324
|
codecTypes[codecImplTyped.id] = {
|
|
276
325
|
input: undefined as unknown as CodecInput<typeof codecImplTyped>,
|
|
277
326
|
output: undefined as unknown as CodecOutput<typeof codecImplTyped>,
|
|
327
|
+
traits: undefined as unknown as CodecTraits<typeof codecImplTyped>,
|
|
278
328
|
};
|
|
279
329
|
}
|
|
280
330
|
this.CodecTypes = codecTypes as ExtractCodecTypes<ScalarNames>;
|
|
@@ -314,7 +364,7 @@ class CodecDefBuilderImpl<
|
|
|
314
364
|
*/
|
|
315
365
|
get codecDefinitions(): {
|
|
316
366
|
readonly [K in keyof ScalarNames]: {
|
|
317
|
-
readonly typeId: ScalarNames[K] extends Codec<infer Id
|
|
367
|
+
readonly typeId: ScalarNames[K] extends Codec<infer Id> ? Id : never;
|
|
318
368
|
readonly scalar: K;
|
|
319
369
|
readonly codec: ScalarNames[K];
|
|
320
370
|
readonly input: CodecInput<ScalarNames[K]>;
|
|
@@ -348,9 +398,7 @@ class CodecDefBuilderImpl<
|
|
|
348
398
|
|
|
349
399
|
return result as {
|
|
350
400
|
readonly [K in keyof ScalarNames]: {
|
|
351
|
-
readonly typeId: ScalarNames[K] extends Codec<infer Id extends string
|
|
352
|
-
? Id
|
|
353
|
-
: never;
|
|
401
|
+
readonly typeId: ScalarNames[K] extends Codec<infer Id extends string> ? Id : never;
|
|
354
402
|
readonly scalar: K;
|
|
355
403
|
readonly codec: ScalarNames[K];
|
|
356
404
|
readonly input: CodecInput<ScalarNames[K]>;
|
package/src/ast/driver-types.ts
CHANGED
|
@@ -13,13 +13,30 @@ export interface SqlExplainResult<Row = Record<string, unknown>> {
|
|
|
13
13
|
readonly rows: ReadonlyArray<Row>;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export
|
|
17
|
-
|
|
16
|
+
export type SqlDriverState = 'unbound' | 'connected' | 'closed';
|
|
17
|
+
|
|
18
|
+
export interface SqlDriver<TBinding = void> extends SqlQueryable {
|
|
19
|
+
readonly state?: SqlDriverState;
|
|
20
|
+
connect(binding: TBinding): Promise<void>;
|
|
21
|
+
acquireConnection(): Promise<SqlConnection>;
|
|
22
|
+
close(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface SqlConnection extends SqlQueryable {
|
|
26
|
+
beginTransaction(): Promise<SqlTransaction>;
|
|
27
|
+
release(): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface SqlTransaction extends SqlQueryable {
|
|
31
|
+
commit(): Promise<void>;
|
|
32
|
+
rollback(): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface SqlQueryable {
|
|
18
36
|
execute<Row = Record<string, unknown>>(request: SqlExecuteRequest): AsyncIterable<Row>;
|
|
19
37
|
explain?(request: SqlExecuteRequest): Promise<SqlExplainResult>;
|
|
20
38
|
query<Row = Record<string, unknown>>(
|
|
21
39
|
sql: string,
|
|
22
40
|
params?: readonly unknown[],
|
|
23
41
|
): Promise<SqlQueryResult<Row>>;
|
|
24
|
-
close(): Promise<void>;
|
|
25
42
|
}
|