@ohos-ports/malloydata-db-duckdb 0.0.0-stage → 0.0.437-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.
package/LICENSE ADDED
@@ -0,0 +1,77 @@
1
+ Malloy Project License
2
+ SPDX-License-Identifier: MIT
3
+
4
+ Copyright Contributors to the Malloy project
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+
24
+ ========================================================================
25
+ SOURCE FILE HEADER
26
+ ========================================================================
27
+
28
+ Every source file in this project carries the following header (shown here
29
+ in C/Java/JavaScript comment style; equivalent comment styles are used for
30
+ other languages):
31
+
32
+ /*
33
+ * Copyright Contributors to the Malloy project
34
+ * SPDX-License-Identifier: MIT
35
+ */
36
+
37
+ ========================================================================
38
+ HISTORICAL ATTRIBUTIONS & NOTICES
39
+ ========================================================================
40
+
41
+ Portions of this software were originally contributed by Google LLC and
42
+ Meta Platforms, Inc. and affiliates under the MIT License. For ease of
43
+ maintenance, individual file headers have been updated to the current
44
+ standard header. The full historical attribution and authorship for
45
+ individual files remains completely preserved and accessible via the Git
46
+ repository history.
47
+
48
+ The original copyright and permission notices for those contributions
49
+ are preserved below:
50
+
51
+ ------------------------------------------------------------------------
52
+ Copyright 2023 Google LLC
53
+
54
+ Permission is hereby granted, free of charge, to any person obtaining
55
+ a copy of this software and associated documentation files (the
56
+ "Software"), to deal in the Software without restriction, including
57
+ without limitation the rights to use, copy, modify, merge, publish,
58
+ distribute, sublicense, and/or sell copies of the Software, and to
59
+ permit persons to whom the Software is furnished to do so, subject to
60
+ the following conditions:
61
+
62
+ The above copyright notice and this permission notice shall be
63
+ included in all copies or substantial portions of the Software.
64
+
65
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
66
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
67
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
68
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
69
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
70
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
71
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
72
+ ------------------------------------------------------------------------
73
+ Copyright (c) Meta Platforms, Inc. and affiliates.
74
+
75
+ This source code is licensed under the MIT license found in the
76
+ LICENSE file in the root directory of this source tree.
77
+ ------------------------------------------------------------------------
@@ -0,0 +1,489 @@
1
+ # DuckDB Config Maintenance Notes
2
+
3
+ This file is the self-contained maintainer handoff for Malloy's native DuckDB
4
+ configuration and restricted-execution policy code. A future maintainer should
5
+ be able to understand the policy entities, their purpose, and the safe way to
6
+ extend them from this file plus the implementation.
7
+
8
+ Historical design notes may exist elsewhere in the repository, but this file
9
+ must not depend on them for essential context.
10
+
11
+ ## Mental Model
12
+
13
+ Malloy exposes one user-facing policy property for native DuckDB:
14
+
15
+ - `securityPolicy: "none" | "local" | "sandboxed"`
16
+
17
+ This field is a Malloy policy control. It is not a raw DuckDB option name
18
+ and it is not a general policy language.
19
+
20
+ The three levels form a strict escalation:
21
+
22
+ - `"none"` — no security policy applied. Ordinary DuckDB behavior.
23
+ - `"local"` — no network access. DuckDB cannot reach the network, but local
24
+ filesystem access is not sandboxed to specific directories.
25
+ - `"sandboxed"` — no network access AND filesystem confined to
26
+ `allowedDirectories`. The reviewed strict recipe.
27
+
28
+ DuckDB's `enable_external_access` is a single toggle that gates both filesystem
29
+ reach beyond the working directory and network reach. Setting
30
+ `allowed_directories` without disabling `enable_external_access` has no effect.
31
+ This is why the policy is a single axis rather than two independent axes — the
32
+ underlying DuckDB mechanism does not support independent filesystem and network
33
+ control.
34
+
35
+ The implementation compiles the public policy value into an internal
36
+ `NormalizedDuckDBSafetyPolicy`. That internal object records the derived
37
+ enforcement requirements, such as locked configuration, no setup SQL,
38
+ temp-file encryption, extension restrictions, and secret neutralization. Keep
39
+ the public surface small and make new enforcement consequences explicit in the
40
+ derived policy object.
41
+
42
+ Restricted execution is about DuckDB filesystem reach, network reach, mutable
43
+ configuration, extension loading, instance sharing, and ambient persistent
44
+ secrets. It is not a complete sandbox. It does not provide CPU, memory,
45
+ temp-space, query-timeout, or denial-of-service isolation. Hosts that need
46
+ resource isolation must configure controls such as `threads`, `memoryLimit`,
47
+ process isolation, query cancellation, and host-level quotas separately.
48
+
49
+ ## Code Map
50
+
51
+ - Native connection schema: `src/native.ts`
52
+ - Registers native DuckDB properties.
53
+ - `securityPolicy` carries `source: 'literal'` (no overlay reference) and
54
+ `mustHaveValue` (writing it must produce a value), so a reference-shaped or
55
+ non-string value fails the connection instead of being silently dropped by
56
+ generic config compilation.
57
+ - Config compiler guard: `../malloy/src/api/foundation/config_compile.ts`
58
+ - Records an authored-but-unusable value as an `invalid` node after warning,
59
+ so `config_lookup.ts` can tell it apart from an omitted property and fail
60
+ closed before the DuckDB factory runs.
61
+ - Normalization and policy derivation: `src/duckdb_config.ts`
62
+ - Parses raw effective config.
63
+ - Derives `NormalizedDuckDBSafetyPolicy`.
64
+ - Applies conflict checks, policy-derived defaults, canonicalization, secret
65
+ directory derivation, and share-key construction.
66
+ - Path security helpers: `src/path_security.ts`
67
+ - Canonicalizes paths and performs containment checks.
68
+ - Path handling is part of the security boundary.
69
+ - Native lifecycle and baseline setup: `src/duckdb_connection.ts`
70
+ - Normalizes before opening DuckDB.
71
+ - Builds the share key.
72
+ - Opens or reuses a native instance.
73
+ - Applies the final baseline, then optional unrestricted `setupSQL`, then
74
+ `lock_configuration=true` when policy requires it.
75
+ - Policy tests:
76
+ - `src/duckdb_config.spec.ts`
77
+ - `src/duckdb_restricted.spec.ts`
78
+
79
+ ## Core Invariants
80
+
81
+ - Restricted execution must fail closed. Unknown policy values, conflicting
82
+ explicit settings, missing required values, or inability to apply the
83
+ baseline must fail connection creation.
84
+ - Policy validation must run early enough that invalid raw values such as
85
+ `true`, `42`, or `{env: "POLICY"}` cannot be silently dropped and interpreted
86
+ as the default `"none"` policy.
87
+ - A restricted DuckDB connection must never share a live instance with a less
88
+ restrictive or otherwise semantically different connection.
89
+ - The fixed baseline must be established before any Malloy-derived SQL runs.
90
+ - Configuration must be locked whenever the derived safety policy requires it.
91
+ - Ordinary DuckDB connections must remain ordinary. Do not implicitly turn them
92
+ into locked connections. Mixed Malloy/SQL workflows that rely on later DuckDB
93
+ `SET` statements remain unrestricted workflows.
94
+ - `duckdb_wasm` does not receive these native policy guarantees. WASM hardening
95
+ is host-owned unless a separate WASM-specific policy design is implemented.
96
+
97
+ ## User-Facing Policy Behavior
98
+
99
+ `securityPolicy: "none"` means no security policy is applied. Ordinary DuckDB
100
+ behavior.
101
+
102
+ `securityPolicy: "local"` means Malloy disables network-capable DuckDB
103
+ behavior:
104
+
105
+ - `enableExternalAccess` is forced to `false`.
106
+ - `httpfs` must not load.
107
+ - DuckDB must not `INSTALL` extensions.
108
+ - network-requiring `databasePath` values, including MotherDuck paths, are
109
+ rejected.
110
+ - `motherDuckToken` is rejected.
111
+ - configuration is locked after baseline setup.
112
+ - `setupSQL` is not allowed.
113
+ - temp-file encryption is required.
114
+ - secrets are neutralized.
115
+
116
+ `securityPolicy: "sandboxed"` means everything in `"local"`, plus Malloy
117
+ derives and enforces a native DuckDB filesystem boundary:
118
+
119
+ - `allowedDirectories` is required or derived.
120
+ - `tempDirectory` is required or derived.
121
+ - `workingDirectory`, when present, must be inside `allowedDirectories`.
122
+ - `tempDirectory` must be inside `allowedDirectories`.
123
+ - Non-POSIX hosts are rejected. Do not approximate Windows path behavior for
124
+ the current policy.
125
+
126
+ ## Registered Config Surface
127
+
128
+ Native DuckDB supports the existing Malloy-facing properties:
129
+
130
+ - `databasePath`
131
+ - `workingDirectory`
132
+ - `motherDuckToken`
133
+ - `additionalExtensions`
134
+ - `readOnly`
135
+ - `setupSQL`
136
+
137
+ The config extension adds the policy property:
138
+
139
+ - `securityPolicy`
140
+
141
+ It also adds curated DuckDB-level properties:
142
+
143
+ - `allowedDirectories`
144
+ - `enableExternalAccess`
145
+ - `lockConfiguration`
146
+ - `autoloadKnownExtensions`
147
+ - `autoinstallKnownExtensions`
148
+ - `allowCommunityExtensions`
149
+ - `allowUnsignedExtensions`
150
+ - `tempFileEncryption`
151
+ - `threads`
152
+ - `memoryLimit`
153
+ - `tempDirectory`
154
+ - `extensionDirectory`
155
+
156
+ `allowedDirectories` is intentionally registered as `json` for now because the
157
+ connection property model does not yet have a first-class string-array type.
158
+ Even though the registry metadata says `json`, DuckDB normalization must require
159
+ the value to be a JSON array of strings. Do not add a registry default for
160
+ `allowedDirectories`; its only defaulting behavior belongs to
161
+ `securityPolicy: "sandboxed"` normalization.
162
+
163
+ `workingDirectory` defaults to `{config: "rootDirectory"}` in the native DuckDB
164
+ registry. Hosts that know the project root should populate `config.rootDirectory`
165
+ so relative DuckDB file paths resolve against the project root rather than the
166
+ location of an individual Malloy file or config file. If a sandboxed connection
167
+ expected this overlay and it is missing, normalization should fail with an error
168
+ that points at `workingDirectory`/`allowedDirectories` and mentions the
169
+ `config.rootDirectory` overlay.
170
+
171
+ `memoryLimit` remains a string because DuckDB accepts values such as `1GB`.
172
+
173
+ ## Normalization Rules
174
+
175
+ All policy reasoning belongs in `normalizeDuckDBConfig()`.
176
+
177
+ Policy parsing:
178
+
179
+ - Missing `securityPolicy` defaults to `"none"`.
180
+ - Accepted policy values are exact documented strings only: `"none"`, `"local"`,
181
+ `"sandboxed"`.
182
+ - Unknown strings, strings with whitespace or different casing, non-strings,
183
+ and reference-shaped values must fail closed.
184
+
185
+ Derived safety policy:
186
+
187
+ - If `securityPolicy` is `"local"` or `"sandboxed"` (i.e., restricted), derive:
188
+ - `requiresLockedConfiguration: true`
189
+ - `requiresNoSetupSQL: true`
190
+ - `requiresTempFileEncryption: true`
191
+ - `requiresSecretNeutralization: true`
192
+ - `forbidAdditionalExtensions: true`
193
+ - `allowHttpfs: false`
194
+ - `enableExternalAccess: false`
195
+ - required baseline extensions `icu` and `json`
196
+ - no extension install or auto-install/autoload expansion
197
+ - If `securityPolicy === "sandboxed"`, also derive:
198
+ - POSIX host required
199
+ - sandboxed path validation required
200
+ - derived temp directory name `.tmp`
201
+
202
+ Conflict checks:
203
+
204
+ - Reject `setupSQL` whenever a restricted policy requires a locked baseline.
205
+ - Reject non-empty `additionalExtensions` whenever a restricted policy forbids
206
+ extension broadening.
207
+ - Reject `lockConfiguration: false` under any restricted policy.
208
+ - Reject `tempFileEncryption: false` under any restricted policy.
209
+ - Under any restricted policy, reject:
210
+ - `enableExternalAccess: true`
211
+ - `autoloadKnownExtensions: true`
212
+ - `autoinstallKnownExtensions: true`
213
+ - `allowCommunityExtensions: true`
214
+ - `allowUnsignedExtensions: true`
215
+ - `motherDuckToken`
216
+ - remote or network-requiring `databasePath`
217
+ - Redundant matching values are allowed. For example,
218
+ `securityPolicy: "local"` plus `enableExternalAccess: false` is valid.
219
+
220
+ Derived defaults:
221
+
222
+ - Under any restricted policy, force:
223
+ - `enableExternalAccess = false`
224
+ - `lockConfiguration = true`
225
+ - `tempFileEncryption = true`
226
+ - `autoloadKnownExtensions = false`
227
+ - `autoinstallKnownExtensions = false`
228
+ - `allowCommunityExtensions = false`
229
+ - `allowUnsignedExtensions = false`
230
+ - Under `securityPolicy: "sandboxed"`:
231
+ - If `allowedDirectories` is omitted, derive it to exactly the canonical
232
+ `workingDirectory`, and nothing broader.
233
+ - If `tempDirectory` is omitted, derive it to `workingDirectory/.tmp`.
234
+ - If Malloy cannot derive the required paths safely, fail closed with a
235
+ field-specific error.
236
+ - Outside `securityPolicy: "sandboxed"`, do not invent an
237
+ `allowedDirectories` default.
238
+ - With `databasePath: ":memory:"`, normalize `readOnly` to `false`.
239
+ This intentionally preserves existing behavior. A user-facing warning for
240
+ ignored `readOnly: true` is deferred until host warning plumbing has a
241
+ reviewed path for normalized connection options.
242
+
243
+ Empty text/list handling:
244
+
245
+ - Empty or whitespace-only `setupSQL` is absent.
246
+ - Empty or whitespace-only `motherDuckToken` is absent.
247
+ - Empty `additionalExtensions` is absent.
248
+
249
+ ## Path Handling
250
+
251
+ Canonicalize path-bearing values before validation and before share-key
252
+ comparison:
253
+
254
+ - `databasePath`, except `:memory:` and recognized remote paths
255
+ - `workingDirectory`
256
+ - `allowedDirectories`
257
+ - `tempDirectory`
258
+ - `extensionDirectory`
259
+
260
+ Canonicalization must:
261
+
262
+ - resolve `.` and `..`
263
+ - normalize separators and remove trailing separators
264
+ - resolve symlinks when the path or its nearest existing parent exists
265
+ - deduplicate and sort list-valued paths before identity comparison
266
+
267
+ Containment checks must operate only on canonicalized values. Treat path
268
+ normalization as security logic, not cosmetic cleanup.
269
+
270
+ `allowedDirectories` is not read-only. Hosts must assume DuckDB may read and
271
+ write inside every allowed directory through features that remain available
272
+ inside the boundary, including `COPY TO`, `EXPORT DATABASE`, and attached
273
+ writable databases. Do not point `allowedDirectories` at shared writable
274
+ locations unless that write surface is acceptable.
275
+
276
+ ## Sharing And Identity
277
+
278
+ Do not cache native DuckDB instances by `databasePath` alone.
279
+
280
+ Use the derived share key from `buildDuckDBShareKey()` and include every
281
+ effective setting that can affect runtime behavior, safety, or semantics:
282
+
283
+ - `databasePath`
284
+ - `readOnly`
285
+ - `securityPolicy`
286
+ - `setupSQL`
287
+ - canonicalized `allowedDirectories`
288
+ - `enableExternalAccess`
289
+ - `lockConfiguration`
290
+ - `autoloadKnownExtensions`
291
+ - `autoinstallKnownExtensions`
292
+ - `allowCommunityExtensions`
293
+ - `allowUnsignedExtensions`
294
+ - `tempFileEncryption`
295
+ - `threads`
296
+ - `memoryLimit`
297
+ - `tempDirectory`
298
+ - `workingDirectory`
299
+ - normalized `additionalExtensions`
300
+ - `extensionDirectory`
301
+ - `motherDuckToken`
302
+
303
+ List-valued inputs must be canonicalized, sorted, and deduplicated so
304
+ semantically identical configs share and semantically different configs do not.
305
+
306
+ Keep the share key separate from `getDigest()`:
307
+
308
+ - `getDigest()` is about build/result identity.
309
+ - the share key is about safe native instance reuse.
310
+
311
+ This share-key behavior intentionally affects ordinary connections too:
312
+ connections with the same `databasePath` but different effective settings
313
+ should not share a live instance.
314
+
315
+ Share keys are sensitive because `motherDuckToken` contributes to them. Use
316
+ `makeDigest(...)` and do not log raw share-key inputs.
317
+
318
+ ## Baseline Setup
319
+
320
+ Prefer open-time DuckDB config through `DuckDBInstance.create(path, options)`
321
+ when the option is supported and serializes cleanly. Keep post-connect setup as
322
+ small as practical.
323
+
324
+ The final baseline must happen before Malloy-derived SQL. When locking is
325
+ required, `lock_configuration=true` is the final baseline step.
326
+
327
+ Current baseline mapping:
328
+
329
+ - `FILE_SEARCH_PATH`
330
+ - set before user SQL when `workingDirectory` exists
331
+ - currently post-connect because open-time behavior is not verified
332
+ - `allowed_directories`
333
+ - set before lock when normalized config has `allowedDirectories`
334
+ - currently post-connect because the DuckDB Node API rejects the list-valued
335
+ option during local verification
336
+ - `secret_directory`
337
+ - set before lock when restricted secret neutralization derives a directory
338
+ - currently post-connect because open-time behavior is not verified
339
+ - `enable_external_access`
340
+ - set at open time when no `allowed_directories` baseline SET is required
341
+ - otherwise set immediately after `allowed_directories`
342
+ - DuckDB rejects changing `allowed_directories` after
343
+ `enable_external_access=false`, so the strict sandboxed recipe has this
344
+ small post-connect ordering constraint until the Node API can apply the
345
+ allowlist at instance creation
346
+ - `TimeZone='UTC'`
347
+ - always part of Malloy's fixed correctness baseline
348
+ - not user-configurable
349
+ - must be established before lock
350
+ - built-in extension loading
351
+ - preserve ordinary compatibility outside restricted modes
352
+ - under any restricted policy, do not `INSTALL`, do not load `httpfs`,
353
+ and load only the fixed Malloy baseline extensions
354
+ - `setupSQL`
355
+ - preserve outside restricted modes
356
+ - reject when a restricted policy requires a locked baseline
357
+ - run only after fixed baseline steps and before optional lock
358
+
359
+ Do not introduce later Malloy-emitted DuckDB `SET` statements that mutate
360
+ configuration after `lock_configuration=true`.
361
+
362
+ ## Extensions
363
+
364
+ `icu` and `json` are part of the fixed Malloy DuckDB baseline.
365
+
366
+ `httpfs` is not part of that baseline. It broadens remote/network-capable
367
+ behavior and is controlled by `securityPolicy`.
368
+
369
+ Under any restricted policy (`"local"` or `"sandboxed"`):
370
+
371
+ - do not load `httpfs`
372
+ - do not `INSTALL` extensions
373
+ - do not allow `additionalExtensions`
374
+ - load only fixed baseline extensions `icu` and `json`
375
+ - fail closed if a required baseline extension is unavailable locally
376
+
377
+ Outside restricted policies, preserve ordinary compatibility unless a
378
+ separate product decision changes it.
379
+
380
+ ## Secrets
381
+
382
+ The full DuckDB secrets product story is deferred. Do not add public
383
+ secrets-related config surface as part of restricted-policy maintenance unless
384
+ there is a reviewed product design.
385
+
386
+ Even without a public secrets product, restricted execution must not expose
387
+ ambient persistent DuckDB secrets from the host environment or another tenant.
388
+
389
+ Current interim behavior:
390
+
391
+ - Any restricted policy derives a private `secretDirectory`.
392
+ - If `tempDirectory` exists, derive secrets under
393
+ `tempDirectory/.duckdb-secrets`.
394
+ - Otherwise, if `workingDirectory` exists, derive secrets under
395
+ `workingDirectory/.duckdb-secrets`.
396
+ - If restricted mode cannot derive a scoped secret directory, fail closed.
397
+ - Apply `secret_directory` before lock.
398
+
399
+ If this behavior changes, update both the safety policy derivation and the
400
+ restricted-mode tests.
401
+
402
+ ## WASM Scope
403
+
404
+ The policy system described here targets native DuckDB.
405
+
406
+ Do not register the native-only policy field in the `duckdb_wasm` connection
407
+ schema in this pass:
408
+
409
+ - `securityPolicy`
410
+ - native-only hardening properties
411
+
412
+ Do not add native restricted-policy behavior to `DuckDBWASMConnection` as a
413
+ side effect of native DuckDB maintenance. WASM runs in a host-provided
414
+ JavaScript/WASM environment, where the host controls the virtual filesystem,
415
+ browser file APIs, fetch/network reach, OPFS, registered files, remote URL
416
+ registration, and credential injection.
417
+
418
+ If Malloy later wants restricted execution for `duckdb_wasm`, design it
419
+ explicitly for WASM instead of copying native policy semantics.
420
+
421
+ ## Adding A New DuckDB Config Property
422
+
423
+ When adding a new native DuckDB config property, update all relevant layers:
424
+
425
+ - Register the property in `src/native.ts` with the correct config metadata.
426
+ - Parse and validate it in `normalizeDuckDBConfig()`.
427
+ - Decide whether it conflicts with `securityPolicy`.
428
+ - Decide whether any restricted policy must derive or force a value.
429
+ - If it is path-like, canonicalize it before validation and identity
430
+ comparison.
431
+ - Include it in `buildDuckDBShareKey()` if it can affect runtime behavior,
432
+ security posture, or semantics.
433
+ - Decide whether it belongs in open-time options or final baseline setup.
434
+ - Add tests for validation, derived behavior, conflict behavior, and sharing
435
+ identity when relevant.
436
+ - Update this file if the property changes the policy model or maintainer
437
+ checklist.
438
+
439
+ Be conservative: new settings that broaden filesystem, network, extension,
440
+ credential, or mutable-configuration behavior should usually be rejected or
441
+ forced to a safe value under restricted policies.
442
+
443
+ ## Changing Policy Behavior
444
+
445
+ When changing `securityPolicy` or `NormalizedDuckDBSafetyPolicy`, review these
446
+ together:
447
+
448
+ - user-facing policy contract
449
+ - normalizer parsing and conflict checks
450
+ - derived defaults
451
+ - path canonicalization and containment rules
452
+ - secret neutralization
453
+ - open-time options
454
+ - final baseline ordering
455
+ - extension install/load behavior
456
+ - lock timing
457
+ - share-key inputs
458
+ - native restricted tests
459
+ - WASM non-claim boundary
460
+ - public documentation
461
+
462
+ Do not make a policy change only in `DuckDBConnection`. The normalizer should
463
+ remain the central place where raw config becomes effective policy and runtime
464
+ state.
465
+
466
+ ## Test Expectations
467
+
468
+ Keep focused tests for:
469
+
470
+ - `allowedDirectories` accepted as a JSON array of strings
471
+ - `allowedDirectories` rejected for non-array or non-string JSON values
472
+ - exact policy value parsing
473
+ - policy field rejected when provided as non-literal or reference-shaped value
474
+ - missing policy-required values failing closed
475
+ - conflict checks
476
+ - redundant matching explicit values accepted
477
+ - sandboxed derived defaults
478
+ - `tempDirectory` containment
479
+ - network-requiring `databasePath` rejection
480
+ - `readOnly: true` with `:memory:` normalizing to `false`
481
+ - share keys differing when safety-relevant settings differ
482
+ - different `securityPolicy` values producing different share keys
483
+ - semantically identical allowlists sharing
484
+ - restricted baseline order
485
+ - restricted policies not loading `httpfs`
486
+ - restricted policies not running `INSTALL`
487
+ - required baseline extensions loaded or failing closed
488
+ - later config-changing `SET` statements failing after lock
489
+ - `closeAllInstances()` clearing all share-keyed native instances
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
- # Temporary Holding Version
1
+ # Malloy
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Malloy is a modern open source language for describing data relationships and transformations. It is both a semantic modeling language and a querying language that runs queries against a relational database. Malloy currently connects to BigQuery and Postgres, and natively supports DuckDB. We've built a Visual Studio Code extension to facilitate building Malloy data models, querying and transforming data, and creating simple visualizations and dashboards.
4
+
5
+ ## This package
6
+
7
+ This package facilitates using the `malloydata/malloy` library with DuckDB - see [here](https://github.com/malloydata/malloy/blob/main/packages/malloy/README.md) for additional information.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,46 @@
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
+ const malloy_1 = require("@malloydata/malloy");
8
+ const duckdb_wasm_connection_browser_1 = require("./duckdb_wasm_connection_browser");
9
+ (0, malloy_1.registerConnectionType)('duckdb_wasm', {
10
+ displayName: 'DuckDB',
11
+ factory: async (config) => new duckdb_wasm_connection_browser_1.DuckDBWASMConnection(config),
12
+ properties: [
13
+ {
14
+ name: 'databasePath',
15
+ displayName: 'Database Path',
16
+ type: 'string',
17
+ optional: true,
18
+ default: ':memory:',
19
+ },
20
+ {
21
+ name: 'workingDirectory',
22
+ displayName: 'Working Directory',
23
+ type: 'string',
24
+ optional: true,
25
+ // Binds to the project root (discovery ceiling) when the host has
26
+ // populated `config.rootDirectory`. Symmetric with the native
27
+ // DuckDB default — resolves to undefined in browser hosts that
28
+ // don't wire a `config` overlay, which is fine.
29
+ default: { config: 'rootDirectory' },
30
+ },
31
+ {
32
+ name: 'motherDuckToken',
33
+ displayName: 'MotherDuck Token',
34
+ type: 'secret',
35
+ optional: true,
36
+ },
37
+ {
38
+ name: 'setupSQL',
39
+ displayName: 'Setup SQL',
40
+ type: 'text',
41
+ optional: true,
42
+ description: 'SQL statements to run when the connection is established',
43
+ },
44
+ ],
45
+ });
46
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1,42 @@
1
+ import type { MalloyQueryData, PersistSQLResults, PooledConnection, QueryRecord, QueryOptionsReader, QueryRunStats, RunSQLOptions, StreamingConnection, StructDef, TestableConnection, SQLSourceDef, TableSourceDef, SQLSourceRequest } from '@malloydata/malloy';
2
+ import { BaseConnection } from '@malloydata/malloy/connection';
3
+ export interface DuckDBQueryOptions {
4
+ rowLimit: number;
5
+ }
6
+ export declare abstract class DuckDBCommon extends BaseConnection implements TestableConnection, PersistSQLResults, StreamingConnection {
7
+ protected queryOptions?: QueryOptionsReader | undefined;
8
+ protected isMotherDuck: boolean;
9
+ protected motherDuckToken: string | undefined;
10
+ protected setupSQL: string | undefined;
11
+ private readonly dialect;
12
+ static DEFAULT_QUERY_OPTIONS: DuckDBQueryOptions;
13
+ readonly name: string;
14
+ get dialectName(): string;
15
+ protected readQueryOptions(): DuckDBQueryOptions;
16
+ constructor(queryOptions?: QueryOptionsReader | undefined);
17
+ isPool(): this is PooledConnection;
18
+ canPersist(): this is PersistSQLResults;
19
+ abstract getDigest(): string;
20
+ protected abstract setup(): Promise<void>;
21
+ protected abstract runDuckDBQuery(sql: string): Promise<{
22
+ rows: QueryRecord[];
23
+ totalRows: number;
24
+ }>;
25
+ runRawSQL(sql: string): Promise<{
26
+ rows: QueryRecord[];
27
+ totalRows: number;
28
+ }>;
29
+ runSQL(sql: string, options?: RunSQLOptions): Promise<MalloyQueryData>;
30
+ abstract runSQLStream(sql: string, options: RunSQLOptions): AsyncIterableIterator<QueryRecord>;
31
+ fetchSelectSchema(sqlRef: SQLSourceRequest): Promise<SQLSourceDef | string>;
32
+ estimateQueryCost(_: string): Promise<QueryRunStats>;
33
+ fillStructDefFromTypeMap(structDef: StructDef, typeMap: {
34
+ [name: string]: string;
35
+ }): void;
36
+ private schemaFromQuery;
37
+ fetchTableSchema(tableKey: string, tablePath: string): Promise<TableSourceDef>;
38
+ canStream(): this is StreamingConnection;
39
+ test(): Promise<void>;
40
+ manifestTemporaryTable(sqlCommand: string): Promise<string>;
41
+ abstract close(): Promise<void>;
42
+ }