@cocreate/unique 1.5.11 → 1.6.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,22 @@
1
+ ## [1.6.1](https://github.com/CoCreate-app/CoCreate-unique/compare/v1.6.0...v1.6.1) (2022-11-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * bump d@cocreate ependencies ([adc4922](https://github.com/CoCreate-app/CoCreate-unique/commit/adc4922e502eeb80e342f5993055f2333f1c855b))
7
+
8
+ # [1.6.0](https://github.com/CoCreate-app/CoCreate-unique/compare/v1.5.11...v1.6.0) (2022-11-21)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * update crud functions to receive an array of objects as the response ([5ee57bf](https://github.com/CoCreate-app/CoCreate-unique/commit/5ee57bff3168597370c830eceeeee04814b7c0d6))
14
+
15
+
16
+ ### Features
17
+
18
+ * updated to use new crud which has the abilty to use multiple databases ([ce3fdf2](https://github.com/CoCreate-app/CoCreate-unique/commit/ce3fdf2bbcad7110df7c9ac38e8ed89ebac90a45))
19
+
1
20
  ## [1.5.11](https://github.com/CoCreate-app/CoCreate-unique/compare/v1.5.10...v1.5.11) (2022-10-02)
2
21
 
3
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/unique",
3
- "version": "1.5.11",
3
+ "version": "1.6.1",
4
4
  "description": "A simple unique component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "unique",
@@ -61,8 +61,8 @@
61
61
  "webpack-log": "^3.0.1"
62
62
  },
63
63
  "dependencies": {
64
- "@cocreate/crud-client": "^1.12.12",
65
- "@cocreate/docs": "^1.3.18",
66
- "@cocreate/uuid": "^1.2.16"
64
+ "@cocreate/crud-client": "^1.13.0",
65
+ "@cocreate/docs": "^1.3.20",
66
+ "@cocreate/uuid": "^1.2.17"
67
67
  }
68
68
  }
package/src/client.js CHANGED
@@ -1,6 +1,12 @@
1
- import crud from '@cocreate/crud-client';
1
+ import CRUD from '@cocreate/crud-client';
2
2
  import uuid from '@cocreate/uuid';
3
3
 
4
+ let crud
5
+ if(CRUD && CRUD.default)
6
+ crud = CRUD.default
7
+ else
8
+ crud = CRUD
9
+
4
10
  const CoCreateUnique = {
5
11
 
6
12
  selector: `input[unique], textarea[unique], contenteditable[unique]`,
@@ -54,7 +60,7 @@ const CoCreateUnique = {
54
60
  request_data['name'] = input.getAttribute('name');
55
61
  request_data['value'] = value || e.target.value;
56
62
  request_data['request_id'] = input.getAttribute(self.requestAttr);
57
- crud.send('checkUnique', request_data);
63
+ crud.socket.send('checkUnique', request_data);
58
64
  });
59
65
  },
60
66
  };
package/src/server.js CHANGED
@@ -1,7 +1,7 @@
1
1
  class CoCreateUnique {
2
- constructor(wsManager, dbClient) {
2
+ constructor(wsManager, crud) {
3
3
  this.wsManager = wsManager
4
- this.dbClient = dbClient
4
+ this.crud = crud
5
5
  this.init();
6
6
  }
7
7
 
@@ -13,28 +13,26 @@ class CoCreateUnique {
13
13
  }
14
14
 
15
15
 
16
- async checkUnique(socket, req_data) {
16
+ async checkUnique(socket, data) {
17
17
  const self = this
18
- const db = this.dbClient.db(req_data['organization_id']);
19
- const collection = db.collection(req_data["collection"]);
20
- const query = {
21
- [req_data['name']]: req_data['value']
22
- };
23
-
24
18
  try {
25
- collection.find(query).toArray(function(error, result) {
26
- if (!error && result) {
27
- let response = {
28
- request_id: req_data['request_id'],
29
- name: req_data['name'],
30
- unique: true
31
- };
32
- if (result.length) {
33
- response.unique = false;
34
- }
35
- self.wsManager.send(socket, 'checkedUnique', response);
19
+ data.filter = {
20
+ query: [
21
+ {name: data['name'], value: data['value'], operator: '$eq'}
22
+ ]
23
+ }
24
+
25
+ this.crud.readDocument(data).then((data) => {
26
+ let response = {
27
+ request_id: data['request_id'],
28
+ name: data['name'],
29
+ unique: true
30
+ };
31
+ if (data.document.length) {
32
+ response.unique = false;
36
33
  }
37
- });
34
+ self.wsManager.send(socket, 'checkedUnique', response);
35
+ })
38
36
  } catch (error) {
39
37
  console.log(error);
40
38
  }