@observablehq/notebook-kit 1.1.0-rc.4 → 1.1.0-rc.6

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.1.0-rc.4",
8
+ "version": "1.1.0-rc.6",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "test": "vitest",
@@ -1,2 +1,2 @@
1
1
  import type { DatabaseContext, DuckDBConfig, QueryTemplateFunction } from "./index.js";
2
- export default function duckdb(_options: DuckDBConfig, context: DatabaseContext): QueryTemplateFunction;
2
+ export default function duckdb({ path, options }: DuckDBConfig, context: DatabaseContext): QueryTemplateFunction;
@@ -1,8 +1,12 @@
1
- import { DuckDBConnection } from "@duckdb/node-api";
1
+ import { DuckDBConnection, DuckDBInstance } from "@duckdb/node-api";
2
2
  import { BIGINT, BIT, BLOB, BOOLEAN, DATE, DOUBLE, FLOAT, HUGEINT, INTEGER, INTERVAL, SMALLINT, TIME, TIMESTAMP, TIMESTAMP_MS, TIMESTAMP_NS, TIMESTAMP_S, TIMESTAMPTZ, TINYINT, UBIGINT, UHUGEINT, UINTEGER, USMALLINT, UTINYINT, UUID, VARCHAR, VARINT } from "@duckdb/node-api"; // prettier-ignore
3
- export default function duckdb(_options, context) {
3
+ import { join } from "node:path";
4
+ export default function duckdb({ path, options }, context) {
5
+ if (path !== undefined)
6
+ path = join(context.cwd, path);
4
7
  return async (strings, ...params) => {
5
- const connection = await DuckDBConnection.create();
8
+ const instance = await DuckDBInstance.create(path, options);
9
+ const connection = await DuckDBConnection.create(instance);
6
10
  await connection.run(`SET file_search_path=$0`, [context.cwd]);
7
11
  const date = new Date();
8
12
  let result;
@@ -13,6 +17,7 @@ export default function duckdb(_options, context) {
13
17
  }
14
18
  finally {
15
19
  connection.disconnectSync();
20
+ instance.closeSync();
16
21
  }
17
22
  return {
18
23
  rows,
@@ -2,6 +2,10 @@ import type { ColumnSchema, QueryParam } from "../runtime/index.js";
2
2
  export type DatabaseConfig = DuckDBConfig | SnowflakeConfig | PostgresConfig;
3
3
  export type DuckDBConfig = {
4
4
  type: "duckdb";
5
+ path?: string;
6
+ options?: {
7
+ [key: string]: string;
8
+ };
5
9
  };
6
10
  export type SnowflakeConfig = {
7
11
  type: "snowflake";
@@ -54,7 +54,7 @@ function revive({ rows, schema, date, ...meta }) {
54
54
  const value = row[name];
55
55
  if (value == null)
56
56
  continue;
57
- row[name] = BigInt(value);
57
+ row[name] = Number(value); // TODO BigInt?
58
58
  }
59
59
  break;
60
60
  }
@@ -54,7 +54,7 @@ export function observable({ window = new JSDOM().window, parser = new window.DO
54
54
  const template = parseTemplate(value);
55
55
  if (!template.expressions.length && !cell.output)
56
56
  statics.add(cell);
57
- const content = md([stripExpressions(template, value)]);
57
+ const content = md([unescapeDollarBackslashCurly(stripExpressions(template, value))]);
58
58
  const codes = content.querySelectorAll("code[class^=language-]");
59
59
  await Promise.all(Array.from(codes, highlight));
60
60
  div.appendChild(content);
@@ -197,6 +197,9 @@ function stripExpressions(template, input) {
197
197
  }
198
198
  return String(source);
199
199
  }
200
+ function unescapeDollarBackslashCurly(input) {
201
+ return input.replace(/(\$\\*)\\({)/g, "$1$2");
202
+ }
200
203
  /** Returns true if the specified character is preceded by an equals sign, ignoring whitespace. */
201
204
  function hasPrecedingEquals(input, index) {
202
205
  let i = index - 1;
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.1.0-rc.4",
8
+ "version": "1.1.0-rc.6",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "test": "vitest",