Socket
Socket
Sign inDemoInstall

@sanity/schema

Package Overview
Dependencies
Maintainers
7
Versions
1328
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/schema

## Terminology


Version published
Weekly downloads
101K
decreased by-29.35%
Maintainers
7
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

FAQs

Package last updated on 23 Mar 2017

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc