@sebspark/promise-cache 2.0.8 → 2.0.10
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/dist/index.d.mts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +28 -25
- package/dist/index.mjs +28 -25
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -25,8 +25,7 @@ declare class Persistor {
|
|
|
25
25
|
private onSuccess;
|
|
26
26
|
private readonly redis?;
|
|
27
27
|
constructor({ redis, clientId, onSuccess, onError, }: PersistorConstructorType);
|
|
28
|
-
|
|
29
|
-
startConnection(): Promise<unknown>;
|
|
28
|
+
startConnection(): Promise<void>;
|
|
30
29
|
size(): Promise<number>;
|
|
31
30
|
get<T>(key: string): Promise<GetType<T> | null>;
|
|
32
31
|
getClientId(): UUID | undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -25,8 +25,7 @@ declare class Persistor {
|
|
|
25
25
|
private onSuccess;
|
|
26
26
|
private readonly redis?;
|
|
27
27
|
constructor({ redis, clientId, onSuccess, onError, }: PersistorConstructorType);
|
|
28
|
-
|
|
29
|
-
startConnection(): Promise<unknown>;
|
|
28
|
+
startConnection(): Promise<void>;
|
|
30
29
|
size(): Promise<number>;
|
|
31
30
|
get<T>(key: string): Promise<GetType<T> | null>;
|
|
32
31
|
getClientId(): UUID | undefined;
|
package/dist/index.js
CHANGED
|
@@ -98,35 +98,38 @@ var Persistor = class {
|
|
|
98
98
|
CACHE_CLIENT = createLocalMemoryClient;
|
|
99
99
|
}
|
|
100
100
|
if (!this.client || !this.client.isReady) {
|
|
101
|
-
this.
|
|
101
|
+
this.startConnection();
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
async
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
104
|
+
async startConnection() {
|
|
105
|
+
try {
|
|
106
|
+
await new Promise((resolve, reject) => {
|
|
107
|
+
var _a;
|
|
108
|
+
this.client = CACHE_CLIENT({
|
|
109
|
+
url: (_a = this.redis) == null ? void 0 : _a.url,
|
|
110
|
+
socket: {
|
|
111
|
+
reconnectStrategy: (retries, cause) => {
|
|
112
|
+
console.error(cause);
|
|
113
|
+
return 1e3 * 2 ** retries;
|
|
114
|
+
}
|
|
115
115
|
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
116
|
+
}).on("error", (err) => {
|
|
117
|
+
this.onError(err);
|
|
118
|
+
reject(err);
|
|
119
|
+
}).on("ready", () => {
|
|
120
|
+
this.onSuccess();
|
|
121
|
+
resolve(true);
|
|
122
|
+
}).on("reconnecting", () => {
|
|
123
|
+
console.log("reconnecting...", this.clientId);
|
|
124
|
+
}).on("end", () => {
|
|
125
|
+
console.log("end...", this.clientId);
|
|
126
|
+
});
|
|
127
|
+
this.client.connect();
|
|
127
128
|
});
|
|
128
|
-
|
|
129
|
-
|
|
129
|
+
} catch (ex) {
|
|
130
|
+
this.onError(`${ex}`);
|
|
131
|
+
console.error(ex);
|
|
132
|
+
}
|
|
130
133
|
}
|
|
131
134
|
async size() {
|
|
132
135
|
if (!this.client) {
|
package/dist/index.mjs
CHANGED
|
@@ -69,35 +69,38 @@ var Persistor = class {
|
|
|
69
69
|
CACHE_CLIENT = createLocalMemoryClient;
|
|
70
70
|
}
|
|
71
71
|
if (!this.client || !this.client.isReady) {
|
|
72
|
-
this.
|
|
72
|
+
this.startConnection();
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
async
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
75
|
+
async startConnection() {
|
|
76
|
+
try {
|
|
77
|
+
await new Promise((resolve, reject) => {
|
|
78
|
+
var _a;
|
|
79
|
+
this.client = CACHE_CLIENT({
|
|
80
|
+
url: (_a = this.redis) == null ? void 0 : _a.url,
|
|
81
|
+
socket: {
|
|
82
|
+
reconnectStrategy: (retries, cause) => {
|
|
83
|
+
console.error(cause);
|
|
84
|
+
return 1e3 * 2 ** retries;
|
|
85
|
+
}
|
|
86
86
|
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
87
|
+
}).on("error", (err) => {
|
|
88
|
+
this.onError(err);
|
|
89
|
+
reject(err);
|
|
90
|
+
}).on("ready", () => {
|
|
91
|
+
this.onSuccess();
|
|
92
|
+
resolve(true);
|
|
93
|
+
}).on("reconnecting", () => {
|
|
94
|
+
console.log("reconnecting...", this.clientId);
|
|
95
|
+
}).on("end", () => {
|
|
96
|
+
console.log("end...", this.clientId);
|
|
97
|
+
});
|
|
98
|
+
this.client.connect();
|
|
98
99
|
});
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
} catch (ex) {
|
|
101
|
+
this.onError(`${ex}`);
|
|
102
|
+
console.error(ex);
|
|
103
|
+
}
|
|
101
104
|
}
|
|
102
105
|
async size() {
|
|
103
106
|
if (!this.client) {
|