Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
@sanity/import
Advanced tools
Readme
Imports documents from an ndjson-stream to a Sanity dataset
npm install --save @sanity/import
const fs = require('fs')
const sanityClient = require('@sanity/client')
const sanityImport = require('@sanity/import')
const client = sanityClient({
projectId: '<your project id>',
dataset: '<your target dataset>',
token: '<token-with-write-perms>',
useCdn: false,
})
// Input can either be a readable stream (for a `.tar.gz` or `.ndjson` file), a folder location (string), or an array of documents
const input = fs.createReadStream('my-documents.ndjson')
const options = {
/**
* A Sanity client instance, preconfigured with the project ID and dataset
* you want to import data to, and with a token that has write access.
*/
client: client,
/**
* Which mutation type to use for creating documents:
* `create` (default) - throws error if document IDs already exists
* `createOrReplace` - replaces documents with same IDs
* `createIfNotExists` - skips document with IDs that already exists
*
* Optional.
*/
operation: 'create',
/**
* Function called when making progress. Gets called with an object of
* the following shape:
* `step` (string) - the current step name of the import process
* `current` (number) - the current progress of the step, only present on some steps
* `total` (number) - total items before complete, only present on some steps
*/
onProgress: (progress) => {
/* report progress */
},
/**
* Whether or not to allow assets in different datasets. This is usually
* an error in the export, where asset documents are part of the export.
*
* Optional, defaults to `false`.
*/
allowAssetsInDifferentDataset: false,
/**
* Whether or not to allow failing assets due to download/upload errors.
*
* Optional, defaults to `false`.
*/
allowFailingAssets: false,
/**
* Whether or not to replace any existing assets with the same hash.
* Setting this to `true` will regenerate image metadata on the server,
* but slows down the import.
*
* Optional, defaults to `false`.
*/
replaceAssets: false,
/**
* Whether or not to skip cross-dataset references. This may be required
* when importing a dataset with cross-dataset references to a different
* project, unless a dataset with the referenced name exists.
*
* Optional, defaults to `false`.
*/
skipCrossDatasetReferences: false,
/**
* Whether or not to import system documents (like permissions and custom retention). This
* is usually not necessary, and may cause conflicts if the target dataset
* already contains these documents. On a new dataset, it is recommended that roles are re-created
* manually, and that any custom retention policies are re-created manually.
*
* Optional, defaults to `false`.
*/
allowSystemDocuments: false,
}
sanityImport(input, options)
.then(({numDocs, warnings}) => {
console.log('Imported %d documents', numDocs)
// Note: There might be warnings! Check `warnings`
})
.catch((err) => {
console.error('Import failed: %s', err.message)
})
This functionality is built in to the @sanity/cli
package as well as a standalone @sanity/import-cli package.
MIT-licensed. See LICENSE.
FAQs
Import documents to a Sanity dataset
We found that @sanity/import demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 51 open source maintainers 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
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).