typia 3.5.0-dev.20221222 → 3.5.0-dev.20230124

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 (184) hide show
  1. package/README.md +5 -2
  2. package/lib/executable/internal/TypiaSetupWizard.d.ts +6 -2
  3. package/lib/executable/internal/TypiaSetupWizard.js +23 -22
  4. package/lib/executable/internal/TypiaSetupWizard.js.map +1 -1
  5. package/lib/executable/typia.js +11 -10
  6. package/lib/executable/typia.js.map +1 -1
  7. package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +1 -0
  8. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +20 -0
  9. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -1
  10. package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +2 -1
  11. package/lib/factories/internal/protocols/iterate_protocol_map.js +7 -4
  12. package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -1
  13. package/lib/factories/internal/protocols/iterate_protocol_metadata.js +3 -3
  14. package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -1
  15. package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +2 -1
  16. package/lib/factories/internal/protocols/iterate_protocol_repeated.js +5 -4
  17. package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -1
  18. package/lib/messages/IProtocolMap.d.ts +5 -0
  19. package/lib/messages/IProtocolMap.js +3 -0
  20. package/lib/messages/IProtocolMap.js.map +1 -0
  21. package/lib/messages/IProtocolProperty.d.ts +2 -1
  22. package/lib/metadata/Metadata.d.ts +1 -0
  23. package/lib/metadata/Metadata.js +145 -51
  24. package/lib/metadata/Metadata.js.map +1 -1
  25. package/lib/programmers/AssertProgrammer.js +1 -1
  26. package/lib/programmers/AssertProgrammer.js.map +1 -1
  27. package/lib/programmers/CheckerProgrammer.d.ts +1 -0
  28. package/lib/programmers/CheckerProgrammer.js +147 -138
  29. package/lib/programmers/CheckerProgrammer.js.map +1 -1
  30. package/lib/programmers/MessageProgrammer.js +7 -2
  31. package/lib/programmers/MessageProgrammer.js.map +1 -1
  32. package/lib/programmers/ValidateProgrammer.js +1 -1
  33. package/lib/programmers/ValidateProgrammer.js.map +1 -1
  34. package/lib/programmers/helpers/UnionExplorer.d.ts +23 -29
  35. package/lib/programmers/helpers/UnionExplorer.js +29 -41
  36. package/lib/programmers/helpers/UnionExplorer.js.map +1 -1
  37. package/lib/programmers/internal/application_array.js +29 -27
  38. package/lib/programmers/internal/application_array.js.map +1 -1
  39. package/lib/programmers/internal/application_object.js +96 -31
  40. package/lib/programmers/internal/application_object.js.map +1 -1
  41. package/lib/programmers/internal/application_schema.js +28 -136
  42. package/lib/programmers/internal/application_schema.js.map +1 -1
  43. package/lib/programmers/internal/application_tuple.js +3 -2
  44. package/lib/programmers/internal/application_tuple.js.map +1 -1
  45. package/lib/programmers/internal/check_array.js +4 -32
  46. package/lib/programmers/internal/check_array.js.map +1 -1
  47. package/lib/programmers/internal/check_array_length.d.ts +1 -0
  48. package/lib/programmers/internal/check_array_length.js +47 -0
  49. package/lib/programmers/internal/check_array_length.js.map +1 -0
  50. package/lib/programmers/internal/check_union_array_like.d.ts +21 -0
  51. package/lib/programmers/internal/check_union_array_like.js +83 -0
  52. package/lib/programmers/internal/check_union_array_like.js.map +1 -0
  53. package/lib/programmers/internal/check_union_tuple.d.ts +1 -0
  54. package/lib/programmers/internal/check_union_tuple.js +11 -0
  55. package/lib/programmers/internal/check_union_tuple.js.map +1 -0
  56. package/lib/schemas/IJsonComponents.d.ts +4 -2
  57. package/lib/schemas/IJsonSchema.d.ts +2 -0
  58. package/package.json +4 -4
  59. package/src/IValidation.ts +21 -21
  60. package/src/Primitive.ts +82 -82
  61. package/src/TypeGuardError.ts +36 -36
  62. package/src/executable/internal/CommandParser.ts +15 -15
  63. package/src/executable/internal/TypiaSetupWizard.ts +30 -21
  64. package/src/executable/typia.ts +48 -46
  65. package/src/factories/CommentFactory.ts +10 -10
  66. package/src/factories/ExpressionFactory.ts +66 -66
  67. package/src/factories/IdentifierFactory.ts +72 -72
  68. package/src/factories/LiteralFactory.ts +44 -44
  69. package/src/factories/StatementFactory.ts +60 -60
  70. package/src/factories/TemplateFactory.ts +56 -56
  71. package/src/factories/TypeFactory.ts +101 -101
  72. package/src/factories/ValueFactory.ts +12 -12
  73. package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +20 -0
  74. package/src/factories/internal/protocols/iterate_protocol_map.ts +9 -3
  75. package/src/factories/internal/protocols/iterate_protocol_metadata.ts +17 -4
  76. package/src/factories/internal/protocols/iterate_protocol_repeated.ts +14 -5
  77. package/src/functional/$every.ts +11 -11
  78. package/src/functional/$guard.ts +35 -35
  79. package/src/functional/$is_email.ts +5 -5
  80. package/src/functional/$is_ipv4.ts +5 -5
  81. package/src/functional/$is_ipv6.ts +5 -5
  82. package/src/functional/$is_url.ts +5 -5
  83. package/src/functional/$is_uuid.ts +5 -5
  84. package/src/functional/$join.ts +50 -50
  85. package/src/functional/$report.ts +15 -15
  86. package/src/functional/$rest.ts +3 -3
  87. package/src/functional/$string.ts +37 -37
  88. package/src/functional/$tail.ts +6 -6
  89. package/src/index.ts +4 -4
  90. package/src/messages/IProtocolMap.ts +5 -0
  91. package/src/messages/IProtocolProperty.ts +3 -1
  92. package/src/metadata/IJsDocTagInfo.ts +10 -10
  93. package/src/metadata/IMetadata.ts +25 -25
  94. package/src/metadata/IMetadataApplication.ts +7 -7
  95. package/src/metadata/IMetadataConstant.ts +16 -16
  96. package/src/metadata/IMetadataEntry.ts +6 -6
  97. package/src/metadata/IMetadataObject.ts +29 -29
  98. package/src/metadata/IMetadataProperty.ts +11 -11
  99. package/src/metadata/Metadata.ts +64 -7
  100. package/src/metadata/MetadataConstant.ts +3 -3
  101. package/src/metadata/MetadataObject.ts +131 -131
  102. package/src/metadata/MetadataProperty.ts +64 -64
  103. package/src/programmers/ApplicationProgrammer.ts +55 -55
  104. package/src/programmers/AssertProgrammer.ts +1 -1
  105. package/src/programmers/CheckerProgrammer.ts +252 -200
  106. package/src/programmers/FeatureProgrammer.ts +327 -327
  107. package/src/programmers/MessageProgrammer.ts +9 -2
  108. package/src/programmers/ValidateProgrammer.ts +1 -1
  109. package/src/programmers/helpers/AtomicPredicator.ts +15 -15
  110. package/src/programmers/helpers/FunctionImporeter.ts +31 -31
  111. package/src/programmers/helpers/IExpressionEntry.ts +10 -10
  112. package/src/programmers/helpers/StringifyJoinder.ts +111 -111
  113. package/src/programmers/helpers/StringifyPredicator.ts +18 -18
  114. package/src/programmers/helpers/UnionExplorer.ts +274 -437
  115. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  116. package/src/programmers/internal/application_array.ts +47 -45
  117. package/src/programmers/internal/application_boolean.ts +17 -17
  118. package/src/programmers/internal/application_constant.ts +29 -29
  119. package/src/programmers/internal/application_default_string.ts +32 -32
  120. package/src/programmers/internal/application_native.ts +29 -29
  121. package/src/programmers/internal/application_number.ts +76 -76
  122. package/src/programmers/internal/application_object.ts +153 -103
  123. package/src/programmers/internal/application_schema.ts +15 -68
  124. package/src/programmers/internal/application_string.ts +49 -49
  125. package/src/programmers/internal/application_templates.ts +27 -27
  126. package/src/programmers/internal/application_tuple.ts +29 -25
  127. package/src/programmers/internal/check_array.ts +22 -44
  128. package/src/programmers/internal/check_array_length.ts +45 -0
  129. package/src/programmers/internal/check_dynamic_properties.ts +146 -146
  130. package/src/programmers/internal/check_everything.ts +25 -25
  131. package/src/programmers/internal/check_length.ts +46 -46
  132. package/src/programmers/internal/check_native.ts +9 -9
  133. package/src/programmers/internal/check_object.ts +42 -42
  134. package/src/programmers/internal/check_string.ts +24 -24
  135. package/src/programmers/internal/check_string_tags.ts +63 -63
  136. package/src/programmers/internal/check_template.ts +50 -50
  137. package/src/programmers/internal/check_union_array_like.ts +242 -0
  138. package/src/programmers/internal/check_union_tuple.ts +33 -0
  139. package/src/programmers/internal/decode_union_object.ts +73 -73
  140. package/src/programmers/internal/feature_object_entries.ts +49 -49
  141. package/src/programmers/internal/metadata_to_pattern.ts +31 -31
  142. package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
  143. package/src/programmers/internal/stringify_native.ts +8 -8
  144. package/src/programmers/internal/stringify_regular_properties.ts +81 -81
  145. package/src/programmers/internal/template_to_pattern.ts +15 -15
  146. package/src/schemas/IJsonApplication.ts +9 -9
  147. package/src/schemas/IJsonComponents.ts +26 -24
  148. package/src/schemas/IJsonSchema.ts +2 -0
  149. package/src/transform.ts +20 -20
  150. package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
  151. package/src/transformers/FileTransformer.ts +49 -49
  152. package/src/transformers/IProject.ts +11 -11
  153. package/src/transformers/NodeTransformer.ts +19 -19
  154. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +1 -0
  155. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
  156. package/src/transformers/features/parsers/AssertParseTransformer.ts +36 -36
  157. package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +32 -32
  158. package/src/transformers/features/parsers/CreateIsParseTransformer.ts +32 -32
  159. package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +32 -32
  160. package/src/transformers/features/parsers/IsParseTransformer.ts +36 -36
  161. package/src/transformers/features/parsers/ValidateParseTransformer.ts +36 -36
  162. package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +38 -38
  163. package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +32 -32
  164. package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +32 -32
  165. package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +31 -31
  166. package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +32 -32
  167. package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +38 -38
  168. package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +38 -38
  169. package/src/transformers/features/validators/AssertTransformer.ts +43 -43
  170. package/src/transformers/features/validators/CreateAssertTransformer.ts +35 -35
  171. package/src/transformers/features/validators/CreateIsTransformer.ts +35 -35
  172. package/src/transformers/features/validators/CreateValidateTransformer.ts +35 -35
  173. package/src/transformers/features/validators/IsTransformer.ts +43 -43
  174. package/src/transformers/features/validators/ValidateTransformer.ts +43 -43
  175. package/src/typings/Atomic.ts +17 -17
  176. package/src/typings/ClassProperties.ts +5 -5
  177. package/src/typings/OmitNever.ts +3 -3
  178. package/src/typings/SpecialFields.ts +3 -3
  179. package/src/typings/Writable.ts +11 -11
  180. package/src/utils/ArrayUtil.ts +49 -49
  181. package/src/utils/Escaper.ts +50 -50
  182. package/src/utils/MapUtil.ts +14 -14
  183. package/src/utils/PatternUtil.ts +30 -30
  184. package/src/utils/Singleton.ts +17 -17
