This repository has been archived by the owner on Feb 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AAE-7657] Let js-api depend on generic http client (#1332)
* [AAE-7657] Let js-api depend on generic http client * Add another overrides * Fix other typing issues * Fix other typing issues II * Fix cspell * Fix unit tests * Fix unit tests II. * Workaround for old circular dependency issues * Clean up workaround
- Loading branch information
1 parent
e69b01f
commit 2730595
Showing
56 changed files
with
411 additions
and
317 deletions.
There are no files selected for viewing
36 changes: 5 additions & 31 deletions
36
api-codegen/src/main/resources/api-code-gen/base.api.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,10 @@ | ||
{{>licenseInfo}} | ||
|
||
import { AlfrescoApi } from '../../../alfrescoApi'; | ||
import { AlfrescoApiClient, RequestOptions } from '../../../alfrescoApiClient'; | ||
import { ApiClient } from '../../../api-clients/api-client'; | ||
import { HttpClient } from '../../../api-clients/http-client.interface'; | ||
|
||
export class BaseApi { | ||
apiClient: AlfrescoApiClient; | ||
constructor(alfrescoApi?: AlfrescoApi) { | ||
if (alfrescoApi) { | ||
this.apiClient = alfrescoApi.contentClient; | ||
} | ||
} | ||
|
||
post<T = any>(options: RequestOptions): Promise<T> { | ||
return this.apiClient.post<T>(options); | ||
} | ||
|
||
put<T = any>(options: RequestOptions): Promise<T> { | ||
return this.apiClient.put<T>(options); | ||
} | ||
|
||
get<T = any>(options: RequestOptions): Promise<T> { | ||
return this.apiClient.get<T>(options); | ||
} | ||
|
||
delete<T = void>(options: RequestOptions): Promise<T> { | ||
return this.apiClient.delete(options); | ||
} | ||
|
||
errorMessage(param: string, methodName: string) { | ||
return `Missing param ${param} in ${methodName}`; | ||
export abstract class BaseApi extends ApiClient { | ||
get apiClient(): HttpClient { | ||
return this.httpClient ?? this.alfrescoApi.contentClient; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/*! | ||
* @license | ||
* Copyright 2018 Alfresco Software, Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { AlfrescoApiType } from "../to-deprecate/alfresco-api-type"; | ||
import { LegacyAlfrescoApiHelper } from "../to-deprecate/legacy-alfresco-api.helper"; | ||
import { HttpClient, RequestOptions } from "./http-client.interface"; | ||
|
||
export abstract class ApiClient { | ||
|
||
protected alfrescoApi: AlfrescoApiType; | ||
protected httpClient: HttpClient; | ||
|
||
get apiClient(): HttpClient { | ||
return this.httpClient; | ||
} | ||
|
||
constructor(legacyApi?: AlfrescoApiType); | ||
constructor(httpClient: HttpClient); | ||
constructor(httpClient?: AlfrescoApiType | HttpClient) { | ||
// TODO: remove legacyApi?: AlfrescoApi option and clean up this code. BREAKING CHANGE! | ||
if (httpClient instanceof LegacyAlfrescoApiHelper) { | ||
this.alfrescoApi = httpClient as AlfrescoApiType; | ||
} else { | ||
this.httpClient = httpClient as HttpClient; | ||
} | ||
} | ||
|
||
post<T = any>(options: RequestOptions): Promise<T> { | ||
return this.apiClient.post<T>(options); | ||
} | ||
|
||
put<T = any>(options: RequestOptions): Promise<T> { | ||
return this.apiClient.put<T>(options); | ||
} | ||
|
||
get<T = any>(options: RequestOptions): Promise<T> { | ||
return this.apiClient.get<T>(options); | ||
} | ||
|
||
delete<T = void>(options: RequestOptions): Promise<T> { | ||
return this.apiClient.delete(options); | ||
} | ||
|
||
errorMessage(param: string, methodName: string) { | ||
return `Missing param ${param} in ${methodName}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/*! | ||
* @license | ||
* Copyright 2019 Alfresco Software, Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export interface RequestOptions { | ||
path: string; | ||
httpMethod?: string; | ||
pathParams?: any; | ||
queryParams?: any; | ||
headerParams?: any; | ||
formParams?: any; | ||
bodyParam?: any; | ||
contentTypes?: string[]; | ||
accepts?: string[]; | ||
returnType?: any; | ||
contextRoot?: string; | ||
responseType?: string; | ||
url?: string; | ||
} | ||
|
||
export interface HttpClientConfig { | ||
contextRoot: string; | ||
host?: string; // Should be mandatory but can't make it because of AlfrescoApiConfig incompatibility 😕 | ||
servicePath?: string; // Should be mandatory but can't make it because of AlfrescoApiConfig incompatibility 😕 | ||
} | ||
export interface HttpClient { | ||
basePath: string; | ||
config: HttpClientConfig; | ||
|
||
request<T = any>(options: RequestOptions): Promise<T>; | ||
post<T = any>(options: RequestOptions): Promise<T>; | ||
put<T = any>(options: RequestOptions): Promise<T>; | ||
get<T = any>(options: RequestOptions): Promise<T>; | ||
delete<T = void>(options: RequestOptions): Promise<T>; | ||
/** @deprecated */ | ||
callApi( | ||
path: string, | ||
httpMethod: string, | ||
pathParams?: any, | ||
queryParams?: any, | ||
headerParams?: any, | ||
formParams?: any, | ||
bodyParam?: any, | ||
contentTypes?: string[], | ||
accepts?: string[], | ||
returnType?: any, | ||
contextRoot?: string, | ||
responseType?: string, | ||
url?: string | ||
): Promise<any>; | ||
/** @deprecated */ | ||
callCustomApi( | ||
path: string, | ||
httpMethod: string, | ||
pathParams?: any, | ||
queryParams?: any, | ||
headerParams?: any, | ||
formParams?: any, | ||
bodyParam?: any, | ||
contentTypes?: string[], | ||
accepts?: string[], | ||
returnType?: any, | ||
contextRoot?: string, | ||
responseType?: string | ||
): Promise<any>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.