@blackglory/cache-js 0.8.1 → 0.9.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 +23 -17
- package/lib/cache.d.ts +10 -10
- package/lib/cache.js +23 -23
- package/lib/cache.js.map +1 -1
- package/lib/contract.d.ts +11 -11
- package/lib/contract.js +1 -1
- package/lib/contract.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,31 +23,37 @@ interface ICacheClientOptions {
|
|
|
23
23
|
class CacheClient {
|
|
24
24
|
static create(options: ICacheClientOptions): Promise<CacheClient>
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
,
|
|
29
|
-
|
|
30
|
-
,
|
|
31
|
-
|
|
32
|
-
): Promise<
|
|
26
|
+
close(): Promise<void>
|
|
27
|
+
|
|
28
|
+
stats(namespace: string, timeout?: number): Promise<IStats>
|
|
29
|
+
getAllNamespaces(timeout?: number): Promise<string[]>
|
|
30
|
+
getAllItemKeys(namespace: string, timeout?: number): Promise<string[]>
|
|
31
|
+
|
|
32
|
+
hasItem(namespace: string, key: string, timeout?: number): Promise<boolean>
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
getItem(namespace: string, key: string, timeout?: number): Promise<string | null>
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
getItemWithMetadata(namespace: string, key: string, timeout?: number): Promise<{
|
|
37
|
+
value: string
|
|
38
|
+
metadata: IMetadata
|
|
39
|
+
} | null>
|
|
40
|
+
|
|
41
|
+
getItems(
|
|
38
42
|
namespace: string
|
|
39
43
|
, keys: string[]
|
|
40
44
|
, timeout?: number
|
|
41
45
|
): Promise<Array<string | null>>
|
|
42
46
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
setItem(
|
|
48
|
+
namespace: string
|
|
49
|
+
, key: string
|
|
50
|
+
, value: string
|
|
51
|
+
, timeToLive: number | null
|
|
52
|
+
, timeout?: number
|
|
53
|
+
): Promise<void>
|
|
48
54
|
|
|
49
|
-
|
|
55
|
+
removeItem(namespace: string, key: string, timeout?: number): Promise<void>
|
|
50
56
|
|
|
51
|
-
|
|
57
|
+
clearItemsByNamespace(namespace: string, timeout?: number): Promise<void>
|
|
52
58
|
}
|
|
53
59
|
```
|
package/lib/cache.d.ts
CHANGED
|
@@ -15,21 +15,21 @@ export declare class CacheClient {
|
|
|
15
15
|
private batchProxy;
|
|
16
16
|
private closeClients;
|
|
17
17
|
private timeout?;
|
|
18
|
+
stats(namespace: string, timeout?: number): Promise<IStats>;
|
|
19
|
+
getAllNamespaces(timeout?: number): Promise<string[]>;
|
|
20
|
+
getAllItemKeys(namespace: string, timeout?: number): Promise<string[]>;
|
|
18
21
|
private constructor();
|
|
19
22
|
static create(options: ICacheClientOptions): Promise<CacheClient>;
|
|
20
23
|
close(): Promise<void>;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
hasItem(namespace: string, key: string, timeout?: number): Promise<boolean>;
|
|
25
|
+
getItem(namespace: string, key: string, timeout?: number): Promise<string | null>;
|
|
26
|
+
getItemWithMetadata(namespace: string, key: string, timeout?: number): Promise<{
|
|
24
27
|
value: string;
|
|
25
28
|
metadata: IMetadata;
|
|
26
29
|
} | null>;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
getAllItemKeys(namespace: string, timeout?: number): Promise<string[]>;
|
|
32
|
-
getAllNamespaces(timeout?: number): Promise<string[]>;
|
|
33
|
-
stats(namespace: string, timeout?: number): Promise<IStats>;
|
|
30
|
+
getItems(namespace: string, keys: string[], timeout?: number): Promise<Array<string | null>>;
|
|
31
|
+
setItem(namespace: string, key: string, value: string, timeToLive: number | null, timeout?: number): Promise<void>;
|
|
32
|
+
removeItem(namespace: string, key: string, timeout?: number): Promise<void>;
|
|
33
|
+
clearItemsByNamespace(namespace: string, timeout?: number): Promise<void>;
|
|
34
34
|
private withTimeout;
|
|
35
35
|
}
|
package/lib/cache.js
CHANGED
|
@@ -9,6 +9,15 @@ export class CacheClient {
|
|
|
9
9
|
this.closeClients = closeClients;
|
|
10
10
|
this.timeout = timeout;
|
|
11
11
|
}
|
|
12
|
+
async stats(namespace, timeout) {
|
|
13
|
+
return await this.withTimeout(() => this.client.stats(namespace), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
|
|
14
|
+
}
|
|
15
|
+
async getAllNamespaces(timeout) {
|
|
16
|
+
return await this.withTimeout(() => this.client.getAllNamespaces(), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
|
|
17
|
+
}
|
|
18
|
+
async getAllItemKeys(namespace, timeout) {
|
|
19
|
+
return await this.withTimeout(() => this.client.getAllItemKeys(namespace), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
|
|
20
|
+
}
|
|
12
21
|
static async create(options) {
|
|
13
22
|
const { client, batchClient, proxy, close } = await createRPCClient(options.server);
|
|
14
23
|
return new CacheClient(client, batchClient, proxy, close, options.timeout);
|
|
@@ -16,15 +25,15 @@ export class CacheClient {
|
|
|
16
25
|
async close() {
|
|
17
26
|
await this.closeClients();
|
|
18
27
|
}
|
|
19
|
-
async
|
|
20
|
-
return await this.withTimeout(() => this.client.
|
|
28
|
+
async hasItem(namespace, key, timeout) {
|
|
29
|
+
return await this.withTimeout(() => this.client.hasItem(namespace, key), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
|
|
21
30
|
}
|
|
22
|
-
async
|
|
23
|
-
return await this.withTimeout(() => this.client.
|
|
31
|
+
async getItem(namespace, key, timeout) {
|
|
32
|
+
return await this.withTimeout(() => this.client.getItem(namespace, key), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
|
|
24
33
|
}
|
|
25
|
-
async
|
|
34
|
+
async getItemWithMetadata(namespace, key, timeout) {
|
|
26
35
|
return await this.withTimeout(async () => {
|
|
27
|
-
const result = await this.client.
|
|
36
|
+
const result = await this.client.getItemWithMetadata(namespace, key);
|
|
28
37
|
if (isNull(result))
|
|
29
38
|
return null;
|
|
30
39
|
return {
|
|
@@ -36,29 +45,20 @@ export class CacheClient {
|
|
|
36
45
|
};
|
|
37
46
|
}, timeout !== null && timeout !== void 0 ? timeout : this.timeout);
|
|
38
47
|
}
|
|
39
|
-
async
|
|
48
|
+
async getItems(namespace, keys, timeout) {
|
|
40
49
|
return await this.withTimeout(async () => {
|
|
41
|
-
const results = await this.batchClient.parallel(...keys.map(key => this.batchProxy.
|
|
50
|
+
const results = await this.batchClient.parallel(...keys.map(key => this.batchProxy.getItem(namespace, key)));
|
|
42
51
|
return results.map(result => result.unwrap());
|
|
43
52
|
}, timeout !== null && timeout !== void 0 ? timeout : this.timeout);
|
|
44
53
|
}
|
|
45
|
-
async
|
|
46
|
-
await this.withTimeout(() => this.client.
|
|
54
|
+
async setItem(namespace, key, value, timeToLive, timeout) {
|
|
55
|
+
await this.withTimeout(() => this.client.setItem(namespace, key, value, timeToLive), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
|
|
47
56
|
}
|
|
48
|
-
async
|
|
49
|
-
await this.withTimeout(() => this.client.
|
|
57
|
+
async removeItem(namespace, key, timeout) {
|
|
58
|
+
await this.withTimeout(() => this.client.removeItem(namespace, key), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
|
|
50
59
|
}
|
|
51
|
-
async
|
|
52
|
-
await this.withTimeout(() => this.client.
|
|
53
|
-
}
|
|
54
|
-
async getAllItemKeys(namespace, timeout) {
|
|
55
|
-
return await this.withTimeout(() => this.client.getAllItemKeys(namespace), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
|
|
56
|
-
}
|
|
57
|
-
async getAllNamespaces(timeout) {
|
|
58
|
-
return await this.withTimeout(() => this.client.getAllNamespaces(), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
|
|
59
|
-
}
|
|
60
|
-
async stats(namespace, timeout) {
|
|
61
|
-
return await this.withTimeout(() => this.client.stats(namespace), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
|
|
60
|
+
async clearItemsByNamespace(namespace, timeout) {
|
|
61
|
+
await this.withTimeout(() => this.client.clearItemsByNamespace(namespace), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
|
|
62
62
|
}
|
|
63
63
|
async withTimeout(fn, timeout = this.timeout) {
|
|
64
64
|
if (timeout) {
|
package/lib/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,8BAA4B;AAGtD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAc5C,MAAM,OAAO,WAAW;
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,8BAA4B;AAGtD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAc5C,MAAM,OAAO,WAAW;IAsBtB,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;IA3BJ,KAAK,CAAC,KAAK,CAAC,SAAiB,EAAE,OAAgB;QAC7C,OAAO,MAAM,IAAI,CAAC,WAAW,CAC3B,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAClC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAI,CAAC,OAAO,CACxB,CAAA;IACH,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,CAAC,OAAO,CACX,SAAiB,EACjB,GAAW,EACX,KAAa,EACb,UAAyB,EACzB,OAAgB;QAEhB,MAAM,IAAI,CAAC,WAAW,CACpB,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CACvB,SAAS,EACT,GAAG,EACH,KAAK,EACL,UAAU,CACX,EACD,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAI,CAAC,OAAO,CACxB,CAAA;IACH,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,SAAiB,EAAE,GAAW,EAAE,OAAgB;QAC/D,MAAM,IAAI,CAAC,WAAW,CACpB,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,EAAE,GAAG,CAAC,EAC5C,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAI,CAAC,OAAO,CACxB,CAAA;IACH,CAAC;IAED,KAAK,CAAC,qBAAqB,CAAC,SAAiB,EAAE,OAAgB;QAC7D,MAAM,IAAI,CAAC,WAAW,CACpB,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,qBAAqB,CAAC,SAAS,CAAC,EAClD,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAI,CAAC,OAAO,CACxB,CAAA;IACH,CAAC;IAEO,KAAK,CAAC,WAAW,CACvB,EAAwB,EACxB,UAA8B,IAAI,CAAC,OAAO;QAE1C,IAAI,OAAO,EAAE;YACX,OAAO,MAAM,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAA;SACzD;aAAM;YACL,OAAO,MAAM,EAAE,EAAE,CAAA;SAClB;IACH,CAAC;CACF"}
|
package/lib/contract.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
export declare const expectedVersion = "^0.8.0";
|
|
1
2
|
export interface IAPI {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
stats(namespace: string): IStats;
|
|
4
|
+
getAllNamespaces(): string[];
|
|
5
|
+
getAllItemKeys(namespace: string): string[];
|
|
6
|
+
hasItem(namespace: string, key: string): boolean;
|
|
7
|
+
getItem(namespace: string, key: string): string | null;
|
|
8
|
+
getItemWithMetadata(namespace: string, key: string): {
|
|
5
9
|
value: string;
|
|
6
10
|
metadata: IMetadata;
|
|
7
|
-
} | null
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
getAllItemKeys(namespace: string): Promise<string[]>;
|
|
12
|
-
getAllNamespaces(): Promise<string[]>;
|
|
13
|
-
stats(namespace: string): Promise<IStats>;
|
|
11
|
+
} | null;
|
|
12
|
+
setItem(namespace: string, key: string, value: string, timeToLive: number | null): null;
|
|
13
|
+
removeItem(namespace: string, key: string): null;
|
|
14
|
+
clearItemsByNamespace(namespace: string): null;
|
|
14
15
|
}
|
|
15
16
|
export interface IStats {
|
|
16
17
|
namespace: string;
|
|
@@ -20,4 +21,3 @@ export interface IMetadata {
|
|
|
20
21
|
updatedAt: number;
|
|
21
22
|
timeToLive: number | null;
|
|
22
23
|
}
|
|
23
|
-
export declare const expectedVersion = "^0.6.0 || ^0.7.0";
|
package/lib/contract.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const expectedVersion = '^0.
|
|
1
|
+
export const expectedVersion = '^0.8.0';
|
|
2
2
|
//# sourceMappingURL=contract.js.map
|
package/lib/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAA"}
|