@happyvertical/cache 0.74.8
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/AGENT.md +33 -0
- package/LICENSE +7 -0
- package/README.md +161 -0
- package/dist/chunks/file-DyC_7WDS.js +450 -0
- package/dist/chunks/file-DyC_7WDS.js.map +1 -0
- package/dist/chunks/memory-C6vfNZYg.js +274 -0
- package/dist/chunks/memory-C6vfNZYg.js.map +1 -0
- package/dist/chunks/redis-D-SNLXE_.js +365 -0
- package/dist/chunks/redis-D-SNLXE_.js.map +1 -0
- package/dist/chunks/s3-ByokNFv_.js +427 -0
- package/dist/chunks/s3-ByokNFv_.js.map +1 -0
- package/dist/cli/claude-context.d.ts +3 -0
- package/dist/cli/claude-context.d.ts.map +1 -0
- package/dist/cli/claude-context.js +21 -0
- package/dist/cli/claude-context.js.map +1 -0
- package/dist/index.d.ts +72 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +170 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/file.d.ts +74 -0
- package/dist/providers/file.d.ts.map +1 -0
- package/dist/providers/memory.d.ts +50 -0
- package/dist/providers/memory.d.ts.map +1 -0
- package/dist/providers/redis.d.ts +37 -0
- package/dist/providers/redis.d.ts.map +1 -0
- package/dist/providers/s3.d.ts +52 -0
- package/dist/providers/s3.d.ts.map +1 -0
- package/dist/shared/types.d.ts +281 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/utils.d.ts +63 -0
- package/dist/shared/utils.d.ts.map +1 -0
- package/metadata.json +35 -0
- package/package.json +72 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { loadEnvConfig } from "@happyvertical/utils";
|
|
2
|
+
class CacheError extends Error {
|
|
3
|
+
constructor(message, code, provider) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.code = code;
|
|
6
|
+
this.provider = provider;
|
|
7
|
+
this.name = "CacheError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
class CacheKeyError extends CacheError {
|
|
11
|
+
constructor(key, provider) {
|
|
12
|
+
super(`Invalid cache key: ${key}`, "INVALID_KEY", provider);
|
|
13
|
+
this.key = key;
|
|
14
|
+
this.name = "CacheKeyError";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
class CacheConnectionError extends CacheError {
|
|
18
|
+
constructor(message, provider) {
|
|
19
|
+
super(message, "CONNECTION_ERROR", provider);
|
|
20
|
+
this.name = "CacheConnectionError";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
class CacheSizeError extends CacheError {
|
|
24
|
+
constructor(message, provider) {
|
|
25
|
+
super(message, "SIZE_EXCEEDED", provider);
|
|
26
|
+
this.name = "CacheSizeError";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
class CacheSerializationError extends CacheError {
|
|
30
|
+
constructor(message, provider) {
|
|
31
|
+
super(message, "SERIALIZATION_ERROR", provider);
|
|
32
|
+
this.name = "CacheSerializationError";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function isValidKey(key) {
|
|
36
|
+
return typeof key === "string" && key.length > 0 && key.length <= 250;
|
|
37
|
+
}
|
|
38
|
+
function calculateSize(value) {
|
|
39
|
+
try {
|
|
40
|
+
const json = JSON.stringify(value);
|
|
41
|
+
return new Blob([json]).size;
|
|
42
|
+
} catch {
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function matchesPattern(pattern, str) {
|
|
47
|
+
const regexPattern = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
48
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
|
49
|
+
return regex.test(str);
|
|
50
|
+
}
|
|
51
|
+
function formatKey(namespace, key) {
|
|
52
|
+
return namespace ? `${namespace}:${key}` : key;
|
|
53
|
+
}
|
|
54
|
+
function extractKey(namespace, fullKey) {
|
|
55
|
+
if (!namespace) {
|
|
56
|
+
return fullKey;
|
|
57
|
+
}
|
|
58
|
+
const prefix = `${namespace}:`;
|
|
59
|
+
return fullKey.startsWith(prefix) ? fullKey.slice(prefix.length) : fullKey;
|
|
60
|
+
}
|
|
61
|
+
function isExpired(expiresAt) {
|
|
62
|
+
if (expiresAt === void 0) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
return Date.now() >= expiresAt;
|
|
66
|
+
}
|
|
67
|
+
function calculateExpiration(ttl) {
|
|
68
|
+
if (ttl === void 0 || ttl <= 0) {
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
return Date.now() + ttl * 1e3;
|
|
72
|
+
}
|
|
73
|
+
function serialize(value) {
|
|
74
|
+
try {
|
|
75
|
+
return JSON.stringify(value);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
`Failed to serialize value: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function deserialize(json) {
|
|
83
|
+
try {
|
|
84
|
+
return JSON.parse(json);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
throw new Error(
|
|
87
|
+
`Failed to deserialize value: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function isMemoryOptions(options) {
|
|
92
|
+
return options.provider === "memory";
|
|
93
|
+
}
|
|
94
|
+
function isFileOptions(options) {
|
|
95
|
+
return options.provider === "file";
|
|
96
|
+
}
|
|
97
|
+
function isRedisOptions(options) {
|
|
98
|
+
return options.provider === "redis";
|
|
99
|
+
}
|
|
100
|
+
function isS3Options(options) {
|
|
101
|
+
return options.provider === "s3";
|
|
102
|
+
}
|
|
103
|
+
async function getCache(options) {
|
|
104
|
+
const config = loadEnvConfig(options, {
|
|
105
|
+
packageName: "cache",
|
|
106
|
+
schema: {
|
|
107
|
+
provider: "string",
|
|
108
|
+
namespace: "string",
|
|
109
|
+
defaultTTL: "number",
|
|
110
|
+
maxSize: "number",
|
|
111
|
+
maxEntries: "number",
|
|
112
|
+
evictionPolicy: "string",
|
|
113
|
+
checkPeriod: "number",
|
|
114
|
+
cacheDir: "string",
|
|
115
|
+
compression: "boolean",
|
|
116
|
+
fileExtension: "string",
|
|
117
|
+
host: "string",
|
|
118
|
+
port: "number",
|
|
119
|
+
password: "string",
|
|
120
|
+
db: "number",
|
|
121
|
+
keyPrefix: "string",
|
|
122
|
+
enableCompression: "boolean",
|
|
123
|
+
compressionThreshold: "number",
|
|
124
|
+
connectTimeout: "number",
|
|
125
|
+
commandTimeout: "number",
|
|
126
|
+
// S3 options
|
|
127
|
+
bucket: "string",
|
|
128
|
+
prefix: "string",
|
|
129
|
+
region: "string"
|
|
130
|
+
},
|
|
131
|
+
allowUnknown: false
|
|
132
|
+
});
|
|
133
|
+
if (isMemoryOptions(config)) {
|
|
134
|
+
const { MemoryProvider } = await import("./chunks/memory-C6vfNZYg.js");
|
|
135
|
+
return new MemoryProvider(config);
|
|
136
|
+
}
|
|
137
|
+
if (isFileOptions(config)) {
|
|
138
|
+
const { FileProvider } = await import("./chunks/file-DyC_7WDS.js");
|
|
139
|
+
return new FileProvider(config);
|
|
140
|
+
}
|
|
141
|
+
if (isRedisOptions(config)) {
|
|
142
|
+
const { RedisProvider } = await import("./chunks/redis-D-SNLXE_.js");
|
|
143
|
+
return new RedisProvider(config);
|
|
144
|
+
}
|
|
145
|
+
if (isS3Options(config)) {
|
|
146
|
+
const { S3Provider } = await import("./chunks/s3-ByokNFv_.js");
|
|
147
|
+
return new S3Provider(config);
|
|
148
|
+
}
|
|
149
|
+
throw new Error(`Unsupported provider: ${config.provider}`);
|
|
150
|
+
}
|
|
151
|
+
const PACKAGE_VERSION_INITIALIZED = true;
|
|
152
|
+
export {
|
|
153
|
+
CacheConnectionError,
|
|
154
|
+
CacheError,
|
|
155
|
+
CacheKeyError,
|
|
156
|
+
CacheSerializationError,
|
|
157
|
+
CacheSizeError,
|
|
158
|
+
PACKAGE_VERSION_INITIALIZED,
|
|
159
|
+
calculateExpiration,
|
|
160
|
+
calculateSize,
|
|
161
|
+
deserialize,
|
|
162
|
+
extractKey,
|
|
163
|
+
formatKey,
|
|
164
|
+
getCache,
|
|
165
|
+
isExpired,
|
|
166
|
+
isValidKey,
|
|
167
|
+
matchesPattern,
|
|
168
|
+
serialize
|
|
169
|
+
};
|
|
170
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/shared/types.ts","../src/shared/utils.ts","../src/index.ts"],"sourcesContent":["/**\n * Core types and interfaces for the Cache library\n */\n\n/**\n * Standardized cache entry structure (internal use)\n */\nexport interface CacheEntry<T = any> {\n /**\n * The cached value\n */\n value: T;\n\n /**\n * When this entry was created (Unix timestamp in milliseconds)\n */\n createdAt: number;\n\n /**\n * When this entry will expire (Unix timestamp in milliseconds)\n * undefined means no expiration\n */\n expiresAt?: number;\n\n /**\n * Size in bytes (for memory/disk management)\n */\n size: number;\n\n /**\n * Number of times this entry has been accessed\n */\n hits: number;\n\n /**\n * Additional metadata\n */\n metadata?: {\n compressed?: boolean;\n serialized?: boolean;\n namespace?: string;\n };\n}\n\n/**\n * Cache statistics\n */\nexport interface CacheStats {\n /**\n * Total number of cached entries\n */\n entries: number;\n\n /**\n * Total size in bytes\n */\n totalSize: number;\n\n /**\n * Cache hit count\n */\n hits: number;\n\n /**\n * Cache miss count\n */\n misses: number;\n\n /**\n * Hit rate (hits / (hits + misses))\n */\n hitRate: number;\n\n /**\n * Number of evictions (entries removed due to size/TTL)\n */\n evictions: number;\n\n /**\n * Backend-specific statistics\n */\n backend?: {\n type: 'memory' | 'file' | 'redis' | 's3';\n [key: string]: any;\n };\n}\n\n/**\n * Cache provider interface - all providers must implement this\n */\nexport interface CacheProvider {\n /**\n * Retrieves a value from the cache by key\n * @param key - The cache key\n * @returns Promise resolving to the cached value, or undefined if not found or expired\n */\n get<T = any>(key: string): Promise<T | undefined>;\n\n /**\n * Stores a value in the cache with an optional time-to-live\n * @param key - The cache key\n * @param value - The value to cache\n * @param ttl - Optional time-to-live in seconds\n * @returns Promise resolving when the value is cached\n */\n set<T = any>(key: string, value: T, ttl?: number): Promise<void>;\n\n /**\n * Checks if a key exists in the cache and is not expired\n * @param key - The cache key\n * @returns Promise resolving to true if the key exists and is valid\n */\n has(key: string): Promise<boolean>;\n\n /**\n * Removes a value from the cache\n * @param key - The cache key\n * @returns Promise resolving to true if the key was deleted, false if it didn't exist\n */\n delete(key: string): Promise<boolean>;\n\n /**\n * Clears all entries from the cache, or all entries in a namespace if specified\n * @param namespace - Optional namespace to clear\n * @returns Promise resolving when the cache is cleared\n */\n clear(namespace?: string): Promise<void>;\n\n /**\n * Gets all keys in the cache, optionally filtered by a pattern\n * @param pattern - Optional glob-style pattern to filter keys\n * @returns Promise resolving to an array of matching keys\n */\n keys(pattern?: string): Promise<string[]>;\n\n /**\n * Retrieves multiple values from the cache\n * @param keys - An array of cache keys\n * @returns Promise resolving to a map of key-value pairs\n */\n getMany<T = any>(keys: string[]): Promise<Map<string, T>>;\n\n /**\n * Stores multiple key-value pairs in the cache\n * @param entries - An array of {key, value, ttl?} objects\n * @returns Promise resolving when all values are cached\n */\n setMany<T = any>(\n entries: Array<{ key: string; value: T; ttl?: number }>,\n ): Promise<void>;\n\n /**\n * Removes multiple values from the cache\n * @param keys - An array of cache keys\n * @returns Promise resolving to the number of keys deleted\n */\n deleteMany(keys: string[]): Promise<number>;\n\n /**\n * Gets cache statistics\n * @returns Promise resolving to cache statistics\n */\n getStats(): Promise<CacheStats>;\n\n /**\n * Updates the TTL for an existing cache entry\n * @param key - The cache key\n * @param ttl - New time-to-live in seconds\n * @returns Promise resolving to true if TTL was updated, false if key doesn't exist\n */\n touch(key: string, ttl: number): Promise<boolean>;\n\n /**\n * Closes the cache connection/cleanup resources\n * @returns Promise resolving when cleanup is complete\n */\n close(): Promise<void>;\n}\n\n/**\n * Cache adapter interface (structurally identical to CacheProvider)\n */\nexport interface CacheAdapter extends CacheProvider {}\n\n/**\n * Memory cache options\n */\nexport interface MemoryOptions {\n provider: 'memory';\n namespace?: string;\n /** Default time-to-live in seconds for entries without an explicit TTL */\n defaultTTL?: number;\n /** Maximum total cache size in bytes (default: 100 MB) */\n maxSize?: number;\n /** Maximum number of entries (default: 10 000) */\n maxEntries?: number;\n evictionPolicy?: 'lru' | 'lfu' | 'fifo';\n /** Interval in milliseconds between expired-entry sweeps (default: 60 000) */\n checkPeriod?: number;\n}\n\n/**\n * File cache options\n */\nexport interface FileOptions {\n provider: 'file';\n /** Directory where cache files are stored (required) */\n cacheDir: string;\n namespace?: string;\n /** Default time-to-live in seconds for entries without an explicit TTL */\n defaultTTL?: number;\n /** Maximum total cache size in bytes (default: 500 MB) */\n maxSize?: number;\n /** Enable gzip compression for stored files (default: false) */\n compression?: boolean;\n /** File suffix for cache files (default: '.cache') */\n fileExtension?: string;\n /** Interval in milliseconds between expired-file cleanup sweeps (default: 300 000) */\n checkPeriod?: number;\n}\n\n/**\n * Redis cache options\n */\nexport interface RedisOptions {\n provider: 'redis';\n /** Redis server hostname (default: 'localhost') */\n host?: string;\n /** Redis server port (default: 6379) */\n port?: number;\n password?: string;\n /** Redis database index 0-15 (default: 0) */\n db?: number;\n namespace?: string;\n /** Alternative to namespace — used as the key prefix */\n keyPrefix?: string;\n /** Default time-to-live in seconds for entries without an explicit TTL */\n defaultTTL?: number;\n /** Enable gzip compression for values exceeding compressionThreshold (default: false) */\n enableCompression?: boolean;\n /** Minimum value size in bytes before compression applies (default: 1024) */\n compressionThreshold?: number;\n /** Socket connect timeout in milliseconds (default: 5000) */\n connectTimeout?: number;\n /** Per-command timeout in milliseconds */\n commandTimeout?: number;\n retryStrategy?: (times: number) => number | null;\n}\n\n/**\n * S3 cache options\n * Use this for CI environments where cache needs to persist between runs\n */\nexport interface S3Options {\n provider: 's3';\n /** S3 bucket name (required) */\n bucket: string;\n /** Key prefix for cache files (default: 'cache/') */\n prefix?: string;\n /** AWS region (default: from AWS_REGION env var or 'us-east-1') */\n region?: string;\n /** Optional namespace for key organization */\n namespace?: string;\n /** Default TTL in seconds */\n defaultTTL?: number;\n /** Enable gzip compression (default: true) */\n compression?: boolean;\n /** Only compress if value exceeds this size in bytes (default: 1024) */\n compressionThreshold?: number;\n}\n\n/**\n * Discriminated union of all cache adapter options\n */\nexport type CacheAdapterOptions =\n | MemoryOptions\n | FileOptions\n | RedisOptions\n | S3Options;\n\n/**\n * Base cache error class\n */\nexport class CacheError extends Error {\n constructor(\n message: string,\n public code: string,\n public provider: string,\n ) {\n super(message);\n this.name = 'CacheError';\n }\n}\n\n/**\n * Invalid cache key error\n */\nexport class CacheKeyError extends CacheError {\n constructor(\n public key: string,\n provider: string,\n ) {\n super(`Invalid cache key: ${key}`, 'INVALID_KEY', provider);\n this.name = 'CacheKeyError';\n }\n}\n\n/**\n * Cache connection error\n */\nexport class CacheConnectionError extends CacheError {\n constructor(message: string, provider: string) {\n super(message, 'CONNECTION_ERROR', provider);\n this.name = 'CacheConnectionError';\n }\n}\n\n/**\n * Cache size limit exceeded error\n */\nexport class CacheSizeError extends CacheError {\n constructor(message: string, provider: string) {\n super(message, 'SIZE_EXCEEDED', provider);\n this.name = 'CacheSizeError';\n }\n}\n\n/**\n * Cache serialization error\n */\nexport class CacheSerializationError extends CacheError {\n constructor(message: string, provider: string) {\n super(message, 'SERIALIZATION_ERROR', provider);\n this.name = 'CacheSerializationError';\n }\n}\n","/**\n * Utility functions for cache operations\n */\n\n/**\n * Validates a cache key\n * @param key - The cache key to validate\n * @returns True if the key is valid\n */\nexport function isValidKey(key: string): boolean {\n return typeof key === 'string' && key.length > 0 && key.length <= 250;\n}\n\n/**\n * Calculates the size of a value in bytes (approximate)\n * @param value - The value to measure\n * @returns Size in bytes\n */\nexport function calculateSize(value: any): number {\n try {\n const json = JSON.stringify(value);\n return new Blob([json]).size;\n } catch {\n // Fallback to rough estimate if stringify fails\n return 0;\n }\n}\n\n/**\n * Checks if a pattern matches a string (glob-style)\n * @param pattern - The glob pattern (supports * wildcard)\n * @param str - The string to test\n * @returns True if the pattern matches\n */\nexport function matchesPattern(pattern: string, str: string): boolean {\n // Convert glob pattern to regex\n const regexPattern = pattern\n .replace(/[.+^${}()|[\\]\\\\]/g, '\\\\$&') // Escape regex special chars\n .replace(/\\*/g, '.*') // Convert * to .*\n .replace(/\\?/g, '.'); // Convert ? to .\n\n const regex = new RegExp(`^${regexPattern}$`);\n return regex.test(str);\n}\n\n/**\n * Formats a namespace and key into a full key\n * @param namespace - Optional namespace\n * @param key - The cache key\n * @returns Formatted key with namespace prefix if provided\n */\nexport function formatKey(namespace: string | undefined, key: string): string {\n return namespace ? `${namespace}:${key}` : key;\n}\n\n/**\n * Extracts the original key from a namespaced key\n * @param namespace - Optional namespace\n * @param fullKey - The full key with namespace\n * @returns Original key without namespace\n */\nexport function extractKey(\n namespace: string | undefined,\n fullKey: string,\n): string {\n if (!namespace) {\n return fullKey;\n }\n const prefix = `${namespace}:`;\n return fullKey.startsWith(prefix) ? fullKey.slice(prefix.length) : fullKey;\n}\n\n/**\n * Checks if an entry has expired\n * @param expiresAt - Expiration timestamp (undefined means no expiration)\n * @returns True if the entry has expired\n */\nexport function isExpired(expiresAt: number | undefined): boolean {\n if (expiresAt === undefined) {\n return false;\n }\n return Date.now() >= expiresAt;\n}\n\n/**\n * Calculates expiration timestamp from TTL\n * @param ttl - Time-to-live in seconds (undefined means no expiration)\n * @returns Expiration timestamp in milliseconds, or undefined\n */\nexport function calculateExpiration(\n ttl: number | undefined,\n): number | undefined {\n if (ttl === undefined || ttl <= 0) {\n return undefined;\n }\n return Date.now() + ttl * 1000;\n}\n\n/**\n * Serializes a value to JSON string\n * @param value - The value to serialize\n * @returns JSON string\n * @throws Error if serialization fails\n */\nexport function serialize(value: any): string {\n try {\n return JSON.stringify(value);\n } catch (error) {\n throw new Error(\n `Failed to serialize value: ${error instanceof Error ? error.message : 'Unknown error'}`,\n );\n }\n}\n\n/**\n * Deserializes a JSON string to a value\n * @param json - The JSON string\n * @returns Deserialized value\n * @throws Error if deserialization fails\n */\nexport function deserialize<T = any>(json: string): T {\n try {\n return JSON.parse(json);\n } catch (error) {\n throw new Error(\n `Failed to deserialize value: ${error instanceof Error ? error.message : 'Unknown error'}`,\n );\n }\n}\n","/**\n * Cache package entry point\n * Provides standardized caching interface\n */\n\nimport { loadEnvConfig } from '@happyvertical/utils';\nimport type {\n CacheAdapter,\n CacheAdapterOptions,\n FileOptions,\n MemoryOptions,\n RedisOptions,\n S3Options,\n} from './shared/types';\n\n// Export all types\nexport * from './shared/types';\nexport * from './shared/utils';\n\n/**\n * Type guard for Memory cache options\n */\nfunction isMemoryOptions(\n options: CacheAdapterOptions,\n): options is MemoryOptions {\n return options.provider === 'memory';\n}\n\n/**\n * Type guard for File cache options\n */\nfunction isFileOptions(options: CacheAdapterOptions): options is FileOptions {\n return options.provider === 'file';\n}\n\n/**\n * Type guard for Redis cache options\n */\nfunction isRedisOptions(options: CacheAdapterOptions): options is RedisOptions {\n return options.provider === 'redis';\n}\n\n/**\n * Type guard for S3 cache options\n */\nfunction isS3Options(options: CacheAdapterOptions): options is S3Options {\n return options.provider === 's3';\n}\n\n/**\n * Factory function to create a cache adapter instance\n *\n * Supports environment variable configuration using the HAVE_CACHE_* pattern:\n * - HAVE_CACHE_PROVIDER → provider ('memory'|'file'|'redis'|'s3')\n * - HAVE_CACHE_NAMESPACE → namespace (string)\n * - HAVE_CACHE_DEFAULT_TTL → defaultTTL (number: seconds)\n * - HAVE_CACHE_MAX_SIZE → maxSize (number: bytes)\n * - HAVE_CACHE_MAX_ENTRIES → maxEntries (number, memory only)\n * - HAVE_CACHE_EVICTION_POLICY → evictionPolicy ('lru'|'lfu'|'fifo', memory only)\n * - HAVE_CACHE_CACHE_DIR → cacheDir (string, file only)\n * - HAVE_CACHE_COMPRESSION → compression (boolean, file/s3)\n * - HAVE_CACHE_HOST → host (string, redis only)\n * - HAVE_CACHE_PORT → port (number, redis only)\n * - HAVE_CACHE_BUCKET → bucket (string, s3 only)\n * - HAVE_CACHE_PREFIX → prefix (string, s3 only)\n * - HAVE_CACHE_REGION → region (string, s3 only)\n *\n * User-provided options always take precedence over environment variables.\n *\n * @param options - Configuration options for the cache provider\n * @returns Promise resolving to a cache adapter that implements CacheAdapter\n *\n * @example\n * ```typescript\n * // Create memory cache with explicit options\n * const memoryCache = await getCache({\n * provider: 'memory',\n * maxSize: 100 * 1024 * 1024,\n * evictionPolicy: 'lru'\n * });\n *\n * // Create memory cache with environment variables\n * // HAVE_CACHE_PROVIDER=memory\n * // HAVE_CACHE_MAX_SIZE=104857600\n * // HAVE_CACHE_EVICTION_POLICY=lru\n * const envCache = await getCache({ provider: 'memory' });\n *\n * // Create file cache\n * const fileCache = await getCache({\n * provider: 'file',\n * cacheDir: './cache',\n * compression: true\n * });\n *\n * // Create Redis cache\n * const redisCache = await getCache({\n * provider: 'redis',\n * host: 'localhost',\n * port: 6379\n * });\n *\n * // Create S3 cache (for CI persistence)\n * const s3Cache = await getCache({\n * provider: 's3',\n * bucket: 'my-cache-bucket',\n * prefix: 'cache/',\n * region: 'us-east-1'\n * });\n *\n * // Use the cache\n * await memoryCache.set('user:123', { name: 'John' });\n * const user = await memoryCache.get('user:123');\n * ```\n */\nexport async function getCache(\n options: CacheAdapterOptions,\n): Promise<CacheAdapter> {\n // Load configuration from environment variables, merging with user options\n // User options always take precedence\n // Use 'any' to work around TypeScript's discriminated union type checking\n const config = loadEnvConfig(options as any, {\n packageName: 'cache',\n schema: {\n provider: 'string',\n namespace: 'string',\n defaultTTL: 'number',\n maxSize: 'number',\n maxEntries: 'number',\n evictionPolicy: 'string',\n checkPeriod: 'number',\n cacheDir: 'string',\n compression: 'boolean',\n fileExtension: 'string',\n host: 'string',\n port: 'number',\n password: 'string',\n db: 'number',\n keyPrefix: 'string',\n enableCompression: 'boolean',\n compressionThreshold: 'number',\n connectTimeout: 'number',\n commandTimeout: 'number',\n // S3 options\n bucket: 'string',\n prefix: 'string',\n region: 'string',\n } as any,\n allowUnknown: false,\n }) as CacheAdapterOptions;\n\n if (isMemoryOptions(config)) {\n const { MemoryProvider } = await import('./providers/memory.js');\n return new MemoryProvider(config);\n }\n\n if (isFileOptions(config)) {\n const { FileProvider } = await import('./providers/file.js');\n return new FileProvider(config);\n }\n\n if (isRedisOptions(config)) {\n const { RedisProvider } = await import('./providers/redis.js');\n return new RedisProvider(config);\n }\n\n if (isS3Options(config)) {\n const { S3Provider } = await import('./providers/s3.js');\n return new S3Provider(config);\n }\n\n // This should never happen due to TypeScript's discriminated union\n throw new Error(`Unsupported provider: ${(config as any).provider}`);\n}\n\n/** @internal */\nexport const PACKAGE_VERSION_INITIALIZED = true;\n"],"names":[],"mappings":";AA2RO,MAAM,mBAAmB,MAAM;AAAA,EACpC,YACE,SACO,MACA,UACP;AACA,UAAM,OAAO;AAHN,SAAA,OAAA;AACA,SAAA,WAAA;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAKO,MAAM,sBAAsB,WAAW;AAAA,EAC5C,YACS,KACP,UACA;AACA,UAAM,sBAAsB,GAAG,IAAI,eAAe,QAAQ;AAHnD,SAAA,MAAA;AAIP,SAAK,OAAO;AAAA,EACd;AACF;AAKO,MAAM,6BAA6B,WAAW;AAAA,EACnD,YAAY,SAAiB,UAAkB;AAC7C,UAAM,SAAS,oBAAoB,QAAQ;AAC3C,SAAK,OAAO;AAAA,EACd;AACF;AAKO,MAAM,uBAAuB,WAAW;AAAA,EAC7C,YAAY,SAAiB,UAAkB;AAC7C,UAAM,SAAS,iBAAiB,QAAQ;AACxC,SAAK,OAAO;AAAA,EACd;AACF;AAKO,MAAM,gCAAgC,WAAW;AAAA,EACtD,YAAY,SAAiB,UAAkB;AAC7C,UAAM,SAAS,uBAAuB,QAAQ;AAC9C,SAAK,OAAO;AAAA,EACd;AACF;ACtUO,SAAS,WAAW,KAAsB;AAC/C,SAAO,OAAO,QAAQ,Y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A,MAAI,YAAY,MAAM,GAAG;AACvB,UAAM,EAAE,WAAA,IAAe,MAAM,OAAO,yBAAmB;AACvD,WAAO,IAAI,WAAW,MAAM;AAAA,EAC9B;AAGA,QAAM,IAAI,MAAM,yBAA0B,OAAe,QAAQ,EAAE;AACrE;AAGO,MAAM,8BAA8B;"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { CacheProvider, CacheStats, FileOptions } from '../shared/types';
|
|
2
|
+
/**
|
|
3
|
+
* File cache provider implementation
|
|
4
|
+
* Stores cache entries as files with optional compression
|
|
5
|
+
*/
|
|
6
|
+
export declare class FileProvider implements CacheProvider {
|
|
7
|
+
private cacheDir;
|
|
8
|
+
private namespace?;
|
|
9
|
+
private defaultTTL?;
|
|
10
|
+
private maxSize;
|
|
11
|
+
private compression;
|
|
12
|
+
private fileExtension;
|
|
13
|
+
private checkPeriod;
|
|
14
|
+
private checkInterval?;
|
|
15
|
+
private stats;
|
|
16
|
+
constructor(options: FileOptions);
|
|
17
|
+
get<T = any>(key: string): Promise<T | undefined>;
|
|
18
|
+
set<T = any>(key: string, value: T, ttl?: number): Promise<void>;
|
|
19
|
+
has(key: string): Promise<boolean>;
|
|
20
|
+
delete(key: string): Promise<boolean>;
|
|
21
|
+
clear(namespace?: string): Promise<void>;
|
|
22
|
+
keys(pattern?: string): Promise<string[]>;
|
|
23
|
+
getMany<T = any>(keys: string[]): Promise<Map<string, T>>;
|
|
24
|
+
setMany<T = any>(entries: Array<{
|
|
25
|
+
key: string;
|
|
26
|
+
value: T;
|
|
27
|
+
ttl?: number;
|
|
28
|
+
}>): Promise<void>;
|
|
29
|
+
deleteMany(keys: string[]): Promise<number>;
|
|
30
|
+
getStats(): Promise<CacheStats>;
|
|
31
|
+
touch(key: string, ttl: number): Promise<boolean>;
|
|
32
|
+
close(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Ensures cache directory exists
|
|
35
|
+
*/
|
|
36
|
+
private ensureCacheDir;
|
|
37
|
+
/**
|
|
38
|
+
* Gets the file path for a cache key
|
|
39
|
+
*/
|
|
40
|
+
private getFilePath;
|
|
41
|
+
/**
|
|
42
|
+
* Sanitizes a key for use as a filename
|
|
43
|
+
*/
|
|
44
|
+
private sanitizeKey;
|
|
45
|
+
/**
|
|
46
|
+
* Desanitizes a filename back to the original key
|
|
47
|
+
*/
|
|
48
|
+
private desanitizeKey;
|
|
49
|
+
/**
|
|
50
|
+
* Gets all cache file names
|
|
51
|
+
*/
|
|
52
|
+
private getAllFiles;
|
|
53
|
+
/**
|
|
54
|
+
* Writes an entry to a file
|
|
55
|
+
*/
|
|
56
|
+
private writeEntry;
|
|
57
|
+
/**
|
|
58
|
+
* Evicts files if size limit is exceeded
|
|
59
|
+
*/
|
|
60
|
+
private evictIfNeeded;
|
|
61
|
+
/**
|
|
62
|
+
* Evicts oldest files based on creation time
|
|
63
|
+
*/
|
|
64
|
+
private evict;
|
|
65
|
+
/**
|
|
66
|
+
* Starts background cleanup of expired files
|
|
67
|
+
*/
|
|
68
|
+
private startCleanup;
|
|
69
|
+
/**
|
|
70
|
+
* Removes expired files
|
|
71
|
+
*/
|
|
72
|
+
private removeExpiredFiles;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/providers/file.ts"],"names":[],"mappings":"AAAA;;GAEG;AAaH,OAAO,KAAK,EAEV,aAAa,EACb,UAAU,EACV,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAsBzB;;;GAGG;AACH,qBAAa,YAAa,YAAW,aAAa;IAChD,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,UAAU,CAAC,CAAS;IAC5B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAU;IAC7B,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,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AC;IAQ5B;;OAEG;YACW,cAAc;IAY5B;;OAEG;IACH,OAAO,CAAC,WAAW;IAKnB;;OAEG;IACH,OAAO,CAAC,WAAW;IAInB;;OAEG;IACH,OAAO,CAAC,aAAa;IAMrB;;OAEG;YACW,WAAW;IAgBzB;;OAEG;YACW,UAAU;IAoBxB;;OAEG;YACW,aAAa;IAkB3B;;OAEG;YACW,KAAK;IAiCnB;;OAEG;IACH,OAAO,CAAC,YAAY;IAWpB;;OAEG;YACW,kBAAkB;CAuBjC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { CacheProvider, CacheStats, MemoryOptions } from '../shared/types';
|
|
2
|
+
/**
|
|
3
|
+
* Memory cache provider implementation
|
|
4
|
+
* Stores cache entries in memory with LRU eviction
|
|
5
|
+
*/
|
|
6
|
+
export declare class MemoryProvider implements CacheProvider {
|
|
7
|
+
private cache;
|
|
8
|
+
private namespace?;
|
|
9
|
+
private defaultTTL?;
|
|
10
|
+
private maxSize;
|
|
11
|
+
private maxEntries;
|
|
12
|
+
private evictionPolicy;
|
|
13
|
+
private checkPeriod;
|
|
14
|
+
private checkInterval?;
|
|
15
|
+
private stats;
|
|
16
|
+
constructor(options: MemoryOptions);
|
|
17
|
+
get<T = any>(key: string): Promise<T | undefined>;
|
|
18
|
+
set<T = any>(key: string, value: T, ttl?: number): Promise<void>;
|
|
19
|
+
has(key: string): Promise<boolean>;
|
|
20
|
+
delete(key: string): Promise<boolean>;
|
|
21
|
+
clear(namespace?: string): Promise<void>;
|
|
22
|
+
keys(pattern?: string): Promise<string[]>;
|
|
23
|
+
getMany<T = any>(keys: string[]): Promise<Map<string, T>>;
|
|
24
|
+
setMany<T = any>(entries: Array<{
|
|
25
|
+
key: string;
|
|
26
|
+
value: T;
|
|
27
|
+
ttl?: number;
|
|
28
|
+
}>): Promise<void>;
|
|
29
|
+
deleteMany(keys: string[]): Promise<number>;
|
|
30
|
+
getStats(): Promise<CacheStats>;
|
|
31
|
+
touch(key: string, ttl: number): Promise<boolean>;
|
|
32
|
+
close(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Evicts entries if size or count limits are exceeded
|
|
35
|
+
*/
|
|
36
|
+
private evictIfNeeded;
|
|
37
|
+
/**
|
|
38
|
+
* Evicts entries based on eviction policy
|
|
39
|
+
*/
|
|
40
|
+
private evict;
|
|
41
|
+
/**
|
|
42
|
+
* Starts background task to remove expired entries
|
|
43
|
+
*/
|
|
44
|
+
private startExpirationCheck;
|
|
45
|
+
/**
|
|
46
|
+
* Removes all expired entries from the cache
|
|
47
|
+
*/
|
|
48
|
+
private removeExpiredEntries;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/providers/memory.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAEV,aAAa,EACb,UAAU,EACV,aAAa,EACd,MAAM,iBAAiB,CAAC;AAYzB;;;GAGG;AACH,qBAAa,cAAe,YAAW,aAAa;IAClD,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,UAAU,CAAC,CAAS;IAC5B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,cAAc,CAAyB;IAC/C,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,aAAa,CAAC,CAAiB;IACvC,OAAO,CAAC,KAAK,CAIX;gBAEU,OAAO,EAAE,aAAa;IAkB5B,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAiCjD,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BhE,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAqBlC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IASrC,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBxC,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAoBzC,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAazD,OAAO,CAAC,CAAC,GAAG,GAAG,EACnB,OAAO,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,CAAC,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GACtD,OAAO,CAAC,IAAI,CAAC;IAMV,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAa3C,QAAQ,IAAI,OAAO,CAAC,UAAU,CAAC;IA+B/B,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAgBjD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAW5B;;OAEG;YACW,aAAa;IA8B3B;;OAEG;YACW,KAAK;IAuCnB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAW5B;;OAEG;IACH,OAAO,CAAC,oBAAoB;CAS7B"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { CacheProvider, CacheStats, RedisOptions } from '../shared/types';
|
|
2
|
+
/**
|
|
3
|
+
* Redis cache provider implementation
|
|
4
|
+
* Uses official redis client with optional compression
|
|
5
|
+
*/
|
|
6
|
+
export declare class RedisProvider implements CacheProvider {
|
|
7
|
+
private options;
|
|
8
|
+
private client;
|
|
9
|
+
private namespace?;
|
|
10
|
+
private defaultTTL?;
|
|
11
|
+
private enableCompression;
|
|
12
|
+
private compressionThreshold;
|
|
13
|
+
private stats;
|
|
14
|
+
private connected;
|
|
15
|
+
constructor(options: RedisOptions);
|
|
16
|
+
/**
|
|
17
|
+
* Ensures the client is connected
|
|
18
|
+
*/
|
|
19
|
+
private ensureConnected;
|
|
20
|
+
get<T = any>(key: string): Promise<T | undefined>;
|
|
21
|
+
set<T = any>(key: string, value: T, ttl?: number): Promise<void>;
|
|
22
|
+
has(key: string): Promise<boolean>;
|
|
23
|
+
delete(key: string): Promise<boolean>;
|
|
24
|
+
clear(namespace?: string): Promise<void>;
|
|
25
|
+
keys(pattern?: string): Promise<string[]>;
|
|
26
|
+
getMany<T = any>(keys: string[]): Promise<Map<string, T>>;
|
|
27
|
+
setMany<T = any>(entries: Array<{
|
|
28
|
+
key: string;
|
|
29
|
+
value: T;
|
|
30
|
+
ttl?: number;
|
|
31
|
+
}>): Promise<void>;
|
|
32
|
+
deleteMany(keys: string[]): Promise<number>;
|
|
33
|
+
getStats(): Promise<CacheStats>;
|
|
34
|
+
touch(key: string, ttl: number): Promise<boolean>;
|
|
35
|
+
close(): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=redis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../src/providers/redis.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAY/E;;;GAGG;AACH,qBAAa,aAAc,YAAW,aAAa;IAYrC,OAAO,CAAC,OAAO;IAX3B,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,UAAU,CAAC,CAAS;IAC5B,OAAO,CA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,CAAC,OAAO,CAAC;IAqBjD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAY7B"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { CacheProvider, CacheStats, S3Options } from '../shared/types';
|
|
2
|
+
/**
|
|
3
|
+
* S3 cache provider implementation
|
|
4
|
+
* Stores cache entries as S3 objects with optional compression
|
|
5
|
+
*/
|
|
6
|
+
export declare class S3Provider implements CacheProvider {
|
|
7
|
+
private client;
|
|
8
|
+
private bucket;
|
|
9
|
+
private prefix;
|
|
10
|
+
private namespace?;
|
|
11
|
+
private defaultTTL?;
|
|
12
|
+
private compression;
|
|
13
|
+
private compressionThreshold;
|
|
14
|
+
private region;
|
|
15
|
+
private initialized;
|
|
16
|
+
private stats;
|
|
17
|
+
constructor(options: S3Options);
|
|
18
|
+
/**
|
|
19
|
+
* Lazily initialize the S3 client
|
|
20
|
+
*/
|
|
21
|
+
private ensureInitialized;
|
|
22
|
+
get<T = any>(key: string): Promise<T | undefined>;
|
|
23
|
+
set<T = any>(key: string, value: T, ttl?: number): Promise<void>;
|
|
24
|
+
has(key: string): Promise<boolean>;
|
|
25
|
+
delete(key: string): Promise<boolean>;
|
|
26
|
+
clear(namespace?: string): Promise<void>;
|
|
27
|
+
keys(pattern?: string): Promise<string[]>;
|
|
28
|
+
getMany<T = any>(keys: string[]): Promise<Map<string, T>>;
|
|
29
|
+
setMany<T = any>(entries: Array<{
|
|
30
|
+
key: string;
|
|
31
|
+
value: T;
|
|
32
|
+
ttl?: number;
|
|
33
|
+
}>): Promise<void>;
|
|
34
|
+
deleteMany(keys: string[]): Promise<number>;
|
|
35
|
+
getStats(): Promise<CacheStats>;
|
|
36
|
+
touch(key: string, ttl: number): Promise<boolean>;
|
|
37
|
+
close(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Gets the S3 key for a cache key
|
|
40
|
+
*/
|
|
41
|
+
private getS3Key;
|
|
42
|
+
/**
|
|
43
|
+
* Sanitizes a key for use as an S3 key
|
|
44
|
+
* S3 keys can contain most characters, but we sanitize for consistency
|
|
45
|
+
*/
|
|
46
|
+
private sanitizeKey;
|
|
47
|
+
/**
|
|
48
|
+
* Desanitizes an S3 key back to the original format
|
|
49
|
+
*/
|
|
50
|
+
private desanitizeKey;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=s3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../src/providers/s3.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAEV,aAAa,EACb,UAAU,EACV,SAAS,EACV,MAAM,iBAAiB,CAAC;AAsDzB;;;GAGG;AACH,qBAAa,UAAW,YAAW,aAAa;IAC9C,OAAO,CAAC,MAAM,CAAM;IACpB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,UAAU,CAAC,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAU;IAC7B,OAAO,CAAC,oBAAoB,CAAS;IACrC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,KAAK,CAIX;gBAEU,OAAO,EAAE,SAAS;IAe9B;;OAEG;YACW,iBAAiB;IAsBzB,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IA0DjD,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA8DhE,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAuClC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAwB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