1
1
2
+ /**
3
+ * An iterable or async iterable of values
4
+ */
2
5
export type AwaitIterable < T > = Iterable < T > | AsyncIterable < T >
6
+
7
+ /**
8
+ * A value or a promise of a value
9
+ */
3
10
export type Await < T > = Promise < T > | T
4
11
5
12
/**
6
13
* Options for async operations.
7
14
*/
8
- export interface Options {
15
+ export interface AbortOptions {
9
16
signal ?: AbortSignal
10
17
}
11
18
12
- export interface Store < Key , Value , Pair > {
19
+ export interface Store < Key , Value , Pair , HasOptionsExtension = { } ,
20
+ PutOptionsExtension = { } , PutManyOptionsExtension = { } ,
21
+ GetOptionsExtension = { } , GetManyOptionsExtension = { } ,
22
+ DeleteOptionsExtension = { } , DeleteManyOptionsExtension = { } > {
13
23
/**
14
24
* Check for the existence of a value for the passed key
15
25
*
@@ -24,7 +34,7 @@ export interface Store<Key, Value, Pair> {
24
34
*}
25
35
*```
26
36
*/
27
- has : ( key : Key , options ?: Options ) => Await < boolean >
37
+ has : ( key : Key , options ?: AbortOptions & HasOptionsExtension ) => Await < boolean >
28
38
29
39
/**
30
40
* Store the passed value under the passed key
@@ -35,7 +45,7 @@ export interface Store<Key, Value, Pair> {
35
45
* await store.put([{ key: new Key('awesome'), value: new Uint8Array([0, 1, 2, 3]) }])
36
46
* ```
37
47
*/
38
- put : ( key : Key , val : Value , options ?: Options ) => Await < void >
48
+ put : ( key : Key , val : Value , options ?: AbortOptions & PutOptionsExtension ) => Await < void >
39
49
40
50
/**
41
51
* Store the given key/value pairs
@@ -51,7 +61,7 @@ export interface Store<Key, Value, Pair> {
51
61
*/
52
62
putMany : (
53
63
source : AwaitIterable < Pair > ,
54
- options ?: Options
64
+ options ?: AbortOptions & PutManyOptionsExtension
55
65
) => AwaitIterable < Pair >
56
66
57
67
/**
@@ -64,7 +74,7 @@ export interface Store<Key, Value, Pair> {
64
74
* // => got content: datastore
65
75
* ```
66
76
*/
67
- get : ( key : Key , options ?: Options ) => Await < Value >
77
+ get : ( key : Key , options ?: AbortOptions & GetOptionsExtension ) => Await < Value >
68
78
69
79
/**
70
80
* Retrieve values for the passed keys
@@ -79,7 +89,7 @@ export interface Store<Key, Value, Pair> {
79
89
*/
80
90
getMany : (
81
91
source : AwaitIterable < Key > ,
82
- options ?: Options
92
+ options ?: AbortOptions & GetManyOptionsExtension
83
93
) => AwaitIterable < Value >
84
94
85
95
/**
@@ -92,7 +102,7 @@ export interface Store<Key, Value, Pair> {
92
102
* console.log('deleted awesome content :(')
93
103
* ```
94
104
*/
95
- delete : ( key : Key , options ?: Options ) => Await < void >
105
+ delete : ( key : Key , options ?: AbortOptions & DeleteOptionsExtension ) => Await < void >
96
106
97
107
/**
98
108
* Remove values for the passed keys
@@ -109,6 +119,6 @@ export interface Store<Key, Value, Pair> {
109
119
*/
110
120
deleteMany : (
111
121
source : AwaitIterable < Key > ,
112
- options ?: Options
122
+ options ?: AbortOptions & DeleteManyOptionsExtension
113
123
) => AwaitIterable < Key >
114
124
}
0 commit comments