@perspective-dev/client 5.6.1 → 5.7.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.
Files changed (142) hide show
  1. package/README.md +5 -1
  2. package/dist/cdn/perspective.js +3 -2
  3. package/dist/cdn/perspective.js.map +4 -4
  4. package/dist/esm/perspective.browser.d.ts +71 -17
  5. package/dist/esm/perspective.js +2 -2
  6. package/dist/esm/perspective.js.map +4 -4
  7. package/dist/esm/perspective.node.d.ts +20 -3
  8. package/dist/esm/perspective.node.js +664 -35
  9. package/dist/esm/perspective.node.js.map +4 -4
  10. package/dist/esm/public_types.d.ts +31 -0
  11. package/dist/esm/virtual_servers/clickhouse.d.ts +37 -0
  12. package/dist/esm/virtual_servers/clickhouse.js +1 -1
  13. package/dist/esm/virtual_servers/clickhouse.js.map +3 -3
  14. package/dist/esm/virtual_servers/duckdb.d.ts +14 -9
  15. package/dist/esm/virtual_servers/duckdb.js +1 -1
  16. package/dist/esm/virtual_servers/duckdb.js.map +3 -3
  17. package/dist/esm/wasm/cdn.d.ts +12 -0
  18. package/dist/esm/wasm/migrate.d.ts +40 -0
  19. package/dist/esm/wasm/registry.d.ts +123 -0
  20. package/dist/esm/wasm/registry.js +3 -0
  21. package/dist/esm/wasm/registry.js.map +7 -0
  22. package/{src/ts/ts-rs/AggSpec.ts → dist/ts-rs/AggSpec.d.ts} +1 -1
  23. package/{src/ts/ts-rs/Features.ts → dist/ts-rs/Features.d.ts} +16 -6
  24. package/{src/ts/ts-rs/Filter.ts → dist/ts-rs/Filter.d.ts} +1 -1
  25. package/{src/ts/ts-rs/FilterTerm.ts → dist/ts-rs/FilterTerm.d.ts} +1 -1
  26. package/{src/ts/ts-rs/JoinOptions.ts → dist/ts-rs/JoinOptions.d.ts} +1 -1
  27. package/dist/ts-rs/ListFlatten.d.ts +3 -0
  28. package/dist/ts-rs/MapFlatten.d.ts +3 -0
  29. package/{src/ts/ts-rs/OnRemoveData.ts → dist/ts-rs/OnRemoveData.d.ts} +1 -1
  30. package/{src/ts/ts-rs/OnUpdateData.ts → dist/ts-rs/OnUpdateData.d.ts} +1 -1
  31. package/{src/ts/ts-rs/OnUpdateOptions.ts → dist/ts-rs/OnUpdateOptions.d.ts} +1 -1
  32. package/{src/ts/ts-rs/Sort.ts → dist/ts-rs/Sort.d.ts} +1 -1
  33. package/dist/ts-rs/StructFlatten.d.ts +3 -0
  34. package/dist/ts-rs/TableIndex.d.ts +9 -0
  35. package/dist/ts-rs/TableInitOptions.d.ts +65 -0
  36. package/{src/ts/ts-rs/UpdateOptions.ts → dist/ts-rs/UpdateOptions.d.ts} +1 -1
  37. package/{src/ts/ts-rs/ViewConfig.ts → dist/ts-rs/ViewConfig.d.ts} +8 -8
  38. package/{src/ts/ts-rs/ViewConfigUpdate.ts → dist/ts-rs/ViewConfigUpdate.d.ts} +8 -8
  39. package/{src/ts/ts-rs/WindowAggSpec.ts → dist/ts-rs/WindowAggSpec.d.ts} +1 -1
  40. package/{src/ts/ts-rs/WindowSort.ts → dist/ts-rs/WindowSort.d.ts} +1 -1
  41. package/{src/ts/ts-rs/WindowSpec.ts → dist/ts-rs/WindowSpec.d.ts} +1 -1
  42. package/{src/ts/ts-rs/Windows.ts → dist/ts-rs/Windows.d.ts} +1 -1
  43. package/dist/wasm/perspective-js.d.ts +121 -54
  44. package/dist/wasm/perspective-js.js +123 -20
  45. package/dist/wasm/perspective-js.wasm +0 -0
  46. package/dist/wasm/perspective-js.wasm.d.ts +10 -6
  47. package/dist/wasm/perspective-migrate-js.d.ts +41 -0
  48. package/dist/wasm/perspective-migrate-js.js +524 -0
  49. package/dist/wasm/perspective-migrate-js.wasm +0 -0
  50. package/dist/wasm/perspective-migrate-js.wasm.d.ts +8 -0
  51. package/package.json +30 -15
  52. package/dist/esm/ts-rs/AggSpec.d.ts +0 -8
  53. package/dist/esm/ts-rs/Aggregate.d.ts +0 -1
  54. package/dist/esm/ts-rs/ColumnType.d.ts +0 -4
  55. package/dist/esm/ts-rs/ColumnWindow.d.ts +0 -4
  56. package/dist/esm/ts-rs/DeleteOptions.d.ts +0 -6
  57. package/dist/esm/ts-rs/Expressions.d.ts +0 -3
  58. package/dist/esm/ts-rs/Features.d.ts +0 -71
  59. package/dist/esm/ts-rs/Filter.d.ts +0 -2
  60. package/dist/esm/ts-rs/FilterReducer.d.ts +0 -1
  61. package/dist/esm/ts-rs/FilterTerm.d.ts +0 -2
  62. package/dist/esm/ts-rs/GroupRollupMode.d.ts +0 -1
  63. package/dist/esm/ts-rs/JoinOptions.d.ts +0 -9
  64. package/dist/esm/ts-rs/JoinType.d.ts +0 -1
  65. package/dist/esm/ts-rs/ListFlatten.d.ts +0 -1
  66. package/dist/esm/ts-rs/OnRemoveData.d.ts +0 -6
  67. package/dist/esm/ts-rs/OnUpdateData.d.ts +0 -6
  68. package/dist/esm/ts-rs/OnUpdateMode.d.ts +0 -9
  69. package/dist/esm/ts-rs/OnUpdateOptions.d.ts +0 -7
  70. package/dist/esm/ts-rs/Scalar.d.ts +0 -5
  71. package/dist/esm/ts-rs/Sort.d.ts +0 -2
  72. package/dist/esm/ts-rs/SortDir.d.ts +0 -1
  73. package/dist/esm/ts-rs/SplitRollupMode.d.ts +0 -9
  74. package/dist/esm/ts-rs/SystemInfo.d.ts +0 -40
  75. package/dist/esm/ts-rs/TableInitOptions.d.ts +0 -45
  76. package/dist/esm/ts-rs/TableReadFormat.d.ts +0 -7
  77. package/dist/esm/ts-rs/TypedArrayWindow.d.ts +0 -33
  78. package/dist/esm/ts-rs/UpdateOptions.d.ts +0 -8
  79. package/dist/esm/ts-rs/ViewConfig.d.ts +0 -24
  80. package/dist/esm/ts-rs/ViewConfigUpdate.d.ts +0 -116
  81. package/dist/esm/ts-rs/ViewOnRemoveResp.d.ts +0 -4
  82. package/dist/esm/ts-rs/ViewOnUpdateResp.d.ts +0 -4
  83. package/dist/esm/ts-rs/ViewWindow.d.ts +0 -30
  84. package/dist/esm/ts-rs/WindowAggSpec.d.ts +0 -25
  85. package/dist/esm/ts-rs/WindowSort.d.ts +0 -7
  86. package/dist/esm/ts-rs/WindowSortDir.d.ts +0 -6
  87. package/dist/esm/ts-rs/WindowSpec.d.ts +0 -47
  88. package/dist/esm/ts-rs/Windows.d.ts +0 -10
  89. package/src/rust/client.rs +0 -590
  90. package/src/rust/generic_sql_model.rs +0 -276
  91. package/src/rust/lib.rs +0 -99
  92. package/src/rust/table.rs +0 -397
  93. package/src/rust/table_data.rs +0 -164
  94. package/src/rust/typed_array.rs +0 -386
  95. package/src/rust/utils/browser.rs +0 -35
  96. package/src/rust/utils/console_logger.rs +0 -237
  97. package/src/rust/utils/errors.rs +0 -274
  98. package/src/rust/utils/futures.rs +0 -274
  99. package/src/rust/utils/json.rs +0 -252
  100. package/src/rust/utils/local_poll_loop.rs +0 -63
  101. package/src/rust/utils/mod.rs +0 -32
  102. package/src/rust/utils/serde.rs +0 -46
  103. package/src/rust/utils/trace_allocator.rs +0 -98
  104. package/src/rust/view.rs +0 -463
  105. package/src/rust/virtual_server.rs +0 -991
  106. package/src/ts/perspective-server.worker.ts +0 -74
  107. package/src/ts/perspective.browser.ts +0 -380
  108. package/src/ts/perspective.cdn.ts +0 -28
  109. package/src/ts/perspective.node.ts +0 -556
  110. package/src/ts/ts-rs/ListFlatten.ts +0 -3
  111. package/src/ts/ts-rs/TableInitOptions.ts +0 -42
  112. package/src/ts/virtual_server.ts +0 -83
  113. package/src/ts/virtual_servers/clickhouse.ts +0 -533
  114. package/src/ts/virtual_servers/duckdb.ts +0 -549
  115. package/src/ts/wasm/browser.ts +0 -134
  116. package/src/ts/wasm/cdn.ts +0 -32
  117. package/src/ts/wasm/decompress.ts +0 -83
  118. package/src/ts/wasm/emscripten_api.ts +0 -91
  119. package/src/ts/wasm/engine.ts +0 -309
  120. package/src/ts/wasm/features.ts +0 -31
  121. package/src/ts/wasm/perspective-server.poly.ts +0 -460
  122. package/src/ts/websocket.ts +0 -95
  123. package/tsconfig.json +0 -22
  124. /package/{src/ts/ts-rs/Aggregate.ts → dist/ts-rs/Aggregate.d.ts} +0 -0
  125. /package/{src/ts/ts-rs/ColumnType.ts → dist/ts-rs/ColumnType.d.ts} +0 -0
  126. /package/{src/ts/ts-rs/ColumnWindow.ts → dist/ts-rs/ColumnWindow.d.ts} +0 -0
  127. /package/{src/ts/ts-rs/DeleteOptions.ts → dist/ts-rs/DeleteOptions.d.ts} +0 -0
  128. /package/{src/ts/ts-rs/Expressions.ts → dist/ts-rs/Expressions.d.ts} +0 -0
  129. /package/{src/ts/ts-rs/FilterReducer.ts → dist/ts-rs/FilterReducer.d.ts} +0 -0
  130. /package/{src/ts/ts-rs/GroupRollupMode.ts → dist/ts-rs/GroupRollupMode.d.ts} +0 -0
  131. /package/{src/ts/ts-rs/JoinType.ts → dist/ts-rs/JoinType.d.ts} +0 -0
  132. /package/{src/ts/ts-rs/OnUpdateMode.ts → dist/ts-rs/OnUpdateMode.d.ts} +0 -0
  133. /package/{src/ts/ts-rs/Scalar.ts → dist/ts-rs/Scalar.d.ts} +0 -0
  134. /package/{src/ts/ts-rs/SortDir.ts → dist/ts-rs/SortDir.d.ts} +0 -0
  135. /package/{src/ts/ts-rs/SplitRollupMode.ts → dist/ts-rs/SplitRollupMode.d.ts} +0 -0
  136. /package/{src/ts/ts-rs/SystemInfo.ts → dist/ts-rs/SystemInfo.d.ts} +0 -0
  137. /package/{src/ts/ts-rs/TableReadFormat.ts → dist/ts-rs/TableReadFormat.d.ts} +0 -0
  138. /package/{src/ts/ts-rs/TypedArrayWindow.ts → dist/ts-rs/TypedArrayWindow.d.ts} +0 -0
  139. /package/{src/ts/ts-rs/ViewOnRemoveResp.ts → dist/ts-rs/ViewOnRemoveResp.d.ts} +0 -0
  140. /package/{src/ts/ts-rs/ViewOnUpdateResp.ts → dist/ts-rs/ViewOnUpdateResp.d.ts} +0 -0
  141. /package/{src/ts/ts-rs/ViewWindow.ts → dist/ts-rs/ViewWindow.d.ts} +0 -0
  142. /package/{src/ts/ts-rs/WindowSortDir.ts → dist/ts-rs/WindowSortDir.d.ts} +0 -0
