diff --git a/lowdb/index.d.ts b/lowdb/index.d.ts new file mode 100644 index 0000000000..ddd20e89ed --- /dev/null +++ b/lowdb/index.d.ts @@ -0,0 +1,536 @@ +declare module 'lowdb' { + interface PromiseLike { + + /** + * Attaches callbacks for the resolution and/or rejection of the Promise. + * @param onfulfilled The callback to execute when the Promise is resolved. + * @param onrejected The callback to execute when the Promise is rejected. + * @returns A Promise for the completion of which ever callback is executed. + */ + then(onfulfilled?: (value: T) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): PromiseLike; + then(onfulfilled?: (value: T) => TResult | PromiseLike, onrejected?: (reason: any) => void): PromiseLike; + } + + interface StringRepresentable { + toString(): string; + } + + interface List { + [index: number]: T; + length: number; + } + + interface Dictionary { + [index: string]: T; + } + + interface DictionaryIterator { + (value: T, key?: string, collection?: Dictionary): TResult; + } + + interface ListIterator { + (value: T, index: number, collection: List): TResult; + } + + interface StringIterator { + (char: string, index?: number, string?: string): TResult; + } + + interface MixinOptions { + chain?: boolean; + } + + interface LoDashWrapper { + + /** + * @see _.has + */ + has(path: StringRepresentable | StringRepresentable[]): LoDashWrapper; + + /** + * @see _.hasIn + */ + hasIn(path: StringRepresentable | StringRepresentable[]): LoDashWrapper; + + /** + * @see _.assign + */ + assign( + source: TSource + ): LoDashWrapper; + + /** + * @see _.assign + */ + assign( + source1: TSource1, + source2: TSource2 + ): LoDashWrapper; + + /** + * @see _.assign + */ + assign( + source1: TSource1, + source2: TSource2, + source3: TSource3 + ): LoDashWrapper; + + /** + * @see _.assign + */ + assign( + source1: TSource1, + source2: TSource2, + source3: TSource3, + source4: TSource4 + ): LoDashWrapper; + + /** + * @see _.assign + */ + assign(): LoDashWrapper; + + /** + * @see _.assign + */ + assign(...otherArgs: any[]): LoDashWrapper; + + /** + * @see _.cloneDeep + */ + cloneDeep(): LoDashWrapper; + + /** + * @see _.cloneDeep + */ + cloneDeep(): LoDashWrapper; + + /** + * @see _.cloneDeep + */ + cloneDeepWith(customizer: (value: any) => any): LoDashWrapper[]; + + /** + * @see _.cloneDeep + */ + cloneDeepWith(customizer: (value: any) => any): LoDashWrapper; + + /** + * @see _.defaults + */ + defaults( + source1: S1, + ...sources: {}[] + ): LoDashWrapper; + + /** + * @see _.defaults + */ + defaults( + source1: S1, + source2: S2, + ...sources: {}[] + ): LoDashWrapper; + + /** + * @see _.defaults + */ + defaults( + source1: S1, + source2: S2, + source3: S3, + ...sources: {}[] + ): LoDashWrapper; + + /** + * @see _.defaults + */ + defaults( + source1: S1, + source2: S2, + source3: S3, + source4: S4, + ...sources: {}[] + ): LoDashWrapper; + + /** + * @see _.defaults + */ + defaults(): LoDashWrapper; + + /** + * @see _.defaults + */ + defaults(...sources: {}[]): LoDashWrapper; + + /** + * @see _.get + */ + get(object: Object, + path: string | number | boolean | Array, + defaultValue?: TResult + ): LoDashWrapper; + + /** + * @see _.get + */ + get(path: string | number | boolean | Array, + defaultValue?: TResult + ): LoDashWrapper; + + + /** + * @see _.mixin + */ + mixin( + source: Dictionary, + options?: MixinOptions + ): LoDashWrapper; + + /** + * @see _.mixin + */ + mixin( + options?: MixinOptions + ): LoDashWrapper; + + /** + * @see _.set + */ + set( + path: StringRepresentable | StringRepresentable[], + value: any + ): LoDashWrapper; + + /** + * @see _.set + */ + set( + path: StringRepresentable | StringRepresentable[], + value: V + ): LoDashWrapper; + + /** + * @see _.find + */ + find( + predicate?: ListIterator, + thisArg?: any + ): LoDashWrapper; + + /** + * @see _.find + */ + find( + predicate?: string, + thisArg?: any + ): LoDashWrapper; + + /** + * @see _.find + */ + find( + predicate?: TObject + ): LoDashWrapper; + + /** + * @see _.find + */ + filter( + predicate?: TObject + ): LoDashWrapper; + + /** + * @see _.filter + */ + filter( + predicate?: ListIterator, + thisArg?: any + ): LoDashWrapper; + + /** + * @see _.filter + */ + filter( + predicate: string, + thisArg?: any + ): LoDashWrapper; + + /** + * @see _.filter + */ + filter( + predicate: ListIterator | DictionaryIterator, + thisArg?: any + ): LoDashWrapper; + + /** + * @see _.filter + */ + filter( + predicate?: StringIterator, + thisArg?: any + ): LoDashWrapper; + + /** + * @see _.filter + */ + filter(predicate: W): LoDashWrapper; + /** + * @see _.map + */ + map( + iteratee?: ListIterator, + thisArg?: any + ): LoDashWrapper; + + /** + * @see _.map + */ + map( + iteratee?: string + ): LoDashWrapper; + + /** + * @see _.map + */ + map( + iteratee?: TObject + ): LoDashWrapper; + /** + * @see _.map + */ + map( + iteratee?: ListIterator | DictionaryIterator, + thisArg?: any + ): LoDashWrapper; + + /** + * @see _.range + */ + range( + end?: number, + step?: number + ): LoDashWrapper; + + /** + * @see _.rangeRight + */ + rangeRight( + end?: number, + step?: number + ): LoDashWrapper; + + /** + * @see _.remove + */ + remove( + predicate?: ListIterator, + thisArg?: any + ): LoDashWrapper; + + /** + * @see _.remove + */ + remove( + predicate?: string, + thisArg?: any + ): LoDashWrapper; + + /** + * @see _.remove + */ + remove( + predicate?: W + ): LoDashWrapper; + + /** + * @see _.sortBy + */ + sortBy( + iteratee?: ListIterator + ): LoDashWrapper; + + /** + * @see _.sortBy + */ + sortBy(iteratee: string): LoDashWrapper; + + /** + * @see _.sortBy + */ + sortBy(whereValue: W): LoDashWrapper; + + /** + * @see _.sortBy + */ + sortBy(): LoDashWrapper; + + /** + * @see _.sortBy + */ + sortBy(...iteratees: (ListIterator | Object | string)[]): LoDashWrapper; + + /** + * @see _.sortBy + */ + sortBy(iteratees: (ListIterator | string | Object)[]): LoDashWrapper; + + /** + * @see _.slice + */ + slice( + start?: number, + end?: number + ): LoDashWrapper; + + /** + * @see _.size + */ + size(): LoDashWrapper; + + /** + * @see _.take + */ + take(n?: number): LoDashWrapper; + + /** + * @see _.times + */ + times( + iteratee: (num: number) => TResult + ): LoDashWrapper; + + /** + * @see _.times + */ + times(): LoDashWrapper; + + /** + * @see _.uniqueId + */ + uniqueId(): LoDashWrapper; + + value(): T; + + pop(): T; + push(...items: T[]): LoDashWrapper; + shift(): T; + sort(compareFn?: (a: T, b: T) => number): LoDashWrapper; + splice(start: number): LoDashWrapper; + splice(start: number, deleteCount: number, ...items: any[]): LoDashWrapper; + unshift(...items: T[]): LoDashWrapper; + } + + interface Storage { + /** + * Reads the database. + * + * @param source The source location. + * @param deserialize The deserialize function to apply. + * @return Returns a promise with the deserialized db object. + */ + read?(source: string, deserialize: any): PromiseLike + /** + * Reads the database. + * + * @param source The source location. + * @param deserialize The deserialize function to apply. + * @return Returns the deserialized db object. + */ + read?(source: string, deserialize: any): Object + /** + * Writes to the database. + * + * @param destination The destination location. + * @param obj The object to write. + * @param serialize The serialize function to apply. + */ + write?(destination: string, obj: any, serialize: any): void + /** + * Writes to the database. + * + * @param destination The destination location. + * @param obj The object to write. + * @param serialize The serialize function to apply. + */ + write?(destination: string, obj: any, serialize: any): PromiseLike + } + + interface Format { + /** + * Writes to the database. + * + * @param obj The object to serialize. + * @return Returns the serialized object string. + */ + serialize(obj: Object): string + /** + * Writes to the database. + * + * @param data The object to deserialize. + * @return Returns the deserialized object. + */ + deserialize(data: string): Object + } + + interface Options { + /** + * The custom "storage" object. + */ + storage?: Storage + /** + * The custom "format" object. + */ + format?: Format + /** + * The flag to automatically persist changes. + */ + writeOnChange?: boolean + } + + export interface Low extends LoDashWrapper, Format { + /** + * Access current database state. + * Returns Returns the database state. + */ + getState(): Object + /** + * Drop or reset database state. + * @param newState New state of the database + */ + setState(newState: Object): void + /** + * Persist database. + * @param source The source location. + */ + write(source: string): void + /** + * Persist database. + * @param source The source location. + */ + write(source: string): PromiseLike + /** + * Read database. + * @param source The source location. + */ + read(source?: string): Object + /** + * Read database. + * @param source The source location. + */ + read(source?: string): PromiseLike + } + +// declare class lowdb { +// new (source?: string, opts?: Options): Low; +// (source?: string, opts?: Options) : Low; +// } + +// declare module "lowdb" { +// export = lowdb; +// } + +} + diff --git a/lowdb/lowdb-tests.ts b/lowdb/lowdb-tests.ts new file mode 100644 index 0000000000..d656c63b62 --- /dev/null +++ b/lowdb/lowdb-tests.ts @@ -0,0 +1,12 @@ +import Lowdb = require('lowdb'); + +Lowdb +let db = new Lowdb(); + +db.defaults({ 'someObject': {}, 'anotherObject': {} }).value(); + +db.get('someObject').set('foo' , 'bar').value(); +db.get('anotherObject').set('foo' , 'bar').value(); +db.set('singleValue', 'foo').value(); + +console.log(db.getState()); diff --git a/lowdb/tsconfig.json b/lowdb/tsconfig.json new file mode 100644 index 0000000000..4a6104842c --- /dev/null +++ b/lowdb/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "lowdb-tests.ts" + ] +} \ No newline at end of file