typia 3.4.21 → 3.4.23

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 (127) hide show
  1. package/README.md +57 -23
  2. package/lib/programmers/AssertProgrammer.js +79 -70
  3. package/lib/programmers/AssertProgrammer.js.map +1 -1
  4. package/lib/programmers/IsProgrammer.d.ts +1 -0
  5. package/lib/programmers/IsProgrammer.js +4 -0
  6. package/lib/programmers/IsProgrammer.js.map +1 -1
  7. package/lib/programmers/ValidateProgrammer.js +68 -59
  8. package/lib/programmers/ValidateProgrammer.js.map +1 -1
  9. package/lib/programmers/helpers/OptionPredicator.d.ts +1 -0
  10. package/lib/programmers/helpers/OptionPredicator.js +4 -0
  11. package/lib/programmers/helpers/OptionPredicator.js.map +1 -1
  12. package/lib/programmers/internal/application_schema.js +23 -21
  13. package/lib/programmers/internal/application_schema.js.map +1 -1
  14. package/lib/programmers/internal/check_dynamic_properties.js +5 -0
  15. package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
  16. package/lib/programmers/internal/check_object.d.ts +1 -0
  17. package/lib/programmers/internal/check_object.js.map +1 -1
  18. package/lib/transformers/ITransformOptions.d.ts +10 -0
  19. package/package.json +2 -2
  20. package/src/IValidation.ts +21 -21
  21. package/src/Primitive.ts +82 -82
  22. package/src/TypeGuardError.ts +36 -36
  23. package/src/executable/internal/CommandParser.ts +15 -15
  24. package/src/factories/CommentFactory.ts +10 -10
  25. package/src/factories/ExpressionFactory.ts +66 -66
  26. package/src/factories/IdentifierFactory.ts +72 -72
  27. package/src/factories/LiteralFactory.ts +44 -44
  28. package/src/factories/StatementFactory.ts +60 -60
  29. package/src/factories/TemplateFactory.ts +56 -56
  30. package/src/factories/TypeFactory.ts +101 -101
  31. package/src/factories/ValueFactory.ts +12 -12
  32. package/src/functional/$every.ts +11 -11
  33. package/src/functional/$is_email.ts +5 -5
  34. package/src/functional/$is_ipv4.ts +5 -5
  35. package/src/functional/$is_ipv6.ts +5 -5
  36. package/src/functional/$is_url.ts +5 -5
  37. package/src/functional/$is_uuid.ts +5 -5
  38. package/src/functional/$join.ts +50 -50
  39. package/src/functional/$report.ts +15 -15
  40. package/src/functional/$rest.ts +3 -3
  41. package/src/functional/$string.ts +37 -37
  42. package/src/functional/$tail.ts +6 -6
  43. package/src/index.ts +4 -4
  44. package/src/metadata/IJsDocTagInfo.ts +10 -10
  45. package/src/metadata/IMetadata.ts +25 -25
  46. package/src/metadata/IMetadataApplication.ts +7 -7
  47. package/src/metadata/IMetadataConstant.ts +16 -16
  48. package/src/metadata/IMetadataEntry.ts +6 -6
  49. package/src/metadata/IMetadataObject.ts +29 -29
  50. package/src/metadata/IMetadataProperty.ts +11 -11
  51. package/src/metadata/MetadataConstant.ts +3 -3
  52. package/src/metadata/MetadataObject.ts +131 -131
  53. package/src/metadata/MetadataProperty.ts +64 -64
  54. package/src/programmers/ApplicationProgrammer.ts +55 -55
  55. package/src/programmers/AssertProgrammer.ts +36 -29
  56. package/src/programmers/IsProgrammer.ts +5 -0
  57. package/src/programmers/ValidateProgrammer.ts +36 -29
  58. package/src/programmers/helpers/AtomicPredicator.ts +15 -15
  59. package/src/programmers/helpers/FunctionImporeter.ts +31 -31
  60. package/src/programmers/helpers/IExpressionEntry.ts +10 -10
  61. package/src/programmers/helpers/OptionPredicator.ts +4 -0
  62. package/src/programmers/helpers/StringifyJoinder.ts +111 -111
  63. package/src/programmers/helpers/StringifyPredicator.ts +18 -18
  64. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  65. package/src/programmers/internal/application_array.ts +47 -47
  66. package/src/programmers/internal/application_boolean.ts +17 -17
  67. package/src/programmers/internal/application_constant.ts +29 -29
  68. package/src/programmers/internal/application_default_string.ts +32 -32
  69. package/src/programmers/internal/application_native.ts +29 -29
  70. package/src/programmers/internal/application_number.ts +76 -76
  71. package/src/programmers/internal/application_schema.ts +9 -6
  72. package/src/programmers/internal/application_string.ts +49 -49
  73. package/src/programmers/internal/application_templates.ts +27 -27
  74. package/src/programmers/internal/application_tuple.ts +29 -29
  75. package/src/programmers/internal/check_dynamic_properties.ts +164 -146
  76. package/src/programmers/internal/check_everything.ts +25 -25
  77. package/src/programmers/internal/check_length.ts +46 -46
  78. package/src/programmers/internal/check_native.ts +9 -9
  79. package/src/programmers/internal/check_object.ts +43 -42
  80. package/src/programmers/internal/check_string.ts +24 -24
  81. package/src/programmers/internal/check_string_tags.ts +63 -63
  82. package/src/programmers/internal/check_template.ts +50 -50
  83. package/src/programmers/internal/decode_union_object.ts +73 -73
  84. package/src/programmers/internal/feature_object_entries.ts +49 -49
  85. package/src/programmers/internal/metadata_to_pattern.ts +31 -31
  86. package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
  87. package/src/programmers/internal/stringify_native.ts +8 -8
  88. package/src/programmers/internal/stringify_regular_properties.ts +81 -81
  89. package/src/programmers/internal/template_to_pattern.ts +15 -15
  90. package/src/schemas/IJsonApplication.ts +9 -9
  91. package/src/schemas/IJsonComponents.ts +26 -26
  92. package/src/transform.ts +20 -20
  93. package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
  94. package/src/transformers/FileTransformer.ts +49 -49
  95. package/src/transformers/IProject.ts +11 -11
  96. package/src/transformers/ITransformOptions.ts +11 -0
  97. package/src/transformers/NodeTransformer.ts +19 -19
  98. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
  99. package/src/transformers/features/parsers/AssertParseTransformer.ts +36 -36
  100. package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +32 -32
  101. package/src/transformers/features/parsers/CreateIsParseTransformer.ts +32 -32
  102. package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +32 -32
  103. package/src/transformers/features/parsers/IsParseTransformer.ts +36 -36
  104. package/src/transformers/features/parsers/ValidateParseTransformer.ts +36 -36
  105. package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +38 -38
  106. package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +32 -32
  107. package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +32 -32
  108. package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +31 -31
  109. package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +32 -32
  110. package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +38 -38
  111. package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +38 -38
  112. package/src/transformers/features/validators/AssertTransformer.ts +43 -43
  113. package/src/transformers/features/validators/CreateAssertTransformer.ts +35 -35
  114. package/src/transformers/features/validators/CreateIsTransformer.ts +35 -35
  115. package/src/transformers/features/validators/CreateValidateTransformer.ts +35 -35
  116. package/src/transformers/features/validators/IsTransformer.ts +43 -43
  117. package/src/transformers/features/validators/ValidateTransformer.ts +43 -43
  118. package/src/typings/Atomic.ts +17 -17
  119. package/src/typings/ClassProperties.ts +5 -5
  120. package/src/typings/OmitNever.ts +3 -3
  121. package/src/typings/SpecialFields.ts +3 -3
  122. package/src/typings/Writable.ts +11 -11
  123. package/src/utils/ArrayUtil.ts +49 -49
  124. package/src/utils/Escaper.ts +50 -50
  125. package/src/utils/MapUtil.ts +14 -14
  126. package/src/utils/PatternUtil.ts +30 -30
  127. package/src/utils/Singleton.ts +17 -17
