@dnax/core 0.21.0 → 0.21.2

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
@@ -534,6 +534,10 @@ function HonoInstance(): typeof app {
534
534
  c.status(err.code || 500);
535
535
  return c.json({
536
536
  message: err?.message || err,
537
+ code: err?.code || 500,
538
+ timestamp: new Date().toISOString(),
539
+ success: false,
540
+ meta: err?.code || {},
537
541
  });
538
542
  }
539
543
  });
@@ -204,6 +204,7 @@ class useRest {
204
204
  if (col?.hooks?.beforeOperation && useHook) {
205
205
  await col.hooks.beforeOperation({
206
206
  io: Cfg.io,
207
+ error: fn.error,
207
208
  sharedData: sharedData,
208
209
  pipeline: pipeline,
209
210
  c: this.#c,
@@ -278,6 +279,7 @@ class useRest {
278
279
  await col.hooks.beforeOperation({
279
280
  sharedData: sharedData,
280
281
  io: Cfg.io,
282
+ error: fn.error,
281
283
  data: data,
282
284
  c: this.#c,
283
285
  driver: "mongodb",
@@ -399,6 +401,7 @@ class useRest {
399
401
  if (col?.hooks?.beforeOperation && useHook) {
400
402
  await col.hooks.beforeOperation({
401
403
  sharedData: sharedData,
404
+ error: fn.error,
402
405
  data: toJson(data),
403
406
  io: Cfg.io,
404
407
  c: this.#c,
@@ -575,6 +578,7 @@ class useRest {
575
578
  await col.hooks.beforeOperation({
576
579
  sharedData: sharedData,
577
580
  c: this.#c,
581
+ error: fn.error,
578
582
  driver: "mongodb",
579
583
  io: Cfg.io,
580
584
  action: "find",
@@ -701,6 +705,7 @@ class useRest {
701
705
  await col.hooks.beforeOperation({
702
706
  sharedData: sharedData,
703
707
  c: this.#c,
708
+ error: fn.error,
704
709
  driver: "mongodb",
705
710
  io: Cfg.io,
706
711
  action: "find",
@@ -811,6 +816,7 @@ class useRest {
811
816
  sharedData: sharedData,
812
817
  id: id,
813
818
  io: Cfg.io,
819
+ error: fn.error,
814
820
  c: this.#c,
815
821
  driver: "mongodb",
816
822
  action: "findOne",
@@ -926,6 +932,7 @@ class useRest {
926
932
  sharedData: sharedData,
927
933
  id: id,
928
934
  io: Cfg.io,
935
+ error: fn.error,
929
936
  c: this.#c,
930
937
  driver: "mongodb",
931
938
  action: "updateOne",
@@ -1083,6 +1090,7 @@ class useRest {
1083
1090
  sharedData: sharedData,
1084
1091
  filter: filter || {},
1085
1092
  c: this.#c,
1093
+ error: fn.error,
1086
1094
  io: Cfg.io,
1087
1095
  driver: "mongodb",
1088
1096
  action: "findOneAndUpdate",
@@ -1202,6 +1210,7 @@ class useRest {
1202
1210
  sharedData: sharedData,
1203
1211
  ids: ids,
1204
1212
  c: this.#c,
1213
+ error: fn.error,
1205
1214
  driver: "mongodb",
1206
1215
  io: Cfg.io,
1207
1216
  action: "updateMany",
@@ -1367,6 +1376,8 @@ class useRest {
1367
1376
  c: this.#c,
1368
1377
  io: Cfg.io,
1369
1378
  driver: "mongodb",
1379
+ error: fn.error,
1380
+
1370
1381
  action: "deleteOne",
1371
1382
  session: sessionStorage(),
1372
1383
  rest: new useRest({
@@ -1468,6 +1479,7 @@ class useRest {
1468
1479
  ids: ids,
1469
1480
  c: this.#c,
1470
1481
  driver: "mongodb",
1482
+ error: fn.error,
1471
1483
  io: Cfg.io,
1472
1484
  action: "deleteMany",
1473
1485
  session: sessionStorage(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.21.0",
3
+ "version": "0.21.2",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1 @@
1
+ import { type } from "arktype";
package/types/index.ts CHANGED
@@ -203,6 +203,28 @@ export type hooksCtx = (ctx: {
203
203
  rest: InstanceType<typeof useRest>;
204
204
  session?: sessionCtx;
205
205
  io: socketIoType;
206
+ error: typeof fn.error;
207
+ }) => any;
208
+
209
+ export type beforeOperationCtx = (ctx: {
210
+ filter?: any;
211
+ result?: any | null | object | undefined;
212
+ driver?: "mongodb" | "postgres";
213
+ data?: object;
214
+ params?: findParam;
215
+ options?: {};
216
+ count?: number;
217
+ id?: string;
218
+ ids?: string[];
219
+ update?: updateParams;
220
+ pipeline?: Array<object>;
221
+ sharedData?: any;
222
+ action?: Actions;
223
+ c?: Context;
224
+ rest: InstanceType<typeof useRest>;
225
+ session?: sessionCtx;
226
+ io: socketIoType;
227
+ error: typeof fn.error;
206
228
  }) => any;
207
229
 
208
230
  export type ctxApi = {
package/utils/index.ts CHANGED
@@ -336,16 +336,21 @@ function getEntryBykeys(obj: object = {}, keys: string[] = []) {
336
336
  return resultat;
337
337
  }
338
338
 
339
- class contextError extends Error {
340
- constructor(message: string, code: number) {
339
+ class ContextError extends Error {
340
+ code: number;
341
+ meta: any;
342
+
343
+ constructor(message: string, code: number, meta?: object) {
341
344
  super(message);
342
345
  this.code = code;
346
+ this.meta = meta;
347
+ Object.setPrototypeOf(this, ContextError.prototype);
343
348
  }
344
349
  }
345
350
 
346
351
  const fn = {
347
352
  error: (message: string, code: number) => {
348
- throw new contextError(message || "unknow", code);
353
+ throw new ContextError(message || "", code);
349
354
  },
350
355
  };
351
356