@opra/nestjs 1.0.0-alpha.8 → 1.0.0-alpha.9
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/cjs/constants.js +4 -0
- package/cjs/decorators/public.decorator.js +7 -0
- package/cjs/index.js +2 -0
- package/cjs/opra-http-core.module.js +8 -8
- package/cjs/opra-http.module.js +3 -2
- package/cjs/opra-nestjs-adapter.js +9 -4
- package/esm/constants.js +1 -0
- package/esm/decorators/public.decorator.js +3 -0
- package/esm/index.js +2 -0
- package/esm/opra-http-core.module.js +8 -8
- package/esm/opra-http.module.js +3 -2
- package/esm/opra-nestjs-adapter.js +9 -4
- package/package.json +3 -3
- package/types/constants.d.ts +1 -0
- package/types/decorators/public.decorator.d.ts +1 -0
- package/types/index.d.ts +2 -0
- package/types/opra-http-core.module.d.ts +1 -1
- package/types/opra-http.module.d.ts +6 -2
- package/types/opra-nestjs-adapter.d.ts +2 -1
package/cjs/constants.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Public = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const constants_js_1 = require("../constants.js");
|
|
6
|
+
const Public = () => (0, common_1.SetMetadata)(constants_js_1.IS_PUBLIC_KEY, true);
|
|
7
|
+
exports.Public = Public;
|
package/cjs/index.js
CHANGED
|
@@ -3,5 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
require("./augmentation/nestjs.augmentation.js");
|
|
6
|
+
tslib_1.__exportStar(require("./constants.js"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./decorators/public.decorator.js"), exports);
|
|
6
8
|
tslib_1.__exportStar(require("./opra-http.module.js"), exports);
|
|
7
9
|
tslib_1.__exportStar(require("./opra-nestjs-adapter.js"), exports);
|
|
@@ -18,17 +18,17 @@ let OpraHttpCoreModule = OpraHttpCoreModule_1 = class OpraHttpCoreModule {
|
|
|
18
18
|
method: common_1.RequestMethod.ALL,
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
-
static forRoot(options) {
|
|
22
|
-
const opraAdapter = new opra_nestjs_adapter_js_1.OpraNestAdapter(options);
|
|
23
|
-
const token =
|
|
21
|
+
static forRoot(init, options) {
|
|
22
|
+
const opraAdapter = new opra_nestjs_adapter_js_1.OpraNestAdapter(init, options);
|
|
23
|
+
const token = init?.id || opra_nestjs_adapter_js_1.OpraNestAdapter;
|
|
24
24
|
const providers = [
|
|
25
|
-
...(
|
|
25
|
+
...(init?.providers || []),
|
|
26
26
|
{
|
|
27
27
|
provide: opra_nestjs_adapter_js_1.OpraNestAdapter,
|
|
28
28
|
useFactory: async () => {
|
|
29
29
|
(0, ts_gems_1.asMutable)(opraAdapter).document = await common_2.ApiDocumentFactory.createDocument({
|
|
30
|
-
...
|
|
31
|
-
api: { protocol: 'http', name:
|
|
30
|
+
...init,
|
|
31
|
+
api: { protocol: 'http', name: init.name, controllers: init.controllers },
|
|
32
32
|
});
|
|
33
33
|
return opraAdapter;
|
|
34
34
|
},
|
|
@@ -43,8 +43,8 @@ let OpraHttpCoreModule = OpraHttpCoreModule_1 = class OpraHttpCoreModule {
|
|
|
43
43
|
return {
|
|
44
44
|
module: OpraHttpCoreModule_1,
|
|
45
45
|
controllers: opraAdapter.nestControllers,
|
|
46
|
-
imports: [...(
|
|
47
|
-
exports: [...(
|
|
46
|
+
imports: [...(init?.imports || [])],
|
|
47
|
+
exports: [...(init?.exports || []), token],
|
|
48
48
|
providers,
|
|
49
49
|
};
|
|
50
50
|
}
|
package/cjs/opra-http.module.js
CHANGED
|
@@ -8,12 +8,13 @@ const opra_http_core_module_js_1 = require("./opra-http-core.module.js");
|
|
|
8
8
|
let OpraHttpModule = OpraHttpModule_1 = class OpraHttpModule {
|
|
9
9
|
/**
|
|
10
10
|
*
|
|
11
|
+
* @param init
|
|
11
12
|
* @param options
|
|
12
13
|
*/
|
|
13
|
-
static forRoot(options) {
|
|
14
|
+
static forRoot(init, options) {
|
|
14
15
|
return {
|
|
15
16
|
module: OpraHttpModule_1,
|
|
16
|
-
imports: [opra_http_core_module_js_1.OpraHttpCoreModule.forRoot(options)],
|
|
17
|
+
imports: [opra_http_core_module_js_1.OpraHttpCoreModule.forRoot(init, options)],
|
|
17
18
|
};
|
|
18
19
|
}
|
|
19
20
|
};
|
|
@@ -7,22 +7,24 @@ const common_2 = require("@opra/common");
|
|
|
7
7
|
const core_1 = require("@opra/core");
|
|
8
8
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
9
9
|
const ts_gems_1 = require("ts-gems");
|
|
10
|
+
const public_decorator_1 = require("./decorators/public.decorator");
|
|
10
11
|
const opra_exception_filter_js_1 = require("./services/opra-exception-filter.js");
|
|
11
12
|
exports.kHandler = Symbol.for('kHandler');
|
|
12
13
|
class OpraNestAdapter extends core_1.HttpAdapter {
|
|
13
|
-
constructor(options) {
|
|
14
|
+
constructor(init, options) {
|
|
14
15
|
super((function () {
|
|
15
16
|
const document = new common_2.ApiDocument();
|
|
16
17
|
document.api = new common_2.HttpApi(document);
|
|
17
18
|
return document;
|
|
18
19
|
})(), options);
|
|
19
20
|
this.nestControllers = [];
|
|
20
|
-
|
|
21
|
+
this.options = options;
|
|
22
|
+
let basePath = options?.basePath || '/';
|
|
21
23
|
if (!basePath.startsWith('/'))
|
|
22
24
|
basePath = '/' + basePath;
|
|
23
25
|
this._addRootController(basePath);
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
+
if (init.controllers)
|
|
27
|
+
init.controllers.forEach(c => this._addToNestControllers(c, basePath));
|
|
26
28
|
}
|
|
27
29
|
async close() {
|
|
28
30
|
//
|
|
@@ -47,6 +49,9 @@ class OpraNestAdapter extends core_1.HttpAdapter {
|
|
|
47
49
|
path: basePath,
|
|
48
50
|
})
|
|
49
51
|
], RootController);
|
|
52
|
+
if (this.options?.schemaRouteIsPublic) {
|
|
53
|
+
(0, public_decorator_1.Public)()(RootController.prototype, 'schema', Object.getOwnPropertyDescriptor(RootController.prototype, 'schema'));
|
|
54
|
+
}
|
|
50
55
|
this.nestControllers.push(RootController);
|
|
51
56
|
}
|
|
52
57
|
_addToNestControllers(sourceClass, currentPath) {
|
package/esm/constants.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const IS_PUBLIC_KEY = 'isPublic';
|
package/esm/index.js
CHANGED
|
@@ -15,17 +15,17 @@ let OpraHttpCoreModule = OpraHttpCoreModule_1 = class OpraHttpCoreModule {
|
|
|
15
15
|
method: RequestMethod.ALL,
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
|
-
static forRoot(options) {
|
|
19
|
-
const opraAdapter = new OpraNestAdapter(options);
|
|
20
|
-
const token =
|
|
18
|
+
static forRoot(init, options) {
|
|
19
|
+
const opraAdapter = new OpraNestAdapter(init, options);
|
|
20
|
+
const token = init?.id || OpraNestAdapter;
|
|
21
21
|
const providers = [
|
|
22
|
-
...(
|
|
22
|
+
...(init?.providers || []),
|
|
23
23
|
{
|
|
24
24
|
provide: OpraNestAdapter,
|
|
25
25
|
useFactory: async () => {
|
|
26
26
|
asMutable(opraAdapter).document = await ApiDocumentFactory.createDocument({
|
|
27
|
-
...
|
|
28
|
-
api: { protocol: 'http', name:
|
|
27
|
+
...init,
|
|
28
|
+
api: { protocol: 'http', name: init.name, controllers: init.controllers },
|
|
29
29
|
});
|
|
30
30
|
return opraAdapter;
|
|
31
31
|
},
|
|
@@ -40,8 +40,8 @@ let OpraHttpCoreModule = OpraHttpCoreModule_1 = class OpraHttpCoreModule {
|
|
|
40
40
|
return {
|
|
41
41
|
module: OpraHttpCoreModule_1,
|
|
42
42
|
controllers: opraAdapter.nestControllers,
|
|
43
|
-
imports: [...(
|
|
44
|
-
exports: [...(
|
|
43
|
+
imports: [...(init?.imports || [])],
|
|
44
|
+
exports: [...(init?.exports || []), token],
|
|
45
45
|
providers,
|
|
46
46
|
};
|
|
47
47
|
}
|
package/esm/opra-http.module.js
CHANGED
|
@@ -5,12 +5,13 @@ import { OpraHttpCoreModule } from './opra-http-core.module.js';
|
|
|
5
5
|
let OpraHttpModule = OpraHttpModule_1 = class OpraHttpModule {
|
|
6
6
|
/**
|
|
7
7
|
*
|
|
8
|
+
* @param init
|
|
8
9
|
* @param options
|
|
9
10
|
*/
|
|
10
|
-
static forRoot(options) {
|
|
11
|
+
static forRoot(init, options) {
|
|
11
12
|
return {
|
|
12
13
|
module: OpraHttpModule_1,
|
|
13
|
-
imports: [OpraHttpCoreModule.forRoot(options)],
|
|
14
|
+
imports: [OpraHttpCoreModule.forRoot(init, options)],
|
|
14
15
|
};
|
|
15
16
|
}
|
|
16
17
|
};
|
|
@@ -4,22 +4,24 @@ import { ApiDocument, HTTP_CONTROLLER_METADATA, HttpApi, isConstructor, NotFound
|
|
|
4
4
|
import { HttpAdapter } from '@opra/core';
|
|
5
5
|
import nodePath from 'path';
|
|
6
6
|
import { asMutable } from 'ts-gems';
|
|
7
|
+
import { Public } from './decorators/public.decorator';
|
|
7
8
|
import { OpraExceptionFilter } from './services/opra-exception-filter.js';
|
|
8
9
|
export const kHandler = Symbol.for('kHandler');
|
|
9
10
|
export class OpraNestAdapter extends HttpAdapter {
|
|
10
|
-
constructor(options) {
|
|
11
|
+
constructor(init, options) {
|
|
11
12
|
super((function () {
|
|
12
13
|
const document = new ApiDocument();
|
|
13
14
|
document.api = new HttpApi(document);
|
|
14
15
|
return document;
|
|
15
16
|
})(), options);
|
|
16
17
|
this.nestControllers = [];
|
|
17
|
-
|
|
18
|
+
this.options = options;
|
|
19
|
+
let basePath = options?.basePath || '/';
|
|
18
20
|
if (!basePath.startsWith('/'))
|
|
19
21
|
basePath = '/' + basePath;
|
|
20
22
|
this._addRootController(basePath);
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
+
if (init.controllers)
|
|
24
|
+
init.controllers.forEach(c => this._addToNestControllers(c, basePath));
|
|
23
25
|
}
|
|
24
26
|
async close() {
|
|
25
27
|
//
|
|
@@ -44,6 +46,9 @@ export class OpraNestAdapter extends HttpAdapter {
|
|
|
44
46
|
path: basePath,
|
|
45
47
|
})
|
|
46
48
|
], RootController);
|
|
49
|
+
if (this.options?.schemaRouteIsPublic) {
|
|
50
|
+
Public()(RootController.prototype, 'schema', Object.getOwnPropertyDescriptor(RootController.prototype, 'schema'));
|
|
51
|
+
}
|
|
47
52
|
this.nestControllers.push(RootController);
|
|
48
53
|
}
|
|
49
54
|
_addToNestControllers(sourceClass, currentPath) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/nestjs",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.9",
|
|
4
4
|
"description": "Opra NestJS module",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"clean:cover": "rimraf ../../coverage/client"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@opra/common": "^1.0.0-alpha.
|
|
31
|
-
"@opra/core": "^1.0.0-alpha.
|
|
30
|
+
"@opra/common": "^1.0.0-alpha.9",
|
|
31
|
+
"@opra/core": "^1.0.0-alpha.9",
|
|
32
32
|
"fast-tokenizer": "^1.3.0",
|
|
33
33
|
"lodash.head": "^4.0.1",
|
|
34
34
|
"reflect-metadata": "^0.2.2"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const IS_PUBLIC_KEY = "isPublic";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const Public: () => import("@nestjs/common").CustomDecorator<string>;
|
package/types/index.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ export declare class OpraHttpCoreModule implements OnModuleDestroy, NestModule {
|
|
|
5
5
|
protected opraAdapter: OpraNestAdapter;
|
|
6
6
|
constructor(opraAdapter: OpraNestAdapter);
|
|
7
7
|
configure(consumer: MiddlewareConsumer): void;
|
|
8
|
-
static forRoot(
|
|
8
|
+
static forRoot(init: OpraHttpModule.Initiator, options?: OpraHttpModule.Options): DynamicModule;
|
|
9
9
|
onModuleDestroy(): Promise<void>;
|
|
10
10
|
}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { DynamicModule } from '@nestjs/common';
|
|
2
2
|
import { ApiDocumentFactory } from '@opra/common';
|
|
3
3
|
export declare namespace OpraHttpModule {
|
|
4
|
-
interface
|
|
4
|
+
interface Initiator extends Pick<DynamicModule, 'imports' | 'providers' | 'exports' | 'controllers'>, Pick<ApiDocumentFactory.InitArguments, 'types' | 'references' | 'info'> {
|
|
5
5
|
id?: any;
|
|
6
6
|
name: string;
|
|
7
|
+
}
|
|
8
|
+
interface Options {
|
|
7
9
|
basePath?: string;
|
|
10
|
+
schemaRouteIsPublic?: boolean;
|
|
8
11
|
}
|
|
9
12
|
}
|
|
10
13
|
export declare class OpraHttpModule {
|
|
11
14
|
/**
|
|
12
15
|
*
|
|
16
|
+
* @param init
|
|
13
17
|
* @param options
|
|
14
18
|
*/
|
|
15
|
-
static forRoot(
|
|
19
|
+
static forRoot(init: OpraHttpModule.Initiator, options?: OpraHttpModule.Options): DynamicModule;
|
|
16
20
|
}
|
|
@@ -4,7 +4,8 @@ import type { OpraHttpModule } from './opra-http.module';
|
|
|
4
4
|
export declare const kHandler: unique symbol;
|
|
5
5
|
export declare class OpraNestAdapter extends HttpAdapter {
|
|
6
6
|
readonly nestControllers: Type[];
|
|
7
|
-
|
|
7
|
+
readonly options?: OpraHttpModule.Options;
|
|
8
|
+
constructor(init: OpraHttpModule.Initiator, options?: OpraHttpModule.Options);
|
|
8
9
|
close(): Promise<void>;
|
|
9
10
|
protected _addRootController(basePath: string): void;
|
|
10
11
|
protected _addToNestControllers(sourceClass: Type, currentPath: string): void;
|