/** * Common Type Definitions * Shared types to eliminate 'any' usage across the SDK */ import { NextFunction, Request, Response } from 'express'; /** * Express Request with typed body and user */ export interface TypedRequest, TParams = Record> extends Request { body: TBody; query: TQuery & Request['query']; params: TParams & Request['params']; user?: AuthUser; correlationId?: string; span?: TracingSpan; featureFlags?: FeatureFlagClient; } /** * Express Response with typed json method */ export interface TypedResponse extends Response { json: (data: TData) => this; } /** * Express middleware signature */ export type ExpressMiddleware = (req: Request, res: Response, next: NextFunction) => void | Promise; /** * Typed Express middleware */ export type TypedMiddleware = (req: TReq, res: TRes, next: NextFunction) => void | Promise; export interface AuthUser { id: string; email?: string; name?: string; roles?: string[]; permissions?: string[]; organizationId?: string; metadata?: Record; } export interface RedisClient { get(key: string): Promise; set(key: string, value: string, mode?: 'EX' | 'PX', duration?: number): Promise; setex(key: string, seconds: number, value: string): Promise; psetex(key: string, milliseconds: number, value: string): Promise; del(key: string | string[]): Promise; exists(key: string | string[]): Promise; expire(key: string, seconds: number): Promise; ttl(key: string): Promise; pttl(key: string): Promise; incr(key: string): Promise; decr(key: string): Promise; incrby(key: string, increment: number): Promise; decrby(key: string, decrement: number): Promise; hget(key: string, field: string): Promise; hset(key: string, field: string, value: string): Promise; hdel(key: string, field: string | string[]): Promise; hgetall(key: string): Promise>; lpush(key: string, ...values: string[]): Promise; rpush(key: string, ...values: string[]): Promise; lpop(key: string): Promise; rpop(key: string): Promise; llen(key: string): Promise; sadd(key: string, ...members: string[]): Promise; srem(key: string, ...members: string[]): Promise; smembers(key: string): Promise; sismember(key: string, member: string): Promise; zadd(key: string, score: number, member: string): Promise; zrem(key: string, member: string | string[]): Promise; zrange(key: string, start: number, stop: number, withScores?: 'WITHSCORES'): Promise; zrevrange(key: string, start: number, stop: number, withScores?: 'WITHSCORES'): Promise; zcard(key: string): Promise; zremrangebyscore(key: string, min: string | number, max: string | number): Promise; keys(pattern: string): Promise; scan(cursor: string, options?: { match?: string; count?: number; }): Promise<[string, string[]]>; mget(...keys: string[]): Promise<(string | null)[]>; mset(...keysAndValues: string[]): Promise; multi(): RedisMulti; pipeline(): RedisPipeline; subscribe(channel: string | string[]): Promise; unsubscribe(channel: string | string[]): Promise; publish(channel: string, message: string): Promise; connect(): Promise; disconnect(): Promise; quit(): Promise; on(event: string, listener: (...args: unknown[]) => void): this; off(event: string, listener: (...args: unknown[]) => void): this; } export interface RedisMulti { get(key: string): RedisMulti; set(key: string, value: string): RedisMulti; del(key: string | string[]): RedisMulti; incr(key: string): RedisMulti; incrby(key: string, increment: number): RedisMulti; expire(key: string, seconds: number): RedisMulti; pexpire(key: string, milliseconds: number): RedisMulti; ttl(key: string): RedisMulti; pttl(key: string): RedisMulti; zadd(key: string, score: number, member: string): RedisMulti; zrem(key: string, member: string): RedisMulti; zremrangebyscore(key: string, min: string | number, max: string | number): RedisMulti; exec(): Promise; } export interface RedisPipeline { get(key: string): RedisPipeline; set(key: string, value: string, mode?: 'EX', duration?: number): RedisPipeline; setex(key: string, seconds: number, value: string): RedisPipeline; del(key: string | string[]): RedisPipeline; expire(key: string, seconds: number): RedisPipeline; exec(): Promise; } /** * Class decorator */ export type ClassDecorator = (target: new (...args: unknown[]) => T) => void; /** * Method decorator */ export type MethodDecorator = (target: unknown, propertyKey: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor | void; /** * Property decorator */ export type PropertyDecorator = (target: unknown, propertyKey: string | symbol) => void; /** * Parameter decorator */ export type ParameterDecorator = (target: unknown, propertyKey: string | symbol, parameterIndex: number) => void; export interface CacheEntry { value: T; ttl?: number; metadata?: Record; } export interface CacheSerializer { serialize(value: unknown): string | Buffer; deserialize(data: string | Buffer): unknown; } export interface FeatureFlagClient { isEnabled(flag: string, userId?: string, attributes?: Record): Promise; getVariant(flag: string, userId?: string, attributes?: Record): Promise; } export interface FeatureFlagConfig { enabled: boolean; percentage?: number; userOverrides?: string[]; groupOverrides?: string[]; metadata?: Record; variants?: Array<{ name: string; weight: number; metadata?: Record; }>; } export interface TracingSpan { end(): void; setAttributes(attributes: Record): void; setStatus(status: { code: number; message?: string; }): void; addEvent(name: string, attributes?: Record): void; } export interface TracingContext { traceparent?: string; tracestate?: string; } export interface DomainEvent { id: string; type: string; streamId: string; version: number; data: T; metadata?: Record; timestamp: Date; correlationId?: string; causationId?: string; } export interface ErrorDetails { code: string; message: string; details?: unknown; stack?: string; cause?: Error; } export interface CircuitBreakerStats { state: 'CLOSED' | 'OPEN' | 'HALF_OPEN'; failures: number; successes: number; lastFailureTime?: Date; nextRetryTime?: Date; } export interface RateLimitResult { allowed: boolean; remaining: number; resetAt: Date; retryAfter?: number; } /** * Deep partial type */ export type DeepPartial = { [P in keyof T]?: T[P] extends object ? DeepPartial : T[P]; }; /** * Async function type */ export type AsyncFunction = (...args: TArgs) => Promise; /** * Sync function type */ export type SyncFunction = (...args: TArgs) => TReturn; /** * Any function type */ export type AnyFunction = SyncFunction | AsyncFunction; /** * Constructor type */ export type Constructor = new (...args: unknown[]) => T; /** * Key-value object */ export type KeyValue = Record; /** * JSON serializable types */ export type JsonPrimitive = string | number | boolean | null; export type JsonObject = { [key: string]: JsonValue; }; export type JsonArray = JsonValue[]; export type JsonValue = JsonPrimitive | JsonObject | JsonArray; /** * Extract promise type */ export type UnwrapPromise = T extends Promise ? U : T; /** * Make specific keys optional */ export type OptionalKeys = Omit & Partial>; //# sourceMappingURL=common.d.ts.map