UNPKG

5.3 kBTypeScriptView Raw
1import * as AbstractLevel from 'abstract-level'
2import * as ClassicLevel from 'classic-level'
3import * as BrowserLevel from 'browser-level'
4
5/**
6 * Universal {@link AbstractLevel} database for Node.js and browsers.
7 *
8 * @template KDefault The default type of keys if not overridden on operations.
9 * @template VDefault The default type of values if not overridden on operations.
10 */
11export class Level<KDefault = string, VDefault = string>
12 extends AbstractLevel.AbstractLevel<string | Buffer | Uint8Array, KDefault, VDefault> {
13 /**
14 * Database constructor.
15 *
16 * @param location Directory path (relative or absolute) where LevelDB will store its
17 * files, or in browsers, the name of the
18 * [`IDBDatabase`](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase) to be
19 * opened.
20 * @param options Options, of which some will be forwarded to {@link open}.
21 */
22 constructor (location: string, options?: DatabaseOptions<KDefault, VDefault> | undefined)
23
24 /**
25 * Location that was passed to the constructor.
26 */
27 get location (): string
28
29 open (): Promise<void>
30 open (options: OpenOptions): Promise<void>
31 open (callback: AbstractLevel.NodeCallback<void>): void
32 open (options: OpenOptions, callback: AbstractLevel.NodeCallback<void>): void
33
34 get (key: KDefault): Promise<VDefault>
35 get (key: KDefault, callback: AbstractLevel.NodeCallback<VDefault>): void
36 get<K = KDefault, V = VDefault> (key: K, options: GetOptions<K, V>): Promise<V>
37 get<K = KDefault, V = VDefault> (key: K, options: GetOptions<K, V>, callback: AbstractLevel.NodeCallback<V>): void
38
39 getMany (keys: KDefault[]): Promise<VDefault[]>
40 getMany (keys: KDefault[], callback: AbstractLevel.NodeCallback<VDefault[]>): void
41 getMany<K = KDefault, V = VDefault> (keys: K[], options: GetManyOptions<K, V>): Promise<V[]>
42 getMany<K = KDefault, V = VDefault> (keys: K[], options: GetManyOptions<K, V>, callback: AbstractLevel.NodeCallback<V[]>): void
43
44 put (key: KDefault, value: VDefault): Promise<void>
45 put (key: KDefault, value: VDefault, callback: AbstractLevel.NodeCallback<void>): void
46 put<K = KDefault, V = VDefault> (key: K, value: V, options: PutOptions<K, V>): Promise<void>
47 put<K = KDefault, V = VDefault> (key: K, value: V, options: PutOptions<K, V>, callback: AbstractLevel.NodeCallback<void>): void
48
49 del (key: KDefault): Promise<void>
50 del (key: KDefault, callback: AbstractLevel.NodeCallback<void>): void
51 del<K = KDefault> (key: K, options: DelOptions<K>): Promise<void>
52 del<K = KDefault> (key: K, options: DelOptions<K>, callback: AbstractLevel.NodeCallback<void>): void
53
54 batch (operations: Array<BatchOperation<typeof this, KDefault, VDefault>>): Promise<void>
55 batch (operations: Array<BatchOperation<typeof this, KDefault, VDefault>>, callback: AbstractLevel.NodeCallback<void>): void
56 batch<K = KDefault, V = VDefault> (operations: Array<BatchOperation<typeof this, K, V>>, options: BatchOptions<K, V>): Promise<void>
57 batch<K = KDefault, V = VDefault> (operations: Array<BatchOperation<typeof this, K, V>>, options: BatchOptions<K, V>, callback: AbstractLevel.NodeCallback<void>): void
58 batch (): ChainedBatch<typeof this, KDefault, VDefault>
59
60 iterator (): Iterator<typeof this, KDefault, VDefault>
61 iterator<K = KDefault, V = VDefault> (options: IteratorOptions<K, V>): Iterator<typeof this, K, V>
62
63 keys (): KeyIterator<typeof this, KDefault>
64 keys<K = KDefault> (options: KeyIteratorOptions<K>): KeyIterator<typeof this, K>
65
66 values (): ValueIterator<typeof this, KDefault, VDefault>
67 values<K = KDefault, V = VDefault> (options: ValueIteratorOptions<K, V>): ValueIterator<typeof this, K, V>
68}
69
70export type DatabaseOptions<K, V> = ClassicLevel.DatabaseOptions<K, V> & BrowserLevel.DatabaseOptions<K, V>
71export type OpenOptions = ClassicLevel.OpenOptions & BrowserLevel.OpenOptions
72export type GetOptions<K, V> = ClassicLevel.GetOptions<K, V> & BrowserLevel.GetOptions<K, V>
73export type GetManyOptions<K, V> = ClassicLevel.GetManyOptions<K, V> & BrowserLevel.GetManyOptions<K, V>
74export type PutOptions<K, V> = ClassicLevel.PutOptions<K, V> & BrowserLevel.PutOptions<K, V>
75export type DelOptions<K> = ClassicLevel.DelOptions<K> & BrowserLevel.DelOptions<K>
76
77export type BatchOptions<K, V> = ClassicLevel.BatchOptions<K, V> & BrowserLevel.BatchOptions<K, V>
78export type BatchOperation<TDatabase, K, V> = ClassicLevel.BatchOperation<TDatabase, K, V> & BrowserLevel.BatchOperation<TDatabase, K, V>
79export type ChainedBatch<TDatabase, K, V> = ClassicLevel.ChainedBatch<TDatabase, K, V> & BrowserLevel.ChainedBatch<TDatabase, K, V>
80
81export type Iterator<TDatabase, K, V> = ClassicLevel.Iterator<TDatabase, K, V> & BrowserLevel.Iterator<TDatabase, K, V>
82export type KeyIterator<TDatabase, K> = ClassicLevel.KeyIterator<TDatabase, K> & BrowserLevel.KeyIterator<TDatabase, K>
83export type ValueIterator<TDatabase, K, V> = ClassicLevel.ValueIterator<TDatabase, K, V> & BrowserLevel.ValueIterator<TDatabase, K, V>
84
85export type IteratorOptions<K, V> = ClassicLevel.IteratorOptions<K, V> & BrowserLevel.IteratorOptions<K, V>
86export type KeyIteratorOptions<K> = ClassicLevel.KeyIteratorOptions<K> & BrowserLevel.KeyIteratorOptions<K>
87export type ValueIteratorOptions<K, V> = ClassicLevel.ValueIteratorOptions<K, V> & BrowserLevel.ValueIteratorOptions<K, V>