Skip to content

Commit e8693bd

Browse files
committed
refactor: align response result accessor with receipt
1 parent fb5018e commit e8693bd

9 files changed

Lines changed: 25 additions & 25 deletions

File tree

client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (c *Client[Req, Res]) Execute(execRequest execution.Request) (execution.Res
6060
return nil, fmt.Errorf("missing receipt for task: %s", task.Link())
6161
}
6262
return execution.NewResponse(
63-
execution.WithResult(receipt.Out()),
63+
execution.WithOutcome(receipt.Out()),
6464
execution.WithMetadata(resContainer),
6565
)
6666
}

client/http_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestHTTPClient(t *testing.T) {
4444
res, err := c.Execute(execution.NewRequest(t.Context(), inv))
4545
require.NoError(t, err)
4646

47-
o, x := result.Unwrap(res.Result())
47+
o, x := result.Unwrap(res.Out())
4848
require.Nil(t, x)
4949
require.NotNil(t, o)
5050
require.Equal(t, "echo!", o.(ipld.Map)["message"])

examples/server_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func TestServer(t *testing.T) {
9898
}
9999

100100
result.MatchResultR0(
101-
resp.Result(),
101+
resp.Out(),
102102
func(o ipld.Any) {
103103
fmt.Printf("Echo response: %+v\n", o)
104104
},
@@ -189,7 +189,7 @@ func TestTypedServer(t *testing.T) {
189189
}
190190

191191
result.MatchResultR0(
192-
resp.Result(),
192+
resp.Out(),
193193
func(o ipld.Any) {
194194
args := types.EchoArguments{}
195195
err := datamodel.Rebind(datamodel.NewAny(o), &args)

execution/bindexec/handler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ func (r *Request[A]) Task() *Task[A] {
8787

8888
type ResponseOption[O Success] func(r *Response[O]) error
8989

90-
func WithResult[O Success](r result.Result[O, error]) ResponseOption[O] {
90+
func WithOutcome[O Success](out result.Result[O, error]) ResponseOption[O] {
9191
return func(resp *Response[O]) error {
92-
o, x := result.Unwrap(r)
92+
o, x := result.Unwrap(out)
9393
if x == nil {
9494
return WithSuccess(o)(resp)
9595
}
@@ -133,7 +133,7 @@ func WithFailure[O Success](x error) ResponseOption[O] {
133133
func WithMetadata[O Success](m ucan.Container) ResponseOption[O] {
134134
return func(r *Response[O]) error {
135135
exr, err := execution.NewResponse(
136-
execution.WithResult(r.Response.Result()),
136+
execution.WithOutcome(r.Response.Out()),
137137
execution.WithMetadata(m),
138138
)
139139
if err != nil {

execution/bindexec/handler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestHandler(t *testing.T) {
3535
require.NoError(t, err)
3636
require.NotNil(t, res)
3737

38-
o, x := result.Unwrap(res.Result())
38+
o, x := result.Unwrap(res.Out())
3939
require.Nil(t, x)
4040
require.NotNil(t, o)
4141
require.Equal(t, "testy", o.(datamodel.Map)["str"])

execution/dispatcher/dispatcher_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestDispatcher(t *testing.T) {
4444
resp, err := executor.Execute(execution.NewRequest(t.Context(), logInv))
4545
require.NoError(t, err)
4646

47-
_, x := result.Unwrap(resp.Result())
47+
_, x := result.Unwrap(resp.Out())
4848
require.Nil(t, x)
4949

5050
require.Len(t, messages, 1)
@@ -61,7 +61,7 @@ func TestDispatcher(t *testing.T) {
6161
resp, err = executor.Execute(execution.NewRequest(t.Context(), echoInv))
6262
require.NoError(t, err)
6363

64-
o, x := result.Unwrap(resp.Result())
64+
o, x := result.Unwrap(resp.Out())
6565
require.NotNil(t, o)
6666
require.Nil(t, x)
6767
t.Log(o)
@@ -84,7 +84,7 @@ func TestDispatcher(t *testing.T) {
8484
resp, err := executor.Execute(execution.NewRequest(t.Context(), inv))
8585
require.NoError(t, err)
8686

87-
o, x := result.Unwrap(resp.Result())
87+
o, x := result.Unwrap(resp.Out())
8888
require.Nil(t, o)
8989
require.NotNil(t, x)
9090
t.Log(x)
@@ -106,7 +106,7 @@ func TestDispatcher(t *testing.T) {
106106
resp, err := executor.Execute(execution.NewRequest(t.Context(), inv))
107107
require.NoError(t, err)
108108

109-
o, x := result.Unwrap(resp.Result())
109+
o, x := result.Unwrap(resp.Out())
110110
require.Nil(t, o)
111111
require.NotNil(t, x)
112112
t.Log(x)
@@ -132,7 +132,7 @@ func TestDispatcher(t *testing.T) {
132132
resp, err := executor.Execute(execution.NewRequest(t.Context(), logInv))
133133
require.NoError(t, err)
134134

135-
o, x := result.Unwrap(resp.Result())
135+
o, x := result.Unwrap(resp.Out())
136136
require.Nil(t, o)
137137
require.NotNil(t, x)
138138
t.Log(x)
@@ -157,7 +157,7 @@ func TestDispatcher(t *testing.T) {
157157
resp, err := executor.Execute(execution.NewRequest(t.Context(), logInv))
158158
require.NoError(t, err)
159159

160-
o, x := result.Unwrap(resp.Result())
160+
o, x := result.Unwrap(resp.Out())
161161
require.Nil(t, o)
162162
require.NotNil(t, x)
163163
t.Log(x)

execution/execution.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ type Request interface {
1717
}
1818

1919
type Response interface {
20-
// Result is the result of the task.
21-
Result() result.Result[ipld.Any, ipld.Any]
20+
// Out is the result of the task.
21+
Out() result.Result[ipld.Any, ipld.Any]
2222
// Metadata provides additional information about the response.
2323
Metadata() ucan.Container
2424
}

execution/response.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ import (
1010
)
1111

1212
type ExecResponse struct {
13-
result result.Result[ipld.Any, ipld.Any]
13+
out result.Result[ipld.Any, ipld.Any]
1414
metadata ucan.Container
1515
}
1616

1717
type ResponseOption func(r *ExecResponse) error
1818

19-
func WithResult(r result.Result[ipld.Any, ipld.Any]) ResponseOption {
19+
func WithOutcome(out result.Result[ipld.Any, ipld.Any]) ResponseOption {
2020
return func(resp *ExecResponse) error {
21-
resp.result = r
21+
resp.out = out
2222
return nil
2323
}
2424
}
2525

2626
func WithSuccess(o ipld.Any) ResponseOption {
2727
return func(resp *ExecResponse) error {
28-
resp.result = result.OK[ipld.Any, ipld.Any](o)
28+
resp.out = result.OK[ipld.Any, ipld.Any](o)
2929
return nil
3030
}
3131
}
@@ -46,7 +46,7 @@ func WithFailure(x error) ResponseOption {
4646
m["name"] = name
4747
m["message"] = x.Error()
4848
}
49-
resp.result = result.Error[ipld.Any, ipld.Any](ipld.Map(m))
49+
resp.out = result.Error[ipld.Any, ipld.Any](ipld.Map(m))
5050
return nil
5151
}
5252
}
@@ -59,7 +59,7 @@ func WithMetadata(m ucan.Container) ResponseOption {
5959
}
6060

6161
func NewResponse(options ...ResponseOption) (*ExecResponse, error) {
62-
response := ExecResponse{result: result.OK[ipld.Any, ipld.Any](datamodel.Map{})}
62+
response := ExecResponse{out: result.OK[ipld.Any, ipld.Any](datamodel.Map{})}
6363
for _, opt := range options {
6464
err := opt(&response)
6565
if err != nil {
@@ -73,6 +73,6 @@ func (r *ExecResponse) Metadata() ucan.Container {
7373
return r.metadata
7474
}
7575

76-
func (r *ExecResponse) Result() result.Result[ipld.Any, ipld.Any] {
77-
return r.result
76+
func (r *ExecResponse) Out() result.Result[ipld.Any, ipld.Any] {
77+
return r.out
7878
}

server/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (s *HTTPServer) RoundTrip(r *http.Request) (*http.Response, error) {
8989
receipt, err := receipt.Issue(
9090
s.id,
9191
inv.Task().Link(),
92-
res.Result(),
92+
res.Out(),
9393
receipt.WithCause(inv.Link()),
9494
)
9595
if err != nil {

0 commit comments

Comments
 (0)