@sanity/mutate
Advanced tools
@@ -241,3 +241,3 @@ "use strict"; | ||
| }; | ||
| throw new Error(`Unknown operation type ${op.type}`); | ||
| throw op.type === "insertIfMissing" ? new Error("Patch type insertIfMissing is not supported by Sanity") : new Error(`Unknown operation type ${op.type}`); | ||
| } | ||
@@ -244,0 +244,0 @@ exports.decode = decode; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"encode.cjs","sources":["../../src/encoders/sanity/decode.ts","../../src/encoders/sanity/encode.ts"],"sourcesContent":["import {type PatchOperations} from '@sanity/client'\n\nimport {type SetIfMissingOp, type SetOp} from '../../mutations/operations/types'\nimport {\n type IdentifiedSanityDocument,\n type Mutation,\n type NodePatch,\n type SanityDocumentBase,\n} from '../../mutations/types'\nimport {parse as parsePath} from '../../path/parser/parse'\nimport {\n type Insert,\n type SanityCreateIfNotExistsMutation,\n type SanityCreateMutation,\n type SanityCreateOrReplaceMutation,\n type SanityDecPatch,\n type SanityDeleteMutation,\n type SanityDiffMatchPatch,\n type SanityIncPatch,\n type SanityInsertPatch,\n type SanityMutation,\n type SanityPatch,\n type SanitySetIfMissingPatch,\n type SanitySetPatch,\n type SanityUnsetPatch,\n} from './types'\n\nexport type {Mutation, SanityDocumentBase}\n\nfunction isCreateIfNotExistsMutation(\n sanityMutation: SanityMutation,\n): sanityMutation is SanityCreateIfNotExistsMutation {\n return 'createIfNotExists' in sanityMutation\n}\n\nfunction isCreateOrReplaceMutation<Doc extends IdentifiedSanityDocument>(\n sanityMutation: SanityMutation,\n): sanityMutation is SanityCreateOrReplaceMutation<Doc> {\n return 'createOrReplace' in sanityMutation\n}\n\nfunction isCreateMutation<Doc extends SanityDocumentBase>(\n sanityMutation: SanityMutation<Doc>,\n): sanityMutation is SanityCreateMutation<Doc> {\n return 'create' in sanityMutation\n}\n\nfunction isDeleteMutation(\n sanityMutation: SanityMutation<any>,\n): sanityMutation is SanityDeleteMutation {\n return 'delete' in sanityMutation\n}\n\nfunction isPatchMutation(sanityMutation: SanityMutation): sanityMutation is {\n patch: SanityPatch\n} {\n return 'patch' in sanityMutation\n}\n\nfunction isSetPatch(\n sanityPatch: PatchOperations,\n): sanityPatch is SanitySetPatch {\n return 'set' in sanityPatch\n}\n\nfunction isSetIfMissingPatch(\n sanityPatch: SanityPatch,\n): sanityPatch is SanitySetIfMissingPatch {\n return 'setIfMissing' in sanityPatch\n}\n\nfunction isDiffMatchPatch(\n sanityPatch: SanityPatch,\n): sanityPatch is SanityDiffMatchPatch {\n return 'diffMatchPatch' in sanityPatch\n}\n\nfunction isUnsetPatch(\n sanityPatch: SanityPatch,\n): sanityPatch is SanityUnsetPatch {\n return 'unset' in sanityPatch\n}\n\nfunction isIncPatch(sanityPatch: SanityPatch): sanityPatch is SanityIncPatch {\n return 'inc' in sanityPatch\n}\n\nfunction isDecPatch(sanityPatch: SanityPatch): sanityPatch is SanityDecPatch {\n return 'inc' in sanityPatch\n}\n\nfunction isInsertPatch(\n sanityPatch: SanityPatch,\n): sanityPatch is SanityInsertPatch {\n return 'insert' in sanityPatch\n}\n\nexport function decodeAll<Doc extends SanityDocumentBase>(\n sanityMutations: SanityMutation<Doc>[],\n) {\n return sanityMutations.map(decodeMutation)\n}\n\nexport function decode<Doc extends SanityDocumentBase>(\n encodedMutation: SanityMutation<Doc>,\n) {\n return decodeMutation(encodedMutation)\n}\n\nfunction decodeMutation<Doc extends SanityDocumentBase>(\n encodedMutation: SanityMutation<Doc>,\n): Mutation {\n if (isCreateIfNotExistsMutation(encodedMutation)) {\n return {\n type: 'createIfNotExists',\n document: encodedMutation.createIfNotExists,\n }\n }\n if (isCreateOrReplaceMutation(encodedMutation)) {\n return {\n type: 'createOrReplace',\n document: encodedMutation.createOrReplace,\n }\n }\n if (isCreateMutation(encodedMutation)) {\n return {type: 'create', document: encodedMutation.create}\n }\n if (isDeleteMutation(encodedMutation)) {\n return {id: encodedMutation.delete.id, type: 'delete'}\n }\n if (isPatchMutation(encodedMutation)) {\n return {\n type: 'patch',\n id: encodedMutation.patch.id,\n patches: decodeNodePatches(encodedMutation.patch),\n }\n }\n throw new Error(`Unknown mutation: ${JSON.stringify(encodedMutation)}`)\n}\n\nconst POSITION_KEYS = ['before', 'replace', 'after'] as const\n\nfunction getInsertPosition(insert: Insert) {\n const positions = POSITION_KEYS.filter(k => k in insert)\n if (positions.length > 1) {\n throw new Error(\n `Insert patch is ambiguous. Should only contain one of: ${POSITION_KEYS.join(\n ', ',\n )}, instead found ${positions.join(', ')}`,\n )\n }\n return positions[0]\n}\n\nfunction decodeNodePatches<T>(patch: SanityPatch): NodePatch<any, any>[] {\n // If multiple patches are included, then the order of execution is as follows\n // set, setIfMissing, unset, inc, dec, insert.\n // order is defined here: https://www.sanity.io/docs/http-mutations#2f480b2baca5\n return [\n ...getSetPatches(patch),\n ...getSetIfMissingPatches(patch),\n ...getUnsetPatches(patch),\n ...getIncPatches(patch),\n ...getDecPatches(patch),\n ...getInsertPatches(patch),\n ...getDiffMatchPatchPatches(patch),\n ]\n}\n\nfunction getSetPatches(patch: PatchOperations): NodePatch<any[], SetOp<any>>[] {\n return isSetPatch(patch)\n ? Object.keys(patch.set).map(path => ({\n path: parsePath(path),\n op: {type: 'set', value: patch.set[path]},\n }))\n : []\n}\n\nfunction getSetIfMissingPatches(\n patch: SanityPatch,\n): NodePatch<any[], SetIfMissingOp<any>>[] {\n return isSetIfMissingPatch(patch)\n ? Object.keys(patch.setIfMissing).map(path => ({\n path: parsePath(path),\n op: {type: 'setIfMissing', value: patch.setIfMissing[path]},\n }))\n : []\n}\n\nfunction getDiffMatchPatchPatches(patch: SanityPatch) {\n return isDiffMatchPatch(patch)\n ? Object.keys(patch.diffMatchPatch).map(path => ({\n path: parsePath(path),\n op: {type: 'diffMatchPatch', value: patch.diffMatchPatch[path]},\n }))\n : []\n}\n\nfunction getUnsetPatches(patch: SanityPatch) {\n return isUnsetPatch(patch)\n ? patch.unset.map(path => ({\n path: parsePath(path),\n op: {type: 'unset'},\n }))\n : []\n}\n\nfunction getIncPatches(patch: SanityPatch) {\n return isIncPatch(patch)\n ? Object.keys(patch.inc).map(path => ({\n path: parsePath(path),\n op: {type: 'inc', amount: patch.inc[path]},\n }))\n : []\n}\n\nfunction getDecPatches(patch: SanityPatch) {\n return isDecPatch(patch)\n ? Object.keys(patch.dec).map(path => ({\n path: parsePath(path),\n op: {type: 'dec', amount: patch.dec[path]},\n }))\n : []\n}\n\nfunction getInsertPatches(patch: SanityPatch) {\n if (!isInsertPatch(patch)) {\n return []\n }\n const position = getInsertPosition(patch.insert)\n if (!position) {\n throw new Error('Insert patch missing position')\n }\n\n const path: string[] = parsePath((patch.insert as any)[position]!)\n const referenceItem = path.pop()\n\n const op =\n position === 'replace'\n ? {\n type: 'insert',\n position: position,\n referenceItem,\n items: patch.insert.items,\n }\n : {\n type: 'insert',\n position: position,\n referenceItem,\n items: patch.insert.items,\n }\n\n return [{path, op}]\n}\n","import {type PatchMutationOperation} from '@sanity/client'\n\nimport {\n type Mutation,\n type NodePatch,\n type Transaction,\n} from '../../mutations/types'\nimport {stringify as stringifyPath} from '../../path/parser/stringify'\nimport {type SanityMutation} from './types'\n\nexport function encode(mutation: Mutation): SanityMutation[] | SanityMutation {\n return encodeMutation(mutation)\n}\n\nexport function encodeAll(mutations: Mutation[]): SanityMutation[] {\n return mutations.flatMap(encode)\n}\n\nexport function encodeTransaction(transaction: Transaction) {\n return {\n transactionId: transaction.id,\n mutations: encodeAll(transaction.mutations),\n }\n}\n\nexport function encodeMutation(\n mutation: Mutation,\n): SanityMutation[] | SanityMutation {\n switch (mutation.type) {\n case 'create':\n return {[mutation.type]: mutation.document}\n case 'createIfNotExists':\n return {[mutation.type]: mutation.document}\n case 'createOrReplace':\n return {[mutation.type]: mutation.document}\n case 'delete':\n return {\n delete: {id: mutation.id},\n }\n case 'patch': {\n const ifRevisionID = mutation.options?.ifRevision\n return mutation.patches.map(patch => {\n return {\n patch: {\n id: mutation.id,\n ...(ifRevisionID && {ifRevisionID}),\n ...patchToSanity(patch),\n },\n } as {id: string; patch: PatchMutationOperation}\n })\n }\n }\n}\n\nfunction patchToSanity(patch: NodePatch) {\n const {path, op} = patch\n if (op.type === 'unset') {\n return {unset: [stringifyPath(path)]}\n }\n if (op.type === 'insert') {\n return {\n insert: {\n [op.position]: stringifyPath([...path, op.referenceItem]),\n items: op.items,\n },\n }\n }\n if (op.type === 'diffMatchPatch') {\n return {diffMatchPatch: {[stringifyPath(path)]: op.value}}\n }\n if (op.type === 'inc') {\n return {inc: {[stringifyPath(path)]: op.amount}}\n }\n if (op.type === 'dec') {\n return {dec: {[stringifyPath(path)]: op.amount}}\n }\n if (op.type === 'set' || op.type === 'setIfMissing') {\n return {[op.type]: {[stringifyPath(path)]: op.value}}\n }\n if (op.type === 'truncate') {\n const range = [\n op.startIndex,\n typeof op.endIndex === 'number' ? op.endIndex : '',\n ].join(':')\n\n return {unset: [`${stringifyPath(path)}[${range}]`]}\n }\n if (op.type === 'upsert') {\n // note: upsert currently not supported by sanity, so will always insert at reference position\n return {\n unset: op.items.map(item =>\n stringifyPath([...path, {_key: (item as any)._key}]),\n ),\n insert: {\n [op.position]: stringifyPath([...path, op.referenceItem]),\n items: op.items,\n },\n }\n }\n if (op.type === 'assign') {\n return {\n set: Object.fromEntries(\n Object.keys(op.value).map(key => [\n stringifyPath(path.concat(key)),\n op.value[key as keyof typeof op.value],\n ]),\n ),\n }\n }\n if (op.type === 'unassign') {\n return {\n unset: op.keys.map(key => stringifyPath(path.concat(key))),\n }\n }\n if (op.type === 'replace') {\n return {\n insert: {\n replace: stringifyPath(path.concat(op.referenceItem)),\n items: op.items,\n },\n }\n }\n if (op.type === 'remove') {\n return {\n unset: [stringifyPath(path.concat(op.referenceItem))],\n }\n }\n //@ts-expect-error all cases should be covered\n throw new Error(`Unknown operation type ${op.type}`)\n}\n"],"names":["parsePath","stringifyPath"],"mappings":";;AA6BA,SAAS,4BACP,gBACmD;AACnD,SAAO,uBAAuB;AAChC;AAEA,SAAS,0BACP,gBACsD;AACtD,SAAO,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AAS;AACd,WAAO;AAAA,MACL,OAAO,GAAG,KAAK,IAAI,CAAA,QAAOA,UAAAA,UAAc,KAAK,OAAO,GAAG,CAAC,CAAC;AAAA,IAAA;AAG7D,MAAI,GAAG,SAAS;AACd,WAAO;AAAA,MACL,QAAQ;AAAA,QACN,SAASA,UAAAA,UAAc,KAAK,OAAO,GAAG,aAAa,CAAC;AAAA,QACpD,OAAO,GAAG;AAAA,MAAA;AAAA,IACZ;AAGJ,MAAI,GAAG,SAAS;AACd,WAAO;AAAA,MACL,OAAO,CAACA,UAAAA,UAAc,KAAK,OAAO,GAAG,aAAa,CAAC,CAAC;AAAA,IAAA;AAIxD,QAAM,IAAI,MAAM,0BAA0B,GAAG,IAAI,EAAE;AACrD;;;;;;;"} | ||
| {"version":3,"file":"encode.cjs","sources":["../../src/encoders/sanity/decode.ts","../../src/encoders/sanity/encode.ts"],"sourcesContent":["import {type PatchOperations} from '@sanity/client'\n\nimport {type SetIfMissingOp, type SetOp} from '../../mutations/operations/types'\nimport {\n type IdentifiedSanityDocument,\n type Mutation,\n type NodePatch,\n type SanityDocumentBase,\n} from '../../mutations/types'\nimport {parse as parsePath} from '../../path/parser/parse'\nimport {\n type Insert,\n type SanityCreateIfNotExistsMutation,\n type SanityCreateMutation,\n type SanityCreateOrReplaceMutation,\n type SanityDecPatch,\n type SanityDeleteMutation,\n type SanityDiffMatchPatch,\n type SanityIncPatch,\n type SanityInsertPatch,\n type SanityMutation,\n type SanityPatch,\n type SanitySetIfMissingPatch,\n type SanitySetPatch,\n type SanityUnsetPatch,\n} from './types'\n\nexport type {Mutation, SanityDocumentBase}\n\nfunction isCreateIfNotExistsMutation(\n sanityMutation: SanityMutation,\n): sanityMutation is SanityCreateIfNotExistsMutation {\n return 'createIfNotExists' in sanityMutation\n}\n\nfunction isCreateOrReplaceMutation<Doc extends IdentifiedSanityDocument>(\n sanityMutation: SanityMutation,\n): sanityMutation is SanityCreateOrReplaceMutation<Doc> {\n return 'createOrReplace' in sanityMutation\n}\n\nfunction isCreateMutation<Doc extends SanityDocumentBase>(\n sanityMutation: SanityMutation<Doc>,\n): sanityMutation is SanityCreateMutation<Doc> {\n return 'create' in sanityMutation\n}\n\nfunction isDeleteMutation(\n sanityMutation: SanityMutation<any>,\n): sanityMutation is SanityDeleteMutation {\n return 'delete' in sanityMutation\n}\n\nfunction isPatchMutation(sanityMutation: SanityMutation): sanityMutation is {\n patch: SanityPatch\n} {\n return 'patch' in sanityMutation\n}\n\nfunction isSetPatch(\n sanityPatch: PatchOperations,\n): sanityPatch is SanitySetPatch {\n return 'set' in sanityPatch\n}\n\nfunction isSetIfMissingPatch(\n sanityPatch: SanityPatch,\n): sanityPatch is SanitySetIfMissingPatch {\n return 'setIfMissing' in sanityPatch\n}\n\nfunction isDiffMatchPatch(\n sanityPatch: SanityPatch,\n): sanityPatch is SanityDiffMatchPatch {\n return 'diffMatchPatch' in sanityPatch\n}\n\nfunction isUnsetPatch(\n sanityPatch: SanityPatch,\n): sanityPatch is SanityUnsetPatch {\n return 'unset' in sanityPatch\n}\n\nfunction isIncPatch(sanityPatch: SanityPatch): sanityPatch is SanityIncPatch {\n return 'inc' in sanityPatch\n}\n\nfunction isDecPatch(sanityPatch: SanityPatch): sanityPatch is SanityDecPatch {\n return 'inc' in sanityPatch\n}\n\nfunction isInsertPatch(\n sanityPatch: SanityPatch,\n): sanityPatch is SanityInsertPatch {\n return 'insert' in sanityPatch\n}\n\nexport function decodeAll<Doc extends SanityDocumentBase>(\n sanityMutations: SanityMutation<Doc>[],\n) {\n return sanityMutations.map(decodeMutation)\n}\n\nexport function decode<Doc extends SanityDocumentBase>(\n encodedMutation: SanityMutation<Doc>,\n) {\n return decodeMutation(encodedMutation)\n}\n\nfunction decodeMutation<Doc extends SanityDocumentBase>(\n encodedMutation: SanityMutation<Doc>,\n): Mutation {\n if (isCreateIfNotExistsMutation(encodedMutation)) {\n return {\n type: 'createIfNotExists',\n document: encodedMutation.createIfNotExists,\n }\n }\n if (isCreateOrReplaceMutation(encodedMutation)) {\n return {\n type: 'createOrReplace',\n document: encodedMutation.createOrReplace,\n }\n }\n if (isCreateMutation(encodedMutation)) {\n return {type: 'create', document: encodedMutation.create}\n }\n if (isDeleteMutation(encodedMutation)) {\n return {id: encodedMutation.delete.id, type: 'delete'}\n }\n if (isPatchMutation(encodedMutation)) {\n return {\n type: 'patch',\n id: encodedMutation.patch.id,\n patches: decodeNodePatches(encodedMutation.patch),\n }\n }\n throw new Error(`Unknown mutation: ${JSON.stringify(encodedMutation)}`)\n}\n\nconst POSITION_KEYS = ['before', 'replace', 'after'] as const\n\nfunction getInsertPosition(insert: Insert) {\n const positions = POSITION_KEYS.filter(k => k in insert)\n if (positions.length > 1) {\n throw new Error(\n `Insert patch is ambiguous. Should only contain one of: ${POSITION_KEYS.join(\n ', ',\n )}, instead found ${positions.join(', ')}`,\n )\n }\n return positions[0]\n}\n\nfunction decodeNodePatches<T>(patch: SanityPatch): NodePatch<any, any>[] {\n // If multiple patches are included, then the order of execution is as follows\n // set, setIfMissing, unset, inc, dec, insert.\n // order is defined here: https://www.sanity.io/docs/http-mutations#2f480b2baca5\n return [\n ...getSetPatches(patch),\n ...getSetIfMissingPatches(patch),\n ...getUnsetPatches(patch),\n ...getIncPatches(patch),\n ...getDecPatches(patch),\n ...getInsertPatches(patch),\n ...getDiffMatchPatchPatches(patch),\n ]\n}\n\nfunction getSetPatches(patch: PatchOperations): NodePatch<any[], SetOp<any>>[] {\n return isSetPatch(patch)\n ? Object.keys(patch.set).map(path => ({\n path: parsePath(path),\n op: {type: 'set', value: patch.set[path]},\n }))\n : []\n}\n\nfunction getSetIfMissingPatches(\n patch: SanityPatch,\n): NodePatch<any[], SetIfMissingOp<any>>[] {\n return isSetIfMissingPatch(patch)\n ? Object.keys(patch.setIfMissing).map(path => ({\n path: parsePath(path),\n op: {type: 'setIfMissing', value: patch.setIfMissing[path]},\n }))\n : []\n}\n\nfunction getDiffMatchPatchPatches(patch: SanityPatch) {\n return isDiffMatchPatch(patch)\n ? Object.keys(patch.diffMatchPatch).map(path => ({\n path: parsePath(path),\n op: {type: 'diffMatchPatch', value: patch.diffMatchPatch[path]},\n }))\n : []\n}\n\nfunction getUnsetPatches(patch: SanityPatch) {\n return isUnsetPatch(patch)\n ? patch.unset.map(path => ({\n path: parsePath(path),\n op: {type: 'unset'},\n }))\n : []\n}\n\nfunction getIncPatches(patch: SanityPatch) {\n return isIncPatch(patch)\n ? Object.keys(patch.inc).map(path => ({\n path: parsePath(path),\n op: {type: 'inc', amount: patch.inc[path]},\n }))\n : []\n}\n\nfunction getDecPatches(patch: SanityPatch) {\n return isDecPatch(patch)\n ? Object.keys(patch.dec).map(path => ({\n path: parsePath(path),\n op: {type: 'dec', amount: patch.dec[path]},\n }))\n : []\n}\n\nfunction getInsertPatches(patch: SanityPatch) {\n if (!isInsertPatch(patch)) {\n return []\n }\n const position = getInsertPosition(patch.insert)\n if (!position) {\n throw new Error('Insert patch missing position')\n }\n\n const path: string[] = parsePath((patch.insert as any)[position]!)\n const referenceItem = path.pop()\n\n const op =\n position === 'replace'\n ? {\n type: 'insert',\n position: position,\n referenceItem,\n items: patch.insert.items,\n }\n : {\n type: 'insert',\n position: position,\n referenceItem,\n items: patch.insert.items,\n }\n\n return [{path, op}]\n}\n","import {type PatchMutationOperation} from '@sanity/client'\n\nimport {\n type Mutation,\n type NodePatch,\n type Transaction,\n} from '../../mutations/types'\nimport {stringify as stringifyPath} from '../../path/parser/stringify'\nimport {type SanityMutation} from './types'\n\nexport function encode(mutation: Mutation): SanityMutation[] | SanityMutation {\n return encodeMutation(mutation)\n}\n\nexport function encodeAll(mutations: Mutation[]): SanityMutation[] {\n return mutations.flatMap(encode)\n}\n\nexport function encodeTransaction(transaction: Transaction) {\n return {\n transactionId: transaction.id,\n mutations: encodeAll(transaction.mutations),\n }\n}\n\nexport function encodeMutation(\n mutation: Mutation,\n): SanityMutation[] | SanityMutation {\n switch (mutation.type) {\n case 'create':\n return {[mutation.type]: mutation.document}\n case 'createIfNotExists':\n return {[mutation.type]: mutation.document}\n case 'createOrReplace':\n return {[mutation.type]: mutation.document}\n case 'delete':\n return {\n delete: {id: mutation.id},\n }\n case 'patch': {\n const ifRevisionID = mutation.options?.ifRevision\n return mutation.patches.map(patch => {\n return {\n patch: {\n id: mutation.id,\n ...(ifRevisionID && {ifRevisionID}),\n ...patchToSanity(patch),\n },\n } as {id: string; patch: PatchMutationOperation}\n })\n }\n }\n}\n\nfunction patchToSanity(patch: NodePatch) {\n const {path, op} = patch\n if (op.type === 'unset') {\n return {unset: [stringifyPath(path)]}\n }\n if (op.type === 'insert') {\n return {\n insert: {\n [op.position]: stringifyPath([...path, op.referenceItem]),\n items: op.items,\n },\n }\n }\n if (op.type === 'diffMatchPatch') {\n return {diffMatchPatch: {[stringifyPath(path)]: op.value}}\n }\n if (op.type === 'inc') {\n return {inc: {[stringifyPath(path)]: op.amount}}\n }\n if (op.type === 'dec') {\n return {dec: {[stringifyPath(path)]: op.amount}}\n }\n if (op.type === 'set' || op.type === 'setIfMissing') {\n return {[op.type]: {[stringifyPath(path)]: op.value}}\n }\n if (op.type === 'truncate') {\n const range = [\n op.startIndex,\n typeof op.endIndex === 'number' ? op.endIndex : '',\n ].join(':')\n\n return {unset: [`${stringifyPath(path)}[${range}]`]}\n }\n if (op.type === 'upsert') {\n // note: upsert currently not supported by sanity, so will always insert at reference position\n return {\n unset: op.items.map(item =>\n stringifyPath([...path, {_key: (item as any)._key}]),\n ),\n insert: {\n [op.position]: stringifyPath([...path, op.referenceItem]),\n items: op.items,\n },\n }\n }\n if (op.type === 'assign') {\n return {\n set: Object.fromEntries(\n Object.keys(op.value).map(key => [\n stringifyPath(path.concat(key)),\n op.value[key as keyof typeof op.value],\n ]),\n ),\n }\n }\n if (op.type === 'unassign') {\n return {\n unset: op.keys.map(key => stringifyPath(path.concat(key))),\n }\n }\n if (op.type === 'replace') {\n return {\n insert: {\n replace: stringifyPath(path.concat(op.referenceItem)),\n items: op.items,\n },\n }\n }\n if (op.type === 'remove') {\n return {\n unset: [stringifyPath(path.concat(op.referenceItem))],\n }\n }\n if (op.type === 'insertIfMissing') {\n // note: insertIfMissing currently not supported by sanity, so will always insert at reference position\n throw new Error('Patch type insertIfMissing is not supported by Sanity')\n }\n //@ts-expect-error all cases should be covered\n throw new Error(`Unknown operation type ${op.type}`)\n}\n"],"names":["parsePath","stringifyPath"],"mappings":";;AA6BA,SAAS,4BACP,gBACmD;AACnD,SAAO,uBAAuB;AAChC;AAEA,SAAS,0BACP,gBACsD;AACtD,SAAO,qBAAqB;AAC9B;AAEA,SAAS,iBACP,gBAC6C;AAC7C,SAAO,YAAY;AACrB;AAEA,SAAS,iBACP,gBACwC;AACxC,SAAO,YAAY;AACrB;AAEA,SAAS,gBAAgB,gBAEvB;AACA,SAAO,WAAW;AACpB;AAEA,SAAS,WACP,aAC+B;AAC/B,SAAO,SAAS;AAClB;AAEA,SAAS,oBACP,aACwC;AACxC,SAAO,kBAAkB;AAC3B;AAEA,SAAS,iBACP,aACqC;AACrC,SAAO,oBAAoB;AAC7B;AAEA,SAAS,aACP,aACiC;AACjC,SAAO,WAAW;AACpB;AAEA,SAAS,WAAW,aAAyD;AAC3E,SAAO,SAAS;AAClB;AAEA,SAAS,WAAW,aAAyD;AAC3E,SAAO,SAAS;AAClB;AAEA,SAAS,cACP,aACkC;AAClC,SAAO,YAAY;AACrB;AAEO,SAAS,UACd,iBACA;AACA,SAAO,gBAAgB,IAAI,cAAc;AAC3C;AAEO,SAAS,OACd,iBACA;AACA,SAAO,eAAe,eAAe;AACvC;AAEA,SAAS,eACP,iBACU;AACV,MAAI,4BAA4B,eAAe;AAC7C,WAAO;AAAA,MACL,MAAM;AAAA,MACN,UAAU,gBAAgB;AAAA,IAAA;AAG9B,MAAI,0BAA0B,eAAe;AAC3C,WAAO;AAAA,MACL,MAAM;AAAA,MACN,UAAU,gBAAgB;AAAA,IAAA;AAG9B,MAAI,iBAAiB,eAAe;AAClC,WAAO,EAAC,MAAM,UAAU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MAAM,GAAG,aAAa,CAAC;AAAA,QACxD,OAAO,GAAG;AAAA,MAAA;AAAA,IACZ;AAGJ,MAAI,GAAG,SAAS;AACd,WAAO;AAAA,MACL,KAAK,OAAO;AAAA,QACV,OAAO,KAAK,GAAG,KAAK,EAAE,IAAI,CAAA,QAAO;AAAA,UAC/BA,UAAAA,UAAc,KAAK,OAAO,GAAG,CAAC;AAAA,UAC9B,GAAG,MAAM,GAA4B;AAAA,QAAA,CACtC;AAAA,MAAA;AAAA,IACH;AAGJ,MAAI,GAAG,SAAS;AACd,WAAO;AAAA,MACL,OAAO,GAAG,KAAK,IAAI,CAAA,QAAOA,UAAAA,UAAc,KAAK,OAAO,GAAG,CAAC,CAAC;AAAA,IAAA;AAG7D,MAAI,GAAG,SAAS;AACd,WAAO;AAAA,MACL,QAAQ;AAAA,QACN,SAASA,UAAAA,UAAc,KAAK,OAAO,GAAG,aAAa,CAAC;AAAA,QACpD,OAAO,GAAG;AAAA,MAAA;AAAA,IACZ;AAGJ,MAAI,GAAG,SAAS;AACd,WAAO;AAAA,MACL,OAAO,CAACA,UAAAA,UAAc,KAAK,OAAO,GAAG,aAAa,CAAC,CAAC;AAAA,IAAA;AAGxD,QAAI,GAAG,SAAS,oBAER,IAAI,MAAM,uDAAuD,IAGnE,IAAI,MAAM,0BAA0B,GAAG,IAAI,EAAE;AACrD;;;;;;;"} |
@@ -32,2 +32,8 @@ "use strict"; | ||
| } | ||
| function omit(val, props) { | ||
| const copy = { ...val }; | ||
| for (const prop of props) | ||
| delete copy[prop]; | ||
| return copy; | ||
| } | ||
| function insert(op, currentValue) { | ||
@@ -46,4 +52,4 @@ if (!Array.isArray(currentValue)) | ||
| return currentValue; | ||
| const replaceItemsMap = [], insertItems = []; | ||
| if (op.items.forEach((itemToBeUpserted, i) => { | ||
| const replaceItemsMap = {}, insertItems = []; | ||
| op.items.forEach((itemToBeUpserted, i) => { | ||
| const existingIndex = currentValue.findIndex( | ||
@@ -53,7 +59,11 @@ (existingItem) => existingItem?._key === itemToBeUpserted._key | ||
| existingIndex >= 0 ? replaceItemsMap[existingIndex] = i : insertItems.push(itemToBeUpserted); | ||
| }), replaceItemsMap.length === 0 && insertItems.length == 0) | ||
| }); | ||
| const itemsToReplace = Object.keys(replaceItemsMap); | ||
| if (itemsToReplace.length === 0 && insertItems.length == 0) | ||
| return currentValue; | ||
| const next = [...currentValue]; | ||
| for (const i of replaceItemsMap) | ||
| next[i] = op.items[replaceItemsMap[i]]; | ||
| for (const i of itemsToReplace) { | ||
| const index = Number(i); | ||
| next[index] = op.items[replaceItemsMap[index]]; | ||
| } | ||
| return insert( | ||
@@ -68,2 +78,19 @@ { | ||
| } | ||
| function insertIfMissing(op, currentValue) { | ||
| if (!Array.isArray(currentValue)) | ||
| throw new TypeError('Cannot apply "insertIfMissing()" on non-array value'); | ||
| if (op.items.length === 0) | ||
| return currentValue; | ||
| const itemsToInsert = op.items.filter( | ||
| (item) => !currentValue.find((existing) => item._key === existing?._key) | ||
| ); | ||
| return itemsToInsert.length === 0 ? currentValue : insert( | ||
| { | ||
| items: itemsToInsert, | ||
| referenceItem: op.referenceItem, | ||
| position: op.position | ||
| }, | ||
| currentValue | ||
| ); | ||
| } | ||
| function replace(op, currentValue) { | ||
@@ -117,8 +144,2 @@ if (!Array.isArray(currentValue)) | ||
| } | ||
| function omit(val, props) { | ||
| const copy = { ...val }; | ||
| for (const prop of props) | ||
| delete copy[prop]; | ||
| return copy; | ||
| } | ||
| function unassign(op, currentValue) { | ||
@@ -146,2 +167,3 @@ if (!isObject.isObject(currentValue)) | ||
| insert, | ||
| insertIfMissing, | ||
| remove, | ||
@@ -189,3 +211,3 @@ replace, | ||
| const patchedValue = applyAtPath(tail, op, current); | ||
| return patchedValue === current ? object : { ...object, [head]: patchedValue }; | ||
| return patchedValue === void 0 ? omit(object, [head]) : patchedValue === current ? object : { ...object, [head]: patchedValue }; | ||
| } | ||
@@ -197,3 +219,11 @@ function applyInArray(head, tail, op, value) { | ||
| const current = value[index], patchedItem = applyAtPath(tail, op, current); | ||
| return patchedItem === current ? value : splice(value, index, 1, [patchedItem]); | ||
| return patchedItem === current ? value : splice( | ||
| value, | ||
| index, | ||
| 1, | ||
| // unset op on an array item should not leave a "hole" in the array | ||
| // eg. apply(at('someArray[1]', unset()), ['foo', 'bar', 'baz'] should result in | ||
| // ['foo', 'baz'], not ['foo', undefined, 'baz'] | ||
| patchedItem === void 0 ? [] : [patchedItem] | ||
| ); | ||
| } | ||
@@ -200,0 +230,0 @@ function isNonEmptyArray(a) { |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"utils.cjs","sources":["../../src/apply/utils/getKeyOf.ts","../../src/apply/utils/array.ts","../../src/apply/patch/operations/array.ts","../../src/apply/patch/operations/common.ts","../../src/apply/patch/operations/number.ts","../../src/apply/utils/hasOwn.ts","../../src/apply/utils/isEmpty.ts","../../src/apply/utils/omit.ts","../../src/apply/patch/operations/object.ts","../../src/apply/patch/operations/string.ts","../../src/apply/patch/applyOp.ts","../../src/apply/patch/applyNodePatch.ts","../../src/apply/applyPatchMutation.ts","../../src/apply/store/utils.ts"],"sourcesContent":["export function keyOf(value: any): string | null {\n return (\n (value !== null &&\n typeof value === 'object' &&\n typeof value._key === 'string' &&\n value._key) ||\n null\n )\n}\n","import {isKeyedElement, type PathElement} from '../../path'\nimport {keyOf} from './getKeyOf'\n\nexport function findTargetIndex<T>(array: T[], pathSegment: PathElement) {\n if (typeof pathSegment === 'number') {\n return normalizeIndex(array.length, pathSegment)\n }\n if (isKeyedElement(pathSegment)) {\n const idx = array.findIndex(value => keyOf(value) === pathSegment._key)\n return idx === -1 ? null : idx\n }\n throw new Error(\n `Expected path segment to be addressing a single array item either by numeric index or by '_key'. Instead saw ${JSON.stringify(\n pathSegment,\n )}`,\n )\n}\n\nexport function getTargetIdx(position: 'before' | 'after', index: number) {\n return position === 'before' ? index : index + 1\n}\n\n// normalizes the index according to the array length\n// returns null if the normalized index is out of bounds\nexport function normalizeIndex(length: number, index: number) {\n if (length === 0 && (index === -1 || index === 0)) {\n return 0\n }\n const normalized = index < 0 ? length + index : index\n return normalized >= length || normalized < 0 ? null : normalized\n}\n\n// non-mutating splice\nexport function splice<T>(arr: T[], start: number, deleteCount: number): T[]\nexport function splice<T>(\n arr: T[],\n start: number,\n deleteCount: number,\n items: T[],\n): T[]\nexport function splice<T>(\n arr: T[],\n start: number,\n deleteCount: number,\n items?: T[],\n): T[] {\n const copy = arr.slice()\n copy.splice(start, deleteCount, ...(items || []))\n return copy\n}\n","import {\n type InsertOp,\n type KeyedPathElement,\n type RelativePosition,\n type RemoveOp,\n type ReplaceOp,\n type TruncateOp,\n type UpsertOp,\n} from '../../../mutations/operations/types'\nimport {findTargetIndex, getTargetIdx, splice} from '../../utils/array'\n\nexport function insert<\n O extends InsertOp<unknown[], RelativePosition, number | KeyedPathElement>,\n CurrentValue extends unknown[],\n>(op: O, currentValue: CurrentValue) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"insert()\" on non-array value')\n }\n\n const index = findTargetIndex(currentValue, op.referenceItem)\n if (index === null) {\n throw new Error(`Found no matching array element to insert ${op.position}`)\n }\n // special case for empty arrays\n if (currentValue.length === 0) {\n return op.items\n }\n return splice(currentValue, getTargetIdx(op.position, index), 0, op.items)\n}\n\nexport function upsert<\n O extends UpsertOp<unknown[], RelativePosition, number | KeyedPathElement>,\n CurrentValue extends unknown[],\n>(op: O, currentValue: CurrentValue) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"upsert()\" on non-array value')\n }\n\n if (op.items.length === 0) {\n return currentValue\n }\n const replaceItemsMap: number[] = []\n const insertItems: unknown[] = []\n op.items.forEach((itemToBeUpserted: any, i) => {\n const existingIndex = currentValue.findIndex(\n existingItem => (existingItem as any)?._key === itemToBeUpserted._key,\n )\n if (existingIndex >= 0) {\n replaceItemsMap[existingIndex] = i\n } else {\n insertItems.push(itemToBeUpserted)\n }\n })\n\n if (replaceItemsMap.length === 0 && insertItems.length == 0) {\n return currentValue\n }\n\n const next = [...currentValue]\n // Replace existing items\n for (const i of replaceItemsMap) {\n next[i] = op.items[replaceItemsMap[i]!]!\n }\n\n // Insert the items that doesn't exist\n return insert(\n {\n type: 'insert',\n items: insertItems,\n referenceItem: op.referenceItem,\n position: op.position,\n },\n next,\n )\n}\n\nexport function replace<\n O extends ReplaceOp<unknown[], number | KeyedPathElement>,\n CurrentValue extends unknown[],\n>(op: O, currentValue: CurrentValue) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"replace()\" on non-array value')\n }\n\n const index = findTargetIndex(currentValue, op.referenceItem)\n if (index === null) {\n throw new Error(`Found no matching array element to replace`)\n }\n return splice(currentValue, index, op.items.length, op.items)\n}\nexport function remove<\n O extends RemoveOp<number | KeyedPathElement>,\n CurrentValue extends unknown[],\n>(op: O, currentValue: CurrentValue) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"remove()\" on non-array value')\n }\n\n const index = findTargetIndex(currentValue, op.referenceItem)\n if (index === null) {\n throw new Error(`Found no matching array element to replace`)\n }\n return splice(currentValue, index, 1, [])\n}\n\nexport function truncate<O extends TruncateOp, CurrentValue extends unknown[]>(\n op: O,\n currentValue: CurrentValue,\n) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"truncate()\" on non-array value')\n }\n\n return typeof op.endIndex === 'number'\n ? currentValue\n .slice(0, op.startIndex)\n .concat(currentValue.slice(op.endIndex))\n : currentValue.slice(0, op.startIndex)\n}\n","import {\n type SetIfMissingOp,\n type SetOp,\n type UnsetOp,\n} from '../../../mutations/operations/types'\n\nexport function set<O extends SetOp<any>, CurrentValue>(\n op: O,\n currentValue: CurrentValue,\n) {\n return op.value\n}\n\nexport function setIfMissing<O extends SetIfMissingOp<any>, CurrentValue>(\n op: O,\n currentValue: CurrentValue,\n) {\n return currentValue ?? op.value\n}\n\nexport function unset<O extends UnsetOp, CurrentValue>(op: O) {\n return undefined\n}\n","import {type DecOp, type IncOp} from '../../../mutations/operations/types'\n\nexport function inc<O extends IncOp<number>, CurrentValue extends number>(\n op: O,\n currentValue: CurrentValue,\n) {\n if (typeof currentValue !== 'number') {\n throw new TypeError('Cannot apply \"inc()\" on non-numeric value')\n }\n\n return currentValue + op.amount\n}\n\nexport function dec<O extends DecOp<number>, CurrentValue extends number>(\n op: O,\n currentValue: CurrentValue,\n) {\n if (typeof currentValue !== 'number') {\n throw new TypeError('Cannot apply \"dec()\" on non-numeric value')\n }\n\n return currentValue - op.amount\n}\n","export const hasOwn = Object.prototype.hasOwnProperty.call.bind(\n Object.prototype.hasOwnProperty,\n)\n","import {hasOwn} from './hasOwn'\n\nexport function isEmpty(v: object) {\n for (const key in v) {\n if (hasOwn(v, key)) {\n return false\n }\n }\n return true\n}\n","export function omit<T, K extends keyof T>(val: T, props: K[]): Omit<T, K> {\n const copy = {...val}\n for (const prop of props) {\n delete copy[prop]\n }\n return copy\n}\n","import {\n type AssignOp,\n type UnassignOp,\n} from '../../../mutations/operations/types'\nimport {isObject} from '../../../utils/isObject'\nimport {isEmpty} from '../../utils/isEmpty'\nimport {omit} from '../../utils/omit'\n\nexport function unassign<T extends object, K extends string[]>(\n op: UnassignOp<K>,\n currentValue: T,\n) {\n if (!isObject(currentValue)) {\n throw new TypeError('Cannot apply \"unassign()\" on non-object value')\n }\n\n return op.keys.length === 0\n ? currentValue\n : omit(currentValue, op.keys as any[])\n}\n\nexport function assign<T extends object>(op: AssignOp<T>, currentValue: T) {\n if (!isObject(currentValue)) {\n throw new TypeError('Cannot apply \"assign()\" on non-object value')\n }\n\n return isEmpty(op.value) ? currentValue : {...currentValue, ...op.value}\n}\n","import {applyPatches, parsePatch} from '@sanity/diff-match-patch'\n\nimport {type DiffMatchPatchOp} from '../../../mutations/operations/types'\n\nexport function diffMatchPatch<\n O extends DiffMatchPatchOp,\n CurrentValue extends string,\n>(op: O, currentValue: CurrentValue) {\n if (typeof currentValue !== 'string') {\n throw new TypeError('Cannot apply \"diffMatchPatch()\" on non-string value')\n }\n\n return applyPatches(parsePatch(op.value), currentValue)[0]\n}\n","import {\n type AnyOp,\n type ArrayOp,\n type NumberOp,\n type ObjectOp,\n type Operation,\n type StringOp,\n} from '../../mutations/operations/types'\nimport {type AnyArray} from '../../utils/typeUtils'\nimport * as operations from './operations'\nimport {type ApplyOp} from './typings/applyOp'\n\nexport function applyOp<const Op extends AnyOp, const CurrentValue>(\n op: Op,\n currentValue: CurrentValue,\n): ApplyOp<Op, CurrentValue>\nexport function applyOp<\n const Op extends NumberOp,\n const CurrentValue extends number,\n>(op: Op, currentValue: CurrentValue): ApplyOp<Op, CurrentValue>\nexport function applyOp<\n const Op extends StringOp,\n const CurrentValue extends string,\n>(op: Op, currentValue: CurrentValue): ApplyOp<Op, CurrentValue>\nexport function applyOp<\n const Op extends ObjectOp,\n const CurrentValue extends {[k in keyof any]: unknown},\n>(op: Op, currentValue: CurrentValue): ApplyOp<Op, CurrentValue>\nexport function applyOp<\n const Op extends ArrayOp,\n const CurrentValue extends AnyArray,\n>(op: Op, currentValue: CurrentValue): ApplyOp<Op, CurrentValue>\nexport function applyOp<const Op extends Operation, const CurrentValue>(\n op: Op,\n currentValue: CurrentValue,\n): ApplyOp<Op, CurrentValue> {\n if (!(op.type in operations)) {\n throw new Error(`Invalid operation type: \"${op.type}\"`)\n }\n\n // eslint-disable-next-line import/namespace\n return (operations[op.type] as CallableFunction)(op, currentValue)\n}\n","import {type Operation} from '../../mutations/operations/types'\nimport {type NodePatch, type NodePatchList} from '../../mutations/types'\nimport {isArrayElement, isPropertyElement, stringify} from '../../path'\nimport {isObject} from '../../utils/isObject'\nimport {type NormalizeReadOnlyArray} from '../../utils/typeUtils'\nimport {type KeyedPathElement, type Path} from '../'\nimport {findTargetIndex, splice} from '../utils/array'\nimport {applyOp} from './applyOp'\nimport {\n type ApplyAtPath,\n type ApplyNodePatch,\n type ApplyPatches,\n} from './typings/applyNodePatch'\n\nexport function applyPatches<Patches extends NodePatchList, const Doc>(\n patches: Patches,\n document: Doc,\n): ApplyPatches<NormalizeReadOnlyArray<Patches>, Doc> {\n return (patches as NodePatch[]).reduce(\n (prev, patch) => applyNodePatch(patch, prev) as any,\n document,\n ) as any\n}\n\nexport function applyNodePatch<const Patch extends NodePatch, const Doc>(\n patch: Patch,\n document: Doc,\n): ApplyNodePatch<Patch, Doc> {\n return applyAtPath(patch.path, patch.op, document) as any\n}\n\nfunction applyAtPath<P extends Path, O extends Operation, T>(\n path: P,\n op: O,\n value: T,\n): ApplyAtPath<P, O, T> {\n if (!isNonEmptyArray(path)) {\n return applyOp(op as any, value) as any\n }\n\n const [head, ...tail] = path\n\n if (isArrayElement(head) && Array.isArray(value)) {\n return applyInArray(head, tail, op, value) as any\n }\n\n if (isPropertyElement(head) && isObject(value)) {\n return applyInObject(head, tail, op, value) as any\n }\n\n throw new Error(\n `Cannot apply operation of type \"${op.type}\" to path ${stringify(\n path,\n )} on ${typeof value} value`,\n )\n}\n\nfunction applyInObject<Key extends keyof any, T extends {[key in Key]?: any}>(\n head: Key,\n tail: Path,\n op: Operation,\n object: T,\n) {\n const current = object[head]\n\n if (current === undefined && tail.length > 0) {\n return object\n }\n\n // The patch targets the item at the index specified by \"head\"\n // so forward it to the item\n const patchedValue = applyAtPath(tail, op, current)\n\n // If the result of applying it to the item yields the item back we assume it was\n // a noop and don't modify our value. If we get a new value back, we return a\n // new array with the modified item replaced\n return patchedValue === current ? object : {...object, [head]: patchedValue}\n}\n\nfunction applyInArray<T>(\n head: number | KeyedPathElement,\n tail: Path,\n op: Operation,\n value: T[],\n) {\n const index = findTargetIndex(value, head!)\n\n if (index === null) {\n // partial is default behavior for arrays\n // the patch targets an index that is out of bounds\n return value\n }\n\n // If the given selector could not be found, return as-is\n if (index === -1) {\n return value\n }\n\n const current = value[index]!\n\n // The patch targets the item at the index specified by \"head\"\n // so forward it to the item\n const patchedItem = applyAtPath(tail, op, current)\n\n // If the result of applying it to the item yields the item back we assume it was\n // a noop and don't modify our value. If we get a new value back, we return a\n // new array with the modified item replaced\n return patchedItem === current\n ? value\n : splice(value, index, 1, [patchedItem])\n}\n\nfunction isNonEmptyArray<T>(a: T[] | readonly T[]): a is [T, ...T[]] {\n return a.length > 0\n}\n","import {type PatchMutation, type SanityDocumentBase} from '../mutations/types'\nimport {type NormalizeReadOnlyArray} from '../utils/typeUtils'\nimport {applyPatches} from './patch/applyNodePatch'\nimport {type ApplyPatches} from './patch/typings/applyNodePatch'\n\nexport type ApplyPatchMutation<\n Mutation extends PatchMutation,\n Doc extends SanityDocumentBase,\n> =\n Mutation extends PatchMutation<infer Patches>\n ? ApplyPatches<NormalizeReadOnlyArray<Patches>, Doc>\n : Doc\n\nexport function applyPatchMutation<\n const Mutation extends PatchMutation,\n const Doc extends SanityDocumentBase,\n>(mutation: Mutation, document: Doc): ApplyPatchMutation<Mutation, Doc> {\n if (\n mutation.options?.ifRevision &&\n document._rev !== mutation.options.ifRevision\n ) {\n throw new Error('Revision mismatch')\n }\n if (mutation.id !== document._id) {\n throw new Error(\n `Document id mismatch. Refusing to apply mutation for document with id=\"${mutation.id}\" on the given document with id=\"${document._id}\"`,\n )\n }\n return applyPatches(mutation.patches, document) as any\n}\n","import {type SanityDocumentBase} from '../../mutations/types'\nimport {type StoredDocument} from '../applyInIndex'\n\nexport function hasId(doc: SanityDocumentBase): doc is StoredDocument {\n return '_id' in doc\n}\nexport function assignId<Doc extends SanityDocumentBase>(\n doc: Doc,\n generateId: () => string,\n): Doc & {_id: string} {\n return hasId(doc) ? doc : {...doc, _id: generateId()}\n}\n"],"names":["isKeyedElement","isObject","applyPatches","parsePatch","isArrayElement","isPropertyElement","stringify"],"mappings":";;AAAO,SAAS,MAAM,OAA2B;AAC/C,SACG,UAAU,QACT,OAAO,SAAU,YACjB,OAAO,MAAM,QAAS,YACtB,MAAM,QACR;AAEJ;ACLO,SAAS,gBAAmB,OAAY,aAA0B;AACvE,MAAI,OAAO,eAAgB;AACzB,WAAO,eAAe,MAAM,QAAQ,WAAW;AAEjD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AK,GAIrB,cAAc,YAAY,MAAM,IAAI,OAAO;AAKjD,SAAO,gBAAgB,UACnB,QACA,OAAO,OAAO,OAAO,GAAG,CAAC,WAAW,CAAC;AAC3C;AAEA,SAAS,gBAAmB,GAAyC;AACnE,SAAO,EAAE,SAAS;AACpB;ACrGO,SAAS,mBAGd,UAAoB,UAAkD;AACtE,MACE,SAAS,SAAS,cAClB,SAAS,SAAS,SAAS,QAAQ;AAEnC,UAAM,IAAI,MAAM,mBAAmB;AAErC,MAAI,SAAS,OAAO,SAAS;AAC3B,UAAM,IAAI;AAAA,MACR,0EAA0E,SAAS,EAAE,oCAAoC,SAAS,GAAG;AAAA,IAAA;AAGzI,SAAO,aAAa,SAAS,SAAS,QAAQ;AAChD;AC1BO,SAAS,MAAM,KAAgD;AACpE,SAAO,SAAS;AAClB;AACO,SAAS,SACd,KACA,YACqB;AACrB,SAAO,MAAM,GAAG,IAAI,MAAM,EAAC,GAAG,KAAK,KAAK,aAAW;AACrD;;;;;;;;"} | ||
| {"version":3,"file":"utils.cjs","sources":["../../src/apply/utils/getKeyOf.ts","../../src/apply/utils/array.ts","../../src/apply/utils/omit.ts","../../src/apply/patch/operations/array.ts","../../src/apply/patch/operations/common.ts","../../src/apply/patch/operations/number.ts","../../src/apply/utils/hasOwn.ts","../../src/apply/utils/isEmpty.ts","../../src/apply/patch/operations/object.ts","../../src/apply/patch/operations/string.ts","../../src/apply/patch/applyOp.ts","../../src/apply/patch/applyNodePatch.ts","../../src/apply/applyPatchMutation.ts","../../src/apply/store/utils.ts"],"sourcesContent":["export function keyOf(value: any): string | null {\n return (\n (value !== null &&\n typeof value === 'object' &&\n typeof value._key === 'string' &&\n value._key) ||\n null\n )\n}\n","import {isKeyedElement, type PathElement} from '../../path'\nimport {keyOf} from './getKeyOf'\n\nexport function findTargetIndex<T>(array: T[], pathSegment: PathElement) {\n if (typeof pathSegment === 'number') {\n return normalizeIndex(array.length, pathSegment)\n }\n if (isKeyedElement(pathSegment)) {\n const idx = array.findIndex(value => keyOf(value) === pathSegment._key)\n return idx === -1 ? null : idx\n }\n throw new Error(\n `Expected path segment to be addressing a single array item either by numeric index or by '_key'. Instead saw ${JSON.stringify(\n pathSegment,\n )}`,\n )\n}\n\nexport function getTargetIdx(position: 'before' | 'after', index: number) {\n return position === 'before' ? index : index + 1\n}\n\n// normalizes the index according to the array length\n// returns null if the normalized index is out of bounds\nexport function normalizeIndex(length: number, index: number) {\n if (length === 0 && (index === -1 || index === 0)) {\n return 0\n }\n const normalized = index < 0 ? length + index : index\n return normalized >= length || normalized < 0 ? null : normalized\n}\n\n// non-mutating splice\nexport function splice<T>(arr: T[], start: number, deleteCount: number): T[]\nexport function splice<T>(\n arr: T[],\n start: number,\n deleteCount: number,\n items: T[],\n): T[]\nexport function splice<T>(\n arr: T[],\n start: number,\n deleteCount: number,\n items?: T[],\n): T[] {\n const copy = arr.slice()\n copy.splice(start, deleteCount, ...(items || []))\n return copy\n}\n","export function omit<T, K extends keyof T>(val: T, props: K[]): Omit<T, K> {\n const copy = {...val}\n for (const prop of props) {\n delete copy[prop]\n }\n return copy\n}\n","import {\n type InsertIfMissingOp,\n type InsertOp,\n type KeyedPathElement,\n type RelativePosition,\n type RemoveOp,\n type ReplaceOp,\n type TruncateOp,\n type UpsertOp,\n} from '../../../mutations/operations/types'\nimport {findTargetIndex, getTargetIdx, splice} from '../../utils/array'\n\nexport function insert<\n O extends InsertOp<unknown[], RelativePosition, number | KeyedPathElement>,\n CurrentValue extends unknown[],\n>(op: O, currentValue: CurrentValue) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"insert()\" on non-array value')\n }\n\n const index = findTargetIndex(currentValue, op.referenceItem)\n if (index === null) {\n throw new Error(`Found no matching array element to insert ${op.position}`)\n }\n // special case for empty arrays\n if (currentValue.length === 0) {\n return op.items\n }\n return splice(currentValue, getTargetIdx(op.position, index), 0, op.items)\n}\n\nexport function upsert<\n O extends UpsertOp<{_key: string}[], RelativePosition, KeyedPathElement>,\n CurrentValue extends unknown[],\n>(op: O, currentValue: CurrentValue) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"upsert()\" on non-array value')\n }\n\n if (op.items.length === 0) {\n return currentValue\n }\n const replaceItemsMap: Record<number, number> = {}\n const insertItems: unknown[] = []\n op.items.forEach((itemToBeUpserted: any, i) => {\n const existingIndex = currentValue.findIndex(\n existingItem => (existingItem as any)?._key === itemToBeUpserted._key,\n )\n if (existingIndex >= 0) {\n replaceItemsMap[existingIndex] = i\n } else {\n insertItems.push(itemToBeUpserted)\n }\n })\n\n const itemsToReplace = Object.keys(replaceItemsMap)\n if (itemsToReplace.length === 0 && insertItems.length == 0) {\n return currentValue\n }\n\n const next = [...currentValue]\n // Replace existing items\n for (const i of itemsToReplace) {\n const index = Number(i)\n next[index] = op.items[replaceItemsMap[index]!]!\n }\n\n // Insert the items that doesn't exist\n return insert(\n {\n type: 'insert',\n items: insertItems,\n referenceItem: op.referenceItem,\n position: op.position,\n },\n next,\n )\n}\nexport function insertIfMissing<\n O extends InsertIfMissingOp<\n {_key: string}[],\n RelativePosition,\n KeyedPathElement\n >,\n CurrentValue extends unknown[],\n>(op: O, currentValue: CurrentValue) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"insertIfMissing()\" on non-array value')\n }\n\n if (op.items.length === 0) {\n return currentValue\n }\n const itemsToInsert = op.items.filter(\n item =>\n !currentValue.find(existing => item._key === (existing as any)?._key),\n )\n\n if (itemsToInsert.length === 0) {\n return currentValue\n }\n\n // Insert the items that doesn't exist\n return insert(\n {\n type: 'insert',\n items: itemsToInsert,\n referenceItem: op.referenceItem,\n position: op.position,\n },\n currentValue,\n )\n}\n\nexport function replace<\n O extends ReplaceOp<unknown[], number | KeyedPathElement>,\n CurrentValue extends unknown[],\n>(op: O, currentValue: CurrentValue) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"replace()\" on non-array value')\n }\n\n const index = findTargetIndex(currentValue, op.referenceItem)\n if (index === null) {\n throw new Error(`Found no matching array element to replace`)\n }\n return splice(currentValue, index, op.items.length, op.items)\n}\nexport function remove<\n O extends RemoveOp<number | KeyedPathElement>,\n CurrentValue extends unknown[],\n>(op: O, currentValue: CurrentValue) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"remove()\" on non-array value')\n }\n\n const index = findTargetIndex(currentValue, op.referenceItem)\n if (index === null) {\n throw new Error(`Found no matching array element to replace`)\n }\n return splice(currentValue, index, 1, [])\n}\n\nexport function truncate<O extends TruncateOp, CurrentValue extends unknown[]>(\n op: O,\n currentValue: CurrentValue,\n) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"truncate()\" on non-array value')\n }\n\n return typeof op.endIndex === 'number'\n ? currentValue\n .slice(0, op.startIndex)\n .concat(currentValue.slice(op.endIndex))\n : currentValue.slice(0, op.startIndex)\n}\n","import {\n type SetIfMissingOp,\n type SetOp,\n type UnsetOp,\n} from '../../../mutations/operations/types'\n\nexport function set<O extends SetOp<any>, CurrentValue>(\n op: O,\n currentValue: CurrentValue,\n) {\n return op.value\n}\n\nexport function setIfMissing<O extends SetIfMissingOp<any>, CurrentValue>(\n op: O,\n currentValue: CurrentValue,\n) {\n return currentValue ?? op.value\n}\n\nexport function unset<O extends UnsetOp, CurrentValue>(op: O) {\n return undefined\n}\n","import {type DecOp, type IncOp} from '../../../mutations/operations/types'\n\nexport function inc<O extends IncOp<number>, CurrentValue extends number>(\n op: O,\n currentValue: CurrentValue,\n) {\n if (typeof currentValue !== 'number') {\n throw new TypeError('Cannot apply \"inc()\" on non-numeric value')\n }\n\n return currentValue + op.amount\n}\n\nexport function dec<O extends DecOp<number>, CurrentValue extends number>(\n op: O,\n currentValue: CurrentValue,\n) {\n if (typeof currentValue !== 'number') {\n throw new TypeError('Cannot apply \"dec()\" on non-numeric value')\n }\n\n return currentValue - op.amount\n}\n","export const hasOwn = Object.prototype.hasOwnProperty.call.bind(\n Object.prototype.hasOwnProperty,\n)\n","import {hasOwn} from './hasOwn'\n\nexport function isEmpty(v: object) {\n for (const key in v) {\n if (hasOwn(v, key)) {\n return false\n }\n }\n return true\n}\n","import {\n type AssignOp,\n type UnassignOp,\n} from '../../../mutations/operations/types'\nimport {isObject} from '../../../utils/isObject'\nimport {isEmpty} from '../../utils/isEmpty'\nimport {omit} from '../../utils/omit'\n\nexport function unassign<T extends object, K extends string[]>(\n op: UnassignOp<K>,\n currentValue: T,\n) {\n if (!isObject(currentValue)) {\n throw new TypeError('Cannot apply \"unassign()\" on non-object value')\n }\n\n return op.keys.length === 0\n ? currentValue\n : omit(currentValue, op.keys as any[])\n}\n\nexport function assign<T extends object>(op: AssignOp<T>, currentValue: T) {\n if (!isObject(currentValue)) {\n throw new TypeError('Cannot apply \"assign()\" on non-object value')\n }\n\n return isEmpty(op.value) ? currentValue : {...currentValue, ...op.value}\n}\n","import {applyPatches, parsePatch} from '@sanity/diff-match-patch'\n\nimport {type DiffMatchPatchOp} from '../../../mutations/operations/types'\n\nexport function diffMatchPatch<\n O extends DiffMatchPatchOp,\n CurrentValue extends string,\n>(op: O, currentValue: CurrentValue) {\n if (typeof currentValue !== 'string') {\n throw new TypeError('Cannot apply \"diffMatchPatch()\" on non-string value')\n }\n\n return applyPatches(parsePatch(op.value), currentValue)[0]\n}\n","import {\n type AnyOp,\n type ArrayOp,\n type NumberOp,\n type ObjectOp,\n type Operation,\n type StringOp,\n} from '../../mutations/operations/types'\nimport {type AnyArray} from '../../utils/typeUtils'\nimport * as operations from './operations'\nimport {type ApplyOp} from './typings/applyOp'\n\nexport function applyOp<const Op extends AnyOp, const CurrentValue>(\n op: Op,\n currentValue: CurrentValue,\n): ApplyOp<Op, CurrentValue>\nexport function applyOp<\n const Op extends NumberOp,\n const CurrentValue extends number,\n>(op: Op, currentValue: CurrentValue): ApplyOp<Op, CurrentValue>\nexport function applyOp<\n const Op extends StringOp,\n const CurrentValue extends string,\n>(op: Op, currentValue: CurrentValue): ApplyOp<Op, CurrentValue>\nexport function applyOp<\n const Op extends ObjectOp,\n const CurrentValue extends {[k in keyof any]: unknown},\n>(op: Op, currentValue: CurrentValue): ApplyOp<Op, CurrentValue>\nexport function applyOp<\n const Op extends ArrayOp,\n const CurrentValue extends AnyArray,\n>(op: Op, currentValue: CurrentValue): ApplyOp<Op, CurrentValue>\nexport function applyOp<const Op extends Operation, const CurrentValue>(\n op: Op,\n currentValue: CurrentValue,\n): ApplyOp<Op, CurrentValue> {\n if (!(op.type in operations)) {\n throw new Error(`Invalid operation type: \"${op.type}\"`)\n }\n\n // eslint-disable-next-line import/namespace\n return (operations[op.type] as CallableFunction)(op, currentValue)\n}\n","import {type Operation} from '../../mutations/operations/types'\nimport {type NodePatch, type NodePatchList} from '../../mutations/types'\nimport {isArrayElement, isPropertyElement, stringify} from '../../path'\nimport {isObject} from '../../utils/isObject'\nimport {type NormalizeReadOnlyArray} from '../../utils/typeUtils'\nimport {type KeyedPathElement, type Path} from '../'\nimport {findTargetIndex, splice} from '../utils/array'\nimport {omit} from '../utils/omit'\nimport {applyOp} from './applyOp'\nimport {\n type ApplyAtPath,\n type ApplyNodePatch,\n type ApplyPatches,\n} from './typings/applyNodePatch'\n\nexport function applyPatches<Patches extends NodePatchList, const Doc>(\n patches: Patches,\n document: Doc,\n): ApplyPatches<NormalizeReadOnlyArray<Patches>, Doc> {\n return (patches as NodePatch[]).reduce(\n (prev, patch) => applyNodePatch(patch, prev) as any,\n document,\n ) as any\n}\n\nexport function applyNodePatch<const Patch extends NodePatch, const Doc>(\n patch: Patch,\n document: Doc,\n): ApplyNodePatch<Patch, Doc> {\n return applyAtPath(patch.path, patch.op, document) as any\n}\n\nfunction applyAtPath<P extends Path, O extends Operation, T>(\n path: P,\n op: O,\n value: T,\n): ApplyAtPath<P, O, T> {\n if (!isNonEmptyArray(path)) {\n return applyOp(op as any, value) as any\n }\n\n const [head, ...tail] = path\n\n if (isArrayElement(head) && Array.isArray(value)) {\n return applyInArray(head, tail, op, value) as any\n }\n\n if (isPropertyElement(head) && isObject(value)) {\n return applyInObject(head, tail, op, value) as any\n }\n\n throw new Error(\n `Cannot apply operation of type \"${op.type}\" to path ${stringify(\n path,\n )} on ${typeof value} value`,\n )\n}\n\nfunction applyInObject<Key extends keyof any, T extends {[key in Key]?: any}>(\n head: Key,\n tail: Path,\n op: Operation,\n object: T,\n) {\n const current = object[head]\n\n if (current === undefined && tail.length > 0) {\n return object\n }\n\n // The patch targets the item at the index specified by \"head\"\n // so forward it to the item\n const patchedValue = applyAtPath(tail, op, current)\n\n if (patchedValue === undefined) {\n // unset op on an object field should not leave the field undefined\n // eg. apply(at('bar', unset()), {foo: 1, bar: 2, baz: 3} should result in\n // {foo: 1, baz: 3}, not {foo: 1, bar: undefined, baz: 3}\n\n return omit(object, [head])\n }\n // If the result of applying it to the item yields the item back we assume it was\n // a noop and don't modify our value. If we get a new value back, we return a\n // new array with the modified item replaced\n return patchedValue === current ? object : {...object, [head]: patchedValue}\n}\n\nfunction applyInArray<T>(\n head: number | KeyedPathElement,\n tail: Path,\n op: Operation,\n value: T[],\n) {\n const index = findTargetIndex(value, head!)\n\n if (index === null) {\n // partial is default behavior for arrays\n // the patch targets an index that is out of bounds\n return value\n }\n\n // If the given selector could not be found, return as-is\n if (index === -1) {\n return value\n }\n\n const current = value[index]!\n\n // The patch targets the item at the index specified by \"head\"\n // so forward it to the item\n const patchedItem = applyAtPath(tail, op, current)\n\n // If the result of applying it to the item yields the item back we assume it was\n // a noop and don't modify our value. If we get a new value back, we return a\n // new array with the modified item replaced\n return patchedItem === current\n ? value\n : splice(\n value,\n index,\n 1,\n // unset op on an array item should not leave a \"hole\" in the array\n // eg. apply(at('someArray[1]', unset()), ['foo', 'bar', 'baz'] should result in\n // ['foo', 'baz'], not ['foo', undefined, 'baz']\n patchedItem === undefined ? [] : [patchedItem],\n )\n}\n\nfunction isNonEmptyArray<T>(a: T[] | readonly T[]): a is [T, ...T[]] {\n return a.length > 0\n}\n","import {type PatchMutation, type SanityDocumentBase} from '../mutations/types'\nimport {type NormalizeReadOnlyArray} from '../utils/typeUtils'\nimport {applyPatches} from './patch/applyNodePatch'\nimport {type ApplyPatches} from './patch/typings/applyNodePatch'\n\nexport type ApplyPatchMutation<\n Mutation extends PatchMutation,\n Doc extends SanityDocumentBase,\n> =\n Mutation extends PatchMutation<infer Patches>\n ? ApplyPatches<NormalizeReadOnlyArray<Patches>, Doc>\n : Doc\n\nexport function applyPatchMutation<\n const Mutation extends PatchMutation,\n const Doc extends SanityDocumentBase,\n>(mutation: Mutation, document: Doc): ApplyPatchMutation<Mutation, Doc> {\n if (\n mutation.options?.ifRevision &&\n document._rev !== mutation.options.ifRevision\n ) {\n throw new Error('Revision mismatch')\n }\n if (mutation.id !== document._id) {\n throw new Error(\n `Document id mismatch. Refusing to apply mutation for document with id=\"${mutation.id}\" on the given document with id=\"${document._id}\"`,\n )\n }\n return applyPatches(mutation.patches, document) as any\n}\n","import {type SanityDocumentBase} from '../../mutations/types'\nimport {type StoredDocument} from '../applyInIndex'\n\nexport function hasId(doc: SanityDocumentBase): doc is StoredDocument {\n return '_id' in doc\n}\nexport function assignId<Doc extends SanityDocumentBase>(\n doc: Doc,\n generateId: () => string,\n): Doc & {_id: string} {\n return hasId(doc) ? doc : {...doc, _id: generateId()}\n}\n"],"names":["isKeyedElement","isObject","applyPatches","parsePatch","isArrayElement","isPropertyElement","stringify"],"mappings":";;AAAO,SAAS,MAAM,OAA2B;AAC/C,SACG,UAAU,QACT,OAAO,SAAU,YACjB,OAAO,MAAM,QAAS,YACtB,MAAM,QACR;AAEJ;ACLO,SAAS,gBAAmB,OAAY,aAA0B;AACvE,MAAI,OAAO,eAAgB;AACzB,WAAO,eAAe,MAAM,QAAQ,WAAW;AAEjD,MAAIA,UAAAA,eAAe,WAAW,GAAG;AAC/B,UAAM,MAAM,MAAM,UAAU,CAAA,UAAS,MAAM,KAAK,MAAM,YAAY,IAAI;AACtE,WAAO,QAAQ,KAAK,OAAO;AAAA,EAC7B;AACA,QA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A;AACA,QAAM,UAAU,OAAO,IAAI;AAE3B,MAAI,YAAY,UAAa,KAAK,SAAS;AACzC,WAAO;AAKT,QAAM,eAAe,YAAY,MAAM,IAAI,OAAO;AAElD,SAAI,iBAAiB,SAKZ,KAAK,QAAQ,CAAC,IAAI,CAAC,IAKrB,iBAAiB,UAAU,SAAS,EAAC,GAAG,QAAQ,CAAC,IAAI,GAAG,aAAA;AACjE;AAEA,SAAS,aACP,MACA,MACA,IACA,OACA;AACA,QAAM,QAAQ,gBAAgB,OAAO,IAAK;AAS1C,MAPI,UAAU,QAOV,UAAU;AACZ,WAAO;AAGT,QAAM,UAAU,MAAM,KAAK,GAIrB,cAAc,YAAY,MAAM,IAAI,OAAO;AAKjD,SAAO,gBAAgB,UACnB,QACA;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA;AAAA;AAAA;AAAA,IAIA,gBAAgB,SAAY,CAAA,IAAK,CAAC,WAAW;AAAA,EAAA;AAErD;AAEA,SAAS,gBAAmB,GAAyC;AACnE,SAAO,EAAE,SAAS;AACpB;ACrHO,SAAS,mBAGd,UAAoB,UAAkD;AACtE,MACE,SAAS,SAAS,cAClB,SAAS,SAAS,SAAS,QAAQ;AAEnC,UAAM,IAAI,MAAM,mBAAmB;AAErC,MAAI,SAAS,OAAO,SAAS;AAC3B,UAAM,IAAI;AAAA,MACR,0EAA0E,SAAS,EAAE,oCAAoC,SAAS,GAAG;AAAA,IAAA;AAGzI,SAAO,aAAa,SAAS,SAAS,QAAQ;AAChD;AC1BO,SAAS,MAAM,KAAgD;AACpE,SAAO,SAAS;AAClB;AACO,SAAS,SACd,KACA,YACqB;AACrB,SAAO,MAAM,GAAG,IAAI,MAAM,EAAC,GAAG,KAAK,KAAK,aAAW;AACrD;;;;;;;;"} |
@@ -42,3 +42,5 @@ import { AnyArray, Index, KeyedPathElement, Optional, Path } from "./types.cjs"; | ||
| }; | ||
| type UpsertOp<Items extends AnyArray, Pos extends RelativePosition, ReferenceItem extends Index | KeyedPathElement> = { | ||
| type UpsertOp<Items extends AnyArray<{ | ||
| _key: string; | ||
| }>, Pos extends RelativePosition, ReferenceItem extends Index | KeyedPathElement> = { | ||
| type: 'upsert'; | ||
@@ -49,2 +51,10 @@ items: Items; | ||
| }; | ||
| type InsertIfMissingOp<Items extends AnyArray<{ | ||
| _key: string; | ||
| }>, Pos extends RelativePosition, ReferenceItem extends Index | KeyedPathElement> = { | ||
| type: 'insertIfMissing'; | ||
| items: Items; | ||
| referenceItem: ReferenceItem; | ||
| position: Pos; | ||
| }; | ||
| type AssignOp<T extends object = object> = { | ||
@@ -67,3 +77,3 @@ type: 'assign'; | ||
| type ObjectOp = AssignOp | UnassignOp; | ||
| type ArrayOp = InsertOp<AnyArray, RelativePosition, Index | KeyedPathElement> | UpsertOp<AnyArray, RelativePosition, Index | KeyedPathElement> | ReplaceOp<AnyArray, Index | KeyedPathElement> | TruncateOp | RemoveOp<Index | KeyedPathElement>; | ||
| type ArrayOp = InsertOp<AnyArray, RelativePosition, Index | KeyedPathElement> | UpsertOp<AnyArray, RelativePosition, Index | KeyedPathElement> | InsertIfMissingOp<AnyArray, RelativePosition, Index | KeyedPathElement> | ReplaceOp<AnyArray, Index | KeyedPathElement> | TruncateOp | RemoveOp<Index | KeyedPathElement>; | ||
| type PrimitiveOp = AnyOp | StringOp | NumberOp; | ||
@@ -115,3 +125,3 @@ type NodePatchList = [NodePatch, ...NodePatch[]] | NodePatch[] | readonly NodePatch[] | readonly [NodePatch, ...NodePatch[]]; | ||
| } | ||
| export { AnyOp, ArrayOp, AssignOp, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, IdentifiedSanityDocument, IncOp, InsertOp, Mutation, NodePatch, NodePatchList, NumberOp, ObjectOp, Operation, PatchMutation, PatchOptions, PrimitiveOp, RelativePosition, RemoveOp, ReplaceOp, SanityDocumentBase, SetIfMissingOp, SetOp, StringOp, Transaction, TruncateOp, UnassignOp, UnsetOp, UpsertOp }; | ||
| export { AnyOp, ArrayOp, AssignOp, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, IdentifiedSanityDocument, IncOp, InsertIfMissingOp, InsertOp, Mutation, NodePatch, NodePatchList, NumberOp, ObjectOp, Operation, PatchMutation, PatchOptions, PrimitiveOp, RelativePosition, RemoveOp, ReplaceOp, SanityDocumentBase, SetIfMissingOp, SetOp, StringOp, Transaction, TruncateOp, UnassignOp, UnsetOp, UpsertOp }; | ||
| //# sourceMappingURL=types2.d.cts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"types2.d.cts","names":[],"sources":["../../src/mutations/operations/types.ts","../../src/mutations/types.ts"],"sourcesContent":[],"mappings":";AAUY,KALA,KAKO,CAAA,CAAA,CAAA,GAAA;EAIP,IAAA,EAAA,KAAA;EAKA,KAAA,EAZH,CAYQ;AAKjB,CAAA;AAKY,KAnBA,OAAA,GAmBA;EAEA,IAAA,EAAA,OAAQ;CAAA;AACJ,KAlBJ,cAkBI,CAAA,CAAA,CAAA,GAAA;MACF,EAAA,cAAA;OACU,EAlBf,CAkBe;;AAGP,KAlBL,KAkBK,CAAA,eAAA,MAAA,CAAA,GAAA;MACL,EAAA,KAAA;QACH,EAlBC,MAkBD;CAAK;AAGF,KAlBA,KAkBU,CAAA,eAAA,MAAA,CAAA,GAAA;EAMV,IAAA,EAAA,KAAQ;EAAA,MAAA,EAtBV,MAsBU;;AAA+B,KAnBvC,gBAAA,GAmBuC,QAAA,GAAA,OAAA;AAElC,KAnBL,QAmBK,CAAA,cAlBD,QAkBC,EAAA,YAjBH,gBAiBG,EAAA,sBAhBO,KAgBP,GAhBe,gBAgBf,CAAA,GAAA;EAAa,IAAA,EAAA,QAAA;EAGlB,aAAS,EAhBJ,aAgBI;EAAA,QAAA,EAfT,GAeS;OACL,EAfP,KAeO;;AACgB,KAbpB,UAAA,GAaoB;MAGf,EAAA,UAAA;YACR,EAAA,MAAA;EAAK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G,CAAA,GAAA;MAElC,EAAA,iBAAA;EAAa,QAAA,EChBlB,GDgBkB;AAG9B,CAAA;AAAqB,KChBT,cAAA,GDgBS;MACL,EAAA,QAAA;MACQ,MAAA;;AAGP,KChBL,aDgBK,CAAA,gBChByB,aDgBzB,GChByC,aDgBzC,CAAA,GAAA;MACR,EAAA,OAAA;EAAK,EAAA,EAAA,MAAA;EAGF,OAAA,ECjBD,ODiBS;EAAA,OAAA,CAAA,EChBR,YDgBQ;;AAEN,KCfF,QDeE,CAAA,YCfmB,kBDenB,GAAA,GAAA,CAAA,GCdV,cDcU,CCdK,GDcL,CAAA,GCbV,yBDaU,CCbgB,GDahB,CAAA,GCZV,uBDYU,CCZc,GDYd,CAAA,GCXV,cDWU,GCVV,aDUU;AACU,KCTZ,SDSY,CAAA,UCRZ,IDQY,GCRL,IDQK,EAAA,UCPZ,SDOY,GCPA,SDOA,CAAA,GAAA;MAAQ,ECLxB,CDKwB;MCJ1B,CDOG;;AAEG,KCNA,YAAA,GDMA;EAAG,UAAA,CAAA,EAAA,MAAA;AAGf,CAAA;AAA6B,UCLZ,WAAA,CDKY;KACb,EAAA,MAAA;WACF,ECLD,QDKC,EAAA"} |
@@ -42,3 +42,5 @@ import { AnyArray, Index, KeyedPathElement, Optional, Path } from "./types.js"; | ||
| }; | ||
| type UpsertOp<Items extends AnyArray, Pos extends RelativePosition, ReferenceItem extends Index | KeyedPathElement> = { | ||
| type UpsertOp<Items extends AnyArray<{ | ||
| _key: string; | ||
| }>, Pos extends RelativePosition, ReferenceItem extends Index | KeyedPathElement> = { | ||
| type: 'upsert'; | ||
@@ -49,2 +51,10 @@ items: Items; | ||
| }; | ||
| type InsertIfMissingOp<Items extends AnyArray<{ | ||
| _key: string; | ||
| }>, Pos extends RelativePosition, ReferenceItem extends Index | KeyedPathElement> = { | ||
| type: 'insertIfMissing'; | ||
| items: Items; | ||
| referenceItem: ReferenceItem; | ||
| position: Pos; | ||
| }; | ||
| type AssignOp<T extends object = object> = { | ||
@@ -67,3 +77,3 @@ type: 'assign'; | ||
| type ObjectOp = AssignOp | UnassignOp; | ||
| type ArrayOp = InsertOp<AnyArray, RelativePosition, Index | KeyedPathElement> | UpsertOp<AnyArray, RelativePosition, Index | KeyedPathElement> | ReplaceOp<AnyArray, Index | KeyedPathElement> | TruncateOp | RemoveOp<Index | KeyedPathElement>; | ||
| type ArrayOp = InsertOp<AnyArray, RelativePosition, Index | KeyedPathElement> | UpsertOp<AnyArray, RelativePosition, Index | KeyedPathElement> | InsertIfMissingOp<AnyArray, RelativePosition, Index | KeyedPathElement> | ReplaceOp<AnyArray, Index | KeyedPathElement> | TruncateOp | RemoveOp<Index | KeyedPathElement>; | ||
| type PrimitiveOp = AnyOp | StringOp | NumberOp; | ||
@@ -115,3 +125,3 @@ type NodePatchList = [NodePatch, ...NodePatch[]] | NodePatch[] | readonly NodePatch[] | readonly [NodePatch, ...NodePatch[]]; | ||
| } | ||
| export { AnyOp, ArrayOp, AssignOp, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, IdentifiedSanityDocument, IncOp, InsertOp, Mutation, NodePatch, NodePatchList, NumberOp, ObjectOp, Operation, PatchMutation, PatchOptions, PrimitiveOp, RelativePosition, RemoveOp, ReplaceOp, SanityDocumentBase, SetIfMissingOp, SetOp, StringOp, Transaction, TruncateOp, UnassignOp, UnsetOp, UpsertOp }; | ||
| export { AnyOp, ArrayOp, AssignOp, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, IdentifiedSanityDocument, IncOp, InsertIfMissingOp, InsertOp, Mutation, NodePatch, NodePatchList, NumberOp, ObjectOp, Operation, PatchMutation, PatchOptions, PrimitiveOp, RelativePosition, RemoveOp, ReplaceOp, SanityDocumentBase, SetIfMissingOp, SetOp, StringOp, Transaction, TruncateOp, UnassignOp, UnsetOp, UpsertOp }; | ||
| //# sourceMappingURL=types2.d.ts.map |
@@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dV,cDcU,CCdK,GDcL,CAAA,GCbV,yBDaU,CCbgB,GDahB,CAAA,GCZV,uBDYU,CCZc,GDYd,CAAA,GCXV,cDWU,GCVV,aDUU;AACU,KCTZ,SDSY,CAAA,UCRZ,IDQY,GCRL,IDQK,EAAA,UCPZ,SDOY,GCPA,SDOA,CAAA,GAAA;MAAQ,ECLxB,CDKwB;MCJ1B,CDOG;;AAEG,KCNA,YAAA,GDMA;EAAG,UAAA,CAAA,EAAA,MAAA;AAGf,CAAA;AAA6B,UCLZ,WAAA,CDKY;KACb,EAAA,MAAA;WACF,ECLD,QDKC,EAAA"} |
@@ -241,3 +241,3 @@ import { parse } from "./parse.js"; | ||
| }; | ||
| throw new Error(`Unknown operation type ${op.type}`); | ||
| throw op.type === "insertIfMissing" ? new Error("Patch type insertIfMissing is not supported by Sanity") : new Error(`Unknown operation type ${op.type}`); | ||
| } | ||
@@ -244,0 +244,0 @@ export { |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"encode.js","sources":["../../src/encoders/sanity/decode.ts","../../src/encoders/sanity/encode.ts"],"sourcesContent":["import {type PatchOperations} from '@sanity/client'\n\nimport {type SetIfMissingOp, type SetOp} from '../../mutations/operations/types'\nimport {\n type IdentifiedSanityDocument,\n type Mutation,\n type NodePatch,\n type SanityDocumentBase,\n} from '../../mutations/types'\nimport {parse as parsePath} from '../../path/parser/parse'\nimport {\n type Insert,\n type SanityCreateIfNotExistsMutation,\n type SanityCreateMutation,\n type SanityCreateOrReplaceMutation,\n type SanityDecPatch,\n type SanityDeleteMutation,\n type SanityDiffMatchPatch,\n type SanityIncPatch,\n type SanityInsertPatch,\n type SanityMutation,\n type SanityPatch,\n type SanitySetIfMissingPatch,\n type SanitySetPatch,\n type SanityUnsetPatch,\n} from './types'\n\nexport type {Mutation, SanityDocumentBase}\n\nfunction isCreateIfNotExistsMutation(\n sanityMutation: SanityMutation,\n): sanityMutation is SanityCreateIfNotExistsMutation {\n return 'createIfNotExists' in sanityMutation\n}\n\nfunction isCreateOrReplaceMutation<Doc extends IdentifiedSanityDocument>(\n sanityMutation: SanityMutation,\n): sanityMutation is SanityCreateOrReplaceMutation<Doc> {\n return 'createOrReplace' in sanityMutation\n}\n\nfunction isCreateMutation<Doc extends SanityDocumentBase>(\n sanityMutation: SanityMutation<Doc>,\n): sanityMutation is SanityCreateMutation<Doc> {\n return 'create' in sanityMutation\n}\n\nfunction isDeleteMutation(\n sanityMutation: SanityMutation<any>,\n): sanityMutation is SanityDeleteMutation {\n return 'delete' in sanityMutation\n}\n\nfunction isPatchMutation(sanityMutation: SanityMutation): sanityMutation is {\n patch: SanityPatch\n} {\n return 'patch' in sanityMutation\n}\n\nfunction isSetPatch(\n sanityPatch: PatchOperations,\n): sanityPatch is SanitySetPatch {\n return 'set' in sanityPatch\n}\n\nfunction isSetIfMissingPatch(\n sanityPatch: SanityPatch,\n): sanityPatch is SanitySetIfMissingPatch {\n return 'setIfMissing' in sanityPatch\n}\n\nfunction isDiffMatchPatch(\n sanityPatch: SanityPatch,\n): sanityPatch is SanityDiffMatchPatch {\n return 'diffMatchPatch' in sanityPatch\n}\n\nfunction isUnsetPatch(\n sanityPatch: SanityPatch,\n): sanityPatch is SanityUnsetPatch {\n return 'unset' in sanityPatch\n}\n\nfunction isIncPatch(sanityPatch: SanityPatch): sanityPatch is SanityIncPatch {\n return 'inc' in sanityPatch\n}\n\nfunction isDecPatch(sanityPatch: SanityPatch): sanityPatch is SanityDecPatch {\n return 'inc' in sanityPatch\n}\n\nfunction isInsertPatch(\n sanityPatch: SanityPatch,\n): sanityPatch is SanityInsertPatch {\n return 'insert' in sanityPatch\n}\n\nexport function decodeAll<Doc extends SanityDocumentBase>(\n sanityMutations: SanityMutation<Doc>[],\n) {\n return sanityMutations.map(decodeMutation)\n}\n\nexport function decode<Doc extends SanityDocumentBase>(\n encodedMutation: SanityMutation<Doc>,\n) {\n return decodeMutation(encodedMutation)\n}\n\nfunction decodeMutation<Doc extends SanityDocumentBase>(\n encodedMutation: SanityMutation<Doc>,\n): Mutation {\n if (isCreateIfNotExistsMutation(encodedMutation)) {\n return {\n type: 'createIfNotExists',\n document: encodedMutation.createIfNotExists,\n }\n }\n if (isCreateOrReplaceMutation(encodedMutation)) {\n return {\n type: 'createOrReplace',\n document: encodedMutation.createOrReplace,\n }\n }\n if (isCreateMutation(encodedMutation)) {\n return {type: 'create', document: encodedMutation.create}\n }\n if (isDeleteMutation(encodedMutation)) {\n return {id: encodedMutation.delete.id, type: 'delete'}\n }\n if (isPatchMutation(encodedMutation)) {\n return {\n type: 'patch',\n id: encodedMutation.patch.id,\n patches: decodeNodePatches(encodedMutation.patch),\n }\n }\n throw new Error(`Unknown mutation: ${JSON.stringify(encodedMutation)}`)\n}\n\nconst POSITION_KEYS = ['before', 'replace', 'after'] as const\n\nfunction getInsertPosition(insert: Insert) {\n const positions = POSITION_KEYS.filter(k => k in insert)\n if (positions.length > 1) {\n throw new Error(\n `Insert patch is ambiguous. Should only contain one of: ${POSITION_KEYS.join(\n ', ',\n )}, instead found ${positions.join(', ')}`,\n )\n }\n return positions[0]\n}\n\nfunction decodeNodePatches<T>(patch: SanityPatch): NodePatch<any, any>[] {\n // If multiple patches are included, then the order of execution is as follows\n // set, setIfMissing, unset, inc, dec, insert.\n // order is defined here: https://www.sanity.io/docs/http-mutations#2f480b2baca5\n return [\n ...getSetPatches(patch),\n ...getSetIfMissingPatches(patch),\n ...getUnsetPatches(patch),\n ...getIncPatches(patch),\n ...getDecPatches(patch),\n ...getInsertPatches(patch),\n ...getDiffMatchPatchPatches(patch),\n ]\n}\n\nfunction getSetPatches(patch: PatchOperations): NodePatch<any[], SetOp<any>>[] {\n return isSetPatch(patch)\n ? Object.keys(patch.set).map(path => ({\n path: parsePath(path),\n op: {type: 'set', value: patch.set[path]},\n }))\n : []\n}\n\nfunction getSetIfMissingPatches(\n patch: SanityPatch,\n): NodePatch<any[], SetIfMissingOp<any>>[] {\n return isSetIfMissingPatch(patch)\n ? Object.keys(patch.setIfMissing).map(path => ({\n path: parsePath(path),\n op: {type: 'setIfMissing', value: patch.setIfMissing[path]},\n }))\n : []\n}\n\nfunction getDiffMatchPatchPatches(patch: SanityPatch) {\n return isDiffMatchPatch(patch)\n ? Object.keys(patch.diffMatchPatch).map(path => ({\n path: parsePath(path),\n op: {type: 'diffMatchPatch', value: patch.diffMatchPatch[path]},\n }))\n : []\n}\n\nfunction getUnsetPatches(patch: SanityPatch) {\n return isUnsetPatch(patch)\n ? patch.unset.map(path => ({\n path: parsePath(path),\n op: {type: 'unset'},\n }))\n : []\n}\n\nfunction getIncPatches(patch: SanityPatch) {\n return isIncPatch(patch)\n ? Object.keys(patch.inc).map(path => ({\n path: parsePath(path),\n op: {type: 'inc', amount: patch.inc[path]},\n }))\n : []\n}\n\nfunction getDecPatches(patch: SanityPatch) {\n return isDecPatch(patch)\n ? Object.keys(patch.dec).map(path => ({\n path: parsePath(path),\n op: {type: 'dec', amount: patch.dec[path]},\n }))\n : []\n}\n\nfunction getInsertPatches(patch: SanityPatch) {\n if (!isInsertPatch(patch)) {\n return []\n }\n const position = getInsertPosition(patch.insert)\n if (!position) {\n throw new Error('Insert patch missing position')\n }\n\n const path: string[] = parsePath((patch.insert as any)[position]!)\n const referenceItem = path.pop()\n\n const op =\n position === 'replace'\n ? {\n type: 'insert',\n position: position,\n referenceItem,\n items: patch.insert.items,\n }\n : {\n type: 'insert',\n position: position,\n referenceItem,\n items: patch.insert.items,\n }\n\n return [{path, op}]\n}\n","import {type PatchMutationOperation} from '@sanity/client'\n\nimport {\n type Mutation,\n type NodePatch,\n type Transaction,\n} from '../../mutations/types'\nimport {stringify as stringifyPath} from '../../path/parser/stringify'\nimport {type SanityMutation} from './types'\n\nexport function encode(mutation: Mutation): SanityMutation[] | SanityMutation {\n return encodeMutation(mutation)\n}\n\nexport function encodeAll(mutations: Mutation[]): SanityMutation[] {\n return mutations.flatMap(encode)\n}\n\nexport function encodeTransaction(transaction: Transaction) {\n return {\n transactionId: transaction.id,\n mutations: encodeAll(transaction.mutations),\n }\n}\n\nexport function encodeMutation(\n mutation: Mutation,\n): SanityMutation[] | SanityMutation {\n switch (mutation.type) {\n case 'create':\n return {[mutation.type]: mutation.document}\n case 'createIfNotExists':\n return {[mutation.type]: mutation.document}\n case 'createOrReplace':\n return {[mutation.type]: mutation.document}\n case 'delete':\n return {\n delete: {id: mutation.id},\n }\n case 'patch': {\n const ifRevisionID = mutation.options?.ifRevision\n return mutation.patches.map(patch => {\n return {\n patch: {\n id: mutation.id,\n ...(ifRevisionID && {ifRevisionID}),\n ...patchToSanity(patch),\n },\n } as {id: string; patch: PatchMutationOperation}\n })\n }\n }\n}\n\nfunction patchToSanity(patch: NodePatch) {\n const {path, op} = patch\n if (op.type === 'unset') {\n return {unset: [stringifyPath(path)]}\n }\n if (op.type === 'insert') {\n return {\n insert: {\n [op.position]: stringifyPath([...path, op.referenceItem]),\n items: op.items,\n },\n }\n }\n if (op.type === 'diffMatchPatch') {\n return {diffMatchPatch: {[stringifyPath(path)]: op.value}}\n }\n if (op.type === 'inc') {\n return {inc: {[stringifyPath(path)]: op.amount}}\n }\n if (op.type === 'dec') {\n return {dec: {[stringifyPath(path)]: op.amount}}\n }\n if (op.type === 'set' || op.type === 'setIfMissing') {\n return {[op.type]: {[stringifyPath(path)]: op.value}}\n }\n if (op.type === 'truncate') {\n const range = [\n op.startIndex,\n typeof op.endIndex === 'number' ? op.endIndex : '',\n ].join(':')\n\n return {unset: [`${stringifyPath(path)}[${range}]`]}\n }\n if (op.type === 'upsert') {\n // note: upsert currently not supported by sanity, so will always insert at reference position\n return {\n unset: op.items.map(item =>\n stringifyPath([...path, {_key: (item as any)._key}]),\n ),\n insert: {\n [op.position]: stringifyPath([...path, op.referenceItem]),\n items: op.items,\n },\n }\n }\n if (op.type === 'assign') {\n return {\n set: Object.fromEntries(\n Object.keys(op.value).map(key => [\n stringifyPath(path.concat(key)),\n op.value[key as keyof typeof op.value],\n ]),\n ),\n }\n }\n if (op.type === 'unassign') {\n return {\n unset: op.keys.map(key => stringifyPath(path.concat(key))),\n }\n }\n if (op.type === 'replace') {\n return {\n insert: {\n replace: stringifyPath(path.concat(op.referenceItem)),\n items: op.items,\n },\n }\n }\n if (op.type === 'remove') {\n return {\n unset: [stringifyPath(path.concat(op.referenceItem))],\n }\n }\n //@ts-expect-error all cases should be covered\n throw new Error(`Unknown operation type ${op.type}`)\n}\n"],"names":["parsePath","stringifyPath"],"mappings":";;AA6BA,SAAS,4BACP,gBACmD;AACnD,SAAO,uBAAuB;AAChC;AAEA,SAAS,0BACP,gBACsD;AACtD,SAAO,qBAAqB;AAC9B;AAEA,SAAS,iBACP,gBAC6C;AAC7C,SAAO,YAAY;AACrB;AAEA,SAAS,iBACP,gBACwC;AACxC,SAAO,YAAY;AACrB;AAEA,SAAS,gBAAgB,gBAEvB;AACA,SAAO,WAAW;AACpB;AAEA,SAAS,WACP,aAC+B;AAC/B,SAAO,SAAS;AAClB;AAEA,SAAS,oBACP,aACwC;AACxC,SAAO,kBAAkB;AAC3B;AAEA,SAAS,iBACP,aACqC;AACrC,SAAO,oBAAoB;AAC7B;AAEA,SAAS,aACP,aACiC;AACjC,SAAO,WAAW;AACpB;AAEA,SAAS,WAAW,aAAyD;AAC3E,SAAO,SAAS;AAClB;AAEA,SAAS,WAAW,aAAyD;AAC3E,SAAO,SAAS;AAClB;AAEA,SAAS,cACP,aACkC;AAClC,SAAO,YAAY;AACrB;AAEO,SAAS,UACd,iBACA;AACA,SAAO,gBAAgB,IAAI,cAAc;AAC3C;AAEO,SAAS,OACd,iBACA;AACA,SAAO,eAAe,eAAe;AACvC;AAEA,SAAS,eACP,iBACU;AACV,MAAI,4BAA4B,eAAe;AAC7C,WAAO;AAAA,MACL,MAAM;AAAA,MACN,UAAU,gBAAgB;AAAA,IAAA;AAG9B,MAAI,0BAA0B,eAAe;AAC3C,WAAO;AAAA,MACL,MAAM;AAAA,MACN,UAAU,gBAAgB;AAAA,IAAA;AAG9B,MAAI,iBAAiB,eAAe;AACl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,GAAG,SAAS;AACd,WAAO;AAAA,MACL,KAAK,OAAO;AAAA,QACV,OAAO,KAAK,GAAG,KAAK,EAAE,IAAI,CAAA,QAAO;AAAA,UAC/BA,UAAc,KAAK,OAAO,GAAG,CAAC;AAAA,UAC9B,GAAG,MAAM,GAA4B;AAAA,QAAA,CACtC;AAAA,MAAA;AAAA,IACH;AAGJ,MAAI,GAAG,SAAS;AACd,WAAO;AAAA,MACL,OAAO,GAAG,KAAK,IAAI,CAAA,QAAOA,UAAc,KAAK,OAAO,GAAG,CAAC,CAAC;AAAA,IAAA;AAG7D,MAAI,GAAG,SAAS;AACd,WAAO;AAAA,MACL,QAAQ;AAAA,QACN,SAASA,UAAc,KAAK,OAAO,GAAG,aAAa,CAAC;AAAA,QACpD,OAAO,GAAG;AAAA,MAAA;AAAA,IACZ;AAGJ,MAAI,GAAG,SAAS;AACd,WAAO;AAAA,MACL,OAAO,CAACA,UAAc,KAAK,OAAO,GAAG,aAAa,CAAC,CAAC;AAAA,IAAA;AAIxD,QAAM,IAAI,MAAM,0BAA0B,GAAG,IAAI,EAAE;AACrD;"} | ||
| {"version":3,"file":"encode.js","sources":["../../src/encoders/sanity/decode.ts","../../src/encoders/sanity/encode.ts"],"sourcesContent":["import {type PatchOperations} from '@sanity/client'\n\nimport {type SetIfMissingOp, type SetOp} from '../../mutations/operations/types'\nimport {\n type IdentifiedSanityDocument,\n type Mutation,\n type NodePatch,\n type SanityDocumentBase,\n} from '../../mutations/types'\nimport {parse as parsePath} from '../../path/parser/parse'\nimport {\n type Insert,\n type SanityCreateIfNotExistsMutation,\n type SanityCreateMutation,\n type SanityCreateOrReplaceMutation,\n type SanityDecPatch,\n type SanityDeleteMutation,\n type SanityDiffMatchPatch,\n type SanityIncPatch,\n type SanityInsertPatch,\n type SanityMutation,\n type SanityPatch,\n type SanitySetIfMissingPatch,\n type SanitySetPatch,\n type SanityUnsetPatch,\n} from './types'\n\nexport type {Mutation, SanityDocumentBase}\n\nfunction isCreateIfNotExistsMutation(\n sanityMutation: SanityMutation,\n): sanityMutation is SanityCreateIfNotExistsMutation {\n return 'createIfNotExists' in sanityMutation\n}\n\nfunction isCreateOrReplaceMutation<Doc extends IdentifiedSanityDocument>(\n sanityMutation: SanityMutation,\n): sanityMutation is SanityCreateOrReplaceMutation<Doc> {\n return 'createOrReplace' in sanityMutation\n}\n\nfunction isCreateMutation<Doc extends SanityDocumentBase>(\n sanityMutation: SanityMutation<Doc>,\n): sanityMutation is SanityCreateMutation<Doc> {\n return 'create' in sanityMutation\n}\n\nfunction isDeleteMutation(\n sanityMutation: SanityMutation<any>,\n): sanityMutation is SanityDeleteMutation {\n return 'delete' in sanityMutation\n}\n\nfunction isPatchMutation(sanityMutation: SanityMutation): sanityMutation is {\n patch: SanityPatch\n} {\n return 'patch' in sanityMutation\n}\n\nfunction isSetPatch(\n sanityPatch: PatchOperations,\n): sanityPatch is SanitySetPatch {\n return 'set' in sanityPatch\n}\n\nfunction isSetIfMissingPatch(\n sanityPatch: SanityPatch,\n): sanityPatch is SanitySetIfMissingPatch {\n return 'setIfMissing' in sanityPatch\n}\n\nfunction isDiffMatchPatch(\n sanityPatch: SanityPatch,\n): sanityPatch is SanityDiffMatchPatch {\n return 'diffMatchPatch' in sanityPatch\n}\n\nfunction isUnsetPatch(\n sanityPatch: SanityPatch,\n): sanityPatch is SanityUnsetPatch {\n return 'unset' in sanityPatch\n}\n\nfunction isIncPatch(sanityPatch: SanityPatch): sanityPatch is SanityIncPatch {\n return 'inc' in sanityPatch\n}\n\nfunction isDecPatch(sanityPatch: SanityPatch): sanityPatch is SanityDecPatch {\n return 'inc' in sanityPatch\n}\n\nfunction isInsertPatch(\n sanityPatch: SanityPatch,\n): sanityPatch is SanityInsertPatch {\n return 'insert' in sanityPatch\n}\n\nexport function decodeAll<Doc extends SanityDocumentBase>(\n sanityMutations: SanityMutation<Doc>[],\n) {\n return sanityMutations.map(decodeMutation)\n}\n\nexport function decode<Doc extends SanityDocumentBase>(\n encodedMutation: SanityMutation<Doc>,\n) {\n return decodeMutation(encodedMutation)\n}\n\nfunction decodeMutation<Doc extends SanityDocumentBase>(\n encodedMutation: SanityMutation<Doc>,\n): Mutation {\n if (isCreateIfNotExistsMutation(encodedMutation)) {\n return {\n type: 'createIfNotExists',\n document: encodedMutation.createIfNotExists,\n }\n }\n if (isCreateOrReplaceMutation(encodedMutation)) {\n return {\n type: 'createOrReplace',\n document: encodedMutation.createOrReplace,\n }\n }\n if (isCreateMutation(encodedMutation)) {\n return {type: 'create', document: encodedMutation.create}\n }\n if (isDeleteMutation(encodedMutation)) {\n return {id: encodedMutation.delete.id, type: 'delete'}\n }\n if (isPatchMutation(encodedMutation)) {\n return {\n type: 'patch',\n id: encodedMutation.patch.id,\n patches: decodeNodePatches(encodedMutation.patch),\n }\n }\n throw new Error(`Unknown mutation: ${JSON.stringify(encodedMutation)}`)\n}\n\nconst POSITION_KEYS = ['before', 'replace', 'after'] as const\n\nfunction getInsertPosition(insert: Insert) {\n const positions = POSITION_KEYS.filter(k => k in insert)\n if (positions.length > 1) {\n throw new Error(\n `Insert patch is ambiguous. Should only contain one of: ${POSITION_KEYS.join(\n ', ',\n )}, instead found ${positions.join(', ')}`,\n )\n }\n return positions[0]\n}\n\nfunction decodeNodePatches<T>(patch: SanityPatch): NodePatch<any, any>[] {\n // If multiple patches are included, then the order of execution is as follows\n // set, setIfMissing, unset, inc, dec, insert.\n // order is defined here: https://www.sanity.io/docs/http-mutations#2f480b2baca5\n return [\n ...getSetPatches(patch),\n ...getSetIfMissingPatches(patch),\n ...getUnsetPatches(patch),\n ...getIncPatches(patch),\n ...getDecPatches(patch),\n ...getInsertPatches(patch),\n ...getDiffMatchPatchPatches(patch),\n ]\n}\n\nfunction getSetPatches(patch: PatchOperations): NodePatch<any[], SetOp<any>>[] {\n return isSetPatch(patch)\n ? Object.keys(patch.set).map(path => ({\n path: parsePath(path),\n op: {type: 'set', value: patch.set[path]},\n }))\n : []\n}\n\nfunction getSetIfMissingPatches(\n patch: SanityPatch,\n): NodePatch<any[], SetIfMissingOp<any>>[] {\n return isSetIfMissingPatch(patch)\n ? Object.keys(patch.setIfMissing).map(path => ({\n path: parsePath(path),\n op: {type: 'setIfMissing', value: patch.setIfMissing[path]},\n }))\n : []\n}\n\nfunction getDiffMatchPatchPatches(patch: SanityPatch) {\n return isDiffMatchPatch(patch)\n ? Object.keys(patch.diffMatchPatch).map(path => ({\n path: parsePath(path),\n op: {type: 'diffMatchPatch', value: patch.diffMatchPatch[path]},\n }))\n : []\n}\n\nfunction getUnsetPatches(patch: SanityPatch) {\n return isUnsetPatch(patch)\n ? patch.unset.map(path => ({\n path: parsePath(path),\n op: {type: 'unset'},\n }))\n : []\n}\n\nfunction getIncPatches(patch: SanityPatch) {\n return isIncPatch(patch)\n ? Object.keys(patch.inc).map(path => ({\n path: parsePath(path),\n op: {type: 'inc', amount: patch.inc[path]},\n }))\n : []\n}\n\nfunction getDecPatches(patch: SanityPatch) {\n return isDecPatch(patch)\n ? Object.keys(patch.dec).map(path => ({\n path: parsePath(path),\n op: {type: 'dec', amount: patch.dec[path]},\n }))\n : []\n}\n\nfunction getInsertPatches(patch: SanityPatch) {\n if (!isInsertPatch(patch)) {\n return []\n }\n const position = getInsertPosition(patch.insert)\n if (!position) {\n throw new Error('Insert patch missing position')\n }\n\n const path: string[] = parsePath((patch.insert as any)[position]!)\n const referenceItem = path.pop()\n\n const op =\n position === 'replace'\n ? {\n type: 'insert',\n position: position,\n referenceItem,\n items: patch.insert.items,\n }\n : {\n type: 'insert',\n position: position,\n referenceItem,\n items: patch.insert.items,\n }\n\n return [{path, op}]\n}\n","import {type PatchMutationOperation} from '@sanity/client'\n\nimport {\n type Mutation,\n type NodePatch,\n type Transaction,\n} from '../../mutations/types'\nimport {stringify as stringifyPath} from '../../path/parser/stringify'\nimport {type SanityMutation} from './types'\n\nexport function encode(mutation: Mutation): SanityMutation[] | SanityMutation {\n return encodeMutation(mutation)\n}\n\nexport function encodeAll(mutations: Mutation[]): SanityMutation[] {\n return mutations.flatMap(encode)\n}\n\nexport function encodeTransaction(transaction: Transaction) {\n return {\n transactionId: transaction.id,\n mutations: encodeAll(transaction.mutations),\n }\n}\n\nexport function encodeMutation(\n mutation: Mutation,\n): SanityMutation[] | SanityMutation {\n switch (mutation.type) {\n case 'create':\n return {[mutation.type]: mutation.document}\n case 'createIfNotExists':\n return {[mutation.type]: mutation.document}\n case 'createOrReplace':\n return {[mutation.type]: mutation.document}\n case 'delete':\n return {\n delete: {id: mutation.id},\n }\n case 'patch': {\n const ifRevisionID = mutation.options?.ifRevision\n return mutation.patches.map(patch => {\n return {\n patch: {\n id: mutation.id,\n ...(ifRevisionID && {ifRevisionID}),\n ...patchToSanity(patch),\n },\n } as {id: string; patch: PatchMutationOperation}\n })\n }\n }\n}\n\nfunction patchToSanity(patch: NodePatch) {\n const {path, op} = patch\n if (op.type === 'unset') {\n return {unset: [stringifyPath(path)]}\n }\n if (op.type === 'insert') {\n return {\n insert: {\n [op.position]: stringifyPath([...path, op.referenceItem]),\n items: op.items,\n },\n }\n }\n if (op.type === 'diffMatchPatch') {\n return {diffMatchPatch: {[stringifyPath(path)]: op.value}}\n }\n if (op.type === 'inc') {\n return {inc: {[stringifyPath(path)]: op.amount}}\n }\n if (op.type === 'dec') {\n return {dec: {[stringifyPath(path)]: op.amount}}\n }\n if (op.type === 'set' || op.type === 'setIfMissing') {\n return {[op.type]: {[stringifyPath(path)]: op.value}}\n }\n if (op.type === 'truncate') {\n const range = [\n op.startIndex,\n typeof op.endIndex === 'number' ? op.endIndex : '',\n ].join(':')\n\n return {unset: [`${stringifyPath(path)}[${range}]`]}\n }\n if (op.type === 'upsert') {\n // note: upsert currently not supported by sanity, so will always insert at reference position\n return {\n unset: op.items.map(item =>\n stringifyPath([...path, {_key: (item as any)._key}]),\n ),\n insert: {\n [op.position]: stringifyPath([...path, op.referenceItem]),\n items: op.items,\n },\n }\n }\n if (op.type === 'assign') {\n return {\n set: Object.fromEntries(\n Object.keys(op.value).map(key => [\n stringifyPath(path.concat(key)),\n op.value[key as keyof typeof op.value],\n ]),\n ),\n }\n }\n if (op.type === 'unassign') {\n return {\n unset: op.keys.map(key => stringifyPath(path.concat(key))),\n }\n }\n if (op.type === 'replace') {\n return {\n insert: {\n replace: stringifyPath(path.concat(op.referenceItem)),\n items: op.items,\n },\n }\n }\n if (op.type === 'remove') {\n return {\n unset: [stringifyPath(path.concat(op.referenceItem))],\n }\n }\n if (op.type === 'insertIfMissing') {\n // note: insertIfMissing currently not supported by sanity, so will always insert at reference position\n throw new Error('Patch type insertIfMissing is not supported by Sanity')\n }\n //@ts-expect-error all cases should be covered\n throw new Error(`Unknown operation type ${op.type}`)\n}\n"],"names":["parsePath","stringifyPath"],"mappings":";;AA6BA,SAAS,4BACP,gBACmD;AACnD,SAAO,uBAAuB;AAChC;AAEA,SAAS,0BACP,gBACsD;AACtD,SAAO,qBAAqB;AAC9B;AAEA,SAAS,iBACP,gBAC6C;AAC7C,SAAO,YAAY;AACrB;AAEA,SAAS,iBACP,gBACwC;AACxC,SAAO,YAAY;AACrB;AAEA,SAAS,gBAAgB,gBAEvB;AACA,SAAO,WAAW;AACpB;AAEA,SAAS,WACP,aAC+B;AAC/B,SAAO,SAAS;AAClB;AAEA,SAAS,oBACP,aACwC;AACxC,SAAO,kBAAkB;AAC3B;AAEA,SAAS,iBACP,aACqC;AACrC,SAAO,oBAAoB;AAC7B;AAEA,SAAS,aACP,aACiC;AACjC,SAAO,WAAW;AACpB;AAEA,SAAS,WAAW,aAAyD;AAC3E,SAAO,SAAS;AAClB;AAEA,SAAS,WAAW,aAAyD;AAC3E,SAAO,SAAS;AAClB;AAEA,SAAS,cACP,aACkC;AAClC,SAAO,YAAY;AACrB;AAEO,SAAS,UACd,iBACA;AACA,SAAO,gBAAgB,IAAI,cAAc;AAC3C;AAEO,SAAS,OACd,iBACA;AACA,SAAO,eAAe,eAAe;AACvC;AAEA,SAAS,eACP,iBACU;AACV,MAAI,4BAA4B,eAAe;AAC7C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AAa,MAAK,CAAC;AAAA,MAAA;AAAA,MAErD,QAAQ;AAAA,QACN,CAAC,GAAG,QAAQ,GAAGA,UAAc,CAAC,GAAG,MAAM,GAAG,aAAa,CAAC;AAAA,QACxD,OAAO,GAAG;AAAA,MAAA;AAAA,IACZ;AAGJ,MAAI,GAAG,SAAS;AACd,WAAO;AAAA,MACL,KAAK,OAAO;AAAA,QACV,OAAO,KAAK,GAAG,KAAK,EAAE,IAAI,CAAA,QAAO;AAAA,UAC/BA,UAAc,KAAK,OAAO,GAAG,CAAC;AAAA,UAC9B,GAAG,MAAM,GAA4B;AAAA,QAAA,CACtC;AAAA,MAAA;AAAA,IACH;AAGJ,MAAI,GAAG,SAAS;AACd,WAAO;AAAA,MACL,OAAO,GAAG,KAAK,IAAI,CAAA,QAAOA,UAAc,KAAK,OAAO,GAAG,CAAC,CAAC;AAAA,IAAA;AAG7D,MAAI,GAAG,SAAS;AACd,WAAO;AAAA,MACL,QAAQ;AAAA,QACN,SAASA,UAAc,KAAK,OAAO,GAAG,aAAa,CAAC;AAAA,QACpD,OAAO,GAAG;AAAA,MAAA;AAAA,IACZ;AAGJ,MAAI,GAAG,SAAS;AACd,WAAO;AAAA,MACL,OAAO,CAACA,UAAc,KAAK,OAAO,GAAG,aAAa,CAAC,CAAC;AAAA,IAAA;AAGxD,QAAI,GAAG,SAAS,oBAER,IAAI,MAAM,uDAAuD,IAGnE,IAAI,MAAM,0BAA0B,GAAG,IAAI,EAAE;AACrD;"} |
+43
-13
@@ -33,2 +33,8 @@ import { isKeyedElement, isArrayElement, isPropertyElement, stringify } from "./stringify.js"; | ||
| } | ||
| function omit(val, props) { | ||
| const copy = { ...val }; | ||
| for (const prop of props) | ||
| delete copy[prop]; | ||
| return copy; | ||
| } | ||
| function insert(op, currentValue) { | ||
@@ -47,4 +53,4 @@ if (!Array.isArray(currentValue)) | ||
| return currentValue; | ||
| const replaceItemsMap = [], insertItems = []; | ||
| if (op.items.forEach((itemToBeUpserted, i) => { | ||
| const replaceItemsMap = {}, insertItems = []; | ||
| op.items.forEach((itemToBeUpserted, i) => { | ||
| const existingIndex = currentValue.findIndex( | ||
@@ -54,7 +60,11 @@ (existingItem) => existingItem?._key === itemToBeUpserted._key | ||
| existingIndex >= 0 ? replaceItemsMap[existingIndex] = i : insertItems.push(itemToBeUpserted); | ||
| }), replaceItemsMap.length === 0 && insertItems.length == 0) | ||
| }); | ||
| const itemsToReplace = Object.keys(replaceItemsMap); | ||
| if (itemsToReplace.length === 0 && insertItems.length == 0) | ||
| return currentValue; | ||
| const next = [...currentValue]; | ||
| for (const i of replaceItemsMap) | ||
| next[i] = op.items[replaceItemsMap[i]]; | ||
| for (const i of itemsToReplace) { | ||
| const index = Number(i); | ||
| next[index] = op.items[replaceItemsMap[index]]; | ||
| } | ||
| return insert( | ||
@@ -69,2 +79,19 @@ { | ||
| } | ||
| function insertIfMissing(op, currentValue) { | ||
| if (!Array.isArray(currentValue)) | ||
| throw new TypeError('Cannot apply "insertIfMissing()" on non-array value'); | ||
| if (op.items.length === 0) | ||
| return currentValue; | ||
| const itemsToInsert = op.items.filter( | ||
| (item) => !currentValue.find((existing) => item._key === existing?._key) | ||
| ); | ||
| return itemsToInsert.length === 0 ? currentValue : insert( | ||
| { | ||
| items: itemsToInsert, | ||
| referenceItem: op.referenceItem, | ||
| position: op.position | ||
| }, | ||
| currentValue | ||
| ); | ||
| } | ||
| function replace(op, currentValue) { | ||
@@ -118,8 +145,2 @@ if (!Array.isArray(currentValue)) | ||
| } | ||
| function omit(val, props) { | ||
| const copy = { ...val }; | ||
| for (const prop of props) | ||
| delete copy[prop]; | ||
| return copy; | ||
| } | ||
| function unassign(op, currentValue) { | ||
@@ -147,2 +168,3 @@ if (!isObject(currentValue)) | ||
| insert, | ||
| insertIfMissing, | ||
| remove, | ||
@@ -190,3 +212,3 @@ replace, | ||
| const patchedValue = applyAtPath(tail, op, current); | ||
| return patchedValue === current ? object : { ...object, [head]: patchedValue }; | ||
| return patchedValue === void 0 ? omit(object, [head]) : patchedValue === current ? object : { ...object, [head]: patchedValue }; | ||
| } | ||
@@ -198,3 +220,11 @@ function applyInArray(head, tail, op, value) { | ||
| const current = value[index], patchedItem = applyAtPath(tail, op, current); | ||
| return patchedItem === current ? value : splice(value, index, 1, [patchedItem]); | ||
| return patchedItem === current ? value : splice( | ||
| value, | ||
| index, | ||
| 1, | ||
| // unset op on an array item should not leave a "hole" in the array | ||
| // eg. apply(at('someArray[1]', unset()), ['foo', 'bar', 'baz'] should result in | ||
| // ['foo', 'baz'], not ['foo', undefined, 'baz'] | ||
| patchedItem === void 0 ? [] : [patchedItem] | ||
| ); | ||
| } | ||
@@ -201,0 +231,0 @@ function isNonEmptyArray(a) { |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"utils.js","sources":["../../src/apply/utils/getKeyOf.ts","../../src/apply/utils/array.ts","../../src/apply/patch/operations/array.ts","../../src/apply/patch/operations/common.ts","../../src/apply/patch/operations/number.ts","../../src/apply/utils/hasOwn.ts","../../src/apply/utils/isEmpty.ts","../../src/apply/utils/omit.ts","../../src/apply/patch/operations/object.ts","../../src/apply/patch/operations/string.ts","../../src/apply/patch/applyOp.ts","../../src/apply/patch/applyNodePatch.ts","../../src/apply/applyPatchMutation.ts","../../src/apply/store/utils.ts"],"sourcesContent":["export function keyOf(value: any): string | null {\n return (\n (value !== null &&\n typeof value === 'object' &&\n typeof value._key === 'string' &&\n value._key) ||\n null\n )\n}\n","import {isKeyedElement, type PathElement} from '../../path'\nimport {keyOf} from './getKeyOf'\n\nexport function findTargetIndex<T>(array: T[], pathSegment: PathElement) {\n if (typeof pathSegment === 'number') {\n return normalizeIndex(array.length, pathSegment)\n }\n if (isKeyedElement(pathSegment)) {\n const idx = array.findIndex(value => keyOf(value) === pathSegment._key)\n return idx === -1 ? null : idx\n }\n throw new Error(\n `Expected path segment to be addressing a single array item either by numeric index or by '_key'. Instead saw ${JSON.stringify(\n pathSegment,\n )}`,\n )\n}\n\nexport function getTargetIdx(position: 'before' | 'after', index: number) {\n return position === 'before' ? index : index + 1\n}\n\n// normalizes the index according to the array length\n// returns null if the normalized index is out of bounds\nexport function normalizeIndex(length: number, index: number) {\n if (length === 0 && (index === -1 || index === 0)) {\n return 0\n }\n const normalized = index < 0 ? length + index : index\n return normalized >= length || normalized < 0 ? null : normalized\n}\n\n// non-mutating splice\nexport function splice<T>(arr: T[], start: number, deleteCount: number): T[]\nexport function splice<T>(\n arr: T[],\n start: number,\n deleteCount: number,\n items: T[],\n): T[]\nexport function splice<T>(\n arr: T[],\n start: number,\n deleteCount: number,\n items?: T[],\n): T[] {\n const copy = arr.slice()\n copy.splice(start, deleteCount, ...(items || []))\n return copy\n}\n","import {\n type InsertOp,\n type KeyedPathElement,\n type RelativePosition,\n type RemoveOp,\n type ReplaceOp,\n type TruncateOp,\n type UpsertOp,\n} from '../../../mutations/operations/types'\nimport {findTargetIndex, getTargetIdx, splice} from '../../utils/array'\n\nexport function insert<\n O extends InsertOp<unknown[], RelativePosition, number | KeyedPathElement>,\n CurrentValue extends unknown[],\n>(op: O, currentValue: CurrentValue) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"insert()\" on non-array value')\n }\n\n const index = findTargetIndex(currentValue, op.referenceItem)\n if (index === null) {\n throw new Error(`Found no matching array element to insert ${op.position}`)\n }\n // special case for empty arrays\n if (currentValue.length === 0) {\n return op.items\n }\n return splice(currentValue, getTargetIdx(op.position, index), 0, op.items)\n}\n\nexport function upsert<\n O extends UpsertOp<unknown[], RelativePosition, number | KeyedPathElement>,\n CurrentValue extends unknown[],\n>(op: O, currentValue: CurrentValue) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"upsert()\" on non-array value')\n }\n\n if (op.items.length === 0) {\n return currentValue\n }\n const replaceItemsMap: number[] = []\n const insertItems: unknown[] = []\n op.items.forEach((itemToBeUpserted: any, i) => {\n const existingIndex = currentValue.findIndex(\n existingItem => (existingItem as any)?._key === itemToBeUpserted._key,\n )\n if (existingIndex >= 0) {\n replaceItemsMap[existingIndex] = i\n } else {\n insertItems.push(itemToBeUpserted)\n }\n })\n\n if (replaceItemsMap.length === 0 && insertItems.length == 0) {\n return currentValue\n }\n\n const next = [...currentValue]\n // Replace existing items\n for (const i of replaceItemsMap) {\n next[i] = op.items[replaceItemsMap[i]!]!\n }\n\n // Insert the items that doesn't exist\n return insert(\n {\n type: 'insert',\n items: insertItems,\n referenceItem: op.referenceItem,\n position: op.position,\n },\n next,\n )\n}\n\nexport function replace<\n O extends ReplaceOp<unknown[], number | KeyedPathElement>,\n CurrentValue extends unknown[],\n>(op: O, currentValue: CurrentValue) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"replace()\" on non-array value')\n }\n\n const index = findTargetIndex(currentValue, op.referenceItem)\n if (index === null) {\n throw new Error(`Found no matching array element to replace`)\n }\n return splice(currentValue, index, op.items.length, op.items)\n}\nexport function remove<\n O extends RemoveOp<number | KeyedPathElement>,\n CurrentValue extends unknown[],\n>(op: O, currentValue: CurrentValue) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"remove()\" on non-array value')\n }\n\n const index = findTargetIndex(currentValue, op.referenceItem)\n if (index === null) {\n throw new Error(`Found no matching array element to replace`)\n }\n return splice(currentValue, index, 1, [])\n}\n\nexport function truncate<O extends TruncateOp, CurrentValue extends unknown[]>(\n op: O,\n currentValue: CurrentValue,\n) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"truncate()\" on non-array value')\n }\n\n return typeof op.endIndex === 'number'\n ? currentValue\n .slice(0, op.startIndex)\n .concat(currentValue.slice(op.endIndex))\n : currentValue.slice(0, op.startIndex)\n}\n","import {\n type SetIfMissingOp,\n type SetOp,\n type UnsetOp,\n} from '../../../mutations/operations/types'\n\nexport function set<O extends SetOp<any>, CurrentValue>(\n op: O,\n currentValue: CurrentValue,\n) {\n return op.value\n}\n\nexport function setIfMissing<O extends SetIfMissingOp<any>, CurrentValue>(\n op: O,\n currentValue: CurrentValue,\n) {\n return currentValue ?? op.value\n}\n\nexport function unset<O extends UnsetOp, CurrentValue>(op: O) {\n return undefined\n}\n","import {type DecOp, type IncOp} from '../../../mutations/operations/types'\n\nexport function inc<O extends IncOp<number>, CurrentValue extends number>(\n op: O,\n currentValue: CurrentValue,\n) {\n if (typeof currentValue !== 'number') {\n throw new TypeError('Cannot apply \"inc()\" on non-numeric value')\n }\n\n return currentValue + op.amount\n}\n\nexport function dec<O extends DecOp<number>, CurrentValue extends number>(\n op: O,\n currentValue: CurrentValue,\n) {\n if (typeof currentValue !== 'number') {\n throw new TypeError('Cannot apply \"dec()\" on non-numeric value')\n }\n\n return currentValue - op.amount\n}\n","export const hasOwn = Object.prototype.hasOwnProperty.call.bind(\n Object.prototype.hasOwnProperty,\n)\n","import {hasOwn} from './hasOwn'\n\nexport function isEmpty(v: object) {\n for (const key in v) {\n if (hasOwn(v, key)) {\n return false\n }\n }\n return true\n}\n","export function omit<T, K extends keyof T>(val: T, props: K[]): Omit<T, K> {\n const copy = {...val}\n for (const prop of props) {\n delete copy[prop]\n }\n return copy\n}\n","import {\n type AssignOp,\n type UnassignOp,\n} from '../../../mutations/operations/types'\nimport {isObject} from '../../../utils/isObject'\nimport {isEmpty} from '../../utils/isEmpty'\nimport {omit} from '../../utils/omit'\n\nexport function unassign<T extends object, K extends string[]>(\n op: UnassignOp<K>,\n currentValue: T,\n) {\n if (!isObject(currentValue)) {\n throw new TypeError('Cannot apply \"unassign()\" on non-object value')\n }\n\n return op.keys.length === 0\n ? currentValue\n : omit(currentValue, op.keys as any[])\n}\n\nexport function assign<T extends object>(op: AssignOp<T>, currentValue: T) {\n if (!isObject(currentValue)) {\n throw new TypeError('Cannot apply \"assign()\" on non-object value')\n }\n\n return isEmpty(op.value) ? currentValue : {...currentValue, ...op.value}\n}\n","import {applyPatches, parsePatch} from '@sanity/diff-match-patch'\n\nimport {type DiffMatchPatchOp} from '../../../mutations/operations/types'\n\nexport function diffMatchPatch<\n O extends DiffMatchPatchOp,\n CurrentValue extends string,\n>(op: O, currentValue: CurrentValue) {\n if (typeof currentValue !== 'string') {\n throw new TypeError('Cannot apply \"diffMatchPatch()\" on non-string value')\n }\n\n return applyPatches(parsePatch(op.value), currentValue)[0]\n}\n","import {\n type AnyOp,\n type ArrayOp,\n type NumberOp,\n type ObjectOp,\n type Operation,\n type StringOp,\n} from '../../mutations/operations/types'\nimport {type AnyArray} from '../../utils/typeUtils'\nimport * as operations from './operations'\nimport {type ApplyOp} from './typings/applyOp'\n\nexport function applyOp<const Op extends AnyOp, const CurrentValue>(\n op: Op,\n currentValue: CurrentValue,\n): ApplyOp<Op, CurrentValue>\nexport function applyOp<\n const Op extends NumberOp,\n const CurrentValue extends number,\n>(op: Op, currentValue: CurrentValue): ApplyOp<Op, CurrentValue>\nexport function applyOp<\n const Op extends StringOp,\n const CurrentValue extends string,\n>(op: Op, currentValue: CurrentValue): ApplyOp<Op, CurrentValue>\nexport function applyOp<\n const Op extends ObjectOp,\n const CurrentValue extends {[k in keyof any]: unknown},\n>(op: Op, currentValue: CurrentValue): ApplyOp<Op, CurrentValue>\nexport function applyOp<\n const Op extends ArrayOp,\n const CurrentValue extends AnyArray,\n>(op: Op, currentValue: CurrentValue): ApplyOp<Op, CurrentValue>\nexport function applyOp<const Op extends Operation, const CurrentValue>(\n op: Op,\n currentValue: CurrentValue,\n): ApplyOp<Op, CurrentValue> {\n if (!(op.type in operations)) {\n throw new Error(`Invalid operation type: \"${op.type}\"`)\n }\n\n // eslint-disable-next-line import/namespace\n return (operations[op.type] as CallableFunction)(op, currentValue)\n}\n","import {type Operation} from '../../mutations/operations/types'\nimport {type NodePatch, type NodePatchList} from '../../mutations/types'\nimport {isArrayElement, isPropertyElement, stringify} from '../../path'\nimport {isObject} from '../../utils/isObject'\nimport {type NormalizeReadOnlyArray} from '../../utils/typeUtils'\nimport {type KeyedPathElement, type Path} from '../'\nimport {findTargetIndex, splice} from '../utils/array'\nimport {applyOp} from './applyOp'\nimport {\n type ApplyAtPath,\n type ApplyNodePatch,\n type ApplyPatches,\n} from './typings/applyNodePatch'\n\nexport function applyPatches<Patches extends NodePatchList, const Doc>(\n patches: Patches,\n document: Doc,\n): ApplyPatches<NormalizeReadOnlyArray<Patches>, Doc> {\n return (patches as NodePatch[]).reduce(\n (prev, patch) => applyNodePatch(patch, prev) as any,\n document,\n ) as any\n}\n\nexport function applyNodePatch<const Patch extends NodePatch, const Doc>(\n patch: Patch,\n document: Doc,\n): ApplyNodePatch<Patch, Doc> {\n return applyAtPath(patch.path, patch.op, document) as any\n}\n\nfunction applyAtPath<P extends Path, O extends Operation, T>(\n path: P,\n op: O,\n value: T,\n): ApplyAtPath<P, O, T> {\n if (!isNonEmptyArray(path)) {\n return applyOp(op as any, value) as any\n }\n\n const [head, ...tail] = path\n\n if (isArrayElement(head) && Array.isArray(value)) {\n return applyInArray(head, tail, op, value) as any\n }\n\n if (isPropertyElement(head) && isObject(value)) {\n return applyInObject(head, tail, op, value) as any\n }\n\n throw new Error(\n `Cannot apply operation of type \"${op.type}\" to path ${stringify(\n path,\n )} on ${typeof value} value`,\n )\n}\n\nfunction applyInObject<Key extends keyof any, T extends {[key in Key]?: any}>(\n head: Key,\n tail: Path,\n op: Operation,\n object: T,\n) {\n const current = object[head]\n\n if (current === undefined && tail.length > 0) {\n return object\n }\n\n // The patch targets the item at the index specified by \"head\"\n // so forward it to the item\n const patchedValue = applyAtPath(tail, op, current)\n\n // If the result of applying it to the item yields the item back we assume it was\n // a noop and don't modify our value. If we get a new value back, we return a\n // new array with the modified item replaced\n return patchedValue === current ? object : {...object, [head]: patchedValue}\n}\n\nfunction applyInArray<T>(\n head: number | KeyedPathElement,\n tail: Path,\n op: Operation,\n value: T[],\n) {\n const index = findTargetIndex(value, head!)\n\n if (index === null) {\n // partial is default behavior for arrays\n // the patch targets an index that is out of bounds\n return value\n }\n\n // If the given selector could not be found, return as-is\n if (index === -1) {\n return value\n }\n\n const current = value[index]!\n\n // The patch targets the item at the index specified by \"head\"\n // so forward it to the item\n const patchedItem = applyAtPath(tail, op, current)\n\n // If the result of applying it to the item yields the item back we assume it was\n // a noop and don't modify our value. If we get a new value back, we return a\n // new array with the modified item replaced\n return patchedItem === current\n ? value\n : splice(value, index, 1, [patchedItem])\n}\n\nfunction isNonEmptyArray<T>(a: T[] | readonly T[]): a is [T, ...T[]] {\n return a.length > 0\n}\n","import {type PatchMutation, type SanityDocumentBase} from '../mutations/types'\nimport {type NormalizeReadOnlyArray} from '../utils/typeUtils'\nimport {applyPatches} from './patch/applyNodePatch'\nimport {type ApplyPatches} from './patch/typings/applyNodePatch'\n\nexport type ApplyPatchMutation<\n Mutation extends PatchMutation,\n Doc extends SanityDocumentBase,\n> =\n Mutation extends PatchMutation<infer Patches>\n ? ApplyPatches<NormalizeReadOnlyArray<Patches>, Doc>\n : Doc\n\nexport function applyPatchMutation<\n const Mutation extends PatchMutation,\n const Doc extends SanityDocumentBase,\n>(mutation: Mutation, document: Doc): ApplyPatchMutation<Mutation, Doc> {\n if (\n mutation.options?.ifRevision &&\n document._rev !== mutation.options.ifRevision\n ) {\n throw new Error('Revision mismatch')\n }\n if (mutation.id !== document._id) {\n throw new Error(\n `Document id mismatch. Refusing to apply mutation for document with id=\"${mutation.id}\" on the given document with id=\"${document._id}\"`,\n )\n }\n return applyPatches(mutation.patches, document) as any\n}\n","import {type SanityDocumentBase} from '../../mutations/types'\nimport {type StoredDocument} from '../applyInIndex'\n\nexport function hasId(doc: SanityDocumentBase): doc is StoredDocument {\n return '_id' in doc\n}\nexport function assignId<Doc extends SanityDocumentBase>(\n doc: Doc,\n generateId: () => string,\n): Doc & {_id: string} {\n return hasId(doc) ? doc : {...doc, _id: generateId()}\n}\n"],"names":["applyPatches"],"mappings":";;;AAAO,SAAS,MAAM,OAA2B;AAC/C,SACG,UAAU,QACT,OAAO,SAAU,YACjB,OAAO,MAAM,QAAS,YACtB,MAAM,QACR;AAEJ;ACLO,SAAS,gBAAmB,OAAY,aAA0B;AACvE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IrB,cAAc,YAAY,MAAM,IAAI,OAAO;AAKjD,SAAO,gBAAgB,UACnB,QACA,OAAO,OAAO,OAAO,GAAG,CAAC,WAAW,CAAC;AAC3C;AAEA,SAAS,gBAAmB,GAAyC;AACnE,SAAO,EAAE,SAAS;AACpB;ACrGO,SAAS,mBAGd,UAAoB,UAAkD;AACtE,MACE,SAAS,SAAS,cAClB,SAAS,SAAS,SAAS,QAAQ;AAEnC,UAAM,IAAI,MAAM,mBAAmB;AAErC,MAAI,SAAS,OAAO,SAAS;AAC3B,UAAM,IAAI;AAAA,MACR,0EAA0E,SAAS,EAAE,oCAAoC,SAAS,GAAG;AAAA,IAAA;AAGzI,SAAO,aAAa,SAAS,SAAS,QAAQ;AAChD;AC1BO,SAAS,MAAM,KAAgD;AACpE,SAAO,SAAS;AAClB;AACO,SAAS,SACd,KACA,YACqB;AACrB,SAAO,MAAM,GAAG,IAAI,MAAM,EAAC,GAAG,KAAK,KAAK,aAAW;AACrD;"} | ||
| {"version":3,"file":"utils.js","sources":["../../src/apply/utils/getKeyOf.ts","../../src/apply/utils/array.ts","../../src/apply/utils/omit.ts","../../src/apply/patch/operations/array.ts","../../src/apply/patch/operations/common.ts","../../src/apply/patch/operations/number.ts","../../src/apply/utils/hasOwn.ts","../../src/apply/utils/isEmpty.ts","../../src/apply/patch/operations/object.ts","../../src/apply/patch/operations/string.ts","../../src/apply/patch/applyOp.ts","../../src/apply/patch/applyNodePatch.ts","../../src/apply/applyPatchMutation.ts","../../src/apply/store/utils.ts"],"sourcesContent":["export function keyOf(value: any): string | null {\n return (\n (value !== null &&\n typeof value === 'object' &&\n typeof value._key === 'string' &&\n value._key) ||\n null\n )\n}\n","import {isKeyedElement, type PathElement} from '../../path'\nimport {keyOf} from './getKeyOf'\n\nexport function findTargetIndex<T>(array: T[], pathSegment: PathElement) {\n if (typeof pathSegment === 'number') {\n return normalizeIndex(array.length, pathSegment)\n }\n if (isKeyedElement(pathSegment)) {\n const idx = array.findIndex(value => keyOf(value) === pathSegment._key)\n return idx === -1 ? null : idx\n }\n throw new Error(\n `Expected path segment to be addressing a single array item either by numeric index or by '_key'. Instead saw ${JSON.stringify(\n pathSegment,\n )}`,\n )\n}\n\nexport function getTargetIdx(position: 'before' | 'after', index: number) {\n return position === 'before' ? index : index + 1\n}\n\n// normalizes the index according to the array length\n// returns null if the normalized index is out of bounds\nexport function normalizeIndex(length: number, index: number) {\n if (length === 0 && (index === -1 || index === 0)) {\n return 0\n }\n const normalized = index < 0 ? length + index : index\n return normalized >= length || normalized < 0 ? null : normalized\n}\n\n// non-mutating splice\nexport function splice<T>(arr: T[], start: number, deleteCount: number): T[]\nexport function splice<T>(\n arr: T[],\n start: number,\n deleteCount: number,\n items: T[],\n): T[]\nexport function splice<T>(\n arr: T[],\n start: number,\n deleteCount: number,\n items?: T[],\n): T[] {\n const copy = arr.slice()\n copy.splice(start, deleteCount, ...(items || []))\n return copy\n}\n","export function omit<T, K extends keyof T>(val: T, props: K[]): Omit<T, K> {\n const copy = {...val}\n for (const prop of props) {\n delete copy[prop]\n }\n return copy\n}\n","import {\n type InsertIfMissingOp,\n type InsertOp,\n type KeyedPathElement,\n type RelativePosition,\n type RemoveOp,\n type ReplaceOp,\n type TruncateOp,\n type UpsertOp,\n} from '../../../mutations/operations/types'\nimport {findTargetIndex, getTargetIdx, splice} from '../../utils/array'\n\nexport function insert<\n O extends InsertOp<unknown[], RelativePosition, number | KeyedPathElement>,\n CurrentValue extends unknown[],\n>(op: O, currentValue: CurrentValue) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"insert()\" on non-array value')\n }\n\n const index = findTargetIndex(currentValue, op.referenceItem)\n if (index === null) {\n throw new Error(`Found no matching array element to insert ${op.position}`)\n }\n // special case for empty arrays\n if (currentValue.length === 0) {\n return op.items\n }\n return splice(currentValue, getTargetIdx(op.position, index), 0, op.items)\n}\n\nexport function upsert<\n O extends UpsertOp<{_key: string}[], RelativePosition, KeyedPathElement>,\n CurrentValue extends unknown[],\n>(op: O, currentValue: CurrentValue) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"upsert()\" on non-array value')\n }\n\n if (op.items.length === 0) {\n return currentValue\n }\n const replaceItemsMap: Record<number, number> = {}\n const insertItems: unknown[] = []\n op.items.forEach((itemToBeUpserted: any, i) => {\n const existingIndex = currentValue.findIndex(\n existingItem => (existingItem as any)?._key === itemToBeUpserted._key,\n )\n if (existingIndex >= 0) {\n replaceItemsMap[existingIndex] = i\n } else {\n insertItems.push(itemToBeUpserted)\n }\n })\n\n const itemsToReplace = Object.keys(replaceItemsMap)\n if (itemsToReplace.length === 0 && insertItems.length == 0) {\n return currentValue\n }\n\n const next = [...currentValue]\n // Replace existing items\n for (const i of itemsToReplace) {\n const index = Number(i)\n next[index] = op.items[replaceItemsMap[index]!]!\n }\n\n // Insert the items that doesn't exist\n return insert(\n {\n type: 'insert',\n items: insertItems,\n referenceItem: op.referenceItem,\n position: op.position,\n },\n next,\n )\n}\nexport function insertIfMissing<\n O extends InsertIfMissingOp<\n {_key: string}[],\n RelativePosition,\n KeyedPathElement\n >,\n CurrentValue extends unknown[],\n>(op: O, currentValue: CurrentValue) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"insertIfMissing()\" on non-array value')\n }\n\n if (op.items.length === 0) {\n return currentValue\n }\n const itemsToInsert = op.items.filter(\n item =>\n !currentValue.find(existing => item._key === (existing as any)?._key),\n )\n\n if (itemsToInsert.length === 0) {\n return currentValue\n }\n\n // Insert the items that doesn't exist\n return insert(\n {\n type: 'insert',\n items: itemsToInsert,\n referenceItem: op.referenceItem,\n position: op.position,\n },\n currentValue,\n )\n}\n\nexport function replace<\n O extends ReplaceOp<unknown[], number | KeyedPathElement>,\n CurrentValue extends unknown[],\n>(op: O, currentValue: CurrentValue) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"replace()\" on non-array value')\n }\n\n const index = findTargetIndex(currentValue, op.referenceItem)\n if (index === null) {\n throw new Error(`Found no matching array element to replace`)\n }\n return splice(currentValue, index, op.items.length, op.items)\n}\nexport function remove<\n O extends RemoveOp<number | KeyedPathElement>,\n CurrentValue extends unknown[],\n>(op: O, currentValue: CurrentValue) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"remove()\" on non-array value')\n }\n\n const index = findTargetIndex(currentValue, op.referenceItem)\n if (index === null) {\n throw new Error(`Found no matching array element to replace`)\n }\n return splice(currentValue, index, 1, [])\n}\n\nexport function truncate<O extends TruncateOp, CurrentValue extends unknown[]>(\n op: O,\n currentValue: CurrentValue,\n) {\n if (!Array.isArray(currentValue)) {\n throw new TypeError('Cannot apply \"truncate()\" on non-array value')\n }\n\n return typeof op.endIndex === 'number'\n ? currentValue\n .slice(0, op.startIndex)\n .concat(currentValue.slice(op.endIndex))\n : currentValue.slice(0, op.startIndex)\n}\n","import {\n type SetIfMissingOp,\n type SetOp,\n type UnsetOp,\n} from '../../../mutations/operations/types'\n\nexport function set<O extends SetOp<any>, CurrentValue>(\n op: O,\n currentValue: CurrentValue,\n) {\n return op.value\n}\n\nexport function setIfMissing<O extends SetIfMissingOp<any>, CurrentValue>(\n op: O,\n currentValue: CurrentValue,\n) {\n return currentValue ?? op.value\n}\n\nexport function unset<O extends UnsetOp, CurrentValue>(op: O) {\n return undefined\n}\n","import {type DecOp, type IncOp} from '../../../mutations/operations/types'\n\nexport function inc<O extends IncOp<number>, CurrentValue extends number>(\n op: O,\n currentValue: CurrentValue,\n) {\n if (typeof currentValue !== 'number') {\n throw new TypeError('Cannot apply \"inc()\" on non-numeric value')\n }\n\n return currentValue + op.amount\n}\n\nexport function dec<O extends DecOp<number>, CurrentValue extends number>(\n op: O,\n currentValue: CurrentValue,\n) {\n if (typeof currentValue !== 'number') {\n throw new TypeError('Cannot apply \"dec()\" on non-numeric value')\n }\n\n return currentValue - op.amount\n}\n","export const hasOwn = Object.prototype.hasOwnProperty.call.bind(\n Object.prototype.hasOwnProperty,\n)\n","import {hasOwn} from './hasOwn'\n\nexport function isEmpty(v: object) {\n for (const key in v) {\n if (hasOwn(v, key)) {\n return false\n }\n }\n return true\n}\n","import {\n type AssignOp,\n type UnassignOp,\n} from '../../../mutations/operations/types'\nimport {isObject} from '../../../utils/isObject'\nimport {isEmpty} from '../../utils/isEmpty'\nimport {omit} from '../../utils/omit'\n\nexport function unassign<T extends object, K extends string[]>(\n op: UnassignOp<K>,\n currentValue: T,\n) {\n if (!isObject(currentValue)) {\n throw new TypeError('Cannot apply \"unassign()\" on non-object value')\n }\n\n return op.keys.length === 0\n ? currentValue\n : omit(currentValue, op.keys as any[])\n}\n\nexport function assign<T extends object>(op: AssignOp<T>, currentValue: T) {\n if (!isObject(currentValue)) {\n throw new TypeError('Cannot apply \"assign()\" on non-object value')\n }\n\n return isEmpty(op.value) ? currentValue : {...currentValue, ...op.value}\n}\n","import {applyPatches, parsePatch} from '@sanity/diff-match-patch'\n\nimport {type DiffMatchPatchOp} from '../../../mutations/operations/types'\n\nexport function diffMatchPatch<\n O extends DiffMatchPatchOp,\n CurrentValue extends string,\n>(op: O, currentValue: CurrentValue) {\n if (typeof currentValue !== 'string') {\n throw new TypeError('Cannot apply \"diffMatchPatch()\" on non-string value')\n }\n\n return applyPatches(parsePatch(op.value), currentValue)[0]\n}\n","import {\n type AnyOp,\n type ArrayOp,\n type NumberOp,\n type ObjectOp,\n type Operation,\n type StringOp,\n} from '../../mutations/operations/types'\nimport {type AnyArray} from '../../utils/typeUtils'\nimport * as operations from './operations'\nimport {type ApplyOp} from './typings/applyOp'\n\nexport function applyOp<const Op extends AnyOp, const CurrentValue>(\n op: Op,\n currentValue: CurrentValue,\n): ApplyOp<Op, CurrentValue>\nexport function applyOp<\n const Op extends NumberOp,\n const CurrentValue extends number,\n>(op: Op, currentValue: CurrentValue): ApplyOp<Op, CurrentValue>\nexport function applyOp<\n const Op extends StringOp,\n const CurrentValue extends string,\n>(op: Op, currentValue: CurrentValue): ApplyOp<Op, CurrentValue>\nexport function applyOp<\n const Op extends ObjectOp,\n const CurrentValue extends {[k in keyof any]: unknown},\n>(op: Op, currentValue: CurrentValue): ApplyOp<Op, CurrentValue>\nexport function applyOp<\n const Op extends ArrayOp,\n const CurrentValue extends AnyArray,\n>(op: Op, currentValue: CurrentValue): ApplyOp<Op, CurrentValue>\nexport function applyOp<const Op extends Operation, const CurrentValue>(\n op: Op,\n currentValue: CurrentValue,\n): ApplyOp<Op, CurrentValue> {\n if (!(op.type in operations)) {\n throw new Error(`Invalid operation type: \"${op.type}\"`)\n }\n\n // eslint-disable-next-line import/namespace\n return (operations[op.type] as CallableFunction)(op, currentValue)\n}\n","import {type Operation} from '../../mutations/operations/types'\nimport {type NodePatch, type NodePatchList} from '../../mutations/types'\nimport {isArrayElement, isPropertyElement, stringify} from '../../path'\nimport {isObject} from '../../utils/isObject'\nimport {type NormalizeReadOnlyArray} from '../../utils/typeUtils'\nimport {type KeyedPathElement, type Path} from '../'\nimport {findTargetIndex, splice} from '../utils/array'\nimport {omit} from '../utils/omit'\nimport {applyOp} from './applyOp'\nimport {\n type ApplyAtPath,\n type ApplyNodePatch,\n type ApplyPatches,\n} from './typings/applyNodePatch'\n\nexport function applyPatches<Patches extends NodePatchList, const Doc>(\n patches: Patches,\n document: Doc,\n): ApplyPatches<NormalizeReadOnlyArray<Patches>, Doc> {\n return (patches as NodePatch[]).reduce(\n (prev, patch) => applyNodePatch(patch, prev) as any,\n document,\n ) as any\n}\n\nexport function applyNodePatch<const Patch extends NodePatch, const Doc>(\n patch: Patch,\n document: Doc,\n): ApplyNodePatch<Patch, Doc> {\n return applyAtPath(patch.path, patch.op, document) as any\n}\n\nfunction applyAtPath<P extends Path, O extends Operation, T>(\n path: P,\n op: O,\n value: T,\n): ApplyAtPath<P, O, T> {\n if (!isNonEmptyArray(path)) {\n return applyOp(op as any, value) as any\n }\n\n const [head, ...tail] = path\n\n if (isArrayElement(head) && Array.isArray(value)) {\n return applyInArray(head, tail, op, value) as any\n }\n\n if (isPropertyElement(head) && isObject(value)) {\n return applyInObject(head, tail, op, value) as any\n }\n\n throw new Error(\n `Cannot apply operation of type \"${op.type}\" to path ${stringify(\n path,\n )} on ${typeof value} value`,\n )\n}\n\nfunction applyInObject<Key extends keyof any, T extends {[key in Key]?: any}>(\n head: Key,\n tail: Path,\n op: Operation,\n object: T,\n) {\n const current = object[head]\n\n if (current === undefined && tail.length > 0) {\n return object\n }\n\n // The patch targets the item at the index specified by \"head\"\n // so forward it to the item\n const patchedValue = applyAtPath(tail, op, current)\n\n if (patchedValue === undefined) {\n // unset op on an object field should not leave the field undefined\n // eg. apply(at('bar', unset()), {foo: 1, bar: 2, baz: 3} should result in\n // {foo: 1, baz: 3}, not {foo: 1, bar: undefined, baz: 3}\n\n return omit(object, [head])\n }\n // If the result of applying it to the item yields the item back we assume it was\n // a noop and don't modify our value. If we get a new value back, we return a\n // new array with the modified item replaced\n return patchedValue === current ? object : {...object, [head]: patchedValue}\n}\n\nfunction applyInArray<T>(\n head: number | KeyedPathElement,\n tail: Path,\n op: Operation,\n value: T[],\n) {\n const index = findTargetIndex(value, head!)\n\n if (index === null) {\n // partial is default behavior for arrays\n // the patch targets an index that is out of bounds\n return value\n }\n\n // If the given selector could not be found, return as-is\n if (index === -1) {\n return value\n }\n\n const current = value[index]!\n\n // The patch targets the item at the index specified by \"head\"\n // so forward it to the item\n const patchedItem = applyAtPath(tail, op, current)\n\n // If the result of applying it to the item yields the item back we assume it was\n // a noop and don't modify our value. If we get a new value back, we return a\n // new array with the modified item replaced\n return patchedItem === current\n ? value\n : splice(\n value,\n index,\n 1,\n // unset op on an array item should not leave a \"hole\" in the array\n // eg. apply(at('someArray[1]', unset()), ['foo', 'bar', 'baz'] should result in\n // ['foo', 'baz'], not ['foo', undefined, 'baz']\n patchedItem === undefined ? [] : [patchedItem],\n )\n}\n\nfunction isNonEmptyArray<T>(a: T[] | readonly T[]): a is [T, ...T[]] {\n return a.length > 0\n}\n","import {type PatchMutation, type SanityDocumentBase} from '../mutations/types'\nimport {type NormalizeReadOnlyArray} from '../utils/typeUtils'\nimport {applyPatches} from './patch/applyNodePatch'\nimport {type ApplyPatches} from './patch/typings/applyNodePatch'\n\nexport type ApplyPatchMutation<\n Mutation extends PatchMutation,\n Doc extends SanityDocumentBase,\n> =\n Mutation extends PatchMutation<infer Patches>\n ? ApplyPatches<NormalizeReadOnlyArray<Patches>, Doc>\n : Doc\n\nexport function applyPatchMutation<\n const Mutation extends PatchMutation,\n const Doc extends SanityDocumentBase,\n>(mutation: Mutation, document: Doc): ApplyPatchMutation<Mutation, Doc> {\n if (\n mutation.options?.ifRevision &&\n document._rev !== mutation.options.ifRevision\n ) {\n throw new Error('Revision mismatch')\n }\n if (mutation.id !== document._id) {\n throw new Error(\n `Document id mismatch. Refusing to apply mutation for document with id=\"${mutation.id}\" on the given document with id=\"${document._id}\"`,\n )\n }\n return applyPatches(mutation.patches, document) as any\n}\n","import {type SanityDocumentBase} from '../../mutations/types'\nimport {type StoredDocument} from '../applyInIndex'\n\nexport function hasId(doc: SanityDocumentBase): doc is StoredDocument {\n return '_id' in doc\n}\nexport function assignId<Doc extends SanityDocumentBase>(\n doc: Doc,\n generateId: () => string,\n): Doc & {_id: string} {\n return hasId(doc) ? doc : {...doc, _id: generateId()}\n}\n"],"names":["applyPatches"],"mappings":";;;AAAO,SAAS,MAAM,OAA2B;AAC/C,SACG,UAAU,QACT,OAAO,SAAU,YACjB,OAAO,MAAM,QAAS,YACtB,MAAM,QACR;AAEJ;ACLO,SAAS,gBAAmB,OAAY,aAA0B;AACvE,MAAI,OAAO,eAAgB;AACzB,WAAO,eAAe,MAAM,QAAQ,WAAW;AAEjD,MAAI,eAAe,WAAW,GAAG;AAC/B,UAAM,MAAM,MAAM,UAAU,CAAA,UAAS,MAAM,KAAK,MAAM,YAAY,IAAI;AACtE,WAAO,QAAQ,KAAK,OAAO;AAAA,EAC7B;AACA,QAAM,IAAI;AAAA,IACR,gHAAgH,KAAK;AAAA,MACnH;AAAA,IAAA,CACD;AAAA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AAI,iBAAiB,SAKZ,KAAK,QAAQ,CAAC,IAAI,CAAC,IAKrB,iBAAiB,UAAU,SAAS,EAAC,GAAG,QAAQ,CAAC,IAAI,GAAG,aAAA;AACjE;AAEA,SAAS,aACP,MACA,MACA,IACA,OACA;AACA,QAAM,QAAQ,gBAAgB,OAAO,IAAK;AAS1C,MAPI,UAAU,QAOV,UAAU;AACZ,WAAO;AAGT,QAAM,UAAU,MAAM,KAAK,GAIrB,cAAc,YAAY,MAAM,IAAI,OAAO;AAKjD,SAAO,gBAAgB,UACnB,QACA;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA;AAAA;AAAA;AAAA,IAIA,gBAAgB,SAAY,CAAA,IAAK,CAAC,WAAW;AAAA,EAAA;AAErD;AAEA,SAAS,gBAAmB,GAAyC;AACnE,SAAO,EAAE,SAAS;AACpB;ACrHO,SAAS,mBAGd,UAAoB,UAAkD;AACtE,MACE,SAAS,SAAS,cAClB,SAAS,SAAS,SAAS,QAAQ;AAEnC,UAAM,IAAI,MAAM,mBAAmB;AAErC,MAAI,SAAS,OAAO,SAAS;AAC3B,UAAM,IAAI;AAAA,MACR,0EAA0E,SAAS,EAAE,oCAAoC,SAAS,GAAG;AAAA,IAAA;AAGzI,SAAO,aAAa,SAAS,SAAS,QAAQ;AAChD;AC1BO,SAAS,MAAM,KAAgD;AACpE,SAAO,SAAS;AAClB;AACO,SAAS,SACd,KACA,YACqB;AACrB,SAAO,MAAM,GAAG,IAAI,MAAM,EAAC,GAAG,KAAK,KAAK,aAAW;AACrD;"} |
| import { AnyArray, AnyEmptyArray, ArrayElement, ArrayLength, ByIndex, Concat, ConcatInner, Digit, ElementType, EmptyArray, Err, FindBy, FindInArray, Format, Index as Index$1, KeyedPathElement, Merge, MergeInner, NormalizeReadOnlyArray, Ok, OnlyDigits, Optional, ParseAllProps, ParseError, ParseExpressions, ParseInnerExpression, ParseKVPair, ParseNumber, ParseObject, ParseProperty, ParseValue, Path, PathElement, PropertyName, Result, SafePath, Split, SplitAll, StringToPath, StripError, ToArray, ToNumber, Trim, TrimLeft, TrimRight, Try, Unwrap } from "./_chunks-dts/types.cjs"; | ||
| import { Get, GetAtPath, getAtPath, isArrayElement, isElementEqual, isEqual, isIndexElement, isKeyElement, isKeyedElement, isPropertyElement, normalize, parse, startsWith, stringify } from "./_chunks-dts/predicates.cjs"; | ||
| import { AnyOp, ArrayOp, AssignOp, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, IncOp, InsertOp, Mutation as Mutation$1, NodePatch, NodePatchList, NumberOp, ObjectOp, Operation, PatchMutation, PatchOptions, PrimitiveOp, RelativePosition, RemoveOp, ReplaceOp, SanityDocumentBase, SetIfMissingOp, SetOp, StringOp, TruncateOp, UnassignOp, UnsetOp, UpsertOp } from "./_chunks-dts/types2.cjs"; | ||
| import { AnyOp, ArrayOp, AssignOp, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, IncOp, InsertIfMissingOp, InsertOp, Mutation as Mutation$1, NodePatch, NodePatchList, NumberOp, ObjectOp, Operation, PatchMutation, PatchOptions, PrimitiveOp, RelativePosition, RemoveOp, ReplaceOp, SanityDocumentBase, SetIfMissingOp, SetOp, StringOp, TruncateOp, UnassignOp, UnsetOp, UpsertOp } from "./_chunks-dts/types2.cjs"; | ||
| import { Call, Numbers, Tuples } from "hotscript"; | ||
@@ -58,3 +58,3 @@ declare function applyInCollection<Doc extends SanityDocumentBase>(collection: Doc[], mutations: Mutation$1 | Mutation$1[]): any[]; | ||
| declare function applyOp<const Op extends ArrayOp, const CurrentValue extends AnyArray>(op: Op, currentValue: CurrentValue): ApplyOp<Op, CurrentValue>; | ||
| export { AdjustIndex, AnyArray, AnyEmptyArray, AnyOp, ApplyAtIndex, ApplyAtPath, ApplyAtSelector, ApplyInArray, ApplyInObject, ApplyNodePatch, ApplyOp, ApplyPatchMutation, ApplyPatches, ArrayElement, ArrayInsert, ArrayLength, ArrayOp, ArrayRemove, Assign, AssignOp, Between, ByIndex, Concat, ConcatInner, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, Digit, DocumentIndex, DropFirst, ElementType, EmptyArray, Err, FindBy, FindInArray, FirstIndexOf, Format, Get, GetAtPath, IncOp, Index$1 as Index, InsertAtIndex, InsertOp, KeyedPathElement, LastIndexOnEmptyArray, Merge, MergeInner, Mutation$1 as Mutation, NodePatch, NodePatchList, NormalizeIndex, NormalizeReadOnlyArray, NumberOp, ObjectOp, Ok, OnlyDigits, Operation, Optional, ParseAllProps, ParseError, ParseExpressions, ParseInnerExpression, ParseKVPair, ParseNumber, ParseObject, ParseProperty, ParseValue, PatchMutation, PatchOptions, Path, PathElement, PickOrUndef, PrimitiveOp, PropertyName, RelativePosition, RemoveAtIndex, RemoveOp, ReplaceOp, RequiredSelect, Result, SafePath, SanityDocumentBase, SetIfMissingOp, SetOp, Split, SplitAll, SplitAtPos, StoredDocument, StringOp, StringToPath, StripError, ToArray, ToIdentified, ToNumber, ToStored, Trim, TrimLeft, TrimRight, TruncateOp, Try, UnassignOp, UnsetOp, Unwrap, UpsertOp, _InsertAtIndex, _RemoveAtIndex, applyInCollection, applyInIndex, applyNodePatch, applyOp, applyPatchMutation, applyPatches, assignId, createStore, getAtPath, hasId, isArrayElement, isElementEqual, isEqual, isIndexElement, isKeyElement, isKeyedElement, isPropertyElement, normalize, parse, startsWith, stringify }; | ||
| export { AdjustIndex, AnyArray, AnyEmptyArray, AnyOp, ApplyAtIndex, ApplyAtPath, ApplyAtSelector, ApplyInArray, ApplyInObject, ApplyNodePatch, ApplyOp, ApplyPatchMutation, ApplyPatches, ArrayElement, ArrayInsert, ArrayLength, ArrayOp, ArrayRemove, Assign, AssignOp, Between, ByIndex, Concat, ConcatInner, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, Digit, DocumentIndex, DropFirst, ElementType, EmptyArray, Err, FindBy, FindInArray, FirstIndexOf, Format, Get, GetAtPath, IncOp, Index$1 as Index, InsertAtIndex, InsertIfMissingOp, InsertOp, KeyedPathElement, LastIndexOnEmptyArray, Merge, MergeInner, Mutation$1 as Mutation, NodePatch, NodePatchList, NormalizeIndex, NormalizeReadOnlyArray, NumberOp, ObjectOp, Ok, OnlyDigits, Operation, Optional, ParseAllProps, ParseError, ParseExpressions, ParseInnerExpression, ParseKVPair, ParseNumber, ParseObject, ParseProperty, ParseValue, PatchMutation, PatchOptions, Path, PathElement, PickOrUndef, PrimitiveOp, PropertyName, RelativePosition, RemoveAtIndex, RemoveOp, ReplaceOp, RequiredSelect, Result, SafePath, SanityDocumentBase, SetIfMissingOp, SetOp, Split, SplitAll, SplitAtPos, StoredDocument, StringOp, StringToPath, StripError, ToArray, ToIdentified, ToNumber, ToStored, Trim, TrimLeft, TrimRight, TruncateOp, Try, UnassignOp, UnsetOp, Unwrap, UpsertOp, _InsertAtIndex, _RemoveAtIndex, applyInCollection, applyInIndex, applyNodePatch, applyOp, applyPatchMutation, applyPatches, assignId, createStore, getAtPath, hasId, isArrayElement, isElementEqual, isEqual, isIndexElement, isKeyElement, isKeyedElement, isPropertyElement, normalize, parse, startsWith, stringify }; | ||
| //# sourceMappingURL=_unstable_apply.d.cts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"_unstable_apply.d.cts","names":[],"sources":["../src/apply/applyInCollection.ts","../src/apply/store/store.ts","../src/apply/store/utils.ts","../src/apply/applyInIndex.ts","../src/apply/patch/typings/applyOp.ts","../src/apply/patch/typings/applyNodePatch.ts","../src/apply/applyPatchMutation.ts","../src/apply/patch/applyNodePatch.ts","../src/apply/patch/applyOp.ts"],"sourcesContent":[],"mappings":";;;;iBAagB,8BAA8B,gCAChC,kBACD,aAAW;KCPZ,kCAAkC,KAAK,KAAK,GAAG,aACnD,MAAM,EAAE,IDIhB;AAAiC,cCapB,WDboB,EAAA,CAAA,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CAAA,iBQQd,QRRc,EAAA,2BAAA,MAAA,CAAA,CAAA,EAAA,EQU3B,ERV2B,EAAA,YAAA,EQUT,YRVS,CAAA,EQUM,ORVN,CQUc,ERVd,EQUkB,YRVlB,CAAA;AAAA,iBQWjB,ORXiB,CAAA,iBQYd,QRZc,EAAA,2BAAA,QAAa,MAAA,GAAA,GAAA,OAAA,QQcxC,ERbQ,EAAA,YAAA,EQaU,YRbV,CAAA,EQayB,ORbzB,CQaiC,ERbjC,EQaqC,YRbrC,CAAA;AACD,iBQaG,ORbH,CAAA,iBQcM,ORdN,EAAA,2BQegB,QRfhB,CAAA,CAAA,EAAA,EQgBP,ERhBO,EAAA,YAAA,EQgBW,YRhBX,CAAA,EQgB0B,ORhB1B,CQgBkC,ERhBlC,EQgBsC,YRhBtC,CAAA"} | ||
| {"version":3,"file":"_unstable_apply.d.cts","names":[],"sources":["../src/apply/applyInCollection.ts","../src/apply/store/store.ts","../src/apply/store/utils.ts","../src/apply/applyInIndex.ts","../src/apply/patch/typings/applyOp.ts","../src/apply/patch/typings/applyNodePatch.ts","../src/apply/applyPatchMutation.ts","../src/apply/patch/applyNodePatch.ts","../src/apply/patch/applyOp.ts"],"sourcesContent":[],"mappings":";;;;iBAagB,8BAA8B,gCAChC,kBACD,aAAW;KCPZ,kCAAkC,KAAK,KAAK,GAAG,aACnD,MAAM,EAAE,IDIhB;AAAiC,cCapB,WDboB,EAAA,CAAA,YCaO,kBDbP,CAAA,CAAA,cAAA,CAAA,ECcd,GDdc,EAAA,EAAA,GAAA;WAAa,OAAA,EAAA,MAAA;SAChC,EAAA,GAAA,GAAA,CAAA,MAAA,QAAA,SAAA,IAAA,qBAAA,CAAA,CAAA,CAAA,EAAA;KACD,EAAA,CAAA,WAAA,MAAA,CAAA,CAAA,EAAA,ECiCH,EDjCG,EAAA,GCkCN,MDlCM,CCkCC,IDlCD,CCkCK,MDlCL,CCkCK,QDlCL,CCkCK,GDlCL,GCkCK,kBDlCL,CAAA,CAAA,EA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iBQcM,ORdN,EAAA,2BQegB,QRfhB,CAAA,CAAA,EAAA,EQgBP,ERhBO,EAAA,YAAA,EQgBW,YRhBX,CAAA,EQgB0B,ORhB1B,CQgBkC,ERhBlC,EQgBsC,YRhBtC,CAAA"} |
| import { AnyArray, AnyEmptyArray, ArrayElement, ArrayLength, ByIndex, Concat, ConcatInner, Digit, ElementType, EmptyArray, Err, FindBy, FindInArray, Format, Index as Index$1, KeyedPathElement, Merge, MergeInner, NormalizeReadOnlyArray, Ok, OnlyDigits, Optional, ParseAllProps, ParseError, ParseExpressions, ParseInnerExpression, ParseKVPair, ParseNumber, ParseObject, ParseProperty, ParseValue, Path, PathElement, PropertyName, Result, SafePath, Split, SplitAll, StringToPath, StripError, ToArray, ToNumber, Trim, TrimLeft, TrimRight, Try, Unwrap } from "./_chunks-dts/types.js"; | ||
| import { Get, GetAtPath, getAtPath, isArrayElement, isElementEqual, isEqual, isIndexElement, isKeyElement, isKeyedElement, isPropertyElement, normalize, parse, startsWith, stringify } from "./_chunks-dts/predicates.js"; | ||
| import { AnyOp, ArrayOp, AssignOp, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, IncOp, InsertOp, Mutation as Mutation$1, NodePatch, NodePatchList, NumberOp, ObjectOp, Operation, PatchMutation, PatchOptions, PrimitiveOp, RelativePosition, RemoveOp, ReplaceOp, SanityDocumentBase, SetIfMissingOp, SetOp, StringOp, TruncateOp, UnassignOp, UnsetOp, UpsertOp } from "./_chunks-dts/types2.js"; | ||
| import { AnyOp, ArrayOp, AssignOp, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, IncOp, InsertIfMissingOp, InsertOp, Mutation as Mutation$1, NodePatch, NodePatchList, NumberOp, ObjectOp, Operation, PatchMutation, PatchOptions, PrimitiveOp, RelativePosition, RemoveOp, ReplaceOp, SanityDocumentBase, SetIfMissingOp, SetOp, StringOp, TruncateOp, UnassignOp, UnsetOp, UpsertOp } from "./_chunks-dts/types2.js"; | ||
| import { Call, Numbers, Tuples } from "hotscript"; | ||
@@ -58,3 +58,3 @@ declare function applyInCollection<Doc extends SanityDocumentBase>(collection: Doc[], mutations: Mutation$1 | Mutation$1[]): any[]; | ||
| declare function applyOp<const Op extends ArrayOp, const CurrentValue extends AnyArray>(op: Op, currentValue: CurrentValue): ApplyOp<Op, CurrentValue>; | ||
| export { AdjustIndex, AnyArray, AnyEmptyArray, AnyOp, ApplyAtIndex, ApplyAtPath, ApplyAtSelector, ApplyInArray, ApplyInObject, ApplyNodePatch, ApplyOp, ApplyPatchMutation, ApplyPatches, ArrayElement, ArrayInsert, ArrayLength, ArrayOp, ArrayRemove, Assign, AssignOp, Between, ByIndex, Concat, ConcatInner, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, Digit, DocumentIndex, DropFirst, ElementType, EmptyArray, Err, FindBy, FindInArray, FirstIndexOf, Format, Get, GetAtPath, IncOp, Index$1 as Index, InsertAtIndex, InsertOp, KeyedPathElement, LastIndexOnEmptyArray, Merge, MergeInner, Mutation$1 as Mutation, NodePatch, NodePatchList, NormalizeIndex, NormalizeReadOnlyArray, NumberOp, ObjectOp, Ok, OnlyDigits, Operation, Optional, ParseAllProps, ParseError, ParseExpressions, ParseInnerExpression, ParseKVPair, ParseNumber, ParseObject, ParseProperty, ParseValue, PatchMutation, PatchOptions, Path, PathElement, PickOrUndef, PrimitiveOp, PropertyName, RelativePosition, RemoveAtIndex, RemoveOp, ReplaceOp, RequiredSelect, Result, SafePath, SanityDocumentBase, SetIfMissingOp, SetOp, Split, SplitAll, SplitAtPos, StoredDocument, StringOp, StringToPath, StripError, ToArray, ToIdentified, ToNumber, ToStored, Trim, TrimLeft, TrimRight, TruncateOp, Try, UnassignOp, UnsetOp, Unwrap, UpsertOp, _InsertAtIndex, _RemoveAtIndex, applyInCollection, applyInIndex, applyNodePatch, applyOp, applyPatchMutation, applyPatches, assignId, createStore, getAtPath, hasId, isArrayElement, isElementEqual, isEqual, isIndexElement, isKeyElement, isKeyedElement, isPropertyElement, normalize, parse, startsWith, stringify }; | ||
| export { AdjustIndex, AnyArray, AnyEmptyArray, AnyOp, ApplyAtIndex, ApplyAtPath, ApplyAtSelector, ApplyInArray, ApplyInObject, ApplyNodePatch, ApplyOp, ApplyPatchMutation, ApplyPatches, ArrayElement, ArrayInsert, ArrayLength, ArrayOp, ArrayRemove, Assign, AssignOp, Between, ByIndex, Concat, ConcatInner, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, Digit, DocumentIndex, DropFirst, ElementType, EmptyArray, Err, FindBy, FindInArray, FirstIndexOf, Format, Get, GetAtPath, IncOp, Index$1 as Index, InsertAtIndex, InsertIfMissingOp, InsertOp, KeyedPathElement, LastIndexOnEmptyArray, Merge, MergeInner, Mutation$1 as Mutation, NodePatch, NodePatchList, NormalizeIndex, NormalizeReadOnlyArray, NumberOp, ObjectOp, Ok, OnlyDigits, Operation, Optional, ParseAllProps, ParseError, ParseExpressions, ParseInnerExpression, ParseKVPair, ParseNumber, ParseObject, ParseProperty, ParseValue, PatchMutation, PatchOptions, Path, PathElement, PickOrUndef, PrimitiveOp, PropertyName, RelativePosition, RemoveAtIndex, RemoveOp, ReplaceOp, RequiredSelect, Result, SafePath, SanityDocumentBase, SetIfMissingOp, SetOp, Split, SplitAll, SplitAtPos, StoredDocument, StringOp, StringToPath, StripError, ToArray, ToIdentified, ToNumber, ToStored, Trim, TrimLeft, TrimRight, TruncateOp, Try, UnassignOp, UnsetOp, Unwrap, UpsertOp, _InsertAtIndex, _RemoveAtIndex, applyInCollection, applyInIndex, applyNodePatch, applyOp, applyPatchMutation, applyPatches, assignId, createStore, getAtPath, hasId, isArrayElement, isElementEqual, isEqual, isIndexElement, isKeyElement, isKeyedElement, isPropertyElement, normalize, parse, startsWith, stringify }; | ||
| //# sourceMappingURL=_unstable_apply.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"_unstable_apply.d.ts","names":[],"sources":["../src/apply/applyInCollection.ts","../src/apply/store/store.ts","../src/apply/store/utils.ts","../src/apply/applyInIndex.ts","../src/apply/patch/typings/applyOp.ts","../src/apply/patch/typings/applyNodePatch.ts","../src/apply/applyPatchMutation.ts","../src/apply/patch/applyNodePatch.ts","../src/apply/patch/applyOp.ts"],"sourcesContent":[],"mappings":";;;;iBAagB,8BAA8B,gCAChC,kBACD,aAAW;KCPZ,kCAAkC,KAAK,KAAK,GAAG,aACnD,MAAM,EAAE,IDIhB;AAAiC,cCapB,WDboB,EAAA,CAAA,YCaO,kBDbP,CAAA,CAAA,cAAA,CAAA,ECcd,GDdc,EAAA,EAAA,GAAA;WAAa,OAAA,EAAA,MAAA;SAChC,EAAA,GAAA,GAAA,CAAA,MAAA,QAAA,SAAA,IAAA,qBAAA,CAAA,CAAA,CAAA,EAAA;KACD,EAAA,CAAA,WAAA,MAAA,CAAA,CAAA,EAAA,ECiCH,EDjCG,EAAA,GCkCN,MDlCM,CCkCC,IDlCD,CCkCK,MDlCL,CCkCK,QDlCL,CCkCK,GDlCL,GCkCK,kBDlCL,CAAA,CAAA,EAAA,KAAA,CAAA,GAAA;IAAW,GAAA,ECkC8C,EDlC9C;EAAQ,CAAA,CAAA;qBCoCT,eAAa;AA3CpC,CAAA;iBCLgB,KAAA,MAAW,4BAA4B;iBAGvC,qBAAqB,yBAC9B,gCAEJ;;AFIH,CAAA;KGCY,0BAA0B;gBAAqC;;AHD3D,iBGGA,YHHiB,CAAA,YGInB,kBHJmB,EAAA,cGKjB,aHLiB,CGKH,QHLG,CGKM,GHLN,CAAA,CAAA,CAAA,CAAA,KAAA,EGMxB,KHNwB,EAAA,SAAA,EGMN,UHNM,CGMG,GHNH,CAAA,EAAA,CAAA,EGMY,KHNZ;AAAA,KG4BrB,QH5BqB,CAAA,YG4BA,kBH5BA,CAAA,GG4BsB,GH5Bt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ee;KI4EP,6BAA6B,mBACvC,cAAc,+BACV,YAAY,GAAG,IAAI,QACnB,YAAY,eAAe,aAAa;KCrGlC,oCACO,2BACL,sBAEZ,iBAAiB,+BACb,aAAa,uBAAuB,UAAU,OAC9C;iBAEU,0CACS,iCACL,8BACR,oBAAoB,MAAM,mBAAmB,UAAU;iBCFnD,6BAA6B,mCAClC,mBACC,MACT,aAAa,uBAAuB,UAAU;iBAOjC,mCAAmC,6BAC1C,iBACG,MACT,eAAe,OAAO;iBCfT,yBAAyB,+BACnC,kBACU,eACb,QAAQ,IAAI;iBACC,yBACG,iDAEb,kBAAkB,eAAe,QAAQ,IAAI;ARNnC,iBQOA,ORPiB,CAAA,iBQQd,QRRc,EAAA,2BAAA,MAAA,CAAA,CAAA,EAAA,EQU3B,ERV2B,EAAA,YAAA,EQUT,YRVS,CAAA,EQUM,ORVN,CQUc,ERVd,EQUkB,YRVlB,CAAA;AAAA,iBQWjB,ORXiB,CAAA,iBQYd,QRZc,EAAA,2BAAA,QAAa,MAAA,GAAA,GAAA,OAAA,QQcxC,ERbQ,EAAA,YAAA,EQaU,YRbV,CAAA,EQayB,ORbzB,CQaiC,ERbjC,EQaqC,YRbrC,CAAA;AACD,iBQaG,ORbH,CAAA,iBQcM,ORdN,EAAA,2BQegB,QRfhB,CAAA,CAAA,EAAA,EQgBP,ERhBO,EAAA,YAAA,EQgBW,YRhBX,CAAA,EQgB0B,ORhB1B,CQgBkC,ERhBlC,EQgBsC,YRhBtC,CAAA"} | ||
| {"version":3,"file":"_unstable_apply.d.ts","names":[],"sources":["../src/apply/applyInCollection.ts","../src/apply/store/store.ts","../src/apply/store/utils.ts","../src/apply/applyInIndex.ts","../src/apply/patch/typings/applyOp.ts","../src/apply/patch/typings/applyNodePatch.ts","../src/apply/applyPatchMutation.ts","../src/apply/patch/applyNodePatch.ts","../src/apply/patch/applyOp.ts"],"sourcesContent":[],"mappings":";;;;iBAagB,8BAA8B,gCAChC,kBACD,aAAW;KCPZ,kCAAk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,IAAI;iBACC,yBACG,iDAEb,kBAAkB,eAAe,QAAQ,IAAI;ARNnC,iBQOA,ORPiB,CAAA,iBQQd,QRRc,EAAA,2BAAA,MAAA,CAAA,CAAA,EAAA,EQU3B,ERV2B,EAAA,YAAA,EQUT,YRVS,CAAA,EQUM,ORVN,CQUc,ERVd,EQUkB,YRVlB,CAAA;AAAA,iBQWjB,ORXiB,CAAA,iBQYd,QRZc,EAAA,2BAAA,QAAa,MAAA,GAAA,GAAA,OAAA,QQcxC,ERbQ,EAAA,YAAA,EQaU,YRbV,CAAA,EQayB,ORbzB,CQaiC,ERbjC,EQaqC,YRbrC,CAAA;AACD,iBQaG,ORbH,CAAA,iBQcM,ORdN,EAAA,2BQegB,QRfhB,CAAA,CAAA,EAAA,EQgBP,ERhBO,EAAA,YAAA,EQgBW,YRhBX,CAAA,EQgB0B,ORhB1B,CQgBkC,ERhBlC,EQgBsC,YRhBtC,CAAA"} |
| import { AnyArray, AnyEmptyArray, ByIndex, Concat, ConcatInner, Digit, ElementType, Err, FindBy, FindInArray, Index, KeyedPathElement, Merge, MergeInner, Ok, OnlyDigits, Optional, ParseAllProps, ParseError, ParseExpressions, ParseInnerExpression, ParseKVPair, ParseNumber, ParseObject, ParseProperty, ParseValue, Path, PathElement, PropertyName, Result, SafePath, Split, SplitAll, StringToPath, StripError, ToArray, ToNumber, Trim, TrimLeft, TrimRight, Try, Unwrap } from "./_chunks-dts/types.cjs"; | ||
| import { Get, GetAtPath, getAtPath, isArrayElement, isElementEqual, isEqual, isIndexElement, isKeyElement, isKeyedElement, isPropertyElement, normalize, parse, startsWith, stringify } from "./_chunks-dts/predicates.cjs"; | ||
| import { AnyOp, ArrayOp, AssignOp, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, IncOp, InsertOp, Mutation, NodePatch, NodePatchList, NumberOp, ObjectOp, Operation, PatchMutation, PatchOptions, PrimitiveOp, RelativePosition, RemoveOp, ReplaceOp, SanityDocumentBase, SetIfMissingOp, SetOp, StringOp, Transaction, TruncateOp, UnassignOp, UnsetOp, UpsertOp } from "./_chunks-dts/types2.cjs"; | ||
| import { AnyOp, ArrayOp, AssignOp, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, IncOp, InsertIfMissingOp, InsertOp, Mutation, NodePatch, NodePatchList, NumberOp, ObjectOp, Operation, PatchMutation, PatchOptions, PrimitiveOp, RelativePosition, RemoveOp, ReplaceOp, SanityDocumentBase, SetIfMissingOp, SetOp, StringOp, Transaction, TruncateOp, UnassignOp, UnsetOp, UpsertOp } from "./_chunks-dts/types2.cjs"; | ||
| import { Insert, SanityCreateIfNotExistsMutation, SanityCreateMutation, SanityCreateOrReplaceMutation, SanityDecPatch, SanityDeleteMutation, SanityDiffMatchPatch, SanityIncPatch, SanityInsertPatch, SanityMutation, SanitySetIfMissingPatch, SanitySetPatch, SanityUnsetPatch } from "./_chunks-dts/types3.cjs"; | ||
@@ -350,3 +350,3 @@ import { Observable } from "rxjs"; | ||
| declare function createOptimisticStoreMockBackend(backendAPI: MockBackendAPI): OptimisticStoreBackend; | ||
| export { AccessibleDocumentResult, AnyArray, AnyEmptyArray, AnyOp, ArrayOp, AssignOp, ByIndex, Concat, ConcatInner, Conflict, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, Digit, DocEndpointResponse, DocumentIdSetEvent, DocumentIdSetState, DocumentLoader, DocumentMap, DocumentMutationUpdate, DocumentReconnectUpdate, DocumentResult, DocumentSyncUpdate, DocumentUpdate, DocumentUpdateListener, ElementType, Err, FetchDocumentIdsFn, FetchDocuments, FindBy, FindInArray, Get, GetAtPath, IdSetListenFn, InaccessibleDocumentResult, InaccessibleReason, IncOp, Index, InitialEvent, Insert, InsertMethod, InsertOp, KeyedPathElement, ListenerChannelErrorEvent, ListenerDisconnectEvent, ListenerEndpointEvent, ListenerEvent, ListenerMutationEvent, ListenerOptions, ListenerReconnectEvent, ListenerSyncEvent, ListenerWelcomeEvent, MapTuple, Merge, MergeInner, MockBackendAPI, Mutation, MutationGroup, MutationResult, NodePatch, NodePatchList, NonTransactionalMutationGroup, NumberOp, ObjectOp, Ok, OmittedDocument, OnlyDigits, Operation, OptimisticDocumentEvent, OptimisticStore, OptimisticStoreBackend, Optional, ParseAllProps, ParseError, ParseExpressions, ParseInnerExpression, ParseKVPair, ParseNumber, ParseObject, ParseProperty, ParseValue, PatchMutation, PatchOptions, Path, PathElement, PrimitiveOp, PropertyName, QueryParams, ReadOnlyDocumentStore, RelativePosition, RemoteDocumentEvent, RemoteMutationEvent, RemoteSyncEvent, RemoveOp, ReplaceOp, RequestOptions, Result, SafePath, SanityCreateIfNotExistsMutation, SanityCreateMutation, SanityCreateOrReplaceMutation, SanityDecPatch, SanityDeleteMutation, SanityDiffMatchPatch, SanityDocumentBase, SanityIncPatch, SanityInsertPatch, SanityMutation, SanitySetIfMissingPatch, SanitySetPatch, SanityUnsetPatch, SetIfMissingOp, SetOp, SharedListenerListenFn, Split, SplitAll, StringOp, StringToPath, StripError, SubmitResult, ToArray, ToNumber, Transaction, TransactionalMutationGroup, Trim, TrimLeft, TrimRight, TruncateOp, Try, UnassignOp, UnsetOp, Unwrap, UpsertOp, createDocumentEventListener, createDocumentLoader, createDocumentLoaderFromClient, createDocumentUpdateListener, createIdSetListener, createIdSetListenerFromClient, createMockBackendAPI, createOptimisticStore, createOptimisticStoreClientBackend, createOptimisticStoreMockBackend, createReadOnlyStore, createSharedListener, createSharedListenerFromClient, getAtPath, isArrayElement, isElementEqual, isEqual, isIndexElement, isKeyElement, isKeyedElement, isPropertyElement, normalize, parse, startsWith, stringify, toState }; | ||
| export { AccessibleDocumentResult, AnyArray, AnyEmptyArray, AnyOp, ArrayOp, AssignOp, ByIndex, Concat, ConcatInner, Conflict, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, Digit, DocEndpointResponse, DocumentIdSetEvent, DocumentIdSetState, DocumentLoader, DocumentMap, DocumentMutationUpdate, DocumentReconnectUpdate, DocumentResult, DocumentSyncUpdate, DocumentUpdate, DocumentUpdateListener, ElementType, Err, FetchDocumentIdsFn, FetchDocuments, FindBy, FindInArray, Get, GetAtPath, IdSetListenFn, InaccessibleDocumentResult, InaccessibleReason, IncOp, Index, InitialEvent, Insert, InsertIfMissingOp, InsertMethod, InsertOp, KeyedPathElement, ListenerChannelErrorEvent, ListenerDisconnectEvent, ListenerEndpointEvent, ListenerEvent, ListenerMutationEvent, ListenerOptions, ListenerReconnectEvent, ListenerSyncEvent, ListenerWelcomeEvent, MapTuple, Merge, MergeInner, MockBackendAPI, Mutation, MutationGroup, MutationResult, NodePatch, NodePatchList, NonTransactionalMutationGroup, NumberOp, ObjectOp, Ok, OmittedDocument, OnlyDigits, Operation, OptimisticDocumentEvent, OptimisticStore, OptimisticStoreBackend, Optional, ParseAllProps, ParseError, ParseExpressions, ParseInnerExpression, ParseKVPair, ParseNumber, ParseObject, ParseProperty, ParseValue, PatchMutation, PatchOptions, Path, PathElement, PrimitiveOp, PropertyName, QueryParams, ReadOnlyDocumentStore, RelativePosition, RemoteDocumentEvent, RemoteMutationEvent, RemoteSyncEvent, RemoveOp, ReplaceOp, RequestOptions, Result, SafePath, SanityCreateIfNotExistsMutation, SanityCreateMutation, SanityCreateOrReplaceMutation, SanityDecPatch, SanityDeleteMutation, SanityDiffMatchPatch, SanityDocumentBase, SanityIncPatch, SanityInsertPatch, SanityMutation, SanitySetIfMissingPatch, SanitySetPatch, SanityUnsetPatch, SetIfMissingOp, SetOp, SharedListenerListenFn, Split, SplitAll, StringOp, StringToPath, StripError, SubmitResult, ToArray, ToNumber, Transaction, TransactionalMutationGroup, Trim, TrimLeft, TrimRight, TruncateOp, Try, UnassignOp, UnsetOp, Unwrap, UpsertOp, createDocumentEventListener, createDocumentLoader, createDocumentLoaderFromClient, createDocumentUpdateListener, createIdSetListener, createIdSetListenerFromClient, createMockBackendAPI, createOptimisticStore, createOptimisticStoreClientBackend, createOptimisticStoreMockBackend, createReadOnlyStore, createSharedListener, createSharedListenerFromClient, getAtPath, isArrayElement, isElementEqual, isEqual, isIndexElement, isKeyElement, isKeyedElement, isPropertyElement, normalize, parse, startsWith, stringify, toState }; | ||
| //# sourceMappingURL=_unstable_store.d.cts.map |
| import { AnyArray, AnyEmptyArray, ByIndex, Concat, ConcatInner, Digit, ElementType, Err, FindBy, FindInArray, Index, KeyedPathElement, Merge, MergeInner, Ok, OnlyDigits, Optional, ParseAllProps, ParseError, ParseExpressions, ParseInnerExpression, ParseKVPair, ParseNumber, ParseObject, ParseProperty, ParseValue, Path, PathElement, PropertyName, Result, SafePath, Split, SplitAll, StringToPath, StripError, ToArray, ToNumber, Trim, TrimLeft, TrimRight, Try, Unwrap } from "./_chunks-dts/types.js"; | ||
| import { Get, GetAtPath, getAtPath, isArrayElement, isElementEqual, isEqual, isIndexElement, isKeyElement, isKeyedElement, isPropertyElement, normalize, parse, startsWith, stringify } from "./_chunks-dts/predicates.js"; | ||
| import { AnyOp, ArrayOp, AssignOp, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, IncOp, InsertOp, Mutation, NodePatch, NodePatchList, NumberOp, ObjectOp, Operation, PatchMutation, PatchOptions, PrimitiveOp, RelativePosition, RemoveOp, ReplaceOp, SanityDocumentBase, SetIfMissingOp, SetOp, StringOp, Transaction, TruncateOp, UnassignOp, UnsetOp, UpsertOp } from "./_chunks-dts/types2.js"; | ||
| import { AnyOp, ArrayOp, AssignOp, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, IncOp, InsertIfMissingOp, InsertOp, Mutation, NodePatch, NodePatchList, NumberOp, ObjectOp, Operation, PatchMutation, PatchOptions, PrimitiveOp, RelativePosition, RemoveOp, ReplaceOp, SanityDocumentBase, SetIfMissingOp, SetOp, StringOp, Transaction, TruncateOp, UnassignOp, UnsetOp, UpsertOp } from "./_chunks-dts/types2.js"; | ||
| import { Insert, SanityCreateIfNotExistsMutation, SanityCreateMutation, SanityCreateOrReplaceMutation, SanityDecPatch, SanityDeleteMutation, SanityDiffMatchPatch, SanityIncPatch, SanityInsertPatch, SanityMutation, SanitySetIfMissingPatch, SanitySetPatch, SanityUnsetPatch } from "./_chunks-dts/types3.js"; | ||
@@ -350,3 +350,3 @@ import { Observable } from "rxjs"; | ||
| declare function createOptimisticStoreMockBackend(backendAPI: MockBackendAPI): OptimisticStoreBackend; | ||
| export { AccessibleDocumentResult, AnyArray, AnyEmptyArray, AnyOp, ArrayOp, AssignOp, ByIndex, Concat, ConcatInner, Conflict, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, Digit, DocEndpointResponse, DocumentIdSetEvent, DocumentIdSetState, DocumentLoader, DocumentMap, DocumentMutationUpdate, DocumentReconnectUpdate, DocumentResult, DocumentSyncUpdate, DocumentUpdate, DocumentUpdateListener, ElementType, Err, FetchDocumentIdsFn, FetchDocuments, FindBy, FindInArray, Get, GetAtPath, IdSetListenFn, InaccessibleDocumentResult, InaccessibleReason, IncOp, Index, InitialEvent, Insert, InsertMethod, InsertOp, KeyedPathElement, ListenerChannelErrorEvent, ListenerDisconnectEvent, ListenerEndpointEvent, ListenerEvent, ListenerMutationEvent, ListenerOptions, ListenerReconnectEvent, ListenerSyncEvent, ListenerWelcomeEvent, MapTuple, Merge, MergeInner, MockBackendAPI, Mutation, MutationGroup, MutationResult, NodePatch, NodePatchList, NonTransactionalMutationGroup, NumberOp, ObjectOp, Ok, OmittedDocument, OnlyDigits, Operation, OptimisticDocumentEvent, OptimisticStore, OptimisticStoreBackend, Optional, ParseAllProps, ParseError, ParseExpressions, ParseInnerExpression, ParseKVPair, ParseNumber, ParseObject, ParseProperty, ParseValue, PatchMutation, PatchOptions, Path, PathElement, PrimitiveOp, PropertyName, QueryParams, ReadOnlyDocumentStore, RelativePosition, RemoteDocumentEvent, RemoteMutationEvent, RemoteSyncEvent, RemoveOp, ReplaceOp, RequestOptions, Result, SafePath, SanityCreateIfNotExistsMutation, SanityCreateMutation, SanityCreateOrReplaceMutation, SanityDecPatch, SanityDeleteMutation, SanityDiffMatchPatch, SanityDocumentBase, SanityIncPatch, SanityInsertPatch, SanityMutation, SanitySetIfMissingPatch, SanitySetPatch, SanityUnsetPatch, SetIfMissingOp, SetOp, SharedListenerListenFn, Split, SplitAll, StringOp, StringToPath, StripError, SubmitResult, ToArray, ToNumber, Transaction, TransactionalMutationGroup, Trim, TrimLeft, TrimRight, TruncateOp, Try, UnassignOp, UnsetOp, Unwrap, UpsertOp, createDocumentEventListener, createDocumentLoader, createDocumentLoaderFromClient, createDocumentUpdateListener, createIdSetListener, createIdSetListenerFromClient, createMockBackendAPI, createOptimisticStore, createOptimisticStoreClientBackend, createOptimisticStoreMockBackend, createReadOnlyStore, createSharedListener, createSharedListenerFromClient, getAtPath, isArrayElement, isElementEqual, isEqual, isIndexElement, isKeyElement, isKeyedElement, isPropertyElement, normalize, parse, startsWith, stringify, toState }; | ||
| export { AccessibleDocumentResult, AnyArray, AnyEmptyArray, AnyOp, ArrayOp, AssignOp, ByIndex, Concat, ConcatInner, Conflict, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, Digit, DocEndpointResponse, DocumentIdSetEvent, DocumentIdSetState, DocumentLoader, DocumentMap, DocumentMutationUpdate, DocumentReconnectUpdate, DocumentResult, DocumentSyncUpdate, DocumentUpdate, DocumentUpdateListener, ElementType, Err, FetchDocumentIdsFn, FetchDocuments, FindBy, FindInArray, Get, GetAtPath, IdSetListenFn, InaccessibleDocumentResult, InaccessibleReason, IncOp, Index, InitialEvent, Insert, InsertIfMissingOp, InsertMethod, InsertOp, KeyedPathElement, ListenerChannelErrorEvent, ListenerDisconnectEvent, ListenerEndpointEvent, ListenerEvent, ListenerMutationEvent, ListenerOptions, ListenerReconnectEvent, ListenerSyncEvent, ListenerWelcomeEvent, MapTuple, Merge, MergeInner, MockBackendAPI, Mutation, MutationGroup, MutationResult, NodePatch, NodePatchList, NonTransactionalMutationGroup, NumberOp, ObjectOp, Ok, OmittedDocument, OnlyDigits, Operation, OptimisticDocumentEvent, OptimisticStore, OptimisticStoreBackend, Optional, ParseAllProps, ParseError, ParseExpressions, ParseInnerExpression, ParseKVPair, ParseNumber, ParseObject, ParseProperty, ParseValue, PatchMutation, PatchOptions, Path, PathElement, PrimitiveOp, PropertyName, QueryParams, ReadOnlyDocumentStore, RelativePosition, RemoteDocumentEvent, RemoteMutationEvent, RemoteSyncEvent, RemoveOp, ReplaceOp, RequestOptions, Result, SafePath, SanityCreateIfNotExistsMutation, SanityCreateMutation, SanityCreateOrReplaceMutation, SanityDecPatch, SanityDeleteMutation, SanityDiffMatchPatch, SanityDocumentBase, SanityIncPatch, SanityInsertPatch, SanityMutation, SanitySetIfMissingPatch, SanitySetPatch, SanityUnsetPatch, SetIfMissingOp, SetOp, SharedListenerListenFn, Split, SplitAll, StringOp, StringToPath, StripError, SubmitResult, ToArray, ToNumber, Transaction, TransactionalMutationGroup, Trim, TrimLeft, TrimRight, TruncateOp, Try, UnassignOp, UnsetOp, Unwrap, UpsertOp, createDocumentEventListener, createDocumentLoader, createDocumentLoaderFromClient, createDocumentUpdateListener, createIdSetListener, createIdSetListenerFromClient, createMockBackendAPI, createOptimisticStore, createOptimisticStoreClientBackend, createOptimisticStoreMockBackend, createReadOnlyStore, createSharedListener, createSharedListenerFromClient, getAtPath, isArrayElement, isElementEqual, isEqual, isIndexElement, isKeyElement, isKeyedElement, isPropertyElement, normalize, parse, startsWith, stringify, toState }; | ||
| //# sourceMappingURL=_unstable_store.d.ts.map |
+37
-10
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: !0 }); | ||
| var parse = require("./_chunks-cjs/parse.cjs"), stringify = require("./_chunks-cjs/stringify.cjs"), arrify = require("./_chunks-cjs/arrify.cjs"), encode$1 = require("./_chunks-cjs/encode.cjs"), isObject = require("./_chunks-cjs/isObject.cjs"); | ||
| var isObject = require("lodash/isObject.js"), parse = require("./_chunks-cjs/parse.cjs"), stringify = require("./_chunks-cjs/stringify.cjs"), arrify = require("./_chunks-cjs/arrify.cjs"), encode$1 = require("./_chunks-cjs/encode.cjs"), isObject$1 = require("./_chunks-cjs/isObject.cjs"); | ||
| function _interopDefaultCompat(e) { | ||
| return e && typeof e == "object" && "default" in e ? e : { default: e }; | ||
| } | ||
| var isObject__default = /* @__PURE__ */ _interopDefaultCompat(isObject); | ||
| function decode(mutations) { | ||
@@ -119,3 +123,3 @@ return mutations.map(decodeMutation); | ||
| if (type === "upsert") { | ||
| const [, , , , [position, referenceItem, items]] = mutation; | ||
| const [, , , , [position, referenceItem, items]] = mutation, decodedReferenceItem = decodeItemRef(referenceItem); | ||
| return { | ||
@@ -130,3 +134,3 @@ type: "patch", | ||
| items, | ||
| referenceItem: decodeItemRef(referenceItem), | ||
| referenceItem: decodedReferenceItem, | ||
| position | ||
@@ -142,3 +146,9 @@ } | ||
| function decodeItemRef(ref) { | ||
| return typeof ref == "string" ? { _key: ref } : ref; | ||
| if (typeof ref == "string") | ||
| return { _key: ref }; | ||
| if (typeof ref == "number") | ||
| return ref; | ||
| if (!hasKey$1(ref)) | ||
| throw new Error("Cannot decode upsert patch: referenceItem is missing key"); | ||
| return ref; | ||
| } | ||
@@ -148,2 +158,5 @@ function createOpts(revisionId) { | ||
| } | ||
| function hasKey$1(item) { | ||
| return isObject__default.default(item) && "_key" in item; | ||
| } | ||
| function encode(mutations) { | ||
@@ -197,2 +210,10 @@ return mutations.flatMap((m) => encodeMutation$1(m)); | ||
| ]; | ||
| if (op.type === "insertIfMissing") | ||
| return [ | ||
| "patch", | ||
| "insertIfMissing", | ||
| id, | ||
| path, | ||
| [op.position, encodeItemRef$1(op.referenceItem), op.items] | ||
| ]; | ||
| if (op.type === "assign") | ||
@@ -316,2 +337,10 @@ return ["patch", "assign", id, path, [op.value]]; | ||
| } | ||
| function insertIfMissing(items, position, referenceItem) { | ||
| return { | ||
| type: "insertIfMissing", | ||
| items: arrify.arrify(items), | ||
| referenceItem, | ||
| position | ||
| }; | ||
| } | ||
| function assertCompatible(formPatchPath) { | ||
@@ -403,3 +432,3 @@ if (formPatchPath.length === 0) | ||
| return [path, `${op.type}(${JSON.stringify(op.keys)})`].join(": "); | ||
| if (op.type === "insert" || op.type === "upsert") | ||
| if (op.type === "insert" || op.type === "upsert" || op.type === "insertIfMissing") | ||
| return [ | ||
@@ -433,3 +462,3 @@ path, | ||
| function hasKey(item) { | ||
| return "_key" in item; | ||
| return isObject$1.isObject(item) && "_key" in item; | ||
| } | ||
@@ -439,9 +468,6 @@ function createEnsureKeys(generateKey) { | ||
| let didModify = !1; | ||
| const withKeys = array.map((item) => needsKey(item) ? (didModify = !0, { ...item, _key: generateKey(item) }) : item); | ||
| const withKeys = array.map((item) => hasKey(item) ? item : (didModify = !0, { ...item, _key: generateKey(item) })); | ||
| return didModify ? withKeys : array; | ||
| }; | ||
| } | ||
| function needsKey(arrayItem) { | ||
| return isObject.isObject(arrayItem) && !hasKey(arrayItem); | ||
| } | ||
| exports.CompactEncoder = index$2; | ||
@@ -467,2 +493,3 @@ exports.CompactFormatter = compact; | ||
| exports.insertBefore = insertBefore; | ||
| exports.insertIfMissing = insertIfMissing; | ||
| exports.patch = patch; | ||
@@ -469,0 +496,0 @@ exports.prepend = prepend; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.cjs","sources":["../src/encoders/compact/decode.ts","../src/encoders/compact/encode.ts","../src/mutations/creators.ts","../src/mutations/operations/creators.ts","../src/encoders/form-compat/encode.ts","../src/formatters/compact.ts","../src/mutations/autoKeys.ts"],"sourcesContent":["import {\n type Mutation,\n type PatchMutation,\n type SanityDocumentBase,\n} from '../../mutations/types'\nimport {type Index, type KeyedPathElement} from '../../path'\nimport {parse as parsePath} from '../../path/parser/parse'\nimport {\n type CompactMutation,\n type CompactPatchMutation,\n type CreateIfNotExistsMutation,\n type CreateMutation,\n type CreateOrReplaceMutation,\n type DeleteMutation,\n type ItemRef,\n} from './types'\n\nexport {Mutation, SanityDocumentBase}\n\nexport function decode<Doc extends SanityDocumentBase>(\n mutations: CompactMutation<Doc>[],\n): Mutation[] {\n return mutations.map(decodeMutation)\n}\n\nexport function decodeMutation<Doc extends SanityDocumentBase>(\n mutation: CompactMutation<Doc>,\n): Mutation {\n const [type] = mutation\n if (type === 'delete') {\n const [, id] = mutation as DeleteMutation\n return {id, type}\n } else if (type === 'create') {\n const [, document] = mutation as CreateMutation<Doc>\n return {type, document}\n } else if (type === 'createIfNotExists') {\n const [, document] = mutation as CreateIfNotExistsMutation<Doc>\n return {type, document}\n } else if (type === 'createOrReplace') {\n const [, document] = mutation as CreateOrReplaceMutation<Doc>\n return {type, document}\n } else if (type === 'patch') {\n return decodePatchMutation(mutation)\n }\n throw new Error(`Unrecognized mutation: ${JSON.stringify(mutation)}`)\n}\n\nfunction decodePatchMutation(mutation: CompactPatchMutation): PatchMutation {\n const [, type, id, serializedPath, , revisionId] = mutation\n\n const path = parsePath(serializedPath)\n if (type === 'dec' || type === 'inc') {\n const [, , , , [amount]] = mutation\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'inc', amount}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'unset') {\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'unset'}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'insert') {\n const [, , , , [position, ref, items]] = mutation\n return {\n type: 'patch',\n id,\n patches: [\n {\n path,\n op: {\n type: 'insert',\n position,\n items,\n referenceItem: typeof ref === 'string' ? {_key: ref} : ref,\n },\n },\n ],\n ...createOpts(revisionId),\n }\n }\n if (type === 'set') {\n const [, , , , [value]] = mutation\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'set', value}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'setIfMissing') {\n const [, , , , [value]] = mutation\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'setIfMissing', value}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'diffMatchPatch') {\n const [, , , , [value]] = mutation\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'diffMatchPatch', value}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'truncate') {\n const [, , , , [startIndex, endIndex]] = mutation\n\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'truncate', startIndex, endIndex}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'assign') {\n const [, , , , [value]] = mutation\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'assign', value}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'replace') {\n const [, , , , [ref, items]] = mutation\n return {\n type: 'patch',\n id,\n patches: [\n {path, op: {type: 'replace', items, referenceItem: decodeItemRef(ref)}},\n ],\n ...createOpts(revisionId),\n }\n }\n if (type === 'upsert') {\n const [, , , , [position, referenceItem, items]] = mutation\n return {\n type: 'patch',\n id,\n patches: [\n {\n path,\n op: {\n type: 'upsert',\n items,\n referenceItem: decodeItemRef(referenceItem),\n position,\n },\n },\n ],\n ...createOpts(revisionId),\n }\n }\n throw new Error(`Invalid mutation type: ${type}`)\n}\n\nfunction decodeItemRef(ref: ItemRef): Index | KeyedPathElement {\n return typeof ref === 'string' ? {_key: ref} : ref\n}\n\nfunction createOpts(revisionId: undefined | string) {\n return revisionId ? {options: {ifRevision: revisionId}} : null\n}\n","// An example of a compact transport/serialization format\nimport {\n type Mutation,\n type NodePatch,\n type SanityDocumentBase,\n} from '../../mutations/types'\nimport {type Index, type KeyedPathElement} from '../../path'\nimport {stringify as stringifyPath} from '../../path/parser/stringify'\nimport {\n type CompactMutation,\n type CompactPatchMutation,\n type ItemRef,\n} from './types'\n\nexport function encode<Doc extends SanityDocumentBase>(\n mutations: Mutation[],\n): CompactMutation<Doc>[] {\n return mutations.flatMap(m => encodeMutation<Doc>(m))\n}\n\nfunction encodeItemRef(ref: Index | KeyedPathElement): ItemRef {\n return typeof ref === 'number' ? ref : ref._key\n}\n\nfunction encodeMutation<Doc extends SanityDocumentBase>(\n mutation: Mutation,\n): CompactMutation<Doc>[] {\n if (\n mutation.type === 'create' ||\n mutation.type === 'createIfNotExists' ||\n mutation.type === 'createOrReplace'\n ) {\n return [[mutation.type, mutation.document]]\n }\n if (mutation.type === 'delete') {\n return [['delete', mutation.id]]\n }\n if (mutation.type === 'patch') {\n return mutation.patches.map(patch =>\n maybeAddRevision(\n mutation.options?.ifRevision,\n encodePatchMutation(mutation.id, patch),\n ),\n )\n }\n\n //@ts-expect-error - all cases are covered\n throw new Error(`Invalid mutation type: ${mutation.type}`)\n}\n\nfunction encodePatchMutation(\n id: string,\n patch: NodePatch<any>,\n): CompactPatchMutation {\n const {op} = patch\n const path = stringifyPath(patch.path)\n if (op.type === 'unset') {\n return ['patch', 'unset', id, path, []]\n }\n if (op.type === 'diffMatchPatch') {\n return ['patch', 'diffMatchPatch', id, path, [op.value]]\n }\n if (op.type === 'inc' || op.type === 'dec') {\n return ['patch', op.type, id, path, [op.amount]]\n }\n if (op.type === 'set') {\n return ['patch', op.type, id, path, [op.value]]\n }\n if (op.type === 'setIfMissing') {\n return ['patch', op.type, id, path, [op.value]]\n }\n if (op.type === 'insert') {\n return [\n 'patch',\n 'insert',\n id,\n path,\n [op.position, encodeItemRef(op.referenceItem), op.items],\n ]\n }\n if (op.type === 'upsert') {\n return [\n 'patch',\n 'upsert',\n id,\n path,\n [op.position, encodeItemRef(op.referenceItem), op.items],\n ]\n }\n if (op.type === 'assign') {\n return ['patch', 'assign', id, path, [op.value]]\n }\n if (op.type === 'unassign') {\n return ['patch', 'assign', id, path, [op.keys]]\n }\n if (op.type === 'replace') {\n return [\n 'patch',\n 'replace',\n id,\n path,\n [encodeItemRef(op.referenceItem), op.items],\n ]\n }\n if (op.type === 'truncate') {\n return ['patch', 'truncate', id, path, [op.startIndex, op.endIndex]]\n }\n if (op.type === 'remove') {\n return ['patch', 'remove', id, path, [encodeItemRef(op.referenceItem)]]\n }\n // @ts-expect-error all cases are covered\n throw new Error(`Invalid operation type: ${op.type}`)\n}\n\nfunction maybeAddRevision<T extends CompactPatchMutation>(\n revision: string | undefined,\n mut: T,\n): T {\n const [mutType, patchType, id, path, args] = mut\n return (revision ? [mutType, patchType, id, path, args, revision] : mut) as T\n}\n","import {parse, type Path, type SafePath} from '../path'\nimport {arrify} from '../utils/arrify'\nimport {\n type NormalizeReadOnlyArray,\n type Optional,\n type Tuplify,\n} from '../utils/typeUtils'\nimport {type Operation} from './operations/types'\nimport {\n type CreateIfNotExistsMutation,\n type CreateMutation,\n type CreateOrReplaceMutation,\n type DeleteMutation,\n type NodePatch,\n type NodePatchList,\n type PatchMutation,\n type PatchOptions,\n type SanityDocumentBase,\n} from './types'\n\nexport function create<Doc extends Optional<SanityDocumentBase, '_id'>>(\n document: Doc,\n): CreateMutation<Doc> {\n return {type: 'create', document}\n}\n\nexport function patch<P extends NodePatchList | NodePatch>(\n id: string,\n patches: P,\n options?: PatchOptions,\n): PatchMutation<NormalizeReadOnlyArray<Tuplify<P>>> {\n return {\n type: 'patch',\n id,\n patches: arrify(patches) as any,\n ...(options ? {options} : {}),\n }\n}\n\nexport function at<const P extends Path, O extends Operation>(\n path: P,\n operation: O,\n): NodePatch<NormalizeReadOnlyArray<P>, O>\n\nexport function at<const P extends string, O extends Operation>(\n path: P,\n operation: O,\n): NodePatch<SafePath<P>, O>\n\nexport function at<O extends Operation>(\n path: Path | string,\n operation: O,\n): NodePatch<Path, O> {\n return {\n path: typeof path === 'string' ? parse(path) : path,\n op: operation,\n }\n}\n\nexport function createIfNotExists<Doc extends SanityDocumentBase>(\n document: Doc,\n): CreateIfNotExistsMutation<Doc> {\n return {type: 'createIfNotExists', document}\n}\n\nexport function createOrReplace<Doc extends SanityDocumentBase>(\n document: Doc,\n): CreateOrReplaceMutation<Doc> {\n return {type: 'createOrReplace', document}\n}\n\nexport function delete_(id: string): DeleteMutation {\n return {type: 'delete', id}\n}\n\nexport const del = delete_\nexport const destroy = delete_\n","import {arrify} from '../../utils/arrify'\nimport {\n type AnyArray,\n type ArrayElement,\n type NormalizeReadOnlyArray,\n} from '../../utils/typeUtils'\nimport {\n type AssignOp,\n type DecOp,\n type DiffMatchPatchOp,\n type IncOp,\n type Index,\n type InsertOp,\n type KeyedPathElement,\n type RelativePosition,\n type RemoveOp,\n type ReplaceOp,\n type SetIfMissingOp,\n type SetOp,\n type TruncateOp,\n type UnassignOp,\n type UnsetOp,\n type UpsertOp,\n} from './types'\n\nexport const set = <const T>(value: T): SetOp<T> => ({type: 'set', value})\n\nexport const assign = <const T extends {[K in string]: unknown}>(\n value: T,\n): AssignOp<T> => ({\n type: 'assign',\n value,\n})\n\nexport const unassign = <const K extends readonly string[]>(\n keys: K,\n): UnassignOp<K> => ({\n type: 'unassign',\n keys,\n})\n\nexport const setIfMissing = <const T>(value: T): SetIfMissingOp<T> => ({\n type: 'setIfMissing',\n value,\n})\n\nexport const unset = (): UnsetOp => ({type: 'unset'})\n\nexport const inc = <const N extends number = 1>(\n amount: N = 1 as N,\n): IncOp<N> => ({\n type: 'inc',\n amount,\n})\n\nexport const dec = <const N extends number = 1>(\n amount: N = 1 as N,\n): DecOp<N> => ({\n type: 'dec',\n amount,\n})\n\nexport const diffMatchPatch = (value: string): DiffMatchPatchOp => ({\n type: 'diffMatchPatch',\n value,\n})\n\nexport function insert<\n const Items extends AnyArray<unknown>,\n const Pos extends RelativePosition,\n const ReferenceItem extends Index | KeyedPathElement,\n>(\n items: Items | ArrayElement<Items>,\n position: Pos,\n indexOrReferenceItem: ReferenceItem,\n): InsertOp<NormalizeReadOnlyArray<Items>, Pos, ReferenceItem> {\n return {\n type: 'insert',\n referenceItem: indexOrReferenceItem,\n position,\n items: arrify(items) as any,\n }\n}\n\nexport function append<const Items extends AnyArray<unknown>>(\n items: Items | ArrayElement<Items>,\n) {\n return insert(items, 'after', -1)\n}\n\nexport function prepend<const Items extends AnyArray<unknown>>(\n items: Items | ArrayElement<Items>,\n) {\n return insert(items, 'before', 0)\n}\n\nexport function insertBefore<\n const Items extends AnyArray<unknown>,\n const ReferenceItem extends Index | KeyedPathElement,\n>(items: Items | ArrayElement<Items>, indexOrReferenceItem: ReferenceItem) {\n return insert(items, 'before', indexOrReferenceItem)\n}\n\nexport const insertAfter = <\n const Items extends AnyArray<unknown>,\n const ReferenceItem extends Index | KeyedPathElement,\n>(\n items: Items | ArrayElement<Items>,\n indexOrReferenceItem: ReferenceItem,\n) => {\n return insert(items, 'after', indexOrReferenceItem)\n}\n\nexport function truncate(startIndex: number, endIndex?: number): TruncateOp {\n return {\n type: 'truncate',\n startIndex,\n endIndex,\n }\n}\n\n/*\n Use this when you know the ref Items already exists\n */\nexport function replace<\n Items extends any[],\n ReferenceItem extends Index | KeyedPathElement,\n>(\n items: Items | ArrayElement<Items>,\n referenceItem: ReferenceItem,\n): ReplaceOp<Items, ReferenceItem> {\n return {\n type: 'replace',\n referenceItem,\n items: arrify(items) as Items,\n }\n}\n\n/*\n Remove an item from an array by either key or index\n */\nexport function remove<ReferenceItem extends Index | KeyedPathElement>(\n referenceItem: ReferenceItem,\n): RemoveOp<ReferenceItem> {\n return {\n type: 'remove',\n referenceItem,\n }\n}\n\n/*\nuse this when the reference Items may or may not exist\n */\nexport function upsert<\n const Items extends AnyArray<unknown>,\n const Pos extends RelativePosition,\n const ReferenceItem extends Index | KeyedPathElement,\n>(\n items: Items | ArrayElement<Items>,\n position: Pos,\n referenceItem: ReferenceItem,\n): UpsertOp<Items, Pos, ReferenceItem> {\n return {\n type: 'upsert',\n items: arrify(items) as Items,\n referenceItem,\n position,\n }\n}\n","import {at} from '../../mutations/creators'\nimport {\n diffMatchPatch,\n insert,\n set,\n setIfMissing,\n unset,\n} from '../../mutations/operations/creators'\nimport {type NodePatch} from '../../mutations/types'\nimport {type KeyedPathElement} from '../../path'\nimport {\n type CompatPath,\n type FormPatchLike,\n type FormPatchPath,\n} from './form-patch-types'\n\nfunction assertCompatible(formPatchPath: FormPatchPath): CompatPath {\n if (formPatchPath.length === 0) {\n return formPatchPath as never[]\n }\n for (const element of formPatchPath) {\n if (Array.isArray(element)) {\n throw new Error('Form patch paths cannot include arrays')\n }\n }\n return formPatchPath as CompatPath\n}\n\n/**\n * Convert a Sanity form patch (ie emitted from an input component) to a {@link NodePatch}\n * Note the lack of encodeMutation here. Sanity forms never emit *mutations*, only patches\n * @param patches - Array of {@link FormPatchLike}\n * @internal\n */\nexport function encodePatches(patches: FormPatchLike[]): NodePatch[] {\n return patches.map(formPatch => {\n const path = assertCompatible(formPatch.path)\n if (formPatch.type === 'unset') {\n return at(path, unset())\n }\n if (formPatch.type === 'set') {\n return at(path, set(formPatch.value))\n }\n if (formPatch.type === 'setIfMissing') {\n return at(path, setIfMissing(formPatch.value))\n }\n if (formPatch.type === 'insert') {\n const arrayPath = path.slice(0, -1)\n const itemRef = formPatch.path[formPatch.path.length - 1]\n return at(\n arrayPath,\n insert(\n formPatch.items,\n formPatch.position,\n itemRef as number | KeyedPathElement,\n ),\n )\n }\n if (formPatch.type === 'diffMatchPatch') {\n return at(path, diffMatchPatch(formPatch.value))\n }\n // @ts-expect-error - should be exhaustive\n throw new Error(`Unknown patch type ${formPatch.type}`)\n })\n}\n","// An example of a compact formatter\n\nimport {\n type Mutation,\n type NodePatch,\n type SanityDocumentBase,\n} from '../mutations/types'\nimport {type Index, type KeyedPathElement, stringify} from '../path'\n\nexport type ItemRef = string | number\n\nexport function format<Doc extends SanityDocumentBase>(\n mutations: Mutation[],\n): string {\n return mutations.flatMap(m => encodeMutation<Doc>(m)).join('\\n')\n}\n\nfunction encodeItemRef(ref: Index | KeyedPathElement): ItemRef {\n return typeof ref === 'number' ? ref : ref._key\n}\n\nfunction encodeMutation<Doc extends SanityDocumentBase>(\n mutation: Mutation,\n): string {\n if (\n mutation.type === 'create' ||\n mutation.type === 'createIfNotExists' ||\n mutation.type === 'createOrReplace'\n ) {\n return [mutation.type, ': ', JSON.stringify(mutation.document)].join('')\n }\n if (mutation.type === 'delete') {\n return ['delete ', mutation.id].join(': ')\n }\n if (mutation.type === 'patch') {\n const ifRevision = mutation.options?.ifRevision\n return [\n 'patch',\n ' ',\n `id=${mutation.id}`,\n ifRevision ? ` (if revision==${ifRevision})` : '',\n ':\\n',\n mutation.patches\n .map(nodePatch => ` ${formatPatchMutation(nodePatch)}`)\n .join('\\n'),\n ].join('')\n }\n\n //@ts-expect-error - all cases are covered\n throw new Error(`Invalid mutation type: ${mutation.type}`)\n}\n\nfunction formatPatchMutation(patch: NodePatch<any>): string {\n const {op} = patch\n const path = stringify(patch.path)\n if (op.type === 'unset') {\n return [path, 'unset()'].join(': ')\n }\n if (op.type === 'diffMatchPatch') {\n return [path, `diffMatchPatch(${op.value})`].join(': ')\n }\n if (op.type === 'inc' || op.type === 'dec') {\n return [path, `${op.type}(${op.amount})`].join(': ')\n }\n if (op.type === 'set' || op.type === 'setIfMissing') {\n return [path, `${op.type}(${JSON.stringify(op.value)})`].join(': ')\n }\n if (op.type === 'assign') {\n return [path, `${op.type}(${JSON.stringify(op.value)})`].join(': ')\n }\n if (op.type === 'unassign') {\n return [path, `${op.type}(${JSON.stringify(op.keys)})`].join(': ')\n }\n if (op.type === 'insert' || op.type === 'upsert') {\n return [\n path,\n `${op.type}(${op.position}, ${encodeItemRef(\n op.referenceItem,\n )}, ${JSON.stringify(op.items)})`,\n ].join(': ')\n }\n if (op.type === 'replace') {\n return [\n path,\n `replace(${encodeItemRef(op.referenceItem)}, ${JSON.stringify(\n op.items,\n )})`,\n ].join(': ')\n }\n if (op.type === 'truncate') {\n return [path, `truncate(${op.startIndex}, ${op.endIndex}`].join(': ')\n }\n if (op.type === 'remove') {\n return [path, `remove(${encodeItemRef(op.referenceItem)})`].join(': ')\n }\n // @ts-expect-error all cases are covered\n throw new Error(`Invalid operation type: ${op.type}`)\n}\n","import {type Index, type KeyedPathElement} from '../path'\nimport {isObject} from '../utils/isObject'\nimport {\n insert as _insert,\n replace as _replace,\n upsert as _upsert,\n} from './operations/creators'\nimport {type RelativePosition} from './operations/types'\n\nexport function autoKeys<Item>(generateKey: (item: Item) => string) {\n const ensureKeys = createEnsureKeys(generateKey)\n\n const insert = <\n Pos extends RelativePosition,\n Ref extends Index | KeyedPathElement,\n >(\n position: Pos,\n referenceItem: Ref,\n items: Item[],\n ) => _insert(ensureKeys(items), position, referenceItem)\n const upsert = <\n Pos extends RelativePosition,\n ReferenceItem extends Index | KeyedPathElement,\n >(\n items: Item[],\n position: Pos,\n referenceItem: ReferenceItem,\n ) => _upsert(ensureKeys(items), position, referenceItem)\n\n const replace = <\n Pos extends RelativePosition,\n ReferenceItem extends Index | KeyedPathElement,\n >(\n items: Item[],\n position: Pos,\n referenceItem: ReferenceItem,\n ) => _replace(ensureKeys(items), referenceItem)\n\n const insertBefore = <Ref extends Index | KeyedPathElement>(\n ref: Ref,\n items: Item[],\n ) => insert('before', ref, items)\n\n const prepend = (items: Item[]) => insertBefore(0, items)\n\n const insertAfter = <Ref extends Index | KeyedPathElement>(\n ref: Ref,\n items: Item[],\n ) => insert('after', ref, items)\n\n const append = (items: Item[]) => insert('after', -1, items)\n\n return {insert, upsert, replace, insertBefore, prepend, insertAfter, append}\n}\n\nfunction hasKey<T extends object>(item: T): item is T & {_key: string} {\n return '_key' in item\n}\n\nfunction createEnsureKeys<T>(generateKey: (item: T) => string) {\n return (array: T[]): T[] => {\n let didModify = false\n const withKeys = array.map(item => {\n if (needsKey(item)) {\n didModify = true\n return {...item, _key: generateKey(item)}\n }\n return item\n })\n return didModify ? withKeys : array\n }\n}\n\nfunction needsKey(arrayItem: any): arrayItem is object {\n return isObject(arrayItem) && !hasKey(arrayItem)\n}\n"],"names":["parsePath","encodeMutation","encodeItemRef","patch","stringifyPath","arrify","parse","stringify","insert","_insert","upsert","_upsert","replace","_replace","insertBefore","isObject"],"mappings":";;;AAmBO,SAAS,OACd,WACY;AACZ,SA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AAU,aAAa,GACjDC,WAAS,CAIb,OACA,UACA,kBACGC,OAAQ,WAAW,KAAK,GAAG,UAAU,aAAa,GAEjDC,YAAU,CAId,OACA,UACA,kBACGC,QAAS,WAAW,KAAK,GAAG,aAAa,GAExCC,gBAAe,CACnB,KACA,UACGN,SAAO,UAAU,KAAK,KAAK;AAWhC,SAAO,UAACA,UAAA,QAAQE,UAAA,SAAQE,WAAS,cAAAE,eAAc,SAT/B,CAAC,UAAkBA,cAAa,GAAG,KAAK,GASA,aAPpC,CAClB,KACA,UACGN,SAAO,SAAS,KAAK,KAAK,GAIsC,QAFtD,CAAC,UAAkBA,SAAO,SAAS,IAAI,KAAK,EAAA;AAG7D;AAEA,SAAS,OAAyB,MAAqC;AACrE,SAAO,UAAU;AACnB;AAEA,SAAS,iBAAoB,aAAkC;AAC7D,SAAO,CAAC,UAAoB;AAC1B,QAAI,YAAY;AAChB,UAAM,WAAW,MAAM,IAAI,CAAA,SACrB,SAAS,IAAI,KACf,YAAY,IACL,EAAC,GAAG,MAAM,MAAM,YAAY,IAAI,EAAA,KAElC,IACR;AACD,WAAO,YAAY,WAAW;AAAA,EAChC;AACF;AAEA,SAAS,SAAS,WAAqC;AACrD,SAAOO,SAAAA,SAAS,SAAS,KAAK,CAAC,OAAO,SAAS;AACjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} | ||
| {"version":3,"file":"index.cjs","sources":["../src/encoders/compact/decode.ts","../src/encoders/compact/encode.ts","../src/mutations/creators.ts","../src/mutations/operations/creators.ts","../src/encoders/form-compat/encode.ts","../src/formatters/compact.ts","../src/mutations/autoKeys.ts"],"sourcesContent":["import {isObject} from 'lodash'\n\nimport {type UpsertOp} from '../../mutations/operations/types'\nimport {\n type Mutation,\n type PatchMutation,\n type SanityDocumentBase,\n} from '../../mutations/types'\nimport {type Index, type KeyedPathElement} from '../../path'\nimport {parse as parsePath} from '../../path/parser/parse'\nimport {\n type CompactMutation,\n type CompactPatchMutation,\n type CreateIfNotExistsMutation,\n type CreateMutation,\n type CreateOrReplaceMutation,\n type DeleteMutation,\n} from './types'\n\nexport {Mutation, SanityDocumentBase}\n\nexport function decode<Doc extends SanityDocumentBase>(\n mutations: CompactMutation<Doc>[],\n): Mutation[] {\n return mutations.map(decodeMutation)\n}\n\nexport function decodeMutation<Doc extends SanityDocumentBase>(\n mutation: CompactMutation<Doc>,\n): Mutation {\n const [type] = mutation\n if (type === 'delete') {\n const [, id] = mutation as DeleteMutation\n return {id, type}\n } else if (type === 'create') {\n const [, document] = mutation as CreateMutation<Doc>\n return {type, document}\n } else if (type === 'createIfNotExists') {\n const [, document] = mutation as CreateIfNotExistsMutation<Doc>\n return {type, document}\n } else if (type === 'createOrReplace') {\n const [, document] = mutation as CreateOrReplaceMutation<Doc>\n return {type, document}\n } else if (type === 'patch') {\n return decodePatchMutation(mutation)\n }\n throw new Error(`Unrecognized mutation: ${JSON.stringify(mutation)}`)\n}\n\nfunction decodePatchMutation(mutation: CompactPatchMutation): PatchMutation {\n const [, type, id, serializedPath, , revisionId] = mutation\n\n const path = parsePath(serializedPath)\n if (type === 'dec' || type === 'inc') {\n const [, , , , [amount]] = mutation\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'inc', amount}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'unset') {\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'unset'}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'insert') {\n const [, , , , [position, ref, items]] = mutation\n return {\n type: 'patch',\n id,\n patches: [\n {\n path,\n op: {\n type: 'insert',\n position,\n items,\n referenceItem: typeof ref === 'string' ? {_key: ref} : ref,\n },\n },\n ],\n ...createOpts(revisionId),\n }\n }\n if (type === 'set') {\n const [, , , , [value]] = mutation\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'set', value}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'setIfMissing') {\n const [, , , , [value]] = mutation\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'setIfMissing', value}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'diffMatchPatch') {\n const [, , , , [value]] = mutation\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'diffMatchPatch', value}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'truncate') {\n const [, , , , [startIndex, endIndex]] = mutation\n\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'truncate', startIndex, endIndex}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'assign') {\n const [, , , , [value]] = mutation\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'assign', value}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'replace') {\n const [, , , , [ref, items]] = mutation\n return {\n type: 'patch',\n id,\n patches: [\n {path, op: {type: 'replace', items, referenceItem: decodeItemRef(ref)}},\n ],\n ...createOpts(revisionId),\n }\n }\n if (type === 'upsert') {\n const [, , , , [position, referenceItem, items]] = mutation\n const decodedReferenceItem = decodeItemRef(referenceItem)\n return {\n type: 'patch',\n id,\n patches: [\n {\n path,\n op: {\n type: 'upsert',\n items,\n referenceItem: decodedReferenceItem,\n position,\n } as UpsertOp<typeof items, typeof position, any>,\n },\n ],\n ...createOpts(revisionId),\n }\n }\n throw new Error(`Invalid mutation type: ${type}`)\n}\n\nfunction decodeItemRef(ref: unknown): Index | KeyedPathElement {\n if (typeof ref === 'string') {\n return {_key: ref}\n }\n if (typeof ref === 'number') {\n return ref\n }\n if (!hasKey(ref)) {\n throw new Error('Cannot decode upsert patch: referenceItem is missing key')\n }\n return ref\n}\n\nfunction createOpts(revisionId: undefined | string) {\n return revisionId ? {options: {ifRevision: revisionId}} : null\n}\n\nfunction hasKey<T>(item: T): item is T & {_key: string} {\n return isObject(item) && '_key' in item\n}\n","// An example of a compact transport/serialization format\nimport {\n type Mutation,\n type NodePatch,\n type SanityDocumentBase,\n} from '../../mutations/types'\nimport {type Index, type KeyedPathElement} from '../../path'\nimport {stringify as stringifyPath} from '../../path/parser/stringify'\nimport {\n type CompactMutation,\n type CompactPatchMutation,\n type ItemRef,\n} from './types'\n\nexport function encode<Doc extends SanityDocumentBase>(\n mutations: Mutation[],\n): CompactMutation<Doc>[] {\n return mutations.flatMap(m => encodeMutation<Doc>(m))\n}\n\nfunction encodeItemRef(ref: Index | KeyedPathElement): ItemRef {\n return typeof ref === 'number' ? ref : ref._key\n}\n\nfunction encodeMutation<Doc extends SanityDocumentBase>(\n mutation: Mutation,\n): CompactMutation<Doc>[] {\n if (\n mutation.type === 'create' ||\n mutation.type === 'createIfNotExists' ||\n mutation.type === 'createOrReplace'\n ) {\n return [[mutation.type, mutation.document]]\n }\n if (mutation.type === 'delete') {\n return [['delete', mutation.id]]\n }\n if (mutation.type === 'patch') {\n return mutation.patches.map(patch =>\n maybeAddRevision(\n mutation.options?.ifRevision,\n encodePatchMutation(mutation.id, patch),\n ),\n )\n }\n\n //@ts-expect-error - all cases are covered\n throw new Error(`Invalid mutation type: ${mutation.type}`)\n}\n\nfunction encodePatchMutation(\n id: string,\n patch: NodePatch<any>,\n): CompactPatchMutation {\n const {op} = patch\n const path = stringifyPath(patch.path)\n if (op.type === 'unset') {\n return ['patch', 'unset', id, path, []]\n }\n if (op.type === 'diffMatchPatch') {\n return ['patch', 'diffMatchPatch', id, path, [op.value]]\n }\n if (op.type === 'inc' || op.type === 'dec') {\n return ['patch', op.type, id, path, [op.amount]]\n }\n if (op.type === 'set') {\n return ['patch', op.type, id, path, [op.value]]\n }\n if (op.type === 'setIfMissing') {\n return ['patch', op.type, id, path, [op.value]]\n }\n if (op.type === 'insert') {\n return [\n 'patch',\n 'insert',\n id,\n path,\n [op.position, encodeItemRef(op.referenceItem), op.items],\n ]\n }\n if (op.type === 'upsert') {\n return [\n 'patch',\n 'upsert',\n id,\n path,\n [op.position, encodeItemRef(op.referenceItem), op.items],\n ]\n }\n if (op.type === 'insertIfMissing') {\n return [\n 'patch',\n 'insertIfMissing',\n id,\n path,\n [op.position, encodeItemRef(op.referenceItem), op.items],\n ]\n }\n if (op.type === 'assign') {\n return ['patch', 'assign', id, path, [op.value]]\n }\n if (op.type === 'unassign') {\n return ['patch', 'assign', id, path, [op.keys]]\n }\n if (op.type === 'replace') {\n return [\n 'patch',\n 'replace',\n id,\n path,\n [encodeItemRef(op.referenceItem), op.items],\n ]\n }\n if (op.type === 'truncate') {\n return ['patch', 'truncate', id, path, [op.startIndex, op.endIndex]]\n }\n if (op.type === 'remove') {\n return ['patch', 'remove', id, path, [encodeItemRef(op.referenceItem)]]\n }\n // @ts-expect-error all cases are covered\n throw new Error(`Invalid operation type: ${op.type}`)\n}\n\nfunction maybeAddRevision<T extends CompactPatchMutation>(\n revision: string | undefined,\n mut: T,\n): T {\n const [mutType, patchType, id, path, args] = mut\n return (revision ? [mutType, patchType, id, path, args, revision] : mut) as T\n}\n","import {parse, type Path, type SafePath} from '../path'\nimport {arrify} from '../utils/arrify'\nimport {\n type NormalizeReadOnlyArray,\n type Optional,\n type Tuplify,\n} from '../utils/typeUtils'\nimport {type Operation} from './operations/types'\nimport {\n type CreateIfNotExistsMutation,\n type CreateMutation,\n type CreateOrReplaceMutation,\n type DeleteMutation,\n type NodePatch,\n type NodePatchList,\n type PatchMutation,\n type PatchOptions,\n type SanityDocumentBase,\n} from './types'\n\nexport function create<Doc extends Optional<SanityDocumentBase, '_id'>>(\n document: Doc,\n): CreateMutation<Doc> {\n return {type: 'create', document}\n}\n\nexport function patch<P extends NodePatchList | NodePatch>(\n id: string,\n patches: P,\n options?: PatchOptions,\n): PatchMutation<NormalizeReadOnlyArray<Tuplify<P>>> {\n return {\n type: 'patch',\n id,\n patches: arrify(patches) as any,\n ...(options ? {options} : {}),\n }\n}\n\nexport function at<const P extends Path, O extends Operation>(\n path: P,\n operation: O,\n): NodePatch<NormalizeReadOnlyArray<P>, O>\n\nexport function at<const P extends string, O extends Operation>(\n path: P,\n operation: O,\n): NodePatch<SafePath<P>, O>\n\nexport function at<O extends Operation>(\n path: Path | string,\n operation: O,\n): NodePatch<Path, O> {\n return {\n path: typeof path === 'string' ? parse(path) : path,\n op: operation,\n }\n}\n\nexport function createIfNotExists<Doc extends SanityDocumentBase>(\n document: Doc,\n): CreateIfNotExistsMutation<Doc> {\n return {type: 'createIfNotExists', document}\n}\n\nexport function createOrReplace<Doc extends SanityDocumentBase>(\n document: Doc,\n): CreateOrReplaceMutation<Doc> {\n return {type: 'createOrReplace', document}\n}\n\nexport function delete_(id: string): DeleteMutation {\n return {type: 'delete', id}\n}\n\nexport const del = delete_\nexport const destroy = delete_\n","import {type Arrify, arrify} from '../../utils/arrify'\nimport {\n type AnyArray,\n type ArrayElement,\n type NormalizeReadOnlyArray,\n} from '../../utils/typeUtils'\nimport {\n type AssignOp,\n type DecOp,\n type DiffMatchPatchOp,\n type IncOp,\n type Index,\n type InsertIfMissingOp,\n type InsertOp,\n type KeyedPathElement,\n type RelativePosition,\n type RemoveOp,\n type ReplaceOp,\n type SetIfMissingOp,\n type SetOp,\n type TruncateOp,\n type UnassignOp,\n type UnsetOp,\n type UpsertOp,\n} from './types'\n\nexport const set = <const T>(value: T): SetOp<T> => ({type: 'set', value})\n\nexport const assign = <const T extends {[K in string]: unknown}>(\n value: T,\n): AssignOp<T> => ({\n type: 'assign',\n value,\n})\n\nexport const unassign = <const K extends readonly string[]>(\n keys: K,\n): UnassignOp<K> => ({\n type: 'unassign',\n keys,\n})\n\nexport const setIfMissing = <const T>(value: T): SetIfMissingOp<T> => ({\n type: 'setIfMissing',\n value,\n})\n\nexport const unset = (): UnsetOp => ({type: 'unset'})\n\nexport const inc = <const N extends number = 1>(\n amount: N = 1 as N,\n): IncOp<N> => ({\n type: 'inc',\n amount,\n})\n\nexport const dec = <const N extends number = 1>(\n amount: N = 1 as N,\n): DecOp<N> => ({\n type: 'dec',\n amount,\n})\n\nexport const diffMatchPatch = (value: string): DiffMatchPatchOp => ({\n type: 'diffMatchPatch',\n value,\n})\n\nexport function insert<\n const Items extends AnyArray<unknown>,\n const Pos extends RelativePosition,\n const ReferenceItem extends Index | KeyedPathElement,\n>(\n items: Items | ArrayElement<Items>,\n position: Pos,\n indexOrReferenceItem: ReferenceItem,\n): InsertOp<NormalizeReadOnlyArray<Items>, Pos, ReferenceItem> {\n return {\n type: 'insert',\n referenceItem: indexOrReferenceItem,\n position,\n items: arrify(items) as any,\n }\n}\n\nexport function append<const Items extends AnyArray<unknown>>(\n items: Items | ArrayElement<Items>,\n) {\n return insert(items, 'after', -1)\n}\n\nexport function prepend<const Items extends AnyArray<unknown>>(\n items: Items | ArrayElement<Items>,\n) {\n return insert(items, 'before', 0)\n}\n\nexport function insertBefore<\n const Items extends AnyArray<unknown>,\n const ReferenceItem extends Index | KeyedPathElement,\n>(items: Items | ArrayElement<Items>, indexOrReferenceItem: ReferenceItem) {\n return insert(items, 'before', indexOrReferenceItem)\n}\n\nexport const insertAfter = <\n const Items extends AnyArray<unknown>,\n const ReferenceItem extends Index | KeyedPathElement,\n>(\n items: Items | ArrayElement<Items>,\n indexOrReferenceItem: ReferenceItem,\n) => {\n return insert(items, 'after', indexOrReferenceItem)\n}\n\nexport function truncate(startIndex: number, endIndex?: number): TruncateOp {\n return {\n type: 'truncate',\n startIndex,\n endIndex,\n }\n}\n\n/*\n Use this when you know the ref Items already exists\n */\nexport function replace<\n Items extends any[],\n ReferenceItem extends Index | KeyedPathElement,\n>(\n items: Items | ArrayElement<Items>,\n referenceItem: ReferenceItem,\n): ReplaceOp<Items, ReferenceItem> {\n return {\n type: 'replace',\n referenceItem,\n items: arrify(items) as Items,\n }\n}\n\n/*\n Remove an item from an array by either key or index\n */\nexport function remove<ReferenceItem extends Index | KeyedPathElement>(\n referenceItem: ReferenceItem,\n): RemoveOp<ReferenceItem> {\n return {\n type: 'remove',\n referenceItem,\n }\n}\n\n/*\nuse this when the reference Items may or may not exist\n */\nexport function upsert<\n const Item extends {_key: string},\n const Pos extends RelativePosition,\n const ReferenceItem extends Index | KeyedPathElement,\n>(\n items: Item | Item[],\n position: Pos,\n referenceItem: ReferenceItem,\n): UpsertOp<Arrify<Item>, Pos, ReferenceItem> {\n return {\n type: 'upsert',\n items: arrify(items) as Arrify<Item>,\n referenceItem,\n position,\n }\n}\n\n/*\nuse this when the reference Items may or may not exist\n */\nexport function insertIfMissing<\n const Item extends {_key: string},\n const Pos extends RelativePosition,\n const ReferenceItem extends Index | KeyedPathElement,\n>(\n items: Item | Item[],\n position: Pos,\n referenceItem: ReferenceItem,\n): InsertIfMissingOp<Arrify<Item>, Pos, ReferenceItem> {\n return {\n type: 'insertIfMissing',\n items: arrify(items) as Arrify<Item>,\n referenceItem,\n position,\n }\n}\n","import {at} from '../../mutations/creators'\nimport {\n diffMatchPatch,\n insert,\n set,\n setIfMissing,\n unset,\n} from '../../mutations/operations/creators'\nimport {type NodePatch} from '../../mutations/types'\nimport {type KeyedPathElement} from '../../path'\nimport {\n type CompatPath,\n type FormPatchLike,\n type FormPatchPath,\n} from './form-patch-types'\n\nfunction assertCompatible(formPatchPath: FormPatchPath): CompatPath {\n if (formPatchPath.length === 0) {\n return formPatchPath as never[]\n }\n for (const element of formPatchPath) {\n if (Array.isArray(element)) {\n throw new Error('Form patch paths cannot include arrays')\n }\n }\n return formPatchPath as CompatPath\n}\n\n/**\n * Convert a Sanity form patch (ie emitted from an input component) to a {@link NodePatch}\n * Note the lack of encodeMutation here. Sanity forms never emit *mutations*, only patches\n * @param patches - Array of {@link FormPatchLike}\n * @internal\n */\nexport function encodePatches(patches: FormPatchLike[]): NodePatch[] {\n return patches.map(formPatch => {\n const path = assertCompatible(formPatch.path)\n if (formPatch.type === 'unset') {\n return at(path, unset())\n }\n if (formPatch.type === 'set') {\n return at(path, set(formPatch.value))\n }\n if (formPatch.type === 'setIfMissing') {\n return at(path, setIfMissing(formPatch.value))\n }\n if (formPatch.type === 'insert') {\n const arrayPath = path.slice(0, -1)\n const itemRef = formPatch.path[formPatch.path.length - 1]\n return at(\n arrayPath,\n insert(\n formPatch.items,\n formPatch.position,\n itemRef as number | KeyedPathElement,\n ),\n )\n }\n if (formPatch.type === 'diffMatchPatch') {\n return at(path, diffMatchPatch(formPatch.value))\n }\n // @ts-expect-error - should be exhaustive\n throw new Error(`Unknown patch type ${formPatch.type}`)\n })\n}\n","// An example of a compact formatter\n\nimport {\n type Mutation,\n type NodePatch,\n type SanityDocumentBase,\n} from '../mutations/types'\nimport {type Index, type KeyedPathElement, stringify} from '../path'\n\nexport type ItemRef = string | number\n\nexport function format<Doc extends SanityDocumentBase>(\n mutations: Mutation[],\n): string {\n return mutations.flatMap(m => encodeMutation<Doc>(m)).join('\\n')\n}\n\nfunction encodeItemRef(ref: Index | KeyedPathElement): ItemRef {\n return typeof ref === 'number' ? ref : ref._key\n}\n\nfunction encodeMutation<Doc extends SanityDocumentBase>(\n mutation: Mutation,\n): string {\n if (\n mutation.type === 'create' ||\n mutation.type === 'createIfNotExists' ||\n mutation.type === 'createOrReplace'\n ) {\n return [mutation.type, ': ', JSON.stringify(mutation.document)].join('')\n }\n if (mutation.type === 'delete') {\n return ['delete ', mutation.id].join(': ')\n }\n if (mutation.type === 'patch') {\n const ifRevision = mutation.options?.ifRevision\n return [\n 'patch',\n ' ',\n `id=${mutation.id}`,\n ifRevision ? ` (if revision==${ifRevision})` : '',\n ':\\n',\n mutation.patches\n .map(nodePatch => ` ${formatPatchMutation(nodePatch)}`)\n .join('\\n'),\n ].join('')\n }\n\n //@ts-expect-error - all cases are covered\n throw new Error(`Invalid mutation type: ${mutation.type}`)\n}\n\nfunction formatPatchMutation(patch: NodePatch<any>): string {\n const {op} = patch\n const path = stringify(patch.path)\n if (op.type === 'unset') {\n return [path, 'unset()'].join(': ')\n }\n if (op.type === 'diffMatchPatch') {\n return [path, `diffMatchPatch(${op.value})`].join(': ')\n }\n if (op.type === 'inc' || op.type === 'dec') {\n return [path, `${op.type}(${op.amount})`].join(': ')\n }\n if (op.type === 'set' || op.type === 'setIfMissing') {\n return [path, `${op.type}(${JSON.stringify(op.value)})`].join(': ')\n }\n if (op.type === 'assign') {\n return [path, `${op.type}(${JSON.stringify(op.value)})`].join(': ')\n }\n if (op.type === 'unassign') {\n return [path, `${op.type}(${JSON.stringify(op.keys)})`].join(': ')\n }\n if (\n op.type === 'insert' ||\n op.type === 'upsert' ||\n op.type === 'insertIfMissing'\n ) {\n return [\n path,\n `${op.type}(${op.position}, ${encodeItemRef(\n op.referenceItem,\n )}, ${JSON.stringify(op.items)})`,\n ].join(': ')\n }\n if (op.type === 'replace') {\n return [\n path,\n `replace(${encodeItemRef(op.referenceItem)}, ${JSON.stringify(\n op.items,\n )})`,\n ].join(': ')\n }\n if (op.type === 'truncate') {\n return [path, `truncate(${op.startIndex}, ${op.endIndex}`].join(': ')\n }\n if (op.type === 'remove') {\n return [path, `remove(${encodeItemRef(op.referenceItem)})`].join(': ')\n }\n // @ts-expect-error all cases are covered\n throw new Error(`Invalid operation type: ${op.type}`)\n}\n","import {type Index, type KeyedPathElement} from '../path'\nimport {isObject} from '../utils/isObject'\nimport {\n insert as _insert,\n replace as _replace,\n upsert as _upsert,\n} from './operations/creators'\nimport {type RelativePosition} from './operations/types'\n\nexport function autoKeys<Item>(generateKey: (item: Item) => string) {\n const ensureKeys = createEnsureKeys(generateKey)\n\n const insert = <\n Pos extends RelativePosition,\n Ref extends Index | KeyedPathElement,\n >(\n position: Pos,\n referenceItem: Ref,\n items: Item[],\n ) => _insert(ensureKeys(items), position, referenceItem)\n\n const upsert = <\n Pos extends RelativePosition,\n ReferenceItem extends KeyedPathElement,\n >(\n items: Item[],\n position: Pos,\n referenceItem: ReferenceItem,\n ) => _upsert(ensureKeys(items), position, referenceItem)\n\n const replace = <\n Pos extends RelativePosition,\n ReferenceItem extends Index | KeyedPathElement,\n >(\n items: Item[],\n position: Pos,\n referenceItem: ReferenceItem,\n ) => _replace(ensureKeys(items), referenceItem)\n\n const insertBefore = <Ref extends Index | KeyedPathElement>(\n ref: Ref,\n items: Item[],\n ) => insert('before', ref, items)\n\n const prepend = (items: Item[]) => insertBefore(0, items)\n\n const insertAfter = <Ref extends Index | KeyedPathElement>(\n ref: Ref,\n items: Item[],\n ) => insert('after', ref, items)\n\n const append = (items: Item[]) => insert('after', -1, items)\n\n return {insert, upsert, replace, insertBefore, prepend, insertAfter, append}\n}\n\nfunction hasKey<T>(item: T): item is T & {_key: string} {\n return isObject(item) && '_key' in item\n}\n\nfunction createEnsureKeys<T>(generateKey: (item: T) => string) {\n return (array: T[]): (T & {_key: string})[] => {\n let didModify = false\n const withKeys = array.map((item): T & {_key: string} => {\n if (!hasKey(item)) {\n didModify = true\n return {...item, _key: generateKey(item)}\n }\n return item\n })\n return didModify ? withKeys : (array as (T & {_key: string})[])\n }\n}\n"],"names":["parsePath","hasKey","isObject","encodeMutation","encodeItemRef","patch","stringifyPath","arrify","parse","stringify","insert","_insert","upsert","_upsert","replace","_replace","insertBefore"],"mappings":";;;;;;;AAqBO,SAAS,OACd,WACY;AACZ,SAAO,UAAU,IAAI,cAAc;AACrC;AAEO,SAAS,eACd,UACU;AACV,QAAM,CAAC,IAAI,IAAI;AACf,MAAI,SAAS,UAAU;AACrB,UAAM,CAAA,EAAG,EAAE,IAAI;AACf,WAAO,EAAC,IAAI,KAAA;AAAA,EACd,WAAW,SAAS,UAAU;AAC5B,UAAM,CAAA,EAAG,QAAQ,IAAI;AACrB,WAAO,EAAC,MAAM,SAAA;AAAA,EAChB,WAAW,SAAS,qBAAqB;AACvC,UAAM,CAAA,EAAG,QAAQ,IAAI;AACrB,WAAO,EAAC,MAAM,SAAA;AAAA,EAChB,WAAW,SAAS,mBAAmB;AACrC,UAAM,CAAA,EAAG,QAAQ,IAAI;AACrB,WAAO,EAAC,MAAM,SAAA;AAAA,EAChB,WAAW,SAAS;AAClB,WAAO,oBAAoB,QAAQ;AAErC,QAAM,IAAI,MAAM,0BAA0B,KAAK,UAAU,QAAQ,CAAC,EAAE;AACtE;AAEA,SAAS,oBAAoB,UAA+C;AAC1E,QAAM,CAAA,EAAG,MAAM,IAAI,gBAAA,EAAkB,UAAU,IAAI,UAE7C,OAAOA,MAAAA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,UACGN,SAAO,UAAU,KAAK,KAAK;AAWhC,SAAO,UAACA,UAAA,QAAQE,UAAA,SAAQE,WAAS,cAAAE,eAAc,SAT/B,CAAC,UAAkBA,cAAa,GAAG,KAAK,GASA,aAPpC,CAClB,KACA,UACGN,SAAO,SAAS,KAAK,KAAK,GAIsC,QAFtD,CAAC,UAAkBA,SAAO,SAAS,IAAI,KAAK,EAAA;AAG7D;AAEA,SAAS,OAAU,MAAqC;AACtD,SAAOR,oBAAS,IAAI,KAAK,UAAU;AACrC;AAEA,SAAS,iBAAoB,aAAkC;AAC7D,SAAO,CAAC,UAAuC;AAC7C,QAAI,YAAY;AAChB,UAAM,WAAW,MAAM,IAAI,CAAC,SACrB,OAAO,IAAI,IAIT,QAHL,YAAY,IACL,EAAC,GAAG,MAAM,MAAM,YAAY,IAAI,IAG1C;AACD,WAAO,YAAY,WAAY;AAAA,EACjC;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} |
+33
-13
| import { AnyArray, AnyEmptyArray, ArrayElement, ByIndex, Concat, ConcatInner, Digit, ElementType, Err, FindBy, FindInArray, Index, KeyedPathElement, Merge, MergeInner, NormalizeReadOnlyArray, Ok, OnlyDigits, Optional, ParseAllProps, ParseError, ParseExpressions, ParseInnerExpression, ParseKVPair, ParseNumber, ParseObject, ParseProperty, ParseValue, Path, PathElement, PropertyName, Result, SafePath, Split, SplitAll, StringToPath, StripError, ToArray, ToNumber, Trim, TrimLeft, TrimRight, Try, Tuplify, Unwrap } from "./_chunks-dts/types.cjs"; | ||
| import { AnyOp, ArrayOp, AssignOp, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, IdentifiedSanityDocument, IncOp, InsertOp, Mutation, NodePatch, NodePatchList, NumberOp, ObjectOp, Operation, PatchMutation, PatchOptions, PrimitiveOp, RelativePosition, RemoveOp, ReplaceOp, SanityDocumentBase, SetIfMissingOp, SetOp, StringOp, Transaction, TruncateOp, UnassignOp, UnsetOp, UpsertOp } from "./_chunks-dts/types2.cjs"; | ||
| import { AnyOp, ArrayOp, AssignOp, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, IdentifiedSanityDocument, IncOp, InsertIfMissingOp, InsertOp, Mutation, NodePatch, NodePatchList, NumberOp, ObjectOp, Operation, PatchMutation, PatchOptions, PrimitiveOp, RelativePosition, RemoveOp, ReplaceOp, SanityDocumentBase, SetIfMissingOp, SetOp, StringOp, Transaction, TruncateOp, UnassignOp, UnsetOp, UpsertOp } from "./_chunks-dts/types2.cjs"; | ||
| import { Insert, InsertAfter, InsertBefore, InsertReplace, PatchMutationOperation, SanityCreateIfNotExistsMutation, SanityCreateMutation, SanityCreateOrReplaceMutation, SanityDecPatch, SanityDeleteMutation, SanityDiffMatchPatch, SanityIncPatch, SanityInsertPatch, SanityMutation, SanityPatch, SanitySetIfMissingPatch, SanitySetPatch, SanityUnsetPatch } from "./_chunks-dts/types3.cjs"; | ||
@@ -27,2 +27,3 @@ declare function decodeAll<Doc extends SanityDocumentBase>(sanityMutations: SanityMutation<Doc>[]): Mutation[]; | ||
| type UpsertMutation = ['patch', 'upsert', Id, CompactPath, [RelativePosition, ItemRef$1, AnyArray], RevisionLock?]; | ||
| type InsertIfMissingMutation = ['patch', 'insertIfMissing', Id, CompactPath, [RelativePosition, ItemRef$1, AnyArray], RevisionLock?]; | ||
| type TruncateMutation = ['patch', 'truncate', Id, CompactPath, [startIndex: number, endIndex: number | undefined], RevisionLock?]; | ||
@@ -38,3 +39,3 @@ type IncMutation = ['patch', 'inc', Id, CompactPath, [number], RevisionLock?]; | ||
| type DiffMatchPatchMutation = ['patch', 'diffMatchPatch', Id, CompactPath, [string], RevisionLock?]; | ||
| type CompactPatchMutation = UnsetMutation | InsertMutation | UpsertMutation | TruncateMutation | IncMutation | DecMutation | SetMutation | SetIfMissingMutation | DiffMatchPatchMutation | AssignMutation | UnassignMutation | ReplaceMutation | RemoveMutation; | ||
| type CompactPatchMutation = UnsetMutation | InsertMutation | UpsertMutation | InsertIfMissingMutation | TruncateMutation | IncMutation | DecMutation | SetMutation | SetIfMissingMutation | DiffMatchPatchMutation | AssignMutation | UnassignMutation | ReplaceMutation | RemoveMutation; | ||
| type CompactMutation<Doc> = DeleteMutation$1 | CreateMutation$1<Doc> | CreateIfNotExistsMutation$1<Doc> | CreateOrReplaceMutation$1<Doc> | CompactPatchMutation; | ||
@@ -44,3 +45,3 @@ declare function decode<Doc extends SanityDocumentBase>(mutations: CompactMutation<Doc>[]): Mutation[]; | ||
| declare namespace index_d_exports { | ||
| export { AssignMutation, CompactMutation, CompactPatchMutation, CompactPath, CreateIfNotExistsMutation$1 as CreateIfNotExistsMutation, CreateMutation$1 as CreateMutation, CreateOrReplaceMutation$1 as CreateOrReplaceMutation, DecMutation, DeleteMutation$1 as DeleteMutation, DiffMatchPatchMutation, Id, IncMutation, InsertMutation, ItemRef$1 as ItemRef, RemoveMutation, ReplaceMutation, RevisionLock, SetIfMissingMutation, SetMutation, TruncateMutation, UnassignMutation, UnsetMutation, UpsertMutation, decode, encode }; | ||
| export { AssignMutation, CompactMutation, CompactPatchMutation, CompactPath, CreateIfNotExistsMutation$1 as CreateIfNotExistsMutation, CreateMutation$1 as CreateMutation, CreateOrReplaceMutation$1 as CreateOrReplaceMutation, DecMutation, DeleteMutation$1 as DeleteMutation, DiffMatchPatchMutation, Id, IncMutation, InsertIfMissingMutation, InsertMutation, ItemRef$1 as ItemRef, RemoveMutation, ReplaceMutation, RevisionLock, SetIfMissingMutation, SetMutation, TruncateMutation, UnassignMutation, UnsetMutation, UpsertMutation, decode, encode }; | ||
| } | ||
@@ -181,9 +182,23 @@ /** | ||
| declare function autoKeys<Item>(generateKey: (item: Item) => string): { | ||
| insert: <Pos extends RelativePosition, Ref extends Index | KeyedPathElement>(position: Pos, referenceItem: Ref, items: Item[]) => InsertOp<Item[], Pos, Ref>; | ||
| upsert: <Pos extends RelativePosition, ReferenceItem extends Index | KeyedPathElement>(items: Item[], position: Pos, referenceItem: ReferenceItem) => UpsertOp<Item[], Pos, ReferenceItem>; | ||
| replace: <Pos extends RelativePosition, ReferenceItem extends Index | KeyedPathElement>(items: Item[], position: Pos, referenceItem: ReferenceItem) => ReplaceOp<Item[], ReferenceItem>; | ||
| insertBefore: <Ref extends Index | KeyedPathElement>(ref: Ref, items: Item[]) => InsertOp<Item[], "before", Ref>; | ||
| prepend: (items: Item[]) => InsertOp<Item[], "before", 0>; | ||
| insertAfter: <Ref extends Index | KeyedPathElement>(ref: Ref, items: Item[]) => InsertOp<Item[], "after", Ref>; | ||
| append: (items: Item[]) => InsertOp<Item[], "after", -1>; | ||
| insert: <Pos extends RelativePosition, Ref extends Index | KeyedPathElement>(position: Pos, referenceItem: Ref, items: Item[]) => InsertOp<(Item & { | ||
| _key: string; | ||
| })[], Pos, Ref>; | ||
| upsert: <Pos extends RelativePosition, ReferenceItem extends KeyedPathElement>(items: Item[], position: Pos, referenceItem: ReferenceItem) => UpsertOp<Arrify<Item & { | ||
| _key: string; | ||
| }>, Pos, ReferenceItem>; | ||
| replace: <Pos extends RelativePosition, ReferenceItem extends Index | KeyedPathElement>(items: Item[], position: Pos, referenceItem: ReferenceItem) => ReplaceOp<(Item & { | ||
| _key: string; | ||
| })[], ReferenceItem>; | ||
| insertBefore: <Ref extends Index | KeyedPathElement>(ref: Ref, items: Item[]) => InsertOp<(Item & { | ||
| _key: string; | ||
| })[], "before", Ref>; | ||
| prepend: (items: Item[]) => InsertOp<(Item & { | ||
| _key: string; | ||
| })[], "before", 0>; | ||
| insertAfter: <Ref extends Index | KeyedPathElement>(ref: Ref, items: Item[]) => InsertOp<(Item & { | ||
| _key: string; | ||
| })[], "after", Ref>; | ||
| append: (items: Item[]) => InsertOp<(Item & { | ||
| _key: string; | ||
| })[], "after", -1>; | ||
| }; | ||
@@ -199,2 +214,3 @@ declare function create<Doc extends Optional<SanityDocumentBase, '_id'>>(document: Doc): CreateMutation<Doc>; | ||
| declare const destroy: typeof delete_; | ||
| type Arrify<T> = (T extends (infer E)[] ? E : T)[]; | ||
| declare const set: <const T>(value: T) => SetOp<T>; | ||
@@ -216,5 +232,9 @@ declare const assign: <const T extends { [K in string]: unknown }>(value: T) => AssignOp<T>; | ||
| declare function remove<ReferenceItem extends Index | KeyedPathElement>(referenceItem: ReferenceItem): RemoveOp<ReferenceItem>; | ||
| declare function upsert<const Items extends AnyArray<unknown>, const Pos extends RelativePosition, const ReferenceItem extends Index | KeyedPathElement>(items: Items | ArrayElement<Items>, position: Pos, referenceItem: ReferenceItem): UpsertOp<Items, Pos, ReferenceItem>; | ||
| type Arrify<T> = (T extends (infer E)[] ? E : T)[]; | ||
| export { type AnyArray, AnyEmptyArray, AnyOp, type ArrayElement, ArrayOp, type Arrify, AssignOp, ByIndex, index_d_exports as CompactEncoder, compact_d_exports as CompactFormatter, Concat, ConcatInner, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, Digit, ElementType, Err, FindBy, FindInArray, index_d_exports$1 as FormCompatEncoder, IdentifiedSanityDocument, IncOp, Index, InsertOp, KeyedPathElement, Merge, MergeInner, type Mutation, NodePatch, NodePatchList, type NormalizeReadOnlyArray, NumberOp, ObjectOp, Ok, OnlyDigits, Operation, type Optional, ParseAllProps, ParseError, ParseExpressions, ParseInnerExpression, ParseKVPair, ParseNumber, ParseObject, ParseProperty, ParseValue, PatchMutation, PatchOptions, Path, PathElement, PrimitiveOp, PropertyName, RelativePosition, RemoveOp, ReplaceOp, Result, SafePath, type SanityDocumentBase, index_d_exports$2 as SanityEncoder, SetIfMissingOp, SetOp, Split, SplitAll, StringOp, StringToPath, StripError, ToArray, ToNumber, Transaction, Trim, TrimLeft, TrimRight, TruncateOp, Try, type Tuplify, UnassignOp, UnsetOp, Unwrap, UpsertOp, append, assign, at, autoKeys, create, createIfNotExists, createOrReplace, dec, del, delete_, destroy, diffMatchPatch, inc, insert, insertAfter, insertBefore, patch, prepend, remove, replace, set, setIfMissing, truncate, unassign, unset, upsert }; | ||
| declare function upsert<const Item extends { | ||
| _key: string; | ||
| }, const Pos extends RelativePosition, const ReferenceItem extends Index | KeyedPathElement>(items: Item | Item[], position: Pos, referenceItem: ReferenceItem): UpsertOp<Arrify<Item>, Pos, ReferenceItem>; | ||
| declare function insertIfMissing<const Item extends { | ||
| _key: string; | ||
| }, const Pos extends RelativePosition, const ReferenceItem extends Index | KeyedPathElement>(items: Item | Item[], position: Pos, referenceItem: ReferenceItem): InsertIfMissingOp<Arrify<Item>, Pos, ReferenceItem>; | ||
| export { type AnyArray, AnyEmptyArray, AnyOp, type ArrayElement, ArrayOp, type Arrify, AssignOp, ByIndex, index_d_exports as CompactEncoder, compact_d_exports as CompactFormatter, Concat, ConcatInner, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, Digit, ElementType, Err, FindBy, FindInArray, index_d_exports$1 as FormCompatEncoder, IdentifiedSanityDocument, IncOp, Index, InsertIfMissingOp, InsertOp, KeyedPathElement, Merge, MergeInner, type Mutation, NodePatch, NodePatchList, type NormalizeReadOnlyArray, NumberOp, ObjectOp, Ok, OnlyDigits, Operation, type Optional, ParseAllProps, ParseError, ParseExpressions, ParseInnerExpression, ParseKVPair, ParseNumber, ParseObject, ParseProperty, ParseValue, PatchMutation, PatchOptions, Path, PathElement, PrimitiveOp, PropertyName, RelativePosition, RemoveOp, ReplaceOp, Result, SafePath, type SanityDocumentBase, index_d_exports$2 as SanityEncoder, SetIfMissingOp, SetOp, Split, SplitAll, StringOp, StringToPath, StripError, ToArray, ToNumber, Transaction, Trim, TrimLeft, TrimRight, TruncateOp, Try, type Tuplify, UnassignOp, UnsetOp, Unwrap, UpsertOp, append, assign, at, autoKeys, create, createIfNotExists, createOrReplace, dec, del, delete_, destroy, diffMatchPatch, inc, insert, insertAfter, insertBefore, insertIfMissing, patch, prepend, remove, replace, set, setIfMissing, truncate, unassign, unset, upsert }; | ||
| //# sourceMappingURL=index.d.cts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.cts","names":[],"sources":["../src/encoders/sanity/decode.ts","../src/encoders/sanity/encode.ts","../src/encoders/sanity/index.ts","../src/encoders/compact/types.ts","../src/encoders/compact/decode.ts","../src/encoders/compact/encode.ts","../src/encoders/compact/index.ts","../src/encoders/form-compat/form-patch-types.ts","../src/encoders/form-compat/encode.ts","../src/encoders/form-compat/index.ts","../src/formatters/compact.ts","../src/mutations/autoKeys.ts","../src/mutations/creators.ts","../src/mutations/operations/creators.ts","../src/utils/arrify.ts"],"sourcesContent":[],"mappings":";;;iBAiGgB,sBAAsB,qCACnB,eAAe,SAAM;iBAKxB,qBAAmB,qCAChB,eAAe,OAAI;iBC9FtB,QAAA,WAAiB,WAAW,mBAAmB;iBAI/C,SAAA,YAAqB,aAAa;iBAIlC,iBAAA,cAA+B;;;;iBAO/B,cAAA,WACJ,WACT,mBAAmB;;;;KExBV,EAAA;KACA,YAAA;KACA,WAAA;KACA,SAAA;KAEA,gBAAA,cAA4B;KAC5B,mCAAiC;KACjC,yDAAuD;KACvD,qDAAmD;KAEnD,aAAA,aHoFI,OAAA,EGjFd,EHiFuB,EGhFvB,WHgFoC,MG9EpC,YH+EsC,CAAA,CAAA;AAKxB,KGlFJ,cAAA,GHkFU,CAAA,OAAA,UAAa,EG/EjC,IACA,WH+EiB,GG9EhB,gBH8EmC,EG9EjB,WAAS,QFhBR,CAAA,EEiBpB,YFjB+B,CAAA;AAA8B,KEoBnD,cAAA,GFpBmD,CAAc,OAAA,EAI7D,QAAA,EEmBd,EFnBuB,EEoBvB,WFpBmC,GEqBlC,gBFrB6D,EEqB3C,SFjBL,EEiBc,QFjBG,GEkB/B;AFXc,KEcJ,gBAAA,GFdkB,CAAA,OAAA,YAClB,EEgBV,IACA,WFhBoB,EAAc,oDEkBlC;KAGU,WAAA,oBAGV,IACA,uBAEA;KAEU,WAAA,oBAGV,IACA,u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CrC,Qb7CqC,Ca6C5B,ab7C4B,CAAA;AAAA,iBauDxB,MbvDwB,CAAA,oBawDlB,QbxDkB,CAAA,OAAA,CAAA,EAAA,kBayDpB,gBbzDoB,EAAA,4Ba0DV,Kb1DU,Ga0DF,gBb1DE,CAAA,CAAA,KAAA,Ea4D/B,Kb5D+B,Ga4DvB,Yb5DuB,Ca4DV,Kb5DU,CAAA,EAAA,QAAA,Ea6D5B,Gb7D4B,EAAA,aAAA,Ea8DvB,ab9DuB,CAAA,Ea+DrC,Qb/DqC,Ca+D5B,Kb/D4B,Ea+DrB,Gb/DqB,Ea+DhB,ab/DgB,CAAA;KclG5B,aAAa,wBAAwB,IAAI"} | ||
| {"version":3,"file":"index.d.cts","names":[],"sources":["../src/encoders/sanity/decode.ts","../src/encoders/sanity/encode.ts","../src/encoders/sanity/index.ts","../src/encoders/compact/types.ts","../src/encoders/compact/decode.ts","../src/encoders/compact/encode.ts","../src/encoders/compact/index.ts","../src/encoders/form-compat/form-patch-types.ts","../src/encoders/form-compat/encode.ts","../src/encoders/form-compat/index.ts","../src/formatters/compact.ts","../src/mutations/autoKeys.ts","../src/mutations/creators.ts","../src/utils/arrify.ts","../src/mutations/operations/creators.ts"],"sourcesContent":[],"mappings":";;;iBAiGgB,sBAAsB,qCACnB,eAAe,SAAM;iBAKxB,qBAAmB,qCAChB,eAAe,OAAI;iBC9FtB,QAAA,WAAiB,WAAW,mBAAmB;iBAI/C,SAAA,YAAqB,aAAa;iBAIlC,iBAAA,cAA+B;;;;iBAO/B,cAAA,WACJ,WACT,mBAAmB;;;;KExBV,EAAA;KACA,YAAA;KACA,WAAA;KACA,SAAA;KAEA,gBAAA,cAA4B;KAC5B,mCAAiC;KACjC,yDAAuD;KACvD,qDAAmD;KAEnD,aAAA,aHoFI,OAAA,EGjFd,EHiFuB,EGhFvB,WHgFoC,MG9EpC,YH+EsC,CAAA,CAAA;AAKxB,KGlFJ,cAAA,GHkFU,CAAA,OAAA,UAAa,EG/EjC,IACA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CvB,ad7CuB,CAAA,Ec8CrC,Qd9CqC,Cc8C5B,ad9C4B,CAAA;AAKxB,iBcmDA,MdnDM,CAAA,mBAAA;EAAA,IAAA,EAAA,MAAA;qBcqDF,gBdrDe,EAAA,4BcsDL,KdtDK,GcsDG,gBdtDH,CAAA,CAAA,KAAA,EcwD1B,IdxD0B,GcwDnB,IdxDmB,EAAA,EAAA,QAAA,EcyDvB,GdzDuB,EAAA,aAAA,Ec0DlB,ad1DkB,CAAA,Ec2DhC,Qd3DgC,Cc2DvB,Md3DuB,Cc2DhB,Id3DgB,CAAA,Ec2DT,Gd3DS,Ec2DJ,ad3DI,CAAA;AACD,iBcsElB,edtEkB,CAAA,mBAAA;MAAf,EAAA,MAAA;qBcwEC,gBdxEkB,EAAA,4BcyER,KdzEQ,GcyEA,gBdzEA,CAAA,CAAA,KAAA,Ec2E7B,Id3E6B,Gc2EtB,Id3EsB,EAAA,EAAA,QAAA,Ec4E1B,Gd5E0B,EAAA,aAAA,Ec6ErB,ad7EqB,CAAA,Ec8EnC,iBd9EmC,Cc8EjB,Md9EiB,Cc8EV,Id9EU,CAAA,Ec8EH,Gd9EG,Ec8EE,ad9EF,CAAA"} |
+33
-13
| import { AnyArray, AnyEmptyArray, ArrayElement, ByIndex, Concat, ConcatInner, Digit, ElementType, Err, FindBy, FindInArray, Index, KeyedPathElement, Merge, MergeInner, NormalizeReadOnlyArray, Ok, OnlyDigits, Optional, ParseAllProps, ParseError, ParseExpressions, ParseInnerExpression, ParseKVPair, ParseNumber, ParseObject, ParseProperty, ParseValue, Path, PathElement, PropertyName, Result, SafePath, Split, SplitAll, StringToPath, StripError, ToArray, ToNumber, Trim, TrimLeft, TrimRight, Try, Tuplify, Unwrap } from "./_chunks-dts/types.js"; | ||
| import { AnyOp, ArrayOp, AssignOp, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, IdentifiedSanityDocument, IncOp, InsertOp, Mutation, NodePatch, NodePatchList, NumberOp, ObjectOp, Operation, PatchMutation, PatchOptions, PrimitiveOp, RelativePosition, RemoveOp, ReplaceOp, SanityDocumentBase, SetIfMissingOp, SetOp, StringOp, Transaction, TruncateOp, UnassignOp, UnsetOp, UpsertOp } from "./_chunks-dts/types2.js"; | ||
| import { AnyOp, ArrayOp, AssignOp, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, IdentifiedSanityDocument, IncOp, InsertIfMissingOp, InsertOp, Mutation, NodePatch, NodePatchList, NumberOp, ObjectOp, Operation, PatchMutation, PatchOptions, PrimitiveOp, RelativePosition, RemoveOp, ReplaceOp, SanityDocumentBase, SetIfMissingOp, SetOp, StringOp, Transaction, TruncateOp, UnassignOp, UnsetOp, UpsertOp } from "./_chunks-dts/types2.js"; | ||
| import { Insert, InsertAfter, InsertBefore, InsertReplace, PatchMutationOperation, SanityCreateIfNotExistsMutation, SanityCreateMutation, SanityCreateOrReplaceMutation, SanityDecPatch, SanityDeleteMutation, SanityDiffMatchPatch, SanityIncPatch, SanityInsertPatch, SanityMutation, SanityPatch, SanitySetIfMissingPatch, SanitySetPatch, SanityUnsetPatch } from "./_chunks-dts/types3.js"; | ||
@@ -27,2 +27,3 @@ declare function decodeAll<Doc extends SanityDocumentBase>(sanityMutations: SanityMutation<Doc>[]): Mutation[]; | ||
| type UpsertMutation = ['patch', 'upsert', Id, CompactPath, [RelativePosition, ItemRef$1, AnyArray], RevisionLock?]; | ||
| type InsertIfMissingMutation = ['patch', 'insertIfMissing', Id, CompactPath, [RelativePosition, ItemRef$1, AnyArray], RevisionLock?]; | ||
| type TruncateMutation = ['patch', 'truncate', Id, CompactPath, [startIndex: number, endIndex: number | undefined], RevisionLock?]; | ||
@@ -38,3 +39,3 @@ type IncMutation = ['patch', 'inc', Id, CompactPath, [number], RevisionLock?]; | ||
| type DiffMatchPatchMutation = ['patch', 'diffMatchPatch', Id, CompactPath, [string], RevisionLock?]; | ||
| type CompactPatchMutation = UnsetMutation | InsertMutation | UpsertMutation | TruncateMutation | IncMutation | DecMutation | SetMutation | SetIfMissingMutation | DiffMatchPatchMutation | AssignMutation | UnassignMutation | ReplaceMutation | RemoveMutation; | ||
| type CompactPatchMutation = UnsetMutation | InsertMutation | UpsertMutation | InsertIfMissingMutation | TruncateMutation | IncMutation | DecMutation | SetMutation | SetIfMissingMutation | DiffMatchPatchMutation | AssignMutation | UnassignMutation | ReplaceMutation | RemoveMutation; | ||
| type CompactMutation<Doc> = DeleteMutation$1 | CreateMutation$1<Doc> | CreateIfNotExistsMutation$1<Doc> | CreateOrReplaceMutation$1<Doc> | CompactPatchMutation; | ||
@@ -44,3 +45,3 @@ declare function decode<Doc extends SanityDocumentBase>(mutations: CompactMutation<Doc>[]): Mutation[]; | ||
| declare namespace index_d_exports { | ||
| export { AssignMutation, CompactMutation, CompactPatchMutation, CompactPath, CreateIfNotExistsMutation$1 as CreateIfNotExistsMutation, CreateMutation$1 as CreateMutation, CreateOrReplaceMutation$1 as CreateOrReplaceMutation, DecMutation, DeleteMutation$1 as DeleteMutation, DiffMatchPatchMutation, Id, IncMutation, InsertMutation, ItemRef$1 as ItemRef, RemoveMutation, ReplaceMutation, RevisionLock, SetIfMissingMutation, SetMutation, TruncateMutation, UnassignMutation, UnsetMutation, UpsertMutation, decode, encode }; | ||
| export { AssignMutation, CompactMutation, CompactPatchMutation, CompactPath, CreateIfNotExistsMutation$1 as CreateIfNotExistsMutation, CreateMutation$1 as CreateMutation, CreateOrReplaceMutation$1 as CreateOrReplaceMutation, DecMutation, DeleteMutation$1 as DeleteMutation, DiffMatchPatchMutation, Id, IncMutation, InsertIfMissingMutation, InsertMutation, ItemRef$1 as ItemRef, RemoveMutation, ReplaceMutation, RevisionLock, SetIfMissingMutation, SetMutation, TruncateMutation, UnassignMutation, UnsetMutation, UpsertMutation, decode, encode }; | ||
| } | ||
@@ -181,9 +182,23 @@ /** | ||
| declare function autoKeys<Item>(generateKey: (item: Item) => string): { | ||
| insert: <Pos extends RelativePosition, Ref extends Index | KeyedPathElement>(position: Pos, referenceItem: Ref, items: Item[]) => InsertOp<Item[], Pos, Ref>; | ||
| upsert: <Pos extends RelativePosition, ReferenceItem extends Index | KeyedPathElement>(items: Item[], position: Pos, referenceItem: ReferenceItem) => UpsertOp<Item[], Pos, ReferenceItem>; | ||
| replace: <Pos extends RelativePosition, ReferenceItem extends Index | KeyedPathElement>(items: Item[], position: Pos, referenceItem: ReferenceItem) => ReplaceOp<Item[], ReferenceItem>; | ||
| insertBefore: <Ref extends Index | KeyedPathElement>(ref: Ref, items: Item[]) => InsertOp<Item[], "before", Ref>; | ||
| prepend: (items: Item[]) => InsertOp<Item[], "before", 0>; | ||
| insertAfter: <Ref extends Index | KeyedPathElement>(ref: Ref, items: Item[]) => InsertOp<Item[], "after", Ref>; | ||
| append: (items: Item[]) => InsertOp<Item[], "after", -1>; | ||
| insert: <Pos extends RelativePosition, Ref extends Index | KeyedPathElement>(position: Pos, referenceItem: Ref, items: Item[]) => InsertOp<(Item & { | ||
| _key: string; | ||
| })[], Pos, Ref>; | ||
| upsert: <Pos extends RelativePosition, ReferenceItem extends KeyedPathElement>(items: Item[], position: Pos, referenceItem: ReferenceItem) => UpsertOp<Arrify<Item & { | ||
| _key: string; | ||
| }>, Pos, ReferenceItem>; | ||
| replace: <Pos extends RelativePosition, ReferenceItem extends Index | KeyedPathElement>(items: Item[], position: Pos, referenceItem: ReferenceItem) => ReplaceOp<(Item & { | ||
| _key: string; | ||
| })[], ReferenceItem>; | ||
| insertBefore: <Ref extends Index | KeyedPathElement>(ref: Ref, items: Item[]) => InsertOp<(Item & { | ||
| _key: string; | ||
| })[], "before", Ref>; | ||
| prepend: (items: Item[]) => InsertOp<(Item & { | ||
| _key: string; | ||
| })[], "before", 0>; | ||
| insertAfter: <Ref extends Index | KeyedPathElement>(ref: Ref, items: Item[]) => InsertOp<(Item & { | ||
| _key: string; | ||
| })[], "after", Ref>; | ||
| append: (items: Item[]) => InsertOp<(Item & { | ||
| _key: string; | ||
| })[], "after", -1>; | ||
| }; | ||
@@ -199,2 +214,3 @@ declare function create<Doc extends Optional<SanityDocumentBase, '_id'>>(document: Doc): CreateMutation<Doc>; | ||
| declare const destroy: typeof delete_; | ||
| type Arrify<T> = (T extends (infer E)[] ? E : T)[]; | ||
| declare const set: <const T>(value: T) => SetOp<T>; | ||
@@ -216,5 +232,9 @@ declare const assign: <const T extends { [K in string]: unknown }>(value: T) => AssignOp<T>; | ||
| declare function remove<ReferenceItem extends Index | KeyedPathElement>(referenceItem: ReferenceItem): RemoveOp<ReferenceItem>; | ||
| declare function upsert<const Items extends AnyArray<unknown>, const Pos extends RelativePosition, const ReferenceItem extends Index | KeyedPathElement>(items: Items | ArrayElement<Items>, position: Pos, referenceItem: ReferenceItem): UpsertOp<Items, Pos, ReferenceItem>; | ||
| type Arrify<T> = (T extends (infer E)[] ? E : T)[]; | ||
| export { type AnyArray, AnyEmptyArray, AnyOp, type ArrayElement, ArrayOp, type Arrify, AssignOp, ByIndex, index_d_exports as CompactEncoder, compact_d_exports as CompactFormatter, Concat, ConcatInner, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, Digit, ElementType, Err, FindBy, FindInArray, index_d_exports$1 as FormCompatEncoder, IdentifiedSanityDocument, IncOp, Index, InsertOp, KeyedPathElement, Merge, MergeInner, type Mutation, NodePatch, NodePatchList, type NormalizeReadOnlyArray, NumberOp, ObjectOp, Ok, OnlyDigits, Operation, type Optional, ParseAllProps, ParseError, ParseExpressions, ParseInnerExpression, ParseKVPair, ParseNumber, ParseObject, ParseProperty, ParseValue, PatchMutation, PatchOptions, Path, PathElement, PrimitiveOp, PropertyName, RelativePosition, RemoveOp, ReplaceOp, Result, SafePath, type SanityDocumentBase, index_d_exports$2 as SanityEncoder, SetIfMissingOp, SetOp, Split, SplitAll, StringOp, StringToPath, StripError, ToArray, ToNumber, Transaction, Trim, TrimLeft, TrimRight, TruncateOp, Try, type Tuplify, UnassignOp, UnsetOp, Unwrap, UpsertOp, append, assign, at, autoKeys, create, createIfNotExists, createOrReplace, dec, del, delete_, destroy, diffMatchPatch, inc, insert, insertAfter, insertBefore, patch, prepend, remove, replace, set, setIfMissing, truncate, unassign, unset, upsert }; | ||
| declare function upsert<const Item extends { | ||
| _key: string; | ||
| }, const Pos extends RelativePosition, const ReferenceItem extends Index | KeyedPathElement>(items: Item | Item[], position: Pos, referenceItem: ReferenceItem): UpsertOp<Arrify<Item>, Pos, ReferenceItem>; | ||
| declare function insertIfMissing<const Item extends { | ||
| _key: string; | ||
| }, const Pos extends RelativePosition, const ReferenceItem extends Index | KeyedPathElement>(items: Item | Item[], position: Pos, referenceItem: ReferenceItem): InsertIfMissingOp<Arrify<Item>, Pos, ReferenceItem>; | ||
| export { type AnyArray, AnyEmptyArray, AnyOp, type ArrayElement, ArrayOp, type Arrify, AssignOp, ByIndex, index_d_exports as CompactEncoder, compact_d_exports as CompactFormatter, Concat, ConcatInner, CreateIfNotExistsMutation, CreateMutation, CreateOrReplaceMutation, DecOp, DeleteMutation, DiffMatchPatchOp, Digit, ElementType, Err, FindBy, FindInArray, index_d_exports$1 as FormCompatEncoder, IdentifiedSanityDocument, IncOp, Index, InsertIfMissingOp, InsertOp, KeyedPathElement, Merge, MergeInner, type Mutation, NodePatch, NodePatchList, type NormalizeReadOnlyArray, NumberOp, ObjectOp, Ok, OnlyDigits, Operation, type Optional, ParseAllProps, ParseError, ParseExpressions, ParseInnerExpression, ParseKVPair, ParseNumber, ParseObject, ParseProperty, ParseValue, PatchMutation, PatchOptions, Path, PathElement, PrimitiveOp, PropertyName, RelativePosition, RemoveOp, ReplaceOp, Result, SafePath, type SanityDocumentBase, index_d_exports$2 as SanityEncoder, SetIfMissingOp, SetOp, Split, SplitAll, StringOp, StringToPath, StripError, ToArray, ToNumber, Transaction, Trim, TrimLeft, TrimRight, TruncateOp, Try, type Tuplify, UnassignOp, UnsetOp, Unwrap, UpsertOp, append, assign, at, autoKeys, create, createIfNotExists, createOrReplace, dec, del, delete_, destroy, diffMatchPatch, inc, insert, insertAfter, insertBefore, insertIfMissing, patch, prepend, remove, replace, set, setIfMissing, truncate, unassign, unset, upsert }; | ||
| //# sourceMappingURL=index.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","names":[],"sources":["../src/encoders/sanity/decode.ts","../src/encoders/sanity/encode.ts","../src/encoders/sanity/index.ts","../src/encoders/compact/types.ts","../src/encoders/compact/decode.ts","../src/encoders/compact/encode.ts","../src/encoders/compact/index.ts","../src/encoders/form-compat/form-patch-types.ts","../src/encoders/form-compat/encode.ts","../src/encoders/form-compat/index.ts","../src/formatters/compact.ts","../src/mutations/autoKeys.ts","../src/mutations/creators.ts","../src/mutations/operations/creators.ts","../src/utils/arrify.ts"],"sourcesContent":[],"mappings":";;;iBAiGgB,sBAAsB,qCACnB,eAAe,SAAM;iBAKxB,qBAAmB,qCAChB,eAAe,OAAI;iBC9FtB,QAAA,WAAiB,WAAW,mBAAmB;iBAI/C,SAAA,YAAqB,aAAa;iBAIlC,iBAAA,cAA+B;;;;iBAO/B,cAAA,WACJ,WACT,mBAAmB;;;;KExBV,EAAA;KACA,YAAA;KACA,WAAA;KACA,SAAA;KAEA,gBAAA,cAA4B;KAC5B,mCAAiC;KACjC,yDAAuD;KACvD,qDAAmD;KAEnD,aAAA,aHoFI,OAAA,EGjFd,EHiFuB,EGhFvB,WHgFoC,MG9EpC,YH+EsC,CAAA,CAAA;AAKxB,KGlFJ,cAAA,GHkFU,CAAA,OAAA,UAAa,EG/EjC,IACA,WH+EiB,GG9EhB,gBH8EmC,EG9EjB,WAAS,QFhBR,CAAA,EEiBpB,YFjB+B,CAAA;AAA8B,KEoBnD,cAAA,GFpBmD,CAAc,OAAA,EAI7D,QAAA,EEmBd,EFnBuB,EEoBvB,WFpBmC,GEqBlC,gBFrB6D,EEqB3C,SFjBL,EEiBc,QFjBG,GEkB/B;AFXc,KEcJ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hCD,CAAA;AAAqB,iBa2CxB,Mb3CwB,CAAA,sBa2CK,Kb3CL,Ga2Ca,gBb3Cb,CAAA,CAAA,aAAA,Ea4CvB,ab5CuB,CAAA,Ea6CrC,Qb7CqC,Ca6C5B,ab7C4B,CAAA;AAAA,iBauDxB,MbvDwB,CAAA,oBawDlB,QbxDkB,CAAA,OAAA,CAAA,EAAA,kBayDpB,gBbzDoB,EAAA,4Ba0DV,Kb1DU,Ga0DF,gBb1DE,CAAA,CAAA,KAAA,Ea4D/B,Kb5D+B,Ga4DvB,Yb5DuB,Ca4DV,Kb5DU,CAAA,EAAA,QAAA,Ea6D5B,Gb7D4B,EAAA,aAAA,Ea8DvB,ab9DuB,CAAA,Ea+DrC,Qb/DqC,Ca+D5B,Kb/D4B,Ea+DrB,Gb/DqB,Ea+DhB,ab/DgB,CAAA;KclG5B,aAAa,wBAAwB,IAAI"} | ||
| {"version":3,"file":"index.d.ts","names":[],"sources":["../src/encoders/sanity/decode.ts","../src/encoders/sanity/encode.ts","../src/encoders/sanity/index.ts","../src/encoders/compact/types.ts","../src/encoders/compact/decode.ts","../src/encoders/compact/encode.ts","../src/encoders/compact/index.ts","../src/encoders/form-compat/form-patch-types.ts","../src/encoders/form-compat/encode.ts","../src/encoders/form-compat/index.ts","../src/formatters/compact.ts","../src/mutations/autoKeys.ts","../src/mutations/creators.ts","../src/utils/arrify.ts","../src/mutations/operations/creators.ts"],"sourcesContent":[],"mappings":";;;iBAiGgB,sBAAsB,qCACnB,eAAe,SAAM;iBAKxB,qBAAmB,qCAChB,eAAe,OAAI;iBC9FtB,QAAA,WAAiB,WAAW,mBAAmB;iBAI/C,SAAA,YAAqB,aAAa;iBAIlC,iBAAA,cAA+B;;;;iBAO/B,cAAA,WACJ,WACT,mBAAmB;;;;KExBV,EAAA;KACA,YAAA;KACA,WAAA;KACA,SAAA;KAEA,gBAAA,cAA4B;KAC5B,mCAAiC;KACjC,yDAAuD;KACvD,qDAAmD;KAEnD,aAAA,aHoFI,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,CciC3B,KdjC2B,EciCpB,adjCoB,CAAA;AAAA,iBc4CxB,Md5CwB,CAAA,sBc4CK,Kd5CL,Gc4Ca,gBd5Cb,CAAA,CAAA,aAAA,Ec6CvB,ad7CuB,CAAA,Ec8CrC,Qd9CqC,Cc8C5B,ad9C4B,CAAA;AAKxB,iBcmDA,MdnDM,CAAA,mBAAA;EAAA,IAAA,EAAA,MAAA;qBcqDF,gBdrDe,EAAA,4BcsDL,KdtDK,GcsDG,gBdtDH,CAAA,CAAA,KAAA,EcwD1B,IdxD0B,GcwDnB,IdxDmB,EAAA,EAAA,QAAA,EcyDvB,GdzDuB,EAAA,aAAA,Ec0DlB,ad1DkB,CAAA,Ec2DhC,Qd3DgC,Cc2DvB,Md3DuB,Cc2DhB,Id3DgB,CAAA,Ec2DT,Gd3DS,Ec2DJ,ad3DI,CAAA;AACD,iBcsElB,edtEkB,CAAA,mBAAA;MAAf,EAAA,MAAA;qBcwEC,gBdxEkB,EAAA,4BcyER,KdzEQ,GcyEA,gBdzEA,CAAA,CAAA,KAAA,Ec2E7B,Id3E6B,Gc2EtB,Id3EsB,EAAA,EAAA,QAAA,Ec4E1B,Gd5E0B,EAAA,aAAA,Ec6ErB,ad7EqB,CAAA,Ec8EnC,iBd9EmC,Cc8EjB,Md9EiB,Cc8EV,Id9EU,CAAA,Ec8EH,Gd9EG,Ec8EE,ad9EF,CAAA"} |
+34
-10
@@ -0,1 +1,2 @@ | ||
| import isObject from "lodash/isObject.js"; | ||
| import { parse } from "./_chunks-es/parse.js"; | ||
@@ -5,3 +6,3 @@ import { stringify } from "./_chunks-es/stringify.js"; | ||
| import { decode as decode$1, decodeAll, encode as encode$1, encodeAll, encodeMutation as encodeMutation$2, encodeTransaction } from "./_chunks-es/encode.js"; | ||
| import { isObject } from "./_chunks-es/isObject.js"; | ||
| import { isObject as isObject$1 } from "./_chunks-es/isObject.js"; | ||
| function decode(mutations) { | ||
@@ -122,3 +123,3 @@ return mutations.map(decodeMutation); | ||
| if (type === "upsert") { | ||
| const [, , , , [position, referenceItem, items]] = mutation; | ||
| const [, , , , [position, referenceItem, items]] = mutation, decodedReferenceItem = decodeItemRef(referenceItem); | ||
| return { | ||
@@ -133,3 +134,3 @@ type: "patch", | ||
| items, | ||
| referenceItem: decodeItemRef(referenceItem), | ||
| referenceItem: decodedReferenceItem, | ||
| position | ||
@@ -145,3 +146,9 @@ } | ||
| function decodeItemRef(ref) { | ||
| return typeof ref == "string" ? { _key: ref } : ref; | ||
| if (typeof ref == "string") | ||
| return { _key: ref }; | ||
| if (typeof ref == "number") | ||
| return ref; | ||
| if (!hasKey$1(ref)) | ||
| throw new Error("Cannot decode upsert patch: referenceItem is missing key"); | ||
| return ref; | ||
| } | ||
@@ -151,2 +158,5 @@ function createOpts(revisionId) { | ||
| } | ||
| function hasKey$1(item) { | ||
| return isObject(item) && "_key" in item; | ||
| } | ||
| function encode(mutations) { | ||
@@ -200,2 +210,10 @@ return mutations.flatMap((m) => encodeMutation$1(m)); | ||
| ]; | ||
| if (op.type === "insertIfMissing") | ||
| return [ | ||
| "patch", | ||
| "insertIfMissing", | ||
| id, | ||
| path, | ||
| [op.position, encodeItemRef$1(op.referenceItem), op.items] | ||
| ]; | ||
| if (op.type === "assign") | ||
@@ -319,2 +337,10 @@ return ["patch", "assign", id, path, [op.value]]; | ||
| } | ||
| function insertIfMissing(items, position, referenceItem) { | ||
| return { | ||
| type: "insertIfMissing", | ||
| items: arrify(items), | ||
| referenceItem, | ||
| position | ||
| }; | ||
| } | ||
| function assertCompatible(formPatchPath) { | ||
@@ -406,3 +432,3 @@ if (formPatchPath.length === 0) | ||
| return [path, `${op.type}(${JSON.stringify(op.keys)})`].join(": "); | ||
| if (op.type === "insert" || op.type === "upsert") | ||
| if (op.type === "insert" || op.type === "upsert" || op.type === "insertIfMissing") | ||
| return [ | ||
@@ -436,3 +462,3 @@ path, | ||
| function hasKey(item) { | ||
| return "_key" in item; | ||
| return isObject$1(item) && "_key" in item; | ||
| } | ||
@@ -442,9 +468,6 @@ function createEnsureKeys(generateKey) { | ||
| let didModify = !1; | ||
| const withKeys = array.map((item) => needsKey(item) ? (didModify = !0, { ...item, _key: generateKey(item) }) : item); | ||
| const withKeys = array.map((item) => hasKey(item) ? item : (didModify = !0, { ...item, _key: generateKey(item) })); | ||
| return didModify ? withKeys : array; | ||
| }; | ||
| } | ||
| function needsKey(arrayItem) { | ||
| return isObject(arrayItem) && !hasKey(arrayItem); | ||
| } | ||
| export { | ||
@@ -471,2 +494,3 @@ index$2 as CompactEncoder, | ||
| insertBefore, | ||
| insertIfMissing, | ||
| patch, | ||
@@ -473,0 +497,0 @@ prepend, |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sources":["../src/encoders/compact/decode.ts","../src/encoders/compact/encode.ts","../src/mutations/creators.ts","../src/mutations/operations/creators.ts","../src/encoders/form-compat/encode.ts","../src/formatters/compact.ts","../src/mutations/autoKeys.ts"],"sourcesContent":["import {\n type Mutation,\n type PatchMutation,\n type SanityDocumentBase,\n} from '../../mutations/types'\nimport {type Index, type KeyedPathElement} from '../../path'\nimport {parse as parsePath} from '../../path/parser/parse'\nimport {\n type CompactMutation,\n type CompactPatchMutation,\n type CreateIfNotExistsMutation,\n type CreateMutation,\n type CreateOrReplaceMutation,\n type DeleteMutation,\n type ItemRef,\n} from './types'\n\nexport {Mutation, SanityDocumentBase}\n\nexport function decode<Doc extends SanityDocumentBase>(\n mutations: CompactMutation<Doc>[],\n): Mutation[] {\n return mutations.map(decodeMutation)\n}\n\nexport function decodeMutation<Doc extends SanityDocumentBase>(\n mutation: CompactMutation<Doc>,\n): Mutation {\n const [type] = mutation\n if (type === 'delete') {\n const [, id] = mutation as DeleteMutation\n return {id, type}\n } else if (type === 'create') {\n const [, document] = mutation as CreateMutation<Doc>\n return {type, document}\n } else if (type === 'createIfNotExists') {\n const [, document] = mutation as CreateIfNotExistsMutation<Doc>\n return {type, document}\n } else if (type === 'createOrReplace') {\n const [, document] = mutation as CreateOrReplaceMutation<Doc>\n return {type, document}\n } else if (type === 'patch') {\n return decodePatchMutation(mutation)\n }\n throw new Error(`Unrecognized mutation: ${JSON.stringify(mutation)}`)\n}\n\nfunction decodePatchMutation(mutation: CompactPatchMutation): PatchMutation {\n const [, type, id, serializedPath, , revisionId] = mutation\n\n const path = parsePath(serializedPath)\n if (type === 'dec' || type === 'inc') {\n const [, , , , [amount]] = mutation\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'inc', amount}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'unset') {\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'unset'}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'insert') {\n const [, , , , [position, ref, items]] = mutation\n return {\n type: 'patch',\n id,\n patches: [\n {\n path,\n op: {\n type: 'insert',\n position,\n items,\n referenceItem: typeof ref === 'string' ? {_key: ref} : ref,\n },\n },\n ],\n ...createOpts(revisionId),\n }\n }\n if (type === 'set') {\n const [, , , , [value]] = mutation\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'set', value}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'setIfMissing') {\n const [, , , , [value]] = mutation\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'setIfMissing', value}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'diffMatchPatch') {\n const [, , , , [value]] = mutation\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'diffMatchPatch', value}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'truncate') {\n const [, , , , [startIndex, endIndex]] = mutation\n\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'truncate', startIndex, endIndex}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'assign') {\n const [, , , , [value]] = mutation\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'assign', value}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'replace') {\n const [, , , , [ref, items]] = mutation\n return {\n type: 'patch',\n id,\n patches: [\n {path, op: {type: 'replace', items, referenceItem: decodeItemRef(ref)}},\n ],\n ...createOpts(revisionId),\n }\n }\n if (type === 'upsert') {\n const [, , , , [position, referenceItem, items]] = mutation\n return {\n type: 'patch',\n id,\n patches: [\n {\n path,\n op: {\n type: 'upsert',\n items,\n referenceItem: decodeItemRef(referenceItem),\n position,\n },\n },\n ],\n ...createOpts(revisionId),\n }\n }\n throw new Error(`Invalid mutation type: ${type}`)\n}\n\nfunction decodeItemRef(ref: ItemRef): Index | KeyedPathElement {\n return typeof ref === 'string' ? {_key: ref} : ref\n}\n\nfunction createOpts(revisionId: undefined | string) {\n return revisionId ? {options: {ifRevision: revisionId}} : null\n}\n","// An example of a compact transport/serialization format\nimport {\n type Mutation,\n type NodePatch,\n type SanityDocumentBase,\n} from '../../mutations/types'\nimport {type Index, type KeyedPathElement} from '../../path'\nimport {stringify as stringifyPath} from '../../path/parser/stringify'\nimport {\n type CompactMutation,\n type CompactPatchMutation,\n type ItemRef,\n} from './types'\n\nexport function encode<Doc extends SanityDocumentBase>(\n mutations: Mutation[],\n): CompactMutation<Doc>[] {\n return mutations.flatMap(m => encodeMutation<Doc>(m))\n}\n\nfunction encodeItemRef(ref: Index | KeyedPathElement): ItemRef {\n return typeof ref === 'number' ? ref : ref._key\n}\n\nfunction encodeMutation<Doc extends SanityDocumentBase>(\n mutation: Mutation,\n): CompactMutation<Doc>[] {\n if (\n mutation.type === 'create' ||\n mutation.type === 'createIfNotExists' ||\n mutation.type === 'createOrReplace'\n ) {\n return [[mutation.type, mutation.document]]\n }\n if (mutation.type === 'delete') {\n return [['delete', mutation.id]]\n }\n if (mutation.type === 'patch') {\n return mutation.patches.map(patch =>\n maybeAddRevision(\n mutation.options?.ifRevision,\n encodePatchMutation(mutation.id, patch),\n ),\n )\n }\n\n //@ts-expect-error - all cases are covered\n throw new Error(`Invalid mutation type: ${mutation.type}`)\n}\n\nfunction encodePatchMutation(\n id: string,\n patch: NodePatch<any>,\n): CompactPatchMutation {\n const {op} = patch\n const path = stringifyPath(patch.path)\n if (op.type === 'unset') {\n return ['patch', 'unset', id, path, []]\n }\n if (op.type === 'diffMatchPatch') {\n return ['patch', 'diffMatchPatch', id, path, [op.value]]\n }\n if (op.type === 'inc' || op.type === 'dec') {\n return ['patch', op.type, id, path, [op.amount]]\n }\n if (op.type === 'set') {\n return ['patch', op.type, id, path, [op.value]]\n }\n if (op.type === 'setIfMissing') {\n return ['patch', op.type, id, path, [op.value]]\n }\n if (op.type === 'insert') {\n return [\n 'patch',\n 'insert',\n id,\n path,\n [op.position, encodeItemRef(op.referenceItem), op.items],\n ]\n }\n if (op.type === 'upsert') {\n return [\n 'patch',\n 'upsert',\n id,\n path,\n [op.position, encodeItemRef(op.referenceItem), op.items],\n ]\n }\n if (op.type === 'assign') {\n return ['patch', 'assign', id, path, [op.value]]\n }\n if (op.type === 'unassign') {\n return ['patch', 'assign', id, path, [op.keys]]\n }\n if (op.type === 'replace') {\n return [\n 'patch',\n 'replace',\n id,\n path,\n [encodeItemRef(op.referenceItem), op.items],\n ]\n }\n if (op.type === 'truncate') {\n return ['patch', 'truncate', id, path, [op.startIndex, op.endIndex]]\n }\n if (op.type === 'remove') {\n return ['patch', 'remove', id, path, [encodeItemRef(op.referenceItem)]]\n }\n // @ts-expect-error all cases are covered\n throw new Error(`Invalid operation type: ${op.type}`)\n}\n\nfunction maybeAddRevision<T extends CompactPatchMutation>(\n revision: string | undefined,\n mut: T,\n): T {\n const [mutType, patchType, id, path, args] = mut\n return (revision ? [mutType, patchType, id, path, args, revision] : mut) as T\n}\n","import {parse, type Path, type SafePath} from '../path'\nimport {arrify} from '../utils/arrify'\nimport {\n type NormalizeReadOnlyArray,\n type Optional,\n type Tuplify,\n} from '../utils/typeUtils'\nimport {type Operation} from './operations/types'\nimport {\n type CreateIfNotExistsMutation,\n type CreateMutation,\n type CreateOrReplaceMutation,\n type DeleteMutation,\n type NodePatch,\n type NodePatchList,\n type PatchMutation,\n type PatchOptions,\n type SanityDocumentBase,\n} from './types'\n\nexport function create<Doc extends Optional<SanityDocumentBase, '_id'>>(\n document: Doc,\n): CreateMutation<Doc> {\n return {type: 'create', document}\n}\n\nexport function patch<P extends NodePatchList | NodePatch>(\n id: string,\n patches: P,\n options?: PatchOptions,\n): PatchMutation<NormalizeReadOnlyArray<Tuplify<P>>> {\n return {\n type: 'patch',\n id,\n patches: arrify(patches) as any,\n ...(options ? {options} : {}),\n }\n}\n\nexport function at<const P extends Path, O extends Operation>(\n path: P,\n operation: O,\n): NodePatch<NormalizeReadOnlyArray<P>, O>\n\nexport function at<const P extends string, O extends Operation>(\n path: P,\n operation: O,\n): NodePatch<SafePath<P>, O>\n\nexport function at<O extends Operation>(\n path: Path | string,\n operation: O,\n): NodePatch<Path, O> {\n return {\n path: typeof path === 'string' ? parse(path) : path,\n op: operation,\n }\n}\n\nexport function createIfNotExists<Doc extends SanityDocumentBase>(\n document: Doc,\n): CreateIfNotExistsMutation<Doc> {\n return {type: 'createIfNotExists', document}\n}\n\nexport function createOrReplace<Doc extends SanityDocumentBase>(\n document: Doc,\n): CreateOrReplaceMutation<Doc> {\n return {type: 'createOrReplace', document}\n}\n\nexport function delete_(id: string): DeleteMutation {\n return {type: 'delete', id}\n}\n\nexport const del = delete_\nexport const destroy = delete_\n","import {arrify} from '../../utils/arrify'\nimport {\n type AnyArray,\n type ArrayElement,\n type NormalizeReadOnlyArray,\n} from '../../utils/typeUtils'\nimport {\n type AssignOp,\n type DecOp,\n type DiffMatchPatchOp,\n type IncOp,\n type Index,\n type InsertOp,\n type KeyedPathElement,\n type RelativePosition,\n type RemoveOp,\n type ReplaceOp,\n type SetIfMissingOp,\n type SetOp,\n type TruncateOp,\n type UnassignOp,\n type UnsetOp,\n type UpsertOp,\n} from './types'\n\nexport const set = <const T>(value: T): SetOp<T> => ({type: 'set', value})\n\nexport const assign = <const T extends {[K in string]: unknown}>(\n value: T,\n): AssignOp<T> => ({\n type: 'assign',\n value,\n})\n\nexport const unassign = <const K extends readonly string[]>(\n keys: K,\n): UnassignOp<K> => ({\n type: 'unassign',\n keys,\n})\n\nexport const setIfMissing = <const T>(value: T): SetIfMissingOp<T> => ({\n type: 'setIfMissing',\n value,\n})\n\nexport const unset = (): UnsetOp => ({type: 'unset'})\n\nexport const inc = <const N extends number = 1>(\n amount: N = 1 as N,\n): IncOp<N> => ({\n type: 'inc',\n amount,\n})\n\nexport const dec = <const N extends number = 1>(\n amount: N = 1 as N,\n): DecOp<N> => ({\n type: 'dec',\n amount,\n})\n\nexport const diffMatchPatch = (value: string): DiffMatchPatchOp => ({\n type: 'diffMatchPatch',\n value,\n})\n\nexport function insert<\n const Items extends AnyArray<unknown>,\n const Pos extends RelativePosition,\n const ReferenceItem extends Index | KeyedPathElement,\n>(\n items: Items | ArrayElement<Items>,\n position: Pos,\n indexOrReferenceItem: ReferenceItem,\n): InsertOp<NormalizeReadOnlyArray<Items>, Pos, ReferenceItem> {\n return {\n type: 'insert',\n referenceItem: indexOrReferenceItem,\n position,\n items: arrify(items) as any,\n }\n}\n\nexport function append<const Items extends AnyArray<unknown>>(\n items: Items | ArrayElement<Items>,\n) {\n return insert(items, 'after', -1)\n}\n\nexport function prepend<const Items extends AnyArray<unknown>>(\n items: Items | ArrayElement<Items>,\n) {\n return insert(items, 'before', 0)\n}\n\nexport function insertBefore<\n const Items extends AnyArray<unknown>,\n const ReferenceItem extends Index | KeyedPathElement,\n>(items: Items | ArrayElement<Items>, indexOrReferenceItem: ReferenceItem) {\n return insert(items, 'before', indexOrReferenceItem)\n}\n\nexport const insertAfter = <\n const Items extends AnyArray<unknown>,\n const ReferenceItem extends Index | KeyedPathElement,\n>(\n items: Items | ArrayElement<Items>,\n indexOrReferenceItem: ReferenceItem,\n) => {\n return insert(items, 'after', indexOrReferenceItem)\n}\n\nexport function truncate(startIndex: number, endIndex?: number): TruncateOp {\n return {\n type: 'truncate',\n startIndex,\n endIndex,\n }\n}\n\n/*\n Use this when you know the ref Items already exists\n */\nexport function replace<\n Items extends any[],\n ReferenceItem extends Index | KeyedPathElement,\n>(\n items: Items | ArrayElement<Items>,\n referenceItem: ReferenceItem,\n): ReplaceOp<Items, ReferenceItem> {\n return {\n type: 'replace',\n referenceItem,\n items: arrify(items) as Items,\n }\n}\n\n/*\n Remove an item from an array by either key or index\n */\nexport function remove<ReferenceItem extends Index | KeyedPathElement>(\n referenceItem: ReferenceItem,\n): RemoveOp<ReferenceItem> {\n return {\n type: 'remove',\n referenceItem,\n }\n}\n\n/*\nuse this when the reference Items may or may not exist\n */\nexport function upsert<\n const Items extends AnyArray<unknown>,\n const Pos extends RelativePosition,\n const ReferenceItem extends Index | KeyedPathElement,\n>(\n items: Items | ArrayElement<Items>,\n position: Pos,\n referenceItem: ReferenceItem,\n): UpsertOp<Items, Pos, ReferenceItem> {\n return {\n type: 'upsert',\n items: arrify(items) as Items,\n referenceItem,\n position,\n }\n}\n","import {at} from '../../mutations/creators'\nimport {\n diffMatchPatch,\n insert,\n set,\n setIfMissing,\n unset,\n} from '../../mutations/operations/creators'\nimport {type NodePatch} from '../../mutations/types'\nimport {type KeyedPathElement} from '../../path'\nimport {\n type CompatPath,\n type FormPatchLike,\n type FormPatchPath,\n} from './form-patch-types'\n\nfunction assertCompatible(formPatchPath: FormPatchPath): CompatPath {\n if (formPatchPath.length === 0) {\n return formPatchPath as never[]\n }\n for (const element of formPatchPath) {\n if (Array.isArray(element)) {\n throw new Error('Form patch paths cannot include arrays')\n }\n }\n return formPatchPath as CompatPath\n}\n\n/**\n * Convert a Sanity form patch (ie emitted from an input component) to a {@link NodePatch}\n * Note the lack of encodeMutation here. Sanity forms never emit *mutations*, only patches\n * @param patches - Array of {@link FormPatchLike}\n * @internal\n */\nexport function encodePatches(patches: FormPatchLike[]): NodePatch[] {\n return patches.map(formPatch => {\n const path = assertCompatible(formPatch.path)\n if (formPatch.type === 'unset') {\n return at(path, unset())\n }\n if (formPatch.type === 'set') {\n return at(path, set(formPatch.value))\n }\n if (formPatch.type === 'setIfMissing') {\n return at(path, setIfMissing(formPatch.value))\n }\n if (formPatch.type === 'insert') {\n const arrayPath = path.slice(0, -1)\n const itemRef = formPatch.path[formPatch.path.length - 1]\n return at(\n arrayPath,\n insert(\n formPatch.items,\n formPatch.position,\n itemRef as number | KeyedPathElement,\n ),\n )\n }\n if (formPatch.type === 'diffMatchPatch') {\n return at(path, diffMatchPatch(formPatch.value))\n }\n // @ts-expect-error - should be exhaustive\n throw new Error(`Unknown patch type ${formPatch.type}`)\n })\n}\n","// An example of a compact formatter\n\nimport {\n type Mutation,\n type NodePatch,\n type SanityDocumentBase,\n} from '../mutations/types'\nimport {type Index, type KeyedPathElement, stringify} from '../path'\n\nexport type ItemRef = string | number\n\nexport function format<Doc extends SanityDocumentBase>(\n mutations: Mutation[],\n): string {\n return mutations.flatMap(m => encodeMutation<Doc>(m)).join('\\n')\n}\n\nfunction encodeItemRef(ref: Index | KeyedPathElement): ItemRef {\n return typeof ref === 'number' ? ref : ref._key\n}\n\nfunction encodeMutation<Doc extends SanityDocumentBase>(\n mutation: Mutation,\n): string {\n if (\n mutation.type === 'create' ||\n mutation.type === 'createIfNotExists' ||\n mutation.type === 'createOrReplace'\n ) {\n return [mutation.type, ': ', JSON.stringify(mutation.document)].join('')\n }\n if (mutation.type === 'delete') {\n return ['delete ', mutation.id].join(': ')\n }\n if (mutation.type === 'patch') {\n const ifRevision = mutation.options?.ifRevision\n return [\n 'patch',\n ' ',\n `id=${mutation.id}`,\n ifRevision ? ` (if revision==${ifRevision})` : '',\n ':\\n',\n mutation.patches\n .map(nodePatch => ` ${formatPatchMutation(nodePatch)}`)\n .join('\\n'),\n ].join('')\n }\n\n //@ts-expect-error - all cases are covered\n throw new Error(`Invalid mutation type: ${mutation.type}`)\n}\n\nfunction formatPatchMutation(patch: NodePatch<any>): string {\n const {op} = patch\n const path = stringify(patch.path)\n if (op.type === 'unset') {\n return [path, 'unset()'].join(': ')\n }\n if (op.type === 'diffMatchPatch') {\n return [path, `diffMatchPatch(${op.value})`].join(': ')\n }\n if (op.type === 'inc' || op.type === 'dec') {\n return [path, `${op.type}(${op.amount})`].join(': ')\n }\n if (op.type === 'set' || op.type === 'setIfMissing') {\n return [path, `${op.type}(${JSON.stringify(op.value)})`].join(': ')\n }\n if (op.type === 'assign') {\n return [path, `${op.type}(${JSON.stringify(op.value)})`].join(': ')\n }\n if (op.type === 'unassign') {\n return [path, `${op.type}(${JSON.stringify(op.keys)})`].join(': ')\n }\n if (op.type === 'insert' || op.type === 'upsert') {\n return [\n path,\n `${op.type}(${op.position}, ${encodeItemRef(\n op.referenceItem,\n )}, ${JSON.stringify(op.items)})`,\n ].join(': ')\n }\n if (op.type === 'replace') {\n return [\n path,\n `replace(${encodeItemRef(op.referenceItem)}, ${JSON.stringify(\n op.items,\n )})`,\n ].join(': ')\n }\n if (op.type === 'truncate') {\n return [path, `truncate(${op.startIndex}, ${op.endIndex}`].join(': ')\n }\n if (op.type === 'remove') {\n return [path, `remove(${encodeItemRef(op.referenceItem)})`].join(': ')\n }\n // @ts-expect-error all cases are covered\n throw new Error(`Invalid operation type: ${op.type}`)\n}\n","import {type Index, type KeyedPathElement} from '../path'\nimport {isObject} from '../utils/isObject'\nimport {\n insert as _insert,\n replace as _replace,\n upsert as _upsert,\n} from './operations/creators'\nimport {type RelativePosition} from './operations/types'\n\nexport function autoKeys<Item>(generateKey: (item: Item) => string) {\n const ensureKeys = createEnsureKeys(generateKey)\n\n const insert = <\n Pos extends RelativePosition,\n Ref extends Index | KeyedPathElement,\n >(\n position: Pos,\n referenceItem: Ref,\n items: Item[],\n ) => _insert(ensureKeys(items), position, referenceItem)\n const upsert = <\n Pos extends RelativePosition,\n ReferenceItem extends Index | KeyedPathElement,\n >(\n items: Item[],\n position: Pos,\n referenceItem: ReferenceItem,\n ) => _upsert(ensureKeys(items), position, referenceItem)\n\n const replace = <\n Pos extends RelativePosition,\n ReferenceItem extends Index | KeyedPathElement,\n >(\n items: Item[],\n position: Pos,\n referenceItem: ReferenceItem,\n ) => _replace(ensureKeys(items), referenceItem)\n\n const insertBefore = <Ref extends Index | KeyedPathElement>(\n ref: Ref,\n items: Item[],\n ) => insert('before', ref, items)\n\n const prepend = (items: Item[]) => insertBefore(0, items)\n\n const insertAfter = <Ref extends Index | KeyedPathElement>(\n ref: Ref,\n items: Item[],\n ) => insert('after', ref, items)\n\n const append = (items: Item[]) => insert('after', -1, items)\n\n return {insert, upsert, replace, insertBefore, prepend, insertAfter, append}\n}\n\nfunction hasKey<T extends object>(item: T): item is T & {_key: string} {\n return '_key' in item\n}\n\nfunction createEnsureKeys<T>(generateKey: (item: T) => string) {\n return (array: T[]): T[] => {\n let didModify = false\n const withKeys = array.map(item => {\n if (needsKey(item)) {\n didModify = true\n return {...item, _key: generateKey(item)}\n }\n return item\n })\n return didModify ? withKeys : array\n }\n}\n\nfunction needsKey(arrayItem: any): arrayItem is object {\n return isObject(arrayItem) && !hasKey(arrayItem)\n}\n"],"names":["parsePath","encodeMutation","encodeItemRef","patch","stringifyPath","insert","_insert","upsert","_upsert","replace","_replace","insertBefore"],"mappings":";;;;;AAmBO,SAAS,OACd,WACY;AACZ,SAAO,UAAU,IAAI,cAAc;AACrC;AAEO,SAAS,eACd,UACU;AACV,QAAM,CAAC,IAAI,IAAI;AACf,MAAI,SAAS,UAAU;AACrB,UAAM,CAAA,EAAG,EAAE,IAAI;AACf,WAAO,EAAC,IAAI,KAAA;AAAA,EACd,WAAW,SAAS,UAAU;AAC5B,UAAM,CAAA,EAAG,QAAQ,IAAI;AACrB,WAAO,EAAC,MAAM,SAAA;AAAA,EAChB,WAAW,SAAS,qBAAqB;AACvC,UAAM,CAAA,EAAG,QAAQ,IAAI;AACrB,WAAO,EAAC,MAAM,SAAA;AAAA,EAChB,WAAW,SAAS,mBAAmB;AACrC,UAAM,CAAA,EAAG,QAAQ,IAAI;AACrB,WAAO,EAAC,MAAM,SAAA;AAAA,EAChB,WAAW,SAAS;AAClB,WAAO,oBAAoB,QAAQ;AAErC,QAAM,IAAI,MAAM,0BAA0B,KAAK,UAAU,Q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AC,GAAG,MAAM,MAAM,YAAY,IAAI,EAAA,KAElC,IACR;AACD,WAAO,YAAY,WAAW;AAAA,EAChC;AACF;AAEA,SAAS,SAAS,WAAqC;AACrD,SAAO,SAAS,SAAS,KAAK,CAAC,OAAO,SAAS;AACjD;"} | ||
| {"version":3,"file":"index.js","sources":["../src/encoders/compact/decode.ts","../src/encoders/compact/encode.ts","../src/mutations/creators.ts","../src/mutations/operations/creators.ts","../src/encoders/form-compat/encode.ts","../src/formatters/compact.ts","../src/mutations/autoKeys.ts"],"sourcesContent":["import {isObject} from 'lodash'\n\nimport {type UpsertOp} from '../../mutations/operations/types'\nimport {\n type Mutation,\n type PatchMutation,\n type SanityDocumentBase,\n} from '../../mutations/types'\nimport {type Index, type KeyedPathElement} from '../../path'\nimport {parse as parsePath} from '../../path/parser/parse'\nimport {\n type CompactMutation,\n type CompactPatchMutation,\n type CreateIfNotExistsMutation,\n type CreateMutation,\n type CreateOrReplaceMutation,\n type DeleteMutation,\n} from './types'\n\nexport {Mutation, SanityDocumentBase}\n\nexport function decode<Doc extends SanityDocumentBase>(\n mutations: CompactMutation<Doc>[],\n): Mutation[] {\n return mutations.map(decodeMutation)\n}\n\nexport function decodeMutation<Doc extends SanityDocumentBase>(\n mutation: CompactMutation<Doc>,\n): Mutation {\n const [type] = mutation\n if (type === 'delete') {\n const [, id] = mutation as DeleteMutation\n return {id, type}\n } else if (type === 'create') {\n const [, document] = mutation as CreateMutation<Doc>\n return {type, document}\n } else if (type === 'createIfNotExists') {\n const [, document] = mutation as CreateIfNotExistsMutation<Doc>\n return {type, document}\n } else if (type === 'createOrReplace') {\n const [, document] = mutation as CreateOrReplaceMutation<Doc>\n return {type, document}\n } else if (type === 'patch') {\n return decodePatchMutation(mutation)\n }\n throw new Error(`Unrecognized mutation: ${JSON.stringify(mutation)}`)\n}\n\nfunction decodePatchMutation(mutation: CompactPatchMutation): PatchMutation {\n const [, type, id, serializedPath, , revisionId] = mutation\n\n const path = parsePath(serializedPath)\n if (type === 'dec' || type === 'inc') {\n const [, , , , [amount]] = mutation\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'inc', amount}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'unset') {\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'unset'}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'insert') {\n const [, , , , [position, ref, items]] = mutation\n return {\n type: 'patch',\n id,\n patches: [\n {\n path,\n op: {\n type: 'insert',\n position,\n items,\n referenceItem: typeof ref === 'string' ? {_key: ref} : ref,\n },\n },\n ],\n ...createOpts(revisionId),\n }\n }\n if (type === 'set') {\n const [, , , , [value]] = mutation\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'set', value}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'setIfMissing') {\n const [, , , , [value]] = mutation\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'setIfMissing', value}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'diffMatchPatch') {\n const [, , , , [value]] = mutation\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'diffMatchPatch', value}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'truncate') {\n const [, , , , [startIndex, endIndex]] = mutation\n\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'truncate', startIndex, endIndex}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'assign') {\n const [, , , , [value]] = mutation\n return {\n type: 'patch',\n id,\n patches: [{path, op: {type: 'assign', value}}],\n ...createOpts(revisionId),\n }\n }\n if (type === 'replace') {\n const [, , , , [ref, items]] = mutation\n return {\n type: 'patch',\n id,\n patches: [\n {path, op: {type: 'replace', items, referenceItem: decodeItemRef(ref)}},\n ],\n ...createOpts(revisionId),\n }\n }\n if (type === 'upsert') {\n const [, , , , [position, referenceItem, items]] = mutation\n const decodedReferenceItem = decodeItemRef(referenceItem)\n return {\n type: 'patch',\n id,\n patches: [\n {\n path,\n op: {\n type: 'upsert',\n items,\n referenceItem: decodedReferenceItem,\n position,\n } as UpsertOp<typeof items, typeof position, any>,\n },\n ],\n ...createOpts(revisionId),\n }\n }\n throw new Error(`Invalid mutation type: ${type}`)\n}\n\nfunction decodeItemRef(ref: unknown): Index | KeyedPathElement {\n if (typeof ref === 'string') {\n return {_key: ref}\n }\n if (typeof ref === 'number') {\n return ref\n }\n if (!hasKey(ref)) {\n throw new Error('Cannot decode upsert patch: referenceItem is missing key')\n }\n return ref\n}\n\nfunction createOpts(revisionId: undefined | string) {\n return revisionId ? {options: {ifRevision: revisionId}} : null\n}\n\nfunction hasKey<T>(item: T): item is T & {_key: string} {\n return isObject(item) && '_key' in item\n}\n","// An example of a compact transport/serialization format\nimport {\n type Mutation,\n type NodePatch,\n type SanityDocumentBase,\n} from '../../mutations/types'\nimport {type Index, type KeyedPathElement} from '../../path'\nimport {stringify as stringifyPath} from '../../path/parser/stringify'\nimport {\n type CompactMutation,\n type CompactPatchMutation,\n type ItemRef,\n} from './types'\n\nexport function encode<Doc extends SanityDocumentBase>(\n mutations: Mutation[],\n): CompactMutation<Doc>[] {\n return mutations.flatMap(m => encodeMutation<Doc>(m))\n}\n\nfunction encodeItemRef(ref: Index | KeyedPathElement): ItemRef {\n return typeof ref === 'number' ? ref : ref._key\n}\n\nfunction encodeMutation<Doc extends SanityDocumentBase>(\n mutation: Mutation,\n): CompactMutation<Doc>[] {\n if (\n mutation.type === 'create' ||\n mutation.type === 'createIfNotExists' ||\n mutation.type === 'createOrReplace'\n ) {\n return [[mutation.type, mutation.document]]\n }\n if (mutation.type === 'delete') {\n return [['delete', mutation.id]]\n }\n if (mutation.type === 'patch') {\n return mutation.patches.map(patch =>\n maybeAddRevision(\n mutation.options?.ifRevision,\n encodePatchMutation(mutation.id, patch),\n ),\n )\n }\n\n //@ts-expect-error - all cases are covered\n throw new Error(`Invalid mutation type: ${mutation.type}`)\n}\n\nfunction encodePatchMutation(\n id: string,\n patch: NodePatch<any>,\n): CompactPatchMutation {\n const {op} = patch\n const path = stringifyPath(patch.path)\n if (op.type === 'unset') {\n return ['patch', 'unset', id, path, []]\n }\n if (op.type === 'diffMatchPatch') {\n return ['patch', 'diffMatchPatch', id, path, [op.value]]\n }\n if (op.type === 'inc' || op.type === 'dec') {\n return ['patch', op.type, id, path, [op.amount]]\n }\n if (op.type === 'set') {\n return ['patch', op.type, id, path, [op.value]]\n }\n if (op.type === 'setIfMissing') {\n return ['patch', op.type, id, path, [op.value]]\n }\n if (op.type === 'insert') {\n return [\n 'patch',\n 'insert',\n id,\n path,\n [op.position, encodeItemRef(op.referenceItem), op.items],\n ]\n }\n if (op.type === 'upsert') {\n return [\n 'patch',\n 'upsert',\n id,\n path,\n [op.position, encodeItemRef(op.referenceItem), op.items],\n ]\n }\n if (op.type === 'insertIfMissing') {\n return [\n 'patch',\n 'insertIfMissing',\n id,\n path,\n [op.position, encodeItemRef(op.referenceItem), op.items],\n ]\n }\n if (op.type === 'assign') {\n return ['patch', 'assign', id, path, [op.value]]\n }\n if (op.type === 'unassign') {\n return ['patch', 'assign', id, path, [op.keys]]\n }\n if (op.type === 'replace') {\n return [\n 'patch',\n 'replace',\n id,\n path,\n [encodeItemRef(op.referenceItem), op.items],\n ]\n }\n if (op.type === 'truncate') {\n return ['patch', 'truncate', id, path, [op.startIndex, op.endIndex]]\n }\n if (op.type === 'remove') {\n return ['patch', 'remove', id, path, [encodeItemRef(op.referenceItem)]]\n }\n // @ts-expect-error all cases are covered\n throw new Error(`Invalid operation type: ${op.type}`)\n}\n\nfunction maybeAddRevision<T extends CompactPatchMutation>(\n revision: string | undefined,\n mut: T,\n): T {\n const [mutType, patchType, id, path, args] = mut\n return (revision ? [mutType, patchType, id, path, args, revision] : mut) as T\n}\n","import {parse, type Path, type SafePath} from '../path'\nimport {arrify} from '../utils/arrify'\nimport {\n type NormalizeReadOnlyArray,\n type Optional,\n type Tuplify,\n} from '../utils/typeUtils'\nimport {type Operation} from './operations/types'\nimport {\n type CreateIfNotExistsMutation,\n type CreateMutation,\n type CreateOrReplaceMutation,\n type DeleteMutation,\n type NodePatch,\n type NodePatchList,\n type PatchMutation,\n type PatchOptions,\n type SanityDocumentBase,\n} from './types'\n\nexport function create<Doc extends Optional<SanityDocumentBase, '_id'>>(\n document: Doc,\n): CreateMutation<Doc> {\n return {type: 'create', document}\n}\n\nexport function patch<P extends NodePatchList | NodePatch>(\n id: string,\n patches: P,\n options?: PatchOptions,\n): PatchMutation<NormalizeReadOnlyArray<Tuplify<P>>> {\n return {\n type: 'patch',\n id,\n patches: arrify(patches) as any,\n ...(options ? {options} : {}),\n }\n}\n\nexport function at<const P extends Path, O extends Operation>(\n path: P,\n operation: O,\n): NodePatch<NormalizeReadOnlyArray<P>, O>\n\nexport function at<const P extends string, O extends Operation>(\n path: P,\n operation: O,\n): NodePatch<SafePath<P>, O>\n\nexport function at<O extends Operation>(\n path: Path | string,\n operation: O,\n): NodePatch<Path, O> {\n return {\n path: typeof path === 'string' ? parse(path) : path,\n op: operation,\n }\n}\n\nexport function createIfNotExists<Doc extends SanityDocumentBase>(\n document: Doc,\n): CreateIfNotExistsMutation<Doc> {\n return {type: 'createIfNotExists', document}\n}\n\nexport function createOrReplace<Doc extends SanityDocumentBase>(\n document: Doc,\n): CreateOrReplaceMutation<Doc> {\n return {type: 'createOrReplace', document}\n}\n\nexport function delete_(id: string): DeleteMutation {\n return {type: 'delete', id}\n}\n\nexport const del = delete_\nexport const destroy = delete_\n","import {type Arrify, arrify} from '../../utils/arrify'\nimport {\n type AnyArray,\n type ArrayElement,\n type NormalizeReadOnlyArray,\n} from '../../utils/typeUtils'\nimport {\n type AssignOp,\n type DecOp,\n type DiffMatchPatchOp,\n type IncOp,\n type Index,\n type InsertIfMissingOp,\n type InsertOp,\n type KeyedPathElement,\n type RelativePosition,\n type RemoveOp,\n type ReplaceOp,\n type SetIfMissingOp,\n type SetOp,\n type TruncateOp,\n type UnassignOp,\n type UnsetOp,\n type UpsertOp,\n} from './types'\n\nexport const set = <const T>(value: T): SetOp<T> => ({type: 'set', value})\n\nexport const assign = <const T extends {[K in string]: unknown}>(\n value: T,\n): AssignOp<T> => ({\n type: 'assign',\n value,\n})\n\nexport const unassign = <const K extends readonly string[]>(\n keys: K,\n): UnassignOp<K> => ({\n type: 'unassign',\n keys,\n})\n\nexport const setIfMissing = <const T>(value: T): SetIfMissingOp<T> => ({\n type: 'setIfMissing',\n value,\n})\n\nexport const unset = (): UnsetOp => ({type: 'unset'})\n\nexport const inc = <const N extends number = 1>(\n amount: N = 1 as N,\n): IncOp<N> => ({\n type: 'inc',\n amount,\n})\n\nexport const dec = <const N extends number = 1>(\n amount: N = 1 as N,\n): DecOp<N> => ({\n type: 'dec',\n amount,\n})\n\nexport const diffMatchPatch = (value: string): DiffMatchPatchOp => ({\n type: 'diffMatchPatch',\n value,\n})\n\nexport function insert<\n const Items extends AnyArray<unknown>,\n const Pos extends RelativePosition,\n const ReferenceItem extends Index | KeyedPathElement,\n>(\n items: Items | ArrayElement<Items>,\n position: Pos,\n indexOrReferenceItem: ReferenceItem,\n): InsertOp<NormalizeReadOnlyArray<Items>, Pos, ReferenceItem> {\n return {\n type: 'insert',\n referenceItem: indexOrReferenceItem,\n position,\n items: arrify(items) as any,\n }\n}\n\nexport function append<const Items extends AnyArray<unknown>>(\n items: Items | ArrayElement<Items>,\n) {\n return insert(items, 'after', -1)\n}\n\nexport function prepend<const Items extends AnyArray<unknown>>(\n items: Items | ArrayElement<Items>,\n) {\n return insert(items, 'before', 0)\n}\n\nexport function insertBefore<\n const Items extends AnyArray<unknown>,\n const ReferenceItem extends Index | KeyedPathElement,\n>(items: Items | ArrayElement<Items>, indexOrReferenceItem: ReferenceItem) {\n return insert(items, 'before', indexOrReferenceItem)\n}\n\nexport const insertAfter = <\n const Items extends AnyArray<unknown>,\n const ReferenceItem extends Index | KeyedPathElement,\n>(\n items: Items | ArrayElement<Items>,\n indexOrReferenceItem: ReferenceItem,\n) => {\n return insert(items, 'after', indexOrReferenceItem)\n}\n\nexport function truncate(startIndex: number, endIndex?: number): TruncateOp {\n return {\n type: 'truncate',\n startIndex,\n endIndex,\n }\n}\n\n/*\n Use this when you know the ref Items already exists\n */\nexport function replace<\n Items extends any[],\n ReferenceItem extends Index | KeyedPathElement,\n>(\n items: Items | ArrayElement<Items>,\n referenceItem: ReferenceItem,\n): ReplaceOp<Items, ReferenceItem> {\n return {\n type: 'replace',\n referenceItem,\n items: arrify(items) as Items,\n }\n}\n\n/*\n Remove an item from an array by either key or index\n */\nexport function remove<ReferenceItem extends Index | KeyedPathElement>(\n referenceItem: ReferenceItem,\n): RemoveOp<ReferenceItem> {\n return {\n type: 'remove',\n referenceItem,\n }\n}\n\n/*\nuse this when the reference Items may or may not exist\n */\nexport function upsert<\n const Item extends {_key: string},\n const Pos extends RelativePosition,\n const ReferenceItem extends Index | KeyedPathElement,\n>(\n items: Item | Item[],\n position: Pos,\n referenceItem: ReferenceItem,\n): UpsertOp<Arrify<Item>, Pos, ReferenceItem> {\n return {\n type: 'upsert',\n items: arrify(items) as Arrify<Item>,\n referenceItem,\n position,\n }\n}\n\n/*\nuse this when the reference Items may or may not exist\n */\nexport function insertIfMissing<\n const Item extends {_key: string},\n const Pos extends RelativePosition,\n const ReferenceItem extends Index | KeyedPathElement,\n>(\n items: Item | Item[],\n position: Pos,\n referenceItem: ReferenceItem,\n): InsertIfMissingOp<Arrify<Item>, Pos, ReferenceItem> {\n return {\n type: 'insertIfMissing',\n items: arrify(items) as Arrify<Item>,\n referenceItem,\n position,\n }\n}\n","import {at} from '../../mutations/creators'\nimport {\n diffMatchPatch,\n insert,\n set,\n setIfMissing,\n unset,\n} from '../../mutations/operations/creators'\nimport {type NodePatch} from '../../mutations/types'\nimport {type KeyedPathElement} from '../../path'\nimport {\n type CompatPath,\n type FormPatchLike,\n type FormPatchPath,\n} from './form-patch-types'\n\nfunction assertCompatible(formPatchPath: FormPatchPath): CompatPath {\n if (formPatchPath.length === 0) {\n return formPatchPath as never[]\n }\n for (const element of formPatchPath) {\n if (Array.isArray(element)) {\n throw new Error('Form patch paths cannot include arrays')\n }\n }\n return formPatchPath as CompatPath\n}\n\n/**\n * Convert a Sanity form patch (ie emitted from an input component) to a {@link NodePatch}\n * Note the lack of encodeMutation here. Sanity forms never emit *mutations*, only patches\n * @param patches - Array of {@link FormPatchLike}\n * @internal\n */\nexport function encodePatches(patches: FormPatchLike[]): NodePatch[] {\n return patches.map(formPatch => {\n const path = assertCompatible(formPatch.path)\n if (formPatch.type === 'unset') {\n return at(path, unset())\n }\n if (formPatch.type === 'set') {\n return at(path, set(formPatch.value))\n }\n if (formPatch.type === 'setIfMissing') {\n return at(path, setIfMissing(formPatch.value))\n }\n if (formPatch.type === 'insert') {\n const arrayPath = path.slice(0, -1)\n const itemRef = formPatch.path[formPatch.path.length - 1]\n return at(\n arrayPath,\n insert(\n formPatch.items,\n formPatch.position,\n itemRef as number | KeyedPathElement,\n ),\n )\n }\n if (formPatch.type === 'diffMatchPatch') {\n return at(path, diffMatchPatch(formPatch.value))\n }\n // @ts-expect-error - should be exhaustive\n throw new Error(`Unknown patch type ${formPatch.type}`)\n })\n}\n","// An example of a compact formatter\n\nimport {\n type Mutation,\n type NodePatch,\n type SanityDocumentBase,\n} from '../mutations/types'\nimport {type Index, type KeyedPathElement, stringify} from '../path'\n\nexport type ItemRef = string | number\n\nexport function format<Doc extends SanityDocumentBase>(\n mutations: Mutation[],\n): string {\n return mutations.flatMap(m => encodeMutation<Doc>(m)).join('\\n')\n}\n\nfunction encodeItemRef(ref: Index | KeyedPathElement): ItemRef {\n return typeof ref === 'number' ? ref : ref._key\n}\n\nfunction encodeMutation<Doc extends SanityDocumentBase>(\n mutation: Mutation,\n): string {\n if (\n mutation.type === 'create' ||\n mutation.type === 'createIfNotExists' ||\n mutation.type === 'createOrReplace'\n ) {\n return [mutation.type, ': ', JSON.stringify(mutation.document)].join('')\n }\n if (mutation.type === 'delete') {\n return ['delete ', mutation.id].join(': ')\n }\n if (mutation.type === 'patch') {\n const ifRevision = mutation.options?.ifRevision\n return [\n 'patch',\n ' ',\n `id=${mutation.id}`,\n ifRevision ? ` (if revision==${ifRevision})` : '',\n ':\\n',\n mutation.patches\n .map(nodePatch => ` ${formatPatchMutation(nodePatch)}`)\n .join('\\n'),\n ].join('')\n }\n\n //@ts-expect-error - all cases are covered\n throw new Error(`Invalid mutation type: ${mutation.type}`)\n}\n\nfunction formatPatchMutation(patch: NodePatch<any>): string {\n const {op} = patch\n const path = stringify(patch.path)\n if (op.type === 'unset') {\n return [path, 'unset()'].join(': ')\n }\n if (op.type === 'diffMatchPatch') {\n return [path, `diffMatchPatch(${op.value})`].join(': ')\n }\n if (op.type === 'inc' || op.type === 'dec') {\n return [path, `${op.type}(${op.amount})`].join(': ')\n }\n if (op.type === 'set' || op.type === 'setIfMissing') {\n return [path, `${op.type}(${JSON.stringify(op.value)})`].join(': ')\n }\n if (op.type === 'assign') {\n return [path, `${op.type}(${JSON.stringify(op.value)})`].join(': ')\n }\n if (op.type === 'unassign') {\n return [path, `${op.type}(${JSON.stringify(op.keys)})`].join(': ')\n }\n if (\n op.type === 'insert' ||\n op.type === 'upsert' ||\n op.type === 'insertIfMissing'\n ) {\n return [\n path,\n `${op.type}(${op.position}, ${encodeItemRef(\n op.referenceItem,\n )}, ${JSON.stringify(op.items)})`,\n ].join(': ')\n }\n if (op.type === 'replace') {\n return [\n path,\n `replace(${encodeItemRef(op.referenceItem)}, ${JSON.stringify(\n op.items,\n )})`,\n ].join(': ')\n }\n if (op.type === 'truncate') {\n return [path, `truncate(${op.startIndex}, ${op.endIndex}`].join(': ')\n }\n if (op.type === 'remove') {\n return [path, `remove(${encodeItemRef(op.referenceItem)})`].join(': ')\n }\n // @ts-expect-error all cases are covered\n throw new Error(`Invalid operation type: ${op.type}`)\n}\n","import {type Index, type KeyedPathElement} from '../path'\nimport {isObject} from '../utils/isObject'\nimport {\n insert as _insert,\n replace as _replace,\n upsert as _upsert,\n} from './operations/creators'\nimport {type RelativePosition} from './operations/types'\n\nexport function autoKeys<Item>(generateKey: (item: Item) => string) {\n const ensureKeys = createEnsureKeys(generateKey)\n\n const insert = <\n Pos extends RelativePosition,\n Ref extends Index | KeyedPathElement,\n >(\n position: Pos,\n referenceItem: Ref,\n items: Item[],\n ) => _insert(ensureKeys(items), position, referenceItem)\n\n const upsert = <\n Pos extends RelativePosition,\n ReferenceItem extends KeyedPathElement,\n >(\n items: Item[],\n position: Pos,\n referenceItem: ReferenceItem,\n ) => _upsert(ensureKeys(items), position, referenceItem)\n\n const replace = <\n Pos extends RelativePosition,\n ReferenceItem extends Index | KeyedPathElement,\n >(\n items: Item[],\n position: Pos,\n referenceItem: ReferenceItem,\n ) => _replace(ensureKeys(items), referenceItem)\n\n const insertBefore = <Ref extends Index | KeyedPathElement>(\n ref: Ref,\n items: Item[],\n ) => insert('before', ref, items)\n\n const prepend = (items: Item[]) => insertBefore(0, items)\n\n const insertAfter = <Ref extends Index | KeyedPathElement>(\n ref: Ref,\n items: Item[],\n ) => insert('after', ref, items)\n\n const append = (items: Item[]) => insert('after', -1, items)\n\n return {insert, upsert, replace, insertBefore, prepend, insertAfter, append}\n}\n\nfunction hasKey<T>(item: T): item is T & {_key: string} {\n return isObject(item) && '_key' in item\n}\n\nfunction createEnsureKeys<T>(generateKey: (item: T) => string) {\n return (array: T[]): (T & {_key: string})[] => {\n let didModify = false\n const withKeys = array.map((item): T & {_key: string} => {\n if (!hasKey(item)) {\n didModify = true\n return {...item, _key: generateKey(item)}\n }\n return item\n })\n return didModify ? withKeys : (array as (T & {_key: string})[])\n }\n}\n"],"names":["parsePath","hasKey","encodeMutation","encodeItemRef","patch","stringifyPath","insert","_insert","upsert","_upsert","replace","_replace","insertBefore","isObject"],"mappings":";;;;;;AAqBO,SAAS,OACd,WACY;AACZ,SAAO,UAAU,IAAI,cAAc;AACrC;AAEO,SAAS,eACd,UACU;AACV,QAAM,CAAC,IAAI,IAAI;AACf,MAAI,SAAS,UAAU;AACrB,UAAM,CAAA,EAAG,EAAE,IAAI;AACf,WAAO,EAA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,IAAI;AAEtE,MAAI,GAAG,SAAS;AACd,WAAO,CAAC,MAAM,UAAU,cAAc,GAAG,aAAa,CAAC,GAAG,EAAE,KAAK,IAAI;AAGvE,QAAM,IAAI,MAAM,2BAA2B,GAAG,IAAI,EAAE;AACtD;;;;;AC5FO,SAAS,SAAe,aAAqC;AAClE,QAAM,aAAa,iBAAiB,WAAW,GAEzCE,WAAS,CAIb,UACA,eACA,UACGC,OAAQ,WAAW,KAAK,GAAG,UAAU,aAAa,GAEjDC,WAAS,CAIb,OACA,UACA,kBACGC,OAAQ,WAAW,KAAK,GAAG,UAAU,aAAa,GAEjDC,YAAU,CAId,OACA,UACA,kBACGC,QAAS,WAAW,KAAK,GAAG,aAAa,GAExCC,gBAAe,CACnB,KACA,UACGN,SAAO,UAAU,KAAK,KAAK;AAWhC,SAAO,UAACA,UAAA,QAAQE,UAAA,SAAQE,WAAS,cAAAE,eAAc,SAT/B,CAAC,UAAkBA,cAAa,GAAG,KAAK,GASA,aAPpC,CAClB,KACA,UACGN,SAAO,SAAS,KAAK,KAAK,GAIsC,QAFtD,CAAC,UAAkBA,SAAO,SAAS,IAAI,KAAK,EAAA;AAG7D;AAEA,SAAS,OAAU,MAAqC;AACtD,SAAOO,WAAS,IAAI,KAAK,UAAU;AACrC;AAEA,SAAS,iBAAoB,aAAkC;AAC7D,SAAO,CAAC,UAAuC;AAC7C,QAAI,YAAY;AAChB,UAAM,WAAW,MAAM,IAAI,CAAC,SACrB,OAAO,IAAI,IAIT,QAHL,YAAY,IACL,EAAC,GAAG,MAAM,MAAM,YAAY,IAAI,IAG1C;AACD,WAAO,YAAY,WAAY;AAAA,EACjC;AACF;"} |
+1
-1
| { | ||
| "name": "@sanity/mutate", | ||
| "version": "0.13.0", | ||
| "version": "0.14.0", | ||
| "description": "Experimental toolkit for working with Sanity mutations in JavaScript & TypeScript", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
778309
2.17%5910
2.52%