@run-trace/duckdb-wasm 0.5.1 → 0.5.2

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.
@@ -11,4 +11,99 @@ js-sha256/src/sha256.js:
11
11
  * @license MIT
12
12
  *)
13
13
  */
14
+ /*TRACE_XHR_HTTP_OPTIONS*/
15
+ (() => {
16
+ "use strict";
17
+ const cfg = () => { try { return self.__DUCKDB_HTTP__ || null; } catch (_e) { return null; } };
18
+ const resolve = (url) => {
19
+ try { return new URL(String(url), self.location && self.location.href).href; }
20
+ catch (_e) { return String(url); }
21
+ };
22
+ const wantsCredentials = (c, url) =>
23
+ !!c && (c.withCredentials === true ||
24
+ (Array.isArray(c.withCredentials) && c.withCredentials.some((p) => url.startsWith(p))));
25
+
26
+ if (typeof XMLHttpRequest !== "undefined" && XMLHttpRequest.prototype && !XMLHttpRequest.prototype.__trace_http_options__) {
27
+ const proto = XMLHttpRequest.prototype;
28
+ proto.__trace_http_options__ = true;
29
+ const origOpen = proto.open;
30
+ proto.open = function (method, url, ...rest) {
31
+ const result = origOpen.call(this, method, url, ...rest);
32
+ try {
33
+ const abs = resolve(url);
34
+ this.__trace_url__ = abs;
35
+ if (wantsCredentials(cfg(), abs)) this.withCredentials = true;
36
+ } catch (_e) {}
37
+ return result;
38
+ };
39
+ const origSend = proto.send;
40
+ proto.send = function (...args) {
41
+ try {
42
+ const c = cfg();
43
+ const url = this.__trace_url__;
44
+ if (c && c.headers && typeof url === "string") {
45
+ for (const prefix of Object.keys(c.headers)) {
46
+ if (url.startsWith(prefix)) {
47
+ const hs = c.headers[prefix];
48
+ for (const name of Object.keys(hs)) {
49
+ try { this.setRequestHeader(name, String(hs[name])); } catch (_e) {}
50
+ }
51
+ }
52
+ }
53
+ }
54
+ } catch (_e) {}
55
+ return origSend.apply(this, args);
56
+ };
57
+ }
58
+
59
+ // Pthreads spawned AFTER the config is known get it injected at spawn time
60
+ // via a bootstrap blob; the registry lets OPEN re-broadcast to pthreads
61
+ // spawned BEFORE (Emscripten preallocates the pool during instantiate()).
62
+ const spawned = new Set();
63
+ if (typeof Worker !== "undefined" && !Worker.__trace_http_options__) {
64
+ const NativeWorker = Worker;
65
+ class TraceWorker extends NativeWorker {
66
+ constructor(url, opts) {
67
+ let target = url;
68
+ try {
69
+ const c = cfg();
70
+ if (c && !(opts && opts.type === "module")) {
71
+ const boot = "self.__DUCKDB_HTTP__=" + JSON.stringify(c) + ";importScripts(" + JSON.stringify(resolve(url)) + ");";
72
+ target = URL.createObjectURL(new Blob([boot], { type: "text/javascript" }));
73
+ }
74
+ } catch (_e) { target = url; }
75
+ super(target, opts);
76
+ try { spawned.add(this); } catch (_e) {}
77
+ }
78
+ }
79
+ TraceWorker.__trace_http_options__ = true;
80
+ self.Worker = TraceWorker;
81
+ }
82
+
83
+ // Both worker targets assign globalThis.onmessage during script evaluation,
84
+ // which has already happened by the time this appended shim runs — so wrap
85
+ // the registered handler.
86
+ // - main DB worker: lift "http" off the OPEN request's config and forward
87
+ // it to running pthreads (observation only; the message continues on and
88
+ // the C++ config parser ignores the extra key).
89
+ // - pthread worker: consume the {cmd:"__duckdb_http__"} broadcast so it
90
+ // never reaches the Emscripten pthread handler.
91
+ const prev = globalThis.onmessage;
92
+ if (typeof prev === "function" && !prev.__trace_http_options__) {
93
+ const wrapped = function (e) {
94
+ try {
95
+ const d = e && e.data;
96
+ if (d && d.cmd === "__duckdb_http__") { self.__DUCKDB_HTTP__ = d.http; return; }
97
+ if (d && d.type === "OPEN" && d.data && typeof d.data === "object" && d.data.http) {
98
+ self.__DUCKDB_HTTP__ = d.data.http;
99
+ for (const w of spawned) { try { w.postMessage({ cmd: "__duckdb_http__", http: d.data.http }); } catch (_e) {} }
100
+ }
101
+ } catch (_e) {}
102
+ return prev.call(this, e);
103
+ };
104
+ wrapped.__trace_http_options__ = true;
105
+ globalThis.onmessage = wrapped;
106
+ }
107
+ })();
108
+
14
109
  //# sourceMappingURL=duckdb-browser-coi.pthread.worker.js.map
