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