(info, dynamicInfo)
| 237 | * @returns {T} the object |
| 238 | */ |
| 239 | const serializeObject = (info, dynamicInfo) => { |
| 240 | const obj = /** @type {EXPECTED_ANY} */ ({}); |
| 241 | // Setup byProperty structure |
| 242 | for (const entry of info.values()) { |
| 243 | if (entry.byProperty !== undefined) { |
| 244 | const byProperty = entry.byProperty; |
| 245 | const byObj = (obj[byProperty] = obj[byProperty] || {}); |
| 246 | for (const byValue of /** @type {ByValues} */ (entry.byValues).keys()) { |
| 247 | byObj[byValue] = byObj[byValue] || {}; |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | for (const [key, entry] of info) { |
| 252 | if (entry.base !== undefined) { |
| 253 | obj[key] = entry.base; |
| 254 | } |
| 255 | // Fill byProperty structure |
| 256 | if (entry.byProperty !== undefined) { |
| 257 | const byProperty = entry.byProperty; |
| 258 | const byObj = (obj[byProperty] = obj[byProperty] || {}); |
| 259 | for (const byValue of Object.keys(byObj)) { |
| 260 | const value = getFromByValues( |
| 261 | /** @type {ByValues} */ |
| 262 | (entry.byValues), |
| 263 | byValue |
| 264 | ); |
| 265 | if (value !== undefined) byObj[byValue][key] = value; |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | if (dynamicInfo !== undefined) { |
| 270 | obj[dynamicInfo.byProperty] = dynamicInfo.fn; |
| 271 | } |
| 272 | return obj; |
| 273 | }; |
| 274 | |
| 275 | const VALUE_TYPE_UNDEFINED = 0; |
| 276 | const VALUE_TYPE_ATOM = 1; |
no test coverage detected