@bluemarble/bm-components 1.2.0 → 1.4.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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +17 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -6
package/dist/index.d.mts
CHANGED
|
@@ -259,7 +259,7 @@ declare class HttpError extends Error {
|
|
|
259
259
|
constructor(status: number, message: any);
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
type PossibleMethods = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
262
|
+
type PossibleMethods = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'ALL';
|
|
263
263
|
type HandlerProps<UserKeyType> = (req: NextApiRequest & {
|
|
264
264
|
user?: UserKeyType;
|
|
265
265
|
}, res: NextApiResponse) => Promise<any>;
|
|
@@ -267,7 +267,7 @@ 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
|
|
270
|
+
onFinally?: (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
271
271
|
onError?: (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
272
272
|
};
|
|
273
273
|
declare class ApiHelper<T> {
|
package/dist/index.d.ts
CHANGED
|
@@ -259,7 +259,7 @@ declare class HttpError extends Error {
|
|
|
259
259
|
constructor(status: number, message: any);
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
type PossibleMethods = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
262
|
+
type PossibleMethods = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'ALL';
|
|
263
263
|
type HandlerProps<UserKeyType> = (req: NextApiRequest & {
|
|
264
264
|
user?: UserKeyType;
|
|
265
265
|
}, res: NextApiResponse) => Promise<any>;
|
|
@@ -267,7 +267,7 @@ 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
|
|
270
|
+
onFinally?: (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
271
271
|
onError?: (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
272
272
|
};
|
|
273
273
|
declare class ApiHelper<T> {
|
package/dist/index.js
CHANGED
|
@@ -3972,6 +3972,17 @@ var HttpError = class extends Error {
|
|
|
3972
3972
|
};
|
|
3973
3973
|
|
|
3974
3974
|
// src/helpers/apiHelper/index.ts
|
|
3975
|
+
var VALID_METHODS = [
|
|
3976
|
+
"GET",
|
|
3977
|
+
"HEAD",
|
|
3978
|
+
"POST",
|
|
3979
|
+
"PUT",
|
|
3980
|
+
"DELETE",
|
|
3981
|
+
"CONNECT",
|
|
3982
|
+
"OPTIONS",
|
|
3983
|
+
"TRACE",
|
|
3984
|
+
"PATCH"
|
|
3985
|
+
];
|
|
3975
3986
|
var ApiHelper = class _ApiHelper {
|
|
3976
3987
|
onFinally(req, res) {
|
|
3977
3988
|
return __async(this, null, function* () {
|
|
@@ -3983,9 +3994,9 @@ var ApiHelper = class _ApiHelper {
|
|
|
3983
3994
|
}
|
|
3984
3995
|
constructor(props) {
|
|
3985
3996
|
this.middlewares = ((props == null ? void 0 : props.middlewares) || []).reverse();
|
|
3986
|
-
this.onFinally = props.onFinally || (() => __async(this, null, function* () {
|
|
3997
|
+
this.onFinally = (props == null ? void 0 : props.onFinally) || (() => __async(this, null, function* () {
|
|
3987
3998
|
}));
|
|
3988
|
-
this.onError = props.onError || (() => __async(this, null, function* () {
|
|
3999
|
+
this.onError = (props == null ? void 0 : props.onError) || (() => __async(this, null, function* () {
|
|
3989
4000
|
}));
|
|
3990
4001
|
}
|
|
3991
4002
|
setMiddlewares(middlewares) {
|
|
@@ -3994,12 +4005,14 @@ var ApiHelper = class _ApiHelper {
|
|
|
3994
4005
|
}
|
|
3995
4006
|
createMethods(methods) {
|
|
3996
4007
|
return (req, res) => __async(this, null, function* () {
|
|
3997
|
-
const currentMethod = methods[req.method];
|
|
4008
|
+
const currentMethod = methods[req.method] || methods.ALL;
|
|
3998
4009
|
if (req.method === "OPTIONS")
|
|
3999
4010
|
return res.status(200).end();
|
|
4000
4011
|
try {
|
|
4001
|
-
if (!
|
|
4012
|
+
if (!VALID_METHODS.includes(req.method))
|
|
4002
4013
|
throw new HttpError(405, "M\xE9todo inv\xE1lido");
|
|
4014
|
+
if (!currentMethod)
|
|
4015
|
+
throw new HttpError(500, "M\xE9todo n\xE3o encontrado");
|
|
4003
4016
|
const methodWithMiddlewares = this.middlewares.reduce(
|
|
4004
4017
|
(acc, fn) => fn(acc),
|
|
4005
4018
|
currentMethod
|