@blackglory/cache-js 0.10.4 → 0.11.0
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 +21 -10
- package/lib/cache-client.d.ts +10 -10
- package/lib/cache-client.js +32 -33
- package/lib/cache-client.js.map +1 -1
- package/package.json +31 -33
- package/src/cache-client.ts +46 -61
package/README.md
CHANGED
|
@@ -34,30 +34,37 @@ class CacheClient {
|
|
|
34
34
|
|
|
35
35
|
close(): Promise<void>
|
|
36
36
|
|
|
37
|
-
getNamespaceStats(
|
|
37
|
+
getNamespaceStats(
|
|
38
|
+
namespace: string
|
|
39
|
+
, signal?: AbortSignal
|
|
40
|
+
): Promise<INamespaceStats>
|
|
38
41
|
|
|
39
|
-
getAllNamespaces(
|
|
42
|
+
getAllNamespaces(signal?: AbortSignal): Promise<string[]>
|
|
40
43
|
|
|
41
|
-
getAllItemKeys(namespace: string,
|
|
44
|
+
getAllItemKeys(namespace: string, signal?: AbortSignal): Promise<string[]>
|
|
42
45
|
|
|
43
|
-
hasItem(
|
|
46
|
+
hasItem(
|
|
47
|
+
namespace: string
|
|
48
|
+
, itemKey: string
|
|
49
|
+
, signal?: AbortSignal
|
|
50
|
+
): Promise<boolean>
|
|
44
51
|
|
|
45
52
|
getItem(
|
|
46
53
|
namespace: string
|
|
47
54
|
, itemKey: string
|
|
48
|
-
,
|
|
55
|
+
, signal?: AbortSignal
|
|
49
56
|
): Promise<IItem | null>
|
|
50
57
|
|
|
51
58
|
getItemValue(
|
|
52
59
|
namespace: string
|
|
53
60
|
, itemKey: string
|
|
54
|
-
,
|
|
61
|
+
, signal?: AbortSignal
|
|
55
62
|
): Promise<JSONValue | null>
|
|
56
63
|
|
|
57
64
|
getItemValues(
|
|
58
65
|
namespace: string
|
|
59
66
|
, itemKeys: string[]
|
|
60
|
-
,
|
|
67
|
+
, signal?: AbortSignal
|
|
61
68
|
): Promise<Array<JSONValue | null>>
|
|
62
69
|
|
|
63
70
|
setItem(
|
|
@@ -65,11 +72,15 @@ class CacheClient {
|
|
|
65
72
|
, itemKey: string
|
|
66
73
|
, itemValue: JSONValue
|
|
67
74
|
, timeToLive: number | null
|
|
68
|
-
,
|
|
75
|
+
, signal?: AbortSignal
|
|
69
76
|
): Promise<void>
|
|
70
77
|
|
|
71
|
-
removeItem(
|
|
78
|
+
removeItem(
|
|
79
|
+
namespace: string
|
|
80
|
+
, itemKey: string
|
|
81
|
+
, signal?: AbortSignal
|
|
82
|
+
): Promise<void>
|
|
72
83
|
|
|
73
|
-
clearItemsByNamespace(namespace: string,
|
|
84
|
+
clearItemsByNamespace(namespace: string, signal?: AbortSignal): Promise<void>
|
|
74
85
|
}
|
|
75
86
|
```
|
package/lib/cache-client.d.ts
CHANGED
|
@@ -15,15 +15,15 @@ export declare class CacheClient {
|
|
|
15
15
|
static create(options: ICacheClientOptions): Promise<CacheClient>;
|
|
16
16
|
private constructor();
|
|
17
17
|
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,
|
|
18
|
+
getNamespaceStats(namespace: string, signal?: AbortSignal): Promise<INamespaceStats>;
|
|
19
|
+
getAllNamespaces(signal?: AbortSignal): Promise<string[]>;
|
|
20
|
+
getAllItemKeys(namespace: string, signal?: AbortSignal): Promise<string[]>;
|
|
21
|
+
hasItem(namespace: string, itemKey: string, signal?: AbortSignal): Promise<boolean>;
|
|
22
|
+
getItem(namespace: string, itemKey: string, signal?: AbortSignal): Promise<IItem | null>;
|
|
23
|
+
getItemValue(namespace: string, itemKey: string, signal?: AbortSignal): Promise<JSONValue | null>;
|
|
24
|
+
getItemValues(namespace: string, itemKeys: string[], signal?: AbortSignal): Promise<Array<JSONValue | null>>;
|
|
25
|
+
setItem(namespace: string, itemKey: string, itemValue: JSONValue, timeToLive: number | null, signal?: AbortSignal): Promise<void>;
|
|
26
|
+
removeItem(namespace: string, itemKey: string, signal?: AbortSignal): Promise<void>;
|
|
27
|
+
clearItemsByNamespace(namespace: string, signal?: AbortSignal): Promise<void>;
|
|
28
28
|
private withTimeout;
|
|
29
29
|
}
|
package/lib/cache-client.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { createRPCClient } from "./utils/rpc-client.js";
|
|
2
|
-
import { timeoutSignal, withAbortSignal } from 'extra-abort';
|
|
2
|
+
import { raceAbortSignals, timeoutSignal, withAbortSignal } from 'extra-abort';
|
|
3
|
+
import { isntUndefined } from '@blackglory/prelude';
|
|
3
4
|
export class CacheClient {
|
|
5
|
+
static async create(options) {
|
|
6
|
+
const { client, batchClient, proxy, close } = await createRPCClient(options.server, options.retryIntervalForReconnection);
|
|
7
|
+
return new CacheClient(client, batchClient, proxy, close, options.timeout);
|
|
8
|
+
}
|
|
4
9
|
constructor(client, batchClient, batchProxy, closeClients, timeout) {
|
|
5
10
|
this.client = client;
|
|
6
11
|
this.batchClient = batchClient;
|
|
@@ -8,53 +13,47 @@ export class CacheClient {
|
|
|
8
13
|
this.closeClients = closeClients;
|
|
9
14
|
this.timeout = timeout;
|
|
10
15
|
}
|
|
11
|
-
static async create(options) {
|
|
12
|
-
const { client, batchClient, proxy, close } = await createRPCClient(options.server, options.retryIntervalForReconnection);
|
|
13
|
-
return new CacheClient(client, batchClient, proxy, close, options.timeout);
|
|
14
|
-
}
|
|
15
16
|
async close() {
|
|
16
17
|
await this.closeClients();
|
|
17
18
|
}
|
|
18
|
-
async getNamespaceStats(namespace,
|
|
19
|
-
return await this.
|
|
19
|
+
async getNamespaceStats(namespace, signal) {
|
|
20
|
+
return await this.client.getNamespaceStats(namespace, this.withTimeout(signal));
|
|
20
21
|
}
|
|
21
|
-
async getAllNamespaces(
|
|
22
|
-
return await this.
|
|
22
|
+
async getAllNamespaces(signal) {
|
|
23
|
+
return await this.client.getAllNamespaces(this.withTimeout(signal));
|
|
23
24
|
}
|
|
24
|
-
async getAllItemKeys(namespace,
|
|
25
|
-
return await this.
|
|
25
|
+
async getAllItemKeys(namespace, signal) {
|
|
26
|
+
return await this.client.getAllItemKeys(namespace, this.withTimeout(signal));
|
|
26
27
|
}
|
|
27
|
-
async hasItem(namespace, itemKey,
|
|
28
|
-
return await this.
|
|
28
|
+
async hasItem(namespace, itemKey, signal) {
|
|
29
|
+
return await this.client.hasItem(namespace, itemKey, this.withTimeout(signal));
|
|
29
30
|
}
|
|
30
|
-
async getItem(namespace, itemKey,
|
|
31
|
-
return await this.
|
|
31
|
+
async getItem(namespace, itemKey, signal) {
|
|
32
|
+
return await this.client.getItem(namespace, itemKey, this.withTimeout(signal));
|
|
32
33
|
}
|
|
33
|
-
async getItemValue(namespace, itemKey,
|
|
34
|
-
return await this.
|
|
34
|
+
async getItemValue(namespace, itemKey, signal) {
|
|
35
|
+
return await this.client.getItemValue(namespace, itemKey, this.withTimeout(signal));
|
|
35
36
|
}
|
|
36
|
-
async getItemValues(namespace, itemKeys,
|
|
37
|
-
return await this.withTimeout(async () => {
|
|
37
|
+
async getItemValues(namespace, itemKeys, signal) {
|
|
38
|
+
return await withAbortSignal(this.withTimeout(signal), async () => {
|
|
38
39
|
const results = await this.batchClient.parallel(...itemKeys.map(key => this.batchProxy.getItemValue(namespace, key)));
|
|
39
40
|
return results.map(result => result.unwrap());
|
|
40
|
-
}
|
|
41
|
+
});
|
|
41
42
|
}
|
|
42
|
-
async setItem(namespace, itemKey, itemValue, timeToLive,
|
|
43
|
-
await this.
|
|
43
|
+
async setItem(namespace, itemKey, itemValue, timeToLive, signal) {
|
|
44
|
+
await this.client.setItem(namespace, itemKey, itemValue, timeToLive, this.withTimeout(signal));
|
|
44
45
|
}
|
|
45
|
-
async removeItem(namespace, itemKey,
|
|
46
|
-
await this.
|
|
46
|
+
async removeItem(namespace, itemKey, signal) {
|
|
47
|
+
await this.client.removeItem(namespace, itemKey, this.withTimeout(signal));
|
|
47
48
|
}
|
|
48
|
-
async clearItemsByNamespace(namespace,
|
|
49
|
-
await this.
|
|
49
|
+
async clearItemsByNamespace(namespace, signal) {
|
|
50
|
+
await this.client.clearItemsByNamespace(namespace, this.withTimeout(signal));
|
|
50
51
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return await fn();
|
|
57
|
-
}
|
|
52
|
+
withTimeout(signal) {
|
|
53
|
+
return raceAbortSignals([
|
|
54
|
+
isntUndefined(this.timeout) && timeoutSignal(this.timeout),
|
|
55
|
+
signal
|
|
56
|
+
]);
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
59
|
//# sourceMappingURL=cache-client.js.map
|
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,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;
|
|
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,MAAM,aAAa,CAAA;AAC9E,OAAO,EAAE,aAAa,EAAa,MAAM,qBAAqB,CAAA;AAS9D,MAAM,OAAO,WAAW;IACtB,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAA4B;QAC9C,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,KAA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C,UAAU,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5E,CAAC;IAED,KAAK,CAAC,qBAAqB,CACzB,SAAiB,EACjB,MAAoB;QAEpB,MAAM,IAAI,CAAC,MAAM,CAAC,qBAAqB,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAA;IAC9E,CAAC;IAEO,WAAW,CAAC,MAAoB;QACtC,OAAO,gBAAgB,CAAC;YACtB,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC;YAC1D,MAAM;SACP,CAAC,CAAA;IACJ,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blackglory/cache-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"files": [
|
|
@@ -18,22 +18,20 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"sideEffects": false,
|
|
20
20
|
"engines": {
|
|
21
|
-
"node": ">=
|
|
21
|
+
"node": ">=22"
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
24
|
"prepare": "ts-patch install -s",
|
|
25
|
-
"lint": "eslint --
|
|
26
|
-
"test": "
|
|
27
|
-
"test:debug": "cross-env NODE_OPTIONS=--experimental-vm-modules node --inspect-brk node_modules/.bin/jest --runInBand jest.config.cjs",
|
|
28
|
-
"test:coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage --config jest.config.cjs",
|
|
25
|
+
"lint": "eslint --quiet src __tests__",
|
|
26
|
+
"test": "vitest --run",
|
|
29
27
|
"prepublishOnly": "run-s prepare clean build",
|
|
30
28
|
"clean": "rimraf lib",
|
|
31
29
|
"build": "tsc --project tsconfig.build.json",
|
|
32
30
|
"docker:test": "run-s docker:test:clean docker:test:build docker:test:run docker:test:clean",
|
|
33
31
|
"docker:coverage": "run-s docker:test:clean docker:test:build docker:test:coverage docker:test:clean",
|
|
34
|
-
"docker:test:build": "docker
|
|
35
|
-
"docker:test:run": "docker
|
|
36
|
-
"docker:test:clean": "docker
|
|
32
|
+
"docker:test:build": "docker compose --project-name cache-js --file docker-compose.test.yml build",
|
|
33
|
+
"docker:test:run": "docker compose --project-name cache-js --file docker-compose.test.yml run --no-TTY --rm test",
|
|
34
|
+
"docker:test:clean": "docker compose --project-name cache-js --file docker-compose.test.yml down",
|
|
37
35
|
"release": "standard-version"
|
|
38
36
|
},
|
|
39
37
|
"husky": {
|
|
@@ -43,35 +41,35 @@
|
|
|
43
41
|
}
|
|
44
42
|
},
|
|
45
43
|
"devDependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"@commitlint/
|
|
48
|
-
"@
|
|
49
|
-
"@types/
|
|
50
|
-
"@
|
|
51
|
-
"@typescript-eslint/
|
|
52
|
-
"@typescript-eslint/parser": "^5.57.0",
|
|
44
|
+
"@commitlint/cli": "^19.8.1",
|
|
45
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
46
|
+
"@eslint/js": "^9.27.0",
|
|
47
|
+
"@types/ws": "^8.18.1",
|
|
48
|
+
"@typescript-eslint/eslint-plugin": "^8.33.0",
|
|
49
|
+
"@typescript-eslint/parser": "^8.33.0",
|
|
53
50
|
"cross-env": "^7.0.3",
|
|
54
|
-
"eslint": "^
|
|
51
|
+
"eslint": "^9.27.0",
|
|
55
52
|
"husky": "4",
|
|
56
|
-
"jest": "^29.5.0",
|
|
57
|
-
"jest-resolve": "^29.5.0",
|
|
58
53
|
"npm-run-all": "^4.1.5",
|
|
59
|
-
"rimraf": "^
|
|
54
|
+
"rimraf": "^6.0.1",
|
|
60
55
|
"standard-version": "^9.5.0",
|
|
61
|
-
"ts-
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"typescript": "
|
|
65
|
-
"typescript-transform-paths": "^3.
|
|
56
|
+
"ts-patch": "^3.3.0",
|
|
57
|
+
"tslib": "^2.8.1",
|
|
58
|
+
"typescript": "5.8.3",
|
|
59
|
+
"typescript-eslint": "^8.33.0",
|
|
60
|
+
"typescript-transform-paths": "^3.5.5",
|
|
61
|
+
"vite": "^6.3.5",
|
|
62
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
63
|
+
"vitest": "^3.1.4"
|
|
66
64
|
},
|
|
67
65
|
"dependencies": {
|
|
68
|
-
"@blackglory/prelude": "^0.
|
|
69
|
-
"@delight-rpc/extra-native-websocket": "^0.
|
|
70
|
-
"@delight-rpc/extra-websocket": "^0.
|
|
71
|
-
"delight-rpc": "^6.
|
|
72
|
-
"extra-abort": "^0.
|
|
73
|
-
"extra-native-websocket": "^0.
|
|
74
|
-
"extra-websocket": "^0.
|
|
75
|
-
"ws": "^8.
|
|
66
|
+
"@blackglory/prelude": "^0.4.0",
|
|
67
|
+
"@delight-rpc/extra-native-websocket": "^0.6.0",
|
|
68
|
+
"@delight-rpc/extra-websocket": "^0.7.0",
|
|
69
|
+
"delight-rpc": "^6.1.2",
|
|
70
|
+
"extra-abort": "^0.4.0",
|
|
71
|
+
"extra-native-websocket": "^0.4.1",
|
|
72
|
+
"extra-websocket": "^0.4.2",
|
|
73
|
+
"ws": "^8.18.2"
|
|
76
74
|
}
|
|
77
75
|
}
|
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 { timeoutSignal, withAbortSignal } from 'extra-abort'
|
|
5
|
-
import { JSONValue } from '@blackglory/prelude'
|
|
4
|
+
import { raceAbortSignals, timeoutSignal, withAbortSignal } from 'extra-abort'
|
|
5
|
+
import { isntUndefined, JSONValue } from '@blackglory/prelude'
|
|
6
6
|
export { INamespaceStats, IItem, IItemMetadata } from './contract.js'
|
|
7
7
|
|
|
8
8
|
export interface ICacheClientOptions {
|
|
@@ -34,74 +34,68 @@ export class CacheClient {
|
|
|
34
34
|
|
|
35
35
|
async getNamespaceStats(
|
|
36
36
|
namespace: string
|
|
37
|
-
,
|
|
37
|
+
, signal?: AbortSignal
|
|
38
38
|
): Promise<INamespaceStats> {
|
|
39
|
-
return await this.
|
|
40
|
-
|
|
41
|
-
,
|
|
39
|
+
return await this.client.getNamespaceStats(
|
|
40
|
+
namespace
|
|
41
|
+
, this.withTimeout(signal)
|
|
42
42
|
)
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
async getAllNamespaces(
|
|
46
|
-
return await this.
|
|
47
|
-
|
|
48
|
-
, timeout ?? this.timeout
|
|
45
|
+
async getAllNamespaces(signal?: AbortSignal): Promise<string[]> {
|
|
46
|
+
return await this.client.getAllNamespaces(
|
|
47
|
+
this.withTimeout(signal)
|
|
49
48
|
)
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
async getAllItemKeys(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
)
|
|
51
|
+
async getAllItemKeys(
|
|
52
|
+
namespace: string
|
|
53
|
+
, signal?: AbortSignal
|
|
54
|
+
): Promise<string[]> {
|
|
55
|
+
return await this.client.getAllItemKeys(namespace, this.withTimeout(signal))
|
|
57
56
|
}
|
|
58
57
|
|
|
59
58
|
async hasItem(
|
|
60
59
|
namespace: string
|
|
61
60
|
, itemKey: string
|
|
62
|
-
,
|
|
61
|
+
, signal?: AbortSignal
|
|
63
62
|
): Promise<boolean> {
|
|
64
|
-
return await this.withTimeout(
|
|
65
|
-
() => this.client.hasItem(namespace, itemKey)
|
|
66
|
-
, timeout ?? this.timeout
|
|
67
|
-
)
|
|
63
|
+
return await this.client.hasItem(namespace, itemKey, this.withTimeout(signal))
|
|
68
64
|
}
|
|
69
65
|
|
|
70
66
|
async getItem(
|
|
71
67
|
namespace: string
|
|
72
68
|
, itemKey: string
|
|
73
|
-
,
|
|
69
|
+
, signal?: AbortSignal
|
|
74
70
|
): Promise<IItem | null> {
|
|
75
|
-
return await this.withTimeout(
|
|
76
|
-
() => this.client.getItem(namespace, itemKey)
|
|
77
|
-
, timeout ?? this.timeout
|
|
78
|
-
)
|
|
71
|
+
return await this.client.getItem(namespace, itemKey, this.withTimeout(signal))
|
|
79
72
|
}
|
|
80
73
|
|
|
81
74
|
async getItemValue(
|
|
82
75
|
namespace: string
|
|
83
76
|
, itemKey: string
|
|
84
|
-
,
|
|
77
|
+
, signal?: AbortSignal
|
|
85
78
|
): Promise<JSONValue | null> {
|
|
86
|
-
return await this.
|
|
87
|
-
|
|
88
|
-
,
|
|
79
|
+
return await this.client.getItemValue(
|
|
80
|
+
namespace
|
|
81
|
+
, itemKey
|
|
82
|
+
, this.withTimeout(signal)
|
|
89
83
|
)
|
|
90
84
|
}
|
|
91
85
|
|
|
92
86
|
async getItemValues(
|
|
93
87
|
namespace: string
|
|
94
88
|
, itemKeys: string[]
|
|
95
|
-
,
|
|
89
|
+
, signal?: AbortSignal
|
|
96
90
|
): Promise<Array<JSONValue | null>> {
|
|
97
|
-
return await
|
|
98
|
-
|
|
91
|
+
return await withAbortSignal(
|
|
92
|
+
this.withTimeout(signal)
|
|
93
|
+
, async () => {
|
|
99
94
|
const results = await this.batchClient.parallel(
|
|
100
95
|
...itemKeys.map(key => this.batchProxy.getItemValue(namespace, key))
|
|
101
96
|
)
|
|
102
97
|
return results.map(result => result.unwrap())
|
|
103
98
|
}
|
|
104
|
-
, timeout ?? this.timeout
|
|
105
99
|
)
|
|
106
100
|
}
|
|
107
101
|
|
|
@@ -110,45 +104,36 @@ export class CacheClient {
|
|
|
110
104
|
, itemKey: string
|
|
111
105
|
, itemValue: JSONValue
|
|
112
106
|
, timeToLive: number | null
|
|
113
|
-
,
|
|
107
|
+
, signal?: AbortSignal
|
|
114
108
|
): Promise<void> {
|
|
115
|
-
await this.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
)
|
|
122
|
-
, timeout ?? this.timeout
|
|
109
|
+
await this.client.setItem(
|
|
110
|
+
namespace
|
|
111
|
+
, itemKey
|
|
112
|
+
, itemValue
|
|
113
|
+
, timeToLive
|
|
114
|
+
, this.withTimeout(signal)
|
|
123
115
|
)
|
|
124
116
|
}
|
|
125
117
|
|
|
126
118
|
async removeItem(
|
|
127
119
|
namespace: string
|
|
128
120
|
, itemKey: string
|
|
129
|
-
,
|
|
121
|
+
, signal?: AbortSignal
|
|
130
122
|
): Promise<void> {
|
|
131
|
-
await this.withTimeout(
|
|
132
|
-
() => this.client.removeItem(namespace, itemKey)
|
|
133
|
-
, timeout ?? this.timeout
|
|
134
|
-
)
|
|
123
|
+
await this.client.removeItem(namespace, itemKey, this.withTimeout(signal))
|
|
135
124
|
}
|
|
136
125
|
|
|
137
|
-
async clearItemsByNamespace(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
)
|
|
126
|
+
async clearItemsByNamespace(
|
|
127
|
+
namespace: string
|
|
128
|
+
, signal?: AbortSignal
|
|
129
|
+
): Promise<void> {
|
|
130
|
+
await this.client.clearItemsByNamespace(namespace, this.withTimeout(signal))
|
|
142
131
|
}
|
|
143
132
|
|
|
144
|
-
private
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return await withAbortSignal(timeoutSignal(timeout), fn)
|
|
150
|
-
} else {
|
|
151
|
-
return await fn()
|
|
152
|
-
}
|
|
133
|
+
private withTimeout(signal?: AbortSignal): AbortSignal {
|
|
134
|
+
return raceAbortSignals([
|
|
135
|
+
isntUndefined(this.timeout) && timeoutSignal(this.timeout)
|
|
136
|
+
, signal
|
|
137
|
+
])
|
|
153
138
|
}
|
|
154
139
|
}
|