@bluemarble/bm-components 0.0.99 → 0.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 -8
- package/dist/index.d.ts +3 -8
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -4,7 +4,6 @@ import { TableCellProps, TextFieldProps, TableRowProps, StandardTextFieldProps,
|
|
|
4
4
|
import IMask$1 from 'imask';
|
|
5
5
|
import { NextApiRequest, NextApiResponse } from 'next';
|
|
6
6
|
import { ZodTypeDef, ZodSchema } from 'zod';
|
|
7
|
-
import { AxiosInstance } from 'axios';
|
|
8
7
|
|
|
9
8
|
interface ColumnTitleProps {
|
|
10
9
|
name: string;
|
|
@@ -264,7 +263,7 @@ declare class HttpError extends Error {
|
|
|
264
263
|
constructor(status: number, message: any);
|
|
265
264
|
}
|
|
266
265
|
|
|
267
|
-
declare type PossibleMethods =
|
|
266
|
+
declare type PossibleMethods = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
268
267
|
declare type HandlerProps = (req: NextApiRequest & {
|
|
269
268
|
user?: number;
|
|
270
269
|
}, res: NextApiResponse) => Promise<any>;
|
|
@@ -279,7 +278,7 @@ declare class ApiHelper {
|
|
|
279
278
|
private onFinally;
|
|
280
279
|
constructor(props?: ConstructorProps);
|
|
281
280
|
setMiddlewares(middlewares: any[]): this;
|
|
282
|
-
createMethods(methods: MethodProps): (req: NextApiRequest, res: NextApiResponse) => Promise<void
|
|
281
|
+
createMethods(methods: MethodProps): (req: NextApiRequest, res: NextApiResponse) => Promise<void | NextApiResponse<any>>;
|
|
283
282
|
static parserErrorWrapper<Output, Def extends ZodTypeDef, Input>(body: Record<string, any>, parser: ZodSchema<Output, Def, Input>): Output;
|
|
284
283
|
static parseQueyFilters<T extends Record<string, any>>(filters: T): T;
|
|
285
284
|
static create({ onFinally }: {
|
|
@@ -291,11 +290,7 @@ declare type Methods = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options';
|
|
|
291
290
|
declare type HandleProps = {
|
|
292
291
|
name: `${Methods}:${string}`;
|
|
293
292
|
};
|
|
294
|
-
declare
|
|
295
|
-
formatErrorMessage: (message: any) => string;
|
|
296
|
-
api: AxiosInstance;
|
|
297
|
-
};
|
|
298
|
-
declare function useFormHelper({ formatErrorMessage, api }: UseFormHelperProps): {
|
|
293
|
+
declare function useFormHelper(): {
|
|
299
294
|
onSubmitWrapper: <T extends Record<string, any>>(fn: (fields: T, methods: any) => Promise<void>, { name }: HandleProps) => (fields: T, methods: any) => Promise<void>;
|
|
300
295
|
onRequestWrapper: <F extends (...args: Parameters<F>) => R, R>(fn: F, { name }: HandleProps) => (...params: Parameters<F>) => Promise<R>;
|
|
301
296
|
isLoading: (prop: string) => boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { TableCellProps, TextFieldProps, TableRowProps, StandardTextFieldProps,
|
|
|
4
4
|
import IMask$1 from 'imask';
|
|
5
5
|
import { NextApiRequest, NextApiResponse } from 'next';
|
|
6
6
|
import { ZodTypeDef, ZodSchema } from 'zod';
|
|
7
|
-
import { AxiosInstance } from 'axios';
|
|
8
7
|
|
|
9
8
|
interface ColumnTitleProps {
|
|
10
9
|
name: string;
|
|
@@ -264,7 +263,7 @@ declare class HttpError extends Error {
|
|
|
264
263
|
constructor(status: number, message: any);
|
|
265
264
|
}
|
|
266
265
|
|
|
267
|
-
declare type PossibleMethods =
|
|
266
|
+
declare type PossibleMethods = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
268
267
|
declare type HandlerProps = (req: NextApiRequest & {
|
|
269
268
|
user?: number;
|
|
270
269
|
}, res: NextApiResponse) => Promise<any>;
|
|
@@ -279,7 +278,7 @@ declare class ApiHelper {
|
|
|
279
278
|
private onFinally;
|
|
280
279
|
constructor(props?: ConstructorProps);
|
|
281
280
|
setMiddlewares(middlewares: any[]): this;
|
|
282
|
-
createMethods(methods: MethodProps): (req: NextApiRequest, res: NextApiResponse) => Promise<void
|
|
281
|
+
createMethods(methods: MethodProps): (req: NextApiRequest, res: NextApiResponse) => Promise<void | NextApiResponse<any>>;
|
|
283
282
|
static parserErrorWrapper<Output, Def extends ZodTypeDef, Input>(body: Record<string, any>, parser: ZodSchema<Output, Def, Input>): Output;
|
|
284
283
|
static parseQueyFilters<T extends Record<string, any>>(filters: T): T;
|
|
285
284
|
static create({ onFinally }: {
|
|
@@ -291,11 +290,7 @@ declare type Methods = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options';
|
|
|
291
290
|
declare type HandleProps = {
|
|
292
291
|
name: `${Methods}:${string}`;
|
|
293
292
|
};
|
|
294
|
-
declare
|
|
295
|
-
formatErrorMessage: (message: any) => string;
|
|
296
|
-
api: AxiosInstance;
|
|
297
|
-
};
|
|
298
|
-
declare function useFormHelper({ formatErrorMessage, api }: UseFormHelperProps): {
|
|
293
|
+
declare function useFormHelper(): {
|
|
299
294
|
onSubmitWrapper: <T extends Record<string, any>>(fn: (fields: T, methods: any) => Promise<void>, { name }: HandleProps) => (fields: T, methods: any) => Promise<void>;
|
|
300
295
|
onRequestWrapper: <F extends (...args: Parameters<F>) => R, R>(fn: F, { name }: HandleProps) => (...params: Parameters<F>) => Promise<R>;
|
|
301
296
|
isLoading: (prop: string) => boolean;
|
package/dist/index.js
CHANGED
|
@@ -3937,6 +3937,8 @@ var ApiHelper = class _ApiHelper {
|
|
|
3937
3937
|
createMethods(methods) {
|
|
3938
3938
|
return (req, res) => __async(this, null, function* () {
|
|
3939
3939
|
const currentMethod = methods[req.method];
|
|
3940
|
+
if (req.method === "OPTIONS")
|
|
3941
|
+
return res.status(200).end();
|
|
3940
3942
|
try {
|
|
3941
3943
|
if (!currentMethod)
|
|
3942
3944
|
throw new HttpError(405, "M\xE9todo inv\xE1lido");
|
|
@@ -4076,10 +4078,16 @@ function useLoading() {
|
|
|
4076
4078
|
return { isLoading, setLoading };
|
|
4077
4079
|
}
|
|
4078
4080
|
|
|
4081
|
+
// src/contexts/FormHelperProvider.tsx
|
|
4082
|
+
|
|
4083
|
+
|
|
4084
|
+
var FormHelperContext = _react.createContext.call(void 0, {});
|
|
4085
|
+
|
|
4079
4086
|
// src/hooks/useFormHelper.ts
|
|
4080
|
-
function useFormHelper(
|
|
4087
|
+
function useFormHelper() {
|
|
4081
4088
|
const alertProps = useAlert();
|
|
4082
4089
|
const loadingProps = useLoading();
|
|
4090
|
+
const { api, formatErrorMessage } = _react.useContext.call(void 0, FormHelperContext);
|
|
4083
4091
|
const { createAlert } = alertProps;
|
|
4084
4092
|
const { setLoading } = loadingProps;
|
|
4085
4093
|
const sourceRef = _react.useRef.call(void 0, );
|