@sebspark/promise-cache 0.2.9 → 1.0.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/dist/index.d.mts CHANGED
@@ -13,8 +13,14 @@ type SetParams<T> = {
13
13
  declare class Persistor {
14
14
  client: ReturnType<typeof createClient> | null;
15
15
  status: 'connected' | 'disconnected';
16
- redisUrl: string | undefined;
17
- constructor(redisUrl?: string);
16
+ redis: {
17
+ url: string;
18
+ password?: string;
19
+ } | undefined;
20
+ constructor(redis?: {
21
+ url: string;
22
+ password?: string;
23
+ });
18
24
  connect(onError?: (message: string) => void, onConnect?: (message: string) => void): Promise<void>;
19
25
  size(): Promise<number>;
20
26
  get<T>(key: string): Promise<GetType<T> | null>;
@@ -32,10 +38,13 @@ declare class PromiseCache<U> {
32
38
  * @param ttlInSeconds Default cache TTL.
33
39
  * @param caseSensitive Set to true if you want to differentiate between keys with different casing.
34
40
  */
35
- constructor({ ttlInSeconds, caseSensitive, redisUrl, }: {
41
+ constructor({ ttlInSeconds, caseSensitive, redis, }: {
36
42
  ttlInSeconds?: number;
37
43
  caseSensitive?: boolean;
38
- redisUrl?: string;
44
+ redis?: {
45
+ url: string;
46
+ password?: string;
47
+ };
39
48
  });
40
49
  /**
41
50
  * Cache size.
package/dist/index.d.ts CHANGED
@@ -13,8 +13,14 @@ type SetParams<T> = {
13
13
  declare class Persistor {
14
14
  client: ReturnType<typeof createClient> | null;
15
15
  status: 'connected' | 'disconnected';
16
- redisUrl: string | undefined;
17
- constructor(redisUrl?: string);
16
+ redis: {
17
+ url: string;
18
+ password?: string;
19
+ } | undefined;
20
+ constructor(redis?: {
21
+ url: string;
22
+ password?: string;
23
+ });
18
24
  connect(onError?: (message: string) => void, onConnect?: (message: string) => void): Promise<void>;
19
25
  size(): Promise<number>;
20
26
  get<T>(key: string): Promise<GetType<T> | null>;
@@ -32,10 +38,13 @@ declare class PromiseCache<U> {
32
38
  * @param ttlInSeconds Default cache TTL.
33
39
  * @param caseSensitive Set to true if you want to differentiate between keys with different casing.
34
40
  */
35
- constructor({ ttlInSeconds, caseSensitive, redisUrl, }: {
41
+ constructor({ ttlInSeconds, caseSensitive, redis, }: {
36
42
  ttlInSeconds?: number;
37
43
  caseSensitive?: boolean;
38
- redisUrl?: string;
44
+ redis?: {
45
+ url: string;
46
+ password?: string;
47
+ };
39
48
  });
40
49
  /**
41
50
  * Cache size.
package/dist/index.js CHANGED
@@ -70,27 +70,26 @@ var createLocalMemoryClient = () => {
70
70
 
71
71
  // src/persistor.ts
72
72
  var CACHE_CLIENT = import_redis.createClient;
73
- if (process.env.NODE_ENV === "test") {
74
- CACHE_CLIENT = createLocalMemoryClient;
75
- }
76
73
  var Persistor = class {
77
74
  client = null;
78
75
  status = "disconnected";
79
- redisUrl;
80
- constructor(redisUrl) {
81
- if (redisUrl) {
82
- this.redisUrl = redisUrl;
76
+ redis;
77
+ constructor(redis) {
78
+ if (redis) {
79
+ this.redis = redis;
83
80
  } else {
84
81
  CACHE_CLIENT = createLocalMemoryClient;
85
82
  }
86
83
  this.connect();
87
84
  }
88
85
  async connect(onError, onConnect) {
86
+ var _a;
89
87
  try {
90
- this.client = CACHE_CLIENT({ url: this.redisUrl });
88
+ this.client = CACHE_CLIENT(this.redis);
91
89
  this.client.on("error", (err) => {
90
+ var _a2;
92
91
  if (onError) {
93
- onError(`\u274C REDIS | Client Error | ${this.redisUrl} ${err}`);
92
+ onError(`\u274C REDIS | Client Error | ${(_a2 = this.redis) == null ? void 0 : _a2.url} ${err}`);
94
93
  }
95
94
  this.status = "disconnected";
96
95
  });
@@ -101,8 +100,9 @@ var Persistor = class {
101
100
  return;
102
101
  }
103
102
  this.client.on("connect", () => {
103
+ var _a2;
104
104
  if (onConnect) {
105
- onConnect(`\u{1F4E6} REDIS | Connection Ready | ${this.redisUrl}`);
105
+ onConnect(`\u{1F4E6} REDIS | Connection Ready | ${(_a2 = this.redis) == null ? void 0 : _a2.url}`);
106
106
  }
107
107
  this.status = "connected";
108
108
  resolve(true);
@@ -110,7 +110,7 @@ var Persistor = class {
110
110
  });
111
111
  } catch (err) {
112
112
  if (onError) {
113
- onError(`\u274C REDIS | Connection Error | ${this.redisUrl} ${err}`);
113
+ onError(`\u274C REDIS | Connection Error | ${(_a = this.redis) == null ? void 0 : _a.url} ${err}`);
114
114
  }
115
115
  this.status = "disconnected";
116
116
  }
@@ -164,8 +164,8 @@ var Persistor = class {
164
164
  }
165
165
  }
166
166
  };
167
- var createPersistor = (redisUrl) => {
168
- const persistor = new Persistor(redisUrl);
167
+ var createPersistor = (redis) => {
168
+ const persistor = new Persistor(redis);
169
169
  return persistor;
170
170
  };
171
171
 
@@ -183,9 +183,9 @@ var PromiseCache = class {
183
183
  constructor({
184
184
  ttlInSeconds,
185
185
  caseSensitive = false,
186
- redisUrl
186
+ redis
187
187
  }) {
188
- this.persistor = createPersistor(redisUrl);
188
+ this.persistor = createPersistor(redis);
189
189
  this.caseSensitive = caseSensitive;
190
190
  if (ttlInSeconds) {
191
191
  this.ttl = ttlInSeconds * 1e3;
package/dist/index.mjs CHANGED
@@ -42,27 +42,26 @@ var createLocalMemoryClient = () => {
42
42
 
43
43
  // src/persistor.ts
44
44
  var CACHE_CLIENT = createClient;
45
- if (process.env.NODE_ENV === "test") {
46
- CACHE_CLIENT = createLocalMemoryClient;
47
- }
48
45
  var Persistor = class {
49
46
  client = null;
50
47
  status = "disconnected";
51
- redisUrl;
52
- constructor(redisUrl) {
53
- if (redisUrl) {
54
- this.redisUrl = redisUrl;
48
+ redis;
49
+ constructor(redis) {
50
+ if (redis) {
51
+ this.redis = redis;
55
52
  } else {
56
53
  CACHE_CLIENT = createLocalMemoryClient;
57
54
  }
58
55
  this.connect();
59
56
  }
60
57
  async connect(onError, onConnect) {
58
+ var _a;
61
59
  try {
62
- this.client = CACHE_CLIENT({ url: this.redisUrl });
60
+ this.client = CACHE_CLIENT(this.redis);
63
61
  this.client.on("error", (err) => {
62
+ var _a2;
64
63
  if (onError) {
65
- onError(`\u274C REDIS | Client Error | ${this.redisUrl} ${err}`);
64
+ onError(`\u274C REDIS | Client Error | ${(_a2 = this.redis) == null ? void 0 : _a2.url} ${err}`);
66
65
  }
67
66
  this.status = "disconnected";
68
67
  });
@@ -73,8 +72,9 @@ var Persistor = class {
73
72
  return;
74
73
  }
75
74
  this.client.on("connect", () => {
75
+ var _a2;
76
76
  if (onConnect) {
77
- onConnect(`\u{1F4E6} REDIS | Connection Ready | ${this.redisUrl}`);
77
+ onConnect(`\u{1F4E6} REDIS | Connection Ready | ${(_a2 = this.redis) == null ? void 0 : _a2.url}`);
78
78
  }
79
79
  this.status = "connected";
80
80
  resolve(true);
@@ -82,7 +82,7 @@ var Persistor = class {
82
82
  });
83
83
  } catch (err) {
84
84
  if (onError) {
85
- onError(`\u274C REDIS | Connection Error | ${this.redisUrl} ${err}`);
85
+ onError(`\u274C REDIS | Connection Error | ${(_a = this.redis) == null ? void 0 : _a.url} ${err}`);
86
86
  }
87
87
  this.status = "disconnected";
88
88
  }
@@ -136,8 +136,8 @@ var Persistor = class {
136
136
  }
137
137
  }
138
138
  };
139
- var createPersistor = (redisUrl) => {
140
- const persistor = new Persistor(redisUrl);
139
+ var createPersistor = (redis) => {
140
+ const persistor = new Persistor(redis);
141
141
  return persistor;
142
142
  };
143
143
 
@@ -155,9 +155,9 @@ var PromiseCache = class {
155
155
  constructor({
156
156
  ttlInSeconds,
157
157
  caseSensitive = false,
158
- redisUrl
158
+ redis
159
159
  }) {
160
- this.persistor = createPersistor(redisUrl);
160
+ this.persistor = createPersistor(redis);
161
161
  this.caseSensitive = caseSensitive;
162
162
  if (ttlInSeconds) {
163
163
  this.ttl = ttlInSeconds * 1e3;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebspark/promise-cache",
3
- "version": "0.2.9",
3
+ "version": "1.0.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",