@sqlbraid/core 1.0.0-rc.1 → 1.0.2
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 +1 -1
- package/README.md +3 -6
- package/dist/driver.d.ts +55 -0
- package/dist/driver.d.ts.map +1 -0
- package/dist/driver.js +156 -0
- package/dist/driver.js.map +1 -0
- package/dist/index.d.ts +674 -311
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +503 -184
- package/dist/index.js.map +1 -1
- package/package.json +22 -18
package/dist/index.js
CHANGED
|
@@ -1,123 +1,5 @@
|
|
|
1
|
-
//#region src/
|
|
2
|
-
|
|
3
|
-
{
|
|
4
|
-
moduleSpecifier: "@sqlbraid/template",
|
|
5
|
-
helperFamily: "template"
|
|
6
|
-
},
|
|
7
|
-
{
|
|
8
|
-
moduleSpecifier: "@sqlbraid/postgres",
|
|
9
|
-
dialectId: "postgres",
|
|
10
|
-
helperFamily: "template"
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
moduleSpecifier: "@sqlbraid/mysql",
|
|
14
|
-
dialectId: "mysql",
|
|
15
|
-
helperFamily: "template"
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
moduleSpecifier: "@sqlbraid/mariadb",
|
|
19
|
-
dialectId: "mariadb",
|
|
20
|
-
helperFamily: "template"
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
moduleSpecifier: "@sqlbraid/sqlite",
|
|
24
|
-
dialectId: "sqlite",
|
|
25
|
-
helperFamily: "template"
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
moduleSpecifier: "@sqlbraid/oracle",
|
|
29
|
-
dialectId: "oracle",
|
|
30
|
-
helperFamily: "template"
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
moduleSpecifier: "@sqlbraid/mssql",
|
|
34
|
-
dialectId: "mssql",
|
|
35
|
-
helperFamily: "template"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
moduleSpecifier: "sqlbraid/pg",
|
|
39
|
-
dialectId: "postgres",
|
|
40
|
-
helperFamily: "facade"
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
moduleSpecifier: "sqlbraid/mysql2",
|
|
44
|
-
dialectId: "mysql",
|
|
45
|
-
helperFamily: "facade"
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
moduleSpecifier: "sqlbraid/mariadb",
|
|
49
|
-
dialectId: "mariadb",
|
|
50
|
-
helperFamily: "facade"
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
moduleSpecifier: "sqlbraid/node-sqlite",
|
|
54
|
-
dialectId: "sqlite",
|
|
55
|
-
helperFamily: "facade"
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
moduleSpecifier: "sqlbraid/better-sqlite3",
|
|
59
|
-
dialectId: "sqlite",
|
|
60
|
-
helperFamily: "facade"
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
moduleSpecifier: "sqlbraid/libsql",
|
|
64
|
-
dialectId: "sqlite",
|
|
65
|
-
helperFamily: "facade"
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
moduleSpecifier: "sqlbraid/sqlite-wasm",
|
|
69
|
-
dialectId: "sqlite",
|
|
70
|
-
helperFamily: "facade"
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
moduleSpecifier: "sqlbraid/d1",
|
|
74
|
-
dialectId: "sqlite",
|
|
75
|
-
helperFamily: "facade"
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
moduleSpecifier: "sqlbraid/oracledb",
|
|
79
|
-
dialectId: "oracle",
|
|
80
|
-
helperFamily: "facade"
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
moduleSpecifier: "sqlbraid/tedious",
|
|
84
|
-
dialectId: "mssql",
|
|
85
|
-
helperFamily: "facade"
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
moduleSpecifier: "sqlbraid/postgres",
|
|
89
|
-
dialectId: "postgres",
|
|
90
|
-
helperFamily: "facade"
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
moduleSpecifier: "sqlbraid/mysql",
|
|
94
|
-
dialectId: "mysql",
|
|
95
|
-
helperFamily: "facade"
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
moduleSpecifier: "sqlbraid/sqlite",
|
|
99
|
-
dialectId: "sqlite",
|
|
100
|
-
helperFamily: "facade"
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
moduleSpecifier: "sqlbraid/oracle",
|
|
104
|
-
dialectId: "oracle",
|
|
105
|
-
helperFamily: "facade"
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
moduleSpecifier: "sqlbraid/mssql",
|
|
109
|
-
dialectId: "mssql",
|
|
110
|
-
helperFamily: "facade"
|
|
111
|
-
}
|
|
112
|
-
].map((entry) => Object.freeze(entry)));
|
|
113
|
-
|
|
114
|
-
//#endregion
|
|
115
|
-
//#region src/index.ts
|
|
116
|
-
const SQL_FRAGMENT = Symbol.for("sqlbraid.fragment");
|
|
117
|
-
const SQL_BOUND_PARAMETER = Symbol.for("sqlbraid.bound-parameter");
|
|
118
|
-
const knownBoundParameters = /* @__PURE__ */ new WeakSet();
|
|
119
|
-
const SQL_ROUTINE_PARAMETER = Symbol.for("sqlbraid.routine-parameter");
|
|
120
|
-
const knownRoutineParameters = /* @__PURE__ */ new WeakSet();
|
|
1
|
+
//#region src/errors.ts
|
|
2
|
+
/** Thrown when a driver value cannot be represented without losing database information. */
|
|
121
3
|
var ResultExactnessError = class ResultExactnessError extends Error {
|
|
122
4
|
static {
|
|
123
5
|
this.code = "BRAID_RESULT_EXACTNESS";
|
|
@@ -204,32 +86,38 @@ const PUBLIC_ERROR_DEFINITIONS = Object.freeze([
|
|
|
204
86
|
{
|
|
205
87
|
code: "BRAID_CALL_UNSUPPORTED",
|
|
206
88
|
category: "adapter",
|
|
207
|
-
owner: "UnsupportedFeatureError"
|
|
89
|
+
owner: "UnsupportedFeatureError",
|
|
90
|
+
features: ["routine.call"]
|
|
208
91
|
},
|
|
209
92
|
{
|
|
210
93
|
code: "BRAID_RESULT_SETS_UNSUPPORTED",
|
|
211
94
|
category: "adapter",
|
|
212
|
-
owner: "UnsupportedFeatureError"
|
|
95
|
+
owner: "UnsupportedFeatureError",
|
|
96
|
+
features: ["routine.result-sets"]
|
|
213
97
|
},
|
|
214
98
|
{
|
|
215
99
|
code: "BRAID_STREAM_UNSUPPORTED",
|
|
216
100
|
category: "adapter",
|
|
217
|
-
owner: "UnsupportedFeatureError"
|
|
101
|
+
owner: "UnsupportedFeatureError",
|
|
102
|
+
features: ["statement.stream"]
|
|
218
103
|
},
|
|
219
104
|
{
|
|
220
105
|
code: "BRAID_CANCEL_UNSUPPORTED",
|
|
221
106
|
category: "adapter",
|
|
222
|
-
owner: "UnsupportedFeatureError"
|
|
107
|
+
owner: "UnsupportedFeatureError",
|
|
108
|
+
features: ["statement.cancel"]
|
|
223
109
|
},
|
|
224
110
|
{
|
|
225
111
|
code: "BRAID_SESSION_UNSUPPORTED",
|
|
226
112
|
category: "adapter",
|
|
227
|
-
owner: "UnsupportedFeatureError"
|
|
113
|
+
owner: "UnsupportedFeatureError",
|
|
114
|
+
features: ["session.pinned"]
|
|
228
115
|
},
|
|
229
116
|
{
|
|
230
117
|
code: "BRAID_TX_UNSUPPORTED",
|
|
231
118
|
category: "adapter",
|
|
232
|
-
owner: "UnsupportedFeatureError"
|
|
119
|
+
owner: "UnsupportedFeatureError",
|
|
120
|
+
features: ["transaction", "transaction.savepoint"]
|
|
233
121
|
},
|
|
234
122
|
{
|
|
235
123
|
code: "BRAID_TX_OPTIONS_INVALID",
|
|
@@ -239,42 +127,61 @@ const PUBLIC_ERROR_DEFINITIONS = Object.freeze([
|
|
|
239
127
|
{
|
|
240
128
|
code: "BRAID_TX_OPTION_UNSUPPORTED",
|
|
241
129
|
category: "adapter",
|
|
242
|
-
owner: "UnsupportedFeatureError"
|
|
130
|
+
owner: "UnsupportedFeatureError",
|
|
131
|
+
features: [
|
|
132
|
+
"transaction.read-only",
|
|
133
|
+
"transaction.isolation.read-uncommitted",
|
|
134
|
+
"transaction.isolation.read-committed",
|
|
135
|
+
"transaction.isolation.repeatable-read",
|
|
136
|
+
"transaction.isolation.serializable"
|
|
137
|
+
]
|
|
243
138
|
},
|
|
244
139
|
{
|
|
245
140
|
code: "BRAID_CALL_RESULT_SETS",
|
|
246
141
|
category: "adapter",
|
|
247
|
-
owner: "UnsupportedFeatureError"
|
|
142
|
+
owner: "UnsupportedFeatureError",
|
|
143
|
+
features: ["routine.result-sets"]
|
|
248
144
|
},
|
|
249
145
|
{
|
|
250
146
|
code: "BRAID_CALL_CURSOR_TX_REQUIRED",
|
|
251
147
|
category: "adapter",
|
|
252
|
-
owner: "UnsupportedFeatureError"
|
|
148
|
+
owner: "UnsupportedFeatureError",
|
|
149
|
+
features: ["routine.out-cursor"]
|
|
253
150
|
},
|
|
254
151
|
{
|
|
255
152
|
code: "BRAID_CALL_OUT_UNSUPPORTED",
|
|
256
153
|
category: "adapter",
|
|
257
|
-
owner: "UnsupportedFeatureError"
|
|
154
|
+
owner: "UnsupportedFeatureError",
|
|
155
|
+
features: ["routine.out", "routine.inout"]
|
|
258
156
|
},
|
|
259
157
|
{
|
|
260
158
|
code: "BRAID_CALL_RETURN_UNSUPPORTED",
|
|
261
159
|
category: "adapter",
|
|
262
|
-
owner: "UnsupportedFeatureError"
|
|
160
|
+
owner: "UnsupportedFeatureError",
|
|
161
|
+
features: ["routine.return-value"]
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
code: "BRAID_CALL_PROCEDURE_INVALID",
|
|
165
|
+
category: "adapter",
|
|
166
|
+
owner: "AdapterError"
|
|
263
167
|
},
|
|
264
168
|
{
|
|
265
169
|
code: "BRAID_CALL_CURSOR_UNSUPPORTED",
|
|
266
170
|
category: "adapter",
|
|
267
|
-
owner: "UnsupportedFeatureError"
|
|
171
|
+
owner: "UnsupportedFeatureError",
|
|
172
|
+
features: ["routine.out-cursor"]
|
|
268
173
|
},
|
|
269
174
|
{
|
|
270
175
|
code: "BRAID_RESOURCE_CLEANUP",
|
|
271
176
|
category: "adapter",
|
|
272
|
-
owner: "adapter cleanup error with code"
|
|
177
|
+
owner: "adapter cleanup error with code",
|
|
178
|
+
features: ["resource.cleanup", "resource.discard"]
|
|
273
179
|
},
|
|
274
180
|
{
|
|
275
181
|
code: "BRAID_BIND_HINT_UNSUPPORTED",
|
|
276
182
|
category: "adapter",
|
|
277
|
-
owner: "UnsupportedFeatureError"
|
|
183
|
+
owner: "UnsupportedFeatureError",
|
|
184
|
+
features: ["statement.bind-hint"]
|
|
278
185
|
},
|
|
279
186
|
{
|
|
280
187
|
code: "BRAID_BIND_VALUE_UNSUPPORTED",
|
|
@@ -284,27 +191,38 @@ const PUBLIC_ERROR_DEFINITIONS = Object.freeze([
|
|
|
284
191
|
{
|
|
285
192
|
code: "BRAID_INTEGER_MODE_UNSUPPORTED",
|
|
286
193
|
category: "adapter",
|
|
287
|
-
owner: "UnsupportedFeatureError"
|
|
194
|
+
owner: "UnsupportedFeatureError",
|
|
195
|
+
features: ["result.exact-integer"]
|
|
288
196
|
},
|
|
289
197
|
{
|
|
290
198
|
code: "BRAID_CALL_LOB_UNSUPPORTED",
|
|
291
199
|
category: "adapter",
|
|
292
|
-
owner: "UnsupportedFeatureError"
|
|
200
|
+
owner: "UnsupportedFeatureError",
|
|
201
|
+
features: ["routine.out"]
|
|
293
202
|
},
|
|
294
203
|
{
|
|
295
204
|
code: "BRAID_BULK_UNSUPPORTED",
|
|
296
205
|
category: "adapter",
|
|
297
|
-
owner: "UnsupportedFeatureError"
|
|
206
|
+
owner: "UnsupportedFeatureError",
|
|
207
|
+
features: ["statement.bulk"]
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
code: "BRAID_PREPARE_UNSUPPORTED",
|
|
211
|
+
category: "adapter",
|
|
212
|
+
owner: "UnsupportedFeatureError",
|
|
213
|
+
features: ["statement.prepare"]
|
|
298
214
|
},
|
|
299
215
|
{
|
|
300
216
|
code: "BRAID_DIALECT_MISMATCH",
|
|
301
217
|
category: "adapter",
|
|
302
|
-
owner: "UnsupportedFeatureError"
|
|
218
|
+
owner: "UnsupportedFeatureError",
|
|
219
|
+
features: ["dialect"]
|
|
303
220
|
},
|
|
304
221
|
{
|
|
305
222
|
code: "BRAID_RESULT_KIND_AMBIGUOUS",
|
|
306
223
|
category: "adapter",
|
|
307
|
-
owner: "UnsupportedFeatureError"
|
|
224
|
+
owner: "UnsupportedFeatureError",
|
|
225
|
+
features: ["result.rows", "result.command"]
|
|
308
226
|
},
|
|
309
227
|
{
|
|
310
228
|
code: "BRAID_PREPARED_NAME",
|
|
@@ -397,9 +315,47 @@ const PUBLIC_ERROR_DEFINITIONS = Object.freeze([
|
|
|
397
315
|
owner: "SqlRenderError"
|
|
398
316
|
}
|
|
399
317
|
]);
|
|
318
|
+
/** Public adapter capability failure. Unsupported features reject explicitly rather than being buffered or simulated. */
|
|
319
|
+
var UnsupportedFeatureError = class extends Error {
|
|
320
|
+
constructor(feature, code, message, options) {
|
|
321
|
+
super(`${code}: ${message}`, options);
|
|
322
|
+
this.feature = feature;
|
|
323
|
+
this.code = code;
|
|
324
|
+
this.name = "UnsupportedFeatureError";
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
/** Return true only for a registered, semantically valid feature/code pair. */
|
|
328
|
+
function isPublicUnsupportedFeatureError(error) {
|
|
329
|
+
if (!(error instanceof UnsupportedFeatureError)) return false;
|
|
330
|
+
return PUBLIC_ERROR_DEFINITIONS.find((candidate) => candidate.owner === "UnsupportedFeatureError" && candidate.code === error.code)?.features?.includes(error.feature) === true;
|
|
331
|
+
}
|
|
332
|
+
/** An adapter-owned input/transport failure that retains TypeError semantics. */
|
|
333
|
+
var AdapterError = class extends TypeError {
|
|
334
|
+
constructor(code, message, options) {
|
|
335
|
+
super(`${code}: ${message}`, options);
|
|
336
|
+
this.code = code;
|
|
337
|
+
this.name = "AdapterError";
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
/** Rendering/authoring failure with a stable diagnostic code, raised before driver execution. */
|
|
341
|
+
var SqlRenderError = class extends Error {
|
|
342
|
+
constructor(code, message) {
|
|
343
|
+
super(message);
|
|
344
|
+
this.name = "SqlRenderError";
|
|
345
|
+
this.code = code;
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/numeric.ts
|
|
400
351
|
function exactnessFailure(message) {
|
|
401
352
|
throw new ResultExactnessError(message);
|
|
402
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* Decode an exact integer from driver output, optionally enforcing bigint bounds.
|
|
356
|
+
*
|
|
357
|
+
* @throws {ResultExactnessError} When the value is not an exact integer or violates the requested range.
|
|
358
|
+
*/
|
|
403
359
|
function decodeExactInteger(value, range) {
|
|
404
360
|
let result;
|
|
405
361
|
if (typeof value === "bigint") result = value;
|
|
@@ -448,12 +404,24 @@ function safeDatabaseCount(value) {
|
|
|
448
404
|
} catch {}
|
|
449
405
|
return exactnessFailure("Database count is not a safe non-negative integer.");
|
|
450
406
|
}
|
|
407
|
+
/**
|
|
408
|
+
* Preserve an exact decimal as text; numeric JavaScript values are rejected because they may already be rounded.
|
|
409
|
+
*
|
|
410
|
+
* @throws {ResultExactnessError} When the value cannot prove exact decimal fidelity.
|
|
411
|
+
*/
|
|
451
412
|
function decodeExactDecimal(value, options) {
|
|
452
413
|
if (typeof value === "string") return value;
|
|
453
414
|
if (typeof value === "bigint" && options?.allowBigInt === true) return value.toString();
|
|
454
415
|
return exactnessFailure("Result value does not have an exact decimal representation.");
|
|
455
416
|
}
|
|
456
|
-
|
|
417
|
+
|
|
418
|
+
//#endregion
|
|
419
|
+
//#region src/parameter.ts
|
|
420
|
+
const SQL_BOUND_PARAMETER = Symbol.for("sqlbraid.bound-parameter");
|
|
421
|
+
const knownBoundParameters = /* @__PURE__ */ new WeakSet();
|
|
422
|
+
const SQL_ROUTINE_PARAMETER = Symbol.for("sqlbraid.routine-parameter");
|
|
423
|
+
const knownRoutineParameters = /* @__PURE__ */ new WeakSet();
|
|
424
|
+
function validHintNumber$1(value) {
|
|
457
425
|
return typeof value === "number" && Number.isFinite(value) && Number.isInteger(value) && value >= 0;
|
|
458
426
|
}
|
|
459
427
|
function validHintInteger(value) {
|
|
@@ -462,14 +430,15 @@ function validHintInteger(value) {
|
|
|
462
430
|
function isParameterTypeHint(value) {
|
|
463
431
|
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
464
432
|
const candidate = value;
|
|
465
|
-
return typeof candidate.databaseType === "string" && candidate.databaseType.trim().length > 0 && (candidate.length === void 0 || candidate.length === "max" || validHintNumber(candidate.length)) && (candidate.precision === void 0 || validHintNumber(candidate.precision)) && (candidate.scale === void 0 || validHintInteger(candidate.scale));
|
|
433
|
+
return typeof candidate.databaseType === "string" && candidate.databaseType.trim().length > 0 && (candidate.length === void 0 || candidate.length === "max" || validHintNumber$1(candidate.length)) && (candidate.precision === void 0 || validHintNumber$1(candidate.precision)) && (candidate.scale === void 0 || validHintInteger(candidate.scale));
|
|
466
434
|
}
|
|
435
|
+
/** Validate and freeze an explicit database parameter-type hint. */
|
|
467
436
|
function createParameterTypeHint(hint) {
|
|
468
437
|
if (!isParameterTypeHint(hint)) throw new TypeError("sql.bind hint must be an object with valid structural fields.");
|
|
469
438
|
const candidate = hint;
|
|
470
439
|
if (typeof candidate.databaseType !== "string" || !candidate.databaseType.trim()) throw new TypeError("sql.bind hint databaseType must be a non-empty string.");
|
|
471
|
-
if (candidate.length !== void 0 && candidate.length !== "max" && !validHintNumber(candidate.length)) throw new TypeError("sql.bind hint length must be a non-negative integer or \"max\".");
|
|
472
|
-
if (candidate.precision !== void 0 && !validHintNumber(candidate.precision)) throw new TypeError("sql.bind hint precision must be a non-negative integer.");
|
|
440
|
+
if (candidate.length !== void 0 && candidate.length !== "max" && !validHintNumber$1(candidate.length)) throw new TypeError("sql.bind hint length must be a non-negative integer or \"max\".");
|
|
441
|
+
if (candidate.precision !== void 0 && !validHintNumber$1(candidate.precision)) throw new TypeError("sql.bind hint precision must be a non-negative integer.");
|
|
473
442
|
if (candidate.scale !== void 0 && !validHintInteger(candidate.scale)) throw new TypeError("sql.bind hint scale must be an integer.");
|
|
474
443
|
const normalized = {
|
|
475
444
|
databaseType: candidate.databaseType,
|
|
@@ -479,6 +448,7 @@ function createParameterTypeHint(hint) {
|
|
|
479
448
|
};
|
|
480
449
|
return Object.freeze(normalized);
|
|
481
450
|
}
|
|
451
|
+
/** Create the value-only marker consumed by adapter binding for an explicitly typed input. */
|
|
482
452
|
function createBoundParameter(value, hint) {
|
|
483
453
|
const normalizedHint = createParameterTypeHint(hint);
|
|
484
454
|
const bound = Object.freeze({
|
|
@@ -489,6 +459,7 @@ function createBoundParameter(value, hint) {
|
|
|
489
459
|
knownBoundParameters.add(bound);
|
|
490
460
|
return bound;
|
|
491
461
|
}
|
|
462
|
+
/** Recognize only bound-parameter objects created by SQLBraid's own constructor. */
|
|
492
463
|
function isBoundParameter(value) {
|
|
493
464
|
if (typeof value !== "object" || value === null || !knownBoundParameters.has(value) || !Object.hasOwn(value, SQL_BOUND_PARAMETER)) return false;
|
|
494
465
|
const candidate = value;
|
|
@@ -498,6 +469,7 @@ function normalizeOutputName(name) {
|
|
|
498
469
|
if (typeof name !== "string" || !name.trim()) throw new TypeError("Routine outputName must be a non-empty string.");
|
|
499
470
|
return name;
|
|
500
471
|
}
|
|
472
|
+
/** Create a value-only OUT parameter descriptor; the adapter supplies the native carrier. */
|
|
501
473
|
function createRoutineOutParameter(name, hint) {
|
|
502
474
|
const normalizedHint = hint === void 0 ? void 0 : createParameterTypeHint(hint);
|
|
503
475
|
const parameter = Object.freeze({
|
|
@@ -510,6 +482,7 @@ function createRoutineOutParameter(name, hint) {
|
|
|
510
482
|
knownRoutineParameters.add(parameter);
|
|
511
483
|
return parameter;
|
|
512
484
|
}
|
|
485
|
+
/** Create a value-only INOUT parameter descriptor; input value and output channel stay distinct. */
|
|
513
486
|
function createRoutineInOutParameter(name, value, hint) {
|
|
514
487
|
const normalizedHint = hint === void 0 ? void 0 : createParameterTypeHint(hint);
|
|
515
488
|
const parameter = Object.freeze({
|
|
@@ -522,15 +495,33 @@ function createRoutineInOutParameter(name, value, hint) {
|
|
|
522
495
|
knownRoutineParameters.add(parameter);
|
|
523
496
|
return parameter;
|
|
524
497
|
}
|
|
498
|
+
/** Recognize only routine OUT/INOUT descriptors created by SQLBraid's own constructor. */
|
|
525
499
|
function isRoutineParameter(value) {
|
|
526
500
|
if (typeof value !== "object" || value === null || Array.isArray(value) || !knownRoutineParameters.has(value)) return false;
|
|
527
501
|
const candidate = value;
|
|
528
502
|
return candidate[SQL_ROUTINE_PARAMETER] === true && Object.hasOwn(candidate, "value") && (candidate.direction === "out" || candidate.direction === "inout") && typeof candidate.outputName === "string" && Boolean(candidate.outputName.trim()) && (candidate.hint === void 0 || isParameterTypeHint(candidate.hint));
|
|
529
503
|
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
*/
|
|
504
|
+
|
|
505
|
+
//#endregion
|
|
506
|
+
//#region src/routine.ts
|
|
507
|
+
/** Identifies which routine channel or row failed during Standard Schema mapping. */
|
|
508
|
+
var RoutineMappingError = class RoutineMappingError extends Error {
|
|
509
|
+
static {
|
|
510
|
+
this.code = "BRAID_CALL_MAP";
|
|
511
|
+
}
|
|
512
|
+
constructor(message, location, options) {
|
|
513
|
+
super(message, options);
|
|
514
|
+
this.code = RoutineMappingError.code;
|
|
515
|
+
this.name = "RoutineMappingError";
|
|
516
|
+
this.location = Object.freeze(location);
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
//#endregion
|
|
521
|
+
//#region src/statement.ts
|
|
522
|
+
function validHintNumber(value) {
|
|
523
|
+
return typeof value === "number" && Number.isFinite(value) && Number.isInteger(value) && value >= 0;
|
|
524
|
+
}
|
|
534
525
|
function createRenderedBulk(bulk) {
|
|
535
526
|
if (bulk === null || typeof bulk !== "object" || Array.isArray(bulk)) throw new TypeError("RenderedBulk must be an object.");
|
|
536
527
|
const statement = createRenderedStatement(bulk.statement);
|
|
@@ -600,6 +591,8 @@ function copyNativeTemplate(value, segments) {
|
|
|
600
591
|
});
|
|
601
592
|
return Object.freeze(cooked);
|
|
602
593
|
}
|
|
594
|
+
/** Validate and freeze one logical statement without creating a second mutable SQL/value source of truth. */
|
|
595
|
+
/** @throws {TypeError|SqlRenderError} For broken segment/parameter invariants or unsupported bind values. */
|
|
603
596
|
function createRenderedStatement(statement) {
|
|
604
597
|
if (typeof statement !== "object" || statement === null) throw new TypeError("RenderedStatement must be an object.");
|
|
605
598
|
if (knownRenderedStatements.has(statement)) return statement;
|
|
@@ -634,6 +627,10 @@ function createRenderedStatement(statement) {
|
|
|
634
627
|
knownRenderedStatements.add(rendered);
|
|
635
628
|
return rendered;
|
|
636
629
|
}
|
|
630
|
+
|
|
631
|
+
//#endregion
|
|
632
|
+
//#region src/binding.ts
|
|
633
|
+
/** Materialize placeholder text as a derived view; this helper does not own reuse or driver transport policy. */
|
|
637
634
|
function parameterizedSql(statement, placeholder) {
|
|
638
635
|
const parts = [statement.segments[0] ?? ""];
|
|
639
636
|
for (let index = 0; index < statement.parameters.length; index += 1) parts.push(placeholder(index + 1), statement.segments[index + 1] ?? "");
|
|
@@ -643,7 +640,10 @@ function genericLiteral(parameter, dialectId, binary) {
|
|
|
643
640
|
const value = parameter.value;
|
|
644
641
|
if (value === null) return "NULL";
|
|
645
642
|
if (value === void 0) return "[undefined]";
|
|
646
|
-
if (typeof value === "string")
|
|
643
|
+
if (typeof value === "string") {
|
|
644
|
+
if (/^(?:mysql|mariadb)/i.test(dialectId)) return `[string ${JSON.stringify(value)}]`;
|
|
645
|
+
return `'${value.replaceAll("'", "''")}'`;
|
|
646
|
+
}
|
|
647
647
|
if (typeof value === "boolean") {
|
|
648
648
|
if (/^(?:mysql|sqlite)/i.test(dialectId) || /^(?:oracle|mssql|sqlserver)/i.test(dialectId)) return value ? "1" : "0";
|
|
649
649
|
if (/^(?:postgres|postgresql|cockroach|redshift)/i.test(dialectId)) return value ? "TRUE" : "FALSE";
|
|
@@ -703,6 +703,7 @@ function literalized(statement, dialectId, formatLiteral, options) {
|
|
|
703
703
|
truncatedParameters
|
|
704
704
|
});
|
|
705
705
|
}
|
|
706
|
+
/** Build an immutable binding description before I/O, including adapter reuse policy and diagnostic literalization. */
|
|
706
707
|
function createStatementBindingDescription(statement, context, options) {
|
|
707
708
|
const logical = createRenderedStatement(statement);
|
|
708
709
|
const adapterId = options.adapterId;
|
|
@@ -802,9 +803,8 @@ function createStatementBindingDescription(statement, context, options) {
|
|
|
802
803
|
return Object.freeze(description);
|
|
803
804
|
}
|
|
804
805
|
/**
|
|
805
|
-
* Build one binding description for a
|
|
806
|
-
* metadata is shared by every parameter set; values and diagnostics are
|
|
807
|
-
* addressed only when requested for a particular item.
|
|
806
|
+
* Build one binding description for a homogeneous bulk statement without cloning application-owned values.
|
|
807
|
+
* Statement metadata is shared by every parameter set; values and diagnostics are addressed by item index.
|
|
808
808
|
*/
|
|
809
809
|
function createBulkBindingDescription(bulk, context, options) {
|
|
810
810
|
const logical = createRenderedBulk(bulk);
|
|
@@ -847,41 +847,360 @@ function createBulkBindingDescription(bulk, context, options) {
|
|
|
847
847
|
});
|
|
848
848
|
return Object.freeze(description);
|
|
849
849
|
}
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
850
|
+
|
|
851
|
+
//#endregion
|
|
852
|
+
//#region src/template-ir.ts
|
|
853
|
+
const SQL_FRAGMENT = Symbol.for("sqlbraid.fragment");
|
|
854
|
+
|
|
855
|
+
//#endregion
|
|
856
|
+
//#region src/authoring-modules.ts
|
|
857
|
+
const AUTHORING_MODULE_CATALOG = Object.freeze([
|
|
858
|
+
{
|
|
859
|
+
moduleSpecifier: "@sqlbraid/template",
|
|
860
|
+
helperFamily: "template"
|
|
861
|
+
},
|
|
862
|
+
{
|
|
863
|
+
moduleSpecifier: "@sqlbraid/postgres",
|
|
864
|
+
dialectId: "postgres",
|
|
865
|
+
helperFamily: "template"
|
|
866
|
+
},
|
|
867
|
+
{
|
|
868
|
+
moduleSpecifier: "@sqlbraid/mysql",
|
|
869
|
+
dialectId: "mysql",
|
|
870
|
+
helperFamily: "template"
|
|
871
|
+
},
|
|
872
|
+
{
|
|
873
|
+
moduleSpecifier: "@sqlbraid/mariadb",
|
|
874
|
+
dialectId: "mariadb",
|
|
875
|
+
helperFamily: "template"
|
|
876
|
+
},
|
|
877
|
+
{
|
|
878
|
+
moduleSpecifier: "@sqlbraid/sqlite",
|
|
879
|
+
dialectId: "sqlite",
|
|
880
|
+
helperFamily: "template"
|
|
881
|
+
},
|
|
882
|
+
{
|
|
883
|
+
moduleSpecifier: "@sqlbraid/oracle",
|
|
884
|
+
dialectId: "oracle",
|
|
885
|
+
helperFamily: "template"
|
|
886
|
+
},
|
|
887
|
+
{
|
|
888
|
+
moduleSpecifier: "@sqlbraid/mssql",
|
|
889
|
+
dialectId: "mssql",
|
|
890
|
+
helperFamily: "template"
|
|
891
|
+
},
|
|
892
|
+
{
|
|
893
|
+
moduleSpecifier: "sqlbraid/pg",
|
|
894
|
+
dialectId: "postgres",
|
|
895
|
+
helperFamily: "facade"
|
|
896
|
+
},
|
|
897
|
+
{
|
|
898
|
+
moduleSpecifier: "sqlbraid/mysql2",
|
|
899
|
+
dialectId: "mysql",
|
|
900
|
+
helperFamily: "facade"
|
|
901
|
+
},
|
|
902
|
+
{
|
|
903
|
+
moduleSpecifier: "sqlbraid/mariadb",
|
|
904
|
+
dialectId: "mariadb",
|
|
905
|
+
helperFamily: "facade"
|
|
906
|
+
},
|
|
907
|
+
{
|
|
908
|
+
moduleSpecifier: "sqlbraid/node-sqlite",
|
|
909
|
+
dialectId: "sqlite",
|
|
910
|
+
helperFamily: "facade"
|
|
911
|
+
},
|
|
912
|
+
{
|
|
913
|
+
moduleSpecifier: "sqlbraid/better-sqlite3",
|
|
914
|
+
dialectId: "sqlite",
|
|
915
|
+
helperFamily: "facade"
|
|
916
|
+
},
|
|
917
|
+
{
|
|
918
|
+
moduleSpecifier: "sqlbraid/libsql",
|
|
919
|
+
dialectId: "sqlite",
|
|
920
|
+
helperFamily: "facade"
|
|
921
|
+
},
|
|
922
|
+
{
|
|
923
|
+
moduleSpecifier: "sqlbraid/sqlite-wasm",
|
|
924
|
+
dialectId: "sqlite",
|
|
925
|
+
helperFamily: "facade"
|
|
926
|
+
},
|
|
927
|
+
{
|
|
928
|
+
moduleSpecifier: "sqlbraid/d1",
|
|
929
|
+
dialectId: "sqlite",
|
|
930
|
+
helperFamily: "facade"
|
|
931
|
+
},
|
|
932
|
+
{
|
|
933
|
+
moduleSpecifier: "sqlbraid/oracledb",
|
|
934
|
+
dialectId: "oracle",
|
|
935
|
+
helperFamily: "facade"
|
|
936
|
+
},
|
|
937
|
+
{
|
|
938
|
+
moduleSpecifier: "sqlbraid/tedious",
|
|
939
|
+
dialectId: "mssql",
|
|
940
|
+
helperFamily: "facade"
|
|
941
|
+
},
|
|
942
|
+
{
|
|
943
|
+
moduleSpecifier: "sqlbraid/postgres",
|
|
944
|
+
dialectId: "postgres",
|
|
945
|
+
helperFamily: "facade"
|
|
946
|
+
},
|
|
947
|
+
{
|
|
948
|
+
moduleSpecifier: "sqlbraid/mysql",
|
|
949
|
+
dialectId: "mysql",
|
|
950
|
+
helperFamily: "facade"
|
|
951
|
+
},
|
|
952
|
+
{
|
|
953
|
+
moduleSpecifier: "sqlbraid/sqlite",
|
|
954
|
+
dialectId: "sqlite",
|
|
955
|
+
helperFamily: "facade"
|
|
956
|
+
},
|
|
957
|
+
{
|
|
958
|
+
moduleSpecifier: "sqlbraid/oracle",
|
|
959
|
+
dialectId: "oracle",
|
|
960
|
+
helperFamily: "facade"
|
|
961
|
+
},
|
|
962
|
+
{
|
|
963
|
+
moduleSpecifier: "sqlbraid/mssql",
|
|
964
|
+
dialectId: "mssql",
|
|
965
|
+
helperFamily: "facade"
|
|
875
966
|
}
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
967
|
+
].map((entry) => Object.freeze(entry)));
|
|
968
|
+
|
|
969
|
+
//#endregion
|
|
970
|
+
//#region src/capabilities.ts
|
|
971
|
+
const definitions = [
|
|
972
|
+
{
|
|
973
|
+
id: "sql.native-transparency",
|
|
974
|
+
family: "support"
|
|
975
|
+
},
|
|
976
|
+
{
|
|
977
|
+
id: "sql.generated-structure",
|
|
978
|
+
family: "support"
|
|
979
|
+
},
|
|
980
|
+
{
|
|
981
|
+
id: "result.rows",
|
|
982
|
+
family: "support"
|
|
983
|
+
},
|
|
984
|
+
{
|
|
985
|
+
id: "result.command",
|
|
986
|
+
family: "support"
|
|
987
|
+
},
|
|
988
|
+
{
|
|
989
|
+
id: "result.multiple-sets",
|
|
990
|
+
family: "support"
|
|
991
|
+
},
|
|
992
|
+
{
|
|
993
|
+
id: "result.standard-schema",
|
|
994
|
+
family: "support"
|
|
995
|
+
},
|
|
996
|
+
{
|
|
997
|
+
id: "numeric.exact-integer",
|
|
998
|
+
family: "representation"
|
|
999
|
+
},
|
|
1000
|
+
{
|
|
1001
|
+
id: "numeric.exact-decimal",
|
|
1002
|
+
family: "representation"
|
|
1003
|
+
},
|
|
1004
|
+
{
|
|
1005
|
+
id: "numeric.approximate-float",
|
|
1006
|
+
family: "representation"
|
|
1007
|
+
},
|
|
1008
|
+
{
|
|
1009
|
+
id: "numeric.approximate-special",
|
|
1010
|
+
family: "representation"
|
|
1011
|
+
},
|
|
1012
|
+
{
|
|
1013
|
+
id: "numeric.bind-exact",
|
|
1014
|
+
family: "representation"
|
|
1015
|
+
},
|
|
1016
|
+
{
|
|
1017
|
+
id: "numeric.aggregate",
|
|
1018
|
+
family: "representation"
|
|
1019
|
+
},
|
|
1020
|
+
{
|
|
1021
|
+
id: "numeric.command-metadata",
|
|
1022
|
+
family: "representation"
|
|
1023
|
+
},
|
|
1024
|
+
{
|
|
1025
|
+
id: "numeric.special-values",
|
|
1026
|
+
family: "representation"
|
|
1027
|
+
},
|
|
1028
|
+
{
|
|
1029
|
+
id: "numeric.scale-greater-than-precision",
|
|
1030
|
+
family: "representation"
|
|
1031
|
+
},
|
|
1032
|
+
{
|
|
1033
|
+
id: "numeric.negative-scale",
|
|
1034
|
+
family: "representation"
|
|
1035
|
+
},
|
|
1036
|
+
{
|
|
1037
|
+
id: "data.json-parsed",
|
|
1038
|
+
family: "representation"
|
|
1039
|
+
},
|
|
1040
|
+
{
|
|
1041
|
+
id: "data.json-lossless-text",
|
|
1042
|
+
family: "representation"
|
|
1043
|
+
},
|
|
1044
|
+
{
|
|
1045
|
+
id: "data.sql-variant",
|
|
1046
|
+
family: "representation"
|
|
1047
|
+
},
|
|
1048
|
+
{
|
|
1049
|
+
id: "data.oracle-object",
|
|
1050
|
+
family: "representation"
|
|
1051
|
+
},
|
|
1052
|
+
{
|
|
1053
|
+
id: "data.oracle-collection",
|
|
1054
|
+
family: "representation"
|
|
1055
|
+
},
|
|
1056
|
+
{
|
|
1057
|
+
id: "data.vector",
|
|
1058
|
+
family: "representation"
|
|
1059
|
+
},
|
|
1060
|
+
{
|
|
1061
|
+
id: "data.binary",
|
|
1062
|
+
family: "representation"
|
|
1063
|
+
},
|
|
1064
|
+
{
|
|
1065
|
+
id: "data.uuid",
|
|
1066
|
+
family: "representation"
|
|
1067
|
+
},
|
|
1068
|
+
{
|
|
1069
|
+
id: "data.temporal-native",
|
|
1070
|
+
family: "representation"
|
|
1071
|
+
},
|
|
1072
|
+
{
|
|
1073
|
+
id: "data.temporal-lossless",
|
|
1074
|
+
family: "representation"
|
|
1075
|
+
},
|
|
1076
|
+
{
|
|
1077
|
+
id: "data.timezone",
|
|
1078
|
+
family: "representation"
|
|
1079
|
+
},
|
|
1080
|
+
{
|
|
1081
|
+
id: "metadata.command-safe",
|
|
1082
|
+
family: "metadata"
|
|
1083
|
+
},
|
|
1084
|
+
{
|
|
1085
|
+
id: "dml.insert-returning",
|
|
1086
|
+
family: "support"
|
|
1087
|
+
},
|
|
1088
|
+
{
|
|
1089
|
+
id: "dml.update-returning",
|
|
1090
|
+
family: "support"
|
|
1091
|
+
},
|
|
1092
|
+
{
|
|
1093
|
+
id: "dml.delete-returning",
|
|
1094
|
+
family: "support"
|
|
1095
|
+
},
|
|
1096
|
+
{
|
|
1097
|
+
id: "dml.merge-returning",
|
|
1098
|
+
family: "support"
|
|
1099
|
+
},
|
|
1100
|
+
{
|
|
1101
|
+
id: "dml.upsert-returning",
|
|
1102
|
+
family: "support"
|
|
1103
|
+
},
|
|
1104
|
+
{
|
|
1105
|
+
id: "session.pinned",
|
|
1106
|
+
family: "support"
|
|
1107
|
+
},
|
|
1108
|
+
{
|
|
1109
|
+
id: "statement.prepare",
|
|
1110
|
+
family: "support"
|
|
1111
|
+
},
|
|
1112
|
+
{
|
|
1113
|
+
id: "statement.cancel",
|
|
1114
|
+
family: "support"
|
|
1115
|
+
},
|
|
1116
|
+
{
|
|
1117
|
+
id: "statement.stream",
|
|
1118
|
+
family: "support"
|
|
1119
|
+
},
|
|
1120
|
+
{
|
|
1121
|
+
id: "statement.bulk",
|
|
1122
|
+
family: "support"
|
|
1123
|
+
},
|
|
1124
|
+
{
|
|
1125
|
+
id: "execution.bulk-fidelity",
|
|
1126
|
+
family: "support"
|
|
1127
|
+
},
|
|
1128
|
+
{
|
|
1129
|
+
id: "transaction",
|
|
1130
|
+
family: "support"
|
|
1131
|
+
},
|
|
1132
|
+
{
|
|
1133
|
+
id: "transaction.savepoint",
|
|
1134
|
+
family: "support"
|
|
1135
|
+
},
|
|
1136
|
+
{
|
|
1137
|
+
id: "transaction.read-only",
|
|
1138
|
+
family: "support"
|
|
1139
|
+
},
|
|
1140
|
+
{
|
|
1141
|
+
id: "transaction.isolation.read-uncommitted",
|
|
1142
|
+
family: "support"
|
|
1143
|
+
},
|
|
1144
|
+
{
|
|
1145
|
+
id: "transaction.isolation.read-committed",
|
|
1146
|
+
family: "support"
|
|
1147
|
+
},
|
|
1148
|
+
{
|
|
1149
|
+
id: "transaction.isolation.repeatable-read",
|
|
1150
|
+
family: "support"
|
|
1151
|
+
},
|
|
1152
|
+
{
|
|
1153
|
+
id: "transaction.isolation.serializable",
|
|
1154
|
+
family: "support"
|
|
1155
|
+
},
|
|
1156
|
+
{
|
|
1157
|
+
id: "routine.call",
|
|
1158
|
+
family: "support"
|
|
1159
|
+
},
|
|
1160
|
+
{
|
|
1161
|
+
id: "routine.out",
|
|
1162
|
+
family: "support"
|
|
1163
|
+
},
|
|
1164
|
+
{
|
|
1165
|
+
id: "routine.inout",
|
|
1166
|
+
family: "support"
|
|
1167
|
+
},
|
|
1168
|
+
{
|
|
1169
|
+
id: "routine.result-sets",
|
|
1170
|
+
family: "support"
|
|
1171
|
+
},
|
|
1172
|
+
{
|
|
1173
|
+
id: "routine.out-cursor",
|
|
1174
|
+
family: "support"
|
|
1175
|
+
},
|
|
1176
|
+
{
|
|
1177
|
+
id: "routine.return-value",
|
|
1178
|
+
family: "support"
|
|
1179
|
+
},
|
|
1180
|
+
{
|
|
1181
|
+
id: "metadata.identity",
|
|
1182
|
+
family: "metadata"
|
|
1183
|
+
},
|
|
1184
|
+
{
|
|
1185
|
+
id: "metadata.generated",
|
|
1186
|
+
family: "metadata"
|
|
1187
|
+
},
|
|
1188
|
+
{
|
|
1189
|
+
id: "metadata.routines",
|
|
1190
|
+
family: "metadata"
|
|
1191
|
+
},
|
|
1192
|
+
{
|
|
1193
|
+
id: "metadata.types",
|
|
1194
|
+
family: "metadata"
|
|
882
1195
|
}
|
|
883
|
-
|
|
1196
|
+
];
|
|
1197
|
+
const WELL_KNOWN_CAPABILITIES = Object.freeze(definitions.map((entry) => Object.freeze(entry)));
|
|
1198
|
+
const WELL_KNOWN_CAPABILITY_IDS = Object.freeze(definitions.map(({ id }) => id));
|
|
1199
|
+
const wellKnownCapabilityIds = new Set(WELL_KNOWN_CAPABILITY_IDS);
|
|
1200
|
+
function isWellKnownCapabilityId(value) {
|
|
1201
|
+
return wellKnownCapabilityIds.has(value);
|
|
1202
|
+
}
|
|
884
1203
|
|
|
885
1204
|
//#endregion
|
|
886
|
-
export { AUTHORING_MODULE_CATALOG, AdapterError, PUBLIC_ERROR_DEFINITIONS, ResultExactnessError, RoutineMappingError, SQL_FRAGMENT, SqlRenderError, UnsupportedFeatureError, createBoundParameter, createBulkBindingDescription, createParameterTypeHint, createRenderedBulk, createRenderedStatement, createRoutineInOutParameter, createRoutineOutParameter, createStatementBindingDescription, decodeExactDecimal, decodeExactInteger, isBoundParameter, isRoutineParameter, normalizeExactInteger, parameterizedSql, safeDatabaseCount };
|
|
1205
|
+
export { AUTHORING_MODULE_CATALOG, AdapterError, PUBLIC_ERROR_DEFINITIONS, ResultExactnessError, RoutineMappingError, SQL_FRAGMENT, SqlRenderError, UnsupportedFeatureError, WELL_KNOWN_CAPABILITIES, WELL_KNOWN_CAPABILITY_IDS, createBoundParameter, createBulkBindingDescription, createParameterTypeHint, createRenderedBulk, createRenderedStatement, createRoutineInOutParameter, createRoutineOutParameter, createStatementBindingDescription, decodeExactDecimal, decodeExactInteger, isBoundParameter, isPublicUnsupportedFeatureError, isRoutineParameter, isWellKnownCapabilityId, normalizeExactInteger, parameterizedSql, safeDatabaseCount };
|
|
887
1206
|
//# sourceMappingURL=index.js.map
|