-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy pathformatter.ts
More file actions
85 lines (72 loc) · 5.08 KB
/
formatter.ts
File metadata and controls
85 lines (72 loc) · 5.08 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
import { ChainTypeFormatter } from "../src/ChainTypeFormatter.js";
import { CircularReferenceTypeFormatter } from "../src/CircularReferenceTypeFormatter.js";
import { CompletedConfig } from "../src/Config.js";
import { MutableTypeFormatter } from "../src/MutableTypeFormatter.js";
import { TypeFormatter } from "../src/TypeFormatter.js";
import { AliasTypeFormatter } from "../src/TypeFormatter/AliasTypeFormatter.js";
import { AnnotatedTypeFormatter } from "../src/TypeFormatter/AnnotatedTypeFormatter.js";
import { AnyTypeFormatter } from "../src/TypeFormatter/AnyTypeFormatter.js";
import { ArrayTypeFormatter } from "../src/TypeFormatter/ArrayTypeFormatter.js";
import { BooleanTypeFormatter } from "../src/TypeFormatter/BooleanTypeFormatter.js";
import { ConstructorTypeFormatter } from "../src/TypeFormatter/ConstructorTypeFormatter.js";
import { DefinitionTypeFormatter } from "../src/TypeFormatter/DefinitionTypeFormatter.js";
import { EnumTypeFormatter } from "../src/TypeFormatter/EnumTypeFormatter.js";
import { FunctionTypeFormatter } from "../src/TypeFormatter/FunctionTypeFormatter.js";
import { IntersectionTypeFormatter } from "../src/TypeFormatter/IntersectionTypeFormatter.js";
import { LiteralTypeFormatter } from "../src/TypeFormatter/LiteralTypeFormatter.js";
import { LiteralUnionTypeFormatter } from "../src/TypeFormatter/LiteralUnionTypeFormatter.js";
import { NeverTypeFormatter } from "../src/TypeFormatter/NeverTypeFormatter.js";
import { NullTypeFormatter } from "../src/TypeFormatter/NullTypeFormatter.js";
import { NumberTypeFormatter } from "../src/TypeFormatter/NumberTypeFormatter.js";
import { ObjectTypeFormatter } from "../src/TypeFormatter/ObjectTypeFormatter.js";
import { OptionalTypeFormatter } from "../src/TypeFormatter/OptionalTypeFormatter.js";
import { PrimitiveUnionTypeFormatter } from "../src/TypeFormatter/PrimitiveUnionTypeFormatter.js";
import { ReferenceTypeFormatter } from "../src/TypeFormatter/ReferenceTypeFormatter.js";
import { RestTypeFormatter } from "../src/TypeFormatter/RestTypeFormatter.js";
import { StringTypeFormatter } from "../src/TypeFormatter/StringTypeFormatter.js";
import { SymbolTypeFormatter } from "../src/TypeFormatter/SymbolTypeFormatter.js";
import { TupleTypeFormatter } from "../src/TypeFormatter/TupleTypeFormatter.js";
import { UndefinedTypeFormatter } from "../src/TypeFormatter/UndefinedTypeFormatter.js";
import { UnionTypeFormatter } from "../src/TypeFormatter/UnionTypeFormatter.js";
import { UnknownTypeFormatter } from "../src/TypeFormatter/UnknownTypeFormatter.js";
import { VoidTypeFormatter } from "../src/TypeFormatter/VoidTypeFormatter.js";
export type FormatterAugmentor = (
formatter: MutableTypeFormatter,
circularReferenceTypeFormatter: CircularReferenceTypeFormatter,
) => void;
export function createFormatter(config: CompletedConfig, augmentor?: FormatterAugmentor): TypeFormatter {
const chainTypeFormatter = new ChainTypeFormatter([]);
const circularReferenceTypeFormatter = new CircularReferenceTypeFormatter(chainTypeFormatter);
if (augmentor) {
augmentor(chainTypeFormatter, circularReferenceTypeFormatter);
}
chainTypeFormatter
.addTypeFormatter(new AnnotatedTypeFormatter(circularReferenceTypeFormatter))
.addTypeFormatter(new StringTypeFormatter())
.addTypeFormatter(new NumberTypeFormatter())
.addTypeFormatter(new BooleanTypeFormatter())
.addTypeFormatter(new NullTypeFormatter())
.addTypeFormatter(new SymbolTypeFormatter())
.addTypeFormatter(new AnyTypeFormatter())
.addTypeFormatter(new UndefinedTypeFormatter())
.addTypeFormatter(new UnknownTypeFormatter())
.addTypeFormatter(new VoidTypeFormatter())
.addTypeFormatter(new NeverTypeFormatter())
.addTypeFormatter(new LiteralTypeFormatter())
.addTypeFormatter(new EnumTypeFormatter())
.addTypeFormatter(new ReferenceTypeFormatter(circularReferenceTypeFormatter, config.encodeRefs ?? true))
.addTypeFormatter(new DefinitionTypeFormatter(circularReferenceTypeFormatter, config.encodeRefs ?? true))
.addTypeFormatter(new ObjectTypeFormatter(circularReferenceTypeFormatter))
.addTypeFormatter(new AliasTypeFormatter(circularReferenceTypeFormatter))
.addTypeFormatter(new PrimitiveUnionTypeFormatter())
.addTypeFormatter(new LiteralUnionTypeFormatter())
.addTypeFormatter(new ConstructorTypeFormatter(circularReferenceTypeFormatter, config.functions))
.addTypeFormatter(new FunctionTypeFormatter(circularReferenceTypeFormatter, config.functions))
.addTypeFormatter(new OptionalTypeFormatter(circularReferenceTypeFormatter))
.addTypeFormatter(new RestTypeFormatter(circularReferenceTypeFormatter))
.addTypeFormatter(new ArrayTypeFormatter(circularReferenceTypeFormatter))
.addTypeFormatter(new TupleTypeFormatter(circularReferenceTypeFormatter))
.addTypeFormatter(new UnionTypeFormatter(circularReferenceTypeFormatter, config.discriminatorType))
.addTypeFormatter(new IntersectionTypeFormatter(circularReferenceTypeFormatter));
return circularReferenceTypeFormatter;
}