add types for 'level-js', add def to 'levelup' (#36182)

This commit is contained in:
Daniel Byrne
2019-06-16 00:02:45 -07:00
committed by Ron Buckton
parent fb092f1628
commit ccb13aa66b
5 changed files with 80 additions and 2 deletions
+27
View File
@@ -0,0 +1,27 @@
// Type definitions for level-js 4.0
// Project: https://github.com/Level/level-js
// Definitions by: Daniel Byrne <https://github.com/danwbyrne>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import { AbstractLevelDOWN, AbstractOptions } from 'abstract-leveldown';
export interface Level extends AbstractLevelDOWN {
readonly location: string;
readonly prefix: string;
readonly version: string | number;
destroy(location: string, cb: (err: Error | undefined) => void): void;
destroy(location: string, prefix: string, cb: (err: Error | undefined) => void): void;
}
export interface LevelOptions {
readonly prefix?: string;
readonly version?: string | number;
}
export interface LevelConstructor {
new (location: string, options?: LevelOptions): Level;
(location: string, options?: LevelOptions): Level;
}
export const Level: LevelConstructor;
+24
View File
@@ -0,0 +1,24 @@
/// <reference types="node" />
import { Level } from 'level-js';
const db = Level('bigData');
const dbClass = new Level('bigData');
db.put('hello', Buffer.from('world'), (err) => {
if (err) throw err;
db.get('hello', (err, value) => {
if (err) throw err;
console.log(value.toString());
});
});
db.location;
db.prefix;
db.version;
db.destroy('bigData', (error) => console.log(error));
db.iterator();
db.iterator({keyAsBuffer: false});
db.createReadStream({gt: new Date('2019-01-01')});
+23
View File
@@ -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-js-tests.ts"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}
+3 -2
View File
@@ -8,7 +8,7 @@
/// <reference types="node" />
import { EventEmitter } from 'events';
import { AbstractLevelDOWN, AbstractIteratorOptions, AbstractBatch, ErrorCallback, AbstractOptions, ErrorValueCallback, AbstractGetOptions } from 'abstract-leveldown';
import { AbstractLevelDOWN, AbstractIteratorOptions, AbstractBatch, ErrorCallback, AbstractOptions, ErrorValueCallback, AbstractGetOptions, AbstractIterator } from 'abstract-leveldown';
type LevelUpPut<K, V, O> =
((key: K, value: V, callback: ErrorCallback) => void) &
@@ -45,7 +45,7 @@ type InferDBDel<DB> =
LevelUpDel<K, O> :
LevelUpDel<any, AbstractOptions>;
export interface LevelUp<DB = AbstractLevelDOWN> extends EventEmitter {
export interface LevelUp<DB = AbstractLevelDOWN, Iterator = AbstractIterator<any, any>> extends EventEmitter {
open(): Promise<void>;
open(callback?: ErrorCallback): void;
close(): Promise<void>;
@@ -60,6 +60,7 @@ export interface LevelUp<DB = AbstractLevelDOWN> extends EventEmitter {
batch(array: AbstractBatch[], callback: (err?: any) => any): void;
batch(): LevelUpChain;
iterator(options?: AbstractIteratorOptions): Iterator;
isOpen(): boolean;
isClosed(): boolean;