Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import config from 'config:sanity'
import configureClient from 'part:@sanity/base/configure-client?'
import sanityClient from '@sanity/client'
const deprecationMessage = `[deprecation] The Sanity client is now exposed in CommonJS format.
For instance, change:
\`const client = require('part:@sanity/base/client').default\`
To the following:
\`const client = require('part:@sanity/base/client')\`
`
const fallbackConfig = {projectId: 'UNSPECIFIED', dataset: 'UNSPECIFIED'}
const apiConfig = {...fallbackConfig, ...config.api, withCredentials: true, useCdn: false}
const client = sanityClient(apiConfig)
const configuredClient = configureClient ? configureClient(sanityClient(apiConfig)) : client
// Warn when people use `.default`
Object.defineProperty(configuredClient, 'default', {
get() {
// eslint-disable-next-line no-console
console.warn(deprecationMessage)
return configuredClient
}
})
// Expose as CJS to allow Node scripts to consume it without `.default`
// eslint-disable-next-line import/no-commonjs
module.exports = configuredClient
import sanityClient from '@sanity/client'
const deprecationMessage = `[deprecation] The Sanity client is now exposed in CommonJS format.
For instance, change:
\`const client = require('part:@sanity/base/client').default\`
To the following:
\`const client = require('part:@sanity/base/client')\`
`
const fallbackConfig = {projectId: 'UNSPECIFIED', dataset: 'UNSPECIFIED'}
const apiConfig = {...fallbackConfig, ...config.api, withCredentials: true, useCdn: false}
const client = sanityClient(apiConfig)
const configuredClient = configureClient ? configureClient(sanityClient(apiConfig)) : client
// Warn when people use `.default`
Object.defineProperty(configuredClient, 'default', {
get() {
// eslint-disable-next-line no-console
console.warn(deprecationMessage)
return configuredClient
}
})
// Expose as CJS to allow Node scripts to consume it without `.default`
// eslint-disable-next-line import/no-commonjs
module.exports = configuredClient
get client() {
return sanityClient(this.sanityOptions)
}
export default async function strengthenReferences(options) {
const {importId, dataset} = options
const progress = options.progress || noop
const timeout = 605000
const concurrency = 10
const client = sanityClient(Object.assign({}, options.client.config(), {dataset, timeout}))
const getReferenceDoc = ({prevImportMapId}) =>
client.fetch(importMapQuery, {importId, prevImportMapId}).then(docs => docs[0])
let referenceDoc = await getReferenceDoc({prevImportMapId: 'none'})
while (referenceDoc) {
debug('Found refmap with ID %s, processing', referenceDoc._id)
await promiseEach(referenceDoc.referenceMaps, unsetRefMapKeys, {concurrency})
debug('Unset weak flag within %d documents', referenceDoc.referenceMaps.length)
debug('Deleting refmap with ID %s', referenceDoc._id)
await client.delete(referenceDoc._id)
referenceDoc = await getReferenceDoc({prevImportMapId: referenceDoc._id})
progress(referenceDoc.referenceMaps.length)
}