Review funkt

This commit is contained in:
2026-08-09 21:56:00 +00:00
parent f522ae9953
commit fe9dfa4519
11366 changed files with 2335077 additions and 97 deletions

26
node_modules/bullmq/dist/esm/utils/create-backend.d.ts generated vendored Normal file
View File

@@ -0,0 +1,26 @@
import { BackendFactory, IQueueBackend } from '../interfaces';
import { RedisQueueBackend } from '../classes/redis-queue-backend';
/**
* The default ({@link RedisConnection}-based) implementation of
* {@link BackendFactory}. The returned backend owns its connection(s); the
* high-level classes (Queue, Worker, FlowProducer, …) depend only on
* {@link IQueueBackend} and never touch a Redis client directly.
*
* Other datastores can provide their own {@link BackendFactory} and inject it
* into the queue classes.
*/
export declare const createRedisBackend: BackendFactory<RedisQueueBackend>;
/**
* Overrides the process-wide default {@link BackendFactory}. Useful to point
* every Queue/Worker/FlowProducer at a different datastore (e.g. the PostgreSQL
* backend) without threading a factory through every constructor — notably so
* the existing test suite can run unchanged against another backend.
*
* Pass no argument (or `undefined`) to reset back to the Redis backend.
*/
export declare function setDefaultBackendFactory(factory?: BackendFactory<IQueueBackend>): void;
/**
* Returns the current process-wide default {@link BackendFactory}, typed as the
* caller's concrete backend `B`.
*/
export declare function getDefaultBackendFactory<B extends IQueueBackend = IQueueBackend>(): BackendFactory<B>;

75
node_modules/bullmq/dist/esm/utils/create-backend.js generated vendored Normal file
View File

@@ -0,0 +1,75 @@
import { RedisQueueBackend } from '../classes/redis-queue-backend';
import { RedisConnection } from '../classes/redis-connection';
import { QueueKeys } from '../classes/queue-keys';
import { createIORedisClient, isIRedisClient } from '../classes/ioredis-client';
import { isRedisInstance } from './index';
/**
* Builds the dedicated, blocking connection that a worker needs so its blocking
* fetch (`BZPOPMIN`) does not stall regular operations. Reuses / duplicates the
* provided connection options with its own name.
*/
const createBlockingConnection = (name, opts) => {
var _a;
const base64Name = Buffer.from(name).toString('base64');
const workerName = opts.name;
const connectionName = `${(_a = opts.prefix) !== null && _a !== void 0 ? _a : 'bull'}:${base64Name}${workerName ? `:w:${workerName}` : ''}`;
return new RedisConnection(isRedisInstance(opts.connection)
? (isIRedisClient(opts.connection)
? opts.connection
: createIORedisClient(opts.connection)).duplicate({ connectionName })
: Object.assign(Object.assign({}, opts.connection), { connectionName }), {
shared: false,
blocking: true,
skipVersionCheck: opts.skipVersionCheck,
});
};
/**
* The default ({@link RedisConnection}-based) implementation of
* {@link BackendFactory}. The returned backend owns its connection(s); the
* high-level classes (Queue, Worker, FlowProducer, …) depend only on
* {@link IQueueBackend} and never touch a Redis client directly.
*
* Other datastores can provide their own {@link BackendFactory} and inject it
* into the queue classes.
*/
export const createRedisBackend = (name, opts, { blocking = false, withBlockingConnection = false } = {}) => {
const connection = new RedisConnection(opts.connection, {
shared: isRedisInstance(opts.connection),
blocking,
skipVersionCheck: opts.skipVersionCheck,
skipWaitingForReady: opts.skipWaitingForReady,
});
const blockingConnection = withBlockingConnection
? createBlockingConnection(name, opts)
: undefined;
const queueKeys = new QueueKeys(opts.prefix);
const keys = queueKeys.getKeys(name);
const toKey = (type) => queueKeys.toKey(name, type);
return new RedisQueueBackend(connection, name, keys, toKey, opts, blockingConnection);
};
/**
* The process-wide default {@link BackendFactory} used by the high-level
* classes ({@link QueueBase}, {@link FlowProducer}) when the caller does not
* pass an explicit `backendFactory`. Initialised to the Redis backend so the
* default behaviour is unchanged.
*/
let defaultBackendFactory = createRedisBackend;
/**
* Overrides the process-wide default {@link BackendFactory}. Useful to point
* every Queue/Worker/FlowProducer at a different datastore (e.g. the PostgreSQL
* backend) without threading a factory through every constructor — notably so
* the existing test suite can run unchanged against another backend.
*
* Pass no argument (or `undefined`) to reset back to the Redis backend.
*/
export function setDefaultBackendFactory(factory) {
defaultBackendFactory =
factory !== null && factory !== void 0 ? factory : createRedisBackend;
}
/**
* Returns the current process-wide default {@link BackendFactory}, typed as the
* caller's concrete backend `B`.
*/
export function getDefaultBackendFactory() {
return defaultBackendFactory;
}

