@venok/core 1.0.0 → 1.0.1-canary.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/constants.d.ts +0 -2
- package/constants.js +1 -3
- package/context/{external/creator.d.ts → context.d.ts} +12 -9
- package/context/{external/creator.js → context.js} +23 -26
- package/context/execution-host.d.ts +1 -1
- package/context/index.d.ts +4 -0
- package/context/index.js +20 -0
- package/context/proxy.d.ts +6 -0
- package/context/proxy.js +33 -0
- package/decorators/catch.decorator.d.ts +1 -1
- package/errors/exceptions/invalid-class-scope.exception.d.ts +1 -1
- package/errors/exceptions/undefined-forwardref.exception.d.ts +1 -1
- package/errors/messages.d.ts +1 -1
- package/exceptions/handler.d.ts +10 -0
- package/exceptions/{external/handler.js → handler.js} +14 -11
- package/exceptions/index.d.ts +2 -0
- package/exceptions/index.js +18 -0
- package/exceptions/zone/index.d.ts +2 -0
- package/exceptions/zone/index.js +18 -0
- package/{exceptions/filter-context.d.ts → filters/context-creator.d.ts} +3 -3
- package/{exceptions/filter-context.js → filters/context-creator.js} +8 -15
- package/filters/context.d.ts +12 -0
- package/{exceptions/external/filter-context.js → filters/context.js} +10 -6
- package/filters/filter.d.ts +6 -0
- package/filters/filter.js +16 -0
- package/filters/index.d.ts +3 -0
- package/filters/index.js +19 -0
- package/guards/context-creator.d.ts +1 -1
- package/injector/container.d.ts +7 -7
- package/injector/helpers/class-scope.helper.d.ts +1 -1
- package/injector/helpers/is-durable.helper.d.ts +1 -1
- package/injector/injector.d.ts +2 -2
- package/injector/internal-core-module/internal-core-module-factory.js +10 -5
- package/injector/module/compiler.d.ts +5 -5
- package/injector/module/lazy/loader.d.ts +1 -1
- package/injector/module/module.d.ts +2 -2
- package/injector/module/token-factory.d.ts +3 -3
- package/inspector/serialized-graph.js +1 -1
- package/interceptors/context-creator.d.ts +1 -1
- package/interfaces/context/index.d.ts +2 -0
- package/interfaces/context/index.js +18 -0
- package/interfaces/features/index.d.ts +4 -0
- package/interfaces/features/index.js +20 -0
- package/interfaces/features/pipes.interface.d.ts +1 -1
- package/interfaces/index.d.ts +2 -0
- package/interfaces/index.js +2 -0
- package/interfaces/modules/definition.interface.d.ts +1 -1
- package/interfaces/modules/dynamic-module.interface.d.ts +1 -1
- package/interfaces/modules/module-metadata.interface.d.ts +1 -1
- package/interfaces/modules/provider.interface.d.ts +1 -1
- package/package.json +1 -1
- package/pipes/context-creator.d.ts +1 -1
- package/scanner.d.ts +9 -9
- package/services/reflector.service.d.ts +8 -8
- package/test/context/{external/creator.spec.js → creator.spec.js} +4 -4
- package/test/context/{external/proxy.spec.js → proxy.spec.js} +10 -9
- package/test/exceptions/{external/handler.spec.js → handler.spec.js} +6 -5
- package/test/{exceptions/filter-context.spec.js → filters/context-creator.spec.js} +3 -3
- package/test/injector/internal-core-module/internal-core-module-factory.spec.js +3 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/context/external/proxy.d.ts +0 -5
- package/context/external/proxy.js +0 -19
- package/exceptions/external/filter-context.d.ts +0 -10
- package/exceptions/external/filter.d.ts +0 -5
- package/exceptions/external/filter.js +0 -16
- package/exceptions/external/handler.d.ts +0 -9
- package/exceptions/select-exception-filter-metadata.d.ts +0 -2
- package/exceptions/select-exception-filter-metadata.js +0 -6
- /package/test/context/{external/creator.spec.d.ts → creator.spec.d.ts} +0 -0
- /package/test/context/{external/proxy.spec.d.ts → proxy.spec.d.ts} +0 -0
- /package/test/exceptions/{external/handler.spec.d.ts → handler.spec.d.ts} +0 -0
- /package/test/{exceptions/filter-context.spec.d.ts → filters/context-creator.spec.d.ts} +0 -0
package/constants.d.ts
CHANGED
|
@@ -28,8 +28,6 @@ export declare const APP_FILTER = "APP_FILTER";
|
|
|
28
28
|
export declare const ENHANCER_TOKEN_TO_SUBTYPE_MAP: Record<typeof APP_GUARD | typeof APP_PIPE | typeof APP_FILTER | typeof APP_INTERCEPTOR, EnhancerSubtype>;
|
|
29
29
|
export declare const REQUEST = "REQUEST";
|
|
30
30
|
export declare const GLOBAL_MODULE_METADATA = "__module:global__";
|
|
31
|
-
export declare const HOST_METADATA = "host";
|
|
32
|
-
export declare const PATH_METADATA = "path";
|
|
33
31
|
export declare const PARAMTYPES_METADATA = "design:paramtypes";
|
|
34
32
|
export declare const SELF_DECLARED_DEPS_METADATA = "self:paramtypes";
|
|
35
33
|
export declare const OPTIONAL_DEPS_METADATA = "optional:paramtypes";
|
package/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.INQUIRER = exports.ENTRY_PROVIDER_WATERMARK = exports.CATCH_WATERMARK = exports.INJECTABLE_WATERMARK = exports.FILTER_CATCH_EXCEPTIONS = exports.CUSTOM_ROUTE_ARGS_METADATA = exports.ROUTE_ARGS_METADATA = exports.MODULE_PATH = exports.SCOPE_OPTIONS_METADATA = exports.OPTIONAL_PROPERTY_DEPS_METADATA = exports.PROPERTY_DEPS_METADATA = exports.OPTIONAL_DEPS_METADATA = exports.SELF_DECLARED_DEPS_METADATA = exports.PARAMTYPES_METADATA = exports.
|
|
3
|
+
exports.INQUIRER = exports.ENTRY_PROVIDER_WATERMARK = exports.CATCH_WATERMARK = exports.INJECTABLE_WATERMARK = exports.FILTER_CATCH_EXCEPTIONS = exports.CUSTOM_ROUTE_ARGS_METADATA = exports.ROUTE_ARGS_METADATA = exports.MODULE_PATH = exports.SCOPE_OPTIONS_METADATA = exports.OPTIONAL_PROPERTY_DEPS_METADATA = exports.PROPERTY_DEPS_METADATA = exports.OPTIONAL_DEPS_METADATA = exports.SELF_DECLARED_DEPS_METADATA = exports.PARAMTYPES_METADATA = exports.GLOBAL_MODULE_METADATA = exports.REQUEST = exports.ENHANCER_TOKEN_TO_SUBTYPE_MAP = exports.APP_FILTER = exports.APP_GUARD = exports.APP_PIPE = exports.APP_INTERCEPTOR = exports.ENHANCER_KEY_TO_SUBTYPE_MAP = exports.EXCEPTION_FILTERS_METADATA = exports.INTERCEPTORS_METADATA = exports.GUARDS_METADATA = exports.PIPES_METADATA = exports.MODULE_METADATA = exports.FORBIDDEN_MESSAGE = exports.MESSAGES = void 0;
|
|
4
4
|
exports.MESSAGES = {
|
|
5
5
|
APPLICATION_START: `Starting Venok application...`,
|
|
6
6
|
APPLICATION_READY: `Venok application successfully started`,
|
|
@@ -35,8 +35,6 @@ exports.ENHANCER_TOKEN_TO_SUBTYPE_MAP = {
|
|
|
35
35
|
};
|
|
36
36
|
exports.REQUEST = "REQUEST";
|
|
37
37
|
exports.GLOBAL_MODULE_METADATA = "__module:global__";
|
|
38
|
-
exports.HOST_METADATA = "host";
|
|
39
|
-
exports.PATH_METADATA = "path";
|
|
40
38
|
exports.PARAMTYPES_METADATA = "design:paramtypes";
|
|
41
39
|
exports.SELF_DECLARED_DEPS_METADATA = "self:paramtypes";
|
|
42
40
|
exports.OPTIONAL_DEPS_METADATA = "optional:paramtypes";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Observable } from "rxjs";
|
|
1
2
|
import { ParamData } from "@venok/core/decorators/create-param.decorator";
|
|
2
3
|
import { GuardsConsumer, GuardsContextCreator } from "@venok/core/guards";
|
|
3
4
|
import { InterceptorsConsumer, InterceptorsContextCreator } from "@venok/core/interceptors";
|
|
@@ -7,8 +8,9 @@ import { VenokContainer } from "@venok/core/injector/container";
|
|
|
7
8
|
import { ContextType } from "@venok/core/interfaces/context/arguments-host.interface";
|
|
8
9
|
import { PipeTransform } from "@venok/core/interfaces/features/pipes.interface";
|
|
9
10
|
import { ContextId } from "@venok/core/injector/instance/wrapper";
|
|
10
|
-
import { ParamProperties } from "@venok/core/helpers/context.helper";
|
|
11
|
-
import {
|
|
11
|
+
import { ContextUtils, ParamProperties } from "@venok/core/helpers/context.helper";
|
|
12
|
+
import { VenokProxy } from "@venok/core/context/proxy";
|
|
13
|
+
import { VenokExceptionFilterContext } from "@venok/core/filters/context";
|
|
12
14
|
export interface ParamsFactory {
|
|
13
15
|
exchangeKeyForValue(type: number, data: ParamData, args: any): any;
|
|
14
16
|
}
|
|
@@ -29,8 +31,9 @@ export interface ExternalContextOptions {
|
|
|
29
31
|
guards?: boolean;
|
|
30
32
|
interceptors?: boolean;
|
|
31
33
|
filters?: boolean;
|
|
34
|
+
callback?: (result: any | Observable<any>, ...args: any[]) => void;
|
|
32
35
|
}
|
|
33
|
-
export declare class
|
|
36
|
+
export declare class VenokContextCreator {
|
|
34
37
|
private readonly guardsContextCreator;
|
|
35
38
|
private readonly guardsConsumer;
|
|
36
39
|
private readonly interceptorsContextCreator;
|
|
@@ -39,15 +42,15 @@ export declare class ExternalContextCreator {
|
|
|
39
42
|
private readonly pipesContextCreator;
|
|
40
43
|
private readonly pipesConsumer;
|
|
41
44
|
private readonly filtersContextCreator;
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
readonly contextUtils: ContextUtils;
|
|
46
|
+
readonly venokProxy: VenokProxy;
|
|
44
47
|
private container;
|
|
45
|
-
constructor(guardsContextCreator: GuardsContextCreator, guardsConsumer: GuardsConsumer, interceptorsContextCreator: InterceptorsContextCreator, interceptorsConsumer: InterceptorsConsumer, modulesContainer: ModulesContainer, pipesContextCreator: PipesContextCreator, pipesConsumer: PipesConsumer, filtersContextCreator:
|
|
46
|
-
static fromContainer(container: VenokContainer):
|
|
48
|
+
constructor(guardsContextCreator: GuardsContextCreator, guardsConsumer: GuardsConsumer, interceptorsContextCreator: InterceptorsContextCreator, interceptorsConsumer: InterceptorsConsumer, modulesContainer: ModulesContainer, pipesContextCreator: PipesContextCreator, pipesConsumer: PipesConsumer, filtersContextCreator: VenokExceptionFilterContext);
|
|
49
|
+
static fromContainer(container: VenokContainer): VenokContextCreator;
|
|
47
50
|
create<TParamsMetadata extends ParamsMetadata = ParamsMetadata, TContext extends string = ContextType>(instance: object, callback: (...args: unknown[]) => unknown, methodName: string, metadataKey?: string, paramsFactory?: ParamsFactory, contextId?: ContextId, inquirerId?: string, options?: ExternalContextOptions, contextType?: TContext): (...args: any[]) => Promise<any>;
|
|
48
51
|
getMetadata<TMetadata, TContext extends string = ContextType>(instance: any, methodName: string, metadataKey?: string, paramsFactory?: ParamsFactory, contextType?: TContext): ExternalHandlerMetadata;
|
|
49
52
|
getContextModuleKey(moduleCtor: Function | undefined): string;
|
|
50
|
-
exchangeKeysForValues<TMetadata
|
|
53
|
+
exchangeKeysForValues<TMetadata extends Record<string | symbol, any>>(keys: string[], metadata: TMetadata, moduleContext: string, paramsFactory: ParamsFactory, contextId?: ContextId, inquirerId?: string, contextFactory?: (args: unknown[]) => import("./execution-host").ExecutionContextHost): ParamProperties[];
|
|
51
54
|
createPipesFn(pipes: PipeTransform[], paramsOptions: (ParamProperties & {
|
|
52
55
|
metatype?: unknown;
|
|
53
56
|
})[]): ((args: unknown[], ...params: unknown[]) => Promise<void>) | null;
|
|
@@ -56,7 +59,7 @@ export declare class ExternalContextCreator {
|
|
|
56
59
|
type: any;
|
|
57
60
|
data: any;
|
|
58
61
|
}, pipes: PipeTransform[]): Promise<any>;
|
|
59
|
-
transformToResult(resultOrDeferred: any): Promise<any>;
|
|
62
|
+
transformToResult(resultOrDeferred: Observable<any> | any): Promise<any>;
|
|
60
63
|
createGuardsFn<TContext extends string = ContextType>(guards: any[], instance: object, callback: (...args: any[]) => any, contextType?: TContext): Function | null;
|
|
61
64
|
registerRequestProvider<T = any>(request: T, contextId: ContextId): void;
|
|
62
65
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.VenokContextCreator = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
4
5
|
const guards_1 = require("@venok/core/guards");
|
|
5
6
|
const interceptors_1 = require("@venok/core/interceptors");
|
|
6
7
|
const pipes_1 = require("@venok/core/pipes");
|
|
7
8
|
const constants_1 = require("@venok/core/injector/constants");
|
|
8
9
|
const constants_2 = require("@venok/core/constants");
|
|
9
10
|
const shared_helper_1 = require("@venok/core/helpers/shared.helper");
|
|
10
|
-
const rxjs_1 = require("rxjs");
|
|
11
11
|
const exceptions_1 = require("@venok/core/errors/exceptions");
|
|
12
12
|
const context_helper_1 = require("@venok/core/helpers/context.helper");
|
|
13
|
-
const proxy_1 = require("@venok/core/context/
|
|
14
|
-
const
|
|
15
|
-
class
|
|
13
|
+
const proxy_1 = require("@venok/core/context/proxy");
|
|
14
|
+
const context_1 = require("@venok/core/filters/context");
|
|
15
|
+
class VenokContextCreator {
|
|
16
16
|
constructor(guardsContextCreator, guardsConsumer, interceptorsContextCreator, interceptorsConsumer, modulesContainer, pipesContextCreator, pipesConsumer, filtersContextCreator) {
|
|
17
17
|
this.guardsContextCreator = guardsContextCreator;
|
|
18
18
|
this.guardsConsumer = guardsConsumer;
|
|
@@ -23,7 +23,7 @@ class ExternalContextCreator {
|
|
|
23
23
|
this.pipesConsumer = pipesConsumer;
|
|
24
24
|
this.filtersContextCreator = filtersContextCreator;
|
|
25
25
|
this.contextUtils = new context_helper_1.ContextUtils();
|
|
26
|
-
this.
|
|
26
|
+
this.venokProxy = new proxy_1.VenokProxy();
|
|
27
27
|
}
|
|
28
28
|
static fromContainer(container) {
|
|
29
29
|
const guardsContextCreator = new guards_1.GuardsContextCreator(container, container.applicationConfig);
|
|
@@ -32,16 +32,17 @@ class ExternalContextCreator {
|
|
|
32
32
|
const interceptorsConsumer = new interceptors_1.InterceptorsConsumer();
|
|
33
33
|
const pipesContextCreator = new pipes_1.PipesContextCreator(container, container.applicationConfig);
|
|
34
34
|
const pipesConsumer = new pipes_1.PipesConsumer();
|
|
35
|
-
const filtersContextCreator = new
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
return
|
|
35
|
+
const filtersContextCreator = new context_1.VenokExceptionFilterContext(container, container.applicationConfig);
|
|
36
|
+
const venokContextCreator = new VenokContextCreator(guardsContextCreator, guardsConsumer, interceptorsContextCreator, interceptorsConsumer, container.getModules(), pipesContextCreator, pipesConsumer, filtersContextCreator);
|
|
37
|
+
venokContextCreator.container = container;
|
|
38
|
+
return venokContextCreator;
|
|
39
39
|
}
|
|
40
40
|
create(instance, callback, methodName, metadataKey, paramsFactory, contextId = constants_1.STATIC_CONTEXT, inquirerId, options = {
|
|
41
41
|
interceptors: true,
|
|
42
42
|
guards: true,
|
|
43
43
|
filters: true,
|
|
44
|
-
|
|
44
|
+
callback: () => { },
|
|
45
|
+
}, contextType = "native") {
|
|
45
46
|
const module = this.getContextModuleKey(instance.constructor);
|
|
46
47
|
const { argsLength, paramtypes, getParamsMetadata } = this.getMetadata(instance, methodName, metadataKey, paramsFactory, contextType);
|
|
47
48
|
const pipes = this.pipesContextCreator.create(instance, callback, module, contextId, inquirerId);
|
|
@@ -65,9 +66,12 @@ class ExternalContextCreator {
|
|
|
65
66
|
const initialArgs = this.contextUtils.createNullArray(argsLength);
|
|
66
67
|
fnCanActivate && (await fnCanActivate(args));
|
|
67
68
|
const result = await this.interceptorsConsumer.intercept(interceptors, args, instance, callback, handler(initialArgs, ...args), contextType);
|
|
68
|
-
|
|
69
|
+
const done = await this.transformToResult(result);
|
|
70
|
+
if (options.callback)
|
|
71
|
+
options.callback(done, ...args);
|
|
72
|
+
return done;
|
|
69
73
|
};
|
|
70
|
-
return options.filters ? this.
|
|
74
|
+
return options.filters ? this.venokProxy.createProxy(target, exceptionFilter, contextType) : target;
|
|
71
75
|
}
|
|
72
76
|
getMetadata(instance, methodName, metadataKey, paramsFactory, contextType) {
|
|
73
77
|
// const cacheMetadata = this.handlerMetadataStorage.get(instance, methodName);
|
|
@@ -92,28 +96,23 @@ class ExternalContextCreator {
|
|
|
92
96
|
}
|
|
93
97
|
getContextModuleKey(moduleCtor) {
|
|
94
98
|
const emptyModuleKey = "";
|
|
95
|
-
if (!moduleCtor)
|
|
99
|
+
if (!moduleCtor)
|
|
96
100
|
return emptyModuleKey;
|
|
97
|
-
}
|
|
98
101
|
const moduleContainerEntries = this.modulesContainer.entries();
|
|
99
102
|
for (const [key, moduleRef] of moduleContainerEntries) {
|
|
100
|
-
|
|
103
|
+
// REFACTOR
|
|
104
|
+
if (moduleRef.hasProvider && moduleRef.hasProvider(moduleCtor))
|
|
101
105
|
return key;
|
|
102
|
-
}
|
|
103
106
|
}
|
|
104
107
|
return emptyModuleKey;
|
|
105
108
|
}
|
|
106
109
|
exchangeKeysForValues(keys, metadata, moduleContext, paramsFactory, contextId = constants_1.STATIC_CONTEXT, inquirerId, contextFactory = this.contextUtils.getContextFactory("http")) {
|
|
107
110
|
this.pipesContextCreator.setModuleContext(moduleContext);
|
|
108
111
|
return keys.map((key) => {
|
|
109
|
-
// Maybe Error
|
|
110
|
-
// @ts-ignore
|
|
111
112
|
const { index, data, pipes: pipesCollection } = metadata[key];
|
|
112
113
|
const pipes = this.pipesContextCreator.createConcreteContext(pipesCollection, contextId, inquirerId);
|
|
113
114
|
const type = this.contextUtils.mapParamType(key);
|
|
114
115
|
if (key.includes(constants_2.CUSTOM_ROUTE_ARGS_METADATA)) {
|
|
115
|
-
// Maybe Error
|
|
116
|
-
// @ts-ignore
|
|
117
116
|
const { factory } = metadata[key];
|
|
118
117
|
const customExtractValue = this.contextUtils.getCustomFactory(factory, data, contextFactory);
|
|
119
118
|
return { index, extractValue: customExtractValue, type, data, pipes };
|
|
@@ -138,17 +137,15 @@ class ExternalContextCreator {
|
|
|
138
137
|
return (0, shared_helper_1.isEmpty)(pipes) ? value : this.pipesConsumer.apply(value, { metatype, type, data }, pipes);
|
|
139
138
|
}
|
|
140
139
|
async transformToResult(resultOrDeferred) {
|
|
141
|
-
if ((0, rxjs_1.isObservable)(resultOrDeferred))
|
|
140
|
+
if ((0, rxjs_1.isObservable)(resultOrDeferred))
|
|
142
141
|
return (0, rxjs_1.lastValueFrom)(resultOrDeferred);
|
|
143
|
-
}
|
|
144
142
|
return resultOrDeferred;
|
|
145
143
|
}
|
|
146
144
|
createGuardsFn(guards, instance, callback, contextType) {
|
|
147
145
|
const canActivateFn = async (args) => {
|
|
148
146
|
const canActivate = await this.guardsConsumer.tryActivate(guards, args, instance, callback, contextType);
|
|
149
|
-
if (!canActivate)
|
|
147
|
+
if (!canActivate)
|
|
150
148
|
throw new exceptions_1.RuntimeException(constants_2.FORBIDDEN_MESSAGE);
|
|
151
|
-
}
|
|
152
149
|
};
|
|
153
150
|
return guards.length ? canActivateFn : null;
|
|
154
151
|
}
|
|
@@ -156,4 +153,4 @@ class ExternalContextCreator {
|
|
|
156
153
|
this.container.registerRequestProvider(request, contextId);
|
|
157
154
|
}
|
|
158
155
|
}
|
|
159
|
-
exports.
|
|
156
|
+
exports.VenokContextCreator = VenokContextCreator;
|
|
@@ -6,7 +6,7 @@ export declare class ExecutionContextHost implements ExecutionContext {
|
|
|
6
6
|
private readonly constructorRef;
|
|
7
7
|
private readonly handler;
|
|
8
8
|
private contextType;
|
|
9
|
-
constructor(args: any[], constructorRef?: Type
|
|
9
|
+
constructor(args: any[], constructorRef?: Type, handler?: Function);
|
|
10
10
|
setType<TContext extends string = ContextType>(type: TContext): void;
|
|
11
11
|
getType<TContext extends string = ContextType>(): TContext;
|
|
12
12
|
getClass<T = any>(): Type<T>;
|
package/context/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./context"), exports);
|
|
18
|
+
__exportStar(require("./creator"), exports);
|
|
19
|
+
__exportStar(require("./execution-host"), exports);
|
|
20
|
+
__exportStar(require("./proxy"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ContextType } from "@venok/core/interfaces";
|
|
2
|
+
import { VenokExceptionsHandler } from "@venok/core/exceptions/handler";
|
|
3
|
+
export declare class VenokProxy {
|
|
4
|
+
createProxy<TContext extends string = ContextType>(targetCallback: (...args: any[]) => any, exceptionsHandler: VenokExceptionsHandler, type?: TContext): (...args: any[]) => Promise<any>;
|
|
5
|
+
createExceptionLayerProxy<TContext extends string = ContextType>(targetCallback: <TError>(err: TError, ...args: any[]) => void, exceptionsHandler: VenokExceptionsHandler, type?: TContext): <TError>(err: TError, ...args: any[]) => Promise<any[] | undefined>;
|
|
6
|
+
}
|
package/context/proxy.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VenokProxy = void 0;
|
|
4
|
+
const execution_host_1 = require("@venok/core/context/execution-host");
|
|
5
|
+
class VenokProxy {
|
|
6
|
+
createProxy(targetCallback, exceptionsHandler, type) {
|
|
7
|
+
return async (...args) => {
|
|
8
|
+
try {
|
|
9
|
+
return await targetCallback(...args);
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
const host = new execution_host_1.ExecutionContextHost(args);
|
|
13
|
+
host.setType(type);
|
|
14
|
+
exceptionsHandler.next(e, host);
|
|
15
|
+
return args;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
createExceptionLayerProxy(targetCallback, exceptionsHandler, type) {
|
|
20
|
+
return async (err, ...args) => {
|
|
21
|
+
try {
|
|
22
|
+
await targetCallback(err, ...args);
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
const host = new execution_host_1.ExecutionContextHost(args);
|
|
26
|
+
host.setType(type);
|
|
27
|
+
exceptionsHandler.next(e, host);
|
|
28
|
+
return args;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.VenokProxy = VenokProxy;
|
|
@@ -14,4 +14,4 @@ import { Abstract, Type } from "@venok/core/interfaces";
|
|
|
14
14
|
*
|
|
15
15
|
* @publicApi
|
|
16
16
|
*/
|
|
17
|
-
export declare function Catch(...exceptions: Array<Type
|
|
17
|
+
export declare function Catch(...exceptions: Array<Type | Abstract<any>>): ClassDecorator;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RuntimeException } from "./runtime.exception";
|
|
2
2
|
import { Abstract, Type } from "@venok/core/interfaces";
|
|
3
3
|
export declare class InvalidClassScopeException extends RuntimeException {
|
|
4
|
-
constructor(metatypeOrToken: Type
|
|
4
|
+
constructor(metatypeOrToken: Type | Abstract<any> | string | symbol);
|
|
5
5
|
}
|
package/errors/messages.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { ForwardReference } from "@venok/core/interfaces/modules";
|
|
|
3
3
|
import { Module } from "@venok/core/injector/module/module";
|
|
4
4
|
import { Type } from "@venok/core/interfaces";
|
|
5
5
|
export declare const UNKNOWN_DEPENDENCIES_MESSAGE: (type: string | symbol, unknownDependencyContext: InjectorDependencyContext, module: Module) => string;
|
|
6
|
-
export declare const UNDEFINED_FORWARDREF_MESSAGE: (scope: Type
|
|
6
|
+
export declare const UNDEFINED_FORWARDREF_MESSAGE: (scope: Type[]) => string;
|
|
7
7
|
export declare const INVALID_MODULE_MESSAGE: (parentModule: any, index: number, scope: any[]) => string;
|
|
8
8
|
export declare const USING_INVALID_CLASS_AS_A_MODULE_MESSAGE: (metatypeUsedAsAModule: Type | ForwardReference, scope: any[]) => string;
|
|
9
9
|
export declare const UNDEFINED_MODULE_MESSAGE: (parentModule: any, index: number, scope: any[]) => string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ArgumentsHost, ExceptionFilter, ExceptionFilterMetadata } from "@venok/core";
|
|
2
|
+
export declare class VenokExceptionsHandler {
|
|
3
|
+
private readonly exceptionsFilter;
|
|
4
|
+
private filters;
|
|
5
|
+
constructor(exceptionsFilter: ExceptionFilter);
|
|
6
|
+
next(exception: Error | any, host: ArgumentsHost): any;
|
|
7
|
+
setCustomFilters(filters: ExceptionFilterMetadata[]): void;
|
|
8
|
+
invokeCustomFilters<T = any>(exception: T, host: ArgumentsHost): boolean;
|
|
9
|
+
protected selectExceptionFilterMetadata<T = any>(filters: ExceptionFilterMetadata[], exception: T): ExceptionFilterMetadata | undefined;
|
|
10
|
+
}
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const filter_1 = require("@venok/core/exceptions/external/filter");
|
|
3
|
+
exports.VenokExceptionsHandler = void 0;
|
|
5
4
|
const invalid_exception_filter_exception_1 = require("@venok/core/errors/exceptions/invalid-exception-filter.exception");
|
|
6
5
|
const shared_helper_1 = require("@venok/core/helpers/shared.helper");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
super(...arguments);
|
|
6
|
+
class VenokExceptionsHandler {
|
|
7
|
+
constructor(exceptionsFilter) {
|
|
8
|
+
this.exceptionsFilter = exceptionsFilter;
|
|
11
9
|
this.filters = [];
|
|
12
10
|
}
|
|
13
11
|
next(exception, host) {
|
|
14
12
|
const result = this.invokeCustomFilters(exception, host);
|
|
15
13
|
if (result)
|
|
16
14
|
return result;
|
|
17
|
-
return
|
|
15
|
+
return this.exceptionsFilter.catch(exception, host);
|
|
18
16
|
}
|
|
19
17
|
setCustomFilters(filters) {
|
|
20
18
|
if (!Array.isArray(filters))
|
|
@@ -23,9 +21,14 @@ class ExternalExceptionsHandler extends filter_1.ExternalExceptionFilter {
|
|
|
23
21
|
}
|
|
24
22
|
invokeCustomFilters(exception, host) {
|
|
25
23
|
if ((0, shared_helper_1.isEmpty)(this.filters))
|
|
26
|
-
return
|
|
27
|
-
const filter =
|
|
28
|
-
|
|
24
|
+
return false;
|
|
25
|
+
const filter = this.selectExceptionFilterMetadata(this.filters, exception);
|
|
26
|
+
filter && filter.func(exception, host);
|
|
27
|
+
return !!filter;
|
|
28
|
+
}
|
|
29
|
+
selectExceptionFilterMetadata(filters, exception) {
|
|
30
|
+
return filters.find(({ exceptionMetatypes }) => !exceptionMetatypes.length ||
|
|
31
|
+
exceptionMetatypes.some((ExceptionMetaType) => exception instanceof ExceptionMetaType));
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
|
-
exports.
|
|
34
|
+
exports.VenokExceptionsHandler = VenokExceptionsHandler;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./zone"), exports);
|
|
18
|
+
__exportStar(require("./handler"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./handler"), exports);
|
|
18
|
+
__exportStar(require("./zone"), exports);
|
|
@@ -3,12 +3,12 @@ import { ContextCreator } from "@venok/core/context/creator";
|
|
|
3
3
|
import { Type } from "@venok/core/interfaces";
|
|
4
4
|
import { InstanceWrapper } from "@venok/core/injector/instance/wrapper";
|
|
5
5
|
import { ExceptionFilter } from "@venok/core/interfaces/features/exception-filter.interface";
|
|
6
|
-
export declare class
|
|
6
|
+
export declare class ExceptionFilterContextCreator extends ContextCreator {
|
|
7
7
|
private readonly container;
|
|
8
8
|
protected moduleContext: string;
|
|
9
9
|
constructor(container: VenokContainer);
|
|
10
10
|
createConcreteContext<T extends any[], R extends any[]>(metadata: T, contextId?: import("@venok/core/injector/instance/wrapper").ContextId, inquirerId?: string): R;
|
|
11
11
|
getFilterInstance(filter: Function | ExceptionFilter, contextId?: import("@venok/core/injector/instance/wrapper").ContextId, inquirerId?: string): ExceptionFilter | null;
|
|
12
|
-
getInstanceByMetatype(metatype: Type
|
|
13
|
-
reflectCatchExceptions(instance: ExceptionFilter): Type
|
|
12
|
+
getInstanceByMetatype(metatype: Type): InstanceWrapper | undefined;
|
|
13
|
+
reflectCatchExceptions(instance: ExceptionFilter): Type[];
|
|
14
14
|
}
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ExceptionFilterContextCreator = void 0;
|
|
4
4
|
const creator_1 = require("@venok/core/context/creator");
|
|
5
5
|
const constants_1 = require("@venok/core/injector/constants");
|
|
6
6
|
const shared_helper_1 = require("@venok/core/helpers/shared.helper");
|
|
7
7
|
const constants_2 = require("@venok/core/constants");
|
|
8
|
-
class
|
|
8
|
+
class ExceptionFilterContextCreator extends creator_1.ContextCreator {
|
|
9
9
|
constructor(container) {
|
|
10
10
|
super();
|
|
11
11
|
this.container = container;
|
|
12
12
|
}
|
|
13
13
|
createConcreteContext(metadata, contextId = constants_1.STATIC_CONTEXT, inquirerId) {
|
|
14
|
-
if ((0, shared_helper_1.isEmpty)(metadata))
|
|
14
|
+
if ((0, shared_helper_1.isEmpty)(metadata))
|
|
15
15
|
return [];
|
|
16
|
-
}
|
|
17
16
|
return metadata
|
|
18
17
|
.filter((instance) => instance && ((0, shared_helper_1.isFunction)(instance.catch) || instance.name))
|
|
19
18
|
.map((filter) => this.getFilterInstance(filter, contextId, inquirerId))
|
|
@@ -24,27 +23,21 @@ class BaseExceptionFilterContext extends creator_1.ContextCreator {
|
|
|
24
23
|
}));
|
|
25
24
|
}
|
|
26
25
|
getFilterInstance(filter, contextId = constants_1.STATIC_CONTEXT, inquirerId) {
|
|
27
|
-
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
if (isObject) {
|
|
26
|
+
if ("catch" in filter)
|
|
30
27
|
return filter;
|
|
31
|
-
}
|
|
32
28
|
const instanceWrapper = this.getInstanceByMetatype(filter);
|
|
33
|
-
if (!instanceWrapper)
|
|
29
|
+
if (!instanceWrapper)
|
|
34
30
|
return null;
|
|
35
|
-
}
|
|
36
31
|
const instanceHost = instanceWrapper.getInstanceByContextId(this.getContextId(contextId, instanceWrapper), inquirerId);
|
|
37
32
|
return instanceHost && instanceHost.instance;
|
|
38
33
|
}
|
|
39
34
|
getInstanceByMetatype(metatype) {
|
|
40
|
-
if (!this.moduleContext)
|
|
35
|
+
if (!this.moduleContext)
|
|
41
36
|
return;
|
|
42
|
-
}
|
|
43
37
|
const collection = this.container.getModules();
|
|
44
38
|
const moduleRef = collection.get(this.moduleContext);
|
|
45
|
-
if (!moduleRef)
|
|
39
|
+
if (!moduleRef)
|
|
46
40
|
return;
|
|
47
|
-
}
|
|
48
41
|
return moduleRef.injectables.get(metatype);
|
|
49
42
|
}
|
|
50
43
|
reflectCatchExceptions(instance) {
|
|
@@ -52,4 +45,4 @@ class BaseExceptionFilterContext extends creator_1.ContextCreator {
|
|
|
52
45
|
return Reflect.getMetadata(constants_2.FILTER_CATCH_EXCEPTIONS, prototype.constructor) || [];
|
|
53
46
|
}
|
|
54
47
|
}
|
|
55
|
-
exports.
|
|
48
|
+
exports.ExceptionFilterContextCreator = ExceptionFilterContextCreator;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { VenokContainer } from "@venok/core/injector/container";
|
|
2
|
+
import { ApplicationConfig } from "@venok/core/application/config";
|
|
3
|
+
import { ExceptionFilterContextCreator } from "@venok/core/filters/context-creator";
|
|
4
|
+
import { ExceptionFilter } from "@venok/core/interfaces/features/exception-filter.interface";
|
|
5
|
+
import { VenokExceptionsHandler } from "@venok/core/exceptions/handler";
|
|
6
|
+
export declare class VenokExceptionFilterContext extends ExceptionFilterContextCreator {
|
|
7
|
+
private readonly config?;
|
|
8
|
+
constructor(container: VenokContainer, config?: ApplicationConfig | undefined);
|
|
9
|
+
create(instance: object, callback: (...args: any) => void, module: string, contextId?: import("@venok/core/injector/instance/wrapper").ContextId, inquirerId?: string): VenokExceptionsHandler;
|
|
10
|
+
getExceptionFilter(): ExceptionFilter;
|
|
11
|
+
getGlobalMetadata<T extends any[]>(contextId?: import("@venok/core/injector/instance/wrapper").ContextId, inquirerId?: string): T;
|
|
12
|
+
}
|
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
3
|
+
exports.VenokExceptionFilterContext = void 0;
|
|
4
|
+
const context_creator_1 = require("@venok/core/filters/context-creator");
|
|
5
5
|
const constants_1 = require("@venok/core/injector/constants");
|
|
6
6
|
const constants_2 = require("@venok/core/constants");
|
|
7
7
|
const shared_helper_1 = require("@venok/core/helpers/shared.helper");
|
|
8
|
-
const handler_1 = require("@venok/core/exceptions/
|
|
9
|
-
|
|
8
|
+
const handler_1 = require("@venok/core/exceptions/handler");
|
|
9
|
+
const filter_1 = require("@venok/core/filters/filter");
|
|
10
|
+
class VenokExceptionFilterContext extends context_creator_1.ExceptionFilterContextCreator {
|
|
10
11
|
constructor(container, config) {
|
|
11
12
|
super(container);
|
|
12
13
|
this.config = config;
|
|
13
14
|
}
|
|
14
15
|
create(instance, callback, module, contextId = constants_1.STATIC_CONTEXT, inquirerId) {
|
|
15
16
|
this.moduleContext = module;
|
|
16
|
-
const exceptionHandler = new handler_1.
|
|
17
|
+
const exceptionHandler = new handler_1.VenokExceptionsHandler(this.getExceptionFilter());
|
|
17
18
|
const filters = this.createContext(instance, callback, constants_2.EXCEPTION_FILTERS_METADATA, contextId, inquirerId);
|
|
18
19
|
if ((0, shared_helper_1.isEmpty)(filters))
|
|
19
20
|
return exceptionHandler;
|
|
20
21
|
exceptionHandler.setCustomFilters(filters.reverse());
|
|
21
22
|
return exceptionHandler;
|
|
22
23
|
}
|
|
24
|
+
getExceptionFilter() {
|
|
25
|
+
return new filter_1.VenokExceptionFilter();
|
|
26
|
+
}
|
|
23
27
|
getGlobalMetadata(contextId = constants_1.STATIC_CONTEXT, inquirerId) {
|
|
24
28
|
if (!this.config)
|
|
25
29
|
return [];
|
|
@@ -34,4 +38,4 @@ class ExternalExceptionFilterContext extends filter_context_1.BaseExceptionFilte
|
|
|
34
38
|
return globalFilters.concat(scopedFilters);
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
|
-
exports.
|
|
41
|
+
exports.VenokExceptionFilterContext = VenokExceptionFilterContext;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ArgumentsHost } from "@venok/core/interfaces/context/arguments-host.interface";
|
|
2
|
+
import { ExceptionFilter } from "@venok/core/interfaces/features/exception-filter.interface";
|
|
3
|
+
export declare class VenokExceptionFilter<T = any, R = any> implements ExceptionFilter {
|
|
4
|
+
private static readonly logger;
|
|
5
|
+
catch(exception: T, host: ArgumentsHost): void;
|
|
6
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VenokExceptionFilter = void 0;
|
|
4
|
+
const logger_service_1 = require("@venok/core/services/logger.service");
|
|
5
|
+
const exceptions_1 = require("@venok/core/errors/exceptions");
|
|
6
|
+
class VenokExceptionFilter {
|
|
7
|
+
catch(exception, host) {
|
|
8
|
+
if (exception instanceof exceptions_1.RuntimeException) {
|
|
9
|
+
return VenokExceptionFilter.logger.error(exception.what(), exception.stack);
|
|
10
|
+
}
|
|
11
|
+
if (exception instanceof Error)
|
|
12
|
+
return VenokExceptionFilter.logger.error(exception.message, exception.stack);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.VenokExceptionFilter = VenokExceptionFilter;
|
|
16
|
+
VenokExceptionFilter.logger = new logger_service_1.Logger("ExternalExceptionsHandler");
|
package/filters/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./context"), exports);
|
|
18
|
+
__exportStar(require("./context-creator"), exports);
|
|
19
|
+
__exportStar(require("./filter"), exports);
|
|
@@ -12,6 +12,6 @@ export declare class GuardsContextCreator extends ContextCreator {
|
|
|
12
12
|
create(instance: object, callback: (...args: unknown[]) => unknown, module: string, contextId?: import("@venok/core/injector/instance/wrapper").ContextId, inquirerId?: string): CanActivate[];
|
|
13
13
|
createConcreteContext<T extends unknown[], R extends unknown[]>(metadata: T, contextId?: import("@venok/core/injector/instance/wrapper").ContextId, inquirerId?: string): R;
|
|
14
14
|
getGuardInstance(metatype: Function | CanActivate, contextId?: import("@venok/core/injector/instance/wrapper").ContextId, inquirerId?: string): CanActivate | null;
|
|
15
|
-
getInstanceByMetatype(metatype: Type
|
|
15
|
+
getInstanceByMetatype(metatype: Type): InstanceWrapper | undefined;
|
|
16
16
|
getGlobalMetadata<T extends unknown[]>(contextId?: import("@venok/core/injector/instance/wrapper").ContextId, inquirerId?: string): T;
|
|
17
17
|
}
|