• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

satisfactory-dev / ajv-utilities / 24733993685

21 Apr 2026 04:27PM UTC coverage: 99.323% (-0.7%) from 100.0%
24733993685

push

github

SignpostMarv
updating readme

260 of 260 branches covered (100.0%)

Branch coverage included in aggregate %.

2089 of 2105 relevant lines covered (99.24%)

899.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.46
/src/TypeScriptify/TypeReferences.ts
1
import type {
3✔
2
        ImportSpecifier,
3✔
3
        TypeReferenceNode,
3✔
4
} from 'typescript';
3✔
5
import {
3✔
6
        createPrinter,
3✔
7
        createSourceFile,
3✔
8
        EmitHint,
3✔
9
        factory,
3✔
10
        ScriptTarget,
3✔
11
} from 'typescript';
3✔
12

3✔
13
import type {
3✔
14
        specify_types_config,
3✔
15
} from './types.ts';
3✔
16

3✔
17
export type prepend_with_imports = {
3✔
18
        [key: string]: Types,
3✔
19
        ajv: Types,
3✔
20
        '@satisfactory-dev/ajv-utilities': Types,
3✔
21
};
3✔
22

3✔
23
interface HasOutput {
3✔
24
        toImportSpecifier(): ImportSpecifier;
3✔
25

3✔
26
        toTypeReferenceNode(): TypeReferenceNode;
3✔
27

3✔
28
        toString(): string;
3✔
29
}
3✔
30

3✔
31
function to_string(instance: HasOutput) {
16✔
32
        const printer = createPrinter({
16✔
33
                omitTrailingSemicolon: true,
16✔
34
        });
16✔
35

16✔
36
        return printer.printNode(
16✔
37
                EmitHint.Unspecified,
16✔
38
                instance.toTypeReferenceNode(),
16✔
39
                createSourceFile('foo.ts', '', ScriptTarget.ESNext),
16✔
40
        );
16✔
41
}
16✔
42

3✔
43
abstract class Type {
3✔
44
        readonly name: Exclude<string, ''>;
3✔
45

424✔
46
        #id: Exclude<string, ''> | undefined;
3✔
47

3✔
48
        get id(): Exclude<string, ''> {
3✔
49
                if (!this.#id) {
1,414✔
50
                        this.#id = this.toId();
398✔
51
                }
398✔
52

1,414✔
53
                return this.#id;
1,414✔
54
        }
1,414✔
55

3✔
56
        constructor(name: Exclude<string, ''>) {
3✔
57
                this.name = name;
424✔
58
        }
424✔
59

3✔
60
        protected abstract toId(): string;
3✔
61

3✔
62
        abstract withArgs(args: [string, ...string[]]): WithArgs;
3✔
63
}
3✔
64

3✔
65
export class NameOnly extends Type implements HasOutput {
3✔
66
        protected toId(): string {
3✔
67
                return this.name;
406✔
68
        }
406✔
69

3✔
70
        toImportSpecifier(): ImportSpecifier {
3✔
71
                return factory.createImportSpecifier(
58✔
72
                        false,
58✔
73
                        undefined,
58✔
74
                        factory.createIdentifier(this.name),
58✔
75
                );
58✔
76
        }
58✔
77

3✔
78
        toTypeReferenceNode(): TypeReferenceNode {
3✔
79
                return factory.createTypeReferenceNode(this.name);
13✔
80
        }
13✔
81

3✔
82
        withArgs(args: [string, ...string[]]): WithArgs {
3✔
83
                return new WithArgs(this.name, args);
7✔
84
        }
7✔
85

3✔
86
        toString() {
3✔
87
                return to_string(this);
6✔
88
        }
6✔
89
}
3✔
90

3✔
91
export class Aliased extends Type {
3✔
92
        readonly as: Exclude<string, ''>;
3✔
93

3✔
94
        constructor(name: Aliased['name'], as: Aliased['as']) {
3✔
95
                super(name);
10✔
96

10✔
97
                this.as = as;
10✔
98
        }
10✔
99

3✔
100
        protected toId(): string {
3✔
101
                return `${this.name} as ${this.as}`;
8✔
102
        }
8✔
103

3✔
104
        toImportSpecifier(): ImportSpecifier {
3✔
105
                return factory.createImportSpecifier(
4✔
106
                        false,
4✔
107
                        factory.createIdentifier(this.name),
4✔
108
                        factory.createIdentifier(this.as),
4✔
109
                );
4✔
110
        }
4✔
111

3✔
112
        toTypeReferenceNode(): TypeReferenceNode {
3✔
113
                return factory.createTypeReferenceNode(this.as);
6✔
114
        }
6✔
115

3✔
116
        withArgs(args: [string, ...string[]]): WithArgs {
3✔
117
                return new WithArgs(this.name, args, this.as);
4✔
118
        }
4✔
119

3✔
120
        toString() {
3✔
121
                return to_string(this);
4✔
122
        }
4✔
123
}
3✔
124

