import { ResolvedCPanyOption, IHandle, Key, IContest, IAuthor, ISubmission, IUser, DiffLog, CPanyOption } from '@cpany/types'; type LogFn = (message: string) => void; type LogLevel = 'warn' | 'error' | 'silent'; interface Logger { debug: (...args: any[]) => void; info: LogFn; warning: LogFn; error: LogFn; startGroup: (name: string) => void; endGroup: () => void; } interface ExtendLogger { debug: (...args: any[]) => void; info: LogFn; warning: LogFn; error: LogFn; startGroup: (name: string) => void; endGroup: () => void; setLevel: (logLevel: LogLevel) => void; } declare function createLogger(option?: { logLevel?: LogLevel; context?: string; }, logger?: Logger): ExtendLogger; declare function createLoggerFactory(contexts: string[], logLevel?: LogLevel, logger?: Logger): (context: string) => ExtendLogger; interface BasicPlugin { name: string; platform: string; enforce?: 'pre' | 'post'; } type CPanyFetchPlugin = CachePlugin | FetchPlugin | QueryPlugin; interface CachePlugin extends BasicPlugin { cache: (context: FetchContext) => Promise; } interface FetchPlugin extends BasicPlugin { fetch: (context: FetchContext) => Promise; } interface QueryPlugin extends BasicPlugin { query: (payload: string, context: FetchContext) => Promise; } interface FetchContext { logger: Logger; readJsonFile: (filename: string) => Promise; readJsonDir: (rootDir: string) => Promise; listDir: (rootDir: string) => Promise; writeFile: (content: string, filename: string) => Promise; removeFile: (filename: string) => Promise; } interface FetchResult { filename: string; content: string; } interface LoadPlugin extends BasicPlugin { load: (option: ResolvedCPanyOption, context: LoadContext) => Promise; } interface LoadContext extends FetchContext { addHandle: (...handles: IHandle[]) => void; addContest: (...contests: Key[]) => void; addUserContest: (name: string, contest: Key, author: IAuthor) => boolean; findHandle: (platform: string, handle: string) => IHandle | undefined; findUsername: (platform: string, handle: string) => string | undefined; } interface DiffContext { addHandleSubmission(name: string, ...submissions: ISubmission[]): void; addHandleContest(name: string, ...contests: IContest[]): void; addContest(...contests: IContest[]): void; } interface DiffPlugin extends BasicPlugin { diff: (context: DiffContext) => Promise; } type CPanyPlugin = CPanyFetchPlugin | LoadPlugin | DiffPlugin; declare function isCachePlugin(plugin: CPanyPlugin): plugin is CachePlugin; declare function isFetchPlugin(plugin: CPanyPlugin): plugin is FetchPlugin; declare function isQueryPlugin(plugin: CPanyPlugin): plugin is QueryPlugin; declare function isLoadPlugin(plugin: CPanyPlugin): plugin is LoadPlugin; declare function isDiffPlugin(plugin: CPanyPlugin): plugin is DiffPlugin; declare function createPluginContainer(plugins?: Array): PluginContainer; declare function sortPlugins(plugins: T[]): T[]; interface PluginContainer { /** * All CPany plugins, sorted by enforce, platform, name */ plugins: CPanyPlugin[]; platforms: string[]; cache(): CachePlugin[]; fetch(platform?: string): FetchPlugin[]; allQuery(): QueryPlugin[]; query(platform: string, name: string): QueryPlugin | undefined; load(): LoadPlugin[]; diff(): DiffPlugin[]; } interface CreateOptions { plugins?: Array; logger?: Logger; logLevel?: LogLevel; } interface CPanyInstance extends FSOperations { logger: Logger; platforms: string[]; fetchAll: (option: ResolvedCPanyOption) => Promise; loadAll: (option: ResolvedCPanyOption) => Promise<{ handles: Array>; contests: Array>; users: IUser[]; }>; cache: () => Promise; fetch: (platform: string, name: string) => Promise; query: (platform: string, name: string, payload: string | number) => Promise; diff: (option: ResolvedCPanyOption) => Promise; } interface FSOperations { on: (event: T, fn: FSEventType[T]) => void; } /** * Paths are relative under the data root directory. */ interface FSEventType { read: (...paths: string[]) => Promise; list: (platform: string, ...paths: string[]) => Promise; write: (content: string, ...paths: string[]) => Promise; remove: (...paths: string[]) => Promise; } declare function createCPany(option: CreateOptions): CPanyInstance; type TaskFn = () => Promise; declare function createRetryContainer(logger: Logger, maxRetry?: number): { add: (id: string, fn: TaskFn) => void; run: () => Promise; }; declare function resolveCPanyOption(dataRoot: string, rawOption: CPanyOption): ResolvedCPanyOption; declare const DefaultMaxRetry = 5; declare const DefaultRecentTime: number; declare const DefaultRecentContestsCount = 15; declare const DefaultRecentUserCount = 5; declare const DefaultNav: string[]; declare function shuffle(array: T[]): T[]; declare function diff(f: (item: T) => string, old: T[], cur: T[]): T[]; export { type CPanyFetchPlugin, type CPanyInstance, type CPanyPlugin, type CachePlugin, DefaultMaxRetry, DefaultNav, DefaultRecentContestsCount, DefaultRecentTime, DefaultRecentUserCount, type DiffPlugin, type ExtendLogger, type FetchContext, type FetchPlugin, type FetchResult, type LoadContext, type LoadPlugin, type LogLevel, type Logger, type QueryPlugin, createCPany, createLogger, createLoggerFactory, createPluginContainer, createRetryContainer, diff, isCachePlugin, isDiffPlugin, isFetchPlugin, isLoadPlugin, isQueryPlugin, resolveCPanyOption, shuffle, sortPlugins };