From a51ad53b00c94ba8fe0bba2a80744b19fabc367d Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 26 May 2020 16:38:40 +0200 Subject: [PATCH] packages/core: group api implementations by the name of the declarations --- .../{ => AlertApi}/AlertApiForwarder.ts | 9 ++++++--- .../api/apis/implementations/AlertApi/index.ts | 17 +++++++++++++++++ .../AppThemeSelector.test.ts | 0 .../AppThemeSelector.ts | 4 ++-- .../{AppThemeSelector => AppThemeApi}/index.ts | 0 .../{ => ErrorApi}/ErrorAlerter.ts | 2 +- .../{ => ErrorApi}/ErrorApiForwarder.ts | 9 ++++++--- .../api/apis/implementations/ErrorApi/index.ts | 18 ++++++++++++++++++ .../MockOAuthApi.test.ts | 0 .../MockOAuthApi.ts | 0 .../OAuthPendingRequests.test.ts | 0 .../OAuthPendingRequests.ts | 0 .../OAuthRequestManager.test.ts | 0 .../OAuthRequestManager.ts | 0 .../index.ts | 0 .../core/src/api/apis/implementations/index.ts | 10 +++++----- .../AuthConnector/DefaultAuthConnector.test.ts | 2 +- .../RefreshingAuthSessionManager.ts | 3 +-- 18 files changed, 57 insertions(+), 17 deletions(-) rename packages/core/src/api/apis/implementations/{ => AlertApi}/AlertApiForwarder.ts (78%) create mode 100644 packages/core/src/api/apis/implementations/AlertApi/index.ts rename packages/core/src/api/apis/implementations/{AppThemeSelector => AppThemeApi}/AppThemeSelector.test.ts (100%) rename packages/core/src/api/apis/implementations/{AppThemeSelector => AppThemeApi}/AppThemeSelector.ts (94%) rename packages/core/src/api/apis/implementations/{AppThemeSelector => AppThemeApi}/index.ts (100%) rename packages/core/src/api/apis/implementations/{ => ErrorApi}/ErrorAlerter.ts (94%) rename packages/core/src/api/apis/implementations/{ => ErrorApi}/ErrorApiForwarder.ts (80%) create mode 100644 packages/core/src/api/apis/implementations/ErrorApi/index.ts rename packages/core/src/api/apis/implementations/{OAuthRequestManager => OAuthRequestApi}/MockOAuthApi.test.ts (100%) rename packages/core/src/api/apis/implementations/{OAuthRequestManager => OAuthRequestApi}/MockOAuthApi.ts (100%) rename packages/core/src/api/apis/implementations/{OAuthRequestManager => OAuthRequestApi}/OAuthPendingRequests.test.ts (100%) rename packages/core/src/api/apis/implementations/{OAuthRequestManager => OAuthRequestApi}/OAuthPendingRequests.ts (100%) rename packages/core/src/api/apis/implementations/{OAuthRequestManager => OAuthRequestApi}/OAuthRequestManager.test.ts (100%) rename packages/core/src/api/apis/implementations/{OAuthRequestManager => OAuthRequestApi}/OAuthRequestManager.ts (100%) rename packages/core/src/api/apis/implementations/{OAuthRequestManager => OAuthRequestApi}/index.ts (100%) diff --git a/packages/core/src/api/apis/implementations/AlertApiForwarder.ts b/packages/core/src/api/apis/implementations/AlertApi/AlertApiForwarder.ts similarity index 78% rename from packages/core/src/api/apis/implementations/AlertApiForwarder.ts rename to packages/core/src/api/apis/implementations/AlertApi/AlertApiForwarder.ts index c95408283c..901d3b57cc 100644 --- a/packages/core/src/api/apis/implementations/AlertApiForwarder.ts +++ b/packages/core/src/api/apis/implementations/AlertApi/AlertApiForwarder.ts @@ -13,10 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { AlertApi, AlertMessage } from '../../../'; -import { PublishSubject } from './lib'; -import { Observable } from '../../types'; +import { AlertApi, AlertMessage } from '../../../..'; +import { PublishSubject } from '../lib'; +import { Observable } from '../../../types'; +/** + * Base implementation for the AlertApi that simply forwards alerts to consumers. + */ export class AlertApiForwarder implements AlertApi { private readonly subject = new PublishSubject(); diff --git a/packages/core/src/api/apis/implementations/AlertApi/index.ts b/packages/core/src/api/apis/implementations/AlertApi/index.ts new file mode 100644 index 0000000000..12ab8bc60c --- /dev/null +++ b/packages/core/src/api/apis/implementations/AlertApi/index.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2020 Spotify AB + * + * 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 { AlertApiForwarder } from './AlertApiForwarder'; diff --git a/packages/core/src/api/apis/implementations/AppThemeSelector/AppThemeSelector.test.ts b/packages/core/src/api/apis/implementations/AppThemeApi/AppThemeSelector.test.ts similarity index 100% rename from packages/core/src/api/apis/implementations/AppThemeSelector/AppThemeSelector.test.ts rename to packages/core/src/api/apis/implementations/AppThemeApi/AppThemeSelector.test.ts diff --git a/packages/core/src/api/apis/implementations/AppThemeSelector/AppThemeSelector.ts b/packages/core/src/api/apis/implementations/AppThemeApi/AppThemeSelector.ts similarity index 94% rename from packages/core/src/api/apis/implementations/AppThemeSelector/AppThemeSelector.ts rename to packages/core/src/api/apis/implementations/AppThemeApi/AppThemeSelector.ts index 7f6659e641..0f554ed7f1 100644 --- a/packages/core/src/api/apis/implementations/AppThemeSelector/AppThemeSelector.ts +++ b/packages/core/src/api/apis/implementations/AppThemeApi/AppThemeSelector.ts @@ -33,7 +33,7 @@ export class AppThemeSelector implements AppThemeApi { selector.setActiveThemeId(initialThemeId); - selector.activeThemeId$().subscribe((themeId) => { + selector.activeThemeId$().subscribe(themeId => { if (themeId) { window.localStorage.setItem(STORAGE_KEY, themeId); } else { @@ -41,7 +41,7 @@ export class AppThemeSelector implements AppThemeApi { } }); - window.addEventListener('storage', (event) => { + window.addEventListener('storage', event => { if (event.key === STORAGE_KEY) { const themeId = localStorage.getItem(STORAGE_KEY) ?? undefined; selector.setActiveThemeId(themeId); diff --git a/packages/core/src/api/apis/implementations/AppThemeSelector/index.ts b/packages/core/src/api/apis/implementations/AppThemeApi/index.ts similarity index 100% rename from packages/core/src/api/apis/implementations/AppThemeSelector/index.ts rename to packages/core/src/api/apis/implementations/AppThemeApi/index.ts diff --git a/packages/core/src/api/apis/implementations/ErrorAlerter.ts b/packages/core/src/api/apis/implementations/ErrorApi/ErrorAlerter.ts similarity index 94% rename from packages/core/src/api/apis/implementations/ErrorAlerter.ts rename to packages/core/src/api/apis/implementations/ErrorApi/ErrorAlerter.ts index 81d0cc8fb8..903463d7de 100644 --- a/packages/core/src/api/apis/implementations/ErrorAlerter.ts +++ b/packages/core/src/api/apis/implementations/ErrorApi/ErrorAlerter.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ErrorApi, ErrorContext, AlertApi } from '../../../'; +import { ErrorApi, ErrorContext, AlertApi } from '../../../..'; /** * Decorates an ErrorApi by also forwarding error messages diff --git a/packages/core/src/api/apis/implementations/ErrorApiForwarder.ts b/packages/core/src/api/apis/implementations/ErrorApi/ErrorApiForwarder.ts similarity index 80% rename from packages/core/src/api/apis/implementations/ErrorApiForwarder.ts rename to packages/core/src/api/apis/implementations/ErrorApi/ErrorApiForwarder.ts index a61fdae5c1..6729050401 100644 --- a/packages/core/src/api/apis/implementations/ErrorApiForwarder.ts +++ b/packages/core/src/api/apis/implementations/ErrorApi/ErrorApiForwarder.ts @@ -13,10 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ErrorApi, ErrorContext } from '../../../'; -import { PublishSubject } from './lib'; -import { Observable } from '../../types'; +import { ErrorApi, ErrorContext } from '../../../..'; +import { PublishSubject } from '../lib'; +import { Observable } from '../../../types'; +/** + * Base implementation for the ErrorApi that simply forwards errors to consumers. + */ export class ErrorApiForwarder implements ErrorApi { private readonly subject = new PublishSubject<{ error: Error; diff --git a/packages/core/src/api/apis/implementations/ErrorApi/index.ts b/packages/core/src/api/apis/implementations/ErrorApi/index.ts new file mode 100644 index 0000000000..757dfd0d8f --- /dev/null +++ b/packages/core/src/api/apis/implementations/ErrorApi/index.ts @@ -0,0 +1,18 @@ +/* + * Copyright 2020 Spotify AB + * + * 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 { ErrorAlerter } from './ErrorAlerter'; +export { ErrorApiForwarder } from './ErrorApiForwarder'; diff --git a/packages/core/src/api/apis/implementations/OAuthRequestManager/MockOAuthApi.test.ts b/packages/core/src/api/apis/implementations/OAuthRequestApi/MockOAuthApi.test.ts similarity index 100% rename from packages/core/src/api/apis/implementations/OAuthRequestManager/MockOAuthApi.test.ts rename to packages/core/src/api/apis/implementations/OAuthRequestApi/MockOAuthApi.test.ts diff --git a/packages/core/src/api/apis/implementations/OAuthRequestManager/MockOAuthApi.ts b/packages/core/src/api/apis/implementations/OAuthRequestApi/MockOAuthApi.ts similarity index 100% rename from packages/core/src/api/apis/implementations/OAuthRequestManager/MockOAuthApi.ts rename to packages/core/src/api/apis/implementations/OAuthRequestApi/MockOAuthApi.ts diff --git a/packages/core/src/api/apis/implementations/OAuthRequestManager/OAuthPendingRequests.test.ts b/packages/core/src/api/apis/implementations/OAuthRequestApi/OAuthPendingRequests.test.ts similarity index 100% rename from packages/core/src/api/apis/implementations/OAuthRequestManager/OAuthPendingRequests.test.ts rename to packages/core/src/api/apis/implementations/OAuthRequestApi/OAuthPendingRequests.test.ts diff --git a/packages/core/src/api/apis/implementations/OAuthRequestManager/OAuthPendingRequests.ts b/packages/core/src/api/apis/implementations/OAuthRequestApi/OAuthPendingRequests.ts similarity index 100% rename from packages/core/src/api/apis/implementations/OAuthRequestManager/OAuthPendingRequests.ts rename to packages/core/src/api/apis/implementations/OAuthRequestApi/OAuthPendingRequests.ts diff --git a/packages/core/src/api/apis/implementations/OAuthRequestManager/OAuthRequestManager.test.ts b/packages/core/src/api/apis/implementations/OAuthRequestApi/OAuthRequestManager.test.ts similarity index 100% rename from packages/core/src/api/apis/implementations/OAuthRequestManager/OAuthRequestManager.test.ts rename to packages/core/src/api/apis/implementations/OAuthRequestApi/OAuthRequestManager.test.ts diff --git a/packages/core/src/api/apis/implementations/OAuthRequestManager/OAuthRequestManager.ts b/packages/core/src/api/apis/implementations/OAuthRequestApi/OAuthRequestManager.ts similarity index 100% rename from packages/core/src/api/apis/implementations/OAuthRequestManager/OAuthRequestManager.ts rename to packages/core/src/api/apis/implementations/OAuthRequestApi/OAuthRequestManager.ts diff --git a/packages/core/src/api/apis/implementations/OAuthRequestManager/index.ts b/packages/core/src/api/apis/implementations/OAuthRequestApi/index.ts similarity index 100% rename from packages/core/src/api/apis/implementations/OAuthRequestManager/index.ts rename to packages/core/src/api/apis/implementations/OAuthRequestApi/index.ts diff --git a/packages/core/src/api/apis/implementations/index.ts b/packages/core/src/api/apis/implementations/index.ts index 1f2b91c16d..bb77cf5bd3 100644 --- a/packages/core/src/api/apis/implementations/index.ts +++ b/packages/core/src/api/apis/implementations/index.ts @@ -19,8 +19,8 @@ // Plugins should rely on these APIs for functionality as much as possible. export * from './auth'; -export * from './AppThemeSelector'; -export * from './AlertApiForwarder'; -export * from './ErrorAlerter'; -export * from './ErrorApiForwarder'; -export * from './OAuthRequestManager'; + +export * from './AlertApi'; +export * from './AppThemeApi'; +export * from './ErrorApi'; +export * from './OAuthRequestApi'; diff --git a/packages/core/src/api/apis/implementations/lib/AuthConnector/DefaultAuthConnector.test.ts b/packages/core/src/api/apis/implementations/lib/AuthConnector/DefaultAuthConnector.test.ts index f3698b4e15..d4f95f7907 100644 --- a/packages/core/src/api/apis/implementations/lib/AuthConnector/DefaultAuthConnector.test.ts +++ b/packages/core/src/api/apis/implementations/lib/AuthConnector/DefaultAuthConnector.test.ts @@ -16,7 +16,7 @@ import ProviderIcon from '@material-ui/icons/AcUnit'; import { DefaultAuthConnector } from './DefaultAuthConnector'; -import MockOAuthApi from '../../OAuthRequestManager/MockOAuthApi'; +import MockOAuthApi from '../../OAuthRequestApi/MockOAuthApi'; import * as loginPopup from '../loginPopup'; const anyFetch = fetch as any; diff --git a/packages/core/src/api/apis/implementations/lib/AuthSessionManager/RefreshingAuthSessionManager.ts b/packages/core/src/api/apis/implementations/lib/AuthSessionManager/RefreshingAuthSessionManager.ts index 0cb0f2f1ea..cbd6d5ca46 100644 --- a/packages/core/src/api/apis/implementations/lib/AuthSessionManager/RefreshingAuthSessionManager.ts +++ b/packages/core/src/api/apis/implementations/lib/AuthSessionManager/RefreshingAuthSessionManager.ts @@ -20,8 +20,7 @@ import { SessionShouldRefreshFunc, } from './types'; import { AuthConnector } from '../AuthConnector'; -import { SessionScopeHelper } from './common'; -import { hasScopes } from '../../OAuthRequestManager/OAuthPendingRequests'; +import { SessionScopeHelper, hasScopes } from './common'; type Options = { /** The connector used for acting on the auth session */