@bluemarble/bm-components 0.2.3 → 1.1.0
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/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +16 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -267,11 +267,13 @@ type MethodProps<T> = Partial<Record<PossibleMethods, HandlerProps<T>>>;
|
|
|
267
267
|
type MiddlewaresProps<T> = ((handler: HandlerProps<T>) => HandlerProps<T>)[];
|
|
268
268
|
type ConstructorProps<T> = {
|
|
269
269
|
middlewares?: MiddlewaresProps<T>;
|
|
270
|
-
onFinally: (req: NextApiRequest) => Promise<void>;
|
|
270
|
+
onFinally: (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
271
|
+
onError?: (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
271
272
|
};
|
|
272
273
|
declare class ApiHelper<T> {
|
|
273
274
|
middlewares: MiddlewaresProps<T>;
|
|
274
275
|
private onFinally;
|
|
276
|
+
private onError;
|
|
275
277
|
constructor(props?: ConstructorProps<T>);
|
|
276
278
|
setMiddlewares(middlewares: any[]): this;
|
|
277
279
|
createMethods(methods: MethodProps<T>): (req: NextApiRequest, res: NextApiResponse) => Promise<void | NextApiResponse<any>>;
|
package/dist/index.d.ts
CHANGED
|
@@ -267,11 +267,13 @@ type MethodProps<T> = Partial<Record<PossibleMethods, HandlerProps<T>>>;
|
|
|
267
267
|
type MiddlewaresProps<T> = ((handler: HandlerProps<T>) => HandlerProps<T>)[];
|
|
268
268
|
type ConstructorProps<T> = {
|
|
269
269
|
middlewares?: MiddlewaresProps<T>;
|
|
270
|
-
onFinally: (req: NextApiRequest) => Promise<void>;
|
|
270
|
+
onFinally: (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
271
|
+
onError?: (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
271
272
|
};
|
|
272
273
|
declare class ApiHelper<T> {
|
|
273
274
|
middlewares: MiddlewaresProps<T>;
|
|
274
275
|
private onFinally;
|
|
276
|
+
private onError;
|
|
275
277
|
constructor(props?: ConstructorProps<T>);
|
|
276
278
|
setMiddlewares(middlewares: any[]): this;
|
|
277
279
|
createMethods(methods: MethodProps<T>): (req: NextApiRequest, res: NextApiResponse) => Promise<void | NextApiResponse<any>>;
|
package/dist/index.js
CHANGED
|
@@ -3969,13 +3969,20 @@ var HttpError = class extends Error {
|
|
|
3969
3969
|
|
|
3970
3970
|
// src/helpers/apiHelper/index.ts
|
|
3971
3971
|
var ApiHelper = class _ApiHelper {
|
|
3972
|
-
onFinally(req) {
|
|
3972
|
+
onFinally(req, res) {
|
|
3973
|
+
return __async(this, null, function* () {
|
|
3974
|
+
});
|
|
3975
|
+
}
|
|
3976
|
+
onError(req, res) {
|
|
3973
3977
|
return __async(this, null, function* () {
|
|
3974
3978
|
});
|
|
3975
3979
|
}
|
|
3976
3980
|
constructor(props) {
|
|
3977
|
-
this.middlewares = (props == null ? void 0 : props.middlewares
|
|
3978
|
-
this.onFinally = props.onFinally
|
|
3981
|
+
this.middlewares = ((props == null ? void 0 : props.middlewares) || []).reverse();
|
|
3982
|
+
this.onFinally = props.onFinally || (() => __async(this, null, function* () {
|
|
3983
|
+
}));
|
|
3984
|
+
this.onError = props.onError || (() => __async(this, null, function* () {
|
|
3985
|
+
}));
|
|
3979
3986
|
}
|
|
3980
3987
|
setMiddlewares(middlewares) {
|
|
3981
3988
|
this.middlewares = middlewares.reverse();
|
|
@@ -3997,15 +4004,18 @@ var ApiHelper = class _ApiHelper {
|
|
|
3997
4004
|
} catch (error) {
|
|
3998
4005
|
if (error instanceof HttpError)
|
|
3999
4006
|
return res.status(error.status).json(error.message);
|
|
4000
|
-
if (process.env.NODE_ENV === "production")
|
|
4001
|
-
|
|
4007
|
+
if (process.env.NODE_ENV === "production") {
|
|
4008
|
+
res.status(500).json({
|
|
4002
4009
|
code: "internal.error",
|
|
4003
4010
|
error: "Erro interno do servidor",
|
|
4004
4011
|
details: error
|
|
4005
4012
|
});
|
|
4013
|
+
return this.onError(req, res);
|
|
4014
|
+
}
|
|
4015
|
+
this.onError(req, res);
|
|
4006
4016
|
throw new Error(error);
|
|
4007
4017
|
} finally {
|
|
4008
|
-
yield this.onFinally(req);
|
|
4018
|
+
yield this.onFinally(req, res);
|
|
4009
4019
|
}
|
|
4010
4020
|
});
|
|
4011
4021
|
}
|