@opra/nestjs 0.33.13 → 1.0.0-alpha.10

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.
Files changed (74) hide show
  1. package/README.md +1 -0
  2. package/cjs/augmentation/http-controller.augmentation.js +16 -0
  3. package/cjs/constants.js +2 -7
  4. package/cjs/decorators/public.decorator.js +7 -0
  5. package/cjs/index.js +4 -5
  6. package/cjs/interfaces/opra-module-options.interface.js +16 -1
  7. package/cjs/opra-http-core.module.js +60 -0
  8. package/cjs/opra-http.module.js +24 -0
  9. package/cjs/opra-nestjs-adapter.js +160 -0
  10. package/cjs/services/opra-exception-filter.js +14 -13
  11. package/cjs/services/opra-middleware.js +24 -0
  12. package/esm/augmentation/http-controller.augmentation.js +16 -0
  13. package/esm/constants.js +1 -6
  14. package/esm/decorators/public.decorator.js +3 -0
  15. package/esm/index.js +4 -5
  16. package/esm/interfaces/opra-module-options.interface.js +17 -1
  17. package/esm/opra-http-core.module.js +57 -0
  18. package/esm/opra-http.module.js +21 -0
  19. package/esm/opra-nestjs-adapter.js +156 -0
  20. package/esm/services/opra-exception-filter.js +13 -13
  21. package/esm/services/opra-middleware.js +21 -0
  22. package/package.json +16 -13
  23. package/types/augmentation/http-controller.augmentation.d.ts +0 -0
  24. package/types/constants.d.ts +1 -6
  25. package/types/decorators/public.decorator.d.ts +1 -0
  26. package/types/index.d.ts +4 -5
  27. package/types/interfaces/opra-module-options.interface.d.ts +0 -25
  28. package/types/opra-http-core.module.d.ts +10 -0
  29. package/types/opra-http.module.d.ts +20 -0
  30. package/types/opra-nestjs-adapter.d.ts +12 -0
  31. package/types/services/opra-exception-filter.d.ts +6 -2
  32. package/types/services/opra-middleware.d.ts +5 -0
  33. package/cjs/augmentation/common-decorator.augmentation.js +0 -40
  34. package/cjs/decorators/context.decorator.js +0 -10
  35. package/cjs/enums/handler-paramtype.enum.js +0 -9
  36. package/cjs/factories/opra-api.factory.js +0 -200
  37. package/cjs/factories/params.factory.js +0 -23
  38. package/cjs/opra-core.module.js +0 -140
  39. package/cjs/opra-module-ref.js +0 -16
  40. package/cjs/opra.module.js +0 -25
  41. package/cjs/services/nest-explorer.js +0 -38
  42. package/cjs/services/opra-api-loader.js +0 -85
  43. package/cjs/types.js +0 -2
  44. package/cjs/utils/class.utils.js +0 -25
  45. package/cjs/utils/function.utils.js +0 -37
  46. package/cjs/utils/param.utils.js +0 -24
  47. package/esm/augmentation/common-decorator.augmentation.js +0 -38
  48. package/esm/decorators/context.decorator.js +0 -7
  49. package/esm/enums/handler-paramtype.enum.js +0 -6
  50. package/esm/factories/opra-api.factory.js +0 -197
  51. package/esm/factories/params.factory.js +0 -19
  52. package/esm/opra-core.module.js +0 -137
  53. package/esm/opra-module-ref.js +0 -12
  54. package/esm/opra.module.js +0 -22
  55. package/esm/services/nest-explorer.js +0 -34
  56. package/esm/services/opra-api-loader.js +0 -81
  57. package/esm/types.js +0 -1
  58. package/esm/utils/class.utils.js +0 -19
  59. package/esm/utils/function.utils.js +0 -33
  60. package/esm/utils/param.utils.js +0 -20
  61. package/types/augmentation/common-decorator.augmentation.d.ts +0 -1
  62. package/types/decorators/context.decorator.d.ts +0 -5
  63. package/types/enums/handler-paramtype.enum.d.ts +0 -5
  64. package/types/factories/opra-api.factory.d.ts +0 -15
  65. package/types/factories/params.factory.d.ts +0 -4
  66. package/types/opra-core.module.d.ts +0 -17
  67. package/types/opra-module-ref.d.ts +0 -11
  68. package/types/opra.module.d.ts +0 -6
  69. package/types/services/nest-explorer.d.ts +0 -8
  70. package/types/services/opra-api-loader.d.ts +0 -19
  71. package/types/types.d.ts +0 -2
  72. package/types/utils/class.utils.d.ts +0 -4
  73. package/types/utils/function.utils.d.ts +0 -1
  74. package/types/utils/param.utils.d.ts +0 -8
