@dnax/core 0.75.0 → 0.75.5

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/app/hono.ts CHANGED
@@ -321,8 +321,11 @@ function HonoInstance(): typeof app {
321
321
  const col = getCollection(collection, c.var["tenant-id"]);
322
322
 
323
323
  // Controlle des actions à mener
324
- if (!getAction(action) && !col?.customApi?.hasOwnProperty(action)) {
325
- throw new ContextError(`Action ${action} not found`, 400);
324
+ if (!getAction(action) && !col?.actions?.hasOwnProperty(action)) {
325
+ throw new ContextError(
326
+ `Action ${action} not found on ${collection}`,
327
+ 400
328
+ );
326
329
  }
327
330
 
328
331
  useCache = stringToBoolean(useCache, false);
@@ -657,8 +660,8 @@ function HonoInstance(): typeof app {
657
660
  response = await rest.insertOne(collection, body?.data || {});
658
661
  }
659
662
 
660
- if (!getAction(action) && col?.customApi?.hasOwnProperty(action)) {
661
- response = await rest.customApi(collection, action, body?.data || {});
663
+ if (!getAction(action) && col?.actions?.hasOwnProperty(action)) {
664
+ response = await rest.runAction(collection, action, body?.data || {});
662
665
  }
663
666
 
664
667
  if (action == "insertMany") {
@@ -2355,13 +2355,14 @@ class useRest {
2355
2355
  * @param data
2356
2356
  * @returns
2357
2357
  */
2358
- async customApi(collection: string, action: string, data: object) {
2358
+ async runAction(collection: string, actionName: string, data: any) {
2359
+ let action = actionName;
2359
2360
  return new Promise(async (resolve, reject) => {
2360
2361
  try {
2361
2362
  let col = getCollection(collection, this.#tenant_id);
2362
2363
  if (!col) return fn.error(`Collection ${collection} not found`, 404);
2363
2364
  if (col?.customApi?.[action]) {
2364
- let result = await col?.customApi?.[action]({
2365
+ let result = await col?.actions?.[action]({
2365
2366
  error: fn.error,
2366
2367
  io: Cfg.io,
2367
2368
  session: sessionStorage(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.75.0",
3
+ "version": "0.75.5",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {},
package/types/index.ts CHANGED
@@ -322,6 +322,9 @@ export type Collection = {
322
322
  operationType:"insert"|"update"|"delete";
323
323
  })=>Promise<any>;
324
324
  };
325
+ actions?:{
326
+ [key:string]:(ctx:ctxApi)=>any;
327
+ },
325
328
  customApi?: {
326
329
  [key:string]:(ctx:ctxApi)=>any;
327
330
  } & {