diff --git a/packages/core-app-api/src/apis/implementations/AlertApi/AlertApiForwarder.ts b/packages/core-app-api/src/apis/implementations/AlertApi/AlertApiForwarder.ts index 8bab1b539d..28cb5bc068 100644 --- a/packages/core-app-api/src/apis/implementations/AlertApi/AlertApiForwarder.ts +++ b/packages/core-app-api/src/apis/implementations/AlertApi/AlertApiForwarder.ts @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { AlertApi, AlertMessage } from '@backstage/core-plugin-api'; +import { AlertApi, AlertMessage, Observable } from '@backstage/core-plugin-api'; import { PublishSubject } from '../../../lib/subjects'; -import { Observable } from '../../../types'; /** * Base implementation for the AlertApi that simply forwards alerts to consumers. diff --git a/packages/core-app-api/src/apis/implementations/AppThemeApi/AppThemeSelector.ts b/packages/core-app-api/src/apis/implementations/AppThemeApi/AppThemeSelector.ts index 6d7adbb03a..3bd4d764ea 100644 --- a/packages/core-app-api/src/apis/implementations/AppThemeApi/AppThemeSelector.ts +++ b/packages/core-app-api/src/apis/implementations/AppThemeApi/AppThemeSelector.ts @@ -14,9 +14,8 @@ * limitations under the License. */ -import { AppThemeApi, AppTheme } from '@backstage/core-plugin-api'; +import { AppThemeApi, AppTheme, Observable } from '@backstage/core-plugin-api'; import { BehaviorSubject } from '../../../lib/subjects'; -import { Observable } from '../../../types'; const STORAGE_KEY = 'theme'; diff --git a/packages/core-app-api/src/apis/implementations/ErrorApi/ErrorApiForwarder.ts b/packages/core-app-api/src/apis/implementations/ErrorApi/ErrorApiForwarder.ts index 479fcdf92d..875d07c0a3 100644 --- a/packages/core-app-api/src/apis/implementations/ErrorApi/ErrorApiForwarder.ts +++ b/packages/core-app-api/src/apis/implementations/ErrorApi/ErrorApiForwarder.ts @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ErrorApi, ErrorContext } from '@backstage/core-plugin-api'; +import { ErrorApi, ErrorContext, Observable } from '@backstage/core-plugin-api'; import { PublishSubject } from '../../../lib/subjects'; -import { Observable } from '../../../types'; /** * Base implementation for the ErrorApi that simply forwards errors to consumers. diff --git a/packages/core-app-api/src/apis/implementations/OAuthRequestApi/OAuthPendingRequests.ts b/packages/core-app-api/src/apis/implementations/OAuthRequestApi/OAuthPendingRequests.ts index f0710cb466..370ba9a3a1 100644 --- a/packages/core-app-api/src/apis/implementations/OAuthRequestApi/OAuthPendingRequests.ts +++ b/packages/core-app-api/src/apis/implementations/OAuthRequestApi/OAuthPendingRequests.ts @@ -14,8 +14,8 @@ * limitations under the License. */ +import { Observable } from '@backstage/core-plugin-api'; import { BehaviorSubject } from '../../../lib/subjects'; -import { Observable } from '../../../types'; type RequestQueueEntry = { scopes: Set; diff --git a/packages/core-app-api/src/apis/implementations/OAuthRequestApi/OAuthRequestManager.ts b/packages/core-app-api/src/apis/implementations/OAuthRequestApi/OAuthRequestManager.ts index 7a69e82aab..e50c18d271 100644 --- a/packages/core-app-api/src/apis/implementations/OAuthRequestApi/OAuthRequestManager.ts +++ b/packages/core-app-api/src/apis/implementations/OAuthRequestApi/OAuthRequestManager.ts @@ -19,10 +19,10 @@ import { PendingAuthRequest, AuthRequester, AuthRequesterOptions, + Observable, } from '@backstage/core-plugin-api'; import { OAuthPendingRequests, PendingRequest } from './OAuthPendingRequests'; import { BehaviorSubject } from '../../../lib/subjects'; -import { Observable } from '../../../types'; /** * The OAuthRequestManager is an implementation of the OAuthRequestApi. diff --git a/packages/core-app-api/src/apis/implementations/StorageApi/WebStorage.ts b/packages/core-app-api/src/apis/implementations/StorageApi/WebStorage.ts index 225bf0ea5e..3f49b644f6 100644 --- a/packages/core-app-api/src/apis/implementations/StorageApi/WebStorage.ts +++ b/packages/core-app-api/src/apis/implementations/StorageApi/WebStorage.ts @@ -17,8 +17,8 @@ import { StorageApi, StorageValueChange, ErrorApi, + Observable, } from '@backstage/core-plugin-api'; -import { Observable } from '../../../types'; import ObservableImpl from 'zen-observable'; const buckets = new Map(); diff --git a/packages/core-app-api/src/apis/implementations/auth/github/GithubAuth.ts b/packages/core-app-api/src/apis/implementations/auth/github/GithubAuth.ts index 040fccf0e1..2ab0e5390f 100644 --- a/packages/core-app-api/src/apis/implementations/auth/github/GithubAuth.ts +++ b/packages/core-app-api/src/apis/implementations/auth/github/GithubAuth.ts @@ -24,13 +24,13 @@ import { ProfileInfo, BackstageIdentity, AuthRequestOptions, + Observable, } from '@backstage/core-plugin-api'; import { SessionManager } from '../../../../lib/AuthSessionManager/types'; import { AuthSessionStore, StaticAuthSessionManager, } from '../../../../lib/AuthSessionManager'; -import { Observable } from '../../../../types'; import { OAuthApiCreateOptions } from '../types'; export type GithubAuthResponse = { diff --git a/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2.ts b/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2.ts index a63636b6f1..c6c251a4f5 100644 --- a/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2.ts +++ b/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2.ts @@ -18,7 +18,6 @@ import OAuth2Icon from '@material-ui/icons/AcUnit'; import { DefaultAuthConnector } from '../../../../lib/AuthConnector'; import { RefreshingAuthSessionManager } from '../../../../lib/AuthSessionManager'; import { SessionManager } from '../../../../lib/AuthSessionManager/types'; -import { Observable } from '../../../../types'; import { AuthRequestOptions, BackstageIdentity, @@ -29,6 +28,7 @@ import { SessionState, SessionApi, BackstageIdentityApi, + Observable, } from '@backstage/core-plugin-api'; import { OAuth2Session } from './types'; import { OAuthApiCreateOptions } from '../types'; diff --git a/packages/core-app-api/src/apis/implementations/auth/saml/SamlAuth.ts b/packages/core-app-api/src/apis/implementations/auth/saml/SamlAuth.ts index 4bb887eb80..7f747d6977 100644 --- a/packages/core-app-api/src/apis/implementations/auth/saml/SamlAuth.ts +++ b/packages/core-app-api/src/apis/implementations/auth/saml/SamlAuth.ts @@ -17,7 +17,6 @@ import SamlIcon from '@material-ui/icons/AcUnit'; import { DirectAuthConnector } from '../../../../lib/AuthConnector'; import { SessionManager } from '../../../../lib/AuthSessionManager/types'; -import { Observable } from '../../../../types'; import { ProfileInfo, BackstageIdentity, @@ -26,6 +25,7 @@ import { ProfileInfoApi, BackstageIdentityApi, SessionApi, + Observable, } from '@backstage/core-plugin-api'; import { SamlSession } from './types'; import { diff --git a/packages/core-app-api/src/index.ts b/packages/core-app-api/src/index.ts index 23e31f6a2c..816e788a2b 100644 --- a/packages/core-app-api/src/index.ts +++ b/packages/core-app-api/src/index.ts @@ -17,4 +17,3 @@ export * from './apis'; export * from './app'; export * from './routing'; -export * from './types'; diff --git a/packages/core-app-api/src/lib/AuthSessionManager/SessionStateTracker.ts b/packages/core-app-api/src/lib/AuthSessionManager/SessionStateTracker.ts index 62cdff44ce..72ca789cc9 100644 --- a/packages/core-app-api/src/lib/AuthSessionManager/SessionStateTracker.ts +++ b/packages/core-app-api/src/lib/AuthSessionManager/SessionStateTracker.ts @@ -15,8 +15,7 @@ */ import { BehaviorSubject } from '../subjects'; -import { SessionState } from '@backstage/core-plugin-api'; -import { Observable } from '../../types'; +import { Observable, SessionState } from '@backstage/core-plugin-api'; export class SessionStateTracker { private readonly subject = new BehaviorSubject( diff --git a/packages/core-app-api/src/lib/AuthSessionManager/types.ts b/packages/core-app-api/src/lib/AuthSessionManager/types.ts index 7b6e5920df..0bed895fba 100644 --- a/packages/core-app-api/src/lib/AuthSessionManager/types.ts +++ b/packages/core-app-api/src/lib/AuthSessionManager/types.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { Observable } from '../../types'; -import { SessionState } from '@backstage/core-plugin-api'; +import { Observable, SessionState } from '@backstage/core-plugin-api'; export type GetSessionOptions = { optional?: boolean; diff --git a/packages/core-app-api/src/lib/subjects.ts b/packages/core-app-api/src/lib/subjects.ts index 5239e460af..52870538f0 100644 --- a/packages/core-app-api/src/lib/subjects.ts +++ b/packages/core-app-api/src/lib/subjects.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Observable } from '../types'; +import { Observable } from '@backstage/core-plugin-api'; import ObservableImpl from 'zen-observable'; // TODO(Rugvip): These are stopgap and probably incomplete implementations of subjects. diff --git a/packages/core-app-api/src/types.ts b/packages/core-app-api/src/types.ts deleted file mode 100644 index ab0aa56a1b..0000000000 --- a/packages/core-app-api/src/types.ts +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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. - */ - -/** - * This file contains non-react related core types used throughout Backstage. - */ - -/** - * Observer interface for consuming an Observer, see TC39. - */ -export type Observer = { - next?(value: T): void; - error?(error: Error): void; - complete?(): void; -}; - -/** - * Subscription returned when subscribing to an Observable, see TC39. - */ -export type Subscription = { - /** - * Cancels the subscription - */ - unsubscribe(): void; - - /** - * Value indicating whether the subscription is closed. - */ - readonly closed: boolean; -}; - -// Declares the global well-known Symbol.observable -// We get the actual runtime polyfill from zen-observable -declare global { - interface SymbolConstructor { - readonly observable: symbol; - } -} - -/** - * Observable sequence of values and errors, see TC39. - * - * https://github.com/tc39/proposal-observable - * - * This is used as a common return type for observable values and can be created - * using many different observable implementations, such as zen-observable or RxJS 5. - */ -export type Observable = { - [Symbol.observable](): Observable; - - /** - * Subscribes to this observable to start receiving new values. - */ - subscribe(observer: Observer): Subscription; - subscribe( - onNext?: (value: T) => void, - onError?: (error: Error) => void, - onComplete?: () => void, - ): Subscription; -}; diff --git a/packages/core-plugin-api/src/types.ts b/packages/core-plugin-api/src/types.ts index 13a8a72570..ab0aa56a1b 100644 --- a/packages/core-plugin-api/src/types.ts +++ b/packages/core-plugin-api/src/types.ts @@ -39,9 +39,17 @@ export type Subscription = { /** * Value indicating whether the subscription is closed. */ - readonly closed: Boolean; + readonly closed: boolean; }; +// Declares the global well-known Symbol.observable +// We get the actual runtime polyfill from zen-observable +declare global { + interface SymbolConstructor { + readonly observable: symbol; + } +} + /** * Observable sequence of values and errors, see TC39. * @@ -51,12 +59,14 @@ export type Subscription = { * using many different observable implementations, such as zen-observable or RxJS 5. */ export type Observable = { + [Symbol.observable](): Observable; + /** * Subscribes to this observable to start receiving new values. */ subscribe(observer: Observer): Subscription; subscribe( - onNext: (value: T) => void, + onNext?: (value: T) => void, onError?: (error: Error) => void, onComplete?: () => void, ): Subscription;