@prisma-next/sql-relational-core 0.5.0-dev.60 → 0.5.0-dev.62

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.
Files changed (58) hide show
  1. package/README.md +45 -47
  2. package/dist/{errors-p3Ou_n9J.d.mts → errors-Chs-ph28.d.mts} +2 -2
  3. package/dist/errors-Chs-ph28.d.mts.map +1 -0
  4. package/dist/{errors-D6kqqjHM.mjs → errors-kgKOaDM1.mjs} +1 -1
  5. package/dist/{errors-D6kqqjHM.mjs.map → errors-kgKOaDM1.mjs.map} +1 -1
  6. package/dist/exports/ast.d.mts +141 -87
  7. package/dist/exports/ast.d.mts.map +1 -1
  8. package/dist/exports/ast.mjs +242 -272
  9. package/dist/exports/ast.mjs.map +1 -1
  10. package/dist/exports/codec-descriptor-registry.d.mts +18 -0
  11. package/dist/exports/codec-descriptor-registry.d.mts.map +1 -0
  12. package/dist/exports/codec-descriptor-registry.mjs +40 -0
  13. package/dist/exports/codec-descriptor-registry.mjs.map +1 -0
  14. package/dist/exports/errors.d.mts +4 -4
  15. package/dist/exports/errors.mjs +1 -1
  16. package/dist/exports/expression.d.mts +29 -24
  17. package/dist/exports/expression.d.mts.map +1 -1
  18. package/dist/exports/expression.mjs +33 -11
  19. package/dist/exports/expression.mjs.map +1 -1
  20. package/dist/exports/plan.d.mts +2 -2
  21. package/dist/exports/query-lane-context.d.mts +2 -3
  22. package/dist/exports/types.d.mts +5 -4
  23. package/dist/index.d.mts +10 -11
  24. package/dist/index.mjs +5 -5
  25. package/dist/{plan-C7SiEWkN.d.mts → plan-nwFE15re.d.mts} +2 -2
  26. package/dist/plan-nwFE15re.d.mts.map +1 -0
  27. package/dist/query-lane-context-DlWgKvvt.d.mts +175 -0
  28. package/dist/query-lane-context-DlWgKvvt.d.mts.map +1 -0
  29. package/dist/{sql-execution-plan-Dgx7BGin.d.mts → sql-execution-plan-DTfj23Tj.d.mts} +2 -2
  30. package/dist/{sql-execution-plan-Dgx7BGin.d.mts.map → sql-execution-plan-DTfj23Tj.d.mts.map} +1 -1
  31. package/dist/{types-DUL-3vy6.mjs → types-CO7zrXfK.mjs} +15 -7
  32. package/dist/types-CO7zrXfK.mjs.map +1 -0
  33. package/dist/{types-DviRR7AL.d.mts → types-G3hdNPZZ.d.mts} +4 -4
  34. package/dist/{types-DviRR7AL.d.mts.map → types-G3hdNPZZ.d.mts.map} +1 -1
  35. package/dist/{types-B4dL4lc3.d.mts → types-U74HFwNI.d.mts} +22 -4
  36. package/dist/types-U74HFwNI.d.mts.map +1 -0
  37. package/dist/{types-BUlUvdIU.d.mts → types-dPxXIUPS.d.mts} +3 -3
  38. package/dist/{types-BUlUvdIU.d.mts.map → types-dPxXIUPS.d.mts.map} +1 -1
  39. package/package.json +10 -8
  40. package/src/ast/adapter-types.ts +3 -19
  41. package/src/ast/codec-types.ts +53 -541
  42. package/src/ast/sql-codec-helpers.ts +79 -0
  43. package/src/ast/sql-codecs.ts +280 -137
  44. package/src/ast/types.ts +33 -8
  45. package/src/ast/validate-param-refs.ts +39 -0
  46. package/src/codec-descriptor-registry.ts +52 -0
  47. package/src/exports/ast.ts +2 -0
  48. package/src/exports/codec-descriptor-registry.ts +1 -0
  49. package/src/expression.ts +40 -23
  50. package/src/query-lane-context.ts +14 -96
  51. package/dist/codec-types-DJEaWT36.d.mts +0 -313
  52. package/dist/codec-types-DJEaWT36.d.mts.map +0 -1
  53. package/dist/errors-p3Ou_n9J.d.mts.map +0 -1
  54. package/dist/plan-C7SiEWkN.d.mts.map +0 -1
  55. package/dist/query-lane-context-Bwca4sc8.d.mts +0 -150
  56. package/dist/query-lane-context-Bwca4sc8.d.mts.map +0 -1
  57. package/dist/types-B4dL4lc3.d.mts.map +0 -1
  58. package/dist/types-DUL-3vy6.mjs.map +0 -1
