prisma-field-encryption
Advanced tools
Comparing version 1.2.0-beta.2 to 1.2.0
@@ -6,2 +6,3 @@ "use strict"; | ||
const errors_1 = require("./errors"); | ||
const supportedCursorTypes = ['Int', 'String']; | ||
function analyseDMMF(dmmf = client_1.Prisma.dmmf) { | ||
@@ -15,7 +16,19 @@ // todo: Make it robust against changes in the DMMF structure | ||
return allModels.reduce((output, model) => { | ||
var _a; | ||
const idField = model.fields.find(field => field.isId && ['Int', 'String'].includes(String(field.type))); | ||
var _a, _b; | ||
const idField = model.fields.find(field => field.isId && supportedCursorTypes.includes(String(field.type))); | ||
const cursorField = model.fields.find(field => { var _a; return (_a = field.documentation) === null || _a === void 0 ? void 0 : _a.includes('@encryption:cursor'); }); | ||
if (cursorField) { | ||
// Make sure custom cursor field is valid | ||
if (!cursorField.isUnique) { | ||
throw new Error(errors_1.errors.nonUniqueCursor(model.name, cursorField.name)); | ||
} | ||
if (!supportedCursorTypes.includes(String(cursorField.type))) { | ||
throw new Error(errors_1.errors.unsupportedCursorType(model.name, cursorField.name, String(cursorField.type))); | ||
} | ||
if ((_a = cursorField.documentation) === null || _a === void 0 ? void 0 : _a.includes('@encrypted')) { | ||
throw new Error(errors_1.errors.encryptedCursor(model.name, cursorField.name)); | ||
} | ||
} | ||
const modelDescriptor = { | ||
cursor: (_a = cursorField === null || cursorField === void 0 ? void 0 : cursorField.name) !== null && _a !== void 0 ? _a : idField === null || idField === void 0 ? void 0 : idField.name, | ||
cursor: (_b = cursorField === null || cursorField === void 0 ? void 0 : cursorField.name) !== null && _b !== void 0 ? _b : idField === null || idField === void 0 ? void 0 : idField.name, | ||
fields: model.fields.reduce((fields, field) => { | ||
@@ -22,0 +35,0 @@ const fieldConfig = parseAnnotation(field.documentation, model.name, field.name); |
@@ -9,2 +9,5 @@ import type { Prisma } from '@prisma/client'; | ||
decryptionErrorReport: (operation: string, errors: string[]) => string; | ||
nonUniqueCursor: (model: string, field: string) => string; | ||
unsupportedCursorType: (model: string, field: string, type: string) => string; | ||
encryptedCursor: (model: string, field: string) => string; | ||
noInteractiveTransactions: string; | ||
@@ -11,0 +14,0 @@ }; |
@@ -19,2 +19,9 @@ "use strict"; | ||
// Generator errors | ||
nonUniqueCursor: (model, field) => prefixError(`the cursor field ${model}.${field} should have a @unique attribute. | ||
Read more: https://github.com/47ng/prisma-field-encryption#custom-cursors`), | ||
unsupportedCursorType: (model, field, type) => prefixError(`the cursor field ${model}.${field} has an unsupported type ${type}. | ||
Only String and Int cursors are supported. | ||
Read more: https://github.com/47ng/prisma-field-encryption#custom-cursors`), | ||
encryptedCursor: (model, field) => prefixError(`the field ${model}.${field} cannot be used as a cursor as it is encrypted. | ||
Read more: https://github.com/47ng/prisma-field-encryption#custom-cursors`), | ||
noInteractiveTransactions: prefixError(`this generator requires enabling the \`interactiveTransactions\` preview feature on \`prisma-client-js\`: | ||
@@ -21,0 +28,0 @@ |
{ | ||
"name": "prisma-field-encryption", | ||
"version": "1.2.0-beta.2", | ||
"version": "1.2.0", | ||
"description": "Transparent field-level encryption at rest for Prisma", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
44736
769
1