New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@sanity/schema

Package Overview
Dependencies
Maintainers
67
Versions
1536
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/schema

3.70.0
Source
npm
Version published
Weekly downloads
199K
1.91%
Maintainers
67
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

sanity

FAQs

Package last updated on 14 Jan 2025

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