@cocreate/crud-server 1.3.3 → 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,12 @@
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
+
1
10
  ## [1.3.3](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.3.2...v1.3.3) (2022-03-05)
2
11
 
3
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/crud-server",
3
- "version": "1.3.3",
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,15 @@ 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
23
  const self = this;
24
24
  if(!req_data.data) return;
25
25
 
@@ -34,21 +34,21 @@ class CoCreateCrud {
34
34
  // let isFlat = req_data.isFlat == false ? false : true;
35
35
  // const response_data = isFlat ? encodeObject(response) : response;
36
36
  // const response_data = response;
37
- self.broadcast('createDocument', socket, req_data, response, roomInfo)
37
+ self.broadcast('createDocument', socket, response, socketInfo)
38
38
  } else {
39
- self.wsManager.send(socket, 'ServerError', error, null, roomInfo);
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, roomInfo);
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, roomInfo) {
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, roomInfo);
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'], roomInfo);
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, roomInfo);
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, roomInfo);
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, roomInfo) {
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, req_data, response, roomInfo)
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, roomInfo);
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, roomInfo) {
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, req_data, response, roomInfo)
161
+ self.broadcast('deleteDocument', socket, response, socketInfo)
162
162
  } else {
163
- self.wsManager.send(socket, 'ServerError', error, null, roomInfo);
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, roomInfo);
168
+ self.wsManager.send(socket, 'ServerError', 'error', null, socketInfo);
169
169
  }
170
170
  }
171
171
 
172
- broadcast(component, socket, req_data, response, roomInfo) {
173
- if (req_data.broadcast_sender != false) {
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, 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