Skip to content

Commit 2f55ab5

Browse files
committed
initial message utilities
0 parents  commit 2f55ab5

25 files changed

+592
-0
lines changed

.github/workflows/test.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
pull_request:
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: erlef/setup-beam@v1
16+
with:
17+
otp-version: "26.0.2"
18+
gleam-version: "1.4.1"
19+
rebar3-version: "3"
20+
# elixir-version: "1.15.4"
21+
- run: gleam deps download
22+
- run: gleam test
23+
- run: gleam format --check src test

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.beam
2+
*.ez
3+
/build
4+
erl_crash.dump
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: 1.2.3
3+
title: encoded error
4+
file: ./test/json_rpc_test.gleam
5+
test_name: encoded_error_test
6+
---
7+
{"jsonrpc":"2.0","id":"id string","error":{"code":404,"message":"Not Found"}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: 1.2.3
3+
title: encoded error with data
4+
file: ./test/json_rpc_test.gleam
5+
test_name: encoded_error_data_test
6+
---
7+
{"jsonrpc":"2.0","id":"id string","error":{"code":-32700,"message":"Parse error","data":"Unexpected End of Input"}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: 1.2.3
3+
title: encoded notification
4+
file: ./test/json_rpc_test.gleam
5+
test_name: encoded_notification_test
6+
---
7+
{"jsonrpc":"2.0","method":"heartbeat"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: 1.2.3
3+
title: encoded notification with params
4+
file: ./test/json_rpc_test.gleam
5+
test_name: encoded_notification_params_test
6+
---
7+
{"jsonrpc":"2.0","method":"progress","params":{"complete":0.5}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: 1.2.3
3+
title: encoded request
4+
file: ./test/json_rpc_test.gleam
5+
test_name: encoded_request_test
6+
---
7+
{"jsonrpc":"2.0","id":777777,"method":"ping"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: 1.2.3
3+
title: encoded request with params
4+
file: ./test/json_rpc_test.gleam
5+
test_name: encoded_request_params_test
6+
---
7+
{"jsonrpc":"2.0","id":999999,"method":"get","params":{"path":"/posts"}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: 1.2.3
3+
title: encoded response
4+
file: ./test/json_rpc_test.gleam
5+
test_name: encoded_response_test
6+
---
7+
{"jsonrpc":"2.0","id":777777,"result":"pong"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: 1.2.3
3+
title: invalid request error message
4+
file: ./test/message_test.gleam
5+
test_name: invalid_message_test
6+
---
7+
{"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"Invalid Request"}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: 1.2.3
3+
title: parsed error with data
4+
file: ./test/message_test.gleam
5+
test_name: parse_error_data_test
6+
---
7+
ErrorResponse(Some(StringId("id string")), ErrorObject(-32700, "Parse error", Some("Unexpected End of Input")))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: 1.2.3
3+
title: parsed notification
4+
file: ./test/message_test.gleam
5+
test_name: parse_notification_test
6+
---
7+
Notification("heartbeat", None)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: 1.2.3
3+
title: parsed notification with params
4+
file: ./test/message_test.gleam
5+
test_name: parse_notification_params_test
6+
---
7+
Notification("progress", Some(dict.from_list([#("complete", 0.5)])))
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: 1.2.3
3+
title: parsed request
4+
file: ./test/message_test.gleam
5+
test_name: parse_request_test
6+
---
7+
Request(IntId(777777), "ping", None)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: 1.2.3
3+
title: parsed request with params
4+
file: ./test/message_test.gleam
5+
test_name: parse_request_params_test
6+
---
7+
Request(IntId(999999), "get", Some(dict.from_list([#("path", "/posts")])))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: 1.2.3
3+
title: parsed response
4+
file: ./test/message_test.gleam
5+
test_name: parse_response_test
6+
---
7+
SuccessResponse(IntId(777777), "pong")
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: 1.2.3
3+
title: prased error
4+
file: ./test/message_test.gleam
5+
test_name: parse_error_test
6+
---
7+
ErrorResponse(Some(StringId("id string")), ErrorObject(404, "Not Found", None))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: 1.2.3
3+
title: unexpected byte error message
4+
file: ./test/message_test.gleam
5+
test_name: unexpected_byte_test
6+
---
7+
{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error","data":"Unexpected Byte: \"0xE2\""}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: 1.2.3
3+
title: unexpected end of input error message
4+
file: ./test/message_test.gleam
5+
test_name: unexpected_end_of_input_test
6+
---
7+
{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error","data":"Unexpected End of Input"}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: 1.2.3
3+
title: unexpected sequence error message
4+
file: ./test/message_test.gleam
5+
test_name: unexpected_sequence_test
6+
---
7+
{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error","data":"Unexpected Sequence: \"\\uxxxx\""}}

gleam.toml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name = "json_rpc"
2+
version = "1.0.0"
3+
gleam = ">= 1.5.0"
4+
description = "JSON-RPC utilities for Gleam"
5+
licences = ["MIT"]
6+
repository = { type = "github", user = "drowrin", repo = "json_rpc" }
7+
8+
[dependencies]
9+
gleam_stdlib = ">= 0.34.0 and < 2.0.0"
10+
gleam_json = ">= 2.0.0 and < 3.0.0"
11+
12+
[dev-dependencies]
13+
gleeunit = ">= 1.0.0 and < 2.0.0"
14+
birdie = ">= 1.2.3 and < 2.0.0"

manifest.toml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This file was generated by Gleam
2+
# You typically do not need to edit this file
3+
4+
packages = [
5+
{ name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" },
6+
{ name = "birdie", version = "1.2.3", build_tools = ["gleam"], requirements = ["argv", "edit_distance", "filepath", "glance", "gleam_community_ansi", "gleam_erlang", "gleam_stdlib", "justin", "rank", "simplifile", "trie_again"], otp_app = "birdie", source = "hex", outer_checksum = "AE1207210E9CC8F4170BCE3FB3C23932F314C352C3FD1BCEA44CF4BF8CF60F93" },
7+
{ name = "edit_distance", version = "2.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "edit_distance", source = "hex", outer_checksum = "A1E485C69A70210223E46E63985FA1008B8B2DDA9848B7897469171B29020C05" },
8+
{ name = "filepath", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "EFB6FF65C98B2A16378ABC3EE2B14124168C0CE5201553DE652E2644DCFDB594" },
9+
{ name = "glance", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "glexer"], otp_app = "glance", source = "hex", outer_checksum = "8F3314D27773B7C3B9FB58D8C02C634290422CE531988C0394FA0DF8676B964D" },
10+
{ name = "gleam_community_ansi", version = "1.4.1", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "4CD513FC62523053E62ED7BAC2F36136EC17D6A8942728250A9A00A15E340E4B" },
11+
{ name = "gleam_community_colour", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "A49A5E3AE8B637A5ACBA80ECB9B1AFE89FD3D5351FF6410A42B84F666D40D7D5" },
12+
{ name = "gleam_erlang", version = "0.26.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "3DF72F95F4716883FA51396FB0C550ED3D55195B541568CAF09745984FD37AD1" },
13+
{ name = "gleam_json", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "CB10B0E7BF44282FB25162F1A24C1A025F6B93E777CCF238C4017E4EEF2CDE97" },
14+
{ name = "gleam_stdlib", version = "0.40.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "86606B75A600BBD05E539EB59FABC6E307EEEA7B1E5865AFB6D980A93BCB2181" },
15+
{ name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" },
16+
{ name = "glexer", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glexer", source = "hex", outer_checksum = "BD477AD657C2B637FEF75F2405FAEFFA533F277A74EF1A5E17B55B1178C228FB" },
17+
{ name = "justin", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "justin", source = "hex", outer_checksum = "7FA0C6DB78640C6DC5FBFD59BF3456009F3F8B485BF6825E97E1EB44E9A1E2CD" },
18+
{ name = "rank", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "rank", source = "hex", outer_checksum = "5660E361F0E49CBB714CC57CC4C89C63415D8986F05B2DA0C719D5642FAD91C9" },
19+
{ name = "simplifile", version = "2.1.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "BDD04F5D31D6D34E2EDFAEF0B68A6297AEC939888C3BFCE61133DE13857F6DA2" },
20+
{ name = "trie_again", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "trie_again", source = "hex", outer_checksum = "5B19176F52B1BD98831B57FDC97BD1F88C8A403D6D8C63471407E78598E27184" },
21+
]
22+
23+
[requirements]
24+
birdie = { version = ">= 1.2.3 and < 2.0.0" }
25+
gleam_json = { version = ">= 2.0.0 and < 3.0.0" }
26+
gleam_stdlib = { version = ">= 0.34.0 and < 2.0.0" }
27+
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }

0 commit comments

Comments
 (0)