corebasic 1.0.259 → 1.0.260

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.
@@ -182,10 +182,29 @@ const apiHandler = async (req, res) => {
182
182
  meta.outlet = 'DEFAULT_OUTLET';
183
183
  }
184
184
  meta.txn = meta.txn ?? Utils.uid();
185
+ function buildQuery(key, id) {
186
+ key = key ? key : "_id";
187
+ const array_paths = key.split(".$.");
188
+ const last_path = array_paths.pop();
189
+ const query = {};
190
+ let obj = query;
191
+ for (const path of array_paths) {
192
+ obj[path] = { $elemMatch: {} };
193
+ obj = obj[path].$elemMatch;
194
+ }
195
+ if (last_path?.endsWith(".$"))
196
+ obj[last_path.split(".$")[0]] = { $elemMatch: { $eq: id } };
197
+ else if (last_path)
198
+ obj[last_path] = id;
199
+ else
200
+ return undefined;
201
+ return query;
202
+ }
185
203
  const message = {
186
204
  meta,
187
205
  data: req.body.data,
188
206
  params: featureless ? req.params : req.body.params,
207
+ query: req.body.params?.key && (feature.key)?.includes(req.body.params?.key) ? buildQuery(req.body.params?.key ?? "_id", req.body.params?.id) : req.body.params?.id ? { _id: req.body.params?.id } : undefined
189
208
  };
190
209
  const appReq = {
191
210
  meta: message.meta,
package/libs/features.ts CHANGED
@@ -63,6 +63,7 @@ type FeatureMessage<I = unknown, T extends keyof Schema = keyof Schema> = {
63
63
  meta: FeatureMeta & { topic: T }
64
64
  data: I
65
65
  params: FeatureParams
66
+ query?: unknown // This is the buildQuery not the express query
66
67
 
67
68
  // feature // Only used as req.body.feature in features.ts, session.ts
68
69
  // client // Only used as req.body.client in auth.ts, session.ts and messaging.ts
@@ -143,7 +144,7 @@ type RemoteFeatureEntry = {
143
144
  headers?: {JWT?: string, service?: boolean, NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN?: string}
144
145
  }
145
146
 
146
- type FeatureEntry = { api: string, topic: string, bypass: boolean, featureless: boolean, subscribe: string, handler: Handler<unknown, unknown, keyof Schema> }
147
+ type FeatureEntry = { api: string, topic: string, bypass: boolean, featureless: boolean, subscribe: string, handler: Handler<unknown, unknown, keyof Schema>, key?: string[] }
147
148
 
148
149
 
149
150
  let features: Record<string, FeatureEntry> = {}
@@ -309,10 +310,32 @@ const apiHandler = async (req: ExpressRequest, res: ExpressResponse) => {
309
310
 
310
311
  meta.txn = meta.txn ?? Utils.uid()
311
312
 
313
+
314
+ function buildQuery(key: string, id: unknown): unknown {
315
+ key = key ? key : "_id"
316
+ const array_paths = key.split(".$.")
317
+ const last_path = array_paths.pop()
318
+ const query: Record<string, unknown> = {}
319
+ let obj = query
320
+ for (const path of array_paths) {
321
+ obj[path] = { $elemMatch: { } }
322
+ obj = (obj[path] as { $elemMatch: Record<string, unknown> }).$elemMatch
323
+ }
324
+
325
+ if (last_path?.endsWith(".$"))
326
+ obj[last_path.split(".$")[0]!] = { $elemMatch: {$eq: id} }
327
+ else if (last_path)
328
+ obj[last_path] = id
329
+ else
330
+ return undefined
331
+ return query
332
+ }
333
+
312
334
  const message: FeatureMessage = {
313
335
  meta,
314
336
  data: req.body.data,
315
337
  params: featureless ? req.params : req.body.params!,
338
+ query: req.body.params?.key && (feature.key!)?.includes(req.body.params?.key as string) ? buildQuery(req.body.params?.key ?? "_id", req.body.params?.id) : req.body.params?.id ? {_id: req.body.params?.id} : undefined
316
339
  }
317
340
 
318
341
  const appReq: Req = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corebasic",
3
3
  "type": "module",
4
- "version": "1.0.259",
4
+ "version": "1.0.260",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "types": "./index.ts",