@casual-simulation/aux-common 3.4.6-alpha.14668890889 → 3.5.0-alpha.15119114602

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 (110) hide show
  1. package/AAGUID.d.ts +11 -0
  2. package/AAGUID.js +116 -0
  3. package/AAGUID.js.map +1 -0
  4. package/BlobPolyfill.js +20 -31
  5. package/BlobPolyfill.js.map +1 -1
  6. package/bots/AuxStateHelpers.js +9 -3
  7. package/bots/AuxStateHelpers.js.map +1 -1
  8. package/bots/Bot.d.ts +1 -1
  9. package/bots/Bot.js +10 -1
  10. package/bots/Bot.js.map +1 -1
  11. package/bots/BotCalculationContext.js.map +1 -1
  12. package/bots/BotCalculations.d.ts +3 -3
  13. package/bots/BotCalculations.js +5 -1
  14. package/bots/BotCalculations.js.map +1 -1
  15. package/bots/BotEvents.d.ts +20 -2
  16. package/bots/BotEvents.js +84 -17
  17. package/bots/BotEvents.js.map +1 -1
  18. package/bots/StateUpdatedEvent.js.map +1 -1
  19. package/bots/StoredAux.d.ts +1 -1
  20. package/bots/StoredAux.js.map +1 -1
  21. package/bots/test/BotCalculationContextTests.d.ts +0 -1
  22. package/bots/test/BotCalculationContextTests.js.map +1 -1
  23. package/common/PolicyPermissions.d.ts +224 -3
  24. package/common/PolicyPermissions.js +46 -0
  25. package/common/PolicyPermissions.js.map +1 -1
  26. package/common/RemoteActions.js +19 -6
  27. package/common/RemoteActions.js.map +1 -1
  28. package/common/StatusUpdateUtils.js +4 -1
  29. package/common/StatusUpdateUtils.js.map +1 -1
  30. package/common/Version.d.ts +22 -0
  31. package/common/Version.js +75 -0
  32. package/common/Version.js.map +1 -0
  33. package/common/WebConfig.d.ts +6 -6
  34. package/common/index.d.ts +1 -0
  35. package/common/index.js +1 -0
  36. package/common/index.js.map +1 -1
  37. package/documents/RemoteYjsSharedDocument.js +30 -54
  38. package/documents/RemoteYjsSharedDocument.js.map +1 -1
  39. package/documents/SharedDocumentFactories.js +7 -18
  40. package/documents/SharedDocumentFactories.js.map +1 -1
  41. package/documents/YjsSharedDocument.js +1 -12
  42. package/documents/YjsSharedDocument.js.map +1 -1
  43. package/documents/test/DocumentTests.js +15 -24
  44. package/documents/test/DocumentTests.js.map +1 -1
  45. package/forms/FormError.d.ts +43 -0
  46. package/forms/FormError.js +56 -0
  47. package/forms/FormError.js.map +1 -0
  48. package/forms/index.d.ts +2 -0
  49. package/forms/index.js +19 -0
  50. package/forms/index.js.map +1 -0
  51. package/http/GenericHttpInterface.d.ts +2 -1
  52. package/http/GenericHttpInterface.js.map +1 -1
  53. package/index.d.ts +2 -0
  54. package/index.js +2 -0
  55. package/index.js.map +1 -1
  56. package/package.json +7 -7
  57. package/partitions/AuxPartition.js +5 -1
  58. package/partitions/AuxPartition.js.map +1 -1
  59. package/partitions/AuxPartitionFactories.js +7 -18
  60. package/partitions/AuxPartitionFactories.js.map +1 -1
  61. package/partitions/MemoryPartition.js +24 -40
  62. package/partitions/MemoryPartition.js.map +1 -1
  63. package/partitions/OtherPlayersPartition.js +140 -159
  64. package/partitions/OtherPlayersPartition.js.map +1 -1
  65. package/partitions/PartitionAuthSource.d.ts +4 -0
  66. package/partitions/PartitionUtils.js +1 -1
  67. package/partitions/PartitionUtils.js.map +1 -1
  68. package/partitions/ProxyBridgePartition.js +32 -47
  69. package/partitions/ProxyBridgePartition.js.map +1 -1
  70. package/partitions/RemoteYjsPartition.js +235 -221
  71. package/partitions/RemoteYjsPartition.js.map +1 -1
  72. package/partitions/YjsPartition.js +215 -205
  73. package/partitions/YjsPartition.js.map +1 -1
  74. package/records/AuthUtils.d.ts +175 -0
  75. package/records/AuthUtils.js +335 -0
  76. package/records/AuthUtils.js.map +1 -0
  77. package/records/RecordKeys.d.ts +52 -0
  78. package/records/RecordKeys.js +131 -0
  79. package/records/RecordKeys.js.map +1 -0
  80. package/records/WebPush.d.ts +2 -0
  81. package/records/WebPush.js +19 -0
  82. package/records/WebPush.js.map +1 -0
  83. package/records/index.d.ts +4 -0
  84. package/records/index.js +21 -0
  85. package/records/index.js.map +1 -0
  86. package/rpc/ErrorCodes.d.ts +2 -2
  87. package/rpc/ErrorCodes.js.map +1 -1
  88. package/rpc/GenericRPCInterface.js +8 -4
  89. package/rpc/GenericRPCInterface.js.map +1 -1
  90. package/test/TestHelpers.js +2 -13
  91. package/test/TestHelpers.js.map +1 -1
  92. package/utils.d.ts +14 -0
  93. package/utils.js +18 -0
  94. package/utils.js.map +1 -1
  95. package/websockets/AuthenticatedConnectionClient.js +39 -10
  96. package/websockets/AuthenticatedConnectionClient.js.map +1 -1
  97. package/websockets/InstRecordsClient.js +18 -8
  98. package/websockets/InstRecordsClient.js.map +1 -1
  99. package/websockets/MemoryConnectionClient.d.ts +1 -1
  100. package/websockets/Utils.d.ts +33 -0
  101. package/websockets/Utils.js +82 -0
  102. package/websockets/Utils.js.map +1 -0
  103. package/websockets/WebsocketEvents.d.ts +18 -17
  104. package/websockets/WebsocketEvents.js.map +1 -1
  105. package/websockets/index.d.ts +1 -0
  106. package/websockets/index.js +1 -0
  107. package/websockets/index.js.map +1 -1
  108. package/yjs/YjsHelpers.js.map +1 -1
  109. package/yjs/YjsIndexedDBPersistence.js +53 -78
  110. package/yjs/YjsIndexedDBPersistence.js.map +1 -1
