Remove hard-coded record types #132

Merged
ashwin merged 17 commits from deep-stack/laconicd-deprecated:ng-rm-record-types into main 2024-01-15 04:20:39 +00:00
4 changed files with 42 additions and 23 deletions
Showing only changes of commit c3e0102571 - Show all commits

View File

@ -121,7 +121,7 @@ func (q queryResolver) QueryRecords(ctx context.Context, attributes []*KeyValueI
res, err := nsQueryClient.ListRecords(
context.Background(),
&registrytypes.QueryListRecordsRequest{
Attributes: toRpcAttributes(attributes),
Attributes: toRPCAttributes(attributes),
All: (all != nil && *all),
},
)

View File

@ -256,43 +256,43 @@ func GetGQLAuction(auction *auctiontypes.Auction, bids []*auctiontypes.Bid) (*Au
return &gqlAuction, nil
}
func toRpcValue(value *ValueInput) *registrytypes.QueryListRecordsRequest_ValueInput {
func toRPCValue(value *ValueInput) *registrytypes.QueryListRecordsRequest_ValueInput {
var rpcval registrytypes.QueryListRecordsRequest_ValueInput
switch {
case value == nil:
return nil
case value.Int != nil:
rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Int{int64(*value.Int)}
rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Int{Int: int64(*value.Int)}
case value.Float != nil:
rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Float{*value.Float}
rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Float{Float: *value.Float}
case value.String != nil:
rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_String_{*value.String}
rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_String_{String_: *value.String}
case value.Boolean != nil:
rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Boolean{*value.Boolean}
rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Boolean{Boolean: *value.Boolean}
case value.Link != nil:
rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Link{value.Link.String()}
rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Link{Link: value.Link.String()}
case value.Array != nil:
var contents registrytypes.QueryListRecordsRequest_ArrayInput
for _, val := range value.Array {
contents.Values = append(contents.Values, toRpcValue(val))
contents.Values = append(contents.Values, toRPCValue(val))
}
rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Array{&contents}
rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Array{Array: &contents}
case value.Map != nil:
var contents registrytypes.QueryListRecordsRequest_MapInput
for _, kv := range value.Map {
contents.Values[kv.Key] = toRpcValue(kv.Value)
contents.Values[kv.Key] = toRPCValue(kv.Value)
}
rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Map{&contents}
rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Map{Map: &contents}
}
return &rpcval
}
func toRpcAttributes(attrs []*KeyValueInput) []*registrytypes.QueryListRecordsRequest_KeyValueInput {
func toRPCAttributes(attrs []*KeyValueInput) []*registrytypes.QueryListRecordsRequest_KeyValueInput {
kvPairs := []*registrytypes.QueryListRecordsRequest_KeyValueInput{}
for _, value := range attrs {
parsedValue := toRpcValue(value.Value)
parsedValue := toRPCValue(value.Value)
kvPair := &registrytypes.QueryListRecordsRequest_KeyValueInput{
Key: value.Key,
Value: parsedValue,

View File

@ -197,22 +197,40 @@ func QueryValueToJSON(input *types.QueryListRecordsRequest_ValueInput) ([]byte,
switch value := input.GetValue().(type) {
case *types.QueryListRecordsRequest_ValueInput_String_:
nb.AssignString(value.String_)
err := nb.AssignString(value.String_)
if err != nil {
return nil, err
}
case *types.QueryListRecordsRequest_ValueInput_Int:
nb.AssignInt(value.Int)
err := nb.AssignInt(value.Int)
if err != nil {
return nil, err
}
case *types.QueryListRecordsRequest_ValueInput_Float:
nb.AssignFloat(value.Float)
err := nb.AssignFloat(value.Float)
if err != nil {
return nil, err
}
case *types.QueryListRecordsRequest_ValueInput_Boolean:
nb.AssignBool(value.Boolean)
err := nb.AssignBool(value.Boolean)
if err != nil {
return nil, err
}
case *types.QueryListRecordsRequest_ValueInput_Link:
link := cidlink.Link{Cid: cid.MustParse(value.Link)}
nb.AssignLink(link)
err := nb.AssignLink(link)
if err != nil {
return nil, err
}
case *types.QueryListRecordsRequest_ValueInput_Array:
return nil, fmt.Errorf("Recursive query values are not supported")
return nil, fmt.Errorf("recursive query values are not supported")
case *types.QueryListRecordsRequest_ValueInput_Map:
return nil, fmt.Errorf("Recursive query values are not supported")
return nil, fmt.Errorf("recursive query values are not supported")
default:
return nil, fmt.Errorf("Value has unexpected type %T", value)
return nil, fmt.Errorf("value has unexpected type %T", value)
}
n := nb.Build()
@ -377,7 +395,7 @@ func (k Keeper) processAttributes(ctx sdk.Context, attrs types.AttributeMap, id
}
n := nb.Build()
if n.Kind() != ipld.Kind_Map {
return fmt.Errorf("Record attributes must be a map, not %T", n.Kind())
return fmt.Errorf("record attributes must be a map, not %T", n.Kind())
}
return k.processAttributeMap(ctx, n, id, prefix)
@ -385,6 +403,7 @@ func (k Keeper) processAttributes(ctx sdk.Context, attrs types.AttributeMap, id
func (k Keeper) processAttributeMap(ctx sdk.Context, n ipld.Node, id string, prefix string) error {
for it := n.MapIterator(); !it.Done(); {
//nolint:misspell
keynode, valuenode, err := it.Next()
if err != nil {
return err

View File

@ -99,7 +99,7 @@ func (r *Record) ToReadableRecord() ReadableRecord {
func (r *ReadableRecord) CanonicalJSON() []byte {
bytes, err := canonicaljson.Marshal(r.Attributes)
if err != nil {
panic("error marshalling record: " + err.Error())
panic("error marshaling record: " + err.Error())
}
return bytes