UNPKG

@sanity/client

Version:

Client for retrieving, creating and patching data from Sanity.io

31 lines (30 loc) • 1.31 kB
import { getPublishedId } from "@sanity/client/csm"; /** * Build the global document reference a comment stores in `target.document._ref`, * without a client. * * `client.collaboration.comments.getTargetDocumentRef` reads the resource off the * client's configuration and calls this. Use this directly when the resource is * already at hand and no client should be involved, for example inside a state * selector that has to stay free of side effects. * * The reference always names the published document: a draft or version ID is * reduced to its published form first. * * @example * ```ts * getCommentTargetDocumentRef({type: 'dataset', id: 'abc123.production'}, 'drafts.doc-1') * // 'dataset:abc123.production:doc-1' * ``` * * @param resource - The resource the comments are stored against, as `ClientConfig['resource']` takes it * @param documentId - Document ID, in published, draft or version form * @returns Global document reference, of the form `resourceType:resourceId:documentId` * @alpha */ function getCommentTargetDocumentRef(resource, documentId) { if (!documentId) throw Error("Document ID must be provided"); return `${resource.type}:${resource.id}:${getPublishedId(documentId)}`; } export { getCommentTargetDocumentRef as t }; //# sourceMappingURL=getCommentTargetDocumentRef-B8NuiBjG.js.map