@@ -1,296 +1,236 @@
1
- import { A as UpdateAst, C as OrExpr, D as SelectAst, E as ProjectionItem, M as isWhereExpr, N as queryAstKinds, O as SubqueryExpr, P as whereExprKinds, S as OperationExpr, T as ParamRef, _ as JsonObjectExpr, a as DefaultValueExpr, b as NotExpr, c as DoNothingConflictAction, d as ExistsExpr, f as IdentifierRef, g as JsonArrayAggExpr, h as JoinAst, i as ColumnRef, j as isQueryAst, k as TableSource, l as DoUpdateSetConflictAction, m as InsertOnConflict, n as AndExpr, o as DeleteAst, p as InsertAst, r as BinaryExpr, s as DerivedTableSource, t as AggregateExpr, u as EqColJoinOn, v as ListExpression, w as OrderByItem, x as NullCheckExpr, y as LiteralExpr } from "../types-DUL-3vy6.mjs";
2
- import { ifDefined } from "@prisma-next/utils/defined";
1
+ import { A as UpdateAst, C as OrExpr, D as SelectAst, E as ProjectionItem, M as isWhereExpr, N as queryAstKinds, O as SubqueryExpr, P as whereExprKinds, S as OperationExpr, T as ParamRef, _ as JsonObjectExpr, a as DefaultValueExpr, b as NotExpr, c as DoNothingConflictAction, d as ExistsExpr, f as IdentifierRef, g as JsonArrayAggExpr, h as JoinAst, i as ColumnRef, j as isQueryAst, k as TableSource, l as DoUpdateSetConflictAction, m as InsertOnConflict, n as AndExpr, o as DeleteAst, p as InsertAst, r as BinaryExpr, s as DerivedTableSource, t as AggregateExpr, u as EqColJoinOn, v as ListExpression, w as OrderByItem, x as NullCheckExpr, y as LiteralExpr } from "../types-CO7zrXfK.mjs";
2
+ import { CodecDescriptorImpl, CodecImpl, column, voidParamsSchema } from "@prisma-next/framework-components/codec";
3
3
  import { type } from "arktype";
4
+ import { runtimeError } from "@prisma-next/framework-components/runtime";
4
5
 
