Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
f837bb5230 | |||
1b76e6882f | |||
83b43f501d | |||
9b626a562d | |||
c216f97bfd | |||
71453877d7 | |||
d1a601d006 | |||
0a9236a605 | |||
3a384307ee | |||
c215356b31 | |||
96f37dd470 | |||
10fac39d30 |
@ -3,10 +3,10 @@
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "apiglobal",
|
||||
"gitscope": "api.global",
|
||||
"gitrepo": "typedrequest",
|
||||
"description": "make typed requests towards apis",
|
||||
"npmPackagename": "@apiglobal/typedrequest",
|
||||
"npmPackagename": "@api.global/typedrequest",
|
||||
"license": "MIT",
|
||||
"projectDomain": "api.global"
|
||||
}
|
||||
|
31
package.json
31
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@apiglobal/typedrequest",
|
||||
"version": "2.0.13",
|
||||
"name": "@api.global/typedrequest",
|
||||
"version": "3.0.5",
|
||||
"private": false,
|
||||
"description": "make typed requests towards apis",
|
||||
"main": "dist_ts/index.js",
|
||||
@ -14,21 +14,22 @@
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.65",
|
||||
"@gitzone/tsbundle": "^2.0.7",
|
||||
"@gitzone/tstest": "^1.0.73",
|
||||
"@pushrocks/smartenv": "^5.0.3",
|
||||
"@pushrocks/smartexpress": "^4.0.21",
|
||||
"@pushrocks/tapbundle": "^5.0.4",
|
||||
"@types/node": "^18.7.6"
|
||||
"@api.global/typedserver": "^3.0.20",
|
||||
"@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.19"
|
||||
},
|
||||
"dependencies": {
|
||||
"@apiglobal/typedrequest-interfaces": "^2.0.0",
|
||||
"@pushrocks/isounique": "^1.0.5",
|
||||
"@pushrocks/lik": "^6.0.0",
|
||||
"@pushrocks/smartdelay": "^2.0.13",
|
||||
"@pushrocks/smartpromise": "^3.1.7",
|
||||
"@pushrocks/webrequest": "^3.0.13"
|
||||
"@api.global/typedrequest-interfaces": "^3.0.1",
|
||||
"@push.rocks/isounique": "^1.0.5",
|
||||
"@push.rocks/lik": "^6.0.12",
|
||||
"@push.rocks/smartdelay": "^3.0.5",
|
||||
"@push.rocks/smartpromise": "^4.0.3",
|
||||
"@push.rocks/webrequest": "^3.0.34"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
4804
pnpm-lock.yaml
generated
4804
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
|
||||
import * as typedrequest from '../ts/index.js';
|
||||
|
||||
|
10
test/test.ts
10
test/test.ts
@ -1,9 +1,9 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smartexpress from '@pushrocks/smartexpress';
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import * as typedserver from '@api.global/typedserver';
|
||||
|
||||
import * as typedrequest from '../ts/index.js';
|
||||
|
||||
let testServer: smartexpress.Server;
|
||||
let testServer: typedserver.servertools.Server;
|
||||
let testTypedHandler: typedrequest.TypedHandler<ITestReqRes>;
|
||||
|
||||
// lets define an interface
|
||||
@ -27,7 +27,7 @@ tap.test('should create a typedHandler', async () => {
|
||||
});
|
||||
|
||||
tap.test('should spawn a server to test with', async () => {
|
||||
testServer = new smartexpress.Server({
|
||||
testServer = new typedserver.servertools.Server({
|
||||
cors: true,
|
||||
forceSsl: false,
|
||||
port: 3000,
|
||||
@ -39,7 +39,7 @@ tap.test('should define a testHandler', async () => {
|
||||
testTypedRouter.addTypedHandler(testTypedHandler);
|
||||
testServer.addRoute(
|
||||
'/testroute',
|
||||
new smartexpress.HandlerTypedRouter(testTypedRouter as any) // the "any" is testspecific, since smartexpress ships with its own version of typedrequest.
|
||||
new typedserver.servertools.HandlerTypedRouter(testTypedRouter as any) // the "any" is testspecific, since smartexpress ships with its own version of typedrequest.
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@apiglobal/typedrequest',
|
||||
version: '2.0.13',
|
||||
name: '@api.global/typedrequest',
|
||||
version: '3.0.5',
|
||||
description: 'make typed requests towards apis'
|
||||
}
|
||||
|
13
ts/plugins.ts
Normal file
13
ts/plugins.ts
Normal file
@ -0,0 +1,13 @@
|
||||
// apiglobal scope
|
||||
import * as typedRequestInterfaces from '@api.global/typedrequest-interfaces';
|
||||
|
||||
export { typedRequestInterfaces };
|
||||
|
||||
// pushrocks scope
|
||||
import * as isounique from '@push.rocks/isounique';
|
||||
import * as lik from '@push.rocks/lik';
|
||||
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 };
|
44
ts/typedrequest.classes.streamobject.ts
Normal file
44
ts/typedrequest.classes.streamobject.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
export class VirtualStream {
|
||||
public streamId: string = plugins.isounique.uni();
|
||||
|
||||
constructor() {}
|
||||
|
||||
public static encodePayloadForNetwork(objectPayload: any): any {
|
||||
if (objectPayload instanceof VirtualStream) {
|
||||
return {
|
||||
_isVirtualStream: true,
|
||||
streamId: objectPayload.streamId,
|
||||
};
|
||||
} else if (Array.isArray(objectPayload)) {
|
||||
return objectPayload.map(VirtualStream.encodePayloadForNetwork);
|
||||
} else if (objectPayload !== null && typeof objectPayload === 'object') {
|
||||
return Object.keys(objectPayload).reduce((acc, key) => {
|
||||
acc[key] = VirtualStream.encodePayloadForNetwork(objectPayload[key]);
|
||||
return acc;
|
||||
}, {});
|
||||
} else {
|
||||
return objectPayload;
|
||||
}
|
||||
}
|
||||
|
||||
public static decodePayloadFromNetwork(objectPayload: any): any {
|
||||
if (objectPayload !== null && typeof objectPayload === 'object') {
|
||||
if (objectPayload._isVirtualStream) {
|
||||
const virtualStream = new VirtualStream();
|
||||
virtualStream.streamId = objectPayload.streamId;
|
||||
return virtualStream;
|
||||
} else if (Array.isArray(objectPayload)) {
|
||||
return objectPayload.map(VirtualStream.decodePayloadFromNetwork);
|
||||
} else {
|
||||
return Object.keys(objectPayload).reduce((acc, key) => {
|
||||
acc[key] = VirtualStream.decodePayloadFromNetwork(objectPayload[key]);
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
} else {
|
||||
return objectPayload;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import * as plugins from './typedrequest.plugins.js';
|
||||
import * as plugins from './plugins.js';
|
||||
import { TypedResponseError } from './typedrequest.classes.typedresponseerror.js';
|
||||
|
||||
export type THandlerFunction<T extends plugins.typedRequestInterfaces.ITypedRequest> = (
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as plugins from './typedrequest.plugins.js';
|
||||
import * as plugins from './plugins.js';
|
||||
import { TypedResponseError } from './typedrequest.classes.typedresponseerror.js';
|
||||
import { TypedRouter } from './typedrequest.classes.typedrouter.js';
|
||||
import { TypedTarget } from './typedrequest.classes.typedtarget.js';
|
||||
@ -36,7 +36,8 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
|
||||
* fires the request
|
||||
*/
|
||||
public async fire(fireArg: T['request'], useCacheArg: boolean = false): Promise<T['response']> {
|
||||
const payload: plugins.typedRequestInterfaces.ITypedRequest = {
|
||||
|
||||
let payload: plugins.typedRequestInterfaces.ITypedRequest = {
|
||||
method: this.method,
|
||||
request: fireArg,
|
||||
response: null,
|
||||
@ -56,7 +57,7 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
|
||||
if (responseBody.error) {
|
||||
console.error(
|
||||
`Got an error ${responseBody.error.text} with data ${JSON.stringify(
|
||||
responseBody.error.data
|
||||
responseBody.error.data, null, 2
|
||||
)}`
|
||||
);
|
||||
if (!responseBody.retry) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as plugins from './typedrequest.plugins.js';
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
export class TypedResponseError {
|
||||
public errorText: string;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as plugins from './typedrequest.plugins.js';
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
import { TypedHandler } from './typedrequest.classes.typedhandler.js';
|
||||
import { TypedRequest } from './typedrequest.classes.typedrequest.js';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { TypedRouter } from './typedrequest.classes.typedrouter.js';
|
||||
import * as plugins from './typedrequest.plugins.js';
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
export type IPostMethod = (
|
||||
typedRequestPostObject: plugins.typedRequestInterfaces.ITypedRequest
|
||||
|
@ -1,13 +0,0 @@
|
||||
// apiglobal scope
|
||||
import * as typedRequestInterfaces from '@apiglobal/typedrequest-interfaces';
|
||||
|
||||
export { typedRequestInterfaces };
|
||||
|
||||
// pushrocks scope
|
||||
import * as isounique from '@pushrocks/isounique';
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as webrequest from '@pushrocks/webrequest';
|
||||
|
||||
export { isounique, lik, smartdelay, smartpromise, webrequest };
|
Reference in New Issue
Block a user