inray 0.0.2 → 0.0.4
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 +220 -36
- package/dist/async/abortable.d.ts +2 -2
- package/dist/async/abortable.d.ts.map +1 -1
- package/dist/async/abortable.js.map +1 -1
- 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/dist/logtape/logtape/level.d.ts +1 -2
- package/dist/logtape/logtape/level.d.ts.map +1 -1
- package/dist/logtape/logtape/level.js +1 -1
- package/dist/logtape/logtape/level.js.map +1 -1
- package/dist/logtape/logtape/mod.d.ts +1 -1
- package/dist/logtape/logtape/mod.d.ts.map +1 -1
- package/dist/logtape/logtape/mod.js +1 -1
- package/dist/logtape/logtape/mod.js.map +1 -1
- package/dist/utils/mod.d.ts +1 -1
- package/dist/utils/mod.d.ts.map +1 -1
- package/dist/utils/mod.js.map +1 -1
- package/dist/utils/validation/inRangeOfMaxInt32.d.ts +2 -0
- package/dist/utils/validation/inRangeOfMaxInt32.d.ts.map +1 -0
- package/dist/utils/validation/inRangeOfMaxInt32.js +4 -0
- package/dist/utils/validation/inRangeOfMaxInt32.js.map +1 -0
- package/dist/utils/validation/isEmail.d.ts +2 -0
- package/dist/utils/validation/isEmail.d.ts.map +1 -0
- package/dist/utils/validation/isEmail.js +7 -0
- package/dist/utils/validation/isEmail.js.map +1 -0
- package/dist/utils/validation/isEmptyObject.d.ts +9 -0
- package/dist/utils/validation/isEmptyObject.d.ts.map +1 -0
- package/dist/utils/validation/isEmptyObject.js +16 -0
- package/dist/utils/validation/isEmptyObject.js.map +1 -0
- package/dist/utils/validation/isNotEmptyString.d.ts +7 -0
- package/dist/utils/validation/isNotEmptyString.d.ts.map +1 -0
- package/dist/utils/validation/isNotEmptyString.js +17 -0
- package/dist/utils/validation/isNotEmptyString.js.map +1 -0
- package/dist/utils/validation/isPositiveInteger.d.ts +2 -0
- package/dist/utils/validation/isPositiveInteger.d.ts.map +1 -0
- package/dist/utils/validation/isPositiveInteger.js +7 -0
- package/dist/utils/validation/isPositiveInteger.js.map +1 -0
- package/dist/utils/validation/isUuid.d.ts +2 -0
- package/dist/utils/validation/isUuid.d.ts.map +1 -0
- package/dist/utils/validation/isUuid.js +7 -0
- package/dist/utils/validation/isUuid.js.map +1 -0
- package/dist/utils/validation/isUuidArray.d.ts +2 -0
- package/dist/utils/validation/isUuidArray.d.ts.map +1 -0
- package/dist/utils/validation/isUuidArray.js +7 -0
- package/dist/utils/validation/isUuidArray.js.map +1 -0
- package/dist/utils/validation/isValidFileName.d.ts +2 -0
- package/dist/utils/validation/isValidFileName.d.ts.map +1 -0
- package/dist/utils/validation/isValidFileName.js +33 -0
- package/dist/utils/validation/isValidFileName.js.map +1 -0
- package/dist/utils/validation/isValidUrlLike.d.ts +6 -0
- package/dist/utils/validation/isValidUrlLike.d.ts.map +1 -0
- package/dist/utils/validation/isValidUrlLike.js +8 -0
- package/dist/utils/validation/isValidUrlLike.js.map +1 -0
- package/dist/utils/validation/mod.d.ts +21 -0
- package/dist/utils/validation/mod.d.ts.map +1 -0
- package/dist/utils/validation/mod.js +21 -0
- package/dist/utils/validation/mod.js.map +1 -0
- package/dist/utils/validation/vEnvBoolean.d.ts +3 -0
- package/dist/utils/validation/vEnvBoolean.d.ts.map +1 -0
- package/dist/utils/validation/vEnvBoolean.js +5 -0
- package/dist/utils/validation/vEnvBoolean.js.map +1 -0
- package/dist/utils/validation/vEnvBooleanOrUndefined.d.ts +3 -0
- package/dist/utils/validation/vEnvBooleanOrUndefined.d.ts.map +1 -0
- package/dist/utils/validation/vEnvBooleanOrUndefined.js +5 -0
- package/dist/utils/validation/vEnvBooleanOrUndefined.js.map +1 -0
- package/dist/utils/validation/vEnvLogLevel.d.ts +4 -0
- package/dist/utils/validation/vEnvLogLevel.d.ts.map +1 -0
- package/dist/utils/validation/vEnvLogLevel.js +6 -0
- package/dist/utils/validation/vEnvLogLevel.js.map +1 -0
- package/dist/utils/validation/vFileName.d.ts +4 -0
- package/dist/utils/validation/vFileName.d.ts.map +1 -0
- package/dist/utils/validation/vFileName.js +21 -0
- package/dist/utils/validation/vFileName.js.map +1 -0
- package/dist/utils/validation/vISO8601DateTime.d.ts +5 -0
- package/dist/utils/validation/vISO8601DateTime.d.ts.map +1 -0
- package/dist/utils/validation/vISO8601DateTime.js +37 -0
- package/dist/utils/validation/vISO8601DateTime.js.map +1 -0
- package/dist/utils/validation/vLatinInput.d.ts +3 -0
- package/dist/utils/validation/vLatinInput.d.ts.map +1 -0
- package/dist/utils/validation/vLatinInput.js +3 -0
- package/dist/utils/validation/vLatinInput.js.map +1 -0
- package/dist/utils/validation/vOmniBoolean.d.ts +3 -0
- package/dist/utils/validation/vOmniBoolean.d.ts.map +1 -0
- package/dist/utils/validation/vOmniBoolean.js +10 -0
- package/dist/utils/validation/vOmniBoolean.js.map +1 -0
- package/dist/utils/validation/vQueryBoolean.d.ts +3 -0
- package/dist/utils/validation/vQueryBoolean.d.ts.map +1 -0
- package/dist/utils/validation/vQueryBoolean.js +7 -0
- package/dist/utils/validation/vQueryBoolean.js.map +1 -0
- package/dist/utils/validation/vQueryEmailArray.d.ts +9 -0
- package/dist/utils/validation/vQueryEmailArray.d.ts.map +1 -0
- package/dist/utils/validation/vQueryEmailArray.js +29 -0
- package/dist/utils/validation/vQueryEmailArray.js.map +1 -0
- package/dist/utils/validation/vQueryNumberArray.d.ts +10 -0
- package/dist/utils/validation/vQueryNumberArray.d.ts.map +1 -0
- package/dist/utils/validation/vQueryNumberArray.js +32 -0
- package/dist/utils/validation/vQueryNumberArray.js.map +1 -0
- package/dist/utils/validation/vQueryStringifiedEnumArray.d.ts +3 -0
- package/dist/utils/validation/vQueryStringifiedEnumArray.d.ts.map +1 -0
- package/dist/utils/validation/vQueryStringifiedEnumArray.js +25 -0
- package/dist/utils/validation/vQueryStringifiedEnumArray.js.map +1 -0
- package/dist/utils/validation/vQueryUuidArray.d.ts +9 -0
- package/dist/utils/validation/vQueryUuidArray.d.ts.map +1 -0
- package/dist/utils/validation/vQueryUuidArray.js +27 -0
- package/dist/utils/validation/vQueryUuidArray.js.map +1 -0
- package/package.json +19 -3
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Original library: hookified (v1.15.1)
|
|
3
|
+
* - Copyright (c) Jared Wray
|
|
4
|
+
*
|
|
5
|
+
* Modified and integrated in "Inray":
|
|
6
|
+
* - Evgeniy Bushin
|
|
7
|
+
*/
|
|
8
|
+
/***/
|
|
9
|
+
export type Logger = {
|
|
10
|
+
trace: (message: string, ...arguments_: unknown[]) => void;
|
|
11
|
+
debug: (message: string, ...arguments_: unknown[]) => void;
|
|
12
|
+
info: (message: string, ...arguments_: unknown[]) => void;
|
|
13
|
+
warn: (message: string, ...arguments_: unknown[]) => void;
|
|
14
|
+
error: (message: string, ...arguments_: unknown[]) => void;
|
|
15
|
+
fatal: (message: string, ...arguments_: unknown[]) => void;
|
|
16
|
+
};
|
|
17
|
+
export type EventEmitterOptions = {
|
|
18
|
+
/**
|
|
19
|
+
* Logger instance for logging errors.
|
|
20
|
+
*/
|
|
21
|
+
logger?: Logger;
|
|
22
|
+
/**
|
|
23
|
+
* Whether to throw an error when emit 'error' and there are no listeners. Default is false and only emits an error event.
|
|
24
|
+
*/
|
|
25
|
+
throwOnEmitError?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Whether to throw on 'error' when there are no listeners. This is the standard functionality in EventEmitter
|
|
28
|
+
* @default false - in v2 this will be set to true by default
|
|
29
|
+
*/
|
|
30
|
+
throwOnEmptyListeners?: boolean;
|
|
31
|
+
};
|
|
32
|
+
export type IEventEmitter = {
|
|
33
|
+
/**
|
|
34
|
+
* Registers a listener for the specified event.
|
|
35
|
+
*
|
|
36
|
+
* @param eventName - The name (or symbol) of the event to listen for.
|
|
37
|
+
* @param listener - A callback function that will be invoked when the event is emitted.
|
|
38
|
+
* @returns The current instance of EventEmitter for method chaining.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* emitter.on('data', (message) => {
|
|
42
|
+
* console.log(message);
|
|
43
|
+
* });
|
|
44
|
+
*/
|
|
45
|
+
on(eventName: string | symbol, listener: (...arguments_: any[]) => void): IEventEmitter;
|
|
46
|
+
/**
|
|
47
|
+
* Alias for `on`. Registers a listener for the specified event.
|
|
48
|
+
*
|
|
49
|
+
* @param eventName - The name (or symbol) of the event to listen for.
|
|
50
|
+
* @param listener - A callback function that will be invoked when the event is emitted.
|
|
51
|
+
* @returns The current instance of EventEmitter for method chaining.
|
|
52
|
+
*/
|
|
53
|
+
addListener(eventName: string | symbol, listener: (...arguments_: any[]) => void): IEventEmitter;
|
|
54
|
+
/**
|
|
55
|
+
* Registers a one-time listener for the specified event. The listener is removed after it is called once.
|
|
56
|
+
*
|
|
57
|
+
* @param eventName - The name (or symbol) of the event to listen for.
|
|
58
|
+
* @param listener - A callback function that will be invoked once when the event is emitted.
|
|
59
|
+
* @returns The current instance of EventEmitter for method chaining.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* emitter.once('close', () => {
|
|
63
|
+
* console.log('The connection was closed.');
|
|
64
|
+
* });
|
|
65
|
+
*/
|
|
66
|
+
once(eventName: string | symbol, listener: (...arguments_: any[]) => void): IEventEmitter;
|
|
67
|
+
/**
|
|
68
|
+
* Removes a previously registered listener for the specified event.
|
|
69
|
+
*
|
|
70
|
+
* @param eventName - The name (or symbol) of the event to stop listening for.
|
|
71
|
+
* @param listener - The specific callback function to remove.
|
|
72
|
+
* @returns The current instance of EventEmitter for method chaining.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* emitter.off('data', myListener);
|
|
76
|
+
*/
|
|
77
|
+
off(eventName: string | symbol, listener: (...arguments_: any[]) => void): IEventEmitter;
|
|
78
|
+
/**
|
|
79
|
+
* Alias for `off`. Removes a previously registered listener for the specified event.
|
|
80
|
+
*
|
|
81
|
+
* @param eventName - The name (or symbol) of the event to stop listening for.
|
|
82
|
+
* @param listener - The specific callback function to remove.
|
|
83
|
+
* @returns The current instance of EventEmitter for method chaining.
|
|
84
|
+
*/
|
|
85
|
+
removeListener(eventName: string | symbol, listener: (...arguments_: any[]) => void): IEventEmitter;
|
|
86
|
+
/**
|
|
87
|
+
* Emits the specified event, invoking all registered listeners with the provided arguments.
|
|
88
|
+
*
|
|
89
|
+
* @param eventName - The name (or symbol) of the event to emit.
|
|
90
|
+
* @param args - Arguments passed to each listener.
|
|
91
|
+
* @returns `true` if the event had listeners, `false` otherwise.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* emitter.emit('data', 'Hello World');
|
|
95
|
+
*/
|
|
96
|
+
emit(eventName: string | symbol, ...arguments_: any[]): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Returns the number of listeners registered for the specified event.
|
|
99
|
+
*
|
|
100
|
+
* @param eventName - The name (or symbol) of the event.
|
|
101
|
+
* @returns The number of registered listeners.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* const count = emitter.listenerCount('data');
|
|
105
|
+
* console.log(count); // e.g., 2
|
|
106
|
+
*/
|
|
107
|
+
listenerCount(eventName: string | symbol): number;
|
|
108
|
+
/**
|
|
109
|
+
* Removes all listeners for the specified event. If no event is specified, it removes all listeners for all events.
|
|
110
|
+
*
|
|
111
|
+
* @param eventName - (Optional) The name (or symbol) of the event.
|
|
112
|
+
* @returns The current instance of EventEmitter for method chaining.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* emitter.removeAllListeners('data');
|
|
116
|
+
*/
|
|
117
|
+
removeAllListeners(eventName?: string | symbol): IEventEmitter;
|
|
118
|
+
/**
|
|
119
|
+
* Returns an array of event names for which listeners have been registered.
|
|
120
|
+
*
|
|
121
|
+
* @returns An array of event names (or symbols).
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* const events = emitter.eventNames();
|
|
125
|
+
* console.log(events); // e.g., ['data', 'close']
|
|
126
|
+
*/
|
|
127
|
+
eventNames(): Array<string | symbol>;
|
|
128
|
+
/**
|
|
129
|
+
* Returns an array of listeners registered for the specified event.
|
|
130
|
+
*
|
|
131
|
+
* @param eventName - The name (or symbol) of the event.
|
|
132
|
+
* @returns An array of listener functions.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* const listeners = emitter.listeners('data');
|
|
136
|
+
* console.log(listeners.length); // e.g., 2
|
|
137
|
+
*/
|
|
138
|
+
listeners(eventName: string | symbol): Array<(...arguments_: any[]) => void>;
|
|
139
|
+
/**
|
|
140
|
+
* Returns an array of raw listeners for the specified event. This includes listeners wrapped by internal mechanisms (e.g., once-only listeners).
|
|
141
|
+
*
|
|
142
|
+
* @param eventName - The name (or symbol) of the event.
|
|
143
|
+
* @returns An array of raw listener functions.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* const rawListeners = emitter.rawListeners('data');
|
|
147
|
+
*/
|
|
148
|
+
rawListeners(eventName: string | symbol): Array<(...arguments_: any[]) => void>;
|
|
149
|
+
/**
|
|
150
|
+
* Adds a listener to the beginning of the listeners array for the specified event.
|
|
151
|
+
*
|
|
152
|
+
* @param eventName - The name (or symbol) of the event to listen for.
|
|
153
|
+
* @param listener - A callback function that will be invoked when the event is emitted.
|
|
154
|
+
* @returns The current instance of EventEmitter for method chaining.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* emitter.prependListener('data', (message) => {
|
|
158
|
+
* console.log('This will run first.');
|
|
159
|
+
* });
|
|
160
|
+
*/
|
|
161
|
+
prependListener(eventName: string | symbol, listener: (...arguments_: any[]) => void): IEventEmitter;
|
|
162
|
+
/**
|
|
163
|
+
* Adds a one-time listener to the beginning of the listeners array for the specified event.
|
|
164
|
+
*
|
|
165
|
+
* @param eventName - The name (or symbol) of the event to listen for.
|
|
166
|
+
* @param listener - A callback function that will be invoked once when the event is emitted.
|
|
167
|
+
* @returns The current instance of EventEmitter for method chaining.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* emitter.prependOnceListener('data', (message) => {
|
|
171
|
+
* console.log('This will run first and only once.');
|
|
172
|
+
* });
|
|
173
|
+
*/
|
|
174
|
+
prependOnceListener(eventName: string | symbol, listener: (...arguments_: any[]) => void): IEventEmitter;
|
|
175
|
+
};
|
|
176
|
+
export type EventListener = (...arguments_: any[]) => void;
|
|
177
|
+
export type Hook = (...arguments_: any[]) => Promise<void> | void;
|
|
178
|
+
export type HookEntry = {
|
|
179
|
+
/**
|
|
180
|
+
* The event name for the hook
|
|
181
|
+
*/
|
|
182
|
+
event: string;
|
|
183
|
+
/**
|
|
184
|
+
* The handler function for the hook
|
|
185
|
+
*/
|
|
186
|
+
handler: Hook;
|
|
187
|
+
};
|
|
188
|
+
export type HookifiedOptions = {
|
|
189
|
+
/**
|
|
190
|
+
* Whether an error should be thrown when a hook throws an error. Default is false and only emits an error event.
|
|
191
|
+
* @deprecated - this will be deprecated in version 2. Please use throwOnHookError.
|
|
192
|
+
*/
|
|
193
|
+
throwHookErrors?: boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Whether an error should be thrown when a hook throws an error. Default is false and only emits an error event.
|
|
196
|
+
*/
|
|
197
|
+
throwOnHookError?: boolean;
|
|
198
|
+
/**
|
|
199
|
+
* Whether to enforce that all hook names start with 'before' or 'after'. Default is false.
|
|
200
|
+
* @type {boolean}
|
|
201
|
+
* @default false
|
|
202
|
+
*/
|
|
203
|
+
enforceBeforeAfter?: boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Map of deprecated hook names to deprecation messages. When a deprecated hook is used, a warning will be emitted.
|
|
206
|
+
* @type {Map<string, string>}
|
|
207
|
+
* @default new Map()
|
|
208
|
+
*/
|
|
209
|
+
deprecatedHooks?: Map<string, string>;
|
|
210
|
+
/**
|
|
211
|
+
* Whether to allow deprecated hooks to be registered and executed. Default is true.
|
|
212
|
+
* @type {boolean}
|
|
213
|
+
* @default true
|
|
214
|
+
*/
|
|
215
|
+
allowDeprecated?: boolean;
|
|
216
|
+
} & EventEmitterOptions;
|
|
217
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/caching/src/hashing/hooks/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;AAEL,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAC3D,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAC3D,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAC1D,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAC1D,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAC3D,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;CAC5D,CAAC;AAEF,MAAM,MAAM,mB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BAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;OAIG;IACH,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,GAAG,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/caching/src/hashing/hooks/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK"}
|
|
@@ -0,0 +1,236 @@
|
|
|
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 { Hookified } from './hooks/index.ts';
|
|
10
|
+
import { Cache } from './cache.ts';
|
|
11
|
+
import { HashProviders } from './providers.ts';
|
|
12
|
+
import type { HasheryLoadProviderOptions, HasheryOptions, HasheryToHashOptions, HasheryToHashSyncOptions, HasheryToNumberOptions, HasheryToNumberSyncOptions, HashProvider, ParseFn, StringifyFn } from './types.js';
|
|
13
|
+
export declare class Hashery extends Hookified {
|
|
14
|
+
private _parse;
|
|
15
|
+
private _stringify;
|
|
16
|
+
private _providers;
|
|
17
|
+
private _defaultAlgorithm;
|
|
18
|
+
private _defaultAlgorithmSync;
|
|
19
|
+
private _cache;
|
|
20
|
+
constructor(options?: HasheryOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Gets the parse function used to deserialize stored values.
|
|
23
|
+
* @returns The current parse function (defaults to JSON.parse)
|
|
24
|
+
*/
|
|
25
|
+
get parse(): ParseFn;
|
|
26
|
+
/**
|
|
27
|
+
* Sets the parse function used to deserialize stored values.
|
|
28
|
+
* @param value - The parse function to use for deserialization
|
|
29
|
+
*/
|
|
30
|
+
set parse(value: ParseFn);
|
|
31
|
+
/**
|
|
32
|
+
* Gets the stringify function used to serialize values for storage.
|
|
33
|
+
* @returns The current stringify function (defaults to JSON.stringify)
|
|
34
|
+
*/
|
|
35
|
+
get stringify(): StringifyFn;
|
|
36
|
+
/**
|
|
37
|
+
* Sets the stringify function used to serialize values for storage.
|
|
38
|
+
* @param value - The stringify function to use for serialization
|
|
39
|
+
*/
|
|
40
|
+
set stringify(value: StringifyFn);
|
|
41
|
+
/**
|
|
42
|
+
* Gets the HashProviders instance used to manage hash providers.
|
|
43
|
+
* @returns The current HashProviders instance
|
|
44
|
+
*/
|
|
45
|
+
get providers(): HashProviders;
|
|
46
|
+
/**
|
|
47
|
+
* Sets the HashProviders instance used to manage hash providers.
|
|
48
|
+
* @param value - The HashProviders instance to use
|
|
49
|
+
*/
|
|
50
|
+
set providers(value: HashProviders);
|
|
51
|
+
/**
|
|
52
|
+
* Gets the names of all registered hash algorithm providers.
|
|
53
|
+
* @returns An array of provider names (e.g., ['SHA-256', 'SHA-384', 'SHA-512'])
|
|
54
|
+
*/
|
|
55
|
+
get names(): Array<string>;
|
|
56
|
+
/**
|
|
57
|
+
* Gets the default hash algorithm used when none is specified.
|
|
58
|
+
* @returns The current default algorithm (defaults to 'SHA-256')
|
|
59
|
+
*/
|
|
60
|
+
get defaultAlgorithm(): string;
|
|
61
|
+
/**
|
|
62
|
+
* Sets the default hash algorithm to use when none is specified.
|
|
63
|
+
* @param value - The default algorithm to use (e.g., 'SHA-256', 'SHA-512', 'djb2')
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* const hashery = new Hashery();
|
|
67
|
+
* hashery.defaultAlgorithm = 'SHA-512';
|
|
68
|
+
*
|
|
69
|
+
* // Now toHash will use SHA-512 by default
|
|
70
|
+
* const hash = await hashery.toHash({ data: 'example' });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
set defaultAlgorithm(value: string);
|
|
74
|
+
/**
|
|
75
|
+
* Gets the default synchronous hash algorithm used when none is specified.
|
|
76
|
+
* @returns The current default synchronous algorithm (defaults to 'djb2')
|
|
77
|
+
*/
|
|
78
|
+
get defaultAlgorithmSync(): string;
|
|
79
|
+
/**
|
|
80
|
+
* Sets the default synchronous hash algorithm to use when none is specified.
|
|
81
|
+
* @param value - The default synchronous algorithm to use (e.g., 'djb2', 'fnv1', 'murmur', 'crc32')
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* const hashery = new Hashery();
|
|
85
|
+
* hashery.defaultAlgorithmSync = 'fnv1';
|
|
86
|
+
*
|
|
87
|
+
* // Now synchronous operations will use fnv1 by default
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
set defaultAlgorithmSync(value: string);
|
|
91
|
+
/**
|
|
92
|
+
* Gets the cache instance used to store computed hash values.
|
|
93
|
+
* @returns The Cache instance
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* const hashery = new Hashery({ cache: { enabled: true } });
|
|
97
|
+
*
|
|
98
|
+
* // Access the cache
|
|
99
|
+
* hashery.cache.enabled; // true
|
|
100
|
+
* hashery.cache.size; // number of cached items
|
|
101
|
+
* hashery.cache.clear(); // clear all cached items
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
get cache(): Cache;
|
|
105
|
+
/**
|
|
106
|
+
* Generates a cryptographic hash of the provided data using the Web Crypto API.
|
|
107
|
+
* The data is first stringified using the configured stringify function, then hashed.
|
|
108
|
+
*
|
|
109
|
+
* If an invalid algorithm is provided, a 'warn' event is emitted and the method falls back
|
|
110
|
+
* to the default algorithm. You can listen to these warnings:
|
|
111
|
+
* ```ts
|
|
112
|
+
* hashery.on('warn', (message) => console.log(message));
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @param data - The data to hash (will be stringified before hashing)
|
|
116
|
+
* @param options - Optional configuration object
|
|
117
|
+
* @param options.algorithm - The hash algorithm to use (defaults to 'SHA-256')
|
|
118
|
+
* @param options.maxLength - Optional maximum length for the hash output
|
|
119
|
+
* @returns A Promise that resolves to the hexadecimal string representation of the hash
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* const hashery = new Hashery();
|
|
124
|
+
* const hash = await hashery.toHash({ name: 'John', age: 30 });
|
|
125
|
+
* console.log(hash); // "a1b2c3d4..."
|
|
126
|
+
*
|
|
127
|
+
* // Using a different algorithm
|
|
128
|
+
* const hash512 = await hashery.toHash({ name: 'John' }, { algorithm: 'SHA-512' });
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
toHash(data: unknown, options?: HasheryToHashOptions): Promise<string>;
|
|
132
|
+
/**
|
|
133
|
+
* Generates a deterministic number within a specified range based on the hash of the provided data.
|
|
134
|
+
* This method uses the toHash function to create a consistent hash, then maps it to a number
|
|
135
|
+
* between min and max (inclusive).
|
|
136
|
+
*
|
|
137
|
+
* @param data - The data to hash (will be stringified before hashing)
|
|
138
|
+
* @param options - Configuration options (optional, defaults to min: 0, max: 100)
|
|
139
|
+
* @param options.min - The minimum value of the range (inclusive, defaults to 0)
|
|
140
|
+
* @param options.max - The maximum value of the range (inclusive, defaults to 100)
|
|
141
|
+
* @param options.algorithm - The hash algorithm to use (defaults to 'SHA-256')
|
|
142
|
+
* @param options.hashLength - Number of characters from hash to use for conversion (defaults to 16)
|
|
143
|
+
* @returns A Promise that resolves to a number between min and max (inclusive)
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* const hashery = new Hashery();
|
|
148
|
+
* const num = await hashery.toNumber({ user: 'john' }); // Uses default min: 0, max: 100
|
|
149
|
+
* console.log(num); // Always returns the same number for the same input, e.g., 42
|
|
150
|
+
*
|
|
151
|
+
* // Using custom range
|
|
152
|
+
* const num2 = await hashery.toNumber({ user: 'john' }, { min: 1, max: 100 });
|
|
153
|
+
*
|
|
154
|
+
* // Using a different algorithm
|
|
155
|
+
* const num512 = await hashery.toNumber({ user: 'john' }, { min: 0, max: 255, algorithm: 'SHA-512' });
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
toNumber(data: unknown, options?: HasheryToNumberOptions): Promise<number>;
|
|
159
|
+
/**
|
|
160
|
+
* Generates a hash of the provided data synchronously using a non-cryptographic hash algorithm.
|
|
161
|
+
* The data is first stringified using the configured stringify function, then hashed.
|
|
162
|
+
*
|
|
163
|
+
* Note: This method only works with synchronous hash providers (djb2, fnv1, murmur, crc32).
|
|
164
|
+
* WebCrypto algorithms (SHA-256, SHA-384, SHA-512) are not supported and will throw an error.
|
|
165
|
+
*
|
|
166
|
+
* If an invalid algorithm is provided, a 'warn' event is emitted and the method falls back
|
|
167
|
+
* to the default synchronous algorithm. You can listen to these warnings:
|
|
168
|
+
* ```ts
|
|
169
|
+
* hashery.on('warn', (message) => console.log(message));
|
|
170
|
+
* ```
|
|
171
|
+
*
|
|
172
|
+
* @param data - The data to hash (will be stringified before hashing)
|
|
173
|
+
* @param options - Optional configuration object
|
|
174
|
+
* @param options.algorithm - The hash algorithm to use (defaults to 'djb2')
|
|
175
|
+
* @param options.maxLength - Optional maximum length for the hash output
|
|
176
|
+
* @returns The hexadecimal string representation of the hash
|
|
177
|
+
*
|
|
178
|
+
* @throws {Error} If the specified algorithm does not support synchronous hashing
|
|
179
|
+
* @throws {Error} If the default algorithm is not found
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* const hashery = new Hashery();
|
|
184
|
+
* const hash = hashery.toHashSync({ name: 'John', age: 30 });
|
|
185
|
+
* console.log(hash); // "7c9df5ea..." (djb2 hash)
|
|
186
|
+
*
|
|
187
|
+
* // Using a different algorithm
|
|
188
|
+
* const hashFnv1 = hashery.toHashSync({ name: 'John' }, { algorithm: 'fnv1' });
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
toHashSync(data: unknown, options?: HasheryToHashSyncOptions): string;
|
|
192
|
+
/**
|
|
193
|
+
* Generates a deterministic number within a specified range based on the hash of the provided data synchronously.
|
|
194
|
+
* This method uses the toHashSync function to create a consistent hash, then maps it to a number
|
|
195
|
+
* between min and max (inclusive).
|
|
196
|
+
*
|
|
197
|
+
* Note: This method only works with synchronous hash providers (djb2, fnv1, murmur, crc32).
|
|
198
|
+
*
|
|
199
|
+
* @param data - The data to hash (will be stringified before hashing)
|
|
200
|
+
* @param options - Configuration options (optional, defaults to min: 0, max: 100)
|
|
201
|
+
* @param options.min - The minimum value of the range (inclusive, defaults to 0)
|
|
202
|
+
* @param options.max - The maximum value of the range (inclusive, defaults to 100)
|
|
203
|
+
* @param options.algorithm - The hash algorithm to use (defaults to 'djb2')
|
|
204
|
+
* @param options.hashLength - Number of characters from hash to use for conversion (defaults to 16)
|
|
205
|
+
* @returns A number between min and max (inclusive)
|
|
206
|
+
*
|
|
207
|
+
* @throws {Error} If the specified algorithm does not support synchronous hashing
|
|
208
|
+
* @throws {Error} If min is greater than max
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```ts
|
|
212
|
+
* const hashery = new Hashery();
|
|
213
|
+
* const num = hashery.toNumberSync({ user: 'john' }); // Uses default min: 0, max: 100
|
|
214
|
+
* console.log(num); // Always returns the same number for the same input, e.g., 42
|
|
215
|
+
*
|
|
216
|
+
* // Using custom range
|
|
217
|
+
* const num2 = hashery.toNumberSync({ user: 'john' }, { min: 1, max: 100 });
|
|
218
|
+
*
|
|
219
|
+
* // Using a different algorithm
|
|
220
|
+
* const numFnv1 = hashery.toNumberSync({ user: 'john' }, { min: 0, max: 255, algorithm: 'fnv1' });
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
toNumberSync(data: unknown, options?: HasheryToNumberSyncOptions): number;
|
|
224
|
+
loadProviders(providers?: Array<HashProvider>, options?: HasheryLoadProviderOptions): void;
|
|
225
|
+
}
|
|
226
|
+
export type { CacheOptions } from './cache.js';
|
|
227
|
+
export { Cache } from './cache.js';
|
|
228
|
+
export { CRC } from './providers/crc.js';
|
|
229
|
+
export type { WebCryptoOptions } from './providers/crypto.js';
|
|
230
|
+
export { WebCrypto } from './providers/crypto.js';
|
|
231
|
+
export { DJB2 } from './providers/djb2.js';
|
|
232
|
+
export { FNV1 } from './providers/fnv1.js';
|
|
233
|
+
export { Murmur } from './providers/murmur.js';
|
|
234
|
+
export { HashProviders } from './providers.js';
|
|
235
|
+
export type { HashAlgorithm, HasheryLoadProviderOptions, HasheryOptions, HasheryToHashOptions, HasheryToHashSyncOptions, HasheryToNumberOptions, HasheryToNumberSyncOptions, HashProvider, HashProvidersGetOptions, HashProvidersOptions, ParseFn, StringifyFn, WebCryptoHashAlgorithm } from './types.js';
|
|
236
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/caching/src/hashing/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,KAAK;AAEL,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAMnC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EACV,0BAA0B,EAC1B,cAAc,EACd,oBAAoB,EACpB,wBAAwB,EACxB,sBAAsB,EACtB,0BAA0B,EAC1B,YAAY,EACZ,OAAO,EACP,WAAW,EAEZ,MAAM,YAAY,CAAC;AAEpB,qBAAa,OAAQ,SAAQ,SAAS;IACpC,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,UAAU,CAA+B;IACjD,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,iBAAiB,CAAqB;IAC9C,OAAO,CAAC,qBAAqB,CAAkB;IAC/C,OAAO,CAAC,MAAM,CAAQ;gBAEV,OAAO,CAAC,EAAE,cAAc;IA0BpC;;;OAGG;IACH,IAAW,KAAK,IAAI,OAAO,CAE1B;IAED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