import { DestinationServer } from '@walkeros/server-core'; import { Flow } from '@walkeros/core'; /** * Arguments passed to Redis XADD. Strings or numbers (for MAXLEN counts). */ type XaddArg = string | number; /** * Mock-friendly Redis pipeline interface. Accumulates commands and * executes them with a single round-trip via exec(). */ interface RedisPipelineMock { xadd: (...args: XaddArg[]) => RedisPipelineMock; exec: () => Promise | null>; } /** * Mock-friendly Redis client interface used by the destination. * Tests provide this via env.Redis; production creates a real ioredis * client and uses it directly. */ interface RedisClientMock { xadd: (...args: XaddArg[]) => Promise; pipeline: () => RedisPipelineMock; quit: () => Promise; on?: (event: string, listener: (...args: unknown[]) => void) => unknown; } /** * Constructor signature for the Redis client. Accepts either a URL * string or an options object, matching ioredis's dual signature. */ interface RedisClientConstructor { new (url: string): RedisClientMock; new (options: RedisClientOptions): RedisClientMock; } /** * Minimal ioredis options subset the destination passes through. * Unknown options are preserved for the SDK to handle. */ interface RedisClientOptions { host?: string; port?: number; username?: string; password?: string; db?: number; tls?: boolean | Record; connectTimeout?: number; commandTimeout?: number; [key: string]: unknown; } type SerializationMode = 'json' | 'flat'; interface RedisSettings { /** Redis stream key name (e.g. 'walkeros:events'). */ streamKey: string; /** Redis connection URL (e.g. 'redis://localhost:6379' or 'rediss://...'). */ url?: string; /** ioredis connection options (used if no url provided). */ options?: RedisClientOptions; /** * Maximum stream length. Enables MAXLEN trimming on every XADD. * Uses approximate (~) trimming by default for performance. * Omit for unlimited stream length. */ maxLen?: number; /** * Use exact MAXLEN instead of approximate (~). * Not recommended for production -- significantly slower. * Default: false (approximate trimming). */ exactTrimming?: boolean; /** * Serialization mode for the event payload. * - 'json': Single 'event' field with JSON string (default) * - 'flat': Top-level event fields as separate stream fields */ serialization?: SerializationMode; _client?: RedisClientMock; _ownedClient?: boolean; } interface Settings { redis: RedisSettings; } /** * Env -- optional Redis SDK override. Production leaves this undefined * and the destination creates real ioredis client instances. Tests provide * mocks via env.Redis. */ interface Env extends DestinationServer.Env { Redis?: { Client: RedisClientConstructor; }; } declare const push: Env; declare const simulation: string[]; declare const env_push: typeof push; declare const env_simulation: typeof simulation; declare namespace env { export { env_push as push, env_simulation as simulation }; } /** * Extended step example that may carry destination-level settings overrides. */ type RedisStepExample = Flow.StepExample & { settings?: Partial; }; /** * Default JSON serialization -- single 'event' field with full event JSON. */ declare const jsonDefault: RedisStepExample; /** * Order event -- verifies different event types pass through correctly. */ declare const orderComplete: RedisStepExample; /** * With MAXLEN approximate trimming -- trimming args inserted before '*'. */ declare const withMaxLen: RedisStepExample; /** * Exact MAXLEN trimming -- no '~' between MAXLEN and the count. */ declare const withExactTrim: RedisStepExample; /** * Stream key override per rule -- routes this event to a dedicated stream. */ declare const streamKeyOverride: RedisStepExample; /** * Ignored event -- mapping.ignore: true produces no xadd call. */ declare const ignoredEvent: RedisStepExample; type step_RedisStepExample = RedisStepExample; declare const step_ignoredEvent: typeof ignoredEvent; declare const step_jsonDefault: typeof jsonDefault; declare const step_orderComplete: typeof orderComplete; declare const step_streamKeyOverride: typeof streamKeyOverride; declare const step_withExactTrim: typeof withExactTrim; declare const step_withMaxLen: typeof withMaxLen; declare namespace step { export { type step_RedisStepExample as RedisStepExample, step_ignoredEvent as ignoredEvent, step_jsonDefault as jsonDefault, step_orderComplete as orderComplete, step_streamKeyOverride as streamKeyOverride, step_withExactTrim as withExactTrim, step_withMaxLen as withMaxLen }; } export { env, step };