@cocreate/crdt 1.3.14 → 1.3.18

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/CHANGELOG.md CHANGED
@@ -1,3 +1,31 @@
1
+ ## [1.3.18](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.3.17...v1.3.18) (2021-09-28)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * update dependencies ([cbccd8a](https://github.com/CoCreate-app/CoCreate-crdt/commit/cbccd8a65de0d6aaa477ee99fb3a4097e5b6056b))
7
+
8
+ ## [1.3.17](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.3.16...v1.3.17) (2021-09-28)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * crud true or false, defaults to true ([c2c01a2](https://github.com/CoCreate-app/CoCreate-crdt/commit/c2c01a2e958dd6740fbc4ac500f5eebed84b35ca))
14
+
15
+ ## [1.3.16](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.3.15...v1.3.16) (2021-09-27)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * sendPostion ([ef57991](https://github.com/CoCreate-app/CoCreate-crdt/commit/ef5799155665454eaf27efc3387310cae66a572b))
21
+
22
+ ## [1.3.15](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.3.14...v1.3.15) (2021-09-16)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * update dependencies ([ea01942](https://github.com/CoCreate-app/CoCreate-crdt/commit/ea01942819ff1b565f4bd893550fdff29aaddf7c))
28
+
1
29
  ## [1.3.14](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.3.13...v1.3.14) (2021-09-16)
2
30
 
3
31
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/crdt",
3
- "version": "1.3.14",
3
+ "version": "1.3.18",
4
4
  "description": "CoCreate crdt",
5
5
  "author": "CoCreate LLC",
6
6
  "license": "SEE LICENSE",
@@ -15,9 +15,9 @@
15
15
  "hosting": "node ./node_modules/@cocreate/hosting/src/index.js"
16
16
  },
