@cocreate/crud-server 1.3.1 → 1.3.4

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,26 @@
1
+ ## [1.3.4](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.3.3...v1.3.4) (2022-03-06)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * broadcast_sender if condition removed and handeled by socket ([c2a0a6d](https://github.com/CoCreate-app/CoCreate-crud-server/commit/c2a0a6d79d331e56160cd9ddaf8a7e521e2270e8))
7
+ * removed param isExact from broadcast as it can be handled by param room ([e709e36](https://github.com/CoCreate-app/CoCreate-crud-server/commit/e709e366493759399f371f2ffc3c630e415f8daa))
8
+ * update param roomInfo to socketInfo ([f50edc9](https://github.com/CoCreate-app/CoCreate-crud-server/commit/f50edc91ee4695f6a652fd8a8c943feac24ba80a))
9
+
10
+ ## [1.3.3](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.3.2...v1.3.3) (2022-03-05)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * typo reponse to response ([bbc67bf](https://github.com/CoCreate-app/CoCreate-crud-server/commit/bbc67bf99652175a3a9f6ccbdd7cd08cf5a536ba))
16
+
17
+ ## [1.3.2](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.3.1...v1.3.2) (2022-03-04)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * add self.wsManager ([537375e](https://github.com/CoCreate-app/CoCreate-crud-server/commit/537375ec182242ff012f0ed11a6d3fe5f905ff26))
23
+
1
24
  ## [1.3.1](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.3.0...v1.3.1) (2022-03-04)
2
25
 
3
26
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/crud-server",
3
- "version": "1.3.1",
3
+ "version": "1.3.4",
4
4
  "description": "CoCreate-crud-server",
5
5
  "keywords": [
6
6
  "cocreate-crud",
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, roomInfo) => this.exportData(socket, data, roomInfo));
17
- // this.wsManager.on('importDB', (socket, data, roomInfo) => this.importData(socket, data, roomInfo));
18
- // this.wsManager.on('importFile2DB', (socket, data, roomInfo) => this.importData(socket, data, roomInfo));
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, roomInfo) => this.downloadData(socket, data, roomInfo))
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, roomInfo) {
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 = roomInfo ? roomInfo.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, roomInfo) {
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 = roomInfo ? roomInfo.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, roomInfo) {
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, roomInfo) {
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 = roomInfo ? roomInfo.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,16 @@ class CoCreateCrud {
11
11
 
12
12
  init() {
13
13
  if (this.wsManager) {
14
- this.wsManager.on('createDocument', (socket, data, roomInfo) => this.createDocument(socket, data, roomInfo));
15
- this.wsManager.on('readDocument', (socket, data, roomInfo) => this.readDocument(socket, data, roomInfo))
16
- this.wsManager.on('updateDocument', (socket, data, roomInfo) => this.updateDocument(socket, data, roomInfo))
17
- this.wsManager.on('deleteDocument', (socket, data, roomInfo) => this.deleteDocument(socket, data, roomInfo))
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, roomInfo){
22
+ async createDocument(socket, req_data, socketInfo){
23
+ const self = this;
23
24
  if(!req_data.data) return;
24
25
 
25
26
  try{
@@ -32,24 +33,25 @@ class CoCreateCrud {
32
33
  const response = {...req_data, document_id: result.ops[0]._id, data:result.ops[0] }
33
34
  // let isFlat = req_data.isFlat == false ? false : true;
34
35
  // const response_data = isFlat ? encodeObject(response) : response;
35
- const response_data = response;
36
- this.broadcast('createDocument', socket, req_data, reponse, roomInfo)
36
+ // const response_data = response;
37
+ self.broadcast('createDocument', socket, response, socketInfo)
37
38
  } else {
38
- this.wsManager.send(socket, 'ServerError', error, null, roomInfo);
39
+ self.wsManager.send(socket, 'ServerError', error, null, socketInfo);
39
40
  }
40
41
  });
41
42
  }catch(error){
42
43
  console.log('createDocument error', error);
43
- this.wsManager.send(socket, 'ServerError', 'error', null, roomInfo);
44
+ self.wsManager.send(socket, 'ServerError', 'error', null, socketInfo);
44
45
  }
45
46
  }
46
47
 
47
48
  /** Read Document **/
48
- async readDocument(socket, req_data, roomInfo) {
49
+ async readDocument(socket, req_data, socketInfo) {
49
50
  if (!req_data['collection'] || req_data['collection'] == 'null' || typeof req_data['collection'] !== 'string') {
50
- this.wsManager.send(socket, 'ServerError', 'error', null, roomInfo);
51
+ this.wsManager.send(socket, 'ServerError', 'error', null, socketInfo);
51
52
  return;
52
53
  }
54
+ const self = this;
53
55
 
54
56
  try {
55
57
  const db = this.dbClient.db(req_data['organization_id']);
@@ -79,19 +81,20 @@ class CoCreateCrud {
79
81
  }
80
82
 
81
83
  let isFlat = req_data.isFlat == true ? true : false;
82
- this.wsManager.send(socket, 'readDocument', { ...req_data, data: isFlat ? encodeObject(tmp) : tmp }, req_data['organization_id'], roomInfo);
84
+ self.wsManager.send(socket, 'readDocument', { ...req_data, data: isFlat ? encodeObject(tmp) : tmp }, req_data['organization_id'], socketInfo);
83
85
  } else {
84
- this.wsManager.send(socket, 'ServerError', error, null, roomInfo);
86
+ self.wsManager.send(socket, 'ServerError', error, null, socketInfo);
85
87
  }
86
88
  });
87
89
  } catch (error) {
88
90
  console.log('readDocument error', error);
89
- this.wsManager.send(socket, 'ServerError', 'error', null, roomInfo);
91
+ self.wsManager.send(socket, 'ServerError', 'error', null, socketInfo);
90
92
  }
91
93
  }
