@bool-ts/core 1.6.13 → 1.7.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/.prettierrc +11 -11
- package/LICENSE +21 -21
- package/__test/controller.ts +93 -79
- package/__test/dispatcher.ts +16 -0
- package/__test/firstGuard.ts +10 -10
- package/__test/firstMiddleware.ts +15 -9
- package/__test/index.ts +8 -8
- package/__test/interfaces.ts +7 -7
- package/__test/module.ts +28 -30
- package/__test/repository.ts +16 -16
- package/__test/secondGuard.ts +10 -10
- package/__test/secondMiddleware.ts +15 -9
- package/__test/service.ts +20 -20
- package/bun.lockb +0 -0
- package/dist/decorators/arguments.d.ts +3 -3
- package/dist/decorators/arguments.js +3 -3
- package/dist/decorators/dispatcher.js +0 -3
- package/dist/decorators/index.d.ts +1 -1
- package/dist/decorators/index.js +1 -1
- package/dist/decorators/middleware.js +0 -3
- package/dist/decorators/module.d.ts +2 -4
- package/dist/decorators/module.js +5 -12
- package/dist/hooks/factory.d.ts +41 -2
- package/dist/hooks/factory.js +501 -406
- package/dist/hooks/injector.d.ts +14 -1
- package/dist/hooks/injector.js +3 -3
- package/dist/http/index.d.ts +1 -1
- package/dist/http/index.js +2 -1
- package/dist/interfaces/dispatcher.d.ts +3 -2
- package/dist/interfaces/middleware.d.ts +3 -2
- package/dist/keys/index.d.ts +2 -1
- package/dist/keys/index.js +2 -1
- package/jsconfig.json +27 -27
- package/package.json +3 -3
- package/src/decorators/arguments.ts +286 -286
- package/src/decorators/controller.ts +21 -21
- package/src/decorators/dispatcher.ts +14 -18
- package/src/decorators/guard.ts +18 -18
- package/src/decorators/http.ts +81 -81
- package/src/decorators/index.ts +29 -29
- package/src/decorators/inject.ts +13 -13
- package/src/decorators/injectable.ts +8 -8
- package/src/decorators/middleware.ts +14 -18
- package/src/decorators/module.ts +84 -94
- package/src/decorators/zodSchema.ts +19 -19
- package/src/entities/index.ts +5 -5
- package/src/entities/route.ts +327 -327
- package/src/entities/router.ts +35 -35
- package/src/entities/routerGroup.ts +34 -34
- package/src/hooks/factory.ts +990 -806
- package/src/hooks/index.ts +2 -2
- package/src/hooks/injector.ts +57 -57
- package/src/http/clientError.ts +45 -45
- package/src/http/index.ts +62 -61
- package/src/http/serverError.ts +27 -27
- package/src/index.ts +9 -9
- package/src/interfaces/context.ts +4 -4
- package/src/interfaces/controller.ts +1 -1
- package/src/interfaces/dispatcher.ts +4 -3
- package/src/interfaces/guard.ts +3 -3
- package/src/interfaces/index.ts +6 -6
- package/src/interfaces/middleware.ts +4 -3
- package/src/interfaces/module.ts +1 -1
- package/src/keys/index.ts +23 -22
- package/test.http +31 -31
- package/tsconfig.json +108 -108
- package/__test/afterDispatcher.ts +0 -9
- package/__test/beforeDispatcher.ts +0 -9
package/src/hooks/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { BoolFactory } from "./factory";
|
|
2
|
-
export { Injector } from "./injector";
|
|
1
|
+
export { BoolFactory } from "./factory";
|
|
2
|
+
export { Injector } from "./injector";
|
package/src/hooks/injector.ts
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
import { controllerKey, dispatcherKey, guardKey, injectableKey, injectKey, middlewareKey } from "../keys";
|
|
3
|
-
|
|
4
|
-
type TDefinition<T = any> = { new (...args: any[]): T } | string | symbol;
|
|
5
|
-
|
|
6
|
-
interface IInjector {
|
|
7
|
-
set(key: TDefinition, value: any): void;
|
|
8
|
-
get<T>(definition: TDefinition): T;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export
|
|
12
|
-
private readonly _mapper: Map<Function | string | symbol, any> = new Map();
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* @param constructor
|
|
17
|
-
*/
|
|
18
|
-
get<T>(definition: TDefinition) {
|
|
19
|
-
if (this._mapper.has(definition)) {
|
|
20
|
-
return this._mapper.get(definition) as T;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (typeof definition !== "function") {
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const ownMetadataKeys = Reflect.getMetadataKeys(definition);
|
|
28
|
-
|
|
29
|
-
if (
|
|
30
|
-
![injectableKey, controllerKey, middlewareKey, guardKey, dispatcherKey].some((value) =>
|
|
31
|
-
ownMetadataKeys.includes(value)
|
|
32
|
-
)
|
|
33
|
-
) {
|
|
34
|
-
throw Error("Missing dependency declaration, please check @Injectable() used on dependency(ies).");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Initialize dependencies injection
|
|
38
|
-
const dependencies: any[] = Reflect.getOwnMetadata(injectKey, definition) || [];
|
|
39
|
-
const injections: any[] = dependencies.map((dependency) =>
|
|
40
|
-
const instance = new definition(...injections);
|
|
41
|
-
|
|
42
|
-
this._mapper.set(definition, instance);
|
|
43
|
-
|
|
44
|
-
return instance;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
*
|
|
49
|
-
* @param key
|
|
50
|
-
* @param value
|
|
51
|
-
*/
|
|
52
|
-
set(key: TDefinition, value: any) {
|
|
53
|
-
this._mapper.set(key, value);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export default Injector;
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { controllerKey, dispatcherKey, guardKey, injectableKey, injectKey, middlewareKey } from "../keys";
|
|
3
|
+
|
|
4
|
+
type TDefinition<T = any> = { new (...args: any[]): T } | string | symbol;
|
|
5
|
+
|
|
6
|
+
interface IInjector {
|
|
7
|
+
set(key: TDefinition, value: any): void;
|
|
8
|
+
get<T>(definition: TDefinition): T;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class Injector implements IInjector {
|
|
12
|
+
private readonly _mapper: Map<Function | string | symbol, any> = new Map();
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param constructor
|
|
17
|
+
*/
|
|
18
|
+
get<T>(definition: TDefinition) {
|
|
19
|
+
if (this._mapper.has(definition)) {
|
|
20
|
+
return this._mapper.get(definition) as T;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (typeof definition !== "function") {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const ownMetadataKeys = Reflect.getMetadataKeys(definition);
|
|
28
|
+
|
|
29
|
+
if (
|
|
30
|
+
![injectableKey, controllerKey, middlewareKey, guardKey, dispatcherKey].some((value) =>
|
|
31
|
+
ownMetadataKeys.includes(value)
|
|
32
|
+
)
|
|
33
|
+
) {
|
|
34
|
+
throw Error("Missing dependency declaration, please check @Injectable() used on dependency(ies).");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Initialize dependencies injection
|
|
38
|
+
const dependencies: any[] = Reflect.getOwnMetadata(injectKey, definition) || [];
|
|
39
|
+
const injections: any[] = dependencies.map((dependency) => this.get(dependency));
|
|
40
|
+
const instance = new definition(...injections);
|
|
41
|
+
|
|
42
|
+
this._mapper.set(definition, instance);
|
|
43
|
+
|
|
44
|
+
return instance;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* @param key
|
|
50
|
+
* @param value
|
|
51
|
+
*/
|
|
52
|
+
set(key: TDefinition, value: any) {
|
|
53
|
+
this._mapper.set(key, value);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export default Injector;
|
package/src/http/clientError.ts
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
export const httpClientErrors = Object.freeze({
|
|
2
|
-
400: "BAD_REQUEST",
|
|
3
|
-
401: "UNAUTHORIZED",
|
|
4
|
-
402: "PAYMENT_REQUIRED",
|
|
5
|
-
403: "FORBIDDEN",
|
|
6
|
-
404: "NOT_FOUND",
|
|
7
|
-
405: "METHOD_NOT_ALLOWED",
|
|
8
|
-
406: "NOT_ACCEPTABLE",
|
|
9
|
-
407: "PROXY_AUTHENCATION_REQUIRED",
|
|
10
|
-
408: "REQUEST_TIMEOUT",
|
|
11
|
-
409: "CONFLICT",
|
|
12
|
-
410: "GONE",
|
|
13
|
-
411: "LENGTH_REQUIRED",
|
|
14
|
-
412: "PRECONDITION_FAILED",
|
|
15
|
-
413: "PAYLOAD_TOO_LARGE",
|
|
16
|
-
414: "URI_TOO_LONG",
|
|
17
|
-
415: "UNSUPPORTED_MEDIA_TYPE",
|
|
18
|
-
416: "RANGE_NOT_SATISFIABLE",
|
|
19
|
-
417: "EXPECTATION_FAILED",
|
|
20
|
-
418: "IM_A_TEAPOT",
|
|
21
|
-
421: "MISDIRECTED_REQUEST",
|
|
22
|
-
422: "UNPROCESSABLE_ENTITY",
|
|
23
|
-
423: "LOCKED",
|
|
24
|
-
424: "FAILED_DEPENDENCY",
|
|
25
|
-
425: "TOO_EARLY_",
|
|
26
|
-
426: "UPGRAGE_REQUIRED",
|
|
27
|
-
428: "PRECONDITION_REQUIRED",
|
|
28
|
-
429: "TOO_MANY_REQUESTS",
|
|
29
|
-
431: "REQUEST_HEADER_FIELDS_TOO_LARGE",
|
|
30
|
-
451: "UNAVAILABLE_FOR_LEGAL_REASONS"
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
export class HttpClientError<T extends keyof typeof httpClientErrors = keyof typeof httpClientErrors, K = any> extends Error {
|
|
34
|
-
public readonly httpCode: T;
|
|
35
|
-
public readonly message: (typeof httpClientErrors)[T] | string;
|
|
36
|
-
public readonly data: K;
|
|
37
|
-
|
|
38
|
-
constructor({ httpCode, data, message }: { httpCode: T; data: K; message?: string }) {
|
|
39
|
-
super();
|
|
40
|
-
|
|
41
|
-
this.httpCode = httpCode;
|
|
42
|
-
this.message = !message?.trim() ? httpClientErrors[httpCode] : message.trim();
|
|
43
|
-
this.data = data;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
1
|
+
export const httpClientErrors = Object.freeze({
|
|
2
|
+
400: "BAD_REQUEST",
|
|
3
|
+
401: "UNAUTHORIZED",
|
|
4
|
+
402: "PAYMENT_REQUIRED",
|
|
5
|
+
403: "FORBIDDEN",
|
|
6
|
+
404: "NOT_FOUND",
|
|
7
|
+
405: "METHOD_NOT_ALLOWED",
|
|
8
|
+
406: "NOT_ACCEPTABLE",
|
|
9
|
+
407: "PROXY_AUTHENCATION_REQUIRED",
|
|
10
|
+
408: "REQUEST_TIMEOUT",
|
|
11
|
+
409: "CONFLICT",
|
|
12
|
+
410: "GONE",
|
|
13
|
+
411: "LENGTH_REQUIRED",
|
|
14
|
+
412: "PRECONDITION_FAILED",
|
|
15
|
+
413: "PAYLOAD_TOO_LARGE",
|
|
16
|
+
414: "URI_TOO_LONG",
|
|
17
|
+
415: "UNSUPPORTED_MEDIA_TYPE",
|
|
18
|
+
416: "RANGE_NOT_SATISFIABLE",
|
|
19
|
+
417: "EXPECTATION_FAILED",
|
|
20
|
+
418: "IM_A_TEAPOT",
|
|
21
|
+
421: "MISDIRECTED_REQUEST",
|
|
22
|
+
422: "UNPROCESSABLE_ENTITY",
|
|
23
|
+
423: "LOCKED",
|
|
24
|
+
424: "FAILED_DEPENDENCY",
|
|
25
|
+
425: "TOO_EARLY_",
|
|
26
|
+
426: "UPGRAGE_REQUIRED",
|
|
27
|
+
428: "PRECONDITION_REQUIRED",
|
|
28
|
+
429: "TOO_MANY_REQUESTS",
|
|
29
|
+
431: "REQUEST_HEADER_FIELDS_TOO_LARGE",
|
|
30
|
+
451: "UNAVAILABLE_FOR_LEGAL_REASONS"
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export class HttpClientError<T extends keyof typeof httpClientErrors = keyof typeof httpClientErrors, K = any> extends Error {
|
|
34
|
+
public readonly httpCode: T;
|
|
35
|
+
public readonly message: (typeof httpClientErrors)[T] | string;
|
|
36
|
+
public readonly data: K;
|
|
37
|
+
|
|
38
|
+
constructor({ httpCode, data, message }: { httpCode: T; data: K; message?: string }) {
|
|
39
|
+
super();
|
|
40
|
+
|
|
41
|
+
this.httpCode = httpCode;
|
|
42
|
+
this.message = !message?.trim() ? httpClientErrors[httpCode] : message.trim();
|
|
43
|
+
this.data = data;
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/http/index.ts
CHANGED
|
@@ -1,61 +1,62 @@
|
|
|
1
|
-
import { HttpClientError } from "./clientError";
|
|
2
|
-
import { HttpServerError } from "./serverError";
|
|
3
|
-
|
|
4
|
-
export type THttpMethods = {
|
|
5
|
-
GET: "GET";
|
|
6
|
-
HEAD: "HEAD";
|
|
7
|
-
POST: "POST";
|
|
8
|
-
PUT: "PUT";
|
|
9
|
-
DELETE: "DELETE";
|
|
10
|
-
CONNECT: "CONNECT";
|
|
11
|
-
OPTIONS: "OPTIONS";
|
|
12
|
-
TRACE: "TRACE";
|
|
13
|
-
PATCH: "PATCH";
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const jsonErrorInfer = (data: any
|
|
17
|
-
headers
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
export * from "./
|
|
1
|
+
import { HttpClientError } from "./clientError";
|
|
2
|
+
import { HttpServerError } from "./serverError";
|
|
3
|
+
|
|
4
|
+
export type THttpMethods = {
|
|
5
|
+
GET: "GET";
|
|
6
|
+
HEAD: "HEAD";
|
|
7
|
+
POST: "POST";
|
|
8
|
+
PUT: "PUT";
|
|
9
|
+
DELETE: "DELETE";
|
|
10
|
+
CONNECT: "CONNECT";
|
|
11
|
+
OPTIONS: "OPTIONS";
|
|
12
|
+
TRACE: "TRACE";
|
|
13
|
+
PATCH: "PATCH";
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const jsonErrorInfer = (data: any) => {
|
|
17
|
+
const headers = new Headers();
|
|
18
|
+
headers.set("Content-Type", "application/json");
|
|
19
|
+
|
|
20
|
+
if (data instanceof HttpClientError || data instanceof HttpServerError) {
|
|
21
|
+
return new Response(JSON.stringify(data), {
|
|
22
|
+
status: data.httpCode,
|
|
23
|
+
statusText: data.message,
|
|
24
|
+
headers: headers
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return new Response(
|
|
29
|
+
JSON.stringify(
|
|
30
|
+
(() => {
|
|
31
|
+
switch (typeof data) {
|
|
32
|
+
case "object":
|
|
33
|
+
return !(data instanceof Error)
|
|
34
|
+
? data
|
|
35
|
+
: {
|
|
36
|
+
message: data.message,
|
|
37
|
+
code: data.name,
|
|
38
|
+
cause: data.cause
|
|
39
|
+
};
|
|
40
|
+
case "string":
|
|
41
|
+
return {
|
|
42
|
+
message: data
|
|
43
|
+
};
|
|
44
|
+
case "number":
|
|
45
|
+
return {
|
|
46
|
+
code: data
|
|
47
|
+
};
|
|
48
|
+
default:
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
})()
|
|
52
|
+
),
|
|
53
|
+
{
|
|
54
|
+
status: 500,
|
|
55
|
+
statusText: "INTERNAL SERVER ERROR",
|
|
56
|
+
headers: headers
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export * from "./clientError";
|
|
62
|
+
export * from "./serverError";
|
package/src/http/serverError.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
export const httpServerErrors = Object.freeze({
|
|
2
|
-
500: "INTERNAL_SERVER_ERROR",
|
|
3
|
-
501: "NOT_IMPLEMENTED",
|
|
4
|
-
502: "BAD_GATEWAY",
|
|
5
|
-
503: "SERVICE_UNAVAILABLE",
|
|
6
|
-
504: "GATEWAY_TIMEOUT",
|
|
7
|
-
505: "HTTP_VERSION_NOT_SUPPORTED",
|
|
8
|
-
506: "VARIANT_ALSO_NEGOTIATES",
|
|
9
|
-
507: "INSUFFICIENT_STORAGE",
|
|
10
|
-
508: "LOOP_DETECTED",
|
|
11
|
-
510: "NOT_EXTENDED",
|
|
12
|
-
511: "NETWORK_AUTHENTICATION_REQUIRED"
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
export class HttpServerError<T extends keyof typeof httpServerErrors = keyof typeof httpServerErrors, K = any> extends Error {
|
|
16
|
-
public readonly httpCode: T;
|
|
17
|
-
public readonly message: (typeof httpServerErrors)[T] | string;
|
|
18
|
-
public readonly data: K;
|
|
19
|
-
|
|
20
|
-
constructor({ httpCode, data, message }: { httpCode: T; data: K; message?: string }) {
|
|
21
|
-
super();
|
|
22
|
-
|
|
23
|
-
this.httpCode = httpCode;
|
|
24
|
-
this.message = !message?.trim() ? httpServerErrors[httpCode] : message.trim();
|
|
25
|
-
this.data = data;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
1
|
+
export const httpServerErrors = Object.freeze({
|
|
2
|
+
500: "INTERNAL_SERVER_ERROR",
|
|
3
|
+
501: "NOT_IMPLEMENTED",
|
|
4
|
+
502: "BAD_GATEWAY",
|
|
5
|
+
503: "SERVICE_UNAVAILABLE",
|
|
6
|
+
504: "GATEWAY_TIMEOUT",
|
|
7
|
+
505: "HTTP_VERSION_NOT_SUPPORTED",
|
|
8
|
+
506: "VARIANT_ALSO_NEGOTIATES",
|
|
9
|
+
507: "INSUFFICIENT_STORAGE",
|
|
10
|
+
508: "LOOP_DETECTED",
|
|
11
|
+
510: "NOT_EXTENDED",
|
|
12
|
+
511: "NETWORK_AUTHENTICATION_REQUIRED"
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export class HttpServerError<T extends keyof typeof httpServerErrors = keyof typeof httpServerErrors, K = any> extends Error {
|
|
16
|
+
public readonly httpCode: T;
|
|
17
|
+
public readonly message: (typeof httpServerErrors)[T] | string;
|
|
18
|
+
public readonly data: K;
|
|
19
|
+
|
|
20
|
+
constructor({ httpCode, data, message }: { httpCode: T; data: K; message?: string }) {
|
|
21
|
+
super();
|
|
22
|
+
|
|
23
|
+
this.httpCode = httpCode;
|
|
24
|
+
this.message = !message?.trim() ? httpServerErrors[httpCode] : message.trim();
|
|
25
|
+
this.data = data;
|
|
26
|
+
}
|
|
27
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
|
|
3
|
-
export type { TRouteModel } from "./entities";
|
|
4
|
-
|
|
5
|
-
export * from "./decorators";
|
|
6
|
-
export * from "./hooks";
|
|
7
|
-
export * from "./http";
|
|
8
|
-
export * from "./interfaces";
|
|
9
|
-
export * as Keys from "./keys";
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
|
|
3
|
+
export type { TRouteModel } from "./entities";
|
|
4
|
+
|
|
5
|
+
export * from "./decorators";
|
|
6
|
+
export * from "./hooks";
|
|
7
|
+
export * from "./http";
|
|
8
|
+
export * from "./interfaces";
|
|
9
|
+
export * as Keys from "./keys";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface IContext {
|
|
2
|
-
get: (key: symbol) => any;
|
|
3
|
-
set: (key: symbol, value: any) => void;
|
|
4
|
-
}
|
|
1
|
+
export interface IContext {
|
|
2
|
+
get: (key: symbol) => any;
|
|
3
|
+
set: (key: symbol, value: any) => void;
|
|
4
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export interface IController<T = any> {}
|
|
1
|
+
export interface IController<T = any> {}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export interface IDispatcher<T = any> {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export interface IDispatcher<T = any, K = any> {
|
|
2
|
+
open?(...args: any[]): T;
|
|
3
|
+
close?(...args: any[]): K;
|
|
4
|
+
}
|
package/src/interfaces/guard.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export interface IGuard {
|
|
2
|
-
enforce(...args: any[]): boolean | Promise<boolean>;
|
|
3
|
-
}
|
|
1
|
+
export interface IGuard {
|
|
2
|
+
enforce(...args: any[]): boolean | Promise<boolean>;
|
|
3
|
+
}
|
package/src/interfaces/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export type { IContext } from "./context";
|
|
2
|
-
export type { IController } from "./controller";
|
|
3
|
-
export type { IDispatcher } from "./dispatcher";
|
|
4
|
-
export type { IGuard } from "./guard";
|
|
5
|
-
export type { IMiddleware } from "./middleware";
|
|
6
|
-
export type { IModule } from "./module";
|
|
1
|
+
export type { IContext } from "./context";
|
|
2
|
+
export type { IController } from "./controller";
|
|
3
|
+
export type { IDispatcher } from "./dispatcher";
|
|
4
|
+
export type { IGuard } from "./guard";
|
|
5
|
+
export type { IMiddleware } from "./middleware";
|
|
6
|
+
export type { IModule } from "./module";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export interface IMiddleware<T = any> {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export interface IMiddleware<T = any, K = any> {
|
|
2
|
+
start?(...args: any[]): T;
|
|
3
|
+
end?(...args: any[]): K;
|
|
4
|
+
}
|
package/src/interfaces/module.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export interface IModule<T = any> {}
|
|
1
|
+
export interface IModule<T = any> {}
|
package/src/keys/index.ts
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
export const argumentsKey = Symbol("__bool:arguments__");
|
|
2
|
-
export const configKey = Symbol("__bool:config__");
|
|
3
|
-
export const controllerKey = Symbol("__bool:controller__");
|
|
4
|
-
export const dispatcherKey = Symbol("__bool:dispatcher__");
|
|
5
|
-
export const guardKey = Symbol("__bool:guard__");
|
|
6
|
-
export const controllerHttpKey = Symbol("__bool:controller.http__");
|
|
7
|
-
export const injectKey = Symbol("__bool:inject__");
|
|
8
|
-
export const injectableKey = Symbol("__bool:injectable__");
|
|
9
|
-
export const middlewareKey = Symbol("__bool:middleware__");
|
|
10
|
-
export const moduleKey = Symbol("__bool:module__");
|
|
11
|
-
export const controllerRouteZodSchemaKey = Symbol("__bool:controller.route.zodSchema__");
|
|
12
|
-
|
|
13
|
-
export const requestHeadersArgsKey = Symbol("__bool:arguments:requestHeaders__");
|
|
14
|
-
export const requestHeaderArgsKey = Symbol("__bool:arguments:requestHeader__");
|
|
15
|
-
export const
|
|
16
|
-
export const paramsArgsKey = Symbol("__bool:arguments:params__");
|
|
17
|
-
export const paramArgsKey = Symbol("__bool:arguments:param__");
|
|
18
|
-
export const queryArgsKey = Symbol("__bool:arguments:query__");
|
|
19
|
-
export const requestArgsKey = Symbol("__bool:arguments:request__");
|
|
20
|
-
export const responseHeadersArgsKey = Symbol("__bool:arguments:responseHeaders__");
|
|
21
|
-
export const contextArgsKey = Symbol("__bool:arguments:context__");
|
|
22
|
-
export const routeModelArgsKey = Symbol("__bool:arguments:routeModel__");
|
|
1
|
+
export const argumentsKey = Symbol("__bool:arguments__");
|
|
2
|
+
export const configKey = Symbol("__bool:config__");
|
|
3
|
+
export const controllerKey = Symbol("__bool:controller__");
|
|
4
|
+
export const dispatcherKey = Symbol("__bool:dispatcher__");
|
|
5
|
+
export const guardKey = Symbol("__bool:guard__");
|
|
6
|
+
export const controllerHttpKey = Symbol("__bool:controller.http__");
|
|
7
|
+
export const injectKey = Symbol("__bool:inject__");
|
|
8
|
+
export const injectableKey = Symbol("__bool:injectable__");
|
|
9
|
+
export const middlewareKey = Symbol("__bool:middleware__");
|
|
10
|
+
export const moduleKey = Symbol("__bool:module__");
|
|
11
|
+
export const controllerRouteZodSchemaKey = Symbol("__bool:controller.route.zodSchema__");
|
|
12
|
+
|
|
13
|
+
export const requestHeadersArgsKey = Symbol("__bool:arguments:requestHeaders__");
|
|
14
|
+
export const requestHeaderArgsKey = Symbol("__bool:arguments:requestHeader__");
|
|
15
|
+
export const requestBodyArgsKey = Symbol("__bool:arguments:requestBody__");
|
|
16
|
+
export const paramsArgsKey = Symbol("__bool:arguments:params__");
|
|
17
|
+
export const paramArgsKey = Symbol("__bool:arguments:param__");
|
|
18
|
+
export const queryArgsKey = Symbol("__bool:arguments:query__");
|
|
19
|
+
export const requestArgsKey = Symbol("__bool:arguments:request__");
|
|
20
|
+
export const responseHeadersArgsKey = Symbol("__bool:arguments:responseHeaders__");
|
|
21
|
+
export const contextArgsKey = Symbol("__bool:arguments:context__");
|
|
22
|
+
export const routeModelArgsKey = Symbol("__bool:arguments:routeModel__");
|
|
23
|
+
export const responseBodyArgsKey = Symbol("__bool:arguments:responseBody__");
|
package/test.http
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
@baseUrl = localhost:3000
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
### Send test GET method
|
|
5
|
-
GET http://{{baseUrl}}/test/abc/23234
|
|
6
|
-
|
|
7
|
-
### Send test POST method
|
|
8
|
-
POST http://{{baseUrl}}/test/abc/123/provider/23234?options[page]=1&options[limit]=6&options[sort][metadata.latestReviewAt]=desc&options[sort][info.searchCount]=desc&options[sort][createdAt]=desc&populate[0]=__headquarters&populate[1]=__logoMedia HTTP/1.1
|
|
9
|
-
content-type: application/json
|
|
10
|
-
|
|
11
|
-
{
|
|
12
|
-
"data": {
|
|
13
|
-
"age": 2,
|
|
14
|
-
"name": "sample",
|
|
15
|
-
"time": "Wed, 21 Oct 2015 18:27:50 GMT"
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
### Send test PUT method
|
|
20
|
-
PUT http://{{baseUrl}}/test
|
|
21
|
-
Content-Type: "application/json"
|
|
22
|
-
|
|
23
|
-
### Send test PATCH method
|
|
24
|
-
PATCH http://{{baseUrl}}/test/abc/23
|
|
25
|
-
Content-Type: "application/json"
|
|
26
|
-
|
|
27
|
-
### Send test DELETE method
|
|
28
|
-
DELETE http://{{baseUrl}}/test
|
|
29
|
-
|
|
30
|
-
### Send test OPTIONS method
|
|
31
|
-
OPTIONS http://{{baseUrl}}/test
|
|
1
|
+
@baseUrl = localhost:3000
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Send test GET method
|
|
5
|
+
GET http://{{baseUrl}}/test/abc/23234
|
|
6
|
+
|
|
7
|
+
### Send test POST method
|
|
8
|
+
POST http://{{baseUrl}}/test/abc/123/provider/23234?options[page]=1&options[limit]=6&options[sort][metadata.latestReviewAt]=desc&options[sort][info.searchCount]=desc&options[sort][createdAt]=desc&populate[0]=__headquarters&populate[1]=__logoMedia HTTP/1.1
|
|
9
|
+
content-type: application/json
|
|
10
|
+
|
|
11
|
+
{
|
|
12
|
+
"data": {
|
|
13
|
+
"age": 2,
|
|
14
|
+
"name": "sample",
|
|
15
|
+
"time": "Wed, 21 Oct 2015 18:27:50 GMT"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
### Send test PUT method
|
|
20
|
+
PUT http://{{baseUrl}}/test
|
|
21
|
+
Content-Type: "application/json"
|
|
22
|
+
|
|
23
|
+
### Send test PATCH method
|
|
24
|
+
PATCH http://{{baseUrl}}/test/abc/23
|
|
25
|
+
Content-Type: "application/json"
|
|
26
|
+
|
|
27
|
+
### Send test DELETE method
|
|
28
|
+
DELETE http://{{baseUrl}}/test
|
|
29
|
+
|
|
30
|
+
### Send test OPTIONS method
|
|
31
|
+
OPTIONS http://{{baseUrl}}/test
|