starpc 0.4.7 → 0.5.0

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.
Files changed (68) hide show
  1. package/Makefile +1 -0
  2. package/README.md +20 -10
  3. package/dist/echo/client-test.d.ts +1 -0
  4. package/dist/echo/client-test.js +20 -18
  5. package/dist/echo/echo.pb.d.ts +165 -12
  6. package/dist/echo/echo.pb.js +61 -17
  7. package/dist/echo/server.d.ts +8 -4
  8. package/dist/echo/server.js +29 -37
  9. package/dist/rpcstream/rpcstream.d.ts +6 -6
  10. package/dist/rpcstream/rpcstream.js +92 -51
  11. package/dist/rpcstream/rpcstream.pb.d.ts +46 -1
  12. package/dist/rpcstream/rpcstream.pb.js +157 -9
  13. package/dist/srpc/broadcast-channel.d.ts +2 -2
  14. package/dist/srpc/broadcast-channel.js +6 -6
  15. package/dist/srpc/client.d.ts +3 -4
  16. package/dist/srpc/client.js +12 -46
  17. package/dist/srpc/common-rpc.d.ts +3 -2
  18. package/dist/srpc/common-rpc.js +12 -0
  19. package/dist/srpc/definition.d.ts +3 -3
  20. package/dist/srpc/handler.d.ts +2 -3
  21. package/dist/srpc/handler.js +5 -22
  22. package/dist/srpc/index.d.ts +2 -2
  23. package/dist/srpc/index.js +2 -2
  24. package/dist/srpc/packet.js +0 -32
  25. package/dist/srpc/pushable.d.ts +2 -0
  26. package/dist/srpc/pushable.js +13 -0
  27. package/dist/srpc/rpcproto.pb.d.ts +13 -6
  28. package/dist/srpc/rpcproto.pb.js +95 -10
  29. package/dist/srpc/server.d.ts +1 -0
  30. package/dist/srpc/server.js +7 -0
  31. package/dist/srpc/ts-proto-rpc.d.ts +3 -4
  32. package/e2e/e2e.ts +4 -3
  33. package/e2e/e2e_test.go +35 -7
  34. package/echo/client-test.ts +23 -18
  35. package/echo/echo.pb.go +33 -20
  36. package/echo/echo.pb.ts +90 -34
  37. package/echo/echo.proto +4 -0
  38. package/echo/echo_srpc.pb.go +77 -0
  39. package/echo/server.go +18 -0
  40. package/echo/server.ts +47 -41
  41. package/integration/integration.go +1 -2
  42. package/integration/integration.ts +5 -1
  43. package/integration/integration_srpc.pb.go +139 -0
  44. package/package.json +13 -11
  45. package/patches/{ts-poet+4.13.0.patch → ts-poet+4.14.0.patch} +1 -1
  46. package/patches/ts-proto+1.115.5.patch +1339 -0
  47. package/srpc/broadcast-channel.ts +8 -8
  48. package/srpc/client.ts +16 -50
  49. package/srpc/common-rpc.ts +14 -2
  50. package/srpc/definition.ts +3 -3
  51. package/srpc/handler.ts +17 -34
  52. package/srpc/index.ts +3 -3
  53. package/srpc/muxed-conn.go +2 -2
  54. package/srpc/packet-rw.go +4 -6
  55. package/srpc/packet.ts +0 -33
  56. package/srpc/pushable.ts +17 -0
  57. package/srpc/rpcproto.pb.ts +122 -12
  58. package/srpc/server-pipe.go +2 -2
  59. package/srpc/server.go +2 -2
  60. package/srpc/server.ts +8 -0
  61. package/srpc/ts-proto-rpc.ts +4 -6
  62. package/srpc/websocket.go +2 -2
  63. package/dist/echo/sever.d.ts +0 -0
  64. package/dist/echo/sever.js +0 -1
  65. package/dist/srpc/observable-source.d.ts +0 -9
  66. package/dist/srpc/observable-source.js +0 -25
  67. package/echo/sever.ts +0 -0
  68. package/srpc/observable-source.ts +0 -40
package/srpc/server.ts CHANGED
@@ -48,6 +48,14 @@ export class Server implements StreamHandler {
48
48
  return rpc
49
49
  }
50
50
 
51
+ // handlePacketDuplex handles an incoming Uint8Array duplex.
52
+ // skips the packet length prefix transform.
53
+ public handlePacketDuplex(stream: Duplex<Uint8Array>): ServerRPC {
54
+ const rpc = this.startRpc()
55
+ pipe(stream, decodePacketSource, rpc, encodePacketSource, stream)
56
+ return rpc
57
+ }
58
+
51
59
  // handlePacketStream handles an incoming Packet duplex.
