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",
|
||||
"version": "0.4.0",
|
||||
"version": "0.4.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "react-rest-request",
|
||||
"version": "0.4.0",
|
||||
"version": "0.4.1",
|
||||
"description": "Minimalistic REST API client for React inspired by Apollo",
|
||||
"readme": "README.md",
|
||||
"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 {
|
||||
private config;
|
||||
constructor(config: ClientConfig);
|
||||
private prepareRequest;
|
||||
prepareRequest(props: PrepareRequestProps): Request;
|
||||
request<Data extends Record<string, any>>({ transformResponseData, ...restProps }: RequestProps<Data>): Promise<ClientResponse<Data>>;
|
||||
}
|
||||
export {};
|
||||
|
|
|
@ -17,10 +17,16 @@ export class Client {
|
|||
this.config = config;
|
||||
}
|
||||
prepareRequest(props) {
|
||||
var _a;
|
||||
const requestCanContainBody = [Method.POST, Method.PATCH, Method.PUT].includes(props.method);
|
||||
const url = /https?:\/\//.test(props.url) ?
|
||||
new URL(props.url)
|
||||
: new URL(this.config.baseUrl + props.url);
|
||||
const defaultBaseUrl = (_a = window) === null || _a === void 0 ? void 0 : _a.location.href;
|
||||
const sourceUrl = /https?:\/\//.test(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) {
|
||||
invariant(!(props.variables instanceof FormData), `Method ${props.method} cannot contain body`);
|
||||
url.search = urlSearchParamsFromObject(props.variables).toString();
|
||||
|
|
Reference in a new issue