package/README.md CHANGED
@@ -1,2 +1,3 @@
1
1
  # OPRA
2
+
2
3
  Open Protocol for Restful Api
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ // import { Controller } from '@nestjs/common';
3
+ // import { DECORATOR, HttpController } from '@opra/common';
4
+ //
5
+ // /*
6
+ // Overrides HttpController decorator function to call NestJS's Controller() when decorator called
7
+ // */
8
+ // const oldHttpControllerDecorator = HttpController[DECORATOR];
9
+ // HttpController[DECORATOR] = function HttpControllerDecorator(options?: HttpController.Options) {
10
+ // const opraControllerDecorator = oldHttpControllerDecorator(options);
11
+ // const nestControllerDecorator = Controller({});
12
+ // return (target: Function) => {
13
+ // opraControllerDecorator(target);
14
+ // nestControllerDecorator(target);
15
+ // };
16
+ // };
package/cjs/constants.js CHANGED
@@ -1,9 +1,4 @@
1
1
  "use strict";
2
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__';
3
+ exports.IS_PUBLIC_KEY = void 0;
4
+ exports.IS_PUBLIC_KEY = 'isPublic';
@@ -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
@@ -2,9 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  require("reflect-metadata");
5
- require("./augmentation/common-decorator.augmentation.js");
6
5
  require("./augmentation/nestjs.augmentation.js");
