starpc 0.35.3 → 0.35.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -36
- package/dist/integration/integration.js +1 -1
- package/dist/srpc/conn.d.ts +2 -2
- package/go.mod +7 -8
- package/go.sum +12 -14
- package/integration/integration.go +3 -3
- package/integration/integration.ts +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,50 +1,63 @@
|
|
|
1
|
-
# Stream RPC
|
|
1
|
+
# Stream RPC (starpc)
|
|
2
2
|
|
|
3
3
|
[![GoDoc Widget]][GoDoc] [![Go Report Card Widget]][Go Report Card]
|
|
4
4
|
|
|
5
|
-
> Protobuf 3 RPC
|
|
5
|
+
> A high-performance Protobuf 3 RPC framework supporting bidirectional streaming over any multiplexer.
|
|
6
6
|
|
|
7
7
|
[GoDoc]: https://godoc.org/github.com/aperturerobotics/starpc
|
|
8
8
|
[GoDoc Widget]: https://godoc.org/github.com/aperturerobotics/starpc?status.svg
|
|
9
9
|
[Go Report Card Widget]: https://goreportcard.com/badge/github.com/aperturerobotics/starpc
|
|
10
10
|
[Go Report Card]: https://goreportcard.com/report/github.com/aperturerobotics/starpc
|
|
11
11
|
|
|
12
|
-
##
|
|
12
|
+
## Table of Contents
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
- [Features](#features)
|
|
15
|
+
- [Installation](#installation)
|
|
16
|
+
- [Quick Start](#quick-start)
|
|
17
|
+
- [Examples](#examples)
|
|
18
|
+
- [Protobuf Definition](#protobuf)
|
|
19
|
+
- [Go Implementation](#go)
|
|
20
|
+
- [TypeScript Implementation](#typescript)
|
|
21
|
+
- [Development Setup](#development-setup)
|
|
22
|
+
- [Support](#support)
|
|
15
23
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
Supports **client-to-server and bidirectional streaming** in the web browser.
|
|
19
|
-
|
|
20
|
-
[rpcproto.proto](./srpc/rpcproto.proto) contains the protocol definition.
|
|
21
|
-
|
|
22
|
-
[rpcstream] supports sub-streams for per-component sub-services.
|
|
23
|
-
|
|
24
|
-
[rpcstream]: ./rpcstream
|
|
24
|
+
## Features
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
- Full [Proto3 services] implementation for both TypeScript and Go
|
|
27
|
+
- Bidirectional streaming support in web browsers
|
|
28
|
+
- Built on libp2p streams with `@chainsafe/libp2p-yamux`
|
|
29
|
+
- Efficient RPC multiplexing over single connections
|
|
30
|
+
- Zero-reflection Go code via [protobuf-go-lite]
|
|
31
|
+
- TypeScript interfaces via [protobuf-es-lite]
|
|
32
|
+
- Sub-streams support through [rpcstream]
|
|
30
33
|
|
|
34
|
+
[Proto3 services]: https://developers.google.com/protocol-buffers/docs/proto3#services
|
|
31
35
|
[protobuf-go-lite]: https://github.com/aperturerobotics/protobuf-go-lite
|
|
32
36
|
[protobuf-es-lite]: https://github.com/aperturerobotics/protobuf-es-lite
|
|
37
|
+
[rpcstream]: ./rpcstream
|
|
33
38
|
|
|
34
|
-
##
|
|
39
|
+
## Installation
|
|
35
40
|
|
|
36
|
-
|
|
41
|
+
```bash
|
|
42
|
+
# Clone the template project
|
|
43
|
+
git clone -b starpc https://github.com/aperturerobotics/protobuf-project
|
|
44
|
+
cd protobuf-project
|
|
37
45
|
|
|
38
|
-
|
|
46
|
+
# Install dependencies
|
|
47
|
+
yarn install
|
|
39
48
|
|
|
40
|
-
|
|
41
|
-
|
|
49
|
+
# Generate TypeScript and Go code
|
|
50
|
+
yarn gen
|
|
51
|
+
```
|
|
42
52
|
|
|
43
|
-
##
|
|
53
|
+
## Quick Start
|
|
44
54
|
|
|
45
|
-
|
|
55
|
+
1. Start with the [protobuf-project] template repository (starpc branch)
|
|
56
|
+
2. Add your .proto files to the project
|
|
57
|
+
3. Run `yarn gen` to generate TypeScript and Go code
|
|
58
|
+
4. Implement your services using the examples below
|
|
46
59
|
|
|
47
|
-
|
|
60
|
+
[protobuf-project]: https://github.com/aperturerobotics/protobuf-project/tree/starpc
|
|
48
61
|
|
|
49
62
|
### Protobuf
|
|
50
63
|
|
|
@@ -128,7 +141,7 @@ This examples demonstrates connecting to a WebSocket server:
|
|
|
128
141
|
import { WebSocketConn } from 'srpc'
|
|
129
142
|
import { EchoerClient } from 'srpc/echo'
|
|
130
143
|
|
|
131
|
-
const ws = new WebSocket('ws://localhost:
|
|
144
|
+
const ws = new WebSocket('ws://localhost:1347/demo')
|
|
132
145
|
const channel = new WebSocketConn(ws)
|
|
133
146
|
const client = channel.buildClient()
|
|
134
147
|
const demoServiceClient = new EchoerClient(client)
|
|
@@ -207,31 +220,41 @@ Uses [protobuf-es-lite] (fork of [protobuf-es]) to generate TypeScript Protobuf
|
|
|
207
220
|
|
|
208
221
|
`protoc-gen-es-starpc` is a heavily modified version of `protoc-gen-connect-es`.
|
|
209
222
|
|
|
210
|
-
##
|
|
223
|
+
## Development Setup
|
|
211
224
|
|
|
212
|
-
|
|
225
|
+
### MacOS Requirements
|
|
213
226
|
|
|
214
|
-
|
|
227
|
+
1. Install required packages:
|
|
228
|
+
```bash
|
|
215
229
|
brew install bash make coreutils gnu-sed findutils protobuf
|
|
216
230
|
brew link --overwrite protobuf
|
|
217
231
|
```
|
|
218
232
|
|
|
219
|
-
Add to your .bashrc or .zshrc:
|
|
220
|
-
|
|
221
|
-
```
|
|
233
|
+
2. Add to your .bashrc or .zshrc:
|
|
234
|
+
```bash
|
|
222
235
|
export PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:$PATH"
|
|
223
236
|
export PATH="/opt/homebrew/opt/gnu-sed/libexec/gnubin:$PATH"
|
|
224
237
|
export PATH="/opt/homebrew/opt/findutils/libexec/gnubin:$PATH"
|
|
225
238
|
export PATH="/opt/homebrew/opt/make/libexec/gnubin:$PATH"
|
|
226
239
|
```
|
|
227
240
|
|
|
228
|
-
##
|
|
241
|
+
## Attribution
|
|
229
242
|
|
|
230
|
-
|
|
243
|
+
- `protoc-gen-go-starpc`: Modified version of `protoc-gen-go-drpc`
|
|
244
|
+
- `protoc-gen-es-starpc`: Modified version of `protoc-gen-connect-es`
|
|
245
|
+
- Uses [vtprotobuf] for Go Protobuf marshaling
|
|
246
|
+
- Uses [protobuf-es-lite] for TypeScript Protobuf interfaces
|
|
231
247
|
|
|
232
|
-
[
|
|
248
|
+
[vtprotobuf]: https://github.com/planetscale/vtprotobuf
|
|
249
|
+
|
|
250
|
+
## Support
|
|
233
251
|
|
|
234
|
-
|
|
252
|
+
Need help? We're here:
|
|
235
253
|
|
|
254
|
+
- [File a GitHub Issue][GitHub issue]
|
|
255
|
+
- [Join our Discord][Join Discord]
|
|
256
|
+
- [Matrix Chat][Matrix Chat]
|
|
257
|
+
|
|
258
|
+
[GitHub issue]: https://github.com/aperturerobotics/starpc/issues/new
|
|
236
259
|
[Join Discord]: https://discord.gg/KJutMESRsT
|
|
237
260
|
[Matrix Chat]: https://matrix.to/#/#aperturerobotics:matrix.org
|
|
@@ -2,7 +2,7 @@ import { WebSocketConn } from '../srpc/websocket.js';
|
|
|
2
2
|
import { runClientTest, runRpcStreamTest, runAbortControllerTest, } from '../echo/client-test.js';
|
|
3
3
|
import WebSocket from 'isomorphic-ws';
|
|
4
4
|
async function runRPC() {
|
|
5
|
-
const addr = 'ws://localhost:
|
|
5
|
+
const addr = 'ws://localhost:4352/demo';
|
|
6
6
|
console.log(`Connecting to ${addr}`);
|
|
7
7
|
const ws = new WebSocket(addr);
|
|
8
8
|
const channel = new WebSocketConn(ws, 'outbound');
|
package/dist/srpc/conn.d.ts
CHANGED
|
@@ -16,8 +16,8 @@ export declare class StreamConn implements Duplex<AsyncGenerator<Uint8Array | Ui
|
|
|
16
16
|
private _muxer;
|
|
17
17
|
private _server?;
|
|
18
18
|
constructor(server?: StreamHandler, connParams?: StreamConnParams);
|
|
19
|
-
get sink(): import("it-stream-types").Sink<AsyncGenerator<Uint8Array | Uint8ArrayList, any, any>, unknown>;
|
|
20
|
-
get source(): AsyncGenerator<Uint8Array | Uint8ArrayList, any, any>;
|
|
19
|
+
get sink(): import("it-stream-types").Sink<AsyncGenerator<Uint8Array<ArrayBufferLike> | Uint8ArrayList, any, any>, unknown>;
|
|
20
|
+
get source(): AsyncGenerator<Uint8Array<ArrayBufferLike> | Uint8ArrayList, any, any>;
|
|
21
21
|
get streams(): Stream[];
|
|
22
22
|
get muxer(): StreamMuxer;
|
|
23
23
|
get server(): StreamHandler | undefined;
|
package/go.mod
CHANGED
|
@@ -6,7 +6,7 @@ toolchain go1.23.3
|
|
|
6
6
|
|
|
7
7
|
replace (
|
|
8
8
|
// This fork uses go-protobuf-lite and adds post-quantum crypto support.
|
|
9
|
-
github.com/libp2p/go-libp2p => github.com/aperturerobotics/go-libp2p v0.
|
|
9
|
+
github.com/libp2p/go-libp2p => github.com/aperturerobotics/go-libp2p v0.37.1-0.20241111002741-5cfbb50b74e0 // aperture
|
|
10
10
|
|
|
11
11
|
// This fork uses go-protobuf-lite.
|
|
12
12
|
github.com/libp2p/go-msgio => github.com/aperturerobotics/go-libp2p-msgio v0.0.0-20240511033615-1b69178aa5c8 // aperture
|
|
@@ -14,21 +14,20 @@ replace (
|
|
|
14
14
|
|
|
15
15
|
require (
|
|
16
16
|
github.com/aperturerobotics/protobuf-go-lite v0.8.0 // latest
|
|
17
|
-
github.com/aperturerobotics/util v1.26.
|
|
17
|
+
github.com/aperturerobotics/util v1.26.3 // latest
|
|
18
18
|
)
|
|
19
19
|
|
|
20
20
|
require (
|
|
21
21
|
github.com/coder/websocket v1.8.12 // latest
|
|
22
|
-
github.com/libp2p/go-libp2p v0.37.
|
|
22
|
+
github.com/libp2p/go-libp2p v0.37.2 // latest
|
|
23
23
|
github.com/libp2p/go-yamux/v4 v4.0.2-0.20240826150533-e92055b23e0e // master
|
|
24
24
|
github.com/pkg/errors v0.9.1 // latest
|
|
25
25
|
github.com/sirupsen/logrus v1.9.3 // latest
|
|
26
|
-
google.golang.org/protobuf v1.35.
|
|
26
|
+
google.golang.org/protobuf v1.35.2 // latest
|
|
27
27
|
)
|
|
28
28
|
|
|
29
29
|
require (
|
|
30
30
|
github.com/aperturerobotics/json-iterator-lite v1.0.0 // indirect
|
|
31
|
-
github.com/cloudflare/circl v1.3.8 // indirect
|
|
32
31
|
github.com/ipfs/go-cid v0.4.1 // indirect
|
|
33
32
|
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
|
|
34
33
|
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
|
|
@@ -42,8 +41,8 @@ require (
|
|
|
42
41
|
github.com/multiformats/go-multistream v0.5.0 // indirect
|
|
43
42
|
github.com/multiformats/go-varint v0.0.7 // indirect
|
|
44
43
|
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
|
45
|
-
golang.org/x/crypto v0.
|
|
46
|
-
golang.org/x/exp v0.0.0-
|
|
47
|
-
golang.org/x/sys v0.
|
|
44
|
+
golang.org/x/crypto v0.29.0 // indirect
|
|
45
|
+
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
|
|
46
|
+
golang.org/x/sys v0.27.0 // indirect
|
|
48
47
|
lukechampine.com/blake3 v1.3.0 // indirect
|
|
49
48
|
)
|
package/go.sum
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
github.com/aperturerobotics/go-libp2p v0.
|
|
2
|
-
github.com/aperturerobotics/go-libp2p v0.
|
|
1
|
+
github.com/aperturerobotics/go-libp2p v0.37.1-0.20241111002741-5cfbb50b74e0 h1:tGwbeDoEeQCrUQL+ClUywldqvz9eRmhcVrGwGxz2xJg=
|
|
2
|
+
github.com/aperturerobotics/go-libp2p v0.37.1-0.20241111002741-5cfbb50b74e0/go.mod h1:FJkAtQcP9XxqG1NNLNHKm+wLVIGSCQX2s6CEoD+w97g=
|
|
3
3
|
github.com/aperturerobotics/json-iterator-lite v1.0.0 h1:cihbrYWoK/S2RYXhJLpDZd+GUjVvFJN+D3w1VOqqHRI=
|
|
4
4
|
github.com/aperturerobotics/json-iterator-lite v1.0.0/go.mod h1:snaApCEDtrHHP6UWSLKiYNOZU9A5NyzccKenx9oZEzg=
|
|
5
5
|
github.com/aperturerobotics/protobuf-go-lite v0.8.0 h1:SoiTAVArmOrNTX31e6CC5Bem6HuOElg3YYNhp4AAPQc=
|
|
6
6
|
github.com/aperturerobotics/protobuf-go-lite v0.8.0/go.mod h1:y49wVEezRHg78uQ2OzLLZbtTTWuox+ChmaTuh6FLJW8=
|
|
7
|
-
github.com/aperturerobotics/util v1.26.
|
|
8
|
-
github.com/aperturerobotics/util v1.26.
|
|
9
|
-
github.com/cloudflare/circl v1.3.8 h1:j+V8jJt09PoeMFIu2uh5JUyEaIHTXVOHslFoLNAKqwI=
|
|
10
|
-
github.com/cloudflare/circl v1.3.8/go.mod h1:PDRU+oXvdD7KCtgKxW95M5Z8BpSCJXQORiZFnBQS5QU=
|
|
7
|
+
github.com/aperturerobotics/util v1.26.3 h1:Z7pjEJX27FDUQyP8OHlBcyEc8MGl8z/ZS1vpRBsIU9E=
|
|
8
|
+
github.com/aperturerobotics/util v1.26.3/go.mod h1:D/N1pG02cPukZtwGggCeb8R/wq11Iy76xjSEGFYa06c=
|
|
11
9
|
github.com/coder/websocket v1.8.12 h1:5bUXkEPPIbewrnkU8LTCLVaxi4N4J8ahufH2vlo4NAo=
|
|
12
10
|
github.com/coder/websocket v1.8.12/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
|
|
13
11
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
@@ -55,16 +53,16 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
|
|
55
53
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
56
54
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
|
57
55
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
|
58
|
-
golang.org/x/crypto v0.
|
|
59
|
-
golang.org/x/crypto v0.
|
|
60
|
-
golang.org/x/exp v0.0.0-
|
|
61
|
-
golang.org/x/exp v0.0.0-
|
|
56
|
+
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
|
|
57
|
+
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
|
|
58
|
+
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f h1:XdNn9LlyWAhLVp6P/i8QYBW+hlyhrhei9uErw2B5GJo=
|
|
59
|
+
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f/go.mod h1:D5SMRVC3C2/4+F/DB1wZsLRnSNimn2Sp/NPsCrsv8ak=
|
|
62
60
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
63
61
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
64
|
-
golang.org/x/sys v0.
|
|
65
|
-
golang.org/x/sys v0.
|
|
66
|
-
google.golang.org/protobuf v1.35.
|
|
67
|
-
google.golang.org/protobuf v1.35.
|
|
62
|
+
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
|
|
63
|
+
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
|
64
|
+
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
|
|
65
|
+
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
|
68
66
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
69
67
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
70
68
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|
@@ -17,15 +17,15 @@ func main() {
|
|
|
17
17
|
logrus.Fatal(err.Error())
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
// listen at: ws://localhost:
|
|
20
|
+
// listen at: ws://localhost:4352/demo
|
|
21
21
|
server, err := srpc.NewHTTPServer(mux, "/demo")
|
|
22
22
|
if err != nil {
|
|
23
23
|
logrus.Fatal(err.Error())
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
fmt.Print("listening on localhost:
|
|
26
|
+
fmt.Print("listening on localhost:4352\n")
|
|
27
27
|
hserver := &http.Server{
|
|
28
|
-
Addr: "localhost:
|
|
28
|
+
Addr: "localhost:4352",
|
|
29
29
|
Handler: server,
|
|
30
30
|
ReadHeaderTimeout: time.Second * 10,
|
|
31
31
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import WebSocket from 'isomorphic-ws'
|
|
8
8
|
|
|
9
9
|
async function runRPC() {
|
|
10
|
-
const addr = 'ws://localhost:
|
|
10
|
+
const addr = 'ws://localhost:4352/demo'
|
|
11
11
|
console.log(`Connecting to ${addr}`)
|
|
12
12
|
const ws = new WebSocket(addr)
|
|
13
13
|
const channel = new WebSocketConn(ws, 'outbound')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starpc",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.5",
|
|
4
4
|
"description": "Streaming protobuf RPC service protocol over any two-way channel.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"type": "module",
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
24
25
|
"import": "./dist/index.js",
|
|
25
|
-
"require": "./dist/index.js"
|
|
26
|
-
"types": "./dist/index.d.ts"
|
|
26
|
+
"require": "./dist/index.js"
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"files": [
|