@vuu-ui/vuu-data-remote 0.13.7 → 0.13.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/index.js +3977 -26
- package/cjs/index.js.map +1 -1
- package/esm/index.js +3962 -7
- package/esm/index.js.map +1 -1
- package/package.json +7 -7
- package/cjs/ConnectionManager.js +0 -169
- package/cjs/ConnectionManager.js.map +0 -1
- package/cjs/DedicatedWorker.js +0 -61
- package/cjs/DedicatedWorker.js.map +0 -1
- package/cjs/VuuDataSource.js +0 -447
- package/cjs/VuuDataSource.js.map +0 -1
- package/cjs/WebSocketConnection.js +0 -23
- package/cjs/WebSocketConnection.js.map +0 -1
- package/cjs/authenticate.js +0 -28
- package/cjs/authenticate.js.map +0 -1
- package/cjs/constants.js +0 -50
- package/cjs/constants.js.map +0 -1
- package/cjs/data-source.js +0 -48
- package/cjs/data-source.js.map +0 -1
- package/cjs/inlined-worker.js +0 -2828
- package/cjs/inlined-worker.js.map +0 -1
- package/cjs/message-utils.js +0 -87
- package/cjs/message-utils.js.map +0 -1
- package/cjs/rest-data/RestDataSource.js +0 -172
- package/cjs/rest-data/RestDataSource.js.map +0 -1
- package/cjs/rest-data/moving-window.js +0 -66
- package/cjs/rest-data/moving-window.js.map +0 -1
- package/cjs/rest-data/rest-utils.js +0 -60
- package/cjs/rest-data/rest-utils.js.map +0 -1
- package/esm/ConnectionManager.js +0 -167
- package/esm/ConnectionManager.js.map +0 -1
- package/esm/DedicatedWorker.js +0 -59
- package/esm/DedicatedWorker.js.map +0 -1
- package/esm/VuuDataSource.js +0 -445
- package/esm/VuuDataSource.js.map +0 -1
- package/esm/WebSocketConnection.js +0 -21
- package/esm/WebSocketConnection.js.map +0 -1
- package/esm/authenticate.js +0 -26
- package/esm/authenticate.js.map +0 -1
- package/esm/constants.js +0 -47
- package/esm/constants.js.map +0 -1
- package/esm/data-source.js +0 -43
- package/esm/data-source.js.map +0 -1
- package/esm/inlined-worker.js +0 -2826
- package/esm/inlined-worker.js.map +0 -1
- package/esm/message-utils.js +0 -80
- package/esm/message-utils.js.map +0 -1
- package/esm/rest-data/RestDataSource.js +0 -170
- package/esm/rest-data/RestDataSource.js.map +0 -1
- package/esm/rest-data/moving-window.js +0 -64
- package/esm/rest-data/moving-window.js.map +0 -1
- package/esm/rest-data/rest-utils.js +0 -55
- package/esm/rest-data/rest-utils.js.map +0 -1
package/cjs/index.js
CHANGED
|
@@ -1,29 +1,3980 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
3
|
+
var vuuUtils = require('@vuu-ui/vuu-utils');
|
|
4
|
+
|
|
5
|
+
const defaultAuthUrl = "api/authn";
|
|
6
|
+
const authenticate = async (username, password, authUrl = defaultAuthUrl) => fetch(authUrl, {
|
|
7
|
+
method: "POST",
|
|
8
|
+
credentials: "include",
|
|
9
|
+
headers: {
|
|
10
|
+
"Content-Type": "application/json",
|
|
11
|
+
"access-control-allow-origin": location.host
|
|
12
|
+
},
|
|
13
|
+
body: JSON.stringify({ username, password })
|
|
14
|
+
}).then((response) => {
|
|
15
|
+
if (response.ok) {
|
|
16
|
+
const authToken = response.headers.get("vuu-auth-token");
|
|
17
|
+
if (typeof authToken === "string" && authToken.length > 0) {
|
|
18
|
+
return authToken;
|
|
19
|
+
} else {
|
|
20
|
+
throw Error(`Authentication failed auth token not returned by server`);
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
throw Error(
|
|
24
|
+
`Authentication failed ${response.status} ${response.statusText}`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const isWebSocketConnectionMessage = (msg) => {
|
|
30
|
+
if ("connectionStatus" in msg) {
|
|
31
|
+
return [
|
|
32
|
+
"connecting",
|
|
33
|
+
"connected",
|
|
34
|
+
"connection-open-awaiting-session",
|
|
35
|
+
"reconnecting",
|
|
36
|
+
"reconnected",
|
|
37
|
+
"disconnected",
|
|
38
|
+
"closed",
|
|
39
|
+
"failed"
|
|
40
|
+
].includes(msg.connectionStatus);
|
|
41
|
+
} else {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const workerSourceCode = `
|
|
47
|
+
var __defProp = Object.defineProperty;
|
|
48
|
+
var __typeError = (msg) => {
|
|
49
|
+
throw TypeError(msg);
|
|
50
|
+
};
|
|
51
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
52
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
53
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
54
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
55
|
+
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);
|
|
56
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
57
|
+
|
|
58
|
+
// ../vuu-utils/src/array-utils.ts
|
|
59
|
+
function partition(array, test, pass = [], fail = []) {
|
|
60
|
+
for (let i = 0, len = array.length; i < len; i++) {
|
|
61
|
+
(test(array[i], i) ? pass : fail).push(array[i]);
|
|
62
|
+
}
|
|
63
|
+
return [pass, fail];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ../vuu-utils/src/column-utils.ts
|
|
67
|
+
var KEY = 6;
|
|
68
|
+
var metadataKeys = {
|
|
69
|
+
IDX: 0,
|
|
70
|
+
RENDER_IDX: 1,
|
|
71
|
+
IS_LEAF: 2,
|
|
72
|
+
IS_EXPANDED: 3,
|
|
73
|
+
DEPTH: 4,
|
|
74
|
+
COUNT: 5,
|
|
75
|
+
KEY,
|
|
76
|
+
SELECTED: 7,
|
|
77
|
+
count: 8,
|
|
78
|
+
// TODO following only used in datamodel
|
|
79
|
+
PARENT_IDX: "parent_idx",
|
|
80
|
+
IDX_POINTER: "idx_pointer",
|
|
81
|
+
FILTER_COUNT: "filter_count",
|
|
82
|
+
NEXT_FILTER_IDX: "next_filter_idx"
|
|
83
|
+
};
|
|
84
|
+
var { DEPTH, IS_LEAF } = metadataKeys;
|
|
85
|
+
|
|
86
|
+
// ../vuu-utils/src/cookie-utils.ts
|
|
87
|
+
var getCookieValue = (name) => {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
if (((_a = globalThis.document) == null ? void 0 : _a.cookie) !== void 0) {
|
|
90
|
+
return (_b = globalThis.document.cookie.split("; ").find((row) => row.startsWith(\`\${name}=\`))) == null ? void 0 : _b.split("=")[1];
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// ../vuu-utils/src/range-utils.ts
|
|
95
|
+
var defaultRangeOptions = {
|
|
96
|
+
renderBufferSize: 0,
|
|
97
|
+
rowCount: -1
|
|
98
|
+
};
|
|
99
|
+
var _baseFrom, _renderBufferSize, _rowCount, _baseTo;
|
|
100
|
+
var _RangeImpl = class _RangeImpl {
|
|
101
|
+
constructor(from, to, rangeOptions = defaultRangeOptions) {
|
|
102
|
+
__privateAdd(this, _baseFrom);
|
|
103
|
+
__privateAdd(this, _renderBufferSize, 0);
|
|
104
|
+
__privateAdd(this, _rowCount, -1);
|
|
105
|
+
__privateAdd(this, _baseTo);
|
|
106
|
+
// We have to keep these as simple public properties (not getters) so they survive structuredClone
|
|
107
|
+
__publicField(this, "from", 0);
|
|
108
|
+
__publicField(this, "to", 0);
|
|
109
|
+
var _a, _b;
|
|
110
|
+
__privateSet(this, _baseFrom, from);
|
|
111
|
+
__privateSet(this, _baseTo, to);
|
|
112
|
+
this.renderBufferSize = (_a = rangeOptions.renderBufferSize) != null ? _a : defaultRangeOptions.renderBufferSize;
|
|
113
|
+
this.rowCount = (_b = rangeOptions.rowCount) != null ? _b : defaultRangeOptions.rowCount;
|
|
114
|
+
}
|
|
115
|
+
get firstRowInViewport() {
|
|
116
|
+
return __privateGet(this, _baseFrom) + 1;
|
|
117
|
+
}
|
|
118
|
+
get lastRowInViewport() {
|
|
119
|
+
if (__privateGet(this, _rowCount) > 0) {
|
|
120
|
+
return Math.min(__privateGet(this, _baseTo), __privateGet(this, _rowCount));
|
|
121
|
+
} else {
|
|
122
|
+
return __privateGet(this, _baseTo);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
get renderBufferSize() {
|
|
126
|
+
return __privateGet(this, _renderBufferSize);
|
|
127
|
+
}
|
|
128
|
+
set renderBufferSize(value) {
|
|
129
|
+
__privateSet(this, _renderBufferSize, value);
|
|
130
|
+
this.from = Math.max(0, __privateGet(this, _baseFrom) - value);
|
|
131
|
+
if (__privateGet(this, _rowCount) > 0) {
|
|
132
|
+
this.to = Math.max(__privateGet(this, _baseTo) + __privateGet(this, _renderBufferSize), __privateGet(this, _rowCount));
|
|
133
|
+
} else {
|
|
134
|
+
this.to = __privateGet(this, _baseTo) + __privateGet(this, _renderBufferSize);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
get rowCount() {
|
|
138
|
+
return __privateGet(this, _rowCount);
|
|
139
|
+
}
|
|
140
|
+
set rowCount(value) {
|
|
141
|
+
__privateSet(this, _rowCount, value);
|
|
142
|
+
if (value > 0) {
|
|
143
|
+
this.to = Math.min(__privateGet(this, _baseTo) + __privateGet(this, _renderBufferSize), value);
|
|
144
|
+
} else {
|
|
145
|
+
this.to = __privateGet(this, _baseTo) + __privateGet(this, _renderBufferSize);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
get reset() {
|
|
149
|
+
return new _RangeImpl(0, __privateGet(this, _baseTo) - __privateGet(this, _baseFrom), {
|
|
150
|
+
rowCount: __privateGet(this, _rowCount),
|
|
151
|
+
renderBufferSize: __privateGet(this, _renderBufferSize)
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
equals(range) {
|
|
155
|
+
return range.from === __privateGet(this, _baseFrom) && range.to === __privateGet(this, _baseTo);
|
|
156
|
+
}
|
|
157
|
+
toJson() {
|
|
158
|
+
return {
|
|
159
|
+
from: this.from,
|
|
160
|
+
to: this.to,
|
|
161
|
+
baseFrom: __privateGet(this, _baseFrom),
|
|
162
|
+
baseTo: __privateGet(this, _baseTo),
|
|
163
|
+
renderBufferSize: __privateGet(this, _renderBufferSize),
|
|
164
|
+
rowCount: __privateGet(this, _rowCount)
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
_baseFrom = new WeakMap();
|
|
169
|
+
_renderBufferSize = new WeakMap();
|
|
170
|
+
_rowCount = new WeakMap();
|
|
171
|
+
_baseTo = new WeakMap();
|
|
172
|
+
var RangeImpl = _RangeImpl;
|
|
173
|
+
var Range = (from, to, rangeOptions) => new RangeImpl(from, to, rangeOptions);
|
|
174
|
+
var NULL_RANGE = Range(0, 0);
|
|
175
|
+
function getFullRange({ from, to }, bufferSize = 0, totalRowCount = Number.MAX_SAFE_INTEGER) {
|
|
176
|
+
if (from === 0 && to === 0) {
|
|
177
|
+
return { from, to };
|
|
178
|
+
} else if (bufferSize === 0) {
|
|
179
|
+
if (totalRowCount < from) {
|
|
180
|
+
return { from: 0, to: 0 };
|
|
181
|
+
} else {
|
|
182
|
+
return { from, to: Math.min(to, totalRowCount) };
|
|
183
|
+
}
|
|
184
|
+
} else if (from === 0) {
|
|
185
|
+
return { from, to: Math.min(to + bufferSize, totalRowCount) };
|
|
186
|
+
} else {
|
|
187
|
+
const shortfallBefore = from - bufferSize < 0;
|
|
188
|
+
const shortfallAfter = totalRowCount - (to + bufferSize) < 0;
|
|
189
|
+
if (shortfallBefore && shortfallAfter) {
|
|
190
|
+
return { from: 0, to: totalRowCount };
|
|
191
|
+
} else if (shortfallBefore) {
|
|
192
|
+
return { from: 0, to: to + bufferSize };
|
|
193
|
+
} else if (shortfallAfter) {
|
|
194
|
+
return {
|
|
195
|
+
from: Math.max(0, from - bufferSize),
|
|
196
|
+
to: totalRowCount
|
|
197
|
+
};
|
|
198
|
+
} else {
|
|
199
|
+
return { from: from - bufferSize, to: to + bufferSize };
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
var withinRange = (value, { from, to }) => value >= from && value < to;
|
|
204
|
+
var WindowRange = class _WindowRange {
|
|
205
|
+
constructor(from, to) {
|
|
206
|
+
__publicField(this, "from");
|
|
207
|
+
__publicField(this, "to");
|
|
208
|
+
this.from = from;
|
|
209
|
+
this.to = to;
|
|
210
|
+
}
|
|
211
|
+
isWithin(index) {
|
|
212
|
+
return withinRange(index, this);
|
|
213
|
+
}
|
|
214
|
+
//find the overlap of this range and a new one
|
|
215
|
+
overlap(from, to) {
|
|
216
|
+
return from >= this.to || to < this.from ? [0, 0] : [Math.max(from, this.from), Math.min(to, this.to)];
|
|
217
|
+
}
|
|
218
|
+
copy() {
|
|
219
|
+
return new _WindowRange(this.from, this.to);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// ../vuu-utils/src/event-emitter.ts
|
|
224
|
+
function isArrayOfListeners(listeners) {
|
|
225
|
+
return Array.isArray(listeners);
|
|
226
|
+
}
|
|
227
|
+
function isOnlyListener(listeners) {
|
|
228
|
+
return !Array.isArray(listeners);
|
|
229
|
+
}
|
|
230
|
+
var _events;
|
|
231
|
+
var EventEmitter = class {
|
|
232
|
+
constructor() {
|
|
233
|
+
__privateAdd(this, _events, /* @__PURE__ */ new Map());
|
|
234
|
+
}
|
|
235
|
+
addListener(event, listener) {
|
|
236
|
+
const listeners = __privateGet(this, _events).get(event);
|
|
237
|
+
if (!listeners) {
|
|
238
|
+
__privateGet(this, _events).set(event, listener);
|
|
239
|
+
} else if (isArrayOfListeners(listeners)) {
|
|
240
|
+
listeners.push(listener);
|
|
241
|
+
} else if (isOnlyListener(listeners)) {
|
|
242
|
+
__privateGet(this, _events).set(event, [listeners, listener]);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
removeListener(event, listener) {
|
|
246
|
+
if (!__privateGet(this, _events).has(event)) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
const listenerOrListeners = __privateGet(this, _events).get(event);
|
|
250
|
+
let position = -1;
|
|
251
|
+
if (listenerOrListeners === listener) {
|
|
252
|
+
__privateGet(this, _events).delete(event);
|
|
253
|
+
} else if (Array.isArray(listenerOrListeners)) {
|
|
254
|
+
for (let i = listenerOrListeners.length; i-- > 0; ) {
|
|
255
|
+
if (listenerOrListeners[i] === listener) {
|
|
256
|
+
position = i;
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (position < 0) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
if (listenerOrListeners.length === 1) {
|
|
264
|
+
listenerOrListeners.length = 0;
|
|
265
|
+
__privateGet(this, _events).delete(event);
|
|
266
|
+
} else {
|
|
267
|
+
listenerOrListeners.splice(position, 1);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
removeAllListeners(event) {
|
|
272
|
+
if (event && __privateGet(this, _events).has(event)) {
|
|
273
|
+
__privateGet(this, _events).delete(event);
|
|
274
|
+
} else if (event === void 0) {
|
|
275
|
+
__privateGet(this, _events).clear();
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
emit(event, ...args) {
|
|
279
|
+
if (__privateGet(this, _events)) {
|
|
280
|
+
const handler = __privateGet(this, _events).get(event);
|
|
281
|
+
if (handler) {
|
|
282
|
+
this.invokeHandler(handler, args);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
once(event, listener) {
|
|
287
|
+
const handler = (...args) => {
|
|
288
|
+
this.removeListener(event, handler);
|
|
289
|
+
listener(...args);
|
|
290
|
+
};
|
|
291
|
+
this.on(event, handler);
|
|
292
|
+
}
|
|
293
|
+
on(event, listener) {
|
|
294
|
+
this.addListener(event, listener);
|
|
295
|
+
}
|
|
296
|
+
hasListener(event, listener) {
|
|
297
|
+
const listeners = __privateGet(this, _events).get(event);
|
|
298
|
+
if (Array.isArray(listeners)) {
|
|
299
|
+
return listeners.includes(listener);
|
|
300
|
+
} else {
|
|
301
|
+
return listeners === listener;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
invokeHandler(handler, args) {
|
|
305
|
+
if (isArrayOfListeners(handler)) {
|
|
306
|
+
handler.slice().forEach((listener) => this.invokeHandler(listener, args));
|
|
307
|
+
} else {
|
|
308
|
+
switch (args.length) {
|
|
309
|
+
case 0:
|
|
310
|
+
handler();
|
|
311
|
+
break;
|
|
312
|
+
case 1:
|
|
313
|
+
handler(args[0]);
|
|
314
|
+
break;
|
|
315
|
+
case 2:
|
|
316
|
+
handler(args[0], args[1]);
|
|
317
|
+
break;
|
|
318
|
+
// slower
|
|
319
|
+
default:
|
|
320
|
+
handler.call(null, ...args);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
_events = new WeakMap();
|
|
326
|
+
|
|
327
|
+
// ../vuu-utils/src/datasource/datasource-utils.ts
|
|
328
|
+
var isConnectionQualityMetrics = (msg) => msg.type === "connection-metrics";
|
|
329
|
+
var isVisualLinkMessage = (msg) => msg.type.endsWith("_VISUAL_LINK");
|
|
330
|
+
var isViewportMessage = (msg) => "viewport" in msg;
|
|
331
|
+
|
|
332
|
+
// ../vuu-utils/src/logging-utils.ts
|
|
333
|
+
var logLevels = ["error", "warn", "info", "debug"];
|
|
334
|
+
var isValidLogLevel = (value) => typeof value === "string" && logLevels.includes(value);
|
|
335
|
+
var DEFAULT_LOG_LEVEL = "error";
|
|
336
|
+
var NO_OP = () => void 0;
|
|
337
|
+
var DEFAULT_DEBUG_LEVEL = false ? "error" : "info";
|
|
338
|
+
var { loggingLevel = DEFAULT_DEBUG_LEVEL } = getLoggingSettings();
|
|
339
|
+
var logger = (category) => {
|
|
340
|
+
const debugEnabled4 = loggingLevel === "debug";
|
|
341
|
+
const infoEnabled4 = debugEnabled4 || loggingLevel === "info";
|
|
342
|
+
const warnEnabled = infoEnabled4 || loggingLevel === "warn";
|
|
343
|
+
const errorEnabled = warnEnabled || loggingLevel === "error";
|
|
344
|
+
const info4 = infoEnabled4 ? (message) => console.info(\`[\${category}] \${message}\`) : NO_OP;
|
|
345
|
+
const warn3 = warnEnabled ? (message) => console.warn(\`[\${category}] \${message}\`) : NO_OP;
|
|
346
|
+
const debug4 = debugEnabled4 ? (message) => console.debug(\`[\${category}] \${message}\`) : NO_OP;
|
|
347
|
+
const error3 = errorEnabled ? (message) => console.error(\`[\${category}] \${message}\`) : NO_OP;
|
|
348
|
+
if (false) {
|
|
349
|
+
return {
|
|
350
|
+
errorEnabled,
|
|
351
|
+
error: error3
|
|
352
|
+
};
|
|
353
|
+
} else {
|
|
354
|
+
return {
|
|
355
|
+
debugEnabled: debugEnabled4,
|
|
356
|
+
infoEnabled: infoEnabled4,
|
|
357
|
+
warnEnabled,
|
|
358
|
+
errorEnabled,
|
|
359
|
+
info: info4,
|
|
360
|
+
warn: warn3,
|
|
361
|
+
debug: debug4,
|
|
362
|
+
error: error3
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
function getLoggingSettings() {
|
|
367
|
+
if (typeof loggingSettings !== "undefined") {
|
|
368
|
+
return loggingSettings;
|
|
369
|
+
} else {
|
|
370
|
+
return {
|
|
371
|
+
loggingLevel: getLoggingLevelFromCookie()
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
function getLoggingLevelFromCookie() {
|
|
376
|
+
const value = getCookieValue("vuu-logging-level");
|
|
377
|
+
if (isValidLogLevel(value)) {
|
|
378
|
+
return value;
|
|
379
|
+
} else {
|
|
380
|
+
return DEFAULT_LOG_LEVEL;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// ../vuu-utils/src/debug-utils.ts
|
|
385
|
+
var { debug, debugEnabled } = logger("range-monitor");
|
|
386
|
+
var RangeMonitor = class {
|
|
387
|
+
constructor(source) {
|
|
388
|
+
this.source = source;
|
|
389
|
+
__publicField(this, "range", { from: 0, to: 0 });
|
|
390
|
+
__publicField(this, "timestamp", 0);
|
|
391
|
+
}
|
|
392
|
+
isSet() {
|
|
393
|
+
return this.timestamp !== 0;
|
|
394
|
+
}
|
|
395
|
+
set({ from, to }) {
|
|
396
|
+
const { timestamp } = this;
|
|
397
|
+
this.range.from = from;
|
|
398
|
+
this.range.to = to;
|
|
399
|
+
this.timestamp = performance.now();
|
|
400
|
+
if (timestamp) {
|
|
401
|
+
debugEnabled && debug(
|
|
402
|
+
\`<\${this.source}> [\${from}-\${to}], \${(this.timestamp - timestamp).toFixed(0)} ms elapsed\`
|
|
403
|
+
);
|
|
404
|
+
} else {
|
|
405
|
+
return 0;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
// ../vuu-utils/src/keyset.ts
|
|
411
|
+
var EMPTY = [];
|
|
412
|
+
var KeySet = class {
|
|
413
|
+
constructor(range) {
|
|
414
|
+
__publicField(this, "keys", /* @__PURE__ */ new Map());
|
|
415
|
+
__publicField(this, "nextKeyValue", 0);
|
|
416
|
+
__publicField(this, "range");
|
|
417
|
+
this.range = range;
|
|
418
|
+
this.init(range);
|
|
419
|
+
}
|
|
420
|
+
next(free = EMPTY) {
|
|
421
|
+
if (free.length > 0) {
|
|
422
|
+
return free.shift();
|
|
423
|
+
} else {
|
|
424
|
+
return this.nextKeyValue++;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
init({ from, to }) {
|
|
428
|
+
this.keys.clear();
|
|
429
|
+
this.nextKeyValue = 0;
|
|
430
|
+
for (let rowIndex = from; rowIndex < to; rowIndex++) {
|
|
431
|
+
const nextKeyValue = this.next();
|
|
432
|
+
this.keys.set(rowIndex, nextKeyValue);
|
|
433
|
+
}
|
|
434
|
+
return true;
|
|
435
|
+
}
|
|
436
|
+
reset(range) {
|
|
437
|
+
const { from, to } = range;
|
|
438
|
+
const newSize = to - from;
|
|
439
|
+
const currentSize = this.range.to - this.range.from;
|
|
440
|
+
this.range = range;
|
|
441
|
+
if (currentSize > newSize) {
|
|
442
|
+
return this.init(range);
|
|
443
|
+
}
|
|
444
|
+
const freeKeys = [];
|
|
445
|
+
this.keys.forEach((keyValue, rowIndex) => {
|
|
446
|
+
if (rowIndex < from || rowIndex >= to) {
|
|
447
|
+
freeKeys.push(keyValue);
|
|
448
|
+
this.keys.delete(rowIndex);
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
for (let rowIndex = from; rowIndex < to; rowIndex++) {
|
|
452
|
+
if (!this.keys.has(rowIndex)) {
|
|
453
|
+
const nextKeyValue = this.next(freeKeys);
|
|
454
|
+
this.keys.set(rowIndex, nextKeyValue);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
keyFor(rowIndex) {
|
|
460
|
+
const key = this.keys.get(rowIndex);
|
|
461
|
+
if (key === void 0) {
|
|
462
|
+
console.log(\`key not found
|
|
463
|
+
keys: \${this.toDebugString()}
|
|
464
|
+
\`);
|
|
465
|
+
throw Error(\`KeySet, no key found for rowIndex \${rowIndex}\`);
|
|
466
|
+
}
|
|
467
|
+
return key;
|
|
468
|
+
}
|
|
469
|
+
toDebugString() {
|
|
470
|
+
return \`\${this.keys.size} keys
|
|
471
|
+
\${Array.from(this.keys.entries()).sort(([key1], [key2]) => key1 - key2).map(([k, v]) => \`\${k}=>\${v}\`).join(",")}]
|
|
472
|
+
\`;
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
// ../vuu-utils/src/selection-utils.ts
|
|
477
|
+
var { SELECTED } = metadataKeys;
|
|
478
|
+
var RowSelected = {
|
|
479
|
+
False: 0,
|
|
480
|
+
True: 1,
|
|
481
|
+
First: 2,
|
|
482
|
+
Last: 4
|
|
483
|
+
};
|
|
484
|
+
var rangeIncludes = (range, index) => index >= range[0] && index <= range[1];
|
|
485
|
+
var SINGLE_SELECTED_ROW = RowSelected.True + RowSelected.First + RowSelected.Last;
|
|
486
|
+
var FIRST_SELECTED_ROW_OF_BLOCK = RowSelected.True + RowSelected.First;
|
|
487
|
+
var LAST_SELECTED_ROW_OF_BLOCK = RowSelected.True + RowSelected.Last;
|
|
488
|
+
var getSelectionStatus = (selected, itemIndex) => {
|
|
489
|
+
for (const item of selected) {
|
|
490
|
+
if (typeof item === "number") {
|
|
491
|
+
if (item === itemIndex) {
|
|
492
|
+
return SINGLE_SELECTED_ROW;
|
|
493
|
+
}
|
|
494
|
+
} else if (rangeIncludes(item, itemIndex)) {
|
|
495
|
+
if (itemIndex === item[0]) {
|
|
496
|
+
return FIRST_SELECTED_ROW_OF_BLOCK;
|
|
497
|
+
} else if (itemIndex === item[1]) {
|
|
498
|
+
return LAST_SELECTED_ROW_OF_BLOCK;
|
|
499
|
+
} else {
|
|
500
|
+
return RowSelected.True;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return RowSelected.False;
|
|
505
|
+
};
|
|
506
|
+
var expandSelection = (selected) => {
|
|
507
|
+
if (selected.every((selectedItem) => typeof selectedItem === "number")) {
|
|
508
|
+
return selected;
|
|
509
|
+
}
|
|
510
|
+
const expandedSelected = [];
|
|
511
|
+
for (const selectedItem of selected) {
|
|
512
|
+
if (typeof selectedItem === "number") {
|
|
513
|
+
expandedSelected.push(selectedItem);
|
|
514
|
+
} else {
|
|
515
|
+
for (let i = selectedItem[0]; i <= selectedItem[1]; i++) {
|
|
516
|
+
expandedSelected.push(i);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return expandedSelected;
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
// ../vuu-utils/src/promise-utils.ts
|
|
524
|
+
var _promise, _resolve, _reject, _resolved;
|
|
525
|
+
var DeferredPromise = class {
|
|
526
|
+
constructor() {
|
|
527
|
+
__privateAdd(this, _promise);
|
|
528
|
+
__privateAdd(this, _resolve, () => console.log("resolve was not set"));
|
|
529
|
+
__privateAdd(this, _reject, () => console.log("reject was not set"));
|
|
530
|
+
__privateAdd(this, _resolved, false);
|
|
531
|
+
__privateSet(this, _promise, new Promise((resolve, reject) => {
|
|
532
|
+
__privateSet(this, _resolve, resolve);
|
|
533
|
+
__privateSet(this, _reject, reject);
|
|
534
|
+
}));
|
|
535
|
+
}
|
|
536
|
+
get promise() {
|
|
537
|
+
return __privateGet(this, _promise);
|
|
538
|
+
}
|
|
539
|
+
get isResolved() {
|
|
540
|
+
return __privateGet(this, _resolved);
|
|
541
|
+
}
|
|
542
|
+
resolve(value) {
|
|
543
|
+
__privateSet(this, _resolved, true);
|
|
544
|
+
return __privateGet(this, _resolve).call(this, value);
|
|
545
|
+
}
|
|
546
|
+
get reject() {
|
|
547
|
+
return __privateGet(this, _reject);
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
_promise = new WeakMap();
|
|
551
|
+
_resolve = new WeakMap();
|
|
552
|
+
_reject = new WeakMap();
|
|
553
|
+
_resolved = new WeakMap();
|
|
554
|
+
|
|
555
|
+
// ../vuu-utils/src/protocol-message-utils.ts
|
|
556
|
+
var MENU_RPC_TYPES = [
|
|
557
|
+
"VIEW_PORT_MENUS_SELECT_RPC",
|
|
558
|
+
"VIEW_PORT_MENU_TABLE_RPC",
|
|
559
|
+
"VIEW_PORT_MENU_ROW_RPC",
|
|
560
|
+
"VIEW_PORT_MENU_CELL_RPC",
|
|
561
|
+
"VP_EDIT_CELL_RPC",
|
|
562
|
+
"VP_EDIT_ROW_RPC",
|
|
563
|
+
"VP_EDIT_ADD_ROW_RPC",
|
|
564
|
+
"VP_EDIT_DELETE_CELL_RPC",
|
|
565
|
+
"VP_EDIT_DELETE_ROW_RPC",
|
|
566
|
+
"VP_EDIT_SUBMIT_FORM_RPC"
|
|
567
|
+
];
|
|
568
|
+
var isVuuMenuRpcRequest = (message) => MENU_RPC_TYPES.includes(message["type"]);
|
|
569
|
+
var isOpenDialogAction = (action) => action !== void 0 && action.type === "OPEN_DIALOG_ACTION";
|
|
570
|
+
var isSessionTable = (table) => {
|
|
571
|
+
if (table !== null && typeof table === "object" && "table" in table && "module" in table) {
|
|
572
|
+
return table.table.startsWith("session");
|
|
573
|
+
}
|
|
574
|
+
return false;
|
|
575
|
+
};
|
|
576
|
+
function isActionMessage(rpcResponse) {
|
|
577
|
+
return rpcResponse.type === "VIEW_PORT_MENU_RESP" || rpcResponse.type === "VIEW_PORT_RPC_REPONSE";
|
|
578
|
+
}
|
|
579
|
+
function isSessionTableActionMessage(rpcResponse) {
|
|
580
|
+
var _a;
|
|
581
|
+
return isActionMessage(rpcResponse) && isOpenDialogAction(rpcResponse.action) && isSessionTable(rpcResponse.action.table) && ((_a = rpcResponse.action) == null ? void 0 : _a.renderComponent) === "inline-form";
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// src/message-utils.ts
|
|
585
|
+
var isVuuRpcRequest = (message) => message["type"] === "VIEW_PORT_RPC_CALL";
|
|
586
|
+
var stripRequestId = ({
|
|
587
|
+
requestId,
|
|
588
|
+
...rest
|
|
589
|
+
}) => [requestId, rest];
|
|
590
|
+
var getFirstAndLastRows = (rows) => {
|
|
591
|
+
let firstRow = rows.at(0);
|
|
592
|
+
if (firstRow.updateType === "SIZE") {
|
|
593
|
+
if (rows.length === 1) {
|
|
594
|
+
return rows;
|
|
595
|
+
} else {
|
|
596
|
+
firstRow = rows.at(1);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
const lastRow = rows.at(-1);
|
|
600
|
+
return [firstRow, lastRow];
|
|
601
|
+
};
|
|
602
|
+
var insertRow = (rows, row) => {
|
|
603
|
+
const lastRow = rows.at(-1);
|
|
604
|
+
if (lastRow === void 0 || row.rowIndex > lastRow.rowIndex) {
|
|
605
|
+
rows.push(row);
|
|
606
|
+
} else {
|
|
607
|
+
for (let i = 0; i < rows.length; i++) {
|
|
608
|
+
if (row.rowIndex < rows[i].rowIndex) {
|
|
609
|
+
rows.splice(i, 0, row);
|
|
610
|
+
return;
|
|
611
|
+
} else if (row.rowIndex === rows[i].rowIndex) {
|
|
612
|
+
if (row.ts < rows[i].ts) {
|
|
613
|
+
} else {
|
|
614
|
+
rows[i] = row;
|
|
615
|
+
}
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
throw Error("don't expect to get this far");
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
var groupRowsByViewport = (rows) => {
|
|
623
|
+
const result = {};
|
|
624
|
+
for (const row of rows) {
|
|
625
|
+
const rowsForViewport = result[row.viewPortId] || (result[row.viewPortId] = []);
|
|
626
|
+
insertRow(rowsForViewport, row);
|
|
627
|
+
}
|
|
628
|
+
return result;
|
|
629
|
+
};
|
|
630
|
+
var createSchemaFromTableMetadata = ({
|
|
631
|
+
columns,
|
|
632
|
+
dataTypes,
|
|
633
|
+
key,
|
|
634
|
+
table
|
|
635
|
+
}) => {
|
|
636
|
+
return {
|
|
637
|
+
table,
|
|
638
|
+
columns: columns.map((col, idx) => ({
|
|
639
|
+
name: col,
|
|
640
|
+
serverDataType: dataTypes[idx]
|
|
641
|
+
})),
|
|
642
|
+
key
|
|
643
|
+
};
|
|
644
|
+
};
|
|
645
|
+
var gapBetweenLastRowSentToClient = (lastRowsReturnedToClient, pendingUpdates, clientRange) => {
|
|
646
|
+
const firstPendingUpdate = pendingUpdates.at(0);
|
|
647
|
+
const lastPendingUpdate = pendingUpdates.at(-1);
|
|
648
|
+
if (firstPendingUpdate && lastPendingUpdate) {
|
|
649
|
+
const [firstRowIndex, lastRowIndex] = lastRowsReturnedToClient;
|
|
650
|
+
if (lastRowIndex < firstPendingUpdate.rowIndex - 1 && clientRange.from < firstPendingUpdate.rowIndex) {
|
|
651
|
+
return {
|
|
652
|
+
from: Math.max(lastRowIndex + 1, clientRange.from),
|
|
653
|
+
to: firstPendingUpdate.rowIndex
|
|
654
|
+
};
|
|
655
|
+
} else if (firstRowIndex > lastPendingUpdate.rowIndex + 1 && clientRange.to > lastPendingUpdate.rowIndex) {
|
|
656
|
+
return {
|
|
657
|
+
from: lastPendingUpdate.rowIndex + 1,
|
|
658
|
+
to: Math.min(clientRange.to, firstRowIndex)
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
|
|
664
|
+
// src/server-proxy/messages.ts
|
|
665
|
+
var CHANGE_VP_SUCCESS = "CHANGE_VP_SUCCESS";
|
|
666
|
+
var CLOSE_TREE_NODE = "CLOSE_TREE_NODE";
|
|
667
|
+
var CLOSE_TREE_SUCCESS = "CLOSE_TREE_SUCCESS";
|
|
668
|
+
var CREATE_VP = "CREATE_VP";
|
|
669
|
+
var DISABLE_VP = "DISABLE_VP";
|
|
670
|
+
var DISABLE_VP_SUCCESS = "DISABLE_VP_SUCCESS";
|
|
671
|
+
var ENABLE_VP = "ENABLE_VP";
|
|
672
|
+
var ENABLE_VP_SUCCESS = "ENABLE_VP_SUCCESS";
|
|
673
|
+
var GET_VP_VISUAL_LINKS = "GET_VP_VISUAL_LINKS";
|
|
674
|
+
var GET_VIEW_PORT_MENUS = "GET_VIEW_PORT_MENUS";
|
|
675
|
+
var HB = "HB";
|
|
676
|
+
var HB_RESP = "HB_RESP";
|
|
677
|
+
var LOGIN = "LOGIN";
|
|
678
|
+
var OPEN_TREE_NODE = "OPEN_TREE_NODE";
|
|
679
|
+
var OPEN_TREE_SUCCESS = "OPEN_TREE_SUCCESS";
|
|
680
|
+
var REMOVE_VP = "REMOVE_VP";
|
|
681
|
+
var SET_SELECTION_SUCCESS = "SET_SELECTION_SUCCESS";
|
|
682
|
+
|
|
683
|
+
// src/server-proxy/rpc-services.ts
|
|
684
|
+
var getRpcServiceModule = (service) => {
|
|
685
|
+
switch (service) {
|
|
686
|
+
case "TypeAheadRpcHandler":
|
|
687
|
+
return "TYPEAHEAD";
|
|
688
|
+
default:
|
|
689
|
+
return "SIMUL";
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
// src/server-proxy/array-backed-moving-window.ts
|
|
694
|
+
var EMPTY_ARRAY = [];
|
|
695
|
+
var log = logger("array-backed-moving-window");
|
|
696
|
+
function dataIsUnchanged(newRow, existingRow) {
|
|
697
|
+
if (!existingRow) {
|
|
698
|
+
return false;
|
|
699
|
+
}
|
|
700
|
+
if (existingRow.data.length !== newRow.data.length) {
|
|
701
|
+
return false;
|
|
702
|
+
}
|
|
703
|
+
if (existingRow.sel !== newRow.sel) {
|
|
704
|
+
return false;
|
|
705
|
+
}
|
|
706
|
+
for (let i = 0; i < existingRow.data.length; i++) {
|
|
707
|
+
if (existingRow.data[i] !== newRow.data[i]) {
|
|
708
|
+
return false;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
return true;
|
|
712
|
+
}
|
|
713
|
+
var _range;
|
|
714
|
+
var ArrayBackedMovingWindow = class {
|
|
715
|
+
// Note, the buffer is already accounted for in the range passed in here
|
|
716
|
+
constructor({ from: clientFrom, to: clientTo }, { from, to }, bufferSize) {
|
|
717
|
+
__privateAdd(this, _range);
|
|
718
|
+
__publicField(this, "bufferSize");
|
|
719
|
+
__publicField(this, "internalData");
|
|
720
|
+
__publicField(this, "rowsWithinRange");
|
|
721
|
+
__publicField(this, "clientRange");
|
|
722
|
+
__publicField(this, "rowCount");
|
|
723
|
+
__publicField(this, "setRowCount", (rowCount) => {
|
|
724
|
+
var _a;
|
|
725
|
+
(_a = log.info) == null ? void 0 : _a.call(log, \`setRowCount \${rowCount}\`);
|
|
726
|
+
if (rowCount < this.internalData.length) {
|
|
727
|
+
this.internalData.length = rowCount;
|
|
728
|
+
}
|
|
729
|
+
if (rowCount < this.rowCount) {
|
|
730
|
+
this.rowsWithinRange = 0;
|
|
731
|
+
const end = Math.min(rowCount, this.clientRange.to);
|
|
732
|
+
for (let i = this.clientRange.from; i < end; i++) {
|
|
733
|
+
const rowIndex = i - __privateGet(this, _range).from;
|
|
734
|
+
if (this.internalData[rowIndex] !== void 0) {
|
|
735
|
+
this.rowsWithinRange += 1;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
this.rowCount = rowCount;
|
|
740
|
+
});
|
|
741
|
+
__publicField(this, "bufferBreakout", (from, to) => {
|
|
742
|
+
const bufferPerimeter = this.bufferSize * 0.25;
|
|
743
|
+
if (__privateGet(this, _range).to - to < bufferPerimeter) {
|
|
744
|
+
return true;
|
|
745
|
+
} else if (__privateGet(this, _range).from > 0 && from - __privateGet(this, _range).from < bufferPerimeter) {
|
|
746
|
+
return true;
|
|
747
|
+
} else {
|
|
748
|
+
return false;
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
this.bufferSize = bufferSize;
|
|
752
|
+
this.clientRange = new WindowRange(clientFrom, clientTo);
|
|
753
|
+
__privateSet(this, _range, new WindowRange(from, to));
|
|
754
|
+
this.internalData = new Array(bufferSize);
|
|
755
|
+
this.rowsWithinRange = 0;
|
|
756
|
+
this.rowCount = 0;
|
|
757
|
+
}
|
|
758
|
+
get range() {
|
|
759
|
+
return __privateGet(this, _range);
|
|
760
|
+
}
|
|
761
|
+
// TODO we should probably have a hasAllClientRowsWithinRange
|
|
762
|
+
get hasAllRowsWithinRange() {
|
|
763
|
+
return this.rowsWithinRange === this.clientRange.to - this.clientRange.from || // this.rowsWithinRange === this.range.to - this.range.from ||
|
|
764
|
+
this.rowCount > 0 && this.clientRange.from + this.rowsWithinRange === this.rowCount;
|
|
765
|
+
}
|
|
766
|
+
// Check to see if set of rows is outside the current viewport range, indicating
|
|
767
|
+
// that veiwport is being scrolled quickly and server is not able to keep up.
|
|
768
|
+
outOfRange(firstIndex, lastIndex) {
|
|
769
|
+
const { from, to } = this.range;
|
|
770
|
+
if (lastIndex < from) {
|
|
771
|
+
return true;
|
|
772
|
+
}
|
|
773
|
+
if (firstIndex >= to) {
|
|
774
|
+
return true;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
setAtIndex(row) {
|
|
778
|
+
const { rowIndex: index } = row;
|
|
779
|
+
const internalIndex = index - __privateGet(this, _range).from;
|
|
780
|
+
if (dataIsUnchanged(row, this.internalData[internalIndex])) {
|
|
781
|
+
return false;
|
|
782
|
+
}
|
|
783
|
+
const isWithinClientRange = this.isWithinClientRange(index);
|
|
784
|
+
if (isWithinClientRange || this.isWithinRange(index)) {
|
|
785
|
+
if (!this.internalData[internalIndex] && isWithinClientRange) {
|
|
786
|
+
this.rowsWithinRange += 1;
|
|
787
|
+
}
|
|
788
|
+
this.internalData[internalIndex] = row;
|
|
789
|
+
}
|
|
790
|
+
return isWithinClientRange;
|
|
791
|
+
}
|
|
792
|
+
getAtIndex(index) {
|
|
793
|
+
return __privateGet(this, _range).isWithin(index) && this.internalData[index - __privateGet(this, _range).from] != null ? this.internalData[index - __privateGet(this, _range).from] : void 0;
|
|
794
|
+
}
|
|
795
|
+
isWithinRange(index) {
|
|
796
|
+
return __privateGet(this, _range).isWithin(index);
|
|
797
|
+
}
|
|
798
|
+
isWithinClientRange(index) {
|
|
799
|
+
return this.clientRange.isWithin(index);
|
|
800
|
+
}
|
|
801
|
+
// Returns [false] or [serverDataRequired, clientRows, holdingRows]
|
|
802
|
+
setClientRange(from, to) {
|
|
803
|
+
var _a;
|
|
804
|
+
(_a = log.debug) == null ? void 0 : _a.call(log, \`setClientRange \${from} - \${to}\`);
|
|
805
|
+
const currentFrom = this.clientRange.from;
|
|
806
|
+
const currentTo = Math.min(this.clientRange.to, this.rowCount);
|
|
807
|
+
if (from === currentFrom && to === currentTo) {
|
|
808
|
+
return [
|
|
809
|
+
false,
|
|
810
|
+
EMPTY_ARRAY
|
|
811
|
+
/*, EMPTY_ARRAY*/
|
|
812
|
+
];
|
|
813
|
+
}
|
|
814
|
+
const originalRange = this.clientRange.copy();
|
|
815
|
+
this.clientRange.from = from;
|
|
816
|
+
this.clientRange.to = to;
|
|
817
|
+
this.rowsWithinRange = 0;
|
|
818
|
+
for (let i = from; i < to; i++) {
|
|
819
|
+
const internalIndex = i - __privateGet(this, _range).from;
|
|
820
|
+
if (this.internalData[internalIndex]) {
|
|
821
|
+
this.rowsWithinRange += 1;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
let clientRows = EMPTY_ARRAY;
|
|
825
|
+
const offset = __privateGet(this, _range).from;
|
|
826
|
+
if (this.hasAllRowsWithinRange) {
|
|
827
|
+
if (to > originalRange.to) {
|
|
828
|
+
const start = Math.max(from, originalRange.to);
|
|
829
|
+
clientRows = this.internalData.slice(start - offset, to - offset);
|
|
830
|
+
} else {
|
|
831
|
+
const end = Math.min(originalRange.from, to);
|
|
832
|
+
clientRows = this.internalData.slice(from - offset, end - offset);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
const serverDataRequired = this.bufferBreakout(from, to);
|
|
836
|
+
return [serverDataRequired, clientRows];
|
|
837
|
+
}
|
|
838
|
+
setRange(from, to) {
|
|
839
|
+
var _a, _b;
|
|
840
|
+
if (from !== __privateGet(this, _range).from || to !== __privateGet(this, _range).to) {
|
|
841
|
+
(_a = log.debug) == null ? void 0 : _a.call(log, \`setRange \${from} - \${to}\`);
|
|
842
|
+
const [overlapFrom, overlapTo] = __privateGet(this, _range).overlap(from, to);
|
|
843
|
+
const newData = new Array(to - from);
|
|
844
|
+
this.rowsWithinRange = 0;
|
|
845
|
+
for (let i = overlapFrom; i < overlapTo; i++) {
|
|
846
|
+
const row = this.getAtIndex(i);
|
|
847
|
+
if (row) {
|
|
848
|
+
const index = i - from;
|
|
849
|
+
newData[index] = row;
|
|
850
|
+
if (this.isWithinClientRange(i)) {
|
|
851
|
+
this.rowsWithinRange += 1;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
this.internalData = newData;
|
|
856
|
+
__privateGet(this, _range).from = from;
|
|
857
|
+
__privateGet(this, _range).to = to;
|
|
858
|
+
} else {
|
|
859
|
+
(_b = log.debug) == null ? void 0 : _b.call(log, \`setRange \${from} - \${to} IGNORED because not changed\`);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
//TODO temp
|
|
863
|
+
get data() {
|
|
864
|
+
return this.internalData;
|
|
865
|
+
}
|
|
866
|
+
getData() {
|
|
867
|
+
var _a;
|
|
868
|
+
const { from, to } = __privateGet(this, _range);
|
|
869
|
+
const { from: clientFrom, to: clientTo } = this.clientRange;
|
|
870
|
+
const startOffset = Math.max(0, clientFrom - from);
|
|
871
|
+
const endOffset = Math.min(
|
|
872
|
+
to - from,
|
|
873
|
+
to,
|
|
874
|
+
clientTo - from,
|
|
875
|
+
(_a = this.rowCount) != null ? _a : to
|
|
876
|
+
);
|
|
877
|
+
return this.internalData.slice(startOffset, endOffset);
|
|
878
|
+
}
|
|
879
|
+
clear() {
|
|
880
|
+
var _a;
|
|
881
|
+
(_a = log.debug) == null ? void 0 : _a.call(log, "clear");
|
|
882
|
+
this.internalData.length = 0;
|
|
883
|
+
this.rowsWithinRange = 0;
|
|
884
|
+
this.setRowCount(0);
|
|
885
|
+
}
|
|
886
|
+
// used only for debugging
|
|
887
|
+
getCurrentDataRange() {
|
|
888
|
+
const rows = this.internalData;
|
|
889
|
+
const len = rows.length;
|
|
890
|
+
let [firstRow] = this.internalData;
|
|
891
|
+
let lastRow = this.internalData[len - 1];
|
|
892
|
+
if (firstRow && lastRow) {
|
|
893
|
+
return [firstRow.rowIndex, lastRow.rowIndex];
|
|
894
|
+
} else {
|
|
895
|
+
for (let i = 0; i < len; i++) {
|
|
896
|
+
if (rows[i] !== void 0) {
|
|
897
|
+
firstRow = rows[i];
|
|
898
|
+
break;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
for (let i = len - 1; i >= 0; i--) {
|
|
902
|
+
if (rows[i] !== void 0) {
|
|
903
|
+
lastRow = rows[i];
|
|
904
|
+
break;
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
if (firstRow && lastRow) {
|
|
908
|
+
return [firstRow.rowIndex, lastRow.rowIndex];
|
|
909
|
+
} else {
|
|
910
|
+
return [-1, -1];
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
};
|
|
915
|
+
_range = new WeakMap();
|
|
916
|
+
|
|
917
|
+
// src/server-proxy/viewport.ts
|
|
918
|
+
var { debug: debug2, debugEnabled: debugEnabled2, error, info, infoEnabled, warn } = logger("Viewport");
|
|
919
|
+
var isLeafUpdate = ({ rowKey, updateType }) => updateType === "U" && !rowKey.startsWith("$root");
|
|
920
|
+
var NO_DATA_UPDATE = [
|
|
921
|
+
void 0,
|
|
922
|
+
void 0
|
|
923
|
+
];
|
|
924
|
+
var NO_UPDATE_STATUS = {
|
|
925
|
+
count: 0,
|
|
926
|
+
mode: void 0,
|
|
927
|
+
size: 0,
|
|
928
|
+
ts: 0
|
|
929
|
+
};
|
|
930
|
+
var _status, _clientRange;
|
|
931
|
+
var Viewport = class {
|
|
932
|
+
constructor({
|
|
933
|
+
aggregations,
|
|
934
|
+
bufferSize = 50,
|
|
935
|
+
columns,
|
|
936
|
+
filterSpec: filter,
|
|
937
|
+
groupBy = [],
|
|
938
|
+
table,
|
|
939
|
+
range,
|
|
940
|
+
sort,
|
|
941
|
+
title,
|
|
942
|
+
viewport,
|
|
943
|
+
visualLink
|
|
944
|
+
}, postMessageToClient) {
|
|
945
|
+
__privateAdd(this, _status, "");
|
|
946
|
+
__publicField(this, "aggregations");
|
|
947
|
+
__publicField(this, "batchMode", false);
|
|
948
|
+
__publicField(this, "bufferSize");
|
|
949
|
+
/**
|
|
950
|
+
* clientRange is always the range requested by the client. We should assume
|
|
951
|
+
* these are the rows visible to the user
|
|
952
|
+
* TODO what is clientRange needed for ?
|
|
953
|
+
*/
|
|
954
|
+
__privateAdd(this, _clientRange);
|
|
955
|
+
__publicField(this, "columns");
|
|
956
|
+
__publicField(this, "dataWindow");
|
|
957
|
+
__publicField(this, "filter");
|
|
958
|
+
__publicField(this, "groupBy");
|
|
959
|
+
__publicField(this, "sort");
|
|
960
|
+
__publicField(this, "hasUpdates", false);
|
|
961
|
+
__publicField(this, "pendingUpdates", []);
|
|
962
|
+
__publicField(this, "keys");
|
|
963
|
+
__publicField(this, "pendingLinkedParent");
|
|
964
|
+
__publicField(this, "pendingOperations", /* @__PURE__ */ new Map());
|
|
965
|
+
__publicField(this, "pendingRangeRequests", []);
|
|
966
|
+
__publicField(this, "postMessageToClient");
|
|
967
|
+
__publicField(this, "rowCountChanged", false);
|
|
968
|
+
__publicField(this, "selectedRows", []);
|
|
969
|
+
__publicField(this, "lastUpdateStatus", NO_UPDATE_STATUS);
|
|
970
|
+
__publicField(this, "updateThrottleTimer");
|
|
971
|
+
__publicField(this, "lastRowsReturnedToClient", [-1, -1]);
|
|
972
|
+
__publicField(this, "rangeMonitor", new RangeMonitor("ViewPort"));
|
|
973
|
+
__publicField(this, "clientViewportId");
|
|
974
|
+
__publicField(this, "disabled", false);
|
|
975
|
+
__publicField(this, "isTree", false);
|
|
976
|
+
__publicField(this, "links");
|
|
977
|
+
__publicField(this, "linkedParent");
|
|
978
|
+
__publicField(this, "serverViewportId");
|
|
979
|
+
// TODO roll disabled/suspended into status
|
|
980
|
+
__publicField(this, "suspended", false);
|
|
981
|
+
__publicField(this, "suspendTimer", null);
|
|
982
|
+
__publicField(this, "table");
|
|
983
|
+
__publicField(this, "title");
|
|
984
|
+
// Records SIZE only updates
|
|
985
|
+
__publicField(this, "setLastSizeOnlyUpdateSize", (size) => {
|
|
986
|
+
this.lastUpdateStatus.size = size;
|
|
987
|
+
});
|
|
988
|
+
__publicField(this, "setLastUpdate", (mode) => {
|
|
989
|
+
const { ts: lastTS, mode: lastMode } = this.lastUpdateStatus;
|
|
990
|
+
let elapsedTime = 0;
|
|
991
|
+
if (lastMode === mode) {
|
|
992
|
+
const ts = Date.now();
|
|
993
|
+
this.lastUpdateStatus.count += 1;
|
|
994
|
+
this.lastUpdateStatus.ts = ts;
|
|
995
|
+
elapsedTime = lastTS === 0 ? 0 : ts - lastTS;
|
|
996
|
+
} else {
|
|
997
|
+
this.lastUpdateStatus.count = 1;
|
|
998
|
+
this.lastUpdateStatus.ts = 0;
|
|
999
|
+
elapsedTime = 0;
|
|
1000
|
+
}
|
|
1001
|
+
this.lastUpdateStatus.mode = mode;
|
|
1002
|
+
return elapsedTime;
|
|
1003
|
+
});
|
|
1004
|
+
__publicField(this, "rangeRequestAlreadyPending", (range) => {
|
|
1005
|
+
const { bufferSize } = this;
|
|
1006
|
+
const bufferThreshold = bufferSize * 0.25;
|
|
1007
|
+
let { from: stillPendingFrom } = range;
|
|
1008
|
+
for (const { from, to } of this.pendingRangeRequests) {
|
|
1009
|
+
if (stillPendingFrom >= from && stillPendingFrom < to) {
|
|
1010
|
+
if (range.to + bufferThreshold <= to) {
|
|
1011
|
+
return true;
|
|
1012
|
+
} else {
|
|
1013
|
+
stillPendingFrom = to;
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
return false;
|
|
1018
|
+
});
|
|
1019
|
+
__publicField(this, "sendThrottledSizeMessage", () => {
|
|
1020
|
+
this.updateThrottleTimer = void 0;
|
|
1021
|
+
this.lastUpdateStatus.count = 3;
|
|
1022
|
+
this.postMessageToClient({
|
|
1023
|
+
clientViewportId: this.clientViewportId,
|
|
1024
|
+
mode: "size-only",
|
|
1025
|
+
size: this.lastUpdateStatus.size,
|
|
1026
|
+
type: "viewport-update"
|
|
1027
|
+
});
|
|
1028
|
+
});
|
|
1029
|
+
// If we are receiving multiple SIZE updates but no data, table is loading rows
|
|
1030
|
+
// outside of our viewport. We can safely throttle these requests. Doing so will
|
|
1031
|
+
// alleviate pressure on UI DataTable.
|
|
1032
|
+
__publicField(this, "shouldThrottleMessage", (mode) => {
|
|
1033
|
+
const elapsedTime = this.setLastUpdate(mode);
|
|
1034
|
+
return mode === "size-only" && elapsedTime > 0 && elapsedTime < 500 && this.lastUpdateStatus.count > 3;
|
|
1035
|
+
});
|
|
1036
|
+
__publicField(this, "throttleMessage", (mode) => {
|
|
1037
|
+
if (this.shouldThrottleMessage(mode)) {
|
|
1038
|
+
info == null ? void 0 : info("throttling updates setTimeout to 2000");
|
|
1039
|
+
if (this.updateThrottleTimer === void 0) {
|
|
1040
|
+
this.updateThrottleTimer = setTimeout(
|
|
1041
|
+
this.sendThrottledSizeMessage,
|
|
1042
|
+
2e3
|
|
1043
|
+
);
|
|
1044
|
+
}
|
|
1045
|
+
return true;
|
|
1046
|
+
} else if (this.updateThrottleTimer !== void 0) {
|
|
1047
|
+
clearTimeout(this.updateThrottleTimer);
|
|
1048
|
+
this.updateThrottleTimer = void 0;
|
|
1049
|
+
}
|
|
1050
|
+
return false;
|
|
1051
|
+
});
|
|
1052
|
+
__publicField(this, "getNewRowCount", () => {
|
|
1053
|
+
if (this.rowCountChanged && this.dataWindow) {
|
|
1054
|
+
this.rowCountChanged = false;
|
|
1055
|
+
return this.dataWindow.rowCount;
|
|
1056
|
+
}
|
|
1057
|
+
});
|
|
1058
|
+
this.aggregations = aggregations;
|
|
1059
|
+
this.bufferSize = bufferSize;
|
|
1060
|
+
__privateSet(this, _clientRange, range);
|
|
1061
|
+
this.clientViewportId = viewport;
|
|
1062
|
+
this.columns = columns;
|
|
1063
|
+
this.filter = filter;
|
|
1064
|
+
this.groupBy = groupBy;
|
|
1065
|
+
this.keys = new KeySet(range);
|
|
1066
|
+
this.pendingLinkedParent = visualLink;
|
|
1067
|
+
this.table = table;
|
|
1068
|
+
this.sort = sort;
|
|
1069
|
+
this.title = title;
|
|
1070
|
+
infoEnabled && (info == null ? void 0 : info(
|
|
1071
|
+
\`constructor #\${viewport} \${table.table} bufferSize=\${bufferSize}\`
|
|
1072
|
+
));
|
|
1073
|
+
this.dataWindow = new ArrayBackedMovingWindow(
|
|
1074
|
+
__privateGet(this, _clientRange),
|
|
1075
|
+
range,
|
|
1076
|
+
this.bufferSize
|
|
1077
|
+
);
|
|
1078
|
+
this.postMessageToClient = postMessageToClient;
|
|
1079
|
+
}
|
|
1080
|
+
get hasUpdatesToProcess() {
|
|
1081
|
+
if (this.suspended) {
|
|
1082
|
+
return false;
|
|
1083
|
+
}
|
|
1084
|
+
return this.rowCountChanged || this.hasUpdates;
|
|
1085
|
+
}
|
|
1086
|
+
get size() {
|
|
1087
|
+
var _a;
|
|
1088
|
+
return (_a = this.dataWindow.rowCount) != null ? _a : 0;
|
|
1089
|
+
}
|
|
1090
|
+
get clientRange() {
|
|
1091
|
+
return __privateGet(this, _clientRange);
|
|
1092
|
+
}
|
|
1093
|
+
get status() {
|
|
1094
|
+
return __privateGet(this, _status);
|
|
1095
|
+
}
|
|
1096
|
+
set status(status) {
|
|
1097
|
+
__privateSet(this, _status, status);
|
|
1098
|
+
}
|
|
1099
|
+
subscribe() {
|
|
1100
|
+
const { filter } = this.filter;
|
|
1101
|
+
this.status = __privateGet(this, _status) === "subscribed" ? "resubscribing" : "subscribing";
|
|
1102
|
+
return {
|
|
1103
|
+
type: CREATE_VP,
|
|
1104
|
+
table: this.table,
|
|
1105
|
+
range: getFullRange(__privateGet(this, _clientRange), this.bufferSize),
|
|
1106
|
+
aggregations: this.aggregations,
|
|
1107
|
+
columns: this.columns,
|
|
1108
|
+
sort: this.sort,
|
|
1109
|
+
groupBy: this.groupBy,
|
|
1110
|
+
filterSpec: { filter }
|
|
1111
|
+
};
|
|
1112
|
+
}
|
|
1113
|
+
handleSubscribed({
|
|
1114
|
+
viewPortId,
|
|
1115
|
+
aggregations,
|
|
1116
|
+
columns,
|
|
1117
|
+
filterSpec: filter,
|
|
1118
|
+
range,
|
|
1119
|
+
sort,
|
|
1120
|
+
groupBy,
|
|
1121
|
+
table
|
|
1122
|
+
}, baseTableSchema) {
|
|
1123
|
+
this.serverViewportId = viewPortId;
|
|
1124
|
+
this.status = "subscribed";
|
|
1125
|
+
this.aggregations = aggregations;
|
|
1126
|
+
this.columns = columns;
|
|
1127
|
+
this.groupBy = groupBy;
|
|
1128
|
+
this.isTree = groupBy && groupBy.length > 0;
|
|
1129
|
+
this.dataWindow.setRange(range.from, range.to);
|
|
1130
|
+
const tableSchema = table === baseTableSchema.table.table ? baseTableSchema : {
|
|
1131
|
+
...baseTableSchema,
|
|
1132
|
+
table: {
|
|
1133
|
+
...baseTableSchema.table,
|
|
1134
|
+
session: table
|
|
1135
|
+
}
|
|
1136
|
+
};
|
|
1137
|
+
return {
|
|
1138
|
+
aggregations,
|
|
1139
|
+
type: "subscribed",
|
|
1140
|
+
clientViewportId: this.clientViewportId,
|
|
1141
|
+
columns,
|
|
1142
|
+
filterSpec: filter,
|
|
1143
|
+
groupBy,
|
|
1144
|
+
range,
|
|
1145
|
+
sort,
|
|
1146
|
+
tableSchema
|
|
1147
|
+
};
|
|
1148
|
+
}
|
|
1149
|
+
awaitOperation(requestId, msg) {
|
|
1150
|
+
this.pendingOperations.set(requestId, msg);
|
|
1151
|
+
}
|
|
1152
|
+
// Return a message if we need to communicate this to client UI
|
|
1153
|
+
completeOperation(requestId, ...params) {
|
|
1154
|
+
var _a;
|
|
1155
|
+
const { clientViewportId, pendingOperations } = this;
|
|
1156
|
+
const pendingOperation = pendingOperations.get(requestId);
|
|
1157
|
+
if (!pendingOperation) {
|
|
1158
|
+
error(
|
|
1159
|
+
\`no matching operation found to complete for requestId \${requestId}\`
|
|
1160
|
+
);
|
|
1161
|
+
return;
|
|
1162
|
+
}
|
|
1163
|
+
const { type } = pendingOperation;
|
|
1164
|
+
info == null ? void 0 : info(\`completeOperation \${type}\`);
|
|
1165
|
+
pendingOperations.delete(requestId);
|
|
1166
|
+
if (type === "CHANGE_VP_RANGE") {
|
|
1167
|
+
const [from, to] = params;
|
|
1168
|
+
infoEnabled && info(
|
|
1169
|
+
\`completeOperation CHANGE_VP_RANGE
|
|
1170
|
+
window setRange (\${from}:\${to}) \${this.pendingRangeRequests.length} range requests pending\`
|
|
1171
|
+
);
|
|
1172
|
+
(_a = this.dataWindow) == null ? void 0 : _a.setRange(from, to);
|
|
1173
|
+
for (let i = this.pendingRangeRequests.length - 1; i >= 0; i--) {
|
|
1174
|
+
const pendingRangeRequest = this.pendingRangeRequests[i];
|
|
1175
|
+
if (pendingRangeRequest.requestId === requestId) {
|
|
1176
|
+
pendingRangeRequest.acked = true;
|
|
1177
|
+
break;
|
|
1178
|
+
} else {
|
|
1179
|
+
warn == null ? void 0 : warn("range requests sent faster than they are being ACKed");
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
} else if (type === "config") {
|
|
1183
|
+
const {
|
|
1184
|
+
aggregations,
|
|
1185
|
+
columns,
|
|
1186
|
+
filterSpec: filter,
|
|
1187
|
+
groupBy,
|
|
1188
|
+
sort
|
|
1189
|
+
} = pendingOperation.data;
|
|
1190
|
+
this.aggregations = aggregations;
|
|
1191
|
+
this.columns = columns;
|
|
1192
|
+
this.filter = filter;
|
|
1193
|
+
this.groupBy = groupBy;
|
|
1194
|
+
this.sort = sort;
|
|
1195
|
+
if (groupBy.length > 0) {
|
|
1196
|
+
this.isTree = true;
|
|
1197
|
+
} else if (this.isTree) {
|
|
1198
|
+
this.isTree = false;
|
|
1199
|
+
}
|
|
1200
|
+
debug2 == null ? void 0 : debug2(\`config change confirmed, isTree : \${this.isTree}\`);
|
|
1201
|
+
return {
|
|
1202
|
+
clientViewportId,
|
|
1203
|
+
type,
|
|
1204
|
+
config: pendingOperation.data
|
|
1205
|
+
};
|
|
1206
|
+
} else if (type === "selection") {
|
|
1207
|
+
} else if (type === "disable") {
|
|
1208
|
+
this.disabled = true;
|
|
1209
|
+
return {
|
|
1210
|
+
type: "disabled",
|
|
1211
|
+
clientViewportId
|
|
1212
|
+
};
|
|
1213
|
+
} else if (type === "enable") {
|
|
1214
|
+
this.disabled = false;
|
|
1215
|
+
return {
|
|
1216
|
+
type: "enabled",
|
|
1217
|
+
clientViewportId
|
|
1218
|
+
};
|
|
1219
|
+
} else if (type === "CREATE_VISUAL_LINK") {
|
|
1220
|
+
const [colName, parentViewportId, parentColName] = params;
|
|
1221
|
+
this.linkedParent = {
|
|
1222
|
+
colName,
|
|
1223
|
+
parentViewportId,
|
|
1224
|
+
parentColName
|
|
1225
|
+
};
|
|
1226
|
+
this.pendingLinkedParent = void 0;
|
|
1227
|
+
return {
|
|
1228
|
+
requestId,
|
|
1229
|
+
type: "vuu-link-created",
|
|
1230
|
+
clientViewportId,
|
|
1231
|
+
colName,
|
|
1232
|
+
parentViewportId,
|
|
1233
|
+
parentColName
|
|
1234
|
+
};
|
|
1235
|
+
} else if (type === "REMOVE_VISUAL_LINK") {
|
|
1236
|
+
this.linkedParent = void 0;
|
|
1237
|
+
return {
|
|
1238
|
+
requestId,
|
|
1239
|
+
type: "vuu-link-removed",
|
|
1240
|
+
clientViewportId
|
|
1241
|
+
};
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
// TODO when a range request arrives, consider the viewport to be scrolling
|
|
1245
|
+
// until data arrives and we have the full range.
|
|
1246
|
+
// When not scrolling, any server data is an update
|
|
1247
|
+
// When scrolling, we are in batch mode
|
|
1248
|
+
rangeRequest(requestId, range) {
|
|
1249
|
+
var _a, _b;
|
|
1250
|
+
if (debugEnabled2) {
|
|
1251
|
+
this.rangeMonitor.set(range);
|
|
1252
|
+
}
|
|
1253
|
+
infoEnabled && info(
|
|
1254
|
+
\`(bufferSize \${this.bufferSize}) rangeRequest (\${range.from}:\${range.to})
|
|
1255
|
+
current: window client (\${this.dataWindow.clientRange.from}:\${this.dataWindow.clientRange.to}), full (\${this.dataWindow.range.from}:\${this.dataWindow.range.to}) \`
|
|
1256
|
+
);
|
|
1257
|
+
const type = "CHANGE_VP_RANGE";
|
|
1258
|
+
if (this.dataWindow) {
|
|
1259
|
+
const [serverDataRequired, clientRows] = this.dataWindow.setClientRange(
|
|
1260
|
+
range.from,
|
|
1261
|
+
range.to
|
|
1262
|
+
);
|
|
1263
|
+
infoEnabled && info(
|
|
1264
|
+
\`updated: window client (\${this.dataWindow.clientRange.from}:\${this.dataWindow.clientRange.to}), full (\${this.dataWindow.range.from}:\${this.dataWindow.range.to})
|
|
1265
|
+
serverDataRequired \${serverDataRequired ? "Y" : "N"}
|
|
1266
|
+
\${clientRows.length} rows returned from local buffer\`
|
|
1267
|
+
);
|
|
1268
|
+
let debounceRequest;
|
|
1269
|
+
const maxRange = this.dataWindow.rowCount || void 0;
|
|
1270
|
+
const serverRequest = serverDataRequired && !this.rangeRequestAlreadyPending(range) ? {
|
|
1271
|
+
type,
|
|
1272
|
+
viewPortId: this.serverViewportId,
|
|
1273
|
+
...getFullRange(range, this.bufferSize, maxRange)
|
|
1274
|
+
} : null;
|
|
1275
|
+
if (serverRequest) {
|
|
1276
|
+
infoEnabled && info(
|
|
1277
|
+
\`create CHANGE_VP_RANGE: (\${serverRequest.from} - \${serverRequest.to})\`
|
|
1278
|
+
);
|
|
1279
|
+
debugEnabled2 && (debug2 == null ? void 0 : debug2(
|
|
1280
|
+
\`create CHANGE_VP_RANGE: [\${serverRequest.from} - \${serverRequest.to}]\`
|
|
1281
|
+
));
|
|
1282
|
+
this.awaitOperation(requestId, { type });
|
|
1283
|
+
const pendingRequest = this.pendingRangeRequests.at(-1);
|
|
1284
|
+
if (pendingRequest) {
|
|
1285
|
+
if (pendingRequest.acked) {
|
|
1286
|
+
console.warn("Range Request before previous request is filled");
|
|
1287
|
+
} else {
|
|
1288
|
+
const { from, to } = pendingRequest;
|
|
1289
|
+
if (this.dataWindow.outOfRange(from, to)) {
|
|
1290
|
+
debounceRequest = {
|
|
1291
|
+
clientViewportId: this.clientViewportId,
|
|
1292
|
+
type: "debounce-begin"
|
|
1293
|
+
};
|
|
1294
|
+
} else {
|
|
1295
|
+
warn == null ? void 0 : warn("Range Request before previous request is acked");
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
this.pendingRangeRequests.push({ ...serverRequest, requestId });
|
|
1300
|
+
} else if (clientRows.length > 0) {
|
|
1301
|
+
this.batchMode = false;
|
|
1302
|
+
}
|
|
1303
|
+
this.keys.reset(this.dataWindow.clientRange);
|
|
1304
|
+
const toClient = this.isTree ? toClientRowTree : toClientRow;
|
|
1305
|
+
if (clientRows.length) {
|
|
1306
|
+
this.lastRowsReturnedToClient[0] = clientRows[0].rowIndex;
|
|
1307
|
+
this.lastRowsReturnedToClient[1] = (_b = (_a = clientRows.at(-1)) == null ? void 0 : _a.rowIndex) != null ? _b : -1;
|
|
1308
|
+
return [
|
|
1309
|
+
serverRequest,
|
|
1310
|
+
clientRows.map((row) => {
|
|
1311
|
+
return toClient(row, this.keys, this.selectedRows);
|
|
1312
|
+
})
|
|
1313
|
+
];
|
|
1314
|
+
} else if (debounceRequest) {
|
|
1315
|
+
return [serverRequest, void 0, debounceRequest];
|
|
1316
|
+
} else {
|
|
1317
|
+
return [serverRequest];
|
|
1318
|
+
}
|
|
1319
|
+
} else {
|
|
1320
|
+
return [null];
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
setLinks(links) {
|
|
1324
|
+
this.links = links.filter(
|
|
1325
|
+
(link) => link.parentVpId !== this.serverViewportId
|
|
1326
|
+
);
|
|
1327
|
+
return [
|
|
1328
|
+
{
|
|
1329
|
+
type: "vuu-links",
|
|
1330
|
+
links: this.links,
|
|
1331
|
+
clientViewportId: this.clientViewportId
|
|
1332
|
+
},
|
|
1333
|
+
this.pendingLinkedParent
|
|
1334
|
+
];
|
|
1335
|
+
}
|
|
1336
|
+
setMenu(menu) {
|
|
1337
|
+
return {
|
|
1338
|
+
type: "vuu-menu",
|
|
1339
|
+
menu,
|
|
1340
|
+
clientViewportId: this.clientViewportId
|
|
1341
|
+
};
|
|
1342
|
+
}
|
|
1343
|
+
openTreeNode(requestId, message) {
|
|
1344
|
+
const treeKey = message.index === void 0 ? message.key : this.getKeyForRowAtIndex(message.index);
|
|
1345
|
+
infoEnabled && info(\`treeKey \${treeKey}\`);
|
|
1346
|
+
return {
|
|
1347
|
+
type: OPEN_TREE_NODE,
|
|
1348
|
+
vpId: this.serverViewportId,
|
|
1349
|
+
treeKey
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
closeTreeNode(requestId, message) {
|
|
1353
|
+
const treeKey = message.index === void 0 ? message.key : this.getKeyForRowAtIndex(message.index);
|
|
1354
|
+
return {
|
|
1355
|
+
type: CLOSE_TREE_NODE,
|
|
1356
|
+
vpId: this.serverViewportId,
|
|
1357
|
+
treeKey
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1360
|
+
createLink(requestId, vuuCreateVisualLink) {
|
|
1361
|
+
const message = {
|
|
1362
|
+
...vuuCreateVisualLink,
|
|
1363
|
+
childVpId: this.serverViewportId
|
|
1364
|
+
};
|
|
1365
|
+
this.awaitOperation(requestId, message);
|
|
1366
|
+
return message;
|
|
1367
|
+
}
|
|
1368
|
+
removeLink(requestId) {
|
|
1369
|
+
const message = {
|
|
1370
|
+
type: "REMOVE_VISUAL_LINK",
|
|
1371
|
+
childVpId: this.serverViewportId
|
|
1372
|
+
};
|
|
1373
|
+
this.awaitOperation(requestId, message);
|
|
1374
|
+
return message;
|
|
1375
|
+
}
|
|
1376
|
+
suspend() {
|
|
1377
|
+
this.suspended = true;
|
|
1378
|
+
info == null ? void 0 : info("suspend");
|
|
1379
|
+
}
|
|
1380
|
+
resume() {
|
|
1381
|
+
this.suspended = false;
|
|
1382
|
+
if (debugEnabled2) {
|
|
1383
|
+
debug2 == null ? void 0 : debug2(\`resume: \${this.currentData()}\`);
|
|
1384
|
+
}
|
|
1385
|
+
return [this.size, this.currentData()];
|
|
1386
|
+
}
|
|
1387
|
+
currentData() {
|
|
1388
|
+
const out = [];
|
|
1389
|
+
if (this.dataWindow) {
|
|
1390
|
+
const records = this.dataWindow.getData();
|
|
1391
|
+
const { keys } = this;
|
|
1392
|
+
const toClient = this.isTree ? toClientRowTree : toClientRow;
|
|
1393
|
+
for (const row of records) {
|
|
1394
|
+
if (row) {
|
|
1395
|
+
out.push(toClient(row, keys, this.selectedRows));
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
return out;
|
|
1400
|
+
}
|
|
1401
|
+
enable(requestId) {
|
|
1402
|
+
this.awaitOperation(requestId, { type: "enable" });
|
|
1403
|
+
info == null ? void 0 : info(\`enable: \${this.serverViewportId}\`);
|
|
1404
|
+
return {
|
|
1405
|
+
type: ENABLE_VP,
|
|
1406
|
+
viewPortId: this.serverViewportId
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
disable(requestId) {
|
|
1410
|
+
this.awaitOperation(requestId, { type: "disable" });
|
|
1411
|
+
info == null ? void 0 : info(\`disable: \${this.serverViewportId}\`);
|
|
1412
|
+
this.suspended = false;
|
|
1413
|
+
return {
|
|
1414
|
+
type: DISABLE_VP,
|
|
1415
|
+
viewPortId: this.serverViewportId
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
1418
|
+
setConfig(requestId, config) {
|
|
1419
|
+
var _a;
|
|
1420
|
+
this.awaitOperation(requestId, { type: "config", data: config });
|
|
1421
|
+
const { filterSpec: filter, ...remainingConfig } = config;
|
|
1422
|
+
debugEnabled2 ? debug2 == null ? void 0 : debug2(\`setConfig \${JSON.stringify(config)}\`) : info == null ? void 0 : info(\`setConfig\`);
|
|
1423
|
+
if (!this.isTree && config.groupBy.length > 0) {
|
|
1424
|
+
(_a = this.dataWindow) == null ? void 0 : _a.clear();
|
|
1425
|
+
this.lastRowsReturnedToClient[0] = -1;
|
|
1426
|
+
this.lastRowsReturnedToClient[1] = -1;
|
|
1427
|
+
}
|
|
1428
|
+
return this.createRequest(
|
|
1429
|
+
{
|
|
1430
|
+
...remainingConfig,
|
|
1431
|
+
filterSpec: typeof (filter == null ? void 0 : filter.filter) === "string" ? {
|
|
1432
|
+
filter: filter.filter
|
|
1433
|
+
} : {
|
|
1434
|
+
filter: ""
|
|
1435
|
+
}
|
|
1436
|
+
},
|
|
1437
|
+
true
|
|
1438
|
+
);
|
|
1439
|
+
}
|
|
1440
|
+
selectRequest(requestId, selected) {
|
|
1441
|
+
this.selectedRows = selected;
|
|
1442
|
+
this.awaitOperation(requestId, { type: "selection", data: selected });
|
|
1443
|
+
info == null ? void 0 : info(\`selectRequest: \${selected}\`);
|
|
1444
|
+
return {
|
|
1445
|
+
type: "SET_SELECTION",
|
|
1446
|
+
vpId: this.serverViewportId,
|
|
1447
|
+
selection: expandSelection(selected)
|
|
1448
|
+
};
|
|
1449
|
+
}
|
|
1450
|
+
removePendingRangeRequest(firstIndex, lastIndex) {
|
|
1451
|
+
for (let i = this.pendingRangeRequests.length - 1; i >= 0; i--) {
|
|
1452
|
+
const { from, to } = this.pendingRangeRequests[i];
|
|
1453
|
+
let isLast = true;
|
|
1454
|
+
if (firstIndex >= from && firstIndex < to || lastIndex > from && lastIndex < to) {
|
|
1455
|
+
if (!isLast) {
|
|
1456
|
+
console.warn(
|
|
1457
|
+
"removePendingRangeRequest TABLE_ROWS are not for latest request"
|
|
1458
|
+
);
|
|
1459
|
+
}
|
|
1460
|
+
this.pendingRangeRequests.splice(i, 1);
|
|
1461
|
+
break;
|
|
1462
|
+
} else {
|
|
1463
|
+
isLast = false;
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
updateRows(rows) {
|
|
1468
|
+
var _a, _b, _c;
|
|
1469
|
+
const [firstRow, lastRow] = getFirstAndLastRows(rows);
|
|
1470
|
+
if (firstRow && lastRow) {
|
|
1471
|
+
this.removePendingRangeRequest(firstRow.rowIndex, lastRow.rowIndex);
|
|
1472
|
+
}
|
|
1473
|
+
if (rows.length === 1) {
|
|
1474
|
+
if (firstRow.vpSize === 0 && this.disabled) {
|
|
1475
|
+
debug2 == null ? void 0 : debug2(
|
|
1476
|
+
\`ignore a SIZE=0 message on disabled viewport (\${rows.length} rows)\`
|
|
1477
|
+
);
|
|
1478
|
+
return;
|
|
1479
|
+
} else if (firstRow.updateType === "SIZE") {
|
|
1480
|
+
this.setLastSizeOnlyUpdateSize(firstRow.vpSize);
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
for (const row of rows) {
|
|
1484
|
+
if (this.isTree && isLeafUpdate(row)) {
|
|
1485
|
+
continue;
|
|
1486
|
+
} else {
|
|
1487
|
+
if (row.updateType === "SIZE" || ((_a = this.dataWindow) == null ? void 0 : _a.rowCount) !== row.vpSize) {
|
|
1488
|
+
(_b = this.dataWindow) == null ? void 0 : _b.setRowCount(row.vpSize);
|
|
1489
|
+
this.rowCountChanged = true;
|
|
1490
|
+
}
|
|
1491
|
+
if (row.updateType === "U") {
|
|
1492
|
+
if ((_c = this.dataWindow) == null ? void 0 : _c.setAtIndex(row)) {
|
|
1493
|
+
this.hasUpdates = true;
|
|
1494
|
+
if (!this.batchMode) {
|
|
1495
|
+
this.pendingUpdates.push(row);
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
getKeyForRowAtIndex(rowIndex) {
|
|
1503
|
+
const row = this.dataWindow.getAtIndex(rowIndex);
|
|
1504
|
+
return row == null ? void 0 : row.rowKey;
|
|
1505
|
+
}
|
|
1506
|
+
// This is called only after new data has been received from server - data
|
|
1507
|
+
// returned direcly from buffer does not use this.
|
|
1508
|
+
getClientRows() {
|
|
1509
|
+
var _a, _b, _c, _d;
|
|
1510
|
+
let out = void 0;
|
|
1511
|
+
let mode = "size-only";
|
|
1512
|
+
if (!this.hasUpdates && !this.rowCountChanged) {
|
|
1513
|
+
return NO_DATA_UPDATE;
|
|
1514
|
+
}
|
|
1515
|
+
if (this.hasUpdates) {
|
|
1516
|
+
const { keys, selectedRows } = this;
|
|
1517
|
+
const toClient = this.isTree ? toClientRowTree : toClientRow;
|
|
1518
|
+
if (this.updateThrottleTimer) {
|
|
1519
|
+
self.clearTimeout(this.updateThrottleTimer);
|
|
1520
|
+
this.updateThrottleTimer = void 0;
|
|
1521
|
+
}
|
|
1522
|
+
if (this.pendingUpdates.length > 0 && this.dataWindow.hasAllRowsWithinRange) {
|
|
1523
|
+
out = [];
|
|
1524
|
+
mode = "update";
|
|
1525
|
+
const missingRows = gapBetweenLastRowSentToClient(
|
|
1526
|
+
this.lastRowsReturnedToClient,
|
|
1527
|
+
this.pendingUpdates,
|
|
1528
|
+
this.dataWindow.clientRange
|
|
1529
|
+
);
|
|
1530
|
+
if (missingRows) {
|
|
1531
|
+
for (let i = missingRows.from; i < missingRows.to; i++) {
|
|
1532
|
+
const row = this.dataWindow.getAtIndex(i);
|
|
1533
|
+
if (row) {
|
|
1534
|
+
out.push(toClient(row, keys, selectedRows));
|
|
1535
|
+
} else {
|
|
1536
|
+
throw Error("[Viewport] missing row not in data cache");
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
for (const row of this.pendingUpdates) {
|
|
1540
|
+
out.push(toClient(row, keys, selectedRows));
|
|
1541
|
+
}
|
|
1542
|
+
out.sort(
|
|
1543
|
+
([idx1], [idx2]) => idx1 - idx2
|
|
1544
|
+
);
|
|
1545
|
+
} else {
|
|
1546
|
+
for (const row of this.pendingUpdates) {
|
|
1547
|
+
out.push(toClient(row, keys, selectedRows));
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
this.lastRowsReturnedToClient[0] = (_b = (_a = out.at(0)) == null ? void 0 : _a[0]) != null ? _b : -1;
|
|
1551
|
+
this.lastRowsReturnedToClient[1] = (_d = (_c = out.at(-1)) == null ? void 0 : _c[0]) != null ? _d : -1;
|
|
1552
|
+
}
|
|
1553
|
+
this.pendingUpdates.length = 0;
|
|
1554
|
+
this.hasUpdates = false;
|
|
1555
|
+
}
|
|
1556
|
+
if (this.throttleMessage(mode)) {
|
|
1557
|
+
return NO_DATA_UPDATE;
|
|
1558
|
+
} else {
|
|
1559
|
+
return [out, mode];
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
createRequest(params, overWrite = false) {
|
|
1563
|
+
if (overWrite) {
|
|
1564
|
+
return {
|
|
1565
|
+
type: "CHANGE_VP",
|
|
1566
|
+
viewPortId: this.serverViewportId,
|
|
1567
|
+
...params
|
|
1568
|
+
};
|
|
1569
|
+
} else {
|
|
1570
|
+
return {
|
|
1571
|
+
type: "CHANGE_VP",
|
|
1572
|
+
viewPortId: this.serverViewportId,
|
|
1573
|
+
aggregations: this.aggregations,
|
|
1574
|
+
columns: this.columns,
|
|
1575
|
+
sort: this.sort,
|
|
1576
|
+
groupBy: this.groupBy,
|
|
1577
|
+
filterSpec: {
|
|
1578
|
+
filter: this.filter.filter
|
|
1579
|
+
},
|
|
1580
|
+
...params
|
|
1581
|
+
};
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1585
|
+
_status = new WeakMap();
|
|
1586
|
+
_clientRange = new WeakMap();
|
|
1587
|
+
var toClientRow = ({ rowIndex, rowKey, sel: isSelected, data }, keys, selectedRows) => {
|
|
1588
|
+
return [
|
|
1589
|
+
rowIndex,
|
|
1590
|
+
keys.keyFor(rowIndex),
|
|
1591
|
+
true,
|
|
1592
|
+
false,
|
|
1593
|
+
0,
|
|
1594
|
+
0,
|
|
1595
|
+
rowKey,
|
|
1596
|
+
isSelected ? getSelectionStatus(selectedRows, rowIndex) : 0
|
|
1597
|
+
].concat(data);
|
|
1598
|
+
};
|
|
1599
|
+
var toClientRowTree = ({ rowIndex, rowKey, sel: isSelected, data }, keys, selectedRows) => {
|
|
1600
|
+
const [depth, isExpanded, , isLeaf, , count, ...rest] = data;
|
|
1601
|
+
return [
|
|
1602
|
+
rowIndex,
|
|
1603
|
+
keys.keyFor(rowIndex),
|
|
1604
|
+
isLeaf,
|
|
1605
|
+
isExpanded,
|
|
1606
|
+
depth,
|
|
1607
|
+
count,
|
|
1608
|
+
rowKey,
|
|
1609
|
+
isSelected ? getSelectionStatus(selectedRows, rowIndex) : 0
|
|
1610
|
+
].concat(rest);
|
|
1611
|
+
};
|
|
1612
|
+
|
|
1613
|
+
// src/server-proxy/server-proxy.ts
|
|
1614
|
+
var _requestId = 1;
|
|
1615
|
+
var { debug: debug3, debugEnabled: debugEnabled3, error: error2, info: info2, infoEnabled: infoEnabled2, warn: warn2 } = logger("ServerProxy");
|
|
1616
|
+
var nextRequestId = () => \`\${_requestId++}\`;
|
|
1617
|
+
var DEFAULT_OPTIONS = {};
|
|
1618
|
+
var isActiveViewport = (viewPort) => viewPort.disabled !== true && viewPort.suspended !== true;
|
|
1619
|
+
var addTitleToLinks = (links, serverViewportId, label) => links.map(
|
|
1620
|
+
(link) => link.parentVpId === serverViewportId ? { ...link, label } : link
|
|
1621
|
+
);
|
|
1622
|
+
function addLabelsToLinks(links, viewports) {
|
|
1623
|
+
return links.map((linkDescriptor) => {
|
|
1624
|
+
const { parentVpId } = linkDescriptor;
|
|
1625
|
+
const viewport = viewports.get(parentVpId);
|
|
1626
|
+
if (viewport) {
|
|
1627
|
+
return {
|
|
1628
|
+
...linkDescriptor,
|
|
1629
|
+
parentClientVpId: viewport.clientViewportId,
|
|
1630
|
+
label: viewport.title
|
|
1631
|
+
};
|
|
1632
|
+
} else {
|
|
1633
|
+
throw Error("addLabelsToLinks viewport not found");
|
|
1634
|
+
}
|
|
1635
|
+
});
|
|
1636
|
+
}
|
|
1637
|
+
var ServerProxy = class {
|
|
1638
|
+
constructor(connection, callback) {
|
|
1639
|
+
__publicField(this, "connection");
|
|
1640
|
+
__publicField(this, "postMessageToClient");
|
|
1641
|
+
__publicField(this, "viewports");
|
|
1642
|
+
__publicField(this, "mapClientToServerViewport");
|
|
1643
|
+
__publicField(this, "authToken", "");
|
|
1644
|
+
__publicField(this, "user", "user");
|
|
1645
|
+
__publicField(this, "pendingLogin");
|
|
1646
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1647
|
+
__publicField(this, "pendingRequests", /* @__PURE__ */ new Map());
|
|
1648
|
+
__publicField(this, "sessionId");
|
|
1649
|
+
__publicField(this, "queuedRequests", []);
|
|
1650
|
+
__publicField(this, "cachedTableMetaRequests", /* @__PURE__ */ new Map());
|
|
1651
|
+
__publicField(this, "cachedTableSchemas", /* @__PURE__ */ new Map());
|
|
1652
|
+
__publicField(this, "tableList");
|
|
1653
|
+
__publicField(this, "reconnect", async () => {
|
|
1654
|
+
await this.login(this.authToken);
|
|
1655
|
+
const [activeViewports, inactiveViewports] = partition(
|
|
1656
|
+
Array.from(this.viewports.values()),
|
|
1657
|
+
isActiveViewport
|
|
1658
|
+
);
|
|
1659
|
+
this.viewports.clear();
|
|
1660
|
+
this.mapClientToServerViewport.clear();
|
|
1661
|
+
const reconnectViewports = (viewports) => {
|
|
1662
|
+
viewports.forEach((viewport) => {
|
|
1663
|
+
const { clientViewportId } = viewport;
|
|
1664
|
+
this.awaitResponseToMessage(
|
|
1665
|
+
viewport.subscribe(),
|
|
1666
|
+
clientViewportId
|
|
1667
|
+
).then((msg) => {
|
|
1668
|
+
if (msg.type === "CREATE_VP_SUCCESS") {
|
|
1669
|
+
this.mapClientToServerViewport.set(
|
|
1670
|
+
clientViewportId,
|
|
1671
|
+
msg.viewPortId
|
|
1672
|
+
);
|
|
1673
|
+
this.viewports.set(msg.viewPortId, viewport);
|
|
1674
|
+
viewport.status = "subscribed";
|
|
1675
|
+
viewport.serverViewportId = msg.viewPortId;
|
|
1676
|
+
}
|
|
1677
|
+
});
|
|
1678
|
+
});
|
|
1679
|
+
};
|
|
1680
|
+
reconnectViewports(activeViewports);
|
|
1681
|
+
setTimeout(() => {
|
|
1682
|
+
reconnectViewports(inactiveViewports);
|
|
1683
|
+
}, 2e3);
|
|
1684
|
+
});
|
|
1685
|
+
this.connection = connection;
|
|
1686
|
+
this.postMessageToClient = callback;
|
|
1687
|
+
this.viewports = /* @__PURE__ */ new Map();
|
|
1688
|
+
this.mapClientToServerViewport = /* @__PURE__ */ new Map();
|
|
1689
|
+
connection.on("reconnected", this.reconnect);
|
|
1690
|
+
}
|
|
1691
|
+
async login(authToken, user = "user") {
|
|
1692
|
+
if (authToken) {
|
|
1693
|
+
this.authToken = authToken;
|
|
1694
|
+
this.user = user;
|
|
1695
|
+
return new Promise((resolve, reject) => {
|
|
1696
|
+
this.sendMessageToServer(
|
|
1697
|
+
{ type: LOGIN, token: this.authToken, user },
|
|
1698
|
+
""
|
|
1699
|
+
);
|
|
1700
|
+
this.pendingLogin = { resolve, reject };
|
|
1701
|
+
});
|
|
1702
|
+
} else if (this.authToken === "") {
|
|
1703
|
+
error2("login, cannot login until auth token has been obtained");
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
disconnect() {
|
|
1707
|
+
this.viewports.forEach((viewport) => {
|
|
1708
|
+
const { clientViewportId } = viewport;
|
|
1709
|
+
this.unsubscribe(clientViewportId);
|
|
1710
|
+
this.postMessageToClient({
|
|
1711
|
+
clientViewportId,
|
|
1712
|
+
type: "viewport-clear"
|
|
1713
|
+
});
|
|
1714
|
+
});
|
|
1715
|
+
}
|
|
1716
|
+
subscribe(message) {
|
|
1717
|
+
if (!this.mapClientToServerViewport.has(message.viewport)) {
|
|
1718
|
+
const pendingTableSchema = this.getTableMeta(message.table);
|
|
1719
|
+
const viewport = new Viewport(message, this.postMessageToClient);
|
|
1720
|
+
this.viewports.set(message.viewport, viewport);
|
|
1721
|
+
const pendingSubscription = this.awaitResponseToMessage(
|
|
1722
|
+
viewport.subscribe(),
|
|
1723
|
+
message.viewport
|
|
1724
|
+
);
|
|
1725
|
+
const pendingResponses = [pendingSubscription, pendingTableSchema];
|
|
1726
|
+
const awaitPendingReponses = Promise.all(pendingResponses);
|
|
1727
|
+
awaitPendingReponses.then(([subscribeResponse, tableSchema]) => {
|
|
1728
|
+
const { viewPortId: serverViewportId } = subscribeResponse;
|
|
1729
|
+
const { status: previousViewportStatus } = viewport;
|
|
1730
|
+
if (message.viewport !== serverViewportId) {
|
|
1731
|
+
this.viewports.delete(message.viewport);
|
|
1732
|
+
this.viewports.set(serverViewportId, viewport);
|
|
1733
|
+
}
|
|
1734
|
+
this.mapClientToServerViewport.set(message.viewport, serverViewportId);
|
|
1735
|
+
const clientResponse = viewport.handleSubscribed(
|
|
1736
|
+
subscribeResponse,
|
|
1737
|
+
tableSchema
|
|
1738
|
+
);
|
|
1739
|
+
if (clientResponse) {
|
|
1740
|
+
this.postMessageToClient(clientResponse);
|
|
1741
|
+
if (debugEnabled3) {
|
|
1742
|
+
debug3(
|
|
1743
|
+
\`post DataSourceSubscribedMessage to client: \${JSON.stringify(
|
|
1744
|
+
clientResponse
|
|
1745
|
+
)}\`
|
|
1746
|
+
);
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
if (message.selectedIndexValues) {
|
|
1750
|
+
infoEnabled2 && info2(\`selected = \${JSON.stringify(message.selectedIndexValues)}\`);
|
|
1751
|
+
this.select(viewport, { selected: message.selectedIndexValues });
|
|
1752
|
+
}
|
|
1753
|
+
if (viewport.disabled) {
|
|
1754
|
+
this.disableViewport(viewport);
|
|
1755
|
+
}
|
|
1756
|
+
if (this.queuedRequests.length > 0) {
|
|
1757
|
+
this.processQueuedRequests();
|
|
1758
|
+
}
|
|
1759
|
+
if (previousViewportStatus === "subscribing" && // A session table will never have Visual Links, nor Context Menus
|
|
1760
|
+
!isSessionTable(viewport.table)) {
|
|
1761
|
+
this.sendMessageToServer({
|
|
1762
|
+
type: GET_VP_VISUAL_LINKS,
|
|
1763
|
+
vpId: serverViewportId
|
|
1764
|
+
});
|
|
1765
|
+
this.sendMessageToServer({
|
|
1766
|
+
type: GET_VIEW_PORT_MENUS,
|
|
1767
|
+
vpId: serverViewportId
|
|
1768
|
+
});
|
|
1769
|
+
Array.from(this.viewports.entries()).filter(
|
|
1770
|
+
([id, { disabled, status }]) => id !== serverViewportId && !disabled && status === "subscribed"
|
|
1771
|
+
).forEach(([vpId]) => {
|
|
1772
|
+
this.sendMessageToServer({
|
|
1773
|
+
type: GET_VP_VISUAL_LINKS,
|
|
1774
|
+
vpId
|
|
1775
|
+
});
|
|
1776
|
+
});
|
|
1777
|
+
}
|
|
1778
|
+
});
|
|
1779
|
+
} else {
|
|
1780
|
+
error2(\`spurious subscribe call \${message.viewport}\`);
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
/**
|
|
1784
|
+
* Currently we only queue range requests, this may change
|
|
1785
|
+
*/
|
|
1786
|
+
addRequestToQueue(queuedRequest) {
|
|
1787
|
+
const isDifferentTypeViewport = (qr) => qr.clientViewportId !== queuedRequest.clientViewportId || queuedRequest.message.type !== qr.message.type;
|
|
1788
|
+
if (!this.queuedRequests.every(isDifferentTypeViewport)) {
|
|
1789
|
+
this.queuedRequests = this.queuedRequests.filter(isDifferentTypeViewport);
|
|
1790
|
+
}
|
|
1791
|
+
this.queuedRequests.push(queuedRequest);
|
|
1792
|
+
}
|
|
1793
|
+
processQueuedRequests() {
|
|
1794
|
+
const newQueue = [];
|
|
1795
|
+
for (const queuedRequest of this.queuedRequests) {
|
|
1796
|
+
const { clientViewportId, message, requestId } = queuedRequest;
|
|
1797
|
+
const serverViewportId = this.mapClientToServerViewport.get(clientViewportId);
|
|
1798
|
+
if (serverViewportId) {
|
|
1799
|
+
this.sendMessageToServer(
|
|
1800
|
+
{
|
|
1801
|
+
...message,
|
|
1802
|
+
viewPortId: serverViewportId
|
|
1803
|
+
},
|
|
1804
|
+
requestId
|
|
1805
|
+
);
|
|
1806
|
+
} else if (this.viewports.has(clientViewportId)) {
|
|
1807
|
+
newQueue.push(queuedRequest);
|
|
1808
|
+
} else {
|
|
1809
|
+
console.warn(
|
|
1810
|
+
\`ServerProxy processQueuedRequests, \${message.type} request not found \${clientViewportId}\`
|
|
1811
|
+
);
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
this.queuedRequests = newQueue;
|
|
1815
|
+
}
|
|
1816
|
+
unsubscribe(clientViewportId) {
|
|
1817
|
+
const serverViewportId = this.mapClientToServerViewport.get(clientViewportId);
|
|
1818
|
+
if (serverViewportId) {
|
|
1819
|
+
info2 == null ? void 0 : info2(
|
|
1820
|
+
\`Unsubscribe Message (Client to Server):
|
|
1821
|
+
\${serverViewportId}\`
|
|
1822
|
+
);
|
|
1823
|
+
this.sendMessageToServer({
|
|
1824
|
+
type: REMOVE_VP,
|
|
1825
|
+
viewPortId: serverViewportId
|
|
1826
|
+
});
|
|
1827
|
+
} else {
|
|
1828
|
+
error2(
|
|
1829
|
+
\`failed to unsubscribe client viewport \${clientViewportId}, viewport not found\`
|
|
1830
|
+
);
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
getViewportForClient(clientViewportId, throws = true) {
|
|
1834
|
+
const serverViewportId = this.mapClientToServerViewport.get(clientViewportId);
|
|
1835
|
+
if (serverViewportId) {
|
|
1836
|
+
const viewport = this.viewports.get(serverViewportId);
|
|
1837
|
+
if (viewport) {
|
|
1838
|
+
return viewport;
|
|
1839
|
+
} else if (throws) {
|
|
1840
|
+
throw Error(
|
|
1841
|
+
\`Viewport not found for client viewport \${clientViewportId}\`
|
|
1842
|
+
);
|
|
1843
|
+
} else {
|
|
1844
|
+
return null;
|
|
1845
|
+
}
|
|
1846
|
+
} else if (this.viewports.has(clientViewportId)) {
|
|
1847
|
+
return this.viewports.get(clientViewportId);
|
|
1848
|
+
} else if (throws) {
|
|
1849
|
+
throw Error(
|
|
1850
|
+
\`Viewport server id not found for client viewport \${clientViewportId}\`
|
|
1851
|
+
);
|
|
1852
|
+
} else {
|
|
1853
|
+
return null;
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
/**********************************************************************/
|
|
1857
|
+
/* Handle messages from client */
|
|
1858
|
+
/**********************************************************************/
|
|
1859
|
+
setViewRange(viewport, message) {
|
|
1860
|
+
const requestId = nextRequestId();
|
|
1861
|
+
infoEnabled2 && info2(\`setViewRange (\${message.range.from}:\${message.range.to})\`);
|
|
1862
|
+
const [serverRequest, rows, debounceRequest] = viewport.rangeRequest(
|
|
1863
|
+
requestId,
|
|
1864
|
+
message.range
|
|
1865
|
+
);
|
|
1866
|
+
if (viewport.status === "subscribed") {
|
|
1867
|
+
info2 == null ? void 0 : info2(\`setViewRange \${message.range.from} - \${message.range.to}\`);
|
|
1868
|
+
if (serverRequest) {
|
|
1869
|
+
if (true) {
|
|
1870
|
+
info2 == null ? void 0 : info2(
|
|
1871
|
+
\`CHANGE_VP_RANGE (\${message.range.from}-\${message.range.to}) => (\${serverRequest.from}-\${serverRequest.to})\`
|
|
1872
|
+
);
|
|
1873
|
+
}
|
|
1874
|
+
infoEnabled2 && info2(
|
|
1875
|
+
\`setViewRange send CHANGE_VP_RANGE<#\${requestId}> (\${serverRequest.from}-\${serverRequest.to})\`
|
|
1876
|
+
);
|
|
1877
|
+
this.sendMessageToServer(serverRequest, requestId);
|
|
1878
|
+
}
|
|
1879
|
+
if (rows) {
|
|
1880
|
+
info2 == null ? void 0 : info2(\`setViewRange \${rows.length} rows returned from cache\`);
|
|
1881
|
+
this.postMessageToClient({
|
|
1882
|
+
mode: "update",
|
|
1883
|
+
type: "viewport-update",
|
|
1884
|
+
clientViewportId: viewport.clientViewportId,
|
|
1885
|
+
range: message.range,
|
|
1886
|
+
rows
|
|
1887
|
+
});
|
|
1888
|
+
} else if (debounceRequest) {
|
|
1889
|
+
this.postMessageToClient(debounceRequest);
|
|
1890
|
+
}
|
|
1891
|
+
} else if (serverRequest) {
|
|
1892
|
+
this.addRequestToQueue({
|
|
1893
|
+
clientViewportId: message.viewport,
|
|
1894
|
+
message: serverRequest,
|
|
1895
|
+
requestId
|
|
1896
|
+
});
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
// TODO check config has actually changed
|
|
1900
|
+
setConfig(viewport, message) {
|
|
1901
|
+
const requestId = nextRequestId();
|
|
1902
|
+
const request = viewport.setConfig(requestId, message.config);
|
|
1903
|
+
this.sendIfReady(request, requestId, viewport.status === "subscribed");
|
|
1904
|
+
}
|
|
1905
|
+
setTitle(viewport, message) {
|
|
1906
|
+
if (viewport) {
|
|
1907
|
+
viewport.title = message.title;
|
|
1908
|
+
this.updateTitleOnVisualLinks(viewport);
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
select(viewport, message) {
|
|
1912
|
+
const requestId = nextRequestId();
|
|
1913
|
+
const { selected } = message;
|
|
1914
|
+
const request = viewport.selectRequest(requestId, selected);
|
|
1915
|
+
this.sendIfReady(request, requestId, viewport.status === "subscribed");
|
|
1916
|
+
}
|
|
1917
|
+
disableViewport(viewport) {
|
|
1918
|
+
const requestId = nextRequestId();
|
|
1919
|
+
const request = viewport.disable(requestId);
|
|
1920
|
+
this.sendIfReady(request, requestId, viewport.status === "subscribed");
|
|
1921
|
+
}
|
|
1922
|
+
enableViewport(viewport) {
|
|
1923
|
+
if (viewport.disabled) {
|
|
1924
|
+
const requestId = nextRequestId();
|
|
1925
|
+
const request = viewport.enable(requestId);
|
|
1926
|
+
this.sendIfReady(request, requestId, viewport.status === "subscribed");
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
suspendViewport(viewport) {
|
|
1930
|
+
viewport.suspend();
|
|
1931
|
+
viewport.suspendTimer = setTimeout(() => {
|
|
1932
|
+
info2 == null ? void 0 : info2("suspendTimer expired, escalate suspend to disable");
|
|
1933
|
+
this.disableViewport(viewport);
|
|
1934
|
+
}, 3e3);
|
|
1935
|
+
}
|
|
1936
|
+
resumeViewport(viewport) {
|
|
1937
|
+
if (viewport.suspendTimer) {
|
|
1938
|
+
debug3 == null ? void 0 : debug3("clear suspend timer");
|
|
1939
|
+
clearTimeout(viewport.suspendTimer);
|
|
1940
|
+
viewport.suspendTimer = null;
|
|
1941
|
+
}
|
|
1942
|
+
const [size, rows] = viewport.resume();
|
|
1943
|
+
debug3 == null ? void 0 : debug3(\`resumeViewport size \${size}, \${rows.length} rows sent to client\`);
|
|
1944
|
+
this.postMessageToClient({
|
|
1945
|
+
clientViewportId: viewport.clientViewportId,
|
|
1946
|
+
mode: "update",
|
|
1947
|
+
rows,
|
|
1948
|
+
size,
|
|
1949
|
+
type: "viewport-update"
|
|
1950
|
+
});
|
|
1951
|
+
}
|
|
1952
|
+
openTreeNode(viewport, message) {
|
|
1953
|
+
if (viewport.serverViewportId) {
|
|
1954
|
+
const requestId = nextRequestId();
|
|
1955
|
+
this.sendIfReady(
|
|
1956
|
+
viewport.openTreeNode(requestId, message),
|
|
1957
|
+
requestId,
|
|
1958
|
+
viewport.status === "subscribed"
|
|
1959
|
+
);
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
closeTreeNode(viewport, message) {
|
|
1963
|
+
if (viewport.serverViewportId) {
|
|
1964
|
+
const requestId = nextRequestId();
|
|
1965
|
+
this.sendIfReady(
|
|
1966
|
+
viewport.closeTreeNode(requestId, message),
|
|
1967
|
+
requestId,
|
|
1968
|
+
viewport.status === "subscribed"
|
|
1969
|
+
);
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
createLink(viewport, message) {
|
|
1973
|
+
const [requestId, visualLinkRequest] = stripRequestId(message);
|
|
1974
|
+
const parentVpId = this.mapClientToServerViewport.get(message.parentVpId);
|
|
1975
|
+
if (parentVpId) {
|
|
1976
|
+
const request = viewport.createLink(requestId, {
|
|
1977
|
+
...visualLinkRequest,
|
|
1978
|
+
parentVpId
|
|
1979
|
+
});
|
|
1980
|
+
this.sendMessageToServer(request, requestId);
|
|
1981
|
+
} else {
|
|
1982
|
+
throw Error(\`createLink parent viewport not found \${message.parentVpId}\`);
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
removeLink(viewport, message) {
|
|
1986
|
+
const { requestId } = message;
|
|
1987
|
+
const request = viewport.removeLink(requestId);
|
|
1988
|
+
this.sendMessageToServer(request, requestId);
|
|
1989
|
+
}
|
|
1990
|
+
updateTitleOnVisualLinks(viewport) {
|
|
1991
|
+
var _a;
|
|
1992
|
+
const { serverViewportId, title } = viewport;
|
|
1993
|
+
for (const vp of this.viewports.values()) {
|
|
1994
|
+
if (vp !== viewport && vp.links && serverViewportId && title) {
|
|
1995
|
+
if ((_a = vp.links) == null ? void 0 : _a.some((link) => link.parentVpId === serverViewportId)) {
|
|
1996
|
+
const [messageToClient] = vp.setLinks(
|
|
1997
|
+
addTitleToLinks(vp.links, serverViewportId, title)
|
|
1998
|
+
);
|
|
1999
|
+
this.postMessageToClient(messageToClient);
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
removeViewportFromVisualLinks(serverViewportId) {
|
|
2005
|
+
var _a;
|
|
2006
|
+
for (const vp of this.viewports.values()) {
|
|
2007
|
+
if ((_a = vp.links) == null ? void 0 : _a.some(({ parentVpId }) => parentVpId === serverViewportId)) {
|
|
2008
|
+
const [messageToClient] = vp.setLinks(
|
|
2009
|
+
vp.links.filter(({ parentVpId }) => parentVpId !== serverViewportId)
|
|
2010
|
+
);
|
|
2011
|
+
this.postMessageToClient(messageToClient);
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
menuRpcCall(message) {
|
|
2016
|
+
const viewport = this.getViewportForClient(message.vpId, false);
|
|
2017
|
+
if (viewport == null ? void 0 : viewport.serverViewportId) {
|
|
2018
|
+
const [requestId, rpcRequest] = stripRequestId(message);
|
|
2019
|
+
this.sendMessageToServer(
|
|
2020
|
+
{
|
|
2021
|
+
...rpcRequest,
|
|
2022
|
+
vpId: viewport.serverViewportId
|
|
2023
|
+
},
|
|
2024
|
+
requestId
|
|
2025
|
+
);
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
viewportRpcCall(message) {
|
|
2029
|
+
const viewport = this.getViewportForClient(message.vpId, false);
|
|
2030
|
+
if (viewport == null ? void 0 : viewport.serverViewportId) {
|
|
2031
|
+
const [requestId, { namedParams = {}, ...rpcRequest }] = stripRequestId(message);
|
|
2032
|
+
this.sendMessageToServer(
|
|
2033
|
+
{
|
|
2034
|
+
...rpcRequest,
|
|
2035
|
+
namedParams,
|
|
2036
|
+
vpId: viewport.serverViewportId
|
|
2037
|
+
},
|
|
2038
|
+
requestId
|
|
2039
|
+
);
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
rpcCall(message) {
|
|
2043
|
+
const [requestId, rpcRequest] = stripRequestId(message);
|
|
2044
|
+
const module = getRpcServiceModule(rpcRequest.service);
|
|
2045
|
+
this.sendMessageToServer(rpcRequest, requestId, { module });
|
|
2046
|
+
}
|
|
2047
|
+
handleMessageFromClient(message) {
|
|
2048
|
+
var _a;
|
|
2049
|
+
if (isViewportMessage(message) || isVisualLinkMessage(message)) {
|
|
2050
|
+
if (message.type === "disable") {
|
|
2051
|
+
const viewport = this.getViewportForClient(message.viewport, false);
|
|
2052
|
+
if (viewport !== null) {
|
|
2053
|
+
return this.disableViewport(viewport);
|
|
2054
|
+
} else {
|
|
2055
|
+
return;
|
|
2056
|
+
}
|
|
2057
|
+
} else {
|
|
2058
|
+
const viewport = isVisualLinkMessage(message) ? this.getViewportForClient(message.childVpId) : this.getViewportForClient(message.viewport);
|
|
2059
|
+
switch (message.type) {
|
|
2060
|
+
case "setViewRange":
|
|
2061
|
+
return this.setViewRange(viewport, message);
|
|
2062
|
+
case "config":
|
|
2063
|
+
return this.setConfig(viewport, message);
|
|
2064
|
+
case "select":
|
|
2065
|
+
return this.select(viewport, message);
|
|
2066
|
+
case "suspend":
|
|
2067
|
+
return this.suspendViewport(viewport);
|
|
2068
|
+
case "resume":
|
|
2069
|
+
return this.resumeViewport(viewport);
|
|
2070
|
+
case "enable":
|
|
2071
|
+
return this.enableViewport(viewport);
|
|
2072
|
+
case "openTreeNode":
|
|
2073
|
+
return this.openTreeNode(viewport, message);
|
|
2074
|
+
case "closeTreeNode":
|
|
2075
|
+
return this.closeTreeNode(viewport, message);
|
|
2076
|
+
case "CREATE_VISUAL_LINK":
|
|
2077
|
+
return this.createLink(viewport, message);
|
|
2078
|
+
case "REMOVE_VISUAL_LINK":
|
|
2079
|
+
return this.removeLink(viewport, message);
|
|
2080
|
+
case "setTitle":
|
|
2081
|
+
return this.setTitle(viewport, message);
|
|
2082
|
+
default:
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
} else if (isVuuRpcRequest(message)) {
|
|
2086
|
+
return this.viewportRpcCall(
|
|
2087
|
+
message
|
|
2088
|
+
);
|
|
2089
|
+
} else if (isVuuMenuRpcRequest(message)) {
|
|
2090
|
+
return this.menuRpcCall(message);
|
|
2091
|
+
} else if (message.type === "disconnect") {
|
|
2092
|
+
return this.disconnect();
|
|
2093
|
+
} else {
|
|
2094
|
+
const { type, requestId } = message;
|
|
2095
|
+
switch (type) {
|
|
2096
|
+
case "GET_TABLE_LIST": {
|
|
2097
|
+
(_a = this.tableList) != null ? _a : this.tableList = this.awaitResponseToMessage(
|
|
2098
|
+
{ type },
|
|
2099
|
+
requestId
|
|
2100
|
+
);
|
|
2101
|
+
this.tableList.then((response) => {
|
|
2102
|
+
this.postMessageToClient({
|
|
2103
|
+
type: "TABLE_LIST_RESP",
|
|
2104
|
+
tables: response.tables,
|
|
2105
|
+
requestId
|
|
2106
|
+
});
|
|
2107
|
+
});
|
|
2108
|
+
return;
|
|
2109
|
+
}
|
|
2110
|
+
case "GET_TABLE_META": {
|
|
2111
|
+
this.getTableMeta(message.table, requestId).then((tableSchema) => {
|
|
2112
|
+
if (tableSchema) {
|
|
2113
|
+
this.postMessageToClient({
|
|
2114
|
+
type: "TABLE_META_RESP",
|
|
2115
|
+
tableSchema,
|
|
2116
|
+
requestId
|
|
2117
|
+
});
|
|
2118
|
+
}
|
|
2119
|
+
});
|
|
2120
|
+
return;
|
|
2121
|
+
}
|
|
2122
|
+
case "RPC_CALL":
|
|
2123
|
+
return this.rpcCall(message);
|
|
2124
|
+
default:
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2127
|
+
error2(
|
|
2128
|
+
\`Vuu ServerProxy Unexpected message from client \${JSON.stringify(
|
|
2129
|
+
message
|
|
2130
|
+
)}\`
|
|
2131
|
+
);
|
|
2132
|
+
}
|
|
2133
|
+
getTableMeta(table, requestId = nextRequestId()) {
|
|
2134
|
+
if (isSessionTable(table)) {
|
|
2135
|
+
return this.awaitResponseToMessage(
|
|
2136
|
+
{ type: "GET_TABLE_META", table },
|
|
2137
|
+
requestId
|
|
2138
|
+
).then(createSchemaFromTableMetadata);
|
|
2139
|
+
}
|
|
2140
|
+
const key = \`\${table.module}:\${table.table}\`;
|
|
2141
|
+
let tableMetaRequest = this.cachedTableMetaRequests.get(key);
|
|
2142
|
+
if (!tableMetaRequest) {
|
|
2143
|
+
tableMetaRequest = this.awaitResponseToMessage(
|
|
2144
|
+
{ type: "GET_TABLE_META", table },
|
|
2145
|
+
requestId
|
|
2146
|
+
);
|
|
2147
|
+
this.cachedTableMetaRequests.set(key, tableMetaRequest);
|
|
2148
|
+
}
|
|
2149
|
+
return tableMetaRequest == null ? void 0 : tableMetaRequest.then((response) => this.cacheTableMeta(response));
|
|
2150
|
+
}
|
|
2151
|
+
awaitResponseToMessage(message, requestId = nextRequestId()) {
|
|
2152
|
+
return new Promise((resolve, reject) => {
|
|
2153
|
+
this.sendMessageToServer(message, requestId);
|
|
2154
|
+
this.pendingRequests.set(requestId, { reject, resolve });
|
|
2155
|
+
});
|
|
2156
|
+
}
|
|
2157
|
+
sendIfReady(message, requestId, isReady = true) {
|
|
2158
|
+
if (isReady) {
|
|
2159
|
+
this.sendMessageToServer(message, requestId);
|
|
2160
|
+
}
|
|
2161
|
+
return isReady;
|
|
2162
|
+
}
|
|
2163
|
+
sendMessageToServer(body, requestId = \`\${_requestId++}\`, options = DEFAULT_OPTIONS) {
|
|
2164
|
+
const { module = "CORE" } = options;
|
|
2165
|
+
if (this.authToken) {
|
|
2166
|
+
this.connection.send({
|
|
2167
|
+
requestId,
|
|
2168
|
+
sessionId: this.sessionId,
|
|
2169
|
+
token: this.authToken,
|
|
2170
|
+
user: this.user,
|
|
2171
|
+
module,
|
|
2172
|
+
body
|
|
2173
|
+
});
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
handleMessageFromServer(message) {
|
|
2177
|
+
var _a, _b, _c;
|
|
2178
|
+
const { body, requestId, sessionId } = message;
|
|
2179
|
+
const pendingRequest = this.pendingRequests.get(requestId);
|
|
2180
|
+
if (pendingRequest) {
|
|
2181
|
+
const { resolve } = pendingRequest;
|
|
2182
|
+
this.pendingRequests.delete(requestId);
|
|
2183
|
+
resolve(body);
|
|
2184
|
+
return;
|
|
2185
|
+
}
|
|
2186
|
+
const { viewports } = this;
|
|
2187
|
+
switch (body.type) {
|
|
2188
|
+
case HB:
|
|
2189
|
+
this.sendMessageToServer(
|
|
2190
|
+
{ type: HB_RESP, ts: +/* @__PURE__ */ new Date() },
|
|
2191
|
+
"NA"
|
|
2192
|
+
);
|
|
2193
|
+
break;
|
|
2194
|
+
case "LOGIN_SUCCESS":
|
|
2195
|
+
if (sessionId) {
|
|
2196
|
+
this.sessionId = sessionId;
|
|
2197
|
+
(_a = this.pendingLogin) == null ? void 0 : _a.resolve(sessionId);
|
|
2198
|
+
this.pendingLogin = void 0;
|
|
2199
|
+
} else {
|
|
2200
|
+
throw Error("LOGIN_SUCCESS did not provide sessionId");
|
|
2201
|
+
}
|
|
2202
|
+
break;
|
|
2203
|
+
// TODO login rejected
|
|
2204
|
+
case "REMOVE_VP_SUCCESS":
|
|
2205
|
+
{
|
|
2206
|
+
const viewport = viewports.get(body.viewPortId);
|
|
2207
|
+
if (viewport) {
|
|
2208
|
+
this.mapClientToServerViewport.delete(viewport.clientViewportId);
|
|
2209
|
+
viewports.delete(body.viewPortId);
|
|
2210
|
+
this.removeViewportFromVisualLinks(body.viewPortId);
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
break;
|
|
2214
|
+
case SET_SELECTION_SUCCESS:
|
|
2215
|
+
{
|
|
2216
|
+
const viewport = this.viewports.get(body.vpId);
|
|
2217
|
+
if (viewport) {
|
|
2218
|
+
viewport.completeOperation(requestId);
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
break;
|
|
2222
|
+
case CHANGE_VP_SUCCESS:
|
|
2223
|
+
case DISABLE_VP_SUCCESS:
|
|
2224
|
+
if (viewports.has(body.viewPortId)) {
|
|
2225
|
+
const viewport = this.viewports.get(body.viewPortId);
|
|
2226
|
+
if (viewport) {
|
|
2227
|
+
const response = viewport.completeOperation(requestId);
|
|
2228
|
+
if (response !== void 0) {
|
|
2229
|
+
this.postMessageToClient(response);
|
|
2230
|
+
if (debugEnabled3) {
|
|
2231
|
+
debug3(\`postMessageToClient \${JSON.stringify(response)}\`);
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
break;
|
|
2237
|
+
case ENABLE_VP_SUCCESS:
|
|
2238
|
+
{
|
|
2239
|
+
const viewport = this.viewports.get(body.viewPortId);
|
|
2240
|
+
if (viewport) {
|
|
2241
|
+
const response = viewport.completeOperation(requestId);
|
|
2242
|
+
if (response) {
|
|
2243
|
+
this.postMessageToClient(response);
|
|
2244
|
+
const [size, rows] = viewport.resume();
|
|
2245
|
+
this.postMessageToClient({
|
|
2246
|
+
clientViewportId: viewport.clientViewportId,
|
|
2247
|
+
mode: "update",
|
|
2248
|
+
rows,
|
|
2249
|
+
size,
|
|
2250
|
+
type: "viewport-update"
|
|
2251
|
+
});
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
break;
|
|
2256
|
+
case "TABLE_ROW":
|
|
2257
|
+
{
|
|
2258
|
+
const viewportRowMap = groupRowsByViewport(body.rows);
|
|
2259
|
+
const [firstRow, secondRow] = body.rows;
|
|
2260
|
+
if (body.rows.length === 0) {
|
|
2261
|
+
infoEnabled2 && info2("handleMessageFromServer TABLE_ROW 0 rows");
|
|
2262
|
+
} else if ((firstRow == null ? void 0 : firstRow.rowIndex) === -1) {
|
|
2263
|
+
if (body.rows.length === 1) {
|
|
2264
|
+
if (firstRow.updateType === "SIZE") {
|
|
2265
|
+
infoEnabled2 && info2(
|
|
2266
|
+
\`handleMessageFromServer [\${firstRow.viewPortId}] TABLE_ROW SIZE ONLY \${firstRow.vpSize}\`
|
|
2267
|
+
);
|
|
2268
|
+
infoEnabled2 && info2(
|
|
2269
|
+
\`handleMessageFromServer [\${firstRow.viewPortId}] TABLE_ROW SIZE ONLY \${firstRow.vpSize}\`
|
|
2270
|
+
);
|
|
2271
|
+
} else {
|
|
2272
|
+
infoEnabled2 && info2(
|
|
2273
|
+
\`handleMessageFromServer [\${firstRow.viewPortId}] TABLE_ROW SIZE \${firstRow.vpSize} rowIdx \${firstRow.rowIndex}\`
|
|
2274
|
+
);
|
|
2275
|
+
}
|
|
2276
|
+
} else {
|
|
2277
|
+
infoEnabled2 && info2(
|
|
2278
|
+
\`handleMessageFromServer TABLE_ROW \${body.rows.length} rows, SIZE \${firstRow.vpSize}, [\${secondRow == null ? void 0 : secondRow.rowIndex}] - [\${(_b = body.rows[body.rows.length - 1]) == null ? void 0 : _b.rowIndex}]\`
|
|
2279
|
+
);
|
|
2280
|
+
}
|
|
2281
|
+
} else {
|
|
2282
|
+
infoEnabled2 && info2(
|
|
2283
|
+
\`handleMessageFromServer TABLE_ROW \${body.rows.length} rows [\${firstRow == null ? void 0 : firstRow.rowIndex}] - [\${(_c = body.rows[body.rows.length - 1]) == null ? void 0 : _c.rowIndex}]\`
|
|
2284
|
+
);
|
|
2285
|
+
}
|
|
2286
|
+
for (const [viewportId, rows] of Object.entries(viewportRowMap)) {
|
|
2287
|
+
const viewport = viewports.get(viewportId);
|
|
2288
|
+
if (viewport) {
|
|
2289
|
+
viewport.updateRows(rows);
|
|
2290
|
+
} else {
|
|
2291
|
+
warn2 == null ? void 0 : warn2(
|
|
2292
|
+
\`TABLE_ROW message received for non registered viewport \${viewportId}\`
|
|
2293
|
+
);
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
this.processUpdates();
|
|
2297
|
+
}
|
|
2298
|
+
break;
|
|
2299
|
+
case "CHANGE_VP_RANGE_SUCCESS":
|
|
2300
|
+
{
|
|
2301
|
+
const viewport = this.viewports.get(body.viewPortId);
|
|
2302
|
+
if (viewport) {
|
|
2303
|
+
const { from, to } = body;
|
|
2304
|
+
infoEnabled2 && info2(\`CHANGE_VP_RANGE_SUCCESS<#\${requestId}> \${from} - \${to}\`);
|
|
2305
|
+
viewport.completeOperation(requestId, from, to);
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
break;
|
|
2309
|
+
case OPEN_TREE_SUCCESS:
|
|
2310
|
+
case CLOSE_TREE_SUCCESS:
|
|
2311
|
+
break;
|
|
2312
|
+
case "CREATE_VISUAL_LINK_SUCCESS":
|
|
2313
|
+
{
|
|
2314
|
+
const viewport = this.viewports.get(body.childVpId);
|
|
2315
|
+
const parentViewport = this.viewports.get(body.parentVpId);
|
|
2316
|
+
if (viewport && parentViewport) {
|
|
2317
|
+
const { childColumnName, parentColumnName } = body;
|
|
2318
|
+
const response = viewport.completeOperation(
|
|
2319
|
+
requestId,
|
|
2320
|
+
childColumnName,
|
|
2321
|
+
parentViewport.clientViewportId,
|
|
2322
|
+
parentColumnName
|
|
2323
|
+
);
|
|
2324
|
+
if (response) {
|
|
2325
|
+
this.postMessageToClient(response);
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
}
|
|
2329
|
+
break;
|
|
2330
|
+
case "REMOVE_VISUAL_LINK_SUCCESS":
|
|
2331
|
+
{
|
|
2332
|
+
const viewport = this.viewports.get(body.childVpId);
|
|
2333
|
+
if (viewport) {
|
|
2334
|
+
const response = viewport.completeOperation(
|
|
2335
|
+
requestId
|
|
2336
|
+
);
|
|
2337
|
+
if (response) {
|
|
2338
|
+
this.postMessageToClient(response);
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
break;
|
|
2343
|
+
case "VP_VISUAL_LINKS_RESP":
|
|
2344
|
+
{
|
|
2345
|
+
const activeLinkDescriptors = this.getActiveLinks(body.links);
|
|
2346
|
+
const viewport = this.viewports.get(body.vpId);
|
|
2347
|
+
if (activeLinkDescriptors.length && viewport) {
|
|
2348
|
+
const linkDescriptorsWithLabels = addLabelsToLinks(
|
|
2349
|
+
activeLinkDescriptors,
|
|
2350
|
+
this.viewports
|
|
2351
|
+
);
|
|
2352
|
+
const [clientMessage, pendingLink] = viewport.setLinks(
|
|
2353
|
+
linkDescriptorsWithLabels
|
|
2354
|
+
);
|
|
2355
|
+
this.postMessageToClient(clientMessage);
|
|
2356
|
+
if (pendingLink) {
|
|
2357
|
+
const { link, parentClientVpId } = pendingLink;
|
|
2358
|
+
const requestId2 = nextRequestId();
|
|
2359
|
+
const parentVpId = this.mapClientToServerViewport.get(parentClientVpId);
|
|
2360
|
+
if (parentVpId) {
|
|
2361
|
+
const message2 = viewport.createLink(requestId2, {
|
|
2362
|
+
childVpId: body.vpId,
|
|
2363
|
+
childColumnName: link.fromColumn,
|
|
2364
|
+
parentColumnName: link.toColumn,
|
|
2365
|
+
parentVpId,
|
|
2366
|
+
type: "CREATE_VISUAL_LINK"
|
|
2367
|
+
});
|
|
2368
|
+
this.sendMessageToServer(message2, requestId2);
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
break;
|
|
2374
|
+
case "VIEW_PORT_MENUS_RESP":
|
|
2375
|
+
if (body.menu.name) {
|
|
2376
|
+
const viewport = this.viewports.get(body.vpId);
|
|
2377
|
+
if (viewport) {
|
|
2378
|
+
const clientMessage = viewport.setMenu(body.menu);
|
|
2379
|
+
this.postMessageToClient(clientMessage);
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
break;
|
|
2383
|
+
case "VP_EDIT_RPC_RESPONSE":
|
|
2384
|
+
{
|
|
2385
|
+
this.postMessageToClient({
|
|
2386
|
+
action: body.action,
|
|
2387
|
+
requestId,
|
|
2388
|
+
rpcName: body.rpcName,
|
|
2389
|
+
type: "VP_EDIT_RPC_RESPONSE"
|
|
2390
|
+
});
|
|
2391
|
+
}
|
|
2392
|
+
break;
|
|
2393
|
+
case "VP_EDIT_RPC_REJECT":
|
|
2394
|
+
{
|
|
2395
|
+
const viewport = this.viewports.get(body.vpId);
|
|
2396
|
+
if (viewport) {
|
|
2397
|
+
this.postMessageToClient({
|
|
2398
|
+
requestId,
|
|
2399
|
+
type: "VP_EDIT_RPC_REJECT",
|
|
2400
|
+
error: body.error
|
|
2401
|
+
});
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
break;
|
|
2405
|
+
case "VIEW_PORT_MENU_REJ": {
|
|
2406
|
+
const { error: error3, rpcName, vpId } = body;
|
|
2407
|
+
const viewport = this.viewports.get(vpId);
|
|
2408
|
+
if (viewport) {
|
|
2409
|
+
this.postMessageToClient({
|
|
2410
|
+
clientViewportId: viewport.clientViewportId,
|
|
2411
|
+
error: error3,
|
|
2412
|
+
rpcName,
|
|
2413
|
+
type: "VIEW_PORT_MENU_REJ",
|
|
2414
|
+
requestId
|
|
2415
|
+
});
|
|
2416
|
+
}
|
|
2417
|
+
break;
|
|
2418
|
+
}
|
|
2419
|
+
case "VIEW_PORT_MENU_RESP":
|
|
2420
|
+
{
|
|
2421
|
+
if (isSessionTableActionMessage(body)) {
|
|
2422
|
+
const { action, rpcName } = body;
|
|
2423
|
+
this.awaitResponseToMessage({
|
|
2424
|
+
type: "GET_TABLE_META",
|
|
2425
|
+
table: action.table
|
|
2426
|
+
}).then((response) => {
|
|
2427
|
+
const tableSchema = createSchemaFromTableMetadata(
|
|
2428
|
+
response
|
|
2429
|
+
);
|
|
2430
|
+
this.postMessageToClient({
|
|
2431
|
+
/* MenuRpcResponse */
|
|
2432
|
+
rpcName,
|
|
2433
|
+
type: "VIEW_PORT_MENU_RESP",
|
|
2434
|
+
action: {
|
|
2435
|
+
...action,
|
|
2436
|
+
tableSchema
|
|
2437
|
+
},
|
|
2438
|
+
tableAlreadyOpen: this.isTableOpen(action.table),
|
|
2439
|
+
requestId
|
|
2440
|
+
});
|
|
2441
|
+
});
|
|
2442
|
+
} else {
|
|
2443
|
+
const { action, rpcName } = body;
|
|
2444
|
+
this.postMessageToClient({
|
|
2445
|
+
/* MenuRpcResponse */
|
|
2446
|
+
action,
|
|
2447
|
+
rpcName,
|
|
2448
|
+
requestId,
|
|
2449
|
+
tableAlreadyOpen: isOpenDialogAction(action) && this.isTableOpen(action.table),
|
|
2450
|
+
type: "VIEW_PORT_MENU_RESP"
|
|
2451
|
+
});
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
break;
|
|
2455
|
+
case "RPC_RESP":
|
|
2456
|
+
{
|
|
2457
|
+
const { method, result } = body;
|
|
2458
|
+
this.postMessageToClient({
|
|
2459
|
+
type: "RPC_RESP",
|
|
2460
|
+
method,
|
|
2461
|
+
result,
|
|
2462
|
+
requestId
|
|
2463
|
+
});
|
|
2464
|
+
}
|
|
2465
|
+
break;
|
|
2466
|
+
case "VIEW_PORT_RPC_REPONSE":
|
|
2467
|
+
{
|
|
2468
|
+
const { method, action } = body;
|
|
2469
|
+
this.postMessageToClient({
|
|
2470
|
+
type: "VIEW_PORT_RPC_RESPONSE",
|
|
2471
|
+
rpcName: method,
|
|
2472
|
+
action,
|
|
2473
|
+
requestId
|
|
2474
|
+
});
|
|
2475
|
+
}
|
|
2476
|
+
break;
|
|
2477
|
+
case "ERROR":
|
|
2478
|
+
error2(body.msg);
|
|
2479
|
+
break;
|
|
2480
|
+
default:
|
|
2481
|
+
infoEnabled2 && info2(\`handleMessageFromServer \${body["type"]}.\`);
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
cacheTableMeta(messageBody) {
|
|
2485
|
+
const { module, table } = messageBody.table;
|
|
2486
|
+
const key = \`\${module}:\${table}\`;
|
|
2487
|
+
let tableSchema = this.cachedTableSchemas.get(key);
|
|
2488
|
+
if (!tableSchema) {
|
|
2489
|
+
tableSchema = createSchemaFromTableMetadata(messageBody);
|
|
2490
|
+
this.cachedTableSchemas.set(key, tableSchema);
|
|
2491
|
+
}
|
|
2492
|
+
return tableSchema;
|
|
2493
|
+
}
|
|
2494
|
+
isTableOpen(table) {
|
|
2495
|
+
if (table) {
|
|
2496
|
+
const tableName = table.table;
|
|
2497
|
+
for (const viewport of this.viewports.values()) {
|
|
2498
|
+
if (!viewport.suspended && viewport.table.table === tableName) {
|
|
2499
|
+
return true;
|
|
2500
|
+
}
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
// Eliminate links to suspended viewports
|
|
2505
|
+
getActiveLinks(linkDescriptors) {
|
|
2506
|
+
return linkDescriptors.filter((linkDescriptor) => {
|
|
2507
|
+
const viewport = this.viewports.get(linkDescriptor.parentVpId);
|
|
2508
|
+
return viewport && !viewport.suspended;
|
|
2509
|
+
});
|
|
2510
|
+
}
|
|
2511
|
+
processUpdates() {
|
|
2512
|
+
this.viewports.forEach((viewport) => {
|
|
2513
|
+
var _a;
|
|
2514
|
+
if (viewport.hasUpdatesToProcess) {
|
|
2515
|
+
const result = viewport.getClientRows();
|
|
2516
|
+
if (result !== NO_DATA_UPDATE) {
|
|
2517
|
+
const [rows, mode] = result;
|
|
2518
|
+
const size = viewport.getNewRowCount();
|
|
2519
|
+
if (size !== void 0 || rows && rows.length > 0) {
|
|
2520
|
+
debugEnabled3 && debug3(
|
|
2521
|
+
\`postMessageToClient #\${viewport.clientViewportId} viewport-update \${mode}, \${(_a = rows == null ? void 0 : rows.length) != null ? _a : "no"} rows, size \${size}\`
|
|
2522
|
+
);
|
|
2523
|
+
if (mode) {
|
|
2524
|
+
this.postMessageToClient({
|
|
2525
|
+
clientViewportId: viewport.clientViewportId,
|
|
2526
|
+
mode,
|
|
2527
|
+
rows,
|
|
2528
|
+
size,
|
|
2529
|
+
type: "viewport-update"
|
|
2530
|
+
});
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
}
|
|
2534
|
+
}
|
|
2535
|
+
});
|
|
2536
|
+
}
|
|
2537
|
+
};
|
|
2538
|
+
|
|
2539
|
+
// src/WebSocketConnection.ts
|
|
2540
|
+
var isNotConnecting = (connectionState) => connectionState.connectionStatus !== "connecting" && connectionState.connectionStatus !== "reconnecting";
|
|
2541
|
+
var isWebSocketConnectionMessage = (msg) => {
|
|
2542
|
+
if ("connectionStatus" in msg) {
|
|
2543
|
+
return [
|
|
2544
|
+
"connecting",
|
|
2545
|
+
"connected",
|
|
2546
|
+
"connection-open-awaiting-session",
|
|
2547
|
+
"reconnecting",
|
|
2548
|
+
"reconnected",
|
|
2549
|
+
"disconnected",
|
|
2550
|
+
"closed",
|
|
2551
|
+
"failed"
|
|
2552
|
+
].includes(msg.connectionStatus);
|
|
2553
|
+
} else {
|
|
2554
|
+
return false;
|
|
2555
|
+
}
|
|
2556
|
+
};
|
|
2557
|
+
var DEFAULT_RETRY_LIMITS = {
|
|
2558
|
+
connect: 5,
|
|
2559
|
+
reconnect: 8
|
|
2560
|
+
};
|
|
2561
|
+
var DEFAULT_CONNECTION_TIMEOUT = 1e4;
|
|
2562
|
+
var ConnectingEndState = {
|
|
2563
|
+
connecting: "connected",
|
|
2564
|
+
reconnecting: "reconnected"
|
|
2565
|
+
};
|
|
2566
|
+
var parseWebSocketMessage = (message) => {
|
|
2567
|
+
try {
|
|
2568
|
+
return JSON.parse(message);
|
|
2569
|
+
} catch (e) {
|
|
2570
|
+
throw Error(\`Error parsing JSON response from server \${message}\`);
|
|
2571
|
+
}
|
|
2572
|
+
};
|
|
2573
|
+
var _callback, _confirmedOpen, _connectionState, _connectionTimeout, _deferredConnection, _protocols, _reconnectAttempts, _requiresLogin, _url, _ws;
|
|
2574
|
+
var WebSocketConnection = class extends EventEmitter {
|
|
2575
|
+
constructor({
|
|
2576
|
+
callback,
|
|
2577
|
+
connectionTimeout = DEFAULT_CONNECTION_TIMEOUT,
|
|
2578
|
+
protocols,
|
|
2579
|
+
retryLimits = DEFAULT_RETRY_LIMITS,
|
|
2580
|
+
url
|
|
2581
|
+
}) {
|
|
2582
|
+
super();
|
|
2583
|
+
__privateAdd(this, _callback);
|
|
2584
|
+
/**
|
|
2585
|
+
We are not confirmedOpen until we receive the first message from the
|
|
2586
|
+
server. If we get an unexpected close event before that, we consider
|
|
2587
|
+
the reconnect attempts as still within the connection phase, not true
|
|
2588
|
+
reconnection. This can happen e.g. when connecting to remote host via
|
|
2589
|
+
a proxy.
|
|
2590
|
+
*/
|
|
2591
|
+
__privateAdd(this, _confirmedOpen, false);
|
|
2592
|
+
__privateAdd(this, _connectionState);
|
|
2593
|
+
__privateAdd(this, _connectionTimeout);
|
|
2594
|
+
__privateAdd(this, _deferredConnection);
|
|
2595
|
+
__privateAdd(this, _protocols);
|
|
2596
|
+
__privateAdd(this, _reconnectAttempts);
|
|
2597
|
+
__privateAdd(this, _requiresLogin, true);
|
|
2598
|
+
__privateAdd(this, _url);
|
|
2599
|
+
__privateAdd(this, _ws);
|
|
2600
|
+
__publicField(this, "receive", (evt) => {
|
|
2601
|
+
const vuuMessageFromServer = parseWebSocketMessage(evt.data);
|
|
2602
|
+
__privateGet(this, _callback).call(this, vuuMessageFromServer);
|
|
2603
|
+
});
|
|
2604
|
+
__publicField(this, "send", (msg) => {
|
|
2605
|
+
var _a;
|
|
2606
|
+
(_a = __privateGet(this, _ws)) == null ? void 0 : _a.send(JSON.stringify(msg));
|
|
2607
|
+
});
|
|
2608
|
+
__privateSet(this, _callback, callback);
|
|
2609
|
+
__privateSet(this, _connectionTimeout, connectionTimeout);
|
|
2610
|
+
__privateSet(this, _url, url);
|
|
2611
|
+
__privateSet(this, _protocols, protocols);
|
|
2612
|
+
__privateSet(this, _reconnectAttempts, {
|
|
2613
|
+
retryAttemptsTotal: retryLimits.reconnect,
|
|
2614
|
+
retryAttemptsRemaining: retryLimits.reconnect,
|
|
2615
|
+
secondsToNextRetry: 1
|
|
2616
|
+
});
|
|
2617
|
+
__privateSet(this, _connectionState, {
|
|
2618
|
+
connectionPhase: "connecting",
|
|
2619
|
+
connectionStatus: "closed",
|
|
2620
|
+
retryAttemptsTotal: retryLimits.connect,
|
|
2621
|
+
retryAttemptsRemaining: retryLimits.connect,
|
|
2622
|
+
secondsToNextRetry: 1
|
|
2623
|
+
});
|
|
2624
|
+
}
|
|
2625
|
+
get connectionTimeout() {
|
|
2626
|
+
return __privateGet(this, _connectionTimeout);
|
|
2627
|
+
}
|
|
2628
|
+
get protocols() {
|
|
2629
|
+
return __privateGet(this, _protocols);
|
|
2630
|
+
}
|
|
2631
|
+
get requiresLogin() {
|
|
2632
|
+
return __privateGet(this, _requiresLogin);
|
|
2633
|
+
}
|
|
2634
|
+
get isClosed() {
|
|
2635
|
+
return this.status === "closed";
|
|
2636
|
+
}
|
|
2637
|
+
get isDisconnected() {
|
|
2638
|
+
return this.status === "disconnected";
|
|
2639
|
+
}
|
|
2640
|
+
get isConnecting() {
|
|
2641
|
+
return __privateGet(this, _connectionState).connectionPhase === "connecting";
|
|
2642
|
+
}
|
|
2643
|
+
get status() {
|
|
2644
|
+
return __privateGet(this, _connectionState).connectionStatus;
|
|
2645
|
+
}
|
|
2646
|
+
set status(connectionStatus) {
|
|
2647
|
+
__privateSet(this, _connectionState, {
|
|
2648
|
+
...__privateGet(this, _connectionState),
|
|
2649
|
+
connectionStatus
|
|
2650
|
+
});
|
|
2651
|
+
if (isNotConnecting(__privateGet(this, _connectionState))) {
|
|
2652
|
+
this.emit("connection-status", __privateGet(this, _connectionState));
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
get connectionState() {
|
|
2656
|
+
return __privateGet(this, _connectionState);
|
|
2657
|
+
}
|
|
2658
|
+
get hasConnectionAttemptsRemaining() {
|
|
2659
|
+
return __privateGet(this, _connectionState).retryAttemptsRemaining > 0;
|
|
2660
|
+
}
|
|
2661
|
+
get confirmedOpen() {
|
|
2662
|
+
return __privateGet(this, _confirmedOpen);
|
|
2663
|
+
}
|
|
2664
|
+
/**
|
|
2665
|
+
* We are 'confirmedOpen' when we see the first message transmitted
|
|
2666
|
+
* from the server. This ensures that even if we have one or more
|
|
2667
|
+
* proxies in our route to the endPoint, all connections have been
|
|
2668
|
+
* opened successfully.
|
|
2669
|
+
* First time in here (on our initial successful connection) we switch
|
|
2670
|
+
* from 'connect' phase to 'reconnect' phase. We may have different
|
|
2671
|
+
* retry configurations for these two phases.
|
|
2672
|
+
*/
|
|
2673
|
+
set confirmedOpen(confirmedOpen) {
|
|
2674
|
+
__privateSet(this, _confirmedOpen, confirmedOpen);
|
|
2675
|
+
if (confirmedOpen && this.isConnecting) {
|
|
2676
|
+
__privateSet(this, _connectionState, {
|
|
2677
|
+
...__privateGet(this, _connectionState),
|
|
2678
|
+
connectionPhase: "reconnecting",
|
|
2679
|
+
...__privateGet(this, _reconnectAttempts)
|
|
2680
|
+
});
|
|
2681
|
+
} else if (confirmedOpen) {
|
|
2682
|
+
__privateSet(this, _connectionState, {
|
|
2683
|
+
...__privateGet(this, _connectionState),
|
|
2684
|
+
...__privateGet(this, _reconnectAttempts)
|
|
2685
|
+
});
|
|
2686
|
+
}
|
|
2687
|
+
}
|
|
2688
|
+
get url() {
|
|
2689
|
+
return __privateGet(this, _url);
|
|
2690
|
+
}
|
|
2691
|
+
async connect(clientCall = true) {
|
|
2692
|
+
var _a;
|
|
2693
|
+
const state = __privateGet(this, _connectionState);
|
|
2694
|
+
if (this.isConnecting && __privateGet(this, _deferredConnection) === void 0) {
|
|
2695
|
+
__privateSet(this, _deferredConnection, new DeferredPromise());
|
|
2696
|
+
}
|
|
2697
|
+
const { connectionTimeout, protocols, url } = this;
|
|
2698
|
+
this.status = state.connectionPhase;
|
|
2699
|
+
const timer = setTimeout(() => {
|
|
2700
|
+
throw Error(
|
|
2701
|
+
\`Failed to open WebSocket connection to \${url}, timed out after \${connectionTimeout}ms\`
|
|
2702
|
+
);
|
|
2703
|
+
}, connectionTimeout);
|
|
2704
|
+
const ws2 = __privateSet(this, _ws, new WebSocket(url, protocols));
|
|
2705
|
+
ws2.onopen = () => {
|
|
2706
|
+
const connectedStatus = ConnectingEndState[state.connectionPhase];
|
|
2707
|
+
this.status = connectedStatus;
|
|
2708
|
+
clearTimeout(timer);
|
|
2709
|
+
if (__privateGet(this, _deferredConnection)) {
|
|
2710
|
+
__privateGet(this, _deferredConnection).resolve(void 0);
|
|
2711
|
+
__privateSet(this, _deferredConnection, void 0);
|
|
2712
|
+
}
|
|
2713
|
+
if (this.isConnecting) {
|
|
2714
|
+
this.emit("connected");
|
|
2715
|
+
} else {
|
|
2716
|
+
this.emit("reconnected");
|
|
2717
|
+
}
|
|
2718
|
+
};
|
|
2719
|
+
ws2.onerror = () => {
|
|
2720
|
+
clearTimeout(timer);
|
|
2721
|
+
};
|
|
2722
|
+
ws2.onclose = () => {
|
|
2723
|
+
if (!this.isClosed) {
|
|
2724
|
+
this.confirmedOpen = false;
|
|
2725
|
+
this.status = "disconnected";
|
|
2726
|
+
if (this.hasConnectionAttemptsRemaining) {
|
|
2727
|
+
this.reconnect();
|
|
2728
|
+
} else {
|
|
2729
|
+
this.close("failure");
|
|
2730
|
+
}
|
|
2731
|
+
}
|
|
2732
|
+
};
|
|
2733
|
+
ws2.onmessage = (evt) => {
|
|
2734
|
+
if (!this.confirmedOpen) {
|
|
2735
|
+
this.confirmedOpen = true;
|
|
2736
|
+
}
|
|
2737
|
+
this.receive(evt);
|
|
2738
|
+
};
|
|
2739
|
+
if (clientCall) {
|
|
2740
|
+
return (_a = __privateGet(this, _deferredConnection)) == null ? void 0 : _a.promise;
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
reconnect() {
|
|
2744
|
+
const { retryAttemptsRemaining, secondsToNextRetry } = __privateGet(this, _connectionState);
|
|
2745
|
+
setTimeout(() => {
|
|
2746
|
+
__privateSet(this, _connectionState, {
|
|
2747
|
+
...__privateGet(this, _connectionState),
|
|
2748
|
+
retryAttemptsRemaining: retryAttemptsRemaining - 1,
|
|
2749
|
+
secondsToNextRetry: secondsToNextRetry * 2
|
|
2750
|
+
});
|
|
2751
|
+
this.connect(false);
|
|
2752
|
+
}, secondsToNextRetry * 1e3);
|
|
2753
|
+
}
|
|
2754
|
+
close(reason = "shutdown") {
|
|
2755
|
+
var _a;
|
|
2756
|
+
this.status = "closed";
|
|
2757
|
+
if (reason === "failure") {
|
|
2758
|
+
if (__privateGet(this, _deferredConnection)) {
|
|
2759
|
+
__privateGet(this, _deferredConnection).reject(Error("connection failed"));
|
|
2760
|
+
__privateSet(this, _deferredConnection, void 0);
|
|
2761
|
+
}
|
|
2762
|
+
} else {
|
|
2763
|
+
(_a = __privateGet(this, _ws)) == null ? void 0 : _a.close();
|
|
2764
|
+
}
|
|
2765
|
+
this.emit("closed", reason);
|
|
2766
|
+
__privateSet(this, _ws, void 0);
|
|
2767
|
+
}
|
|
2768
|
+
};
|
|
2769
|
+
_callback = new WeakMap();
|
|
2770
|
+
_confirmedOpen = new WeakMap();
|
|
2771
|
+
_connectionState = new WeakMap();
|
|
2772
|
+
_connectionTimeout = new WeakMap();
|
|
2773
|
+
_deferredConnection = new WeakMap();
|
|
2774
|
+
_protocols = new WeakMap();
|
|
2775
|
+
_reconnectAttempts = new WeakMap();
|
|
2776
|
+
_requiresLogin = new WeakMap();
|
|
2777
|
+
_url = new WeakMap();
|
|
2778
|
+
_ws = new WeakMap();
|
|
2779
|
+
|
|
2780
|
+
// src/worker.ts
|
|
2781
|
+
var server;
|
|
2782
|
+
var { info: info3, infoEnabled: infoEnabled3 } = logger("worker");
|
|
2783
|
+
var getRetryLimits = (retryLimitDisconnect, retryLimitStartup) => {
|
|
2784
|
+
if (retryLimitDisconnect !== void 0 && retryLimitStartup !== void 0) {
|
|
2785
|
+
return {
|
|
2786
|
+
connect: retryLimitStartup,
|
|
2787
|
+
reconnect: retryLimitDisconnect
|
|
2788
|
+
};
|
|
2789
|
+
} else if (retryLimitDisconnect !== void 0) {
|
|
2790
|
+
return {
|
|
2791
|
+
connect: retryLimitDisconnect,
|
|
2792
|
+
reconnect: retryLimitDisconnect
|
|
2793
|
+
};
|
|
2794
|
+
} else if (retryLimitStartup !== void 0) {
|
|
2795
|
+
return {
|
|
2796
|
+
connect: retryLimitStartup,
|
|
2797
|
+
reconnect: retryLimitStartup
|
|
2798
|
+
};
|
|
2799
|
+
}
|
|
2800
|
+
};
|
|
2801
|
+
var ws;
|
|
2802
|
+
var sendMessageToClient = (message) => {
|
|
2803
|
+
postMessage(message);
|
|
2804
|
+
};
|
|
2805
|
+
async function connectToServer(url, protocols, token, username, retryLimitDisconnect, retryLimitStartup) {
|
|
2806
|
+
const websocketConnection = ws = new WebSocketConnection({
|
|
2807
|
+
callback: (msg) => {
|
|
2808
|
+
if (isConnectionQualityMetrics(msg)) {
|
|
2809
|
+
postMessage({ type: "connection-metrics", messages: msg });
|
|
2810
|
+
} else if (isWebSocketConnectionMessage(msg)) {
|
|
2811
|
+
postMessage(msg);
|
|
2812
|
+
} else {
|
|
2813
|
+
server.handleMessageFromServer(msg);
|
|
2814
|
+
}
|
|
2815
|
+
},
|
|
2816
|
+
protocols,
|
|
2817
|
+
retryLimits: getRetryLimits(retryLimitStartup, retryLimitDisconnect),
|
|
2818
|
+
url
|
|
2819
|
+
});
|
|
2820
|
+
websocketConnection.on("connection-status", postMessage);
|
|
2821
|
+
await websocketConnection.connect();
|
|
2822
|
+
server = new ServerProxy(websocketConnection, sendMessageToClient);
|
|
2823
|
+
if (websocketConnection.requiresLogin) {
|
|
2824
|
+
await server.login(token, username);
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2827
|
+
var handleMessageFromClient = async ({
|
|
2828
|
+
data: message
|
|
2829
|
+
}) => {
|
|
2830
|
+
switch (message.type) {
|
|
2831
|
+
case "connect":
|
|
2832
|
+
try {
|
|
2833
|
+
await connectToServer(
|
|
2834
|
+
message.url,
|
|
2835
|
+
message.protocol,
|
|
2836
|
+
message.token,
|
|
2837
|
+
message.username,
|
|
2838
|
+
message.retryLimitDisconnect,
|
|
2839
|
+
message.retryLimitStartup
|
|
2840
|
+
);
|
|
2841
|
+
postMessage({ type: "connected" });
|
|
2842
|
+
} catch (err) {
|
|
2843
|
+
postMessage({ type: "connection-failed", reason: String(err) });
|
|
2844
|
+
}
|
|
2845
|
+
break;
|
|
2846
|
+
// If any of the messages below are received BEFORE we have connected and created
|
|
2847
|
+
// the server - handle accordingly
|
|
2848
|
+
case "disconnect":
|
|
2849
|
+
server.disconnect();
|
|
2850
|
+
ws == null ? void 0 : ws.close();
|
|
2851
|
+
break;
|
|
2852
|
+
case "subscribe":
|
|
2853
|
+
infoEnabled3 && info3(\`client subscribe: \${JSON.stringify(message)}\`);
|
|
2854
|
+
server.subscribe(message);
|
|
2855
|
+
break;
|
|
2856
|
+
case "unsubscribe":
|
|
2857
|
+
infoEnabled3 && info3(\`client unsubscribe: \${JSON.stringify(message)}\`);
|
|
2858
|
+
server.unsubscribe(message.viewport);
|
|
2859
|
+
break;
|
|
2860
|
+
default:
|
|
2861
|
+
infoEnabled3 && info3(\`client message: \${JSON.stringify(message)}\`);
|
|
2862
|
+
server.handleMessageFromClient(message);
|
|
2863
|
+
}
|
|
2864
|
+
};
|
|
2865
|
+
self.addEventListener("message", handleMessageFromClient);
|
|
2866
|
+
postMessage({ type: "ready" });
|
|
2867
|
+
|
|
2868
|
+
`;
|
|
2869
|
+
|
|
2870
|
+
var __typeError$3 = (msg) => {
|
|
2871
|
+
throw TypeError(msg);
|
|
2872
|
+
};
|
|
2873
|
+
var __accessCheck$3 = (obj, member, msg) => member.has(obj) || __typeError$3("Cannot " + msg);
|
|
2874
|
+
var __privateGet$3 = (obj, member, getter) => (__accessCheck$3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
2875
|
+
var __privateAdd$3 = (obj, member, value) => member.has(obj) ? __typeError$3("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
2876
|
+
var __privateSet$2 = (obj, member, value, setter) => (__accessCheck$3(obj, member, "write to private field"), member.set(obj, value), value);
|
|
2877
|
+
var _deferredConnection, _worker$1;
|
|
2878
|
+
const workerBlob = new Blob([vuuUtils.getLoggingConfigForWorker() + workerSourceCode], {
|
|
2879
|
+
type: "text/javascript"
|
|
2880
|
+
});
|
|
2881
|
+
const workerBlobUrl = URL.createObjectURL(workerBlob);
|
|
2882
|
+
class DedicatedWorker {
|
|
2883
|
+
constructor(onMessage) {
|
|
2884
|
+
__privateAdd$3(this, _deferredConnection);
|
|
2885
|
+
__privateAdd$3(this, _worker$1);
|
|
2886
|
+
const deferredWorker = new vuuUtils.DeferredPromise();
|
|
2887
|
+
__privateSet$2(this, _worker$1, deferredWorker.promise);
|
|
2888
|
+
const worker = new Worker(workerBlobUrl);
|
|
2889
|
+
const timer = window.setTimeout(() => {
|
|
2890
|
+
console.warn("timed out waiting for worker to load");
|
|
2891
|
+
}, 1e3);
|
|
2892
|
+
worker.onmessage = (msg) => {
|
|
2893
|
+
const { data: message } = msg;
|
|
2894
|
+
if (message.type === "ready") {
|
|
2895
|
+
window.clearTimeout(timer);
|
|
2896
|
+
deferredWorker.resolve(worker);
|
|
2897
|
+
} else if (message.type === "connected") {
|
|
2898
|
+
__privateGet$3(this, _deferredConnection)?.resolve("connected");
|
|
2899
|
+
} else if (message.type === "connection-failed") {
|
|
2900
|
+
__privateGet$3(this, _deferredConnection)?.resolve("rejected");
|
|
2901
|
+
} else {
|
|
2902
|
+
onMessage(message);
|
|
2903
|
+
}
|
|
2904
|
+
};
|
|
2905
|
+
}
|
|
2906
|
+
async connect(options) {
|
|
2907
|
+
__privateSet$2(this, _deferredConnection, new vuuUtils.DeferredPromise());
|
|
2908
|
+
this.send({
|
|
2909
|
+
...options,
|
|
2910
|
+
type: "connect"
|
|
2911
|
+
});
|
|
2912
|
+
return __privateGet$3(this, _deferredConnection).promise;
|
|
2913
|
+
}
|
|
2914
|
+
async send(message) {
|
|
2915
|
+
(await __privateGet$3(this, _worker$1)).postMessage(message);
|
|
2916
|
+
}
|
|
2917
|
+
async terminate() {
|
|
2918
|
+
(await __privateGet$3(this, _worker$1)).terminate();
|
|
2919
|
+
}
|
|
2920
|
+
}
|
|
2921
|
+
_deferredConnection = new WeakMap();
|
|
2922
|
+
_worker$1 = new WeakMap();
|
|
2923
|
+
|
|
2924
|
+
const isSizeOnly = (message) => message.type === "viewport-update" && message.mode === "size-only";
|
|
2925
|
+
const toDataSourceConfig = (message) => {
|
|
2926
|
+
switch (message.type) {
|
|
2927
|
+
case "aggregate":
|
|
2928
|
+
return { aggregations: message.aggregations };
|
|
2929
|
+
case "columns":
|
|
2930
|
+
return { columns: message.columns };
|
|
2931
|
+
case "filter":
|
|
2932
|
+
return { filterSpec: message.filter };
|
|
2933
|
+
case "groupBy":
|
|
2934
|
+
return { groupBy: message.groupBy };
|
|
2935
|
+
case "sort":
|
|
2936
|
+
return { sort: message.sort };
|
|
2937
|
+
case "config":
|
|
2938
|
+
return message.config;
|
|
2939
|
+
}
|
|
2940
|
+
};
|
|
2941
|
+
const datasourceMessages = [
|
|
2942
|
+
"config",
|
|
2943
|
+
"aggregate",
|
|
2944
|
+
"viewport-clear",
|
|
2945
|
+
"viewport-update",
|
|
2946
|
+
"columns",
|
|
2947
|
+
"debounce-begin",
|
|
2948
|
+
"disabled",
|
|
2949
|
+
"enabled",
|
|
2950
|
+
"filter",
|
|
2951
|
+
"groupBy",
|
|
2952
|
+
"vuu-links",
|
|
2953
|
+
"vuu-menu",
|
|
2954
|
+
"sort",
|
|
2955
|
+
"subscribed"
|
|
2956
|
+
];
|
|
2957
|
+
const shouldMessageBeRoutedToDataSource = (message) => {
|
|
2958
|
+
const type = message.type;
|
|
2959
|
+
return datasourceMessages.includes(type);
|
|
2960
|
+
};
|
|
2961
|
+
const isDataSourceConfigMessage = (message) => ["config", "aggregate", "columns", "filter", "groupBy", "sort"].includes(
|
|
2962
|
+
message.type
|
|
2963
|
+
);
|
|
2964
|
+
|
|
2965
|
+
var __defProp$3 = Object.defineProperty;
|
|
2966
|
+
var __typeError$2 = (msg) => {
|
|
2967
|
+
throw TypeError(msg);
|
|
2968
|
+
};
|
|
2969
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2970
|
+
var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2971
|
+
var __accessCheck$2 = (obj, member, msg) => member.has(obj) || __typeError$2("Cannot " + msg);
|
|
2972
|
+
var __privateGet$2 = (obj, member, getter) => (__accessCheck$2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
2973
|
+
var __privateAdd$2 = (obj, member, value) => member.has(obj) ? __typeError$2("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
2974
|
+
var __privateSet$1 = (obj, member, value, setter) => (__accessCheck$2(obj, member, "write to private field"), member.set(obj, value), value);
|
|
2975
|
+
var _connectionState, _instance, _deferredServerAPI, _pendingRequests, _viewports, _worker;
|
|
2976
|
+
const _ConnectionManager = class _ConnectionManager extends vuuUtils.EventEmitter {
|
|
2977
|
+
constructor() {
|
|
2978
|
+
super();
|
|
2979
|
+
__privateAdd$2(this, _connectionState, {
|
|
2980
|
+
connectionPhase: "connecting",
|
|
2981
|
+
connectionStatus: "closed",
|
|
2982
|
+
retryAttemptsTotal: -1,
|
|
2983
|
+
retryAttemptsRemaining: -1,
|
|
2984
|
+
secondsToNextRetry: -1
|
|
2985
|
+
});
|
|
2986
|
+
__privateAdd$2(this, _deferredServerAPI, new vuuUtils.DeferredPromise());
|
|
2987
|
+
__privateAdd$2(this, _pendingRequests, /* @__PURE__ */ new Map());
|
|
2988
|
+
__privateAdd$2(this, _viewports, /* @__PURE__ */ new Map());
|
|
2989
|
+
// #worker?: Worker;
|
|
2990
|
+
__privateAdd$2(this, _worker);
|
|
2991
|
+
__publicField$3(this, "handleMessageFromWorker", (message) => {
|
|
2992
|
+
if (shouldMessageBeRoutedToDataSource(message)) {
|
|
2993
|
+
const viewport = __privateGet$2(this, _viewports).get(message.clientViewportId);
|
|
2994
|
+
if (viewport) {
|
|
2995
|
+
viewport.postMessageToClientDataSource(message);
|
|
2996
|
+
} else {
|
|
2997
|
+
console.error(
|
|
2998
|
+
`[ConnectionManager] ${message.type} message received, viewport not found`
|
|
2999
|
+
);
|
|
3000
|
+
}
|
|
3001
|
+
} else if (isWebSocketConnectionMessage(message)) {
|
|
3002
|
+
__privateSet$1(this, _connectionState, message);
|
|
3003
|
+
this.emit("connection-status", message);
|
|
3004
|
+
} else if (vuuUtils.isConnectionQualityMetrics(message)) {
|
|
3005
|
+
this.emit("connection-metrics", message);
|
|
3006
|
+
} else if (vuuUtils.isRequestResponse(message)) {
|
|
3007
|
+
const { requestId } = message;
|
|
3008
|
+
if (__privateGet$2(this, _pendingRequests).has(requestId)) {
|
|
3009
|
+
const { resolve } = __privateGet$2(this, _pendingRequests).get(requestId);
|
|
3010
|
+
__privateGet$2(this, _pendingRequests).delete(requestId);
|
|
3011
|
+
const { requestId: _, ...messageWithoutRequestId } = message;
|
|
3012
|
+
if (vuuUtils.messageHasResult(message)) {
|
|
3013
|
+
resolve(message.result);
|
|
3014
|
+
} else if (message.type === "VP_EDIT_RPC_RESPONSE" || message.type === "VP_EDIT_RPC_REJECT") {
|
|
3015
|
+
resolve(message);
|
|
3016
|
+
} else if (vuuUtils.isTableSchemaMessage(message)) {
|
|
3017
|
+
resolve(message.tableSchema);
|
|
3018
|
+
} else {
|
|
3019
|
+
resolve(messageWithoutRequestId);
|
|
3020
|
+
}
|
|
3021
|
+
} else {
|
|
3022
|
+
console.warn(
|
|
3023
|
+
"%cConnectionManager Unexpected message from the worker",
|
|
3024
|
+
"color:red;font-weight:bold;"
|
|
3025
|
+
);
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
3028
|
+
});
|
|
3029
|
+
__publicField$3(this, "connectedServerAPI", {
|
|
3030
|
+
subscribe: (message, callback) => {
|
|
3031
|
+
if (__privateGet$2(this, _viewports).get(message.viewport)) {
|
|
3032
|
+
throw Error(
|
|
3033
|
+
`ConnectionManager attempting to subscribe with an existing viewport id`
|
|
3034
|
+
);
|
|
3035
|
+
}
|
|
3036
|
+
__privateGet$2(this, _viewports).set(message.viewport, {
|
|
3037
|
+
status: "subscribing",
|
|
3038
|
+
request: message,
|
|
3039
|
+
postMessageToClientDataSource: callback
|
|
3040
|
+
});
|
|
3041
|
+
__privateGet$2(this, _worker).send({ type: "subscribe", ...message });
|
|
3042
|
+
},
|
|
3043
|
+
unsubscribe: (viewport) => {
|
|
3044
|
+
__privateGet$2(this, _worker).send({ type: "unsubscribe", viewport });
|
|
3045
|
+
},
|
|
3046
|
+
send: (message) => {
|
|
3047
|
+
__privateGet$2(this, _worker).send(message);
|
|
3048
|
+
},
|
|
3049
|
+
destroy: (viewportId) => {
|
|
3050
|
+
if (viewportId && __privateGet$2(this, _viewports).has(viewportId)) {
|
|
3051
|
+
__privateGet$2(this, _viewports).delete(viewportId);
|
|
3052
|
+
}
|
|
3053
|
+
},
|
|
3054
|
+
rpcCall: async (message) => this.asyncRequest(message),
|
|
3055
|
+
getTableList: async () => this.asyncRequest({ type: "GET_TABLE_LIST" }),
|
|
3056
|
+
getTableSchema: async (table) => this.asyncRequest({
|
|
3057
|
+
type: "GET_TABLE_META",
|
|
3058
|
+
table
|
|
3059
|
+
})
|
|
3060
|
+
});
|
|
3061
|
+
__publicField$3(this, "asyncRequest", (msg) => {
|
|
3062
|
+
const requestId = vuuUtils.uuid();
|
|
3063
|
+
__privateGet$2(this, _worker).send({
|
|
3064
|
+
requestId,
|
|
3065
|
+
...msg
|
|
3066
|
+
});
|
|
3067
|
+
return new Promise((resolve, reject) => {
|
|
3068
|
+
__privateGet$2(this, _pendingRequests).set(requestId, { resolve, reject });
|
|
3069
|
+
});
|
|
3070
|
+
});
|
|
3071
|
+
__privateSet$1(this, _worker, new DedicatedWorker(this.handleMessageFromWorker));
|
|
3072
|
+
}
|
|
3073
|
+
static get instance() {
|
|
3074
|
+
if (!__privateGet$2(_ConnectionManager, _instance)) {
|
|
3075
|
+
__privateSet$1(_ConnectionManager, _instance, new _ConnectionManager());
|
|
3076
|
+
}
|
|
3077
|
+
return __privateGet$2(_ConnectionManager, _instance);
|
|
3078
|
+
}
|
|
3079
|
+
/**
|
|
3080
|
+
* Open a connection to the VuuServer. This method opens the websocket connection
|
|
3081
|
+
* and logs in. It can be called from whichever client code has access to the auth
|
|
3082
|
+
* token (eg. the login page, or just a hardcoded login script in a sample).
|
|
3083
|
+
* This will unblock any DataSources which may have already tried to subscribe to data,
|
|
3084
|
+
* but lacked access to the auth token.
|
|
3085
|
+
*
|
|
3086
|
+
* @param serverUrl
|
|
3087
|
+
* @param token
|
|
3088
|
+
*/
|
|
3089
|
+
async connect(options) {
|
|
3090
|
+
const result = await __privateGet$2(this, _worker).connect(options);
|
|
3091
|
+
if (result === "connected") {
|
|
3092
|
+
__privateGet$2(this, _deferredServerAPI).resolve(this.connectedServerAPI);
|
|
3093
|
+
}
|
|
3094
|
+
return result;
|
|
3095
|
+
}
|
|
3096
|
+
get connectionStatus() {
|
|
3097
|
+
return __privateGet$2(this, _connectionState).connectionStatus;
|
|
3098
|
+
}
|
|
3099
|
+
get serverAPI() {
|
|
3100
|
+
return __privateGet$2(this, _deferredServerAPI).promise;
|
|
3101
|
+
}
|
|
3102
|
+
async disconnect() {
|
|
3103
|
+
try {
|
|
3104
|
+
__privateGet$2(this, _worker).send({ type: "disconnect" });
|
|
3105
|
+
__privateSet$1(this, _deferredServerAPI, new vuuUtils.DeferredPromise());
|
|
3106
|
+
return "disconnected";
|
|
3107
|
+
} catch (err) {
|
|
3108
|
+
return "rejected";
|
|
3109
|
+
}
|
|
3110
|
+
}
|
|
3111
|
+
destroy() {
|
|
3112
|
+
__privateGet$2(this, _worker).terminate();
|
|
3113
|
+
}
|
|
3114
|
+
};
|
|
3115
|
+
_connectionState = new WeakMap();
|
|
3116
|
+
_instance = new WeakMap();
|
|
3117
|
+
_deferredServerAPI = new WeakMap();
|
|
3118
|
+
_pendingRequests = new WeakMap();
|
|
3119
|
+
_viewports = new WeakMap();
|
|
3120
|
+
_worker = new WeakMap();
|
|
3121
|
+
__privateAdd$2(_ConnectionManager, _instance);
|
|
3122
|
+
let ConnectionManager = _ConnectionManager;
|
|
3123
|
+
var ConnectionManager$1 = ConnectionManager.instance;
|
|
3124
|
+
|
|
3125
|
+
let _connectionId = 0;
|
|
3126
|
+
const connectionId = {
|
|
3127
|
+
get nextValue() {
|
|
3128
|
+
return _connectionId++;
|
|
3129
|
+
}
|
|
3130
|
+
};
|
|
3131
|
+
const msgType = {
|
|
3132
|
+
connect: "connect",
|
|
3133
|
+
connectionStatus: "connection-status",
|
|
3134
|
+
getFilterData: "GetFilterData",
|
|
3135
|
+
rowData: "rowData",
|
|
3136
|
+
rowSet: "rowset",
|
|
3137
|
+
select: "select",
|
|
3138
|
+
selectAll: "selectAll",
|
|
3139
|
+
selectNone: "selectNone",
|
|
3140
|
+
selected: "selected",
|
|
3141
|
+
snapshot: "snapshot",
|
|
3142
|
+
update: "update",
|
|
3143
|
+
createLink: "createLink",
|
|
3144
|
+
disable: "disable",
|
|
3145
|
+
enable: "enable",
|
|
3146
|
+
suspend: "suspend",
|
|
3147
|
+
resume: "resume",
|
|
3148
|
+
addSubscription: "AddSubscription",
|
|
3149
|
+
closeTreeNode: "closeTreeNode",
|
|
3150
|
+
columnList: "ColumnList",
|
|
3151
|
+
data: "data",
|
|
3152
|
+
openTreeNode: "openTreeNode",
|
|
3153
|
+
aggregate: "aggregate",
|
|
3154
|
+
filter: "filter",
|
|
3155
|
+
filterQuery: "filterQuery",
|
|
3156
|
+
filterData: "filterData",
|
|
3157
|
+
getSearchData: "GetSearchData",
|
|
3158
|
+
groupBy: "groupBy",
|
|
3159
|
+
modifySubscription: "ModifySubscription",
|
|
3160
|
+
searchData: "searchData",
|
|
3161
|
+
setGroupState: "setGroupState",
|
|
3162
|
+
size: "size",
|
|
3163
|
+
sort: "sort",
|
|
3164
|
+
subscribed: "Subscribed",
|
|
3165
|
+
tableList: "TableList",
|
|
3166
|
+
unsubscribe: "TerminateSubscription",
|
|
3167
|
+
viewRangeChanged: "ViewRangeChanged"
|
|
3168
|
+
};
|
|
3169
|
+
|
|
3170
|
+
const isVuuRpcRequest = (message) => message["type"] === "VIEW_PORT_RPC_CALL";
|
|
3171
|
+
const stripRequestId = ({
|
|
3172
|
+
requestId,
|
|
3173
|
+
...rest
|
|
3174
|
+
}) => [requestId, rest];
|
|
3175
|
+
const getFirstAndLastRows = (rows) => {
|
|
3176
|
+
let firstRow = rows.at(0);
|
|
3177
|
+
if (firstRow.updateType === "SIZE") {
|
|
3178
|
+
if (rows.length === 1) {
|
|
3179
|
+
return rows;
|
|
3180
|
+
} else {
|
|
3181
|
+
firstRow = rows.at(1);
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
const lastRow = rows.at(-1);
|
|
3185
|
+
return [firstRow, lastRow];
|
|
3186
|
+
};
|
|
3187
|
+
const insertRow = (rows, row) => {
|
|
3188
|
+
const lastRow = rows.at(-1);
|
|
3189
|
+
if (lastRow === void 0 || row.rowIndex > lastRow.rowIndex) {
|
|
3190
|
+
rows.push(row);
|
|
3191
|
+
} else {
|
|
3192
|
+
for (let i = 0; i < rows.length; i++) {
|
|
3193
|
+
if (row.rowIndex < rows[i].rowIndex) {
|
|
3194
|
+
rows.splice(i, 0, row);
|
|
3195
|
+
return;
|
|
3196
|
+
} else if (row.rowIndex === rows[i].rowIndex) {
|
|
3197
|
+
if (row.ts < rows[i].ts) ; else {
|
|
3198
|
+
rows[i] = row;
|
|
3199
|
+
}
|
|
3200
|
+
return;
|
|
3201
|
+
}
|
|
3202
|
+
}
|
|
3203
|
+
throw Error("don't expect to get this far");
|
|
3204
|
+
}
|
|
3205
|
+
};
|
|
3206
|
+
const groupRowsByViewport = (rows) => {
|
|
3207
|
+
const result = {};
|
|
3208
|
+
for (const row of rows) {
|
|
3209
|
+
const rowsForViewport = result[row.viewPortId] || (result[row.viewPortId] = []);
|
|
3210
|
+
insertRow(rowsForViewport, row);
|
|
3211
|
+
}
|
|
3212
|
+
return result;
|
|
3213
|
+
};
|
|
3214
|
+
const createSchemaFromTableMetadata = ({
|
|
3215
|
+
columns,
|
|
3216
|
+
dataTypes,
|
|
3217
|
+
key,
|
|
3218
|
+
table
|
|
3219
|
+
}) => {
|
|
3220
|
+
return {
|
|
3221
|
+
table,
|
|
3222
|
+
columns: columns.map((col, idx) => ({
|
|
3223
|
+
name: col,
|
|
3224
|
+
serverDataType: dataTypes[idx]
|
|
3225
|
+
})),
|
|
3226
|
+
key
|
|
3227
|
+
};
|
|
3228
|
+
};
|
|
3229
|
+
const gapBetweenLastRowSentToClient = (lastRowsReturnedToClient, pendingUpdates, clientRange) => {
|
|
3230
|
+
const firstPendingUpdate = pendingUpdates.at(0);
|
|
3231
|
+
const lastPendingUpdate = pendingUpdates.at(-1);
|
|
3232
|
+
if (firstPendingUpdate && lastPendingUpdate) {
|
|
3233
|
+
const [firstRowIndex, lastRowIndex] = lastRowsReturnedToClient;
|
|
3234
|
+
if (lastRowIndex < firstPendingUpdate.rowIndex - 1 && clientRange.from < firstPendingUpdate.rowIndex) {
|
|
3235
|
+
return {
|
|
3236
|
+
from: Math.max(lastRowIndex + 1, clientRange.from),
|
|
3237
|
+
to: firstPendingUpdate.rowIndex
|
|
3238
|
+
};
|
|
3239
|
+
} else if (firstRowIndex > lastPendingUpdate.rowIndex + 1 && clientRange.to > lastPendingUpdate.rowIndex) {
|
|
3240
|
+
return {
|
|
3241
|
+
from: lastPendingUpdate.rowIndex + 1,
|
|
3242
|
+
to: Math.min(clientRange.to, firstRowIndex)
|
|
3243
|
+
};
|
|
3244
|
+
}
|
|
3245
|
+
}
|
|
3246
|
+
};
|
|
3247
|
+
|
|
3248
|
+
const NDJsonReader = (startIndex, jsonHandler, onEnd) => (response) => {
|
|
3249
|
+
if (response.ok && response.body) {
|
|
3250
|
+
const stream = response.body.getReader();
|
|
3251
|
+
const decoder = new TextDecoder();
|
|
3252
|
+
const matcher = /\r?\n/;
|
|
3253
|
+
let buf = "";
|
|
3254
|
+
let index = startIndex;
|
|
3255
|
+
const loop = () => stream.read().then(({ done, value }) => {
|
|
3256
|
+
if (done) {
|
|
3257
|
+
if (buf.length > 0) jsonHandler(index, JSON.parse(buf));
|
|
3258
|
+
onEnd();
|
|
3259
|
+
} else {
|
|
3260
|
+
const chunk = decoder.decode(value, {
|
|
3261
|
+
stream: true
|
|
3262
|
+
});
|
|
3263
|
+
buf += chunk;
|
|
3264
|
+
const jsonFragments = buf.split(matcher);
|
|
3265
|
+
buf = jsonFragments.pop() ?? "";
|
|
3266
|
+
for (const jsonFragment of jsonFragments) {
|
|
3267
|
+
jsonHandler(index, JSON.parse(jsonFragment));
|
|
3268
|
+
index += 1;
|
|
3269
|
+
}
|
|
3270
|
+
return loop();
|
|
3271
|
+
}
|
|
3272
|
+
});
|
|
3273
|
+
return loop();
|
|
3274
|
+
} else {
|
|
3275
|
+
throw Error(`response invalid ${response.status} ${response.statusText}`);
|
|
3276
|
+
}
|
|
3277
|
+
};
|
|
3278
|
+
const jsonToDataSourceRow = (rowIndex, json, columnMap) => {
|
|
3279
|
+
const dataSourceRow = [
|
|
3280
|
+
rowIndex,
|
|
3281
|
+
rowIndex,
|
|
3282
|
+
true,
|
|
3283
|
+
false,
|
|
3284
|
+
0,
|
|
3285
|
+
0,
|
|
3286
|
+
json.ric,
|
|
3287
|
+
0
|
|
3288
|
+
];
|
|
3289
|
+
for (const [column, colIdx] of Object.entries(columnMap)) {
|
|
3290
|
+
dataSourceRow[colIdx] = json[column];
|
|
3291
|
+
}
|
|
3292
|
+
return dataSourceRow;
|
|
3293
|
+
};
|
|
3294
|
+
const sortParamsToList = (sortDefs) => sortDefs.reduce(
|
|
3295
|
+
(list, { column, sortType }) => list.concat([column, sortType]),
|
|
3296
|
+
[]
|
|
3297
|
+
);
|
|
3298
|
+
const sortToQueryString = (sort) => `&sort=[${sortParamsToList(sort.sortDefs)}]`;
|
|
3299
|
+
const filterToQueryString = (vuuFilter) => `&filter=[${vuuFilter.filter}]`;
|
|
3300
|
+
|
|
3301
|
+
var __defProp$2 = Object.defineProperty;
|
|
3302
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3303
|
+
var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3304
|
+
const { SELECTED } = vuuUtils.metadataKeys;
|
|
3305
|
+
class MovingWindow {
|
|
3306
|
+
constructor({ from, to }) {
|
|
3307
|
+
__publicField$2(this, "data");
|
|
3308
|
+
__publicField$2(this, "rowCount", 0);
|
|
3309
|
+
__publicField$2(this, "range");
|
|
3310
|
+
__publicField$2(this, "setRowCount", (rowCount) => {
|
|
3311
|
+
if (rowCount < this.data.length) {
|
|
3312
|
+
this.data.length = rowCount;
|
|
3313
|
+
}
|
|
3314
|
+
this.rowCount = rowCount;
|
|
3315
|
+
});
|
|
3316
|
+
this.range = new vuuUtils.WindowRange(from, to);
|
|
3317
|
+
this.data = new Array(Math.max(0, to - from));
|
|
3318
|
+
this.rowCount = 0;
|
|
3319
|
+
}
|
|
3320
|
+
add(data) {
|
|
3321
|
+
const [index] = data;
|
|
3322
|
+
if (this.isWithinRange(index)) {
|
|
3323
|
+
const internalIndex = index - this.range.from;
|
|
3324
|
+
this.data[internalIndex] = data;
|
|
3325
|
+
if (data[SELECTED]) {
|
|
3326
|
+
const previousRow = this.data[internalIndex - 1];
|
|
3327
|
+
if (vuuUtils.isRowSelectedLast(previousRow)) {
|
|
3328
|
+
this.data[internalIndex - 1] = previousRow.slice();
|
|
3329
|
+
this.data[internalIndex - 1][SELECTED] -= 4;
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
getAtIndex(index) {
|
|
3335
|
+
return this.range.isWithin(index) && this.data[index - this.range.from] != null ? this.data[index - this.range.from] : void 0;
|
|
3336
|
+
}
|
|
3337
|
+
isWithinRange(index) {
|
|
3338
|
+
return this.range.isWithin(index);
|
|
3339
|
+
}
|
|
3340
|
+
setRange({ from, to }) {
|
|
3341
|
+
if (from !== this.range.from || to !== this.range.to) {
|
|
3342
|
+
const [overlapFrom, overlapTo] = this.range.overlap(from, to);
|
|
3343
|
+
const newData = new Array(Math.max(0, to - from));
|
|
3344
|
+
for (let i = overlapFrom; i < overlapTo; i++) {
|
|
3345
|
+
const data = this.getAtIndex(i);
|
|
3346
|
+
if (data) {
|
|
3347
|
+
const index = i - from;
|
|
3348
|
+
newData[index] = data;
|
|
3349
|
+
}
|
|
3350
|
+
}
|
|
3351
|
+
this.data = newData;
|
|
3352
|
+
this.range.from = from;
|
|
3353
|
+
this.range.to = to;
|
|
3354
|
+
}
|
|
3355
|
+
}
|
|
3356
|
+
getSelectedRows() {
|
|
3357
|
+
return this.data.filter((row) => row[SELECTED] !== 0);
|
|
3358
|
+
}
|
|
3359
|
+
}
|
|
3360
|
+
|
|
3361
|
+
var __defProp$1 = Object.defineProperty;
|
|
3362
|
+
var __typeError$1 = (msg) => {
|
|
3363
|
+
throw TypeError(msg);
|
|
3364
|
+
};
|
|
3365
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3366
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3367
|
+
var __accessCheck$1 = (obj, member, msg) => member.has(obj) || __typeError$1("Cannot " + msg);
|
|
3368
|
+
var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
3369
|
+
var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
3370
|
+
var _columnMap, _dataWindow;
|
|
3371
|
+
const _RestDataSource = class _RestDataSource extends vuuUtils.BaseDataSource {
|
|
3372
|
+
constructor(props) {
|
|
3373
|
+
super(props);
|
|
3374
|
+
__privateAdd$1(this, _columnMap, vuuUtils.buildColumnMap([
|
|
3375
|
+
"bbg",
|
|
3376
|
+
"currency",
|
|
3377
|
+
"description",
|
|
3378
|
+
"exchange",
|
|
3379
|
+
"ric",
|
|
3380
|
+
"lotSize"
|
|
3381
|
+
]));
|
|
3382
|
+
__privateAdd$1(this, _dataWindow, new MovingWindow(vuuUtils.NULL_RANGE));
|
|
3383
|
+
__publicField$1(this, "groupBy", []);
|
|
3384
|
+
__publicField$1(this, "selectedRowsCount", 0);
|
|
3385
|
+
__publicField$1(this, "status", "initialising");
|
|
3386
|
+
__publicField$1(this, "table");
|
|
3387
|
+
__publicField$1(this, "fetchData", async () => {
|
|
3388
|
+
const { recordCount } = await this.fetchMetaData();
|
|
3389
|
+
const pageCount = Math.ceil(recordCount / this.pageSize);
|
|
3390
|
+
this.emit("page-count", pageCount);
|
|
3391
|
+
const start = performance.now();
|
|
3392
|
+
const allDone = () => {
|
|
3393
|
+
const end = performance.now();
|
|
3394
|
+
console.log(
|
|
3395
|
+
`processing ${__privateGet$1(this, _dataWindow).data.length} rows took ${end - start}ms`
|
|
3396
|
+
);
|
|
3397
|
+
this._clientCallback?.({
|
|
3398
|
+
clientViewportId: this.viewport,
|
|
3399
|
+
mode: "update",
|
|
3400
|
+
range: this._range,
|
|
3401
|
+
rows: __privateGet$1(this, _dataWindow).data,
|
|
3402
|
+
size: recordCount,
|
|
3403
|
+
type: "viewport-update"
|
|
3404
|
+
});
|
|
3405
|
+
};
|
|
3406
|
+
console.log(`base ${_RestDataSource.api}`);
|
|
3407
|
+
fetch(this.dataUrl, {
|
|
3408
|
+
headers: this.httpHeaders,
|
|
3409
|
+
mode: "cors"
|
|
3410
|
+
}).then(
|
|
3411
|
+
NDJsonReader(
|
|
3412
|
+
this._range.from,
|
|
3413
|
+
(index, json) => __privateGet$1(this, _dataWindow).add(
|
|
3414
|
+
jsonToDataSourceRow(index, json, __privateGet$1(this, _columnMap))
|
|
3415
|
+
),
|
|
3416
|
+
allDone
|
|
3417
|
+
)
|
|
3418
|
+
);
|
|
3419
|
+
});
|
|
3420
|
+
__publicField$1(this, "fetchMetaData", async () => new Promise((resolve, reject) => {
|
|
3421
|
+
fetch(this.metaDataUrl, {
|
|
3422
|
+
headers: this.httpHeaders,
|
|
3423
|
+
mode: "cors"
|
|
3424
|
+
}).then((response) => {
|
|
3425
|
+
if (response.ok) {
|
|
3426
|
+
resolve(response.json());
|
|
3427
|
+
} else {
|
|
3428
|
+
reject(response.status);
|
|
3429
|
+
}
|
|
3430
|
+
});
|
|
3431
|
+
}));
|
|
3432
|
+
__publicField$1(this, "applyEdit", async () => {
|
|
3433
|
+
return "Method not implemented";
|
|
3434
|
+
});
|
|
3435
|
+
__publicField$1(this, "openTreeNode", () => {
|
|
3436
|
+
throw new Error("openTreeNode, Method not implemented.");
|
|
3437
|
+
});
|
|
3438
|
+
__publicField$1(this, "closeTreeNode", () => {
|
|
3439
|
+
throw new Error("closeTreeNode, Method not implemented.");
|
|
3440
|
+
});
|
|
3441
|
+
__publicField$1(this, "remoteProcedureCall", async () => "Method not implemented");
|
|
3442
|
+
__publicField$1(this, "menuRpcCall", async () => {
|
|
3443
|
+
return "Method not supported";
|
|
3444
|
+
});
|
|
3445
|
+
__publicField$1(this, "rpcCall", async () => {
|
|
3446
|
+
return "Method not supported";
|
|
3447
|
+
});
|
|
3448
|
+
__publicField$1(this, "select", () => {
|
|
3449
|
+
throw new Error("remoteProcedureCall, Method not implemented.");
|
|
3450
|
+
});
|
|
3451
|
+
const { table } = props;
|
|
3452
|
+
if (!table) throw Error("RestDataSource constructor called without table");
|
|
3453
|
+
this.table = table;
|
|
3454
|
+
}
|
|
3455
|
+
async subscribe(subscribeProps, callback) {
|
|
3456
|
+
super.subscribe(subscribeProps, callback);
|
|
3457
|
+
console.log(`subscribe ${JSON.stringify(subscribeProps, null, 2)}`);
|
|
3458
|
+
this.rangeRequest(this._range);
|
|
3459
|
+
}
|
|
3460
|
+
unsubscribe() {
|
|
3461
|
+
console.log("unsubscribe");
|
|
3462
|
+
}
|
|
3463
|
+
get pageSize() {
|
|
3464
|
+
return this._range.to - this._range.from;
|
|
3465
|
+
}
|
|
3466
|
+
static get api() {
|
|
3467
|
+
return this._api;
|
|
3468
|
+
}
|
|
3469
|
+
static set api(url) {
|
|
3470
|
+
this._api = url;
|
|
3471
|
+
}
|
|
3472
|
+
get url() {
|
|
3473
|
+
return `${_RestDataSource.api}/${this.table.table}`;
|
|
3474
|
+
}
|
|
3475
|
+
get dataUrl() {
|
|
3476
|
+
const { from, to } = this._range;
|
|
3477
|
+
return `${this.url}?origin=${from}&limit=${to - from}${this.queryStringParameters}`;
|
|
3478
|
+
}
|
|
3479
|
+
get httpHeaders() {
|
|
3480
|
+
return void 0;
|
|
3481
|
+
}
|
|
3482
|
+
get metaDataUrl() {
|
|
3483
|
+
return `${this.url}/summary`;
|
|
3484
|
+
}
|
|
3485
|
+
get queryStringParameters() {
|
|
3486
|
+
const params = [];
|
|
3487
|
+
if (vuuUtils.hasSort(this._config)) {
|
|
3488
|
+
params.push(sortToQueryString(this._config.sort));
|
|
3489
|
+
}
|
|
3490
|
+
if (vuuUtils.hasFilter(this._config)) {
|
|
3491
|
+
params.push(filterToQueryString(this._config.filterSpec));
|
|
3492
|
+
}
|
|
3493
|
+
return params.join("");
|
|
3494
|
+
}
|
|
3495
|
+
get title() {
|
|
3496
|
+
return this._title ?? `${this.table.module} ${this.table.table}`;
|
|
3497
|
+
}
|
|
3498
|
+
set title(title) {
|
|
3499
|
+
this._title = title;
|
|
3500
|
+
}
|
|
3501
|
+
rangeRequest(range) {
|
|
3502
|
+
console.log(`set range ${JSON.stringify(range)}`);
|
|
3503
|
+
__privateGet$1(this, _dataWindow).setRange(range);
|
|
3504
|
+
this.fetchData();
|
|
3505
|
+
}
|
|
3506
|
+
get config() {
|
|
3507
|
+
return super.config;
|
|
3508
|
+
}
|
|
3509
|
+
set config(config) {
|
|
3510
|
+
const previousConfig = this._config;
|
|
3511
|
+
super.config = config;
|
|
3512
|
+
if (this._config !== previousConfig) {
|
|
3513
|
+
this.fetchData();
|
|
3514
|
+
}
|
|
3515
|
+
}
|
|
3516
|
+
sendRowsToClient() {
|
|
3517
|
+
console.log(`send rows to client`);
|
|
3518
|
+
}
|
|
3519
|
+
};
|
|
3520
|
+
_columnMap = new WeakMap();
|
|
3521
|
+
_dataWindow = new WeakMap();
|
|
3522
|
+
__publicField$1(_RestDataSource, "_api", "/api");
|
|
3523
|
+
let RestDataSource = _RestDataSource;
|
|
3524
|
+
|
|
3525
|
+
var __defProp = Object.defineProperty;
|
|
3526
|
+
var __typeError = (msg) => {
|
|
3527
|
+
throw TypeError(msg);
|
|
3528
|
+
};
|
|
3529
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3530
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3531
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
3532
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
3533
|
+
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);
|
|
3534
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
3535
|
+
var _pendingVisualLink, _links, _menu, _optimize, _selectedRowsCount, _status, _tableSchema;
|
|
3536
|
+
const { info, infoEnabled } = vuuUtils.logger("VuuDataSource");
|
|
3537
|
+
class VuuDataSource extends vuuUtils.BaseDataSource {
|
|
3538
|
+
constructor(props) {
|
|
3539
|
+
super(props);
|
|
3540
|
+
__publicField(this, "bufferSize");
|
|
3541
|
+
__publicField(this, "server", null);
|
|
3542
|
+
__publicField(this, "rangeRequest");
|
|
3543
|
+
__privateAdd(this, _pendingVisualLink);
|
|
3544
|
+
__privateAdd(this, _links);
|
|
3545
|
+
__privateAdd(this, _menu);
|
|
3546
|
+
__privateAdd(this, _optimize, "throttle");
|
|
3547
|
+
__privateAdd(this, _selectedRowsCount, 0);
|
|
3548
|
+
__privateAdd(this, _status, "initialising");
|
|
3549
|
+
__privateAdd(this, _tableSchema);
|
|
3550
|
+
__publicField(this, "table");
|
|
3551
|
+
__publicField(this, "handleMessageFromServer", (message) => {
|
|
3552
|
+
if (message.type === "subscribed") {
|
|
3553
|
+
__privateSet(this, _status, "subscribed");
|
|
3554
|
+
this.tableSchema = message.tableSchema;
|
|
3555
|
+
this._clientCallback?.(message);
|
|
3556
|
+
if (__privateGet(this, _pendingVisualLink)) {
|
|
3557
|
+
this.visualLink = __privateGet(this, _pendingVisualLink);
|
|
3558
|
+
__privateSet(this, _pendingVisualLink, void 0);
|
|
3559
|
+
}
|
|
3560
|
+
this.emit("subscribed", message);
|
|
3561
|
+
} else if (message.type === "disabled") {
|
|
3562
|
+
__privateSet(this, _status, "disabled");
|
|
3563
|
+
} else if (message.type === "enabled") {
|
|
3564
|
+
__privateSet(this, _status, "enabled");
|
|
3565
|
+
} else if (isDataSourceConfigMessage(message)) {
|
|
3566
|
+
return;
|
|
3567
|
+
} else if (message.type === "debounce-begin") {
|
|
3568
|
+
this.optimize = "debounce";
|
|
3569
|
+
} else {
|
|
3570
|
+
if (message.type === "viewport-update" && message.size !== void 0 && message.size !== this.size) {
|
|
3571
|
+
this.size = message.size;
|
|
3572
|
+
this.emit("resize", message.size);
|
|
3573
|
+
} else if (message.type === "viewport-clear") {
|
|
3574
|
+
this.size = 0;
|
|
3575
|
+
this.emit("resize", 0);
|
|
3576
|
+
}
|
|
3577
|
+
if (this.isAwaitingConfirmationOfConfigChange) {
|
|
3578
|
+
this.confirmConfigChange();
|
|
3579
|
+
}
|
|
3580
|
+
if (vuuUtils.isViewportMenusAction(message)) {
|
|
3581
|
+
__privateSet(this, _menu, message.menu);
|
|
3582
|
+
} else if (vuuUtils.isVisualLinksAction(message)) {
|
|
3583
|
+
__privateSet(this, _links, message.links);
|
|
3584
|
+
} else {
|
|
3585
|
+
if (infoEnabled && message.type === "viewport-update") {
|
|
3586
|
+
info(
|
|
3587
|
+
`handleMessageFromServer<viewport-update> range (${message.range?.from}:${message.range?.to}) rows ${message.rows?.at(0)?.[0]} - ${message.rows?.at(-1)?.[0]}`
|
|
3588
|
+
);
|
|
3589
|
+
}
|
|
3590
|
+
this._clientCallback?.(message);
|
|
3591
|
+
}
|
|
3592
|
+
if (this.optimize === "debounce") {
|
|
3593
|
+
this.revertDebounce();
|
|
3594
|
+
}
|
|
3595
|
+
}
|
|
3596
|
+
});
|
|
3597
|
+
__publicField(this, "revertDebounce", vuuUtils.debounce(() => {
|
|
3598
|
+
this.optimize = "throttle";
|
|
3599
|
+
}, 100));
|
|
3600
|
+
__publicField(this, "rawRangeRequest", (range) => {
|
|
3601
|
+
if (this.viewport && this.server) {
|
|
3602
|
+
this.server.send({
|
|
3603
|
+
viewport: this.viewport,
|
|
3604
|
+
type: "setViewRange",
|
|
3605
|
+
range
|
|
3606
|
+
});
|
|
3607
|
+
}
|
|
3608
|
+
});
|
|
3609
|
+
__publicField(this, "debounceRangeRequest", vuuUtils.debounce((range) => {
|
|
3610
|
+
if (this.viewport && this.server) {
|
|
3611
|
+
this.server.send({
|
|
3612
|
+
viewport: this.viewport,
|
|
3613
|
+
type: "setViewRange",
|
|
3614
|
+
range
|
|
3615
|
+
});
|
|
3616
|
+
}
|
|
3617
|
+
}, 50));
|
|
3618
|
+
__publicField(this, "throttleRangeRequest", vuuUtils.throttle((range) => {
|
|
3619
|
+
if (this.viewport && this.server) {
|
|
3620
|
+
this.server.send({
|
|
3621
|
+
viewport: this.viewport,
|
|
3622
|
+
type: "setViewRange",
|
|
3623
|
+
range
|
|
3624
|
+
});
|
|
3625
|
+
}
|
|
3626
|
+
}, 80));
|
|
3627
|
+
const { bufferSize = 100, table, visualLink } = props;
|
|
3628
|
+
if (!table)
|
|
3629
|
+
throw Error("RemoteDataSource constructor called without table");
|
|
3630
|
+
this.bufferSize = bufferSize;
|
|
3631
|
+
this.table = table;
|
|
3632
|
+
__privateSet(this, _pendingVisualLink, visualLink);
|
|
3633
|
+
this.rangeRequest = this.rawRangeRequest;
|
|
3634
|
+
}
|
|
3635
|
+
async subscribe(subscribeProps, callback) {
|
|
3636
|
+
super.subscribe(subscribeProps, callback);
|
|
3637
|
+
const {
|
|
3638
|
+
selectedIndexValues,
|
|
3639
|
+
viewport = this.viewport || (this.viewport = vuuUtils.uuid())
|
|
3640
|
+
} = subscribeProps;
|
|
3641
|
+
if (__privateGet(this, _status) === "disabled" || __privateGet(this, _status) === "disabling") {
|
|
3642
|
+
this.enable(callback);
|
|
3643
|
+
return;
|
|
3644
|
+
}
|
|
3645
|
+
if (__privateGet(this, _status) !== "initialising" && __privateGet(this, _status) !== "unsubscribed") {
|
|
3646
|
+
return;
|
|
3647
|
+
}
|
|
3648
|
+
__privateSet(this, _status, "subscribing");
|
|
3649
|
+
__privateSet(this, _selectedRowsCount, vuuUtils.selectionCount(selectedIndexValues));
|
|
3650
|
+
this.server = await ConnectionManager$1.serverAPI;
|
|
3651
|
+
const { bufferSize } = this;
|
|
3652
|
+
const dataSourceConfig = vuuUtils.combineFilters(this.config);
|
|
3653
|
+
this.server?.subscribe(
|
|
3654
|
+
{
|
|
3655
|
+
...dataSourceConfig,
|
|
3656
|
+
bufferSize,
|
|
3657
|
+
range: this._range,
|
|
3658
|
+
selectedIndexValues,
|
|
3659
|
+
table: this.table,
|
|
3660
|
+
title: this._title,
|
|
3661
|
+
viewport
|
|
3662
|
+
},
|
|
3663
|
+
this.handleMessageFromServer
|
|
3664
|
+
);
|
|
3665
|
+
}
|
|
3666
|
+
unsubscribe() {
|
|
3667
|
+
if (__privateGet(this, _status) !== "unsubscribed") {
|
|
3668
|
+
info?.(`unsubscribe #${this.viewport}`);
|
|
3669
|
+
if (this.viewport) {
|
|
3670
|
+
this.server?.unsubscribe(this.viewport);
|
|
3671
|
+
this.emit("unsubscribed", this.viewport);
|
|
3672
|
+
}
|
|
3673
|
+
this.server?.destroy(this.viewport);
|
|
3674
|
+
this.server = null;
|
|
3675
|
+
this.removeAllListeners();
|
|
3676
|
+
__privateSet(this, _status, "unsubscribed");
|
|
3677
|
+
this.viewport = "";
|
|
3678
|
+
this.range = vuuUtils.Range(0, 0);
|
|
3679
|
+
}
|
|
3680
|
+
}
|
|
3681
|
+
suspend() {
|
|
3682
|
+
if (__privateGet(this, _status) !== "unsubscribed") {
|
|
3683
|
+
info?.(`suspend #${this.viewport}, current status ${__privateGet(this, _status)}`);
|
|
3684
|
+
if (this.viewport) {
|
|
3685
|
+
__privateSet(this, _status, "suspended");
|
|
3686
|
+
this.server?.send({
|
|
3687
|
+
type: "suspend",
|
|
3688
|
+
viewport: this.viewport
|
|
3689
|
+
});
|
|
3690
|
+
this.emit("suspended", this.viewport);
|
|
3691
|
+
}
|
|
3692
|
+
}
|
|
3693
|
+
}
|
|
3694
|
+
resume(callback) {
|
|
3695
|
+
const isDisabled = __privateGet(this, _status).startsWith("disabl");
|
|
3696
|
+
const isSuspended = __privateGet(this, _status) === "suspended";
|
|
3697
|
+
info?.(`resume #${this.viewport}, current status ${__privateGet(this, _status)}`);
|
|
3698
|
+
if (callback) {
|
|
3699
|
+
this._clientCallback = callback;
|
|
3700
|
+
}
|
|
3701
|
+
if (this.viewport) {
|
|
3702
|
+
if (isDisabled) {
|
|
3703
|
+
this.enable();
|
|
3704
|
+
} else if (isSuspended) {
|
|
3705
|
+
this.server?.send({
|
|
3706
|
+
type: "resume",
|
|
3707
|
+
viewport: this.viewport
|
|
3708
|
+
});
|
|
3709
|
+
__privateSet(this, _status, "subscribed");
|
|
3710
|
+
this.emit("resumed", this.viewport);
|
|
3711
|
+
}
|
|
3712
|
+
}
|
|
3713
|
+
}
|
|
3714
|
+
disable() {
|
|
3715
|
+
info?.(`disable #${this.viewport}, current status ${__privateGet(this, _status)}`);
|
|
3716
|
+
if (this.viewport) {
|
|
3717
|
+
__privateSet(this, _status, "disabling");
|
|
3718
|
+
this.server?.send({
|
|
3719
|
+
viewport: this.viewport,
|
|
3720
|
+
type: "disable"
|
|
3721
|
+
});
|
|
3722
|
+
this.emit("disabled", this.viewport);
|
|
3723
|
+
}
|
|
3724
|
+
}
|
|
3725
|
+
enable(callback) {
|
|
3726
|
+
info?.(`enable #${this.viewport}, current status ${__privateGet(this, _status)}`);
|
|
3727
|
+
if (this.viewport && (__privateGet(this, _status) === "disabled" || __privateGet(this, _status) === "disabling")) {
|
|
3728
|
+
__privateSet(this, _status, "enabling");
|
|
3729
|
+
if (callback) {
|
|
3730
|
+
this._clientCallback = callback;
|
|
3731
|
+
}
|
|
3732
|
+
this.server?.send({
|
|
3733
|
+
viewport: this.viewport,
|
|
3734
|
+
type: "enable"
|
|
3735
|
+
});
|
|
3736
|
+
this.emit("enabled", this.viewport);
|
|
3737
|
+
}
|
|
3738
|
+
}
|
|
3739
|
+
select(selected) {
|
|
3740
|
+
__privateSet(this, _selectedRowsCount, vuuUtils.selectionCount(selected));
|
|
3741
|
+
if (this.viewport) {
|
|
3742
|
+
this.server?.send({
|
|
3743
|
+
viewport: this.viewport,
|
|
3744
|
+
type: "select",
|
|
3745
|
+
selected
|
|
3746
|
+
});
|
|
3747
|
+
this.emit("row-selection", selected, __privateGet(this, _selectedRowsCount));
|
|
3748
|
+
}
|
|
3749
|
+
}
|
|
3750
|
+
openTreeNode(keyOrIndex) {
|
|
3751
|
+
if (this.viewport) {
|
|
3752
|
+
const [key, index] = typeof keyOrIndex === "string" ? [keyOrIndex] : [void 0, keyOrIndex];
|
|
3753
|
+
this.server?.send({
|
|
3754
|
+
index,
|
|
3755
|
+
key,
|
|
3756
|
+
type: "openTreeNode",
|
|
3757
|
+
viewport: this.viewport
|
|
3758
|
+
});
|
|
3759
|
+
}
|
|
3760
|
+
}
|
|
3761
|
+
closeTreeNode(keyOrIndex) {
|
|
3762
|
+
if (this.viewport) {
|
|
3763
|
+
const [key, index] = typeof keyOrIndex === "string" ? [keyOrIndex] : [void 0, keyOrIndex];
|
|
3764
|
+
this.server?.send({
|
|
3765
|
+
index,
|
|
3766
|
+
key,
|
|
3767
|
+
type: "closeTreeNode",
|
|
3768
|
+
viewport: this.viewport
|
|
3769
|
+
});
|
|
3770
|
+
}
|
|
3771
|
+
}
|
|
3772
|
+
get tableSchema() {
|
|
3773
|
+
return __privateGet(this, _tableSchema);
|
|
3774
|
+
}
|
|
3775
|
+
set tableSchema(tableSchema) {
|
|
3776
|
+
__privateSet(this, _tableSchema, tableSchema);
|
|
3777
|
+
}
|
|
3778
|
+
get links() {
|
|
3779
|
+
return __privateGet(this, _links);
|
|
3780
|
+
}
|
|
3781
|
+
get menu() {
|
|
3782
|
+
return __privateGet(this, _menu);
|
|
3783
|
+
}
|
|
3784
|
+
get status() {
|
|
3785
|
+
return __privateGet(this, _status);
|
|
3786
|
+
}
|
|
3787
|
+
get optimize() {
|
|
3788
|
+
return __privateGet(this, _optimize);
|
|
3789
|
+
}
|
|
3790
|
+
set optimize(optimize) {
|
|
3791
|
+
if (optimize !== __privateGet(this, _optimize)) {
|
|
3792
|
+
__privateSet(this, _optimize, optimize);
|
|
3793
|
+
switch (optimize) {
|
|
3794
|
+
case "none":
|
|
3795
|
+
this.rangeRequest = this.rawRangeRequest;
|
|
3796
|
+
break;
|
|
3797
|
+
case "debounce":
|
|
3798
|
+
this.rangeRequest = this.debounceRangeRequest;
|
|
3799
|
+
break;
|
|
3800
|
+
case "throttle":
|
|
3801
|
+
this.rangeRequest = this.throttleRangeRequest;
|
|
3802
|
+
break;
|
|
3803
|
+
}
|
|
3804
|
+
this.emit("optimize", optimize);
|
|
3805
|
+
}
|
|
3806
|
+
}
|
|
3807
|
+
get selectedRowsCount() {
|
|
3808
|
+
return __privateGet(this, _selectedRowsCount);
|
|
3809
|
+
}
|
|
3810
|
+
get config() {
|
|
3811
|
+
return super.config;
|
|
3812
|
+
}
|
|
3813
|
+
set config(config) {
|
|
3814
|
+
if (config !== this.config) {
|
|
3815
|
+
super.config = config;
|
|
3816
|
+
this.server?.send({
|
|
3817
|
+
viewport: this.viewport,
|
|
3818
|
+
type: "config",
|
|
3819
|
+
config: vuuUtils.combineFilters(this._config)
|
|
3820
|
+
});
|
|
3821
|
+
}
|
|
3822
|
+
}
|
|
3823
|
+
set impendingConfig(config) {
|
|
3824
|
+
if (config !== this.config) {
|
|
3825
|
+
super.impendingConfig = config;
|
|
3826
|
+
this.server?.send({
|
|
3827
|
+
viewport: this.viewport,
|
|
3828
|
+
type: "config",
|
|
3829
|
+
config: vuuUtils.combineFilters(this.config)
|
|
3830
|
+
});
|
|
3831
|
+
}
|
|
3832
|
+
}
|
|
3833
|
+
get groupBy() {
|
|
3834
|
+
return this._config.groupBy;
|
|
3835
|
+
}
|
|
3836
|
+
set groupBy(groupBy) {
|
|
3837
|
+
if (vuuUtils.itemsOrOrderChanged(this.groupBy, groupBy)) {
|
|
3838
|
+
const wasGrouped = this.groupBy.length > 0;
|
|
3839
|
+
this.impendingConfig = {
|
|
3840
|
+
...this._config,
|
|
3841
|
+
groupBy
|
|
3842
|
+
};
|
|
3843
|
+
if (!wasGrouped && groupBy.length > 0 && this.viewport) {
|
|
3844
|
+
this._clientCallback?.({
|
|
3845
|
+
clientViewportId: this.viewport,
|
|
3846
|
+
mode: "batch",
|
|
3847
|
+
type: "viewport-update",
|
|
3848
|
+
size: 0,
|
|
3849
|
+
rows: []
|
|
3850
|
+
});
|
|
3851
|
+
}
|
|
3852
|
+
}
|
|
3853
|
+
}
|
|
3854
|
+
get title() {
|
|
3855
|
+
return super.title || `${this.table.module} ${this.table.table}`;
|
|
3856
|
+
}
|
|
3857
|
+
set title(title) {
|
|
3858
|
+
super.title = title;
|
|
3859
|
+
if (this.viewport && title) {
|
|
3860
|
+
this.server?.send({
|
|
3861
|
+
type: "setTitle",
|
|
3862
|
+
title,
|
|
3863
|
+
viewport: this.viewport
|
|
3864
|
+
});
|
|
3865
|
+
}
|
|
3866
|
+
}
|
|
3867
|
+
get visualLink() {
|
|
3868
|
+
return this._config.visualLink;
|
|
3869
|
+
}
|
|
3870
|
+
set visualLink(visualLink) {
|
|
3871
|
+
this._config = {
|
|
3872
|
+
...this._config,
|
|
3873
|
+
visualLink
|
|
3874
|
+
};
|
|
3875
|
+
if (visualLink) {
|
|
3876
|
+
const {
|
|
3877
|
+
parentClientVpId,
|
|
3878
|
+
link: { fromColumn, toColumn }
|
|
3879
|
+
} = visualLink;
|
|
3880
|
+
if (this.viewport) {
|
|
3881
|
+
this.server?.rpcCall({
|
|
3882
|
+
childColumnName: fromColumn,
|
|
3883
|
+
childVpId: this.viewport,
|
|
3884
|
+
parentColumnName: toColumn,
|
|
3885
|
+
parentVpId: parentClientVpId,
|
|
3886
|
+
type: "CREATE_VISUAL_LINK"
|
|
3887
|
+
}).then((response) => {
|
|
3888
|
+
this.emit("visual-link-created", response);
|
|
3889
|
+
});
|
|
3890
|
+
}
|
|
3891
|
+
} else {
|
|
3892
|
+
if (this.viewport) {
|
|
3893
|
+
this.server?.rpcCall({
|
|
3894
|
+
type: "REMOVE_VISUAL_LINK",
|
|
3895
|
+
childVpId: this.viewport
|
|
3896
|
+
}).then(() => {
|
|
3897
|
+
this.emit("visual-link-removed");
|
|
3898
|
+
});
|
|
3899
|
+
}
|
|
3900
|
+
}
|
|
3901
|
+
this.emit("config", this._config, this.range);
|
|
3902
|
+
}
|
|
3903
|
+
async remoteProcedureCall() {
|
|
3904
|
+
return Promise.reject();
|
|
3905
|
+
}
|
|
3906
|
+
/** @deprecated */
|
|
3907
|
+
async rpcCall(rpcRequest) {
|
|
3908
|
+
if (this.viewport && this.server) {
|
|
3909
|
+
return this.server?.rpcCall({
|
|
3910
|
+
...rpcRequest,
|
|
3911
|
+
vpId: this.viewport
|
|
3912
|
+
});
|
|
3913
|
+
} else {
|
|
3914
|
+
throw Error(`rpcCall server or viewport are undefined`);
|
|
3915
|
+
}
|
|
3916
|
+
}
|
|
3917
|
+
/** @deprecated */
|
|
3918
|
+
async menuRpcCall(rpcRequest) {
|
|
3919
|
+
if (this.viewport) {
|
|
3920
|
+
return this.server?.rpcCall({
|
|
3921
|
+
...rpcRequest,
|
|
3922
|
+
vpId: this.viewport
|
|
3923
|
+
});
|
|
3924
|
+
}
|
|
3925
|
+
}
|
|
3926
|
+
applyEdit(rowKey, columnName, value) {
|
|
3927
|
+
return this.menuRpcCall(vuuUtils.vuuEditCellRequest(rowKey, columnName, value)).then(
|
|
3928
|
+
(response) => {
|
|
3929
|
+
if (response?.error) {
|
|
3930
|
+
return response.error;
|
|
3931
|
+
} else {
|
|
3932
|
+
return true;
|
|
3933
|
+
}
|
|
3934
|
+
}
|
|
3935
|
+
);
|
|
3936
|
+
}
|
|
3937
|
+
insertRow(rowKey, data) {
|
|
3938
|
+
return this.menuRpcCall(vuuUtils.vuuAddRowRequest(rowKey, data)).then((response) => {
|
|
3939
|
+
if (response?.error) {
|
|
3940
|
+
return response.error;
|
|
3941
|
+
} else {
|
|
3942
|
+
return true;
|
|
3943
|
+
}
|
|
3944
|
+
});
|
|
3945
|
+
}
|
|
3946
|
+
deleteRow(rowKey) {
|
|
3947
|
+
return this.menuRpcCall(vuuUtils.vuuDeleteRowRequest(rowKey)).then((response) => {
|
|
3948
|
+
if (response?.error) {
|
|
3949
|
+
return response.error;
|
|
3950
|
+
} else {
|
|
3951
|
+
return true;
|
|
3952
|
+
}
|
|
3953
|
+
});
|
|
3954
|
+
}
|
|
3955
|
+
}
|
|
3956
|
+
_pendingVisualLink = new WeakMap();
|
|
3957
|
+
_links = new WeakMap();
|
|
3958
|
+
_menu = new WeakMap();
|
|
3959
|
+
_optimize = new WeakMap();
|
|
3960
|
+
_selectedRowsCount = new WeakMap();
|
|
3961
|
+
_status = new WeakMap();
|
|
3962
|
+
_tableSchema = new WeakMap();
|
|
3963
|
+
|
|
3964
|
+
exports.ConnectionManager = ConnectionManager$1;
|
|
3965
|
+
exports.RestDataSource = RestDataSource;
|
|
3966
|
+
exports.VuuDataSource = VuuDataSource;
|
|
3967
|
+
exports.authenticate = authenticate;
|
|
3968
|
+
exports.connectionId = connectionId;
|
|
3969
|
+
exports.createSchemaFromTableMetadata = createSchemaFromTableMetadata;
|
|
3970
|
+
exports.gapBetweenLastRowSentToClient = gapBetweenLastRowSentToClient;
|
|
3971
|
+
exports.getFirstAndLastRows = getFirstAndLastRows;
|
|
3972
|
+
exports.groupRowsByViewport = groupRowsByViewport;
|
|
3973
|
+
exports.isDataSourceConfigMessage = isDataSourceConfigMessage;
|
|
3974
|
+
exports.isSizeOnly = isSizeOnly;
|
|
3975
|
+
exports.isVuuRpcRequest = isVuuRpcRequest;
|
|
3976
|
+
exports.msgType = msgType;
|
|
3977
|
+
exports.shouldMessageBeRoutedToDataSource = shouldMessageBeRoutedToDataSource;
|
|
3978
|
+
exports.stripRequestId = stripRequestId;
|
|
3979
|
+
exports.toDataSourceConfig = toDataSourceConfig;
|
|
29
3980
|
//# sourceMappingURL=index.js.map
|