standardized eslint and prettier configs

This commit is contained in:
Eric Passmore
2023-02-08 09:49:06 -08:00
parent 4a56bc8622
commit 6fba4d7f32
6 changed files with 1013 additions and 881 deletions
+33
View File
@@ -0,0 +1,33 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "es-x"],
"ignorePatterns": ["lib/*", "node_modules/**"],
"extends": [
"eslint:recommended",
"plugin:prettier/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:es-x/no-new-in-es2022"
],
"rules": {
"prettier/prettier": "warn",
"no-console": "warn",
"sort-imports": [
"warn",
{
"ignoreCase": true,
"ignoreDeclarationSort": true
}
],
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-empty-function": "warn",
"@typescript-eslint/no-this-alias": "off",
"no-inner-declarations": "off",
"es-x/no-class-fields": "OFF",
"es-x/no-export-ns-from": "OFF"
}
}
+8
View File
@@ -0,0 +1,8 @@
arrowParens: "always"
bracketSpacing: false
endOfLine: "lf"
printWidth: 100
semi: false
singleQuote: true
tabWidth: 4
trailingComma: "es5"
+492 -448
View File
File diff suppressed because it is too large Load Diff
+11 -5
View File
@@ -31,37 +31,43 @@
"@types/text-encoding": "^0.0.36",
"bn.js": "5.2.0",
"elliptic": "6.5.4",
"eslist": "^1.0.0-beta.1",
"hash.js": "1.1.7",
"node-fetch": "2.6.7",
"pako": "2.0.3",
"semver": "^7.3.7"
},
"devDependencies": {
"@blockone/eslint-config-blockone": "^4.0.1",
"@cypress/skip-test": "^2.6.1",
"@types/elliptic": "^6.4.13",
"@types/jest": "^26.0.24",
"@types/node": "^14.18.21",
"@types/node": "^14.18.36",
"@types/node-fetch": "^2.5.11",
"@types/pako": "^1.0.2",
"@typescript-eslint/eslint-plugin": "^5.51.0",
"@typescript-eslint/parser": "^5.51.0",
"buffer": "^6.0.3",
"clean-webpack-plugin": "^3.0.0",
"crypto-browserify": "^3.12.0",
"cypress": "^7.7.0",
"eosjs-ecc": "^4.0.7",
"eslint": "^7.30.0",
"eslint": "^8.33.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-es-x": "^6.0.0",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^26.6.3",
"jest-extended": "^0.11.5",
"jest-fetch-mock": "^3.0.3",
"none": "^1.0.0",
"prettier": "2.8.4",
"rimraf": "^3.0.2",
"text-encoding": "^0.7.0",
"ts-jest": "^26.5.6",
"ts-loader": "^9.2.3",
"typedoc": "^0.23.5",
"typedoc": "^0.23.24",
"typedoc-markdown-theme": "^0.0.4",
"typedoc-plugin-markdown": "^3.13.2",
"typescript": "^4.3.5",
"typescript": "^4.9.5",
"webpack": "^5.44.0",
"webpack-cli": "^4.7.2"
},
+138 -95
View File
@@ -3,23 +3,37 @@
*/
// copyright defined in eosjs/LICENSE.txt
import { AbiProvider, AuthorityProvider, AuthorityProviderArgs, BinaryAbi } from './eosjs-api-interfaces';
import { base64ToBinary, convertLegacyPublicKeys } from './eosjs-numeric';
import { GetAbiResult, GetBlockResult, GetCodeResult, GetInfoResult, GetRawCodeAndAbiResult, PushTransactionArgs, GetBlockHeaderStateResult, SendTransaction2Args } from "./eosjs-rpc-interfaces" // tslint:disable-line
import { RpcError } from './eosjs-rpcerror';
import {
AbiProvider,
AuthorityProvider,
AuthorityProviderArgs,
BinaryAbi,
} from './eosjs-api-interfaces'
import {base64ToBinary, convertLegacyPublicKeys} from './eosjs-numeric'
import {
GetAbiResult,
GetBlockHeaderStateResult,
GetBlockResult,
GetCodeResult,
GetInfoResult,
GetRawCodeAndAbiResult,
PushTransactionArgs,
SendTransaction2Args,
} from './eosjs-rpc-interfaces' // tslint:disable-line
import {RpcError} from './eosjs-rpcerror'
function arrayToHex(data: Uint8Array) {
let result = '';
let result = ''
for (const x of data) {
result += ('00' + x.toString(16)).slice(-2);
result += ('00' + x.toString(16)).slice(-2)
}
return result;
return result
}
/** Make RPC calls */
export class JsonRpc implements AuthorityProvider, AbiProvider {
public endpoint: string;
public fetchBuiltin: (input?: Request | string, init?: RequestInit) => Promise<Response>;
public endpoint: string
public fetchBuiltin: (input?: Request | string, init?: RequestInit) => Promise<Response>
/**
* @param endpoint
@@ -28,107 +42,122 @@ export class JsonRpc implements AuthorityProvider, AbiProvider {
* * browsers: leave `null` or `undefined`
* * node: provide an implementation
*/
constructor(endpoint: string, args:
{ fetch?: (input?: string | Request, init?: RequestInit) => Promise<Response> } = {},
constructor(
endpoint: string,
args: {fetch?: (input?: string | Request, init?: RequestInit) => Promise<Response>} = {}
) {
this.endpoint = endpoint.replace(/\/$/, '');
this.endpoint = endpoint.replace(/\/$/, '')
if (args.fetch) {
this.fetchBuiltin = args.fetch;
this.fetchBuiltin = args.fetch
} else {
this.fetchBuiltin = (global as any).fetch;
this.fetchBuiltin = (global as any).fetch
}
}
/** Post `body` to `endpoint + path`. Throws detailed error information in `RpcError` when available. */
public async fetch(path: string, body: any) {
let response;
let json;
let response
let json
try {
const f = this.fetchBuiltin;
const f = this.fetchBuiltin
response = await f(this.endpoint + path, {
body: JSON.stringify(body),
method: 'POST',
});
json = await response.json();
})
json = await response.json()
if (json.processed && json.processed.except) {
throw new RpcError(json);
throw new RpcError(json)
}
} catch (e) {
e.isFetchError = true;
throw e;
e.isFetchError = true
throw e
}
if (!response.ok) {
throw new RpcError(json);
throw new RpcError(json)
}
return json;
return json
}
/** Raw call to `/v1/chain/get_abi` */
public async get_abi(accountName: string): Promise<GetAbiResult> {
return await this.fetch('/v1/chain/get_abi', { account_name: accountName });
return await this.fetch('/v1/chain/get_abi', {account_name: accountName})
}
/** Raw call to `/v1/chain/get_account` */
public async get_account(accountName: string): Promise<any> {
return await this.fetch('/v1/chain/get_account', { account_name: accountName });
return await this.fetch('/v1/chain/get_account', {account_name: accountName})
}
/** Raw call to `/v1/chain/get_block_header_state` */
public async get_block_header_state(blockNumOrId: number | string): Promise<GetBlockHeaderStateResult> {
return await this.fetch('/v1/chain/get_block_header_state', { block_num_or_id: blockNumOrId });
public async get_block_header_state(
blockNumOrId: number | string
): Promise<GetBlockHeaderStateResult> {
return await this.fetch('/v1/chain/get_block_header_state', {block_num_or_id: blockNumOrId})
}
/** Raw call to `/v1/chain/get_block` */
public async get_block(blockNumOrId: number | string): Promise<GetBlockResult> {
return await this.fetch('/v1/chain/get_block', { block_num_or_id: blockNumOrId });
return await this.fetch('/v1/chain/get_block', {block_num_or_id: blockNumOrId})
}
/** Raw call to `/v1/chain/get_code` */
public async get_code(accountName: string): Promise<GetCodeResult> {
return await this.fetch('/v1/chain/get_code', { account_name: accountName });
return await this.fetch('/v1/chain/get_code', {account_name: accountName})
}
/** Raw call to `/v1/chain/get_currency_balance` */
public async get_currency_balance(code: string, account: string, symbol: string = null): Promise<any> {
return await this.fetch('/v1/chain/get_currency_balance', { code, account, symbol });
public async get_currency_balance(
code: string,
account: string,
symbol: string = null
): Promise<any> {
return await this.fetch('/v1/chain/get_currency_balance', {code, account, symbol})
}
/** Raw call to `/v1/chain/get_currency_stats` */
public async get_currency_stats(code: string, symbol: string): Promise<any> {
return await this.fetch('/v1/chain/get_currency_stats', { code, symbol });
return await this.fetch('/v1/chain/get_currency_stats', {code, symbol})
}
/** Raw call to `/v1/chain/get_info` */
public async get_info(): Promise<GetInfoResult> {
return await this.fetch('/v1/chain/get_info', {});
return await this.fetch('/v1/chain/get_info', {})
}
/** Raw call to `/v1/chain/get_producer_schedule` */
public async get_producer_schedule(): Promise<any> {
return await this.fetch('/v1/chain/get_producer_schedule', {});
return await this.fetch('/v1/chain/get_producer_schedule', {})
}
/** Raw call to `/v1/chain/get_producers` */
public async get_producers(json = true, lowerBound = '', limit = 50): Promise<any> {
return await this.fetch('/v1/chain/get_producers', { json, lower_bound: lowerBound, limit });
return await this.fetch('/v1/chain/get_producers', {json, lower_bound: lowerBound, limit})
}
/** Raw call to `/v1/chain/get_raw_code_and_abi` */
public async get_raw_code_and_abi(accountName: string): Promise<GetRawCodeAndAbiResult> {
return await this.fetch('/v1/chain/get_raw_code_and_abi', { account_name: accountName });
return await this.fetch('/v1/chain/get_raw_code_and_abi', {account_name: accountName})
}
/** calls `/v1/chain/get_raw_code_and_abi` and pulls out unneeded raw wasm code */
// TODO: use `/v1/chain/get_raw_abi` directly when it becomes available
public async getRawAbi(accountName: string): Promise<BinaryAbi> {
const rawCodeAndAbi = await this.get_raw_code_and_abi(accountName);
const abi = base64ToBinary(rawCodeAndAbi.abi);
return { accountName: rawCodeAndAbi.account_name, abi };
const rawCodeAndAbi = await this.get_raw_code_and_abi(accountName)
const abi = base64ToBinary(rawCodeAndAbi.abi)
return {accountName: rawCodeAndAbi.account_name, abi}
}
/** Raw call to `/v1/chain/get_scheduled_transactions` */
public async get_scheduled_transactions(json = true, lowerBound = '', limit = 50): Promise<any> {
return await this.fetch('/v1/chain/get_scheduled_transactions', { json, lower_bound: lowerBound, limit });
public async get_scheduled_transactions(
json = true,
lowerBound = '',
limit = 50
): Promise<any> {
return await this.fetch('/v1/chain/get_scheduled_transactions', {
json,
lower_bound: lowerBound,
limit,
})
}
/** Raw call to `/v1/chain/get_table_rows` */
@@ -145,22 +174,21 @@ export class JsonRpc implements AuthorityProvider, AbiProvider {
limit = 10,
reverse = false,
show_payer = false,
}: any): Promise<any> {
return await this.fetch(
'/v1/chain/get_table_rows', {
json,
code,
scope,
table,
table_key,
lower_bound,
upper_bound,
index_position,
key_type,
limit,
reverse,
show_payer,
});
}: any): Promise<any> {
return await this.fetch('/v1/chain/get_table_rows', {
json,
code,
scope,
table,
table_key,
lower_bound,
upper_bound,
index_position,
key_type,
limit,
reverse,
show_payer,
})
}
/** Raw call to `/v1/chain/get_table_by_scope` */
@@ -171,57 +199,62 @@ export class JsonRpc implements AuthorityProvider, AbiProvider {
upper_bound = '',
limit = 10,
}: any): Promise<any> {
return await this.fetch(
'/v1/chain/get_table_by_scope', {
code,
table,
lower_bound,
upper_bound,
limit,
});
return await this.fetch('/v1/chain/get_table_by_scope', {
code,
table,
lower_bound,
upper_bound,
limit,
})
}
/** Get subset of `availableKeys` needed to meet authorities in `transaction`. Implements `AuthorityProvider` */
public async getRequiredKeys(args: AuthorityProviderArgs): Promise<string[]> {
return convertLegacyPublicKeys((await this.fetch('/v1/chain/get_required_keys', {
transaction: args.transaction,
available_keys: args.availableKeys,
})).required_keys);
return convertLegacyPublicKeys(
(
await this.fetch('/v1/chain/get_required_keys', {
transaction: args.transaction,
available_keys: args.availableKeys,
})
).required_keys
)
}
/** Push a serialized transaction (replaced by send_transaction, but returned format has changed) */
public async push_transaction(
{ signatures, serializedTransaction, serializedContextFreeData }: PushTransactionArgs
): Promise<any> {
public async push_transaction({
signatures,
serializedTransaction,
serializedContextFreeData,
}: PushTransactionArgs): Promise<any> {
return await this.fetch('/v1/chain/push_transaction', {
signatures,
compression: 0,
packed_context_free_data: arrayToHex(serializedContextFreeData || new Uint8Array(0)),
packed_trx: arrayToHex(serializedTransaction),
});
})
}
/** Send a serialized transaction */
public async send_transaction(
{ signatures, serializedTransaction, serializedContextFreeData }: PushTransactionArgs
): Promise<any> {
public async send_transaction({
signatures,
serializedTransaction,
serializedContextFreeData,
}: PushTransactionArgs): Promise<any> {
return await this.fetch('/v1/chain/send_transaction', {
signatures,
compression: 0,
packed_context_free_data: arrayToHex(serializedContextFreeData || new Uint8Array(0)),
packed_trx: arrayToHex(serializedTransaction),
});
})
}
/** Send a serialized transaction2 */
public async send_transaction2(
{
return_failure_trace,
retry_trx,
retry_trx_num_blocks,
transaction: { signatures, serializedTransaction, serializedContextFreeData }
}: SendTransaction2Args
): Promise<any> {
public async send_transaction2({
return_failure_trace,
retry_trx,
retry_trx_num_blocks,
transaction: {signatures, serializedTransaction, serializedContextFreeData},
}: SendTransaction2Args): Promise<any> {
return await this.fetch('/v1/chain/send_transaction2', {
return_failure_trace,
retry_trx,
@@ -229,32 +262,42 @@ export class JsonRpc implements AuthorityProvider, AbiProvider {
transaction: {
signatures,
compression: 0,
packed_context_free_data: arrayToHex(serializedContextFreeData || new Uint8Array(0)),
packed_context_free_data: arrayToHex(
serializedContextFreeData || new Uint8Array(0)
),
packed_trx: arrayToHex(serializedTransaction),
}
});
},
})
}
/** Raw call to `/v1/db_size/get` */
public async db_size_get() { return await this.fetch('/v1/db_size/get', {}); }
public async db_size_get() {
return await this.fetch('/v1/db_size/get', {})
}
/** Raw call to `/v1/history/get_actions` */
public async history_get_actions(accountName: string, pos: number = null, offset: number = null) {
return await this.fetch('/v1/history/get_actions', { account_name: accountName, pos, offset });
public async history_get_actions(
accountName: string,
pos: number = null,
offset: number = null
) {
return await this.fetch('/v1/history/get_actions', {account_name: accountName, pos, offset})
}
/** Raw call to `/v1/history/get_transaction` */
public async history_get_transaction(id: string, blockNumHint: number = null) {
return await this.fetch('/v1/history/get_transaction', { id, block_num_hint: blockNumHint });
return await this.fetch('/v1/history/get_transaction', {id, block_num_hint: blockNumHint})
}
/** Raw call to `/v1/history/get_key_accounts` */
public async history_get_key_accounts(publicKey: string) {
return await this.fetch('/v1/history/get_key_accounts', { public_key: publicKey });
return await this.fetch('/v1/history/get_key_accounts', {public_key: publicKey})
}
/** Raw call to `/v1/history/get_controlled_accounts` */
public async history_get_controlled_accounts(controllingAccount: string) {
return await this.fetch('/v1/history/get_controlled_accounts', { controlling_account: controllingAccount });
return await this.fetch('/v1/history/get_controlled_accounts', {
controlling_account: controllingAccount,
})
}
} // JsonRpc
+331 -333
View File
File diff suppressed because it is too large Load Diff