@observablehq/notebook-kit 1.1.0-rc.8 → 1.1.0-rc.9

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": "1.1.0-rc.8",
8
+ "version": "1.1.0-rc.9",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "test": "vitest",
@@ -58,12 +58,12 @@ export declare class NotebookRuntime {
58
58
  width: () => AsyncGenerator<number, void, unknown>;
59
59
  DatabaseClient: () => {
60
60
  (name: string, options?: import("./stdlib/databaseClient.js").QueryOptionsSpec): import("./stdlib/databaseClient.js").DatabaseClient;
61
- hash: typeof import("../lib/hash.js").hash;
62
61
  revive: ({ rows, schema, date, ...meta }: import("../databases/index.js").SerializableQueryResult) => import("./stdlib/databaseClient.js").QueryResult;
63
62
  prototype: {
64
63
  readonly name: string;
65
64
  readonly options: import("./stdlib/databaseClient.js").QueryOptions;
66
65
  sql(strings: readonly string[], ...params: import("./stdlib/databaseClient.js").QueryParam[]): Promise<import("./stdlib/databaseClient.js").QueryResult>;
66
+ cachePath(strings: readonly string[], ...params: import("./stdlib/databaseClient.js").QueryParam[]): Promise<string>;
67
67
  };
68
68
  };
69
69
  FileAttachment: () => {
@@ -1,5 +1,4 @@
1
1
  import type { SerializableQueryResult } from "../../databases/index.js";
2
- import { hash } from "../../lib/hash.js";
3
2
  /** A serializable value that can be interpolated into a query. */
4
3
  export type QueryParam = any;
5
4
  /** @see https://observablehq.com/@observablehq/database-client-specification#%C2%A71 */
@@ -32,7 +31,6 @@ export interface DatabaseClient {
32
31
  }
33
32
  export declare const DatabaseClient: {
34
33
  (name: string, options?: QueryOptionsSpec): DatabaseClient;
35
- hash: typeof hash;
36
34
  revive: typeof revive;
37
35
  prototype: DatabaseClientImpl;
38
36
  };
@@ -41,6 +39,7 @@ declare class DatabaseClientImpl implements DatabaseClient {
41
39
  readonly options: QueryOptions;
42
40
  constructor(name: string, options: QueryOptions);
43
41
  sql(strings: readonly string[], ...params: QueryParam[]): Promise<QueryResult>;
42
+ cachePath(strings: readonly string[], ...params: QueryParam[]): Promise<string>;
44
43
  }
45
44
  declare function revive({ rows, schema, date, ...meta }: SerializableQueryResult): QueryResult;
46
45
  export {};
@@ -30,12 +30,15 @@ class DatabaseClientImpl {
30
30
  });
31
31
  }
32
32
  async sql(strings, ...params) {
33
- const path = `.observable/cache/${await nameHash(this.name)}-${await hash(strings, ...params)}.json`;
33
+ const path = await this.cachePath(strings, ...params);
34
34
  const response = await fetch(path);
35
35
  if (!response.ok)
36
36
  throw new Error(`failed to fetch: ${path}`);
37
37
  return await response.json().then(revive);
38
38
  }
39
+ async cachePath(strings, ...params) {
40
+ return `.observable/cache/${await nameHash(this.name)}-${await hash(strings, ...params)}.json`;
41
+ }
39
42
  }
40
43
  function revive({ rows, schema, date, ...meta }) {
41
44
  for (const column of schema) {
@@ -69,7 +72,6 @@ function revive({ rows, schema, date, ...meta }) {
69
72
  function asDate(value) {
70
73
  return new Date(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?$/.test(value) ? value + "Z" : value);
71
74
  }
72
- DatabaseClient.hash = hash;
73
75
  DatabaseClient.revive = revive;
74
76
  DatabaseClient.prototype = DatabaseClientImpl.prototype; // instanceof
75
77
  Object.defineProperty(DatabaseClientImpl, "name", { value: "DatabaseClient" }); // prevent mangling
@@ -48,12 +48,12 @@ export declare const library: {
48
48
  width: () => AsyncGenerator<number, void, unknown>;
49
49
  DatabaseClient: () => {
50
50
  (name: string, options?: import("./databaseClient.js").QueryOptionsSpec): DatabaseClient;
51
- hash: typeof import("../../lib/hash.js").hash;
52
51
  revive: ({ rows, schema, date, ...meta }: import("../../databases/index.js").SerializableQueryResult) => import("./databaseClient.js").QueryResult;
53
52
  prototype: {
54
53
  readonly name: string;
55
54
  readonly options: import("./databaseClient.js").QueryOptions;
56
55
  sql(strings: readonly string[], ...params: import("./databaseClient.js").QueryParam[]): Promise<import("./databaseClient.js").QueryResult>;
56
+ cachePath(strings: readonly string[], ...params: import("./databaseClient.js").QueryParam[]): Promise<string>;
57
57
  };
58
58
  };
59
59
  FileAttachment: () => {
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": "1.1.0-rc.8",
8
+ "version": "1.1.0-rc.9",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "test": "vitest",