diff --git a/index.d.ts b/index.d.ts index f660d289..2e8081b5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,97 +1,85 @@ -declare namespace Abstract { - interface LevelDOWN< - TKey=any, - TValue=any, - TOptions=any, - TPutOptions=any, - TGetOptions=any, - TDeleteOptions=any, - TIteratorOptions=any, - TBatchOptions=any> { - open(callback: any): void; - open(options: TOptions, callback: any): void; - close(callback: any): void; - get(key: TKey, callback: any): void; - get(key: TKey, options: TGetOptions, callback: any): void; - put(key: TKey, value: TValue, callback: any): void; - put(key: TKey, value: TValue, options: TPutOptions, callback: any): void; - del(key: TKey, callback: any): void; - del(key: TKey, options: TDeleteOptions, callback: any): void; - batch(): ChainedBatch - batch(array: any[], callback: any): any; - batch(array: any[], options: TBatchOptions, callback: any): any; - iterator(options?: TIteratorOptions): Iterator - [index: string]: any; - } - - interface LevelDOWNConstructor { - new - < - TKey=any, - TValue=any, - TOptions=any, - TPutOptions=any, - TGetOptions=any, - TDeleteOptions=any, - TIteratorOptions=any, - TBatchOptions=any - >(location: string): LevelDOWN< - TKey, - TValue, - TOptions, - TPutOptions, - TGetOptions, - TDeleteOptions, - TIteratorOptions, - TBatchOptions>; - < - TKey=any, - TValue=any, - TOptions=any, - TPutOptions=any, - TGetOptions=any, - TDeleteOptions=any, - TIteratorOptions=any, - TBatchOptions=any - >(location: string): LevelDOWN< - TKey, - TValue, - TOptions, - TPutOptions, - TGetOptions, - TDeleteOptions, - TIteratorOptions, - TBatchOptions> - } - - interface Iterator { - next(callback: any): void; - end(callback: any): void; - [index: string]: any; - } - interface IteratorConstructor { - new(db: any): Iterator; - (db: any): Iterator; - } - - interface ChainedBatch { - put(key: TKey, value: TValue): this; - del(key: TKey): this; - clear(): this; - write(callback: any): any - write(options: any, callback: any): any - [index: string]: any; - } - - interface ChainedBatchConstructor { - new (db: any): ChainedBatch; - (db: any): ChainedBatch; - } - - export const AbstractIterator: IteratorConstructor & Iterator; - export const AbstractLevelDOWN: LevelDOWNConstructor & LevelDOWN; - export const AbstractChainedBatch: ChainedBatchConstructor & ChainedBatch; - export function isLevelDOWN(db: any): boolean; +interface AbstractLevelDOWN { + open(callback: (err?: any) => void); + open(options: O, callback: (err?: any) => void); + + close(callback: (err?: any) => void); + + get(key: K, callback: (err, value: V) => any); + get(key: K, options: GO, callback: (err, value: V) => any); + + put(key: K, value: V, callback: (err: any) => any); + put(key: K, value: V, options: PO, callback: (err: any) => any); + + del(key: K, callback: (err: any) => any); + del(key: K, options: DO, callback: (err: any) => any); + + batch(): AbstractChainedBatch; + batch(array: Batch[], callback: (err: any) => any); + batch(array: Batch[], options: BO, callback: (err: any) => any); + + iterator(options?: IO & AbstractIteratorOptions): AbstractIterator; + + approximateSize(start: K, end: K, cb: (err: any, size: number) => void): void; + + [index: string]: any; +} + +interface AbstractLevelDOWNConstructor { + new (location: string): AbstractLevelDOWN< + K, V, O, PO, GO, DO, IO, BO>; + (location: string): AbstractLevelDOWN< + K, V, O, PO, GO, DO, IO, BO>; +} + +export interface AbstractIteratorOptions { + gt?: K; + gte?: K; + lt?: K; + lte?: K; + reverse?: boolean; + limit?: number; + keys?: boolean; + values?: boolean; +} + +export type Batch = PutBatch | DelBatch + +export interface PutBatch { + type: 'put', + key: K, + value: V +} + +export interface DelBatch { + type: 'del', + key: K +} + +interface AbstractIterator { + next(callback: (err: any, key: K, value: V) => void): void; + end(callback: (err: any) => void): void; +} + +interface AbstractIteratorConstructor { + new (db: any): AbstractIterator; + (db: any): AbstractIterator; +} + +interface AbstractChainedBatch extends AbstractChainedBatchConstructor { + put(key: K, value: V): this; + del(key: K): this; + clear(): this; + write(callback: any): any + write(options: BO, callback: any): any + [index: string]: any; +} + +interface AbstractChainedBatchConstructor { + new (db: any): AbstractChainedBatch; + (db: any): AbstractChainedBatch; } -export = Abstract; \ No newline at end of file +export const AbstractLevelDOWN: AbstractLevelDOWNConstructor +export const AbstractIterator: AbstractIteratorConstructor +export const AbstractChainedBatch: AbstractChainedBatchConstructor +export function isLevelDOWN(db: any): boolean; \ No newline at end of file