Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #129 from MeirionHughes/master
Browse files Browse the repository at this point in the history
refactor(typings): add missing types and simplify.
  • Loading branch information
ralphtheninja authored Sep 30, 2017
2 parents d7b0bb4 + 2046f8b commit a71072b
Showing 1 changed file with 83 additions and 95 deletions.
178 changes: 83 additions & 95 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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<TKey, TValue>
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<TKey=any, TValue=any> {
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 <TKey, TValue>(db: any): ChainedBatch<TKey, TValue>;
<TKey, TValue>(db: any): ChainedBatch<TKey, TValue>;
}

export const AbstractIterator: IteratorConstructor & Iterator;
export const AbstractLevelDOWN: LevelDOWNConstructor & LevelDOWN;
export const AbstractChainedBatch: ChainedBatchConstructor & ChainedBatch;
export function isLevelDOWN(db: any): boolean;
interface AbstractLevelDOWN<K=any, V=any, O=any, PO=any, GO=any, DO=any, IO=any, BO=any> {
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<K, V, BO>;
batch(array: Batch<K, V>[], callback: (err: any) => any);
batch(array: Batch<K, V>[], options: BO, callback: (err: any) => any);

iterator(options?: IO & AbstractIteratorOptions<K>): AbstractIterator<K, V>;

approximateSize(start: K, end: K, cb: (err: any, size: number) => void): void;

[index: string]: any;
}

interface AbstractLevelDOWNConstructor {
new <K=any, V=any, O=any, PO=any, GO=any, DO=any, IO=any, BO=any>(location: string): AbstractLevelDOWN<
K, V, O, PO, GO, DO, IO, BO>;
<K=any, V=any, O=any, PO=any, GO=any, DO=any, IO=any, BO=any>(location: string): AbstractLevelDOWN<
K, V, O, PO, GO, DO, IO, BO>;
}

export interface AbstractIteratorOptions<K=any> {
gt?: K;
gte?: K;
lt?: K;
lte?: K;
reverse?: boolean;
limit?: number;
keys?: boolean;
values?: boolean;
}

export type Batch<K=any, V=any> = PutBatch<K, V> | DelBatch<K>

export interface PutBatch<K=any, V=any> {
type: 'put',
key: K,
value: V
}

export interface DelBatch<K=any, V=any> {
type: 'del',
key: K
}

interface AbstractIterator<K=any, V=any> {
next(callback: (err: any, key: K, value: V) => void): void;
end(callback: (err: any) => void): void;
}

interface AbstractIteratorConstructor {
new <K=any, V=any>(db: any): AbstractIterator<K, V>;
<K=any, V=any>(db: any): AbstractIterator<K, V>;
}

interface AbstractChainedBatch<K=any, V=any, BO=any> 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 <K, V, BO>(db: any): AbstractChainedBatch<K, V, BO>;
<K, V, BO>(db: any): AbstractChainedBatch<K, V, BO>;
}

export = Abstract;
export const AbstractLevelDOWN: AbstractLevelDOWNConstructor
export const AbstractIterator: AbstractIteratorConstructor
export const AbstractChainedBatch: AbstractChainedBatchConstructor
export function isLevelDOWN(db: any): boolean;

0 comments on commit a71072b

Please sign in to comment.