@databricks/sql 1.15.0 → 1.16.0-rc.1

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 (119) hide show
  1. package/dist/DBSQLClient.d.ts +3 -0
  2. package/dist/DBSQLClient.js +97 -56
  3. package/dist/DBSQLClient.js.map +1 -1
  4. package/dist/DBSQLLogger.d.ts +3 -0
  5. package/dist/DBSQLLogger.js +25 -0
  6. package/dist/DBSQLLogger.js.map +1 -1
  7. package/dist/DBSQLOperation.d.ts +36 -17
  8. package/dist/DBSQLOperation.js +133 -214
  9. package/dist/DBSQLOperation.js.map +1 -1
  10. package/dist/DBSQLParameter.d.ts +2 -0
  11. package/dist/DBSQLParameter.js +63 -7
  12. package/dist/DBSQLParameter.js.map +1 -1
  13. package/dist/DBSQLSession.d.ts +24 -17
  14. package/dist/DBSQLSession.js +45 -263
  15. package/dist/DBSQLSession.js.map +1 -1
  16. package/dist/connection/connections/HttpRetryPolicy.d.ts +3 -0
  17. package/dist/connection/connections/HttpRetryPolicy.js +116 -21
  18. package/dist/connection/connections/HttpRetryPolicy.js.map +1 -1
  19. package/dist/connection/connections/ThriftHttpConnection.js +18 -3
  20. package/dist/connection/connections/ThriftHttpConnection.js.map +1 -1
  21. package/dist/contracts/IBackend.d.ts +31 -0
  22. package/dist/contracts/IBackend.js +3 -0
  23. package/dist/contracts/IBackend.js.map +1 -0
  24. package/dist/contracts/IClientContext.d.ts +1 -0
  25. package/dist/contracts/IDBSQLClient.d.ts +31 -0
  26. package/dist/contracts/IDBSQLLogger.d.ts +17 -0
  27. package/dist/contracts/IDBSQLLogger.js.map +1 -1
  28. package/dist/contracts/IDBSQLSession.d.ts +24 -1
  29. package/dist/contracts/IOperation.d.ts +10 -1
  30. package/dist/contracts/IOperationBackend.d.ts +98 -0
  31. package/dist/contracts/IOperationBackend.js +3 -0
  32. package/dist/contracts/IOperationBackend.js.map +1 -0
  33. package/dist/contracts/ISessionBackend.d.ts +36 -0
  34. package/dist/contracts/ISessionBackend.js +3 -0
  35. package/dist/contracts/ISessionBackend.js.map +1 -0
  36. package/dist/contracts/InternalConnectionOptions.d.ts +72 -0
  37. package/dist/contracts/InternalConnectionOptions.js +3 -0
  38. package/dist/contracts/InternalConnectionOptions.js.map +1 -0
  39. package/dist/contracts/OperationStatus.d.ts +76 -0
  40. package/dist/contracts/OperationStatus.js +28 -0
  41. package/dist/contracts/OperationStatus.js.map +1 -0
  42. package/dist/contracts/ResultMetadata.d.ts +34 -0
  43. package/dist/contracts/ResultMetadata.js +16 -0
  44. package/dist/contracts/ResultMetadata.js.map +1 -0
  45. package/dist/errors/AuthenticationError.d.ts +1 -0
  46. package/dist/errors/AuthenticationError.js +4 -0
  47. package/dist/errors/AuthenticationError.js.map +1 -1
  48. package/dist/kernel/KernelArrowIpc.d.ts +54 -0
  49. package/dist/kernel/KernelArrowIpc.js +292 -0
  50. package/dist/kernel/KernelArrowIpc.js.map +1 -0
  51. package/dist/kernel/KernelArrowIpcDurationFix.d.ts +29 -0
  52. package/dist/kernel/KernelArrowIpcDurationFix.js +605 -0
  53. package/dist/kernel/KernelArrowIpcDurationFix.js.map +1 -0
  54. package/dist/kernel/KernelAuth.d.ts +300 -0
  55. package/dist/kernel/KernelAuth.js +463 -0
  56. package/dist/kernel/KernelAuth.js.map +1 -0
  57. package/dist/kernel/KernelBackend.d.ts +53 -0
  58. package/dist/kernel/KernelBackend.js +164 -0
  59. package/dist/kernel/KernelBackend.js.map +1 -0
  60. package/dist/kernel/KernelErrorMapping.d.ts +109 -0
  61. package/dist/kernel/KernelErrorMapping.js +249 -0
  62. package/dist/kernel/KernelErrorMapping.js.map +1 -0
  63. package/dist/kernel/KernelInputValidation.d.ts +16 -0
  64. package/dist/kernel/KernelInputValidation.js +49 -0
  65. package/dist/kernel/KernelInputValidation.js.map +1 -0
  66. package/dist/kernel/KernelLogging.d.ts +63 -0
  67. package/dist/kernel/KernelLogging.js +128 -0
  68. package/dist/kernel/KernelLogging.js.map +1 -0
  69. package/dist/kernel/KernelNativeLoader.d.ts +77 -0
  70. package/dist/kernel/KernelNativeLoader.js +178 -0
  71. package/dist/kernel/KernelNativeLoader.js.map +1 -0
  72. package/dist/kernel/KernelOperationBackend.d.ts +154 -0
  73. package/dist/kernel/KernelOperationBackend.js +640 -0
  74. package/dist/kernel/KernelOperationBackend.js.map +1 -0
  75. package/dist/kernel/KernelOperationLifecycle.d.ts +130 -0
  76. package/dist/kernel/KernelOperationLifecycle.js +245 -0
  77. package/dist/kernel/KernelOperationLifecycle.js.map +1 -0
  78. package/dist/kernel/KernelPositionalParams.d.ts +16 -0
  79. package/dist/kernel/KernelPositionalParams.js +120 -0
  80. package/dist/kernel/KernelPositionalParams.js.map +1 -0
  81. package/dist/kernel/KernelResultsProvider.d.ts +44 -0
  82. package/dist/kernel/KernelResultsProvider.js +102 -0
  83. package/dist/kernel/KernelResultsProvider.js.map +1 -0
  84. package/dist/kernel/KernelServerInfo.d.ts +44 -0
  85. package/dist/kernel/KernelServerInfo.js +73 -0
  86. package/dist/kernel/KernelServerInfo.js.map +1 -0
  87. package/dist/kernel/KernelSessionBackend.d.ts +100 -0
  88. package/dist/kernel/KernelSessionBackend.js +384 -0
  89. package/dist/kernel/KernelSessionBackend.js.map +1 -0
  90. package/dist/result/ArrowResultConverter.d.ts +31 -2
  91. package/dist/result/ArrowResultConverter.js +226 -14
  92. package/dist/result/ArrowResultConverter.js.map +1 -1
  93. package/dist/result/CloudFetchResultHandler.js +36 -8
  94. package/dist/result/CloudFetchResultHandler.js.map +1 -1
  95. package/dist/telemetry/DatabricksTelemetryExporter.js +34 -1
  96. package/dist/telemetry/DatabricksTelemetryExporter.js.map +1 -1
  97. package/dist/telemetry/telemetryTypeMappers.d.ts +1 -1
  98. package/dist/telemetry/telemetryTypeMappers.js +1 -1
  99. package/dist/telemetry/telemetryTypeMappers.js.map +1 -1
  100. package/dist/telemetry/types.d.ts +15 -0
  101. package/dist/thrift-backend/ThriftBackend.d.ts +17 -0
  102. package/dist/thrift-backend/ThriftBackend.js +80 -0
  103. package/dist/thrift-backend/ThriftBackend.js.map +1 -0
  104. package/dist/thrift-backend/ThriftOperationBackend.d.ts +70 -0
  105. package/dist/thrift-backend/ThriftOperationBackend.js +330 -0
  106. package/dist/thrift-backend/ThriftOperationBackend.js.map +1 -0
  107. package/dist/thrift-backend/ThriftSessionBackend.d.ts +36 -0
  108. package/dist/thrift-backend/ThriftSessionBackend.js +266 -0
  109. package/dist/thrift-backend/ThriftSessionBackend.js.map +1 -0
  110. package/dist/thrift-backend/wireSynthesis.d.ts +30 -0
  111. package/dist/thrift-backend/wireSynthesis.js +128 -0
  112. package/dist/thrift-backend/wireSynthesis.js.map +1 -0
  113. package/dist/version.d.ts +1 -1
  114. package/dist/version.js +1 -1
  115. package/dist/version.js.map +1 -1
  116. package/native/kernel/README.md +97 -0
  117. package/native/kernel/index.d.ts +1069 -0
  118. package/native/kernel/index.js +325 -0
  119. package/package.json +13 -2
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ // Copyright (c) 2026 Databricks, Inc.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ var __importDefault = (this && this.__importDefault) || function (mod) {
16
+ return (mod && mod.__esModule) ? mod : { "default": mod };
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ const IDBSQLLogger_1 = require("../contracts/IDBSQLLogger");
20
+ const HiveDriverError_1 = __importDefault(require("../errors/HiveDriverError"));
21
+ const utils_1 = require("../utils");
22
+ const KernelNativeLoader_1 = require("./KernelNativeLoader");
23
+ const KernelErrorMapping_1 = require("./KernelErrorMapping");
24
+ const KernelAuth_1 = require("./KernelAuth");
25
+ const KernelLogging_1 = require("./KernelLogging");
26
+ const KernelSessionBackend_1 = __importDefault(require("./KernelSessionBackend"));
27
+ /**
28
+ * kernel-backed implementation of `IBackend`.
29
+ *
30
+ * **M0 dispatch model:** the napi binding's `openSession()` already
31
+ * builds a kernel `Session` from PAT + hostname + httpPath, so there is
32
+ * no "connect" round-trip before `openSession` — `connect()` only
33
+ * captures the `ConnectionOptions` and validates that PAT auth is in
34
+ * use. The actual session open happens inside `openSession()`.
35
+ *
36
+ * **Auth validation:** delegates to `buildKernelConnectionOptions` from
37
+ * `KernelAuth`, which mirrors the existing DBSQLClient validation pattern
38
+ * (slash-prepended httpPath, AuthenticationError on missing token or
39
+ * blank OAuth credentials, HiveDriverError on unsupported authType /
40
+ * Azure-direct / ambiguous credential combinations). M2M and U2M
41
+ * routing key off `oauthClientId` presence; see KernelAuth.ts.
42
+ *
43
+ * **Why we don't use IClientContext's connectionProvider here:** that
44
+ * provider is the Thrift HTTP transport. The kernel owns its own
45
+ * reqwest+rustls stack inside the native binding, so there is no
46
+ * NodeJS-level connection state to manage on the kernel path. The
47
+ * `IClientContext` is still useful for logger + config access.
48
+ */
49
+ class KernelBackend {
50
+ constructor(options) {
51
+ var _a;
52
+ // Drops the kernel-log level-change listener on close. No-op until connect()
53
+ // installs the bridge (and a no-op closure if the logger/binding can't
54
+ // retarget at runtime).
55
+ this.kernelLogUnsubscribe = () => { };
56
+ this.context = options.context;
57
+ this.binding = (_a = options.nativeBinding) !== null && _a !== void 0 ? _a : (0, KernelNativeLoader_1.getKernelNative)();
58
+ }
59
+ async connect(options) {
60
+ var _a, _b;
61
+ // Validate PAT auth + capture the napi-binding option shape.
62
+ // Any non-PAT mode (or a missing/empty token) throws here, before
63
+ // we ever touch the native binding.
64
+ // Forward the driver's retry config to the kernel, which owns the retry
65
+ // loop on the kernel path. This keeps kernel and Thrift governed by one retry
66
+ // config (the same `ClientConfig` knobs the Thrift `HttpRetryPolicy` reads),
67
+ // converted from the connector's milliseconds to the kernel's whole seconds.
68
+ this.nativeOptions = {
69
+ ...(0, KernelAuth_1.buildKernelConnectionOptions)(options),
70
+ ...(0, KernelAuth_1.buildKernelRetryOptions)(this.context.getConfig()),
71
+ };
72
+ // Bridge the Rust kernel's `tracing` logs into the SAME `DBSQLLogger` the
73
+ // driver logs through, so logs from all three layers (driver, napi shim,
74
+ // kernel) land in one place — and one file when the logger has a file
75
+ // transport. Kernel verbosity follows the logger's own level; loggers that
76
+ // don't expose `getLevel()` leave the bridge at `info`. No-op on a binding
77
+ // that predates the bridge (logging is advisory).
78
+ const logger = this.context.getLogger();
79
+ const kernelLogLevel = (_b = (_a = logger.getLevel) === null || _a === void 0 ? void 0 : _a.call(logger)) !== null && _b !== void 0 ? _b : IDBSQLLogger_1.LogLevel.info;
80
+ this.kernelLogUnsubscribe = (0, KernelLogging_1.installKernelLogBridge)(this.binding, logger, kernelLogLevel);
81
+ // Warn on the insecure combo: a `customCaCert` paired with
82
+ // `checkServerCertificate: false` is almost always a mistake — verification
83
+ // is fully off, so the custom trust anchor is never used. The combo is
84
+ // still honoured (kernel contract), but a secure-looking `customCaCert`
85
+ // shouldn't silently mask disabled verification.
86
+ const tlsOpts = options;
87
+ if (tlsOpts.checkServerCertificate === false && tlsOpts.customCaCert !== undefined) {
88
+ this.context
89
+ .getLogger()
90
+ .log(IDBSQLLogger_1.LogLevel.warn, 'kernel: `customCaCert` is set but `checkServerCertificate: false` disables certificate ' +
91
+ 'verification entirely — the custom CA is not used. Set `checkServerCertificate: true` to use it.');
92
+ }
93
+ }
94
+ async openSession(request) {
95
+ var _a;
96
+ if (!this.nativeOptions) {
97
+ throw new HiveDriverError_1.default('KernelBackend: not connected. Call connect() first.');
98
+ }
99
+ // Fold session-level defaults from the OpenSessionRequest into the
100
+ // napi `ConnectionOptions`. The kernel routes these through
101
+ // `Session::builder().defaults(DefaultOpts)` + `.session_conf(...)`
102
+ // so they land on the SEA `CreateSession` wire fields, not on each
103
+ // per-statement request. Matches pyo3's `Session.__new__` shape.
104
+ //
105
+ // Only set the optional keys when present so the napi call shape
106
+ // stays minimal — keeps wire snapshots / test assertions stable
107
+ // for callers who pass no defaults.
108
+ const sessionOptions = { ...this.nativeOptions };
109
+ if (request.initialCatalog !== undefined) {
110
+ sessionOptions.catalog = request.initialCatalog;
111
+ }
112
+ if (request.initialSchema !== undefined) {
113
+ sessionOptions.schema = request.initialSchema;
114
+ }
115
+ if (request.configuration !== undefined) {
116
+ sessionOptions.sessionConf = { ...request.configuration };
117
+ }
118
+ // Session-level query tags: serialize into the reserved `QUERY_TAGS`
119
+ // session conf. The kernel allowlists `QUERY_TAGS` (SESSION_CONF_ALLOWLIST)
120
+ // and forwards it onto the SEA `CreateSession` `session_confs`, mirroring
121
+ // the Thrift backend's `ThriftBackend.openSession`. Runs after the
122
+ // `configuration` merge so `queryTags` takes precedence over an explicit
123
+ // `configuration.QUERY_TAGS`, matching the documented contract.
124
+ if (request.queryTags !== undefined) {
125
+ const serialized = (0, utils_1.serializeQueryTags)(request.queryTags);
126
+ if (serialized) {
127
+ sessionOptions.sessionConf = { ...((_a = sessionOptions.sessionConf) !== null && _a !== void 0 ? _a : {}), QUERY_TAGS: serialized };
128
+ }
129
+ else if (sessionOptions.sessionConf) {
130
+ delete sessionOptions.sessionConf.QUERY_TAGS;
131
+ }
132
+ }
133
+ let nativeConnection;
134
+ try {
135
+ // `KernelNativeConnectionOptions.authMode` is a string-literal union
136
+ // ('Pat' | 'OAuthM2m' | 'OAuthU2m') — deliberately not the binding's
137
+ // `const enum AuthMode` (see KernelAuth's note on why a const-enum import
138
+ // is avoided). The literal values are byte-identical to the enum's, so
139
+ // the only divergence is TS's const-enum strictness; cast to the
140
+ // binding's parameter type at this single boundary.
141
+ nativeConnection = (await this.binding.openSession(sessionOptions));
142
+ }
143
+ catch (err) {
144
+ throw (0, KernelErrorMapping_1.decodeNapiKernelError)(err);
145
+ }
146
+ return new KernelSessionBackend_1.default({
147
+ connection: nativeConnection,
148
+ context: this.context,
149
+ id: nativeConnection.sessionId,
150
+ });
151
+ }
152
+ async close() {
153
+ // No backend-level resources to release — each `KernelSessionBackend`
154
+ // owns its own napi `Connection` lifecycle.
155
+ this.nativeOptions = undefined;
156
+ // Stop retargeting the (process-global) kernel log level from this backend's
157
+ // logger; the kernel sink itself is process-global and is replaced by the
158
+ // next connect, matching the bridge's last-writer-wins model.
159
+ this.kernelLogUnsubscribe();
160
+ this.kernelLogUnsubscribe = () => { };
161
+ }
162
+ }
163
+ exports.default = KernelBackend;
164
+ //# sourceMappingURL=KernelBackend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KernelBackend.js","sourceRoot":"","sources":["../../lib/kernel/KernelBackend.ts"],"names":[],"mappings":";AAAA,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;;;;AAOjC,4DAAqD;AACrD,gFAAwD;AACxD,oCAA8C;AAC9C,6DAA8F;AAC9F,6DAA6D;AAC7D,6CAAoH;AACpH,mDAAyD;AACzD,kFAA0D;AAmB1D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAqB,aAAa;IAYhC,YAAY,OAA6B;;QALzC,6EAA6E;QAC7E,uEAAuE;QACvE,wBAAwB;QAChB,yBAAoB,GAAe,GAAG,EAAE,GAAE,CAAC,CAAC;QAGlD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,MAAA,OAAO,CAAC,aAAa,mCAAI,IAAA,oCAAe,GAAE,CAAC;IAC5D,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,OAA0B;;QAC7C,6DAA6D;QAC7D,kEAAkE;QAClE,oCAAoC;QACpC,w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AAE,EAAE,gBAAiB,CAAC,SAAS;SAChC,CAAC,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,KAAK;QAChB,sEAAsE;QACtE,4CAA4C;QAC5C,IAAI,CAAC,aAAa,GAAG,SAAS,CAAC;QAE/B,6EAA6E;QAC7E,0EAA0E;QAC1E,8DAA8D;QAC9D,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5B,IAAI,CAAC,oBAAoB,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;IACvC,CAAC;CACF;AAjID,gCAiIC"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Shape of the kernel error surfaced by the napi-binding's `napi_err_from_kernel`.
3
+ *
4
+ * The Rust kernel's `kernel_error::Error` is exposed as a `JsError` whose
5
+ * properties mirror the Rust struct: the `ErrorCode` variant name (as a string),
6
+ * the message, and an optional SQLSTATE (either taken from the structured
7
+ * server response or recovered via `extract_sqlstate_from_message`).
8
+ */
9
+ export interface KernelErrorShape {
10
+ /** Kernel `ErrorCode` variant name, e.g. `"Unauthenticated"`, `"SqlError"`. */
11
+ code: string;
12
+ /** Human-readable error message. */
13
+ message: string;
14
+ /** Optional SQLSTATE — five-char alphanumeric, when the kernel was able to surface it. */
15
+ sqlstate?: string;
16
+ }
17
+ /**
18
+ * Kernel `ErrorCode` variants — the 13 variants of the `#[non_exhaustive]` enum
19
+ * defined in `src/kernel_error.rs:66-134`.
20
+ *
21
+ * Kept here as a literal type rather than an `enum` so test exhaustiveness checks
22
+ * and runtime `code` strings are guaranteed to stay in lockstep with the kernel.
23
+ */
24
+ export type KernelErrorCode = 'InvalidArgument' | 'Unauthenticated' | 'PermissionDenied' | 'NotFound' | 'ResourceExhausted' | 'Unavailable' | 'Timeout' | 'Cancelled' | 'DataLoss' | 'Internal' | 'InvalidStatementHandle' | 'NetworkError' | 'SqlError';
25
+ /**
26
+ * Optional metadata fields the kernel may attach via the
27
+ * `__databricks_error__:` envelope (per `native/kernel/src/error.rs:50-89`).
28
+ *
29
+ * `errorCode` is namespaced under `kernelMetadata` rather than placed at
30
+ * the top level because `OperationStateError` already declares a top-level
31
+ * `errorCode: enum` field, and `DBSQLOperation.ts` switches on it
32
+ * (`err.errorCode === OperationStateErrorCode.Canceled`, around `:374`). Top-level
33
+ * defineProperty would clobber that enum with a kernel string and break
34
+ * cancel/close detection.
35
+ */
36
+ export interface KernelMetadata {
37
+ errorCode?: string;
38
+ vendorCode?: number;
39
+ httpStatus?: number;
40
+ retryable?: boolean;
41
+ queryId?: string;
42
+ /**
43
+ * Rich server-error diagnostics from the kernel terminal-error payload. These
44
+ * mirror the fields the **Thrift** backend already surfaces via
45
+ * `OperationStateError.response` (`TGetOperationStatusResp.displayMessage` /
46
+ * `.errorMessage` / `.errorDetailsJson`) and that the Python `use_kernel`
47
+ * connector forwards onto its exceptions — so kernel stays at parity rather
48
+ * than dropping them. Kernel sources: `Error.display_message` /
49
+ * `.diagnostic_info` / `.error_details_json`.
50
+ */
51
+ displayMessage?: string;
52
+ diagnosticInfo?: string;
53
+ errorDetailsJson?: string;
54
+ }
55
+ /**
56
+ * An `Error` carrying optional kernel-side kernel context. `sqlState` is
57
+ * exposed at the top level (no collision in the existing driver error
58
+ * tree); the remaining envelope fields live under a `kernelMetadata`
59
+ * namespace to avoid clobbering pre-existing `errorCode` semantics on
60
+ * `OperationStateError`.
61
+ */
62
+ export interface ErrorWithSqlState extends Error {
63
+ sqlState?: string;
64
+ kernelMetadata?: KernelMetadata;
65
+ }
66
+ /**
67
+ * Map a kernel error (as surfaced by the napi-binding) to the appropriate JS
68
+ * driver error class.
69
+ *
70
+ * M0 mapping table:
71
+ * Unauthenticated, PermissionDenied → AuthenticationError
72
+ * Cancelled → OperationStateError(Canceled)
73
+ * Timeout → OperationStateError(Timeout)
74
+ * InvalidArgument → ParameterError
75
+ * NetworkError, Unavailable,
76
+ * NotFound, ResourceExhausted,
77
+ * DataLoss, Internal,
78
+ * InvalidStatementHandle, SqlError → HiveDriverError
79
+ *
80
+ * Unknown `code` values (e.g. if the kernel adds a new variant) fall through
81
+ * to HiveDriverError so the driver never silently drops an error. The kernel's
82
+ * `ErrorCode` is `#[non_exhaustive]` so this can legitimately happen.
83
+ *
84
+ * SQLSTATE, when present, is attached on `error.sqlState` regardless of which
85
+ * class is returned.
86
+ */
87
+ export declare function mapKernelErrorToJsError(kErr: KernelErrorShape): ErrorWithSqlState;
88
+ /**
89
+ * Decode a napi-binding error into the typed JS error class.
90
+ *
91
+ * Two paths:
92
+ * - Structured kernel error: `Error.message` starts with
93
+ * {@link ERROR_SENTINEL} followed by a JSON envelope. We strip the
94
+ * sentinel, parse the JSON, route the {@link KernelErrorShape}
95
+ * through {@link mapKernelErrorToJsError}, and attach the remaining
96
+ * envelope fields under a single non-enumerable `kernelMetadata`
97
+ * namespace. Namespacing avoids the collision with
98
+ * `OperationStateError.errorCode` (an enum already switched on at the
99
+ * JS layer — see `DBSQLOperation.ts` around `:374`).
100
+ * - Binding-side error (e.g. `napi::Error::new(InvalidArg, "openSession:
101
+ * \`token\` is required for the requested auth mode")` produced by
102
+ * the binding's own validation): returned unchanged. These don't
103
+ * carry kernel `code` info, so we surface them as-is.
104
+ *
105
+ * Non-`Error` values (e.g. a `Promise.reject('string')`) pass through
106
+ * wrapped in `HiveDriverError` so callers always see an `Error`
107
+ * subclass.
108
+ */
109
+ export declare function decodeNapiKernelError(err: unknown): Error;
@@ -0,0 +1,249 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.decodeNapiKernelError = exports.mapKernelErrorToJsError = void 0;
30
+ const HiveDriverError_1 = __importDefault(require("../errors/HiveDriverError"));
31
+ const AuthenticationError_1 = __importDefault(require("../errors/AuthenticationError"));
32
+ const OperationStateError_1 = __importStar(require("../errors/OperationStateError"));
33
+ const ParameterError_1 = __importDefault(require("../errors/ParameterError"));
34
+ /**
35
+ * Sentinel prefix the napi binding's `napi_err_from_kernel` puts on
36
+ * `Error.message` when the underlying failure was a structured kernel
37
+ * `Error` rather than a plain napi `InvalidArg` from binding-side
38
+ * validation. Defined here (and in `native/kernel/src/error.rs:44`) — the
39
+ * two MUST stay in lockstep.
40
+ */
41
+ const ERROR_SENTINEL = '__databricks_error__:';
42
+ /**
43
+ * Attach a non-enumerable own-property to the error. The shape matches
44
+ * Node's convention for attaching `.code` to system errors:
45
+ * non-enumerable (clean `JSON.stringify`) but readable via direct
46
+ * property access and `Object.getOwnPropertyDescriptor`. One helper for
47
+ * both the top-level `sqlState` and the namespaced `kernelMetadata`
48
+ * object so the `defineProperty` flags live in exactly one place.
49
+ */
50
+ function defineErrorMetadata(error, key, value) {
51
+ Object.defineProperty(error, key, {
52
+ value,
53
+ writable: true,
54
+ enumerable: false,
55
+ configurable: true,
56
+ });
57
+ }
58
+ /**
59
+ * Map a kernel error (as surfaced by the napi-binding) to the appropriate JS
60
+ * driver error class.
61
+ *
62
+ * M0 mapping table:
63
+ * Unauthenticated, PermissionDenied → AuthenticationError
64
+ * Cancelled → OperationStateError(Canceled)
65
+ * Timeout → OperationStateError(Timeout)
66
+ * InvalidArgument → ParameterError
67
+ * NetworkError, Unavailable,
68
+ * NotFound, ResourceExhausted,
69
+ * DataLoss, Internal,
70
+ * InvalidStatementHandle, SqlError → HiveDriverError
71
+ *
72
+ * Unknown `code` values (e.g. if the kernel adds a new variant) fall through
73
+ * to HiveDriverError so the driver never silently drops an error. The kernel's
74
+ * `ErrorCode` is `#[non_exhaustive]` so this can legitimately happen.
75
+ *
76
+ * SQLSTATE, when present, is attached on `error.sqlState` regardless of which
77
+ * class is returned.
78
+ */
79
+ function mapKernelErrorToJsError(kErr) {
80
+ const { code, message, sqlstate } = kErr;
81
+ let error;
82
+ switch (code) {
83
+ case 'Unauthenticated':
84
+ case 'PermissionDenied':
85
+ error = new AuthenticationError_1.default(message);
86
+ break;
87
+ case 'Cancelled':
88
+ // OperationStateError with the Canceled code carries the kernel message
89
+ // through the response.displayMessage fallback path.
90
+ error = new OperationStateError_1.default(OperationStateError_1.OperationStateErrorCode.Canceled);
91
+ error.message = message;
92
+ break;
93
+ case 'Timeout':
94
+ error = new OperationStateError_1.default(OperationStateError_1.OperationStateErrorCode.Timeout);
95
+ error.message = message;
96
+ break;
97
+ case 'InvalidArgument':
98
+ error = new ParameterError_1.default(message);
99
+ break;
100
+ case 'SqlError': {
101
+ // A server-reported SQL execution failure (kernel `SqlError`, e.g. a
102
+ // bad query, missing table, divide-by-zero, invalid cast). The Thrift
103
+ // backend surfaces the same situation as `OperationStateError(Error)`
104
+ // when the operation reaches ERROR_STATE (see DBSQLOperation), so map
105
+ // SqlError to the same class for backend parity. OperationStateError
106
+ // extends HiveDriverError, so existing `instanceof HiveDriverError`
107
+ // catches are unaffected.
108
+ const stateError = new OperationStateError_1.default(OperationStateError_1.OperationStateErrorCode.Error);
109
+ stateError.message = message;
110
+ error = stateError;
111
+ break;
112
+ }
113
+ // All remaining kernel ErrorCode variants map to the base driver error class.
114
+ // M0 intentionally does not introduce new error classes; M1 may add nuance.
115
+ case 'NotFound':
116
+ case 'ResourceExhausted':
117
+ case 'Unavailable':
118
+ case 'DataLoss':
119
+ case 'Internal':
120
+ case 'InvalidStatementHandle':
121
+ case 'NetworkError':
122
+ error = new HiveDriverError_1.default(message);
123
+ break;
124
+ default:
125
+ // Unknown/future kernel variant — never drop the error, surface as base class.
126
+ error = new HiveDriverError_1.default(message);
127
+ break;
128
+ }
129
+ if (sqlstate !== undefined) {
130
+ defineErrorMetadata(error, 'sqlState', sqlstate);
131
+ }
132
+ return error;
133
+ }
134
+ exports.mapKernelErrorToJsError = mapKernelErrorToJsError;
135
+ /**
136
+ * Build a {@link KernelMetadata} object from a parsed envelope, applying
137
+ * per-field type validation. A kernel-side bug that emits, say,
138
+ * `retryable: "true"` (string) instead of `true` (boolean) would
139
+ * otherwise leak the wrong-typed value through to JS callers; the
140
+ * type-guard discards the malformed field rather than passing it through.
141
+ */
142
+ function buildKernelMetadata(parsed) {
143
+ const meta = {};
144
+ if (typeof parsed.errorCode === 'string') {
145
+ meta.errorCode = parsed.errorCode;
146
+ }
147
+ if (typeof parsed.vendorCode === 'number') {
148
+ meta.vendorCode = parsed.vendorCode;
149
+ }
150
+ if (typeof parsed.httpStatus === 'number') {
151
+ meta.httpStatus = parsed.httpStatus;
152
+ }
153
+ if (typeof parsed.retryable === 'boolean') {
154
+ meta.retryable = parsed.retryable;
155
+ }
156
+ if (typeof parsed.queryId === 'string') {
157
+ meta.queryId = parsed.queryId;
158
+ }
159
+ // Rich diagnostics — Thrift/Python parity (were previously dropped).
160
+ if (typeof parsed.displayMessage === 'string') {
161
+ meta.displayMessage = parsed.displayMessage;
162
+ }
163
+ if (typeof parsed.diagnosticInfo === 'string') {
164
+ meta.diagnosticInfo = parsed.diagnosticInfo;
165
+ }
166
+ if (typeof parsed.errorDetailsJson === 'string') {
167
+ meta.errorDetailsJson = parsed.errorDetailsJson;
168
+ }
169
+ return meta;
170
+ }
171
+ /**
172
+ * Decode a napi-binding error into the typed JS error class.
173
+ *
174
+ * Two paths:
175
+ * - Structured kernel error: `Error.message` starts with
176
+ * {@link ERROR_SENTINEL} followed by a JSON envelope. We strip the
177
+ * sentinel, parse the JSON, route the {@link KernelErrorShape}
178
+ * through {@link mapKernelErrorToJsError}, and attach the remaining
179
+ * envelope fields under a single non-enumerable `kernelMetadata`
180
+ * namespace. Namespacing avoids the collision with
181
+ * `OperationStateError.errorCode` (an enum already switched on at the
182
+ * JS layer — see `DBSQLOperation.ts` around `:374`).
183
+ * - Binding-side error (e.g. `napi::Error::new(InvalidArg, "openSession:
184
+ * \`token\` is required for the requested auth mode")` produced by
185
+ * the binding's own validation): returned unchanged. These don't
186
+ * carry kernel `code` info, so we surface them as-is.
187
+ *
188
+ * Non-`Error` values (e.g. a `Promise.reject('string')`) pass through
189
+ * wrapped in `HiveDriverError` so callers always see an `Error`
190
+ * subclass.
191
+ */
192
+ function decodeNapiKernelError(err) {
193
+ if (!(err instanceof Error)) {
194
+ return new HiveDriverError_1.default(typeof err === 'string' ? err : 'kernel backend: unknown error');
195
+ }
196
+ const { message } = err;
197
+ if (typeof message !== 'string' || !message.startsWith(ERROR_SENTINEL)) {
198
+ return err;
199
+ }
200
+ const jsonStr = message.slice(ERROR_SENTINEL.length);
201
+ let parsed;
202
+ try {
203
+ parsed = JSON.parse(jsonStr);
204
+ }
205
+ catch (_a) {
206
+ // Corrupted envelope — surface the raw post-sentinel payload rather
207
+ // than silently dropping the original error. Strip the internal
208
+ // `__databricks_error__:` prefix; it's a binding/JS-side framing
209
+ // marker, not user-actionable, and leaking it makes the message
210
+ // confusing to operators triaging a malformed kernel response.
211
+ //
212
+ // Mutate in place when possible so the napi-binding's original
213
+ // stack survives — that stack is the only useful triage signal on
214
+ // a malformed-envelope path (where did a sentinel-prefixed
215
+ // non-JSON message come from?). Fall back to a fresh
216
+ // `HiveDriverError` only if a future napi-rs revision makes
217
+ // `Error.message` non-writable (no such guarantee today, but the
218
+ // descriptor contract is implementation-defined).
219
+ try {
220
+ err.message = jsonStr;
221
+ return err;
222
+ }
223
+ catch (_b) {
224
+ return new HiveDriverError_1.default(jsonStr);
225
+ }
226
+ }
227
+ if (typeof parsed !== 'object' ||
228
+ parsed === null ||
229
+ typeof parsed.code !== 'string' ||
230
+ typeof parsed.message !== 'string') {
231
+ return err;
232
+ }
233
+ const envelope = parsed;
234
+ const code = envelope.code;
235
+ const msg = envelope.message;
236
+ const sqlState = typeof envelope.sqlState === 'string' ? envelope.sqlState : undefined;
237
+ const jsErr = mapKernelErrorToJsError({ code, message: msg, sqlstate: sqlState });
238
+ const meta = buildKernelMetadata(envelope);
239
+ // Skip the namespace attachment entirely when no fields validated
240
+ // through — keeps `err.kernelMetadata` absent rather than `{}` for
241
+ // simple envelopes (the common case). Key-count check so new
242
+ // `KernelMetadata` fields are covered automatically.
243
+ if (Object.keys(meta).length > 0) {
244
+ defineErrorMetadata(jsErr, 'kernelMetadata', meta);
245
+ }
246
+ return jsErr;
247
+ }
248
+ exports.decodeNapiKernelError = decodeNapiKernelError;
249
+ //# sourceMappingURL=KernelErrorMapping.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KernelErrorMapping.js","sourceRoot":"","sources":["../../lib/kernel/KernelErrorMapping.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gFAAwD;AACxD,wFAAgE;AAChE,qFAA6F;AAC7F,8EAAsD;AAEtD;;;;;;GAMG;AACH,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAoF/C;;;;;;;GAOG;AACH,SAAS,mBAAmB,CAAsB,KAAY,EAAE,GAAM,EAAE,KAAQ;IAC9E,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE;QAChC,KAAK;QACL,QAAQ,EAAE,IAAI;QACd,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,IAAI;KACnB,CAAC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KAAK,QAAQ,EAC7D;QACA,OAAO,GAAG,CAAC;KACZ;IAED,MAAM,QAAQ,GAAG,MAAiC,CAAC;IACnD,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAc,CAAC;IACrC,MAAM,GAAG,GAAG,QAAQ,CAAC,OAAiB,CAAC;IACvC,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IAEvF,MAAM,KAAK,GAAG,uBAAuB,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;IAElF,MAAM,IAAI,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IAC3C,kEAAkE;IAClE,mEAAmE;IACnE,6DAA6D;IAC7D,qDAAqD;IACrD,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;QAChC,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,EAAE,IAAI,CAAC,CAAC;KACpD;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AA7DD,sDA6DC"}
@@ -0,0 +1,16 @@
1
+ import { DBSQLParameter, DBSQLParameterValue } from '../DBSQLParameter';
2
+ /**
3
+ * Reject a parameter value that cannot be bound as a scalar. Arrays and plain
4
+ * objects stringify to garbage (e.g. `[1,2,3]` → `"1,2,3"`) that the server
5
+ * fails to coerce — on the Thrift path the operation never returns to
6
+ * FINISHED (a DoS hazard), and on kernel it surfaces an opaque server error. We
7
+ * fail fast at bind time instead, mirroring the kernel's compound-type
8
+ * rejection. `DBSQLParameter`, `Int64`, `Date`, and JS primitives are allowed.
9
+ *
10
+ * Parameter-marker counting and arity validation are intentionally NOT done
11
+ * here: the kernel's `statement::params` codec owns that check and binds
12
+ * exactly one placeholder style per statement, so duplicating the SQL-walk
13
+ * JS-side would only risk drift. The driver's sole bind-time job is this
14
+ * cheap, type-shape gate before the value crosses the napi boundary.
15
+ */
16
+ export default function assertBindableValue(value: DBSQLParameter | DBSQLParameterValue, label: string): void;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ // Copyright (c) 2026 Databricks, Inc.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ var __importDefault = (this && this.__importDefault) || function (mod) {
16
+ return (mod && mod.__esModule) ? mod : { "default": mod };
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ const node_int64_1 = __importDefault(require("node-int64"));
20
+ const DBSQLParameter_1 = require("../DBSQLParameter");
21
+ const ParameterError_1 = __importDefault(require("../errors/ParameterError"));
22
+ /**
23
+ * Reject a parameter value that cannot be bound as a scalar. Arrays and plain
24
+ * objects stringify to garbage (e.g. `[1,2,3]` → `"1,2,3"`) that the server
25
+ * fails to coerce — on the Thrift path the operation never returns to
26
+ * FINISHED (a DoS hazard), and on kernel it surfaces an opaque server error. We
27
+ * fail fast at bind time instead, mirroring the kernel's compound-type
28
+ * rejection. `DBSQLParameter`, `Int64`, `Date`, and JS primitives are allowed.
29
+ *
30
+ * Parameter-marker counting and arity validation are intentionally NOT done
31
+ * here: the kernel's `statement::params` codec owns that check and binds
32
+ * exactly one placeholder style per statement, so duplicating the SQL-walk
33
+ * JS-side would only risk drift. The driver's sole bind-time job is this
34
+ * cheap, type-shape gate before the value crosses the napi boundary.
35
+ */
36
+ function assertBindableValue(value, label) {
37
+ if (value instanceof DBSQLParameter_1.DBSQLParameter)
38
+ return;
39
+ if (value === null || value === undefined)
40
+ return;
41
+ if (Array.isArray(value)) {
42
+ throw new ParameterError_1.default(`${label} is an array; compound types (ARRAY/MAP/STRUCT) are not bindable as a parameter value`);
43
+ }
44
+ if (typeof value === 'object' && !(value instanceof Date) && !(value instanceof node_int64_1.default)) {
45
+ throw new ParameterError_1.default(`${label} is an object; only scalar values (string/number/bigint/boolean), Date, and Int64 are bindable`);
46
+ }
47
+ }
48
+ exports.default = assertBindableValue;
49
+ //# sourceMappingURL=KernelInputValidation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KernelInputValidation.js","sourceRoot":"","sources":["../../lib/kernel/KernelInputValidation.ts"],"names":[],"mappings":";AAAA,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;;;;AAEjC,4DAA+B;AAC/B,sDAAwE;AACxE,8EAAsD;AAEtD;;;;;;;;;;;;;GAaG;AACH,SAAwB,mBAAmB,CAAC,KAA2C,EAAE,KAAa;IACpG,IAAI,KAAK,YAAY,+BAAc;QAAE,OAAO;IAC5C,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO;IAClD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACxB,MAAM,IAAI,wBAAc,CACtB,GAAG,KAAK,uFAAuF,CAChG,CAAC;KACH;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,YAAY,oBAAK,CAAC,EAAE;QACtF,MAAM,IAAI,wBAAc,CACtB,GAAG,KAAK,gGAAgG,CACzG,CAAC;KACH;AACH,CAAC;AAbD,sCAaC"}