Compare commits

...

24 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
aa15da6b92 2.0.12 2022-10-09 18:57:31 +02:00
f144f27daa fix(core): update 2022-10-09 18:57:31 +02:00
a58c9a0541 2.0.11 2022-10-09 18:52:50 +02:00
649db1059c fix(core): update 2022-10-09 18:52:49 +02:00
e0c75716d7 2.0.10 2022-08-19 17:59:47 +02:00
009985c226 fix(core): update 2022-08-19 17:59:47 +02:00
f3f2f8e3bf 2.0.9 2022-08-18 23:24:04 +02:00
cf304ceccd fix(core): update 2022-08-18 23:24:04 +02:00
6f075132c4 2.0.8 2022-07-29 04:48:34 +02:00
4dca98e81d fix(core): update 2022-07-29 04:48:34 +02:00
19 changed files with 6106 additions and 10920 deletions

View File

@ -12,20 +12,12 @@ stages:
- release
- metadata
before_script:
- npm install -g @shipzone/npmci
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
@ -36,6 +28,7 @@ auditProductionDependencies:
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
@ -96,10 +89,9 @@ codequality:
only:
- tags
script:
- npmci command npm install -g tslint typescript
- npmci command npm install -g typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- lossless
- docker
@ -119,11 +111,10 @@ trigger:
pages:
stage: metadata
script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci node install stable
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
- npmci command npm run buildDocs
tags:
- lossless
- docker

24
.vscode/launch.json vendored
View File

@ -2,28 +2,10 @@
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
"type": "node-terminal"
}
]
}

View File

@ -3,10 +3,10 @@
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "apiglobal",
"gitscope": "api.global",
"gitrepo": "typedrequest",
"shortDescription": "make typed requests towards apis",
"npmPackagename": "@apiglobal/typedrequest",
"description": "make typed requests towards apis",
"npmPackagename": "@api.global/typedrequest",
"license": "MIT",
"projectDomain": "api.global"
}

10804
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.7",
"name": "@api.global/typedrequest",
"version": "3.0.5",
"private": false,
"description": "make typed requests towards apis",
"main": "dist_ts/index.js",
@ -11,26 +11,25 @@
"scripts": {
"test": "(tstest test/)",
"build": "(tsbuild --web --allowimplicitany && tsbundle npm)",
"format": "(gitzone format)"
"buildDocs": "tsdoc"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.63",
"@gitzone/tsbundle": "^2.0.4",
"@gitzone/tstest": "^1.0.71",
"@pushrocks/smartenv": "^5.0.2",
"@pushrocks/smartexpress": "^4.0.5",
"@pushrocks/tapbundle": "^5.0.3",
"@types/node": "^17.0.36",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
"@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.7"
"@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.7',
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> = (
@ -32,7 +32,7 @@ export class TypedHandler<T extends plugins.typedRequestInterfaces.ITypedRequest
if (e instanceof TypedResponseError) {
typedResponseError = e;
} else {
throw e;
console.log(e);
}
});

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';
@ -6,8 +6,6 @@ import { TypedTarget } from './typedrequest.classes.typedtarget.js';
const webrequestInstance = new plugins.webrequest.WebRequest();
export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest> {
/**
* in case we post against a url endpoint
*/
@ -23,7 +21,7 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
/**
* note the overloading is thought to deal with promises
* @param postEndPointArg
* @param methodArg
* @param methodArg
*/
constructor(postTarget: string | TypedTarget, methodArg: T['method']) {
if (typeof postTarget === 'string') {
@ -38,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,
@ -58,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';
@ -23,7 +23,7 @@ export class TypedRouter {
* adds the handler to the routing map
* @param typedHandlerArg
*/
public addTypedHandler<T extends plugins.typedRequestInterfaces.ITypedRequest> (
public addTypedHandler<T extends plugins.typedRequestInterfaces.ITypedRequest>(
typedHandlerArg: TypedHandler<T>
) {
// lets check for deduplication
@ -41,15 +41,15 @@ export class TypedRouter {
* adds another sub typedRouter
* @param typedRequest
*/
public addTypedRouter (typedRouterArg: TypedRouter) {
const routerExists = this.routerMap.findSync(routerArg => routerArg === typedRouterArg)
public addTypedRouter(typedRouterArg: TypedRouter) {
const routerExists = this.routerMap.findSync((routerArg) => routerArg === typedRouterArg);
if (!routerExists) {
this.routerMap.add(typedRouterArg);
typedRouterArg.addTypedRouter(this);
}
}
public checkForTypedHandler (methodArg: string): boolean {
public checkForTypedHandler(methodArg: string): boolean {
return !!this.getTypedHandlerForMethod(methodArg);
}
@ -58,7 +58,7 @@ export class TypedRouter {
* @param methodArg
* @param checkUpstreamRouter
*/
public getTypedHandlerForMethod (
public getTypedHandlerForMethod(
methodArg: string,
checkedRouters: TypedRouter[] = []
): TypedHandler<any> {
@ -86,8 +86,10 @@ export class TypedRouter {
* if typedrequest object has correlation.phase === 'response' -> routes a typed request object to request fire event
* @param typedRequestArg
*/
public async routeAndAddResponse<T extends plugins.typedRequestInterfaces.ITypedRequest = plugins.typedRequestInterfaces.ITypedRequest> (typedRequestArg: T): Promise<T> {
if (typedRequestArg?.correlation?.phase === 'request') {
public async routeAndAddResponse<
T extends plugins.typedRequestInterfaces.ITypedRequest = plugins.typedRequestInterfaces.ITypedRequest
>(typedRequestArg: T, localRequestArg = false): Promise<T> {
if (typedRequestArg?.correlation?.phase === 'request' || localRequestArg) {
const typedHandler = this.getTypedHandlerForMethod(typedRequestArg.method);
if (!typedHandler) {
@ -110,7 +112,7 @@ export class TypedRouter {
} else {
console.log('received weirdly shaped request');
console.log(typedRequestArg);
return null
return null;
}
}
}

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
@ -52,7 +52,9 @@ export class TypedTarget {
*/
public isAsync: boolean;
public async post<T extends plugins.typedRequestInterfaces.ITypedRequest>(payloadArg: T): Promise<T> {
public async post<T extends plugins.typedRequestInterfaces.ITypedRequest>(
payloadArg: T
): Promise<T> {
let responseInterest: plugins.lik.Interest<
string,
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 };

10
tsconfig.json Normal file
View File

@ -0,0 +1,10 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext",
"esModuleInterop": true
}
}

View File

@ -1,17 +0,0 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}