@akanjs/nest 0.0.23 → 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 -24
package/package.json
CHANGED
package/src/interceptors.js
CHANGED
|
@@ -71,43 +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
|
-
const GlobalObservable = global.Observable ?? import_rxjs.Observable;
|
|
86
|
-
return new GlobalObservable((subscriber) => {
|
|
87
|
-
subscriber.next(cachedData);
|
|
88
|
-
subscriber.complete();
|
|
89
|
-
});
|
|
90
|
-
}
|
|
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}`);
|
|
91
83
|
return next.handle().pipe(
|
|
92
|
-
(0,
|
|
93
|
-
const cacheDuration = gqlMeta.signalOption.cache;
|
|
94
|
-
if (typeof cacheDuration === "number") {
|
|
95
|
-
void __privateMethod(this, _setCache, setCache_fn).call(this, cacheKey, data, cacheDuration);
|
|
96
|
-
__privateGet(this, _logger).debug(`Cache set for key: ${cacheKey}`);
|
|
97
|
-
}
|
|
98
|
-
return data;
|
|
99
|
-
}),
|
|
84
|
+
(0, import_operators.map)(() => cachedData),
|
|
100
85
|
(0, import_operators.catchError)((error) => {
|
|
101
86
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
102
87
|
__privateGet(this, _logger).error(`Error in cache interceptor for ${cacheKey}: ${errorMessage}`);
|
|
103
88
|
return (0, import_rxjs.throwError)(() => error);
|
|
104
89
|
})
|
|
105
90
|
);
|
|
106
|
-
} catch (error) {
|
|
107
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
108
|
-
__privateGet(this, _logger).error(`Cache error for ${cacheKey}: ${errorMessage}`);
|
|
109
|
-
return next.handle();
|
|
110
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
|
+
);
|
|
111
107
|
}
|
|
112
108
|
};
|
|
113
109
|
_logger = new WeakMap();
|