@observablehq/notebook-kit 2.5.4 → 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 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.5.4",
8
+ "version": "2.5.5",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "test": "TZ=America/Los_Angeles vitest",
@@ -123,9 +123,11 @@ function getPrefix(cell) {
123
123
  }
124
124
  function getDatabase(cell) {
125
125
  const { id, database = "var:db", since } = cell;
126
- return database.startsWith("var:")
127
- ? database.slice("var:".length)
128
- : `DatabaseClient(${JSON.stringify(database)}, {id: ${id}${since === undefined ? "" : `, since: ${JSON.stringify(since)}`}})`;
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;
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.5.4",
8
+ "version": "2.5.5",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "test": "TZ=America/Los_Angeles vitest",