@vuu-ui/vuu-data-remote 3.0.0-beta.3 → 3.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/package.json +18 -13
  2. package/src/ConnectionManager.mjs +134 -0
  3. package/src/DedicatedWorker.mjs +44 -0
  4. package/src/LostConnectionHandler.mjs +89 -0
  5. package/src/VuuAuthProvider.mjs +78 -0
  6. package/src/VuuAuthenticator.mjs +36 -0
  7. package/src/VuuDataSource.mjs +573 -0
  8. package/src/WebSocketConnection.mjs +149 -0
  9. package/src/authenticate.mjs +50 -0
  10. package/src/constants.mjs +45 -0
  11. package/src/data-source.mjs +57 -0
  12. package/src/index.mjs +11 -0
  13. package/src/message-utils.mjs +55 -0
  14. package/src/server-proxy/array-backed-moving-window.mjs +172 -0
  15. package/src/server-proxy/messages.mjs +34 -0
  16. package/src/server-proxy/server-proxy.mjs +817 -0
  17. package/src/server-proxy/viewport.mjs +608 -0
  18. package/src/worker.mjs +65 -0
  19. package/cjs/ConnectionManager.js +0 -181
  20. package/cjs/ConnectionManager.js.map +0 -1
  21. package/cjs/DedicatedWorker.js +0 -61
  22. package/cjs/DedicatedWorker.js.map +0 -1
  23. package/cjs/LostConnectionHandler.js +0 -83
  24. package/cjs/LostConnectionHandler.js.map +0 -1
  25. package/cjs/VuuAuthProvider.js +0 -87
  26. package/cjs/VuuAuthProvider.js.map +0 -1
  27. package/cjs/VuuAuthenticator.js +0 -57
  28. package/cjs/VuuAuthenticator.js.map +0 -1
  29. package/cjs/VuuDataSource.js +0 -689
  30. package/cjs/VuuDataSource.js.map +0 -1
  31. package/cjs/WebSocketConnection.js +0 -20
  32. package/cjs/WebSocketConnection.js.map +0 -1
  33. package/cjs/authenticate.js +0 -64
  34. package/cjs/authenticate.js.map +0 -1
  35. package/cjs/constants.js +0 -50
  36. package/cjs/constants.js.map +0 -1
  37. package/cjs/data-source.js +0 -49
  38. package/cjs/data-source.js.map +0 -1
  39. package/cjs/index.js +0 -38
  40. package/cjs/index.js.map +0 -1
  41. package/cjs/inlined-worker.js +0 -2798
  42. package/cjs/inlined-worker.js.map +0 -1
  43. package/cjs/message-utils.js +0 -86
  44. package/cjs/message-utils.js.map +0 -1
  45. package/esm/ConnectionManager.js +0 -179
  46. package/esm/ConnectionManager.js.map +0 -1
  47. package/esm/DedicatedWorker.js +0 -59
  48. package/esm/DedicatedWorker.js.map +0 -1
  49. package/esm/LostConnectionHandler.js +0 -79
  50. package/esm/LostConnectionHandler.js.map +0 -1
  51. package/esm/VuuAuthProvider.js +0 -85
  52. package/esm/VuuAuthProvider.js.map +0 -1
  53. package/esm/VuuAuthenticator.js +0 -54
  54. package/esm/VuuAuthenticator.js.map +0 -1
  55. package/esm/VuuDataSource.js +0 -687
  56. package/esm/VuuDataSource.js.map +0 -1
  57. package/esm/WebSocketConnection.js +0 -17
  58. package/esm/WebSocketConnection.js.map +0 -1
  59. package/esm/authenticate.js +0 -60
  60. package/esm/authenticate.js.map +0 -1
  61. package/esm/constants.js +0 -47
  62. package/esm/constants.js.map +0 -1
  63. package/esm/data-source.js +0 -44
  64. package/esm/data-source.js.map +0 -1
  65. package/esm/index.js +0 -11
  66. package/esm/index.js.map +0 -1
  67. package/esm/inlined-worker.js +0 -2796
  68. package/esm/inlined-worker.js.map +0 -1
  69. package/esm/message-utils.js +0 -80
  70. package/esm/message-utils.js.map +0 -1
