import type net from 'node:net'; import type tls from 'node:tls'; import type { SolidisClient } from '../client.ts'; import type { RespError } from '../common/utils/error.ts'; import type { SolidisConnection } from '../modules/connection.ts'; import type { SolidisDebugMemory } from '../modules/debug.ts'; import type { SolidisPubSub } from '../modules/pubsub.ts'; export type StringOrBuffer = string | Buffer; export type SolidisData = string | number | null | Buffer | boolean | bigint | RespError | SolidisData[] | Map | Set; export type SolidisRecursiveStringRecord = { [key: string]: string | undefined | SolidisRecursiveStringRecord; }; export declare const SolidisProtocols: { readonly RESP2: "RESP2"; readonly RESP3: "RESP3"; }; export type SolidisProtocols = keyof typeof SolidisProtocols; type DeepRequired = { [P in keyof T]-?: NonNullable extends object ? DeepRequired> : NonNullable; }; export interface SolidisClientOptions { authentication?: { username?: string; password?: string; }; autoReconnect?: boolean; autoRecovery?: { database?: boolean; subscribe?: boolean; ssubscribe?: boolean; psubscribe?: boolean; }; clientName?: string; commandTimeout?: number; connectionTimeout?: number; connectionRetryDelay?: number; database?: number; debug?: boolean; debugMaxEntries?: number; enableReadyCheck?: boolean; host?: string; uri?: string | URL | false; lazyConnect?: boolean; maxConnectionRetries?: number; maxCommandsPerPipeline?: number; maxEventListenersForClient?: number; maxEventListenersForSocket?: number; maxProcessReplyBytesPerChunk?: number; maxProcessRepliesPerChunk?: number; maxSocketWriteSizePerOnce?: number; parser?: { buffer?: { initial?: number; shiftThreshold?: number; }; maxBulkStringLength?: number; }; port?: number; protocol?: SolidisProtocols; readyCheckInterval?: number; maxReadyCheckRetries?: number; rejectOnPartialPipelineError?: boolean; socketWriteTimeout?: number; tls?: tls.ConnectionOptions; } export type SolidisClientFrozenOptions = Readonly> & { tls?: tls.ConnectionOptions; }>; export type SolidisConnectionOptions = SolidisClientFrozenOptions & { debugMemory?: SolidisDebugMemory; }; export type SolidisRequesterOptions = SolidisClientFrozenOptions & { connection: SolidisConnection; pubSub: SolidisPubSub; debugMemory?: SolidisDebugMemory; }; export type SolidisSocket = net.Socket | tls.TLSSocket; export type SolidisSubRequestResolveHandler = (value: SolidisData[]) => void; export type SolidisRequestResolveHandler = (value: SolidisData[][]) => void; export type SolidisRejectHandler = (reason?: unknown) => void; export type SolidisRespLengthType = 'Bulk' | 'BlobError' | 'Array' | 'Push' | 'Map' | 'Set' | 'VerbatimString'; export type SolidisRespSimpleLineType = 'SimpleString' | 'Error' | 'Double' | 'BigNumber'; export type SolidisRespPrimitiveType = 'Integer' | 'Boolean' | 'Null'; export type SolidisRespType = SolidisRespLengthType | SolidisRespSimpleLineType | SolidisRespPrimitiveType; export type SolidisParsed = { data: T | null; length: number; ignore?: boolean; } | null; export type SolidisParsedBufferWithLength = (Omit, 'data'> & { data: Buffer | null; }) | null; export interface SolidisRequest { commands: StringOrBuffer[][]; resolve: SolidisRequestResolveHandler; reject: SolidisRejectHandler; replies: SolidisData[][]; } export interface SolidisPipelineSubRequest { span: number; resolve: SolidisSubRequestResolveHandler; reject: SolidisRejectHandler; } export interface SolidisPipelineRequest { resolve: SolidisRequestResolveHandler; reject: SolidisRejectHandler; commandsBuffer: Buffer; subRequestIndex: number; currentSubReplies: SolidisData[]; receivedReplyCount: number; expectedReplyCount: number; subRequests: SolidisPipelineSubRequest[]; subscribeCommandCount: number; timeoutId?: NodeJS.Timeout; isTimedOut?: boolean; } export interface SolidisPipelineRequestChunk { pipelinedCommands: StringOrBuffer[][]; subRequests: SolidisPipelineSubRequest[]; subscribeCommandCount: number; expectedReplyCount: number; } export interface SolidisPipelineRequestChunkContext { cursor: number; chunks: SolidisPipelineRequestChunk[]; pipelinedCommands: StringOrBuffer[][]; subRequests: SolidisPipelineSubRequest[]; subscribeCommandCount: number; } export interface SolidisSubscribeEvents { subscribe: (channel: string, count: number) => void; ssubscribe: (channel: string, count: number) => void; psubscribe: (pattern: string, count: number) => void; unsubscribe: (channel: string, count: number) => void; sunsubscribe: (channel: string, count: number) => void; punsubscribe: (pattern: string, count: number) => void; } export interface SolidisPubSubEvents extends SolidisSubscribeEvents { message: (channel: string, message: StringOrBuffer) => void; smessage: (channel: string, message: StringOrBuffer) => void; pmessage: (pattern: string, channel: string, message: StringOrBuffer) => void; } export type SolidisTranslatedPubSubReplies = [ string | null, string | null, number | StringOrBuffer | null, StringOrBuffer | null ]; export interface SolidisClientEvents extends SolidisPubSubEvents { connect: () => void; ready: () => void; reconnected: () => void; error: (error: Error) => void; end: () => void; drain: () => void; close: () => void; debug: (entry: SolidisDebugLog) => void; } export interface SolidisClientEventHandlers { emit: (event: E, ...parameters: Parameters) => boolean; on: (event: E, listener: SolidisClientEvents[E]) => T; once: (event: E, listener: SolidisClientEvents[E]) => T; } export type SolidisClientRecoveryStep) => Promise> = { condition: boolean; method: T | undefined; methodName: string; parameters: Parameters; }; export interface SolidisConnectionEvents { connect: () => void; error: (error: Error) => void; close: () => void; end: () => void; closed: (error: Error) => void; reconnected: () => void; } export interface SolidisConnectionEventHandlers { emit: (event: E, ...parameters: Parameters) => boolean; on: (event: E, listener: SolidisConnectionEvents[E]) => T; } export type SolidisDebugEvents = { pushed: (entry: SolidisDebugLog) => void; close: () => void; drain: () => void; error: (error: Error) => void; finish: () => void; pipe: (source: NodeJS.ReadableStream) => void; unpipe: (source: NodeJS.ReadableStream) => void; }; export interface SolidisDebugMemoryEventHandlers { write(chunk: SolidisDebugLog, callback?: (error: Error | null | undefined) => void): boolean; write(chunk: SolidisDebugLog, encoding: BufferEncoding, callback?: (error: Error | null | undefined) => void): boolean; emit(event: E, ...parameters: Parameters): boolean; on(event: E, listener: SolidisDebugEvents[E]): T; } export interface SolidisSocketWriteEventHandlers { onError: (error: Error) => void; waitForDrain: () => Promise; removeEventListeners: () => void; isError: boolean; error: Error | null; } export type SolidisDebugLogType = 'error' | 'info' | 'debug' | 'warn'; export interface SolidisDebugLog { timestamp?: number; type: SolidisDebugLogType; message: string; data?: unknown; } export type SolidisTransactionMethod = T extends (...parameters: infer Parameters) => unknown ? (...parameters: Parameters) => void : T; export type SolidisTransactionBannedMethods = 'multi' | 'pipeline' | 'watch' | 'unwatch' | 'subscribe' | 'ssubscribe' | 'psubscribe' | 'unsubscribe' | 'sunsubscribe' | 'punsubscribe' | 'auth' | 'hello'; export type SolidisTransactionClient = { [K in keyof T as K extends SolidisTransactionBannedMethods ? never : K]: SolidisTransactionMethod; } & { exec(): Promise; discard(): void; }; export type SolidisClientExtensions = Record> = { [K in keyof T]: K extends 'multi' ? T[K] extends (...parameters: infer Parameters) => unknown ? (...parameters: Parameters) => SolidisTransactionClient : T[K] : T[K] extends (...parameters: infer Parameters) => infer R ? (...parameters: Parameters) => R : T[K]; }; export type SolidisSubscribeMethod = (...channels: string[]) => Promise; export type SolidisSSubscribeMethod = (...channels: string[]) => Promise; export type SolidisPSubscribeMethod = (...patterns: string[]) => Promise; export {};