index.d.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { Cluster, Redis } from 'ioredis';
  2. import { AbortController } from '../classes/abort-controller';
  3. import { ChildMessage, ContextManager, ParentOptions, RedisClient, Span, Tracer } from '../interfaces';
  4. import { EventEmitter } from 'events';
  5. import { SpanKind } from '../enums';
  6. import { DatabaseType } from '../types';
  7. export declare const errorObject: {
  8. [index: string]: any;
  9. };
  10. export declare function tryCatch(fn: (...args: any) => any, ctx: any, args: any[]): any;
  11. /**
  12. * Checks the size of string for ascii/non-ascii characters
  13. * @see https://stackoverflow.com/a/23318053/1347170
  14. * @param str -
  15. */
  16. export declare function lengthInUtf8Bytes(str: string): number;
  17. export declare function isEmpty(obj: object): boolean;
  18. export declare function array2obj(arr: string[]): Record<string, string>;
  19. export declare function objectToFlatArray(obj: Record<string, any>): string[];
  20. export declare function delay(ms: number, abortController?: AbortController): Promise<void>;
  21. export declare function increaseMaxListeners(emitter: EventEmitter, count: number): void;
  22. type Invert<T extends Record<PropertyKey, PropertyKey>> = {
  23. [V in T[keyof T]]: {
  24. [K in keyof T]: T[K] extends V ? K : never;
  25. }[keyof T];
  26. };
  27. export declare function invertObject<T extends Record<PropertyKey, PropertyKey>>(obj: T): Invert<T>;
  28. export declare const optsDecodeMap: {
  29. readonly de: "deduplication";
  30. readonly fpof: "failParentOnFailure";
  31. readonly cpof: "continueParentOnFailure";
  32. readonly idof: "ignoreDependencyOnFailure";
  33. readonly kl: "keepLogs";
  34. readonly rdof: "removeDependencyOnFailure";
  35. };
  36. export declare const optsEncodeMap: {
  37. readonly debounce: "de";
  38. readonly keepLogs: "kl";
  39. readonly deduplication: "de";
  40. readonly failParentOnFailure: "fpof";
  41. readonly continueParentOnFailure: "cpof";
  42. readonly ignoreDependencyOnFailure: "idof";
  43. readonly removeDependencyOnFailure: "rdof";
  44. };
  45. export declare function isRedisInstance(obj: any): obj is Redis | Cluster;
  46. export declare function isRedisCluster(obj: unknown): obj is Cluster;
  47. export declare function decreaseMaxListeners(emitter: EventEmitter, count: number): void;
  48. export declare function removeAllQueueData(client: RedisClient, queueName: string, prefix?: string): Promise<void | boolean>;
  49. export declare function getParentKey(opts: ParentOptions): string | undefined;
  50. export declare const clientCommandMessageReg: RegExp;
  51. export declare const DELAY_TIME_5 = 5000;
  52. export declare const DELAY_TIME_1 = 100;
  53. export declare function isNotConnectionError(error: Error): boolean;
  54. interface procSendLike {
  55. send?(message: any, callback?: (error: Error | null) => void): boolean;
  56. postMessage?(message: any): void;
  57. }
  58. export declare const asyncSend: <T extends procSendLike>(proc: T, msg: any) => Promise<void>;
  59. export declare const childSend: (proc: NodeJS.Process, msg: ChildMessage) => Promise<void>;
  60. export declare const isRedisVersionLowerThan: (currentVersion: string, minimumVersion: string, currentDatabaseType: DatabaseType, desiredDatabaseType?: DatabaseType) => boolean;
  61. export declare const parseObjectValues: (obj: {
  62. [key: string]: string;
  63. }) => Record<string, any>;
  64. export declare const errorToJSON: (value: any) => Record<string, any>;
  65. export declare const toString: (value: any) => string;
  66. export declare const QUEUE_EVENT_SUFFIX = ":qe";
  67. export declare function removeUndefinedFields<T extends Record<string, any>>(obj: Record<string, any>): T;
  68. /**
  69. * Wraps the code with telemetry and provides a span for configuration.
  70. *
  71. * @param telemetry - telemetry configuration. If undefined, the callback will be executed without telemetry.
  72. * @param spanKind - kind of the span: Producer, Consumer, Internal
  73. * @param queueName - queue name
  74. * @param operation - operation name (such as add, process, etc)
  75. * @param destination - destination name (normally the queue name)
  76. * @param callback - code to wrap with telemetry
  77. * @param srcPropagationMetadata -
  78. * @returns
  79. */
  80. export declare function trace<T>(telemetry: {
  81. tracer: Tracer;
  82. contextManager: ContextManager;
  83. } | undefined, spanKind: SpanKind, queueName: string, operation: string, destination: string, callback: (span?: Span, dstPropagationMetadata?: string) => Promise<T> | T, srcPropagationMetadata?: string): Promise<T>;
  84. export {};