5
- //#region src/ast/codec-types.ts
6
- /**
7
- * Implementation of CodecRegistry.
8
- */
9
- var CodecRegistryImpl = class {
10
- _byId = /* @__PURE__ */ new Map();
11
- _byScalar = /* @__PURE__ */ new Map();
12
- /**
13
- * Map-like interface for codec lookup by ID.
14
- * Example: registry.get('pg/text@1')
15
- */
16
- get(id) {
17
- return this._byId.get(id);
18
- }
19
- /**
20
- * Check if a codec with the given ID is registered.
21
- */
22
- has(id) {
23
- return this._byId.has(id);
24
- }
25
- /**
26
- * Get all codecs that handle a given scalar type.
27
- * Returns an empty frozen array if no codecs are found.
28
- * Example: registry.getByScalar('text') → [codec1, codec2, ...]
29
- */
30
- getByScalar(scalar) {
31
- return this._byScalar.get(scalar) ?? Object.freeze([]);
32
- }
33
- /**
34
- * Get the default codec for a scalar type (first registered codec).
35
- * Returns undefined if no codec handles this scalar type.
36
- */
37
- getDefaultCodec(scalar) {
38
- return this._byScalar.get(scalar)?.[0];
39
- }
40
- /**
41
- * Register a codec in the registry.
42
- * Throws an error if a codec with the same ID is already registered.
43
- *
44
- * @param codec - The codec to register
45
- * @throws Error if a codec with the same ID already exists
46
- */
47
- register(codec$1) {
48
- if (this._byId.has(codec$1.id)) throw new Error(`Codec with ID '${codec$1.id}' is already registered`);
49
- this._byId.set(codec$1.id, codec$1);
50
- for (const scalarType of codec$1.targetTypes) {
51
- const existing = this._byScalar.get(scalarType);
52
- if (existing) existing.push(codec$1);
53
- else this._byScalar.set(scalarType, [codec$1]);
54
- }
55
- }
56
- hasTrait(codecId, trait) {
57
- return this._byId.get(codecId)?.traits?.includes(trait) ?? false;
58
- }
59
- traitsOf(codecId) {
60
- return this._byId.get(codecId)?.traits ?? [];
61
- }
62
- /**
63
- * Returns an iterator over all registered codecs.
64
- * Useful for iterating through codecs from another registry.
65
- */
66
- *[Symbol.iterator]() {
67
- for (const codec$1 of this._byId.values()) yield codec$1;
68
- }
69
- /**
70
- * Returns an iterable of all registered codecs.
71
- */
72
- values() {
73
- return this._byId.values();
74
- }
75
- };
76
- /**
77
- * Construct a SQL codec from author functions and optional metadata.
78
- *
79
- * Author `encode` and `decode` as sync or async functions; the factory
80
- * produces a {@link Codec} whose query-time methods follow the boundary
81
- * contract documented on `Codec`. Authors receive a second `ctx` options
82
- * argument carrying the SQL-family per-call context; ignore it if you
83
- * don't need it.
84
- *
85
- * Both `encode` and `decode` are required so `TInput` and `TWire` are
86
- * always covered by an explicit author function — the factory installs
87
- * no identity fallback. `encodeJson` and `decodeJson` default to identity
88
- * **only when `TInput` is assignable to `JsonValue`**; otherwise both are
89
- * required so the contract artifact stays JSON-safe.
90
- */
91
- function codec(config) {
92
- const identity = (v) => v;
93
- const userEncode = config.encode;
94
- const userDecode = config.decode;
95
- const widenedConfig = config;
96
- return {
97
- id: config.typeId,
98
- targetTypes: config.targetTypes,
99
- ...ifDefined("meta", config.meta),
100
- ...ifDefined("paramsSchema", config.paramsSchema),
101
- ...ifDefined("init", config.init),
102
- ...ifDefined("traits", config.traits ? Object.freeze([...config.traits]) : void 0),
103
- ...ifDefined("renderOutputType", config.renderOutputType),
104
- encode: (value, ctx) => {
105
- try {
106
- return Promise.resolve(userEncode(value, ctx));
107
- } catch (error) {
108
- return Promise.reject(error);
109
- }
110
- },
111
- decode: (wire, ctx) => {
112
- try {
113
- return Promise.resolve(userDecode(wire, ctx));
114
- } catch (error) {
115
- return Promise.reject(error);
116
- }
117
- },
118
- encodeJson: widenedConfig.encodeJson ?? identity,
119
- decodeJson: widenedConfig.decodeJson ?? identity
120
- };
121
- }
122
- /**
123
- * Implementation of CodecDefBuilder.
124
- */
125
- var CodecDefBuilderImpl = class CodecDefBuilderImpl {
126
- _codecs;
127
- CodecTypes;
128
- dataTypes;
129
- constructor(codecs$1) {
130
- this._codecs = codecs$1;
131
- const codecTypes = {};
132
- for (const [, codecImpl] of Object.entries(this._codecs)) {
133
- const codecImplTyped = codecImpl;
134
- codecTypes[codecImplTyped.id] = {
135
- input: void 0,
136
- output: void 0,
137
- traits: void 0
138
- };
139
- }
140
- this.CodecTypes = codecTypes;
141
- const dataTypes = {};
142
- for (const key in this._codecs) if (Object.hasOwn(this._codecs, key)) dataTypes[key] = this._codecs[key].id;
143
- this.dataTypes = dataTypes;
144
- }
145
- add(scalarName, codecImpl) {
146
- return new CodecDefBuilderImpl({
147
- ...this._codecs,
148
- [scalarName]: codecImpl
149
- });
150
- }
151
- /**
152
- * Derive codecDefinitions structure.
153
- */
154
- get codecDefinitions() {
155
- const result = {};
156
- for (const [scalarName, codecImpl] of Object.entries(this._codecs)) {
157
- const codec$1 = codecImpl;
158
- result[scalarName] = {
159
- typeId: codec$1.id,
160
- scalar: scalarName,
161
- codec: codec$1,
162
- input: void 0,
163
- output: void 0,
164
- jsType: void 0
165
- };
166
- }
167
- return result;
168
- }
169
- };
170
- /**
171
- * Create a new codec registry.
172
- */
173
- function createCodecRegistry() {
174
- return new CodecRegistryImpl();
175
- }
176
- /**
177
- * Create a new codec definition builder.
178
- */
179
- function defineCodecs() {
180
- return new CodecDefBuilderImpl({});
181
- }
182
-
183
- //#endregion
184
- //#region src/ast/sql-codecs.ts
6
+ //#region src/ast/sql-codec-helpers.ts
185
7
  const SQL_CHAR_CODEC_ID = "sql/char@1";
