/
1.ts
44 lines (40 loc) · 911 Bytes
/
1.ts
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
import { z } from "zod"
import { defineVersion } from "verzod"
import { V0_SCHEMA } from "./0"
export const uniqueID = () => Math.random().toString(36).substring(2, 16)
export const V1_SCHEMA = z.object({
v: z.literal(1),
id: z.string(),
name: z.string(),
variables: z.array(
z.union([
z.object({
key: z.string(),
secret: z.literal(true),
}),
z.object({
key: z.string(),
value: z.string(),
secret: z.literal(false).catch(false),
}),
])
),
})
export default defineVersion({
initial: false,
schema: V1_SCHEMA,
up(old: z.infer<typeof V0_SCHEMA>) {
const result: z.infer<typeof V1_SCHEMA> = {
...old,
v: 1,
id: old.id || uniqueID(),
variables: old.variables.map((variable) => {
return {
...variable,
secret: false,
}
}),
}
return result
},
})