@romysaputrasihanandaa/nestjs-beanstalk 1.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.
Files changed (36) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +307 -0
  3. package/dist/client/beanstalk.client.d.ts +15 -0
  4. package/dist/client/beanstalk.client.d.ts.map +1 -0
  5. package/dist/client/beanstalk.client.js +110 -0
  6. package/dist/client/beanstalk.client.js.map +1 -0
  7. package/dist/context/beanstalk.context.d.ts +9 -0
  8. package/dist/context/beanstalk.context.d.ts.map +1 -0
  9. package/dist/context/beanstalk.context.js +17 -0
  10. package/dist/context/beanstalk.context.js.map +1 -0
  11. package/dist/decorators/index.d.ts +2 -0
  12. package/dist/decorators/index.d.ts.map +1 -0
  13. package/dist/decorators/index.js +7 -0
  14. package/dist/decorators/index.js.map +1 -0
  15. package/dist/index.d.ts +6 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +22 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/interfaces/beanstalk-message.interface.d.ts +5 -0
  20. package/dist/interfaces/beanstalk-message.interface.d.ts.map +1 -0
  21. package/dist/interfaces/beanstalk-message.interface.js +3 -0
  22. package/dist/interfaces/beanstalk-message.interface.js.map +1 -0
  23. package/dist/interfaces/beanstalk-options.interface.d.ts +27 -0
  24. package/dist/interfaces/beanstalk-options.interface.d.ts.map +1 -0
  25. package/dist/interfaces/beanstalk-options.interface.js +3 -0
  26. package/dist/interfaces/beanstalk-options.interface.js.map +1 -0
  27. package/dist/interfaces/index.d.ts +3 -0
  28. package/dist/interfaces/index.d.ts.map +1 -0
  29. package/dist/interfaces/index.js +19 -0
  30. package/dist/interfaces/index.js.map +1 -0
  31. package/dist/server/beanstalk.server.d.ts +25 -0
  32. package/dist/server/beanstalk.server.d.ts.map +1 -0
  33. package/dist/server/beanstalk.server.js +244 -0
  34. package/dist/server/beanstalk.server.js.map +1 -0
  35. package/dist/tsconfig.build.tsbuildinfo +1 -0
  36. package/package.json +99 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2019 Jesse Carter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,307 @@
