
Security News
pnpm 10.16 Adds New Setting for Delayed Dependency Updates
pnpm's new minimumReleaseAge setting delays package updates to prevent supply chain attacks, with other tools like Taze and NCU following suit.
@astro-content/validator
Advanced tools
A fail-safe way to ingest your project content.
pnpm astro add @astro-content/validator
—OR—
pnpm i @astro-content/validator
, then add to your astro.config.mjs
:
import { schemasToCheckers } from '@astro-content/validator';
export default defineConfig({
// ...
integrations: [
//...
schemasToCheckers({ outDir: 'src/checkers' }),
],
});
—OR—
Shallow clone demo project:
pnpx degit JulianCataldo/astro-content/packages/validator/demo ./ac-validator-demo
It will scan all src/**/*.schema.yaml
in the Astro project and generate associated runtime validator and static types.
outDir
: Central destination for the generated checkers.
Default: Nonesrc/checkers
, .astro-content/checkers
, .astro/checkers
…If you leave it blank, generated files will be colocated with their input schema, regardless of their containing directory (a bit like a TypeScript declaration file).
E.g. ./src/schemas/post.schema.yaml
→ ./src/schemas/post.checker.ts
Gist:
import { checkArticle } from '/src/checkers/article.checker';
const frontmatter = { title: 'Hello world' };
const { result: entry, errors } = await checkArticle(frontmatter);
console.log({ title: entry.title, errors });
if (errors) {
// We don't want to pursue…
}
// Or maybe we want to!
// E.g. You've set the `default` or `examples` fields as fallbacks,
// or you'll get valid, though fake data.
See also .remarkrc.yaml, wrong_entry-foo.md, blog-post.schema.yaml.
In Astro templates:
---
import { Code } from 'astro/components';
import { checkBlogPost } from '../checkers/blog-post.checker';
// Pre-validate all data upfront. This is not always wanted.
const blogPosts = await Astro.glob('/content/blog-posts/*.md').then((posts) =>
Promise.all(posts.map((post) => checkBlogPost(post.frontmatter))),
);
console.log(blogPosts);
---
<Code code={JSON.stringify(blogPosts, null, 2)} lang={'json'} />
[
{
"result": {
"title": "This is a cool title.",
"description": "My description is long enough to make the schema happy.\nMore text. More text. More text. More text. More text.\n"
},
"schema": {
// ...
}
},
{
"result": {
"title": "My untitled blog post",
"tags": ["Music"],
"description": "No description found."
},
"errors": [
{
"instancePath": "/tags/0",
"schemaPath": "#/allOf/0/properties/tags/items/type",
"keyword": "type",
"params": {
"type": "string"
},
"message": "must be string"
},
{
"instancePath": "/tags/0",
"schemaPath": "#/allOf/0/properties/tags/items/enum",
"keyword": "enum",
"params": {
"allowedValues": [
"Music",
"Video",
"Development",
"Cooking",
"Gardening",
"Sport"
]
},
"message": "must be equal to one of the allowed values"
},
{
"instancePath": "",
"schemaPath": "#/allOf/1/required",
"keyword": "required",
"params": {
"missingProperty": "description"
},
"message": "must have required property 'description'"
},
{
"instancePath": "/title",
"schemaPath": "#/allOf/1/properties/title/type",
"keyword": "type",
"params": {
"type": "string"
},
"message": "must be string"
}
],
"original": {
"title": 123456,
"tags": [123456]
},
"schema": {
// ...
}
}
]
See also the demo project to play with.
This library is thought primarly as an Astro project integration but in fact, you could use it with any JS / TS project of yours, and use the helpers in the browser, too.
Moreover, you might want to customize checker generation inside your workflow.
You can access these helpers with an API and the CLI too.
import { generateChecker, generateAllCheckers } from './schema-to-validator';
const outDir = 'src/checkers';
await generateAllCheckers(outDir);
const schemaPath = 'src/schemas/post.schema.yaml';
await generateChecker(schemaPath, outDir);
content-validator "<outdir (optional)>"
For the best experience, use these helpers in combination with remark-lint-frontmatter-schema.
But really, the two main reasons are that:
description
field).
Which means nice and insightful auto-completion.FAQs
A fail-safe way to ingest your project content.
We found that @astro-content/validator 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
pnpm's new minimumReleaseAge setting delays package updates to prevent supply chain attacks, with other tools like Taze and NCU following suit.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.