fix(core): update

This commit is contained in:
Philipp Kunz 2024-02-29 22:59:31 +01:00
parent c8e4343ac7
commit 5c6922c710
2 changed files with 17 additions and 19 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@api.global/typedrequest',
version: '3.0.11',
version: '3.0.12',
description: 'make typed requests towards apis'
}

View File

@ -52,26 +52,24 @@ export class VirtualStream<T = ArrayBufferLike> implements plugins.typedRequestI
};
}
} else if (Array.isArray(objectPayload)) {
const returnArray = [];
for (const item of objectPayload) {
returnArray.push(
VirtualStream.encodePayloadForNetwork(
item,
commFunctions,
originalPayload || objectPayload,
path
)
);
}
return returnArray;
} else if (objectPayload !== null && typeof objectPayload === 'object') {
return Object.keys(objectPayload).reduce((acc, key) => {
path.push(key);
acc[key] = VirtualStream.encodePayloadForNetwork(
objectPayload[key],
// For arrays, we recurse over each item.
return objectPayload.map((item, index) =>
VirtualStream.encodePayloadForNetwork(
item,
commFunctions,
originalPayload || objectPayload,
path
path.concat(String(index)) // Convert index to string and concatenate to path
)
);
} else if (objectPayload !== null && typeof objectPayload === 'object') {
// For objects, we recurse over each key-value pair.
return Object.entries(objectPayload).reduce((acc, [key, value]) => {
const newPath = path.concat(key); // Concatenate the new key to the path
acc[key] = VirtualStream.encodePayloadForNetwork(
value,
commFunctions,
originalPayload || objectPayload,
newPath
);
return acc;
}, {});