@@ -4,6 +4,7 @@ import { IdentifierFactory } from "../factories/IdentifierFactory";
4
4
 
5
5
  // import { StatementFactory } from "../factories/StatementFactory";
6
6
  import { IProject } from "../transformers/IProject";
7
+ import { ITransformOptions } from "../transformers/ITransformOptions";
7
8
 
8
9
  import { CheckerProgrammer } from "./CheckerProgrammer";
9
10
  import { IsProgrammer } from "./IsProgrammer";
@@ -240,8 +241,8 @@ export namespace AssertProgrammer {
240
241
  trace: true,
241
242
  numeric: OptionPredicator.numeric(project.options),
242
243
  equals,
243
- combiner: combiner(equals)(importer),
244
- joiner: joiner(equals)(importer),
244
+ combiner: combiner(project.options)(equals)(importer),
245
+ joiner: joiner(project.options)(equals)(importer),
245
246
  success: ts.factory.createTrue(),
246
247
  },
247
248
  importer,
@@ -277,12 +278,13 @@ export namespace AssertProgrammer {
277
278
  };
278
279
 
279
280
  const combiner =
281
+ (options: ITransformOptions) =>
280
282
  (equals: boolean) =>
281
283
  (importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
282
284
  (explore: CheckerProgrammer.IExplore) => {
283
285
  if (explore.tracable === false)
284
286
  return IsProgrammer.CONFIG({
285
- object: assert_object(equals)(importer),
287
+ object: assert_object(options)(equals)(importer),
286
288
  numeric: true,
287
289
  }).combiner(explore);
288
290
 
@@ -350,39 +352,44 @@ export namespace AssertProgrammer {
350
352
  // );
351
353
  };
352
354
 
353
- const assert_object = (equals: boolean) => (importer: FunctionImporter) =>
354
- check_object({
355
- equals,
356
- assert: true,
357
- reduce: ts.factory.createLogicalAnd,
358
- positive: ts.factory.createTrue(),
359
- superfluous: (value) =>
360
- create_guard_call(importer)()(
361
- ts.factory.createAdd(
362
- ts.factory.createIdentifier("path"),
363
- ts.factory.createCallExpression(
364
- importer.use("join"),
365
- undefined,
366
- [ts.factory.createIdentifier("key")],
355
+ const assert_object =
356
+ (options: ITransformOptions) =>
357
+ (equals: boolean) =>
358
+ (importer: FunctionImporter) =>
359
+ check_object({
360
+ equals,
361
+ assert: true,
362
+ undefined: OptionPredicator.undefined(options),
363
+ reduce: ts.factory.createLogicalAnd,
364
+ positive: ts.factory.createTrue(),
365
+ superfluous: (value) =>
366
+ create_guard_call(importer)()(
367
+ ts.factory.createAdd(
368
+ ts.factory.createIdentifier("path"),
369
+ ts.factory.createCallExpression(
370
+ importer.use("join"),
371
+ undefined,
372
+ [ts.factory.createIdentifier("key")],
373
+ ),
367
374
  ),
375
+ "undefined",
376
+ value,
368
377
  ),
369
- "undefined",
370
- value,
371
- ),
372
- halt: (expr) =>
373
- ts.factory.createLogicalOr(
374
- ts.factory.createStrictEquality(
375
- ts.factory.createFalse(),
376
- ts.factory.createIdentifier("exceptionable"),
378
+ halt: (expr) =>
379
+ ts.factory.createLogicalOr(
380
+ ts.factory.createStrictEquality(
381
+ ts.factory.createFalse(),
382
+ ts.factory.createIdentifier("exceptionable"),
383
+ ),
384
+ expr,
377
385
  ),
378
- expr,
379
- ),
380
- });
386
+ });
381
387
 
382
388
  const joiner =
389
+ (options: ITransformOptions) =>
383
390
  (equals: boolean) =>
384
391
  (importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
385
- object: assert_object(equals)(importer),
392
+ object: assert_object(options)(equals)(importer),
386
393
  array: (input, arrow) =>
387
394
  ts.factory.createCallExpression(
388
395
  IdentifierFactory.join(input, "every"),
@@ -51,6 +51,9 @@ export namespace IsProgrammer {
51
51
  options?.object ||
52
52
  check_object({
53
53
  equals: !!options?.object,
54
+ undefined: OptionPredicator.undefined({
55
+ undefined: options?.undefined,
56
+ }),
54
57
  assert: true,
55
58
  reduce: ts.factory.createLogicalAnd,
56
59
  positive: ts.factory.createTrue(),
@@ -70,6 +73,7 @@ export namespace IsProgrammer {
70
73
  export namespace CONFIG {
71
74
  export interface IOptions {
72
75
  numeric: boolean;
76
+ undefined: boolean;
73
77
  object: (entries: IExpressionEntry[]) => ts.Expression;
74
78
  }
75
79
  }
@@ -88,6 +92,7 @@ export namespace IsProgrammer {
88
92
  const config = CONFIG({
89
93
  object: check_object({
90
94
  equals,
95
+ undefined: OptionPredicator.undefined(project.options),
91
96
  assert: true,
92
97
  reduce: ts.factory.createLogicalAnd,
93
98
  positive: ts.factory.createTrue(),
@@ -4,6 +4,7 @@ import { IdentifierFactory } from "../factories/IdentifierFactory";
4
4
  import { StatementFactory } from "../factories/StatementFactory";
5
5
 
6
6
  import { IProject } from "../transformers/IProject";
7
+ import { ITransformOptions } from "../transformers/ITransformOptions";
7
8
 
8
9
  import { CheckerProgrammer } from "./CheckerProgrammer";
9
10
  import { IsProgrammer } from "./IsProgrammer";
@@ -30,8 +31,8 @@ export namespace ValidateProgrammer {
30
31
  trace: true,
31
32
  numeric: OptionPredicator.numeric(project.options),
32
33
  equals,
33
- combiner: combine(equals)(importer),
34
- joiner: joiner(equals)(importer),
34
+ combiner: combine(project.options)(equals)(importer),
35
+ joiner: joiner(project.options)(equals)(importer),
35
36
  success: ts.factory.createTrue(),
36
37
  },
37
38
  importer,
@@ -85,12 +86,13 @@ export namespace ValidateProgrammer {
85
86
  }
86
87
 
87
88
  const combine =
89
+ (options: ITransformOptions) =>
88
90
  (equals: boolean) =>
89
91
  (importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
90
92
  (explore: CheckerProgrammer.IExplore) => {
91
93
  if (explore.tracable === false)
92
94
  return IsProgrammer.CONFIG({
93
- object: validate_object(equals)(importer),
95
+ object: validate_object(options)(equals)(importer),
94
96
  numeric: true,
95
97
  }).combiner(explore);
96
98
 
@@ -131,39 +133,44 @@ const combine =
131
133
  );
132
134
  };
133
135
 
134
- const validate_object = (equals: boolean) => (importer: FunctionImporter) =>
135
- check_object({
136
- equals,
137
- assert: false,
138
- reduce: ts.factory.createLogicalAnd,
139
- positive: ts.factory.createTrue(),
140
- superfluous: (value) =>
141
- create_report_call()(
142
- ts.factory.createAdd(
143
- ts.factory.createIdentifier("path"),
144
- ts.factory.createCallExpression(
145
- importer.use("join"),
146
- undefined,
147
- [ts.factory.createIdentifier("key")],
136
+ const validate_object =
137
+ (options: ITransformOptions) =>
138
+ (equals: boolean) =>
139
+ (importer: FunctionImporter) =>
140
+ check_object({
141
+ equals,
142
+ undefined: OptionPredicator.undefined(options),
143
+ assert: false,
144
+ reduce: ts.factory.createLogicalAnd,
145
+ positive: ts.factory.createTrue(),
146
+ superfluous: (value) =>
147
+ create_report_call()(
148
+ ts.factory.createAdd(
149
+ ts.factory.createIdentifier("path"),
150
+ ts.factory.createCallExpression(
151
+ importer.use("join"),
152
+ undefined,
153
+ [ts.factory.createIdentifier("key")],
154
+ ),
148
155
  ),
156
+ "undefined",
157
+ value,
149
158
  ),
150
- "undefined",
151
- value,
152
- ),
153
- halt: (expr) =>
154
- ts.factory.createLogicalOr(
155
- ts.factory.createStrictEquality(
156
- ts.factory.createFalse(),
157
- ts.factory.createIdentifier("exceptionable"),
159
+ halt: (expr) =>
160
+ ts.factory.createLogicalOr(
161
+ ts.factory.createStrictEquality(
162
+ ts.factory.createFalse(),
163
+ ts.factory.createIdentifier("exceptionable"),
164
+ ),
165
+ expr,
158
166
  ),
159
- expr,
160
- ),
161
- });
167
+ });
162
168
 
163
169
  const joiner =
170
+ (options: ITransformOptions) =>
164
171
  (equals: boolean) =>
165
172
  (importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
166
- object: validate_object(equals)(importer),
173
+ object: validate_object(options)(equals)(importer),
167
174
  array: (input, arrow) =>
168
175
  check_everything(
169
176
  ts.factory.createCallExpression(
@@ -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
+ }
@@ -12,4 +12,8 @@ export namespace OptionPredicator {
12
12
  export function finite(options: ITransformOptions): boolean {
13
13
  return options.finite === true;
14
14
  }
15
+
16
+ export function undefined(options: ITransformOptions): boolean {
17
+ return options.undefined !== false;
18
+ }
15
19
  }
@@ -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
+ }