Skip to content

Commit 9a723ad

Browse files
committed
feat: declare command result types with Binding[Args, OK]
Carry each command's result type alongside its arguments by migrating declarations to commands.MustParse[*Args, *OK]. Handlers and clients then derive the result type from the command, so result/handler type mismatches are caught at compile time instead of at run time. Tracks the ucantone bind.Binding[Args, OK] change: fil-forge/ucantone#17
1 parent 851c11c commit 9a723ad

35 files changed

Lines changed: 42 additions & 39 deletions

commands/access/claim.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ type ClaimArguments = commands.Unit
88

99
// Claim can be invoked by an agent to claim a set of delegations from the
1010
// account.
11-
var Claim = commands.MustParse[*ClaimArguments]("/access/claim")
11+
var Claim = commands.MustParse[*ClaimArguments, *ClaimOK]("/access/claim")

commands/access/confirm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type ConfirmOK = ClaimOK
1717
const ConfirmMetaKey = "accessConfirm"
1818

1919
// Confirm can be invoked by an agent to confirm an access request.
20-
var Confirm = commands.MustParse[*ConfirmArguments]("/access/confirm")
20+
var Confirm = commands.MustParse[*ConfirmArguments, *ConfirmOK]("/access/confirm")
2121

2222
const (
2323
InvalidAccessConfirmSubjectErrorName = "InvalidAccessConfirmSubject"

commands/access/delegate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type DelegateOK = commands.Unit
88

99
// Delegate can be invoked by an agent to delegate a set of capabilities that
1010
// may be subsequently claimed by another agent.
11-
var Delegate = commands.MustParse[*DelegateArguments]("/access/delegate")
11+
var Delegate = commands.MustParse[*DelegateArguments, *DelegateOK]("/access/delegate")
1212

1313
const (
1414
DelegationNotFoundErrorName = "DelegationNotFound"

commands/access/grant.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type GrantOK = ClaimOK
1818
// Grant can be invoked by an agent to request that a set of capabilities be
1919
// granted directly. Unlike Request -> Confirm, Grant is one-shot: the
2020
// executor decides immediately whether to issue the delegation.
21-
var Grant = commands.MustParse[*GrantArguments](GrantCommand)
21+
var Grant = commands.MustParse[*GrantArguments, *GrantOK](GrantCommand)
2222

2323
const (
2424
UnknownAbilityErrorName = "UnknownAbility"

commands/access/request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const RequestMetaKey = "accessRequest"
1111

1212
// Request can be invoked by an agent to request set of capabilities from the
1313
// account.
14-
var Request = commands.MustParse[*RequestArguments]("/access/request")
14+
var Request = commands.MustParse[*RequestArguments, *RequestOK]("/access/request")
1515

1616
const (
1717
InvalidAuthorizationAccountErrorName = "InvalidAuthorizationAccount"

commands/assert/equals.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ import "github.com/fil-forge/libforge/commands"
77
type EqualsOK = commands.Unit
88

99
// Equals claims data is referred to by another CID e.g CAR CID & Piece CID
10-
var Equals = commands.MustParse[*EqualsArguments]("/assert/equals")
10+
var Equals = commands.MustParse[*EqualsArguments, *EqualsOK]("/assert/equals")

commands/assert/index.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ type IndexOK = commands.Unit
88

99
// Index claims that a content graph can be found in blob(s) that are identified
1010
// and indexed in the given index CID.
11-
var Index = commands.MustParse[*IndexArguments]("/assert/index")
11+
var Index = commands.MustParse[*IndexArguments, *IndexOK]("/assert/index")

commands/assert/location.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ import "github.com/fil-forge/libforge/commands"
66

77
type LocationOK = commands.Unit
88

9-
var Location = commands.MustParse[*LocationArguments]("/assert/location")
9+
var Location = commands.MustParse[*LocationArguments, *LocationOK]("/assert/location")

commands/bind.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package commands
22

3-
import "github.com/fil-forge/ucantone/validator/bindcom"
3+
import (
4+
"github.com/fil-forge/ucantone/bind"
5+
"github.com/fil-forge/ucantone/ucan"
6+
)
47

5-
// MustParse is like [bindcom.Parse] but panics if the command cannot be
8+
// MustParse is like [bind.Parse] but panics if the command cannot be
69
// constructed. It exists for package-level command declarations where the
710
// command and options are static — any error indicates a programming bug
811
// (malformed command string, invalid option) and should fail loudly at init
912
// rather than be silently dropped with `, _`.
10-
func MustParse[A bindcom.Arguments](cmd string) bindcom.Command[A] {
11-
c, err := bindcom.Parse[A](cmd)
13+
func MustParse[Args, OK ucan.CBORValue](cmd string) bind.Binding[Args, OK] {
14+
c, err := bind.Parse[Args, OK](cmd)
1215
if err != nil {
1316
panic(err)
1417
}

commands/blob/accept.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ package blob
44

55
import "github.com/fil-forge/libforge/commands"
66

7-
var Accept = commands.MustParse[*AcceptArguments]("/blob/accept")
7+
var Accept = commands.MustParse[*AcceptArguments, *AcceptOK]("/blob/accept")

0 commit comments

Comments
 (0)