typia 7.0.0-dev.20240921 → 7.0.0-dev.20240922

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.
@@ -33,8 +33,12 @@ export namespace ProtobufMessageProgrammer {
33
33
 
34
34
  // STRINGIFY
35
35
  const hierarchies: Map<string, Hierarchy> = new Map();
36
- for (const obj of collection.objects())
37
- if (is_dynamic_object(obj) === false) emplace(hierarchies)(obj);
36
+ for (const object of collection.objects())
37
+ if (is_dynamic_object(object) === false)
38
+ emplace({
39
+ hierarchies,
40
+ object,
41
+ });
38
42
 
39
43
  const content: string =
40
44
  `syntax = "proto3";\n\n` +
@@ -46,22 +50,26 @@ export namespace ProtobufMessageProgrammer {
46
50
  return ts.factory.createStringLiteral(content);
47
51
  };
48
52
 
49
- const emplace = (dict: Map<string, Hierarchy>) => (obj: MetadataObject) => {
50
- const accessors: string[] = obj.name.split(".");
53
+ const emplace = (props: {
54
+ hierarchies: Map<string, Hierarchy>;
55
+ object: MetadataObject;
56
+ }) => {
57
+ let hierarchies: Map<string, Hierarchy> = props.hierarchies;
58
+ const accessors: string[] = props.object.name.split(".");
51
59
  accessors.forEach((access, i) => {
52
- const hierarchy: Hierarchy = MapUtil.take(dict)(access, () => ({
60
+ const hierarchy: Hierarchy = MapUtil.take(hierarchies)(access, () => ({
53
61
  key: access,
54
62
  object: null!,
55
63
  children: new Map(),
56
64
  }));
57
- dict = hierarchy.children;
58
- if (i === accessors.length - 1) hierarchy.object = obj;
65
+ hierarchies = hierarchy.children;
66
+ if (i === accessors.length - 1) hierarchy.object = props.object;
59
67
  });
60
68
  };
61
69
 
62
- const is_dynamic_object = (obj: MetadataObject): boolean =>
63
- obj.properties.length === 1 &&
64
- obj.properties[0]!.key.isSoleLiteral() === false;
70
+ const is_dynamic_object = (object: MetadataObject): boolean =>
71
+ object.properties.length === 1 &&
72
+ object.properties[0]!.key.isSoleLiteral() === false;
65
73
 
66
74
  const write_hierarchy = (hierarchy: Hierarchy): string => {
67
75
  const elements: string[] = [
@@ -87,21 +95,24 @@ export namespace ProtobufMessageProgrammer {
87
95
  return elements.join("\n");
88
96
  };
89
97
 
90
- const write_object = (obj: MetadataObject): string => {
91
- const ptr: IPointer<number> = { value: 0 };
92
- return obj.properties
93
- .map((prop) => {
94
- const key: string = prop.key.getSoleLiteral()!;
95
- const type: string = decode(ptr)(prop.value);
98
+ const write_object = (object: MetadataObject): string => {
99
+ const sequence: IPointer<number> = { value: 0 };
100
+ return object.properties
101
+ .map((p) => {
102
+ const key: string = p.key.getSoleLiteral()!;
103
+ const type: string = decode({
104
+ sequence,
105
+ metadata: p.value,
106
+ });
96
107
  return type.indexOf("${name}") !== -1
97
108
  ? type.replace("${name}", key)
98
109
  : `${
99
- prop.value.arrays.length || type.startsWith("map<")
110
+ p.value.arrays.length || type.startsWith("map<")
100
111
  ? ""
101
- : !prop.value.isRequired() || prop.value.nullable
112
+ : !p.value.isRequired() || p.value.nullable
102
113
  ? "optional "
103
114
  : "required "
104
- }${type} ${key} = ${++ptr.value};`;
115
+ }${type} ${key} = ${++sequence.value};`;
105
116
  })
106
117
  .join("\n");
107
118
  };
@@ -109,50 +120,72 @@ export namespace ProtobufMessageProgrammer {
109
120
  /* -----------------------------------------------------------
110
121
  DECODERS
111
122
  ----------------------------------------------------------- */
112
- const decode =
113
- (ptr: IPointer<number>) =>
114
- (meta: Metadata): string => {
115
- const elements: Set<string> = new Set();
116
- if (meta.natives.length) elements.add("bytes");
117
- for (const atomic of ProtobufUtil.getAtomics(meta)) elements.add(atomic);
118
- for (const array of meta.arrays)
119
- elements.add(`repeated ${decode(ptr)(array.type.value)}`);
120
- for (const obj of meta.objects)
121
- elements.add(
122
- is_dynamic_object(obj)
123
- ? decode_map(ptr)(
124
- MetadataProperty.create({
125
- ...obj.properties[0]!,
126
- key: (() => {
127
- const key: Metadata = Metadata.initialize();
128
- key.atomics.push(
129
- MetadataAtomic.create({
130
- type: "string",
131
- tags: [],
132
- }),
133
- );
134
- return key;
135
- })(),
136
- }),
137
- )
138
- : NameEncoder.encode(obj.name),
139
- );
140
- for (const map of meta.maps) elements.add(decode_map(ptr)(map));
141
- return elements.size === 1
142
- ? [...elements][0]!
143
- : [
144
- "oneof ${name} {",
145
- ...[...elements].map(
146
- (str) => `${TAB}${str} v${ptr.value + 1} = ${++ptr.value};`,
147
- ),
148
- "}",
149
- ].join("\n");
150
- };
151
-
152
- const decode_map =
153
- (ptr: IPointer<number>) =>
154
- (prop: Metadata.Entry): string =>
155
- `map<${decode(ptr)(prop.key)}, ${decode(ptr)(prop.value)}>`;
123
+ const decode = (props: {
124
+ sequence: IPointer<number>;
125
+ metadata: Metadata;
126
+ }): string => {
127
+ const elements: Set<string> = new Set();
128
+ if (props.metadata.natives.length) elements.add("bytes");
129
+ for (const atomic of ProtobufUtil.getAtomics(props.metadata))
130
+ elements.add(atomic);
131
+ for (const array of props.metadata.arrays)
132
+ elements.add(
133
+ `repeated ${decode({
134
+ sequence: props.sequence,
135
+ metadata: array.type.value,
136
+ })}`,
137
+ );
138
+ for (const obj of props.metadata.objects)
139
+ elements.add(
140
+ is_dynamic_object(obj)
141
+ ? decode_map({
142
+ sequence: props.sequence,
143
+ entry: MetadataProperty.create({
144
+ ...obj.properties[0]!,
145
+ key: (() => {
146
+ const key: Metadata = Metadata.initialize();
147
+ key.atomics.push(
148
+ MetadataAtomic.create({
149
+ type: "string",
150
+ tags: [],
151
+ }),
152
+ );
153
+ return key;
154
+ })(),
155
+ }),
156
+ })
157
+ : NameEncoder.encode(obj.name),
158
+ );
159
+ for (const entry of props.metadata.maps)
160
+ elements.add(
161
+ decode_map({
162
+ sequence: props.sequence,
163
+ entry,
164
+ }),
165
+ );
166
+ return elements.size === 1
167
+ ? [...elements][0]!
168
+ : [
169
+ "oneof ${name} {",
170
+ ...[...elements].map((str) => {
171
+ const index: number = ++props.sequence.value;
172
+ return `${TAB}${str} v${index} = ${index};`;
173
+ }),
174
+ "}",
175
+ ].join("\n");
176
+ };
177
+
178
+ const decode_map = (props: {
179
+ sequence: IPointer<number>;
180
+ entry: Metadata.Entry;
181
+ }): string =>
182
+ `map<${decode({
183
+ sequence: props.sequence,
184
+ metadata: props.entry.key,
185
+ })}, ${decode({
186
+ sequence: props.sequence,
187
+ metadata: props.entry.value,
188
+ })}>`;
156
189
  }
157
190
 
158
191
  interface Hierarchy {