fix(core): update

This commit is contained in:
Philipp Kunz 2024-02-25 01:54:01 +01:00
parent 51fedb270b
commit b346da01f1
6 changed files with 78 additions and 39 deletions

View File

@ -14,7 +14,7 @@
"buildDocs": "tsdoc"
},
"devDependencies": {
"@api.global/typedserver": "^3.0.23",
"@api.global/typedserver": "^3.0.24",
"@git.zone/tsbuild": "^2.1.72",
"@git.zone/tsbundle": "^2.0.15",
"@git.zone/tsrun": "^1.2.44",
@ -24,9 +24,10 @@
"@types/node": "^20.11.20"
},
"dependencies": {
"@api.global/typedrequest-interfaces": "^3.0.14",
"@api.global/typedrequest-interfaces": "^3.0.17",
"@push.rocks/isounique": "^1.0.5",
"@push.rocks/lik": "^6.0.13",
"@push.rocks/smartbuffer": "^1.0.6",
"@push.rocks/smartdelay": "^3.0.5",
"@push.rocks/smartpromise": "^4.0.3",
"@push.rocks/webrequest": "^3.0.34"

View File

@ -6,14 +6,17 @@ settings:
dependencies:
'@api.global/typedrequest-interfaces':
specifier: ^3.0.14
version: 3.0.14
specifier: ^3.0.17
version: 3.0.17
'@push.rocks/isounique':
specifier: ^1.0.5
version: 1.0.5
'@push.rocks/lik':
specifier: ^6.0.13
version: 6.0.13
'@push.rocks/smartbuffer':
specifier: ^1.0.6
version: 1.0.6
'@push.rocks/smartdelay':
specifier: ^3.0.5
version: 3.0.5
@ -26,8 +29,8 @@ dependencies:
devDependencies:
'@api.global/typedserver':
specifier: ^3.0.23
version: 3.0.23
specifier: ^3.0.24
version: 3.0.24
'@git.zone/tsbuild':
specifier: ^2.1.72
version: 2.1.72
@ -52,13 +55,13 @@ devDependencies:
packages:
/@api.global/typedrequest-interfaces@3.0.14:
resolution: {integrity: sha512-DvLKy1SrZYPxmt57ONH0hawJa2ZTF9tvyYdEn9bjy29hD3O/zOmtcWevtEHkOE5ifLGEpj6cwTyuNkBfsMoJ2w==}
/@api.global/typedrequest-interfaces@3.0.17:
resolution: {integrity: sha512-bbSNnhwgi9GOdxEMC0Sr776/7apJFjp9C3WnNUftptGvFhRQfOre6ifTwDKdFnAzZWH2A4g+hg16dbeqIL/vtA==}
/@api.global/typedrequest@3.0.4:
resolution: {integrity: sha512-8UThH9c3MxdSLiON8UN1CPXooU6Mp0eleFhVS3QB2OUsYqgEGn/EzuMt+cMIv/+ESSS6zcTpHvAhZ8ZMLfpL8A==}
dependencies:
'@api.global/typedrequest-interfaces': 3.0.14
'@api.global/typedrequest-interfaces': 3.0.17
'@push.rocks/isounique': 1.0.5
'@push.rocks/lik': 6.0.13
'@push.rocks/smartdelay': 3.0.5
@ -66,11 +69,11 @@ packages:
'@push.rocks/webrequest': 3.0.34
dev: true
/@api.global/typedserver@3.0.23:
resolution: {integrity: sha512-8n84MXIJXUxjEu6JVQulzdwQ+JYwXjhWbpqQQTDDeMNlpmaz3QEoE83rwehL8AyTaY++VwwYpkJqSXPGWQ+5ww==}
/@api.global/typedserver@3.0.24:
resolution: {integrity: sha512-aRzdJyws7cQ+uHZqgV5n9CudDscSHiefGBiUgrD9oKV+WUCnhgJSqYp6hoSp/lt2FqutdDOiw1MWsfApQRtTgw==}
dependencies:
'@api.global/typedrequest': 3.0.4
'@api.global/typedrequest-interfaces': 3.0.14
'@api.global/typedrequest-interfaces': 3.0.17
'@api.global/typedsocket': 3.0.0
'@push.rocks/lik': 6.0.13
'@push.rocks/smartchok': 1.0.32
@ -109,7 +112,7 @@ packages:
resolution: {integrity: sha512-ui+6MLd99iTN/lC+iC/FKPRjzVyiZ4PrmlU6ptbCtbBj3cSOXHx+RRGF54+be2xHodf4FOgwFv/GZdW8LtO3vg==}
dependencies:
'@api.global/typedrequest': 3.0.4
'@api.global/typedrequest-interfaces': 3.0.14
'@api.global/typedrequest-interfaces': 3.0.17
'@push.rocks/isohash': 2.0.1
'@push.rocks/smartjson': 5.0.10
'@push.rocks/smartrx': 3.0.7
@ -419,7 +422,7 @@ packages:
resolution: {integrity: sha512-ec95MNeA21L+ob+lvLVCmwPTTC1BY+v/JHLYZ9DOZ9+9buLgx+cJ7VkwGBJCnlWJtqEtJosUrFKTih36iNuT3g==}
hasBin: true
dependencies:
'@api.global/typedserver': 3.0.23
'@api.global/typedserver': 3.0.24
'@git.zone/tsbundle': 2.0.15
'@git.zone/tsrun': 1.2.46(@types/node@20.11.20)
'@push.rocks/consolecolor': 2.0.1
@ -626,6 +629,10 @@ packages:
- utf-8-validate
dev: true
/@push.rocks/smartbuffer@1.0.6:
resolution: {integrity: sha512-TpZuKVrj0D/C6+RApjajp2FGBfXuz7b9BQSYAR+N1XmAxO8jYAmS6YlChcofThY2aB9sTA98Tt110hM/d+cc8g==}
dev: false
/@push.rocks/smartcache@1.0.16:
resolution: {integrity: sha512-UAXf74eDuH4/RebJhydIbHlYVR3ACYJjniEY/9ZePblu7bIPgwFZqLBE9g1lcKVogbH9yY62dk3rSpgBzenyfQ==}
dependencies:
@ -939,8 +946,8 @@ packages:
/@push.rocks/smartsocket@2.0.24:
resolution: {integrity: sha512-Glqv1Zi5TXgD+04P8OvTpiytyfrQxTPv67qAwZizAVVQ2zWJJgKqnIuoHT1zKP8QiKRNer+D58LCxX0ZE2XfzQ==}
dependencies:
'@api.global/typedrequest-interfaces': 3.0.14
'@api.global/typedserver': 3.0.23
'@api.global/typedrequest-interfaces': 3.0.17
'@api.global/typedserver': 3.0.24
'@push.rocks/isohash': 2.0.1
'@push.rocks/isounique': 1.0.5
'@push.rocks/lik': 6.0.13
@ -1009,7 +1016,7 @@ packages:
'@types/randomatic': 3.1.5
buffer: 6.0.3
crypto-random-string: 5.0.0
js-base64: 3.7.6
js-base64: 3.7.7
normalize-newline: 4.1.0
randomatic: 3.1.1
strip-indent: 4.0.0
@ -1056,7 +1063,7 @@ packages:
/@push.rocks/smartxml@1.0.8:
resolution: {integrity: sha512-idrPsBj9t6oxkLZJZgWtyZK6PnQ5BVDbBErk0UfGanXgSWJc+ZEKNYjVqr850+Na3+y0CT6AQdug7pnaokygwg==}
dependencies:
fast-xml-parser: 4.3.4
fast-xml-parser: 4.3.5
dev: true
/@push.rocks/smartyaml@2.0.5:
@ -3082,8 +3089,8 @@ packages:
/fast-json-stable-stringify@2.1.0:
resolution: {integrity: sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==}
/fast-xml-parser@4.3.4:
resolution: {integrity: sha512-utnwm92SyozgA3hhH2I8qldf2lBqm6qHOICawRNRFu1qMe3+oqr+GcXjGqTmXTMGE5T4eC03kr/rlh5C1IRdZA==}
/fast-xml-parser@4.3.5:
resolution: {integrity: sha512-sWvP1Pl8H03B8oFJpFR3HE31HUfwtX7Rlf9BNsvdpujD4n7WMhfmu8h9wOV2u+c1k0ZilTADhPqypzx2J690ZQ==}
hasBin: true
dependencies:
strnum: 1.0.5
@ -3874,6 +3881,10 @@ packages:
resolution: {integrity: sha512-NPrWuHFxFUknr1KqJRDgUQPexQF0uIJWjeT+2KjEePhitQxQEx5EJBG1lVn5/hc8aLycTpXrDOgPQ6Zq+EDiTA==}
dev: true
/js-base64@3.7.7:
resolution: {integrity: sha512-7rCnleh0z2CkXhH67J8K1Ytz0b2Y+yxTPL+/KOJoa20hfnVQ/3/T6W/KflYI4bRHRagNeXeU2bkNGI3v1oS/lw==}
dev: true
/js-tokens@4.0.0:
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
dev: true
@ -5158,12 +5169,14 @@ packages:
is-fullwidth-code-point: 3.0.0
dev: true
/socket.io-adapter@2.5.2:
resolution: {integrity: sha512-87C3LO/NOMc+eMcpcxUBebGjkpMDkNBS9tf7KJqcDsmL936EChtVva71Dw2q4tQcuVC+hAUy4an2NO/sYXmwRA==}
/socket.io-adapter@2.5.4:
resolution: {integrity: sha512-wDNHGXGewWAjQPt3pyeYBtpWSq9cLE5UW1ZUPL/2eGK9jtse/FpXib7epSTsz0Q0m+6sg6Y4KtcFTlah1bdOVg==}
dependencies:
debug: 4.3.4
ws: 8.11.0
transitivePeerDependencies:
- bufferutil
- supports-color
- utf-8-validate
dev: true
@ -5200,7 +5213,7 @@ packages:
cors: 2.8.5
debug: 4.3.4
engine.io: 6.5.2
socket.io-adapter: 2.5.2
socket.io-adapter: 2.5.4
socket.io-parser: 4.2.4
transitivePeerDependencies:
- bufferutil

View File

@ -2,6 +2,7 @@ import { expect, tap } from '@push.rocks/tapbundle';
import * as typedserver from '@api.global/typedserver';
import * as typedrequest from '../ts/index.js';
import * as typedrequestInterfaces from '@api.global/typedrequest-interfaces';
let testServer: typedserver.servertools.Server;
let testTypedRouter: typedrequest.TypedRouter;
@ -21,10 +22,10 @@ interface ITestReqRes {
interface ITestStream {
method: 'handleStream';
request: {
requestStream: any;
requestStream: typedrequestInterfaces.IVirtualStream;
};
response: {
responseStream: any;
responseStream: typedrequestInterfaces.IVirtualStream;
};
}
@ -72,11 +73,16 @@ tap.test('should fire a request', async () => {
});
tap.test('should allow VirtualStreams', async () => {
const newRequestingVS = new typedrequest.VirtualStream();
const newRespondingVS = new typedrequest.VirtualStream();
let generatedRequestingVS: typedrequestInterfaces.IVirtualStream;
let generatedRespondingVS: typedrequestInterfaces.IVirtualStream;
testTypedRouter.addTypedHandler(new typedrequest.TypedHandler<ITestStream>('handleStream', async (reqArg) => {
console.log('hey there');
console.log(reqArg.requestStream);
generatedRequestingVS = reqArg.requestStream;
return {
responseStream: new typedrequest.VirtualStream(),
responseStream: newRespondingVS,
};
}));
const typedRequest = new typedrequest.TypedRequest<ITestStream>(
@ -84,9 +90,14 @@ tap.test('should allow VirtualStreams', async () => {
'handleStream'
);
const response = await typedRequest.fire({
requestStream: new typedrequest.VirtualStream(),
requestStream: newRequestingVS,
});
console.log(response.responseStream);
newRequestingVS.sendData(Buffer.from('hello'));
const data = await generatedRequestingVS.fetchData();
const decodedData = data.toString();
expect(data.toString()).toEqual('hello');
})
tap.test('should end the server', async (toolsArg) => {

View File

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

View File

@ -6,8 +6,9 @@ export { typedRequestInterfaces };
// pushrocks scope
import * as isounique from '@push.rocks/isounique';
import * as lik from '@push.rocks/lik';
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';
export { isounique, lik, smartdelay, smartpromise, webrequest };
export { isounique, lik, smartbuffer, smartdelay, smartpromise, webrequest };

View File

@ -15,7 +15,7 @@ export interface ICommFunctions {
* 3. It has a Readable and Writable side.
* 4. The Writable side is Readable on the other side and vice versa.
*/
export class VirtualStream<T = ArrayBufferLike> {
export class VirtualStream<T = ArrayBufferLike> implements plugins.typedRequestInterfaces.IVirtualStream<T> {
// STATIC
public static encodePayloadForNetwork(
objectPayload: any,
@ -23,6 +23,9 @@ export class VirtualStream<T = ArrayBufferLike> {
originalPayload?: any,
path = []
): any {
if (plugins.smartbuffer.isBufferLike(objectPayload)) {
return objectPayload;
}
if (objectPayload instanceof VirtualStream) {
if (!objectPayload.side && commFunctions.sendMethod) {
objectPayload.side = 'requesting';
@ -34,6 +37,7 @@ export class VirtualStream<T = ArrayBufferLike> {
commFunctions.typedrouter.registeredVirtualStreams.add(objectPayload);
}
if (!originalPayload.response || path.includes('response')) {
objectPayload.startKeepAliveLoop();
return {
_isVirtualStream: true,
streamId: objectPayload.streamId,
@ -74,6 +78,9 @@ export class VirtualStream<T = ArrayBufferLike> {
}
public static decodePayloadFromNetwork(objectPayload: any, commFunctions: ICommFunctions): any {
if (plugins.smartbuffer.isBufferLike(objectPayload)) {
return objectPayload;
}
if (objectPayload !== null && typeof objectPayload === 'object') {
if (objectPayload._isVirtualStream) {
const virtualStream = new VirtualStream();
@ -87,6 +94,7 @@ export class VirtualStream<T = ArrayBufferLike> {
virtualStream.typedrouter = commFunctions.typedrouter;
commFunctions.typedrouter.registeredVirtualStreams.add(virtualStream);
}
virtualStream.startKeepAliveLoop();
return virtualStream;
} else if (Array.isArray(objectPayload)) {
const returnArray = [];
@ -116,7 +124,7 @@ export class VirtualStream<T = ArrayBufferLike> {
// wether to keep the stream alive
private keepAlive = true;
private lastKeepAliveEvent = Date.now();
private lastKeepAliveEvent: number;
// backpressured arrays
private sendBackpressuredArray =
@ -128,9 +136,7 @@ export class VirtualStream<T = ArrayBufferLike> {
16
);
constructor() {
this.startKeepAliveLoop();
}
constructor() {}
/**
* takes care of sending
@ -162,26 +168,31 @@ export class VirtualStream<T = ArrayBufferLike> {
// do work loop
let thisSideIsBackpressured = this.receiveBackpressuredArray.checkSpaceAvailable();
let thisSideIsBackpressured = !this.receiveBackpressuredArray.checkSpaceAvailable();
let otherSideHasNext = false;
let otherSideIsBackpressured = false;
while (this.sendBackpressuredArray.data.length > 0 || otherSideHasNext) {
const dataArg = this.sendBackpressuredArray.shift();
const streamTr = await this.sendMethod({
let dataArg: typeof this.sendBackpressuredArray.data[0];
if (this.sendBackpressuredArray.data.length > 0) {
dataArg = this.sendBackpressuredArray.shift();
}
let streamTr: plugins.typedRequestInterfaces.IStreamRequest;
streamTr = await this.sendMethod({
method: '##VirtualStream##',
request: {
streamId: this.streamId,
cycleId: plugins.isounique.uni(),
cycle: 'request',
mainPurpose: 'chunk',
mainPurpose: dataArg ? 'chunk' : 'read',
backpressure: thisSideIsBackpressured,
next: this.sendBackpressuredArray.data.length > 0,
chunkData: dataArg,
...dataArg ? { chunkData: dataArg } : {},
},
response: null,
}).catch(() => {
console.log('stream ended immaturely');
this.keepAlive = false;
return null;
});
if (streamTr && streamTr.response && streamTr.response.chunkData) {
@ -264,6 +275,7 @@ export class VirtualStream<T = ArrayBufferLike> {
return streamTrArg;
}
// lifecycle methods
/**
* closes the virtual stream
*/
@ -328,6 +340,7 @@ export class VirtualStream<T = ArrayBufferLike> {
this.workOnQueue();
await this.sendBackpressuredArray.waitForSpace();
}
public async fetchData(): Promise<T> {
if (this.receiveBackpressuredArray.hasSpace) {
// do something maybe?