@sanity/client 6.11.0 → 6.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/csm.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"csm.cjs","sources":["../src/csm/applySourceDocuments.ts","../src/csm/resolvedKeyedSourcePath.ts","../src/csm/resolveEditUrl.ts"],"sourcesContent":["import {DRAFTS_PREFIX, getPublishedId} from './getPublishedId'\nimport {parseJsonPath} from './jsonPath'\nimport {resolveMapping} from './resolveMapping'\nimport * as paths from './studioPath'\nimport type {\n Any,\n ApplySourceDocumentsUpdateFunction,\n ClientPerspective,\n ContentSourceMap,\n ContentSourceMapDocuments,\n Path,\n SanityDocument,\n} from './types'\nimport {walkMap} from './walkMap'\n\nconst defaultUpdateFunction = <T = unknown>(changed: T): T => changed\n\n/**\n * Optimistically applies source documents to a result, using the content source map to trace fields.\n * Can be used to apply mutations to documents being edited in a Studio, or any mutation on Content Lake, to a result with extremely low latency.\n * @alpha\n */\nexport function applySourceDocuments<Result = unknown>(\n result: Result,\n resultSourceMap: ContentSourceMap | undefined,\n getCachedDocument: (\n sourceDocument: ContentSourceMapDocuments[number],\n ) => SanityDocument | undefined,\n updateFn: ApplySourceDocumentsUpdateFunction = defaultUpdateFunction,\n perspective: ClientPerspective = 'raw',\n): Result {\n if (!resultSourceMap) return result\n\n if (perspective !== 'published' && perspective !== 'raw' && perspective !== 'previewDrafts') {\n throw new Error(`Unknown perspective \"${perspective}\"`)\n }\n\n return walkMap(JSON.parse(JSON.stringify(result)), (value, path) => {\n const resolveMappingResult = resolveMapping(path, resultSourceMap)\n if (!resolveMappingResult) {\n // console.warn('no mapping for path', path)\n return value\n }\n\n const {mapping, pathSuffix} = resolveMappingResult\n if (mapping.type !== 'value') {\n return value\n }\n\n if (mapping.source.type !== 'documentValue') {\n return value\n }\n\n const sourceDocument = resultSourceMap.documents[mapping.source.document]\n const sourcePath = resultSourceMap.paths[mapping.source.path]\n\n if (sourceDocument) {\n const parsedPath = parseJsonPath(sourcePath + pathSuffix)\n const stringifiedPath = paths.toString(parsedPath as Path)\n\n // The _id is sometimes used used as `key` in lists, and should not be changed optimistically\n if (stringifiedPath === '_id') {\n return value\n }\n\n let cachedDocument: SanityDocument | undefined\n if (perspective === 'previewDrafts') {\n cachedDocument = getCachedDocument(\n sourceDocument._id.startsWith(DRAFTS_PREFIX)\n ? sourceDocument\n : {...sourceDocument, _id: `${DRAFTS_PREFIX}.${sourceDocument._id}}`},\n )\n if (!cachedDocument) {\n cachedDocument = getCachedDocument(\n sourceDocument._id.startsWith(DRAFTS_PREFIX)\n ? {...sourceDocument, _id: getPublishedId(sourceDocument._id)}\n : sourceDocument,\n )\n }\n if (cachedDocument) {\n cachedDocument = {\n ...cachedDocument,\n _id: getPublishedId(sourceDocument._id),\n _originalId: sourceDocument._id,\n }\n }\n } else {\n cachedDocument = getCachedDocument(sourceDocument)\n }\n\n if (!cachedDocument) {\n return value\n }\n\n const changedValue = cachedDocument\n ? paths.get<Result[keyof Result]>(cachedDocument, stringifiedPath, value)\n : value\n return value === changedValue\n ? value\n : updateFn<Result[keyof Result]>(changedValue as Any, {\n cachedDocument,\n previousValue: value as Result[keyof Result],\n sourceDocument,\n sourcePath: parsedPath,\n })\n }\n\n return value\n }) as Result\n}\n","import {jsonPath, parseJsonPath} from './jsonPath'\nimport type {ContentSourceMapParsedPath} from './types'\n\n/**\n * @internal\n */\nexport function resolvedKeyedSourcePath(options: {\n keyedResultPath: ContentSourceMapParsedPath\n pathSuffix?: string\n sourceBasePath: string\n}): ContentSourceMapParsedPath {\n const {keyedResultPath, pathSuffix, sourceBasePath} = options\n\n const inferredResultPath = pathSuffix === undefined ? [] : parseJsonPath(pathSuffix)\n\n const inferredPath = keyedResultPath.slice(keyedResultPath.length - inferredResultPath.length)\n\n const inferredPathSuffix = inferredPath.length ? jsonPath(inferredPath).slice(1) : ''\n\n return parseJsonPath(sourceBasePath + inferredPathSuffix)\n}\n","import {createEditUrl} from './createEditUrl'\nimport {studioPathToJsonPath} from './jsonPath'\nimport {resolveEditInfo} from './resolveEditInfo'\nimport type {ResolveEditUrlOptions} from './types'\n\n/** @alpha */\nexport function resolveEditUrl(\n options: ResolveEditUrlOptions,\n): ReturnType<typeof createEditUrl> | undefined {\n const {resultSourceMap, studioUrl} = options\n const resultPath = studioPathToJsonPath(options.resultPath)\n\n const editInfo = resolveEditInfo({\n resultPath,\n resultSourceMap,\n studioUrl,\n })\n if (!editInfo) {\n return undefined\n }\n\n return createEditUrl(editInfo)\n}\n"],"names":["defaultUpdateFunction","changed","applySourceDocuments","result","resultSourceMap","getCachedDocument","updateFn","arguments","length","undefined","perspective","Error","concat","walkMap","JSON","parse","stringify","value","path","resolveMappingResult","resolveMapping","mapping","pathSuffix","type","source","sourceDocument","documents","document","sourcePath","paths","parsedPath","parseJsonPath","stringifiedPath","paths.toString","cachedDocument","_id","startsWith","DRAFTS_PREFIX","getPublishedId","_originalId","changedValue","paths.get","previousValue","resolvedKeyedSourcePath","options","keyedResultPath","sourceBasePath","inferredResultPath","inferredPath","slice","inferredPathSuffix","jsonPath","resolveEditUrl","studioUrl","resultPath","studioPathToJsonPath","editInfo","resolveEditInfo","createEditUrl"],"mappings":";;;;;;AAeA,MAAMA,qBAAA,GAAsCC,OAAkB,IAAAA,OAAA;AAOvD,SAASC,qBACdC,MACA,EAAAC,eAAA,EACAC,mBAKQ;EAAA,IAFRC,QAA+C,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAAP,qBAAA;EAAA,IAC/CU,kFAAiC,KACzB;EACR,IAAI,CAACN,eAAA,EAAwB,OAAAD,MAAA;EAE7B,IAAIO,WAAgB,KAAA,WAAA,IAAeA,WAAgB,KAAA,KAAA,IAASA,gBAAgB,eAAiB,EAAA;IAC3F,MAAM,IAAIC,KAAA,CAAM,uBAAwB,CAAAC,MAAA,CAAAF,WAAA,EAAW,GAAG,CAAA,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C,kBAAA,GAAqBF,aAAaxC,MAAS,GAAA2C,eAAA,CAAAA,QAAA,CAASH,YAAY,CAAE,CAAAC,KAAA,CAAM,CAAC,CAAI,GAAA,EAAA;EAE5E,OAAAlB,eAAA,CAAAA,aAAA,CAAce,iBAAiBI,kBAAkB,CAAA;AAC1D;ACdO,SAASE,eACdR,OAC8C,EAAA;EACxC,MAAA;IAACxC,eAAiB;IAAAiD;EAAa,CAAA,GAAAT,OAAA;EAC/B,MAAAU,UAAA,GAAaC,eAAAA,CAAAA,oBAAqB,CAAAX,OAAA,CAAQU,UAAU,CAAA;EAE1D,MAAME,WAAWC,eAAAA,CAAAA,eAAgB,CAAA;IAC/BH,UAAA;IACAlD,eAAA;IACAiD;EAAA,CACD,CAAA;EACD,IAAI,CAACG,QAAU,EAAA;IACN,OAAA,KAAA,CAAA;EACT;EAEA,OAAOE,eAAAA,CAAAA,cAAcF,QAAQ,CAAA;AAC/B;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"csm.cjs","sources":["../src/csm/applySourceDocuments.ts","../src/csm/resolvedKeyedSourcePath.ts","../src/csm/resolveEditUrl.ts"],"sourcesContent":["import {DRAFTS_PREFIX, getPublishedId} from './getPublishedId'\nimport {parseJsonPath} from './jsonPath'\nimport {resolveMapping} from './resolveMapping'\nimport * as paths from './studioPath'\nimport type {\n Any,\n ApplySourceDocumentsUpdateFunction,\n ClientPerspective,\n ContentSourceMap,\n ContentSourceMapDocuments,\n Path,\n SanityDocument,\n} from './types'\nimport {walkMap} from './walkMap'\n\nconst defaultUpdateFunction = <T = unknown>(changed: T): T => changed\n\n/**\n * Optimistically applies source documents to a result, using the content source map to trace fields.\n * Can be used to apply mutations to documents being edited in a Studio, or any mutation on Content Lake, to a result with extremely low latency.\n * @alpha\n */\nexport function applySourceDocuments<Result = unknown>(\n result: Result,\n resultSourceMap: ContentSourceMap | undefined,\n getCachedDocument: (\n sourceDocument: ContentSourceMapDocuments[number],\n ) => Partial<SanityDocument> | null | undefined,\n updateFn: ApplySourceDocumentsUpdateFunction = defaultUpdateFunction,\n perspective: ClientPerspective = 'raw',\n): Result {\n if (!resultSourceMap) return result\n\n if (perspective !== 'published' && perspective !== 'raw' && perspective !== 'previewDrafts') {\n throw new Error(`Unknown perspective \"${perspective}\"`)\n }\n\n return walkMap(JSON.parse(JSON.stringify(result)), (value, path) => {\n const resolveMappingResult = resolveMapping(path, resultSourceMap)\n if (!resolveMappingResult) {\n // console.warn('no mapping for path', path)\n return value\n }\n\n const {mapping, pathSuffix} = resolveMappingResult\n if (mapping.type !== 'value') {\n return value\n }\n\n if (mapping.source.type !== 'documentValue') {\n return value\n }\n\n const sourceDocument = resultSourceMap.documents[mapping.source.document]\n const sourcePath = resultSourceMap.paths[mapping.source.path]\n\n if (sourceDocument) {\n const parsedPath = parseJsonPath(sourcePath + pathSuffix)\n const stringifiedPath = paths.toString(parsedPath as Path)\n\n // The _id is sometimes used used as `key` in lists, and should not be changed optimistically\n if (stringifiedPath === '_id') {\n return value\n }\n\n let cachedDocument: Partial<SanityDocument> | null | undefined\n if (perspective === 'previewDrafts') {\n cachedDocument = getCachedDocument(\n sourceDocument._id.startsWith(DRAFTS_PREFIX)\n ? sourceDocument\n : {...sourceDocument, _id: `${DRAFTS_PREFIX}.${sourceDocument._id}}`},\n )\n if (!cachedDocument) {\n cachedDocument = getCachedDocument(\n sourceDocument._id.startsWith(DRAFTS_PREFIX)\n ? {...sourceDocument, _id: getPublishedId(sourceDocument._id)}\n : sourceDocument,\n )\n }\n if (cachedDocument) {\n cachedDocument = {\n ...cachedDocument,\n _id: getPublishedId(sourceDocument._id),\n _originalId: sourceDocument._id,\n }\n }\n } else {\n cachedDocument = getCachedDocument(sourceDocument)\n }\n\n if (!cachedDocument) {\n return value\n }\n\n const changedValue = cachedDocument\n ? paths.get<Result[keyof Result]>(cachedDocument, stringifiedPath, value)\n : value\n return value === changedValue\n ? value\n : updateFn<Result[keyof Result]>(changedValue as Any, {\n cachedDocument,\n previousValue: value as Result[keyof Result],\n sourceDocument,\n sourcePath: parsedPath,\n })\n }\n\n return value\n }) as Result\n}\n","import {jsonPath, parseJsonPath} from './jsonPath'\nimport type {ContentSourceMapParsedPath} from './types'\n\n/**\n * @internal\n */\nexport function resolvedKeyedSourcePath(options: {\n keyedResultPath: ContentSourceMapParsedPath\n pathSuffix?: string\n sourceBasePath: string\n}): ContentSourceMapParsedPath {\n const {keyedResultPath, pathSuffix, sourceBasePath} = options\n\n const inferredResultPath = pathSuffix === undefined ? [] : parseJsonPath(pathSuffix)\n\n const inferredPath = keyedResultPath.slice(keyedResultPath.length - inferredResultPath.length)\n\n const inferredPathSuffix = inferredPath.length ? jsonPath(inferredPath).slice(1) : ''\n\n return parseJsonPath(sourceBasePath + inferredPathSuffix)\n}\n","import {createEditUrl} from './createEditUrl'\nimport {studioPathToJsonPath} from './jsonPath'\nimport {resolveEditInfo} from './resolveEditInfo'\nimport type {ResolveEditUrlOptions} from './types'\n\n/** @alpha */\nexport function resolveEditUrl(\n options: ResolveEditUrlOptions,\n): ReturnType<typeof createEditUrl> | undefined {\n const {resultSourceMap, studioUrl} = options\n const resultPath = studioPathToJsonPath(options.resultPath)\n\n const editInfo = resolveEditInfo({\n resultPath,\n resultSourceMap,\n studioUrl,\n })\n if (!editInfo) {\n return undefined\n }\n\n return createEditUrl(editInfo)\n}\n"],"names":["defaultUpdateFunction","changed","applySourceDocuments","result","resultSourceMap","getCachedDocument","updateFn","arguments","length","undefined","perspective","Error","concat","walkMap","JSON","parse","stringify","value","path","resolveMappingResult","resolveMapping","mapping","pathSuffix","type","source","sourceDocument","documents","document","sourcePath","paths","parsedPath","parseJsonPath","stringifiedPath","paths.toString","cachedDocument","_id","startsWith","DRAFTS_PREFIX","getPublishedId","_originalId","changedValue","paths.get","previousValue","resolvedKeyedSourcePath","options","keyedResultPath","sourceBasePath","inferredResultPath","inferredPath","slice","inferredPathSuffix","jsonPath","resolveEditUrl","studioUrl","resultPath","studioPathToJsonPath","editInfo","resolveEditInfo","create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AA;QAClDN,cAAA;QACAQ,aAAe,EAAAzB,KAAA;QACfQ,cAAA;QACAG,UAAY,EAAAE;MAAA,CACb,CAAA;IACP;IAEO,OAAAb,KAAA;EAAA,CACR,CAAA;AACH;ACvGO,SAAS0B,wBAAwBC,OAIT,EAAA;EAC7B,MAAM;IAACC,eAAA;IAAiBvB,UAAY;IAAAwB;EAAA,CAAkB,GAAAF,OAAA;EAEtD,MAAMG,qBAAqBzB,UAAe,KAAA,KAAA,CAAA,GAAY,EAAC,GAAIS,eAAAA,CAAAA,cAAcT,UAAU,CAAA;EAEnF,MAAM0B,eAAeH,eAAgB,CAAAI,KAAA,CAAMJ,eAAgB,CAAArC,MAAA,GAASuC,mBAAmBvC,MAAM,CAAA;EAEvF,MAAA0C,kBAAA,GAAqBF,aAAaxC,MAAS,GAAA2C,eAAA,CAAAA,QAAA,CAASH,YAAY,CAAE,CAAAC,KAAA,CAAM,CAAC,CAAI,GAAA,EAAA;EAE5E,OAAAlB,eAAA,CAAAA,aAAA,CAAce,iBAAiBI,kBAAkB,CAAA;AAC1D;ACdO,SAASE,eACdR,OAC8C,EAAA;EACxC,MAAA;IAACxC,eAAiB;IAAAiD;EAAa,CAAA,GAAAT,OAAA;EAC/B,MAAAU,UAAA,GAAaC,eAAAA,CAAAA,oBAAqB,CAAAX,OAAA,CAAQU,UAAU,CAAA;EAE1D,MAAME,WAAWC,eAAAA,CAAAA,eAAgB,CAAA;IAC/BH,UAAA;IACAlD,eAAA;IACAiD;EAAA,CACD,CAAA;EACD,IAAI,CAACG,QAAU,EAAA;IACN,OAAA,KAAA,CAAA;EACT;EAEA,OAAOE,eAAAA,CAAAA,cAAcF,QAAQ,CAAA;AAC/B;;;;;;;;;;;;;"}
package/dist/csm.d.ts CHANGED
@@ -16,7 +16,7 @@ export declare function applySourceDocuments<Result = unknown>(
16
16
  resultSourceMap: ContentSourceMap | undefined,
17
17
  getCachedDocument: (
18
18
  sourceDocument: ContentSourceMapDocuments[number],
19
- ) => SanityDocument | undefined,
19
+ ) => Partial<SanityDocument> | null | undefined,
20
20
  updateFn?: ApplySourceDocumentsUpdateFunction,
21
21
  perspective?: ClientPerspective,
22
22
  ): Result
@@ -27,7 +27,7 @@ export declare function applySourceDocuments<Result = unknown>(
27
27
  export declare type ApplySourceDocumentsUpdateFunction = <T = unknown>(
28
28
  changedValue: T,
29
29
  context: {
30
- cachedDocument: SanityDocument
30
+ cachedDocument: Partial<SanityDocument>
31
31
  previousValue: T
32
32
  sourceDocument: ContentSourceMapDocuments[number]
33
33
  sourcePath: ContentSourceMapParsedPath
package/dist/csm.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"csm.js","sources":["../src/csm/applySourceDocuments.ts","../src/csm/resolvedKeyedSourcePath.ts","../src/csm/resolveEditUrl.ts"],"sourcesContent":["import {DRAFTS_PREFIX, getPublishedId} from './getPublishedId'\nimport {parseJsonPath} from './jsonPath'\nimport {resolveMapping} from './resolveMapping'\nimport * as paths from './studioPath'\nimport type {\n Any,\n ApplySourceDocumentsUpdateFunction,\n ClientPerspective,\n ContentSourceMap,\n ContentSourceMapDocuments,\n Path,\n SanityDocument,\n} from './types'\nimport {walkMap} from './walkMap'\n\nconst defaultUpdateFunction = <T = unknown>(changed: T): T => changed\n\n/**\n * Optimistically applies source documents to a result, using the content source map to trace fields.\n * Can be used to apply mutations to documents being edited in a Studio, or any mutation on Content Lake, to a result with extremely low latency.\n * @alpha\n */\nexport function applySourceDocuments<Result = unknown>(\n result: Result,\n resultSourceMap: ContentSourceMap | undefined,\n getCachedDocument: (\n sourceDocument: ContentSourceMapDocuments[number],\n ) => SanityDocument | undefined,\n updateFn: ApplySourceDocumentsUpdateFunction = defaultUpdateFunction,\n perspective: ClientPerspective = 'raw',\n): Result {\n if (!resultSourceMap) return result\n\n if (perspective !== 'published' && perspective !== 'raw' && perspective !== 'previewDrafts') {\n throw new Error(`Unknown perspective \"${perspective}\"`)\n }\n\n return walkMap(JSON.parse(JSON.stringify(result)), (value, path) => {\n const resolveMappingResult = resolveMapping(path, resultSourceMap)\n if (!resolveMappingResult) {\n // console.warn('no mapping for path', path)\n return value\n }\n\n const {mapping, pathSuffix} = resolveMappingResult\n if (mapping.type !== 'value') {\n return value\n }\n\n if (mapping.source.type !== 'documentValue') {\n return value\n }\n\n const sourceDocument = resultSourceMap.documents[mapping.source.document]\n const sourcePath = resultSourceMap.paths[mapping.source.path]\n\n if (sourceDocument) {\n const parsedPath = parseJsonPath(sourcePath + pathSuffix)\n const stringifiedPath = paths.toString(parsedPath as Path)\n\n // The _id is sometimes used used as `key` in lists, and should not be changed optimistically\n if (stringifiedPath === '_id') {\n return value\n }\n\n let cachedDocument: SanityDocument | undefined\n if (perspective === 'previewDrafts') {\n cachedDocument = getCachedDocument(\n sourceDocument._id.startsWith(DRAFTS_PREFIX)\n ? sourceDocument\n : {...sourceDocument, _id: `${DRAFTS_PREFIX}.${sourceDocument._id}}`},\n )\n if (!cachedDocument) {\n cachedDocument = getCachedDocument(\n sourceDocument._id.startsWith(DRAFTS_PREFIX)\n ? {...sourceDocument, _id: getPublishedId(sourceDocument._id)}\n : sourceDocument,\n )\n }\n if (cachedDocument) {\n cachedDocument = {\n ...cachedDocument,\n _id: getPublishedId(sourceDocument._id),\n _originalId: sourceDocument._id,\n }\n }\n } else {\n cachedDocument = getCachedDocument(sourceDocument)\n }\n\n if (!cachedDocument) {\n return value\n }\n\n const changedValue = cachedDocument\n ? paths.get<Result[keyof Result]>(cachedDocument, stringifiedPath, value)\n : value\n return value === changedValue\n ? value\n : updateFn<Result[keyof Result]>(changedValue as Any, {\n cachedDocument,\n previousValue: value as Result[keyof Result],\n sourceDocument,\n sourcePath: parsedPath,\n })\n }\n\n return value\n }) as Result\n}\n","import {jsonPath, parseJsonPath} from './jsonPath'\nimport type {ContentSourceMapParsedPath} from './types'\n\n/**\n * @internal\n */\nexport function resolvedKeyedSourcePath(options: {\n keyedResultPath: ContentSourceMapParsedPath\n pathSuffix?: string\n sourceBasePath: string\n}): ContentSourceMapParsedPath {\n const {keyedResultPath, pathSuffix, sourceBasePath} = options\n\n const inferredResultPath = pathSuffix === undefined ? [] : parseJsonPath(pathSuffix)\n\n const inferredPath = keyedResultPath.slice(keyedResultPath.length - inferredResultPath.length)\n\n const inferredPathSuffix = inferredPath.length ? jsonPath(inferredPath).slice(1) : ''\n\n return parseJsonPath(sourceBasePath + inferredPathSuffix)\n}\n","import {createEditUrl} from './createEditUrl'\nimport {studioPathToJsonPath} from './jsonPath'\nimport {resolveEditInfo} from './resolveEditInfo'\nimport type {ResolveEditUrlOptions} from './types'\n\n/** @alpha */\nexport function resolveEditUrl(\n options: ResolveEditUrlOptions,\n): ReturnType<typeof createEditUrl> | undefined {\n const {resultSourceMap, studioUrl} = options\n const resultPath = studioPathToJsonPath(options.resultPath)\n\n const editInfo = resolveEditInfo({\n resultPath,\n resultSourceMap,\n studioUrl,\n })\n if (!editInfo) {\n return undefined\n }\n\n return createEditUrl(editInfo)\n}\n"],"names":["defaultUpdateFunction","changed","applySourceDocuments","result","resultSourceMap","getCachedDocument","updateFn","arguments","length","undefined","perspective","Error","concat","walkMap","JSON","parse","stringify","value","path","resolveMappingResult","resolveMapping","mapping","pathSuffix","type","source","sourceDocument","documents","document","sourcePath","paths","parsedPath","parseJsonPath","stringifiedPath","paths.toString","cachedDocument","_id","startsWith","DRAFTS_PREFIX","getPublishedId","_originalId","changedValue","paths.get","previousValue","resolvedKeyedSourcePath","options","keyedResultPath","sourceBasePath","inferredResultPath","inferredPath","slice","inferredPathSuffix","jsonPath","resolveEditUrl","studioUrl","resultPath","studioPathToJsonPath","editInfo","resolveEditInfo","createEditUrl"],"mappings":";;AAeA,MAAMA,qBAAA,GAAsCC,OAAkB,IAAAA,OAAA;AAOvD,SAASC,qBACdC,MACA,EAAAC,eAAA,EACAC,mBAKQ;EAAA,IAFRC,QAA+C,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAAP,qBAAA;EAAA,I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MAAM0B,eAAeH,eAAgB,CAAAI,KAAA,CAAMJ,eAAgB,CAAArC,MAAA,GAASuC,mBAAmBvC,MAAM,CAAA;EAEvF,MAAA0C,kBAAA,GAAqBF,aAAaxC,MAAS,GAAA2C,QAAA,CAASH,YAAY,CAAE,CAAAC,KAAA,CAAM,CAAC,CAAI,GAAA,EAAA;EAE5E,OAAAlB,aAAA,CAAce,iBAAiBI,kBAAkB,CAAA;AAC1D;ACdO,SAASE,eACdR,OAC8C,EAAA;EACxC,MAAA;IAACxC,eAAiB;IAAAiD;EAAa,CAAA,GAAAT,OAAA;EAC/B,MAAAU,UAAA,GAAaC,oBAAqB,CAAAX,OAAA,CAAQU,UAAU,CAAA;EAE1D,MAAME,WAAWC,eAAgB,CAAA;IAC/BH,UAAA;IACAlD,eAAA;IACAiD;EAAA,CACD,CAAA;EACD,IAAI,CAACG,QAAU,EAAA;IACN,OAAA,KAAA,CAAA;EACT;EAEA,OAAOE,cAAcF,QAAQ,CAAA;AAC/B;"}
1
+ {"version":3,"file":"csm.js","sources":["../src/csm/applySourceDocuments.ts","../src/csm/resolvedKeyedSourcePath.ts","../src/csm/resolveEditUrl.ts"],"sourcesContent":["import {DRAFTS_PREFIX, getPublishedId} from './getPublishedId'\nimport {parseJsonPath} from './jsonPath'\nimport {resolveMapping} from './resolveMapping'\nimport * as paths from './studioPath'\nimport type {\n Any,\n ApplySourceDocumentsUpdateFunction,\n ClientPerspective,\n ContentSourceMap,\n ContentSourceMapDocuments,\n Path,\n SanityDocument,\n} from './types'\nimport {walkMap} from './walkMap'\n\nconst defaultUpdateFunction = <T = unknown>(changed: T): T => changed\n\n/**\n * Optimistically applies source documents to a result, using the content source map to trace fields.\n * Can be used to apply mutations to documents being edited in a Studio, or any mutation on Content Lake, to a result with extremely low latency.\n * @alpha\n */\nexport function applySourceDocuments<Result = unknown>(\n result: Result,\n resultSourceMap: ContentSourceMap | undefined,\n getCachedDocument: (\n sourceDocument: ContentSourceMapDocuments[number],\n ) => Partial<SanityDocument> | null | undefined,\n updateFn: ApplySourceDocumentsUpdateFunction = defaultUpdateFunction,\n perspective: ClientPerspective = 'raw',\n): Result {\n if (!resultSourceMap) return result\n\n if (perspective !== 'published' && perspective !== 'raw' && perspective !== 'previewDrafts') {\n throw new Error(`Unknown perspective \"${perspective}\"`)\n }\n\n return walkMap(JSON.parse(JSON.stringify(result)), (value, path) => {\n const resolveMappingResult = resolveMapping(path, resultSourceMap)\n if (!resolveMappingResult) {\n // console.warn('no mapping for path', path)\n return value\n }\n\n const {mapping, pathSuffix} = resolveMappingResult\n if (mapping.type !== 'value') {\n return value\n }\n\n if (mapping.source.type !== 'documentValue') {\n return value\n }\n\n const sourceDocument = resultSourceMap.documents[mapping.source.document]\n const sourcePath = resultSourceMap.paths[mapping.source.path]\n\n if (sourceDocument) {\n const parsedPath = parseJsonPath(sourcePath + pathSuffix)\n const stringifiedPath = paths.toString(parsedPath as Path)\n\n // The _id is sometimes used used as `key` in lists, and should not be changed optimistically\n if (stringifiedPath === '_id') {\n return value\n }\n\n let cachedDocument: Partial<SanityDocument> | null | undefined\n if (perspective === 'previewDrafts') {\n cachedDocument = getCachedDocument(\n sourceDocument._id.startsWith(DRAFTS_PREFIX)\n ? sourceDocument\n : {...sourceDocument, _id: `${DRAFTS_PREFIX}.${sourceDocument._id}}`},\n )\n if (!cachedDocument) {\n cachedDocument = getCachedDocument(\n sourceDocument._id.startsWith(DRAFTS_PREFIX)\n ? {...sourceDocument, _id: getPublishedId(sourceDocument._id)}\n : sourceDocument,\n )\n }\n if (cachedDocument) {\n cachedDocument = {\n ...cachedDocument,\n _id: getPublishedId(sourceDocument._id),\n _originalId: sourceDocument._id,\n }\n }\n } else {\n cachedDocument = getCachedDocument(sourceDocument)\n }\n\n if (!cachedDocument) {\n return value\n }\n\n const changedValue = cachedDocument\n ? paths.get<Result[keyof Result]>(cachedDocument, stringifiedPath, value)\n : value\n return value === changedValue\n ? value\n : updateFn<Result[keyof Result]>(changedValue as Any, {\n cachedDocument,\n previousValue: value as Result[keyof Result],\n sourceDocument,\n sourcePath: parsedPath,\n })\n }\n\n return value\n }) as Result\n}\n","import {jsonPath, parseJsonPath} from './jsonPath'\nimport type {ContentSourceMapParsedPath} from './types'\n\n/**\n * @internal\n */\nexport function resolvedKeyedSourcePath(options: {\n keyedResultPath: ContentSourceMapParsedPath\n pathSuffix?: string\n sourceBasePath: string\n}): ContentSourceMapParsedPath {\n const {keyedResultPath, pathSuffix, sourceBasePath} = options\n\n const inferredResultPath = pathSuffix === undefined ? [] : parseJsonPath(pathSuffix)\n\n const inferredPath = keyedResultPath.slice(keyedResultPath.length - inferredResultPath.length)\n\n const inferredPathSuffix = inferredPath.length ? jsonPath(inferredPath).slice(1) : ''\n\n return parseJsonPath(sourceBasePath + inferredPathSuffix)\n}\n","import {createEditUrl} from './createEditUrl'\nimport {studioPathToJsonPath} from './jsonPath'\nimport {resolveEditInfo} from './resolveEditInfo'\nimport type {ResolveEditUrlOptions} from './types'\n\n/** @alpha */\nexport function resolveEditUrl(\n options: ResolveEditUrlOptions,\n): ReturnType<typeof createEditUrl> | undefined {\n const {resultSourceMap, studioUrl} = options\n const resultPath = studioPathToJsonPath(options.resultPath)\n\n const editInfo = resolveEditInfo({\n resultPath,\n resultSourceMap,\n studioUrl,\n })\n if (!editInfo) {\n return undefined\n }\n\n return createEditUrl(editInfo)\n}\n"],"names":["defaultUpdateFunction","changed","applySourceDocuments","result","resultSourceMap","getCachedDocument","updateFn","arguments","length","undefined","perspective","Error","concat","walkMap","JSON","parse","stringify","value","path","resolveMappingResult","resolveMapping","mapping","pathSuffix","type","source","sourceDocument","documents","document","sourcePath","paths","parsedPath","parseJsonPath","stringifiedPath","paths.toString","cachedDocument","_id","startsWith","DRAFTS_PREFIX","getPublishedId","_originalId","changedValue","paths.get","previousValue","resolvedKeyedSourcePath","options","keyedResultPath","sourceBasePath","inferredResultPath","inferredPath","slice","inferredPathSuffix","jsonPath","resolveEditUrl","studioUrl","resultPath","studioPathToJson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IAEO,OAAAb,KAAA;EAAA,CACR,CAAA;AACH;ACvGO,SAAS0B,wBAAwBC,OAIT,EAAA;EAC7B,MAAM;IAACC,eAAA;IAAiBvB,UAAY;IAAAwB;EAAA,CAAkB,GAAAF,OAAA;EAEtD,MAAMG,qBAAqBzB,UAAe,KAAA,KAAA,CAAA,GAAY,EAAC,GAAIS,cAAcT,UAAU,CAAA;EAEnF,MAAM0B,eAAeH,eAAgB,CAAAI,KAAA,CAAMJ,eAAgB,CAAArC,MAAA,GAASuC,mBAAmBvC,MAAM,CAAA;EAEvF,MAAA0C,kBAAA,GAAqBF,aAAaxC,MAAS,GAAA2C,QAAA,CAASH,YAAY,CAAE,CAAAC,KAAA,CAAM,CAAC,CAAI,GAAA,EAAA;EAE5E,OAAAlB,aAAA,CAAce,iBAAiBI,kBAAkB,CAAA;AAC1D;ACdO,SAASE,eACdR,OAC8C,EAAA;EACxC,MAAA;IAACxC,eAAiB;IAAAiD;EAAa,CAAA,GAAAT,OAAA;EAC/B,MAAAU,UAAA,GAAaC,oBAAqB,CAAAX,OAAA,CAAQU,UAAU,CAAA;EAE1D,MAAME,WAAWC,eAAgB,CAAA;IAC/BH,UAAA;IACAlD,eAAA;IACAiD;EAAA,CACD,CAAA;EACD,IAAI,CAACG,QAAU,EAAA;IACN,OAAA,KAAA,CAAA;EACT;EAEA,OAAOE,cAAcF,QAAQ,CAAA;AAC/B;"}
package/dist/index.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', {
4
4
  value: true
5
5
  });
6
- var nodeMiddleware = require('./_chunks/nodeMiddleware-qHjfdThT.cjs');
6
+ var nodeMiddleware = require('./_chunks/nodeMiddleware-qKdVvFDs.cjs');
7
7
  var getIt = require('get-it');
8
8
  function defineDeprecatedCreateClient(createClient) {
9
9
  return function deprecatedCreateClient(config) {
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { printNoDefaultExport, defineCreateClientExports, SanityClient, middleware } from './_chunks/nodeMiddleware-KmzBikOI.js';
2
- export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, ServerError, Transaction } from './_chunks/nodeMiddleware-KmzBikOI.js';
1
+ import { printNoDefaultExport, defineCreateClientExports, SanityClient, middleware } from './_chunks/nodeMiddleware-P6A9E9ae.js';
2
+ export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, ServerError, Transaction } from './_chunks/nodeMiddleware-P6A9E9ae.js';
3
3
  export { adapter as unstable__adapter, environment as unstable__environment } from 'get-it';
4
4
  function defineDeprecatedCreateClient(createClient) {
5
5
  return function deprecatedCreateClient(config) {
package/dist/stega.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', {
4
4
  value: true
5
5
  });
6
- var nodeMiddleware = require('./_chunks/nodeMiddleware-qHjfdThT.cjs');
6
+ var nodeMiddleware = require('./_chunks/nodeMiddleware-qKdVvFDs.cjs');
7
7
  var operators = require('rxjs/operators');
8
8
  var stega = require('@vercel/stega');
9
9
  var resolveEditInfo = require('./_chunks/resolveEditInfo-TYjTkHKU.cjs');
package/dist/stega.js CHANGED
@@ -1,5 +1,5 @@
1
- import { ObservableSanityClient, defaultConfig, SanityClient, defineCreateClientExports, middleware } from './_chunks/nodeMiddleware-KmzBikOI.js';
2
- export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableTransaction, Patch, ServerError, Transaction } from './_chunks/nodeMiddleware-KmzBikOI.js';
1
+ import { ObservableSanityClient, defaultConfig, SanityClient, defineCreateClientExports, middleware } from './_chunks/nodeMiddleware-P6A9E9ae.js';
2
+ export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableTransaction, Patch, ServerError, Transaction } from './_chunks/nodeMiddleware-P6A9E9ae.js';
3
3
  import { map } from 'rxjs/operators';
4
4
  import { vercelStegaCombine, vercelStegaSplit } from '@vercel/stega';
5
5
  import { walkMap, resolveMapping, parseJsonPath, resolveStudioBaseRoute, createEditUrl, reKeySegment, toString, jsonPathToStudioPath } from './_chunks/resolveEditInfo-FaeuCV4M.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "6.11.0",
3
+ "version": "6.11.1",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "keywords": [
6
6
  "sanity",
@@ -25,7 +25,7 @@ export function applySourceDocuments<Result = unknown>(
25
25
  resultSourceMap: ContentSourceMap | undefined,
26
26
  getCachedDocument: (
27
27
  sourceDocument: ContentSourceMapDocuments[number],
28
- ) => SanityDocument | undefined,
28
+ ) => Partial<SanityDocument> | null | undefined,
29
29
  updateFn: ApplySourceDocumentsUpdateFunction = defaultUpdateFunction,
30
30
  perspective: ClientPerspective = 'raw',
31
31
  ): Result {
@@ -63,7 +63,7 @@ export function applySourceDocuments<Result = unknown>(
63
63
  return value
64
64
  }
65
65
 
66
- let cachedDocument: SanityDocument | undefined
66
+ let cachedDocument: Partial<SanityDocument> | null | undefined
67
67
  if (perspective === 'previewDrafts') {
68
68
  cachedDocument = getCachedDocument(
69
69
  sourceDocument._id.startsWith(DRAFTS_PREFIX)
package/src/csm/types.ts CHANGED
@@ -90,7 +90,7 @@ export interface ResolveEditUrlOptions extends Omit<ResolveEditInfoOptions, 'res
90
90
  export type ApplySourceDocumentsUpdateFunction = <T = unknown>(
91
91
  changedValue: T,
92
92
  context: {
93
- cachedDocument: SanityDocument
93
+ cachedDocument: Partial<SanityDocument>
94
94
  previousValue: T
95
95
  sourceDocument: ContentSourceMapDocuments[number]
96
96
  sourcePath: ContentSourceMapParsedPath