diff --git a/packages/commons/package.json b/packages/commons/package.json index 3713b9853b..ea0a09ac38 100644 --- a/packages/commons/package.json +++ b/packages/commons/package.json @@ -45,6 +45,10 @@ "import": "./lib/esm/fromBase64.js", "require": "./lib/cjs/fromBase64.js" }, + "./utils/lru-cache": { + "import": "./lib/esm/LRUCache.js", + "require": "./lib/cjs/LRUCache.js" + }, "./types": { "import": "./lib/esm/types/index.js", "require": "./lib/cjs/types/index.js" @@ -60,6 +64,10 @@ "lib/cjs/fromBase64.d.ts", "lib/esm/fromBase64.d.ts" ], + "utils/lru-cache": [ + "lib/cjs/LRUCache.d.ts", + "lib/esm/LRUCache.d.ts" + ], "types": [ "lib/cjs/types/index.d.ts", "lib/esm/types/index.d.ts" @@ -88,4 +96,4 @@ "devDependencies": { "@aws-lambda-powertools/testing-utils": "file:../testing" } -} +} \ No newline at end of file diff --git a/packages/idempotency/src/persistence/LRUCache.ts b/packages/commons/src/LRUCache.ts similarity index 98% rename from packages/idempotency/src/persistence/LRUCache.ts rename to packages/commons/src/LRUCache.ts index c41f07e1a6..76d2c6efc2 100644 --- a/packages/idempotency/src/persistence/LRUCache.ts +++ b/packages/commons/src/LRUCache.ts @@ -1,4 +1,4 @@ -import type { LRUCacheOptions } from '../types/LRUCache.js'; +import type { LRUCacheOptions } from './types/LRUCache.js'; const DEFAULT_MAX_SIZE = 100; const NEWER = Symbol('newer'); @@ -213,7 +213,7 @@ class LRUCache { */ private trackItemUse(item: Item): void { // If the item is already the newest, we don't need to do anything - if (this.mostRecentlyUsed === item) return; // TODO: check this + if (this.mostRecentlyUsed === item) return; // If the item is not the newest, we need to mark it as the newest if (item[NEWER]) { diff --git a/packages/idempotency/src/types/LRUCache.ts b/packages/commons/src/types/LRUCache.ts similarity index 100% rename from packages/idempotency/src/types/LRUCache.ts rename to packages/commons/src/types/LRUCache.ts diff --git a/packages/idempotency/tests/unit/persistence/LRUCache.test.ts b/packages/commons/tests/unit/LRUCache.test.ts similarity index 96% rename from packages/idempotency/tests/unit/persistence/LRUCache.test.ts rename to packages/commons/tests/unit/LRUCache.test.ts index 5732c31a45..cec778ac4c 100644 --- a/packages/idempotency/tests/unit/persistence/LRUCache.test.ts +++ b/packages/commons/tests/unit/LRUCache.test.ts @@ -1,9 +1,9 @@ /** * Test LRUCache class * - * @group unit/idempotency/persistence/lru-cache + * @group unit/commons/lru-cache */ -import { LRUCache } from '../../../src/persistence/LRUCache.js'; +import { LRUCache } from '../../src/LRUCache.js'; describe('Class: LRUMap', () => { describe('Method: add', () => { diff --git a/packages/commons/typedoc.json b/packages/commons/typedoc.json index 60dfaa41cd..fb15e9b68e 100644 --- a/packages/commons/typedoc.json +++ b/packages/commons/typedoc.json @@ -1,5 +1,13 @@ { - "extends": ["../../typedoc.base.json"], - "entryPoints": ["./src/index.ts", "./src/types/index.ts"], + "extends": [ + "../../typedoc.base.json" + ], + "entryPoints": [ + "./src/index.ts", + "./src/types/index.ts", + "./src/typeUtils.ts", + "./src/fromBase64.ts", + "./src/LRUCache.ts" + ], "readme": "./README.md" -} +} \ No newline at end of file diff --git a/packages/idempotency/src/persistence/BasePersistenceLayer.ts b/packages/idempotency/src/persistence/BasePersistenceLayer.ts index 83c730c72f..cd883c4218 100644 --- a/packages/idempotency/src/persistence/BasePersistenceLayer.ts +++ b/packages/idempotency/src/persistence/BasePersistenceLayer.ts @@ -1,5 +1,6 @@ import { type Hash, createHash } from 'node:crypto'; import type { JSONValue } from '@aws-lambda-powertools/commons/types'; +import { LRUCache } from '@aws-lambda-powertools/commons/utils/lru-cache'; import { search } from '@aws-lambda-powertools/jmespath'; import type { JMESPathParsingOptions } from '@aws-lambda-powertools/jmespath/types'; import { EnvironmentVariablesService } from '../config/EnvironmentVariablesService.js'; @@ -15,7 +16,6 @@ import type { BasePersistenceLayerOptions, } from '../types/BasePersistenceLayer.js'; import { IdempotencyRecord } from './IdempotencyRecord.js'; -import { LRUCache } from './LRUCache.js'; /** * Base class for all persistence layers. This class provides the basic functionality for