///
import { Borders, CellValue, Style } from "exceljs";
import { Consumer, ConsumerConfig, ConsumerRunConfig, ConsumerSubscribeTopics, Producer, ProducerConfig, ProducerRecord, TopicPartitionOffsetAndMetadata } from "kafkajs";
import { FILTER_OPERATOR, HttpMethod, LOG_LEVEL, SET_CACHE_POLICY } from "./constants";
import { AxiosRequestConfig } from "axios";
export interface Subscription {
unsubscribe(): Promise;
}
export interface DelayedTaskOps {
callback: () => void;
startOnCreate?: boolean;
timeout: number;
}
export interface TaskRescheduleOps {
msFromNow?: number;
runTime?: Date;
}
export interface TaskQueue {
push(queueName: string, name: string, handler: any): Promise;
}
export type DelayFn = (callback: () => void, timeout: number) => Subscription;
export type TaskFn = () => any | Promise;
export interface ITask {
id: string;
isRunning: boolean;
isCancelled: boolean;
isCron: boolean;
start(): Promise;
cancel(): Promise;
lastRun(): Promise;
nextRun(): Promise;
reschedule(options: TaskRescheduleOps): Promise;
}
export interface TaskRegistry {
register(options: DelayedTaskOps): Promise;
count(): Promise;
getTasks(): Promise;
getTaskById(id: string): Promise;
cancelTaskById(id: string): Promise;
startTaskById(id: string): Promise;
}
export interface SQLRunner {
query(sql: string, ...args: any[]): Promise;
}
export interface HttpRequestOption extends AxiosRequestConfig {
serviceName?: string;
body?: any;
query?: any;
headers?: Record;
reqId?: string;
}
export interface Logger {
info(message: string, ...args: any[]): void;
error(message: string, ...args: any[]): void;
warn(message: string, ...args: any[]): void;
}
export interface HttpService {
send(method: HttpMethod, url: string, options: HttpRequestOption): Promise>;
}
export interface InternalAuthGatewayOptions {
endpointURL: string;
secret: string;
serviceName?: string;
}
export interface InternalAuthLoginResult {
accessToken?: string;
code?: string;
}
export interface InternalServiceAuthResult {
name: string;
type: "internal" | "external";
}
export interface DeleteByPatternOptions {
includePrefixInScanPattern: boolean;
}
export interface CacheService {
ttl(key: string): Promise;
get(key: string): Promise;
set(key: string, value: any, option?: SetCacheOption): Promise;
del(...keys: string[]): Promise;
incrBy(key: string, value?: number): Promise;
incrByFloat(key: string, value: number): Promise;
decrBy(key: string, value: number): Promise;
deleteByPattern(pattern: string): Promise;
getNumber(key: string): Promise;
expire(key: string, ttl: number): Promise;
}
export interface IPaginatedDataCache {
generateCacheKey(filter?: Record, limit?: number, offset?: number): string;
getCurrentVersion(): Promise;
getCachedPaginatedData(filter: Record, limit: number, offset: number): Promise>;
setCachedPaginatedData(filter: Record, limit: number, offset: number, data: PaginationResult, ttlInSecs?: number): Promise;
incrementCacheVersion(ttl?: number): Promise;
}
export interface PaginationResult {
rows: T[];
total: number;
limit: number;
offset: number;
}
export interface HashCacheService {
hset(key: string, field: string, value: any): Promise;
hget(key: string, field: string): Promise;
hlen(key: string): Promise;
hincrbyfloat(key: string, field: string, value?: number): Promise;
hincrby(key: string, field: string, value?: number): Promise;
hkeys(key: string): Promise;
hdel(key: string, ...fields: string[]): Promise;
hexists(key: string, field: string): Promise;
}
export interface SetCacheService {
sadd(key: string, ...values: string[]): Promise;
srem(key: string, ...values: string[]): Promise;
scard(key: string): Promise;
}
export interface ListCacheService {
lpush(key: string, value: any): Promise;
lset(key: string, index: number, value: any): Promise;
lrem(key: string, count: string | number, element: string | Buffer | number): Promise;
rpush(key: string, value: any): Promise;
lrange(key: string, start: number, end: number): Promise;
lindex(key: string, index: number): Promise;
llen(key: string): Promise;
}
export type LuaCall = [script: string, numberOfKeys: number, ...args: any[]];
export interface CacheScriptEvaluator {
eval(script: string, numberOfKeys: number, ...args: any[]): Promise;
multiEval(calls: LuaCall[]): Promise;
}
export interface LockResult {
isLocked: boolean;
attemptsLeft: number;
}
export interface CRUDService {
findById(userId: any, ...options: any[]): Promise;
}
export interface SetCacheOption {
policy: Policy;
value?: any;
}
export interface IMessageQueueService {
initProducer(config?: any): Promise;
initConsumer(config?: any): Promise;
listen(subscribeConfig: any, runConfig: any): Promise;
publish(record: any): Promise;
commitOffsets(data: TopicPartitionOffsetAndMetadata[]): Promise;
producer: Producer;
consumer: Consumer;
}
export interface HttpResponse {
success?: boolean;
code?: string;
httpCode?: number;
message?: string;
data?: T;
}
export interface IKafkaService extends IMessageQueueService {
initProducer(config?: ProducerConfig): Promise;
initConsumer(config?: ConsumerConfig): Promise;
listen(subscribeConfig: ConsumerSubscribeTopics, runConfig: ConsumerRunConfig): Promise;
publish(record: ProducerRecord): Promise;
}
export interface PutObjectOption {
domain: string;
timeout?: number;
}
export interface CloudStorageClient {
generateTmpCredentials(sessionId: string): Promise;
getObjectReadStream(fileName: string): Promise;
deleteObject(filePath: string): Promise;
uploadLocalToBucket(fileName: string, fileData: Buffer, options?: PutObjectOption): Promise;
uploadRemoteObjectToBucket(fileName: string, remoteUrl: string, options?: PutObjectOption): Promise;
}
export interface IFilter {
field: string;
operator: FILTER_OPERATOR;
value: any;
}
export type SORT_DIRECTION = "ASC" | "DESC";
export interface ISort {
columnName: string;
direction: SORT_DIRECTION;
}
export interface EmailSender {
send(mailOptions: SendMailOptions): Promise;
}
export interface SendMailOptions {
from?: string;
to?: string | string[];
cc?: string | string[];
bcc?: string | string[];
subject: string;
text?: string;
html?: string;
}
export interface ICellOptions {
style?: Partial