@amqp-contract/client-nestjs 0.0.1
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/LICENSE +21 -0
- package/README.md +44 -0
- package/dist/index.cjs +91 -0
- package/dist/index.d.cts +52 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +52 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +81 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Benoit Travers
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# @amqp-contract/client-nestjs
|
|
2
|
+
|
|
3
|
+
NestJS integration for [@amqp-contract/client](../client). Type-safe AMQP message publishing with automatic lifecycle management.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @amqp-contract/client-nestjs @amqp-contract/client @amqp-contract/contract amqplib
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Injectable, Module } from '@nestjs/common';
|
|
15
|
+
import { AmqpClientModule, AmqpClientService } from '@amqp-contract/client-nestjs';
|
|
16
|
+
import { contract } from './contract';
|
|
17
|
+
|
|
18
|
+
@Module({
|
|
19
|
+
imports: [
|
|
20
|
+
AmqpClientModule.forRoot({
|
|
21
|
+
contract,
|
|
22
|
+
connection: 'amqp://localhost',
|
|
23
|
+
}),
|
|
24
|
+
],
|
|
25
|
+
})
|
|
26
|
+
export class AppModule {}
|
|
27
|
+
|
|
28
|
+
@Injectable()
|
|
29
|
+
export class OrderService {
|
|
30
|
+
constructor(
|
|
31
|
+
private readonly client: AmqpClientService<typeof contract>,
|
|
32
|
+
) {}
|
|
33
|
+
|
|
34
|
+
async createOrder(orderId: string, amount: number) {
|
|
35
|
+
await this.client.publish('orderCreated', { orderId, amount });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The client automatically connects when the module initializes and cleans up on shutdown.
|
|
41
|
+
|
|
42
|
+
## License
|
|
43
|
+
|
|
44
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
let _nestjs_common = require("@nestjs/common");
|
|
2
|
+
let _amqp_contract_client = require("@amqp-contract/client");
|
|
3
|
+
|
|
4
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/decorateMetadata.js
|
|
5
|
+
function __decorateMetadata(k, v) {
|
|
6
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/decorateParam.js
|
|
11
|
+
function __decorateParam(paramIndex, decorator) {
|
|
12
|
+
return function(target, key) {
|
|
13
|
+
decorator(target, key, paramIndex);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/decorate.js
|
|
19
|
+
function __decorate(decorators, target, key, desc) {
|
|
20
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
21
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
22
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
23
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/client.service.ts
|
|
28
|
+
let AmqpClientService = class AmqpClientService$1 {
|
|
29
|
+
client = null;
|
|
30
|
+
constructor(options) {
|
|
31
|
+
this.options = options;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Initialize the client when the NestJS module starts
|
|
35
|
+
*/
|
|
36
|
+
async onModuleInit() {
|
|
37
|
+
this.client = await _amqp_contract_client.TypedAmqpClient.create({
|
|
38
|
+
contract: this.options.contract,
|
|
39
|
+
connection: this.options.connection
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Close the client when the NestJS module is destroyed
|
|
44
|
+
*/
|
|
45
|
+
async onModuleDestroy() {
|
|
46
|
+
if (this.client) {
|
|
47
|
+
await this.client.close();
|
|
48
|
+
this.client = null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Publish a message using a defined publisher
|
|
53
|
+
* This method provides type-safe message publishing
|
|
54
|
+
*/
|
|
55
|
+
async publish(publisherName, message, options) {
|
|
56
|
+
if (!this.client) throw new Error("Client not initialized. Create the client using TypedAmqpClient.create() to establish a connection.");
|
|
57
|
+
return this.client.publish(publisherName, message, options);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
AmqpClientService = __decorate([
|
|
61
|
+
(0, _nestjs_common.Injectable)(),
|
|
62
|
+
__decorateParam(0, (0, _nestjs_common.Inject)(MODULE_OPTIONS_TOKEN)),
|
|
63
|
+
__decorateMetadata("design:paramtypes", [Object])
|
|
64
|
+
], AmqpClientService);
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/client.module.ts
|
|
68
|
+
/**
|
|
69
|
+
* ConfigurableModuleBuilder for AMQP client module
|
|
70
|
+
* This creates forRoot and forRootAsync methods automatically
|
|
71
|
+
*/
|
|
72
|
+
const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN } = new _nestjs_common.ConfigurableModuleBuilder().setClassMethodName("forRoot").build();
|
|
73
|
+
let AmqpClientModule = class AmqpClientModule$1 extends ConfigurableModuleClass {};
|
|
74
|
+
AmqpClientModule = __decorate([(0, _nestjs_common.Module)({
|
|
75
|
+
providers: [AmqpClientService],
|
|
76
|
+
exports: [AmqpClientService]
|
|
77
|
+
})], AmqpClientModule);
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
Object.defineProperty(exports, 'AmqpClientModule', {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
get: function () {
|
|
83
|
+
return AmqpClientModule;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
Object.defineProperty(exports, 'AmqpClientService', {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
get: function () {
|
|
89
|
+
return AmqpClientService;
|
|
90
|
+
}
|
|
91
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as _nestjs_common0 from "@nestjs/common";
|
|
2
|
+
import { OnModuleDestroy, OnModuleInit } from "@nestjs/common";
|
|
3
|
+
import { Options } from "amqplib";
|
|
4
|
+
import { ClientInferPublisherInput, ContractDefinition, InferPublisherNames } from "@amqp-contract/contract";
|
|
5
|
+
import { PublishOptions } from "@amqp-contract/client";
|
|
6
|
+
|
|
7
|
+
//#region src/client.service.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Options for creating a NestJS client service
|
|
10
|
+
*/
|
|
11
|
+
interface AmqpClientModuleOptions<TContract extends ContractDefinition> {
|
|
12
|
+
contract: TContract;
|
|
13
|
+
connection: string | Options.Connect;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Type-safe AMQP client service for NestJS
|
|
17
|
+
* This service integrates @amqp-contract/client with NestJS lifecycle
|
|
18
|
+
*/
|
|
19
|
+
declare class AmqpClientService<TContract extends ContractDefinition> implements OnModuleInit, OnModuleDestroy {
|
|
20
|
+
private readonly options;
|
|
21
|
+
private client;
|
|
22
|
+
constructor(options: AmqpClientModuleOptions<TContract>);
|
|
23
|
+
/**
|
|
24
|
+
* Initialize the client when the NestJS module starts
|
|
25
|
+
*/
|
|
26
|
+
onModuleInit(): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Close the client when the NestJS module is destroyed
|
|
29
|
+
*/
|
|
30
|
+
onModuleDestroy(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Publish a message using a defined publisher
|
|
33
|
+
* This method provides type-safe message publishing
|
|
34
|
+
*/
|
|
35
|
+
publish<TName extends InferPublisherNames<TContract>>(publisherName: TName, message: ClientInferPublisherInput<TContract, TName>, options?: PublishOptions): Promise<boolean>;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/client.module.d.ts
|
|
39
|
+
/**
|
|
40
|
+
* ConfigurableModuleBuilder for AMQP client module
|
|
41
|
+
* This creates forRoot and forRootAsync methods automatically
|
|
42
|
+
*/
|
|
43
|
+
declare const ConfigurableModuleClass: _nestjs_common0.ConfigurableModuleCls<AmqpClientModuleOptions<never>, "forRoot", "create", {}>, MODULE_OPTIONS_TOKEN: string | symbol;
|
|
44
|
+
/**
|
|
45
|
+
* NestJS module for AMQP client integration
|
|
46
|
+
* This module provides type-safe AMQP client functionality using @amqp-contract/client
|
|
47
|
+
* without relying on NestJS decorators (except for dependency injection)
|
|
48
|
+
*/
|
|
49
|
+
declare class AmqpClientModule extends ConfigurableModuleClass {}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { AmqpClientModule, type AmqpClientModuleOptions, AmqpClientService };
|
|
52
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/client.service.ts","../src/client.module.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAaiB,UAAA,uBAAuB,CAAA,kBAAmB,kBAAnB,CAAA,CAAA;EAAmB,QAAA,EAC/C,SAD+C;EAC/C,UAAA,EAAA,MAAA,GACW,OAAA,CAAQ,OADnB;;;AAQZ;;;AAQ8B,cAPjB,iBAOiB,CAAA,kBAPmB,kBAOnB,CAAA,YANjB,YAMiB,EANH,eAMG,CAAA;EAMN,iBAAA,OAAA;EAUG,QAAA,MAAA;EAWuB,WAAA,CAAA,OAAA,EA3BpB,uBA2BoB,CA3BI,SA2BJ,CAAA;EAApB;;;EAEoB,YAAA,CAAA,CAAA,EAvB1B,OAuB0B,CAAA,IAAA,CAAA;EAArC;;;EAnCA,eAAA,CAAA,CAAA,EAsBc,OAtBd,CAAA,IAAA,CAAA;EAAc;;;;wBAiCG,oBAAoB,2BAC/B,gBACN,0BAA0B,WAAW,kBACpC,iBACT;ACrDL;;;;;;;cAAe,yBAAuB,eAAA,CAAA,sBAAA;;ADKtC;;;;AAEsC,cCQzB,gBAAA,SAAyB,uBAAA,CDRA"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as _nestjs_common0 from "@nestjs/common";
|
|
2
|
+
import { OnModuleDestroy, OnModuleInit } from "@nestjs/common";
|
|
3
|
+
import { PublishOptions } from "@amqp-contract/client";
|
|
4
|
+
import { Options } from "amqplib";
|
|
5
|
+
import { ClientInferPublisherInput, ContractDefinition, InferPublisherNames } from "@amqp-contract/contract";
|
|
6
|
+
|
|
7
|
+
//#region src/client.service.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Options for creating a NestJS client service
|
|
10
|
+
*/
|
|
11
|
+
interface AmqpClientModuleOptions<TContract extends ContractDefinition> {
|
|
12
|
+
contract: TContract;
|
|
13
|
+
connection: string | Options.Connect;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Type-safe AMQP client service for NestJS
|
|
17
|
+
* This service integrates @amqp-contract/client with NestJS lifecycle
|
|
18
|
+
*/
|
|
19
|
+
declare class AmqpClientService<TContract extends ContractDefinition> implements OnModuleInit, OnModuleDestroy {
|
|
20
|
+
private readonly options;
|
|
21
|
+
private client;
|
|
22
|
+
constructor(options: AmqpClientModuleOptions<TContract>);
|
|
23
|
+
/**
|
|
24
|
+
* Initialize the client when the NestJS module starts
|
|
25
|
+
*/
|
|
26
|
+
onModuleInit(): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Close the client when the NestJS module is destroyed
|
|
29
|
+
*/
|
|
30
|
+
onModuleDestroy(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Publish a message using a defined publisher
|
|
33
|
+
* This method provides type-safe message publishing
|
|
34
|
+
*/
|
|
35
|
+
publish<TName extends InferPublisherNames<TContract>>(publisherName: TName, message: ClientInferPublisherInput<TContract, TName>, options?: PublishOptions): Promise<boolean>;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/client.module.d.ts
|
|
39
|
+
/**
|
|
40
|
+
* ConfigurableModuleBuilder for AMQP client module
|
|
41
|
+
* This creates forRoot and forRootAsync methods automatically
|
|
42
|
+
*/
|
|
43
|
+
declare const ConfigurableModuleClass: _nestjs_common0.ConfigurableModuleCls<AmqpClientModuleOptions<never>, "forRoot", "create", {}>, MODULE_OPTIONS_TOKEN: string | symbol;
|
|
44
|
+
/**
|
|
45
|
+
* NestJS module for AMQP client integration
|
|
46
|
+
* This module provides type-safe AMQP client functionality using @amqp-contract/client
|
|
47
|
+
* without relying on NestJS decorators (except for dependency injection)
|
|
48
|
+
*/
|
|
49
|
+
declare class AmqpClientModule extends ConfigurableModuleClass {}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { AmqpClientModule, type AmqpClientModuleOptions, AmqpClientService };
|
|
52
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/client.service.ts","../src/client.module.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAaiB,UAAA,uBAAuB,CAAA,kBAAmB,kBAAnB,CAAA,CAAA;EAAmB,QAAA,EAC/C,SAD+C;EAC/C,UAAA,EAAA,MAAA,GACW,OAAA,CAAQ,OADnB;;;AAQZ;;;AAQ8B,cAPjB,iBAOiB,CAAA,kBAPmB,kBAOnB,CAAA,YANjB,YAMiB,EANH,eAMG,CAAA;EAMN,iBAAA,OAAA;EAUG,QAAA,MAAA;EAWuB,WAAA,CAAA,OAAA,EA3BpB,uBA2BoB,CA3BI,SA2BJ,CAAA;EAApB;;;EAEoB,YAAA,CAAA,CAAA,EAvB1B,OAuB0B,CAAA,IAAA,CAAA;EAArC;;;EAnCA,eAAA,CAAA,CAAA,EAsBc,OAtBd,CAAA,IAAA,CAAA;EAAc;;;;wBAiCG,oBAAoB,2BAC/B,gBACN,0BAA0B,WAAW,kBACpC,iBACT;ACrDL;;;;;;;cAAe,yBAAuB,eAAA,CAAA,sBAAA;;ADKtC;;;;AAEsC,cCQzB,gBAAA,SAAyB,uBAAA,CDRA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ConfigurableModuleBuilder, Inject, Injectable, Module } from "@nestjs/common";
|
|
2
|
+
import { TypedAmqpClient } from "@amqp-contract/client";
|
|
3
|
+
|
|
4
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/decorateMetadata.js
|
|
5
|
+
function __decorateMetadata(k, v) {
|
|
6
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/decorateParam.js
|
|
11
|
+
function __decorateParam(paramIndex, decorator) {
|
|
12
|
+
return function(target, key) {
|
|
13
|
+
decorator(target, key, paramIndex);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/decorate.js
|
|
19
|
+
function __decorate(decorators, target, key, desc) {
|
|
20
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
21
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
22
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
23
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/client.service.ts
|
|
28
|
+
let AmqpClientService = class AmqpClientService$1 {
|
|
29
|
+
client = null;
|
|
30
|
+
constructor(options) {
|
|
31
|
+
this.options = options;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Initialize the client when the NestJS module starts
|
|
35
|
+
*/
|
|
36
|
+
async onModuleInit() {
|
|
37
|
+
this.client = await TypedAmqpClient.create({
|
|
38
|
+
contract: this.options.contract,
|
|
39
|
+
connection: this.options.connection
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Close the client when the NestJS module is destroyed
|
|
44
|
+
*/
|
|
45
|
+
async onModuleDestroy() {
|
|
46
|
+
if (this.client) {
|
|
47
|
+
await this.client.close();
|
|
48
|
+
this.client = null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Publish a message using a defined publisher
|
|
53
|
+
* This method provides type-safe message publishing
|
|
54
|
+
*/
|
|
55
|
+
async publish(publisherName, message, options) {
|
|
56
|
+
if (!this.client) throw new Error("Client not initialized. Create the client using TypedAmqpClient.create() to establish a connection.");
|
|
57
|
+
return this.client.publish(publisherName, message, options);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
AmqpClientService = __decorate([
|
|
61
|
+
Injectable(),
|
|
62
|
+
__decorateParam(0, Inject(MODULE_OPTIONS_TOKEN)),
|
|
63
|
+
__decorateMetadata("design:paramtypes", [Object])
|
|
64
|
+
], AmqpClientService);
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/client.module.ts
|
|
68
|
+
/**
|
|
69
|
+
* ConfigurableModuleBuilder for AMQP client module
|
|
70
|
+
* This creates forRoot and forRootAsync methods automatically
|
|
71
|
+
*/
|
|
72
|
+
const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN } = new ConfigurableModuleBuilder().setClassMethodName("forRoot").build();
|
|
73
|
+
let AmqpClientModule = class AmqpClientModule$1 extends ConfigurableModuleClass {};
|
|
74
|
+
AmqpClientModule = __decorate([Module({
|
|
75
|
+
providers: [AmqpClientService],
|
|
76
|
+
exports: [AmqpClientService]
|
|
77
|
+
})], AmqpClientModule);
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
export { AmqpClientModule, AmqpClientService };
|
|
81
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["AmqpClientService","options: AmqpClientModuleOptions<TContract>","AmqpClientModule"],"sources":["../src/client.service.ts","../src/client.module.ts"],"sourcesContent":["import { Inject, Injectable, type OnModuleDestroy, type OnModuleInit } from \"@nestjs/common\";\nimport type { Options } from \"amqplib\";\nimport type {\n ClientInferPublisherInput,\n ContractDefinition,\n InferPublisherNames,\n} from \"@amqp-contract/contract\";\nimport { TypedAmqpClient, type PublishOptions } from \"@amqp-contract/client\";\nimport { MODULE_OPTIONS_TOKEN } from \"./client.module.js\";\n\n/**\n * Options for creating a NestJS client service\n */\nexport interface AmqpClientModuleOptions<TContract extends ContractDefinition> {\n contract: TContract;\n connection: string | Options.Connect;\n}\n\n/**\n * Type-safe AMQP client service for NestJS\n * This service integrates @amqp-contract/client with NestJS lifecycle\n */\n@Injectable()\nexport class AmqpClientService<TContract extends ContractDefinition>\n implements OnModuleInit, OnModuleDestroy\n{\n private client: TypedAmqpClient<TContract> | null = null;\n\n constructor(\n @Inject(MODULE_OPTIONS_TOKEN)\n private readonly options: AmqpClientModuleOptions<TContract>,\n ) {}\n\n /**\n * Initialize the client when the NestJS module starts\n */\n async onModuleInit(): Promise<void> {\n this.client = await TypedAmqpClient.create({\n contract: this.options.contract,\n connection: this.options.connection,\n });\n }\n\n /**\n * Close the client when the NestJS module is destroyed\n */\n async onModuleDestroy(): Promise<void> {\n if (this.client) {\n await this.client.close();\n this.client = null;\n }\n }\n\n /**\n * Publish a message using a defined publisher\n * This method provides type-safe message publishing\n */\n async publish<TName extends InferPublisherNames<TContract>>(\n publisherName: TName,\n message: ClientInferPublisherInput<TContract, TName>,\n options?: PublishOptions,\n ): Promise<boolean> {\n if (!this.client) {\n throw new Error(\n \"Client not initialized. Create the client using TypedAmqpClient.create() to establish a connection.\",\n );\n }\n\n return this.client.publish(publisherName, message, options);\n }\n}\n","import { ConfigurableModuleBuilder, Module } from \"@nestjs/common\";\nimport type { AmqpClientModuleOptions } from \"./client.service.js\";\nimport { AmqpClientService } from \"./client.service.js\";\n\n/**\n * ConfigurableModuleBuilder for AMQP client module\n * This creates forRoot and forRootAsync methods automatically\n */\nexport const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN } = new ConfigurableModuleBuilder<\n AmqpClientModuleOptions<never>\n>()\n .setClassMethodName(\"forRoot\")\n .build();\n\n/**\n * NestJS module for AMQP client integration\n * This module provides type-safe AMQP client functionality using @amqp-contract/client\n * without relying on NestJS decorators (except for dependency injection)\n */\n@Module({\n providers: [AmqpClientService],\n exports: [AmqpClientService],\n})\nexport class AmqpClientModule extends ConfigurableModuleClass {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBO,8BAAMA,oBAEb;CACE,AAAQ,SAA4C;CAEpD,YACE,AACiBC,SACjB;EADiB;;;;;CAMnB,MAAM,eAA8B;AAClC,OAAK,SAAS,MAAM,gBAAgB,OAAO;GACzC,UAAU,KAAK,QAAQ;GACvB,YAAY,KAAK,QAAQ;GAC1B,CAAC;;;;;CAMJ,MAAM,kBAAiC;AACrC,MAAI,KAAK,QAAQ;AACf,SAAM,KAAK,OAAO,OAAO;AACzB,QAAK,SAAS;;;;;;;CAQlB,MAAM,QACJ,eACA,SACA,SACkB;AAClB,MAAI,CAAC,KAAK,OACR,OAAM,IAAI,MACR,sGACD;AAGH,SAAO,KAAK,OAAO,QAAQ,eAAe,SAAS,QAAQ;;;;CA9C9D,YAAY;oBAOR,OAAO,qBAAqB;;;;;;;;;;ACrBjC,MAAa,EAAE,yBAAyB,yBAAyB,IAAI,2BAElE,CACA,mBAAmB,UAAU,CAC7B,OAAO;AAWH,6BAAMC,2BAAyB,wBAAwB;+BAJ7D,OAAO;CACN,WAAW,CAAC,kBAAkB;CAC9B,SAAS,CAAC,kBAAkB;CAC7B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@amqp-contract/client-nestjs",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "NestJS integration for @amqp-contract/client",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"amqp",
|
|
7
|
+
"client",
|
|
8
|
+
"contract",
|
|
9
|
+
"nestjs",
|
|
10
|
+
"rabbitmq",
|
|
11
|
+
"typescript"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/btravers/amqp-contract#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/btravers/amqp-contract/issues"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/btravers/amqp-contract.git",
|
|
20
|
+
"directory": "packages/client-nestjs"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "Benoit TRAVERS <benoit.travers.fr@gmail.com>",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"import": {
|
|
28
|
+
"types": "./dist/index.d.mts",
|
|
29
|
+
"default": "./dist/index.mjs"
|
|
30
|
+
},
|
|
31
|
+
"require": {
|
|
32
|
+
"types": "./dist/index.d.cts",
|
|
33
|
+
"default": "./dist/index.cjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json"
|
|
37
|
+
},
|
|
38
|
+
"main": "./dist/index.cjs",
|
|
39
|
+
"module": "./dist/index.mjs",
|
|
40
|
+
"types": "./dist/index.d.mts",
|
|
41
|
+
"files": [
|
|
42
|
+
"dist"
|
|
43
|
+
],
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@amqp-contract/client": "0.0.6",
|
|
46
|
+
"@amqp-contract/contract": "0.0.6"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@nestjs/common": "11.0.10",
|
|
50
|
+
"@types/amqplib": "0.10.8",
|
|
51
|
+
"@types/node": "25.0.3",
|
|
52
|
+
"@vitest/coverage-v8": "4.0.16",
|
|
53
|
+
"amqplib": "0.10.9",
|
|
54
|
+
"reflect-metadata": "0.2.2",
|
|
55
|
+
"rxjs": "7.8.1",
|
|
56
|
+
"tsdown": "0.18.1",
|
|
57
|
+
"typescript": "5.9.3",
|
|
58
|
+
"vitest": "4.0.16",
|
|
59
|
+
"zod": "4.2.1",
|
|
60
|
+
"@amqp-contract/tsconfig": "0.0.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"@nestjs/common": ">=11.0.0",
|
|
64
|
+
"@nestjs/core": ">=11.0.0",
|
|
65
|
+
"amqplib": ">=0.10.0",
|
|
66
|
+
"reflect-metadata": ">=0.1.13",
|
|
67
|
+
"rxjs": ">=7.0.0"
|
|
68
|
+
},
|
|
69
|
+
"scripts": {
|
|
70
|
+
"build": "tsdown src/index.ts --format cjs,esm --dts --clean",
|
|
71
|
+
"dev": "tsdown src/index.ts --format cjs,esm --dts --watch",
|
|
72
|
+
"test": "vitest run --project unit",
|
|
73
|
+
"test:watch": "vitest --project unit",
|
|
74
|
+
"typecheck": "tsc --noEmit"
|
|
75
|
+
}
|
|
76
|
+
}
|