@cocreate/crdt 1.22.4 → 1.23.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 +21 -0
- package/package.json +5 -5
- package/src/index.js +42 -34
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [1.23.1](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.23.0...v1.23.1) (2023-10-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* broadcastBrowser true on updateText ([dabfba1](https://github.com/CoCreate-app/CoCreate-crdt/commit/dabfba1488385534c782d95d2914ec65e111dead))
|
|
7
|
+
|
|
8
|
+
# [1.23.0](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.22.4...v1.23.0) (2023-10-14)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* bump dependencies ([65ce3b5](https://github.com/CoCreate-app/CoCreate-crdt/commit/65ce3b55b9a0d60f4d1dd3f1af13736f1a2eddb3))
|
|
14
|
+
* set $filter.limit ([c4d0d81](https://github.com/CoCreate-app/CoCreate-crdt/commit/c4d0d8138cc8a922890146ee079ec606c4b646c8))
|
|
15
|
+
* text.length ([fa80d0d](https://github.com/CoCreate-app/CoCreate-crdt/commit/fa80d0d6e9181957417c6fd66fc3006a0395cbf6))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* frameId to manage frames ([e6a8776](https://github.com/CoCreate-app/CoCreate-crdt/commit/e6a8776db0b4731a3b10502b6451df0d794ae235))
|
|
21
|
+
|
|
1
22
|
## [1.22.4](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.22.3...v1.22.4) (2023-10-09)
|
|
2
23
|
|
|
3
24
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/crdt",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.1",
|
|
4
4
|
"description": "CoCreate crdt",
|
|
5
5
|
"author": "CoCreate LLC",
|
|
6
6
|
"license": "AGPL-3.0",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"webpack-log": "^3.0.1"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@cocreate/crud-client": "^1.28.
|
|
44
|
-
"@cocreate/local-storage": "^1.10.
|
|
45
|
-
"@cocreate/message-client": "^1.8.
|
|
46
|
-
"@cocreate/utils": "^1.25.
|
|
43
|
+
"@cocreate/crud-client": "^1.28.4",
|
|
44
|
+
"@cocreate/local-storage": "^1.10.5",
|
|
45
|
+
"@cocreate/message-client": "^1.8.3",
|
|
46
|
+
"@cocreate/utils": "^1.25.3"
|
|
47
47
|
}
|
|
48
48
|
}
|
package/src/index.js
CHANGED
|
@@ -27,7 +27,7 @@ import uuid from '@cocreate/uuid';
|
|
|
27
27
|
import localStorage from '@cocreate/local-storage';
|
|
28
28
|
|
|
29
29
|
const docs = new Map();
|
|
30
|
-
const
|
|
30
|
+
const frameId = crud.socket.frameId || uuid.generate(12);
|
|
31
31
|
const checkedDb = new Map();
|
|
32
32
|
const isInit = new Map();
|
|
33
33
|
|
|
@@ -35,7 +35,7 @@ function init(data) {
|
|
|
35
35
|
getText(data).then(value => {
|
|
36
36
|
data.value = value;
|
|
37
37
|
data.start = 0;
|
|
38
|
-
data['
|
|
38
|
+
data['frameId'] = frameId;
|
|
39
39
|
localChange(data);
|
|
40
40
|
});
|
|
41
41
|
}
|
|
@@ -68,7 +68,8 @@ async function getDoc(data) {
|
|
|
68
68
|
key: 'docName',
|
|
69
69
|
operator: "$eq",
|
|
70
70
|
value: docName
|
|
71
|
-
}]
|
|
71
|
+
}],
|
|
72
|
+
limit: 1
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
});
|
|
@@ -79,13 +80,11 @@ async function getDoc(data) {
|
|
|
79
80
|
doc.set('changeLog', changeLog);
|
|
80
81
|
await generateText(data, true);
|
|
81
82
|
}
|
|
82
|
-
}
|
|
83
|
-
else if (!doc.has('text')) {
|
|
83
|
+
} else if (!doc.has('text')) {
|
|
84
84
|
await generateText(data, false);
|
|
85
85
|
}
|
|
86
86
|
return doc;
|
|
87
|
-
}
|
|
88
|
-
catch (e) {
|
|
87
|
+
} catch (e) {
|
|
89
88
|
console.log('Invalid param', e);
|
|
90
89
|
}
|
|
91
90
|
}
|
|
@@ -101,17 +100,18 @@ async function generateText(data, flag) {
|
|
|
101
100
|
let string = '';
|
|
102
101
|
let changeLog = doc.get('changeLog');
|
|
103
102
|
for (let change of changeLog) {
|
|
104
|
-
if (change
|
|
103
|
+
if (change) {
|
|
105
104
|
string = string.customSplice(change.start, change.length, change.value);
|
|
106
105
|
}
|
|
107
106
|
}
|
|
107
|
+
|
|
108
108
|
if (string === '' && data.read !== 'false') {
|
|
109
|
-
string = await checkDb(data, flag)
|
|
109
|
+
string = await checkDb(data, flag) || ''
|
|
110
110
|
}
|
|
111
|
+
|
|
111
112
|
doc.set('text', string);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
catch (e) {
|
|
113
|
+
return string;
|
|
114
|
+
} catch (e) {
|
|
115
115
|
console.error(e);
|
|
116
116
|
}
|
|
117
117
|
}
|
|
@@ -128,15 +128,17 @@ async function checkDb(data, flag) {
|
|
|
128
128
|
let response = await crud.send({ method: 'read.object', array, object: { _id: object, key } });
|
|
129
129
|
string = crud.getValueFromObject(response.object[0], key);
|
|
130
130
|
}
|
|
131
|
+
|
|
131
132
|
if (string && typeof string !== 'string')
|
|
132
133
|
string = ""
|
|
133
134
|
if (string && typeof string === 'string' && flag != false) {
|
|
134
135
|
data.value = string;
|
|
135
136
|
data.start = 0;
|
|
136
|
-
data.
|
|
137
|
+
data.frameId = frameId;
|
|
137
138
|
insertChange(data);
|
|
138
139
|
}
|
|
139
|
-
|
|
140
|
+
|
|
141
|
+
return string;
|
|
140
142
|
}
|
|
141
143
|
|
|
142
144
|
function insertChange(data, flag) {
|
|
@@ -157,7 +159,7 @@ function insertChange(data, flag) {
|
|
|
157
159
|
start: data.start,
|
|
158
160
|
end: data.end,
|
|
159
161
|
length: data.length || 0,
|
|
160
|
-
|
|
162
|
+
frameId: data.frameId || frameId,
|
|
161
163
|
user_id: data.user_id || localStorage.getItem("user_id"),
|
|
162
164
|
type
|
|
163
165
|
};
|
|
@@ -205,23 +207,21 @@ function insertChange(data, flag) {
|
|
|
205
207
|
doc.set('text', string.customSplice(change.start, change.length, change.value));
|
|
206
208
|
string = doc.get('text');
|
|
207
209
|
|
|
208
|
-
if (!data.
|
|
210
|
+
if (!data.frameId) {
|
|
209
211
|
data['datetime'] = change.datetime;
|
|
210
|
-
data['
|
|
212
|
+
data['frameId'] = change.frameId;
|
|
211
213
|
|
|
212
214
|
broadcastChange(data);
|
|
213
215
|
localChange(data, string);
|
|
214
|
-
}
|
|
215
|
-
else
|
|
216
|
+
} else
|
|
216
217
|
localChange(data, string);
|
|
217
218
|
|
|
218
|
-
if (data.
|
|
219
|
+
if (data.frameId == frameId && data.save != "false")
|
|
219
220
|
persistChange(data);
|
|
220
221
|
}
|
|
221
222
|
|
|
222
223
|
function broadcastChange(data) {
|
|
223
224
|
message.send({
|
|
224
|
-
room: "",
|
|
225
225
|
broadcastSender: false,
|
|
226
226
|
broadcastBrowser: true,
|
|
227
227
|
message: "crdt",
|
|
@@ -260,6 +260,7 @@ function persistChange(data) {
|
|
|
260
260
|
room: data.room,
|
|
261
261
|
broadcast: data.broadcast,
|
|
262
262
|
broadcastSender: data.broadcastSender,
|
|
263
|
+
broadcastBrowser: false,
|
|
263
264
|
metadata: 'crdt-change'
|
|
264
265
|
}
|
|
265
266
|
|
|
@@ -272,7 +273,7 @@ message.listen('crdt', function (response) {
|
|
|
272
273
|
let doc = docs.get(docName);
|
|
273
274
|
|
|
274
275
|
if (doc) {
|
|
275
|
-
if (data.
|
|
276
|
+
if (data.frameId !== frameId) {
|
|
276
277
|
insertChange(data);
|
|
277
278
|
}
|
|
278
279
|
}
|
|
@@ -282,12 +283,21 @@ crud.listen('update.object', (data) => sync(data))
|
|
|
282
283
|
crud.listen('delete.object', (data) => sync(data))
|
|
283
284
|
|
|
284
285
|
function sync(data) {
|
|
286
|
+
if (data.frameId === frameId)
|
|
287
|
+
return
|
|
285
288
|
if (data.array.includes('crdt-transactions')) {
|
|
286
289
|
if (data.object && data.object[0]) {
|
|
287
290
|
let Data = data.object[0];
|
|
288
291
|
let docName = Data.docName;
|
|
289
292
|
let doc = docs.get(docName);
|
|
290
293
|
if (doc && Data.crud) {
|
|
294
|
+
// let text = doc.get('text')
|
|
295
|
+
// if (!text && text !== '') {
|
|
296
|
+
// setTimeout(function () {
|
|
297
|
+
// console.log("text empty timout set");
|
|
298
|
+
// sync(data)
|
|
299
|
+
// }, 1000); // Delayed action after 2 seconds
|
|
300
|
+
// } else {
|
|
291
301
|
Data.crud.value = Data.text
|
|
292
302
|
Data.crud.start = 0
|
|
293
303
|
Data.crud.length = doc.get('text').length
|
|
@@ -297,6 +307,7 @@ function sync(data) {
|
|
|
297
307
|
// TODO: compare modified dates to check if arrays need to merged and orderd by date or if we just use server
|
|
298
308
|
localChange(Data.crud, Data.text)
|
|
299
309
|
console.log('crdtSync')
|
|
310
|
+
// }
|
|
300
311
|
}
|
|
301
312
|
}
|
|
302
313
|
}
|
|
@@ -316,12 +327,10 @@ async function getText(data) {
|
|
|
316
327
|
if (doc) {
|
|
317
328
|
let value = doc.get('text')
|
|
318
329
|
return value;
|
|
319
|
-
}
|
|
320
|
-
else {
|
|
330
|
+
} else {
|
|
321
331
|
console.log('undefined')
|
|
322
332
|
}
|
|
323
|
-
}
|
|
324
|
-
catch (e) {
|
|
333
|
+
} catch (e) {
|
|
325
334
|
console.error(e);
|
|
326
335
|
return "";
|
|
327
336
|
}
|
|
@@ -352,8 +361,7 @@ async function replaceText(data) {
|
|
|
352
361
|
data.start = 0;
|
|
353
362
|
updateText(data, 'replace');
|
|
354
363
|
}
|
|
355
|
-
}
|
|
356
|
-
catch (e) {
|
|
364
|
+
} catch (e) {
|
|
357
365
|
console.error(e);
|
|
358
366
|
}
|
|
359
367
|
}
|
|
@@ -388,7 +396,8 @@ async function updateText(data, flag) {
|
|
|
388
396
|
namespace: data.namespace,
|
|
389
397
|
room: data.room,
|
|
390
398
|
broadcast: data.broadcast,
|
|
391
|
-
broadcastSender:
|
|
399
|
+
broadcastSender: false,
|
|
400
|
+
broadcastBrowser: true,
|
|
392
401
|
metadata: 'crdt-updateobject'
|
|
393
402
|
});
|
|
394
403
|
}
|
|
@@ -407,9 +416,9 @@ function createChange(data, change) {
|
|
|
407
416
|
change.type = 'insert';
|
|
408
417
|
}
|
|
409
418
|
data = { ...data, ...change };
|
|
410
|
-
delete data.
|
|
419
|
+
delete data.frameId
|
|
411
420
|
delete data.datetime
|
|
412
|
-
delete change.
|
|
421
|
+
delete change.frameId
|
|
413
422
|
delete change.datetime
|
|
414
423
|
return { data, change }
|
|
415
424
|
}
|
|
@@ -422,7 +431,7 @@ function undoText(data) {
|
|
|
422
431
|
|
|
423
432
|
for (let index = changeLog.length - 1; index >= 0; index--) {
|
|
424
433
|
let change = Object.assign({}, changeLog[index]);
|
|
425
|
-
if (change && change.
|
|
434
|
+
if (change && change.frameId == frameId) {
|
|
426
435
|
let log = undoLog.get(index)
|
|
427
436
|
if (!log) {
|
|
428
437
|
if (log != 'undo') {
|
|
@@ -475,8 +484,7 @@ async function viewVersion(data) {
|
|
|
475
484
|
}
|
|
476
485
|
}
|
|
477
486
|
return { ...data, ...string }
|
|
478
|
-
}
|
|
479
|
-
catch (e) {
|
|
487
|
+
} catch (e) {
|
|
480
488
|
console.error(e);
|
|
481
489
|
}
|
|
482
490
|
}
|