@opra/nestjs 1.0.0-beta.3 → 1.0.0-beta.5

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 (39) hide show
  1. package/cjs/augmentation/nestjs.augmentation.js +8 -0
  2. package/cjs/constants.js +3 -2
  3. package/cjs/http/opra-http-core.module.js +116 -0
  4. package/cjs/{opra-nestjs-adapter.js → http/opra-http-nestjs-adapter.js} +14 -21
  5. package/cjs/{opra-http.module.js → http/opra-http.module.js} +11 -2
  6. package/cjs/{services → http/services}/opra-exception-filter.js +2 -2
  7. package/cjs/{services → http/services}/opra-middleware.js +3 -6
  8. package/cjs/index.js +4 -2
  9. package/cjs/kafka/opra-kafka-core.module.js +107 -0
  10. package/cjs/kafka/opra-kafka-nestjs-adapter.js +79 -0
  11. package/cjs/kafka/opra-kafka.module.js +33 -0
  12. package/esm/augmentation/nestjs.augmentation.js +8 -0
  13. package/esm/constants.js +2 -1
  14. package/esm/http/opra-http-core.module.js +113 -0
  15. package/esm/{opra-nestjs-adapter.js → http/opra-http-nestjs-adapter.js} +12 -19
  16. package/esm/{opra-http.module.js → http/opra-http.module.js} +11 -2
  17. package/esm/{services → http/services}/opra-exception-filter.js +2 -2
  18. package/esm/{services → http/services}/opra-middleware.js +5 -8
  19. package/esm/index.js +4 -2
  20. package/esm/kafka/opra-kafka-core.module.js +104 -0
  21. package/esm/kafka/opra-kafka-nestjs-adapter.js +75 -0
  22. package/esm/kafka/opra-kafka.module.js +30 -0
  23. package/package.json +8 -4
  24. package/types/constants.d.ts +2 -1
  25. package/types/http/opra-http-core.module.d.ts +12 -0
  26. package/types/{opra-nestjs-adapter.d.ts → http/opra-http-nestjs-adapter.d.ts} +6 -5
  27. package/types/http/opra-http.module.d.ts +35 -0
  28. package/types/http/services/opra-middleware.d.ts +8 -0
  29. package/types/index.d.cts +4 -2
  30. package/types/index.d.ts +4 -2
  31. package/types/kafka/opra-kafka-core.module.d.ts +14 -0
  32. package/types/kafka/opra-kafka-nestjs-adapter.d.ts +19 -0
  33. package/types/kafka/opra-kafka.module.d.ts +33 -0
  34. package/cjs/opra-http-core.module.js +0 -82
  35. package/esm/opra-http-core.module.js +0 -79
  36. package/types/opra-http-core.module.d.ts +0 -10
  37. package/types/opra-http.module.d.ts +0 -22
  38. package/types/services/opra-middleware.d.ts +0 -10
  39. /package/types/{services → http/services}/opra-exception-filter.d.ts +0 -0
