Files
Eric Allam 3c492bc202 feat: Run metadata (#1357)
* 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
2024-09-26 09:23:38 +01:00

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>;