@@ -11,4 +11,99 @@ js-sha256/src/sha256.js:
11
11
  * @license MIT
12
12
  *)
13
13
  */
14
+ /*TRACE_XHR_HTTP_OPTIONS*/
15
+ (() => {
16
+ "use strict";
17
+ const cfg = () => { try { return self.__DUCKDB_HTTP__ || null; } catch (_e) { return null; } };
18
+ const resolve = (url) => {
19
+ try { return new URL(String(url), self.location && self.location.href).href; }
20
+ catch (_e) { return String(url); }
21
+ };
22
+ const wantsCredentials = (c, url) =>
23
+ !!c && (c.withCredentials === true ||
24
+ (Array.isArray(c.withCredentials) && c.withCredentials.some((p) => url.startsWith(p))));
25
+
26
+ if (typeof XMLHttpRequest !== "undefined" && XMLHttpRequest.prototype && !XMLHttpRequest.prototype.__trace_http_options__) {
27
+ const proto = XMLHttpRequest.prototype;
28
+ proto.__trace_http_options__ = true;
29
+ const origOpen = proto.open;
30
+ proto.open = function (method, url, ...rest) {
31
+ const result = origOpen.call(this, method, url, ...rest);
32
+ try {
33
+ const abs = resolve(url);
34
+ this.__trace_url__ = abs;
35
+ if (wantsCredentials(cfg(), abs)) this.withCredentials = true;
36
+ } catch (_e) {}
37
+ return result;
38
+ };
39
+ const origSend = proto.send;
40
+ proto.send = function (...args) {
41
+ try {
42
+ const c = cfg();
43
+ const url = this.__trace_url__;
44
+ if (c && c.headers && typeof url === "string") {
45
+ for (const prefix of Object.keys(c.headers)) {
46
+ if (url.startsWith(prefix)) {
47
+ const hs = c.headers[prefix];
48
+ for (const name of Object.keys(hs)) {
49
+ try { this.setRequestHeader(name, String(hs[name])); } catch (_e) {}
50
+ }
51
+ }
52
+ }
53
+ }
54
+ } catch (_e) {}
55
+ return origSend.apply(this, args);
56
+ };
57
+ }
58
+
59
+ // Pthreads spawned AFTER the config is known get it injected at spawn time
60
+ // via a bootstrap blob; the registry lets OPEN re-broadcast to pthreads
61
+ // spawned BEFORE (Emscripten preallocates the pool during instantiate()).
62
+ const spawned = new Set();
63
+ if (typeof Worker !== "undefined" && !Worker.__trace_http_options__) {
64
+ const NativeWorker = Worker;
65
+ class TraceWorker extends NativeWorker {
66
+ constructor(url, opts) {
67
+ let target = url;
68
+ try {
69
+ const c = cfg();
70
+ if (c && !(opts && opts.type === "module")) {
71
+ const boot = "self.__DUCKDB_HTTP__=" + JSON.stringify(c) + ";importScripts(" + JSON.stringify(resolve(url)) + ");";
72
+ target = URL.createObjectURL(new Blob([boot], { type: "text/javascript" }));
73
+ }
74
+ } catch (_e) { target = url; }
75
+ super(target, opts);
76
+ try { spawned.add(this); } catch (_e) {}
77
+ }
78
+ }
79
+ TraceWorker.__trace_http_options__ = true;
80
+ self.Worker = TraceWorker;
81
+ }
82
+
83
+ // Both worker targets assign globalThis.onmessage during script evaluation,
84
+ // which has already happened by the time this appended shim runs — so wrap
85
+ // the registered handler.
86
+ // - main DB worker: lift "http" off the OPEN request's config and forward
87
+ // it to running pthreads (observation only; the message continues on and
88
+ // the C++ config parser ignores the extra key).
89
+ // - pthread worker: consume the {cmd:"__duckdb_http__"} broadcast so it
90
+ // never reaches the Emscripten pthread handler.
91
+ const prev = globalThis.onmessage;
92
+ if (typeof prev === "function" && !prev.__trace_http_options__) {
93
+ const wrapped = function (e) {
94
+ try {
95
+ const d = e && e.data;
96
+ if (d && d.cmd === "__duckdb_http__") { self.__DUCKDB_HTTP__ = d.http; return; }
97
+ if (d && d.type === "OPEN" && d.data && typeof d.data === "object" && d.data.http) {
98
+ self.__DUCKDB_HTTP__ = d.data.http;
99
+ for (const w of spawned) { try { w.postMessage({ cmd: "__duckdb_http__", http: d.data.http }); } catch (_e) {} }
100
+ }
101
+ } catch (_e) {}
102
+ return prev.call(this, e);
103
+ };
104
+ wrapped.__trace_http_options__ = true;
105
+ globalThis.onmessage = wrapped;
106
+ }
107
+ })();
108
+
14
109
  //# sourceMappingURL=duckdb-browser-coi.worker.js.map
