@sebspark/promise-cache 2.0.1 → 2.0.2

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 CHANGED
@@ -22,6 +22,7 @@ declare class Persistor {
22
22
  private clientId;
23
23
  private onError;
24
24
  private onSuccess;
25
+ private isConnected;
25
26
  private readonly redis?;
26
27
  constructor(options: PersistorConstructorType);
27
28
  connect(): Promise<void>;
@@ -29,6 +30,7 @@ declare class Persistor {
29
30
  size(): Promise<number>;
30
31
  get<T>(key: string): Promise<GetType<T> | null>;
31
32
  getClientId(): UUID;
33
+ getIsClientConnected(): boolean;
32
34
  private createOptions;
33
35
  set<T>(key: string, { value, timestamp, ttl }: SetParams<T>): Promise<void>;
34
36
  delete(key: string): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -22,6 +22,7 @@ declare class Persistor {
22
22
  private clientId;
23
23
  private onError;
24
24
  private onSuccess;
25
+ private isConnected;
25
26
  private readonly redis?;
26
27
  constructor(options: PersistorConstructorType);
27
28
  connect(): Promise<void>;
@@ -29,6 +30,7 @@ declare class Persistor {
29
30
  size(): Promise<number>;
30
31
  get<T>(key: string): Promise<GetType<T> | null>;
31
32
  getClientId(): UUID;
33
+ getIsClientConnected(): boolean;
32
34
  private createOptions;
33
35
  set<T>(key: string, { value, timestamp, ttl }: SetParams<T>): Promise<void>;
34
36
  delete(key: string): Promise<void>;
package/dist/index.js CHANGED
@@ -81,6 +81,7 @@ var Persistor = class {
81
81
  clientId = (0, import_node_crypto.randomUUID)();
82
82
  onError;
83
83
  onSuccess;
84
+ isConnected = false;
84
85
  redis;
85
86
  constructor(options) {
86
87
  const { redis, onError, onSuccess } = options;
@@ -91,7 +92,9 @@ var Persistor = class {
91
92
  } else {
92
93
  CACHE_CLIENT = createLocalMemoryClient;
93
94
  }
94
- this.connect();
95
+ if (!this.isConnected) {
96
+ this.connect();
97
+ }
95
98
  }
96
99
  async connect() {
97
100
  const settings = {
@@ -113,6 +116,7 @@ var Persistor = class {
113
116
  this.client = CACHE_CLIENT(this.redis);
114
117
  this.client.on("error", (err) => {
115
118
  var _a2, _b2;
119
+ this.isConnected = false;
116
120
  if (this.onError) {
117
121
  this.onError(`\u274C REDIS | Client Error | ${(_a2 = this.redis) == null ? void 0 : _a2.url} ${err}`);
118
122
  }
@@ -120,6 +124,7 @@ var Persistor = class {
120
124
  });
121
125
  this.client.on("connect", () => {
122
126
  var _a2, _b2, _c, _d;
127
+ this.isConnected = true;
123
128
  if (this.onSuccess) {
124
129
  this.onSuccess(
125
130
  `\u{1F4E6} REDIS | Connection Ready | ${(_a2 = this.redis) == null ? void 0 : _a2.name} | ${this.clientId} | ${(_b2 = this.redis) == null ? void 0 : _b2.url}`
@@ -160,6 +165,9 @@ var Persistor = class {
160
165
  getClientId() {
161
166
  return this.clientId;
162
167
  }
168
+ getIsClientConnected() {
169
+ return this.isConnected;
170
+ }
163
171
  createOptions(ttl) {
164
172
  if (ttl !== null && ttl !== void 0) {
165
173
  return { PX: Math.round(ttl) };
package/dist/index.mjs CHANGED
@@ -50,6 +50,7 @@ var Persistor = class {
50
50
  clientId = randomUUID();
51
51
  onError;
52
52
  onSuccess;
53
+ isConnected = false;
53
54
  redis;
54
55
  constructor(options) {
55
56
  const { redis, onError, onSuccess } = options;
@@ -60,7 +61,9 @@ var Persistor = class {
60
61
  } else {
61
62
  CACHE_CLIENT = createLocalMemoryClient;
62
63
  }
63
- this.connect();
64
+ if (!this.isConnected) {
65
+ this.connect();
66
+ }
64
67
  }
65
68
  async connect() {
66
69
  const settings = {
@@ -82,6 +85,7 @@ var Persistor = class {
82
85
  this.client = CACHE_CLIENT(this.redis);
83
86
  this.client.on("error", (err) => {
84
87
  var _a2, _b2;
88
+ this.isConnected = false;
85
89
  if (this.onError) {
86
90
  this.onError(`\u274C REDIS | Client Error | ${(_a2 = this.redis) == null ? void 0 : _a2.url} ${err}`);
87
91
  }
@@ -89,6 +93,7 @@ var Persistor = class {
89
93
  });
90
94
  this.client.on("connect", () => {
91
95
  var _a2, _b2, _c, _d;
96
+ this.isConnected = true;
92
97
  if (this.onSuccess) {
93
98
  this.onSuccess(
94
99
  `\u{1F4E6} REDIS | Connection Ready | ${(_a2 = this.redis) == null ? void 0 : _a2.name} | ${this.clientId} | ${(_b2 = this.redis) == null ? void 0 : _b2.url}`
@@ -129,6 +134,9 @@ var Persistor = class {
129
134
  getClientId() {
130
135
  return this.clientId;
131
136
  }
137
+ getIsClientConnected() {
138
+ return this.isConnected;
139
+ }
132
140
  createOptions(ttl) {
133
141
  if (ttl !== null && ttl !== void 0) {
134
142
  return { PX: Math.round(ttl) };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebspark/promise-cache",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",