@opra/nestjs 0.33.13 → 1.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/cjs/augmentation/http-controller.augmentation.js +16 -0
- package/cjs/index.js +2 -5
- package/cjs/interfaces/opra-module-options.interface.js +16 -1
- package/cjs/opra-http-core.module.js +52 -0
- package/cjs/opra-http.module.js +23 -0
- package/cjs/opra-nestjs-adapter.js +138 -0
- package/cjs/services/opra-exception-filter.js +14 -13
- package/esm/augmentation/http-controller.augmentation.js +16 -0
- package/esm/index.js +2 -5
- package/esm/interfaces/opra-module-options.interface.js +17 -1
- package/esm/opra-http-core.module.js +49 -0
- package/esm/opra-http.module.js +20 -0
- package/esm/opra-nestjs-adapter.js +133 -0
- package/esm/services/opra-exception-filter.js +13 -13
- package/package.json +12 -11
- package/types/augmentation/http-controller.augmentation.d.ts +0 -0
- package/types/index.d.ts +2 -5
- package/types/interfaces/opra-module-options.interface.d.ts +0 -25
- package/types/opra-http-core.module.d.ts +9 -0
- package/types/opra-http.module.d.ts +16 -0
- package/types/opra-nestjs-adapter.d.ts +10 -0
- package/types/services/opra-exception-filter.d.ts +6 -2
- package/cjs/augmentation/common-decorator.augmentation.js +0 -40
- package/cjs/constants.js +0 -9
- package/cjs/decorators/context.decorator.js +0 -10
- package/cjs/enums/handler-paramtype.enum.js +0 -9
- package/cjs/factories/opra-api.factory.js +0 -200
- package/cjs/factories/params.factory.js +0 -23
- package/cjs/opra-core.module.js +0 -140
- package/cjs/opra-module-ref.js +0 -16
- package/cjs/opra.module.js +0 -25
- package/cjs/services/nest-explorer.js +0 -38
- package/cjs/services/opra-api-loader.js +0 -85
- package/cjs/types.js +0 -2
- package/cjs/utils/class.utils.js +0 -25
- package/cjs/utils/function.utils.js +0 -37
- package/cjs/utils/param.utils.js +0 -24
- package/esm/augmentation/common-decorator.augmentation.js +0 -38
- package/esm/constants.js +0 -6
- package/esm/decorators/context.decorator.js +0 -7
- package/esm/enums/handler-paramtype.enum.js +0 -6
- package/esm/factories/opra-api.factory.js +0 -197
- package/esm/factories/params.factory.js +0 -19
- package/esm/opra-core.module.js +0 -137
- package/esm/opra-module-ref.js +0 -12
- package/esm/opra.module.js +0 -22
- package/esm/services/nest-explorer.js +0 -34
- package/esm/services/opra-api-loader.js +0 -81
- package/esm/types.js +0 -1
- package/esm/utils/class.utils.js +0 -19
- package/esm/utils/function.utils.js +0 -33
- package/esm/utils/param.utils.js +0 -20
- package/types/augmentation/common-decorator.augmentation.d.ts +0 -1
- package/types/constants.d.ts +0 -6
- package/types/decorators/context.decorator.d.ts +0 -5
- package/types/enums/handler-paramtype.enum.d.ts +0 -5
- package/types/factories/opra-api.factory.d.ts +0 -15
- package/types/factories/params.factory.d.ts +0 -4
- package/types/opra-core.module.d.ts +0 -17
- package/types/opra-module-ref.d.ts +0 -11
- package/types/opra.module.d.ts +0 -6
- package/types/services/nest-explorer.d.ts +0 -8
- package/types/services/opra-api-loader.d.ts +0 -19
- package/types/types.d.ts +0 -2
- package/types/utils/class.utils.d.ts +0 -4
- package/types/utils/function.utils.d.ts +0 -1
- package/types/utils/param.utils.d.ts +0 -8
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { ModuleMetadata, Type } from '@nestjs/common';
|
|
2
|
-
import { ApiDocumentFactory } from '@opra/common';
|
|
3
|
-
import { ExpressAdapter, NodeHttpAdapter } from '@opra/core';
|
|
4
|
-
export type OpraModuleOptions = NodeHttpAdapter.Options & {
|
|
5
|
-
id?: any;
|
|
6
|
-
adapterNode?: ExpressAdapter.Options;
|
|
7
|
-
adapterExpress?: ExpressAdapter.Options;
|
|
8
|
-
document?: Partial<ApiDocumentFactory.InitArguments>;
|
|
9
|
-
/**
|
|
10
|
-
* @default true
|
|
11
|
-
*/
|
|
12
|
-
useGlobalPrefix?: boolean;
|
|
13
|
-
};
|
|
14
|
-
type OpraModuleOptionsWithoutId = Omit<OpraModuleOptions, 'id'>;
|
|
15
|
-
export interface OpraModuleOptionsFactory {
|
|
16
|
-
createOptions(): Promise<OpraModuleOptionsWithoutId> | OpraModuleOptionsWithoutId;
|
|
17
|
-
}
|
|
18
|
-
export interface OpraModuleAsyncOptions extends Pick<ModuleMetadata, 'imports' | 'providers'> {
|
|
19
|
-
id?: any;
|
|
20
|
-
useExisting?: Type<OpraModuleOptionsFactory>;
|
|
21
|
-
useClass?: Type<OpraModuleOptionsFactory>;
|
|
22
|
-
useFactory?: (...args: any[]) => Promise<OpraModuleOptionsWithoutId> | OpraModuleOptionsWithoutId;
|
|
23
|
-
inject?: any[];
|
|
24
|
-
}
|
|
25
|
-
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DynamicModule, OnModuleDestroy } from '@nestjs/common';
|
|
2
|
+
import type { OpraHttpModule } from './opra-http.module';
|
|
3
|
+
import { OpraNestAdapter } from './opra-nestjs-adapter.js';
|
|
4
|
+
export declare class OpraHttpCoreModule implements OnModuleDestroy {
|
|
5
|
+
protected opraAdapter: OpraNestAdapter;
|
|
6
|
+
constructor(opraAdapter: OpraNestAdapter);
|
|
7
|
+
static forRoot(options: OpraHttpModule.Options): DynamicModule;
|
|
8
|
+
onModuleDestroy(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { ApiDocumentFactory } from '@opra/common';
|
|
3
|
+
export declare namespace OpraHttpModule {
|
|
4
|
+
interface Options extends Pick<DynamicModule, 'imports' | 'providers' | 'exports' | 'controllers'>, Pick<ApiDocumentFactory.InitArguments, 'types' | 'references' | 'info'> {
|
|
5
|
+
id?: any;
|
|
6
|
+
name: string;
|
|
7
|
+
basePath?: string;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare class OpraHttpModule {
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param options
|
|
14
|
+
*/
|
|
15
|
+
static forRoot(options: OpraHttpModule.Options): DynamicModule;
|
|
16
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Type } from '@nestjs/common';
|
|
2
|
+
import { HttpAdapter } from '@opra/core';
|
|
3
|
+
import type { OpraHttpModule } from './opra-http.module';
|
|
4
|
+
export declare const kHandler: unique symbol;
|
|
5
|
+
export declare class OpraNestAdapter extends HttpAdapter {
|
|
6
|
+
readonly controllers: Type[];
|
|
7
|
+
constructor(options: OpraHttpModule.Options);
|
|
8
|
+
close(): Promise<void>;
|
|
9
|
+
protected _createNestControllers(source: Type, currentPath: string): void;
|
|
10
|
+
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { ExceptionFilter } from '@nestjs/common';
|
|
1
|
+
import { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
|
|
2
|
+
import { OpraNestAdapter } from '../opra-nestjs-adapter.js';
|
|
3
|
+
export declare const kHandler: unique symbol;
|
|
2
4
|
export declare class OpraExceptionFilter implements ExceptionFilter {
|
|
3
|
-
|
|
5
|
+
readonly adapter: OpraNestAdapter;
|
|
6
|
+
constructor(adapter: OpraNestAdapter);
|
|
7
|
+
catch(exception: any, host: ArgumentsHost): Promise<void>;
|
|
4
8
|
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const common_1 = require("@nestjs/common");
|
|
4
|
-
const common_2 = require("@opra/common");
|
|
5
|
-
/*
|
|
6
|
-
Overrides Collection decorator function to call NestJS's Injectable() when Collection decorator called
|
|
7
|
-
*/
|
|
8
|
-
const oldCollectionDecorator = common_2.Collection[common_2.DECORATOR];
|
|
9
|
-
common_2.Collection[common_2.DECORATOR] = function CollectionDecorator(...args) {
|
|
10
|
-
const collectionDecorator = oldCollectionDecorator(...args);
|
|
11
|
-
const injectableDecorator = (0, common_1.Injectable)();
|
|
12
|
-
return (target) => {
|
|
13
|
-
collectionDecorator(target);
|
|
14
|
-
injectableDecorator(target);
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
/*
|
|
18
|
-
Overrides Singleton decorator function to call NestJS's Injectable() when Singleton decorator called
|
|
19
|
-
*/
|
|
20
|
-
const oldSingletonDecorator = common_2.Singleton[common_2.DECORATOR];
|
|
21
|
-
common_2.Singleton[common_2.DECORATOR] = function SingletonDecorator(...args) {
|
|
22
|
-
const singletonDecorator = oldSingletonDecorator(...args);
|
|
23
|
-
const injectableDecorator = (0, common_1.Injectable)();
|
|
24
|
-
return (target) => {
|
|
25
|
-
singletonDecorator(target);
|
|
26
|
-
injectableDecorator(target);
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
/*
|
|
30
|
-
Overrides Singleton decorator function to call NestJS's Injectable() when Singleton decorator called
|
|
31
|
-
*/
|
|
32
|
-
const oldStorageDecorator = common_2.Storage[common_2.DECORATOR];
|
|
33
|
-
common_2.Storage[common_2.DECORATOR] = function StorageDecorator(...args) {
|
|
34
|
-
const storageDecorator = oldStorageDecorator(...args);
|
|
35
|
-
const injectableDecorator = (0, common_1.Injectable)();
|
|
36
|
-
return (target) => {
|
|
37
|
-
storageDecorator(target);
|
|
38
|
-
injectableDecorator(target);
|
|
39
|
-
};
|
|
40
|
-
};
|
package/cjs/constants.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PARAM_ARGS_METADATA = exports.kAdapter = exports.kOptions = exports.OPRA_INITIALIZER = exports.OPRA_MODULE_ID = exports.OPRA_MODULE_OPTIONS = void 0;
|
|
4
|
-
exports.OPRA_MODULE_OPTIONS = 'opra:module_options';
|
|
5
|
-
exports.OPRA_MODULE_ID = 'opra:module_id';
|
|
6
|
-
exports.OPRA_INITIALIZER = 'opra_initializer';
|
|
7
|
-
exports.kOptions = Symbol('kOptions');
|
|
8
|
-
exports.kAdapter = Symbol('kAdapter');
|
|
9
|
-
exports.PARAM_ARGS_METADATA = '__routeArguments__';
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Context = void 0;
|
|
4
|
-
const handler_paramtype_enum_js_1 = require("../enums/handler-paramtype.enum.js");
|
|
5
|
-
const param_utils_js_1 = require("../utils/param.utils.js");
|
|
6
|
-
/**
|
|
7
|
-
* Handler method parameter decorator. Populates the decorated
|
|
8
|
-
* parameter with the value of `RequestContext`.
|
|
9
|
-
*/
|
|
10
|
-
exports.Context = (0, param_utils_js_1.createOpraParamDecorator)(handler_paramtype_enum_js_1.HandlerParamType.CONTEXT);
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HandlerParamType = void 0;
|
|
4
|
-
var HandlerParamType;
|
|
5
|
-
(function (HandlerParamType) {
|
|
6
|
-
HandlerParamType[HandlerParamType["CONTEXT"] = 0] = "CONTEXT";
|
|
7
|
-
HandlerParamType[HandlerParamType["REQUEST"] = 1] = "REQUEST";
|
|
8
|
-
HandlerParamType[HandlerParamType["RESPONSE"] = 2] = "RESPONSE";
|
|
9
|
-
})(HandlerParamType || (exports.HandlerParamType = HandlerParamType = {}));
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpraApiFactory = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const lodash_head_1 = tslib_1.__importDefault(require("lodash.head"));
|
|
6
|
-
const common_1 = require("@nestjs/common");
|
|
7
|
-
const core_1 = require("@nestjs/core");
|
|
8
|
-
const external_context_creator_1 = require("@nestjs/core/helpers/external-context-creator");
|
|
9
|
-
const injector_1 = require("@nestjs/core/injector/injector");
|
|
10
|
-
const internal_core_module_1 = require("@nestjs/core/injector/internal-core-module");
|
|
11
|
-
const request_constants_1 = require("@nestjs/core/router/request/request-constants");
|
|
12
|
-
const common_2 = require("@opra/common");
|
|
13
|
-
const constants_js_1 = require("../constants.js");
|
|
14
|
-
const handler_paramtype_enum_js_1 = require("../enums/handler-paramtype.enum.js");
|
|
15
|
-
const nest_explorer_js_1 = require("../services/nest-explorer.js");
|
|
16
|
-
const function_utils_js_1 = require("../utils/function.utils.js");
|
|
17
|
-
const params_factory_js_1 = require("./params.factory.js");
|
|
18
|
-
const noOpFunction = () => void 0;
|
|
19
|
-
let OpraApiFactory = class OpraApiFactory {
|
|
20
|
-
constructor() {
|
|
21
|
-
this.paramsFactory = new params_factory_js_1.OpraParamsFactory();
|
|
22
|
-
this.injector = new injector_1.Injector();
|
|
23
|
-
}
|
|
24
|
-
async generateService(rootModule, contextType, apiSchema) {
|
|
25
|
-
const info = { ...apiSchema?.info };
|
|
26
|
-
info.title = info.title || 'Untitled service';
|
|
27
|
-
info.version = info.version || '1';
|
|
28
|
-
const root = {
|
|
29
|
-
resources: []
|
|
30
|
-
};
|
|
31
|
-
const apiInit = {
|
|
32
|
-
version: common_2.OpraSchema.SpecVersion,
|
|
33
|
-
...apiSchema,
|
|
34
|
-
info,
|
|
35
|
-
types: apiSchema?.types || [],
|
|
36
|
-
root
|
|
37
|
-
};
|
|
38
|
-
/*
|
|
39
|
-
* Walk through modules and add Resource instances to the api schema
|
|
40
|
-
*/
|
|
41
|
-
this.explorerService.exploreResources(rootModule, (wrapper, modulePath) => {
|
|
42
|
-
const instance = wrapper.instance;
|
|
43
|
-
const ctor = instance.constructor;
|
|
44
|
-
const metadata = Reflect.getMetadata(common_2.RESOURCE_METADATA, ctor);
|
|
45
|
-
let node = root;
|
|
46
|
-
modulePath.forEach(m => {
|
|
47
|
-
const mt = Reflect.getMetadata(common_2.RESOURCE_METADATA, m._metatype);
|
|
48
|
-
if (mt) {
|
|
49
|
-
let n = node.resources.find(x => x.controller === m.instance);
|
|
50
|
-
if (!n) {
|
|
51
|
-
n = {
|
|
52
|
-
...mt,
|
|
53
|
-
kind: 'Container',
|
|
54
|
-
resources: [...(mt.resources || [])],
|
|
55
|
-
controller: m.instance
|
|
56
|
-
};
|
|
57
|
-
node.resources.push(n);
|
|
58
|
-
}
|
|
59
|
-
node = n;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
// Do not add Modules decorated with @Container
|
|
63
|
-
if (wrapper.metatype !== wrapper.host?.metatype)
|
|
64
|
-
node.resources.push(instance);
|
|
65
|
-
/* Wrap operation and action functions */
|
|
66
|
-
const isRequestScoped = !wrapper.isDependencyTreeStatic();
|
|
67
|
-
const methodNames = [...Object.keys(metadata.operations || []), ...Object.keys(metadata.actions || [])];
|
|
68
|
-
for (const methodName of methodNames) {
|
|
69
|
-
const endpointFunction = instance[methodName];
|
|
70
|
-
const nestHandlerName = methodName + '_nestjs';
|
|
71
|
-
// Skip patch if controller do not have function for endpoint or already patched before
|
|
72
|
-
if (typeof endpointFunction !== 'function')
|
|
73
|
-
continue;
|
|
74
|
-
// NestJs requires calling handler function in different order than Opra.
|
|
75
|
-
// In NestJS, handler functions must be called with these parameters (req, res, next)
|
|
76
|
-
// In Opra, handler functions must be called with these parameters (context)
|
|
77
|
-
// To work handlers properly we create new handlers that will work as a proxy to wrap parameters
|
|
78
|
-
// Opra request (context) -> Nest (req, res, next, context: QueryRequestContext) -> Opra response (context)
|
|
79
|
-
const paramArgsMetadata = Reflect.getMetadata(constants_js_1.PARAM_ARGS_METADATA, instance.constructor, methodName);
|
|
80
|
-
const hasParamsArgs = !!paramArgsMetadata;
|
|
81
|
-
const patchedFn = instance[nestHandlerName] = function (...args) {
|
|
82
|
-
if (hasParamsArgs)
|
|
83
|
-
return endpointFunction.apply(this, args);
|
|
84
|
-
return endpointFunction.call(this, args[3]);
|
|
85
|
-
};
|
|
86
|
-
if (paramArgsMetadata)
|
|
87
|
-
Reflect.defineMetadata(constants_js_1.PARAM_ARGS_METADATA, paramArgsMetadata, instance.constructor, nestHandlerName);
|
|
88
|
-
// Copy all metadata from old Function to new one
|
|
89
|
-
Reflect.getMetadataKeys(endpointFunction).forEach(k => {
|
|
90
|
-
const m = Reflect.getMetadata(k, endpointFunction);
|
|
91
|
-
Reflect.defineMetadata(k, m, patchedFn);
|
|
92
|
-
});
|
|
93
|
-
this._createContextCallback(instance, wrapper, rootModule, methodName, isRequestScoped, contextType);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
// Create api document
|
|
97
|
-
return common_2.ApiDocumentFactory.createDocument(apiInit);
|
|
98
|
-
}
|
|
99
|
-
_createHandler(callback) {
|
|
100
|
-
return function (ctx) {
|
|
101
|
-
switch (ctx.protocol) {
|
|
102
|
-
case 'http':
|
|
103
|
-
const httpContext = ctx.switchToHttp();
|
|
104
|
-
return callback(httpContext.incoming, httpContext.outgoing, noOpFunction, ctx);
|
|
105
|
-
default:
|
|
106
|
-
throw new Error(`"${ctx.protocol}" context type is not implemented yet`);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
_createContextCallback(instance, wrapper, moduleRef, methodName, isRequestScoped, contextType, options) {
|
|
111
|
-
const paramsFactory = this.paramsFactory;
|
|
112
|
-
const nestHandlerName = methodName + '_nestjs';
|
|
113
|
-
const callback = isRequestScoped
|
|
114
|
-
? async (...args) => {
|
|
115
|
-
const opraContext = paramsFactory.exchangeKeyForValue(handler_paramtype_enum_js_1.HandlerParamType.CONTEXT, undefined, args);
|
|
116
|
-
const contextId = this.getContextId(opraContext);
|
|
117
|
-
this.registerContextProvider(opraContext, contextId);
|
|
118
|
-
const contextInstance = await this.injector.loadPerContext(instance, moduleRef, moduleRef.providers, contextId);
|
|
119
|
-
const contextCallback = this.externalContextCreator.create(contextInstance, contextInstance[methodName], nestHandlerName, constants_js_1.PARAM_ARGS_METADATA, paramsFactory, contextId, wrapper.id, options, opraContext.protocol);
|
|
120
|
-
contextInstance[methodName] = this._createHandler(contextCallback);
|
|
121
|
-
return contextCallback(...args);
|
|
122
|
-
}
|
|
123
|
-
: this.externalContextCreator.create(instance, instance[nestHandlerName], nestHandlerName, constants_js_1.PARAM_ARGS_METADATA, paramsFactory, undefined, undefined, options, contextType);
|
|
124
|
-
instance[methodName] = this._createHandler(callback);
|
|
125
|
-
return callback;
|
|
126
|
-
}
|
|
127
|
-
// noinspection JSMethodCanBeStatic
|
|
128
|
-
getContextId(gqlContext) {
|
|
129
|
-
const numberOfArguments = (0, function_utils_js_1.getNumberOfArguments)(core_1.ContextIdFactory.getByRequest);
|
|
130
|
-
if (numberOfArguments === 2) {
|
|
131
|
-
// @ts-ignore
|
|
132
|
-
const contextId = core_1.ContextIdFactory.getByRequest(gqlContext, ['req']);
|
|
133
|
-
if (!gqlContext[request_constants_1.REQUEST_CONTEXT_ID]) {
|
|
134
|
-
Object.defineProperty(gqlContext, request_constants_1.REQUEST_CONTEXT_ID, {
|
|
135
|
-
value: contextId,
|
|
136
|
-
enumerable: false,
|
|
137
|
-
configurable: false,
|
|
138
|
-
writable: false,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
return contextId;
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
// TODO remove in the next version (backward-compatibility layer)
|
|
145
|
-
// Left for backward compatibility purposes
|
|
146
|
-
let contextId;
|
|
147
|
-
if (gqlContext && gqlContext[request_constants_1.REQUEST_CONTEXT_ID]) {
|
|
148
|
-
contextId = gqlContext[request_constants_1.REQUEST_CONTEXT_ID];
|
|
149
|
-
}
|
|
150
|
-
else if (gqlContext &&
|
|
151
|
-
gqlContext.req &&
|
|
152
|
-
gqlContext.req[request_constants_1.REQUEST_CONTEXT_ID]) {
|
|
153
|
-
contextId = gqlContext.req[request_constants_1.REQUEST_CONTEXT_ID];
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
contextId = (0, core_1.createContextId)();
|
|
157
|
-
Object.defineProperty(gqlContext, request_constants_1.REQUEST_CONTEXT_ID, {
|
|
158
|
-
value: contextId,
|
|
159
|
-
enumerable: false,
|
|
160
|
-
configurable: false,
|
|
161
|
-
writable: false,
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
return contextId;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
registerContextProvider(request, contextId) {
|
|
168
|
-
const coreModuleArray = [...this.modulesContainer.entries()]
|
|
169
|
-
.filter(
|
|
170
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
171
|
-
([key, { metatype }]) => metatype && metatype.name === internal_core_module_1.InternalCoreModule.name)
|
|
172
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
173
|
-
.map(([key, value]) => value);
|
|
174
|
-
const coreModuleRef = (0, lodash_head_1.default)(coreModuleArray);
|
|
175
|
-
if (!coreModuleRef) {
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
const wrapper = coreModuleRef.getProviderByKey(core_1.REQUEST);
|
|
179
|
-
wrapper.setInstanceByContextId(contextId, {
|
|
180
|
-
instance: request,
|
|
181
|
-
isResolved: true,
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
exports.OpraApiFactory = OpraApiFactory;
|
|
186
|
-
tslib_1.__decorate([
|
|
187
|
-
(0, common_1.Inject)(),
|
|
188
|
-
tslib_1.__metadata("design:type", core_1.ModulesContainer)
|
|
189
|
-
], OpraApiFactory.prototype, "modulesContainer", void 0);
|
|
190
|
-
tslib_1.__decorate([
|
|
191
|
-
(0, common_1.Inject)(),
|
|
192
|
-
tslib_1.__metadata("design:type", external_context_creator_1.ExternalContextCreator)
|
|
193
|
-
], OpraApiFactory.prototype, "externalContextCreator", void 0);
|
|
194
|
-
tslib_1.__decorate([
|
|
195
|
-
(0, common_1.Inject)(),
|
|
196
|
-
tslib_1.__metadata("design:type", nest_explorer_js_1.NestExplorer)
|
|
197
|
-
], OpraApiFactory.prototype, "explorerService", void 0);
|
|
198
|
-
exports.OpraApiFactory = OpraApiFactory = tslib_1.__decorate([
|
|
199
|
-
(0, common_1.Injectable)()
|
|
200
|
-
], OpraApiFactory);
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpraParamsFactory = void 0;
|
|
4
|
-
const handler_paramtype_enum_js_1 = require("../enums/handler-paramtype.enum.js");
|
|
5
|
-
class OpraParamsFactory {
|
|
6
|
-
exchangeKeyForValue(type, data, args) {
|
|
7
|
-
if (!args) {
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
args = Array.isArray(args) ? args : [];
|
|
11
|
-
switch (type) {
|
|
12
|
-
case handler_paramtype_enum_js_1.HandlerParamType.CONTEXT:
|
|
13
|
-
return args[3];
|
|
14
|
-
case handler_paramtype_enum_js_1.HandlerParamType.REQUEST:
|
|
15
|
-
return args[3].request;
|
|
16
|
-
case handler_paramtype_enum_js_1.HandlerParamType.RESPONSE:
|
|
17
|
-
return args[3].response;
|
|
18
|
-
default:
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.OpraParamsFactory = OpraParamsFactory;
|
package/cjs/opra-core.module.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var OpraCoreModule_1;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.OpraCoreModule = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const crypto = tslib_1.__importStar(require("crypto"));
|
|
7
|
-
const common_1 = require("@nestjs/common");
|
|
8
|
-
const core_1 = require("@nestjs/core");
|
|
9
|
-
const metadata_scanner_1 = require("@nestjs/core/metadata-scanner");
|
|
10
|
-
const constants_js_1 = require("./constants.js");
|
|
11
|
-
const opra_api_factory_js_1 = require("./factories/opra-api.factory.js");
|
|
12
|
-
const opra_module_ref_js_1 = require("./opra-module-ref.js");
|
|
13
|
-
const nest_explorer_js_1 = require("./services/nest-explorer.js");
|
|
14
|
-
const opra_api_loader_js_1 = require("./services/opra-api-loader.js");
|
|
15
|
-
let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
|
|
16
|
-
constructor(httpAdapterHost, modulesContainer, options, apiLoader) {
|
|
17
|
-
this.httpAdapterHost = httpAdapterHost;
|
|
18
|
-
this.modulesContainer = modulesContainer;
|
|
19
|
-
this.options = options;
|
|
20
|
-
this.apiLoader = apiLoader;
|
|
21
|
-
}
|
|
22
|
-
static forRoot(options) {
|
|
23
|
-
const providers = [
|
|
24
|
-
...(options.providers || []),
|
|
25
|
-
{
|
|
26
|
-
provide: constants_js_1.OPRA_MODULE_OPTIONS,
|
|
27
|
-
useValue: options,
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
provide: constants_js_1.OPRA_INITIALIZER,
|
|
31
|
-
useClass: opra_api_loader_js_1.OpraApiLoader
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
provide: options.id || opra_module_ref_js_1.OpraModuleRef,
|
|
35
|
-
inject: [constants_js_1.OPRA_INITIALIZER],
|
|
36
|
-
useFactory: (apiLoader) => {
|
|
37
|
-
return apiLoader.opraModuleRef;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
];
|
|
41
|
-
return {
|
|
42
|
-
module: OpraCoreModule_1,
|
|
43
|
-
imports: [...(options.imports || [])],
|
|
44
|
-
exports: [...(options.exports || [])],
|
|
45
|
-
providers
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
static forRootAsync(asyncOptions) {
|
|
49
|
-
return {
|
|
50
|
-
module: OpraCoreModule_1,
|
|
51
|
-
imports: [...(asyncOptions.imports || [])],
|
|
52
|
-
providers: [
|
|
53
|
-
...(asyncOptions.providers || []),
|
|
54
|
-
{
|
|
55
|
-
provide: constants_js_1.OPRA_MODULE_ID,
|
|
56
|
-
useValue: crypto.randomUUID()
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
provide: constants_js_1.OPRA_INITIALIZER,
|
|
60
|
-
useClass: opra_api_loader_js_1.OpraApiLoader
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
provide: asyncOptions.id || opra_module_ref_js_1.OpraModuleRef,
|
|
64
|
-
inject: [constants_js_1.OPRA_INITIALIZER],
|
|
65
|
-
useFactory: (apiLoader) => {
|
|
66
|
-
return apiLoader.opraModuleRef;
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
...this.createAsyncProviders(asyncOptions)
|
|
70
|
-
]
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
static createAsyncProviders(asyncOptions) {
|
|
74
|
-
if (asyncOptions.useExisting || asyncOptions.useFactory)
|
|
75
|
-
return [this.createAsyncOptionsProvider(asyncOptions)];
|
|
76
|
-
if (asyncOptions.useClass)
|
|
77
|
-
return [
|
|
78
|
-
this.createAsyncOptionsProvider(asyncOptions),
|
|
79
|
-
{
|
|
80
|
-
provide: asyncOptions.useClass,
|
|
81
|
-
useClass: asyncOptions.useClass
|
|
82
|
-
}
|
|
83
|
-
];
|
|
84
|
-
throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting');
|
|
85
|
-
}
|
|
86
|
-
static createAsyncOptionsProvider(asyncOptions) {
|
|
87
|
-
if (asyncOptions.useFactory) {
|
|
88
|
-
return {
|
|
89
|
-
provide: constants_js_1.OPRA_MODULE_OPTIONS,
|
|
90
|
-
useFactory: asyncOptions.useFactory,
|
|
91
|
-
inject: asyncOptions.inject || []
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
const useClass = asyncOptions.useClass || asyncOptions.useExisting;
|
|
95
|
-
if (useClass) {
|
|
96
|
-
return {
|
|
97
|
-
provide: constants_js_1.OPRA_MODULE_OPTIONS,
|
|
98
|
-
useFactory: (optionsFactory) => optionsFactory.createOptions(),
|
|
99
|
-
inject: [useClass]
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting');
|
|
103
|
-
}
|
|
104
|
-
async onModuleInit() {
|
|
105
|
-
const httpAdapter = this.httpAdapterHost?.httpAdapter;
|
|
106
|
-
if (!httpAdapter)
|
|
107
|
-
return;
|
|
108
|
-
const opraModule = (() => {
|
|
109
|
-
for (const m of this.modulesContainer.values()) {
|
|
110
|
-
for (const imp of m.imports.values()) {
|
|
111
|
-
for (const prv of imp.providers.values())
|
|
112
|
-
if (prv.instance === this) {
|
|
113
|
-
return imp;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
})();
|
|
118
|
-
if (opraModule) {
|
|
119
|
-
await this.apiLoader.initialize(opraModule);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
async onModuleDestroy() {
|
|
123
|
-
await this.apiLoader.stop();
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
exports.OpraCoreModule = OpraCoreModule;
|
|
127
|
-
exports.OpraCoreModule = OpraCoreModule = OpraCoreModule_1 = tslib_1.__decorate([
|
|
128
|
-
(0, common_1.Module)({
|
|
129
|
-
providers: [
|
|
130
|
-
opra_api_factory_js_1.OpraApiFactory,
|
|
131
|
-
metadata_scanner_1.MetadataScanner,
|
|
132
|
-
nest_explorer_js_1.NestExplorer
|
|
133
|
-
]
|
|
134
|
-
}),
|
|
135
|
-
(0, common_1.Global)(),
|
|
136
|
-
tslib_1.__param(2, (0, common_1.Inject)(constants_js_1.OPRA_MODULE_OPTIONS)),
|
|
137
|
-
tslib_1.__param(3, (0, common_1.Inject)(constants_js_1.OPRA_INITIALIZER)),
|
|
138
|
-
tslib_1.__metadata("design:paramtypes", [core_1.HttpAdapterHost,
|
|
139
|
-
core_1.ModulesContainer, Object, opra_api_loader_js_1.OpraApiLoader])
|
|
140
|
-
], OpraCoreModule);
|
package/cjs/opra-module-ref.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpraModuleRef = void 0;
|
|
4
|
-
const constants_js_1 = require("./constants.js");
|
|
5
|
-
class OpraModuleRef {
|
|
6
|
-
get adapter() {
|
|
7
|
-
return this[constants_js_1.kAdapter];
|
|
8
|
-
}
|
|
9
|
-
get api() {
|
|
10
|
-
return this[constants_js_1.kAdapter].api;
|
|
11
|
-
}
|
|
12
|
-
get options() {
|
|
13
|
-
return this[constants_js_1.kOptions];
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.OpraModuleRef = OpraModuleRef;
|
package/cjs/opra.module.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var OpraModule_1;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.OpraModule = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const common_1 = require("@nestjs/common");
|
|
7
|
-
const opra_core_module_js_1 = require("./opra-core.module.js");
|
|
8
|
-
let OpraModule = OpraModule_1 = class OpraModule {
|
|
9
|
-
static forRoot(options) {
|
|
10
|
-
return {
|
|
11
|
-
module: OpraModule_1,
|
|
12
|
-
imports: [opra_core_module_js_1.OpraCoreModule.forRoot(options)]
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
static forRootAsync(asyncOptions) {
|
|
16
|
-
return {
|
|
17
|
-
module: OpraModule_1,
|
|
18
|
-
imports: [opra_core_module_js_1.OpraCoreModule.forRootAsync(asyncOptions)]
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
exports.OpraModule = OpraModule;
|
|
23
|
-
exports.OpraModule = OpraModule = OpraModule_1 = tslib_1.__decorate([
|
|
24
|
-
(0, common_1.Module)({})
|
|
25
|
-
], OpraModule);
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NestExplorer = void 0;
|
|
4
|
-
const common_1 = require("@opra/common");
|
|
5
|
-
class NestExplorer {
|
|
6
|
-
exploreProviders(rootModule, callback) {
|
|
7
|
-
const modules = new Set();
|
|
8
|
-
const tree = [];
|
|
9
|
-
const scanModules = (m) => {
|
|
10
|
-
if (modules.has(m))
|
|
11
|
-
return;
|
|
12
|
-
modules.add(m);
|
|
13
|
-
tree.push(m);
|
|
14
|
-
for (const mm of m.imports.values()) {
|
|
15
|
-
scanModules(mm);
|
|
16
|
-
}
|
|
17
|
-
for (const wrapper of m.providers.values()) {
|
|
18
|
-
callback(wrapper, tree);
|
|
19
|
-
if (wrapper.host)
|
|
20
|
-
scanModules(wrapper.host);
|
|
21
|
-
}
|
|
22
|
-
tree.pop();
|
|
23
|
-
};
|
|
24
|
-
scanModules(rootModule);
|
|
25
|
-
}
|
|
26
|
-
exploreResources(rootModule, callback) {
|
|
27
|
-
this.exploreProviders(rootModule, (wrapper, tree) => {
|
|
28
|
-
if (wrapper.instance
|
|
29
|
-
&& typeof wrapper.instance === 'object'
|
|
30
|
-
&& wrapper.instance.constructor
|
|
31
|
-
&& common_1.OpraSchema.isResource(Reflect.getMetadata(common_1.RESOURCE_METADATA, wrapper.instance.constructor))) {
|
|
32
|
-
callback(wrapper, tree);
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
exports.NestExplorer = NestExplorer;
|