@sebspark/promise-cache 2.0.3 → 2.0.4
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 +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +33 -34
- package/dist/index.mjs +33 -34
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -15,8 +15,8 @@ type SetParams<T> = {
|
|
|
15
15
|
type PersistorConstructorType = {
|
|
16
16
|
redis?: RedisClientOptions;
|
|
17
17
|
clientId?: UUID;
|
|
18
|
-
onError
|
|
19
|
-
onSuccess
|
|
18
|
+
onError: (error: string) => void;
|
|
19
|
+
onSuccess: () => void;
|
|
20
20
|
};
|
|
21
21
|
declare class Persistor {
|
|
22
22
|
client: ReturnType<typeof createClient> | null;
|
|
@@ -41,7 +41,7 @@ type PromiseCacheOptions = {
|
|
|
41
41
|
ttlInSeconds?: number;
|
|
42
42
|
caseSensitive?: boolean;
|
|
43
43
|
redis?: RedisClientOptions;
|
|
44
|
-
onError?: () => void;
|
|
44
|
+
onError?: (error: string) => void;
|
|
45
45
|
onSuccess?: () => void;
|
|
46
46
|
};
|
|
47
47
|
declare class PromiseCache<U> {
|
package/dist/index.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ type SetParams<T> = {
|
|
|
15
15
|
type PersistorConstructorType = {
|
|
16
16
|
redis?: RedisClientOptions;
|
|
17
17
|
clientId?: UUID;
|
|
18
|
-
onError
|
|
19
|
-
onSuccess
|
|
18
|
+
onError: (error: string) => void;
|
|
19
|
+
onSuccess: () => void;
|
|
20
20
|
};
|
|
21
21
|
declare class Persistor {
|
|
22
22
|
client: ReturnType<typeof createClient> | null;
|
|
@@ -41,7 +41,7 @@ type PromiseCacheOptions = {
|
|
|
41
41
|
ttlInSeconds?: number;
|
|
42
42
|
caseSensitive?: boolean;
|
|
43
43
|
redis?: RedisClientOptions;
|
|
44
|
-
onError?: () => void;
|
|
44
|
+
onError?: (error: string) => void;
|
|
45
45
|
onSuccess?: () => void;
|
|
46
46
|
};
|
|
47
47
|
declare class PromiseCache<U> {
|
package/dist/index.js
CHANGED
|
@@ -116,36 +116,25 @@ var Persistor = class {
|
|
|
116
116
|
await (0, import_retry.retry)(() => this.startConnection(), settings);
|
|
117
117
|
}
|
|
118
118
|
async startConnection() {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
this.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
console.log(
|
|
139
|
-
`\u{1F4E6} REDIS | Connection Ready | ${(_c = this.redis) == null ? void 0 : _c.name}\xA0| ${this.clientId} | ${(_d = this.redis) == null ? void 0 : _d.url}`
|
|
140
|
-
);
|
|
141
|
-
});
|
|
142
|
-
return await this.client.connect();
|
|
143
|
-
} catch (err) {
|
|
144
|
-
if (this.onError) {
|
|
145
|
-
this.onError(`\u274C REDIS | Connection Error | ${(_a = this.redis) == null ? void 0 : _a.url} ${err}`);
|
|
119
|
+
return new Promise((resolve, reject) => {
|
|
120
|
+
try {
|
|
121
|
+
this.client = CACHE_CLIENT(this.redis);
|
|
122
|
+
this.client.on("error", (err) => {
|
|
123
|
+
this.isConnected = false;
|
|
124
|
+
this.onError(err);
|
|
125
|
+
reject();
|
|
126
|
+
});
|
|
127
|
+
this.client.on("connect", () => {
|
|
128
|
+
this.isConnected = true;
|
|
129
|
+
this.onSuccess();
|
|
130
|
+
resolve(true);
|
|
131
|
+
});
|
|
132
|
+
this.client.connect();
|
|
133
|
+
} catch (err) {
|
|
134
|
+
this.onError(`${err}`);
|
|
135
|
+
reject();
|
|
146
136
|
}
|
|
147
|
-
|
|
148
|
-
}
|
|
137
|
+
});
|
|
149
138
|
}
|
|
150
139
|
async size() {
|
|
151
140
|
if (!this.client) {
|
|
@@ -180,7 +169,7 @@ var Persistor = class {
|
|
|
180
169
|
return {};
|
|
181
170
|
}
|
|
182
171
|
async set(key, { value, timestamp, ttl }) {
|
|
183
|
-
if (!this.
|
|
172
|
+
if (!this.client) {
|
|
184
173
|
throw new Error("Client not connected");
|
|
185
174
|
}
|
|
186
175
|
try {
|
|
@@ -192,7 +181,7 @@ var Persistor = class {
|
|
|
192
181
|
}
|
|
193
182
|
}
|
|
194
183
|
async delete(key) {
|
|
195
|
-
if (!this.
|
|
184
|
+
if (!this.client) {
|
|
196
185
|
throw new Error("Client not connected");
|
|
197
186
|
}
|
|
198
187
|
try {
|
|
@@ -211,12 +200,22 @@ var getPersistor = ({
|
|
|
211
200
|
onSuccess,
|
|
212
201
|
clientId
|
|
213
202
|
}) => {
|
|
214
|
-
const connectionName = (redis == null ? void 0 : redis.name) || "default";
|
|
203
|
+
const connectionName = redis ? (redis == null ? void 0 : redis.name) || "default" : "local";
|
|
215
204
|
if (!persistors[connectionName]) {
|
|
216
205
|
persistors[connectionName] = new Persistor({
|
|
217
206
|
redis,
|
|
218
|
-
onError
|
|
219
|
-
|
|
207
|
+
onError: (error) => {
|
|
208
|
+
onError == null ? void 0 : onError(error);
|
|
209
|
+
console.error(
|
|
210
|
+
`\u274C REDIS | Client Error | ${connectionName} | ${redis == null ? void 0 : redis.url}: ${error}`
|
|
211
|
+
);
|
|
212
|
+
},
|
|
213
|
+
onSuccess: () => {
|
|
214
|
+
onSuccess == null ? void 0 : onSuccess();
|
|
215
|
+
console.log(
|
|
216
|
+
`\u{1F4E6} REDIS | Connection Ready | ${connectionName} | ${redis == null ? void 0 : redis.url}`
|
|
217
|
+
);
|
|
218
|
+
},
|
|
220
219
|
clientId
|
|
221
220
|
});
|
|
222
221
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -87,36 +87,25 @@ var Persistor = class {
|
|
|
87
87
|
await retry(() => this.startConnection(), settings);
|
|
88
88
|
}
|
|
89
89
|
async startConnection() {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
this.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
console.log(
|
|
110
|
-
`\u{1F4E6} REDIS | Connection Ready | ${(_c = this.redis) == null ? void 0 : _c.name}\xA0| ${this.clientId} | ${(_d = this.redis) == null ? void 0 : _d.url}`
|
|
111
|
-
);
|
|
112
|
-
});
|
|
113
|
-
return await this.client.connect();
|
|
114
|
-
} catch (err) {
|
|
115
|
-
if (this.onError) {
|
|
116
|
-
this.onError(`\u274C REDIS | Connection Error | ${(_a = this.redis) == null ? void 0 : _a.url} ${err}`);
|
|
90
|
+
return new Promise((resolve, reject) => {
|
|
91
|
+
try {
|
|
92
|
+
this.client = CACHE_CLIENT(this.redis);
|
|
93
|
+
this.client.on("error", (err) => {
|
|
94
|
+
this.isConnected = false;
|
|
95
|
+
this.onError(err);
|
|
96
|
+
reject();
|
|
97
|
+
});
|
|
98
|
+
this.client.on("connect", () => {
|
|
99
|
+
this.isConnected = true;
|
|
100
|
+
this.onSuccess();
|
|
101
|
+
resolve(true);
|
|
102
|
+
});
|
|
103
|
+
this.client.connect();
|
|
104
|
+
} catch (err) {
|
|
105
|
+
this.onError(`${err}`);
|
|
106
|
+
reject();
|
|
117
107
|
}
|
|
118
|
-
|
|
119
|
-
}
|
|
108
|
+
});
|
|
120
109
|
}
|
|
121
110
|
async size() {
|
|
122
111
|
if (!this.client) {
|
|
@@ -151,7 +140,7 @@ var Persistor = class {
|
|
|
151
140
|
return {};
|
|
152
141
|
}
|
|
153
142
|
async set(key, { value, timestamp, ttl }) {
|
|
154
|
-
if (!this.
|
|
143
|
+
if (!this.client) {
|
|
155
144
|
throw new Error("Client not connected");
|
|
156
145
|
}
|
|
157
146
|
try {
|
|
@@ -163,7 +152,7 @@ var Persistor = class {
|
|
|
163
152
|
}
|
|
164
153
|
}
|
|
165
154
|
async delete(key) {
|
|
166
|
-
if (!this.
|
|
155
|
+
if (!this.client) {
|
|
167
156
|
throw new Error("Client not connected");
|
|
168
157
|
}
|
|
169
158
|
try {
|
|
@@ -182,12 +171,22 @@ var getPersistor = ({
|
|
|
182
171
|
onSuccess,
|
|
183
172
|
clientId
|
|
184
173
|
}) => {
|
|
185
|
-
const connectionName = (redis == null ? void 0 : redis.name) || "default";
|
|
174
|
+
const connectionName = redis ? (redis == null ? void 0 : redis.name) || "default" : "local";
|
|
186
175
|
if (!persistors[connectionName]) {
|
|
187
176
|
persistors[connectionName] = new Persistor({
|
|
188
177
|
redis,
|
|
189
|
-
onError
|
|
190
|
-
|
|
178
|
+
onError: (error) => {
|
|
179
|
+
onError == null ? void 0 : onError(error);
|
|
180
|
+
console.error(
|
|
181
|
+
`\u274C REDIS | Client Error | ${connectionName} | ${redis == null ? void 0 : redis.url}: ${error}`
|
|
182
|
+
);
|
|
183
|
+
},
|
|
184
|
+
onSuccess: () => {
|
|
185
|
+
onSuccess == null ? void 0 : onSuccess();
|
|
186
|
+
console.log(
|
|
187
|
+
`\u{1F4E6} REDIS | Connection Ready | ${connectionName} | ${redis == null ? void 0 : redis.url}`
|
|
188
|
+
);
|
|
189
|
+
},
|
|
191
190
|
clientId
|
|
192
191
|
});
|
|
193
192
|
}
|