3c492bc202
* Run metadata * Remove metadata from context, move it to it’s own tab * More run metadata stuff - Add metadata to testing - Make using metadata outside of runs a no-op - Add docs * Replaying should copy over the metadata * transfer final attempt output to the task run * A couple of minor fixes * Use the new clientOrThrow() method everywhere * Cleaned up the update metadata endpoint and added an API doc page for it * Mirror task run attempt errors and output
67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
import { z } from "zod";
|
|
|
|
export const TestTaskData = z
|
|
.discriminatedUnion("triggerSource", [
|
|
z.object({
|
|
triggerSource: z.literal("STANDARD"),
|
|
payload: z.string().transform((payload, ctx) => {
|
|
try {
|
|
const data = JSON.parse(payload);
|
|
return data as any;
|
|
} catch (e) {
|
|
console.log("parsing error", e);
|
|
|
|
if (e instanceof Error) {
|
|
ctx.addIssue({
|
|
code: z.ZodIssueCode.custom,
|
|
message: e.message,
|
|
});
|
|
} else {
|
|
ctx.addIssue({
|
|
code: z.ZodIssueCode.custom,
|
|
message: "This is invalid JSON",
|
|
});
|
|
}
|
|
}
|
|
}),
|
|
metadata: z.string().transform((metadata, ctx) => {
|
|
try {
|
|
const data = JSON.parse(metadata);
|
|
return data as any;
|
|
} catch (e) {
|
|
console.log("parsing error", e);
|
|
|
|
if (e instanceof Error) {
|
|
ctx.addIssue({
|
|
code: z.ZodIssueCode.custom,
|
|
message: e.message,
|
|
});
|
|
} else {
|
|
ctx.addIssue({
|
|
code: z.ZodIssueCode.custom,
|
|
message: "This is invalid JSON",
|
|
});
|
|
}
|
|
}
|
|
}),
|
|
}),
|
|
z.object({
|
|
triggerSource: z.literal("SCHEDULED"),
|
|
timestamp: z.preprocess((val) => (val === "" ? undefined : val), z.coerce.date()),
|
|
lastTimestamp: z.preprocess(
|
|
(val) => (val === "" ? undefined : val),
|
|
z.coerce.date().optional()
|
|
),
|
|
timezone: z.string(),
|
|
externalId: z.preprocess((val) => (val === "" ? undefined : val), z.string().optional()),
|
|
}),
|
|
])
|
|
.and(
|
|
z.object({
|
|
taskIdentifier: z.string(),
|
|
environmentId: z.string(),
|
|
})
|
|
);
|
|
|
|
export type TestTaskData = z.infer<typeof TestTaskData>;
|