Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
c8e4343ac7 | |||
924bc2c5a7 | |||
2274afcd38 | |||
23aab2adf8 | |||
90311ad65e | |||
407e1383f8 |
15
package.json
15
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@api.global/typedrequest",
|
||||
"version": "3.0.8",
|
||||
"version": "3.0.11",
|
||||
"private": false,
|
||||
"description": "make typed requests towards apis",
|
||||
"main": "dist_ts/index.js",
|
||||
@ -14,23 +14,24 @@
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@api.global/typedserver": "^3.0.24",
|
||||
"@api.global/typedserver": "^3.0.25",
|
||||
"@git.zone/tsbuild": "^2.1.72",
|
||||
"@git.zone/tsbundle": "^2.0.15",
|
||||
"@git.zone/tsrun": "^1.2.44",
|
||||
"@git.zone/tstest": "^1.0.86",
|
||||
"@push.rocks/smartenv": "^5.0.12",
|
||||
"@push.rocks/tapbundle": "^5.0.15",
|
||||
"@types/node": "^20.11.20"
|
||||
"@types/node": "^20.11.24"
|
||||
},
|
||||
"dependencies": {
|
||||
"@api.global/typedrequest-interfaces": "^3.0.17",
|
||||
"@api.global/typedrequest-interfaces": "^3.0.18",
|
||||
"@push.rocks/isounique": "^1.0.5",
|
||||
"@push.rocks/lik": "^6.0.13",
|
||||
"@push.rocks/smartbuffer": "^1.0.6",
|
||||
"@push.rocks/lik": "^6.0.14",
|
||||
"@push.rocks/smartbuffer": "^1.0.7",
|
||||
"@push.rocks/smartdelay": "^3.0.5",
|
||||
"@push.rocks/smartpromise": "^4.0.3",
|
||||
"@push.rocks/webrequest": "^3.0.34"
|
||||
"@push.rocks/webrequest": "^3.0.34",
|
||||
"@push.rocks/webstream": "^1.0.8"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
1251
pnpm-lock.yaml
generated
1251
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -98,7 +98,7 @@ tap.test('should allow VirtualStreams', async () => {
|
||||
const data = await generatedRequestingVS.fetchData();
|
||||
const decodedData = data.toString();
|
||||
expect(data.toString()).toEqual('hello');
|
||||
})
|
||||
});
|
||||
|
||||
tap.test('should end the server', async (toolsArg) => {
|
||||
await toolsArg.delayFor(5000);
|
@ -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();
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@api.global/typedrequest',
|
||||
version: '3.0.8',
|
||||
version: '3.0.11',
|
||||
description: 'make typed requests towards apis'
|
||||
}
|
||||
|
@ -10,5 +10,6 @@ import * as smartbuffer from '@push.rocks/smartbuffer';
|
||||
import * as smartdelay from '@push.rocks/smartdelay';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as webrequest from '@push.rocks/webrequest';
|
||||
import * as webstream from '@push.rocks/webstream';
|
||||
|
||||
export { isounique, lik, smartbuffer, smartdelay, smartpromise, webrequest };
|
||||
export { isounique, lik, smartbuffer, smartdelay, smartpromise, webrequest, webstream };
|
||||
|
@ -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;
|
||||
}
|
||||
@ -143,6 +146,10 @@ export class VirtualStream<T = ArrayBufferLike> implements plugins.typedRequestI
|
||||
*/
|
||||
private async workOnQueue() {
|
||||
if(this.side === 'requesting') {
|
||||
let thisSideIsBackpressured = !this.receiveBackpressuredArray.checkSpaceAvailable();
|
||||
let otherSideHasNext = false;
|
||||
let otherSideIsBackpressured = false;
|
||||
|
||||
// helper functions
|
||||
const getFeedback = async () => {
|
||||
const streamTr = await this.sendMethod({
|
||||
@ -165,12 +172,9 @@ export class VirtualStream<T = ArrayBufferLike> implements plugins.typedRequestI
|
||||
otherSideHasNext = streamTr.response.next;
|
||||
}
|
||||
}
|
||||
|
||||
await getFeedback();
|
||||
|
||||
// do work loop
|
||||
let thisSideIsBackpressured = !this.receiveBackpressuredArray.checkSpaceAvailable();
|
||||
let otherSideHasNext = false;
|
||||
let otherSideIsBackpressured = false;
|
||||
while (this.sendBackpressuredArray.data.length > 0 || otherSideHasNext) {
|
||||
let dataArg: typeof this.sendBackpressuredArray.data[0];
|
||||
if (this.sendBackpressuredArray.data.length > 0) {
|
||||
@ -243,7 +247,6 @@ export class VirtualStream<T = ArrayBufferLike> implements plugins.typedRequestI
|
||||
next: this.sendBackpressuredArray.data.length > 0,
|
||||
backpressure: this.receiveBackpressuredArray.checkSpaceAvailable(),
|
||||
};
|
||||
streamTrArg.request = null;
|
||||
}
|
||||
|
||||
// chunk handling
|
||||
@ -350,10 +353,26 @@ export class VirtualStream<T = ArrayBufferLike> implements plugins.typedRequestI
|
||||
return dataPackage;
|
||||
}
|
||||
|
||||
public pipeWebStream(webStream: any) {
|
||||
// lets do the piping
|
||||
webStream.on('data', (data: any) => {});
|
||||
webStream.on('end', () => {});
|
||||
webStream.on('error', (error: any) => {});
|
||||
/**
|
||||
* reads from a Readable and sends it to the other side
|
||||
* @param readableStreamArg
|
||||
*/
|
||||
public async readFromWebstream(readableStreamArg: ReadableStream<T>) {
|
||||
const reader = readableStreamArg.getReader();
|
||||
let streamIsDone = false;
|
||||
while(!streamIsDone) {
|
||||
const { value, done } = await reader.read();
|
||||
if(value) {
|
||||
await this.sendData(value);
|
||||
}
|
||||
streamIsDone = done;
|
||||
}
|
||||
}
|
||||
|
||||
public async writeToWebstream(writableStreamArg: WritableStream<T>) {
|
||||
const writer = writableStreamArg.getWriter();
|
||||
while(this.keepAlive) {
|
||||
await writer.write(await this.fetchData());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user