@@ -1,79 +0,0 @@
1
- var OpraHttpCoreModule_1;
2
- import { __decorate, __metadata } from "tslib";
3
- import { Global, Module, RequestMethod, } from '@nestjs/common';
4
- import { APP_FILTER, ModuleRef } from '@nestjs/core';
5
- import { ApiDocumentFactory, isConstructor } from '@opra/common';
6
- import { asMutable } from 'ts-gems';
7
- import { OPRA_HTTP_MODULE_OPTIONS } from './constants.js';
8
- import { OpraNestAdapter } from './opra-nestjs-adapter.js';
9
- import { OpraExceptionFilter } from './services/opra-exception-filter.js';
10
- import { OpraMiddleware } from './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(OpraMiddleware).forRoutes({
17
- path: '*',
18
- method: RequestMethod.ALL,
19
- });
20
- }
21
- static forRoot(init, options) {
22
- const opraAdapter = new OpraNestAdapter(init, options);
23
- const token = init?.id || OpraNestAdapter;
24
- const providers = [
25
- ...(init?.providers || []),
26
- {
27
- provide: OPRA_HTTP_MODULE_OPTIONS,
28
- useValue: { ...options },
29
- },
30
- {
31
- provide: OpraNestAdapter,
32
- inject: [ModuleRef],
33
- useFactory: async (moduleRef) => {
34
- asMutable(opraAdapter).document = await ApiDocumentFactory.createDocument({
35
- ...init,
36
- api: { transport: 'http', name: init.name, controllers: init.controllers },
37
- });
38
- opraAdapter.interceptors.map(x => {
39
- if (isConstructor(x)) {
40
- return (ctx, next) => {
41
- const interceptor = moduleRef.get(x);
42
- if (typeof interceptor.intercept === 'function')
43
- return interceptor.intercept(ctx, next());
44
- };
45
- }
46
- return x;
47
- });
48
- return opraAdapter;
49
- },
50
- },
51
- {
52
- provide: APP_FILTER,
53
- useClass: OpraExceptionFilter,
54
- },
55
- ];
56
- if (token !== OpraNestAdapter) {
57
- providers.push({
58
- provide: token,
59
- useValue: opraAdapter,
60
- });
61
- }
62
- return {
63
- module: OpraHttpCoreModule_1,
64
- controllers: opraAdapter.nestControllers,
65
- imports: [...(init?.imports || [])],
66
- exports: [...(init?.exports || []), token],
67
- providers,
68
- };
69
- }
70
- async onModuleDestroy() {
71
- await this.opraAdapter.close();
72
- }
73
- };
74
- OpraHttpCoreModule = OpraHttpCoreModule_1 = __decorate([
75
- Module({}),
76
- Global(),
77
- __metadata("design:paramtypes", [OpraNestAdapter])
78
- ], OpraHttpCoreModule);
79
- export { OpraHttpCoreModule };
@@ -1,10 +0,0 @@
1
- import { type DynamicModule, type MiddlewareConsumer, type NestModule, type OnModuleDestroy } from '@nestjs/common';
2
- import type { OpraHttpModule } from './opra-http.module.js';
3
- import { OpraNestAdapter } from './opra-nestjs-adapter.js';
4
- export declare class OpraHttpCoreModule implements OnModuleDestroy, NestModule {
5
- protected opraAdapter: OpraNestAdapter;
6
- constructor(opraAdapter: OpraNestAdapter);
7
- configure(consumer: MiddlewareConsumer): void;
8
- static forRoot(init: OpraHttpModule.Initiator, options?: OpraHttpModule.Options): DynamicModule;
9
- onModuleDestroy(): Promise<void>;
10
- }
@@ -1,22 +0,0 @@
1
- import { type DynamicModule, type Type } from '@nestjs/common';
2
- import { ApiDocumentFactory } from '@opra/common';
3
- import { HttpAdapter } from '@opra/http';
4
- export declare namespace OpraHttpModule {
5
- interface Initiator extends Pick<DynamicModule, 'imports' | 'providers' | 'exports' | 'controllers'>, Pick<ApiDocumentFactory.InitArguments, 'types' | 'references' | 'info'> {
6
- id?: any;
7
- name: string;
8
- }
9
- interface Options {
10
- basePath?: string;
11
- schemaRouteIsPublic?: boolean;
12
- interceptors?: (HttpAdapter.InterceptorFunction | HttpAdapter.IHttpInterceptor | Type<HttpAdapter.IHttpInterceptor>)[];
13
- }
14
- }
15
- export declare class OpraHttpModule {
16
- /**
17
- *
18
- * @param init
19
- * @param options
20
- */
21
- static forRoot(init: OpraHttpModule.Initiator, options?: OpraHttpModule.Options): DynamicModule;
22
- }
@@ -1,10 +0,0 @@
1
- import { type NestMiddleware } from '@nestjs/common';
2
- import type { NextFunction, Request, Response } from 'express';
3
- import type { OpraHttpModule } from '../opra-http.module.js';
4
- import { OpraNestAdapter } from '../opra-nestjs-adapter.js';
5
- export declare class OpraMiddleware implements NestMiddleware {
6
- protected opraAdapter: OpraNestAdapter;
7
- protected options: OpraHttpModule.Options;
8
- constructor(opraAdapter: OpraNestAdapter, options: OpraHttpModule.Options);
9
- use(req: Request, res: Response, next: NextFunction): void;
10
- }