corebasic 1.0.204 → 1.0.206
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 +4 -1
- package/libs/elabase.js +10 -2
- package/libs/features.js +20 -10
- package/package.json +1 -1
package/libs/dip.js
CHANGED
|
@@ -18,6 +18,9 @@ export const companyMeta = Elabase.companyMeta
|
|
|
18
18
|
export const outletMeta = Elabase.outletMeta
|
|
19
19
|
export const customMeta = Elabase.customMeta
|
|
20
20
|
export const schema = Elabase.schema
|
|
21
|
+
export const isDipMeta = Elabase.isDipMeta
|
|
22
|
+
export const excludeCollectionConfig = Elabase.excludeCollectionConfig
|
|
23
|
+
export const includeCollectionConfig = Elabase.includeCollectionConfig
|
|
21
24
|
|
|
22
25
|
export const shard_stats = Elabase.shard_stats
|
|
23
26
|
export let config = Elabase.config
|
|
@@ -88,7 +91,7 @@ export const idip = async (message, callback, cleanup) => {
|
|
|
88
91
|
|
|
89
92
|
|
|
90
93
|
export const insertKeys = (message, meta) => {
|
|
91
|
-
if (!(meta
|
|
94
|
+
if (!isDipMeta(meta)) throw {message: 'Error: Provided meta is not an instance of DipMeta in Dip.insertKeys()'}
|
|
92
95
|
return {
|
|
93
96
|
"created": message.date, "updated": message.date,
|
|
94
97
|
"createdBy": message.meta.staff,
|
package/libs/elabase.js
CHANGED
|
@@ -67,7 +67,7 @@ class DipMeta {
|
|
|
67
67
|
Object.freeze(this);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
|
|
70
|
+
export const isDipMeta = meta => meta instanceof DipMeta
|
|
71
71
|
|
|
72
72
|
export const globalMeta = args => {
|
|
73
73
|
return new DipMeta({ ...args, company: "GLOBAL", outlet: "GLOBAL" })
|
|
@@ -255,6 +255,13 @@ function init_collections_config() {
|
|
|
255
255
|
if (COLLECTIONS_JSON)
|
|
256
256
|
init_collections_config()
|
|
257
257
|
|
|
258
|
+
const EXCLUDED_COLLECTIONS_CONFIG = {}
|
|
259
|
+
export function excludeCollectionConfig(collection) {
|
|
260
|
+
EXCLUDED_COLLECTIONS_CONFIG[collection] = true
|
|
261
|
+
}
|
|
262
|
+
export function includeCollectionConfig(collection) {
|
|
263
|
+
delete EXCLUDED_COLLECTIONS_CONFIG[collection]
|
|
264
|
+
}
|
|
258
265
|
|
|
259
266
|
function validate_topology(meta, collection, fn_name) {
|
|
260
267
|
|
|
@@ -262,7 +269,8 @@ function validate_topology(meta, collection, fn_name) {
|
|
|
262
269
|
|
|
263
270
|
let config = COLLECTIONS_JSON?.[collection]
|
|
264
271
|
if (!config) {
|
|
265
|
-
|
|
272
|
+
if (!EXCLUDED_COLLECTIONS_CONFIG[collection])
|
|
273
|
+
console.warn(`Warn: Missing config for collection: ${collection}${fn_name ? ` ${fn_name}` : ''}`)
|
|
266
274
|
return new_meta
|
|
267
275
|
}
|
|
268
276
|
|
package/libs/features.js
CHANGED
|
@@ -217,6 +217,9 @@ function registerApi() {
|
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
export const start = async (app, url, file) => {
|
|
220
|
+
const globalMeta = Dip.globalMeta()
|
|
221
|
+
Dip.excludeCollectionConfig("users.txns")
|
|
222
|
+
Dip.excludeCollectionConfig("Features.txns")
|
|
220
223
|
ExpressApp = app
|
|
221
224
|
PROJECT_ROOT_URL = url
|
|
222
225
|
features = await Utils.fileToJson(url, file)
|
|
@@ -257,9 +260,12 @@ export const start = async (app, url, file) => {
|
|
|
257
260
|
topic = topic.replace(/^.*Features./,'')
|
|
258
261
|
while (true) {
|
|
259
262
|
try {
|
|
260
|
-
|
|
263
|
+
// const iso_date = new Date(message.date).toISOString()
|
|
264
|
+
// // TODO: use $useChunks: [] once support is added in dip insert
|
|
265
|
+
// await Dip.insert(globalMeta, `users.txns`, { _id: `${message.user}_${iso_date}_${message.txn}`, user: message.user, feature: message.feature, date: message.date, created: message.date, updated: message.date, status: "Queued" }, {idempotent: true}) // Can always update the status later
|
|
266
|
+
// TODO: Avoid duplicate processing
|
|
261
267
|
await features[message.feature].handler(topic, message)
|
|
262
|
-
await Dip.insert(
|
|
268
|
+
await Dip.insert(globalMeta, "Features.txns", {_id: message.txn, status: "Processed"}, {idempotent: true})
|
|
263
269
|
break
|
|
264
270
|
} catch(err) {
|
|
265
271
|
if (process.env.DEBUG_MODE)
|
|
@@ -276,7 +282,7 @@ export const start = async (app, url, file) => {
|
|
|
276
282
|
// Transaction status api
|
|
277
283
|
app.get('/transactions/:id', async (req, res) => { // Front end calls this as a regular feature call. so `req.meta` exists
|
|
278
284
|
try {
|
|
279
|
-
let items = await Dip.query(
|
|
285
|
+
let items = await Dip.query(globalMeta, "Features.txns", {_id: req.params.id})
|
|
280
286
|
if (items.length)
|
|
281
287
|
res.json({ data: { ...items[0], txn: items._id } })
|
|
282
288
|
else
|
|
@@ -285,13 +291,17 @@ export const start = async (app, url, file) => {
|
|
|
285
291
|
res.status(500).json({ message: "Failed to retreive data" })
|
|
286
292
|
}
|
|
287
293
|
})
|
|
288
|
-
app.get('/users/:id/transactions', async (req, res) => {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
})
|
|
294
|
+
// app.get('/users/:id/transactions', async (req, res) => {
|
|
295
|
+
// try {
|
|
296
|
+
// const idPrefix = `${req.params.id}_`
|
|
297
|
+
// // TODO: use $useChunks: [] once support is added in dip insert
|
|
298
|
+
// // TODO: remove $orderby: { date: -1 } and remove $orderby: { _id: -1 }
|
|
299
|
+
// // res.json({ data: await Dip.query(globalMeta, `users.txns`, {}, { $rangeFrom: idPrefix, $rangeTo: idPrefix, $rangeDirection: -1, $rangeInclusive: true, $orderby: { date: -1 } }) })
|
|
300
|
+
// res.json({ data: await Dip.query(globalMeta, `users.txns`, {}, { $rangeFrom: idPrefix, $rangeTo: idPrefix, $rangeDirection: -1, $rangeInclusive: true, $orderby: { _id: -1 } }) })
|
|
301
|
+
// } catch {
|
|
302
|
+
// res.status(500).json({ message: "Failed to retreive data" })
|
|
303
|
+
// }
|
|
304
|
+
// })
|
|
295
305
|
|
|
296
306
|
try { await Messaging.start(app) } catch { console.log('Messaging failed to start. Maybe missing redis') }
|
|
297
307
|
}
|