Skip to content

Commit

Permalink
Merge pull request #13 from graycraft/release/v0.2.3-alpha
Browse files Browse the repository at this point in the history
Release v0.2.3-alpha
  • Loading branch information
graycraft authored Oct 11, 2024
2 parents 9a9f1c6 + 35e8664 commit 2fc36ab
Show file tree
Hide file tree
Showing 262 changed files with 17,587 additions and 5,764 deletions.
17 changes: 10 additions & 7 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# @see https://editorconfig.org
# @see https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig
# https://editorconfig.org
# https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig

charset = utf-8
[*]
root = true
[*.{cjs,es,es6,js,jsm,json,json5,json6,jsonc,jsox,jsx,mjs,node,ts,tsx}]

[**/*]
charset = utf-8

[**/*.{cjs,cjsx,cts,ctsx,es,es6,js,jsm,json,json5,json6,jsonc,jsox,jsx,mjs,mjsx,mts,mtsx,node,ts,tsx}]
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
max_line_length = 120
trim_trailing_whitespace = true
[*.md]
# @see https://github.com/Microsoft/vscode/issues/1679#issuecomment-323608456

# https://github.com/Microsoft/vscode/issues/1679#issuecomment-323608456
[**/*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
NODE_NO_WARNINGS=1
NODE_OPTIONS=--experimental-vm-modules
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
coverage
node_modules
response/**/snapshot
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Directories with auto-generated files.
.vscode
collection
coverage
response/**/snapshot
67 changes: 61 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# API Tools

Tools to work with a REST API (WebSocket and GraphQL support is on the way).
Tools to work with a REST API and WebSocket.

This package allows to:

Expand Down Expand Up @@ -71,7 +71,9 @@ $ npm i

### Environment

Optionally `NODE_NO_WARNINGS` can be exported from `.env` file to silence process warnings regarding experimental features:
Optionally `NODE_NO_WARNINGS` can be exported from `.env` file to silence process warnings regarding experimental features.

This command also enables `--experimental-vm-modules` option for running [Jest with ESM](https://jestjs.io/docs/ecmascript-modules):

```bash
$ export $(cat .env | xargs)
Expand All @@ -86,13 +88,66 @@ Open settings file of an API and set appropriate fields in `account`, `address`
General syntax of commands:

```bash
$ node <request|response|socket>[ --<option|optionKey=optionValue>]
$ node <api>[ <handler>][ <parameter>][ <paramKey=paramValue>][ --<option>]
$ node request|response|socket[ <option>]
$ node <api>[ <handler>[ <parameter>[ <option>]]]
```
Run all flows for all APIs:
```bash
$ node request
```
Run `currency` flow for all APIs:
```bash
$ node request --flow=currency
```
`<api>` is an API name implemented in API Tools:
```bash
$ node bybit
$ node coinbase
```
`<handler>` is an API request handler:
```bash
$ node bybit currencyAll
$ node bybit networkAll
```
`<implicit>` is implicit parameter (without value):
```bash
$ node bybit currencyAll 10
$ node bybit currencyAll ETHUSDT
```
`<explicit>` is explicit parameter (with a value):
```bash
$ node bybit currencyAll limit=10
$ node bybit currencyAll pair=ETHUSDT
```
`<option>` is option to apply while executing an API request handler or flow:
```bash
$ node bybit --flow=order
$ node bybit --verbose
$ node bybit currencyAll --verbose
$ node bybit currencyAll 10
$ node bybit currencyAll limit=10 --verbose
```
Full list of commands, parameters and options depends on API implementation.
- --auth[entication] - output authentication information from internal variables.
- --debug[ging] - output debugging information from internal variables.
- --head[ers] - output request and response headers.
- --verb[ose] - output verbose information about executed request.
See detailed syntax and command examples in **sub directory readme** files.
Full list of handlers, parameters and options depends on API implementation.
### Request
Expand Down
69 changes: 69 additions & 0 deletions __tests__/library/utility.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { parseArguments } from '#lib/utility.mjs';

describe('parseArguments', () => {
test('root api', () => {
expect(parseArguments(['root', 'api'])).toEqual({
explicit: {},
handler: '',
implicit: [],
options: {},
params: [],
});
});
test('root api handler', () => {
expect(parseArguments(['root', 'api', 'handler'])).toEqual({
explicit: {},
handler: 'handler',
implicit: [],
options: {},
params: [],
});
});
test('root api handler param', () => {
expect(parseArguments(['root', 'api', 'handler', 'param'])).toEqual({
explicit: {},
handler: 'handler',
implicit: ['param'],
options: {},
params: ['param'],
});
});
test('root api handler param paramKey=paramValue', () => {
expect(parseArguments(['root', 'api', 'handler', 'param', 'paramKey=paramValue'])).toEqual({
explicit: { paramKey: 'paramValue' },
handler: 'handler',
implicit: ['param'],
options: {},
params: ['param', { paramKey: 'paramValue' }],
});
});
test('root api handler param paramKey=paramValue --aggr=optionValue', () => {
expect(
parseArguments([
'root',
'api',
'handler',
'param',
'paramKey=paramValue',
'--aggr=optionValue',
]),
).toEqual({
explicit: { paramKey: 'paramValue' },
handler: 'handler',
implicit: ['param'],
options: { aggregate: true },
params: ['param', { paramKey: 'paramValue' }],
});
});
test('root api handler param paramKey=paramValue --aggr=off', () => {
expect(
parseArguments(['root', 'api', 'handler', 'param', 'paramKey=paramValue', '--aggr=off']),
).toEqual({
explicit: { paramKey: 'paramValue' },
handler: 'handler',
implicit: ['param'],
options: { aggregate: false },
params: ['param', { paramKey: 'paramValue' }],
});
});
});
Loading

0 comments on commit 2fc36ab

Please sign in to comment.