
Research
/Security News
Malicious npm Packages Target WhatsApp Developers with Remote Kill Switch
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
prismavalidator
Advanced tools
The validator function is a utility designed to ensure that the data being passed to the API endpoint conforms to the required format and data types. It checks for the presence of all required fields and verifies that the data types of these fields are co
Prisma Validate is a JavaScript library that allows you to easily validate your data against a Prisma schema. It helps you ensure that your data is consistent with the types and requirements defined in your Prisma schema, making it easier to prevent errors and improve the quality of your data.
install Prisma Validate, run the following command in your terminal:
npm install prismavalidator
The validate function takes in the following arguments:
The function returns an object with the following properties:
To use Prisma Validate, you'll need to import the validateModel function and pass in your Prisma client instance, the name of the model you want to validate, and the data you want to validate. Optionally, you can also pass in an array of fields to omit from the validation process.
const { PrismaClient } = require("@prisma/client");
const prisma = new PrismaClient();
const { validateModel } = require("prisma-validate");
const result = validateModel(
//instance of prisma
prisma,
//name of model
"User",
//data to validate
{
name: "John",
email: "john@example.com",
age: 30,
},
//attributes to omit
["id"]
);
The validateModel function will return an object containing two keys: invalidFields and missingFields. invalidFields is an array of objects, each representing a field with an incorrect type. missingFields is an array of strings, representing the names of required fields that are missing in the data.
console.log(result);
// {
// invalidFields: [],
// invalidFieldsArray: [],
// missingFields: []
// error: ""
// isValid: bool
// }
You can specify custom validation rules by passing in an additional configuration object as the fourth parameter. This object should have keys that correspond to the field names in your model and values that are functions that return a boolean value.
Note: The validateModel function currently only supports minLength and maxLength validation for string fields, and regex validation for any field type. More validation rules can be easily added as needed.
const data = {
name: "John",
email: "john@example.com",
password: "password",
};
const configuration = {
name: {
minLength: 2,
maxLength: 50,
regex: "/^[A-Z]{3}$/",
},
email: {
minLength: 5,
maxLength: 50,
},
password: {
minLength: 8,
maxLength: 50,
},
};
const validationResult = validateModel(
prisma,
"User",
data,
["id"],
configuration
);
const data = {
name: "Hanis",
email: "John@gmail.com",
password: "short",
};
const configuration = {
name: {
minLength: 10,
maxLength: 50,
regex: "/^[A-Z]{3}$/",
},
email: {
minLength: 20,
maxLength: 50,
},
password: {
minLength: 3,
maxLength: 50,
},
};
const result = validateModel(prisma, "User", data, configuration);
console.log(result);
Output:
{
invalidFields: [
{
model: 'User',
fieldName: 'name',
error: 'Field does not match required pattern'
},
{
model: 'User',
fieldName: 'email',
error: 'Field does not meet minimum length requirement of 20'
}
],
invalidFieldsArray: [ 'name', 'email', 'password' ],
missingFields: [],
error: "Validation failed for the following field(s): firstname, lastname, type, ministryId, name",
isValid:false
}
Hanis Hapsa
To report any bug or suggest a feature update, kindly join the discord channel below. (https://discord.gg/kpyXeneeVq)
FAQs
The validator function is a utility designed to ensure that the data being passed to the API endpoint conforms to the required format and data types. It checks for the presence of all required fields and verifies that the data types of these fields are co
The npm package prismavalidator receives a total of 0 weekly downloads. As such, prismavalidator popularity was classified as not popular.
We found that prismavalidator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
Research
/Security News
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.