typia 7.0.0-dev.20241012 → 7.0.0-dev.20241018

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 (236) hide show
  1. package/lib/factories/JsonMetadataFactory.js +3 -2
  2. package/lib/factories/JsonMetadataFactory.js.map +1 -1
  3. package/lib/factories/MetadataCollection.d.ts +3 -3
  4. package/lib/factories/MetadataCollection.js +2 -2
  5. package/lib/factories/MetadataCollection.js.map +1 -1
  6. package/lib/factories/MetadataFactory.d.ts +2 -2
  7. package/lib/factories/MetadataFactory.js +3 -3
  8. package/lib/factories/MetadataFactory.js.map +1 -1
  9. package/lib/factories/MetadataTypeTagFactory.d.ts +3 -2
  10. package/lib/factories/MetadataTypeTagFactory.js +26 -3
  11. package/lib/factories/MetadataTypeTagFactory.js.map +1 -1
  12. package/lib/factories/ProtobufFactory.js +829 -156
  13. package/lib/factories/ProtobufFactory.js.map +1 -1
  14. package/lib/factories/internal/metadata/IMetadataIteratorProps.d.ts +1 -0
  15. package/lib/factories/internal/metadata/MetadataHelper.js +1 -1
  16. package/lib/factories/internal/metadata/MetadataHelper.js.map +1 -1
  17. package/lib/factories/internal/metadata/emplace_metadata_alias.d.ts +2 -2
  18. package/lib/factories/internal/metadata/emplace_metadata_object.js +5 -5
  19. package/lib/factories/internal/metadata/emplace_metadata_object.js.map +1 -1
  20. package/lib/factories/internal/metadata/explore_metadata.js +2 -0
  21. package/lib/factories/internal/metadata/explore_metadata.js.map +1 -1
  22. package/lib/factories/internal/metadata/iterate_metadata.js +1 -1
  23. package/lib/factories/internal/metadata/iterate_metadata.js.map +1 -1
  24. package/lib/factories/internal/metadata/iterate_metadata_alias.js +8 -2
  25. package/lib/factories/internal/metadata/iterate_metadata_alias.js.map +1 -1
  26. package/lib/factories/internal/metadata/iterate_metadata_collection.js +6 -6
  27. package/lib/factories/internal/metadata/iterate_metadata_collection.js.map +1 -1
  28. package/lib/factories/internal/metadata/iterate_metadata_intersection.js +262 -137
  29. package/lib/factories/internal/metadata/iterate_metadata_intersection.js.map +1 -1
  30. package/lib/factories/internal/metadata/iterate_metadata_map.js +4 -2
  31. package/lib/factories/internal/metadata/iterate_metadata_map.js.map +1 -1
  32. package/lib/factories/internal/metadata/iterate_metadata_native.js +27 -11
  33. package/lib/factories/internal/metadata/iterate_metadata_native.js.map +1 -1
  34. package/lib/factories/internal/metadata/iterate_metadata_set.js +8 -1
  35. package/lib/factories/internal/metadata/iterate_metadata_set.js.map +1 -1
  36. package/lib/factories/internal/metadata/iterate_metadata_sort.js +1 -1
  37. package/lib/factories/internal/metadata/iterate_metadata_sort.js.map +1 -1
  38. package/lib/factories/internal/metadata/iterate_metadata_template.js +1 -1
  39. package/lib/factories/internal/metadata/iterate_metadata_template.js.map +1 -1
  40. package/lib/programmers/CheckerProgrammer.js +5 -5
  41. package/lib/programmers/CheckerProgrammer.js.map +1 -1
  42. package/lib/programmers/RandomProgrammer.js +12 -12
  43. package/lib/programmers/RandomProgrammer.js.map +1 -1
  44. package/lib/programmers/helpers/AtomicPredicator.js +3 -3
  45. package/lib/programmers/helpers/AtomicPredicator.js.map +1 -1
  46. package/lib/programmers/helpers/ProtobufUtil.d.ts +5 -4
  47. package/lib/programmers/helpers/ProtobufUtil.js +215 -92
  48. package/lib/programmers/helpers/ProtobufUtil.js.map +1 -1
  49. package/lib/programmers/helpers/UnionExplorer.d.ts +4 -2
  50. package/lib/programmers/helpers/UnionExplorer.js +1 -1
  51. package/lib/programmers/helpers/UnionExplorer.js.map +1 -1
  52. package/lib/programmers/http/HttpFormDataProgrammer.js +6 -6
  53. package/lib/programmers/http/HttpFormDataProgrammer.js.map +1 -1
  54. package/lib/programmers/internal/application_escaped.js +2 -2
  55. package/lib/programmers/internal/application_escaped.js.map +1 -1
  56. package/lib/programmers/internal/application_v30_alias.js +13 -8
  57. package/lib/programmers/internal/application_v30_alias.js.map +1 -1
  58. package/lib/programmers/internal/application_v30_native.js +17 -10
  59. package/lib/programmers/internal/application_v30_native.js.map +1 -1
  60. package/lib/programmers/internal/application_v30_object.js +16 -6
  61. package/lib/programmers/internal/application_v30_object.js.map +1 -1
  62. package/lib/programmers/internal/application_v30_schema.js +24 -17
  63. package/lib/programmers/internal/application_v30_schema.js.map +1 -1
  64. package/lib/programmers/internal/application_v31_alias.js +12 -11
  65. package/lib/programmers/internal/application_v31_alias.js.map +1 -1
  66. package/lib/programmers/internal/application_v31_native.js +17 -10
  67. package/lib/programmers/internal/application_v31_native.js.map +1 -1
  68. package/lib/programmers/internal/application_v31_object.js +13 -6
  69. package/lib/programmers/internal/application_v31_object.js.map +1 -1
  70. package/lib/programmers/internal/application_v31_schema.js +23 -16
  71. package/lib/programmers/internal/application_v31_schema.js.map +1 -1
  72. package/lib/programmers/internal/check_dynamic_key.js +4 -4
  73. package/lib/programmers/internal/check_dynamic_key.js.map +1 -1
  74. package/lib/programmers/internal/check_native.js +3 -3
  75. package/lib/programmers/internal/check_union_array_like.js.map +1 -1
  76. package/lib/programmers/internal/llm_schema_escaped.js +2 -2
  77. package/lib/programmers/internal/llm_schema_escaped.js.map +1 -1
  78. package/lib/programmers/internal/llm_schema_object.js +18 -14
  79. package/lib/programmers/internal/llm_schema_object.js.map +1 -1
  80. package/lib/programmers/internal/llm_schema_station.js +8 -8
  81. package/lib/programmers/internal/llm_schema_station.js.map +1 -1
  82. package/lib/programmers/json/JsonSchemasProgrammer.js +5 -5
  83. package/lib/programmers/json/JsonSchemasProgrammer.js.map +1 -1
  84. package/lib/programmers/json/JsonStringifyProgrammer.js +18 -17
  85. package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
  86. package/lib/programmers/llm/LlmSchemaProgrammer.js +6 -6
  87. package/lib/programmers/llm/LlmSchemaProgrammer.js.map +1 -1
  88. package/lib/programmers/misc/MiscCloneProgrammer.js +7 -5
  89. package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
  90. package/lib/programmers/misc/MiscPruneProgrammer.js +1 -1
  91. package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
  92. package/lib/programmers/notations/NotationGeneralProgrammer.js +6 -4
  93. package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
  94. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +15 -12
  95. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
  96. package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js +6 -4
  97. package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js.map +1 -1
  98. package/lib/programmers/protobuf/ProtobufMessageProgrammer.js +51 -34
  99. package/lib/programmers/protobuf/ProtobufMessageProgrammer.js.map +1 -1
  100. package/lib/schemas/metadata/IMetadata.d.ts +14 -18
  101. package/lib/schemas/metadata/IMetadataAlias.d.ts +2 -7
  102. package/lib/schemas/metadata/IMetadataAliasType.d.ts +10 -0
  103. package/lib/schemas/metadata/IMetadataAliasType.js +3 -0
  104. package/lib/schemas/metadata/IMetadataAliasType.js.map +1 -0
  105. package/lib/schemas/metadata/IMetadataComponents.d.ts +2 -2
  106. package/lib/schemas/metadata/IMetadataConstantValue.d.ts +1 -1
  107. package/lib/schemas/metadata/IMetadataDictionary.d.ts +2 -2
  108. package/lib/schemas/metadata/IMetadataMap.d.ts +7 -0
  109. package/lib/schemas/metadata/{IMetadataEntry.js → IMetadataMap.js} +1 -1
  110. package/lib/schemas/metadata/IMetadataMap.js.map +1 -0
  111. package/lib/schemas/metadata/IMetadataNative.d.ts +5 -0
  112. package/lib/schemas/metadata/IMetadataNative.js +3 -0
  113. package/lib/schemas/metadata/IMetadataNative.js.map +1 -0
  114. package/lib/schemas/metadata/IMetadataSet.d.ts +6 -0
  115. package/lib/schemas/metadata/IMetadataSet.js +3 -0
  116. package/lib/schemas/metadata/IMetadataSet.js.map +1 -0
  117. package/lib/schemas/metadata/IMetadataTemplate.d.ts +1 -1
  118. package/lib/schemas/metadata/IMetadataTypeTag.d.ts +1 -1
  119. package/lib/schemas/metadata/Metadata.d.ts +6 -9
  120. package/lib/schemas/metadata/Metadata.js +136 -98
  121. package/lib/schemas/metadata/Metadata.js.map +1 -1
  122. package/lib/schemas/metadata/MetadataAlias.d.ts +8 -11
  123. package/lib/schemas/metadata/MetadataAlias.js +48 -33
  124. package/lib/schemas/metadata/MetadataAlias.js.map +1 -1
  125. package/lib/schemas/metadata/MetadataAliasType.d.ts +16 -0
  126. package/lib/schemas/metadata/MetadataAliasType.js +51 -0
  127. package/lib/schemas/metadata/MetadataAliasType.js.map +1 -0
  128. package/lib/schemas/metadata/MetadataComponents.d.ts +2 -2
  129. package/lib/schemas/metadata/MetadataComponents.js +2 -2
  130. package/lib/schemas/metadata/MetadataComponents.js.map +1 -1
  131. package/lib/schemas/metadata/MetadataConstantValue.d.ts +1 -1
  132. package/lib/schemas/metadata/MetadataMap.d.ts +14 -0
  133. package/lib/schemas/metadata/MetadataMap.js +66 -0
  134. package/lib/schemas/metadata/MetadataMap.js.map +1 -0
  135. package/lib/schemas/metadata/MetadataNative.d.ts +12 -0
  136. package/lib/schemas/metadata/MetadataNative.js +65 -0
  137. package/lib/schemas/metadata/MetadataNative.js.map +1 -0
  138. package/lib/schemas/metadata/MetadataSet.d.ts +13 -0
  139. package/lib/schemas/metadata/MetadataSet.js +64 -0
  140. package/lib/schemas/metadata/MetadataSet.js.map +1 -0
  141. package/lib/schemas/metadata/MetadataTemplate.d.ts +1 -1
  142. package/lib/tags/Example.d.ts +2 -2
  143. package/lib/tags/Examples.d.ts +2 -2
  144. package/lib/tags/JsonSchemaPlugin.d.ts +1 -1
  145. package/lib/tags/Sequence.d.ts +9 -0
  146. package/lib/tags/Sequence.js +3 -0
  147. package/lib/tags/Sequence.js.map +1 -0
  148. package/lib/tags/TagBase.d.ts +1 -1
  149. package/lib/tags/index.d.ts +1 -0
  150. package/lib/tags/index.js +1 -0
  151. package/lib/tags/index.js.map +1 -1
  152. package/package.json +1 -1
  153. package/src/factories/JsonMetadataFactory.ts +5 -2
  154. package/src/factories/MetadataCollection.ts +6 -6
  155. package/src/factories/MetadataFactory.ts +7 -7
  156. package/src/factories/MetadataTypeTagFactory.ts +31 -6
  157. package/src/factories/ProtobufFactory.ts +494 -176
  158. package/src/factories/internal/metadata/IMetadataIteratorProps.ts +1 -0
  159. package/src/factories/internal/metadata/MetadataHelper.ts +1 -1
  160. package/src/factories/internal/metadata/emplace_metadata_alias.ts +2 -2
  161. package/src/factories/internal/metadata/emplace_metadata_object.ts +5 -5
  162. package/src/factories/internal/metadata/explore_metadata.ts +1 -0
  163. package/src/factories/internal/metadata/iterate_metadata.ts +1 -1
  164. package/src/factories/internal/metadata/iterate_metadata_alias.ts +9 -4
  165. package/src/factories/internal/metadata/iterate_metadata_collection.ts +6 -6
  166. package/src/factories/internal/metadata/iterate_metadata_intersection.ts +163 -181
  167. package/src/factories/internal/metadata/iterate_metadata_map.ts +5 -2
  168. package/src/factories/internal/metadata/iterate_metadata_native.ts +20 -2
  169. package/src/factories/internal/metadata/iterate_metadata_set.ts +27 -11
  170. package/src/factories/internal/metadata/iterate_metadata_sort.ts +1 -1
  171. package/src/factories/internal/metadata/iterate_metadata_template.ts +1 -3
  172. package/src/programmers/CheckerProgrammer.ts +9 -7
  173. package/src/programmers/RandomProgrammer.ts +16 -14
  174. package/src/programmers/helpers/AtomicPredicator.ts +3 -3
  175. package/src/programmers/helpers/ProtobufUtil.ts +146 -43
  176. package/src/programmers/helpers/UnionExplorer.ts +62 -62
  177. package/src/programmers/http/HttpFormDataProgrammer.ts +10 -6
  178. package/src/programmers/internal/application_escaped.ts +2 -2
  179. package/src/programmers/internal/application_v30_alias.ts +18 -12
  180. package/src/programmers/internal/application_v30_native.ts +22 -12
  181. package/src/programmers/internal/application_v30_object.ts +23 -8
  182. package/src/programmers/internal/application_v30_schema.ts +31 -34
  183. package/src/programmers/internal/application_v31_alias.ts +16 -13
  184. package/src/programmers/internal/application_v31_native.ts +22 -12
  185. package/src/programmers/internal/application_v31_object.ts +19 -8
  186. package/src/programmers/internal/application_v31_schema.ts +26 -29
  187. package/src/programmers/internal/check_dynamic_key.ts +4 -4
  188. package/src/programmers/internal/check_native.ts +4 -4
  189. package/src/programmers/internal/check_union_array_like.ts +2 -1
  190. package/src/programmers/internal/llm_schema_escaped.ts +2 -2
  191. package/src/programmers/internal/llm_schema_object.ts +21 -18
  192. package/src/programmers/internal/llm_schema_station.ts +9 -11
  193. package/src/programmers/json/JsonSchemasProgrammer.ts +5 -5
  194. package/src/programmers/json/JsonStringifyProgrammer.ts +5 -5
  195. package/src/programmers/llm/LlmSchemaProgrammer.ts +6 -6
  196. package/src/programmers/misc/MiscCloneProgrammer.ts +11 -7
  197. package/src/programmers/misc/MiscPruneProgrammer.ts +1 -1
  198. package/src/programmers/notations/NotationGeneralProgrammer.ts +10 -6
  199. package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +14 -7
  200. package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +11 -8
  201. package/src/programmers/protobuf/ProtobufMessageProgrammer.ts +45 -20
  202. package/src/schemas/metadata/IMetadata.ts +35 -39
  203. package/src/schemas/metadata/IMetadataAlias.ts +6 -12
  204. package/src/schemas/metadata/IMetadataAliasType.ts +12 -0
  205. package/src/schemas/metadata/IMetadataArray.ts +6 -6
  206. package/src/schemas/metadata/IMetadataComponents.ts +11 -11
  207. package/src/schemas/metadata/IMetadataConstantValue.ts +1 -1
  208. package/src/schemas/metadata/IMetadataDictionary.ts +2 -2
  209. package/src/schemas/metadata/IMetadataMap.ts +8 -0
  210. package/src/schemas/metadata/IMetadataNative.ts +6 -0
  211. package/src/schemas/metadata/IMetadataObjectType.ts +13 -13
  212. package/src/schemas/metadata/IMetadataSet.ts +7 -0
  213. package/src/schemas/metadata/IMetadataTemplate.ts +7 -7
  214. package/src/schemas/metadata/IMetadataTuple.ts +6 -6
  215. package/src/schemas/metadata/IMetadataTypeTag.ts +16 -16
  216. package/src/schemas/metadata/Metadata.ts +100 -47
  217. package/src/schemas/metadata/MetadataAlias.ts +46 -61
  218. package/src/schemas/metadata/MetadataAliasType.ts +63 -0
  219. package/src/schemas/metadata/MetadataArray.ts +49 -49
  220. package/src/schemas/metadata/MetadataComponents.ts +3 -3
  221. package/src/schemas/metadata/MetadataConstantValue.ts +1 -1
  222. package/src/schemas/metadata/MetadataMap.ts +48 -0
  223. package/src/schemas/metadata/MetadataNative.ts +44 -0
  224. package/src/schemas/metadata/MetadataProperty.ts +5 -0
  225. package/src/schemas/metadata/MetadataSet.ts +45 -0
  226. package/src/schemas/metadata/MetadataTemplate.ts +80 -80
  227. package/src/schemas/metadata/MetadataTuple.ts +32 -32
  228. package/src/tags/Example.ts +24 -17
  229. package/src/tags/Examples.ts +16 -16
  230. package/src/tags/JsonSchemaPlugin.ts +8 -8
  231. package/src/tags/Sequence.ts +10 -0
  232. package/src/tags/TagBase.ts +82 -76
  233. package/src/tags/index.ts +1 -0
  234. package/lib/schemas/metadata/IMetadataEntry.d.ts +0 -5
  235. package/lib/schemas/metadata/IMetadataEntry.js.map +0 -1
  236. package/src/schemas/metadata/IMetadataEntry.ts +0 -6
