@cocreate/unique 1.5.10 → 1.6.0
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 +19 -0
- package/package.json +4 -4
- package/src/client.js +8 -2
- package/src/server.js +19 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
# [1.6.0](https://github.com/CoCreate-app/CoCreate-unique/compare/v1.5.11...v1.6.0) (2022-11-21)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* update crud functions to receive an array of objects as the response ([5ee57bf](https://github.com/CoCreate-app/CoCreate-unique/commit/5ee57bff3168597370c830eceeeee04814b7c0d6))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* updated to use new crud which has the abilty to use multiple databases ([ce3fdf2](https://github.com/CoCreate-app/CoCreate-unique/commit/ce3fdf2bbcad7110df7c9ac38e8ed89ebac90a45))
|
|
12
|
+
|
|
13
|
+
## [1.5.11](https://github.com/CoCreate-app/CoCreate-unique/compare/v1.5.10...v1.5.11) (2022-10-02)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* bump dependencies ([3231a35](https://github.com/CoCreate-app/CoCreate-unique/commit/3231a35e72e53b811be398b6e5243bf5fdae8811))
|
|
19
|
+
|
|
1
20
|
## [1.5.10](https://github.com/CoCreate-app/CoCreate-unique/compare/v1.5.9...v1.5.10) (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.
|
|
3
|
+
"version": "1.6.0",
|
|
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.
|
|
65
|
-
"@cocreate/docs": "^1.3.
|
|
66
|
-
"@cocreate/uuid": "^1.2.
|
|
64
|
+
"@cocreate/crud-client": "^1.12.12",
|
|
65
|
+
"@cocreate/docs": "^1.3.18",
|
|
66
|
+
"@cocreate/uuid": "^1.2.16"
|
|
67
67
|
}
|
|
68
68
|
}
|
package/src/client.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import
|
|
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,
|
|
2
|
+
constructor(wsManager, crud) {
|
|
3
3
|
this.wsManager = wsManager
|
|
4
|
-
this.
|
|
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,
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
}
|