Skip to content

Commit

Permalink
feat: add package for abstracts
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Aug 22, 2019
1 parent 4e01777 commit 85d01b9
Show file tree
Hide file tree
Showing 13 changed files with 229 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/abstract/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib/**/*.d.ts
22 changes: 22 additions & 0 deletions packages/abstract/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# @qiwi/substrate-abstract
Abstract classes collection

### Install
```bash
yarn add @qiwi/substrate-abstract -D
npm add @qiwi/substrate-abstract -D
```

### Usage
```typescript
import { AbstractError } from '@qiwi/substrate-abstract'

class CustomError extends AbstractError {
foo: string
constructor(args) {
super(...args)

this.foo = 'bar'
}
}
```
30 changes: 30 additions & 0 deletions packages/abstract/jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"testEnvironment": "node",
"collectCoverage": true,
"rootDir": "../../",
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"collectCoverageFrom": [
"<rootDir>/packages/abstract/src/main/**/*.ts"
],
"testMatch": [
"<rootDir>/packages/abstract/src/test/**/*.ts"
],
"testPathIgnorePatterns": [
"<rootDir>/packages/abstract/src/test/ts/index.ts",
"<rootDir>/packages/abstract/src/test/ts/index.d.ts"
],
"transformIgnorePatterns": [
"/!node_modules\\/lodash-es/",
"<roodDir>/node_modules/(?!lodash-es)"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
}
60 changes: 60 additions & 0 deletions packages/abstract/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"name": "@qiwi/substrate-abstract",
"description": "Abstract classes",
"version": "1.16.0",
"main": "target/es5/index.js",
"types": "typings/index.d.ts",
"typesVersions": {
">=3.1": {
"*": [
"typings/index.d.ts",
"src/test/ts/*"
]
}
},
"license": "MIT",
"scripts": {
"clean": "rm -rf target",
"build": "yarn build:es5 && yarn build:es6 && yarn build:ts && yarn libdef",
"build:es5": "mkdir -p target/es5 && tsc -p tsconfig.json --target ES5 --outDir target/es5",
"build:es6": "mkdir -p target/es6 && tsc -p tsconfig.json --target ES6 --outDir target/es6",
"build:ts": "cp -r src/main/ts/ target/ts/",
"libdef": "yarn dtsgen && yarn libdeffix && yarn flowgen",
"libdeffix": "node -r esm ../../scripts/libdef-fix.js --flow=./typings/index.flow.js --dts=./typings/index.d.ts",
"dtsgen": "dts-generator --project ./ --out typings/index.d.ts --prefix @qiwi/substrate-abstract/target/es5 --name @qiwi/substrate-abstract --main @qiwi/substrate-abstract/target/es5/index --moduleResolution node",
"flowgen": "flowgen typings/index.d.ts --output-file typings/index.flow.js",
"test": "yarn test:libdefs && yarn jest",
"test:libdefs": "cp typings/index.d.ts src/test/ts/index.d.ts && yarn dtslint",
"jest": "jest --config=jest.config.json",
"dtslint": "dtslint src/test/ts --onlyTestTsNext"
},
"files": [
"README.md",
"CHANGELOG.md",
"typings",
"target"
],
"devDependencies": {
"@qiwi/uniconfig": "^3.0.1",
"@types/bluebird": "^3.5.27",
"@types/config": "^0.0.34",
"@types/jest": "^24.0.18",
"@types/lodash": "^4.14.137",
"@types/node": "^12.7.2",
"@types/parsimmon": "^1.10.0",
"@types/underscore": "^1.9.2",
"bluebird": "^3.5.5",
"conf": "^4.1.0",
"config": "^3.1.0",
"dts-generator": "^3.0.0",
"dtslint": "^0.9.1",
"flowgen": "^1.10.0",
"lodash": "^4.17.15",
"replace-in-file": "^4.1.3",
"ts-loader": "^6.0.4",
"ts-node": "^8.3.0",
"ts-to-flow": "^0.0.3",
"typescript": "3.5.3",
"underscore": "^1.9.1"
}
}
22 changes: 22 additions & 0 deletions packages/abstract/src/main/ts/AError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export type IError = {
message: string
code?: string | number
[key: string]: any
}

export type IErrorOpts = {
message: string
}

export class AbstractError extends Error implements IError {
message: string
code?: string | number
constructor(message: string | IErrorOpts) {
const opts = typeof message === 'string'
? { message }
: message

super(opts.message)
this.message = opts.message
}
}
1 change: 1 addition & 0 deletions packages/abstract/src/main/ts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './AError'
12 changes: 12 additions & 0 deletions packages/abstract/src/test/ts/AError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { AbstractError } from './index';

describe('AbstractError', () => {
describe('constructor', () => {
it('constructs by message', () => {
const message = 'foo';
const instance = new AbstractError(message);

expect(instance.message).toBe(message);
});
});
});
21 changes: 21 additions & 0 deletions packages/abstract/src/test/ts/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
declare module '@qiwi/substrate-abstract/target/es5/AError' {
type IError = {
message: string;
code?: string | number;
[key: string]: any;
};
type IErrorOpts = {
message: string;
};
class AbstractError extends Error implements IError {
message: string;
code?: string | number;
constructor(message: string | IErrorOpts);
}
}
declare module '@qiwi/substrate-abstract/target/es5/index' {
export * from '@qiwi/substrate-abstract/target/es5/AError';
}
declare module '@qiwi/substrate-abstract' {
export * from '@qiwi/substrate-abstract/target/es5/index';
}
1 change: 1 addition & 0 deletions packages/abstract/src/test/ts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@qiwi/substrate-abstract';
36 changes: 36 additions & 0 deletions packages/abstract/src/test/ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"alwaysStrict": true,
/* Additional Checks */
/* next line commented out because we need unused vars for type tests */
// "noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"lib": ["es6", "dom"],
"skipLibCheck": true,
"baseUrl": ".",
"paths": {
"@qiwi/substrate-abstract": [
"../../main/ts"
]
},
"typeRoots": [
".",
"../../../../../node_modules/@types"
]
},
"include": [
"./*"
],
"exclude": [
"node_modules"
]
}
9 changes: 9 additions & 0 deletions packages/abstract/src/test/ts/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "dtslint/dtslint.json",
"rules": {
"strict-type-predicates": true,
"interface-over-type-literal": false,
"interface-name": [true, "always-prefix"],
"max-line-length": [true, 1000]
}
}
11 changes: 11 additions & 0 deletions packages/abstract/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src/main/ts",
"outDir": "target/es5",
"baseUrl": "src/main/ts"
},
"include": [
"src/main/**/*"
]
}
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"@qiwi/substrate": ["./facade/src/main/ts"],
"@qiwi/substrate/*": ["./facade/src/main/ts/*"],
"@qiwi/substrate-types": ["./types/src/main/ts"],
"@qiwi/substrate-types/*": ["./types/src/main/ts/*"]
"@qiwi/substrate-types/*": ["./types/src/main/ts/*"],
"@qiwi/substrate-abstract": ["./abstract/src/main/ts"],
"@qiwi/substrate-abstract/*": ["./abstract/src/main/ts/*"]
}
}
}

0 comments on commit 85d01b9

Please sign in to comment.