@@ -1,7 +1,9 @@
1
1
  import ts from "typescript";
2
2
 
3
+ import { IMetadataTypeTag } from "../schemas/metadata/IMetadataTypeTag";
3
4
  import { Metadata } from "../schemas/metadata/Metadata";
4
5
  import { MetadataObjectType } from "../schemas/metadata/MetadataObjectType";
6
+ import { MetadataProperty } from "../schemas/metadata/MetadataProperty";
5
7
 
6
8
  import { ProtobufUtil } from "../programmers/helpers/ProtobufUtil";
7
9
 
@@ -21,6 +23,9 @@ export namespace ProtobufFactory {
21
23
  type: ts.Type;
22
24
  }
23
25
 
26
+ /* -----------------------------------------------------------
27
+ METADATA COMPOSER
28
+ ----------------------------------------------------------- */
24
29
  export const metadata = (props: IProps): Metadata => {
25
30
  // COMPOSE METADATA WITH INDIVIDUAL VALIDATIONS
26
31
  const result: ValidationPipe<Metadata, MetadataFactory.IError> =
@@ -31,7 +36,7 @@ export namespace ProtobufFactory {
31
36
  escape: false,
32
37
  constant: true,
33
38
  absorb: true,
34
- validate,
39
+ validate: validate(),
35
40
  },
36
41
  });