@@ -1,24 +1,4 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __rest = (this && this.__rest) || function (s, e) {
11
- var t = {};
12
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
- t[p] = s[p];
14
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
- t[p[i]] = s[p[i]];
18
- }
19
- return t;
20
- };
21
- import { isTagEdit, preserve, del, insert, edit, ON_REMOTE_WHISPER_ACTION_NAME, ON_REMOTE_DATA_ACTION_NAME, } from '../bots';
1
+ import { isTagEdit, preserve, del, insert, edit, ON_REMOTE_WHISPER_ACTION_NAME, ON_REMOTE_DATA_ACTION_NAME, getInstStateFromUpdates, } from '../bots';
22
2
  import { BehaviorSubject } from 'rxjs';
23
3
  import { breakIntoIndividualEvents, botAdded, createBot, botRemoved, hasValue, botUpdated, action, asyncResult, asyncError, convertToString, ON_SPACE_MAX_SIZE_REACHED, ON_SPACE_RATE_LIMIT_EXCEEDED_ACTION_NAME, } from '../bots';
24
4
  import { Text, Map, applyUpdate, YMapEvent, createAbsolutePositionFromRelativePosition, YTextEvent, } from 'yjs';
@@ -26,9 +6,10 @@ import { MemoryPartitionImpl } from './MemoryPartition';
26
6
  import { createRelativePositionFromStateVector, getClock, getStateVector, } from '../yjs/YjsHelpers';
27
7
  import { fromByteArray, toByteArray } from 'base64-js';
28
8
  import { YjsPartitionImpl } from './YjsPartition';
