@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,81 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import { Inject, Logger } from '@nestjs/common';
|
|
3
|
-
import { ApplicationConfig, HttpAdapterHost } from '@nestjs/core';
|
|
4
|
-
import { OpraURLPath } from '@opra/common';
|
|
5
|
-
import { ExpressAdapter } from '@opra/core';
|
|
6
|
-
import { kAdapter, kOptions, OPRA_MODULE_OPTIONS } from '../constants.js';
|
|
7
|
-
import { OpraApiFactory } from '../factories/opra-api.factory.js';
|
|
8
|
-
import { OpraModuleRef } from '../opra-module-ref.js';
|
|
9
|
-
export class OpraApiLoader {
|
|
10
|
-
constructor() {
|
|
11
|
-
this.logger = new Logger(OpraApiLoader.name, { timestamp: true });
|
|
12
|
-
this.opraModuleRef = new OpraModuleRef();
|
|
13
|
-
}
|
|
14
|
-
async initialize(rootModule) {
|
|
15
|
-
const httpAdapter = this.httpAdapterHost?.httpAdapter;
|
|
16
|
-
const globalPrefix = this.applicationConfig.getGlobalPrefix();
|
|
17
|
-
const platformName = httpAdapter.getType();
|
|
18
|
-
const moduleOptions = this.options;
|
|
19
|
-
this.opraModuleRef[kOptions] = this.options;
|
|
20
|
-
let prefixPath = new OpraURLPath((moduleOptions.useGlobalPrefix !== false ? globalPrefix : ''));
|
|
21
|
-
if (moduleOptions.basePath)
|
|
22
|
-
prefixPath = prefixPath.join(moduleOptions.basePath);
|
|
23
|
-
const name = moduleOptions.document?.info?.title || 'untitled service';
|
|
24
|
-
const options = {
|
|
25
|
-
...moduleOptions,
|
|
26
|
-
basePath: prefixPath.toString()
|
|
27
|
-
};
|
|
28
|
-
try {
|
|
29
|
-
const apiDocument = await this.opraFactory.generateService(rootModule, 'http', options.document);
|
|
30
|
-
if (!Object.keys(apiDocument.root).length) {
|
|
31
|
-
this.logger.warn(`No Sources found (${name})`);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (platformName === 'express') {
|
|
35
|
-
this.opraModuleRef[kAdapter] = await this.registerExpress(apiDocument, options);
|
|
36
|
-
// else if (platformName === 'fastify')
|
|
37
|
-
// await this.registerFastify();
|
|
38
|
-
}
|
|
39
|
-
else { // noinspection ExceptionCaughtLocallyJS
|
|
40
|
-
throw new Error(`No support for current HttpAdapter: ${platformName}`);
|
|
41
|
-
}
|
|
42
|
-
this.logger.log(`Mapped {${prefixPath.toString() || '/'}} to "${name}" service`);
|
|
43
|
-
}
|
|
44
|
-
catch (e) {
|
|
45
|
-
this.logger.error(e);
|
|
46
|
-
throw e;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
async stop() {
|
|
50
|
-
//
|
|
51
|
-
}
|
|
52
|
-
async registerExpress(apiDocument, moduleOptions) {
|
|
53
|
-
const httpAdapter = this.httpAdapterHost.httpAdapter;
|
|
54
|
-
/* istanbul ignore next */
|
|
55
|
-
if (!httpAdapter)
|
|
56
|
-
throw new Error('HttpAdapterHost is not initialized');
|
|
57
|
-
const app = httpAdapter.getInstance();
|
|
58
|
-
const logger = moduleOptions.logger ||
|
|
59
|
-
(process.env.NODE_ENV === 'test' ? undefined : new Logger(apiDocument.info.title));
|
|
60
|
-
return await ExpressAdapter.create(app, apiDocument, {
|
|
61
|
-
...moduleOptions,
|
|
62
|
-
logger,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
__decorate([
|
|
67
|
-
Inject(),
|
|
68
|
-
__metadata("design:type", HttpAdapterHost)
|
|
69
|
-
], OpraApiLoader.prototype, "httpAdapterHost", void 0);
|
|
70
|
-
__decorate([
|
|
71
|
-
Inject(),
|
|
72
|
-
__metadata("design:type", ApplicationConfig)
|
|
73
|
-
], OpraApiLoader.prototype, "applicationConfig", void 0);
|
|
74
|
-
__decorate([
|
|
75
|
-
Inject(),
|
|
76
|
-
__metadata("design:type", OpraApiFactory)
|
|
77
|
-
], OpraApiLoader.prototype, "opraFactory", void 0);
|
|
78
|
-
__decorate([
|
|
79
|
-
Inject(OPRA_MODULE_OPTIONS),
|
|
80
|
-
__metadata("design:type", Object)
|
|
81
|
-
], OpraApiLoader.prototype, "options", void 0);
|
package/esm/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/esm/utils/class.utils.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { isFunction, isString } from '@nestjs/common/utils/shared.utils';
|
|
2
|
-
export function isConstructor(obj) {
|
|
3
|
-
return typeof obj === 'function' &&
|
|
4
|
-
!!(obj.prototype && obj.prototype.constructor);
|
|
5
|
-
}
|
|
6
|
-
export function getClassOrUndefined(typeOrFunc) {
|
|
7
|
-
return isConstructor(typeOrFunc)
|
|
8
|
-
? typeOrFunc
|
|
9
|
-
: isFunction(typeOrFunc)
|
|
10
|
-
? typeOrFunc()
|
|
11
|
-
: undefined;
|
|
12
|
-
}
|
|
13
|
-
export function getClassName(nameOrType) {
|
|
14
|
-
if (isString(nameOrType)) {
|
|
15
|
-
return nameOrType;
|
|
16
|
-
}
|
|
17
|
-
const classOrUndefined = getClassOrUndefined(nameOrType);
|
|
18
|
-
return classOrUndefined && classOrUndefined.name;
|
|
19
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { splitString, tokenize } from 'fast-tokenizer';
|
|
2
|
-
export function getNumberOfArguments(fn) {
|
|
3
|
-
const functionAsString = fn.toString();
|
|
4
|
-
const tokenizer = tokenize(functionAsString, {
|
|
5
|
-
// keepBrackets: true,
|
|
6
|
-
keepDelimiters: true,
|
|
7
|
-
keepQuotes: true,
|
|
8
|
-
brackets: {}
|
|
9
|
-
});
|
|
10
|
-
let k = 0;
|
|
11
|
-
let s = '';
|
|
12
|
-
for (const token of tokenizer) {
|
|
13
|
-
if (token.startsWith('(')) {
|
|
14
|
-
s += token.substring(1);
|
|
15
|
-
k++;
|
|
16
|
-
}
|
|
17
|
-
else if (token.startsWith(')')) {
|
|
18
|
-
if (k === 1)
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
else if (k)
|
|
22
|
-
s += token;
|
|
23
|
-
}
|
|
24
|
-
const x = splitString(s, {
|
|
25
|
-
brackets: {
|
|
26
|
-
'{': '}',
|
|
27
|
-
'(': ')',
|
|
28
|
-
'[': ']',
|
|
29
|
-
'/*': '*/'
|
|
30
|
-
}, delimiters: ','
|
|
31
|
-
});
|
|
32
|
-
return x.length > 1 ? x.length : (x[0] ? 1 : 0);
|
|
33
|
-
}
|
package/esm/utils/param.utils.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { PARAM_ARGS_METADATA } from '../constants.js';
|
|
3
|
-
function assignMetadata(args, paramType, index, data, ...pipes) {
|
|
4
|
-
return {
|
|
5
|
-
...args,
|
|
6
|
-
[`${paramType}:${index}`]: {
|
|
7
|
-
index,
|
|
8
|
-
data,
|
|
9
|
-
pipes,
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
export function createOpraParamDecorator(paramType) {
|
|
14
|
-
return (target, key, index) => {
|
|
15
|
-
if (!key)
|
|
16
|
-
return;
|
|
17
|
-
const args = Reflect.getMetadata(PARAM_ARGS_METADATA, target.constructor, key) || {};
|
|
18
|
-
Reflect.defineMetadata(PARAM_ARGS_METADATA, assignMetadata(args, paramType, index), target.constructor, key);
|
|
19
|
-
};
|
|
20
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/types/constants.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare const OPRA_MODULE_OPTIONS = "opra:module_options";
|
|
2
|
-
export declare const OPRA_MODULE_ID = "opra:module_id";
|
|
3
|
-
export declare const OPRA_INITIALIZER = "opra_initializer";
|
|
4
|
-
export declare const kOptions: unique symbol;
|
|
5
|
-
export declare const kAdapter: unique symbol;
|
|
6
|
-
export declare const PARAM_ARGS_METADATA = "__routeArguments__";
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ContextType } from '@nestjs/common';
|
|
2
|
-
import { Module } from '@nestjs/core/injector/module.js';
|
|
3
|
-
import { ApiDocument, ApiDocumentFactory } from '@opra/common';
|
|
4
|
-
export declare class OpraApiFactory {
|
|
5
|
-
private readonly paramsFactory;
|
|
6
|
-
private readonly injector;
|
|
7
|
-
private readonly modulesContainer;
|
|
8
|
-
private readonly externalContextCreator;
|
|
9
|
-
private readonly explorerService;
|
|
10
|
-
generateService(rootModule: Module, contextType: ContextType, apiSchema?: Partial<ApiDocumentFactory.InitArguments>): Promise<ApiDocument>;
|
|
11
|
-
private _createHandler;
|
|
12
|
-
private _createContextCallback;
|
|
13
|
-
private getContextId;
|
|
14
|
-
private registerContextProvider;
|
|
15
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { DynamicModule, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
|
|
2
|
-
import { HttpAdapterHost, ModulesContainer } from '@nestjs/core';
|
|
3
|
-
import { OpraModuleAsyncOptions, OpraModuleOptions } from './interfaces/opra-module-options.interface.js';
|
|
4
|
-
import { OpraApiLoader } from './services/opra-api-loader.js';
|
|
5
|
-
export declare class OpraCoreModule implements OnModuleInit, OnModuleDestroy {
|
|
6
|
-
private readonly httpAdapterHost;
|
|
7
|
-
protected readonly modulesContainer: ModulesContainer;
|
|
8
|
-
private readonly options;
|
|
9
|
-
private readonly apiLoader;
|
|
10
|
-
constructor(httpAdapterHost: HttpAdapterHost, modulesContainer: ModulesContainer, options: OpraModuleOptions, apiLoader: OpraApiLoader);
|
|
11
|
-
static forRoot(options: OpraModuleOptions & Pick<DynamicModule, 'imports' | 'providers' | 'exports'>): DynamicModule;
|
|
12
|
-
static forRootAsync(asyncOptions: OpraModuleAsyncOptions): DynamicModule;
|
|
13
|
-
private static createAsyncProviders;
|
|
14
|
-
private static createAsyncOptionsProvider;
|
|
15
|
-
onModuleInit(): Promise<void>;
|
|
16
|
-
onModuleDestroy(): Promise<void>;
|
|
17
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ApiDocument } from '@opra/common';
|
|
2
|
-
import { PlatformAdapter } from '@opra/core';
|
|
3
|
-
import { kAdapter, kOptions } from './constants.js';
|
|
4
|
-
import { OpraModuleOptions } from './interfaces/opra-module-options.interface.js';
|
|
5
|
-
export declare class OpraModuleRef {
|
|
6
|
-
protected [kOptions]: OpraModuleOptions;
|
|
7
|
-
protected [kAdapter]: PlatformAdapter;
|
|
8
|
-
get adapter(): PlatformAdapter;
|
|
9
|
-
get api(): ApiDocument;
|
|
10
|
-
get options(): OpraModuleOptions;
|
|
11
|
-
}
|
package/types/opra.module.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { DynamicModule } from '@nestjs/common';
|
|
2
|
-
import { OpraModuleAsyncOptions, OpraModuleOptions } from './interfaces/opra-module-options.interface.js';
|
|
3
|
-
export declare class OpraModule {
|
|
4
|
-
static forRoot(options: OpraModuleOptions & Pick<DynamicModule, 'imports' | 'providers' | 'exports'>): DynamicModule;
|
|
5
|
-
static forRootAsync(asyncOptions: OpraModuleAsyncOptions): DynamicModule;
|
|
6
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper';
|
|
2
|
-
import { Module } from '@nestjs/core/injector/module';
|
|
3
|
-
type WrapperCallback = (wrapper: InstanceWrapper, tree: Module[]) => void;
|
|
4
|
-
export declare class NestExplorer {
|
|
5
|
-
exploreProviders(rootModule: Module, callback: WrapperCallback): void;
|
|
6
|
-
exploreResources(rootModule: Module, callback: WrapperCallback): void;
|
|
7
|
-
}
|
|
8
|
-
export {};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@nestjs/common';
|
|
2
|
-
import { ApplicationConfig, HttpAdapterHost } from '@nestjs/core';
|
|
3
|
-
import { Module } from '@nestjs/core/injector/module.js';
|
|
4
|
-
import { ApiDocument } from '@opra/common';
|
|
5
|
-
import { ExpressAdapter } from '@opra/core';
|
|
6
|
-
import { OpraApiFactory } from '../factories/opra-api.factory.js';
|
|
7
|
-
import { OpraModuleOptions } from '../interfaces/opra-module-options.interface.js';
|
|
8
|
-
import { OpraModuleRef } from '../opra-module-ref.js';
|
|
9
|
-
export declare class OpraApiLoader {
|
|
10
|
-
protected readonly logger: Logger;
|
|
11
|
-
readonly opraModuleRef: OpraModuleRef;
|
|
12
|
-
protected readonly httpAdapterHost: HttpAdapterHost;
|
|
13
|
-
protected readonly applicationConfig: ApplicationConfig;
|
|
14
|
-
protected readonly opraFactory: OpraApiFactory;
|
|
15
|
-
protected readonly options: OpraModuleOptions;
|
|
16
|
-
initialize(rootModule: Module): Promise<void>;
|
|
17
|
-
stop(): Promise<void>;
|
|
18
|
-
protected registerExpress(apiDocument: ApiDocument, moduleOptions: OpraModuleOptions): Promise<ExpressAdapter>;
|
|
19
|
-
}
|
package/types/types.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Type } from '@nestjs/common';
|
|
2
|
-
export declare function isConstructor(obj: any): obj is Type;
|
|
3
|
-
export declare function getClassOrUndefined(typeOrFunc: Function | Type): Type | undefined;
|
|
4
|
-
export declare function getClassName(nameOrType: string | Function | Type): string | undefined;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getNumberOfArguments(fn: Function): number | undefined;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { HandlerParamType } from '../enums/handler-paramtype.enum.js';
|
|
3
|
-
export type ParamData = object | string | number;
|
|
4
|
-
export type ParamsMetadata = Record<number, {
|
|
5
|
-
index: number;
|
|
6
|
-
data?: ParamData;
|
|
7
|
-
}>;
|
|
8
|
-
export declare function createOpraParamDecorator(paramType: HandlerParamType): ParameterDecorator;
|