Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
BuckleScript bindings to Ajv (Another JSON Validator)
To be able to use standardized validation schemas across our JavaScript and BuckleScript based code.
yarn add bs-ajv
bsconfig.json
{
"dependencies": [ "bs-ajv" ]
}
The interface here is a bit rough, but it is usable and is used within production. Here are a few examples pulled from the Ajv docs.
let schema = Json.Encode.(object_([
("properties", object_([
("smaller", object_([
("type", string("number")),
("maximum", object_([
("$data", string("1/larger")),
])),
])),
("larger", object_([
("type", string("number")),
])),
])),
]));
let validData = Json.Encode.(object_([
("smaller", int(5)),
("larger", int(7)),
]));
AjvOptions.make()
|> AjvOptions.setData(_, Js.true_)
|> Ajv.ajv
|> Ajv.validate(`Schema(schema), validData)
/* This will return `Js.true_` */
let schema = Json.Encode.(object_([
("additionalProperties", object_([
("type", string("string")),
("format", object_([ ("$data", string("0#")) ]))
])),
]));
let validData = Json.Encode.(object_([
("date-time", string("1963-06-19T08:30:06.283185Z")),
("email", string("joe.bloggs@example.com")),
]));
AjvOptions.make()
|> AjvOptions.setData(_, Js.true_)
|> Ajv.ajv
|> Ajv.validate(`Schema(schema), validData)
/* This will return `Js.true_` */
let schema = Json.Encode.(object_([
("additionalProperties", bool(false)),
("properties", object_([
("foo", object_([
("type", string("number")),
])),
("bar", object_([
("baz", object_([
("type", string("string")),
])),
])),
])),
]));
let validData = Json.Encode.(object_([
("foo", int(0)),
("additional1", int(1)),
("bar", object_([
("baz", string("abc")),
("additional2", int(2)),
])),
]));
AjvOptions.make()
|> AjvOptions.removeAdditional(_, Js.true_)
|> Ajv.ajv
|> Ajv.compile(schema)
|> (fun
| `Sync(fn) => fn
| `Async(_) => failwith("unexpected_async_mode")
)
|> (v) => validate(validData)
|> (fun
| `Valid(_) => Js.true_
| `Invalid(_) => Js.false_
)
/* This will return `Js.true_`
FAQs
BucklesScript bindings to Ajv (Another JSON Validator)
The npm package bs-ajv receives a total of 43 weekly downloads. As such, bs-ajv popularity was classified as not popular.
We found that bs-ajv demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.