Skip to content

Commit

Permalink
Add translator and generator support for new functioned arrows
Browse files Browse the repository at this point in the history
  • Loading branch information
josephschorr committed Jun 27, 2024
1 parent ff3289a commit 7aa3232
Show file tree
Hide file tree
Showing 9 changed files with 1,718 additions and 319 deletions.
33 changes: 33 additions & 0 deletions pkg/namespace/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,39 @@ func TupleToUserset(tuplesetRelation, usersetRelation string) *core.SetOperation
}
}

// MustFunctionedTupleToUserset creates a child which first loads all tuples with the specific relation,
// and then applies the function to all children on the usersets found by following a relation on those loaded
// tuples.
func MustFunctionedTupleToUserset(tuplesetRelation, functionName, usersetRelation string) *core.SetOperation_Child {
function := core.FunctionedTupleToUserset_FUNCTION_ANY

switch functionName {
case "any":
function = core.FunctionedTupleToUserset_FUNCTION_ANY

case "all":
function = core.FunctionedTupleToUserset_FUNCTION_ALL

default:
panic(spiceerrors.MustBugf("unknown function name: %s", functionName))
}

return &core.SetOperation_Child{
ChildType: &core.SetOperation_Child_FunctionedTupleToUserset{
FunctionedTupleToUserset: &core.FunctionedTupleToUserset{
Function: function,
Tupleset: &core.FunctionedTupleToUserset_Tupleset{
Relation: tuplesetRelation,
},
ComputedUserset: &core.ComputedUserset{
Relation: usersetRelation,
Object: core.ComputedUserset_TUPLE_USERSET_OBJECT,
},
},
},
}
}

// Rewrite wraps a rewrite as a set operation child of another rewrite.
func Rewrite(rewrite *core.UsersetRewrite) *core.SetOperation_Child {
return &core.SetOperation_Child{
Expand Down
Loading

0 comments on commit 7aa3232

Please sign in to comment.