inray 0.0.2 → 0.0.3
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/LICENSE.md +1 -0
- package/README.md +132 -32
- package/dist/caching/mod.d.ts +2 -0
- package/dist/caching/mod.d.ts.map +1 -0
- package/dist/caching/mod.js +2 -0
- package/dist/caching/mod.js.map +1 -0
- package/dist/caching/src/cache.d.ts +89 -0
- package/dist/caching/src/cache.d.ts.map +1 -0
- package/dist/caching/src/cache.js +309 -0
- package/dist/caching/src/cache.js.map +1 -0
- package/dist/caching/src/hashing/cache.d.ts +92 -0
- package/dist/caching/src/hashing/cache.d.ts.map +1 -0
- package/dist/caching/src/hashing/cache.js +119 -0
- package/dist/caching/src/hashing/cache.js.map +1 -0
- package/dist/caching/src/hashing/hooks/eventified.d.ts +157 -0
- package/dist/caching/src/hashing/hooks/eventified.d.ts.map +1 -0
- package/dist/caching/src/hashing/hooks/eventified.js +333 -0
- package/dist/caching/src/hashing/hooks/eventified.js.map +1 -0
- package/dist/caching/src/hashing/hooks/index.d.ts +199 -0
- package/dist/caching/src/hashing/hooks/index.d.ts.map +1 -0
- package/dist/caching/src/hashing/hooks/index.js +383 -0
- package/dist/caching/src/hashing/hooks/index.js.map +1 -0
- package/dist/caching/src/hashing/hooks/types.d.ts +217 -0
- package/dist/caching/src/hashing/hooks/types.d.ts.map +1 -0
- package/dist/caching/src/hashing/hooks/types.js +10 -0
- package/dist/caching/src/hashing/hooks/types.js.map +1 -0
- package/dist/caching/src/hashing/index.d.ts +236 -0
- package/dist/caching/src/hashing/index.d.ts.map +1 -0
- package/dist/caching/src/hashing/index.js +447 -0
- package/dist/caching/src/hashing/index.js.map +1 -0
- package/dist/caching/src/hashing/providers/crc.d.ts +15 -0
- package/dist/caching/src/hashing/providers/crc.d.ts.map +1 -0
- package/dist/caching/src/hashing/providers/crc.js +49 -0
- package/dist/caching/src/hashing/providers/crc.js.map +1 -0
- package/dist/caching/src/hashing/providers/crypto.d.ts +19 -0
- package/dist/caching/src/hashing/providers/crypto.d.ts.map +1 -0
- package/dist/caching/src/hashing/providers/crypto.js +28 -0
- package/dist/caching/src/hashing/providers/crypto.js.map +1 -0
- package/dist/caching/src/hashing/providers/djb2.d.ts +60 -0
- package/dist/caching/src/hashing/providers/djb2.d.ts.map +1 -0
- package/dist/caching/src/hashing/providers/djb2.js +92 -0
- package/dist/caching/src/hashing/providers/djb2.js.map +1 -0
- package/dist/caching/src/hashing/providers/fnv1.d.ts +33 -0
- package/dist/caching/src/hashing/providers/fnv1.d.ts.map +1 -0
- package/dist/caching/src/hashing/providers/fnv1.js +68 -0
- package/dist/caching/src/hashing/providers/fnv1.js.map +1 -0
- package/dist/caching/src/hashing/providers/murmur.d.ts +81 -0
- package/dist/caching/src/hashing/providers/murmur.d.ts.map +1 -0
- package/dist/caching/src/hashing/providers/murmur.js +173 -0
- package/dist/caching/src/hashing/providers/murmur.js.map +1 -0
- package/dist/caching/src/hashing/providers.d.ts +126 -0
- package/dist/caching/src/hashing/providers.d.ts.map +1 -0
- package/dist/caching/src/hashing/providers.js +163 -0
- package/dist/caching/src/hashing/providers.js.map +1 -0
- package/dist/caching/src/hashing/types.d.ts +340 -0
- package/dist/caching/src/hashing/types.d.ts.map +1 -0
- package/dist/caching/src/hashing/types.js +10 -0
- package/dist/caching/src/hashing/types.js.map +1 -0
- package/dist/caching/src/keyValue/capabilities.d.ts +161 -0
- package/dist/caching/src/keyValue/capabilities.d.ts.map +1 -0
- package/dist/caching/src/keyValue/capabilities.js +334 -0
- package/dist/caching/src/keyValue/capabilities.js.map +1 -0
- package/dist/caching/src/keyValue/event-manager.d.ts +27 -0
- package/dist/caching/src/keyValue/event-manager.d.ts.map +1 -0
- package/dist/caching/src/keyValue/event-manager.js +88 -0
- package/dist/caching/src/keyValue/event-manager.js.map +1 -0
- package/dist/caching/src/keyValue/generic-store.d.ts +243 -0
- package/dist/caching/src/keyValue/generic-store.d.ts.map +1 -0
- package/dist/caching/src/keyValue/generic-store.js +295 -0
- package/dist/caching/src/keyValue/generic-store.js.map +1 -0
- package/dist/caching/src/keyValue/hooks-manager.d.ts +21 -0
- package/dist/caching/src/keyValue/hooks-manager.d.ts.map +1 -0
- package/dist/caching/src/keyValue/hooks-manager.js +59 -0
- package/dist/caching/src/keyValue/hooks-manager.js.map +1 -0
- package/dist/caching/src/keyValue/index.d.ts +334 -0
- package/dist/caching/src/keyValue/index.d.ts.map +1 -0
- package/dist/caching/src/keyValue/index.js +796 -0
- package/dist/caching/src/keyValue/index.js.map +1 -0
- package/dist/caching/src/keyValue/serialize/serialize.d.ts +12 -0
- package/dist/caching/src/keyValue/serialize/serialize.d.ts.map +1 -0
- package/dist/caching/src/keyValue/serialize/serialize.js +64 -0
- package/dist/caching/src/keyValue/serialize/serialize.js.map +1 -0
- package/dist/caching/src/keyValue/stats-manager.d.ts +27 -0
- package/dist/caching/src/keyValue/stats-manager.d.ts.map +1 -0
- package/dist/caching/src/keyValue/stats-manager.js +64 -0
- package/dist/caching/src/keyValue/stats-manager.js.map +1 -0
- package/dist/caching/src/keyValue/types.d.ts +22 -0
- package/dist/caching/src/keyValue/types.d.ts.map +1 -0
- package/dist/caching/src/keyValue/types.js +11 -0
- package/dist/caching/src/keyValue/types.js.map +1 -0
- package/dist/caching/src/keyv-adapter.d.ts +40 -0
- package/dist/caching/src/keyv-adapter.d.ts.map +1 -0
- package/dist/caching/src/keyv-adapter.js +56 -0
- package/dist/caching/src/keyv-adapter.js.map +1 -0
- package/dist/caching/src/utils/cache-tags.d.ts +275 -0
- package/dist/caching/src/utils/cache-tags.d.ts.map +1 -0
- package/dist/caching/src/utils/cache-tags.js +407 -0
- package/dist/caching/src/utils/cache-tags.js.map +1 -0
- package/dist/caching/src/utils/cacheable-item-types.d.ts +35 -0
- package/dist/caching/src/utils/cacheable-item-types.d.ts.map +1 -0
- package/dist/caching/src/utils/cacheable-item-types.js +10 -0
- package/dist/caching/src/utils/cacheable-item-types.js.map +1 -0
- package/dist/caching/src/utils/coalesce-async.d.ts +29 -0
- package/dist/caching/src/utils/coalesce-async.d.ts.map +1 -0
- package/dist/caching/src/utils/coalesce-async.js +88 -0
- package/dist/caching/src/utils/coalesce-async.js.map +1 -0
- package/dist/caching/src/utils/hash.d.ts +55 -0
- package/dist/caching/src/utils/hash.d.ts.map +1 -0
- package/dist/caching/src/utils/hash.js +116 -0
- package/dist/caching/src/utils/hash.js.map +1 -0
- package/dist/caching/src/utils/index.d.ts +24 -0
- package/dist/caching/src/utils/index.d.ts.map +1 -0
- package/dist/caching/src/utils/index.js +21 -0
- package/dist/caching/src/utils/index.js.map +1 -0
- package/dist/caching/src/utils/is-keyv-instance.d.ts +10 -0
- package/dist/caching/src/utils/is-keyv-instance.d.ts.map +1 -0
- package/dist/caching/src/utils/is-keyv-instance.js +37 -0
- package/dist/caching/src/utils/is-keyv-instance.js.map +1 -0
- package/dist/caching/src/utils/is-object.d.ts +10 -0
- package/dist/caching/src/utils/is-object.d.ts.map +1 -0
- package/dist/caching/src/utils/is-object.js +13 -0
- package/dist/caching/src/utils/is-object.js.map +1 -0
- package/dist/caching/src/utils/less-than.d.ts +10 -0
- package/dist/caching/src/utils/less-than.d.ts.map +1 -0
- package/dist/caching/src/utils/less-than.js +13 -0
- package/dist/caching/src/utils/less-than.js.map +1 -0
- package/dist/caching/src/utils/memoize.d.ts +107 -0
- package/dist/caching/src/utils/memoize.d.ts.map +1 -0
- package/dist/caching/src/utils/memoize.js +201 -0
- package/dist/caching/src/utils/memoize.js.map +1 -0
- package/dist/caching/src/utils/mock-cacheable.d.ts +28 -0
- package/dist/caching/src/utils/mock-cacheable.d.ts.map +1 -0
- package/dist/caching/src/utils/mock-cacheable.js +87 -0
- package/dist/caching/src/utils/mock-cacheable.js.map +1 -0
- package/dist/caching/src/utils/run-if-fn.d.ts +12 -0
- package/dist/caching/src/utils/run-if-fn.d.ts.map +1 -0
- package/dist/caching/src/utils/run-if-fn.js +12 -0
- package/dist/caching/src/utils/run-if-fn.js.map +1 -0
- package/dist/caching/src/utils/shorthand-time.d.ts +27 -0
- package/dist/caching/src/utils/shorthand-time.d.ts.map +1 -0
- package/dist/caching/src/utils/shorthand-time.js +96 -0
- package/dist/caching/src/utils/shorthand-time.js.map +1 -0
- package/dist/caching/src/utils/sleep.d.ts +10 -0
- package/dist/caching/src/utils/sleep.d.ts.map +1 -0
- package/dist/caching/src/utils/sleep.js +11 -0
- package/dist/caching/src/utils/sleep.js.map +1 -0
- package/dist/caching/src/utils/stats.d.ts +354 -0
- package/dist/caching/src/utils/stats.d.ts.map +1 -0
- package/dist/caching/src/utils/stats.js +593 -0
- package/dist/caching/src/utils/stats.js.map +1 -0
- package/dist/caching/src/utils/ttl.d.ts +58 -0
- package/dist/caching/src/utils/ttl.d.ts.map +1 -0
- package/dist/caching/src/utils/ttl.js +77 -0
- package/dist/caching/src/utils/ttl.js.map +1 -0
- package/package.json +11 -3
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Original library: keyv (v5.6.0)
|
|
3
|
+
* - Copyright (c) 2017-2021 Luke Childs
|
|
4
|
+
* - Copyright (c) 2021-2022 Jared Wray
|
|
5
|
+
*
|
|
6
|
+
* Modified and integrated in "Inray":
|
|
7
|
+
* - Evgeniy Bushin
|
|
8
|
+
*/
|
|
9
|
+
/***/
|
|
10
|
+
import EventManager from './event-manager.ts';
|
|
11
|
+
import { Keyv, type KeyvEntry, type KeyvStoreAdapter, type StoredData } from './index.ts';
|
|
12
|
+
/**
|
|
13
|
+
* Configuration options for KeyvGenericStore.
|
|
14
|
+
*/
|
|
15
|
+
export type KeyvGenericStoreOptions = {
|
|
16
|
+
/**
|
|
17
|
+
* The namespace to use for keys. Can be a static string or a function that returns a string.
|
|
18
|
+
* When set, all keys will be prefixed with the namespace followed by the key separator.
|
|
19
|
+
*/
|
|
20
|
+
namespace?: string | (() => string);
|
|
21
|
+
/**
|
|
22
|
+
* The separator used between namespace and key. Defaults to "::".
|
|
23
|
+
*/
|
|
24
|
+
keySeparator?: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Interface for a Map-like store that can be used with KeyvGenericStore.
|
|
28
|
+
* This allows any object implementing these methods to be used as the underlying storage.
|
|
29
|
+
* Compatible with Map, QuickLRU, lru.min, and other LRU cache implementations.
|
|
30
|
+
*/
|
|
31
|
+
export type KeyvMapType = {
|
|
32
|
+
/** Retrieves a value by key */
|
|
33
|
+
get: (key: string) => any;
|
|
34
|
+
/** Sets a value with a key. Additional parameters (like TTL) vary by implementation. */
|
|
35
|
+
set: (key: string, value: any, ...args: any[]) => any;
|
|
36
|
+
/** Deletes a key from the store */
|
|
37
|
+
delete: (key: string) => boolean;
|
|
38
|
+
/** Clears all entries from the store */
|
|
39
|
+
clear: () => void;
|
|
40
|
+
/** Checks if a key exists in the store */
|
|
41
|
+
has: (key: string) => boolean;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Represents a cache item with its key, value, and optional TTL.
|
|
45
|
+
*/
|
|
46
|
+
export type CacheItem = {
|
|
47
|
+
/** The cache key */
|
|
48
|
+
key: string;
|
|
49
|
+
/** The cached value */
|
|
50
|
+
value: any;
|
|
51
|
+
/** Time-to-live in milliseconds */
|
|
52
|
+
ttl?: number;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Represents how an item is stored internally in the cache.
|
|
56
|
+
*/
|
|
57
|
+
export type CacheItemStore = {
|
|
58
|
+
/** The cache key */
|
|
59
|
+
key: string;
|
|
60
|
+
/** The cached value */
|
|
61
|
+
value: any;
|
|
62
|
+
/** Unix timestamp (in milliseconds) when the item expires */
|
|
63
|
+
expires?: number;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Data structure returned when parsing a prefixed key.
|
|
67
|
+
*/
|
|
68
|
+
export type KeyPrefixData = {
|
|
69
|
+
/** The namespace extracted from the key, if present */
|
|
70
|
+
namespace?: string;
|
|
71
|
+
/** The key without the namespace prefix */
|
|
72
|
+
key: string;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* A generic in-memory store adapter for Keyv that wraps any Map-like object.
|
|
76
|
+
*
|
|
77
|
+
* This class provides a unified interface for using various Map-like stores
|
|
78
|
+
* with Keyv, handling namespace prefixing, TTL-based expiration, and batch operations.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* // Using with a standard Map
|
|
83
|
+
* const store = new KeyvGenericStore(new Map(), { namespace: 'cache' });
|
|
84
|
+
*
|
|
85
|
+
* // Using with a custom store
|
|
86
|
+
* const customStore = new KeyvGenericStore(myCustomMapLikeStore, {
|
|
87
|
+
* namespace: () => `tenant-${getTenantId()}`,
|
|
88
|
+
* keySeparator: ':'
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare class KeyvGenericStore extends EventManager implements KeyvStoreAdapter {
|
|
93
|
+
private readonly _options?;
|
|
94
|
+
private _store;
|
|
95
|
+
private _namespace?;
|
|
96
|
+
private _keySeparator;
|
|
97
|
+
/**
|
|
98
|
+
* Creates a new KeyvGenericStore instance.
|
|
99
|
+
* @param store - The underlying Map or Map-like object to use for storage
|
|
100
|
+
* @param options - Configuration options for the store
|
|
101
|
+
*/
|
|
102
|
+
constructor(store: KeyvMapType, options?: KeyvGenericStoreOptions);
|
|
103
|
+
/**
|
|
104
|
+
* Gets the underlying store instance.
|
|
105
|
+
*/
|
|
106
|
+
get store(): KeyvMapType;
|
|
107
|
+
/**
|
|
108
|
+
* Sets the underlying store instance.
|
|
109
|
+
*/
|
|
110
|
+
set store(store: KeyvMapType);
|
|
111
|
+
/**
|
|
112
|
+
* Gets the current key separator used between namespace and key.
|
|
113
|
+
*/
|
|
114
|
+
get keySeparator(): string;
|
|
115
|
+
/**
|
|
116
|
+
* Sets the key separator used between namespace and key.
|
|
117
|
+
*/
|
|
118
|
+
set keySeparator(separator: string);
|
|
119
|
+
/**
|
|
120
|
+
* Gets the options passed to the constructor.
|
|
121
|
+
*/
|
|
122
|
+
get opts(): KeyvGenericStoreOptions | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* Gets the current namespace value (resolved if it's a function).
|
|
125
|
+
*/
|
|
126
|
+
get namespace(): string | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* Sets the namespace to a static string value.
|
|
129
|
+
*/
|
|
130
|
+
set namespace(namespace: string | undefined);
|
|
131
|
+
/**
|
|
132
|
+
* Gets the current namespace, resolving it if it's a function.
|
|
133
|
+
* @returns The resolved namespace string, or undefined if not set
|
|
134
|
+
*/
|
|
135
|
+
getNamespace(): string | undefined;
|
|
136
|
+
/**
|
|
137
|
+
* Sets the namespace to a static string or a function that returns a string.
|
|
138
|
+
* Using a function allows for dynamic namespaces (e.g., per-tenant).
|
|
139
|
+
* @param namespace - The namespace string, function, or undefined to clear
|
|
140
|
+
*/
|
|
141
|
+
setNamespace(namespace: string | (() => string) | undefined): void;
|
|
142
|
+
/**
|
|
143
|
+
* Creates a prefixed key by combining the namespace and key with the separator.
|
|
144
|
+
* @param key - The base key
|
|
145
|
+
* @param namespace - Optional namespace to prefix the key with
|
|
146
|
+
* @returns The prefixed key if namespace is provided, otherwise the original key
|
|
147
|
+
*/
|
|
148
|
+
getKeyPrefix(key: string, namespace?: string): string;
|
|
149
|
+
/**
|
|
150
|
+
* Parses a prefixed key to extract the namespace and original key.
|
|
151
|
+
* @param key - The prefixed key to parse
|
|
152
|
+
* @returns An object containing the namespace (if present) and the original key
|
|
153
|
+
*/
|
|
154
|
+
getKeyPrefixData(key: string): {
|
|
155
|
+
namespace: string;
|
|
156
|
+
key: string;
|
|
157
|
+
} | {
|
|
158
|
+
key: string;
|
|
159
|
+
namespace?: undefined;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Retrieves a value from the store by key.
|
|
163
|
+
* Automatically handles namespace prefixing and TTL expiration.
|
|
164
|
+
* @param key - The key to retrieve
|
|
165
|
+
* @returns The stored data, or undefined if not found or expired
|
|
166
|
+
*/
|
|
167
|
+
get<T>(key: string): Promise<StoredData<T> | undefined>;
|
|
168
|
+
/**
|
|
169
|
+
* Stores a value in the store with an optional TTL.
|
|
170
|
+
* @param key - The key to store the value under
|
|
171
|
+
* @param value - The value to store
|
|
172
|
+
* @param ttl - Optional time-to-live in milliseconds
|
|
173
|
+
* @returns Always returns true indicating success
|
|
174
|
+
*/
|
|
175
|
+
set(key: string, value: any, ttl?: number): Promise<boolean>;
|
|
176
|
+
/**
|
|
177
|
+
* Stores multiple entries in the store at once.
|
|
178
|
+
* @param entries - Array of entries containing key, value, and optional TTL
|
|
179
|
+
*/
|
|
180
|
+
setMany(entries: KeyvEntry[]): Promise<void>;
|
|
181
|
+
/**
|
|
182
|
+
* Deletes a value from the store by key.
|
|
183
|
+
* @param key - The key to delete
|
|
184
|
+
* @returns True if the key was deleted, false otherwise
|
|
185
|
+
*/
|
|
186
|
+
delete(key: string): Promise<boolean>;
|
|
187
|
+
/**
|
|
188
|
+
* Clears all entries from the store.
|
|
189
|
+
* Note: This clears the entire underlying store, not just the current namespace.
|
|
190
|
+
*/
|
|
191
|
+
clear(): Promise<void>;
|
|
192
|
+
/**
|
|
193
|
+
* Checks if a key exists in the store and is not expired.
|
|
194
|
+
* @param key - The key to check
|
|
195
|
+
* @returns True if the key exists and is not expired, false otherwise
|
|
196
|
+
*/
|
|
197
|
+
has(key: string): Promise<boolean>;
|
|
198
|
+
/**
|
|
199
|
+
* Retrieves multiple values from the store by their keys.
|
|
200
|
+
* @param keys - Array of keys to retrieve
|
|
201
|
+
* @returns Array of stored data in the same order as the input keys
|
|
202
|
+
*/
|
|
203
|
+
getMany<T>(keys: string[]): Promise<Array<StoredData<T | undefined>>>;
|
|
204
|
+
/**
|
|
205
|
+
* Deletes multiple keys from the store at once.
|
|
206
|
+
* @param keys - Array of keys to delete
|
|
207
|
+
* @returns True if all deletions succeeded, false if an error occurred
|
|
208
|
+
*/
|
|
209
|
+
deleteMany(keys: string[]): Promise<boolean>;
|
|
210
|
+
/**
|
|
211
|
+
* Creates an async iterator for iterating over store entries.
|
|
212
|
+
* If the underlying store does not support iteration, returns an empty generator.
|
|
213
|
+
* @param namespace - Optional namespace to filter entries by
|
|
214
|
+
* @returns {AsyncGenerator<Array<string | Awaited<Value> | undefined>, void>} An async generator yielding [key, value] pairs
|
|
215
|
+
*/
|
|
216
|
+
iterator<Value>(namespace?: string): AsyncGenerator<Array<string | Awaited<Value> | undefined>, void>;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Creates a Keyv instance with a generic store optimized for in-memory storage.
|
|
220
|
+
*
|
|
221
|
+
* This factory function configures Keyv to bypass serialization/deserialization
|
|
222
|
+
* and key prefixing, resulting in faster performance for in-memory use cases
|
|
223
|
+
* where data doesn't need to be persisted or transmitted.
|
|
224
|
+
*
|
|
225
|
+
* @param store - The underlying Map or Map-like object to use for storage
|
|
226
|
+
* @param options - Configuration options for the generic store
|
|
227
|
+
* @returns A configured Keyv instance with optimized settings for in-memory storage
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* // Create a simple in-memory cache
|
|
232
|
+
* const cache = createKeyv(new Map());
|
|
233
|
+
* await cache.set('user:1', { name: 'John' });
|
|
234
|
+
*
|
|
235
|
+
* // Create with namespace for multi-tenant scenarios
|
|
236
|
+
* const tenantCache = createKeyv(new Map(), {
|
|
237
|
+
* namespace: 'tenant-123',
|
|
238
|
+
* keySeparator: ':'
|
|
239
|
+
* });
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
export declare function createKeyv(store: KeyvMapType, options?: KeyvGenericStoreOptions): Keyv<any>;
|
|
243
|
+
//# sourceMappingURL=generic-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generic-store.d.ts","sourceRoot":"","sources":["../../../../src/caching/src/keyValue/generic-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,KAAK;AAEL,OAAO,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KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOlE;;;OAGG;IACG,OAAO,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAQlD;;;;OAIG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAK3C;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;;;OAIG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKxC;;;;OAIG;IACG,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;IAU3E;;;;OAIG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAclD;;;;;OAKG;IACI,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC,EAAE,IAAI,CAAC;CA4B7G;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,uBAAuB,aAM/E"}
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Original library: keyv (v5.6.0)
|
|
3
|
+
* - Copyright (c) 2017-2021 Luke Childs
|
|
4
|
+
* - Copyright (c) 2021-2022 Jared Wray
|
|
5
|
+
*
|
|
6
|
+
* Modified and integrated in "Inray":
|
|
7
|
+
* - Evgeniy Bushin
|
|
8
|
+
*/
|
|
9
|
+
/***/
|
|
10
|
+
import EventManager from "./event-manager.js";
|
|
11
|
+
import { Keyv } from "./index.js";
|
|
12
|
+
/**
|
|
13
|
+
* A generic in-memory store adapter for Keyv that wraps any Map-like object.
|
|
14
|
+
*
|
|
15
|
+
* This class provides a unified interface for using various Map-like stores
|
|
16
|
+
* with Keyv, handling namespace prefixing, TTL-based expiration, and batch operations.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // Using with a standard Map
|
|
21
|
+
* const store = new KeyvGenericStore(new Map(), { namespace: 'cache' });
|
|
22
|
+
*
|
|
23
|
+
* // Using with a custom store
|
|
24
|
+
* const customStore = new KeyvGenericStore(myCustomMapLikeStore, {
|
|
25
|
+
* namespace: () => `tenant-${getTenantId()}`,
|
|
26
|
+
* keySeparator: ':'
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export class KeyvGenericStore extends EventManager {
|
|
31
|
+
_options;
|
|
32
|
+
_store;
|
|
33
|
+
_namespace;
|
|
34
|
+
_keySeparator = '::';
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new KeyvGenericStore instance.
|
|
37
|
+
* @param store - The underlying Map or Map-like object to use for storage
|
|
38
|
+
* @param options - Configuration options for the store
|
|
39
|
+
*/
|
|
40
|
+
constructor(store, options) {
|
|
41
|
+
super();
|
|
42
|
+
this._store = store;
|
|
43
|
+
this._options = options;
|
|
44
|
+
if (options?.keySeparator) {
|
|
45
|
+
this._keySeparator = options.keySeparator;
|
|
46
|
+
}
|
|
47
|
+
if (options?.namespace) {
|
|
48
|
+
this._namespace = options?.namespace;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Gets the underlying store instance.
|
|
53
|
+
*/
|
|
54
|
+
get store() {
|
|
55
|
+
return this._store;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Sets the underlying store instance.
|
|
59
|
+
*/
|
|
60
|
+
set store(store) {
|
|
61
|
+
this._store = store;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Gets the current key separator used between namespace and key.
|
|
65
|
+
*/
|
|
66
|
+
get keySeparator() {
|
|
67
|
+
return this._keySeparator;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Sets the key separator used between namespace and key.
|
|
71
|
+
*/
|
|
72
|
+
set keySeparator(separator) {
|
|
73
|
+
this._keySeparator = separator;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Gets the options passed to the constructor.
|
|
77
|
+
*/
|
|
78
|
+
get opts() {
|
|
79
|
+
return this._options;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Gets the current namespace value (resolved if it's a function).
|
|
83
|
+
*/
|
|
84
|
+
get namespace() {
|
|
85
|
+
return this.getNamespace();
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Sets the namespace to a static string value.
|
|
89
|
+
*/
|
|
90
|
+
set namespace(namespace) {
|
|
91
|
+
this._namespace = namespace;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Gets the current namespace, resolving it if it's a function.
|
|
95
|
+
* @returns The resolved namespace string, or undefined if not set
|
|
96
|
+
*/
|
|
97
|
+
getNamespace() {
|
|
98
|
+
if (typeof this._namespace === 'function') {
|
|
99
|
+
return this._namespace();
|
|
100
|
+
}
|
|
101
|
+
return this._namespace;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Sets the namespace to a static string or a function that returns a string.
|
|
105
|
+
* Using a function allows for dynamic namespaces (e.g., per-tenant).
|
|
106
|
+
* @param namespace - The namespace string, function, or undefined to clear
|
|
107
|
+
*/
|
|
108
|
+
setNamespace(namespace) {
|
|
109
|
+
this._namespace = namespace;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Creates a prefixed key by combining the namespace and key with the separator.
|
|
113
|
+
* @param key - The base key
|
|
114
|
+
* @param namespace - Optional namespace to prefix the key with
|
|
115
|
+
* @returns The prefixed key if namespace is provided, otherwise the original key
|
|
116
|
+
*/
|
|
117
|
+
getKeyPrefix(key, namespace) {
|
|
118
|
+
if (namespace) {
|
|
119
|
+
return `${namespace}${this._keySeparator}${key}`;
|
|
120
|
+
}
|
|
121
|
+
return key;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Parses a prefixed key to extract the namespace and original key.
|
|
125
|
+
* @param key - The prefixed key to parse
|
|
126
|
+
* @returns An object containing the namespace (if present) and the original key
|
|
127
|
+
*/
|
|
128
|
+
getKeyPrefixData(key) {
|
|
129
|
+
if (key.includes(this._keySeparator)) {
|
|
130
|
+
const [namespace, ...rest] = key.split(this._keySeparator);
|
|
131
|
+
return { namespace, key: rest.join(this._keySeparator) };
|
|
132
|
+
}
|
|
133
|
+
return { key };
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Retrieves a value from the store by key.
|
|
137
|
+
* Automatically handles namespace prefixing and TTL expiration.
|
|
138
|
+
* @param key - The key to retrieve
|
|
139
|
+
* @returns The stored data, or undefined if not found or expired
|
|
140
|
+
*/
|
|
141
|
+
async get(key) {
|
|
142
|
+
const keyPrefix = this.getKeyPrefix(key, this.getNamespace());
|
|
143
|
+
const data = this._store.get(keyPrefix);
|
|
144
|
+
if (!data) {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
// Check if it is expired
|
|
148
|
+
if (data.expires && Date.now() > data.expires) {
|
|
149
|
+
this._store.delete(keyPrefix);
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
return data;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Stores a value in the store with an optional TTL.
|
|
156
|
+
* @param key - The key to store the value under
|
|
157
|
+
* @param value - The value to store
|
|
158
|
+
* @param ttl - Optional time-to-live in milliseconds
|
|
159
|
+
* @returns Always returns true indicating success
|
|
160
|
+
*/
|
|
161
|
+
async set(key, value, ttl) {
|
|
162
|
+
const keyPrefix = this.getKeyPrefix(key, this.getNamespace());
|
|
163
|
+
const data = { value, expires: ttl ? Date.now() + ttl : undefined };
|
|
164
|
+
this._store.set(keyPrefix, data, ttl);
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Stores multiple entries in the store at once.
|
|
169
|
+
* @param entries - Array of entries containing key, value, and optional TTL
|
|
170
|
+
*/
|
|
171
|
+
async setMany(entries) {
|
|
172
|
+
const results = [];
|
|
173
|
+
for (const entry of entries) {
|
|
174
|
+
const result = await this.set(entry.key, entry.value, entry.ttl);
|
|
175
|
+
results.push(result);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Deletes a value from the store by key.
|
|
180
|
+
* @param key - The key to delete
|
|
181
|
+
* @returns True if the key was deleted, false otherwise
|
|
182
|
+
*/
|
|
183
|
+
async delete(key) {
|
|
184
|
+
const keyPrefix = this.getKeyPrefix(key, this.getNamespace());
|
|
185
|
+
return this._store.delete(keyPrefix);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Clears all entries from the store.
|
|
189
|
+
* Note: This clears the entire underlying store, not just the current namespace.
|
|
190
|
+
*/
|
|
191
|
+
async clear() {
|
|
192
|
+
this._store.clear();
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Checks if a key exists in the store and is not expired.
|
|
196
|
+
* @param key - The key to check
|
|
197
|
+
* @returns True if the key exists and is not expired, false otherwise
|
|
198
|
+
*/
|
|
199
|
+
async has(key) {
|
|
200
|
+
const value = await this.get(key);
|
|
201
|
+
return Boolean(value);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Retrieves multiple values from the store by their keys.
|
|
205
|
+
* @param keys - Array of keys to retrieve
|
|
206
|
+
* @returns Array of stored data in the same order as the input keys
|
|
207
|
+
*/
|
|
208
|
+
async getMany(keys) {
|
|
209
|
+
const values = [];
|
|
210
|
+
for (const key of keys) {
|
|
211
|
+
const value = await this.get(key);
|
|
212
|
+
values.push(value);
|
|
213
|
+
}
|
|
214
|
+
return values;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Deletes multiple keys from the store at once.
|
|
218
|
+
* @param keys - Array of keys to delete
|
|
219
|
+
* @returns True if all deletions succeeded, false if an error occurred
|
|
220
|
+
*/
|
|
221
|
+
async deleteMany(keys) {
|
|
222
|
+
try {
|
|
223
|
+
for (const key of keys) {
|
|
224
|
+
const keyPrefix = this.getKeyPrefix(key, this.getNamespace());
|
|
225
|
+
this._store.delete(keyPrefix);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
this.emit('error', error);
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Creates an async iterator for iterating over store entries.
|
|
236
|
+
* If the underlying store does not support iteration, returns an empty generator.
|
|
237
|
+
* @param namespace - Optional namespace to filter entries by
|
|
238
|
+
* @returns {AsyncGenerator<Array<string | Awaited<Value> | undefined>, void>} An async generator yielding [key, value] pairs
|
|
239
|
+
*/
|
|
240
|
+
async *iterator(namespace) {
|
|
241
|
+
// Check if store supports iteration
|
|
242
|
+
if (typeof this._store.entries !== 'function') {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const iterator = this._store.entries();
|
|
246
|
+
for (const [key, data] of iterator) {
|
|
247
|
+
// Filter by namespace if provided
|
|
248
|
+
if (namespace) {
|
|
249
|
+
if (!key.startsWith(`${namespace}${this._keySeparator}`)) {
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
// Check expiration
|
|
254
|
+
if (data?.expires && Date.now() > data.expires) {
|
|
255
|
+
this._store.delete(key);
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
// Extract the key without namespace prefix
|
|
259
|
+
const keyWithoutPrefix = namespace ? key.slice(namespace.length + this._keySeparator.length) : key;
|
|
260
|
+
yield [keyWithoutPrefix, data?.value];
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Creates a Keyv instance with a generic store optimized for in-memory storage.
|
|
266
|
+
*
|
|
267
|
+
* This factory function configures Keyv to bypass serialization/deserialization
|
|
268
|
+
* and key prefixing, resulting in faster performance for in-memory use cases
|
|
269
|
+
* where data doesn't need to be persisted or transmitted.
|
|
270
|
+
*
|
|
271
|
+
* @param store - The underlying Map or Map-like object to use for storage
|
|
272
|
+
* @param options - Configuration options for the generic store
|
|
273
|
+
* @returns A configured Keyv instance with optimized settings for in-memory storage
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```typescript
|
|
277
|
+
* // Create a simple in-memory cache
|
|
278
|
+
* const cache = createKeyv(new Map());
|
|
279
|
+
* await cache.set('user:1', { name: 'John' });
|
|
280
|
+
*
|
|
281
|
+
* // Create with namespace for multi-tenant scenarios
|
|
282
|
+
* const tenantCache = createKeyv(new Map(), {
|
|
283
|
+
* namespace: 'tenant-123',
|
|
284
|
+
* keySeparator: ':'
|
|
285
|
+
* });
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
export function createKeyv(store, options) {
|
|
289
|
+
const genericStore = new KeyvGenericStore(store, options);
|
|
290
|
+
const keyv = new Keyv({ store: genericStore, useKeyPrefix: false });
|
|
291
|
+
keyv.serialize = undefined;
|
|
292
|
+
keyv.deserialize = undefined;
|
|
293
|
+
return keyv;
|
|
294
|
+
}
|
|
295
|
+
//# sourceMappingURL=generic-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generic-store.js","sourceRoot":"","sources":["../../../../src/caching/src/keyValue/generic-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,KAAK;AAEL,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAA0D,MAAM,YAAY,CAAC;AAqE1F;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,gBAAiB,SAAQ,YAA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+
import EventManager from './event-manager.ts';
|
|
11
|
+
type HookHandler = (...arguments_: any[]) => void;
|
|
12
|
+
declare class HooksManager extends EventManager {
|
|
13
|
+
_hookHandlers: Map<string, HookHandler[]>;
|
|
14
|
+
constructor();
|
|
15
|
+
addHandler(event: string, handler: HookHandler): void;
|
|
16
|
+
removeHandler(event: string, handler: HookHandler): void;
|
|
17
|
+
trigger(event: string, data: any): void;
|
|
18
|
+
get handlers(): Map<string, HookHandler[]>;
|
|
19
|
+
}
|
|
20
|
+
export default HooksManager;
|
|
21
|
+
//# sourceMappingURL=hooks-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks-manager.d.ts","sourceRoot":"","sources":["../../../../src/caching/src/keyValue/hooks-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,KAAK;AAEL,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAE9C,KAAK,WAAW,GAAG,CAAC,GAAG,UAAU,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAElD,cAAM,YAAa,SAAQ,YAAY;IACrC,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;;IAQ1C,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW;IAU9C,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW;IAYjD,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG;IAchC,IAAI,QAAQ,+BAGX;CACF;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Original library: keyv (v5.6.0)
|
|
3
|
+
* - Copyright (c) 2017-2021 Luke Childs
|
|
4
|
+
* - Copyright (c) 2021-2022 Jared Wray
|
|
5
|
+
*
|
|
6
|
+
* Modified and integrated in "Inray":
|
|
7
|
+
* - Evgeniy Bushin
|
|
8
|
+
*/
|
|
9
|
+
/***/
|
|
10
|
+
import EventManager from "./event-manager.js";
|
|
11
|
+
class HooksManager extends EventManager {
|
|
12
|
+
_hookHandlers;
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
this._hookHandlers = new Map();
|
|
16
|
+
}
|
|
17
|
+
// Adds a handler function for a specific event
|
|
18
|
+
addHandler(event, handler) {
|
|
19
|
+
const eventHandlers = this._hookHandlers.get(event);
|
|
20
|
+
if (eventHandlers) {
|
|
21
|
+
eventHandlers.push(handler);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
this._hookHandlers.set(event, [handler]);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// Removes a specific handler function for a specific event
|
|
28
|
+
removeHandler(event, handler) {
|
|
29
|
+
const eventHandlers = this._hookHandlers.get(event);
|
|
30
|
+
/* v8 ignore next -- @preserve */
|
|
31
|
+
if (eventHandlers) {
|
|
32
|
+
const index = eventHandlers.indexOf(handler);
|
|
33
|
+
if (index !== -1) {
|
|
34
|
+
eventHandlers.splice(index, 1);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// Triggers all handlers for a specific event with provided data
|
|
39
|
+
trigger(event, data) {
|
|
40
|
+
const eventHandlers = this._hookHandlers.get(event);
|
|
41
|
+
if (eventHandlers) {
|
|
42
|
+
for (const handler of eventHandlers) {
|
|
43
|
+
try {
|
|
44
|
+
handler(data);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
this.emit('error', new Error(`Error in hook handler for event "${event}": ${error.message}`));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Provides read-only access to the current handlers
|
|
53
|
+
get handlers() {
|
|
54
|
+
// Creating a new map to prevent external modifications to the original map
|
|
55
|
+
return new Map(this._hookHandlers);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export default HooksManager;
|
|
59
|
+
//# sourceMappingURL=hooks-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks-manager.js","sourceRoot":"","sources":["../../../../src/caching/src/keyValue/hooks-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,KAAK;AAEL,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAI9C,MAAM,YAAa,SAAQ,YAAY;IACrC,aAAa,CAA6B;IAE1C;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;IACjC,CAAC;IAED,+CAA+C;IAC/C,UAAU,CAAC,KAAa,EAAE,OAAoB;QAC5C,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACpD,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9B,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IAED,2DAA2D;IAC3D,aAAa,CAAC,KAAa,EAAE,OAAoB;QAC/C,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACpD,iCAAiC;QACjC,IAAI,aAAa,EAAE,CAAC;YAClB,MAAM,KAAK,GAAG,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC7C,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;gBACjB,aAAa,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YACjC,CAAC;QACH,CAAC;IACH,CAAC;IAED,gEAAgE;IAChE,OAAO,CAAC,KAAa,EAAE,IAAS;QAC9B,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACpD,IAAI,aAAa,EAAE,CAAC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