92
94
 
93
95
  /** Update Document **/
94
- async updateDocument(socket, req_data, roomInfo) {
96
+ async updateDocument(socket, req_data, socketInfo) {
97
+ const self = this;
95
98
  try {
96
99
  const db = this.dbClient.db(req_data['organization_id']);
97
100
  const collection = db.collection(req_data["collection"]);
@@ -129,20 +132,22 @@ class CoCreateCrud {
129
132
 
130
133
  if(req_data['unset']) response['delete_fields'] = req_data['unset'];
131
134
 
132
- this.broadcast('updateDocument', socket, req_data, response, roomInfo)
135
+ self.broadcast('updateDocument', socket, response, socketInfo)
133
136
  }).catch((error) => {
134
137
  console.log('error', error)
135
- this.wsManager.send(socket, 'ServerError', error, null, roomInfo);
138
+ self.wsManager.send(socket, 'ServerError', error, null, socketInfo);
136
139
  });
137
140
 
138
141
  } catch (error) {
139
142
  console.log(error)
140
- this.wsManager.send(socket, 'updateDocumentError', error, req_data['organization_id']);
143
+ self.wsManager.send(socket, 'updateDocumentError', error, req_data['organization_id']);
141
144
  }
142
145
  }
143
146
 
144
147
  /** Delete Document **/
