@casual-simulation/aux-common 3.3.11 → 3.3.13

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 (38) hide show
  1. package/bots/BotEvents.d.ts +30 -1
  2. package/bots/BotEvents.js +16 -0
  3. package/bots/BotEvents.js.map +1 -1
  4. package/common/DenialReason.d.ts +4 -1
  5. package/documents/RemoteYjsSharedDocument.d.ts +52 -0
  6. package/documents/RemoteYjsSharedDocument.js +304 -0
  7. package/documents/RemoteYjsSharedDocument.js.map +1 -0
  8. package/documents/SharedDocument.d.ts +449 -0
  9. package/documents/SharedDocument.js +2 -0
  10. package/documents/SharedDocument.js.map +1 -0
  11. package/documents/SharedDocumentConfig.d.ts +65 -0
  12. package/documents/SharedDocumentConfig.js +2 -0
  13. package/documents/SharedDocumentConfig.js.map +1 -0
  14. package/documents/SharedDocumentFactories.d.ts +20 -0
  15. package/documents/SharedDocumentFactories.js +29 -0
  16. package/documents/SharedDocumentFactories.js.map +1 -0
  17. package/documents/YjsSharedDocument.d.ts +152 -0
  18. package/documents/YjsSharedDocument.js +628 -0
  19. package/documents/YjsSharedDocument.js.map +1 -0
  20. package/documents/index.d.ts +6 -0
  21. package/documents/index.js +6 -0
  22. package/documents/index.js.map +1 -0
  23. package/documents/test/DocumentTests.d.ts +6 -0
  24. package/documents/test/DocumentTests.js +497 -0
  25. package/documents/test/DocumentTests.js.map +1 -0
  26. package/package.json +2 -2
  27. package/partitions/AuxPartitionConfig.d.ts +5 -4
  28. package/partitions/PartitionAuthSource.d.ts +4 -0
  29. package/partitions/RemoteYjsPartition.d.ts +8 -50
  30. package/partitions/RemoteYjsPartition.js +65 -364
  31. package/partitions/RemoteYjsPartition.js.map +1 -1
  32. package/partitions/YjsPartition.d.ts +4 -28
  33. package/partitions/YjsPartition.js +7 -93
  34. package/partitions/YjsPartition.js.map +1 -1
  35. package/rpc/ErrorCodes.d.ts +1 -1
  36. package/rpc/ErrorCodes.js.map +1 -1
  37. package/websockets/InstRecordsClient.js +1 -1
  38. package/websockets/InstRecordsClient.js.map +1 -1
@@ -1,59 +1,27 @@
1
- import { Observable, Subject, BehaviorSubject } from 'rxjs';
1
+ import { Observable } from 'rxjs';
2
2
  import { AuxPartitionRealtimeStrategy, YjsPartition } from './AuxPartition';
3
3
  import { BotAction, Bot, UpdatedBot, StateUpdatedEvent, BotsState } from '../bots';
4
4
  import { PartitionConfig, YjsClientPartitionConfig, RemoteYjsPartitionConfig } from './AuxPartitionConfig';
5
- import { Doc } from 'yjs';
6
- import { Action, RemoteActions, StatusUpdate, CurrentVersion } from '../common';
7
- import { InstRecordsClient } from '../websockets';
5
+ import { RemoteActions } from '../common';
6
+ import { ClientEvent, InstRecordsClient, MaxInstSizeReachedClientError, RateLimitExceededMessage } from '../websockets';
8
7
  import { PartitionAuthSource } from './PartitionAuthSource';
8
+ import { RemoteYjsSharedDocument } from '../documents/RemoteYjsSharedDocument';
9
9
  /**
10
10
  * Attempts to create a YjsPartition from the given config.
11
11
  * @param config The config.
12
12
  * @param authSource The auth source.
13
13
  */
14
14
  export declare function createRemoteClientYjsPartition(config: PartitionConfig, authSource: PartitionAuthSource): YjsPartition;
