amqpx 1.0.1 → 1.0.3
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 +3 -3
- package/dist/cjs/connection/connection-implementation.d.ts +1 -1
- package/dist/cjs/exchange/exchange-implementation.d.ts +1 -0
- package/dist/cjs/exchange/exchange-implementation.js +6 -29
- package/dist/cjs/exchange/exchange.d.ts +13 -12
- package/dist/cjs/exchange/types.d.ts +4 -13
- package/dist/cjs/exchange/types.js +0 -6
- package/dist/cjs/extensions/vitest/test-batch-consumer.d.ts +3 -2
- package/dist/cjs/extensions/vitest/test-channel.d.ts +17 -26
- package/dist/cjs/extensions/vitest/test-connection.d.ts +12 -11
- package/dist/cjs/extensions/vitest/test-consumer.d.ts +4 -3
- package/dist/cjs/extensions/vitest/test-exchange.d.ts +8 -7
- package/dist/cjs/extensions/vitest/test-producer.d.ts +3 -2
- package/dist/cjs/extensions/vitest/test-queue.d.ts +7 -6
- package/dist/cjs/predefined.d.ts +26 -21
- package/dist/cjs/predefined.js +11 -5
- package/dist/cjs/queue/queue-implementation.d.ts +8 -0
- package/dist/cjs/queue/queue-implementation.js +62 -10
- package/dist/cjs/queue/queue.d.ts +3 -1
- package/dist/cjs/queue/types.d.ts +3 -3
- package/dist/esm/connection/connection-implementation.d.ts +1 -1
- package/dist/esm/exchange/exchange-implementation.d.ts +1 -0
- package/dist/esm/exchange/exchange-implementation.js +6 -29
- package/dist/esm/exchange/exchange.d.ts +13 -12
- package/dist/esm/exchange/types.d.ts +4 -13
- package/dist/esm/exchange/types.js +1 -5
- package/dist/esm/extensions/vitest/test-batch-consumer.d.ts +3 -2
- package/dist/esm/extensions/vitest/test-channel.d.ts +17 -26
- package/dist/esm/extensions/vitest/test-connection.d.ts +12 -11
- package/dist/esm/extensions/vitest/test-consumer.d.ts +4 -3
- package/dist/esm/extensions/vitest/test-exchange.d.ts +8 -7
- package/dist/esm/extensions/vitest/test-producer.d.ts +3 -2
- package/dist/esm/extensions/vitest/test-queue.d.ts +7 -6
- package/dist/esm/predefined.d.ts +26 -21
- package/dist/esm/predefined.js +11 -5
- package/dist/esm/queue/queue-implementation.d.ts +8 -0
- package/dist/esm/queue/queue-implementation.js +60 -11
- package/dist/esm/queue/queue.d.ts +3 -1
- package/dist/esm/queue/types.d.ts +3 -3
- package/package.json +19 -14
|
@@ -8,9 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.QueueImplementation = void 0;
|
|
13
16
|
const util_1 = require("util");
|
|
17
|
+
const safe_stable_stringify_1 = __importDefault(require("safe-stable-stringify"));
|
|
14
18
|
const consumer_1 = require("../consumer");
|
|
15
19
|
const producer_1 = require("../producer");
|
|
16
20
|
const index_1 = require("../index");
|
|
@@ -25,10 +29,13 @@ class QueueImplementation {
|
|
|
25
29
|
this.channel = channel;
|
|
26
30
|
this.queueName = queueName;
|
|
27
31
|
this.assertPromise = null;
|
|
32
|
+
this.declaredName = null;
|
|
33
|
+
this.bindings = [];
|
|
28
34
|
this.options = (0, utils_1.deepMerge)({}, DEFAULT_QUEUE_OPTIONS, options !== null && options !== void 0 ? options : {});
|
|
29
35
|
this.channel.on('close', () => {
|
|
30
36
|
debug('native-close');
|
|
31
37
|
this.assertPromise = null;
|
|
38
|
+
this.declaredName = null;
|
|
32
39
|
});
|
|
33
40
|
}
|
|
34
41
|
assert() {
|
|
@@ -37,43 +44,88 @@ class QueueImplementation {
|
|
|
37
44
|
yield this.assertPromise;
|
|
38
45
|
return this;
|
|
39
46
|
}
|
|
40
|
-
|
|
47
|
+
const promise = (() => __awaiter(this, void 0, void 0, function* () {
|
|
41
48
|
var _a, _b, _c;
|
|
42
49
|
debug('assert name=%s mode=%s', this.queueName, (_a = this.options) === null || _a === void 0 ? void 0 : _a.assertionMode);
|
|
43
50
|
const channel = yield this.channel.native();
|
|
44
51
|
switch ((_b = this.options) === null || _b === void 0 ? void 0 : _b.assertionMode) {
|
|
45
52
|
case types_1.AssertionMode.Check:
|
|
46
53
|
yield channel.checkQueue(this.queueName);
|
|
54
|
+
this.declaredName = this.queueName;
|
|
47
55
|
debug('native-check-done name=%s', this.queueName);
|
|
48
56
|
break;
|
|
49
|
-
case types_1.AssertionMode.Assert:
|
|
50
|
-
yield channel.assertQueue(this.queueName, this.options);
|
|
51
|
-
|
|
57
|
+
case types_1.AssertionMode.Assert: {
|
|
58
|
+
const reply = yield channel.assertQueue(this.queueName, this.options);
|
|
59
|
+
this.declaredName = reply.queue;
|
|
60
|
+
debug('native-assert-done name=%s declared-name=%s', this.queueName, this.declaredName);
|
|
52
61
|
break;
|
|
62
|
+
}
|
|
53
63
|
case types_1.AssertionMode.Passive:
|
|
64
|
+
this.declaredName = this.queueName;
|
|
54
65
|
debug('no-assert name=%s mode=%s', this.queueName, this.options.assertionMode);
|
|
55
66
|
break;
|
|
56
67
|
default:
|
|
57
68
|
throw new Error(`Unknown assertion mode: ${(_c = this.options) === null || _c === void 0 ? void 0 : _c.assertionMode}`);
|
|
58
69
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
70
|
+
yield this.rebind();
|
|
71
|
+
debug('assert-complete name=%s', this.currentName());
|
|
72
|
+
}))().catch((error) => {
|
|
73
|
+
if (this.assertPromise === promise) {
|
|
74
|
+
this.assertPromise = null;
|
|
75
|
+
this.declaredName = null;
|
|
76
|
+
}
|
|
77
|
+
throw error;
|
|
78
|
+
});
|
|
79
|
+
this.assertPromise = promise;
|
|
80
|
+
yield promise;
|
|
62
81
|
return this;
|
|
63
82
|
});
|
|
64
83
|
}
|
|
65
84
|
name() {
|
|
66
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
return this.assert().then(self => self.
|
|
86
|
+
return this.assert().then(self => self.currentName());
|
|
68
87
|
});
|
|
69
88
|
}
|
|
70
89
|
bindExchange(exchange, pattern, args) {
|
|
71
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
|
|
73
|
-
yield
|
|
91
|
+
yield this.assert();
|
|
92
|
+
yield this.nativeBind({ exchange, pattern, args });
|
|
93
|
+
const isSameBinding = (binding) => binding.exchange === exchange &&
|
|
94
|
+
binding.pattern === pattern &&
|
|
95
|
+
(0, safe_stable_stringify_1.default)(binding.args) === (0, safe_stable_stringify_1.default)(args);
|
|
96
|
+
if (this.bindings.every(binding => !isSameBinding(binding)))
|
|
97
|
+
this.bindings.push({ exchange, pattern, args });
|
|
74
98
|
return this;
|
|
75
99
|
});
|
|
76
100
|
}
|
|
101
|
+
nativeBind(_a) {
|
|
102
|
+
return __awaiter(this, arguments, void 0, function* ({ exchange, pattern, args }) {
|
|
103
|
+
const exchangeName = yield exchange.name();
|
|
104
|
+
const queueName = this.currentName();
|
|
105
|
+
debug('bind-exchange queue=%s exchange=%s pattern=%s', queueName, exchangeName, pattern);
|
|
106
|
+
const channel = yield this.channel.native();
|
|
107
|
+
yield channel.bindQueue(queueName, exchangeName, pattern, args);
|
|
108
|
+
debug('bind-exchange-done queue=%s exchange=%s pattern=%s', queueName, exchangeName, pattern);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
currentName() {
|
|
112
|
+
var _a;
|
|
113
|
+
return (_a = this.declaredName) !== null && _a !== void 0 ? _a : this.queueName;
|
|
114
|
+
}
|
|
115
|
+
rebind() {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
if (this.bindings.length === 0)
|
|
118
|
+
return;
|
|
119
|
+
debug('rebind name=%s bindings=%d', this.currentName(), this.bindings.length);
|
|
120
|
+
const results = yield Promise.allSettled(this.bindings.map(binding => this.nativeBind(binding)));
|
|
121
|
+
const failed = results.find(result => result.status === 'rejected');
|
|
122
|
+
if (failed) {
|
|
123
|
+
debug('rebind-failed error=%s', (0, utils_1.errToMessage)(failed.reason));
|
|
124
|
+
throw failed.reason;
|
|
125
|
+
}
|
|
126
|
+
debug('rebind-complete name=%s', this.currentName());
|
|
127
|
+
});
|
|
128
|
+
}
|
|
77
129
|
createConsumer(options = {}) {
|
|
78
130
|
var _a;
|
|
79
131
|
return Promise.resolve(new consumer_1.ConsumerImplementation((_a = options.channel) !== null && _a !== void 0 ? _a : this.channel.connection.createChannel(), this, options));
|
|
@@ -21,7 +21,9 @@ export interface Queue {
|
|
|
21
21
|
name(): Promise<string>;
|
|
22
22
|
/**
|
|
23
23
|
* Bind this queue to an exchange.
|
|
24
|
-
* Asserts the queue first if
|
|
24
|
+
* Asserts the queue and the exchange first if they have not been asserted yet.
|
|
25
|
+
* Equivalent to `exchange.bindQueue(queue, pattern, args)`.
|
|
26
|
+
* The binding is restored when the queue is asserted again after a reconnect.
|
|
25
27
|
* @param exchange - Exchange to bind this queue to.
|
|
26
28
|
* @param pattern - Routing key pattern under which to bind.
|
|
27
29
|
* @param args - Optional AMQP headers or x-arguments for the binding.
|
|
@@ -15,11 +15,11 @@ export type QueueOptions = amqp.Options.AssertQueue & {
|
|
|
15
15
|
*/
|
|
16
16
|
assertionMode?: AssertionMode;
|
|
17
17
|
};
|
|
18
|
-
type ExchangeName = string;
|
|
19
18
|
type Pattern = string;
|
|
20
|
-
|
|
19
|
+
/** A binding of a queue to an exchange. */
|
|
20
|
+
export type QueueBinding = {
|
|
21
21
|
exchange: Exchange;
|
|
22
22
|
pattern: Pattern;
|
|
23
23
|
args?: BindingArgs;
|
|
24
|
-
}
|
|
24
|
+
};
|
|
25
25
|
export {};
|
|
@@ -14,7 +14,7 @@ export declare class ConnectionImplementation extends EventEmitter<ConnectionEve
|
|
|
14
14
|
private connection;
|
|
15
15
|
private closingHandler;
|
|
16
16
|
private connectionState;
|
|
17
|
-
constructor(options: amqp.Options.Connect, retryStrategy?: RetryStrategy, socketOptions?:
|
|
17
|
+
constructor(options: amqp.Options.Connect, retryStrategy?: RetryStrategy, socketOptions?: amqp.SocketOptions | undefined);
|
|
18
18
|
connect(): Promise<this>;
|
|
19
19
|
close(timeout?: number): Promise<void>;
|
|
20
20
|
state(): ConnectionState;
|
|
@@ -9,6 +9,7 @@ export declare class ExchangeImplementation implements Exchange {
|
|
|
9
9
|
private readonly exchangeType;
|
|
10
10
|
private readonly options?;
|
|
11
11
|
private assertPromise;
|
|
12
|
+
/** Exchange bindings, re-applied when the exchange is asserted again. */
|
|
12
13
|
private bindings;
|
|
13
14
|
constructor(channel: Channel, exchangeName: string, exchangeType: ExchangeTypes, options?: ExchangeOptions);
|
|
14
15
|
assert(): Promise<this>;
|
|
@@ -12,7 +12,6 @@ import stableJsonStringify from 'safe-stable-stringify';
|
|
|
12
12
|
import { ProducerImplementation } from '../producer';
|
|
13
13
|
import { deepMerge, errToMessage, LIB_NAME } from '../utils';
|
|
14
14
|
import { AssertionMode } from '../types';
|
|
15
|
-
import { BindingType } from './types';
|
|
16
15
|
const debug = debuglog(`${LIB_NAME}:exchange`);
|
|
17
16
|
const DEFAULT_EXCHANGE_OPTIONS = {
|
|
18
17
|
assertionMode: AssertionMode.Assert,
|
|
@@ -69,26 +68,8 @@ export class ExchangeImplementation {
|
|
|
69
68
|
}
|
|
70
69
|
bindQueue(queue, pattern, args) {
|
|
71
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
queue.name(),
|
|
75
|
-
]);
|
|
76
|
-
debug('bind-queue exchange=%s queue=%s pattern=%s', thisName, queueName, pattern);
|
|
77
|
-
const doesBindingMatch = (binding) => binding.type === BindingType.queue &&
|
|
78
|
-
binding.pattern === pattern &&
|
|
79
|
-
binding.queue === queue &&
|
|
80
|
-
stableJsonStringify(binding.args) === stableJsonStringify(args);
|
|
81
|
-
if (this.bindings.every(binding => !doesBindingMatch(binding))) {
|
|
82
|
-
this.bindings.push({
|
|
83
|
-
args,
|
|
84
|
-
pattern,
|
|
85
|
-
type: BindingType.queue,
|
|
86
|
-
queue,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
const channel = yield this.channel.native();
|
|
90
|
-
yield channel.bindQueue(queueName, thisName, pattern, args);
|
|
91
|
-
debug('bind-queue-done exchange=%s queue=%s pattern=%s', thisName, queueName, pattern);
|
|
71
|
+
debug('bind-queue exchange=%s pattern=%s', this.exchangeName, pattern);
|
|
72
|
+
yield queue.bindExchange(this, pattern, args);
|
|
92
73
|
return this;
|
|
93
74
|
});
|
|
94
75
|
}
|
|
@@ -99,15 +80,13 @@ export class ExchangeImplementation {
|
|
|
99
80
|
exchange.name(),
|
|
100
81
|
]);
|
|
101
82
|
debug('bind-exchange dest=%s source=%s pattern=%s', thisName, exchangeName, pattern);
|
|
102
|
-
const doesBindingMatch = (binding) => binding.
|
|
103
|
-
binding.pattern === pattern &&
|
|
83
|
+
const doesBindingMatch = (binding) => binding.pattern === pattern &&
|
|
104
84
|
binding.exchange === exchange &&
|
|
105
85
|
stableJsonStringify(binding.args) === stableJsonStringify(args);
|
|
106
86
|
if (this.bindings.every(binding => !doesBindingMatch(binding))) {
|
|
107
87
|
this.bindings.push({
|
|
108
88
|
args,
|
|
109
89
|
pattern,
|
|
110
|
-
type: BindingType.exchange,
|
|
111
90
|
exchange,
|
|
112
91
|
});
|
|
113
92
|
}
|
|
@@ -120,9 +99,7 @@ export class ExchangeImplementation {
|
|
|
120
99
|
rebind() {
|
|
121
100
|
return __awaiter(this, void 0, void 0, function* () {
|
|
122
101
|
debug('rebind name=%s bindings=%d', this.exchangeName, this.bindings.length);
|
|
123
|
-
const promises = yield Promise.allSettled(this.bindings.map(binding => (binding.
|
|
124
|
-
? this.bindQueue(binding.queue, binding.pattern, binding.args)
|
|
125
|
-
: this.bindExchange(binding.exchange, binding.pattern, binding.args))));
|
|
102
|
+
const promises = yield Promise.allSettled(this.bindings.map(binding => this.bindExchange(binding.exchange, binding.pattern, binding.args)));
|
|
126
103
|
const failedPromise = promises.find(p => p.status === 'rejected');
|
|
127
104
|
if (failedPromise) {
|
|
128
105
|
debug('rebind-failed error=%s', errToMessage(failedPromise.reason));
|
|
@@ -134,14 +111,14 @@ export class ExchangeImplementation {
|
|
|
134
111
|
createConsumer(options_1) {
|
|
135
112
|
return __awaiter(this, arguments, void 0, function* (options, queueOptions = {}) {
|
|
136
113
|
const queue = yield this.channel.createQueue('', Object.assign(Object.assign({}, queueOptions), { durable: false, exclusive: true }));
|
|
137
|
-
yield
|
|
114
|
+
yield queue.bindExchange(this, options.pattern, options.bindingArgs);
|
|
138
115
|
return queue.createConsumer(options);
|
|
139
116
|
});
|
|
140
117
|
}
|
|
141
118
|
createBatchConsumer(options_1) {
|
|
142
119
|
return __awaiter(this, arguments, void 0, function* (options, queueOptions = {}) {
|
|
143
120
|
const queue = yield this.channel.createQueue('', Object.assign(Object.assign({}, queueOptions), { durable: false, exclusive: true }));
|
|
144
|
-
yield
|
|
121
|
+
yield queue.bindExchange(this, options.pattern, options.bindingArgs);
|
|
145
122
|
return queue.createBatchConsumer(options);
|
|
146
123
|
});
|
|
147
124
|
}
|
|
@@ -21,7 +21,9 @@ export interface Exchange {
|
|
|
21
21
|
name(): Promise<string>;
|
|
22
22
|
/**
|
|
23
23
|
* Bind a queue to this exchange.
|
|
24
|
-
* Asserts the exchange first if
|
|
24
|
+
* Asserts the queue and the exchange first if they have not been asserted yet.
|
|
25
|
+
* Equivalent to `queue.bindExchange(exchange, pattern, args)`.
|
|
26
|
+
* The binding is restored when the queue is asserted again after a reconnect.
|
|
25
27
|
* @param queue - Queue to bind to this exchange.
|
|
26
28
|
* @param pattern - Routing key pattern under which to bind.
|
|
27
29
|
* @param args - Optional AMQP headers or x-arguments for the binding.
|
|
@@ -37,25 +39,24 @@ export interface Exchange {
|
|
|
37
39
|
bindExchange(exchange: Exchange, pattern: string, args?: BindingArgs): Promise<Exchange>;
|
|
38
40
|
/**
|
|
39
41
|
* Creates a consumer for the current exchange.
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
42
|
+
* The consumer reads from a temporary exclusive queue bound to the exchange under `options.pattern`
|
|
43
|
+
* and keeps receiving messages after a reconnect.
|
|
44
|
+
* By default, creates a new dedicated channel for the consumer.
|
|
45
|
+
* Pass a channel in `options` to use a specific one instead.
|
|
44
46
|
*/
|
|
45
47
|
createConsumer<T>(options: ExchangeConsumerOptions<T>, queueOptions?: ExchangeConsumerQueueOptions): Promise<Consumer<T>>;
|
|
46
48
|
/**
|
|
47
49
|
* Creates a batch consumer for the current exchange.
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
50
|
+
* The consumer reads from a temporary exclusive queue bound to the exchange under `options.pattern`
|
|
51
|
+
* and keeps receiving messages after a reconnect.
|
|
52
|
+
* By default, creates a new dedicated channel for the consumer.
|
|
53
|
+
* Pass a channel in `options` to use a specific one instead.
|
|
52
54
|
*/
|
|
53
55
|
createBatchConsumer<T>(options: ExchangeBatchConsumerOptions<T>, queueOptions?: ExchangeConsumerQueueOptions): Promise<BatchConsumer<T>>;
|
|
54
56
|
/**
|
|
55
57
|
* Creates a producer for the current exchange.
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* Consider using `connection.createProducerForExchange` instead.
|
|
58
|
+
* By default, creates a new dedicated channel for the producer.
|
|
59
|
+
* Pass a channel in `options` to use a specific one instead.
|
|
59
60
|
*
|
|
60
61
|
* @param options - Optional producer options (serialization, routing key, hooks, …).
|
|
61
62
|
* Set `options.isConfirmed` to `true` to open the dedicated channel in confirm mode.
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as amqp from 'amqplib';
|
|
2
2
|
import { AssertionMode } from '../types';
|
|
3
3
|
import { ConsumerOptions, BatchConsumerOptions } from '../consumer';
|
|
4
|
-
import { Queue } from '../queue';
|
|
5
4
|
import { Exchange } from './exchange';
|
|
6
5
|
/**
|
|
7
6
|
* The type of exchange to create. Accepted values: `'direct'`, `'fanout'`, `'topic'`, `'headers'`, `'match'`.
|
|
@@ -31,21 +30,13 @@ export type ExchangeConsumerOptions<T> = ExchangeConsumerBindingOptions & Consum
|
|
|
31
30
|
*/
|
|
32
31
|
export type ExchangeBatchConsumerOptions<T> = ExchangeConsumerBindingOptions & BatchConsumerOptions<T>;
|
|
33
32
|
export type BindingArgs = Record<string, string | number | boolean>;
|
|
34
|
-
export declare enum BindingType {
|
|
35
|
-
queue = "queue",
|
|
36
|
-
exchange = "exchange"
|
|
37
|
-
}
|
|
38
33
|
type Pattern = string;
|
|
39
|
-
|
|
34
|
+
/** A binding of another exchange to this exchange. */
|
|
35
|
+
export type ExchangeBinding = {
|
|
36
|
+
exchange: Exchange;
|
|
40
37
|
pattern: Pattern;
|
|
41
38
|
args?: BindingArgs;
|
|
42
|
-
}
|
|
43
|
-
type: BindingType.queue;
|
|
44
|
-
queue: Queue;
|
|
45
|
-
} | {
|
|
46
|
-
type: BindingType.exchange;
|
|
47
|
-
exchange: Exchange;
|
|
48
|
-
});
|
|
39
|
+
};
|
|
49
40
|
export type ExchangeOptions = amqp.Options.AssertExchange & {
|
|
50
41
|
/**
|
|
51
42
|
* Controls how the exchange is verified against the broker when `assert()` is called.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
+
import type { Mock } from 'vitest';
|
|
2
3
|
import type * as amqp from 'amqplib';
|
|
3
4
|
import { BatchConsumer } from '../../index';
|
|
4
5
|
import { TestQueue } from './test-queue';
|
|
@@ -32,8 +33,8 @@ import { TestChannel } from './test-channel';
|
|
|
32
33
|
*/
|
|
33
34
|
export declare class TestBatchConsumer<T> extends EventEmitter implements BatchConsumer<T> {
|
|
34
35
|
constructor();
|
|
35
|
-
close:
|
|
36
|
-
listen:
|
|
36
|
+
close: Mock;
|
|
37
|
+
listen: Mock;
|
|
37
38
|
queue: TestQueue;
|
|
38
39
|
channel: TestChannel;
|
|
39
40
|
/**
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
+
import type { Mock } from 'vitest';
|
|
2
3
|
import { Channel, Connection } from '../../index';
|
|
4
|
+
type NativeChannelMock = Record<'cancel' | 'prefetch' | 'consume' | 'ack' | 'nack' | 'assertQueue' | 'checkQueue' | 'assertExchange' | 'checkExchange' | 'bindQueue' | 'bindExchange', Mock>;
|
|
3
5
|
/**
|
|
4
6
|
* Mock implementation of Channel using vitest mocks.
|
|
5
7
|
*
|
|
@@ -25,21 +27,21 @@ import { Channel, Connection } from '../../index';
|
|
|
25
27
|
export declare class TestChannel extends EventEmitter implements Channel {
|
|
26
28
|
readonly connection: Connection;
|
|
27
29
|
constructor(connection?: Connection);
|
|
28
|
-
connect:
|
|
29
|
-
close:
|
|
30
|
-
createExchange:
|
|
31
|
-
createQueue:
|
|
32
|
-
createProducerForQueue:
|
|
33
|
-
createProducerForExchange:
|
|
34
|
-
createConsumerForQueue:
|
|
35
|
-
createConsumerForExchange:
|
|
36
|
-
createBatchConsumerForQueue:
|
|
37
|
-
createBatchConsumerForExchange:
|
|
38
|
-
native:
|
|
30
|
+
connect: Mock;
|
|
31
|
+
close: Mock;
|
|
32
|
+
createExchange: Mock;
|
|
33
|
+
createQueue: Mock;
|
|
34
|
+
createProducerForQueue: Mock;
|
|
35
|
+
createProducerForExchange: Mock;
|
|
36
|
+
createConsumerForQueue: Mock;
|
|
37
|
+
createConsumerForExchange: Mock;
|
|
38
|
+
createBatchConsumerForQueue: Mock;
|
|
39
|
+
createBatchConsumerForExchange: Mock;
|
|
40
|
+
native: Mock;
|
|
39
41
|
private _drainPending;
|
|
40
42
|
private _drainResolvers;
|
|
41
|
-
publish:
|
|
42
|
-
checkQueue:
|
|
43
|
+
publish: Mock;
|
|
44
|
+
checkQueue: Mock;
|
|
43
45
|
/**
|
|
44
46
|
* Simulates a channel close by emitting the `close` event.
|
|
45
47
|
*/
|
|
@@ -55,17 +57,6 @@ export declare class TestChannel extends EventEmitter implements Channel {
|
|
|
55
57
|
consumeResponse: {
|
|
56
58
|
consumerTag: `${string}-${string}-${string}-${string}-${string}`;
|
|
57
59
|
};
|
|
58
|
-
nativeChannel:
|
|
59
|
-
cancel: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
60
|
-
prefetch: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
61
|
-
consume: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
62
|
-
ack: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
63
|
-
nack: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
64
|
-
assertQueue: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
65
|
-
checkQueue: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
66
|
-
assertExchange: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
67
|
-
checkExchange: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
68
|
-
bindQueue: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
69
|
-
bindExchange: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
70
|
-
};
|
|
60
|
+
nativeChannel: NativeChannelMock;
|
|
71
61
|
}
|
|
62
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
+
import type { Mock } from 'vitest';
|
|
2
3
|
import { Connection } from '../../index';
|
|
3
4
|
/**
|
|
4
5
|
* Mock implementation of Connection using vitest mocks.
|
|
@@ -20,17 +21,17 @@ import { Connection } from '../../index';
|
|
|
20
21
|
* ```
|
|
21
22
|
*/
|
|
22
23
|
export declare class TestConnection extends EventEmitter implements Connection {
|
|
23
|
-
close:
|
|
24
|
-
connect:
|
|
25
|
-
createChannel:
|
|
26
|
-
createConsumerForExchange:
|
|
27
|
-
createConsumerForQueue:
|
|
28
|
-
createBatchConsumerForQueue:
|
|
29
|
-
createBatchConsumerForExchange:
|
|
30
|
-
createProducerForExchange:
|
|
31
|
-
createProducerForQueue:
|
|
32
|
-
native:
|
|
33
|
-
state:
|
|
24
|
+
close: Mock;
|
|
25
|
+
connect: Mock;
|
|
26
|
+
createChannel: Mock;
|
|
27
|
+
createConsumerForExchange: Mock;
|
|
28
|
+
createConsumerForQueue: Mock;
|
|
29
|
+
createBatchConsumerForQueue: Mock;
|
|
30
|
+
createBatchConsumerForExchange: Mock;
|
|
31
|
+
createProducerForExchange: Mock;
|
|
32
|
+
createProducerForQueue: Mock;
|
|
33
|
+
native: Mock;
|
|
34
|
+
state: Mock;
|
|
34
35
|
/**
|
|
35
36
|
* Simulates a server-side disconnect by emitting the `reconnecting` event.
|
|
36
37
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
+
import type { Mock } from 'vitest';
|
|
2
3
|
import type * as amqp from 'amqplib';
|
|
3
4
|
import { Consumer } from '../../index';
|
|
4
5
|
import { TestQueue } from './test-queue';
|
|
@@ -32,9 +33,9 @@ import { TestChannel } from './test-channel';
|
|
|
32
33
|
*/
|
|
33
34
|
export declare class TestConsumer<T> extends EventEmitter implements Consumer<T> {
|
|
34
35
|
constructor();
|
|
35
|
-
close:
|
|
36
|
-
listen:
|
|
37
|
-
setPrefetch:
|
|
36
|
+
close: Mock;
|
|
37
|
+
listen: Mock;
|
|
38
|
+
setPrefetch: Mock;
|
|
38
39
|
queue: TestQueue;
|
|
39
40
|
channel: TestChannel;
|
|
40
41
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Mock } from 'vitest';
|
|
1
2
|
import { Exchange } from '../../index';
|
|
2
3
|
/**
|
|
3
4
|
* Mock implementation of Exchange using vitest mocks.
|
|
@@ -16,11 +17,11 @@ import { Exchange } from '../../index';
|
|
|
16
17
|
* ```
|
|
17
18
|
*/
|
|
18
19
|
export declare class TestExchange implements Exchange {
|
|
19
|
-
assert:
|
|
20
|
-
name:
|
|
21
|
-
bindQueue:
|
|
22
|
-
bindExchange:
|
|
23
|
-
createConsumer:
|
|
24
|
-
createBatchConsumer:
|
|
25
|
-
createProducer:
|
|
20
|
+
assert: Mock;
|
|
21
|
+
name: Mock;
|
|
22
|
+
bindQueue: Mock;
|
|
23
|
+
bindExchange: Mock;
|
|
24
|
+
createConsumer: Mock;
|
|
25
|
+
createBatchConsumer: Mock;
|
|
26
|
+
createProducer: Mock;
|
|
26
27
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
+
import type { Mock } from 'vitest';
|
|
2
3
|
import { Producer } from '../../index';
|
|
3
4
|
import { TestChannel } from './test-channel';
|
|
4
5
|
/**
|
|
@@ -24,8 +25,8 @@ import { TestChannel } from './test-channel';
|
|
|
24
25
|
*/
|
|
25
26
|
export declare class TestProducer<T> extends EventEmitter implements Producer<T> {
|
|
26
27
|
constructor();
|
|
27
|
-
close:
|
|
28
|
-
publish:
|
|
28
|
+
close: Mock;
|
|
29
|
+
publish: Mock;
|
|
29
30
|
channel: TestChannel;
|
|
30
31
|
/**
|
|
31
32
|
* Returns the first argument (the message payload) from every `publish` call recorded so far.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Mock } from 'vitest';
|
|
1
2
|
import { Queue } from '../../index';
|
|
2
3
|
/**
|
|
3
4
|
* Mock implementation of Queue using vitest mocks.
|
|
@@ -16,10 +17,10 @@ import { Queue } from '../../index';
|
|
|
16
17
|
* ```
|
|
17
18
|
*/
|
|
18
19
|
export declare class TestQueue implements Queue {
|
|
19
|
-
assert:
|
|
20
|
-
name:
|
|
21
|
-
bindExchange:
|
|
22
|
-
createConsumer:
|
|
23
|
-
createBatchConsumer:
|
|
24
|
-
createProducer:
|
|
20
|
+
assert: Mock;
|
|
21
|
+
name: Mock;
|
|
22
|
+
bindExchange: Mock;
|
|
23
|
+
createConsumer: Mock;
|
|
24
|
+
createBatchConsumer: Mock;
|
|
25
|
+
createProducer: Mock;
|
|
25
26
|
}
|
package/dist/esm/predefined.d.ts
CHANGED
|
@@ -1,49 +1,54 @@
|
|
|
1
1
|
import { Exchange } from './exchange';
|
|
2
2
|
import { Channel } from './channel';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Returns the direct exchange that RabbitMQ creates by default in every virtual host.
|
|
5
5
|
*
|
|
6
|
-
* The
|
|
6
|
+
* The exchange has name *amq.direct*, is durable, and has type *direct*.
|
|
7
|
+
* The exchange always exists on the broker, so it is never declared.
|
|
7
8
|
*
|
|
8
|
-
* @param channel The channel
|
|
9
|
-
* @returns The exchange
|
|
9
|
+
* @param channel The channel the exchange belongs to
|
|
10
|
+
* @returns The predefined exchange
|
|
10
11
|
*/
|
|
11
12
|
export declare const directExchange: (channel: Channel) => Exchange;
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
|
+
* Returns the fanout exchange that RabbitMQ creates by default in every virtual host.
|
|
14
15
|
*
|
|
15
|
-
* The
|
|
16
|
+
* The exchange has name *amq.fanout*, is durable, and has type *fanout*.
|
|
17
|
+
* The exchange always exists on the broker, so it is never declared.
|
|
16
18
|
*
|
|
17
|
-
* @param channel The channel
|
|
18
|
-
* @returns The exchange
|
|
19
|
+
* @param channel The channel the exchange belongs to
|
|
20
|
+
* @returns The predefined exchange
|
|
19
21
|
*/
|
|
20
22
|
export declare const fanoutExchange: (channel: Channel) => Exchange;
|
|
21
23
|
/**
|
|
22
|
-
*
|
|
24
|
+
* Returns the headers exchange that RabbitMQ creates by default in every virtual host.
|
|
23
25
|
*
|
|
24
|
-
* The
|
|
26
|
+
* The exchange has name *amq.headers*, is durable, and has type *headers*.
|
|
27
|
+
* The exchange always exists on the broker, so it is never declared.
|
|
25
28
|
*
|
|
26
|
-
* @param channel The channel
|
|
27
|
-
* @returns The exchange
|
|
29
|
+
* @param channel The channel the exchange belongs to
|
|
30
|
+
* @returns The predefined exchange
|
|
28
31
|
*/
|
|
29
32
|
export declare const headersExchange: (channel: Channel) => Exchange;
|
|
30
33
|
/**
|
|
31
|
-
*
|
|
32
|
-
* Behaves the same as
|
|
34
|
+
* Returns the match exchange that RabbitMQ creates by default in every virtual host.
|
|
35
|
+
* Behaves the same as {@link headersExchange}, but has a different name.
|
|
33
36
|
*
|
|
34
|
-
* The
|
|
37
|
+
* The exchange has name *amq.match*, is durable, and has type *headers*.
|
|
38
|
+
* The exchange always exists on the broker, so it is never declared.
|
|
35
39
|
*
|
|
36
|
-
* @param channel The channel
|
|
37
|
-
* @returns The exchange
|
|
40
|
+
* @param channel The channel the exchange belongs to
|
|
41
|
+
* @returns The predefined exchange
|
|
38
42
|
*/
|
|
39
43
|
export declare const matchExchange: (channel: Channel) => Exchange;
|
|
40
44
|
/**
|
|
41
|
-
*
|
|
45
|
+
* Returns the topic exchange that RabbitMQ creates by default in every virtual host.
|
|
42
46
|
*
|
|
43
|
-
* The
|
|
47
|
+
* The exchange has name *amq.topic*, is durable, and has type *topic*.
|
|
48
|
+
* The exchange always exists on the broker, so it is never declared.
|
|
44
49
|
*
|
|
45
|
-
* @param channel The channel
|
|
46
|
-
* @returns The exchange
|
|
50
|
+
* @param channel The channel the exchange belongs to
|
|
51
|
+
* @returns The predefined exchange
|
|
47
52
|
*/
|
|
48
53
|
export declare const topicExchange: (channel: Channel) => Exchange;
|
|
49
54
|
/**
|