typia 5.2.6 → 5.3.0-dev.20231112
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.js +14 -16
- package/lib/factories/ExpressionFactory.js.map +1 -1
- package/lib/factories/JsonMetadataFactory.d.ts +1 -1
- package/lib/factories/JsonMetadataFactory.js +2 -2
- package/lib/factories/JsonMetadataFactory.js.map +1 -1
- package/lib/factories/LiteralFactory.js +2 -0
- package/lib/factories/LiteralFactory.js.map +1 -1
- package/lib/factories/MetadataCollection.d.ts +2 -2
- package/lib/factories/MetadataFactory.d.ts +1 -1
- package/lib/factories/MetadataFactory.js +236 -170
- package/lib/factories/MetadataFactory.js.map +1 -1
- package/lib/factories/NumericRangeFactory.d.ts +2 -2
- package/lib/factories/NumericRangeFactory.js +41 -21
- package/lib/factories/NumericRangeFactory.js.map +1 -1
- package/lib/factories/ProtobufFactory.d.ts +1 -1
- package/lib/factories/ProtobufFactory.js +2 -2
- package/lib/factories/ProtobufFactory.js.map +1 -1
- package/lib/factories/internal/metadata/MetadataHelper.js +3 -2
- package/lib/factories/internal/metadata/MetadataHelper.js.map +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_constant.js +13 -8
- package/lib/factories/internal/metadata/iterate_metadata_constant.js.map +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_intersection.js +8 -5
- package/lib/factories/internal/metadata/iterate_metadata_intersection.js.map +1 -1
- package/lib/functional/$from.d.ts +3 -0
- package/lib/functional/$from.js +9 -0
- package/lib/functional/$from.js.map +1 -0
- package/lib/functional/Namespace.js +7 -0
- package/lib/functional/Namespace.js.map +1 -1
- package/lib/module.d.ts +1 -0
- package/lib/module.js +2 -5
- package/lib/module.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.js +11 -16
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/RandomProgrammer.js +1 -1
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/helpers/ProtobufUtil.js.map +1 -1
- package/lib/programmers/http/HttpHeadersProgrammer.js +1 -1
- package/lib/programmers/http/HttpHeadersProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpParameterProgrammer.js +1 -1
- package/lib/programmers/http/HttpParameterProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpQueryProgrammer.js +1 -1
- package/lib/programmers/http/HttpQueryProgrammer.js.map +1 -1
- package/lib/programmers/internal/application_array.js +8 -0
- package/lib/programmers/internal/application_array.js.map +1 -1
- package/lib/programmers/internal/application_number.js +8 -1
- package/lib/programmers/internal/application_number.js.map +1 -1
- package/lib/programmers/internal/application_string.js +8 -1
- package/lib/programmers/internal/application_string.js.map +1 -1
- package/lib/programmers/internal/check_array_length.js +7 -4
- package/lib/programmers/internal/check_array_length.js.map +1 -1
- package/lib/programmers/internal/check_bigint.js +7 -4
- package/lib/programmers/internal/check_bigint.js.map +1 -1
- package/lib/programmers/internal/check_number.js +7 -4
- package/lib/programmers/internal/check_number.js.map +1 -1
- package/lib/programmers/internal/check_string.js +7 -4
- package/lib/programmers/internal/check_string.js.map +1 -1
- package/lib/programmers/internal/metadata_to_pattern.js +3 -1
- package/lib/programmers/internal/metadata_to_pattern.js.map +1 -1
- package/lib/programmers/json/JsonAssertParseProgrammer.js +1 -1
- package/lib/programmers/json/JsonAssertParseProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonIsParseProgrammer.js +1 -1
- package/lib/programmers/json/JsonIsParseProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonStringifyProgrammer.js +3 -8
- package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonValidateParseProgrammer.js +1 -1
- package/lib/programmers/json/JsonValidateParseProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js +19 -24
- 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 +11 -16
- package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js +11 -16
- package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js +38 -42
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufMessageProgrammer.d.ts +1 -1
- package/lib/programmers/protobuf/ProtobufMessageProgrammer.js +22 -25
- package/lib/programmers/protobuf/ProtobufMessageProgrammer.js.map +1 -1
- package/lib/reflect.d.ts +3 -0
- package/lib/reflect.js +13 -0
- package/lib/reflect.js.map +1 -0
- package/lib/schemas/json/IJsonSchema.d.ts +1 -0
- package/lib/schemas/metadata/IMetadataApplication.d.ts +2 -2
- package/lib/schemas/metadata/{IMetadataCollection.d.ts → IMetadataComponents.d.ts} +1 -1
- package/lib/schemas/metadata/{IMetadataCollection.js → IMetadataComponents.js} +1 -1
- package/lib/schemas/metadata/IMetadataComponents.js.map +1 -0
- package/lib/schemas/metadata/IMetadataConstant.d.ts +1 -1
- package/lib/schemas/metadata/IMetadataTypeTag.d.ts +2 -2
- package/lib/schemas/metadata/Metadata.d.ts +2 -2
- package/lib/schemas/metadata/Metadata.js +82 -173
- package/lib/schemas/metadata/Metadata.js.map +1 -1
- package/lib/schemas/metadata/MetadataAlias.js +1 -1
- package/lib/schemas/metadata/MetadataAlias.js.map +1 -1
- package/lib/schemas/metadata/MetadataApplication.d.ts +13 -0
- package/lib/schemas/metadata/MetadataApplication.js +30 -0
- package/lib/schemas/metadata/MetadataApplication.js.map +1 -0
- package/lib/schemas/metadata/MetadataArrayType.js +1 -1
- package/lib/schemas/metadata/MetadataArrayType.js.map +1 -1
- package/lib/schemas/metadata/MetadataAtomic.d.ts +3 -0
- package/lib/schemas/metadata/MetadataAtomic.js +42 -0
- package/lib/schemas/metadata/MetadataAtomic.js.map +1 -1
- package/lib/schemas/metadata/MetadataComponents.d.ts +16 -0
- package/lib/schemas/metadata/MetadataComponents.js +151 -0
- package/lib/schemas/metadata/MetadataComponents.js.map +1 -0
- package/lib/schemas/metadata/MetadataConstant.d.ts +9 -1
- package/lib/schemas/metadata/MetadataConstant.js +29 -0
- package/lib/schemas/metadata/MetadataConstant.js.map +1 -1
- package/lib/schemas/metadata/MetadataEscaped.js +4 -4
- package/lib/schemas/metadata/MetadataEscaped.js.map +1 -1
- package/lib/schemas/metadata/MetadataObject.js +2 -2
- package/lib/schemas/metadata/MetadataObject.js.map +1 -1
- package/lib/schemas/metadata/MetadataProperty.js +4 -4
- package/lib/schemas/metadata/MetadataProperty.js.map +1 -1
- package/lib/schemas/metadata/MetadataTupleType.js +1 -1
- package/lib/schemas/metadata/MetadataTupleType.js.map +1 -1
- package/lib/transformers/CallExpressionTransformer.js +5 -2
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/features/json/JsonApplicationTransformer.d.ts +1 -1
- package/lib/transformers/features/json/JsonApplicationTransformer.js +4 -5
- package/lib/transformers/features/json/JsonApplicationTransformer.js.map +1 -1
- package/lib/transformers/features/reflect/ReflectMetadataTransformer.d.ts +5 -0
- package/lib/transformers/features/reflect/ReflectMetadataTransformer.js +58 -0
- package/lib/transformers/features/reflect/ReflectMetadataTransformer.js.map +1 -0
- package/package.json +2 -2
- 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 +12 -13
- package/src/factories/JsonMetadataFactory.ts +53 -50
- package/src/factories/LiteralFactory.ts +2 -0
- package/src/factories/MetadataCollection.ts +282 -282
- package/src/factories/MetadataFactory.ts +55 -22
- package/src/factories/NumericRangeFactory.ts +56 -17
- package/src/factories/ProtobufFactory.ts +5 -2
- package/src/factories/internal/metadata/MetadataHelper.ts +7 -4
- package/src/factories/internal/metadata/emplace_metadata_object.ts +178 -178
- package/src/factories/internal/metadata/iterate_metadata_constant.ts +10 -8
- package/src/factories/internal/metadata/iterate_metadata_intersection.ts +9 -8
- package/src/functional/$from.ts +5 -0
- package/src/functional/$stoll.ts +8 -8
- package/src/functional/Namespace.ts +175 -168
- package/src/module.ts +1 -19
- package/src/programmers/AssertProgrammer.ts +322 -322
- package/src/programmers/CheckerProgrammer.ts +16 -17
- package/src/programmers/IsProgrammer.ts +258 -258
- package/src/programmers/RandomProgrammer.ts +4 -1
- package/src/programmers/ValidateProgrammer.ts +350 -350
- package/src/programmers/helpers/AtomicPredicator.ts +31 -31
- package/src/programmers/helpers/ProtobufUtil.ts +3 -2
- package/src/programmers/http/HttpHeadersProgrammer.ts +4 -1
- package/src/programmers/http/HttpParameterProgrammer.ts +4 -1
- package/src/programmers/http/HttpQueryProgrammer.ts +4 -1
- package/src/programmers/internal/application_array.ts +8 -0
- package/src/programmers/internal/application_number.ts +8 -1
- package/src/programmers/internal/application_string.ts +8 -1
- package/src/programmers/internal/check_array_length.ts +5 -2
- package/src/programmers/internal/check_bigint.ts +5 -2
- package/src/programmers/internal/check_dynamic_key.ts +178 -178
- package/src/programmers/internal/check_dynamic_properties.ts +202 -202
- package/src/programmers/internal/check_number.ts +5 -2
- package/src/programmers/internal/check_object.ts +62 -62
- package/src/programmers/internal/check_string.ts +5 -3
- package/src/programmers/internal/metadata_to_pattern.ts +3 -1
- package/src/programmers/json/JsonAssertParseProgrammer.ts +1 -0
- package/src/programmers/json/JsonIsParseProgrammer.ts +1 -0
- package/src/programmers/json/JsonStringifyProgrammer.ts +959 -960
- package/src/programmers/json/JsonValidateParseProgrammer.ts +1 -0
- package/src/programmers/misc/MiscCloneProgrammer.ts +787 -786
- package/src/programmers/misc/MiscLiteralsProgrammer.ts +4 -1
- package/src/programmers/misc/MiscPruneProgrammer.ts +549 -548
- package/src/programmers/notations/NotationGeneralProgrammer.ts +717 -716
- package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +1 -0
- package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +872 -882
- package/src/programmers/protobuf/ProtobufMessageProgrammer.ts +21 -21
- package/src/reflect.ts +24 -0
- package/src/schemas/json/IJsonSchema.ts +1 -0
- package/src/schemas/metadata/IMetadataApplication.ts +2 -2
- package/src/schemas/metadata/{IMetadataCollection.ts → IMetadataComponents.ts} +1 -1
- package/src/schemas/metadata/IMetadataConstant.ts +1 -1
- package/src/schemas/metadata/IMetadataTypeTag.ts +9 -2
- package/src/schemas/metadata/Metadata.ts +18 -91
- package/src/schemas/metadata/MetadataAlias.ts +1 -1
- package/src/schemas/metadata/MetadataApplication.ts +44 -0
- package/src/schemas/metadata/MetadataArrayType.ts +1 -1
- package/src/schemas/metadata/MetadataAtomic.ts +44 -0
- package/src/schemas/metadata/MetadataComponents.ts +98 -0
- package/src/schemas/metadata/MetadataConstant.ts +44 -1
- package/src/schemas/metadata/MetadataEscaped.ts +4 -4
- package/src/schemas/metadata/MetadataObject.ts +2 -2
- package/src/schemas/metadata/MetadataProperty.ts +4 -7
- package/src/schemas/metadata/MetadataTupleType.ts +1 -1
- package/src/transform.ts +35 -35
- package/src/transformers/CallExpressionTransformer.ts +5 -2
- package/src/transformers/features/json/JsonApplicationTransformer.ts +7 -4
- package/src/transformers/features/{misc/MetadataTransformer.ts → reflect/ReflectMetadataTransformer.ts} +25 -8
- package/lib/schemas/metadata/IMetadataCollection.js.map +0 -1
- package/lib/transformers/features/misc/MetadataTransformer.d.ts +0 -5
- package/lib/transformers/features/misc/MetadataTransformer.js +0 -55
- package/lib/transformers/features/misc/MetadataTransformer.js.map +0 -1
|
@@ -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
|
+
};
|
|
@@ -26,10 +26,11 @@ export const iterate_metadata_constant =
|
|
|
26
26
|
const constant: MetadataConstant = ArrayUtil.take(
|
|
27
27
|
meta.constants,
|
|
28
28
|
(elem) => elem.type === typeof value,
|
|
29
|
-
() =>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
() =>
|
|
30
|
+
MetadataConstant.create({
|
|
31
|
+
type: typeof value as "number",
|
|
32
|
+
values: [],
|
|
33
|
+
}),
|
|
33
34
|
);
|
|
34
35
|
ArrayUtil.add(
|
|
35
36
|
constant.values as Array<any>,
|
|
@@ -42,10 +43,11 @@ export const iterate_metadata_constant =
|
|
|
42
43
|
const constant: MetadataConstant = ArrayUtil.take(
|
|
43
44
|
meta.constants,
|
|
44
45
|
(elem) => elem.type === "boolean",
|
|
45
|
-
() =>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
() =>
|
|
47
|
+
MetadataConstant.create({
|
|
48
|
+
type: "boolean",
|
|
49
|
+
values: [],
|
|
50
|
+
}),
|
|
49
51
|
);
|
|
50
52
|
ArrayUtil.add(
|
|
51
53
|
constant.values as boolean[],
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
|
-
import { IMetadataConstant } from "../../../schemas/metadata/IMetadataConstant";
|
|
4
3
|
import { IMetadataTypeTag } from "../../../schemas/metadata/IMetadataTypeTag";
|
|
5
4
|
import { Metadata } from "../../../schemas/metadata/Metadata";
|
|
6
5
|
import { MetadataAtomic } from "../../../schemas/metadata/MetadataAtomic";
|
|
6
|
+
import { MetadataConstant } from "../../../schemas/metadata/MetadataConstant";
|
|
7
7
|
|
|
8
8
|
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
9
9
|
|
|
@@ -181,7 +181,7 @@ export const iterate_metadata_intersection =
|
|
|
181
181
|
elem,
|
|
182
182
|
(a, b) => a === b,
|
|
183
183
|
);
|
|
184
|
-
else meta.constants.push(
|
|
184
|
+
else meta.constants.push(MetadataConstant.create(c));
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
return true;
|
|
@@ -210,13 +210,14 @@ export const iterate_metadata_intersection =
|
|
|
210
210
|
(a, b) => a.type === b.type,
|
|
211
211
|
);
|
|
212
212
|
else
|
|
213
|
-
ArrayUtil.take<
|
|
213
|
+
ArrayUtil.take<MetadataConstant>(
|
|
214
214
|
meta.constants,
|
|
215
215
|
(x) => x.type === "boolean",
|
|
216
|
-
() =>
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
216
|
+
() =>
|
|
217
|
+
MetadataConstant.create({
|
|
218
|
+
type: "boolean",
|
|
219
|
+
values: [booleanLiteral],
|
|
220
|
+
}),
|
|
220
221
|
);
|
|
221
222
|
else if (target === "array") {
|
|
222
223
|
const name: string = arrays.values().next().value;
|
|
@@ -247,7 +248,7 @@ export const iterate_metadata_intersection =
|
|
|
247
248
|
.find((a) => a.type === target)!
|
|
248
249
|
.tags.push(tags);
|
|
249
250
|
else {
|
|
250
|
-
const constant:
|
|
251
|
+
const constant: MetadataConstant = meta.constants.find(
|
|
251
252
|
(c) => c.type === "boolean",
|
|
252
253
|
)!;
|
|
253
254
|
constant.tags ??= [];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { IMetadataApplication } from "../schemas/metadata/IMetadataApplication";
|
|
2
|
+
import { MetadataApplication } from "../schemas/metadata/MetadataApplication";
|
|
3
|
+
|
|
4
|
+
export const $from = (json: IMetadataApplication): MetadataApplication =>
|
|
5
|
+
MetadataApplication.from(json);
|
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
|
+
};
|