Compare commits

...

8 Commits

Author SHA1 Message Date
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
2274afcd38 3.0.10 2024-02-29 22:47:54 +01:00
23aab2adf8 fix(core): update 2024-02-29 22:47:53 +01:00
6 changed files with 398 additions and 796 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@api.global/typedrequest",
"version": "3.0.9",
"version": "3.0.13",
"private": false,
"description": "make typed requests towards apis",
"main": "dist_ts/index.js",
@ -27,7 +27,7 @@
"@api.global/typedrequest-interfaces": "^3.0.18",
"@push.rocks/isounique": "^1.0.5",
"@push.rocks/lik": "^6.0.14",
"@push.rocks/smartbuffer": "^1.0.6",
"@push.rocks/smartbuffer": "^1.0.7",
"@push.rocks/smartdelay": "^3.0.5",
"@push.rocks/smartpromise": "^4.0.3",
"@push.rocks/webrequest": "^3.0.34",

1143
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -31,9 +31,15 @@ tap.test('should define a testHandler', async () => {
tap.test('should fire a request', async () => {
const typedRequest = new typedrequest.TypedRequest<ITestReqRes>(
'http://localhost:3000/testroute',
'http://localhost:3000/typedrequest',
'hi'
);
const result = await typedRequest.fire({
name: 'yes',
}).catch(err => {
console.log(err);
});
console.log(result);
});
tap.start();

View File

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

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