@ohos-ports/malloydata-db-duckdb 0.0.437-beta.0 → 0.0.439-beta.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.
@@ -418,6 +418,22 @@ registration, and credential injection.
418
418
  If Malloy later wants restricted execution for `duckdb_wasm`, design it
419
419
  explicitly for WASM instead of copying native policy semantics.
420
420
 
421
+ ## Host Scope
422
+
423
+ `DuckDBHostConnection` (the `/host` entry point) runs SQL in a database that
424
+ belongs to its host, such as a DuckDB extension running Malloy in an embedded
425
+ JavaScript engine.
426
+
427
+ - The `/host` entry point exists so such a host can load the connection
428
+ without the native driver. Its imports must stay free of `@duckdb/node-api`
429
+ and Node built-ins; `duckdb_host_connection.ts` imports only
430
+ `@malloydata/malloy` and `duckdb_common.ts`.
431
+ - It applies no session baseline. The `TimeZone='UTC'` and extension loading
432
+ above are the native connection's; the host's session is the host's own,
433
+ and `DuckDBHost.query`'s doc tells a host what Malloy's SQL expects.
434
+ - No security policy or config properties apply: the host decides what its
435
+ database can reach.
436
+
421
437
  ## Adding A New DuckDB Config Property
422
438
 
423
439
  When adding a new native DuckDB config property, update all relevant layers:
