ts-packages 2.0.0 → 3.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/package.json +1 -1
- package/packages/cache/README.md +105 -9
- package/packages/cache/dist/cjs/adapters/memcache/MemcacheCache.d.ts +1 -54
- package/packages/cache/dist/cjs/adapters/memcache/MemcacheCache.js +75 -281
- package/packages/cache/dist/cjs/adapters/memory/MemoryCache.js +76 -22
- package/packages/cache/dist/cjs/adapters/redis/RedisCache.js +84 -26
- package/packages/cache/dist/cjs/core/BaseCache.js +13 -4
- package/packages/cache/dist/cjs/core/factory.js +26 -4
- package/packages/cache/dist/cjs/errors/CacheError.d.ts +10 -7
- package/packages/cache/dist/cjs/errors/CacheError.js +6 -11
- package/packages/cache/dist/cjs/errors/cacheErrorCodes.d.ts +22 -0
- package/packages/cache/dist/cjs/errors/cacheErrorCodes.js +24 -0
- package/packages/cache/dist/cjs/errors/index.js +3 -0
- package/packages/cache/dist/cjs/middleware/express/cacheMiddleware.js +8 -8
- package/packages/cache/dist/cjs/session/SessionStore.js +84 -28
- package/packages/cache/dist/esm/adapters/memcache/MemcacheCache.d.ts +1 -54
- package/packages/cache/dist/esm/adapters/memcache/MemcacheCache.js +75 -281
- package/packages/cache/dist/esm/adapters/memory/MemoryCache.js +76 -22
- package/packages/cache/dist/esm/adapters/redis/RedisCache.js +84 -26
- package/packages/cache/dist/esm/core/BaseCache.js +13 -4
- package/packages/cache/dist/esm/core/factory.js +26 -4
- package/packages/cache/dist/esm/errors/CacheError.d.ts +10 -7
- package/packages/cache/dist/esm/errors/CacheError.js +6 -11
- package/packages/cache/dist/esm/errors/cacheErrorCodes.d.ts +22 -0
- package/packages/cache/dist/esm/errors/cacheErrorCodes.js +21 -0
- package/packages/cache/dist/esm/errors/index.js +3 -0
- package/packages/cache/dist/esm/middleware/express/cacheMiddleware.js +8 -8
- package/packages/cache/dist/esm/session/SessionStore.js +84 -28
- package/packages/cache/dist/types/adapters/memcache/MemcacheCache.d.ts +1 -54
- package/packages/cache/dist/types/errors/CacheError.d.ts +10 -7
- package/packages/cache/dist/types/errors/cacheErrorCodes.d.ts +22 -0
- package/packages/cache/package.json +8 -6
- package/packages/cache/src/adapters/memcache/MemcacheCache.ts +79 -352
- package/packages/cache/src/adapters/memory/MemoryCache.ts +76 -77
- package/packages/cache/src/adapters/redis/RedisCache.ts +84 -86
- package/packages/cache/src/core/BaseCache.ts +13 -14
- package/packages/cache/src/core/factory.ts +27 -16
- package/packages/cache/src/errors/CacheError.ts +16 -17
- package/packages/cache/src/errors/cacheErrorCodes.ts +24 -0
- package/packages/cache/src/errors/index.ts +5 -0
- package/packages/cache/src/middleware/express/cacheMiddleware.ts +8 -8
- package/packages/cache/src/session/SessionStore.ts +84 -84
- package/packages/errors-utils/README.md +54 -57
- package/packages/errors-utils/dist/cjs/constants/errorCodes.d.ts +28 -23
- package/packages/errors-utils/dist/cjs/constants/errorCodes.js +57 -22
- package/packages/errors-utils/dist/cjs/constants/errorMessages.d.ts +8 -1
- package/packages/errors-utils/dist/cjs/constants/errorMessages.js +72 -29
- package/packages/errors-utils/dist/cjs/error/AppError.d.ts +2 -2
- package/packages/errors-utils/dist/cjs/error/AppError.js +2 -2
- package/packages/errors-utils/dist/cjs/error/ServiceUnavailableError.d.ts +4 -0
- package/packages/errors-utils/dist/cjs/error/ServiceUnavailableError.js +11 -0
- package/packages/errors-utils/dist/cjs/error/TokenExpiredError.d.ts +2 -2
- package/packages/errors-utils/dist/cjs/error/TokenExpiredError.js +2 -2
- package/packages/errors-utils/dist/cjs/error/TokenMalformedError.d.ts +2 -2
- package/packages/errors-utils/dist/cjs/error/TokenMalformedError.js +2 -2
- package/packages/errors-utils/dist/cjs/error/UnauthorizedError.d.ts +1 -2
- package/packages/errors-utils/dist/cjs/error/UnauthorizedError.js +2 -2
- package/packages/errors-utils/dist/cjs/error/index.d.ts +14 -0
- package/packages/errors-utils/dist/cjs/error/index.js +39 -0
- package/packages/errors-utils/dist/cjs/errorRegistry/errorRegistry.d.ts +19 -0
- package/packages/errors-utils/dist/cjs/errorRegistry/errorRegistry.js +63 -0
- package/packages/errors-utils/dist/cjs/errorRegistry/index.d.ts +3 -0
- package/packages/errors-utils/dist/cjs/errorRegistry/index.js +6 -0
- package/packages/errors-utils/dist/cjs/index.d.ts +3 -9
- package/packages/errors-utils/dist/cjs/index.js +12 -9
- package/packages/errors-utils/dist/cjs/middleware/express/{errorHandler.js → errorHandler.middleware.js} +4 -4
- package/packages/errors-utils/dist/cjs/middleware/express/index.d.ts +2 -2
- package/packages/errors-utils/dist/cjs/middleware/express/index.js +2 -2
- package/packages/errors-utils/dist/esm/constants/errorCodes.d.ts +28 -23
- package/packages/errors-utils/dist/esm/constants/errorCodes.js +57 -22
- package/packages/errors-utils/dist/esm/constants/errorMessages.d.ts +8 -1
- package/packages/errors-utils/dist/esm/constants/errorMessages.js +72 -29
- package/packages/errors-utils/dist/esm/error/AppError.d.ts +2 -2
- package/packages/errors-utils/dist/esm/error/AppError.js +2 -2
- package/packages/errors-utils/dist/esm/error/ServiceUnavailableError.d.ts +4 -0
- package/packages/errors-utils/dist/esm/error/ServiceUnavailableError.js +7 -0
- package/packages/errors-utils/dist/esm/error/TokenExpiredError.d.ts +2 -2
- package/packages/errors-utils/dist/esm/error/TokenExpiredError.js +2 -2
- package/packages/errors-utils/dist/esm/error/TokenMalformedError.d.ts +2 -2
- package/packages/errors-utils/dist/esm/error/TokenMalformedError.js +2 -2
- package/packages/errors-utils/dist/esm/error/UnauthorizedError.d.ts +1 -2
- package/packages/errors-utils/dist/esm/error/UnauthorizedError.js +2 -2
- package/packages/errors-utils/dist/esm/error/index.d.ts +14 -0
- package/packages/errors-utils/dist/esm/error/index.js +23 -0
- package/packages/errors-utils/dist/esm/errorRegistry/errorRegistry.d.ts +19 -0
- package/packages/errors-utils/dist/esm/errorRegistry/errorRegistry.js +59 -0
- package/packages/errors-utils/dist/esm/errorRegistry/index.d.ts +3 -0
- package/packages/errors-utils/dist/esm/errorRegistry/index.js +3 -0
- package/packages/errors-utils/dist/esm/index.d.ts +3 -9
- package/packages/errors-utils/dist/esm/index.js +12 -9
- package/packages/errors-utils/dist/esm/middleware/express/{errorHandler.js → errorHandler.middleware.js} +5 -5
- package/packages/errors-utils/dist/esm/middleware/express/index.d.ts +2 -2
- package/packages/errors-utils/dist/esm/middleware/express/index.js +2 -2
- package/packages/errors-utils/dist/types/constants/errorCodes.d.ts +28 -23
- package/packages/errors-utils/dist/types/constants/errorMessages.d.ts +8 -1
- package/packages/errors-utils/dist/types/error/AppError.d.ts +2 -2
- package/packages/errors-utils/dist/types/error/ServiceUnavailableError.d.ts +4 -0
- package/packages/errors-utils/dist/types/error/TokenExpiredError.d.ts +2 -2
- package/packages/errors-utils/dist/types/error/TokenMalformedError.d.ts +2 -2
- package/packages/errors-utils/dist/types/error/UnauthorizedError.d.ts +1 -2
- package/packages/errors-utils/dist/types/error/index.d.ts +14 -0
- package/packages/errors-utils/dist/types/errorRegistry/errorRegistry.d.ts +19 -0
- package/packages/errors-utils/dist/types/errorRegistry/index.d.ts +3 -0
- package/packages/errors-utils/dist/types/index.d.ts +3 -9
- package/packages/errors-utils/dist/types/middleware/express/index.d.ts +2 -2
- package/packages/errors-utils/package.json +4 -4
- package/packages/errors-utils/src/constants/errorCodes.ts +64 -23
- package/packages/errors-utils/src/constants/errorMessages.ts +91 -34
- package/packages/errors-utils/src/error/AppError.ts +3 -2
- package/packages/errors-utils/src/error/ServiceUnavailableError.ts +8 -0
- package/packages/errors-utils/src/error/TokenExpiredError.ts +2 -2
- package/packages/errors-utils/src/error/TokenMalformedError.ts +2 -2
- package/packages/errors-utils/src/error/UnauthorizedError.ts +8 -8
- package/packages/errors-utils/src/error/index.ts +26 -0
- package/packages/errors-utils/src/errorRegistry/errorRegistry.ts +74 -0
- package/packages/errors-utils/src/errorRegistry/index.ts +4 -0
- package/packages/errors-utils/src/index.ts +12 -10
- package/packages/errors-utils/src/middleware/express/{errorHandler.ts → errorHandler.middleware.ts} +5 -5
- package/packages/errors-utils/src/middleware/express/index.ts +2 -2
- package/packages/js-extensions/README.md +174 -425
- package/packages/js-extensions/dist/cjs/array/array-extensions.js +84 -50
- package/packages/js-extensions/dist/cjs/core/performance.d.ts +1 -0
- package/packages/js-extensions/dist/cjs/core/performance.js +6 -0
- package/packages/js-extensions/dist/cjs/core/version.d.ts +1 -0
- package/packages/js-extensions/dist/cjs/core/version.js +9 -0
- package/packages/js-extensions/dist/cjs/index.d.ts +1 -0
- package/packages/js-extensions/dist/cjs/index.js +1 -0
- package/packages/js-extensions/dist/cjs/number/number-extensions.js +85 -97
- package/packages/js-extensions/dist/cjs/object/object-extensions.js +102 -103
- package/packages/js-extensions/dist/cjs/string/string-extensions.js +66 -43
- package/packages/js-extensions/dist/cjs/types/global-augmentations.d.ts +1 -0
- package/packages/js-extensions/dist/cjs/utils/defineExtension.d.ts +1 -0
- package/packages/js-extensions/dist/cjs/utils/defineExtension.js +13 -0
- package/packages/js-extensions/dist/cjs/utils/index.d.ts +1 -0
- package/packages/js-extensions/dist/cjs/utils/index.js +1 -0
- package/packages/js-extensions/dist/esm/array/array-extensions.js +84 -50
- package/packages/js-extensions/dist/esm/core/performance.d.ts +1 -0
- package/packages/js-extensions/dist/esm/core/performance.js +5 -0
- package/packages/js-extensions/dist/esm/core/version.d.ts +1 -0
- package/packages/js-extensions/dist/esm/core/version.js +5 -0
- package/packages/js-extensions/dist/esm/index.d.ts +1 -0
- package/packages/js-extensions/dist/esm/index.js +1 -0
- package/packages/js-extensions/dist/esm/number/number-extensions.js +86 -98
- package/packages/js-extensions/dist/esm/object/object-extensions.js +102 -103
- package/packages/js-extensions/dist/esm/string/string-extensions.js +66 -43
- package/packages/js-extensions/dist/esm/types/global-augmentations.d.ts +1 -0
- package/packages/js-extensions/dist/esm/utils/defineExtension.d.ts +1 -0
- package/packages/js-extensions/dist/esm/utils/defineExtension.js +10 -0
- package/packages/js-extensions/dist/esm/utils/index.d.ts +1 -0
- package/packages/js-extensions/dist/esm/utils/index.js +1 -0
- package/packages/js-extensions/dist/types/core/performance.d.ts +1 -0
- package/packages/js-extensions/dist/types/core/version.d.ts +1 -0
- package/packages/js-extensions/dist/types/index.d.ts +1 -0
- package/packages/js-extensions/dist/types/types/global-augmentations.d.ts +1 -0
- package/packages/js-extensions/dist/types/utils/defineExtension.d.ts +1 -0
- package/packages/js-extensions/dist/types/utils/index.d.ts +1 -0
- package/packages/js-extensions/package.json +8 -4
- package/packages/js-extensions/src/array/array-extensions.ts +268 -150
- package/packages/js-extensions/src/core/performance.ts +11 -0
- package/packages/js-extensions/src/core/version.ts +7 -0
- package/packages/js-extensions/src/index.ts +2 -0
- package/packages/js-extensions/src/number/number-extensions.ts +90 -123
- package/packages/js-extensions/src/object/object-extensions.ts +102 -130
- package/packages/js-extensions/src/string/string-extensions.ts +80 -76
- package/packages/js-extensions/src/types/global-augmentations.ts +2 -1
- package/packages/js-extensions/src/utils/defineExtension.ts +14 -0
- package/packages/js-extensions/src/utils/index.ts +1 -0
- package/packages/response-utils/README.md +156 -198
- package/packages/response-utils/dist/cjs/core/BaseResponder.js +20 -4
- package/packages/response-utils/dist/cjs/index.d.ts +0 -1
- package/packages/response-utils/dist/cjs/index.js +1 -25
- package/packages/response-utils/dist/esm/core/BaseResponder.js +20 -4
- package/packages/response-utils/dist/esm/index.d.ts +0 -1
- package/packages/response-utils/dist/esm/index.js +0 -2
- package/packages/response-utils/dist/types/index.d.ts +0 -1
- package/packages/response-utils/package.json +1 -1
- package/packages/response-utils/src/core/BaseResponder.ts +25 -4
- package/packages/response-utils/src/index.ts +0 -3
- package/packages/response-utils/src/middleware/express/expressMiddleware.ts +1 -1
- package/packages/security/README.md +153 -355
- package/packages/security/dist/cjs/core/crypto/cryptoManager.js +34 -17
- package/packages/security/dist/cjs/core/jwt/decode.js +4 -1
- package/packages/security/dist/cjs/core/jwt/generateTokens.js +4 -1
- package/packages/security/dist/cjs/core/jwt/jwtManager.d.ts +19 -43
- package/packages/security/dist/cjs/core/jwt/jwtManager.js +84 -199
- package/packages/security/dist/cjs/core/jwt/parseDuration.js +3 -2
- package/packages/security/dist/cjs/core/jwt/signToken.js +2 -1
- package/packages/security/dist/cjs/core/jwt/validateToken.d.ts +10 -7
- package/packages/security/dist/cjs/core/jwt/validateToken.js +19 -10
- package/packages/security/dist/cjs/core/jwt/verify.d.ts +8 -9
- package/packages/security/dist/cjs/core/jwt/verify.js +59 -14
- package/packages/security/dist/cjs/core/password/hash.js +4 -4
- package/packages/security/dist/cjs/core/password/passwordManager.d.ts +1 -1
- package/packages/security/dist/cjs/core/password/passwordManager.js +36 -80
- package/packages/security/dist/cjs/core/password/strength.js +12 -6
- package/packages/security/dist/cjs/core/password/utils.d.ts +12 -0
- package/packages/security/dist/cjs/core/password/utils.js +16 -1
- package/packages/security/dist/cjs/core/password/verify.js +4 -4
- package/packages/security/dist/cjs/index.d.ts +2 -7
- package/packages/security/dist/esm/core/crypto/cryptoManager.js +34 -17
- package/packages/security/dist/esm/core/jwt/decode.js +4 -1
- package/packages/security/dist/esm/core/jwt/generateTokens.js +4 -1
- package/packages/security/dist/esm/core/jwt/jwtManager.d.ts +19 -43
- package/packages/security/dist/esm/core/jwt/jwtManager.js +85 -200
- package/packages/security/dist/esm/core/jwt/parseDuration.js +3 -2
- package/packages/security/dist/esm/core/jwt/signToken.js +2 -1
- package/packages/security/dist/esm/core/jwt/validateToken.d.ts +10 -7
- package/packages/security/dist/esm/core/jwt/validateToken.js +19 -10
- package/packages/security/dist/esm/core/jwt/verify.d.ts +8 -9
- package/packages/security/dist/esm/core/jwt/verify.js +58 -13
- package/packages/security/dist/esm/core/password/hash.js +4 -4
- package/packages/security/dist/esm/core/password/passwordManager.d.ts +1 -1
- package/packages/security/dist/esm/core/password/passwordManager.js +36 -80
- package/packages/security/dist/esm/core/password/strength.js +12 -6
- package/packages/security/dist/esm/core/password/utils.d.ts +12 -0
- package/packages/security/dist/esm/core/password/utils.js +16 -1
- package/packages/security/dist/esm/core/password/verify.js +4 -4
- package/packages/security/dist/esm/index.d.ts +2 -7
- package/packages/security/dist/types/core/jwt/jwtManager.d.ts +19 -43
- package/packages/security/dist/types/core/jwt/validateToken.d.ts +10 -7
- package/packages/security/dist/types/core/jwt/verify.d.ts +8 -9
- package/packages/security/dist/types/core/password/passwordManager.d.ts +1 -1
- package/packages/security/dist/types/core/password/utils.d.ts +12 -0
- package/packages/security/dist/types/index.d.ts +2 -7
- package/packages/security/package.json +3 -3
- package/packages/security/src/core/crypto/cryptoManager.ts +53 -21
- package/packages/security/src/core/jwt/decode.ts +4 -1
- package/packages/security/src/core/jwt/generateTokens.ts +4 -1
- package/packages/security/src/core/jwt/jwtManager.ts +105 -257
- package/packages/security/src/core/jwt/parseDuration.ts +4 -2
- package/packages/security/src/core/jwt/signToken.ts +2 -1
- package/packages/security/src/core/jwt/validateToken.ts +21 -13
- package/packages/security/src/core/jwt/verify.ts +82 -20
- package/packages/security/src/core/password/hash.ts +10 -4
- package/packages/security/src/core/password/passwordManager.ts +38 -108
- package/packages/security/src/core/password/strength.ts +13 -8
- package/packages/security/src/core/password/utils.ts +19 -3
- package/packages/security/src/core/password/verify.ts +6 -4
- package/packages/server-utils/README.md +1 -1
- package/packages/server-utils/dist/cjs/core/server.js +6 -6
- package/packages/server-utils/dist/cjs/middleware/auth.middleware.d.ts +1 -2
- package/packages/server-utils/dist/cjs/middleware/auth.middleware.js +17 -14
- package/packages/server-utils/dist/cjs/middleware/cache.middleware.js +2 -2
- package/packages/server-utils/dist/cjs/middleware/errorHandler.middleware.d.ts +1 -1
- package/packages/server-utils/dist/cjs/middleware/errorHandler.middleware.js +34 -17
- package/packages/server-utils/dist/cjs/middleware/session.middleware.js +8 -8
- package/packages/server-utils/dist/cjs/middleware/validation.middleware.js +2 -2
- package/packages/server-utils/dist/esm/core/server.js +6 -6
- package/packages/server-utils/dist/esm/middleware/auth.middleware.d.ts +1 -2
- package/packages/server-utils/dist/esm/middleware/auth.middleware.js +18 -15
- package/packages/server-utils/dist/esm/middleware/cache.middleware.js +2 -2
- package/packages/server-utils/dist/esm/middleware/errorHandler.middleware.d.ts +1 -1
- package/packages/server-utils/dist/esm/middleware/errorHandler.middleware.js +34 -17
- package/packages/server-utils/dist/esm/middleware/session.middleware.js +8 -8
- package/packages/server-utils/dist/esm/middleware/validation.middleware.js +2 -2
- package/packages/server-utils/dist/types/middleware/auth.middleware.d.ts +1 -2
- package/packages/server-utils/dist/types/middleware/errorHandler.middleware.d.ts +1 -1
- package/packages/server-utils/package.json +4 -4
- package/packages/server-utils/src/core/server.ts +6 -6
- package/packages/server-utils/src/middleware/auth.middleware.ts +40 -27
- package/packages/server-utils/src/middleware/cache.middleware.ts +2 -2
- package/packages/server-utils/src/middleware/errorHandler.middleware.ts +39 -24
- package/packages/server-utils/src/middleware/session.middleware.ts +11 -8
- package/packages/server-utils/src/middleware/validation.middleware.ts +2 -3
- package/packages/errors-utils/dist/cjs/error/RateLimitError.d.ts +0 -4
- package/packages/errors-utils/dist/cjs/error/RateLimitError.js +0 -11
- package/packages/errors-utils/dist/cjs/utils/mapAppErrorToResponder.d.ts +0 -3
- package/packages/errors-utils/dist/cjs/utils/mapAppErrorToResponder.js +0 -27
- package/packages/errors-utils/dist/esm/error/RateLimitError.d.ts +0 -4
- package/packages/errors-utils/dist/esm/error/RateLimitError.js +0 -7
- package/packages/errors-utils/dist/esm/utils/mapAppErrorToResponder.d.ts +0 -3
- package/packages/errors-utils/dist/esm/utils/mapAppErrorToResponder.js +0 -24
- package/packages/errors-utils/dist/types/error/RateLimitError.d.ts +0 -4
- package/packages/errors-utils/dist/types/utils/mapAppErrorToResponder.d.ts +0 -3
- package/packages/errors-utils/src/error/RateLimitError.ts +0 -8
- package/packages/errors-utils/src/utils/mapAppErrorToResponder.ts +0 -38
- package/packages/response-utils/src/legacy.ts +0 -30
- /package/packages/errors-utils/dist/cjs/middleware/express/{errorConverter.d.ts → errorConverter.middleware.d.ts} +0 -0
- /package/packages/errors-utils/dist/cjs/middleware/express/{errorConverter.js → errorConverter.middleware.js} +0 -0
- /package/packages/errors-utils/dist/cjs/middleware/express/{errorHandler.d.ts → errorHandler.middleware.d.ts} +0 -0
- /package/packages/errors-utils/dist/esm/middleware/express/{errorConverter.d.ts → errorConverter.middleware.d.ts} +0 -0
- /package/packages/errors-utils/dist/esm/middleware/express/{errorConverter.js → errorConverter.middleware.js} +0 -0
- /package/packages/errors-utils/dist/esm/middleware/express/{errorHandler.d.ts → errorHandler.middleware.d.ts} +0 -0
- /package/packages/errors-utils/dist/types/middleware/express/{errorConverter.d.ts → errorConverter.middleware.d.ts} +0 -0
- /package/packages/errors-utils/dist/types/middleware/express/{errorHandler.d.ts → errorHandler.middleware.d.ts} +0 -0
- /package/packages/errors-utils/src/middleware/express/{errorConverter.ts → errorConverter.middleware.ts} +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createClient, createCluster } from 'redis';
|
|
2
|
+
import { CACHE_ERROR_CODES } from 'src/errors/cacheErrorCodes';
|
|
2
3
|
import { BaseCache } from '../../core/BaseCache';
|
|
3
4
|
import { CacheError } from '../../errors';
|
|
4
5
|
/**
|
|
@@ -66,8 +67,12 @@ export class RedisCache extends BaseCache {
|
|
|
66
67
|
this.isConnected = true;
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
|
-
catch (
|
|
70
|
-
throw new CacheError(
|
|
70
|
+
catch (error) {
|
|
71
|
+
throw new CacheError(CACHE_ERROR_CODES.CACHE_CONNECTION_FAILED, {
|
|
72
|
+
adapter: 'redis',
|
|
73
|
+
operation: 'connect',
|
|
74
|
+
cause: error instanceof Error ? error : undefined,
|
|
75
|
+
});
|
|
71
76
|
}
|
|
72
77
|
}
|
|
73
78
|
/**
|
|
@@ -93,8 +98,13 @@ export class RedisCache extends BaseCache {
|
|
|
93
98
|
this.recordHit();
|
|
94
99
|
return this.deserialize(value);
|
|
95
100
|
}
|
|
96
|
-
catch (
|
|
97
|
-
throw new CacheError(
|
|
101
|
+
catch (error) {
|
|
102
|
+
throw new CacheError(CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
103
|
+
adapter: 'redis',
|
|
104
|
+
operation: 'get',
|
|
105
|
+
details: { key },
|
|
106
|
+
cause: error instanceof Error ? error : undefined,
|
|
107
|
+
});
|
|
98
108
|
}
|
|
99
109
|
}
|
|
100
110
|
/**
|
|
@@ -114,8 +124,13 @@ export class RedisCache extends BaseCache {
|
|
|
114
124
|
}
|
|
115
125
|
this.recordSet();
|
|
116
126
|
}
|
|
117
|
-
catch (
|
|
118
|
-
throw new CacheError(
|
|
127
|
+
catch (error) {
|
|
128
|
+
throw new CacheError(CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
129
|
+
adapter: 'redis',
|
|
130
|
+
operation: 'set',
|
|
131
|
+
details: { key },
|
|
132
|
+
cause: error instanceof Error ? error : undefined,
|
|
133
|
+
});
|
|
119
134
|
}
|
|
120
135
|
}
|
|
121
136
|
/**
|
|
@@ -129,8 +144,13 @@ export class RedisCache extends BaseCache {
|
|
|
129
144
|
this.recordDelete();
|
|
130
145
|
return result > 0;
|
|
131
146
|
}
|
|
132
|
-
catch (
|
|
133
|
-
throw new CacheError(
|
|
147
|
+
catch (error) {
|
|
148
|
+
throw new CacheError(CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
149
|
+
adapter: 'redis',
|
|
150
|
+
operation: 'delete',
|
|
151
|
+
details: { key },
|
|
152
|
+
cause: error instanceof Error ? error : undefined,
|
|
153
|
+
});
|
|
134
154
|
}
|
|
135
155
|
}
|
|
136
156
|
/**
|
|
@@ -143,8 +163,13 @@ export class RedisCache extends BaseCache {
|
|
|
143
163
|
const result = await this.client.exists(fullKey);
|
|
144
164
|
return result > 0;
|
|
145
165
|
}
|
|
146
|
-
catch (
|
|
147
|
-
throw new CacheError(
|
|
166
|
+
catch (error) {
|
|
167
|
+
throw new CacheError(CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
168
|
+
adapter: 'redis',
|
|
169
|
+
operation: 'exists',
|
|
170
|
+
details: { key },
|
|
171
|
+
cause: error instanceof Error ? error : undefined,
|
|
172
|
+
});
|
|
148
173
|
}
|
|
149
174
|
}
|
|
150
175
|
/**
|
|
@@ -169,8 +194,12 @@ export class RedisCache extends BaseCache {
|
|
|
169
194
|
}
|
|
170
195
|
}
|
|
171
196
|
}
|
|
172
|
-
catch (
|
|
173
|
-
throw new CacheError(
|
|
197
|
+
catch (error) {
|
|
198
|
+
throw new CacheError(CACHE_ERROR_CODES.CACHE_OPERATION_TIMEOUT, {
|
|
199
|
+
adapter: 'redis',
|
|
200
|
+
operation: 'clear',
|
|
201
|
+
cause: error instanceof Error ? error : undefined,
|
|
202
|
+
});
|
|
174
203
|
}
|
|
175
204
|
}
|
|
176
205
|
/**
|
|
@@ -195,8 +224,13 @@ export class RedisCache extends BaseCache {
|
|
|
195
224
|
});
|
|
196
225
|
return result;
|
|
197
226
|
}
|
|
198
|
-
catch (
|
|
199
|
-
throw new CacheError(
|
|
227
|
+
catch (error) {
|
|
228
|
+
throw new CacheError(CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
229
|
+
adapter: 'redis',
|
|
230
|
+
operation: 'getMultiple',
|
|
231
|
+
details: { keys },
|
|
232
|
+
cause: error instanceof Error ? error : undefined,
|
|
233
|
+
});
|
|
200
234
|
}
|
|
201
235
|
}
|
|
202
236
|
/**
|
|
@@ -227,8 +261,13 @@ export class RedisCache extends BaseCache {
|
|
|
227
261
|
}
|
|
228
262
|
this.stats.sets += Object.keys(data).length;
|
|
229
263
|
}
|
|
230
|
-
catch (
|
|
231
|
-
throw new CacheError(
|
|
264
|
+
catch (error) {
|
|
265
|
+
throw new CacheError(CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
266
|
+
adapter: 'redis',
|
|
267
|
+
operation: 'setMultiple',
|
|
268
|
+
details: { keys: Object.keys(data) },
|
|
269
|
+
cause: error instanceof Error ? error : undefined,
|
|
270
|
+
});
|
|
232
271
|
}
|
|
233
272
|
}
|
|
234
273
|
/**
|
|
@@ -242,8 +281,13 @@ export class RedisCache extends BaseCache {
|
|
|
242
281
|
this.stats.deletes += result;
|
|
243
282
|
return result;
|
|
244
283
|
}
|
|
245
|
-
catch (
|
|
246
|
-
throw new CacheError(
|
|
284
|
+
catch (error) {
|
|
285
|
+
throw new CacheError(CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
286
|
+
adapter: 'redis',
|
|
287
|
+
operation: 'deleteMultiple',
|
|
288
|
+
details: { keys },
|
|
289
|
+
cause: error instanceof Error ? error : undefined,
|
|
290
|
+
});
|
|
247
291
|
}
|
|
248
292
|
}
|
|
249
293
|
/**
|
|
@@ -255,8 +299,13 @@ export class RedisCache extends BaseCache {
|
|
|
255
299
|
const fullKey = this.buildKey(key);
|
|
256
300
|
return await this.client.incrBy(fullKey, amount);
|
|
257
301
|
}
|
|
258
|
-
catch (
|
|
259
|
-
throw new CacheError(
|
|
302
|
+
catch (error) {
|
|
303
|
+
throw new CacheError(CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
304
|
+
adapter: 'redis',
|
|
305
|
+
operation: 'increment',
|
|
306
|
+
details: { key },
|
|
307
|
+
cause: error instanceof Error ? error : undefined,
|
|
308
|
+
});
|
|
260
309
|
}
|
|
261
310
|
}
|
|
262
311
|
/**
|
|
@@ -268,8 +317,13 @@ export class RedisCache extends BaseCache {
|
|
|
268
317
|
const fullKey = this.buildKey(key);
|
|
269
318
|
return await this.client.decrBy(fullKey, amount);
|
|
270
319
|
}
|
|
271
|
-
catch (
|
|
272
|
-
throw new CacheError(
|
|
320
|
+
catch (error) {
|
|
321
|
+
throw new CacheError(CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
322
|
+
adapter: 'redis',
|
|
323
|
+
operation: 'decrement',
|
|
324
|
+
details: { key },
|
|
325
|
+
cause: error instanceof Error ? error : undefined,
|
|
326
|
+
});
|
|
273
327
|
}
|
|
274
328
|
}
|
|
275
329
|
/**
|
|
@@ -294,12 +348,12 @@ export class RedisCache extends BaseCache {
|
|
|
294
348
|
timestamp: new Date(),
|
|
295
349
|
};
|
|
296
350
|
}
|
|
297
|
-
catch (
|
|
351
|
+
catch (error) {
|
|
298
352
|
return {
|
|
299
353
|
isAlive: false,
|
|
300
354
|
adapter: 'redis',
|
|
301
355
|
timestamp: new Date(),
|
|
302
|
-
error:
|
|
356
|
+
error: error.message,
|
|
303
357
|
};
|
|
304
358
|
}
|
|
305
359
|
}
|
|
@@ -314,8 +368,12 @@ export class RedisCache extends BaseCache {
|
|
|
314
368
|
this.client = null;
|
|
315
369
|
}
|
|
316
370
|
}
|
|
317
|
-
catch (
|
|
318
|
-
throw new CacheError(
|
|
371
|
+
catch (error) {
|
|
372
|
+
throw new CacheError(CACHE_ERROR_CODES.CACHE_ERROR, {
|
|
373
|
+
adapter: 'redis',
|
|
374
|
+
operation: 'close',
|
|
375
|
+
cause: error instanceof Error ? error : undefined,
|
|
376
|
+
});
|
|
319
377
|
}
|
|
320
378
|
}
|
|
321
379
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CACHE_ERROR_CODES } from 'src/errors/cacheErrorCodes';
|
|
1
2
|
import { CacheError } from '../errors';
|
|
2
3
|
/**
|
|
3
4
|
* Abstract base class for all cache adapters
|
|
@@ -27,8 +28,12 @@ export class BaseCache {
|
|
|
27
28
|
try {
|
|
28
29
|
return JSON.parse(data);
|
|
29
30
|
}
|
|
30
|
-
catch (
|
|
31
|
-
throw new CacheError(
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw new CacheError(CACHE_ERROR_CODES.CACHE_DESERIALIZE_ERROR, {
|
|
33
|
+
adapter: this.config.adapter,
|
|
34
|
+
operation: 'deserialize',
|
|
35
|
+
cause: error instanceof Error ? error : undefined,
|
|
36
|
+
});
|
|
32
37
|
}
|
|
33
38
|
}
|
|
34
39
|
/**
|
|
@@ -38,8 +43,12 @@ export class BaseCache {
|
|
|
38
43
|
try {
|
|
39
44
|
return JSON.stringify(value);
|
|
40
45
|
}
|
|
41
|
-
catch (
|
|
42
|
-
throw new CacheError(
|
|
46
|
+
catch (error) {
|
|
47
|
+
throw new CacheError(CACHE_ERROR_CODES.CACHE_SERIALIZE_ERROR, {
|
|
48
|
+
adapter: this.config.adapter,
|
|
49
|
+
operation: 'serialize',
|
|
50
|
+
cause: error instanceof Error ? error : undefined,
|
|
51
|
+
});
|
|
43
52
|
}
|
|
44
53
|
}
|
|
45
54
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CACHE_ERROR_CODES } from 'src/errors/cacheErrorCodes';
|
|
1
2
|
import { MemcacheCache } from '../adapters/memcache';
|
|
2
3
|
import { MemoryCache } from '../adapters/memory';
|
|
3
4
|
import { RedisCache } from '../adapters/redis';
|
|
@@ -15,11 +16,23 @@ export class CacheFactory {
|
|
|
15
16
|
const redisConfig = config;
|
|
16
17
|
// Validate: can't use both single + cluster
|
|
17
18
|
if (redisConfig.host && redisConfig.cluster) {
|
|
18
|
-
throw new CacheError(
|
|
19
|
+
throw new CacheError(CACHE_ERROR_CODES.CACHE_INVALID_CONFIG, {
|
|
20
|
+
adapter: 'redis',
|
|
21
|
+
operation: 'create',
|
|
22
|
+
details: {
|
|
23
|
+
reason: 'Redis config cannot have both "host" and "cluster" defined',
|
|
24
|
+
},
|
|
25
|
+
});
|
|
19
26
|
}
|
|
20
27
|
// Require either single or cluster
|
|
21
28
|
if (!redisConfig.host && !redisConfig.cluster) {
|
|
22
|
-
throw new CacheError(
|
|
29
|
+
throw new CacheError(CACHE_ERROR_CODES.CACHE_INVALID_CONFIG, {
|
|
30
|
+
adapter: 'redis',
|
|
31
|
+
operation: 'create',
|
|
32
|
+
details: {
|
|
33
|
+
reason: 'Redis requires either host or cluster config',
|
|
34
|
+
},
|
|
35
|
+
});
|
|
23
36
|
}
|
|
24
37
|
return new RedisCache(redisConfig);
|
|
25
38
|
case 'memcache':
|
|
@@ -27,7 +40,10 @@ export class CacheFactory {
|
|
|
27
40
|
case 'memory':
|
|
28
41
|
return new MemoryCache(config);
|
|
29
42
|
default:
|
|
30
|
-
throw new CacheError(
|
|
43
|
+
throw new CacheError(CACHE_ERROR_CODES.CACHE_UNSUPPORTED_ADAPTER, {
|
|
44
|
+
adapter: config.adapter,
|
|
45
|
+
operation: 'create',
|
|
46
|
+
});
|
|
31
47
|
}
|
|
32
48
|
}
|
|
33
49
|
/**
|
|
@@ -51,6 +67,12 @@ export class CacheFactory {
|
|
|
51
67
|
});
|
|
52
68
|
}
|
|
53
69
|
// No fallback, throw error
|
|
54
|
-
throw new CacheError(
|
|
70
|
+
throw new CacheError(CACHE_ERROR_CODES.CACHE_CONNECTION_FAILED, {
|
|
71
|
+
adapter: config.adapter,
|
|
72
|
+
operation: 'createWithFallback',
|
|
73
|
+
details: {
|
|
74
|
+
reason: `${config.adapter} cache is not alive and fallback is disabled`,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
55
77
|
}
|
|
56
78
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare class CacheError extends Error {
|
|
5
|
-
readonly code: string;
|
|
1
|
+
import { AppError } from '@naman_deep_singh/errors-utils';
|
|
2
|
+
import type { CacheErrorCode } from './cacheErrorCodes';
|
|
3
|
+
export declare class CacheError extends AppError {
|
|
6
4
|
readonly adapter?: string;
|
|
7
|
-
readonly
|
|
8
|
-
constructor(
|
|
5
|
+
readonly operation?: string;
|
|
6
|
+
constructor(code: CacheErrorCode, options?: {
|
|
7
|
+
adapter?: string;
|
|
8
|
+
operation?: string;
|
|
9
|
+
details?: unknown;
|
|
10
|
+
cause?: Error;
|
|
11
|
+
});
|
|
9
12
|
}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.name = 'CacheError';
|
|
8
|
-
this.code = code;
|
|
9
|
-
this.adapter = adapter;
|
|
10
|
-
this.originalError = originalError;
|
|
11
|
-
Object.setPrototypeOf(this, CacheError.prototype);
|
|
1
|
+
import { AppError } from '@naman_deep_singh/errors-utils';
|
|
2
|
+
export class CacheError extends AppError {
|
|
3
|
+
constructor(code, options) {
|
|
4
|
+
super(code, undefined, options?.details, options?.cause);
|
|
5
|
+
this.adapter = options?.adapter;
|
|
6
|
+
this.operation = options?.operation;
|
|
12
7
|
}
|
|
13
8
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const CACHE_ERROR_CODES: {
|
|
2
|
+
readonly CACHE_ERROR: "Temporary caching issue, please retry";
|
|
3
|
+
readonly CACHE_CONNECTION_FAILED: "Failed to connect to the cache server";
|
|
4
|
+
readonly CACHE_UNSUPPORTED_ADAPTER: "The specified cache adapter is not supported";
|
|
5
|
+
readonly CACHE_INVALID_CONFIG: "The provided cache configuration is invalid";
|
|
6
|
+
readonly CACHE_KEY_NOT_FOUND: "The requested cache key was not found";
|
|
7
|
+
readonly CACHE_OPERATION_TIMEOUT: "The cache operation timed out";
|
|
8
|
+
readonly CACHE_SERIALIZE_ERROR: "Failed to serialize cached data";
|
|
9
|
+
readonly CACHE_DESERIALIZE_ERROR: "Failed to deserialize cached data";
|
|
10
|
+
readonly SESSION_CREATE_ERROR: "Failed to create a new session";
|
|
11
|
+
readonly SESSION_GET_ERROR: "Failed to get session data";
|
|
12
|
+
readonly SESSION_UPDATE_ERROR: "Failed to update session data";
|
|
13
|
+
readonly SESSION_DELETE_ERROR: "Failed to delete session data";
|
|
14
|
+
readonly SESSION_EXISTS_ERROR: "Failed to check session existence";
|
|
15
|
+
readonly SESSION_CLEAR_ERROR: "Failed to clear sessions";
|
|
16
|
+
readonly SESSION_GET_MULTIPLE_ERROR: "Failed to get multiple sessions";
|
|
17
|
+
readonly SESSION_DELETE_MULTIPLE_ERROR: "Failed to delete multiple sessions";
|
|
18
|
+
readonly SESSION_EXTEND_ERROR: "Failed to extend session expiry";
|
|
19
|
+
readonly SESSION_GET_EXTEND_ERROR: "Failed to get and extend session data";
|
|
20
|
+
readonly SESSION_NOT_FOUND: "Session not found";
|
|
21
|
+
};
|
|
22
|
+
export type CacheErrorCode = (typeof CACHE_ERROR_CODES)[keyof typeof CACHE_ERROR_CODES];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const CACHE_ERROR_CODES = {
|
|
2
|
+
CACHE_ERROR: 'Temporary caching issue, please retry',
|
|
3
|
+
CACHE_CONNECTION_FAILED: 'Failed to connect to the cache server',
|
|
4
|
+
CACHE_UNSUPPORTED_ADAPTER: 'The specified cache adapter is not supported',
|
|
5
|
+
CACHE_INVALID_CONFIG: 'The provided cache configuration is invalid',
|
|
6
|
+
CACHE_KEY_NOT_FOUND: 'The requested cache key was not found',
|
|
7
|
+
CACHE_OPERATION_TIMEOUT: 'The cache operation timed out',
|
|
8
|
+
CACHE_SERIALIZE_ERROR: 'Failed to serialize cached data',
|
|
9
|
+
CACHE_DESERIALIZE_ERROR: 'Failed to deserialize cached data',
|
|
10
|
+
SESSION_CREATE_ERROR: 'Failed to create a new session',
|
|
11
|
+
SESSION_GET_ERROR: 'Failed to get session data',
|
|
12
|
+
SESSION_UPDATE_ERROR: 'Failed to update session data',
|
|
13
|
+
SESSION_DELETE_ERROR: 'Failed to delete session data',
|
|
14
|
+
SESSION_EXISTS_ERROR: 'Failed to check session existence',
|
|
15
|
+
SESSION_CLEAR_ERROR: 'Failed to clear sessions',
|
|
16
|
+
SESSION_GET_MULTIPLE_ERROR: 'Failed to get multiple sessions',
|
|
17
|
+
SESSION_DELETE_MULTIPLE_ERROR: 'Failed to delete multiple sessions',
|
|
18
|
+
SESSION_EXTEND_ERROR: 'Failed to extend session expiry',
|
|
19
|
+
SESSION_GET_EXTEND_ERROR: 'Failed to get and extend session data',
|
|
20
|
+
SESSION_NOT_FOUND: 'Session not found',
|
|
21
|
+
};
|
|
@@ -18,8 +18,8 @@ export function cacheSessionMiddleware(sessionStore, options) {
|
|
|
18
18
|
}
|
|
19
19
|
next();
|
|
20
20
|
}
|
|
21
|
-
catch (
|
|
22
|
-
console.error('Session middleware error:',
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.error('Session middleware error:', error);
|
|
23
23
|
next();
|
|
24
24
|
}
|
|
25
25
|
};
|
|
@@ -35,12 +35,12 @@ export function cacheHealthCheckMiddleware(cache, endpoint = '/.health/cache') {
|
|
|
35
35
|
.then((health) => {
|
|
36
36
|
res.status(health.isAlive ? 200 : 503).json(health);
|
|
37
37
|
})
|
|
38
|
-
.catch((
|
|
38
|
+
.catch((error) => {
|
|
39
39
|
res.status(503).json({
|
|
40
40
|
isAlive: false,
|
|
41
41
|
adapter: 'unknown',
|
|
42
42
|
timestamp: new Date(),
|
|
43
|
-
error:
|
|
43
|
+
error: error.message,
|
|
44
44
|
});
|
|
45
45
|
});
|
|
46
46
|
return;
|
|
@@ -93,8 +93,8 @@ export function cacheResponseMiddleware(cache, options) {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
if (responseData !== null) {
|
|
96
|
-
cache.set(cacheKey, responseData, ttl).catch((
|
|
97
|
-
console.error('Failed to cache response:',
|
|
96
|
+
cache.set(cacheKey, responseData, ttl).catch((error) => {
|
|
97
|
+
console.error('Failed to cache response:', error);
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
100
|
}
|
|
@@ -103,8 +103,8 @@ export function cacheResponseMiddleware(cache, options) {
|
|
|
103
103
|
};
|
|
104
104
|
next();
|
|
105
105
|
})
|
|
106
|
-
.catch((
|
|
107
|
-
console.error('Cache middleware error:',
|
|
106
|
+
.catch((error) => {
|
|
107
|
+
console.error('Cache middleware error:', error);
|
|
108
108
|
next();
|
|
109
109
|
});
|
|
110
110
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CacheError } from '../errors';
|
|
2
|
+
import { CACHE_ERROR_CODES } from 'src/errors/cacheErrorCodes';
|
|
2
3
|
/**
|
|
3
4
|
* Session store wrapper around cache adapters
|
|
4
5
|
* Provides session management functionality
|
|
@@ -20,8 +21,13 @@ export class SessionStore {
|
|
|
20
21
|
const ttlValue = ttl ?? this.options.ttl;
|
|
21
22
|
await this.cache.set(sessionId, data, ttlValue);
|
|
22
23
|
}
|
|
23
|
-
catch (
|
|
24
|
-
throw new CacheError(
|
|
24
|
+
catch (error) {
|
|
25
|
+
throw new CacheError(CACHE_ERROR_CODES.SESSION_CREATE_ERROR, {
|
|
26
|
+
adapter: 'session',
|
|
27
|
+
operation: 'create',
|
|
28
|
+
details: { sessionId },
|
|
29
|
+
cause: error instanceof Error ? error : undefined,
|
|
30
|
+
});
|
|
25
31
|
}
|
|
26
32
|
}
|
|
27
33
|
/**
|
|
@@ -31,8 +37,13 @@ export class SessionStore {
|
|
|
31
37
|
try {
|
|
32
38
|
return await this.cache.get(sessionId);
|
|
33
39
|
}
|
|
34
|
-
catch (
|
|
35
|
-
throw new CacheError(
|
|
40
|
+
catch (error) {
|
|
41
|
+
throw new CacheError(CACHE_ERROR_CODES.SESSION_GET_ERROR, {
|
|
42
|
+
adapter: 'session',
|
|
43
|
+
operation: 'get',
|
|
44
|
+
details: { sessionId },
|
|
45
|
+
cause: error instanceof Error ? error : undefined,
|
|
46
|
+
});
|
|
36
47
|
}
|
|
37
48
|
}
|
|
38
49
|
/**
|
|
@@ -42,16 +53,25 @@ export class SessionStore {
|
|
|
42
53
|
try {
|
|
43
54
|
const current = await this.cache.get(sessionId);
|
|
44
55
|
if (!current) {
|
|
45
|
-
throw new CacheError(
|
|
56
|
+
throw new CacheError(CACHE_ERROR_CODES.SESSION_NOT_FOUND, {
|
|
57
|
+
adapter: 'session',
|
|
58
|
+
operation: 'update',
|
|
59
|
+
details: { sessionId },
|
|
60
|
+
});
|
|
46
61
|
}
|
|
47
62
|
const merged = { ...current, ...data };
|
|
48
63
|
await this.cache.set(sessionId, merged, this.options.ttl);
|
|
49
64
|
}
|
|
50
|
-
catch (
|
|
51
|
-
if (
|
|
52
|
-
throw
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (error instanceof CacheError) {
|
|
67
|
+
throw error;
|
|
53
68
|
}
|
|
54
|
-
throw new CacheError(
|
|
69
|
+
throw new CacheError(CACHE_ERROR_CODES.SESSION_UPDATE_ERROR, {
|
|
70
|
+
adapter: 'session',
|
|
71
|
+
operation: 'update',
|
|
72
|
+
details: { sessionId },
|
|
73
|
+
cause: error instanceof Error ? error : undefined,
|
|
74
|
+
});
|
|
55
75
|
}
|
|
56
76
|
}
|
|
57
77
|
/**
|
|
@@ -61,8 +81,13 @@ export class SessionStore {
|
|
|
61
81
|
try {
|
|
62
82
|
return await this.cache.delete(sessionId);
|
|
63
83
|
}
|
|
64
|
-
catch (
|
|
65
|
-
throw new CacheError(
|
|
84
|
+
catch (error) {
|
|
85
|
+
throw new CacheError(CACHE_ERROR_CODES.SESSION_DELETE_ERROR, {
|
|
86
|
+
adapter: 'session',
|
|
87
|
+
operation: 'delete',
|
|
88
|
+
details: { sessionId },
|
|
89
|
+
cause: error instanceof Error ? error : undefined,
|
|
90
|
+
});
|
|
66
91
|
}
|
|
67
92
|
}
|
|
68
93
|
/**
|
|
@@ -72,8 +97,13 @@ export class SessionStore {
|
|
|
72
97
|
try {
|
|
73
98
|
return await this.cache.exists(sessionId);
|
|
74
99
|
}
|
|
75
|
-
catch (
|
|
76
|
-
throw new CacheError(
|
|
100
|
+
catch (error) {
|
|
101
|
+
throw new CacheError(CACHE_ERROR_CODES.SESSION_EXISTS_ERROR, {
|
|
102
|
+
adapter: 'session',
|
|
103
|
+
operation: 'exists',
|
|
104
|
+
details: { sessionId },
|
|
105
|
+
cause: error instanceof Error ? error : undefined,
|
|
106
|
+
});
|
|
77
107
|
}
|
|
78
108
|
}
|
|
79
109
|
/**
|
|
@@ -83,8 +113,12 @@ export class SessionStore {
|
|
|
83
113
|
try {
|
|
84
114
|
await this.cache.clear();
|
|
85
115
|
}
|
|
86
|
-
catch (
|
|
87
|
-
throw new CacheError(
|
|
116
|
+
catch (error) {
|
|
117
|
+
throw new CacheError(CACHE_ERROR_CODES.SESSION_CLEAR_ERROR, {
|
|
118
|
+
adapter: 'session',
|
|
119
|
+
operation: 'clear',
|
|
120
|
+
cause: error instanceof Error ? error : undefined,
|
|
121
|
+
});
|
|
88
122
|
}
|
|
89
123
|
}
|
|
90
124
|
/**
|
|
@@ -94,8 +128,12 @@ export class SessionStore {
|
|
|
94
128
|
try {
|
|
95
129
|
return await this.cache.getMultiple(sessionIds);
|
|
96
130
|
}
|
|
97
|
-
catch (
|
|
98
|
-
throw new CacheError(
|
|
131
|
+
catch (error) {
|
|
132
|
+
throw new CacheError(CACHE_ERROR_CODES.SESSION_GET_MULTIPLE_ERROR, {
|
|
133
|
+
adapter: 'session',
|
|
134
|
+
operation: 'getMultiple',
|
|
135
|
+
cause: error instanceof Error ? error : undefined,
|
|
136
|
+
});
|
|
99
137
|
}
|
|
100
138
|
}
|
|
101
139
|
/**
|
|
@@ -105,8 +143,12 @@ export class SessionStore {
|
|
|
105
143
|
try {
|
|
106
144
|
return await this.cache.deleteMultiple(sessionIds);
|
|
107
145
|
}
|
|
108
|
-
catch (
|
|
109
|
-
throw new CacheError(
|
|
146
|
+
catch (error) {
|
|
147
|
+
throw new CacheError(CACHE_ERROR_CODES.SESSION_DELETE_MULTIPLE_ERROR, {
|
|
148
|
+
adapter: 'session',
|
|
149
|
+
operation: 'deleteMultiple',
|
|
150
|
+
cause: error instanceof Error ? error : undefined,
|
|
151
|
+
});
|
|
110
152
|
}
|
|
111
153
|
}
|
|
112
154
|
/**
|
|
@@ -116,16 +158,25 @@ export class SessionStore {
|
|
|
116
158
|
try {
|
|
117
159
|
const current = await this.cache.get(sessionId);
|
|
118
160
|
if (!current) {
|
|
119
|
-
throw new CacheError(
|
|
161
|
+
throw new CacheError(CACHE_ERROR_CODES.SESSION_NOT_FOUND, {
|
|
162
|
+
adapter: 'session',
|
|
163
|
+
operation: 'extend',
|
|
164
|
+
details: { sessionId },
|
|
165
|
+
});
|
|
120
166
|
}
|
|
121
167
|
const ttlValue = ttl ?? this.options.ttl;
|
|
122
168
|
await this.cache.set(sessionId, current, ttlValue);
|
|
123
169
|
}
|
|
124
|
-
catch (
|
|
125
|
-
if (
|
|
126
|
-
throw
|
|
170
|
+
catch (error) {
|
|
171
|
+
if (error instanceof CacheError) {
|
|
172
|
+
throw error;
|
|
127
173
|
}
|
|
128
|
-
throw new CacheError(
|
|
174
|
+
throw new CacheError(CACHE_ERROR_CODES.SESSION_EXTEND_ERROR, {
|
|
175
|
+
adapter: 'session',
|
|
176
|
+
operation: 'extend',
|
|
177
|
+
details: { sessionId },
|
|
178
|
+
cause: error instanceof Error ? error : undefined,
|
|
179
|
+
});
|
|
129
180
|
}
|
|
130
181
|
}
|
|
131
182
|
/**
|
|
@@ -139,11 +190,16 @@ export class SessionStore {
|
|
|
139
190
|
}
|
|
140
191
|
return data;
|
|
141
192
|
}
|
|
142
|
-
catch (
|
|
143
|
-
if (
|
|
144
|
-
throw
|
|
193
|
+
catch (error) {
|
|
194
|
+
if (error instanceof CacheError) {
|
|
195
|
+
throw error;
|
|
145
196
|
}
|
|
146
|
-
throw new CacheError(
|
|
197
|
+
throw new CacheError(CACHE_ERROR_CODES.SESSION_GET_EXTEND_ERROR, {
|
|
198
|
+
adapter: 'session',
|
|
199
|
+
operation: 'getAndExtend',
|
|
200
|
+
details: { sessionId },
|
|
201
|
+
cause: error instanceof Error ? error : undefined,
|
|
202
|
+
});
|
|
147
203
|
}
|
|
148
204
|
}
|
|
149
205
|
/**
|