@vuu-ui/vuu-data-remote 2.1.18 → 2.1.19-beta.1

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 (57) hide show
  1. package/package.json +10 -12
  2. package/types/ConnectionManager.d.ts +2 -2
  3. package/types/VuuDataSource.d.ts +2 -2
  4. package/types/inlined-worker.d.ts +1 -1
  5. package/types/server-proxy/viewport.d.ts +1 -1
  6. package/cjs/ConnectionManager.js +0 -181
  7. package/cjs/ConnectionManager.js.map +0 -1
  8. package/cjs/DedicatedWorker.js +0 -61
  9. package/cjs/DedicatedWorker.js.map +0 -1
  10. package/cjs/LostConnectionHandler.js +0 -83
  11. package/cjs/LostConnectionHandler.js.map +0 -1
  12. package/cjs/VuuAuthProvider.js +0 -87
  13. package/cjs/VuuAuthProvider.js.map +0 -1
  14. package/cjs/VuuAuthenticator.js +0 -57
  15. package/cjs/VuuAuthenticator.js.map +0 -1
  16. package/cjs/VuuDataSource.js +0 -638
  17. package/cjs/VuuDataSource.js.map +0 -1
  18. package/cjs/WebSocketConnection.js +0 -20
  19. package/cjs/WebSocketConnection.js.map +0 -1
  20. package/cjs/authenticate.js +0 -64
  21. package/cjs/authenticate.js.map +0 -1
  22. package/cjs/constants.js +0 -50
  23. package/cjs/constants.js.map +0 -1
  24. package/cjs/data-source.js +0 -49
  25. package/cjs/data-source.js.map +0 -1
  26. package/cjs/index.js +0 -38
  27. package/cjs/index.js.map +0 -1
  28. package/cjs/inlined-worker.js +0 -2742
  29. package/cjs/inlined-worker.js.map +0 -1
  30. package/cjs/message-utils.js +0 -70
  31. package/cjs/message-utils.js.map +0 -1
  32. package/esm/ConnectionManager.js +0 -179
  33. package/esm/ConnectionManager.js.map +0 -1
  34. package/esm/DedicatedWorker.js +0 -59
  35. package/esm/DedicatedWorker.js.map +0 -1
  36. package/esm/LostConnectionHandler.js +0 -79
  37. package/esm/LostConnectionHandler.js.map +0 -1
  38. package/esm/VuuAuthProvider.js +0 -85
  39. package/esm/VuuAuthProvider.js.map +0 -1
  40. package/esm/VuuAuthenticator.js +0 -54
  41. package/esm/VuuAuthenticator.js.map +0 -1
  42. package/esm/VuuDataSource.js +0 -636
  43. package/esm/VuuDataSource.js.map +0 -1
  44. package/esm/WebSocketConnection.js +0 -17
  45. package/esm/WebSocketConnection.js.map +0 -1
  46. package/esm/authenticate.js +0 -60
  47. package/esm/authenticate.js.map +0 -1
  48. package/esm/constants.js +0 -47
  49. package/esm/constants.js.map +0 -1
  50. package/esm/data-source.js +0 -44
  51. package/esm/data-source.js.map +0 -1
  52. package/esm/index.js +0 -11
  53. package/esm/index.js.map +0 -1
  54. package/esm/inlined-worker.js +0 -2740
  55. package/esm/inlined-worker.js.map +0 -1
  56. package/esm/message-utils.js +0 -64
  57. package/esm/message-utils.js.map +0 -1
