forked from triggerdotdev/trigger.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestTask.ts
More file actions
118 lines (112 loc) · 3.04 KB
/
testTask.ts
File metadata and controls
118 lines (112 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { z } from "zod";
import { MachinePresetName } from "@trigger.dev/core/v3/schemas";
export const RunOptionsData = z.object({
delaySeconds: z
.number()
.min(0)
.optional()
.transform((val) => (val === 0 ? undefined : val)),
ttlSeconds: z
.number()
.min(0)
.optional()
.transform((val) => (val === 0 ? undefined : val)),
idempotencyKey: z.string().optional(),
idempotencyKeyTTLSeconds: z
.number()
.min(0)
.optional()
.transform((val) => (val === 0 ? undefined : val)),
queue: z.string().optional(),
concurrencyKey: z.string().optional(),
maxAttempts: z.number().min(1).optional(),
machine: MachinePresetName.optional(),
maxDurationSeconds: z
.number()
.min(0)
.optional()
.transform((val) => (val === 0 ? undefined : val)),
tags: z
.string()
.optional()
.transform((val) => {
if (!val || val.trim() === "") {
return undefined;
}
return val
.split(",")
.map((tag) => tag.trim())
.filter((tag) => tag.length > 0);
})
.refine((tags) => !tags || tags.length <= 10, {
message: "Maximum 10 tags allowed",
})
.refine((tags) => !tags || tags.every((tag) => tag.length <= 128), {
message: "Each tag must be at most 128 characters long",
}),
version: z.string().optional(),
prioritySeconds: z
.number()
.min(0)
.optional()
.transform((val) => (val === 0 ? undefined : val)),
});
export type RunOptionsData = z.infer<typeof RunOptionsData>;
export const TestTaskData = z
.discriminatedUnion("triggerSource", [
z.object({
triggerSource: z.literal("STANDARD"),
payload: z
.string()
.optional()
.transform((val, ctx) => {
if (!val) {
return {};
}
try {
return JSON.parse(val);
} catch {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Payload must be a valid JSON string",
});
return z.NEVER;
}
}),
metadata: z
.string()
.optional()
.transform((val, ctx) => {
if (!val) {
return {};
}
try {
return JSON.parse(val);
} catch {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Metadata must be a valid JSON string",
});
return z.NEVER;
}
}),
}),
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(RunOptionsData)
.and(
z.object({
taskIdentifier: z.string(),
environmentId: z.string(),
})
);
export type TestTaskData = z.infer<typeof TestTaskData>;