mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
Merge pull request #28956 from danwbyrne/leveldown
type definitions for v3/4 of 'LevelUp'/'LevelDown' packages.
This commit is contained in:
@@ -13,6 +13,14 @@
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"levelup": [
|
||||
"levelup/v1"
|
||||
],
|
||||
"leveldown": [
|
||||
"leveldown/v1"
|
||||
]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
@@ -20,4 +28,4 @@
|
||||
"index.d.ts",
|
||||
"level-sublevel-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+70
-123
@@ -1,148 +1,95 @@
|
||||
// Type definitions for LevelDown 1.7
|
||||
// Project: https://github.com/level/leveldown
|
||||
// Definitions by: Thiago de Arruda <https://github.com/tarruda>
|
||||
// Linus Unnebäck <https://github.com/LinusU>
|
||||
// Type definitions for leveldown 4.0
|
||||
// Project: https://github.com/Level/leveldown
|
||||
// Definitions by: Meirion Hughes <https://github.com/MeirionHughes>
|
||||
// Daniel Byrne <https://github.com/danwbyrne>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
export = leveldown;
|
||||
import {
|
||||
AbstractLevelDOWN,
|
||||
AbstractIteratorOptions,
|
||||
AbstractIterator,
|
||||
AbstractOpenOptions,
|
||||
AbstractGetOptions,
|
||||
ErrorCallback,
|
||||
ErrorValueCallback,
|
||||
AbstractChainedBatch,
|
||||
AbstractBatch,
|
||||
AbstractOptions
|
||||
} from 'abstract-leveldown';
|
||||
|
||||
declare var leveldown: leveldown.Constructor;
|
||||
export type Bytes = string | Buffer;
|
||||
export type ErrorSizeCallback = (err: Error | undefined, size: number) => void;
|
||||
|
||||
declare namespace leveldown {
|
||||
type Bytes = string | Buffer;
|
||||
type ErrCallback = (error: any) => void;
|
||||
type ErrNumberCallback = (error: any, value: number) => void;
|
||||
type ErrBufferCallback = (error: any, value: Buffer) => void;
|
||||
type ErrStringCallback = (error: any, value: string) => void;
|
||||
type KeyAsStringCallback = (error: any, key: string, value: Buffer) => void;
|
||||
type ValueAsStringCallback = (error: any, key: Buffer, value: string) => void;
|
||||
type KeyAndValueAsStringCallback = (error: any, key: string, value: string) => void;
|
||||
type KeyAndValueAsBufferCallback = (error: any, key: Buffer, value: Buffer) => void;
|
||||
export interface LevelDown extends AbstractLevelDOWN<Bytes, Bytes> {
|
||||
open(cb: ErrorCallback): void;
|
||||
open(options: LevelDownOpenOptions, cb: ErrorCallback): void;
|
||||
|
||||
interface PutBatch {
|
||||
type: "put";
|
||||
key: Bytes;
|
||||
value: Bytes;
|
||||
get(key: Bytes, cb: ErrorValueCallback<Bytes>): void;
|
||||
get(key: Bytes, options: LevelDownGetOptions, cb: ErrorValueCallback<Bytes>): 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<Bytes, Bytes>;
|
||||
batch(array: AbstractBatch[], cb: ErrorCallback): AbstractChainedBatch<Bytes, Bytes>;
|
||||
batch(array: AbstractBatch[], options: LevelDownBatchOptions, cb: ErrorCallback): AbstractChainedBatch<Bytes, Bytes>;
|
||||
|
||||
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 DelBatch {
|
||||
type: "del";
|
||||
key: Bytes;
|
||||
interface LevelDownConstructor {
|
||||
new(location: string): LevelDown;
|
||||
(location: string): LevelDown;
|
||||
}
|
||||
|
||||
type Batch = PutBatch | DelBatch;
|
||||
|
||||
interface OpenOptions {
|
||||
createIfMissing?: boolean;
|
||||
errorIfExists?: boolean;
|
||||
compression?: boolean;
|
||||
cacheSize?: number;
|
||||
export interface LevelDownOpenOptions extends AbstractOpenOptions {
|
||||
compression?: boolean;
|
||||
cacheSize?: number;
|
||||
writeBufferSize?: number;
|
||||
blockSize?: number;
|
||||
maxOpenFiles?: number;
|
||||
blockRestartInterval?: number;
|
||||
maxFileSize?: number;
|
||||
}
|
||||
|
||||
interface OpenAdvancedOptions extends OpenOptions {
|
||||
writeBufferSize?: number;
|
||||
blockSize?: number;
|
||||
maxOpenFiles?: number;
|
||||
blockRestartInterval?: number;
|
||||
maxFileSize?: number;
|
||||
export interface LevelDownGetOptions extends AbstractGetOptions {
|
||||
fillCache?: boolean;
|
||||
}
|
||||
|
||||
interface WriteOptions {
|
||||
sync?: boolean;
|
||||
export interface LevelDownPutOptions extends AbstractOptions {
|
||||
sync?: boolean;
|
||||
}
|
||||
|
||||
interface ReadOptions {
|
||||
fillCache?: boolean;
|
||||
export interface LevelDownDelOptions extends AbstractOptions {
|
||||
sync?: boolean;
|
||||
}
|
||||
|
||||
interface BufferReadOptions extends ReadOptions {
|
||||
asBuffer?: true;
|
||||
export interface LevelDownBatchOptions extends AbstractOptions {
|
||||
sync?: boolean;
|
||||
}
|
||||
|
||||
interface StringReadOptions extends ReadOptions {
|
||||
asBuffer: false;
|
||||
export interface LevelDownIteratorOptions extends AbstractIteratorOptions<Bytes> {
|
||||
fillCache?: boolean;
|
||||
}
|
||||
|
||||
interface IteratorOptions {
|
||||
gt?: Bytes;
|
||||
lt?: Bytes;
|
||||
gte?: Bytes;
|
||||
lte?: Bytes;
|
||||
reverse?: boolean;
|
||||
keys?: boolean;
|
||||
values?: boolean;
|
||||
limit?: number;
|
||||
fillCache?: boolean;
|
||||
export interface LevelDownIterator extends AbstractIterator<Bytes, Bytes> {
|
||||
seek(key: Bytes): void;
|
||||
binding: any;
|
||||
cache: any;
|
||||
finished: any;
|
||||
fastFuture: any;
|
||||
}
|
||||
|
||||
interface KeyAsStringIteratorOptions extends IteratorOptions {
|
||||
keyAsBuffer: false;
|
||||
valueAsBuffer?: true;
|
||||
}
|
||||
|
||||
interface ValueAsStringIteratorOptions extends IteratorOptions {
|
||||
keyAsBuffer?: true;
|
||||
valueAsBuffer: false;
|
||||
}
|
||||
|
||||
interface KeyAndValueAsStringIteratorOptions extends IteratorOptions {
|
||||
keyAsBuffer: false;
|
||||
valueAsBuffer: false;
|
||||
}
|
||||
|
||||
interface KeyAndValueAsBufferIteratorOptions extends IteratorOptions {
|
||||
keyAsBuffer?: true;
|
||||
valueAsBuffer?: true;
|
||||
}
|
||||
|
||||
interface Iterator {
|
||||
seek(key: Bytes): void;
|
||||
end(callback: ErrCallback): void;
|
||||
}
|
||||
|
||||
interface KeyAsStringIterator extends Iterator {
|
||||
next(callback: KeyAsStringCallback): void;
|
||||
}
|
||||
|
||||
interface ValueAsStringIterator extends Iterator {
|
||||
next(callback: ValueAsStringCallback): void;
|
||||
}
|
||||
|
||||
interface KeyAndValueAsStringIterator extends Iterator {
|
||||
next(callback: KeyAndValueAsStringCallback): void;
|
||||
}
|
||||
|
||||
interface KeyAndValueAsBufferIterator extends Iterator {
|
||||
next(callback: KeyAndValueAsBufferCallback): void;
|
||||
}
|
||||
|
||||
interface LevelDown {
|
||||
open(callback: ErrCallback): void;
|
||||
open(options: OpenOptions, callback: ErrCallback): void;
|
||||
close(callback?: ErrCallback): void;
|
||||
put(key: Bytes, value: Bytes, callback: ErrCallback): void;
|
||||
put(key: Bytes, value: Bytes, options: WriteOptions, callback: ErrCallback): void;
|
||||
get(key: Bytes, callback: ErrBufferCallback): void;
|
||||
get(key: Bytes, options: BufferReadOptions, callback: ErrBufferCallback): void;
|
||||
get(key: Bytes, options: StringReadOptions, callback: ErrStringCallback): void;
|
||||
del(key: Bytes, callback?: ErrCallback): void;
|
||||
del(key: Bytes, options: WriteOptions, callback?: ErrCallback): void;
|
||||
batch(operations: Batch[], callback?: ErrCallback): void;
|
||||
batch(operations: Batch[], options?: WriteOptions, callback?: ErrCallback): void;
|
||||
approximateSize(start: Bytes, end: Bytes, callback: ErrNumberCallback): void;
|
||||
compactRange(start: Bytes, end: Bytes, callback: ErrCallback): void;
|
||||
getProperty(property: string): string;
|
||||
iterator(options?: KeyAsStringIteratorOptions): KeyAsStringIterator;
|
||||
iterator(options?: ValueAsStringIteratorOptions): ValueAsStringIterator;
|
||||
iterator(options?: KeyAndValueAsStringIteratorOptions): KeyAndValueAsStringIterator;
|
||||
iterator(options?: KeyAndValueAsBufferIteratorOptions): KeyAndValueAsBufferIterator;
|
||||
}
|
||||
|
||||
interface Constructor {
|
||||
(location: string): LevelDown;
|
||||
destroy(location: string, callback: ErrCallback): void;
|
||||
repair(location: string, callback: ErrCallback): void;
|
||||
}
|
||||
}
|
||||
declare const LevelDOWN: LevelDownConstructor;
|
||||
export default LevelDOWN;
|
||||
|
||||
@@ -1,86 +1,19 @@
|
||||
import leveldown = require("leveldown");
|
||||
import LevelDOWN from 'leveldown';
|
||||
|
||||
const db = leveldown("db1");
|
||||
// can use new, or not.
|
||||
const a = new LevelDOWN("./tmp/leveldown");
|
||||
const b = LevelDOWN("./tmp/leveldown");
|
||||
|
||||
db.open((err) => {});
|
||||
db.open({createIfMissing: true}, (err) => {});
|
||||
const down = new LevelDOWN("./tmp/leveldown");
|
||||
|
||||
db.put("key", "value", (err) => {});
|
||||
db.put(Buffer.from("key"), Buffer.from("value"), (err) => {});
|
||||
db.put("key", "value", {sync: true}, (err) => {});
|
||||
down.open(() => {
|
||||
down.put("key", "value", (err?) => { });
|
||||
down.put(Buffer.from([1]), "value", { something: true }, (err?) => { });
|
||||
|
||||
db.get("key", {asBuffer: false}, (error, val) => {
|
||||
console.log(val.toUpperCase());
|
||||
down.get("key", (err?) => { });
|
||||
down.get(Buffer.from([1]), { something: true }, (err: Error | undefined, value: any) => { });
|
||||
|
||||
down.close(() => {
|
||||
// do nothing
|
||||
});
|
||||
});
|
||||
db.get("key", {fillCache: true}, (error, val) => {
|
||||
console.log(val.readUInt32BE(0));
|
||||
});
|
||||
db.get("key", (error, val) => {
|
||||
console.log(val.readUInt32BE(0));
|
||||
});
|
||||
|
||||
db.del("key");
|
||||
db.del("key", (error) => {});
|
||||
db.del("key", {sync: true}, (error) => {});
|
||||
|
||||
db.batch([{
|
||||
type: "put", key: "k", value: "v"
|
||||
}, {
|
||||
type: "del", key: "k"
|
||||
}], (error) => {});
|
||||
|
||||
const keyAsStringIterator = db.iterator({keyAsBuffer: false});
|
||||
keyAsStringIterator.next((err, k, v) => {
|
||||
console.log(k.toUpperCase());
|
||||
console.log(v.readUInt32BE(0));
|
||||
});
|
||||
|
||||
const valueAsStringIterator = db.iterator({valueAsBuffer: false});
|
||||
valueAsStringIterator.next((err, k, v) => {
|
||||
console.log(k.readUInt32BE(0));
|
||||
console.log(v.toUpperCase());
|
||||
});
|
||||
|
||||
const keyAndValueAsStringIterator = db.iterator({keyAsBuffer: false, valueAsBuffer: false});
|
||||
keyAndValueAsStringIterator.next((err, k, v) => {
|
||||
console.log(k.toUpperCase());
|
||||
console.log(v.toUpperCase());
|
||||
});
|
||||
|
||||
const keyAndValueAsBufferIterator1 = db.iterator({keyAsBuffer: true, valueAsBuffer: true});
|
||||
keyAndValueAsBufferIterator1.next((err, k, v) => {
|
||||
console.log(k.readUInt32BE(0));
|
||||
console.log(v.readUInt32BE(0));
|
||||
});
|
||||
|
||||
const keyAndValueAsBufferIterator2 = db.iterator({keyAsBuffer: true});
|
||||
keyAndValueAsBufferIterator2.next((err, k, v) => {
|
||||
console.log(k.readUInt32BE(0));
|
||||
console.log(v.readUInt32BE(0));
|
||||
});
|
||||
|
||||
const keyAndValueAsBufferIterator3 = db.iterator({valueAsBuffer: true});
|
||||
keyAndValueAsBufferIterator3.next((err, k, v) => {
|
||||
console.log(k.readUInt32BE(0));
|
||||
console.log(v.readUInt32BE(0));
|
||||
});
|
||||
|
||||
const keyAndValueAsBufferIterator4 = db.iterator({});
|
||||
keyAndValueAsBufferIterator4.next((err, k, v) => {
|
||||
console.log(k.readUInt32BE(0));
|
||||
console.log(v.readUInt32BE(0));
|
||||
});
|
||||
|
||||
keyAndValueAsBufferIterator4.seek("k");
|
||||
keyAndValueAsBufferIterator4.end((err) => {});
|
||||
|
||||
const s: string = db.getProperty("leveldb.stats");
|
||||
|
||||
db.approximateSize("k1", "k2", (err, size) => {
|
||||
console.log(size.toExponential());
|
||||
});
|
||||
|
||||
db.compactRange("k1", "k2", (err) => {});
|
||||
|
||||
leveldown.destroy("/path/to/db", (err) => {});
|
||||
leveldown.repair("/path/to/db", (err) => {});
|
||||
|
||||
@@ -20,4 +20,4 @@
|
||||
"index.d.ts",
|
||||
"leveldown-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
|
||||
Vendored
+148
@@ -0,0 +1,148 @@
|
||||
// Type definitions for leveldown 1.7
|
||||
// Project: https://github.com/level/leveldown
|
||||
// Definitions by: Thiago de Arruda <https://github.com/tarruda>
|
||||
// Linus Unnebäck <https://github.com/LinusU>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
export = leveldown;
|
||||
|
||||
declare var leveldown: leveldown.Constructor;
|
||||
|
||||
declare namespace leveldown {
|
||||
type Bytes = string | Buffer;
|
||||
type ErrCallback = (error: any) => void;
|
||||
type ErrNumberCallback = (error: any, value: number) => void;
|
||||
type ErrBufferCallback = (error: any, value: Buffer) => void;
|
||||
type ErrStringCallback = (error: any, value: string) => void;
|
||||
type KeyAsStringCallback = (error: any, key: string, value: Buffer) => void;
|
||||
type ValueAsStringCallback = (error: any, key: Buffer, value: string) => void;
|
||||
type KeyAndValueAsStringCallback = (error: any, key: string, value: string) => void;
|
||||
type KeyAndValueAsBufferCallback = (error: any, key: Buffer, value: Buffer) => void;
|
||||
|
||||
interface PutBatch {
|
||||
type: "put";
|
||||
key: Bytes;
|
||||
value: Bytes;
|
||||
}
|
||||
|
||||
interface DelBatch {
|
||||
type: "del";
|
||||
key: Bytes;
|
||||
}
|
||||
|
||||
type Batch = PutBatch | DelBatch;
|
||||
|
||||
interface OpenOptions {
|
||||
createIfMissing?: boolean;
|
||||
errorIfExists?: boolean;
|
||||
compression?: boolean;
|
||||
cacheSize?: number;
|
||||
}
|
||||
|
||||
interface OpenAdvancedOptions extends OpenOptions {
|
||||
writeBufferSize?: number;
|
||||
blockSize?: number;
|
||||
maxOpenFiles?: number;
|
||||
blockRestartInterval?: number;
|
||||
maxFileSize?: number;
|
||||
}
|
||||
|
||||
interface WriteOptions {
|
||||
sync?: boolean;
|
||||
}
|
||||
|
||||
interface ReadOptions {
|
||||
fillCache?: boolean;
|
||||
}
|
||||
|
||||
interface BufferReadOptions extends ReadOptions {
|
||||
asBuffer?: true;
|
||||
}
|
||||
|
||||
interface StringReadOptions extends ReadOptions {
|
||||
asBuffer: false;
|
||||
}
|
||||
|
||||
interface IteratorOptions {
|
||||
gt?: Bytes;
|
||||
lt?: Bytes;
|
||||
gte?: Bytes;
|
||||
lte?: Bytes;
|
||||
reverse?: boolean;
|
||||
keys?: boolean;
|
||||
values?: boolean;
|
||||
limit?: number;
|
||||
fillCache?: boolean;
|
||||
}
|
||||
|
||||
interface KeyAsStringIteratorOptions extends IteratorOptions {
|
||||
keyAsBuffer: false;
|
||||
valueAsBuffer?: true;
|
||||
}
|
||||
|
||||
interface ValueAsStringIteratorOptions extends IteratorOptions {
|
||||
keyAsBuffer?: true;
|
||||
valueAsBuffer: false;
|
||||
}
|
||||
|
||||
interface KeyAndValueAsStringIteratorOptions extends IteratorOptions {
|
||||
keyAsBuffer: false;
|
||||
valueAsBuffer: false;
|
||||
}
|
||||
|
||||
interface KeyAndValueAsBufferIteratorOptions extends IteratorOptions {
|
||||
keyAsBuffer?: true;
|
||||
valueAsBuffer?: true;
|
||||
}
|
||||
|
||||
interface Iterator {
|
||||
seek(key: Bytes): void;
|
||||
end(callback: ErrCallback): void;
|
||||
}
|
||||
|
||||
interface KeyAsStringIterator extends Iterator {
|
||||
next(callback: KeyAsStringCallback): void;
|
||||
}
|
||||
|
||||
interface ValueAsStringIterator extends Iterator {
|
||||
next(callback: ValueAsStringCallback): void;
|
||||
}
|
||||
|
||||
interface KeyAndValueAsStringIterator extends Iterator {
|
||||
next(callback: KeyAndValueAsStringCallback): void;
|
||||
}
|
||||
|
||||
interface KeyAndValueAsBufferIterator extends Iterator {
|
||||
next(callback: KeyAndValueAsBufferCallback): void;
|
||||
}
|
||||
|
||||
interface LevelDown {
|
||||
open(callback: ErrCallback): void;
|
||||
open(options: OpenOptions, callback: ErrCallback): void;
|
||||
close(callback?: ErrCallback): void;
|
||||
put(key: Bytes, value: Bytes, callback: ErrCallback): void;
|
||||
put(key: Bytes, value: Bytes, options: WriteOptions, callback: ErrCallback): void;
|
||||
get(key: Bytes, callback: ErrBufferCallback): void;
|
||||
get(key: Bytes, options: BufferReadOptions, callback: ErrBufferCallback): void;
|
||||
get(key: Bytes, options: StringReadOptions, callback: ErrStringCallback): void;
|
||||
del(key: Bytes, callback?: ErrCallback): void;
|
||||
del(key: Bytes, options: WriteOptions, callback?: ErrCallback): void;
|
||||
batch(operations: Batch[], callback?: ErrCallback): void;
|
||||
batch(operations: Batch[], options?: WriteOptions, callback?: ErrCallback): void;
|
||||
approximateSize(start: Bytes, end: Bytes, callback: ErrNumberCallback): void;
|
||||
compactRange(start: Bytes, end: Bytes, callback: ErrCallback): void;
|
||||
getProperty(property: string): string;
|
||||
iterator(options?: KeyAsStringIteratorOptions): KeyAsStringIterator;
|
||||
iterator(options?: ValueAsStringIteratorOptions): ValueAsStringIterator;
|
||||
iterator(options?: KeyAndValueAsStringIteratorOptions): KeyAndValueAsStringIterator;
|
||||
iterator(options?: KeyAndValueAsBufferIteratorOptions): KeyAndValueAsBufferIterator;
|
||||
}
|
||||
|
||||
interface Constructor {
|
||||
(location: string): LevelDown;
|
||||
destroy(location: string, callback: ErrCallback): void;
|
||||
repair(location: string, callback: ErrCallback): void;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import leveldown = require("leveldown");
|
||||
|
||||
const db = leveldown("db1");
|
||||
|
||||
db.open((err) => {});
|
||||
db.open({createIfMissing: true}, (err) => {});
|
||||
|
||||
db.put("key", "value", (err) => {});
|
||||
db.put(Buffer.from("key"), Buffer.from("value"), (err) => {});
|
||||
db.put("key", "value", {sync: true}, (err) => {});
|
||||
|
||||
db.get("key", {asBuffer: false}, (error, val) => {
|
||||
console.log(val.toUpperCase());
|
||||
});
|
||||
db.get("key", {fillCache: true}, (error, val) => {
|
||||
console.log(val.readUInt32BE(0));
|
||||
});
|
||||
db.get("key", (error, val) => {
|
||||
console.log(val.readUInt32BE(0));
|
||||
});
|
||||
|
||||
db.del("key");
|
||||
db.del("key", (error) => {});
|
||||
db.del("key", {sync: true}, (error) => {});
|
||||
|
||||
db.batch([{
|
||||
type: "put", key: "k", value: "v"
|
||||
}, {
|
||||
type: "del", key: "k"
|
||||
}], (error) => {});
|
||||
|
||||
const keyAsStringIterator = db.iterator({keyAsBuffer: false});
|
||||
keyAsStringIterator.next((err, k, v) => {
|
||||
console.log(k.toUpperCase());
|
||||
console.log(v.readUInt32BE(0));
|
||||
});
|
||||
|
||||
const valueAsStringIterator = db.iterator({valueAsBuffer: false});
|
||||
valueAsStringIterator.next((err, k, v) => {
|
||||
console.log(k.readUInt32BE(0));
|
||||
console.log(v.toUpperCase());
|
||||
});
|
||||
|
||||
const keyAndValueAsStringIterator = db.iterator({keyAsBuffer: false, valueAsBuffer: false});
|
||||
keyAndValueAsStringIterator.next((err, k, v) => {
|
||||
console.log(k.toUpperCase());
|
||||
console.log(v.toUpperCase());
|
||||
});
|
||||
|
||||
const keyAndValueAsBufferIterator1 = db.iterator({keyAsBuffer: true, valueAsBuffer: true});
|
||||
keyAndValueAsBufferIterator1.next((err, k, v) => {
|
||||
console.log(k.readUInt32BE(0));
|
||||
console.log(v.readUInt32BE(0));
|
||||
});
|
||||
|
||||
const keyAndValueAsBufferIterator2 = db.iterator({keyAsBuffer: true});
|
||||
keyAndValueAsBufferIterator2.next((err, k, v) => {
|
||||
console.log(k.readUInt32BE(0));
|
||||
console.log(v.readUInt32BE(0));
|
||||
});
|
||||
|
||||
const keyAndValueAsBufferIterator3 = db.iterator({valueAsBuffer: true});
|
||||
keyAndValueAsBufferIterator3.next((err, k, v) => {
|
||||
console.log(k.readUInt32BE(0));
|
||||
console.log(v.readUInt32BE(0));
|
||||
});
|
||||
|
||||
const keyAndValueAsBufferIterator4 = db.iterator({});
|
||||
keyAndValueAsBufferIterator4.next((err, k, v) => {
|
||||
console.log(k.readUInt32BE(0));
|
||||
console.log(v.readUInt32BE(0));
|
||||
});
|
||||
|
||||
keyAndValueAsBufferIterator4.seek("k");
|
||||
keyAndValueAsBufferIterator4.end((err) => {});
|
||||
|
||||
const s: string = db.getProperty("leveldb.stats");
|
||||
|
||||
db.approximateSize("k1", "k2", (err, size) => {
|
||||
console.log(size.toExponential());
|
||||
});
|
||||
|
||||
db.compactRange("k1", "k2", (err) => {});
|
||||
|
||||
leveldown.destroy("/path/to/db", (err) => {});
|
||||
leveldown.repair("/path/to/db", (err) => {});
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../../",
|
||||
"typeRoots": [
|
||||
"../../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"leveldown": [
|
||||
"leveldown/v1"
|
||||
],
|
||||
"leveldown/*": [
|
||||
"leveldown/v1/*"
|
||||
]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"leveldown-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Vendored
+100
-59
@@ -1,82 +1,123 @@
|
||||
// Type definitions for LevelUp
|
||||
// Type definitions for levelup 3.1
|
||||
// Project: https://github.com/Level/levelup
|
||||
// Definitions by: Bret Little <https://github.com/blittle>, Thiago de Arruda <https://github.com/tarruda>
|
||||
// Definitions by: Meirion Hughes <https://github.com/MeirionHughes>
|
||||
// Daniel Byrne <https://github.com/danwbyrne>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as leveldown from "leveldown";
|
||||
import { EventEmitter } from 'events';
|
||||
import { AbstractLevelDOWN, AbstractIteratorOptions, AbstractBatch, ErrorCallback, AbstractOptions, ErrorValueCallback, AbstractGetOptions } from 'abstract-leveldown';
|
||||
|
||||
export = levelup;
|
||||
type LevelUpPut<K, V, O> =
|
||||
((key: K, value: V, callback: ErrorCallback) => void) &
|
||||
((key: K, value: V, options: O, callback: ErrorCallback) => void) &
|
||||
((key: K, value: V, options?: O) => Promise<void>);
|
||||
|
||||
declare var levelup: levelup.LevelUpConstructor;
|
||||
type LevelUpGet<K, V, O> =
|
||||
((key: K, callback: ErrorValueCallback<V>) => void) &
|
||||
((key: K, options: O, callback: ErrorValueCallback<V>) => void) &
|
||||
((key: K, options?: O) => Promise<V>);
|
||||
|
||||
declare namespace levelup {
|
||||
type LevelUpDel<K, O> =
|
||||
((key: K, callback: ErrorCallback) => void) &
|
||||
((key: K, options: O, callback: ErrorCallback) => void) &
|
||||
((key: K, options?: O) => Promise<void>);
|
||||
|
||||
interface CustomEncoding {
|
||||
encode(val: any): Buffer| string;
|
||||
decode(val: Buffer | string): any;
|
||||
buffer: boolean;
|
||||
type: string;
|
||||
}
|
||||
type LevelUpBatch<K, O> =
|
||||
((key: K, callback: ErrorCallback) => void) &
|
||||
((key: K, options: O, callback: ErrorCallback) => void) &
|
||||
((key: K, options?: O) => Promise<void>);
|
||||
|
||||
type Encoding = string | CustomEncoding;
|
||||
type InferDBPut<DB> =
|
||||
DB extends { put: (key: infer K, value: infer V, options: infer O, cb: any) => void } ?
|
||||
LevelUpPut<K, V, O> :
|
||||
LevelUpPut<any, any, AbstractOptions>;
|
||||
|
||||
interface Batch {
|
||||
type: string;
|
||||
key: any;
|
||||
value?: any;
|
||||
keyEncoding?: Encoding;
|
||||
valueEncoding?: Encoding;
|
||||
}
|
||||
type InferDBGet<DB> =
|
||||
DB extends { get: (key: infer K, options: infer O, callback: ErrorValueCallback<infer V>) => void } ?
|
||||
LevelUpGet<K, V, O> :
|
||||
LevelUpGet<any, any, AbstractGetOptions>;
|
||||
|
||||
interface LevelUpBase<BatchType extends Batch> {
|
||||
open(callback ?: (error : any) => any): void;
|
||||
close(callback ?: (error : any) => any): void;
|
||||
put(key: any, value: any, callback ?: (error: any) => any): void;
|
||||
put(key: any, value: any, options?: { sync?: boolean }, callback ?: (error: any) => any): void;
|
||||
get(key: any, callback ?: (error: any, value: any) => any): void;
|
||||
type InferDBDel<DB> =
|
||||
DB extends { del: (key: infer K, options: infer O, callback: ErrorCallback) => void } ?
|
||||
LevelUpDel<K, O> :
|
||||
LevelUpDel<any, AbstractOptions>;
|
||||
|
||||
get(key: any, options ?: { keyEncoding?: Encoding; fillCache?: boolean }, callback ?: (error: any, value: any) => any): void;
|
||||
del(key: any, callback ?: (error: any) => any): void;
|
||||
del(key: any, options ?: { keyEncoding?: Encoding; sync?: boolean }, callback ?: (error: any) => any): void;
|
||||
export interface LevelUp<DB = AbstractLevelDOWN> extends EventEmitter {
|
||||
open(): Promise<void>;
|
||||
open(callback?: ErrorCallback): void;
|
||||
close(): Promise<void>;
|
||||
close(callback?: ErrorCallback): void;
|
||||
|
||||
put: InferDBPut<DB>;
|
||||
get: InferDBGet<DB>;
|
||||
del: InferDBDel<DB>;
|
||||
|
||||
batch(array: BatchType[], options?: { keyEncoding?: Encoding; valueEncoding?: Encoding; sync?: boolean }, callback?: (error?: any)=>any): void;
|
||||
batch(array: BatchType[], callback?: (error?: any)=>any): void;
|
||||
batch():LevelUpChain;
|
||||
isOpen():boolean;
|
||||
isClosed():boolean;
|
||||
createReadStream(options?: any): any;
|
||||
createKeyStream(options?: any): any;
|
||||
createValueStream(options?: any): any;
|
||||
createWriteStream(options?: any): any;
|
||||
destroy(location: string, callback?: Function): void;
|
||||
repair(location: string, callback?: Function): void;
|
||||
}
|
||||
batch(array: AbstractBatch[], options?: any): Promise<void>;
|
||||
batch(array: AbstractBatch[], options: any, callback: (err?: any) => any): void;
|
||||
batch(array: AbstractBatch[], callback: (err?: any) => any): void;
|
||||
|
||||
type LevelUp = LevelUpBase<Batch>
|
||||
batch(): LevelUpChain;
|
||||
|
||||
interface LevelUpChain {
|
||||
put(key: any, value: any): LevelUpChain;
|
||||
put(key: any, value: any, options?: { sync?: boolean }): LevelUpChain;
|
||||
del(key: any): LevelUpChain;
|
||||
del(key: any, options ?: { keyEncoding?: Encoding; sync?: boolean }): LevelUpChain;
|
||||
clear(): LevelUpChain;
|
||||
write(callback?: (error?: any)=>any) : LevelUpChain;
|
||||
}
|
||||
isOpen(): boolean;
|
||||
isClosed(): boolean;
|
||||
|
||||
interface levelupOptions {
|
||||
createIfMissing?: boolean;
|
||||
errorIfExists?: boolean;
|
||||
compression?: boolean;
|
||||
cacheSize?: number;
|
||||
keyEncoding?: Encoding;
|
||||
valueEncoding?: Encoding;
|
||||
db?: leveldown.Constructor;
|
||||
createReadStream(options?: AbstractIteratorOptions): NodeJS.ReadableStream;
|
||||
createKeyStream(options?: AbstractIteratorOptions): NodeJS.ReadableStream;
|
||||
createValueStream(options?: AbstractIteratorOptions): NodeJS.ReadableStream;
|
||||
|
||||
/*
|
||||
emitted when a new value is 'put'
|
||||
*/
|
||||
on(event: 'put', cb: (key: any, value: any) => void): this;
|
||||
/*
|
||||
emitted when a value is deleted
|
||||
*/
|
||||
on(event: 'del', cb: (key: any) => void): this;
|
||||
/*
|
||||
emitted when a batch operation has executed
|
||||
*/
|
||||
on(event: 'batch', cb: (ary: any[]) => void): this;
|
||||
/*
|
||||
emitted on given event
|
||||
*/
|
||||
on(event: 'open' | 'ready' | 'closed' | 'opening' | 'closing', cb: () => void): this;
|
||||
}
|
||||
|
||||
interface LevelUpConstructor {
|
||||
(hostname: string, options?: levelupOptions): LevelUp;
|
||||
<DB extends AbstractLevelDOWN = AbstractLevelDOWN>(
|
||||
db: DB,
|
||||
options: any,
|
||||
cb?: ErrorCallback): LevelUp<DB>;
|
||||
|
||||
<DB extends AbstractLevelDOWN = AbstractLevelDOWN>(
|
||||
db: DB,
|
||||
cb?: ErrorCallback): LevelUp<DB>;
|
||||
|
||||
new <DB extends AbstractLevelDOWN = AbstractLevelDOWN>(
|
||||
db: DB,
|
||||
options: any,
|
||||
cb?: ErrorCallback): LevelUp<DB>;
|
||||
|
||||
new <DB extends AbstractLevelDOWN = AbstractLevelDOWN>(
|
||||
db: DB,
|
||||
cb?: ErrorCallback): LevelUp<DB>;
|
||||
|
||||
errors: /*typeof levelerrors*/ any; // ? level-errors is not in DT
|
||||
}
|
||||
|
||||
export interface LevelUpChain<K = any, V = any> {
|
||||
readonly length: number;
|
||||
put(key: K, value: V): this;
|
||||
del(key: K): this;
|
||||
clear(): this;
|
||||
write(callback: ErrorCallback): this;
|
||||
write(): Promise<this>;
|
||||
}
|
||||
|
||||
export const errors: /*typeof levelerrors*/ any; // ? level-errors is not in DT
|
||||
|
||||
declare const LevelUp: LevelUpConstructor;
|
||||
export default LevelUp;
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
import levelup = require("levelup");
|
||||
|
||||
interface BufferEncoding {
|
||||
encode(val: any): Buffer;
|
||||
decode(val: Buffer): any;
|
||||
buffer: boolean;
|
||||
type: string;
|
||||
}
|
||||
import levelup from 'levelup';
|
||||
import { AbstractLevelDOWN } from 'abstract-leveldown';
|
||||
|
||||
interface StringEncoding {
|
||||
encode(val: any): string;
|
||||
@@ -14,50 +8,39 @@ interface StringEncoding {
|
||||
type: string;
|
||||
}
|
||||
|
||||
declare const bufferEncoding: BufferEncoding;
|
||||
declare const stringEncoding: StringEncoding;
|
||||
|
||||
var db1 = levelup("db1", {
|
||||
keyEncoding: bufferEncoding,
|
||||
valueEncoding: bufferEncoding
|
||||
});
|
||||
var db2 = levelup("db2", {
|
||||
const db = levelup(new AbstractLevelDOWN('here'), {
|
||||
keyEncoding: stringEncoding,
|
||||
valueEncoding: stringEncoding
|
||||
});
|
||||
|
||||
var db = levelup('./mydb')
|
||||
db.open();
|
||||
db.close();
|
||||
db.open((error)=> {
|
||||
|
||||
db.open((error) => {
|
||||
});
|
||||
|
||||
db.close((error)=> {
|
||||
|
||||
db.close((error) => {
|
||||
});
|
||||
|
||||
|
||||
db.put("key", {});
|
||||
db.put("key", {}, (error)=>{});
|
||||
db.put("key", {}, { sync: true}, (error)=>{});
|
||||
db.put("key", {}, (error) => {});
|
||||
db.put("key", {}, { sync: true}, (error) => {});
|
||||
|
||||
db.get("key", {keyEncoding: "json"}, (error, val) => {});
|
||||
db.get("key", {fillCache: true}, (error, val) => {});
|
||||
db.get("key", (error, val) => {});
|
||||
|
||||
db.del("key");
|
||||
db.del("key", (error)=>{});
|
||||
db.del("key", {keyEncoding: "json"}, (error)=>{});
|
||||
db.del("key", {sync: true}, (error)=>{});
|
||||
db.del("key", (error) => {});
|
||||
db.del("key", {keyEncoding: "json"}, (error) => {});
|
||||
db.del("key", {sync: true}, (error) => {});
|
||||
|
||||
db.batch([{
|
||||
type : 'put'
|
||||
, key : ([1, 2, 3])
|
||||
, value : { some: 'json' }
|
||||
, keyEncoding : 'binary'
|
||||
, valueEncoding : 'json'
|
||||
}], (error)=> {});
|
||||
}], (error: Error | undefined) => {});
|
||||
|
||||
db.batch()
|
||||
.del('father')
|
||||
@@ -65,20 +48,23 @@ db.batch()
|
||||
.put('dob', '16 February 1941')
|
||||
.put('spouse', 'Kim Young-sook')
|
||||
.put('occupation', 'Clown')
|
||||
.write(function () { console.log('Done!') })
|
||||
.write(() => { console.log('Done!'); });
|
||||
|
||||
// $ExpectType boolean
|
||||
db.isOpen();
|
||||
// $ExpectType boolean
|
||||
db.isClosed();
|
||||
|
||||
var open:boolean = db.isOpen();
|
||||
var closed:boolean = db.isClosed();
|
||||
db.createReadStream()
|
||||
.on('data', function (data: any) {
|
||||
console.log(data.key, '=', data.value)
|
||||
.on('data', (data: any) => {
|
||||
console.log(data.key, '=', data.value);
|
||||
})
|
||||
.on('error', function (err: any) {
|
||||
console.log('Oh my!', err)
|
||||
.on('error', (err: any) => {
|
||||
console.log('Oh my!', err);
|
||||
})
|
||||
.on('close', function () {
|
||||
console.log('Stream closed')
|
||||
})
|
||||
.on('end', function () {
|
||||
console.log('Stream closed')
|
||||
.on('close', () => {
|
||||
console.log('Stream closed');
|
||||
})
|
||||
.on('end', () => {
|
||||
console.log('Stream closed');
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
@@ -20,4 +20,4 @@
|
||||
"index.d.ts",
|
||||
"levelup-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,79 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
}
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
|
||||
Vendored
+82
@@ -0,0 +1,82 @@
|
||||
// Type definitions for levelup 1.0
|
||||
// Project: https://github.com/Level/levelup
|
||||
// Definitions by: Bret Little <https://github.com/blittle>, Thiago de Arruda <https://github.com/tarruda>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as leveldown from "leveldown";
|
||||
|
||||
export = levelup;
|
||||
|
||||
declare var levelup: levelup.LevelUpConstructor;
|
||||
|
||||
declare namespace levelup {
|
||||
|
||||
interface CustomEncoding {
|
||||
encode(val: any): Buffer| string;
|
||||
decode(val: Buffer | string): any;
|
||||
buffer: boolean;
|
||||
type: string;
|
||||
}
|
||||
|
||||
type Encoding = string | CustomEncoding;
|
||||
|
||||
interface Batch {
|
||||
type: string;
|
||||
key: any;
|
||||
value?: any;
|
||||
keyEncoding?: Encoding;
|
||||
valueEncoding?: Encoding;
|
||||
}
|
||||
|
||||
interface LevelUpBase<BatchType extends Batch> {
|
||||
open(callback ?: (error : any) => any): void;
|
||||
close(callback ?: (error : any) => any): void;
|
||||
put(key: any, value: any, callback ?: (error: any) => any): void;
|
||||
put(key: any, value: any, options?: { sync?: boolean }, callback ?: (error: any) => any): void;
|
||||
get(key: any, callback ?: (error: any, value: any) => any): void;
|
||||
|
||||
get(key: any, options ?: { keyEncoding?: Encoding; fillCache?: boolean }, callback ?: (error: any, value: any) => any): void;
|
||||
del(key: any, callback ?: (error: any) => any): void;
|
||||
del(key: any, options ?: { keyEncoding?: Encoding; sync?: boolean }, callback ?: (error: any) => any): void;
|
||||
|
||||
|
||||
batch(array: BatchType[], options?: { keyEncoding?: Encoding; valueEncoding?: Encoding; sync?: boolean }, callback?: (error?: any)=>any): void;
|
||||
batch(array: BatchType[], callback?: (error?: any)=>any): void;
|
||||
batch():LevelUpChain;
|
||||
isOpen():boolean;
|
||||
isClosed():boolean;
|
||||
createReadStream(options?: any): any;
|
||||
createKeyStream(options?: any): any;
|
||||
createValueStream(options?: any): any;
|
||||
createWriteStream(options?: any): any;
|
||||
destroy(location: string, callback?: Function): void;
|
||||
repair(location: string, callback?: Function): void;
|
||||
}
|
||||
|
||||
type LevelUp = LevelUpBase<Batch>
|
||||
|
||||
interface LevelUpChain {
|
||||
put(key: any, value: any): LevelUpChain;
|
||||
put(key: any, value: any, options?: { sync?: boolean }): LevelUpChain;
|
||||
del(key: any): LevelUpChain;
|
||||
del(key: any, options ?: { keyEncoding?: Encoding; sync?: boolean }): LevelUpChain;
|
||||
clear(): LevelUpChain;
|
||||
write(callback?: (error?: any)=>any) : LevelUpChain;
|
||||
}
|
||||
|
||||
interface levelupOptions {
|
||||
createIfMissing?: boolean;
|
||||
errorIfExists?: boolean;
|
||||
compression?: boolean;
|
||||
cacheSize?: number;
|
||||
keyEncoding?: Encoding;
|
||||
valueEncoding?: Encoding;
|
||||
db?: leveldown.Constructor;
|
||||
}
|
||||
|
||||
interface LevelUpConstructor {
|
||||
(hostname: string, options?: levelupOptions): LevelUp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import levelup = require("levelup");
|
||||
|
||||
interface BufferEncoding {
|
||||
encode(val: any): Buffer;
|
||||
decode(val: Buffer): any;
|
||||
buffer: boolean;
|
||||
type: string;
|
||||
}
|
||||
|
||||
interface StringEncoding {
|
||||
encode(val: any): string;
|
||||
decode(val: string): any;
|
||||
buffer: boolean;
|
||||
type: string;
|
||||
}
|
||||
|
||||
declare const bufferEncoding: BufferEncoding;
|
||||
declare const stringEncoding: StringEncoding;
|
||||
|
||||
var db1 = levelup("db1", {
|
||||
keyEncoding: bufferEncoding,
|
||||
valueEncoding: bufferEncoding
|
||||
});
|
||||
var db2 = levelup("db2", {
|
||||
keyEncoding: stringEncoding,
|
||||
valueEncoding: stringEncoding
|
||||
});
|
||||
|
||||
var db = levelup('./mydb')
|
||||
db.open();
|
||||
db.close();
|
||||
db.open((error) => {
|
||||
|
||||
});
|
||||
|
||||
db.close((error) => {
|
||||
|
||||
});
|
||||
|
||||
|
||||
db.put("key", {});
|
||||
db.put("key", {}, (error) => { });
|
||||
db.put("key", {}, { sync: true }, (error) => { });
|
||||
|
||||
db.get("key", { keyEncoding: "json" }, (error, val) => { });
|
||||
db.get("key", { fillCache: true }, (error, val) => { });
|
||||
db.get("key", (error, val) => { });
|
||||
|
||||
db.del("key");
|
||||
db.del("key", (error) => { });
|
||||
db.del("key", { keyEncoding: "json" }, (error) => { });
|
||||
db.del("key", { sync: true }, (error) => { });
|
||||
|
||||
db.batch([{
|
||||
type: 'put'
|
||||
, key: ([1, 2, 3])
|
||||
, value: { some: 'json' }
|
||||
, keyEncoding: 'binary'
|
||||
, valueEncoding: 'json'
|
||||
}], (error) => { });
|
||||
|
||||
db.batch()
|
||||
.del('father')
|
||||
.put('name', 'Yuri Irsenovich Kim')
|
||||
.put('dob', '16 February 1941')
|
||||
.put('spouse', 'Kim Young-sook')
|
||||
.put('occupation', 'Clown')
|
||||
.write(function () { console.log('Done!') })
|
||||
|
||||
var open: boolean = db.isOpen();
|
||||
var closed: boolean = db.isClosed();
|
||||
db.createReadStream()
|
||||
.on('data', function (data: any) {
|
||||
console.log(data.key, '=', data.value)
|
||||
})
|
||||
.on('error', function (err: any) {
|
||||
console.log('Oh my!', err)
|
||||
})
|
||||
.on('close', function () {
|
||||
console.log('Stream closed')
|
||||
})
|
||||
.on('end', function () {
|
||||
console.log('Stream closed')
|
||||
})
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../../",
|
||||
"typeRoots": [
|
||||
"../../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"levelup": [
|
||||
"levelup/v1"
|
||||
],
|
||||
"levelup/*": [
|
||||
"levelup/v1/*"
|
||||
],
|
||||
"leveldown": [
|
||||
"leveldown/v1"
|
||||
]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"levelup-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user