37
42
  if (result.success === false)
@@ -42,192 +47,496 @@ export namespace ProtobufFactory {
42
47
  return result.data;
43
48
  };
44
49
 
45
- const validate = (
46
- meta: Metadata,
47
- explore: MetadataFactory.IExplore,
48
- ): string[] => {
49
- const errors: string[] = [];
50
- const insert = (msg: string) => errors.push(msg);
50
+ /* -----------------------------------------------------------
51
+ VALIDATORS
52
+ ----------------------------------------------------------- */
53
+ const validate = () => {
54
+ const visited: WeakSet<MetadataObjectType> = new WeakSet();
55
+ return (meta: Metadata, explore: MetadataFactory.IExplore): string[] => {
56
+ const errors: string[] = [];
57
+ const insert = (msg: string) => errors.push(msg);
51
58
 
52
- if (explore.top === true) {
53
- const onlyObject: boolean =
54
- meta.size() === 1 &&
55
- meta.objects.length === 1 &&
56
- meta.objects[0]!.type.properties.every((p) => p.key.isSoleLiteral()) &&
57
- meta.isRequired() === true &&
58
- meta.nullable === false;
59
- if (onlyObject === false)
60
- insert("target type must be a sole and static object type");
61
- }
59
+ if (explore.top === true) {
60
+ const onlyObject: boolean =
61
+ meta.size() === 1 &&
62
+ meta.objects.length === 1 &&
63
+ meta.objects[0]!.type.properties.every((p) =>
64
+ p.key.isSoleLiteral(),
65
+ ) &&
66
+ meta.isRequired() === true &&
67
+ meta.nullable === false;
68
+ if (onlyObject === false)
69
+ insert("target type must be a sole and static object type");
70
+ }
71
+ if (explore.object !== null && visited.has(explore.object) === false) {
72
+ visited.add(explore.object);
73
+ validateRegularObject({
74
+ object: explore.object,
75
+ errors,
76
+ });
77
+ for (const p of explore.object.properties)
78
+ validateRegularProperty({
79
+ value: p.value,
80
+ errors,
81
+ });
82
+ }
62
83
 
63
- //----
64
- // NOT SUPPORTED TYPES
65
- //----
66
- const noSupport = (msg: string) => insert(`does not support ${msg}`);
84
+ //----
85
+ // NOT SUPPORTED TYPES
86
+ //----
87
+ const noSupport = (msg: string) => insert(`does not support ${msg}`);
67
88
 
68
- // PROHIBIT ANY TYPE
69
- if (meta.any) noSupport("any type");
70
- // PROHIBIT FUNCTIONAL TYPE
71
- if (meta.functions.length) noSupport("functional type");
72
- // PROHIBIT TUPLE TYPE
73
- if (meta.tuples.length) noSupport("tuple type");
74
- // PROHIBIT SET TYPE
75
- if (meta.sets.length) noSupport("Set type");
76
- // NATIVE TYPE, BUT NOT Uint8Array
77
- if (meta.natives.length)
78
- for (const native of meta.natives) {
79
- if (native === "Uint8Array") continue;
89
+ // PROHIBIT ANY TYPE
90
+ if (meta.any) noSupport("any type");
91
+ // PROHIBIT FUNCTIONAL TYPE
92
+ if (meta.functions.length) noSupport("functional type");
93
+ // PROHIBIT TUPLE TYPE
94
+ if (meta.tuples.length) noSupport("tuple type");
95
+ // PROHIBIT SET TYPE
96
+ if (meta.sets.length) noSupport("Set type");
97
+ // NATIVE TYPE, BUT NOT Uint8Array
98
+ if (meta.natives.length)
99
+ for (const native of meta.natives) {
100
+ if (native.name === "Uint8Array") continue;
80
101
 
81
- const instead = BANNED_NATIVE_TYPES.get(native);
82
- if (instead === undefined) noSupport(`${native} type`);
83
- else noSupport(`${native} type. Use ${instead} type instead.`);
84
- }
85
- //----
86
- // ATOMIC CASES
87
- //----
88
- if (meta.atomics.length) {
89
- const numbers = ProtobufUtil.getNumbers(meta);
90
- const bigints = ProtobufUtil.getBigints(meta);
102
+ const instead = BANNED_NATIVE_TYPES.get(native.name);
103
+ if (instead === undefined) noSupport(`${native.name} type`);
104
+ else noSupport(`${native.name} type. Use ${instead} type instead.`);
105
+ }
106
+ //----
107
+ // ATOMIC CASES
108
+ //----
109
+ if (meta.atomics.length) {
110
+ const numbers = ProtobufUtil.getNumbers(meta);
111
+ const bigints = ProtobufUtil.getBigints(meta);
91
112
 
92
- for (const type of ["int64", "uint64"])
93
- if (numbers.some((n) => n === type) && bigints.some((b) => b === type))
94
- insert(
95
- `tags.Type<"${type}"> cannot be used in both number and bigint types. Recommend to remove from number type`,
96
- );
97
- }
98
- //----
99
- // ARRRAY CASES
100
- //----
101
- // DO NOT ALLOW MULTI-DIMENTIONAL ARRAY
102
- if (
103
- meta.arrays.length &&
104
- meta.arrays.some((array) => !!array.type.value.arrays.length)
105
- )
106
- noSupport("over two dimenstional array type");
107
- // CHILD OF ARRAY TYPE MUST BE REQUIRED
108
- if (
109
- meta.arrays.length &&
110
- meta.arrays.some(
111
- (array) =>
112
- array.type.value.isRequired() === false ||
113
- array.type.value.nullable === true,
113
+ for (const type of ["int64", "uint64"])
114
+ if (numbers.has(type) && bigints.has(type))
115
+ insert(
116
+ `tags.Type<"${type}"> cannot be used in both number and bigint types. Recommend to remove from number type`,
117
+ );
118
+ }
119
+ //----
120
+ // ARRRAY CASES
121
+ //----
122
+ // DO NOT ALLOW MULTI-DIMENTIONAL ARRAY
123
+ if (
124
+ meta.arrays.length &&
125
+ meta.arrays.some((array) => !!array.type.value.arrays.length)
114
126
  )
115
- )
116
- noSupport("optional type in array");
117
- // UNION IN ARRAY
118
- if (
119
- meta.arrays.length &&
120
- meta.arrays.some(
121
- (a) =>
122
- a.type.value.size() > 1 &&
123
- a.type.value.constants.length !== 1 &&
124
- a.type.value.constants[0]?.values.length !== a.type.value.size(),
127
+ noSupport("over two dimenstional array type");
128
+ // CHILD OF ARRAY TYPE MUST BE REQUIRED
129
+ if (
130
+ meta.arrays.length &&
131
+ meta.arrays.some(
132
+ (array) =>
133
+ array.type.value.isRequired() === false ||
134
+ array.type.value.nullable === true,
135
+ )
125
136
  )
126
- )
127
- noSupport("union type in array");
128
- // DO DYNAMIC OBJECT IN ARRAY
129
- if (
130
- meta.arrays.length &&
131
- meta.arrays.some(
132
- (a) =>
133
- a.type.value.maps.length ||
134
- (a.type.value.objects.length &&
135
- a.type.value.objects.some(
136
- (o) => ProtobufUtil.isStaticObject(o.type) === false,
137
- )),
137
+ noSupport("optional type in array");
138
+ // UNION IN ARRAY
139
+ if (
140
+ meta.arrays.length &&
141
+ meta.arrays.some(
142
+ (a) =>
143
+ a.type.value.size() > 1 &&
144
+ a.type.value.constants.length !== 1 &&
145
+ a.type.value.constants[0]?.values.length !== a.type.value.size(),
146
+ )
138
147
  )
139
- )
140
- noSupport("dynamic object in array");
141
- // UNION WITH ARRAY
142
- if (meta.size() > 1 && meta.arrays.length)
143
- noSupport("union type with array type");
144
- //----
145
- // OBJECT CASES
146
- //----
147
- // EMPTY PROPERTY
148
- if (
149
- meta.objects.length &&
150
- meta.objects.some((obj) => obj.type.properties.length === 0)
151
- )
152
- noSupport("empty object type");
153
- // MULTIPLE DYNAMIC KEY TYPED PROPERTIES
154
- if (
155
- meta.objects.length &&
156
- meta.objects.some(
157
- (obj) =>
158
- obj.type.properties.filter((p) => !p.key.isSoleLiteral()).length > 1,
148
+ noSupport("union type in array");
149
+ // DO DYNAMIC OBJECT IN ARRAY
150
+ if (
151
+ meta.arrays.length &&
152
+ meta.arrays.some(
153
+ (a) =>
154
+ a.type.value.maps.length ||
155
+ (a.type.value.objects.length &&
156
+ a.type.value.objects.some(
157
+ (o) => ProtobufUtil.isStaticObject(o.type) === false,
158
+ )),
159
+ )
159
160
  )
160
- )
161
- noSupport(
162
- "object type with multiple dynamic key typed properties. Keep only one.",
163
- );
164
- // STATIC AND DYNAMIC PROPERTIES ARE COMPATIBLE
165
- if (
166
- meta.objects.length &&
167
- meta.objects.some(
168
- (obj) =>
169
- obj.type.properties.some((p) => p.key.isSoleLiteral()) &&
170
- obj.type.properties.some((p) => !p.key.isSoleLiteral()),
161
+ noSupport("dynamic object in array");
162
+ // UNION WITH ARRAY
163
+ if (meta.size() > 1 && meta.arrays.length)
164
+ noSupport("union type with array type");
165
+ //----
166
+ // OBJECT CASES
167
+ //----
168
+ // EMPTY PROPERTY
169
+ if (
170
+ meta.objects.length &&
171
+ meta.objects.some((obj) => obj.type.properties.length === 0)
171
172
  )
172
- )
173
- noSupport(
174
- "object type with mixed static and dynamic key typed properties. Keep statics or dynamic only.",
175
- );
176
- // DYNAMIC OBJECT, BUT PROPERTY VALUE TYPE IS ARRAY
177
- if (
178
- meta.objects.length &&
179
- isDynamicObject(meta.objects[0]!.type) &&
180
- meta.objects[0]!.type.properties.some((p) => !!p.value.arrays.length)
181
- )
182
- noSupport("dynamic object with array value type");
183
- // UNION WITH DYNAMIC OBJECTa
184
- if (
185
- meta.size() > 1 &&
186
- meta.objects.length &&
187
- isDynamicObject(meta.objects[0]!.type)
188
- )
189
- noSupport("union type with dynamic object type");
190
- // UNION IN DYNAMIC PROPERTY VALUE
191
- if (
192
- meta.objects.length &&
193
- meta.objects.some(
194
- (obj) =>
195
- isDynamicObject(obj.type) &&
196
- obj.type.properties.some((p) => ProtobufUtil.isUnion(p.value)),
173
+ noSupport("empty object type");
174
+ // MULTIPLE DYNAMIC KEY TYPED PROPERTIES
175
+ if (
176
+ meta.objects.length &&
177
+ meta.objects.some(
178
+ (obj) =>
179
+ obj.type.properties.filter((p) => !p.key.isSoleLiteral()).length >
180
+ 1,
181
+ )
182
+ )
183
+ noSupport(
184
+ "object type with multiple dynamic key typed properties. Keep only one.",
185
+ );
186
+ // STATIC AND DYNAMIC PROPERTIES ARE COMPATIBLE
187
+ if (
188
+ meta.objects.length &&
189
+ meta.objects.some(
190
+ (obj) =>
191
+ obj.type.properties.some((p) => p.key.isSoleLiteral()) &&
192
+ obj.type.properties.some((p) => !p.key.isSoleLiteral()),
193
+ )
194
+ )
195
+ noSupport(
196
+ "object type with mixed static and dynamic key typed properties. Keep statics or dynamic only.",
197
+ );
198
+ // DYNAMIC OBJECT, BUT PROPERTY VALUE TYPE IS ARRAY
199
+ if (
200
+ meta.objects.length &&
201
+ isDynamicObject(meta.objects[0]!.type) &&
202
+ meta.objects[0]!.type.properties.some((p) => !!p.value.arrays.length)
203
+ )
204
+ noSupport("dynamic object with array value type");
205
+ // UNION WITH DYNAMIC OBJECTa
206
+ if (
207
+ meta.size() > 1 &&
208
+ meta.objects.length &&
209
+ isDynamicObject(meta.objects[0]!.type)
210
+ )
211
+ noSupport("union type with dynamic object type");
212
+ // UNION IN DYNAMIC PROPERTY VALUE
213
+ if (
214
+ meta.objects.length &&
215
+ meta.objects.some(
216
+ (obj) =>
217
+ isDynamicObject(obj.type) &&
218
+ obj.type.properties.some((p) => ProtobufUtil.isUnion(p.value)),
219
+ )
220
+ )
221
+ noSupport("union type in dynamic property");
222
+ //----
223
+ // MAP CASES
224
+ //----
225
+ // KEY TYPE IS UNION
226
+ if (
227
+ meta.maps.length &&
228
+ meta.maps.some((m) => ProtobufUtil.isUnion(m.key))
197
229
  )
198
- )
199
- noSupport("union type in dynamic property");
200
- //----
201
- // MAP CASES
202
- //----
203
- // KEY TYPE IS UNION
204
- if (meta.maps.length && meta.maps.some((m) => ProtobufUtil.isUnion(m.key)))
205
- noSupport("union key typed map");
206
- // KEY TYPE IS NOT ATOMIC
207
- if (
208
- meta.maps.length &&
209
- meta.maps.some((m) => ProtobufUtil.getAtomics(m.key).length !== 1)
210
- )
211
- noSupport("non-atomic key typed map");
212
- // MAP TYPE, BUT PROPERTY KEY TYPE IS OPTIONAL
213
- if (
214
- meta.maps.length &&
215
- meta.maps.some((m) => m.key.isRequired() === false || m.key.nullable)
216
- )
217
- noSupport("optional key typed map");
218
- // MAP TYPE, BUT VALUE TYPE IS ARRAY
219
- if (meta.maps.length && meta.maps.some((m) => !!m.value.arrays.length))
220
- noSupport("map type with array value type");
221
- // UNION WITH MAP
222
- if (meta.size() > 1 && meta.maps.length)
223
- noSupport("union type with map type");
224
- // UNION IN MAP
225
- if (
226
- meta.maps.length &&
227
- meta.maps.some((m) => ProtobufUtil.isUnion(m.value))
228
- )
229
- noSupport("union type in map value type");
230
- return errors;
230
+ noSupport("union key typed map");
231
+ // KEY TYPE IS NOT ATOMIC
232
+ if (
233
+ meta.maps.length &&
234
+ meta.maps.some((m) => ProtobufUtil.getAtomics(m.key).size !== 1)
235
+ )
236
+ noSupport("non-atomic key typed map");
237
+ // MAP TYPE, BUT PROPERTY KEY TYPE IS OPTIONAL
238
+ if (
239
+ meta.maps.length &&
240
+ meta.maps.some((m) => m.key.isRequired() === false || m.key.nullable)
241
+ )
242
+ noSupport("optional key typed map");
243
+ // MAP TYPE, BUT VALUE TYPE IS ARRAY
244
+ if (meta.maps.length && meta.maps.some((m) => !!m.value.arrays.length))
245
+ noSupport("map type with array value type");
246
+ // UNION WITH MAP
247
+ if (meta.size() > 1 && meta.maps.length)
248
+ noSupport("union type with map type");
249
+ // UNION IN MAP
250
+ if (
251
+ meta.maps.length &&
252
+ meta.maps.some((m) => ProtobufUtil.isUnion(m.value))
253
+ )
254
+ noSupport("union type in map value type");
255
+ return errors;
256
+ };
257
+ };
258
+
259
+ /* -----------------------------------------------------------
260
+ SEQUENE VALIDATOR
261
+ ----------------------------------------------------------- */
262
+ const validateRegularObject = (next: {
263
+ object: MetadataObjectType;
264
+ errors: string[];
265
+ }): void => {
266
+ const entire: Map<number, string> = new Map();
267
+ const visitProperty = (p: MetadataProperty) => {
268
+ const local: Set<number> = new Set();
269
+ const tagger = (matrix: IMetadataTypeTag[][]): void => {
270
+ matrix.forEach((tags) => {
271
+ const value: number | null = ProtobufUtil.getSequence(tags);
272
+ if (value !== null) local.add(value);
273
+ });
274
+ };
275
+ for (const c of p.value.constants)
276
+ for (const v of c.values) tagger(v.tags);
277
+ for (const a of p.value.atomics) tagger(a.tags);
278
+ for (const t of p.value.templates) tagger(t.tags);
279
+ for (const o of p.value.objects) tagger(o.tags);
280
+ for (const a of p.value.arrays) tagger(a.tags);
281
+
282
+ for (const s of local)
283
+ if (entire.has(s))
284
+ next.errors.push(
285
+ `The Sequence<${s}> tag is duplicated in two properties (${JSON.stringify(entire.get(s))} and ${JSON.stringify(p.key.getSoleLiteral())})`,
286
+ );
287
+ else entire.set(s, p.key.getSoleLiteral()!);
288
+ };
289
+ for (const p of next.object.properties) visitProperty(p);
290
+ };
291
+
292
+ const validateRegularProperty = (next: {
293
+ value: Metadata;
294
+ errors: string[];
295
+ }): void => {
296
+ let expected: number = 0;
297
+ const sequences: Set<number> = new Set();
298
+ const add = (value: number): boolean => {
299
+ if (sequences.has(value)) return false;
300
+ sequences.add(value);
301
+ ++expected;
302
+ return true;
303
+ };
304
+
305
+ for (const validator of [
306
+ validateBooleanSequence,
307
+ validateNumericSequences({
308
+ type: "bigint",
309
+ default: "int64",
310
+ categories: BIGINT_TYPES,
311
+ }),
312
+ validateNumericSequences({
313
+ type: "number",
314
+ default: "double",
315
+ categories: NUMBER_TYPES,
316
+ }),
317
+ validateStringSequence,
318
+ ])
319
+ validator({ metadata: next.value, errors: next.errors, add });
320
+ for (const array of next.value.arrays)
321
+ validateInstanceSequence({
322
+ type: "array",
323
+ tags: array.tags,
324
+ errors: next.errors,
325
+ add,
326
+ });
327
+ for (const object of next.value.objects)
328
+ validateInstanceSequence({
329
+ type: "object",
330
+ tags: object.tags,
331
+ errors: next.errors,
332
+ add,
333
+ });
334
+ for (const map of next.value.maps)
335
+ validateInstanceSequence({
336
+ type: "map",
337
+ tags: map.tags,
338
+ errors: next.errors,
339
+ add,
340
+ });
341
+ for (const native of next.value.natives)
342
+ if (native.name === "Uint8Array")
343
+ validateInstanceSequence({
344
+ type: "Uint8Array",
345
+ tags: native.tags,
346
+ errors: next.errors,
347
+ add,
348
+ });
349
+ };
350
+
351
+ const validateBooleanSequence = (next: {
352
+ metadata: Metadata;
353
+ errors: string[];
354
+ add: (value: number) => boolean;
355
+ }): void => {
356
+ // PREPARE EMPLACER
357
+ const unique: Set<number> = new Set();
358
+ let expected: number = 0;
359
+ let actual: number = 0;
360
+ const emplace = (matrix: IMetadataTypeTag[][]): void => {
361
+ for (const tags of matrix)
362
+ for (const tag of tags) {
363
+ const sequence = ProtobufUtil.getSequence([tag]);
364
+ if (sequence !== null) {
365
+ unique.add(sequence);
366
+ ++actual;
367
+ }
368
+ ++expected;
369
+ }
370
+ };
371
+
372
+ // GATHER SEQUENCE TAGS
373
+ for (const atomic of next.metadata.atomics)
374
+ if (atomic.type === "boolean") emplace(atomic.tags);
375
+ for (const constant of next.metadata.constants)
376
+ if (constant.type === "boolean")
377
+ for (const value of constant.values) emplace(value.tags);
378
+
379
+ // PREDICATE
380
+ if (unique.size && actual !== expected)
381
+ next.errors.push(
382
+ `The sequence tag must be declared in every union type members`,
383
+ );
384
+ else if (unique.size > 1)
385
+ next.errors.push(
386
+ `The sequence tag value must be the same in boolean type (including literal types)`,
387
+ );
388
+ else if (unique.size === 1) {
389
+ const value: number = unique.values().next().value!;
390
+ if (next.add(value) === false)
391
+ next.errors.push(
392
+ `The sequence tag value ${value} in boolean type is duplicated with other types`,
393
+ );
394
+ }
395
+ };
396
+
397
+ const validateNumericSequences =
398
+ (config: {
399
+ type: "number" | "bigint";
400
+ default: string;
401
+ categories: Set<string>;
402
+ }) =>
403
+ (next: {
404
+ metadata: Metadata;
405
+ errors: string[];
406
+ add: (value: number) => boolean;
407
+ }): void => {
408
+ // FIND TYPE CATEGORIES
409
+ const categories: Set<string> = new Set();
410
+ const getType = (tags: IMetadataTypeTag[]): string => {
411
+ const found: IMetadataTypeTag | undefined = tags.find(
412
+ (t) => t.kind === "type" && config.categories.has(t.value),
413
+ );
414
+ return found?.value ?? config.default;
415
+ };
416
+ const exploreCategory = (matrix: IMetadataTypeTag[][]): void => {
417
+ for (const tags of matrix) categories.add(getType(tags));
418
+ };
419
+ for (const atomic of next.metadata.atomics)
420
+ if (atomic.type === config.type) exploreCategory(atomic.tags);
421
+ for (const constant of next.metadata.constants)
422
+ if (constant.type === config.type)
423
+ for (const value of constant.values) exploreCategory(value.tags);
424
+
425
+ // ITERATE TYPE CATEGORIES
426
+ for (const category of categories) {
427
+ const unique: Set<number> = new Set();
428
+ let expected: number = 0;
429
+ let actual: number = 0;
430
+ const emplace = (tags: IMetadataTypeTag[]): void => {
431
+ const sequence: number | null = ProtobufUtil.getSequence(tags);
432
+ if (sequence !== null) {
433
+ unique.add(sequence);
434
+ ++actual;
435
+ }
436
+ ++expected;
437
+ };
438
+
439
+ for (const atomic of next.metadata.atomics)
440
+ if (atomic.type === config.type)
441
+ for (const tags of atomic.tags)
442
+ if (getType(tags) === category) emplace(tags);
443
+ for (const constant of next.metadata.constants)
444
+ if (constant.type === config.type)
445
+ for (const value of constant.values)
446
+ for (const tags of value.tags)
447
+ if (getType(tags) === category) emplace(tags);
448
+
449
+ if (unique.size && actual !== expected) {
450
+ console.log(category, actual, expected, unique);
451
+ next.errors.push(
452
+ `The sequence tag must be declared in every union type members`,
453
+ );
454
+ } else if (unique.size > 1)
455
+ next.errors.push(
456
+ `The sequence tag value must be the same in ${config.type} type (including literal types)`,
457
+ );
458
+ else if (unique.size === 1) {
459
+ const value: number = unique.values().next().value!;
460
+ if (next.add(value) === false)
461
+ next.errors.push(
462
+ `The sequence tag value ${value} in ${config.type} type is duplicated with other types`,
463
+ );
464
+ }
465
+ }
466
+ };
467
+
468
+ const validateStringSequence = (next: {
469
+ metadata: Metadata;
470
+ errors: string[];
471
+ add: (value: number) => boolean;
472
+ }): void => {
473
+ const unique: Set<number> = new Set();
474
+ let expected: number = 0;
475
+ let actual: number = 0;
476
+ const emplace = (matrix: IMetadataTypeTag[][]): void => {
477
+ for (const tags of matrix)
478
+ for (const tag of tags) {
479
+ const sequence = ProtobufUtil.getSequence([tag]);
480
+ if (sequence !== null) {
481
+ unique.add(sequence);
482
+ ++actual;
483
+ }
484
+ ++expected;
485
+ }
486
+ };
487
+ for (const atomic of next.metadata.atomics)
488
+ if (atomic.type === "string") emplace(atomic.tags);
489
+ for (const constant of next.metadata.constants)
490
+ if (constant.type === "string")
491
+ for (const value of constant.values) emplace(value.tags);
492
+ for (const template of next.metadata.templates) emplace(template.tags);
493
+
494
+ if (unique.size && actual !== expected)
495
+ next.errors.push(
496
+ `The sequence tag must be declared in every union type members`,
497
+ );
498
+ else if (unique.size > 1)
499
+ next.errors.push(
500
+ `The sequence tag value must be the same in string types including literal and template types`,
501
+ );
502
+ else if (unique.size === 1) {
503
+ const value: number = unique.values().next().value!;
504
+ if (next.add(value) === false)
505
+ next.errors.push(
506
+ `The sequence tag value ${value} in string type is duplicated with other types`,
507
+ );
508
+ }
509
+ };
510
+
511
+ const validateInstanceSequence = (next: {
512
+ type: "array" | "object" | "map" | "Uint8Array";
513
+ tags: IMetadataTypeTag[][];
514
+ errors: string[];
515
+ add: (value: number) => boolean;
516
+ }): void => {
517
+ const unique: Set<number> = new Set();
518
+ let count: number = 0;
519
+ for (const tags of next.tags) {
520
+ const value: number | null = ProtobufUtil.getSequence(tags);
521
+ if (value === null) continue;
522
+ unique.add(value);
523
+ ++count;
524
+ }
525
+ if (unique.size && count !== next.tags.length)
526
+ next.errors.push(
527
+ `The sequence tag must be declared in every union type members`,
528
+ );
529
+ else if (unique.size > 1)
530
+ next.errors.push(
531
+ `The sequence tag value must be the same in ${next.type === "array" ? "an array" : "object"} type.`,
532
+ );
533
+ else if (unique.size === 1) {
534
+ const value: number = unique.values().next().value!;
535
+ if (next.add(value) === false)
536
+ next.errors.push(
537
+ `The sequence tag value ${value} in ${next.type} type is duplicated with other types`,
538
+ );
539
+ }
231
540
  };
232
541
  }
233
542
 
@@ -259,3 +568,12 @@ const BANNED_NATIVE_TYPES: Map<string, string | null> = new Map([
259
568
  ["WeakSet", "Array"],
260
569
  ["WeakMap", "Map"],
261
570
  ]);
571
+ const NUMBER_TYPES: Set<string> = new Set([
572
+ "int32",
573
+ "uint32",
574
+ "int64",
575
+ "uint64",
576
+ "float",
577
+ "double",
578
+ ]);
579
+ const BIGINT_TYPES = new Set(["int64", "uint64"]);