starpc 0.49.20 → 0.50.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 (44) hide show
  1. package/dist/integration/cross-language/ts-server.js +22 -6
  2. package/dist/mock/index.d.ts +2 -2
  3. package/dist/mock/index.js +2 -2
  4. package/dist/rpcstream/receipt.test.d.ts +1 -0
  5. package/dist/rpcstream/receipt.test.js +41 -0
  6. package/dist/srpc/call-receipt.js +2 -1
  7. package/dist/srpc/call-receipt.test.js +15 -14
  8. package/dist/srpc/common-rpc.d.ts +1 -3
  9. package/dist/srpc/common-rpc.js +10 -13
  10. package/dist/srpc/index.d.ts +1 -1
  11. package/dist/srpc/index.js +1 -0
  12. package/dist/srpc/rpcproto.pb.d.ts +44 -0
  13. package/dist/srpc/rpcproto.pb.js +53 -0
  14. package/dist/srpc/server-invocation.d.ts +1 -1
  15. package/go.mod +13 -12
  16. package/go.sum +24 -24
  17. package/integration/cross-language/go-server/fixture-owner_test.go +127 -0
  18. package/integration/cross-language/go-server/main.go +64 -42
  19. package/integration/cross-language/run.bash +2 -2
  20. package/integration/cross-language/ts-server.ts +27 -7
  21. package/mock/index.ts +2 -2
  22. package/package.json +19 -26
  23. package/srpc/accept.go +1 -1
  24. package/srpc/call-receipt-e2e_test.go +2 -2
  25. package/srpc/call-receipt.go +1 -1
  26. package/srpc/call-receipt.test.ts +19 -16
  27. package/srpc/call-receipt.ts +2 -1
  28. package/srpc/call-receipt_test.go +19 -19
  29. package/srpc/common-rpc.go +6 -6
  30. package/srpc/common-rpc.ts +17 -16
  31. package/srpc/index.ts +1 -1
  32. package/srpc/muxed-conn.go +1 -1
  33. package/srpc/muxed-yamux.go +1 -1
  34. package/srpc/rpcproto.pb.cc +15 -4
  35. package/srpc/rpcproto.pb.go +96 -0
  36. package/srpc/rpcproto.pb.h +59 -0
  37. package/srpc/rpcproto.pb.rs +45 -0
  38. package/srpc/rpcproto.pb.ts +62 -0
  39. package/srpc/rpcproto.proto +16 -0
  40. package/srpc/schema-ownership_test.go +115 -0
  41. package/srpc/server-invocation.go +1 -19
  42. package/srpc/server-invocation.ts +1 -7
  43. package/srpc/stream-yamux.go +1 -1
  44. package/srpc/websocket.go +1 -1
@@ -2,6 +2,7 @@
2
2
  // @generated from file github.com/aperturerobotics/starpc/srpc/rpcproto.proto (package srpc, syntax proto3)
3
3
  /* eslint-disable */
4
4
 
5
+ import { createEnumType } from '@aptre/protobuf-es-lite/enum'
5
6
  import type { MessageType } from '@aptre/protobuf-es-lite/message'
6
7
  import { createMessageType } from '@aptre/protobuf-es-lite/message'
7
8
  import { ScalarType } from '@aptre/protobuf-es-lite/scalar'
@@ -9,6 +10,67 @@ import type { PartialFieldInfo } from '@aptre/protobuf-es-lite/field'
9
10
 
10
11
  export const protobufPackage = 'srpc'
11
12
 
13
+ /**
14
+ * TerminalKind is the terminal state of a held unary invocation.
15
+ *
16
+ * @generated from enum srpc.TerminalKind
17
+ */
18
+ export enum TerminalKind {
19
+ /**
20
+ * TERMINAL_KIND_UNSPECIFIED is not a valid terminal state.
21
+ *
22
+ * @generated from enum value: TERMINAL_KIND_UNSPECIFIED = 0;
23
+ */
24
+ UNSPECIFIED = 0,
25
+
26
+ /**
27
+ * TERMINAL_KIND_COMMITTED identifies an explicit remote CallData completion.
28
+ *
29
+ * @generated from enum value: TERMINAL_KIND_COMMITTED = 1;
30
+ */
31
+ COMMITTED = 1,
32
+
33
+ /**
34
+ * TERMINAL_KIND_CANCELED identifies a remote CallCancel packet.
35
+ *
36
+ * @generated from enum value: TERMINAL_KIND_CANCELED = 2;
37
+ */
38
+ CANCELED = 2,
39
+
40
+ /**
41
+ * TERMINAL_KIND_TRANSPORT_LOST identifies a remote error or transport failure.
42
+ *
43
+ * @generated from enum value: TERMINAL_KIND_TRANSPORT_LOST = 3;
44
+ */
45
+ TRANSPORT_LOST = 3,
46
+
47
+ /**
48
+ * TERMINAL_KIND_CLOSED identifies a bare remote close without completion.
49
+ *
50
+ * @generated from enum value: TERMINAL_KIND_CLOSED = 4;
51
+ */
52
+ CLOSED = 4,
53
+
54
+ /**
55
+ * TERMINAL_KIND_ABANDONED identifies owner-context expiry without a remote terminal.
56
+ *
57
+ * @generated from enum value: TERMINAL_KIND_ABANDONED = 5;
58
+ */
59
+ ABANDONED = 5,
60
+ }
61
+
62
+ export const TerminalKind_Enum = /* @__PURE__ */ createEnumType(
63
+ 'srpc.TerminalKind',
64
+ [
65
+ [0, 'TERMINAL_KIND_UNSPECIFIED'],
66
+ [1, 'TERMINAL_KIND_COMMITTED'],
67
+ [2, 'TERMINAL_KIND_CANCELED'],
68
+ [3, 'TERMINAL_KIND_TRANSPORT_LOST'],
69
+ [4, 'TERMINAL_KIND_CLOSED'],
70
+ [5, 'TERMINAL_KIND_ABANDONED'],
71
+ ],
72
+ )
73
+
12
74
  /**
13
75
  * CallStart requests starting a new RPC call.
14
76
  *
@@ -1,6 +1,22 @@
1
1
  syntax = "proto3";
2
2
  package srpc;
3
3
 
4
+ // TerminalKind is the terminal state of a held unary invocation.
5
+ enum TerminalKind {
6
+ // TERMINAL_KIND_UNSPECIFIED is not a valid terminal state.
7
+ TERMINAL_KIND_UNSPECIFIED = 0;
8
+ // TERMINAL_KIND_COMMITTED identifies an explicit remote CallData completion.
9
+ TERMINAL_KIND_COMMITTED = 1;
10
+ // TERMINAL_KIND_CANCELED identifies a remote CallCancel packet.
11
+ TERMINAL_KIND_CANCELED = 2;
12
+ // TERMINAL_KIND_TRANSPORT_LOST identifies a remote error or transport failure.
13
+ TERMINAL_KIND_TRANSPORT_LOST = 3;
14
+ // TERMINAL_KIND_CLOSED identifies a bare remote close without completion.
15
+ TERMINAL_KIND_CLOSED = 4;
16
+ // TERMINAL_KIND_ABANDONED identifies owner-context expiry without a remote terminal.
17
+ TERMINAL_KIND_ABANDONED = 5;
18
+ }
19
+
4
20
  // Packet is a message sent over a srpc packet connection.
5
21
  message Packet {
6
22
  // Body is the packet body.
@@ -0,0 +1,115 @@
1
+ package srpc
2
+
3
+ import (
4
+ "go/ast"
5
+ "go/parser"
6
+ "go/token"
7
+ "os"
8
+ "strings"
9
+ "testing"
10
+ )
11
+
12
+ // handwrittenTerminalConst names the parallel iota constants the receipt
13
+ // post-mortem removed. Their reappearance signals a second handwritten owner of
14
+ // the cross-language terminal vocabulary.
15
+ var handwrittenTerminalConst = map[string]bool{
16
+ "TerminalCommitted": true,
17
+ "TerminalCanceled": true,
18
+ "TerminalLost": true,
19
+ "TerminalClosed": true,
20
+ "TerminalAbandoned": true,
21
+ }
22
+
23
+ // handwrittenTerminalKindOwners returns the source files that declare the shared
24
+ // TerminalKind vocabulary by hand instead of consuming the generated rpcproto
25
+ // owner. The cross-language terminal noun has exactly one schema owner; a
26
+ // handwritten type or iota constant reintroduces the parallel owner.
27
+ func handwrittenTerminalKindOwners(t *testing.T, files map[string]string) []string {
28
+ t.Helper()
29
+ var owners []string
30
+ for name, src := range files {
31
+ fset := token.NewFileSet()
32
+ file, err := parser.ParseFile(fset, name, src, 0)
33
+ if err != nil {
34
+ t.Fatalf("parse %s: %v", name, err)
35
+ }
36
+ if declaresTerminalKindByHand(file) {
37
+ owners = append(owners, name)
38
+ }
39
+ }
40
+ return owners
41
+ }
42
+
43
+ // declaresTerminalKindByHand reports whether a file declares the TerminalKind
44
+ // type or one of its removed iota constants.
45
+ func declaresTerminalKindByHand(file *ast.File) bool {
46
+ for _, decl := range file.Decls {
47
+ gen, ok := decl.(*ast.GenDecl)
48
+ if !ok {
49
+ continue
50
+ }
51
+ for _, spec := range gen.Specs {
52
+ switch s := spec.(type) {
53
+ case *ast.TypeSpec:
54
+ if s.Name.Name == "TerminalKind" {
55
+ return true
56
+ }
57
+ case *ast.ValueSpec:
58
+ for _, id := range s.Names {
59
+ if handwrittenTerminalConst[id.Name] {
60
+ return true
61
+ }
62
+ }
63
+ }
64
+ }
65
+ }
66
+ return false
67
+ }
68
+
69
+ // packageSourceFiles reads the non-generated, non-test Go sources of the current
70
+ // package directory.
71
+ func packageSourceFiles(t *testing.T) map[string]string {
72
+ t.Helper()
73
+ entries, err := os.ReadDir(".")
74
+ if err != nil {
75
+ t.Fatalf("read package dir: %v", err)
76
+ }
77
+ files := map[string]string{}
78
+ for _, entry := range entries {
79
+ name := entry.Name()
80
+ if !strings.HasSuffix(name, ".go") {
81
+ continue
82
+ }
83
+ if strings.HasSuffix(name, ".pb.go") || strings.HasSuffix(name, "_test.go") {
84
+ continue
85
+ }
86
+ data, err := os.ReadFile(name)
87
+ if err != nil {
88
+ t.Fatalf("read %s: %v", name, err)
89
+ }
90
+ files[name] = string(data)
91
+ }
92
+ return files
93
+ }
94
+
95
+ // TestTerminalKindHasSingleSchemaOwner proves no handwritten srpc source owns
96
+ // the cross-language TerminalKind vocabulary alongside the generated owner.
97
+ func TestTerminalKindHasSingleSchemaOwner(t *testing.T) {
98
+ owners := handwrittenTerminalKindOwners(t, packageSourceFiles(t))
99
+ if len(owners) != 0 {
100
+ t.Fatalf("TerminalKind must come from generated rpcproto; handwritten owners: %v", owners)
101
+ }
102
+ }
103
+
104
+ // TestTerminalKindGuardDetectsHandwrittenOwner proves the guard fires when a
105
+ // parallel handwritten TerminalKind owner regresses into the package.
106
+ func TestTerminalKindGuardDetectsHandwrittenOwner(t *testing.T) {
107
+ bad := map[string]string{
108
+ "server-invocation.go": "package srpc\n\n" +
109
+ "type TerminalKind int\n\n" +
110
+ "const (\n\tTerminalCommitted TerminalKind = iota\n)\n",
111
+ }
112
+ if owners := handwrittenTerminalKindOwners(t, bad); len(owners) == 0 {
113
+ t.Fatal("guard failed to flag a handwritten TerminalKind owner")
114
+ }
115
+ }
@@ -1,24 +1,6 @@
1
1
  package srpc
2
2
 
3
- import (
4
- "context"
5
- )
6
-
7
- // TerminalKind is the terminal state of a held unary invocation.
8
- type TerminalKind int
9
-
10
- const (
11
- // TerminalCommitted identifies an explicit remote CallData completion.
12
- TerminalCommitted TerminalKind = iota
13
- // TerminalCanceled identifies a remote CallCancel packet.
14
- TerminalCanceled
15
- // TerminalLost identifies a remote error or transport failure.
16
- TerminalLost
17
- // TerminalClosed identifies a bare remote close without completion.
18
- TerminalClosed
19
- // TerminalAbandoned identifies owner-context expiry without a remote terminal.
20
- TerminalAbandoned
21
- )
3
+ import "context"
22
4
 
23
5
  // ServerInvocation exposes the terminal of a held unary server invocation.
24
6
  type ServerInvocation interface {
@@ -1,10 +1,4 @@
1
- // TerminalKind is the terminal state of a held unary invocation.
2
- export type TerminalKind =
3
- | 'committed'
4
- | 'canceled'
5
- | 'transportLost'
6
- | 'closed'
7
- | 'abandoned'
1
+ import type { TerminalKind } from './rpcproto.pb.js'
8
2
 
9
3
  // ServerInvocation exposes the invocation signal and terminal wait.
10
4
  export class ServerInvocation implements AbortSignal {
@@ -4,7 +4,7 @@ import (
4
4
  "errors"
5
5
  "time"
6
6
 
7
- yamux "github.com/libp2p/go-yamux/v4"
7
+ yamux "github.com/libp2p/go-yamux/v5"
8
8
  )
9
9
 
10
10
  // yamuxStream wraps a yamux.Stream to implement MuxedStream.
package/srpc/websocket.go CHANGED
@@ -4,7 +4,7 @@ import (
4
4
  "context"
5
5
 
6
6
  "github.com/aperturerobotics/go-websocket"
7
- "github.com/libp2p/go-yamux/v4"
7
+ "github.com/libp2p/go-yamux/v5"
8
8
  )
9
9
 
10
10
  // NewWebSocketConn wraps a websocket into a MuxedConn.