@observablehq/notebook-kit 1.1.0-rc.3 → 1.1.0-rc.5
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 +1 -1
- package/dist/src/databases/duckdb.d.ts +1 -1
- package/dist/src/databases/duckdb.js +9 -4
- package/dist/src/databases/index.d.ts +4 -0
- package/dist/src/databases/postgres.js +1 -1
- package/dist/src/vite/config.js +1 -1
- package/dist/src/vite/observable.js +4 -1
- package/package.json +1 -1
package/dist/package.json
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { DatabaseContext, DuckDBConfig, QueryTemplateFunction } from "./index.js";
|
|
2
|
-
export default function duckdb(
|
|
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
|
-
|
|
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
|
|
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,
|
|
@@ -42,7 +47,7 @@ function getColumnType(type) {
|
|
|
42
47
|
case UBIGINT:
|
|
43
48
|
case HUGEINT:
|
|
44
49
|
case UHUGEINT:
|
|
45
|
-
return "
|
|
50
|
+
return "integer"; // TODO bigint?
|
|
46
51
|
case FLOAT:
|
|
47
52
|
case DOUBLE:
|
|
48
53
|
return "number";
|
|
@@ -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";
|
package/dist/src/vite/config.js
CHANGED
|
@@ -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;
|