-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathschema.ts
More file actions
131 lines (112 loc) · 4.2 KB
/
Copy pathschema.ts
File metadata and controls
131 lines (112 loc) · 4.2 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
119
120
121
122
123
124
125
126
127
128
129
130
131
import { z } from "zod";
const FunctionNameSchema = z
.string()
.trim()
.min(1, "Function name cannot be empty")
.regex(/^[^.]+$/, "Function name cannot contain dots");
const FunctionFileSchema = z.object({
path: z.string().min(1),
content: z.string(),
});
// Base fields shared by all automation types
const AutomationBaseSchema = z.object({
name: z.string().min(1, "Automation name cannot be empty"),
description: z.string().nullable().optional(),
function_args: z.record(z.string(), z.unknown()).nullable().optional(),
is_active: z.boolean().optional().default(true),
});
// One-time scheduled automation
const ScheduledOneTimeSchema = AutomationBaseSchema.extend({
type: z.literal("scheduled"),
schedule_mode: z.literal("one-time"),
one_time_date: z
.string()
.min(1, "One-time date is required for one-time schedules"),
});
// Recurring cron scheduled automation
const ScheduledCronSchema = AutomationBaseSchema.extend({
type: z.literal("scheduled"),
schedule_mode: z.literal("recurring"),
schedule_type: z.literal("cron"),
cron_expression: z
.string()
.min(1, "Cron expression is required for cron schedules"),
ends_type: z.enum(["never", "on", "after"]).optional().default("never"),
ends_on_date: z.string().nullable().optional(),
ends_after_count: z.number().int().positive().nullable().optional(),
});
// Recurring simple scheduled automation
const ScheduledSimpleSchema = AutomationBaseSchema.extend({
type: z.literal("scheduled"),
schedule_mode: z.literal("recurring"),
schedule_type: z.literal("simple"),
repeat_unit: z.enum(["minutes", "hours", "days", "weeks", "months"]),
repeat_interval: z.number().int().positive().optional(),
start_time: z.string().nullable().optional(),
repeat_on_days: z.array(z.number().int().min(0).max(6)).nullable().optional(),
repeat_on_day_of_month: z.number().int().min(1).max(31).nullable().optional(),
ends_type: z.enum(["never", "on", "after"]).optional().default("never"),
ends_on_date: z.string().nullable().optional(),
ends_after_count: z.number().int().positive().nullable().optional(),
});
// Entity event automation
const EntityAutomationSchema = AutomationBaseSchema.extend({
type: z.literal("entity"),
entity_name: z.string().min(1, "Entity name cannot be empty"),
event_types: z
.array(z.enum(["create", "update", "delete"]))
.min(1, "At least one event type is required"),
});
// Union of all automation types
const AutomationSchema = z.union([
ScheduledOneTimeSchema,
ScheduledCronSchema,
ScheduledSimpleSchema,
EntityAutomationSchema,
]);
export const FunctionConfigSchema = z.object({
name: FunctionNameSchema.optional(),
entry: z.string().min(1, "Entry point cannot be empty"),
automations: z.array(AutomationSchema).optional(),
});
const BackendFunctionSchema = FunctionConfigSchema.extend({
name: FunctionNameSchema,
entryPath: z.string().min(1, "Entry path cannot be empty"),
filePaths: z.array(z.string()).min(1, "Function must have at least one file"),
});
export const DeployFunctionsResponseSchema = z.object({
deployed: z.array(z.string()),
deleted: z.array(z.string()),
skipped: z.array(z.string()).optional().nullable(),
errors: z
.array(z.object({ name: z.string(), message: z.string() }))
.nullable(),
});
export type FunctionConfig = z.infer<typeof FunctionConfigSchema>;
export type BackendFunction = z.infer<typeof BackendFunctionSchema>;
export type FunctionFile = z.infer<typeof FunctionFileSchema>;
export type DeployFunctionsResponse = z.infer<
typeof DeployFunctionsResponseSchema
>;
export type FunctionWithCode = Omit<BackendFunction, "filePaths"> & {
files: FunctionFile[];
};
/**
* Log levels from Deno Deploy runtime.
*/
export const LogLevelSchema = z.enum(["info", "warning", "error", "debug"]);
export type LogLevel = z.infer<typeof LogLevelSchema>;
const FunctionLogEntrySchema = z.object({
time: z.string(),
level: LogLevelSchema,
message: z.string(),
});
export const FunctionLogsResponseSchema = z.array(FunctionLogEntrySchema);
export type FunctionLogsResponse = z.infer<typeof FunctionLogsResponseSchema>;
export interface FunctionLogFilters {
since?: string;
until?: string;
level?: LogLevel;
limit?: number;
order?: "asc" | "desc";
}