@cocreate/crud-server 1.28.11 → 1.29.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,27 @@
1
+ ## [1.29.1](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.29.0...v1.29.1) (2023-11-09)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * date updated to ISO format ([78efb88](https://github.com/CoCreate-app/CoCreate-crud-server/commit/78efb886aee6b8f2522a32180315781c4824f79d))
7
+ * meta name typo ([cb45152](https://github.com/CoCreate-app/CoCreate-crud-server/commit/cb45152c9895a92cd27c3ddbeb055ad67e0a2f4c))
8
+ * update crud methods ([76e0135](https://github.com/CoCreate-app/CoCreate-crud-server/commit/76e0135f34976beec3c2bbd0f14ec2338b1fecac))
9
+ * update host ([efeddaf](https://github.com/CoCreate-app/CoCreate-crud-server/commit/efeddaff4f791f8c4d3d288f5e108b152eec07c8))
10
+
11
+ # [1.29.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.28.11...v1.29.0) (2023-11-03)
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * removed limit slice ([26c6cc1](https://github.com/CoCreate-app/CoCreate-crud-server/commit/26c6cc1c3f8c760b0c8d90f9ab0923896c2cce59))
17
+ * update dependencies to the lates versions ([e2ddb24](https://github.com/CoCreate-app/CoCreate-crud-server/commit/e2ddb2440daa92bdcd547b355ef75933eced2947))
18
+ * update method to use object.update etc ([b6400da](https://github.com/CoCreate-app/CoCreate-crud-server/commit/b6400da90f16fd98d59ef18b06f40980f91b67d7))
19
+
20
+
21
+ ### Features
22
+
23
+ * get orgainization and storage once using promise ([1dac253](https://github.com/CoCreate-app/CoCreate-crud-server/commit/1dac2539cb5167da803130d0a94458e02318f63e))
24
+
1
25
  ## [1.28.11](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.28.10...v1.28.11) (2023-10-25)
2
26
 
3
27
 
@@ -12,8 +12,7 @@ module.exports = {
12
12
  "pathname": "/docs/crud-server/index.html",
13
13
  "src": "{{./docs/index.html}}",
14
14
  "host": [
15
- "*",
16
- "general.cocreate.app"
15
+ "*"
17
16
  ],
18
17
  "directory": "crud-server",
19
18
  "content-type": "text/html",
package/docs/index.html CHANGED
@@ -11,10 +11,10 @@
11
11
  sizes="32x32"
12
12
  href="https://cocreate.app/images/favicon.ico" />
13
13
  <meta
14
- key="description"
14
+ name="description"
15
15
  content="A simple HTML5 and pure javascript component. Easy configuration using data-attributes and highly styleable." />
16
16
  <meta
17
- key="keywords"
17
+ name="keywords"
18
18
  content="helper classes, utility classes, css framework, css library, inline style classes" />
19
19
  <meta name="robots" content="index,follow" />
20
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/crud-server",
3
- "version": "1.28.11",
3
+ "version": "1.29.1",
4
4
  "description": "CoCreate-crud-server",
5
5
  "keywords": [
6
6
  "cocreate-crud",
@@ -40,8 +40,8 @@
40
40
  },
41
41
  "homepage": "https://cocreate.app/docs/CoCreate-crud-server",
42
42
  "dependencies": {
43
- "@cocreate/config": "^1.6.5",
44
- "@cocreate/utils": "^1.26.1",
43
+ "@cocreate/config": "^1.6.6",
44
+ "@cocreate/utils": "^1.26.2",
45
45
  "csvtojson": "^2.0.10",
46
46
  "json-2-csv": "^3.10.3"
47
47
  }
package/src/index.js CHANGED
@@ -8,7 +8,7 @@ class CoCreateCrudServer {
8
8
  this.wsManager = wsManager
9
9
  this.databases = databases
10
10
  this.ObjectId = ObjectId
11
- this.storages = new Map();
11
+ this.organizations = {};
12
12
  this.init()
13
13
  }
14
14
 
@@ -43,12 +43,12 @@ class CoCreateCrudServer {
43
43
  process.exit()
44
44
 
45
45
  if (this.wsManager) {
46
- const method = ['create', 'read', 'update', 'delete'];
47
46
  const type = ['storage', 'database', 'array', 'index', 'object'];
47
+ const method = ['create', 'read', 'update', 'delete'];
48
48
 
49
- for (let i = 0; i < method.length; i++) {
50
- for (let j = 0; j < type.length; j++) {
51
- const action = method[i] + '.' + type[j];
49
+ for (let i = 0; i < type.length; i++) {
50
+ for (let j = 0; j < method.length; j++) {
51
+ const action = type[i] + '.' + method[j];
52
52
  this.wsManager.on(action, (data) =>
53
53
  this.send(data))
54
54
  }
@@ -76,50 +76,22 @@ class CoCreateCrudServer {
76
76
  }
77
77
  })
78
78
 
79
- let storages = this.storages.get(data.organization_id)
80
- if (storages === false)
81
- return resolve({ serverStorage: false, error: 'A storage or database could not be found' })
82
-
83
- if (!storages) {
84
- if (data.organization_id === this.config.organization_id) {
85
- storages = this.config.storage
86
- if (storages)
87
- this.storages.set(data.organization_id, storages)
88
- } else {
89
- let organization = await this.send({
90
- method: 'read.object',
91
- database: this.config.organization_id,
92
- array: 'organizations',
93
- object: [{ _id: data.organization_id }],
94
- organization_id: this.config.organization_id
95
- })
96
- if (organization
97
- && organization.object
98
- && organization.object[0]) {
99
- if (organization.object[0].storage)
100
- this.storages.set(data.organization_id, organization.object[0].storage)
101
- else
102
- return resolve({ serverStorage: false, error: 'A storage url could not be found' })
103
- } else {
104
- return resolve({ serverOrganization: false, error: 'An organization could not be found' })
105
- }
106
- }
107
- }
79
+ let storages = await this.getStorage(data)
80
+ if (storages.error)
81
+ return resolve(storages)
108
82
 
109
- if (data['timeStamp'])
110
- data['timeStamp'] = new Date(data['timeStamp'])
111
- else
112
- data['timeStamp'] = new Date()
83
+ if (!data['timeStamp'])
84
+ data['timeStamp'] = new Date().toISOString()
113
85
 
114
86
  // TODO: manage error handling if if no method defined
115
- if (data.method.startsWith('update.') && data.upsert != false)
87
+ if (data.method.endsWith('.update') && data.upsert != false)
116
88
  data.upsert = true
117
89
 
118
90
  if (data.array) {
119
91
  if (!data.database)
120
92
  data['database'] = data.organization_id
121
93
 
122
- if (data.method.startsWith('update.object') && data.organization_id !== this.config.organization_id) {
94
+ if (data.method === 'object.update' && data.organization_id !== this.config.organization_id) {
123
95
  let syncKeys
124
96
  if (data.array === 'organizations')
125
97
  syncKeys = ['name', 'logo', 'databases', 'host', 'apis']
@@ -138,15 +110,13 @@ class CoCreateCrudServer {
138
110
  if (object) {
139
111
  for (let key of syncKeys) {
140
112
  if (object[key])
141
- platformUpdate.object[0][key] = object[key]
113
+ platformobject.update[0][key] = object[key]
142
114
  }
143
115
  }
144
116
 
145
117
  this.send(platformUpdate)
146
118
  }
147
-
148
119
  }
149
-
150
120
  }
151
121
 
152
122
  if (!data.storage || !data.storage.length) {
@@ -170,14 +140,11 @@ class CoCreateCrudServer {
170
140
  }
171
141
 
172
142
  if (data.$filter) {
173
- if (!data.type)
174
- data.type = data.method.split('.').pop()
143
+ let type = data.method.split(".")[0]
175
144
  if (data.$filter.sort && data.$filter.sort.length)
176
- data[data.type] = sortData(data[data.type], data.$filter.sort)
177
- if (data.$filter.index && data.$filter.limit)
178
- data[data.type] = data[data.type].slice(data.$filter.index, data.$filter.limit)
145
+ data[type] = sortData(data[type], data.$filter.sort)
179
146
 
180
- data.$filter.count = data[data.type].length
147
+ data.$filter.count = data[type].length
181
148
  }
182
149
 
183
150
  }
@@ -212,6 +179,48 @@ class CoCreateCrudServer {
212
179
  });
213
180
  }
214
181
 
182
+ async getStorage(data) {
183
+ if (this.organizations[data.organization_id])
184
+ return await this.organizations[data.organization_id]
185
+
186
+ if (data.organization_id === this.config.organization_id) {
187
+ this.organizations[data.organization_id] = this.config.storage
188
+ return this.config.storage
189
+ } else {
190
+ if (this.organizations[data.organization_id]) {
191
+ return await this.organizations[data.organization_id]
192
+ } else {
193
+ this.organizations[data.organization_id] = this.getOrganization(data)
194
+ this.organizations[data.organization_id] = await this.organizations[data.organization_id]
195
+ return this.organizations[data.organization_id]
196
+ }
197
+ }
198
+
199
+ }
200
+
201
+ async getOrganization(data) {
202
+ let organization = await this.send({
203
+ method: 'object.read',
204
+ database: this.config.organization_id,
205
+ array: 'organizations',
206
+ object: [{ _id: data.organization_id }],
207
+ organization_id: this.config.organization_id
208
+ })
209
+
210
+ if (organization
211
+ && organization.object
212
+ && organization.object[0]) {
213
+ if (organization.object[0].storage) {
214
+ return organization.object[0].storage
215
+ } else
216
+ return { serverStorage: false, error: 'A storage url could not be found' }
217
+ } else {
218
+ return { serverOrganization: false, error: 'An organization could not be found' }
219
+ }
220
+
221
+ }
222
+
223
+
215
224
  errorHandler(data, error, database, array) {
216
225
  if (typeof error == 'object')
217
226
  error['storage'] = 'mongodb'