starpc 0.50.0 → 0.52.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 (100) hide show
  1. package/cmd/protoc-gen-es-starpc/typescript.ts +37 -0
  2. package/dist/cmd/protoc-gen-es-starpc/typescript.js +24 -0
  3. package/dist/echo/echo_srpc.pb.d.ts +44 -1
  4. package/dist/echo/server.d.ts +9 -8
  5. package/dist/echo/server.js +6 -6
  6. package/dist/integration/cross-language/ts-client.js +5 -79
  7. package/dist/integration/cross-language/ts-server.js +4 -100
  8. package/dist/mock/mock_srpc.pb.d.ts +14 -1
  9. package/dist/srpc/channel.js +6 -3
  10. package/dist/srpc/channel.test.js +20 -1
  11. package/dist/srpc/client.d.ts +1 -3
  12. package/dist/srpc/client.js +2 -22
  13. package/dist/srpc/common-rpc.d.ts +1 -9
  14. package/dist/srpc/common-rpc.js +4 -62
  15. package/dist/srpc/handler.d.ts +12 -4
  16. package/dist/srpc/index.d.ts +2 -4
  17. package/dist/srpc/index.js +1 -3
  18. package/dist/srpc/invoker.d.ts +2 -2
  19. package/dist/srpc/invoker.js +2 -2
  20. package/dist/srpc/rpcproto.pb.d.ts +0 -44
  21. package/dist/srpc/rpcproto.pb.js +0 -53
  22. package/dist/srpc/server-context.d.ts +11 -0
  23. package/dist/srpc/server-context.js +28 -0
  24. package/dist/srpc/server-rpc.js +3 -3
  25. package/dist/srpc/server.test.js +65 -2
  26. package/dist/srpc/watchdog.test.js +1 -0
  27. package/echo/echo.go +8 -8
  28. package/echo/echo.pb.go +12 -36
  29. package/echo/echo_srpc.pb.cpp +1 -1
  30. package/echo/echo_srpc.pb.go +1 -1
  31. package/echo/echo_srpc.pb.hpp +1 -1
  32. package/echo/echo_srpc.pb.rs +1 -1
  33. package/echo/echo_srpc.pb.ts +74 -0
  34. package/echo/server.go +1 -1
  35. package/echo/server.ts +24 -5
  36. package/go.mod +1 -1
  37. package/go.sum +2 -0
  38. package/integration/cross-language/go-client/main.go +4 -142
  39. package/integration/cross-language/go-server/main.go +2 -170
  40. package/integration/cross-language/run.bash +5 -105
  41. package/integration/cross-language/ts-client.ts +5 -90
  42. package/integration/cross-language/ts-server.ts +4 -112
  43. package/mock/mock.go +1 -1
  44. package/mock/mock.pb.go +12 -36
  45. package/mock/mock_srpc.pb.cpp +1 -1
  46. package/mock/mock_srpc.pb.go +1 -1
  47. package/mock/mock_srpc.pb.hpp +1 -1
  48. package/mock/mock_srpc.pb.rs +1 -1
  49. package/mock/mock_srpc.pb.ts +19 -1
  50. package/package.json +2 -2
  51. package/srpc/channel.test.ts +21 -1
  52. package/srpc/channel.ts +7 -3
  53. package/srpc/client-prefix.go +1 -1
  54. package/srpc/client-set.go +1 -1
  55. package/srpc/client.go +1 -1
  56. package/srpc/client.ts +4 -31
  57. package/srpc/common-rpc.go +15 -69
  58. package/srpc/common-rpc.ts +4 -77
  59. package/srpc/common-rpc_test.go +81 -0
  60. package/srpc/errors.go +26 -1
  61. package/srpc/handler.ts +54 -5
  62. package/srpc/index.ts +7 -4
  63. package/srpc/invoker-prefix.go +1 -1
  64. package/srpc/invoker.go +2 -2
  65. package/srpc/invoker.ts +20 -7
  66. package/srpc/message.go +1 -1
  67. package/srpc/msg-stream.go +1 -9
  68. package/srpc/mux-verbose.go +1 -1
  69. package/srpc/mux.go +1 -1
  70. package/srpc/rpcproto.pb.cc +4 -15
  71. package/srpc/rpcproto.pb.go +102 -419
  72. package/srpc/rpcproto.pb.h +0 -59
  73. package/srpc/rpcproto.pb.rs +0 -45
  74. package/srpc/rpcproto.pb.ts +0 -62
  75. package/srpc/rpcproto.proto +0 -16
  76. package/srpc/server-context.ts +55 -0
  77. package/srpc/server-rpc.go +1 -1
  78. package/srpc/server-rpc.ts +4 -6
  79. package/srpc/server.test.ts +94 -1
  80. package/srpc/stream-pipe.go +1 -1
  81. package/srpc/stream-rwc.go +1 -1
  82. package/srpc/stream.go +0 -20
  83. package/srpc/watchdog.test.ts +1 -0
  84. package/dist/rpcstream/receipt.test.d.ts +0 -1
  85. package/dist/rpcstream/receipt.test.js +0 -41
  86. package/dist/srpc/call-receipt.d.ts +0 -17
  87. package/dist/srpc/call-receipt.js +0 -106
  88. package/dist/srpc/call-receipt.test.d.ts +0 -1
  89. package/dist/srpc/call-receipt.test.js +0 -375
  90. package/dist/srpc/server-invocation.d.ts +0 -17
  91. package/dist/srpc/server-invocation.js +0 -37
  92. package/integration/cross-language/go-server/fixture-owner_test.go +0 -127
  93. package/srpc/call-receipt-e2e_test.go +0 -111
  94. package/srpc/call-receipt.go +0 -112
  95. package/srpc/call-receipt.test.ts +0 -441
  96. package/srpc/call-receipt.ts +0 -131
  97. package/srpc/call-receipt_test.go +0 -536
  98. package/srpc/schema-ownership_test.go +0 -115
  99. package/srpc/server-invocation.go +0 -40
  100. package/srpc/server-invocation.ts +0 -76