186
8
  const SQL_VARCHAR_CODEC_ID = "sql/varchar@1";
187
9
  const SQL_INT_CODEC_ID = "sql/int@1";
188
10
  const SQL_FLOAT_CODEC_ID = "sql/float@1";
189
11
  const SQL_TEXT_CODEC_ID = "sql/text@1";
190
12
  const SQL_TIMESTAMP_CODEC_ID = "sql/timestamp@1";
191
- const lengthParamsSchema = type({ length: "number.integer > 0" });
13
+ const sqlCharEncode = (value) => value;
14
+ const sqlCharDecode = (wire) => wire.trimEnd();
15
+ const sqlCharRenderOutputType = (typeParams) => {
16
+ const length = typeParams.length;
17
+ if (length === void 0) return void 0;
18
+ if (typeof length !== "number" || !Number.isFinite(length) || !Number.isInteger(length)) throw new Error(`renderOutputType: expected integer "length" in typeParams for Char, got ${String(length)}`);
19
+ return `Char<${length}>`;
20
+ };
21
+ const sqlVarcharEncode = (value) => value;
22
+ const sqlVarcharDecode = (wire) => wire;
23
+ const sqlVarcharRenderOutputType = (typeParams) => {
24
+ const length = typeParams.length;
25
+ if (length === void 0) return void 0;
26
+ if (typeof length !== "number" || !Number.isFinite(length) || !Number.isInteger(length)) throw new Error(`renderOutputType: expected integer "length" in typeParams for Varchar, got ${String(length)}`);
27
+ return `Varchar<${length}>`;
28
+ };
29
+ const sqlIntEncode = (value) => value;
30
+ const sqlIntDecode = (wire) => wire;
31
+ const sqlFloatEncode = (value) => value;
32
+ const sqlFloatDecode = (wire) => wire;
33
+ const sqlTextEncode = (value) => value;
34
+ const sqlTextDecode = (wire) => wire;
35
+ const sqlTimestampEncode = (value) => value;
36
+ const sqlTimestampDecode = (wire) => wire;
37
+ const sqlTimestampEncodeJson = (value) => value.toISOString();
38
+ const sqlTimestampDecodeJson = (json) => {
39
+ if (typeof json !== "string") throw new Error(`Expected ISO date string for sql/timestamp@1, got ${typeof json}`);
40
+ const date = new Date(json);
41
+ if (Number.isNaN(date.getTime())) throw new Error(`Invalid ISO date string for sql/timestamp@1: ${json}`);
42
+ return date;
43
+ };
44
+ const sqlTimestampRenderOutputType = (typeParams) => {
45
+ const precision = typeParams.precision;
46
+ if (precision === void 0) return "Timestamp";
47
+ if (typeof precision !== "number" || !Number.isFinite(precision) || !Number.isInteger(precision)) throw new Error(`renderOutputType: expected integer "precision" in typeParams for Timestamp, got ${String(precision)}`);
48
+ return `Timestamp<${precision}>`;
49
+ };
50
+
51
+ //#endregion
52
+ //#region src/ast/sql-codecs.ts
53
+ const lengthParamsSchema = type({ "length?": "number.integer > 0" });
192
54
  const precisionParamsSchema = type({ "precision?": "number.integer >= 0 & number.integer <= 6" });
