@dereekb/util 13.4.0 → 13.4.1
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/fetch/index.cjs.js +191 -109
- package/fetch/index.esm.js +191 -109
- package/fetch/package.json +2 -2
- package/fetch/src/lib/error.d.ts +6 -0
- package/fetch/src/lib/fetch.d.ts +37 -0
- package/fetch/src/lib/fetch.file.d.ts +7 -5
- package/fetch/src/lib/fetch.limit.d.ts +7 -0
- package/fetch/src/lib/fetch.url.d.ts +6 -3
- package/fetch/src/lib/json.d.ts +12 -1
- package/fetch/src/lib/timeout.d.ts +8 -0
- package/fetch/src/lib/url.d.ts +33 -0
- package/index.cjs.js +1440 -746
- package/index.esm.js +1440 -747
- package/package.json +1 -1
- package/src/lib/array/array.boolean.d.ts +7 -0
- package/src/lib/array/array.filter.d.ts +4 -4
- package/src/lib/array/array.index.d.ts +3 -1
- package/src/lib/array/array.indexed.d.ts +9 -3
- package/src/lib/array/array.limit.d.ts +2 -0
- package/src/lib/assertion/assert.d.ts +3 -0
- package/src/lib/assertion/assert.error.d.ts +6 -0
- package/src/lib/boolean.d.ts +3 -0
- package/src/lib/date/expires.d.ts +3 -3
- package/src/lib/date/minute.d.ts +14 -8
- package/src/lib/date/time.d.ts +3 -0
- package/src/lib/error/error.server.d.ts +1 -0
- package/src/lib/file/pdf.d.ts +1 -1
- package/src/lib/getter/getter.cache.d.ts +1 -1
- package/src/lib/grouping.d.ts +11 -2
- package/src/lib/map/map.key.d.ts +1 -1
- package/src/lib/model/model.d.ts +14 -9
- package/src/lib/number/dollar.d.ts +8 -0
- package/src/lib/number/number.d.ts +4 -0
- package/src/lib/object/object.equal.d.ts +2 -2
- package/src/lib/object/object.filter.pojo.d.ts +7 -0
- package/src/lib/object/object.filter.tuple.d.ts +2 -0
- package/src/lib/object/object.map.d.ts +1 -1
- package/src/lib/path/path.d.ts +4 -2
- package/src/lib/promise/poll.d.ts +3 -0
- package/src/lib/promise/promise.d.ts +19 -7
- package/src/lib/promise/promise.loop.d.ts +27 -9
- package/src/lib/relation/relation.d.ts +12 -0
- package/src/lib/service/handler.config.d.ts +3 -1
- package/src/lib/service/handler.d.ts +6 -2
- package/src/lib/service/typed.service.d.ts +3 -1
- package/src/lib/set/set.d.ts +32 -19
- package/src/lib/set/set.hashset.d.ts +3 -1
- package/src/lib/sort.d.ts +11 -0
- package/src/lib/storage/storage.error.d.ts +3 -0
- package/src/lib/storage/storage.memory.d.ts +7 -0
- package/src/lib/storage/storage.object.d.ts +5 -0
- package/src/lib/string/dencoder.d.ts +4 -1
- package/src/lib/string/mimetype.d.ts +57 -19
- package/src/lib/string/transform.d.ts +10 -1
- package/src/lib/string/tree.d.ts +18 -6
- package/src/lib/string/url.d.ts +57 -19
- package/src/lib/tree/tree.d.ts +12 -4
- package/src/lib/tree/tree.flatten.d.ts +3 -1
- package/src/lib/value/address.d.ts +24 -7
- package/src/lib/value/bound.d.ts +3 -0
- package/src/lib/value/build.d.ts +3 -0
- package/src/lib/value/comparator.d.ts +4 -0
- package/src/lib/value/cron.d.ts +1 -0
- package/src/lib/value/decision.d.ts +3 -0
- package/src/lib/value/equal.d.ts +3 -0
- package/src/lib/value/indexed.d.ts +4 -0
- package/src/lib/value/label.d.ts +1 -0
- package/src/lib/value/map.d.ts +9 -0
- package/src/lib/value/maybe.d.ts +13 -0
- package/src/lib/value/modifier.d.ts +9 -0
- package/src/lib/value/point.d.ts +3 -0
- package/src/lib/value/url.d.ts +1 -0
- package/src/lib/value/vector.d.ts +5 -0
- package/test/index.cjs.js +29 -6
- package/test/index.esm.js +29 -6
- package/test/package.json +2 -2
- package/test/src/lib/jest/jest.fail.d.ts +3 -3
- package/test/src/lib/shared/shared.d.ts +7 -1
- package/test/src/lib/shared/shared.fail.d.ts +8 -2
- package/test/src/lib/shared/shared.wrap.d.ts +1 -0
|
@@ -29,8 +29,8 @@ export interface MakeFileForFetchInput {
|
|
|
29
29
|
/**
|
|
30
30
|
* Creates a File object from the given input.
|
|
31
31
|
*
|
|
32
|
-
* @
|
|
33
|
-
*
|
|
32
|
+
* @param input - configuration containing the file content, name, optional MIME type, and last modified timestamp
|
|
33
|
+
* @returns a File object constructed from the provided input
|
|
34
34
|
*/
|
|
35
35
|
export declare function makeFileForFetch(input: MakeFileForFetchInput): File;
|
|
36
36
|
/**
|
|
@@ -61,9 +61,8 @@ export interface FetchFileFromUrlInput {
|
|
|
61
61
|
*
|
|
62
62
|
* When safe is true, returns undefined instead of throwing on fetch failure.
|
|
63
63
|
*
|
|
64
|
-
* @
|
|
65
|
-
*
|
|
66
|
-
* formData.append('file', file)
|
|
64
|
+
* @param input - configuration containing the URL, optional file name, MIME type override, and fetch function
|
|
65
|
+
* @returns the downloaded content as a File object, or undefined in safe mode on failure
|
|
67
66
|
*/
|
|
68
67
|
export declare function fetchFileFromUrl(input: FetchFileFromUrlInput): Promise<File>;
|
|
69
68
|
export declare function fetchFileFromUrl(input: FetchFileFromUrlInput, safe: true): Promise<Maybe<File>>;
|
|
@@ -111,5 +110,8 @@ export interface FetchUploadFileBody {
|
|
|
111
110
|
}
|
|
112
111
|
/**
|
|
113
112
|
* @deprecated Use makeFileForFetch() with FormData and context.fetch() instead.
|
|
113
|
+
*
|
|
114
|
+
* @param input - configuration containing the upload URL, fetch function, HTTP method, and file body
|
|
115
|
+
* @returns a promise resolving to the fetch Response
|
|
114
116
|
*/
|
|
115
117
|
export declare function fetchUploadFile(input: FetchUploadFile): Promise<Response>;
|
|
@@ -30,4 +30,11 @@ export interface RateLimitedFetchHandlerConfig<T extends PromiseRateLimiter> {
|
|
|
30
30
|
*/
|
|
31
31
|
updateWithResponse(response: Response, fetchResponseError?: Maybe<FetchResponseError>): PromiseOrValue<boolean>;
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates a FetchHandler that enforces rate limiting via the provided PromiseRateLimiter and supports
|
|
35
|
+
* automatic retry when the server signals throttling.
|
|
36
|
+
*
|
|
37
|
+
* @param config - configuration containing the rate limiter, retry settings, and response handler
|
|
38
|
+
* @returns a RateLimitedFetchHandler that rate-limits outgoing requests and retries on throttle responses
|
|
39
|
+
*/
|
|
33
40
|
export declare function rateLimitedFetchHandler<T extends PromiseRateLimiter>(config: RateLimitedFetchHandlerConfig<T>): RateLimitedFetchHandler<T>;
|
|
@@ -34,9 +34,9 @@ export interface MakeUrlSearchParamsOptions {
|
|
|
34
34
|
/**
|
|
35
35
|
* Creates URLSearchParams from the input objects. The input objects are merged together.
|
|
36
36
|
*
|
|
37
|
-
* @param input
|
|
38
|
-
* @param
|
|
39
|
-
* @returns
|
|
37
|
+
* @param input - one or more objects (or nullish values) whose key-value pairs become search parameters
|
|
38
|
+
* @param options - optional configuration for filtering, omitting keys, and space encoding
|
|
39
|
+
* @returns a URLSearchParams instance built from the merged and filtered input
|
|
40
40
|
*/
|
|
41
41
|
export declare function makeUrlSearchParams(input: Maybe<ArrayOrValue<Maybe<object | Record<string, string | number>>>>, options?: Maybe<MakeUrlSearchParamsOptions>): URLSearchParams;
|
|
42
42
|
/**
|
|
@@ -54,5 +54,8 @@ export declare function makeUrlSearchParams(input: Maybe<ArrayOrValue<Maybe<obje
|
|
|
54
54
|
export declare function makeUrlSearchParamsString(input: Maybe<ArrayOrValue<Maybe<object | Record<string, string | number>>>>, options?: Maybe<MakeUrlSearchParamsOptions>): string;
|
|
55
55
|
/**
|
|
56
56
|
* Merges an array of MakeUrlSearchParamsOptions into a single MakeUrlSearchParamsOptions value.
|
|
57
|
+
*
|
|
58
|
+
* @param options - one or more options objects whose omitKeys sets are combined
|
|
59
|
+
* @returns a single MakeUrlSearchParamsOptions with the union of all omitKeys
|
|
57
60
|
*/
|
|
58
61
|
export declare function mergeMakeUrlSearchParamsOptions(options: ArrayOrValue<Maybe<MakeUrlSearchParamsOptions>>): MakeUrlSearchParamsOptions;
|
package/fetch/src/lib/json.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export type FetchJsonWithInputFunction = <R>(url: FetchURLInput, input: FetchJso
|
|
|
31
31
|
* Used to fetch from the input url and retrieve a JSON response.
|
|
32
32
|
*/
|
|
33
33
|
export type FetchJsonFunction = FetchJsonGetFunction & FetchJsonMethodAndBodyFunction & FetchJsonWithInputFunction;
|
|
34
|
-
export type FetchJsonInterceptJsonResponseFunction = (json:
|
|
34
|
+
export type FetchJsonInterceptJsonResponseFunction = (json: unknown, response: Response) => unknown;
|
|
35
35
|
export type HandleFetchJsonParseErrorFunction = (response: Response) => string | null | never;
|
|
36
36
|
export declare const throwJsonResponseParseErrorFunction: HandleFetchJsonParseErrorFunction;
|
|
37
37
|
export declare const returnNullHandleFetchJsonParseErrorFunction: HandleFetchJsonParseErrorFunction;
|
|
@@ -49,6 +49,10 @@ export interface FetchJsonFunctionConfig extends FetchJsonRequestInitFunctionCon
|
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* Creates a FetchJsonFunction from the input ConfiguredFetch.
|
|
52
|
+
*
|
|
53
|
+
* @param fetch - the configured fetch function to use for making HTTP requests
|
|
54
|
+
* @param inputConfig - optional configuration or error handler for JSON parsing; when a function is provided it is used as the parse error handler
|
|
55
|
+
* @returns a FetchJsonFunction that performs requests and parses JSON responses
|
|
52
56
|
*/
|
|
53
57
|
export declare function fetchJsonFunction(fetch: ConfiguredFetch, inputConfig?: FetchJsonFunctionConfig | HandleFetchJsonParseErrorFunction): FetchJsonFunction;
|
|
54
58
|
export interface FetchJsonRequestInitFunctionConfig {
|
|
@@ -64,5 +68,12 @@ export interface FetchJsonRequestInitFunctionConfig {
|
|
|
64
68
|
mapFetchJsonInput?: FetchJsonInputMapFunction;
|
|
65
69
|
}
|
|
66
70
|
export type FetchJsonRequestInitFunction = (methodOrInput?: string | FetchJsonInput | undefined, body?: FetchJsonBody) => RequestInit;
|
|
71
|
+
/**
|
|
72
|
+
* Creates a {@link FetchJsonRequestInitFunction} that converts method/body inputs into a fully formed {@link RequestInit},
|
|
73
|
+
* applying the configured default method and optional input mapping.
|
|
74
|
+
*
|
|
75
|
+
* @param config - optional configuration specifying the default HTTP method and an input mapping function
|
|
76
|
+
* @returns a function that produces a {@link RequestInit} from a method string or {@link FetchJsonInput}
|
|
77
|
+
*/
|
|
67
78
|
export declare function fetchJsonRequestInitFunction(config?: FetchJsonRequestInitFunctionConfig): FetchJsonRequestInitFunction;
|
|
68
79
|
export declare const fetchJsonRequestInit: FetchJsonRequestInitFunction;
|
|
@@ -4,4 +4,12 @@ export declare class FetchTimeoutError extends BaseError {
|
|
|
4
4
|
readonly timeout: number;
|
|
5
5
|
constructor(response: Response, timeout: number);
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Wraps a fetch function to add automatic timeout/abort support. If a timeout value
|
|
9
|
+
* is present on the RequestInit or Request and no abort signal is already provided,
|
|
10
|
+
* an AbortController is created to abort the request after the specified duration.
|
|
11
|
+
*
|
|
12
|
+
* @param inputFetch - the fetch function to wrap with timeout behavior
|
|
13
|
+
* @returns a wrapped fetch function that enforces timeouts via AbortController
|
|
14
|
+
*/
|
|
7
15
|
export declare function fetchTimeout(inputFetch: typeof fetch): typeof fetch;
|
package/fetch/src/lib/url.d.ts
CHANGED
|
@@ -11,8 +11,27 @@ export interface FetchURLConfiguration {
|
|
|
11
11
|
queryParams?: FetchURLQueryParamsInput;
|
|
12
12
|
}
|
|
13
13
|
export type FetchURLInput = SimpleFetchURLInput | FetchURLConfiguration;
|
|
14
|
+
/**
|
|
15
|
+
* Resolves a FetchURLInput to a URL string. Handles plain strings, URL objects, and
|
|
16
|
+
* FetchURLConfiguration objects by appending query parameters when provided.
|
|
17
|
+
*
|
|
18
|
+
* @param input - a string, URL, or FetchURLConfiguration to resolve
|
|
19
|
+
* @returns the resolved URL as a string
|
|
20
|
+
*/
|
|
14
21
|
export declare function fetchURL(input: FetchURLInput): string;
|
|
22
|
+
/**
|
|
23
|
+
* Type guard that checks whether the given value is a URL instance.
|
|
24
|
+
*
|
|
25
|
+
* @param input - the value to test
|
|
26
|
+
* @returns true if the input is a URL instance
|
|
27
|
+
*/
|
|
15
28
|
export declare function isURL(input: unknown): input is URL;
|
|
29
|
+
/**
|
|
30
|
+
* Type guard that checks whether the given value is a URLSearchParams instance.
|
|
31
|
+
*
|
|
32
|
+
* @param input - the value to test
|
|
33
|
+
* @returns true if the input is a URLSearchParams instance
|
|
34
|
+
*/
|
|
16
35
|
export declare function isURLSearchParams(input: unknown): input is URLSearchParams;
|
|
17
36
|
export type FetchURLQueryParamsInput = URLSearchParams | FetchURLSearchParamsObject | Iterable<FetchURLQueryKeyValueStringTuple> | Iterable<FetchURLQueryKeyValueTuple> | string;
|
|
18
37
|
export type FetchURLQueryKeyValueStringTuple = [string, string];
|
|
@@ -26,8 +45,22 @@ export declare function fetchURLQueryKeyValueStringTuples(input: Iterable<FetchU
|
|
|
26
45
|
export type FetchURLQueryKeyValueTuple = [Maybe<FetchURLQueryKeyValueTupleKey>, Maybe<ArrayOrValue<Maybe<FetchURLQueryKeyValueTupleKeyValue>>>];
|
|
27
46
|
export type FetchURLQueryKeyValueTupleKey = string | number;
|
|
28
47
|
export type FetchURLQueryKeyValueTupleKeyValue = string | number | boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Converts a FetchURLQueryParamsInput value (URLSearchParams, string, iterable of tuples, or
|
|
50
|
+
* params object) into a URLSearchParams instance.
|
|
51
|
+
*
|
|
52
|
+
* @param input - the query parameters input to convert
|
|
53
|
+
* @returns a URLSearchParams instance representing the input
|
|
54
|
+
*/
|
|
29
55
|
export declare function queryParamsToSearchParams(input: FetchURLQueryParamsInput): URLSearchParams;
|
|
30
56
|
export type FetchURLSearchTupleValueKey = string | number;
|
|
31
57
|
export type FetchURLSearchTupleValue = string | number;
|
|
32
58
|
export type FetchURLSearchParamsObject = Partial<Record<FetchURLQueryKeyValueTupleKey, Maybe<ArrayOrValue<FetchURLQueryKeyValueTupleKeyValue>>>>;
|
|
59
|
+
/**
|
|
60
|
+
* Converts a FetchURLSearchParamsObject (a plain key-value record) into a URLSearchParams instance,
|
|
61
|
+
* expanding array values into multiple entries for the same key and filtering out null/undefined values.
|
|
62
|
+
*
|
|
63
|
+
* @param input - the params object to convert
|
|
64
|
+
* @returns a URLSearchParams instance representing the input object
|
|
65
|
+
*/
|
|
33
66
|
export declare function fetchURLSearchParamsObjectToURLSearchParams(input: FetchURLSearchParamsObject): URLSearchParams;
|