@perspective-dev/client 5.0.0 → 5.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/cdn/perspective.js +2 -2
- package/dist/cdn/perspective.js.map +3 -3
- package/dist/esm/perspective.inline.js +2 -2
- package/dist/esm/perspective.inline.js.map +3 -3
- package/dist/esm/perspective.js +2 -2
- package/dist/esm/perspective.js.map +3 -3
- package/dist/esm/perspective.node.js +10 -10
- package/dist/esm/perspective.node.js.map +2 -2
- package/dist/esm/ts-rs/AggSpec.d.ts +8 -0
- package/dist/esm/ts-rs/Features.d.ts +66 -0
- package/dist/esm/ts-rs/ListFlatten.d.ts +1 -0
- package/dist/esm/ts-rs/SplitRollupMode.d.ts +9 -0
- package/dist/esm/ts-rs/TableInitOptions.d.ts +9 -0
- package/dist/esm/ts-rs/ViewConfig.d.ts +4 -0
- package/dist/esm/ts-rs/ViewConfigUpdate.d.ts +24 -0
- package/dist/esm/ts-rs/WindowAggSpec.d.ts +25 -0
- package/dist/esm/ts-rs/WindowSort.d.ts +7 -0
- package/dist/esm/ts-rs/WindowSortDir.d.ts +6 -0
- package/dist/esm/ts-rs/WindowSpec.d.ts +47 -0
- package/dist/esm/ts-rs/Windows.d.ts +10 -0
- package/dist/esm/virtual_server.d.ts +8 -34
- package/dist/esm/virtual_servers/clickhouse.js +1 -1
- package/dist/esm/virtual_servers/clickhouse.js.map +3 -3
- package/dist/esm/virtual_servers/duckdb.d.ts +6 -26
- package/dist/esm/virtual_servers/duckdb.js +1 -1
- package/dist/esm/virtual_servers/duckdb.js.map +3 -3
- package/dist/wasm/perspective-js.d.ts +96 -6
- package/dist/wasm/perspective-js.js +11 -11
- package/dist/wasm/perspective-js.wasm +0 -0
- package/dist/wasm/perspective-js.wasm.d.ts +5 -5
- package/package.json +1 -1
- package/src/rust/lib.rs +6 -0
- package/src/rust/typed_array.rs +22 -3
- package/src/rust/virtual_server.rs +98 -2
- package/src/ts/ts-rs/AggSpec.ts +10 -0
- package/src/ts/ts-rs/Features.ts +61 -0
- package/src/ts/ts-rs/ListFlatten.ts +3 -0
- package/src/ts/ts-rs/SplitRollupMode.ts +11 -0
- package/src/ts/ts-rs/TableInitOptions.ts +10 -1
- package/src/ts/ts-rs/ViewConfig.ts +3 -1
- package/src/ts/ts-rs/ViewConfigUpdate.ts +24 -1
- package/src/ts/ts-rs/WindowAggSpec.ts +25 -0
- package/src/ts/ts-rs/WindowSort.ts +9 -0
- package/src/ts/ts-rs/WindowSortDir.ts +8 -0
- package/src/ts/ts-rs/WindowSpec.ts +47 -0
- package/src/ts/ts-rs/Windows.ts +10 -0
- package/src/ts/virtual_server.ts +17 -55
- package/src/ts/virtual_servers/clickhouse.ts +78 -4
- package/src/ts/virtual_servers/duckdb.ts +145 -31
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/ts/virtual_servers/duckdb.ts"],
|
|
4
|
-
"sourcesContent": ["// \u250F\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2513\n// \u2503 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588\u2584 \u2580\u2588\u2588\u2588 \u2588 \u2503\n// \u2503 \u2584\u2584\u2584\u2584\u2584\u2588 \u2588\u2584\u2584\u2584\u2584\u2584 \u2584\u2584\u2584\u2584\u2584\u2588 \u2580\u2580\u2580\u2580\u2580\u2588\u2580\u2580\u2580\u2580\u2580 \u2588 \u2580\u2580\u2580\u2580\u2580\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u258C\u2590\u2588\u2588\u2588 \u2588\u2588\u2588\u2584 \u2580\u2588 \u2588 \u2580\u2580\u2580\u2580\u2580 \u2503\n// \u2503 \u2588\u2580\u2580\u2580\u2580\u2580 \u2588\u2580\u2580\u2580\u2580\u2580 \u2588\u2580\u2588\u2588\u2580\u2580 \u2584\u2584\u2584\u2584\u2584 \u2588 \u2584\u2584\u2584\u2584\u2584\u2588 \u2584\u2584\u2584\u2584\u2584\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u258C\u2590\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2584 \u2588 \u2584\u2584\u2584\u2584\u2584 \u2503\n// \u2503 \u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588 \u2580\u2588\u2584 \u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588 \u2588\u2588\u2588\u258C\u2590\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2584 \u2588 \u2503\n// \u2523\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u252B\n// \u2503 Copyright (c) 2017, the Perspective Authors. \u2503\n// \u2503 \u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C \u2503\n// \u2503 This file is part of the Perspective library, distributed under the terms \u2503\n// \u2503 of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). \u2503\n// \u2517\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u251B\n\n/**\n * An implementation of a Perspective Virtual Server for DuckDB.\n *\n * This import is optional, and so must be imported manually from either\n * `@perspective-dev/client/dist/esm/virtual_servers/duckdb.js` or\n * `@perspective-dev/client/src/ts/virtual_servers/duckdb.ts`, it is not\n * exported from the package root `@perspective-dev/client`\n *\n * @module\n */\n\nimport type * as perspective from \"@perspective-dev/client\";\nimport type { ColumnType } from \"@perspective-dev/client/dist/esm/ts-rs/ColumnType.d.ts\";\nimport type { ViewConfig } from \"@perspective-dev/client/dist/esm/ts-rs/ViewConfig.d.ts\";\nimport type { ViewWindow } from \"@perspective-dev/client/dist/esm/ts-rs/ViewWindow.d.ts\";\nimport type * as duckdb from \"@duckdb/duckdb-wasm\";\n\nconst NUMBER_AGGS = [\n \"sum\",\n \"count\",\n \"any_value\",\n \"arbitrary\",\n \"array_agg\",\n \"avg\",\n \"bit_and\",\n \"bit_or\",\n \"bit_xor\",\n \"bitstring_agg\",\n \"bool_and\",\n \"bool_or\",\n \"countif\",\n \"favg\",\n \"fsum\",\n \"geomean\",\n \"kahan_sum\",\n \"last\",\n \"max\",\n \"min\",\n \"product\",\n \"string_agg\",\n \"sumkahan\",\n];\n\nconst STRING_AGGS = [\n \"count\",\n \"any_value\",\n \"arbitrary\",\n \"first\",\n \"countif\",\n \"last\",\n \"string_agg\",\n];\n\nconst FILTER_OPS = [\n \"==\",\n \"!=\",\n \"LIKE\",\n \"IS DISTINCT FROM\",\n \"IS NOT DISTINCT FROM\",\n \">=\",\n \"<=\",\n \">\",\n \"<\",\n];\n\nfunction duckdbTypeToPsp(name: string): ColumnType {\n name = name.toLowerCase();\n if (name === \"varchar\" || name == \"utf8\") {\n return \"string\";\n }\n\n if (\n name === \"double\" ||\n name === \"bigint\" ||\n name === \"hugeint\" ||\n name === \"float64\" ||\n name.startsWith(\"decimal\")\n ) {\n return \"float\";\n }\n\n if (name.startsWith(\"int\")) {\n return \"integer\";\n }\n\n if (name.startsWith(\"date\")) {\n return \"date\";\n }\n\n if (name.startsWith(\"bool\")) {\n return \"boolean\";\n }\n\n if (name.startsWith(\"timestamp\")) {\n return \"datetime\";\n }\n\n if (name.startsWith(\"json\")) {\n return \"string\";\n }\n\n if (name.startsWith(\"struct\")) {\n return \"string\";\n }\n\n if (name.startsWith(\"time\")) {\n return \"float\";\n }\n\n console.warn(`Unknown type '${name}'`);\n return \"string\";\n}\n\nasync function runQuery(\n db: duckdb.AsyncDuckDBConnection,\n query: string,\n options: { columns: true },\n): Promise<{\n rows: any[];\n columns: string[];\n dtypes: string[];\n}>;\n\nasync function runQuery(\n db: duckdb.AsyncDuckDBConnection,\n query: string,\n options?: { columns: false },\n): Promise<any[]>;\n\nasync function runQuery(\n db: duckdb.AsyncDuckDBConnection,\n query: string,\n options: { columns?: boolean } = {},\n) {\n query = query.replace(/\\s+/g, \" \").trim();\n try {\n const result = await db.query(query);\n if (options.columns) {\n return {\n rows: result.toArray(),\n columns: result.schema.fields.map((f) => f.name),\n dtypes: result.schema.fields.map((f) => f.type.toString()),\n };\n }\n\n return result.toArray();\n } catch (error) {\n console.error(\"Query error:\", error);\n console.error(\"Query:\", query);\n throw error;\n }\n}\n\n/**\n * An implementation of Perspective's Virtual Server for `@duckdb/duckdb-wasm`.\n */\nexport class DuckDBHandler implements perspective.VirtualServerHandler {\n private db: duckdb.AsyncDuckDBConnection;\n private sqlBuilder: perspective.GenericSQLVirtualServerModel;\n constructor(db: duckdb.AsyncDuckDBConnection, mod?: typeof perspective) {\n if (!mod) {\n if (customElements) {\n const viewer_class: any =\n customElements.get(\"perspective-viewer\");\n if (viewer_class) {\n mod = viewer_class.__wasm_module__;\n } else {\n throw new Error(\"Missing perspective-client.wasm\");\n }\n } else {\n }\n }\n\n this.db = db;\n this.sqlBuilder = new mod!.GenericSQLVirtualServerModel({\n column_separator: \"|\",\n });\n }\n\n getFeatures() {\n return {\n group_by: true,\n split_by: true,\n sort: true,\n expressions: true,\n group_rollup_mode: [\"rollup\", \"flat\", \"total\"],\n filter_ops: {\n integer: FILTER_OPS,\n float: FILTER_OPS,\n string: FILTER_OPS,\n boolean: FILTER_OPS,\n date: FILTER_OPS,\n datetime: FILTER_OPS,\n },\n aggregates: {\n integer: NUMBER_AGGS,\n float: NUMBER_AGGS,\n string: STRING_AGGS,\n boolean: STRING_AGGS,\n date: STRING_AGGS,\n datetime: STRING_AGGS,\n },\n };\n }\n\n async getHostedTables() {\n const query = this.sqlBuilder.getHostedTables();\n const results = await runQuery(this.db, query);\n return results.map((row) => {\n const json = row.toJSON();\n return `${json.database || \"memory\"}.${json.name}`;\n });\n }\n\n async tableSchema(tableId: string, config?: ViewConfig) {\n const query = this.sqlBuilder.tableSchema(tableId);\n const results = await runQuery(this.db, query);\n const schema = {} as Record<string, ColumnType>;\n for (const result of results) {\n const res = result.toJSON();\n const colName = res.column_name;\n if (!colName.startsWith(\"__\")) {\n schema[colName] = duckdbTypeToPsp(\n res.column_type,\n ) as ColumnType;\n }\n }\n\n return schema;\n }\n\n async viewColumnSize(viewId: string, config: ViewConfig) {\n const query = this.sqlBuilder.viewColumnSize(viewId);\n const results = await runQuery(this.db, query);\n const count = Number(Object.values(results[0].toJSON())[0]);\n const gs = config.group_by?.length || 0;\n const is_flat = config.group_rollup_mode === \"flat\";\n return count - (gs === 0 ? 0 : is_flat ? gs : gs + 1);\n }\n\n async tableSize(tableId: string) {\n const query = this.sqlBuilder.tableSize(tableId);\n const results = await runQuery(this.db, query);\n return Number(results[0].toJSON()[\"count_star()\"]);\n }\n\n async tableMakeView(tableId: string, viewId: string, config: ViewConfig) {\n const query = this.sqlBuilder.tableMakeView(tableId, viewId, config);\n await runQuery(this.db, query);\n }\n\n async tableValidateExpression(tableId: string, expression: string) {\n const query = this.sqlBuilder.tableValidateExpression(\n tableId,\n expression,\n );\n const results = await runQuery(this.db, query);\n return duckdbTypeToPsp(\n results[0].toJSON()[\"column_type\"],\n ) as ColumnType;\n }\n\n async viewDelete(viewId: string) {\n const query = this.sqlBuilder.viewDelete(viewId);\n await runQuery(this.db, query);\n }\n\n async viewGetMinMax(\n viewId: string,\n columnName: string,\n config: ViewConfig,\n ) {\n const query = this.sqlBuilder.viewGetMinMax(viewId, columnName, config);\n const results = await runQuery(this.db, query);\n const row = results[0].toJSON();\n let [min, max] = Object.values(row);\n if (typeof min === \"bigint\") min = Number(min);\n if (typeof max === \"bigint\") max = Number(max);\n return { min: min ?? null, max: max ?? null };\n }\n\n async viewGetData(\n viewId: string,\n config: ViewConfig,\n schema: Record<string, ColumnType>,\n viewport: ViewWindow,\n dataSlice: perspective.VirtualDataSlice,\n ) {\n const query = this.sqlBuilder.viewGetData(\n viewId,\n config,\n viewport,\n schema,\n );\n\n const ipc = await this.db.useUnsafe((bindings, conn) =>\n bindings.runQuery(conn, query),\n );\n\n dataSlice.fromArrowIpc(ipc);\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["NUMBER_AGGS", "STRING_AGGS", "FILTER_OPS", "duckdbTypeToPsp", "name", "runQuery", "db", "query", "options", "result", "f", "error", "DuckDBHandler", "mod", "viewer_class", "row", "json", "tableId", "config", "results", "schema", "res", "colName", "viewId", "count", "gs", "is_flat", "expression", "columnName", "min", "max", "viewport", "dataSlice", "ipc", "bindings", "conn"]
|
|
4
|
+
"sourcesContent": ["// \u250F\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2513\n// \u2503 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588\u2584 \u2580\u2588\u2588\u2588 \u2588 \u2503\n// \u2503 \u2584\u2584\u2584\u2584\u2584\u2588 \u2588\u2584\u2584\u2584\u2584\u2584 \u2584\u2584\u2584\u2584\u2584\u2588 \u2580\u2580\u2580\u2580\u2580\u2588\u2580\u2580\u2580\u2580\u2580 \u2588 \u2580\u2580\u2580\u2580\u2580\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u258C\u2590\u2588\u2588\u2588 \u2588\u2588\u2588\u2584 \u2580\u2588 \u2588 \u2580\u2580\u2580\u2580\u2580 \u2503\n// \u2503 \u2588\u2580\u2580\u2580\u2580\u2580 \u2588\u2580\u2580\u2580\u2580\u2580 \u2588\u2580\u2588\u2588\u2580\u2580 \u2584\u2584\u2584\u2584\u2584 \u2588 \u2584\u2584\u2584\u2584\u2584\u2588 \u2584\u2584\u2584\u2584\u2584\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u258C\u2590\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2584 \u2588 \u2584\u2584\u2584\u2584\u2584 \u2503\n// \u2503 \u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588 \u2580\u2588\u2584 \u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588 \u2588\u2588\u2588\u258C\u2590\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2584 \u2588 \u2503\n// \u2523\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u252B\n// \u2503 Copyright (c) 2017, the Perspective Authors. \u2503\n// \u2503 \u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C \u2503\n// \u2503 This file is part of the Perspective library, distributed under the terms \u2503\n// \u2503 of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). \u2503\n// \u2517\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u251B\n\n/**\n * An implementation of a Perspective Virtual Server for DuckDB.\n *\n * This import is optional, and so must be imported manually from either\n * `@perspective-dev/client/dist/esm/virtual_servers/duckdb.js` or\n * `@perspective-dev/client/src/ts/virtual_servers/duckdb.ts`, it is not\n * exported from the package root `@perspective-dev/client`\n *\n * @module\n */\n\nimport type * as perspective from \"@perspective-dev/client\";\nimport type { ColumnType } from \"@perspective-dev/client/dist/esm/ts-rs/ColumnType.d.ts\";\nimport type { ViewConfig } from \"@perspective-dev/client/dist/esm/ts-rs/ViewConfig.d.ts\";\nimport type { ViewConfigUpdate } from \"@perspective-dev/client/dist/esm/ts-rs/ViewConfigUpdate.d.ts\";\nimport type { ViewWindow } from \"@perspective-dev/client/dist/esm/ts-rs/ViewWindow.d.ts\";\nimport type { WindowAggSpec } from \"@perspective-dev/client/dist/esm/ts-rs/WindowAggSpec.d.ts\";\nimport type { Scalar } from \"@perspective-dev/client/dist/esm/ts-rs/Scalar.d.ts\";\nimport type * as duckdb from \"@duckdb/duckdb-wasm\";\n\nconst NUMBER_AGGS = [\n \"sum\",\n \"count\",\n \"any_value\",\n \"arbitrary\",\n \"array_agg\",\n \"avg\",\n \"bit_and\",\n \"bit_or\",\n \"bit_xor\",\n \"bitstring_agg\",\n \"bool_and\",\n \"bool_or\",\n \"countif\",\n \"favg\",\n \"fsum\",\n \"geomean\",\n \"kahan_sum\",\n \"last\",\n \"max\",\n \"min\",\n \"product\",\n \"string_agg\",\n \"sumkahan\",\n];\n\nconst STRING_AGGS = [\n \"count\",\n \"any_value\",\n \"arbitrary\",\n \"first\",\n \"countif\",\n \"last\",\n \"string_agg\",\n];\n\nconst FRAMES = [\"rows\", \"range\", \"cumulative\"];\n\nconst WINDOW_AGGREGATES: WindowAggSpec[] = [\n { name: \"sum\", frames: FRAMES, result_type: \"float\" },\n { name: \"avg\", frames: FRAMES, result_type: \"float\" },\n { name: \"count\", frames: FRAMES, result_type: \"float\" },\n { name: \"min\", frames: FRAMES },\n { name: \"max\", frames: FRAMES },\n { name: \"product\", frames: FRAMES, result_type: \"float\" },\n { name: \"median\", frames: FRAMES, result_type: \"float\" },\n // DuckDB spells sample and population variants separately, so both are\n // offered rather than one being picked on the user's behalf.\n { name: \"stddev_samp\", frames: FRAMES, result_type: \"float\" },\n { name: \"stddev_pop\", frames: FRAMES, result_type: \"float\" },\n { name: \"var_samp\", frames: FRAMES, result_type: \"float\" },\n { name: \"var_pop\", frames: FRAMES, result_type: \"float\" },\n // Navigation.\n { name: \"first_value\", frames: FRAMES },\n { name: \"last_value\", frames: FRAMES },\n { name: \"nth_value\", frames: FRAMES, offset: true },\n { name: \"lag\", offset: true },\n { name: \"lead\", offset: true },\n // Ranking. These take no source column - the window's `order_by` is their\n // input - but Perspective requires one, so the choice of source is\n // immaterial for them.\n { name: \"row_number\", result_type: \"float\" },\n { name: \"rank\", result_type: \"float\" },\n { name: \"dense_rank\", result_type: \"float\" },\n { name: \"percent_rank\", result_type: \"float\" },\n { name: \"cume_dist\", result_type: \"float\" },\n // `ntile`'s argument is a bucket count rather than a row offset.\n { name: \"ntile\", offset: true, result_type: \"float\" },\n // Perspective's own, with no DuckDB equivalent - the SQL translation\n // synthesizes them from `lag` and `first_value`.\n { name: \"diff\", offset: true, result_type: \"float\" },\n { name: \"rate\", frames: [\"range\"], result_type: \"float\" },\n];\n\n// Arithmetic is undefined for the non-numeric types; ordering and navigation\n// are not.\nconst WINDOW_AGGREGATES_ANY: WindowAggSpec[] = [\n { name: \"count\", frames: FRAMES, result_type: \"float\" },\n { name: \"min\", frames: FRAMES },\n { name: \"max\", frames: FRAMES },\n { name: \"first_value\", frames: FRAMES },\n { name: \"last_value\", frames: FRAMES },\n { name: \"nth_value\", frames: FRAMES, offset: true },\n { name: \"lag\", offset: true },\n { name: \"lead\", offset: true },\n { name: \"row_number\", result_type: \"float\" },\n { name: \"rank\", result_type: \"float\" },\n { name: \"dense_rank\", result_type: \"float\" },\n { name: \"percent_rank\", result_type: \"float\" },\n { name: \"cume_dist\", result_type: \"float\" },\n { name: \"ntile\", offset: true, result_type: \"float\" },\n];\n\nconst FILTER_OPS = [\n \"==\",\n \"!=\",\n \"IS DISTINCT FROM\",\n \"IS NOT DISTINCT FROM\",\n \">=\",\n \"<=\",\n \">\",\n \"<\",\n \"is null\",\n \"is not null\",\n];\n\n// Perspective's canonical string ops (translated to `ILIKE` / `regexp_matches`\n// by the SQL builder), plus DuckDB's raw infix pattern ops spliced verbatim.\nconst STRING_FILTER_OPS = [\n ...FILTER_OPS,\n \"begins with\",\n \"not begins with\",\n \"contains\",\n \"not contains\",\n \"ends with\",\n \"not ends with\",\n \"matches\",\n \"not matches\",\n \"in\",\n \"not in\",\n \"LIKE\",\n \"NOT LIKE\",\n \"ILIKE\",\n \"NOT ILIKE\",\n];\n\n/**\n * Convert a DuckDB `dtype` to a Perspective `ColumnType`.\n */\nfunction duckdbTypeToPsp(name: string): ColumnType {\n name = name.toLowerCase();\n\n if (name.startsWith(\"bool\")) {\n return \"boolean\";\n }\n\n // 32-bit and narrower - `coerce_column` widens these to `Int32`.\n if (\n [\"tinyint\", \"smallint\", \"integer\", \"utinyint\", \"usmallint\"].includes(\n name,\n ) ||\n [\"int8\", \"int16\", \"int32\", \"uint8\", \"uint16\"].includes(name)\n ) {\n return \"integer\";\n }\n\n // Wider than `Int32`, or fractional - all coerce to `Float64`.\n if (\n [\"bigint\", \"hugeint\", \"uhugeint\", \"uinteger\", \"ubigint\"].includes(\n name,\n ) ||\n [\"float\", \"real\", \"double\", \"varint\"].includes(name) ||\n [\"int64\", \"uint32\", \"uint64\", \"float32\", \"float64\"].includes(name) ||\n name.startsWith(\"decimal\") ||\n name.startsWith(\"numeric\")\n ) {\n return \"float\";\n }\n\n if (name.startsWith(\"date\")) {\n return \"date\";\n }\n\n // `timestamp`, `timestamptz`, `timestamp_ns`, and `time`/`timetz`,\n // which coerce to `Timestamp(Millisecond)` rather than to a number.\n if (name.startsWith(\"time\")) {\n return \"datetime\";\n }\n\n // Everything else renders as text: `varchar`, `enum(...)` (which\n // arrives dictionary-encoded), `json`, `uuid`, `blob`, `interval`,\n // and the nested types.\n if (\n !(\n name.startsWith(\"varchar\") ||\n name === \"utf8\" ||\n name.startsWith(\"enum\") ||\n [\"json\", \"uuid\", \"blob\", \"bit\", \"interval\"].includes(name) ||\n name.startsWith(\"struct\") ||\n name.startsWith(\"map\") ||\n name.startsWith(\"union\") ||\n name.endsWith(\"[]\")\n )\n ) {\n // Unknown, not fatal - the column still renders, as text.\n console.warn(`Unknown type '${name}'`);\n }\n\n return \"string\";\n}\n\nasync function runQuery(\n db: duckdb.AsyncDuckDBConnection,\n query: string,\n options: { columns: true },\n): Promise<{\n rows: any[];\n columns: string[];\n dtypes: string[];\n}>;\n\nasync function runQuery(\n db: duckdb.AsyncDuckDBConnection,\n query: string,\n options?: { columns: false },\n): Promise<any[]>;\n\nasync function runQuery(\n db: duckdb.AsyncDuckDBConnection,\n query: string,\n options: { columns?: boolean } = {},\n) {\n query = query.replace(/\\s+/g, \" \").trim();\n try {\n const result = await db.query(query);\n if (options.columns) {\n return {\n rows: result.toArray(),\n columns: result.schema.fields.map((f) => f.name),\n dtypes: result.schema.fields.map((f) => f.type.toString()),\n };\n }\n\n return result.toArray();\n } catch (error) {\n console.error(\"Query error:\", error);\n console.error(\"Query:\", query);\n throw error;\n }\n}\n\n/**\n * An implementation of Perspective's Virtual Server for `@duckdb/duckdb-wasm`.\n */\nexport class DuckDBHandler implements perspective.VirtualServerHandler {\n private db: duckdb.AsyncDuckDBConnection;\n private sqlBuilder: perspective.GenericSQLVirtualServerModel;\n constructor(db: duckdb.AsyncDuckDBConnection, mod?: typeof perspective) {\n if (!mod) {\n if (customElements) {\n const viewer_class: any =\n customElements.get(\"perspective-viewer\");\n if (viewer_class) {\n mod = viewer_class.__wasm_module__;\n } else {\n throw new Error(\"Missing perspective-client.wasm\");\n }\n } else {\n }\n }\n\n this.db = db;\n this.sqlBuilder = new mod!.GenericSQLVirtualServerModel({\n column_separator: \"|\",\n like_escape_clause: \"\\\\\",\n regex_fn: \"regexp_matches\",\n });\n }\n\n getFeatures(): perspective.Features {\n return {\n group_by: true,\n split_by: true,\n sort: true,\n expressions: true,\n window_aggregates: {\n // `ema` is recursive and has no SQL window translation.\n integer: WINDOW_AGGREGATES,\n float: WINDOW_AGGREGATES,\n string: WINDOW_AGGREGATES_ANY,\n date: WINDOW_AGGREGATES_ANY,\n datetime: WINDOW_AGGREGATES_ANY,\n boolean: WINDOW_AGGREGATES_ANY,\n },\n group_rollup_mode: [\"rollup\", \"flat\", \"total\"],\n split_rollup_mode: [\"flat\", \"rollup\"],\n filter_ops: {\n integer: FILTER_OPS,\n float: FILTER_OPS,\n string: STRING_FILTER_OPS,\n boolean: FILTER_OPS,\n date: FILTER_OPS,\n datetime: FILTER_OPS,\n },\n aggregates: {\n integer: NUMBER_AGGS,\n float: NUMBER_AGGS,\n string: STRING_AGGS,\n boolean: STRING_AGGS,\n date: STRING_AGGS,\n datetime: STRING_AGGS,\n },\n };\n }\n\n async getHostedTables() {\n const query = this.sqlBuilder.getHostedTables();\n const results = await runQuery(this.db, query);\n return results.map((row) => {\n const json = row.toJSON();\n return `${json.database || \"memory\"}.${json.name}`;\n });\n }\n\n async tableSchema(tableId: string, config?: ViewConfig) {\n const query = this.sqlBuilder.tableSchema(tableId);\n const results = await runQuery(this.db, query);\n const schema = {} as Record<string, ColumnType>;\n for (const result of results) {\n const res = result.toJSON();\n const colName = res.column_name;\n if (!colName.startsWith(\"__\")) {\n schema[colName] = duckdbTypeToPsp(\n res.column_type,\n ) as ColumnType;\n }\n }\n\n return schema;\n }\n\n async viewColumnSize(viewId: string, config: ViewConfig) {\n const query = this.sqlBuilder.viewColumnSize(viewId);\n const results = await runQuery(this.db, query);\n const count = Number(Object.values(results[0].toJSON())[0]);\n const gs = config.group_by?.length || 0;\n const is_flat = config.group_rollup_mode === \"flat\";\n return count - (gs === 0 ? 0 : is_flat ? gs : gs + 1);\n }\n\n async tableSize(tableId: string) {\n const query = this.sqlBuilder.tableSize(tableId);\n const results = await runQuery(this.db, query);\n return Number(results[0].toJSON()[\"count_star()\"]);\n }\n\n async tableMakeView(\n tableId: string,\n viewId: string,\n config: ViewConfigUpdate,\n ) {\n const query = this.sqlBuilder.tableMakeView(tableId, viewId, config);\n await runQuery(this.db, query);\n }\n\n async tableValidateExpression(tableId: string, expression: string) {\n const query = this.sqlBuilder.tableValidateExpression(\n tableId,\n expression,\n );\n const results = await runQuery(this.db, query);\n return duckdbTypeToPsp(\n results[0].toJSON()[\"column_type\"],\n ) as ColumnType;\n }\n\n async viewDelete(viewId: string) {\n const query = this.sqlBuilder.viewDelete(viewId);\n await runQuery(this.db, query);\n }\n\n async viewGetMinMax(\n viewId: string,\n columnName: string,\n config: ViewConfig,\n ) {\n const query = this.sqlBuilder.viewGetMinMax(viewId, columnName, config);\n const results = await runQuery(this.db, query);\n const row = results[0].toJSON();\n let [min, max] = Object.values(row);\n if (typeof min === \"bigint\") min = Number(min);\n if (typeof max === \"bigint\") max = Number(max);\n return { min: (min ?? null) as Scalar, max: (max ?? null) as Scalar };\n }\n\n async viewGetData(\n viewId: string,\n config: ViewConfig,\n schema: Record<string, ColumnType>,\n viewport: ViewWindow,\n dataSlice: perspective.VirtualDataSlice,\n ) {\n const query = this.sqlBuilder.viewGetData(\n viewId,\n config,\n viewport,\n schema,\n );\n\n const ipc = await this.db.useUnsafe((bindings, conn) =>\n bindings.runQuery(conn, query),\n );\n\n dataSlice.fromArrowIpc(ipc);\n }\n}\n"],
|
|
5
|
+
"mappings": "AAgCA,IAAMA,EAAc,CAChB,MACA,QACA,YACA,YACA,YACA,MACA,UACA,SACA,UACA,gBACA,WACA,UACA,UACA,OACA,OACA,UACA,YACA,OACA,MACA,MACA,UACA,aACA,UACJ,EAEMC,EAAc,CAChB,QACA,YACA,YACA,QACA,UACA,OACA,YACJ,EAEMC,EAAS,CAAC,OAAQ,QAAS,YAAY,EAEvCC,EAAqC,CACvC,CAAE,KAAM,MAAO,OAAQD,EAAQ,YAAa,OAAQ,EACpD,CAAE,KAAM,MAAO,OAAQA,EAAQ,YAAa,OAAQ,EACpD,CAAE,KAAM,QAAS,OAAQA,EAAQ,YAAa,OAAQ,EACtD,CAAE,KAAM,MAAO,OAAQA,CAAO,EAC9B,CAAE,KAAM,MAAO,OAAQA,CAAO,EAC9B,CAAE,KAAM,UAAW,OAAQA,EAAQ,YAAa,OAAQ,EACxD,CAAE,KAAM,SAAU,OAAQA,EAAQ,YAAa,OAAQ,EAGvD,CAAE,KAAM,cAAe,OAAQA,EAAQ,YAAa,OAAQ,EAC5D,CAAE,KAAM,aAAc,OAAQA,EAAQ,YAAa,OAAQ,EAC3D,CAAE,KAAM,WAAY,OAAQA,EAAQ,YAAa,OAAQ,EACzD,CAAE,KAAM,UAAW,OAAQA,EAAQ,YAAa,OAAQ,EAExD,CAAE,KAAM,cAAe,OAAQA,CAAO,EACtC,CAAE,KAAM,aAAc,OAAQA,CAAO,EACrC,CAAE,KAAM,YAAa,OAAQA,EAAQ,OAAQ,EAAK,EAClD,CAAE,KAAM,MAAO,OAAQ,EAAK,EAC5B,CAAE,KAAM,OAAQ,OAAQ,EAAK,EA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AI,OAAOc,GAAQ,WAAUA,EAAM,OAAOA,CAAG,GACzC,OAAOC,GAAQ,WAAUA,EAAM,OAAOA,CAAG,GACtC,CAAE,IAAMD,GAAO,KAAiB,IAAMC,GAAO,IAAgB,CACxE,CAEA,MAAM,YACFP,EACAL,EACAE,EACAW,EACAC,EACF,CACE,IAAMzB,EAAQ,KAAK,WAAW,YAC1BgB,EACAL,EACAa,EACAX,CACJ,EAEMa,EAAM,MAAM,KAAK,GAAG,UAAU,CAACC,EAAUC,IAC3CD,EAAS,SAASC,EAAM5B,CAAK,CACjC,EAEAyB,EAAU,aAAaC,CAAG,CAC9B,CACJ",
|
|
6
|
+
"names": ["NUMBER_AGGS", "STRING_AGGS", "FRAMES", "WINDOW_AGGREGATES", "WINDOW_AGGREGATES_ANY", "FILTER_OPS", "STRING_FILTER_OPS", "duckdbTypeToPsp", "name", "runQuery", "db", "query", "options", "result", "f", "error", "DuckDBHandler", "mod", "viewer_class", "row", "json", "tableId", "config", "results", "schema", "res", "colName", "viewId", "count", "gs", "is_flat", "expression", "columnName", "min", "max", "viewport", "dataSlice", "ipc", "bindings", "conn"]
|
|
7
7
|
}
|
|
@@ -1,6 +1,90 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* A table hosted by a `VirtualServerHandler`, as returned by
|
|
6
|
+
* `getHostedTables()`. A plain `string` is shorthand for `{ name }`.
|
|
7
|
+
*/
|
|
8
|
+
export interface VirtualHostedTable {
|
|
9
|
+
name: string;
|
|
10
|
+
index?: string;
|
|
11
|
+
limit?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Handler interface that you implement to provide custom data sources.
|
|
16
|
+
*
|
|
17
|
+
* All methods will be called by the `VirtualServer` when handling protocol
|
|
18
|
+
* messages from Perspective clients. Methods can return values directly or
|
|
19
|
+
* return Promises for asynchronous operations (e.g., database queries).
|
|
20
|
+
* Optional methods fall back to defaults documented per-method.
|
|
21
|
+
*/
|
|
22
|
+
export interface VirtualServerHandler {
|
|
23
|
+
getHostedTables():
|
|
24
|
+
| (string | VirtualHostedTable)[]
|
|
25
|
+
| Promise<(string | VirtualHostedTable)[]>;
|
|
26
|
+
tableSchema(
|
|
27
|
+
tableId: string,
|
|
28
|
+
): Record<string, ColumnType> | Promise<Record<string, ColumnType>>;
|
|
29
|
+
tableSize(tableId: string): number | Promise<number>;
|
|
30
|
+
tableMakeView(
|
|
31
|
+
tableId: string,
|
|
32
|
+
viewId: string,
|
|
33
|
+
config: ViewConfigUpdate,
|
|
34
|
+
): void | Promise<void>;
|
|
35
|
+
viewDelete(viewId: string): void | Promise<void>;
|
|
36
|
+
viewGetData(
|
|
37
|
+
viewId: string,
|
|
38
|
+
config: ViewConfig,
|
|
39
|
+
schema: Record<string, ColumnType>,
|
|
40
|
+
viewport: ViewWindow,
|
|
41
|
+
dataSlice: VirtualDataSlice,
|
|
42
|
+
): void | Promise<void>;
|
|
43
|
+
|
|
44
|
+
/** Defaults to `tableSchema(viewId)`. */
|
|
45
|
+
viewSchema?(
|
|
46
|
+
viewId: string,
|
|
47
|
+
config: ViewConfig,
|
|
48
|
+
): Record<string, ColumnType> | Promise<Record<string, ColumnType>>;
|
|
49
|
+
|
|
50
|
+
/** Defaults to `tableSize(viewId)`. */
|
|
51
|
+
viewSize?(viewId: string): number | Promise<number>;
|
|
52
|
+
|
|
53
|
+
/** Defaults to the length of `tableSchema(tableId)`. */
|
|
54
|
+
tableColumnsSize?(tableId: string): number | Promise<number>;
|
|
55
|
+
|
|
56
|
+
/** Defaults to the length of `viewSchema(viewId, config)`. */
|
|
57
|
+
viewColumnSize?(
|
|
58
|
+
viewId: string,
|
|
59
|
+
config: ViewConfig,
|
|
60
|
+
): number | Promise<number>;
|
|
61
|
+
|
|
62
|
+
/** Required when `getFeatures()` reports `expressions: true`. */
|
|
63
|
+
tableValidateExpression?(
|
|
64
|
+
tableId: string,
|
|
65
|
+
expression: string,
|
|
66
|
+
): ColumnType | Promise<ColumnType>;
|
|
67
|
+
|
|
68
|
+
viewGetMinMax?(
|
|
69
|
+
viewId: string,
|
|
70
|
+
columnName: string,
|
|
71
|
+
config: ViewConfig,
|
|
72
|
+
): { min: Scalar; max: Scalar } | Promise<{ min: Scalar; max: Scalar }>;
|
|
73
|
+
|
|
74
|
+
/** Defaults to no optional features. */
|
|
75
|
+
getFeatures?(): Features | Promise<Features>;
|
|
76
|
+
|
|
77
|
+
/** Defaults to port `0`. */
|
|
78
|
+
tableMakePort?(): number | Promise<number>;
|
|
79
|
+
|
|
80
|
+
makeTable?(
|
|
81
|
+
tableId: string,
|
|
82
|
+
data: string | Uint8Array,
|
|
83
|
+
): void | Promise<void>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
4
88
|
export type * from "../../src/ts/ts-rs/ViewWindow.d.ts";
|
|
5
89
|
export type * from "../../src/ts/ts-rs/ColumnType.d.ts";
|
|
6
90
|
export type * from "../../src/ts/ts-rs/ColumnWindow.d.ts";
|
|
@@ -18,6 +102,9 @@ export type * from "../../src/ts/ts-rs/ViewConfig.d.ts";
|
|
|
18
102
|
export type * from "../../src/ts/ts-rs/JoinOptions.ts";
|
|
19
103
|
export type * from "../../src/ts/ts-rs/JoinType.ts";
|
|
20
104
|
export type * from "../../src/ts/ts-rs/TypedArrayWindow.ts";
|
|
105
|
+
export type * from "../../src/ts/ts-rs/Features.ts";
|
|
106
|
+
export type * from "../../src/ts/ts-rs/AggSpec.ts";
|
|
107
|
+
export type * from "../../src/ts/ts-rs/WindowAggSpec.ts";
|
|
21
108
|
|
|
22
109
|
import type {ColumnWindow} from "../../src/ts/ts-rs/ColumnWindow.d.ts";
|
|
23
110
|
import type {ColumnType} from "../../src/ts/ts-rs/ColumnType.d.ts";
|
|
@@ -32,6 +119,9 @@ import type {OnUpdateOptions} from "../../src/ts/ts-rs/OnUpdateOptions.d.ts";
|
|
|
32
119
|
import type {UpdateOptions} from "../../src/ts/ts-rs/UpdateOptions.d.ts";
|
|
33
120
|
import type {DeleteOptions} from "../../src/ts/ts-rs/DeleteOptions.d.ts";
|
|
34
121
|
import type {SystemInfo} from "../../src/ts/ts-rs/SystemInfo.d.ts";
|
|
122
|
+
import type {ViewConfig} from "../../src/ts/ts-rs/ViewConfig.d.ts";
|
|
123
|
+
import type {Scalar} from "../../src/ts/ts-rs/Scalar.d.ts";
|
|
124
|
+
import type {Features} from "../../src/ts/ts-rs/Features.ts";
|
|
35
125
|
|
|
36
126
|
|
|
37
127
|
|
|
@@ -773,7 +863,7 @@ export class VirtualServer {
|
|
|
773
863
|
free(): void;
|
|
774
864
|
[Symbol.dispose](): void;
|
|
775
865
|
handleRequest(bytes: Uint8Array): Promise<any>;
|
|
776
|
-
constructor(handler:
|
|
866
|
+
constructor(handler: VirtualServerHandler);
|
|
777
867
|
}
|
|
778
868
|
|
|
779
869
|
export function init(): void;
|
|
@@ -874,11 +964,11 @@ export interface InitOutput {
|
|
|
874
964
|
readonly virtualdataslice_setStringCol: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
875
965
|
readonly virtualserver_handleRequest: (a: number, b: number, c: number) => number;
|
|
876
966
|
readonly virtualserver_new: (a: number, b: number) => void;
|
|
877
|
-
readonly
|
|
878
|
-
readonly
|
|
879
|
-
readonly
|
|
880
|
-
readonly
|
|
881
|
-
readonly
|
|
967
|
+
readonly __wasm_bindgen_func_elem_1146: (a: number, b: number) => void;
|
|
968
|
+
readonly __wasm_bindgen_func_elem_4239: (a: number, b: number) => void;
|
|
969
|
+
readonly __wasm_bindgen_func_elem_12398: (a: number, b: number, c: number, d: number) => void;
|
|
970
|
+
readonly __wasm_bindgen_func_elem_4256: (a: number, b: number, c: number) => void;
|
|
971
|
+
readonly __wasm_bindgen_func_elem_1860: (a: number, b: number) => number;
|
|
882
972
|
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
883
973
|
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
884
974
|
readonly __wbindgen_export3: (a: number) => void;
|
|
@@ -1649,7 +1649,7 @@ export class VirtualServer {
|
|
|
1649
1649
|
return takeObject(ret);
|
|
1650
1650
|
}
|
|
1651
1651
|
/**
|
|
1652
|
-
* @param {
|
|
1652
|
+
* @param {VirtualServerHandler} handler
|
|
1653
1653
|
*/
|
|
1654
1654
|
constructor(handler) {
|
|
1655
1655
|
try {
|
|
@@ -2016,7 +2016,7 @@ function __wbg_get_imports() {
|
|
|
2016
2016
|
const a = state0.a;
|
|
2017
2017
|
state0.a = 0;
|
|
2018
2018
|
try {
|
|
2019
|
-
return
|
|
2019
|
+
return __wasm_bindgen_func_elem_12398(a, state0.b, arg0, arg1);
|
|
2020
2020
|
} finally {
|
|
2021
2021
|
state0.a = a;
|
|
2022
2022
|
}
|
|
@@ -2175,12 +2175,12 @@ function __wbg_get_imports() {
|
|
|
2175
2175
|
},
|
|
2176
2176
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
2177
2177
|
// Cast intrinsic for `Closure(Closure { dtor_idx: 12, function: Function { arguments: [], shim_idx: 31, ret: NamedExternref("Promise<any>"), inner_ret: Some(NamedExternref("Promise<any>")) }, mutable: false }) -> Externref`.
|
|
2178
|
-
const ret = makeClosure(arg0, arg1, wasm.
|
|
2178
|
+
const ret = makeClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_1146, __wasm_bindgen_func_elem_1860);
|
|
2179
2179
|
return addHeapObject(ret);
|
|
2180
2180
|
},
|
|
2181
2181
|
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
2182
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx:
|
|
2183
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
2182
|
+
// Cast intrinsic for `Closure(Closure { dtor_idx: 580, function: Function { arguments: [Externref], shim_idx: 581, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
2183
|
+
const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_4239, __wasm_bindgen_func_elem_4256);
|
|
2184
2184
|
return addHeapObject(ret);
|
|
2185
2185
|
},
|
|
2186
2186
|
__wbindgen_cast_0000000000000003: function(arg0) {
|
|
@@ -2257,17 +2257,17 @@ function __wbg_get_imports() {
|
|
|
2257
2257
|
};
|
|
2258
2258
|
}
|
|
2259
2259
|
|
|
2260
|
-
function
|
|
2261
|
-
const ret = wasm.
|
|
2260
|
+
function __wasm_bindgen_func_elem_1860(arg0, arg1) {
|
|
2261
|
+
const ret = wasm.__wasm_bindgen_func_elem_1860(arg0, arg1);
|
|
2262
2262
|
return takeObject(ret);
|
|
2263
2263
|
}
|
|
2264
2264
|
|
|
2265
|
-
function
|
|
2266
|
-
wasm.
|
|
2265
|
+
function __wasm_bindgen_func_elem_4256(arg0, arg1, arg2) {
|
|
2266
|
+
wasm.__wasm_bindgen_func_elem_4256(arg0, arg1, addHeapObject(arg2));
|
|
2267
2267
|
}
|
|
2268
2268
|
|
|
2269
|
-
function
|
|
2270
|
-
wasm.
|
|
2269
|
+
function __wasm_bindgen_func_elem_12398(arg0, arg1, arg2, arg3) {
|
|
2270
|
+
wasm.__wasm_bindgen_func_elem_12398(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
|
|
2271
2271
|
}
|
|
2272
2272
|
|
|
2273
2273
|
const ClientFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
Binary file
|
|
@@ -93,11 +93,11 @@ export const virtualdataslice_setIntegerCol: (a: number, b: number, c: number, d
|
|
|
93
93
|
export const virtualdataslice_setStringCol: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
94
94
|
export const virtualserver_handleRequest: (a: number, b: number, c: number) => number;
|
|
95
95
|
export const virtualserver_new: (a: number, b: number) => void;
|
|
96
|
-
export const
|
|
97
|
-
export const
|
|
98
|
-
export const
|
|
99
|
-
export const
|
|
100
|
-
export const
|
|
96
|
+
export const __wasm_bindgen_func_elem_1146: (a: number, b: number) => void;
|
|
97
|
+
export const __wasm_bindgen_func_elem_4239: (a: number, b: number) => void;
|
|
98
|
+
export const __wasm_bindgen_func_elem_12398: (a: number, b: number, c: number, d: number) => void;
|
|
99
|
+
export const __wasm_bindgen_func_elem_4256: (a: number, b: number, c: number) => void;
|
|
100
|
+
export const __wasm_bindgen_func_elem_1860: (a: number, b: number) => number;
|
|
101
101
|
export const __wbindgen_export: (a: number, b: number) => number;
|
|
102
102
|
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
103
103
|
export const __wbindgen_export3: (a: number) => void;
|
package/package.json
CHANGED
package/src/rust/lib.rs
CHANGED
|
@@ -64,6 +64,9 @@ export type * from "../../src/ts/ts-rs/ViewConfig.d.ts";
|
|
|
64
64
|
export type * from "../../src/ts/ts-rs/JoinOptions.ts";
|
|
65
65
|
export type * from "../../src/ts/ts-rs/JoinType.ts";
|
|
66
66
|
export type * from "../../src/ts/ts-rs/TypedArrayWindow.ts";
|
|
67
|
+
export type * from "../../src/ts/ts-rs/Features.ts";
|
|
68
|
+
export type * from "../../src/ts/ts-rs/AggSpec.ts";
|
|
69
|
+
export type * from "../../src/ts/ts-rs/WindowAggSpec.ts";
|
|
67
70
|
|
|
68
71
|
import type {ColumnWindow} from "../../src/ts/ts-rs/ColumnWindow.d.ts";
|
|
69
72
|
import type {ColumnType} from "../../src/ts/ts-rs/ColumnType.d.ts";
|
|
@@ -78,6 +81,9 @@ import type {OnUpdateOptions} from "../../src/ts/ts-rs/OnUpdateOptions.d.ts";
|
|
|
78
81
|
import type {UpdateOptions} from "../../src/ts/ts-rs/UpdateOptions.d.ts";
|
|
79
82
|
import type {DeleteOptions} from "../../src/ts/ts-rs/DeleteOptions.d.ts";
|
|
80
83
|
import type {SystemInfo} from "../../src/ts/ts-rs/SystemInfo.d.ts";
|
|
84
|
+
import type {ViewConfig} from "../../src/ts/ts-rs/ViewConfig.d.ts";
|
|
85
|
+
import type {Scalar} from "../../src/ts/ts-rs/Scalar.d.ts";
|
|
86
|
+
import type {Features} from "../../src/ts/ts-rs/Features.ts";
|
|
81
87
|
"#;
|
|
82
88
|
|
|
83
89
|
#[cfg(feature = "export-init")]
|
package/src/rust/typed_array.rs
CHANGED
|
@@ -14,7 +14,7 @@ use std::io::Cursor;
|
|
|
14
14
|
|
|
15
15
|
use arrow_array::cast::AsArray;
|
|
16
16
|
use arrow_array::types::*;
|
|
17
|
-
use arrow_array::{Array as _, ArrowPrimitiveType, PrimitiveArray};
|
|
17
|
+
use arrow_array::{Array as _, ArrowPrimitiveType, DictionaryArray, PrimitiveArray, StringArray};
|
|
18
18
|
use arrow_ipc::reader::StreamReader;
|
|
19
19
|
use arrow_schema::{DataType, TimeUnit};
|
|
20
20
|
use js_sys::{Array, Function, JsString, Uint8Array};
|
|
@@ -219,13 +219,32 @@ pub(crate) async fn decode_and_call(
|
|
|
219
219
|
js_dicts.set(col_idx as u32, JsValue::NULL);
|
|
220
220
|
},
|
|
221
221
|
DataType::Dictionary(..) => {
|
|
222
|
-
let dict = col
|
|
222
|
+
let dict = col
|
|
223
|
+
.as_any()
|
|
224
|
+
.downcast_ref::<DictionaryArray<Int32Type>>()
|
|
225
|
+
.ok_or_else(|| {
|
|
226
|
+
JsValue::from_str(&format!(
|
|
227
|
+
"Unsupported dictionary key type for typed array: {}",
|
|
228
|
+
col.data_type()
|
|
229
|
+
))
|
|
230
|
+
})?;
|
|
231
|
+
|
|
223
232
|
let keys = dict.keys();
|
|
224
233
|
zero_invalid_slots(keys);
|
|
225
234
|
let arr = unsafe { js_sys::Int32Array::view(keys.values().as_ref()) };
|
|
226
235
|
js_values.set(col_idx as u32, arr.into());
|
|
227
236
|
|
|
228
|
-
let values = dict
|
|
237
|
+
let values = dict
|
|
238
|
+
.values()
|
|
239
|
+
.as_any()
|
|
240
|
+
.downcast_ref::<StringArray>()
|
|
241
|
+
.ok_or_else(|| {
|
|
242
|
+
JsValue::from_str(&format!(
|
|
243
|
+
"Unsupported dictionary value type for typed array: {}",
|
|
244
|
+
dict.values().data_type()
|
|
245
|
+
))
|
|
246
|
+
})?;
|
|
247
|
+
|
|
229
248
|
let js_dict = Array::new_with_length(values.len() as u32);
|
|
230
249
|
for i in 0..values.len() {
|
|
231
250
|
js_dict.set(i as u32, JsValue::from_str(values.value(i)));
|
|
@@ -74,6 +74,102 @@ fn jsvalue_to_scalar(val: &JsValue) -> perspective_client::config::Scalar {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
// This interface is the TypeScript contract for [`JsServerHandler`] below.
|
|
78
|
+
// There is no codegen tying the two together - every method dispatched via
|
|
79
|
+
// `Reflect::get` in this file MUST be declared here, with the exact argument
|
|
80
|
+
// and return types the `Reflect` call sites accept. Keep them in sync when
|
|
81
|
+
// editing either.
|
|
82
|
+
#[wasm_bindgen(typescript_custom_section)]
|
|
83
|
+
const TS_VIRTUAL_SERVER_HANDLER: &'static str = r#"
|
|
84
|
+
/**
|
|
85
|
+
* A table hosted by a `VirtualServerHandler`, as returned by
|
|
86
|
+
* `getHostedTables()`. A plain `string` is shorthand for `{ name }`.
|
|
87
|
+
*/
|
|
88
|
+
export interface VirtualHostedTable {
|
|
89
|
+
name: string;
|
|
90
|
+
index?: string;
|
|
91
|
+
limit?: number;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Handler interface that you implement to provide custom data sources.
|
|
96
|
+
*
|
|
97
|
+
* All methods will be called by the `VirtualServer` when handling protocol
|
|
98
|
+
* messages from Perspective clients. Methods can return values directly or
|
|
99
|
+
* return Promises for asynchronous operations (e.g., database queries).
|
|
100
|
+
* Optional methods fall back to defaults documented per-method.
|
|
101
|
+
*/
|
|
102
|
+
export interface VirtualServerHandler {
|
|
103
|
+
getHostedTables():
|
|
104
|
+
| (string | VirtualHostedTable)[]
|
|
105
|
+
| Promise<(string | VirtualHostedTable)[]>;
|
|
106
|
+
tableSchema(
|
|
107
|
+
tableId: string,
|
|
108
|
+
): Record<string, ColumnType> | Promise<Record<string, ColumnType>>;
|
|
109
|
+
tableSize(tableId: string): number | Promise<number>;
|
|
110
|
+
tableMakeView(
|
|
111
|
+
tableId: string,
|
|
112
|
+
viewId: string,
|
|
113
|
+
config: ViewConfigUpdate,
|
|
114
|
+
): void | Promise<void>;
|
|
115
|
+
viewDelete(viewId: string): void | Promise<void>;
|
|
116
|
+
viewGetData(
|
|
117
|
+
viewId: string,
|
|
118
|
+
config: ViewConfig,
|
|
119
|
+
schema: Record<string, ColumnType>,
|
|
120
|
+
viewport: ViewWindow,
|
|
121
|
+
dataSlice: VirtualDataSlice,
|
|
122
|
+
): void | Promise<void>;
|
|
123
|
+
|
|
124
|
+
/** Defaults to `tableSchema(viewId)`. */
|
|
125
|
+
viewSchema?(
|
|
126
|
+
viewId: string,
|
|
127
|
+
config: ViewConfig,
|
|
128
|
+
): Record<string, ColumnType> | Promise<Record<string, ColumnType>>;
|
|
129
|
+
|
|
130
|
+
/** Defaults to `tableSize(viewId)`. */
|
|
131
|
+
viewSize?(viewId: string): number | Promise<number>;
|
|
132
|
+
|
|
133
|
+
/** Defaults to the length of `tableSchema(tableId)`. */
|
|
134
|
+
tableColumnsSize?(tableId: string): number | Promise<number>;
|
|
135
|
+
|
|
136
|
+
/** Defaults to the length of `viewSchema(viewId, config)`. */
|
|
137
|
+
viewColumnSize?(
|
|
138
|
+
viewId: string,
|
|
139
|
+
config: ViewConfig,
|
|
140
|
+
): number | Promise<number>;
|
|
141
|
+
|
|
142
|
+
/** Required when `getFeatures()` reports `expressions: true`. */
|
|
143
|
+
tableValidateExpression?(
|
|
144
|
+
tableId: string,
|
|
145
|
+
expression: string,
|
|
146
|
+
): ColumnType | Promise<ColumnType>;
|
|
147
|
+
|
|
148
|
+
viewGetMinMax?(
|
|
149
|
+
viewId: string,
|
|
150
|
+
columnName: string,
|
|
151
|
+
config: ViewConfig,
|
|
152
|
+
): { min: Scalar; max: Scalar } | Promise<{ min: Scalar; max: Scalar }>;
|
|
153
|
+
|
|
154
|
+
/** Defaults to no optional features. */
|
|
155
|
+
getFeatures?(): Features | Promise<Features>;
|
|
156
|
+
|
|
157
|
+
/** Defaults to port `0`. */
|
|
158
|
+
tableMakePort?(): number | Promise<number>;
|
|
159
|
+
|
|
160
|
+
makeTable?(
|
|
161
|
+
tableId: string,
|
|
162
|
+
data: string | Uint8Array,
|
|
163
|
+
): void | Promise<void>;
|
|
164
|
+
}
|
|
165
|
+
"#;
|
|
166
|
+
|
|
167
|
+
#[wasm_bindgen]
|
|
168
|
+
extern "C" {
|
|
169
|
+
#[wasm_bindgen(typescript_type = "VirtualServerHandler")]
|
|
170
|
+
pub type JsVirtualServerHandler;
|
|
171
|
+
}
|
|
172
|
+
|
|
77
173
|
pub struct JsServerHandler(Object);
|
|
78
174
|
|
|
79
175
|
impl JsServerHandler {
|
|
@@ -785,9 +881,9 @@ pub struct VirtualServer(Rc<UnsafeCell<virtual_server::VirtualServer<JsServerHan
|
|
|
785
881
|
#[wasm_bindgen]
|
|
786
882
|
impl VirtualServer {
|
|
787
883
|
#[wasm_bindgen(constructor)]
|
|
788
|
-
pub fn new(handler:
|
|
884
|
+
pub fn new(handler: JsVirtualServerHandler) -> Result<VirtualServer, JsValue> {
|
|
789
885
|
Ok(VirtualServer(Rc::new(UnsafeCell::new(
|
|
790
|
-
virtual_server::VirtualServer::new(JsServerHandler(handler)),
|
|
886
|
+
virtual_server::VirtualServer::new(JsServerHandler(handler.unchecked_into())),
|
|
791
887
|
))))
|
|
792
888
|
}
|
|
793
889
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
import type { ColumnType } from "./ColumnType.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Specification for an aggregate function.
|
|
6
|
+
*
|
|
7
|
+
* Aggregates can either take no additional arguments ([`AggSpec::Single`])
|
|
8
|
+
* or require column type arguments ([`AggSpec::Multiple`]).
|
|
9
|
+
*/
|
|
10
|
+
export type AggSpec = string | [string, Array<ColumnType>];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
import type { AggSpec } from "./AggSpec.js";
|
|
3
|
+
import type { ColumnType } from "./ColumnType.js";
|
|
4
|
+
import type { GroupRollupMode } from "./GroupRollupMode.js";
|
|
5
|
+
import type { SplitRollupMode } from "./SplitRollupMode.js";
|
|
6
|
+
import type { WindowAggSpec } from "./WindowAggSpec.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Describes the capabilities supported by a virtual server handler.
|
|
10
|
+
*
|
|
11
|
+
* This struct is returned by
|
|
12
|
+
* [`VirtualServerHandler::get_features`](super::VirtualServerHandler::get_features)
|
|
13
|
+
* to inform clients about which operations are available.
|
|
14
|
+
*/
|
|
15
|
+
export type Features = {
|
|
16
|
+
/**
|
|
17
|
+
* Whether group-by aggregation is supported.
|
|
18
|
+
*/
|
|
19
|
+
group_by?: boolean,
|
|
20
|
+
/**
|
|
21
|
+
* Which `group_by_rollup_mode` options are supported
|
|
22
|
+
*/
|
|
23
|
+
group_rollup_mode?: Array<GroupRollupMode>,
|
|
24
|
+
/**
|
|
25
|
+
* Whether split-by (pivot) operations are supported.
|
|
26
|
+
*/
|
|
27
|
+
split_by?: boolean,
|
|
28
|
+
/**
|
|
29
|
+
* Which `split_rollup_mode` options are supported. Empty (the default)
|
|
30
|
+
* means `["flat"]` - a server must opt in to `"rollup"` explicitly, as
|
|
31
|
+
* it requires emitting subtotal and grand-total column groups.
|
|
32
|
+
*/
|
|
33
|
+
split_rollup_mode?: Array<SplitRollupMode>,
|
|
34
|
+
/**
|
|
35
|
+
* Available filter operators per column type.
|
|
36
|
+
*/
|
|
37
|
+
filter_ops?: { [key in ColumnType]?: Array<string> },
|
|
38
|
+
/**
|
|
39
|
+
* Available aggregate functions per column type.
|
|
40
|
+
*/
|
|
41
|
+
aggregates?: { [key in ColumnType]?: Array<AggSpec> },
|
|
42
|
+
/**
|
|
43
|
+
* Whether sorting is supported.
|
|
44
|
+
*/
|
|
45
|
+
sort?: boolean,
|
|
46
|
+
/**
|
|
47
|
+
* Whether computed expressions are supported.
|
|
48
|
+
*/
|
|
49
|
+
expressions?: boolean,
|
|
50
|
+
/**
|
|
51
|
+
* Available window aggregates per column type.
|
|
52
|
+
*/
|
|
53
|
+
window_aggregates?: { [key in ColumnType]?: Array<WindowAggSpec> },
|
|
54
|
+
/**
|
|
55
|
+
* Whether update callbacks are supported.
|
|
56
|
+
*/
|
|
57
|
+
on_update?: boolean,
|
|
58
|
+
/**
|
|
59
|
+
* The data store has no reliable natural row order
|
|
60
|
+
*/
|
|
61
|
+
unordered?: boolean, };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The `split_by` corollary to [`GroupRollupMode`]. `Flat` (the default,
|
|
5
|
+
* matching this crate's historical behavior) emits only full-depth split
|
|
6
|
+
* combinations as columns; `Rollup` additionally emits grand-total and
|
|
7
|
+
* subtotal column groups in "totals before" order. There is no `Total`
|
|
8
|
+
* variant - an empty `split_by` already expresses a single grand-total
|
|
9
|
+
* column group.
|
|
10
|
+
*/
|
|
11
|
+
export type SplitRollupMode = "flat" | "rollup";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
import type { ListFlatten } from "./ListFlatten.js";
|
|
2
3
|
import type { TableReadFormat } from "./TableReadFormat.js";
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -24,4 +25,12 @@ limit?: number,
|
|
|
24
25
|
* instead of memory. On native targets this is a memory-mapped file; on
|
|
25
26
|
* WASM it is OPFS (Worker only). Defaults to in-memory.
|
|
26
27
|
*/
|
|
27
|
-
page_to_disk?: boolean,
|
|
28
|
+
page_to_disk?: boolean,
|
|
29
|
+
/**
|
|
30
|
+
* How Arrow `LIST` and JSON `Array` columns are ingested. `zip` (the
|
|
31
|
+
* default) and `cartesian` expand a row into one row per list element,
|
|
32
|
+
* and are incompatible with `index`, as the rows of an expansion
|
|
33
|
+
* repeat their index. `stringify` encodes each list as a JSON array in
|
|
34
|
+
* a single string column instead.
|
|
35
|
+
*/
|
|
36
|
+
list_flatten?: ListFlatten, };
|
|
@@ -5,5 +5,7 @@ import type { Filter } from "./Filter.js";
|
|
|
5
5
|
import type { FilterReducer } from "./FilterReducer.js";
|
|
6
6
|
import type { GroupRollupMode } from "./GroupRollupMode.js";
|
|
7
7
|
import type { Sort } from "./Sort.js";
|
|
8
|
+
import type { SplitRollupMode } from "./SplitRollupMode.js";
|
|
9
|
+
import type { Windows } from "./Windows.js";
|
|
8
10
|
|
|
9
|
-
export type ViewConfig = { group_by: Array<string>, split_by: Array<string>, sort: Array<Sort>, filter: Array<Filter>, group_rollup_mode: GroupRollupMode, filter_op?: FilterReducer, expressions: Expressions, columns: Array<string | null>, aggregates: { [key in string]?: Aggregate }, group_by_depth?: number | null, };
|
|
11
|
+
export type ViewConfig = { group_by: Array<string>, split_by: Array<string>, sort: Array<Sort>, filter: Array<Filter>, group_rollup_mode: GroupRollupMode, split_rollup_mode: SplitRollupMode, filter_op?: FilterReducer, expressions: Expressions, windows?: Windows, columns: Array<string | null>, aggregates: { [key in string]?: Aggregate }, group_by_depth?: number | null, };
|