Skip to content

Commit 6968105

Browse files
feat: prepare package for first release (#13)
1 parent 3d83d9f commit 6968105

File tree

7 files changed

+124
-24
lines changed

7 files changed

+124
-24
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ node_modules
33
.DS_Store
44
coverage
55
lib
6+
esm
7+
cjs

CODEOWNERS

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This file provides an overview of code owners in this repository.
2+
3+
# Each line is a file pattern followed by one or more owners.
4+
# The last matching pattern has the most precedence.
5+
# For more details, read the following article on GitHub: https://help.github.com/articles/about-codeowners/.
6+
7+
# The default owners are automatically added as reviewers when you open a pull request unless different owners are specified in the file.
8+
* @imabp @magicmatatjahu @asyncapi-bot-eve

README.md

+62-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,63 @@
1-
# AsyncAPI Problem interface
1+
# AsyncAPI Problem
22

3-
comes from https://github.com/asyncapi/community/discussions/300
3+
Library that implements the Problem interface. Reference https://www.rfc-editor.org/rfc/rfc7807.
4+
5+
<!-- toc is generated with GitHub Actions do not remove toc markers -->
6+
7+
<!-- toc -->
8+
9+
- [Installation](#installation)
10+
- [Examples](#examples)
11+
* [Simple example](#simple-example)
12+
* [Mixin example](#mixin-example)
13+
- [Develop](#develop)
14+
- [Contributing](#contributing)
15+
16+
<!-- tocstop -->
17+
18+
## Installation
19+
20+
```bash
21+
npm install @asyncapi/problem
22+
// OR
23+
yarn add @asyncapi/problem
24+
```
25+
26+
## Examples
27+
28+
### Simple example
29+
30+
```ts
31+
import { Problem } from '@asyncapi/problem';
32+
33+
const problem = new Problem({ type: 'https://example.com/problem', title: 'Example problem' });
34+
console.log(problem.get('type'));
35+
36+
// Output:
37+
// https://example.com/problem
38+
```
39+
40+
### Mixin example
41+
42+
```ts
43+
import { ProblemMixin } from '@asyncapi/problem';
44+
45+
class MyProblem extends ProblemMixin({ typePrefix: 'https://example.com' }) {}
46+
47+
const problem = new MyProblem({ type: 'problem', title: 'Example problem' });
48+
console.log(problem.get('type'));
49+
50+
// Output:
51+
// https://example.com/problem
52+
```
53+
54+
## Develop
55+
56+
1. Write code and tests in the `__tests__` folder.
57+
2. Make sure all tests pass by `npm test` command.
58+
3. Make sure code can be transformed to JS by `npm run build` command.
59+
4. Make sure code is well formatted and secure by `npm run lint:fix` command.
60+
61+
## Contributing
62+
63+
Read [CONTRIBUTING](./CONTRIBUTING.md) guide.

package.json

+23-9
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22
"name": "@asyncapi/problem",
33
"version": "0.0.1",
44
"description": "AsyncAPI Problem interface",
5-
"main": "lib/index.js",
6-
"types": "lib/index.d.ts",
7-
"scripts": {
8-
"build": "tsc",
9-
"test": "cross-env CI=true jest --coverage",
10-
"lint": "eslint --no-error-on-unmatched-pattern --max-warnings 0 --config \".eslintrc\" \".\"",
11-
"lint:fix": "eslint --no-error-on-unmatched-pattern --max-warnings 0 --config \".eslintrc\" \".\" --fix",
12-
"generate:readme:toc": "markdown-toc -i \"README.md\""
13-
},
145
"bugs": {
156
"url": "https://github.com/asyncapi/problem/issues"
167
},
@@ -23,6 +14,29 @@
2314
},
2415
"license": "Apache-2.0",
2516
"homepage": "https://github.com/asyncapi/problem",
17+
"sideEffects": false,
18+
"main": "cjs/index.js",
19+
"module": "esm/index.js",
20+
"types": "esm/index.d.ts",
21+
"files": [
22+
"/esm",
23+
"/cjs",
24+
"/browser",
25+
"LICENSE",
26+
"README.md"
27+
],
28+
"scripts": {
29+
"build": "npm run build:esm && npm run build:cjs",
30+
"build:dev": "npm run build:esm",
31+
"build:esm": "tsc",
32+
"build:cjs": "tsc --project ./tsconfig.cjs.json",
33+
"test": "cross-env CI=true jest --coverage",
34+
"lint": "eslint --no-error-on-unmatched-pattern --max-warnings 0 --config \".eslintrc\" \".\"",
35+
"lint:fix": "eslint --no-error-on-unmatched-pattern --max-warnings 0 --config \".eslintrc\" \".\" --fix",
36+
"generate:readme:toc": "markdown-toc -i \"README.md\"",
37+
"generate:assets": "npm run build && npm run generate:readme:toc",
38+
"prepublishOnly": "npm run generate:assets"
39+
},
2640
"devDependencies": {
2741
"@jest/types": "^29.3.1",
2842
"@types/jest": "^29.2.5",

src/problem.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class Problem<T extends Record<string, unknown> = {}> extends Error {
5050
if (typeof keyOrObject !== 'string') {
5151
return Object.assign(this.problem, keyOrObject);
5252
}
53-
return this.problem[keyOrObject] = value;
53+
return this.problem[keyOrObject] = value as (ProblemInterface & T)[K];
5454
}
5555

5656
copy(options?: CopyProblemOptions<Array<keyof Omit<ProblemInterface & T, 'type' | 'title'>>>): Problem {

tsconfig.cjs.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"module": "commonjs",
5+
"outDir": "./cjs"
6+
}
7+
}

tsconfig.json

+21-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
{
22
"compilerOptions": {
3-
"outDir": "./lib",
4-
"rootDir": "./src",
5-
"module": "commonjs",
3+
"outDir": "./esm",
4+
"baseUrl": "./src",
5+
"target": "es6",
6+
"module": "esnext",
7+
"lib": [
8+
"esnext",
9+
"DOM"
10+
],
611
"declaration": true,
7-
"noImplicitAny": false,
8-
"noUnusedLocals": false,
9-
"removeComments": true,
10-
"noLib": false,
11-
"target": "ES2015",
12-
"sourceMap": true,
1312
"allowJs": true,
14-
"lib": ["ESNext"]
13+
"skipLibCheck": true,
14+
"esModuleInterop": true,
15+
"allowSyntheticDefaultImports": true,
16+
"strict": true,
17+
"forceConsistentCasingInFileNames": true,
18+
"noFallthroughCasesInSwitch": true,
19+
"moduleResolution": "node",
20+
"resolveJsonModule": true,
21+
"isolatedModules": true,
22+
"sourceMap": true,
1523
},
16-
"include": ["src/*.ts", "src/**/*.ts"],
17-
"exclude": ["node_modules"]
24+
"include": [
25+
"src"
26+
]
1827
}

0 commit comments

Comments
 (0)