
Security News
TC39 Advances 11 Proposals for Math Precision, Binary APIs, and More
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.
validata-mongo
Advanced tools
Type safe data validation and sanitization for MongoDB update $set
operations
using validata.
See validata for more details on validation functionality.
npm i validata validata-mongo
Given interfaces
interface MyObject {
required: string;
optional?: string;
child: Child;
}
interface Child {
foo: number;
bar: number;
}
And validata
const myCheck = isObjectSet<MyObject>({
required: isString(),
optional: maybeString(),
child: isObjectSet({
foo: isNumber({ min: 1 }),
bar: asNumber({ coerceMax: 10 }),
}),
});
Then
const result = check(myCheck, () => ({
required: 'blue',
child: {
foo: 1,
bar: 2,
},
}));
console.log(JSON.stringify(result));
// -> SUCCESS -> {"required":"blue","child":{"foo":1,"bar":2}}
const result = check(myCheck, () => ({
required: 'blue',
optional: 'red',
child: {
foo: 20,
bar: '20',
},
}));
console.log(JSON.stringify(result));
// -> SUCCESS -> {"required":"blue","optional":"red","child":{"foo":20,"bar":10}}
// NOTE child.bar has been converted to a number and coerced to a max of 10
const result = check(myCheck, () => ({
required: 'blue',
'child.foo': 3,
}));
console.log(JSON.stringify(result));
// -> SUCCESS -> {"required":"blue","child.foo":3}
const result = check(myCheck, () => ({
required: 'blue',
'child.bar': '73',
}));
console.log(JSON.stringify(result));
// -> SUCCESS -> {"required":"blue","child.bar":10}
// NOTE child.bar has been converted to a number and coerced to a max of 10
check(myCheck, () => ({
wow: 'blue',
}));
// -> ERROR -> {"issues":[{"path":["wow"],"value":"blue","reason":"unexpected-property"}],"name":"ValidationError"}
check(myCheck, () => ({
required: 'blue',
'child.unexpected': 17,
}));
// -> ERROR -> {"issues":[{"path":["child.unexpected"],"value":17,"reason":"unexpected-property"}],"name":"ValidationError"}
FAQs
MongoDB update `$set` operations
The npm package validata-mongo receives a total of 185 weekly downloads. As such, validata-mongo popularity was classified as not popular.
We found that validata-mongo 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.
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.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.