@prisma-next/sql-relational-core 0.3.0-dev.7 → 0.3.0-dev.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +18 -2
- package/dist/errors-7_V3El9I.mjs +3 -0
- package/dist/errors-DVufq9PT.d.mts +2 -0
- package/dist/exports/ast.d.mts +192 -0
- package/dist/exports/ast.d.mts.map +1 -0
- package/dist/exports/ast.mjs +361 -0
- package/dist/exports/ast.mjs.map +1 -0
- package/dist/exports/errors.d.mts +2 -0
- package/dist/exports/errors.mjs +3 -0
- package/dist/exports/guards.d.mts +5 -0
- package/dist/exports/guards.mjs +3 -0
- package/dist/exports/operations-registry.d.mts +5 -0
- package/dist/exports/operations-registry.mjs +3 -0
- package/dist/exports/param.d.mts +5 -0
- package/dist/exports/param.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 +2 -0
- package/dist/exports/query-lane-context.mjs +1 -0
- package/dist/exports/schema.d.mts +5 -0
- package/dist/exports/schema.mjs +4 -0
- package/dist/exports/types.d.mts +4 -0
- package/dist/exports/types.mjs +3 -0
- package/dist/exports/utils/guards.d.mts +5 -0
- package/dist/exports/utils/guards.mjs +4 -0
- package/dist/guards-0ycyntYX.mjs +132 -0
- package/dist/guards-0ycyntYX.mjs.map +1 -0
- package/dist/guards-DCCpAlOL.d.mts +87 -0
- package/dist/guards-DCCpAlOL.d.mts.map +1 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.mjs +12 -0
- package/dist/operations-registry-DPZ5aElH.mjs +152 -0
- package/dist/operations-registry-DPZ5aElH.mjs.map +1 -0
- package/dist/operations-registry-wVEaiLyt.d.mts +9 -0
- package/dist/operations-registry-wVEaiLyt.d.mts.map +1 -0
- package/dist/param-C4n0OW59.d.mts +8 -0
- package/dist/param-C4n0OW59.d.mts.map +1 -0
- package/dist/param-DMU3OWfI.mjs +14 -0
- package/dist/param-DMU3OWfI.mjs.map +1 -0
- package/dist/plan-BhSWuTfw.d.mts +194 -0
- package/dist/plan-BhSWuTfw.d.mts.map +1 -0
- package/dist/query-lane-context-CgkPuKaR.d.mts +259 -0
- package/dist/query-lane-context-CgkPuKaR.d.mts.map +1 -0
- package/dist/schema-Bi5p4aAc.mjs +175 -0
- package/dist/schema-Bi5p4aAc.mjs.map +1 -0
- package/dist/schema-CgrEMqEd.d.mts +86 -0
- package/dist/schema-CgrEMqEd.d.mts.map +1 -0
- package/dist/types-CEUzDuDC.d.mts +447 -0
- package/dist/types-CEUzDuDC.d.mts.map +1 -0
- package/dist/types-Cdi4Whda.mjs +18 -0
- package/dist/types-Cdi4Whda.mjs.map +1 -0
- package/package.json +39 -56
- package/src/ast/codec-types.ts +77 -8
- package/src/ast/delete.ts +2 -2
- package/src/ast/driver-types.ts +20 -3
- package/src/ast/predicate.ts +14 -4
- package/src/ast/select.ts +4 -3
- package/src/ast/sql-codecs.ts +67 -0
- package/src/ast/types.ts +89 -19
- package/src/ast/update.ts +2 -2
- package/src/exports/ast.ts +1 -0
- package/src/exports/guards.ts +5 -0
- package/src/exports/utils/guards.ts +1 -0
- package/src/operations-registry.ts +112 -73
- package/src/query-lane-context.ts +77 -1
- package/src/schema.ts +91 -33
- package/src/types.ts +327 -75
- package/src/utils/guards.ts +88 -18
- 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 -118
- 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-2F7DSEOU.js +0 -8
- package/dist/chunk-2F7DSEOU.js.map +0 -1
- package/dist/chunk-36WJWNHT.js +0 -1
- package/dist/chunk-36WJWNHT.js.map +0 -1
- package/dist/chunk-5N34PNVZ.js +0 -62
- package/dist/chunk-5N34PNVZ.js.map +0 -1
- package/dist/chunk-7I3EMQID.js +0 -16
- package/dist/chunk-7I3EMQID.js.map +0 -1
- package/dist/chunk-CBTYMOX2.js +0 -152
- package/dist/chunk-CBTYMOX2.js.map +0 -1
- package/dist/chunk-G52ENULI.js +0 -1
- package/dist/chunk-G52ENULI.js.map +0 -1
- package/dist/chunk-KYSP7L5C.js +0 -16
- package/dist/chunk-KYSP7L5C.js.map +0 -1
- package/dist/chunk-M23L3JHG.js +0 -159
- package/dist/chunk-M23L3JHG.js.map +0 -1
- package/dist/chunk-MM74SVJ4.js +0 -13
- package/dist/chunk-MM74SVJ4.js.map +0 -1
- package/dist/chunk-U7AXAUJA.js +0 -1
- package/dist/chunk-U7AXAUJA.js.map +0 -1
- package/dist/chunk-WZBPVEZI.js +0 -320
- package/dist/chunk-WZBPVEZI.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 -21
- 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 -14
- 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 -16
- package/dist/query-lane-context.d.ts.map +0 -1
- package/dist/schema.d.ts +0 -63
- package/dist/schema.d.ts.map +0 -1
- package/dist/types.d.ts +0 -332
- package/dist/types.d.ts.map +0 -1
- package/dist/utils/guards.d.ts +0 -55
- package/dist/utils/guards.d.ts.map +0 -1
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { ReturnSpec } from "@prisma-next/operations";
|
|
2
|
+
import { ExecutionPlan, ParamDescriptor } from "@prisma-next/contract/types";
|
|
3
|
+
import { SqlLoweringSpec } from "@prisma-next/sql-operations";
|
|
4
|
+
import { StorageColumn } from "@prisma-next/sql-contract/types";
|
|
5
|
+
|
|
6
|
+
//#region src/ast/types.d.ts
|
|
7
|
+
type Direction = 'asc' | 'desc';
|
|
8
|
+
interface TableRef {
|
|
9
|
+
readonly kind: 'table';
|
|
10
|
+
readonly name: string;
|
|
11
|
+
}
|
|
12
|
+
interface ColumnRef {
|
|
13
|
+
readonly kind: 'col';
|
|
14
|
+
readonly table: string;
|
|
15
|
+
readonly column: string;
|
|
16
|
+
}
|
|
17
|
+
interface ParamRef {
|
|
18
|
+
readonly kind: 'param';
|
|
19
|
+
readonly index: number;
|
|
20
|
+
readonly name?: string;
|
|
21
|
+
}
|
|
22
|
+
interface LiteralExpr {
|
|
23
|
+
readonly kind: 'literal';
|
|
24
|
+
readonly value: unknown;
|
|
25
|
+
}
|
|
26
|
+
interface OperationExpr {
|
|
27
|
+
readonly kind: 'operation';
|
|
28
|
+
readonly method: string;
|
|
29
|
+
readonly forTypeId: string;
|
|
30
|
+
readonly self: Expression;
|
|
31
|
+
readonly args: ReadonlyArray<Expression | ParamRef | LiteralExpr>;
|
|
32
|
+
readonly returns: ReturnSpec;
|
|
33
|
+
readonly lowering: SqlLoweringSpec;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Unified expression type - the canonical AST representation for column references
|
|
37
|
+
* and operation expressions. This is what all builders convert to via toExpr().
|
|
38
|
+
*/
|
|
39
|
+
type Expression = ColumnRef | OperationExpr;
|
|
40
|
+
/**
|
|
41
|
+
* Interface for any builder that can produce an Expression.
|
|
42
|
+
* Implemented by ColumnBuilder and ExpressionBuilder.
|
|
43
|
+
*/
|
|
44
|
+
interface ExpressionSource {
|
|
45
|
+
toExpr(): Expression;
|
|
46
|
+
}
|
|
47
|
+
declare function isOperationExpr(expr: Expression): expr is OperationExpr;
|
|
48
|
+
type BinaryOp = 'eq' | 'neq' | 'gt' | 'lt' | 'gte' | 'lte' | 'like' | 'ilike' | 'in' | 'notIn';
|
|
49
|
+
interface BinaryExpr {
|
|
50
|
+
readonly kind: 'bin';
|
|
51
|
+
readonly op: BinaryOp;
|
|
52
|
+
readonly left: Expression;
|
|
53
|
+
readonly right: Expression | ParamRef | LiteralExpr | ListLiteralExpr;
|
|
54
|
+
}
|
|
55
|
+
interface ListLiteralExpr {
|
|
56
|
+
readonly kind: 'listLiteral';
|
|
57
|
+
readonly values: ReadonlyArray<ParamRef | LiteralExpr>;
|
|
58
|
+
}
|
|
59
|
+
interface AndExpr {
|
|
60
|
+
readonly kind: 'and';
|
|
61
|
+
readonly exprs: ReadonlyArray<WhereExpr>;
|
|
62
|
+
}
|
|
63
|
+
interface OrExpr {
|
|
64
|
+
readonly kind: 'or';
|
|
65
|
+
readonly exprs: ReadonlyArray<WhereExpr>;
|
|
66
|
+
}
|
|
67
|
+
interface ExistsExpr {
|
|
68
|
+
readonly kind: 'exists';
|
|
69
|
+
readonly not: boolean;
|
|
70
|
+
readonly subquery: SelectAst;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Unary expression for IS NULL / IS NOT NULL checks.
|
|
74
|
+
* Used in WHERE clauses to check for null values.
|
|
75
|
+
*/
|
|
76
|
+
interface NullCheckExpr {
|
|
77
|
+
readonly kind: 'nullCheck';
|
|
78
|
+
readonly expr: Expression;
|
|
79
|
+
readonly isNull: boolean;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Union type for WHERE clause expressions.
|
|
83
|
+
*/
|
|
84
|
+
type WhereExpr = BinaryExpr | ExistsExpr | NullCheckExpr | AndExpr | OrExpr;
|
|
85
|
+
interface BoundWhereExpr {
|
|
86
|
+
readonly expr: WhereExpr;
|
|
87
|
+
readonly params: readonly unknown[];
|
|
88
|
+
readonly paramDescriptors: ReadonlyArray<ParamDescriptor>;
|
|
89
|
+
}
|
|
90
|
+
interface ToWhereExpr {
|
|
91
|
+
toWhereExpr(): BoundWhereExpr;
|
|
92
|
+
}
|
|
93
|
+
type WhereArg = WhereExpr | ToWhereExpr;
|
|
94
|
+
type JoinOnExpr = {
|
|
95
|
+
readonly kind: 'eqCol';
|
|
96
|
+
readonly left: ColumnRef;
|
|
97
|
+
readonly right: ColumnRef;
|
|
98
|
+
} | WhereExpr;
|
|
99
|
+
interface JoinAst {
|
|
100
|
+
readonly kind: 'join';
|
|
101
|
+
readonly joinType: 'inner' | 'left' | 'right' | 'full';
|
|
102
|
+
readonly table: TableRef;
|
|
103
|
+
readonly on: JoinOnExpr;
|
|
104
|
+
}
|
|
105
|
+
interface IncludeRef {
|
|
106
|
+
readonly kind: 'includeRef';
|
|
107
|
+
readonly alias: string;
|
|
108
|
+
}
|
|
109
|
+
interface IncludeAst {
|
|
110
|
+
readonly kind: 'includeMany';
|
|
111
|
+
readonly alias: string;
|
|
112
|
+
readonly child: {
|
|
113
|
+
readonly table: TableRef;
|
|
114
|
+
readonly on: JoinOnExpr;
|
|
115
|
+
readonly where?: WhereExpr;
|
|
116
|
+
readonly orderBy?: ReadonlyArray<{
|
|
117
|
+
expr: Expression;
|
|
118
|
+
dir: Direction;
|
|
119
|
+
}>;
|
|
120
|
+
readonly limit?: number;
|
|
121
|
+
readonly project: ReadonlyArray<{
|
|
122
|
+
alias: string;
|
|
123
|
+
expr: Expression;
|
|
124
|
+
}>;
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
interface SelectAst {
|
|
128
|
+
readonly kind: 'select';
|
|
129
|
+
readonly from: TableRef;
|
|
130
|
+
readonly joins?: ReadonlyArray<JoinAst>;
|
|
131
|
+
readonly includes?: ReadonlyArray<IncludeAst>;
|
|
132
|
+
readonly project: ReadonlyArray<{
|
|
133
|
+
alias: string;
|
|
134
|
+
expr: Expression | IncludeRef | LiteralExpr;
|
|
135
|
+
}>;
|
|
136
|
+
readonly where?: WhereExpr;
|
|
137
|
+
readonly orderBy?: ReadonlyArray<{
|
|
138
|
+
expr: Expression;
|
|
139
|
+
dir: Direction;
|
|
140
|
+
}>;
|
|
141
|
+
readonly limit?: number;
|
|
142
|
+
readonly selectAllIntent?: {
|
|
143
|
+
table?: string;
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
interface InsertAst {
|
|
147
|
+
readonly kind: 'insert';
|
|
148
|
+
readonly table: TableRef;
|
|
149
|
+
readonly values: Record<string, ColumnRef | ParamRef>;
|
|
150
|
+
readonly returning?: ReadonlyArray<ColumnRef>;
|
|
151
|
+
}
|
|
152
|
+
interface UpdateAst {
|
|
153
|
+
readonly kind: 'update';
|
|
154
|
+
readonly table: TableRef;
|
|
155
|
+
readonly set: Record<string, ColumnRef | ParamRef>;
|
|
156
|
+
readonly where?: WhereExpr;
|
|
157
|
+
readonly returning?: ReadonlyArray<ColumnRef>;
|
|
158
|
+
}
|
|
159
|
+
interface DeleteAst {
|
|
160
|
+
readonly kind: 'delete';
|
|
161
|
+
readonly table: TableRef;
|
|
162
|
+
readonly where?: WhereExpr;
|
|
163
|
+
readonly returning?: ReadonlyArray<ColumnRef>;
|
|
164
|
+
}
|
|
165
|
+
type QueryAst = SelectAst | InsertAst | UpdateAst | DeleteAst;
|
|
166
|
+
interface LoweredStatement {
|
|
167
|
+
readonly sql: string;
|
|
168
|
+
readonly params: readonly unknown[];
|
|
169
|
+
readonly annotations?: Record<string, unknown>;
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/plan.d.ts
|
|
173
|
+
/**
|
|
174
|
+
* SQL query plan produced by lanes before lowering.
|
|
175
|
+
*
|
|
176
|
+
* Lanes build ASTs and metadata but do not perform SQL lowering.
|
|
177
|
+
* The `sql` field is absent - lowering happens in the runtime executor.
|
|
178
|
+
*
|
|
179
|
+
* Structurally aligns with ExecutionPlan<Row, QueryAst> (without sql field) to maintain
|
|
180
|
+
* compatibility with ExecutionPlan/Plan-based utilities.
|
|
181
|
+
* The generic parameter `_Row` is preserved for type extraction via ResultType.
|
|
182
|
+
*/
|
|
183
|
+
interface SqlQueryPlan<_Row = unknown> extends Pick<ExecutionPlan<_Row, QueryAst>, 'params' | 'meta'> {
|
|
184
|
+
readonly ast: QueryAst;
|
|
185
|
+
readonly _Row?: _Row;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Augments the last ParamDescriptor in the array with codecId and nativeType from columnMeta.
|
|
189
|
+
* This is used when building WHERE expressions to ensure param descriptors have type information.
|
|
190
|
+
*/
|
|
191
|
+
declare function augmentDescriptorWithColumnMeta(descriptors: ParamDescriptor[], columnMeta: StorageColumn | undefined): void;
|
|
192
|
+
//#endregion
|
|
193
|
+
export { WhereArg as A, OrExpr as C, TableRef as D, SelectAst as E, isOperationExpr as M, ToWhereExpr as O, OperationExpr as S, QueryAst as T, JoinOnExpr as _, BinaryOp as a, LoweredStatement as b, DeleteAst as c, Expression as d, ExpressionSource as f, JoinAst as g, InsertAst as h, BinaryExpr as i, WhereExpr as j, UpdateAst as k, Direction as l, IncludeRef as m, augmentDescriptorWithColumnMeta as n, BoundWhereExpr as o, IncludeAst as p, AndExpr as r, ColumnRef as s, SqlQueryPlan as t, ExistsExpr as u, ListLiteralExpr as v, ParamRef as w, NullCheckExpr as x, LiteralExpr as y };
|
|
194
|
+
//# sourceMappingURL=plan-BhSWuTfw.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-BhSWuTfw.d.mts","names":[],"sources":["../src/ast/types.ts","../src/plan.ts"],"sourcesContent":[],"mappings":";;;;;;KAOY,SAAA;UAEK,QAAA;;EAFL,SAAA,IAAS,EAAA,MAAA;AAErB;AAKiB,UAAA,SAAA,CAAS;EAMT,SAAA,IAAQ,EAAA,KAAA;EAMR,SAAA,KAAW,EAAA,MAAA;EAKX,S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EAAa,SAAA,GAAA,ECpB5B,QDoB4B;EAAW,SAAA,IAAA,CAAA,ECjBrC,IDiBqC;;;;;AASvD;AAMiB,iBCzBD,+BAAA,CD0BM,WAAA,ECzBP,eDyBO,EAAA,EAAA,UAAA,ECxBR,aDwBQ,GAAA,SAAA,CAAA,EAAA,IAAA"}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { Type } from "arktype";
|
|
2
|
+
import { OperationRegistry } from "@prisma-next/operations";
|
|
3
|
+
import { O } from "ts-toolbelt";
|
|
4
|
+
import { SqlContract, SqlStorage } from "@prisma-next/sql-contract/types";
|
|
5
|
+
|
|
6
|
+
//#region src/ast/codec-types.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Descriptor for parameterized codecs that require type parameter validation.
|
|
10
|
+
* Shared between adapter (compile-time) and runtime layers to avoid duplication.
|
|
11
|
+
*
|
|
12
|
+
* @template TParams - The shape of the type parameters (e.g., `{ length: number }`)
|
|
13
|
+
* @template THelper - The type returned by the optional `init` hook
|
|
14
|
+
*/
|
|
15
|
+
interface CodecParamsDescriptor<TParams = Record<string, unknown>, THelper = unknown> {
|
|
16
|
+
/** The codec ID this descriptor applies to (e.g., 'pg/vector@1') */
|
|
17
|
+
readonly codecId: string;
|
|
18
|
+
/**
|
|
19
|
+
* Arktype schema for validating typeParams.
|
|
20
|
+
* Used to validate both storage.types entries and inline column typeParams.
|
|
21
|
+
*/
|
|
22
|
+
readonly paramsSchema: Type<TParams>;
|
|
23
|
+
/**
|
|
24
|
+
* Optional init hook called during runtime context creation.
|
|
25
|
+
* Receives validated params and returns a helper object to be stored in context.types.
|
|
26
|
+
* If not provided, the validated params are stored directly.
|
|
27
|
+
*/
|
|
28
|
+
readonly init?: (params: TParams) => THelper;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Codec metadata for database-specific type information.
|
|
32
|
+
* Used for schema introspection and verification.
|
|
33
|
+
*/
|
|
34
|
+
interface CodecMeta {
|
|
35
|
+
readonly db?: {
|
|
36
|
+
readonly sql?: {
|
|
37
|
+
readonly postgres?: {
|
|
38
|
+
readonly nativeType: string;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Codec interface for encoding/decoding values between wire format and JavaScript types.
|
|
45
|
+
*
|
|
46
|
+
* Codecs are pure, synchronous functions with no side effects or IO.
|
|
47
|
+
* They provide deterministic conversion between database wire types and JS values.
|
|
48
|
+
*/
|
|
49
|
+
interface Codec<Id$1 extends string = string, TWire = unknown, TJs = unknown, TParams = Record<string, unknown>, THelper = unknown> {
|
|
50
|
+
/**
|
|
51
|
+
* Namespaced codec identifier in format 'namespace/name@version'
|
|
52
|
+
* Examples: 'pg/text@1', 'pg/uuid@1', 'pg/timestamptz@1'
|
|
53
|
+
*/
|
|
54
|
+
readonly id: Id$1;
|
|
55
|
+
/**
|
|
56
|
+
* Contract scalar type IDs that this codec can handle.
|
|
57
|
+
* Examples: ['text'], ['int4', 'float8'], ['timestamp', 'timestamptz']
|
|
58
|
+
*/
|
|
59
|
+
readonly targetTypes: readonly string[];
|
|
60
|
+
/**
|
|
61
|
+
* Optional metadata for database-specific type information.
|
|
62
|
+
* Used for schema introspection and verification.
|
|
63
|
+
*/
|
|
64
|
+
readonly meta?: CodecMeta;
|
|
65
|
+
/**
|
|
66
|
+
* Optional params schema for parameterized codecs.
|
|
67
|
+
* If provided, typeParams are validated against this schema.
|
|
68
|
+
*/
|
|
69
|
+
readonly paramsSchema?: Type<TParams>;
|
|
70
|
+
/**
|
|
71
|
+
* Optional init hook for building runtime helper state from validated params.
|
|
72
|
+
*
|
|
73
|
+
* Useful when parameterized types need derived data at runtime, for example:
|
|
74
|
+
* - normalize typeParams into a stable helper shape consumed by lanes/adapters
|
|
75
|
+
* - precompute reusable values once during context creation
|
|
76
|
+
* - avoid repeating typeParams parsing logic during query execution
|
|
77
|
+
*
|
|
78
|
+
* Example:
|
|
79
|
+
* { length: 255 } -> { kind: 'variable', maxLength: 255 }
|
|
80
|
+
*
|
|
81
|
+
* **Convention for JSON/JSONB codecs**: When the helper includes a `validate`
|
|
82
|
+
* property of type `JsonSchemaValidateFn`, the runtime will use it to enforce
|
|
83
|
+
* JSON Schema conformance during encoding and decoding. The property is
|
|
84
|
+
* discovered via duck typing (`helper?.validate`) for flexibility across
|
|
85
|
+
* different codec types.
|
|
86
|
+
*/
|
|
87
|
+
readonly init?: (params: TParams) => THelper;
|
|
88
|
+
/**
|
|
89
|
+
* Decode a wire value (from database) to JavaScript type.
|
|
90
|
+
* Must be synchronous and pure (no side effects).
|
|
91
|
+
*/
|
|
92
|
+
decode(wire: TWire): TJs;
|
|
93
|
+
/**
|
|
94
|
+
* Encode a JavaScript value to wire format (for database).
|
|
95
|
+
* Optional - if not provided, values pass through unchanged.
|
|
96
|
+
* Must be synchronous and pure (no side effects).
|
|
97
|
+
*/
|
|
98
|
+
encode?(value: TJs): TWire;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Registry interface for codecs organized by ID and by contract scalar type.
|
|
102
|
+
*
|
|
103
|
+
* The registry allows looking up codecs by their namespaced ID or by the
|
|
104
|
+
* contract scalar types they handle. Multiple codecs may handle the same
|
|
105
|
+
* scalar type; ordering in byScalar reflects preference (adapter first,
|
|
106
|
+
* then packs, then app overrides).
|
|
107
|
+
*/
|
|
108
|
+
interface CodecRegistry {
|
|
109
|
+
get(id: string): Codec<string> | undefined;
|
|
110
|
+
has(id: string): boolean;
|
|
111
|
+
getByScalar(scalar: string): readonly Codec<string>[];
|
|
112
|
+
getDefaultCodec(scalar: string): Codec<string> | undefined;
|
|
113
|
+
register(codec: Codec<string>): void;
|
|
114
|
+
[Symbol.iterator](): Iterator<Codec<string>>;
|
|
115
|
+
values(): IterableIterator<Codec<string>>;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Codec factory - creates a codec with typeId and encode/decode functions.
|
|
119
|
+
*/
|
|
120
|
+
declare function codec<Id$1 extends string, TWire, TJs, TParams = Record<string, unknown>, THelper = unknown>(config: {
|
|
121
|
+
typeId: Id$1;
|
|
122
|
+
targetTypes: readonly string[];
|
|
123
|
+
encode: (value: TJs) => TWire;
|
|
124
|
+
decode: (wire: TWire) => TJs;
|
|
125
|
+
meta?: CodecMeta;
|
|
126
|
+
paramsSchema?: Type<TParams>;
|
|
127
|
+
init?: (params: TParams) => THelper;
|
|
128
|
+
}): Codec<Id$1, TWire, TJs, TParams, THelper>;
|
|
129
|
+
/**
|
|
130
|
+
* Type helpers to extract codec types.
|
|
131
|
+
*/
|
|
132
|
+
type CodecId<T> = T extends Codec<infer Id, unknown, unknown> ? Id : T extends {
|
|
133
|
+
readonly id: infer Id;
|
|
134
|
+
} ? Id : never;
|
|
135
|
+
type CodecInput<T> = T extends Codec<string, unknown, infer JsT> ? JsT : never;
|
|
136
|
+
type CodecOutput<T> = T extends Codec<string, unknown, infer JsT> ? JsT : never;
|
|
137
|
+
/**
|
|
138
|
+
* Type helper to extract codec types from builder instance.
|
|
139
|
+
*/
|
|
140
|
+
type ExtractCodecTypes$1<ScalarNames extends { readonly [K in keyof ScalarNames]: Codec<string> } = Record<never, never>> = { readonly [K in keyof ScalarNames as ScalarNames[K] extends Codec<infer Id, unknown, unknown> ? Id : never]: {
|
|
141
|
+
readonly input: CodecInput<ScalarNames[K]>;
|
|
142
|
+
readonly output: CodecOutput<ScalarNames[K]>;
|
|
143
|
+
} };
|
|
144
|
+
/**
|
|
145
|
+
* Type helper to extract data type IDs from builder instance.
|
|
146
|
+
* Uses ExtractCodecTypes which preserves literal types as keys.
|
|
147
|
+
* Since ExtractCodecTypes<Record<K, ScalarNames[K]>> has exactly one key (the Id),
|
|
148
|
+
* we extract it by creating a mapped type that uses the Id as both key and value,
|
|
149
|
+
* then extract the value type. This preserves literal types.
|
|
150
|
+
*/
|
|
151
|
+
type ExtractDataTypes<ScalarNames extends { readonly [K in keyof ScalarNames]: Codec<string> }> = { readonly [K in keyof ScalarNames]: { readonly [Id in keyof ExtractCodecTypes$1<Record<K, ScalarNames[K]>>]: Id }[keyof ExtractCodecTypes$1<Record<K, ScalarNames[K]>>] };
|
|
152
|
+
/**
|
|
153
|
+
* Builder interface for declaring codecs.
|
|
154
|
+
*/
|
|
155
|
+
interface CodecDefBuilder<ScalarNames extends { readonly [K in keyof ScalarNames]: Codec<string> } = Record<never, never>> {
|
|
156
|
+
readonly CodecTypes: ExtractCodecTypes$1<ScalarNames>;
|
|
157
|
+
add<ScalarName extends string, CodecImpl extends Codec<string>>(scalarName: ScalarName, codecImpl: CodecImpl): CodecDefBuilder<O.Overwrite<ScalarNames, Record<ScalarName, CodecImpl>> & Record<ScalarName, CodecImpl>>;
|
|
158
|
+
readonly codecDefinitions: { readonly [K in keyof ScalarNames]: {
|
|
159
|
+
readonly typeId: ScalarNames[K] extends Codec<infer Id extends string, unknown, unknown> ? Id : never;
|
|
160
|
+
readonly scalar: K;
|
|
161
|
+
readonly codec: ScalarNames[K];
|
|
162
|
+
readonly input: CodecInput<ScalarNames[K]>;
|
|
163
|
+
readonly output: CodecOutput<ScalarNames[K]>;
|
|
164
|
+
readonly jsType: CodecOutput<ScalarNames[K]>;
|
|
165
|
+
} };
|
|
166
|
+
readonly dataTypes: { readonly [K in keyof ScalarNames]: { readonly [Id in keyof ExtractCodecTypes$1<Record<K, ScalarNames[K]>>]: Id }[keyof ExtractCodecTypes$1<Record<K, ScalarNames[K]>>] };
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Create a new codec registry.
|
|
170
|
+
*/
|
|
171
|
+
declare function createCodecRegistry(): CodecRegistry;
|
|
172
|
+
/**
|
|
173
|
+
* Create a new codec definition builder.
|
|
174
|
+
*/
|
|
175
|
+
declare function defineCodecs(): CodecDefBuilder<Record<never, never>>;
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/query-lane-context.d.ts
|
|
178
|
+
/**
|
|
179
|
+
* Registry of initialized type helpers from storage.types.
|
|
180
|
+
* Each key is a type name from storage.types, and the value is:
|
|
181
|
+
* - The result of the codec's init hook (if provided), or
|
|
182
|
+
* - The full StorageTypeInstance metadata (codecId, nativeType, typeParams) if no init hook
|
|
183
|
+
*/
|
|
184
|
+
type TypeHelperRegistry = Record<string, unknown>;
|
|
185
|
+
/**
|
|
186
|
+
* A single validation error from JSON Schema validation.
|
|
187
|
+
*/
|
|
188
|
+
interface JsonSchemaValidationError {
|
|
189
|
+
readonly path: string;
|
|
190
|
+
readonly message: string;
|
|
191
|
+
readonly keyword: string;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Result of a JSON Schema validation.
|
|
195
|
+
*/
|
|
196
|
+
type JsonSchemaValidationResult = {
|
|
197
|
+
readonly valid: true;
|
|
198
|
+
} | {
|
|
199
|
+
readonly valid: false;
|
|
200
|
+
readonly errors: ReadonlyArray<JsonSchemaValidationError>;
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* A compiled JSON Schema validate function.
|
|
204
|
+
* Returns a structured result indicating whether the value conforms to the schema.
|
|
205
|
+
*/
|
|
206
|
+
type JsonSchemaValidateFn = (value: unknown) => JsonSchemaValidationResult;
|
|
207
|
+
/**
|
|
208
|
+
* Registry of compiled JSON Schema validators for columns with typed JSON/JSONB.
|
|
209
|
+
*
|
|
210
|
+
* Built during context creation by scanning the contract for columns whose codec
|
|
211
|
+
* descriptor provides an `init` hook that returns a `{ validate }` helper.
|
|
212
|
+
* Keys are `"table.column"` (e.g., `"user.metadata"`).
|
|
213
|
+
*/
|
|
214
|
+
interface JsonSchemaValidatorRegistry {
|
|
215
|
+
/** Get the compiled validator for a column. Key format: "table.column". */
|
|
216
|
+
get(key: string): JsonSchemaValidateFn | undefined;
|
|
217
|
+
/** Number of registered validators. */
|
|
218
|
+
readonly size: number;
|
|
219
|
+
}
|
|
220
|
+
type MutationDefaultsOp = 'create' | 'update';
|
|
221
|
+
type AppliedMutationDefault = {
|
|
222
|
+
readonly column: string;
|
|
223
|
+
readonly value: unknown;
|
|
224
|
+
};
|
|
225
|
+
type MutationDefaultsOptions = {
|
|
226
|
+
readonly op: MutationDefaultsOp;
|
|
227
|
+
readonly table: string;
|
|
228
|
+
readonly values: Record<string, unknown>;
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* Minimal context interface for SQL query lanes.
|
|
232
|
+
*
|
|
233
|
+
* Lanes only need contract, operations, and codecs to build typed ASTs and attach
|
|
234
|
+
* operation builders. This interface explicitly excludes runtime concerns like
|
|
235
|
+
* adapters, connection management, and transaction state.
|
|
236
|
+
*/
|
|
237
|
+
interface ExecutionContext<TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>> {
|
|
238
|
+
readonly contract: TContract;
|
|
239
|
+
readonly operations: OperationRegistry;
|
|
240
|
+
readonly codecs: CodecRegistry;
|
|
241
|
+
/**
|
|
242
|
+
* Type helper registry for parameterized types.
|
|
243
|
+
* Schema builders expose these helpers via schema.types.
|
|
244
|
+
*/
|
|
245
|
+
readonly types: TypeHelperRegistry;
|
|
246
|
+
/**
|
|
247
|
+
* Compiled JSON Schema validators for typed JSON/JSONB columns.
|
|
248
|
+
* Present only when the contract declares columns with JSON Schema typeParams.
|
|
249
|
+
*/
|
|
250
|
+
readonly jsonSchemaValidators?: JsonSchemaValidatorRegistry;
|
|
251
|
+
/**
|
|
252
|
+
* Applies execution-time mutation defaults for the given table.
|
|
253
|
+
* Returns the applied defaults (caller-provided values always win).
|
|
254
|
+
*/
|
|
255
|
+
applyMutationDefaults(options: MutationDefaultsOptions): ReadonlyArray<AppliedMutationDefault>;
|
|
256
|
+
}
|
|
257
|
+
//#endregion
|
|
258
|
+
export { defineCodecs as S, CodecRegistry as _, JsonSchemaValidationResult as a, codec as b, MutationDefaultsOptions as c, CodecDefBuilder as d, CodecId as f, CodecParamsDescriptor as g, CodecOutput as h, JsonSchemaValidationError as i, TypeHelperRegistry as l, CodecMeta as m, ExecutionContext as n, JsonSchemaValidatorRegistry as o, CodecInput as p, JsonSchemaValidateFn as r, MutationDefaultsOp as s, AppliedMutationDefault as t, Codec as u, ExtractCodecTypes$1 as v, createCodecRegistry as x, ExtractDataTypes as y };
|
|
259
|
+
//# sourceMappingURL=query-lane-context-CgkPuKaR.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-lane-context-CgkPuKaR.d.mts","names":[],"sources":["../src/ast/codec-types.ts","../src/query-lane-context.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AAWA;;;AAQyB,UARR,qBAQQ,CAAA,UARwB,MAQxB,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,UAAA,OAAA,CAAA,CAAA;EAOE;EAAY,SAAA,OAAA,EAAA,MAAA;EAAO;AAO9C;AAgBA;;EAWe,SAAA,YAAA,EAzCU,IAyCV,CAzCe,OAyCf,CAAA;EAYG;;;;;EA+BH,SAAA,IAAA,CAAA,EAAA,CAAA,MAAA,EA7EY,OA6EZ,EAAA,GA7EwB,OA6ExB;;;;;AAkBf;AACmB,UAzFF,SAAA,CAyFE;EAEqB,SAAA,EAAA,CAAA,EAAA;IACL,SAAA,GAAA,CAAA,EAAA;MACjB,SAAA,QAAA,CAAA,EAAA;QACc,SAAA,UAAA,EAAA,MAAA;MAAT,CAAA;IACM,CAAA;EAAjB,CAAA;;AAyFZ;;;;;;AAU2B,UAlLV,KAkLU,CAAA,aAAA,MAAA,GAAA,MAAA,EAAA,QAAA,OAAA,EAAA,MAAA,OAAA,EAAA,UA9Kf,MA8Ke,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,UAAA,OAAA,CAAA,CAAA;EAClB;;;;EAEqB,SAAA,EAAA,EA1Kf,IA0Ke;EACpB;;;;EAAyB,SAAA,WAAA,EAAA,SAAA,MAAA,EAAA;EAA/B;;AAeJ;;EACY,SAAA,IAAA,CAAA,EA/KM,SA+KN;EAEN;;AAGN;AACA;EAKY,SAAA,YAAA,CAAiB,EApLH,IAoLG,CApLE,OAoLF,CAAA;EACgB;;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,UDoLY,CAAA,GCpLE,WDoLF,CCpLc,UDoLd,CAAA,CAAA,CAAA;EAKhC,SAAA,QAAA,ECvLS,SDuLQ;EACgB,SAAA,UAAA,ECvLtB,iBDuLsB;EAAc,SAAA,MAAA,ECtLxC,aDsLwC;EAAkB;;;;EAEhB,SAAA,KAAA,ECnL3C,kBDmL2C;EAG9B;;;;EACc,SAAA,oBAAA,CAAA,EClLX,2BDkLW;EAAxB;;AAWrB;;EAC2D,qBAAA,CAAA,OAAA,ECzL1B,uBDyL0B,CAAA,ECzLA,aDyLA,CCzLc,sBDyLd,CAAA"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { t as attachOperationsToColumnBuilder } from "./operations-registry-DPZ5aElH.mjs";
|
|
2
|
+
import { planInvalid } from "@prisma-next/plan";
|
|
3
|
+
|
|
4
|
+
//#region src/schema.ts
|
|
5
|
+
var ColumnBuilderImpl = class {
|
|
6
|
+
kind = "column";
|
|
7
|
+
constructor(table, column, storageColumn) {
|
|
8
|
+
this.table = table;
|
|
9
|
+
this.column = column;
|
|
10
|
+
this.storageColumn = storageColumn;
|
|
11
|
+
}
|
|
12
|
+
get columnMeta() {
|
|
13
|
+
return this.storageColumn;
|
|
14
|
+
}
|
|
15
|
+
get __jsType() {}
|
|
16
|
+
/**
|
|
17
|
+
* Converts this column builder to a ColumnRef expression.
|
|
18
|
+
* This is the canonical way to get an AST node from a builder.
|
|
19
|
+
*/
|
|
20
|
+
toExpr() {
|
|
21
|
+
return Object.freeze({
|
|
22
|
+
kind: "col",
|
|
23
|
+
table: this.table,
|
|
24
|
+
column: this.column
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
createBinaryBuilder(op, value) {
|
|
28
|
+
if (value == null) throw planInvalid("Parameter placeholder or expression source required for column comparison");
|
|
29
|
+
if ("toExpr" in value && typeof value.toExpr === "function") return Object.freeze({
|
|
30
|
+
kind: "binary",
|
|
31
|
+
op,
|
|
32
|
+
left: this.toExpr(),
|
|
33
|
+
right: value
|
|
34
|
+
});
|
|
35
|
+
if ("kind" in value && value.kind === "param-placeholder") return Object.freeze({
|
|
36
|
+
kind: "binary",
|
|
37
|
+
op,
|
|
38
|
+
left: this.toExpr(),
|
|
39
|
+
right: value
|
|
40
|
+
});
|
|
41
|
+
throw planInvalid("Parameter placeholder or expression source required for column comparison");
|
|
42
|
+
}
|
|
43
|
+
eq(value) {
|
|
44
|
+
return this.createBinaryBuilder("eq", value);
|
|
45
|
+
}
|
|
46
|
+
neq(value) {
|
|
47
|
+
return this.createBinaryBuilder("neq", value);
|
|
48
|
+
}
|
|
49
|
+
gt(value) {
|
|
50
|
+
return this.createBinaryBuilder("gt", value);
|
|
51
|
+
}
|
|
52
|
+
lt(value) {
|
|
53
|
+
return this.createBinaryBuilder("lt", value);
|
|
54
|
+
}
|
|
55
|
+
gte(value) {
|
|
56
|
+
return this.createBinaryBuilder("gte", value);
|
|
57
|
+
}
|
|
58
|
+
lte(value) {
|
|
59
|
+
return this.createBinaryBuilder("lte", value);
|
|
60
|
+
}
|
|
61
|
+
asc() {
|
|
62
|
+
return Object.freeze({
|
|
63
|
+
kind: "order",
|
|
64
|
+
expr: this.toExpr(),
|
|
65
|
+
dir: "asc"
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
desc() {
|
|
69
|
+
return Object.freeze({
|
|
70
|
+
kind: "order",
|
|
71
|
+
expr: this.toExpr(),
|
|
72
|
+
dir: "desc"
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Creates an IS NULL check for this column.
|
|
77
|
+
* Available on all columns at runtime, but typed to only be visible on nullable columns.
|
|
78
|
+
*/
|
|
79
|
+
isNull() {
|
|
80
|
+
return Object.freeze({
|
|
81
|
+
kind: "nullCheck",
|
|
82
|
+
expr: this.toExpr(),
|
|
83
|
+
isNull: true
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Creates an IS NOT NULL check for this column.
|
|
88
|
+
* Available on all columns at runtime, but typed to only be visible on nullable columns.
|
|
89
|
+
*/
|
|
90
|
+
isNotNull() {
|
|
91
|
+
return Object.freeze({
|
|
92
|
+
kind: "nullCheck",
|
|
93
|
+
expr: this.toExpr(),
|
|
94
|
+
isNull: false
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
var TableBuilderImpl = class {
|
|
99
|
+
kind = "table";
|
|
100
|
+
columns;
|
|
101
|
+
_name;
|
|
102
|
+
constructor(name, columns) {
|
|
103
|
+
this._name = name;
|
|
104
|
+
this.columns = columns;
|
|
105
|
+
}
|
|
106
|
+
get name() {
|
|
107
|
+
return this._name;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
function buildColumns(tableName, storage, _contract, operationRegistry, contractCapabilities) {
|
|
111
|
+
const table = storage.tables[tableName];
|
|
112
|
+
if (!table) throw planInvalid(`Unknown table ${tableName}`);
|
|
113
|
+
const tableColumns = table.columns;
|
|
114
|
+
const result = {};
|
|
115
|
+
const assignColumn = (columnName, columnDef) => {
|
|
116
|
+
result[columnName] = attachOperationsToColumnBuilder(new ColumnBuilderImpl(tableName, columnName, columnDef), columnDef, operationRegistry, contractCapabilities);
|
|
117
|
+
};
|
|
118
|
+
for (const columnName of Object.keys(tableColumns)) {
|
|
119
|
+
const columnDef = tableColumns[columnName];
|
|
120
|
+
if (!columnDef) continue;
|
|
121
|
+
assignColumn(columnName, columnDef);
|
|
122
|
+
}
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Creates a Proxy that enables accessing table columns directly on the table object,
|
|
127
|
+
* in addition to the standard `table.columns.columnName` syntax.
|
|
128
|
+
*
|
|
129
|
+
* This allows both access patterns:
|
|
130
|
+
* - `tables.user.columns.id` (standard access)
|
|
131
|
+
* - `tables.user.id` (convenience access via proxy)
|
|
132
|
+
*
|
|
133
|
+
* The proxy intercepts property access and routes column name lookups to
|
|
134
|
+
* `table.columns[prop]`, while preserving direct access to table properties
|
|
135
|
+
* like `name`, `kind`, and `columns`.
|
|
136
|
+
*/
|
|
137
|
+
function createTableProxy(table) {
|
|
138
|
+
return new Proxy(table, { get(target, prop) {
|
|
139
|
+
if (prop === "name" || prop === "kind" || prop === "columns") return Reflect.get(target, prop);
|
|
140
|
+
if (typeof prop === "string" && prop in target.columns) return target.columns[prop];
|
|
141
|
+
} });
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Creates a schema handle for building SQL queries.
|
|
145
|
+
*
|
|
146
|
+
* @param context - Query lane context containing contract, codec and operation registries
|
|
147
|
+
* @returns A schema handle with typed table builders and type helpers
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* const schemaHandle = schema<Contract>(context);
|
|
152
|
+
* const userTable = schemaHandle.tables.user;
|
|
153
|
+
* const vectorType = schemaHandle.types.Vector1536;
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
function schema(context) {
|
|
157
|
+
const contract = context.contract;
|
|
158
|
+
const storage = contract.storage;
|
|
159
|
+
const tables = {};
|
|
160
|
+
const contractCapabilities = contract.capabilities;
|
|
161
|
+
const operationRegistry = context.operations;
|
|
162
|
+
for (const tableName of Object.keys(storage.tables)) {
|
|
163
|
+
const proxiedTable = createTableProxy(new TableBuilderImpl(tableName, buildColumns(tableName, storage, contract, operationRegistry, contractCapabilities)));
|
|
164
|
+
tables[tableName] = Object.freeze(proxiedTable);
|
|
165
|
+
}
|
|
166
|
+
const types = context.types;
|
|
167
|
+
return Object.freeze({
|
|
168
|
+
tables,
|
|
169
|
+
types
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
//#endregion
|
|
174
|
+
export { TableBuilderImpl as n, schema as r, ColumnBuilderImpl as t };
|
|
175
|
+
//# sourceMappingURL=schema-Bi5p4aAc.mjs.map
|