introduce core-types

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2021-10-21 09:45:32 +02:00
parent 00da5e919f
commit 41c49884d2
27 changed files with 350 additions and 89 deletions
+8
View File
@@ -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.
+19 -16
View File
@@ -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<T = JsonValue>(key?: string): T;
getOptional<T = JsonValue>(key?: string): T | undefined;
get<T = JsonValue_2>(key?: string): T;
getOptional<T = JsonValue_2>(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<T = JsonValue>(key?: string): T;
get<T = JsonValue_2>(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<T = JsonValue>(key?: string): T | undefined;
getOptional<T = JsonValue_2>(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<JsonValue> {}
// @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;
```
+1
View File
@@ -30,6 +30,7 @@
"clean": "backstage-cli clean"
},
"dependencies": {
"@backstage/core-types": "^0.1.0",
"lodash": "^4.17.21"
},
"devDependencies": {
+55
View File
@@ -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;
+3 -4
View File
@@ -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';
+2 -1
View File
@@ -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';
+1 -27
View File
@@ -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<JsonValue> {}
/**
* 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.
+2 -1
View File
@@ -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;
+15 -27
View File
@@ -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<AlertMessage>;
alert$(): Observable_2<AlertMessage>;
};
// 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<string | undefined>;
activeThemeId$(): Observable_2<string | undefined>;
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<AuthResponse>(
options: AuthRequesterOptions<AuthResponse>,
): AuthRequester<AuthResponse>;
authRequest$(): Observable<PendingAuthRequest[]>;
authRequest$(): Observable_2<PendingAuthRequest[]>;
};
// 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<T> = {
[Symbol.observable](): Observable<T>;
subscribe(observer: Observer<T>): Subscription;
subscribe(
onNext?: (value: T) => void,
onError?: (error: Error) => void,
onComplete?: () => void,
): Subscription;
};
// @public @deprecated
export type Observable<T> = Observable_2<T>;
// 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<T> = {
next?(value: T): void;
error?(error: Error): void;
complete?(): void;
};
// @public @deprecated
export type Observer<T> = Observer_2<T>;
// 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<void>;
signOut(): Promise<void>;
sessionState$(): Observable<SessionState>;
sessionState$(): Observable_2<SessionState>;
};
// 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<T>(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$<T>(key: string): Observable<StorageValueChange<T>>;
observe$<T>(key: string): Observable_2<StorageValueChange<T>>;
// 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<void>;
@@ -908,11 +899,8 @@ export type SubRouteRef<Params extends AnyParams = any> = {
// 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)
//
+1
View File
@@ -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",
@@ -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;
@@ -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.
@@ -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
@@ -15,7 +15,7 @@
*/
import { IconComponent } from '../../icons/types';
import { Observable } from '../../types';
import { Observable } from '@backstage/core-types';
import { ApiRef, createApiRef } from '../system';
/**
@@ -15,7 +15,7 @@
*/
import { ApiRef, createApiRef } from '../system';
import { Observable } from '../../types';
import { Observable } from '@backstage/core-types';
export type StorageValueChange<T = any> = {
key: string;
@@ -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.
@@ -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<T> = CoreObserver<T>;
/**
* 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<T> = CoreObservable<T>;
+1 -1
View File
@@ -27,4 +27,4 @@ export * from './extensions';
export * from './icons';
export * from './plugin';
export * from './routing';
export * from './types';
export * from './deprecatedTypes';
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
extends: [require.resolve('@backstage/cli/config/eslint')],
};
+9
View File
@@ -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)
+49
View File
@@ -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<JsonValue> {}
// @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<T> = {
[Symbol.observable](): Observable<T>;
subscribe(observer: Observer<T>): 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<T> = {
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;
};
```
+39
View File
@@ -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"
]
}
+24
View File
@@ -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';
+43
View File
@@ -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<JsonValue> {}
/**
* A type representing all allowed JSON values.
*
* @public
*/
export type JsonValue = JsonObject | JsonArray | JsonPrimitive;
@@ -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.
*/
+17
View File
@@ -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 {};
+3 -1
View File
@@ -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<express.Router>;
// @public (undocumented)
export const createTemplateAction: <
Input extends Partial<{
[name: string]: JsonValue | Partial<JsonObject> | undefined;
[name: string]: JsonValue_2 | Partial<JsonObject_2> | undefined;
}>,
>(
templateAction: TemplateAction<Input>,