3✔
125
class WithArgs implements HasOutput {
3✔
126
        readonly name: Exclude<string, ''>;
3✔
127

11✔
128
        readonly as: Exclude<string, ''> | undefined;
11✔
129

11✔
130
        readonly args: [string, ...string[]];
3✔
131

3✔
132
        constructor(
3✔
133
                name: WithArgs['name'],
11✔
134
                args: WithArgs['args'],
11✔
135
                as?: Exclude<WithArgs['as'], undefined>,
11✔
136
        ) {
11✔
137
                this.name = name;
11✔
138
                this.args = args;
11✔
139
                this.as = as;
11✔
140
        }
11✔
141

3✔
142
        protected toId(): string {
3✔
143
                return `${
×
144
                        this.as
×
145
                                ? `${this.name} as ${this.as}`
×
146
                                : this.name
×
147
                }`;
×
148
        }
×
149

3✔
150
        toImportSpecifier(): ImportSpecifier {
3✔
151
                return factory.createImportSpecifier(
×
152
                        false,
×
153
                        (
×
154
                                this.as
×
155
                                        ? factory.createIdentifier(this.name)
×
156
                                        : undefined
×
157
                        ),
×
158
                        factory.createIdentifier(this.as || this.name),
×
159
                );
×
160
        }
×
161

3✔
162
        toTypeReferenceNode(): TypeReferenceNode {
3✔
163
                return factory.createTypeReferenceNode(
11✔
164
                        this.as || this.name,
11✔
165
                        this.args.map((value) => factory.createLiteralTypeNode(
11✔
166
                                factory.createStringLiteral(value),
28✔
167
                        )),
11✔
168
                );
11✔
169
        }
11✔
170

3✔
171
        toString() {
3✔
172
                return to_string(this);
6✔
173
        }
6✔
174
}
3✔
175

3✔
176
export class Types {
3✔
177
        list_of_types: [
3✔
178
                (
62✔
179
                        | NameOnly
62✔
180
                        | Aliased
62✔
181
                ),
62✔
182
                ...(
62✔
183
                        | NameOnly
62✔
184
                        | Aliased
62✔
185
                )[],
62✔
186
        ] | undefined = undefined;
3✔
187

3✔
188
        get size() {
3✔
189
                return this.list_of_types ? this.list_of_types.length : 0;
53✔
190
        }
53✔
191

3✔
192
        #is_object_type(
3✔
193
                type: specify_types_config,
424✔
194
        ): type is Exclude<specify_types_config, string> {
424✔
195
                return 'string' !== typeof type;
424✔
196
        }
424✔
197

3✔
198
        add<T extends specify_types_config>(type: T) {
3✔
199
                const is_object = this.#is_object_type(type);
424✔
200

424✔
201
                let as_object = (
424✔
202
                        !is_object
424✔
203
                                ? new NameOnly(type)
424✔
204
                                : (
424✔
205
                                        'as' in type && type.as
17✔
206
                                                ? new Aliased(type.name, type.as)
17✔
207
                                                : new NameOnly(type.name)
17✔
208
                                )
17✔
209
                );
424✔
210

424✔
211
                if (undefined === this.list_of_types) {
424✔
212
                        this.list_of_types = [as_object];
45✔
213
                } else {
8✔
214
                        const maybe = this.list_of_types.find((
363✔
215
                                maybe,
690✔
216
                        ) => maybe.id === as_object.id);
363✔
217

363✔
218
                        if (!maybe) {
363✔
219
                                this.list_of_types.push(as_object);
363✔
220
                        } else {
363✔
221
                                as_object = maybe;
363✔
222
                        }
363✔
223
                }
363✔
224

424✔
225
                return is_object && 'args' in type
424✔
226
                        ? as_object.withArgs(type.args)
424✔
227
                        : as_object;
424✔
228
        }
424✔
229

3✔
230
        * [Symbol.iterator]() {
3✔
231
                if (!this.list_of_types) {
46✔
232
                        return;
46✔
233
                }
46✔
234

46✔
235
                for (const type of this.list_of_types) {
46✔
236
                        yield type;
62✔
237
                }
62✔
238
        }
46✔
239
}
3✔
240

3✔
241
export type {
3✔
242
        WithArgs,
3✔
243
};
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc