@observablehq/notebook-kit 2.6.6 → 2.7.0
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 +5 -1
- package/dist/src/runtime/index.d.ts +0 -1
- package/dist/src/runtime/index.js +0 -1
- package/dist/src/runtime/stdlib/duckdb.d.ts +2 -2
- package/dist/src/runtime/stdlib/duckdb.js +4 -2
- package/dist/src/runtime/stdlib/index.d.ts +1 -2
- package/dist/src/runtime/stdlib/index.js +0 -2
- package/dist/src/runtime/stdlib/recommendedLibraries.d.ts +1 -0
- package/dist/src/runtime/stdlib/recommendedLibraries.js +1 -0
- package/dist/src/runtime/stdlib/sql.d.ts +1 -1
- package/dist/src/runtime/stdlib/sql.js +45 -20
- package/package.json +5 -1
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": "2.
|
|
8
|
+
"version": "2.7.0",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "TZ=America/Los_Angeles vitest",
|
|
@@ -35,6 +35,10 @@
|
|
|
35
35
|
"types": "./dist/src/runtime/index.d.ts",
|
|
36
36
|
"import": "./dist/src/runtime/index.js"
|
|
37
37
|
},
|
|
38
|
+
"./sql": {
|
|
39
|
+
"types": "./dist/src/runtime/stdlib/sql.d.ts",
|
|
40
|
+
"import": "./dist/src/runtime/stdlib/sql.js"
|
|
41
|
+
},
|
|
38
42
|
"./vite": {
|
|
39
43
|
"types": "./dist/src/vite/index.d.ts",
|
|
40
44
|
"import": "./dist/src/vite/index.js"
|
|
@@ -13,7 +13,6 @@ export type * from "./stdlib/fileAttachment.js";
|
|
|
13
13
|
export { FileAttachment, requireFileRegistration, registerFile } from "./stdlib/fileAttachment.js";
|
|
14
14
|
export type * from "./stdlib/interpreter.js";
|
|
15
15
|
export { Interpreter } from "./stdlib/interpreter.js";
|
|
16
|
-
export { sql } from "./stdlib/sql.js";
|
|
17
16
|
export declare class NotebookRuntime {
|
|
18
17
|
readonly runtime: Runtime & {
|
|
19
18
|
fileAttachments: typeof fileAttachments;
|
|
@@ -8,7 +8,6 @@ export * from "./stdlib/index.js";
|
|
|
8
8
|
export { DatabaseClient } from "./stdlib/databaseClient.js";
|
|
9
9
|
export { FileAttachment, requireFileRegistration, registerFile } from "./stdlib/fileAttachment.js";
|
|
10
10
|
export { Interpreter } from "./stdlib/interpreter.js";
|
|
11
|
-
export { sql } from "./stdlib/sql.js";
|
|
12
11
|
export class NotebookRuntime {
|
|
13
12
|
constructor(builtins = library) {
|
|
14
13
|
Object.defineProperty(this, "runtime", {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export class DuckDBClient {
|
|
2
2
|
static of(sources?: {}, config?: {}): Promise<DuckDBClient>;
|
|
3
|
-
static sql(...args: any[]): Promise<(strings: any, ...
|
|
3
|
+
static sql(...args: any[]): Promise<(strings: any, ...params: any[]) => Promise<any>>;
|
|
4
4
|
constructor(db: any);
|
|
5
5
|
queryStream(query: any, params: any): Promise<{
|
|
6
6
|
schema: any;
|
|
@@ -8,7 +8,7 @@ export class DuckDBClient {
|
|
|
8
8
|
}>;
|
|
9
9
|
query(query: any, params: any): Promise<any>;
|
|
10
10
|
queryRow(query: any, params: any): Promise<any>;
|
|
11
|
-
sql(strings: any, ...
|
|
11
|
+
sql(strings: any, ...params: any[]): Promise<any>;
|
|
12
12
|
queryTag(strings: any, ...params: any[]): any[];
|
|
13
13
|
escape(name: any): string;
|
|
14
14
|
describeTables(): Promise<{
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as duckdb from "https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.32.0/+esm";
|
|
2
|
+
import { sql } from "./sql.js";
|
|
2
3
|
// Adapted from https://observablehq.com/@cmudig/duckdb-client
|
|
3
4
|
// Copyright 2021 CMU Data Interaction Group
|
|
4
5
|
//
|
|
@@ -132,8 +133,9 @@ export class DuckDBClient {
|
|
|
132
133
|
await reader.return();
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
|
-
async sql(strings, ...
|
|
136
|
-
|
|
136
|
+
async sql(strings, ...params) {
|
|
137
|
+
({ strings, params } = sql.call(null, strings, ...params).flat(this.dialect));
|
|
138
|
+
return await this.query(strings.join("?"), params);
|
|
137
139
|
}
|
|
138
140
|
queryTag(strings, ...params) {
|
|
139
141
|
return [strings.join("?"), params];
|
|
@@ -6,7 +6,6 @@ import * as Generators from "./generators/index.js";
|
|
|
6
6
|
import { Interpreter } from "./interpreter.js";
|
|
7
7
|
import { Mutable } from "./mutable.js";
|
|
8
8
|
import * as Promises from "./promises/index.js";
|
|
9
|
-
import { sql } from "./sql.js";
|
|
10
9
|
export declare const root: HTMLElement;
|
|
11
10
|
export declare const library: {
|
|
12
11
|
aapl: () => Promise<any>;
|
|
@@ -41,6 +40,7 @@ export declare const library: {
|
|
|
41
40
|
Plot: () => Promise<any>;
|
|
42
41
|
React: () => Promise<any>;
|
|
43
42
|
ReactDOM: () => Promise<any>;
|
|
43
|
+
sql: () => Promise<typeof import("./sql.js").sql>;
|
|
44
44
|
tex: () => Promise<import("./template.js").RawTemplateRenderer & {
|
|
45
45
|
options: (options?: any) => import("./template.js").RawTemplateRenderer;
|
|
46
46
|
block: import("./template.js").RawTemplateRenderer;
|
|
@@ -104,5 +104,4 @@ export declare const library: {
|
|
|
104
104
|
Promises: () => typeof Promises;
|
|
105
105
|
Files: () => typeof Files;
|
|
106
106
|
DOM: () => typeof DOM;
|
|
107
|
-
sql: () => typeof sql;
|
|
108
107
|
};
|
|
@@ -8,7 +8,6 @@ import { Mutable } from "./mutable.js";
|
|
|
8
8
|
import * as Promises from "./promises/index.js";
|
|
9
9
|
import * as recommendedLibraries from "./recommendedLibraries.js";
|
|
10
10
|
import * as sampleDatasets from "./sampleDatasets.js";
|
|
11
|
-
import { sql } from "./sql.js";
|
|
12
11
|
export const root = document.querySelector("main") ?? document.body;
|
|
13
12
|
export const library = {
|
|
14
13
|
dark: () => Generators.dark(),
|
|
@@ -22,7 +21,6 @@ export const library = {
|
|
|
22
21
|
Promises: () => Promises, // deprecated!
|
|
23
22
|
Files: () => Files, // deprecated!
|
|
24
23
|
DOM: () => DOM, // deprecated!
|
|
25
|
-
sql: () => sql,
|
|
26
24
|
...recommendedLibraries,
|
|
27
25
|
...sampleDatasets
|
|
28
26
|
};
|
|
@@ -18,6 +18,7 @@ export declare const mermaid: () => Promise<import("./template.js").AsyncRawTemp
|
|
|
18
18
|
export declare const Plot: () => Promise<any>;
|
|
19
19
|
export declare const React: () => Promise<any>;
|
|
20
20
|
export declare const ReactDOM: () => Promise<any>;
|
|
21
|
+
export declare const sql: () => Promise<typeof import("./sql.js").sql>;
|
|
21
22
|
export declare const tex: () => Promise<import("./template.js").RawTemplateRenderer & {
|
|
22
23
|
options: (options?: any) => import("./template.js").RawTemplateRenderer;
|
|
23
24
|
block: import("./template.js").RawTemplateRenderer;
|
|
@@ -18,6 +18,7 @@ export const mermaid = () => import("./mermaid.js").then((_) => _.mermaid);
|
|
|
18
18
|
export const Plot = () => import("https://cdn.jsdelivr.net/npm/@observablehq/plot/+esm");
|
|
19
19
|
export const React = () => import("https://cdn.jsdelivr.net/npm/react/+esm");
|
|
20
20
|
export const ReactDOM = () => import("https://cdn.jsdelivr.net/npm/react-dom/+esm");
|
|
21
|
+
export const sql = () => import("./sql.js").then((_) => _.sql);
|
|
21
22
|
// export const SQLite = () => import("observablehq:stdlib/sqlite").then((_) => _.default);
|
|
22
23
|
// export const SQLiteDatabaseClient = () => import("observablehq:stdlib/sqlite").then((_) => _.SQLiteDatabaseClient);
|
|
23
24
|
export const tex = () => import("./tex.js").then((_) => _.tex);
|
|
@@ -8,7 +8,7 @@ export declare namespace sql {
|
|
|
8
8
|
var view: (strings: readonly string[], ...params: unknown[]) => SqlView;
|
|
9
9
|
var variant: (variants: Partial<Record<SqlDialect | "default", unknown>>) => SqlVariant;
|
|
10
10
|
var ident: (name: string) => SqlVariant;
|
|
11
|
-
var text: (value: string) =>
|
|
11
|
+
var text: (value: string) => SqlVariant;
|
|
12
12
|
var Fragment: typeof SqlFragment;
|
|
13
13
|
var View: typeof SqlView;
|
|
14
14
|
var Variant: typeof SqlVariant;
|
|
@@ -8,20 +8,10 @@ sql.variant = function variant(variants) {
|
|
|
8
8
|
return new SqlVariant(variants);
|
|
9
9
|
};
|
|
10
10
|
sql.ident = function ident(name) {
|
|
11
|
-
return
|
|
12
|
-
get databricks() {
|
|
13
|
-
return sql([tquote(name)]);
|
|
14
|
-
},
|
|
15
|
-
get bigquery() {
|
|
16
|
-
return sql([tquote(name)]);
|
|
17
|
-
},
|
|
18
|
-
get default() {
|
|
19
|
-
return sql([dquote(name)]);
|
|
20
|
-
}
|
|
21
|
-
});
|
|
11
|
+
return quoted(name, iquotes);
|
|
22
12
|
};
|
|
23
13
|
sql.text = function text(value) {
|
|
24
|
-
return
|
|
14
|
+
return quoted(value, squotes);
|
|
25
15
|
};
|
|
26
16
|
class SqlFragment {
|
|
27
17
|
constructor(strings, params) {
|
|
@@ -155,6 +145,10 @@ class SqlVariant {
|
|
|
155
145
|
return String(this.toDialect());
|
|
156
146
|
}
|
|
157
147
|
}
|
|
148
|
+
// prevent mangling
|
|
149
|
+
Object.defineProperty(SqlFragment, "name", { value: "SqlFragment" });
|
|
150
|
+
Object.defineProperty(SqlView, "name", { value: "SqlView" });
|
|
151
|
+
Object.defineProperty(SqlVariant, "name", { value: "SqlVariant" });
|
|
158
152
|
sql.Fragment = SqlFragment;
|
|
159
153
|
sql.View = SqlView;
|
|
160
154
|
sql.Variant = SqlVariant;
|
|
@@ -270,15 +264,30 @@ function findUndernames(strings, params, names = new Set()) {
|
|
|
270
264
|
}
|
|
271
265
|
return names;
|
|
272
266
|
}
|
|
267
|
+
/** Identifier quoting, by dialect. */
|
|
268
|
+
const iquotes = new Map([
|
|
269
|
+
["bigquery", btquote],
|
|
270
|
+
["databricks", tquote],
|
|
271
|
+
["mssql", brquote],
|
|
272
|
+
["mysql", tquote],
|
|
273
|
+
["default", dquote]
|
|
274
|
+
]);
|
|
275
|
+
/** String literal quoting, by dialect. */
|
|
276
|
+
const squotes = new Map([
|
|
277
|
+
["bigquery", bsquote],
|
|
278
|
+
["databricks", bsquote],
|
|
279
|
+
["mssql", (value) => `N${squote(value.replace(/\\(?=\r?\n)/g, "\\\\\n"))}`],
|
|
280
|
+
["mysql", (value) => squote(value.replace(/\\/g, "\\\\"))],
|
|
281
|
+
["snowflake", bsquote],
|
|
282
|
+
["default", squote]
|
|
283
|
+
]);
|
|
284
|
+
/** Returns a variant of the specified value quoted for each dialect. */
|
|
285
|
+
function quoted(value, quotes) {
|
|
286
|
+
return new SqlVariant(Object.fromEntries(Array.from(quotes, ([d, q]) => [d, sql([q(value)])])));
|
|
287
|
+
}
|
|
273
288
|
/** Quotes the specified SQL identifier. */
|
|
274
|
-
function getIquote(dialect) {
|
|
275
|
-
|
|
276
|
-
case "databricks":
|
|
277
|
-
case "bigquery":
|
|
278
|
-
return tquote;
|
|
279
|
-
default:
|
|
280
|
-
return dquote;
|
|
281
|
-
}
|
|
289
|
+
function getIquote(dialect = "default") {
|
|
290
|
+
return iquotes.get(dialect) ?? iquotes.get("default");
|
|
282
291
|
}
|
|
283
292
|
/** Quotes the specified name with double quotes. */
|
|
284
293
|
function dquote(name) {
|
|
@@ -288,7 +297,23 @@ function dquote(name) {
|
|
|
288
297
|
function tquote(name) {
|
|
289
298
|
return `\`${name.replace(/`/g, "``")}\``;
|
|
290
299
|
}
|
|
300
|
+
/** Quotes the specified name with square brackets. */
|
|
301
|
+
function brquote(name) {
|
|
302
|
+
return `[${name.replace(/]/g, "]]")}]`;
|
|
303
|
+
}
|
|
304
|
+
/** Quotes the specified name with backticks, escaping with backslashes. */
|
|
305
|
+
function btquote(name) {
|
|
306
|
+
return `\`${name.replace(/[\\`\n\r]/g, bescape)}\``;
|
|
307
|
+
}
|
|
291
308
|
/** Quotes the specified name with single quotes. */
|
|
292
309
|
function squote(name) {
|
|
293
310
|
return `'${name.replace(/'/g, "''")}'`;
|
|
294
311
|
}
|
|
312
|
+
/** Quotes the specified value with single quotes, escaping with backslashes. */
|
|
313
|
+
function bsquote(name) {
|
|
314
|
+
return `'${name.replace(/[\\'\n\r]/g, bescape)}'`;
|
|
315
|
+
}
|
|
316
|
+
/** Escapes the specified character with a backslash. */
|
|
317
|
+
function bescape(char) {
|
|
318
|
+
return char === "\n" ? "\\n" : char === "\r" ? "\\r" : `\\${char}`;
|
|
319
|
+
}
|
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": "2.
|
|
8
|
+
"version": "2.7.0",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "TZ=America/Los_Angeles vitest",
|
|
@@ -35,6 +35,10 @@
|
|
|
35
35
|
"types": "./dist/src/runtime/index.d.ts",
|
|
36
36
|
"import": "./dist/src/runtime/index.js"
|
|
37
37
|
},
|
|
38
|
+
"./sql": {
|
|
39
|
+
"types": "./dist/src/runtime/stdlib/sql.d.ts",
|
|
40
|
+
"import": "./dist/src/runtime/stdlib/sql.js"
|
|
41
|
+
},
|
|
38
42
|
"./vite": {
|
|
39
43
|
"types": "./dist/src/vite/index.d.ts",
|
|
40
44
|
"import": "./dist/src/vite/index.js"
|