@observablehq/notebook-kit 2.5.4 → 2.5.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 +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/fileAttachment.js +4 -4
- package/dist/src/runtime/stdlib/index.d.ts +3 -0
- 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
|
|
@@ -118,8 +118,8 @@ export class AbstractFile {
|
|
|
118
118
|
});
|
|
119
119
|
}
|
|
120
120
|
async arrow() {
|
|
121
|
-
const [
|
|
122
|
-
return
|
|
121
|
+
const [Flechette, buffer] = await Promise.all([import("https://cdn.jsdelivr.net/npm/@uwdata/flechette/+esm"), this.arrayBuffer()]); // prettier-ignore
|
|
122
|
+
return Flechette.tableFromIPC(buffer, { useDate: true });
|
|
123
123
|
}
|
|
124
124
|
async arquero(options) {
|
|
125
125
|
let request;
|
|
@@ -156,8 +156,8 @@ export class AbstractFile {
|
|
|
156
156
|
return aq[from](body, options);
|
|
157
157
|
}
|
|
158
158
|
async parquet() {
|
|
159
|
-
const [
|
|
160
|
-
return
|
|
159
|
+
const [Flechette, Parquet, buffer] = await Promise.all([import("https://cdn.jsdelivr.net/npm/@uwdata/flechette/+esm"), import("https://cdn.jsdelivr.net/npm/parquet-wasm/+esm").then(async (Parquet) => (await Parquet.default("https://cdn.jsdelivr.net/npm/parquet-wasm/esm/parquet_wasm_bg.wasm"), Parquet)), this.arrayBuffer()]); // prettier-ignore
|
|
160
|
+
return Flechette.tableFromIPC(Parquet.readParquet(new Uint8Array(buffer)).intoIPCStream(), { useDate: true }); // prettier-ignore
|
|
161
161
|
}
|
|
162
162
|
async zip() {
|
|
163
163
|
const [{ ZipArchive }, buffer] = await Promise.all([import("./zip.js"), this.arrayBuffer()]);
|
|
@@ -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;
|