@@ -1,74 +0,0 @@
1
- // ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2
- // ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
3
- // ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
4
- // ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
5
- // ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
6
- // ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7
- // ┃ Copyright (c) 2017, the Perspective Authors. ┃
8
- // ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9
- // ┃ This file is part of the Perspective library, distributed under the terms ┃
10
- // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11
- // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
-
13
- import {
14
- PerspectiveSession,
15
- PerspectiveServer,
16
- PerspectivePollThread,
17
- } from "./wasm/engine.ts";
18
- import { compile_perspective } from "./wasm/emscripten_api.ts";
19
-
20
- let GLOBAL_SERVER: PerspectiveServer;
21
- let POLL_THREAD: PerspectivePollThread;
22
-
23
- let SESSION: PerspectiveSession | undefined;
24
-
25
- async function handleMessage(this: MessagePort, msg: MessageEvent) {
26
- if (msg.data.cmd === "init") {
27
- const id = msg.data.id;
28
- if (!GLOBAL_SERVER) {
29
- const module = await compile_perspective(msg.data.args[0]);
30
-
31
- GLOBAL_SERVER = new PerspectiveServer(module, {
32
- on_poll_request: () => POLL_THREAD.on_poll_request(),
33
- });
34
-
35
- POLL_THREAD = new PerspectivePollThread(GLOBAL_SERVER);
36
- }
37
-
38
- SESSION = GLOBAL_SERVER.make_session(async (resp) => {
39
- const f = resp.slice().buffer;
40
- this.postMessage(f, { transfer: [f] });
41
- });
42
-
43
- this.postMessage({ id });
44
- } else {
45
- if (SESSION) {
46
- await SESSION?.handle_request(new Uint8Array(msg.data));
47
- } else {
48
- throw new Error("No session");
49
- }
50
- }
51
- }
52
-
53
- function bindPortSharedWorker(msg: MessageEvent) {
54
- const port = msg.ports[0];
55
- port.addEventListener("message", handleMessage.bind(port));
56
- port.start();
57
- }
58
-
59
- /**
60
- * Provided by `@perspective-dev/esbuild-plugin/worker`, which replaces this
61
- * module with a stub when it is imported (rather than built as an entry
62
- * point). Constructs a `Worker` from the bundled source, or falls back to
63
- * running it on the main thread and returns a `MessagePort` to it.
64
- */
65
- export declare function initialize(
66
- opts?: WorkerOptions,
67
- ): Promise<Worker | MessagePort>;
68
-
69
- // @ts-expect-error wrong scope
70
- self.addEventListener("connect", bindPortSharedWorker);
71
- self.addEventListener(
72
- "message",
73
- handleMessage.bind(self as unknown as MessagePort),
74
- );
@@ -1,380 +0,0 @@
1
- // ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2
- // ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
3
- // ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
4
- // ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
5
- // ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
6
- // ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7
- // ┃ Copyright (c) 2017, the Perspective Authors. ┃
8
- // ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9
- // ┃ This file is part of the Perspective library, distributed under the terms ┃
10
- // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11
- // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
-
13
- export type * from "../../dist/wasm/perspective-js.d.ts";
14
- import type * as psp from "../../dist/wasm/perspective-js.d.ts";
15
- export type * from "./virtual_server.ts";
16
- import * as psp_virtual from "./virtual_server.ts";
17
- import * as wasm_module from "../../dist/wasm/perspective-js.js";
18
- import * as api from "./wasm/browser.ts";
19
- import { load_wasm_stage_0 } from "./wasm/decompress.ts";
20
- import { host_supports_memory64 } from "./wasm/features.ts";
21
- export { host_supports_memory64 } from "./wasm/features.ts";
22
-
23
- export {
24
- GenericSQLVirtualServerModel,
25
- VirtualDataSlice,
26
- VirtualServer,
27
- } from "../../dist/wasm/perspective-js.js";
28
-
29
- import {
30
- GenericSQLVirtualServerModel,
31
- VirtualDataSlice,
32
- VirtualServer,
33
- } from "../../dist/wasm/perspective-js.js";
34
-
35
- /**
36
- * A single Perspective engine binary, in any form `init_server` accepts.
37
- * Thunk sources are only invoked if selected — register both bitnesses as
38
- * `() => fetch(...)` and only the winning binary is ever downloaded.
39
- */
40
- export type ServerWasmSource =
41
- | Uint8Array
42
- | ArrayBuffer
43
- | Response
44
- | WebAssembly.Module
45
- | Promise<ArrayBuffer | Response | WebAssembly.Module>
46
- | (() => Promise<ArrayBuffer | Response | WebAssembly.Module>);
47
-
48
- /**
49
- * Engine binaries by bitness. Registering `wasm64` is the opt-in for the
50
- * Memory64 engine (4GB heap ceiling raised to 16GB, at some engine
51
- * performance cost) — it is selected whenever the host supports Memory64.
52
- */
53
- export interface ServerWasmRegistration {
54
- wasm32?: ServerWasmSource;
55
- wasm64?: ServerWasmSource;
56
- }
57
-
58
- export interface InitServerOptions {
59
- disable_stage_0?: boolean;
60
- }
61
-
62
- interface ServerWasmRegistry extends ServerWasmRegistration {
63
- sole?: ServerWasmSource;
64
- disable_stage_0: boolean;
65
- }
66
-
67
- let SERVER_REGISTRY: ServerWasmRegistry | undefined;
68
- let GLOBAL_SERVER_WASM: Promise<ArrayBuffer | WebAssembly.Module> | undefined;
69
-
70
- export async function createMessageHandler(
71
- handler: psp_virtual.VirtualServerHandler,
72
- ) {
73
- return psp_virtual.createMessageHandler(await get_client(), handler);
74
- }
75
-
76
- function is_wasm_source(
77
- wasm: ServerWasmSource | ServerWasmRegistration,
78
- ): wasm is ServerWasmSource {
79
- return (
80
- wasm instanceof Uint8Array ||
81
- wasm instanceof ArrayBuffer ||
82
- (typeof Response !== "undefined" && wasm instanceof Response) ||
83
- wasm instanceof Promise ||
84
- wasm instanceof WebAssembly.Module ||
85
- typeof wasm === "function"
86
- );
87
- }
88
-
89
- async function materialize_server_wasm(
90
- source: ServerWasmSource,
91
- disable_stage_0: boolean,
92
- ): Promise<ArrayBuffer | WebAssembly.Module> {
93
- let wasm = typeof source === "function" ? await source() : await source;
94
- if (wasm instanceof Uint8Array) {
95
- wasm = wasm.buffer as ArrayBuffer;
96
- }
97
-
98
- if (typeof Response !== "undefined" && wasm instanceof Response) {
99
- if (!wasm.ok) {
100
- throw new Error(
101
- `Failed to fetch perspective server wasm (HTTP ${wasm.status} "${wasm.url}")`,
102
- );
103
- }
104
-
105
- if (disable_stage_0) {
106
- return await wasm.arrayBuffer();
107
- }
108
- }
109
-
110
- if (disable_stage_0) {
111
- return wasm as ArrayBuffer | WebAssembly.Module;
112
- }
113
-
114
- const bytes = await load_wasm_stage_0(wasm);
115
- return bytes.buffer as ArrayBuffer;
116
- }
117
-
118
- async function select_server_wasm(
119
- registry: ServerWasmRegistry,
120
- ): Promise<ArrayBuffer | WebAssembly.Module> {
121
- if (registry.sole !== undefined) {
122
- return await materialize_server_wasm(
123
- registry.sole,
124
- registry.disable_stage_0,
125
- );
126
- }
127
-
128
- // A lone `wasm64` registration is an explicit opt-in and is used as-is
129
- // regardless of the probe (an unsupporting host fails at instantiation,
130
- // which is the correct error).
131
- if (
132
- registry.wasm64 !== undefined &&
133
- (registry.wasm32 === undefined || host_supports_memory64())
134
- ) {
135
- try {
136
- return await materialize_server_wasm(
137
- registry.wasm64,
138
- registry.disable_stage_0,
139
- );
140
- } catch (e) {
141
- if (registry.wasm32 === undefined) {
142
- throw e;
143
- }
144
-
145
- console.warn(
146
- "Memory64 perspective server wasm failed to load, falling back to wasm32",
147
- e,
148
- );
149
- }
150
- }
151
-
152
- return await materialize_server_wasm(
153
- registry.wasm32!,
154
- registry.disable_stage_0,
155
- );
156
- }
157
-
158
- /**
159
- * Register the Perspective engine ("server") WebAssembly binary that backs
160
- * `worker()`.
161
- *
162
- * The single-argument form registers one binary of either bitness. The
163
- * object form registers a wasm32 and/or wasm64 (Memory64) binary; the wasm64
164
- * binary is preferred whenever the host supports Memory64, raising the
165
- * engine's heap ceiling from 4GB to 16GB (at some engine performance cost —
166
- * register only `wasm32` to opt out). Sources registered as thunks are only
167
- * invoked if selected, so the losing binary is never downloaded; if the
168
- * selected wasm64 source fails to load and a wasm32 source is also
169
- * registered, selection falls back to wasm32 with a console warning.
170
- *
171
- * Selection and download are deferred to the first `worker()` call.
172
- *
173
- * # Examples
174
- *
175
- * ```javascript
176
- * perspective.init_server(
177
- * fetch("perspective-server.wasm"),
178
- * );
179
- *
180
- * perspective.init_server({
181
- * wasm32: () => fetch("perspective-server.wasm"),
182
- * wasm64: () => fetch("perspective-server.memory64.wasm"),
183
- * });
184
- * ```
185
- */
186
- export function init_server(
187
- wasm: ServerWasmSource | ServerWasmRegistration,
188
- options: boolean | InitServerOptions = false,
189
- ) {
190
- const disable_stage_0 =
191
- typeof options === "boolean" ? options : !!options.disable_stage_0;
192
-
193
- GLOBAL_SERVER_WASM = undefined;
194
- if (is_wasm_source(wasm)) {
195
- SERVER_REGISTRY = { sole: wasm, disable_stage_0 };
196
- return;
197
- }
198
-
199
- // `WebAssembly.Module`'s lib type is structurally empty, so TypeScript
200
- // can't negatively narrow this branch itself.
201
- const registration = wasm as ServerWasmRegistration;
202
- if (
203
- registration.wasm32 !== undefined ||
204
- registration.wasm64 !== undefined
205
- ) {
206
- SERVER_REGISTRY = {
207
- wasm32: registration.wasm32,
208
- wasm64: registration.wasm64,
209
- disable_stage_0,
210
- };
211
- } else {
212
- throw new Error(
213
- "init_server requires a wasm source or a {wasm32, wasm64} registration",
214
- );
215
- }
216
- }
217
-
218
- let GLOBAL_CLIENT_WASM: Promise<typeof psp>;
219
- let GLOBAL_CLIENT_MODULE: Promise<WebAssembly.Module> | undefined;
220
-
221
- async function compile_module(wasm: any): Promise<WebAssembly.Module> {
222
- if (wasm instanceof WebAssembly.Module) {
223
- return wasm;
224
- }
225
-
226
- if (typeof Response !== "undefined" && wasm instanceof Response) {
227
- return WebAssembly.compileStreaming(wasm);
228
- }
229
-
230
- return WebAssembly.compile(wasm);
231
- }
232
-
233
- async function compilerize(
234
- wasm: PerspectiveWasm,
235
- disable_stage_0: boolean = false,
236
- ) {
237
- const wasm_buff = disable_stage_0 ? wasm : await load_wasm_stage_0(wasm);
238
- const compiled = await compile_module(wasm_buff);
239
- GLOBAL_CLIENT_MODULE = Promise.resolve(compiled);
240
- await wasm_module.default({ module_or_path: compiled });
241
- await wasm_module.init();
242
- return wasm_module;
243
- }
244
-
245
- export type PerspectiveWasm =
246
- | ArrayBuffer
247
- | Response
248
- | typeof psp
249
- | Promise<ArrayBuffer | Response | Object>;
250
-
251
- export function init_client(wasm: PerspectiveWasm, disable_stage_0 = false) {
252
- if (wasm instanceof Uint8Array) {
253
- GLOBAL_CLIENT_WASM = compilerize(
254
- wasm.buffer as ArrayBuffer,
255
- disable_stage_0,
256
- );
257
- } else if (wasm instanceof ArrayBuffer) {
258
- GLOBAL_CLIENT_WASM = compilerize(wasm, disable_stage_0);
259
- } else if (wasm instanceof Response) {
260
- GLOBAL_CLIENT_WASM = compilerize(wasm, disable_stage_0);
261
- } else if (wasm instanceof Promise) {
262
- GLOBAL_CLIENT_WASM = compilerize(wasm, disable_stage_0);
263
- } else if (wasm instanceof Object) {
264
- GLOBAL_CLIENT_WASM = Promise.resolve(wasm as typeof psp);
265
- }
266
- }
267
-
268
- function get_client() {
269
- const viewer_class: any = customElements.get("perspective-viewer");
270
- if (viewer_class) {
271
- GLOBAL_CLIENT_WASM = Promise.resolve(viewer_class.__wasm_module__);
272
- if (
273
- GLOBAL_CLIENT_MODULE === undefined &&
274
- viewer_class.__wasm_client_module__
275
- ) {
276
- GLOBAL_CLIENT_MODULE = Promise.resolve(
277
- viewer_class.__wasm_client_module__,
278
- );
279
- }
280
- } else if (GLOBAL_CLIENT_WASM === undefined) {
281
- throw new Error("Missing perspective-client.wasm");
282
- }
283
-
284
- return GLOBAL_CLIENT_WASM;
285
- }
286
-
287
- /**
288
- * Returns the compiled `WebAssembly.Module` for the perspective-js client
289
- * runtime. The module is structured-cloneable, so it can be sent via
290
- * `postMessage` to a Worker which can instantiate its own `Client` without
291
- * re-fetching or re-compiling the wasm binary.
292
- *
293
- * Requires that the client wasm has been initialized — typically by a prior
294
- * call to `init_client(...)`, or implicitly by mounting a `<perspective-viewer>`
295
- * element. Throws otherwise.
296
- *
297
- * # Examples
298
- *
299
- * ```javascript
300
- * const mod = await perspective.getCompiledClientWasm();
301
- * worker.postMessage({ kind: "init", clientWasm: mod }, [port]);
302
- * ```
303
- */
304
- export async function getCompiledClientWasm(): Promise<WebAssembly.Module> {
305
- if (GLOBAL_CLIENT_MODULE !== undefined) {
306
- return GLOBAL_CLIENT_MODULE;
307
- }
308
-
309
- const viewer_class: any = customElements.get("perspective-viewer");
310
- if (viewer_class?.__wasm_client_module__) {
311
- GLOBAL_CLIENT_MODULE = Promise.resolve(
312
- viewer_class.__wasm_client_module__,
313
- );
314
- return GLOBAL_CLIENT_MODULE;
315
- }
316
-
317
- throw new Error(
318
- "perspective-js client wasm has not been compiled yet — call " +
319
- "`init_client(...)` or `perspective.worker()` before " +
320
- "`getCompiledClientWasm()`.",
321
- );
322
- }
323
-
324
- function get_server() {
325
- if (SERVER_REGISTRY === undefined) {
326
- throw new Error("Missing perspective-server.wasm");
327
- }
328
-
329
- if (GLOBAL_SERVER_WASM === undefined) {
330
- GLOBAL_SERVER_WASM = select_server_wasm(SERVER_REGISTRY);
331
- }
332
-
333
- return GLOBAL_SERVER_WASM.then((x) =>
334
- x instanceof WebAssembly.Module ? x : x.slice(0),
335
- );
336
- }
337
-
338
- let GLOBAL_WORKER: undefined | (() => Promise<Worker>) = undefined;
339
-
340
- // `WorkerPlugin` resolves this import to a stub that exports
341
- // `getPerspectiveWorkerURL(): Promise<string>`.
342
- import { initialize as initializePerspectiveWorker } from "../../src/ts/perspective-server.worker.js";
343
-
344
- async function get_worker(): Promise<Worker | MessagePort> {
345
- if (GLOBAL_WORKER === undefined) {
346
- return await initializePerspectiveWorker({
347
- type: "module",
348
- name: "perspective-server",
349
- });
350
- }
351
-
352
- return GLOBAL_WORKER();
353
- }
354
-
355
- export async function websocket(url: string | URL) {
356
- return await api.websocket(get_client(), url);
357
- }
358
-
359
- export async function worker(
360
- worker?: Promise<SharedWorker | Worker | MessagePort>,
361
- ) {
362
- if (typeof worker === "undefined") {
363
- worker = get_worker();
364
- }
365
-
366
- return await api.worker(get_client(), get_server(), worker);
367
- }
368
-
369
- export default {
370
- websocket,
371
- worker,
372
- init_client,
373
- init_server,
374
- host_supports_memory64,
375
- createMessageHandler,
376
- getCompiledClientWasm,
377
- GenericSQLVirtualServerModel,
378
- VirtualDataSlice,
379
- VirtualServer,
380
- };
@@ -1,28 +0,0 @@
1
- // ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2
- // ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
3
- // ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
4
- // ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
5
- // ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
6
- // ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7
- // ┃ Copyright (c) 2017, the Perspective Authors. ┃
8
- // ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9
- // ┃ This file is part of the Perspective library, distributed under the terms ┃
10
- // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11
- // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
-
13
- import perspective from "./perspective.browser.ts";
14
- export * from "./perspective.browser.ts";
15
- import { resolve_server_wasm_url } from "./wasm/cdn.ts";
16
-
17
- perspective.init_server({
18
- wasm32: () => fetch(resolve_server_wasm_url(import.meta.url)),
19
- wasm64: () =>
20
- fetch(
21
- resolve_server_wasm_url(
22
- import.meta.url,
23
- "perspective-server.memory64.wasm",
24
- ),
25
- ),
26
- });
27
-
28
- export default perspective;