typia 6.7.2 → 6.8.0-dev.20240811

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.
Files changed (63) hide show
  1. package/lib/programmers/internal/application_bigint.d.ts +1 -0
  2. package/lib/programmers/internal/application_bigint.js +14 -0
  3. package/lib/programmers/internal/application_bigint.js.map +1 -0
  4. package/lib/programmers/internal/application_v30_schema.js +10 -12
  5. package/lib/programmers/internal/application_v30_schema.js.map +1 -1
  6. package/lib/programmers/internal/application_v31_constant.js +3 -1
  7. package/lib/programmers/internal/application_v31_constant.js.map +1 -1
  8. package/lib/programmers/internal/application_v31_schema.js +10 -12
  9. package/lib/programmers/internal/application_v31_schema.js.map +1 -1
  10. package/lib/tags/Constant.d.ts +2 -2
  11. package/lib/tags/Default.d.ts +5 -1
  12. package/lib/tags/ExclusiveMaximum.d.ts +9 -5
  13. package/lib/tags/ExclusiveMinimum.d.ts +9 -5
  14. package/lib/tags/JsonSchemaPlugin.d.ts +1 -1
  15. package/lib/tags/Maximum.d.ts +8 -5
  16. package/lib/tags/Minimum.d.ts +8 -5
  17. package/lib/tags/MultipleOf.d.ts +7 -4
  18. package/package.json +2 -2
  19. package/src/factories/CommentFactory.ts +79 -79
  20. package/src/factories/MetadataCollection.ts +274 -274
  21. package/src/factories/MetadataFactory.ts +272 -272
  22. package/src/factories/StatementFactory.ts +74 -74
  23. package/src/factories/TypeFactory.ts +118 -118
  24. package/src/factories/internal/metadata/emplace_metadata_array_type.ts +42 -42
  25. package/src/factories/internal/metadata/emplace_metadata_object.ts +176 -176
  26. package/src/factories/internal/metadata/iterate_metadata.ts +94 -94
  27. package/src/factories/internal/metadata/iterate_metadata_array.ts +63 -63
  28. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +62 -62
  29. package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
  30. package/src/factories/internal/metadata/iterate_metadata_constant.ts +76 -76
  31. package/src/factories/internal/metadata/iterate_metadata_intersection.ts +213 -213
  32. package/src/factories/internal/metadata/iterate_metadata_map.ts +50 -50
  33. package/src/factories/internal/metadata/iterate_metadata_native.ts +220 -220
  34. package/src/factories/internal/metadata/iterate_metadata_object.ts +33 -33
  35. package/src/factories/internal/metadata/iterate_metadata_set.ts +41 -41
  36. package/src/factories/internal/metadata/iterate_metadata_template.ts +44 -44
  37. package/src/factories/internal/metadata/iterate_metadata_union.ts +27 -27
  38. package/src/programmers/internal/application_bigint.ts +25 -0
  39. package/src/programmers/internal/application_v30_alias.ts +52 -52
  40. package/src/programmers/internal/application_v30_object.ts +149 -149
  41. package/src/programmers/internal/application_v30_schema.ts +162 -159
  42. package/src/programmers/internal/application_v30_tuple.ts +33 -33
  43. package/src/programmers/internal/application_v31_constant.ts +4 -1
  44. package/src/programmers/internal/application_v31_schema.ts +159 -157
  45. package/src/programmers/json/JsonApplicationProgrammer.ts +82 -82
  46. package/src/schemas/metadata/IMetadataConstantValue.ts +11 -11
  47. package/src/schemas/metadata/IMetadataTemplate.ts +7 -7
  48. package/src/tags/Constant.ts +2 -2
  49. package/src/tags/Default.ts +7 -3
  50. package/src/tags/ExclusiveMaximum.ts +12 -6
  51. package/src/tags/ExclusiveMinimum.ts +12 -6
  52. package/src/tags/JsonSchemaPlugin.ts +1 -1
  53. package/src/tags/Maximum.ts +9 -8
  54. package/src/tags/Minimum.ts +9 -8
  55. package/src/tags/MultipleOf.ts +9 -8
  56. package/src/tags/Type.ts +32 -32
  57. package/src/transformers/FileTransformer.ts +91 -91
  58. package/src/transformers/features/CreateRandomTransformer.ts +40 -40
  59. package/src/transformers/features/RandomTransformer.ts +44 -44
  60. package/src/transformers/features/json/JsonApplicationTransformer.ts +124 -124
  61. package/src/transformers/features/misc/MiscLiteralsTransformer.ts +32 -32
  62. package/src/transformers/features/protobuf/ProtobufMessageTransformer.ts +33 -33
  63. package/src/transformers/features/reflect/ReflectMetadataTransformer.ts +62 -62