15
- export declare class RemoteYjsPartitionImpl implements YjsPartition {
16
- protected _onVersionUpdated: BehaviorSubject<CurrentVersion>;
17
- private _onUpdates;
18
- protected _onError: Subject<any>;
19
- protected _onEvents: Subject<Action[]>;
20
- protected _onStatusUpdated: Subject<StatusUpdate>;
21
- protected _hasRegisteredSubs: boolean;
22
- private _sub;
15
+ export declare class RemoteYjsPartitionImpl extends RemoteYjsSharedDocument implements YjsPartition {
23
16
  private _emittedMaxSizeReached;
24
- private _localId;
25
- private _remoteId;
26
- private _doc;
27
17
  private _bots;
28
18
  private _masks;
29
- private _client;
30
- private _currentVersion;
31
19
  private _internalPartition;
32
- private _isLocalTransaction;
33
- private _isRemoteUpdate;
34
- private _static;
35
- private _skipInitialLoad;
36
- private _sendInitialUpdates;
37
- private _watchingBranch;
38
- private _synced;
39
- private _authorized;
40
- private _recordName;
41
- private _inst;
42
- private _branch;
43
- private _temporary;
44
- private _readOnly;
45
20
  private _remoteEvents;
46
- private _authSource;
47
- private _indexeddb;
48
- private _persistence;
49
21
  get onBotsAdded(): Observable<Bot[]>;
50
22
  get onBotsRemoved(): Observable<string[]>;
51
23
  get onBotsUpdated(): Observable<UpdatedBot[]>;
52
24
  get onStateUpdated(): Observable<StateUpdatedEvent>;
53
- get onVersionUpdated(): Observable<CurrentVersion>;
54
- get onError(): Observable<any>;
55
- get onEvents(): Observable<Action[]>;
56
- get onStatusUpdated(): Observable<StatusUpdate>;
57
25
  unsubscribe(): void;
58
26
  get closed(): boolean;
59
27
  get state(): BotsState;
@@ -62,23 +30,13 @@ export declare class RemoteYjsPartitionImpl implements YjsPartition {
62
30
  get space(): string;
63
31
  set space(value: string);
64
32
  get realtimeStrategy(): AuxPartitionRealtimeStrategy;
65
- get site(): string;
66
- get onUpdates(): Observable<string[]>;
67
- get doc(): Doc;
68
- private get _remoteSite();
69
- private get _currentSite();
70
33
  constructor(client: InstRecordsClient, authSource: PartitionAuthSource, config: YjsClientPartitionConfig | RemoteYjsPartitionConfig);
71
34
  applyEvents(events: BotAction[]): Promise<BotAction[]>;
72
- init(): Promise<void>;
73
- connect(): void;
74
35
  sendRemoteEvents(events: RemoteActions[]): Promise<void>;
75
- enableCollaboration(): Promise<void>;
76
- private _initializePartitionWithoutLoading;
77
- private _requestBranch;
78
- private _watchBranch;
79
- private _updateSynced;
36
+ protected _handleClientEvent(event: ClientEvent): void;
37
+ protected _onMaxSizeReached(event: MaxInstSizeReachedClientError): void;
38
+ protected _onRateLimitExceeded(event: RateLimitExceededMessage): void;
80
39
  private _applyEvents;
81
- private _applyUpdates;
82
40
  private _processTransaction;
83
41
  private _mapToBot;
84
42
  /**
@@ -18,18 +18,17 @@ var __rest = (this && this.__rest) || function (s, e) {
18
18
  }
19
19
  return t;
20
20
  };
21
- import { isTagEdit, preserve, del, insert, edit, } from '../bots';
22
- import { Subscription, Subject, BehaviorSubject, firstValueFrom, } from 'rxjs';
23
- import { breakIntoIndividualEvents, botAdded, createBot, botRemoved, hasValue, botUpdated, action, ON_REMOTE_DATA_ACTION_NAME, ON_REMOTE_WHISPER_ACTION_NAME, asyncResult, asyncError, convertToString, ON_SPACE_MAX_SIZE_REACHED, ON_SPACE_RATE_LIMIT_EXCEEDED_ACTION_NAME, } from '../bots';
24
- import { Doc, Text, Map, applyUpdate, YMapEvent, createAbsolutePositionFromRelativePosition, YTextEvent, encodeStateAsUpdate, } from 'yjs';
21
+ import { isTagEdit, preserve, del, insert, edit, ON_REMOTE_WHISPER_ACTION_NAME, ON_REMOTE_DATA_ACTION_NAME, } from '../bots';
22
+ import { BehaviorSubject, } from 'rxjs';
23
+ 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
+ import { Text, Map, applyUpdate, YMapEvent, createAbsolutePositionFromRelativePosition, YTextEvent, } from 'yjs';
25
25
  import { MemoryPartitionImpl } from './MemoryPartition';
26
26
  import { createRelativePositionFromStateVector, getClock, getStateVector, } from '../yjs/YjsHelpers';
27
27
  import { fromByteArray, toByteArray } from 'base64-js';
28
- import { filter, startWith } from 'rxjs/operators';
29
28
  import { YjsPartitionImpl } from './YjsPartition';
30
29
  import { ensureTagIsSerializable, supportsRemoteEvent } from './PartitionUtils';
31
- import { device, getConnectionId, } from '../common';
32
- import { YjsIndexedDBPersistence } from '../yjs/YjsIndexedDBPersistence';
30
+ import { device, } from '../common';
31
+ import { RemoteYjsSharedDocument } from '../documents/RemoteYjsSharedDocument';
33
32
  /**
34
33
  * Attempts to create a YjsPartition from the given config.
35
34
  * @param config The config.
@@ -41,8 +40,7 @@ export function createRemoteClientYjsPartition(config, authSource) {
41
40
  }
42
41
  return undefined;
43
42
  }
44
- const APPLY_UPDATES_TO_INST_TRANSACTION_ORIGIN = '__apply_updates_to_inst';
45
- export class RemoteYjsPartitionImpl {
43
+ export class RemoteYjsPartitionImpl extends RemoteYjsSharedDocument {
46
44
  get onBotsAdded() {
47
45
  return this._internalPartition.onBotsAdded;
48
46
  }
@@ -55,18 +53,6 @@ export class RemoteYjsPartitionImpl {
55
53
  get onStateUpdated() {
56
54
  return this._internalPartition.onStateUpdated;
57
55
  }
58
- get onVersionUpdated() {
59
- return this._onVersionUpdated;
60
- }
61
- get onError() {
62
- return this._onError;
63
- }
64
- get onEvents() {
65
- return this._onEvents;
66
- }
67
- get onStatusUpdated() {
68
- return this._onStatusUpdated;
69
- }
70
56
  unsubscribe() {
71
57
  return this._sub.unsubscribe();
72
58
  }
@@ -85,51 +71,13 @@ export class RemoteYjsPartitionImpl {
85
71
  get realtimeStrategy() {
86
72
  return this._static ? 'delayed' : 'immediate';
87
73
  }
88
- get site() {
89
- return this._currentSite;
90
- }
91
- get onUpdates() {
92
- return this._onUpdates.pipe(startWith([fromByteArray(encodeStateAsUpdate(this._doc))]));
93
- }
94
- get doc() {
95
- return this._doc;
96
- }
97
- get _remoteSite() {
98
- return this._remoteId.toString();
99
- }
100
- get _currentSite() {
101
- return this._localId.toString();
102
- }
103
74
  constructor(client, authSource, config) {
104
- this._onError = new Subject();
105
- this._onEvents = new Subject();
106
- this._onStatusUpdated = new Subject();
107
- this._hasRegisteredSubs = false;
108
- this._sub = new Subscription();
75
+ super(client, authSource, config);
109
76
  this._emittedMaxSizeReached = false;
110
- this._doc = new Doc();
111
- this._isLocalTransaction = true;
112
- this._isRemoteUpdate = false;
113
- this._sendInitialUpdates = false;
114
77
  this.type = 'yjs';
115
78
  this.private = config.private || false;
116
- this._client = client;
117
- this._static = config.static;
118
- this._skipInitialLoad = config.skipInitialLoad;
119
79
  this._remoteEvents =
120
80
  'remoteEvents' in config ? config.remoteEvents : true;
121
- this._recordName = config.recordName;
122
- this._inst = config.inst;
123
- this._branch = config.branch;
124
- this._temporary = config.temporary;
125
- this._persistence = config.localPersistence;
126
- this._synced = false;
127
- this._authorized = false;
128
- this._authSource = authSource;
129
- // static implies read only
130
- this._readOnly = config.readOnly || this._static || false;
131
- this._localId = this._doc.clientID;
132
- this._remoteId = new Doc().clientID;
133
81
  this._bots = this._doc.getMap('bots');
134
82
  this._masks = this._doc.getMap('masks');
135
83
  this._doc.on('afterTransaction', (transaction) => {
@@ -141,7 +89,6 @@ export class RemoteYjsPartitionImpl {
141
89
  vector: {},
142
90
  };
143
91
  this._onVersionUpdated = new BehaviorSubject(this._currentVersion);
144
- this._onUpdates = new Subject();
145
92
  this._internalPartition = new MemoryPartitionImpl({
146
93
  type: 'memory',
147
94
  initialState: {},
@@ -194,26 +141,6 @@ export class RemoteYjsPartitionImpl {
194
141
  return [];
195
142
  });
196
143
  }
197
- init() {
198
- return __awaiter(this, void 0, void 0, function* () { });
199
- }
200
- connect() {
201
- var _a, _b;
202
- if (!this._temporary && ((_a = this._persistence) === null || _a === void 0 ? void 0 : _a.saveToIndexedDb)) {
203
- console.log('[RemoteYjsPartition] Using IndexedDB persistence');
204
- const name = `${(_b = this._recordName) !== null && _b !== void 0 ? _b : ''}/${this._inst}/${this._branch}`;
205
- this._indexeddb = new YjsIndexedDBPersistence(name, this._doc);
206
- }
207
- if (this._skipInitialLoad) {
208
- this._initializePartitionWithoutLoading();
209
- }
210
- else if (this._static) {
211
- this._requestBranch();
212
- }
213
- else {
214
- this._watchBranch();
215
- }
216
- }
217
144
  sendRemoteEvents(events) {
218
145
  return __awaiter(this, void 0, void 0, function* () {
219
146
  if (this._readOnly || !this._remoteEvents) {
@@ -310,7 +237,7 @@ export class RemoteYjsPartitionImpl {
310
237
  else if (event.event.type === 'apply_updates_to_inst') {
311
238
  const action = event.event;
312
239
  try {
313
- this._applyUpdates(action.updates.map((u) => u.update), APPLY_UPDATES_TO_INST_TRANSACTION_ORIGIN);
240
+ this.applyStateUpdates(action.updates);
314
241
  this._onEvents.next([
315
242
  asyncResult(event.taskId, null, false),
316
243
  ]);
@@ -322,11 +249,7 @@ export class RemoteYjsPartitionImpl {
322
249
  else if (event.event.type === 'get_current_inst_update') {
323
250
  const action = event.event;
324
251
  try {
325
- const update = {
326
- id: 0,
327
- timestamp: Date.now(),
328
- update: fromByteArray(encodeStateAsUpdate(this._doc)),
329
- };
252
+ const update = this.getStateUpdate();
330
253
  this._onEvents.next([
331
254
  asyncResult(event.taskId, update, false),
332
255
  ]);
@@ -345,277 +268,56 @@ export class RemoteYjsPartitionImpl {
345
268
  }
346
269
  });
347
270
  }
348
- enableCollaboration() {
349
- return __awaiter(this, void 0, void 0, function* () {
350
- this._static = false;
351
- this._skipInitialLoad = false;
352
- this._sendInitialUpdates = true;
353
- this._synced = false;
354
- const promise = firstValueFrom(this._onStatusUpdated.pipe(filter((u) => u.type === 'sync' && u.synced)));
355
- this._watchBranch();
356
- yield promise;
357
- });
358
- }
359
- _initializePartitionWithoutLoading() {
360
- var _a;
361
- return __awaiter(this, void 0, void 0, function* () {
362
- this._onStatusUpdated.next({
363
- type: 'connection',
364
- connected: true,
365
- });
366
- const indicator = this._client.connection.indicator;
367
- const connectionId = indicator
368
- ? getConnectionId(indicator)
369
- : 'missing-connection-id';
370
- this._onStatusUpdated.next({
371
- type: 'authentication',
372
- authenticated: true,
373
- info: (_a = this._client.connection.info) !== null && _a !== void 0 ? _a : {
374
- connectionId: connectionId,
375
- sessionId: null,
376
- userId: null,
377
- },
378
- });
379
- this._updateSynced(true);
380
- });
381
- }
382
- _requestBranch() {
383
- this._client
384
- .getBranchUpdates(this._recordName, this._inst, this._branch)
385
- .subscribe({
386
- next: (updates) => {
387
- this._onStatusUpdated.next({
388
- type: 'connection',
389
- connected: true,
390
- });
391
- this._onStatusUpdated.next({
392
- type: 'authentication',
393
- authenticated: true,
394
- info: this._client.connection.info,
395
- });
396
- this._updateSynced(true);
397
- this._applyUpdates(updates.updates);
398
- if (!this._static) {
399
- // the partition has been unlocked while getting the branch
400
- this._watchBranch();
401
- }
402
- },
403
- error: (err) => this._onError.next(err),
404
- });
405
- }
406
- _watchBranch() {
407
- if (this._watchingBranch) {
408
- return;
271
+ _handleClientEvent(event) {
272
+ if (event.action.type === 'device') {
273
+ if (event.action.event.type === 'action') {
274
+ const remoteAction = event.action.event;
275
+ this._onEvents.next([
276
+ action(ON_REMOTE_DATA_ACTION_NAME, null, null, {
277
+ name: remoteAction.eventName,
278
+ that: remoteAction.argument,
279
+ remoteId: event.action.connection.connectionId,
280
+ }),
281
+ action(ON_REMOTE_WHISPER_ACTION_NAME, null, null, {
282
+ name: remoteAction.eventName,
283
+ that: remoteAction.argument,
284
+ playerId: event.action.connection.connectionId,
285
+ }),
286
+ ]);
287
+ }
288
+ 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);
290
+ this._onEvents.next([newEvent]);
291
+ }
292
+ else {
293
+ this._onEvents.next([event.action]);
294
+ }
409
295
  }
410
- this._watchingBranch = true;
411
- this._sub.add(this._client.connection.connectionState.subscribe({
412
- next: (state) => {
413
- const connected = state.connected;
414
- this._onStatusUpdated.next({
415
- type: 'connection',
416
- connected: !!connected,
417
- });
418
- if (connected) {
419
- this._onStatusUpdated.next({
420
- type: 'authentication',
421
- authenticated: true,
422
- info: state.info,
423
- });
424
- }
425
- else {
426
- this._updateSynced(false);
427
- }
428
- },
429
- error: (err) => this._onError.next(err),
430
- }));
431
- this._sub.add(this._client
432
- .watchBranchUpdates({
433
- type: 'repo/watch_branch',
434
- recordName: this._recordName,
435
- inst: this._inst,
436
- branch: this._branch,
437
- temporary: this._temporary,
438
- })
439
- .subscribe({
440
- next: (event) => {
441
- // The partition should become synced if it was not synced
442
- // and it just got some new data.
443
- if (!this._synced && event.type === 'updates') {
444
- if (this._sendInitialUpdates) {
445
- this._sendInitialUpdates = false;
446
- const update = encodeStateAsUpdate(this._doc);
447
- const updates = [fromByteArray(update)];
448
- this._client.addUpdates(this._recordName, this._inst, this._branch, updates);
449
- }
450
- this._updateSynced(true);
451
- }
452
- if (event.type === 'updates') {
453
- this._applyUpdates(event.updates);
454
- }
455
- else if (event.type === 'event') {
456
- if (event.action.type === 'device') {
457
- if (event.action.event.type === 'action') {
458
- const remoteAction = event.action
459
- .event;
460
- this._onEvents.next([
461
- action(ON_REMOTE_DATA_ACTION_NAME, null, null, {
462
- name: remoteAction.eventName,
463
- that: remoteAction.argument,
464
- remoteId: event.action.connection
465
- .connectionId,
466
- }),
467
- action(ON_REMOTE_WHISPER_ACTION_NAME, null, null, {
468
- name: remoteAction.eventName,
469
- that: remoteAction.argument,
470
- playerId: event.action.connection
471
- .connectionId,
472
- }),
473
- ]);
474
- }
475
- else if (hasValue(event.action.taskId)) {
476
- const newEvent = device(event.action.connection, Object.assign(Object.assign({}, event.action.event), { taskId: event.action.taskId, playerId: event.action.connection
477
- .connectionId }), event.action.taskId);
478
- this._onEvents.next([newEvent]);
479
- }
480
- else {
481
- this._onEvents.next([event.action]);
482
- }
483
- }
484
- else {
485
- this._onEvents.next([event.action]);
486
- }
487
- }
488
- else if (event.type === 'error') {
489
- if (event.kind === 'max_size_reached') {
490
- if (!this._emittedMaxSizeReached) {
491
- console.log('[RemoteYjsPartition] Max size reached!', this.space);
492
- this._emittedMaxSizeReached = true;
493
- this._onEvents.next([
494
- action(ON_SPACE_MAX_SIZE_REACHED, null, null, {
495
- space: this.space,
496
- maxSizeInBytes: event.maxBranchSizeInBytes,
497
- neededSizeInBytes: event.neededBranchSizeInBytes,
498
- }),
499
- ]);
500
- }
501
- }
502
- else if (event.kind === 'error') {
503
- const errorCode = event.info.errorCode;
504
- if (errorCode === 'not_authorized' ||
505
- errorCode ===
506
- 'subscription_limit_reached' ||
507
- errorCode === 'inst_not_found' ||
508
- errorCode === 'record_not_found' ||
509
- errorCode === 'invalid_record_key' ||
510
- errorCode === 'invalid_token' ||
511
- errorCode ===
512
- 'unacceptable_connection_id' ||
513
- errorCode ===
514
- 'unacceptable_connection_token' ||
515
- errorCode === 'user_is_banned' ||
516
- errorCode === 'not_logged_in' ||
517
- errorCode === 'session_expired') {
518
- this._onStatusUpdated.next({
519
- type: 'authorization',
520
- authorized: false,
521
- error: event.info,
522
- });
523
- this._authSource.sendAuthRequest({
524
- type: 'request',
525
- kind: 'not_authorized',
526
- errorCode: event.info.errorCode,
527
- errorMessage: event.info.errorMessage,
528
- origin: this._client.connection.origin,
529
- reason: event.info.reason,
530
- resource: {
531
- type: 'inst',
532
- recordName: this._recordName,
533
- inst: this._inst,
534
- },
535
- });
536
- }
537
- }
538
- }
539
- else if (event.type === 'repo/watch_branch_result') {
540
- if (event.success === false) {
541
- const errorCode = event.errorCode;
542
- if (errorCode === 'not_authorized' ||
543
- errorCode ===
544
- 'subscription_limit_reached' ||
545
- errorCode === 'inst_not_found' ||
546
- errorCode === 'record_not_found' ||
547
- errorCode === 'invalid_record_key' ||
548
- errorCode === 'invalid_token' ||
549
- errorCode ===
550
- 'unacceptable_connection_id' ||
551
- errorCode ===
552
- 'unacceptable_connection_token' ||
553
- errorCode === 'user_is_banned' ||
554
- errorCode === 'not_logged_in' ||
555
- errorCode === 'session_expired') {
556
- const { type } = event, error = __rest(event, ["type"]);
557
- this._onStatusUpdated.next({
558
- type: 'authorization',
559
- authorized: false,
560
- error: error,
561
- });
562
- this._authSource.sendAuthRequest({
563
- type: 'request',
564
- kind: 'not_authorized',
565
- errorCode: event.errorCode,
566
- errorMessage: event.errorMessage,
567
- origin: this._client.connection.origin,
568
- reason: event.reason,
569
- resource: {
570
- type: 'inst',
571
- recordName: this._recordName,
572
- inst: this._inst,
573
- },
574
- });
575
- }
576
- }
577
- }
578
- },
579
- error: (err) => this._onError.next(err),
580
- }));
581
- this._sub.add(this._client.watchRateLimitExceeded().subscribe((event) => {
582
- console.error('[RemoteYjsPartition] Rate limit exceeded!', event);
296
+ else {
297
+ super._handleClientEvent(event);
298
+ }
299
+ }
300
+ _onMaxSizeReached(event) {
301
+ super._onMaxSizeReached(event);
302
+ if (!this._emittedMaxSizeReached) {
303
+ console.log('[RemoteYjsPartition] Max size reached!', this.recordName, this.address);
304
+ this._emittedMaxSizeReached = true;
583
305
  this._onEvents.next([
584
- action(ON_SPACE_RATE_LIMIT_EXCEEDED_ACTION_NAME, null, null, {
306
+ action(ON_SPACE_MAX_SIZE_REACHED, null, null, {
585
307
  space: this.space,
308
+ maxSizeInBytes: event.maxBranchSizeInBytes,
309
+ neededSizeInBytes: event.neededBranchSizeInBytes,
586
310
  }),
587
311
  ]);
588
- }));
589
- const updateHandler = (update, origin, doc, transaction) => {
590
- if (this._readOnly) {
591
- return;
592
- }
593
- if (transaction &&
594
- (transaction.local ||
595
- origin === APPLY_UPDATES_TO_INST_TRANSACTION_ORIGIN)) {
596
- const updates = [fromByteArray(update)];
597
- this._client.addUpdates(this._recordName, this._inst, this._branch, updates);
598
- this._onUpdates.next(updates);
599
- }
600
- };
601
- this._doc.on('update', updateHandler);
602
- this._sub.add(new Subscription(() => {
603
- this._doc.off('update', updateHandler);
604
- }));
605
- }
606
- _updateSynced(synced) {
607
- if (synced && !this._authorized) {
608
- this._authorized = true;
609
- this._onStatusUpdated.next({
610
- type: 'authorization',
611
- authorized: true,
612
- });
613
312
  }
614
- this._synced = synced;
615
- this._onStatusUpdated.next({
616
- type: 'sync',
617
- synced: synced,
618
- });
313
+ }
314
+ _onRateLimitExceeded(event) {
315
+ super._onRateLimitExceeded(event);
316
+ this._onEvents.next([
317
+ action(ON_SPACE_RATE_LIMIT_EXCEEDED_ACTION_NAME, null, null, {
318
+ space: this.space,
319
+ }),
320
+ ]);
619
321
  }
620
322
  _applyEvents(events) {
621
323
  try {
@@ -689,18 +391,17 @@ export class RemoteYjsPartitionImpl {
689
391
  this._isLocalTransaction = false;
690
392
  }
691
393
  }
692
- _applyUpdates(updates, transactionOrigin) {
693
- try {
694
- this._isRemoteUpdate = true;
695
- for (let updateBase64 of updates) {
696
- const update = toByteArray(updateBase64);
697
- applyUpdate(this._doc, update, transactionOrigin);
698
- }
699
- }
700
- finally {
701
- this._isRemoteUpdate = false;
702
- }
703
- }
394
+ // private _applyUpdates(updates: string[], transactionOrigin?: string) {
395
+ // try {
396
+ // this._isRemoteUpdate = true;
397
+ // for (let updateBase64 of updates) {
398
+ // const update = toByteArray(updateBase64);
399
+ // applyUpdate(this._doc, update, transactionOrigin);
400
+ // }
401
+ // } finally {
402
+ // this._isRemoteUpdate = false;
403
+ // }
404
+ // }
704
405
  _processTransaction(transaction) {
705
406
  return __awaiter(this, void 0, void 0, function* () {
706
407
  let memoryEvents = [];