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