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,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Original library: hashery (v1.5.1)
|
|
3
|
+
* - Copyright (c) 2025 Jared Wray
|
|
4
|
+
*
|
|
5
|
+
* Modified and integrated in "Inray":
|
|
6
|
+
* - Evgeniy Bushin
|
|
7
|
+
*/
|
|
8
|
+
/***/
|
|
9
|
+
/**
|
|
10
|
+
* Manages a collection of hash providers for the Hashery system.
|
|
11
|
+
* Provides methods to add, remove, and load multiple hash providers.
|
|
12
|
+
*/
|
|
13
|
+
export class HashProviders {
|
|
14
|
+
_providers = new Map();
|
|
15
|
+
_getFuzzy = true;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new HashProviders instance.
|
|
18
|
+
* @param options - Optional configuration including initial providers to load
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const providers = new HashProviders({
|
|
22
|
+
* providers: [{ name: 'custom', toHash: async (data) => '...' }]
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
constructor(options) {
|
|
27
|
+
if (options?.providers) {
|
|
28
|
+
this.loadProviders(options?.providers);
|
|
29
|
+
}
|
|
30
|
+
if (options?.getFuzzy !== undefined) {
|
|
31
|
+
this._getFuzzy = Boolean(options?.getFuzzy);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Loads multiple hash providers at once.
|
|
36
|
+
* Each provider is added to the internal map using its name as the key.
|
|
37
|
+
* @param providers - Array of HashProvider objects to load
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const providers = new HashProviders();
|
|
41
|
+
* providers.loadProviders([
|
|
42
|
+
* { name: 'md5', toHash: async (data) => '...' },
|
|
43
|
+
* { name: 'sha1', toHash: async (data) => '...' }
|
|
44
|
+
* ]);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
loadProviders(providers) {
|
|
48
|
+
for (const provider of providers) {
|
|
49
|
+
this._providers.set(provider.name, provider);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Gets the internal Map of all registered hash providers.
|
|
54
|
+
* @returns Map of provider names to HashProvider objects
|
|
55
|
+
*/
|
|
56
|
+
get providers() {
|
|
57
|
+
return this._providers;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Sets the internal Map of hash providers, replacing all existing providers.
|
|
61
|
+
* @param providers - Map of provider names to HashProvider objects
|
|
62
|
+
*/
|
|
63
|
+
set providers(providers) {
|
|
64
|
+
this._providers = providers;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Gets an array of all provider names.
|
|
68
|
+
* @returns Array of provider names
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* const providers = new HashProviders();
|
|
72
|
+
* providers.add({ name: 'sha256', toHash: async (data) => '...' });
|
|
73
|
+
* providers.add({ name: 'md5', toHash: async (data) => '...' });
|
|
74
|
+
* console.log(providers.names); // ['sha256', 'md5']
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
get names() {
|
|
78
|
+
return Array.from(this._providers.keys());
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Gets a hash provider by name with optional fuzzy matching.
|
|
82
|
+
*
|
|
83
|
+
* Fuzzy matching (enabled by default) attempts to find providers by:
|
|
84
|
+
* 1. Exact match (after trimming whitespace)
|
|
85
|
+
* 2. Case-insensitive match (lowercase)
|
|
86
|
+
* 3. Dash-removed match (e.g., "SHA-256" matches "sha256")
|
|
87
|
+
*
|
|
88
|
+
* @param name - The name of the provider to retrieve
|
|
89
|
+
* @param options - Optional configuration for the get operation
|
|
90
|
+
* @param options.fuzzy - Enable/disable fuzzy matching (overrides constructor setting)
|
|
91
|
+
* @returns The HashProvider if found, undefined otherwise
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* const providers = new HashProviders();
|
|
95
|
+
* providers.add({ name: 'sha256', toHash: async (data) => '...' });
|
|
96
|
+
*
|
|
97
|
+
* // Exact match
|
|
98
|
+
* const provider = providers.get('sha256');
|
|
99
|
+
*
|
|
100
|
+
* // Fuzzy match (case-insensitive)
|
|
101
|
+
* const provider2 = providers.get('SHA256');
|
|
102
|
+
*
|
|
103
|
+
* // Fuzzy match (with dash)
|
|
104
|
+
* const provider3 = providers.get('SHA-256');
|
|
105
|
+
*
|
|
106
|
+
* // Disable fuzzy matching
|
|
107
|
+
* const provider4 = providers.get('SHA256', { fuzzy: false }); // returns undefined
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
get(name, options) {
|
|
111
|
+
// set the options
|
|
112
|
+
const getFuzzy = options?.fuzzy ?? this._getFuzzy;
|
|
113
|
+
// do the trim
|
|
114
|
+
name = name.trim();
|
|
115
|
+
let result = this._providers.get(name);
|
|
116
|
+
// try with lower case
|
|
117
|
+
if (result === undefined && getFuzzy === true) {
|
|
118
|
+
name = name.toLowerCase();
|
|
119
|
+
result = this._providers.get(name);
|
|
120
|
+
}
|
|
121
|
+
// try removing dash
|
|
122
|
+
if (result === undefined && getFuzzy === true) {
|
|
123
|
+
name = name.replaceAll('-', '');
|
|
124
|
+
result = this._providers.get(name);
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Adds a single hash provider to the collection.
|
|
130
|
+
* If a provider with the same name already exists, it will be replaced.
|
|
131
|
+
* @param provider - The HashProvider object to add
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* const providers = new HashProviders();
|
|
135
|
+
* providers.add({
|
|
136
|
+
* name: 'custom-hash',
|
|
137
|
+
* toHash: async (data) => {
|
|
138
|
+
* // Custom hashing logic
|
|
139
|
+
* return 'hash-result';
|
|
140
|
+
* }
|
|
141
|
+
* });
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
add(provider) {
|
|
145
|
+
this._providers.set(provider.name, provider);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Removes a hash provider from the collection by name.
|
|
149
|
+
* @param name - The name of the provider to remove
|
|
150
|
+
* @returns true if the provider was found and removed, false otherwise
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* const providers = new HashProviders();
|
|
154
|
+
* providers.add({ name: 'custom', toHash: async (data) => '...' });
|
|
155
|
+
* const removed = providers.remove('custom'); // returns true
|
|
156
|
+
* const removed2 = providers.remove('nonexistent'); // returns false
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
remove(name) {
|
|
160
|
+
return this._providers.delete(name);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../../../../src/caching/src/hashing/providers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;AAIL;;;GAGG;AACH,MAAM,OAAO,aAAa;IAChB,UAAU,GAA8B,IAAI,GAAG,EAAE,CAAC;IA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EAAE,CAAC;YAC9C,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;YAC1B,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACrC,CAAC;QAED,oBAAoB;QACpB,IAAI,MAAM,KAAK,SAAS,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YAC9C,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAChC,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACrC,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACI,GAAG,CAAC,QAAsB;QAC/B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;;;;;;;OAWG;IACI,MAAM,CAAC,IAAY;QACxB,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;CACF"}
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Original library: hashery (v1.5.1)
|
|
3
|
+
* - Copyright (c) 2025 Jared Wray
|
|
4
|
+
*
|
|
5
|
+
* Modified and integrated in "Inray":
|
|
6
|
+
* - Evgeniy Bushin
|
|
7
|
+
*/
|
|
8
|
+
/***/
|
|
9
|
+
import type { HookifiedOptions } from './hooks/index.ts';
|
|
10
|
+
import type { CacheOptions } from './cache.ts';
|
|
11
|
+
/**
|
|
12
|
+
* Configuration options for Hashery instances.
|
|
13
|
+
* Extends HookifiedOptions to include parse and stringify functionality.
|
|
14
|
+
*/
|
|
15
|
+
export type HasheryOptions = {
|
|
16
|
+
/**
|
|
17
|
+
* Custom parse function to deserialize string data.
|
|
18
|
+
* Defaults to JSON.parse if not provided.
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import superjson from 'superjson';
|
|
22
|
+
*
|
|
23
|
+
* const hashery = new Hashery({
|
|
24
|
+
* parse: (data) => superjson.parse(data)
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
parse?: ParseFn;
|
|
29
|
+
/**
|
|
30
|
+
* Custom stringify function to serialize data to string format.
|
|
31
|
+
* Defaults to JSON.stringify if not provided.
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import superjson from 'superjson';
|
|
35
|
+
*
|
|
36
|
+
* const hashery = new Hashery({
|
|
37
|
+
* stringify: (data) => superjson.stringify(data)
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
stringify?: StringifyFn;
|
|
42
|
+
/**
|
|
43
|
+
* Array of hash providers to add to base providers
|
|
44
|
+
* Providers implement the HashProvider interface and enable custom hashing algorithms.
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* const customProvider = {
|
|
48
|
+
* name: 'custom-hash',
|
|
49
|
+
* toHash: async (data) => {
|
|
50
|
+
* // Custom hash implementation
|
|
51
|
+
* return 'hash-value';
|
|
52
|
+
* }
|
|
53
|
+
* };
|
|
54
|
+
*
|
|
55
|
+
* const hashery = new Hashery({
|
|
56
|
+
* providers: [customProvider]
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
providers?: Array<HashProvider>;
|
|
61
|
+
/**
|
|
62
|
+
* Whether to include base WebCrypto providers (SHA-256, SHA-384, SHA-512).
|
|
63
|
+
* Defaults to true.
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* // Create instance without base providers
|
|
67
|
+
* const hashery = new Hashery({
|
|
68
|
+
* includeBase: false,
|
|
69
|
+
* providers: [customProvider]
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
includeBase?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Default hash algorithm to use when none is specified.
|
|
76
|
+
* Defaults to 'SHA-256'.
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* const hashery = new Hashery({
|
|
80
|
+
* defaultAlgorithm: 'SHA-512'
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* // This will use SHA-512 instead of SHA-256
|
|
84
|
+
* const hash = await hashery.toHash({ data: 'example' });
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
defaultAlgorithm?: HashAlgorithm | (string & {});
|
|
88
|
+
/**
|
|
89
|
+
* Default synchronous hash algorithm to use when none is specified.
|
|
90
|
+
* Defaults to 'djb2'.
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* const hashery = new Hashery({
|
|
94
|
+
* defaultAlgorithmSync: 'fnv1'
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* // This will use fnv1 for synchronous operations by default
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
defaultAlgorithmSync?: HashAlgorithm | (string & {});
|
|
101
|
+
/**
|
|
102
|
+
* Cache configuration options.
|
|
103
|
+
* Pass { enabled: true } to enable caching of hash results.
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* const hashery = new Hashery({
|
|
107
|
+
* cache: { enabled: true, maxSize: 500 }
|
|
108
|
+
* });
|
|
109
|
+
*
|
|
110
|
+
* // Hashes will be cached and reused for identical inputs
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
cache?: CacheOptions;
|
|
114
|
+
} & HookifiedOptions;
|
|
115
|
+
/**
|
|
116
|
+
* Options for the toHash method.
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* const hashery = new Hashery();
|
|
120
|
+
*
|
|
121
|
+
* // Using a specific algorithm
|
|
122
|
+
* const hash = await hashery.toHash({ data: 'example' }, { algorithm: 'SHA-512' });
|
|
123
|
+
*
|
|
124
|
+
* // Truncating the hash output
|
|
125
|
+
* const shortHash = await hashery.toHash(
|
|
126
|
+
* { data: 'example' },
|
|
127
|
+
* { algorithm: 'SHA-256', maxLength: 16 }
|
|
128
|
+
* );
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export type HasheryToHashOptions = {
|
|
132
|
+
/**
|
|
133
|
+
* The hash algorithm to use.
|
|
134
|
+
* Defaults to 'SHA-256' if not specified.
|
|
135
|
+
* Supported algorithms include: 'SHA-256', 'SHA-384', 'SHA-512', 'djb2', 'fnv1', 'murmur', 'crc32'
|
|
136
|
+
*/
|
|
137
|
+
algorithm?: HashAlgorithm | (string & {});
|
|
138
|
+
/**
|
|
139
|
+
* Maximum length for the hash output.
|
|
140
|
+
* If specified, the hash will be truncated to this length.
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* // Get a 16-character hash instead of the full 64-character SHA-256 hash
|
|
144
|
+
* const hash = await hashery.toHash({ data: 'example' }, { maxLength: 16 });
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
maxLength?: number;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Options for the toNumber method.
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* const hashery = new Hashery();
|
|
154
|
+
*
|
|
155
|
+
* // Using default range (0-100)
|
|
156
|
+
* const num = await hashery.toNumber({ user: 'john' });
|
|
157
|
+
*
|
|
158
|
+
* // Using custom range
|
|
159
|
+
* const slot = await hashery.toNumber({ user: 'john' }, { min: 0, max: 9 });
|
|
160
|
+
*
|
|
161
|
+
* // Using different algorithm
|
|
162
|
+
* const num512 = await hashery.toNumber(
|
|
163
|
+
* { user: 'john' },
|
|
164
|
+
* { min: 0, max: 255, algorithm: 'SHA-512' }
|
|
165
|
+
* );
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export type HasheryToNumberOptions = {
|
|
169
|
+
/**
|
|
170
|
+
* The hash algorithm to use.
|
|
171
|
+
* Defaults to 'SHA-256' if not specified.
|
|
172
|
+
* Supported algorithms include: 'SHA-256', 'SHA-384', 'SHA-512', 'djb2', 'fnv1', 'murmur', 'crc32'
|
|
173
|
+
*/
|
|
174
|
+
algorithm?: HashAlgorithm | (string & {});
|
|
175
|
+
/**
|
|
176
|
+
* The minimum value of the range (inclusive).
|
|
177
|
+
* Defaults to 0 if not specified.
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* // Generate number between 1 and 100
|
|
181
|
+
* const num = await hashery.toNumber({ data: 'example' }, { min: 1, max: 100 });
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
min?: number;
|
|
185
|
+
/**
|
|
186
|
+
* The maximum value of the range (inclusive).
|
|
187
|
+
* Defaults to 100 if not specified.
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* // Generate number between 0 and 1000
|
|
191
|
+
* const num = await hashery.toNumber({ data: 'example' }, { min: 0, max: 1000 });
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
max?: number;
|
|
195
|
+
/**
|
|
196
|
+
* Number of characters from the hash to use for conversion.
|
|
197
|
+
* Defaults to 16 if not specified.
|
|
198
|
+
* This provides good distribution while avoiding precision issues with JavaScript numbers.
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* // Use more hash characters for better distribution
|
|
202
|
+
* const num = await hashery.toNumber({ data: 'example' }, { hashLength: 32 });
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
hashLength?: number;
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Options for the toHashSync method.
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* const hashery = new Hashery();
|
|
212
|
+
*
|
|
213
|
+
* // Using a specific algorithm
|
|
214
|
+
* const hash = hashery.toHashSync({ data: 'example' }, { algorithm: 'fnv1' });
|
|
215
|
+
*
|
|
216
|
+
* // Truncating the hash output
|
|
217
|
+
* const shortHash = hashery.toHashSync(
|
|
218
|
+
* { data: 'example' },
|
|
219
|
+
* { algorithm: 'djb2', maxLength: 16 }
|
|
220
|
+
* );
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
export type HasheryToHashSyncOptions = {
|
|
224
|
+
/**
|
|
225
|
+
* The hash algorithm to use.
|
|
226
|
+
* Defaults to 'djb2' if not specified.
|
|
227
|
+
* Supported synchronous algorithms include: 'djb2', 'fnv1', 'murmur', 'crc32'
|
|
228
|
+
* Note: WebCrypto algorithms (SHA-256, SHA-384, SHA-512) are not supported in sync mode.
|
|
229
|
+
*/
|
|
230
|
+
algorithm?: HashAlgorithm | (string & {});
|
|
231
|
+
/**
|
|
232
|
+
* Maximum length for the hash output.
|
|
233
|
+
* If specified, the hash will be truncated to this length.
|
|
234
|
+
* @example
|
|
235
|
+
* ```ts
|
|
236
|
+
* // Get a 16-character hash
|
|
237
|
+
* const hash = hashery.toHashSync({ data: 'example' }, { maxLength: 16 });
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
maxLength?: number;
|
|
241
|
+
};
|
|
242
|
+
/**
|
|
243
|
+
* Options for the toNumberSync method.
|
|
244
|
+
* @example
|
|
245
|
+
* ```ts
|
|
246
|
+
* const hashery = new Hashery();
|
|
247
|
+
*
|
|
248
|
+
* // Using default range (0-100)
|
|
249
|
+
* const num = hashery.toNumberSync({ user: 'john' });
|
|
250
|
+
*
|
|
251
|
+
* // Using custom range
|
|
252
|
+
* const slot = hashery.toNumberSync({ user: 'john' }, { min: 0, max: 9 });
|
|
253
|
+
*
|
|
254
|
+
* // Using different algorithm
|
|
255
|
+
* const num = hashery.toNumberSync(
|
|
256
|
+
* { user: 'john' },
|
|
257
|
+
* { min: 0, max: 255, algorithm: 'fnv1' }
|
|
258
|
+
* );
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
export type HasheryToNumberSyncOptions = {
|
|
262
|
+
/**
|
|
263
|
+
* The hash algorithm to use.
|
|
264
|
+
* Defaults to 'djb2' if not specified.
|
|
265
|
+
* Supported synchronous algorithms include: 'djb2', 'fnv1', 'murmur', 'crc32'
|
|
266
|
+
* Note: WebCrypto algorithms (SHA-256, SHA-384, SHA-512) are not supported in sync mode.
|
|
267
|
+
*/
|
|
268
|
+
algorithm?: HashAlgorithm | (string & {});
|
|
269
|
+
/**
|
|
270
|
+
* The minimum value of the range (inclusive).
|
|
271
|
+
* Defaults to 0 if not specified.
|
|
272
|
+
* @example
|
|
273
|
+
* ```ts
|
|
274
|
+
* // Generate number between 1 and 100
|
|
275
|
+
* const num = hashery.toNumberSync({ data: 'example' }, { min: 1, max: 100 });
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
min?: number;
|
|
279
|
+
/**
|
|
280
|
+
* The maximum value of the range (inclusive).
|
|
281
|
+
* Defaults to 100 if not specified.
|
|
282
|
+
* @example
|
|
283
|
+
* ```ts
|
|
284
|
+
* // Generate number between 0 and 1000
|
|
285
|
+
* const num = hashery.toNumberSync({ data: 'example' }, { min: 0, max: 1000 });
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
max?: number;
|
|
289
|
+
/**
|
|
290
|
+
* Number of characters from the hash to use for conversion.
|
|
291
|
+
* Defaults to 16 if not specified.
|
|
292
|
+
* This provides good distribution while avoiding precision issues with JavaScript numbers.
|
|
293
|
+
* @example
|
|
294
|
+
* ```ts
|
|
295
|
+
* // Use more hash characters for better distribution
|
|
296
|
+
* const num = hashery.toNumberSync({ data: 'example' }, { hashLength: 32 });
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
hashLength?: number;
|
|
300
|
+
};
|
|
301
|
+
/**
|
|
302
|
+
* Function type for serializing data to a string.
|
|
303
|
+
* @param data - The data to stringify
|
|
304
|
+
* @returns The stringified representation
|
|
305
|
+
*/
|
|
306
|
+
export type StringifyFn = (data: unknown) => string;
|
|
307
|
+
/**
|
|
308
|
+
* Function type for parsing string data.
|
|
309
|
+
* @param data - The string data to parse
|
|
310
|
+
* @returns The parsed data
|
|
311
|
+
*/
|
|
312
|
+
export type ParseFn = (data: string) => unknown;
|
|
313
|
+
/**
|
|
314
|
+
* Supported hash algorithms for the Web Crypto API.
|
|
315
|
+
* - SHA-256: Recommended algorithm (256-bit) - good balance of security and performance
|
|
316
|
+
* - SHA-384: High security algorithm (384-bit)
|
|
317
|
+
* - SHA-512: Highest security algorithm (512-bit)
|
|
318
|
+
*/
|
|
319
|
+
export type WebCryptoHashAlgorithm = 'SHA-256' | 'SHA-384' | 'SHA-512';
|
|
320
|
+
/**
|
|
321
|
+
* All built-in hash algorithm names supported by Hashery.
|
|
322
|
+
* Includes both WebCrypto (async-only) and non-cryptographic (sync & async) algorithms.
|
|
323
|
+
*/
|
|
324
|
+
export type HashAlgorithm = 'SHA-256' | 'SHA-384' | 'SHA-512' | 'djb2' | 'fnv1' | 'murmur' | 'crc32';
|
|
325
|
+
export type HashProvider = {
|
|
326
|
+
name: string;
|
|
327
|
+
toHash(data: BufferSource): Promise<string>;
|
|
328
|
+
toHashSync?(data: BufferSource): string;
|
|
329
|
+
};
|
|
330
|
+
export type HashProvidersOptions = {
|
|
331
|
+
providers?: Array<HashProvider>;
|
|
332
|
+
getFuzzy?: boolean;
|
|
333
|
+
};
|
|
334
|
+
export type HashProvidersGetOptions = {
|
|
335
|
+
fuzzy?: boolean;
|
|
336
|
+
};
|
|
337
|
+
export type HasheryLoadProviderOptions = {
|
|
338
|
+
includeBase?: boolean;
|
|
339
|
+
};
|
|
340
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/caching/src/hashing/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;AAEL,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MA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AG;IACpC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/caching/src/hashing/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK"}
|
|
@@ -0,0 +1,161 @@
|
|
|
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
|
+
export type IsKeyvResult = {
|
|
11
|
+
keyv: boolean;
|
|
12
|
+
get: boolean;
|
|
13
|
+
set: boolean;
|
|
14
|
+
delete: boolean;
|
|
15
|
+
clear: boolean;
|
|
16
|
+
has: boolean;
|
|
17
|
+
getMany: boolean;
|
|
18
|
+
setMany: boolean;
|
|
19
|
+
deleteMany: boolean;
|
|
20
|
+
hasMany: boolean;
|
|
21
|
+
disconnect: boolean;
|
|
22
|
+
getRaw: boolean;
|
|
23
|
+
getManyRaw: boolean;
|
|
24
|
+
hooks: boolean;
|
|
25
|
+
stats: boolean;
|
|
26
|
+
iterator: boolean;
|
|
27
|
+
};
|
|
28
|
+
export type IsKeyvStorageResult = {
|
|
29
|
+
keyvStorage: boolean;
|
|
30
|
+
get: boolean;
|
|
31
|
+
set: boolean;
|
|
32
|
+
delete: boolean;
|
|
33
|
+
clear: boolean;
|
|
34
|
+
has: boolean;
|
|
35
|
+
getMany: boolean;
|
|
36
|
+
setMany: boolean;
|
|
37
|
+
deleteMany: boolean;
|
|
38
|
+
hasMany: boolean;
|
|
39
|
+
disconnect: boolean;
|
|
40
|
+
iterator: boolean;
|
|
41
|
+
namespace: boolean;
|
|
42
|
+
};
|
|
43
|
+
export type IsKeyvCompressionResult = {
|
|
44
|
+
keyvCompression: boolean;
|
|
45
|
+
compress: boolean;
|
|
46
|
+
decompress: boolean;
|
|
47
|
+
};
|
|
48
|
+
export type IsKeyvSerializationResult = {
|
|
49
|
+
keyvSerialization: boolean;
|
|
50
|
+
stringify: boolean;
|
|
51
|
+
parse: boolean;
|
|
52
|
+
};
|
|
53
|
+
export type IsKeyvEncryptionResult = {
|
|
54
|
+
keyvEncryption: boolean;
|
|
55
|
+
encrypt: boolean;
|
|
56
|
+
decrypt: boolean;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Check if an object is a Keyv instance or has Keyv-like capabilities
|
|
60
|
+
* @param obj - The object to check
|
|
61
|
+
* @returns An object with boolean properties for each Keyv method/property
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* import { isKeyv } from 'keyv';
|
|
65
|
+
*
|
|
66
|
+
* isKeyv(new Map());
|
|
67
|
+
* // { keyv: false, get: true, set: true, delete: true, clear: true, has: true,
|
|
68
|
+
* // getMany: false, setMany: false, deleteMany: false, hasMany: false,
|
|
69
|
+
* // disconnect: false, getRaw: false, getManyRaw: false, hooks: false,
|
|
70
|
+
* // stats: false, iterator: false }
|
|
71
|
+
*
|
|
72
|
+
* isKeyv(new Keyv());
|
|
73
|
+
* // { keyv: true, get: true, set: true, delete: true, clear: true, has: true,
|
|
74
|
+
* // getMany: true, setMany: true, deleteMany: true, hasMany: true,
|
|
75
|
+
* // disconnect: true, getRaw: true, getManyRaw: true, hooks: true,
|
|
76
|
+
* // stats: true, iterator: false }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function isKeyv(obj: unknown): IsKeyvResult;
|
|
80
|
+
/**
|
|
81
|
+
* Check if an object is a Keyv storage adapter or has storage adapter-like capabilities
|
|
82
|
+
* @param obj - The object to check
|
|
83
|
+
* @returns An object with boolean properties for each storage adapter method/property
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* import { isKeyvStorage } from 'keyv';
|
|
87
|
+
*
|
|
88
|
+
* isKeyvStorage(new Map());
|
|
89
|
+
* // { keyvStorage: false, get: true, set: true, delete: true, clear: true, has: true,
|
|
90
|
+
* // getMany: false, setMany: false, deleteMany: false, hasMany: false,
|
|
91
|
+
* // disconnect: false, iterator: false, namespace: false }
|
|
92
|
+
*
|
|
93
|
+
* const adapter = new KeyvRedis();
|
|
94
|
+
* isKeyvStorage(adapter);
|
|
95
|
+
* // { keyvStorage: true, get: true, set: true, delete: true, clear: true, has: true,
|
|
96
|
+
* // getMany: true, setMany: true, deleteMany: true, hasMany: true,
|
|
97
|
+
* // disconnect: true, iterator: true, namespace: true }
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function isKeyvStorage(obj: unknown): IsKeyvStorageResult;
|
|
101
|
+
/**
|
|
102
|
+
* Check if an object is a Keyv compression adapter or has compression capabilities
|
|
103
|
+
* @param obj - The object to check
|
|
104
|
+
* @returns An object with boolean properties for each compression method
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* import { isKeyvCompression } from 'keyv';
|
|
108
|
+
*
|
|
109
|
+
* const gzip = {
|
|
110
|
+
* compress: (data) => compressSync(data),
|
|
111
|
+
* decompress: (data) => decompressSync(data)
|
|
112
|
+
* };
|
|
113
|
+
* isKeyvCompression(gzip);
|
|
114
|
+
* // { keyvCompression: true, compress: true, decompress: true }
|
|
115
|
+
*
|
|
116
|
+
* isKeyvCompression({});
|
|
117
|
+
* // { keyvCompression: false, compress: false, decompress: false }
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare function isKeyvCompression(obj: unknown): IsKeyvCompressionResult;
|
|
121
|
+
/**
|
|
122
|
+
* Check if an object is a Keyv serialization adapter or has serialization capabilities
|
|
123
|
+
* @param obj - The object to check
|
|
124
|
+
* @returns An object with boolean properties for each serialization method
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* import { isKeyvSerialization } from 'keyv';
|
|
128
|
+
*
|
|
129
|
+
* const json = {
|
|
130
|
+
* stringify: (obj) => JSON.stringify(obj),
|
|
131
|
+
* parse: (str) => JSON.parse(str)
|
|
132
|
+
* };
|
|
133
|
+
* isKeyvSerialization(json);
|
|
134
|
+
* // { keyvSerialization: true, stringify: true, parse: true }
|
|
135
|
+
*
|
|
136
|
+
* isKeyvSerialization({});
|
|
137
|
+
* // { keyvSerialization: false, stringify: false, parse: false }
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export declare function isKeyvSerialization(obj: unknown): IsKeyvSerializationResult;
|
|
141
|
+
/**
|
|
142
|
+
* Check if an object is a Keyv encryption adapter or has encryption capabilities
|
|
143
|
+
* @param obj - The object to check
|
|
144
|
+
* @returns An object with boolean properties for each encryption method
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* import { isKeyvEncryption } from 'keyv';
|
|
148
|
+
*
|
|
149
|
+
* const aes = {
|
|
150
|
+
* encrypt: (data) => encryptAES(data),
|
|
151
|
+
* decrypt: (data) => decryptAES(data)
|
|
152
|
+
* };
|
|
153
|
+
* isKeyvEncryption(aes);
|
|
154
|
+
* // { keyvEncryption: true, encrypt: true, decrypt: true }
|
|
155
|
+
*
|
|
156
|
+
* isKeyvEncryption({});
|
|
157
|
+
* // { keyvEncryption: false, encrypt: false, decrypt: false }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export declare function isKeyvEncryption(obj: unknown): IsKeyvEncryptionResult;
|
|
161
|
+
//# sourceMappingURL=capabilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../../../src/caching/src/keyValue/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,KAAK;AAEL,MAAM,MAAM,YAAY,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