open-index/open-npm huggingface dataset:
npm package: @open-policy-agent/ucast-prisma
Description: Interpreter for using ucast conditions with Prisma.
Author: The OPA Authors
Latest version: 0.1.6

# @open-policy-agent/ucast-prisma

[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![NPM Version](https://img.shields.io/npm/v/%40open-policy-agent%2Fucast-prisma?style=flat&color=%2324b6e0)](https://www.npmjs.com/package/@open-policy-agent/ucast-prisma)

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


## Usage

This package can be used to add filtering to Prisma queries from UCAST conditions.
The conditions returned by the [EOPA](https://github.com/open-policy-agent/eopa) Compile API look like this:

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

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

```json
{
  "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,

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

can be applied to a Prisma-returned object like

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

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


## Community

For questions, discussions and announcements related to this project, please join Slack!