corebasic 1.0.179 → 1.0.180
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/libs/dip.js +1 -0
- package/libs/elabase.js +39 -30
- package/libs/features.js +5 -4
- package/package.json +1 -1
package/libs/dip.js
CHANGED
package/libs/elabase.js
CHANGED
|
@@ -55,34 +55,38 @@ export function start(dbName) {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
|
|
58
|
-
let
|
|
59
|
-
let
|
|
60
|
-
let stats = false
|
|
58
|
+
let isBranch = false
|
|
59
|
+
let batches = []
|
|
61
60
|
|
|
62
|
-
export function
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
export function batchBegin() {
|
|
62
|
+
isBranch = true
|
|
63
|
+
batches = []
|
|
65
64
|
}
|
|
66
|
-
export function
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
export function batchAbort() {
|
|
66
|
+
isBranch = false
|
|
67
|
+
batches = []
|
|
69
68
|
}
|
|
70
|
-
export function
|
|
71
|
-
|
|
69
|
+
export function batchReset() {
|
|
70
|
+
batchAbort()
|
|
72
71
|
}
|
|
73
|
-
export function
|
|
74
|
-
let txns =
|
|
75
|
-
let mode =
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
export function batchSubmit(arg) {
|
|
73
|
+
let txns = batches
|
|
74
|
+
let mode = batches.some(txn => txn.insert || txn.update || txn.delete) ? "command" : "query"
|
|
75
|
+
isBranch = false
|
|
76
|
+
batches = []
|
|
78
77
|
return new Promise((resolve, reject) => resolve())
|
|
79
|
-
.then(() => execute({ "
|
|
78
|
+
.then(() => execute({ "batch": txns, mode, version: arg?.version, compression: arg?.compression }))
|
|
80
79
|
.then (result => {
|
|
81
|
-
Events.send("Elabase.
|
|
80
|
+
Events.send("Elabase.batchSubmit", { response: result })
|
|
82
81
|
return result
|
|
83
82
|
})
|
|
84
83
|
}
|
|
85
84
|
|
|
85
|
+
export const operation = async (name, extras) => {
|
|
86
|
+
return execute({ operation: name, ...extras })
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
86
90
|
export const insert = async (meta, collection, value, _id, extras) => {
|
|
87
91
|
if (typeof collection !== "string") throw {message: "Error: collection type is not string in Dip.insert()"}
|
|
88
92
|
// Multi Company Support
|
|
@@ -111,8 +115,8 @@ export const insert = async (meta, collection, value, _id, extras) => {
|
|
|
111
115
|
throw {message: "Error: invalid _id in Dip.insert()"}
|
|
112
116
|
|
|
113
117
|
|
|
114
|
-
if (
|
|
115
|
-
|
|
118
|
+
if (isBranch) {
|
|
119
|
+
batches.push(arg)
|
|
116
120
|
return
|
|
117
121
|
}
|
|
118
122
|
arg.mode = "command"
|
|
@@ -146,8 +150,8 @@ export const query = async (meta, collection, query, options, extras) => {
|
|
|
146
150
|
...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
|
|
147
151
|
}
|
|
148
152
|
arg = Object.assign(arg, extras)
|
|
149
|
-
if (
|
|
150
|
-
|
|
153
|
+
if (isBranch) {
|
|
154
|
+
batches.push(arg)
|
|
151
155
|
return
|
|
152
156
|
}
|
|
153
157
|
arg.mode = "query"
|
|
@@ -205,8 +209,8 @@ export const update = async (meta, collection, query, update, options, extras) =
|
|
|
205
209
|
...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
|
|
206
210
|
}
|
|
207
211
|
arg = Object.assign(arg, extras)
|
|
208
|
-
if (
|
|
209
|
-
|
|
212
|
+
if (isBranch) {
|
|
213
|
+
batches.push(arg)
|
|
210
214
|
return
|
|
211
215
|
}
|
|
212
216
|
arg.mode = "command"
|
|
@@ -218,7 +222,7 @@ export const update = async (meta, collection, query, update, options, extras) =
|
|
|
218
222
|
})
|
|
219
223
|
}
|
|
220
224
|
|
|
221
|
-
export const remove = async (meta, collection, query, extras) => {
|
|
225
|
+
export const remove = async (meta, collection, query, options, extras) => {
|
|
222
226
|
// Multi Company Support
|
|
223
227
|
if (Utils.isEmpty(meta?.company)) throw {message: "Error: meta argument not provided in Dip.remove()"}
|
|
224
228
|
if (typeof collection !== "string") throw {message: "Error: collection type is not string in Dip.remove()"}
|
|
@@ -226,17 +230,22 @@ export const remove = async (meta, collection, query, extras) => {
|
|
|
226
230
|
if (meta.company !== "GLOBAL")
|
|
227
231
|
query.company = meta.company
|
|
228
232
|
// ---------------------
|
|
233
|
+
if (Utils.isEmpty(query._id) && !meta.allowDangerousRemove) {
|
|
234
|
+
throw { message: "Error: Dip.remove() without _id blocked by default (Dangerous Operation). Set allowDangerousRemove key if intentional." }
|
|
235
|
+
return
|
|
236
|
+
}
|
|
229
237
|
|
|
230
238
|
var arg = {
|
|
231
239
|
collection: collection,
|
|
232
240
|
query: query,
|
|
233
241
|
delete: true,
|
|
242
|
+
options: options ? options : {},
|
|
234
243
|
...(meta.DIP_URL ? {DIP_URL: meta.DIP_URL} : {}),
|
|
235
244
|
...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
|
|
236
245
|
}
|
|
237
246
|
arg = Object.assign(arg, extras)
|
|
238
|
-
if (
|
|
239
|
-
|
|
247
|
+
if (isBranch) {
|
|
248
|
+
batches.push(arg)
|
|
240
249
|
return
|
|
241
250
|
}
|
|
242
251
|
arg.mode = "command"
|
|
@@ -273,8 +282,6 @@ function execute(arg) {
|
|
|
273
282
|
arg.engine = arg.engine ?? internal.engineName
|
|
274
283
|
arg.compression = true // Compress all for now
|
|
275
284
|
|
|
276
|
-
if (stats)
|
|
277
|
-
arg.stats = true
|
|
278
285
|
|
|
279
286
|
return config.useDipper ? dipper(arg)
|
|
280
287
|
: axios
|
|
@@ -285,7 +292,9 @@ function execute(arg) {
|
|
|
285
292
|
// console.log(JSON.stringify(res.header, null, 4));
|
|
286
293
|
// console.log(JSON.stringify(res.body, null, 4));
|
|
287
294
|
|
|
288
|
-
|
|
295
|
+
let res = result.data.mode === "query" ? result.data.items : result.data
|
|
296
|
+
res.stats = result.data.mode === "query" ? _ => result.data.stats : res.stats
|
|
297
|
+
return res
|
|
289
298
|
})
|
|
290
299
|
// .catch(err => { console.log(err.message); console.log(err.response); return err});
|
|
291
300
|
}
|
package/libs/features.js
CHANGED
|
@@ -118,9 +118,10 @@ function getFeaturelessFeature(req) {
|
|
|
118
118
|
|
|
119
119
|
const apiHandler = async (req, res) => {
|
|
120
120
|
let method = req.method.toLowerCase()
|
|
121
|
+
let featureless
|
|
121
122
|
try {
|
|
122
123
|
let feature = getFeature(req.body?.feature)
|
|
123
|
-
|
|
124
|
+
featureless = feature ? undefined : (feature = getFeaturelessFeature(req))
|
|
124
125
|
|
|
125
126
|
if (!req.body?.feature && !featureless) {
|
|
126
127
|
console.warn(`Feature: feature not sent by client`)
|
|
@@ -150,7 +151,7 @@ const apiHandler = async (req, res) => {
|
|
|
150
151
|
await feature.handler({...req, headers: req.headers, body: {...req.body, topic} }, res)
|
|
151
152
|
} catch (err) {
|
|
152
153
|
if (process.env.DEBUG_MODE)
|
|
153
|
-
console.log('Error: Feature: ', req.body?.feature, err)
|
|
154
|
+
console.log('Error: Feature: ', req.body?.feature ?? (featureless ? `Featureless Api:${featureless.api}` : undefined), err)
|
|
154
155
|
throw {status: 500, message: "Failed to GET feature", ...err}
|
|
155
156
|
}
|
|
156
157
|
} else if (method !== "get" && feature.bypass) {
|
|
@@ -158,14 +159,14 @@ const apiHandler = async (req, res) => {
|
|
|
158
159
|
await feature.handler(topic, prepareMessage(req), req, res)
|
|
159
160
|
} catch (err) {
|
|
160
161
|
if (process.env.DEBUG_MODE)
|
|
161
|
-
console.log('Error: Feature: ', req.body?.feature, err)
|
|
162
|
+
console.log('Error: Feature: ', req.body?.feature ?? (featureless ? `Featureless Api:${featureless.api}` : undefined), err)
|
|
162
163
|
throw {status: 500, message: "Failed to POST feature", ...err}
|
|
163
164
|
}
|
|
164
165
|
} else
|
|
165
166
|
await commandAction(req, res, topic)
|
|
166
167
|
} catch (err) {
|
|
167
168
|
if (process.env.DEBUG_MODE)
|
|
168
|
-
console.log('Error: Feature: ', req.body?.feature, err)
|
|
169
|
+
console.log('Error: Feature: ', req.body?.feature ?? (featureless ? `Featureless Api:${featureless.api}` : undefined), err)
|
|
169
170
|
try { // Sometimes error occurs when disconnecting stream from front end
|
|
170
171
|
res.status(err.status ?? 500).json(err)
|
|
171
172
|
} catch (_) { }
|