124
node_modules/bullmq/dist/esm/utils/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,124 @@
import { EventEmitter } from 'events';
import { AbortController } from '../classes/abort-controller';
export { randomUUID } from 'crypto';
import { ChildMessage, ContextManager, IRedisClient, ParentOptions, Span, Tracer } from '../interfaces';
import { SpanKind } from '../enums';
import { DatabaseType } from '../types';
type RedisLikeClient = {
connect(...args: any[]): any;
disconnect(...args: any[]): any;
duplicate(...args: any[]): any;
};
export declare const errorObject: {
[index: string]: any;
};
export declare function tryCatch(fn: (...args: any) => any, ctx: any, args: any[]): any;
/**
* Returns the size of a string in UTF-8 bytes (handles multi-byte characters correctly).
* @see https://stackoverflow.com/a/23318053/1347170
* @param str - The string to measure.
* @returns The byte length of the string when encoded as UTF-8.
*/
export declare function lengthInUtf8Bytes(str: string): number;
export declare function isEmpty(obj: object): boolean;
export declare function array2obj(arr: string[]): Record<string, string>;
export declare function objectToFlatArray(obj: Record<string, any>): string[];
export declare function delay(ms: number, abortController?: AbortController): Promise<void>;
/**
* Forwards 'error' events from a connection to its owning emitter, but only
* when a consumer is listening. Emitting 'error' on an EventEmitter with no
* listeners throws, which would turn a transient connection error (e.g. a
* failed init handshake before the consumer attached its listener) into an
* unhandled rejection.
*
* @param emitter - The owner emitter (Queue, Worker, FlowProducer, ...).
* @param connection - The connection whose 'error' events should be forwarded.
*/
export declare function forwardConnectionError(emitter: EventEmitter, connection: EventEmitter): void;
export declare function increaseMaxListeners(emitter: {
getMaxListeners(): number;
setMaxListeners(n: number): any;
}, count: number): void;
type Invert<T extends Record<PropertyKey, PropertyKey>> = {
[V in T[keyof T]]: {
[K in keyof T]: T[K] extends V ? K : never;
}[keyof T];
};
export declare function invertObject<T extends Record<PropertyKey, PropertyKey>>(obj: T): Invert<T>;
export declare const optsDecodeMap: {
readonly de: "deduplication";
readonly fpof: "failParentOnFailure";
readonly cpof: "continueParentOnFailure";
readonly idof: "ignoreDependencyOnFailure";
readonly kl: "keepLogs";
readonly rdof: "removeDependencyOnFailure";
};
export declare const optsEncodeMap: {
readonly deduplication: "de";
readonly keepLogs: "kl";
readonly failParentOnFailure: "fpof";
readonly continueParentOnFailure: "cpof";
readonly ignoreDependencyOnFailure: "idof";
readonly removeDependencyOnFailure: "rdof";
};
export declare function isRedisInstance(obj: any): obj is IRedisClient | RedisLikeClient;
export declare function isRedisCluster(obj: unknown): obj is IRedisClient & {
isCluster: true;
};
export declare function decreaseMaxListeners(emitter: {
getMaxListeners(): number;
setMaxListeners(n: number): any;
}, count: number): void;
type RemoveAllQueueDataPipeline = {
del(...keys: string[]): any;
exec(): Promise<any>;
};
type RemoveAllQueueDataClient = {
scanStream(options: {
match: string;
count?: number;
}): {
on(event: 'data', listener: (keys: string[]) => void): any;
on(event: 'end', listener: () => void): any;
on(event: 'error', listener: (error: Error) => void): any;
};
pipeline(): RemoveAllQueueDataPipeline;
quit(): Promise<any>;
isCluster?: boolean;
};
export declare function removeAllQueueData(client: RemoveAllQueueDataClient, queueName: string, prefix?: string): Promise<void | boolean>;
export declare function getParentKey(opts: ParentOptions): string | undefined;
export declare const clientCommandMessageReg: RegExp;
export declare const DELAY_TIME_5 = 5000;
export declare const DELAY_TIME_1 = 100;
export declare function isNotConnectionError(error: Error): boolean;
interface procSendLike {
send?(message: any, callback?: (error: Error | null) => void): boolean;
postMessage?(message: any): void;
}
export declare const asyncSend: <T extends procSendLike>(proc: T, msg: any) => Promise<void>;
export declare const childSend: (proc: NodeJS.Process, msg: ChildMessage) => Promise<void>;
export declare const isRedisVersionLowerThan: (currentVersion: string, minimumVersion: string, currentDatabaseType: DatabaseType, desiredDatabaseType?: DatabaseType) => boolean;
export declare const parseObjectValues: (obj: {
[key: string]: string;
}) => Record<string, any>;
export declare const errorToJSON: (value: any) => Record<string, any>;
export declare const toString: (value: any) => string;
export declare const QUEUE_EVENT_SUFFIX = ":qe";
export declare function removeUndefinedFields<T extends Record<string, any>>(obj: Record<string, any>): T;
/**
* Wraps the code with telemetry and provides a span for configuration.
*
* @param telemetry - telemetry configuration. If undefined, the callback will be executed without telemetry.
* @param spanKind - kind of the span: Producer, Consumer, Internal
* @param queueName - queue name
* @param operation - operation name (such as add, process, etc)
* @param destination - destination name (normally the queue name)
* @param callback - code to wrap with telemetry
* @param srcPropagationMetadata -
* @returns
*/
export declare function trace<T>(telemetry: {
tracer: Tracer;
contextManager: ContextManager;
} | undefined, spanKind: SpanKind, queueName: string, operation: string, destination: string, callback: (span?: Span, dstPropagationMetadata?: string) => Promise<T> | T, srcPropagationMetadata?: string): Promise<T>;

