typia 5.1.0-dev.20230924 → 5.1.0-dev.20230926
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/functional/$HeadersReader.d.ts +3 -3
- package/lib/functional/$HeadersReader.js +21 -3
- package/lib/functional/$HeadersReader.js.map +1 -1
- package/lib/functional/$ParameterReader.d.ts +6 -0
- package/lib/functional/$ParameterReader.js +35 -0
- package/lib/functional/$ParameterReader.js.map +1 -0
- package/lib/functional/$QueryReader.js +22 -2
- package/lib/functional/$QueryReader.js.map +1 -1
- package/lib/functional/Namespace.js +2 -0
- package/lib/functional/Namespace.js.map +1 -1
- package/lib/http.d.ts +2 -2
- package/lib/http.js +2 -0
- package/lib/http.js.map +1 -1
- package/lib/programmers/http/HttpHeadersProgrammer.js +36 -50
- package/lib/programmers/http/HttpHeadersProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpParameterProgrammer.js +10 -29
- package/lib/programmers/http/HttpParameterProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpQueryProgrammer.js +16 -12
- package/lib/programmers/http/HttpQueryProgrammer.js.map +1 -1
- package/package.json +1 -1
- package/src/factories/MetadataCollection.ts +274 -274
- package/src/functional/$HeadersReader.ts +28 -9
- package/src/functional/$ParameterReader.ts +31 -0
- package/src/functional/$QueryReader.ts +53 -32
- package/src/functional/Namespace.ts +2 -0
- package/src/http.ts +1149 -1141
- package/src/programmers/helpers/HttpMetadataUtil.ts +21 -21
- package/src/programmers/http/HttpAssertHeadersProgrammer.ts +77 -77
- package/src/programmers/http/HttpAssertQueryProgrammer.ts +77 -77
- package/src/programmers/http/HttpHeadersProgrammer.ts +320 -321
- package/src/programmers/http/HttpIsHeadersProgrammer.ts +87 -87
- package/src/programmers/http/HttpIsQueryProgrammer.ts +87 -87
- package/src/programmers/http/HttpParameterProgrammer.ts +104 -168
- package/src/programmers/http/HttpQueryProgrammer.ts +286 -267
- package/src/programmers/http/HttpValidateHeadersProgrammer.ts +77 -77
- package/src/programmers/http/HttpValidateQueryProgrammer.ts +77 -77
- package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +0 -1
- package/src/transformers/features/http/CreateHttpAssertHeadersTransformer.ts +12 -12
- package/src/transformers/features/http/CreateHttpAssertQueryTransformer.ts +12 -12
- package/src/transformers/features/http/CreateHttpHeadersTransformer.ts +9 -9
- package/src/transformers/features/http/CreateHttpIsHeadersTransformer.ts +9 -9
- package/src/transformers/features/http/CreateHttpIsQueryTransformer.ts +9 -9
- package/src/transformers/features/http/CreateHttpParameterTransformer.ts +9 -9
- package/src/transformers/features/http/CreateHttpQueryTransformer.ts +9 -9
- package/src/transformers/features/http/CreateHttpValidateHeadersTransformer copy.ts +12 -12
- package/src/transformers/features/http/CreateHttpValidateQueryTransformer.ts +12 -12
- package/src/transformers/features/http/HttpAssertHeadersTransformer.ts +10 -10
- package/src/transformers/features/http/HttpAssertQueryTransformer.ts +10 -10
- package/src/transformers/features/http/HttpHeadersTransformer.ts +9 -9
- package/src/transformers/features/http/HttpIsHeadersTransformer.ts +9 -9
- package/src/transformers/features/http/HttpIsQueryTransformer.ts +9 -9
- package/src/transformers/features/http/HttpParameterTransformer.ts +9 -9
- package/src/transformers/features/http/HttpQueryTransformer.ts +9 -9
- package/src/transformers/features/http/HttpValidateHeadersTransformer.ts +10 -10
- package/src/transformers/features/http/HttpValidateQueryTransformer.ts +10 -10
|
@@ -1,274 +1,274 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IMetadataCollection } from "../schemas/metadata/IMetadataCollection";
|
|
4
|
-
import { Metadata } from "../schemas/metadata/Metadata";
|
|
5
|
-
import { MetadataAlias } from "../schemas/metadata/MetadataAlias";
|
|
6
|
-
import { MetadataArrayType } from "../schemas/metadata/MetadataArrayType";
|
|
7
|
-
import { MetadataObject } from "../schemas/metadata/MetadataObject";
|
|
8
|
-
import { MetadataTupleType } from "../schemas/metadata/MetadataTupleType";
|
|
9
|
-
|
|
10
|
-
import { Writable } from "../typings/Writable";
|
|
11
|
-
|
|
12
|
-
import { MapUtil } from "../utils/MapUtil";
|
|
13
|
-
|
|
14
|
-
import { CommentFactory } from "./CommentFactory";
|
|
15
|
-
import { TypeFactory } from "./TypeFactory";
|
|
16
|
-
|
|
17
|
-
export class MetadataCollection {
|
|
18
|
-
private readonly objects_: Map<ts.Type, MetadataObject>;
|
|
19
|
-
private readonly object_unions_: Map<string, MetadataObject[]>;
|
|
20
|
-
private readonly aliases_: Map<ts.Type, MetadataAlias>;
|
|
21
|
-
private readonly arrays_: Map<ts.Type, MetadataArrayType>;
|
|
22
|
-
private readonly tuples_: Map<ts.Type, MetadataTupleType>;
|
|
23
|
-
|
|
24
|
-
private readonly names_: Map<string, Map<ts.Type, string>>;
|
|
25
|
-
private object_index_: number;
|
|
26
|
-
private recursive_array_index_: number;
|
|
27
|
-
private recursive_tuple_index_: number;
|
|
28
|
-
|
|
29
|
-
public constructor(
|
|
30
|
-
private readonly options?: Partial<MetadataCollection.IOptions>,
|
|
31
|
-
) {
|
|
32
|
-
this.objects_ = new Map();
|
|
33
|
-
this.object_unions_ = new Map();
|
|
34
|
-
this.aliases_ = new Map();
|
|
35
|
-
this.arrays_ = new Map();
|
|
36
|
-
this.tuples_ = new Map();
|
|
37
|
-
|
|
38
|
-
this.names_ = new Map();
|
|
39
|
-
this.object_index_ = 0;
|
|
40
|
-
this.recursive_array_index_ = 0;
|
|
41
|
-
this.recursive_tuple_index_ = 0;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/* -----------------------------------------------------------
|
|
45
|
-
ACCESSORS
|
|
46
|
-
----------------------------------------------------------- */
|
|
47
|
-
public aliases(): MetadataAlias[] {
|
|
48
|
-
return [...this.aliases_.values()];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
public objects(): MetadataObject[] {
|
|
52
|
-
return [...this.objects_.values()];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
public unions(): MetadataObject[][] {
|
|
56
|
-
return [...this.object_unions_.values()];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
public arrays(): MetadataArrayType[] {
|
|
60
|
-
return [...this.arrays_.values()];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
public tuples(): MetadataTupleType[] {
|
|
64
|
-
return [...this.tuples_.values()];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
private getName(checker: ts.TypeChecker, type: ts.Type): string {
|
|
68
|
-
const name: string = (() => {
|
|
69
|
-
const str: string = TypeFactory.getFullName(checker)(type);
|
|
70
|
-
return this.options?.replace ? this.options.replace(str) : str;
|
|
71
|
-
})();
|
|
72
|
-
|
|
73
|
-
const duplicates: Map<ts.Type, string> = MapUtil.take(this.names_)(
|
|
74
|
-
name,
|
|
75
|
-
() => new Map(),
|
|
76
|
-
);
|
|
77
|
-
const oldbie: string | undefined = duplicates.get(type);
|
|
78
|
-
if (oldbie !== undefined) return oldbie;
|
|
79
|
-
|
|
80
|
-
const addicted: string = duplicates.size
|
|
81
|
-
? `${name}.o${duplicates.size}`
|
|
82
|
-
: name;
|
|
83
|
-
duplicates.set(type, addicted);
|
|
84
|
-
return addicted;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* @internal
|
|
89
|
-
*/
|
|
90
|
-
public getUnionIndex(meta: Metadata): number {
|
|
91
|
-
const key: string = meta.objects.map((obj) => obj.name).join(" | ");
|
|
92
|
-
MapUtil.take(this.object_unions_)(key, () => meta.objects);
|
|
93
|
-
return [...this.object_unions_.keys()].indexOf(key);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/* -----------------------------------------------------------
|
|
97
|
-
INSTANCES
|
|
98
|
-
----------------------------------------------------------- */
|
|
99
|
-
public emplace(
|
|
100
|
-
checker: ts.TypeChecker,
|
|
101
|
-
type: ts.Type,
|
|
102
|
-
): [MetadataObject, boolean] {
|
|
103
|
-
const oldbie = this.objects_.get(type);
|
|
104
|
-
if (oldbie !== undefined) return [oldbie, false];
|
|
105
|
-
|
|
106
|
-
// const displays = type.symbol.getDocumentationComment(checker);
|
|
107
|
-
// const tags = type.symbol.getJsDocTags(checker);
|
|
108
|
-
|
|
109
|
-
// console.log(
|
|
110
|
-
// ts.displayPartsToString(displays),
|
|
111
|
-
// tags.map((tag) => tag.name),
|
|
112
|
-
// tags.map((tag) => ts.displayPartsToString(tag.text)),
|
|
113
|
-
// );
|
|
114
|
-
|
|
115
|
-
const $id: string = this.getName(checker, type);
|
|
116
|
-
const obj: MetadataObject = MetadataObject.create({
|
|
117
|
-
name: $id,
|
|
118
|
-
properties: [],
|
|
119
|
-
description:
|
|
120
|
-
(type.symbol && CommentFactory.description(type.symbol)) ??
|
|
121
|
-
undefined,
|
|
122
|
-
jsDocTags: type.symbol?.getJsDocTags() ?? [],
|
|
123
|
-
validated: false,
|
|
124
|
-
index: this.object_index_++,
|
|
125
|
-
recursive: null!,
|
|
126
|
-
nullables: [],
|
|
127
|
-
});
|
|
128
|
-
this.objects_.set(type, obj);
|
|
129
|
-
return [obj, true];
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
public emplaceAlias(
|
|
133
|
-
checker: ts.TypeChecker,
|
|
134
|
-
type: ts.Type,
|
|
135
|
-
symbol: ts.Symbol,
|
|
136
|
-
): [MetadataAlias, boolean, (meta: Metadata) => void] {
|
|
137
|
-
const oldbie = this.aliases_.get(type);
|
|
138
|
-
if (oldbie !== undefined) return [oldbie, false, () => {}];
|
|
139
|
-
|
|
140
|
-
const $id: string = this.getName(checker, type);
|
|
141
|
-
const alias: MetadataAlias = MetadataAlias.create({
|
|
142
|
-
name: $id,
|
|
143
|
-
value: null!,
|
|
144
|
-
description: CommentFactory.description(symbol) ?? null,
|
|
145
|
-
recursive: null!,
|
|
146
|
-
nullables: [],
|
|
147
|
-
jsDocTags: symbol.getJsDocTags() ?? [],
|
|
148
|
-
});
|
|
149
|
-
this.aliases_.set(type, alias);
|
|
150
|
-
return [alias, true, (meta) => (Writable(alias).value = meta)];
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
public emplaceArray(
|
|
154
|
-
checker: ts.TypeChecker,
|
|
155
|
-
type: ts.Type,
|
|
156
|
-
): [MetadataArrayType, boolean, (meta: Metadata) => void] {
|
|
157
|
-
const oldbie = this.arrays_.get(type);
|
|
158
|
-
if (oldbie !== undefined) return [oldbie, false, () => {}];
|
|
159
|
-
|
|
160
|
-
const $id = this.getName(checker, type);
|
|
161
|
-
const array: MetadataArrayType = MetadataArrayType.create({
|
|
162
|
-
name: $id,
|
|
163
|
-
value: null!,
|
|
164
|
-
index: null,
|
|
165
|
-
recursive: null!,
|
|
166
|
-
nullables: [],
|
|
167
|
-
});
|
|
168
|
-
this.arrays_.set(type, array);
|
|
169
|
-
return [array, true, (meta) => (Writable(array).value = meta)];
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
public emplaceTuple(
|
|
173
|
-
checker: ts.TypeChecker,
|
|
174
|
-
type: ts.TupleType,
|
|
175
|
-
): [MetadataTupleType, boolean, (elements: Metadata[]) => void] {
|
|
176
|
-
const oldbie = this.tuples_.get(type);
|
|
177
|
-
if (oldbie !== undefined) return [oldbie, false, () => {}];
|
|
178
|
-
|
|
179
|
-
const $id = this.getName(checker, type);
|
|
180
|
-
const tuple: MetadataTupleType = MetadataTupleType.create({
|
|
181
|
-
name: $id,
|
|
182
|
-
elements: null!,
|
|
183
|
-
index: null,
|
|
184
|
-
recursive: null!,
|
|
185
|
-
nullables: [],
|
|
186
|
-
});
|
|
187
|
-
this.tuples_.set(type, tuple);
|
|
188
|
-
return [
|
|
189
|
-
tuple,
|
|
190
|
-
true,
|
|
191
|
-
(elements) => (Writable(tuple).elements = elements),
|
|
192
|
-
];
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* @internal
|
|
197
|
-
*/
|
|
198
|
-
public setObjectRecursive(obj: MetadataObject, recursive: boolean): void {
|
|
199
|
-
Writable(obj).recursive = recursive;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* @internal
|
|
204
|
-
*/
|
|
205
|
-
public setAliasRecursive(alias: MetadataAlias, recursive: boolean): void {
|
|
206
|
-
Writable(alias).recursive = recursive;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* @internal
|
|
211
|
-
*/
|
|
212
|
-
public setArrayRecursive(
|
|
213
|
-
array: MetadataArrayType,
|
|
214
|
-
recursive: boolean,
|
|
215
|
-
): void {
|
|
216
|
-
Writable(array).recursive = recursive;
|
|
217
|
-
if (recursive) Writable(array).index = this.recursive_array_index_++;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
public setTupleRecursive(
|
|
221
|
-
tuple: MetadataTupleType,
|
|
222
|
-
recursive: boolean,
|
|
223
|
-
): void {
|
|
224
|
-
Writable(tuple).recursive = recursive;
|
|
225
|
-
if (recursive) Writable(tuple).index = this.recursive_tuple_index_++;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
public toJSON(): IMetadataCollection {
|
|
229
|
-
return {
|
|
230
|
-
objects: this.objects().map((o) => o.toJSON()),
|
|
231
|
-
aliases: this.aliases().map((d) => d.toJSON()),
|
|
232
|
-
arrays: [...this.arrays_.values()].map((a) => a.toJSON()),
|
|
233
|
-
tuples: [...this.tuples_.values()].map((t) => t.toJSON()),
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
export namespace MetadataCollection {
|
|
238
|
-
export interface IOptions {
|
|
239
|
-
replace?(str: string): string;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
export const replace = (str: string): string => {
|
|
243
|
-
let replaced: string = str;
|
|
244
|
-
for (const [before] of REPLACERS)
|
|
245
|
-
replaced = replaced.split(before).join("");
|
|
246
|
-
if (replaced.length !== 0) return replaced;
|
|
247
|
-
|
|
248
|
-
for (const [before, after] of REPLACERS)
|
|
249
|
-
str = str.split(before).join(after);
|
|
250
|
-
return str;
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
export const escape = (str: string): string => {
|
|
254
|
-
for (const [before, after] of REPLACERS)
|
|
255
|
-
if (after !== "") str = str.split(after).join(before);
|
|
256
|
-
return str;
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
const REPLACERS: [string, string][] = [
|
|
260
|
-
["$", "_dollar_"],
|
|
261
|
-
["&", "_and_"],
|
|
262
|
-
["|", "_or_"],
|
|
263
|
-
["{", "_blt_"],
|
|
264
|
-
["}", "_bgt_"],
|
|
265
|
-
["<", "_lt_"],
|
|
266
|
-
[">", "_gt_"],
|
|
267
|
-
["[", "_alt_"],
|
|
268
|
-
["]", "_agt_"],
|
|
269
|
-
[",", "_comma_"],
|
|
270
|
-
["`", "_backquote_"],
|
|
271
|
-
["'", "_singlequote_"],
|
|
272
|
-
['"', "_doublequote_"],
|
|
273
|
-
[" ", "_space_"],
|
|
274
|
-
];
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IMetadataCollection } from "../schemas/metadata/IMetadataCollection";
|
|
4
|
+
import { Metadata } from "../schemas/metadata/Metadata";
|
|
5
|
+
import { MetadataAlias } from "../schemas/metadata/MetadataAlias";
|
|
6
|
+
import { MetadataArrayType } from "../schemas/metadata/MetadataArrayType";
|
|
7
|
+
import { MetadataObject } from "../schemas/metadata/MetadataObject";
|
|
8
|
+
import { MetadataTupleType } from "../schemas/metadata/MetadataTupleType";
|
|
9
|
+
|
|
10
|
+
import { Writable } from "../typings/Writable";
|
|
11
|
+
|
|
12
|
+
import { MapUtil } from "../utils/MapUtil";
|
|
13
|
+
|
|
14
|
+
import { CommentFactory } from "./CommentFactory";
|
|
15
|
+
import { TypeFactory } from "./TypeFactory";
|
|
16
|
+
|
|
17
|
+
export class MetadataCollection {
|
|
18
|
+
private readonly objects_: Map<ts.Type, MetadataObject>;
|
|
19
|
+
private readonly object_unions_: Map<string, MetadataObject[]>;
|
|
20
|
+
private readonly aliases_: Map<ts.Type, MetadataAlias>;
|
|
21
|
+
private readonly arrays_: Map<ts.Type, MetadataArrayType>;
|
|
22
|
+
private readonly tuples_: Map<ts.Type, MetadataTupleType>;
|
|
23
|
+
|
|
24
|
+
private readonly names_: Map<string, Map<ts.Type, string>>;
|
|
25
|
+
private object_index_: number;
|
|
26
|
+
private recursive_array_index_: number;
|
|
27
|
+
private recursive_tuple_index_: number;
|
|
28
|
+
|
|
29
|
+
public constructor(
|
|
30
|
+
private readonly options?: Partial<MetadataCollection.IOptions>,
|
|
31
|
+
) {
|
|
32
|
+
this.objects_ = new Map();
|
|
33
|
+
this.object_unions_ = new Map();
|
|
34
|
+
this.aliases_ = new Map();
|
|
35
|
+
this.arrays_ = new Map();
|
|
36
|
+
this.tuples_ = new Map();
|
|
37
|
+
|
|
38
|
+
this.names_ = new Map();
|
|
39
|
+
this.object_index_ = 0;
|
|
40
|
+
this.recursive_array_index_ = 0;
|
|
41
|
+
this.recursive_tuple_index_ = 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* -----------------------------------------------------------
|
|
45
|
+
ACCESSORS
|
|
46
|
+
----------------------------------------------------------- */
|
|
47
|
+
public aliases(): MetadataAlias[] {
|
|
48
|
+
return [...this.aliases_.values()];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public objects(): MetadataObject[] {
|
|
52
|
+
return [...this.objects_.values()];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public unions(): MetadataObject[][] {
|
|
56
|
+
return [...this.object_unions_.values()];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public arrays(): MetadataArrayType[] {
|
|
60
|
+
return [...this.arrays_.values()];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public tuples(): MetadataTupleType[] {
|
|
64
|
+
return [...this.tuples_.values()];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private getName(checker: ts.TypeChecker, type: ts.Type): string {
|
|
68
|
+
const name: string = (() => {
|
|
69
|
+
const str: string = TypeFactory.getFullName(checker)(type);
|
|
70
|
+
return this.options?.replace ? this.options.replace(str) : str;
|
|
71
|
+
})();
|
|
72
|
+
|
|
73
|
+
const duplicates: Map<ts.Type, string> = MapUtil.take(this.names_)(
|
|
74
|
+
name,
|
|
75
|
+
() => new Map(),
|
|
76
|
+
);
|
|
77
|
+
const oldbie: string | undefined = duplicates.get(type);
|
|
78
|
+
if (oldbie !== undefined) return oldbie;
|
|
79
|
+
|
|
80
|
+
const addicted: string = duplicates.size
|
|
81
|
+
? `${name}.o${duplicates.size}`
|
|
82
|
+
: name;
|
|
83
|
+
duplicates.set(type, addicted);
|
|
84
|
+
return addicted;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
public getUnionIndex(meta: Metadata): number {
|
|
91
|
+
const key: string = meta.objects.map((obj) => obj.name).join(" | ");
|
|
92
|
+
MapUtil.take(this.object_unions_)(key, () => meta.objects);
|
|
93
|
+
return [...this.object_unions_.keys()].indexOf(key);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/* -----------------------------------------------------------
|
|
97
|
+
INSTANCES
|
|
98
|
+
----------------------------------------------------------- */
|
|
99
|
+
public emplace(
|
|
100
|
+
checker: ts.TypeChecker,
|
|
101
|
+
type: ts.Type,
|
|
102
|
+
): [MetadataObject, boolean] {
|
|
103
|
+
const oldbie = this.objects_.get(type);
|
|
104
|
+
if (oldbie !== undefined) return [oldbie, false];
|
|
105
|
+
|
|
106
|
+
// const displays = type.symbol.getDocumentationComment(checker);
|
|
107
|
+
// const tags = type.symbol.getJsDocTags(checker);
|
|
108
|
+
|
|
109
|
+
// console.log(
|
|
110
|
+
// ts.displayPartsToString(displays),
|
|
111
|
+
// tags.map((tag) => tag.name),
|
|
112
|
+
// tags.map((tag) => ts.displayPartsToString(tag.text)),
|
|
113
|
+
// );
|
|
114
|
+
|
|
115
|
+
const $id: string = this.getName(checker, type);
|
|
116
|
+
const obj: MetadataObject = MetadataObject.create({
|
|
117
|
+
name: $id,
|
|
118
|
+
properties: [],
|
|
119
|
+
description:
|
|
120
|
+
(type.symbol && CommentFactory.description(type.symbol)) ??
|
|
121
|
+
undefined,
|
|
122
|
+
jsDocTags: type.symbol?.getJsDocTags() ?? [],
|
|
123
|
+
validated: false,
|
|
124
|
+
index: this.object_index_++,
|
|
125
|
+
recursive: null!,
|
|
126
|
+
nullables: [],
|
|
127
|
+
});
|
|
128
|
+
this.objects_.set(type, obj);
|
|
129
|
+
return [obj, true];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public emplaceAlias(
|
|
133
|
+
checker: ts.TypeChecker,
|
|
134
|
+
type: ts.Type,
|
|
135
|
+
symbol: ts.Symbol,
|
|
136
|
+
): [MetadataAlias, boolean, (meta: Metadata) => void] {
|
|
137
|
+
const oldbie = this.aliases_.get(type);
|
|
138
|
+
if (oldbie !== undefined) return [oldbie, false, () => {}];
|
|
139
|
+
|
|
140
|
+
const $id: string = this.getName(checker, type);
|
|
141
|
+
const alias: MetadataAlias = MetadataAlias.create({
|
|
142
|
+
name: $id,
|
|
143
|
+
value: null!,
|
|
144
|
+
description: CommentFactory.description(symbol) ?? null,
|
|
145
|
+
recursive: null!,
|
|
146
|
+
nullables: [],
|
|
147
|
+
jsDocTags: symbol.getJsDocTags() ?? [],
|
|
148
|
+
});
|
|
149
|
+
this.aliases_.set(type, alias);
|
|
150
|
+
return [alias, true, (meta) => (Writable(alias).value = meta)];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
public emplaceArray(
|
|
154
|
+
checker: ts.TypeChecker,
|
|
155
|
+
type: ts.Type,
|
|
156
|
+
): [MetadataArrayType, boolean, (meta: Metadata) => void] {
|
|
157
|
+
const oldbie = this.arrays_.get(type);
|
|
158
|
+
if (oldbie !== undefined) return [oldbie, false, () => {}];
|
|
159
|
+
|
|
160
|
+
const $id = this.getName(checker, type);
|
|
161
|
+
const array: MetadataArrayType = MetadataArrayType.create({
|
|
162
|
+
name: $id,
|
|
163
|
+
value: null!,
|
|
164
|
+
index: null,
|
|
165
|
+
recursive: null!,
|
|
166
|
+
nullables: [],
|
|
167
|
+
});
|
|
168
|
+
this.arrays_.set(type, array);
|
|
169
|
+
return [array, true, (meta) => (Writable(array).value = meta)];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
public emplaceTuple(
|
|
173
|
+
checker: ts.TypeChecker,
|
|
174
|
+
type: ts.TupleType,
|
|
175
|
+
): [MetadataTupleType, boolean, (elements: Metadata[]) => void] {
|
|
176
|
+
const oldbie = this.tuples_.get(type);
|
|
177
|
+
if (oldbie !== undefined) return [oldbie, false, () => {}];
|
|
178
|
+
|
|
179
|
+
const $id = this.getName(checker, type);
|
|
180
|
+
const tuple: MetadataTupleType = MetadataTupleType.create({
|
|
181
|
+
name: $id,
|
|
182
|
+
elements: null!,
|
|
183
|
+
index: null,
|
|
184
|
+
recursive: null!,
|
|
185
|
+
nullables: [],
|
|
186
|
+
});
|
|
187
|
+
this.tuples_.set(type, tuple);
|
|
188
|
+
return [
|
|
189
|
+
tuple,
|
|
190
|
+
true,
|
|
191
|
+
(elements) => (Writable(tuple).elements = elements),
|
|
192
|
+
];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @internal
|
|
197
|
+
*/
|
|
198
|
+
public setObjectRecursive(obj: MetadataObject, recursive: boolean): void {
|
|
199
|
+
Writable(obj).recursive = recursive;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* @internal
|
|
204
|
+
*/
|
|
205
|
+
public setAliasRecursive(alias: MetadataAlias, recursive: boolean): void {
|
|
206
|
+
Writable(alias).recursive = recursive;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* @internal
|
|
211
|
+
*/
|
|
212
|
+
public setArrayRecursive(
|
|
213
|
+
array: MetadataArrayType,
|
|
214
|
+
recursive: boolean,
|
|
215
|
+
): void {
|
|
216
|
+
Writable(array).recursive = recursive;
|
|
217
|
+
if (recursive) Writable(array).index = this.recursive_array_index_++;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
public setTupleRecursive(
|
|
221
|
+
tuple: MetadataTupleType,
|
|
222
|
+
recursive: boolean,
|
|
223
|
+
): void {
|
|
224
|
+
Writable(tuple).recursive = recursive;
|
|
225
|
+
if (recursive) Writable(tuple).index = this.recursive_tuple_index_++;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
public toJSON(): IMetadataCollection {
|
|
229
|
+
return {
|
|
230
|
+
objects: this.objects().map((o) => o.toJSON()),
|
|
231
|
+
aliases: this.aliases().map((d) => d.toJSON()),
|
|
232
|
+
arrays: [...this.arrays_.values()].map((a) => a.toJSON()),
|
|
233
|
+
tuples: [...this.tuples_.values()].map((t) => t.toJSON()),
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
export namespace MetadataCollection {
|
|
238
|
+
export interface IOptions {
|
|
239
|
+
replace?(str: string): string;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export const replace = (str: string): string => {
|
|
243
|
+
let replaced: string = str;
|
|
244
|
+
for (const [before] of REPLACERS)
|
|
245
|
+
replaced = replaced.split(before).join("");
|
|
246
|
+
if (replaced.length !== 0) return replaced;
|
|
247
|
+
|
|
248
|
+
for (const [before, after] of REPLACERS)
|
|
249
|
+
str = str.split(before).join(after);
|
|
250
|
+
return str;
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
export const escape = (str: string): string => {
|
|
254
|
+
for (const [before, after] of REPLACERS)
|
|
255
|
+
if (after !== "") str = str.split(after).join(before);
|
|
256
|
+
return str;
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
const REPLACERS: [string, string][] = [
|
|
260
|
+
["$", "_dollar_"],
|
|
261
|
+
["&", "_and_"],
|
|
262
|
+
["|", "_or_"],
|
|
263
|
+
["{", "_blt_"],
|
|
264
|
+
["}", "_bgt_"],
|
|
265
|
+
["<", "_lt_"],
|
|
266
|
+
[">", "_gt_"],
|
|
267
|
+
["[", "_alt_"],
|
|
268
|
+
["]", "_agt_"],
|
|
269
|
+
[",", "_comma_"],
|
|
270
|
+
["`", "_backquote_"],
|
|
271
|
+
["'", "_singlequote_"],
|
|
272
|
+
['"', "_doublequote_"],
|
|
273
|
+
[" ", "_space_"],
|
|
274
|
+
];
|
|
@@ -1,9 +1,28 @@
|
|
|
1
|
-
export namespace $HeadersReader {
|
|
2
|
-
export const boolean = (value: string | undefined) =>
|
|
3
|
-
value !== undefined
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
export namespace $HeadersReader {
|
|
2
|
+
export const boolean = (value: string | undefined) =>
|
|
3
|
+
value !== undefined
|
|
4
|
+
? value === "true"
|
|
5
|
+
? true
|
|
6
|
+
: value === "false"
|
|
7
|
+
? false
|
|
8
|
+
: value
|
|
9
|
+
: undefined;
|
|
10
|
+
export const bigint = (value: string | undefined) =>
|
|
11
|
+
value !== undefined ? toBigint(value) : undefined;
|
|
12
|
+
export const number = (value: string | undefined) =>
|
|
13
|
+
value !== undefined ? toNumber(value) : undefined;
|
|
14
|
+
export const string = (value: string | undefined) => value;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const toNumber = (str: string): number | string => {
|
|
18
|
+
const value: number = Number(str);
|
|
19
|
+
return isNaN(value) ? str : value;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const toBigint = (str: string): bigint | string => {
|
|
23
|
+
try {
|
|
24
|
+
return BigInt(str);
|
|
25
|
+
} catch {
|
|
26
|
+
return str;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export namespace $ParameterReader {
|
|
2
|
+
export const boolean = (value: string) =>
|
|
3
|
+
value !== "null"
|
|
4
|
+
? value === "true"
|
|
5
|
+
? true
|
|
6
|
+
: value === "false"
|
|
7
|
+
? false
|
|
8
|
+
: value
|
|
9
|
+
: null;
|
|
10
|
+
|
|
11
|
+
export const bigint = (value: string) =>
|
|
12
|
+
value !== "null" ? toBigint(value) : null;
|
|
13
|
+
|
|
14
|
+
export const number = (value: string) =>
|
|
15
|
+
value !== "null" ? toNumber(value) : null;
|
|
16
|
+
|
|
17
|
+
export const string = (value: string) => (value !== "null" ? value : null);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const toNumber = (str: string): number | string => {
|
|
21
|
+
const value: number = Number(str);
|
|
22
|
+
return isNaN(value) ? str : value;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const toBigint = (str: string): bigint | string => {
|
|
26
|
+
try {
|
|
27
|
+
return BigInt(str);
|
|
28
|
+
} catch {
|
|
29
|
+
return str;
|
|
30
|
+
}
|
|
31
|
+
};
|