From 9e2863ed9cd54d623dd30512afa6a3858334a666 Mon Sep 17 00:00:00 2001 From: Daniel Byrne Date: Mon, 17 Sep 2018 11:20:05 -0700 Subject: [PATCH] adds typings for version 4.0 of the 'leveldown' package --- types/leveldown/v4/index.d.ts | 95 +++++++++++++++++++++++++++ types/leveldown/v4/leveldown-tests.ts | 19 ++++++ types/leveldown/v4/tsconfig.json | 29 ++++++++ types/leveldown/v4/tslint.json | 3 + 4 files changed, 146 insertions(+) create mode 100644 types/leveldown/v4/index.d.ts create mode 100644 types/leveldown/v4/leveldown-tests.ts create mode 100644 types/leveldown/v4/tsconfig.json create mode 100644 types/leveldown/v4/tslint.json diff --git a/types/leveldown/v4/index.d.ts b/types/leveldown/v4/index.d.ts new file mode 100644 index 0000000000..ae45f2da69 --- /dev/null +++ b/types/leveldown/v4/index.d.ts @@ -0,0 +1,95 @@ +// Type definitions for leveldown 4.0 +// Project: https://github.com/Level/leveldown +// 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'; + +export type Bytes = string | Buffer; +export type ErrorSizeCallback = (err: Error | undefined, size: number) => void; + +export interface LevelDown extends AbstractLevelDOWN { + open(cb: ErrorCallback): void; + open(options: LevelDownOpenOptions, cb: ErrorCallback): void; + + get(key: Bytes, cb: ErrorValueCallback): void; + get(key: Bytes, options: LevelDownGetOptions, cb: ErrorValueCallback): void; + + put(key: Bytes, value: Bytes, cb: ErrorCallback): void; + put(key: Bytes, value: Bytes, options: LevelDownPutOptions, cb: ErrorCallback): void; + + del(key: Bytes, cb: ErrorCallback): void; + del(key: Bytes, options: LevelDownDelOptions, cb: ErrorCallback): void; + + batch(): AbstractChainedBatch; + batch(array: AbstractBatch[], cb: ErrorCallback): AbstractChainedBatch; + batch(array: AbstractBatch[], options: LevelDownBatchOptions, cb: ErrorCallback): AbstractChainedBatch; + + approximateSize(start: Bytes, end: Bytes, cb: ErrorSizeCallback): void; + compactRange(start: Bytes, end: Bytes, cb: ErrorCallback): void; + getProperty(property: string): string; + destroy(location: string, cb: ErrorCallback): void; + repair(location: string, cb: ErrorCallback): void; + iterator(options?: LevelDownIteratorOptions): LevelDownIterator; +} + +interface LevelDownConstructor { + new(location: string): LevelDown; + (location: string): LevelDown; +} + +export interface LevelDownOpenOptions extends AbstractOpenOptions { + compression?: boolean; + cacheSize?: number; + writeBufferSize?: number; + blockSize?: number; + maxOpenFiles?: number; + blockRestartInterval?: number; + maxFileSize?: number; +} + +export interface LevelDownGetOptions extends AbstractGetOptions { + fillCache?: boolean; +} + +export interface LevelDownPutOptions extends AbstractOptions { + sync?: boolean; +} + +export interface LevelDownDelOptions extends AbstractOptions { + sync?: boolean; +} + +export interface LevelDownBatchOptions extends AbstractOptions { + sync?: boolean; +} + +export interface LevelDownIteratorOptions extends AbstractIteratorOptions { + fillCache?: boolean; +} + +export interface LevelDownIterator extends AbstractIterator { + seek(key: Bytes): void; + binding: any; + cache: any; + finished: any; + fastFuture: any; +} + +declare const LevelDOWN: LevelDownConstructor; +export default LevelDOWN; diff --git a/types/leveldown/v4/leveldown-tests.ts b/types/leveldown/v4/leveldown-tests.ts new file mode 100644 index 0000000000..8c38bae399 --- /dev/null +++ b/types/leveldown/v4/leveldown-tests.ts @@ -0,0 +1,19 @@ +import LevelDOWN from 'leveldown'; + +// can use new, or not. +const a = new LevelDOWN("./tmp/leveldown"); +const b = LevelDOWN("./tmp/leveldown"); + +const down = new LevelDOWN("./tmp/leveldown"); + +down.open(() => { + down.put("key", "value", (err?) => { }); + down.put(Buffer.from([1]), "value", { something: true }, (err?) => { }); + + down.get("key", (err?) => { }); + down.get(Buffer.from([1]), { something: true }, (err: Error | undefined, value: any) => { }); + + down.close(() => { + // do nothing + }); +}); diff --git a/types/leveldown/v4/tsconfig.json b/types/leveldown/v4/tsconfig.json new file mode 100644 index 0000000000..018e7c53d6 --- /dev/null +++ b/types/leveldown/v4/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "types": [], + "paths": { + "leveldown": [ + "leveldown/v4" + ], + "leveldown/*": [ + "leveldown/v4/*" + ] + }, + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "leveldown-tests.ts" + ] +} \ No newline at end of file diff --git a/types/leveldown/v4/tslint.json b/types/leveldown/v4/tslint.json new file mode 100644 index 0000000000..d88586e5bd --- /dev/null +++ b/types/leveldown/v4/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}