typia 3.4.15 → 3.5.0-dev.20221222

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 (169) hide show
  1. package/README.md +48 -7
  2. package/lib/factories/MetadataCollection.d.ts +1 -9
  3. package/lib/factories/MetadataCollection.js +2 -75
  4. package/lib/factories/MetadataCollection.js.map +1 -1
  5. package/lib/factories/ProtocolFactory.d.ts +8 -0
  6. package/lib/factories/ProtocolFactory.js +119 -0
  7. package/lib/factories/ProtocolFactory.js.map +1 -0
  8. package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +11 -0
  9. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +76 -0
  10. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -0
  11. package/lib/factories/internal/protocols/emplace_protocol_object.d.ts +3 -0
  12. package/lib/factories/internal/protocols/emplace_protocol_object.js +47 -0
  13. package/lib/factories/internal/protocols/emplace_protocol_object.js.map +1 -0
  14. package/lib/factories/internal/protocols/emplace_protocol_property.d.ts +4 -0
  15. package/lib/factories/internal/protocols/emplace_protocol_property.js +20 -0
  16. package/lib/factories/internal/protocols/emplace_protocol_property.js.map +1 -0
  17. package/lib/factories/internal/protocols/iterate_protocol_atomic.d.ts +3 -0
  18. package/lib/factories/internal/protocols/iterate_protocol_atomic.js +69 -0
  19. package/lib/factories/internal/protocols/iterate_protocol_atomic.js.map +1 -0
  20. package/lib/factories/internal/protocols/iterate_protocol_constant.d.ts +2 -0
  21. package/lib/factories/internal/protocols/iterate_protocol_constant.js +30 -0
  22. package/lib/factories/internal/protocols/iterate_protocol_constant.js.map +1 -0
  23. package/lib/factories/internal/protocols/iterate_protocol_main.d.ts +3 -0
  24. package/lib/factories/internal/protocols/iterate_protocol_main.js +17 -0
  25. package/lib/factories/internal/protocols/iterate_protocol_main.js.map +1 -0
  26. package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +3 -0
  27. package/lib/factories/internal/protocols/iterate_protocol_map.js +71 -0
  28. package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -0
  29. package/lib/factories/internal/protocols/iterate_protocol_metadata.d.ts +5 -0
  30. package/lib/factories/internal/protocols/iterate_protocol_metadata.js +192 -0
  31. package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -0
  32. package/lib/factories/internal/protocols/iterate_protocol_native.d.ts +2 -0
  33. package/lib/factories/internal/protocols/iterate_protocol_native.js +33 -0
  34. package/lib/factories/internal/protocols/iterate_protocol_native.js.map +1 -0
  35. package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +4 -0
  36. package/lib/factories/internal/protocols/iterate_protocol_repeated.js +24 -0
  37. package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -0
  38. package/lib/factories/internal/protocols/iterate_protocol_tuple.d.ts +3 -0
  39. package/lib/factories/internal/protocols/iterate_protocol_tuple.js +46 -0
  40. package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -0
  41. package/lib/functional/$proto_bytes.d.ts +2 -0
  42. package/lib/functional/$proto_bytes.js +37 -0
  43. package/lib/functional/$proto_bytes.js.map +1 -0
  44. package/lib/functional/$proto_field.d.ts +10 -0
  45. package/lib/functional/$proto_field.js +42 -0
  46. package/lib/functional/$proto_field.js.map +1 -0
  47. package/lib/functional/$proto_float.d.ts +4 -0
  48. package/lib/functional/$proto_float.js +28 -0
  49. package/lib/functional/$proto_float.js.map +1 -0
  50. package/lib/functional/$proto_i32.d.ts +2 -0
  51. package/lib/functional/$proto_i32.js +23 -0
  52. package/lib/functional/$proto_i32.js.map +1 -0
  53. package/lib/functional/$proto_i64.d.ts +2 -0
  54. package/lib/functional/$proto_i64.js +31 -0
  55. package/lib/functional/$proto_i64.js.map +1 -0
  56. package/lib/functional/$proto_size.d.ts +6 -0
  57. package/lib/functional/$proto_size.js +76 -0
  58. package/lib/functional/$proto_size.js.map +1 -0
  59. package/lib/functional/$proto_string.d.ts +2 -0
  60. package/lib/functional/$proto_string.js +34 -0
  61. package/lib/functional/$proto_string.js.map +1 -0
  62. package/lib/functional/$varint.d.ts +6 -0
  63. package/lib/functional/$varint.js +99 -0
  64. package/lib/functional/$varint.js.map +1 -0
  65. package/lib/functional/$zigzag.d.ts +4 -0
  66. package/lib/functional/$zigzag.js +34 -0
  67. package/lib/functional/$zigzag.js.map +1 -0
  68. package/lib/messages/IProtocolMessage.d.ts +5 -0
  69. package/lib/messages/IProtocolMessage.js +3 -0
  70. package/lib/messages/IProtocolMessage.js.map +1 -0
  71. package/lib/messages/IProtocolProperty.d.ts +11 -0
  72. package/lib/messages/IProtocolProperty.js +3 -0
  73. package/lib/messages/IProtocolProperty.js.map +1 -0
  74. package/lib/metadata/IMetadataTag.d.ts +7 -3
  75. package/lib/metadata/Metadata.js +1 -1
  76. package/lib/metadata/Metadata.js.map +1 -1
  77. package/lib/module.d.ts +2 -0
  78. package/lib/module.js +5 -1
  79. package/lib/module.js.map +1 -1
  80. package/lib/programmers/MessageProgrammer.d.ts +5 -0
  81. package/lib/programmers/MessageProgrammer.js +134 -0
  82. package/lib/programmers/MessageProgrammer.js.map +1 -0
  83. package/lib/programmers/internal/application_object.js +9 -9
  84. package/lib/programmers/internal/application_object.js.map +1 -1
  85. package/lib/programmers/internal/application_schema.js +5 -3
  86. package/lib/programmers/internal/application_schema.js.map +1 -1
  87. package/lib/transformers/CallExpressionTransformer.js +3 -1
  88. package/lib/transformers/CallExpressionTransformer.js.map +1 -1
  89. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +1 -3
  90. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
  91. package/lib/transformers/features/protocols/MessageTransformer.d.ts +5 -0
  92. package/lib/transformers/features/protocols/MessageTransformer.js +17 -0
  93. package/lib/transformers/features/protocols/MessageTransformer.js.map +1 -0
  94. package/lib/utils/NameEncoder.d.ts +4 -0
  95. package/lib/utils/NameEncoder.js +89 -0
  96. package/lib/utils/NameEncoder.js.map +1 -0
  97. package/package.json +2 -3
  98. package/src/executable/internal/TypiaSetupWizard.ts +173 -173
  99. package/src/factories/MetadataCollection.ts +83 -122
  100. package/src/factories/MetadataFactory.ts +47 -47
  101. package/src/factories/MetadataTagFactory.ts +351 -351
  102. package/src/factories/ProtocolFactory.ts +92 -0
  103. package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
  104. package/src/factories/internal/metadata/emplace_metadata_object.ts +140 -140
  105. package/src/factories/internal/metadata/explore_metadata.ts +92 -92
  106. package/src/factories/internal/metadata/iterate_metadata.ts +80 -80
  107. package/src/factories/internal/metadata/iterate_metadata_array.ts +29 -29
  108. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
  109. package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
  110. package/src/factories/internal/metadata/iterate_metadata_constant.ts +58 -58
  111. package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
  112. package/src/factories/internal/metadata/iterate_metadata_native.ts +227 -227
  113. package/src/factories/internal/metadata/iterate_metadata_object.ts +48 -48
  114. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +27 -27
  115. package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
  116. package/src/factories/internal/metadata/iterate_metadata_template.ts +38 -38
  117. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +45 -45
  118. package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
  119. package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +81 -0
  120. package/src/factories/internal/protocols/emplace_protocol_object.ts +25 -0
  121. package/src/factories/internal/protocols/emplace_protocol_property.ts +12 -0
  122. package/src/factories/internal/protocols/iterate_protocol_atomic.ts +34 -0
  123. package/src/factories/internal/protocols/iterate_protocol_constant.ts +27 -0
  124. package/src/factories/internal/protocols/iterate_protocol_main.ts +19 -0
  125. package/src/factories/internal/protocols/iterate_protocol_map.ts +38 -0
  126. package/src/factories/internal/protocols/iterate_protocol_metadata.ts +76 -0
  127. package/src/factories/internal/protocols/iterate_protocol_native.ts +34 -0
  128. package/src/factories/internal/protocols/iterate_protocol_repeated.ts +25 -0
  129. package/src/factories/internal/protocols/iterate_protocol_tuple.ts +25 -0
  130. package/src/functional/$number.ts +12 -12
  131. package/src/functional/$proto_bytes.ts +25 -0
  132. package/src/functional/$proto_field.ts +30 -0
  133. package/src/functional/$proto_float.ts +37 -0
  134. package/src/functional/$proto_i32.ts +29 -0
  135. package/src/functional/$proto_i64.ts +37 -0
  136. package/src/functional/$proto_size.ts +82 -0
  137. package/src/functional/$proto_string.ts +24 -0
  138. package/src/functional/$varint.ts +130 -0
  139. package/src/functional/$zigzag.ts +39 -0
  140. package/src/messages/IProtocolMessage.ts +6 -0
  141. package/src/messages/IProtocolProperty.ts +11 -0
  142. package/src/metadata/IMetadataTag.ts +137 -122
  143. package/src/metadata/Metadata.ts +479 -477
  144. package/src/module.ts +1547 -1535
  145. package/src/programmers/AssertParseProgrammer.ts +55 -55
  146. package/src/programmers/AssertProgrammer.ts +445 -445
  147. package/src/programmers/AssertStringifyProgrammer.ts +65 -65
  148. package/src/programmers/CheckerProgrammer.ts +810 -810
  149. package/src/programmers/IsParseProgrammer.ts +61 -61
  150. package/src/programmers/IsProgrammer.ts +175 -175
  151. package/src/programmers/IsStringifyProgrammer.ts +69 -69
  152. package/src/programmers/MessageProgrammer.ts +116 -0
  153. package/src/programmers/StringifyProgrammer.ts +762 -762
  154. package/src/programmers/ValidateParseProgrammer.ts +59 -59
  155. package/src/programmers/ValidateProgrammer.ts +237 -237
  156. package/src/programmers/ValidateStringifyProgrammer.ts +80 -80
  157. package/src/programmers/helpers/OptionPredicator.ts +15 -15
  158. package/src/programmers/internal/application_default.ts +17 -17
  159. package/src/programmers/internal/application_object.ts +5 -5
  160. package/src/programmers/internal/application_schema.ts +231 -228
  161. package/src/programmers/internal/check_bigint.ts +85 -85
  162. package/src/programmers/internal/check_number.ts +175 -175
  163. package/src/schemas/IJsonSchema.ts +90 -90
  164. package/src/transformers/CallExpressionTransformer.ts +131 -124
  165. package/src/transformers/ITransformOptions.ts +47 -47
  166. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +117 -119
  167. package/src/transformers/features/protocols/MessageTransformer.ts +32 -0
  168. package/src/transformers/features/stringifiers/StringifyTransformer.ts +46 -46
  169. package/src/utils/NameEncoder.ts +32 -0
@@ -1,38 +1,38 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../../metadata/Metadata";
4
-
5
- import { MetadataCollection } from "../../MetadataCollection";
6
- import { MetadataFactory } from "../../MetadataFactory";
7
- import { MetadataHelper } from "./MetadataHelper";
8
- import { explore_metadata } from "./explore_metadata";
9
-
10
- export const iterate_metadata_template =
11
- (checker: ts.TypeChecker) =>
12
- (options: MetadataFactory.IOptions) =>
13
- (collection: MetadataCollection) =>
14
- (meta: Metadata, type: ts.Type): boolean => {
15
- const filter = (flag: ts.TypeFlags) => (type.getFlags() & flag) !== 0;
16
- if (!filter(ts.TypeFlags.TemplateLiteral)) return false;
17
-
18
- const template: ts.TemplateLiteralType = type as ts.TemplateLiteralType;
19
- const row: Metadata[] = [];
20
-
21
- template.texts.forEach((text, i) => {
22
- // TEXT LITERAL TYPE
23
- if (text !== "") row.push(MetadataHelper.literal_to_metadata(text));
24
-
25
- // BINDED TEMPLATE TYPE
26
- const binded: ts.Type | undefined = template.types[i];
27
- if (binded)
28
- row.push(
29
- explore_metadata(checker)(options)(collection)(
30
- binded,
31
- false,
32
- ),
33
- );
34
- });
35
- meta.templates.push(row);
36
-
37
- return true;
38
- };
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../../metadata/Metadata";
4
+
5
+ import { MetadataCollection } from "../../MetadataCollection";
6
+ import { MetadataFactory } from "../../MetadataFactory";
7
+ import { MetadataHelper } from "./MetadataHelper";
8
+ import { explore_metadata } from "./explore_metadata";
9
+
10
+ export const iterate_metadata_template =
11
+ (checker: ts.TypeChecker) =>
12
+ (options: MetadataFactory.IOptions) =>
13
+ (collection: MetadataCollection) =>
14
+ (meta: Metadata, type: ts.Type): boolean => {
15
+ const filter = (flag: ts.TypeFlags) => (type.getFlags() & flag) !== 0;
16
+ if (!filter(ts.TypeFlags.TemplateLiteral)) return false;
17
+
18
+ const template: ts.TemplateLiteralType = type as ts.TemplateLiteralType;
19
+ const row: Metadata[] = [];
20
+
21
+ template.texts.forEach((text, i) => {
22
+ // TEXT LITERAL TYPE
23
+ if (text !== "") row.push(MetadataHelper.literal_to_metadata(text));
24
+
25
+ // BINDED TEMPLATE TYPE
26
+ const binded: ts.Type | undefined = template.types[i];
27
+ if (binded)
28
+ row.push(
29
+ explore_metadata(checker)(options)(collection)(
30
+ binded,
31
+ false,
32
+ ),
33
+ );
34
+ });
35
+ meta.templates.push(row);
36
+
37
+ return true;
38
+ };
@@ -1,45 +1,45 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../../metadata/Metadata";
4
-
5
- import { Writable } from "../../../typings/Writable";
6
-
7
- import { ArrayUtil } from "../../../utils/ArrayUtil";
8
-
9
- import { MetadataCollection } from "../../MetadataCollection";
10
- import { MetadataFactory } from "../../MetadataFactory";
11
- import { explore_metadata } from "./explore_metadata";
12
-
13
- export const iterate_metadata_tuple =
14
- (checker: ts.TypeChecker) =>
15
- (options: MetadataFactory.IOptions) =>
16
- (collection: MetadataCollection) =>
17
- (meta: Metadata, type: ts.TupleType): boolean => {
18
- if (!(checker as any).isTupleType(type)) return false;
19
-
20
- const elementFlags: readonly ts.ElementFlags[] =
21
- type.elementFlags ??
22
- (type.target as ts.TupleType)?.elementFlags ??
23
- [];
24
-
25
- const children: Metadata[] = checker
26
- .getTypeArguments(type as ts.TypeReference)
27
- .map((elem, i) => {
28
- const child: Metadata = explore_metadata(checker)(options)(
29
- collection,
30
- )(elem, false);
31
-
32
- const flag: ts.ElementFlags | undefined = elementFlags[i];
33
- if (flag !== ts.ElementFlags.Rest) return child;
34
-
35
- const wrapper: Metadata = Metadata.initialize();
36
- Writable(wrapper).rest = child;
37
- return wrapper;
38
- });
39
- ArrayUtil.set(meta.tuples, children, join_tuple_names);
40
- return true;
41
- };
42
-
43
- function join_tuple_names(metas: Metadata[]): string {
44
- return `[${metas.map((m) => m.getName).join(", ")}]`;
45
- }
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../../metadata/Metadata";
4
+
5
+ import { Writable } from "../../../typings/Writable";
6
+
7
+ import { ArrayUtil } from "../../../utils/ArrayUtil";
8
+
9
+ import { MetadataCollection } from "../../MetadataCollection";
10
+ import { MetadataFactory } from "../../MetadataFactory";
11
+ import { explore_metadata } from "./explore_metadata";
12
+
13
+ export const iterate_metadata_tuple =
14
+ (checker: ts.TypeChecker) =>
15
+ (options: MetadataFactory.IOptions) =>
16
+ (collection: MetadataCollection) =>
17
+ (meta: Metadata, type: ts.TupleType): boolean => {
18
+ if (!(checker as any).isTupleType(type)) return false;
19
+
20
+ const elementFlags: readonly ts.ElementFlags[] =
21
+ type.elementFlags ??
22
+ (type.target as ts.TupleType)?.elementFlags ??
23
+ [];
24
+
25
+ const children: Metadata[] = checker
26
+ .getTypeArguments(type as ts.TypeReference)
27
+ .map((elem, i) => {
28
+ const child: Metadata = explore_metadata(checker)(options)(
29
+ collection,
30
+ )(elem, false);
31
+
32
+ const flag: ts.ElementFlags | undefined = elementFlags[i];
33
+ if (flag !== ts.ElementFlags.Rest) return child;
34
+
35
+ const wrapper: Metadata = Metadata.initialize();
36
+ Writable(wrapper).rest = child;
37
+ return wrapper;
38
+ });
39
+ ArrayUtil.set(meta.tuples, children, join_tuple_names);
40
+ return true;
41
+ };
42
+
43
+ function join_tuple_names(metas: Metadata[]): string {
44
+ return `[${metas.map((m) => m.getName).join(", ")}]`;
45
+ }
@@ -1,59 +1,59 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../../metadata/Metadata";
4
-
5
- import { Writable } from "../../../typings/Writable";
6
-
7
- import { MetadataCollection } from "../../MetadataCollection";
8
- import { MetadataFactory } from "../../MetadataFactory";
9
- import { TypeFactory } from "../../TypeFactory";
10
- import { iterate_metadata } from "./iterate_metadata";
11
-
12
- export const iterate_metadata_union =
13
- (checker: ts.TypeChecker) =>
14
- (options: MetadataFactory.IOptions) =>
15
- (collection: MetadataCollection) =>
16
- (meta: Metadata, type: ts.Type, parentResolved: boolean): boolean => {
17
- if (!type.isUnion()) return false;
18
- else if (options.resolve === false || parentResolved === true) {
19
- type.types.forEach((t) =>
20
- iterate_metadata(checker)(options)(collection)(meta, t, false),
21
- );
22
- return true;
23
- }
24
-
25
- const filter = (flag: ts.TypeFlags, t: ts.Type) =>
26
- (t.getFlags() & flag) !== 0;
27
- const normals: ts.Type[] = [];
28
- const toJsons: ts.Type[] = [];
29
-
30
- for (const individual of type.types) {
31
- if (filter(ts.TypeFlags.Object, individual)) {
32
- const resolved: ts.Type | null = TypeFactory.resolve(
33
- checker,
34
- individual,
35
- );
36
- if (resolved !== null) toJsons.push(resolved);
37
- else normals.push(individual);
38
- } else normals.push(individual);
39
- }
40
- if (toJsons.length !== 0) {
41
- Writable(meta).resolved = (() => {
42
- const union: Metadata = Metadata.initialize();
43
- toJsons.forEach((t) =>
44
- iterate_metadata(checker)(options)(collection)(
45
- meta,
46
- t,
47
- true,
48
- ),
49
- );
50
- if (union.objects.length > 1)
51
- union.union_index = collection.getUnionIndex(union);
52
- return union;
53
- })();
54
- }
55
- normals.forEach((t) =>
56
- iterate_metadata(checker)(options)(collection)(meta, t, false),
57
- );
58
- return true;
59
- };
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../../metadata/Metadata";
4
+
5
+ import { Writable } from "../../../typings/Writable";
6
+
7
+ import { MetadataCollection } from "../../MetadataCollection";
8
+ import { MetadataFactory } from "../../MetadataFactory";
9
+ import { TypeFactory } from "../../TypeFactory";
10
+ import { iterate_metadata } from "./iterate_metadata";
11
+
12
+ export const iterate_metadata_union =
13
+ (checker: ts.TypeChecker) =>
14
+ (options: MetadataFactory.IOptions) =>
15
+ (collection: MetadataCollection) =>
16
+ (meta: Metadata, type: ts.Type, parentResolved: boolean): boolean => {
17
+ if (!type.isUnion()) return false;
18
+ else if (options.resolve === false || parentResolved === true) {
19
+ type.types.forEach((t) =>
20
+ iterate_metadata(checker)(options)(collection)(meta, t, false),
21
+ );
22
+ return true;
23
+ }
24
+
25
+ const filter = (flag: ts.TypeFlags, t: ts.Type) =>
26
+ (t.getFlags() & flag) !== 0;
27
+ const normals: ts.Type[] = [];
28
+ const toJsons: ts.Type[] = [];
29
+
30
+ for (const individual of type.types) {
31
+ if (filter(ts.TypeFlags.Object, individual)) {
32
+ const resolved: ts.Type | null = TypeFactory.resolve(
33
+ checker,
34
+ individual,
35
+ );
36
+ if (resolved !== null) toJsons.push(resolved);
37
+ else normals.push(individual);
38
+ } else normals.push(individual);
39
+ }
40
+ if (toJsons.length !== 0) {
41
+ Writable(meta).resolved = (() => {
42
+ const union: Metadata = Metadata.initialize();
43
+ toJsons.forEach((t) =>
44
+ iterate_metadata(checker)(options)(collection)(
45
+ meta,
46
+ t,
47
+ true,
48
+ ),
49
+ );
50
+ if (union.objects.length > 1)
51
+ union.union_index = collection.getUnionIndex(union);
52
+ return union;
53
+ })();
54
+ }
55
+ normals.forEach((t) =>
56
+ iterate_metadata(checker)(options)(collection)(meta, t, false),
57
+ );
58
+ return true;
59
+ };
@@ -0,0 +1,81 @@
1
+ import { IMetadataTag } from "../../../metadata/IMetadataTag";
2
+ import { Metadata } from "../../../metadata/Metadata";
3
+ import { MetadataObject } from "../../../metadata/MetadataObject";
4
+ import { MetadataProperty } from "../../../metadata/MetadataProperty";
5
+
6
+ export namespace ProtocolMetadataUtil {
7
+ export function size(meta: Metadata): number {
8
+ return (
9
+ meta.atomics.length +
10
+ meta.constants.filter(
11
+ (c) =>
12
+ meta.atomics.find((type) => c.type === type) === undefined,
13
+ ).length +
14
+ (meta.templates.length !== 0 &&
15
+ meta.atomics.find((type) => type === "string") === undefined &&
16
+ meta.constants.find((c) => c.type === "string") === undefined
17
+ ? 1
18
+ : 0) +
19
+ meta.tuples.length +
20
+ meta.arrays.length +
21
+ meta.sets.length +
22
+ meta.maps.length +
23
+ meta.objects.length +
24
+ meta.natives.filter((n) => n === "Date").length +
25
+ (meta.natives.filter((n) => n !== "Date").length ? 1 : 0)
26
+ );
27
+ }
28
+
29
+ export function standalone(meta: Metadata): boolean {
30
+ return (
31
+ size(meta) === 1 &&
32
+ meta.required === true &&
33
+ meta.nullable === false &&
34
+ meta.tuples.length === 0 &&
35
+ meta.arrays.length === 0 &&
36
+ meta.sets.length === 0 &&
37
+ meta.maps.length === 0 &&
38
+ meta.objects.every((obj) =>
39
+ obj.properties.every((p) => p.key.isSoleLiteral()),
40
+ )
41
+ );
42
+ }
43
+
44
+ export function regular(obj: MetadataObject): boolean {
45
+ return obj.properties.every((p) => p.key.isSoleLiteral());
46
+ }
47
+
48
+ export function object(name: string, index: number): MetadataObject {
49
+ return MetadataObject.create({
50
+ name,
51
+ index,
52
+ properties: [],
53
+ description: undefined,
54
+ jsDocTags: [],
55
+ validated: false,
56
+ recursive: false,
57
+ nullables: [false],
58
+ });
59
+ }
60
+
61
+ export function property(
62
+ key: string,
63
+ value: Metadata,
64
+ tags: IMetadataTag[],
65
+ ): MetadataProperty {
66
+ return MetadataProperty.create({
67
+ key: (() => {
68
+ const meta: Metadata = Metadata.initialize();
69
+ meta.constants.push({
70
+ type: "string",
71
+ values: [key],
72
+ });
73
+ return meta;
74
+ })(),
75
+ value: value,
76
+ description: undefined,
77
+ tags,
78
+ jsDocTags: [],
79
+ });
80
+ }
81
+ }
@@ -0,0 +1,25 @@
1
+ import { MetadataObject } from "../../../metadata/MetadataObject";
2
+
3
+ import { IProtocolMessage } from "../../../messages/IProtocolMessage";
4
+ import { emplace_protocol_property } from "./emplace_protocol_property";
5
+
6
+ export const emplace_protocol_object =
7
+ (dict: Map<string, IProtocolMessage>) => (object: MetadataObject) => {
8
+ if (dict.has(object.name)) return;
9
+
10
+ const regular = object.properties.filter((p) => p.key.isSoleLiteral());
11
+ const dynamic = object.properties.filter((p) => !p.key.isSoleLiteral());
12
+
13
+ if (!regular.length || dynamic.length) return;
14
+
15
+ const output: IProtocolMessage = {
16
+ name: object.name,
17
+ properties: [],
18
+ };
19
+ dict.set(object.name, output);
20
+
21
+ output.properties.push(
22
+ ...regular.map((prop) => emplace_protocol_property(dict)(prop)),
23
+ );
24
+ return output;
25
+ };
@@ -0,0 +1,12 @@
1
+ import { MetadataProperty } from "../../../metadata/MetadataProperty";
2
+
3
+ import { IProtocolMessage } from "../../../messages/IProtocolMessage";
4
+ import { IProtocolProperty } from "../../../messages/IProtocolProperty";
5
+ import { iterate_protocol_metadata } from "./iterate_protocol_metadata";
6
+
7
+ export const emplace_protocol_property =
8
+ (dict: Map<string, IProtocolMessage>) =>
9
+ (property: MetadataProperty): IProtocolProperty => ({
10
+ key: property.key.getSoleLiteral()!,
11
+ ...iterate_protocol_metadata(dict)(property.value)(property.tags),
12
+ });
@@ -0,0 +1,34 @@
1
+ import { IMetadataTag } from "../../../metadata/IMetadataTag";
2
+
3
+ import { Atomic } from "../../../typings/Atomic";
4
+
5
+ export const iterate_protocol_atomic =
6
+ (tags: IMetadataTag[]) => (type: Atomic.Literal) => {
7
+ if (type === "boolean") return "bool";
8
+ else if (type === "number") return number(tags);
9
+ else if (type === "bigint") return bigint(tags);
10
+ else return "string";
11
+ };
12
+
13
+ const number = (tagList: IMetadataTag[]) => {
14
+ const filtered: IMetadataTag.INumberType[] = tagList.filter(
15
+ (tag) => tag.kind === "type",
16
+ ) as IMetadataTag.INumberType[];
17
+
18
+ for (const { value } of filtered)
19
+ if (value === "int") return "int32";
20
+ else if (value === "uint") return "uint32";
21
+ return "double";
22
+ };
23
+
24
+ const bigint = (tagList: IMetadataTag[]) => {
25
+ const filtered: IMetadataTag.IBigintType[] = tagList.filter(
26
+ (tag) =>
27
+ tag.kind === "type" &&
28
+ (tag.value === "int64" || tag.value === "uint64"),
29
+ ) as IMetadataTag.IBigintType[];
30
+
31
+ for (const { value } of filtered)
32
+ if (value === "int64" || value === "uint64") return value;
33
+ return "int64";
34
+ };
@@ -0,0 +1,27 @@
1
+ import { MetadataConstant } from "../../../metadata/MetadataConstant";
2
+
3
+ export const iterate_protocol_constant = ({
4
+ type,
5
+ values,
6
+ }: MetadataConstant) => {
7
+ if (type === "boolean") return "bool";
8
+ else if (type === "number") return number(values);
9
+ else if (type === "bigint") return bigint(values);
10
+ else return "string";
11
+ };
12
+
13
+ const bigint = (values: bigint[]): string => {
14
+ return values.every((v) => v >= BigInt(0)) ? "uint64" : "int64";
15
+ };
16
+
17
+ const number = (values: number[]): string => {
18
+ return values.some((v) => Math.floor(v) !== v)
19
+ ? "double"
20
+ : values.every((v) => v >= 0)
21
+ ? values.every((v) => v <= 2 ** 64 - 1)
22
+ ? "uint32"
23
+ : "uint64"
24
+ : values.every((v) => -(2 ** 31) <= v && v <= 2 ** 31 - 1)
25
+ ? "int32"
26
+ : "int64";
27
+ };
@@ -0,0 +1,19 @@
1
+ import { Metadata } from "../../../metadata/Metadata";
2
+
3
+ import { IProtocolMessage } from "../../../messages/IProtocolMessage";
4
+ import { ProtocolMetadataUtil } from "./ProtocolMetadataUtil";
5
+ import { emplace_protocol_object } from "./emplace_protocol_object";
6
+
7
+ export const iterate_protocol_main =
8
+ (dict: Map<string, IProtocolMessage>) =>
9
+ (meta: Metadata): string => {
10
+ // ONLY ONE OBJECT TYPE
11
+ if (ProtocolMetadataUtil.standalone(meta) && meta.objects.length === 1)
12
+ return meta.getName();
13
+
14
+ const obj = ProtocolMetadataUtil.object("__Main", dict.size);
15
+ obj.properties.push(ProtocolMetadataUtil.property("value", meta, []));
16
+ emplace_protocol_object(dict)(obj);
17
+
18
+ return obj.name;
19
+ };
@@ -0,0 +1,38 @@
1
+ import { Metadata } from "../../../metadata/Metadata";
2
+ import { MetadataObject } from "../../../metadata/MetadataObject";
3
+
4
+ import { IProtocolMessage } from "../../../messages/IProtocolMessage";
5
+ import { ProtocolMetadataUtil } from "./ProtocolMetadataUtil";
6
+ import { emplace_protocol_object } from "./emplace_protocol_object";
7
+ import { iterate_protocol_atomic } from "./iterate_protocol_atomic";
8
+ import { iterate_protocol_constant } from "./iterate_protocol_constant";
9
+
10
+ export const iterate_protocol_map =
11
+ (container: "Object" | "Map") =>
12
+ (dict: Map<string, IProtocolMessage>) =>
13
+ (key: Metadata) =>
14
+ (value: Metadata) =>
15
+ `map<${getKeyName(key)}, ${getValueName(container)(dict)(value)}>`;
16
+
17
+ const getKeyName = (meta: Metadata) => {
18
+ for (const atomic of meta.atomics)
19
+ return iterate_protocol_atomic([])(atomic);
20
+ for (const constant of meta.constants)
21
+ return iterate_protocol_constant(constant);
22
+ return "string";
23
+ };
24
+
25
+ const getValueName =
26
+ (container: "Object" | "Map") =>
27
+ (dict: Map<string, IProtocolMessage>) =>
28
+ (meta: Metadata) => {
29
+ if (ProtocolMetadataUtil.standalone(meta)) return meta.getName();
30
+
31
+ const obj: MetadataObject = ProtocolMetadataUtil.object(
32
+ `${container}.Value<${meta.getName()}>`,
33
+ dict.size,
34
+ );
35
+ obj.properties.push(ProtocolMetadataUtil.property("value", meta, []));
36
+ emplace_protocol_object(dict)(obj);
37
+ return obj.name;
38
+ };
@@ -0,0 +1,76 @@
1
+ import { IMetadataTag } from "../../../metadata/IMetadataTag";
2
+ import { Metadata } from "../../../metadata/Metadata";
3
+
4
+ import { IProtocolMessage } from "../../../messages/IProtocolMessage";
5
+ import { IProtocolProperty } from "../../../messages/IProtocolProperty";
6
+ import { iterate_protocol_atomic } from "./iterate_protocol_atomic";
7
+ import { iterate_protocol_constant } from "./iterate_protocol_constant";
8
+ import { iterate_protocol_map } from "./iterate_protocol_map";
9
+ import { iterate_protocol_native } from "./iterate_protocol_native";
10
+ import { iterate_protocol_repeated } from "./iterate_protocol_repeated";
11
+ import { iterate_protocol_tuple } from "./iterate_protocol_tuple";
12
+
13
+ export const iterate_protocol_metadata =
14
+ (dict: Map<string, IProtocolMessage>) =>
15
+ (meta: Metadata) =>
16
+ (tags: IMetadataTag[]): Omit<IProtocolProperty, "key"> => {
17
+ // PREPARE ASSETS
18
+ const required: boolean = meta.required && !meta.nullable;
19
+ const oneOf: IProtocolProperty.IOneOf[] = [];
20
+
21
+ const add = (type: string) => {
22
+ if (oneOf.some((one) => one.type === type)) return;
23
+ oneOf.push({
24
+ type,
25
+ });
26
+ };
27
+
28
+ // WHEN SINGULAR ARRAY TYPE
29
+ if (meta.size() === 1 && meta.arrays.length + meta.sets.length === 1) {
30
+ const [container, child] =
31
+ meta.arrays.length === 1
32
+ ? (["Array", meta.arrays[0]!] as const)
33
+ : (["Set", meta.sets[0]!] as const);
34
+ add(iterate_protocol_repeated(container)(true)(dict)(child)(tags));
35
+ return {
36
+ required,
37
+ oneOf,
38
+ repeated: true,
39
+ };
40
+ }
41
+
42
+ // ATOMIC TYPES
43
+ for (const type of meta.atomics)
44
+ add(iterate_protocol_atomic(tags)(type));
45
+ for (const constant of meta.constants)
46
+ add(iterate_protocol_constant(constant));
47
+ if (meta.templates.length) add("string");
48
+
49
+ // INSTANCE TYPES
50
+ for (const obj of meta.objects)
51
+ if (obj.properties.some((p) => !p.key.isSoleLiteral())) {
52
+ for (const prop of obj.properties)
53
+ add(
54
+ iterate_protocol_map("Object")(dict)(prop.key)(
55
+ prop.value,
56
+ ),
57
+ );
58
+ } else add(obj.name);
59
+ for (const native of meta.natives)
60
+ add(iterate_protocol_native(dict)(native));
61
+ for (const tuple of meta.tuples)
62
+ add(iterate_protocol_tuple(dict)(tuple));
63
+ for (const array of meta.arrays)
64
+ add(iterate_protocol_repeated("Array")(false)(dict)(array)(tags));
65
+ for (const set of meta.sets)
66
+ add(iterate_protocol_repeated("Set")(false)(dict)(set)(tags));
67
+ for (const map of meta.maps)
68
+ add(iterate_protocol_map("Map")(dict)(map.key)(map.value));
69
+
70
+ // RETURNS
71
+ return {
72
+ required,
73
+ oneOf,
74
+ repeated: false,
75
+ };
76
+ };
@@ -0,0 +1,34 @@
1
+ import { Metadata } from "../../../metadata/Metadata";
2
+
3
+ import { IProtocolMessage } from "../../../messages/IProtocolMessage";
4
+ import { ProtocolMetadataUtil } from "./ProtocolMetadataUtil";
5
+ import { emplace_protocol_object } from "./emplace_protocol_object";
6
+
7
+ export const iterate_protocol_native =
8
+ (dict: Map<string, IProtocolMessage>) => (native: string) => {
9
+ if (native === "Date") {
10
+ const obj = ProtocolMetadataUtil.object("__Timestamp", dict.size);
11
+ obj.properties.push(
12
+ ProtocolMetadataUtil.property("seconds", integer("bigint"), [
13
+ {
14
+ kind: "type",
15
+ value: "int64",
16
+ },
17
+ ]),
18
+ ProtocolMetadataUtil.property("nanos", integer("number"), [
19
+ {
20
+ kind: "type",
21
+ value: "int",
22
+ },
23
+ ]),
24
+ );
25
+ emplace_protocol_object(dict)(obj);
26
+ return "__Timestamp";
27
+ } else return "bytes";
28
+ };
29
+
30
+ const integer = (type: "number" | "bigint") => {
31
+ const meta = Metadata.initialize();
32
+ meta.atomics.push(type);
33
+ return meta;
34
+ };