@@ -1,115 +0,0 @@
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,40 +0,0 @@
1
- package srpc
2
-
3
- import "context"
4
-
5
- // ServerInvocation exposes the terminal of a held unary server invocation.
6
- type ServerInvocation interface {
7
- // WaitTerminal waits for a remote terminal or owner-context expiry. The
8
- // owner context must outlive the invocation context.
9
- WaitTerminal(ownerCtx context.Context) (TerminalKind, error)
10
- // Done returns the invocation context cancellation channel for diagnostics.
11
- Done() <-chan struct{}
12
- }
13
-
14
- type serverInvocationKey struct{}
15
-
16
- func withServerInvocation(ctx context.Context, invocation ServerInvocation) context.Context {
17
- return context.WithValue(ctx, serverInvocationKey{}, invocation)
18
- }
19
-
20
- // GetServerInvocation returns the held unary invocation attached to a context.
21
- func GetServerInvocation(ctx context.Context) (ServerInvocation, bool) {
22
- if ctx == nil {
23
- return nil, false
24
- }
25
- invocation, ok := ctx.Value(serverInvocationKey{}).(ServerInvocation)
26
- return invocation, ok
27
- }
28
-
29
- // WaitTerminal waits for and classifies the terminal of a held unary invocation.
30
- func (r *ServerRPC) WaitTerminal(ownerCtx context.Context) (TerminalKind, error) {
31
- return r.commonRPC.WaitTerminal(ownerCtx)
32
- }
33
-
34
- // Done returns the invocation context cancellation channel for diagnostics.
35
- func (r *ServerRPC) Done() <-chan struct{} {
36
- return r.ctx.Done()
37
- }
38
-
39
- // _ is a type assertion.
40
- var _ ServerInvocation = (*ServerRPC)(nil)
@@ -1,76 +0,0 @@
1
- import type { TerminalKind } from './rpcproto.pb.js'
2
-
3
- // ServerInvocation exposes the invocation signal and terminal wait.
4
- export class ServerInvocation implements AbortSignal {
5
- public constructor(
6
- public readonly signal: AbortSignal,
7
- private readonly waitFn: (
8
- ownerSignal: AbortSignal,
9
- ) => Promise<TerminalKind>,
10
- ) {}
11
-
12
- public get aborted(): boolean {
13
- return this.signal.aborted
14
- }
15
-
16
- public get onabort() {
17
- return this.signal.onabort
18
- }
19
-
20
- public set onabort(value: typeof this.signal.onabort) {
21
- this.signal.onabort = value
22
- }
23
-
24
- public get reason() {
25
- return this.signal.reason
26
- }
27
-
28
- public throwIfAborted(): void {
29
- this.signal.throwIfAborted()
30
- }
31
-
32
- public addEventListener<K extends keyof AbortSignalEventMap>(
33
- type: K,
34
- listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => unknown,
35
- options?: boolean | AddEventListenerOptions,
36
- ): void
37
- public addEventListener(
38
- type: string,
39
- listener: EventListenerOrEventListenerObject,
40
- options?: boolean | AddEventListenerOptions,
41
- ): void
42
- public addEventListener(
43
- type: string,
44
- listener: EventListenerOrEventListenerObject,
45
- options?: boolean | AddEventListenerOptions,
46
- ): void {
47
- this.signal.addEventListener(type, listener, options)
48
- }
49
-
50
- public removeEventListener<K extends keyof AbortSignalEventMap>(
51
- type: K,
52
- listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => unknown,
53
- options?: boolean | EventListenerOptions,
54
- ): void
55
- public removeEventListener(
56
- type: string,
57
- listener: EventListenerOrEventListenerObject,
58
- options?: boolean | EventListenerOptions,
59
- ): void
60
- public removeEventListener(
61
- type: string,
62
- listener: EventListenerOrEventListenerObject,
63
- options?: boolean | EventListenerOptions,
64
- ): void {
65
- this.signal.removeEventListener(type, listener, options)
66
- }
67
-
68
- public dispatchEvent(event: Event): boolean {
69
- return this.signal.dispatchEvent(event)
70
- }
71
-
72
- // waitTerminal waits for a remote terminal or owner-signal cancellation.
73
- public waitTerminal(ownerSignal: AbortSignal): Promise<TerminalKind> {
74
- return this.waitFn(ownerSignal)
75
- }
76
- }