@andrew_l/toolkit 0.2.8 → 0.2.10
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/dist/index.cjs +851 -714
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +301 -158
- package/dist/index.d.mts +301 -158
- package/dist/index.d.ts +301 -158
- package/dist/index.mjs +849 -715
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -350,7 +350,7 @@ declare function weightedRoundRobin<T = unknown>(arr: WrrItem<T>[]): () => T;
|
|
|
350
350
|
|
|
351
351
|
declare function ok(value: unknown, message?: string | Error): asserts value;
|
|
352
352
|
declare function equal<T>(actual: unknown, expected: T, message?: string | Error): asserts actual is T;
|
|
353
|
-
declare function
|
|
353
|
+
declare function notEmpty(value: unknown, message?: string | Error): asserts value;
|
|
354
354
|
declare function object(value: unknown, message?: string | Error): asserts value is object;
|
|
355
355
|
declare function string(value: unknown, message?: string | Error): asserts value is string;
|
|
356
356
|
declare function boolean(value: unknown, message?: string | Error): asserts value is boolean;
|
|
@@ -360,11 +360,6 @@ declare function date(value: unknown, message?: string | Error): asserts value i
|
|
|
360
360
|
declare function fn(value: unknown, message?: string | Error): asserts value is Function;
|
|
361
361
|
declare function greaterThan(value: unknown, target: number, message?: string | Error): asserts value is number;
|
|
362
362
|
declare function lessThan(value: unknown, target: number, message?: string | Error): asserts value is number;
|
|
363
|
-
/**
|
|
364
|
-
* @param {unknown} value
|
|
365
|
-
* @param {string | Error} [message]
|
|
366
|
-
* @return {asserts value is Array}
|
|
367
|
-
*/
|
|
368
363
|
declare function array(value: unknown, message?: string | Error): asserts value is unknown[];
|
|
369
364
|
declare function arrayStrings(value: unknown, message?: string | Error): asserts value is string[];
|
|
370
365
|
declare function arrayNumbers(value: unknown, message?: string | Error): asserts value is number[];
|
|
@@ -374,18 +369,18 @@ declare const assert_arrayNumbers: typeof arrayNumbers;
|
|
|
374
369
|
declare const assert_arrayStrings: typeof arrayStrings;
|
|
375
370
|
declare const assert_boolean: typeof boolean;
|
|
376
371
|
declare const assert_date: typeof date;
|
|
377
|
-
declare const assert_empty: typeof empty;
|
|
378
372
|
declare const assert_equal: typeof equal;
|
|
379
373
|
declare const assert_fn: typeof fn;
|
|
380
374
|
declare const assert_greaterThan: typeof greaterThan;
|
|
381
375
|
declare const assert_lessThan: typeof lessThan;
|
|
376
|
+
declare const assert_notEmpty: typeof notEmpty;
|
|
382
377
|
declare const assert_notEmptyString: typeof notEmptyString;
|
|
383
378
|
declare const assert_number: typeof number;
|
|
384
379
|
declare const assert_object: typeof object;
|
|
385
380
|
declare const assert_ok: typeof ok;
|
|
386
381
|
declare const assert_string: typeof string;
|
|
387
382
|
declare namespace assert {
|
|
388
|
-
export { assert_array as array, assert_arrayNumbers as arrayNumbers, assert_arrayStrings as arrayStrings, assert_boolean as boolean, assert_date as date,
|
|
383
|
+
export { assert_array as array, assert_arrayNumbers as arrayNumbers, assert_arrayStrings as arrayStrings, assert_boolean as boolean, assert_date as date, assert_equal as equal, assert_fn as fn, assert_greaterThan as greaterThan, assert_lessThan as lessThan, assert_notEmpty as notEmpty, assert_notEmptyString as notEmptyString, assert_number as number, assert_object as object, assert_ok as ok, assert_string as string };
|
|
389
384
|
}
|
|
390
385
|
|
|
391
386
|
type Base64ToBytesOptions = {
|
|
@@ -2517,17 +2512,30 @@ declare const env: Readonly<EnvParser>;
|
|
|
2517
2512
|
*/
|
|
2518
2513
|
declare function createEnvParser(targetObject: Record<string, string> | Dict<string>): Readonly<EnvParser>;
|
|
2519
2514
|
|
|
2515
|
+
interface AppErrorOptions extends ErrorOptions {
|
|
2516
|
+
/**
|
|
2517
|
+
* Custom error code
|
|
2518
|
+
*/
|
|
2519
|
+
code?: string;
|
|
2520
|
+
}
|
|
2520
2521
|
/**
|
|
2521
2522
|
* Simple application error class with the code
|
|
2522
2523
|
* @group Errors
|
|
2523
2524
|
*/
|
|
2524
2525
|
declare class AppError extends Error {
|
|
2525
|
-
code: number;
|
|
2526
|
-
constructor(messageOrCode: string | number, code?: number, options?: ErrorOptions);
|
|
2527
2526
|
/**
|
|
2528
|
-
*
|
|
2527
|
+
* HTTP valid status code
|
|
2529
2528
|
*/
|
|
2530
|
-
|
|
2529
|
+
statusCode: number;
|
|
2530
|
+
/**
|
|
2531
|
+
* Custom error code
|
|
2532
|
+
*/
|
|
2533
|
+
code?: string;
|
|
2534
|
+
constructor(message: string, statusCode?: number, options?: AppErrorOptions);
|
|
2535
|
+
/**
|
|
2536
|
+
* Message will be generated from status code
|
|
2537
|
+
*/
|
|
2538
|
+
constructor(statusCode: number, options?: AppErrorOptions);
|
|
2531
2539
|
get name(): string;
|
|
2532
2540
|
static is(value: any): value is AppError;
|
|
2533
2541
|
}
|
|
@@ -2571,15 +2579,6 @@ declare class BrowserAssertionError extends Error {
|
|
|
2571
2579
|
});
|
|
2572
2580
|
}
|
|
2573
2581
|
|
|
2574
|
-
/**
|
|
2575
|
-
* @group Utility Functions
|
|
2576
|
-
*/
|
|
2577
|
-
declare function isSuccess<T extends ExecResult>(value: T): value is ExecResultToSuccess<T>;
|
|
2578
|
-
/**
|
|
2579
|
-
* @group Utility Functions
|
|
2580
|
-
*/
|
|
2581
|
-
declare function isSkip<T extends ExecResult>(value: T): value is ExecResultToSkip<T>;
|
|
2582
|
-
|
|
2583
2582
|
/**
|
|
2584
2583
|
* Extract file extension from string
|
|
2585
2584
|
*
|
|
@@ -2632,6 +2631,279 @@ declare function getMostSpecificPaths(keys: string[]): string[];
|
|
|
2632
2631
|
*/
|
|
2633
2632
|
declare function humanFileSize(bytes: number, digits?: number, withSpace?: boolean): string;
|
|
2634
2633
|
|
|
2634
|
+
interface DebounceOptions {
|
|
2635
|
+
/**
|
|
2636
|
+
* An optional AbortSignal to cancel the debounced function.
|
|
2637
|
+
*/
|
|
2638
|
+
signal?: AbortSignal;
|
|
2639
|
+
/**
|
|
2640
|
+
* An optional array specifying whether the function should be invoked on the leading edge, trailing edge, or both.
|
|
2641
|
+
* If `edges` includes "leading", the function will be invoked at the start of the delay period.
|
|
2642
|
+
* If `edges` includes "trailing", the function will be invoked at the end of the delay period.
|
|
2643
|
+
* If both "leading" and "trailing" are included, the function will be invoked at both the start and end of the delay period.
|
|
2644
|
+
* @default ["trailing"]
|
|
2645
|
+
*/
|
|
2646
|
+
edges?: Array<'leading' | 'trailing'>;
|
|
2647
|
+
}
|
|
2648
|
+
interface DebouncedFunction<F extends (...args: any[]) => void> {
|
|
2649
|
+
(...args: Parameters<F>): void;
|
|
2650
|
+
/**
|
|
2651
|
+
* Schedules the execution of the debounced function after the specified debounce delay.
|
|
2652
|
+
* This method resets any existing timer, ensuring that the function is only invoked
|
|
2653
|
+
* after the delay has elapsed since the last call to the debounced function.
|
|
2654
|
+
* It is typically called internally whenever the debounced function is invoked.
|
|
2655
|
+
*
|
|
2656
|
+
* @returns {void}
|
|
2657
|
+
*/
|
|
2658
|
+
schedule: () => void;
|
|
2659
|
+
/**
|
|
2660
|
+
* Cancels any pending execution of the debounced function.
|
|
2661
|
+
* This method clears the active timer and resets any stored context or arguments.
|
|
2662
|
+
*/
|
|
2663
|
+
cancel: () => void;
|
|
2664
|
+
/**
|
|
2665
|
+
* Immediately invokes the debounced function if there is a pending execution.
|
|
2666
|
+
* This method also cancels the current timer, ensuring that the function executes right away.
|
|
2667
|
+
*/
|
|
2668
|
+
flush: () => void;
|
|
2669
|
+
}
|
|
2670
|
+
/**
|
|
2671
|
+
* Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds
|
|
2672
|
+
* have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`
|
|
2673
|
+
* method to cancel any pending execution.
|
|
2674
|
+
*
|
|
2675
|
+
* @template F - The type of function.
|
|
2676
|
+
* @param {F} func - The function to debounce.
|
|
2677
|
+
* @param {number} debounceMs - The number of milliseconds to delay.
|
|
2678
|
+
* @param {DebounceOptions} options - The options object
|
|
2679
|
+
* @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.
|
|
2680
|
+
* @returns A new debounced function with a `cancel` method.
|
|
2681
|
+
*
|
|
2682
|
+
* @example
|
|
2683
|
+
* const debouncedFunction = debounce(() => {
|
|
2684
|
+
* console.log('Function executed');
|
|
2685
|
+
* }, 1000);
|
|
2686
|
+
*
|
|
2687
|
+
* // Will log 'Function executed' after 1 second if not called again in that time
|
|
2688
|
+
* debouncedFunction();
|
|
2689
|
+
*
|
|
2690
|
+
* // Will not log anything as the previous call is canceled
|
|
2691
|
+
* debouncedFunction.cancel();
|
|
2692
|
+
*
|
|
2693
|
+
* // With AbortSignal
|
|
2694
|
+
* const controller = new AbortController();
|
|
2695
|
+
* const signal = controller.signal;
|
|
2696
|
+
* const debouncedWithSignal = debounce(() => {
|
|
2697
|
+
* console.log('Function executed');
|
|
2698
|
+
* }, 1000, { signal });
|
|
2699
|
+
*
|
|
2700
|
+
* debouncedWithSignal();
|
|
2701
|
+
*
|
|
2702
|
+
* // Will cancel the debounced function call
|
|
2703
|
+
* controller.abort();
|
|
2704
|
+
*
|
|
2705
|
+
* @author es-toolkit
|
|
2706
|
+
* @group Utility Functions
|
|
2707
|
+
*/
|
|
2708
|
+
declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number, { signal, edges }?: DebounceOptions): DebouncedFunction<F>;
|
|
2709
|
+
|
|
2710
|
+
/**
|
|
2711
|
+
* @group Utility Functions
|
|
2712
|
+
*/
|
|
2713
|
+
declare function isSuccess<T extends ExecResult>(value: T): value is ExecResultToSuccess<T>;
|
|
2714
|
+
/**
|
|
2715
|
+
* @group Utility Functions
|
|
2716
|
+
*/
|
|
2717
|
+
declare function isSkip<T extends ExecResult>(value: T): value is ExecResultToSkip<T>;
|
|
2718
|
+
|
|
2719
|
+
type TypeOf = keyof TypeOfMap;
|
|
2720
|
+
type TypeOfMap = {
|
|
2721
|
+
null: null;
|
|
2722
|
+
undefined: undefined;
|
|
2723
|
+
object: Record<PropertyKey, any>;
|
|
2724
|
+
string: string;
|
|
2725
|
+
number: number;
|
|
2726
|
+
function: AnyFunction;
|
|
2727
|
+
bigint: bigint;
|
|
2728
|
+
boolean: boolean;
|
|
2729
|
+
symbol: symbol;
|
|
2730
|
+
date: Date;
|
|
2731
|
+
array: any[];
|
|
2732
|
+
map: Map<any, any>;
|
|
2733
|
+
weakmap: WeakMap<WeakKey, any>;
|
|
2734
|
+
set: Set<any>;
|
|
2735
|
+
weakset: WeakSet<WeakKey>;
|
|
2736
|
+
unknown: unknown;
|
|
2737
|
+
};
|
|
2738
|
+
/**
|
|
2739
|
+
* Typeof that you deserve
|
|
2740
|
+
* @group Utility Functions
|
|
2741
|
+
*/
|
|
2742
|
+
declare function typeOf(value: unknown): TypeOf;
|
|
2743
|
+
|
|
2744
|
+
type StringifyOptions = {
|
|
2745
|
+
/**
|
|
2746
|
+
* Exclude empty values, checking by `isEmpty`
|
|
2747
|
+
* @default true
|
|
2748
|
+
*/
|
|
2749
|
+
excludeEmpty?: boolean;
|
|
2750
|
+
/**
|
|
2751
|
+
* Exclude values when equals with defaults
|
|
2752
|
+
*/
|
|
2753
|
+
excludeDefaults?: Record<string, any>;
|
|
2754
|
+
};
|
|
2755
|
+
/**
|
|
2756
|
+
* Simple query stringy interface that supports encoding/decoding of `Array`, `Set`, `Map`, `Object`, `BigInt`
|
|
2757
|
+
*
|
|
2758
|
+
* @example
|
|
2759
|
+
* // encode
|
|
2760
|
+
* qs.stringify({ page: 1, limit: 10 }); // 'page=1&limit=10'
|
|
2761
|
+
*
|
|
2762
|
+
* // decode
|
|
2763
|
+
* const defaults = { page: 1, limit: 10 };
|
|
2764
|
+
* const params = qs.parse('page=5&limit=abc', defaults); // { page: 5, limit: 10 }
|
|
2765
|
+
*
|
|
2766
|
+
* @group Utility Functions
|
|
2767
|
+
*/
|
|
2768
|
+
declare const qs: {
|
|
2769
|
+
toParams: typeof toParams;
|
|
2770
|
+
stringify: typeof stringify;
|
|
2771
|
+
stringifyValue: typeof stringifyValue;
|
|
2772
|
+
parse: typeof parse;
|
|
2773
|
+
parseValue: typeof parseValue;
|
|
2774
|
+
merge: typeof merge;
|
|
2775
|
+
};
|
|
2776
|
+
/**
|
|
2777
|
+
* Merge first level values
|
|
2778
|
+
*/
|
|
2779
|
+
declare function merge(...values: Record<string, any>[]): Record<string, any>;
|
|
2780
|
+
/**
|
|
2781
|
+
* Simple function to transform object into query string (not standards)
|
|
2782
|
+
*/
|
|
2783
|
+
declare function stringify(obj: Record<string, any>, options?: StringifyOptions): string;
|
|
2784
|
+
/**
|
|
2785
|
+
* Prepare search params object
|
|
2786
|
+
*/
|
|
2787
|
+
declare function toParams(obj: Record<string, any>, options?: StringifyOptions): Record<string, string>;
|
|
2788
|
+
/**
|
|
2789
|
+
* Parse query string as is without type casting
|
|
2790
|
+
*/
|
|
2791
|
+
declare function parse(value: string): Record<string, string>;
|
|
2792
|
+
/**
|
|
2793
|
+
* Parse query string and use default object as type cast schema
|
|
2794
|
+
*/
|
|
2795
|
+
declare function parse<T extends Record<string, any>>(value: string, defaults: Partial<T>): T;
|
|
2796
|
+
/**
|
|
2797
|
+
* Parse query params and use default object as type cast schema
|
|
2798
|
+
*/
|
|
2799
|
+
declare function parse<T extends Record<string, any>>(value: Record<string, any>, defaults: T): Partial<T>;
|
|
2800
|
+
/**
|
|
2801
|
+
* Stringify value to use as query parameter
|
|
2802
|
+
*/
|
|
2803
|
+
declare function stringifyValue(value: unknown): string;
|
|
2804
|
+
/**
|
|
2805
|
+
* Parse string query value as a type
|
|
2806
|
+
*/
|
|
2807
|
+
declare function parseValue<T extends TypeOf>(value: any, asType: T): TypeOfMap[T] | undefined;
|
|
2808
|
+
|
|
2809
|
+
type RetryOnErrorConfig = {
|
|
2810
|
+
/**
|
|
2811
|
+
* The function to execute before retry attempt; Allows to update parameters for the main function by returning then in an array
|
|
2812
|
+
*/
|
|
2813
|
+
beforeRetryCallback?: (attempt: number, lastAttempt: boolean) => Promise<unknown[] | void>;
|
|
2814
|
+
/**
|
|
2815
|
+
* Error validation function. If returns true, the main callback's considered ready to be executed again
|
|
2816
|
+
*/
|
|
2817
|
+
shouldRetryBasedOnError?: (error: unknown, attempt: number) => boolean;
|
|
2818
|
+
/**
|
|
2819
|
+
* Number of retries until the execution fails
|
|
2820
|
+
*/
|
|
2821
|
+
maxRetriesNumber: number;
|
|
2822
|
+
/**
|
|
2823
|
+
* Delay multiply factor
|
|
2824
|
+
*/
|
|
2825
|
+
delayFactor?: number;
|
|
2826
|
+
/**
|
|
2827
|
+
* Delay min milliseconds
|
|
2828
|
+
*/
|
|
2829
|
+
delayMinMs?: number;
|
|
2830
|
+
/**
|
|
2831
|
+
* Delay max milliseconds
|
|
2832
|
+
*/
|
|
2833
|
+
delayMaxMs?: number;
|
|
2834
|
+
};
|
|
2835
|
+
/**
|
|
2836
|
+
* Wraps a function with retry logic.
|
|
2837
|
+
*
|
|
2838
|
+
* @example
|
|
2839
|
+
* const fn = await retryOnError({
|
|
2840
|
+
* maxRetriesNumber: 10,
|
|
2841
|
+
* delayFactor: 2,
|
|
2842
|
+
* delayMinMs: 1000,
|
|
2843
|
+
* delayMaxMs: 3000,
|
|
2844
|
+
* shouldRetryBasedOnError(error, attemptNumber) {
|
|
2845
|
+
* return error.code !== 'RECORD_EXISTS';
|
|
2846
|
+
* }
|
|
2847
|
+
* }, async () => {
|
|
2848
|
+
* await db.transactions.insert(doc);
|
|
2849
|
+
* });
|
|
2850
|
+
*
|
|
2851
|
+
* await fn();
|
|
2852
|
+
*
|
|
2853
|
+
* @group Utility Functions
|
|
2854
|
+
*/
|
|
2855
|
+
declare function retryOnError<T extends AnyFunction>({ beforeRetryCallback, shouldRetryBasedOnError, maxRetriesNumber, delayFactor, delayMaxMs, delayMinMs, }: RetryOnErrorConfig, fn: T): (...args: Parameters<T>) => Promise<Awaited<ReturnType<T>>>;
|
|
2856
|
+
|
|
2857
|
+
interface ThrottleOptions {
|
|
2858
|
+
/**
|
|
2859
|
+
* An optional AbortSignal to cancel the debounced function.
|
|
2860
|
+
*/
|
|
2861
|
+
signal?: AbortSignal;
|
|
2862
|
+
/**
|
|
2863
|
+
* An optional array specifying whether the function should be invoked on the leading edge, trailing edge, or both.
|
|
2864
|
+
* If `edges` includes "leading", the function will be invoked at the start of the delay period.
|
|
2865
|
+
* If `edges` includes "trailing", the function will be invoked at the end of the delay period.
|
|
2866
|
+
* If both "leading" and "trailing" are included, the function will be invoked at both the start and end of the delay period.
|
|
2867
|
+
* @default ["leading", "trailing"]
|
|
2868
|
+
*/
|
|
2869
|
+
edges?: Array<'leading' | 'trailing'>;
|
|
2870
|
+
}
|
|
2871
|
+
interface ThrottledFunction<F extends (...args: any[]) => void> {
|
|
2872
|
+
(...args: Parameters<F>): void;
|
|
2873
|
+
cancel: () => void;
|
|
2874
|
+
flush: () => void;
|
|
2875
|
+
}
|
|
2876
|
+
/**
|
|
2877
|
+
* Creates a throttled function that only invokes the provided function at most once
|
|
2878
|
+
* per every `throttleMs` milliseconds. Subsequent calls to the throttled function
|
|
2879
|
+
* within the wait time will not trigger the execution of the original function.
|
|
2880
|
+
*
|
|
2881
|
+
* @template F - The type of function.
|
|
2882
|
+
* @param {F} func - The function to throttle.
|
|
2883
|
+
* @param {number} throttleMs - The number of milliseconds to throttle executions to.
|
|
2884
|
+
* @returns {(...args: Parameters<F>) => void} A new throttled function that accepts the same parameters as the original function.
|
|
2885
|
+
*
|
|
2886
|
+
* @example
|
|
2887
|
+
* const throttledFunction = throttle(() => {
|
|
2888
|
+
* console.log('Function executed');
|
|
2889
|
+
* }, 1000);
|
|
2890
|
+
*
|
|
2891
|
+
* // Will log 'Function executed' immediately
|
|
2892
|
+
* throttledFunction();
|
|
2893
|
+
*
|
|
2894
|
+
* // Will not log anything as it is within the throttle time
|
|
2895
|
+
* throttledFunction();
|
|
2896
|
+
*
|
|
2897
|
+
* // After 1 second
|
|
2898
|
+
* setTimeout(() => {
|
|
2899
|
+
* throttledFunction(); // Will log 'Function executed'
|
|
2900
|
+
* }, 1000);
|
|
2901
|
+
*
|
|
2902
|
+
* @author es-toolkit
|
|
2903
|
+
* @group Utility Functions
|
|
2904
|
+
*/
|
|
2905
|
+
declare function throttle<F extends (...args: any[]) => void>(func: F, throttleMs: number, { signal, edges }?: ThrottleOptions): ThrottledFunction<F>;
|
|
2906
|
+
|
|
2635
2907
|
/**
|
|
2636
2908
|
* Determines if the window object is available in the global scope
|
|
2637
2909
|
*
|
|
@@ -2725,6 +2997,11 @@ declare const isSymbol: (val: any) => val is Symbol;
|
|
|
2725
2997
|
* @group Predicates
|
|
2726
2998
|
*/
|
|
2727
2999
|
declare const isSet: <T = any>(val: any) => val is Set<T>;
|
|
3000
|
+
/**
|
|
3001
|
+
* Checks if the given value is a `RegExp`.
|
|
3002
|
+
* @group Predicates
|
|
3003
|
+
*/
|
|
3004
|
+
declare const isRegExp: (val: any) => val is RegExp;
|
|
2728
3005
|
/**
|
|
2729
3006
|
* Checks if the given value is a `WeekSet`.
|
|
2730
3007
|
* @group Predicates
|
|
@@ -2783,7 +3060,7 @@ declare const isEmpty: (obj: any) => boolean;
|
|
|
2783
3060
|
* Checks if the given value is a `Promise`
|
|
2784
3061
|
* @group Predicates
|
|
2785
3062
|
*/
|
|
2786
|
-
declare function isPromise<T = void>(value:
|
|
3063
|
+
declare function isPromise<T = void>(value: unknown): value is Promise<T>;
|
|
2787
3064
|
/**
|
|
2788
3065
|
* Checks whether a value is a JavaScript primitive.
|
|
2789
3066
|
*
|
|
@@ -4318,7 +4595,7 @@ declare class SimpleEventEmitter<T extends SimpleEventMap<T> = SimpleDefaultEven
|
|
|
4318
4595
|
* - A `Promise` that will be awaited until completion, or
|
|
4319
4596
|
* - A function that takes an `AbortSignal` and returns a `Promise` or a value.
|
|
4320
4597
|
* @param timeoutError - The error that will be thrown if the timeout is reached before the promise or callback resolves.
|
|
4321
|
-
* (Defaults to `
|
|
4598
|
+
* (Defaults to `AppError(408)` if not provided).
|
|
4322
4599
|
* @returns A `Promise` that resolves with the result of the provided `promiseOrCallback`, or rejects with the `timeoutError` if the timeout occurs.
|
|
4323
4600
|
*
|
|
4324
4601
|
* @throws {Error} - Throws the `timeoutError` if the operation exceeds the specified timeout.
|
|
@@ -4327,140 +4604,6 @@ declare class SimpleEventEmitter<T extends SimpleEventMap<T> = SimpleDefaultEven
|
|
|
4327
4604
|
*/
|
|
4328
4605
|
declare function timeout<T = any>(ms: number, promiseOrCallback: Promise<T> | ((abortSignal: AbortSignal) => Awaitable<T>), timeoutError?: any): Promise<T>;
|
|
4329
4606
|
|
|
4330
|
-
type TypeOf = keyof TypeOfMap;
|
|
4331
|
-
type TypeOfMap = {
|
|
4332
|
-
null: null;
|
|
4333
|
-
undefined: undefined;
|
|
4334
|
-
object: Record<PropertyKey, any>;
|
|
4335
|
-
string: string;
|
|
4336
|
-
number: number;
|
|
4337
|
-
function: AnyFunction;
|
|
4338
|
-
bigint: bigint;
|
|
4339
|
-
boolean: boolean;
|
|
4340
|
-
symbol: symbol;
|
|
4341
|
-
date: Date;
|
|
4342
|
-
array: any[];
|
|
4343
|
-
map: Map<any, any>;
|
|
4344
|
-
weakmap: WeakMap<WeakKey, any>;
|
|
4345
|
-
set: Set<any>;
|
|
4346
|
-
weakset: WeakSet<WeakKey>;
|
|
4347
|
-
unknown: unknown;
|
|
4348
|
-
};
|
|
4349
|
-
/**
|
|
4350
|
-
* Typeof that you deserve
|
|
4351
|
-
* @group Utility Functions
|
|
4352
|
-
*/
|
|
4353
|
-
declare function typeOf(value: unknown): TypeOf;
|
|
4354
|
-
|
|
4355
|
-
type StringifyOptions = {
|
|
4356
|
-
/**
|
|
4357
|
-
* Exclude empty values, checking by `isEmpty`
|
|
4358
|
-
* @default true
|
|
4359
|
-
*/
|
|
4360
|
-
excludeEmpty?: boolean;
|
|
4361
|
-
/**
|
|
4362
|
-
* Exclude values when equals with defaults
|
|
4363
|
-
*/
|
|
4364
|
-
excludeDefaults?: Record<string, any>;
|
|
4365
|
-
};
|
|
4366
|
-
/**
|
|
4367
|
-
* Simple query stringy interface that supports encoding/decoding of `Array`, `Set`, `Map`, `Object`, `BigInt`
|
|
4368
|
-
*
|
|
4369
|
-
* @example
|
|
4370
|
-
* // encode
|
|
4371
|
-
* qs.stringify({ page: 1, limit: 10 }); // 'page=1&limit=10'
|
|
4372
|
-
*
|
|
4373
|
-
* // decode
|
|
4374
|
-
* const defaults = { page: 1, limit: 10 };
|
|
4375
|
-
* const params = qs.parse('page=5&limit=abc', defaults); // { page: 5, limit: 10 }
|
|
4376
|
-
*
|
|
4377
|
-
* @group Utility Functions
|
|
4378
|
-
*/
|
|
4379
|
-
declare const qs: {
|
|
4380
|
-
toParams: typeof toParams;
|
|
4381
|
-
stringify: typeof stringify;
|
|
4382
|
-
stringifyValue: typeof stringifyValue;
|
|
4383
|
-
parse: typeof parse;
|
|
4384
|
-
parseValue: typeof parseValue;
|
|
4385
|
-
merge: typeof merge;
|
|
4386
|
-
};
|
|
4387
|
-
/**
|
|
4388
|
-
* Merge first level values
|
|
4389
|
-
*/
|
|
4390
|
-
declare function merge(...values: Record<string, any>[]): Record<string, any>;
|
|
4391
|
-
/**
|
|
4392
|
-
* Simple function to transform object into query string (not standards)
|
|
4393
|
-
*/
|
|
4394
|
-
declare function stringify(obj: Record<string, any>, options?: StringifyOptions): string;
|
|
4395
|
-
/**
|
|
4396
|
-
* Prepare search params object
|
|
4397
|
-
*/
|
|
4398
|
-
declare function toParams(obj: Record<string, any>, options?: StringifyOptions): Record<string, string>;
|
|
4399
|
-
/**
|
|
4400
|
-
* Parse query string as is without type casting
|
|
4401
|
-
*/
|
|
4402
|
-
declare function parse(value: string): Record<string, string>;
|
|
4403
|
-
/**
|
|
4404
|
-
* Parse query string and use default object as type cast schema
|
|
4405
|
-
*/
|
|
4406
|
-
declare function parse<T extends Record<string, any>>(value: string, defaults: Partial<T>): T;
|
|
4407
|
-
/**
|
|
4408
|
-
* Parse query params and use default object as type cast schema
|
|
4409
|
-
*/
|
|
4410
|
-
declare function parse<T extends Record<string, any>>(value: Record<string, any>, defaults: T): Partial<T>;
|
|
4411
|
-
/**
|
|
4412
|
-
* Stringify value to use as query parameter
|
|
4413
|
-
*/
|
|
4414
|
-
declare function stringifyValue(value: unknown): string;
|
|
4415
|
-
/**
|
|
4416
|
-
* Parse string query value as a type
|
|
4417
|
-
*/
|
|
4418
|
-
declare function parseValue<T extends TypeOf>(value: any, asType: T): TypeOfMap[T] | undefined;
|
|
4419
|
-
|
|
4420
|
-
type RetryOnErrorConfig = {
|
|
4421
|
-
/**
|
|
4422
|
-
* The function to execute before retry attempt; Allows to update parameters for the main function by returning then in an array
|
|
4423
|
-
*/
|
|
4424
|
-
beforeRetryCallback?: (attempt: number, lastAttempt: boolean) => Promise<unknown[] | void>;
|
|
4425
|
-
/**
|
|
4426
|
-
* Error validation function. If returns true, the main callback's considered ready to be executed again
|
|
4427
|
-
*/
|
|
4428
|
-
shouldRetryBasedOnError?: (error: unknown, attempt: number) => boolean;
|
|
4429
|
-
/**
|
|
4430
|
-
* Number of retries until the execution fails
|
|
4431
|
-
*/
|
|
4432
|
-
maxRetriesNumber: number;
|
|
4433
|
-
/**
|
|
4434
|
-
* Delay multiply factor
|
|
4435
|
-
*/
|
|
4436
|
-
delayFactor?: number;
|
|
4437
|
-
/**
|
|
4438
|
-
* Delay min milliseconds
|
|
4439
|
-
*/
|
|
4440
|
-
delayMinMs?: number;
|
|
4441
|
-
/**
|
|
4442
|
-
* Delay max milliseconds
|
|
4443
|
-
*/
|
|
4444
|
-
delayMaxMs?: number;
|
|
4445
|
-
};
|
|
4446
|
-
/**
|
|
4447
|
-
* @example
|
|
4448
|
-
* await retryOnError({
|
|
4449
|
-
* maxRetriesNumber: 10,
|
|
4450
|
-
* delayFactor: 2,
|
|
4451
|
-
* delayMinMs: 1000,
|
|
4452
|
-
* delayMaxMs: 3000,
|
|
4453
|
-
* shouldRetryBasedOnError(error, attemptNumber) {
|
|
4454
|
-
* return error.code !== 'RECORD_EXISTS';
|
|
4455
|
-
* }
|
|
4456
|
-
* }, async () => {
|
|
4457
|
-
* await db.transactions.insert(doc);
|
|
4458
|
-
* });
|
|
4459
|
-
*
|
|
4460
|
-
* @group Errors
|
|
4461
|
-
*/
|
|
4462
|
-
declare function retryOnError<T extends AnyFunction>({ beforeRetryCallback, shouldRetryBasedOnError, maxRetriesNumber, delayFactor, delayMaxMs, delayMinMs, }: RetryOnErrorConfig, fn: T): (...args: Parameters<T>) => Promise<Awaited<ReturnType<T>>>;
|
|
4463
|
-
|
|
4464
4607
|
/**
|
|
4465
4608
|
* Converts a string to camel case.
|
|
4466
4609
|
*
|
|
@@ -4995,4 +5138,4 @@ declare function wrapText(value: string, maxLength?: number): string;
|
|
|
4995
5138
|
*/
|
|
4996
5139
|
declare function toError<T>(value: T, unknownMessage?: string): T extends Error ? T : Error;
|
|
4997
5140
|
|
|
4998
|
-
export { type AnyFunction, AppError, type ArgumentsType, type Arrayable, AsyncIterableQueue, type Awaitable, type Base64ToBytesOptions, BrowserAssertionError, type BytesToBase64Options, CancellablePromise, type CatchErrorResult, Color, type ColorChannels, ColorParser, type Data, type DateObject, type DateObjectInput, type DeepPartial, type DeepReadonly, type Defer, instance as EJSON, EJSONStream, type EJSONStreamOptions, type EJSONStreamOptionsWithPayload, type EnvParser, type ExecResult, type ExecResultToSkip, type ExecResultToSuccess, type ExecSkip, type ExecSuccess, FindMean, FixedMap, FixedWeakMap, type Fn, type FormatMoney, type FormatNumber, type FunctionArgs, type GenericObject, type IfAny, type IsAny, type LiteralUnion, type Logger, LruCache, type Nothing, type OverwriteWith, type Prettify, type Primitive, type PromisifyFn, Queue, type RandomizerOptions, type RetryOnErrorConfig, type SelectOptionItem, type SelectOptions, type SimpleDefaultEventMap, SimpleEventEmitter, type SimpleEventMap, _default as TWEMOJI_REGEX, type ThemeConfig, TimeBucket, type TimeBucketOptions, type TimeObject, type TimeObjectInput, TimeSpan, type TimeSpanUnit, type TimeString, type TimeValue, type TimestampMsInput, type TypeOf, type TypeOfMap, type ValuesOfObject, type WithCache, type WithCacheBucketBatchOptions, type WithCacheBucketOptions, type WithCacheFixedOptions, type WithCacheLruOptions, type WithCacheOptions, type WithCachePointer, type WithCacheResult, type WithCacheStorage, type WithCustomizer, type WithCustomizerFactory, type WithCustomizerValue, type WrrItem, alpha, arrayable, assert, asyncFilter, asyncFind, asyncForEach, asyncMap, avg, base64ToBytes, bigIntBytes, bigIntFromBytes, blendColors, buildCssColor, bytesToBase64, cache, cacheBucket, cacheFixed, cacheLRU, camelCase, capitalize, captureStackTrace, catchError, channelsToHSL, channelsToHex, channelsToRGB, checkBitmask, chunk, chunkSeries, clamp, cleanEmpty, cleanObject, colorToChannels, compareBytes, concatenateBytes, contrastRatio, convertToUnit, crc32, createCustomizer, createCustomizerFactory, createDateObject, createDeepCloneWith, createEJSON, createEJSONStream, createEnvParser, createRandomizer, createSecureCustomizer, createTimeObject, createTimeSpan, createWithCache, cssVariable, dateInDays, dateInSeconds, deepAssign, deepClone, deepCloneWith, deepDefaults, deepFreeze, def, defer, delay, difference, dropCache, env, escapeHtml, escapeNumeric, escapeRegExp, fastIdle, fastIdlePromise, fastRaf, findMean, flagsToMap, flatten, formatMoney, formatNumber, get, getFileExtension, getFileName, getInitials, getMostSpecificPaths, getRandomInt, getRandomTime, getWords, groupBy, has, hasOwn, hasProtocol, hex, hexToChannels, hmToSeconds, hslToChannels, humanFileSize, humanize, interpolateColor, intersection, isBigInt, isBoolean, isCached, isClient, isColorChannels, isCustomizerFactory, isDate, isDateObject, isDef, isEmpty, isEqual, isError, isFunction, isInfinity, isMap, isNullOrUndefined, isNumber, isObject, isOneEmoji, isPlainObject, isPrimitive, isPromise, isSet, isSkip, isString, isSuccess, isSymbol, isTimeObject, isTimeString, isTimeValue, isValidWeekDay, isWeakMap, isWeakSet, isWithCache, isoToFlagEmoji, kebabCase, keyBy, logger, loggerSetLevel, lowerCase, luminance, maskingEmail, maskingPhone, maskingWords, nextTickIteration, noop, objectId, omit, omitPrefixed, orderBy, parseAllNumbers, parseAlpha, parsePercentage, percentOf, pick, pickPrefixed, qs, rafPromise, randomString, removeVS16s, retryOnError, rgbToChannels, round2digits, secondsToHm, set, shuffle, snakeCase, sprintf, startCase, strAssign, sum, timeFromMinutes, timeStringify, timeToMinutes, timeout, timestamp, timestampMs, timestampToDate, tintedTextColor, toError, toMap, truncate, typeOf, uint16ToUint8, uint32ToUint8, uint8ToUint16, uint8ToUint32, unflatten, union, uniq, uniqBy, unset, weeksInYear, weightedRoundRobin, withCache, withCacheBucket, withCacheBucketBatch, withCacheFixed, withCacheLRU, withDeepClone, withPointerCache, wrapText };
|
|
5141
|
+
export { type AnyFunction, AppError, type AppErrorOptions, type ArgumentsType, type Arrayable, AsyncIterableQueue, type Awaitable, type Base64ToBytesOptions, BrowserAssertionError, type BytesToBase64Options, CancellablePromise, type CatchErrorResult, Color, type ColorChannels, ColorParser, type Data, type DateObject, type DateObjectInput, type DebouncedFunction, type DeepPartial, type DeepReadonly, type Defer, instance as EJSON, EJSONStream, type EJSONStreamOptions, type EJSONStreamOptionsWithPayload, type EnvParser, type ExecResult, type ExecResultToSkip, type ExecResultToSuccess, type ExecSkip, type ExecSuccess, FindMean, FixedMap, FixedWeakMap, type Fn, type FormatMoney, type FormatNumber, type FunctionArgs, type GenericObject, type IfAny, type IsAny, type LiteralUnion, type Logger, LruCache, type Nothing, type OverwriteWith, type Prettify, type Primitive, type PromisifyFn, Queue, type RandomizerOptions, type RetryOnErrorConfig, type SelectOptionItem, type SelectOptions, type SimpleDefaultEventMap, SimpleEventEmitter, type SimpleEventMap, _default as TWEMOJI_REGEX, type ThemeConfig, type ThrottledFunction, TimeBucket, type TimeBucketOptions, type TimeObject, type TimeObjectInput, TimeSpan, type TimeSpanUnit, type TimeString, type TimeValue, type TimestampMsInput, type TypeOf, type TypeOfMap, type ValuesOfObject, type WithCache, type WithCacheBucketBatchOptions, type WithCacheBucketOptions, type WithCacheFixedOptions, type WithCacheLruOptions, type WithCacheOptions, type WithCachePointer, type WithCacheResult, type WithCacheStorage, type WithCustomizer, type WithCustomizerFactory, type WithCustomizerValue, type WrrItem, alpha, arrayable, assert, asyncFilter, asyncFind, asyncForEach, asyncMap, avg, base64ToBytes, bigIntBytes, bigIntFromBytes, blendColors, buildCssColor, bytesToBase64, cache, cacheBucket, cacheFixed, cacheLRU, camelCase, capitalize, captureStackTrace, catchError, channelsToHSL, channelsToHex, channelsToRGB, checkBitmask, chunk, chunkSeries, clamp, cleanEmpty, cleanObject, colorToChannels, compareBytes, concatenateBytes, contrastRatio, convertToUnit, crc32, createCustomizer, createCustomizerFactory, createDateObject, createDeepCloneWith, createEJSON, createEJSONStream, createEnvParser, createRandomizer, createSecureCustomizer, createTimeObject, createTimeSpan, createWithCache, cssVariable, dateInDays, dateInSeconds, debounce, deepAssign, deepClone, deepCloneWith, deepDefaults, deepFreeze, def, defer, delay, difference, dropCache, env, escapeHtml, escapeNumeric, escapeRegExp, fastIdle, fastIdlePromise, fastRaf, findMean, flagsToMap, flatten, formatMoney, formatNumber, get, getFileExtension, getFileName, getInitials, getMostSpecificPaths, getRandomInt, getRandomTime, getWords, groupBy, has, hasOwn, hasProtocol, hex, hexToChannels, hmToSeconds, hslToChannels, humanFileSize, humanize, interpolateColor, intersection, isBigInt, isBoolean, isCached, isClient, isColorChannels, isCustomizerFactory, isDate, isDateObject, isDef, isEmpty, isEqual, isError, isFunction, isInfinity, isMap, isNullOrUndefined, isNumber, isObject, isOneEmoji, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isSkip, isString, isSuccess, isSymbol, isTimeObject, isTimeString, isTimeValue, isValidWeekDay, isWeakMap, isWeakSet, isWithCache, isoToFlagEmoji, kebabCase, keyBy, logger, loggerSetLevel, lowerCase, luminance, maskingEmail, maskingPhone, maskingWords, nextTickIteration, noop, objectId, omit, omitPrefixed, orderBy, parseAllNumbers, parseAlpha, parsePercentage, percentOf, pick, pickPrefixed, qs, rafPromise, randomString, removeVS16s, retryOnError, rgbToChannels, round2digits, secondsToHm, set, shuffle, snakeCase, sprintf, startCase, strAssign, sum, throttle, timeFromMinutes, timeStringify, timeToMinutes, timeout, timestamp, timestampMs, timestampToDate, tintedTextColor, toError, toMap, truncate, typeOf, uint16ToUint8, uint32ToUint8, uint8ToUint16, uint8ToUint32, unflatten, union, uniq, uniqBy, unset, weeksInYear, weightedRoundRobin, withCache, withCacheBucket, withCacheBucketBatch, withCacheFixed, withCacheLRU, withDeepClone, withPointerCache, wrapText };
|