Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
7ce3f83d54 | |||
2e0c6400e8 | |||
58637ed90e | |||
489fa237b9 | |||
4449c82611 | |||
fe31a779e4 | |||
9b96c22d6a | |||
262891ccf3 | |||
0d60b29ff7 | |||
ecca2a9f32 | |||
3643e5e753 | |||
4cba418f13 | |||
a966b0735c | |||
6fed2cdc5c |
21
package.json
21
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@api.global/typedrequest",
|
||||
"version": "3.0.20",
|
||||
"version": "3.0.27",
|
||||
"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,24 +14,25 @@
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@api.global/typedserver": "^3.0.27",
|
||||
"@git.zone/tsbuild": "^2.1.72",
|
||||
"@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.88",
|
||||
"@git.zone/tstest": "^1.0.90",
|
||||
"@push.rocks/smartenv": "^5.0.12",
|
||||
"@push.rocks/tapbundle": "^5.0.23",
|
||||
"@types/node": "^20.12.7"
|
||||
"@types/node": "^20.12.13"
|
||||
},
|
||||
"dependencies": {
|
||||
"@api.global/typedrequest-interfaces": "^3.0.18",
|
||||
"@api.global/typedrequest-interfaces": "^3.0.19",
|
||||
"@push.rocks/isounique": "^1.0.5",
|
||||
"@push.rocks/lik": "^6.0.14",
|
||||
"@push.rocks/smartbuffer": "^2.0.3",
|
||||
"@push.rocks/lik": "^6.0.15",
|
||||
"@push.rocks/smartbuffer": "^3.0.4",
|
||||
"@push.rocks/smartdelay": "^3.0.5",
|
||||
"@push.rocks/smartguard": "^3.0.2",
|
||||
"@push.rocks/smartpromise": "^4.0.3",
|
||||
"@push.rocks/webrequest": "^3.0.36",
|
||||
"@push.rocks/webstream": "^1.0.8"
|
||||
"@push.rocks/webrequest": "^3.0.37",
|
||||
"@push.rocks/webstream": "^1.0.10"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
7567
pnpm-lock.yaml
generated
7567
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -44,4 +44,4 @@ tap.skip.test('test', async (tools) => {
|
||||
await tools.delayFor(5000);
|
||||
})
|
||||
|
||||
tap.start();
|
||||
export default tap.start();
|
||||
|
@ -106,4 +106,4 @@ tap.test('should end the server', async (toolsArg) => {
|
||||
setTimeout(() => process.exit(0), 100);
|
||||
});
|
||||
|
||||
tap.start();
|
||||
export default tap.start();
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@api.global/typedrequest',
|
||||
version: '3.0.20',
|
||||
version: '3.0.27',
|
||||
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 './typedrequest.classes.typedresponseerror.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 {
|
@ -1,8 +1,8 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import { VirtualStream } from './typedrequest.classes.virtualstream.js';
|
||||
import { TypedResponseError } from './typedrequest.classes.typedresponseerror.js';
|
||||
import { TypedRouter } from './typedrequest.classes.typedrouter.js';
|
||||
import { TypedTarget } from './typedrequest.classes.typedtarget.js';
|
||||
import { VirtualStream } from './classes.virtualstream.js';
|
||||
import { TypedResponseError } from './classes.typedresponseerror.js';
|
||||
import { TypedRouter } from './classes.typedrouter.js';
|
||||
import { TypedTarget } from './classes.typedtarget.js';
|
||||
|
||||
const webrequestInstance = new plugins.webrequest.WebRequest();
|
||||
|
@ -1,8 +1,8 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import { VirtualStream } from './typedrequest.classes.virtualstream.js';
|
||||
import { VirtualStream } from './classes.virtualstream.js';
|
||||
|
||||
import { TypedHandler } from './typedrequest.classes.typedhandler.js';
|
||||
import { TypedRequest } from './typedrequest.classes.typedrequest.js';
|
||||
import { TypedHandler } from './classes.typedhandler.js';
|
||||
import { TypedRequest } from './classes.typedrequest.js';
|
||||
|
||||
/**
|
||||
* A typed router decides on which typed handler to call based on the method
|
@ -1,4 +1,4 @@
|
||||
import { TypedRouter } from './typedrequest.classes.typedrouter.js';
|
||||
import { TypedRouter } from './classes.typedrouter.js';
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
export type IPostMethod = (
|
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 });
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import type { TypedRouter } from './typedrequest.classes.typedrouter.js';
|
||||
import { TypedRouter } from './classes.typedrouter.js';
|
||||
|
||||
export interface ICommFunctions {
|
||||
sendMethod?: (
|
||||
@ -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> implements plugins.typedRequestInterfaces.IVirtualStream<T> {
|
||||
export class VirtualStream<T = Uint8Array> implements plugins.typedRequestInterfaces.IVirtualStream<T> {
|
||||
// STATIC
|
||||
public static encodePayloadForNetwork(
|
||||
objectPayload: any,
|
||||
@ -79,7 +79,11 @@ export class VirtualStream<T = ArrayBufferLike> implements plugins.typedRequestI
|
||||
}
|
||||
|
||||
public static decodePayloadFromNetwork(objectPayload: any, commFunctions: ICommFunctions): any {
|
||||
if (plugins.smartbuffer.isBufferLike(objectPayload)) {
|
||||
|
||||
if (
|
||||
plugins.smartbuffer.isBufferLike(objectPayload)
|
||||
|| objectPayload instanceof TypedRouter
|
||||
) {
|
||||
return objectPayload;
|
||||
}
|
||||
if (objectPayload !== null && typeof objectPayload === 'object') {
|
12
ts/index.ts
12
ts/index.ts
@ -1,6 +1,6 @@
|
||||
export * from './typedrequest.classes.typedrequest.js';
|
||||
export * from './typedrequest.classes.typedhandler.js';
|
||||
export * from './typedrequest.classes.typedrouter.js';
|
||||
export * from './typedrequest.classes.typedresponseerror.js';
|
||||
export * from './typedrequest.classes.typedtarget.js';
|
||||
export * from './typedrequest.classes.virtualstream.js';
|
||||
export * from './classes.typedrequest.js';
|
||||
export * from './classes.typedhandler.js';
|
||||
export * from './classes.typedrouter.js';
|
||||
export * from './classes.typedresponseerror.js';
|
||||
export * from './classes.typedtarget.js';
|
||||
export * from './classes.virtualstream.js';
|
@ -8,8 +8,8 @@ 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 smartguard from '@push.rocks/smartguard';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as webrequest from '@push.rocks/webrequest';
|
||||
|
||||
|
||||
export { isounique, lik, smartbuffer, smartdelay, smartpromise, webrequest };
|
||||
export { isounique, lik, smartbuffer, smartdelay, smartguard, smartpromise, webrequest };
|
||||
|
Reference in New Issue
Block a user