From 974a7917f1bcba866c798dc6a16a338a81560ef5 Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 23 Feb 2022 16:46:47 +0100 Subject: [PATCH] chore: reworking some types Signed-off-by: blam --- plugins/scaffolder/api-report.md | 187 ++++++++++++++---- plugins/scaffolder/src/api.ts | 2 +- .../src/components/TaskPage/TaskPage.tsx | 10 +- .../src/components/TaskPage/TaskPageLinks.tsx | 4 +- .../TemplatePage/TemplatePage.test.tsx | 3 +- .../components/TemplatePage/TemplatePage.tsx | 21 +- .../src/components/hooks/useEventStream.ts | 17 +- plugins/scaffolder/src/types.ts | 38 ++-- 8 files changed, 194 insertions(+), 88 deletions(-) diff --git a/plugins/scaffolder/api-report.md b/plugins/scaffolder/api-report.md index fb3fd830f7..95fc6f9aa2 100644 --- a/plugins/scaffolder/api-report.md +++ b/plugins/scaffolder/api-report.md @@ -12,7 +12,6 @@ import { ComponentProps } from 'react'; import { ComponentType } from 'react'; import { DiscoveryApi } from '@backstage/core-plugin-api'; import { Entity } from '@backstage/catalog-model'; -import { EntityName } from '@backstage/catalog-model'; import { Extension } from '@backstage/core-plugin-api'; import { ExternalRouteRef } from '@backstage/core-plugin-api'; import { FetchApi } from '@backstage/core-plugin-api'; @@ -20,7 +19,7 @@ import { FieldProps } from '@rjsf/core'; import { FieldValidation } from '@rjsf/core'; import { IconButton } from '@material-ui/core'; import { JsonObject } from '@backstage/types'; -import { JSONSchema } from '@backstage/catalog-model'; +import { JSONSchema7 } from 'json-schema'; import { Observable } from '@backstage/types'; import { default as React_2 } from 'react'; import { ReactNode } from 'react'; @@ -122,6 +121,48 @@ export type FieldExtensionOptions< validation?: CustomFieldValidator; }; +// Warning: (ae-missing-release-tag) "JobStatus" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export type JobStatus = 'PENDING' | 'STARTED' | 'COMPLETED' | 'FAILED'; + +// Warning: (ae-missing-release-tag) "ListActionsResponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export type ListActionsResponse = Array<{ + id: string; + description?: string; + schema?: { + input?: JSONSchema7; + output?: JSONSchema7; + }; +}>; + +// Warning: (ae-missing-release-tag) "LogEvent" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export type LogEvent = { + type: 'log' | 'completion'; + body: { + message: string; + stepId?: string; + status?: LogEventStatus; + }; + createdAt: string; + id: string; + taskId: string; +}; + +// Warning: (ae-missing-release-tag) "LogEventStatus" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export type LogEventStatus = + | 'open' + | 'processing' + | 'failed' + | 'completed' + | 'skipped'; + // Warning: (ae-missing-release-tag) "OwnedEntityPicker" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public @@ -210,34 +251,24 @@ export interface RepoUrlPickerUiOptions { // @public export interface ScaffolderApi { // (undocumented) - getIntegrationsList(options: { allowedHosts: string[] }): Promise< - { - type: string; - title: string; - host: string; - }[] - >; - // Warning: (ae-forgotten-export) The symbol "ScaffolderTask" needs to be exported by the entry point index.d.ts - // + getIntegrationsList( + options: ScaffolderGetIntegrationsListOptions, + ): Promise; // (undocumented) getTask(taskId: string): Promise; - // Warning: (ae-forgotten-export) The symbol "TemplateParameterSchema" needs to be exported by the entry point index.d.ts - // // (undocumented) getTemplateParameterSchema( - templateName: EntityName, + templateRef: string, ): Promise; - // Warning: (ae-forgotten-export) The symbol "ListActionsResponse" needs to be exported by the entry point index.d.ts listActions(): Promise; + // Warning: (tsdoc-param-tag-with-invalid-name) The @param block should be followed by a valid parameter name: The identifier cannot non-word characters + // Warning: (tsdoc-param-tag-with-invalid-name) The @param block should be followed by a valid parameter name: The identifier cannot non-word characters + // Warning: (tsdoc-param-tag-with-invalid-name) The @param block should be followed by a valid parameter name: The identifier cannot non-word characters scaffold( - templateName: string, - values: Record, - secrets?: Record, - ): Promise; - // Warning: (ae-forgotten-export) The symbol "LogEvent" needs to be exported by the entry point index.d.ts - // + options: ScaffolderScaffoldOptions, + ): Promise; // (undocumented) - streamLogs(options: { taskId: string; after?: number }): Observable; + streamLogs(options: ScaffolderStreamLogsOptions): Observable; } // @public @@ -252,28 +283,25 @@ export class ScaffolderClient implements ScaffolderApi { useLongPollingLogs?: boolean; }); // (undocumented) - getIntegrationsList(options: { allowedHosts: string[] }): Promise< - { - type: string; - title: string; - host: string; - }[] - >; + getIntegrationsList( + options: ScaffolderGetIntegrationsListOptions, + ): Promise; // (undocumented) - getTask(taskId: string): Promise; + getTask(taskId: string): Promise; // (undocumented) getTemplateParameterSchema( - templateName: EntityName, + templateRef: string, ): Promise; // (undocumented) listActions(): Promise; + // Warning: (tsdoc-param-tag-with-invalid-name) The @param block should be followed by a valid parameter name: The identifier cannot non-word characters + // Warning: (tsdoc-param-tag-with-invalid-name) The @param block should be followed by a valid parameter name: The identifier cannot non-word characters + // Warning: (tsdoc-param-tag-with-invalid-name) The @param block should be followed by a valid parameter name: The identifier cannot non-word characters scaffold( - templateName: string, - values: Record, - secrets?: Record, - ): Promise; + options: ScaffolderScaffoldOptions, + ): Promise; // (undocumented) - streamLogs(options: { taskId: string; after?: number }): Observable; + streamLogs(options: ScaffolderStreamLogsOptions): Observable; } // Warning: (ae-missing-release-tag) "ScaffolderFieldExtensions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) @@ -281,6 +309,26 @@ export class ScaffolderClient implements ScaffolderApi { // @public (undocumented) export const ScaffolderFieldExtensions: React_2.ComponentType; +// Warning: (ae-missing-release-tag) "ScaffolderGetIntegrationsListOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export interface ScaffolderGetIntegrationsListOptions { + // (undocumented) + allowedHosts: string[]; +} + +// Warning: (ae-missing-release-tag) "ScaffolderGetIntegrationsListResponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export interface ScaffolderGetIntegrationsListResponse { + // (undocumented) + integrations: { + type: string; + title: string; + host: string; + }[]; +} + // Warning: (ae-missing-release-tag) "ScaffolderPage" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) @@ -316,6 +364,58 @@ export const scaffolderPlugin: BackstagePlugin< } >; +// Warning: (ae-missing-release-tag) "ScaffolderScaffoldOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export interface ScaffolderScaffoldOptions { + // (undocumented) + secrets?: Record; + // (undocumented) + templateName: string; + // (undocumented) + values: Record; +} + +// Warning: (ae-missing-release-tag) "ScaffolderScaffoldResponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export interface ScaffolderScaffoldResponse { + // (undocumented) + taskId: string; +} + +// Warning: (ae-missing-release-tag) "ScaffolderStreamLogsOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export interface ScaffolderStreamLogsOptions { + // (undocumented) + after?: number; + // (undocumented) + taskId: string; +} + +// Warning: (ae-missing-release-tag) "ScaffolderTask" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export type ScaffolderTask = { + id: string; + spec: TaskSpec; + status: 'failed' | 'completed' | 'processing' | 'open' | 'cancelled'; + lastHeartbeatAt: string; + createdAt: string; +}; + +// Warning: (ae-missing-release-tag) "ScaffolderTaskOutput" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export type ScaffolderTaskOutput = { + entityRef?: string; + remoteUrl?: string; + links?: ScaffolderOutputLink[]; +} & { + [key: string]: unknown; +}; + // @public export const TaskPage: ({ loadingText }: TaskPageProps) => JSX.Element; @@ -348,6 +448,17 @@ export type TemplateListProps = { }; }; +// Warning: (ae-missing-release-tag) "TemplateParameterSchema" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export type TemplateParameterSchema = { + title: string; + steps: Array<{ + title: string; + schema: JsonObject; + }>; +}; + // Warning: (ae-missing-release-tag) "TemplateTypePicker" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) @@ -357,4 +468,8 @@ export const TemplateTypePicker: () => JSX.Element | null; export const useTemplateSecrets: () => { setSecret: (input: Record) => void; }; + +// Warnings were encountered during analysis: +// +// src/types.d.ts:32:5 - (ae-forgotten-export) The symbol "ScaffolderOutputLink" needs to be exported by the entry point index.d.ts ``` diff --git a/plugins/scaffolder/src/api.ts b/plugins/scaffolder/src/api.ts index 8a29daa95d..d12ce68555 100644 --- a/plugins/scaffolder/src/api.ts +++ b/plugins/scaffolder/src/api.ts @@ -140,7 +140,7 @@ export class ScaffolderClient implements ScaffolderApi { } const { id } = (await response.json()) as { id: string }; - return { jobId: id }; + return { taskId: id }; } async getTask(taskId: string): Promise { diff --git a/plugins/scaffolder/src/components/TaskPage/TaskPage.tsx b/plugins/scaffolder/src/components/TaskPage/TaskPage.tsx index a642660bac..5387391e99 100644 --- a/plugins/scaffolder/src/components/TaskPage/TaskPage.tsx +++ b/plugins/scaffolder/src/components/TaskPage/TaskPage.tsx @@ -49,7 +49,7 @@ import React, { memo, useEffect, useMemo, useState } from 'react'; import { generatePath, useNavigate, useParams } from 'react-router'; import useInterval from 'react-use/lib/useInterval'; import { rootRouteRef } from '../../routes'; -import { Status, TaskOutput } from '../../types'; +import { LogEventStatus, ScaffolderTaskOutput } from '../../types'; import { useTaskEventStream } from '../hooks/useEventStream'; import { TaskPageLinks } from './TaskPageLinks'; @@ -86,7 +86,7 @@ const useStyles = makeStyles((theme: Theme) => type TaskStep = { id: string; name: string; - status: Status; + status: LogEventStatus; startedAt?: string; endedAt?: string; }; @@ -217,7 +217,11 @@ export const TaskStatusStepper = memo( }, ); -const hasLinks = ({ entityRef, remoteUrl, links = [] }: TaskOutput): boolean => +const hasLinks = ({ + entityRef, + remoteUrl, + links = [], +}: ScaffolderTaskOutput): boolean => !!(entityRef || remoteUrl || links.length > 0); /** diff --git a/plugins/scaffolder/src/components/TaskPage/TaskPageLinks.tsx b/plugins/scaffolder/src/components/TaskPage/TaskPageLinks.tsx index d53b5d705c..5451b4e725 100644 --- a/plugins/scaffolder/src/components/TaskPage/TaskPageLinks.tsx +++ b/plugins/scaffolder/src/components/TaskPage/TaskPageLinks.tsx @@ -19,12 +19,12 @@ import { entityRouteRef } from '@backstage/plugin-catalog-react'; import { Box } from '@material-ui/core'; import LanguageIcon from '@material-ui/icons/Language'; import React from 'react'; -import { TaskOutput } from '../../types'; +import { ScaffolderTaskOutput } from '../../types'; import { IconLink } from './IconLink'; import { IconComponent, useApp, useRouteRef } from '@backstage/core-plugin-api'; type TaskPageLinksProps = { - output: TaskOutput; + output: ScaffolderTaskOutput; }; export const TaskPageLinks = ({ output }: TaskPageLinksProps) => { diff --git a/plugins/scaffolder/src/components/TemplatePage/TemplatePage.test.tsx b/plugins/scaffolder/src/components/TemplatePage/TemplatePage.test.tsx index 48710b7086..d0eca58b9d 100644 --- a/plugins/scaffolder/src/components/TemplatePage/TemplatePage.test.tsx +++ b/plugins/scaffolder/src/components/TemplatePage/TemplatePage.test.tsx @@ -23,7 +23,8 @@ import { ThemeProvider } from '@material-ui/core'; import { act, fireEvent, within } from '@testing-library/react'; import React from 'react'; import { MemoryRouter, Route } from 'react-router'; -import { ScaffolderApi, scaffolderApiRef } from '../../api'; +import { scaffolderApiRef } from '../../api'; +import { ScaffolderApi } from '../../types'; import { rootRouteRef } from '../../routes'; import { TemplatePage } from './TemplatePage'; import { diff --git a/plugins/scaffolder/src/components/TemplatePage/TemplatePage.tsx b/plugins/scaffolder/src/components/TemplatePage/TemplatePage.tsx index d30c292053..fade247a24 100644 --- a/plugins/scaffolder/src/components/TemplatePage/TemplatePage.tsx +++ b/plugins/scaffolder/src/components/TemplatePage/TemplatePage.tsx @@ -42,16 +42,11 @@ import { useRouteRef, } from '@backstage/core-plugin-api'; -const useTemplateParameterSchema = (templateName: string) => { +const useTemplateParameterSchema = (templateRef: string) => { const scaffolderApi = useApi(scaffolderApiRef); const { value, loading, error } = useAsync( - () => - scaffolderApi.getTemplateParameterSchema({ - name: templateName, - kind: 'template', - namespace: 'default', - }), - [scaffolderApi, templateName], + () => scaffolderApi.getTemplateParameterSchema(templateRef), + [scaffolderApi, templateRef], ); return { schema: value, loading, error }; }; @@ -141,11 +136,11 @@ export const TemplatePage = ({ ); const handleCreate = async () => { - const id = await scaffolderApi.scaffold( + const { taskId } = await scaffolderApi.scaffold({ templateName, - formState, - secretsContext?.secrets, - ); + values: formState, + secrets: secretsContext?.secrets, + }); const formParams = qs.stringify( { formData: formState }, @@ -158,7 +153,7 @@ export const TemplatePage = ({ // extra back/forward slots. window.history?.replaceState(null, document.title, newUrl); - navigate(generatePath(`${rootLink()}/tasks/:taskId`, { taskId: id })); + navigate(generatePath(`${rootLink()}/tasks/:taskId`, { taskId })); }; if (error) { diff --git a/plugins/scaffolder/src/components/hooks/useEventStream.ts b/plugins/scaffolder/src/components/hooks/useEventStream.ts index 7414a35189..b5ce7241a1 100644 --- a/plugins/scaffolder/src/components/hooks/useEventStream.ts +++ b/plugins/scaffolder/src/components/hooks/useEventStream.ts @@ -15,14 +15,19 @@ */ import { useImmerReducer } from 'use-immer'; import { useEffect } from 'react'; -import { scaffolderApiRef, LogEvent } from '../../api'; -import { ScaffolderTask, Status, TaskOutput } from '../../types'; +import { scaffolderApiRef } from '../../api'; +import { + ScaffolderTask, + LogEventStatus, + ScaffolderTaskOutput, + LogEvent, +} from '../../types'; import { useApi } from '@backstage/core-plugin-api'; import { Subscription } from '@backstage/types'; type Step = { id: string; - status: Status; + status: LogEventStatus; endedAt?: string; startedAt?: string; }; @@ -34,16 +39,16 @@ export type TaskStream = { completed: boolean; task?: ScaffolderTask; steps: { [stepId in string]: Step }; - output?: TaskOutput; + output?: ScaffolderTaskOutput; }; type ReducerLogEntry = { createdAt: string; body: { stepId?: string; - status?: Status; + status?: LogEventStatus; message: string; - output?: TaskOutput; + output?: ScaffolderTaskOutput; }; }; diff --git a/plugins/scaffolder/src/types.ts b/plugins/scaffolder/src/types.ts index 9b65bc5e5e..a6304fc2c2 100644 --- a/plugins/scaffolder/src/types.ts +++ b/plugins/scaffolder/src/types.ts @@ -17,28 +17,14 @@ import { TaskSpec } from '@backstage/plugin-scaffolder-common'; import { JsonObject, Observable } from '@backstage/types'; import { JSONSchema7 } from 'json-schema'; -export type Status = 'open' | 'processing' | 'failed' | 'completed' | 'skipped'; -export type JobStatus = 'PENDING' | 'STARTED' | 'COMPLETED' | 'FAILED'; -export type Job = { - id: string; - metadata: { - entity: any; - values: any; - remoteUrl?: string; - catalogInfoUrl?: string; - }; - status: JobStatus; - stages: Stage[]; - error?: Error; -}; +export type LogEventStatus = + | 'open' + | 'processing' + | 'failed' + | 'completed' + | 'skipped'; -export type Stage = { - name: string; - log: string[]; - status: JobStatus; - startedAt: string; - endedAt?: string; -}; +export type JobStatus = 'PENDING' | 'STARTED' | 'COMPLETED' | 'FAILED'; export type ScaffolderTask = { id: string; @@ -57,19 +43,19 @@ export type ListActionsResponse = Array<{ }; }>; -type OutputLink = { +type ScaffolderOutputLink = { title?: string; icon?: string; url?: string; entityRef?: string; }; -export type TaskOutput = { +export type ScaffolderTaskOutput = { /** @deprecated use the `links` property to link out to relevant resources */ entityRef?: string; /** @deprecated use the `links` property to link out to relevant resources */ remoteUrl?: string; - links?: OutputLink[]; + links?: ScaffolderOutputLink[]; } & { [key: string]: unknown; }; @@ -87,7 +73,7 @@ export type LogEvent = { body: { message: string; stepId?: string; - status?: Status; + status?: LogEventStatus; }; createdAt: string; id: string; @@ -100,7 +86,7 @@ export interface ScaffolderScaffoldOptions { } export interface ScaffolderScaffoldResponse { - jobId: string; + taskId: string; } export interface ScaffolderGetIntegrationsListOptions {