@observablehq/notebook-kit 1.7.2 → 1.7.4

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.2",
8
+ "version": "1.7.4",
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
@@ -21,7 +21,7 @@ function resolve(_specifier) {
21
21
  if (isProtocol(specifier) || isLocal(specifier))
22
22
  return specifier;
23
23
  const { name, range, path } = parseNpmSpecifier(specifier);
24
- return `https://cdn.jsdelivr.net/npm/${name}${range}${path + (isFile(path) || isDirectory(path) ? "" : "/+esm")}`;
24
+ return `https://cdn.jsdelivr.net/npm/${name}${range}${path + ((isFile(path) && !isJavaScript(path)) || isDirectory(path) ? "" : "/+esm")}`;
25
25
  }
26
26
  /** Promote exclusive default export to module. */
27
27
  function defaultify(module) {
@@ -46,10 +46,14 @@ function isLocal(specifier) {
46
46
  return /^(\.\/|\.\.\/|\/)/.test(specifier);
47
47
  }
48
48
  /** Returns true for e.g. foo/bar.js */
49
+ function isJavaScript(specifier) {
50
+ return /\.js$/i.test(specifier);
51
+ }
52
+ /** Returns true for e.g. foo/bar.txt */
49
53
  function isFile(specifier) {
50
- return /(\.\w*)$/.test(specifier);
54
+ return /\.\w*$/.test(specifier);
51
55
  }
52
56
  /** Returns true for e.g. foo/bar/ */
53
57
  function isDirectory(specifier) {
54
- return /(\/)$/.test(specifier);
58
+ return /\/$/.test(specifier);
55
59
  }
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.2",
8
+ "version": "1.7.4",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "test": "vitest",