typia 3.4.22 → 3.4.24

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 (106) hide show
  1. package/README.md +57 -23
  2. package/lib/programmers/internal/check_dynamic_properties.js +5 -1
  3. package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
  4. package/package.json +1 -1
  5. package/src/IValidation.ts +21 -21
  6. package/src/Primitive.ts +82 -82
  7. package/src/TypeGuardError.ts +36 -36
  8. package/src/executable/internal/CommandParser.ts +15 -15
  9. package/src/factories/CommentFactory.ts +10 -10
  10. package/src/factories/ExpressionFactory.ts +66 -66
  11. package/src/factories/IdentifierFactory.ts +72 -72
  12. package/src/factories/LiteralFactory.ts +44 -44
  13. package/src/factories/StatementFactory.ts +60 -60
  14. package/src/factories/TemplateFactory.ts +56 -56
  15. package/src/factories/TypeFactory.ts +101 -101
  16. package/src/factories/ValueFactory.ts +12 -12
  17. package/src/functional/$every.ts +11 -11
  18. package/src/functional/$is_email.ts +5 -5
  19. package/src/functional/$is_ipv4.ts +5 -5
  20. package/src/functional/$is_ipv6.ts +5 -5
  21. package/src/functional/$is_url.ts +5 -5
  22. package/src/functional/$is_uuid.ts +5 -5
  23. package/src/functional/$join.ts +50 -50
  24. package/src/functional/$report.ts +15 -15
  25. package/src/functional/$rest.ts +3 -3
  26. package/src/functional/$string.ts +37 -37
  27. package/src/functional/$tail.ts +6 -6
  28. package/src/index.ts +4 -4
  29. package/src/metadata/IJsDocTagInfo.ts +10 -10
  30. package/src/metadata/IMetadata.ts +25 -25
  31. package/src/metadata/IMetadataApplication.ts +7 -7
  32. package/src/metadata/IMetadataConstant.ts +16 -16
  33. package/src/metadata/IMetadataEntry.ts +6 -6
  34. package/src/metadata/IMetadataObject.ts +29 -29
  35. package/src/metadata/IMetadataProperty.ts +11 -11
  36. package/src/metadata/MetadataConstant.ts +3 -3
  37. package/src/metadata/MetadataObject.ts +131 -131
  38. package/src/metadata/MetadataProperty.ts +64 -64
  39. package/src/programmers/ApplicationProgrammer.ts +55 -55
  40. package/src/programmers/helpers/AtomicPredicator.ts +15 -15
  41. package/src/programmers/helpers/FunctionImporeter.ts +31 -31
  42. package/src/programmers/helpers/IExpressionEntry.ts +10 -10
  43. package/src/programmers/helpers/StringifyJoinder.ts +111 -111
  44. package/src/programmers/helpers/StringifyPredicator.ts +18 -18
  45. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  46. package/src/programmers/internal/application_array.ts +47 -47
  47. package/src/programmers/internal/application_boolean.ts +17 -17
  48. package/src/programmers/internal/application_constant.ts +29 -29
  49. package/src/programmers/internal/application_default_string.ts +32 -32
  50. package/src/programmers/internal/application_native.ts +29 -29
  51. package/src/programmers/internal/application_number.ts +76 -76
  52. package/src/programmers/internal/application_string.ts +49 -49
  53. package/src/programmers/internal/application_templates.ts +27 -27
  54. package/src/programmers/internal/application_tuple.ts +29 -29
  55. package/src/programmers/internal/check_dynamic_properties.ts +164 -146
  56. package/src/programmers/internal/check_everything.ts +25 -25
  57. package/src/programmers/internal/check_length.ts +46 -46
  58. package/src/programmers/internal/check_native.ts +9 -9
  59. package/src/programmers/internal/check_object.ts +42 -42
  60. package/src/programmers/internal/check_string.ts +24 -24
  61. package/src/programmers/internal/check_string_tags.ts +63 -63
  62. package/src/programmers/internal/check_template.ts +50 -50
  63. package/src/programmers/internal/decode_union_object.ts +73 -73
  64. package/src/programmers/internal/feature_object_entries.ts +49 -49
  65. package/src/programmers/internal/metadata_to_pattern.ts +31 -31
  66. package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
  67. package/src/programmers/internal/stringify_native.ts +8 -8
  68. package/src/programmers/internal/stringify_regular_properties.ts +81 -81
  69. package/src/programmers/internal/template_to_pattern.ts +15 -15
  70. package/src/schemas/IJsonApplication.ts +9 -9
  71. package/src/schemas/IJsonComponents.ts +26 -26
  72. package/src/transform.ts +20 -20
  73. package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
  74. package/src/transformers/FileTransformer.ts +49 -49
  75. package/src/transformers/IProject.ts +11 -11
  76. package/src/transformers/NodeTransformer.ts +19 -19
  77. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
  78. package/src/transformers/features/parsers/AssertParseTransformer.ts +36 -36
  79. package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +32 -32
  80. package/src/transformers/features/parsers/CreateIsParseTransformer.ts +32 -32
  81. package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +32 -32
  82. package/src/transformers/features/parsers/IsParseTransformer.ts +36 -36
  83. package/src/transformers/features/parsers/ValidateParseTransformer.ts +36 -36
  84. package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +38 -38
  85. package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +32 -32
  86. package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +32 -32
  87. package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +31 -31
  88. package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +32 -32
  89. package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +38 -38
  90. package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +38 -38
  91. package/src/transformers/features/validators/AssertTransformer.ts +43 -43
  92. package/src/transformers/features/validators/CreateAssertTransformer.ts +35 -35
  93. package/src/transformers/features/validators/CreateIsTransformer.ts +35 -35
  94. package/src/transformers/features/validators/CreateValidateTransformer.ts +35 -35
  95. package/src/transformers/features/validators/IsTransformer.ts +43 -43
  96. package/src/transformers/features/validators/ValidateTransformer.ts +43 -43
  97. package/src/typings/Atomic.ts +17 -17
  98. package/src/typings/ClassProperties.ts +5 -5
  99. package/src/typings/OmitNever.ts +3 -3
  100. package/src/typings/SpecialFields.ts +3 -3
  101. package/src/typings/Writable.ts +11 -11
  102. package/src/utils/ArrayUtil.ts +49 -49
  103. package/src/utils/Escaper.ts +50 -50
  104. package/src/utils/MapUtil.ts +14 -14
  105. package/src/utils/PatternUtil.ts +30 -30
  106. package/src/utils/Singleton.ts +17 -17
