@casual-simulation/aux-common 3.4.6-alpha.14601027727 → 3.5.0-alpha.15117651144
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/AAGUID.d.ts +11 -0
- package/AAGUID.js +116 -0
- package/AAGUID.js.map +1 -0
- package/BlobPolyfill.js +20 -31
- package/BlobPolyfill.js.map +1 -1
- package/bots/AuxStateHelpers.js +9 -3
- package/bots/AuxStateHelpers.js.map +1 -1
- package/bots/Bot.d.ts +1 -1
- package/bots/Bot.js +10 -1
- package/bots/Bot.js.map +1 -1
- package/bots/BotCalculationContext.js.map +1 -1
- package/bots/BotCalculations.d.ts +3 -3
- package/bots/BotCalculations.js +5 -1
- package/bots/BotCalculations.js.map +1 -1
- package/bots/BotEvents.d.ts +20 -2
- package/bots/BotEvents.js +84 -17
- package/bots/BotEvents.js.map +1 -1
- package/bots/StateUpdatedEvent.js.map +1 -1
- package/bots/StoredAux.d.ts +1 -1
- package/bots/StoredAux.js.map +1 -1
- package/bots/test/BotCalculationContextTests.d.ts +0 -1
- package/bots/test/BotCalculationContextTests.js.map +1 -1
- package/common/PolicyPermissions.d.ts +224 -3
- package/common/PolicyPermissions.js +46 -0
- package/common/PolicyPermissions.js.map +1 -1
- package/common/RemoteActions.js +19 -6
- package/common/RemoteActions.js.map +1 -1
- package/common/StatusUpdateUtils.js +4 -1
- package/common/StatusUpdateUtils.js.map +1 -1
- package/common/Version.d.ts +22 -0
- package/common/Version.js +75 -0
- package/common/Version.js.map +1 -0
- package/common/WebConfig.d.ts +6 -6
- package/common/index.d.ts +1 -0
- package/common/index.js +1 -0
- package/common/index.js.map +1 -1
- package/documents/RemoteYjsSharedDocument.js +30 -54
- package/documents/RemoteYjsSharedDocument.js.map +1 -1
- package/documents/SharedDocumentFactories.js +7 -18
- package/documents/SharedDocumentFactories.js.map +1 -1
- package/documents/YjsSharedDocument.js +1 -12
- package/documents/YjsSharedDocument.js.map +1 -1
- package/documents/test/DocumentTests.js +15 -24
- package/documents/test/DocumentTests.js.map +1 -1
- package/forms/FormError.d.ts +43 -0
- package/forms/FormError.js +56 -0
- package/forms/FormError.js.map +1 -0
- package/forms/index.d.ts +2 -0
- package/forms/index.js +19 -0
- package/forms/index.js.map +1 -0
- package/http/GenericHttpInterface.d.ts +2 -1
- package/http/GenericHttpInterface.js.map +1 -1
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/index.js.map +1 -1
- package/package.json +7 -7
- package/partitions/AuxPartition.js +5 -1
- package/partitions/AuxPartition.js.map +1 -1
- package/partitions/AuxPartitionFactories.js +7 -18
- package/partitions/AuxPartitionFactories.js.map +1 -1
- package/partitions/MemoryPartition.js +25 -41
- package/partitions/MemoryPartition.js.map +1 -1
- package/partitions/OtherPlayersPartition.js +140 -159
- package/partitions/OtherPlayersPartition.js.map +1 -1
- package/partitions/PartitionAuthSource.d.ts +4 -0
- package/partitions/PartitionUtils.js +1 -1
- package/partitions/PartitionUtils.js.map +1 -1
- package/partitions/ProxyBridgePartition.js +32 -47
- package/partitions/ProxyBridgePartition.js.map +1 -1
- package/partitions/RemoteYjsPartition.js +235 -221
- package/partitions/RemoteYjsPartition.js.map +1 -1
- package/partitions/YjsPartition.js +215 -205
- package/partitions/YjsPartition.js.map +1 -1
- package/records/AuthUtils.d.ts +175 -0
- package/records/AuthUtils.js +335 -0
- package/records/AuthUtils.js.map +1 -0
- package/records/RecordKeys.d.ts +52 -0
- package/records/RecordKeys.js +131 -0
- package/records/RecordKeys.js.map +1 -0
- package/records/WebPush.d.ts +2 -0
- package/records/WebPush.js +19 -0
- package/records/WebPush.js.map +1 -0
- package/records/index.d.ts +4 -0
- package/records/index.js +21 -0
- package/records/index.js.map +1 -0
- package/rpc/ErrorCodes.d.ts +2 -2
- package/rpc/ErrorCodes.js.map +1 -1
- package/rpc/GenericRPCInterface.js +8 -4
- package/rpc/GenericRPCInterface.js.map +1 -1
- package/test/TestHelpers.js +2 -13
- package/test/TestHelpers.js.map +1 -1
- package/utils.d.ts +14 -0
- package/utils.js +18 -0
- package/utils.js.map +1 -1
- package/websockets/AuthenticatedConnectionClient.js +39 -10
- package/websockets/AuthenticatedConnectionClient.js.map +1 -1
- package/websockets/InstRecordsClient.js +18 -8
- package/websockets/InstRecordsClient.js.map +1 -1
- package/websockets/MemoryConnectionClient.d.ts +1 -1
- package/websockets/Utils.d.ts +33 -0
- package/websockets/Utils.js +82 -0
- package/websockets/Utils.js.map +1 -0
- package/websockets/WebsocketEvents.d.ts +18 -17
- package/websockets/WebsocketEvents.js.map +1 -1
- package/websockets/index.d.ts +1 -0
- package/websockets/index.js +1 -0
- package/websockets/index.js.map +1 -1
- package/yjs/YjsHelpers.js.map +1 -1
- package/yjs/YjsIndexedDBPersistence.js +53 -78
- package/yjs/YjsIndexedDBPersistence.js.map +1 -1
|
@@ -1,24 +1,4 @@
|
|
|
1
|
-
|
|
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
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
119
|
+
}
|
|
120
|
+
this._applyEvents(finalEvents);
|
|
121
|
+
return [];
|
|
143
122
|
}
|
|
144
|
-
sendRemoteEvents(events) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
150
|
-
if (
|
|
151
|
-
|
|
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 === '
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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,
|
|
144
|
+
asyncResult(event.taskId, count),
|
|
209
145
|
]);
|
|
210
|
-
}
|
|
211
|
-
|
|
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
|
-
|
|
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
|
-
|
|
246
|
-
|
|
247
|
-
|
|
185
|
+
this._onEvents.next([
|
|
186
|
+
asyncResult(event.taskId, partition.state, false),
|
|
187
|
+
]);
|
|
248
188
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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,
|
|
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
|
-
|
|
258
|
-
|
|
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
|
-
|
|
262
|
-
this.
|
|
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,
|
|
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
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
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
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
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
|
-
|
|
471
|
-
[
|
|
472
|
-
[tag]: val,
|
|
473
|
-
},
|
|
463
|
+
tags: {
|
|
464
|
+
[tag]: val,
|
|
474
465
|
},
|
|
475
466
|
}));
|
|
476
467
|
}
|
|
477
468
|
}
|
|
478
469
|
}
|
|
479
|
-
this.
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
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 =
|
|
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;
|