193
- function createLengthTypeHelper(kind) {
194
- return (params) => ({
195
- kind,
196
- maxLength: params["length"]
197
- });
198
- }
199
- const sqlCharCodec = codec({
200
- typeId: SQL_CHAR_CODEC_ID,
201
- targetTypes: ["char"],
202
- traits: [
55
+ var SqlTextCodec = class extends CodecImpl {
56
+ async encode(value, _ctx) {
57
+ return sqlTextEncode(value);
58
+ }
59
+ async decode(wire, _ctx) {
60
+ return sqlTextDecode(wire);
61
+ }
62
+ encodeJson(value) {
63
+ return value;
64
+ }
65
+ decodeJson(json) {
66
+ return json;
67
+ }
68
+ };
69
+ var SqlTextDescriptor = class extends CodecDescriptorImpl {
70
+ codecId = SQL_TEXT_CODEC_ID;
71
+ traits = [
203
72
  "equality",
204
73
  "order",
205
74
  "textual"
206
- ],
207
- encode: (value) => value,
208
- decode: (wire) => wire.trimEnd(),
209
- paramsSchema: lengthParamsSchema,
210
- init: createLengthTypeHelper("fixed"),
211
- renderOutputType: (typeParams) => {
212
- const length = typeParams["length"];
213
- if (length === void 0) return void 0;
214
- if (typeof length !== "number" || !Number.isFinite(length) || !Number.isInteger(length)) throw new Error(`renderOutputType: expected integer "length" in typeParams for Char, got ${String(length)}`);
215
- return `Char<${length}>`;
216
- }
217
- });
218
- const sqlVarcharCodec = codec({
219
- typeId: SQL_VARCHAR_CODEC_ID,
220
- targetTypes: ["varchar"],
221
- traits: [
75
+ ];
76
+ targetTypes = ["text"];
77
+ paramsSchema = voidParamsSchema;
78
+ factory() {
79
+ return () => new SqlTextCodec(this);
80
+ }
81
+ };
82
+ const sqlTextDescriptor = new SqlTextDescriptor();
83
+ const sqlTextColumn = () => column(sqlTextDescriptor.factory(), sqlTextDescriptor.codecId, void 0, "text");
84
+ var SqlIntCodec = class extends CodecImpl {
85
+ async encode(value, _ctx) {
86
+ return sqlIntEncode(value);
87
+ }
88
+ async decode(wire, _ctx) {
89
+ return sqlIntDecode(wire);
90
+ }
91
+ encodeJson(value) {
92
+ return value;
93
+ }
94
+ decodeJson(json) {
95
+ return json;
96
+ }
97
+ };
98
+ var SqlIntDescriptor = class extends CodecDescriptorImpl {
99
+ codecId = SQL_INT_CODEC_ID;
100
+ traits = [
222
101
  "equality",
223
102
  "order",
224
- "textual"
225
- ],
226
- encode: (value) => value,
227
- decode: (wire) => wire,
228
- paramsSchema: lengthParamsSchema,
229
- init: createLengthTypeHelper("variable"),
230
- renderOutputType: (typeParams) => {
231
- const length = typeParams["length"];
232
- if (length === void 0) return void 0;
233
- if (typeof length !== "number" || !Number.isFinite(length) || !Number.isInteger(length)) throw new Error(`renderOutputType: expected integer "length" in typeParams for Varchar, got ${String(length)}`);
234
- return `Varchar<${length}>`;
235
- }
236
- });
237
- const sqlIntCodec = codec({
238
- typeId: SQL_INT_CODEC_ID,
239
- targetTypes: ["int"],
240
- traits: [
103
+ "numeric"
104
+ ];
105
+ targetTypes = ["int"];
106
+ paramsSchema = voidParamsSchema;
107
+ factory() {
108
+ return () => new SqlIntCodec(this);
109
+ }
110
+ };
111
+ const sqlIntDescriptor = new SqlIntDescriptor();
112
+ const sqlIntColumn = () => column(sqlIntDescriptor.factory(), sqlIntDescriptor.codecId, void 0, "int");
113
+ var SqlFloatCodec = class extends CodecImpl {
114
+ async encode(value, _ctx) {
115
+ return sqlFloatEncode(value);
116
+ }
117
+ async decode(wire, _ctx) {
118
+ return sqlFloatDecode(wire);
119
+ }
120
+ encodeJson(value) {
121
+ return value;
122
+ }
123
+ decodeJson(json) {
124
+ return json;
125
+ }
126
+ };
127
+ var SqlFloatDescriptor = class extends CodecDescriptorImpl {
128
+ codecId = SQL_FLOAT_CODEC_ID;
129
+ traits = [
241
130
  "equality",
242
131
  "order",
243
132
  "numeric"
244
- ],
245
- encode: (value) => value,
246
- decode: (wire) => wire
247
- });
248
- const sqlFloatCodec = codec({
249
- typeId: SQL_FLOAT_CODEC_ID,
250
- targetTypes: ["float"],
251
- traits: [
133
+ ];
134
+ targetTypes = ["float"];
135
+ paramsSchema = voidParamsSchema;
136
+ factory() {
137
+ return () => new SqlFloatCodec(this);
138
+ }
139
+ };
140
+ const sqlFloatDescriptor = new SqlFloatDescriptor();
141
+ const sqlFloatColumn = () => column(sqlFloatDescriptor.factory(), sqlFloatDescriptor.codecId, void 0, "float");
142
+ var SqlCharCodec = class extends CodecImpl {
143
+ async encode(value, _ctx) {
144
+ return sqlCharEncode(value);
145
+ }
146
+ async decode(wire, _ctx) {
147
+ return sqlCharDecode(wire);
148
+ }
149
+ encodeJson(value) {
150
+ return value;
151
+ }
152
+ decodeJson(json) {
153
+ return json;
154
+ }
155
+ };
156
+ var SqlCharDescriptor = class extends CodecDescriptorImpl {
157
+ codecId = SQL_CHAR_CODEC_ID;
158
+ traits = [
252
159
  "equality",
253
160
  "order",
254
- "numeric"
255
- ],
256
- encode: (value) => value,
257
- decode: (wire) => wire
258
- });
259
- const sqlTextCodec = codec({
260
- typeId: SQL_TEXT_CODEC_ID,
261
- targetTypes: ["text"],
262
- traits: [
161
+ "textual"
162
+ ];
163
+ targetTypes = ["char"];
164
+ paramsSchema = lengthParamsSchema;
165
+ renderOutputType(params) {
166
+ return sqlCharRenderOutputType(params);
167
+ }
168
+ factory(_params) {
169
+ return () => new SqlCharCodec(this);
170
+ }
171
+ };
172
+ const sqlCharDescriptor = new SqlCharDescriptor();
173
+ const sqlCharColumn = (params = {}) => column(sqlCharDescriptor.factory(params), sqlCharDescriptor.codecId, params, "char");
174
+ var SqlVarcharCodec = class extends CodecImpl {
175
+ async encode(value, _ctx) {
176
+ return sqlVarcharEncode(value);
177
+ }
178
+ async decode(wire, _ctx) {
179
+ return sqlVarcharDecode(wire);
180
+ }
181
+ encodeJson(value) {
182
+ return value;
183
+ }
184
+ decodeJson(json) {
185
+ return json;
186
+ }
187
+ };
188
+ var SqlVarcharDescriptor = class extends CodecDescriptorImpl {
189
+ codecId = SQL_VARCHAR_CODEC_ID;
190
+ traits = [
263
191
  "equality",
264
192
  "order",
265
193
  "textual"
266
- ],
267
- encode: (value) => value,
268
- decode: (wire) => wire
269
- });
270
- const sqlTimestampCodec = codec({
271
- typeId: SQL_TIMESTAMP_CODEC_ID,
272
- targetTypes: ["timestamp"],
273
- traits: ["equality", "order"],
274
- encode: (value) => value,
275
- decode: (wire) => wire,
276
- encodeJson: (value) => value.toISOString(),
277
- decodeJson: (json) => {
278
- if (typeof json !== "string") throw new Error(`Expected ISO date string for sql/timestamp@1, got ${typeof json}`);
279
- const date = new Date(json);
280
- if (Number.isNaN(date.getTime())) throw new Error(`Invalid ISO date string for sql/timestamp@1: ${json}`);
281
- return date;
282
- },
283
- paramsSchema: precisionParamsSchema,
284
- renderOutputType: (typeParams) => {
285
- const precision = typeParams["precision"];
286
- if (precision === void 0) return "Timestamp";
287
- if (typeof precision !== "number" || !Number.isFinite(precision) || !Number.isInteger(precision)) throw new Error(`renderOutputType: expected integer "precision" in typeParams for Timestamp, got ${String(precision)}`);
288
- return `Timestamp<${precision}>`;
289
- }
290
- });
291
- const codecs = defineCodecs().add("char", sqlCharCodec).add("varchar", sqlVarcharCodec).add("int", sqlIntCodec).add("float", sqlFloatCodec).add("text", sqlTextCodec).add("timestamp", sqlTimestampCodec);
292
- const sqlCodecDefinitions = codecs.codecDefinitions;
293
- const sqlDataTypes = codecs.dataTypes;
194
+ ];
195
+ targetTypes = ["varchar"];
196
+ paramsSchema = lengthParamsSchema;
197
+ renderOutputType(params) {
198
+ return sqlVarcharRenderOutputType(params);
199
+ }
200
+ factory(_params) {
201
+ return () => new SqlVarcharCodec(this);
202
+ }
203
+ };
204
+ const sqlVarcharDescriptor = new SqlVarcharDescriptor();
205
+ const sqlVarcharColumn = (params = {}) => column(sqlVarcharDescriptor.factory(params), sqlVarcharDescriptor.codecId, params, "varchar");
206
+ var SqlTimestampCodec = class extends CodecImpl {
207
+ async encode(value, _ctx) {
208
+ return sqlTimestampEncode(value);
209
+ }
210
+ async decode(wire, _ctx) {
211
+ return sqlTimestampDecode(wire);
212
+ }
213
+ encodeJson(value) {
214
+ return sqlTimestampEncodeJson(value);
215
+ }
216
+ decodeJson(json) {
217
+ return sqlTimestampDecodeJson(json);
218
+ }
219
+ };
220
+ var SqlTimestampDescriptor = class extends CodecDescriptorImpl {
221
+ codecId = SQL_TIMESTAMP_CODEC_ID;
222
+ traits = ["equality", "order"];
223
+ targetTypes = ["timestamp"];
224
+ paramsSchema = precisionParamsSchema;
225
+ renderOutputType(params) {
226
+ return sqlTimestampRenderOutputType(params);
227
+ }
228
+ factory(_params) {
229
+ return () => new SqlTimestampCodec(this);
230
+ }
231
+ };
232
+ const sqlTimestampDescriptor = new SqlTimestampDescriptor();
233
+ const sqlTimestampColumn = (params = {}) => column(sqlTimestampDescriptor.factory(params), sqlTimestampDescriptor.codecId, params, "timestamp");
294
234
 