@@ -1,63 +1,63 @@
1
- import ts from "typescript";
2
-
3
- import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
-
5
- import { IMetadataTag } from "../../metadata/IMetadataTag";
6
-
7
- import { FunctionImporter } from "../helpers/FunctionImporeter";
8
- import { check_length } from "./check_length";
9
-
10
- /**
11
- * @internal
12
- */
13
- export const check_string_tags =
14
- (importer: FunctionImporter) =>
15
- (input: ts.Expression, tagList: IMetadataTag[]) => {
16
- const conditions: ts.Expression[] = [];
17
- for (const tag of tagList)
18
- if (tag.kind === "format")
19
- conditions.push(
20
- ts.factory.createStrictEquality(
21
- ts.factory.createTrue(),
22
- ts.factory.createCallExpression(
23
- importer.use(`is_${tag.value}`),
24
- undefined,
25
- [input],
26
- ),
27
- ),
28
- );
29
- else if (tag.kind === "pattern")
30
- conditions.push(
31
- ts.factory.createStrictEquality(
32
- ts.factory.createTrue(),
33
- ts.factory.createCallExpression(
34
- ts.factory.createIdentifier(
35
- `RegExp(/${tag.value}/).test`,
36
- ),
37
- undefined,
38
- [input],
39
- ),
40
- ),
41
- );
42
- else if (tag.kind === "minLength")
43
- conditions.push(
44
- ts.factory.createLessThanEquals(
45
- ts.factory.createNumericLiteral(tag.value),
46
- IdentifierFactory.join(input, "length"),
47
- ),
48
- );
49
- else if (tag.kind === "maxLength")
50
- conditions.push(
51
- ts.factory.createGreaterThanEquals(
52
- ts.factory.createNumericLiteral(tag.value),
53
- IdentifierFactory.join(input, "length"),
54
- ),
55
- );
56
- else if (tag.kind === "length")
57
- check_length(
58
- conditions,
59
- IdentifierFactory.join(input, "length"),
60
- tag,
61
- );
62
- return conditions;
63
- };
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
+
5
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
6
+
7
+ import { FunctionImporter } from "../helpers/FunctionImporeter";
8
+ import { check_length } from "./check_length";
9
+
10
+ /**
11
+ * @internal
12
+ */
13
+ export const check_string_tags =
14
+ (importer: FunctionImporter) =>
15
+ (input: ts.Expression, tagList: IMetadataTag[]) => {
16
+ const conditions: ts.Expression[] = [];
17
+ for (const tag of tagList)
18
+ if (tag.kind === "format")
19
+ conditions.push(
20
+ ts.factory.createStrictEquality(
21
+ ts.factory.createTrue(),
22
+ ts.factory.createCallExpression(
23
+ importer.use(`is_${tag.value}`),
24
+ undefined,
25
+ [input],
26
+ ),
27
+ ),
28
+ );
29
+ else if (tag.kind === "pattern")
30
+ conditions.push(
31
+ ts.factory.createStrictEquality(
32
+ ts.factory.createTrue(),
33
+ ts.factory.createCallExpression(
34
+ ts.factory.createIdentifier(
35
+ `RegExp(/${tag.value}/).test`,
36
+ ),
37
+ undefined,
38
+ [input],
39
+ ),
40
+ ),
41
+ );
42
+ else if (tag.kind === "minLength")
43
+ conditions.push(
44
+ ts.factory.createLessThanEquals(
45
+ ts.factory.createNumericLiteral(tag.value),
46
+ IdentifierFactory.join(input, "length"),
47
+ ),
48
+ );
49
+ else if (tag.kind === "maxLength")
50
+ conditions.push(
51
+ ts.factory.createGreaterThanEquals(
52
+ ts.factory.createNumericLiteral(tag.value),
53
+ IdentifierFactory.join(input, "length"),
54
+ ),
55
+ );
56
+ else if (tag.kind === "length")
57
+ check_length(
58
+ conditions,
59
+ IdentifierFactory.join(input, "length"),
60
+ tag,
61
+ );
62
+ return conditions;
63
+ };
@@ -1,50 +1,50 @@
1
- import ts from "typescript";
2
-
3
- import { IMetadataTag } from "../../metadata/IMetadataTag";
4
- import { Metadata } from "../../metadata/Metadata";
5
-
6
- import { FunctionImporter } from "../helpers/FunctionImporeter";
7
- import { check_string_tags } from "./check_string_tags";
8
- import { template_to_pattern } from "./template_to_pattern";
9
-
10
- /**
11
- * @internal
12
- */
13
- export const check_template =
14
- (importer: FunctionImporter) =>
15
- (
16
- input: ts.Expression,
17
- templates: Metadata[][],
18
- tagList: IMetadataTag[],
19
- ) => {
20
- // TYPEOF STRING & TAGS
21
- const conditions: ts.Expression[] = [
22
- ts.factory.createStrictEquality(
23
- ts.factory.createStringLiteral("string"),
24
- ts.factory.createTypeOfExpression(input),
25
- ),
26
- ...check_string_tags(importer)(input, tagList),
27
- ];
28
-
29
- // TEMPLATES
30
- const internal = templates.map((tpl) =>
31
- ts.factory.createStrictEquality(
32
- ts.factory.createTrue(),
33
- ts.factory.createCallExpression(
34
- ts.factory.createIdentifier(
35
- `RegExp(/${template_to_pattern(true)(tpl)}/).test`,
36
- ),
37
- undefined,
38
- [input],
39
- ),
40
- ),
41
- );
42
- conditions.push(
43
- internal.length === 1
44
- ? internal[0]!
45
- : internal.reduce((x, y) => ts.factory.createLogicalOr(x, y)),
46
- );
47
-
48
- // COMBINATION
49
- return conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
50
- };
1
+ import ts from "typescript";
2
+
3
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
4
+ import { Metadata } from "../../metadata/Metadata";
5
+
6
+ import { FunctionImporter } from "../helpers/FunctionImporeter";
7
+ import { check_string_tags } from "./check_string_tags";
8
+ import { template_to_pattern } from "./template_to_pattern";
9
+
10
+ /**
11
+ * @internal
12
+ */
13
+ export const check_template =
14
+ (importer: FunctionImporter) =>
15
+ (
16
+ input: ts.Expression,
17
+ templates: Metadata[][],
18
+ tagList: IMetadataTag[],
19
+ ) => {
20
+ // TYPEOF STRING & TAGS
21
+ const conditions: ts.Expression[] = [
22
+ ts.factory.createStrictEquality(
23
+ ts.factory.createStringLiteral("string"),
24
+ ts.factory.createTypeOfExpression(input),
25
+ ),
26
+ ...check_string_tags(importer)(input, tagList),
27
+ ];
28
+
29
+ // TEMPLATES
30
+ const internal = templates.map((tpl) =>
31
+ ts.factory.createStrictEquality(
32
+ ts.factory.createTrue(),
33
+ ts.factory.createCallExpression(
34
+ ts.factory.createIdentifier(
35
+ `RegExp(/${template_to_pattern(true)(tpl)}/).test`,
36
+ ),
37
+ undefined,
38
+ [input],
39
+ ),
40
+ ),
41
+ );
42
+ conditions.push(
43
+ internal.length === 1
44
+ ? internal[0]!
45
+ : internal.reduce((x, y) => ts.factory.createLogicalOr(x, y)),
46
+ );
47
+
48
+ // COMBINATION
49
+ return conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
50
+ };
@@ -1,73 +1,73 @@
1
- import ts from "typescript";
2
-
3
- import { MetadataObject } from "../../metadata/MetadataObject";
4
-
5
- import { FeatureProgrammer } from "../FeatureProgrammer";
6
-
7
- /**
8
- * @internal
9
- */
10
- export const decode_union_object =
11
- (
12
- checker: (
13
- input: ts.Expression,
14
- obj: MetadataObject,
15
- explore: FeatureProgrammer.IExplore,
16
- ) => ts.Expression,
17
- ) =>
18
- (
19
- decoder: (
20
- input: ts.Expression,
21
- obj: MetadataObject,
22
- explore: FeatureProgrammer.IExplore,
23
- ) => ts.Expression,
24
- ) =>
25
- (success: (exp: ts.Expression) => ts.Expression) =>
26
- (escaper: (value: ts.Expression, expected: string) => ts.Statement) =>
27
- (
28
- input: ts.Expression,
29
- targets: MetadataObject[],
30
- explore: FeatureProgrammer.IExplore,
31
- ): ts.CallExpression =>
32
- ts.factory.createCallExpression(
33
- ts.factory.createArrowFunction(
34
- undefined,
35
- undefined,
36
- [],
37
- undefined,
38
- undefined,
39
- iterate(escaper)(
40
- input,
41
- targets.map((obj) => ({
42
- type: "object",
43
- is: () => success(checker(input, obj, explore)),
44
- value: () => decoder(input, obj, explore),
45
- })),
46
- `(${targets.map((t) => t.name).join(" | ")})`,
47
- ),
48
- ),
49
- undefined,
50
- undefined,
51
- );
52
-
53
- const iterate =
54
- (escaper: (value: ts.Expression, expected: string) => ts.Statement) =>
55
- (input: ts.Expression, unions: IUnion[], expected: string) =>
56
- ts.factory.createBlock(
57
- [
58
- ...unions.map((u) =>
59
- ts.factory.createIfStatement(
60
- u.is(),
61
- ts.factory.createReturnStatement(u.value()),
62
- ),
63
- ),
64
- escaper(input, expected),
65
- ],
66
- true,
67
- );
68
-
69
- interface IUnion {
70
- type: string;
71
- is: () => ts.Expression;
72
- value: () => ts.Expression;
73
- }
1
+ import ts from "typescript";
2
+
3
+ import { MetadataObject } from "../../metadata/MetadataObject";
4
+
5
+ import { FeatureProgrammer } from "../FeatureProgrammer";
6
+
7
+ /**
8
+ * @internal
9
+ */
10
+ export const decode_union_object =
11
+ (
12
+ checker: (
13
+ input: ts.Expression,
14
+ obj: MetadataObject,
15
+ explore: FeatureProgrammer.IExplore,
16
+ ) => ts.Expression,
17
+ ) =>
18
+ (
19
+ decoder: (
20
+ input: ts.Expression,
21
+ obj: MetadataObject,
22
+ explore: FeatureProgrammer.IExplore,
23
+ ) => ts.Expression,
24
+ ) =>
25
+ (success: (exp: ts.Expression) => ts.Expression) =>
26
+ (escaper: (value: ts.Expression, expected: string) => ts.Statement) =>
27
+ (
28
+ input: ts.Expression,
29
+ targets: MetadataObject[],
30
+ explore: FeatureProgrammer.IExplore,
31
+ ): ts.CallExpression =>
32
+ ts.factory.createCallExpression(
33
+ ts.factory.createArrowFunction(
34
+ undefined,
35
+ undefined,
36
+ [],
37
+ undefined,
38
+ undefined,
39
+ iterate(escaper)(
40
+ input,
41
+ targets.map((obj) => ({
42
+ type: "object",
43
+ is: () => success(checker(input, obj, explore)),
44
+ value: () => decoder(input, obj, explore),
45
+ })),
46
+ `(${targets.map((t) => t.name).join(" | ")})`,
47
+ ),
48
+ ),
49
+ undefined,
50
+ undefined,
51
+ );
52
+
53
+ const iterate =
54
+ (escaper: (value: ts.Expression, expected: string) => ts.Statement) =>
55
+ (input: ts.Expression, unions: IUnion[], expected: string) =>
56
+ ts.factory.createBlock(
57
+ [
58
+ ...unions.map((u) =>
59
+ ts.factory.createIfStatement(
60
+ u.is(),
61
+ ts.factory.createReturnStatement(u.value()),
62
+ ),
63
+ ),
64
+ escaper(input, expected),
65
+ ],
66
+ true,
67
+ );
68
+
69
+ interface IUnion {
70
+ type: string;
71
+ is: () => ts.Expression;
72
+ value: () => ts.Expression;
73
+ }
@@ -1,49 +1,49 @@
1
- import ts from "typescript";
2
-
3
- import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
-
5
- import { MetadataObject } from "../../metadata/MetadataObject";
6
-
7
- import { Escaper } from "../../utils/Escaper";
8
-
9
- import { FeatureProgrammer } from "../FeatureProgrammer";
10
-
11
- export const feature_object_entries =
12
- (config: Pick<FeatureProgrammer.IConfig, "decoder" | "path" | "trace">) =>
13
- (obj: MetadataObject) =>
14
- (input: ts.Expression) =>
15
- obj.properties.map((prop) => {
16
- const sole: string | null = prop.key.getSoleLiteral();
17
- const propInput =
18
- sole === null
19
- ? ts.factory.createIdentifier("value")
20
- : Escaper.variable(sole)
21
- ? ts.factory.createPropertyAccessExpression(
22
- input,
23
- ts.factory.createIdentifier(sole),
24
- )
25
- : ts.factory.createElementAccessExpression(
26
- input,
27
- ts.factory.createStringLiteral(sole),
28
- );
29
-
30
- return {
31
- input: propInput,
32
- key: prop.key,
33
- meta: prop.value,
34
- expression: config.decoder(
35
- propInput,
36
- prop.value,
37
- {
38
- tracable: config.path || config.trace,
39
- source: "object",
40
- from: "object",
41
- postfix:
42
- sole !== null
43
- ? IdentifierFactory.postfix(sole)
44
- : `$join(key)`,
45
- },
46
- prop.tags,
47
- ),
48
- };
49
- });
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
+
5
+ import { MetadataObject } from "../../metadata/MetadataObject";
6
+
7
+ import { Escaper } from "../../utils/Escaper";
8
+
9
+ import { FeatureProgrammer } from "../FeatureProgrammer";
10
+
11
+ export const feature_object_entries =
12
+ (config: Pick<FeatureProgrammer.IConfig, "decoder" | "path" | "trace">) =>
13
+ (obj: MetadataObject) =>
14
+ (input: ts.Expression) =>
15
+ obj.properties.map((prop) => {
16
+ const sole: string | null = prop.key.getSoleLiteral();
17
+ const propInput =
18
+ sole === null
19
+ ? ts.factory.createIdentifier("value")
20
+ : Escaper.variable(sole)
21
+ ? ts.factory.createPropertyAccessExpression(
22
+ input,
23
+ ts.factory.createIdentifier(sole),
24
+ )
25
+ : ts.factory.createElementAccessExpression(
26
+ input,
27
+ ts.factory.createStringLiteral(sole),
28
+ );
29
+
30
+ return {
31
+ input: propInput,
32
+ key: prop.key,
33
+ meta: prop.value,
34
+ expression: config.decoder(
35
+ propInput,
36
+ prop.value,
37
+ {
38
+ tracable: config.path || config.trace,
39
+ source: "object",
40
+ from: "object",
41
+ postfix:
42
+ sole !== null
43
+ ? IdentifierFactory.postfix(sole)
44
+ : `$join(key)`,
45
+ },
46
+ prop.tags,
47
+ ),
48
+ };
49
+ });
@@ -1,31 +1,31 @@
1
- import { Metadata } from "../../metadata/Metadata";
2
-
3
- import { ArrayUtil } from "../../utils/ArrayUtil";
4
- import { PatternUtil } from "../../utils/PatternUtil";
5
-
6
- import { template_to_pattern } from "./template_to_pattern";
7
-
8
- export const metadata_to_pattern =
9
- (top: boolean) =>
10
- (meta: Metadata): string => {
11
- if (meta.atomics.find((type) => type === "string") !== undefined)
12
- return "(.*)";
13
-
14
- const values: string[] = ArrayUtil.flat(
15
- meta.constants.map((c) => {
16
- if (c.type !== "string")
17
- return c.values.map((v) => v.toString());
18
- return c.values.map((str) => PatternUtil.escape(str));
19
- }),
20
- );
21
- for (const type of meta.atomics)
22
- if (type === "number" || type === "bigint")
23
- values.push(PatternUtil.NUMBER);
24
- else if (type === "boolean") values.push(PatternUtil.BOOLEAN);
25
- for (const childTpl of meta.templates)
26
- values.push("(" + template_to_pattern(false)(childTpl) + ")");
27
-
28
- const pattern: string =
29
- values.length === 1 ? values[0]! : "(" + values.join("|") + ")";
30
- return top ? PatternUtil.fix(pattern) : pattern;
31
- };
1
+ import { Metadata } from "../../metadata/Metadata";
2
+
3
+ import { ArrayUtil } from "../../utils/ArrayUtil";
4
+ import { PatternUtil } from "../../utils/PatternUtil";
5
+
6
+ import { template_to_pattern } from "./template_to_pattern";
7
+
8
+ export const metadata_to_pattern =
9
+ (top: boolean) =>
10
+ (meta: Metadata): string => {
11
+ if (meta.atomics.find((type) => type === "string") !== undefined)
12
+ return "(.*)";
13
+
14
+ const values: string[] = ArrayUtil.flat(
15
+ meta.constants.map((c) => {
16
+ if (c.type !== "string")
17
+ return c.values.map((v) => v.toString());
18
+ return c.values.map((str) => PatternUtil.escape(str));
19
+ }),
20
+ );
21
+ for (const type of meta.atomics)
22
+ if (type === "number" || type === "bigint")
23
+ values.push(PatternUtil.NUMBER);
24
+ else if (type === "boolean") values.push(PatternUtil.BOOLEAN);
25
+ for (const childTpl of meta.templates)
26
+ values.push("(" + template_to_pattern(false)(childTpl) + ")");
27
+
28
+ const pattern: string =
29
+ values.length === 1 ? values[0]! : "(" + values.join("|") + ")";
30
+ return top ? PatternUtil.fix(pattern) : pattern;
31
+ };