typia 4.0.0 → 4.0.1-dev.20230604

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 (87) hide show
  1. package/lib/programmers/ApplicationProgrammer.js +1 -1
  2. package/lib/programmers/internal/application_array.js +19 -41
  3. package/lib/programmers/internal/application_array.js.map +1 -1
  4. package/lib/programmers/internal/application_definition.d.ts +1 -1
  5. package/lib/programmers/internal/application_definition.js +8 -8
  6. package/lib/programmers/internal/application_definition.js.map +1 -1
  7. package/lib/programmers/internal/application_native.js +3 -3
  8. package/lib/programmers/internal/application_object.js +4 -4
  9. package/lib/programmers/internal/application_schema.js +3 -3
  10. package/lib/programmers/internal/application_schema.js.map +1 -1
  11. package/lib/programmers/internal/application_tuple.js +8 -30
  12. package/lib/programmers/internal/application_tuple.js.map +1 -1
  13. package/lib/schemas/IJsonComponents.d.ts +1 -12
  14. package/lib/schemas/IJsonSchema.d.ts +1 -1
  15. package/package.json +1 -1
  16. package/src/IRandomGenerator.ts +34 -34
  17. package/src/factories/IdentifierFactory.ts +65 -65
  18. package/src/factories/MetadataCollection.ts +254 -254
  19. package/src/factories/MetadataFactory.ts +40 -40
  20. package/src/factories/MetadataTagFactory.ts +300 -300
  21. package/src/factories/internal/metadata/emplace_metadata_array.ts +34 -34
  22. package/src/factories/internal/metadata/emplace_metadata_definition.ts +35 -35
  23. package/src/factories/internal/metadata/emplace_metadata_object.ts +142 -142
  24. package/src/factories/internal/metadata/emplace_metadata_tuple.ts +50 -50
  25. package/src/factories/internal/metadata/explore_metadata.ts +66 -66
  26. package/src/factories/internal/metadata/iterate_metadata.ts +77 -77
  27. package/src/factories/internal/metadata/iterate_metadata_array.ts +25 -25
  28. package/src/factories/internal/metadata/iterate_metadata_collection.ts +130 -130
  29. package/src/factories/internal/metadata/iterate_metadata_definition.ts +30 -30
  30. package/src/factories/internal/metadata/iterate_metadata_object.ts +49 -49
  31. package/src/factories/internal/metadata/iterate_metadata_sort.ts +68 -68
  32. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +24 -24
  33. package/src/factories/internal/metadata/iterate_metadata_union.ts +68 -68
  34. package/src/metadata/IMetadata.ts +27 -27
  35. package/src/metadata/IMetadataAlias.ts +12 -12
  36. package/src/metadata/IMetadataApplication.ts +7 -7
  37. package/src/metadata/IMetadataArray.ts +10 -10
  38. package/src/metadata/IMetadataCollection.ts +11 -11
  39. package/src/metadata/IMetadataDictionary.ts +14 -14
  40. package/src/metadata/IMetadataObject.ts +18 -18
  41. package/src/metadata/IMetadataProperty.ts +11 -11
  42. package/src/metadata/IMetadataTuple.ts +10 -10
  43. package/src/metadata/Metadata.ts +585 -585
  44. package/src/metadata/MetadataAlias.ts +61 -61
  45. package/src/metadata/MetadataArray.ts +52 -52
  46. package/src/metadata/MetadataObject.ts +114 -114
  47. package/src/metadata/MetadataProperty.ts +64 -64
  48. package/src/metadata/MetadataTuple.ts +53 -53
  49. package/src/programmers/ApplicationProgrammer.ts +55 -55
  50. package/src/programmers/AssertProgrammer.ts +291 -291
  51. package/src/programmers/CheckerProgrammer.ts +1182 -1182
  52. package/src/programmers/CloneProgrammer.ts +595 -595
  53. package/src/programmers/FeatureProgrammer.ts +495 -495
  54. package/src/programmers/IsProgrammer.ts +250 -250
  55. package/src/programmers/LiteralsProgrammer.ts +66 -66
  56. package/src/programmers/PruneProgrammer.ts +550 -550
  57. package/src/programmers/RandomProgrammer.ts +589 -589
  58. package/src/programmers/StringifyProgrammer.ts +990 -990
  59. package/src/programmers/ValidateProgrammer.ts +313 -313
  60. package/src/programmers/helpers/FunctionImporeter.ts +78 -78
  61. package/src/programmers/helpers/RandomJoiner.ts +173 -173
  62. package/src/programmers/helpers/UnionExplorer.ts +301 -301
  63. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  64. package/src/programmers/helpers/disable_function_importer_declare.ts +26 -26
  65. package/src/programmers/internal/JSON_SCHEMA_PREFIX.ts +1 -1
  66. package/src/programmers/internal/application_array.ts +30 -64
  67. package/src/programmers/internal/application_boolean.ts +15 -15
  68. package/src/programmers/internal/application_constant.ts +26 -26
  69. package/src/programmers/internal/application_default.ts +17 -17
  70. package/src/programmers/internal/application_definition.ts +45 -45
  71. package/src/programmers/internal/application_native.ts +39 -39
  72. package/src/programmers/internal/application_number.ts +74 -74
  73. package/src/programmers/internal/application_object.ts +167 -167
  74. package/src/programmers/internal/application_schema.ts +156 -164
  75. package/src/programmers/internal/application_tuple.ts +47 -77
  76. package/src/programmers/internal/check_union_array_like.ts +329 -329
  77. package/src/programmers/internal/feature_object_entries.ts +63 -63
  78. package/src/programmers/internal/wrap_metadata_rest_tuple.ts +16 -16
  79. package/src/schemas/IJsonApplication.ts +8 -8
  80. package/src/schemas/IJsonComponents.ts +34 -45
  81. package/src/schemas/IJsonSchema.ts +134 -134
  82. package/src/transformers/CallExpressionTransformer.ts +179 -179
  83. package/src/transformers/FileTransformer.ts +47 -47
  84. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +104 -104
  85. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +53 -53
  86. package/src/utils/ArrayUtil.ts +45 -45
  87. package/src/utils/RandomGenerator.ts +81 -81
