@venok/integration 2.0.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/dist/configurable/constants.js +26 -0
- package/dist/configurable/helpers/generate-options-injection-token.helper.js +24 -0
- package/dist/configurable/helpers/get-injection-providers.helper.js +34 -0
- package/dist/configurable/helpers/index.js +3 -0
- package/dist/configurable/index.js +3 -0
- package/dist/configurable/module.builder.js +169 -0
- package/dist/exceptions/index.js +3 -0
- package/dist/exceptions/invalid-middleware-configuration.exception.js +27 -0
- package/dist/exceptions/invalid-middleware.exception.js +27 -0
- package/dist/exceptions/messages.js +22 -0
- package/dist/index.d.ts +367 -0
- package/dist/index.js +8 -0
- package/dist/integration.module.js +29 -0
- package/dist/interfaces/configurable/async-options.interface.js +0 -0
- package/dist/interfaces/configurable/cls.interface.js +0 -0
- package/dist/interfaces/configurable/host.interface.js +0 -0
- package/dist/interfaces/configurable/index.js +4 -0
- package/dist/interfaces/index.js +4 -0
- package/dist/interfaces/middleware/configuration.interface.js +0 -0
- package/dist/interfaces/middleware/index.js +3 -0
- package/dist/interfaces/middleware/middleware.interface.js +0 -0
- package/dist/interfaces/services/discovery.interface.js +0 -0
- package/dist/interfaces/services/explorer.interface.js +0 -0
- package/dist/interfaces/services/index.js +3 -0
- package/dist/middleware/container.js +59 -0
- package/dist/middleware/index.js +4 -0
- package/dist/middleware/resolver.js +42 -0
- package/dist/middleware/service.js +134 -0
- package/dist/services/discovery.service.js +55 -0
- package/dist/services/explorer.service.js +123 -0
- package/dist/services/index.js +3 -0
- package/package.json +40 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyMetadataTS = (k, v) => {
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
13
|
+
return Reflect.metadata(k, v);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// packages/integration/src/configurable/constants.ts
|
|
17
|
+
var DEFAULT_METHOD_KEY = "register";
|
|
18
|
+
var DEFAULT_FACTORY_CLASS_METHOD_KEY = "create";
|
|
19
|
+
var ASYNC_METHOD_SUFFIX = "Async";
|
|
20
|
+
var CONFIGURABLE_MODULE_ID = "CONFIGURABLE_MODULE_ID";
|
|
21
|
+
export {
|
|
22
|
+
DEFAULT_METHOD_KEY,
|
|
23
|
+
DEFAULT_FACTORY_CLASS_METHOD_KEY,
|
|
24
|
+
CONFIGURABLE_MODULE_ID,
|
|
25
|
+
ASYNC_METHOD_SUFFIX
|
|
26
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyMetadataTS = (k, v) => {
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
13
|
+
return Reflect.metadata(k, v);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// packages/integration/src/configurable/helpers/generate-options-injection-token.helper.ts
|
|
17
|
+
import { randomStringGenerator } from "@venok/core";
|
|
18
|
+
function generateOptionsInjectionToken() {
|
|
19
|
+
const hash = randomStringGenerator();
|
|
20
|
+
return `CONFIGURABLE_MODULE_OPTIONS[${hash}]`;
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
generateOptionsInjectionToken
|
|
24
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyMetadataTS = (k, v) => {
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
13
|
+
return Reflect.metadata(k, v);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// packages/integration/src/configurable/helpers/get-injection-providers.helper.ts
|
|
17
|
+
import { isUndefined } from "@venok/core";
|
|
18
|
+
function isOptionalFactoryDependency(value) {
|
|
19
|
+
return !isUndefined(value.token) && !isUndefined(value.optional) && !value.prototype;
|
|
20
|
+
}
|
|
21
|
+
var mapInjectToTokens = (t) => isOptionalFactoryDependency(t) ? t.token : t;
|
|
22
|
+
function getInjectionProviders(providers, tokens) {
|
|
23
|
+
const result = [];
|
|
24
|
+
let search = tokens.map(mapInjectToTokens);
|
|
25
|
+
while (search.length > 0) {
|
|
26
|
+
const match = (providers ?? []).filter((p) => !result.includes(p) && (search.includes(p) || search.includes(p?.provide)));
|
|
27
|
+
result.push(...match);
|
|
28
|
+
search = match.filter((p) => p?.inject).map((p) => p.inject).flat().map(mapInjectToTokens);
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
getInjectionProviders
|
|
34
|
+
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyMetadataTS = (k, v) => {
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
13
|
+
return Reflect.metadata(k, v);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// packages/integration/src/configurable/module.builder.ts
|
|
17
|
+
import { Logger, randomStringGenerator } from "@venok/core";
|
|
18
|
+
import { generateOptionsInjectionToken } from "../configurable/helpers/generate-options-injection-token.helper.js";
|
|
19
|
+
import { ASYNC_METHOD_SUFFIX, CONFIGURABLE_MODULE_ID, DEFAULT_FACTORY_CLASS_METHOD_KEY, DEFAULT_METHOD_KEY } from "../configurable/constants.js";
|
|
20
|
+
import { getInjectionProviders } from "../configurable/helpers/get-injection-providers.helper.js";
|
|
21
|
+
|
|
22
|
+
class ConfigurableModuleBuilder {
|
|
23
|
+
options;
|
|
24
|
+
staticMethodKey;
|
|
25
|
+
factoryClassMethodKey;
|
|
26
|
+
extras;
|
|
27
|
+
transformModuleDefinition;
|
|
28
|
+
logger = new Logger(ConfigurableModuleBuilder.name);
|
|
29
|
+
constructor(options = {}, parentBuilder) {
|
|
30
|
+
this.options = options;
|
|
31
|
+
if (parentBuilder) {
|
|
32
|
+
this.staticMethodKey = parentBuilder.staticMethodKey;
|
|
33
|
+
this.factoryClassMethodKey = parentBuilder.factoryClassMethodKey;
|
|
34
|
+
this.transformModuleDefinition = parentBuilder.transformModuleDefinition;
|
|
35
|
+
this.extras = parentBuilder.extras;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
setExtras(extras, transformDefinition = (def) => def) {
|
|
39
|
+
const builder = new ConfigurableModuleBuilder(this.options, this);
|
|
40
|
+
builder.extras = extras;
|
|
41
|
+
builder.transformModuleDefinition = transformDefinition;
|
|
42
|
+
return builder;
|
|
43
|
+
}
|
|
44
|
+
setClassMethodName(key) {
|
|
45
|
+
const builder = new ConfigurableModuleBuilder(this.options, this);
|
|
46
|
+
builder.staticMethodKey = key;
|
|
47
|
+
return builder;
|
|
48
|
+
}
|
|
49
|
+
setFactoryMethodName(key) {
|
|
50
|
+
const builder = new ConfigurableModuleBuilder(this.options, this);
|
|
51
|
+
builder.factoryClassMethodKey = key;
|
|
52
|
+
return builder;
|
|
53
|
+
}
|
|
54
|
+
build() {
|
|
55
|
+
this.staticMethodKey ??= DEFAULT_METHOD_KEY;
|
|
56
|
+
this.factoryClassMethodKey ??= DEFAULT_FACTORY_CLASS_METHOD_KEY;
|
|
57
|
+
this.options.optionsInjectionToken ??= this.options.moduleName ? this.constructInjectionTokenString() : generateOptionsInjectionToken();
|
|
58
|
+
this.transformModuleDefinition ??= (definition) => definition;
|
|
59
|
+
return {
|
|
60
|
+
ConfigurableModuleClass: this.createConfigurableModuleCls(),
|
|
61
|
+
MODULE_OPTIONS_TOKEN: this.options.optionsInjectionToken,
|
|
62
|
+
ASYNC_OPTIONS_TYPE: this.createTypeProxy("ASYNC_OPTIONS_TYPE"),
|
|
63
|
+
OPTIONS_TYPE: this.createTypeProxy("OPTIONS_TYPE")
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
constructInjectionTokenString() {
|
|
67
|
+
const moduleNameInSnakeCase = (this.options.moduleName ?? randomStringGenerator()).trim().split(/(?=[A-Z])/).join("_").toUpperCase();
|
|
68
|
+
return `${moduleNameInSnakeCase}_MODULE_OPTIONS`;
|
|
69
|
+
}
|
|
70
|
+
createConfigurableModuleCls() {
|
|
71
|
+
const self = this;
|
|
72
|
+
const asyncMethodKey = this.staticMethodKey + ASYNC_METHOD_SUFFIX;
|
|
73
|
+
|
|
74
|
+
class InternalModuleClass {
|
|
75
|
+
static [self.staticMethodKey](options) {
|
|
76
|
+
const providers = [
|
|
77
|
+
{
|
|
78
|
+
provide: self.options.optionsInjectionToken,
|
|
79
|
+
useValue: this.omitExtras(options, self.extras)
|
|
80
|
+
}
|
|
81
|
+
];
|
|
82
|
+
if (self.options.alwaysTransient) {
|
|
83
|
+
providers.push({
|
|
84
|
+
provide: CONFIGURABLE_MODULE_ID,
|
|
85
|
+
useValue: randomStringGenerator()
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return self.transformModuleDefinition({
|
|
89
|
+
module: this,
|
|
90
|
+
providers
|
|
91
|
+
}, {
|
|
92
|
+
...self.extras,
|
|
93
|
+
...options
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
static [asyncMethodKey](options) {
|
|
97
|
+
const providers = this.createAsyncProviders(options);
|
|
98
|
+
if (self.options.alwaysTransient) {
|
|
99
|
+
providers.push({
|
|
100
|
+
provide: CONFIGURABLE_MODULE_ID,
|
|
101
|
+
useValue: randomStringGenerator()
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return self.transformModuleDefinition({
|
|
105
|
+
module: this,
|
|
106
|
+
imports: options.imports || [],
|
|
107
|
+
providers
|
|
108
|
+
}, {
|
|
109
|
+
...self.extras,
|
|
110
|
+
...options
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
static omitExtras(input, extras) {
|
|
114
|
+
if (!extras)
|
|
115
|
+
return input;
|
|
116
|
+
const moduleOptions = {};
|
|
117
|
+
const extrasKeys = Object.keys(extras);
|
|
118
|
+
Object.keys(input).filter((key) => !extrasKeys.includes(key)).forEach((key) => {
|
|
119
|
+
moduleOptions[key] = input[key];
|
|
120
|
+
});
|
|
121
|
+
return moduleOptions;
|
|
122
|
+
}
|
|
123
|
+
static createAsyncProviders(options) {
|
|
124
|
+
if (options.useExisting || options.useFactory) {
|
|
125
|
+
if (options.inject && options.provideInjectionTokensFrom) {
|
|
126
|
+
return [
|
|
127
|
+
this.createAsyncOptionsProvider(options),
|
|
128
|
+
...getInjectionProviders(options.provideInjectionTokensFrom, options.inject)
|
|
129
|
+
];
|
|
130
|
+
}
|
|
131
|
+
return [this.createAsyncOptionsProvider(options)];
|
|
132
|
+
}
|
|
133
|
+
return [
|
|
134
|
+
this.createAsyncOptionsProvider(options),
|
|
135
|
+
{
|
|
136
|
+
provide: options.useClass,
|
|
137
|
+
useClass: options.useClass
|
|
138
|
+
}
|
|
139
|
+
];
|
|
140
|
+
}
|
|
141
|
+
static createAsyncOptionsProvider(options) {
|
|
142
|
+
if (options.useFactory) {
|
|
143
|
+
return {
|
|
144
|
+
provide: self.options.optionsInjectionToken,
|
|
145
|
+
useFactory: options.useFactory,
|
|
146
|
+
inject: options.inject || []
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
provide: self.options.optionsInjectionToken,
|
|
151
|
+
useFactory: async (optionsFactory) => await optionsFactory[self.factoryClassMethodKey](),
|
|
152
|
+
inject: [options.useExisting || options.useClass]
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return InternalModuleClass;
|
|
157
|
+
}
|
|
158
|
+
createTypeProxy(typeName) {
|
|
159
|
+
const proxy = new Proxy({}, {
|
|
160
|
+
get: () => {
|
|
161
|
+
throw new Error(`"${typeName}" is not supposed to be used as a value.`);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
return proxy;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
export {
|
|
168
|
+
ConfigurableModuleBuilder
|
|
169
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyMetadataTS = (k, v) => {
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
13
|
+
return Reflect.metadata(k, v);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// packages/integration/src/exceptions/invalid-middleware-configuration.exception.ts
|
|
17
|
+
import { RuntimeException } from "@venok/core";
|
|
18
|
+
import { INVALID_MIDDLEWARE_CONFIGURATION } from "../exceptions/messages.js";
|
|
19
|
+
|
|
20
|
+
class InvalidMiddlewareConfigurationException extends RuntimeException {
|
|
21
|
+
constructor() {
|
|
22
|
+
super(INVALID_MIDDLEWARE_CONFIGURATION);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
InvalidMiddlewareConfigurationException
|
|
27
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyMetadataTS = (k, v) => {
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
13
|
+
return Reflect.metadata(k, v);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// packages/integration/src/exceptions/invalid-middleware.exception.ts
|
|
17
|
+
import { RuntimeException } from "@venok/core";
|
|
18
|
+
import { INVALID_MIDDLEWARE_MESSAGE } from "../exceptions/messages.js";
|
|
19
|
+
|
|
20
|
+
class InvalidMiddlewareException extends RuntimeException {
|
|
21
|
+
constructor(name) {
|
|
22
|
+
super(INVALID_MIDDLEWARE_MESSAGE`${name}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
InvalidMiddlewareException
|
|
27
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyMetadataTS = (k, v) => {
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
13
|
+
return Reflect.metadata(k, v);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// packages/integration/src/exceptions/messages.ts
|
|
17
|
+
var INVALID_MIDDLEWARE_CONFIGURATION = `An invalid middleware configuration has been passed inside the module 'configure()' method.`;
|
|
18
|
+
var INVALID_MIDDLEWARE_MESSAGE = (text, name) => `The middleware doesn't provide the 'use' method (${name})`;
|
|
19
|
+
export {
|
|
20
|
+
INVALID_MIDDLEWARE_MESSAGE,
|
|
21
|
+
INVALID_MIDDLEWARE_CONFIGURATION
|
|
22
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thanks for using Venloc Venok <3
|
|
3
|
+
* https://github.com/venloc-tech/svm
|
|
4
|
+
*/
|
|
5
|
+
import { DynamicModule as DynamicModule$1 } from '@venok/core/index.js';
|
|
6
|
+
import * as _venok_core from '@venok/core';
|
|
7
|
+
import { ModuleMetadata, Type, FactoryProvider, Provider, DynamicModule, Logger, ExternalContextOptions, VenokExceptionFilterContext, VenokContextCreator, InjectionToken, InstanceWrapper, Injector, CoreModule, VenokContainer, ModulesContainer, CustomDecorator, Reflector, MetadataScanner, VenokParamsFactoryInterface } from '@venok/core';
|
|
8
|
+
|
|
9
|
+
declare const DEFAULT_METHOD_KEY = "register";
|
|
10
|
+
declare const DEFAULT_FACTORY_CLASS_METHOD_KEY = "create";
|
|
11
|
+
declare const ASYNC_METHOD_SUFFIX = "Async";
|
|
12
|
+
declare const CONFIGURABLE_MODULE_ID = "CONFIGURABLE_MODULE_ID";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Interface that must be implemented by the module options factory class.
|
|
16
|
+
* Method key varies depending on the "FactoryClassMethodKey" type argument.
|
|
17
|
+
*
|
|
18
|
+
* @publicApi
|
|
19
|
+
*/
|
|
20
|
+
type ConfigurableModuleOptionsFactory<ModuleOptions, FactoryClassMethodKey extends string> = Record<`${FactoryClassMethodKey}`, () => Promise<ModuleOptions> | ModuleOptions>;
|
|
21
|
+
/**
|
|
22
|
+
* Interface that represents the module async options object
|
|
23
|
+
* Factory method name varies depending on the "FactoryClassMethodKey" type argument.
|
|
24
|
+
*
|
|
25
|
+
* @publicApi
|
|
26
|
+
*/
|
|
27
|
+
interface ConfigurableModuleAsyncOptions<ModuleOptions, FactoryClassMethodKey extends string = typeof DEFAULT_FACTORY_CLASS_METHOD_KEY> extends Pick<ModuleMetadata, "imports"> {
|
|
28
|
+
/**
|
|
29
|
+
* Injection token resolving to an existing provider. The provider must implement
|
|
30
|
+
* the corresponding interface.
|
|
31
|
+
*/
|
|
32
|
+
useExisting?: Type<ConfigurableModuleOptionsFactory<ModuleOptions, FactoryClassMethodKey>>;
|
|
33
|
+
/**
|
|
34
|
+
* Injection token resolving to a class that will be instantiated as a provider.
|
|
35
|
+
* The class must implement the corresponding interface.
|
|
36
|
+
*/
|
|
37
|
+
useClass?: Type<ConfigurableModuleOptionsFactory<ModuleOptions, FactoryClassMethodKey>>;
|
|
38
|
+
/**
|
|
39
|
+
* Function returning options (or a Promise resolving to options) to configure the
|
|
40
|
+
* cache module.
|
|
41
|
+
*/
|
|
42
|
+
useFactory?: (...args: any[]) => Promise<ModuleOptions> | ModuleOptions;
|
|
43
|
+
/**
|
|
44
|
+
* Dependencies that a Factory may inject.
|
|
45
|
+
*/
|
|
46
|
+
inject?: FactoryProvider["inject"];
|
|
47
|
+
/**
|
|
48
|
+
* List of parent module's providers that will be filtered to only provide necessary
|
|
49
|
+
* providers for the 'inject' array
|
|
50
|
+
* useful to pass options to nested async modules
|
|
51
|
+
*/
|
|
52
|
+
provideInjectionTokensFrom?: Provider[];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Class that represents a blueprint/prototype for a configurable Nest module.
|
|
57
|
+
* This class provides static methods for constructing dynamic modules. Their names
|
|
58
|
+
* can be controlled through the "MethodKey" type argument.
|
|
59
|
+
*
|
|
60
|
+
* @publicApi
|
|
61
|
+
*/
|
|
62
|
+
type ConfigurableModuleCls<ModuleOptions, MethodKey extends string = typeof DEFAULT_METHOD_KEY, FactoryClassMethodKey extends string = typeof DEFAULT_FACTORY_CLASS_METHOD_KEY, ExtraModuleDefinitionOptions = object> = {
|
|
63
|
+
new (): any;
|
|
64
|
+
} & Record<`${MethodKey}`, (options: ModuleOptions & Partial<ExtraModuleDefinitionOptions>) => DynamicModule> & Record<`${MethodKey}Async`, (options: ConfigurableModuleAsyncOptions<ModuleOptions, FactoryClassMethodKey> & Partial<ExtraModuleDefinitionOptions>) => DynamicModule>;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Configurable module host. See properties for more details
|
|
68
|
+
*
|
|
69
|
+
* @publicApi
|
|
70
|
+
*/
|
|
71
|
+
interface ConfigurableModuleHost<ModuleOptions = Record<string, unknown>, MethodKey extends string = string, FactoryClassMethodKey extends string = string, ExtraModuleDefinitionOptions = object> {
|
|
72
|
+
/**
|
|
73
|
+
* Class that represents a blueprint/prototype for a configurable Nest module.
|
|
74
|
+
* This class provides static methods for constructing dynamic modules. Their names
|
|
75
|
+
* can be controlled through the "MethodKey" type argument.
|
|
76
|
+
*
|
|
77
|
+
* Your module class should inherit from this class to make the static methods available.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* @Module({})
|
|
82
|
+
* class IntegrationModule extends ConfigurableModuleCls {
|
|
83
|
+
* // ...
|
|
84
|
+
* }
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
ConfigurableModuleClass: ConfigurableModuleCls<ModuleOptions, MethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
|
|
88
|
+
/**
|
|
89
|
+
* Module options provider token. Can be used to inject the "options object" to
|
|
90
|
+
* providers registered within the host module.
|
|
91
|
+
*/
|
|
92
|
+
MODULE_OPTIONS_TOKEN: string | symbol;
|
|
93
|
+
/**
|
|
94
|
+
* Can be used to auto-infer the compound "async module options" type.
|
|
95
|
+
* Note: this property is not supposed to be used as a value.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* @Module({})
|
|
100
|
+
* class IntegrationModule extends ConfigurableModuleCls {
|
|
101
|
+
* static module = initializer(IntegrationModule);
|
|
102
|
+
*
|
|
103
|
+
* static registerAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule {
|
|
104
|
+
* return super.registerAsync(options);
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
ASYNC_OPTIONS_TYPE: ConfigurableModuleAsyncOptions<ModuleOptions, FactoryClassMethodKey> & Partial<ExtraModuleDefinitionOptions>;
|
|
109
|
+
/**
|
|
110
|
+
* Can be used to auto-infer the compound "module options" type (options interface + extra module definition options).
|
|
111
|
+
* Note: this property is not supposed to be used as a value.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* @Module({})
|
|
116
|
+
* class IntegrationModule extends ConfigurableModuleCls {
|
|
117
|
+
* static module = initializer(IntegrationModule);
|
|
118
|
+
*
|
|
119
|
+
* static register(options: typeof OPTIONS_TYPE): DynamicModule {
|
|
120
|
+
* return super.register(options);
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
OPTIONS_TYPE: ModuleOptions & Partial<ExtraModuleDefinitionOptions>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @publicApi
|
|
129
|
+
*/
|
|
130
|
+
interface ConfigurableModuleBuilderOptions {
|
|
131
|
+
/**
|
|
132
|
+
* Specified what injection token should be used for the module options provider.
|
|
133
|
+
* By default, an auto-generated UUID will be used.
|
|
134
|
+
*/
|
|
135
|
+
optionsInjectionToken?: string | symbol;
|
|
136
|
+
/**
|
|
137
|
+
* By default, a UUID will be used as a module options provider token.
|
|
138
|
+
* Explicitly specifying the "moduleName" will instruct the "ConfigurableModuleBuilder"
|
|
139
|
+
* to use a more descriptive provider token.
|
|
140
|
+
*
|
|
141
|
+
* For example, if `moduleName: "Cache"` then auto-generated provider token will be "CACHE_MODULE_OPTIONS".
|
|
142
|
+
*/
|
|
143
|
+
moduleName?: string;
|
|
144
|
+
/**
|
|
145
|
+
* Indicates whether module should always be "transient", meaning,
|
|
146
|
+
* every time you call the static method to construct a dynamic module,
|
|
147
|
+
* regardless of what arguments you pass in, a new "unique" module will be created.
|
|
148
|
+
*
|
|
149
|
+
* @default false
|
|
150
|
+
*/
|
|
151
|
+
alwaysTransient?: boolean;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Factory that lets you create configurable module and
|
|
155
|
+
* provides a way to reduce the majority of dynamic module boilerplate.
|
|
156
|
+
*
|
|
157
|
+
* @publicApi
|
|
158
|
+
*/
|
|
159
|
+
declare class ConfigurableModuleBuilder<ModuleOptions, StaticMethodKey extends string = typeof DEFAULT_METHOD_KEY, FactoryClassMethodKey extends string = typeof DEFAULT_FACTORY_CLASS_METHOD_KEY, ExtraModuleDefinitionOptions = object> {
|
|
160
|
+
protected readonly options: ConfigurableModuleBuilderOptions;
|
|
161
|
+
protected staticMethodKey: StaticMethodKey;
|
|
162
|
+
protected factoryClassMethodKey: FactoryClassMethodKey;
|
|
163
|
+
protected extras: ExtraModuleDefinitionOptions;
|
|
164
|
+
protected transformModuleDefinition: (definition: DynamicModule$1, extraOptions: ExtraModuleDefinitionOptions) => DynamicModule$1;
|
|
165
|
+
protected readonly logger: Logger;
|
|
166
|
+
constructor(options?: ConfigurableModuleBuilderOptions, parentBuilder?: ConfigurableModuleBuilder<ModuleOptions>);
|
|
167
|
+
/**
|
|
168
|
+
* Registers the "extras" object (a set of extra options that can be used to modify the dynamic module definition).
|
|
169
|
+
* Values you specify within the "extras" object will be used as default values (that can be overridden by module consumers).
|
|
170
|
+
*
|
|
171
|
+
* This method also applies the so-called "module definition transform function" that takes the auto-generated
|
|
172
|
+
* dynamic module object ("DynamicModule") and the actual consumer "extras" object as input parameters.
|
|
173
|
+
* The "extras" object consists of values explicitly specified by module consumers and default values.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* .setExtras<{ isGlobal?: boolean }>({ isGlobal: false }, (definition, extras) =>
|
|
178
|
+
* ({ ...definition, global: extras.isGlobal })
|
|
179
|
+
* )
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
setExtras<ExtraModuleDefinitionOptions>(extras: ExtraModuleDefinitionOptions, transformDefinition?: (definition: DynamicModule$1, extras: ExtraModuleDefinitionOptions) => DynamicModule$1): ConfigurableModuleBuilder<ModuleOptions, StaticMethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
|
|
183
|
+
/**
|
|
184
|
+
* Dynamic module must expose public static methods that let you pass in
|
|
185
|
+
* configuration parameters (control the module's behavior from the outside).
|
|
186
|
+
* Some frequently used names that you may have seen in other module are:
|
|
187
|
+
* "forRoot", "forFeature", "register", "configure".
|
|
188
|
+
*
|
|
189
|
+
* This method "setClassMethodName" lets you specify the name of the
|
|
190
|
+
* method that will be auto-generated.
|
|
191
|
+
*
|
|
192
|
+
* @param key name of the method
|
|
193
|
+
*/
|
|
194
|
+
setClassMethodName<StaticMethodKey extends string>(key: StaticMethodKey): ConfigurableModuleBuilder<ModuleOptions, StaticMethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
|
|
195
|
+
/**
|
|
196
|
+
* Asynchronously configured module (that rely on other module, i.e. "ConfigModule")
|
|
197
|
+
* let you pass the configuration factory class that will be registered and instantiated as a provider.
|
|
198
|
+
* This provider then will be used to retrieve the module's configuration. To provide the configuration,
|
|
199
|
+
* the corresponding factory method must be implemented.
|
|
200
|
+
*
|
|
201
|
+
* This method ("setFactoryMethodName") lets you control what method name will have to be
|
|
202
|
+
* implemented by the config factory (default is "create").
|
|
203
|
+
*
|
|
204
|
+
* @param key name of the method
|
|
205
|
+
*/
|
|
206
|
+
setFactoryMethodName<FactoryClassMethodKey extends string>(key: FactoryClassMethodKey): ConfigurableModuleBuilder<ModuleOptions, StaticMethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
|
|
207
|
+
/**
|
|
208
|
+
* Returns an object consisting of multiple properties that lets you
|
|
209
|
+
* easily construct dynamic configurable module. See "ConfigurableModuleHost" interface for more details.
|
|
210
|
+
*/
|
|
211
|
+
build(): ConfigurableModuleHost<ModuleOptions, StaticMethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
|
|
212
|
+
private constructInjectionTokenString;
|
|
213
|
+
private createConfigurableModuleCls;
|
|
214
|
+
private createTypeProxy;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
interface BaseMiddlewareConfiguration<MiddlewareType = any, ToType = any> {
|
|
218
|
+
middleware: MiddlewareType;
|
|
219
|
+
to: (string | Type | ToType)[];
|
|
220
|
+
exclude?: (string | ToType)[];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
*
|
|
225
|
+
* @publicApi
|
|
226
|
+
*/
|
|
227
|
+
interface VenokMiddleware {
|
|
228
|
+
use(...args: any[]): any;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* @publicApi
|
|
233
|
+
*/
|
|
234
|
+
interface FilterByInclude {
|
|
235
|
+
/**
|
|
236
|
+
* List of modules to include (whitelist) into the discovery process.
|
|
237
|
+
*/
|
|
238
|
+
include?: Function[];
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* @publicApi
|
|
242
|
+
*/
|
|
243
|
+
interface FilterByMetadataKey {
|
|
244
|
+
/**
|
|
245
|
+
* A key to filter controllers and providers by.
|
|
246
|
+
* Only instance wrappers with the specified metadata key will be returned.
|
|
247
|
+
*/
|
|
248
|
+
metadataKey?: string;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* @publicApi
|
|
252
|
+
*/
|
|
253
|
+
type DiscoveryOptions = FilterByInclude | FilterByMetadataKey;
|
|
254
|
+
|
|
255
|
+
type ExplorerSettings = Partial<{
|
|
256
|
+
contextType: string;
|
|
257
|
+
isRequestScopeSupported: boolean;
|
|
258
|
+
requestContextArgIndex: number;
|
|
259
|
+
options: ExternalContextOptions;
|
|
260
|
+
exceptionsFilterClass: typeof VenokExceptionFilterContext;
|
|
261
|
+
contextCreatorClass: typeof VenokContextCreator;
|
|
262
|
+
metadataKey: string;
|
|
263
|
+
}>;
|
|
264
|
+
|
|
265
|
+
declare class MiddlewareContainer {
|
|
266
|
+
private readonly middleware;
|
|
267
|
+
private readonly configurationSets;
|
|
268
|
+
getMiddlewareCollection(moduleKey: string): Map<InjectionToken, InstanceWrapper>;
|
|
269
|
+
getConfigurations(): Map<string, Set<BaseMiddlewareConfiguration>>;
|
|
270
|
+
insertConfig(configList: BaseMiddlewareConfiguration[], moduleKey: string): void;
|
|
271
|
+
private getTargetConfig;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
declare class MiddlewareResolver {
|
|
275
|
+
private readonly middlewareContainer;
|
|
276
|
+
private readonly injector;
|
|
277
|
+
constructor(middlewareContainer: MiddlewareContainer, injector: Injector);
|
|
278
|
+
resolveInstances(moduleRef: CoreModule, moduleName: string): Promise<void>;
|
|
279
|
+
private resolveMiddlewareInstance;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
type VenokContextCallback = (...args: any[]) => void | Promise<void>;
|
|
283
|
+
declare abstract class MiddlewareService<MiddlewareConfiguration extends BaseMiddlewareConfiguration> {
|
|
284
|
+
readonly container: VenokContainer;
|
|
285
|
+
protected index: number;
|
|
286
|
+
protected type: string;
|
|
287
|
+
protected readonly exceptionsFilter: VenokExceptionFilterContext;
|
|
288
|
+
private readonly venokProxy;
|
|
289
|
+
private readonly exceptionFiltersCache;
|
|
290
|
+
protected readonly logger: Logger;
|
|
291
|
+
protected readonly injector: Injector;
|
|
292
|
+
protected readonly middlewareContainer: MiddlewareContainer;
|
|
293
|
+
protected readonly resolver: MiddlewareResolver;
|
|
294
|
+
constructor(container: VenokContainer);
|
|
295
|
+
explore(middlewareClass: any): Promise<void>;
|
|
296
|
+
private loadConfiguration;
|
|
297
|
+
protected abstract getMiddlewareBuilder(): any;
|
|
298
|
+
build(): Promise<void>;
|
|
299
|
+
private registerConfig;
|
|
300
|
+
private registerMiddleware;
|
|
301
|
+
protected abstract registerHandler(info: MiddlewareConfiguration["to"][number], proxy: (...args: any[]) => any, config: MiddlewareConfiguration): Promise<void> | void;
|
|
302
|
+
protected createCallback(wrapper: InstanceWrapper<VenokMiddleware>, moduleRef: CoreModule, collection: Map<InjectionToken, InstanceWrapper>): Promise<VenokContextCallback>;
|
|
303
|
+
private createProxy;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* @publicApi
|
|
308
|
+
*/
|
|
309
|
+
declare class DiscoveryService {
|
|
310
|
+
private readonly modulesContainer;
|
|
311
|
+
constructor(modulesContainer: ModulesContainer);
|
|
312
|
+
/**
|
|
313
|
+
* Returns an array of instance wrappers (providers).
|
|
314
|
+
* Depending on the options, the array will contain either all providers or only providers with the specified metadata key.
|
|
315
|
+
* @param options Discovery options.
|
|
316
|
+
* @param modules A list of modules to filter by.
|
|
317
|
+
* @returns An array of instance wrappers (providers).
|
|
318
|
+
*/
|
|
319
|
+
getProviders(options?: DiscoveryOptions, modules?: CoreModule[]): InstanceWrapper[];
|
|
320
|
+
/**
|
|
321
|
+
* Retrieves metadata from the specified instance wrapper.
|
|
322
|
+
* @param decorator The decorator to retrieve metadata of.
|
|
323
|
+
* @param instanceWrapper Reference to the instance wrapper.
|
|
324
|
+
* @param methodKey An optional method key to retrieve metadata from.
|
|
325
|
+
* @returns Discovered metadata.
|
|
326
|
+
*/
|
|
327
|
+
getMetadataByDecorator<T extends CustomDecorator>(decorator: T, instanceWrapper: InstanceWrapper, methodKey?: string): T extends CustomDecorator<infer R> ? R | undefined : T | undefined;
|
|
328
|
+
/**
|
|
329
|
+
* Returns a list of modules to be used for discovery.
|
|
330
|
+
*/
|
|
331
|
+
protected getModules(options?: DiscoveryOptions): CoreModule[];
|
|
332
|
+
private includeWhitelisted;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
declare abstract class ExplorerService<T = any> extends Reflector {
|
|
336
|
+
protected readonly container: VenokContainer;
|
|
337
|
+
protected readonly discoveryService: DiscoveryService;
|
|
338
|
+
protected readonly metadataScanner: MetadataScanner;
|
|
339
|
+
protected abstract readonly paramsFactory: VenokParamsFactoryInterface;
|
|
340
|
+
protected readonly type: string;
|
|
341
|
+
protected readonly withRequestScope: boolean;
|
|
342
|
+
protected readonly requestArgIndex: number;
|
|
343
|
+
protected readonly options: Omit<ExternalContextOptions, "callback">;
|
|
344
|
+
protected readonly metadataKey: string;
|
|
345
|
+
protected readonly exceptionsFilterClass: typeof VenokExceptionFilterContext;
|
|
346
|
+
protected readonly contextCreatorClass: typeof VenokContextCreator;
|
|
347
|
+
protected readonly exceptionsFilter: VenokExceptionFilterContext;
|
|
348
|
+
protected readonly contextCreator: VenokContextCreator;
|
|
349
|
+
protected readonly wrappers: InstanceWrapper[];
|
|
350
|
+
private readonly exceptionFiltersCache;
|
|
351
|
+
constructor(container: VenokContainer, discoveryService: DiscoveryService, metadataScanner: MetadataScanner);
|
|
352
|
+
explore(metadataKey: string): T[];
|
|
353
|
+
protected abstract getSettings(): ExplorerSettings;
|
|
354
|
+
protected abstract filterProperties(wrapper: InstanceWrapper, metadataKey: string): NonNullable<T> | undefined;
|
|
355
|
+
protected createCallback(wrapper: InstanceWrapper, methodName: string): (...args: any[]) => Promise<any>;
|
|
356
|
+
protected createContextCallback(instance: object, callback: (...args: any[]) => any, methodName: string, contextId?: _venok_core.ContextId, inquirerId?: string | undefined): (...args: any[]) => Promise<any>;
|
|
357
|
+
protected getContextArgForRequest(args: any[]): any;
|
|
358
|
+
private createRequestScopeContextCallback;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* @publicApi
|
|
363
|
+
*/
|
|
364
|
+
declare class IntegrationModule {
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
export { ASYNC_METHOD_SUFFIX, type BaseMiddlewareConfiguration, CONFIGURABLE_MODULE_ID, type ConfigurableModuleAsyncOptions, ConfigurableModuleBuilder, type ConfigurableModuleBuilderOptions, type ConfigurableModuleCls, type ConfigurableModuleHost, type ConfigurableModuleOptionsFactory, DEFAULT_FACTORY_CLASS_METHOD_KEY, DEFAULT_METHOD_KEY, type DiscoveryOptions, DiscoveryService, ExplorerService, type ExplorerSettings, type FilterByInclude, type FilterByMetadataKey, IntegrationModule, MiddlewareContainer, MiddlewareResolver, MiddlewareService, type VenokMiddleware };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// packages/integration/src/index.ts
|
|
2
|
+
import"reflect-metadata";
|
|
3
|
+
|
|
4
|
+
export * from "./configurable/index.js";
|
|
5
|
+
export * from "./interfaces/index.js";
|
|
6
|
+
export * from "./middleware/index.js";
|
|
7
|
+
export * from "./services/index.js";
|
|
8
|
+
export * from "./integration.module.js";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyMetadataTS = (k, v) => {
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
13
|
+
return Reflect.metadata(k, v);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// packages/integration/src/integration.module.ts
|
|
17
|
+
import { MetadataScanner, Module } from "@venok/core";
|
|
18
|
+
import { DiscoveryService } from "./services/discovery.service.js";
|
|
19
|
+
class IntegrationModule {
|
|
20
|
+
}
|
|
21
|
+
IntegrationModule = __legacyDecorateClassTS([
|
|
22
|
+
Module({
|
|
23
|
+
providers: [MetadataScanner, DiscoveryService],
|
|
24
|
+
exports: [MetadataScanner, DiscoveryService]
|
|
25
|
+
})
|
|
26
|
+
], IntegrationModule);
|
|
27
|
+
export {
|
|
28
|
+
IntegrationModule
|
|
29
|
+
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyMetadataTS = (k, v) => {
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
13
|
+
return Reflect.metadata(k, v);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// packages/integration/src/middleware/container.ts
|
|
17
|
+
import { getClassScope, InstanceWrapper, isDurable } from "@venok/core";
|
|
18
|
+
|
|
19
|
+
class MiddlewareContainer {
|
|
20
|
+
middleware = new Map;
|
|
21
|
+
configurationSets = new Map;
|
|
22
|
+
getMiddlewareCollection(moduleKey) {
|
|
23
|
+
if (!this.middleware.has(moduleKey)) {
|
|
24
|
+
this.middleware.set(moduleKey, new Map);
|
|
25
|
+
}
|
|
26
|
+
return this.middleware.get(moduleKey);
|
|
27
|
+
}
|
|
28
|
+
getConfigurations() {
|
|
29
|
+
return this.configurationSets;
|
|
30
|
+
}
|
|
31
|
+
insertConfig(configList, moduleKey) {
|
|
32
|
+
const middleware = this.getMiddlewareCollection(moduleKey);
|
|
33
|
+
const targetConfig = this.getTargetConfig(moduleKey);
|
|
34
|
+
const configurations = configList || [];
|
|
35
|
+
const insertMiddleware = (metatype) => {
|
|
36
|
+
const token = metatype;
|
|
37
|
+
middleware.set(token, new InstanceWrapper({
|
|
38
|
+
scope: getClassScope(metatype),
|
|
39
|
+
durable: isDurable(metatype),
|
|
40
|
+
name: token?.name ?? token,
|
|
41
|
+
metatype,
|
|
42
|
+
token
|
|
43
|
+
}));
|
|
44
|
+
};
|
|
45
|
+
configurations.forEach((config) => {
|
|
46
|
+
[].concat(config.middleware).map(insertMiddleware);
|
|
47
|
+
targetConfig.add(config);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
getTargetConfig(moduleName) {
|
|
51
|
+
if (!this.configurationSets.has(moduleName)) {
|
|
52
|
+
this.configurationSets.set(moduleName, new Set);
|
|
53
|
+
}
|
|
54
|
+
return this.configurationSets.get(moduleName);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
MiddlewareContainer
|
|
59
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyMetadataTS = (k, v) => {
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
13
|
+
return Reflect.metadata(k, v);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// packages/integration/src/middleware/resolver.ts
|
|
17
|
+
import { STATIC_CONTEXT, isUndefined } from "@venok/core";
|
|
18
|
+
|
|
19
|
+
class MiddlewareResolver {
|
|
20
|
+
middlewareContainer;
|
|
21
|
+
injector;
|
|
22
|
+
constructor(middlewareContainer, injector) {
|
|
23
|
+
this.middlewareContainer = middlewareContainer;
|
|
24
|
+
this.injector = injector;
|
|
25
|
+
}
|
|
26
|
+
async resolveInstances(moduleRef, moduleName) {
|
|
27
|
+
const middlewareMap = this.middlewareContainer.getMiddlewareCollection(moduleName);
|
|
28
|
+
const resolveInstance = async (wrapper) => this.resolveMiddlewareInstance(wrapper, middlewareMap, moduleRef);
|
|
29
|
+
await Promise.all([...middlewareMap.values()].map(resolveInstance));
|
|
30
|
+
}
|
|
31
|
+
async resolveMiddlewareInstance(wrapper, middlewareMap, moduleRef) {
|
|
32
|
+
const { metatype, token } = wrapper;
|
|
33
|
+
const targetWrapper = middlewareMap.get(token);
|
|
34
|
+
if (!targetWrapper || !isUndefined(targetWrapper.instance))
|
|
35
|
+
return;
|
|
36
|
+
targetWrapper.instance = Object.create(metatype.prototype);
|
|
37
|
+
await this.injector.loadInstance(wrapper, middlewareMap, moduleRef, STATIC_CONTEXT, wrapper);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
MiddlewareResolver
|
|
42
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyMetadataTS = (k, v) => {
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
13
|
+
return Reflect.metadata(k, v);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// packages/integration/src/middleware/service.ts
|
|
17
|
+
import { ExecutionContextHost, Injectable, Injector, isUndefined, Logger, RuntimeException, STATIC_CONTEXT, VenokContainer, VenokExceptionFilterContext, VenokProxy } from "@venok/core";
|
|
18
|
+
import { MiddlewareContainer } from "../middleware/container.js";
|
|
19
|
+
import { MiddlewareResolver } from "../middleware/resolver.js";
|
|
20
|
+
import { InvalidMiddlewareException } from "../exceptions/invalid-middleware.exception.js";
|
|
21
|
+
class MiddlewareService {
|
|
22
|
+
container;
|
|
23
|
+
index = 0;
|
|
24
|
+
type = "native";
|
|
25
|
+
exceptionsFilter;
|
|
26
|
+
venokProxy = new VenokProxy;
|
|
27
|
+
exceptionFiltersCache = new WeakMap;
|
|
28
|
+
logger = new Logger(MiddlewareService.name, { timestamp: true });
|
|
29
|
+
injector = new Injector;
|
|
30
|
+
middlewareContainer = new MiddlewareContainer;
|
|
31
|
+
resolver = new MiddlewareResolver(this.middlewareContainer, this.injector);
|
|
32
|
+
constructor(container) {
|
|
33
|
+
this.container = container;
|
|
34
|
+
console.log("initialized");
|
|
35
|
+
this.exceptionsFilter = new VenokExceptionFilterContext(this.container, this.container.applicationConfig);
|
|
36
|
+
}
|
|
37
|
+
async explore(middlewareClass) {
|
|
38
|
+
const modules = this.container.getModules();
|
|
39
|
+
const moduleEntries = [...modules.entries()];
|
|
40
|
+
const loadMiddlewareConfiguration = async ([moduleName, moduleRef]) => {
|
|
41
|
+
await this.loadConfiguration(moduleRef, moduleName, middlewareClass);
|
|
42
|
+
await this.resolver.resolveInstances(moduleRef, moduleName);
|
|
43
|
+
};
|
|
44
|
+
await Promise.all(moduleEntries.map(loadMiddlewareConfiguration));
|
|
45
|
+
}
|
|
46
|
+
async loadConfiguration(moduleRef, moduleKey, middlewareClass) {
|
|
47
|
+
const { instance } = moduleRef;
|
|
48
|
+
if (!instance.configure)
|
|
49
|
+
return;
|
|
50
|
+
if (!(instance instanceof middlewareClass))
|
|
51
|
+
return;
|
|
52
|
+
const builder = this.getMiddlewareBuilder();
|
|
53
|
+
try {
|
|
54
|
+
await instance.configure(builder);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
const warningMessage = `Warning! "${moduleRef.name}" module exposes a "configure" method that throws an exception in the preview mode` + ` (possibly due to missing dependencies). Note: you can ignore this message, just be aware that some of those conditional middlewares will not be reflected in your graph.`;
|
|
57
|
+
this.logger.warn(warningMessage);
|
|
58
|
+
throw err;
|
|
59
|
+
}
|
|
60
|
+
const config = builder.build();
|
|
61
|
+
this.middlewareContainer.insertConfig(config, moduleKey);
|
|
62
|
+
}
|
|
63
|
+
async build() {
|
|
64
|
+
const configs = this.middlewareContainer.getConfigurations();
|
|
65
|
+
const registerAllConfigs = async (moduleKey, middlewareConfig) => {
|
|
66
|
+
for (const config of middlewareConfig)
|
|
67
|
+
await this.registerConfig(config, moduleKey);
|
|
68
|
+
};
|
|
69
|
+
const entriesSortedByDistance = [...configs.entries()].sort(([moduleA], [moduleB]) => {
|
|
70
|
+
return this.container.getModuleByKey(moduleA).distance - this.container.getModuleByKey(moduleB).distance;
|
|
71
|
+
});
|
|
72
|
+
for (const [moduleRef, moduleConfigurations] of entriesSortedByDistance) {
|
|
73
|
+
await registerAllConfigs(moduleRef, [...moduleConfigurations]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async registerConfig(config, moduleKey) {
|
|
77
|
+
const { to } = config;
|
|
78
|
+
for (const info of to)
|
|
79
|
+
await this.registerMiddleware(info, moduleKey, config);
|
|
80
|
+
}
|
|
81
|
+
async registerMiddleware(to, moduleKey, config) {
|
|
82
|
+
const middlewareCollection = [].concat(config.middleware);
|
|
83
|
+
const collection = this.middlewareContainer.getMiddlewareCollection(moduleKey);
|
|
84
|
+
const moduleRef = this.container.getModuleByKey(moduleKey);
|
|
85
|
+
for (const metatype of middlewareCollection) {
|
|
86
|
+
const instanceWrapper = collection.get(metatype);
|
|
87
|
+
if (isUndefined(instanceWrapper))
|
|
88
|
+
throw new RuntimeException;
|
|
89
|
+
if (instanceWrapper.isTransient)
|
|
90
|
+
return;
|
|
91
|
+
const proxy = await this.createCallback(instanceWrapper, moduleRef, collection);
|
|
92
|
+
await this.registerHandler(to, proxy, config);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async createCallback(wrapper, moduleRef, collection) {
|
|
96
|
+
const { instance, metatype } = wrapper;
|
|
97
|
+
if (isUndefined(instance?.use))
|
|
98
|
+
throw new InvalidMiddlewareException(metatype.name);
|
|
99
|
+
const isStatic = wrapper.isDependencyTreeStatic();
|
|
100
|
+
if (isStatic)
|
|
101
|
+
return await this.createProxy(instance);
|
|
102
|
+
const isTreeDurable = wrapper.isDependencyTreeDurable();
|
|
103
|
+
return async (...args) => {
|
|
104
|
+
try {
|
|
105
|
+
const contextId = this.container.getContextId(args[this.index], isTreeDurable);
|
|
106
|
+
const contextInstance = await this.injector.loadPerContext(instance, moduleRef, collection, contextId);
|
|
107
|
+
const proxy = await this.createProxy(contextInstance, contextId);
|
|
108
|
+
return proxy(...args);
|
|
109
|
+
} catch (err) {
|
|
110
|
+
let exceptionsHandler = this.exceptionFiltersCache.get(instance.use);
|
|
111
|
+
if (!exceptionsHandler) {
|
|
112
|
+
exceptionsHandler = this.exceptionsFilter.create(instance, instance.use, undefined);
|
|
113
|
+
this.exceptionFiltersCache.set(instance.use, exceptionsHandler);
|
|
114
|
+
}
|
|
115
|
+
const host = new ExecutionContextHost(args);
|
|
116
|
+
exceptionsHandler.next(err, host);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
async createProxy(instance, contextId = STATIC_CONTEXT) {
|
|
121
|
+
const exceptionsHandler = this.exceptionsFilter.create(instance, instance.use, undefined, contextId);
|
|
122
|
+
const middleware = instance.use.bind(instance);
|
|
123
|
+
return this.venokProxy.createProxy(middleware, exceptionsHandler, this.type);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
MiddlewareService = __legacyDecorateClassTS([
|
|
127
|
+
Injectable(),
|
|
128
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
129
|
+
typeof VenokContainer === "undefined" ? Object : VenokContainer
|
|
130
|
+
])
|
|
131
|
+
], MiddlewareService);
|
|
132
|
+
export {
|
|
133
|
+
MiddlewareService
|
|
134
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyMetadataTS = (k, v) => {
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
13
|
+
return Reflect.metadata(k, v);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// packages/integration/src/services/discovery.service.ts
|
|
17
|
+
import { flatten, Injectable, MetaHostStorage, ModulesContainer } from "@venok/core";
|
|
18
|
+
class DiscoveryService {
|
|
19
|
+
modulesContainer;
|
|
20
|
+
constructor(modulesContainer) {
|
|
21
|
+
this.modulesContainer = modulesContainer;
|
|
22
|
+
}
|
|
23
|
+
getProviders(options = {}, modules = this.getModules(options)) {
|
|
24
|
+
if ("metadataKey" in options && options.metadataKey) {
|
|
25
|
+
const providers2 = MetaHostStorage.getProvidersByMetaKey(this.modulesContainer, options.metadataKey);
|
|
26
|
+
return Array.from(providers2);
|
|
27
|
+
}
|
|
28
|
+
const providers = modules.map((item) => [...item.providers.values()]);
|
|
29
|
+
return flatten(providers);
|
|
30
|
+
}
|
|
31
|
+
getMetadataByDecorator(decorator, instanceWrapper, methodKey) {
|
|
32
|
+
if (methodKey)
|
|
33
|
+
return Reflect.getMetadata(decorator.KEY, instanceWrapper.instance[methodKey]);
|
|
34
|
+
const clsRef = instanceWrapper.instance?.constructor ?? instanceWrapper.metatype;
|
|
35
|
+
return Reflect.getMetadata(decorator.KEY, clsRef);
|
|
36
|
+
}
|
|
37
|
+
getModules(options = {}) {
|
|
38
|
+
if (!(("include" in options) && options.include))
|
|
39
|
+
return [...this.modulesContainer.values()];
|
|
40
|
+
return this.includeWhitelisted(options.include);
|
|
41
|
+
}
|
|
42
|
+
includeWhitelisted(include) {
|
|
43
|
+
const moduleRefs = [...this.modulesContainer.values()];
|
|
44
|
+
return moduleRefs.filter(({ metatype }) => include.some((item) => item === metatype));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
DiscoveryService = __legacyDecorateClassTS([
|
|
48
|
+
Injectable(),
|
|
49
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
50
|
+
typeof ModulesContainer === "undefined" ? Object : ModulesContainer
|
|
51
|
+
])
|
|
52
|
+
], DiscoveryService);
|
|
53
|
+
export {
|
|
54
|
+
DiscoveryService
|
|
55
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyMetadataTS = (k, v) => {
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
13
|
+
return Reflect.metadata(k, v);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// packages/integration/src/services/explorer.service.ts
|
|
17
|
+
import {
|
|
18
|
+
ExecutionContextHost,
|
|
19
|
+
Injectable,
|
|
20
|
+
Injector,
|
|
21
|
+
MetadataScanner,
|
|
22
|
+
Reflector,
|
|
23
|
+
ROUTE_ARGS_METADATA,
|
|
24
|
+
STATIC_CONTEXT,
|
|
25
|
+
VenokContainer,
|
|
26
|
+
VenokContextCreator,
|
|
27
|
+
VenokExceptionFilterContext
|
|
28
|
+
} from "@venok/core";
|
|
29
|
+
import { DiscoveryService } from "../services/discovery.service.js";
|
|
30
|
+
class ExplorerService extends Reflector {
|
|
31
|
+
container;
|
|
32
|
+
discoveryService;
|
|
33
|
+
metadataScanner;
|
|
34
|
+
type;
|
|
35
|
+
withRequestScope;
|
|
36
|
+
requestArgIndex;
|
|
37
|
+
options;
|
|
38
|
+
metadataKey;
|
|
39
|
+
exceptionsFilterClass;
|
|
40
|
+
contextCreatorClass;
|
|
41
|
+
exceptionsFilter;
|
|
42
|
+
contextCreator;
|
|
43
|
+
wrappers;
|
|
44
|
+
exceptionFiltersCache = new WeakMap;
|
|
45
|
+
constructor(container, discoveryService, metadataScanner) {
|
|
46
|
+
super();
|
|
47
|
+
this.container = container;
|
|
48
|
+
this.discoveryService = discoveryService;
|
|
49
|
+
this.metadataScanner = metadataScanner;
|
|
50
|
+
const {
|
|
51
|
+
contextType = "native",
|
|
52
|
+
contextCreatorClass = VenokContextCreator,
|
|
53
|
+
exceptionsFilterClass = VenokExceptionFilterContext,
|
|
54
|
+
isRequestScopeSupported = false,
|
|
55
|
+
options = { guards: true, filters: true, interceptors: true, callback: undefined },
|
|
56
|
+
requestContextArgIndex = 0,
|
|
57
|
+
metadataKey = ROUTE_ARGS_METADATA
|
|
58
|
+
} = this.getSettings();
|
|
59
|
+
this.options = options;
|
|
60
|
+
this.type = contextType;
|
|
61
|
+
this.metadataKey = metadataKey;
|
|
62
|
+
this.requestArgIndex = requestContextArgIndex;
|
|
63
|
+
this.contextCreatorClass = contextCreatorClass;
|
|
64
|
+
this.withRequestScope = isRequestScopeSupported;
|
|
65
|
+
this.exceptionsFilterClass = exceptionsFilterClass;
|
|
66
|
+
this.contextCreator = this.contextCreatorClass.fromContainer(container, this.contextCreatorClass, this.exceptionsFilterClass);
|
|
67
|
+
this.exceptionsFilter = new this.exceptionsFilterClass(this.container, this.container.applicationConfig);
|
|
68
|
+
this.wrappers = this.discoveryService.getProviders().filter((wrapper) => {
|
|
69
|
+
const { instance } = wrapper;
|
|
70
|
+
const prototype = instance ? Object.getPrototypeOf(instance) : null;
|
|
71
|
+
return this.withRequestScope ? instance && prototype : instance && prototype && wrapper.isDependencyTreeStatic();
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
explore(metadataKey) {
|
|
75
|
+
return this.wrappers.flatMap((wrapper) => this.filterProperties(wrapper, metadataKey)).filter(Boolean);
|
|
76
|
+
}
|
|
77
|
+
createCallback(wrapper, methodName) {
|
|
78
|
+
if (!this.withRequestScope)
|
|
79
|
+
return this.createContextCallback(wrapper.instance, wrapper.instance[methodName], methodName);
|
|
80
|
+
const isRequestScoped = !wrapper.isDependencyTreeStatic();
|
|
81
|
+
return isRequestScoped ? this.createRequestScopeContextCallback(wrapper, methodName) : this.createContextCallback(wrapper.instance, wrapper.instance[methodName], methodName);
|
|
82
|
+
}
|
|
83
|
+
createContextCallback(instance, callback, methodName, contextId = STATIC_CONTEXT, inquirerId = undefined) {
|
|
84
|
+
return this.contextCreator.create(instance, callback, methodName, this.metadataKey, this.paramsFactory, contextId, inquirerId, this.options, this.type);
|
|
85
|
+
}
|
|
86
|
+
getContextArgForRequest(args) {
|
|
87
|
+
return this.paramsFactory.exchangeKeyForValue(this.requestArgIndex, undefined, args);
|
|
88
|
+
}
|
|
89
|
+
createRequestScopeContextCallback(wrapper, methodName) {
|
|
90
|
+
const { instance } = wrapper;
|
|
91
|
+
const moduleKey = this.contextCreator.getContextModuleKey(instance.constructor);
|
|
92
|
+
const moduleRef = this.container.getModuleByKey(moduleKey);
|
|
93
|
+
const collection = moduleRef.injectables;
|
|
94
|
+
const isTreeDurable = wrapper.isDependencyTreeDurable();
|
|
95
|
+
return async (...args) => {
|
|
96
|
+
try {
|
|
97
|
+
const contextArg = this.getContextArgForRequest(args);
|
|
98
|
+
const contextId = this.container.getContextId(contextArg, isTreeDurable);
|
|
99
|
+
const contextInstance = await new Injector().loadPerContext(instance, moduleRef, collection, contextId);
|
|
100
|
+
await this.createContextCallback(contextInstance, contextInstance[methodName], methodName, contextId, wrapper.id)(...args);
|
|
101
|
+
} catch (err) {
|
|
102
|
+
let exceptionFilter = this.exceptionFiltersCache.get(instance[methodName]);
|
|
103
|
+
if (!exceptionFilter) {
|
|
104
|
+
exceptionFilter = this.exceptionsFilter.create(instance, instance[methodName], moduleKey);
|
|
105
|
+
this.exceptionFiltersCache.set(instance[methodName], exceptionFilter);
|
|
106
|
+
}
|
|
107
|
+
const host = new ExecutionContextHost(args);
|
|
108
|
+
exceptionFilter.next(err, host);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
ExplorerService = __legacyDecorateClassTS([
|
|
114
|
+
Injectable(),
|
|
115
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
116
|
+
typeof VenokContainer === "undefined" ? Object : VenokContainer,
|
|
117
|
+
typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
|
|
118
|
+
typeof MetadataScanner === "undefined" ? Object : MetadataScanner
|
|
119
|
+
])
|
|
120
|
+
], ExplorerService);
|
|
121
|
+
export {
|
|
122
|
+
ExplorerService
|
|
123
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@venok/integration",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"author": "shiz-ceo",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"homepage": "",
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"files": ["package.json", "dist"],
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
},
|
|
19
|
+
"import": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/venokjs/venok.git",
|
|
28
|
+
"directory": "packages/integration"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "venok build",
|
|
32
|
+
"test": "mocha test/**/*.spec.ts"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@venok/core": "1.1.0",
|
|
36
|
+
"uuid": "^13.0.0",
|
|
37
|
+
"reflect-metadata": "^0.2.2",
|
|
38
|
+
"rxjs": "^7.8.1"
|
|
39
|
+
}
|
|
40
|
+
}
|