Skip to content

Commit

Permalink
fix: add lint and update packagejson build script
Browse files Browse the repository at this point in the history
  • Loading branch information
imabp committed Dec 24, 2022
1 parent 0d4b3ad commit 8a18e66
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 30 deletions.
1 change: 1 addition & 0 deletions .tsbuildinfo

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
"name": "asyncapi-problem",
"version": "0.0.1",
"description": "AsyncAPI Problem interface",
"type": "commonjs",
"main": "./lib/index.js",
"scripts": {
"build": "tsc",
"test": "cross-env CI=true jest --coverage",
"lint": "eslint --no-error-on-unmatched-pattern --max-warnings 0 --config \".eslintrc\" \".\"",
"lint:fix": "eslint --no-error-on-unmatched-pattern --max-warnings 0 --config \".eslintrc\" \".\" --fix",
"generate:readme:toc": "markdown-toc -i \"README.md\""
},

"bugs": {
"url": "https://github.com/imabp/asyncapi_problem/issues"
},
Expand Down
6 changes: 2 additions & 4 deletions src/types/index.ts → src/@types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Problem } from "../problem";

export type ProblemInterface = {
type: string;
title: string;
Expand All @@ -20,5 +18,5 @@ export type UpdateProblemParamType = {
};

export type ToJsonParamType = {
includeStack?:boolean
}
includeStack?: boolean;
};
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './problem';
export * from './types'
import { Problem } from "./problem";
export { Problem };
29 changes: 18 additions & 11 deletions src/problem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ProblemInterface,
ToJsonParamType,
UpdateProblemParamType,
} from "./types";
} from "./@types";

import { COPY_MODE } from "./constants";
import { objectToProblemMap } from "./util";
Expand Down Expand Up @@ -34,29 +34,36 @@ export class Problem extends Error implements ProblemInterface {
copy(mode: COPY_MODE = COPY_MODE.LEAVE_PROPS, props: string[] = []): Problem {
switch (mode) {
// returns a new problem object with preserved keys passed as props
case COPY_MODE.LEAVE_PROPS:{
let newProblemKeyValuePairs:Record<string,any> = {
case COPY_MODE.LEAVE_PROPS: {
let newProblemKeyValuePairs: Record<string, any> = {
type: this.problem.type,
title:this.problem.title,
}
props.forEach((key)=>{
newProblemKeyValuePairs={...newProblemKeyValuePairs, [key]:this.problem[key]}
})
const newProblem = new Problem(objectToProblemMap(newProblemKeyValuePairs));
title: this.problem.title,
};
props.forEach((key) => {
newProblemKeyValuePairs = {
...newProblemKeyValuePairs,
[key]: this.problem[key],
};
});
const newProblem = new Problem(
objectToProblemMap(newProblemKeyValuePairs)
);
return newProblem;
}
// skip the copy of keys
case COPY_MODE.SKIP_PROPS:
default: {
let newProblemKeyValuePairs:Record<string,any>={};
let newProblemKeyValuePairs: Record<string, any> = {};

// loop to copy only the required keys
for (let key in this.problem) {
// Skip only those keys, which are given in props and NOT a default key.
if (props.includes(key) && !DEFAULT_KEYS.includes(key)) continue;
newProblemKeyValuePairs[key] = this.problem[key];
}
const newProblem = new Problem(objectToProblemMap(newProblemKeyValuePairs))
const newProblem = new Problem(
objectToProblemMap(newProblemKeyValuePairs)
);
return newProblem;
}
}
Expand Down
20 changes: 11 additions & 9 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { ProblemInterface } from "types";
import { ProblemInterface } from "@types";

export const objectToProblemMap = (obj:Record<string,any>) =>{
const type: string = obj.type;
const title: string = obj.title;
const problemObject:ProblemInterface = {
type, title, ...obj
}
return problemObject
}
export const objectToProblemMap = (obj: Record<string, any>) => {
const type: string = obj.type;
const title: string = obj.title;
const problemObject: ProblemInterface = {
type,
title,
...obj,
};
return problemObject;
};
9 changes: 6 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"compilerOptions": {
"outDir": "./lib",
"baseUrl": "./src",
"outDir": "lib",
"baseUrl": "src",
"rootDir": "src",
"target": "es6",
"lib": [
"esnext"
],
"noEmit": false,
"composite": true,
"tsBuildInfoFile": ".tsbuildinfo",
"declaration": true,
"allowJs": true,
"skipLibCheck": true,
Expand All @@ -22,7 +25,7 @@
},

"include": [
"src"
"./src"
],
"exclude": [
"__tests__",
Expand Down

0 comments on commit 8a18e66

Please sign in to comment.