mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
AAE-30882 Simplify typing of methods
This commit is contained in:
parent
e50a3f04ce
commit
7f4a46f4c3
@ -45,20 +45,12 @@ export class SuperagentHttpClient implements HttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
request<T = any>(url: string, options: RequestOptions, securityOptions: SecurityOptions, emitters: Emitters): Promise<T> {
|
request<T = any>(url: string, options: RequestOptions, securityOptions: SecurityOptions, emitters: Emitters): Promise<T> {
|
||||||
const { httpMethod, queryParams, headerParams, formParams, bodyParam, contentType, accept, responseType, returnType } = options;
|
const { returnType } = options;
|
||||||
const { eventEmitter, apiClientEmitter } = emitters;
|
const { eventEmitter, apiClientEmitter } = emitters;
|
||||||
|
|
||||||
const { urlWithParams, fetchOptions } = this.buildRequest({
|
const { urlWithParams, fetchOptions } = this.buildRequest({
|
||||||
httpMethod,
|
...options,
|
||||||
url,
|
url,
|
||||||
queryParams,
|
|
||||||
headerParams,
|
|
||||||
formParams,
|
|
||||||
bodyParam,
|
|
||||||
contentType,
|
|
||||||
accept,
|
|
||||||
responseType,
|
|
||||||
returnType,
|
|
||||||
securityOptions
|
securityOptions
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -120,19 +112,7 @@ export class SuperagentHttpClient implements HttpClient {
|
|||||||
responseType,
|
responseType,
|
||||||
returnType,
|
returnType,
|
||||||
securityOptions
|
securityOptions
|
||||||
}: {
|
}: RequestOptions & { securityOptions: SecurityOptions }) {
|
||||||
httpMethod: string;
|
|
||||||
url: string;
|
|
||||||
queryParams: { [key: string]: any };
|
|
||||||
headerParams: { [key: string]: any };
|
|
||||||
formParams: { [key: string]: any };
|
|
||||||
bodyParam: string | object;
|
|
||||||
contentType: string;
|
|
||||||
accept: string;
|
|
||||||
responseType: string;
|
|
||||||
returnType: string;
|
|
||||||
securityOptions: SecurityOptions;
|
|
||||||
}) {
|
|
||||||
const urlWithParams = new URL(url);
|
const urlWithParams = new URL(url);
|
||||||
urlWithParams.search = new URLSearchParams(SuperagentHttpClient.normalizeParams(queryParams)).toString();
|
urlWithParams.search = new URLSearchParams(SuperagentHttpClient.normalizeParams(queryParams)).toString();
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ jest.mock('ofetch', () => ({
|
|||||||
|
|
||||||
jest.mock('../src/utils', () => ({
|
jest.mock('../src/utils', () => ({
|
||||||
isBrowser: jest.fn(() => true),
|
isBrowser: jest.fn(() => true),
|
||||||
paramToString: (param: any) => String(param)
|
paramToString: (param: unknown) => String(param)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('SuperagentHttpClient', () => {
|
describe('SuperagentHttpClient', () => {
|
||||||
@ -100,14 +100,10 @@ describe('SuperagentHttpClient', () => {
|
|||||||
const securityOptions = { ...defaultSecurityOptions };
|
const securityOptions = { ...defaultSecurityOptions };
|
||||||
|
|
||||||
const request = client['buildRequest']({
|
const request = client['buildRequest']({
|
||||||
|
...options,
|
||||||
|
path: '',
|
||||||
httpMethod,
|
httpMethod,
|
||||||
url,
|
url,
|
||||||
queryParams: options.queryParams,
|
|
||||||
headerParams: options.headerParams,
|
|
||||||
formParams: options.formParams,
|
|
||||||
contentType: options.contentType,
|
|
||||||
accept: options.accept,
|
|
||||||
responseType: options.responseType,
|
|
||||||
bodyParam: null,
|
bodyParam: null,
|
||||||
returnType: null,
|
returnType: null,
|
||||||
securityOptions
|
securityOptions
|
||||||
@ -134,14 +130,10 @@ describe('SuperagentHttpClient', () => {
|
|||||||
(isBrowser as jest.Mock).mockReturnValue(false);
|
(isBrowser as jest.Mock).mockReturnValue(false);
|
||||||
|
|
||||||
const request = client['buildRequest']({
|
const request = client['buildRequest']({
|
||||||
|
...options,
|
||||||
|
path: '',
|
||||||
httpMethod,
|
httpMethod,
|
||||||
url,
|
url,
|
||||||
queryParams: options.queryParams,
|
|
||||||
headerParams: options.headerParams,
|
|
||||||
formParams: options.formParams,
|
|
||||||
contentType: options.contentType,
|
|
||||||
accept: options.accept,
|
|
||||||
responseType: options.responseType,
|
|
||||||
bodyParam: null,
|
bodyParam: null,
|
||||||
returnType: null,
|
returnType: null,
|
||||||
securityOptions
|
securityOptions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user