equipped 5.0.0-alpha.7 → 5.0.0-alpha.8
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 +7 -0
- package/lib/scripts/json-schema.d.ts +2 -1
- package/lib/scripts/json-schema.js +4 -3
- package/lib/server/impls/fastify.d.ts +1 -1
- package/lib/server/middlewares/errorHandler.d.ts +1 -1
- package/lib/server/middlewares/notFoundHandler.d.ts +1 -1
- package/lib/server/middlewares/parseAuthUser.d.ts +1 -1
- package/lib/server/middlewares/requireAuthUser.d.ts +1 -1
- package/lib/server/middlewares/requireRefreshUser.d.ts +1 -1
- package/lib/server/routes.d.ts +1 -1
- package/lib/server/types.d.ts +8 -5
- package/lib/types/index.d.ts +2 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
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-alpha.8](https://github.com/kevinand11/equipped/compare/v5.0.0-alpha.7...v5.0.0-alpha.8) (2024-06-27)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* apiDef key for api definition ([29608b9](https://github.com/kevinand11/equipped/commit/29608b98ff9c1e6eab1061fdc03deb95fed4b023))
|
|
11
|
+
|
|
5
12
|
## [5.0.0-alpha.7](https://github.com/kevinand11/equipped/compare/v5.0.0-alpha.6...v5.0.0-alpha.7) (2024-06-27)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Options } from 'ts-oas';
|
|
2
|
+
import type { CompilerOptions } from 'typescript';
|
|
2
3
|
import { RouteSchema } from '../server';
|
|
3
4
|
export declare function generateJSONSchema(patterns: (string | RegExp)[], paths: string[], options?: {
|
|
4
|
-
|
|
5
|
+
tsConfig?: string | CompilerOptions;
|
|
5
6
|
options?: Options;
|
|
6
7
|
}): Record<string, RouteSchema>;
|
|
@@ -30,7 +30,7 @@ const server_1 = require("../server");
|
|
|
30
30
|
const fileSchema = { type: 'string', format: 'binary' };
|
|
31
31
|
const statusCodes = Object.entries(server_1.StatusCodes);
|
|
32
32
|
function generateJSONSchema(patterns, paths, options) {
|
|
33
|
-
const tsProgram = (0, ts_oas_1.createProgram)(paths, options?.
|
|
33
|
+
const tsProgram = (0, ts_oas_1.createProgram)(paths, options?.tsConfig);
|
|
34
34
|
const logger = instance_1.Instance.createLogger();
|
|
35
35
|
const tsoas = new ts_oas_1.default(tsProgram, {
|
|
36
36
|
ref: false,
|
|
@@ -42,7 +42,8 @@ function generateJSONSchema(patterns, paths, options) {
|
|
|
42
42
|
.map(([name, { properties: def }]) => {
|
|
43
43
|
try {
|
|
44
44
|
const key = def?.key?.enum?.at(0) ?? name;
|
|
45
|
-
|
|
45
|
+
const isApiDef = def?.__apiDef?.type === 'boolean' && def?.__apiDef?.enum?.[0] === true;
|
|
46
|
+
if (!def || !isApiDef || !key || !def.method)
|
|
46
47
|
return [undefined, undefined];
|
|
47
48
|
const response = def.responses.properties ?? def.responses.anyOf?.reduce((acc, cur) => {
|
|
48
49
|
if (cur.properties)
|
|
@@ -79,7 +80,7 @@ function generateJSONSchema(patterns, paths, options) {
|
|
|
79
80
|
body,
|
|
80
81
|
params: def.params,
|
|
81
82
|
querystring: def.query,
|
|
82
|
-
headers: def.
|
|
83
|
+
headers: def.requestHeaders,
|
|
83
84
|
response,
|
|
84
85
|
operationId: key,
|
|
85
86
|
summary: name,
|
|
@@ -9,7 +9,7 @@ export declare class FastifyServer extends Server<FastifyRequest, FastifyReply>
|
|
|
9
9
|
protected onLoad(): Promise<void>;
|
|
10
10
|
protected registerRoute(route: FullRoute): void;
|
|
11
11
|
protected startServer(port: number): Promise<boolean>;
|
|
12
|
-
protected parse(req: FastifyRequest, res: FastifyReply): Promise<Request<import("../types").Api<any, string, import("../types").MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, Record<string, string | string[]>, import("../types").SupportedStatusCodes>>>;
|
|
12
|
+
protected parse(req: FastifyRequest, res: FastifyReply): Promise<Request<import("../types").Api<any, string, import("../types").MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, Record<string, string | string[]>, Record<string, string | string[]>, import("../types").SupportedStatusCodes>>>;
|
|
13
13
|
makeController(cb: Defined<Route['handler']>): RouteHandlerMethod;
|
|
14
14
|
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>;
|
|
15
15
|
makeErrorMiddleware(cb: Defined<Route['onError']>['cb']): (error: import("fastify").FastifyError, request: FastifyRequest, reply: FastifyReply) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const errorHandler: {
|
|
2
|
-
cb: import("../types").ErrorHandler<import("../types").Api<any, string, import("../types").MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, Record<string, string | string[]>, import("../types").SupportedStatusCodes>>;
|
|
2
|
+
cb: import("../types").ErrorHandler<import("../types").Api<any, string, import("../types").MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, Record<string, string | string[]>, Record<string, string | string[]>, import("../types").SupportedStatusCodes>>;
|
|
3
3
|
onSetup?: import("../types").HandlerSetup;
|
|
4
4
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const notFoundHandler: {
|
|
2
|
-
cb: import("../types").RouteMiddlewareHandler<import("../types").Api<any, string, import("../types").MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, Record<string, string | string[]>, import("../types").SupportedStatusCodes>>;
|
|
2
|
+
cb: import("../types").RouteMiddlewareHandler<import("../types").Api<any, string, import("../types").MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, Record<string, string | string[]>, Record<string, string | string[]>, import("../types").SupportedStatusCodes>>;
|
|
3
3
|
onSetup?: import("../types").HandlerSetup;
|
|
4
4
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const parseAuthUser: {
|
|
2
|
-
cb: import("../types").RouteMiddlewareHandler<import("../types").Api<any, string, import("../types").MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, Record<string, string | string[]>, import("../types").SupportedStatusCodes>>;
|
|
2
|
+
cb: import("../types").RouteMiddlewareHandler<import("../types").Api<any, string, import("../types").MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, Record<string, string | string[]>, Record<string, string | string[]>, import("../types").SupportedStatusCodes>>;
|
|
3
3
|
onSetup?: import("../types").HandlerSetup;
|
|
4
4
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const requireAuthUser: {
|
|
2
|
-
cb: import("../types").RouteMiddlewareHandler<import("../types").Api<any, string, import("../types").MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, Record<string, string | string[]>, import("../types").SupportedStatusCodes>>;
|
|
2
|
+
cb: import("../types").RouteMiddlewareHandler<import("../types").Api<any, string, import("../types").MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, Record<string, string | string[]>, Record<string, string | string[]>, import("../types").SupportedStatusCodes>>;
|
|
3
3
|
onSetup?: import("../types").HandlerSetup;
|
|
4
4
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const requireRefreshUser: {
|
|
2
|
-
cb: import("../types").RouteMiddlewareHandler<import("../types").Api<any, string, import("../types").MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, Record<string, string | string[]>, import("../types").SupportedStatusCodes>>;
|
|
2
|
+
cb: import("../types").RouteMiddlewareHandler<import("../types").Api<any, string, import("../types").MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, Record<string, string | string[]>, Record<string, string | string[]>, import("../types").SupportedStatusCodes>>;
|
|
3
3
|
onSetup?: import("../types").HandlerSetup;
|
|
4
4
|
};
|
package/lib/server/routes.d.ts
CHANGED
|
@@ -7,5 +7,5 @@ export declare class Router extends ClassPropertiesWrapper<AddMethodImpls> {
|
|
|
7
7
|
constructor(config?: GeneralConfig);
|
|
8
8
|
add(...routes: Route[]): void;
|
|
9
9
|
nest(...routers: Router[]): void;
|
|
10
|
-
get routes(): Route<import("./types").ApiDef<import("./types").Api<any, string, import("./types").MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, Record<string, string | string[]>, import("./types").SupportedStatusCodes>>>[];
|
|
10
|
+
get routes(): Route<import("./types").ApiDef<import("./types").Api<any, string, import("./types").MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, Record<string, string | string[]>, Record<string, string | string[]>, import("./types").SupportedStatusCodes>>>[];
|
|
11
11
|
}
|
package/lib/server/types.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type SupportedStatusCodes = Enum<typeof StatusCodes>;
|
|
|
25
25
|
type GoodStatusCodes = 200;
|
|
26
26
|
type ApiErrors = Record<Exclude<SupportedStatusCodes, GoodStatusCodes>, JSONValue<CustomError['serializedErrors']>>;
|
|
27
27
|
type ApiResponse<T, StatusCode extends SupportedStatusCodes> = Record<StatusCode, JSONValue<T>> | Omit<ApiErrors, StatusCode>;
|
|
28
|
-
export interface Api<Res = any, Key extends string = string, Method extends MethodTypes = MethodTypes, Body = any, Files extends Record<string, boolean> = Record<string, boolean>, Params extends Record<string, string> = Record<string, string>, Query extends Record<string, any> = Record<string, any>,
|
|
28
|
+
export interface Api<Res = any, Key extends string = string, Method extends MethodTypes = MethodTypes, Body = any, Files extends Record<string, boolean> = Record<string, boolean>, Params extends Record<string, string> = Record<string, string>, Query extends Record<string, any> = Record<string, any>, RequestHeaders extends Record<string, string | string[]> = Record<string, string | string[]>, ResponeHeaders extends Record<string, string | string[]> = Record<string, string | string[]>, DefaultStatus extends SupportedStatusCodes = SupportedStatusCodes> {
|
|
29
29
|
key: Key;
|
|
30
30
|
method: Method;
|
|
31
31
|
response: Res;
|
|
@@ -33,7 +33,8 @@ export interface Api<Res = any, Key extends string = string, Method extends Meth
|
|
|
33
33
|
files?: Files;
|
|
34
34
|
params?: Params;
|
|
35
35
|
query?: Query;
|
|
36
|
-
|
|
36
|
+
requestHeaders?: RequestHeaders;
|
|
37
|
+
responseHeaders?: ResponeHeaders;
|
|
37
38
|
defaultStatusCode?: DefaultStatus;
|
|
38
39
|
}
|
|
39
40
|
export interface ApiDef<T extends Api> {
|
|
@@ -43,8 +44,10 @@ export interface ApiDef<T extends Api> {
|
|
|
43
44
|
params: Defined<T['params']>;
|
|
44
45
|
query: Defined<T['query']>;
|
|
45
46
|
files: Defined<T['files']>;
|
|
46
|
-
|
|
47
|
+
requestHeaders: Defined<T['requestHeaders']>;
|
|
48
|
+
responseHeaders: Defined<T['responseHeaders']>;
|
|
47
49
|
responses: ApiResponse<T['response'], GetDefaultStatusCode<T['defaultStatusCode']>>;
|
|
50
|
+
__apiDef: true;
|
|
48
51
|
}
|
|
49
52
|
type AnyApi<Method extends MethodTypes = MethodTypes> = Api<any, any, Method, any, any, any, any, any, any>;
|
|
50
53
|
type Awaitable<T> = Promise<T> | T;
|
|
@@ -88,6 +91,6 @@ declare class MiddlewareHandler<Cb extends Function> {
|
|
|
88
91
|
private constructor();
|
|
89
92
|
static make<Cb extends Function>(cb: Cb, onSetup?: HandlerSetup): MiddlewareHandler<Cb>;
|
|
90
93
|
}
|
|
91
|
-
export declare const makeMiddleware: <Def extends Api = Api<any, string, MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, Record<string, string | string[]>, SupportedStatusCodes>>(cb: RouteMiddlewareHandler<Def>, onSetup?: HandlerSetup | undefined) => MiddlewareHandler<RouteMiddlewareHandler<Def>>;
|
|
92
|
-
export declare const makeErrorMiddleware: <Def extends Api = Api<any, string, MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, Record<string, string | string[]>, SupportedStatusCodes>>(cb: ErrorHandler<Def>, onSetup?: HandlerSetup | undefined) => MiddlewareHandler<ErrorHandler<Def>>;
|
|
94
|
+
export declare const makeMiddleware: <Def extends Api = Api<any, string, MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, Record<string, string | string[]>, Record<string, string | string[]>, SupportedStatusCodes>>(cb: RouteMiddlewareHandler<Def>, onSetup?: HandlerSetup | undefined) => MiddlewareHandler<RouteMiddlewareHandler<Def>>;
|
|
95
|
+
export declare const makeErrorMiddleware: <Def extends Api = Api<any, string, MethodTypes, any, Record<string, boolean>, Record<string, string>, Record<string, any>, Record<string, string | string[]>, Record<string, string | string[]>, SupportedStatusCodes>>(cb: ErrorHandler<Def>, onSetup?: HandlerSetup | undefined) => MiddlewareHandler<ErrorHandler<Def>>;
|
|
93
96
|
export {};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -15,6 +15,6 @@ export type Paths<T, D = never> = T extends StopTypes ? '' : T extends readonly
|
|
|
15
15
|
}[keyof T & string];
|
|
16
16
|
export type JSONPrimitives = string | number | boolean | null;
|
|
17
17
|
export type JSONValue<T> = T extends JSONPrimitives ? T : T extends Array<infer U> ? JSONValue<U>[] : T extends BaseEntity<infer _M, infer I> ? JSONValue<DeepOmit<T, I, '__ignoreInJSON'>> : T extends Function ? never : T extends object ? {
|
|
18
|
-
[K in keyof T
|
|
19
|
-
} :
|
|
18
|
+
[K in keyof T as JSONValue<T[K]> extends never ? never : JSONValue<T[K]> extends undefined ? never : K]: JSONValue<T[K]>;
|
|
19
|
+
} : never;
|
|
20
20
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "equipped",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.8",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"redis": "^4.6.14",
|
|
81
81
|
"socket.io": "4.7.5",
|
|
82
82
|
"supertest": "^7.0.0",
|
|
83
|
-
"ts-oas": "^0.4.
|
|
83
|
+
"ts-oas": "^0.4.4",
|
|
84
84
|
"valleyed": "4.3.0"
|
|
85
85
|
},
|
|
86
86
|
"repository": {
|