@sanity/client
Version:
Client for retrieving, creating and patching data from Sanity.io
178 lines • 8.1 kB
TypeScript
import { Any, ClientPerspective, ContentSourceMap, ContentSourceMap as ContentSourceMap$1, ContentSourceMapDocument, ContentSourceMapDocumentBase, ContentSourceMapDocumentValueSource, ContentSourceMapDocuments, ContentSourceMapDocuments as ContentSourceMapDocuments$1, ContentSourceMapLiteralSource, ContentSourceMapMapping, ContentSourceMapMappings, ContentSourceMapPaths, ContentSourceMapRemoteDocument, ContentSourceMapSource, ContentSourceMapUnknownSource, ContentSourceMapValueMapping, SanityDocument, SanityDocument as SanityDocument$1 } from "@sanity/client";
declare namespace studioPath_d_exports {
export { IndexTuple, KeyedSegment, Path, PathSegment, fromString, get, isIndexSegment, isIndexTuple, isKeySegment, reKeySegment, toString };
}
/** @alpha */
type KeyedSegment = {
_key: string;
};
/** @alpha */
type IndexTuple = [number | '', number | ''];
/** @alpha */
type PathSegment = string | number | KeyedSegment | IndexTuple;
/** @alpha */
type Path = PathSegment[];
/** @internal */
declare const reKeySegment: RegExp;
/** @internal */
declare function isIndexSegment(segment: PathSegment): segment is number;
/** @internal */
declare function isKeySegment(segment: PathSegment): segment is KeyedSegment;
/** @internal */
declare function isIndexTuple(segment: PathSegment): segment is IndexTuple;
/** @internal */
declare function get<Result = unknown, Fallback = unknown>(obj: unknown, path: Path | string, defaultVal?: Fallback): Result | typeof defaultVal;
/** @alpha */
declare function toString(path: Path): string;
/** @alpha */
declare function fromString(path: string): Path;
/**
* @alpha
* @deprecated use `ContentSourceMapParsedPath[number]` instead
*/
type ContentSourceMapParsedPathSegment = ContentSourceMapParsedPath[number];
/** @alpha */
type ContentSourceMapParsedPathKeyedSegment = {
_key: string;
_index: number;
};
/** @alpha */
type ContentSourceMapParsedPath = (string | number | ContentSourceMapParsedPathKeyedSegment)[];
/** @alpha */
type StudioBaseUrl = `/${string}` | `${string}.sanity.studio` | `https://${string}` | (string & {});
/** @alpha */
type StudioBaseRoute = {
baseUrl: StudioBaseUrl;
workspace?: string;
tool?: string;
};
/** @alpha */
type StudioUrl = StudioBaseUrl | StudioBaseRoute;
/** @alpha */
type ResolveStudioUrl = (sourceDocument: ContentSourceMapDocuments$1[number]) => StudioUrl;
/**
* Path syntax as used by the `sanity` package, you can give it a string:
* `products[0].images[_key=="abc123"].asset._ref`
* or an array:
* `['products', 0, 'images', {_key: 'abc123'}, 'asset', '_ref']`
* @alpha
*/
type StudioPathLike = Path | string;
/** @alpha */
type EditIntentUrl = `/intent/edit/mode=presentation;id=${string};type=${string};path=${string}`;
/** @internal */
interface CreateEditUrlOptions {
baseUrl: string;
workspace?: string;
tool?: string;
id: string;
type: string;
path: ContentSourceMapParsedPath | string;
projectId?: string;
dataset?: string;
}
/** @alpha */
interface ResolveEditInfoOptions {
studioUrl: StudioUrl | ResolveStudioUrl;
resultSourceMap: ContentSourceMap$1;
resultPath: ContentSourceMapParsedPath;
}
/** @alpha */
interface ResolveEditUrlOptions extends Omit<ResolveEditInfoOptions, 'resultPath'> {
resultPath: StudioPathLike;
}
/**
* @alpha
*/
type ApplySourceDocumentsUpdateFunction = <T = unknown>(changedValue: T, context: {
cachedDocument: Partial<SanityDocument$1>;
previousValue: T;
sourceDocument: ContentSourceMapDocuments$1[number];
sourcePath: ContentSourceMapParsedPath;
}) => T;
/**
* @internal
*/
type WalkMapFn = (value: unknown, path: ContentSourceMapParsedPath) => unknown;
/**
* Optimistically applies source documents to a result, using the content source map to trace fields.
* 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.
* @alpha
*/
declare function applySourceDocuments<Result = unknown>(result: Result, resultSourceMap: ContentSourceMap | undefined, getCachedDocument: (sourceDocument: ContentSourceMapDocuments[number]) => (Partial<SanityDocument> & Required<Pick<SanityDocument, '_id' | '_type'>>) | null | undefined, updateFn: ApplySourceDocumentsUpdateFunction, perspective: Exclude<ClientPerspective, 'raw'>): Result;
/** @internal */
declare function createEditUrl(options: CreateEditUrlOptions): `${StudioBaseUrl}${EditIntentUrl}`;
type Opaque<T, K> = T & {
__opaqueId__: K;
};
/** @internal */
type DraftId = Opaque<string, 'draftId'>;
/** @internal */
type PublishedId = Opaque<string, 'publishedId'>;
/** @internal */
declare const DRAFTS_FOLDER = "drafts";
/** @internal */
declare const VERSION_FOLDER = "versions";
/** @internal */
declare function isDraftId(id: string): id is DraftId;
/** @internal */
declare function isVersionId(id: string): boolean;
/** @internal */
declare function isPublishedId(id: string): id is PublishedId;
/** @internal */
declare function getDraftId(id: string): DraftId;
/** @internal */
declare function getVersionId(id: string, version: string): string;
/**
* @internal
* Given an id, returns the versionId if it exists.
* e.g. `versions.summer-drop.foo` = `summer-drop`
* e.g. `drafts.foo` = `undefined`
* e.g. `foo` = `undefined`
*/
declare function getVersionFromId(id: string): string | undefined;
/** @internal */
declare function getPublishedId(id: string): PublishedId;
/**
* @internal
*/
declare function jsonPath(path: ContentSourceMapParsedPath): ContentSourceMapPaths[number];
/**
* @internal
*/
declare function parseJsonPath(path: ContentSourceMapPaths[number]): ContentSourceMapParsedPath;
/**
* @internal
*/
declare function jsonPathToStudioPath(path: ContentSourceMapParsedPath): Path;
/**
* @internal
*/
declare function studioPathToJsonPath(path: Path | string): ContentSourceMapParsedPath;
/**
* @internal
*/
declare function resolvedKeyedSourcePath(options: {
keyedResultPath: ContentSourceMapParsedPath;
pathSuffix?: string;
sourceBasePath: string;
}): ContentSourceMapParsedPath;
/** @internal */
declare function resolveEditInfo(options: ResolveEditInfoOptions): CreateEditUrlOptions | undefined;
/** @alpha */
declare function resolveEditUrl(options: ResolveEditUrlOptions): ReturnType<typeof createEditUrl> | undefined;
/**
* @internal
*/
declare function resolveMapping(resultPath: ContentSourceMapParsedPath, csm?: ContentSourceMap): {
mapping: ContentSourceMapMapping;
matchedPath: string;
pathSuffix: string;
} | undefined;
/**
* generic way to walk a nested object or array and apply a mapping function to each value
* @internal
*/
declare function walkMap(value: unknown, mappingFn: WalkMapFn, path?: ContentSourceMapParsedPath): unknown;
export { type Any, type ApplySourceDocumentsUpdateFunction, type ClientPerspective, type ContentSourceMap, type ContentSourceMapDocument, type ContentSourceMapDocumentBase, type ContentSourceMapDocumentValueSource, type ContentSourceMapDocuments, type ContentSourceMapLiteralSource, type ContentSourceMapMapping, type ContentSourceMapMappings, type ContentSourceMapParsedPath, type ContentSourceMapParsedPathKeyedSegment, type ContentSourceMapParsedPathSegment, type ContentSourceMapPaths, type ContentSourceMapRemoteDocument, type ContentSourceMapSource, type ContentSourceMapUnknownSource, type ContentSourceMapValueMapping, type CreateEditUrlOptions, DRAFTS_FOLDER, type DraftId, type EditIntentUrl, type IndexTuple, type KeyedSegment, type Path, type PathSegment, type PublishedId, type ResolveEditInfoOptions, type ResolveEditUrlOptions, type ResolveStudioUrl, type SanityDocument, type StudioBaseRoute, type StudioBaseUrl, type StudioPathLike, type StudioUrl, VERSION_FOLDER, type WalkMapFn, applySourceDocuments, createEditUrl, getDraftId, getPublishedId, getVersionFromId, getVersionId, isDraftId, isPublishedId, isVersionId, jsonPath, jsonPathToStudioPath, parseJsonPath, resolveEditInfo, resolveEditUrl, resolveMapping, resolvedKeyedSourcePath, studioPath_d_exports as studioPath, studioPathToJsonPath, walkMap };
//# sourceMappingURL=csm.d.ts.map