@dnax/core 0.21.1 → 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 +4 -0
- package/package.json +1 -1
- package/types/index.ts +21 -0
- package/utils/index.ts +8 -3
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
|
});
|
package/package.json
CHANGED
package/types/index.ts
CHANGED
|
@@ -206,6 +206,27 @@ export type hooksCtx = (ctx: {
|
|
|
206
206
|
error: typeof fn.error;
|
|
207
207
|
}) => any;
|
|
208
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;
|
|
228
|
+
}) => any;
|
|
229
|
+
|
|
209
230
|
export type ctxApi = {
|
|
210
231
|
rest: useRest;
|
|
211
232
|
data?: any;
|
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
|
|
340
|
-
|
|
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
|
|
353
|
+
throw new ContextError(message || "", code);
|
|
349
354
|
},
|
|
350
355
|
};
|
|
351
356
|
|