
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
@sidewinder/validator
Advanced tools
This package provides JSON schema validation for the @sidewinder/type package. It is built upon Ajv and provides additional validation support for Uint8Array as well as void used in Sidewinder Contracts.
License MIT
$ npm install @sidewinder/validation
The following shows general usual
import { Validator } from '@sidewinder/validation'
import { Type } from '@sidewinder/type'
const T = Type.Object({
a: Type.String(),
b: Type.Number(),
c: Type.Boolean(),
d: Type.Uint8Array(),
e: Type.Void(),
})
const validator = new Validator(T)
validator.assert({
a: 'foo',
b: 1,
c: true,
d: new Uint8Array(),
e: null,
})
The assert function will check the given data and throws with a ValidatorError if the data fails to check.
import { Validator, ValidatorError } from '@sidewinder/validation'
const validator = new Validator(T)
try {
validator.assert({
a: 'foo',
b: 1,
c: true,
d: new Uint8Array(),
e: null,
})
} catch (error) {
if (error instanceof ValidatorError) {
console.log(error.errors)
console.log(error.message)
}
}
The check function will check the given data and return a ValidatorResult object containing the result of the validation. This can be used
to test the value without throwing.
import { Validator, ValidatorResult } from '@sidewinder/validation'
const validator = new Validator(T)
const result: ValidationResult = validator.check({
a: 'foo',
b: 1,
c: true,
d: new Uint8Array(),
e: null,
})
if (!result.success) {
console.log(result.errors)
console.log(result.message)
}
Sidewinder Validation supports schema referencing by appending the internal AJV schema compiler with additional schemas. Internally it maintains a singleton validation context that can be appended with additional schemas which allow the compiler to reference in downstream types. Because the compiler is singleton, each schema MUST have a unique $id across the entire application.
import { Compiler, Validator } from '@sidewinder/validation'
// -------------------------------------------------------------------
// Referenceable Schema
// -------------------------------------------------------------------
const T = Type.Object(
{
a: Type.String(),
b: Type.Number(),
c: Type.Boolean(),
d: Type.Uint8Array(),
e: Type.Void(),
},
{ $id: 'T' },
) // must be unique
Compiler.addSchema(T)
// -------------------------------------------------------------------
// Referenced Type
// -------------------------------------------------------------------
const R = Type.Ref(T)
const validator = new Validator(R)
// -------------------------------------------------------------------
// Check
// -------------------------------------------------------------------
const result = validator.check({
a: 'foo',
b: 1,
c: true,
d: new Uint8Array(),
e: null,
})
FAQs
Sidewinder Validator
We found that @sidewinder/validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers 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
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.