-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
117 lines (107 loc) · 3.82 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Assumed to be installed side-by-side, declared as an optional peerDependency.
import {
AbstractLevel,
AbstractIteratorOptions,
AbstractKeyIteratorOptions,
AbstractValueIteratorOptions,
AbstractBatchOptions,
AbstractBatchOperation
} from 'abstract-level'
/**
* A {@link ReadableStream} that yields entries.
*/
export class EntryStream<K, V, TDatabase = AbstractLevel<any, any, any>> extends ReadableStream<{ key: K, value: V }> {
/**
* Create a {@link ReadableStream} that yields entries from {@link db}.
* @param db Database to read from.
* @param options Options for the stream and its underlying iterator.
*/
constructor (db: TDatabase, options?: (LevelReadableStreamOptions & Omit<AbstractIteratorOptions<K, V>, 'keys' | 'values'>) | undefined)
// TODO: support passing in an iterator so that its implementation-specific options are typed?
// constructor (iterator: AbstractIterator<TDatabase, K, V>, ...)
}
/**
* A {@link ReadableStream} that yields keys.
*/
export class KeyStream<K, TDatabase = AbstractLevel<any, any, any>> extends ReadableStream<K> {
/**
* Create a {@link ReadableStream} that yields keys from {@link db}.
* @param db Database to read from.
* @param options Options for the stream and its underlying iterator.
*/
constructor (db: TDatabase, options?: (LevelReadableStreamOptions & AbstractKeyIteratorOptions<K>) | undefined)
}
/**
* A {@link ReadableStream} that yields values.
*/
export class ValueStream<K, V, TDatabase = AbstractLevel<any, any, any>> extends ReadableStream<V> {
/**
* Create a {@link ReadableStream} that yields values from {@link db}.
* @param db Database to read from.
* @param options Options for the stream and its underlying iterator.
*/
constructor (db: TDatabase, options?: (LevelReadableStreamOptions & AbstractValueIteratorOptions<K, V>) | undefined)
}
declare interface LevelReadableStreamOptions {
/**
* The maximum number of items to buffer internally before ceasing to read further
* items.
*
* @defaultValue `1000`
*/
highWaterMark?: number | undefined
/**
* Limit the amount of data that the underlying iterator will hold in memory.
*
* Only supported by [`classic-level`][1] and [`rocks-level`][2], and possibly by
* similar `abstract-level` implementations that are backed by a database on disk.
*
* [1]: https://github.com/Level/classic-level
* [2]: https://github.com/Level/rocks-level
*/
highWaterMarkBytes?: number | undefined
/**
* Only supported by [`classic-level`][1] and [`rocks-level`][2], and possibly by
* similar `abstract-level` implementations that are backed by a database on disk.
*
* [1]: https://github.com/Level/classic-level
* [2]: https://github.com/Level/rocks-level
*/
fillCache?: boolean | undefined
}
/**
* A {@link WritableStream} that takes _operations_ or _entries_.
*/
export class BatchStream<K, V, TDatabase = AbstractLevel<any, any, any>>
extends WritableStream<AbstractBatchOperation<TDatabase, K, V> | [K, V]> {
/**
* Create a {@link WritableStream} that takes _operations_ or _entries_, to be
* written to {@link db} in batches of fixed size using `db.batch()`.
*
* @param db Database to write to.
* @param options Options for the stream and `db.batch()`.
*/
constructor (
db: TDatabase,
options?: (BatchStreamOptions & AbstractBatchOptions<K, V>) | undefined
)
}
/**
* Stream options for {@link BatchStream}.
*/
declare interface BatchStreamOptions {
/**
* The maximum number of operations to buffer internally before
* committing them to the database with `db.batch()`.
*
* @defaultValue `500`
*/
highWaterMark?: number | undefined
/**
* Default operation `type` if not set on individual operations or entries (which can't
* set it).
*
* @defaultValue `'put'`
*/
type?: 'put' | 'del'
}