@@ -1,78 +1,78 @@
1
- import ts from "typescript";
2
-
3
- import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
- import { StatementFactory } from "../../factories/StatementFactory";
5
- import { TypeFactory } from "../../factories/TypeFactory";
6
-
7
- export class FunctionImporter {
8
- private readonly used_: Set<string> = new Set();
9
- private readonly local_: Set<string> = new Set();
10
- private readonly unions_: Map<string, [string, ts.ArrowFunction]> =
11
- new Map();
12
- private sequence_: number = 0;
13
-
14
- public empty(): boolean {
15
- return this.used_.size === 0;
16
- }
17
-
18
- public use(name: string): ts.Identifier {
19
- this.used_.add(name);
20
- return ts.factory.createIdentifier("$" + name);
21
- }
22
-
23
- public useLocal(name: string): string {
24
- this.local_.add(name);
25
- return name;
26
- }
27
-
28
- public hasLocal(name: string): boolean {
29
- return this.local_.has(name);
30
- }
31
-
32
- public declare(modulo: ts.LeftHandSideExpression): ts.Statement[] {
33
- return [
34
- ...[...this.used_].map((name) =>
35
- StatementFactory.constant(
36
- "$" + name,
37
- IdentifierFactory.access(
38
- ts.factory.createParenthesizedExpression(
39
- ts.factory.createAsExpression(
40
- modulo,
41
- TypeFactory.keyword("any"),
42
- ),
43
- ),
44
- )(name),
45
- ),
46
- ),
47
- ...[...this.unions_.values()].map(([key, arrow]) =>
48
- StatementFactory.constant(key, arrow),
49
- ),
50
- ];
51
- }
52
-
53
- public increment(): number {
54
- return ++this.sequence_;
55
- }
56
-
57
- public emplaceUnion(
58
- prefix: string,
59
- name: string,
60
- factory: () => ts.ArrowFunction,
61
- ): string {
62
- const oldbie = this.unions_.get(name);
63
- if (oldbie) return oldbie[0];
64
-
65
- const index: number = this.unions_.size;
66
- const accessor: string = `${prefix}p${index}`;
67
-
68
- const tuple: [string, ReturnType<typeof factory>] = [accessor, null!];
69
- this.unions_.set(name, tuple);
70
- tuple[1] = factory();
71
- return accessor;
72
- }
73
-
74
- public trace(): void {
75
- console.log(...this.used_);
76
- console.log(...this.local_);
77
- }
78
- }
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
+ import { StatementFactory } from "../../factories/StatementFactory";
5
+ import { TypeFactory } from "../../factories/TypeFactory";
6
+
7
+ export class FunctionImporter {
8
+ private readonly used_: Set<string> = new Set();
9
+ private readonly local_: Set<string> = new Set();
10
+ private readonly unions_: Map<string, [string, ts.ArrowFunction]> =
11
+ new Map();
12
+ private sequence_: number = 0;
13
+
14
+ public empty(): boolean {
15
+ return this.used_.size === 0;
16
+ }
17
+
18
+ public use(name: string): ts.Identifier {
19
+ this.used_.add(name);
20
+ return ts.factory.createIdentifier("$" + name);
21
+ }
22
+
23
+ public useLocal(name: string): string {
24
+ this.local_.add(name);
25
+ return name;
26
+ }
27
+
28
+ public hasLocal(name: string): boolean {
29
+ return this.local_.has(name);
30
+ }
31
+
32
+ public declare(modulo: ts.LeftHandSideExpression): ts.Statement[] {
33
+ return [
34
+ ...[...this.used_].map((name) =>
35
+ StatementFactory.constant(
36
+ "$" + name,
37
+ IdentifierFactory.access(
38
+ ts.factory.createParenthesizedExpression(
39
+ ts.factory.createAsExpression(
40
+ modulo,
41
+ TypeFactory.keyword("any"),
42
+ ),
43
+ ),
44
+ )(name),
45
+ ),
46
+ ),
47
+ ...[...this.unions_.values()].map(([key, arrow]) =>
48
+ StatementFactory.constant(key, arrow),
49
+ ),
50
+ ];
51
+ }
52
+
53
+ public increment(): number {
54
+ return ++this.sequence_;
55
+ }
56
+
57
+ public emplaceUnion(
58
+ prefix: string,
59
+ name: string,
60
+ factory: () => ts.ArrowFunction,
61
+ ): string {
62
+ const oldbie = this.unions_.get(name);
63
+ if (oldbie) return oldbie[0];
64
+
65
+ const index: number = this.unions_.size;
66
+ const accessor: string = `${prefix}p${index}`;
67
+
68
+ const tuple: [string, ReturnType<typeof factory>] = [accessor, null!];
69
+ this.unions_.set(name, tuple);
70
+ tuple[1] = factory();
71
+ return accessor;
72
+ }
73
+
74
+ public trace(): void {
75
+ console.log(...this.used_);
76
+ console.log(...this.local_);
77
+ }
78
+ }
@@ -1,173 +1,173 @@
1
- import ts from "typescript";
2
-
3
- import { StatementFactory } from "../../factories/StatementFactory";
4
- import { TypeFactory } from "../../factories/TypeFactory";
5
-
6
- import { ICommentTag } from "../../metadata/ICommentTag";
7
- import { IMetadataTag } from "../../metadata/IMetadataTag";
8
- import { Metadata } from "../../metadata/Metadata";
9
- import { MetadataObject } from "../../metadata/MetadataObject";
10
- import { MetadataProperty } from "../../metadata/MetadataProperty";
11
-
12
- import { Escaper } from "../../utils/Escaper";
13
-
14
- import { get_comment_tags } from "../internal/get_comment_tags";
15
-
16
- export namespace RandomJoiner {
17
- export type Decoder = (
18
- meta: Metadata,
19
- tags: IMetadataTag[],
20
- comments: ICommentTag[],
21
- ) => ts.Expression;
22
-
23
- export const array =
24
- (coalesce: (method: string) => ts.Expression) =>
25
- (decoder: Decoder) =>
26
- (explore: IExplore) =>
27
- (length: ts.Expression | undefined) =>
28
- (
29
- item: Metadata,
30
- tags: IMetadataTag[],
31
- comments: ICommentTag[],
32
- ): ts.Expression => {
33
- const generator: ts.Expression = ts.factory.createCallExpression(
34
- coalesce("array"),
35
- undefined,
36
- [
37
- ts.factory.createArrowFunction(
38
- undefined,
39
- undefined,
40
- [],
41
- undefined,
42
- undefined,
43
- decoder(item, tags, comments),
44
- ),
45
- ...(length ? [length] : []),
46
- ],
47
- );
48
- if (explore.recursive === false) return generator;
49
- return ts.factory.createConditionalExpression(
50
- ts.factory.createGreaterThanEquals(
51
- ts.factory.createNumericLiteral(5),
52
- ts.factory.createIdentifier("_depth"),
53
- ),
54
- undefined,
55
- generator,
56
- undefined,
57
- ts.factory.createArrayLiteralExpression([]),
58
- );
59
- };
60
-
61
- export const tuple =
62
- (decoder: Decoder) =>
63
- (items: Metadata[], tags: IMetadataTag[], comments: ICommentTag[]) =>
64
- ts.factory.createArrayLiteralExpression(
65
- items.map((i) => decoder(i.rest ?? i, tags, comments)),
66
- true,
67
- );
68
-
69
- export const object =
70
- (coalesce: (method: string) => ts.Expression) =>
71
- (decoder: Decoder) =>
72
- (obj: MetadataObject): ts.ConciseBody => {
73
- if (obj.properties.length === 0)
74
- return ts.factory.createIdentifier("{}");
75
-
76
- // LIST UP PROPERTIES
77
- const regular = obj.properties.filter((p) => p.key.isSoleLiteral());
78
- const dynamic = obj.properties.filter(
79
- (p) => !p.key.isSoleLiteral(),
80
- );
81
-
82
- // REGULAR OBJECT
83
- const literal: ts.ObjectLiteralExpression =
84
- ts.factory.createObjectLiteralExpression(
85
- regular.map((p) => {
86
- const str: string = p.key.getSoleLiteral()!;
87
- return ts.factory.createPropertyAssignment(
88
- Escaper.variable(str)
89
- ? str
90
- : ts.factory.createStringLiteral(str),
91
- decoder(
92
- p.value,
93
- p.tags,
94
- get_comment_tags(false)(p.jsDocTags),
95
- ),
96
- );
97
- }),
98
- true,
99
- );
100
- if (dynamic.length === 0) return literal;
101
-
102
- const properties: ts.Statement[] = dynamic.map((p) =>
103
- ts.factory.createExpressionStatement(
104
- dynamicProperty(coalesce)(decoder)(p),
105
- ),
106
- );
107
- return ts.factory.createBlock(
108
- [
109
- StatementFactory.constant(
110
- "output",
111
- ts.factory.createAsExpression(
112
- literal,
113
- TypeFactory.keyword("any"),
114
- ),
115
- ),
116
- ...(obj.recursive
117
- ? [
118
- ts.factory.createIfStatement(
119
- ts.factory.createGreaterThanEquals(
120
- ts.factory.createNumericLiteral(5),
121
- ts.factory.createIdentifier("_depth"),
122
- ),
123
- ts.factory.createBlock(properties, true),
124
- ),
125
- ]
126
- : properties),
127
- ts.factory.createReturnStatement(
128
- ts.factory.createIdentifier("output"),
129
- ),
130
- ],
131
- true,
132
- );
133
- };
134
-
135
- const dynamicProperty =
136
- (coalesce: (method: string) => ts.Expression) =>
137
- (decoder: Decoder) =>
138
- (p: MetadataProperty) =>
139
- ts.factory.createCallExpression(coalesce("array"), undefined, [
140
- ts.factory.createArrowFunction(
141
- undefined,
142
- undefined,
143
- [],
144
- undefined,
145
- undefined,
146
- ts.factory.createBinaryExpression(
147
- ts.factory.createElementAccessExpression(
148
- ts.factory.createIdentifier("output"),
149
- decoder(p.key, [], []),
150
- ),
151
- ts.factory.createToken(ts.SyntaxKind.EqualsToken),
152
- decoder(
153
- p.value,
154
- p.tags,
155
- get_comment_tags(false)(p.jsDocTags),
156
- ),
157
- ),
158
- ),
159
- ts.factory.createCallExpression(
160
- coalesce("integer"),
161
- undefined,
162
- [
163
- ts.factory.createNumericLiteral(0),
164
- ts.factory.createNumericLiteral(3),
165
- ],
166
- ),
167
- ]);
168
- }
169
-
170
- interface IExplore {
171
- function: boolean;
172
- recursive: boolean;
173
- }
1
+ import ts from "typescript";
2
+
3
+ import { StatementFactory } from "../../factories/StatementFactory";
4
+ import { TypeFactory } from "../../factories/TypeFactory";
5
+
6
+ import { ICommentTag } from "../../metadata/ICommentTag";
7
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
8
+ import { Metadata } from "../../metadata/Metadata";
9
+ import { MetadataObject } from "../../metadata/MetadataObject";
10
+ import { MetadataProperty } from "../../metadata/MetadataProperty";
11
+
12
+ import { Escaper } from "../../utils/Escaper";
13
+
14
+ import { get_comment_tags } from "../internal/get_comment_tags";
15
+
16
+ export namespace RandomJoiner {
17
+ export type Decoder = (
18
+ meta: Metadata,
19
+ tags: IMetadataTag[],
20
+ comments: ICommentTag[],
21
+ ) => ts.Expression;
22
+
23
+ export const array =
24
+ (coalesce: (method: string) => ts.Expression) =>
25
+ (decoder: Decoder) =>
26
+ (explore: IExplore) =>
27
+ (length: ts.Expression | undefined) =>
28
+ (
29
+ item: Metadata,
30
+ tags: IMetadataTag[],
31
+ comments: ICommentTag[],
32
+ ): ts.Expression => {
33
+ const generator: ts.Expression = ts.factory.createCallExpression(
34
+ coalesce("array"),
35
+ undefined,
36
+ [
37
+ ts.factory.createArrowFunction(
38
+ undefined,
39
+ undefined,
40
+ [],
41
+ undefined,
42
+ undefined,
43
+ decoder(item, tags, comments),
44
+ ),
45
+ ...(length ? [length] : []),
46
+ ],
47
+ );
48
+ if (explore.recursive === false) return generator;
49
+ return ts.factory.createConditionalExpression(
50
+ ts.factory.createGreaterThanEquals(
51
+ ts.factory.createNumericLiteral(5),
52
+ ts.factory.createIdentifier("_depth"),
53
+ ),
54
+ undefined,
55
+ generator,
56
+ undefined,
57
+ ts.factory.createArrayLiteralExpression([]),
58
+ );
59
+ };
60
+
61
+ export const tuple =
62
+ (decoder: Decoder) =>
63
+ (items: Metadata[], tags: IMetadataTag[], comments: ICommentTag[]) =>
64
+ ts.factory.createArrayLiteralExpression(
65
+ items.map((i) => decoder(i.rest ?? i, tags, comments)),
66
+ true,
67
+ );
68
+
69
+ export const object =
70
+ (coalesce: (method: string) => ts.Expression) =>
71
+ (decoder: Decoder) =>
72
+ (obj: MetadataObject): ts.ConciseBody => {
73
+ if (obj.properties.length === 0)
74
+ return ts.factory.createIdentifier("{}");
75
+
76
+ // LIST UP PROPERTIES
77
+ const regular = obj.properties.filter((p) => p.key.isSoleLiteral());
78
+ const dynamic = obj.properties.filter(
79
+ (p) => !p.key.isSoleLiteral(),
80
+ );
81
+
82
+ // REGULAR OBJECT
83
+ const literal: ts.ObjectLiteralExpression =
84
+ ts.factory.createObjectLiteralExpression(
85
+ regular.map((p) => {
86
+ const str: string = p.key.getSoleLiteral()!;
87
+ return ts.factory.createPropertyAssignment(
88
+ Escaper.variable(str)
89
+ ? str
90
+ : ts.factory.createStringLiteral(str),
91
+ decoder(
92
+ p.value,
93
+ p.tags,
94
+ get_comment_tags(false)(p.jsDocTags),
95
+ ),
96
+ );
97
+ }),
98
+ true,
99
+ );
100
+ if (dynamic.length === 0) return literal;
101
+
102
+ const properties: ts.Statement[] = dynamic.map((p) =>
103
+ ts.factory.createExpressionStatement(
104
+ dynamicProperty(coalesce)(decoder)(p),
105
+ ),
106
+ );
107
+ return ts.factory.createBlock(
108
+ [
109
+ StatementFactory.constant(
110
+ "output",
111
+ ts.factory.createAsExpression(
112
+ literal,
113
+ TypeFactory.keyword("any"),
114
+ ),
115
+ ),
116
+ ...(obj.recursive
117
+ ? [
118
+ ts.factory.createIfStatement(
119
+ ts.factory.createGreaterThanEquals(
120
+ ts.factory.createNumericLiteral(5),
121
+ ts.factory.createIdentifier("_depth"),
122
+ ),
123
+ ts.factory.createBlock(properties, true),
124
+ ),
125
+ ]
126
+ : properties),
127
+ ts.factory.createReturnStatement(
128
+ ts.factory.createIdentifier("output"),
129
+ ),
130
+ ],
131
+ true,
132
+ );
133
+ };
134
+
135
+ const dynamicProperty =
136
+ (coalesce: (method: string) => ts.Expression) =>
137
+ (decoder: Decoder) =>
138
+ (p: MetadataProperty) =>
139
+ ts.factory.createCallExpression(coalesce("array"), undefined, [
140
+ ts.factory.createArrowFunction(
141
+ undefined,
142
+ undefined,
143
+ [],
144
+ undefined,
145
+ undefined,
146
+ ts.factory.createBinaryExpression(
147
+ ts.factory.createElementAccessExpression(
148
+ ts.factory.createIdentifier("output"),
149
+ decoder(p.key, [], []),
150
+ ),
151
+ ts.factory.createToken(ts.SyntaxKind.EqualsToken),
152
+ decoder(
153
+ p.value,
154
+ p.tags,
155
+ get_comment_tags(false)(p.jsDocTags),
156
+ ),
157
+ ),
158
+ ),
159
+ ts.factory.createCallExpression(
160
+ coalesce("integer"),
161
+ undefined,
162
+ [
163
+ ts.factory.createNumericLiteral(0),
164
+ ts.factory.createNumericLiteral(3),
165
+ ],
166
+ ),
167
+ ]);
168
+ }
169
+
170
+ interface IExplore {
171
+ function: boolean;
172
+ recursive: boolean;
173
+ }