@akanjs/nest 0.0.22 → 0.0.24
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/package.json +1 -1
- package/src/interceptors.js +20 -23
package/package.json
CHANGED
package/src/interceptors.js
CHANGED
|
@@ -71,42 +71,39 @@ let CacheInterceptor = class {
|
|
|
71
71
|
const signalKey = handler.name;
|
|
72
72
|
const gqlMeta = (0, import_signal.getGqlMeta)(context.getClass(), signalKey);
|
|
73
73
|
if (gqlMeta.type !== "Query" || !gqlMeta.signalOption.cache) {
|
|
74
|
-
if (gqlMeta.signalOption.cache)
|
|
74
|
+
if (gqlMeta.signalOption.cache)
|
|
75
75
|
__privateGet(this, _logger).warn(`CacheInterceptor: ${signalKey} is not Query endpoint or cache is not set`);
|
|
76
|
-
}
|
|
77
76
|
return next.handle();
|
|
78
77
|
}
|
|
79
78
|
const args = (0, import_authGuards.getArgs)(context);
|
|
80
79
|
const cacheKey = __privateMethod(this, _generateCacheKey, generateCacheKey_fn).call(this, signalKey, args);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
__privateGet(this, _logger).debug(`Cache hit for key: ${cacheKey}`);
|
|
85
|
-
return new import_rxjs.Observable((subscriber) => {
|
|
86
|
-
subscriber.next(cachedData);
|
|
87
|
-
subscriber.complete();
|
|
88
|
-
});
|
|
89
|
-
}
|
|
80
|
+
const cachedData = await __privateMethod(this, _getCache, getCache_fn).call(this, cacheKey);
|
|
81
|
+
if (cachedData) {
|
|
82
|
+
__privateGet(this, _logger).debug(`Cache hit for key: ${cacheKey}`);
|
|
90
83
|
return next.handle().pipe(
|
|
91
|
-
(0,
|
|
92
|
-
const cacheDuration = gqlMeta.signalOption.cache;
|
|
93
|
-
if (typeof cacheDuration === "number") {
|
|
94
|
-
void __privateMethod(this, _setCache, setCache_fn).call(this, cacheKey, data, cacheDuration);
|
|
95
|
-
__privateGet(this, _logger).debug(`Cache set for key: ${cacheKey}`);
|
|
96
|
-
}
|
|
97
|
-
return data;
|
|
98
|
-
}),
|
|
84
|
+
(0, import_operators.map)(() => cachedData),
|
|
99
85
|
(0, import_operators.catchError)((error) => {
|
|
100
86
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
101
87
|
__privateGet(this, _logger).error(`Error in cache interceptor for ${cacheKey}: ${errorMessage}`);
|
|
102
88
|
return (0, import_rxjs.throwError)(() => error);
|
|
103
89
|
})
|
|
104
90
|
);
|
|
105
|
-
} catch (error) {
|
|
106
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
107
|
-
__privateGet(this, _logger).error(`Cache error for ${cacheKey}: ${errorMessage}`);
|
|
108
|
-
return next.handle();
|
|
109
91
|
}
|
|
92
|
+
return next.handle().pipe(
|
|
93
|
+
(0, import_operators.map)((data) => {
|
|
94
|
+
const cacheDuration = gqlMeta.signalOption.cache;
|
|
95
|
+
if (typeof cacheDuration === "number") {
|
|
96
|
+
void __privateMethod(this, _setCache, setCache_fn).call(this, cacheKey, data, cacheDuration);
|
|
97
|
+
__privateGet(this, _logger).debug(`Cache set for key: ${cacheKey}`);
|
|
98
|
+
}
|
|
99
|
+
return data;
|
|
100
|
+
}),
|
|
101
|
+
(0, import_operators.catchError)((error) => {
|
|
102
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
103
|
+
__privateGet(this, _logger).error(`Error in cache interceptor for ${cacheKey}: ${errorMessage}`);
|
|
104
|
+
return (0, import_rxjs.throwError)(() => error);
|
|
105
|
+
})
|
|
106
|
+
);
|
|
110
107
|
}
|
|
111
108
|
};
|
|
112
109
|
_logger = new WeakMap();
|