index int64 0 0 | repo_id stringlengths 16 181 | file_path stringlengths 28 270 | content stringlengths 1 11.6M | __index_level_0__ int64 0 10k |
|---|---|---|---|---|
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import | petrpan-code/sanity-io/sanity/packages/@sanity/import/src/serializePath.js | module.exports = function serializePath(item) {
return item.path.reduce((target, part, i) => {
const isIndex = typeof part === 'number'
const isNumericStringKey = !isIndex && isFinite(part)
const seperator = i === 0 ? '' : '.'
if (!isIndex && !isNumericStringKey) {
return `${target}${seperator}$... | 2,000 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import | petrpan-code/sanity-io/sanity/packages/@sanity/import/src/uploadAssets.js | const basename = require('path').basename
const parseUrl = require('url').parse
const debug = require('debug')('sanity:import')
const pMap = require('p-map')
const {isSanityImageUrl} = require('@sanity/asset-utils')
const progressStepper = require('./util/progressStepper')
const getHashedBufferForUri = require('./util/... | 2,001 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import | petrpan-code/sanity-io/sanity/packages/@sanity/import/src/validateAssetDocuments.js | const debug = require('debug')('sanity:import:asset-validation')
const {generateHelpUrl} = require('@sanity/generate-help-url')
const pMap = require('p-map')
const urlExists = require('./util/urlExists')
const DEFAULT_VERIFY_CONCURRENCY = 12
const REQUIRED_PROPERTIES = {
_id: 'string',
_type: 'string',
assetId: ... | 2,002 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import | petrpan-code/sanity-io/sanity/packages/@sanity/import/src/validateCdrDatasets.js | const {get} = require('lodash')
const {extractWithPath} = require('@sanity/mutator')
module.exports = async function validateCdrDatasets(docs, options) {
const datasets = getDatasetsFromCrossDatasetReferences(docs)
if (datasets.length === 0) {
return
}
const {client} = options
const existing = (await cl... | 2,003 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import | petrpan-code/sanity-io/sanity/packages/@sanity/import/src/validateOptions.js | const fs = require('fs')
const noop = require('lodash/noop')
const defaults = require('lodash/defaults')
const clientMethods = ['fetch', 'transaction', 'config']
const allowedOperations = ['create', 'createIfNotExists', 'createOrReplace']
const defaultOperation = allowedOperations[0]
function validateOptions(input, o... | 2,004 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/src | petrpan-code/sanity-io/sanity/packages/@sanity/import/src/util/ensureUniqueIds.js | function reduceDuplicateIds(ids, doc) {
if (!doc._id) {
return ids
}
if (ids.seen.includes(doc._id)) {
ids.duplicates.push(doc._id)
} else {
ids.seen.push(doc._id)
}
return ids
}
module.exports = function ensureUniqueIds(documents) {
const {duplicates} = documents.reduce(reduceDuplicateIds,... | 2,005 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/src | petrpan-code/sanity-io/sanity/packages/@sanity/import/src/util/getHashedBufferForUri.js | const crypto = require('crypto')
const {URL} = require('url')
const miss = require('mississippi')
const getUri = require('get-uri')
const {getIt} = require('get-it')
const {promise} = require('get-it/middleware')
const retryOnFailure = require('./retryOnFailure')
const request = getIt([promise()])
module.exports = (... | 2,006 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/src | petrpan-code/sanity-io/sanity/packages/@sanity/import/src/util/getJsonStreamer.js | const split = require('split2')
const documentHasErrors = require('../documentHasErrors')
module.exports = function getJsonStreamer() {
let lineNumber = 0
return split(parseRow)
function parseRow(row) {
lineNumber++
if (!row) {
return undefined
}
try {
const doc = JSON.parse(row)
... | 2,007 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/src | petrpan-code/sanity-io/sanity/packages/@sanity/import/src/util/progressStepper.js | function progressStepper(onProgress, options) {
let current = -1
// Stepper function which increments progress up to defined total and returns
// input argument verbatim so it may be used in the middle of a promise chain
const step = (inp) => {
onProgress({
step: options.step,
total: options.to... | 2,008 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/src | petrpan-code/sanity-io/sanity/packages/@sanity/import/src/util/readJson.js | const {readFile} = require('fs/promises')
module.exports = async function readJson(filePath) {
const file = await readFile(filePath, 'utf8')
return JSON.parse(file)
}
| 2,009 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/src | petrpan-code/sanity-io/sanity/packages/@sanity/import/src/util/retryOnFailure.js | /* eslint-disable no-await-in-loop, max-depth, consistent-return */
const debug = require('debug')('sanity:import')
const {defaults} = require('lodash')
module.exports = async function retryOnFailure(op, opts = {}) {
const options = defaults({}, opts, {delay: 150, maxTries: 3, isRetriable: () => true})
for (let a... | 2,010 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/src | petrpan-code/sanity-io/sanity/packages/@sanity/import/src/util/rimraf.js | const {promisify} = require('util')
const rimrafCb = require('rimraf')
module.exports = promisify(rimrafCb)
| 2,011 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/src | petrpan-code/sanity-io/sanity/packages/@sanity/import/src/util/suffixTag.js | module.exports = (tag, suffix) => `${tag.replace(/\.+$/, '')}.${suffix}`
| 2,012 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/src | petrpan-code/sanity-io/sanity/packages/@sanity/import/src/util/urlExists.js | const https = require('https')
const parseUrl = require('url').parse
const MAX_RETRIES = 5
function getStatusCodeForUrl(url) {
const options = {...parseUrl(url), method: 'HEAD'}
return new Promise((resolve, reject) => {
const req = https.request(options, (res) => {
res.resume()
resolve(res.statusC... | 2,013 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import | petrpan-code/sanity-io/sanity/packages/@sanity/import/test/.eslintrc | {
"env": {
"node": true,
"browser": false
}
}
| 2,014 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import | petrpan-code/sanity-io/sanity/packages/@sanity/import/test/import.test.js | /* eslint-disable no-sync */
const fs = require('fs')
const path = require('path')
const {createClient} = require('@sanity/client')
const importer = require('../src/import')
const {getSanityClient} = require('./helpers')
const defaultClient = createClient({
apiVersion: '1',
projectId: 'foo',
dataset: 'bar',
us... | 2,015 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import | petrpan-code/sanity-io/sanity/packages/@sanity/import/test/retryOnFailure.test.js | const retryOnFailure = require('../src/util/retryOnFailure')
describe('retry on failure utility', () => {
test('does not retry on initial success', async () => {
const fn = jest.fn()
fn.mockReturnValueOnce(Promise.resolve('hei'))
expect(await retryOnFailure(fn)).toEqual('hei')
expect(fn).toHaveBeenC... | 2,016 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import | petrpan-code/sanity-io/sanity/packages/@sanity/import/test/uploadAssets.test.js | const path = require('path')
const fileUrl = require('file-url')
const noop = require('lodash/noop')
const nock = require('nock')
const uploadAssets = require('../src/uploadAssets')
const mockAssets = require('./fixtures/mock-assets')
const {getSanityClient} = require('./helpers')
const fixturesDir = path.join(__dirna... | 2,017 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/test | petrpan-code/sanity-io/sanity/packages/@sanity/import/test/__snapshots__/import.test.js.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`accepts a stream as source: employee creation 1`] = `
Object {
"mutations": Array [
Object {
"create": Object {
"_id": "espen",
"_type": "employee",
"name": "Espen",
},
},
Object {
"create": Object {
"_i... | 2,018 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/test | petrpan-code/sanity-io/sanity/packages/@sanity/import/test/__snapshots__/uploadAssets.test.js.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`fails if asset download fails 1`] = `
[Error: Failed to download image @ http://127.0.0.1:49999/img.gif:
connect ECONNREFUSED 127.0.0.1:49999]
`;
exports[`will reuse an existing asset if it exists: single asset mutation 1`] = `
Object {
"mutations": Array [
Ob... | 2,019 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/test | petrpan-code/sanity-io/sanity/packages/@sanity/import/test/fixtures/duplicate-ids.ndjson | {"_id": "espen", "_type": "employee", "name": "Espen"}
{"_id": "pk", "_type": "employee", "name": "Per-Kristian"}
{"_type": "nondupe", "dummy": "value"}
{"_type": "nondupe", "dummy": "value"}
{"_type": "nondupe", "dummy": "value"}
{"_type": "nondupe", "dummy": "value"}
{"_type": "nondupe", "dummy": "value"}
{"_type": "... | 2,020 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/test | petrpan-code/sanity-io/sanity/packages/@sanity/import/test/fixtures/employees.ndjson | {"_id": "espen", "_type": "employee", "name": "Espen"}
{"_id": "pk", "_type": "employee", "name": "Per-Kristian"}
| 2,021 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/test | petrpan-code/sanity-io/sanity/packages/@sanity/import/test/fixtures/invalid-id-format.ndjson | {"_id": "espen", "_type": "employee", "name": "Espen"}
{"_id": "pk#123", "_type": "employee", "name": "Per-Kristian"}
{"_id": "Even", "_type": "employee", "name": "Even"}
| 2,022 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/test | petrpan-code/sanity-io/sanity/packages/@sanity/import/test/fixtures/invalid-id.ndjson | {"_id": "espen", "_type": "employee", "name": "Espen"}
{"_id": 123, "_type": "employee", "name": "Per-Kristian"}
{"_id": "Even", "_type": "employee", "name": "Even"}
| 2,023 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/test | petrpan-code/sanity-io/sanity/packages/@sanity/import/test/fixtures/invalid-json.ndjson | {"_id":"foo","_type":"bar","num":0}
{"_id":"bar","_type":"bar","num":1}
{_id: "foo"}
| 2,024 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/test | petrpan-code/sanity-io/sanity/packages/@sanity/import/test/fixtures/missing-asset-type.ndjson | {"_id": "domino", "_type": "xForce", "image": {"_sanityAsset": "image@https://en.wikipedia.org/wiki/File:Domino_Uncanny_X-Men_Annual_Vol_4_1.png"}}
{"_id": "deadpool", "_type": "xForce", "image": {"_sanityAsset": "https://en.wikipedia.org/wiki/File:Deadpool_poster.jpg"}}
{"_id": "zeitgeist", "_type": "xForce", "image":... | 2,025 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/test | petrpan-code/sanity-io/sanity/packages/@sanity/import/test/fixtures/missing-type.ndjson | {"_id": "espen", "_type": "employee", "name": "Espen"}
{"_id": "Even", "_type": "employee", "name": "Even"}
{"_id": "pk", "name": "Per-Kristian"}
| 2,026 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/test | petrpan-code/sanity-io/sanity/packages/@sanity/import/test/fixtures/mock-assets.js | module.exports = (url) => {
const docs = []
for (let i = 1; i <= 60; i++) {
docs.push({
documentId: `doc_${i}`,
path: 'some.path',
url: url,
type: 'image',
})
}
return docs
}
| 2,027 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/test | petrpan-code/sanity-io/sanity/packages/@sanity/import/test/fixtures/references.ndjson | {"_id": "grrm", "_type": "author", "name": "George R. R. Martin"}
{"_id": "no-ref", "_type": "mock", "title": "No references"}
{"_id": "normal-ref", "_type": "mock", "title": "Normal reference", "author": {"_type": "reference", "_ref": "grrm"}}
{"_id": "missing-type-ref", "_type": "mock", "title": "Reference missing `_... | 2,028 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/test | petrpan-code/sanity-io/sanity/packages/@sanity/import/test/fixtures/unkeyed.ndjson | {"_id": "espen", "_type": "employee", "name": "Espen", "favGames": [{"_ref": "bf1942"}]}
{"_id": "pk", "_type": "employee", "name": "Per-Kristian", "favGames": [{"_ref": "cod2"}, {"_ref": "bf2"}]}
| 2,029 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/test | petrpan-code/sanity-io/sanity/packages/@sanity/import/test/fixtures/valid-but-missing-ids.ndjson | {"_type": "employee", "name": "Espen"}
{"_id":"pk", "_type": "employee", "name": "Per-Kristian"}
{"_type": "employee", "name": "Bjørge"}
| 2,030 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/test | petrpan-code/sanity-io/sanity/packages/@sanity/import/test/helpers/helpers.js | const noop = require('lodash/noop')
const {createClient, requester: defaultRequester} = require('@sanity/client')
const {injectResponse} = require('get-it/middleware')
process.on('unhandledRejection', (reason) => {
// eslint-disable-next-line no-console
console.error('UNHANDLED REJECTION', reason)
})
const defaul... | 2,031 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/import/test | petrpan-code/sanity-io/sanity/packages/@sanity/import/test/helpers/index.js | module.exports = require('./helpers')
| 2,032 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/.depcheckignore.json | {
"ignore": ["@optimize-lodash/rollup-plugin", "@sanity/pkg-utils"]
}
| 2,033 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/.eslintrc.cjs | 'use strict'
const path = require('path')
const ROOT_PATH = path.resolve(__dirname, '../../..')
module.exports = {
rules: {
'import/no-extraneous-dependencies': ['error', {packageDir: [ROOT_PATH, __dirname]}],
},
}
| 2,034 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/LICENSE | MIT License
Copyright (c) 2016 - 2023 Sanity.io
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, ... | 2,035 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/README.md | # @sanity/mutator
## Installing
```
npm install --save @sanity/mutator
```
## License
MIT-licensed. See LICENSE.
| 2,036 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/TODO.md | - [x] probes should have kind
- [x] attributes, keys -> property
- [x] support immutability through returned values for all patch operations
- [x] make ImmutableAccessor into RecursiveImmutableAccessor
- [x] delete -> unset
- [x] patch class names Set -> SetPatch
- [ ] Implement '\*'
- [ ] replace
- [ ] merge
- [ ] in... | 2,037 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/jest.config.cjs | 'use strict'
const {createJestConfig} = require('../../../test/config.cjs')
module.exports = createJestConfig({
displayName: require('./package.json').name,
})
| 2,038 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/package.config.ts | import {defineConfig} from '@sanity/pkg-utils'
import baseConfig from '../../../package.config'
export default defineConfig({...baseConfig})
| 2,039 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/package.json | {
"name": "@sanity/mutator",
"version": "3.20.1",
"description": "A set of models to make it easier to utilize the powerful real time collaborative features of Sanity",
"keywords": [
"sanity",
"cms",
"headless",
"realtime",
"content",
"mutator"
],
"homepage": "https://www.sanity.io/"... | 2,040 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/tsconfig.json | {
"extends": "../../../tsconfig.settings",
"include": ["./perf", "./src", "./test"],
"compilerOptions": {
"composite": true,
"declarationDir": "./lib/dts",
"rootDir": ".",
"outDir": "./lib/dts"
}
}
| 2,041 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/tsconfig.lib.json | {
"extends": "../../../tsconfig.settings",
"include": ["./src"],
"exclude": [
"./src/**/__fixtures__",
"./src/**/__mocks__",
"./src/**/__workshop__",
"./src/**/*.test.ts",
"./src/**/*.test.tsx"
],
"compilerOptions": {
"composite": true,
"rootDir": ".",
"outDir": "./lib/dts",
... | 2,042 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/perf/.eslintrc | {
"rules": {
"@typescript-eslint/no-var-requires": "off"
}
}
| 2,043 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/perf/run.js | /* eslint-disable no-console */
const {BufferedDocument, Mutation} = require('../lib')
const mutations = require('./fixtures/patches')
const snapshot = require('./fixtures/snapshot')
const bufferedDocument = new BufferedDocument(snapshot)
const labelAll = `Adding ${mutations.length} mutations`
console.time(labelAll)
m... | 2,044 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/perf | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/perf/fixtures/patches.js | module.exports = [
[
{setIfMissing: {recursiveObject: {_type: 'recursiveObject'}}},
{setIfMissing: {'recursiveObject.myself': {_type: 'recursiveObject'}}},
{setIfMissing: {'recursiveObject.myself.myself': {_type: 'recursiveObject'}}},
{setIfMissing: {'recursiveObject.myself.myself.myself': {_type: 're... | 2,045 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/perf | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/perf/fixtures/snapshot.js | module.exports = {
_createdAt: '2018-09-10T14:53:55Z',
_id: 'drafts.5b559770-af25-4475-981e-376c6847638d',
_rev: 'yk9has-9e5-zk5-xqd-pxnx8wncc',
_type: 'recursiveObjectTest',
_updatedAt: '2018-09-10T16:45:03Z',
recursiveObject: {
_type: 'recursiveObject',
first: 'dskfsdjafjsdfhasjkdfhasjkfhaskdjfhsa... | 2,046 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/index.ts | export {extract, extractWithPath, arrayToJSONMatchPath} from './jsonpath'
export {
BufferedDocument,
Mutation,
type MutationParams,
type Doc,
type Mut,
type Document,
type SquashingBuffer,
type SubmissionResponder,
type CommitHandlerMessage,
} from './document'
| 2,047 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/util.ts | export function isRecord(value: unknown): value is {[key: string]: unknown} {
return value !== null && typeof value === 'object'
}
| 2,048 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/document/BufferedDocument.ts | import {isEqual} from 'lodash'
import {Document} from './Document'
import {Mutation} from './Mutation'
import {SquashingBuffer} from './SquashingBuffer'
import {debug} from './debug'
import type {Doc, Mut} from './types'
const ONE_MINUTE = 1000 * 60
/**
* @internal
*/
export interface CommitHandlerMessage {
mutat... | 2,049 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/document/Document.ts | // TODO: When we have timestamps on mutation notifications, we can reject incoming mutations that are older
// than the document we are seeing.
import {isEqual} from 'lodash'
import {Mutation} from './Mutation'
import {debug} from './debug'
import type {Doc} from './types'
/**
* @internal
*/
export interface Submis... | 2,050 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/document/Mutation.ts | import {Patcher} from '../patch'
import {luid} from './luid'
import {debug} from './debug'
import type {Doc, Mut} from './types'
/**
* Parameters attached to the mutation
*
* @internal
*/
export interface MutationParams {
transactionId?: string
transition?: string
identity?: string
previousRev?: string
r... | 2,051 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/document/SquashingBuffer.ts | import {makePatches, stringifyPatches} from '@sanity/diff-match-patch'
import {extractWithPath} from '../jsonpath/extractWithPath'
import {arrayToJSONMatchPath} from '../jsonpath/arrayToJSONMatchPath'
import {Mutation} from './Mutation'
import {debug} from './debug'
import type {Doc, Mut} from './types'
/**
* Impleme... | 2,052 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/document/debug.ts | import debugIt from 'debug'
export const debug = debugIt('mutator-document')
| 2,053 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/document/index.ts | export {Document, type SubmissionResponder} from './Document'
export {Mutation, type MutationParams} from './Mutation'
export {BufferedDocument, type CommitHandlerMessage} from './BufferedDocument'
export {SquashingBuffer} from './SquashingBuffer'
export type {Doc, Mut} from './types'
| 2,054 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/document/luid.ts | import {uuid} from '@sanity/uuid'
/**
* Locally unique id's. We use this to generate transaction ids, and they don't have to be
* cryptographically unique, as the worst that can happen is that they get rejected because
* of a collision, and then we should just retry with a new id.
*/
export const luid = uuid
| 2,055 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/document/types.ts | import type {
CreateIfNotExistsMutation,
CreateMutation,
CreateOrReplaceMutation,
DeleteMutation,
PatchMutation,
} from '@sanity/types'
/**
* Sanity document with a guaranteed `_id` and `_type`
*
* @internal
*/
export interface Doc {
_id: string
_type: string
_rev?: string
_updatedAt?: string
[... | 2,056 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/jsonpath/Descender.ts | import {flatten} from 'lodash'
import {Expression} from './Expression'
import type {Probe} from './Probe'
/**
* Descender models the state of one partial jsonpath evaluation. Head is the
* next thing to match, tail is the upcoming things once the head is matched.
*/
export class Descender {
head: Expression | nul... | 2,057 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/jsonpath/Expression.ts | // A utility wrapper class to process parsed jsonpath expressions
import type {Expr, HeadTail} from './types'
import type {Probe} from './Probe'
import {descend} from './descend'
import {toPath} from './toPath'
import {parseJsonPath} from './parse'
export interface Range {
start: number
end: number
step: number... | 2,058 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/jsonpath/Matcher.ts | import {parseJsonPath} from './parse'
import {Descender} from './Descender'
import {Expression} from './Expression'
import type {Probe} from './Probe'
interface Result<P = unknown> {
leads: {
target: Expression
matcher: Matcher
}[]
delivery?: {
targets: Expression[]
payload: P
}
}
/**
* @int... | 2,059 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/jsonpath/PlainProbe.ts | import {isRecord} from '../util'
import type {Probe} from './Probe'
// A default implementation of a probe for vanilla JS _values
export class PlainProbe implements Probe {
_value: unknown
path: (string | number)[]
constructor(value: unknown, path?: (string | number)[]) {
this._value = value
this.path =... | 2,060 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/jsonpath/Probe.ts | export interface Probe {
path: (string | number)[]
containerType(): 'object' | 'array' | 'primitive'
length(): number
getIndex(index: number): Probe | false | null
get: () => unknown
getAttribute(attr: string): Probe | null
attributeKeys(): string[]
hasAttribute(attr: string): boolean
}
| 2,061 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/jsonpath/arrayToJSONMatchPath.ts | import type {Path, PathSegment} from '@sanity/types'
import {isRecord} from '../util'
const IS_DOTTABLE = /^[a-z_$]+/
/**
* Converts a path in array form to a JSONPath string
*
* @param pathArray - Array of path segments
* @returns String representation of the path
* @internal
*/
export function arrayToJSONMatc... | 2,062 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/jsonpath/descend.ts | import type {Expr, PathExpr} from './types'
/**
* Splits an expression into a set of heads, tails. A head is the next leaf node to
* check for matches, and a tail is everything that follows it. Matching is done by
* matching heads, then proceedint to the matching value, splitting the tail into
* heads and tails an... | 2,063 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/jsonpath/extract.ts | import {extractAccessors} from './extractAccessors'
/**
* Extracts values matching the given JsonPath
*
* @param path - Path to extract
* @param value - Value to extract from
* @returns An array of values matching the given path
* @public
*/
export function extract(path: string, value: unknown): unknown[] {
c... | 2,064 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/jsonpath/extractAccessors.ts | import {compact} from 'lodash'
import {Expression} from './Expression'
import {Matcher} from './Matcher'
import {PlainProbe} from './PlainProbe'
import {Probe} from './Probe'
export function extractAccessors(path: string, value: unknown): Probe[] {
const result: Probe[] = []
const matcher = Matcher.fromPath(path).... | 2,065 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/jsonpath/extractWithPath.ts | import {extractAccessors} from './extractAccessors'
/**
* Extracts a value for the given JsonPath, and includes the specific path of where it was found
*
* @param path - Path to extract
* @param value - Value to extract from
* @returns An array of objects with `path` and `value` keys
* @internal
*/
export funct... | 2,066 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/jsonpath/index.ts | import {Matcher} from './Matcher'
import {Expression} from './Expression'
import {extract} from './extract'
import {extractWithPath} from './extractWithPath'
import {arrayToJSONMatchPath} from './arrayToJSONMatchPath'
export {Matcher, Expression, extract, extractWithPath, arrayToJSONMatchPath}
| 2,067 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/jsonpath/parse.ts | // Converts a string into an abstract syntax tree representation
import {tokenize} from './tokenize'
import type {
AliasExpr,
AttributeExpr,
BooleanExpr,
ConstraintExpr,
IndexExpr,
NumberExpr,
PathExpr,
RangeExpr,
RecursiveExpr,
StringExpr,
Token,
UnionExpr,
} from './types'
// TODO: Support '... | 2,068 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/jsonpath/toPath.ts | import type {Expr} from './types'
/**
* Converts a parsed expression back into jsonpath2, roughly -
* mostly for use with tests.
*
* @param expr - Expression to convert to path
* @returns a string representation of the path
* @internal
*/
export function toPath(expr: Expr): string {
return toPathInner(expr, f... | 2,069 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/jsonpath/tokenize.ts | import type {
IdentifierToken,
NumberToken,
QuotedToken,
SymbolClass,
SymbolToken,
Token,
} from './types'
// TODO: Support '*'
const digitChar = /[0-9]/
const attributeCharMatcher = /^[a-zA-Z0-9_]$/
const attributeFirstCharMatcher = /^[a-zA-Z_]$/
const symbols: Record<SymbolClass, string[]> = {
// NOT... | 2,070 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/jsonpath/types.ts | import type {Expression} from './Expression'
export type SymbolClass = 'boolean' | 'operator' | 'comparator' | 'keyword' | 'paren'
export interface QuotedToken {
type: 'quoted'
quote: 'double' | 'single'
value: string | null
}
export interface IdentifierToken {
type: 'identifier'
name: string
}
export int... | 2,071 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/patch/DiffMatchPatch.ts | import {applyPatches, parsePatch, type Patch} from '@sanity/diff-match-patch'
import {Expression} from '../jsonpath'
import {ImmutableAccessor} from './ImmutableAccessor'
function applyPatch(patch: Patch[], oldValue: unknown) {
// Silently avoid patching if the value type is not string
if (typeof oldValue !== 'str... | 2,072 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/patch/ImmutableAccessor.ts | import type {Probe} from '../jsonpath/Probe'
/**
* An immutable probe/writer for plain JS objects that will never mutate
* the provided _value in place. Each setter returns a new (wrapped) version
* of the value.
*/
export class ImmutableAccessor implements Probe {
_value: unknown
path: (string | number)[]
... | 2,073 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/patch/IncPatch.ts | import type {Expression} from '../jsonpath'
import type {ImmutableAccessor} from './ImmutableAccessor'
function performIncrement(previousValue: unknown, delta: number): number {
if (typeof previousValue !== 'number' || !Number.isFinite(previousValue)) {
return previousValue as number
}
return previousValue ... | 2,074 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/patch/InsertPatch.ts | import {min, max} from 'lodash'
import type {Expression} from '../jsonpath'
import type {ImmutableAccessor} from './ImmutableAccessor'
import {targetsToIndicies} from './util'
export class InsertPatch {
location: string
path: string
items: unknown[]
id: string
constructor(id: string, location: string, path:... | 2,075 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/patch/Patcher.ts | import type {Doc} from '../document/types'
import {Matcher} from '../jsonpath'
import {parsePatch} from './parse'
import {ImmutableAccessor} from './ImmutableAccessor'
import {PatchTypes, SingleDocumentPatch} from './types'
import {SetPatch} from './SetPatch'
import {SetIfMissingPatch} from './SetIfMissingPatch'
expor... | 2,076 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/patch/SetIfMissingPatch.ts | import type {Expression} from '../jsonpath'
import type {ImmutableAccessor} from './ImmutableAccessor'
export class SetIfMissingPatch {
id: string
path: string
value: unknown
constructor(id: string, path: string, value: unknown) {
this.id = id
this.path = path
this.value = value
}
apply(targe... | 2,077 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/patch/SetPatch.ts | import type {Expression} from '../jsonpath'
import type {ImmutableAccessor} from './ImmutableAccessor'
export class SetPatch {
id: string
path: string
value: unknown
constructor(id: string, path: string, value: unknown) {
this.id = id
this.path = path
this.value = value
}
apply(targets: Expre... | 2,078 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/patch/UnsetPatch.ts | import type {Expression} from '../jsonpath'
import type {ImmutableAccessor} from './ImmutableAccessor'
import {targetsToIndicies} from './util'
export class UnsetPatch {
id: string
path: string
value: unknown
constructor(id: string, path: string) {
this.id = id
this.path = path
}
// eslint-disabl... | 2,079 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/patch/index.ts | export {Patcher} from './Patcher'
export {ImmutableAccessor} from './ImmutableAccessor'
| 2,080 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/patch/parse.ts | import {SetPatch} from './SetPatch'
import {IncPatch} from './IncPatch'
import {InsertPatch} from './InsertPatch'
import {SetIfMissingPatch} from './SetIfMissingPatch'
import {UnsetPatch} from './UnsetPatch'
import {DiffMatchPatch} from './DiffMatchPatch'
import type {PatchTypes, SingleDocumentPatch} from './types'
//... | 2,081 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/patch/types.ts | import type {PatchOperations} from '@sanity/types'
import type {DiffMatchPatch} from './DiffMatchPatch'
import type {IncPatch} from './IncPatch'
import type {InsertPatch} from './InsertPatch'
import type {SetIfMissingPatch} from './SetIfMissingPatch'
import type {SetPatch} from './SetPatch'
import type {UnsetPatch} fro... | 2,082 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/src/patch/util.ts | import type {Expression} from '../jsonpath'
import type {ImmutableAccessor} from './ImmutableAccessor'
export function targetsToIndicies(targets: Expression[], accessor: ImmutableAccessor): number[] {
const result: number[] = []
targets.forEach((target) => {
if (target.isIndexReference()) {
result.push(.... | 2,083 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/test/BufferedDocument.test.ts | import {BufferedDocumentTester} from './util/BufferedDocumentTester'
test('simple edit cycle', () => {
new BufferedDocumentTester({
_id: 'a',
_type: 't',
_rev: '1',
title: 'Hello',
})
.hasNoLocalEdits()
.stage('when applying first local edit')
.localPatch({
id: 'a',
set: {
... | 2,084 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/test/Descender.test.ts | import type {Expr} from '../src/jsonpath/types'
import {parseJsonPath} from '../src/jsonpath/parse'
import {Expression} from '../src/jsonpath/Expression'
import {Descender} from '../src/jsonpath/Descender'
import {PlainProbe} from '../src/jsonpath/PlainProbe'
function inner(jsonpath: string): Expr | null {
const exp... | 2,085 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/test/Document.test.ts | import {DocumentTester} from './util/DocumentTester'
test('simple remote mutation', () => {
new DocumentTester({
_id: 'a',
_type: 't',
_rev: '1',
title: 'Hello',
})
.isConsistent()
.stage('when remote patch arrive')
.remotePatch('1', '2', {
id: 'a',
set: {
title: 'Go... | 2,086 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/test/Expression.test.ts | import {parseJsonPath} from '../src/jsonpath/parse'
import {Expression} from '../src/jsonpath/Expression'
import {PlainProbe} from '../src/jsonpath/PlainProbe'
import {PathExpr, UnionExpr} from '../src/jsonpath/types'
function parseAsPath(path: string): PathExpr | UnionExpr {
const parsed = parseJsonPath(path)
if ... | 2,087 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/test/Matcher.test.ts | import {Matcher} from '../src/jsonpath/Matcher'
import {PlainProbe} from '../src/jsonpath/PlainProbe'
// Just a couple of basic tests to check that basic object descent works.
// The real hardcore testing of the matcher is done indirectly in the
// 'patch' test.
test('basic path match', () => {
const mx = Matcher.fr... | 2,088 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/test/Mutation.test.ts | import {Mutation} from '../src/document/Mutation'
test('updates _updatedAt when there is a timestamp', () => {
const timestamp = '2017-05-02T11:56:00.643Z'
const mutation = new Mutation({
mutations: [{patch: {id: '1', set: {value: 'banana'}}}],
timestamp,
})
const doc = mutation.apply({_id: '1', _type:... | 2,089 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/test/SquashingBuffer.test.ts | import type {PatchMutationOperation} from '@sanity/types'
import type {Mut} from '../src/document/types'
import {SquashingBuffer} from '../src/document/SquashingBuffer'
import {Mutation} from '../src/document/Mutation'
function add(sb: SquashingBuffer, op: Mut) {
const mut = new Mutation({
mutations: [op],
})
... | 2,090 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/test/arrayToJSONMatchPath.test.ts | // Converts an array of simple values (strings, numbers only) to a jsonmatch path string.
import {arrayToJSONMatchPath} from '../src/jsonpath/arrayToJSONMatchPath'
const cases: [any, string][] = [
[['a', 'b', 'c'], 'a.b.c'],
[['a', 'b', 5], 'a.b[5]'],
[[1, 2, 3], '[1][2][3]'],
[[1, 'foo', 'bar', 4], '[1].foo.... | 2,091 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/test/descend.test.ts | import {parseJsonPath} from '../src/jsonpath/parse'
import {toPath} from '../src/jsonpath/toPath'
import {descend} from '../src/jsonpath/descend'
import {Expr, PathExpr} from '../src/jsonpath/types'
function headTailToStr(headTail: [Expr | null, PathExpr | null]): string {
if (!headTail[0]) {
return ''
}
re... | 2,092 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/test/extract.test.ts | import {extract} from '../src/jsonpath'
test('basic extraction', () => {
expect(extract('nums[3,5]', {nums: [0, 1, 2, 3, 4, 5]})).toEqual([3, 5])
expect(extract('[nums, nums[1]]', {nums: [42, 13]})).toEqual([13, [42, 13]])
expect(extract('..[_ref?]', {parent: {_ref: '123'}})).toEqual([{_ref: '123'}])
expect(ex... | 2,093 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/test/extractWithPath.test.ts | import {extractWithPath} from '../src/jsonpath'
test('basic extraction', () => {
expect(
extractWithPath('..[_weak == true]._ref', {reference: {_ref: '123', _weak: true}}),
).toEqual([{path: ['reference', '_ref'], value: '123'}])
})
| 2,094 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/test/parse.test.ts | import {parseJsonPath} from '../src/jsonpath/parse'
const cases = {
a: {
type: 'attribute',
name: 'a',
},
'a.b': {
type: 'path',
nodes: [
{
type: 'attribute',
name: 'a',
},
{
type: 'attribute',
name: 'b',
},
],
},
'[7]': {
type: ... | 2,095 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/test/patch.test.ts | import {cloneDeep} from 'lodash'
import {Patcher} from '../src/patch'
import type {Doc} from '../src/document/types'
// Test suites
import set from './patchExamples/set'
import setIfMissing from './patchExamples/setIfMissing'
import unset from './patchExamples/unset'
import diffMatchPatch from './patchExamples/diffMat... | 2,096 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/test/toPath.test.ts | import {parseJsonPath} from '../src/jsonpath/parse'
import {toPath} from '../src/jsonpath/toPath'
const cases = [
'a.b.c',
'a.b[5]',
'[1,2,3]',
'[1:4]',
'[count > 5]',
'..a',
'[name == "\\"quoted\\""]',
]
cases.forEach((path, i) => {
test(`case #${i}`, () => {
const parsed = parseJsonPath(path)
... | 2,097 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/test/tokenize.test.ts | import {tokenize} from '../src/jsonpath/tokenize'
const cases = {
'a.b[7]': [
{
type: 'identifier',
name: 'a',
},
{
type: 'operator',
symbol: '.',
},
{
type: 'identifier',
name: 'b',
},
{
type: 'paren',
symbol: '[',
},
{
type: ... | 2,098 |
0 | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/test | petrpan-code/sanity-io/sanity/packages/@sanity/mutator/test/patchExamples/diffMatchPatch.ts | import type {PatchExample} from './types'
const examples: PatchExample[] = [
{
name: 'Diff match patch',
before: {
a: 'The rabid dog',
},
patch: {
id: 'a',
diffMatchPatch: {
a: '@@ -1,13 +1,12 @@\n The \n-rabid\n+nice\n dog\n',
},
},
after: {
a: 'The nic... | 2,099 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.