7
- tslib_1.__exportStar(require("./opra.module.js"), exports);
8
- tslib_1.__exportStar(require("./decorators/context.decorator.js"), exports);
9
- tslib_1.__exportStar(require("./interfaces/opra-module-options.interface.js"), exports);
10
- tslib_1.__exportStar(require("./opra-module-ref.js"), exports);
6
+ tslib_1.__exportStar(require("./constants.js"), exports);
7
+ tslib_1.__exportStar(require("./decorators/public.decorator.js"), exports);
8
+ tslib_1.__exportStar(require("./opra-http.module.js"), exports);
9
+ tslib_1.__exportStar(require("./opra-nestjs-adapter.js"), exports);
@@ -1,2 +1,17 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+ // import { ApiDocumentFactory } from '@opra/common';
3
+ // import { ExpressAdapter, HttpAdapter } from '@opra/core';
4
+ // export interface OpraModuleOptions extends HttpAdapter.Options {
5
+ // id?: any;
6
+ // document?: Partial<ApiDocumentFactory.InitArguments>;
7
+ //
8
+ // /**
9
+ // * @default true
10
+ // */
11
+ // useGlobalPrefix?: boolean;
12
+ // }
13
+ // export interface ExpressModuleOptions extends OpraModuleOptions, HttpAdapter.Options {}
14
+ // type OpraModuleOptionsWithoutId = Omit<OpraModuleOptions, 'id'>;
15
+ // export interface OpraModuleOptionsFactory {
16
+ // createOptions(): Promise<OpraModuleOptionsWithoutId> | OpraModuleOptionsWithoutId;
17
+ // }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var OpraHttpCoreModule_1;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.OpraHttpCoreModule = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const common_1 = require("@nestjs/common");
7
+ const common_2 = require("@opra/common");
8
+ const ts_gems_1 = require("ts-gems");
9
+ const opra_nestjs_adapter_js_1 = require("./opra-nestjs-adapter.js");
10
+ const opra_middleware_js_1 = require("./services/opra-middleware.js");
11
+ let OpraHttpCoreModule = OpraHttpCoreModule_1 = class OpraHttpCoreModule {
12
+ constructor(opraAdapter) {
13
+ this.opraAdapter = opraAdapter;
14
+ }
15
+ configure(consumer) {
16
+ consumer.apply(opra_middleware_js_1.OpraMiddleware).forRoutes({
17
+ path: '*',
18
+ method: common_1.RequestMethod.ALL,
19
+ });
20
+ }
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
+ const providers = [
25
+ ...(init?.providers || []),
26
+ {
27
+ provide: opra_nestjs_adapter_js_1.OpraNestAdapter,
28
+ useFactory: async () => {
29
+ (0, ts_gems_1.asMutable)(opraAdapter).document = await common_2.ApiDocumentFactory.createDocument({
30
+ ...init,
31
+ api: { protocol: 'http', name: init.name, controllers: init.controllers },
32
+ });
33
+ return opraAdapter;
34
+ },
35
+ },
36
+ ];
37
+ if (token !== opra_nestjs_adapter_js_1.OpraNestAdapter) {
38
+ providers.push({
39
+ provide: token,
40
+ useValue: opraAdapter,
41
+ });
42
+ }
43
+ return {
44
+ module: OpraHttpCoreModule_1,
45
+ controllers: opraAdapter.nestControllers,
46
+ imports: [...(init?.imports || [])],
47
+ exports: [...(init?.exports || []), token],
48
+ providers,
49
+ };
50
+ }
51
+ async onModuleDestroy() {
52
+ await this.opraAdapter.close();
53
+ }
54
+ };
55
+ exports.OpraHttpCoreModule = OpraHttpCoreModule;
56
+ exports.OpraHttpCoreModule = OpraHttpCoreModule = OpraHttpCoreModule_1 = tslib_1.__decorate([
57
+ (0, common_1.Module)({}),
58
+ (0, common_1.Global)(),
59
+ tslib_1.__metadata("design:paramtypes", [opra_nestjs_adapter_js_1.OpraNestAdapter])
60
+ ], OpraHttpCoreModule);
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var OpraHttpModule_1;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.OpraHttpModule = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const common_1 = require("@nestjs/common");
7
+ const opra_http_core_module_js_1 = require("./opra-http-core.module.js");
8
+ let OpraHttpModule = OpraHttpModule_1 = class OpraHttpModule {
9
+ /**
10
+ *
11
+ * @param init
12
+ * @param options
13
+ */
14
+ static forRoot(init, options) {
15
+ return {
16
+ module: OpraHttpModule_1,
17
+ imports: [opra_http_core_module_js_1.OpraHttpCoreModule.forRoot(init, options)],
18
+ };
19
+ }
20
+ };
21
+ exports.OpraHttpModule = OpraHttpModule;
22
+ exports.OpraHttpModule = OpraHttpModule = OpraHttpModule_1 = tslib_1.__decorate([
23
+ (0, common_1.Module)({})
24
+ ], OpraHttpModule);
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpraNestAdapter = exports.kHandler = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const common_2 = require("@opra/common");
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");
11
+ const opra_exception_filter_js_1 = require("./services/opra-exception-filter.js");
12
+ exports.kHandler = Symbol.for('kHandler');
13
+ class OpraNestAdapter extends core_1.HttpAdapter {
14
+ constructor(init, options) {
15
+ super((function () {
16
+ const document = new common_2.ApiDocument();
17
+ document.api = new common_2.HttpApi(document);
18
+ return document;
19
+ })(), options);
20
+ this.nestControllers = [];
21
+ this.options = options;
22
+ let basePath = options?.basePath || '/';
23
+ if (!basePath.startsWith('/'))
24
+ basePath = '/' + basePath;
25
+ this._addRootController(basePath);
26
+ if (init.controllers)
27
+ init.controllers.forEach(c => this._addToNestControllers(c, basePath));
28
+ }
29
+ async close() {
30
+ //
31
+ }
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);
59
+ if (!metadata)
60
+ return;
61
+ const newClass = {
62
+ [sourceClass.name]: class extends sourceClass {
63
+ },
64
+ }[sourceClass.name];
65
+ const newPath = metadata.path ? path_1.default.join(currentPath, metadata.path) : currentPath;
66
+ const adapter = this;
67
+ /** Inject exception filter */
68
+ (0, common_1.UseFilters)(new opra_exception_filter_js_1.OpraExceptionFilter(adapter))(newClass);
69
+ (0, common_1.Controller)()(newClass);
70
+ this.nestControllers.push(newClass);
71
+ if (metadata.operations) {
72
+ for (const [k, v] of Object.entries(metadata.operations)) {
73
+ const operationHandler = sourceClass.prototype[k];
74
+ Object.defineProperty(newClass.prototype, k, {
75
+ writable: true,
76
+ /** NestJS handler method */
77
+ async value(_req) {
78
+ const api = adapter.document.api;
79
+ const controller = api.findController(sourceClass);
80
+ const operation = controller?.operations.get(k);
81
+ const context = (0, ts_gems_1.asMutable)(_req.opraContext);
82
+ if (!(context && operation && typeof operationHandler === 'function')) {
83
+ throw new common_2.NotFoundError({
84
+ message: `No endpoint found for [${_req.method}]${_req.baseUrl}`,
85
+ details: {
86
+ path: _req.baseUrl,
87
+ method: _req.method,
88
+ },
89
+ });
90
+ }
91
+ /** Configure the HttpContext */
92
+ context.adapter = adapter;
93
+ context.document = adapter.document;
94
+ context.operation = operation;
95
+ context.controller = operation.owner;
96
+ context.controllerInstance = this;
97
+ context.operationHandler = operationHandler;
98
+ /** Handle request */
99
+ await adapter[exports.kHandler].handleRequest(context);
100
+ },
101
+ });
102
+ /** Copy metadata keys from source function to new one */
103
+ const metadataKeys = Reflect.getOwnMetadataKeys(operationHandler);
104
+ const newFn = newClass.prototype[k];
105
+ for (const key of metadataKeys) {
106
+ const m = Reflect.getMetadata(key, operationHandler);
107
+ Reflect.defineMetadata(key, m, newFn);
108
+ }
109
+ (0, common_1.Req)()(newClass.prototype, k, 0);
110
+ (0, common_1.Res)()(newClass.prototype, k, 1);
111
+ const descriptor = Object.getOwnPropertyDescriptor(newClass.prototype, k);
112
+ const operationPath = newPath + (v.path || '');
113
+ switch (v.method || 'GET') {
114
+ case 'DELETE':
115
+ /** Call @Delete decorator over new property */
116
+ (0, common_1.Delete)(operationPath)(newClass.prototype, k, descriptor);
117
+ break;
118
+ case 'GET':
119
+ /** Call @Get decorator over new property */
120
+ (0, common_1.Get)(operationPath)(newClass.prototype, k, descriptor);
121
+ break;
122
+ case 'HEAD':
123
+ /** Call @Head decorator over new property */
124
+ (0, common_1.Head)(operationPath)(newClass.prototype, k, descriptor);
125
+ break;
126
+ case 'OPTIONS':
127
+ /** Call @Options decorator over new property */
128
+ (0, common_1.Options)(operationPath)(newClass.prototype, k, descriptor);
129
+ break;
130
+ case 'PATCH':
131
+ /** Call @Patch decorator over new property */
132
+ (0, common_1.Patch)(operationPath)(newClass.prototype, k, descriptor);
133
+ break;
134
+ case 'POST':
135
+ /** Call @Post decorator over new property */
136
+ (0, common_1.Post)(operationPath)(newClass.prototype, k, descriptor);
137
+ break;
138
+ case 'PUT':
139
+ /** Call @Put decorator over new property */
140
+ (0, common_1.Put)(operationPath)(newClass.prototype, k, descriptor);
141
+ break;
142
+ case 'SEARCH':
143
+ /** Call @Search decorator over new property */
144
+ (0, common_1.Search)(operationPath)(newClass.prototype, k, descriptor);
145
+ break;
146
+ default:
147
+ break;
148
+ }
149
+ }
150
+ }
151
+ if (metadata.controllers) {
152
+ for (const child of metadata.controllers) {
153
+ if (!(0, common_2.isConstructor)(child))
154
+ throw new TypeError('Controllers should be injectable a class');
155
+ this._addToNestControllers(child, newPath);
156
+ }
157
+ }
158
+ }
159
+ }
160
+ exports.OpraNestAdapter = OpraNestAdapter;
@@ -1,17 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpraExceptionFilter = void 0;
4
- const tslib_1 = require("tslib");
5
- const common_1 = require("@nestjs/common");
6
- const common_2 = require("@opra/common");
7
- let OpraExceptionFilter = class OpraExceptionFilter {
8
- catch(exception) {
9
- if (exception instanceof common_2.OpraException)
10
- return true;
11
- throw exception;
3
+ exports.OpraExceptionFilter = exports.kHandler = void 0;
4
+ const core_1 = require("@opra/core");
5
+ exports.kHandler = Symbol.for('kHandler');
6
+ class OpraExceptionFilter {
7
+ constructor(adapter) {
8
+ this.adapter = adapter;
12
9
  }
13
- };
10
+ catch(exception, host) {
11
+ const ctx = host.switchToHttp();
12
+ const _res = ctx.getResponse();
13
+ const error = (0, core_1.wrapException)(exception);
14
+ const response = core_1.HttpOutgoing.from(_res);
15
+ return this.adapter[exports.kHandler].sendErrorResponse(response, [error]);
16
+ }
17
+ }
14
18
  exports.OpraExceptionFilter = OpraExceptionFilter;
15
- exports.OpraExceptionFilter = OpraExceptionFilter = tslib_1.__decorate([
16
- (0, common_1.Catch)(common_2.OpraException)
17
- ], OpraExceptionFilter);
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpraMiddleware = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const core_1 = require("@opra/core");
7
+ let OpraMiddleware = class OpraMiddleware {
8
+ use(req, res, next) {
9
+ const request = core_1.HttpIncoming.from(req);
10
+ const response = core_1.HttpOutgoing.from(res);
11
+ /** Create the HttpContext */
12
+ req.opraContext = new core_1.HttpContext({
13
+ adapter: {},
14
+ platform: req.route ? 'express' : 'fastify',
15
+ request,
16
+ response,
17
+ });
18
+ next();
19
+ }
20
+ };
21
+ exports.OpraMiddleware = OpraMiddleware;
22
+ exports.OpraMiddleware = OpraMiddleware = tslib_1.__decorate([
23
+ (0, common_1.Injectable)()
24
+ ], OpraMiddleware);
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ // import { Controller } from '@nestjs/common';
3
+ // import { DECORATOR, HttpController } from '@opra/common';
4
+ //
5
+ // /*
6
+ // Overrides HttpController decorator function to call NestJS's Controller() when decorator called
7
+ // */
8
+ // const oldHttpControllerDecorator = HttpController[DECORATOR];
9
+ // HttpController[DECORATOR] = function HttpControllerDecorator(options?: HttpController.Options) {
10
+ // const opraControllerDecorator = oldHttpControllerDecorator(options);
11
+ // const nestControllerDecorator = Controller({});
12
+ // return (target: Function) => {
13
+ // opraControllerDecorator(target);
14
+ // nestControllerDecorator(target);
15
+ // };
16
+ // };
package/esm/constants.js CHANGED
@@ -1,6 +1 @@
1
- export const OPRA_MODULE_OPTIONS = 'opra:module_options';
2
- export const OPRA_MODULE_ID = 'opra:module_id';
3
- export const OPRA_INITIALIZER = 'opra_initializer';
4
- export const kOptions = Symbol('kOptions');
5
- export const kAdapter = Symbol('kAdapter');
6
- export const PARAM_ARGS_METADATA = '__routeArguments__';
1
+ export const IS_PUBLIC_KEY = 'isPublic';
@@ -0,0 +1,3 @@
1
+ import { SetMetadata } from '@nestjs/common';
2
+ import { IS_PUBLIC_KEY } from '../constants.js';
3
+ export const Public = () => SetMetadata(IS_PUBLIC_KEY, true);
package/esm/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import 'reflect-metadata';
2
- import './augmentation/common-decorator.augmentation.js';
3
2
  import './augmentation/nestjs.augmentation.js';
4
- export * from './opra.module.js';
5
- export * from './decorators/context.decorator.js';
6
- export * from './interfaces/opra-module-options.interface.js';
7
- export * from './opra-module-ref.js';
3
+ export * from './constants.js';
4
+ export * from './decorators/public.decorator.js';
5
+ export * from './opra-http.module.js';
6
+ export * from './opra-nestjs-adapter.js';
@@ -1 +1,17 @@
1
- export {};
1
+ "use strict";
2
+ // import { ApiDocumentFactory } from '@opra/common';
3
+ // import { ExpressAdapter, HttpAdapter } from '@opra/core';
4
+ // export interface OpraModuleOptions extends HttpAdapter.Options {
5
+ // id?: any;
6
+ // document?: Partial<ApiDocumentFactory.InitArguments>;
7
+ //
8
+ // /**
9
+ // * @default true
10
+ // */
11
+ // useGlobalPrefix?: boolean;
12
+ // }
13
+ // export interface ExpressModuleOptions extends OpraModuleOptions, HttpAdapter.Options {}
14
+ // type OpraModuleOptionsWithoutId = Omit<OpraModuleOptions, 'id'>;
15
+ // export interface OpraModuleOptionsFactory {
16
+ // createOptions(): Promise<OpraModuleOptionsWithoutId> | OpraModuleOptionsWithoutId;
17
+ // }
@@ -0,0 +1,57 @@
1
+ var OpraHttpCoreModule_1;
2
+ import { __decorate, __metadata } from "tslib";
3
+ import { Global, Module, RequestMethod, } from '@nestjs/common';
4
+ import { ApiDocumentFactory } from '@opra/common';
5
+ import { asMutable } from 'ts-gems';
6
+ import { OpraNestAdapter } from './opra-nestjs-adapter.js';
7
+ import { OpraMiddleware } from './services/opra-middleware.js';
8
+ let OpraHttpCoreModule = OpraHttpCoreModule_1 = class OpraHttpCoreModule {
9
+ constructor(opraAdapter) {
10
+ this.opraAdapter = opraAdapter;
11
+ }
12
+ configure(consumer) {
13
+ consumer.apply(OpraMiddleware).forRoutes({
14
+ path: '*',
15
+ method: RequestMethod.ALL,
16
+ });
17
+ }
18
+ static forRoot(init, options) {
19
+ const opraAdapter = new OpraNestAdapter(init, options);
20
+ const token = init?.id || OpraNestAdapter;
21
+ const providers = [
22
+ ...(init?.providers || []),
23
+ {
24
+ provide: OpraNestAdapter,
25
+ useFactory: async () => {
26
+ asMutable(opraAdapter).document = await ApiDocumentFactory.createDocument({
27
+ ...init,
28
+ api: { protocol: 'http', name: init.name, controllers: init.controllers },
29
+ });
30
+ return opraAdapter;
31
+ },
32
+ },
33
+ ];
34
+ if (token !== OpraNestAdapter) {
35
+ providers.push({
36
+ provide: token,
37
+ useValue: opraAdapter,
38
+ });
39
+ }
40
+ return {
41
+ module: OpraHttpCoreModule_1,
42
+ controllers: opraAdapter.nestControllers,
43
+ imports: [...(init?.imports || [])],
44
+ exports: [...(init?.exports || []), token],
45
+ providers,
46
+ };
47
+ }
48
+ async onModuleDestroy() {
49
+ await this.opraAdapter.close();
50
+ }
51
+ };
52
+ OpraHttpCoreModule = OpraHttpCoreModule_1 = __decorate([
53
+ Module({}),
54
+ Global(),
55
+ __metadata("design:paramtypes", [OpraNestAdapter])
56
+ ], OpraHttpCoreModule);
57
+ export { OpraHttpCoreModule };
@@ -0,0 +1,21 @@
1
+ var OpraHttpModule_1;
2
+ import { __decorate } from "tslib";
3
+ import { Module } from '@nestjs/common';
4
+ import { OpraHttpCoreModule } from './opra-http-core.module.js';
5
+ let OpraHttpModule = OpraHttpModule_1 = class OpraHttpModule {
6
+ /**
7
+ *
8
+ * @param init
9
+ * @param options
10
+ */
11
+ static forRoot(init, options) {
12
+ return {
13
+ module: OpraHttpModule_1,
14
+ imports: [OpraHttpCoreModule.forRoot(init, options)],
15
+ };
16
+ }
17
+ };
18
+ OpraHttpModule = OpraHttpModule_1 = __decorate([
19
+ Module({})
20
+ ], OpraHttpModule);
21
+ export { OpraHttpModule };