chore: flatten the optional properties from zod
Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
@@ -35,7 +35,7 @@ export const createMockActionContext = <
|
||||
TActionOutput extends JsonObject = JsonObject,
|
||||
>(
|
||||
options?: Partial<ActionContext<TActionInput, TActionOutput>>,
|
||||
): ActionContext<TActionInput, TActionOutput, any> => {
|
||||
): ActionContext<TActionInput, TActionOutput> => {
|
||||
const credentials = mockCredentials.user();
|
||||
const defaultContext = {
|
||||
logger: loggerToWinstonLogger(mockServices.logger.mock()),
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user