308
node_modules/bullmq/dist/esm/utils/index.js generated vendored Normal file
View File

@@ -0,0 +1,308 @@
export { randomUUID } from 'crypto';
import { ConnectionClosedError, CONNECTION_CLOSED_ERROR_MSG, } from '../classes/errors/connection-closed-error';
import * as semver from 'semver';
import { SpanKind, TelemetryAttributes } from '../enums';
export const errorObject = { value: null };
export function tryCatch(fn, ctx, args) {
try {
return fn.apply(ctx, args);
}
catch (e) {
errorObject.value = e;
return errorObject;
}
}
/**
* Returns the size of a string in UTF-8 bytes (handles multi-byte characters correctly).
* @see https://stackoverflow.com/a/23318053/1347170
* @param str - The string to measure.
* @returns The byte length of the string when encoded as UTF-8.
*/
export function lengthInUtf8Bytes(str) {
return Buffer.byteLength(str, 'utf8');
}
export function isEmpty(obj) {
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
return false;
}
}
return true;
}
export function array2obj(arr) {
const obj = {};
for (let i = 0; i < arr.length; i += 2) {
obj[arr[i]] = arr[i + 1];
}
return obj;
}
export function objectToFlatArray(obj) {
const arr = [];
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key) &&
obj[key] !== undefined) {
arr[arr.length] = key;
arr[arr.length] = obj[key];
}
}
return arr;
}
export function delay(ms, abortController) {
return new Promise(resolve => {
// eslint-disable-next-line prefer-const
let timeout;
const callback = () => {
abortController === null || abortController === void 0 ? void 0 : abortController.signal.removeEventListener('abort', callback);
clearTimeout(timeout);
resolve();
};
timeout = setTimeout(callback, ms);
abortController === null || abortController === void 0 ? void 0 : abortController.signal.addEventListener('abort', callback);
});
}
/**
* Forwards 'error' events from a connection to its owning emitter, but only
* when a consumer is listening. Emitting 'error' on an EventEmitter with no
* listeners throws, which would turn a transient connection error (e.g. a
* failed init handshake before the consumer attached its listener) into an
* unhandled rejection.
*
* @param emitter - The owner emitter (Queue, Worker, FlowProducer, ...).
* @param connection - The connection whose 'error' events should be forwarded.
*/
export function forwardConnectionError(emitter, connection) {
connection.on('error', (error) => {
if (emitter.listenerCount('error') > 0) {
emitter.emit('error', error);
}
});
}
export function increaseMaxListeners(emitter, count) {
const maxListeners = emitter.getMaxListeners();
emitter.setMaxListeners(maxListeners + count);
}
export function invertObject(obj) {
return Object.entries(obj).reduce((result, [key, value]) => {
result[value] = key;
return result;
}, {});
}
export const optsDecodeMap = {
de: 'deduplication',
fpof: 'failParentOnFailure',
cpof: 'continueParentOnFailure',
idof: 'ignoreDependencyOnFailure',
kl: 'keepLogs',
rdof: 'removeDependencyOnFailure',
};
export const optsEncodeMap = Object.assign({}, invertObject(optsDecodeMap));
export function isRedisInstance(obj) {
if (!obj) {
return false;
}
const redisApi = ['connect', 'disconnect', 'duplicate'];
return redisApi.every(name => typeof obj[name] === 'function');
}
export function isRedisCluster(obj) {
return isRedisInstance(obj) && !!obj.isCluster;
}
export function decreaseMaxListeners(emitter, count) {
increaseMaxListeners(emitter, -count);
}
export async function removeAllQueueData(client, queueName, prefix = process.env.BULLMQ_TEST_PREFIX || 'bull') {
if (client.isCluster) {
// scanStream is not cluster-safe across all key slots.
// Applies to adapter clients and raw ioredis Cluster clients alike.
// @see https://github.com/luin/ioredis/issues/175
return false;
}
const pattern = `${prefix}:${queueName}:*`;
const pendingOperations = [];
await new Promise((resolve, reject) => {
const stream = client.scanStream({
match: pattern,
});
stream.on('data', (keys) => {
if (keys.length) {
const pipeline = client.pipeline();
keys.forEach(key => {
pipeline.del(key);
});
const execPromise = pipeline.exec().catch(error => {
reject(error);
throw error;
});
pendingOperations.push(execPromise);
}
});
stream.on('end', () => resolve());
stream.on('error', error => reject(error));
});
// Wait for all pipeline operations to complete before closing the connection
await Promise.all(pendingOperations);
// Handle connection close with better error handling for Dragonfly
try {
await client.quit();
}
catch (error) {
if (isNotConnectionError(error)) {
throw error;
}
}
}
export function getParentKey(opts) {
if (opts) {
return `${opts.queue}:${opts.id}`;
}
}
export const clientCommandMessageReg = /ERR unknown command ['`]\s*client\s*['`]/;
export const DELAY_TIME_5 = 5000;
export const DELAY_TIME_1 = 100;
export function isNotConnectionError(error) {
if (error instanceof ConnectionClosedError) {
return false;
}
const { code, message: errorMessage } = error;
return (errorMessage !== CONNECTION_CLOSED_ERROR_MSG &&
!errorMessage.includes('ECONNREFUSED') &&
code !== 'ECONNREFUSED');
}
export const asyncSend = (proc, msg) => {
return new Promise((resolve, reject) => {
if (typeof proc.send === 'function') {
proc.send(msg, (err) => {
if (err) {
reject(err);
}
else {
resolve();
}
});
}
else if (typeof proc.postMessage === 'function') {
resolve(proc.postMessage(msg));
}
else {
resolve();
}
});
};
export const childSend = (proc, msg) => asyncSend(proc, msg);
export const isRedisVersionLowerThan = (currentVersion, minimumVersion, currentDatabaseType, desiredDatabaseType = 'redis') => {
if (currentDatabaseType === desiredDatabaseType) {
const version = semver.valid(semver.coerce(currentVersion));
return semver.lt(version, minimumVersion);
}
return false;
};
export const parseObjectValues = (obj) => {
const accumulator = {};
for (const value of Object.entries(obj)) {
accumulator[value[0]] = JSON.parse(value[1]);
}
return accumulator;
};
const getCircularReplacer = (rootReference) => {
const references = new WeakSet();
references.add(rootReference);
return (_, value) => {
if (typeof value === 'object' && value !== null) {
if (references.has(value)) {
return '[Circular]';
}
references.add(value);
}
return value;
};
};
export const errorToJSON = (value) => {
const error = {};
Object.getOwnPropertyNames(value).forEach(function (propName) {
error[propName] = value[propName];
});
return JSON.parse(JSON.stringify(error, getCircularReplacer(value)));
};
const INFINITY = 1 / 0;
export const toString = (value) => {
if (value == null) {
return '';
}
// Exit early for strings to avoid a performance hit in some environments.
if (typeof value === 'string') {
return value;
}
if (Array.isArray(value)) {
// Recursively convert values (susceptible to call stack limits).
return `${value.map(other => (other == null ? other : toString(other)))}`;
}
if (typeof value == 'symbol' ||
Object.prototype.toString.call(value) == '[object Symbol]') {
return value.toString();
}
const result = `${value}`;
return result === '0' && 1 / value === -INFINITY ? '-0' : result;
};
export const QUEUE_EVENT_SUFFIX = ':qe';
export function removeUndefinedFields(obj) {
const newObj = {};
for (const key in obj) {
if (obj[key] !== undefined) {
newObj[key] = obj[key];
}
}
return newObj;
}
/**
* Wraps the code with telemetry and provides a span for configuration.
*
* @param telemetry - telemetry configuration. If undefined, the callback will be executed without telemetry.
* @param spanKind - kind of the span: Producer, Consumer, Internal
* @param queueName - queue name
* @param operation - operation name (such as add, process, etc)
* @param destination - destination name (normally the queue name)
* @param callback - code to wrap with telemetry
* @param srcPropagationMetadata -
* @returns
*/
export async function trace(telemetry, spanKind, queueName, operation, destination, callback, srcPropagationMetadata) {
if (!telemetry) {
return callback();
}
else {
const { tracer, contextManager } = telemetry;
const currentContext = contextManager.active();
let parentContext;
if (srcPropagationMetadata) {
parentContext = contextManager.fromMetadata(currentContext, srcPropagationMetadata);
}
const spanName = destination ? `${operation} ${destination}` : operation;
const span = tracer.startSpan(spanName, {
kind: spanKind,
}, parentContext);
try {
span.setAttributes({
[TelemetryAttributes.QueueName]: queueName,
[TelemetryAttributes.QueueOperation]: operation,
});
let messageContext;
let dstPropagationMetadata;
if (spanKind === SpanKind.CONSUMER && parentContext) {
messageContext = span.setSpanOnContext(parentContext);
}
else {
messageContext = span.setSpanOnContext(currentContext);
}
if (callback.length == 2) {
dstPropagationMetadata = contextManager.getMetadata(messageContext);
}
return await contextManager.with(messageContext, () => callback(span, dstPropagationMetadata));
}
catch (err) {
span.recordException(err);
throw err;
}
finally {
span.end();
}
}
}