@cocreate/crud-server 1.18.0 → 1.19.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 +20 -0
- package/CoCreate.config.js +1 -1
- package/package.json +1 -1
- package/src/index.js +80 -29
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
## [1.19.1](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.19.0...v1.19.1) (2023-04-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* pass dbUrl to constructor ([7900c05](https://github.com/CoCreate-app/CoCreate-crud-server/commit/7900c0539998cb5f42cd27aed3844d0d43f5370b))
|
|
7
|
+
|
|
8
|
+
# [1.19.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.18.0...v1.19.0) (2023-04-11)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* renamed domans to hosts ([312353a](https://github.com/CoCreate-app/CoCreate-crud-server/commit/312353a9ec03d65b05d749675db9c73a1e16e069))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* custom dburls stored and fetched from platform db organizations. sync fields from org and user to platform prototype ([183839b](https://github.com/CoCreate-app/CoCreate-crud-server/commit/183839b02655ac4d7edf24375b9012ad80feeee9))
|
|
19
|
+
* if dbUrls not defined query platform db ([05fecfe](https://github.com/CoCreate-app/CoCreate-crud-server/commit/05fecfe999f471541717765e606aa57649398821))
|
|
20
|
+
|
|
1
21
|
# [1.18.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.17.29...v1.18.0) (2023-03-19)
|
|
2
22
|
|
|
3
23
|
|
package/CoCreate.config.js
CHANGED
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
const {ObjectId, searchData, sortData} = require("@cocreate/utils");
|
|
4
4
|
|
|
5
5
|
class CoCreateCrudServer {
|
|
6
|
-
constructor(wsManager, databases) {
|
|
6
|
+
constructor(wsManager, databases, dbUrl) {
|
|
7
7
|
this.wsManager = wsManager
|
|
8
8
|
this.databases = databases
|
|
9
|
+
this.dbUrl = dbUrl
|
|
9
10
|
this.ObjectId = ObjectId
|
|
11
|
+
this.databaseUrls = new Map();
|
|
10
12
|
this.init();
|
|
11
13
|
}
|
|
12
14
|
|
|
@@ -95,20 +97,49 @@ class CoCreateCrudServer {
|
|
|
95
97
|
async db(socket, action, data) {
|
|
96
98
|
return new Promise(async (resolve) => {
|
|
97
99
|
try {
|
|
100
|
+
if (!data.organization_id)
|
|
101
|
+
resolve()
|
|
102
|
+
|
|
103
|
+
let dbUrl = this.databaseUrls.get(data.organization_id)
|
|
104
|
+
if (dbUrl == 'false')
|
|
105
|
+
resolve()
|
|
106
|
+
|
|
107
|
+
if (!dbUrl) {
|
|
108
|
+
if (data.organization_id === process.env.organization_id) {
|
|
109
|
+
dbUrl = this.dbUrl
|
|
110
|
+
console.log('platform dbUrl crud', dbUrl)
|
|
111
|
+
this.databaseUrls.set(data.organization_id, dbUrl)
|
|
112
|
+
} else {
|
|
113
|
+
let organization = await this.databases['mongodb']['readDocument']({
|
|
114
|
+
database: process.env.organization_id,
|
|
115
|
+
collection: 'organizations',
|
|
116
|
+
document: [{_id: data.organization_id}],
|
|
117
|
+
organization_id: process.env.organization_id
|
|
118
|
+
})
|
|
119
|
+
if (organization && organization.document && organization.document[0])
|
|
120
|
+
organization = organization.document[0]
|
|
121
|
+
if (organization && organization.databases) {
|
|
122
|
+
dbUrl = organization.databases
|
|
123
|
+
this.databaseUrls.set(data.organization_id, dbUrl)
|
|
124
|
+
console.log('organization dbUrl queried from platform')
|
|
125
|
+
} else {
|
|
126
|
+
this.databaseUrls.set(data.organization_id, 'false')
|
|
127
|
+
console.log('organization or dbUrl urls could not be found')
|
|
128
|
+
resolve()
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
98
133
|
if (!data['timeStamp'])
|
|
99
134
|
data['timeStamp'] = new Date().toISOString()
|
|
100
135
|
|
|
101
136
|
if (action == 'updateDocument' && data.upsert != false)
|
|
102
137
|
data.upsert = true
|
|
103
|
-
|
|
138
|
+
|
|
104
139
|
// ToDo: support stats from multiple dbs
|
|
105
140
|
if (data.collection || action == 'databaseStats') {
|
|
106
|
-
if (!data.db)
|
|
107
|
-
data['db'] = ['indexeddb', 'mongodb']
|
|
108
141
|
if (!data.database)
|
|
109
|
-
data['database'] = data.organization_id
|
|
110
|
-
if (!data.organization_id)
|
|
111
|
-
data['organization_id'] = process.env.organization_id
|
|
142
|
+
data['database'] = data.organization_id
|
|
112
143
|
}
|
|
113
144
|
|
|
114
145
|
if (!data.db || !data.db.length)
|
|
@@ -117,30 +148,50 @@ class CoCreateCrudServer {
|
|
|
117
148
|
for (let i = 0; i < data.db.length; i++) {
|
|
118
149
|
dbsLength -= 1
|
|
119
150
|
if (this.databases[data.db[i]]) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
151
|
+
// ToDo: for loop on each dbUrl
|
|
152
|
+
if (dbUrl && dbUrl[data.db[i]]) {
|
|
153
|
+
data['dbUrl'] = dbUrl[data.db[i]][0]
|
|
154
|
+
data = await this.databases[data.db[i]][action](data)
|
|
155
|
+
|
|
156
|
+
// ToDo: sync orgdb and platformdb specified keys from collections organizations and users
|
|
157
|
+
if (data.collection === 'organization' || data.collection === 'user') {
|
|
158
|
+
let syncKeys
|
|
159
|
+
if (data.collection === 'organizations')
|
|
160
|
+
syncKeys = ['name', 'logo', 'databases', 'hosts', 'apis']
|
|
161
|
+
else if (data.collection === 'users')
|
|
162
|
+
syncKeys = ['name', 'email', 'password', 'avatar']
|
|
163
|
+
|
|
164
|
+
if (syncKeys && syncKeys.length) {
|
|
165
|
+
let platformUpdate = {
|
|
166
|
+
dbUrl: dbUrl[data.db[i]][0],
|
|
167
|
+
database: process.env.organization_id,
|
|
168
|
+
collection: data.collection,
|
|
169
|
+
document: [{}],
|
|
170
|
+
organization_id: process.env.organization_id
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
let document = data.document[0] || data.document
|
|
174
|
+
if (document) {
|
|
175
|
+
for (let key of syncKeys) {
|
|
176
|
+
if (document[key])
|
|
177
|
+
platformUpdate.document[0][key] = document[key]
|
|
178
|
+
}
|
|
179
|
+
}
|
|
132
180
|
}
|
|
181
|
+
|
|
182
|
+
this.databases['mongodb'][action]()
|
|
133
183
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
184
|
+
//ToDo: sorting should take place here in order to return sorted values from multiple dbs
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (!dbsLength) {
|
|
189
|
+
if (socket) {
|
|
190
|
+
this.wsManager.broadcast(socket, action, data);
|
|
191
|
+
process.emit('changed-document', data)
|
|
192
|
+
resolve()
|
|
193
|
+
} else {
|
|
194
|
+
resolve(data)
|
|
144
195
|
}
|
|
145
196
|
}
|
|
146
197
|
}
|