@dereekb/util 11.0.7 → 11.0.8
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 +20 -0
- package/fetch/index.esm.js +25 -2
- package/fetch/package.json +1 -1
- package/fetch/src/lib/fetch.page.d.ts +15 -12
- package/fetch/src/lib/fetch.url.d.ts +22 -0
- package/fetch/src/lib/index.d.ts +1 -0
- package/index.esm.js +4 -0
- package/package.json +1 -1
- package/src/lib/object/object.d.ts +5 -1
- package/src/lib/page/page.d.ts +3 -3
- package/test/CHANGELOG.md +4 -0
- package/test/package.json +1 -1
package/fetch/index.cjs.js
CHANGED
|
@@ -5428,6 +5428,25 @@ const iterateFetchPagesByItems = _async(function (config) {
|
|
|
5428
5428
|
return iterateFetchPages(fetchPagesConfig);
|
|
5429
5429
|
});
|
|
5430
5430
|
|
|
5431
|
+
/**
|
|
5432
|
+
* Creates URLSearchParams from the input objects. The input objects are merged together.
|
|
5433
|
+
*
|
|
5434
|
+
* @param input
|
|
5435
|
+
* @param omitKeys
|
|
5436
|
+
* @returns
|
|
5437
|
+
*/
|
|
5438
|
+
function makeUrlSearchParams(input, options) {
|
|
5439
|
+
const {
|
|
5440
|
+
omitKeys
|
|
5441
|
+
} = options != null ? options : {};
|
|
5442
|
+
const mergedInput = Array.isArray(input) ? util.mergeObjects(input) : input;
|
|
5443
|
+
const searchParams = new URLSearchParams(mergedInput);
|
|
5444
|
+
if (omitKeys != null) {
|
|
5445
|
+
util.useIterableOrValue(omitKeys, key => searchParams.delete(key), false);
|
|
5446
|
+
}
|
|
5447
|
+
return searchParams;
|
|
5448
|
+
}
|
|
5449
|
+
|
|
5431
5450
|
var anObject$1 = anObject$e;
|
|
5432
5451
|
|
|
5433
5452
|
// `RegExp.prototype.flags` getter implementation
|
|
@@ -5684,6 +5703,7 @@ exports.isURL = isURL;
|
|
|
5684
5703
|
exports.isURLSearchParams = isURLSearchParams;
|
|
5685
5704
|
exports.iterateFetchPages = iterateFetchPages;
|
|
5686
5705
|
exports.iterateFetchPagesByItems = iterateFetchPagesByItems;
|
|
5706
|
+
exports.makeUrlSearchParams = makeUrlSearchParams;
|
|
5687
5707
|
exports.mergeRequestHeaders = mergeRequestHeaders;
|
|
5688
5708
|
exports.mergeRequestInits = mergeRequestInits;
|
|
5689
5709
|
exports.nodeFetchService = nodeFetchService;
|
package/fetch/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { removeTrailingSlashes, asGetter, multiValueMapBuilder, filterMaybeValues, objectToTuples, fixMultiSlashesInSlashPath, isPromiseLike, cachedGetter, FIRST_PAGE, mapIdentityFunction, performTasksFromFactoryInParallelFunction, isEmptyIterable, fixExtraQueryParameters, forEachInIterable,
|
|
1
|
+
import { removeTrailingSlashes, asGetter, multiValueMapBuilder, filterMaybeValues, objectToTuples, fixMultiSlashesInSlashPath, isPromiseLike, cachedGetter, FIRST_PAGE, mapIdentityFunction, performTasksFromFactoryInParallelFunction, mergeObjects, useIterableOrValue, isEmptyIterable, fixExtraQueryParameters, forEachInIterable, isIterable, forEachKeyValue } from '@dereekb/util';
|
|
2
2
|
|
|
3
3
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
4
4
|
|
|
@@ -5335,6 +5335,29 @@ async function iterateFetchPages(config) {
|
|
|
5335
5335
|
return result;
|
|
5336
5336
|
}
|
|
5337
5337
|
|
|
5338
|
+
/**
|
|
5339
|
+
* Options for makeUrlSearchParams()
|
|
5340
|
+
*/
|
|
5341
|
+
|
|
5342
|
+
/**
|
|
5343
|
+
* Creates URLSearchParams from the input objects. The input objects are merged together.
|
|
5344
|
+
*
|
|
5345
|
+
* @param input
|
|
5346
|
+
* @param omitKeys
|
|
5347
|
+
* @returns
|
|
5348
|
+
*/
|
|
5349
|
+
function makeUrlSearchParams(input, options) {
|
|
5350
|
+
const {
|
|
5351
|
+
omitKeys
|
|
5352
|
+
} = options != null ? options : {};
|
|
5353
|
+
const mergedInput = Array.isArray(input) ? mergeObjects(input) : input;
|
|
5354
|
+
const searchParams = new URLSearchParams(mergedInput);
|
|
5355
|
+
if (omitKeys != null) {
|
|
5356
|
+
useIterableOrValue(omitKeys, key => searchParams.delete(key), false);
|
|
5357
|
+
}
|
|
5358
|
+
return searchParams;
|
|
5359
|
+
}
|
|
5360
|
+
|
|
5338
5361
|
var anObject$1 = anObject$e;
|
|
5339
5362
|
|
|
5340
5363
|
// `RegExp.prototype.flags` getter implementation
|
|
@@ -5572,4 +5595,4 @@ const nodeFetchService = fetchService({
|
|
|
5572
5595
|
makeRequest: (x, y) => new Request(x, y)
|
|
5573
5596
|
});
|
|
5574
5597
|
|
|
5575
|
-
export { FETCH_PAGE_FACTORY_DEFAULT_MAX_PAGE, FetchPageLimitReachedError, FetchPageNoNextPageError, FetchRequestFactoryError, FetchResponseError, FetchTimeoutError, JsonResponseParseError, configureFetch, fetchJsonBodyString, fetchJsonFunction, fetchJsonRequestInit, fetchJsonRequestInitFunction, fetchOk, fetchPageFactory, fetchRequestFactory, fetchService, fetchTimeout, fetchURL, fetchURLQueryKeyValueStringTuples, fetchURLSearchParamsObjectToURLSearchParams, headersToHeadersTuple, isFetchRequest, isURL, isURLSearchParams, iterateFetchPages, iterateFetchPagesByItems, mergeRequestHeaders, mergeRequestInits, nodeFetchService, queryParamsToSearchParams, requireOkResponse, returnNullHandleFetchJsonParseErrorFunction, throwJsonResponseParseErrorFunction };
|
|
5598
|
+
export { FETCH_PAGE_FACTORY_DEFAULT_MAX_PAGE, FetchPageLimitReachedError, FetchPageNoNextPageError, FetchRequestFactoryError, FetchResponseError, FetchTimeoutError, JsonResponseParseError, configureFetch, fetchJsonBodyString, fetchJsonFunction, fetchJsonRequestInit, fetchJsonRequestInitFunction, fetchOk, fetchPageFactory, fetchRequestFactory, fetchService, fetchTimeout, fetchURL, fetchURLQueryKeyValueStringTuples, fetchURLSearchParamsObjectToURLSearchParams, headersToHeadersTuple, isFetchRequest, isURL, isURLSearchParams, iterateFetchPages, iterateFetchPagesByItems, makeUrlSearchParams, mergeRequestHeaders, mergeRequestInits, nodeFetchService, queryParamsToSearchParams, requireOkResponse, returnNullHandleFetchJsonParseErrorFunction, throwJsonResponseParseErrorFunction };
|
package/fetch/package.json
CHANGED
|
@@ -79,7 +79,20 @@ export interface FetchPageFactoryInputOptions {
|
|
|
79
79
|
*/
|
|
80
80
|
readonly maxItemsPerPage?: Maybe<number>;
|
|
81
81
|
}
|
|
82
|
-
export
|
|
82
|
+
export type ReadFetchPageResultInfo = Omit<FetchPageResultInfo, 'page'>;
|
|
83
|
+
export interface FetchPageFactoryConfigDefaults {
|
|
84
|
+
/**
|
|
85
|
+
* The default max page to load up to.
|
|
86
|
+
*
|
|
87
|
+
* Defaults to 100. Pass null to disable the max page amount.
|
|
88
|
+
*/
|
|
89
|
+
readonly defaultMaxPage?: Maybe<number>;
|
|
90
|
+
/**
|
|
91
|
+
* The default maximum number of items to load per page.
|
|
92
|
+
*/
|
|
93
|
+
readonly defaultMaxItemsPerPage?: Maybe<number>;
|
|
94
|
+
}
|
|
95
|
+
export interface FetchPageFactoryConfig<I, O> extends FetchPageFactoryConfigDefaults {
|
|
83
96
|
/**
|
|
84
97
|
* The configured Fetch function that takes in the input and returns a results.
|
|
85
98
|
*/
|
|
@@ -92,7 +105,7 @@ export interface FetchPageFactoryConfig<I, O> {
|
|
|
92
105
|
* @param result
|
|
93
106
|
* @returns
|
|
94
107
|
*/
|
|
95
|
-
readonly readFetchPageResultInfo: (result: O) => PromiseOrValue<
|
|
108
|
+
readonly readFetchPageResultInfo: (result: O) => PromiseOrValue<ReadFetchPageResultInfo>;
|
|
96
109
|
/**
|
|
97
110
|
* Creates new input for the next page that is merged with the previous input.
|
|
98
111
|
*
|
|
@@ -102,16 +115,6 @@ export interface FetchPageFactoryConfig<I, O> {
|
|
|
102
115
|
* @returns
|
|
103
116
|
*/
|
|
104
117
|
readonly buildInputForNextPage: (pageResult: Partial<FetchPageResult<O>>, input: I, options: FetchPageFactoryInputOptions) => PromiseOrValue<Maybe<Partial<I>>>;
|
|
105
|
-
/**
|
|
106
|
-
* The default max page to load up to.
|
|
107
|
-
*
|
|
108
|
-
* Defaults to 100. Pass null to disable the max page amount.
|
|
109
|
-
*/
|
|
110
|
-
readonly defaultMaxPage?: Maybe<number>;
|
|
111
|
-
/**
|
|
112
|
-
* The default maximum number of items to load per page.
|
|
113
|
-
*/
|
|
114
|
-
readonly defaultMaxItemsPerPage?: Maybe<number>;
|
|
115
118
|
}
|
|
116
119
|
export type FetchPageFactoryOptions<I, O> = FetchPageFactoryInputOptions;
|
|
117
120
|
/**
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Maybe, type ArrayOrValue, type IterableOrValue, type ObjectKey, type FilterKeyValueTuplesInput } from '@dereekb/util';
|
|
2
|
+
/**
|
|
3
|
+
* Options for makeUrlSearchParams()
|
|
4
|
+
*/
|
|
5
|
+
export interface MakeUrlSearchParamsOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Optional iterable of keys to remove from the search params.
|
|
8
|
+
*/
|
|
9
|
+
readonly omitKeys?: Maybe<IterableOrValue<ObjectKey>>;
|
|
10
|
+
/**
|
|
11
|
+
* Optional filter for merging the objects together.
|
|
12
|
+
*/
|
|
13
|
+
readonly mergeFilter?: FilterKeyValueTuplesInput;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates URLSearchParams from the input objects. The input objects are merged together.
|
|
17
|
+
*
|
|
18
|
+
* @param input
|
|
19
|
+
* @param omitKeys
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
export declare function makeUrlSearchParams(input: Maybe<ArrayOrValue<Maybe<object | Record<string, string | number>>>>, options?: Maybe<MakeUrlSearchParamsOptions>): URLSearchParams;
|
package/fetch/src/lib/index.d.ts
CHANGED
package/index.esm.js
CHANGED
|
@@ -2788,6 +2788,10 @@ function arrayDecision(values, decision, mode) {
|
|
|
2788
2788
|
return arrayDecisionFunction(decision, mode)(values);
|
|
2789
2789
|
}
|
|
2790
2790
|
|
|
2791
|
+
/**
|
|
2792
|
+
* Key of an object.
|
|
2793
|
+
*/
|
|
2794
|
+
|
|
2791
2795
|
function objectHasNoKeys(obj) {
|
|
2792
2796
|
return Object.keys(obj).length === 0;
|
|
2793
2797
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { type FieldOfType } from '../key';
|
|
2
2
|
import { type SetIncludesMode } from '../set/set.mode';
|
|
3
3
|
import { type KeyAsString } from '../type';
|
|
4
|
+
/**
|
|
5
|
+
* Key of an object.
|
|
6
|
+
*/
|
|
7
|
+
export type ObjectKey = string;
|
|
4
8
|
export type EmptyObject = Record<string, never>;
|
|
5
9
|
export declare function objectHasNoKeys(obj: object): obj is EmptyObject;
|
|
6
10
|
export declare function objectHasKey<T>(obj: T, key: KeyAsString<keyof T>): boolean;
|
|
@@ -13,7 +17,7 @@ export declare function objectHasKey<T, K extends keyof T>(obj: T, key: K): bool
|
|
|
13
17
|
* @param keys
|
|
14
18
|
*/
|
|
15
19
|
export declare function objectHasKeys<T>(obj: T, keys: KeyAsString<keyof T>[], mode?: SetIncludesMode): boolean;
|
|
16
|
-
export declare function objectHasKeys(obj: unknown, keys:
|
|
20
|
+
export declare function objectHasKeys(obj: unknown, keys: ObjectKey[], mode?: SetIncludesMode): boolean;
|
|
17
21
|
export declare function objectHasKeys<T, K extends keyof T>(obj: T, keys: K[], mode?: SetIncludesMode): boolean;
|
|
18
22
|
export declare function applyToMultipleFields<T extends object, X = unknown>(value: X, fields: FieldOfType<T>[]): Partial<{
|
|
19
23
|
[K in keyof T]: X;
|
package/src/lib/page/page.d.ts
CHANGED
|
@@ -21,6 +21,6 @@ export interface Page {
|
|
|
21
21
|
*/
|
|
22
22
|
page: PageNumber;
|
|
23
23
|
}
|
|
24
|
-
export declare function getPageNumber(page: Maybe<Page
|
|
25
|
-
export declare function getNextPageNumber(page: Maybe<Page
|
|
26
|
-
export declare function isFinalPage(page: Maybe<Page
|
|
24
|
+
export declare function getPageNumber(page: Maybe<Partial<Page>>): number;
|
|
25
|
+
export declare function getNextPageNumber(page: Maybe<Partial<Page>>): number;
|
|
26
|
+
export declare function isFinalPage(page: Maybe<Partial<Page>>): boolean;
|
package/test/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [11.0.8](https://github.com/dereekb/dbx-components/compare/v11.0.7-dev...v11.0.8) (2024-11-23)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
5
9
|
## [11.0.7](https://github.com/dereekb/dbx-components/compare/v11.0.6-dev...v11.0.7) (2024-11-22)
|
|
6
10
|
|
|
7
11
|
|