fix(core): update
This commit is contained in:
parent
25a9bb4ec8
commit
37b0968c18
@ -1,18 +1,16 @@
|
|||||||
# gitzone ci_default
|
# gitzone ci_default
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
variables:
|
|
||||||
GIT_STRATEGY: clone
|
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
@ -20,23 +18,23 @@ stages:
|
|||||||
mirror:
|
mirror:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
snyk:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
|
||||||
- npmci command npm cache clean --force
|
|
||||||
- npmci command npm install -g snyk
|
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command snyk test
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
@ -45,37 +43,40 @@ snyk:
|
|||||||
testStable:
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- priv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
testBuild:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command npm run build
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# metadata stage
|
# metadata stage
|
||||||
@ -85,33 +86,35 @@ codequality:
|
|||||||
allow_failure: true
|
allow_failure: true
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g tslint typescript
|
||||||
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- priv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-dbase:npmci
|
|
||||||
services:
|
|
||||||
- docker:18-dind
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
|
- npmci node install lts
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
@ -119,5 +122,5 @@ pages:
|
|||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"json.schemas": [
|
||||||
|
{
|
||||||
|
"fileMatch": ["/npmextra.json"],
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"npmci": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for npmci"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for gitzone",
|
||||||
|
"properties": {
|
||||||
|
"projectType": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["website", "element", "service", "npm"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "apiglobal",
|
"gitscope": "apiglobal",
|
||||||
|
904
package-lock.json
generated
904
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
33
package.json
33
package.json
@ -13,27 +13,28 @@
|
|||||||
"format": "(gitzone format)"
|
"format": "(gitzone format)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.1.17",
|
||||||
"@gitzone/tstest": "^1.0.15",
|
"@gitzone/tstest": "^1.0.28",
|
||||||
"@pushrocks/smartexpress": "^3.0.40",
|
"@pushrocks/smartexpress": "^3.0.57",
|
||||||
"@pushrocks/tapbundle": "^3.0.13",
|
"@pushrocks/tapbundle": "^3.2.0",
|
||||||
"@types/node": "^12.7.2",
|
"@types/node": "^13.7.1",
|
||||||
"tslint": "^5.19.0",
|
"tslint": "^6.0.0",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@apiglobal/typedrequest-interfaces": "^1.0.7",
|
"@apiglobal/typedrequest-interfaces": "^1.0.12",
|
||||||
"@pushrocks/lik": "^3.0.11",
|
"@pushrocks/lik": "^3.0.17",
|
||||||
"@pushrocks/smartjson": "^3.0.8",
|
"@pushrocks/smartdelay": "^2.0.6",
|
||||||
"@pushrocks/smartrequest": "^1.1.23"
|
"@pushrocks/smartjson": "^3.0.10",
|
||||||
|
"@pushrocks/smartrequest": "^1.1.47"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/*",
|
"ts/**/*",
|
||||||
"ts_web/*",
|
"ts_web/**/*",
|
||||||
"dist/*",
|
"dist/**/*",
|
||||||
"dist_web/*",
|
"dist_web/**/*",
|
||||||
"dist_ts_web/*",
|
"dist_ts_web/**/*",
|
||||||
"assets/*",
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
|
@ -8,7 +8,7 @@ make typed requests towards apis
|
|||||||
* [docs (typedoc)](https://apiglobal.gitlab.io/typedrequest/)
|
* [docs (typedoc)](https://apiglobal.gitlab.io/typedrequest/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
[![build status](https://gitlab.com/apiglobal/typedrequest/badges/master/build.svg)](https://gitlab.com/apiglobal/typedrequest/commits/master)
|
[![pipeline status](https://gitlab.com/apiglobal/typedrequest/badges/master/pipeline.svg)](https://gitlab.com/apiglobal/typedrequest/commits/master)
|
||||||
[![coverage report](https://gitlab.com/apiglobal/typedrequest/badges/master/coverage.svg)](https://gitlab.com/apiglobal/typedrequest/commits/master)
|
[![coverage report](https://gitlab.com/apiglobal/typedrequest/badges/master/coverage.svg)](https://gitlab.com/apiglobal/typedrequest/commits/master)
|
||||||
[![npm downloads per month](https://img.shields.io/npm/dm/@apiglobal/typedrequest.svg)](https://www.npmjs.com/package/@apiglobal/typedrequest)
|
[![npm downloads per month](https://img.shields.io/npm/dm/@apiglobal/typedrequest.svg)](https://www.npmjs.com/package/@apiglobal/typedrequest)
|
||||||
[![Known Vulnerabilities](https://snyk.io/test/npm/@apiglobal/typedrequest/badge.svg)](https://snyk.io/test/npm/@apiglobal/typedrequest)
|
[![Known Vulnerabilities](https://snyk.io/test/npm/@apiglobal/typedrequest/badge.svg)](https://snyk.io/test/npm/@apiglobal/typedrequest)
|
||||||
@ -18,6 +18,11 @@ make typed requests towards apis
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
18
test/test.ts
18
test/test.ts
@ -17,7 +17,7 @@ interface ITestReqRes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tap.test('should create a typedHandler', async () => {
|
tap.test('should create a typedHandler', async () => {
|
||||||
testTypedHandler = new typedrequest.TypedHandler<ITestReqRes>('hi', async (reqArg) => {
|
testTypedHandler = new typedrequest.TypedHandler<ITestReqRes>('hi', async reqArg => {
|
||||||
return {
|
return {
|
||||||
surname: 'wow'
|
surname: 'wow'
|
||||||
};
|
};
|
||||||
@ -33,10 +33,13 @@ tap.test('should spawn a server to test with', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should define a testHandler', async () => {
|
tap.test('should define a testHandler', async () => {
|
||||||
testServer.addRoute('/testroute', new smartexpress.Handler('POST', async (req, res) => {
|
testServer.addRoute(
|
||||||
console.log(req.body);
|
'/testroute',
|
||||||
res.json(await testTypedHandler.addResponse(req.body));
|
new smartexpress.Handler('POST', async (req, res) => {
|
||||||
}));
|
console.log(req.body);
|
||||||
|
res.json(await testTypedHandler.addResponse(req.body));
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should start the server', async () => {
|
tap.test('should start the server', async () => {
|
||||||
@ -44,7 +47,10 @@ tap.test('should start the server', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should fire a request', async () => {
|
tap.test('should fire a request', async () => {
|
||||||
const typedRequest = new typedrequest.TypedRequest<ITestReqRes>('http://localhost:3000/testroute', 'hi');
|
const typedRequest = new typedrequest.TypedRequest<ITestReqRes>(
|
||||||
|
'http://localhost:3000/testroute',
|
||||||
|
'hi'
|
||||||
|
);
|
||||||
const response = await typedRequest.fire({
|
const response = await typedRequest.fire({
|
||||||
name: 'really'
|
name: 'really'
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import * as plugins from './typedrequest.plugins';
|
import * as plugins from './typedrequest.plugins';
|
||||||
|
|
||||||
type THandlerFunction<T extends plugins.typedRequestInterfaces.ITypedRequest> = (requestArg: T['request']) => Promise<T['response']>;
|
type THandlerFunction<T extends plugins.typedRequestInterfaces.ITypedRequest> = (
|
||||||
|
requestArg: T['request']
|
||||||
|
) => Promise<T['response']>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* typed handler for dealing with typed requests
|
* typed handler for dealing with typed requests
|
||||||
@ -20,7 +22,9 @@ export class TypedHandler<T extends plugins.typedRequestInterfaces.ITypedRequest
|
|||||||
*/
|
*/
|
||||||
public async addResponse(typedRequestArg: T) {
|
public async addResponse(typedRequestArg: T) {
|
||||||
if (typedRequestArg.method !== this.method) {
|
if (typedRequestArg.method !== this.method) {
|
||||||
throw new Error('this handler has been given a wrong method to answer to. Please use a TypedRouter to filter requests');
|
throw new Error(
|
||||||
|
'this handler has been given a wrong method to answer to. Please use a TypedRouter to filter requests'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const response = await this.handlerFunction(typedRequestArg.request);
|
const response = await this.handlerFunction(typedRequestArg.request);
|
||||||
typedRequestArg.response = response;
|
typedRequestArg.response = response;
|
||||||
|
@ -25,7 +25,11 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
|
|||||||
if (responseBody.error) {
|
if (responseBody.error) {
|
||||||
console.log(responseBody.error.text);
|
console.log(responseBody.error.text);
|
||||||
console.log(responseBody.error.data);
|
console.log(responseBody.error.data);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return response.body.response;
|
if (responseBody.retry) {
|
||||||
|
console.log('server requested retry');
|
||||||
|
};
|
||||||
|
return responseBody.response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,9 @@ export class TypedRouter {
|
|||||||
* adds the handler to the routing map
|
* adds the handler to the routing map
|
||||||
* @param handlerArg
|
* @param handlerArg
|
||||||
*/
|
*/
|
||||||
public addTypedHandler<T extends plugins.typedRequestInterfaces.ITypedRequest>(handlerArg: TypedHandler<T>) {
|
public addTypedHandler<T extends plugins.typedRequestInterfaces.ITypedRequest>(
|
||||||
|
handlerArg: TypedHandler<T>
|
||||||
|
) {
|
||||||
this.handlerMap.add(handlerArg);
|
this.handlerMap.add(handlerArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,7 +29,7 @@ export class TypedRouter {
|
|||||||
|
|
||||||
if (!typedHandler) {
|
if (!typedHandler) {
|
||||||
const availableMethods: string[] = [];
|
const availableMethods: string[] = [];
|
||||||
await this.handlerMap.forEach(async (handler) => {
|
await this.handlerMap.forEach(async handler => {
|
||||||
availableMethods.push(handler.method);
|
availableMethods.push(handler.method);
|
||||||
});
|
});
|
||||||
console.log(`Cannot find method for ${typedHandler}`);
|
console.log(`Cannot find method for ${typedHandler}`);
|
||||||
|
@ -5,7 +5,8 @@ export { typedRequestInterfaces };
|
|||||||
|
|
||||||
// pushrocks scope
|
// pushrocks scope
|
||||||
import * as lik from '@pushrocks/lik';
|
import * as lik from '@pushrocks/lik';
|
||||||
|
import * as smartdelay from '@pushrocks/smartdelay';
|
||||||
import * as smartrequest from '@pushrocks/smartrequest';
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
import * as smartjson from '@pushrocks/smartjson';
|
import * as smartjson from '@pushrocks/smartjson';
|
||||||
|
|
||||||
export { lik, smartrequest, smartjson };
|
export { lik, smartdelay, smartrequest, smartjson };
|
||||||
|
Loading…
Reference in New Issue
Block a user