Skip to content

Commit 2fc36ab

Browse files
authored
Merge pull request #13 from graycraft/release/v0.2.3-alpha
Release v0.2.3-alpha
2 parents 9a9f1c6 + 35e8664 commit 2fc36ab

File tree

262 files changed

+17587
-5764
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

262 files changed

+17587
-5764
lines changed

.editorconfig

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
# @see https://editorconfig.org
2-
# @see https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig
1+
# https://editorconfig.org
2+
# https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig
33

4-
charset = utf-8
5-
[*]
64
root = true
7-
[*.{cjs,es,es6,js,jsm,json,json5,json6,jsonc,jsox,jsx,mjs,node,ts,tsx}]
5+
6+
[**/*]
7+
charset = utf-8
8+
9+
[**/*.{cjs,cjsx,cts,ctsx,es,es6,js,jsm,json,json5,json6,jsonc,jsox,jsx,mjs,mjsx,mts,mtsx,node,ts,tsx}]
810
end_of_line = lf
911
indent_size = 2
1012
indent_style = space
1113
insert_final_newline = true
1214
max_line_length = 120
1315
trim_trailing_whitespace = true
14-
[*.md]
15-
# @see https://github.com/Microsoft/vscode/issues/1679#issuecomment-323608456
16+
17+
# https://github.com/Microsoft/vscode/issues/1679#issuecomment-323608456
18+
[**/*.md]
1619
trim_trailing_whitespace = false

.env

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
NODE_NO_WARNINGS=1
2+
NODE_OPTIONS=--experimental-vm-modules

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
coverage
12
node_modules
23
response/**/snapshot

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Directories with auto-generated files.
22
.vscode
33
collection
4+
coverage
45
response/**/snapshot

README.md

+61-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# API Tools
22

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

55
This package allows to:
66

@@ -71,7 +71,9 @@ $ npm i
7171

7272
### Environment
7373

74-
Optionally `NODE_NO_WARNINGS` can be exported from `.env` file to silence process warnings regarding experimental features:
74+
Optionally `NODE_NO_WARNINGS` can be exported from `.env` file to silence process warnings regarding experimental features.
75+
76+
This command also enables `--experimental-vm-modules` option for running [Jest with ESM](https://jestjs.io/docs/ecmascript-modules):
7577

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

8890
```bash
89-
$ node <request|response|socket>[ --<option|optionKey=optionValue>]
90-
$ node <api>[ <handler>][ <parameter>][ <paramKey=paramValue>][ --<option>]
91+
$ node request|response|socket[ <option>]
92+
$ node <api>[ <handler>[ <parameter>[ <option>]]]
93+
```
94+
95+
Run all flows for all APIs:
96+
97+
```bash
98+
$ node request
99+
```
100+
101+
Run `currency` flow for all APIs:
102+
103+
```bash
104+
$ node request --flow=currency
105+
```
106+
107+
`<api>` is an API name implemented in API Tools:
108+
109+
```bash
110+
$ node bybit
111+
$ node coinbase
112+
```
113+
114+
`<handler>` is an API request handler:
115+
116+
```bash
117+
$ node bybit currencyAll
118+
$ node bybit networkAll
119+
```
120+
121+
`<implicit>` is implicit parameter (without value):
122+
123+
```bash
124+
$ node bybit currencyAll 10
125+
$ node bybit currencyAll ETHUSDT
126+
```
127+
128+
`<explicit>` is explicit parameter (with a value):
129+
130+
```bash
131+
$ node bybit currencyAll limit=10
132+
$ node bybit currencyAll pair=ETHUSDT
133+
```
134+
135+
`<option>` is option to apply while executing an API request handler or flow:
136+
137+
```bash
138+
$ node bybit --flow=order
139+
$ node bybit --verbose
140+
$ node bybit currencyAll --verbose
141+
$ node bybit currencyAll 10
142+
$ node bybit currencyAll limit=10 --verbose
91143
```
92144
93-
Full list of commands, parameters and options depends on API implementation.
145+
- --auth[entication] - output authentication information from internal variables.
146+
- --debug[ging] - output debugging information from internal variables.
147+
- --head[ers] - output request and response headers.
148+
- --verb[ose] - output verbose information about executed request.
94149
95-
See detailed syntax and command examples in **sub directory readme** files.
150+
Full list of handlers, parameters and options depends on API implementation.
96151
97152
### Request
98153

__tests__/library/utility.test.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { parseArguments } from '#lib/utility.mjs';
2+
3+
describe('parseArguments', () => {
4+
test('root api', () => {
5+
expect(parseArguments(['root', 'api'])).toEqual({
6+
explicit: {},
7+
handler: '',
8+
implicit: [],
9+
options: {},
10+
params: [],
11+
});
12+
});
13+
test('root api handler', () => {
14+
expect(parseArguments(['root', 'api', 'handler'])).toEqual({
15+
explicit: {},
16+
handler: 'handler',
17+
implicit: [],
18+
options: {},
19+
params: [],
20+
});
21+
});
22+
test('root api handler param', () => {
23+
expect(parseArguments(['root', 'api', 'handler', 'param'])).toEqual({
24+
explicit: {},
25+
handler: 'handler',
26+
implicit: ['param'],
27+
options: {},
28+
params: ['param'],
29+
});
30+
});
31+
test('root api handler param paramKey=paramValue', () => {
32+
expect(parseArguments(['root', 'api', 'handler', 'param', 'paramKey=paramValue'])).toEqual({
33+
explicit: { paramKey: 'paramValue' },
34+
handler: 'handler',
35+
implicit: ['param'],
36+
options: {},
37+
params: ['param', { paramKey: 'paramValue' }],
38+
});
39+
});
40+
test('root api handler param paramKey=paramValue --aggr=optionValue', () => {
41+
expect(
42+
parseArguments([
43+
'root',
44+
'api',
45+
'handler',
46+
'param',
47+
'paramKey=paramValue',
48+
'--aggr=optionValue',
49+
]),
50+
).toEqual({
51+
explicit: { paramKey: 'paramValue' },
52+
handler: 'handler',
53+
implicit: ['param'],
54+
options: { aggregate: true },
55+
params: ['param', { paramKey: 'paramValue' }],
56+
});
57+
});
58+
test('root api handler param paramKey=paramValue --aggr=off', () => {
59+
expect(
60+
parseArguments(['root', 'api', 'handler', 'param', 'paramKey=paramValue', '--aggr=off']),
61+
).toEqual({
62+
explicit: { paramKey: 'paramValue' },
63+
handler: 'handler',
64+
implicit: ['param'],
65+
options: { aggregate: false },
66+
params: ['param', { paramKey: 'paramValue' }],
67+
});
68+
});
69+
});

0 commit comments

Comments
 (0)