@@ -1,74 +1,74 @@
1
- import ts from "typescript";
2
-
3
- import { TypeFactory } from "./TypeFactory";
4
-
5
- export namespace StatementFactory {
6
- export const mut = (name: string, initializer?: ts.Expression) =>
7
- ts.factory.createVariableStatement(
8
- undefined,
9
- ts.factory.createVariableDeclarationList(
10
- [
11
- ts.factory.createVariableDeclaration(
12
- name,
13
- undefined,
14
- initializer === undefined ? TypeFactory.keyword("any") : undefined,
15
- initializer,
16
- ),
17
- ],
18
- ts.NodeFlags.Let,
19
- ),
20
- );
21
-
22
- export const constant = (name: string, initializer?: ts.Expression) =>
23
- ts.factory.createVariableStatement(
24
- undefined,
25
- ts.factory.createVariableDeclarationList(
26
- [
27
- ts.factory.createVariableDeclaration(
28
- name,
29
- undefined,
30
- undefined,
31
- initializer,
32
- ),
33
- ],
34
- ts.NodeFlags.Const,
35
- ),
36
- );
37
-
38
- export const entry = (key: string) => (value: string) =>
39
- ts.factory.createVariableDeclarationList(
40
- [
41
- ts.factory.createVariableDeclaration(
42
- ts.factory.createArrayBindingPattern([
43
- ts.factory.createBindingElement(
44
- undefined,
45
- undefined,
46
- ts.factory.createIdentifier(key),
47
- undefined,
48
- ),
49
- ts.factory.createBindingElement(
50
- undefined,
51
- undefined,
52
- ts.factory.createIdentifier(value),
53
- undefined,
54
- ),
55
- ]),
56
- undefined,
57
- undefined,
58
- undefined,
59
- ),
60
- ],
61
- ts.NodeFlags.Const,
62
- );
63
-
64
- export const transpile = (script: string) =>
65
- ts.factory.createExpressionStatement(
66
- ts.factory.createIdentifier(ts.transpile(script)),
67
- );
68
-
69
- export const block = (expression: ts.Expression) =>
70
- ts.factory.createBlock(
71
- [ts.factory.createExpressionStatement(expression)],
72
- true,
73
- );
74
- }
1
+ import ts from "typescript";
2
+
3
+ import { TypeFactory } from "./TypeFactory";
4
+
5
+ export namespace StatementFactory {
6
+ export const mut = (name: string, initializer?: ts.Expression) =>
7
+ ts.factory.createVariableStatement(
8
+ undefined,
9
+ ts.factory.createVariableDeclarationList(
10
+ [
11
+ ts.factory.createVariableDeclaration(
12
+ name,
13
+ undefined,
14
+ initializer === undefined ? TypeFactory.keyword("any") : undefined,
15
+ initializer,
16
+ ),
17
+ ],
18
+ ts.NodeFlags.Let,
19
+ ),
20
+ );
21
+
22
+ export const constant = (name: string, initializer?: ts.Expression) =>
23
+ ts.factory.createVariableStatement(
24
+ undefined,
25
+ ts.factory.createVariableDeclarationList(
26
+ [
27
+ ts.factory.createVariableDeclaration(
28
+ name,
29
+ undefined,
30
+ undefined,
31
+ initializer,
32
+ ),
33
+ ],
34
+ ts.NodeFlags.Const,
35
+ ),
36
+ );
37
+
38
+ export const entry = (key: string) => (value: string) =>
39
+ ts.factory.createVariableDeclarationList(
40
+ [
41
+ ts.factory.createVariableDeclaration(
42
+ ts.factory.createArrayBindingPattern([
43
+ ts.factory.createBindingElement(
44
+ undefined,
45
+ undefined,
46
+ ts.factory.createIdentifier(key),
47
+ undefined,
48
+ ),
49
+ ts.factory.createBindingElement(
50
+ undefined,
51
+ undefined,
52
+ ts.factory.createIdentifier(value),
53
+ undefined,
54
+ ),
55
+ ]),
56
+ undefined,
57
+ undefined,
58
+ undefined,
59
+ ),
60
+ ],
61
+ ts.NodeFlags.Const,
62
+ );
63
+
64
+ export const transpile = (script: string) =>
65
+ ts.factory.createExpressionStatement(
66
+ ts.factory.createIdentifier(ts.transpile(script)),
67
+ );
68
+
69
+ export const block = (expression: ts.Expression) =>
70
+ ts.factory.createBlock(
71
+ [ts.factory.createExpressionStatement(expression)],
72
+ true,
73
+ );
74
+ }
@@ -1,118 +1,118 @@
1
- import ts from "typescript";
2
-
3
- export namespace TypeFactory {
4
- export const isFunction = (type: ts.Type): boolean =>
5
- getFunction(type) !== null;
6
-
7
- const getFunction = (type: ts.Type) => {
8
- const node = type.symbol?.declarations?.[0];
9
- if (node === undefined) return null;
10
-
11
- return ts.isFunctionLike(node)
12
- ? node
13
- : ts.isPropertyAssignment(node) || ts.isPropertyDeclaration(node)
14
- ? ts.isFunctionLike(node.initializer)
15
- ? node.initializer
16
- : null
17
- : null;
18
- };
19
-
20
- export const getReturnType =
21
- (checker: ts.TypeChecker) =>
22
- (type: ts.Type) =>
23
- (name: string): ts.Type | null => {
24
- // FIND TO-JSON METHOD
25
- const symbol: ts.Symbol | undefined = type.getProperty(name);
26
- if (!symbol) return null;
27
- else if (!symbol.valueDeclaration) return null;
28
-
29
- // GET FUNCTION DECLARATION
30
- const functor: ts.Type = checker.getTypeOfSymbolAtLocation(
31
- symbol,
32
- symbol.valueDeclaration,
33
- );
34
-
35
- // RETURNS THE RETURN-TYPE
36
- const signature: ts.Signature | undefined = checker.getSignaturesOfType(
37
- functor,
38
- ts.SignatureKind.Call,
39
- )[0];
40
- return signature ? signature.getReturnType() : null;
41
- };
42
-
43
- export const getFullName =
44
- (checker: ts.TypeChecker) =>
45
- (type: ts.Type, symbol?: ts.Symbol): string => {
46
- // PRIMITIVE
47
- symbol ??= type.aliasSymbol ?? type.getSymbol();
48
- if (symbol === undefined) return checker.typeToString(type);
49
-
50
- // UNION OR INTERSECT
51
- if (type.aliasSymbol === undefined && type.isUnionOrIntersection()) {
52
- const joiner: string = type.isIntersection() ? " & " : " | ";
53
- return type.types
54
- .map((child) => getFullName(checker)(child))
55
- .join(joiner);
56
- }
57
-
58
- //----
59
- // SPECIALIZATION
60
- //----
61
- const name: string = get_name(symbol);
62
-
63
- // CHECK GENERIC
64
- const generic: readonly ts.Type[] = type.aliasSymbol
65
- ? type.aliasTypeArguments || []
66
- : checker.getTypeArguments(type as ts.TypeReference);
67
- return generic.length
68
- ? name === "Promise"
69
- ? getFullName(checker)(generic[0]!)
70
- : `${name}<${generic
71
- .map((child) => getFullName(checker)(child))
72
- .join(", ")}>`
73
- : name;
74
- };
75
-
76
- const explore_name =
77
- (decl: ts.Node) =>
78
- (name: string): string =>
79
- ts.isModuleBlock(decl)
80
- ? explore_name(decl.parent.parent)(
81
- `${decl.parent.name.getFullText().trim()}.${name}`,
82
- )
83
- : name;
84
-
85
- const get_name = (symbol: ts.Symbol): string => {
86
- const parent = symbol.getDeclarations()?.[0]?.parent;
87
- return parent
88
- ? explore_name(parent)(symbol.escapedName.toString())
89
- : "__type";
90
- };
91
-
92
- export const keyword = (
93
- type:
94
- | "void"
95
- | "any"
96
- | "unknown"
97
- | "boolean"
98
- | "number"
99
- | "bigint"
100
- | "string",
101
- ) => {
102
- return ts.factory.createKeywordTypeNode(
103
- type === "void"
104
- ? ts.SyntaxKind.VoidKeyword
105
- : type === "any"
106
- ? ts.SyntaxKind.AnyKeyword
107
- : type === "unknown"
108
- ? ts.SyntaxKind.UnknownKeyword
109
- : type === "boolean"
110
- ? ts.SyntaxKind.BooleanKeyword
111
- : type === "number"
112
- ? ts.SyntaxKind.NumberKeyword
113
- : type === "bigint"
114
- ? ts.SyntaxKind.BigIntKeyword
115
- : ts.SyntaxKind.StringKeyword,
116
- );
117
- };
118
- }
1
+ import ts from "typescript";
2
+
3
+ export namespace TypeFactory {
4
+ export const isFunction = (type: ts.Type): boolean =>
5
+ getFunction(type) !== null;
6
+
7
+ const getFunction = (type: ts.Type) => {
8
+ const node = type.symbol?.declarations?.[0];
9
+ if (node === undefined) return null;
10
+
11
+ return ts.isFunctionLike(node)
12
+ ? node
13
+ : ts.isPropertyAssignment(node) || ts.isPropertyDeclaration(node)
14
+ ? ts.isFunctionLike(node.initializer)
15
+ ? node.initializer
16
+ : null
17
+ : null;
18
+ };
19
+
20
+ export const getReturnType =
21
+ (checker: ts.TypeChecker) =>
22
+ (type: ts.Type) =>
23
+ (name: string): ts.Type | null => {
24
+ // FIND TO-JSON METHOD
25
+ const symbol: ts.Symbol | undefined = type.getProperty(name);
26
+ if (!symbol) return null;
27
+ else if (!symbol.valueDeclaration) return null;
28
+
29
+ // GET FUNCTION DECLARATION
30
+ const functor: ts.Type = checker.getTypeOfSymbolAtLocation(
31
+ symbol,
32
+ symbol.valueDeclaration,
33
+ );
34
+
35
+ // RETURNS THE RETURN-TYPE
36
+ const signature: ts.Signature | undefined = checker.getSignaturesOfType(
37
+ functor,
38
+ ts.SignatureKind.Call,
39
+ )[0];
40
+ return signature ? signature.getReturnType() : null;
41
+ };
42
+
43
+ export const getFullName =
44
+ (checker: ts.TypeChecker) =>
45
+ (type: ts.Type, symbol?: ts.Symbol): string => {
46
+ // PRIMITIVE
47
+ symbol ??= type.aliasSymbol ?? type.getSymbol();
48
+ if (symbol === undefined) return checker.typeToString(type);
49
+
50
+ // UNION OR INTERSECT
51
+ if (type.aliasSymbol === undefined && type.isUnionOrIntersection()) {
52
+ const joiner: string = type.isIntersection() ? " & " : " | ";
53
+ return type.types
54
+ .map((child) => getFullName(checker)(child))
55
+ .join(joiner);
56
+ }
57
+
58
+ //----
59
+ // SPECIALIZATION
60
+ //----
61
+ const name: string = get_name(symbol);
62
+
63
+ // CHECK GENERIC
64
+ const generic: readonly ts.Type[] = type.aliasSymbol
65
+ ? type.aliasTypeArguments || []
66
+ : checker.getTypeArguments(type as ts.TypeReference);
67
+ return generic.length
68
+ ? name === "Promise"
69
+ ? getFullName(checker)(generic[0]!)
70
+ : `${name}<${generic
71
+ .map((child) => getFullName(checker)(child))
72
+ .join(", ")}>`
73
+ : name;
74
+ };
75
+
76
+ const explore_name =
77
+ (decl: ts.Node) =>
78
+ (name: string): string =>
79
+ ts.isModuleBlock(decl)
80
+ ? explore_name(decl.parent.parent)(
81
+ `${decl.parent.name.getFullText().trim()}.${name}`,
82
+ )
83
+ : name;
84
+
85
+ const get_name = (symbol: ts.Symbol): string => {
86
+ const parent = symbol.getDeclarations()?.[0]?.parent;
87
+ return parent
88
+ ? explore_name(parent)(symbol.escapedName.toString())
89
+ : "__type";
90
+ };
91
+
92
+ export const keyword = (
93
+ type:
94
+ | "void"
95
+ | "any"
96
+ | "unknown"
97
+ | "boolean"
98
+ | "number"
99
+ | "bigint"
100
+ | "string",
101
+ ) => {
102
+ return ts.factory.createKeywordTypeNode(
103
+ type === "void"
104
+ ? ts.SyntaxKind.VoidKeyword
105
+ : type === "any"
106
+ ? ts.SyntaxKind.AnyKeyword
107
+ : type === "unknown"
108
+ ? ts.SyntaxKind.UnknownKeyword
109
+ : type === "boolean"
110
+ ? ts.SyntaxKind.BooleanKeyword
111
+ : type === "number"
112
+ ? ts.SyntaxKind.NumberKeyword
113
+ : type === "bigint"
114
+ ? ts.SyntaxKind.BigIntKeyword
115
+ : ts.SyntaxKind.StringKeyword,
116
+ );
117
+ };
118
+ }
@@ -1,42 +1,42 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../../schemas/metadata/Metadata";
4
- import { MetadataArrayType } from "../../../schemas/metadata/MetadataArrayType";
5
-
6
- import { ArrayUtil } from "../../../utils/ArrayUtil";
7
-
8
- import { MetadataCollection } from "../../MetadataCollection";
9
- import { MetadataFactory } from "../../MetadataFactory";
10
- import { explore_metadata } from "./explore_metadata";
11
-
12
- export const emplace_metadata_array_type =
13
- (checker: ts.TypeChecker) =>
14
- (options: MetadataFactory.IOptions) =>
15
- (collection: MetadataCollection) =>
16
- (errors: MetadataFactory.IError[]) =>
17
- (
18
- aliasType: ts.Type,
19
- arrayType: ts.Type,
20
- nullable: boolean,
21
- explore: MetadataFactory.IExplore,
22
- ): MetadataArrayType => {
23
- // CHECK EXISTENCE
24
- const [array, newbie, setValue] = collection.emplaceArray(
25
- checker,
26
- aliasType,
27
- );
28
- ArrayUtil.add(array.nullables, nullable);
29
- if (newbie === false) return array;
30
-
31
- // CONSTRUCT VALUE TYPE
32
- const value: Metadata = explore_metadata(checker)(options)(collection)(
33
- errors,
34
- )(arrayType.getNumberIndexType()!, {
35
- ...explore,
36
- escaped: false,
37
- aliased: false,
38
- });
39
- setValue(value);
40
-
41
- return array;
42
- };
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../../schemas/metadata/Metadata";
4
+ import { MetadataArrayType } from "../../../schemas/metadata/MetadataArrayType";
5
+
6
+ import { ArrayUtil } from "../../../utils/ArrayUtil";
7
+
8
+ import { MetadataCollection } from "../../MetadataCollection";
9
+ import { MetadataFactory } from "../../MetadataFactory";
10
+ import { explore_metadata } from "./explore_metadata";
11
+
12
+ export const emplace_metadata_array_type =
13
+ (checker: ts.TypeChecker) =>
14
+ (options: MetadataFactory.IOptions) =>
15
+ (collection: MetadataCollection) =>
16
+ (errors: MetadataFactory.IError[]) =>
17
+ (
18
+ aliasType: ts.Type,
19
+ arrayType: ts.Type,
20
+ nullable: boolean,
21
+ explore: MetadataFactory.IExplore,
22
+ ): MetadataArrayType => {
23
+ // CHECK EXISTENCE
24
+ const [array, newbie, setValue] = collection.emplaceArray(
25
+ checker,
26
+ aliasType,
27
+ );
28
+ ArrayUtil.add(array.nullables, nullable);
29
+ if (newbie === false) return array;
30
+
31
+ // CONSTRUCT VALUE TYPE
32
+ const value: Metadata = explore_metadata(checker)(options)(collection)(
33
+ errors,
34
+ )(arrayType.getNumberIndexType()!, {
35
+ ...explore,
36
+ escaped: false,
37
+ aliased: false,
38
+ });
39
+ setValue(value);
40
+
41
+ return array;
42
+ };