UNPKG

4.06 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
32 get (key: KDefault): Promise<VDefault>
33 get<K = KDefault, V = VDefault> (key: K, options: GetOptions<K, V>): Promise<V>
34
35 getMany (keys: KDefault[]): Promise<VDefault[]>
36 getMany<K = KDefault, V = VDefault> (keys: K[], options: GetManyOptions<K, V>): Promise<V[]>
37
38 put (key: KDefault, value: VDefault): Promise<void>
39 put<K = KDefault, V = VDefault> (key: K, value: V, options: PutOptions<K, V>): Promise<void>
40
41 del (key: KDefault): Promise<void>
42 del<K = KDefault> (key: K, options: DelOptions<K>): Promise<void>
43
44 batch (operations: Array<BatchOperation<typeof this, KDefault, VDefault>>): Promise<void>
45 batch<K = KDefault, V = VDefault> (operations: Array<BatchOperation<typeof this, K, V>>, options: BatchOptions<K, V>): Promise<void>
46 batch (): ChainedBatch<typeof this, KDefault, VDefault>
47
48 iterator (): Iterator<typeof this, KDefault, VDefault>
49 iterator<K = KDefault, V = VDefault> (options: IteratorOptions<K, V>): Iterator<typeof this, K, V>
50
51 keys (): KeyIterator<typeof this, KDefault>
52 keys<K = KDefault> (options: KeyIteratorOptions<K>): KeyIterator<typeof this, K>
53
54 values (): ValueIterator<typeof this, KDefault, VDefault>
55 values<K = KDefault, V = VDefault> (options: ValueIteratorOptions<K, V>): ValueIterator<typeof this, K, V>
56}
57
58export type DatabaseOptions<K, V> = ClassicLevel.DatabaseOptions<K, V> & BrowserLevel.DatabaseOptions<K, V>
59export type OpenOptions = ClassicLevel.OpenOptions & BrowserLevel.OpenOptions
60export type GetOptions<K, V> = ClassicLevel.GetOptions<K, V> & BrowserLevel.GetOptions<K, V>
61export type GetManyOptions<K, V> = ClassicLevel.GetManyOptions<K, V> & BrowserLevel.GetManyOptions<K, V>
62export type PutOptions<K, V> = ClassicLevel.PutOptions<K, V> & BrowserLevel.PutOptions<K, V>
63export type DelOptions<K> = ClassicLevel.DelOptions<K> & BrowserLevel.DelOptions<K>
64
65export type BatchOptions<K, V> = ClassicLevel.BatchOptions<K, V> & BrowserLevel.BatchOptions<K, V>
66export type BatchOperation<TDatabase, K, V> = ClassicLevel.BatchOperation<TDatabase, K, V> & BrowserLevel.BatchOperation<TDatabase, K, V>
67export type ChainedBatch<TDatabase, K, V> = ClassicLevel.ChainedBatch<TDatabase, K, V> & BrowserLevel.ChainedBatch<TDatabase, K, V>
68
69export type Iterator<TDatabase, K, V> = ClassicLevel.Iterator<TDatabase, K, V> & BrowserLevel.Iterator<TDatabase, K, V>
70export type KeyIterator<TDatabase, K> = ClassicLevel.KeyIterator<TDatabase, K> & BrowserLevel.KeyIterator<TDatabase, K>
71export type ValueIterator<TDatabase, K, V> = ClassicLevel.ValueIterator<TDatabase, K, V> & BrowserLevel.ValueIterator<TDatabase, K, V>
72
73export type IteratorOptions<K, V> = ClassicLevel.IteratorOptions<K, V> & BrowserLevel.IteratorOptions<K, V>
74export type KeyIteratorOptions<K> = ClassicLevel.KeyIteratorOptions<K> & BrowserLevel.KeyIteratorOptions<K>
75export type ValueIteratorOptions<K, V> = ClassicLevel.ValueIteratorOptions<K, V> & BrowserLevel.ValueIteratorOptions<K, V>