Compare commits

...

14 Commits

Author SHA1 Message Date
f837bb5230 3.0.5 2024-02-20 17:40:31 +01:00
1b76e6882f fix(core): update 2024-02-20 17:40:30 +01:00
83b43f501d 3.0.4 2023-12-08 19:36:25 +01:00
9b626a562d fix(core): update 2023-12-08 19:36:24 +01:00
c216f97bfd 3.0.3 2023-12-05 23:42:44 +01:00
71453877d7 fix(core): update 2023-12-05 23:42:43 +01:00
d1a601d006 3.0.2 2023-10-20 17:39:09 +02:00
0a9236a605 fix(core): update 2023-10-20 17:39:08 +02:00
3a384307ee 3.0.1 2023-08-04 16:55:25 +02:00
c215356b31 fix(core): update 2023-08-04 16:55:24 +02:00
96f37dd470 3.0.0 2023-08-04 16:10:48 +02:00
10fac39d30 BREAKING CHANGE(core): update 2023-08-04 16:10:47 +02:00
912572cba5 2.0.13 2022-10-26 14:23:24 +02:00
b001ebaab8 fix(core): update 2022-10-26 14:23:24 +02:00
15 changed files with 6069 additions and 14178 deletions

View File

@ -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"
}

14133
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@apiglobal/typedrequest",
"version": "2.0.12",
"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": "^1.0.15",
"@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/**/*",

5978
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
import { expect, tap } from '@pushrocks/tapbundle';
import { expect, tap } from '@push.rocks/tapbundle';
import * as typedrequest from '../ts/index.js';

View File

@ -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.
);
});

View File

@ -2,7 +2,7 @@
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@apiglobal/typedrequest',
version: '2.0.12',
name: '@api.global/typedrequest',
version: '3.0.5',
description: 'make typed requests towards apis'
}

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

View 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;
}
}
}

View File

@ -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> = (

View File

@ -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) {

View File

@ -1,4 +1,4 @@
import * as plugins from './typedrequest.plugins.js';
import * as plugins from './plugins.js';
export class TypedResponseError {
public errorText: string;

View File

@ -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';

View File

@ -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

View File

@ -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 };