@observablehq/notebook-kit 2.5.3 → 2.5.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/javascript/template.js +5 -3
- package/dist/src/runtime/stdlib/databaseClient.d.ts +4 -0
- package/dist/src/runtime/stdlib/databaseClient.js +9 -0
- package/dist/src/runtime/stdlib/index.d.ts +3 -0
- package/dist/src/runtime/stdlib/md.js +4 -2
- package/package.json +1 -1
package/dist/package.json
CHANGED
|
@@ -123,9 +123,11 @@ function getPrefix(cell) {
|
|
|
123
123
|
}
|
|
124
124
|
function getDatabase(cell) {
|
|
125
125
|
const { id, database = "var:db", since } = cell;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
if (database.startsWith("var:")) {
|
|
127
|
+
const name = database.slice("var:".length);
|
|
128
|
+
return `(await DatabaseClient.of(${name}, ${JSON.stringify(name)}))`;
|
|
129
|
+
}
|
|
130
|
+
return `DatabaseClient(${JSON.stringify(database)}, {id: ${id}${since === undefined ? "" : `, since: ${JSON.stringify(since)}`}})`;
|
|
129
131
|
}
|
|
130
132
|
function getSqlPrefix(cell) {
|
|
131
133
|
return `${cell.hidden ? "" : cell.output ? "((_) => (display(Inputs.table(_)), _))(" : "Inputs.table("}await ${getDatabase(cell)}.sql`;
|
|
@@ -32,6 +32,7 @@ export interface DatabaseClient<T = QueryResult> {
|
|
|
32
32
|
}
|
|
33
33
|
export declare const DatabaseClient: {
|
|
34
34
|
(name: string, options?: QueryOptionsSpec): DatabaseClient;
|
|
35
|
+
of: typeof of;
|
|
35
36
|
revive: typeof revive;
|
|
36
37
|
prototype: DatabaseClientImpl;
|
|
37
38
|
};
|
|
@@ -42,5 +43,8 @@ declare class DatabaseClientImpl implements DatabaseClient {
|
|
|
42
43
|
sql<T = QueryResult>(strings: readonly string[], ...params: unknown[]): Promise<T>;
|
|
43
44
|
cachePath(strings: readonly string[], ...params: unknown[]): Promise<string>;
|
|
44
45
|
}
|
|
46
|
+
declare function of(source: unknown, name: string): Promise<{
|
|
47
|
+
sql: DatabaseClient["sql"];
|
|
48
|
+
}>;
|
|
45
49
|
declare function revive({ rows, schema, date, ...meta }: SerializableQueryResult): QueryResult;
|
|
46
50
|
export {};
|
|
@@ -40,6 +40,14 @@ class DatabaseClientImpl {
|
|
|
40
40
|
return `.observable/cache/${await nameHash(this.name)}-${await hash(strings, ...params)}.json`;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
async function of(source, name) {
|
|
44
|
+
return source != null &&
|
|
45
|
+
typeof source === "object" &&
|
|
46
|
+
"sql" in source &&
|
|
47
|
+
typeof source["sql"] === "function"
|
|
48
|
+
? source
|
|
49
|
+
: (await import("./duckdb.js")).DuckDBClient.of({ [name]: source });
|
|
50
|
+
}
|
|
43
51
|
function revive({ rows, schema, date, ...meta }) {
|
|
44
52
|
for (const column of schema) {
|
|
45
53
|
switch (column.type) {
|
|
@@ -72,6 +80,7 @@ function revive({ rows, schema, date, ...meta }) {
|
|
|
72
80
|
function asDate(value) {
|
|
73
81
|
return new Date(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?$/.test(value) ? value + "Z" : value);
|
|
74
82
|
}
|
|
83
|
+
DatabaseClient.of = of;
|
|
75
84
|
DatabaseClient.revive = revive;
|
|
76
85
|
DatabaseClient.prototype = DatabaseClientImpl.prototype; // instanceof
|
|
77
86
|
Object.defineProperty(DatabaseClientImpl, "name", { value: "DatabaseClient" }); // prevent mangling
|
|
@@ -52,6 +52,9 @@ export declare const library: {
|
|
|
52
52
|
width: () => ObservableAsyncGenerator<number>;
|
|
53
53
|
DatabaseClient: () => {
|
|
54
54
|
(name: string, options?: import("./databaseClient.js").QueryOptionsSpec): DatabaseClient;
|
|
55
|
+
of: (source: unknown, name: string) => Promise<{
|
|
56
|
+
sql: DatabaseClient["sql"];
|
|
57
|
+
}>;
|
|
55
58
|
revive: ({ rows, schema, date, ...meta }: import("../../databases/index.js").SerializableQueryResult) => import("./databaseClient.js").QueryResult;
|
|
56
59
|
prototype: {
|
|
57
60
|
readonly name: string;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { slugifyWithCounter } from "@sindresorhus/slugify";
|
|
2
2
|
import MarkdownIt from "markdown-it";
|
|
3
3
|
import MarkdownItAnchor from "markdown-it-anchor";
|
|
4
4
|
const mi = MarkdownIt({ html: true, linkify: true, typographer: true });
|
|
5
|
+
const slugify = slugifyWithCounter();
|
|
5
6
|
mi.use(MarkdownItAnchor, {
|
|
6
7
|
level: [2, 3],
|
|
7
|
-
slugify: (s) => slugify(s),
|
|
8
|
+
slugify: (s) => slugify(s).replace(/^(?=\d)/, "-"),
|
|
8
9
|
permalink: MarkdownItAnchor.permalink.headerLink({ class: "" })
|
|
9
10
|
});
|
|
10
11
|
export function MarkdownRenderer({ document = window.document } = {}) {
|
|
@@ -42,6 +43,7 @@ export function MarkdownRenderer({ document = window.document } = {}) {
|
|
|
42
43
|
source += template[i + 1];
|
|
43
44
|
}
|
|
44
45
|
// Render the text.
|
|
46
|
+
slugify.reset();
|
|
45
47
|
const root = document.createElement("div");
|
|
46
48
|
root.innerHTML = mi.render(source);
|
|
47
49
|
// Walk the rendered content to replace anchor placeholders.
|