@@ -45,7 +45,28 @@ export declare enum DuckDBAccessMode {
45
45
  READ_ONLY = 2,
46
46
  READ_WRITE = 3
47
47
  }
48
+ export interface DuckDBHTTPConfig {
49
+ /**
50
+ * Send cookies (credentialed CORS) with engine HTTP requests.
51
+ * true = all URLs; string[] = URL-prefix allowlist.
52
+ * Cross-origin servers must respond with Access-Control-Allow-Origin set
53
+ * to the exact page origin (not "*") and
54
+ * Access-Control-Allow-Credentials: true.
55
+ */
56
+ withCredentials?: boolean | string[];
57
+ /**
58
+ * Extra request headers, keyed by URL prefix. Applied to every engine
59
+ * HTTP request (quack, read_parquet('https://...'), ...) whose absolute
60
+ * URL starts with the prefix. Headers are appended, not replaced.
61
+ */
62
+ headers?: Record<string, Record<string, string>>;
63
+ }
48
64
  export interface DuckDBConfig {
65
+ /**
66
+ * HTTP options for engine requests (cookies via withCredentials, extra
67
+ * headers). Handled by the trace XHR shim in the browser worker bundles.
68
+ */
69
+ http?: DuckDBHTTPConfig;
49
70
  /**
50
71
  * The database path
51
72
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@run-trace/duckdb-wasm",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "DuckDB powered by WebAssembly — Trace fork with bundled extensions",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -70,7 +70,7 @@
70
70
  "test:node:coverage": "nyc -r json --report-dir ./coverage/node node ../../node_modules/jasmine/bin/jasmine ./dist/tests-node.cjs",
71
71
  "test:firefox": "karma start ./karma/tests-firefox.cjs",
72
72
  "test:chrome": "karma start ./karma/tests-chrome.cjs",
73
- "test:chrome:eh": "karma start ./karma/tests-chrome-eh.cjs",
73
+ "test:chrome:eh": "karma start ./karma/tests-chrome-eh.cjs",
74
74
  "test:chrome:coverage": "karma start ./karma/tests-chrome-coverage.cjs",
75
75
  "test:browser": "karma start ./karma/tests-all.cjs",
76
76
  "test:browser:debug": "karma start ./karma/tests-debug.cjs",