typia 9.7.2 → 10.0.0-dev.20251107

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 (116) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +153 -153
  3. package/lib/factories/ProtobufFactory.js +1 -1
  4. package/lib/factories/ProtobufFactory.mjs +1 -1
  5. package/lib/programmers/internal/json_schema_station.d.mts +2 -2
  6. package/lib/programmers/internal/json_schema_station.d.ts +2 -2
  7. package/lib/programmers/llm/LlmApplicationProgrammer.js +5 -1
  8. package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -1
  9. package/lib/programmers/llm/LlmApplicationProgrammer.mjs +5 -1
  10. package/lib/programmers/llm/LlmSchemaProgrammer.js +1 -4
  11. package/lib/programmers/llm/LlmSchemaProgrammer.js.map +1 -1
  12. package/lib/programmers/llm/LlmSchemaProgrammer.mjs +1 -35
  13. package/package.json +121 -121
  14. package/src/AssertionGuard.ts +41 -41
  15. package/src/CamelCase.ts +75 -75
  16. package/src/IRandomGenerator.ts +337 -337
  17. package/src/IReadableURLSearchParams.ts +9 -9
  18. package/src/PascalCase.ts +71 -71
  19. package/src/Primitive.ts +90 -90
  20. package/src/Resolved.ts +72 -72
  21. package/src/SnakeCase.ts +127 -127
  22. package/src/TypeGuardError.ts +216 -216
  23. package/src/factories/MetadataCollection.ts +270 -270
  24. package/src/factories/MetadataCommentTagFactory.ts +632 -632
  25. package/src/factories/MetadataFactory.ts +402 -402
  26. package/src/factories/ProtobufFactory.ts +873 -873
  27. package/src/functional.ts +705 -705
  28. package/src/http.ts +972 -972
  29. package/src/internal/_ProtobufReader.ts +188 -188
  30. package/src/internal/_ProtobufSizer.ts +137 -137
  31. package/src/internal/_ProtobufWriter.ts +135 -135
  32. package/src/internal/_jsonStringifyString.ts +42 -42
  33. package/src/json.ts +643 -643
  34. package/src/llm.ts +615 -615
  35. package/src/misc.ts +594 -594
  36. package/src/module.ts +889 -889
  37. package/src/notations.ts +751 -751
  38. package/src/programmers/FeatureProgrammer.ts +605 -605
  39. package/src/programmers/ImportProgrammer.ts +179 -179
  40. package/src/programmers/RandomProgrammer.ts +1195 -1195
  41. package/src/programmers/helpers/ProtobufWire.ts +34 -34
  42. package/src/programmers/internal/check_array_length.ts +43 -43
  43. package/src/programmers/internal/check_bigint.ts +46 -46
  44. package/src/programmers/internal/check_dynamic_key.ts +197 -197
  45. package/src/programmers/internal/check_dynamic_properties.ts +231 -231
  46. package/src/programmers/internal/check_everything.ts +21 -21
  47. package/src/programmers/internal/check_native.ts +23 -23
  48. package/src/programmers/internal/check_number.ts +108 -108
  49. package/src/programmers/internal/check_object.ts +72 -72
  50. package/src/programmers/internal/check_string.ts +46 -46
  51. package/src/programmers/internal/check_template.ts +46 -46
  52. package/src/programmers/internal/check_union_array_like.ts +331 -331
  53. package/src/programmers/internal/decode_union_object.ts +110 -110
  54. package/src/programmers/internal/feature_object_entries.ts +59 -59
  55. package/src/programmers/internal/json_schema_escaped.ts +78 -78
  56. package/src/programmers/internal/json_schema_object.ts +150 -150
  57. package/src/programmers/internal/json_schema_station.ts +2 -2
  58. package/src/programmers/internal/metadata_to_pattern.ts +40 -40
  59. package/src/programmers/internal/postfix_of_tuple.ts +3 -3
  60. package/src/programmers/internal/prune_object_properties.ts +69 -69
  61. package/src/programmers/internal/stringify_dynamic_properties.ts +158 -158
  62. package/src/programmers/internal/stringify_native.ts +5 -5
  63. package/src/programmers/internal/stringify_regular_properties.ts +77 -77
  64. package/src/programmers/internal/template_to_pattern.ts +21 -21
  65. package/src/programmers/internal/wrap_metadata_rest_tuple.ts +21 -21
  66. package/src/programmers/json/JsonStringifyProgrammer.ts +1124 -1124
  67. package/src/programmers/llm/LlmApplicationProgrammer.ts +10 -1
  68. package/src/programmers/llm/LlmSchemaProgrammer.ts +2 -7
  69. package/src/protobuf.ts +820 -820
  70. package/src/reflect.ts +46 -46
  71. package/src/schemas/json/IJsonApplication.ts +77 -77
  72. package/src/schemas/json/IJsonSchemaCollection.ts +212 -212
  73. package/src/schemas/json/IJsonSchemaUnit.ts +263 -263
  74. package/src/schemas/metadata/IMetadataTypeTag.ts +14 -14
  75. package/src/schemas/metadata/Metadata.ts +669 -669
  76. package/src/schemas/metadata/MetadataAliasType.ts +57 -57
  77. package/src/schemas/metadata/MetadataApplication.ts +40 -40
  78. package/src/schemas/metadata/MetadataArray.ts +47 -47
  79. package/src/schemas/metadata/MetadataArrayType.ts +51 -51
  80. package/src/schemas/metadata/MetadataAtomic.ts +85 -85
  81. package/src/schemas/metadata/MetadataEscaped.ts +45 -45
  82. package/src/schemas/metadata/MetadataFunction.ts +45 -45
  83. package/src/schemas/metadata/MetadataObject.ts +46 -46
  84. package/src/schemas/metadata/MetadataObjectType.ts +137 -137
  85. package/src/schemas/metadata/MetadataParameter.ts +52 -52
  86. package/src/schemas/metadata/MetadataProperty.ts +53 -53
  87. package/src/schemas/metadata/MetadataTemplate.ts +78 -78
  88. package/src/schemas/metadata/MetadataTuple.ts +28 -28
  89. package/src/schemas/metadata/MetadataTupleType.ts +61 -61
  90. package/src/tags/Constant.ts +47 -47
  91. package/src/tags/ContentMediaType.ts +27 -27
  92. package/src/tags/Default.ts +52 -52
  93. package/src/tags/Example.ts +56 -56
  94. package/src/tags/Examples.ts +56 -56
  95. package/src/tags/ExclusiveMaximum.ts +44 -44
  96. package/src/tags/ExclusiveMinimum.ts +44 -44
  97. package/src/tags/Format.ts +78 -78
  98. package/src/tags/JsonSchemaPlugin.ts +36 -36
  99. package/src/tags/MaxItems.ts +31 -31
  100. package/src/tags/MaxLength.ts +25 -25
  101. package/src/tags/Maximum.ts +39 -39
  102. package/src/tags/MinItems.ts +31 -31
  103. package/src/tags/MinLength.ts +25 -25
  104. package/src/tags/Minimum.ts +39 -39
  105. package/src/tags/MultipleOf.ts +42 -42
  106. package/src/tags/Pattern.ts +49 -49
  107. package/src/tags/Sequence.ts +37 -37
  108. package/src/tags/TagBase.ts +102 -102
  109. package/src/tags/Type.ts +64 -64
  110. package/src/tags/UniqueItems.ts +34 -34
  111. package/src/tags/internal/FormatCheatSheet.ts +71 -71
  112. package/src/transformers/ITransformOptions.ts +70 -70
  113. package/src/transformers/ImportTransformer.ts +253 -253
  114. package/src/transformers/NoTransformConfigurationError.ts +16 -16
  115. package/src/transformers/features/llm/LlmApplicationTransformer.ts +224 -224
  116. package/src/typings/Equal.ts +18 -18
