typia 3.4.22 → 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 (124) 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/check_dynamic_properties.js +5 -0
  13. package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
  14. package/lib/programmers/internal/check_object.d.ts +1 -0
  15. package/lib/programmers/internal/check_object.js.map +1 -1
  16. package/lib/transformers/ITransformOptions.d.ts +10 -0
  17. package/package.json +2 -2
  18. package/src/IValidation.ts +21 -21
  19. package/src/Primitive.ts +82 -82
  20. package/src/TypeGuardError.ts +36 -36
  21. package/src/executable/internal/CommandParser.ts +15 -15
  22. package/src/factories/CommentFactory.ts +10 -10
  23. package/src/factories/ExpressionFactory.ts +66 -66
  24. package/src/factories/IdentifierFactory.ts +72 -72
  25. package/src/factories/LiteralFactory.ts +44 -44
  26. package/src/factories/StatementFactory.ts +60 -60
  27. package/src/factories/TemplateFactory.ts +56 -56
  28. package/src/factories/TypeFactory.ts +101 -101
  29. package/src/factories/ValueFactory.ts +12 -12
  30. package/src/functional/$every.ts +11 -11
  31. package/src/functional/$is_email.ts +5 -5
  32. package/src/functional/$is_ipv4.ts +5 -5
  33. package/src/functional/$is_ipv6.ts +5 -5
  34. package/src/functional/$is_url.ts +5 -5
  35. package/src/functional/$is_uuid.ts +5 -5
  36. package/src/functional/$join.ts +50 -50
  37. package/src/functional/$report.ts +15 -15
  38. package/src/functional/$rest.ts +3 -3
  39. package/src/functional/$string.ts +37 -37
  40. package/src/functional/$tail.ts +6 -6
  41. package/src/index.ts +4 -4
  42. package/src/metadata/IJsDocTagInfo.ts +10 -10
  43. package/src/metadata/IMetadata.ts +25 -25
  44. package/src/metadata/IMetadataApplication.ts +7 -7
  45. package/src/metadata/IMetadataConstant.ts +16 -16
  46. package/src/metadata/IMetadataEntry.ts +6 -6
  47. package/src/metadata/IMetadataObject.ts +29 -29
  48. package/src/metadata/IMetadataProperty.ts +11 -11
  49. package/src/metadata/MetadataConstant.ts +3 -3
  50. package/src/metadata/MetadataObject.ts +131 -131
  51. package/src/metadata/MetadataProperty.ts +64 -64
  52. package/src/programmers/ApplicationProgrammer.ts +55 -55
  53. package/src/programmers/AssertProgrammer.ts +36 -29
  54. package/src/programmers/IsProgrammer.ts +5 -0
  55. package/src/programmers/ValidateProgrammer.ts +36 -29
  56. package/src/programmers/helpers/AtomicPredicator.ts +15 -15
  57. package/src/programmers/helpers/FunctionImporeter.ts +31 -31
  58. package/src/programmers/helpers/IExpressionEntry.ts +10 -10
  59. package/src/programmers/helpers/OptionPredicator.ts +4 -0
  60. package/src/programmers/helpers/StringifyJoinder.ts +111 -111
  61. package/src/programmers/helpers/StringifyPredicator.ts +18 -18
  62. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  63. package/src/programmers/internal/application_array.ts +47 -47
  64. package/src/programmers/internal/application_boolean.ts +17 -17
  65. package/src/programmers/internal/application_constant.ts +29 -29
  66. package/src/programmers/internal/application_default_string.ts +32 -32
  67. package/src/programmers/internal/application_native.ts +29 -29
  68. package/src/programmers/internal/application_number.ts +76 -76
  69. package/src/programmers/internal/application_string.ts +49 -49
  70. package/src/programmers/internal/application_templates.ts +27 -27
  71. package/src/programmers/internal/application_tuple.ts +29 -29
  72. package/src/programmers/internal/check_dynamic_properties.ts +164 -146
  73. package/src/programmers/internal/check_everything.ts +25 -25
  74. package/src/programmers/internal/check_length.ts +46 -46
  75. package/src/programmers/internal/check_native.ts +9 -9
  76. package/src/programmers/internal/check_object.ts +43 -42
  77. package/src/programmers/internal/check_string.ts +24 -24
  78. package/src/programmers/internal/check_string_tags.ts +63 -63
  79. package/src/programmers/internal/check_template.ts +50 -50
  80. package/src/programmers/internal/decode_union_object.ts +73 -73
  81. package/src/programmers/internal/feature_object_entries.ts +49 -49
  82. package/src/programmers/internal/metadata_to_pattern.ts +31 -31
  83. package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
  84. package/src/programmers/internal/stringify_native.ts +8 -8
  85. package/src/programmers/internal/stringify_regular_properties.ts +81 -81
  86. package/src/programmers/internal/template_to_pattern.ts +15 -15
  87. package/src/schemas/IJsonApplication.ts +9 -9
  88. package/src/schemas/IJsonComponents.ts +26 -26
  89. package/src/transform.ts +20 -20
  90. package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
  91. package/src/transformers/FileTransformer.ts +49 -49
  92. package/src/transformers/IProject.ts +11 -11
  93. package/src/transformers/ITransformOptions.ts +11 -0
  94. package/src/transformers/NodeTransformer.ts +19 -19
  95. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
  96. package/src/transformers/features/parsers/AssertParseTransformer.ts +36 -36
  97. package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +32 -32
  98. package/src/transformers/features/parsers/CreateIsParseTransformer.ts +32 -32
  99. package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +32 -32
  100. package/src/transformers/features/parsers/IsParseTransformer.ts +36 -36
  101. package/src/transformers/features/parsers/ValidateParseTransformer.ts +36 -36
  102. package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +38 -38
  103. package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +32 -32
  104. package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +32 -32
  105. package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +31 -31
  106. package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +32 -32
  107. package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +38 -38
  108. package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +38 -38
  109. package/src/transformers/features/validators/AssertTransformer.ts +43 -43
  110. package/src/transformers/features/validators/CreateAssertTransformer.ts +35 -35
  111. package/src/transformers/features/validators/CreateIsTransformer.ts +35 -35
  112. package/src/transformers/features/validators/CreateValidateTransformer.ts +35 -35
  113. package/src/transformers/features/validators/IsTransformer.ts +43 -43
  114. package/src/transformers/features/validators/ValidateTransformer.ts +43 -43
  115. package/src/typings/Atomic.ts +17 -17
  116. package/src/typings/ClassProperties.ts +5 -5
  117. package/src/typings/OmitNever.ts +3 -3
  118. package/src/typings/SpecialFields.ts +3 -3
  119. package/src/typings/Writable.ts +11 -11
  120. package/src/utils/ArrayUtil.ts +49 -49
  121. package/src/utils/Escaper.ts +50 -50
  122. package/src/utils/MapUtil.ts +14 -14
  123. package/src/utils/PatternUtil.ts +30 -30
  124. package/src/utils/Singleton.ts +17 -17