@@ -1,687 +0,0 @@
1
- import { logger, BaseDataSource, debounce, constrainRange, throttle, uuid, combineFilters, Range, isSelectSuccessWithRowCount, isConfigChanged, itemsOrOrderChanged, isRpcSuccess, StaleUpdateError, isViewportMenusAction, isVisualLinksAction } from '@vuu-ui/vuu-utils';
2
- import ConnectionManager from './ConnectionManager.js';
3
- import { isDataSourceConfigMessage } from './data-source.js';
4
-
5
- var __defProp = Object.defineProperty;
6
- var __typeError = (msg) => {
7
- throw TypeError(msg);
8
- };
9
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
11
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
12
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
13
- 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);
14
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
15
- var _allColumns, _autosubscribeColumns, _pendingVisualLink, _links, _maxRangeEnd, _maxRangeWidth, _menu, _optimize, _selectedRowsCount, _sessionDataSource, _sessionTableMessageColumn, _status, _tableSchema;
16
- const { info, infoEnabled } = logger("VuuDataSource");
17
- const combineColumnsWithAutosubscribeColumns = (columns, autosubscribeColumns = []) => {
18
- if (autosubscribeColumns.length === 0) {
19
- return columns;
20
- } else {
21
- const out = columns.slice();
22
- autosubscribeColumns.forEach((name) => {
23
- if (!out.includes(name)) {
24
- out.push(name);
25
- }
26
- });
27
- return out;
28
- }
29
- };
30
- const _VuuDataSource = class _VuuDataSource extends BaseDataSource {
31
- constructor({
32
- sessionTableMessageColumn,
33
- ...props
34
- }) {
35
- super(props);
36
- __publicField(this, "bufferSize");
37
- __publicField(this, "server", null);
38
- __publicField(this, "rangeRequest");
39
- /**
40
- * this is the combined set of regular columns and autosubscribe columns
41
- */
42
- __privateAdd(this, _allColumns);
43
- __privateAdd(this, _autosubscribeColumns, []);
44
- __privateAdd(this, _pendingVisualLink);
45
- __privateAdd(this, _links);
46
- __privateAdd(this, _maxRangeEnd, Number.MAX_SAFE_INTEGER);
47
- __privateAdd(this, _maxRangeWidth, Number.MAX_SAFE_INTEGER);
48
- __privateAdd(this, _menu);
49
- __privateAdd(this, _optimize, "throttle");
50
- __privateAdd(this, _selectedRowsCount, 0);
51
- __privateAdd(this, _sessionDataSource);
52
- __privateAdd(this, _sessionTableMessageColumn);
53
- __privateAdd(this, _status, "initialising");
54
- __privateAdd(this, _tableSchema);
55
- __publicField(this, "table");
56
- __publicField(this, "handleMessageFromServer", (message) => {
57
- if (message.type === "subscribed") {
58
- __privateSet(this, _status, "subscribed");
59
- this.tableSchema = message.tableSchema;
60
- if (message.tableSchema.rangeLimits) {
61
- __privateSet(this, _maxRangeEnd, message.tableSchema.rangeLimits.maxRangeEnd);
62
- __privateSet(this, _maxRangeWidth, message.tableSchema.rangeLimits.maxRangeWidth);
63
- }
64
- this._clientCallback?.(message);
65
- if (__privateGet(this, _pendingVisualLink)) {
66
- this.visualLink = __privateGet(this, _pendingVisualLink);
67
- __privateSet(this, _pendingVisualLink, void 0);
68
- }
69
- this.emit("subscribed", message);
70
- } else if (message.type === "disabled") {
71
- __privateSet(this, _status, "disabled");
72
- } else if (message.type === "enabled") {
73
- __privateSet(this, _status, "subscribed");
74
- this.emit("enabled", this.viewport);
75
- } else if (isDataSourceConfigMessage(message)) {
76
- return;
77
- } else if (message.type === "debounce-begin") {
78
- this.optimize = "debounce";
79
- } else {
80
- if (message.type === "viewport-update") {
81
- if (message.size !== void 0 && message.size !== this.size) {
82
- this.size = message.size;
83
- this.emit("resize", message.size, __privateGet(this, _maxRangeEnd));
84
- }
85
- if (Array.isArray(message.rows) && message.rows.length > 0 && __privateGet(this, _sessionDataSource)) {
86
- this.emit("remote-update-during-local-edit", message.rows);
87
- console.log(
88
- `updates incoming whilst edit in progress ${this.viewport}`
89
- );
90
- console.table(message.rows);
91
- return;
92
- }
93
- } else if (message.type === "viewport-clear") {
94
- this.size = 0;
95
- this.emit("resize", 0);
96
- }
97
- if (this.isAwaitingConfirmationOfConfigChange) {
98
- this.confirmConfigChange();
99
- }
100
- if (isViewportMenusAction(message)) {
101
- __privateSet(this, _menu, message.menu);
102
- } else if (isVisualLinksAction(message)) {
103
- __privateSet(this, _links, message.links);
104
- } else {
105
- if (infoEnabled && message.type === "viewport-update") {
106
- info(
107
- `handleMessageFromServer<viewport-update> range (${message.range?.from}:${message.range?.to}) rows ${message.rows?.at(0)?.[0]} - ${message.rows?.at(-1)?.[0]}`
108
- );
109
- }
110
- this._clientCallback?.(message);
111
- }
112
- if (this.optimize === "debounce") {
113
- this.revertDebounce();
114
- }
115
- }
116
- });
117
- __publicField(this, "handleSessionMessageFromServer", (msg) => {
118
- if (msg.type === "subscribed") {
119
- console.log(`[VuuDataSource subscribed to session table]`);
120
- } else if (msg.type === "viewport-update") {
121
- if (msg.size !== void 0 && msg.size !== this.size) {
122
- this.size = msg.size;
123
- this.emit("resize", msg.size);
124
- }
125
- this._clientCallback?.(msg);
126
- }
127
- });
128
- __publicField(this, "revertDebounce", debounce(() => {
129
- this.optimize = "throttle";
130
- }, 100));
131
- __publicField(this, "rawRangeRequest", (range) => {
132
- if (this.viewport && this.server) {
133
- this.server.send({
134
- viewport: this.viewport,
135
- type: "setViewRange",
136
- range: constrainRange(range, __privateGet(this, _maxRangeEnd), __privateGet(this, _maxRangeWidth))
137
- });
138
- }
139
- });
140
- __publicField(this, "debounceRangeRequest", debounce((range) => {
141
- if (this.viewport && this.server) {
142
- this.server.send({
143
- viewport: this.viewport,
144
- type: "setViewRange",
145
- range: constrainRange(range, __privateGet(this, _maxRangeEnd), __privateGet(this, _maxRangeWidth))
146
- });
147
- }
148
- }, 50));
149
- __publicField(this, "throttleRangeRequest", throttle((range) => {
150
- if (this.viewport && this.server) {
151
- this.server.send({
152
- viewport: this.viewport,
153
- type: "setViewRange",
154
- range: constrainRange(range, __privateGet(this, _maxRangeEnd), __privateGet(this, _maxRangeWidth))
155
- });
156
- }
157
- }, 80));
158
- const { bufferSize = 100, table, visualLink } = props;
159
- if (!table)
160
- throw Error("RemoteDataSource constructor called without table");
161
- this.bufferSize = bufferSize;
162
- this.table = table;
163
- __privateSet(this, _pendingVisualLink, visualLink);
164
- __privateSet(this, _sessionTableMessageColumn, sessionTableMessageColumn);
165
- this.rangeRequest = this.rawRangeRequest;
166
- if (props.autosubscribeColumns) {
167
- __privateSet(this, _autosubscribeColumns, props.autosubscribeColumns);
168
- __privateSet(this, _allColumns, combineColumnsWithAutosubscribeColumns(
169
- super.columns,
170
- props.autosubscribeColumns
171
- ));
172
- }
173
- }
174
- async subscribe(subscribeProps, callback) {
175
- super.subscribe(subscribeProps, callback);
176
- const { viewport = this.viewport || (this.viewport = uuid()) } = subscribeProps;
177
- if (__privateGet(this, _status) === "disabled" || __privateGet(this, _status) === "disabling" || __privateGet(this, _status) === "enabling") {
178
- this.enable(callback);
179
- return;
180
- }
181
- if (__privateGet(this, _status) !== "initialising" && __privateGet(this, _status) !== "unsubscribed") {
182
- throw Error(
183
- `[VuuDataSource] invalid status ${__privateGet(this, _status)} for subscribe`
184
- );
185
- }
186
- __privateSet(this, _status, "subscribing");
187
- this.server = await ConnectionManager.serverAPI;
188
- const { bufferSize } = this;
189
- const { columns, ...dataSourceConfig } = combineFilters(this.config);
190
- this.server?.subscribe(
191
- {
192
- ...dataSourceConfig,
193
- bufferSize,
194
- columns: this.columns,
195
- range: this._range.withBuffer,
196
- table: this.table,
197
- title: this._title,
198
- viewport
199
- },
200
- this.handleMessageFromServer
201
- );
202
- }
203
- unsubscribe() {
204
- if (__privateGet(this, _status) !== "unsubscribed") {
205
- info?.(`unsubscribe #${this.viewport}`);
206
- if (this.viewport) {
207
- this.server?.unsubscribe(this.viewport);
208
- this.emit("unsubscribed", this.viewport);
209
- }
210
- this.server?.destroy(this.viewport);
211
- this.server = null;
212
- this.removeAllListeners();
213
- __privateSet(this, _status, "unsubscribed");
214
- this.viewport = "";
215
- this.range = Range(0, 0);
216
- }
217
- }
218
- suspend(escalateToDisable = this._defaultSuspenseProps.escalateToDisable, escalateDelay = this._defaultSuspenseProps.escalateDelay) {
219
- if (__privateGet(this, _status) !== "unsubscribed") {
220
- info?.(`suspend #${this.viewport}, current status ${__privateGet(this, _status)}`);
221
- if (this.viewport) {
222
- __privateSet(this, _status, "suspended");
223
- this.server?.send({
224
- escalateDelay,
225
- escalateToDisable,
226
- type: "suspend",
227
- viewport: this.viewport
228
- });
229
- this.emit("suspended", this.viewport);
230
- }
231
- }
232
- }
233
- /**
234
- * Tell the server we wish to resume receiving messages. Server will send a
235
- * snapshot of rows currently in cache. This can be used to update with
236
- * latest data, e.g after an edit session during which we might have ignored
237
- * some updates.
238
- */
239
- sendResumeMessage() {
240
- this.server?.send({
241
- type: "resume",
242
- viewport: this.viewport
243
- });
244
- }
245
- resume(callback) {
246
- const isDisabled = __privateGet(this, _status).startsWith("disabl");
247
- const isSuspended = __privateGet(this, _status) === "suspended";
248
- info?.(`resume #${this.viewport}, current status ${__privateGet(this, _status)}`);
249
- if (callback) {
250
- this._clientCallback = callback;
251
- }
252
- if (this.viewport) {
253
- if (isDisabled) {
254
- this.enable();
255
- } else if (isSuspended) {
256
- this.sendResumeMessage();
257
- __privateSet(this, _status, "subscribed");
258
- this.emit("resumed", this.viewport);
259
- if (__privateGet(this, _selectedRowsCount) > 0) {
260
- this.emit("row-selection", __privateGet(this, _selectedRowsCount));
261
- }
262
- }
263
- }
264
- }
265
- freeze() {
266
- super.freeze();
267
- if (this.viewport) {
268
- this.server?.send({
269
- viewport: this.viewport,
270
- type: "FREEZE_VP"
271
- });
272
- }
273
- }
274
- unfreeze() {
275
- super.unfreeze();
276
- if (this.viewport) {
277
- this.server?.send({
278
- viewport: this.viewport,
279
- type: "UNFREEZE_VP"
280
- });
281
- }
282
- }
283
- disable() {
284
- info?.(`disable #${this.viewport}, current status ${__privateGet(this, _status)}`);
285
- if (this.viewport) {
286
- __privateSet(this, _status, "disabling");
287
- this.server?.send({
288
- viewport: this.viewport,
289
- type: "disable"
290
- });
291
- this.emit("disabled", this.viewport);
292
- }
293
- }
294
- enable(callback) {
295
- info?.(`enable #${this.viewport}, current status ${__privateGet(this, _status)}`);
296
- if (this.viewport && (__privateGet(this, _status) === "disabled" || __privateGet(this, _status) === "disabling")) {
297
- __privateSet(this, _status, "enabling");
298
- if (callback) {
299
- this._clientCallback = callback;
300
- }
301
- this.server?.send({
302
- viewport: this.viewport,
303
- type: "enable"
304
- });
305
- this.emit("enabled", this.viewport);
306
- }
307
- }
308
- async select(selectRequest) {
309
- if (this.viewport && this.server) {
310
- const response = await this.server.select({
311
- ...selectRequest,
312
- vpId: this.viewport
313
- });
314
- if (isSelectSuccessWithRowCount(response)) {
315
- __privateSet(this, _selectedRowsCount, response.selectedRowCount);
316
- this.emit("row-selection", response.selectedRowCount);
317
- } else {
318
- console.warn(`select error`);
319
- }
320
- }
321
- }
322
- openTreeNode(keyOrIndex) {
323
- if (this.viewport) {
324
- const [key, index] = typeof keyOrIndex === "string" ? [keyOrIndex] : [void 0, keyOrIndex];
325
- this.server?.send({
326
- index,
327
- key,
328
- type: "openTreeNode",
329
- viewport: this.viewport
330
- });
331
- }
332
- }
333
- closeTreeNode(keyOrIndex) {
334
- if (this.viewport) {
335
- const [key, index] = typeof keyOrIndex === "string" ? [keyOrIndex] : [void 0, keyOrIndex];
336
- this.server?.send({
337
- index,
338
- key,
339
- type: "closeTreeNode",
340
- viewport: this.viewport
341
- });
342
- }
343
- }
344
- //TODO is this going to be confusing - the lack of symmetry between set and get columns
345
- // when there are autoSubscribe columns ?
346
- // alternative would be an allColumns prop, but every datasource would then have to add it.
347
- get columns() {
348
- return __privateGet(this, _allColumns) ?? super.columns;
349
- }
350
- set columns(columns) {
351
- super.columns = columns;
352
- if (__privateGet(this, _autosubscribeColumns).length) {
353
- __privateSet(this, _allColumns, combineColumnsWithAutosubscribeColumns(
354
- columns,
355
- __privateGet(this, _autosubscribeColumns)
356
- ));
357
- }
358
- }
359
- get tableSchema() {
360
- return __privateGet(this, _tableSchema);
361
- }
362
- set tableSchema(tableSchema) {
363
- __privateSet(this, _tableSchema, tableSchema);
364
- }
365
- get links() {
366
- return __privateGet(this, _links);
367
- }
368
- get maxRangeEnd() {
369
- return __privateGet(this, _maxRangeEnd);
370
- }
371
- get menu() {
372
- return __privateGet(this, _menu);
373
- }
374
- get status() {
375
- return __privateGet(this, _status);
376
- }
377
- get optimize() {
378
- return __privateGet(this, _optimize);
379
- }
380
- set optimize(optimize) {
381
- if (optimize !== __privateGet(this, _optimize)) {
382
- __privateSet(this, _optimize, optimize);
383
- switch (optimize) {
384
- case "none":
385
- this.rangeRequest = this.rawRangeRequest;
386
- break;
387
- case "debounce":
388
- this.rangeRequest = this.debounceRangeRequest;
389
- break;
390
- case "throttle":
391
- this.rangeRequest = this.throttleRangeRequest;
392
- break;
393
- }
394
- this.emit("optimize", optimize);
395
- }
396
- }
397
- get selectedRowsCount() {
398
- return __privateGet(this, _selectedRowsCount);
399
- }
400
- get config() {
401
- return super.config;
402
- }
403
- set config(config) {
404
- const { noChanges, columnsChanged } = isConfigChanged(this.config, config);
405
- if (!noChanges) {
406
- super.config = config;
407
- const { columns, ...dataSourceConfig } = combineFilters(this.config);
408
- const serverConfig = {
409
- ...dataSourceConfig,
410
- columns: combineColumnsWithAutosubscribeColumns(
411
- columns,
412
- __privateGet(this, _autosubscribeColumns)
413
- )
414
- };
415
- if (columnsChanged && __privateGet(this, _autosubscribeColumns).length) {
416
- __privateSet(this, _allColumns, combineColumnsWithAutosubscribeColumns(
417
- columns,
418
- __privateGet(this, _autosubscribeColumns)
419
- ));
420
- }
421
- this.server?.send({
422
- viewport: this.viewport,
423
- type: "config",
424
- config: serverConfig
425
- });
426
- }
427
- }
428
- set impendingConfig(config) {
429
- if (config !== this.config) {
430
- super.impendingConfig = config;
431
- this.server?.send({
432
- viewport: this.viewport,
433
- type: "config",
434
- config: combineFilters(this.config)
435
- });
436
- }
437
- }
438
- get groupBy() {
439
- return this._configWithVisualLink.groupBy;
440
- }
441
- set groupBy(groupBy) {
442
- if (itemsOrOrderChanged(this.groupBy, groupBy)) {
443
- const wasGrouped = this.groupBy.length > 0;
444
- this.impendingConfig = {
445
- ...this._configWithVisualLink,
446
- groupBy
447
- };
448
- if (!wasGrouped && groupBy.length > 0 && this.viewport) {
449
- this._clientCallback?.({
450
- clientViewportId: this.viewport,
451
- mode: "batch",
452
- type: "viewport-update",
453
- size: 0,
454
- rows: []
455
- });
456
- }
457
- }
458
- }
459
- get range() {
460
- return super.range;
461
- }
462
- set range(range) {
463
- super.range = range;
464
- if (__privateGet(this, _sessionDataSource)) {
465
- __privateGet(this, _sessionDataSource).range = range;
466
- }
467
- }
468
- get title() {
469
- return super.title || `${this.table.module} ${this.table.table}`;
470
- }
471
- set title(title) {
472
- super.title = title;
473
- if (this.viewport && title) {
474
- this.server?.send({
475
- type: "setTitle",
476
- title,
477
- viewport: this.viewport
478
- });
479
- }
480
- }
481
- get visualLink() {
482
- return this._configWithVisualLink.visualLink;
483
- }
484
- set visualLink(visualLink) {
485
- this._configWithVisualLink = {
486
- ...this._configWithVisualLink,
487
- visualLink
488
- };
489
- if (visualLink) {
490
- const {
491
- parentClientVpId,
492
- link: { fromColumn, toColumn }
493
- } = visualLink;
494
- if (this.viewport) {
495
- this.server?.rpcCall({
496
- childColumnName: fromColumn,
497
- childVpId: this.viewport,
498
- parentColumnName: toColumn,
499
- parentVpId: parentClientVpId,
500
- type: "CREATE_VISUAL_LINK"
501
- }).then((response) => {
502
- this.emit("visual-link-created", response);
503
- });
504
- }
505
- } else {
506
- if (this.viewport) {
507
- this.server?.rpcCall({
508
- type: "REMOVE_VISUAL_LINK",
509
- childVpId: this.viewport
510
- }).then(() => {
511
- this.emit("visual-link-removed");
512
- });
513
- }
514
- }
515
- this.emit("config", this._configWithVisualLink, this.range);
516
- }
517
- async remoteProcedureCall() {
518
- return Promise.reject();
519
- }
520
- async createSessionDataSource(copyOption) {
521
- const rpcResponse = await this?.rpcRequest?.({
522
- type: "RPC_REQUEST",
523
- rpcName: "createSessionTable",
524
- params: { copyOption }
525
- });
526
- if (isRpcSuccess(rpcResponse)) {
527
- const { table: sessionTable } = rpcResponse.data;
528
- return new _VuuDataSource({
529
- ...this.config,
530
- table: sessionTable,
531
- viewport: sessionTable.table
532
- });
533
- } else {
534
- throw Error(
535
- `[VuuDataSource] createSessionDataSource ${rpcResponse?.errorMessage}`
536
- );
537
- }
538
- }
539
- async beginEditSession(editSessionMode = "all-rows") {
540
- const rpcResponse = await this?.rpcRequest?.({
541
- type: "RPC_REQUEST",
542
- rpcName: "beginEditSession",
543
- params: {
544
- editSessionMode
545
- }
546
- });
547
- if (isRpcSuccess(rpcResponse)) {
548
- const { table: sessionTable } = rpcResponse.data;
549
- const columns = __privateGet(this, _sessionTableMessageColumn) ? this.columns.concat(__privateGet(this, _sessionTableMessageColumn)) : this.columns;
550
- __privateSet(this, _sessionDataSource, new _VuuDataSource({
551
- ...this.config,
552
- columns,
553
- table: sessionTable,
554
- viewport: sessionTable.table
555
- }));
556
- __privateGet(this, _sessionDataSource).subscribe(
557
- {
558
- range: this.range
559
- },
560
- this.handleSessionMessageFromServer
561
- );
562
- } else {
563
- throw Error(
564
- `[VuuDataSource] beginEditSession ${rpcResponse.errorMessage}`
565
- );
566
- }
567
- }
568
- async editCell(key, column, data) {
569
- const rpcHost = __privateGet(this, _sessionDataSource) ?? this;
570
- return rpcHost.rpcRequest?.({
571
- type: "RPC_REQUEST",
572
- rpcName: "editCell",
573
- params: {
574
- column,
575
- data,
576
- key
577
- }
578
- });
579
- }
580
- async endEditSession(saveChanges = false, force = false) {
581
- const type = "RPC_REQUEST";
582
- const rpcName = "endEditSession";
583
- const sessionDataSource = __privateGet(this, _sessionDataSource);
584
- const rpcHost = sessionDataSource ?? this;
585
- if (sessionDataSource) {
586
- __privateSet(this, _sessionDataSource, void 0);
587
- }
588
- const rpcResponse = await rpcHost.rpcRequest?.(
589
- saveChanges ? { type, rpcName, params: { save: true, force } } : { type, rpcName, params: {} }
590
- );
591
- if (isRpcSuccess(rpcResponse)) {
592
- if (sessionDataSource) {
593
- sessionDataSource?.unsubscribe();
594
- }
595
- } else {
596
- if (rpcResponse?.errorMessage === "stale update") {
597
- __privateSet(this, _sessionDataSource, sessionDataSource);
598
- throw new StaleUpdateError(rpcResponse.errorMessage);
599
- } else {
600
- throw Error("unknown error");
601
- }
602
- }
603
- this.sendResumeMessage();
604
- }
605
- async rpcRequest(rpcRequest) {
606
- if (this.viewport && this.server) {
607
- return this.server?.rpcCall({
608
- ...rpcRequest,
609
- context: { type: "VIEWPORT_CONTEXT", viewPortId: this.viewport }
610
- });
611
- } else {
612
- throw Error(`rpcCall server or viewport are undefined`);
613
- }
614
- }
615
- async menuRpcCall(rpcRequest) {
616
- if (this.viewport) {
617
- return this.server?.rpcCall({
618
- ...rpcRequest,
619
- vpId: this.viewport
620
- });
621
- }
622
- }
623
- insertRow() {
624
- return Promise.resolve("not supported");
625
- }
626
- async deleteRow(key, mode = "hard") {
627
- const rpcHost = __privateGet(this, _sessionDataSource) ?? this;
628
- const response = await rpcHost.rpcRequest?.({
629
- type: "RPC_REQUEST",
630
- rpcName: "deleteRow",
631
- params: { key, mode }
632
- });
633
- if (isRpcSuccess(response)) {
634
- return true;
635
- }
636
- return response?.errorMessage ?? "deleteRow failed";
637
- }
638
- async deleteSelectedRows(mode = "soft") {
639
- const rpcHost = __privateGet(this, _sessionDataSource) ?? this;
640
- const response = await rpcHost.rpcRequest?.({
641
- type: "RPC_REQUEST",
642
- rpcName: "deleteSelectedRows",
643
- params: { mode }
644
- });
645
- return response ?? {
646
- type: "ERROR_RESULT",
647
- errorMessage: "deleteSelectedRows failed"
648
- };
649
- }
650
- async addRow(rowData = {}) {
651
- const response = await this.rpcRequest?.({
652
- type: "RPC_REQUEST",
653
- rpcName: "addRow",
654
- params: { data: rowData }
655
- });
656
- if (isRpcSuccess(response)) {
657
- return true;
658
- }
659
- return response?.errorMessage ?? "addRow failed";
660
- }
661
- async undoRowChange(key) {
662
- const rpcHost = __privateGet(this, _sessionDataSource) ?? this;
663
- const response = await rpcHost.rpcRequest?.({
664
- type: "RPC_REQUEST",
665
- rpcName: "undoRowChange",
666
- params: { key }
667
- });
668
- return response ?? { type: "ERROR_RESULT", errorMessage: "undoRowChange failed" };
669
- }
670
- };
671
- _allColumns = new WeakMap();
672
- _autosubscribeColumns = new WeakMap();
673
- _pendingVisualLink = new WeakMap();
674
- _links = new WeakMap();
675
- _maxRangeEnd = new WeakMap();
676
- _maxRangeWidth = new WeakMap();
677
- _menu = new WeakMap();
678
- _optimize = new WeakMap();
679
- _selectedRowsCount = new WeakMap();
680
- _sessionDataSource = new WeakMap();
681
- _sessionTableMessageColumn = new WeakMap();
682
- _status = new WeakMap();
683
- _tableSchema = new WeakMap();
684
- let VuuDataSource = _VuuDataSource;
685
-
686
- export { VuuDataSource };
687
- //# sourceMappingURL=VuuDataSource.js.map