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,124 +1,124 @@
1
- import ts from "typescript";
2
-
3
- import { LiteralFactory } from "../../../factories/LiteralFactory";
4
- import { MetadataCollection } from "../../../factories/MetadataCollection";
5
- import { MetadataFactory } from "../../../factories/MetadataFactory";
6
-
7
- import { IJsonApplication } from "../../../schemas/json/IJsonApplication";
8
- import { Metadata } from "../../../schemas/metadata/Metadata";
9
-
10
- import { JsonApplicationProgrammer } from "../../../programmers/json/JsonApplicationProgrammer";
11
-
12
- import { ValidationPipe } from "../../../typings/ValidationPipe";
13
-
14
- import { IProject } from "../../IProject";
15
- import { TransformerError } from "../../TransformerError";
16
-
17
- export namespace JsonApplicationTransformer {
18
- export const transform =
19
- (project: IProject) =>
20
- (expression: ts.CallExpression): ts.Expression => {
21
- if (!expression.typeArguments?.length)
22
- throw new TransformerError({
23
- code: "typia.json.application",
24
- message: "no generic argument.",
25
- });
26
-
27
- //----
28
- // GET ARGUMENTS
29
- //----
30
- // VALIDATE TUPLE ARGUMENTS
31
- const top: ts.Node = expression.typeArguments[0]!;
32
- if (!ts.isTupleTypeNode(top)) return expression;
33
- else if (top.elements.some((child) => !ts.isTypeNode(child)))
34
- return expression;
35
-
36
- // GET TYPES
37
- const types: ts.Type[] = top.elements.map((child) =>
38
- project.checker.getTypeFromTypeNode(child as ts.TypeNode),
39
- );
40
- if (types.some((t) => t.isTypeParameter()))
41
- throw new TransformerError({
42
- code: "typia.json.application",
43
- message: "non-specified generic argument(s).",
44
- });
45
-
46
- // ADDITIONAL PARAMETERS
47
- const version: "3.0" | "3.1" = get_parameter<"3.0" | "3.1">({
48
- checker: project.checker,
49
- name: "Version",
50
- is: (str) => str === "3.0" || str === "3.1",
51
- cast: (str) => str as "3.0" | "3.1",
52
- default: () => "3.1",
53
- })(expression.typeArguments[1]);
54
-
55
- //----
56
- // GENERATORS
57
- //----
58
- // METADATA
59
- const collection: MetadataCollection = new MetadataCollection({
60
- replace: MetadataCollection.replace,
61
- });
62
- const results: ValidationPipe<Metadata, MetadataFactory.IError>[] =
63
- types.map((type) =>
64
- MetadataFactory.analyze(
65
- project.checker,
66
- project.context,
67
- )({
68
- escape: true,
69
- constant: true,
70
- absorb: false,
71
- validate: JsonApplicationProgrammer.validate,
72
- })(collection)(type),
73
- );
74
-
75
- // REPORT BUG IF REQUIRED
76
- const metadatas: Metadata[] = [];
77
- const errors: MetadataFactory.IError[] = [];
78
- for (const r of results) {
79
- if (r.success === false) errors.push(...r.errors);
80
- else metadatas.push(r.data);
81
- }
82
- if (errors.length)
83
- throw TransformerError.from("typia.json.application")(errors);
84
-
85
- // APPLICATION
86
- const app: IJsonApplication<any> =
87
- JsonApplicationProgrammer.write(version)(metadatas);
88
- return LiteralFactory.generate(app);
89
- };
90
-
91
- const get_parameter =
92
- <Value>(props: {
93
- checker: ts.TypeChecker;
94
- name: string;
95
- is: (value: string) => boolean;
96
- cast: (value: string) => Value;
97
- default: () => Value;
98
- }) =>
99
- (node: ts.TypeNode | undefined): Value => {
100
- if (!node) return props.default();
101
-
102
- // CHECK LITERAL TYPE
103
- const type: ts.Type = props.checker.getTypeFromTypeNode(node);
104
- if (
105
- !type.isLiteral() &&
106
- (type.getFlags() & ts.TypeFlags.BooleanLiteral) === 0
107
- )
108
- throw new TransformerError({
109
- code: "typia.json.application",
110
- message: `generic argument "${props.name}" must be constant.`,
111
- });
112
-
113
- // GET VALUE AND VALIDATE IT
114
- const value = type.isLiteral()
115
- ? type.value
116
- : props.checker.typeToString(type);
117
- if (typeof value !== "string" || props.is(value) === false)
118
- throw new TransformerError({
119
- code: "typia.json.application",
120
- message: `invalid value on generic argument "${props.name}".`,
121
- });
122
- return props.cast(value);
123
- };
124
- }
1
+ import ts from "typescript";
2
+
3
+ import { LiteralFactory } from "../../../factories/LiteralFactory";
4
+ import { MetadataCollection } from "../../../factories/MetadataCollection";
5
+ import { MetadataFactory } from "../../../factories/MetadataFactory";
6
+
7
+ import { IJsonApplication } from "../../../schemas/json/IJsonApplication";
8
+ import { Metadata } from "../../../schemas/metadata/Metadata";
9
+
10
+ import { JsonApplicationProgrammer } from "../../../programmers/json/JsonApplicationProgrammer";
11
+
12
+ import { ValidationPipe } from "../../../typings/ValidationPipe";
13
+
14
+ import { IProject } from "../../IProject";
15
+ import { TransformerError } from "../../TransformerError";
16
+
17
+ export namespace JsonApplicationTransformer {
18
+ export const transform =
19
+ (project: IProject) =>
20
+ (expression: ts.CallExpression): ts.Expression => {
21
+ if (!expression.typeArguments?.length)
22
+ throw new TransformerError({
23
+ code: "typia.json.application",
24
+ message: "no generic argument.",
25
+ });
26
+
27
+ //----
28
+ // GET ARGUMENTS
29
+ //----
30
+ // VALIDATE TUPLE ARGUMENTS
31
+ const top: ts.Node = expression.typeArguments[0]!;
32
+ if (!ts.isTupleTypeNode(top)) return expression;
33
+ else if (top.elements.some((child) => !ts.isTypeNode(child)))
34
+ return expression;
35
+
36
+ // GET TYPES
37
+ const types: ts.Type[] = top.elements.map((child) =>
38
+ project.checker.getTypeFromTypeNode(child as ts.TypeNode),
39
+ );
40
+ if (types.some((t) => t.isTypeParameter()))
41
+ throw new TransformerError({
42
+ code: "typia.json.application",
43
+ message: "non-specified generic argument(s).",
44
+ });
45
+
46
+ // ADDITIONAL PARAMETERS
47
+ const version: "3.0" | "3.1" = get_parameter<"3.0" | "3.1">({
48
+ checker: project.checker,
49
+ name: "Version",
50
+ is: (str) => str === "3.0" || str === "3.1",
51
+ cast: (str) => str as "3.0" | "3.1",
52
+ default: () => "3.1",
53
+ })(expression.typeArguments[1]);
54
+
55
+ //----
56
+ // GENERATORS
57
+ //----
58
+ // METADATA
59
+ const collection: MetadataCollection = new MetadataCollection({
60
+ replace: MetadataCollection.replace,
61
+ });
62
+ const results: ValidationPipe<Metadata, MetadataFactory.IError>[] =
63
+ types.map((type) =>
64
+ MetadataFactory.analyze(
65
+ project.checker,
66
+ project.context,
67
+ )({
68
+ escape: true,
69
+ constant: true,
70
+ absorb: false,
71
+ validate: JsonApplicationProgrammer.validate,
72
+ })(collection)(type),
73
+ );
74
+
75
+ // REPORT BUG IF REQUIRED
76
+ const metadatas: Metadata[] = [];
77
+ const errors: MetadataFactory.IError[] = [];
78
+ for (const r of results) {
79
+ if (r.success === false) errors.push(...r.errors);
80
+ else metadatas.push(r.data);
81
+ }
82
+ if (errors.length)
83
+ throw TransformerError.from("typia.json.application")(errors);
84
+
85
+ // APPLICATION
86
+ const app: IJsonApplication<any> =
87
+ JsonApplicationProgrammer.write(version)(metadatas);
88
+ return LiteralFactory.generate(app);
89
+ };
90
+
91
+ const get_parameter =
92
+ <Value>(props: {
93
+ checker: ts.TypeChecker;
94
+ name: string;
95
+ is: (value: string) => boolean;
96
+ cast: (value: string) => Value;
97
+ default: () => Value;
98
+ }) =>
99
+ (node: ts.TypeNode | undefined): Value => {
100
+ if (!node) return props.default();
101
+
102
+ // CHECK LITERAL TYPE
103
+ const type: ts.Type = props.checker.getTypeFromTypeNode(node);
104
+ if (
105
+ !type.isLiteral() &&
106
+ (type.getFlags() & ts.TypeFlags.BooleanLiteral) === 0
107
+ )
108
+ throw new TransformerError({
109
+ code: "typia.json.application",
110
+ message: `generic argument "${props.name}" must be constant.`,
111
+ });
112
+
113
+ // GET VALUE AND VALIDATE IT
114
+ const value = type.isLiteral()
115
+ ? type.value
116
+ : props.checker.typeToString(type);
117
+ if (typeof value !== "string" || props.is(value) === false)
118
+ throw new TransformerError({
119
+ code: "typia.json.application",
120
+ message: `invalid value on generic argument "${props.name}".`,
121
+ });
122
+ return props.cast(value);
123
+ };
124
+ }
@@ -1,32 +1,32 @@
1
- import ts from "typescript";
2
-
3
- import { MiscLiteralsProgrammer } from "../../../programmers/misc/MiscLiteralsProgrammer";
4
-
5
- import { IProject } from "../../IProject";
6
- import { TransformerError } from "../../TransformerError";
7
-
8
- export namespace MiscLiteralsTransformer {
9
- export const transform =
10
- (project: IProject) =>
11
- (expression: ts.CallExpression): ts.Expression => {
12
- // CHECK GENERIC ARGUMENT EXISTENCE
13
- if (!expression.typeArguments?.[0])
14
- throw new TransformerError({
15
- code: "typia.misc.literals",
16
- message: "generic argument is not specified.",
17
- });
18
-
19
- // GET TYPE INFO
20
- const node: ts.TypeNode = expression.typeArguments[0];
21
- const type: ts.Type = project.checker.getTypeFromTypeNode(node);
22
-
23
- if (type.isTypeParameter())
24
- throw new TransformerError({
25
- code: "typia.misc.literals",
26
- message: "non-specified generic argument.",
27
- });
28
-
29
- // DO TRANSFORM
30
- return MiscLiteralsProgrammer.write(project)(type);
31
- };
32
- }
1
+ import ts from "typescript";
2
+
3
+ import { MiscLiteralsProgrammer } from "../../../programmers/misc/MiscLiteralsProgrammer";
4
+
5
+ import { IProject } from "../../IProject";
6
+ import { TransformerError } from "../../TransformerError";
7
+
8
+ export namespace MiscLiteralsTransformer {
9
+ export const transform =
10
+ (project: IProject) =>
11
+ (expression: ts.CallExpression): ts.Expression => {
12
+ // CHECK GENERIC ARGUMENT EXISTENCE
13
+ if (!expression.typeArguments?.[0])
14
+ throw new TransformerError({
15
+ code: "typia.misc.literals",
16
+ message: "generic argument is not specified.",
17
+ });
18
+
19
+ // GET TYPE INFO
20
+ const node: ts.TypeNode = expression.typeArguments[0];
21
+ const type: ts.Type = project.checker.getTypeFromTypeNode(node);
22
+
23
+ if (type.isTypeParameter())
24
+ throw new TransformerError({
25
+ code: "typia.misc.literals",
26
+ message: "non-specified generic argument.",
27
+ });
28
+
29
+ // DO TRANSFORM
30
+ return MiscLiteralsProgrammer.write(project)(type);
31
+ };
32
+ }
@@ -1,33 +1,33 @@
1
- import ts from "typescript";
2
-
3
- import { ProtobufMessageProgrammer } from "../../../programmers/protobuf/ProtobufMessageProgrammer";
4
-
5
- import { IProject } from "../../IProject";
6
- import { TransformerError } from "../../TransformerError";
7
-
8
- export namespace ProtobufMessageTransformer {
9
- export const transform =
10
- (project: IProject) =>
11
- (_modulo: ts.LeftHandSideExpression) =>
12
- (expression: ts.CallExpression): ts.Expression => {
13
- // CHECK GENERIC ARGUMENT EXISTENCE
14
- if (!expression.typeArguments || !expression.typeArguments[0])
15
- throw new TransformerError({
16
- code: "typia.protobuf.message",
17
- message: "generic argument is not specified.",
18
- });
19
-
20
- // GET TYPE INFO
21
- const type: ts.Type = project.checker.getTypeFromTypeNode(
22
- expression.typeArguments[0],
23
- );
24
- if (type.isTypeParameter())
25
- throw new TransformerError({
26
- code: "tyipa.protobuf.message",
27
- message: "non-specified generic argument.",
28
- });
29
-
30
- // DO TRANSFORM
31
- return ProtobufMessageProgrammer.write(project)(type);
32
- };
33
- }
1
+ import ts from "typescript";
2
+
3
+ import { ProtobufMessageProgrammer } from "../../../programmers/protobuf/ProtobufMessageProgrammer";
4
+
5
+ import { IProject } from "../../IProject";
6
+ import { TransformerError } from "../../TransformerError";
7
+
8
+ export namespace ProtobufMessageTransformer {
9
+ export const transform =
10
+ (project: IProject) =>
11
+ (_modulo: ts.LeftHandSideExpression) =>
12
+ (expression: ts.CallExpression): ts.Expression => {
13
+ // CHECK GENERIC ARGUMENT EXISTENCE
14
+ if (!expression.typeArguments || !expression.typeArguments[0])
15
+ throw new TransformerError({
16
+ code: "typia.protobuf.message",
17
+ message: "generic argument is not specified.",
18
+ });
19
+
20
+ // GET TYPE INFO
21
+ const type: ts.Type = project.checker.getTypeFromTypeNode(
22
+ expression.typeArguments[0],
23
+ );
24
+ if (type.isTypeParameter())
25
+ throw new TransformerError({
26
+ code: "tyipa.protobuf.message",
27
+ message: "non-specified generic argument.",
28
+ });
29
+
30
+ // DO TRANSFORM
31
+ return ProtobufMessageProgrammer.write(project)(type);
32
+ };
33
+ }
@@ -1,62 +1,62 @@
1
- import ts from "typescript";
2
-
3
- import { LiteralFactory } from "../../../factories/LiteralFactory";
4
- import { MetadataCollection } from "../../../factories/MetadataCollection";
5
- import { MetadataFactory } from "../../../factories/MetadataFactory";
6
-
7
- import { IMetadataApplication } from "../../../schemas/metadata/IMetadataApplication";
8
- import { Metadata } from "../../../schemas/metadata/Metadata";
9
-
10
- import { IProject } from "../../IProject";
11
- import { TransformerError } from "../../TransformerError";
12
-
13
- export namespace ReflectMetadataTransformer {
14
- export const transform =
15
- (project: IProject) =>
16
- (expression: ts.CallExpression): ts.Expression => {
17
- if (!expression.typeArguments?.length)
18
- throw new TransformerError({
19
- code: "typia.reflect.metadata",
20
- message: "no generic argument.",
21
- });
22
-
23
- // VALIDATE TUPLE ARGUMENTS
24
- const top: ts.Node = expression.typeArguments[0]!;
25
- if (!ts.isTupleTypeNode(top)) return expression;
26
- else if (top.elements.some((child) => !ts.isTypeNode(child)))
27
- return expression;
28
-
29
- // GET TYPES
30
- const types: ts.Type[] = top.elements.map((child) =>
31
- project.checker.getTypeFromTypeNode(child as ts.TypeNode),
32
- );
33
- if (types.some((t) => t.isTypeParameter()))
34
- throw new TransformerError({
35
- code: "typia.reflect.metadata",
36
- message: "non-specified generic argument(s).",
37
- });
38
-
39
- // METADATA
40
- const collection: MetadataCollection = new MetadataCollection();
41
- const metadatas: Array<Metadata> = types.map((type) => {
42
- const result = MetadataFactory.analyze(
43
- project.checker,
44
- project.context,
45
- )({
46
- escape: true,
47
- constant: true,
48
- absorb: true,
49
- })(collection)(type);
50
- if (result.success === false)
51
- throw TransformerError.from("typia.reflect.metadata")(result.errors);
52
- return result.data;
53
- });
54
-
55
- // CONVERT TO PRIMITIVE TYPE
56
- const app: IMetadataApplication = {
57
- metadatas: metadatas.map((metadata) => metadata.toJSON()),
58
- components: collection.toJSON(),
59
- };
60
- return LiteralFactory.generate(app);
61
- };
62
- }
1
+ import ts from "typescript";
2
+
3
+ import { LiteralFactory } from "../../../factories/LiteralFactory";
4
+ import { MetadataCollection } from "../../../factories/MetadataCollection";
5
+ import { MetadataFactory } from "../../../factories/MetadataFactory";
6
+
7
+ import { IMetadataApplication } from "../../../schemas/metadata/IMetadataApplication";
8
+ import { Metadata } from "../../../schemas/metadata/Metadata";
9
+
10
+ import { IProject } from "../../IProject";
11
+ import { TransformerError } from "../../TransformerError";
12
+
13
+ export namespace ReflectMetadataTransformer {
14
+ export const transform =
15
+ (project: IProject) =>
16
+ (expression: ts.CallExpression): ts.Expression => {
17
+ if (!expression.typeArguments?.length)
18
+ throw new TransformerError({
19
+ code: "typia.reflect.metadata",
20
+ message: "no generic argument.",
21
+ });
22
+
23
+ // VALIDATE TUPLE ARGUMENTS
24
+ const top: ts.Node = expression.typeArguments[0]!;
25
+ if (!ts.isTupleTypeNode(top)) return expression;
26
+ else if (top.elements.some((child) => !ts.isTypeNode(child)))
27
+ return expression;
28
+
29
+ // GET TYPES
30
+ const types: ts.Type[] = top.elements.map((child) =>
31
+ project.checker.getTypeFromTypeNode(child as ts.TypeNode),
32
+ );
33
+ if (types.some((t) => t.isTypeParameter()))
34
+ throw new TransformerError({
35
+ code: "typia.reflect.metadata",
36
+ message: "non-specified generic argument(s).",
37
+ });
38
+
39
+ // METADATA
40
+ const collection: MetadataCollection = new MetadataCollection();
41
+ const metadatas: Array<Metadata> = types.map((type) => {
42
+ const result = MetadataFactory.analyze(
43
+ project.checker,
44
+ project.context,
45
+ )({
46
+ escape: true,
47
+ constant: true,
48
+ absorb: true,
49
+ })(collection)(type);
50
+ if (result.success === false)
51
+ throw TransformerError.from("typia.reflect.metadata")(result.errors);
52
+ return result.data;
53
+ });
54
+
55
+ // CONVERT TO PRIMITIVE TYPE
56
+ const app: IMetadataApplication = {
57
+ metadatas: metadatas.map((metadata) => metadata.toJSON()),
58
+ components: collection.toJSON(),
59
+ };
60
+ return LiteralFactory.generate(app);
61
+ };
62
+ }