Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
f3f2f8e3bf | |||
cf304ceccd | |||
6f075132c4 | |||
4dca98e81d | |||
1e022d6c68 | |||
f20d737ecf | |||
d791eca5e8 | |||
63c6dac8fa | |||
c2c1dee427 | |||
4ae90a5cf6 | |||
803d4d2894 | |||
fcc75af1ff | |||
0e3bb07a69 | |||
c90aa07ace |
17193
package-lock.json
generated
17193
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
24
package.json
24
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@apiglobal/typedrequest",
|
||||
"version": "2.0.2",
|
||||
"version": "2.0.9",
|
||||
"private": false,
|
||||
"description": "make typed requests towards apis",
|
||||
"main": "dist_ts/index.js",
|
||||
@ -10,27 +10,25 @@
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web && tsbundle npm)",
|
||||
"build": "(tsbuild --web --allowimplicitany && tsbundle npm)",
|
||||
"format": "(gitzone format)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.61",
|
||||
"@gitzone/tsbundle": "^1.0.101",
|
||||
"@gitzone/tstest": "^1.0.69",
|
||||
"@pushrocks/smartenv": "^5.0.0",
|
||||
"@pushrocks/smartexpress": "^4.0.0",
|
||||
"@pushrocks/tapbundle": "^5.0.3",
|
||||
"@types/node": "^17.0.23",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
"@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"
|
||||
},
|
||||
"dependencies": {
|
||||
"@apiglobal/typedrequest-interfaces": "^1.0.15",
|
||||
"@pushrocks/isounique": "^1.0.5",
|
||||
"@pushrocks/lik": "^5.0.4",
|
||||
"@pushrocks/lik": "^6.0.0",
|
||||
"@pushrocks/smartdelay": "^2.0.13",
|
||||
"@pushrocks/smartpromise": "^3.1.7",
|
||||
"@pushrocks/webrequest": "^3.0.2"
|
||||
"@pushrocks/webrequest": "^3.0.12"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@apiglobal/typedrequest',
|
||||
version: '2.0.9',
|
||||
description: 'make typed requests towards apis'
|
||||
}
|
@ -32,7 +32,7 @@ export class TypedHandler<T extends plugins.typedRequestInterfaces.ITypedRequest
|
||||
if (e instanceof TypedResponseError) {
|
||||
typedResponseError = e;
|
||||
} else {
|
||||
throw e;
|
||||
console.log(e);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -37,7 +37,7 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
|
||||
/**
|
||||
* fires the request
|
||||
*/
|
||||
public async fire(fireArg: T['request']): Promise<T['response']> {
|
||||
public async fire(fireArg: T['request'], useCacheArg: boolean = false): Promise<T['response']> {
|
||||
const payload: plugins.typedRequestInterfaces.ITypedRequest = {
|
||||
method: this.method,
|
||||
request: fireArg,
|
||||
@ -50,7 +50,7 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
|
||||
|
||||
let responseBody: plugins.typedRequestInterfaces.ITypedRequest;
|
||||
if (this.urlEndPoint) {
|
||||
const response = await webrequestInstance.postJson(this.urlEndPoint, payload);
|
||||
const response = await webrequestInstance.postJson(this.urlEndPoint, payload, useCacheArg);
|
||||
responseBody = response;
|
||||
} else {
|
||||
responseBody = await this.typedTarget.post(payload);
|
||||
|
@ -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,7 +41,7 @@ export class TypedRouter {
|
||||
* adds another sub typedRouter
|
||||
* @param typedRequest
|
||||
*/
|
||||
public addTypedRouter(typedRouterArg: TypedRouter) {
|
||||
public addTypedRouter (typedRouterArg: TypedRouter) {
|
||||
const routerExists = this.routerMap.findSync(routerArg => routerArg === typedRouterArg)
|
||||
if (!routerExists) {
|
||||
this.routerMap.add(typedRouterArg);
|
||||
@ -49,7 +49,7 @@ export class TypedRouter {
|
||||
}
|
||||
}
|
||||
|
||||
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> {
|
||||
@ -69,7 +69,7 @@ export class TypedRouter {
|
||||
typedHandler = this.handlerMap.findSync((handler) => {
|
||||
return handler.method === methodArg;
|
||||
});
|
||||
|
||||
|
||||
if (!typedHandler) {
|
||||
this.routerMap.getArray().forEach((typedRouterArg) => {
|
||||
if (!typedHandler && !checkedRouters.includes(typedRouterArg)) {
|
||||
@ -86,7 +86,7 @@ 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 = any>(typedRequestArg: T): Promise<T> {
|
||||
public async routeAndAddResponse<T extends plugins.typedRequestInterfaces.ITypedRequest = plugins.typedRequestInterfaces.ITypedRequest> (typedRequestArg: T): Promise<T> {
|
||||
if (typedRequestArg?.correlation?.phase === 'request') {
|
||||
const typedHandler = this.getTypedHandlerForMethod(typedRequestArg.method);
|
||||
|
||||
@ -106,6 +106,7 @@ export class TypedRouter {
|
||||
this.fireEventInterestMap
|
||||
.findInterest(typedRequestArg.correlation.id)
|
||||
?.fullfillInterest(typedRequestArg);
|
||||
return null;
|
||||
} else {
|
||||
console.log('received weirdly shaped request');
|
||||
console.log(typedRequestArg);
|
||||
|
10
tsconfig.json
Normal file
10
tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext",
|
||||
"esModuleInterop": true
|
||||
}
|
||||
}
|
17
tslint.json
17
tslint.json
@ -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"
|
||||
}
|
Reference in New Issue
Block a user