@blackglory/cache-js 0.9.0 → 0.9.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 +7 -7
- package/lib/cache.d.ts +6 -6
- package/lib/cache.js +12 -12
- package/lib/cache.js.map +1 -1
- package/lib/contract.d.ts +13 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,30 +29,30 @@ class CacheClient {
|
|
|
29
29
|
getAllNamespaces(timeout?: number): Promise<string[]>
|
|
30
30
|
getAllItemKeys(namespace: string, timeout?: number): Promise<string[]>
|
|
31
31
|
|
|
32
|
-
hasItem(namespace: string,
|
|
32
|
+
hasItem(namespace: string, itemKey: string, timeout?: number): Promise<boolean>
|
|
33
33
|
|
|
34
|
-
getItem(namespace: string,
|
|
34
|
+
getItem(namespace: string, itemKey: string, timeout?: number): Promise<string | null>
|
|
35
35
|
|
|
36
|
-
getItemWithMetadata(namespace: string,
|
|
36
|
+
getItemWithMetadata(namespace: string, itemKey: string, timeout?: number): Promise<{
|
|
37
37
|
value: string
|
|
38
38
|
metadata: IMetadata
|
|
39
39
|
} | null>
|
|
40
40
|
|
|
41
41
|
getItems(
|
|
42
42
|
namespace: string
|
|
43
|
-
,
|
|
43
|
+
, itemKeys: string[]
|
|
44
44
|
, timeout?: number
|
|
45
45
|
): Promise<Array<string | null>>
|
|
46
46
|
|
|
47
47
|
setItem(
|
|
48
48
|
namespace: string
|
|
49
|
-
,
|
|
50
|
-
,
|
|
49
|
+
, itemKey: string
|
|
50
|
+
, itemValue: string
|
|
51
51
|
, timeToLive: number | null
|
|
52
52
|
, timeout?: number
|
|
53
53
|
): Promise<void>
|
|
54
54
|
|
|
55
|
-
removeItem(namespace: string,
|
|
55
|
+
removeItem(namespace: string, itemKey: string, timeout?: number): Promise<void>
|
|
56
56
|
|
|
57
57
|
clearItemsByNamespace(namespace: string, timeout?: number): Promise<void>
|
|
58
58
|
}
|
package/lib/cache.d.ts
CHANGED
|
@@ -21,15 +21,15 @@ export declare class CacheClient {
|
|
|
21
21
|
private constructor();
|
|
22
22
|
static create(options: ICacheClientOptions): Promise<CacheClient>;
|
|
23
23
|
close(): Promise<void>;
|
|
24
|
-
hasItem(namespace: string,
|
|
25
|
-
getItem(namespace: string,
|
|
26
|
-
getItemWithMetadata(namespace: string,
|
|
24
|
+
hasItem(namespace: string, itemKey: string, timeout?: number): Promise<boolean>;
|
|
25
|
+
getItem(namespace: string, itemKey: string, timeout?: number): Promise<string | null>;
|
|
26
|
+
getItemWithMetadata(namespace: string, itemKey: string, timeout?: number): Promise<{
|
|
27
27
|
value: string;
|
|
28
28
|
metadata: IMetadata;
|
|
29
29
|
} | null>;
|
|
30
|
-
getItems(namespace: string,
|
|
31
|
-
setItem(namespace: string,
|
|
32
|
-
removeItem(namespace: string,
|
|
30
|
+
getItems(namespace: string, itemKeys: string[], timeout?: number): Promise<Array<string | null>>;
|
|
31
|
+
setItem(namespace: string, itemKey: string, itemValue: string, timeToLive: number | null, timeout?: number): Promise<void>;
|
|
32
|
+
removeItem(namespace: string, itemKey: string, timeout?: number): Promise<void>;
|
|
33
33
|
clearItemsByNamespace(namespace: string, timeout?: number): Promise<void>;
|
|
34
34
|
private withTimeout;
|
|
35
35
|
}
|
package/lib/cache.js
CHANGED
|
@@ -25,15 +25,15 @@ export class CacheClient {
|
|
|
25
25
|
async close() {
|
|
26
26
|
await this.closeClients();
|
|
27
27
|
}
|
|
28
|
-
async hasItem(namespace,
|
|
29
|
-
return await this.withTimeout(() => this.client.hasItem(namespace,
|
|
28
|
+
async hasItem(namespace, itemKey, timeout) {
|
|
29
|
+
return await this.withTimeout(() => this.client.hasItem(namespace, itemKey), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
|
|
30
30
|
}
|
|
31
|
-
async getItem(namespace,
|
|
32
|
-
return await this.withTimeout(() => this.client.getItem(namespace,
|
|
31
|
+
async getItem(namespace, itemKey, timeout) {
|
|
32
|
+
return await this.withTimeout(() => this.client.getItem(namespace, itemKey), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
|
|
33
33
|
}
|
|
34
|
-
async getItemWithMetadata(namespace,
|
|
34
|
+
async getItemWithMetadata(namespace, itemKey, timeout) {
|
|
35
35
|
return await this.withTimeout(async () => {
|
|
36
|
-
const result = await this.client.getItemWithMetadata(namespace,
|
|
36
|
+
const result = await this.client.getItemWithMetadata(namespace, itemKey);
|
|
37
37
|
if (isNull(result))
|
|
38
38
|
return null;
|
|
39
39
|
return {
|
|
@@ -45,17 +45,17 @@ export class CacheClient {
|
|
|
45
45
|
};
|
|
46
46
|
}, timeout !== null && timeout !== void 0 ? timeout : this.timeout);
|
|
47
47
|
}
|
|
48
|
-
async getItems(namespace,
|
|
48
|
+
async getItems(namespace, itemKeys, timeout) {
|
|
49
49
|
return await this.withTimeout(async () => {
|
|
50
|
-
const results = await this.batchClient.parallel(...
|
|
50
|
+
const results = await this.batchClient.parallel(...itemKeys.map(key => this.batchProxy.getItem(namespace, key)));
|
|
51
51
|
return results.map(result => result.unwrap());
|
|
52
52
|
}, timeout !== null && timeout !== void 0 ? timeout : this.timeout);
|
|
53
53
|
}
|
|
54
|
-
async setItem(namespace,
|
|
55
|
-
await this.withTimeout(() => this.client.setItem(namespace,
|
|
54
|
+
async setItem(namespace, itemKey, itemValue, timeToLive, timeout) {
|
|
55
|
+
await this.withTimeout(() => this.client.setItem(namespace, itemKey, itemValue, timeToLive), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
|
|
56
56
|
}
|
|
57
|
-
async removeItem(namespace,
|
|
58
|
-
await this.withTimeout(() => this.client.removeItem(namespace,
|
|
57
|
+
async removeItem(namespace, itemKey, timeout) {
|
|
58
|
+
await this.withTimeout(() => this.client.removeItem(namespace, itemKey), timeout !== null && timeout !== void 0 ? timeout : this.timeout);
|
|
59
59
|
}
|
|
60
60
|
async clearItemsByNamespace(namespace, timeout) {
|
|
61
61
|
await this.withTimeout(() => this.client.clearItemsByNamespace(namespace), timeout !== null && timeout !== void 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,EACjB,UAAyB,EACzB,OAAgB;QAEhB,MAAM,IAAI,CAAC,WAAW,CACpB,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CACvB,SAAS,EACT,OAAO,EACP,SAAS,EACT,UAAU,CACX,EACD,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAI,CAAC,OAAO,CACxB,CAAA;IACH,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,SAAiB,EAAE,OAAe,EAAE,OAAgB;QACnE,MAAM,IAAI,CAAC,WAAW,CACpB,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC,EAChD,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,23 +1,23 @@
|
|
|
1
1
|
export declare const expectedVersion = "^0.8.0";
|
|
2
|
+
export interface IStats {
|
|
3
|
+
namespace: string;
|
|
4
|
+
items: number;
|
|
5
|
+
}
|
|
6
|
+
export interface IMetadata {
|
|
7
|
+
updatedAt: number;
|
|
8
|
+
timeToLive: number | null;
|
|
9
|
+
}
|
|
2
10
|
export interface IAPI {
|
|
3
11
|
stats(namespace: string): IStats;
|
|
4
12
|
getAllNamespaces(): string[];
|
|
5
13
|
getAllItemKeys(namespace: string): string[];
|
|
6
|
-
hasItem(namespace: string,
|
|
7
|
-
getItem(namespace: string,
|
|
8
|
-
getItemWithMetadata(namespace: string,
|
|
14
|
+
hasItem(namespace: string, itemKey: string): boolean;
|
|
15
|
+
getItem(namespace: string, itemKey: string): string | null;
|
|
16
|
+
getItemWithMetadata(namespace: string, itemKey: string): {
|
|
9
17
|
value: string;
|
|
10
18
|
metadata: IMetadata;
|
|
11
19
|
} | null;
|
|
12
|
-
setItem(namespace: string,
|
|
13
|
-
removeItem(namespace: string,
|
|
20
|
+
setItem(namespace: string, itemKey: string, itemValue: string, timeToLive: number | null): null;
|
|
21
|
+
removeItem(namespace: string, itemKey: string): null;
|
|
14
22
|
clearItemsByNamespace(namespace: string): null;
|
|
15
23
|
}
|
|
16
|
-
export interface IStats {
|
|
17
|
-
namespace: string;
|
|
18
|
-
items: number;
|
|
19
|
-
}
|
|
20
|
-
export interface IMetadata {
|
|
21
|
-
updatedAt: number;
|
|
22
|
-
timeToLive: number | null;
|
|
23
|
-
}
|