@opra/nestjs 1.0.0-alpha.7 → 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 +12 -11
- package/cjs/opra-http.module.js +3 -2
- package/cjs/opra-nestjs-adapter.js +47 -16
- 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 +12 -11
- package/esm/opra-http.module.js +3 -2
- package/esm/opra-nestjs-adapter.js +49 -17
- package/package.json +9 -7
- 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 +5 -3
- package/types/services/opra-middleware.d.ts +1 -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);
|
|
@@ -3,9 +3,9 @@ var OpraHttpCoreModule_1;
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.OpraHttpCoreModule = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
|
-
const ts_gems_1 = require("ts-gems");
|
|
7
6
|
const common_1 = require("@nestjs/common");
|
|
8
7
|
const common_2 = require("@opra/common");
|
|
8
|
+
const ts_gems_1 = require("ts-gems");
|
|
9
9
|
const opra_nestjs_adapter_js_1 = require("./opra-nestjs-adapter.js");
|
|
10
10
|
const opra_middleware_js_1 = require("./services/opra-middleware.js");
|
|
11
11
|
let OpraHttpCoreModule = OpraHttpCoreModule_1 = class OpraHttpCoreModule {
|
|
@@ -18,32 +18,33 @@ 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
|
},
|
|
35
35
|
},
|
|
36
36
|
];
|
|
37
|
-
if (token !== opra_nestjs_adapter_js_1.OpraNestAdapter)
|
|
37
|
+
if (token !== opra_nestjs_adapter_js_1.OpraNestAdapter) {
|
|
38
38
|
providers.push({
|
|
39
39
|
provide: token,
|
|
40
40
|
useValue: opraAdapter,
|
|
41
41
|
});
|
|
42
|
+
}
|
|
42
43
|
return {
|
|
43
44
|
module: OpraHttpCoreModule_1,
|
|
44
|
-
controllers: opraAdapter.
|
|
45
|
-
imports: [...(
|
|
46
|
-
exports: [...(
|
|
45
|
+
controllers: opraAdapter.nestControllers,
|
|
46
|
+
imports: [...(init?.imports || [])],
|
|
47
|
+
exports: [...(init?.exports || []), token],
|
|
47
48
|
providers,
|
|
48
49
|
};
|
|
49
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
|
};
|
|
@@ -2,56 +2,84 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OpraNestAdapter = exports.kHandler = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
6
|
-
const ts_gems_1 = require("ts-gems");
|
|
7
5
|
const common_1 = require("@nestjs/common");
|
|
8
6
|
const common_2 = require("@opra/common");
|
|
9
7
|
const core_1 = require("@opra/core");
|
|
8
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
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
|
-
this.
|
|
20
|
-
|
|
20
|
+
this.nestControllers = [];
|
|
21
|
+
this.options = options;
|
|
22
|
+
let basePath = options?.basePath || '/';
|
|
21
23
|
if (!basePath.startsWith('/'))
|
|
22
24
|
basePath = '/' + basePath;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
this._addRootController(basePath);
|
|
26
|
+
if (init.controllers)
|
|
27
|
+
init.controllers.forEach(c => this._addToNestControllers(c, basePath));
|
|
25
28
|
}
|
|
26
29
|
async close() {
|
|
27
30
|
//
|
|
28
31
|
}
|
|
29
|
-
|
|
30
|
-
const
|
|
32
|
+
_addRootController(basePath) {
|
|
33
|
+
const _this = this;
|
|
34
|
+
let RootController = class RootController {
|
|
35
|
+
schema(_req, next) {
|
|
36
|
+
_this[exports.kHandler].sendDocumentSchema(_req.opraContext).catch(next);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
tslib_1.__decorate([
|
|
40
|
+
(0, common_1.Get)('/\\$schema'),
|
|
41
|
+
tslib_1.__param(0, (0, common_1.Req)()),
|
|
42
|
+
tslib_1.__param(1, (0, common_1.Next)()),
|
|
43
|
+
tslib_1.__metadata("design:type", Function),
|
|
44
|
+
tslib_1.__metadata("design:paramtypes", [Object, Function]),
|
|
45
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
46
|
+
], RootController.prototype, "schema", null);
|
|
47
|
+
RootController = tslib_1.__decorate([
|
|
48
|
+
(0, common_1.Controller)({
|
|
49
|
+
path: basePath,
|
|
50
|
+
})
|
|
51
|
+
], RootController);
|
|
52
|
+
if (this.options?.schemaRouteIsPublic) {
|
|
53
|
+
(0, public_decorator_1.Public)()(RootController.prototype, 'schema', Object.getOwnPropertyDescriptor(RootController.prototype, 'schema'));
|
|
54
|
+
}
|
|
55
|
+
this.nestControllers.push(RootController);
|
|
56
|
+
}
|
|
57
|
+
_addToNestControllers(sourceClass, currentPath) {
|
|
58
|
+
const metadata = Reflect.getMetadata(common_2.HTTP_CONTROLLER_METADATA, sourceClass);
|
|
31
59
|
if (!metadata)
|
|
32
60
|
return;
|
|
33
61
|
const newClass = {
|
|
34
|
-
[
|
|
62
|
+
[sourceClass.name]: class extends sourceClass {
|
|
35
63
|
},
|
|
36
|
-
}[
|
|
64
|
+
}[sourceClass.name];
|
|
37
65
|
const newPath = metadata.path ? path_1.default.join(currentPath, metadata.path) : currentPath;
|
|
38
66
|
const adapter = this;
|
|
39
67
|
/** Inject exception filter */
|
|
40
68
|
(0, common_1.UseFilters)(new opra_exception_filter_js_1.OpraExceptionFilter(adapter))(newClass);
|
|
41
69
|
(0, common_1.Controller)()(newClass);
|
|
42
|
-
this.
|
|
70
|
+
this.nestControllers.push(newClass);
|
|
43
71
|
if (metadata.operations) {
|
|
44
72
|
for (const [k, v] of Object.entries(metadata.operations)) {
|
|
45
|
-
const operationHandler =
|
|
73
|
+
const operationHandler = sourceClass.prototype[k];
|
|
46
74
|
Object.defineProperty(newClass.prototype, k, {
|
|
47
75
|
writable: true,
|
|
48
76
|
/** NestJS handler method */
|
|
49
77
|
async value(_req) {
|
|
50
78
|
const api = adapter.document.api;
|
|
51
|
-
const controller = api.findController(
|
|
79
|
+
const controller = api.findController(sourceClass);
|
|
52
80
|
const operation = controller?.operations.get(k);
|
|
53
81
|
const context = (0, ts_gems_1.asMutable)(_req.opraContext);
|
|
54
|
-
if (!(context && operation && typeof operationHandler === 'function'))
|
|
82
|
+
if (!(context && operation && typeof operationHandler === 'function')) {
|
|
55
83
|
throw new common_2.NotFoundError({
|
|
56
84
|
message: `No endpoint found for [${_req.method}]${_req.baseUrl}`,
|
|
57
85
|
details: {
|
|
@@ -59,6 +87,7 @@ class OpraNestAdapter extends core_1.HttpAdapter {
|
|
|
59
87
|
method: _req.method,
|
|
60
88
|
},
|
|
61
89
|
});
|
|
90
|
+
}
|
|
62
91
|
/** Configure the HttpContext */
|
|
63
92
|
context.adapter = adapter;
|
|
64
93
|
context.document = adapter.document;
|
|
@@ -114,6 +143,8 @@ class OpraNestAdapter extends core_1.HttpAdapter {
|
|
|
114
143
|
/** Call @Search decorator over new property */
|
|
115
144
|
(0, common_1.Search)(operationPath)(newClass.prototype, k, descriptor);
|
|
116
145
|
break;
|
|
146
|
+
default:
|
|
147
|
+
break;
|
|
117
148
|
}
|
|
118
149
|
}
|
|
119
150
|
}
|
|
@@ -121,7 +152,7 @@ class OpraNestAdapter extends core_1.HttpAdapter {
|
|
|
121
152
|
for (const child of metadata.controllers) {
|
|
122
153
|
if (!(0, common_2.isConstructor)(child))
|
|
123
154
|
throw new TypeError('Controllers should be injectable a class');
|
|
124
|
-
this.
|
|
155
|
+
this._addToNestControllers(child, newPath);
|
|
125
156
|
}
|
|
126
157
|
}
|
|
127
158
|
}
|
package/esm/constants.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const IS_PUBLIC_KEY = 'isPublic';
|
package/esm/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
var OpraHttpCoreModule_1;
|
|
2
2
|
import { __decorate, __metadata } from "tslib";
|
|
3
|
-
import { asMutable } from 'ts-gems';
|
|
4
3
|
import { Global, Module, RequestMethod, } from '@nestjs/common';
|
|
5
4
|
import { ApiDocumentFactory } from '@opra/common';
|
|
5
|
+
import { asMutable } from 'ts-gems';
|
|
6
6
|
import { OpraNestAdapter } from './opra-nestjs-adapter.js';
|
|
7
7
|
import { OpraMiddleware } from './services/opra-middleware.js';
|
|
8
8
|
let OpraHttpCoreModule = OpraHttpCoreModule_1 = class OpraHttpCoreModule {
|
|
@@ -15,32 +15,33 @@ 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
|
},
|
|
32
32
|
},
|
|
33
33
|
];
|
|
34
|
-
if (token !== OpraNestAdapter)
|
|
34
|
+
if (token !== OpraNestAdapter) {
|
|
35
35
|
providers.push({
|
|
36
36
|
provide: token,
|
|
37
37
|
useValue: opraAdapter,
|
|
38
38
|
});
|
|
39
|
+
}
|
|
39
40
|
return {
|
|
40
41
|
module: OpraHttpCoreModule_1,
|
|
41
|
-
controllers: opraAdapter.
|
|
42
|
-
imports: [...(
|
|
43
|
-
exports: [...(
|
|
42
|
+
controllers: opraAdapter.nestControllers,
|
|
43
|
+
imports: [...(init?.imports || [])],
|
|
44
|
+
exports: [...(init?.exports || []), token],
|
|
44
45
|
providers,
|
|
45
46
|
};
|
|
46
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
|
};
|
|
@@ -1,53 +1,82 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { Controller, Delete, Get, Head, Options, Patch, Post, Put, Req, Res, Search, UseFilters, } from '@nestjs/common';
|
|
1
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
+
import { Controller, Delete, Get, Head, Next, Options, Patch, Post, Put, Req, Res, Search, UseFilters, } from '@nestjs/common';
|
|
4
3
|
import { ApiDocument, HTTP_CONTROLLER_METADATA, HttpApi, isConstructor, NotFoundError, } from '@opra/common';
|
|
5
4
|
import { HttpAdapter } from '@opra/core';
|
|
5
|
+
import nodePath from 'path';
|
|
6
|
+
import { asMutable } from 'ts-gems';
|
|
7
|
+
import { Public } from './decorators/public.decorator';
|
|
6
8
|
import { OpraExceptionFilter } from './services/opra-exception-filter.js';
|
|
7
9
|
export const kHandler = Symbol.for('kHandler');
|
|
8
10
|
export class OpraNestAdapter extends HttpAdapter {
|
|
9
|
-
constructor(options) {
|
|
11
|
+
constructor(init, options) {
|
|
10
12
|
super((function () {
|
|
11
13
|
const document = new ApiDocument();
|
|
12
14
|
document.api = new HttpApi(document);
|
|
13
15
|
return document;
|
|
14
16
|
})(), options);
|
|
15
|
-
this.
|
|
16
|
-
|
|
17
|
+
this.nestControllers = [];
|
|
18
|
+
this.options = options;
|
|
19
|
+
let basePath = options?.basePath || '/';
|
|
17
20
|
if (!basePath.startsWith('/'))
|
|
18
21
|
basePath = '/' + basePath;
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
this._addRootController(basePath);
|
|
23
|
+
if (init.controllers)
|
|
24
|
+
init.controllers.forEach(c => this._addToNestControllers(c, basePath));
|
|
21
25
|
}
|
|
22
26
|
async close() {
|
|
23
27
|
//
|
|
24
28
|
}
|
|
25
|
-
|
|
26
|
-
const
|
|
29
|
+
_addRootController(basePath) {
|
|
30
|
+
const _this = this;
|
|
31
|
+
let RootController = class RootController {
|
|
32
|
+
schema(_req, next) {
|
|
33
|
+
_this[kHandler].sendDocumentSchema(_req.opraContext).catch(next);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
__decorate([
|
|
37
|
+
Get('/\\$schema'),
|
|
38
|
+
__param(0, Req()),
|
|
39
|
+
__param(1, Next()),
|
|
40
|
+
__metadata("design:type", Function),
|
|
41
|
+
__metadata("design:paramtypes", [Object, Function]),
|
|
42
|
+
__metadata("design:returntype", void 0)
|
|
43
|
+
], RootController.prototype, "schema", null);
|
|
44
|
+
RootController = __decorate([
|
|
45
|
+
Controller({
|
|
46
|
+
path: basePath,
|
|
47
|
+
})
|
|
48
|
+
], RootController);
|
|
49
|
+
if (this.options?.schemaRouteIsPublic) {
|
|
50
|
+
Public()(RootController.prototype, 'schema', Object.getOwnPropertyDescriptor(RootController.prototype, 'schema'));
|
|
51
|
+
}
|
|
52
|
+
this.nestControllers.push(RootController);
|
|
53
|
+
}
|
|
54
|
+
_addToNestControllers(sourceClass, currentPath) {
|
|
55
|
+
const metadata = Reflect.getMetadata(HTTP_CONTROLLER_METADATA, sourceClass);
|
|
27
56
|
if (!metadata)
|
|
28
57
|
return;
|
|
29
58
|
const newClass = {
|
|
30
|
-
[
|
|
59
|
+
[sourceClass.name]: class extends sourceClass {
|
|
31
60
|
},
|
|
32
|
-
}[
|
|
61
|
+
}[sourceClass.name];
|
|
33
62
|
const newPath = metadata.path ? nodePath.join(currentPath, metadata.path) : currentPath;
|
|
34
63
|
const adapter = this;
|
|
35
64
|
/** Inject exception filter */
|
|
36
65
|
UseFilters(new OpraExceptionFilter(adapter))(newClass);
|
|
37
66
|
Controller()(newClass);
|
|
38
|
-
this.
|
|
67
|
+
this.nestControllers.push(newClass);
|
|
39
68
|
if (metadata.operations) {
|
|
40
69
|
for (const [k, v] of Object.entries(metadata.operations)) {
|
|
41
|
-
const operationHandler =
|
|
70
|
+
const operationHandler = sourceClass.prototype[k];
|
|
42
71
|
Object.defineProperty(newClass.prototype, k, {
|
|
43
72
|
writable: true,
|
|
44
73
|
/** NestJS handler method */
|
|
45
74
|
async value(_req) {
|
|
46
75
|
const api = adapter.document.api;
|
|
47
|
-
const controller = api.findController(
|
|
76
|
+
const controller = api.findController(sourceClass);
|
|
48
77
|
const operation = controller?.operations.get(k);
|
|
49
78
|
const context = asMutable(_req.opraContext);
|
|
50
|
-
if (!(context && operation && typeof operationHandler === 'function'))
|
|
79
|
+
if (!(context && operation && typeof operationHandler === 'function')) {
|
|
51
80
|
throw new NotFoundError({
|
|
52
81
|
message: `No endpoint found for [${_req.method}]${_req.baseUrl}`,
|
|
53
82
|
details: {
|
|
@@ -55,6 +84,7 @@ export class OpraNestAdapter extends HttpAdapter {
|
|
|
55
84
|
method: _req.method,
|
|
56
85
|
},
|
|
57
86
|
});
|
|
87
|
+
}
|
|
58
88
|
/** Configure the HttpContext */
|
|
59
89
|
context.adapter = adapter;
|
|
60
90
|
context.document = adapter.document;
|
|
@@ -110,6 +140,8 @@ export class OpraNestAdapter extends HttpAdapter {
|
|
|
110
140
|
/** Call @Search decorator over new property */
|
|
111
141
|
Search(operationPath)(newClass.prototype, k, descriptor);
|
|
112
142
|
break;
|
|
143
|
+
default:
|
|
144
|
+
break;
|
|
113
145
|
}
|
|
114
146
|
}
|
|
115
147
|
}
|
|
@@ -117,7 +149,7 @@ export class OpraNestAdapter extends HttpAdapter {
|
|
|
117
149
|
for (const child of metadata.controllers) {
|
|
118
150
|
if (!isConstructor(child))
|
|
119
151
|
throw new TypeError('Controllers should be injectable a class');
|
|
120
|
-
this.
|
|
152
|
+
this._addToNestControllers(child, newPath);
|
|
121
153
|
}
|
|
122
154
|
}
|
|
123
155
|
}
|
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,21 +27,23 @@
|
|
|
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"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@nestjs/common": "^10.3.
|
|
38
|
-
"@nestjs/core": "^10.3.
|
|
37
|
+
"@nestjs/common": "^10.3.10",
|
|
38
|
+
"@nestjs/core": "^10.3.10"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@nestjs/platform-express": "^10.3.
|
|
42
|
-
"@nestjs/testing": "^10.3.
|
|
41
|
+
"@nestjs/platform-express": "^10.3.10",
|
|
42
|
+
"@nestjs/testing": "^10.3.10",
|
|
43
43
|
"@types/lodash.head": "^4.0.9",
|
|
44
44
|
"filedirname": "^3.4.0",
|
|
45
|
+
"rxjs": "^7.8.1",
|
|
46
|
+
"supertest": "^7.0.0",
|
|
45
47
|
"ts-gems": "^3.4.0"
|
|
46
48
|
},
|
|
47
49
|
"type": "module",
|
|
@@ -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
|
}
|
|
@@ -3,8 +3,10 @@ import { HttpAdapter } from '@opra/core';
|
|
|
3
3
|
import type { OpraHttpModule } from './opra-http.module';
|
|
4
4
|
export declare const kHandler: unique symbol;
|
|
5
5
|
export declare class OpraNestAdapter extends HttpAdapter {
|
|
6
|
-
readonly
|
|
7
|
-
|
|
6
|
+
readonly nestControllers: Type[];
|
|
7
|
+
readonly options?: OpraHttpModule.Options;
|
|
8
|
+
constructor(init: OpraHttpModule.Initiator, options?: OpraHttpModule.Options);
|
|
8
9
|
close(): Promise<void>;
|
|
9
|
-
protected
|
|
10
|
+
protected _addRootController(basePath: string): void;
|
|
11
|
+
protected _addToNestControllers(sourceClass: Type, currentPath: string): void;
|
|
10
12
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { NextFunction, Request, Response } from 'express';
|
|
2
1
|
import { NestMiddleware } from '@nestjs/common';
|
|
2
|
+
import type { NextFunction, Request, Response } from 'express';
|
|
3
3
|
export declare class OpraMiddleware implements NestMiddleware {
|
|
4
4
|
use(req: Request, res: Response, next: NextFunction): void;
|
|
5
5
|
}
|