@cerbos/orm-prisma 1.1.0-alpha.1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +19 -19
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Cerbos + Prisma ORM Adapter
2
2
 
3
- An adapater library that takes a [Cerbos](https://cerbos.dev) Query Plan ([PlanResources API](https://docs.cerbos.dev/cerbos/latest/api/index.html#resources-query-plan)) response and converts it into a [Prisma](https://prisma.io) where class object. This is designed to work alongside a project using the [Cerbos Javascript SDK](https://github.com/cerbos/cerbos-sdk-javascript).
3
+ An adapter library that takes a [Cerbos](https://cerbos.dev) Query Plan ([PlanResources API](https://docs.cerbos.dev/cerbos/latest/api/index.html#resources-query-plan)) response and converts it into a [Prisma](https://prisma.io) where class object. This is designed to work alongside a project using the [Cerbos Javascript SDK](https://github.com/cerbos/cerbos-sdk-javascript).
4
4
 
5
5
  The following conditions are supported: `and`, `or`, `eq`, `ne`, `lt`, `gt`, `lte`, `gte` and `in`, as well as relational filters `some`, `none`, `is` and `isNot`.
6
6
 
@@ -18,6 +18,7 @@ Not Supported:
18
18
  - Composite keys
19
19
 
20
20
  ## Requirements
21
+
21
22
  - Cerbos > v0.16
22
23
  - `@cerbos/http` or `@cerbos/grpc` client
23
24
 
@@ -117,8 +118,8 @@ The `fieldNameMapper` is used to convert the field names in the query plan respo
117
118
  const filters = queryPlanToPrisma({
118
119
  queryPlan,
119
120
  fieldNameMapper: {
120
- "request.resource.attr.aFieldName": "prismaModelFieldName"
121
- }
121
+ "request.resource.attr.aFieldName": "prismaModelFieldName",
122
+ },
122
123
  });
123
124
 
124
125
  //or
@@ -126,18 +127,17 @@ const filters = queryPlanToPrisma({
126
127
  const filters = queryPlanToPrisma({
127
128
  queryPlan,
128
129
  fieldNameMapper: (fieldName: string): string => {
129
- if(fieldName.indexOf("request.resource.") > 0) {
130
- return fieldName.replace("request.resource.attr", "")
130
+ if (fieldName.indexOf("request.resource.") > 0) {
131
+ return fieldName.replace("request.resource.attr", "");
131
132
  }
132
133
 
133
- if(fieldName.indexOf("request.principal.") > 0) {
134
- return fieldName.replace("request.principal.attr", "")
134
+ if (fieldName.indexOf("request.principal.") > 0) {
135
+ return fieldName.replace("request.principal.attr", "");
135
136
  }
136
- }
137
+ },
137
138
  });
138
139
  ```
139
140
 
140
-
141
141
  The `relationMapper` is used to convert references to fields which are joins at the database level
142
142
 
143
143
  ```js
@@ -146,10 +146,10 @@ const filters = queryPlanToPrisma({
146
146
  fieldNameMapper: {},
147
147
  relationMapper: {
148
148
  "request.resource.attr.aRelatedModel": {
149
- "relation": "aRelatedModel",
150
- "field": "id" // the column it is joined on
151
- }
152
- }
149
+ relation: "aRelatedModel",
150
+ field: "id", // the column it is joined on
151
+ },
152
+ },
153
153
  });
154
154
 
155
155
  //or
@@ -158,16 +158,16 @@ const filters = queryPlanToPrisma({
158
158
  queryPlan,
159
159
  fieldNameMapper: {},
160
160
  relationMapper: (fieldName: string): string => {
161
- if(fieldName.indexOf("request.resource.") > 0) {
161
+ if (fieldName.indexOf("request.resource.") > 0) {
162
162
  return {
163
- "relation": fieldName.replace("request.resource.attr.", ""),
164
- "field": "id" // the column it is joined on
165
- }
163
+ relation: fieldName.replace("request.resource.attr.", ""),
164
+ field: "id", // the column it is joined on
165
+ };
166
166
  }
167
- }
167
+ },
168
168
  });
169
169
  ```
170
170
 
171
171
  ## Full Example
172
172
 
173
- A full Prisma application making use of this adapater can be found at [https://github.com/cerbos/express-prisma-cerbos](https://github.com/cerbos/express-prisma-cerbos)
173
+ A full Prisma application making use of this adapater can be found at [https://github.com/cerbos/express-prisma-cerbos](https://github.com/cerbos/express-prisma-cerbos)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cerbos/orm-prisma",
3
- "version": "1.1.0-alpha.1",
3
+ "version": "1.1.1",
4
4
  "homepage": "https://cerbos.dev",
5
5
  "description": "",
6
6
  "private": false,
@@ -25,12 +25,12 @@
25
25
  "@types/jest": "^29.0.3",
26
26
  "@types/node": "^18.7.21",
27
27
  "prisma": "^4.3.1",
28
- "ts-jest": "^28.0.8",
28
+ "ts-jest": "^29.0.0",
29
29
  "ts-node": "^10.4.0",
30
- "typescript": "^4.5.4"
30
+ "typescript": "^5.0.0"
31
31
  },
32
32
  "dependencies": {
33
- "@cerbos/core": "^0.5.1",
34
- "@cerbos/grpc": "^0.8.0"
33
+ "@cerbos/core": "^0.12.0",
34
+ "@cerbos/grpc": "^0.12.0"
35
35
  }
36
36
  }