Skip to content

Commit 6c2dee9

Browse files
committed
refactor: IPLD map type
1 parent c5e78f9 commit 6c2dee9

13 files changed

Lines changed: 30 additions & 29 deletions

File tree

ipld/datamodel/map.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,5 +249,5 @@ func (m *Map) UnmarshalDagJSON(r io.Reader) (err error) {
249249
return nil
250250
}
251251

252-
var _ ipld.Map[string, ipld.Any] = (*Map)(nil)
253-
var _ ipld.MutableMap[string, ipld.Any] = (*Map)(nil)
252+
var _ ipld.Map = (*Map)(nil)
253+
var _ ipld.MutableMap = (*Map)(nil)

ipld/ipld.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,24 @@ import (
1919
// - Link ([cid.Cid])
2020
type Any = any
2121

22-
// Map is an IPLD map that supports any of the IPLD types for keys/values.
23-
type Map[K, V Any] interface {
22+
// Map is an IPLD map that supports any of the IPLD types for values. Keys MUST
23+
// be strings.
24+
type Map interface {
2425
// All is an iterator over all the key/value pairs in this map.
25-
All() iter.Seq2[K, V]
26+
All() iter.Seq2[string, Any]
2627
// Get a value for the given key. It returns false if the key does not exist
2728
// in the map.
28-
Get(k K) (V, bool)
29+
Get(k string) (Any, bool)
2930
// Keys is an iterator over the keys in this map.
30-
Keys() iter.Seq[K]
31+
Keys() iter.Seq[string]
3132
// Values is an iterator over the values in this map.
32-
Values() iter.Seq[V]
33+
Values() iter.Seq[Any]
3334
}
3435

3536
// MutableMap is a [Map] that supports changes.
36-
type MutableMap[K, V Any] interface {
37+
type MutableMap interface {
3738
// Set a value for the given key.
38-
Set(k K, v V)
39+
Set(k string, v Any)
3940
}
4041

4142
// Block is content addressed and encoded IPLD data.

testutil/args.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/stretchr/testify/require"
1010
)
1111

12-
func RandomArgs(t *testing.T) ipld.Map[string, any] {
12+
func RandomArgs(t *testing.T) ipld.Map {
1313
var list []string
1414
for range RandomBytes(t, 1)[0] {
1515
list = append(list, RandomCID(t).String())

ucan/delegation/delegation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (d *Delegation) Link() cid.Cid {
7373
// A map of arbitrary metadata, facts, and proofs of knowledge.
7474
//
7575
// https://github.com/ucan-wg/spec/blob/main/README.md#metadata
76-
func (d *Delegation) Metadata() ipld.Map[string, ipld.Any] {
76+
func (d *Delegation) Metadata() ipld.Map {
7777
if d.model.SigPayload.TokenPayload1_0_0_rc1.Meta == nil {
7878
return nil
7979
}

ucan/delegation/options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type delegationConfig struct {
1818
noexp bool
1919
nnc []byte
2020
nonnc bool
21-
meta ipld.Map[string, ipld.Any]
21+
meta ipld.Map
2222
pol policy.Policy
2323
}
2424

@@ -96,7 +96,7 @@ func WithNotBefore(nbf ucan.UTCUnixTimestamp) Option {
9696
}
9797

9898
// WithMetadata configures the arbitrary metadata for the UCAN.
99-
func WithMetadata(meta ipld.Map[string, ipld.Any]) Option {
99+
func WithMetadata(meta ipld.Map) Option {
100100
return func(cfg *delegationConfig) error {
101101
cfg.meta = meta
102102
return nil

ucan/delegation/policy/selector/selector.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func resolve(sel Selector, subject any, at []string) (any, []any, error) {
206206
}
207207
}
208208
return nil, many, nil
209-
} else if m, ok := cur.(ipld.Map[string, any]); ok {
209+
} else if m, ok := cur.(ipld.Map); ok {
210210
var many []any
211211
for k := range m.Keys() {
212212
v, _ := m.Get(k)
@@ -229,7 +229,7 @@ func resolve(sel Selector, subject any, at []string) (any, []any, error) {
229229
}
230230
} else if seg.Field != "" {
231231
at = append(at, seg.Field)
232-
if m, ok := cur.(ipld.Map[string, ipld.Any]); ok {
232+
if m, ok := cur.(ipld.Map); ok {
233233
v, ok := m.Get(seg.Field)
234234
if !ok && !seg.Optional {
235235
return nil, nil, NewResolutionError(fmt.Sprintf("object has no field named: %s", seg.Field), at)

ucan/delegation/policy/selector/selector_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ func TestSelect(t *testing.T) {
305305
require.NotEmpty(t, one)
306306
require.Empty(t, many)
307307

308-
user, ok := one.(ipld.Map[string, any])
308+
user, ok := one.(ipld.Map)
309309
require.True(t, ok)
310310
require.Equal(t, alice, user)
311311
})

ucan/invocation/arguments.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (n NoArguments) Values() iter.Seq[ipld.Any] {
3636
return func(func(ipld.Any) bool) {}
3737
}
3838

39-
var _ ipld.Map[string, ipld.Any] = (*NoArguments)(nil)
39+
var _ ipld.Map = (*NoArguments)(nil)
4040
var _ dagcbor.CBORMarshalable = (*NoArguments)(nil)
4141

4242
// UnknownArguments can be used when the arguments for an invocation cannot be

ucan/invocation/invocation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type Invocation struct {
3737
// Parameters expected by the command.
3838
//
3939
// https://github.com/ucan-wg/invocation/blob/main/README.md#arguments
40-
func (inv *Invocation) Arguments() ipld.Map[string, ipld.Any] {
40+
func (inv *Invocation) Arguments() ipld.Map {
4141
if inv.model.SigPayload.TokenPayload1_0_0_rc1.Args == nil {
4242
return datamodel.NewMap()
4343
}
@@ -105,7 +105,7 @@ func (inv *Invocation) Link() cid.Cid {
105105
// Arbitrary metadata or extensible fields.
106106
//
107107
// https://github.com/ucan-wg/invocation/blob/main/README.md#metadata
108-
func (inv *Invocation) Metadata() ipld.Map[string, ipld.Any] {
108+
func (inv *Invocation) Metadata() ipld.Map {
109109
if inv.model.SigPayload.TokenPayload1_0_0_rc1.Meta == nil {
110110
return nil
111111
}
@@ -266,7 +266,7 @@ func Invoke(
266266
issuer ucan.Signer,
267267
subject ucan.Subject,
268268
command ucan.Command,
269-
arguments ipld.Map[string, ipld.Any],
269+
arguments ipld.Map,
270270
options ...Option,
271271
) (*Invocation, error) {
272272
cfg := invocationConfig{}

ucan/invocation/options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type invocationConfig struct {
1616
noexp bool
1717
nnc []byte
1818
nonnc bool
19-
meta ipld.Map[string, ipld.Any]
19+
meta ipld.Map
2020
prf []cid.Cid
2121
iat *ucan.UTCUnixTimestamp
2222
cause *cid.Cid
@@ -65,7 +65,7 @@ func WithNoNonce() Option {
6565
}
6666

6767
// WithMetadata configures the arbitrary metadata for the UCAN.
68-
func WithMetadata(meta ipld.Map[string, ipld.Any]) Option {
68+
func WithMetadata(meta ipld.Map) Option {
6969
return func(cfg *invocationConfig) {
7070
cfg.meta = meta
7171
}

0 commit comments

Comments
 (0)