17
17
  "dependencies": {
18
- "@cocreate/crud-client": "^1.2.22",
19
- "@cocreate/cursors": "^1.4.9",
20
- "@cocreate/utils": "^1.1.16",
18
+ "@cocreate/crud-client": "^1.2.25",
19
+ "@cocreate/cursors": "^1.5.2",
20
+ "@cocreate/utils": "^1.1.19",
21
21
  "y-indexeddb": "^9.0.6",
22
22
  "y-websocket": "^1.3.16",
23
23
  "yjs": "^13.5.11"
package/src/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ /*globals config, atob, btoa, CustomEvent*/
2
+
1
3
  import * as Y from 'yjs';
2
4
  import { WebsocketProvider } from 'y-websocket';
3
5
  // import { IndexeddbPersistence } from 'y-indexeddb';
@@ -24,7 +26,7 @@ class CoCreateCRDTClass {
24
26
  */
25
27
  init(info) {
26
28
  try {
27
- this.createDoc(info)
29
+ this.createDoc(info);
28
30
  } catch(e) {
29
31
  console.log('Invalid param', e);
30
32
  }
@@ -46,7 +48,7 @@ class CoCreateCRDTClass {
46
48
 
47
49
  const crdtDoc = this.doc;
48
50
  const url_socket = this.__getSocketUrl();
49
- const shardType = crdtDoc.getText(typeName);
51
+ const sharedType = crdtDoc.getText(typeName);
50
52
 
51
53
  var socketProvider = new WebsocketProvider(url_socket, docName, crdtDoc);
52
54
 
@@ -59,7 +61,7 @@ class CoCreateCRDTClass {
59
61
 
60
62
  this._awarenessListener = event => {
61
63
  const f = clientId => {
62
- this.updateSelection(crdtDoc, typeName, shardType, this._cursors, clientId, awareness);
64
+ this.updateSelection(crdtDoc, typeName, sharedType, this._cursors, clientId, awareness);
63
65
  };
64
66
  event.added.forEach(f);
65
67
  event.removed.forEach(f);
@@ -107,10 +109,10 @@ class CoCreateCRDTClass {
107
109
 
108
110
  _registerUpdateEvent(docName, typeName) {
109
111
  const crdtDoc = docName.doc;
110
- const shardType = crdtDoc.getText(typeName);
112
+ const sharedType = crdtDoc.getText(typeName);
111
113
  let self = this;
112
114
 
113
- shardType.observe((event) => {
115
+ sharedType.observe((event) => {
114
116
  self._crdtUpdateEvent(event, typeName);
115
117
  });
116
118
  }
@@ -225,12 +227,12 @@ class CoCreateCRDTClass {
225
227
  }
226
228
 
227
229
  generateDocName(info) {
228
- let docName = {org: config.organization_Id, collection: info.collection, document_id: info.document_id}
230
+ let docName = {org: config.organization_Id, collection: info.collection, document_id: info.document_id};
229
231
  return btoa(JSON.stringify(docName));
230
232
  }
231
233
 
232
234
  generateTypeName(info) {
233
- let nameId = {org: config.organization_Id, collection: info.collection, document_id: info.document_id, name: info.name}
235
+ let nameId = {org: config.organization_Id, collection: info.collection, document_id: info.document_id, name: info.name};
234
236
  return btoa(JSON.stringify(nameId));
235
237
  }
236
238
 
@@ -249,31 +251,31 @@ class CoCreateCRDTClass {
249
251
  let docName = this.generateDocName(info);
250
252
  let typeName = this.generateTypeName(info);
251
253
  if (!this.docs[docName]){
252
- this.init(info)
253
- };
254
+ this.init(info);
255
+ }
254
256
  if (info.updateCrud != false) info.updateCrud = true;
255
257
 
256
258
  if (docName) {
257
259
  let oldData = this.docs[docName].doc.getText(typeName).toString();
258
260
  let textValue = info['value'].toString();
259
261
  if (oldData && oldData.length > 0) {
260
- this.deleteText({collection: info['collection'], document_id: info['document_id'], name: info['name'], position: 0, length: Math.max(oldData.length, textValue.length), crud: info['crud']});
262
+ this.deleteText({collection: info.collection, document_id: info.document_id, name: info.name, position: 0, length: Math.max(oldData.length, textValue.length), crud: info['crud']});
261
263
  }
262
- this.insertText({ collection: info.collection, document_id: info.document_id, name: info.name, position: 0, value: textValue });
264
+ this.insertText({ collection: info.collection, document_id: info.document_id, name: info.name, position: 0, value: textValue, crud: info.crud });
263
265
  }
264
- if (info.crud != false) {
266
+ if (info.crud != 'false') {
265
267
  crud.updateDocument({
266
268
  collection: info.collection,
267
269
  document_id: info.document_id,
268
270
  data: {[info.name]: info.value},
269
- element: info.element,
270
- metadata:info.metadata,
271
+ upsert: info.upsert,
272
+ // element: info.element,
271
273
  namespace: info.namespace,
272
274
  room: info.room,
273
275
  broadcast: info.broadcast,
274
- upsert: info.upsert,
275
- broadcast_sender: info.broadcast_sender
276
- })
276
+ broadcast_sender: info.broadcast_sender,
277
+ metadata:info.metadata
278
+ });
277
279
  }
278
280
  }
279
281
 
@@ -289,22 +291,26 @@ class CoCreateCRDTClass {
289
291
  */
290
292
  insertText(info) {
291
293
  try {
292
- let docName = this.generateDocName(info)
293
- let typeName = this.generateTypeName(info)
294
- let meta = {test: 'hello'}
294
+ let docName = this.generateDocName(info);
295
+ let typeName = this.generateTypeName(info);
295
296
  if (docName) {
296
297
  this.docs[docName].doc.getText(typeName).insert(info['position'], info['value'], info['attributes']);
297
- let wholestring = this.docs[docName].doc.getText(typeName).toString();
298
298
 
299
- if (info.crud != false) {
299
+ if (info.crud != 'false') {
300
+ let wholestring = this.docs[docName].doc.getText(typeName).toString();
300
301
  crud.updateDocument({
301
302
  collection: info.collection,
302
303
  document_id: info.document_id,
303
304
  data: {
304
305
  [info.name]: wholestring
305
306
  },
306
- metadata: 'yjs-change'
307
- })
307
+ upsert: info.upsert,
308
+ namespace: info.namespace,
309
+ room: info.room,
310
+ broadcast: info.broadcast,
311
+ broadcast_sender: info.broadcast_sender,
312
+ metadata: 'crdt-change'
313
+ });
308
314
  }
309
315
  }
310
316
  }
@@ -324,21 +330,26 @@ class CoCreateCRDTClass {
324
330
  */
325
331
  deleteText(info) {
326
332
  try{
327
- let docName = this.generateDocName(info)
328
- let typeName = this.generateTypeName(info)
333
+ let docName = this.generateDocName(info);
334
+ let typeName = this.generateTypeName(info);
329
335
  if (docName) {
330
336
  this.docs[docName].doc.getText(typeName).delete(info['position'], info['length']);
331
- let wholestring = this.docs[docName].doc.getText(typeName).toString();
332
337
 
333
- if (info.crud != false) {
338
+ if (info.crud != 'false') {
339
+ let wholestring = this.docs[docName].doc.getText(typeName).toString();
334
340
  crud.updateDocument({
335
341
  collection: info.collection,
336
342
  document_id: info.document_id,
337
343
  data: {
338
344
  [info.name]: wholestring
339
345
  },
340
- metadata: 'yjs-change'
341
- })
346
+ upsert: info.upsert,
347
+ namespace: info.namespace,
348
+ room: info.room,
349
+ broadcast: info.broadcast,
350
+ broadcast_sender: info.broadcast_sender,
351
+ metadata: 'crdt-change'
352
+ });
342
353
  }
343
354
  }
344
355
  }
@@ -357,9 +368,12 @@ class CoCreateCRDTClass {
357
368
  */
358
369
  getText(info) {
359
370
  try{
360
- let docName = this.generateDocName(info)
361
- let typeName = this.generateTypeName(info)
371
+ let docName = this.generateDocName(info);
372
+ let typeName = this.generateTypeName(info);
362
373
  if (docName) {
374
+ if (!this.docs[docName]){
375
+ this.init(info);
376
+ }
363
377
  return this.docs[docName].doc.getText(typeName).toString();
364
378
  }
365
379
  else return "--";
@@ -370,27 +384,6 @@ class CoCreateCRDTClass {
370
384
  }
371
385
  }
372
386
 
373
- /*
374
- crdt.getText({
375
- collection: 'module_activities',
376
- document_id: '5e4802ce3ed96d38e71fc7e5',
377
- name: 'name'
378
- })
379
- */
380
- getText(info) {
381
- try{
382
- let docName = this.generateDocName(info)
383
- let typeName = this.generateTypeName(info)
384
- if (docName) {
385
- return this.docs[docName].doc.getText(typeName).toString();
386
- }
387
- else return "--";
388
- }
389
- catch (e) {
390
- console.error(e);
391
- return "";
392
- }
393
- }
394
387
 
395
388
  /*
396
389
  crdt.getDoc({
@@ -401,9 +394,12 @@ class CoCreateCRDTClass {
401
394
  */
402
395
  getDoc(info) {
403
396
  try{
404
- let docName = this.generateDocName(info)
405
- let typeName = this.generateTypeName(info)
397
+ let docName = this.generateDocName(info);
398
+ let typeName = this.generateTypeName(info);
406
399
  if (docName) {
400
+ if (!this.docs[docName]){
401
+ this.init(info);
402
+ }
407
403
  return this.docs[docName].doc.getText(typeName);
408
404
  }
409
405
  else return false;
@@ -422,7 +418,7 @@ class CoCreateCRDTClass {
422
418
  if(typeof miFuncion === 'function')
423
419
  this.changeListenAwereness(callback);
424
420
  else
425
- console.error('Callback should be a function')
421
+ console.error('Callback should be a function');
426
422
  }
427
423
  }
428
424