295
235
  //#endregion
296
236
  //#region src/ast/util.ts
@@ -325,5 +265,35 @@ function collectOrderedParamRefs(ast) {
325
265
  }
326
266
 
327
267
  //#endregion
328
- export { AggregateExpr, AndExpr, BinaryExpr, ColumnRef, DefaultValueExpr, DeleteAst, DerivedTableSource, DoNothingConflictAction, DoUpdateSetConflictAction, EqColJoinOn, ExistsExpr, IdentifierRef, InsertAst, InsertOnConflict, JoinAst, JsonArrayAggExpr, JsonObjectExpr, ListExpression, LiteralExpr, NotExpr, NullCheckExpr, OperationExpr, OrExpr, OrderByItem, ParamRef, ProjectionItem, SQL_CHAR_CODEC_ID, SQL_FLOAT_CODEC_ID, SQL_INT_CODEC_ID, SQL_TEXT_CODEC_ID, SQL_TIMESTAMP_CODEC_ID, SQL_VARCHAR_CODEC_ID, SelectAst, SubqueryExpr, TableSource, UpdateAst, codec, collectOrderedParamRefs, compact, createCodecRegistry, defineCodecs, isQueryAst, isWhereExpr, queryAstKinds, sqlCodecDefinitions, sqlDataTypes, whereExprKinds };
268
+ //#region src/ast/validate-param-refs.ts
269
+ /**
270
+ * Builder-pipeline validator pass: every {@link ParamRef} whose `codecId` resolves to a *parameterized* descriptor must carry `refs: { table, column }` so encode-side dispatch can call `contractCodecs.forColumn(table, column)`. Refs-less parameterized `ParamRef`s are a hard error — the codec-id-keyed `forCodecId` fallback cannot disambiguate per-instance codecs (e.g. `vector(1024)` vs. `vector(1536)`), so the dispatch
271
+ * path must reject them at validation time rather than silently bind to the wrong instance.
272
+ *
273
+ * Non-parameterized codec ids (the `voidParamsSchema` case) are always dispatch-safe via codec id alone, so refs-less ParamRefs for those ids are accepted unchanged.
274
+ *
275
+ * The pass runs post-build / pre-execute — the natural location is the SQL runtime's `lower()` step, between any `beforeCompile` rewrites and `encodeParams`. See AC-5 in the codec-registry-unification spec.
276
+ */
277
+ /**
278
+ * Validate that every parameterized-codec `ParamRef` in `plan` carries `refs`. Throws `RUNTIME.PARAM_REF_REFS_REQUIRED` (a runtime envelope) naming the codec id and the binding label when the invariant is violated. Returns the plan unchanged on success — callers that prefer a side-effecting assertion can ignore the return value.
279
+ *
280
+ * The `registry` is consulted via `descriptorFor(codecId).isParameterized` — `true` whenever the descriptor's `paramsSchema` is not the singleton `voidParamsSchema`.
281
+ */
282
+ function validateParamRefRefs(plan, registry) {
283
+ for (const ref of collectOrderedParamRefs(plan)) diagnoseRef(ref, registry);
284
+ }
285
+ function diagnoseRef(ref, registry) {
286
+ if (!ref.codecId) return;
287
+ const descriptor = registry.descriptorFor(ref.codecId);
288
+ if (descriptor === void 0) return;
289
+ if (!descriptor.isParameterized) return;
290
+ if (ref.refs) return;
291
+ throw runtimeError("RUNTIME.PARAM_REF_REFS_REQUIRED", `ParamRef '${ref.name ?? "<anonymous>"}' for parameterized codec '${ref.codecId}' is missing column refs; column-aware dispatch requires { table, column } at the binding site.`, {
292
+ codecId: ref.codecId,
293
+ paramName: ref.name
294
+ });
295
+ }
296
+
297
+ //#endregion
298
+ export { AggregateExpr, AndExpr, BinaryExpr, ColumnRef, DefaultValueExpr, DeleteAst, DerivedTableSource, DoNothingConflictAction, DoUpdateSetConflictAction, EqColJoinOn, ExistsExpr, IdentifierRef, InsertAst, InsertOnConflict, JoinAst, JsonArrayAggExpr, JsonObjectExpr, ListExpression, LiteralExpr, NotExpr, NullCheckExpr, OperationExpr, OrExpr, OrderByItem, ParamRef, ProjectionItem, SQL_CHAR_CODEC_ID, SQL_FLOAT_CODEC_ID, SQL_INT_CODEC_ID, SQL_TEXT_CODEC_ID, SQL_TIMESTAMP_CODEC_ID, SQL_VARCHAR_CODEC_ID, SelectAst, SqlCharCodec, SqlCharDescriptor, SqlFloatCodec, SqlFloatDescriptor, SqlIntCodec, SqlIntDescriptor, SqlTextCodec, SqlTextDescriptor, SqlTimestampCodec, SqlTimestampDescriptor, SqlVarcharCodec, SqlVarcharDescriptor, SubqueryExpr, TableSource, UpdateAst, collectOrderedParamRefs, compact, isQueryAst, isWhereExpr, queryAstKinds, sqlCharColumn, sqlCharDecode, sqlCharDescriptor, sqlCharEncode, sqlCharRenderOutputType, sqlFloatColumn, sqlFloatDecode, sqlFloatDescriptor, sqlFloatEncode, sqlIntColumn, sqlIntDecode, sqlIntDescriptor, sqlIntEncode, sqlTextColumn, sqlTextDecode, sqlTextDescriptor, sqlTextEncode, sqlTimestampColumn, sqlTimestampDecode, sqlTimestampDecodeJson, sqlTimestampDescriptor, sqlTimestampEncode, sqlTimestampEncodeJson, sqlTimestampRenderOutputType, sqlVarcharColumn, sqlVarcharDecode, sqlVarcharDescriptor, sqlVarcharEncode, sqlVarcharRenderOutputType, validateParamRefRefs, whereExprKinds };
329
299
  //# sourceMappingURL=ast.mjs.map