typia 6.1.2 → 6.2.0-dev.20240621

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 (42) hide show
  1. package/lib/factories/internal/metadata/iterate_metadata_intersection.js +35 -10
  2. package/lib/factories/internal/metadata/iterate_metadata_intersection.js.map +1 -1
  3. package/lib/factories/internal/metadata/iterate_metadata_template.js +2 -1
  4. package/lib/factories/internal/metadata/iterate_metadata_template.js.map +1 -1
  5. package/lib/programmers/RandomProgrammer.js +1 -1
  6. package/lib/programmers/RandomProgrammer.js.map +1 -1
  7. package/lib/programmers/internal/application_templates.js +56 -4
  8. package/lib/programmers/internal/application_templates.js.map +1 -1
  9. package/lib/programmers/internal/application_v30_schema.js +1 -1
  10. package/lib/programmers/internal/application_v30_schema.js.map +1 -1
  11. package/lib/programmers/internal/application_v31_schema.js +1 -1
  12. package/lib/programmers/internal/application_v31_schema.js.map +1 -1
  13. package/lib/programmers/internal/check_template.js +2 -16
  14. package/lib/programmers/internal/check_template.js.map +1 -1
  15. package/lib/programmers/internal/metadata_to_pattern.js +2 -2
  16. package/lib/programmers/internal/metadata_to_pattern.js.map +1 -1
  17. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +2 -1
  18. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
  19. package/lib/schemas/metadata/IMetadata.d.ts +2 -1
  20. package/lib/schemas/metadata/IMetadataTemplate.d.ts +6 -0
  21. package/lib/schemas/metadata/IMetadataTemplate.js +3 -0
  22. package/lib/schemas/metadata/IMetadataTemplate.js.map +1 -0
  23. package/lib/schemas/metadata/Metadata.d.ts +2 -1
  24. package/lib/schemas/metadata/Metadata.js +4 -15
  25. package/lib/schemas/metadata/Metadata.js.map +1 -1
  26. package/lib/schemas/metadata/MetadataTemplate.d.ts +15 -0
  27. package/lib/schemas/metadata/MetadataTemplate.js +88 -0
  28. package/lib/schemas/metadata/MetadataTemplate.js.map +1 -0
  29. package/package.json +1 -1
  30. package/src/factories/internal/metadata/iterate_metadata_intersection.ts +34 -9
  31. package/src/factories/internal/metadata/iterate_metadata_template.ts +2 -2
  32. package/src/programmers/RandomProgrammer.ts +3 -2
  33. package/src/programmers/internal/application_templates.ts +42 -5
  34. package/src/programmers/internal/application_v30_schema.ts +1 -1
  35. package/src/programmers/internal/application_v31_schema.ts +1 -1
  36. package/src/programmers/internal/check_template.ts +4 -19
  37. package/src/programmers/internal/metadata_to_pattern.ts +2 -2
  38. package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +2 -1
  39. package/src/schemas/metadata/IMetadata.ts +2 -1
  40. package/src/schemas/metadata/IMetadataTemplate.ts +7 -0
  41. package/src/schemas/metadata/Metadata.ts +5 -19
  42. package/src/schemas/metadata/MetadataTemplate.ts +80 -0
@@ -1,6 +1,6 @@
1
1
  import ts from "typescript";
2
2
 
3
- import { Metadata } from "../../schemas/metadata/Metadata";
3
+ import { MetadataTemplate } from "../../schemas/metadata/MetadataTemplate";
4
4
 
5
5
  import { ICheckEntry } from "../helpers/ICheckEntry";
6
6
  import { template_to_pattern } from "./template_to_pattern";
@@ -9,7 +9,7 @@ import { template_to_pattern } from "./template_to_pattern";
9
9
  * @internal
10
10
  */
11
11
  export const check_template =
12
- (templates: Metadata[][]) =>
12
+ (templates: MetadataTemplate[]) =>
13
13
  (input: ts.Expression): ICheckEntry => {
14
14
  // TYPEOF STRING & TAGS
15
15
  const conditions: ts.Expression[] = [
@@ -23,7 +23,7 @@ export const check_template =
23
23
  const internal: ts.Expression[] = templates.map((tpl) =>
24
24
  ts.factory.createCallExpression(
25
25
  ts.factory.createIdentifier(
26
- `RegExp(/${template_to_pattern(true)(tpl)}/).test`,
26
+ `RegExp(/${template_to_pattern(true)(tpl.row)}/).test`,
27
27
  ),
28
28
  undefined,
29
29
  [input],
@@ -41,21 +41,6 @@ export const check_template =
41
41
  ts.factory.createLogicalAnd(x, y),
42
42
  ),
43
43
  conditions: [],
44
- expected: templates
45
- .map(
46
- (tpl) =>
47
- "`" +
48
- tpl
49
- .map((child) =>
50
- child.isConstant() && child.size() === 1
51
- ? child.constants[0]!.values[0]!.value
52
- : `$\{${child.getName()}\}`,
53
- )
54
- .join("")
55
- .split("`")
56
- .join("\\`") +
57
- "`",
58
- )
59
- .join(" | "),
44
+ expected: templates.map((tpl) => tpl.getName()).join(" | "),
60
45
  };
61
46
  };
@@ -25,8 +25,8 @@ export const metadata_to_pattern =
25
25
  if (a.type === "number" || a.type === "bigint")
26
26
  values.push(PatternUtil.NUMBER);
27
27
  else if (a.type === "boolean") values.push(PatternUtil.BOOLEAN);
28
- for (const childTpl of meta.templates)
29
- values.push("(" + template_to_pattern(false)(childTpl) + ")");
28
+ for (const { row } of meta.templates)
29
+ values.push("(" + template_to_pattern(false)(row) + ")");
30
30
 
31
31
  const pattern: string =
32
32
  values.length === 1 ? values[0]! : "(" + values.join("|") + ")";
@@ -262,7 +262,8 @@ export namespace ProtobufDecodeProgrammer {
262
262
  ) ||
263
263
  value.templates.some(
264
264
  (tpl) =>
265
- tpl.length === 1 && tpl[0]!.getName() === "string",
265
+ tpl.row.length === 1 &&
266
+ tpl.row[0]!.getName() === "string",
266
267
  )
267
268
  ? ts.factory.createStringLiteral("")
268
269
  : value.objects.length &&
@@ -2,6 +2,7 @@ import { IMetadataAtomic } from "./IMetadataAtomic";
2
2
  import { IMetadataConstant } from "./IMetadataConstant";
3
3
  import { IMetadataEntry } from "./IMetadataEntry";
4
4
  import { IMetadataEscaped } from "./IMetadataEscaped";
5
+ import { IMetadataTemplate } from "./IMetadataTemplate";
5
6
  import { IMetadataTypeTag } from "./IMetadataTypeTag";
6
7
 
7
8
  export interface IMetadata {
@@ -13,7 +14,7 @@ export interface IMetadata {
13
14
 
14
15
  atomics: IMetadataAtomic[];
15
16
  constants: IMetadataConstant[];
16
- templates: IMetadata[][];
17
+ templates: IMetadataTemplate[];
17
18
  escaped: IMetadataEscaped | null;
18
19
 
19
20
  rest: IMetadata | null;
@@ -0,0 +1,7 @@
1
+ import { IMetadata } from "./IMetadata";
2
+ import { IMetadataTypeTag } from "./IMetadataTypeTag";
3
+
4
+ export interface IMetadataTemplate {
5
+ row: IMetadata[];
6
+ tags: IMetadataTypeTag[][] | undefined;
7
+ }
@@ -11,6 +11,7 @@ import { MetadataAtomic } from "./MetadataAtomic";
11
11
  import { MetadataConstant } from "./MetadataConstant";
12
12
  import { MetadataEscaped } from "./MetadataEscaped";
13
13
  import { MetadataObject } from "./MetadataObject";
14
+ import { MetadataTemplate } from "./MetadataTemplate";
14
15
  import { MetadataTuple } from "./MetadataTuple";
15
16
 
16
17
  export class Metadata {
@@ -23,7 +24,7 @@ export class Metadata {
23
24
  public escaped: MetadataEscaped | null;
24
25
  public atomics: MetadataAtomic[];
25
26
  public constants: MetadataConstant[];
26
- public templates: Metadata[][];
27
+ public templates: MetadataTemplate[];
27
28
 
28
29
  public rest: Metadata | null;
29
30
  public aliases: MetadataAlias[];
@@ -116,7 +117,7 @@ export class Metadata {
116
117
 
117
118
  atomics: this.atomics.map((a) => a.toJSON()),
118
119
  constants: this.constants.map((c) => c.toJSON()),
119
- templates: this.templates.map((tpl) => tpl.map((meta) => meta.toJSON())),
120
+ templates: this.templates.map((tpl) => tpl.toJSON()),
120
121
  escaped: this.escaped ? this.escaped.toJSON() : null,
121
122
 
122
123
  rest: this.rest ? this.rest.toJSON() : null,
@@ -150,9 +151,7 @@ export class Metadata {
150
151
 
151
152
  constants: meta.constants.map(MetadataConstant.from),
152
153
  atomics: meta.atomics.map(MetadataAtomic.from),
153
- templates: meta.templates.map((tpl) =>
154
- tpl.map((meta) => this.from(meta, dict)),
155
- ),
154
+ templates: meta.templates.map((tpl) => MetadataTemplate.from(tpl, dict)),
156
155
  escaped: meta.escaped ? MetadataEscaped.from(meta.escaped, dict) : null,
157
156
 
158
157
  rest: meta.rest ? this.from(meta.rest, dict) : null,
@@ -551,20 +550,7 @@ const getName = (metadata: Metadata): string => {
551
550
  }
552
551
  for (const constant of metadata.constants)
553
552
  for (const value of constant.values) elements.push(value.getName());
554
- for (const template of metadata.templates)
555
- elements.push(
556
- "`" +
557
- template
558
- .map((child) =>
559
- child.isConstant() && child.size() === 1
560
- ? child.constants[0]!.values[0]!
561
- : `$\{${child.getName()}\}`,
562
- )
563
- .join("")
564
- .split("`")
565
- .join("\\`") +
566
- "`",
567
- );
553
+ for (const template of metadata.templates) elements.push(template.getName());
568
554
 
569
555
  // NATIVES
570
556
  for (const native of metadata.natives) elements.push(native);
@@ -0,0 +1,80 @@
1
+ import { ClassProperties } from "../../typings/ClassProperties";
2
+
3
+ import { IMetadataDictionary } from "./IMetadataDictionary";
4
+ import { IMetadataTemplate } from "./IMetadataTemplate";
5
+ import { IMetadataTypeTag } from "./IMetadataTypeTag";
6
+ import { Metadata } from "./Metadata";
7
+
8
+ export class MetadataTemplate {
9
+ public readonly row: Metadata[];
10
+ public tags: IMetadataTypeTag[][] | undefined;
11
+
12
+ private name_?: string;
13
+
14
+ private constructor(props: ClassProperties<MetadataTemplate>) {
15
+ this.row = props.row.map(Metadata.create);
16
+ this.tags = props.tags;
17
+ }
18
+
19
+ public static create(
20
+ props: ClassProperties<MetadataTemplate>,
21
+ ): MetadataTemplate {
22
+ return new MetadataTemplate(props);
23
+ }
24
+
25
+ public static from(
26
+ json: IMetadataTemplate,
27
+ dict: IMetadataDictionary,
28
+ ): MetadataTemplate {
29
+ return new MetadataTemplate({
30
+ row: json.row.map((m) => Metadata.from(m, dict)),
31
+ tags: json.tags,
32
+ });
33
+ }
34
+
35
+ public getName(): string {
36
+ return (this.name_ ??= getName(this));
37
+ }
38
+
39
+ /**
40
+ * @internal
41
+ */
42
+ public getBaseName(): string {
43
+ return (
44
+ "`" +
45
+ this.row
46
+ .map((child) =>
47
+ child.isConstant() && child.size() === 1
48
+ ? child.constants[0]!.values[0]!.value
49
+ : `$\{${child.getName()}\}`,
50
+ )
51
+ .join("")
52
+ .split("`")
53
+ .join("\\`") +
54
+ "`"
55
+ );
56
+ }
57
+
58
+ public toJSON(): IMetadataTemplate {
59
+ return {
60
+ row: this.row.map((m) => m.toJSON()),
61
+ tags: this.tags,
62
+ };
63
+ }
64
+ }
65
+
66
+ const getName = (template: MetadataTemplate): string => {
67
+ const base: string = template.getBaseName();
68
+ if (!template.tags?.length) return base;
69
+ else if (template.tags.length === 1) {
70
+ const str: string = [base, ...template.tags[0]!.map((t) => t.name)].join(
71
+ " & ",
72
+ );
73
+ return `(${str})`;
74
+ }
75
+ const rows: string[] = template.tags.map((row) => {
76
+ const str: string = row.map((t) => t.name).join(" & ");
77
+ return row.length === 1 ? str : `(${str})`;
78
+ });
79
+ return `(${base} & (${rows.join(" | ")}))`;
80
+ };