@blackglory/cache-js 0.10.4 → 0.11.1

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, options.timeout);
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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AAC,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"}
@@ -1,6 +1,6 @@
1
1
  import { IAPI } from "../contract.js";
2
2
  import { ClientProxy, BatchClient, BatchClientProxy } from 'delight-rpc';
3
- export declare function createRPCClient(url: string, retryIntervalForReconnection?: number): Promise<{
3
+ export declare function createRPCClient(url: string, retryIntervalForReconnection?: number, timeout?: number): Promise<{
4
4
  client: ClientProxy<IAPI>;
5
5
  batchClient: BatchClient<IAPI>;
6
6
  proxy: BatchClientProxy<IAPI, unknown>;
@@ -2,10 +2,13 @@ import { expectedVersion } from "../contract.js";
2
2
  import { createBatchProxy } from 'delight-rpc';
3
3
  import { createClient, createBatchClient } from '@delight-rpc/extra-native-websocket';
4
4
  import { ExtraNativeWebSocket, autoReconnect } from 'extra-native-websocket';
5
- export async function createRPCClient(url, retryIntervalForReconnection) {
5
+ import { timeoutSignal } from 'extra-abort';
6
+ export async function createRPCClient(url, retryIntervalForReconnection, timeout) {
6
7
  const ws = new ExtraNativeWebSocket(() => new WebSocket(url));
7
- const cancelAutoReconnect = autoReconnect(ws, retryIntervalForReconnection);
8
- await ws.connect();
8
+ const cancelAutoReconnect = autoReconnect(ws, retryIntervalForReconnection, timeout);
9
+ await ws.connect(timeout
10
+ ? timeoutSignal(timeout)
11
+ : undefined);
9
12
  const [client, closeClient] = createClient(ws, { expectedVersion });
10
13
  const [batchClient, closeBatchClient] = createBatchClient(ws, { expectedVersion });
11
14
  const proxy = createBatchProxy();
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-client.browser.js","sourceRoot":"","sources":["../../src/utils/rpc-client.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,eAAe,EAAE,uBAAwB;AACxD,OAAO,EAA8C,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC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EAAE,MAAM,aAAa,CAAA;AAE3C,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,GAAW,EACX,4BAAqC,EACrC,OAAgB;IAOhB,MAAM,EAAE,GAAG,IAAI,oBAAoB,CAAC,GAAG,EAAE,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC,CAAA;IAC7D,MAAM,mBAAmB,GAAG,aAAa,CACvC,EAAE,EACF,4BAA4B,EAC5B,OAAO,CACR,CAAA;IACD,MAAM,EAAE,CAAC,OAAO,CACd,OAAO;QACT,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC;QACxB,CAAC,CAAC,SAAS,CACV,CAAA;IAED,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,YAAY,CAAO,EAAE,EAAE,EAAE,eAAe,EAAE,CAAC,CAAA;IACzE,MAAM,CAAC,WAAW,EAAE,gBAAgB,CAAC,GAAG,iBAAiB,CAAC,EAAE,EAAE,EAAE,eAAe,EAAE,CAAC,CAAA;IAClF,MAAM,KAAK,GAAG,gBAAgB,EAAQ,CAAA;IAEtC,OAAO;QACL,MAAM;QACN,WAAW;QACX,KAAK;QACL,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,WAAW,EAAE,CAAA;YACb,gBAAgB,EAAE,CAAA;YAClB,mBAAmB,EAAE,CAAA;YACrB,MAAM,EAAE,CAAC,KAAK,EAAE,CAAA;QAClB,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { IAPI } from "../contract.js";
2
2
  import { ClientProxy, BatchClient, BatchClientProxy } from 'delight-rpc';
3
- export declare function createRPCClient(url: string, retryIntervalForReconnection?: number): Promise<{
3
+ export declare function createRPCClient(url: string, retryIntervalForReconnection?: number, timeout?: number): Promise<{
4
4
  client: ClientProxy<IAPI>;
5
5
  batchClient: BatchClient<IAPI>;
6
6
  proxy: BatchClientProxy<IAPI, unknown>;
@@ -2,11 +2,14 @@ import { expectedVersion } from "../contract.js";
2
2
  import { createBatchProxy } from 'delight-rpc';
3
3
  import { createClient, createBatchClient } from '@delight-rpc/extra-websocket';
4
4
  import { WebSocket } from 'ws';
5
+ import { timeoutSignal } from 'extra-abort';
5
6
  import { ExtraWebSocket, autoReconnect } from 'extra-websocket';
6
- export async function createRPCClient(url, retryIntervalForReconnection) {
7
+ export async function createRPCClient(url, retryIntervalForReconnection, timeout) {
7
8
  const ws = new ExtraWebSocket(() => new WebSocket(url));
8
- const cancelAutoReconnect = autoReconnect(ws, retryIntervalForReconnection);
9
- await ws.connect();
9
+ const cancelAutoReconnect = autoReconnect(ws, retryIntervalForReconnection, timeout);
10
+ await ws.connect(timeout
11
+ ? timeoutSignal(timeout)
12
+ : undefined);
10
13
  const [client, closeClient] = createClient(ws, { expectedVersion });
11
14
  const [batchClient, closeBatchClient] = createBatchClient(ws, { expectedVersion });
12
15
  const proxy = createBatchProxy();
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-client.js","sourceRoot":"","sources":["../../src/utils/rpc-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,eAAe,EAAE,uBAAwB;AACxD,OAAO,EAA8C,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC1F,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAA;AAC9B,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/D,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,GAAW,EACX,4BAAqC;IAOrC,MAAM,EAAE,GAAG,IAAI,cAAc,CAAC,GAAG,EAAE,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC,CAAA;IACvD,MAAM,mBAAmB,GAAG,aAAa,CAAC,EAAE,EAAE,4BAA4B,CAAC,CAAA;IAC3E,MAAM,EAAE,CAAC,OAAO,EAAE,CAAA;IAElB,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,YA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M,EAAE,WAAW,CAAC,GAAG,YAAY,CAAO,EAAE,EAAE,EAAE,eAAe,EAAE,CAAC,CAAA;IACzE,MAAM,CAAC,WAAW,EAAE,gBAAgB,CAAC,GAAG,iBAAiB,CAAC,EAAE,EAAE,EAAE,eAAe,EAAE,CAAC,CAAA;IAClF,MAAM,KAAK,GAAG,gBAAgB,EAAQ,CAAA;IAEtC,OAAO;QACL,MAAM;QACN,WAAW;QACX,KAAK;QACL,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,WAAW,EAAE,CAAA;YACb,gBAAgB,EAAE,CAAA;YAClB,mBAAmB,EAAE,CAAA;YACrB,MAAM,EAAE,CAAC,KAAK,EAAE,CAAA;QAClB,CAAC;KACF,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blackglory/cache-js",
3
- "version": "0.10.4",
3
+ "version": "0.11.1",
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,33 @@
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",
53
48
  "cross-env": "^7.0.3",
54
- "eslint": "^8.36.0",
49
+ "eslint": "^9.27.0",
55
50
  "husky": "4",
56
- "jest": "^29.5.0",
57
- "jest-resolve": "^29.5.0",
58
51
  "npm-run-all": "^4.1.5",
59
- "rimraf": "^3.0.2",
52
+ "rimraf": "^6.0.1",
60
53
  "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"
54
+ "ts-patch": "^3.3.0",
55
+ "tslib": "^2.8.1",
56
+ "typescript": "5.8.3",
57
+ "typescript-eslint": "^8.33.0",
58
+ "typescript-transform-paths": "^3.5.5",
59
+ "vite": "^6.3.5",
60
+ "vite-tsconfig-paths": "^5.1.4",
61
+ "vitest": "^3.1.4"
66
62
  },
67
63
  "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"
64
+ "@blackglory/prelude": "^0.4.0",
65
+ "@delight-rpc/extra-native-websocket": "^0.6.0",
66
+ "@delight-rpc/extra-websocket": "^0.7.0",
67
+ "delight-rpc": "^6.1.2",
68
+ "extra-abort": "^0.4.0",
69
+ "extra-native-websocket": "^0.4.1",
70
+ "extra-websocket": "^0.4.2",
71
+ "ws": "^8.18.2"
76
72
  }
77
73
  }
@@ -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 {
@@ -16,6 +16,7 @@ export class CacheClient {
16
16
  const { client, batchClient, proxy, close } = await createRPCClient(
17
17
  options.server
18
18
  , options.retryIntervalForReconnection
19
+ , options.timeout
19
20
  )
20
21
  return new CacheClient(client, batchClient, proxy, close, options.timeout)
21
22
  }
@@ -34,74 +35,68 @@ export class CacheClient {
34
35
 
35
36
  async getNamespaceStats(
36
37
  namespace: string
37
- , timeout?: number
38
+ , signal?: AbortSignal
38
39
  ): Promise<INamespaceStats> {
39
- return await this.withTimeout(
40
- () => this.client.getNamespaceStats(namespace)
41
- , timeout ?? this.timeout
40
+ return await this.client.getNamespaceStats(
41
+ namespace
42
+ , this.withTimeout(signal)
42
43
  )
43
44
  }
44
45
 
45
- async getAllNamespaces(timeout?: number): Promise<string[]> {
46
- return await this.withTimeout(
47
- () => this.client.getAllNamespaces()
48
- , timeout ?? this.timeout
46
+ async getAllNamespaces(signal?: AbortSignal): Promise<string[]> {
47
+ return await this.client.getAllNamespaces(
48
+ this.withTimeout(signal)
49
49
  )
50
50
  }
51
51
 
52
- async getAllItemKeys(namespace: string, timeout?: number): Promise<string[]> {
53
- return await this.withTimeout(
54
- () => this.client.getAllItemKeys(namespace)
55
- , timeout ?? this.timeout
56
- )
52
+ async getAllItemKeys(
53
+ namespace: string
54
+ , signal?: AbortSignal
55
+ ): Promise<string[]> {
56
+ return await this.client.getAllItemKeys(namespace, this.withTimeout(signal))
57
57
  }
58
58
 
59
59
  async hasItem(
60
60
  namespace: string
61
61
  , itemKey: string
62
- , timeout?: number
62
+ , signal?: AbortSignal
63
63
  ): Promise<boolean> {
64
- return await this.withTimeout(
65
- () => this.client.hasItem(namespace, itemKey)
66
- , timeout ?? this.timeout
67
- )
64
+ return await this.client.hasItem(namespace, itemKey, this.withTimeout(signal))
68
65
  }
69
66
 
70
67
  async getItem(
71
68
  namespace: string
72
69
  , itemKey: string
73
- , timeout?: number
70
+ , signal?: AbortSignal
74
71
  ): Promise<IItem | null> {
75
- return await this.withTimeout(
76
- () => this.client.getItem(namespace, itemKey)
77
- , timeout ?? this.timeout
78
- )
72
+ return await this.client.getItem(namespace, itemKey, this.withTimeout(signal))
79
73
  }
80
74
 
81
75
  async getItemValue(
82
76
  namespace: string
83
77
  , itemKey: string
84
- , timeout?: number
78
+ , signal?: AbortSignal
85
79
  ): Promise<JSONValue | null> {
86
- return await this.withTimeout(
87
- () => this.client.getItemValue(namespace, itemKey)
88
- , timeout ?? this.timeout
80
+ return await this.client.getItemValue(
81
+ namespace
82
+ , itemKey
83
+ , this.withTimeout(signal)
89
84
  )
90
85
  }
91
86
 
92
87
  async getItemValues(
93
88
  namespace: string
94
89
  , itemKeys: string[]
95
- , timeout?: number
90
+ , signal?: AbortSignal
96
91
  ): Promise<Array<JSONValue | null>> {
97
- return await this.withTimeout(
98
- async () => {
92
+ return await withAbortSignal(
93
+ this.withTimeout(signal)
94
+ , async () => {
99
95
  const results = await this.batchClient.parallel(
100
96
  ...itemKeys.map(key => this.batchProxy.getItemValue(namespace, key))
101
97
  )
102
98
  return results.map(result => result.unwrap())
103
99
  }
104
- , timeout ?? this.timeout
105
100
  )
106
101
  }
107
102
 
@@ -110,45 +105,36 @@ export class CacheClient {
110
105
  , itemKey: string
111
106
  , itemValue: JSONValue
112
107
  , timeToLive: number | null
113
- , timeout?: number
108
+ , signal?: AbortSignal
114
109
  ): Promise<void> {
115
- await this.withTimeout(
116
- () => this.client.setItem(
117
- namespace
118
- , itemKey
119
- , itemValue
120
- , timeToLive
121
- )
122
- , timeout ?? this.timeout
110
+ await this.client.setItem(
111
+ namespace
112
+ , itemKey
113
+ , itemValue
114
+ , timeToLive
115
+ , this.withTimeout(signal)
123
116
  )
124
117
  }
125
118
 
126
119
  async removeItem(
127
120
  namespace: string
128
121
  , itemKey: string
129
- , timeout?: number
122
+ , signal?: AbortSignal
130
123
  ): Promise<void> {
131
- await this.withTimeout(
132
- () => this.client.removeItem(namespace, itemKey)
133
- , timeout ?? this.timeout
134
- )
124
+ await this.client.removeItem(namespace, itemKey, this.withTimeout(signal))
135
125
  }
136
126
 
137
- async clearItemsByNamespace(namespace: string, timeout?: number): Promise<void> {
138
- await this.withTimeout(
139
- () => this.client.clearItemsByNamespace(namespace)
140
- , timeout ?? this.timeout
141
- )
127
+ async clearItemsByNamespace(
128
+ namespace: string
129
+ , signal?: AbortSignal
130
+ ): Promise<void> {
131
+ await this.client.clearItemsByNamespace(namespace, this.withTimeout(signal))
142
132
  }
143
133
 
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
- }
134
+ private withTimeout(signal?: AbortSignal): AbortSignal {
135
+ return raceAbortSignals([
136
+ isntUndefined(this.timeout) && timeoutSignal(this.timeout)
137
+ , signal
138
+ ])
153
139
  }
154
140
  }
@@ -2,10 +2,12 @@ import { IAPI, expectedVersion } from '@src/contract.js'
2
2
  import { ClientProxy, BatchClient, BatchClientProxy, createBatchProxy } from 'delight-rpc'
3
3
  import { createClient, createBatchClient } from '@delight-rpc/extra-native-websocket'
4
4
  import { ExtraNativeWebSocket, autoReconnect } from 'extra-native-websocket'
5
+ import { timeoutSignal } from 'extra-abort'
5
6
 
6
7
  export async function createRPCClient(
7
8
  url: string
8
9
  , retryIntervalForReconnection?: number
10
+ , timeout?: number
9
11
  ): Promise<{
10
12
  client: ClientProxy<IAPI>
11
13
  batchClient: BatchClient<IAPI>
@@ -13,8 +15,16 @@ export async function createRPCClient(
13
15
  close: () => Promise<void>
14
16
  }> {
15
17
  const ws = new ExtraNativeWebSocket(() => new WebSocket(url))
16
- const cancelAutoReconnect = autoReconnect(ws, retryIntervalForReconnection)
17
- await ws.connect()
18
+ const cancelAutoReconnect = autoReconnect(
19
+ ws
20
+ , retryIntervalForReconnection
21
+ , timeout
22
+ )
23
+ await ws.connect(
24
+ timeout
25
+ ? timeoutSignal(timeout)
26
+ : undefined
27
+ )
18
28
 
19
29
  const [client, closeClient] = createClient<IAPI>(ws, { expectedVersion })
20
30
  const [batchClient, closeBatchClient] = createBatchClient(ws, { expectedVersion })
@@ -2,11 +2,13 @@ import { IAPI, expectedVersion } from '@src/contract.js'
2
2
  import { ClientProxy, BatchClient, BatchClientProxy, createBatchProxy } from 'delight-rpc'
3
3
  import { createClient, createBatchClient } from '@delight-rpc/extra-websocket'
4
4
  import { WebSocket } from 'ws'
5
+ import { timeoutSignal } from 'extra-abort'
5
6
  import { ExtraWebSocket, autoReconnect } from 'extra-websocket'
6
7
 
7
8
  export async function createRPCClient(
8
9
  url: string
9
10
  , retryIntervalForReconnection?: number
11
+ , timeout?: number
10
12
  ): Promise<{
11
13
  client: ClientProxy<IAPI>
12
14
  batchClient: BatchClient<IAPI>
@@ -14,8 +16,16 @@ export async function createRPCClient(
14
16
  close: () => Promise<void>
15
17
  }> {
16
18
  const ws = new ExtraWebSocket(() => new WebSocket(url))
17
- const cancelAutoReconnect = autoReconnect(ws, retryIntervalForReconnection)
18
- await ws.connect()
19
+ const cancelAutoReconnect = autoReconnect(
20
+ ws
21
+ , retryIntervalForReconnection
22
+ , timeout
23
+ )
24
+ await ws.connect(
25
+ timeout
26
+ ? timeoutSignal(timeout)
27
+ : undefined
28
+ )
19
29
 
20
30
  const [client, closeClient] = createClient<IAPI>(ws, { expectedVersion })
21
31
  const [batchClient, closeBatchClient] = createBatchClient(ws, { expectedVersion })