diff --git a/types/level-codec/index.d.ts b/types/level-codec/index.d.ts new file mode 100644 index 0000000000..a106350215 --- /dev/null +++ b/types/level-codec/index.d.ts @@ -0,0 +1,32 @@ +// Type definitions for level-codec 9.0 +// Project: https://github.com/Level/codec +// Definitions by: Daniel Byrne +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface CodecEncoder { + encode: (val: any) => any; + decode: (val: any) => any; + buffer: boolean; + type: string; +} +export interface CodecOptions { + keyEncoding?: string | CodecEncoder; + valueEncoding?: string | CodecEncoder; +} +export interface Codec { + encodeKey(key: any, opts?: CodecOptions, batchOpts?: CodecOptions): any; + encodeValue(value: any, opts?: CodecOptions, batchOpts?: CodecOptions): any; + decodeKey(key: any, opts?: CodecOptions): any; + decodeValue(value: any, opts?: CodecOptions): any; + encodeBatch(ops: any, opts?: CodecOptions): any; + encodeLtgt(ltgt: any): any; + createStreamDecoder(opts: CodecOptions): any; + keyAsBuffer(opts?: CodecOptions): any; + valueAsBuffer(opts?: CodecOptions): any; +} +export interface CodecConstructor { + new (options?: CodecOptions): Codec; + (options?: CodecOptions): Codec; +} + +export const Codec: CodecConstructor; diff --git a/types/level-codec/level-codec-tests.ts b/types/level-codec/level-codec-tests.ts new file mode 100644 index 0000000000..371966844f --- /dev/null +++ b/types/level-codec/level-codec-tests.ts @@ -0,0 +1,12 @@ +import { Codec } from "level-codec"; + +const test = (codec: Codec) => { + return codec.keyAsBuffer(); +}; + +test(new Codec({ keyEncoding: "hex" })); +test(new Codec()); + +// new not needed +test(Codec({ keyEncoding: "hex" })); +test(Codec()); diff --git a/types/level-codec/tsconfig.json b/types/level-codec/tsconfig.json new file mode 100644 index 0000000000..0381e4eb12 --- /dev/null +++ b/types/level-codec/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", + "level-codec-tests.ts" + ] +} diff --git a/types/level-codec/tslint.json b/types/level-codec/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/level-codec/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }