-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdefault.ts
43 lines (37 loc) · 934 Bytes
/
default.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
import * as zod from "zod";
import {ZodAccelerator} from "../accelerator";
import {ZodAcceleratorContent} from "../content";
@ZodAccelerator.autoInstance
export class ZodDefaultAccelerator extends ZodAccelerator{
public get support(){
return ZodAccelerator.zod.ZodDefault;
}
public makeAcceleratorContent(zodSchema: zod.ZodDefault<zod.ZodAny>, zac: ZodAcceleratorContent){
const def = zodSchema._def;
const zacInnerType = ZodAccelerator.findAcceleratorContent(def.innerType);
zac.addContext({
defaultValue: def.defaultValue
});
zac.addContent(
ZodDefaultAccelerator.contentPart.default(),
"else {",
[
zacInnerType,
{
path: null,
input: "$input",
output: "$input",
}
],
"}"
);
return zac;
}
static contentPart = {
default: () => /* js */`
if($input === undefined){
$input = $this.defaultValue()
}
`
};
}