typia 5.2.5 → 5.2.6-dev.20231108
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/lib/factories/ExpressionFactory.d.ts +1 -0
- package/lib/factories/ExpressionFactory.js +5 -0
- package/lib/factories/ExpressionFactory.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.js +4 -4
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/RandomProgrammer.js +16 -18
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +2 -1
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/lib/programmers/helpers/RandomJoiner.js +4 -6
- package/lib/programmers/helpers/RandomJoiner.js.map +1 -1
- package/lib/programmers/helpers/RandomRanger.js +3 -2
- package/lib/programmers/helpers/RandomRanger.js.map +1 -1
- package/lib/programmers/http/HttpHeadersProgrammer.js +1 -1
- package/lib/programmers/http/HttpHeadersProgrammer.js.map +1 -1
- package/lib/programmers/internal/check_dynamic_properties.js +4 -3
- package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
- package/lib/programmers/internal/check_union_array_like.js +3 -2
- package/lib/programmers/internal/check_union_array_like.js.map +1 -1
- package/lib/programmers/json/JsonStringifyProgrammer.js +1 -3
- package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js +1 -3
- package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscLiteralsProgrammer.js +1 -1
- package/lib/programmers/misc/MiscLiteralsProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscPruneProgrammer.js +1 -3
- package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js +1 -3
- package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +6 -6
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js +2 -2
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js.map +1 -1
- package/package.json +1 -1
- package/src/Primitive.ts +135 -135
- package/src/executable/TypiaSetupWizard.ts +142 -142
- package/src/executable/setup/CommandExecutor.ts +8 -8
- package/src/factories/ExpressionFactory.ts +8 -0
- package/src/factories/JsonMetadataFactory.ts +50 -50
- package/src/factories/MetadataCollection.ts +282 -282
- package/src/factories/internal/metadata/emplace_metadata_object.ts +178 -178
- package/src/functional/$stoll.ts +8 -8
- package/src/functional/Namespace.ts +168 -168
- package/src/programmers/AssertProgrammer.ts +322 -322
- package/src/programmers/CheckerProgrammer.ts +4 -4
- package/src/programmers/IsProgrammer.ts +258 -258
- package/src/programmers/RandomProgrammer.ts +16 -17
- package/src/programmers/ValidateProgrammer.ts +350 -349
- package/src/programmers/helpers/AtomicPredicator.ts +31 -31
- package/src/programmers/helpers/RandomJoiner.ts +4 -6
- package/src/programmers/helpers/RandomRanger.ts +4 -2
- package/src/programmers/http/HttpHeadersProgrammer.ts +1 -1
- package/src/programmers/internal/check_dynamic_key.ts +178 -178
- package/src/programmers/internal/check_dynamic_properties.ts +202 -201
- package/src/programmers/internal/check_object.ts +62 -62
- package/src/programmers/internal/check_union_array_like.ts +4 -3
- package/src/programmers/json/JsonStringifyProgrammer.ts +960 -964
- package/src/programmers/misc/MiscCloneProgrammer.ts +786 -790
- package/src/programmers/misc/MiscLiteralsProgrammer.ts +1 -1
- package/src/programmers/misc/MiscPruneProgrammer.ts +548 -552
- package/src/programmers/notations/NotationGeneralProgrammer.ts +716 -720
- package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +7 -9
- package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +882 -882
- package/src/transform.ts +35 -35
|
@@ -1,178 +1,178 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../../../schemas/metadata/Metadata";
|
|
4
|
-
import { MetadataObject } from "../../../schemas/metadata/MetadataObject";
|
|
5
|
-
import { MetadataProperty } from "../../../schemas/metadata/MetadataProperty";
|
|
6
|
-
|
|
7
|
-
import { Writable } from "../../../typings/Writable";
|
|
8
|
-
|
|
9
|
-
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
10
|
-
|
|
11
|
-
import { CommentFactory } from "../../CommentFactory";
|
|
12
|
-
import { MetadataCollection } from "../../MetadataCollection";
|
|
13
|
-
import { MetadataFactory } from "../../MetadataFactory";
|
|
14
|
-
import { MetadataHelper } from "./MetadataHelper";
|
|
15
|
-
import { explore_metadata } from "./explore_metadata";
|
|
16
|
-
import { iterate_metadata_coalesce } from "./iterate_metadata_coalesce";
|
|
17
|
-
|
|
18
|
-
export const emplace_metadata_object =
|
|
19
|
-
(checker: ts.TypeChecker) =>
|
|
20
|
-
(options: MetadataFactory.IOptions) =>
|
|
21
|
-
(collection: MetadataCollection) =>
|
|
22
|
-
(errors: MetadataFactory.IError[]) =>
|
|
23
|
-
(parent: ts.Type, nullable: boolean): MetadataObject => {
|
|
24
|
-
// EMPLACE OBJECT
|
|
25
|
-
const [obj, newbie] = collection.emplace(checker, parent);
|
|
26
|
-
ArrayUtil.add(obj.nullables, nullable, (elem) => elem === nullable);
|
|
27
|
-
|
|
28
|
-
if (newbie === false) return obj;
|
|
29
|
-
|
|
30
|
-
// PREPARE ASSETS
|
|
31
|
-
const isClass: boolean = parent.isClass();
|
|
32
|
-
const pred: (node: ts.Declaration) => boolean = isClass
|
|
33
|
-
? (node) => {
|
|
34
|
-
const kind: ts.SyntaxKind | undefined = node
|
|
35
|
-
.getChildren()[0]
|
|
36
|
-
?.getChildren()[0]?.kind;
|
|
37
|
-
return (
|
|
38
|
-
kind !== ts.SyntaxKind.PrivateKeyword &&
|
|
39
|
-
kind !== ts.SyntaxKind.ProtectedKeyword &&
|
|
40
|
-
(ts.isParameter(node) || isProperty(node))
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
: (node) => isProperty(node);
|
|
44
|
-
|
|
45
|
-
const insert =
|
|
46
|
-
(key: Metadata) =>
|
|
47
|
-
(value: Metadata) =>
|
|
48
|
-
(
|
|
49
|
-
symbol: ts.Symbol | undefined,
|
|
50
|
-
filter?: (doc: ts.JSDocTagInfo) => boolean,
|
|
51
|
-
): MetadataProperty => {
|
|
52
|
-
// COMMENTS AND TAGS
|
|
53
|
-
const description: string | null = symbol
|
|
54
|
-
? CommentFactory.description(symbol) ?? null
|
|
55
|
-
: null;
|
|
56
|
-
const jsDocTags: ts.JSDocTagInfo[] = (
|
|
57
|
-
symbol?.getJsDocTags() ?? []
|
|
58
|
-
).filter(filter ?? (() => true));
|
|
59
|
-
|
|
60
|
-
// THE PROPERTY
|
|
61
|
-
const property = MetadataProperty.create({
|
|
62
|
-
key,
|
|
63
|
-
value,
|
|
64
|
-
description,
|
|
65
|
-
jsDocTags,
|
|
66
|
-
});
|
|
67
|
-
obj.properties.push(property);
|
|
68
|
-
return property;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
//----
|
|
72
|
-
// REGULAR PROPERTIES
|
|
73
|
-
//----
|
|
74
|
-
for (const prop of parent.getApparentProperties()) {
|
|
75
|
-
// CHECK INTERNAL TAG
|
|
76
|
-
if (
|
|
77
|
-
(prop.getJsDocTags(checker) ?? []).find(
|
|
78
|
-
(tag) => tag.name === "internal",
|
|
79
|
-
) !== undefined
|
|
80
|
-
)
|
|
81
|
-
continue;
|
|
82
|
-
|
|
83
|
-
// CHECK NODE IS A FORMAL PROPERTY
|
|
84
|
-
const [node, type] = (() => {
|
|
85
|
-
const node = prop.getDeclarations()?.[0] as
|
|
86
|
-
| ts.PropertyDeclaration
|
|
87
|
-
| undefined;
|
|
88
|
-
const type: ts.Type | undefined = node
|
|
89
|
-
? checker.getTypeOfSymbolAtLocation(prop, node)
|
|
90
|
-
: checker.getTypeOfPropertyOfType(parent, prop.name);
|
|
91
|
-
return [node, type];
|
|
92
|
-
})();
|
|
93
|
-
if ((node && pred(node) === false) || type === undefined) continue;
|
|
94
|
-
|
|
95
|
-
// GET EXACT TYPE
|
|
96
|
-
const key: Metadata = MetadataHelper.literal_to_metadata(prop.name);
|
|
97
|
-
const value: Metadata = explore_metadata(checker)(options)(
|
|
98
|
-
collection,
|
|
99
|
-
)(errors)(type, {
|
|
100
|
-
top: false,
|
|
101
|
-
object: obj,
|
|
102
|
-
property: prop.name,
|
|
103
|
-
nested: null,
|
|
104
|
-
escaped: false,
|
|
105
|
-
aliased: false,
|
|
106
|
-
});
|
|
107
|
-
Writable(value).optional =
|
|
108
|
-
(prop.flags & ts.SymbolFlags.Optional) !== 0;
|
|
109
|
-
insert(key)(value)(prop);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
//----
|
|
113
|
-
// DYNAMIC PROPERTIES
|
|
114
|
-
//----
|
|
115
|
-
for (const index of checker.getIndexInfosOfType(parent)) {
|
|
116
|
-
// GET EXACT TYPE
|
|
117
|
-
const analyzer = (type: ts.Type) => (property: {} | null) =>
|
|
118
|
-
explore_metadata(checker)(options)(collection)(errors)(type, {
|
|
119
|
-
top: false,
|
|
120
|
-
object: obj,
|
|
121
|
-
property,
|
|
122
|
-
nested: null,
|
|
123
|
-
escaped: false,
|
|
124
|
-
aliased: false,
|
|
125
|
-
});
|
|
126
|
-
const key: Metadata = analyzer(index.keyType)(null);
|
|
127
|
-
const value: Metadata = analyzer(index.type)({});
|
|
128
|
-
|
|
129
|
-
if (
|
|
130
|
-
key.atomics.length +
|
|
131
|
-
key.constants
|
|
132
|
-
.map((c) => c.values.length)
|
|
133
|
-
.reduce((a, b) => a + b, 0) +
|
|
134
|
-
key.templates.length +
|
|
135
|
-
key.natives.filter(
|
|
136
|
-
(type) =>
|
|
137
|
-
type === "Boolean" ||
|
|
138
|
-
type === "BigInt" ||
|
|
139
|
-
type === "Number" ||
|
|
140
|
-
type === "String",
|
|
141
|
-
).length !==
|
|
142
|
-
key.size()
|
|
143
|
-
)
|
|
144
|
-
errors.push({
|
|
145
|
-
name: key.getName(),
|
|
146
|
-
explore: {
|
|
147
|
-
top: false,
|
|
148
|
-
object: obj,
|
|
149
|
-
property: "[key]",
|
|
150
|
-
nested: null,
|
|
151
|
-
escaped: false,
|
|
152
|
-
aliased: false,
|
|
153
|
-
},
|
|
154
|
-
messages: [],
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
// INSERT WITH REQUIRED CONFIGURATION
|
|
158
|
-
insert(key)(value)(
|
|
159
|
-
index.declaration?.parent
|
|
160
|
-
? checker.getSymbolAtLocation(index.declaration.parent)
|
|
161
|
-
: undefined,
|
|
162
|
-
(doc) => doc.name !== "default",
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
return obj;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
const isProperty = (node: ts.Declaration) =>
|
|
169
|
-
ts.isPropertyDeclaration(node) ||
|
|
170
|
-
ts.isPropertyAssignment(node) ||
|
|
171
|
-
ts.isPropertySignature(node) ||
|
|
172
|
-
ts.isTypeLiteralNode(node);
|
|
173
|
-
|
|
174
|
-
const iterate_optional_coalesce = (meta: Metadata, type: ts.Type): void => {
|
|
175
|
-
if (type.isUnionOrIntersection())
|
|
176
|
-
type.types.forEach((child) => iterate_optional_coalesce(meta, child));
|
|
177
|
-
else iterate_metadata_coalesce(meta, type);
|
|
178
|
-
};
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../../schemas/metadata/Metadata";
|
|
4
|
+
import { MetadataObject } from "../../../schemas/metadata/MetadataObject";
|
|
5
|
+
import { MetadataProperty } from "../../../schemas/metadata/MetadataProperty";
|
|
6
|
+
|
|
7
|
+
import { Writable } from "../../../typings/Writable";
|
|
8
|
+
|
|
9
|
+
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
10
|
+
|
|
11
|
+
import { CommentFactory } from "../../CommentFactory";
|
|
12
|
+
import { MetadataCollection } from "../../MetadataCollection";
|
|
13
|
+
import { MetadataFactory } from "../../MetadataFactory";
|
|
14
|
+
import { MetadataHelper } from "./MetadataHelper";
|
|
15
|
+
import { explore_metadata } from "./explore_metadata";
|
|
16
|
+
import { iterate_metadata_coalesce } from "./iterate_metadata_coalesce";
|
|
17
|
+
|
|
18
|
+
export const emplace_metadata_object =
|
|
19
|
+
(checker: ts.TypeChecker) =>
|
|
20
|
+
(options: MetadataFactory.IOptions) =>
|
|
21
|
+
(collection: MetadataCollection) =>
|
|
22
|
+
(errors: MetadataFactory.IError[]) =>
|
|
23
|
+
(parent: ts.Type, nullable: boolean): MetadataObject => {
|
|
24
|
+
// EMPLACE OBJECT
|
|
25
|
+
const [obj, newbie] = collection.emplace(checker, parent);
|
|
26
|
+
ArrayUtil.add(obj.nullables, nullable, (elem) => elem === nullable);
|
|
27
|
+
|
|
28
|
+
if (newbie === false) return obj;
|
|
29
|
+
|
|
30
|
+
// PREPARE ASSETS
|
|
31
|
+
const isClass: boolean = parent.isClass();
|
|
32
|
+
const pred: (node: ts.Declaration) => boolean = isClass
|
|
33
|
+
? (node) => {
|
|
34
|
+
const kind: ts.SyntaxKind | undefined = node
|
|
35
|
+
.getChildren()[0]
|
|
36
|
+
?.getChildren()[0]?.kind;
|
|
37
|
+
return (
|
|
38
|
+
kind !== ts.SyntaxKind.PrivateKeyword &&
|
|
39
|
+
kind !== ts.SyntaxKind.ProtectedKeyword &&
|
|
40
|
+
(ts.isParameter(node) || isProperty(node))
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
: (node) => isProperty(node);
|
|
44
|
+
|
|
45
|
+
const insert =
|
|
46
|
+
(key: Metadata) =>
|
|
47
|
+
(value: Metadata) =>
|
|
48
|
+
(
|
|
49
|
+
symbol: ts.Symbol | undefined,
|
|
50
|
+
filter?: (doc: ts.JSDocTagInfo) => boolean,
|
|
51
|
+
): MetadataProperty => {
|
|
52
|
+
// COMMENTS AND TAGS
|
|
53
|
+
const description: string | null = symbol
|
|
54
|
+
? CommentFactory.description(symbol) ?? null
|
|
55
|
+
: null;
|
|
56
|
+
const jsDocTags: ts.JSDocTagInfo[] = (
|
|
57
|
+
symbol?.getJsDocTags() ?? []
|
|
58
|
+
).filter(filter ?? (() => true));
|
|
59
|
+
|
|
60
|
+
// THE PROPERTY
|
|
61
|
+
const property = MetadataProperty.create({
|
|
62
|
+
key,
|
|
63
|
+
value,
|
|
64
|
+
description,
|
|
65
|
+
jsDocTags,
|
|
66
|
+
});
|
|
67
|
+
obj.properties.push(property);
|
|
68
|
+
return property;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
//----
|
|
72
|
+
// REGULAR PROPERTIES
|
|
73
|
+
//----
|
|
74
|
+
for (const prop of parent.getApparentProperties()) {
|
|
75
|
+
// CHECK INTERNAL TAG
|
|
76
|
+
if (
|
|
77
|
+
(prop.getJsDocTags(checker) ?? []).find(
|
|
78
|
+
(tag) => tag.name === "internal",
|
|
79
|
+
) !== undefined
|
|
80
|
+
)
|
|
81
|
+
continue;
|
|
82
|
+
|
|
83
|
+
// CHECK NODE IS A FORMAL PROPERTY
|
|
84
|
+
const [node, type] = (() => {
|
|
85
|
+
const node = prop.getDeclarations()?.[0] as
|
|
86
|
+
| ts.PropertyDeclaration
|
|
87
|
+
| undefined;
|
|
88
|
+
const type: ts.Type | undefined = node
|
|
89
|
+
? checker.getTypeOfSymbolAtLocation(prop, node)
|
|
90
|
+
: checker.getTypeOfPropertyOfType(parent, prop.name);
|
|
91
|
+
return [node, type];
|
|
92
|
+
})();
|
|
93
|
+
if ((node && pred(node) === false) || type === undefined) continue;
|
|
94
|
+
|
|
95
|
+
// GET EXACT TYPE
|
|
96
|
+
const key: Metadata = MetadataHelper.literal_to_metadata(prop.name);
|
|
97
|
+
const value: Metadata = explore_metadata(checker)(options)(
|
|
98
|
+
collection,
|
|
99
|
+
)(errors)(type, {
|
|
100
|
+
top: false,
|
|
101
|
+
object: obj,
|
|
102
|
+
property: prop.name,
|
|
103
|
+
nested: null,
|
|
104
|
+
escaped: false,
|
|
105
|
+
aliased: false,
|
|
106
|
+
});
|
|
107
|
+
Writable(value).optional =
|
|
108
|
+
(prop.flags & ts.SymbolFlags.Optional) !== 0;
|
|
109
|
+
insert(key)(value)(prop);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
//----
|
|
113
|
+
// DYNAMIC PROPERTIES
|
|
114
|
+
//----
|
|
115
|
+
for (const index of checker.getIndexInfosOfType(parent)) {
|
|
116
|
+
// GET EXACT TYPE
|
|
117
|
+
const analyzer = (type: ts.Type) => (property: {} | null) =>
|
|
118
|
+
explore_metadata(checker)(options)(collection)(errors)(type, {
|
|
119
|
+
top: false,
|
|
120
|
+
object: obj,
|
|
121
|
+
property,
|
|
122
|
+
nested: null,
|
|
123
|
+
escaped: false,
|
|
124
|
+
aliased: false,
|
|
125
|
+
});
|
|
126
|
+
const key: Metadata = analyzer(index.keyType)(null);
|
|
127
|
+
const value: Metadata = analyzer(index.type)({});
|
|
128
|
+
|
|
129
|
+
if (
|
|
130
|
+
key.atomics.length +
|
|
131
|
+
key.constants
|
|
132
|
+
.map((c) => c.values.length)
|
|
133
|
+
.reduce((a, b) => a + b, 0) +
|
|
134
|
+
key.templates.length +
|
|
135
|
+
key.natives.filter(
|
|
136
|
+
(type) =>
|
|
137
|
+
type === "Boolean" ||
|
|
138
|
+
type === "BigInt" ||
|
|
139
|
+
type === "Number" ||
|
|
140
|
+
type === "String",
|
|
141
|
+
).length !==
|
|
142
|
+
key.size()
|
|
143
|
+
)
|
|
144
|
+
errors.push({
|
|
145
|
+
name: key.getName(),
|
|
146
|
+
explore: {
|
|
147
|
+
top: false,
|
|
148
|
+
object: obj,
|
|
149
|
+
property: "[key]",
|
|
150
|
+
nested: null,
|
|
151
|
+
escaped: false,
|
|
152
|
+
aliased: false,
|
|
153
|
+
},
|
|
154
|
+
messages: [],
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// INSERT WITH REQUIRED CONFIGURATION
|
|
158
|
+
insert(key)(value)(
|
|
159
|
+
index.declaration?.parent
|
|
160
|
+
? checker.getSymbolAtLocation(index.declaration.parent)
|
|
161
|
+
: undefined,
|
|
162
|
+
(doc) => doc.name !== "default",
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
return obj;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const isProperty = (node: ts.Declaration) =>
|
|
169
|
+
ts.isPropertyDeclaration(node) ||
|
|
170
|
+
ts.isPropertyAssignment(node) ||
|
|
171
|
+
ts.isPropertySignature(node) ||
|
|
172
|
+
ts.isTypeLiteralNode(node);
|
|
173
|
+
|
|
174
|
+
const iterate_optional_coalesce = (meta: Metadata, type: ts.Type): void => {
|
|
175
|
+
if (type.isUnionOrIntersection())
|
|
176
|
+
type.types.forEach((child) => iterate_optional_coalesce(meta, child));
|
|
177
|
+
else iterate_metadata_coalesce(meta, type);
|
|
178
|
+
};
|
package/src/functional/$stoll.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export const $is_bigint_string = (str: string): boolean => {
|
|
2
|
-
try {
|
|
3
|
-
BigInt(str);
|
|
4
|
-
return true;
|
|
5
|
-
} catch {
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
};
|
|
1
|
+
export const $is_bigint_string = (str: string): boolean => {
|
|
2
|
+
try {
|
|
3
|
+
BigInt(str);
|
|
4
|
+
return true;
|
|
5
|
+
} catch {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
};
|