29
- import { ensureTagIsSerializable, supportsRemoteEvent } from './PartitionUtils';
9
+ import { ensureTagIsSerializable, getStateFromUpdates, supportsRemoteEvent, } from './PartitionUtils';
30
10
  import { device } from '../common';
31
11
  import { RemoteYjsSharedDocument } from '../documents/RemoteYjsSharedDocument';
12
+ import { v4 as uuid } from 'uuid';
32
13
  /**
33
14
  * Attempts to create a YjsPartition from the given config.
34
15
  * @param config The config.
@@ -100,7 +81,7 @@ export class RemoteYjsPartitionImpl extends RemoteYjsSharedDocument {
100
81
  var _a;
101
82
  const version = getStateVector(this._doc);
102
83
  if (this._isRemoteUpdate) {
103
- const _b = version, _c = this._currentSite, currentVersion = _b[_c], otherVersions = __rest(_b, [typeof _c === "symbol" ? _c : _c + ""]);
84
+ const { [this._currentSite]: currentVersion, ...otherVersions } = version;
104
85
  return {
105
86
  currentSite: this._currentSite,
106
87
  remoteSite: this._remoteSite,
@@ -121,152 +102,180 @@ export class RemoteYjsPartitionImpl extends RemoteYjsSharedDocument {
121
102
  }
122
103
  };
123
104
  }
124
- applyEvents(events) {
125
- return __awaiter(this, void 0, void 0, function* () {
126
- if (this._static) {
127
- return [];
105
+ async applyEvents(events) {
106
+ if (this._static) {
107
+ return [];
108
+ }
109
+ let finalEvents = [];
110
+ for (let e of events) {
111
+ if (e.type === 'apply_state') {
112
+ finalEvents.push(...breakIntoIndividualEvents(this.state, e));
128
113
  }
129
- let finalEvents = [];
130
- for (let e of events) {
131
- if (e.type === 'apply_state') {
132
- finalEvents.push(...breakIntoIndividualEvents(this.state, e));
133
- }
134
- else if (e.type === 'add_bot' ||
135
- e.type === 'remove_bot' ||
136
- e.type === 'update_bot') {
137
- finalEvents.push(e);
138
- }
114
+ else if (e.type === 'add_bot' ||
115
+ e.type === 'remove_bot' ||
116
+ e.type === 'update_bot') {
117
+ finalEvents.push(e);
139
118
  }
140
- this._applyEvents(finalEvents);
141
- return [];
142
- });
119
+ }
120
+ this._applyEvents(finalEvents);
121
+ return [];
143
122
  }
144
- sendRemoteEvents(events) {
145
- return __awaiter(this, void 0, void 0, function* () {
146
- if (this._readOnly || !this._remoteEvents) {
147
- return;
123
+ async sendRemoteEvents(events) {
124
+ if (this._readOnly || !this._remoteEvents) {
125
+ return;
126
+ }
127
+ for (let event of events) {
128
+ if (!supportsRemoteEvent(this._remoteEvents, event)) {
129
+ continue;
148
130
  }
149
- for (let event of events) {
150
- if (!supportsRemoteEvent(this._remoteEvents, event)) {
151
- continue;
131
+ if (event.type === 'remote') {
132
+ if (event.event.type === 'get_remotes') {
133
+ // Do nothing for get_remotes since it will be handled by the OtherPlayersPartition.
134
+ // TODO: Make this mechanism more extensible so that we don't have to hardcode for each time
135
+ // we do this type of logic.
152
136
  }
153
- if (event.type === 'remote') {
154
- if (event.event.type === 'get_remotes') {
155
- // Do nothing for get_remotes since it will be handled by the OtherPlayersPartition.
156
- // TODO: Make this mechanism more extensible so that we don't have to hardcode for each time
157
- // we do this type of logic.
158
- }
159
- else if (event.event.type === 'get_remote_count') {
160
- const action = event.event;
161
- this._client
162
- .connectionCount(action.recordName, action.inst, action.branch)
163
- .subscribe({
164
- next: (count) => {
165
- this._onEvents.next([
166
- asyncResult(event.taskId, count),
167
- ]);
168
- },
169
- error: (err) => {
170
- this._onEvents.next([
171
- asyncError(event.taskId, err),
172
- ]);
173
- },
174
- });
175
- }
176
- else if (event.event.type === 'list_inst_updates') {
177
- const action = event.event;
178
- this._client
179
- .getBranchUpdates(this._recordName, this._inst, this._branch)
180
- .subscribe({
181
- next: ({ updates, timestamps }) => {
182
- this._onEvents.next([
183
- asyncResult(event.taskId, updates.map((u, i) => ({
184
- id: i,
185
- update: u,
186
- timestamp: timestamps === null || timestamps === void 0 ? void 0 : timestamps[i],
187
- }))),
188
- ]);
189
- },
190
- error: (err) => {
191
- this._onEvents.next([
192
- asyncError(event.taskId, err),
193
- ]);
194
- },
195
- });
196
- }
197
- else if (event.event.type === 'get_inst_state_from_updates') {
198
- const action = event.event;
199
- try {
200
- let partition = new YjsPartitionImpl({
201
- type: 'yjs',
202
- });
203
- for (let { update } of action.updates) {
204
- const updateBytes = toByteArray(update);
205
- applyUpdate(partition.doc, updateBytes);
206
- }
137
+ else if (event.event.type === 'get_remote_count') {
138
+ const action = event.event;
139
+ this._client
140
+ .connectionCount(action.recordName, action.inst, action.branch)
141
+ .subscribe({
142
+ next: (count) => {
207
143
  this._onEvents.next([
208
- asyncResult(event.taskId, partition.state, false),
144
+ asyncResult(event.taskId, count),
209
145
  ]);
210
- }
211
- catch (err) {
212
- this._onEvents.next([asyncError(event.taskId, err)]);
213
- }
214
- }
215
- else if (event.event.type === 'create_initialization_update') {
216
- const action = (event.event);
217
- try {
218
- let partition = new YjsPartitionImpl({
219
- type: 'yjs',
220
- });
221
- partition.doc.on('update', (update) => {
222
- let instUpdate = {
223
- id: 0,
224
- timestamp: Date.now(),
225
- update: fromByteArray(update),
226
- };
227
- this._onEvents.next([
228
- asyncResult(event.taskId, instUpdate, false),
229
- ]);
230
- });
231
- yield partition.applyEvents(action.bots.map((b) => botAdded(createBot(b.id, b.tags))));
232
- }
233
- catch (err) {
234
- this._onEvents.next([asyncError(event.taskId, err)]);
235
- }
236
- }
237
- else if (event.event.type === 'apply_updates_to_inst') {
238
- const action = event.event;
239
- try {
240
- this.applyStateUpdates(action.updates);
146
+ },
147
+ error: (err) => {
241
148
  this._onEvents.next([
242
- asyncResult(event.taskId, null, false),
149
+ asyncError(event.taskId, err),
243
150
  ]);
151
+ },
152
+ });
153
+ }
154
+ else if (event.event.type === 'list_inst_updates') {
155
+ const action = event.event;
156
+ this._client
157
+ .getBranchUpdates(this._recordName, this._inst, this._branch)
158
+ .subscribe({
159
+ next: ({ updates, timestamps }) => {
160
+ this._onEvents.next([
161
+ asyncResult(event.taskId, updates.map((u, i) => ({
162
+ id: i,
163
+ update: u,
164
+ timestamp: timestamps === null || timestamps === void 0 ? void 0 : timestamps[i],
165
+ }))),
166
+ ]);
167
+ },
168
+ error: (err) => {
169
+ this._onEvents.next([
170
+ asyncError(event.taskId, err),
171
+ ]);
172
+ },
173
+ });
174
+ }
175
+ else if (event.event.type === 'get_inst_state_from_updates') {
176
+ const action = event.event;
177
+ try {
178
+ let partition = new YjsPartitionImpl({
179
+ type: 'yjs',
180
+ });
181
+ for (let { update } of action.updates) {
182
+ const updateBytes = toByteArray(update);
183
+ applyUpdate(partition.doc, updateBytes);
244
184
  }
245
- catch (err) {
246
- this._onEvents.next([asyncError(event.taskId, err)]);
247
- }
185
+ this._onEvents.next([
186
+ asyncResult(event.taskId, partition.state, false),
187
+ ]);
248
188
  }
249
- else if (event.event.type === 'get_current_inst_update') {
250
- const action = event.event;
251
- try {
252
- const update = this.getStateUpdate();
189
+ catch (err) {
190
+ this._onEvents.next([asyncError(event.taskId, err)]);
191
+ }
192
+ }
193
+ else if (event.event.type === 'create_initialization_update') {
194
+ const action = (event.event);
195
+ try {
196
+ let partition = new YjsPartitionImpl({
197
+ type: 'yjs',
198
+ });
199
+ partition.doc.on('update', (update) => {
200
+ let instUpdate = {
201
+ id: 0,
202
+ timestamp: Date.now(),
203
+ update: fromByteArray(update),
204
+ };
253
205
  this._onEvents.next([
254
- asyncResult(event.taskId, update, false),
206
+ asyncResult(event.taskId, instUpdate, false),
255
207
  ]);
208
+ });
209
+ await partition.applyEvents(action.bots.map((b) => botAdded(createBot(b.id, b.tags))));
210
+ }
211
+ catch (err) {
212
+ this._onEvents.next([asyncError(event.taskId, err)]);
213
+ }
214
+ }
215
+ else if (event.event.type === 'apply_updates_to_inst') {
216
+ const action = event.event;
217
+ try {
218
+ this.applyStateUpdates(action.updates);
219
+ this._onEvents.next([
220
+ asyncResult(event.taskId, null, false),
221
+ ]);
222
+ }
223
+ catch (err) {
224
+ this._onEvents.next([asyncError(event.taskId, err)]);
225
+ }
226
+ }
227
+ else if (event.event.type === 'get_current_inst_update') {
228
+ const action = event.event;
229
+ try {
230
+ const update = this.getStateUpdate();
231
+ this._onEvents.next([
232
+ asyncResult(event.taskId, update, false),
233
+ ]);
234
+ }
235
+ catch (err) {
236
+ this._onEvents.next([asyncError(event.taskId, err)]);
237
+ }
238
+ }
239
+ else if (event.event.type === 'install_aux_file') {
240
+ const action = event.event;
241
+ try {
242
+ if (action.mode === 'copy') {
243
+ let bots;
244
+ if (action.aux.version === 2) {
245
+ const state = getStateFromUpdates(getInstStateFromUpdates(action.aux.updates));
246
+ bots = Object.values(state);
247
+ }
248
+ else {
249
+ bots = Object.values(action.aux.state);
250
+ }
251
+ if (bots && bots.length > 0) {
252
+ this._applyEvents(bots.map((b) => botAdded(createBot(uuid(), b.tags))));
253
+ }
256
254
  }
257
- catch (err) {
258
- this._onEvents.next([asyncError(event.taskId, err)]);
255
+ else {
256
+ if (action.aux.version === 2) {
257
+ this.applyStateUpdates(action.aux.updates);
258
+ }
259
+ else if (action.aux.version === 1) {
260
+ this._applyEvents(Object.values(action.aux.state).map((b) => botAdded(createBot(b.id, b.tags))));
261
+ }
259
262
  }
263
+ this._onEvents.next([
264
+ asyncResult(event.taskId, null, false),
265
+ ]);
260
266
  }
261
- else {
262
- this._client.sendAction(this._recordName, this._inst, this._branch, event);
267
+ catch (err) {
268
+ this._onEvents.next([asyncError(event.taskId, err)]);
263
269
  }
264
270
  }
265
271
  else {
266
272
  this._client.sendAction(this._recordName, this._inst, this._branch, event);
267
273
  }
268
274
  }
269
- });
275
+ else {
276
+ this._client.sendAction(this._recordName, this._inst, this._branch, event);
277
+ }
278
+ }
270
279
  }
271
280
  _handleClientEvent(event) {
272
281
  if (event.action.type === 'device') {
@@ -286,7 +295,11 @@ export class RemoteYjsPartitionImpl extends RemoteYjsSharedDocument {
286
295
  ]);
287
296
  }
288
297
  else if (hasValue(event.action.taskId)) {
289
- const newEvent = device(event.action.connection, Object.assign(Object.assign({}, event.action.event), { taskId: event.action.taskId, playerId: event.action.connection.connectionId }), event.action.taskId);
298
+ const newEvent = device(event.action.connection, {
299
+ ...event.action.event,
300
+ taskId: event.action.taskId,
301
+ playerId: event.action.connection.connectionId,
302
+ }, event.action.taskId);
290
303
  this._onEvents.next([newEvent]);
291
304
  }
292
305
  else {
@@ -402,88 +415,86 @@ export class RemoteYjsPartitionImpl extends RemoteYjsSharedDocument {
402
415
  // this._isRemoteUpdate = false;
403
416
  // }
404
417
  // }
405
- _processTransaction(transaction) {
406
- return __awaiter(this, void 0, void 0, function* () {
407
- let memoryEvents = [];
408
- const version = getStateVector(this._doc);
409
- for (let [type, events] of transaction.changedParentTypes) {
410
- if (type === this._bots) {
411
- for (let event of events) {
412
- // Update the current target so that the event
413
- // path is calculated from the bots map.
414
- // see https://github.com/yjs/yjs/blob/5244755879daaa7b5a1ca64e6af617cdbb110462/src/utils/YEvent.js#L63
415
- event.currentTarget = this._bots;
416
- const target = event.target;
417
- if (target === type) {
418
- // Bot was added or removed
419
- if (event instanceof YMapEvent) {
420
- for (let [key, change] of event.changes.keys) {
421
- if (change.action === 'add') {
422
- // bot added
423
- const value = this._bots.get(key);
424
- const bot = this._mapToBot(key, value);
425
- memoryEvents.push(botAdded(bot));
426
- }
427
- else if (change.action === 'delete') {
428
- // bot deleted
429
- memoryEvents.push(botRemoved(key));
430
- }
431
- else if (change.action === 'update') {
432
- // bot updated in a way that we can't track
433
- // in this scenario, we just remove the bot and re-add it
434
- memoryEvents.push(botRemoved(key));
435
- const value = this._bots.get(key);
436
- const bot = this._mapToBot(key, value);
437
- memoryEvents.push(botAdded(bot));
438
- }
418
+ async _processTransaction(transaction) {
419
+ let memoryEvents = [];
420
+ const version = getStateVector(this._doc);
421
+ for (let [type, events] of transaction.changedParentTypes) {
422
+ if (type === this._bots) {
423
+ for (let event of events) {
424
+ // Update the current target so that the event
425
+ // path is calculated from the bots map.
426
+ // see https://github.com/yjs/yjs/blob/5244755879daaa7b5a1ca64e6af617cdbb110462/src/utils/YEvent.js#L63
427
+ event.currentTarget = this._bots;
428
+ const target = event.target;
429
+ if (target === type) {
430
+ // Bot was added or removed
431
+ if (event instanceof YMapEvent) {
432
+ for (let [key, change] of event.changes.keys) {
433
+ if (change.action === 'add') {
434
+ // bot added
435
+ const value = this._bots.get(key);
436
+ const bot = this._mapToBot(key, value);
437
+ memoryEvents.push(botAdded(bot));
438
+ }
439
+ else if (change.action === 'delete') {
440
+ // bot deleted
441
+ memoryEvents.push(botRemoved(key));
442
+ }
443
+ else if (change.action === 'update') {
444
+ // bot updated in a way that we can't track
445
+ // in this scenario, we just remove the bot and re-add it
446
+ memoryEvents.push(botRemoved(key));
447
+ const value = this._bots.get(key);
448
+ const bot = this._mapToBot(key, value);
449
+ memoryEvents.push(botAdded(bot));
439
450
  }
440
451
  }
441
452
  }
442
- else {
443
- this._handleValueUpdates(target, event, memoryEvents, version, (event) => event.path[event.path.length - 1], (event, key) => {
444
- throw new Error('should not happen');
445
- }, (event) => ({
446
- id: event.path[event.path.length - 2],
447
- tag: event.path[event.path.length - 1],
448
- }), (id, tags) => botUpdated(id, {
449
- tags,
450
- }), (id, tag, val) => botUpdated(id, {
451
- tags: {
452
- [tag]: val,
453
- },
454
- }));
455
- }
456
453
  }
457
- }
458
- else if (type === this._masks) {
459
- for (let event of events) {
460
- // Update the current target so that the event
461
- // path is calculated from the bots map.
462
- // see https://github.com/yjs/yjs/blob/5244755879daaa7b5a1ca64e6af617cdbb110462/src/utils/YEvent.js#L63
463
- event.currentTarget = this._masks;
464
- const target = event.target;
465
- this._handleValueUpdates(target, event, memoryEvents, version, (event) => event.path[event.path.length - 1], (event, key) => parseTagMaskId(key), (event) => parseTagMaskId(event.path[event.path.length - 1]), (id, tags) => botUpdated(id, {
466
- masks: {
467
- [this.space]: tags,
468
- },
454
+ else {
455
+ this._handleValueUpdates(target, event, memoryEvents, version, (event) => event.path[event.path.length - 1], (event, key) => {
456
+ throw new Error('should not happen');
457
+ }, (event) => ({
458
+ id: event.path[event.path.length - 2],
459
+ tag: event.path[event.path.length - 1],
460
+ }), (id, tags) => botUpdated(id, {
461
+ tags,
469
462
  }), (id, tag, val) => botUpdated(id, {
470
- masks: {
471
- [this.space]: {
472
- [tag]: val,
473
- },
463
+ tags: {
464
+ [tag]: val,
474
465
  },
475
466
  }));
476
467
  }
477
468
  }
478
469
  }
479
- this._currentVersion = {
480
- currentSite: this._currentSite,
481
- remoteSite: this._remoteSite,
482
- vector: version,
483
- };
484
- yield this._internalPartition.applyEvents(memoryEvents);
485
- this._onVersionUpdated.next(this._currentVersion);
486
- });
470
+ else if (type === this._masks) {
471
+ for (let event of events) {
472
+ // Update the current target so that the event
473
+ // path is calculated from the bots map.
474
+ // see https://github.com/yjs/yjs/blob/5244755879daaa7b5a1ca64e6af617cdbb110462/src/utils/YEvent.js#L63
475
+ event.currentTarget = this._masks;
476
+ const target = event.target;
477
+ this._handleValueUpdates(target, event, memoryEvents, version, (event) => event.path[event.path.length - 1], (event, key) => parseTagMaskId(key), (event) => parseTagMaskId(event.path[event.path.length - 1]), (id, tags) => botUpdated(id, {
478
+ masks: {
479
+ [this.space]: tags,
480
+ },
481
+ }), (id, tag, val) => botUpdated(id, {
482
+ masks: {
483
+ [this.space]: {
484
+ [tag]: val,
485
+ },
486
+ },
487
+ }));
488
+ }
489
+ }
490
+ }
491
+ this._currentVersion = {
492
+ currentSite: this._currentSite,
493
+ remoteSite: this._remoteSite,
494
+ vector: version,
495
+ };
496
+ await this._internalPartition.applyEvents(memoryEvents);
497
+ this._onVersionUpdated.next(this._currentVersion);
487
498
  }
488
499
  _mapToBot(id, map) {
489
500
  let tags = {};
@@ -527,7 +538,10 @@ export class RemoteYjsPartitionImpl extends RemoteYjsSharedDocument {
527
538
  text = new Text(convertToString(val));
528
539
  map.set(valueId, text);
529
540
  }
530
- const version = Object.assign(Object.assign({}, newVal.version), { [this._currentSite]: getClock(doc, this._localId) });
541
+ const version = {
542
+ ...newVal.version,
543
+ [this._currentSite]: getClock(doc, this._localId),
544
+ };
531
545
  if (text instanceof Text) {
532
546
  for (let ops of newVal.operations) {
533
547
  let index = 0;