diff --git a/package.json b/package.json index e6972ed..eea92cb 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@nestjs/common": "^10", "@nestjs/core": "^10", "@nestjs/graphql": "^12", - "lru-cache": "^6", + "lru-cache": "^10", "protobufjs": "^7.1.2", "reflect-metadata": "^0.1.13", "rxjs": "^7.8.1" @@ -61,7 +61,6 @@ "@nestjs/testing": "^10.3.3", "@types/express": "^4.17.21", "@types/jest": "^29.5.12", - "@types/lru-cache": "^7.10.10", "@types/node": "^20", "@types/supertest": "^2.0.12", "@typescript-eslint/eslint-plugin": "^7.1.0", @@ -76,7 +75,7 @@ "graphql": "^16.8.1", "jest": "^29.3.1", "jest-extended": "^3.2.1", - "lru-cache": "^7.14.1", + "lru-cache": "^10.2.0", "npm-run-all": "^4.1.5", "prettier": "^3.2.5", "protobufjs": "^7.1.2", diff --git a/src/dataloaders/grpc-dataloader.interceptor.ts b/src/dataloaders/grpc-dataloader.interceptor.ts index a184afc..7afcb44 100644 --- a/src/dataloaders/grpc-dataloader.interceptor.ts +++ b/src/dataloaders/grpc-dataloader.interceptor.ts @@ -11,17 +11,17 @@ import DataLoader from 'dataloader'; import { Observable } from 'rxjs'; import { GrpcDataLoaderProvider } from './grpc-dataloader.provider'; import { getRequest, Request } from '../utils'; -import LRU from 'lru-cache'; +import { LRUCache } from 'lru-cache'; @Injectable() export class GrpcDataLoaderInterceptor implements NestInterceptor { private readonly logger = new Logger(GrpcDataLoaderInterceptor.name); // eslint-disable-next-line @typescript-eslint/no-explicit-any - private lru: LRU; + private lru: LRUCache; constructor(private moduleRef: ModuleRef) { - this.lru = new LRU({ + this.lru = new LRUCache({ max: 500, ttl: 1000, }); diff --git a/src/dataloaders/grpc-dataloader.provider.ts b/src/dataloaders/grpc-dataloader.provider.ts index 3b3ada3..e0b85a9 100644 --- a/src/dataloaders/grpc-dataloader.provider.ts +++ b/src/dataloaders/grpc-dataloader.provider.ts @@ -7,7 +7,7 @@ import { UncachedDataloader } from './uncached.dataloader'; import { FirstArgumentType, ReturnType } from '../types/util.types'; import { Request } from '../utils'; import { catchError } from 'rxjs/operators'; -import LRU from 'lru-cache'; +import { LRUCache } from 'lru-cache'; interface CacheSingleConfig { cacheKeyFn: (request: FirstArgumentType) => string; @@ -33,7 +33,7 @@ export type MergeConfig = Partial<{ }>; function wrapCache( - cache: LRU>, + cache: LRUCache>, config: CacheSingleConfig<(req: K) => Observable> ): CacheMap> { return { @@ -60,7 +60,7 @@ export abstract class GrpcDataLoaderProvider { generateDataLoader( methodName: string, request: Request, - cache?: LRU> + cache?: LRUCache> ): DataLoader { this.logger.debug( `Creating dataloader ${methodName} in ${this.constructor.name}` diff --git a/yarn.lock b/yarn.lock index 9b11efb..6234d50 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1431,13 +1431,6 @@ resolved "https://registry.npmjs.org/@types/long/-/long-4.0.2.tgz#b74129719fc8d11c01868010082d483b7545591a" integrity sha512-MqTGEo5bj5t157U6fA/BiDynNkn0YknVdh48CMPkTSpFTVmvao5UQmm7uEF6xBEo7qIMAlY/JSleYaE6VOdpaA== -"@types/lru-cache@^7.10.10": - version "7.10.10" - resolved "https://registry.npmjs.org/@types/lru-cache/-/lru-cache-7.10.10.tgz#3fa937c35ff4b3f6753d5737915c9bf8e693a713" - integrity sha512-nEpVRPWW9EBmx2SCfNn3ClYxPL7IktPX12HhIoSc/H5mMjdeW3+YsXIpseLQ2xF35+OcpwKQbEUw5VtqE4PDNA== - dependencies: - lru-cache "*" - "@types/mime@^1": version "1.3.2" resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a" @@ -4552,17 +4545,12 @@ long@^5.0.0: resolved "https://registry.npmjs.org/long/-/long-5.2.1.tgz#e27595d0083d103d2fa2c20c7699f8e0c92b897f" integrity sha512-GKSNGeNAtw8IryjjkhZxuKB3JzlcLTwjtiQCHKvqQet81I93kXslhDQruGI/QsddO83mcDToBVy7GqGS/zYf/A== -lru-cache@*, lru-cache@^7.14.1: - version "7.14.1" - resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-7.14.1.tgz#8da8d2f5f59827edb388e63e459ac23d6d408fea" - integrity sha512-ysxwsnTKdAx96aTRdhDOCQfDgbHnt8SK0KY8SEjO0wHinhWOFTESbjVCMPbU1uGXg/ch4lifqx0wfjOawU2+WA== - "lru-cache@7.10.1 - 7.13.1": version "7.13.1" resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-7.13.1.tgz#267a81fbd0881327c46a81c5922606a2cfe336c4" integrity sha512-CHqbAq7NFlW3RSnoWXLJBxCWaZVBrfa9UEHId2M3AW8iEBurbqduNexEUCGc3SHc6iCYXNJCDi903LajSVAEPQ== -lru-cache@^10.1.0, "lru-cache@^9.1.1 || ^10.0.0": +lru-cache@^10.1.0, lru-cache@^10.2.0, "lru-cache@^9.1.1 || ^10.0.0": version "10.2.0" resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.2.0.tgz#0bd445ca57363465900f4d1f9bd8db343a4d95c3" integrity sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q==