1
- import type { Static } from "./deps/typebox.ts" ;
2
- import { FlexObject , NonEmptyString , PosInt , Type } from "./deps/typebox.ts" ;
1
+ import { Arr , Bool , Enum , Lit , NonEmpStr , Obj , Opt , PartObj , PosInt , Rec , Str , Uni } from "@wok/schema/schema" ;
3
2
4
- export const Cidr = NonEmptyString ( {
3
+ export const Cidr = NonEmpStr ( {
5
4
pattern : "^([0-9]{1,3}\.){3}[0-9]{1,3}(\/([0-9]|[1-2][0-9]|3[0-2]))$" ,
6
5
} ) ;
7
- export const Ipv4 = NonEmptyString ( {
6
+ export const Ipv4 = NonEmpStr ( {
8
7
format : "ipv4" ,
9
8
} ) ;
10
- export const Url = NonEmptyString ( { format : "url" } ) ;
9
+ export const Url = NonEmpStr ( { format : "url" } ) ;
11
10
12
- export const ServerInstanceConfigSchema = Type . Object ( {
13
- role : Type . Literal ( "server" ) ,
14
- name : NonEmptyString ( ) ,
15
- contextName : Type . Optional ( NonEmptyString ( ) ) ,
16
- image : Type . Optional ( NonEmptyString ( ) ) ,
11
+ export const ServerInstanceConfigSchema = Obj ( {
12
+ role : Lit ( "server" ) ,
13
+ name : NonEmpStr ( ) ,
14
+ contextName : Opt ( NonEmpStr ( ) ) ,
15
+ image : Opt ( NonEmpStr ( ) ) ,
17
16
cpus : PosInt ( ) ,
18
17
memoryGiBs : PosInt ( ) ,
19
18
diskGiBs : PosInt ( ) ,
20
- bridged : Type . Optional ( Type . Boolean ( ) ) ,
21
- k3sVersion : NonEmptyString ( ) ,
22
- externalNetworkCidr : Type . Optional ( Cidr ) ,
23
- datastoreEndpoint : Type . Optional ( NonEmptyString ( ) ) ,
19
+ bridged : Opt ( Bool ( ) ) ,
20
+ k3sVersion : NonEmpStr ( ) ,
21
+ externalNetworkCidr : Opt ( Cidr ) ,
22
+ datastoreEndpoint : Opt ( NonEmpStr ( ) ) ,
24
23
clusterCidr : Cidr ,
25
24
serviceCidr : Cidr ,
26
25
clusterDnsIp : Ipv4 ,
27
- clusterDomain : NonEmptyString ( { format : "hostname" } ) ,
28
- kubelet : Type . Optional ( Type . Object ( {
29
- maxPods : Type . Optional ( PosInt ( ) ) ,
26
+ clusterDomain : NonEmpStr ( { format : "hostname" } ) ,
27
+ kubelet : Opt ( Obj ( {
28
+ maxPods : Opt ( PosInt ( ) ) ,
30
29
} ) ) ,
31
- disableComponents : Type . Optional ( Type . Object ( {
32
- coredns : Type . Optional ( Type . Boolean ( ) ) ,
33
- servicelb : Type . Optional ( Type . Boolean ( ) ) ,
34
- traefik : Type . Optional ( Type . Boolean ( ) ) ,
35
- localStorage : Type . Optional ( Type . Boolean ( ) ) ,
36
- metricsServer : Type . Optional ( Type . Boolean ( ) ) ,
30
+ disableComponents : Opt ( Obj ( {
31
+ coredns : Opt ( Bool ( ) ) ,
32
+ servicelb : Opt ( Bool ( ) ) ,
33
+ traefik : Opt ( Bool ( ) ) ,
34
+ localStorage : Opt ( Bool ( ) ) ,
35
+ metricsServer : Opt ( Bool ( ) ) ,
37
36
} ) ) ,
38
- nodeLabels : Type . Optional ( Type . Record ( NonEmptyString ( ) , NonEmptyString ( ) ) ) ,
39
- nodeTaints : Type . Optional ( Type . Record ( NonEmptyString ( ) , NonEmptyString ( ) ) ) ,
40
- sshDirectoryPath : NonEmptyString ( ) ,
41
- joinMetadataPath : NonEmptyString ( ) ,
42
- userName : Type . Optional ( NonEmptyString ( ) ) ,
43
- userPassword : Type . Optional ( NonEmptyString ( ) ) ,
44
- clusterInit : Type . Optional ( Type . Boolean ( ) ) ,
45
- keepalived : Type . Optional ( Type . Object ( {
46
- state : Type . Union ( [ Type . Literal ( "MASTER" ) , Type . Literal ( "BACKUP" ) ] ) ,
37
+ nodeLabels : Opt ( Rec ( NonEmpStr ( ) , NonEmpStr ( ) ) ) ,
38
+ nodeTaints : Opt ( Rec ( NonEmpStr ( ) , NonEmpStr ( ) ) ) ,
39
+ sshDirectoryPath : NonEmpStr ( ) ,
40
+ joinMetadataPath : NonEmpStr ( ) ,
41
+ userName : Opt ( NonEmpStr ( ) ) ,
42
+ userPassword : Opt ( NonEmpStr ( ) ) ,
43
+ clusterInit : Opt ( Bool ( ) ) ,
44
+ keepalived : Opt ( Obj ( {
45
+ state : Uni ( [ Lit ( "MASTER" ) , Lit ( "BACKUP" ) ] ) ,
47
46
virtualRouterId : PosInt ( ) ,
48
47
virtualIp : Ipv4 ,
49
48
priority : PosInt ( ) ,
50
- password : NonEmptyString ( ) ,
49
+ password : NonEmpStr ( ) ,
51
50
} ) ) ,
52
51
} ) ;
53
52
54
- export const AgentInstanceConfigSchema = Type . Object ( {
55
- role : Type . Literal ( "agent" ) ,
56
- name : NonEmptyString ( ) ,
57
- image : Type . Optional ( NonEmptyString ( ) ) ,
53
+ export const AgentInstanceConfigSchema = Obj ( {
54
+ role : Lit ( "agent" ) ,
55
+ name : NonEmpStr ( ) ,
56
+ image : Opt ( NonEmpStr ( ) ) ,
58
57
cpus : PosInt ( ) ,
59
58
memoryGiBs : PosInt ( ) ,
60
59
diskGiBs : PosInt ( ) ,
61
- bridged : Type . Optional ( Type . Boolean ( ) ) ,
62
- clusterDomain : NonEmptyString ( { format : "hostname" } ) ,
63
- kubelet : Type . Optional ( Type . Object ( {
60
+ bridged : Opt ( Bool ( ) ) ,
61
+ clusterDomain : NonEmpStr ( { format : "hostname" } ) ,
62
+ kubelet : Opt ( Obj ( {
64
63
maxPods : PosInt ( ) ,
65
64
} ) ) ,
66
- externalNetworkCidr : Type . Optional ( Cidr ) ,
67
- k3sVersion : NonEmptyString ( ) ,
68
- nodeLabels : Type . Optional ( Type . Record ( NonEmptyString ( ) , NonEmptyString ( ) ) ) ,
69
- nodeTaints : Type . Optional ( Type . Record ( NonEmptyString ( ) , NonEmptyString ( ) ) ) ,
70
- sshDirectoryPath : NonEmptyString ( ) ,
71
- joinMetadataPath : NonEmptyString ( ) ,
72
- userName : Type . Optional ( NonEmptyString ( ) ) ,
73
- userPassword : Type . Optional ( NonEmptyString ( ) ) ,
65
+ externalNetworkCidr : Opt ( Cidr ) ,
66
+ k3sVersion : NonEmpStr ( ) ,
67
+ nodeLabels : Opt ( Rec ( NonEmpStr ( ) , NonEmpStr ( ) ) ) ,
68
+ nodeTaints : Opt ( Rec ( NonEmpStr ( ) , NonEmpStr ( ) ) ) ,
69
+ sshDirectoryPath : NonEmpStr ( ) ,
70
+ joinMetadataPath : NonEmpStr ( ) ,
71
+ userName : Opt ( NonEmpStr ( ) ) ,
72
+ userPassword : Opt ( NonEmpStr ( ) ) ,
74
73
} ) ;
75
74
76
- export const ClusterInstanceConfigSchema = Type . Object ( {
77
- servers : Type . Array ( ServerInstanceConfigSchema ) ,
78
- agents : Type . Array ( AgentInstanceConfigSchema ) ,
75
+ export const ClusterInstanceConfigSchema = Obj ( {
76
+ servers : Arr ( ServerInstanceConfigSchema ) ,
77
+ agents : Arr ( AgentInstanceConfigSchema ) ,
79
78
} ) ;
80
79
81
- export const InstanceConfigSchema = Type . Union ( [
80
+ export const InstanceConfigSchema = Uni ( [
82
81
ServerInstanceConfigSchema ,
83
82
AgentInstanceConfigSchema ,
84
83
] ) ;
85
84
86
- export const JoinMetadataSchema = Type . Object ( {
87
- url : NonEmptyString ( { format : "uri" } ) ,
88
- token : NonEmptyString ( ) ,
85
+ export const JoinMetadataSchema = Obj ( {
86
+ url : NonEmpStr ( { format : "uri" } ) ,
87
+ token : NonEmpStr ( ) ,
89
88
} ) ;
90
89
91
- export type JoinMetadata = Static < typeof JoinMetadataSchema > ;
90
+ export type JoinMetadata = typeof JoinMetadataSchema . infer ;
92
91
93
92
export enum InstanceState {
94
93
Starting = "Starting" ,
@@ -98,21 +97,21 @@ export enum InstanceState {
98
97
Unknown = "Unknown" ,
99
98
}
100
99
101
- export const MultipassInfo = FlexObject ( {
102
- info : Type . Record (
103
- NonEmptyString ( ) ,
104
- FlexObject ( {
105
- ipv4 : Type . Array ( Ipv4 ) ,
106
- state : Type . Enum ( InstanceState ) ,
100
+ export const MultipassInfo = PartObj ( {
101
+ info : Rec (
102
+ NonEmpStr ( ) ,
103
+ PartObj ( {
104
+ ipv4 : Arr ( Ipv4 ) ,
105
+ state : Enum ( Object . values ( InstanceState ) ) ,
107
106
} ) ,
108
107
) ,
109
108
} ) ;
110
109
111
- export type ServerInstanceConfig = Static < typeof ServerInstanceConfigSchema > ;
112
- export type AgentInstanceConfig = Static < typeof AgentInstanceConfigSchema > ;
113
- export type InstanceConfig = Static < typeof InstanceConfigSchema > ;
110
+ export type ServerInstanceConfig = typeof ServerInstanceConfigSchema . infer ;
111
+ export type AgentInstanceConfig = typeof AgentInstanceConfigSchema . infer ;
112
+ export type InstanceConfig = typeof InstanceConfigSchema . infer ;
114
113
115
- export const InstanceConfigPathSchema = Type . String ( {
114
+ export const InstanceConfigPathSchema = Str ( {
116
115
minLength : 1 ,
117
116
description : "Path to the instance config file. It should be an ES module with a default export." ,
118
117
} ) ;
0 commit comments