@sebspark/promise-cache 3.1.0 → 3.3.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.js CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/index.ts
@@ -40,7 +30,6 @@ var import_node_crypto = require("crypto");
40
30
 
41
31
  // src/persistor.ts
42
32
  var import_redis = require("redis");
43
- var import_superjson = __toESM(require("superjson"));
44
33
 
45
34
  // src/localMemory.ts
46
35
  var LocalStorage = class {
@@ -84,6 +73,8 @@ var createLocalMemoryClient = () => {
84
73
  };
85
74
 
86
75
  // src/persistor.ts
76
+ var fixESM = require("fix-esm");
77
+ var superjson = fixESM.require("superjson");
87
78
  var CACHE_CLIENT = import_redis.createClient;
88
79
  var isTestRunning = process.env.NODE_ENV === "test";
89
80
  function toMillis(seconds) {
@@ -122,9 +113,8 @@ var Persistor = class {
122
113
  var _a;
123
114
  try {
124
115
  await new Promise((resolve, reject) => {
125
- var _a2;
126
116
  this.client = CACHE_CLIENT({
127
- url: (_a2 = this.redis) == null ? void 0 : _a2.url,
117
+ ...this.redis,
128
118
  socket: {
129
119
  reconnectStrategy: (retries, cause) => {
130
120
  console.error(cause);
@@ -138,11 +128,11 @@ var Persistor = class {
138
128
  this.onSuccess();
139
129
  resolve(true);
140
130
  }).on("reconnecting", () => {
141
- var _a3;
142
- (_a3 = this.logger) == null ? void 0 : _a3.info("reconnecting...", this.clientId);
131
+ var _a2;
132
+ (_a2 = this.logger) == null ? void 0 : _a2.info("reconnecting...", this.clientId);
143
133
  }).on("end", () => {
144
- var _a3;
145
- (_a3 = this.logger) == null ? void 0 : _a3.info("end...", this.clientId);
134
+ var _a2;
135
+ (_a2 = this.logger) == null ? void 0 : _a2.info("end...", this.clientId);
146
136
  });
147
137
  this.client.connect();
148
138
  });
@@ -184,7 +174,7 @@ var Persistor = class {
184
174
  return;
185
175
  }
186
176
  try {
187
- const serializedData = import_superjson.default.stringify({
177
+ const serializedData = superjson.stringify({
188
178
  value,
189
179
  ttl,
190
180
  timestamp
@@ -212,7 +202,7 @@ var Persistor = class {
212
202
  if (!data) {
213
203
  return null;
214
204
  }
215
- return import_superjson.default.parse(data);
205
+ return superjson.parse(data);
216
206
  } catch (error) {
217
207
  (_b = this.logger) == null ? void 0 : _b.error(`Error getting data in redis: ${error}`);
218
208
  throw new Error(`Error getting data from redis: ${error}`);
package/dist/index.mjs CHANGED
@@ -1,9 +1,15 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
1
8
  // src/promiseCache.ts
2
9
  import { randomUUID } from "node:crypto";
3
10
 
4
11
  // src/persistor.ts
5
12
  import { createClient } from "redis";
6
- import superjson from "superjson";
7
13
 
8
14
  // src/localMemory.ts
9
15
  var LocalStorage = class {
@@ -47,6 +53,8 @@ var createLocalMemoryClient = () => {
47
53
  };
48
54
 
49
55
  // src/persistor.ts
56
+ var fixESM = __require("fix-esm");
57
+ var superjson = fixESM.require("superjson");
50
58
  var CACHE_CLIENT = createClient;
51
59
  var isTestRunning = process.env.NODE_ENV === "test";
52
60
  function toMillis(seconds) {
@@ -85,9 +93,8 @@ var Persistor = class {
85
93
  var _a;
86
94
  try {
87
95
  await new Promise((resolve, reject) => {
88
- var _a2;
89
96
  this.client = CACHE_CLIENT({
90
- url: (_a2 = this.redis) == null ? void 0 : _a2.url,
97
+ ...this.redis,
91
98
  socket: {
92
99
  reconnectStrategy: (retries, cause) => {
93
100
  console.error(cause);
@@ -101,11 +108,11 @@ var Persistor = class {
101
108
  this.onSuccess();
102
109
  resolve(true);
103
110
  }).on("reconnecting", () => {
104
- var _a3;
105
- (_a3 = this.logger) == null ? void 0 : _a3.info("reconnecting...", this.clientId);
111
+ var _a2;
112
+ (_a2 = this.logger) == null ? void 0 : _a2.info("reconnecting...", this.clientId);
106
113
  }).on("end", () => {
107
- var _a3;
108
- (_a3 = this.logger) == null ? void 0 : _a3.info("end...", this.clientId);
114
+ var _a2;
115
+ (_a2 = this.logger) == null ? void 0 : _a2.info("end...", this.clientId);
109
116
  });
110
117
  this.client.connect();
111
118
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebspark/promise-cache",
3
- "version": "3.1.0",
3
+ "version": "3.3.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -19,6 +19,7 @@
19
19
  "tsconfig": "*"
20
20
  },
21
21
  "dependencies": {
22
+ "fix-esm": "^1.0.1",
22
23
  "redis": "4.7.0",
23
24
  "superjson": "^2.2.2"
24
25
  }