@cocreate/crud-server 1.23.0 → 1.23.2
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 +15 -0
- package/CoCreate.config.js +1 -1
- package/package.json +2 -4
- package/src/index.js +23 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## [1.23.2](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.23.1...v1.23.2) (2023-06-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* renamed db to storage ([9b1df98](https://github.com/CoCreate-app/CoCreate-crud-server/commit/9b1df98ecae81f2c861757f51d04bf773dd77f2b))
|
|
7
|
+
* renamed hosts to host. the value can be a string or an array of strings ([1cfaade](https://github.com/CoCreate-app/CoCreate-crud-server/commit/1cfaadeeeccd8b899a83ed1a0c1b2d0811829b77))
|
|
8
|
+
|
|
9
|
+
## [1.23.1](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.23.0...v1.23.1) (2023-06-10)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* Update dependencies versions for [@cocreate](https://github.com/cocreate) libraries ([24ae198](https://github.com/CoCreate-app/CoCreate-crud-server/commit/24ae19861b462a35c1f3c0770070b24226525746))
|
|
15
|
+
|
|
1
16
|
# [1.23.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.22.4...v1.23.0) (2023-06-10)
|
|
2
17
|
|
|
3
18
|
|
package/CoCreate.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/crud-server",
|
|
3
|
-
"version": "1.23.
|
|
3
|
+
"version": "1.23.2",
|
|
4
4
|
"description": "CoCreate-crud-server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cocreate-crud",
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
"scripts": {
|
|
27
27
|
"demo": "PORT=5000 node demo/server.js",
|
|
28
28
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
29
|
-
"docs": "node ./node_modules/@cocreate/docs/src/index.js",
|
|
30
29
|
"postinstall": "node ./node_modules/@cocreate/cli/check-coc.js"
|
|
31
30
|
},
|
|
32
31
|
"main": "./src/index",
|
|
@@ -44,8 +43,7 @@
|
|
|
44
43
|
"@cocreate/cli": "^1.29.3"
|
|
45
44
|
},
|
|
46
45
|
"dependencies": {
|
|
47
|
-
"@cocreate/
|
|
48
|
-
"@cocreate/utils": "^1.21.3",
|
|
46
|
+
"@cocreate/utils": "^1.21.4",
|
|
49
47
|
"csvtojson": "^2.0.10",
|
|
50
48
|
"json-2-csv": "^3.10.3"
|
|
51
49
|
}
|
package/src/index.js
CHANGED
|
@@ -8,14 +8,14 @@ class CoCreateCrudServer {
|
|
|
8
8
|
this.wsManager = wsManager
|
|
9
9
|
this.databases = databases
|
|
10
10
|
this.ObjectId = ObjectId
|
|
11
|
-
this.
|
|
11
|
+
this.storages = new Map();
|
|
12
12
|
config([
|
|
13
13
|
{
|
|
14
14
|
key: 'organization_id',
|
|
15
15
|
prompt: 'Enter your organization_id: ',
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
|
-
key: '
|
|
18
|
+
key: 'storage',
|
|
19
19
|
prompt: 'Enter your db object as json.string: ',
|
|
20
20
|
}
|
|
21
21
|
])//
|
|
@@ -110,14 +110,15 @@ class CoCreateCrudServer {
|
|
|
110
110
|
if (!data.organization_id)
|
|
111
111
|
return resolve()
|
|
112
112
|
|
|
113
|
-
let
|
|
114
|
-
if (
|
|
115
|
-
return resolve({
|
|
113
|
+
let storage = this.storages.get(data.organization_id)
|
|
114
|
+
if (storage === false)
|
|
115
|
+
return resolve({ storage: false, error: 'A storage or database could not be found' })
|
|
116
116
|
|
|
117
|
-
if (!
|
|
117
|
+
if (!storage) {
|
|
118
118
|
if (data.organization_id === process.env.organization_id) {
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
storage = process.env.storage
|
|
120
|
+
if (storage)
|
|
121
|
+
this.storages.set(data.organization_id, JSON.parse(storage))
|
|
121
122
|
} else {
|
|
122
123
|
let organization = await this.readDocument({
|
|
123
124
|
database: process.env.organization_id,
|
|
@@ -127,13 +128,13 @@ class CoCreateCrudServer {
|
|
|
127
128
|
})
|
|
128
129
|
if (organization && organization.document && organization.document[0])
|
|
129
130
|
organization = organization.document[0]
|
|
130
|
-
if (organization && organization.
|
|
131
|
-
|
|
132
|
-
this.
|
|
131
|
+
if (organization && organization.storage) {
|
|
132
|
+
storage = organization.storage
|
|
133
|
+
this.storages.set(data.organization_id, storage)
|
|
133
134
|
} else {
|
|
134
|
-
this.
|
|
135
|
+
this.storages.set(data.organization_id, false)
|
|
135
136
|
if (organization)
|
|
136
|
-
return resolve({
|
|
137
|
+
return resolve({ storage: false, error: 'database url could not be found' })
|
|
137
138
|
else
|
|
138
139
|
return resolve({ organization: false, error: 'organization could not be found' })
|
|
139
140
|
}
|
|
@@ -154,7 +155,7 @@ class CoCreateCrudServer {
|
|
|
154
155
|
if (action === 'updateDocument' && data.organization_id !== process.env.organization_id) {
|
|
155
156
|
let syncKeys
|
|
156
157
|
if (data.collection === 'organizations')
|
|
157
|
-
syncKeys = ['name', 'logo', 'databases', '
|
|
158
|
+
syncKeys = ['name', 'logo', 'databases', 'host', 'apis']
|
|
158
159
|
else if (data.collection === 'users')
|
|
159
160
|
syncKeys = ['name', 'email', 'password', 'avatar']
|
|
160
161
|
|
|
@@ -181,14 +182,14 @@ class CoCreateCrudServer {
|
|
|
181
182
|
|
|
182
183
|
}
|
|
183
184
|
|
|
184
|
-
if (!data.
|
|
185
|
-
data.
|
|
186
|
-
} else if (!Array.isArray(data.
|
|
187
|
-
data.
|
|
185
|
+
if (!data.storage || !data.storage.length) {
|
|
186
|
+
data.storage = [Object.keys(storage)[0]]
|
|
187
|
+
} else if (!Array.isArray(data.storage))
|
|
188
|
+
data.storage = [data.storage]
|
|
188
189
|
|
|
189
|
-
for (let i = 0; i < data.
|
|
190
|
-
if (
|
|
191
|
-
let db =
|
|
190
|
+
for (let i = 0; i < data.storage.length; i++) {
|
|
191
|
+
if (storage && storage[data.storage[i]]) {
|
|
192
|
+
let db = storage[data.storage[i]]
|
|
192
193
|
|
|
193
194
|
if (db.provider && this.databases[db.provider]) {
|
|
194
195
|
if (!Array.isArray(db.url))
|
|
@@ -234,7 +235,7 @@ class CoCreateCrudServer {
|
|
|
234
235
|
|
|
235
236
|
errorHandler(data, error, database, collection) {
|
|
236
237
|
if (typeof error == 'object')
|
|
237
|
-
error['
|
|
238
|
+
error['storage'] = 'mongodb'
|
|
238
239
|
else
|
|
239
240
|
error = { location: 'crudServer', message: error }
|
|
240
241
|
|