equipped 5.0.0-beta-2 → 5.0.0-beta-4
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/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [5.0.0-beta-4](https://github.com/kevinand11/equipped/compare/v5.0.0-beta-3...v5.0.0-beta-4) (2024-05-30)
|
|
6
|
+
|
|
7
|
+
## [5.0.0-beta-3](https://github.com/kevinand11/equipped/compare/v5.0.0-beta-2...v5.0.0-beta-3) (2024-05-30)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* allow custom validator in validate ([24a1d7a](https://github.com/kevinand11/equipped/commit/24a1d7a7cf69eabc73148dd9d36324d32ba95fc3))
|
|
13
|
+
|
|
5
14
|
## [5.0.0-beta-2](https://github.com/kevinand11/equipped/compare/v5.0.0-beta-1...v5.0.0-beta-2) (2024-05-30)
|
|
6
15
|
|
|
7
16
|
|
|
@@ -11,7 +11,7 @@ export declare class FastifyServer extends Server<FastifyRequest, FastifyReply>
|
|
|
11
11
|
protected onLoad(): Promise<void>;
|
|
12
12
|
protected registerRoute(route: FullRoute): void;
|
|
13
13
|
protected startServer(port: number): Promise<boolean>;
|
|
14
|
-
protected parse(req: FastifyRequest, res: FastifyReply): Promise<Request<import("../types").Api
|
|
14
|
+
protected parse(req: FastifyRequest, res: FastifyReply): Promise<Request<import("../types").Api<unknown, string, import("../types").MethodTypes, unknown, unknown, unknown, import("../types").SupportedStatusCodes>>>;
|
|
15
15
|
makeController(cb: Defined<Route['handler']>): RouteHandlerMethod;
|
|
16
16
|
makeMiddleware(cb: Defined<Route['middlewares']>[number]['cb']): preHandlerHookHandler<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").RouteGenericInterface, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, import("fastify").FastifyBaseLogger>;
|
|
17
17
|
makeErrorMiddleware(cb: Defined<Route['onError']>['cb']): (error: import("fastify").FastifyError, request: FastifyRequest<import("fastify").RouteGenericInterface, import("fastify").RawServerDefault, import("http").IncomingMessage, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown, import("fastify").FastifyBaseLogger, import("fastify/types/type-provider").ResolveFastifyRequestType<import("fastify").FastifyTypeProviderDefault, import("fastify").FastifySchema, import("fastify").RouteGenericInterface>>, reply: FastifyReply<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").RouteGenericInterface, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown>) => void;
|
package/lib/server/routes.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ export declare class Router extends ClassPropertiesWrapper<AddMethodImpls> {
|
|
|
5
5
|
#private;
|
|
6
6
|
constructor(config?: GeneralConfig);
|
|
7
7
|
include(router: Router): void;
|
|
8
|
-
get routes(): Route[];
|
|
8
|
+
get routes(): Route<import("./types").ApiDef<import("./types").Api<unknown, string, import("./types").MethodTypes, unknown, unknown, unknown, import("./types").SupportedStatusCodes>>>[];
|
|
9
9
|
}
|
package/lib/server/types.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ type ApiResponse<T, StatusCode extends SupportedStatusCodes> = Record<StatusCode
|
|
|
28
28
|
type Any = object | unknown;
|
|
29
29
|
type Arrayable<T> = T | T[];
|
|
30
30
|
type AllowedResponses = Arrayable<JSONPrimitives | Any>;
|
|
31
|
-
export
|
|
31
|
+
export interface Api<Res = AllowedResponses, Key extends string = string, Method extends MethodTypes = MethodTypes, Body extends Any = Any, Params extends Any = Any, Query extends Any = Any, DefaultStatus extends SupportedStatusCodes = SupportedStatusCodes> {
|
|
32
32
|
key: Key;
|
|
33
33
|
method: Method;
|
|
34
34
|
response: Res;
|
|
@@ -36,8 +36,8 @@ export type Api<Res = AllowedResponses, Key extends string = string, Method exte
|
|
|
36
36
|
params?: Params;
|
|
37
37
|
query?: Query;
|
|
38
38
|
defaultStatusCode?: DefaultStatus;
|
|
39
|
-
}
|
|
40
|
-
export
|
|
39
|
+
}
|
|
40
|
+
export interface ApiDef<T extends Api = Api> {
|
|
41
41
|
key: T['key'];
|
|
42
42
|
method: T['method'];
|
|
43
43
|
body: T['body'];
|
|
@@ -45,7 +45,7 @@ export type ApiDef<T extends Api = Api> = {
|
|
|
45
45
|
query: T['query'];
|
|
46
46
|
responses: ApiResponse<T['response'], GetDefaultStatusCode<T['defaultStatusCode']>>;
|
|
47
47
|
__api?: T;
|
|
48
|
-
}
|
|
48
|
+
}
|
|
49
49
|
type Awaitable<T> = Promise<T> | T;
|
|
50
50
|
type Res<T, S extends SupportedStatusCodes> = Awaitable<Response<T, S> | T>;
|
|
51
51
|
type InferApiFromApiDef<T> = T extends ApiDef<infer A> ? A : never;
|
|
@@ -55,7 +55,7 @@ export type ErrorHandler<Def extends Api = Api> = (req: Request<Def>, err: Error
|
|
|
55
55
|
export type RouteMiddlewareHandler<Def extends Api = Api> = (req: Request<Def>) => Awaitable<void>;
|
|
56
56
|
export type HandlerSetup = (route: Route) => void;
|
|
57
57
|
export type RouteSchema = Omit<FastifySchema, 'tags' | 'security' | 'hide'>;
|
|
58
|
-
export
|
|
58
|
+
export interface Route<Def extends ApiDef = ApiDef> {
|
|
59
59
|
key?: Def['key'];
|
|
60
60
|
path: string;
|
|
61
61
|
method: Def['method'];
|
|
@@ -68,7 +68,7 @@ export type Route<Def extends ApiDef = ApiDef> = {
|
|
|
68
68
|
hideSchema?: boolean;
|
|
69
69
|
security?: Record<string, string[]>[];
|
|
70
70
|
__def?: Def;
|
|
71
|
-
}
|
|
71
|
+
}
|
|
72
72
|
export type RouteConfig<T extends ApiDef = ApiDef> = Omit<Route<T>, 'method' | 'handler'>;
|
|
73
73
|
export type GeneralConfig = Omit<RouteConfig, 'schema' | 'key'>;
|
|
74
74
|
export type AddMethodImpls = {
|
|
@@ -154,7 +154,7 @@ export declare const Validation: {
|
|
|
154
154
|
ignored: boolean;
|
|
155
155
|
};
|
|
156
156
|
};
|
|
157
|
-
export declare const validate: <T extends Record<string, Validate.VCore<any
|
|
157
|
+
export declare const validate: <T extends Record<string, Validate.VCore<any>>, S extends Validate.VCore<any> = Validate.VCore<any>>(schema: T | S, value: unknown) => any;
|
|
158
158
|
export declare const Hash: {
|
|
159
159
|
hash: (password: string) => Promise<string>;
|
|
160
160
|
compare: (plainPassword: string, hashed: string) => Promise<boolean>;
|
package/lib/validations/index.js
CHANGED
|
@@ -48,7 +48,8 @@ Validate.v.file = (...args) => file(...args).addRule(isNotTruncated());
|
|
|
48
48
|
exports.Schema = Validate.v;
|
|
49
49
|
exports.Validation = { ...Validate, isNotTruncated, isValidPhone };
|
|
50
50
|
const validate = (schema, value) => {
|
|
51
|
-
const
|
|
51
|
+
const validator = schema instanceof Validate.VCore ? schema : Validate.v.object(schema);
|
|
52
|
+
const validity = validator.parse(value);
|
|
52
53
|
if (validity.valid)
|
|
53
54
|
return validity.value;
|
|
54
55
|
const errorsObject = validity.errors
|