github.com/openfga/openfga@v1.5.4-rc1/pkg/storage/record.go (about)

     1  package storage
     2  
     3  import (
     4  	"time"
     5  
     6  	openfgav1 "github.com/openfga/api/proto/openfga/v1"
     7  	"google.golang.org/protobuf/types/known/structpb"
     8  	"google.golang.org/protobuf/types/known/timestamppb"
     9  
    10  	tupleutils "github.com/openfga/openfga/pkg/tuple"
    11  )
    12  
    13  // TupleRecord represents a record structure used
    14  // to store information about a specific tuple.
    15  type TupleRecord struct {
    16  	Store            string
    17  	ObjectType       string
    18  	ObjectID         string
    19  	Relation         string
    20  	User             string
    21  	ConditionName    string
    22  	ConditionContext *structpb.Struct
    23  	Ulid             string
    24  	InsertedAt       time.Time
    25  }
    26  
    27  // AsTuple converts a [TupleRecord] into a [*openfgav1.Tuple].
    28  func (t *TupleRecord) AsTuple() *openfgav1.Tuple {
    29  	return &openfgav1.Tuple{
    30  		Key: tupleutils.NewTupleKeyWithCondition(
    31  			tupleutils.BuildObject(t.ObjectType, t.ObjectID),
    32  			t.Relation,
    33  			t.User,
    34  			t.ConditionName,
    35  			t.ConditionContext,
    36  		),
    37  		Timestamp: timestamppb.New(t.InsertedAt),
    38  	}
    39  }