Skip to content

Commit

Permalink
fix: up deps, fix vuls, linting
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Feb 12, 2022
1 parent 5333df9 commit c8c3f43
Show file tree
Hide file tree
Showing 23 changed files with 4,354 additions and 7,935 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module.exports = {
extends: 'eslint-config-qiwi'
extends: 'eslint-config-qiwi',
rules: {
'no-use-before-define': 'off',
'@typescript-eslint/ban-types': 'off'
}
}
2 changes: 1 addition & 1 deletion jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"globals": {
"ts-jest": {
"tsConfig": "tsconfig.test.json"
"tsconfig": "tsconfig.test.json"
}
}
}
78 changes: 30 additions & 48 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@
"jest": "jest -w 2 --config=jest.config.json",
"test": "yarn lint && yarn jest",
"clean": "rimraf target typings",
"build": "yarn clean && yarn build:es5 && yarn build:es6 && yarn build:ts && yarn libdef && yarn docs && yarn uglify && yarn build:bundle",
"build": "yarn clean && yarn build:es5 && yarn build:es6 && yarn build:ts && yarn build:libdef && yarn docs && yarn uglify && yarn build:bundle",
"build:es5": "mkdir -p target/es5 && tsc -p tsconfig.es5.json",
"build:es6": "mkdir -p target/es6 && tsc -p tsconfig.es6.json",
"build:ts": "cp -r src/main/ts/ target/ts/",
"build:bundle": "microbundle build src/main/ts/index.ts -o target/bundle",
"dtsgen": "dts-generator --project ./ --out typings/index.d.ts --prefix @qiwi/health-indicator/target/es5 --name @qiwi/health-indicator --main @qiwi/health-indicator/target/es5/index --moduleResolution node",
"flowgen": "flowgen typings/index.d.ts --output-file flow-typed/index.flow.js",
"libdef": "yarn dtsgen && yarn libdeffix && yarn flowgen",
"libdeffix": "node -r esm ./scripts/js/libdef-fix.js --dts=./typings/index.d.ts --prefix=@qiwi/health-indicator/target/es5",
"test:report": "yarn test && yarn push:report",
"push:report": "yarn coveralls:push",
"coveralls:push": "cat ./coverage/lcov.info | coveralls",
"docs": "typedoc --readme README.md --tsconfig tsconfig.json src/main --ignoreCompilerErrors || exit 0",
"build:bundle": "microbundle build -o target/bundle",
"build:libdef": "libdefkit --tsconfig=tsconfig.es5.json --tsconfig=tsconfig.es6.json --entry=@qiwi/health-indicator/target/es5 --no-flow-out",
"test:report": "yarn test && yarn test:push",
"test:push": "cat ./coverage/lcov.info | npm_config_yes=true npx coveralls@3",
"docs": "typedoc --readme README.md --tsconfig tsconfig.json || exit 0",
"uglify": "for f in $(find target -name '*.js'); do short=${f%.js}; terser -c -m -o $short.js -- $f; done",
"postupdate": "yarn && yarn build && yarn test",
"lint": "eslint src/**/*.ts",
Expand All @@ -53,47 +49,33 @@
"dependencies": {
"http-status-codes": "^2.2.0",
"lodash": "^4.17.21",
"tslib": "^1.10.0"
"tslib": "^2.3.1"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.4",
"@babel/plugin-external-helpers": "^7.8.3",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.8.3",
"@babel/cli": "^7.17.0",
"@babel/core": "^7.17.2",
"@babel/plugin-external-helpers": "^7.16.7",
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/plugin-transform-runtime": "^7.17.0",
"@babel/polyfill": "^7.8.3",
"@babel/preset-env": "^7.8.4",
"@babel/register": "^7.8.3",
"@babel/runtime": "^7.8.4",
"@qiwi/license": "^1.1.1",
"@qiwi/semantic-release-gh-pages-plugin": "^1.15.8",
"@semantic-release/changelog": "^5.0.0",
"@semantic-release/git": "^9.0.0",
"@semantic-release/github": "^7.0.2",
"@semantic-release/npm": "^7.0.2",
"@types/jest": "^25.1.1",
"@types/jest-json-schema": "^2.1.1",
"@typescript-eslint/parser": "^2.19.0",
"coveralls": "^3.0.9",
"dts-generator": "^3.0.0",
"eslint": "^6.8.0",
"eslint-config-qiwi": "^1.3.1",
"eslint-plugin-typescript": "^0.14.0",
"esm": "^3.2.25",
"flowgen": "1.10.0",
"jest": "^25.1.0",
"lodash": "^4.17.15",
"microbundle": "^0.12.0-next.6",
"replace-in-file": "^5.0.2",
"reqresnext": "^1.6.3",
"rimraf": "^3.0.1",
"semantic-release": "^17.0.2",
"terser": "^4.6.3",
"ts-jest": "^25.2.0",
"typedoc": "0.16.9",
"typedoc-plugin-external-module-name": "^3.0.0",
"typescript": "^3.7.5",
"typescript-eslint-parser": "^22.0.0"
"@babel/preset-env": "^7.16.11",
"@babel/register": "^7.17.0",
"@babel/runtime": "^7.17.2",
"@qiwi/license": "^1.3.3",
"@qiwi/libdefkit": "^4.0.4",
"@types/jest": "^27.4.0",
"@types/jest-json-schema": "^6.1.0",
"@typescript-eslint/parser": "^5.11.0",
"eslint": "^8.9.0",
"eslint-config-qiwi": "^1.16.0",
"jest": "^27.5.1",
"microbundle": "^0.14.2",
"reqresnext": "^1.6.6",
"rimraf": "^3.0.2",
"terser": "^5.10.0",
"ts-jest": "^27.1.3",
"typedoc": "0.22.11",
"typescript": "^4.5.5"
},
"release": {
"branch": "master",
Expand Down
2 changes: 1 addition & 1 deletion src/main/ts/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export {
isFunction,
mapValues,
toArray,
pickBy
pickBy,
} from 'lodash'

export function isDefined (value?: any): boolean {
Expand Down
20 changes: 12 additions & 8 deletions src/main/ts/endpoint/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import { IEndpoint, IResponse, IRequest } from './interface'
import { IIndicator } from '../indicator/interface'
import { IFunction } from '@qiwi/substrate'

import { INTERNAL_SERVER_ERROR } from '../endpoint/statuses'
import { IIndicator } from '../indicator/interface'
import { IEndpoint, IRequest, IResponse } from './interface'

export class Endpoint implements IEndpoint {
type ThisConstructor<T> = {
// @see https://github.com/Microsoft/TypeScript/issues/3841#issuecomment-337560146
['constructor']: T
}

export class Endpoint implements IEndpoint, ThisConstructor<typeof Endpoint> {
indicator: IIndicator
/**
* @see https://github.com/Microsoft/TypeScript/issues/3841#issuecomment-337560146
*/
// @see https://github.com/Microsoft/TypeScript/issues/3841#issuecomment-337560146
['constructor']: typeof Endpoint

constructor (indicator: IIndicator) {
if (!indicator) {
throw new Error('Indicator param is required')
}

this.indicator = indicator

return this
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
middleware (_req: IRequest, res: IResponse, _next?: Function) {
middleware (_req: IRequest, res: IResponse, _next?: IFunction | Function) {
try {
const health = this.indicator.health()
const status = health.status
Expand Down
6 changes: 4 additions & 2 deletions src/main/ts/endpoint/interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { IFunction } from '@qiwi/substrate'

type IAny = any

export type IHeaders = {
Expand All @@ -9,9 +11,9 @@ export type IRequest = IAny
export interface IResponse {
writeHead (code: number, headers: IHeaders): IAny,

end (data?: string, encoding?: string, cb?: Function): IResponse
end (data?: string, encoding?: string, cb?: IFunction | Function): IResponse
}

export interface IEndpoint {
middleware (req: IRequest, res: IResponse, next?: Function): IAny;
middleware (req: IRequest, res: IResponse, next?: IFunction | Function): IAny;
}
2 changes: 1 addition & 1 deletion src/main/ts/health/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { extend } from '../base'
import { IHealth, IHealthOpts, IHealthDeps } from './interface'
import { IHealth, IHealthDeps, IHealthOpts } from './interface'

export class Health implements IHealth {
status: string
Expand Down
8 changes: 4 additions & 4 deletions src/main/ts/health/interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export type IHealthDeps = {
[key: string]: IHealth;
} | undefined

export interface IHealth {
status: string,
critical: boolean,
Expand All @@ -13,10 +17,6 @@ export type IHealthOpts = {
extra?: IHealthExtra,
}

export type IHealthDeps = {
[key: string]: IHealth;
} | undefined

export type IHealthExtra = {
[key: string]: any
} | undefined
22 changes: 11 additions & 11 deletions src/main/ts/indicator/abstract.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { Health } from '../health'
import { find, isDefined, isEmpty, mapValues, maxBy, minBy, pickBy, toArray } from '../base'
import { OK } from '../endpoint/statuses'
import { mapValues, find, minBy, maxBy, toArray, isEmpty, isDefined, pickBy } from '../base'
import { Health } from '../health'
import { IHealth, IHealthDeps, IHealthExtra } from '../health/interface'
import {
IHttpMap,
IIndicator,
IIndicatorOpts,
IIndicatorDeps,
IHttpMap,
IStatusMap, IIndicatorStatics
IIndicatorOpts,
IIndicatorStatics,
IStatusMap,
} from './interface'
import { IHealth, IHealthDeps, IHealthExtra } from '../health/interface'

export const UNKNOWN = 'UNKNOWN'
export const DEFAULT_CRITICAL = false
export const DEFAULT_STATUS = UNKNOWN
export const DEFAULT_HTTP_CODE = OK
export const SEVERITY_ORDER = [UNKNOWN]
export const HTTP_MAP = {
[UNKNOWN]: DEFAULT_HTTP_CODE
[UNKNOWN]: DEFAULT_HTTP_CODE,
}

/**
Expand All @@ -34,7 +35,6 @@ export class AbstractIndicator implements IIndicator {
['constructor']: typeof AbstractIndicator & IIndicatorStatics

constructor ({ critical, status, deps, extra }: IIndicatorOpts = {}) {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
if (this.constructor === AbstractIndicator) {
throw new Error('Abstract cannot be instantiated')
Expand Down Expand Up @@ -66,7 +66,7 @@ export class AbstractIndicator implements IIndicator {
status,
critical,
deps,
extra
extra,
})
}

Expand All @@ -82,7 +82,7 @@ export class AbstractIndicator implements IIndicator {
return this.constructor.resolveStatusFromDeps(
this.getDeps(),
this.constructor.getSeverityOrder(),
this.constructor.getDefaultStatus()
this.constructor.getDefaultStatus(),
)
}

Expand All @@ -96,7 +96,7 @@ export class AbstractIndicator implements IIndicator {

return this.constructor.resolveCriticalFromDeps(
this.getDeps(),
this.constructor.getDefaultCritical()
this.constructor.getDefaultCritical(),
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/ts/indicator/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbstractIndicator } from './abstract'
import { StandardIndicator } from './standard'
import { SemaphoreIndicator } from './semaphore'
import { StandardIndicator } from './standard'

export { AbstractIndicator, StandardIndicator, SemaphoreIndicator }
4 changes: 3 additions & 1 deletion src/main/ts/indicator/interface.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { IConstructor } from '@qiwi/substrate'

import { IHealth, IHealthExtra } from '../health/interface'

export interface IPrimitiveIndicator {
/**
* @see https://github.com/Microsoft/TypeScript/issues/3841#issuecomment-337560146
*/
['constructor']: Function & IIndicatorStatics,
['constructor']: IConstructor & IIndicatorStatics,
status: string | undefined,

health (): IHealth
Expand Down
4 changes: 2 additions & 2 deletions src/main/ts/indicator/semaphore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbstractIndicator } from './abstract'
import { OK, SERVICE_UNAVAILABLE } from '../endpoint/statuses'
import { AbstractIndicator } from './abstract'
import { IHttpMap, IIndicator, IStatusMap } from './interface'

export const GREEN = 'GREEN'
Expand All @@ -12,7 +12,7 @@ export const DEFAULT_STATUS = BROKEN
export const HTTP_MAP = {
[GREEN]: OK,
[RED]: SERVICE_UNAVAILABLE,
[BROKEN]: SERVICE_UNAVAILABLE
[BROKEN]: SERVICE_UNAVAILABLE,
}

export class SemaphoreIndicator extends AbstractIndicator implements IIndicator {
Expand Down
6 changes: 3 additions & 3 deletions src/main/ts/indicator/standard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbstractIndicator } from './abstract'
import { OK, SERVICE_UNAVAILABLE } from '../endpoint/statuses'
import { IStatusMap, IHttpMap, IIndicator } from './interface'
import { AbstractIndicator } from './abstract'
import { IHttpMap, IIndicator, IStatusMap } from './interface'

export const UP = 'UP'
export const DOWN = 'DOWN'
Expand All @@ -12,7 +12,7 @@ export const SEVERITY_ORDER = [DOWN, OUT_OF_SERVICE, UNKNOWN, UP]
export const HTTP_MAP = {
[UP]: OK,
[DOWN]: SERVICE_UNAVAILABLE,
[OUT_OF_SERVICE]: SERVICE_UNAVAILABLE
[OUT_OF_SERVICE]: SERVICE_UNAVAILABLE,
}

export class StandardIndicator extends AbstractIndicator implements IIndicator {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ts/endpoint/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import reqresnext from 'reqresnext'

import { Endpoint } from '../../../main/ts/endpoint'
import { SemaphoreIndicator } from '../../../main/ts/indicator'

describe('Endpoint', () => {
const indicator = new SemaphoreIndicator()
describe('constructor', () => {
it('requires indicator instance as param', () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
expect(() => new Endpoint()).toThrow()
})
Expand Down
2 changes: 1 addition & 1 deletion src/test/ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AbstractIndicator, SemaphoreIndicator, StandardIndicator, Endpoint } from '../../main/ts'
import { AbstractIndicator, Endpoint, SemaphoreIndicator, StandardIndicator } from '../../main/ts'

describe('index', () => {
it('properly exposes its inners', () => {
Expand Down
Loading

0 comments on commit c8c3f43

Please sign in to comment.