@cocreate/crud-server 1.3.2 → 1.4.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 +23 -0
- package/package.json +1 -1
- package/src/backup.js +11 -11
- package/src/crud.js +23 -33
- package/src/list.js +17 -29
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
# [1.4.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.3.4...v1.4.0) (2022-04-01)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* readCollections to return a list of collections ([2ad15d4](https://github.com/CoCreate-app/CoCreate-crud-server/commit/2ad15d43baf22c6dabbf56582cac182dec8876ad))
|
|
7
|
+
|
|
8
|
+
## [1.3.4](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.3.3...v1.3.4) (2022-03-06)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* broadcast_sender if condition removed and handeled by socket ([c2a0a6d](https://github.com/CoCreate-app/CoCreate-crud-server/commit/c2a0a6d79d331e56160cd9ddaf8a7e521e2270e8))
|
|
14
|
+
* removed param isExact from broadcast as it can be handled by param room ([e709e36](https://github.com/CoCreate-app/CoCreate-crud-server/commit/e709e366493759399f371f2ffc3c630e415f8daa))
|
|
15
|
+
* update param roomInfo to socketInfo ([f50edc9](https://github.com/CoCreate-app/CoCreate-crud-server/commit/f50edc91ee4695f6a652fd8a8c943feac24ba80a))
|
|
16
|
+
|
|
17
|
+
## [1.3.3](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.3.2...v1.3.3) (2022-03-05)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* typo reponse to response ([bbc67bf](https://github.com/CoCreate-app/CoCreate-crud-server/commit/bbc67bf99652175a3a9f6ccbdd7cd08cf5a536ba))
|
|
23
|
+
|
|
1
24
|
## [1.3.2](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.3.1...v1.3.2) (2022-03-04)
|
|
2
25
|
|
|
3
26
|
|
package/package.json
CHANGED
package/src/backup.js
CHANGED
|
@@ -13,11 +13,11 @@ class CoCreateBackup {
|
|
|
13
13
|
|
|
14
14
|
init() {
|
|
15
15
|
if (this.wsManager) {
|
|
16
|
-
// this.wsManager.on('exportDB', (socket, data,
|
|
17
|
-
// this.wsManager.on('importDB', (socket, data,
|
|
18
|
-
// this.wsManager.on('importFile2DB', (socket, data,
|
|
16
|
+
// this.wsManager.on('exportDB', (socket, data, socketInfo) => this.exportData(socket, data, socketInfo));
|
|
17
|
+
// this.wsManager.on('importDB', (socket, data, socketInfo) => this.importData(socket, data, socketInfo));
|
|
18
|
+
// this.wsManager.on('importFile2DB', (socket, data, socketInfo) => this.importData(socket, data, socketInfo));
|
|
19
19
|
|
|
20
|
-
// this.wsManager.on('downloadData', (socket, data,
|
|
20
|
+
// this.wsManager.on('downloadData', (socket, data, socketInfo) => this.downloadData(socket, data, socketInfo))
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -28,13 +28,13 @@ class CoCreateBackup {
|
|
|
28
28
|
data: JSON data
|
|
29
29
|
}
|
|
30
30
|
**/
|
|
31
|
-
// async downloadData(socket, data,
|
|
31
|
+
// async downloadData(socket, data, socketInfo) {
|
|
32
32
|
// const export_type = data.type || "json";
|
|
33
33
|
|
|
34
34
|
// try {
|
|
35
35
|
// let binaryData = null;
|
|
36
36
|
// const result = data.data;
|
|
37
|
-
// const orgId =
|
|
37
|
+
// const orgId = socketInfo ? socketInfo.orgId : "";
|
|
38
38
|
// if (export_type === 'csv') {
|
|
39
39
|
// binaryData = await json2csv.json2csvAsync(JSON.parse(JSON.stringify(result)), {
|
|
40
40
|
// emptyFieldValue: ''
|
|
@@ -60,7 +60,7 @@ class CoCreateBackup {
|
|
|
60
60
|
|
|
61
61
|
})
|
|
62
62
|
**/
|
|
63
|
-
// async exportData(socket, data,
|
|
63
|
+
// async exportData(socket, data, socketInfo) {
|
|
64
64
|
// const self = this;
|
|
65
65
|
|
|
66
66
|
// const export_type = data.export_type || "json";
|
|
@@ -68,7 +68,7 @@ class CoCreateBackup {
|
|
|
68
68
|
// try {
|
|
69
69
|
|
|
70
70
|
// var collection = this.dbClient.db(data['namespace']).collection(data["collection"]);
|
|
71
|
-
// const orgId =
|
|
71
|
+
// const orgId = socketInfo ? socketInfo.orgId : "";
|
|
72
72
|
|
|
73
73
|
// var query = {};
|
|
74
74
|
|
|
@@ -92,13 +92,13 @@ class CoCreateBackup {
|
|
|
92
92
|
// }
|
|
93
93
|
// }
|
|
94
94
|
|
|
95
|
-
// async setImportData(socket, data,
|
|
95
|
+
// async setImportData(socket, data, socketInfo) {
|
|
96
96
|
// this.importCollection = data['collection']
|
|
97
97
|
// this.importType = data['import_type'];
|
|
98
98
|
// this.importDB = data['namespace'];
|
|
99
99
|
// }
|
|
100
100
|
|
|
101
|
-
// async importData(socket, data,
|
|
101
|
+
// async importData(socket, data, socketInfo) {
|
|
102
102
|
// const importCollection = data['collection']
|
|
103
103
|
// const importType = data['import_type'];
|
|
104
104
|
// const importFile = data['file'];
|
|
@@ -106,7 +106,7 @@ class CoCreateBackup {
|
|
|
106
106
|
|
|
107
107
|
// console.log('import:', importCollection, importType, importFile)
|
|
108
108
|
// const self = this;
|
|
109
|
-
// // const orgId =
|
|
109
|
+
// // const orgId = socketInfo ? socketInfo.orgId : "";
|
|
110
110
|
// if (!importCollection || !importType) {
|
|
111
111
|
// return;
|
|
112
112
|
// }
|
package/src/crud.js
CHANGED
|
@@ -11,15 +11,15 @@ class CoCreateCrud {
|
|
|
11
11
|
|
|
12
12
|
init() {
|
|
13
13
|
if (this.wsManager) {
|
|
14
|
-
this.wsManager.on('createDocument', (socket, data,
|
|
15
|
-
this.wsManager.on('readDocument', (socket, data,
|
|
16
|
-
this.wsManager.on('updateDocument', (socket, data,
|
|
17
|
-
this.wsManager.on('deleteDocument', (socket, data,
|
|
14
|
+
this.wsManager.on('createDocument', (socket, data, socketInfo) => this.createDocument(socket, data, socketInfo));
|
|
15
|
+
this.wsManager.on('readDocument', (socket, data, socketInfo) => this.readDocument(socket, data, socketInfo))
|
|
16
|
+
this.wsManager.on('updateDocument', (socket, data, socketInfo) => this.updateDocument(socket, data, socketInfo))
|
|
17
|
+
this.wsManager.on('deleteDocument', (socket, data, socketInfo) => this.deleteDocument(socket, data, socketInfo))
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/** Create Document **/
|
|
22
|
-
async createDocument(socket, req_data,
|
|
22
|
+
async createDocument(socket, req_data, socketInfo){
|
|
23
23
|
const self = this;
|
|
24
24
|
if(!req_data.data) return;
|
|
25
25
|
|
|
@@ -33,22 +33,22 @@ class CoCreateCrud {
|
|
|
33
33
|
const response = {...req_data, document_id: result.ops[0]._id, data:result.ops[0] }
|
|
34
34
|
// let isFlat = req_data.isFlat == false ? false : true;
|
|
35
35
|
// const response_data = isFlat ? encodeObject(response) : response;
|
|
36
|
-
const response_data = response;
|
|
37
|
-
self.broadcast('createDocument', socket,
|
|
36
|
+
// const response_data = response;
|
|
37
|
+
self.broadcast('createDocument', socket, response, socketInfo)
|
|
38
38
|
} else {
|
|
39
|
-
self.wsManager.send(socket, 'ServerError', error, null,
|
|
39
|
+
self.wsManager.send(socket, 'ServerError', error, null, socketInfo);
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
}catch(error){
|
|
43
43
|
console.log('createDocument error', error);
|
|
44
|
-
self.wsManager.send(socket, 'ServerError', 'error', null,
|
|
44
|
+
self.wsManager.send(socket, 'ServerError', 'error', null, socketInfo);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/** Read Document **/
|
|
49
|
-
async readDocument(socket, req_data,
|
|
49
|
+
async readDocument(socket, req_data, socketInfo) {
|
|
50
50
|
if (!req_data['collection'] || req_data['collection'] == 'null' || typeof req_data['collection'] !== 'string') {
|
|
51
|
-
this.wsManager.send(socket, 'ServerError', 'error', null,
|
|
51
|
+
this.wsManager.send(socket, 'ServerError', 'error', null, socketInfo);
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
54
|
const self = this;
|
|
@@ -81,19 +81,19 @@ class CoCreateCrud {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
let isFlat = req_data.isFlat == true ? true : false;
|
|
84
|
-
self.wsManager.send(socket, 'readDocument', { ...req_data, data: isFlat ? encodeObject(tmp) : tmp }, req_data['organization_id'],
|
|
84
|
+
self.wsManager.send(socket, 'readDocument', { ...req_data, data: isFlat ? encodeObject(tmp) : tmp }, req_data['organization_id'], socketInfo);
|
|
85
85
|
} else {
|
|
86
|
-
self.wsManager.send(socket, 'ServerError', error, null,
|
|
86
|
+
self.wsManager.send(socket, 'ServerError', error, null, socketInfo);
|
|
87
87
|
}
|
|
88
88
|
});
|
|
89
89
|
} catch (error) {
|
|
90
90
|
console.log('readDocument error', error);
|
|
91
|
-
self.wsManager.send(socket, 'ServerError', 'error', null,
|
|
91
|
+
self.wsManager.send(socket, 'ServerError', 'error', null, socketInfo);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
/** Update Document **/
|
|
96
|
-
async updateDocument(socket, req_data,
|
|
96
|
+
async updateDocument(socket, req_data, socketInfo) {
|
|
97
97
|
const self = this;
|
|
98
98
|
try {
|
|
99
99
|
const db = this.dbClient.db(req_data['organization_id']);
|
|
@@ -132,10 +132,10 @@ class CoCreateCrud {
|
|
|
132
132
|
|
|
133
133
|
if(req_data['unset']) response['delete_fields'] = req_data['unset'];
|
|
134
134
|
|
|
135
|
-
self.broadcast('updateDocument', socket,
|
|
135
|
+
self.broadcast('updateDocument', socket, response, socketInfo)
|
|
136
136
|
}).catch((error) => {
|
|
137
137
|
console.log('error', error)
|
|
138
|
-
self.wsManager.send(socket, 'ServerError', error, null,
|
|
138
|
+
self.wsManager.send(socket, 'ServerError', error, null, socketInfo);
|
|
139
139
|
});
|
|
140
140
|
|
|
141
141
|
} catch (error) {
|
|
@@ -145,7 +145,7 @@ class CoCreateCrud {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
/** Delete Document **/
|
|
148
|
-
async deleteDocument(socket, req_data,
|
|
148
|
+
async deleteDocument(socket, req_data, socketInfo) {
|
|
149
149
|
const self = this;
|
|
150
150
|
|
|
151
151
|
try {
|
|
@@ -158,29 +158,19 @@ class CoCreateCrud {
|
|
|
158
158
|
collection.deleteOne(query, function(error, result) {
|
|
159
159
|
if (!error) {
|
|
160
160
|
let response = { ...req_data }
|
|
161
|
-
self.broadcast('deleteDocument', socket,
|
|
161
|
+
self.broadcast('deleteDocument', socket, response, socketInfo)
|
|
162
162
|
} else {
|
|
163
|
-
self.wsManager.send(socket, 'ServerError', error, null,
|
|
163
|
+
self.wsManager.send(socket, 'ServerError', error, null, socketInfo);
|
|
164
164
|
}
|
|
165
165
|
})
|
|
166
166
|
} catch (error) {
|
|
167
167
|
console.log(error);
|
|
168
|
-
self.wsManager.send(socket, 'ServerError', 'error', null,
|
|
168
|
+
self.wsManager.send(socket, 'ServerError', 'error', null, socketInfo);
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
broadcast(component, socket,
|
|
173
|
-
|
|
174
|
-
this.wsManager.send(socket, component, { ...response, element: req_data['element']}, req_data['organization_id'], roomInfo);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (req_data.broadcast !== false) {
|
|
178
|
-
if (req_data.room) {
|
|
179
|
-
this.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'] , req_data.room, component, response, true, roomInfo);
|
|
180
|
-
} else {
|
|
181
|
-
this.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'], null, component, response, true, roomInfo)
|
|
182
|
-
}
|
|
183
|
-
}
|
|
172
|
+
broadcast(component, socket, response, socketInfo) {
|
|
173
|
+
this.wsManager.broadcast(socket, response.namespace || response['organization_id'], response.room, component, response, socketInfo);
|
|
184
174
|
process.emit('changed-document', response)
|
|
185
175
|
}
|
|
186
176
|
}
|
package/src/list.js
CHANGED
|
@@ -8,8 +8,8 @@ class CoCreateList {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
init() {
|
|
11
|
-
this.wsManager.on('readDocumentList', (socket, data,
|
|
12
|
-
this.wsManager.on('
|
|
11
|
+
this.wsManager.on('readDocumentList', (socket, data, socketInfo) => this.readDocumentList(socket, data, socketInfo));
|
|
12
|
+
this.wsManager.on('readCollections', (socket, data, socketInfo) => this.readCollections(socket, data, socketInfo));
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -40,26 +40,23 @@ class CoCreateList {
|
|
|
40
40
|
count: 0 (integer)
|
|
41
41
|
},
|
|
42
42
|
|
|
43
|
-
is_collection: true | false,
|
|
44
43
|
//. case fetch document case
|
|
45
44
|
export: true | false
|
|
46
45
|
-------- additional response data -----------
|
|
47
46
|
data: [] // array
|
|
48
47
|
}
|
|
49
48
|
**/
|
|
50
|
-
async readDocumentList(socket, req_data,
|
|
49
|
+
async readDocumentList(socket, req_data, socketInfo) {
|
|
51
50
|
function sleep(ms) {
|
|
52
51
|
return new Promise((resolve) => {
|
|
53
52
|
setTimeout(resolve, ms);
|
|
54
53
|
});
|
|
55
54
|
}
|
|
56
|
-
|
|
57
|
-
// await sleep(3000)
|
|
58
55
|
|
|
59
56
|
const self = this;
|
|
60
57
|
|
|
61
58
|
if (req_data['is_collection']) {
|
|
62
|
-
var result = await this.
|
|
59
|
+
var result = await this.readCollections(socket, req_data, socketInfo);
|
|
63
60
|
return;
|
|
64
61
|
}
|
|
65
62
|
|
|
@@ -116,42 +113,33 @@ class CoCreateList {
|
|
|
116
113
|
|
|
117
114
|
result_data = result;
|
|
118
115
|
}
|
|
119
|
-
self.wsManager.send(socket, 'readDocumentList', { ...req_data, data: result_data, operator: {...operator, total: total}}, req_data['organization_id'],
|
|
116
|
+
self.wsManager.send(socket, 'readDocumentList', { ...req_data, data: result_data, operator: {...operator, total: total}}, req_data['organization_id'], socketInfo);
|
|
120
117
|
} else {
|
|
121
118
|
console.log(error)
|
|
122
|
-
self.wsManager.send(socket, 'ServerError', error, null,
|
|
119
|
+
self.wsManager.send(socket, 'ServerError', error, null, socketInfo);
|
|
123
120
|
}
|
|
124
121
|
})
|
|
125
122
|
} catch (error) {
|
|
126
123
|
console.log('readDocumentList error', error);
|
|
127
|
-
this.wsManager.send(socket, 'ServerError', 'error', null,
|
|
124
|
+
this.wsManager.send(socket, 'ServerError', 'error', null, socketInfo);
|
|
128
125
|
}
|
|
129
126
|
}
|
|
130
127
|
|
|
131
|
-
async
|
|
128
|
+
async readCollections(socket, data, socketInfo) {
|
|
132
129
|
try {
|
|
133
|
-
|
|
134
|
-
const db = this.dbClient.db(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
name: item.name,
|
|
141
|
-
_id: __uuid,
|
|
142
|
-
id: __uuid,
|
|
143
|
-
});
|
|
144
|
-
})
|
|
145
|
-
return result;
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
this.wsManager.send(socket, 'readCollectionList', {...data, data: collections }, data['organization_id'], roomInfo);
|
|
130
|
+
const self = this;
|
|
131
|
+
const db = this.dbClient.db(data['organization_id']);
|
|
132
|
+
db.listCollections().toArray(function(error, result) {
|
|
133
|
+
if (!error && result && result.length > 0) {
|
|
134
|
+
self.wsManager.send(socket, 'readCollections', {...data, data: result }, data['organization_id'], socketInfo);
|
|
135
|
+
}
|
|
136
|
+
})
|
|
149
137
|
} catch(error) {
|
|
150
|
-
|
|
138
|
+
console.log('readCollections error', error);
|
|
139
|
+
this.wsManager.send(socket, 'ServerError', 'error', null, socketInfo);
|
|
151
140
|
}
|
|
152
141
|
}
|
|
153
142
|
|
|
154
|
-
|
|
155
143
|
/**
|
|
156
144
|
* function that make query from data
|
|
157
145
|
*
|