@observablehq/notebook-kit 1.2.0-rc.1 → 1.2.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/bin/query.js CHANGED
@@ -17,7 +17,8 @@ export default async function run(args) {
17
17
  default: "."
18
18
  },
19
19
  database: {
20
- type: "string"
20
+ type: "string",
21
+ default: "duckdb"
21
22
  },
22
23
  help: {
23
24
  type: "boolean",
@@ -28,7 +29,7 @@ export default async function run(args) {
28
29
  if (values.help || !values.database) {
29
30
  console.log(`usage: notebooks query <...query>
30
31
 
31
- --database <name> name of the database
32
+ --database <name> name of the database; defaults to duckdb
32
33
  --root <dir> path to the root directory; defaults to cwd
33
34
  -h, --help show this message
34
35
  `);
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.2.0-rc.1",
8
+ "version": "1.2.0",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "test": "vitest",
@@ -63,6 +63,7 @@
63
63
  "vite": "^7.0.0"
64
64
  },
65
65
  "devDependencies": {
66
+ "@databricks/sql": "^1.11.0",
66
67
  "@duckdb/node-api": "^1.3.2-alpha.26",
67
68
  "@eslint/js": "^9.29.0",
68
69
  "@google-cloud/bigquery": "^8.1.1",
@@ -80,12 +81,16 @@
80
81
  "vitest": "^3.2.4"
81
82
  },
82
83
  "peerDependencies": {
84
+ "@databricks/sql": "^1.11.0",
83
85
  "@duckdb/node-api": "^1.3.2-alpha.26",
84
86
  "@google-cloud/bigquery": "^8.1.1",
85
87
  "postgres": "^3.4.7",
86
88
  "snowflake-sdk": "^2.1.3"
87
89
  },
88
90
  "peerDependenciesMeta": {
91
+ "@databricks/sql": {
92
+ "optional": true
93
+ },
89
94
  "@duckdb/node-api": {
90
95
  "optional": true
91
96
  },
@@ -1,4 +1,11 @@
1
- import type { BigQueryConfig, QueryTemplateFunction } from "./index.js";
1
+ import type { QueryTemplateFunction } from "./index.js";
2
+ export type BigQueryConfig = {
3
+ type: "bigquery";
4
+ apiKey?: string;
5
+ keyFilename?: string;
6
+ keyFile?: string;
7
+ projectId?: string;
8
+ };
2
9
  export default function bigquery({ type, ...options }: BigQueryConfig): QueryTemplateFunction;
3
10
  export declare function replacer(this: {
4
11
  [key: string]: unknown;
@@ -0,0 +1,14 @@
1
+ import type { QueryTemplateFunction } from "./index.js";
2
+ export type DatabricksConfig = {
3
+ type: "databricks";
4
+ host: string;
5
+ path: string;
6
+ } & ({
7
+ authType?: "access-token";
8
+ token: string;
9
+ } | {
10
+ authType: "databricks-oauth";
11
+ oauthClientId?: string;
12
+ oauthClientSecret?: string;
13
+ });
14
+ export default function databricks({ type, ...options }: DatabricksConfig): QueryTemplateFunction;
@@ -0,0 +1,65 @@
1
+ import { DBSQLClient, DBSQLLogger, LogLevel, thrift } from "@databricks/sql";
2
+ const TTypeId = thrift.TCLIService_types.TTypeId;
3
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
+ export default function databricks({ type, ...options }) {
5
+ return async (strings, ...params) => {
6
+ const logger = new DBSQLLogger({ level: LogLevel.error });
7
+ const client = new DBSQLClient({ logger });
8
+ await client.connect(options);
9
+ try {
10
+ const session = await client.openSession();
11
+ try {
12
+ const date = new Date();
13
+ const operation = await session.executeStatement(strings.join("?"), {
14
+ runAsync: true,
15
+ ordinalParameters: params,
16
+ maxRows: 10000
17
+ });
18
+ try {
19
+ const rows = (await operation.fetchAll());
20
+ const schema = await operation.getSchema();
21
+ return { rows, schema: getTableSchema(schema), duration: Date.now() - +date, date };
22
+ }
23
+ finally {
24
+ await operation.close();
25
+ }
26
+ }
27
+ finally {
28
+ await session.close();
29
+ }
30
+ }
31
+ finally {
32
+ await client.close();
33
+ }
34
+ };
35
+ }
36
+ function getTableSchema({ columns }) {
37
+ return columns.map(getColumnSchema);
38
+ }
39
+ function getColumnSchema(column) {
40
+ return { name: column.columnName, type: getColumnType(column.typeDesc) };
41
+ }
42
+ function getColumnType({ types: [type] }) {
43
+ switch (type.primitiveEntry?.type) {
44
+ case TTypeId.BINARY_TYPE:
45
+ return "buffer";
46
+ case TTypeId.BOOLEAN_TYPE:
47
+ return "boolean";
48
+ case TTypeId.BIGINT_TYPE:
49
+ case TTypeId.TINYINT_TYPE:
50
+ case TTypeId.SMALLINT_TYPE:
51
+ case TTypeId.INT_TYPE:
52
+ case TTypeId.DECIMAL_TYPE:
53
+ return "integer";
54
+ case TTypeId.DOUBLE_TYPE:
55
+ case TTypeId.FLOAT_TYPE:
56
+ return "number";
57
+ case TTypeId.DATE_TYPE:
58
+ case TTypeId.TIMESTAMP_TYPE:
59
+ case TTypeId.INTERVAL_DAY_TIME_TYPE:
60
+ case TTypeId.INTERVAL_YEAR_MONTH_TYPE:
61
+ return "date";
62
+ default:
63
+ return "string";
64
+ }
65
+ }
@@ -1,2 +1,9 @@
1
- import type { DuckDBConfig, QueryTemplateFunction } from "./index.js";
1
+ import type { QueryTemplateFunction } from "./index.js";
2
+ export type DuckDBConfig = {
3
+ type: "duckdb";
4
+ path?: string;
5
+ options?: {
6
+ [key: string]: string;
7
+ };
8
+ };
2
9
  export default function duckdb({ path, options }: DuckDBConfig): QueryTemplateFunction;
@@ -1,42 +1,11 @@
1
1
  import type { ColumnSchema, QueryParam } from "../runtime/index.js";
2
- export type DatabaseConfig = BigQueryConfig | DuckDBConfig | SQLiteConfig | SnowflakeConfig | PostgresConfig;
3
- export type BigQueryConfig = {
4
- type: "bigquery";
5
- apiKey?: string;
6
- keyFilename?: string;
7
- keyFile?: string;
8
- projectId?: string;
9
- };
10
- export type DuckDBConfig = {
11
- type: "duckdb";
12
- path?: string;
13
- options?: {
14
- [key: string]: string;
15
- };
16
- };
17
- export type SQLiteConfig = {
18
- type: "sqlite";
19
- path?: string;
20
- };
21
- export type SnowflakeConfig = {
22
- type: "snowflake";
23
- account: string;
24
- database?: string;
25
- role?: string;
26
- schema?: string;
27
- username?: string;
28
- warehouse?: string;
29
- password?: string;
30
- };
31
- export type PostgresConfig = {
32
- type: "postgres";
33
- host?: string;
34
- port?: string | number;
35
- username?: string;
36
- password?: string;
37
- database?: string;
38
- ssl?: boolean;
39
- };
2
+ import type { BigQueryConfig } from "./bigquery.js";
3
+ import type { DatabricksConfig } from "./databricks.js";
4
+ import type { DuckDBConfig } from "./duckdb.js";
5
+ import type { SQLiteConfig } from "./sqlite.js";
6
+ import type { SnowflakeConfig } from "./snowflake.js";
7
+ import type { PostgresConfig } from "./postgres.js";
8
+ export type DatabaseConfig = BigQueryConfig | DatabricksConfig | DuckDBConfig | SQLiteConfig | SnowflakeConfig | PostgresConfig;
40
9
  export type QueryTemplateFunction = (strings: readonly string[], ...params: QueryParam[]) => Promise<SerializableQueryResult>;
41
10
  export type SerializableQueryResult = {
42
11
  rows: Record<string, unknown>[];
@@ -26,7 +26,7 @@ export async function getDatabaseConfig(sourcePath, databaseName) {
26
26
  else if (/\.duckdb$/i.test(databaseName))
27
27
  config = { type: "duckdb", path: databaseName };
28
28
  else if (/\.db$/i.test(databaseName))
29
- config = { type: "sqlite", path: databaseName }; // TODO disambiguate
29
+ config = { type: "sqlite", path: databaseName };
30
30
  else
31
31
  throw new Error(`database not found: ${databaseName}`);
32
32
  }
@@ -36,10 +36,12 @@ export async function getDatabase(config) {
36
36
  switch (config.type) {
37
37
  case "bigquery":
38
38
  return (await import("./bigquery.js")).default(config);
39
+ case "databricks":
40
+ return (await import("./databricks.js")).default(config);
39
41
  case "duckdb":
40
42
  return (await import("./duckdb.js")).default(config);
41
43
  case "sqlite":
42
- return (await import(process.versions.bun ? "./sqlite-bun.js" : "./sqlite-node.js")).default(config);
44
+ return (await import(process.versions.bun ? "./sqlite-bun.js" : "./sqlite-node.js")).default(config); // prettier-ignore
43
45
  case "snowflake":
44
46
  return (await import("./snowflake.js")).default(config);
45
47
  case "postgres":
@@ -1,2 +1,11 @@
1
- import type { PostgresConfig, QueryTemplateFunction } from "./index.js";
1
+ import type { QueryTemplateFunction } from "./index.js";
2
+ export type PostgresConfig = {
3
+ type: "postgres";
4
+ host?: string;
5
+ port?: string | number;
6
+ username?: string;
7
+ password?: string;
8
+ database?: string;
9
+ ssl?: boolean;
10
+ };
2
11
  export default function postgres(options: PostgresConfig): QueryTemplateFunction;
@@ -1,4 +1,14 @@
1
- import { QueryTemplateFunction, SnowflakeConfig } from "./index.js";
1
+ import { QueryTemplateFunction } from "./index.js";
2
+ export type SnowflakeConfig = {
3
+ type: "snowflake";
4
+ account: string;
5
+ database?: string;
6
+ role?: string;
7
+ schema?: string;
8
+ username?: string;
9
+ warehouse?: string;
10
+ password?: string;
11
+ };
2
12
  export default function snowflake(options: SnowflakeConfig): QueryTemplateFunction;
3
13
  export declare function replacer(this: {
4
14
  [key: string]: unknown;
@@ -1,2 +1,3 @@
1
- import type { SQLiteConfig, QueryTemplateFunction } from "./index.js";
1
+ import type { QueryTemplateFunction } from "./index.js";
2
+ import type { SQLiteConfig } from "./sqlite.js";
2
3
  export default function sqlite({ path }: SQLiteConfig): QueryTemplateFunction;
@@ -1,2 +1,3 @@
1
- import type { SQLiteConfig, QueryTemplateFunction } from "./index.js";
1
+ import type { QueryTemplateFunction } from "./index.js";
2
+ import type { SQLiteConfig } from "./sqlite.js";
2
3
  export default function sqlite({ path }: SQLiteConfig): QueryTemplateFunction;
@@ -1,2 +1,6 @@
1
1
  import type { ColumnSchema } from "../runtime/index.js";
2
+ export type SQLiteConfig = {
3
+ type: "sqlite";
4
+ path?: string;
5
+ };
2
6
  export declare function getColumnType(type: string | null): ColumnSchema["type"];
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.2.0-rc.1",
8
+ "version": "1.2.0",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "test": "vitest",
@@ -63,6 +63,7 @@
63
63
  "vite": "^7.0.0"
64
64
  },
65
65
  "devDependencies": {
66
+ "@databricks/sql": "^1.11.0",
66
67
  "@duckdb/node-api": "^1.3.2-alpha.26",
67
68
  "@eslint/js": "^9.29.0",
68
69
  "@google-cloud/bigquery": "^8.1.1",
@@ -80,12 +81,16 @@
80
81
  "vitest": "^3.2.4"
81
82
  },
82
83
  "peerDependencies": {
84
+ "@databricks/sql": "^1.11.0",
83
85
  "@duckdb/node-api": "^1.3.2-alpha.26",
84
86
  "@google-cloud/bigquery": "^8.1.1",
85
87
  "postgres": "^3.4.7",
86
88
  "snowflake-sdk": "^2.1.3"
87
89
  },
88
90
  "peerDependenciesMeta": {
91
+ "@databricks/sql": {
92
+ "optional": true
93
+ },
89
94
  "@duckdb/node-api": {
90
95
  "optional": true
91
96
  },