-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextend.valibot.ts
More file actions
53 lines (46 loc) · 1.69 KB
/
extend.valibot.ts
File metadata and controls
53 lines (46 loc) · 1.69 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
import { pipe } from 'valibot'
import { minValue } from 'valibot'
import { email } from 'valibot'
import { union } from 'valibot'
import { minLength } from 'valibot'
import { InferOutput } from 'valibot'
import { array, boolean, literal, number, object, string, uuid } from 'valibot'
const Extend_BaseSchema = object({
id: pipe(string(), uuid()),
name: pipe(string(), minLength(1)),
age: pipe(number(), minValue(1)),
level: union([literal('beginner'), literal('intermediate'), literal('advanced')]),
})
const Extend_AdminSchema = object({
...Extend_BaseSchema.entries,
email: pipe(string(), email()),
department: pipe(string(), minLength(1)),
position: pipe(string(), minLength(1)),
role: literal('admin'),
})
const Extend_StrictAdminSchema = object({
...Extend_AdminSchema.entries,
permissions: array(pipe(string(), minLength(1))),
role: literal('superadmin'),
})
const Extend_UserSchema = object({
...Extend_BaseSchema.entries,
email: pipe(string(), email()),
isActive: boolean(),
role: literal('user'),
})
const Extend_StrictUserSchema = object({
...Extend_UserSchema.entries,
permissions: array(pipe(string(), minLength(1))),
role: literal('superuser'),
})
const Extend_GuestSchema = object({
...Extend_BaseSchema.entries,
isActive: boolean(),
role: literal('guest'),
})
export type Extend_AdminModelInput = InferOutput<typeof Extend_AdminSchema>
export type Extend_StrictAdminModelInput = InferOutput<typeof Extend_StrictAdminSchema>
export type Extend_UserModelInput = InferOutput<typeof Extend_UserSchema>
export type Extend_StrictUserModelInput = InferOutput<typeof Extend_StrictUserSchema>
export type Extend_GuestModelInput = InferOutput<typeof Extend_GuestSchema>