@blackglory/cache-js 0.11.2 → 0.11.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -10
- package/lib/cache-client.d.ts +15 -11
- package/lib/cache-client.js +28 -25
- package/lib/cache-client.js.map +1 -1
- package/package.json +8 -8
- package/src/cache-client.ts +59 -25
package/README.md
CHANGED
|
@@ -15,6 +15,11 @@ interface ICacheClientOptions {
|
|
|
15
15
|
retryIntervalForReconnection?: number
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
interface ICacheClientRequestOptions {
|
|
19
|
+
signal?: AbortSignal
|
|
20
|
+
timeout?: number | false
|
|
21
|
+
}
|
|
22
|
+
|
|
18
23
|
interface INamespaceStats {
|
|
19
24
|
items: number
|
|
20
25
|
}
|
|
@@ -36,35 +41,40 @@ class CacheClient {
|
|
|
36
41
|
|
|
37
42
|
getNamespaceStats(
|
|
38
43
|
namespace: string
|
|
39
|
-
,
|
|
44
|
+
, signalOrOptions?: AbortSignal | ICacheClientRequestOptions
|
|
40
45
|
): Promise<INamespaceStats>
|
|
41
46
|
|
|
42
|
-
getAllNamespaces(
|
|
47
|
+
getAllNamespaces(
|
|
48
|
+
signalOrOptions?: AbortSignal | ICacheClientRequestOptions
|
|
49
|
+
): Promise<string[]>
|
|
43
50
|
|
|
44
|
-
getAllItemKeys(
|
|
51
|
+
getAllItemKeys(
|
|
52
|
+
namespace: string
|
|
53
|
+
, signalOrOptions?: AbortSignal | ICacheClientRequestOptions
|
|
54
|
+
): Promise<string[]>
|
|
45
55
|
|
|
46
56
|
hasItem(
|
|
47
57
|
namespace: string
|
|
48
58
|
, itemKey: string
|
|
49
|
-
,
|
|
59
|
+
, signalOrOptions?: AbortSignal | ICacheClientRequestOptions
|
|
50
60
|
): Promise<boolean>
|
|
51
61
|
|
|
52
62
|
getItem(
|
|
53
63
|
namespace: string
|
|
54
64
|
, itemKey: string
|
|
55
|
-
,
|
|
65
|
+
, signalOrOptions?: AbortSignal | ICacheClientRequestOptions
|
|
56
66
|
): Promise<IItem | null>
|
|
57
67
|
|
|
58
68
|
getItemValue(
|
|
59
69
|
namespace: string
|
|
60
70
|
, itemKey: string
|
|
61
|
-
,
|
|
71
|
+
, signalOrOptions?: AbortSignal | ICacheClientRequestOptions
|
|
62
72
|
): Promise<JSONValue | null>
|
|
63
73
|
|
|
64
74
|
getItemValues(
|
|
65
75
|
namespace: string
|
|
66
76
|
, itemKeys: string[]
|
|
67
|
-
,
|
|
77
|
+
, signalOrOptions?: AbortSignal | ICacheClientRequestOptions
|
|
68
78
|
): Promise<Array<JSONValue | null>>
|
|
69
79
|
|
|
70
80
|
setItem(
|
|
@@ -72,15 +82,18 @@ class CacheClient {
|
|
|
72
82
|
, itemKey: string
|
|
73
83
|
, itemValue: JSONValue
|
|
74
84
|
, timeToLive: number | null
|
|
75
|
-
,
|
|
85
|
+
, signalOrOptions?: AbortSignal | ICacheClientRequestOptions
|
|
76
86
|
): Promise<void>
|
|
77
87
|
|
|
78
88
|
removeItem(
|
|
79
89
|
namespace: string
|
|
80
90
|
, itemKey: string
|
|
81
|
-
,
|
|
91
|
+
, signalOrOptions?: AbortSignal | ICacheClientRequestOptions
|
|
82
92
|
): Promise<void>
|
|
83
93
|
|
|
84
|
-
clearItemsByNamespace(
|
|
94
|
+
clearItemsByNamespace(
|
|
95
|
+
namespace: string
|
|
96
|
+
, signalOrOptions?: AbortSignal | ICacheClientRequestOptions
|
|
97
|
+
): Promise<void>
|
|
85
98
|
}
|
|
86
99
|
```
|
package/lib/cache-client.d.ts
CHANGED
|
@@ -6,6 +6,10 @@ export interface ICacheClientOptions {
|
|
|
6
6
|
timeout?: number;
|
|
7
7
|
retryIntervalForReconnection?: number;
|
|
8
8
|
}
|
|
9
|
+
export interface ICacheClientRequestOptions {
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
timeout?: number | false;
|
|
12
|
+
}
|
|
9
13
|
export declare class CacheClient {
|
|
10
14
|
private client;
|
|
11
15
|
private batchClient;
|
|
@@ -15,15 +19,15 @@ export declare class CacheClient {
|
|
|
15
19
|
static create(options: ICacheClientOptions): Promise<CacheClient>;
|
|
16
20
|
private constructor();
|
|
17
21
|
close(): Promise<void>;
|
|
18
|
-
getNamespaceStats(namespace: string,
|
|
19
|
-
getAllNamespaces(
|
|
20
|
-
getAllItemKeys(namespace: string,
|
|
21
|
-
hasItem(namespace: string, itemKey: string,
|
|
22
|
-
getItem(namespace: string, itemKey: string,
|
|
23
|
-
getItemValue(namespace: string, itemKey: string,
|
|
24
|
-
getItemValues(namespace: string, itemKeys: string[],
|
|
25
|
-
setItem(namespace: string, itemKey: string, itemValue: JSONValue, timeToLive: number | null,
|
|
26
|
-
removeItem(namespace: string, itemKey: string,
|
|
27
|
-
clearItemsByNamespace(namespace: string,
|
|
28
|
-
private
|
|
22
|
+
getNamespaceStats(namespace: string, signalOrOptions?: AbortSignal | ICacheClientRequestOptions): Promise<INamespaceStats>;
|
|
23
|
+
getAllNamespaces(signalOrOptions?: AbortSignal | ICacheClientRequestOptions): Promise<string[]>;
|
|
24
|
+
getAllItemKeys(namespace: string, signalOrOptions?: AbortSignal | ICacheClientRequestOptions): Promise<string[]>;
|
|
25
|
+
hasItem(namespace: string, itemKey: string, signalOrOptions?: AbortSignal | ICacheClientRequestOptions): Promise<boolean>;
|
|
26
|
+
getItem(namespace: string, itemKey: string, signalOrOptions?: AbortSignal | ICacheClientRequestOptions): Promise<IItem | null>;
|
|
27
|
+
getItemValue(namespace: string, itemKey: string, signalOrOptions?: AbortSignal | ICacheClientRequestOptions): Promise<JSONValue | null>;
|
|
28
|
+
getItemValues(namespace: string, itemKeys: string[], signalOrOptions?: AbortSignal | ICacheClientRequestOptions): Promise<Array<JSONValue | null>>;
|
|
29
|
+
setItem(namespace: string, itemKey: string, itemValue: JSONValue, timeToLive: number | null, signalOrOptions?: AbortSignal | ICacheClientRequestOptions): Promise<void>;
|
|
30
|
+
removeItem(namespace: string, itemKey: string, signalOrOptions?: AbortSignal | ICacheClientRequestOptions): Promise<void>;
|
|
31
|
+
clearItemsByNamespace(namespace: string, signalOrOptions?: AbortSignal | ICacheClientRequestOptions): Promise<void>;
|
|
32
|
+
private createSignal;
|
|
29
33
|
}
|
package/lib/cache-client.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createRPCClient } from "./utils/rpc-client.js";
|
|
2
|
-
import { raceAbortSignals, timeoutSignal, withAbortSignal } from 'extra-abort';
|
|
3
|
-
import { isntUndefined } from '@blackglory/prelude';
|
|
2
|
+
import { raceAbortSignals, timeoutSignal, withAbortSignal, isAbortSignal } from 'extra-abort';
|
|
4
3
|
export class CacheClient {
|
|
5
4
|
static async create(options) {
|
|
6
5
|
const { client, batchClient, proxy, close } = await createRPCClient(options.server, options.retryIntervalForReconnection, options.timeout);
|
|
@@ -16,43 +15,47 @@ export class CacheClient {
|
|
|
16
15
|
async close() {
|
|
17
16
|
await this.closeClients();
|
|
18
17
|
}
|
|
19
|
-
async getNamespaceStats(namespace,
|
|
20
|
-
return await this.client.getNamespaceStats(namespace, this.
|
|
18
|
+
async getNamespaceStats(namespace, signalOrOptions) {
|
|
19
|
+
return await this.client.getNamespaceStats(namespace, this.createSignal(signalOrOptions));
|
|
21
20
|
}
|
|
22
|
-
async getAllNamespaces(
|
|
23
|
-
return await this.client.getAllNamespaces(this.
|
|
21
|
+
async getAllNamespaces(signalOrOptions) {
|
|
22
|
+
return await this.client.getAllNamespaces(this.createSignal(signalOrOptions));
|
|
24
23
|
}
|
|
25
|
-
async getAllItemKeys(namespace,
|
|
26
|
-
return await this.client.getAllItemKeys(namespace, this.
|
|
24
|
+
async getAllItemKeys(namespace, signalOrOptions) {
|
|
25
|
+
return await this.client.getAllItemKeys(namespace, this.createSignal(signalOrOptions));
|
|
27
26
|
}
|
|
28
|
-
async hasItem(namespace, itemKey,
|
|
29
|
-
return await this.client.hasItem(namespace, itemKey, this.
|
|
27
|
+
async hasItem(namespace, itemKey, signalOrOptions) {
|
|
28
|
+
return await this.client.hasItem(namespace, itemKey, this.createSignal(signalOrOptions));
|
|
30
29
|
}
|
|
31
|
-
async getItem(namespace, itemKey,
|
|
32
|
-
return await this.client.getItem(namespace, itemKey, this.
|
|
30
|
+
async getItem(namespace, itemKey, signalOrOptions) {
|
|
31
|
+
return await this.client.getItem(namespace, itemKey, this.createSignal(signalOrOptions));
|
|
33
32
|
}
|
|
34
|
-
async getItemValue(namespace, itemKey,
|
|
35
|
-
return await this.client.getItemValue(namespace, itemKey, this.
|
|
33
|
+
async getItemValue(namespace, itemKey, signalOrOptions) {
|
|
34
|
+
return await this.client.getItemValue(namespace, itemKey, this.createSignal(signalOrOptions));
|
|
36
35
|
}
|
|
37
|
-
async getItemValues(namespace, itemKeys,
|
|
38
|
-
return await withAbortSignal(this.
|
|
36
|
+
async getItemValues(namespace, itemKeys, signalOrOptions) {
|
|
37
|
+
return await withAbortSignal(this.createSignal(signalOrOptions), async () => {
|
|
39
38
|
const results = await this.batchClient.parallel(...itemKeys.map(key => this.batchProxy.getItemValue(namespace, key)));
|
|
40
39
|
return results.map(result => result.unwrap());
|
|
41
40
|
});
|
|
42
41
|
}
|
|
43
|
-
async setItem(namespace, itemKey, itemValue, timeToLive,
|
|
44
|
-
await this.client.setItem(namespace, itemKey, itemValue, timeToLive, this.
|
|
42
|
+
async setItem(namespace, itemKey, itemValue, timeToLive, signalOrOptions) {
|
|
43
|
+
await this.client.setItem(namespace, itemKey, itemValue, timeToLive, this.createSignal(signalOrOptions));
|
|
45
44
|
}
|
|
46
|
-
async removeItem(namespace, itemKey,
|
|
47
|
-
await this.client.removeItem(namespace, itemKey, this.
|
|
45
|
+
async removeItem(namespace, itemKey, signalOrOptions) {
|
|
46
|
+
await this.client.removeItem(namespace, itemKey, this.createSignal(signalOrOptions));
|
|
48
47
|
}
|
|
49
|
-
async clearItemsByNamespace(namespace,
|
|
50
|
-
await this.client.clearItemsByNamespace(namespace, this.
|
|
48
|
+
async clearItemsByNamespace(namespace, signalOrOptions) {
|
|
49
|
+
await this.client.clearItemsByNamespace(namespace, this.createSignal(signalOrOptions));
|
|
51
50
|
}
|
|
52
|
-
|
|
51
|
+
createSignal(signalOrOptions = {}) {
|
|
52
|
+
var _a;
|
|
53
|
+
const options = isAbortSignal(signalOrOptions)
|
|
54
|
+
? { signal: signalOrOptions }
|
|
55
|
+
: signalOrOptions;
|
|
53
56
|
return raceAbortSignals([
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
options.signal,
|
|
58
|
+
options.timeout !== false && ((_a = (options.timeout && timeoutSignal(options.timeout))) !== null && _a !== void 0 ? _a : (this.timeout && timeoutSignal(this.timeout)))
|
|
56
59
|
]);
|
|
57
60
|
}
|
|
58
61
|
}
|
package/lib/cache-client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache-client.js","sourceRoot":"","sources":["../src/cache-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,8BAA4B;AAGtD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"cache-client.js","sourceRoot":"","sources":["../src/cache-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,8BAA4B;AAGtD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAe7F,MAAM,OAAO,WAAW;IACtB,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAA4B;QAC9C,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,MAAM,eAAe,CACjE,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,4BAA4B,EACpC,OAAO,CAAC,OAAO,CAChB,CAAA;QACD,OAAO,IAAI,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CA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IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,CACnC,CAAA;IACH,CAAC;IAEO,YAAY,CAClB,kBAA4D,EAAE;;QAE9D,MAAM,OAAO,GAA+B,aAAa,CAAC,eAAe,CAAC;YAChC,CAAC,CAAC,EAAE,MAAM,EAAE,eAAe,EAAE;YAC7B,CAAC,CAAC,eAAe,CAAA;QAE3D,OAAO,gBAAgB,CAAC;YACtB,OAAO,CAAC,MAAM;YACd,OAAO,CAAC,OAAO,KAAK,KAAK,IAAI,CAC3B,MAAA,CAAC,OAAO,CAAC,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,mCACnD,CAAC,IAAI,CAAC,OAAO,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAC9C;SACF,CAAC,CAAA;IACJ,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blackglory/cache-js",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"files": [
|
|
@@ -62,12 +62,12 @@
|
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@blackglory/prelude": "^0.4.0",
|
|
65
|
-
"@delight-rpc/extra-native-websocket": "^0.6.
|
|
66
|
-
"@delight-rpc/extra-websocket": "^0.7.
|
|
67
|
-
"delight-rpc": "^
|
|
68
|
-
"extra-abort": "^0.
|
|
69
|
-
"extra-native-websocket": "^0.5.
|
|
70
|
-
"extra-websocket": "^0.5.
|
|
71
|
-
"ws": "^8.
|
|
65
|
+
"@delight-rpc/extra-native-websocket": "^0.6.6",
|
|
66
|
+
"@delight-rpc/extra-websocket": "^0.7.8",
|
|
67
|
+
"delight-rpc": "^7.0.0",
|
|
68
|
+
"extra-abort": "^0.5.1",
|
|
69
|
+
"extra-native-websocket": "^0.5.2",
|
|
70
|
+
"extra-websocket": "^0.5.3",
|
|
71
|
+
"ws": "^8.21.0"
|
|
72
72
|
}
|
|
73
73
|
}
|
package/src/cache-client.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createRPCClient } from '@utils/rpc-client.js'
|
|
2
2
|
import { ClientProxy, BatchClient, BatchClientProxy } from 'delight-rpc'
|
|
3
3
|
import { IAPI, INamespaceStats, IItem } from './contract.js'
|
|
4
|
-
import { raceAbortSignals, timeoutSignal, withAbortSignal } from 'extra-abort'
|
|
5
|
-
import {
|
|
4
|
+
import { raceAbortSignals, timeoutSignal, withAbortSignal, isAbortSignal } from 'extra-abort'
|
|
5
|
+
import { JSONValue } from '@blackglory/prelude'
|
|
6
6
|
export { INamespaceStats, IItem, IItemMetadata } from './contract.js'
|
|
7
7
|
|
|
8
8
|
export interface ICacheClientOptions {
|
|
@@ -11,6 +11,11 @@ export interface ICacheClientOptions {
|
|
|
11
11
|
retryIntervalForReconnection?: number
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
export interface ICacheClientRequestOptions {
|
|
15
|
+
signal?: AbortSignal
|
|
16
|
+
timeout?: number | false
|
|
17
|
+
}
|
|
18
|
+
|
|
14
19
|
export class CacheClient {
|
|
15
20
|
static async create(options: ICacheClientOptions): Promise<CacheClient> {
|
|
16
21
|
const { client, batchClient, proxy, close } = await createRPCClient(
|
|
@@ -35,62 +40,75 @@ export class CacheClient {
|
|
|
35
40
|
|
|
36
41
|
async getNamespaceStats(
|
|
37
42
|
namespace: string
|
|
38
|
-
,
|
|
43
|
+
, signalOrOptions?: AbortSignal | ICacheClientRequestOptions
|
|
39
44
|
): Promise<INamespaceStats> {
|
|
40
45
|
return await this.client.getNamespaceStats(
|
|
41
46
|
namespace
|
|
42
|
-
, this.
|
|
47
|
+
, this.createSignal(signalOrOptions)
|
|
43
48
|
)
|
|
44
49
|
}
|
|
45
50
|
|
|
46
|
-
async getAllNamespaces(
|
|
51
|
+
async getAllNamespaces(
|
|
52
|
+
signalOrOptions?: AbortSignal | ICacheClientRequestOptions
|
|
53
|
+
): Promise<string[]> {
|
|
47
54
|
return await this.client.getAllNamespaces(
|
|
48
|
-
this.
|
|
55
|
+
this.createSignal(signalOrOptions)
|
|
49
56
|
)
|
|
50
57
|
}
|
|
51
58
|
|
|
52
59
|
async getAllItemKeys(
|
|
53
60
|
namespace: string
|
|
54
|
-
,
|
|
61
|
+
, signalOrOptions?: AbortSignal | ICacheClientRequestOptions
|
|
55
62
|
): Promise<string[]> {
|
|
56
|
-
return await this.client.getAllItemKeys(
|
|
63
|
+
return await this.client.getAllItemKeys(
|
|
64
|
+
namespace
|
|
65
|
+
, this.createSignal(signalOrOptions)
|
|
66
|
+
)
|
|
57
67
|
}
|
|
58
68
|
|
|
59
69
|
async hasItem(
|
|
60
70
|
namespace: string
|
|
61
71
|
, itemKey: string
|
|
62
|
-
,
|
|
72
|
+
, signalOrOptions?: AbortSignal | ICacheClientRequestOptions
|
|
63
73
|
): Promise<boolean> {
|
|
64
|
-
return await this.client.hasItem(
|
|
74
|
+
return await this.client.hasItem(
|
|
75
|
+
namespace
|
|
76
|
+
, itemKey
|
|
77
|
+
, this.createSignal(signalOrOptions)
|
|
78
|
+
)
|
|
65
79
|
}
|
|
66
80
|
|
|
67
81
|
async getItem(
|
|
68
82
|
namespace: string
|
|
69
83
|
, itemKey: string
|
|
70
|
-
,
|
|
84
|
+
, signalOrOptions?: AbortSignal | ICacheClientRequestOptions
|
|
71
85
|
): Promise<IItem | null> {
|
|
72
|
-
return await this.client.getItem(
|
|
86
|
+
return await this.client.getItem(
|
|
87
|
+
namespace
|
|
88
|
+
, itemKey
|
|
89
|
+
, this.createSignal(signalOrOptions)
|
|
90
|
+
)
|
|
73
91
|
}
|
|
74
92
|
|
|
75
93
|
async getItemValue(
|
|
76
94
|
namespace: string
|
|
77
95
|
, itemKey: string
|
|
78
|
-
,
|
|
96
|
+
, signalOrOptions?: AbortSignal | ICacheClientRequestOptions
|
|
79
97
|
): Promise<JSONValue | null> {
|
|
80
98
|
return await this.client.getItemValue(
|
|
81
99
|
namespace
|
|
82
100
|
, itemKey
|
|
83
|
-
, this.
|
|
101
|
+
, this.createSignal(signalOrOptions)
|
|
84
102
|
)
|
|
85
103
|
}
|
|
86
104
|
|
|
87
105
|
async getItemValues(
|
|
88
106
|
namespace: string
|
|
89
107
|
, itemKeys: string[]
|
|
90
|
-
,
|
|
108
|
+
, signalOrOptions?: AbortSignal | ICacheClientRequestOptions
|
|
91
109
|
): Promise<Array<JSONValue | null>> {
|
|
92
110
|
return await withAbortSignal(
|
|
93
|
-
this.
|
|
111
|
+
this.createSignal(signalOrOptions)
|
|
94
112
|
, async () => {
|
|
95
113
|
const results = await this.batchClient.parallel(
|
|
96
114
|
...itemKeys.map(key => this.batchProxy.getItemValue(namespace, key))
|
|
@@ -105,36 +123,52 @@ export class CacheClient {
|
|
|
105
123
|
, itemKey: string
|
|
106
124
|
, itemValue: JSONValue
|
|
107
125
|
, timeToLive: number | null
|
|
108
|
-
,
|
|
126
|
+
, signalOrOptions?: AbortSignal | ICacheClientRequestOptions
|
|
109
127
|
): Promise<void> {
|
|
110
128
|
await this.client.setItem(
|
|
111
129
|
namespace
|
|
112
130
|
, itemKey
|
|
113
131
|
, itemValue
|
|
114
132
|
, timeToLive
|
|
115
|
-
, this.
|
|
133
|
+
, this.createSignal(signalOrOptions)
|
|
116
134
|
)
|
|
117
135
|
}
|
|
118
136
|
|
|
119
137
|
async removeItem(
|
|
120
138
|
namespace: string
|
|
121
139
|
, itemKey: string
|
|
122
|
-
,
|
|
140
|
+
, signalOrOptions?: AbortSignal | ICacheClientRequestOptions
|
|
123
141
|
): Promise<void> {
|
|
124
|
-
await this.client.removeItem(
|
|
142
|
+
await this.client.removeItem(
|
|
143
|
+
namespace
|
|
144
|
+
, itemKey
|
|
145
|
+
, this.createSignal(signalOrOptions)
|
|
146
|
+
)
|
|
125
147
|
}
|
|
126
148
|
|
|
127
149
|
async clearItemsByNamespace(
|
|
128
150
|
namespace: string
|
|
129
|
-
,
|
|
151
|
+
, signalOrOptions?: AbortSignal | ICacheClientRequestOptions
|
|
130
152
|
): Promise<void> {
|
|
131
|
-
await this.client.clearItemsByNamespace(
|
|
153
|
+
await this.client.clearItemsByNamespace(
|
|
154
|
+
namespace
|
|
155
|
+
, this.createSignal(signalOrOptions)
|
|
156
|
+
)
|
|
132
157
|
}
|
|
133
158
|
|
|
134
|
-
private
|
|
159
|
+
private createSignal(
|
|
160
|
+
signalOrOptions: AbortSignal | ICacheClientRequestOptions = {}
|
|
161
|
+
): AbortSignal {
|
|
162
|
+
const options: ICacheClientRequestOptions = isAbortSignal(signalOrOptions)
|
|
163
|
+
? { signal: signalOrOptions }
|
|
164
|
+
: signalOrOptions
|
|
165
|
+
|
|
135
166
|
return raceAbortSignals([
|
|
136
|
-
|
|
137
|
-
,
|
|
167
|
+
options.signal
|
|
168
|
+
, options.timeout !== false && (
|
|
169
|
+
(options.timeout && timeoutSignal(options.timeout)) ??
|
|
170
|
+
(this.timeout && timeoutSignal(this.timeout))
|
|
171
|
+
)
|
|
138
172
|
])
|
|
139
173
|
}
|
|
140
174
|
}
|