@@ -6,27 +6,38 @@ import (
66 "github.com/storacha/go-ucanto/core/invocation"
77 "github.com/storacha/go-ucanto/core/ipld"
88 "github.com/storacha/go-ucanto/core/receipt/fx"
9+ "github.com/storacha/go-ucanto/core/result"
10+ "github.com/storacha/go-ucanto/core/result/failure"
911 "github.com/storacha/go-ucanto/server"
1012 "github.com/storacha/go-ucanto/server/transaction"
1113 "github.com/storacha/go-ucanto/ucan"
1214 "github.com/storacha/go-ucanto/validator"
1315)
1416
1517// HandlerFunc is an invocation handler function. It is different to
16- // [server.HandlerFunc] in that it allows an [RetrievalResponse ] to be returned,
18+ // [server.HandlerFunc] in that it allows an [Response ] to be returned,
1719// which for a retrieval server will determine the HTTP headers and body content
1820// of the HTTP response. The usual handler response (out and effects) are added
1921// to the X-Agent-Message HTTP header.
20- type HandlerFunc [C any , O ipld.Builder ] func (ctx context.Context , capability ucan.Capability [C ], invocation invocation.Invocation , context server.InvocationContext ) (O , fx.Effects , * RetrievalResponse , error )
22+ type HandlerFunc [C any , O ipld.Builder , X failure.IPLDBuilderFailure ] func (
23+ ctx context.Context ,
24+ capability ucan.Capability [C ],
25+ invocation invocation.Invocation ,
26+ context server.InvocationContext ,
27+ request Request ,
28+ ) (result result.Result [O , X ], fx fx.Effects , resp Response , err error )
2129
2230// Provide is used to define given capability provider. It decorates the passed
2331// handler and takes care of UCAN validation. It only calls the handler
2432// when validation succeeds.
25- func Provide [C any , O ipld.Builder ](capability validator.CapabilityParser [C ], handler HandlerFunc [C , O ]) ServiceMethod [O ] {
26- return func (ctx context.Context , inv invocation.Invocation , ictx server.InvocationContext ) (transaction.Transaction [O , ipld.Builder ], * RetrievalResponse , error ) {
27- var response * RetrievalResponse
28- method := server .Provide (capability , func (ctx context.Context , capability ucan.Capability [C ], inv invocation.Invocation , ictx server.InvocationContext ) (O , fx.Effects , error ) {
29- out , fx , res , err := handler (ctx , capability , inv , ictx )
33+ func Provide [C any , O ipld.Builder , X failure.IPLDBuilderFailure ](
34+ capability validator.CapabilityParser [C ],
35+ handler HandlerFunc [C , O , X ],
36+ ) ServiceMethod [O , failure.IPLDBuilderFailure ] {
37+ return func (ctx context.Context , inv invocation.Invocation , ictx server.InvocationContext , req Request ) (transaction.Transaction [O , failure.IPLDBuilderFailure ], Response , error ) {
38+ var response Response
39+ method := server .Provide (capability , func (ctx context.Context , capability ucan.Capability [C ], inv invocation.Invocation , ictx server.InvocationContext ) (result.Result [O , X ], fx.Effects , error ) {
40+ out , fx , res , err := handler (ctx , capability , inv , ictx , req )
3041 response = res
3142 return out , fx , err
3243 })
0 commit comments