@observablehq/notebook-kit 1.7.1 → 1.7.3

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/dist/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/observablehq/notebook-kit.git"
7
7
  },
8
- "version": "1.7.1",
8
+ "version": "1.7.3",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "test": "vitest",
@@ -39,6 +39,10 @@ const bundles = {
39
39
  };
40
40
  const bundle = duckdb.selectBundle(bundles);
41
41
  const logger = new duckdb.ConsoleLogger(duckdb.LogLevel.WARNING);
42
+ const mainWorkerUrl = bundle.then(({ mainWorker }) => {
43
+ const source = `importScripts(${JSON.stringify(mainWorker)});`;
44
+ return URL.createObjectURL(new Blob([source], { type: "text/javascript" }));
45
+ });
42
46
  // let db;
43
47
  // let inserts = [];
44
48
  // const sources = new Map();
@@ -316,10 +320,9 @@ async function insertArray(database, name, array, options) {
316
320
  return await insertArrowTable(database, name, table, options);
317
321
  }
318
322
  async function createDuckDB() {
319
- const { mainWorker, mainModule } = await bundle;
320
- const worker = await duckdb.createWorker(mainWorker);
323
+ const worker = new Worker(await mainWorkerUrl);
321
324
  const db = new duckdb.AsyncDuckDB(logger, worker);
322
- await db.instantiate(mainModule);
325
+ await db.instantiate((await bundle).mainModule);
323
326
  return db;
324
327
  }
325
328
  // https://duckdb.org/docs/sql/data_types/overview
@@ -23,11 +23,18 @@ function resolve(_specifier) {
23
23
  const { name, range, path } = parseNpmSpecifier(specifier);
24
24
  return `https://cdn.jsdelivr.net/npm/${name}${range}${path + (isFile(path) || isDirectory(path) ? "" : "/+esm")}`;
25
25
  }
26
+ /** Promote exclusive default export to module. */
27
+ function defaultify(module) {
28
+ for (const key in module)
29
+ if (key !== "default")
30
+ return { ...module }; // any named export
31
+ return "default" in module ? module.default : { ...module }; // promote exclusive default export
32
+ }
26
33
  /** Allow mutation of required modules while maintaining a canonical instance; ugly! */
27
34
  function objectify(module) {
28
35
  let object = cache.get(module);
29
36
  if (!object)
30
- cache.set(module, (object = { ...module }));
37
+ cache.set(module, (object = defaultify(module)));
31
38
  return object;
32
39
  }
33
40
  /** Returns true for e.g. https://example.com/ */
@@ -17,5 +17,6 @@ declare class ZipArchiveEntry extends AbstractFile {
17
17
  arrayBuffer(): Promise<ArrayBuffer>;
18
18
  text(): Promise<string>;
19
19
  json(): Promise<any>;
20
+ stream(): Promise<ReadableStream<Uint8Array>>;
20
21
  }
21
22
  export {};
@@ -19,7 +19,7 @@ export class ZipArchive {
19
19
  }
20
20
  class ZipArchiveEntry extends AbstractFile {
21
21
  constructor(object) {
22
- super(undefined, object.name);
22
+ super(object.name);
23
23
  Object.defineProperty(this, "href", {
24
24
  enumerable: true,
25
25
  configurable: true,
@@ -46,6 +46,9 @@ class ZipArchiveEntry extends AbstractFile {
46
46
  async json() {
47
47
  return JSON.parse(await this.text());
48
48
  }
49
+ async stream() {
50
+ return (await this.blob()).stream(); // since href is unavailable
51
+ }
49
52
  }
50
53
  Object.defineProperty(ZipArchive, "name", { value: "ZipArchive" }); // prevent mangling
51
54
  Object.defineProperty(ZipArchiveEntry, "name", { value: "ZipArchiveEntry" }); // prevent mangling
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/observablehq/notebook-kit.git"
7
7
  },
8
- "version": "1.7.1",
8
+ "version": "1.7.3",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "test": "vitest",