@blackglory/cache-js 0.10.3 → 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 CHANGED
@@ -34,30 +34,37 @@ class CacheClient {
34
34
 
35
35
  close(): Promise<void>
36
36
 
37
- getNamespaceStats(namespace: string, timeout?: number): Promise<INamespaceStats>
37
+ getNamespaceStats(
38
+ namespace: string
39
+ , signal?: AbortSignal
40
+ ): Promise<INamespaceStats>
38
41
 
39
- getAllNamespaces(timeout?: number): Promise<string[]>
42
+ getAllNamespaces(signal?: AbortSignal): Promise<string[]>
40
43
 
41
- getAllItemKeys(namespace: string, timeout?: number): Promise<string[]>
44
+ getAllItemKeys(namespace: string, signal?: AbortSignal): Promise<string[]>
42
45
 
43
- hasItem(namespace: string, itemKey: string, timeout?: number): Promise<boolean>
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
- , timeout?: number
55
+ , signal?: AbortSignal
49
56
  ): Promise<IItem | null>
50
57
 
51
58
  getItemValue(
52
59
  namespace: string
53
60
  , itemKey: string
54
- , timeout?: number
61
+ , signal?: AbortSignal
55
62
  ): Promise<JSONValue | null>
56
63
 
57
64
  getItemValues(
58
65
  namespace: string
59
66
  , itemKeys: string[]
60
- , timeout?: number
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
- , timeout?: number
75
+ , signal?: AbortSignal
69
76
  ): Promise<void>
70
77
 
71
- removeItem(namespace: string, itemKey: string, timeout?: number): Promise<void>
78
+ removeItem(
79
+ namespace: string
80
+ , itemKey: string
81
+ , signal?: AbortSignal
82
+ ): Promise<void>
72
83
 
73
- clearItemsByNamespace(namespace: string, timeout?: number): Promise<void>
84
+ clearItemsByNamespace(namespace: string, signal?: AbortSignal): Promise<void>
74
85
  }
