@dereekb/util 9.17.0 → 9.17.2
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/CHANGELOG.md +13 -0
- package/fetch/CHANGELOG.md +13 -0
- package/fetch/package.json +2 -2
- package/fetch/src/lib/json.d.ts +8 -1
- package/fetch/src/lib/json.js +16 -3
- package/fetch/src/lib/json.js.map +1 -1
- package/package.json +1 -1
- package/test/CHANGELOG.md +8 -0
- package/test/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [9.17.2](https://github.com/dereekb/dbx-components/compare/v9.17.1-dev...v9.17.2) (2022-11-28)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## [9.17.1](https://github.com/dereekb/dbx-components/compare/v9.17.0-dev...v9.17.1) (2022-11-27)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* added handleFetchJsonParseErrorFunction config ([71c1681](https://github.com/dereekb/dbx-components/commit/71c16810abd7d490769ae956cfa7e9f2e4d5a514))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
5
18
|
# [9.17.0](https://github.com/dereekb/dbx-components/compare/v9.16.4-dev...v9.17.0) (2022-11-25)
|
|
6
19
|
|
|
7
20
|
|
package/fetch/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [9.17.2](https://github.com/dereekb/dbx-components/compare/v9.17.1-dev...v9.17.2) (2022-11-28)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## [9.17.1](https://github.com/dereekb/dbx-components/compare/v9.17.0-dev...v9.17.1) (2022-11-27)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* added handleFetchJsonParseErrorFunction config ([71c1681](https://github.com/dereekb/dbx-components/commit/71c16810abd7d490769ae956cfa7e9f2e4d5a514))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
5
18
|
# [9.17.0](https://github.com/dereekb/dbx-components/compare/v9.16.4-dev...v9.17.0) (2022-11-25)
|
|
6
19
|
|
|
7
20
|
|
package/fetch/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dereekb/util/fetch",
|
|
3
|
-
"version": "9.17.
|
|
3
|
+
"version": "9.17.2",
|
|
4
4
|
"main": "./src/index.js",
|
|
5
5
|
"typings": "./src/index.d.ts",
|
|
6
6
|
"dependencies": {},
|
|
7
7
|
"peerDependencies": {
|
|
8
|
-
"@dereekb/util": "9.17.
|
|
8
|
+
"@dereekb/util": "9.17.2",
|
|
9
9
|
"lodash.isequal": "^4.5.0",
|
|
10
10
|
"make-error": "^1.3.0",
|
|
11
11
|
"class-validator": "^0.13.2",
|
package/fetch/src/lib/json.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { FetchMethod, ConfiguredFetch } from './fetch.type';
|
|
2
2
|
import { FetchURLInput } from './url';
|
|
3
3
|
export declare type FetchJsonBody = string | object;
|
|
4
|
+
export declare class JsonResponseParseError extends Error {
|
|
5
|
+
readonly response: Response;
|
|
6
|
+
constructor(response: Response);
|
|
7
|
+
}
|
|
4
8
|
/**
|
|
5
9
|
* Converts the input to a JSON string, or undefined if not provided.
|
|
6
10
|
*
|
|
@@ -19,8 +23,11 @@ export declare type FetchJsonWithInputFunction = <R>(url: FetchURLInput, input:
|
|
|
19
23
|
* Used to fetch from the input url and retrieve a JSON response.
|
|
20
24
|
*/
|
|
21
25
|
export declare type FetchJsonFunction = FetchJsonGetFunction & FetchJsonMethodAndBodyFunction & FetchJsonWithInputFunction;
|
|
26
|
+
export declare type HandleFetchJsonParseErrorFunction = (response: Response) => string | null | never;
|
|
27
|
+
export declare const throwJsonResponseParseErrorFunction: HandleFetchJsonParseErrorFunction;
|
|
28
|
+
export declare const returnNullHandleFetchJsonParseErrorFunction: HandleFetchJsonParseErrorFunction;
|
|
22
29
|
/**
|
|
23
30
|
* Creates a FetchJsonFunction from the input ConfiguredFetch.
|
|
24
31
|
*/
|
|
25
|
-
export declare function fetchJsonFunction(fetch: ConfiguredFetch): FetchJsonFunction;
|
|
32
|
+
export declare function fetchJsonFunction(fetch: ConfiguredFetch, handleFetchJsonParseErrorFunction?: HandleFetchJsonParseErrorFunction): FetchJsonFunction;
|
|
26
33
|
export declare function fetchJsonRequestInit(methodOrInput?: string | FetchJsonInput, body?: FetchJsonBody): RequestInit;
|
package/fetch/src/lib/json.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchJsonRequestInit = exports.fetchJsonFunction = exports.fetchJsonBodyString = void 0;
|
|
3
|
+
exports.fetchJsonRequestInit = exports.fetchJsonFunction = exports.returnNullHandleFetchJsonParseErrorFunction = exports.throwJsonResponseParseErrorFunction = exports.fetchJsonBodyString = exports.JsonResponseParseError = void 0;
|
|
4
4
|
const url_1 = require("./url");
|
|
5
|
+
class JsonResponseParseError extends Error {
|
|
6
|
+
constructor(response) {
|
|
7
|
+
super('Failed to parse the JSON body.');
|
|
8
|
+
this.response = response;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.JsonResponseParseError = JsonResponseParseError;
|
|
5
12
|
/**
|
|
6
13
|
* Converts the input to a JSON string, or undefined if not provided.
|
|
7
14
|
*
|
|
@@ -12,15 +19,21 @@ function fetchJsonBodyString(body) {
|
|
|
12
19
|
return body != null ? (typeof body === 'string' ? body : JSON.stringify(body)) : undefined;
|
|
13
20
|
}
|
|
14
21
|
exports.fetchJsonBodyString = fetchJsonBodyString;
|
|
22
|
+
const throwJsonResponseParseErrorFunction = (response) => {
|
|
23
|
+
throw new JsonResponseParseError(response);
|
|
24
|
+
};
|
|
25
|
+
exports.throwJsonResponseParseErrorFunction = throwJsonResponseParseErrorFunction;
|
|
26
|
+
const returnNullHandleFetchJsonParseErrorFunction = (response) => null;
|
|
27
|
+
exports.returnNullHandleFetchJsonParseErrorFunction = returnNullHandleFetchJsonParseErrorFunction;
|
|
15
28
|
/**
|
|
16
29
|
* Creates a FetchJsonFunction from the input ConfiguredFetch.
|
|
17
30
|
*/
|
|
18
|
-
function fetchJsonFunction(fetch) {
|
|
31
|
+
function fetchJsonFunction(fetch, handleFetchJsonParseErrorFunction = exports.throwJsonResponseParseErrorFunction) {
|
|
19
32
|
return (url, methodOrInput, body) => {
|
|
20
33
|
const requestUrl = (0, url_1.fetchURL)(url);
|
|
21
34
|
const requestInit = fetchJsonRequestInit(methodOrInput, body);
|
|
22
35
|
const response = fetch(requestUrl, requestInit);
|
|
23
|
-
return response.then((x) => x.json());
|
|
36
|
+
return response.then((x) => x.json().catch(handleFetchJsonParseErrorFunction));
|
|
24
37
|
};
|
|
25
38
|
}
|
|
26
39
|
exports.fetchJsonFunction = fetchJsonFunction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../../../../../packages/util/fetch/src/lib/json.ts"],"names":[],"mappings":";;;AACA,+BAAgD;AAIhD;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,IAA+B;IACjE,OAAO,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7F,CAAC;AAFD,kDAEC;
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../../../../../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CAAC;AAPD,8CAOC;AAED,SAAgB,oBAAoB,CAAC,gBAAyC,KAAK,EAAE,IAAoB;IACvG,IAAI,MAAsB,CAAC;IAE3B,IAAI,aAAa,KAAK,IAAI,EAAE;QAC1B,MAAM,GAAG;YACP,MAAM,EAAE,KAAK;SACd,CAAC;KACH;SAAM,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE;QAC5C,MAAM,GAAG;YACP,MAAM,EAAE,aAAa;YACrB,IAAI;SACL,CAAC;KACH;SAAM;QACL,MAAM,GAAG,aAAa,CAAC;KACxB;IAED,MAAM,WAAW,mCACZ,MAAM,KACT,IAAI,EAAE,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,GACvC,CAAC;IAEF,OAAO,WAAW,CAAC;AACrB,CAAC;AAtBD,oDAsBC"}
|
package/package.json
CHANGED
package/test/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [9.17.2](https://github.com/dereekb/dbx-components/compare/v9.17.1-dev...v9.17.2) (2022-11-28)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## [9.17.1](https://github.com/dereekb/dbx-components/compare/v9.17.0-dev...v9.17.1) (2022-11-27)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
5
13
|
# [9.17.0](https://github.com/dereekb/dbx-components/compare/v9.16.4-dev...v9.17.0) (2022-11-25)
|
|
6
14
|
|
|
7
15
|
|
package/test/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dereekb/util/test",
|
|
3
|
-
"version": "9.17.
|
|
3
|
+
"version": "9.17.2",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"typings": "./src/index.d.ts",
|
|
7
7
|
"dependencies": {},
|
|
8
8
|
"peerDependencies": {
|
|
9
|
-
"@dereekb/util": "9.17.
|
|
9
|
+
"@dereekb/util": "9.17.2",
|
|
10
10
|
"lodash.isequal": "^4.5.0",
|
|
11
11
|
"make-error": "^1.3.0",
|
|
12
12
|
"class-validator": "^0.13.2",
|