corebasic 1.0.205 → 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 CHANGED
@@ -19,6 +19,8 @@ export const outletMeta = Elabase.outletMeta
19
19
  export const customMeta = Elabase.customMeta
20
20
  export const schema = Elabase.schema
21
21
  export const isDipMeta = Elabase.isDipMeta
22
+ export const excludeCollectionConfig = Elabase.excludeCollectionConfig
23
+ export const includeCollectionConfig = Elabase.includeCollectionConfig
22
24
 
23
25
  export const shard_stats = Elabase.shard_stats
24
26
  export let config = Elabase.config
package/libs/elabase.js CHANGED
@@ -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
- console.warn(`Warn: Missing config for collection: ${collection}${fn_name ? ` ${fn_name}` : ''}`)
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
- await Dip.update(message.meta, `users.txns.${message.user}`, {_id: message.txn}, { $setOnInsert: { user: message.user, feature: message.feature, date: message.date, created: message.date, updated: message.date, status: "Queued" } }, {upsert: true}) // Can always update the status later
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(message.meta, "Features.txns", {_id: message.txn, status: "Processed"})
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(req.meta, "Features.txns", {_id: req.params.id})
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
- try {
290
- res.json({ data: await Dip.query(req.meta, `users.txns.${req.params.id}`, {}, { $orderby: { date: -1 } }) })
291
- } catch {
292
- res.status(500).json({ message: "Failed to retreive data" })
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
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corebasic",
3
3
  "type": "module",
4
- "version": "1.0.205",
4
+ "version": "1.0.206",
5
5
  "description": "",
6
6
  "main": "index.js",
7
7
  "scripts": {