75
86
  ```
@@ -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, timeout?: number): Promise<INamespaceStats>;
19
- getAllNamespaces(timeout?: number): Promise<string[]>;
20
- getAllItemKeys(namespace: string, timeout?: number): Promise<string[]>;
21
- hasItem(namespace: string, itemKey: string, timeout?: number): Promise<boolean>;
22
- getItem(namespace: string, itemKey: string, timeout?: number): Promise<IItem | null>;
23
- getItemValue(namespace: string, itemKey: string, timeout?: number): Promise<JSONValue | null>;
24
- getItemValues(namespace: string, itemKeys: string[], timeout?: number): Promise<Array<JSONValue | null>>;
25
- setItem(namespace: string, itemKey: string, itemValue: JSONValue, timeToLive: number | null, timeout?: number): Promise<void>;
26
- removeItem(namespace: string, itemKey: string, timeout?: number): Promise<void>;
27
- clearItemsByNamespace(namespace: string, timeout?: number): Promise<void>;
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
  }
@@ -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, timeout) {
19
- return await this.withTimeout(() => this.client.getNamespaceStats(namespace), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
19
+ async getNamespaceStats(namespace, signal) {
20
+ return await this.client.getNamespaceStats(namespace, this.withTimeout(signal));
20
21
  }
21
- async getAllNamespaces(timeout) {
22
- return await this.withTimeout(() => this.client.getAllNamespaces(), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
22
+ async getAllNamespaces(signal) {
23
+ return await this.client.getAllNamespaces(this.withTimeout(signal));
23
24
  }
24
- async getAllItemKeys(namespace, timeout) {
25
- return await this.withTimeout(() => this.client.getAllItemKeys(namespace), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
25
+ async getAllItemKeys(namespace, signal) {
26
+ return await this.client.getAllItemKeys(namespace, this.withTimeout(signal));
26
27
  }
27
- async hasItem(namespace, itemKey, timeout) {
28
- return await this.withTimeout(() => this.client.hasItem(namespace, itemKey), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
28
+ async hasItem(namespace, itemKey, signal) {
29
+ return await this.client.hasItem(namespace, itemKey, this.withTimeout(signal));
29
30
  }
30
- async getItem(namespace, itemKey, timeout) {
31
- return await this.withTimeout(() => this.client.getItem(namespace, itemKey), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
31
+ async getItem(namespace, itemKey, signal) {
32
+ return await this.client.getItem(namespace, itemKey, this.withTimeout(signal));
32
33
  }
33
- async getItemValue(namespace, itemKey, timeout) {
34
- return await this.withTimeout(() => this.client.getItemValue(namespace, itemKey), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
34
+ async getItemValue(namespace, itemKey, signal) {
35
+ return await this.client.getItemValue(namespace, itemKey, this.withTimeout(signal));
35
36
  }
36
- async getItemValues(namespace, itemKeys, timeout) {
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
- }, timeout !== null && timeout !== void 0 ? timeout : this.timeout);
41
+ });
41
42
  }
42
- async setItem(namespace, itemKey, itemValue, timeToLive, timeout) {
43
- await this.withTimeout(() => this.client.setItem(namespace, itemKey, itemValue, timeToLive), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
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, timeout) {
46
- await this.withTimeout(() => this.client.removeItem(namespace, itemKey), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
46
+ async removeItem(namespace, itemKey, signal) {
47
+ await this.client.removeItem(namespace, itemKey, this.withTimeout(signal));
47
48
  }
48
- async clearItemsByNamespace(namespace, timeout) {
49
- await this.withTimeout(() => this.client.clearItemsByNamespace(namespace), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
49
+ async clearItemsByNamespace(namespace, signal) {
50
+ await this.client.clearItemsByNamespace(namespace, this.withTimeout(signal));
50
51
  }
51
- async withTimeout(fn, timeout = this.timeout) {
52
- if (timeout) {
53
- return await withAbortSignal(timeoutSignal(timeout), fn);
54
- }
55
- else {
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
@@ -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;AAU5D,MAAM,OAAO,WAAW;IAStB,YACU,MAAyB,EACzB,WAAwB,EACxB,UAA2C,EAC3C,YAAiC,EACjC,OAAgB;QAJhB,WAAM,GAAN,MAAM,CAAmB;QACzB,gBAAW,GAAX,WAAW,CAAa;QACxB,eAAU,GAAV,UAAU,CAAiC;QAC3C,iBAAY,GAAZ,YAAY,CAAqB;QACjC,YAAO,GAAP,OAAO,CAAS;IACvB,CAAC;IAdJ,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,CACrC,CAAA;QACD,OAAO,IAAI,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IAC5E,CAAC;IAUD,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,YAAY,EAAE,CAAA;IAC3B,CAAC;IAED,KAAK,CAAC,iBAAiB,CACrB,SAAiB,EACjB,OAAgB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,CAAC;YACtB,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC;YAC1D,MAAM;SACP,CAAC,CAAA;IACJ,CAAC;CACF"}
package/lib/contract.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { JSONValue } from '@blackglory/prelude';
2
- export declare const expectedVersion = "^0.9.0";
2
+ export declare const expectedVersion = "^0.9.0 || ^0.10.0";
3
3
  export interface INamespaceStats {
4
4
  items: number;
5
5
  }
package/lib/contract.js CHANGED
@@ -1,2 +1,2 @@
1
- export const expectedVersion = '^0.9.0';
1
+ export const expectedVersion = '^0.9.0 || ^0.10.0';
2
2
  //# sourceMappingURL=contract.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAA"}
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,eAAe,GAAG,mBAAmB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blackglory/cache-js",
3
- "version": "0.10.3",
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": ">=16"
21
+ "node": ">=22"
22
22
  },
23
23
  "scripts": {
24
24
  "prepare": "ts-patch install -s",
25
- "lint": "eslint --ext .js,.jsx,.ts,.tsx --quiet src __tests__",
26
- "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --no-cache --config jest.config.cjs",
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-compose --project-name cache-js --file docker-compose.test.yml build",
35
- "docker:test:run": "docker-compose --project-name cache-js --file docker-compose.test.yml run --rm test",
36
- "docker:test:clean": "docker-compose --project-name cache-js --file docker-compose.test.yml down",
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
- "@blackglory/jest-resolver": "^0.3.0",
47
- "@commitlint/cli": "^17.5.1",
48
- "@commitlint/config-conventional": "^17.4.4",
49
- "@types/jest": "^29.5.0",
50
- "@types/ws": "^8.5.4",
51
- "@typescript-eslint/eslint-plugin": "^5.57.0",
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": "^8.36.0",
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": "^3.0.2",
54
+ "rimraf": "^6.0.1",
60
55
  "standard-version": "^9.5.0",
61
- "ts-jest": "^29.0.5",
62
- "ts-patch": "^2.1.0",
63
- "tslib": "^2.5.0",
64
- "typescript": "4.8",
65
- "typescript-transform-paths": "^3.4.6"
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.3.1",
69
- "@delight-rpc/extra-native-websocket": "^0.5.1",
70
- "@delight-rpc/extra-websocket": "^0.6.1",
71
- "delight-rpc": "^6.0.1",
72
- "extra-abort": "^0.3.4",
73
- "extra-native-websocket": "^0.3.1",
74
- "extra-websocket": "^0.3.0",
75
- "ws": "^8.13.0"
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
  }
@@ -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
- , timeout?: number
37
+ , signal?: AbortSignal
38
38
  ): Promise<INamespaceStats> {
39
- return await this.withTimeout(
40
- () => this.client.getNamespaceStats(namespace)
41
- , timeout ?? this.timeout
39
+ return await this.client.getNamespaceStats(
40
+ namespace
41
+ , this.withTimeout(signal)
42
42
  )
43
43
  }
44
44
 
45
- async getAllNamespaces(timeout?: number): Promise<string[]> {
46
- return await this.withTimeout(
47
- () => this.client.getAllNamespaces()
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(namespace: string, timeout?: number): Promise<string[]> {
53
- return await this.withTimeout(
54
- () => this.client.getAllItemKeys(namespace)
55
- , timeout ?? this.timeout
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
- , timeout?: number
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
- , timeout?: number
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
- , timeout?: number
77
+ , signal?: AbortSignal
85
78
  ): Promise<JSONValue | null> {
86
- return await this.withTimeout(
87
- () => this.client.getItemValue(namespace, itemKey)
88
- , timeout ?? this.timeout
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
- , timeout?: number
89
+ , signal?: AbortSignal
96
90
  ): Promise<Array<JSONValue | null>> {
97
- return await this.withTimeout(
98
- async () => {
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
- , timeout?: number
107
+ , signal?: AbortSignal
114
108
  ): Promise<void> {
115
- await this.withTimeout(
116
- () => this.client.setItem(
117
- namespace
118
- , itemKey
119
- , itemValue
120
- , timeToLive
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
- , timeout?: number
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(namespace: string, timeout?: number): Promise<void> {
138
- await this.withTimeout(
139
- () => this.client.clearItemsByNamespace(namespace)
140
- , timeout ?? this.timeout
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 async withTimeout<T>(
145
- fn: () => PromiseLike<T>
146
- , timeout: number | undefined = this.timeout
147
- ): Promise<T> {
148
- if (timeout) {
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
  }
package/src/contract.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { JSONValue } from '@blackglory/prelude'
2
2
 
3
- export const expectedVersion = '^0.9.0'
3
+ export const expectedVersion = '^0.9.0 || ^0.10.0'
4
4
 
5
5
  export interface INamespaceStats {
6
6
  items: number