fix(core): update

This commit is contained in:
Philipp Kunz 2024-05-30 22:41:49 +02:00
parent 58637ed90e
commit 2e0c6400e8
5 changed files with 280 additions and 174 deletions

View File

@ -14,14 +14,14 @@
"buildDocs": "tsdoc"
},
"devDependencies": {
"@api.global/typedserver": "^3.0.44",
"@api.global/typedserver": "^3.0.50",
"@git.zone/tsbuild": "^2.1.80",
"@git.zone/tsbundle": "^2.0.15",
"@git.zone/tsrun": "^1.2.44",
"@git.zone/tstest": "^1.0.90",
"@push.rocks/smartenv": "^5.0.12",
"@push.rocks/tapbundle": "^5.0.23",
"@types/node": "^20.12.12"
"@types/node": "^20.12.13"
},
"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/smartguard": "^3.0.2",
"@push.rocks/smartpromise": "^4.0.3",
"@push.rocks/webrequest": "^3.0.37",
"@push.rocks/webstream": "^1.0.8"
"@push.rocks/webstream": "^1.0.10"
},
"files": [
"ts/**/*",

424
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@api.global/typedrequest',
version: '3.0.26',
version: '3.0.27',
description: 'A TypeScript library for making typed requests towards APIs, including facilities for handling requests, routing, and virtual stream handling.'
}

View File

@ -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?: any
) => 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 {

13
ts/classes.typedtools.ts Normal file
View 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 });
}
}
}