@blackglory/cache-js 0.1.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/LICENSE +21 -0
- package/README.md +52 -0
- package/dist/es2015/index.min.mjs +30 -0
- package/dist/es2015/index.min.mjs.map +1 -0
- package/dist/es2015/index.mjs +27939 -0
- package/dist/es2015/index.mjs.map +1 -0
- package/dist/es2015/index.umd.js +27951 -0
- package/dist/es2015/index.umd.js.map +1 -0
- package/dist/es2015/index.umd.min.js +31 -0
- package/dist/es2015/index.umd.min.js.map +1 -0
- package/dist/es2018/index.min.mjs +16 -0
- package/dist/es2018/index.min.mjs.map +1 -0
- package/dist/es2018/index.mjs +27888 -0
- package/dist/es2018/index.mjs.map +1 -0
- package/dist/es2018/index.umd.js +27900 -0
- package/dist/es2018/index.umd.js.map +1 -0
- package/dist/es2018/index.umd.min.js +16 -0
- package/dist/es2018/index.umd.min.js.map +1 -0
- package/lib/es2015/cache.d.ts +36 -0
- package/lib/es2015/cache.js +113 -0
- package/lib/es2015/cache.js.map +1 -0
- package/lib/es2015/contract.d.ts +23 -0
- package/lib/es2015/contract.js +3 -0
- package/lib/es2015/contract.js.map +1 -0
- package/lib/es2015/index.d.ts +1 -0
- package/lib/es2015/index.js +18 -0
- package/lib/es2015/index.js.map +1 -0
- package/lib/es2015/rpc-client.browser.d.ts +8 -0
- package/lib/es2015/rpc-client.browser.js +35 -0
- package/lib/es2015/rpc-client.browser.js.map +1 -0
- package/lib/es2015/rpc-client.d.ts +8 -0
- package/lib/es2015/rpc-client.js +36 -0
- package/lib/es2015/rpc-client.js.map +1 -0
- package/lib/es2018/cache.d.ts +36 -0
- package/lib/es2018/cache.js +80 -0
- package/lib/es2018/cache.js.map +1 -0
- package/lib/es2018/contract.d.ts +23 -0
- package/lib/es2018/contract.js +3 -0
- package/lib/es2018/contract.js.map +1 -0
- package/lib/es2018/index.d.ts +1 -0
- package/lib/es2018/index.js +18 -0
- package/lib/es2018/index.js.map +1 -0
- package/lib/es2018/rpc-client.browser.d.ts +8 -0
- package/lib/es2018/rpc-client.browser.js +24 -0
- package/lib/es2018/rpc-client.browser.js.map +1 -0
- package/lib/es2018/rpc-client.d.ts +8 -0
- package/lib/es2018/rpc-client.js +25 -0
- package/lib/es2018/rpc-client.js.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ClientProxy, BatchClient, BatchClientProxy } from 'delight-rpc';
|
|
2
|
+
import { IAPI, IStats } from './contract';
|
|
3
|
+
export { IStats } from './contract';
|
|
4
|
+
export interface IMetadata {
|
|
5
|
+
updatedAt: number;
|
|
6
|
+
timeToLive: number;
|
|
7
|
+
timeBeforeDeletion: number;
|
|
8
|
+
}
|
|
9
|
+
export interface ICacheClientOptions {
|
|
10
|
+
server: string;
|
|
11
|
+
timeout?: number;
|
|
12
|
+
}
|
|
13
|
+
export declare class CacheClient {
|
|
14
|
+
private client;
|
|
15
|
+
private batchClient;
|
|
16
|
+
private batchProxy;
|
|
17
|
+
private closeClients;
|
|
18
|
+
private timeout?;
|
|
19
|
+
constructor(client: ClientProxy<IAPI>, batchClient: BatchClient, batchProxy: BatchClientProxy<IAPI, unknown>, closeClients: () => void, timeout?: number | undefined);
|
|
20
|
+
static create(options: ICacheClientOptions): Promise<CacheClient>;
|
|
21
|
+
close(): void;
|
|
22
|
+
has(namespace: string, key: string, timeout?: number): Promise<boolean>;
|
|
23
|
+
get(namespace: string, key: string, timeout?: number): Promise<string | null>;
|
|
24
|
+
bulkGet(namespace: string, keys: string[], timeout?: number): Promise<Array<string | null>>;
|
|
25
|
+
getWithMetadata(namespace: string, key: string, timeout?: number): Promise<{
|
|
26
|
+
value: string;
|
|
27
|
+
metadata: IMetadata;
|
|
28
|
+
} | null>;
|
|
29
|
+
set(namespace: string, key: string, value: string, timeToLive: number, timeBeforeDeletion: number, timeout?: number): Promise<void>;
|
|
30
|
+
del(namespace: string, key: string, timeout?: number): Promise<void>;
|
|
31
|
+
clear(namespace: string, timeout?: number): Promise<void>;
|
|
32
|
+
getAllItemKeys(namespace: string, timeout?: number): Promise<string[]>;
|
|
33
|
+
getAllNamespaces(timeout?: number): Promise<string[]>;
|
|
34
|
+
stats(namespace: string, timeout?: number): Promise<IStats>;
|
|
35
|
+
private withTimeout;
|
|
36
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CacheClient = void 0;
|
|
13
|
+
const rpc_client_1 = require("./rpc-client");
|
|
14
|
+
const prelude_1 = require("@blackglory/prelude");
|
|
15
|
+
const extra_abort_1 = require("extra-abort");
|
|
16
|
+
class CacheClient {
|
|
17
|
+
constructor(client, batchClient, batchProxy, closeClients, timeout) {
|
|
18
|
+
this.client = client;
|
|
19
|
+
this.batchClient = batchClient;
|
|
20
|
+
this.batchProxy = batchProxy;
|
|
21
|
+
this.closeClients = closeClients;
|
|
22
|
+
this.timeout = timeout;
|
|
23
|
+
}
|
|
24
|
+
static create(options) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const { client, batchClient, proxy, close } = yield (0, rpc_client_1.createRPCClient)(options.server);
|
|
27
|
+
return new CacheClient(client, batchClient, proxy, close, options.timeout);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
close() {
|
|
31
|
+
this.closeClients();
|
|
32
|
+
}
|
|
33
|
+
has(namespace, key, timeout) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
return yield this.withTimeout(() => this.client.has(namespace, key), timeout);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
get(namespace, key, timeout) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
return yield this.withTimeout(() => this.client.get(namespace, key), timeout);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
bulkGet(namespace, keys, timeout) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
return yield this.withTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const results = yield this.batchClient.parallel(...keys.map(key => this.batchProxy.get(namespace, key)));
|
|
47
|
+
return results.map(result => result.unwrap());
|
|
48
|
+
}), timeout);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
getWithMetadata(namespace, key, timeout) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
return yield this.withTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
var _a, _b;
|
|
55
|
+
const result = yield this.client.getWithMetadata(namespace, key);
|
|
56
|
+
if ((0, prelude_1.isNull)(result))
|
|
57
|
+
return null;
|
|
58
|
+
return {
|
|
59
|
+
value: result.value,
|
|
60
|
+
metadata: {
|
|
61
|
+
updatedAt: result.metadata.updatedAt,
|
|
62
|
+
timeToLive: (_a = result.metadata.timeToLive) !== null && _a !== void 0 ? _a : Infinity,
|
|
63
|
+
timeBeforeDeletion: (_b = result.metadata.timeBeforeDeletion) !== null && _b !== void 0 ? _b : Infinity
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}), timeout);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
set(namespace, key, value, timeToLive, timeBeforeDeletion, timeout) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
yield this.withTimeout(() => this.client.set(namespace, key, value, (0, prelude_1.isPositiveInfinity)(timeToLive)
|
|
72
|
+
? null
|
|
73
|
+
: timeToLive, (0, prelude_1.isPositiveInfinity)(timeBeforeDeletion)
|
|
74
|
+
? null
|
|
75
|
+
: timeBeforeDeletion), timeout);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
del(namespace, key, timeout) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
yield this.withTimeout(() => this.client.del(namespace, key), timeout);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
clear(namespace, timeout) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
yield this.withTimeout(() => this.client.clear(namespace), timeout);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
getAllItemKeys(namespace, timeout) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
return yield this.withTimeout(() => this.client.getAllItemKeys(namespace), timeout);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
getAllNamespaces(timeout) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
return yield this.withTimeout(() => this.client.getAllNamespaces(), timeout);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
stats(namespace, timeout) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
return yield this.withTimeout(() => this.client.stats(namespace), timeout);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
withTimeout(fn, timeout = this.timeout) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
if (timeout) {
|
|
106
|
+
return yield (0, extra_abort_1.withAbortSignal)((0, extra_abort_1.timeoutSignal)(timeout), fn);
|
|
107
|
+
}
|
|
108
|
+
return yield fn();
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.CacheClient = CacheClient;
|
|
113
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/cache.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA8C;AAG9C,iDAAgE;AAChE,6CAA4D;AAc5D,MAAa,WAAW;IACtB,YACU,MAAyB,EACzB,WAAwB,EACxB,UAA2C,EAC3C,YAAwB,EACxB,OAAgB;QAJhB,WAAM,GAAN,MAAM,CAAmB;QACzB,gBAAW,GAAX,WAAW,CAAa;QACxB,eAAU,GAAV,UAAU,CAAiC;QAC3C,iBAAY,GAAZ,YAAY,CAAY;QACxB,YAAO,GAAP,OAAO,CAAS;IACvB,CAAC;IAEJ,MAAM,CAAO,MAAM,CAAC,OAA4B;;YAC9C,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,MAAM,IAAA,4BAAe,EAAC,OAAO,CAAC,MAAM,CAAC,CAAA;YACnF,OAAO,IAAI,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;QAC5E,CAAC;KAAA;IAED,KAAK;QACH,IAAI,CAAC,YAAY,EAAE,CAAA;IACrB,CAAC;IAEK,GAAG,CAAC,SAAiB,EAAE,GAAW,EAAE,OAAgB;;YACxD,OAAO,MAAM,IAAI,CAAC,WAAW,CAC3B,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,EACrC,OAAO,CACR,CAAA;QACH,CAAC;KAAA;IAEK,GAAG,CAAC,SAAiB,EAAE,GAAW,EAAE,OAAgB;;YACxD,OAAO,MAAM,IAAI,CAAC,WAAW,CAC3B,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,EAC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,CAAA;QACH,CAAC;KAAA;IAEa,WAAW,CACvB,EAAwB,EACxB,UAA8B,IAAI,CAAC,OAAO;;YAE1C,IAAI,OAAO,EAAE;gBACX,OAAO,MAAM,IAAA,6BAAe,EAAC,IAAA,2BAAa,EAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAA;aACzD;YACD,OAAO,MAAM,EAAE,EAAE,CAAA;QACnB,CAAC;KAAA;CACF;AAvID,kCAuIC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface IAPI {
|
|
2
|
+
has(namespace: string, key: string): Promise<boolean>;
|
|
3
|
+
get(namespace: string, key: string): Promise<string | null>;
|
|
4
|
+
getWithMetadata(namespace: string, key: string): Promise<{
|
|
5
|
+
value: string;
|
|
6
|
+
metadata: IMetadata;
|
|
7
|
+
} | null>;
|
|
8
|
+
set(namespace: string, key: string, value: string, timeToLive: number | null, timeBeforeDeletion: number | null): Promise<null>;
|
|
9
|
+
del(namespace: string, key: string): Promise<null>;
|
|
10
|
+
clear(namespace: string): Promise<null>;
|
|
11
|
+
getAllItemKeys(namespace: string): Promise<string[]>;
|
|
12
|
+
getAllNamespaces(): Promise<string[]>;
|
|
13
|
+
stats(namespace: string): Promise<IStats>;
|
|
14
|
+
}
|
|
15
|
+
export interface IStats {
|
|
16
|
+
namespace: string;
|
|
17
|
+
items: number;
|
|
18
|
+
}
|
|
19
|
+
export interface IMetadata {
|
|
20
|
+
updatedAt: number;
|
|
21
|
+
timeToLive: number | null;
|
|
22
|
+
timeBeforeDeletion: number | null;
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/contract.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './cache';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./cache"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IAPI } from './contract';
|
|
2
|
+
import { ClientProxy, BatchClient, BatchClientProxy } from 'delight-rpc';
|
|
3
|
+
export declare function createRPCClient(url: string): Promise<{
|
|
4
|
+
client: ClientProxy<IAPI>;
|
|
5
|
+
batchClient: BatchClient<IAPI>;
|
|
6
|
+
proxy: BatchClientProxy<IAPI, unknown>;
|
|
7
|
+
close: () => void;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createRPCClient = void 0;
|
|
13
|
+
const delight_rpc_1 = require("delight-rpc");
|
|
14
|
+
const websocket_browser_1 = require("@delight-rpc/websocket-browser");
|
|
15
|
+
const wait_for_1 = require("@blackglory/wait-for");
|
|
16
|
+
function createRPCClient(url) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const ws = new WebSocket(url);
|
|
19
|
+
yield (0, wait_for_1.waitForEventTarget)(ws, 'open');
|
|
20
|
+
const [client, closeClient] = (0, websocket_browser_1.createClient)(ws);
|
|
21
|
+
const [batchClient, closeBatchClient] = (0, websocket_browser_1.createBatchClient)(new WebSocket(url));
|
|
22
|
+
const proxy = (0, delight_rpc_1.createBatchProxy)();
|
|
23
|
+
return {
|
|
24
|
+
client,
|
|
25
|
+
batchClient,
|
|
26
|
+
proxy,
|
|
27
|
+
close: () => {
|
|
28
|
+
closeClient();
|
|
29
|
+
closeBatchClient();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
exports.createRPCClient = createRPCClient;
|
|
35
|
+
//# sourceMappingURL=rpc-client.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-client.browser.js","sourceRoot":"","sources":["../../src/rpc-client.browser.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,6CAA0F;AAC1F,sEAAgF;AAChF,mDAAyD;AAEzD,SAAsB,eAAe,CAAC,GAAW;;QAM/C,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,GAAG,CAAC,CAAA;QAC7B,MAAM,IAAA,6BAAkB,EAAC,EAAE,EAAE,MAAM,CAAC,CAAA;QACpC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,IAAA,gCAAY,EAAO,EAAE,CAAC,CAAA;QACpD,MAAM,CAAC,WAAW,EAAE,gBAAgB,CAAC,GAAG,IAAA,qCAAiB,EAAC,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC,CAAA;QAC7E,MAAM,KAAK,GAAG,IAAA,8BAAgB,GAAQ,CAAA;QACtC,OAAO;YACL,MAAM;YACN,WAAW;YACX,KAAK;YACL,KAAK,EAAE,GAAG,EAAE;gBACV,WAAW,EAAE,CAAA;gBACb,gBAAgB,EAAE,CAAA;YACpB,CAAC;SACF,CAAA;IACH,CAAC;CAAA;AApBD,0CAoBC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IAPI } from './contract';
|
|
2
|
+
import { ClientProxy, BatchClient, BatchClientProxy } from 'delight-rpc';
|
|
3
|
+
export declare function createRPCClient(url: string): Promise<{
|
|
4
|
+
client: ClientProxy<IAPI>;
|
|
5
|
+
batchClient: BatchClient<IAPI>;
|
|
6
|
+
proxy: BatchClientProxy<IAPI, unknown>;
|
|
7
|
+
close: () => void;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createRPCClient = void 0;
|
|
13
|
+
const delight_rpc_1 = require("delight-rpc");
|
|
14
|
+
const websocket_1 = require("@delight-rpc/websocket");
|
|
15
|
+
const ws_1 = require("ws");
|
|
16
|
+
const wait_for_1 = require("@blackglory/wait-for");
|
|
17
|
+
function createRPCClient(url) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const ws = new ws_1.WebSocket(url);
|
|
20
|
+
yield (0, wait_for_1.waitForEventEmitter)(ws, 'open');
|
|
21
|
+
const [client, closeClient] = (0, websocket_1.createClient)(ws);
|
|
22
|
+
const [batchClient, closeBatchClient] = (0, websocket_1.createBatchClient)(new ws_1.WebSocket(url));
|
|
23
|
+
const proxy = (0, delight_rpc_1.createBatchProxy)();
|
|
24
|
+
return {
|
|
25
|
+
client,
|
|
26
|
+
batchClient,
|
|
27
|
+
proxy,
|
|
28
|
+
close: () => {
|
|
29
|
+
closeClient();
|
|
30
|
+
closeBatchClient();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
exports.createRPCClient = createRPCClient;
|
|
36
|
+
//# sourceMappingURL=rpc-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-client.js","sourceRoot":"","sources":["../../src/rpc-client.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,6CAA0F;AAC1F,sDAAwE;AACxE,2BAA8B;AAC9B,mDAA0D;AAE1D,SAAsB,eAAe,CAAC,GAAW;;QAM/C,MAAM,EAAE,GAAG,IAAI,cAAS,CAAC,GAAG,CAAC,CAAA;QAC7B,MAAM,IAAA,8BAAmB,EAAC,EAAE,EAAE,MAAM,CAAC,CAAA;QACrC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,IAAA,wBAAY,EAAO,EAAE,CAAC,CAAA;QACpD,MAAM,CAAC,WAAW,EAAE,gBAAgB,CAAC,GAAG,IAAA,6BAAiB,EAAC,IAAI,cAAS,CAAC,GAAG,CAAC,CAAC,CAAA;QAC7E,MAAM,KAAK,GAAG,IAAA,8BAAgB,GAAQ,CAAA;QACtC,OAAO;YACL,MAAM;YACN,WAAW;YACX,KAAK;YACL,KAAK,EAAE,GAAG,EAAE;gBACV,WAAW,EAAE,CAAA;gBACb,gBAAgB,EAAE,CAAA;YACpB,CAAC;SACF,CAAA;IACH,CAAC;CAAA;AApBD,0CAoBC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ClientProxy, BatchClient, BatchClientProxy } from 'delight-rpc';
|
|
2
|
+
import { IAPI, IStats } from './contract';
|
|
3
|
+
export { IStats } from './contract';
|
|
4
|
+
export interface IMetadata {
|
|
5
|
+
updatedAt: number;
|
|
6
|
+
timeToLive: number;
|
|
7
|
+
timeBeforeDeletion: number;
|
|
8
|
+
}
|
|
9
|
+
export interface ICacheClientOptions {
|
|
10
|
+
server: string;
|
|
11
|
+
timeout?: number;
|
|
12
|
+
}
|
|
13
|
+
export declare class CacheClient {
|
|
14
|
+
private client;
|
|
15
|
+
private batchClient;
|
|
16
|
+
private batchProxy;
|
|
17
|
+
private closeClients;
|
|
18
|
+
private timeout?;
|
|
19
|
+
constructor(client: ClientProxy<IAPI>, batchClient: BatchClient, batchProxy: BatchClientProxy<IAPI, unknown>, closeClients: () => void, timeout?: number | undefined);
|
|
20
|
+
static create(options: ICacheClientOptions): Promise<CacheClient>;
|
|
21
|
+
close(): void;
|
|
22
|
+
has(namespace: string, key: string, timeout?: number): Promise<boolean>;
|
|
23
|
+
get(namespace: string, key: string, timeout?: number): Promise<string | null>;
|
|
24
|
+
bulkGet(namespace: string, keys: string[], timeout?: number): Promise<Array<string | null>>;
|
|
25
|
+
getWithMetadata(namespace: string, key: string, timeout?: number): Promise<{
|
|
26
|
+
value: string;
|
|
27
|
+
metadata: IMetadata;
|
|
28
|
+
} | null>;
|
|
29
|
+
set(namespace: string, key: string, value: string, timeToLive: number, timeBeforeDeletion: number, timeout?: number): Promise<void>;
|
|
30
|
+
del(namespace: string, key: string, timeout?: number): Promise<void>;
|
|
31
|
+
clear(namespace: string, timeout?: number): Promise<void>;
|
|
32
|
+
getAllItemKeys(namespace: string, timeout?: number): Promise<string[]>;
|
|
33
|
+
getAllNamespaces(timeout?: number): Promise<string[]>;
|
|
34
|
+
stats(namespace: string, timeout?: number): Promise<IStats>;
|
|
35
|
+
private withTimeout;
|
|
36
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CacheClient = void 0;
|
|
4
|
+
const rpc_client_1 = require("./rpc-client");
|
|
5
|
+
const prelude_1 = require("@blackglory/prelude");
|
|
6
|
+
const extra_abort_1 = require("extra-abort");
|
|
7
|
+
class CacheClient {
|
|
8
|
+
constructor(client, batchClient, batchProxy, closeClients, timeout) {
|
|
9
|
+
this.client = client;
|
|
10
|
+
this.batchClient = batchClient;
|
|
11
|
+
this.batchProxy = batchProxy;
|
|
12
|
+
this.closeClients = closeClients;
|
|
13
|
+
this.timeout = timeout;
|
|
14
|
+
}
|
|
15
|
+
static async create(options) {
|
|
16
|
+
const { client, batchClient, proxy, close } = await (0, rpc_client_1.createRPCClient)(options.server);
|
|
17
|
+
return new CacheClient(client, batchClient, proxy, close, options.timeout);
|
|
18
|
+
}
|
|
19
|
+
close() {
|
|
20
|
+
this.closeClients();
|
|
21
|
+
}
|
|
22
|
+
async has(namespace, key, timeout) {
|
|
23
|
+
return await this.withTimeout(() => this.client.has(namespace, key), timeout);
|
|
24
|
+
}
|
|
25
|
+
async get(namespace, key, timeout) {
|
|
26
|
+
return await this.withTimeout(() => this.client.get(namespace, key), timeout);
|
|
27
|
+
}
|
|
28
|
+
async bulkGet(namespace, keys, timeout) {
|
|
29
|
+
return await this.withTimeout(async () => {
|
|
30
|
+
const results = await this.batchClient.parallel(...keys.map(key => this.batchProxy.get(namespace, key)));
|
|
31
|
+
return results.map(result => result.unwrap());
|
|
32
|
+
}, timeout);
|
|
33
|
+
}
|
|
34
|
+
async getWithMetadata(namespace, key, timeout) {
|
|
35
|
+
return await this.withTimeout(async () => {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
const result = await this.client.getWithMetadata(namespace, key);
|
|
38
|
+
if ((0, prelude_1.isNull)(result))
|
|
39
|
+
return null;
|
|
40
|
+
return {
|
|
41
|
+
value: result.value,
|
|
42
|
+
metadata: {
|
|
43
|
+
updatedAt: result.metadata.updatedAt,
|
|
44
|
+
timeToLive: (_a = result.metadata.timeToLive) !== null && _a !== void 0 ? _a : Infinity,
|
|
45
|
+
timeBeforeDeletion: (_b = result.metadata.timeBeforeDeletion) !== null && _b !== void 0 ? _b : Infinity
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}, timeout);
|
|
49
|
+
}
|
|
50
|
+
async set(namespace, key, value, timeToLive, timeBeforeDeletion, timeout) {
|
|
51
|
+
await this.withTimeout(() => this.client.set(namespace, key, value, (0, prelude_1.isPositiveInfinity)(timeToLive)
|
|
52
|
+
? null
|
|
53
|
+
: timeToLive, (0, prelude_1.isPositiveInfinity)(timeBeforeDeletion)
|
|
54
|
+
? null
|
|
55
|
+
: timeBeforeDeletion), timeout);
|
|
56
|
+
}
|
|
57
|
+
async del(namespace, key, timeout) {
|
|
58
|
+
await this.withTimeout(() => this.client.del(namespace, key), timeout);
|
|
59
|
+
}
|
|
60
|
+
async clear(namespace, timeout) {
|
|
61
|
+
await this.withTimeout(() => this.client.clear(namespace), timeout);
|
|
62
|
+
}
|
|
63
|
+
async getAllItemKeys(namespace, timeout) {
|
|
64
|
+
return await this.withTimeout(() => this.client.getAllItemKeys(namespace), timeout);
|
|
65
|
+
}
|
|
66
|
+
async getAllNamespaces(timeout) {
|
|
67
|
+
return await this.withTimeout(() => this.client.getAllNamespaces(), timeout);
|
|
68
|
+
}
|
|
69
|
+
async stats(namespace, timeout) {
|
|
70
|
+
return await this.withTimeout(() => this.client.stats(namespace), timeout);
|
|
71
|
+
}
|
|
72
|
+
async withTimeout(fn, timeout = this.timeout) {
|
|
73
|
+
if (timeout) {
|
|
74
|
+
return await (0, extra_abort_1.withAbortSignal)((0, extra_abort_1.timeoutSignal)(timeout), fn);
|
|
75
|
+
}
|
|
76
|
+
return await fn();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.CacheClient = CacheClient;
|
|
80
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/cache.ts"],"names":[],"mappings":";;;AAAA,6CAA8C;AAG9C,iDAAgE;AAChE,6CAA4D;AAc5D,MAAa,WAAW;IACtB,YACU,MAAyB,EACzB,WAAwB,EACxB,UAA2C,EAC3C,YAAwB,EACxB,OAAgB;QAJhB,WAAM,GAAN,MAAM,CAAmB;QACzB,gBAAW,GAAX,WAAW,CAAa;QACxB,eAAU,GAAV,UAAU,CAAiC;QAC3C,iBAAY,GAAZ,YAAY,CAAY;QACxB,YAAO,GAAP,OAAO,CAAS;IACvB,CAAC;IAEJ,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAA4B;QAC9C,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,MAAM,IAAA,4BAAe,EAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QACnF,OAAO,IAAI,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IAC5E,CAAC;IAED,KAAK;QACH,IAAI,CAAC,YAAY,EAAE,CAAA;IACrB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,SAAiB,EAAE,GAAW,EAAE,OAAgB;QACxD,OAAO,MAAM,IAAI,CAAC,WAAW,CAC3B,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GA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3B,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,EACpC,OAAO,CACR,CAAA;IACH,CAAC;IAED,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,CACR,CAAA;IACH,CAAC;IAEO,KAAK,CAAC,WAAW,CACvB,EAAwB,EACxB,UAA8B,IAAI,CAAC,OAAO;QAE1C,IAAI,OAAO,EAAE;YACX,OAAO,MAAM,IAAA,6BAAe,EAAC,IAAA,2BAAa,EAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAA;SACzD;QACD,OAAO,MAAM,EAAE,EAAE,CAAA;IACnB,CAAC;CACF;AAvID,kCAuIC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface IAPI {
|
|
2
|
+
has(namespace: string, key: string): Promise<boolean>;
|
|
3
|
+
get(namespace: string, key: string): Promise<string | null>;
|
|
4
|
+
getWithMetadata(namespace: string, key: string): Promise<{
|
|
5
|
+
value: string;
|
|
6
|
+
metadata: IMetadata;
|
|
7
|
+
} | null>;
|
|
8
|
+
set(namespace: string, key: string, value: string, timeToLive: number | null, timeBeforeDeletion: number | null): Promise<null>;
|
|
9
|
+
del(namespace: string, key: string): Promise<null>;
|
|
10
|
+
clear(namespace: string): Promise<null>;
|
|
11
|
+
getAllItemKeys(namespace: string): Promise<string[]>;
|
|
12
|
+
getAllNamespaces(): Promise<string[]>;
|
|
13
|
+
stats(namespace: string): Promise<IStats>;
|
|
14
|
+
}
|
|
15
|
+
export interface IStats {
|
|
16
|
+
namespace: string;
|
|
17
|
+
items: number;
|
|
18
|
+
}
|
|
19
|
+
export interface IMetadata {
|
|
20
|
+
updatedAt: number;
|
|
21
|
+
timeToLive: number | null;
|
|
22
|
+
timeBeforeDeletion: number | null;
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/contract.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './cache';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./cache"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IAPI } from './contract';
|
|
2
|
+
import { ClientProxy, BatchClient, BatchClientProxy } from 'delight-rpc';
|
|
3
|
+
export declare function createRPCClient(url: string): Promise<{
|
|
4
|
+
client: ClientProxy<IAPI>;
|
|
5
|
+
batchClient: BatchClient<IAPI>;
|
|
6
|
+
proxy: BatchClientProxy<IAPI, unknown>;
|
|
7
|
+
close: () => void;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRPCClient = void 0;
|
|
4
|
+
const delight_rpc_1 = require("delight-rpc");
|
|
5
|
+
const websocket_browser_1 = require("@delight-rpc/websocket-browser");
|
|
6
|
+
const wait_for_1 = require("@blackglory/wait-for");
|
|
7
|
+
async function createRPCClient(url) {
|
|
8
|
+
const ws = new WebSocket(url);
|
|
9
|
+
await (0, wait_for_1.waitForEventTarget)(ws, 'open');
|
|
10
|
+
const [client, closeClient] = (0, websocket_browser_1.createClient)(ws);
|
|
11
|
+
const [batchClient, closeBatchClient] = (0, websocket_browser_1.createBatchClient)(new WebSocket(url));
|
|
12
|
+
const proxy = (0, delight_rpc_1.createBatchProxy)();
|
|
13
|
+
return {
|
|
14
|
+
client,
|
|
15
|
+
batchClient,
|
|
16
|
+
proxy,
|
|
17
|
+
close: () => {
|
|
18
|
+
closeClient();
|
|
19
|
+
closeBatchClient();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
exports.createRPCClient = createRPCClient;
|
|
24
|
+
//# sourceMappingURL=rpc-client.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-client.browser.js","sourceRoot":"","sources":["../../src/rpc-client.browser.ts"],"names":[],"mappings":";;;AACA,6CAA0F;AAC1F,sEAAgF;AAChF,mDAAyD;AAElD,KAAK,UAAU,eAAe,CAAC,GAAW;IAM/C,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,GAAG,CAAC,CAAA;IAC7B,MAAM,IAAA,6BAAkB,EAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IACpC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,IAAA,gCAAY,EAAO,EAAE,CAAC,CAAA;IACpD,MAAM,CAAC,WAAW,EAAE,gBAAgB,CAAC,GAAG,IAAA,qCAAiB,EAAC,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC,CAAA;IAC7E,MAAM,KAAK,GAAG,IAAA,8BAAgB,GAAQ,CAAA;IACtC,OAAO;QACL,MAAM;QACN,WAAW;QACX,KAAK;QACL,KAAK,EAAE,GAAG,EAAE;YACV,WAAW,EAAE,CAAA;YACb,gBAAgB,EAAE,CAAA;QACpB,CAAC;KACF,CAAA;AACH,CAAC;AApBD,0CAoBC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IAPI } from './contract';
|
|
2
|
+
import { ClientProxy, BatchClient, BatchClientProxy } from 'delight-rpc';
|
|
3
|
+
export declare function createRPCClient(url: string): Promise<{
|
|
4
|
+
client: ClientProxy<IAPI>;
|
|
5
|
+
batchClient: BatchClient<IAPI>;
|
|
6
|
+
proxy: BatchClientProxy<IAPI, unknown>;
|
|
7
|
+
close: () => void;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRPCClient = void 0;
|
|
4
|
+
const delight_rpc_1 = require("delight-rpc");
|
|
5
|
+
const websocket_1 = require("@delight-rpc/websocket");
|
|
6
|
+
const ws_1 = require("ws");
|
|
7
|
+
const wait_for_1 = require("@blackglory/wait-for");
|
|
8
|
+
async function createRPCClient(url) {
|
|
9
|
+
const ws = new ws_1.WebSocket(url);
|
|
10
|
+
await (0, wait_for_1.waitForEventEmitter)(ws, 'open');
|
|
11
|
+
const [client, closeClient] = (0, websocket_1.createClient)(ws);
|
|
12
|
+
const [batchClient, closeBatchClient] = (0, websocket_1.createBatchClient)(new ws_1.WebSocket(url));
|
|
13
|
+
const proxy = (0, delight_rpc_1.createBatchProxy)();
|
|
14
|
+
return {
|
|
15
|
+
client,
|
|
16
|
+
batchClient,
|
|
17
|
+
proxy,
|
|
18
|
+
close: () => {
|
|
19
|
+
closeClient();
|
|
20
|
+
closeBatchClient();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.createRPCClient = createRPCClient;
|
|
25
|
+
//# sourceMappingURL=rpc-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-client.js","sourceRoot":"","sources":["../../src/rpc-client.ts"],"names":[],"mappings":";;;AACA,6CAA0F;AAC1F,sDAAwE;AACxE,2BAA8B;AAC9B,mDAA0D;AAEnD,KAAK,UAAU,eAAe,CAAC,GAAW;IAM/C,MAAM,EAAE,GAAG,IAAI,cAAS,CAAC,GAAG,CAAC,CAAA;IAC7B,MAAM,IAAA,8BAAmB,EAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IACrC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,IAAA,wBAAY,EAAO,EAAE,CAAC,CAAA;IACpD,MAAM,CAAC,WAAW,EAAE,gBAAgB,CAAC,GAAG,IAAA,6BAAiB,EAAC,IAAI,cAAS,CAAC,GAAG,CAAC,CAAC,CAAA;IAC7E,MAAM,KAAK,GAAG,IAAA,8BAAgB,GAAQ,CAAA;IACtC,OAAO;QACL,MAAM;QACN,WAAW;QACX,KAAK;QACL,KAAK,EAAE,GAAG,EAAE;YACV,WAAW,EAAE,CAAA;YACb,gBAAgB,EAAE,CAAA;QACpB,CAAC;KACF,CAAA;AACH,CAAC;AApBD,0CAoBC"}
|