52
60
  public handlePacketStream(stream: Duplex<Packet>): ServerRPC {
53
61
  const rpc = this.startRpc()
@@ -1,5 +1,3 @@
1
- import type { Observable } from 'rxjs'
2
-
3
1
  // TsProtoRpc matches the Rpc interface generated by ts-proto.
4
2
  export interface TsProtoRpc {
5
3
  // request fires a one-off unary RPC request.
@@ -12,18 +10,18 @@ export interface TsProtoRpc {
12
10
  clientStreamingRequest(
13
11
  service: string,
14
12
  method: string,
15
- data: Observable<Uint8Array>
13
+ data: AsyncIterable<Uint8Array>
16
14
  ): Promise<Uint8Array>
17
15
  // serverStreamingRequest fires a one-way server->client streaming request.
18
16
  serverStreamingRequest(
19
17
  service: string,
20
18
  method: string,
21
19
  data: Uint8Array
22
- ): Observable<Uint8Array>
20
+ ): AsyncIterable<Uint8Array>
23
21
  // bidirectionalStreamingRequest implements a two-way streaming request.
24
22
  bidirectionalStreamingRequest(
25
23
  service: string,
26
24
  method: string,
27
- data: Observable<Uint8Array>
28
- ): Observable<Uint8Array>
25
+ data: AsyncIterable<Uint8Array>
26
+ ): AsyncIterable<Uint8Array>
29
27
  }
package/srpc/websocket.go CHANGED
@@ -49,9 +49,9 @@ func (w *WebSocketConn) OpenStream(ctx context.Context, msgHandler PacketHandler
49
49
  return nil, err
50
50
  }
51
51
 
52
- rw := NewPacketReadWriter(muxedStream, msgHandler)
52
+ rw := NewPacketReadWriter(muxedStream)
53
53
  go func() {
54
- err := rw.ReadPump()
54
+ err := rw.ReadPump(msgHandler)
55
55
  if err != nil {
56
56
  _ = rw.Close()
57
57
  }
File without changes
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,9 +0,0 @@
1
- import { Source } from 'it-stream-types';
2
- import { Observable } from 'rxjs';
3
- export declare class ObservableSource<T> {
4
- readonly source: Source<T>;
5
- private readonly _source;
6
- private readonly subscription;
7
- constructor(observable: Observable<T>);
8
- close(err?: Error): void;
9
- }
@@ -1,25 +0,0 @@
1
- import { pushable } from 'it-pushable';
2
- // ObservableSource wraps an Observable into a Source.
3
- export class ObservableSource {
4
- constructor(observable) {
5
- const source = pushable({ objectMode: true });
6
- this.source = source;
7
- this._source = source;
8
- this.subscription = observable.subscribe({
9
- next: (value) => {
10
- this._source.push(value);
11
- },
12
- error: (err) => {
13
- this._source.end(err);
14
- },
15
- complete: () => {
16
- this._source.end();
17
- },
18
- });
19
- }
20
- // close closes the subscription.
21
- close(err) {
22
- this._source.end(err);
23
- this.subscription.unsubscribe();
24
- }
25
- }
package/echo/sever.ts DELETED
File without changes
@@ -1,40 +0,0 @@
1
- import { Source } from 'it-stream-types'
2
- import { pushable, Pushable } from 'it-pushable'
3
- import { Observable, Subscription } from 'rxjs'
4
-
5
- // ObservableSource wraps an Observable into a Source.
6
- export class ObservableSource<T> {
7
- // source is the source for observable objects.
8
- public readonly source: Source<T>
9
- // _source emits incoming data to the source.
10
- private readonly _source: {
11
- push: (val: T) => void
12
- end: (err?: Error) => void
13
- }
14
- // subscription is the observable subscription
15
- private readonly subscription: Subscription
16
-
17
- constructor(observable: Observable<T>) {
18
- const source: Pushable<T> = pushable({ objectMode: true })
19
- this.source = source
20
- this._source = source
21
-
22
- this.subscription = observable.subscribe({
23
- next: (value: T) => {
24
- this._source.push(value)
25
- },
26
- error: (err) => {
27
- this._source.end(err)
28
- },
29
- complete: () => {
30
- this._source.end()
31
- },
32
- })
33
- }
34
-
35
- // close closes the subscription.
36
- public close(err?: Error) {
37
- this._source.end(err)
38
- this.subscription.unsubscribe()
39
- }
40
- }