|
| 1 | +// Copyright (c) 2026 Databricks, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +/** |
| 16 | + * Loader for the SEA (Statement Execution API) native binding. |
| 17 | + * |
| 18 | + * Round 1b: minimal pass-through to the napi-rs auto-generated |
| 19 | + * `index.js` shim in `native/sea/`. The shim itself picks the right |
| 20 | + * per-platform `.node` artifact (linux-x64-gnu today; more triples in |
| 21 | + * the bundling feature). |
| 22 | + * |
| 23 | + * Round 2+ will extend this with: lazy require to defer the `.node` |
| 24 | + * load until the first SEA call, structured load-error diagnostics |
| 25 | + * (which platform/arch was attempted, whether the package was |
| 26 | + * installed at all), and a JS-side `DBSQLLogger` install path that |
| 27 | + * forwards to the binding's `installLogger()` once that surface lands. |
| 28 | + */ |
| 29 | + |
| 30 | +// The path is relative to this file at runtime (`dist/sea/SeaNativeLoader.js`) |
| 31 | +// resolving to `dist/sea/../../native/sea/index.js` once `tsc` has emitted |
| 32 | +// to `dist/`. We use a require-time path resolution because the napi |
| 33 | +// shim is plain CommonJS and not part of the TS source tree. |
| 34 | +// |
| 35 | +// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require |
| 36 | +const native = require('../../native/sea/index.js'); |
| 37 | + |
| 38 | +export interface SeaNativeBinding { |
| 39 | + /** Returns the native crate version (smoke test for the binding's load path). */ |
| 40 | + version(): string; |
| 41 | +} |
| 42 | + |
| 43 | +/** |
| 44 | + * Returns the loaded native binding. Throws if the platform-specific |
| 45 | + * `.node` artifact cannot be found (napi-rs's auto-generated shim |
| 46 | + * surfaces a descriptive error in that case). |
| 47 | + */ |
| 48 | +export function getSeaNative(): SeaNativeBinding { |
| 49 | + return native as SeaNativeBinding; |
| 50 | +} |
| 51 | + |
| 52 | +/** |
| 53 | + * Convenience accessor for the smoke-test path. Equivalent to |
| 54 | + * `getSeaNative().version()` but reads more naturally in tests and |
| 55 | + * REPLs. |
| 56 | + */ |
| 57 | +export function version(): string { |
| 58 | + return getSeaNative().version(); |
| 59 | +} |
0 commit comments