From c8705c8dbc03d477fd193bd5dd5e68484639f220 Mon Sep 17 00:00:00 2001 From: Daniel Byrne Date: Sun, 26 Aug 2018 13:04:48 -0700 Subject: [PATCH] adds typings for the 'encoding-down' package --- types/encoding-down/encoding-down-tests.ts | 13 +++++ types/encoding-down/index.d.ts | 59 ++++++++++++++++++++++ types/encoding-down/tsconfig.json | 23 +++++++++ types/encoding-down/tslint.json | 1 + 4 files changed, 96 insertions(+) create mode 100644 types/encoding-down/encoding-down-tests.ts create mode 100644 types/encoding-down/index.d.ts create mode 100644 types/encoding-down/tsconfig.json create mode 100644 types/encoding-down/tslint.json diff --git a/types/encoding-down/encoding-down-tests.ts b/types/encoding-down/encoding-down-tests.ts new file mode 100644 index 0000000000..c541522317 --- /dev/null +++ b/types/encoding-down/encoding-down-tests.ts @@ -0,0 +1,13 @@ +import { AbstractLevelDOWN } from 'abstract-leveldown'; +import EncodingDOWN from 'encoding-down'; + +const test = (encoding: EncodingDOWN) => { + encoding.put("key", "value", (err?: Error) => { }); + encoding.put(1, "value", { something: true }, (err?: Error) => { }); + + encoding.get("key", (err?: Error) => { }); + encoding.get(1, { something: true }, (err: Error | undefined, value: any) => { }); +}; + +// $ExpectType void +test(new EncodingDOWN(new AbstractLevelDOWN("here"))); diff --git a/types/encoding-down/index.d.ts b/types/encoding-down/index.d.ts new file mode 100644 index 0000000000..d25ff11f2c --- /dev/null +++ b/types/encoding-down/index.d.ts @@ -0,0 +1,59 @@ +// Type definitions for encoding-down 5.0 +// Project: https://github.com/Level/encoding-down +// Definitions by: Meirion Hughes +// Daniel Byrne +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import { + AbstractLevelDOWN, + AbstractIteratorOptions, + AbstractIterator, + AbstractOpenOptions, + AbstractGetOptions, + ErrorCallback, + ErrorValueCallback, + AbstractChainedBatch, + AbstractBatch, + AbstractOptions +} from 'abstract-leveldown'; + +import { CodecOptions, CodecEncoder } from 'level-codec'; + +interface EncodingDown extends AbstractLevelDOWN { + get(key: K, cb: ErrorValueCallback): void; + get(key: K, options: EncodingDown.GetOptions, cb: ErrorValueCallback): void; + + put(key: K, value: V, cb: ErrorCallback): void; + put(key: K, value: V, options: EncodingDown.PutOptions, cb: ErrorCallback): void; + + del(key: K, cb: ErrorCallback): void; + del(key: K, options: EncodingDown.DelOptions, cb: ErrorCallback): void; + + batch(): EncodingDown.ChainedBatch; + batch(array: AbstractBatch[], cb: ErrorCallback): EncodingDown.ChainedBatch; + batch(array: AbstractBatch[], options: EncodingDown.BatchOptions, cb: ErrorCallback): EncodingDown.ChainedBatch; + + iterator(options?: EncodingDown.IteratorOptions): AbstractIterator; +} + +declare namespace EncodingDown { + interface GetOptions extends AbstractGetOptions, CodecOptions {} + interface PutOptions extends AbstractOptions, CodecOptions {} + interface DelOptions extends AbstractOptions, CodecOptions {} + interface BatchOptions extends AbstractOptions, CodecOptions {} + interface IteratorOptions extends AbstractIteratorOptions, CodecOptions {} + interface ChainedBatch extends AbstractChainedBatch { + write(cb: any): any; + write(options: CodecOptions & AbstractOptions, cb: any): any; + } + interface Constructor { + // tslint:disable-next-line:no-unnecessary-generics + (db: AbstractLevelDOWN, options?: CodecOptions): EncodingDown; + // tslint:disable-next-line:no-unnecessary-generics + new (db: AbstractLevelDOWN, options?: CodecOptions): EncodingDown; + } +} + +declare const EncodingDown: EncodingDown.Constructor; +export default EncodingDown; diff --git a/types/encoding-down/tsconfig.json b/types/encoding-down/tsconfig.json new file mode 100644 index 0000000000..d95d49b5c7 --- /dev/null +++ b/types/encoding-down/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "encoding-down-tests.ts" + ] +} \ No newline at end of file diff --git a/types/encoding-down/tslint.json b/types/encoding-down/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/encoding-down/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }