@cuboapp/crdt 1.0.12 → 1.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuboapp/crdt",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "CRDT for CUBO",
5
5
  "main": "src/index.ts",
6
6
  "repository": "git@github.com:cuboapp/crdt.git",
@@ -1,12 +1,13 @@
1
1
  import { keyBy, pick, uuid } from '@cuboapp/utils'
2
2
  import { computed, reactive } from 'vue'
3
- import { applyUpdate, Doc } from 'yjs'
4
3
  import { applyAwarenessUpdate, Awareness, encodeAwarenessUpdate, removeAwarenessStates } from 'y-protocols/awareness'
4
+ import { applyUpdate, Doc } from 'yjs'
5
5
 
6
6
  import { CUBO_CRDT_EVENT } from '../constants'
7
7
  import { CuboCrdtServerDocumentIncomingAction } from '../server'
8
8
  import { CuboCrdtKey } from '../types'
9
9
 
10
+ import { AsyncSerialQueue } from './queue'
10
11
  import {
11
12
  CuboCrdtClientDocOrigin,
12
13
  CuboCrdtClientDocUpdateOptions,
@@ -17,7 +18,6 @@ import {
17
18
  CuboCrdtClientSubscribeEvent,
18
19
  CuboCrdtClientUseOptions
19
20
  } from './types'
20
- import { AsyncSerialQueue } from './queue'
21
21
 
22
22
  export * from './types'
23
23
 
@@ -154,6 +154,8 @@ export class CuboCrdtClient<M> {
154
154
  // отписываемся на фронте
155
155
  this.listeners.get(entity)?.delete(subscribe_id)
156
156
 
157
+ this.store[storeKey]!.state.subscribed = false
158
+
157
159
  // очищаем стор
158
160
  if (clear !== false) {
159
161
  const item = this.store[storeKey]
@@ -351,7 +353,8 @@ export class CuboCrdtClient<M> {
351
353
  awareness = new Awareness(doc)
352
354
 
353
355
  awareness.on('update', ({ added, updated, removed }, origin) => {
354
- console.log('[CRDT] awarness update', origin)
356
+ // console.log('[CRDT] awarness update', origin)
357
+
355
358
  if (origin === 'remote') {
356
359
  return
357
360
  }
@@ -1,5 +1,6 @@
1
1
  import { cloneDeep } from '@cuboapp/utils'
2
2
  import { WsServerSocket } from '@cuboapp/ws'
3
+ import { applyAwarenessUpdate, encodeAwarenessUpdate, removeAwarenessStates } from 'y-protocols/awareness'
3
4
 
4
5
  import { CUBO_CRDT_EVENT } from '../constants'
5
6
  import { CuboCrdtAction } from '../types'
@@ -16,7 +17,6 @@ import {
16
17
  CuboCrdtServerUnsubscribeDto,
17
18
  CuboCrdtSocketClient
18
19
  } from './types'
19
- import { applyAwarenessUpdate, encodeAwarenessUpdate, removeAwarenessStates } from 'y-protocols/awareness'
20
20
 
21
21
  export * from './document'
22
22
  export * from './types'
@@ -99,7 +99,7 @@ export class CuboCrdtServer<M, A = {}, E extends Extract<keyof M, string> = Extr
99
99
  console.log('[CRDT] incoming event', data)
100
100
  }
101
101
 
102
- data.forEach((row: any) => {
102
+ for (const row of data) {
103
103
  const update = new Uint8Array(row.data)
104
104
 
105
105
  switch (row.action) {
@@ -114,10 +114,9 @@ export class CuboCrdtServer<M, A = {}, E extends Extract<keyof M, string> = Extr
114
114
  break
115
115
  case 'awareness':
116
116
  this.onAwarenessExternalUpdate(update, row)
117
-
118
117
  break
119
118
  }
120
- })
119
+ }
121
120
  })
122
121
 
123
122
  this.ws.registerHttpHandler('GET', '/stats', () => {
@@ -381,15 +380,16 @@ export class CuboCrdtServer<M, A = {}, E extends Extract<keyof M, string> = Extr
381
380
  }
382
381
 
383
382
  private onDocumentExternalUpdate(update: Uint8Array, action: CuboCrdtServerDocumentIncomingAction) {
384
- const document = this.getDocument(action.entity, action.entity_id)
385
-
386
- // console.log('onDocumentExternalUpdate', action)
387
-
383
+ let document = this.getDocument(action.entity, action.entity_id)
388
384
  if (!document) {
389
- console.warn('[CRDT] onDocumentExternalUpdate - document not found:', action.entity, action.entity_id)
390
- } else {
391
- document.applyUpdate(new Uint8Array(update), action.origin)
385
+ if (this.debug) {
386
+ console.warn('[CRDT] onDocumentExternalUpdate - document not found, creating:', action.entity, action.entity_id)
387
+ }
388
+
389
+ document = this.ensureDocument(action.entity as E, action.entity_id, true)
392
390
  }
391
+
392
+ document.applyUpdate(new Uint8Array(update), action.origin)
393
393
  }
394
394
 
395
395
  private onAwarenessExternalUpdate(update: Uint8Array, action: CuboCrdtServerDocumentIncomingAction) {
package/tsconfig.json CHANGED
@@ -9,11 +9,12 @@
9
9
  "target": "ES2021",
10
10
  "sourceMap": true,
11
11
  "outDir": "./dist",
12
- "baseUrl": "./",
12
+ "strict": false,
13
+ "rootDir": "./",
13
14
  "incremental": true,
14
15
  "skipLibCheck": true,
15
16
  "paths": {
16
- "@/*": ["src/*"]
17
+ "@/*": ["./src/*"]
17
18
  }
18
19
  },
19
20
  "include": ["src/**/*"],