chore: simplify the types a little bit
Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
|
||||
import { ExtensionPoint } from '@backstage/backend-plugin-api';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import { JsonValue } from '@backstage/types';
|
||||
import { Logger } from 'winston';
|
||||
import { Schema } from 'jsonschema';
|
||||
import { TemplateInfo } from '@backstage/plugin-scaffolder-common';
|
||||
@@ -18,24 +17,16 @@ import { z } from 'zod';
|
||||
// @public
|
||||
export type ActionContext<
|
||||
TActionInput extends JsonObject,
|
||||
TActionOutput extends JsonObject | unknown | undefined = unknown,
|
||||
TActionOutput extends JsonObject = JsonObject,
|
||||
> = {
|
||||
logger: Logger;
|
||||
logStream: Writable;
|
||||
secrets?: TaskSecrets;
|
||||
workspacePath: string;
|
||||
input: TActionInput;
|
||||
output<KEY extends keyof TActionOutput>(
|
||||
name: TActionOutput extends JsonObject
|
||||
? KEY
|
||||
: TActionOutput extends undefined
|
||||
? never
|
||||
: string,
|
||||
value: TActionOutput extends JsonObject
|
||||
? TActionOutput[KEY]
|
||||
: TActionOutput extends undefined
|
||||
? never
|
||||
: JsonValue,
|
||||
output(
|
||||
name: keyof TActionOutput,
|
||||
value: TActionOutput[keyof TActionOutput],
|
||||
): void;
|
||||
createTemporaryDirectory(): Promise<string>;
|
||||
templateInfo?: TemplateInfo;
|
||||
@@ -47,35 +38,24 @@ export type ActionContext<
|
||||
signal?: AbortSignal;
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
export type ActionOutputType<
|
||||
TOutputSchema,
|
||||
FallbackOutput = unknown,
|
||||
> = TOutputSchema extends z.ZodType<any, any, infer IReturn>
|
||||
? IReturn
|
||||
: TOutputSchema extends undefined
|
||||
? undefined
|
||||
: FallbackOutput;
|
||||
|
||||
// @public
|
||||
export const createTemplateAction: <
|
||||
TInputParams,
|
||||
TOutputParams = unknown,
|
||||
TInputParams extends JsonObject = JsonObject,
|
||||
TOutputParams extends JsonObject = JsonObject,
|
||||
TInputSchema extends z.ZodType<any, z.ZodTypeDef, any> | Schema = {},
|
||||
TOutputSchema extends z.ZodType<any, z.ZodTypeDef, any> | Schema = {},
|
||||
TActionInput = TInputSchema extends z.ZodType<any, any, infer IReturn>
|
||||
? IReturn
|
||||
: TInputParams,
|
||||
TActionOutput extends ActionOutputType<
|
||||
TOutputSchema,
|
||||
TOutputParams
|
||||
> = ActionOutputType<TOutputSchema, TOutputParams>,
|
||||
TActionOutput = TOutputSchema extends z.ZodType<any, any, infer IReturn_1>
|
||||
? IReturn_1
|
||||
: TOutputParams,
|
||||
>(
|
||||
action: TemplateActionOptions<
|
||||
TActionInput,
|
||||
TActionOutput,
|
||||
TInputSchema,
|
||||
TOutputSchema,
|
||||
TActionOutput
|
||||
TOutputSchema
|
||||
>,
|
||||
) => TemplateAction<TActionInput, TActionOutput>;
|
||||
|
||||
@@ -94,7 +74,10 @@ export type TaskSecrets = Record<string, string> & {
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
export type TemplateAction<TActionInput = unknown, TActionOutput = unknown> = {
|
||||
export type TemplateAction<
|
||||
TActionInput = unknown,
|
||||
TActionOutput = JsonObject,
|
||||
> = {
|
||||
id: string;
|
||||
description?: string;
|
||||
examples?: {
|
||||
@@ -112,9 +95,9 @@ export type TemplateAction<TActionInput = unknown, TActionOutput = unknown> = {
|
||||
// @public (undocumented)
|
||||
export type TemplateActionOptions<
|
||||
TActionInput = {},
|
||||
TActionOutput = {},
|
||||
TInputSchema extends Schema | z.ZodType = {},
|
||||
TOutputSchema extends Schema | z.ZodType = {},
|
||||
TActionOutput extends ActionOutputType<TOutputSchema> = ActionOutputType<TOutputSchema>,
|
||||
> = {
|
||||
id: string;
|
||||
description?: string;
|
||||
|
||||
@@ -18,23 +18,14 @@ import { ActionContext, TemplateAction } from './types';
|
||||
import { z } from 'zod';
|
||||
import { Schema } from 'jsonschema';
|
||||
import zodToJsonSchema from 'zod-to-json-schema';
|
||||
|
||||
/** @public */
|
||||
export type ActionOutputType<
|
||||
TOutputSchema,
|
||||
FallbackOutput = unknown,
|
||||
> = TOutputSchema extends z.ZodType<any, any, infer IReturn>
|
||||
? IReturn
|
||||
: TOutputSchema extends undefined
|
||||
? undefined
|
||||
: FallbackOutput;
|
||||
import { JsonObject } from '@backstage/types';
|
||||
|
||||
/** @public */
|
||||
export type TemplateActionOptions<
|
||||
TActionInput = {},
|
||||
TActionOutput = {},
|
||||
TInputSchema extends Schema | z.ZodType = {},
|
||||
TOutputSchema extends Schema | z.ZodType = {},
|
||||
TActionOutput extends ActionOutputType<TOutputSchema> = ActionOutputType<TOutputSchema>,
|
||||
> = {
|
||||
id: string;
|
||||
description?: string;
|
||||
@@ -53,23 +44,22 @@ export type TemplateActionOptions<
|
||||
* @public
|
||||
*/
|
||||
export const createTemplateAction = <
|
||||
TInputParams,
|
||||
TOutputParams = unknown,
|
||||
TInputParams extends JsonObject = JsonObject,
|
||||
TOutputParams extends JsonObject = JsonObject,
|
||||
TInputSchema extends Schema | z.ZodType = {},
|
||||
TOutputSchema extends Schema | z.ZodType = {},
|
||||
TActionInput = TInputSchema extends z.ZodType<any, any, infer IReturn>
|
||||
? IReturn
|
||||
: TInputParams,
|
||||
TActionOutput extends ActionOutputType<
|
||||
TOutputSchema,
|
||||
TOutputParams
|
||||
> = ActionOutputType<TOutputSchema, TOutputParams>,
|
||||
TActionOutput = TOutputSchema extends z.ZodType<any, any, infer IReturn>
|
||||
? IReturn
|
||||
: TOutputParams,
|
||||
>(
|
||||
action: TemplateActionOptions<
|
||||
TActionInput,
|
||||
TActionOutput,
|
||||
TInputSchema,
|
||||
TOutputSchema,
|
||||
TActionOutput
|
||||
TOutputSchema
|
||||
>,
|
||||
): TemplateAction<TActionInput, TActionOutput> => {
|
||||
const inputSchema =
|
||||
|
||||
@@ -17,6 +17,5 @@
|
||||
export {
|
||||
createTemplateAction,
|
||||
type TemplateActionOptions,
|
||||
type ActionOutputType,
|
||||
} from './createTemplateAction';
|
||||
export { type ActionContext, type TemplateAction } from './types';
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
import { Logger } from 'winston';
|
||||
import { Writable } from 'stream';
|
||||
import { JsonObject, JsonValue } from '@backstage/types';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import { TaskSecrets } from '../tasks';
|
||||
import { TemplateInfo } from '@backstage/plugin-scaffolder-common';
|
||||
import { UserEntity } from '@backstage/catalog-model';
|
||||
@@ -28,24 +28,16 @@ import { Schema } from 'jsonschema';
|
||||
*/
|
||||
export type ActionContext<
|
||||
TActionInput extends JsonObject,
|
||||
TActionOutput extends JsonObject | unknown | undefined = unknown,
|
||||
TActionOutput extends JsonObject = JsonObject,
|
||||
> = {
|
||||
logger: Logger;
|
||||
logStream: Writable;
|
||||
secrets?: TaskSecrets;
|
||||
workspacePath: string;
|
||||
input: TActionInput;
|
||||
output<KEY extends keyof TActionOutput>(
|
||||
name: TActionOutput extends JsonObject
|
||||
? KEY
|
||||
: TActionOutput extends undefined
|
||||
? never
|
||||
: string,
|
||||
value: TActionOutput extends JsonObject
|
||||
? TActionOutput[KEY]
|
||||
: TActionOutput extends undefined
|
||||
? never
|
||||
: JsonValue,
|
||||
output(
|
||||
name: keyof TActionOutput,
|
||||
value: TActionOutput[keyof TActionOutput],
|
||||
): void;
|
||||
|
||||
/**
|
||||
@@ -82,7 +74,10 @@ export type ActionContext<
|
||||
};
|
||||
|
||||
/** @public */
|
||||
export type TemplateAction<TActionInput = unknown, TActionOutput = unknown> = {
|
||||
export type TemplateAction<
|
||||
TActionInput = unknown,
|
||||
TActionOutput = JsonObject,
|
||||
> = {
|
||||
id: string;
|
||||
description?: string;
|
||||
examples?: { description: string; example: string }[];
|
||||
|
||||
Reference in New Issue
Block a user