Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
b003da7f59 | |||
735890bc3d | |||
69035f49c8 | |||
5ec20ee526 | |||
8b811ffd6b | |||
35df3697c7 | |||
8b4befc828 | |||
77dddd9157 | |||
737f413324 | |||
e613937c43 | |||
9c66752f8b | |||
5c6922c710 |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@api.global/typedrequest",
|
||||
"version": "3.0.11",
|
||||
"version": "3.0.17",
|
||||
"private": false,
|
||||
"description": "make typed requests towards apis",
|
||||
"main": "dist_ts/index.js",
|
||||
|
@ -36,10 +36,12 @@ tap.test('should fire a request', async () => {
|
||||
);
|
||||
const result = await typedRequest.fire({
|
||||
name: 'yes',
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
})
|
||||
console.log(result);
|
||||
});
|
||||
|
||||
tap.test('test', async (tools) => {
|
||||
await tools.delayFor(5000);
|
||||
})
|
||||
|
||||
tap.start();
|
||||
|
@ -101,8 +101,9 @@ tap.test('should allow VirtualStreams', async () => {
|
||||
});
|
||||
|
||||
tap.test('should end the server', async (toolsArg) => {
|
||||
await toolsArg.delayFor(5000);
|
||||
await toolsArg.delayFor(1000);
|
||||
await testServer.stop();
|
||||
setTimeout(() => process.exit(0), 100);
|
||||
});
|
||||
|
||||
tap.start();
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@api.global/typedrequest',
|
||||
version: '3.0.11',
|
||||
version: '3.0.17',
|
||||
description: 'make typed requests towards apis'
|
||||
}
|
||||
|
@ -120,6 +120,7 @@ export class TypedRouter {
|
||||
typedRequestArg.correlation.phase = 'response';
|
||||
|
||||
// encode again before handing back
|
||||
typedRequestArg.localData = null;
|
||||
typedRequestArg = VirtualStream.encodePayloadForNetwork(typedRequestArg, {
|
||||
typedrouter: this,
|
||||
});
|
||||
|
@ -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;
|
||||
}, {});
|
||||
|
Reference in New Issue
Block a user