Compare commits

...

16 Commits

Author SHA1 Message Date
265109fca6 1.0.52 2020-10-06 17:37:07 +00:00
8bfd4d8866 fix(core): update 2020-10-06 17:37:06 +00:00
785f247027 1.0.51 2020-10-06 17:28:00 +00:00
3f3f488dc4 fix(core): update 2020-10-06 17:27:59 +00:00
0241eda296 1.0.50 2020-10-06 16:37:25 +00:00
66722759af fix(core): update 2020-10-06 16:37:25 +00:00
e9fad241ee 1.0.49 2020-10-06 15:50:12 +00:00
34face164f fix(core): update 2020-10-06 15:50:12 +00:00
f7bf366962 1.0.48 2020-10-06 15:05:29 +00:00
046059d228 fix(core): update 2020-10-06 15:05:29 +00:00
78e8171a6a 1.0.47 2020-10-06 14:29:50 +00:00
c97a535035 fix(core): update 2020-10-06 14:29:49 +00:00
dcf198787a 1.0.46 2020-09-29 15:51:06 +00:00
a1e0ebd658 fix(core): update 2020-09-29 15:51:05 +00:00
8bf0a71266 1.0.45 2020-09-14 08:28:08 +00:00
e499612ecb fix(core): update 2020-09-14 08:28:07 +00:00
9 changed files with 63 additions and 31 deletions

View File

@ -19,23 +19,35 @@ mirror:
stage: security
script:
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
audit:
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high
- npmci command npm audit --audit-level=high --only=dev
tags:
- lossless
- docker
- notpriv
allow_failure: true
# ====================
# test stage
@ -50,9 +62,7 @@ testStable:
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- priv
testBuild:
stage: test
@ -63,9 +73,7 @@ testBuild:
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- notpriv
release:
stage: release
@ -85,6 +93,8 @@ release:
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare

View File

@ -15,7 +15,7 @@
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm"]
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@apiglobal/typedrequest",
"version": "1.0.44",
"version": "1.0.52",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@apiglobal/typedrequest",
"version": "1.0.44",
"version": "1.0.52",
"private": false,
"description": "make typed requests towards apis",
"main": "dist_ts/index.js",
@ -41,5 +41,8 @@
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
]
}

View File

