@styra/ucast-prisma

License NPM Version

This package contains helpers for using UCAST conditions with Prisma queries.

This package can be used to add filtering to Prisma queries from UCAST conditions. The conditions returned by the Enterprise OPA Compile API look like this:

{
"conditions": {
"or": [
{ "tickets.resolved": false },
{ "users.name": "ceasar" }
]
}
}

A call to ucastToPrisma(conditions, "tickets") turns it into this Prisma query:

{
"OR": [
{
"resolved": {
"equals": false
}
},
{
"users": {
"name": {
"equals": "ceasar"
}
}
}
]
}

A similar translation for masking rules is provided through the mask helper: E.g. the mask rules returned from the Compile API,

{
"tickets.assignee": {
"replace": {
"value": "***"
}
},
"users.name": {
"replace": {
"value": "<username>"
}
}
}

can be applied to a Prisma-returned object like

{
"id": 200,
"assignee": "bob",
"users": {
"id": 10,
"name": "bobby"
}
}

via mask(maskRules, obj, "tickets"), masking the appropriate fields.

For questions, discussions and announcements related to Styra products, services and open source projects, please join the Styra community on Slack!