@credo-ts/redis-cache 0.7.2-pr-2704-20260918194459 → 0.7.2
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/build/RedisCache.d.mts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { AgentContext, Cache, CacheOptions } from "@credo-ts/core";
|
|
2
2
|
import Redis, { RedisOptions } from "ioredis";
|
|
3
|
-
|
|
4
3
|
//#region src/RedisCache.d.ts
|
|
5
|
-
type RedisCacheOptions = RedisOptions;
|
|
4
|
+
export type RedisCacheOptions = RedisOptions;
|
|
6
5
|
/**
|
|
7
6
|
* Redis Cache implementation of the {@link Cache} interface.
|
|
8
7
|
*
|
|
@@ -10,7 +9,7 @@ type RedisCacheOptions = RedisOptions;
|
|
|
10
9
|
* `global:` for entries using the `'global'` scope, making the cache safe to use across multiple
|
|
11
10
|
* agent context instances. This means `global` is effectively a reserved context correlation id.
|
|
12
11
|
*/
|
|
13
|
-
declare class RedisCache implements Cache {
|
|
12
|
+
export declare class RedisCache implements Cache {
|
|
14
13
|
private readonly _client;
|
|
15
14
|
constructor(options?: RedisCacheOptions | Redis);
|
|
16
15
|
private client;
|
|
@@ -30,5 +29,4 @@ declare class RedisCache implements Cache {
|
|
|
30
29
|
disconnect(): Promise<void>;
|
|
31
30
|
}
|
|
32
31
|
//#endregion
|
|
33
|
-
export { RedisCache, RedisCacheOptions };
|
|
34
32
|
//# sourceMappingURL=RedisCache.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RedisCache.d.mts","names":[],"sources":["../src/RedisCache.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"RedisCache.d.mts","names":[],"sources":["../src/RedisCache.ts"],"mappings":";;;YAGY,oBAAoB;;;;;;;;qBASnB,sBAAsB;mBAChB;EAEL,YAAA,UAAS,oBAAoB;UAI3B;UAUN;UAQA;UAIA;UAIA;EAQK,IAAI,YACf,cAAc,cACd,aACA,UAAU,eACT,QAAQ;EAOE,IAAI,YACf,cAAc,cACd,aACA,OAAO,YACP,uCACA,UAAU,eACT;EAYU,OAAO,cAAc,cAAc,aAAa,UAAU,eAAe;;;;;;EAWzE,QAAQ,cAAc,eAAY;EAuBlC,cAAU"}
|
package/build/RedisCache.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CacheModuleConfig } from "@credo-ts/core";
|
|
2
2
|
import Redis from "ioredis";
|
|
3
|
-
|
|
4
3
|
//#region src/RedisCache.ts
|
|
5
4
|
/**
|
|
6
5
|
* Redis Cache implementation of the {@link Cache} interface.
|
|
@@ -75,7 +74,7 @@ var RedisCache = class {
|
|
|
75
74
|
await this._client.quit();
|
|
76
75
|
}
|
|
77
76
|
};
|
|
78
|
-
|
|
79
77
|
//#endregion
|
|
80
78
|
export { RedisCache };
|
|
79
|
+
|
|
81
80
|
//# sourceMappingURL=RedisCache.mjs.map
|
package/build/RedisCache.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RedisCache.mjs","names":[],"sources":["../src/RedisCache.ts"],"sourcesContent":["import { AgentContext, type Cache, CacheModuleConfig, type CacheOptions } from '@credo-ts/core'\nimport Redis, { type RedisOptions } from 'ioredis'\n\nexport type RedisCacheOptions = RedisOptions\n\n/**\n * Redis Cache implementation of the {@link Cache} interface.\n *\n * Keys are namespaced by the `contextCorrelationId` of the agent context by default, and by\n * `global:` for entries using the `'global'` scope, making the cache safe to use across multiple\n * agent context instances. This means `global` is effectively a reserved context correlation id.\n */\nexport class RedisCache implements Cache {\n private readonly _client: Redis\n\n constructor(options: RedisCacheOptions | Redis = {}) {\n this._client = options instanceof Redis ? options : new Redis(options)\n }\n\n private async client() {\n try {\n await this._client.ping()\n return this._client\n } catch {\n await this._client.connect()\n return this._client\n }\n }\n\n private getNamespacedKey(agentContext: AgentContext, key: string, options?: CacheOptions): string {\n if (options?.scope === 'global') {\n return `global:${key}`\n }\n\n return `${agentContext.contextCorrelationId}:${key}`\n }\n\n private serialize<CacheValue>(value: CacheValue): string {\n return JSON.stringify(value)\n }\n\n private deserialize<CacheValue>(value: string | null): CacheValue | null {\n return value === null ? value : (JSON.parse(value) as CacheValue)\n }\n\n private getDefaultExpiryInSeconds(agentContext: AgentContext) {\n try {\n return agentContext.resolve(CacheModuleConfig).defaultExpiryInSeconds\n } catch {\n return undefined\n }\n }\n\n public async get<CacheValue>(\n agentContext: AgentContext,\n key: string,\n options?: CacheOptions\n ): Promise<CacheValue | null> {\n const client = await this.client()\n const namespacedKey = this.getNamespacedKey(agentContext, key, options)\n const value = await client.get(namespacedKey)\n return this.deserialize<CacheValue>(value)\n }\n\n public async set<CacheValue>(\n agentContext: AgentContext,\n key: string,\n value: CacheValue,\n expiresInSeconds: number | undefined = this.getDefaultExpiryInSeconds(agentContext),\n options?: CacheOptions\n ): Promise<void> {\n const client = await this.client()\n const namespacedKey = this.getNamespacedKey(agentContext, key, options)\n const serializedValue = this.serialize(value)\n\n if (expiresInSeconds) {\n await client.set(namespacedKey, serializedValue, 'EX', expiresInSeconds)\n } else {\n await client.set(namespacedKey, serializedValue)\n }\n }\n\n public async remove(agentContext: AgentContext, key: string, options?: CacheOptions): Promise<void> {\n const client = await this.client()\n const namespacedKey = this.getNamespacedKey(agentContext, key, options)\n await client.del(namespacedKey)\n }\n\n /**\n * Removes all entries scoped to the context of the provided agent context. Entries in the\n * global scope are never removed by this method and are only reclaimed through their TTL or\n * an explicit `remove`.\n */\n public async destroy(agentContext: AgentContext) {\n const client = await this.client()\n let cursor = '0'\n\n do {\n const [nextCursor, keys] = await client.scan(\n cursor,\n 'MATCH',\n `${agentContext.contextCorrelationId}:*`,\n 'COUNT',\n '100' // limit\n )\n\n cursor = nextCursor\n\n if (keys.length > 0) {\n await client.del(...keys)\n }\n } while (cursor !== '0')\n }\n\n // TODO: we should have a method to close the cache, so we can hook into the\n // shutdown method.\n public async disconnect() {\n await this._client.quit()\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"RedisCache.mjs","names":[],"sources":["../src/RedisCache.ts"],"sourcesContent":["import { AgentContext, type Cache, CacheModuleConfig, type CacheOptions } from '@credo-ts/core'\nimport Redis, { type RedisOptions } from 'ioredis'\n\nexport type RedisCacheOptions = RedisOptions\n\n/**\n * Redis Cache implementation of the {@link Cache} interface.\n *\n * Keys are namespaced by the `contextCorrelationId` of the agent context by default, and by\n * `global:` for entries using the `'global'` scope, making the cache safe to use across multiple\n * agent context instances. This means `global` is effectively a reserved context correlation id.\n */\nexport class RedisCache implements Cache {\n private readonly _client: Redis\n\n constructor(options: RedisCacheOptions | Redis = {}) {\n this._client = options instanceof Redis ? options : new Redis(options)\n }\n\n private async client() {\n try {\n await this._client.ping()\n return this._client\n } catch {\n await this._client.connect()\n return this._client\n }\n }\n\n private getNamespacedKey(agentContext: AgentContext, key: string, options?: CacheOptions): string {\n if (options?.scope === 'global') {\n return `global:${key}`\n }\n\n return `${agentContext.contextCorrelationId}:${key}`\n }\n\n private serialize<CacheValue>(value: CacheValue): string {\n return JSON.stringify(value)\n }\n\n private deserialize<CacheValue>(value: string | null): CacheValue | null {\n return value === null ? value : (JSON.parse(value) as CacheValue)\n }\n\n private getDefaultExpiryInSeconds(agentContext: AgentContext) {\n try {\n return agentContext.resolve(CacheModuleConfig).defaultExpiryInSeconds\n } catch {\n return undefined\n }\n }\n\n public async get<CacheValue>(\n agentContext: AgentContext,\n key: string,\n options?: CacheOptions\n ): Promise<CacheValue | null> {\n const client = await this.client()\n const namespacedKey = this.getNamespacedKey(agentContext, key, options)\n const value = await client.get(namespacedKey)\n return this.deserialize<CacheValue>(value)\n }\n\n public async set<CacheValue>(\n agentContext: AgentContext,\n key: string,\n value: CacheValue,\n expiresInSeconds: number | undefined = this.getDefaultExpiryInSeconds(agentContext),\n options?: CacheOptions\n ): Promise<void> {\n const client = await this.client()\n const namespacedKey = this.getNamespacedKey(agentContext, key, options)\n const serializedValue = this.serialize(value)\n\n if (expiresInSeconds) {\n await client.set(namespacedKey, serializedValue, 'EX', expiresInSeconds)\n } else {\n await client.set(namespacedKey, serializedValue)\n }\n }\n\n public async remove(agentContext: AgentContext, key: string, options?: CacheOptions): Promise<void> {\n const client = await this.client()\n const namespacedKey = this.getNamespacedKey(agentContext, key, options)\n await client.del(namespacedKey)\n }\n\n /**\n * Removes all entries scoped to the context of the provided agent context. Entries in the\n * global scope are never removed by this method and are only reclaimed through their TTL or\n * an explicit `remove`.\n */\n public async destroy(agentContext: AgentContext) {\n const client = await this.client()\n let cursor = '0'\n\n do {\n const [nextCursor, keys] = await client.scan(\n cursor,\n 'MATCH',\n `${agentContext.contextCorrelationId}:*`,\n 'COUNT',\n '100' // limit\n )\n\n cursor = nextCursor\n\n if (keys.length > 0) {\n await client.del(...keys)\n }\n } while (cursor !== '0')\n }\n\n // TODO: we should have a method to close the cache, so we can hook into the\n // shutdown method.\n public async disconnect() {\n await this._client.quit()\n }\n}\n"],"mappings":";;;;;;;;;;AAYA,IAAa,aAAb,MAAyC;CAGvC,YAAY,UAAqC,CAAC,GAAG;EACnD,KAAK,UAAU,mBAAmB,QAAQ,UAAU,IAAI,MAAM,OAAO;CACvE;CAEA,MAAc,SAAS;EACrB,IAAI;GACF,MAAM,KAAK,QAAQ,KAAK;GACxB,OAAO,KAAK;EACd,QAAQ;GACN,MAAM,KAAK,QAAQ,QAAQ;GAC3B,OAAO,KAAK;EACd;CACF;CAEA,iBAAyB,cAA4B,KAAa,SAAgC;EAChG,IAAI,SAAS,UAAU,UACrB,OAAO,UAAU;EAGnB,OAAO,GAAG,aAAa,qBAAqB,GAAG;CACjD;CAEA,UAA8B,OAA2B;EACvD,OAAO,KAAK,UAAU,KAAK;CAC7B;CAEA,YAAgC,OAAyC;EACvE,OAAO,UAAU,OAAO,QAAS,KAAK,MAAM,KAAK;CACnD;CAEA,0BAAkC,cAA4B;EAC5D,IAAI;GACF,OAAO,aAAa,QAAQ,iBAAiB,CAAC,CAAC;EACjD,QAAQ;GACN;EACF;CACF;CAEA,MAAa,IACX,cACA,KACA,SAC4B;EAC5B,MAAM,SAAS,MAAM,KAAK,OAAO;EACjC,MAAM,gBAAgB,KAAK,iBAAiB,cAAc,KAAK,OAAO;EACtE,MAAM,QAAQ,MAAM,OAAO,IAAI,aAAa;EAC5C,OAAO,KAAK,YAAwB,KAAK;CAC3C;CAEA,MAAa,IACX,cACA,KACA,OACA,mBAAuC,KAAK,0BAA0B,YAAY,GAClF,SACe;EACf,MAAM,SAAS,MAAM,KAAK,OAAO;EACjC,MAAM,gBAAgB,KAAK,iBAAiB,cAAc,KAAK,OAAO;EACtE,MAAM,kBAAkB,KAAK,UAAU,KAAK;EAE5C,IAAI,kBACF,MAAM,OAAO,IAAI,eAAe,iBAAiB,MAAM,gBAAgB;OAEvE,MAAM,OAAO,IAAI,eAAe,eAAe;CAEnD;CAEA,MAAa,OAAO,cAA4B,KAAa,SAAuC;EAClG,MAAM,SAAS,MAAM,KAAK,OAAO;EACjC,MAAM,gBAAgB,KAAK,iBAAiB,cAAc,KAAK,OAAO;EACtE,MAAM,OAAO,IAAI,aAAa;CAChC;;;;;;CAOA,MAAa,QAAQ,cAA4B;EAC/C,MAAM,SAAS,MAAM,KAAK,OAAO;EACjC,IAAI,SAAS;EAEb,GAAG;GACD,MAAM,CAAC,YAAY,QAAQ,MAAM,OAAO,KACtC,QACA,SACA,GAAG,aAAa,qBAAqB,KACrC,SACA,KACF;GAEA,SAAS;GAET,IAAI,KAAK,SAAS,GAChB,MAAM,OAAO,IAAI,GAAG,IAAI;EAE5B,SAAS,WAAW;CACtB;CAIA,MAAa,aAAa;EACxB,MAAM,KAAK,QAAQ,KAAK;CAC1B;AACF"}
|
package/build/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
".": "./build/index.mjs",
|
|
5
5
|
"./package.json": "./package.json"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.7.2
|
|
7
|
+
"version": "0.7.2",
|
|
8
8
|
"files": [
|
|
9
9
|
"build"
|
|
10
10
|
],
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"ioredis": "^5.10.1",
|
|
23
|
-
"@credo-ts/core": "0.7.2
|
|
23
|
+
"@credo-ts/core": "0.7.2"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"typescript": "~5.9.3"
|