Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sanity/schema

Package Overview
Dependencies
Maintainers
62
Versions
1375
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/schema

  • 3.62.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
284K
increased by95.45%
Maintainers
62
Weekly downloads
 
Created

What is @sanity/schema?

@sanity/schema is a package used to define and manage schemas for Sanity, a platform for structured content. It allows developers to create and validate content models, which can then be used to structure and manage content in a Sanity project.

What are @sanity/schema's main functionalities?

Define Document Schema

This feature allows you to define a document schema with various fields. In this example, a 'post' document type is defined with 'title' and 'body' fields.

const schema = require('@sanity/schema');

const mySchema = schema.compile({
  name: 'mySchema',
  types: [
    {
      name: 'post',
      type: 'document',
      fields: [
        {name: 'title', type: 'string'},
        {name: 'body', type: 'text'}
      ]
    }
  ]
});

Define Object Schema

This feature allows you to define an object schema. In this example, an 'author' object type is defined with 'name' and 'bio' fields.

const schema = require('@sanity/schema');

const mySchema = schema.compile({
  name: 'mySchema',
  types: [
    {
      name: 'author',
      type: 'object',
      fields: [
        {name: 'name', type: 'string'},
        {name: 'bio', type: 'text'}
      ]
    }
  ]
});

Validation

This feature allows you to add validation rules to your schema fields. In this example, the 'title' field is required and must be at least 10 characters long, while the 'body' field is also required.

const schema = require('@sanity/schema');

const mySchema = schema.compile({
  name: 'mySchema',
  types: [
    {
      name: 'post',
      type: 'document',
      fields: [
        {name: 'title', type: 'string', validation: Rule => Rule.required().min(10)},
        {name: 'body', type: 'text', validation: Rule => Rule.required()}
      ]
    }
  ]
});

Other packages similar to @sanity/schema

Keywords

FAQs

Package last updated on 24 Oct 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc