@sqlbraid/core 1.0.0-rc.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -111,6 +111,241 @@ const AUTHORING_MODULE_CATALOG = Object.freeze([
111
111
  }
112
112
  ].map((entry) => Object.freeze(entry)));
113
113
 
114
+ //#endregion
115
+ //#region src/capabilities.ts
116
+ const definitions = [
117
+ {
118
+ id: "sql.native-transparency",
119
+ family: "support"
120
+ },
121
+ {
122
+ id: "sql.generated-structure",
123
+ family: "support"
124
+ },
125
+ {
126
+ id: "result.rows",
127
+ family: "support"
128
+ },
129
+ {
130
+ id: "result.command",
131
+ family: "support"
132
+ },
133
+ {
134
+ id: "result.multiple-sets",
135
+ family: "support"
136
+ },
137
+ {
138
+ id: "result.standard-schema",
139
+ family: "support"
140
+ },
141
+ {
142
+ id: "numeric.exact-integer",
143
+ family: "representation"
144
+ },
145
+ {
146
+ id: "numeric.exact-decimal",
147
+ family: "representation"
148
+ },
149
+ {
150
+ id: "numeric.approximate-float",
151
+ family: "representation"
152
+ },
153
+ {
154
+ id: "numeric.approximate-special",
155
+ family: "representation"
156
+ },
157
+ {
158
+ id: "numeric.bind-exact",
159
+ family: "representation"
160
+ },
161
+ {
162
+ id: "numeric.aggregate",
163
+ family: "representation"
164
+ },
165
+ {
166
+ id: "numeric.command-metadata",
167
+ family: "representation"
168
+ },
169
+ {
170
+ id: "numeric.special-values",
171
+ family: "representation"
172
+ },
173
+ {
174
+ id: "numeric.scale-greater-than-precision",
175
+ family: "representation"
176
+ },
177
+ {
178
+ id: "numeric.negative-scale",
179
+ family: "representation"
180
+ },
181
+ {
182
+ id: "data.json-parsed",
183
+ family: "representation"
184
+ },
185
+ {
186
+ id: "data.json-lossless-text",
187
+ family: "representation"
188
+ },
189
+ {
190
+ id: "data.sql-variant",
191
+ family: "representation"
192
+ },
193
+ {
194
+ id: "data.oracle-object",
195
+ family: "representation"
196
+ },
197
+ {
198
+ id: "data.oracle-collection",
199
+ family: "representation"
200
+ },
201
+ {
202
+ id: "data.vector",
203
+ family: "representation"
204
+ },
205
+ {
206
+ id: "data.binary",
207
+ family: "representation"
208
+ },
209
+ {
210
+ id: "data.uuid",
211
+ family: "representation"
212
+ },
213
+ {
214
+ id: "data.temporal-native",
215
+ family: "representation"
216
+ },
217
+ {
218
+ id: "data.temporal-lossless",
219
+ family: "representation"
220
+ },
221
+ {
222
+ id: "data.timezone",
223
+ family: "representation"
224
+ },
225
+ {
226
+ id: "metadata.command-safe",
227
+ family: "metadata"
228
+ },
229
+ {
230
+ id: "dml.insert-returning",
231
+ family: "support"
232
+ },
233
+ {
234
+ id: "dml.update-returning",
235
+ family: "support"
236
+ },
237
+ {
238
+ id: "dml.delete-returning",
239
+ family: "support"
240
+ },
241
+ {
242
+ id: "dml.merge-returning",
243
+ family: "support"
244
+ },
245
+ {
246
+ id: "dml.upsert-returning",
247
+ family: "support"
248
+ },
249
+ {
250
+ id: "session.pinned",
251
+ family: "support"
252
+ },
253
+ {
254
+ id: "statement.prepare",
255
+ family: "support"
256
+ },
257
+ {
258
+ id: "statement.cancel",
259
+ family: "support"
260
+ },
261
+ {
262
+ id: "statement.stream",
263
+ family: "support"
264
+ },
265
+ {
266
+ id: "statement.bulk",
267
+ family: "support"
268
+ },
269
+ {
270
+ id: "execution.bulk-fidelity",
271
+ family: "support"
272
+ },
273
+ {
274
+ id: "transaction",
275
+ family: "support"
276
+ },
277
+ {
278
+ id: "transaction.savepoint",
279
+ family: "support"
280
+ },
281
+ {
282
+ id: "transaction.read-only",
283
+ family: "support"
284
+ },
285
+ {
286
+ id: "transaction.isolation.read-uncommitted",
287
+ family: "support"
288
+ },
289
+ {
290
+ id: "transaction.isolation.read-committed",
291
+ family: "support"
292
+ },
293
+ {
294
+ id: "transaction.isolation.repeatable-read",
295
+ family: "support"
296
+ },
297
+ {
298
+ id: "transaction.isolation.serializable",
299
+ family: "support"
300
+ },
301
+ {
302
+ id: "routine.call",
303
+ family: "support"
304
+ },
305
+ {
306
+ id: "routine.out",
307
+ family: "support"
308
+ },
309
+ {
310
+ id: "routine.inout",
311
+ family: "support"
312
+ },
313
+ {
314
+ id: "routine.result-sets",
315
+ family: "support"
316
+ },
317
+ {
318
+ id: "routine.out-cursor",
319
+ family: "support"
320
+ },
321
+ {
322
+ id: "routine.return-value",
323
+ family: "support"
324
+ },
325
+ {
326
+ id: "metadata.identity",
327
+ family: "metadata"
328
+ },
329
+ {
330
+ id: "metadata.generated",
331
+ family: "metadata"
332
+ },
333
+ {
334
+ id: "metadata.routines",
335
+ family: "metadata"
336
+ },
337
+ {
338
+ id: "metadata.types",
339
+ family: "metadata"
340
+ }
341
+ ];
342
+ const WELL_KNOWN_CAPABILITIES = Object.freeze(definitions.map((entry) => Object.freeze(entry)));
343
+ const WELL_KNOWN_CAPABILITY_IDS = Object.freeze(definitions.map(({ id }) => id));
344
+ const wellKnownCapabilityIds = new Set(WELL_KNOWN_CAPABILITY_IDS);
345
+ function isWellKnownCapabilityId(value) {
346
+ return wellKnownCapabilityIds.has(value);
347
+ }
348
+
114
349
  //#endregion
115
350
  //#region src/index.ts
116
351
  const SQL_FRAGMENT = Symbol.for("sqlbraid.fragment");
@@ -204,32 +439,38 @@ const PUBLIC_ERROR_DEFINITIONS = Object.freeze([
204
439
  {
205
440
  code: "BRAID_CALL_UNSUPPORTED",
206
441
  category: "adapter",
207
- owner: "UnsupportedFeatureError"
442
+ owner: "UnsupportedFeatureError",
443
+ features: ["routine.call"]
208
444
  },
209
445
  {
210
446
  code: "BRAID_RESULT_SETS_UNSUPPORTED",
211
447
  category: "adapter",
212
- owner: "UnsupportedFeatureError"
448
+ owner: "UnsupportedFeatureError",
449
+ features: ["routine.result-sets"]
213
450
  },
214
451
  {
215
452
  code: "BRAID_STREAM_UNSUPPORTED",
216
453
  category: "adapter",
217
- owner: "UnsupportedFeatureError"
454
+ owner: "UnsupportedFeatureError",
455
+ features: ["statement.stream"]
218
456
  },
219
457
  {
220
458
  code: "BRAID_CANCEL_UNSUPPORTED",
221
459
  category: "adapter",
222
- owner: "UnsupportedFeatureError"
460
+ owner: "UnsupportedFeatureError",
461
+ features: ["statement.cancel"]
223
462
  },
224
463
  {
225
464
  code: "BRAID_SESSION_UNSUPPORTED",
226
465
  category: "adapter",
227
- owner: "UnsupportedFeatureError"
466
+ owner: "UnsupportedFeatureError",
467
+ features: ["session.pinned"]
228
468
  },
229
469
  {
230
470
  code: "BRAID_TX_UNSUPPORTED",
231
471
  category: "adapter",
232
- owner: "UnsupportedFeatureError"
472
+ owner: "UnsupportedFeatureError",
473
+ features: ["transaction", "transaction.savepoint"]
233
474
  },
234
475
  {
235
476
  code: "BRAID_TX_OPTIONS_INVALID",
@@ -239,42 +480,56 @@ const PUBLIC_ERROR_DEFINITIONS = Object.freeze([
239
480
  {
240
481
  code: "BRAID_TX_OPTION_UNSUPPORTED",
241
482
  category: "adapter",
242
- owner: "UnsupportedFeatureError"
483
+ owner: "UnsupportedFeatureError",
484
+ features: [
485
+ "transaction.read-only",
486
+ "transaction.isolation.read-uncommitted",
487
+ "transaction.isolation.read-committed",
488
+ "transaction.isolation.repeatable-read",
489
+ "transaction.isolation.serializable"
490
+ ]
243
491
  },
244
492
  {
245
493
  code: "BRAID_CALL_RESULT_SETS",
246
494
  category: "adapter",
247
- owner: "UnsupportedFeatureError"
495
+ owner: "UnsupportedFeatureError",
496
+ features: ["routine.result-sets"]
248
497
  },
249
498
  {
250
499
  code: "BRAID_CALL_CURSOR_TX_REQUIRED",
251
500
  category: "adapter",
252
- owner: "UnsupportedFeatureError"
501
+ owner: "UnsupportedFeatureError",
502
+ features: ["routine.out-cursor"]
253
503
  },
254
504
  {
255
505
  code: "BRAID_CALL_OUT_UNSUPPORTED",
256
506
  category: "adapter",
257
- owner: "UnsupportedFeatureError"
507
+ owner: "UnsupportedFeatureError",
508
+ features: ["routine.out", "routine.inout"]
258
509
  },
259
510
  {
260
511
  code: "BRAID_CALL_RETURN_UNSUPPORTED",
261
512
  category: "adapter",
262
- owner: "UnsupportedFeatureError"
513
+ owner: "UnsupportedFeatureError",
514
+ features: ["routine.call", "routine.return-value"]
263
515
  },
264
516
  {
265
517
  code: "BRAID_CALL_CURSOR_UNSUPPORTED",
266
518
  category: "adapter",
267
- owner: "UnsupportedFeatureError"
519
+ owner: "UnsupportedFeatureError",
520
+ features: ["routine.out-cursor"]
268
521
  },
269
522
  {
270
523
  code: "BRAID_RESOURCE_CLEANUP",
271
524
  category: "adapter",
272
- owner: "adapter cleanup error with code"
525
+ owner: "adapter cleanup error with code",
526
+ features: ["resource.cleanup", "resource.discard"]
273
527
  },
274
528
  {
275
529
  code: "BRAID_BIND_HINT_UNSUPPORTED",
276
530
  category: "adapter",
277
- owner: "UnsupportedFeatureError"
531
+ owner: "UnsupportedFeatureError",
532
+ features: ["statement.bind-hint"]
278
533
  },
279
534
  {
280
535
  code: "BRAID_BIND_VALUE_UNSUPPORTED",
@@ -284,27 +539,38 @@ const PUBLIC_ERROR_DEFINITIONS = Object.freeze([
284
539
  {
285
540
  code: "BRAID_INTEGER_MODE_UNSUPPORTED",
286
541
  category: "adapter",
287
- owner: "UnsupportedFeatureError"
542
+ owner: "UnsupportedFeatureError",
543
+ features: ["result.exact-integer"]
288
544
  },
289
545
  {
290
546
  code: "BRAID_CALL_LOB_UNSUPPORTED",
291
547
  category: "adapter",
292
- owner: "UnsupportedFeatureError"
548
+ owner: "UnsupportedFeatureError",
549
+ features: ["routine.out"]
293
550
  },
294
551
  {
295
552
  code: "BRAID_BULK_UNSUPPORTED",
296
553
  category: "adapter",
297
- owner: "UnsupportedFeatureError"
554
+ owner: "UnsupportedFeatureError",
555
+ features: ["statement.bulk"]
556
+ },
557
+ {
558
+ code: "BRAID_PREPARE_UNSUPPORTED",
559
+ category: "adapter",
560
+ owner: "UnsupportedFeatureError",
561
+ features: ["statement.prepare"]
298
562
  },
299
563
  {
300
564
  code: "BRAID_DIALECT_MISMATCH",
301
565
  category: "adapter",
302
- owner: "UnsupportedFeatureError"
566
+ owner: "UnsupportedFeatureError",
567
+ features: ["dialect"]
303
568
  },
304
569
  {
305
570
  code: "BRAID_RESULT_KIND_AMBIGUOUS",
306
571
  category: "adapter",
307
- owner: "UnsupportedFeatureError"
572
+ owner: "UnsupportedFeatureError",
573
+ features: ["result.rows", "result.command"]
308
574
  },
309
575
  {
310
576
  code: "BRAID_PREPARED_NAME",
@@ -643,7 +909,10 @@ function genericLiteral(parameter, dialectId, binary) {
643
909
  const value = parameter.value;
644
910
  if (value === null) return "NULL";
645
911
  if (value === void 0) return "[undefined]";
646
- if (typeof value === "string") return `'${value.replaceAll("'", "''")}'`;
912
+ if (typeof value === "string") {
913
+ if (/^(?:mysql|mariadb)/i.test(dialectId)) return `[string ${JSON.stringify(value)}]`;
914
+ return `'${value.replaceAll("'", "''")}'`;
915
+ }
647
916
  if (typeof value === "boolean") {
648
917
  if (/^(?:mysql|sqlite)/i.test(dialectId) || /^(?:oracle|mssql|sqlserver)/i.test(dialectId)) return value ? "1" : "0";
649
918
  if (/^(?:postgres|postgresql|cockroach|redshift)/i.test(dialectId)) return value ? "TRUE" : "FALSE";
@@ -855,6 +1124,11 @@ var UnsupportedFeatureError = class extends Error {
855
1124
  this.name = "UnsupportedFeatureError";
856
1125
  }
857
1126
  };
1127
+ /** Return true only for a registered, semantically valid feature/code pair. */
1128
+ function isPublicUnsupportedFeatureError(error) {
1129
+ if (!(error instanceof UnsupportedFeatureError)) return false;
1130
+ return PUBLIC_ERROR_DEFINITIONS.find((candidate) => candidate.owner === "UnsupportedFeatureError" && candidate.code === error.code)?.features?.includes(error.feature) === true;
1131
+ }
858
1132
  /** An adapter-owned input/transport failure that retains TypeError semantics. */
859
1133
  var AdapterError = class extends TypeError {
860
1134
  constructor(code, message, options) {
@@ -883,5 +1157,5 @@ var SqlRenderError = class extends Error {
883
1157
  };
884
1158
 
885
1159
  //#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 };
1160
+ 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
1161
  //# sourceMappingURL=index.js.map