chore: bump version
This commit is contained in:
parent
8a87c9af14
commit
96c7ea554c
4 changed files with 12 additions and 6 deletions
2
package-lock.json
generated
2
package-lock.json
generated
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "react-rest-request",
|
"name": "react-rest-request",
|
||||||
"version": "0.4.0",
|
"version": "0.4.1",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "react-rest-request",
|
"name": "react-rest-request",
|
||||||
"version": "0.4.0",
|
"version": "0.4.1",
|
||||||
"description": "Minimalistic REST API client for React inspired by Apollo",
|
"description": "Minimalistic REST API client for React inspired by Apollo",
|
||||||
"readme": "README.md",
|
"readme": "README.md",
|
||||||
"main": "./target/index.js",
|
"main": "./target/index.js",
|
||||||
|
|
2
target/client.d.ts
vendored
2
target/client.d.ts
vendored
|
@ -17,7 +17,7 @@ export declare type ClientResponse<Data extends Record<string, any>> = Readonly<
|
||||||
export declare class Client {
|
export declare class Client {
|
||||||
private config;
|
private config;
|
||||||
constructor(config: ClientConfig);
|
constructor(config: ClientConfig);
|
||||||
private prepareRequest;
|
prepareRequest(props: PrepareRequestProps): Request;
|
||||||
request<Data extends Record<string, any>>({ transformResponseData, ...restProps }: RequestProps<Data>): Promise<ClientResponse<Data>>;
|
request<Data extends Record<string, any>>({ transformResponseData, ...restProps }: RequestProps<Data>): Promise<ClientResponse<Data>>;
|
||||||
}
|
}
|
||||||
export {};
|
export {};
|
||||||
|
|
|
@ -17,10 +17,16 @@ export class Client {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
prepareRequest(props) {
|
prepareRequest(props) {
|
||||||
|
var _a;
|
||||||
const requestCanContainBody = [Method.POST, Method.PATCH, Method.PUT].includes(props.method);
|
const requestCanContainBody = [Method.POST, Method.PATCH, Method.PUT].includes(props.method);
|
||||||
const url = /https?:\/\//.test(props.url) ?
|
const defaultBaseUrl = (_a = window) === null || _a === void 0 ? void 0 : _a.location.href;
|
||||||
new URL(props.url)
|
const sourceUrl = /https?:\/\//.test(props.url) ?
|
||||||
: new URL(this.config.baseUrl + props.url);
|
props.url
|
||||||
|
: this.config.baseUrl + props.url;
|
||||||
|
if (!defaultBaseUrl && sourceUrl.startsWith('/')) {
|
||||||
|
throw new Error(`Invalid request method: ${sourceUrl}`);
|
||||||
|
}
|
||||||
|
const url = new URL(sourceUrl, defaultBaseUrl);
|
||||||
if (!requestCanContainBody) {
|
if (!requestCanContainBody) {
|
||||||
invariant(!(props.variables instanceof FormData), `Method ${props.method} cannot contain body`);
|
invariant(!(props.variables instanceof FormData), `Method ${props.method} cannot contain body`);
|
||||||
url.search = urlSearchParamsFromObject(props.variables).toString();
|
url.search = urlSearchParamsFromObject(props.variables).toString();
|
||||||
|
|
Reference in a new issue