@@ -1,108 +1,108 @@
1
- import ts from "typescript";
2
-
3
- import { ExpressionFactory } from "../../factories/ExpressionFactory";
4
-
5
- import { MetadataAtomic } from "../../schemas/metadata/MetadataAtomic";
6
-
7
- import { ITypiaContext } from "../../transformers/ITypiaContext";
8
-
9
- import { ICheckEntry } from "../helpers/ICheckEntry";
10
- import { OptionPredicator } from "../helpers/OptionPredicator";
11
-
12
- /** @internal */
13
- export const check_number = (props: {
14
- numeric: boolean;
15
- context: ITypiaContext;
16
- atomic: MetadataAtomic;
17
- input: ts.Expression;
18
- }): ICheckEntry => {
19
- const base: ts.BinaryExpression = ts.factory.createStrictEquality(
20
- ts.factory.createStringLiteral("number"),
21
- ts.factory.createTypeOfExpression(props.input),
22
- );
23
- const addition: ts.Expression | null =
24
- props.numeric === true
25
- ? OptionPredicator.finite(props.context.options)
26
- ? ts.factory.createCallExpression(
27
- ts.factory.createIdentifier("Number.isFinite"),
28
- undefined,
29
- [props.input],
30
- )
31
- : OptionPredicator.numeric(props.context.options)
32
- ? ts.factory.createLogicalNot(
33
- ts.factory.createCallExpression(
34
- ts.factory.createIdentifier("Number.isNaN"),
35
- undefined,
36
- [props.input],
37
- ),
38
- )
39
- : null
40
- : null;
41
- const conditions: ICheckEntry.ICondition[][] = check_numeric_type_tags({
42
- context: props.context,
43
- atomic: props.atomic,
44
- input: props.input,
45
- addition,
46
- });
47
- return {
48
- expected: props.atomic.getName(),
49
- expression:
50
- addition !== null && conditions.length === 0
51
- ? ts.factory.createLogicalAnd(base, addition)
52
- : base,
53
- conditions,
54
- };
55
- };
56
-
57
- /** @internal */
58
- const check_numeric_type_tags = (props: {
59
- context: ITypiaContext;
60
- atomic: MetadataAtomic;
61
- addition: ts.Expression | null;
62
- input: ts.Expression;
63
- }): ICheckEntry.ICondition[][] =>
64
- props.atomic.tags
65
- .map((row) => row.filter((tag) => !!tag.validate))
66
- .filter((row) => !!row.length)
67
- .map((row) => [
68
- ...(props.addition === null
69
- ? []
70
- : row.some(
71
- (tag) =>
72
- tag.kind === "type" &&
73
- (tag.value === "int32" ||
74
- tag.value === "uint32" ||
75
- tag.value === "int64" ||
76
- tag.value === "uint64" ||
77
- tag.value === "float"),
78
- ) ||
79
- row.some(
80
- (tag) =>
81
- tag.kind === "multipleOf" && typeof tag.value === "number",
82
- ) ||
83
- (row.some(
84
- (tag) =>
85
- (tag.kind === "minimum" || tag.kind === "exclusiveMinimum") &&
86
- typeof tag.value === "number",
87
- ) &&
88
- row.some(
89
- (tag) =>
90
- (tag.kind === "maximum" || tag.kind === "exclusiveMaximum") &&
91
- typeof tag.value === "number",
92
- ))
93
- ? []
94
- : [
95
- {
96
- expected: "number",
97
- expression: props.addition!,
98
- },
99
- ]),
100
- ...row.map((tag) => ({
101
- expected: `number & ${tag.name}`,
102
- expression: ExpressionFactory.transpile({
103
- transformer: props.context.transformer,
104
- importer: props.context.importer,
105
- script: tag.validate!,
106
- })(props.input),
107
- })),
108
- ]);
1
+ import ts from "typescript";
2
+
3
+ import { ExpressionFactory } from "../../factories/ExpressionFactory";
4
+
5
+ import { MetadataAtomic } from "../../schemas/metadata/MetadataAtomic";
6
+
7
+ import { ITypiaContext } from "../../transformers/ITypiaContext";
8
+
9
+ import { ICheckEntry } from "../helpers/ICheckEntry";
10
+ import { OptionPredicator } from "../helpers/OptionPredicator";
11
+
12
+ /** @internal */
13
+ export const check_number = (props: {
14
+ numeric: boolean;
15
+ context: ITypiaContext;
16
+ atomic: MetadataAtomic;
17
+ input: ts.Expression;
18
+ }): ICheckEntry => {
19
+ const base: ts.BinaryExpression = ts.factory.createStrictEquality(
20
+ ts.factory.createStringLiteral("number"),
21
+ ts.factory.createTypeOfExpression(props.input),
22
+ );
23
+ const addition: ts.Expression | null =
24
+ props.numeric === true
25
+ ? OptionPredicator.finite(props.context.options)
26
+ ? ts.factory.createCallExpression(
27
+ ts.factory.createIdentifier("Number.isFinite"),
28
+ undefined,
29
+ [props.input],
30
+ )
31
+ : OptionPredicator.numeric(props.context.options)
32
+ ? ts.factory.createLogicalNot(
33
+ ts.factory.createCallExpression(
34
+ ts.factory.createIdentifier("Number.isNaN"),
35
+ undefined,
36
+ [props.input],
37
+ ),
38
+ )
39
+ : null
40
+ : null;
41
+ const conditions: ICheckEntry.ICondition[][] = check_numeric_type_tags({
42
+ context: props.context,
43
+ atomic: props.atomic,
44
+ input: props.input,
45
+ addition,
46
+ });
47
+ return {
48
+ expected: props.atomic.getName(),
49
+ expression:
50
+ addition !== null && conditions.length === 0
51
+ ? ts.factory.createLogicalAnd(base, addition)
52
+ : base,
53
+ conditions,
54
+ };
55
+ };
56
+
57
+ /** @internal */
58
+ const check_numeric_type_tags = (props: {
59
+ context: ITypiaContext;
60
+ atomic: MetadataAtomic;
61
+ addition: ts.Expression | null;
62
+ input: ts.Expression;
63
+ }): ICheckEntry.ICondition[][] =>
64
+ props.atomic.tags
65
+ .map((row) => row.filter((tag) => !!tag.validate))
66
+ .filter((row) => !!row.length)
67
+ .map((row) => [
68
+ ...(props.addition === null
69
+ ? []
70
+ : row.some(
71
+ (tag) =>
72
+ tag.kind === "type" &&
73
+ (tag.value === "int32" ||
74
+ tag.value === "uint32" ||
75
+ tag.value === "int64" ||
76
+ tag.value === "uint64" ||
77
+ tag.value === "float"),
78
+ ) ||
79
+ row.some(
80
+ (tag) =>
81
+ tag.kind === "multipleOf" && typeof tag.value === "number",
82
+ ) ||
83
+ (row.some(
84
+ (tag) =>
85
+ (tag.kind === "minimum" || tag.kind === "exclusiveMinimum") &&
86
+ typeof tag.value === "number",
87
+ ) &&
88
+ row.some(
89
+ (tag) =>
90
+ (tag.kind === "maximum" || tag.kind === "exclusiveMaximum") &&
91
+ typeof tag.value === "number",
92
+ ))
93
+ ? []
94
+ : [
95
+ {
96
+ expected: "number",
97
+ expression: props.addition!,
98
+ },
99
+ ]),
100
+ ...row.map((tag) => ({
101
+ expected: `number & ${tag.name}`,
102
+ expression: ExpressionFactory.transpile({
103
+ transformer: props.context.transformer,
104
+ importer: props.context.importer,
105
+ script: tag.validate!,
106
+ })(props.input),
107
+ })),
108
+ ]);
@@ -1,72 +1,72 @@
1
- import ts from "typescript";
2
-
3
- import { ITypiaContext } from "../../transformers/ITypiaContext";
4
-
5
- import { IExpressionEntry } from "../helpers/IExpressionEntry";
6
- import { check_dynamic_properties } from "./check_dynamic_properties";
7
- import { check_everything } from "./check_everything";
8
-
9
- /** @internal */
10
- export const check_object = (props: {
11
- config: check_object.IConfig;
12
- context: ITypiaContext;
13
- input: ts.Expression;
14
- entries: IExpressionEntry<ts.Expression>[];
15
- }) => {
16
- // PREPARE ASSETS
17
- const regular = props.entries.filter((entry) => entry.key.isSoleLiteral());
18
- const dynamic = props.entries.filter((entry) => !entry.key.isSoleLiteral());
19
- const flags: ts.Expression[] = regular.map((entry) => entry.expression);
20
-
21
- // REGULAR WITHOUT DYNAMIC PROPERTIES
22
- if (props.config.equals === false && dynamic.length === 0)
23
- return regular.length === 0
24
- ? props.config.positive
25
- : reduce({
26
- config: props.config,
27
- expressions: flags,
28
- });
29
-
30
- // CHECK DYNAMIC PROPERTIES
31
- flags.push(
32
- check_dynamic_properties({
33
- config: props.config,
34
- context: props.context,
35
- input: props.input,
36
- regular,
37
- dynamic,
38
- }),
39
- );
40
- return reduce({
41
- config: props.config,
42
- expressions: flags,
43
- });
44
- };
45
-
46
- /** @internal */
47
- export namespace check_object {
48
- export interface IConfig {
49
- equals: boolean;
50
- assert: boolean;
51
- undefined: boolean;
52
- halt?: undefined | ((exp: ts.Expression) => ts.Expression);
53
- reduce: (a: ts.Expression, b: ts.Expression) => ts.Expression;
54
- positive: ts.Expression;
55
- superfluous: (
56
- value: ts.Expression,
57
- description?: ts.Expression,
58
- ) => ts.Expression;
59
- entries?: undefined | ts.Identifier;
60
- }
61
- }
62
-
63
- /** @internal */
64
- const reduce = (props: {
65
- config: check_object.IConfig;
66
- expressions: ts.Expression[];
67
- }) =>
68
- props.config.assert
69
- ? props.expressions.reduce(props.config.reduce)
70
- : check_everything(
71
- ts.factory.createArrayLiteralExpression(props.expressions),
72
- );
1
+ import ts from "typescript";
2
+
3
+ import { ITypiaContext } from "../../transformers/ITypiaContext";
4
+
5
+ import { IExpressionEntry } from "../helpers/IExpressionEntry";
6
+ import { check_dynamic_properties } from "./check_dynamic_properties";
7
+ import { check_everything } from "./check_everything";
8
+
9
+ /** @internal */
10
+ export const check_object = (props: {
11
+ config: check_object.IConfig;
12
+ context: ITypiaContext;
13
+ input: ts.Expression;
14
+ entries: IExpressionEntry<ts.Expression>[];
15
+ }) => {
16
+ // PREPARE ASSETS
17
+ const regular = props.entries.filter((entry) => entry.key.isSoleLiteral());
18
+ const dynamic = props.entries.filter((entry) => !entry.key.isSoleLiteral());
19
+ const flags: ts.Expression[] = regular.map((entry) => entry.expression);
20
+
21
+ // REGULAR WITHOUT DYNAMIC PROPERTIES
22
+ if (props.config.equals === false && dynamic.length === 0)
23
+ return regular.length === 0
24
+ ? props.config.positive
25
+ : reduce({
26
+ config: props.config,
27
+ expressions: flags,
28
+ });
29
+
30
+ // CHECK DYNAMIC PROPERTIES
31
+ flags.push(
32
+ check_dynamic_properties({
33
+ config: props.config,
34
+ context: props.context,
35
+ input: props.input,
36
+ regular,
37
+ dynamic,
38
+ }),
39
+ );
40
+ return reduce({
41
+ config: props.config,
42
+ expressions: flags,
43
+ });
44
+ };
45
+
46
+ /** @internal */
47
+ export namespace check_object {
48
+ export interface IConfig {
49
+ equals: boolean;
50
+ assert: boolean;
51
+ undefined: boolean;
52
+ halt?: undefined | ((exp: ts.Expression) => ts.Expression);
53
+ reduce: (a: ts.Expression, b: ts.Expression) => ts.Expression;
54
+ positive: ts.Expression;
55
+ superfluous: (
56
+ value: ts.Expression,
57
+ description?: ts.Expression,
58
+ ) => ts.Expression;
59
+ entries?: undefined | ts.Identifier;
60
+ }
61
+ }
62
+
63
+ /** @internal */
64
+ const reduce = (props: {
65
+ config: check_object.IConfig;
66
+ expressions: ts.Expression[];
67
+ }) =>
68
+ props.config.assert
69
+ ? props.expressions.reduce(props.config.reduce)
70
+ : check_everything(
71
+ ts.factory.createArrayLiteralExpression(props.expressions),
72
+ );
@@ -1,46 +1,46 @@
1
- import ts from "typescript";
2
-
3
- import { ExpressionFactory } from "../../factories/ExpressionFactory";
4
-
5
- import { MetadataAtomic } from "../../schemas/metadata/MetadataAtomic";
6
-
7
- import { ITypiaContext } from "../../transformers/ITypiaContext";
8
-
9
- import { ICheckEntry } from "../helpers/ICheckEntry";
10
-
11
- /** @internal */
12
- export const check_string = (props: {
13
- context: ITypiaContext;
14
- atomic: MetadataAtomic;
15
- input: ts.Expression;
16
- }): ICheckEntry => {
17
- const conditions: ICheckEntry.ICondition[][] = check_string_type_tags(props);
18
- return {
19
- expected: props.atomic.getName(),
20
- expression: ts.factory.createStrictEquality(
21
- ts.factory.createStringLiteral("string"),
22
- ts.factory.createTypeOfExpression(props.input),
23
- ),
24
- conditions,
25
- };
26
- };
27
-
28
- /** @internal */
29
- const check_string_type_tags = (props: {
30
- context: ITypiaContext;
31
- atomic: MetadataAtomic;
32
- input: ts.Expression;
33
- }): ICheckEntry.ICondition[][] =>
34
- props.atomic.tags
35
- .map((row) => row.filter((tag) => !!tag.validate))
36
- .filter((row) => !!row.length)
37
- .map((row) =>
38
- row.map((tag) => ({
39
- expected: `string & ${tag.name}`,
40
- expression: ExpressionFactory.transpile({
41
- transformer: props.context.transformer,
42
- importer: props.context.importer,
43
- script: tag.validate!,
44
- })(props.input),
45
- })),
46
- );
1
+ import ts from "typescript";
2
+
3
+ import { ExpressionFactory } from "../../factories/ExpressionFactory";
4
+
5
+ import { MetadataAtomic } from "../../schemas/metadata/MetadataAtomic";
6
+
7
+ import { ITypiaContext } from "../../transformers/ITypiaContext";
8
+
9
+ import { ICheckEntry } from "../helpers/ICheckEntry";
10
+
11
+ /** @internal */
12
+ export const check_string = (props: {
13
+ context: ITypiaContext;
14
+ atomic: MetadataAtomic;
15
+ input: ts.Expression;
16
+ }): ICheckEntry => {
17
+ const conditions: ICheckEntry.ICondition[][] = check_string_type_tags(props);
18
+ return {
19
+ expected: props.atomic.getName(),
20
+ expression: ts.factory.createStrictEquality(
21
+ ts.factory.createStringLiteral("string"),
22
+ ts.factory.createTypeOfExpression(props.input),
23
+ ),
24
+ conditions,
25
+ };
26
+ };
27
+
28
+ /** @internal */
29
+ const check_string_type_tags = (props: {
30
+ context: ITypiaContext;
31
+ atomic: MetadataAtomic;
32
+ input: ts.Expression;
33
+ }): ICheckEntry.ICondition[][] =>
34
+ props.atomic.tags
35
+ .map((row) => row.filter((tag) => !!tag.validate))
36
+ .filter((row) => !!row.length)
37
+ .map((row) =>
38
+ row.map((tag) => ({
39
+ expected: `string & ${tag.name}`,
40
+ expression: ExpressionFactory.transpile({
41
+ transformer: props.context.transformer,
42
+ importer: props.context.importer,
43
+ script: tag.validate!,
44
+ })(props.input),
45
+ })),
46
+ );
@@ -1,46 +1,46 @@
1
- import ts from "typescript";
2
-
3
- import { MetadataTemplate } from "../../schemas/metadata/MetadataTemplate";
4
-
5
- import { ICheckEntry } from "../helpers/ICheckEntry";
6
- import { template_to_pattern } from "./template_to_pattern";
7
-
8
- /** @internal */
9
- export const check_template = (props: {
10
- templates: MetadataTemplate[];
11
- input: ts.Expression;
12
- }): ICheckEntry => {
13
- // TYPEOF STRING & TAGS
14
- const conditions: ts.Expression[] = [
15
- ts.factory.createStrictEquality(
16
- ts.factory.createStringLiteral("string"),
17
- ts.factory.createTypeOfExpression(props.input),
18
- ),
19
- ];
20
-
21
- // TEMPLATES
22
- const internal: ts.Expression[] = props.templates.map((tpl) =>
23
- ts.factory.createCallExpression(
24
- ts.factory.createIdentifier(
25
- `RegExp(/${template_to_pattern({
26
- top: true,
27
- template: tpl.row,
28
- })}/).test`,
29
- ),
30
- undefined,
31
- [props.input],
32
- ),
33
- );
34
- conditions.push(
35
- internal.length === 1
36
- ? internal[0]!
37
- : internal.reduce((x, y) => ts.factory.createLogicalOr(x, y)),
38
- );
39
-
40
- // COMBINATION
41
- return {
42
- expression: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y)),
43
- conditions: [],
44
- expected: props.templates.map((tpl) => tpl.getName()).join(" | "),
45
- };
46
- };
1
+ import ts from "typescript";
2
+
3
+ import { MetadataTemplate } from "../../schemas/metadata/MetadataTemplate";
4
+
5
+ import { ICheckEntry } from "../helpers/ICheckEntry";
6
+ import { template_to_pattern } from "./template_to_pattern";
7
+
8
+ /** @internal */
9
+ export const check_template = (props: {
10
+ templates: MetadataTemplate[];
11
+ input: ts.Expression;
12
+ }): ICheckEntry => {
13
+ // TYPEOF STRING & TAGS
14
+ const conditions: ts.Expression[] = [
15
+ ts.factory.createStrictEquality(
16
+ ts.factory.createStringLiteral("string"),
17
+ ts.factory.createTypeOfExpression(props.input),
18
+ ),
19
+ ];
20
+
21
+ // TEMPLATES
22
+ const internal: ts.Expression[] = props.templates.map((tpl) =>
23
+ ts.factory.createCallExpression(
24
+ ts.factory.createIdentifier(
25
+ `RegExp(/${template_to_pattern({
26
+ top: true,
27
+ template: tpl.row,
28
+ })}/).test`,
29
+ ),
30
+ undefined,
31
+ [props.input],
32
+ ),
33
+ );
34
+ conditions.push(
35
+ internal.length === 1
36
+ ? internal[0]!
37
+ : internal.reduce((x, y) => ts.factory.createLogicalOr(x, y)),
38
+ );
39
+
40
+ // COMBINATION
41
+ return {
42
+ expression: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y)),
43
+ conditions: [],
44
+ expected: props.templates.map((tpl) => tpl.getName()).join(" | "),
45
+ };
46
+ };