145
- async deleteDocument(socket, req_data, roomInfo) {
148
+ async deleteDocument(socket, req_data, socketInfo) {
149
+ const self = this;
150
+
146
151
  try {
147
152
  const db = this.dbClient.db(req_data['organization_id']);
148
153
  const collection = db.collection(req_data["collection"]);
@@ -153,29 +158,19 @@ class CoCreateCrud {
153
158
  collection.deleteOne(query, function(error, result) {
154
159
  if (!error) {
155
160
  let response = { ...req_data }
156
- this.broadcast('deleteDocument', socket, req_data, response, roomInfo)
161
+ self.broadcast('deleteDocument', socket, response, socketInfo)
157
162
  } else {
158
- this.wsManager.send(socket, 'ServerError', error, null, roomInfo);
163
+ self.wsManager.send(socket, 'ServerError', error, null, socketInfo);
159
164
  }
160
165
  })
161
166
  } catch (error) {
162
167
  console.log(error);
163
- this.wsManager.send(socket, 'ServerError', 'error', null, roomInfo);
168
+ self.wsManager.send(socket, 'ServerError', 'error', null, socketInfo);
164
169
  }
165
170
  }
166
171
 
167
- broadcast(component, socket, req_data, response, roomInfo) {
168
- if (req_data.broadcast_sender != false) {
169
- this.wsManager.send(socket, component, { ...response, element: req_data['element']}, req_data['organization_id'], roomInfo);
170
- }
171
-
172
- if (req_data.broadcast !== false) {
173
- if (req_data.room) {
174
- this.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'] , req_data.room, component, response, true, roomInfo);
175
- } else {
176
- this.wsManager.broadcast(socket, req_data.namespace || req_data['organization_id'], null, component, response, true, roomInfo)
177
- }
178
- }
172
+ broadcast(component, socket, response, socketInfo) {
173
+ this.wsManager.broadcast(socket, response.namespace || response['organization_id'], response.room, component, response, socketInfo);
179
174
  process.emit('changed-document', response)
180
175
  }
181
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, roomInfo) => this.readDocumentList(socket, data, roomInfo));
12
- this.wsManager.on('readCollectionList', (socket, data, roomInfo) => this.readCollectionList(socket, data, roomInfo));
11
+ this.wsManager.on('readDocumentList', (socket, data, socketInfo) => this.readDocumentList(socket, data, socketInfo));
12
+ this.wsManager.on('readCollectionList', (socket, data, socketInfo) => this.readCollectionList(socket, data, socketInfo));
13
13
  }
14
14
 
15
15
  /**
@@ -47,7 +47,7 @@ class CoCreateList {
47
47
  data: [] // array
48
48
  }
49
49
  **/
50
- async readDocumentList(socket, req_data, roomInfo) {
50
+ async readDocumentList(socket, req_data, socketInfo) {
51
51
  function sleep(ms) {
52
52
  return new Promise((resolve) => {
53
53
  setTimeout(resolve, ms);
@@ -59,7 +59,7 @@ class CoCreateList {
59
59
  const self = this;
60
60
 
61
61
  if (req_data['is_collection']) {
62
- var result = await this.readCollectionList(socket, req_data, roomInfo);
62
+ var result = await this.readCollectionList(socket, req_data, socketInfo);
63
63
  return;
64
64
  }
65
65
 
@@ -116,19 +116,19 @@ class CoCreateList {
116
116
 
117
117
  result_data = result;
118
118
  }
119
- self.wsManager.send(socket, 'readDocumentList', { ...req_data, data: result_data, operator: {...operator, total: total}}, req_data['organization_id'], roomInfo);
119
+ self.wsManager.send(socket, 'readDocumentList', { ...req_data, data: result_data, operator: {...operator, total: total}}, req_data['organization_id'], socketInfo);
120
120
  } else {
121
121
  console.log(error)
122
- self.wsManager.send(socket, 'ServerError', error, null, roomInfo);
122
+ self.wsManager.send(socket, 'ServerError', error, null, socketInfo);
123
123
  }
124
124
  })
125
125
  } catch (error) {
126
126
  console.log('readDocumentList error', error);
127
- this.wsManager.send(socket, 'ServerError', 'error', null, roomInfo);
127
+ this.wsManager.send(socket, 'ServerError', 'error', null, socketInfo);
128
128
  }
129
129
  }
130
130
 
131
- async readCollectionList(socket, data, roomInfo) {
131
+ async readCollectionList(socket, data, socketInfo) {
132
132
  try {
133
133
  var collections = [];
134
134
  const db = this.dbClient.db(req_data['organization_id']);
@@ -145,9 +145,9 @@ class CoCreateList {
145
145
  return result;
146
146
  })
147
147
 
148
- this.wsManager.send(socket, 'readCollectionList', {...data, data: collections }, data['organization_id'], roomInfo);
148
+ this.wsManager.send(socket, 'readCollectionList', {...data, data: collections }, data['organization_id'], socketInfo);
149
149
  } catch(error) {
150
- this.wsManager.send(socket, 'ServerError', 'error', null, roomInfo);
150
+ this.wsManager.send(socket, 'ServerError', 'error', null, socketInfo);
151
151
  }
152
152
  }
153
153