1
+ # @romysaputrasihanandaa/nestjs-beanstalk
2
+
3
+ NestJS custom transport strategy for [Beanstalkd](https://beanstalkd.github.io/).
4
+ Use `@MessagePattern`, `@Payload`, and `@Ctx` exactly like any built-in NestJS transport.
5
+
6
+ ## Features
7
+
8
+ - Drop-in transport strategy — wire it up with `NestFactory.createMicroservice()`
9
+ - Full `@MessagePattern` / `@Payload` / `@Ctx` support
10
+ - Automatic retry with configurable delay and max attempts
11
+ - Automatic bury after retries exhausted
12
+ - `kickBuried()` / `kickJob()` to resurrect buried jobs
13
+ - Concurrency — multiple reserve workers per server instance
14
+ - Auto-reconnect on connection loss
15
+ - NestJS-style logging (`[Nest] pid - date LEVEL [BeanstalkServer] message`)
16
+ - Pluggable logger — pass any `LoggerService` (Winston, Pino, etc.)
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install @romysaputrasihanandaa/nestjs-beanstalk
22
+ ```
23
+
24
+ Peer dependencies (install separately if not already present):
25
+
26
+ ```bash
27
+ npm install @nestjs/common @nestjs/core @nestjs/microservices reflect-metadata
28
+ ```
29
+
30
+ ## Quick Start
31
+
32
+ ### Consumer
33
+
34
+ ```ts
35
+ // main.ts
36
+ import { NestFactory } from '@nestjs/core';
37
+ import { BeanstalkServer } from '@romysaputrasihanandaa/nestjs-beanstalk';
38
+ import { AppModule } from './app.module';
39
+
40
+ async function bootstrap() {
41
+ const app = await NestFactory.createMicroservice(AppModule, {
42
+ strategy: new BeanstalkServer({
43
+ host: 'localhost',
44
+ port: 11300,
45
+ tube: 'orders',
46
+ concurrency: 3,
47
+ }),
48
+ });
49
+ await app.listen();
50
+ }
51
+ bootstrap();
52
+ ```
53
+
54
+ ```ts
55
+ // orders.controller.ts
56
+ import { Controller } from '@nestjs/common';
57
+ import { Ctx, MessagePattern, Payload } from '@nestjs/microservices';
58
+ import { BeanstalkContext } from '@romysaputrasihanandaa/nestjs-beanstalk';
59
+
60
+ @Controller()
61
+ export class OrdersController {
62
+ @MessagePattern('order.created')
63
+ async handleOrderCreated(
64
+ @Payload() data: { id: number; product: string },
65
+ @Ctx() ctx: BeanstalkContext,
66
+ ): Promise<void> {
67
+ console.log(`job #${ctx.getJobId()} on tube "${ctx.getTube()}"`, data);
68
+ }
69
+ }
70
+ ```
71
+
72
+ ### Producer
73
+
74
+ ```ts
75
+ import { BeanstalkClient } from '@romysaputrasihanandaa/nestjs-beanstalk';
76
+
77
+ const client = new BeanstalkClient({ host: 'localhost', tube: 'orders' });
78
+ await client.connect();
79
+
80
+ const jobId = await client.emit('order.created', { id: 1, product: 'Widget' });
81
+ console.log('queued job', jobId);
82
+
83
+ client.disconnect();
84
+ ```
85
+
86
+ ## API Reference
87
+
88
+ ### `BeanstalkServer`
89
+
90
+ ```ts
91
+ new BeanstalkServer(options?: BeanstalkServerOptions)
92
+ ```
93
+
94
+ | Option | Type | Default | Description |
95
+ |---|---|---|---|
96
+ | `host` | `string` | `'localhost'` | Beanstalkd host |
97
+ | `port` | `number` | `11300` | Beanstalkd port |
98
+ | `tube` | `string` | `'default'` | Tube to watch |
99
+ | `concurrency` | `number` | `1` | Number of parallel reserve workers |
100
+ | `autoAck` | `boolean` | `true` | Delete job automatically after handler succeeds |
101
+ | `maxRetries` | `number` | `3` | Max releases before burying the job |
102
+ | `retryDelay` | `number` | `5` | Seconds before a released job becomes ready again |
103
+ | `retryPriority` | `number` | `0` | Priority used when releasing for retry |
104
+ | `ttr` | `number` | `60` | Time-To-Run in seconds |
105
+ | `reconnectDelay` | `number` | `3000` | Milliseconds before a reconnect attempt |
106
+ | `logger` | `boolean \| LoggerService` | `true` | `true` = NestJS Logger, `false` = silent, or a custom `LoggerService` |
107
+
108
+ ### `BeanstalkClient`
109
+
110
+ ```ts
111
+ new BeanstalkClient(options?: BeanstalkClientOptions)
112
+ ```
113
+
114
+ | Option | Type | Default | Description |
115
+ |---|---|---|---|
116
+ | `host` | `string` | `'localhost'` | Beanstalkd host |
117
+ | `port` | `number` | `11300` | Beanstalkd port |
118
+ | `tube` | `string` | `'default'` | Tube to put jobs into |
119
+ | `priority` | `number` | `0` | Default job priority (lower = higher priority) |
120
+ | `delay` | `number` | `0` | Default delay in seconds before job becomes ready |
121
+ | `ttr` | `number` | `60` | Default Time-To-Run in seconds |
122
+
123
+ #### Methods
124
+
125
+ ```ts
126
+ // Connect to Beanstalkd (lazy — called automatically on first emit)
127
+ await client.connect(): Promise<void>
128
+
129
+ // Disconnect
130
+ client.disconnect(): void
131
+
132
+ // Put a job onto the tube — returns the Beanstalkd job ID
133
+ await client.emit(pattern: string, data: T, options?: BeanstalkEmitOptions): Promise<number>
134
+
135
+ // Switch the active tube without reconnecting
136
+ await client.useTube(tube: string): Promise<void>
137
+
138
+ // Kick up to `bound` buried jobs in the current tube back to ready (default: 100)
139
+ await client.kickBuried(bound?: number): Promise<number>
140
+
141
+ // Kick a single buried or delayed job by ID back to ready
142
+ await client.kickJob(jobId: number): Promise<void>
143
+ ```
144
+
145
+ `BeanstalkEmitOptions` overrides per call:
146
+
147
+ ```ts
148
+ { priority?: number; delay?: number; ttr?: number; }
149
+ ```
150
+
151
+ ### `BeanstalkContext`
152
+
153
+ Injected via `@Ctx()`. Extends `BaseRpcContext`.
154
+
155
+ ```ts
156
+ ctx.getJobId(): number // Beanstalkd job ID
157
+ ctx.getTube(): string // tube the job was reserved from
158
+ ```
159
+
160
+ ### `@BeanstalkPattern(pattern)`
161
+
162
+ Alias for `@MessagePattern()` — functionally identical, provided for clarity.
163
+
164
+ ```ts
165
+ import { BeanstalkPattern } from '@romysaputrasihanandaa/nestjs-beanstalk';
166
+
167
+ @BeanstalkPattern('order.created')
168
+ async handle(@Payload() data: any) { ... }
169
+ ```
170
+
171
+ ## Message Format
172
+
173
+ Jobs are stored in Beanstalkd as JSON:
174
+
175
+ ```json
176
+ {
177
+ "pattern": "order.created",
178
+ "data": { "id": 1, "product": "Widget" }
179
+ }
180
+ ```
181
+
182
+ The `pattern` field is matched against registered `@MessagePattern()` handlers.
183
+
184
+ ## Retry & Bury
185
+
186
+ When a handler throws, the server checks the job's release count via `stats-job`:
187
+
188
+ ```
189
+ attempt 1 → throws → releases=0 < maxRetries → release (delay Ns)
190
+ attempt 2 → throws → releases=1 < maxRetries → release (delay Ns)
191
+ attempt 3 → throws → releases=2 < maxRetries → release (delay Ns)
192
+ attempt 4 → throws → releases=3 = maxRetries → bury
193
+ ```
194
+
195
+ With the default `maxRetries: 3`, a job is buried after **4 total attempts**.
196
+
197
+ ### Kicking buried jobs
198
+
199
+ ```ts
200
+ // Resurrect up to 100 buried jobs in the current tube
201
+ const kicked = await client.kickBuried();
202
+ console.log(`${kicked} jobs moved back to ready`);
203
+
204
+ // Resurrect a specific job by ID
205
+ await client.kickJob(jobId);
206
+ ```
207
+
208
+ ## Logging
209
+
210
+ Logs use the same format as the NestJS framework:
211
+
212
+ ```
213
+ [Nest] 1234 - 04/06/2026, 1:57:39 AM LOG [BeanstalkServer] Listening on localhost:11300 tube="orders" concurrency=3
214
+ [Nest] 1234 - 04/06/2026, 1:57:41 AM WARN [BeanstalkServer] Job #42: retry 1/3 (delay 5s)
215
+ [Nest] 1234 - 04/06/2026, 1:57:51 AM WARN [BeanstalkServer] Job #42: buried — exceeded maxRetries (3)
216
+ [Nest] 1234 - 04/06/2026, 1:57:52 AM ERROR [BeanstalkServer] Job #42 (worker #0) handler threw: Error: ...
217
+ ```
218
+
219
+ Disable logging:
220
+
221
+ ```ts
222
+ new BeanstalkServer({ logger: false })
223
+ ```
224
+
225
+ Custom logger (e.g. Winston):
226
+
227
+ ```ts
228
+ new BeanstalkServer({ logger: new WinstonLogger() })
229
+ ```
230
+
231
+ ## Advanced Usage
232
+
233
+ ### Manual ack
234
+
235
+ When `autoAck: false`, the job stays reserved after the handler returns. The job is released back to ready when the connection closes (after TTR expires).
236
+
237
+ ```ts
238
+ new BeanstalkServer({ autoAck: false })
239
+
240
+ @MessagePattern('order.created')
241
+ async handle(@Payload() data: any, @Ctx() ctx: BeanstalkContext) {
242
+ console.log('processing job', ctx.getJobId());
243
+ // job is not auto-deleted — handle deletion yourself
244
+ }
245
+ ```
246
+
247
+ ### Concurrency
248
+
249
+ ```ts
250
+ new BeanstalkServer({ tube: 'orders', concurrency: 5 })
251
+ ```
252
+
253
+ Each worker has its own TCP connection and reserves jobs independently.
254
+
255
+ ### Delayed jobs
256
+
257
+ ```ts
258
+ await client.emit('report.generate', { reportId: 7 }, { delay: 60 }); // ready in 60s
259
+ ```
260
+
261
+ ### Multiple tubes from one producer
262
+
263
+ ```ts
264
+ const client = new BeanstalkClient({ tube: 'orders' });
265
+ await client.connect();
266
+
267
+ await client.emit('order.created', { id: 1 });
268
+
269
+ await client.useTube('notifications');
270
+ await client.emit('email.send', { to: 'user@example.com' });
271
+
272
+ client.disconnect();
273
+ ```
274
+
275
+ ## Project Structure
276
+
277
+ ```
278
+ src/
279
+ ├── client/
280
+ │ └── beanstalk.client.ts # BeanstalkClient — job producer
281
+ ├── context/
282
+ │ └── beanstalk.context.ts # BeanstalkContext — injected via @Ctx()
283
+ ├── decorators/
284
+ │ └── index.ts # @BeanstalkPattern alias
285
+ ├── interfaces/
286
+ │ ├── beanstalk-message.interface.ts
287
+ │ └── beanstalk-options.interface.ts
288
+ ├── server/
289
+ │ └── beanstalk.server.ts # BeanstalkServer — transport strategy
290
+ ├── types/
291
+ │ └── fivebeans.d.ts # TypeScript declarations for fivebeans
292
+ └── index.ts # Public API barrel
293
+ ```
294
+
295
+ ## Running Tests
296
+
297
+ ```bash
298
+ # unit tests
299
+ npm test
300
+
301
+ # integration tests (requires Beanstalkd running on 127.0.0.1:11300)
302
+ npm run test:e2e
303
+ ```
304
+
305
+ ## License
306
+
307
+ MIT
@@ -0,0 +1,15 @@
1
+ import { BeanstalkClientOptions, BeanstalkEmitOptions } from '../interfaces';
2
+ export declare class BeanstalkClient {
3
+ private readonly opts;
4
+ private _client;
5
+ private _connected;
6
+ constructor(options?: BeanstalkClientOptions);
7
+ connect(): Promise<void>;
8
+ disconnect(): void;
9
+ emit<T = unknown>(pattern: string, data: T, options?: BeanstalkEmitOptions): Promise<number>;
10
+ useTube(tube: string): Promise<void>;
11
+ kickBuried(bound?: number): Promise<number>;
12
+ kickJob(jobId: number): Promise<void>;
13
+ get isConnected(): boolean;
14
+ }
15
+ //# sourceMappingURL=beanstalk.client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"beanstalk.client.d.ts","sourceRoot":"","sources":["../../src/client/beanstalk.client.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EAErB,MAAM,eAAe,CAAC;AAuBvB,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAmC;IACxD,OAAO,CAAC,OAAO,CAAgC;IAC/C,OAAO,CAAC,UAAU,CAAS;gBAEf,OAAO,GAAE,sBAA2B;IAMhD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA2BxB,UAAU,IAAI,IAAI;IAqBZ,IAAI,CAAC,CAAC,GAAG,OAAO,EACpB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,CAAC,EACP,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,MAAM,CAAC;IAwBlB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAyB9B,UAAU,CAAC,KAAK,SAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAqBxC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS3C,IAAI,WAAW,IAAI,OAAO,CAEzB;CACF"}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BeanstalkClient = void 0;
4
+ const fivebeans_1 = require("fivebeans");
5
+ const DEFAULTS = {
6
+ host: 'localhost',
7
+ port: 11300,
8
+ tube: 'default',
9
+ priority: 0,
10
+ delay: 0,
11
+ ttr: 60,
12
+ };
13
+ class BeanstalkClient {
14
+ constructor(options = {}) {
15
+ this._client = null;
16
+ this._connected = false;
17
+ this.opts = { ...DEFAULTS, ...options };
18
+ }
19
+ connect() {
20
+ if (this._connected)
21
+ return Promise.resolve();
22
+ return new Promise((resolve, reject) => {
23
+ const { host, port, tube } = this.opts;
24
+ const c = new fivebeans_1.client(host, port);
25
+ const onError = (err) => {
26
+ c.removeAllListeners();
27
+ reject(err);
28
+ };
29
+ c.once('error', onError);
30
+ c.once('connect', () => {
31
+ c.removeListener('error', onError);
32
+ c.use(tube, (err) => {
33
+ if (err)
34
+ return reject(err);
35
+ this._client = c;
36
+ this._connected = true;
37
+ resolve();
38
+ });
39
+ });
40
+ c.connect();
41
+ });
42
+ }
43
+ disconnect() {
44
+ if (this._client) {
45
+ try {
46
+ this._client.end();
47
+ }
48
+ catch {
49
+ }
50
+ }
51
+ this._client = null;
52
+ this._connected = false;
53
+ }
54
+ async emit(pattern, data, options = {}) {
55
+ if (!this._connected || !this._client) {
56
+ await this.connect();
57
+ }
58
+ const msg = { pattern, data };
59
+ const body = JSON.stringify(msg);
60
+ const priority = options.priority ?? this.opts.priority;
61
+ const delay = options.delay ?? this.opts.delay;
62
+ const ttr = options.ttr ?? this.opts.ttr;
63
+ return new Promise((resolve, reject) => {
64
+ this._client.put(priority, delay, ttr, body, (err, jobId) => {
65
+ if (err)
66
+ return reject(err);
67
+ resolve(typeof jobId === 'string' ? parseInt(jobId, 10) : jobId);
68
+ });
69
+ });
70
+ }
71
+ useTube(tube) {
72
+ if (!this._client) {
73
+ return Promise.reject(new Error('Not connected. Call connect() first.'));
74
+ }
75
+ return new Promise((resolve, reject) => {
76
+ this._client.use(tube, (err) => {
77
+ if (err)
78
+ return reject(err);
79
+ this.opts.tube = tube;
80
+ resolve();
81
+ });
82
+ });
83
+ }
84
+ async kickBuried(bound = 100) {
85
+ if (!this._connected || !this._client) {
86
+ await this.connect();
87
+ }
88
+ return new Promise((resolve, reject) => {
89
+ this._client.kick(bound, (err, count) => {
90
+ if (err)
91
+ return reject(err);
92
+ const n = typeof count === 'string' ? parseInt(count, 10) : count;
93
+ resolve(n);
94
+ });
95
+ });
96
+ }
97
+ async kickJob(jobId) {
98
+ if (!this._connected || !this._client) {
99
+ await this.connect();
100
+ }
101
+ return new Promise((resolve, reject) => {
102
+ this._client.kick_job(jobId, (err) => (err ? reject(err) : resolve()));
103
+ });
104
+ }
105
+ get isConnected() {
106
+ return this._connected;
107
+ }
108
+ }
109
+ exports.BeanstalkClient = BeanstalkClient;
110
+ //# sourceMappingURL=beanstalk.client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"beanstalk.client.js","sourceRoot":"","sources":["../../src/client/beanstalk.client.ts"],"names":[],"mappings":";;;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,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;gBAClE,OAAO,CAAC,CAAC,CAAC,CAAC;YACb,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAUD,KAAK,CAAC,OAAO,CAAC,KAAa;QACzB,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YACtC,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QACvB,CAAC;QACD,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3C,IAAI,CAAC,OAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAC1E,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;CACF;AAjJD,0CAiJC"}
@@ -0,0 +1,9 @@
1
+ import { BaseRpcContext } from '@nestjs/microservices';
2
+ type BeanstalkContextArgs = [jobId: number, tube: string];
3
+ export declare class BeanstalkContext extends BaseRpcContext<BeanstalkContextArgs> {
4
+ constructor(args: BeanstalkContextArgs);
5
+ getJobId(): number;
6
+ getTube(): string;
7
+ }
8
+ export {};
9
+ //# sourceMappingURL=beanstalk.context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"beanstalk.context.d.ts","sourceRoot":"","sources":["../../src/context/beanstalk.context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,KAAK,oBAAoB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AAa1D,qBAAa,gBAAiB,SAAQ,cAAc,CAAC,oBAAoB,CAAC;gBAC5D,IAAI,EAAE,oBAAoB;IAKtC,QAAQ,IAAI,MAAM;IAKlB,OAAO,IAAI,MAAM;CAGlB"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BeanstalkContext = void 0;
4
+ const microservices_1 = require("@nestjs/microservices");
5
+ class BeanstalkContext extends microservices_1.BaseRpcContext {
6
+ constructor(args) {
7
+ super(args);
8
+ }
9
+ getJobId() {
10
+ return this.args[0];
11
+ }
12
+ getTube() {
13
+ return this.args[1];
14
+ }
15
+ }
16
+ exports.BeanstalkContext = BeanstalkContext;
17
+ //# sourceMappingURL=beanstalk.context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"beanstalk.context.js","sourceRoot":"","sources":["../../src/context/beanstalk.context.ts"],"names":[],"mappings":";;;AAAA,yDAAuD;AAevD,MAAa,gBAAiB,SAAQ,8BAAoC;IACxE,YAAY,IAA0B;QACpC,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAGD,QAAQ;QACN,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACtB,CAAC;IAGD,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACtB,CAAC;CACF;AAdD,4CAcC"}
@@ -0,0 +1,2 @@
1
+ export declare const BeanstalkPattern: (pattern: string) => MethodDecorator;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,gBAAgB,GAAI,SAAS,MAAM,KAAG,eAC1B,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BeanstalkPattern = void 0;
4
+ const microservices_1 = require("@nestjs/microservices");
5
+ const BeanstalkPattern = (pattern) => (0, microservices_1.MessagePattern)(pattern);
6
+ exports.BeanstalkPattern = BeanstalkPattern;
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";;;AAAA,yDAAuD;AAahD,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAmB,EAAE,CACnE,IAAA,8BAAc,EAAC,OAAO,CAAC,CAAC;AADb,QAAA,gBAAgB,oBACH"}
@@ -0,0 +1,6 @@
1
+ export * from './client/beanstalk.client';
2
+ export * from './context/beanstalk.context';
3
+ export * from './decorators';
4
+ export * from './interfaces';
5
+ export * from './server/beanstalk.server';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,2BAA2B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./client/beanstalk.client"), exports);
18
+ __exportStar(require("./context/beanstalk.context"), exports);
19
+ __exportStar(require("./decorators"), exports);
20
+ __exportStar(require("./interfaces"), exports);
21
+ __exportStar(require("./server/beanstalk.server"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,8DAA4C;AAC5C,+CAA6B;AAC7B,+CAA6B;AAC7B,4DAA0C"}
@@ -0,0 +1,5 @@
1
+ export interface BeanstalkMessage<T = unknown> {
2
+ pattern: string;
3
+ data: T;
4
+ }
5
+ //# sourceMappingURL=beanstalk-message.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"beanstalk-message.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/beanstalk-message.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,OAAO;IAE3C,OAAO,EAAE,MAAM,CAAC;IAEhB,IAAI,EAAE,CAAC,CAAC;CACT"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=beanstalk-message.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"beanstalk-message.interface.js","sourceRoot":"","sources":["../../src/interfaces/beanstalk-message.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,27 @@
1
+ export interface BeanstalkServerOptions {
2
+ host?: string;
3
+ port?: number;
4
+ tube?: string;
5
+ concurrency?: number;
6
+ autoAck?: boolean;
7
+ maxRetries?: number;
8
+ retryDelay?: number;
9
+ retryPriority?: number;
10
+ ttr?: number;
11
+ reconnectDelay?: number;
12
+ logger?: boolean | import('@nestjs/common').LoggerService;
13
+ }
14
+ export interface BeanstalkClientOptions {
15
+ host?: string;
16
+ port?: number;
17
+ tube?: string;
18
+ priority?: number;
19
+ delay?: number;
20
+ ttr?: number;
21
+ }
22
+ export interface BeanstalkEmitOptions {
23
+ priority?: number;
24
+ delay?: number;
25
+ ttr?: number;
26
+ }
27
+ //# sourceMappingURL=beanstalk-options.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"beanstalk-options.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/beanstalk-options.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IAErC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,WAAW,CAAC,EAAE,MAAM,CAAC;IAKrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,cAAc,CAAC,EAAE,MAAM,CAAC;IAOxB,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,gBAAgB,EAAE,aAAa,CAAC;CAC3D;AAED,MAAM,WAAW,sBAAsB;IAErC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;CACd"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=beanstalk-options.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"beanstalk-options.interface.js","sourceRoot":"","sources":["../../src/interfaces/beanstalk-options.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export * from './beanstalk-message.interface';
2
+ export * from './beanstalk-options.interface';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./beanstalk-message.interface"), exports);
18
+ __exportStar(require("./beanstalk-options.interface"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA8C;AAC9C,gEAA8C"}