@@ -275,6 +275,26 @@ class DuckDBConnection extends duckdb_common_1.DuckDBCommon {
275
275
  catch (loadError) {
276
276
  if (!options.allowInstall) {
277
277
  if (options.required) {
278
+ // Upstream marks the restricted baseline extensions
279
+ // ('json', 'icu') required because official DuckDB builds
280
+ // statically link them, so `LOAD` keeps working after
281
+ // `SET enable_external_access=false`. On builds where a
282
+ // baseline extension is NOT statically linked (e.g. 'json'
283
+ // in the @ohos-ports duckdb-node-bindings build), the same
284
+ // LOAD is rejected with "Loading external extensions is
285
+ // disabled through configuration" — the restricted
286
+ // configuration itself forbids the load. Degrade that
287
+ // specific case to a warning instead of failing every
288
+ // restricted-policy connection; the restricted security
289
+ // contract (external access disabled, httpfs unloaded) is
290
+ // unchanged. Any other load failure still fails closed.
291
+ if (this.normalized.securityPolicy !== 'none' &&
292
+ this.normalized.enableExternalAccess === false &&
293
+ /loading external extensions is disabled through configuration/i.test(String((loadError === null || loadError === void 0 ? void 0 : loadError.message) || loadError))) {
294
+ // eslint-disable-next-line no-console
295
+ console.error(`Unable to load DuckDB extension "${extension}" under the restricted security policy (extension is not statically linked in this DuckDB build)`, loadError);
296
+ return;
297
+ }
278
298
  throw loadError;
279
299
  }
280
300
  // eslint-disable-next-line no-console
@@ -0,0 +1,51 @@
1
+ import type { QueryOptionsReader, QueryRecord, RunSQLOptions } from '@malloydata/malloy';
2
+ import { DuckDBCommon } from './duckdb_common';
3
+ /**
4
+ * A host that is itself a DuckDB database, such as a DuckDB extension
5
+ * running Malloy in an embedded JavaScript engine.
6
+ */
7
+ export interface DuckDBHost {
8
+ /**
9
+ * Runs one DuckDB statement in the host's database and returns its rows.
10
+ * Throw to report a failure; the message reaches the user.
11
+ *
12
+ * - **Rows** are one object per row keyed by column name, with values as
13
+ * DuckDB converts them to JSON (the Node connection reads
14
+ * `getRowObjectsJson()`): BIGINT, HUGEINT and DECIMAL as strings, dates and
15
+ * timestamps as strings, LISTs as arrays, STRUCTs as objects.
16
+ * - **Statements** can be any DuckDB SQL. A query may begin with a
17
+ * metadata comment. Reading a table's or a SQL source's schema sends
18
+ * `DESCRIBE SELECT * FROM <table>` or `DESCRIBE SELECT * FROM (<sql>)`
19
+ * and reads each row's `column_name` and `column_type`; `test()` sends `SELECT 1`; persisting
20
+ * a result sends `CREATE TEMPORARY TABLE`.
21
+ * - **Session settings** are the host's. Malloy's generated SQL expects
22
+ * what the Node connection sets up: `SET TimeZone='UTC'` and the `json`
23
+ * and `icu` extensions loaded. A host that differs gets different
24
+ * answers for time and JSON functions.
25
+ */
26
+ query(sql: string): QueryRecord[] | Promise<QueryRecord[]>;
27
+ /**
28
+ * Any stable string identifying the host's database, as a database path
29
+ * does for the Node connection. The connection's digest is made from it,
30
+ * so two connections with the same `databaseId` are taken to read the
31
+ * same tables.
32
+ */
33
+ databaseId: string;
34
+ }
35
+ /**
36
+ * A DuckDB connection whose database belongs to the host: the host runs the
37
+ * SQL. A streamed query is read whole from the host and then yielded.
38
+ */
39
+ export declare class DuckDBHostConnection extends DuckDBCommon {
40
+ private readonly host;
41
+ readonly name: string;
42
+ constructor(name: string, host: DuckDBHost, queryOptions?: QueryOptionsReader);
43
+ getDigest(): string;
44
+ protected setup(): Promise<void>;
45
+ protected runDuckDBQuery(sql: string): Promise<{
46
+ rows: QueryRecord[];
47
+ totalRows: number;
48
+ }>;
49
+ runSQLStream(sql: string, options?: RunSQLOptions): AsyncIterableIterator<QueryRecord>;
50
+ close(): Promise<void>;
51
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright Contributors to the Malloy project
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.DuckDBHostConnection = void 0;
8
+ const malloy_1 = require("@malloydata/malloy");
9
+ const duckdb_common_1 = require("./duckdb_common");
10
+ /**
11
+ * A DuckDB connection whose database belongs to the host: the host runs the
12
+ * SQL. A streamed query is read whole from the host and then yielded.
13
+ */
14
+ class DuckDBHostConnection extends duckdb_common_1.DuckDBCommon {
15
+ constructor(name, host, queryOptions) {
16
+ super(queryOptions);
17
+ this.host = host;
18
+ this.name = name;
19
+ }
20
+ getDigest() {
21
+ return (0, malloy_1.makeDigest)('duckdb-host', this.host.databaseId);
22
+ }
23
+ async setup() { }
24
+ async runDuckDBQuery(sql) {
25
+ const rows = await this.host.query(sql);
26
+ return { rows, totalRows: rows.length };
27
+ }
28
+ async *runSQLStream(sql, options = {}) {
29
+ var _a;
30
+ const { rows } = await this.runSQL(sql, options);
31
+ for (const row of rows) {
32
+ if ((_a = options.abortSignal) === null || _a === void 0 ? void 0 : _a.aborted)
33
+ return;
34
+ yield row;
35
+ }
36
+ }
37
+ async close() { }
38
+ }
39
+ exports.DuckDBHostConnection = DuckDBHostConnection;
40
+ //# sourceMappingURL=duckdb_host_connection.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohos-ports/malloydata-db-duckdb",
3
- "version": "0.0.437-beta.0",
3
+ "version": "0.0.439-beta.0",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -25,6 +25,10 @@
25
25
  "browser": "./dist/duckdb_wasm_connection_browser.js",
26
26
  "node": "./dist/duckdb_wasm_connection_node.js",
27
27
  "types": "./dist/duckdb_wasm_connection_browser.d.ts"
28
+ },
29
+ "./host": {
30
+ "types": "./dist/duckdb_host_connection.d.ts",
31
+ "default": "./dist/duckdb_host_connection.js"
28
32
  }
29
33
  },
30
34
  "typesVersions": {
@@ -40,19 +44,22 @@
40
44
  ],
41
45
  "wasm": [
42
46
  "./dist/duckdb_wasm_connection_browser.d.ts"
47
+ ],
48
+ "host": [
49
+ "./dist/duckdb_host_connection.d.ts"
43
50
  ]
44
51
  }
45
52
  },
46
- "homepage": "https://github.com/ohos-ports/ohos-ports/tree/main/ports/malloydata-db-duckdb/0.0.437",
53
+ "homepage": "https://github.com/ohos-ports/ohos-ports#readme",
47
54
  "repository": {
48
55
  "type": "git",
49
56
  "url": "https://github.com/ohos-ports/ohos-ports.git",
50
- "directory": "ports/malloydata-db-duckdb/0.0.437"
57
+ "directory": "ports/malloydata-db-duckdb/0.0.439"
51
58
  },
52
59
  "dependencies": {
53
60
  "@duckdb/duckdb-wasm": "1.33.1-dev57.0",
54
61
  "@ohos-ports/duckdb-node-api": "^1.5.5-r.4-beta.0",
55
- "@malloydata/malloy": "0.0.437",
62
+ "@malloydata/malloy": "0.0.439",
56
63
  "@motherduck/wasm-client": "0.6.6",
57
64
  "apache-arrow": "^17.0.0",
58
65
  "web-worker": "^1.5.0"