Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
855663eea9 | |||
4d98915dbd | |||
f461f16bfd | |||
6beadb8cfc | |||
360c8a618b | |||
c03854a9fc | |||
cebd903c9b | |||
e7cf5b7694 | |||
839bd138c1 | |||
e1c721d511 | |||
7ce3f83d54 | |||
2e0c6400e8 |
24
changelog.md
Normal file
24
changelog.md
Normal file
@ -0,0 +1,24 @@
|
||||
# Changelog
|
||||
|
||||
## 2024-09-06 - 3.0.32 - fix(virtualstream)
|
||||
Fix keep-alive loop handling and test cleanup
|
||||
|
||||
- Prevent unnecessary keep-alive loop from starting on the responding side
|
||||
- Add logging for keep-alive loop initiation in VirtualStream
|
||||
- Temporarily comment out stream close and tap forceful stop in test to avoid abrupt termination
|
||||
|
||||
## 2024-09-06 - 3.0.31 - fix(core)
|
||||
Updated dependencies and added close method to VirtualStream
|
||||
|
||||
- Updated dependencies in package.json for better compatibility
|
||||
- Added close method to VirtualStream class in ts/classes.virtualstream.ts for more graceful stream termination
|
||||
|
||||
## 2024-05-31 - 3.0.28 - Error Handling
|
||||
Enhancement to error handling mechanisms.
|
||||
|
||||
- Logs now include the method to which an error was given.
|
||||
|
||||
## 2023-08-04 - 3.0.0 - Core
|
||||
Introduced a breaking change.
|
||||
|
||||
- Major update to core functionalities.
|
18
package.json
18
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@api.global/typedrequest",
|
||||
"version": "3.0.26",
|
||||
"version": "3.0.32",
|
||||
"private": false,
|
||||
"description": "A TypeScript library for making typed requests towards APIs, including facilities for handling requests, routing, and virtual stream handling.",
|
||||
"main": "dist_ts/index.js",
|
||||
@ -14,14 +14,14 @@
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@api.global/typedserver": "^3.0.44",
|
||||
"@git.zone/tsbuild": "^2.1.80",
|
||||
"@api.global/typedserver": "^3.0.51",
|
||||
"@git.zone/tsbuild": "^2.1.84",
|
||||
"@git.zone/tsbundle": "^2.0.15",
|
||||
"@git.zone/tsrun": "^1.2.44",
|
||||
"@git.zone/tsrun": "^1.2.49",
|
||||
"@git.zone/tstest": "^1.0.90",
|
||||
"@push.rocks/smartenv": "^5.0.12",
|
||||
"@push.rocks/tapbundle": "^5.0.23",
|
||||
"@types/node": "^20.12.12"
|
||||
"@push.rocks/tapbundle": "^5.0.24",
|
||||
"@types/node": "^22.5.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@api.global/typedrequest-interfaces": "^3.0.19",
|
||||
@ -29,10 +29,10 @@
|
||||
"@push.rocks/lik": "^6.0.15",
|
||||
"@push.rocks/smartbuffer": "^3.0.4",
|
||||
"@push.rocks/smartdelay": "^3.0.5",
|
||||
"@push.rocks/smartguard": "^3.0.1",
|
||||
"@push.rocks/smartpromise": "^4.0.3",
|
||||
"@push.rocks/smartguard": "^3.1.0",
|
||||
"@push.rocks/smartpromise": "^4.0.4",
|
||||
"@push.rocks/webrequest": "^3.0.37",
|
||||
"@push.rocks/webstream": "^1.0.8"
|
||||
"@push.rocks/webstream": "^1.0.10"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
1439
pnpm-lock.yaml
generated
1439
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -98,12 +98,13 @@ tap.test('should allow VirtualStreams', async () => {
|
||||
const data = await generatedRequestingVS.fetchData();
|
||||
const decodedData = new TextDecoder().decode(data);
|
||||
expect(decodedData).toEqual('hello');
|
||||
// await newRequestingVS.close();
|
||||
});
|
||||
|
||||
tap.test('should end the server', async (toolsArg) => {
|
||||
await toolsArg.delayFor(1000);
|
||||
await testServer.stop();
|
||||
setTimeout(() => process.exit(0), 100);
|
||||
// await tap.stopForcefully();
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@api.global/typedrequest',
|
||||
version: '3.0.26',
|
||||
version: '3.0.32',
|
||||
description: 'A TypeScript library for making typed requests towards APIs, including facilities for handling requests, routing, and virtual stream handling.'
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import { TypedResponseError } from './classes.typedresponseerror.js';
|
||||
import { TypedTools } from './classes.typedtools.js';
|
||||
|
||||
export type THandlerFunction<T extends plugins.typedRequestInterfaces.ITypedRequest> = (
|
||||
requestArg: T['request']
|
||||
requestArg: T['request'],
|
||||
typedToolsArg?: TypedTools
|
||||
) => Promise<T['response']>;
|
||||
|
||||
/**
|
||||
@ -28,7 +30,8 @@ export class TypedHandler<T extends plugins.typedRequestInterfaces.ITypedRequest
|
||||
);
|
||||
}
|
||||
let typedResponseError: TypedResponseError;
|
||||
const response = await this.handlerFunction(typedRequestArg.request).catch((e) => {
|
||||
const typedtoolsInstance = new TypedTools();
|
||||
const response = await this.handlerFunction(typedRequestArg.request, typedtoolsInstance).catch((e) => {
|
||||
if (e instanceof TypedResponseError) {
|
||||
typedResponseError = e;
|
||||
} else {
|
||||
|
@ -79,7 +79,7 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
|
||||
}
|
||||
if (payloadReceiving.error) {
|
||||
console.error(
|
||||
`Got an error ${payloadReceiving.error.text} with data ${JSON.stringify(
|
||||
`method: >>${this.method}<< got an ERROR: "${payloadReceiving.error.text}" with data ${JSON.stringify(
|
||||
payloadReceiving.error.data,
|
||||
null,
|
||||
2
|
||||
|
13
ts/classes.typedtools.ts
Normal file
13
ts/classes.typedtools.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { TypedResponseError } from './classes.typedresponseerror.js';
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
export class TypedTools {
|
||||
public async passGuards<T = any>(guardsArg: plugins.smartguard.Guard<T>[], dataArg: T) {
|
||||
const guardSet = new plugins.smartguard.GuardSet<T>(guardsArg);
|
||||
const guardResult = await guardSet.allGuardsPass(dataArg);
|
||||
if (!guardResult) {
|
||||
const failedHint = await guardSet.getFailedHint(dataArg);
|
||||
throw new TypedResponseError(`guard failed: ${failedHint}`, { failedHint });
|
||||
}
|
||||
}
|
||||
}
|
@ -295,10 +295,14 @@ export class VirtualStream<T = Uint8Array> implements plugins.typedRequestInterf
|
||||
*/
|
||||
private async startKeepAliveLoop() {
|
||||
// initially wait for a second
|
||||
if (this.side === 'responding') {
|
||||
return;
|
||||
}
|
||||
await plugins.smartdelay.delayFor(0);
|
||||
console.log(`starting keepalive loop on side ${this.side}`);
|
||||
let counter = 0;
|
||||
keepAliveLoop: while (this.keepAlive) {
|
||||
const triggerResult = await this.triggerKeepAlive();
|
||||
await this.triggerKeepAlive();
|
||||
await plugins.smartdelay.delayFor(1000);
|
||||
}
|
||||
await plugins.smartdelay.delayFor(1000);
|
||||
@ -377,4 +381,8 @@ export class VirtualStream<T = Uint8Array> implements plugins.typedRequestInterf
|
||||
await writer.write(await this.fetchData());
|
||||
}
|
||||
}
|
||||
|
||||
public async close() {
|
||||
this.keepAlive = false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user