@@ -1,2740 +0,0 @@
1
- const workerSourceCode = `
2
- var __defProp = Object.defineProperty;
3
- var __typeError = (msg) => {
4
- throw TypeError(msg);
5
- };
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
9
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
10
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
11
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
12
-
13
- // ../vuu-utils/src/array-utils.ts
14
- function partition(array, test, pass = [], fail = []) {
15
- for (let i = 0, len = array.length; i < len; i++) {
16
- (test(array[i], i) ? pass : fail).push(array[i]);
17
- }
18
- return [pass, fail];
19
- }
20
-
21
- // ../vuu-utils/src/cookie-utils.ts
22
- var getCookieValue = (name) => {
23
- var _a, _b;
24
- if (((_a = globalThis.document) == null ? void 0 : _a.cookie) !== void 0) {
25
- return (_b = globalThis.document.cookie.split("; ").find((row) => row.startsWith(\`\${name}=\`))) == null ? void 0 : _b.split("=")[1];
26
- }
27
- };
28
-
29
- // ../vuu-utils/src/event-emitter.ts
30
- function isArrayOfListeners(listeners) {
31
- return Array.isArray(listeners);
32
- }
33
- function isOnlyListener(listeners) {
34
- return !Array.isArray(listeners);
35
- }
36
- var _events;
37
- var EventEmitter = class {
38
- constructor() {
39
- __privateAdd(this, _events, /* @__PURE__ */ new Map());
40
- }
41
- addListener(event, listener) {
42
- const listeners = __privateGet(this, _events).get(event);
43
- if (!listeners) {
44
- __privateGet(this, _events).set(event, listener);
45
- } else if (isArrayOfListeners(listeners)) {
46
- listeners.push(listener);
47
- } else if (isOnlyListener(listeners)) {
48
- __privateGet(this, _events).set(event, [listeners, listener]);
49
- }
50
- }
51
- removeListener(event, listener) {
52
- if (!__privateGet(this, _events).has(event)) {
53
- return;
54
- }
55
- const listenerOrListeners = __privateGet(this, _events).get(event);
56
- let position = -1;
57
- if (listenerOrListeners === listener) {
58
- __privateGet(this, _events).delete(event);
59
- } else if (Array.isArray(listenerOrListeners)) {
60
- for (let i = listenerOrListeners.length; i-- > 0; ) {
61
- if (listenerOrListeners[i] === listener) {
62
- position = i;
63
- break;
64
- }
65
- }
66
- if (position < 0) {
67
- return;
68
- }
69
- if (listenerOrListeners.length === 1) {
70
- listenerOrListeners.length = 0;
71
- __privateGet(this, _events).delete(event);
72
- } else {
73
- listenerOrListeners.splice(position, 1);
74
- }
75
- }
76
- }
77
- removeAllListeners(event) {
78
- if (event && __privateGet(this, _events).has(event)) {
79
- __privateGet(this, _events).delete(event);
80
- } else if (event === void 0) {
81
- __privateGet(this, _events).clear();
82
- }
83
- }
84
- emit(event, ...args) {
85
- if (__privateGet(this, _events)) {
86
- const handler = __privateGet(this, _events).get(event);
87
- if (handler) {
88
- this.invokeHandler(handler, args);
89
- }
90
- }
91
- }
92
- once(event, listener) {
93
- const handler = ((...args) => {
94
- this.removeListener(event, handler);
95
- listener(...args);
96
- });
97
- this.on(event, handler);
98
- }
99
- on(event, listener) {
100
- this.addListener(event, listener);
101
- }
102
- hasListener(event, listener) {
103
- const listeners = __privateGet(this, _events).get(event);
104
- if (Array.isArray(listeners)) {
105
- return listeners.includes(listener);
106
- } else {
107
- return listeners === listener;
108
- }
109
- }
110
- invokeHandler(handler, args) {
111
- if (isArrayOfListeners(handler)) {
112
- handler.slice().forEach((listener) => this.invokeHandler(listener, args));
113
- } else {
114
- switch (args.length) {
115
- case 0:
116
- handler();
117
- break;
118
- case 1:
119
- handler(args[0]);
120
- break;
121
- case 2:
122
- handler(args[0], args[1]);
123
- break;
124
- // slower
125
- default:
126
- handler.call(null, ...args);
127
- }
128
- }
129
- }
130
- };
131
- _events = new WeakMap();
132
-
133
- // ../vuu-utils/src/protocol-message-utils.ts
134
- var MENU_RPC_TYPES = [
135
- "VIEW_PORT_MENUS_SELECT_RPC",
136
- "VIEW_PORT_MENU_TABLE_RPC",
137
- "VIEW_PORT_MENU_ROW_RPC",
138
- "VIEW_PORT_MENU_CELL_RPC"
139
- ];
140
- var INVALID_SESSION = "Invalid session";
141
- var SESSION_LIMIT_EXCEEDED = "User session limit exceeded";
142
- var INVALID_TOKEN = "Invalid token";
143
- var TOKEN_EXPIRED = "Token has expired";
144
- var InvalidLoginMessages = [
145
- INVALID_SESSION,
146
- SESSION_LIMIT_EXCEEDED,
147
- INVALID_TOKEN,
148
- TOKEN_EXPIRED
149
- ];
150
- var isErrorMessage = (message) => typeof message == "object" && (message == null ? void 0 : message.type) === "ERROR";
151
- var isLoginErrorMessage = (message) => typeof message === "string" && InvalidLoginMessages.includes(message);
152
- var isSelectRequest = (message) => message && typeof message === "object" && "type" in message && (message.type === "SELECT_ROW" || message.type === "DESELECT_ROW" || message.type === "SELECT_ROW_RANGE" || message.type === "SELECT_ALL" || message.type === "DESELECT_ALL");
153
- var isRpcServiceRequest = (message) => message.type === "RPC_REQUEST";
154
- var hasViewPortContext = (message) => message.context.type === "VIEWPORT_CONTEXT";
155
- var isVuuMenuRpcRequest = (message) => MENU_RPC_TYPES.includes(message["type"]);
156
- var isOpenDialogAction = (action) => action !== void 0 && action.type === "OPEN_DIALOG_ACTION";
157
- var isCreateVpSuccess = (response) => response.type === "CREATE_VP_SUCCESS";
158
- var isSessionTable = (table) => {
159
- if (table !== null && typeof table === "object" && "table" in table && "module" in table) {
160
- return table.table.startsWith("session");
161
- }
162
- return false;
163
- };
164
- function isActionMessage(rpcResponse) {
165
- return rpcResponse.type === "VIEW_PORT_MENU_RESP";
166
- }
167
- function isSessionTableActionMessage(rpcResponse) {
168
- var _a, _b;
169
- return isActionMessage(rpcResponse) && isOpenDialogAction(rpcResponse.action) && isSessionTable(rpcResponse.action.table) && (((_a = rpcResponse.action) == null ? void 0 : _a.renderComponent) === "inline-form" || ((_b = rpcResponse.action) == null ? void 0 : _b.renderComponent) === "grid");
170
- }
171
-
172
- // ../vuu-utils/src/datasource/datasource-utils.ts
173
- var isConnectionQualityMetrics = (msg) => msg.type === "connection-metrics";
174
- var isVisualLinkMessage = (msg) => msg.type.endsWith("_VISUAL_LINK");
175
- var isViewportMessage = (msg) => "viewport" in msg;
176
-
177
- // ../vuu-utils/src/range-utils.ts
178
- var _baseFrom, _renderBufferSize, _baseTo;
179
- var _RangeImpl = class _RangeImpl {
180
- // We have to keep from and to as simple public properties (not getters) so they survive structuredClone
181
- constructor(from, to, renderBufferSize = 0) {
182
- this.from = from;
183
- this.to = to;
184
- __privateAdd(this, _baseFrom);
185
- __privateAdd(this, _renderBufferSize, 0);
186
- __privateAdd(this, _baseTo);
187
- __privateSet(this, _baseFrom, from);
188
- __privateSet(this, _baseTo, to);
189
- __privateSet(this, _renderBufferSize, renderBufferSize);
190
- }
191
- get reset() {
192
- return new _RangeImpl(
193
- 0,
194
- __privateGet(this, _baseTo) - __privateGet(this, _baseFrom),
195
- __privateGet(this, _renderBufferSize)
196
- );
197
- }
198
- get withBuffer() {
199
- return getFullRange(this, __privateGet(this, _renderBufferSize));
200
- }
201
- equals(range) {
202
- return range.from === __privateGet(this, _baseFrom) && range.to === __privateGet(this, _baseTo);
203
- }
204
- toJson() {
205
- return {
206
- from: this.from,
207
- to: this.to,
208
- baseFrom: __privateGet(this, _baseFrom),
209
- baseTo: __privateGet(this, _baseTo),
210
- renderBufferSize: __privateGet(this, _renderBufferSize)
211
- };
212
- }
213
- };
214
- _baseFrom = new WeakMap();
215
- _renderBufferSize = new WeakMap();
216
- _baseTo = new WeakMap();
217
- var RangeImpl = _RangeImpl;
218
- var Range = (from, to, renderBufferSize) => new RangeImpl(from, to, renderBufferSize);
219
- var NULL_RANGE = Range(0, 0);
220
- function getFullRange({ from, to }, bufferSize = 0, totalRowCount = Number.MAX_SAFE_INTEGER) {
221
- if (from === 0 && to === 0) {
222
- return { from, to };
223
- } else if (bufferSize === 0) {
224
- if (totalRowCount < from) {
225
- return { from: 0, to: 0 };
226
- } else {
227
- return { from, to: Math.min(to, totalRowCount) };
228
- }
229
- } else if (from === 0) {
230
- return { from, to: Math.min(to + bufferSize, totalRowCount) };
231
- } else {
232
- const shortfallBefore = from - bufferSize < 0;
233
- const shortfallAfter = totalRowCount - (to + bufferSize) < 0;
234
- if (shortfallBefore && shortfallAfter) {
235
- return { from: 0, to: totalRowCount };
236
- } else if (shortfallBefore) {
237
- return { from: 0, to: to + bufferSize };
238
- } else if (shortfallAfter) {
239
- return {
240
- from: Math.max(0, from - bufferSize),
241
- to: totalRowCount
242
- };
243
- } else {
244
- return { from: from - bufferSize, to: to + bufferSize };
245
- }
246
- }
247
- }
248
- var withinRange = (value, { from, to }) => value >= from && value < to;
249
- var WindowRange = class _WindowRange {
250
- constructor(from, to) {
251
- __publicField(this, "from");
252
- __publicField(this, "to");
253
- this.from = from;
254
- this.to = to;
255
- }
256
- isWithin(index) {
257
- return withinRange(index, this);
258
- }
259
- //find the overlap of this range and a new one
260
- overlap(from, to) {
261
- return from >= this.to || to < this.from ? [0, 0] : [Math.max(from, this.from), Math.min(to, this.to)];
262
- }
263
- copy() {
264
- return new _WindowRange(this.from, this.to);
265
- }
266
- };
267
-
268
- // ../vuu-utils/src/logging-utils.ts
269
- var logLevels = ["error", "warn", "info", "debug"];
270
- var isValidLogLevel = (value) => typeof value === "string" && logLevels.includes(value);
271
- var DEFAULT_LOG_LEVEL = "error";
272
- var NO_OP = () => void 0;
273
- var DEFAULT_DEBUG_LEVEL = false ? "error" : "info";
274
- var { loggingLevel = DEFAULT_DEBUG_LEVEL } = getLoggingSettings();
275
- var logger = (category) => {
276
- const debugEnabled5 = loggingLevel === "debug";
277
- const infoEnabled4 = debugEnabled5 || loggingLevel === "info";
278
- const warnEnabled = infoEnabled4 || loggingLevel === "warn";
279
- const errorEnabled = warnEnabled || loggingLevel === "error";
280
- const info5 = infoEnabled4 ? (message) => console.info(\`\${Date.now()} [\${category}] \${message}\`) : NO_OP;
281
- const warn3 = warnEnabled ? (message) => console.warn(\`[\${category}] \${message}\`) : NO_OP;
282
- const debug5 = debugEnabled5 ? (message) => console.debug(\`\${Date.now()} [\${category}] \${message}\`) : NO_OP;
283
- const error3 = errorEnabled ? (message) => console.error(\`[\${category}] \${message}\`) : NO_OP;
284
- if (false) {
285
- return {
286
- errorEnabled,
287
- error: error3
288
- };
289
- } else {
290
- return {
291
- debugEnabled: debugEnabled5,
292
- infoEnabled: infoEnabled4,
293
- warnEnabled,
294
- errorEnabled,
295
- info: info5,
296
- warn: warn3,
297
- debug: debug5,
298
- error: error3
299
- };
300
- }
301
- };
302
- function getLoggingSettings() {
303
- if (typeof loggingSettings !== "undefined") {
304
- return loggingSettings;
305
- } else {
306
- return {
307
- loggingLevel: getLoggingLevelFromCookie()
308
- };
309
- }
310
- }
311
- function getLoggingLevelFromCookie() {
312
- const value = getCookieValue("vuu-logging-level");
313
- if (isValidLogLevel(value)) {
314
- return value;
315
- } else {
316
- return DEFAULT_LOG_LEVEL;
317
- }
318
- }
319
-
320
- // ../vuu-utils/src/debug-utils.ts
321
- var { debug, debugEnabled } = logger("range-monitor");
322
- var RangeMonitor = class {
323
- constructor(source) {
324
- this.source = source;
325
- __publicField(this, "range", { from: 0, to: 0 });
326
- __publicField(this, "timestamp", 0);
327
- }
328
- isSet() {
329
- return this.timestamp !== 0;
330
- }
331
- set({ from, to }) {
332
- const { timestamp } = this;
333
- this.range.from = from;
334
- this.range.to = to;
335
- this.timestamp = performance.now();
336
- if (timestamp) {
337
- debugEnabled && debug(
338
- \`<\${this.source}> [\${from}-\${to}], \${(this.timestamp - timestamp).toFixed(0)} ms elapsed\`
339
- );
340
- } else {
341
- return 0;
342
- }
343
- }
344
- };
345
-
346
- // ../vuu-utils/src/keyset.ts
347
- var EMPTY = [];
348
- var KeySet = class {
349
- constructor(range) {
350
- __publicField(this, "keys", /* @__PURE__ */ new Map());
351
- __publicField(this, "nextKeyValue", 0);
352
- __publicField(this, "range");
353
- this.range = range;
354
- this.init(range);
355
- }
356
- next(free = EMPTY) {
357
- if (free.length > 0) {
358
- return free.shift();
359
- } else {
360
- return this.nextKeyValue++;
361
- }
362
- }
363
- init({ from, to }) {
364
- this.keys.clear();
365
- this.nextKeyValue = 0;
366
- for (let rowIndex = from; rowIndex < to; rowIndex++) {
367
- const nextKeyValue = this.next();
368
- this.keys.set(rowIndex, nextKeyValue);
369
- }
370
- return true;
371
- }
372
- reset(range) {
373
- const { from, to } = range;
374
- const newSize = to - from;
375
- const currentSize = this.range.to - this.range.from;
376
- this.range = range;
377
- if (currentSize > newSize) {
378
- return this.init(range);
379
- }
380
- const freeKeys = [];
381
- this.keys.forEach((keyValue, rowIndex) => {
382
- if (rowIndex < from || rowIndex >= to) {
383
- freeKeys.push(keyValue);
384
- this.keys.delete(rowIndex);
385
- }
386
- });
387
- for (let rowIndex = from; rowIndex < to; rowIndex++) {
388
- if (!this.keys.has(rowIndex)) {
389
- const nextKeyValue = this.next(freeKeys);
390
- this.keys.set(rowIndex, nextKeyValue);
391
- }
392
- }
393
- return false;
394
- }
395
- keyFor(rowIndex) {
396
- const key = this.keys.get(rowIndex);
397
- if (key === void 0) {
398
- console.log(\`key not found
399
- keys: \${this.toDebugString()}
400
- \`);
401
- throw Error(\`KeySet, no key found for rowIndex \${rowIndex}\`);
402
- }
403
- return key;
404
- }
405
- toDebugString() {
406
- return \`\${this.keys.size} keys
407
- \${Array.from(this.keys.entries()).sort(([key1], [key2]) => key1 - key2).map(([k, v]) => \`\${k}=>\${v}\`).join(",")}]
408
- \`;
409
- }
410
- };
411
-
412
- // ../vuu-utils/src/promise-utils.ts
413
- var _promise, _resolve, _reject, _resolved;
414
- var DeferredPromise = class {
415
- constructor() {
416
- __privateAdd(this, _promise);
417
- __privateAdd(this, _resolve, () => console.log("resolve was not set"));
418
- __privateAdd(this, _reject, () => console.log("reject was not set"));
419
- __privateAdd(this, _resolved, false);
420
- __privateSet(this, _promise, new Promise((resolve, reject) => {
421
- __privateSet(this, _resolve, resolve);
422
- __privateSet(this, _reject, reject);
423
- }));
424
- }
425
- get promise() {
426
- return __privateGet(this, _promise);
427
- }
428
- get isResolved() {
429
- return __privateGet(this, _resolved);
430
- }
431
- resolve(value) {
432
- __privateSet(this, _resolved, true);
433
- return __privateGet(this, _resolve).call(this, value);
434
- }
435
- get reject() {
436
- return __privateGet(this, _reject);
437
- }
438
- };
439
- _promise = new WeakMap();
440
- _resolve = new WeakMap();
441
- _reject = new WeakMap();
442
- _resolved = new WeakMap();
443
-
444
- // src/message-utils.ts
445
- var hasRequestId = (message) => {
446
- return "requestId" in message;
447
- };
448
- var stripRequestId = ({
449
- requestId,
450
- ...rest
451
- }) => [requestId, rest];
452
- var getFirstAndLastRows = (rows) => {
453
- let firstRow = rows.at(0);
454
- if (firstRow.updateType === "SIZE") {
455
- if (rows.length === 1) {
456
- return rows;
457
- } else {
458
- firstRow = rows.at(1);
459
- }
460
- }
461
- const lastRow = rows.at(-1);
462
- return [firstRow, lastRow];
463
- };
464
- var insertRow = (rows, row) => {
465
- const lastRow = rows.at(-1);
466
- if (lastRow === void 0 || row.rowIndex > lastRow.rowIndex) {
467
- rows.push(row);
468
- } else {
469
- for (let i = 0; i < rows.length; i++) {
470
- if (row.rowIndex < rows[i].rowIndex) {
471
- rows.splice(i, 0, row);
472
- return;
473
- } else if (row.rowIndex === rows[i].rowIndex) {
474
- if (row.ts < rows[i].ts) {
475
- } else {
476
- rows[i] = row;
477
- }
478
- return;
479
- }
480
- }
481
- throw Error("don't expect to get this far");
482
- }
483
- };
484
- var groupRowsByViewport = (rows) => {
485
- const result = {};
486
- for (const row of rows) {
487
- const rowsForViewport = result[row.viewPortId] || (result[row.viewPortId] = []);
488
- insertRow(rowsForViewport, row);
489
- }
490
- return result;
491
- };
492
- var createSchemaFromTableMetadata = ({
493
- columns,
494
- dataTypes,
495
- key,
496
- table
497
- }) => {
498
- return {
499
- table,
500
- columns: columns.map((col, idx) => ({
501
- name: col,
502
- serverDataType: dataTypes[idx]
503
- })),
504
- key
505
- };
506
- };
507
-
508
- // src/server-proxy/messages.ts
509
- var CHANGE_VP_SUCCESS = "CHANGE_VP_SUCCESS";
510
- var CLOSE_TREE_NODE = "CLOSE_TREE_NODE";
511
- var CLOSE_TREE_SUCCESS = "CLOSE_TREE_SUCCESS";
512
- var CREATE_VP = "CREATE_VP";
513
- var DISABLE_VP = "DISABLE_VP";
514
- var DISABLE_VP_SUCCESS = "DISABLE_VP_SUCCESS";
515
- var ENABLE_VP = "ENABLE_VP";
516
- var ENABLE_VP_SUCCESS = "ENABLE_VP_SUCCESS";
517
- var GET_VP_VISUAL_LINKS = "GET_VP_VISUAL_LINKS";
518
- var GET_VIEW_PORT_MENUS = "GET_VIEW_PORT_MENUS";
519
- var HB = "HB";
520
- var HB_RESP = "HB_RESP";
521
- var OPEN_TREE_NODE = "OPEN_TREE_NODE";
522
- var OPEN_TREE_SUCCESS = "OPEN_TREE_SUCCESS";
523
- var REMOVE_VP = "REMOVE_VP";
524
-
525
- // src/server-proxy/array-backed-moving-window.ts
526
- var EMPTY_ARRAY = [];
527
- var log = logger("array-backed-moving-window");
528
- function dataIsUnchanged(newRow, existingRow) {
529
- if (!existingRow) {
530
- return false;
531
- }
532
- if (existingRow.data.length !== newRow.data.length) {
533
- return false;
534
- }
535
- if (existingRow.sel !== newRow.sel) {
536
- return false;
537
- }
538
- for (let i = 0; i < existingRow.data.length; i++) {
539
- if (existingRow.data[i] !== newRow.data[i]) {
540
- return false;
541
- }
542
- }
543
- return true;
544
- }
545
- var _range;
546
- var ArrayBackedMovingWindow = class {
547
- // Note, the buffer is already accounted for in the range passed in here
548
- constructor({ from: clientFrom, to: clientTo }, { from, to }, bufferSize) {
549
- __privateAdd(this, _range);
550
- __publicField(this, "bufferSize");
551
- __publicField(this, "internalData");
552
- __publicField(this, "rowsWithinRange");
553
- __publicField(this, "clientRange");
554
- __publicField(this, "rowCount");
555
- __publicField(this, "setRowCount", (rowCount) => {
556
- var _a;
557
- (_a = log.info) == null ? void 0 : _a.call(log, \`setRowCount \${rowCount}\`);
558
- if (rowCount < this.internalData.length) {
559
- this.internalData.length = rowCount;
560
- }
561
- if (rowCount < this.rowCount) {
562
- this.rowsWithinRange = 0;
563
- const end = Math.min(rowCount, this.clientRange.to);
564
- for (let i = this.clientRange.from; i < end; i++) {
565
- const rowIndex = i - __privateGet(this, _range).from;
566
- if (this.internalData[rowIndex] !== void 0) {
567
- this.rowsWithinRange += 1;
568
- }
569
- }
570
- }
571
- this.rowCount = rowCount;
572
- });
573
- __publicField(this, "bufferBreakout", (from, to) => {
574
- const bufferPerimeter = this.bufferSize * 0.25;
575
- if (__privateGet(this, _range).to - to < bufferPerimeter) {
576
- return true;
577
- } else if (__privateGet(this, _range).from > 0 && from - __privateGet(this, _range).from < bufferPerimeter) {
578
- return true;
579
- } else {
580
- return false;
581
- }
582
- });
583
- this.bufferSize = bufferSize;
584
- this.clientRange = new WindowRange(clientFrom, clientTo);
585
- __privateSet(this, _range, new WindowRange(from, to));
586
- this.internalData = new Array(bufferSize);
587
- this.rowsWithinRange = 0;
588
- this.rowCount = 0;
589
- }
590
- get range() {
591
- return __privateGet(this, _range);
592
- }
593
- // get hasAllRowsWithinRange(): boolean {
594
- // return (
595
- // this.rowsWithinRange === this.clientRange.to - this.clientRange.from ||
596
- // (this.rowCount > 0 &&
597
- // this.clientRange.from + this.rowsWithinRange === this.rowCount)
598
- // );
599
- // }
600
- // Check to see if set of rows is outside the current viewport range, indicating
601
- // that veiwport is being scrolled quickly and server is not able to keep up.
602
- outOfRange(firstIndex, lastIndex) {
603
- const { from, to } = this.range;
604
- if (lastIndex < from) {
605
- return true;
606
- }
607
- if (firstIndex >= to) {
608
- return true;
609
- }
610
- }
611
- setAtIndex(row) {
612
- const { rowIndex: index } = row;
613
- const internalIndex = index - __privateGet(this, _range).from;
614
- if (dataIsUnchanged(row, this.internalData[internalIndex])) {
615
- return false;
616
- }
617
- const isWithinClientRange = this.isWithinClientRange(index);
618
- if (isWithinClientRange || this.isWithinRange(index)) {
619
- if (!this.internalData[internalIndex] && isWithinClientRange) {
620
- this.rowsWithinRange += 1;
621
- }
622
- this.internalData[internalIndex] = row;
623
- }
624
- return isWithinClientRange;
625
- }
626
- getAtIndex(index) {
627
- return __privateGet(this, _range).isWithin(index) && this.internalData[index - __privateGet(this, _range).from] != null ? this.internalData[index - __privateGet(this, _range).from] : void 0;
628
- }
629
- isWithinRange(index) {
630
- return __privateGet(this, _range).isWithin(index);
631
- }
632
- isWithinClientRange(index) {
633
- return this.clientRange.isWithin(index);
634
- }
635
- // Returns [false] or [serverDataRequired, clientRows]
636
- setClientRange(from, to) {
637
- var _a;
638
- (_a = log.debug) == null ? void 0 : _a.call(log, \`setClientRange \${from} - \${to}\`);
639
- const currentFrom = this.clientRange.from;
640
- const currentTo = Math.min(this.clientRange.to, this.rowCount);
641
- if (from === currentFrom && to === currentTo) {
642
- return [false, EMPTY_ARRAY];
643
- }
644
- const originalRange = this.clientRange.copy();
645
- this.clientRange.from = from;
646
- this.clientRange.to = to;
647
- this.rowsWithinRange = 0;
648
- for (let i = from; i < to; i++) {
649
- const internalIndex = i - __privateGet(this, _range).from;
650
- if (this.internalData[internalIndex]) {
651
- this.rowsWithinRange += 1;
652
- }
653
- }
654
- const clientRows = [];
655
- const offset = __privateGet(this, _range).from;
656
- if (to > originalRange.to) {
657
- const start = Math.max(from, originalRange.to);
658
- for (let i = start - offset; i < to - offset; i++) {
659
- const row = this.internalData[i];
660
- if (row) {
661
- clientRows.push(row);
662
- }
663
- }
664
- } else {
665
- const end = Math.min(originalRange.from, to);
666
- for (let i = from - offset; i < end - offset; i++) {
667
- const row = this.internalData[i];
668
- if (row) {
669
- clientRows.push(row);
670
- }
671
- }
672
- }
673
- const serverDataRequired = this.bufferBreakout(from, to);
674
- return [serverDataRequired, clientRows];
675
- }
676
- setRange(from, to) {
677
- var _a, _b;
678
- if (from !== __privateGet(this, _range).from || to !== __privateGet(this, _range).to) {
679
- (_a = log.debug) == null ? void 0 : _a.call(log, \`setRange \${from} - \${to}\`);
680
- const [overlapFrom, overlapTo] = __privateGet(this, _range).overlap(from, to);
681
- const newData = new Array(to - from);
682
- this.rowsWithinRange = 0;
683
- for (let i = overlapFrom; i < overlapTo; i++) {
684
- const row = this.getAtIndex(i);
685
- if (row) {
686
- const index = i - from;
687
- newData[index] = row;
688
- if (this.isWithinClientRange(i)) {
689
- this.rowsWithinRange += 1;
690
- }
691
- }
692
- }
693
- this.internalData = newData;
694
- __privateGet(this, _range).from = from;
695
- __privateGet(this, _range).to = to;
696
- } else {
697
- (_b = log.debug) == null ? void 0 : _b.call(log, \`setRange \${from} - \${to} IGNORED because not changed\`);
698
- }
699
- }
700
- //TODO temp
701
- get data() {
702
- return this.internalData;
703
- }
704
- getData() {
705
- var _a;
706
- const { from, to } = __privateGet(this, _range);
707
- const { from: clientFrom, to: clientTo } = this.clientRange;
708
- const startOffset = Math.max(0, clientFrom - from);
709
- const endOffset = Math.min(
710
- to - from,
711
- to,
712
- clientTo - from,
713
- (_a = this.rowCount) != null ? _a : to
714
- );
715
- return this.internalData.slice(startOffset, endOffset);
716
- }
717
- clear() {
718
- var _a;
719
- (_a = log.debug) == null ? void 0 : _a.call(log, "clear");
720
- this.internalData.length = 0;
721
- this.rowsWithinRange = 0;
722
- this.setRowCount(0);
723
- }
724
- // used only for debugging
725
- getCurrentDataRange() {
726
- const rows = this.internalData;
727
- const len = rows.length;
728
- let [firstRow] = this.internalData;
729
- let lastRow = this.internalData[len - 1];
730
- if (firstRow && lastRow) {
731
- return [firstRow.rowIndex, lastRow.rowIndex];
732
- } else {
733
- for (let i = 0; i < len; i++) {
734
- if (rows[i] !== void 0) {
735
- firstRow = rows[i];
736
- break;
737
- }
738
- }
739
- for (let i = len - 1; i >= 0; i--) {
740
- if (rows[i] !== void 0) {
741
- lastRow = rows[i];
742
- break;
743
- }
744
- }
745
- if (firstRow && lastRow) {
746
- return [firstRow.rowIndex, lastRow.rowIndex];
747
- } else {
748
- return [-1, -1];
749
- }
750
- }
751
- }
752
- };
753
- _range = new WeakMap();
754
-
755
- // src/server-proxy/viewport.ts
756
- var { debug: debug2, debugEnabled: debugEnabled2, error, info, infoEnabled, warn } = logger("Viewport");
757
- var isLeafUpdate = ({ rowKey, updateType }) => updateType === "U" && !rowKey.startsWith("$root");
758
- var NO_DATA_UPDATE = [
759
- void 0,
760
- void 0
761
- ];
762
- var NO_UPDATE_STATUS = {
763
- count: 0,
764
- mode: void 0,
765
- size: 0,
766
- ts: 0
767
- };
768
- var _status, _clientRange;
769
- var Viewport = class {
770
- constructor({
771
- aggregations,
772
- bufferSize = 50,
773
- columns,
774
- filterSpec: filter,
775
- groupBy = [],
776
- table,
777
- range,
778
- sort,
779
- title,
780
- viewport,
781
- visualLink
782
- }, postMessageToClient) {
783
- __privateAdd(this, _status, "");
784
- __publicField(this, "aggregations");
785
- __publicField(this, "batchMode", false);
786
- __publicField(this, "bufferSize");
787
- /**
788
- * clientRange is always the range requested by the client. We should assume
789
- * these are the rows visible to the user
790
- * TODO what is clientRange needed for ?
791
- */
792
- __privateAdd(this, _clientRange);
793
- __publicField(this, "columns");
794
- __publicField(this, "dataWindow");
795
- __publicField(this, "filter");
796
- __publicField(this, "groupBy");
797
- __publicField(this, "sort");
798
- __publicField(this, "hasUpdates", false);
799
- __publicField(this, "pendingUpdates", []);
800
- __publicField(this, "keys");
801
- __publicField(this, "pendingLinkedParent");
802
- __publicField(this, "pendingOperations", /* @__PURE__ */ new Map());
803
- __publicField(this, "pendingRangeRequests", []);
804
- __publicField(this, "postMessageToClient");
805
- __publicField(this, "rowCountChanged", false);
806
- __publicField(this, "lastUpdateStatus", NO_UPDATE_STATUS);
807
- __publicField(this, "updateThrottleTimer");
808
- __publicField(this, "rangeMonitor", new RangeMonitor("ViewPort"));
809
- __publicField(this, "clientViewportId");
810
- __publicField(this, "disabled", false);
811
- /**
812
- * disabledActive is a state assigned when all active viewports are disabled, used
813
- * when browser window is hidden or minimised.
814
- */
815
- __publicField(this, "disabledActive", false);
816
- __publicField(this, "frozen", false);
817
- __publicField(this, "isTree", false);
818
- __publicField(this, "links");
819
- __publicField(this, "linkedParent");
820
- __publicField(this, "serverViewportId");
821
- // TODO roll disabled/suspended into status
822
- __publicField(this, "suspended", false);
823
- __publicField(this, "suspendTimer", null);
824
- __publicField(this, "table");
825
- __publicField(this, "title");
826
- // Records SIZE only updates
827
- __publicField(this, "setLastSizeOnlyUpdateSize", (size) => {
828
- this.lastUpdateStatus.size = size;
829
- });
830
- __publicField(this, "setLastUpdate", (mode) => {
831
- const { ts: lastTS, mode: lastMode } = this.lastUpdateStatus;
832
- let elapsedTime = 0;
833
- if (lastMode === mode) {
834
- const ts = Date.now();
835
- this.lastUpdateStatus.count += 1;
836
- this.lastUpdateStatus.ts = ts;
837
- elapsedTime = lastTS === 0 ? 0 : ts - lastTS;
838
- } else {
839
- this.lastUpdateStatus.count = 1;
840
- this.lastUpdateStatus.ts = 0;
841
- elapsedTime = 0;
842
- }
843
- this.lastUpdateStatus.mode = mode;
844
- return elapsedTime;
845
- });
846
- __publicField(this, "rangeRequestAlreadyPending", (range) => {
847
- const { bufferSize } = this;
848
- const bufferThreshold = bufferSize * 0.25;
849
- let { from: stillPendingFrom } = range;
850
- for (const { from, to } of this.pendingRangeRequests) {
851
- if (stillPendingFrom >= from && stillPendingFrom < to) {
852
- if (range.to + bufferThreshold <= to) {
853
- return true;
854
- } else {
855
- stillPendingFrom = to;
856
- }
857
- }
858
- }
859
- return false;
860
- });
861
- __publicField(this, "sendThrottledSizeMessage", () => {
862
- this.updateThrottleTimer = void 0;
863
- this.lastUpdateStatus.count = 3;
864
- this.postMessageToClient({
865
- clientViewportId: this.clientViewportId,
866
- mode: "size-only",
867
- size: this.lastUpdateStatus.size,
868
- type: "viewport-update"
869
- });
870
- });
871
- // If we are receiving multiple SIZE updates but no data, table is loading rows
872
- // outside of our viewport. We can safely throttle these requests. Doing so will
873
- // alleviate pressure on UI DataTable.
874
- __publicField(this, "shouldThrottleMessage", (mode) => {
875
- const elapsedTime = this.setLastUpdate(mode);
876
- return mode === "size-only" && elapsedTime > 0 && elapsedTime < 500 && this.lastUpdateStatus.count > 3;
877
- });
878
- __publicField(this, "throttleMessage", (mode) => {
879
- if (this.shouldThrottleMessage(mode)) {
880
- info == null ? void 0 : info("[Viewport] throttling updates setTimeout to 300");
881
- this.setLastSizeOnlyUpdateSize(this.dataWindow.rowCount);
882
- if (this.updateThrottleTimer === void 0) {
883
- this.updateThrottleTimer = setTimeout(
884
- this.sendThrottledSizeMessage,
885
- 100
886
- );
887
- }
888
- return true;
889
- } else if (this.updateThrottleTimer !== void 0) {
890
- clearTimeout(this.updateThrottleTimer);
891
- this.updateThrottleTimer = void 0;
892
- }
893
- return false;
894
- });
895
- __publicField(this, "getNewRowCount", () => {
896
- if (this.rowCountChanged && this.dataWindow) {
897
- this.rowCountChanged = false;
898
- return this.dataWindow.rowCount;
899
- }
900
- });
901
- this.aggregations = aggregations;
902
- this.bufferSize = bufferSize;
903
- __privateSet(this, _clientRange, range);
904
- this.clientViewportId = viewport;
905
- this.columns = columns;
906
- this.filter = filter;
907
- this.groupBy = groupBy;
908
- this.keys = new KeySet(range);
909
- this.pendingLinkedParent = visualLink;
910
- this.table = table;
911
- this.sort = sort;
912
- this.title = title;
913
- infoEnabled && (info == null ? void 0 : info(\`\${table.table} #\${viewport}, bufferSize=\${bufferSize}\`));
914
- this.dataWindow = new ArrayBackedMovingWindow(
915
- __privateGet(this, _clientRange),
916
- range,
917
- this.bufferSize
918
- );
919
- this.postMessageToClient = postMessageToClient;
920
- }
921
- get hasUpdatesToProcess() {
922
- if (this.suspended) {
923
- return false;
924
- }
925
- return this.rowCountChanged || this.hasUpdates;
926
- }
927
- get size() {
928
- var _a;
929
- return (_a = this.dataWindow.rowCount) != null ? _a : 0;
930
- }
931
- get clientRange() {
932
- return __privateGet(this, _clientRange);
933
- }
934
- get status() {
935
- return __privateGet(this, _status);
936
- }
937
- set status(status) {
938
- __privateSet(this, _status, status);
939
- }
940
- subscribe() {
941
- const { filter } = this.filter;
942
- this.status = __privateGet(this, _status) === "subscribed" ? "resubscribing" : "subscribing";
943
- return {
944
- type: CREATE_VP,
945
- table: this.table,
946
- range: getFullRange(__privateGet(this, _clientRange), this.bufferSize),
947
- aggregations: this.aggregations,
948
- columns: this.columns,
949
- sort: this.sort,
950
- groupBy: this.groupBy,
951
- filterSpec: { filter }
952
- };
953
- }
954
- handleSubscribed({
955
- viewPortId,
956
- aggregations,
957
- columns,
958
- filterSpec: filter,
959
- range,
960
- sort,
961
- groupBy,
962
- table
963
- }, baseTableSchema) {
964
- this.serverViewportId = viewPortId;
965
- this.status = "subscribed";
966
- this.aggregations = aggregations;
967
- this.columns = columns;
968
- this.groupBy = groupBy;
969
- this.isTree = groupBy && groupBy.length > 0;
970
- this.dataWindow.setRange(range.from, range.to);
971
- const tableSchema = table === baseTableSchema.table.table ? baseTableSchema : {
972
- ...baseTableSchema,
973
- table: {
974
- ...baseTableSchema.table,
975
- session: table
976
- }
977
- };
978
- return {
979
- aggregations,
980
- type: "subscribed",
981
- clientViewportId: this.clientViewportId,
982
- columns,
983
- filterSpec: filter,
984
- groupBy,
985
- range,
986
- sort,
987
- tableSchema
988
- };
989
- }
990
- awaitOperation(requestId, msg) {
991
- this.pendingOperations.set(requestId, msg);
992
- }
993
- // Return a message if we need to communicate this to client UI
994
- completeOperation(requestId, ...params) {
995
- var _a;
996
- const { clientViewportId, pendingOperations } = this;
997
- const pendingOperation = pendingOperations.get(requestId);
998
- if (!pendingOperation) {
999
- error(
1000
- \`no matching operation found to complete for requestId \${requestId}\`
1001
- );
1002
- return;
1003
- }
1004
- const { type } = pendingOperation;
1005
- info == null ? void 0 : info(\`completeOperation \${type}\`);
1006
- pendingOperations.delete(requestId);
1007
- if (type === "CHANGE_VP_RANGE") {
1008
- const [from, to] = params;
1009
- infoEnabled && info(
1010
- \`completeOperation CHANGE_VP_RANGE
1011
- window setRange (\${from}:\${to}) \${this.pendingRangeRequests.length} range requests pending\`
1012
- );
1013
- (_a = this.dataWindow) == null ? void 0 : _a.setRange(from, to);
1014
- for (let i = this.pendingRangeRequests.length - 1; i >= 0; i--) {
1015
- const pendingRangeRequest = this.pendingRangeRequests[i];
1016
- if (pendingRangeRequest.requestId === requestId) {
1017
- pendingRangeRequest.acked = true;
1018
- break;
1019
- } else {
1020
- warn == null ? void 0 : warn("range requests sent faster than they are being ACKed");
1021
- }
1022
- }
1023
- } else if (type === "config") {
1024
- const {
1025
- aggregations,
1026
- columns,
1027
- filterSpec: filter,
1028
- groupBy,
1029
- sort
1030
- } = pendingOperation.data;
1031
- this.aggregations = aggregations;
1032
- this.columns = columns;
1033
- this.filter = filter;
1034
- this.groupBy = groupBy;
1035
- this.sort = sort;
1036
- if (groupBy.length > 0) {
1037
- this.isTree = true;
1038
- } else if (this.isTree) {
1039
- this.isTree = false;
1040
- }
1041
- debug2 == null ? void 0 : debug2(\`config change confirmed, isTree : \${this.isTree}\`);
1042
- return {
1043
- clientViewportId,
1044
- type,
1045
- config: pendingOperation.data
1046
- };
1047
- } else if (type === "selection") {
1048
- } else if (type === "disable") {
1049
- this.suspended = false;
1050
- this.disabled = true;
1051
- this.disabledActive = pendingOperation.disableActive;
1052
- return {
1053
- type: "disabled",
1054
- clientViewportId
1055
- };
1056
- } else if (type === "enable") {
1057
- this.disabled = false;
1058
- this.disabledActive = false;
1059
- return {
1060
- type: "enabled",
1061
- clientViewportId
1062
- };
1063
- } else if (type === "freeze") {
1064
- this.frozen = true;
1065
- return {
1066
- type: "frozen",
1067
- clientViewportId
1068
- };
1069
- } else if (type === "unfreeze") {
1070
- this.frozen = false;
1071
- return {
1072
- type: "unfrozen",
1073
- clientViewportId
1074
- };
1075
- } else if (type === "CREATE_VISUAL_LINK") {
1076
- const [colName, parentViewportId, parentColName] = params;
1077
- this.linkedParent = {
1078
- colName,
1079
- parentViewportId,
1080
- parentColName
1081
- };
1082
- this.pendingLinkedParent = void 0;
1083
- return {
1084
- requestId,
1085
- type: "vuu-link-created",
1086
- clientViewportId,
1087
- colName,
1088
- parentViewportId,
1089
- parentColName
1090
- };
1091
- } else if (type === "REMOVE_VISUAL_LINK") {
1092
- this.linkedParent = void 0;
1093
- return {
1094
- requestId,
1095
- type: "vuu-link-removed",
1096
- clientViewportId
1097
- };
1098
- }
1099
- }
1100
- // TODO when a range request arrives, consider the viewport to be scrolling
1101
- // until data arrives and we have the full range.
1102
- // When not scrolling, any server data is an update
1103
- // When scrolling, we are in batch mode
1104
- rangeRequest(requestId, range) {
1105
- if (debugEnabled2) {
1106
- this.rangeMonitor.set(range);
1107
- }
1108
- infoEnabled && info(
1109
- \`(bufferSize \${this.bufferSize}) rangeRequest (\${range.from}:\${range.to}) current: window client (\${this.dataWindow.clientRange.from}:\${this.dataWindow.clientRange.to}), full (\${this.dataWindow.range.from}:\${this.dataWindow.range.to}) \`
1110
- );
1111
- const type = "CHANGE_VP_RANGE";
1112
- if (this.dataWindow) {
1113
- const [serverDataRequired, clientRows] = this.dataWindow.setClientRange(
1114
- range.from,
1115
- range.to
1116
- );
1117
- infoEnabled && info(
1118
- \`updated: dataWindow clientRange (\${this.dataWindow.clientRange.from}:\${this.dataWindow.clientRange.to}), fullRange (\${this.dataWindow.range.from}:\${this.dataWindow.range.to}) serverDataRequired \${serverDataRequired ? "Y" : "N"} \${clientRows.length} rows returned from local buffer\`
1119
- );
1120
- let debounceRequest;
1121
- const maxRange = this.dataWindow.rowCount || void 0;
1122
- const serverRequest = serverDataRequired && !this.rangeRequestAlreadyPending(range) ? {
1123
- type,
1124
- viewPortId: this.serverViewportId,
1125
- ...getFullRange(range, this.bufferSize, maxRange)
1126
- } : null;
1127
- if (serverRequest) {
1128
- infoEnabled && info(
1129
- \`create CHANGE_VP_RANGE: (\${serverRequest.from} - \${serverRequest.to})\`
1130
- );
1131
- debugEnabled2 && (debug2 == null ? void 0 : debug2(
1132
- \`create CHANGE_VP_RANGE: [\${serverRequest.from} - \${serverRequest.to}]\`
1133
- ));
1134
- this.awaitOperation(requestId, { type });
1135
- const pendingRequest = this.pendingRangeRequests.at(-1);
1136
- if (pendingRequest) {
1137
- if (pendingRequest.acked) {
1138
- console.warn("Range Request before previous request is filled");
1139
- } else {
1140
- const { from, to } = pendingRequest;
1141
- if (this.dataWindow.outOfRange(from, to)) {
1142
- debounceRequest = {
1143
- clientViewportId: this.clientViewportId,
1144
- type: "debounce-begin"
1145
- };
1146
- } else {
1147
- warn == null ? void 0 : warn("Range Request before previous request is acked");
1148
- }
1149
- }
1150
- }
1151
- this.pendingRangeRequests.push({ ...serverRequest, requestId });
1152
- } else if (clientRows.length > 0) {
1153
- this.batchMode = false;
1154
- }
1155
- this.keys.reset(this.dataWindow.clientRange);
1156
- const toClient = this.isTree ? toClientRowTree : toClientRow;
1157
- if (clientRows.length) {
1158
- return [
1159
- serverRequest,
1160
- clientRows.map((row) => {
1161
- return toClient(row, this.keys);
1162
- })
1163
- ];
1164
- } else if (debounceRequest) {
1165
- return [serverRequest, void 0, debounceRequest];
1166
- } else {
1167
- return [serverRequest];
1168
- }
1169
- } else {
1170
- return [null];
1171
- }
1172
- }
1173
- setLinks(links) {
1174
- this.links = links.filter(
1175
- (link) => link.parentVpId !== this.serverViewportId
1176
- );
1177
- return [
1178
- {
1179
- type: "vuu-links",
1180
- links: this.links,
1181
- clientViewportId: this.clientViewportId
1182
- },
1183
- this.pendingLinkedParent
1184
- ];
1185
- }
1186
- setMenu(menu) {
1187
- return {
1188
- type: "vuu-menu",
1189
- menu,
1190
- clientViewportId: this.clientViewportId
1191
- };
1192
- }
1193
- openTreeNode(requestId, message) {
1194
- const treeKey = message.index === void 0 ? message.key : this.getKeyForRowAtIndex(message.index);
1195
- infoEnabled && info(\`treeKey \${treeKey}\`);
1196
- return {
1197
- type: OPEN_TREE_NODE,
1198
- vpId: this.serverViewportId,
1199
- treeKey
1200
- };
1201
- }
1202
- closeTreeNode(requestId, message) {
1203
- const treeKey = message.index === void 0 ? message.key : this.getKeyForRowAtIndex(message.index);
1204
- return {
1205
- type: CLOSE_TREE_NODE,
1206
- vpId: this.serverViewportId,
1207
- treeKey
1208
- };
1209
- }
1210
- createLink(requestId, vuuCreateVisualLink) {
1211
- const message = {
1212
- ...vuuCreateVisualLink,
1213
- childVpId: this.serverViewportId
1214
- };
1215
- this.awaitOperation(requestId, message);
1216
- return message;
1217
- }
1218
- removeLink(requestId) {
1219
- const message = {
1220
- type: "REMOVE_VISUAL_LINK",
1221
- childVpId: this.serverViewportId
1222
- };
1223
- this.awaitOperation(requestId, message);
1224
- return message;
1225
- }
1226
- suspend() {
1227
- this.suspended = true;
1228
- this.pendingUpdates.length = 0;
1229
- info == null ? void 0 : info("suspend");
1230
- }
1231
- resume() {
1232
- this.suspended = false;
1233
- if (debugEnabled2) {
1234
- debug2 == null ? void 0 : debug2(\`resume: \${this.currentData()}\`);
1235
- }
1236
- return [this.size, this.currentData()];
1237
- }
1238
- currentData() {
1239
- const out = [];
1240
- if (this.dataWindow) {
1241
- const records = this.dataWindow.getData();
1242
- const { keys } = this;
1243
- const toClient = this.isTree ? toClientRowTree : toClientRow;
1244
- for (const row of records) {
1245
- if (row) {
1246
- out.push(toClient(row, keys));
1247
- }
1248
- }
1249
- }
1250
- return out;
1251
- }
1252
- enable(requestId) {
1253
- this.awaitOperation(requestId, { type: "enable" });
1254
- info == null ? void 0 : info(\`enable: \${this.serverViewportId}\`);
1255
- return {
1256
- type: ENABLE_VP,
1257
- viewPortId: this.serverViewportId
1258
- };
1259
- }
1260
- disable(requestId, disableActive = false) {
1261
- this.awaitOperation(requestId, { type: "disable", disableActive });
1262
- info == null ? void 0 : info(\`disable: \${this.serverViewportId}\`);
1263
- return {
1264
- type: DISABLE_VP,
1265
- viewPortId: this.serverViewportId
1266
- };
1267
- }
1268
- freeze(requestId) {
1269
- this.awaitOperation(requestId, { type: "freeze" });
1270
- info == null ? void 0 : info(\`freeze: \${this.serverViewportId}\`);
1271
- return {
1272
- type: "FREEZE_VP",
1273
- viewPortId: this.serverViewportId
1274
- };
1275
- }
1276
- unfreeze(requestId) {
1277
- this.awaitOperation(requestId, { type: "unfreeze" });
1278
- info == null ? void 0 : info(\`unfreeze: \${this.serverViewportId}\`);
1279
- this.frozen = false;
1280
- return {
1281
- type: "UNFREEZE_VP",
1282
- viewPortId: this.serverViewportId
1283
- };
1284
- }
1285
- setConfig(requestId, config) {
1286
- var _a;
1287
- this.awaitOperation(requestId, { type: "config", data: config });
1288
- const { filterSpec: filter, ...remainingConfig } = config;
1289
- debugEnabled2 ? debug2 == null ? void 0 : debug2(\`setConfig \${JSON.stringify(config)}\`) : info == null ? void 0 : info(\`setConfig\`);
1290
- if (!this.isTree && config.groupBy.length > 0) {
1291
- (_a = this.dataWindow) == null ? void 0 : _a.clear();
1292
- }
1293
- return this.createRequest(
1294
- {
1295
- ...remainingConfig,
1296
- filterSpec: typeof (filter == null ? void 0 : filter.filter) === "string" ? {
1297
- filter: filter.filter
1298
- } : {
1299
- filter: ""
1300
- }
1301
- },
1302
- true
1303
- );
1304
- }
1305
- selectRequest(request) {
1306
- info == null ? void 0 : info(\`selectRequest: \${request.type}\`);
1307
- if (this.serverViewportId) {
1308
- return {
1309
- ...request,
1310
- vpId: this.serverViewportId
1311
- };
1312
- } else {
1313
- throw Error(
1314
- \`[Viewport] cannot process \${request.type} before serverViewportId has been set\`
1315
- );
1316
- }
1317
- }
1318
- removePendingRangeRequest(firstIndex, lastIndex) {
1319
- for (let i = this.pendingRangeRequests.length - 1; i >= 0; i--) {
1320
- const { from, to } = this.pendingRangeRequests[i];
1321
- let isLast = true;
1322
- if (firstIndex >= from && firstIndex < to || lastIndex > from && lastIndex < to) {
1323
- if (!isLast) {
1324
- console.warn(
1325
- "removePendingRangeRequest TABLE_ROWS are not for latest request"
1326
- );
1327
- }
1328
- this.pendingRangeRequests.splice(i, 1);
1329
- break;
1330
- } else {
1331
- isLast = false;
1332
- }
1333
- }
1334
- }
1335
- clearCache() {
1336
- this.dataWindow.setRowCount(0);
1337
- this.postMessageToClient({
1338
- clientViewportId: this.clientViewportId,
1339
- type: "viewport-clear"
1340
- });
1341
- }
1342
- updateRows(rows) {
1343
- var _a, _b, _c;
1344
- const [firstRow, lastRow] = getFirstAndLastRows(rows);
1345
- if (firstRow && lastRow) {
1346
- this.removePendingRangeRequest(firstRow.rowIndex, lastRow.rowIndex);
1347
- }
1348
- if (rows.length === 1) {
1349
- if (firstRow.vpSize === 0 && this.disabled) {
1350
- debug2 == null ? void 0 : debug2(
1351
- \`ignore a SIZE=0 message on disabled viewport (\${rows.length} rows)\`
1352
- );
1353
- return;
1354
- }
1355
- }
1356
- for (const row of rows) {
1357
- if (this.isTree && isLeafUpdate(row)) {
1358
- continue;
1359
- } else {
1360
- if (row.updateType === "SIZE" || ((_a = this.dataWindow) == null ? void 0 : _a.rowCount) !== row.vpSize) {
1361
- (_b = this.dataWindow) == null ? void 0 : _b.setRowCount(row.vpSize);
1362
- this.rowCountChanged = true;
1363
- }
1364
- if (row.updateType === "U") {
1365
- if ((_c = this.dataWindow) == null ? void 0 : _c.setAtIndex(row)) {
1366
- if (this.suspended !== true) {
1367
- this.hasUpdates = true;
1368
- if (!this.batchMode) {
1369
- this.pendingUpdates.push(row);
1370
- }
1371
- }
1372
- }
1373
- }
1374
- }
1375
- }
1376
- }
1377
- getKeyForRowAtIndex(rowIndex) {
1378
- const row = this.dataWindow.getAtIndex(rowIndex);
1379
- return row == null ? void 0 : row.rowKey;
1380
- }
1381
- // This is called only after new data has been received from server - data
1382
- // returned direcly from buffer does not use this.
1383
- getClientRows() {
1384
- let out = void 0;
1385
- let mode = "size-only";
1386
- if (!this.hasUpdates && !this.rowCountChanged) {
1387
- return NO_DATA_UPDATE;
1388
- }
1389
- if (this.hasUpdates) {
1390
- const { keys } = this;
1391
- const toClient = this.isTree ? toClientRowTree : toClientRow;
1392
- if (this.updateThrottleTimer) {
1393
- self.clearTimeout(this.updateThrottleTimer);
1394
- this.updateThrottleTimer = void 0;
1395
- }
1396
- if (this.pendingUpdates.length > 0) {
1397
- out = [];
1398
- mode = "update";
1399
- for (const row of this.pendingUpdates) {
1400
- out.push(toClient(row, keys));
1401
- }
1402
- }
1403
- this.pendingUpdates.length = 0;
1404
- this.hasUpdates = false;
1405
- }
1406
- if (this.throttleMessage(mode)) {
1407
- return NO_DATA_UPDATE;
1408
- } else {
1409
- return [out, mode];
1410
- }
1411
- }
1412
- createRequest(params, overWrite = false) {
1413
- if (overWrite) {
1414
- return {
1415
- type: "CHANGE_VP",
1416
- viewPortId: this.serverViewportId,
1417
- ...params
1418
- };
1419
- } else {
1420
- return {
1421
- type: "CHANGE_VP",
1422
- viewPortId: this.serverViewportId,
1423
- aggregations: this.aggregations,
1424
- columns: this.columns,
1425
- sort: this.sort,
1426
- groupBy: this.groupBy,
1427
- filterSpec: {
1428
- filter: this.filter.filter
1429
- },
1430
- ...params
1431
- };
1432
- }
1433
- }
1434
- };
1435
- _status = new WeakMap();
1436
- _clientRange = new WeakMap();
1437
- var isNew = false;
1438
- var toClientRow = ({ rowIndex, rowKey, sel: isSelected, data, ts }, keys) => {
1439
- return [
1440
- rowIndex,
1441
- keys.keyFor(rowIndex),
1442
- true,
1443
- false,
1444
- 0,
1445
- 0,
1446
- rowKey,
1447
- isSelected,
1448
- ts,
1449
- isNew
1450
- ].concat(data);
1451
- };
1452
- var toClientRowTree = ({ rowIndex, rowKey, sel: isSelected, data, ts }, keys) => {
1453
- const [depth, isExpanded, , isLeaf, , count, ...rest] = data;
1454
- return [
1455
- rowIndex,
1456
- keys.keyFor(rowIndex),
1457
- isLeaf,
1458
- isExpanded,
1459
- depth,
1460
- count,
1461
- rowKey,
1462
- isSelected,
1463
- ts,
1464
- isNew
1465
- ].concat(rest);
1466
- };
1467
-
1468
- // src/WebSocketConnection.ts
1469
- var { debug: debug3, debugEnabled: debugEnabled3, info: info2 } = logger("WebSocketConnection");
1470
- var isLoginRejectedMessage = (message) => message !== null && "type" in message && message.type === "LOGIN_REJECTED";
1471
- var DEFAULT_CONNECTION_TIMEOUT = 1e4;
1472
- var parseWebSocketMessage = (message) => {
1473
- try {
1474
- return JSON.parse(message);
1475
- } catch (e) {
1476
- throw Error(\`Error parsing JSON response from server \${message}\`);
1477
- }
1478
- };
1479
- var _callback, _confirmedOpen, _connectionPhase, _connectionStatus, _connectionTimeout, _deferredOpen, _protocols, _url, _ws;
1480
- var WebSocketConnection = class extends EventEmitter {
1481
- constructor({
1482
- callback,
1483
- connectionTimeout = DEFAULT_CONNECTION_TIMEOUT,
1484
- protocols,
1485
- url
1486
- }) {
1487
- super();
1488
- __privateAdd(this, _callback);
1489
- /**
1490
- We are not confirmedOpen until we receive the first message from the
1491
- server. If we get an unexpected close event before that, we consider
1492
- the reconnect attempts as still within the connection phase, not true
1493
- reconnection. This can happen e.g. when connecting to remote host via
1494
- a proxy.
1495
- */
1496
- __privateAdd(this, _confirmedOpen, false);
1497
- __privateAdd(this, _connectionPhase, "initial-connection");
1498
- __privateAdd(this, _connectionStatus, "closed");
1499
- __privateAdd(this, _connectionTimeout);
1500
- __privateAdd(this, _deferredOpen);
1501
- __privateAdd(this, _protocols);
1502
- __privateAdd(this, _url);
1503
- __privateAdd(this, _ws);
1504
- __publicField(this, "receive", (evt) => {
1505
- if (isLoginErrorMessage(evt.data)) {
1506
- console.warn(\`[WebSocketConnection] closed because of login issue\`);
1507
- if (__privateGet(this, _deferredOpen)) {
1508
- console.warn(\`... and we have a deferred connection\`);
1509
- }
1510
- __privateGet(this, _callback).call(this, {
1511
- type: "LOGIN_REJECTED",
1512
- reason: evt.data
1513
- });
1514
- this.close(evt.data);
1515
- } else {
1516
- const vuuMessageFromServer = parseWebSocketMessage(evt.data);
1517
- if (debugEnabled3) {
1518
- if (vuuMessageFromServer.body.type !== "HB") {
1519
- debug3(\`<=== \${vuuMessageFromServer.body.type}\`);
1520
- if (vuuMessageFromServer.body.type === "CHANGE_VP_SUCCESS") {
1521
- debug3(JSON.stringify(vuuMessageFromServer.body));
1522
- }
1523
- }
1524
- }
1525
- __privateGet(this, _callback).call(this, vuuMessageFromServer);
1526
- if (!this.confirmedOpen) {
1527
- if (vuuMessageFromServer.body.type === "LOGIN_SUCCESS") {
1528
- this.connectionStatus = __privateGet(this, _connectionPhase) === "initial-connection" ? "connected" : "reconnected";
1529
- this.confirmedOpen = true;
1530
- }
1531
- }
1532
- }
1533
- });
1534
- __publicField(this, "send", (msg) => {
1535
- var _a;
1536
- if (msg.body.type === "CHANGE_VP_RANGE") {
1537
- info2 == null ? void 0 : info2(
1538
- \`===> CHANGE_VP_RANGE<#\${msg.requestId}> \${msg.body.from}-\${msg.body.to}\`
1539
- );
1540
- }
1541
- (_a = __privateGet(this, _ws)) == null ? void 0 : _a.send(JSON.stringify(msg));
1542
- });
1543
- __privateSet(this, _callback, callback);
1544
- __privateSet(this, _connectionTimeout, connectionTimeout);
1545
- __privateSet(this, _url, url);
1546
- __privateSet(this, _protocols, protocols);
1547
- }
1548
- get connectionTimeout() {
1549
- return __privateGet(this, _connectionTimeout);
1550
- }
1551
- get protocols() {
1552
- return __privateGet(this, _protocols);
1553
- }
1554
- get isClosed() {
1555
- return __privateGet(this, _connectionStatus) === "closed";
1556
- }
1557
- get isDisconnected() {
1558
- return __privateGet(this, _connectionStatus) === "disconnected";
1559
- }
1560
- get connectionPhase() {
1561
- return __privateGet(this, _connectionPhase);
1562
- }
1563
- get connectionStatus() {
1564
- return __privateGet(this, _connectionStatus);
1565
- }
1566
- set connectionStatus(connectionStatus) {
1567
- if (connectionStatus !== "connecting" && connectionStatus !== "reconnecting") {
1568
- __privateSet(this, _connectionStatus, connectionStatus);
1569
- this.emit("connection-status", __privateGet(this, _connectionStatus));
1570
- }
1571
- }
1572
- get confirmedOpen() {
1573
- return __privateGet(this, _confirmedOpen);
1574
- }
1575
- /**
1576
- * We are 'confirmedOpen' when we see the first message transmitted
1577
- * from the server. This ensures that even if we have one or more
1578
- * proxies in our route to the endPoint, all connections have been
1579
- * opened successfully.
1580
- * First time in here (on our initial successful connection) we switch
1581
- * from 'connect' phase to 'reconnect' phase. We may have different
1582
- * retry configurations for these two phases.
1583
- */
1584
- set confirmedOpen(confirmedOpen) {
1585
- __privateSet(this, _confirmedOpen, confirmedOpen);
1586
- if (confirmedOpen && __privateGet(this, _connectionPhase) === "initial-connection") {
1587
- __privateSet(this, _connectionPhase, "post-disconnect-reconnection");
1588
- }
1589
- }
1590
- get url() {
1591
- return __privateGet(this, _url);
1592
- }
1593
- async openWebSocket() {
1594
- var _a;
1595
- const initialConnect = __privateGet(this, _connectionPhase) === "initial-connection";
1596
- if (__privateGet(this, _deferredOpen) === void 0) {
1597
- __privateSet(this, _deferredOpen, new DeferredPromise());
1598
- }
1599
- const { connectionTimeout, protocols, url } = this;
1600
- __privateSet(this, _connectionStatus, initialConnect ? "connecting" : "reconnecting");
1601
- const timer = setTimeout(() => {
1602
- throw Error(
1603
- \`Failed to open WebSocket connection to \${url}, timed out after \${connectionTimeout}ms\`
1604
- );
1605
- }, connectionTimeout);
1606
- const ws = __privateSet(this, _ws, new WebSocket(url, protocols));
1607
- ws.onopen = () => {
1608
- this.connectionStatus = "websocket-open";
1609
- clearTimeout(timer);
1610
- if (__privateGet(this, _deferredOpen)) {
1611
- __privateGet(this, _deferredOpen).resolve(void 0);
1612
- __privateSet(this, _deferredOpen, void 0);
1613
- }
1614
- };
1615
- ws.onerror = () => {
1616
- clearTimeout(timer);
1617
- };
1618
- ws.onclose = () => {
1619
- if (!this.isClosed) {
1620
- this.confirmedOpen = false;
1621
- this.connectionStatus = "disconnected";
1622
- this.close("failure");
1623
- }
1624
- };
1625
- ws.onmessage = (evt) => {
1626
- this.receive(evt);
1627
- };
1628
- return (_a = __privateGet(this, _deferredOpen)) == null ? void 0 : _a.promise;
1629
- }
1630
- close(reason = "shutdown") {
1631
- var _a;
1632
- this.connectionStatus = "closed";
1633
- if (reason === "failure") {
1634
- if (__privateGet(this, _deferredOpen)) {
1635
- __privateGet(this, _deferredOpen).reject(Error("connection failed"));
1636
- __privateSet(this, _deferredOpen, void 0);
1637
- }
1638
- } else {
1639
- (_a = __privateGet(this, _ws)) == null ? void 0 : _a.close();
1640
- }
1641
- __privateSet(this, _ws, void 0);
1642
- }
1643
- };
1644
- _callback = new WeakMap();
1645
- _confirmedOpen = new WeakMap();
1646
- _connectionPhase = new WeakMap();
1647
- _connectionStatus = new WeakMap();
1648
- _connectionTimeout = new WeakMap();
1649
- _deferredOpen = new WeakMap();
1650
- _protocols = new WeakMap();
1651
- _url = new WeakMap();
1652
- _ws = new WeakMap();
1653
-
1654
- // src/server-proxy/server-proxy.ts
1655
- var _requestId = 1;
1656
- var { debug: debug4, debugEnabled: debugEnabled4, error: error2, info: info3, infoEnabled: infoEnabled2, warn: warn2 } = logger("ServerProxy");
1657
- var nextRequestId = () => \`\${_requestId++}\`;
1658
- var DEFAULT_OPTIONS = {};
1659
- var isActiveViewport = (viewPort) => viewPort.disabled !== true && viewPort.suspended !== true;
1660
- var addTitleToLinks = (links, serverViewportId, label) => links.map(
1661
- (link) => link.parentVpId === serverViewportId ? { ...link, label } : link
1662
- );
1663
- function addLabelsToLinks(links, viewports) {
1664
- return links.map((linkDescriptor) => {
1665
- const { parentVpId } = linkDescriptor;
1666
- const viewport = viewports.get(parentVpId);
1667
- if (viewport) {
1668
- return {
1669
- ...linkDescriptor,
1670
- parentClientVpId: viewport.clientViewportId,
1671
- label: viewport.title
1672
- };
1673
- } else {
1674
- throw Error("addLabelsToLinks viewport not found");
1675
- }
1676
- });
1677
- }
1678
- var ServerProxy = class {
1679
- constructor(connection, callback) {
1680
- __publicField(this, "connection");
1681
- __publicField(this, "postMessageToClient");
1682
- __publicField(this, "viewports");
1683
- __publicField(this, "mapClientToServerViewport");
1684
- __publicField(this, "authToken", "");
1685
- __publicField(this, "pendingLogin");
1686
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1687
- __publicField(this, "pendingRequests", /* @__PURE__ */ new Map());
1688
- __publicField(this, "sessionId");
1689
- __publicField(this, "queuedRequests", []);
1690
- __publicField(this, "cachedTableMetaRequests", /* @__PURE__ */ new Map());
1691
- __publicField(this, "cachedTableSchemas", /* @__PURE__ */ new Map());
1692
- __publicField(this, "tableList");
1693
- __publicField(this, "connectionStatusChanged", (status) => {
1694
- if (status === "disconnected") {
1695
- this.sessionId = void 0;
1696
- this.clearAllViewports();
1697
- } else if (status === "reconnected") {
1698
- this.reconnect();
1699
- }
1700
- });
1701
- __publicField(this, "reconnect", async () => {
1702
- const [activeViewports, inactiveViewports] = partition(
1703
- Array.from(this.viewports.values()),
1704
- isActiveViewport
1705
- );
1706
- this.viewports.clear();
1707
- this.mapClientToServerViewport.clear();
1708
- const reconnectViewports = (viewports) => {
1709
- viewports.forEach((viewport) => {
1710
- const { clientViewportId } = viewport;
1711
- this.awaitResponseToMessage(
1712
- viewport.subscribe(),
1713
- clientViewportId
1714
- ).then((msg) => {
1715
- if (msg.type === "CREATE_VP_SUCCESS") {
1716
- this.mapClientToServerViewport.set(
1717
- clientViewportId,
1718
- msg.viewPortId
1719
- );
1720
- this.viewports.set(msg.viewPortId, viewport);
1721
- viewport.status = "subscribed";
1722
- viewport.serverViewportId = msg.viewPortId;
1723
- } else {
1724
- }
1725
- });
1726
- });
1727
- };
1728
- reconnectViewports(activeViewports);
1729
- setTimeout(() => {
1730
- reconnectViewports(inactiveViewports);
1731
- }, 2e3);
1732
- });
1733
- this.connection = connection;
1734
- this.postMessageToClient = callback;
1735
- this.viewports = /* @__PURE__ */ new Map();
1736
- this.mapClientToServerViewport = /* @__PURE__ */ new Map();
1737
- connection.on("connection-status", this.connectionStatusChanged);
1738
- }
1739
- async login(authToken) {
1740
- if (authToken) {
1741
- this.authToken = authToken;
1742
- return new Promise((resolve, reject) => {
1743
- this.sendMessageToServer({ type: "LOGIN", token: this.authToken }, "");
1744
- this.pendingLogin = { resolve, reject };
1745
- });
1746
- } else if (this.authToken === "") {
1747
- error2("login, cannot login until auth token has been obtained");
1748
- }
1749
- }
1750
- clearAllViewports() {
1751
- this.viewports.forEach((viewport) => {
1752
- viewport.clearCache();
1753
- });
1754
- }
1755
- disconnect() {
1756
- this.viewports.forEach((viewport) => {
1757
- const { clientViewportId } = viewport;
1758
- this.unsubscribe(clientViewportId);
1759
- this.postMessageToClient({
1760
- clientViewportId,
1761
- type: "viewport-clear"
1762
- });
1763
- });
1764
- }
1765
- async subscribe(message) {
1766
- if (!this.mapClientToServerViewport.has(message.viewport)) {
1767
- const pendingTableSchema = this.getTableMeta(message.table);
1768
- const viewport = new Viewport(message, this.postMessageToClient);
1769
- this.viewports.set(message.viewport, viewport);
1770
- const pendingSubscription = this.awaitResponseToMessage(
1771
- viewport.subscribe(),
1772
- message.viewport
1773
- );
1774
- const [subscribeResponse, tableSchema] = await Promise.all([
1775
- pendingSubscription,
1776
- pendingTableSchema
1777
- ]);
1778
- if (isErrorMessage(tableSchema)) {
1779
- this.postMessageToClient({
1780
- clientViewportId: message.viewport,
1781
- type: "subscribe-failed",
1782
- msg: \`failed to fetch schema for table \${message.table.table}: \${tableSchema.msg}\`
1783
- });
1784
- } else if (isCreateVpSuccess(subscribeResponse)) {
1785
- const { viewPortId: serverViewportId } = subscribeResponse;
1786
- const { status: previousViewportStatus } = viewport;
1787
- if (message.viewport !== serverViewportId) {
1788
- this.viewports.delete(message.viewport);
1789
- this.viewports.set(serverViewportId, viewport);
1790
- }
1791
- this.mapClientToServerViewport.set(message.viewport, serverViewportId);
1792
- const clientResponse = viewport.handleSubscribed(
1793
- subscribeResponse,
1794
- tableSchema
1795
- );
1796
- if (clientResponse) {
1797
- this.postMessageToClient(clientResponse);
1798
- if (debugEnabled4) {
1799
- debug4(
1800
- \`post DataSourceSubscribedMessage to client: \${JSON.stringify(
1801
- clientResponse
1802
- )}\`
1803
- );
1804
- }
1805
- }
1806
- if (viewport.disabled) {
1807
- this.disableViewport(viewport);
1808
- }
1809
- if (this.queuedRequests.length > 0) {
1810
- this.processQueuedRequests();
1811
- }
1812
- if (previousViewportStatus === "subscribing" && // A session table will never have Visual Links, nor Context Menus
1813
- !isSessionTable(viewport.table)) {
1814
- this.sendMessageToServer({
1815
- type: GET_VP_VISUAL_LINKS,
1816
- vpId: serverViewportId
1817
- });
1818
- this.sendMessageToServer({
1819
- type: GET_VIEW_PORT_MENUS,
1820
- vpId: serverViewportId
1821
- });
1822
- Array.from(this.viewports.entries()).filter(
1823
- ([id, { disabled, status }]) => id !== serverViewportId && !disabled && status === "subscribed"
1824
- ).forEach(([vpId]) => {
1825
- this.sendMessageToServer({
1826
- type: GET_VP_VISUAL_LINKS,
1827
- vpId
1828
- });
1829
- });
1830
- }
1831
- } else {
1832
- this.postMessageToClient({
1833
- clientViewportId: message.viewport,
1834
- type: "subscribe-failed",
1835
- msg: \`failed to open subscription on table \${message.table.table}: \${subscribeResponse.msg}\`
1836
- });
1837
- }
1838
- } else {
1839
- error2(\`spurious subscribe call \${message.viewport}\`);
1840
- }
1841
- }
1842
- /**
1843
- * Currently we only queue range requests, this may change
1844
- */
1845
- addRequestToQueue(queuedRequest) {
1846
- const isDifferentTypeViewport = (qr) => qr.clientViewportId !== queuedRequest.clientViewportId || queuedRequest.message.type !== qr.message.type;
1847
- if (!this.queuedRequests.every(isDifferentTypeViewport)) {
1848
- this.queuedRequests = this.queuedRequests.filter(isDifferentTypeViewport);
1849
- }
1850
- this.queuedRequests.push(queuedRequest);
1851
- }
1852
- processQueuedRequests() {
1853
- const newQueue = [];
1854
- for (const queuedRequest of this.queuedRequests) {
1855
- const { clientViewportId, message, requestId } = queuedRequest;
1856
- const serverViewportId = this.mapClientToServerViewport.get(clientViewportId);
1857
- if (serverViewportId) {
1858
- this.sendMessageToServer(
1859
- {
1860
- ...message,
1861
- viewPortId: serverViewportId
1862
- },
1863
- requestId
1864
- );
1865
- } else if (this.viewports.has(clientViewportId)) {
1866
- newQueue.push(queuedRequest);
1867
- } else {
1868
- console.warn(
1869
- \`ServerProxy processQueuedRequests, \${message.type} request not found \${clientViewportId}\`
1870
- );
1871
- }
1872
- }
1873
- this.queuedRequests = newQueue;
1874
- }
1875
- unsubscribe(clientViewportId) {
1876
- const serverViewportId = this.mapClientToServerViewport.get(clientViewportId);
1877
- if (serverViewportId) {
1878
- info3 == null ? void 0 : info3(
1879
- \`Unsubscribe Message (Client to Server):
1880
- \${serverViewportId}\`
1881
- );
1882
- this.sendMessageToServer({
1883
- type: REMOVE_VP,
1884
- viewPortId: serverViewportId
1885
- });
1886
- } else {
1887
- error2(
1888
- \`failed to unsubscribe client viewport \${clientViewportId}, viewport not found\`
1889
- );
1890
- }
1891
- }
1892
- getViewportForClient(clientViewportId, throws = true) {
1893
- const serverViewportId = this.mapClientToServerViewport.get(clientViewportId);
1894
- if (serverViewportId) {
1895
- const viewport = this.viewports.get(serverViewportId);
1896
- if (viewport) {
1897
- return viewport;
1898
- } else if (throws) {
1899
- throw Error(
1900
- \`Viewport not found for client viewport \${clientViewportId}\`
1901
- );
1902
- } else {
1903
- return null;
1904
- }
1905
- } else if (this.viewports.has(clientViewportId)) {
1906
- return this.viewports.get(clientViewportId);
1907
- } else if (throws) {
1908
- throw Error(
1909
- \`Viewport server id not found for client viewport \${clientViewportId}\`
1910
- );
1911
- } else {
1912
- return null;
1913
- }
1914
- }
1915
- /**********************************************************************/
1916
- /* Handle messages from client */
1917
- /**********************************************************************/
1918
- setViewRange(viewport, message) {
1919
- const requestId = nextRequestId();
1920
- infoEnabled2 && info3(\`setViewRange (\${message.range.from}:\${message.range.to})\`);
1921
- const [serverRequest, rows, debounceRequest] = viewport.rangeRequest(
1922
- requestId,
1923
- message.range
1924
- );
1925
- if (viewport.status === "subscribed") {
1926
- info3 == null ? void 0 : info3(\`setViewRange \${message.range.from} - \${message.range.to}\`);
1927
- if (serverRequest) {
1928
- if (true) {
1929
- info3 == null ? void 0 : info3(
1930
- \`CHANGE_VP_RANGE (\${message.range.from}-\${message.range.to}) => (\${serverRequest.from}-\${serverRequest.to})\`
1931
- );
1932
- }
1933
- infoEnabled2 && info3(
1934
- \`setViewRange send CHANGE_VP_RANGE<#\${requestId}> (\${serverRequest.from}-\${serverRequest.to})\`
1935
- );
1936
- this.sendMessageToServer(serverRequest, requestId);
1937
- }
1938
- if (rows) {
1939
- info3 == null ? void 0 : info3(\`setViewRange \${rows.length} rows returned from cache\`);
1940
- this.postMessageToClient({
1941
- mode: "update",
1942
- type: "viewport-update",
1943
- clientViewportId: viewport.clientViewportId,
1944
- range: message.range,
1945
- rows
1946
- });
1947
- } else if (debounceRequest) {
1948
- this.postMessageToClient(debounceRequest);
1949
- }
1950
- } else if (serverRequest) {
1951
- this.addRequestToQueue({
1952
- clientViewportId: message.viewport,
1953
- message: serverRequest,
1954
- requestId
1955
- });
1956
- }
1957
- }
1958
- // TODO check config has actually changed
1959
- setConfig(viewport, message) {
1960
- const requestId = nextRequestId();
1961
- const request = viewport.setConfig(requestId, message.config);
1962
- this.sendIfReady(request, requestId, viewport.status === "subscribed");
1963
- }
1964
- setTitle(viewport, message) {
1965
- if (viewport) {
1966
- viewport.title = message.title;
1967
- this.updateTitleOnVisualLinks(viewport);
1968
- }
1969
- }
1970
- select(viewport, message) {
1971
- const [requestId, selectRequest] = stripRequestId(message);
1972
- const request = viewport.selectRequest(selectRequest);
1973
- this.sendMessageToServer(request, requestId);
1974
- }
1975
- disableAllActiveViewports() {
1976
- console.log(\`[ServerProxy] disableAllActiveViewports\`);
1977
- this.viewports.forEach((vp) => {
1978
- if (isActiveViewport(vp)) {
1979
- this.disableViewport(vp, true);
1980
- }
1981
- });
1982
- }
1983
- enableAllActiveViewports() {
1984
- this.viewports.forEach((vp) => {
1985
- if (vp.disabledActive) {
1986
- this.enableViewport(vp);
1987
- }
1988
- });
1989
- }
1990
- disableViewport(viewport, disableActive = false) {
1991
- const requestId = nextRequestId();
1992
- const request = viewport.disable(requestId, disableActive);
1993
- this.sendIfReady(request, requestId, viewport.status === "subscribed");
1994
- }
1995
- enableViewport(viewport) {
1996
- if (viewport.disabled) {
1997
- const requestId = nextRequestId();
1998
- const request = viewport.enable(requestId);
1999
- this.sendIfReady(request, requestId, viewport.status === "subscribed");
2000
- }
2001
- }
2002
- freezeViewport(viewport) {
2003
- const requestId = nextRequestId();
2004
- const request = viewport.freeze(requestId);
2005
- this.sendIfReady(request, requestId, viewport.status === "subscribed");
2006
- }
2007
- unfreezeViewport(viewport) {
2008
- if (viewport.frozen) {
2009
- const requestId = nextRequestId();
2010
- const request = viewport.unfreeze(requestId);
2011
- this.sendIfReady(request, requestId, viewport.status === "subscribed");
2012
- }
2013
- }
2014
- suspendViewport(viewport, escalateToDisable = true, escalateDelay = 3e3) {
2015
- viewport.suspend();
2016
- if (escalateToDisable) {
2017
- viewport.suspendTimer = setTimeout(() => {
2018
- info3 == null ? void 0 : info3("suspendTimer expired, escalate suspend to disable");
2019
- this.disableViewport(viewport);
2020
- }, escalateDelay);
2021
- }
2022
- }
2023
- resumeViewport(viewport) {
2024
- if (viewport.suspendTimer) {
2025
- debug4 == null ? void 0 : debug4("clear suspend timer");
2026
- clearTimeout(viewport.suspendTimer);
2027
- viewport.suspendTimer = null;
2028
- }
2029
- const [size, rows] = viewport.resume();
2030
- debug4 == null ? void 0 : debug4(\`resumeViewport size \${size}, \${rows.length} rows sent to client\`);
2031
- this.postMessageToClient({
2032
- clientViewportId: viewport.clientViewportId,
2033
- mode: "update",
2034
- rows,
2035
- size,
2036
- type: "viewport-update"
2037
- });
2038
- }
2039
- openTreeNode(viewport, message) {
2040
- if (viewport.serverViewportId) {
2041
- const requestId = nextRequestId();
2042
- this.sendIfReady(
2043
- viewport.openTreeNode(requestId, message),
2044
- requestId,
2045
- viewport.status === "subscribed"
2046
- );
2047
- }
2048
- }
2049
- closeTreeNode(viewport, message) {
2050
- if (viewport.serverViewportId) {
2051
- const requestId = nextRequestId();
2052
- this.sendIfReady(
2053
- viewport.closeTreeNode(requestId, message),
2054
- requestId,
2055
- viewport.status === "subscribed"
2056
- );
2057
- }
2058
- }
2059
- createLink(viewport, message) {
2060
- const [requestId, visualLinkRequest] = stripRequestId(message);
2061
- const parentVpId = this.mapClientToServerViewport.get(message.parentVpId);
2062
- if (parentVpId) {
2063
- const request = viewport.createLink(requestId, {
2064
- ...visualLinkRequest,
2065
- parentVpId
2066
- });
2067
- this.sendMessageToServer(request, requestId);
2068
- } else {
2069
- throw Error(\`createLink parent viewport not found \${message.parentVpId}\`);
2070
- }
2071
- }
2072
- removeLink(viewport, message) {
2073
- const { requestId } = message;
2074
- const request = viewport.removeLink(requestId);
2075
- this.sendMessageToServer(request, requestId);
2076
- }
2077
- updateTitleOnVisualLinks(viewport) {
2078
- var _a;
2079
- const { serverViewportId, title } = viewport;
2080
- for (const vp of this.viewports.values()) {
2081
- if (vp !== viewport && vp.links && serverViewportId && title) {
2082
- if ((_a = vp.links) == null ? void 0 : _a.some((link) => link.parentVpId === serverViewportId)) {
2083
- const [messageToClient] = vp.setLinks(
2084
- addTitleToLinks(vp.links, serverViewportId, title)
2085
- );
2086
- this.postMessageToClient(messageToClient);
2087
- }
2088
- }
2089
- }
2090
- }
2091
- removeViewportFromVisualLinks(serverViewportId) {
2092
- var _a;
2093
- for (const vp of this.viewports.values()) {
2094
- if ((_a = vp.links) == null ? void 0 : _a.some(({ parentVpId }) => parentVpId === serverViewportId)) {
2095
- const [messageToClient] = vp.setLinks(
2096
- vp.links.filter(({ parentVpId }) => parentVpId !== serverViewportId)
2097
- );
2098
- this.postMessageToClient(messageToClient);
2099
- }
2100
- }
2101
- }
2102
- menuRpcCall(message) {
2103
- const viewport = this.getViewportForClient(message.vpId, false);
2104
- if (viewport == null ? void 0 : viewport.serverViewportId) {
2105
- const [requestId, rpcRequest] = stripRequestId(message);
2106
- this.sendMessageToServer(
2107
- {
2108
- ...rpcRequest,
2109
- vpId: viewport.serverViewportId
2110
- },
2111
- requestId
2112
- );
2113
- }
2114
- }
2115
- rpcRequest(message) {
2116
- if (hasViewPortContext(message)) {
2117
- const viewport = this.getViewportForClient(
2118
- message.context.viewPortId,
2119
- false
2120
- );
2121
- if (viewport == null ? void 0 : viewport.serverViewportId) {
2122
- const [requestId, rpcRequest] = stripRequestId(message);
2123
- this.sendMessageToServer(
2124
- {
2125
- ...rpcRequest,
2126
- context: {
2127
- type: "VIEWPORT_CONTEXT",
2128
- viewPortId: viewport.serverViewportId
2129
- }
2130
- },
2131
- requestId
2132
- );
2133
- }
2134
- } else {
2135
- throw Error(
2136
- \`[ServerProxy] rpcRequest only supports VIEWPORT_CONTEXT at present\`
2137
- );
2138
- }
2139
- }
2140
- handleMessageFromClient(message) {
2141
- var _a;
2142
- if (isViewportMessage(message) || isVisualLinkMessage(message)) {
2143
- if (message.type === "disable") {
2144
- const viewport = this.getViewportForClient(message.viewport, false);
2145
- if (viewport !== null) {
2146
- return this.disableViewport(viewport);
2147
- } else {
2148
- return;
2149
- }
2150
- } else {
2151
- const viewport = isVisualLinkMessage(message) ? this.getViewportForClient(message.childVpId) : this.getViewportForClient(message.viewport);
2152
- switch (message.type) {
2153
- case "setViewRange":
2154
- return this.setViewRange(viewport, message);
2155
- case "config":
2156
- return this.setConfig(viewport, message);
2157
- case "suspend": {
2158
- const { escalateToDisable, escalateDelay } = message;
2159
- return this.suspendViewport(
2160
- viewport,
2161
- escalateToDisable,
2162
- escalateDelay
2163
- );
2164
- }
2165
- case "resume":
2166
- return this.resumeViewport(viewport);
2167
- case "enable":
2168
- return this.enableViewport(viewport);
2169
- case "FREEZE_VP":
2170
- return this.freezeViewport(viewport);
2171
- case "UNFREEZE_VP":
2172
- return this.unfreezeViewport(viewport);
2173
- case "openTreeNode":
2174
- return this.openTreeNode(viewport, message);
2175
- case "closeTreeNode":
2176
- return this.closeTreeNode(viewport, message);
2177
- case "CREATE_VISUAL_LINK":
2178
- return this.createLink(viewport, message);
2179
- case "REMOVE_VISUAL_LINK":
2180
- return this.removeLink(viewport, message);
2181
- case "setTitle":
2182
- return this.setTitle(viewport, message);
2183
- default:
2184
- }
2185
- }
2186
- } else if (isSelectRequest(message)) {
2187
- if (hasRequestId(message)) {
2188
- const viewport = this.getViewportForClient(message.vpId);
2189
- return this.select(viewport, message);
2190
- } else {
2191
- console.warn(\`selectRequest must have requestId\`);
2192
- }
2193
- } else if (isRpcServiceRequest(message)) {
2194
- return this.rpcRequest(message);
2195
- } else if (isVuuMenuRpcRequest(message)) {
2196
- return this.menuRpcCall(message);
2197
- } else if (message.type === "disconnect") {
2198
- return this.disconnect();
2199
- } else if (message.type === "disable-all-active") {
2200
- return this.disableAllActiveViewports();
2201
- } else if (message.type === "enable-all-active") {
2202
- return this.enableAllActiveViewports();
2203
- } else {
2204
- const { type, requestId } = message;
2205
- switch (type) {
2206
- case "GET_TABLE_LIST": {
2207
- (_a = this.tableList) != null ? _a : this.tableList = this.awaitResponseToMessage(
2208
- { type },
2209
- requestId
2210
- );
2211
- this.tableList.then((response) => {
2212
- this.postMessageToClient({
2213
- type: "TABLE_LIST_RESP",
2214
- tables: response.tables,
2215
- requestId
2216
- });
2217
- });
2218
- return;
2219
- }
2220
- case "GET_TABLE_META": {
2221
- this.getTableMeta(message.table, requestId).then((tableSchema) => {
2222
- if (isErrorMessage(tableSchema)) {
2223
- } else if (tableSchema) {
2224
- this.postMessageToClient({
2225
- type: "TABLE_META_RESP",
2226
- tableSchema,
2227
- requestId
2228
- });
2229
- }
2230
- });
2231
- return;
2232
- }
2233
- default:
2234
- }
2235
- }
2236
- error2(
2237
- \`Vuu ServerProxy Unexpected message from client \${JSON.stringify(
2238
- message
2239
- )}\`
2240
- );
2241
- }
2242
- getTableMeta(table, requestId = nextRequestId()) {
2243
- if (isSessionTable(table)) {
2244
- return this.awaitResponseToMessage({ type: "GET_TABLE_META", table }, requestId).then(
2245
- (resp) => isErrorMessage(resp) ? resp : createSchemaFromTableMetadata(resp)
2246
- );
2247
- }
2248
- const key = \`\${table.module}:\${table.table}\`;
2249
- let tableMetaRequest = this.cachedTableMetaRequests.get(key);
2250
- if (!tableMetaRequest) {
2251
- tableMetaRequest = this.awaitResponseToMessage(
2252
- { type: "GET_TABLE_META", table },
2253
- requestId
2254
- );
2255
- this.cachedTableMetaRequests.set(key, tableMetaRequest);
2256
- }
2257
- return tableMetaRequest == null ? void 0 : tableMetaRequest.then((response) => {
2258
- if (isErrorMessage(response)) {
2259
- return response;
2260
- } else {
2261
- return this.cacheTableMeta(response);
2262
- }
2263
- });
2264
- }
2265
- awaitResponseToMessage(message, requestId = nextRequestId()) {
2266
- return new Promise((resolve, reject) => {
2267
- this.sendMessageToServer(message, requestId);
2268
- this.pendingRequests.set(requestId, { reject, resolve });
2269
- });
2270
- }
2271
- sendIfReady(message, requestId, isReady = true) {
2272
- if (isReady) {
2273
- this.sendMessageToServer(message, requestId);
2274
- }
2275
- return isReady;
2276
- }
2277
- sendMessageToServer(body, requestId = \`\${_requestId++}\`, options = DEFAULT_OPTIONS) {
2278
- const { module = "CORE" } = options;
2279
- if (this.authToken) {
2280
- this.connection.send({
2281
- requestId,
2282
- sessionId: this.sessionId,
2283
- module,
2284
- body
2285
- });
2286
- }
2287
- }
2288
- handleMessageFromServer(message) {
2289
- var _a, _b;
2290
- if (isLoginRejectedMessage(message)) {
2291
- if (this.pendingLogin) {
2292
- this.pendingLogin.reject(message.reason);
2293
- this.pendingLogin = void 0;
2294
- this.authToken = "";
2295
- }
2296
- return;
2297
- }
2298
- const { body, requestId, sessionId } = message;
2299
- const pendingRequest = this.pendingRequests.get(requestId);
2300
- if (pendingRequest) {
2301
- const { resolve } = pendingRequest;
2302
- this.pendingRequests.delete(requestId);
2303
- resolve(body);
2304
- return;
2305
- }
2306
- const { viewports } = this;
2307
- switch (body.type) {
2308
- case HB:
2309
- this.sendMessageToServer(
2310
- { type: HB_RESP, ts: +/* @__PURE__ */ new Date() },
2311
- "NA"
2312
- );
2313
- break;
2314
- case "LOGIN_SUCCESS":
2315
- if (sessionId) {
2316
- this.sessionId = sessionId;
2317
- (_a = this.pendingLogin) == null ? void 0 : _a.resolve(sessionId);
2318
- this.pendingLogin = void 0;
2319
- this.postMessageToClient({
2320
- ...body,
2321
- sessionId
2322
- });
2323
- } else {
2324
- throw Error("LOGIN_SUCCESS did not provide sessionId");
2325
- }
2326
- break;
2327
- case "REMOVE_VP_SUCCESS":
2328
- {
2329
- const viewport = viewports.get(body.viewPortId);
2330
- if (viewport) {
2331
- this.mapClientToServerViewport.delete(viewport.clientViewportId);
2332
- viewports.delete(body.viewPortId);
2333
- this.removeViewportFromVisualLinks(body.viewPortId);
2334
- }
2335
- }
2336
- break;
2337
- case "SELECT_ALL_SUCCESS":
2338
- case "SELECT_ROW_SUCCESS":
2339
- case "SELECT_ROW_RANGE_SUCCESS":
2340
- case "DESELECT_ROW_SUCCESS": {
2341
- const { type, selectedRowCount } = body;
2342
- this.postMessageToClient({
2343
- requestId,
2344
- type,
2345
- selectedRowCount
2346
- });
2347
- break;
2348
- }
2349
- case "DESELECT_ALL_SUCCESS": {
2350
- const { type } = body;
2351
- this.postMessageToClient({
2352
- requestId,
2353
- type,
2354
- selectedRowCount: 0
2355
- });
2356
- break;
2357
- }
2358
- case "SELECT_ROW_REJECT":
2359
- case "DESELECT_ROW_REJECT":
2360
- case "SELECT_ROW_RANGE_REJECT":
2361
- case "SELECT_ALL_REJECT":
2362
- case "DESELECT_ALL_REJECT":
2363
- console.warn(\`select error \${body.type} \${body.errorMsg}\`);
2364
- break;
2365
- case CHANGE_VP_SUCCESS:
2366
- case DISABLE_VP_SUCCESS:
2367
- if (viewports.has(body.viewPortId)) {
2368
- const viewport = this.viewports.get(body.viewPortId);
2369
- if (viewport) {
2370
- const response = viewport.completeOperation(requestId);
2371
- if (response !== void 0) {
2372
- this.postMessageToClient(response);
2373
- if (debugEnabled4) {
2374
- debug4(\`postMessageToClient \${JSON.stringify(response)}\`);
2375
- }
2376
- }
2377
- }
2378
- }
2379
- break;
2380
- case ENABLE_VP_SUCCESS:
2381
- {
2382
- const viewport = this.viewports.get(body.viewPortId);
2383
- if (viewport) {
2384
- const response = viewport.completeOperation(requestId);
2385
- if (response) {
2386
- this.postMessageToClient(response);
2387
- const [size, rows] = viewport.resume();
2388
- this.postMessageToClient({
2389
- clientViewportId: viewport.clientViewportId,
2390
- mode: "update",
2391
- rows,
2392
- size,
2393
- type: "viewport-update"
2394
- });
2395
- }
2396
- }
2397
- }
2398
- break;
2399
- case "FREEZE_VP_SUCCESS":
2400
- {
2401
- const viewport = this.viewports.get(body.viewPortId);
2402
- if (viewport) {
2403
- const response = viewport.completeOperation(requestId);
2404
- if (response) {
2405
- this.postMessageToClient(response);
2406
- }
2407
- }
2408
- }
2409
- break;
2410
- case "UNFREEZE_VP_SUCCESS":
2411
- {
2412
- const viewport = this.viewports.get(body.viewPortId);
2413
- if (viewport) {
2414
- const response = viewport.completeOperation(requestId);
2415
- if (response) {
2416
- this.postMessageToClient(response);
2417
- }
2418
- }
2419
- }
2420
- break;
2421
- case "TABLE_ROW":
2422
- {
2423
- const viewportRowMap = groupRowsByViewport(body.rows);
2424
- if (debugEnabled4) {
2425
- const [firstRow] = body.rows;
2426
- if (body.rows.length === 0) {
2427
- infoEnabled2 && info3("<=== TABLE_ROW 0 rows");
2428
- } else if ((firstRow == null ? void 0 : firstRow.rowIndex) === -1) {
2429
- if (body.rows.length === 1) {
2430
- if (firstRow.updateType === "SIZE") {
2431
- infoEnabled2 && info3(
2432
- \`<=== [\${firstRow.viewPortId}] TABLE_ROW SIZE ONLY \${firstRow.vpSize}\`
2433
- );
2434
- } else {
2435
- infoEnabled2 && info3(
2436
- \`<=== [\${firstRow.viewPortId}] TABLE_ROW SIZE \${firstRow.vpSize} rowIdx \${firstRow.rowIndex}\`
2437
- );
2438
- }
2439
- } else {
2440
- infoEnabled2 && info3(
2441
- \`<=== TABLE_ROW \${body.rows.length} rows, SIZE \${firstRow.vpSize}, [\${body.rows.map((r) => r.rowIndex).join(",")}]\`
2442
- );
2443
- }
2444
- } else {
2445
- infoEnabled2 && info3(
2446
- \`<=== TABLE_ROW \${body.rows.length} rows [\${body.rows.map((r) => r.rowIndex).join(",")}]\`
2447
- );
2448
- }
2449
- }
2450
- for (const [viewportId, rows] of Object.entries(viewportRowMap)) {
2451
- const viewport = viewports.get(viewportId);
2452
- if (viewport) {
2453
- viewport.updateRows(rows);
2454
- } else {
2455
- warn2 == null ? void 0 : warn2(
2456
- \`TABLE_ROW message received for non registered viewport \${viewportId}\`
2457
- );
2458
- }
2459
- }
2460
- this.processUpdates();
2461
- }
2462
- break;
2463
- case "CHANGE_VP_RANGE_SUCCESS":
2464
- {
2465
- const viewport = this.viewports.get(body.viewPortId);
2466
- if (viewport) {
2467
- const { from, to } = body;
2468
- infoEnabled2 && info3(
2469
- \`<=== CHANGE_VP_RANGE_SUCCESS<#\${requestId}> \${from} - \${to}\`
2470
- );
2471
- viewport.completeOperation(requestId, from, to);
2472
- }
2473
- }
2474
- break;
2475
- case OPEN_TREE_SUCCESS:
2476
- case CLOSE_TREE_SUCCESS:
2477
- break;
2478
- case "CREATE_VISUAL_LINK_SUCCESS":
2479
- {
2480
- const viewport = this.viewports.get(body.childVpId);
2481
- const parentViewport = this.viewports.get(body.parentVpId);
2482
- if (viewport && parentViewport) {
2483
- const { childColumnName, parentColumnName } = body;
2484
- const response = viewport.completeOperation(
2485
- requestId,
2486
- childColumnName,
2487
- parentViewport.clientViewportId,
2488
- parentColumnName
2489
- );
2490
- if (response) {
2491
- this.postMessageToClient(response);
2492
- }
2493
- }
2494
- }
2495
- break;
2496
- case "REMOVE_VISUAL_LINK_SUCCESS":
2497
- {
2498
- const viewport = this.viewports.get(body.childVpId);
2499
- if (viewport) {
2500
- const response = viewport.completeOperation(
2501
- requestId
2502
- );
2503
- if (response) {
2504
- this.postMessageToClient(response);
2505
- }
2506
- }
2507
- }
2508
- break;
2509
- case "VP_VISUAL_LINKS_RESP":
2510
- {
2511
- const activeLinkDescriptors = this.getActiveLinks(body.links);
2512
- const viewport = this.viewports.get(body.vpId);
2513
- if (activeLinkDescriptors.length && viewport) {
2514
- const linkDescriptorsWithLabels = addLabelsToLinks(
2515
- activeLinkDescriptors,
2516
- this.viewports
2517
- );
2518
- const [clientMessage, pendingLink] = viewport.setLinks(
2519
- linkDescriptorsWithLabels
2520
- );
2521
- this.postMessageToClient(clientMessage);
2522
- if (pendingLink) {
2523
- const { link, parentClientVpId } = pendingLink;
2524
- const requestId2 = nextRequestId();
2525
- const parentVpId = this.mapClientToServerViewport.get(parentClientVpId);
2526
- if (parentVpId) {
2527
- const message2 = viewport.createLink(requestId2, {
2528
- childVpId: body.vpId,
2529
- childColumnName: link.fromColumn,
2530
- parentColumnName: link.toColumn,
2531
- parentVpId,
2532
- type: "CREATE_VISUAL_LINK"
2533
- });
2534
- this.sendMessageToServer(message2, requestId2);
2535
- }
2536
- }
2537
- }
2538
- }
2539
- break;
2540
- case "VIEW_PORT_MENUS_RESP":
2541
- if ((_b = body.menu) == null ? void 0 : _b.name) {
2542
- const viewport = this.viewports.get(body.vpId);
2543
- if (viewport) {
2544
- const clientMessage = viewport.setMenu(body.menu);
2545
- this.postMessageToClient(clientMessage);
2546
- }
2547
- }
2548
- break;
2549
- case "VIEW_PORT_MENU_REJ": {
2550
- const { error: error3, rpcName, vpId } = body;
2551
- const viewport = this.viewports.get(vpId);
2552
- if (viewport) {
2553
- this.postMessageToClient({
2554
- clientViewportId: viewport.clientViewportId,
2555
- error: error3,
2556
- rpcName,
2557
- type: "VIEW_PORT_MENU_REJ",
2558
- requestId
2559
- });
2560
- }
2561
- break;
2562
- }
2563
- case "VIEW_PORT_MENU_RESP":
2564
- {
2565
- if (isSessionTableActionMessage(body)) {
2566
- const { action, rpcName } = body;
2567
- this.awaitResponseToMessage({
2568
- type: "GET_TABLE_META",
2569
- table: action.table
2570
- }).then((response) => {
2571
- const tableSchema = createSchemaFromTableMetadata(
2572
- response
2573
- );
2574
- this.postMessageToClient({
2575
- /* MenuRpcResponse */
2576
- rpcName,
2577
- type: "VIEW_PORT_MENU_RESP",
2578
- action: {
2579
- ...action,
2580
- tableSchema
2581
- },
2582
- tableAlreadyOpen: this.isTableOpen(action.table),
2583
- requestId
2584
- });
2585
- });
2586
- } else {
2587
- const { action, rpcName } = body;
2588
- this.postMessageToClient({
2589
- /* MenuRpcResponse */
2590
- action,
2591
- rpcName,
2592
- requestId,
2593
- tableAlreadyOpen: isOpenDialogAction(action) && this.isTableOpen(action.table),
2594
- type: "VIEW_PORT_MENU_RESP"
2595
- });
2596
- }
2597
- }
2598
- break;
2599
- case "RPC_RESPONSE":
2600
- {
2601
- const { action, error: error3, result } = body;
2602
- this.postMessageToClient({
2603
- action,
2604
- type: "RPC_RESPONSE",
2605
- error: error3,
2606
- result,
2607
- requestId
2608
- });
2609
- }
2610
- break;
2611
- case "ERROR":
2612
- error2(body.msg);
2613
- break;
2614
- default:
2615
- infoEnabled2 && info3(\`<=== \${body["type"]}.\`);
2616
- }
2617
- }
2618
- cacheTableMeta(messageBody) {
2619
- const { module, table } = messageBody.table;
2620
- const key = \`\${module}:\${table}\`;
2621
- let tableSchema = this.cachedTableSchemas.get(key);
2622
- if (!tableSchema) {
2623
- tableSchema = createSchemaFromTableMetadata(messageBody);
2624
- this.cachedTableSchemas.set(key, tableSchema);
2625
- }
2626
- return tableSchema;
2627
- }
2628
- isTableOpen(table) {
2629
- if (table) {
2630
- const tableName = table.table;
2631
- for (const viewport of this.viewports.values()) {
2632
- if (!viewport.suspended && viewport.table.table === tableName) {
2633
- return true;
2634
- }
2635
- }
2636
- }
2637
- }
2638
- // Eliminate links to suspended viewports
2639
- getActiveLinks(linkDescriptors) {
2640
- return linkDescriptors.filter((linkDescriptor) => {
2641
- const viewport = this.viewports.get(linkDescriptor.parentVpId);
2642
- return viewport && !viewport.suspended;
2643
- });
2644
- }
2645
- processUpdates() {
2646
- this.viewports.forEach((viewport) => {
2647
- var _a;
2648
- if (viewport.hasUpdatesToProcess) {
2649
- const result = viewport.getClientRows();
2650
- if (result !== NO_DATA_UPDATE) {
2651
- const [rows, mode] = result;
2652
- const size = viewport.getNewRowCount();
2653
- if (size !== void 0 || rows && rows.length > 0) {
2654
- debugEnabled4 && debug4(
2655
- \`===> #\${viewport.clientViewportId} viewport-update \${mode}, \${(_a = rows == null ? void 0 : rows.length) != null ? _a : "no"} rows, size \${size}\`
2656
- );
2657
- if (mode) {
2658
- this.postMessageToClient({
2659
- clientViewportId: viewport.clientViewportId,
2660
- mode,
2661
- rows,
2662
- size,
2663
- type: "viewport-update"
2664
- });
2665
- }
2666
- }
2667
- }
2668
- }
2669
- });
2670
- }
2671
- };
2672
-
2673
- // src/worker.ts
2674
- var serverProxy;
2675
- var webSocketConnection;
2676
- var { info: info4, infoEnabled: infoEnabled3 } = logger("worker");
2677
- var sendMessageToClient = (message) => {
2678
- postMessage(message);
2679
- };
2680
- async function connectToServer(url, protocols, token) {
2681
- if (webSocketConnection === void 0 && serverProxy === void 0) {
2682
- webSocketConnection = new WebSocketConnection({
2683
- callback: (msg) => {
2684
- if (isConnectionQualityMetrics(msg)) {
2685
- postMessage({ type: "connection-metrics", messages: msg });
2686
- } else {
2687
- serverProxy.handleMessageFromServer(msg);
2688
- }
2689
- },
2690
- protocols,
2691
- url
2692
- });
2693
- webSocketConnection.on("connection-status", postMessage);
2694
- serverProxy = new ServerProxy(webSocketConnection, sendMessageToClient);
2695
- }
2696
- await webSocketConnection.openWebSocket();
2697
- return serverProxy.login(token);
2698
- }
2699
- var handleMessageFromClient = async ({
2700
- data: message
2701
- }) => {
2702
- switch (message.type) {
2703
- case "connect":
2704
- try {
2705
- const sessionId = await connectToServer(
2706
- message.url,
2707
- message.protocol,
2708
- message.token
2709
- );
2710
- postMessage({ type: "connected", sessionId });
2711
- } catch (err) {
2712
- postMessage({ type: "connection-failed", reason: String(err) });
2713
- }
2714
- break;
2715
- // If any of the messages below are received BEFORE we have connected and created
2716
- // the server - handle accordingly
2717
- case "disconnect":
2718
- serverProxy.disconnect();
2719
- webSocketConnection == null ? void 0 : webSocketConnection.close();
2720
- break;
2721
- case "subscribe":
2722
- infoEnabled3 && info4(\`===> \${JSON.stringify(message)}\`);
2723
- serverProxy.subscribe(message);
2724
- break;
2725
- case "unsubscribe":
2726
- infoEnabled3 && info4(\`===> \${JSON.stringify(message)}\`);
2727
- serverProxy.unsubscribe(message.viewport);
2728
- break;
2729
- default:
2730
- infoEnabled3 && info4(\`===> \${JSON.stringify(message)}\`);
2731
- serverProxy.handleMessageFromClient(message);
2732
- }
2733
- };
2734
- self.addEventListener("message", handleMessageFromClient);
2735
- postMessage({ type: "ready" });
2736
-
2737
- `;
2738
-
2739
- export { workerSourceCode };
2740
- //# sourceMappingURL=inlined-worker.js.map