@bool-ts/core 1.9.1 → 1.9.2
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/__test/_constants.ts +1 -0
- package/__test/container.ts +28 -0
- package/__test/controller.ts +1 -1
- package/__test/{module.ts → firstModule.ts} +4 -6
- package/__test/index.ts +2 -4
- package/__test/secondModule.ts +29 -0
- package/__test/tsconfig.json +1 -1
- package/dist/decorators/arguments.d.ts +5 -1
- package/dist/decorators/container.d.ts +10 -10
- package/dist/decorators/index.d.ts +4 -2
- package/dist/decorators/module.d.ts +6 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -5
- package/dist/interfaces/context.d.ts +8 -2
- package/dist/interfaces/index.d.ts +1 -1
- package/dist/keys/index.d.ts +2 -0
- package/dist/producers/context.d.ts +13 -0
- package/dist/{hooks → producers}/factory.d.ts +3 -2
- package/dist/{hooks → producers}/injector.d.ts +7 -1
- package/package.json +3 -3
- package/src/decorators/arguments.ts +27 -0
- package/src/decorators/container.ts +45 -30
- package/src/decorators/index.ts +4 -1
- package/src/decorators/module.ts +16 -2
- package/src/index.ts +1 -1
- package/src/interfaces/context.ts +9 -2
- package/src/interfaces/index.ts +1 -1
- package/src/keys/index.ts +2 -0
- package/src/producers/context.ts +63 -0
- package/src/producers/factory.ts +2013 -0
- package/src/{hooks → producers}/injector.ts +41 -6
- package/src/hooks/factory.ts +0 -1703
- /package/dist/{hooks → producers}/index.d.ts +0 -0
- /package/src/{hooks → producers}/index.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const mongodbKey = Symbol.for("mongo");
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Container } from "@dist";
|
|
2
|
+
import { mongodbKey } from "_constants";
|
|
3
|
+
import { FirstModule } from "firstModule";
|
|
4
|
+
import { SecondModule } from "secondModule";
|
|
5
|
+
import { FirstGuard } from "./firstGuard";
|
|
6
|
+
import { FirstMiddleware } from "./firstMiddleware";
|
|
7
|
+
import { TestRepository } from "./repository";
|
|
8
|
+
import { SecondGuard } from "./secondGuard";
|
|
9
|
+
import { SecondMiddleware } from "./secondMiddleware";
|
|
10
|
+
import { TestService } from "./service";
|
|
11
|
+
|
|
12
|
+
@Container<{
|
|
13
|
+
mongodb: string;
|
|
14
|
+
}>({
|
|
15
|
+
config: {
|
|
16
|
+
mongodb: "123"
|
|
17
|
+
},
|
|
18
|
+
loaders: {
|
|
19
|
+
mongodb: ({ config }) => {
|
|
20
|
+
return [mongodbKey, { hehe: "435345" }];
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
modules: [FirstModule, SecondModule],
|
|
24
|
+
middlewares: [FirstMiddleware, SecondMiddleware],
|
|
25
|
+
guards: [FirstGuard, SecondGuard],
|
|
26
|
+
dependencies: [TestService, TestRepository]
|
|
27
|
+
})
|
|
28
|
+
export class AppContainer {}
|
package/__test/controller.ts
CHANGED
|
@@ -52,7 +52,7 @@ const headersSchema = Zod.object({
|
|
|
52
52
|
@Controller("test")
|
|
53
53
|
export class TestController {
|
|
54
54
|
constructor(
|
|
55
|
-
@Inject(Symbol.for("
|
|
55
|
+
@Inject(Symbol.for("mongo")) private readonly testInject: any,
|
|
56
56
|
@Inject(TestService) private readonly testService: IService
|
|
57
57
|
) {
|
|
58
58
|
console.log("testInject", testInject);
|
|
@@ -13,11 +13,9 @@ import { TestWebSocket } from "./webSocket";
|
|
|
13
13
|
mongodb: string;
|
|
14
14
|
}>({
|
|
15
15
|
config: {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
mongodb: ({ config }) => {
|
|
20
|
-
return [Symbol.for("etst"), { hehe: "435345" }];
|
|
16
|
+
key: Symbol("firstModuleConfig"),
|
|
17
|
+
value: {
|
|
18
|
+
mongodb: "123"
|
|
21
19
|
}
|
|
22
20
|
},
|
|
23
21
|
middlewares: [FirstMiddleware, SecondMiddleware],
|
|
@@ -27,4 +25,4 @@ import { TestWebSocket } from "./webSocket";
|
|
|
27
25
|
dependencies: [TestService, TestRepository],
|
|
28
26
|
webSockets: [TestWebSocket]
|
|
29
27
|
})
|
|
30
|
-
export class
|
|
28
|
+
export class FirstModule {}
|
package/__test/index.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
|
|
3
1
|
import { BoolFactory } from "@dist";
|
|
4
|
-
import {
|
|
2
|
+
import { AppContainer } from "container";
|
|
5
3
|
|
|
6
|
-
BoolFactory(
|
|
4
|
+
BoolFactory(AppContainer, {
|
|
7
5
|
port: 3000,
|
|
8
6
|
log: {
|
|
9
7
|
methods: ["GET", "POST"]
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Module } from "@dist";
|
|
2
|
+
import { TestController } from "./controller";
|
|
3
|
+
import { CustomDispatcher } from "./dispatcher";
|
|
4
|
+
import { FirstGuard } from "./firstGuard";
|
|
5
|
+
import { FirstMiddleware } from "./firstMiddleware";
|
|
6
|
+
import { TestRepository } from "./repository";
|
|
7
|
+
import { SecondGuard } from "./secondGuard";
|
|
8
|
+
import { SecondMiddleware } from "./secondMiddleware";
|
|
9
|
+
import { TestService } from "./service";
|
|
10
|
+
import { TestWebSocket } from "./webSocket";
|
|
11
|
+
|
|
12
|
+
@Module<{
|
|
13
|
+
mongodb: string;
|
|
14
|
+
}>({
|
|
15
|
+
prefix: "/second-module",
|
|
16
|
+
config: {
|
|
17
|
+
key: Symbol.for("secondModuleConfig"),
|
|
18
|
+
value: {
|
|
19
|
+
mongodb: "123"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
middlewares: [FirstMiddleware, SecondMiddleware],
|
|
23
|
+
guards: [FirstGuard, SecondGuard],
|
|
24
|
+
dispatchers: [CustomDispatcher],
|
|
25
|
+
controllers: [TestController],
|
|
26
|
+
dependencies: [TestService, TestRepository],
|
|
27
|
+
webSockets: [TestWebSocket]
|
|
28
|
+
})
|
|
29
|
+
export class SecondModule {}
|
package/__test/tsconfig.json
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"baseUrl": "./" /* Specify the base directory to resolve non-relative module names. */,
|
|
32
32
|
"paths": {
|
|
33
33
|
"@src": ["../src"],
|
|
34
|
-
"@dist": ["../
|
|
34
|
+
"@dist": ["../src"]
|
|
35
35
|
} /* Specify a set of entries that re-map imports to additional lookup locations. */,
|
|
36
36
|
"rootDirs": [
|
|
37
37
|
"./",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Zod from "zod";
|
|
2
|
-
import { contextArgsKey, paramArgsKey, paramsArgsKey, queryArgsKey, requestArgsKey, requestBodyArgsKey, requestHeaderArgsKey, requestHeadersArgsKey, responseHeadersArgsKey, routeModelArgsKey } from "../keys";
|
|
2
|
+
import { contextArgsKey, httpServerArgsKey, paramArgsKey, paramsArgsKey, queryArgsKey, requestArgsKey, requestBodyArgsKey, requestHeaderArgsKey, requestHeadersArgsKey, responseHeadersArgsKey, routeModelArgsKey } from "../keys";
|
|
3
3
|
export type TArgumentsMetadata = {
|
|
4
4
|
index: number;
|
|
5
5
|
type: typeof requestHeadersArgsKey;
|
|
@@ -41,6 +41,9 @@ export type TArgumentsMetadata = {
|
|
|
41
41
|
} | {
|
|
42
42
|
index: number;
|
|
43
43
|
type: typeof routeModelArgsKey;
|
|
44
|
+
} | {
|
|
45
|
+
index: number;
|
|
46
|
+
type: typeof httpServerArgsKey;
|
|
44
47
|
};
|
|
45
48
|
export type TArgumentsMetadataCollection = Record<`argumentIndexes.${number}`, TArgumentsMetadata>;
|
|
46
49
|
export declare const RequestHeaders: (schema?: Zod.Schema) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => void;
|
|
@@ -53,3 +56,4 @@ export declare const Request: (schema?: Zod.Schema) => (target: Object, methodNa
|
|
|
53
56
|
export declare const ResponseHeaders: () => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => void;
|
|
54
57
|
export declare const Context: (key?: symbol) => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => void;
|
|
55
58
|
export declare const RouteModel: () => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => void;
|
|
59
|
+
export declare const HttpServer: () => (target: Object, methodName: string | symbol | undefined, parameterIndex: number) => void;
|
|
@@ -3,26 +3,26 @@ type TInstances = Array<new (...args: any[]) => any>;
|
|
|
3
3
|
type TLoaders<TConfig extends {} = {}> = Record<string | symbol, (args: {
|
|
4
4
|
config: TConfig;
|
|
5
5
|
}) => [string | symbol, any] | Promise<[string | symbol, any]>>;
|
|
6
|
-
export type
|
|
6
|
+
export type TContainerConfig<TConfig> = TConfig | (() => TConfig | Promise<TConfig>) | Readonly<{
|
|
7
|
+
key: symbol;
|
|
8
|
+
value: TConfig | (() => TConfig | Promise<TConfig>);
|
|
9
|
+
}>;
|
|
10
|
+
export type TContainerOptions<TConfig extends {} = {}> = Partial<{
|
|
11
|
+
config: TContainerConfig<TConfig>;
|
|
7
12
|
modules: TInstances;
|
|
8
|
-
}> & Partial<{
|
|
9
|
-
config: TConfig | (() => TConfig | Promise<TConfig>);
|
|
10
13
|
dependencies: TInstances;
|
|
11
14
|
loaders: TLoaders<TConfig>;
|
|
12
15
|
middlewares: TInstances;
|
|
13
16
|
guards: TInstances;
|
|
14
|
-
|
|
15
|
-
}>
|
|
16
|
-
export type TContainerMetadata<TConfig extends {} = {}> = (Required<{
|
|
17
|
+
}> | undefined;
|
|
18
|
+
export type TContainerMetadata<TConfig extends {} = {}> = Partial<{
|
|
17
19
|
modules: TInstances;
|
|
18
|
-
|
|
19
|
-
config: TConfig | ((...args: any[]) => TConfig | Promise<TConfig>);
|
|
20
|
+
config: TContainerConfig<TConfig>;
|
|
20
21
|
dependencies: TInstances;
|
|
21
22
|
loaders: TLoaders<TConfig>;
|
|
22
23
|
middlewares: TInstances;
|
|
23
24
|
guards: TInstances;
|
|
24
|
-
|
|
25
|
-
}>) | undefined;
|
|
25
|
+
}> | undefined;
|
|
26
26
|
export declare const Container: <TConfig extends {} = {}>(args?: TContainerOptions<TConfig>) => <T extends {
|
|
27
27
|
new (...args: any[]): IModule;
|
|
28
28
|
}>(target: T) => void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { Context, Param, Params, Query, Request, RequestBody, RequestHeader, RequestHeaders, ResponseHeaders, RouteModel } from "./arguments";
|
|
1
|
+
export { Context, HttpServer, Param, Params, Query, Request, RequestBody, RequestHeader, RequestHeaders, ResponseHeaders, RouteModel } from "./arguments";
|
|
2
|
+
export { Container } from "./container";
|
|
2
3
|
export { Controller } from "./controller";
|
|
3
4
|
export { Dispatcher } from "./dispatcher";
|
|
4
5
|
export { Guard } from "./guard";
|
|
@@ -12,11 +13,12 @@ export { WebSocketCloseCode, WebSocketCloseReason, WebSocketConnection, WebSocke
|
|
|
12
13
|
export { WebSocketEvent } from "./webSocketEvent";
|
|
13
14
|
export { ZodSchema } from "./zodSchema";
|
|
14
15
|
export type { TArgumentsMetadata } from "./arguments";
|
|
16
|
+
export type { TContainerConfig, TContainerMetadata, TContainerOptions } from "./container";
|
|
15
17
|
export type { TControllerMetadata } from "./controller";
|
|
16
18
|
export type { TDispatcherMetadata } from "./dispatcher";
|
|
17
19
|
export type { TGuardMetadata } from "./guard";
|
|
18
20
|
export type { THttpMetadata } from "./http";
|
|
19
21
|
export type { TMiddlewareMetadata } from "./middleware";
|
|
20
|
-
export type { TModuleMetadata, TModuleOptions } from "./module";
|
|
22
|
+
export type { TModuleConfig, TModuleMetadata, TModuleOptions } from "./module";
|
|
21
23
|
export type { TWebSocketMetadata } from "./webSocket";
|
|
22
24
|
export type { TWebSocketEventHandlerMetadata, TWebSocketEventMetadata } from "./webSocketEvent";
|
|
@@ -3,8 +3,12 @@ type TInstances = Array<new (...args: any[]) => any>;
|
|
|
3
3
|
type TLoaders<TConfig extends {} = {}> = Record<string | symbol, (args: {
|
|
4
4
|
config: TConfig;
|
|
5
5
|
}) => [string | symbol, any] | Promise<[string | symbol, any]>>;
|
|
6
|
+
export type TModuleConfig<TConfig> = TConfig | (() => TConfig | Promise<TConfig>) | Readonly<{
|
|
7
|
+
key: symbol;
|
|
8
|
+
value: TConfig | (() => TConfig | Promise<TConfig>);
|
|
9
|
+
}>;
|
|
6
10
|
export type TModuleOptions<TConfig extends {} = {}> = Partial<{
|
|
7
|
-
config:
|
|
11
|
+
config: TModuleConfig<TConfig>;
|
|
8
12
|
prefix: string;
|
|
9
13
|
dependencies: TInstances;
|
|
10
14
|
loaders: TLoaders<TConfig>;
|
|
@@ -15,7 +19,7 @@ export type TModuleOptions<TConfig extends {} = {}> = Partial<{
|
|
|
15
19
|
webSockets: TInstances;
|
|
16
20
|
}> | undefined;
|
|
17
21
|
export type TModuleMetadata<TConfig extends {} = {}> = Partial<{
|
|
18
|
-
config:
|
|
22
|
+
config: TModuleConfig<TConfig>;
|
|
19
23
|
prefix: string;
|
|
20
24
|
dependencies: TInstances;
|
|
21
25
|
loaders: TLoaders<TConfig>;
|
package/dist/index.d.ts
CHANGED