Compare commits

...

14 Commits

Author SHA1 Message Date
b003da7f59 3.0.17 2024-03-01 00:12:55 +01:00
735890bc3d fix(core): update 2024-03-01 00:12:55 +01:00
69035f49c8 3.0.16 2024-03-01 00:12:44 +01:00
5ec20ee526 fix(core): update 2024-03-01 00:12:43 +01:00
8b811ffd6b 3.0.15 2024-02-29 23:55:34 +01:00
35df3697c7 fix(core): update 2024-02-29 23:55:34 +01:00
8b4befc828 3.0.14 2024-02-29 23:12:52 +01:00
77dddd9157 fix(core): update 2024-02-29 23:12:51 +01:00
737f413324 3.0.13 2024-02-29 22:59:43 +01:00
e613937c43 fix(core): update 2024-02-29 22:59:42 +01:00
9c66752f8b 3.0.12 2024-02-29 22:59:32 +01:00
5c6922c710 fix(core): update 2024-02-29 22:59:31 +01:00
c8e4343ac7 3.0.11 2024-02-29 22:51:44 +01:00
924bc2c5a7 fix(core): update 2024-02-29 22:51:44 +01:00
6 changed files with 29 additions and 24 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@api.global/typedrequest",
"version": "3.0.10",
"version": "3.0.17",
"private": false,
"description": "make typed requests towards apis",
"main": "dist_ts/index.js",

View File

@ -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();

View File

@ -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();

View File

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

View File

@ -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,
});

View File

@ -23,6 +23,9 @@ export class VirtualStream<T = ArrayBufferLike> implements plugins.typedRequestI
originalPayload?: any,
path = []
): any {
if (!objectPayload) {
return objectPayload;
}
if (plugins.smartbuffer.isBufferLike(objectPayload)) {
return objectPayload;
}
@ -49,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;
}, {});