clean up types some

Signed-off-by: Kurt King <kurtaking@gmail.com>
This commit is contained in:
Kurt King
2025-03-24 19:41:31 -06:00
committed by benjdlambert
parent 70eae7fa1a
commit dbde1805b6
9 changed files with 50 additions and 85 deletions
+2 -2
View File
@@ -23,7 +23,7 @@ import {
BackstageCredentials,
LoggerService,
} from '@backstage/backend-plugin-api';
import { CheckpointOptions } from '../checkpoints';
import { CheckpointContext } from '../checkpoints';
/**
* ActionContext is passed into scaffolder actions.
@@ -39,7 +39,7 @@ export type ActionContext<
workspacePath: string;
input: TActionInput;
checkpoint<T extends JsonValue | void>(
opts: CheckpointOptions<T>,
opts: CheckpointContext<T>,
): Promise<T>;
output(
name: keyof TActionOutput,
@@ -1,5 +1,5 @@
/*
* Copyright 2024 The Backstage Authors
* Copyright 2025 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.
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { JsonValue } from '@backstage/types';
/**
@@ -28,9 +27,9 @@ export type CheckpointStatus = 'failed' | 'success';
*
* @public
*/
export type CheckpointSuccessState = {
status: Extract<CheckpointStatus, 'success'>;
value: JsonValue;
export type CheckpointSuccessState<T extends JsonValue = JsonValue> = {
status: 'success';
value: T;
};
/**
@@ -39,34 +38,34 @@ export type CheckpointSuccessState = {
* @public
*/
export type CheckpointFailedState = {
status: Extract<CheckpointStatus, 'failed'>;
status: 'failed';
reason: string;
};
/**
* Represents the union of all possible checkpoint state values.
*
* @public
*/
export type CheckpointStateValue =
| CheckpointSuccessState
| CheckpointFailedState;
/**
* A map of checkpoint keys to their states.
*
* @public
*/
export type CheckpointState = {
[key: string]: CheckpointSuccessState | CheckpointFailedState;
[key: string]: CheckpointStateValue;
};
/**
* Options for updating a checkpoint in a task.
* Context for checkpoint function invocation.
*
* @public
*/
export type UpdateCheckpointOptions = {
key: string;
} & CheckpointState[keyof CheckpointState];
/**
* Options for checkpoint function invocation.
*
* @public
*/
export type CheckpointOptions<T extends JsonValue | void = JsonValue> = {
export type CheckpointContext<T extends JsonValue | void = JsonValue> = {
/**
* Unique key for the checkpoint
*/
@@ -25,4 +25,5 @@ export type {
TaskContext,
TaskEventType,
TaskStatus,
UpdateTaskCheckpointOptions,
} from './types';
+11 -2
View File
@@ -17,7 +17,7 @@
import { BackstageCredentials } from '@backstage/backend-plugin-api';
import { TaskSpec } from '@backstage/plugin-scaffolder-common';
import { JsonObject, Observable } from '@backstage/types';
import { UpdateCheckpointOptions } from '../checkpoints';
import { CheckpointStateValue } from '../checkpoints';
/**
* TaskSecrets
@@ -105,6 +105,15 @@ export type TaskBrokerDispatchOptions = {
createdBy?: string;
};
/**
* Options for updating a checkpoint in a task.
*
* @public
*/
export type UpdateTaskCheckpointOptions = {
key: string;
} & CheckpointStateValue;
/**
* Task
*
@@ -130,7 +139,7 @@ export interface TaskContext {
| undefined
>;
updateCheckpoint?(options: UpdateCheckpointOptions): Promise<void>;
updateCheckpoint?(options: UpdateTaskCheckpointOptions): Promise<void>;
serializeWorkspace?(options: { path: string }): Promise<void>;