From 41c49884d29ad5392dd909341be101aec9f942e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Thu, 21 Oct 2021 09:45:32 +0200 Subject: [PATCH 1/5] introduce core-types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .changeset/rotten-melons-carry.md | 8 +++ packages/config/api-report.md | 35 ++++++------ packages/config/package.json | 1 + packages/config/src/deprecatedTypes.ts | 55 +++++++++++++++++++ packages/config/src/index.ts | 7 +-- packages/config/src/reader.ts | 3 +- packages/config/src/types.ts | 28 +--------- packages/core-app-api/api-report.md | 3 +- packages/core-plugin-api/api-report.md | 42 +++++--------- packages/core-plugin-api/package.json | 1 + .../src/apis/definitions/AlertApi.ts | 3 +- .../src/apis/definitions/AppThemeApi.ts | 2 +- .../src/apis/definitions/ErrorApi.ts | 2 +- .../src/apis/definitions/OAuthRequestApi.ts | 2 +- .../src/apis/definitions/StorageApi.ts | 2 +- .../src/apis/definitions/auth.ts | 2 +- .../core-plugin-api/src/deprecatedTypes.ts | 47 ++++++++++++++++ packages/core-plugin-api/src/index.ts | 2 +- packages/core-types/.eslintrc.js | 3 + packages/core-types/README.md | 9 +++ packages/core-types/api-report.md | 49 +++++++++++++++++ packages/core-types/package.json | 39 +++++++++++++ packages/core-types/src/index.ts | 24 ++++++++ packages/core-types/src/json.ts | 43 +++++++++++++++ .../types.ts => core-types/src/observable.ts} | 6 +- packages/core-types/src/setupTests.ts | 17 ++++++ plugins/scaffolder-backend/api-report.md | 4 +- 27 files changed, 350 insertions(+), 89 deletions(-) create mode 100644 .changeset/rotten-melons-carry.md create mode 100644 packages/config/src/deprecatedTypes.ts create mode 100644 packages/core-plugin-api/src/deprecatedTypes.ts create mode 100644 packages/core-types/.eslintrc.js create mode 100644 packages/core-types/README.md create mode 100644 packages/core-types/api-report.md create mode 100644 packages/core-types/package.json create mode 100644 packages/core-types/src/index.ts create mode 100644 packages/core-types/src/json.ts rename packages/{core-plugin-api/src/types.ts => core-types/src/observable.ts} (93%) create mode 100644 packages/core-types/src/setupTests.ts diff --git a/.changeset/rotten-melons-carry.md b/.changeset/rotten-melons-carry.md new file mode 100644 index 0000000000..5e9f849d2f --- /dev/null +++ b/.changeset/rotten-melons-carry.md @@ -0,0 +1,8 @@ +--- +'@backstage/config': patch +'@backstage/core-app-api': patch +'@backstage/core-plugin-api': patch +'@backstage/plugin-scaffolder-backend': patch +--- + +Start using the new `@backstage/core-types` package. Initially, this means using the `Observable` and `Json*` types from there. The types also remain in their old places but deprecated, and will be removed in a future release. diff --git a/packages/config/api-report.md b/packages/config/api-report.md index 9948aa1e29..116231ac72 100644 --- a/packages/config/api-report.md +++ b/packages/config/api-report.md @@ -3,10 +3,15 @@ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). ```ts +import type { JsonArray as JsonArray_2 } from '@backstage/core-types'; +import { JsonObject as JsonObject_2 } from '@backstage/core-types'; +import type { JsonPrimitive as JsonPrimitive_2 } from '@backstage/core-types'; +import { JsonValue as JsonValue_2 } from '@backstage/core-types'; + // @public export type AppConfig = { context: string; - data: JsonObject; + data: JsonObject_2; filteredKeys?: string[]; }; @@ -17,8 +22,8 @@ export type Config = { }; has(key: string): boolean; keys(): string[]; - get(key?: string): T; - getOptional(key?: string): T | undefined; + get(key?: string): T; + getOptional(key?: string): T | undefined; getConfig(key: string): Config; getOptionalConfig(key: string): Config | undefined; getConfigArray(key: string): Config[]; @@ -36,7 +41,7 @@ export type Config = { // @public export class ConfigReader implements Config { constructor( - data: JsonObject | undefined, + data: JsonObject_2 | undefined, context?: string, fallback?: ConfigReader | undefined, prefix?: string, @@ -44,7 +49,7 @@ export class ConfigReader implements Config { // (undocumented) static fromConfigs(configs: AppConfig[]): ConfigReader; // (undocumented) - get(key?: string): T; + get(key?: string): T; // (undocumented) getBoolean(key: string): boolean; // (undocumented) @@ -54,7 +59,7 @@ export class ConfigReader implements Config { // (undocumented) getNumber(key: string): number; // (undocumented) - getOptional(key?: string): T | undefined; + getOptional(key?: string): T | undefined; // (undocumented) getOptionalBoolean(key: string): boolean | undefined; // (undocumented) @@ -77,17 +82,15 @@ export class ConfigReader implements Config { keys(): string[]; } -// @public -export interface JsonArray extends Array {} +// @public @deprecated +export type JsonArray = JsonArray_2; -// @public -export type JsonObject = { - [key in string]?: JsonValue; -}; +// @public @deprecated +export type JsonObject = JsonObject_2; -// @public -export type JsonPrimitive = number | string | boolean | null; +// @public @deprecated +export type JsonPrimitive = JsonPrimitive_2; -// @public -export type JsonValue = JsonObject | JsonArray | JsonPrimitive; +// @public @deprecated +export type JsonValue = JsonValue_2; ``` diff --git a/packages/config/package.json b/packages/config/package.json index ffa2404300..7cd39eb2b0 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -30,6 +30,7 @@ "clean": "backstage-cli clean" }, "dependencies": { + "@backstage/core-types": "^0.1.0", "lodash": "^4.17.21" }, "devDependencies": { diff --git a/packages/config/src/deprecatedTypes.ts b/packages/config/src/deprecatedTypes.ts new file mode 100644 index 0000000000..17876f60eb --- /dev/null +++ b/packages/config/src/deprecatedTypes.ts @@ -0,0 +1,55 @@ +/* + * Copyright 2021 The Backstage Authors + * + * 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. + */ + +// Temporarily re-export the JSON types from @backstage/core-types +import type { + JsonArray as CoreJsonArray, + JsonObject as CoreJsonObject, + JsonPrimitive as CoreJsonPrimitive, + JsonValue as CoreJsonValue, +} from '@backstage/core-types'; + +/** + * A type representing all allowed JSON primitive values. + * + * @public + * @deprecated Please use the same type from `@backstage/core-types` instead + */ +export type JsonPrimitive = CoreJsonPrimitive; + +/** + * A type representing all allowed JSON object values. + * + * @public + * @deprecated Please use the same type from `@backstage/core-types` instead + */ +export type JsonObject = CoreJsonObject; + +/** + * A type representing all allowed JSON array values. + * + * @public + * @deprecated Please use the same type from `@backstage/core-types` instead + */ +export type JsonArray = CoreJsonArray; + +/** + * A type representing all allowed JSON values. + * + * @public + * @deprecated Please use the same type from `@backstage/core-types` instead + */ +export type JsonValue = CoreJsonValue; diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts index 59b5e8fff8..c8800d0ad2 100644 --- a/packages/config/src/index.ts +++ b/packages/config/src/index.ts @@ -20,12 +20,11 @@ * @packageDocumentation */ -export { ConfigReader } from './reader'; export type { - AppConfig, - Config, JsonArray, JsonObject, JsonPrimitive, JsonValue, -} from './types'; +} from './deprecatedTypes'; +export { ConfigReader } from './reader'; +export type { AppConfig, Config } from './types'; diff --git a/packages/config/src/reader.ts b/packages/config/src/reader.ts index 92ca0eede3..fee1b34569 100644 --- a/packages/config/src/reader.ts +++ b/packages/config/src/reader.ts @@ -14,7 +14,8 @@ * limitations under the License. */ -import { AppConfig, Config, JsonValue, JsonObject } from './types'; +import { JsonValue, JsonObject } from '@backstage/core-types'; +import { AppConfig, Config } from './types'; import cloneDeep from 'lodash/cloneDeep'; import mergeWith from 'lodash/mergeWith'; diff --git a/packages/config/src/types.ts b/packages/config/src/types.ts index d5f551cd69..e98dee9fa7 100644 --- a/packages/config/src/types.ts +++ b/packages/config/src/types.ts @@ -14,33 +14,7 @@ * limitations under the License. */ -/** - * A type representing all allowed JSON primitive values. - * - * @public - */ -export type JsonPrimitive = number | string | boolean | null; - -/** - * A type representing all allowed JSON object values. - * - * @public - */ -export type JsonObject = { [key in string]?: JsonValue }; - -/** - * A type representing all allowed JSON array values. - * - * @public - */ -export interface JsonArray extends Array {} - -/** - * A type representing all allowed JSON values. - * - * @public - */ -export type JsonValue = JsonObject | JsonArray | JsonPrimitive; +import { JsonObject, JsonValue } from '@backstage/core-types'; /** * A serialized form of configuration data that carries additional context. diff --git a/packages/core-app-api/api-report.md b/packages/core-app-api/api-report.md index 22d5092aa6..bfeaa7f678 100644 --- a/packages/core-app-api/api-report.md +++ b/packages/core-app-api/api-report.md @@ -40,6 +40,7 @@ import { microsoftAuthApiRef } from '@backstage/core-plugin-api'; import { OAuthApi } from '@backstage/core-plugin-api'; import { OAuthRequestApi } from '@backstage/core-plugin-api'; import { Observable } from '@backstage/core-plugin-api'; +import { Observable as Observable_2 } from '@backstage/core-types'; import { oktaAuthApiRef } from '@backstage/core-plugin-api'; import { oneloginAuthApiRef } from '@backstage/core-plugin-api'; import { OpenIdConnectApi } from '@backstage/core-plugin-api'; @@ -326,7 +327,7 @@ export const defaultConfigLoader: AppConfigLoader; export class ErrorAlerter implements ErrorApi { constructor(alertApi: AlertApi, errorApi: ErrorApi); // (undocumented) - error$(): Observable<{ + error$(): Observable_2<{ error: { name: string; message: string; diff --git a/packages/core-plugin-api/api-report.md b/packages/core-plugin-api/api-report.md index 4d1fe4fffd..765cdaa21c 100644 --- a/packages/core-plugin-api/api-report.md +++ b/packages/core-plugin-api/api-report.md @@ -8,9 +8,12 @@ import { BackstageTheme } from '@backstage/theme'; import { ComponentType } from 'react'; import { Config } from '@backstage/config'; +import { Observable as Observable_2 } from '@backstage/core-types'; +import { Observer as Observer_2 } from '@backstage/core-types'; import { default as React_2 } from 'react'; import { ReactElement } from 'react'; import { ReactNode } from 'react'; +import { Subscription as Subscription_2 } from '@backstage/core-types'; import { SvgIconProps } from '@material-ui/core'; // Warning: (ae-missing-release-tag) "AlertApi" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) @@ -18,7 +21,7 @@ import { SvgIconProps } from '@material-ui/core'; // @public export type AlertApi = { post(alert: AlertMessage): void; - alert$(): Observable; + alert$(): Observable_2; }; // Warning: (ae-missing-release-tag) "alertApiRef" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) @@ -201,7 +204,7 @@ export type AppTheme = { // @public export type AppThemeApi = { getInstalledThemes(): AppTheme[]; - activeThemeId$(): Observable; + activeThemeId$(): Observable_2; getActiveThemeId(): string | undefined; setActiveThemeId(themeId?: string): void; }; @@ -471,7 +474,7 @@ export interface ElementCollection { // @public export type ErrorApi = { post(error: Error_2, context?: ErrorContext): void; - error$(): Observable<{ + error$(): Observable_2<{ error: Error_2; context?: ErrorContext; }>; @@ -667,7 +670,7 @@ export type OAuthRequestApi = { createAuthRequester( options: AuthRequesterOptions, ): AuthRequester; - authRequest$(): Observable; + authRequest$(): Observable_2; }; // Warning: (ae-missing-release-tag) "oauthRequestApiRef" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) @@ -682,25 +685,13 @@ export type OAuthScope = string | string[]; // Warning: (ae-missing-release-tag) "Observable" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public -export type Observable = { - [Symbol.observable](): Observable; - subscribe(observer: Observer): Subscription; - subscribe( - onNext?: (value: T) => void, - onError?: (error: Error) => void, - onComplete?: () => void, - ): Subscription; -}; +// @public @deprecated +export type Observable = Observable_2; // Warning: (ae-missing-release-tag) "Observer" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public -export type Observer = { - next?(value: T): void; - error?(error: Error): void; - complete?(): void; -}; +// @public @deprecated +export type Observer = Observer_2; // Warning: (ae-missing-release-tag) "oidcAuthApiRef" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -829,7 +820,7 @@ export const samlAuthApiRef: ApiRef< export type SessionApi = { signIn(): Promise; signOut(): Promise; - sessionState$(): Observable; + sessionState$(): Observable_2; }; // Warning: (ae-missing-release-tag) "SessionState" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) @@ -874,7 +865,7 @@ export interface StorageApi { get(key: string): T | undefined; // Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen // Warning: (tsdoc-param-tag-with-invalid-type) The @param block should not include a JSDoc-style '{type}' - observe$(key: string): Observable>; + observe$(key: string): Observable_2>; // Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen // Warning: (tsdoc-param-tag-with-invalid-type) The @param block should not include a JSDoc-style '{type}' remove(key: string): Promise; @@ -908,11 +899,8 @@ export type SubRouteRef = { // Warning: (ae-missing-release-tag) "Subscription" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // -// @public -export type Subscription = { - unsubscribe(): void; - readonly closed: boolean; -}; +// @public @deprecated +export type Subscription = Subscription_2; // Warning: (ae-missing-release-tag) "TypesToApiRefs" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // diff --git a/packages/core-plugin-api/package.json b/packages/core-plugin-api/package.json index 5c8daec606..fbb2760e59 100644 --- a/packages/core-plugin-api/package.json +++ b/packages/core-plugin-api/package.json @@ -30,6 +30,7 @@ }, "dependencies": { "@backstage/config": "^0.1.9", + "@backstage/core-types": "^0.1.0", "@backstage/theme": "^0.2.9", "@backstage/version-bridge": "^0.1.0", "@material-ui/core": "^4.12.2", diff --git a/packages/core-plugin-api/src/apis/definitions/AlertApi.ts b/packages/core-plugin-api/src/apis/definitions/AlertApi.ts index aac2283973..ecd12c533a 100644 --- a/packages/core-plugin-api/src/apis/definitions/AlertApi.ts +++ b/packages/core-plugin-api/src/apis/definitions/AlertApi.ts @@ -13,8 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import { createApiRef, ApiRef } from '../system'; -import { Observable } from '../../types'; +import { Observable } from '@backstage/core-types'; export type AlertMessage = { message: string; diff --git a/packages/core-plugin-api/src/apis/definitions/AppThemeApi.ts b/packages/core-plugin-api/src/apis/definitions/AppThemeApi.ts index 3ff9ddce98..8608b53593 100644 --- a/packages/core-plugin-api/src/apis/definitions/AppThemeApi.ts +++ b/packages/core-plugin-api/src/apis/definitions/AppThemeApi.ts @@ -16,7 +16,7 @@ import { ApiRef, createApiRef } from '../system'; import { BackstageTheme } from '@backstage/theme'; -import { Observable } from '../../types'; +import { Observable } from '@backstage/core-types'; /** * Describes a theme provided by the app. diff --git a/packages/core-plugin-api/src/apis/definitions/ErrorApi.ts b/packages/core-plugin-api/src/apis/definitions/ErrorApi.ts index dc63e28e1a..6fd47ac966 100644 --- a/packages/core-plugin-api/src/apis/definitions/ErrorApi.ts +++ b/packages/core-plugin-api/src/apis/definitions/ErrorApi.ts @@ -15,7 +15,7 @@ */ import { ApiRef, createApiRef } from '../system'; -import { Observable } from '../../types'; +import { Observable } from '@backstage/core-types'; /** * Mirrors the JavaScript Error class, for the purpose of diff --git a/packages/core-plugin-api/src/apis/definitions/OAuthRequestApi.ts b/packages/core-plugin-api/src/apis/definitions/OAuthRequestApi.ts index 3fe7f26bc0..43351edaf8 100644 --- a/packages/core-plugin-api/src/apis/definitions/OAuthRequestApi.ts +++ b/packages/core-plugin-api/src/apis/definitions/OAuthRequestApi.ts @@ -15,7 +15,7 @@ */ import { IconComponent } from '../../icons/types'; -import { Observable } from '../../types'; +import { Observable } from '@backstage/core-types'; import { ApiRef, createApiRef } from '../system'; /** diff --git a/packages/core-plugin-api/src/apis/definitions/StorageApi.ts b/packages/core-plugin-api/src/apis/definitions/StorageApi.ts index 9332c80f0f..7951403040 100644 --- a/packages/core-plugin-api/src/apis/definitions/StorageApi.ts +++ b/packages/core-plugin-api/src/apis/definitions/StorageApi.ts @@ -15,7 +15,7 @@ */ import { ApiRef, createApiRef } from '../system'; -import { Observable } from '../../types'; +import { Observable } from '@backstage/core-types'; export type StorageValueChange = { key: string; diff --git a/packages/core-plugin-api/src/apis/definitions/auth.ts b/packages/core-plugin-api/src/apis/definitions/auth.ts index a78414048c..314f2955cf 100644 --- a/packages/core-plugin-api/src/apis/definitions/auth.ts +++ b/packages/core-plugin-api/src/apis/definitions/auth.ts @@ -15,7 +15,7 @@ */ import { ApiRef, createApiRef } from '../system'; -import { Observable } from '../../types'; +import { Observable } from '@backstage/core-types'; /** * This file contains declarations for common interfaces of auth-related APIs. diff --git a/packages/core-plugin-api/src/deprecatedTypes.ts b/packages/core-plugin-api/src/deprecatedTypes.ts new file mode 100644 index 0000000000..598f666317 --- /dev/null +++ b/packages/core-plugin-api/src/deprecatedTypes.ts @@ -0,0 +1,47 @@ +/* + * Copyright 2020 The Backstage Authors + * + * 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 { + Observer as CoreObserver, + Subscription as CoreSubscription, + Observable as CoreObservable, +} from '@backstage/core-types'; + +/** + * Observer interface for consuming an Observer, see TC39. + * + * @deprecated Please use the same type from `@backstage/core-types` instead + */ +export type Observer = CoreObserver; + +/** + * Subscription returned when subscribing to an Observable, see TC39. + * + * @deprecated Please use the same type from `@backstage/core-types` instead + */ +export type Subscription = CoreSubscription; + +/** + * 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. + * + * @deprecated Please use the same type from `@backstage/core-types` instead + */ +export type Observable = CoreObservable; diff --git a/packages/core-plugin-api/src/index.ts b/packages/core-plugin-api/src/index.ts index 782416c4d0..7a4f2e72ba 100644 --- a/packages/core-plugin-api/src/index.ts +++ b/packages/core-plugin-api/src/index.ts @@ -27,4 +27,4 @@ export * from './extensions'; export * from './icons'; export * from './plugin'; export * from './routing'; -export * from './types'; +export * from './deprecatedTypes'; diff --git a/packages/core-types/.eslintrc.js b/packages/core-types/.eslintrc.js new file mode 100644 index 0000000000..13573efa9c --- /dev/null +++ b/packages/core-types/.eslintrc.js @@ -0,0 +1,3 @@ +module.exports = { + extends: [require.resolve('@backstage/cli/config/eslint')], +}; diff --git a/packages/core-types/README.md b/packages/core-types/README.md new file mode 100644 index 0000000000..52bd1fa7a5 --- /dev/null +++ b/packages/core-types/README.md @@ -0,0 +1,9 @@ +# Common core types used within Backstage + +Contains some common types that are used widely within the rest of the Backstage project and in plugins. + +This package will be imported both by the frontend and backend. + +## Links + +- [The Backstage homepage](https://backstage.io) diff --git a/packages/core-types/api-report.md b/packages/core-types/api-report.md new file mode 100644 index 0000000000..bd4d145a10 --- /dev/null +++ b/packages/core-types/api-report.md @@ -0,0 +1,49 @@ +## API Report File for "@backstage/core-types" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +// @public +export interface JsonArray extends Array {} + +// @public +export type JsonObject = { + [key in string]?: JsonValue; +}; + +// @public +export type JsonPrimitive = number | string | boolean | null; + +// @public +export type JsonValue = JsonObject | JsonArray | JsonPrimitive; + +// Warning: (ae-missing-release-tag) "Observable" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public +export type Observable = { + [Symbol.observable](): Observable; + subscribe(observer: Observer): Subscription; + subscribe( + onNext?: (value: T) => void, + onError?: (error: Error) => void, + onComplete?: () => void, + ): Subscription; +}; + +// Warning: (ae-missing-release-tag) "Observer" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public +export type Observer = { + next?(value: T): void; + error?(error: Error): void; + complete?(): void; +}; + +// Warning: (ae-missing-release-tag) "Subscription" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public +export type Subscription = { + unsubscribe(): void; + readonly closed: boolean; +}; +``` diff --git a/packages/core-types/package.json b/packages/core-types/package.json new file mode 100644 index 0000000000..ce6fc05fb4 --- /dev/null +++ b/packages/core-types/package.json @@ -0,0 +1,39 @@ +{ + "name": "@backstage/core-types", + "description": "Common core types used within Backstage", + "version": "0.1.0", + "main": "src/index.ts", + "types": "src/index.ts", + "license": "Apache-2.0", + "private": false, + "publishConfig": { + "access": "public", + "main": "dist/index.cjs.js", + "module": "dist/index.esm.js", + "types": "dist/index.d.ts" + }, + "homepage": "https://backstage.io", + "repository": { + "type": "git", + "url": "https://github.com/backstage/backstage", + "directory": "packages/core-types" + }, + "keywords": [ + "backstage" + ], + "scripts": { + "build": "backstage-cli build", + "lint": "backstage-cli lint", + "test": "backstage-cli test", + "prepack": "backstage-cli prepack", + "postpack": "backstage-cli postpack", + "clean": "backstage-cli clean" + }, + "dependencies": {}, + "devDependencies": { + "@backstage/cli": "^0.7.11" + }, + "files": [ + "dist" + ] +} diff --git a/packages/core-types/src/index.ts b/packages/core-types/src/index.ts new file mode 100644 index 0000000000..9e7a33c5f2 --- /dev/null +++ b/packages/core-types/src/index.ts @@ -0,0 +1,24 @@ +/* + * Copyright 2020 The Backstage Authors + * + * 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. + */ + +/** + * Common core types used within Backstage + * + * @packageDocumentation + */ + +export type { JsonArray, JsonObject, JsonPrimitive, JsonValue } from './json'; +export type { Observable, Observer, Subscription } from './observable'; diff --git a/packages/core-types/src/json.ts b/packages/core-types/src/json.ts new file mode 100644 index 0000000000..bcbaaa1030 --- /dev/null +++ b/packages/core-types/src/json.ts @@ -0,0 +1,43 @@ +/* + * Copyright 2021 The Backstage Authors + * + * 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. + */ + +/** + * A type representing all allowed JSON primitive values. + * + * @public + */ +export type JsonPrimitive = number | string | boolean | null; + +/** + * A type representing all allowed JSON object values. + * + * @public + */ +export type JsonObject = { [key in string]?: JsonValue }; + +/** + * A type representing all allowed JSON array values. + * + * @public + */ +export interface JsonArray extends Array {} + +/** + * A type representing all allowed JSON values. + * + * @public + */ +export type JsonValue = JsonObject | JsonArray | JsonPrimitive; diff --git a/packages/core-plugin-api/src/types.ts b/packages/core-types/src/observable.ts similarity index 93% rename from packages/core-plugin-api/src/types.ts rename to packages/core-types/src/observable.ts index fff4cb1515..367fa087e0 100644 --- a/packages/core-plugin-api/src/types.ts +++ b/packages/core-types/src/observable.ts @@ -1,5 +1,5 @@ /* - * Copyright 2020 The Backstage Authors + * Copyright 2021 The Backstage Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,6 @@ * limitations under the License. */ -/** - * This file contains non-react related core types used throughout Backstage. - */ - /** * Observer interface for consuming an Observer, see TC39. */ diff --git a/packages/core-types/src/setupTests.ts b/packages/core-types/src/setupTests.ts new file mode 100644 index 0000000000..d3232290a7 --- /dev/null +++ b/packages/core-types/src/setupTests.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2020 The Backstage Authors + * + * 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 {}; diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index ef4defcc50..9dd86eeddc 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -15,7 +15,9 @@ import { createPullRequest } from 'octokit-plugin-create-pull-request'; import { Entity } from '@backstage/catalog-model'; import express from 'express'; import { JsonObject } from '@backstage/config'; +import { JsonObject as JsonObject_2 } from '@backstage/core-types'; import { JsonValue } from '@backstage/config'; +import { JsonValue as JsonValue_2 } from '@backstage/core-types'; import { LocationSpec } from '@backstage/catalog-model'; import { Logger as Logger_2 } from 'winston'; import { Octokit } from '@octokit/rest'; @@ -183,7 +185,7 @@ export function createRouter(options: RouterOptions): Promise; // @public (undocumented) export const createTemplateAction: < Input extends Partial<{ - [name: string]: JsonValue | Partial | undefined; + [name: string]: JsonValue_2 | Partial | undefined; }>, >( templateAction: TemplateAction, From db58c2e879745a9401f1c7a4ab6d1a1e03ffdb0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Thu, 21 Oct 2021 09:52:17 +0200 Subject: [PATCH 2/5] mark the observable types public MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- packages/core-types/api-report.md | 6 ------ packages/core-types/src/observable.ts | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/core-types/api-report.md b/packages/core-types/api-report.md index bd4d145a10..09611f63e1 100644 --- a/packages/core-types/api-report.md +++ b/packages/core-types/api-report.md @@ -17,8 +17,6 @@ export type JsonPrimitive = number | string | boolean | null; // @public export type JsonValue = JsonObject | JsonArray | JsonPrimitive; -// Warning: (ae-missing-release-tag) "Observable" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public export type Observable = { [Symbol.observable](): Observable; @@ -30,8 +28,6 @@ export type Observable = { ): Subscription; }; -// Warning: (ae-missing-release-tag) "Observer" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public export type Observer = { next?(value: T): void; @@ -39,8 +35,6 @@ export type Observer = { complete?(): void; }; -// Warning: (ae-missing-release-tag) "Subscription" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public export type Subscription = { unsubscribe(): void; diff --git a/packages/core-types/src/observable.ts b/packages/core-types/src/observable.ts index 367fa087e0..f7292c293c 100644 --- a/packages/core-types/src/observable.ts +++ b/packages/core-types/src/observable.ts @@ -16,6 +16,8 @@ /** * Observer interface for consuming an Observer, see TC39. + * + * @public */ export type Observer = { next?(value: T): void; @@ -25,6 +27,8 @@ export type Observer = { /** * Subscription returned when subscribing to an Observable, see TC39. + * + * @public */ export type Subscription = { /** @@ -53,6 +57,8 @@ declare global { * * 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. + * + * @public */ export type Observable = { [Symbol.observable](): Observable; From 447c514899c84dc4a53439e8ae121b37831f6607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Thu, 21 Oct 2021 15:05:07 +0200 Subject: [PATCH 3/5] rename to just types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .changeset/rotten-melons-carry.md | 2 +- packages/config/api-report.md | 8 ++++---- packages/config/package.json | 2 +- packages/config/src/deprecatedTypes.ts | 12 ++++++------ packages/config/src/reader.ts | 2 +- packages/config/src/types.ts | 2 +- packages/core-app-api/api-report.md | 2 +- packages/core-plugin-api/api-report.md | 6 +++--- packages/core-plugin-api/package.json | 2 +- .../core-plugin-api/src/apis/definitions/AlertApi.ts | 2 +- .../src/apis/definitions/AppThemeApi.ts | 2 +- .../core-plugin-api/src/apis/definitions/ErrorApi.ts | 2 +- .../src/apis/definitions/OAuthRequestApi.ts | 2 +- .../src/apis/definitions/StorageApi.ts | 2 +- .../core-plugin-api/src/apis/definitions/auth.ts | 2 +- packages/core-plugin-api/src/deprecatedTypes.ts | 8 ++++---- packages/{core-types => types}/.eslintrc.js | 0 packages/{core-types => types}/README.md | 2 +- packages/{core-types => types}/api-report.md | 2 +- packages/{core-types => types}/package.json | 6 +++--- packages/{core-types => types}/src/index.ts | 2 +- packages/{core-types => types}/src/json.ts | 0 packages/{core-types => types}/src/observable.ts | 0 packages/{core-types => types}/src/setupTests.ts | 0 plugins/scaffolder-backend/api-report.md | 4 ++-- 25 files changed, 37 insertions(+), 37 deletions(-) rename packages/{core-types => types}/.eslintrc.js (100%) rename packages/{core-types => types}/README.md (82%) rename packages/{core-types => types}/api-report.md (94%) rename packages/{core-types => types}/package.json (85%) rename packages/{core-types => types}/src/index.ts (94%) rename packages/{core-types => types}/src/json.ts (100%) rename packages/{core-types => types}/src/observable.ts (100%) rename packages/{core-types => types}/src/setupTests.ts (100%) diff --git a/.changeset/rotten-melons-carry.md b/.changeset/rotten-melons-carry.md index 5e9f849d2f..2f1429c399 100644 --- a/.changeset/rotten-melons-carry.md +++ b/.changeset/rotten-melons-carry.md @@ -5,4 +5,4 @@ '@backstage/plugin-scaffolder-backend': patch --- -Start using the new `@backstage/core-types` package. Initially, this means using the `Observable` and `Json*` types from there. The types also remain in their old places but deprecated, and will be removed in a future release. +Start using the new `@backstage/types` package. Initially, this means using the `Observable` and `Json*` types from there. The types also remain in their old places but deprecated, and will be removed in a future release. diff --git a/packages/config/api-report.md b/packages/config/api-report.md index 116231ac72..205db6ef2b 100644 --- a/packages/config/api-report.md +++ b/packages/config/api-report.md @@ -3,10 +3,10 @@ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). ```ts -import type { JsonArray as JsonArray_2 } from '@backstage/core-types'; -import { JsonObject as JsonObject_2 } from '@backstage/core-types'; -import type { JsonPrimitive as JsonPrimitive_2 } from '@backstage/core-types'; -import { JsonValue as JsonValue_2 } from '@backstage/core-types'; +import type { JsonArray as JsonArray_2 } from '@backstage/types'; +import { JsonObject as JsonObject_2 } from '@backstage/types'; +import type { JsonPrimitive as JsonPrimitive_2 } from '@backstage/types'; +import { JsonValue as JsonValue_2 } from '@backstage/types'; // @public export type AppConfig = { diff --git a/packages/config/package.json b/packages/config/package.json index 7cd39eb2b0..da741b7a3b 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -30,7 +30,7 @@ "clean": "backstage-cli clean" }, "dependencies": { - "@backstage/core-types": "^0.1.0", + "@backstage/types": "^0.1.0", "lodash": "^4.17.21" }, "devDependencies": { diff --git a/packages/config/src/deprecatedTypes.ts b/packages/config/src/deprecatedTypes.ts index 17876f60eb..823825451b 100644 --- a/packages/config/src/deprecatedTypes.ts +++ b/packages/config/src/deprecatedTypes.ts @@ -14,19 +14,19 @@ * limitations under the License. */ -// Temporarily re-export the JSON types from @backstage/core-types +// Temporarily re-export the JSON types from @backstage/types import type { JsonArray as CoreJsonArray, JsonObject as CoreJsonObject, JsonPrimitive as CoreJsonPrimitive, JsonValue as CoreJsonValue, -} from '@backstage/core-types'; +} from '@backstage/types'; /** * A type representing all allowed JSON primitive values. * * @public - * @deprecated Please use the same type from `@backstage/core-types` instead + * @deprecated Please use the same type from `@backstage/types` instead */ export type JsonPrimitive = CoreJsonPrimitive; @@ -34,7 +34,7 @@ export type JsonPrimitive = CoreJsonPrimitive; * A type representing all allowed JSON object values. * * @public - * @deprecated Please use the same type from `@backstage/core-types` instead + * @deprecated Please use the same type from `@backstage/types` instead */ export type JsonObject = CoreJsonObject; @@ -42,7 +42,7 @@ export type JsonObject = CoreJsonObject; * A type representing all allowed JSON array values. * * @public - * @deprecated Please use the same type from `@backstage/core-types` instead + * @deprecated Please use the same type from `@backstage/types` instead */ export type JsonArray = CoreJsonArray; @@ -50,6 +50,6 @@ export type JsonArray = CoreJsonArray; * A type representing all allowed JSON values. * * @public - * @deprecated Please use the same type from `@backstage/core-types` instead + * @deprecated Please use the same type from `@backstage/types` instead */ export type JsonValue = CoreJsonValue; diff --git a/packages/config/src/reader.ts b/packages/config/src/reader.ts index fee1b34569..bc8a860c85 100644 --- a/packages/config/src/reader.ts +++ b/packages/config/src/reader.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { JsonValue, JsonObject } from '@backstage/core-types'; +import { JsonValue, JsonObject } from '@backstage/types'; import { AppConfig, Config } from './types'; import cloneDeep from 'lodash/cloneDeep'; import mergeWith from 'lodash/mergeWith'; diff --git a/packages/config/src/types.ts b/packages/config/src/types.ts index e98dee9fa7..a543233277 100644 --- a/packages/config/src/types.ts +++ b/packages/config/src/types.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { JsonObject, JsonValue } from '@backstage/core-types'; +import { JsonObject, JsonValue } from '@backstage/types'; /** * A serialized form of configuration data that carries additional context. diff --git a/packages/core-app-api/api-report.md b/packages/core-app-api/api-report.md index bfeaa7f678..f47ad2e791 100644 --- a/packages/core-app-api/api-report.md +++ b/packages/core-app-api/api-report.md @@ -40,7 +40,7 @@ import { microsoftAuthApiRef } from '@backstage/core-plugin-api'; import { OAuthApi } from '@backstage/core-plugin-api'; import { OAuthRequestApi } from '@backstage/core-plugin-api'; import { Observable } from '@backstage/core-plugin-api'; -import { Observable as Observable_2 } from '@backstage/core-types'; +import { Observable as Observable_2 } from '@backstage/types'; import { oktaAuthApiRef } from '@backstage/core-plugin-api'; import { oneloginAuthApiRef } from '@backstage/core-plugin-api'; import { OpenIdConnectApi } from '@backstage/core-plugin-api'; diff --git a/packages/core-plugin-api/api-report.md b/packages/core-plugin-api/api-report.md index 765cdaa21c..0347b4b018 100644 --- a/packages/core-plugin-api/api-report.md +++ b/packages/core-plugin-api/api-report.md @@ -8,12 +8,12 @@ import { BackstageTheme } from '@backstage/theme'; import { ComponentType } from 'react'; import { Config } from '@backstage/config'; -import { Observable as Observable_2 } from '@backstage/core-types'; -import { Observer as Observer_2 } from '@backstage/core-types'; +import { Observable as Observable_2 } from '@backstage/types'; +import { Observer as Observer_2 } from '@backstage/types'; import { default as React_2 } from 'react'; import { ReactElement } from 'react'; import { ReactNode } from 'react'; -import { Subscription as Subscription_2 } from '@backstage/core-types'; +import { Subscription as Subscription_2 } from '@backstage/types'; import { SvgIconProps } from '@material-ui/core'; // Warning: (ae-missing-release-tag) "AlertApi" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) diff --git a/packages/core-plugin-api/package.json b/packages/core-plugin-api/package.json index fbb2760e59..938ddc63e3 100644 --- a/packages/core-plugin-api/package.json +++ b/packages/core-plugin-api/package.json @@ -30,8 +30,8 @@ }, "dependencies": { "@backstage/config": "^0.1.9", - "@backstage/core-types": "^0.1.0", "@backstage/theme": "^0.2.9", + "@backstage/types": "^0.1.0", "@backstage/version-bridge": "^0.1.0", "@material-ui/core": "^4.12.2", "@types/react": "*", diff --git a/packages/core-plugin-api/src/apis/definitions/AlertApi.ts b/packages/core-plugin-api/src/apis/definitions/AlertApi.ts index ecd12c533a..7110c1d9f8 100644 --- a/packages/core-plugin-api/src/apis/definitions/AlertApi.ts +++ b/packages/core-plugin-api/src/apis/definitions/AlertApi.ts @@ -15,7 +15,7 @@ */ import { createApiRef, ApiRef } from '../system'; -import { Observable } from '@backstage/core-types'; +import { Observable } from '@backstage/types'; export type AlertMessage = { message: string; diff --git a/packages/core-plugin-api/src/apis/definitions/AppThemeApi.ts b/packages/core-plugin-api/src/apis/definitions/AppThemeApi.ts index 8608b53593..5ac16f83fd 100644 --- a/packages/core-plugin-api/src/apis/definitions/AppThemeApi.ts +++ b/packages/core-plugin-api/src/apis/definitions/AppThemeApi.ts @@ -16,7 +16,7 @@ import { ApiRef, createApiRef } from '../system'; import { BackstageTheme } from '@backstage/theme'; -import { Observable } from '@backstage/core-types'; +import { Observable } from '@backstage/types'; /** * Describes a theme provided by the app. diff --git a/packages/core-plugin-api/src/apis/definitions/ErrorApi.ts b/packages/core-plugin-api/src/apis/definitions/ErrorApi.ts index 6fd47ac966..69c331bc06 100644 --- a/packages/core-plugin-api/src/apis/definitions/ErrorApi.ts +++ b/packages/core-plugin-api/src/apis/definitions/ErrorApi.ts @@ -15,7 +15,7 @@ */ import { ApiRef, createApiRef } from '../system'; -import { Observable } from '@backstage/core-types'; +import { Observable } from '@backstage/types'; /** * Mirrors the JavaScript Error class, for the purpose of diff --git a/packages/core-plugin-api/src/apis/definitions/OAuthRequestApi.ts b/packages/core-plugin-api/src/apis/definitions/OAuthRequestApi.ts index 43351edaf8..14609f5b3a 100644 --- a/packages/core-plugin-api/src/apis/definitions/OAuthRequestApi.ts +++ b/packages/core-plugin-api/src/apis/definitions/OAuthRequestApi.ts @@ -15,7 +15,7 @@ */ import { IconComponent } from '../../icons/types'; -import { Observable } from '@backstage/core-types'; +import { Observable } from '@backstage/types'; import { ApiRef, createApiRef } from '../system'; /** diff --git a/packages/core-plugin-api/src/apis/definitions/StorageApi.ts b/packages/core-plugin-api/src/apis/definitions/StorageApi.ts index 7951403040..f9a52a0bf4 100644 --- a/packages/core-plugin-api/src/apis/definitions/StorageApi.ts +++ b/packages/core-plugin-api/src/apis/definitions/StorageApi.ts @@ -15,7 +15,7 @@ */ import { ApiRef, createApiRef } from '../system'; -import { Observable } from '@backstage/core-types'; +import { Observable } from '@backstage/types'; export type StorageValueChange = { key: string; diff --git a/packages/core-plugin-api/src/apis/definitions/auth.ts b/packages/core-plugin-api/src/apis/definitions/auth.ts index 314f2955cf..e1c56279d9 100644 --- a/packages/core-plugin-api/src/apis/definitions/auth.ts +++ b/packages/core-plugin-api/src/apis/definitions/auth.ts @@ -15,7 +15,7 @@ */ import { ApiRef, createApiRef } from '../system'; -import { Observable } from '@backstage/core-types'; +import { Observable } from '@backstage/types'; /** * This file contains declarations for common interfaces of auth-related APIs. diff --git a/packages/core-plugin-api/src/deprecatedTypes.ts b/packages/core-plugin-api/src/deprecatedTypes.ts index 598f666317..605dc72ee3 100644 --- a/packages/core-plugin-api/src/deprecatedTypes.ts +++ b/packages/core-plugin-api/src/deprecatedTypes.ts @@ -18,19 +18,19 @@ import { Observer as CoreObserver, Subscription as CoreSubscription, Observable as CoreObservable, -} from '@backstage/core-types'; +} from '@backstage/types'; /** * Observer interface for consuming an Observer, see TC39. * - * @deprecated Please use the same type from `@backstage/core-types` instead + * @deprecated Please use the same type from `@backstage/types` instead */ export type Observer = CoreObserver; /** * Subscription returned when subscribing to an Observable, see TC39. * - * @deprecated Please use the same type from `@backstage/core-types` instead + * @deprecated Please use the same type from `@backstage/types` instead */ export type Subscription = CoreSubscription; @@ -42,6 +42,6 @@ export type Subscription = CoreSubscription; * 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. * - * @deprecated Please use the same type from `@backstage/core-types` instead + * @deprecated Please use the same type from `@backstage/types` instead */ export type Observable = CoreObservable; diff --git a/packages/core-types/.eslintrc.js b/packages/types/.eslintrc.js similarity index 100% rename from packages/core-types/.eslintrc.js rename to packages/types/.eslintrc.js diff --git a/packages/core-types/README.md b/packages/types/README.md similarity index 82% rename from packages/core-types/README.md rename to packages/types/README.md index 52bd1fa7a5..4462890ed2 100644 --- a/packages/core-types/README.md +++ b/packages/types/README.md @@ -1,4 +1,4 @@ -# Common core types used within Backstage +# Common TypeScript types used within Backstage Contains some common types that are used widely within the rest of the Backstage project and in plugins. diff --git a/packages/core-types/api-report.md b/packages/types/api-report.md similarity index 94% rename from packages/core-types/api-report.md rename to packages/types/api-report.md index 09611f63e1..43e3cfee0e 100644 --- a/packages/core-types/api-report.md +++ b/packages/types/api-report.md @@ -1,4 +1,4 @@ -## API Report File for "@backstage/core-types" +## API Report File for "@backstage/types" > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). diff --git a/packages/core-types/package.json b/packages/types/package.json similarity index 85% rename from packages/core-types/package.json rename to packages/types/package.json index ce6fc05fb4..8274c1ce74 100644 --- a/packages/core-types/package.json +++ b/packages/types/package.json @@ -1,6 +1,6 @@ { - "name": "@backstage/core-types", - "description": "Common core types used within Backstage", + "name": "@backstage/types", + "description": "Common TypeScript types used within Backstage", "version": "0.1.0", "main": "src/index.ts", "types": "src/index.ts", @@ -16,7 +16,7 @@ "repository": { "type": "git", "url": "https://github.com/backstage/backstage", - "directory": "packages/core-types" + "directory": "packages/types" }, "keywords": [ "backstage" diff --git a/packages/core-types/src/index.ts b/packages/types/src/index.ts similarity index 94% rename from packages/core-types/src/index.ts rename to packages/types/src/index.ts index 9e7a33c5f2..1f1b13c349 100644 --- a/packages/core-types/src/index.ts +++ b/packages/types/src/index.ts @@ -15,7 +15,7 @@ */ /** - * Common core types used within Backstage + * Common TypeScript types used within Backstage * * @packageDocumentation */ diff --git a/packages/core-types/src/json.ts b/packages/types/src/json.ts similarity index 100% rename from packages/core-types/src/json.ts rename to packages/types/src/json.ts diff --git a/packages/core-types/src/observable.ts b/packages/types/src/observable.ts similarity index 100% rename from packages/core-types/src/observable.ts rename to packages/types/src/observable.ts diff --git a/packages/core-types/src/setupTests.ts b/packages/types/src/setupTests.ts similarity index 100% rename from packages/core-types/src/setupTests.ts rename to packages/types/src/setupTests.ts diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index 9dd86eeddc..07c6c7a57d 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -15,9 +15,9 @@ import { createPullRequest } from 'octokit-plugin-create-pull-request'; import { Entity } from '@backstage/catalog-model'; import express from 'express'; import { JsonObject } from '@backstage/config'; -import { JsonObject as JsonObject_2 } from '@backstage/core-types'; +import { JsonObject as JsonObject_2 } from '@backstage/types'; import { JsonValue } from '@backstage/config'; -import { JsonValue as JsonValue_2 } from '@backstage/core-types'; +import { JsonValue as JsonValue_2 } from '@backstage/types'; import { LocationSpec } from '@backstage/catalog-model'; import { Logger as Logger_2 } from 'winston'; import { Octokit } from '@octokit/rest'; From 7c5cf5a4a443dd20f26bf2142ac4f5cc15195689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Thu, 21 Oct 2021 16:07:35 +0200 Subject: [PATCH 4/5] add test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- packages/types/package.json | 4 +- packages/types/src/json.test.ts | 81 +++++++++++++++++++++++++++ packages/types/src/observable.test.ts | 42 ++++++++++++++ 3 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 packages/types/src/json.test.ts create mode 100644 packages/types/src/observable.test.ts diff --git a/packages/types/package.json b/packages/types/package.json index 8274c1ce74..e8117fff37 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -31,7 +31,9 @@ }, "dependencies": {}, "devDependencies": { - "@backstage/cli": "^0.7.11" + "@backstage/cli": "^0.7.11", + "@types/zen-observable": "^0.8.0", + "zen-observable": "^0.8.15" }, "files": [ "dist" diff --git a/packages/types/src/json.test.ts b/packages/types/src/json.test.ts new file mode 100644 index 0000000000..7da0ef8a3e --- /dev/null +++ b/packages/types/src/json.test.ts @@ -0,0 +1,81 @@ +/* + * Copyright 2021 The Backstage Authors + * + * 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 { JsonPrimitive, JsonArray, JsonObject, JsonValue } from './json'; + +describe('json', () => { + it('JsonPrimitive', () => { + function isValid(..._v: JsonPrimitive[]) {} + isValid(1, 's', true, false, null); + + // @ts-expect-error + const v1: JsonPrimitive = []; + // @ts-expect-error + const v2: JsonPrimitive = {}; + + expect(true).toBe(true); + }); + + it('JsonArray', () => { + function isValid(..._v: JsonArray[]) {} + isValid([], [1, 's', true, false, null, {}, []]); + + // @ts-expect-error + const v1: JsonArray = 1; + // @ts-expect-error + const v2: JsonArray = 's'; + // @ts-expect-error + const v3: JsonArray = true; + // @ts-expect-error + const v4: JsonArray = false; + // @ts-expect-error + const v5: JsonArray = null; + // @ts-expect-error + const v6: JsonArray = {}; + + expect(true).toBe(true); + }); + + it('JsonObject', () => { + function isValid(..._v: JsonObject[]) {} + isValid( + {}, + { v1: 1, v2: 's', v3: true, v4: false, v5: null, v6: {}, v7: [] }, + ); + + // @ts-expect-error + const v1: JsonObject = 1; + // @ts-expect-error + const v2: JsonObject = 's'; + // @ts-expect-error + const v3: JsonObject = true; + // @ts-expect-error + const v4: JsonObject = false; + // @ts-expect-error + const v5: JsonObject = null; + // @ts-expect-error + const v6: JsonObject = []; + + expect(true).toBe(true); + }); + + it('JsonValue', () => { + function isValid(..._v: JsonValue[]) {} + isValid(1, 's', true, false, null, {}, []); + + expect(true).toBe(true); + }); +}); diff --git a/packages/types/src/observable.test.ts b/packages/types/src/observable.test.ts new file mode 100644 index 0000000000..77cd074fa3 --- /dev/null +++ b/packages/types/src/observable.test.ts @@ -0,0 +1,42 @@ +/* + * Copyright 2021 The Backstage Authors + * + * 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 ZenObservable from 'zen-observable'; +import { Observable, Observer, Subscription } from './observable'; + +describe('observable', () => { + it('works in conjunction with zen-observables', () => { + // Use ZenObservable as the concrete implementation, but use our types in + // all other possible places in the code + const observable: Observable = new ZenObservable( + (subscriber: Observer) => { + subscriber.next!('a'); + subscriber.error!(new Error('e')); + subscriber.complete!(); + }, + ); + + const subscription: Subscription = observable.subscribe( + _value => {}, + _error => {}, + () => {}, + ); + + subscription.unsubscribe(); + + expect(true).toBe(true); + }); +}); From 66bcc31ec42d91d40b5a46ccbe1652ee7056b208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Thu, 21 Oct 2021 16:36:41 +0200 Subject: [PATCH 5/5] some more fixup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- packages/core-plugin-api/api-report.md | 6 ------ packages/core-plugin-api/src/deprecatedTypes.ts | 3 +++ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/core-plugin-api/api-report.md b/packages/core-plugin-api/api-report.md index 0347b4b018..575d0b755f 100644 --- a/packages/core-plugin-api/api-report.md +++ b/packages/core-plugin-api/api-report.md @@ -683,13 +683,9 @@ export const oauthRequestApiRef: ApiRef; // @public export type OAuthScope = string | string[]; -// Warning: (ae-missing-release-tag) "Observable" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public @deprecated export type Observable = Observable_2; -// Warning: (ae-missing-release-tag) "Observer" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public @deprecated export type Observer = Observer_2; @@ -897,8 +893,6 @@ export type SubRouteRef = { params: ParamKeys; }; -// Warning: (ae-missing-release-tag) "Subscription" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public @deprecated export type Subscription = Subscription_2; diff --git a/packages/core-plugin-api/src/deprecatedTypes.ts b/packages/core-plugin-api/src/deprecatedTypes.ts index 605dc72ee3..4b24614e17 100644 --- a/packages/core-plugin-api/src/deprecatedTypes.ts +++ b/packages/core-plugin-api/src/deprecatedTypes.ts @@ -23,6 +23,7 @@ import { /** * Observer interface for consuming an Observer, see TC39. * + * @public * @deprecated Please use the same type from `@backstage/types` instead */ export type Observer = CoreObserver; @@ -30,6 +31,7 @@ export type Observer = CoreObserver; /** * Subscription returned when subscribing to an Observable, see TC39. * + * @public * @deprecated Please use the same type from `@backstage/types` instead */ export type Subscription = CoreSubscription; @@ -42,6 +44,7 @@ export type Subscription = CoreSubscription; * 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. * + * @public * @deprecated Please use the same type from `@backstage/types` instead */ export type Observable = CoreObservable;