@cocreate/crdt 1.13.12 → 1.14.1

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,24 @@
1
+ ## [1.14.1](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.14.0...v1.14.1) (2022-11-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * bump d@cocreate ependencies ([e688a7e](https://github.com/CoCreate-app/CoCreate-crdt/commit/e688a7e00963c38ea9da3d14013ce410d157510a))
7
+
8
+ # [1.14.0](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.13.12...v1.14.0) (2022-11-21)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * if no changeLog return ([f49fe1b](https://github.com/CoCreate-app/CoCreate-crdt/commit/f49fe1b11df5dccd03dcc793cb7fb184ebaa7a9d))
14
+ * renamed data.data to data.document ([c72f10c](https://github.com/CoCreate-app/CoCreate-crdt/commit/c72f10ce530c5ec3e3c7dad84af3c0b3f8cfbac9))
15
+ * update crud functions to receive an array of objects as the response ([89e0713](https://github.com/CoCreate-app/CoCreate-crdt/commit/89e0713bff990100a0cb7e98dfd1258c16f51050))
16
+
17
+
18
+ ### Features
19
+
20
+ * newDocument to set newValue or overide existing value. ([4a811c6](https://github.com/CoCreate-app/CoCreate-crdt/commit/4a811c66362c60138dc27d723168c4d2d54417cc))
21
+
1
22
  ## [1.13.12](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.13.11...v1.13.12) (2022-10-02)
2
23
 
3
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/crdt",
3
- "version": "1.13.12",
3
+ "version": "1.14.1",
4
4
  "description": "CoCreate crdt",
5
5
  "author": "CoCreate LLC",
6
6
  "license": "SEE LICENSE",
@@ -43,8 +43,8 @@
43
43
  "webpack-log": "^3.0.1"
44
44
  },
45
45
  "dependencies": {
46
- "@cocreate/crud-client": "^1.12.11",
47
- "@cocreate/message-client": "^1.1.85",
48
- "@cocreate/utils": "^1.10.11"
46
+ "@cocreate/crud-client": "^1.13.0",
47
+ "@cocreate/message-client": "^1.1.87",
48
+ "@cocreate/utils": "^1.10.14"
49
49
  }
50
50
  }
package/src/index.js CHANGED
@@ -1,8 +1,14 @@
1
1
  /*globals config, atob, btoa, localStorage, CustomEvent*/
2
- import crud from '@cocreate/crud-client';
2
+ import CRUD from '@cocreate/crud-client';
3
3
  import message from '@cocreate/message-client';
4
4
  import uuid from '@cocreate/uuid';
5
5
 
6
+ let crud
7
+ if(CRUD && CRUD.default)
8
+ crud = CRUD.default
9
+ else
10
+ crud = CRUD
11
+
6
12
  const docs = new Map();
7
13
  const clientId = crud.socket.clientId || uuid.generate(12);
8
14
  const checkedDb = new Map();
@@ -47,23 +53,24 @@ async function getDoc(info) {
47
53
  type.set('redoLog', redoLog)
48
54
 
49
55
  if (info.read != 'false') {
50
- let response = await crud.readDocuments({
51
- collection: "crdt-transactions",
52
- filter: {
53
- query: [{
54
- name: 'docName',
55
- operator: "$eq",
56
- value: docName
57
- }]
56
+ if (!info.newDocument) {
57
+ let response = await crud.readDocument({
58
+ collection: "crdt-transactions",
59
+ filter: {
60
+ query: [{
61
+ name: 'docName',
62
+ operator: "$eq",
63
+ value: docName
64
+ }]
65
+ }
66
+ });
67
+ if (response.document.length && response.document[0][typeName]) {
68
+ changeLog = response.document[0][typeName];
58
69
  }
59
- });
60
- if (response.data.length && response.data[0][typeName]) {
61
- changeLog = response.data[0][typeName];
62
70
  }
63
71
  type.set('changeLog', changeLog);
64
72
  await generateText(info, true);
65
- }
66
-
73
+ }
67
74
  }
68
75
  else if (!type.has('text')){
69
76
  await generateText(info, false);
@@ -88,9 +95,8 @@ async function generateText(info, flag) {
88
95
  if (change || change !== null ) {
89
96
  string = string.customSplice(change.start, change.length, change.value);
90
97
  }
91
- // string = string.customSplice(change.start, change.length, change.value);
92
98
  }
93
- if (string === '' && info.read !== 'false'){
99
+ if (string === '' && info.read !== 'false') {
94
100
  string = await checkDb(info, flag);
95
101
  }
96
102
  name.set('text', string);
@@ -105,8 +111,14 @@ async function checkDb(info, flag) {
105
111
  let { collection, document_id, name } = info;
106
112
  if (checkedDb.get(`${collection}${document_id}${name}`)) return;
107
113
  checkedDb.set(`${collection}${document_id}${name}`, true);
108
- let response = await crud.readDocument({ collection, document_id, name });
109
- let string = crud.getObjectValueByPath(response.data, name);
114
+
115
+ let string = ''
116
+ if (info.newDocument)
117
+ string = info.newDocument
118
+ else {
119
+ let response = await crud.readDocument({ collection, document: {_id: document_id, name}});
120
+ string = crud.getObjectValueByPath(response.document[0], name);
121
+ }
110
122
  if (string && flag != false) {
111
123
  info.value = string;
112
124
  info.start = 0;
@@ -138,6 +150,8 @@ function insertChange(info, flag) {
138
150
 
139
151
  let name = docs.get(docName).get(typeName);
140
152
  let changeLog = name.get('changeLog');
153
+ if (!changeLog)
154
+ return
141
155
 
142
156
  let lastChange = changeLog[changeLog.length - 1];
143
157
  if (lastChange && change.datetime && lastChange.datetime){
@@ -212,7 +226,7 @@ function persistChange(info) {
212
226
  crud.updateDocument({
213
227
  collection: 'crdt-transactions',
214
228
  document_id: info.document_id,
215
- data: {
229
+ document: {
216
230
  _id: info.document_id,
217
231
  docName,
218
232
  [typeName]: changeLog
@@ -227,7 +241,7 @@ function persistChange(info) {
227
241
  }
228
242
 
229
243
  message.listen('crdt', function(response) {
230
- let data = response.data
244
+ let data = response.data
231
245
  if (docs.get(`${data.collection}${data.document_id}`)){
232
246
  if (docs.get(`${data.collection}${data.document_id}`).get(data.name))
233
247
  if (data.clientId !== clientId){
@@ -305,7 +319,6 @@ crdt.updateText({
305
319
  })
306
320
  */
307
321
  async function updateText(info, flag) {
308
- let broadcast = true;
309
322
  let doc = await getDoc(info);
310
323
  if (doc) {
311
324
 
@@ -315,8 +328,8 @@ async function updateText(info, flag) {
315
328
  let wholestring = await getText(info);
316
329
  crud.updateDocument({
317
330
  collection: info.collection,
318
- document_id: info.document_id,
319
- data: {
331
+ document: {
332
+ _id: info.document_id,
320
333
  [info.name]: wholestring
321
334
  },
322
335
  upsert: info.upsert,