@cocreate/crdt 1.11.2 → 1.13.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.13.1](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.13.0...v1.13.1) (2022-08-18)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * checkDb function requires for clientId to be added ([b5a1545](https://github.com/CoCreate-app/CoCreate-crdt/commit/b5a1545bb83a26b7eb9427a030081ec170688a6b))
7
+
8
+ # [1.13.0](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.12.0...v1.13.0) (2022-07-25)
9
+
10
+
11
+ ### Features
12
+
13
+ * crud.getObjectValueByPath to return value using name containing a dotNotation string ([fd8bebf](https://github.com/CoCreate-app/CoCreate-crdt/commit/fd8bebf17722396a71d55affb297ec2718fb46a8))
14
+
15
+ # [1.12.0](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.11.2...v1.12.0) (2022-07-03)
16
+
17
+
18
+ ### Features
19
+
20
+ * viewVersion function to return string of a specified version ([e652663](https://github.com/CoCreate-app/CoCreate-crdt/commit/e65266331c25baef10698e6234686a82b77ca4a6))
21
+
1
22
  ## [1.11.2](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.11.1...v1.11.2) (2022-06-18)
2
23
 
3
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/crdt",
3
- "version": "1.11.2",
3
+ "version": "1.13.1",
4
4
  "description": "CoCreate crdt",
5
5
  "author": "CoCreate LLC",
6
6
  "license": "SEE LICENSE",
package/src/index.js CHANGED
@@ -19,6 +19,8 @@ function init(info){
19
19
 
20
20
  async function getDoc(info) {
21
21
  try {
22
+ if (['_id', 'organization_id'].includes(info.name))
23
+ return
22
24
  let docName = generateDocName(info);
23
25
  let typeName = info.name;
24
26
  let doc = docs.get(docName);
@@ -104,10 +106,11 @@ async function checkDb(info, flag) {
104
106
  if (checkedDb.get(`${collection}${document_id}${name}`)) return;
105
107
  checkedDb.set(`${collection}${document_id}${name}`, true);
106
108
  let response = await crud.readDocument({ collection, document_id, name });
107
- let string = response.data[name];
109
+ let string = crud.getObjectValueByPath(response.data, name);
108
110
  if (string && flag != false) {
109
111
  info.value = string;
110
112
  info.start = 0;
113
+ info.clientId = clientId;
111
114
  insertChange(info);
112
115
  }
113
116
  return string || '';
@@ -396,6 +399,24 @@ function redoText(info){
396
399
  }
397
400
  }
398
401
 
402
+ async function viewVersion(data) {
403
+ try {
404
+ let name = docs.get(`${data.collection}${data.document_id}`).get(data.name);
405
+ let string = '';
406
+ let changeLog = name.get('changeLog');
407
+ let log = changeLog.slice(0, data.version)
408
+ for (let change of log) {
409
+ if (change || change !== null ) {
410
+ string = string.customSplice(change.start, change.length, change.value);
411
+ }
412
+ }
413
+ return { ...data, ...string }
414
+ }
415
+ catch (e) {
416
+ console.error(e);
417
+ }
418
+ }
419
+
399
420
 
400
421
 
401
422
  // function deleteDoc(docName) {
@@ -415,4 +436,4 @@ function generateDocName(info) {
415
436
  // return btoa(JSON.stringify(docName));
416
437
  }
417
438
 
418
- export default { init, getText, updateText, replaceText, undoText, redoText };
439
+ export default { init, getText, updateText, replaceText, undoText, redoText, viewVersion };