@autofleet/rabbit 4.0.2 → 4.1.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/dist/index.d.ts +63 -72
- package/dist/index.js +378 -393
- package/dist/index.js.map +1 -1
- package/dist/lib/consts.d.ts +2 -2
- package/dist/lib/consts.js.map +1 -1
- package/dist/lib/redis.d.ts +2 -1
- package/dist/lib/redis.js +2 -8
- package/dist/lib/redis.js.map +1 -1
- package/dist/lib/types.d.ts +11 -6
- package/dist/lib/types.js.map +1 -1
- package/dist/lib/utils.d.ts +12 -8
- package/dist/lib/utils.js +15 -13
- package/dist/lib/utils.js.map +1 -1
- package/package.json +3 -5
- package/src/index.ts +475 -538
- package/src/lib/consts.ts +8 -4
- package/src/lib/redis.ts +2 -7
- package/src/lib/types.ts +13 -8
- package/src/lib/utils.ts +27 -14
- package/src/redis-lock.d.ts +5 -3
package/src/lib/consts.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import type { BackoffOptions } from 'exponential-backoff';
|
|
2
|
+
import type { ConsumeOptions } from './types';
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_DEAD_TTL_TWO_DAYS = 60_000 * 60 * 12;
|
|
2
5
|
export const DEFAULT_LOCK_TIMEOUT = 1000 * 5;
|
|
3
6
|
export const RETRY_HEADER = 'x-retry-count';
|
|
4
7
|
export const TRACING_HEADER = 'x-trace-id';
|
|
@@ -14,15 +17,16 @@ export const DEFAULT_OPTIONS = {
|
|
|
14
17
|
useConsumeWithLock: DEFAULT_USE_CONSUME_WITH_LOCK,
|
|
15
18
|
auditContext: null,
|
|
16
19
|
enableRabbitTrace: false,
|
|
17
|
-
};
|
|
20
|
+
} satisfies ConsumeOptions;
|
|
21
|
+
|
|
18
22
|
export const ASSERT_VHOST_EXPONENTIAL_BACKOFF_DEV_ENV_CONFIG = {
|
|
19
23
|
startingDelay: 500,
|
|
20
24
|
timeMultiple: 4,
|
|
21
25
|
numOfAttempts: 5,
|
|
22
|
-
};
|
|
26
|
+
} satisfies BackoffOptions;
|
|
23
27
|
|
|
24
28
|
export const ASSERT_VHOST_EXPONENTIAL_BACKOFF_PROD_CONFIG = {
|
|
25
29
|
startingDelay: 1,
|
|
26
30
|
timeMultiple: 1,
|
|
27
31
|
numOfAttempts: 5,
|
|
28
|
-
};
|
|
32
|
+
} satisfies BackoffOptions;
|
package/src/lib/redis.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const redis = require('redis');
|
|
4
|
-
|
|
5
|
-
bluebird.promisifyAll(redis.RedisClient.prototype);
|
|
6
|
-
bluebird.promisifyAll(redis.Multi.prototype);
|
|
1
|
+
import { createClient } from 'redis';
|
|
7
2
|
|
|
8
3
|
export type RedisConfig = {
|
|
9
4
|
host: string;
|
|
@@ -11,6 +6,6 @@ export type RedisConfig = {
|
|
|
11
6
|
prefix?: string;
|
|
12
7
|
}
|
|
13
8
|
|
|
14
|
-
const getRedisInstance = (config: RedisConfig):
|
|
9
|
+
const getRedisInstance = (config: RedisConfig): ReturnType<typeof createClient> => createClient({ socket: config });
|
|
15
10
|
|
|
16
11
|
export default getRedisInstance;
|
package/src/lib/types.ts
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
import { AmqpConnectionManager } from 'amqp-connection-manager';
|
|
2
|
-
import { ConsumeMessage, Options, Replies } from 'amqplib';
|
|
1
|
+
import type { AmqpConnectionManager } from 'amqp-connection-manager';
|
|
2
|
+
import type { ConsumeMessage, Options, Replies } from 'amqplib';
|
|
3
3
|
|
|
4
4
|
export interface ExchangesCache {
|
|
5
|
-
[key: string]:
|
|
5
|
+
[key: string]: Replies.AssertExchange | undefined;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export interface QueuesCache {
|
|
9
|
-
[key: string]:
|
|
9
|
+
[key: string]: Replies.AssertQueue | undefined;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface QueueSetupPromisesDictionary {
|
|
13
|
-
[key: string]: Promise<Replies.AssertQueue> | undefined
|
|
13
|
+
[key: string]: Promise<Replies.AssertQueue> | undefined;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export interface AssertExchangePromisesDictionary {
|
|
17
|
-
[key: string]: Promise<Replies.AssertExchange> | undefined
|
|
17
|
+
[key: string]: Promise<Replies.AssertExchange> | undefined;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export type CustomMessageHeaders = {
|
|
21
21
|
redisTimestampValidationKey?: string;
|
|
22
22
|
}
|
|
23
|
-
export type RedisLockType = (args0?: string, arg1?: number) => Promise<any>
|
|
24
23
|
export type ConsumeMessageOrNull = ConsumeMessage | null;
|
|
25
24
|
|
|
26
25
|
export interface ConsumeOptions {
|
|
@@ -36,7 +35,13 @@ export interface ConsumeOptions {
|
|
|
36
35
|
isQuorumQueue?: boolean;
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
export
|
|
38
|
+
export interface NackOptions {
|
|
39
|
+
skipRetry?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type Message = Omit<ConsumeMessage, 'content'> & { content: any; };
|
|
43
|
+
|
|
44
|
+
export type CallbackFunction = (msg: Message, ack: () => Promise<void>, nack: (ignored: ConsumeMessageOrNull, nackOptions?: NackOptions) => Promise<void>) => Promise<void>;
|
|
40
45
|
|
|
41
46
|
export type newChannelOpts = {
|
|
42
47
|
name?: string;
|
package/src/lib/utils.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { ConfirmChannel, Replies } from 'amqplib';
|
|
2
|
+
import type { ChannelWrapper } from 'amqp-connection-manager';
|
|
3
|
+
import type { BackoffOptions } from 'exponential-backoff';
|
|
3
4
|
import { ASSERT_VHOST_EXPONENTIAL_BACKOFF_PROD_CONFIG, ASSERT_VHOST_EXPONENTIAL_BACKOFF_DEV_ENV_CONFIG } from './consts';
|
|
4
5
|
|
|
5
6
|
const { PROJECT_ID } = process.env;
|
|
@@ -9,21 +10,33 @@ export const assertExchangeFanout = async (
|
|
|
9
10
|
exchangeName: string,
|
|
10
11
|
): Promise<Replies.AssertExchange> => c.assertExchange(exchangeName, 'fanout');
|
|
11
12
|
|
|
12
|
-
export const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
export const rand = (): number => Math.floor(Math.random() * 100_000);
|
|
14
|
+
|
|
15
|
+
interface PromiseWithResolvers<T> {
|
|
16
|
+
promise: Promise<T>;
|
|
17
|
+
resolve: (value: T | PromiseLike<T>) => void;
|
|
18
|
+
reject: (reason?: any) => void;
|
|
19
|
+
}
|
|
20
|
+
interface PromiseCls extends PromiseConstructor {
|
|
21
|
+
withResolvers<T>(): PromiseWithResolvers<T>;
|
|
22
|
+
}
|
|
23
|
+
/** This is polyfill for `Promise.withResolvers` which exists only on Node v22 and onwards */
|
|
24
|
+
export const createDeferredPromise = <T = void>(): PromiseWithResolvers<T> => {
|
|
25
|
+
if ((Promise as PromiseCls).withResolvers) {
|
|
26
|
+
return (Promise as PromiseCls).withResolvers<T>();
|
|
27
|
+
}
|
|
28
|
+
let resolve!: PromiseWithResolvers<T>['resolve'];
|
|
29
|
+
let reject!: PromiseWithResolvers<T>['reject'];
|
|
30
|
+
const promise = new Promise<T>((res, rej) => {
|
|
31
|
+
resolve = res;
|
|
32
|
+
reject = rej;
|
|
20
33
|
});
|
|
21
|
-
}
|
|
22
|
-
|
|
34
|
+
return { promise, resolve, reject };
|
|
35
|
+
};
|
|
23
36
|
|
|
24
|
-
const isDevEnv = () => ['af-experiment-manager', 'dev1-experiment-manager'].includes(PROJECT_ID || '');
|
|
37
|
+
const isDevEnv = (): boolean => ['af-experiment-manager', 'dev1-experiment-manager'].includes(PROJECT_ID || '');
|
|
25
38
|
|
|
26
|
-
export const getAssertVhostExponentialBackoffConfig = () => (
|
|
39
|
+
export const getAssertVhostExponentialBackoffConfig = (): BackoffOptions => (
|
|
27
40
|
isDevEnv()
|
|
28
41
|
? ASSERT_VHOST_EXPONENTIAL_BACKOFF_DEV_ENV_CONFIG
|
|
29
42
|
: ASSERT_VHOST_EXPONENTIAL_BACKOFF_PROD_CONFIG);
|
package/src/redis-lock.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
declare module 'redis-lock' {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import type { createClient } from 'redis';
|
|
3
|
+
|
|
4
|
+
declare function redisLock(client: ReturnType<typeof createClient>, retryDelay?: number): (lockName: string, timeout?: number) => Promise<() => Promise<void>>;
|
|
5
|
+
export = redisLock;
|
|
6
|
+
}
|