@@ -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
+ }
@@ -1,81 +1,81 @@
1
- import { Metadata } from "../../metadata/Metadata";
2
- import { MetadataObject } from "../../metadata/MetadataObject";
3
- import { MetadataProperty } from "../../metadata/MetadataProperty";
4
-
5
- import { ArrayUtil } from "../../utils/ArrayUtil";
6
- import { MapUtil } from "../../utils/MapUtil";
7
-
8
- export namespace UnionPredicator {
9
- export interface ISpecialized {
10
- index: number;
11
- object: MetadataObject;
12
- property: MetadataProperty;
13
- neighbour: boolean;
14
- }
15
-
16
- export function object(targets: MetadataObject[]): Array<ISpecialized> {
17
- // PROPERTY MATRIX
18
- const matrix: Map<string, Array<MetadataProperty | null>> = new Map();
19
- for (const obj of targets)
20
- for (const prop of obj.properties) {
21
- const key: string | null = prop.key.getSoleLiteral();
22
- if (key !== null)
23
- MapUtil.take(matrix, key, () =>
24
- ArrayUtil.repeat(targets.length, () => null),
25
- );
26
- }
27
- targets.forEach((obj, i) => {
28
- for (const prop of obj.properties) {
29
- const key: string | null = prop.key.getSoleLiteral();
30
- if (key !== null) matrix.get(key)![i] = prop;
31
- }
32
- });
33
-
34
- // EXPLORE SPECIALIZERS
35
- const output: ISpecialized[] = [];
36
- targets.forEach((obj, i) => {
37
- const children: ISpecializedProperty[] = [];
38
- obj.properties.forEach((prop) => {
39
- // MUST BE REQUIRED
40
- if (prop.value.required === false) return;
41
- const key: string | null = prop.key.getSoleLiteral();
42
- if (key === null) return;
43
-
44
- // FIND NEIGHBORHOOD PROPERTIES
45
- const neighbors: MetadataProperty[] = matrix
46
- .get(key)!
47
- .filter(
48
- (oppo, k) => i !== k && oppo !== null,
49
- ) as MetadataProperty[];
50
-
51
- // NO NEIGHBORHOOD
52
- const unique: boolean =
53
- neighbors.length === 0 ||
54
- neighbors.every(
55
- (n) => !Metadata.intersects(prop.value, n.value, false),
56
- );
57
- if (unique === true)
58
- children.push({
59
- property: prop,
60
- neighbour: neighbors.length !== 0,
61
- });
62
- });
63
- if (children.length === 0) return;
64
-
65
- const top: ISpecializedProperty =
66
- children.find((child) => child.property.value.isConstant()) ||
67
- children[0]!;
68
- output.push({
69
- index: i,
70
- object: obj,
71
- ...top,
72
- });
73
- });
74
- return output;
75
- }
76
- }
77
-
78
- interface ISpecializedProperty {
79
- property: MetadataProperty;
80
- neighbour: boolean;
81
- }
1
+ import { Metadata } from "../../metadata/Metadata";
2
+ import { MetadataObject } from "../../metadata/MetadataObject";
3
+ import { MetadataProperty } from "../../metadata/MetadataProperty";
4
+
5
+ import { ArrayUtil } from "../../utils/ArrayUtil";
6
+ import { MapUtil } from "../../utils/MapUtil";
7
+
8
+ export namespace UnionPredicator {
9
+ export interface ISpecialized {
10
+ index: number;
11
+ object: MetadataObject;
12
+ property: MetadataProperty;
13
+ neighbour: boolean;
14
+ }
15
+
16
+ export function object(targets: MetadataObject[]): Array<ISpecialized> {
17
+ // PROPERTY MATRIX
18
+ const matrix: Map<string, Array<MetadataProperty | null>> = new Map();
19
+ for (const obj of targets)
20
+ for (const prop of obj.properties) {
21
+ const key: string | null = prop.key.getSoleLiteral();
22
+ if (key !== null)
23
+ MapUtil.take(matrix, key, () =>
24
+ ArrayUtil.repeat(targets.length, () => null),
25
+ );
26
+ }
27
+ targets.forEach((obj, i) => {
28
+ for (const prop of obj.properties) {
29
+ const key: string | null = prop.key.getSoleLiteral();
30
+ if (key !== null) matrix.get(key)![i] = prop;
31
+ }
32
+ });
33
+
34
+ // EXPLORE SPECIALIZERS
35
+ const output: ISpecialized[] = [];
36
+ targets.forEach((obj, i) => {
37
+ const children: ISpecializedProperty[] = [];
38
+ obj.properties.forEach((prop) => {
39
+ // MUST BE REQUIRED
40
+ if (prop.value.required === false) return;
41
+ const key: string | null = prop.key.getSoleLiteral();
42
+ if (key === null) return;
43
+
44
+ // FIND NEIGHBORHOOD PROPERTIES
45
+ const neighbors: MetadataProperty[] = matrix
46
+ .get(key)!
47
+ .filter(
48
+ (oppo, k) => i !== k && oppo !== null,
49
+ ) as MetadataProperty[];
50
+
51
+ // NO NEIGHBORHOOD
52
+ const unique: boolean =
53
+ neighbors.length === 0 ||
54
+ neighbors.every(
55
+ (n) => !Metadata.intersects(prop.value, n.value, false),
56
+ );
57
+ if (unique === true)
58
+ children.push({
59
+ property: prop,
60
+ neighbour: neighbors.length !== 0,
61
+ });
62
+ });
63
+ if (children.length === 0) return;
64
+
65
+ const top: ISpecializedProperty =
66
+ children.find((child) => child.property.value.isConstant()) ||
67
+ children[0]!;
68
+ output.push({
69
+ index: i,
70
+ object: obj,
71
+ ...top,
72
+ });
73
+ });
74
+ return output;
75
+ }
76
+ }
77
+
78
+ interface ISpecializedProperty {
79
+ property: MetadataProperty;
80
+ neighbour: boolean;
81
+ }