Skip to content

Commit 6446a76

Browse files
committed
add coverage
1 parent 572b106 commit 6446a76

18 files changed

+623
-90
lines changed

.github/workflows/ci.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ${{ matrix.os }}
12+
timeout-minutes: 30
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
deno:
17+
- v1.x
18+
- canary
19+
os:
20+
- ubuntu-22.04
21+
- windows-2022
22+
- macOS-12
23+
24+
steps:
25+
- name: Clone repository
26+
uses: actions/checkout@v4
27+
with:
28+
submodules: true
29+
30+
- name: Set up Deno
31+
uses: denoland/setup-deno@v1
32+
with:
33+
deno-version: ${{ matrix.deno }}
34+
35+
- name: Run tests canary
36+
run: deno task test
37+
38+
- name: Generate lcov
39+
run: deno task cov:gen
40+
41+
- name: Upload coverage
42+
uses: codecov/codecov-action@v3
43+
env:
44+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
45+
with:
46+
name: ${{ matrix.os }}-${{ matrix.deno }}
47+
files: cov.lcov
48+
49+
lint:
50+
runs-on: ubuntu-22.04
51+
steps:
52+
- name: Clone repository
53+
uses: actions/checkout@v4
54+
with:
55+
submodules: false
56+
persist-credentials: false
57+
58+
- name: Set up Deno
59+
uses: denoland/setup-deno@v1
60+
with:
61+
deno-version: canary
62+
63+
- name: Format
64+
run: deno fmt --check
65+
66+
- name: Lint
67+
run: deno task lint

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
docs/
2+
coverage/
3+
cov.lcov

README.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# json-rpc-ts
22

33
[![deno.land/x](https://shield.deno.dev/x/json_rpc_ts)](https://deno.land/x/json_rpc_ts)
4+
[![ci](https://github.com/yieldray/json-rpc-ts/actions/workflows/ci.yml/badge.svg)](https://github.com/yieldray/json-rpc-ts/actions/workflows/ci.yml)
45

5-
A strictly typed json-rpc(2.0) implemention, zero dependency, minimal abstraction, with simple api
6+
A strictly typed json-rpc(2.0) implementation, zero dependency, minimal abstraction, with simple api
67

78
> Specification <https://www.jsonrpc.org/specification>
89
@@ -14,19 +15,29 @@ const methodSet = {
1415
minus: ([a, b]: [number, number]) => a - b,
1516
}
1617

18+
// initialize all methods with the constructor
1719
const server = new JSONRPCServer(methodSet)
1820

21+
// or add methods manually
22+
const server = new JSONRPCServer<typeof methodSet>()
23+
server.setMethod('upper', methodSet.upper)
24+
server.setMethod('lower', methodSet.lower)
25+
server.setMethod('plus', methodSet.plus)
26+
server.setMethod('minus', methodSet.minus)
27+
28+
// (optional) provide a generic parameter to enable ts check
1929
const client = new JSONRPCClient<typeof methodSet>((json) =>
2030
server.process(json)
2131
)
2232

33+
// request, Notification and batch are always async
2334
assertEquals(await client.request('upper', 'hello'), 'HELLO')
2435

2536
assertEquals(
2637
await client.batch(
2738
client.createRequest('upper', 'nihao'),
28-
// notifaction does not have response, even when response errors
29-
client.createNotifaction('upper'),
39+
// Notification does not have response, even when response errors
40+
client.createNotification('upper'),
3041
client.createRequest('upper', 'shijie'),
3142
client.createRequest('plus', [1, 1]),
3243
),
@@ -85,3 +96,13 @@ const httpServer = Deno.serve(
8596
},
8697
)
8798
```
99+
100+
# build for JavaScript
101+
102+
To use this library without typescript, you have to build it to javascript.
103+
104+
```sh
105+
git clone https://github.com/YieldRay/json-rpc-ts.git
106+
cd json-rpc-ts
107+
esbuild --bundle src/index.ts --outdir=dist --format=esm
108+
```

deno.json

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,38 @@
11
{
2+
"compilerOptions": {
3+
"strict": true,
4+
"useUnknownInCatchVariables": true,
5+
"noImplicitOverride": true
6+
},
27
"imports": {
38
"std/": "https://deno.land/[email protected]/"
49
},
510
"tasks": {
6-
"docs": "deno doc --html --name=json-rpc-ts --output=./docs/ ./src/index.ts"
11+
"lint": "deno lint",
12+
"fmt": "deno fmt",
13+
"docs": "deno doc --html --name=json-rpc-ts --output=./docs/ ./mod.ts",
14+
"test": "deno test --parallel --coverage --trace-ops",
15+
"cov:gen": "deno coverage coverage --lcov --output=cov.lcov",
16+
"cov:view": "deno coverage --html coverage",
17+
"cov:clean": "rm -rf ./coverage/ cov.lcov"
718
},
819
"fmt": {
920
"lineWidth": 80,
1021
"semiColons": false,
1122
"indentWidth": 4,
1223
"singleQuote": true,
1324
"proseWrap": "preserve",
14-
"include": ["*"],
15-
"exclude": []
16-
}
25+
"include": [
26+
"src",
27+
".github",
28+
"deno.json",
29+
"README.md",
30+
"mod.ts"
31+
]
32+
},
33+
"exclude": [
34+
".git",
35+
"docs",
36+
"coverage"
37+
]
1738
}

mod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "./src/index.ts"
1+
export * from './src/index.ts'

0 commit comments

Comments
 (0)