@tc-libs/rmq 0.9.0

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 ADDED
@@ -0,0 +1,11 @@
1
+ # rmq
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build rmq` to build the library.
8
+
9
+ ## Running unit tests
10
+
11
+ Run `nx test rmq` to execute the unit tests via [Jest](https://jestjs.io).
package/package.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "@tc-libs/rmq",
3
+ "version": "0.9.0",
4
+ "dependencies": {
5
+ "tslib": "^2.3.0"
6
+ },
7
+ "type": "commonjs",
8
+ "main": "./src/index.js",
9
+ "typings": "./src/index.d.ts",
10
+ "types": "./src/index.d.ts"
11
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './rmq.module';
2
+ export * from './services/rmq.service';
package/src/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./rmq.module"), exports);
5
+ tslib_1.__exportStar(require("./services/rmq.service"), exports);
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/rmq/src/index.ts"],"names":[],"mappings":";;;AAAA,uDAA6B;AAC7B,iEAAuC"}
@@ -0,0 +1,6 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import RmqModuleAsyncOptions, { RmqModuleOptions } from './rmq.module.options';
3
+ export declare class RmqModule {
4
+ static register(queue: string, options: RmqModuleOptions): DynamicModule;
5
+ static registerAsync(queue: string, options: RmqModuleAsyncOptions): DynamicModule;
6
+ }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ var RmqModule_1;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.RmqModule = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const common_1 = require("@nestjs/common");
7
+ const microservices_1 = require("@nestjs/microservices");
8
+ const rmq_service_1 = require("./services/rmq.service");
9
+ const rmq_module_options_1 = require("./rmq.module.options");
10
+ let RmqModule = RmqModule_1 = class RmqModule {
11
+ static register(queue, options) {
12
+ return {
13
+ module: RmqModule_1,
14
+ providers: [{ provide: rmq_module_options_1.RMQ_CONFIG_OPTIONS, useValue: options }],
15
+ imports: [
16
+ microservices_1.ClientsModule.register([
17
+ {
18
+ transport: microservices_1.Transport.RMQ,
19
+ name: queue,
20
+ options: {
21
+ urls: [options.url],
22
+ queue: `RMQ_${queue}_QUEUE`,
23
+ socketOptions: {
24
+ timeout: 1000 * 600,
25
+ },
26
+ },
27
+ },
28
+ ]),
29
+ ],
30
+ exports: [microservices_1.ClientsModule],
31
+ };
32
+ }
33
+ static registerAsync(queue, options) {
34
+ return {
35
+ module: RmqModule_1,
36
+ providers: [
37
+ {
38
+ provide: rmq_module_options_1.RMQ_CONFIG_OPTIONS,
39
+ useFactory: options.useFactory,
40
+ inject: options.inject,
41
+ },
42
+ ],
43
+ imports: [
44
+ microservices_1.ClientsModule.registerAsync([
45
+ {
46
+ name: queue,
47
+ useFactory: async (...args) => {
48
+ const rmqOptions = await options.useFactory(...args);
49
+ return {
50
+ transport: microservices_1.Transport.RMQ,
51
+ options: {
52
+ urls: [rmqOptions.url],
53
+ queue: `RMQ_${queue}_QUEUE`,
54
+ socketOptions: {
55
+ timeout: 1000 * 600,
56
+ },
57
+ },
58
+ };
59
+ },
60
+ inject: options.inject,
61
+ },
62
+ ]),
63
+ ],
64
+ exports: [microservices_1.ClientsModule],
65
+ };
66
+ }
67
+ };
68
+ exports.RmqModule = RmqModule;
69
+ exports.RmqModule = RmqModule = RmqModule_1 = tslib_1.__decorate([
70
+ (0, common_1.Global)(),
71
+ (0, common_1.Module)({
72
+ providers: [rmq_service_1.RmqService],
73
+ exports: [rmq_service_1.RmqService],
74
+ })
75
+ ], RmqModule);
76
+ //# sourceMappingURL=rmq.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rmq.module.js","sourceRoot":"","sources":["../../../../packages/rmq/src/rmq.module.ts"],"names":[],"mappings":";;;;;AAAA,2CAA+D;AAC/D,yDAAiE;AACjE,wDAAoD;AACpD,6DAG8B;AAOvB,IAAM,SAAS,iBAAf,MAAM,SAAS;IACpB,MAAM,CAAC,QAAQ,CAAC,KAAa,EAAE,OAAyB;QACtD,OAAO;YACL,MAAM,EAAE,WAAS;YACjB,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,uCAAkB,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;YAC/D,OAAO,EAAE;gBACP,6BAAa,CAAC,QAAQ,CAAC;oBACrB;wBACE,SAAS,EAAE,yBAAS,CAAC,GAAG;wBACxB,IAAI,EAAE,KAAK;wBACX,OAAO,EAAE;4BACP,IAAI,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC;4BACnB,KAAK,EAAE,OAAO,KAAK,QAAQ;4BAC3B,aAAa,EAAE;gCACb,OAAO,EAAE,IAAI,GAAG,GAAG;6BACpB;yBACF;qBACF;iBACF,CAAC;aACH;YACD,OAAO,EAAE,CAAC,6BAAa,CAAC;SACzB,CAAC;IACJ,CAAC;IACD,MAAM,CAAC,aAAa,CAClB,KAAa,EACb,OAA8B;QAE9B,OAAO;YACL,MAAM,EAAE,WAAS;YACjB,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,uCAAkB;oBAC3B,UAAU,EAAE,OAAO,CAAC,UAAU;oBAC9B,MAAM,EAAE,OAAO,CAAC,MAAM;iBACvB;aACF;YACD,OAAO,EAAE;gBACP,6BAAa,CAAC,aAAa,CAAC;oBAC1B;wBACE,IAAI,EAAE,KAAK;wBACX,UAAU,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,EAAE;4BAC5B,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC;4BACrD,OAAO;gCACL,SAAS,EAAE,yBAAS,CAAC,GAAG;gCACxB,OAAO,EAAE;oCACP,IAAI,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC;oCACtB,KAAK,EAAE,OAAO,KAAK,QAAQ;oCAC3B,aAAa,EAAE;wCACb,OAAO,EAAE,IAAI,GAAG,GAAG;qCACpB;iCACF;6BACF,CAAC;wBACJ,CAAC;wBACD,MAAM,EAAE,OAAO,CAAC,MAAM;qBACvB;iBACF,CAAC;aACH;YACD,OAAO,EAAE,CAAC,6BAAa,CAAC;SACzB,CAAC;IACJ,CAAC;CACF,CAAA;AA5DY,8BAAS;oBAAT,SAAS;IALrB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,SAAS,EAAE,CAAC,wBAAU,CAAC;QACvB,OAAO,EAAE,CAAC,wBAAU,CAAC;KACtB,CAAC;GACW,SAAS,CA4DrB"}
@@ -0,0 +1,8 @@
1
+ import { ModuleMetadata } from '@nestjs/common';
2
+ import { FactoryProvider } from '@nestjs/common/interfaces/modules/provider.interface';
3
+ export declare const RMQ_CONFIG_OPTIONS = "RMQ_CONFIG_OPTIONS";
4
+ export interface RmqModuleOptions {
5
+ url: string;
6
+ }
7
+ type RmqModuleAsyncOptions = Pick<ModuleMetadata, 'imports'> & Pick<FactoryProvider<RmqModuleOptions>, 'useFactory' | 'inject'>;
8
+ export default RmqModuleAsyncOptions;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RMQ_CONFIG_OPTIONS = void 0;
4
+ exports.RMQ_CONFIG_OPTIONS = 'RMQ_CONFIG_OPTIONS';
5
+ //# sourceMappingURL=rmq.module.options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rmq.module.options.js","sourceRoot":"","sources":["../../../../packages/rmq/src/rmq.module.options.ts"],"names":[],"mappings":";;;AAGa,QAAA,kBAAkB,GAAG,oBAAoB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { RmqContext, RmqOptions } from '@nestjs/microservices';
2
+ export declare class RmqService {
3
+ getOptions(urls: string[], queue: string, prefetchCount?: number, noAck?: boolean): RmqOptions;
4
+ ack(context: RmqContext): void;
5
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RmqService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const microservices_1 = require("@nestjs/microservices");
7
+ let RmqService = class RmqService {
8
+ getOptions(urls, queue, prefetchCount, noAck = false) {
9
+ return {
10
+ transport: microservices_1.Transport.RMQ,
11
+ options: {
12
+ urls,
13
+ queue,
14
+ noAck,
15
+ persistent: true,
16
+ prefetchCount,
17
+ },
18
+ };
19
+ }
20
+ ack(context) {
21
+ const channel = context.getChannelRef();
22
+ const originalMessage = context.getMessage();
23
+ channel.ack(originalMessage);
24
+ }
25
+ };
26
+ exports.RmqService = RmqService;
27
+ exports.RmqService = RmqService = tslib_1.__decorate([
28
+ (0, common_1.Injectable)()
29
+ ], RmqService);
30
+ //# sourceMappingURL=rmq.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rmq.service.js","sourceRoot":"","sources":["../../../../../packages/rmq/src/services/rmq.service.ts"],"names":[],"mappings":";;;;AAAA,2CAA4C;AAC5C,yDAA0E;AAGnE,IAAM,UAAU,GAAhB,MAAM,UAAU;IACrB,UAAU,CACR,IAAc,EACd,KAAa,EACb,aAAsB,EACtB,KAAK,GAAG,KAAK;QAEb,OAAO;YACL,SAAS,EAAE,yBAAS,CAAC,GAAG;YACxB,OAAO,EAAE;gBACP,IAAI;gBACJ,KAAK;gBACL,KAAK;gBACL,UAAU,EAAE,IAAI;gBAChB,aAAa;aACd;SACF,CAAC;IACJ,CAAC;IAED,GAAG,CAAC,OAAmB;QACrB,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QACxC,MAAM,eAAe,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;QAC7C,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC/B,CAAC;CACF,CAAA;AAxBY,gCAAU;qBAAV,UAAU;IADtB,IAAA,mBAAU,GAAE;GACA,UAAU,CAwBtB"}