Skip to content

Commit

Permalink
Merge PR #22 from 'nodech/ts-lint'
Browse files Browse the repository at this point in the history
  • Loading branch information
nodech committed Sep 1, 2023
2 parents 7ca6403 + 7a939f0 commit b35a7a3
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 61 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ jobs:
node-version: 20.x

- name: Install tools
run: npm install --location=global bslint
run: npm install --location=global bslint typescript

- name: Install dependencies
run: npm install

- name: Lint
run: npm run lint

- name: Lint types
run: npm run lint-types

test:
name: Test
runs-on: ${{ matrix.os }}
Expand Down
37 changes: 30 additions & 7 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Client extends EventEmitter {
*/

clone() {
// @ts-ignore
const copy = new this.constructor();
copy.ssl = this.ssl;
copy.strictSSL = this.strictSSL;
Expand Down Expand Up @@ -232,9 +233,11 @@ class Client extends EventEmitter {

if (json.error && res.statusCode >= 400) {
const {error} = json;
const err = new Error(error.message);
err.type = String(error.type);
err.code = error.code;
const err = new RequestError(
error.message,
String(error.type),
error.code
);
throw err;
}

Expand Down Expand Up @@ -515,17 +518,37 @@ class ClientOptions {
}

/**
* RPC Error
* RPC and Request Errors
*/

class RPCError extends Error {
constructor(msg, code) {
class RequestError extends Error {
/**
* @param {String} msg
* @param {String} type
* @param {Number} code
*/

constructor(msg, type, code) {
super();

this.type = 'RPCError';
this.type = type || 'RequestError';
this.message = String(msg);
this.code = code >> 0;

if (Error.captureStackTrace)
Error.captureStackTrace(this, RequestError);
}
}

class RPCError extends RequestError {
/**
* @param {String} msg
* @param {Number} code
*/

constructor(msg, code) {
super(msg, 'RPCError', code);

if (Error.captureStackTrace)
Error.captureStackTrace(this, RPCError);
}
Expand Down
72 changes: 25 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@
"main": "./lib/bcurl.js",
"scripts": {
"lint": "eslint lib/ test/",
"test": "bmocha --reporter spec test/*-test.js",
"test-ci": "nyc -a -n 'lib/**/*.js' --reporter=lcov --reporter=text npm run test"
"lint-types": "tsc -p .",
"test": "bmocha --reporter spec test/*-test.js"
},
"dependencies": {
"brq": "~0.1.8",
"bsert": "~0.0.10",
"bsock": "~0.1.9"
"brq": "~0.1.10",
"bsert": "~0.0.12",
"bsock": "~0.1.10"
},
"devDependencies": {
"bmocha": "^2.1.2"
"bmocha": "^2.1.8",
"bts-type-deps": "^0.0.3"
},
"engines": {
"node": ">=8.0.0"
Expand Down
31 changes: 31 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"include": [
"lib/**/*.js"
],
"compilerOptions": {
"rootDir": ".",
"target": "ES2020",
"lib": [
"ES2020"
],

"noEmit": true,

"allowJs": true,
"checkJs": true,
"maxNodeModuleJsDepth": 10,

"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,

"stripInternal": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": false,

"typeRoots": [
"node_modules/bts-type-deps/types"
]
}
}

0 comments on commit b35a7a3

Please sign in to comment.