move types to node package
Signed-off-by: Kurt King <kurtaking@gmail.com>
This commit is contained in:
@@ -23,6 +23,8 @@ import {
|
||||
BackstageCredentials,
|
||||
LoggerService,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { CheckpointOptions } from '../checkpoints';
|
||||
|
||||
/**
|
||||
* ActionContext is passed into scaffolder actions.
|
||||
* @public
|
||||
@@ -36,10 +38,9 @@ export type ActionContext<
|
||||
secrets?: TaskSecrets;
|
||||
workspacePath: string;
|
||||
input: TActionInput;
|
||||
checkpoint<T extends JsonValue | void>(opts: {
|
||||
key: string;
|
||||
fn: () => Promise<T> | T;
|
||||
}): Promise<T>;
|
||||
checkpoint<T extends JsonValue | void>(
|
||||
opts: CheckpointOptions<T>,
|
||||
): Promise<T>;
|
||||
output(
|
||||
name: keyof TActionOutput,
|
||||
value: TActionOutput[keyof TActionOutput],
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2024 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 * from './types';
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2024 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 { JsonValue } from '@backstage/types';
|
||||
|
||||
/**
|
||||
* The status of a checkpoint, indicating whether it succeeded or failed.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type CheckpointStatus = 'failed' | 'success';
|
||||
|
||||
/**
|
||||
* Represents a successful checkpoint state with a value.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type CheckpointSuccessState = {
|
||||
status: Extract<CheckpointStatus, 'success'>;
|
||||
value: JsonValue;
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents a failed checkpoint state with a reason for failure.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type CheckpointFailedState = {
|
||||
status: Extract<CheckpointStatus, 'failed'>;
|
||||
reason: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* A map of checkpoint keys to their states.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type CheckpointState = {
|
||||
[key: string]: CheckpointSuccessState | CheckpointFailedState;
|
||||
};
|
||||
|
||||
/**
|
||||
* Options for updating a checkpoint in a task.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type UpdateCheckpointOptions = {
|
||||
key: string;
|
||||
} & CheckpointState[keyof CheckpointState];
|
||||
|
||||
/**
|
||||
* Options for checkpoint function invocation.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type CheckpointOptions<T extends JsonValue | void = JsonValue> = {
|
||||
/**
|
||||
* Unique key for the checkpoint
|
||||
*/
|
||||
key: string;
|
||||
/**
|
||||
* Function to execute for the checkpoint
|
||||
*/
|
||||
fn: () => Promise<T> | T;
|
||||
};
|
||||
@@ -24,3 +24,4 @@ export * from './actions';
|
||||
export * from './tasks';
|
||||
export * from './files';
|
||||
export * from './types';
|
||||
export * from './checkpoints';
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
|
||||
import { BackstageCredentials } from '@backstage/backend-plugin-api';
|
||||
import { TaskSpec } from '@backstage/plugin-scaffolder-common';
|
||||
import { JsonObject, JsonValue, Observable } from '@backstage/types';
|
||||
import { JsonObject, Observable } from '@backstage/types';
|
||||
import { UpdateCheckpointOptions } from '../checkpoints';
|
||||
|
||||
/**
|
||||
* TaskSecrets
|
||||
@@ -129,19 +130,7 @@ export interface TaskContext {
|
||||
| undefined
|
||||
>;
|
||||
|
||||
updateCheckpoint?(
|
||||
options:
|
||||
| {
|
||||
key: string;
|
||||
status: 'success';
|
||||
value: JsonValue;
|
||||
}
|
||||
| {
|
||||
key: string;
|
||||
status: 'failed';
|
||||
reason: string;
|
||||
},
|
||||
): Promise<void>;
|
||||
updateCheckpoint?(options: UpdateCheckpointOptions): Promise<void>;
|
||||
|
||||
serializeWorkspace?(options: { path: string }): Promise<void>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user