@ -49,9 +49,9 @@ interface ITestReqRes {
tap.test('should create a typedHandler', async () => {
// lets use the interface in a TypedHandler
testTypedHandler = new typedrequest.TypedHandler<ITestReqRes>('hi', async reqArg => {
testTypedHandler = new typedrequest.TypedHandler<ITestReqRes>('hi', async (reqArg) => {
return {
surname: 'wow'
surname: 'wow',
};
});
});
@ -60,7 +60,7 @@ tap.test('should spawn a server to test with', async () => {
testServer = new smartexpress.Server({
cors: true,
forceSsl: false,
port: 3000
port: 3000,
});
});
@ -69,7 +69,7 @@ tap.test('should define a testHandler', async () => {
testTypedRouter.addTypedHandler(testTypedHandler);
testServer.addRoute(
'/testroute',
new smartexpress.HandlerTypedRouter(testTypedRouter as any)
new smartexpress.HandlerTypedRouter(testTypedRouter as any) // the "any" is testspecific, since smartexpress ships with its own version of typedrequest.
);
});
@ -83,7 +83,7 @@ tap.test('should fire a request', async () => {
'hi'
);
const response = await typedRequest.fire({
name: 'really'
name: 'really',
});
console.log('this is the response:');
console.log(response);

View File

@ -19,9 +19,9 @@ interface ITestReqRes {
tap.test('should create a typedHandler', async () => {
// lets use the interface in a TypedHandler
testTypedHandler = new typedrequest.TypedHandler<ITestReqRes>('hi', async reqArg => {
testTypedHandler = new typedrequest.TypedHandler<ITestReqRes>('hi', async (reqArg) => {
return {
surname: 'wow'
surname: 'wow',
};
});
});
@ -30,7 +30,7 @@ tap.test('should spawn a server to test with', async () => {
testServer = new smartexpress.Server({
cors: true,
forceSsl: false,
port: 3000
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)
new smartexpress.HandlerTypedRouter(testTypedRouter as any) // the "any" is testspecific, since smartexpress ships with its own version of typedrequest.
);
});
@ -53,7 +53,7 @@ tap.test('should fire a request', async () => {
'hi'
);
const response = await typedRequest.fire({
name: 'really'
name: 'really',
});
console.log('this is the response:');
console.log(response);

View File

@ -1,7 +1,7 @@
import * as plugins from './typedrequest.plugins';
import { TypedResponseError } from './typedrequest.classes.typedresponseerror';
type THandlerFunction<T extends plugins.typedRequestInterfaces.ITypedRequest> = (
export type THandlerFunction<T extends plugins.typedRequestInterfaces.ITypedRequest> = (
requestArg: T['request']
) => Promise<T['response']>;
@ -28,7 +28,7 @@ export class TypedHandler<T extends plugins.typedRequestInterfaces.ITypedRequest
);
}
let typedResponseError: TypedResponseError;
const response = await this.handlerFunction(typedRequestArg.request).catch(e => {
const response = await this.handlerFunction(typedRequestArg.request).catch((e) => {
if (e instanceof TypedResponseError) {
typedResponseError = e;
} else {
@ -39,7 +39,7 @@ export class TypedHandler<T extends plugins.typedRequestInterfaces.ITypedRequest
if (typedResponseError) {
typedRequestArg.error = {
text: typedResponseError.errorText,
data: typedResponseError.errorData
data: typedResponseError.errorData,
};
}
@ -47,7 +47,7 @@ export class TypedHandler<T extends plugins.typedRequestInterfaces.ITypedRequest
typedRequestArg.response = response;
}
typedRequestArg?.correlation?.phase ? typedRequestArg.correlation.phase = 'response' : null;
typedRequestArg?.correlation?.phase ? (typedRequestArg.correlation.phase = 'response') : null;
return typedRequestArg;
}

View File

@ -4,9 +4,16 @@ import { TypedRouter } from './typedrequest.classes.typedrouter';
export type IPostMethod = (
typedRequestPostObject: plugins.typedRequestInterfaces.ITypedRequest
) => void | Promise<plugins.typedRequestInterfaces.ITypedRequest>;
) => Promise<plugins.typedRequestInterfaces.ITypedRequest>;
export type IPostMethodWithTypedRouter = (
typedRequestPostObject: plugins.typedRequestInterfaces.ITypedRequest
) => Promise<void> | Promise<plugins.typedRequestInterfaces.ITypedRequest>;
export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest> {
/**
* this typedrouter allows us to have easy async request response cycles
*/
public typedRouterRef: TypedRouter;
public webrequest = new plugins.webrequest.WebRequest();
@ -18,12 +25,18 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
/**
* in case we post with some other method, ec ipc communication
*/
public postMethod?: IPostMethod;
public postMethod?: IPostMethod | IPostMethodWithTypedRouter;
public method: string;
// STATIC
constructor(postEndPointArg: string | IPostMethod, methodArg: T['method']);
constructor(
postEndPointArg: string | IPostMethod,
postEndPointArg: string | IPostMethodWithTypedRouter,
methodArg: T['method'],
typedrouterRefArg: TypedRouter
);
constructor(
postEndPointArg: string | IPostMethodWithTypedRouter,
methodArg: T['method'],
typedrouterRefArg?: TypedRouter
) {
@ -56,9 +69,10 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
responseBody = response;
} else {
let responseInterest: plugins.lik.Interest<
string,
plugins.typedRequestInterfaces.ITypedRequest
string,
plugins.typedRequestInterfaces.ITypedRequest
>;
// having a typedrouter allows us to work with async request response cycles.
if (this.typedRouterRef) {
responseInterest = await this.typedRouterRef.fireEventInterestMap.addInterest(
payload.correlation.id,

View File

@ -109,7 +109,12 @@ export class TypedRouter {
this.fireEventInterestMap
.findInterest(typedRequestArg.correlation.id)
?.fullfillInterest(typedRequestArg);
return {
...typedRequestArg,
...{
method: 'nullPathFromResponse'
}
};
}
return typedRequestArg;
}
}