chore: flatten the optional properties from zod

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2025-02-07 13:23:17 +01:00
committed by benjdlambert
parent cf8b627f07
commit e2d82fc3d8
3 changed files with 20 additions and 10 deletions
@@ -52,6 +52,17 @@ export type TemplateActionOptions<
) => Promise<void>;
};
/**
* @ignore
*/
type FlattenOptionalProperties<T extends { [key in string]: unknown }> = Expand<
{
[K in keyof T as undefined extends T[K] ? never : K]: T[K];
} & {
[K in keyof T as undefined extends T[K] ? K : never]?: T[K];
}
>;
/**
* This function is used to create new template actions to get type safety.
* Will convert zod schemas to json schemas for use throughout the system.
@@ -72,10 +83,10 @@ export function createTemplateAction<
TOutputSchema
>,
): TemplateAction<
Expand<{
FlattenOptionalProperties<{
[key in keyof TInputSchema]: z.output<ReturnType<TInputSchema[key]>>;
}>,
Expand<{
FlattenOptionalProperties<{
[key in keyof TOutputSchema]: z.output<ReturnType<TOutputSchema[key]>>;
}>,
TInputSchema
+6 -7
View File
@@ -42,14 +42,13 @@ export type ActionContext<
secrets?: TaskSecrets;
workspacePath: string;
input: TActionInput;
checkpoint<U extends JsonValue>(
key: string,
fn: () => Promise<U>,
): Promise<U>;
checkpoint<T extends JsonValue | void>(opts: {
key: string;
fn: () => Promise<T> | T;
}): Promise<T>;
output(
...params: {
[K in keyof TActionOutput]: [name: K, value: TActionOutput[K]];
}[keyof TActionOutput]
name: keyof TActionOutput,
value: TActionOutput[keyof TActionOutput],
): void;
/**
* Creates a temporary directory for use by the action, which is then cleaned up automatically.