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

@sanity/export

Package Overview
Dependencies
Maintainers
44
Versions
1042
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/export

Export Sanity documents and assets

  • 3.32.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
124K
increased by1.21%
Maintainers
44
Weekly downloads
 
Created

What is @sanity/export?

@sanity/export is a utility for exporting data from a Sanity.io dataset. It allows you to export documents, assets, and other data from your Sanity project into a JSON file, which can be useful for backups, migrations, or transferring data between projects.

What are @sanity/export's main functionalities?

Exporting all documents

This feature allows you to export all documents from a specified dataset in your Sanity project. The exported data is saved to a JSON file.

const sanityClient = require('@sanity/client');
const exportDataset = require('@sanity/export');

const client = sanityClient({
  projectId: 'your-project-id',
  dataset: 'your-dataset-name',
  token: 'your-auth-token',
  useCdn: false
});

const options = {
  outputPath: './exported-data.json',
  dataset: 'your-dataset-name',
  client: client
};

exportDataset(options).then(() => {
  console.log('Export complete!');
}).catch((err) => {
  console.error('Export failed:', err);
});

Exporting specific document types

This feature allows you to export only specific types of documents from your dataset. In this example, only documents of type 'post' and 'author' are exported.

const sanityClient = require('@sanity/client');
const exportDataset = require('@sanity/export');

const client = sanityClient({
  projectId: 'your-project-id',
  dataset: 'your-dataset-name',
  token: 'your-auth-token',
  useCdn: false
});

const options = {
  outputPath: './exported-data.json',
  dataset: 'your-dataset-name',
  client: client,
  types: ['post', 'author']
};

exportDataset(options).then(() => {
  console.log('Export complete!');
}).catch((err) => {
  console.error('Export failed:', err);
});

Exporting with a query

This feature allows you to export documents based on a specific query. In this example, only published posts are exported.

const sanityClient = require('@sanity/client');
const exportDataset = require('@sanity/export');

const client = sanityClient({
  projectId: 'your-project-id',
  dataset: 'your-dataset-name',
  token: 'your-auth-token',
  useCdn: false
});

const options = {
  outputPath: './exported-data.json',
  dataset: 'your-dataset-name',
  client: client,
  query: '*[_type == "post" && published == true]'
};

exportDataset(options).then(() => {
  console.log('Export complete!');
}).catch((err) => {
  console.error('Export failed:', err);
});

Other packages similar to @sanity/export

Keywords

FAQs

Package last updated on 06 Mar 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