@@ -11,6 +11,7 @@ import { Escaper } from "../utils/Escaper";
11
11
  import { MapUtil } from "../utils/MapUtil";
12
12
  import { NameEncoder } from "../utils/NameEncoder";
13
13
 
14
+ import { IProtocolMap } from "../messages/IProtocolMap";
14
15
  import { IProtocolMessage } from "../messages/IProtocolMessage";
15
16
 
16
17
  export namespace MessageProgrammer {
@@ -53,7 +54,7 @@ export namespace MessageProgrammer {
53
54
  TAB,
54
55
  property.required ? "" : "optional ",
55
56
  property.repeated ? "repeated " : "",
56
- NameEncoder.encode(property.oneOf[0]!.type) + " ",
57
+ getTypeName(property.oneOf[0]!.type) + " ",
57
58
  Escaper.variable(property.key)
58
59
  ? property.key
59
60
  : `v${index + 1}`,
@@ -65,7 +66,7 @@ export namespace MessageProgrammer {
65
66
  property.oneOf
66
67
  .map(
67
68
  (o, i) =>
68
- `${TAB}${TAB}${NameEncoder.encode(
69
+ `${TAB}${TAB}${getTypeName(
69
70
  o.type,
70
71
  )} o${i} = ${index++};`,
71
72
  )
@@ -105,6 +106,12 @@ export namespace MessageProgrammer {
105
106
  if (i === accessors.length - 1) hierarchy.message = message;
106
107
  });
107
108
  };
109
+
110
+ function getTypeName(type: string | IProtocolMap): string {
111
+ return typeof type === "string"
112
+ ? NameEncoder.encode(type)
113
+ : `map<${type.key}, ${getTypeName(type.value)}>`;
114
+ }
108
115
  }
109
116
 
110
117
  interface Hierarchy {
@@ -88,7 +88,7 @@ const combine =
88
88
  (equals: boolean) =>
89
89
  (importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
90
90
  (explore: CheckerProgrammer.IExplore) => {
91
- if (explore.tracable === false && explore.from !== "top")
91
+ if (explore.tracable === false)
92
92
  return IsProgrammer.CONFIG({
93
93
  object: validate_object(equals)(importer),
94
94
  numeric: true,
@@ -1,15 +1,15 @@
1
- import { Metadata } from "../../metadata/Metadata";
2
-
3
- import { Atomic } from "../../typings/Atomic";
4
-
5
- import { ArrayUtil } from "../../utils/ArrayUtil";
6
-
7
- export namespace AtomicPredicator {
8
- export const constant =
9
- (meta: Metadata) =>
10
- (name: Atomic.Literal): boolean =>
11
- !ArrayUtil.has(meta.atomics, (atomic) => atomic === name);
12
-
13
- export const template = (meta: Metadata): boolean =>
14
- !ArrayUtil.has(meta.atomics, (type) => type === "string");
15
- }
1
+ import { Metadata } from "../../metadata/Metadata";
2
+
3
+ import { Atomic } from "../../typings/Atomic";
4
+
5
+ import { ArrayUtil } from "../../utils/ArrayUtil";
6
+
7
+ export namespace AtomicPredicator {
8
+ export const constant =
9
+ (meta: Metadata) =>
10
+ (name: Atomic.Literal): boolean =>
11
+ !ArrayUtil.has(meta.atomics, (atomic) => atomic === name);
12
+
13
+ export const template = (meta: Metadata): boolean =>
14
+ !ArrayUtil.has(meta.atomics, (type) => type === "string");
15
+ }
@@ -1,31 +1,31 @@
1
- import ts from "typescript";
2
-
3
- import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
- import { StatementFactory } from "../../factories/StatementFactory";
5
-
6
- export class FunctionImporter {
7
- private readonly used_: Set<string> = new Set();
8
- private sequence_: number = 0;
9
-
10
- public empty(): boolean {
11
- return this.used_.size === 0;
12
- }
13
-
14
- public use(name: string): ts.Identifier {
15
- this.used_.add(name);
16
- return ts.factory.createIdentifier("$" + name);
17
- }
18
-
19
- public declare(modulo: ts.LeftHandSideExpression): ts.Statement[] {
20
- return [...this.used_].map((name) =>
21
- StatementFactory.constant(
22
- "$" + name,
23
- IdentifierFactory.join(modulo, name),
24
- ),
25
- );
26
- }
27
-
28
- public increment(): number {
29
- return ++this.sequence_;
30
- }
31
- }
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
+ import { StatementFactory } from "../../factories/StatementFactory";
5
+
6
+ export class FunctionImporter {
7
+ private readonly used_: Set<string> = new Set();
8
+ private sequence_: number = 0;
9
+
10
+ public empty(): boolean {
11
+ return this.used_.size === 0;
12
+ }
13
+
14
+ public use(name: string): ts.Identifier {
15
+ this.used_.add(name);
16
+ return ts.factory.createIdentifier("$" + name);
17
+ }
18
+
19
+ public declare(modulo: ts.LeftHandSideExpression): ts.Statement[] {
20
+ return [...this.used_].map((name) =>
21
+ StatementFactory.constant(
22
+ "$" + name,
23
+ IdentifierFactory.join(modulo, name),
24
+ ),
25
+ );
26
+ }
27
+
28
+ public increment(): number {
29
+ return ++this.sequence_;
30
+ }
31
+ }
@@ -1,10 +1,10 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../metadata/Metadata";
4
-
5
- export interface IExpressionEntry {
6
- input: ts.Expression;
7
- key: Metadata;
8
- meta: Metadata;
9
- expression: ts.Expression;
10
- }
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../metadata/Metadata";
4
+
5
+ export interface IExpressionEntry {
6
+ input: ts.Expression;
7
+ key: Metadata;
8
+ meta: Metadata;
9
+ expression: ts.Expression;
10
+ }
@@ -1,111 +1,111 @@
1
- import ts from "typescript";
2
-
3
- import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
- import { TemplateFactory } from "../../factories/TemplateFactory";
5
-
6
- import { stringify_dynamic_properties } from "../internal/stringify_dynamic_properties";
7
- import { stringify_regular_properties } from "../internal/stringify_regular_properties";
8
- import { FunctionImporter } from "./FunctionImporeter";
9
- import { IExpressionEntry } from "./IExpressionEntry";
10
-
11
- export namespace StringifyJoiner {
12
- export const object =
13
- (importer: FunctionImporter) =>
14
- (entries: IExpressionEntry[]): ts.Expression => {
15
- // CHECK AND SORT ENTRIES
16
- const regular: IExpressionEntry[] = entries.filter((entry) =>
17
- entry.key.isSoleLiteral(),
18
- );
19
- const dynamic: IExpressionEntry[] = entries.filter(
20
- (entry) => !entry.key.isSoleLiteral(),
21
- );
22
- if (regular.length === 0 && dynamic.length === 0)
23
- return ts.factory.createStringLiteral("{}");
24
-
25
- // PROPERTIES
26
- const expressions: ts.Expression[] = [
27
- ...stringify_regular_properties(regular, dynamic),
28
- ...(dynamic.length
29
- ? [
30
- stringify_dynamic_properties(
31
- dynamic,
32
- regular.map((r) => r.key.getSoleLiteral()!),
33
- ),
34
- ]
35
- : []),
36
- ];
37
-
38
- // POP LAST COMMA, IF REQUIRED
39
- const filtered: ts.Expression[] =
40
- (regular.length &&
41
- regular[regular.length - 1]!.meta.required &&
42
- dynamic.length === 0) ||
43
- (regular.length === 0 && dynamic.length)
44
- ? expressions
45
- : [
46
- ts.factory.createCallExpression(
47
- importer.use("tail"),
48
- undefined,
49
- [TemplateFactory.generate(expressions)],
50
- ),
51
- ];
52
-
53
- // RETURNS WITH OBJECT BRACKET
54
- return TemplateFactory.generate([
55
- ts.factory.createStringLiteral(`{`),
56
- ...filtered,
57
- ts.factory.createStringLiteral(`}`),
58
- ]);
59
- };
60
-
61
- export function array(
62
- input: ts.Expression,
63
- arrow: ts.ArrowFunction,
64
- ): ts.Expression {
65
- return TemplateFactory.generate([
66
- ts.factory.createStringLiteral(`[`),
67
- ts.factory.createCallExpression(
68
- ts.factory.createPropertyAccessExpression(
69
- ts.factory.createCallExpression(
70
- IdentifierFactory.join(input, "map"),
71
- undefined,
72
- [arrow],
73
- ),
74
- ts.factory.createIdentifier("join"),
75
- ),
76
- undefined,
77
- [ts.factory.createStringLiteral(`,`)],
78
- ),
79
- ts.factory.createStringLiteral(`]`),
80
- ]);
81
- }
82
-
83
- export function tuple(
84
- children: ts.Expression[],
85
- rest: ts.Expression | null,
86
- ): ts.Expression {
87
- if (children.length === 0) return ts.factory.createStringLiteral("[]");
88
- if (
89
- rest === null &&
90
- children.every((child) => ts.isStringLiteral(child))
91
- )
92
- return ts.factory.createStringLiteral(
93
- "[" +
94
- children
95
- .map((child) => (child as ts.StringLiteral).text)
96
- .join(",") +
97
- "]",
98
- );
99
-
100
- const elements: ts.Expression[] = [ts.factory.createStringLiteral(`[`)];
101
- children.forEach((child, i) => {
102
- elements.push(child);
103
- if (i !== children.length - 1)
104
- elements.push(ts.factory.createStringLiteral(`,`));
105
- });
106
- if (rest !== null) elements.push(rest);
107
-
108
- elements.push(ts.factory.createStringLiteral(`]`));
109
- return TemplateFactory.generate(elements);
110
- }
111
- }
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
+ import { TemplateFactory } from "../../factories/TemplateFactory";
5
+
6
+ import { stringify_dynamic_properties } from "../internal/stringify_dynamic_properties";
7
+ import { stringify_regular_properties } from "../internal/stringify_regular_properties";
8
+ import { FunctionImporter } from "./FunctionImporeter";
9
+ import { IExpressionEntry } from "./IExpressionEntry";
10
+
11
+ export namespace StringifyJoiner {
12
+ export const object =
13
+ (importer: FunctionImporter) =>
14
+ (entries: IExpressionEntry[]): ts.Expression => {
15
+ // CHECK AND SORT ENTRIES
16
+ const regular: IExpressionEntry[] = entries.filter((entry) =>
17
+ entry.key.isSoleLiteral(),
18
+ );
19
+ const dynamic: IExpressionEntry[] = entries.filter(
20
+ (entry) => !entry.key.isSoleLiteral(),
21
+ );
22
+ if (regular.length === 0 && dynamic.length === 0)
23
+ return ts.factory.createStringLiteral("{}");
24
+
25
+ // PROPERTIES
26
+ const expressions: ts.Expression[] = [
27
+ ...stringify_regular_properties(regular, dynamic),
28
+ ...(dynamic.length
29
+ ? [
30
+ stringify_dynamic_properties(
31
+ dynamic,
32
+ regular.map((r) => r.key.getSoleLiteral()!),
33
+ ),
34
+ ]
35
+ : []),
36
+ ];
37
+
38
+ // POP LAST COMMA, IF REQUIRED
39
+ const filtered: ts.Expression[] =
40
+ (regular.length &&
41
+ regular[regular.length - 1]!.meta.required &&
42
+ dynamic.length === 0) ||
43
+ (regular.length === 0 && dynamic.length)
44
+ ? expressions
45
+ : [
46
+ ts.factory.createCallExpression(
47
+ importer.use("tail"),
48
+ undefined,
49
+ [TemplateFactory.generate(expressions)],
50
+ ),
51
+ ];
52
+
53
+ // RETURNS WITH OBJECT BRACKET
54
+ return TemplateFactory.generate([
55
+ ts.factory.createStringLiteral(`{`),
56
+ ...filtered,
57
+ ts.factory.createStringLiteral(`}`),
58
+ ]);
59
+ };
60
+
61
+ export function array(
62
+ input: ts.Expression,
63
+ arrow: ts.ArrowFunction,
64
+ ): ts.Expression {
65
+ return TemplateFactory.generate([
66
+ ts.factory.createStringLiteral(`[`),
67
+ ts.factory.createCallExpression(
68
+ ts.factory.createPropertyAccessExpression(
69
+ ts.factory.createCallExpression(
70
+ IdentifierFactory.join(input, "map"),
71
+ undefined,
72
+ [arrow],
73
+ ),
74
+ ts.factory.createIdentifier("join"),
75
+ ),
76
+ undefined,
77
+ [ts.factory.createStringLiteral(`,`)],
78
+ ),
79
+ ts.factory.createStringLiteral(`]`),
80
+ ]);
81
+ }
82
+
83
+ export function tuple(
84
+ children: ts.Expression[],
85
+ rest: ts.Expression | null,
86
+ ): ts.Expression {
87
+ if (children.length === 0) return ts.factory.createStringLiteral("[]");
88
+ if (
89
+ rest === null &&
90
+ children.every((child) => ts.isStringLiteral(child))
91
+ )
92
+ return ts.factory.createStringLiteral(
93
+ "[" +
94
+ children
95
+ .map((child) => (child as ts.StringLiteral).text)
96
+ .join(",") +
97
+ "]",
98
+ );
99
+
100
+ const elements: ts.Expression[] = [ts.factory.createStringLiteral(`[`)];
101
+ children.forEach((child, i) => {
102
+ elements.push(child);
103
+ if (i !== children.length - 1)
104
+ elements.push(ts.factory.createStringLiteral(`,`));
105
+ });
106
+ if (rest !== null) elements.push(rest);
107
+
108
+ elements.push(ts.factory.createStringLiteral(`]`));
109
+ return TemplateFactory.generate(elements);
110
+ }
111
+ }
@@ -1,18 +1,18 @@
1
- import { Metadata } from "../../metadata/Metadata";
2
-
3
- export namespace StringifyPredicator {
4
- export function require_escape(value: string): boolean {
5
- return value
6
- .split("")
7
- .some((ch) => ESCAPED.some((escaped) => escaped === ch));
8
- }
9
-
10
- export function undefindable(meta: Metadata): boolean {
11
- return (
12
- meta.required === false ||
13
- (meta.resolved !== null && meta.resolved.required === false)
14
- );
15
- }
16
-
17
- const ESCAPED = ['"', "\\", "\b", "\f", "\n", "\n", "\r", "\t"];
18
- }
1
+ import { Metadata } from "../../metadata/Metadata";
2
+
3
+ export namespace StringifyPredicator {
4
+ export function require_escape(value: string): boolean {
5
+ return value
6
+ .split("")
7
+ .some((ch) => ESCAPED.some((escaped) => escaped === ch));
8
+ }
9
+
10
+ export function undefindable(meta: Metadata): boolean {
11
+ return (
12
+ meta.required === false ||
13
+ (meta.resolved !== null && meta.resolved.required === false)
14
+ );
15
+ }
16
+
17
+ const ESCAPED = ['"', "\\", "\b", "\f", "\n", "\n", "\r", "\t"];
18
+ }