index.d.ts 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263
  1. /// <reference types="node" />
  2. import {Observable} from 'rxjs'
  3. import {Requester} from 'get-it'
  4. import {adapter as unstable__adapter} from 'get-it'
  5. import {environment as unstable__environment} from 'get-it'
  6. /** @internal */
  7. export declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
  8. returnFirst: false
  9. returnDocuments: false
  10. }
  11. /** @internal */
  12. export declare type AllDocumentsMutationOptions = BaseMutationOptions & {
  13. returnFirst: false
  14. returnDocuments?: true
  15. }
  16. /**
  17. * Used to tag types that is set to `any` as a temporary measure, but should be replaced with proper typings in the future
  18. * @internal
  19. */
  20. export declare type Any = any
  21. /** @internal */
  22. export declare interface ApiError {
  23. error: string
  24. message: string
  25. statusCode: number
  26. }
  27. /** @public */
  28. export declare type AssetMetadataType =
  29. | 'location'
  30. | 'exif'
  31. | 'image'
  32. | 'palette'
  33. | 'lqip'
  34. | 'blurhash'
  35. | 'none'
  36. /** @internal */
  37. export declare class AssetsClient {
  38. #private
  39. constructor(client: SanityClient, httpRequest: HttpRequest)
  40. /**
  41. * Uploads a file asset to the configured dataset
  42. *
  43. * @param assetType - Asset type (file)
  44. * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
  45. * @param options - Options to use for the upload
  46. */
  47. upload(
  48. assetType: 'file',
  49. body: UploadBody,
  50. options?: UploadClientConfig
  51. ): Promise<SanityAssetDocument>
  52. /**
  53. * Uploads an image asset to the configured dataset
  54. *
  55. * @param assetType - Asset type (image)
  56. * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
  57. * @param options - Options to use for the upload
  58. */
  59. upload(
  60. assetType: 'image',
  61. body: UploadBody,
  62. options?: UploadClientConfig
  63. ): Promise<SanityImageAssetDocument>
  64. /**
  65. * Uploads a file or an image asset to the configured dataset
  66. *
  67. * @param assetType - Asset type (file/image)
  68. * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
  69. * @param options - Options to use for the upload
  70. */
  71. upload(
  72. assetType: 'file' | 'image',
  73. body: UploadBody,
  74. options?: UploadClientConfig
  75. ): Promise<SanityAssetDocument | SanityImageAssetDocument>
  76. }
  77. /** @internal */
  78. export declare type AttributeSet = {
  79. [key: string]: Any
  80. }
  81. /** @internal */
  82. export declare interface AuthProvider {
  83. name: string
  84. title: string
  85. url: string
  86. }
  87. /** @internal */
  88. export declare type AuthProviderResponse = {
  89. providers: AuthProvider[]
  90. }
  91. /** @internal */
  92. export declare type BaseMutationOptions = RequestOptions & {
  93. visibility?: 'sync' | 'async' | 'deferred'
  94. returnDocuments?: boolean
  95. returnFirst?: boolean
  96. dryRun?: boolean
  97. autoGenerateArrayKeys?: boolean
  98. skipCrossDatasetReferenceValidation?: boolean
  99. transactionId?: string
  100. }
  101. /** @internal */
  102. export declare class BasePatch {
  103. protected selection: PatchSelection
  104. protected operations: PatchOperations
  105. constructor(selection: PatchSelection, operations?: PatchOperations)
  106. /**
  107. * Sets the given attributes to the document. Does NOT merge objects.
  108. * The operation is added to the current patch, ready to be commited by `commit()`
  109. *
  110. * @param attrs - Attributes to set. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "value"\}
  111. */
  112. set(attrs: AttributeSet): this
  113. /**
  114. * Sets the given attributes to the document if they are not currently set. Does NOT merge objects.
  115. * The operation is added to the current patch, ready to be commited by `commit()`
  116. *
  117. * @param attrs - Attributes to set. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "value"\}
  118. */
  119. setIfMissing(attrs: AttributeSet): this
  120. /**
  121. * Performs a "diff-match-patch" operation on the string attributes provided.
  122. * The operation is added to the current patch, ready to be commited by `commit()`
  123. *
  124. * @param attrs - Attributes to perform operation on. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "dmp"\}
  125. */
  126. diffMatchPatch(attrs: AttributeSet): this
  127. /**
  128. * Unsets the attribute paths provided.
  129. * The operation is added to the current patch, ready to be commited by `commit()`
  130. *
  131. * @param attrs - Attribute paths to unset.
  132. */
  133. unset(attrs: string[]): this
  134. /**
  135. * Increment a numeric value. Each entry in the argument is either an attribute or a JSON path. The value may be a positive or negative integer or floating-point value. The operation will fail if target value is not a numeric value, or doesn't exist.
  136. *
  137. * @param attrs - Object of attribute paths to increment, values representing the number to increment by.
  138. */
  139. inc(attrs: {[key: string]: number}): this
  140. /**
  141. * Decrement a numeric value. Each entry in the argument is either an attribute or a JSON path. The value may be a positive or negative integer or floating-point value. The operation will fail if target value is not a numeric value, or doesn't exist.
  142. *
  143. * @param attrs - Object of attribute paths to decrement, values representing the number to decrement by.
  144. */
  145. dec(attrs: {[key: string]: number}): this
  146. /**
  147. * Provides methods for modifying arrays, by inserting, appending and replacing elements via a JSONPath expression.
  148. *
  149. * @param at - Location to insert at, relative to the given selector, or 'replace' the matched path
  150. * @param selector - JSONPath expression, eg `comments[-1]` or `blocks[_key=="abc123"]`
  151. * @param items - Array of items to insert/replace
  152. */
  153. insert(at: 'before' | 'after' | 'replace', selector: string, items: Any[]): this
  154. /**
  155. * Append the given items to the array at the given JSONPath
  156. *
  157. * @param selector - Attribute/path to append to, eg `comments` or `person.hobbies`
  158. * @param items - Array of items to append to the array
  159. */
  160. append(selector: string, items: Any[]): this
  161. /**
  162. * Prepend the given items to the array at the given JSONPath
  163. *
  164. * @param selector - Attribute/path to prepend to, eg `comments` or `person.hobbies`
  165. * @param items - Array of items to prepend to the array
  166. */
  167. prepend(selector: string, items: Any[]): this
  168. /**
  169. * Change the contents of an array by removing existing elements and/or adding new elements.
  170. *
  171. * @param selector - Attribute or JSONPath expression for array
  172. * @param start - Index at which to start changing the array (with origin 0). If greater than the length of the array, actual starting index will be set to the length of the array. If negative, will begin that many elements from the end of the array (with origin -1) and will be set to 0 if absolute value is greater than the length of the array.x
  173. * @param deleteCount - An integer indicating the number of old array elements to remove.
  174. * @param items - The elements to add to the array, beginning at the start index. If you don't specify any elements, splice() will only remove elements from the array.
  175. */
  176. splice(selector: string, start: number, deleteCount?: number, items?: Any[]): this
  177. /**
  178. * Adds a revision clause, preventing the document from being patched if the `_rev` property does not match the given value
  179. *
  180. * @param rev - Revision to lock the patch to
  181. */
  182. ifRevisionId(rev: string): this
  183. /**
  184. * Return a plain JSON representation of the patch
  185. */
  186. serialize(): PatchMutationOperation
  187. /**
  188. * Return a plain JSON representation of the patch
  189. */
  190. toJSON(): PatchMutationOperation
  191. /**
  192. * Clears the patch of all operations
  193. */
  194. reset(): this
  195. protected _assign(op: keyof PatchOperations, props: Any, merge?: boolean): this
  196. protected _set(op: keyof PatchOperations, props: Any): this
  197. }
  198. /** @internal */
  199. export declare class BaseTransaction {
  200. protected operations: Mutation[]
  201. protected trxId?: string
  202. constructor(operations?: Mutation[], transactionId?: string)
  203. /**
  204. * Creates a new Sanity document. If `_id` is provided and already exists, the mutation will fail. If no `_id` is given, one will automatically be generated by the database.
  205. * The operation is added to the current transaction, ready to be commited by `commit()`
  206. *
  207. * @param doc - Document to create. Requires a `_type` property.
  208. */
  209. create<R extends Record<string, Any> = Record<string, Any>>(doc: SanityDocumentStub<R>): this
  210. /**
  211. * Creates a new Sanity document. If a document with the same `_id` already exists, the create operation will be ignored.
  212. * The operation is added to the current transaction, ready to be commited by `commit()`
  213. *
  214. * @param doc - Document to create if it does not already exist. Requires `_id` and `_type` properties.
  215. */
  216. createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
  217. doc: IdentifiedSanityDocumentStub<R>
  218. ): this
  219. /**
  220. * Creates a new Sanity document, or replaces an existing one if the same `_id` is already used.
  221. * The operation is added to the current transaction, ready to be commited by `commit()`
  222. *
  223. * @param doc - Document to create or replace. Requires `_id` and `_type` properties.
  224. */
  225. createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
  226. doc: IdentifiedSanityDocumentStub<R>
  227. ): this
  228. /**
  229. * Deletes the document with the given document ID
  230. * The operation is added to the current transaction, ready to be commited by `commit()`
  231. *
  232. * @param documentId - Document ID to delete
  233. */
  234. delete(documentId: string): this
  235. /**
  236. * Gets the current transaction ID, if any
  237. */
  238. transactionId(): string | undefined
  239. /**
  240. * Set the ID of this transaction.
  241. *
  242. * @param id - Transaction ID
  243. */
  244. transactionId(id: string): this
  245. /**
  246. * Return a plain JSON representation of the transaction
  247. */
  248. serialize(): Mutation[]
  249. /**
  250. * Return a plain JSON representation of the transaction
  251. */
  252. toJSON(): Mutation[]
  253. /**
  254. * Clears the transaction of all operations
  255. */
  256. reset(): this
  257. protected _add(mut: Mutation): this
  258. }
  259. /** @public */
  260. export declare type ChannelErrorEvent = {
  261. type: 'channelError'
  262. message: string
  263. }
  264. /** @public */
  265. export declare interface ClientConfig {
  266. projectId?: string
  267. dataset?: string
  268. useCdn?: boolean
  269. token?: string
  270. apiHost?: string
  271. apiVersion?: string
  272. proxy?: string
  273. requestTagPrefix?: string
  274. ignoreBrowserTokenWarning?: boolean
  275. withCredentials?: boolean
  276. allowReconfigure?: boolean
  277. timeout?: number
  278. /**
  279. * @deprecated Don't use
  280. */
  281. useProjectHostname?: boolean
  282. /**
  283. * @deprecated Don't use
  284. */
  285. requester?: Requester
  286. }
  287. /** @public */
  288. export declare class ClientError extends Error {
  289. response: ErrorProps['response']
  290. statusCode: ErrorProps['statusCode']
  291. responseBody: ErrorProps['responseBody']
  292. details: ErrorProps['details']
  293. constructor(res: Any)
  294. }
  295. /** @public */
  296. export declare const createClient: (config: ClientConfig) => SanityClient
  297. /** @internal */
  298. export declare interface CurrentSanityUser {
  299. id: string
  300. name: string
  301. email: string
  302. profileImage: string | null
  303. role: string
  304. }
  305. /** @internal */
  306. export declare type DatasetAclMode = 'public' | 'private' | 'custom'
  307. /** @internal */
  308. export declare type DatasetResponse = {
  309. datasetName: string
  310. aclMode: DatasetAclMode
  311. }
  312. /** @internal */
  313. export declare class DatasetsClient {
  314. #private
  315. constructor(client: SanityClient, httpRequest: HttpRequest)
  316. /**
  317. * Create a new dataset with the given name
  318. *
  319. * @param name - Name of the dataset to create
  320. * @param options - Options for the dataset
  321. */
  322. create(
  323. name: string,
  324. options?: {
  325. aclMode?: DatasetAclMode
  326. }
  327. ): Promise<DatasetResponse>
  328. /**
  329. * Edit a dataset with the given name
  330. *
  331. * @param name - Name of the dataset to edit
  332. * @param options - New options for the dataset
  333. */
  334. edit(
  335. name: string,
  336. options?: {
  337. aclMode?: DatasetAclMode
  338. }
  339. ): Promise<DatasetResponse>
  340. /**
  341. * Delete a dataset with the given name
  342. *
  343. * @param name - Name of the dataset to delete
  344. */
  345. delete(name: string): Promise<{
  346. deleted: true
  347. }>
  348. /**
  349. * Fetch a list of datasets for the configured project
  350. */
  351. list(): Promise<DatasetsResponse>
  352. }
  353. /** @internal */
  354. export declare type DatasetsResponse = {
  355. name: string
  356. aclMode: DatasetAclMode
  357. }[]
  358. /**
  359. * @public
  360. * @deprecated Use the named export `createClient` instead of the `default` export
  361. */
  362. declare function deprecatedCreateClient(config: ClientConfig): SanityClient
  363. export default deprecatedCreateClient
  364. /** @public */
  365. export declare type DisconnectEvent = {
  366. type: 'disconnect'
  367. reason: string
  368. }
  369. /** @public */
  370. export declare interface ErrorProps {
  371. message: string
  372. response: Any
  373. statusCode: number
  374. responseBody: Any
  375. details: Any
  376. }
  377. /** @internal */
  378. export declare type FilteredResponseQueryOptions = RequestOptions & {
  379. filterResponse?: true
  380. }
  381. /** @internal */
  382. export declare type FirstDocumentIdMutationOptions = BaseMutationOptions & {
  383. returnFirst?: true
  384. returnDocuments: false
  385. }
  386. /** @internal */
  387. export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
  388. returnFirst?: true
  389. returnDocuments?: true
  390. }
  391. /** @public */
  392. export declare type HttpRequest = {
  393. defaultRequester: Requester
  394. (options: RequestOptions, requester: Requester): ReturnType<Requester>
  395. }
  396. /** @public */
  397. export declare type HttpRequestEvent<T = unknown> = ResponseEvent<T> | ProgressEvent_2
  398. /** @public */
  399. export declare type IdentifiedSanityDocumentStub<
  400. T extends Record<string, Any> = Record<string, Any>
  401. > = {
  402. [P in keyof T]: T[P]
  403. } & {
  404. _id: string
  405. } & SanityDocumentStub
  406. /** @public */
  407. export declare interface InitializedClientConfig extends ClientConfig {
  408. apiHost: string
  409. apiVersion: string
  410. useProjectHostname: boolean
  411. useCdn: boolean
  412. /**
  413. * @deprecated Internal, don't use
  414. */
  415. isDefaultApi: boolean
  416. /**
  417. * @deprecated Internal, don't use
  418. */
  419. url: string
  420. /**
  421. * @deprecated Internal, don't use
  422. */
  423. cdnUrl: string
  424. }
  425. /** @internal */
  426. export declare type InsertPatch =
  427. | {
  428. before: string
  429. items: Any[]
  430. }
  431. | {
  432. after: string
  433. items: Any[]
  434. }
  435. | {
  436. replace: string
  437. items: Any[]
  438. }
  439. /**
  440. * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
  441. *
  442. * @param query - GROQ-filter to listen to changes for
  443. * @param params - Optional query parameters
  444. * @param options - Listener options
  445. * @internal
  446. */
  447. export declare function _listen<R extends Record<string, Any> = Record<string, Any>>(
  448. this: SanityClient | ObservableSanityClient,
  449. query: string,
  450. params?: QueryParams
  451. ): Observable<MutationEvent_2<R>>
  452. /**
  453. * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
  454. *
  455. * @param query - GROQ-filter to listen to changes for
  456. * @param params - Optional query parameters
  457. * @param options - Listener options
  458. * @internal
  459. */
  460. export declare function _listen<R extends Record<string, Any> = Record<string, Any>>(
  461. this: SanityClient | ObservableSanityClient,
  462. query: string,
  463. params?: QueryParams,
  464. options?: ListenOptions
  465. ): Observable<ListenEvent<R>>
  466. /** @public */
  467. export declare type ListenEvent<R extends Record<string, Any>> =
  468. | MutationEvent_2<R>
  469. | ChannelErrorEvent
  470. | DisconnectEvent
  471. | ReconnectEvent
  472. | WelcomeEvent
  473. /** @public */
  474. export declare type ListenEventName = 'mutation' | 'welcome' | 'reconnect'
  475. /** @public */
  476. export declare interface ListenOptions {
  477. includeResult?: boolean
  478. includePreviousRevision?: boolean
  479. visibility?: 'sync' | 'async' | 'query'
  480. events?: ListenEventName[]
  481. effectFormat?: 'mendoza'
  482. tag?: string
  483. }
  484. /** @internal */
  485. export declare interface MultipleMutationResult {
  486. transactionId: string
  487. documentIds: string[]
  488. results: {
  489. id: string
  490. operation: MutationOperation
  491. }[]
  492. }
  493. /** @public */
  494. export declare type Mutation<R extends Record<string, Any> = Record<string, Any>> =
  495. | {
  496. create: SanityDocumentStub<R>
  497. }
  498. | {
  499. createOrReplace: IdentifiedSanityDocumentStub<R>
  500. }
  501. | {
  502. createIfNotExists: IdentifiedSanityDocumentStub<R>
  503. }
  504. | {
  505. delete: MutationSelection
  506. }
  507. | {
  508. patch: PatchMutationOperation
  509. }
  510. /** @internal */
  511. export declare interface MutationError {
  512. error: {
  513. type: 'mutationError'
  514. description: string
  515. items?: MutationErrorItem[]
  516. }
  517. }
  518. /** @internal */
  519. export declare interface MutationErrorItem {
  520. error: {
  521. type: string
  522. description: string
  523. value?: unknown
  524. }
  525. }
  526. /** @public */
  527. declare type MutationEvent_2<R extends Record<string, Any> = Record<string, Any>> = {
  528. type: 'mutation'
  529. documentId: string
  530. eventId: string
  531. identity: string
  532. mutations: Mutation[]
  533. previousRev?: string
  534. resultRev?: string
  535. result?: SanityDocument<R>
  536. previous?: SanityDocument<R> | null
  537. effects?: {
  538. apply: unknown[]
  539. revert: unknown[]
  540. }
  541. timestamp: string
  542. transactionId: string
  543. transition: 'update' | 'appear' | 'disappear'
  544. visibility: 'query' | 'transaction'
  545. }
  546. export {MutationEvent_2 as MutationEvent}
  547. /** @internal */
  548. export declare type MutationOperation = 'create' | 'delete' | 'update' | 'none'
  549. /** @internal */
  550. export declare type MutationSelection =
  551. | {
  552. query: string
  553. params?: QueryParams
  554. }
  555. | {
  556. id: string | string[]
  557. }
  558. /** @internal */
  559. export declare class ObservableAssetsClient {
  560. #private
  561. constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
  562. /**
  563. * Uploads a file asset to the configured dataset
  564. *
  565. * @param assetType - Asset type (file)
  566. * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
  567. * @param options - Options to use for the upload
  568. */
  569. upload(
  570. assetType: 'file',
  571. body: UploadBody,
  572. options?: UploadClientConfig
  573. ): Observable<
  574. HttpRequestEvent<{
  575. document: SanityAssetDocument
  576. }>
  577. >
  578. /**
  579. * Uploads an image asset to the configured dataset
  580. *
  581. * @param assetType - Asset type (image)
  582. * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
  583. * @param options - Options to use for the upload
  584. */
  585. upload(
  586. assetType: 'image',
  587. body: UploadBody,
  588. options?: UploadClientConfig
  589. ): Observable<
  590. HttpRequestEvent<{
  591. document: SanityImageAssetDocument
  592. }>
  593. >
  594. /**
  595. * Uploads a file or an image asset to the configured dataset
  596. *
  597. * @param assetType - Asset type (file/image)
  598. * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
  599. * @param options - Options to use for the upload
  600. */
  601. upload(
  602. assetType: 'file' | 'image',
  603. body: UploadBody,
  604. options?: UploadClientConfig
  605. ): Observable<
  606. HttpRequestEvent<{
  607. document: SanityAssetDocument | SanityImageAssetDocument
  608. }>
  609. >
  610. }
  611. /** @internal */
  612. export declare class ObservableDatasetsClient {
  613. #private
  614. constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
  615. /**
  616. * Create a new dataset with the given name
  617. *
  618. * @param name - Name of the dataset to create
  619. * @param options - Options for the dataset
  620. */
  621. create(
  622. name: string,
  623. options?: {
  624. aclMode?: DatasetAclMode
  625. }
  626. ): Observable<DatasetResponse>
  627. /**
  628. * Edit a dataset with the given name
  629. *
  630. * @param name - Name of the dataset to edit
  631. * @param options - New options for the dataset
  632. */
  633. edit(
  634. name: string,
  635. options?: {
  636. aclMode?: DatasetAclMode
  637. }
  638. ): Observable<DatasetResponse>
  639. /**
  640. * Delete a dataset with the given name
  641. *
  642. * @param name - Name of the dataset to delete
  643. */
  644. delete(name: string): Observable<{
  645. deleted: true
  646. }>
  647. /**
  648. * Fetch a list of datasets for the configured project
  649. */
  650. list(): Observable<DatasetsResponse>
  651. }
  652. /** @public */
  653. export declare class ObservablePatch extends BasePatch {
  654. #private
  655. constructor(
  656. selection: PatchSelection,
  657. operations?: PatchOperations,
  658. client?: ObservableSanityClient
  659. )
  660. /**
  661. * Clones the patch
  662. */
  663. clone(): ObservablePatch
  664. /**
  665. * Commit the patch, returning an observable that produces the first patched document
  666. *
  667. * @param options - Options for the mutation operation
  668. */
  669. commit<R extends Record<string, Any> = Record<string, Any>>(
  670. options: FirstDocumentMutationOptions
  671. ): Observable<SanityDocument<R>>
  672. /**
  673. * Commit the patch, returning an observable that produces an array of the mutated documents
  674. *
  675. * @param options - Options for the mutation operation
  676. */
  677. commit<R extends Record<string, Any> = Record<string, Any>>(
  678. options: AllDocumentsMutationOptions
  679. ): Observable<SanityDocument<R>[]>
  680. /**
  681. * Commit the patch, returning an observable that produces a mutation result object
  682. *
  683. * @param options - Options for the mutation operation
  684. */
  685. commit(options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
  686. /**
  687. * Commit the patch, returning an observable that produces a mutation result object
  688. *
  689. * @param options - Options for the mutation operation
  690. */
  691. commit(options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
  692. /**
  693. * Commit the patch, returning an observable that produces the first patched document
  694. *
  695. * @param options - Options for the mutation operation
  696. */
  697. commit<R extends Record<string, Any> = Record<string, Any>>(
  698. options?: BaseMutationOptions
  699. ): Observable<SanityDocument<R>>
  700. }
  701. /** @public */
  702. export declare type ObservablePatchBuilder = (patch: ObservablePatch) => ObservablePatch
  703. /** @internal */
  704. export declare class ObservableProjectsClient {
  705. #private
  706. constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
  707. /**
  708. * Fetch a list of projects the authenticated user has access to
  709. */
  710. list(): Observable<SanityProject[]>
  711. /**
  712. * Fetch a project by project ID
  713. *
  714. * @param projectId - ID of the project to fetch
  715. */
  716. getById(projectId: string): Observable<SanityProject>
  717. }
  718. /** @public */
  719. export declare class ObservableSanityClient {
  720. #private
  721. assets: ObservableAssetsClient
  722. datasets: ObservableDatasetsClient
  723. projects: ObservableProjectsClient
  724. users: ObservableUsersClient
  725. /**
  726. * Instance properties
  727. */
  728. listen: typeof _listen
  729. constructor(httpRequest: HttpRequest, config?: ClientConfig)
  730. /**
  731. * Clone the client - returns a new instance
  732. */
  733. clone(): ObservableSanityClient
  734. /**
  735. * Returns the current client configuration
  736. */
  737. config(): InitializedClientConfig
  738. /**
  739. * Reconfigure the client. Note that this _mutates_ the current client.
  740. */
  741. config(newConfig?: Partial<ClientConfig>): this
  742. /**
  743. * Clone the client with a new (partial) configuration.
  744. *
  745. * @param newConfig - New client configuration properties, shallowly merged with existing configuration
  746. */
  747. withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityClient
  748. /**
  749. * Perform a GROQ-query against the configured dataset.
  750. *
  751. * @param query - GROQ-query to perform
  752. */
  753. fetch<R = Any>(query: string): Observable<R>
  754. /**
  755. * Perform a GROQ-query against the configured dataset.
  756. *
  757. * @param query - GROQ-query to perform
  758. * @param params - Query parameters
  759. */
  760. fetch<R = Any, Q = QueryParams>(query: string, params: Q): Observable<R>
  761. /**
  762. * Perform a GROQ-query against the configured dataset.
  763. *
  764. * @param query - GROQ-query to perform
  765. * @param params - Query parameters
  766. * @param options - Request options
  767. */
  768. fetch<R = Any, Q = QueryParams>(
  769. query: string,
  770. params: Q | undefined,
  771. options: FilteredResponseQueryOptions
  772. ): Observable<R>
  773. /**
  774. * Perform a GROQ-query against the configured dataset.
  775. *
  776. * @param query - GROQ-query to perform
  777. * @param params - Query parameters
  778. * @param options - Request options
  779. */
  780. fetch<R = Any, Q = QueryParams>(
  781. query: string,
  782. params: Q | undefined,
  783. options: UnfilteredResponseQueryOptions
  784. ): Observable<RawQueryResponse<R>>
  785. /**
  786. * Fetch a single document with the given ID.
  787. *
  788. * @param id - Document ID to fetch
  789. * @param options - Request options
  790. */
  791. getDocument<R extends Record<string, Any> = Record<string, Any>>(
  792. id: string,
  793. options?: {
  794. tag?: string
  795. }
  796. ): Observable<SanityDocument<R> | undefined>
  797. /**
  798. * Fetch multiple documents in one request.
  799. * Should be used sparingly - performing a query is usually a better option.
  800. * The order/position of documents is preserved based on the original array of IDs.
  801. * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
  802. *
  803. * @param ids - Document IDs to fetch
  804. * @param options - Request options
  805. */
  806. getDocuments<R extends Record<string, Any> = Record<string, Any>>(
  807. ids: string[],
  808. options?: {
  809. tag?: string
  810. }
  811. ): Observable<(SanityDocument<R> | null)[]>
  812. /**
  813. * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
  814. * Returns an observable that resolves to the created document.
  815. *
  816. * @param document - Document to create
  817. * @param options - Mutation options
  818. */
  819. create<R extends Record<string, Any> = Record<string, Any>>(
  820. document: SanityDocumentStub<R>,
  821. options: FirstDocumentMutationOptions
  822. ): Observable<SanityDocument<R>>
  823. /**
  824. * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
  825. * Returns an observable that resolves to an array containing the created document.
  826. *
  827. * @param document - Document to create
  828. * @param options - Mutation options
  829. */
  830. create<R extends Record<string, Any> = Record<string, Any>>(
  831. document: SanityDocumentStub<R>,
  832. options: AllDocumentsMutationOptions
  833. ): Observable<SanityDocument<R>[]>
  834. /**
  835. * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
  836. * Returns an observable that resolves to a mutation result object containing the ID of the created document.
  837. *
  838. * @param document - Document to create
  839. * @param options - Mutation options
  840. */
  841. create<R extends Record<string, Any> = Record<string, Any>>(
  842. document: SanityDocumentStub<R>,
  843. options: FirstDocumentIdMutationOptions
  844. ): Observable<SingleMutationResult>
  845. /**
  846. * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
  847. * Returns an observable that resolves to a mutation result object containing the ID of the created document.
  848. *
  849. * @param document - Document to create
  850. * @param options - Mutation options
  851. */
  852. create<R extends Record<string, Any> = Record<string, Any>>(
  853. document: SanityDocumentStub<R>,
  854. options: AllDocumentIdsMutationOptions
  855. ): Observable<MultipleMutationResult>
  856. /**
  857. * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
  858. * Returns an observable that resolves to the created document.
  859. *
  860. * @param document - Document to create
  861. * @param options - Mutation options
  862. */
  863. create<R extends Record<string, Any> = Record<string, Any>>(
  864. document: SanityDocumentStub<R>,
  865. options?: BaseMutationOptions
  866. ): Observable<SanityDocument<R>>
  867. /**
  868. * Create a document if no document with the same ID already exists.
  869. * Returns an observable that resolves to the created document.
  870. *
  871. * @param document - Document to create
  872. * @param options - Mutation options
  873. */
  874. createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
  875. document: IdentifiedSanityDocumentStub<R>,
  876. options: FirstDocumentMutationOptions
  877. ): Observable<SanityDocument<R>>
  878. /**
  879. * Create a document if no document with the same ID already exists.
  880. * Returns an observable that resolves to an array containing the created document.
  881. *
  882. * @param document - Document to create
  883. * @param options - Mutation options
  884. */
  885. createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
  886. document: IdentifiedSanityDocumentStub<R>,
  887. options: AllDocumentsMutationOptions
  888. ): Observable<SanityDocument<R>[]>
  889. /**
  890. * Create a document if no document with the same ID already exists.
  891. * Returns an observable that resolves to a mutation result object containing the ID of the created document.
  892. *
  893. * @param document - Document to create
  894. * @param options - Mutation options
  895. */
  896. createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
  897. document: IdentifiedSanityDocumentStub<R>,
  898. options: FirstDocumentIdMutationOptions
  899. ): Observable<SingleMutationResult>
  900. /**
  901. * Create a document if no document with the same ID already exists.
  902. * Returns an observable that resolves to a mutation result object containing the ID of the created document.
  903. *
  904. * @param document - Document to create
  905. * @param options - Mutation options
  906. */
  907. createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
  908. document: IdentifiedSanityDocumentStub<R>,
  909. options: AllDocumentIdsMutationOptions
  910. ): Observable<MultipleMutationResult>
  911. /**
  912. * Create a document if no document with the same ID already exists.
  913. * Returns an observable that resolves to the created document.
  914. *
  915. * @param document - Document to create
  916. * @param options - Mutation options
  917. */
  918. createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
  919. document: IdentifiedSanityDocumentStub<R>,
  920. options?: BaseMutationOptions
  921. ): Observable<SanityDocument<R>>
  922. /**
  923. * Create a document if it does not exist, or replace a document with the same document ID
  924. * Returns an observable that resolves to the created document.
  925. *
  926. * @param document - Document to either create or replace
  927. * @param options - Mutation options
  928. */
  929. createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
  930. document: IdentifiedSanityDocumentStub<R>,
  931. options: FirstDocumentMutationOptions
  932. ): Observable<SanityDocument<R>>
  933. /**
  934. * Create a document if it does not exist, or replace a document with the same document ID
  935. * Returns an observable that resolves to an array containing the created document.
  936. *
  937. * @param document - Document to either create or replace
  938. * @param options - Mutation options
  939. */
  940. createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
  941. document: IdentifiedSanityDocumentStub<R>,
  942. options: AllDocumentsMutationOptions
  943. ): Observable<SanityDocument<R>[]>
  944. /**
  945. * Create a document if it does not exist, or replace a document with the same document ID
  946. * Returns an observable that resolves to a mutation result object containing the ID of the created document.
  947. *
  948. * @param document - Document to either create or replace
  949. * @param options - Mutation options
  950. */
  951. createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
  952. document: IdentifiedSanityDocumentStub<R>,
  953. options: FirstDocumentIdMutationOptions
  954. ): Observable<SingleMutationResult>
  955. /**
  956. * Create a document if it does not exist, or replace a document with the same document ID
  957. * Returns an observable that resolves to a mutation result object containing the created document ID.
  958. *
  959. * @param document - Document to either create or replace
  960. * @param options - Mutation options
  961. */
  962. createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
  963. document: IdentifiedSanityDocumentStub<R>,
  964. options: AllDocumentIdsMutationOptions
  965. ): Observable<MultipleMutationResult>
  966. /**
  967. * Create a document if it does not exist, or replace a document with the same document ID
  968. * Returns an observable that resolves to the created document.
  969. *
  970. * @param document - Document to either create or replace
  971. * @param options - Mutation options
  972. */
  973. createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
  974. document: IdentifiedSanityDocumentStub<R>,
  975. options?: BaseMutationOptions
  976. ): Observable<SanityDocument<R>>
  977. /**
  978. * Deletes a document with the given document ID.
  979. * Returns an observable that resolves to the deleted document.
  980. *
  981. * @param id - Document ID to delete
  982. * @param options - Options for the mutation
  983. */
  984. delete<R extends Record<string, Any> = Record<string, Any>>(
  985. id: string,
  986. options: FirstDocumentMutationOptions
  987. ): Observable<SanityDocument<R>>
  988. /**
  989. * Deletes a document with the given document ID.
  990. * Returns an observable that resolves to an array containing the deleted document.
  991. *
  992. * @param id - Document ID to delete
  993. * @param options - Options for the mutation
  994. */
  995. delete<R extends Record<string, Any> = Record<string, Any>>(
  996. id: string,
  997. options: AllDocumentsMutationOptions
  998. ): Observable<SanityDocument<R>[]>
  999. /**
  1000. * Deletes a document with the given document ID.
  1001. * Returns an observable that resolves to a mutation result object containing the deleted document ID.
  1002. *
  1003. * @param id - Document ID to delete
  1004. * @param options - Options for the mutation
  1005. */
  1006. delete(id: string, options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
  1007. /**
  1008. * Deletes a document with the given document ID.
  1009. * Returns an observable that resolves to a mutation result object containing the deleted document ID.
  1010. *
  1011. * @param id - Document ID to delete
  1012. * @param options - Options for the mutation
  1013. */
  1014. delete(id: string, options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
  1015. /**
  1016. * Deletes a document with the given document ID.
  1017. * Returns an observable that resolves to the deleted document.
  1018. *
  1019. * @param id - Document ID to delete
  1020. * @param options - Options for the mutation
  1021. */
  1022. delete<R extends Record<string, Any> = Record<string, Any>>(
  1023. id: string,
  1024. options?: BaseMutationOptions
  1025. ): Observable<SanityDocument<R>>
  1026. /**
  1027. * Deletes one or more documents matching the given query or document ID.
  1028. * Returns an observable that resolves to first deleted document.
  1029. *
  1030. * @param selection - An object with either an `id` or `query` key defining what to delete
  1031. * @param options - Options for the mutation
  1032. */
  1033. delete<R extends Record<string, Any> = Record<string, Any>>(
  1034. selection: MutationSelection,
  1035. options: FirstDocumentMutationOptions
  1036. ): Observable<SanityDocument<R>>
  1037. /**
  1038. * Deletes one or more documents matching the given query or document ID.
  1039. * Returns an observable that resolves to an array containing the deleted documents.
  1040. *
  1041. * @param selection - An object with either an `id` or `query` key defining what to delete
  1042. * @param options - Options for the mutation
  1043. */
  1044. delete<R extends Record<string, Any> = Record<string, Any>>(
  1045. selection: MutationSelection,
  1046. options: AllDocumentsMutationOptions
  1047. ): Observable<SanityDocument<R>[]>
  1048. /**
  1049. * Deletes one or more documents matching the given query or document ID.
  1050. * Returns an observable that resolves to a mutation result object containing the ID of the first deleted document.
  1051. *
  1052. * @param selection - An object with either an `id` or `query` key defining what to delete
  1053. * @param options - Options for the mutation
  1054. */
  1055. delete(
  1056. selection: MutationSelection,
  1057. options: FirstDocumentIdMutationOptions
  1058. ): Observable<SingleMutationResult>
  1059. /**
  1060. * Deletes one or more documents matching the given query or document ID.
  1061. * Returns an observable that resolves to a mutation result object containing the document IDs that were deleted.
  1062. *
  1063. * @param selection - An object with either an `id` or `query` key defining what to delete
  1064. * @param options - Options for the mutation
  1065. */
  1066. delete(
  1067. selection: MutationSelection,
  1068. options: AllDocumentIdsMutationOptions
  1069. ): Observable<MultipleMutationResult>
  1070. /**
  1071. * Deletes one or more documents matching the given query or document ID.
  1072. * Returns an observable that resolves to first deleted document.
  1073. *
  1074. * @param selection - An object with either an `id` or `query` key defining what to delete
  1075. * @param options - Options for the mutation
  1076. */
  1077. delete<R extends Record<string, Any> = Record<string, Any>>(
  1078. selection: MutationSelection,
  1079. options?: BaseMutationOptions
  1080. ): Observable<SanityDocument<R>>
  1081. /**
  1082. * Perform mutation operations against the configured dataset
  1083. * Returns an observable that resolves to the first mutated document.
  1084. *
  1085. * @param operations - Mutation operations to execute
  1086. * @param options - Mutation options
  1087. */
  1088. mutate<R extends Record<string, Any> = Record<string, Any>>(
  1089. operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
  1090. options: FirstDocumentMutationOptions
  1091. ): Observable<SanityDocument<R>>
  1092. /**
  1093. * Perform mutation operations against the configured dataset.
  1094. * Returns an observable that resolves to an array of the mutated documents.
  1095. *
  1096. * @param operations - Mutation operations to execute
  1097. * @param options - Mutation options
  1098. */
  1099. mutate<R extends Record<string, Any> = Record<string, Any>>(
  1100. operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
  1101. options: AllDocumentsMutationOptions
  1102. ): Observable<SanityDocument<R>[]>
  1103. /**
  1104. * Perform mutation operations against the configured dataset
  1105. * Returns an observable that resolves to a mutation result object containing the document ID of the first mutated document.
  1106. *
  1107. * @param operations - Mutation operations to execute
  1108. * @param options - Mutation options
  1109. */
  1110. mutate<R extends Record<string, Any> = Record<string, Any>>(
  1111. operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
  1112. options: FirstDocumentIdMutationOptions
  1113. ): Observable<SingleMutationResult>
  1114. /**
  1115. * Perform mutation operations against the configured dataset
  1116. * Returns an observable that resolves to a mutation result object containing the mutated document IDs.
  1117. *
  1118. * @param operations - Mutation operations to execute
  1119. * @param options - Mutation options
  1120. */
  1121. mutate<R extends Record<string, Any> = Record<string, Any>>(
  1122. operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
  1123. options: AllDocumentIdsMutationOptions
  1124. ): Observable<MultipleMutationResult>
  1125. /**
  1126. * Perform mutation operations against the configured dataset
  1127. * Returns an observable that resolves to the first mutated document.
  1128. *
  1129. * @param operations - Mutation operations to execute
  1130. * @param options - Mutation options
  1131. */
  1132. mutate<R extends Record<string, Any> = Record<string, Any>>(
  1133. operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
  1134. options?: BaseMutationOptions
  1135. ): Observable<SanityDocument<R>>
  1136. /**
  1137. * Create a new buildable patch of operations to perform
  1138. *
  1139. * @param documentId - Document ID(s) to patch
  1140. * @param operations - Optional object of patch operations to initialize the patch instance with
  1141. */
  1142. patch(documentId: PatchSelection, operations?: PatchOperations): ObservablePatch
  1143. /**
  1144. * Create a new transaction of mutations
  1145. *
  1146. * @param operations - Optional array of mutation operations to initialize the transaction instance with
  1147. */
  1148. transaction<R extends Record<string, Any> = Record<string, Any>>(
  1149. operations?: Mutation<R>[]
  1150. ): ObservableTransaction
  1151. /**
  1152. * DEPRECATED: Perform an HTTP request against the Sanity API
  1153. *
  1154. * @deprecated Use your own request library!
  1155. * @param options - Request options
  1156. */
  1157. request<R = Any>(options: RawRequestOptions): Observable<R>
  1158. /**
  1159. * Get a Sanity API URL for the URI provided
  1160. *
  1161. * @param uri - URI/path to build URL for
  1162. * @param canUseCdn - Whether or not to allow using the API CDN for this route
  1163. */
  1164. getUrl(uri: string, canUseCdn?: boolean): string
  1165. /**
  1166. * Get a Sanity API URL for the data operation and path provided
  1167. *
  1168. * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
  1169. * @param path - Path to append after the operation
  1170. */
  1171. getDataUrl(operation: string, path?: string): string
  1172. }
  1173. /** @public */
  1174. export declare class ObservableTransaction extends BaseTransaction {
  1175. #private
  1176. constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
  1177. /**
  1178. * Clones the transaction
  1179. */
  1180. clone(): ObservableTransaction
  1181. /**
  1182. * Commit the transaction, returning an observable that produces the first mutated document
  1183. *
  1184. * @param options - Options for the mutation operation
  1185. */
  1186. commit<R extends Record<string, Any>>(
  1187. options: TransactionFirstDocumentMutationOptions
  1188. ): Observable<SanityDocument<R>>
  1189. /**
  1190. * Commit the transaction, returning an observable that produces an array of the mutated documents
  1191. *
  1192. * @param options - Options for the mutation operation
  1193. */
  1194. commit<R extends Record<string, Any>>(
  1195. options: TransactionAllDocumentsMutationOptions
  1196. ): Observable<SanityDocument<R>[]>
  1197. /**
  1198. * Commit the transaction, returning an observable that produces a mutation result object
  1199. *
  1200. * @param options - Options for the mutation operation
  1201. */
  1202. commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
  1203. /**
  1204. * Commit the transaction, returning an observable that produces a mutation result object
  1205. *
  1206. * @param options - Options for the mutation operation
  1207. */
  1208. commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
  1209. /**
  1210. * Commit the transaction, returning an observable that produces a mutation result object
  1211. *
  1212. * @param options - Options for the mutation operation
  1213. */
  1214. commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
  1215. /**
  1216. * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
  1217. * The operation is added to the current transaction, ready to be commited by `commit()`
  1218. *
  1219. * @param documentId - Document ID to perform the patch operation on
  1220. * @param patchOps - Operations to perform, or a builder function
  1221. */
  1222. patch(documentId: string, patchOps?: ObservablePatchBuilder | PatchOperations): this
  1223. /**
  1224. * Adds the given patch instance to the transaction.
  1225. * The operation is added to the current transaction, ready to be commited by `commit()`
  1226. *
  1227. * @param patch - ObservablePatch to execute
  1228. */
  1229. patch(patch: ObservablePatch): this
  1230. }
  1231. /** @public */
  1232. export declare class ObservableUsersClient {
  1233. #private
  1234. constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
  1235. /**
  1236. * Fetch a user by user ID
  1237. *
  1238. * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
  1239. */
  1240. getById<T extends 'me' | string>(
  1241. id: T
  1242. ): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
  1243. }
  1244. /** @public */
  1245. export declare class Patch extends BasePatch {
  1246. #private
  1247. constructor(selection: PatchSelection, operations?: PatchOperations, client?: SanityClient)
  1248. /**
  1249. * Clones the patch
  1250. */
  1251. clone(): Patch
  1252. /**
  1253. * Commit the patch, returning a promise that resolves to the first patched document
  1254. *
  1255. * @param options - Options for the mutation operation
  1256. */
  1257. commit<R extends Record<string, Any> = Record<string, Any>>(
  1258. options: FirstDocumentMutationOptions
  1259. ): Promise<SanityDocument<R>>
  1260. /**
  1261. * Commit the patch, returning a promise that resolves to an array of the mutated documents
  1262. *
  1263. * @param options - Options for the mutation operation
  1264. */
  1265. commit<R extends Record<string, Any> = Record<string, Any>>(
  1266. options: AllDocumentsMutationOptions
  1267. ): Promise<SanityDocument<R>[]>
  1268. /**
  1269. * Commit the patch, returning a promise that resolves to a mutation result object
  1270. *
  1271. * @param options - Options for the mutation operation
  1272. */
  1273. commit(options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
  1274. /**
  1275. * Commit the patch, returning a promise that resolves to a mutation result object
  1276. *
  1277. * @param options - Options for the mutation operation
  1278. */
  1279. commit(options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
  1280. /**
  1281. * Commit the patch, returning a promise that resolves to the first patched document
  1282. *
  1283. * @param options - Options for the mutation operation
  1284. */
  1285. commit<R extends Record<string, Any> = Record<string, Any>>(
  1286. options?: BaseMutationOptions
  1287. ): Promise<SanityDocument<R>>
  1288. }
  1289. /** @public */
  1290. export declare type PatchBuilder = (patch: Patch) => Patch
  1291. /** @internal */
  1292. export declare type PatchMutationOperation = PatchOperations & MutationSelection
  1293. /** @internal */
  1294. export declare interface PatchOperations {
  1295. set?: {
  1296. [key: string]: Any
  1297. }
  1298. setIfMissing?: {
  1299. [key: string]: Any
  1300. }
  1301. diffMatchPatch?: {
  1302. [key: string]: Any
  1303. }
  1304. unset?: string[]
  1305. inc?: {
  1306. [key: string]: number
  1307. }
  1308. dec?: {
  1309. [key: string]: number
  1310. }
  1311. insert?: InsertPatch
  1312. ifRevisionID?: string
  1313. }
  1314. /** @internal */
  1315. export declare type PatchSelection = string | string[] | MutationSelection
  1316. /** @public */
  1317. declare interface ProgressEvent_2 {
  1318. type: 'progress'
  1319. stage: 'upload' | 'download'
  1320. percent: number
  1321. total?: number
  1322. loaded?: number
  1323. lengthComputable: boolean
  1324. }
  1325. export {ProgressEvent_2 as ProgressEvent}
  1326. /** @internal */
  1327. export declare class ProjectsClient {
  1328. #private
  1329. constructor(client: SanityClient, httpRequest: HttpRequest)
  1330. /**
  1331. * Fetch a list of projects the authenticated user has access to
  1332. */
  1333. list(): Promise<SanityProject[]>
  1334. /**
  1335. * Fetch a project by project ID
  1336. *
  1337. * @param projectId - ID of the project to fetch
  1338. */
  1339. getById(projectId: string): Promise<SanityProject>
  1340. }
  1341. /** @public */
  1342. export declare type QueryParams = {
  1343. [key: string]: Any
  1344. }
  1345. /** @internal */
  1346. export declare interface RawQueryResponse<R> {
  1347. q: string
  1348. ms: number
  1349. result: R
  1350. }
  1351. /** @internal */
  1352. export declare interface RawRequestOptions {
  1353. url?: string
  1354. uri?: string
  1355. method?: string
  1356. token?: string
  1357. json?: boolean
  1358. tag?: string
  1359. useGlobalApi?: boolean
  1360. withCredentials?: boolean
  1361. query?: {
  1362. [key: string]: string | string[]
  1363. }
  1364. headers?: {
  1365. [key: string]: string
  1366. }
  1367. timeout?: number
  1368. proxy?: string
  1369. body?: Any
  1370. maxRedirects?: number
  1371. }
  1372. /** @public */
  1373. export declare type ReconnectEvent = {
  1374. type: 'reconnect'
  1375. }
  1376. /** @public */
  1377. export declare const requester: Requester
  1378. /** @internal */
  1379. export declare interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
  1380. url?: string
  1381. uri?: string
  1382. canUseCdn?: boolean
  1383. tag?: string
  1384. }
  1385. /** @public */
  1386. export declare interface RequestOptions {
  1387. timeout?: number
  1388. token?: string
  1389. tag?: string
  1390. headers?: Record<string, string>
  1391. method?: string
  1392. query?: Any
  1393. body?: Any
  1394. signal?: AbortSignal
  1395. }
  1396. /** @public */
  1397. export declare interface ResponseEvent<T = unknown> {
  1398. type: 'response'
  1399. body: T
  1400. url: string
  1401. method: string
  1402. statusCode: number
  1403. statusMessage?: string
  1404. headers: Record<string, string>
  1405. }
  1406. /** @internal */
  1407. export declare interface SanityAssetDocument extends SanityDocument {
  1408. url: string
  1409. path: string
  1410. size: number
  1411. assetId: string
  1412. mimeType: string
  1413. sha1hash: string
  1414. extension: string
  1415. uploadId?: string
  1416. originalFilename?: string
  1417. }
  1418. /** @public */
  1419. export declare class SanityClient {
  1420. #private
  1421. assets: AssetsClient
  1422. datasets: DatasetsClient
  1423. projects: ProjectsClient
  1424. users: UsersClient
  1425. /**
  1426. * Observable version of the Sanity client, with the same configuration as the promise-based one
  1427. */
  1428. observable: ObservableSanityClient
  1429. /**
  1430. * Instance properties
  1431. */
  1432. listen: typeof _listen
  1433. constructor(httpRequest: HttpRequest, config?: ClientConfig)
  1434. /**
  1435. * Clone the client - returns a new instance
  1436. */
  1437. clone(): SanityClient
  1438. /**
  1439. * Returns the current client configuration
  1440. */
  1441. config(): InitializedClientConfig
  1442. /**
  1443. * Reconfigure the client. Note that this _mutates_ the current client.
  1444. */
  1445. config(newConfig?: Partial<ClientConfig>): this
  1446. /**
  1447. * Clone the client with a new (partial) configuration.
  1448. *
  1449. * @param newConfig - New client configuration properties, shallowly merged with existing configuration
  1450. */
  1451. withConfig(newConfig?: Partial<ClientConfig>): SanityClient
  1452. /**
  1453. * Perform a GROQ-query against the configured dataset.
  1454. *
  1455. * @param query - GROQ-query to perform
  1456. */
  1457. fetch<R = Any>(query: string): Promise<R>
  1458. /**
  1459. * Perform a GROQ-query against the configured dataset.
  1460. *
  1461. * @param query - GROQ-query to perform
  1462. * @param params - Optional query parameters
  1463. */
  1464. fetch<R = Any, Q = QueryParams>(query: string, params: Q): Promise<R>
  1465. /**
  1466. * Perform a GROQ-query against the configured dataset.
  1467. *
  1468. * @param query - GROQ-query to perform
  1469. * @param params - Optional query parameters
  1470. * @param options - Request options
  1471. */
  1472. fetch<R = Any, Q = QueryParams>(
  1473. query: string,
  1474. params: Q | undefined,
  1475. options: FilteredResponseQueryOptions
  1476. ): Promise<R>
  1477. /**
  1478. * Perform a GROQ-query against the configured dataset.
  1479. *
  1480. * @param query - GROQ-query to perform
  1481. * @param params - Optional query parameters
  1482. * @param options - Request options
  1483. */
  1484. fetch<R = Any, Q = QueryParams>(
  1485. query: string,
  1486. params: Q | undefined,
  1487. options: UnfilteredResponseQueryOptions
  1488. ): Promise<RawQueryResponse<R>>
  1489. /**
  1490. * Fetch a single document with the given ID.
  1491. *
  1492. * @param id - Document ID to fetch
  1493. * @param options - Request options
  1494. */
  1495. getDocument<R extends Record<string, Any> = Record<string, Any>>(
  1496. id: string,
  1497. options?: {
  1498. tag?: string
  1499. }
  1500. ): Promise<SanityDocument<R> | undefined>
  1501. /**
  1502. * Fetch multiple documents in one request.
  1503. * Should be used sparingly - performing a query is usually a better option.
  1504. * The order/position of documents is preserved based on the original array of IDs.
  1505. * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
  1506. *
  1507. * @param ids - Document IDs to fetch
  1508. * @param options - Request options
  1509. */
  1510. getDocuments<R extends Record<string, Any> = Record<string, Any>>(
  1511. ids: string[],
  1512. options?: {
  1513. tag?: string
  1514. }
  1515. ): Promise<(SanityDocument<R> | null)[]>
  1516. /**
  1517. * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
  1518. * Returns a promise that resolves to the created document.
  1519. *
  1520. * @param document - Document to create
  1521. * @param options - Mutation options
  1522. */
  1523. create<R extends Record<string, Any> = Record<string, Any>>(
  1524. document: SanityDocumentStub<R>,
  1525. options: FirstDocumentMutationOptions
  1526. ): Promise<SanityDocument<R>>
  1527. /**
  1528. * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
  1529. * Returns a promise that resolves to an array containing the created document.
  1530. *
  1531. * @param document - Document to create
  1532. * @param options - Mutation options
  1533. */
  1534. create<R extends Record<string, Any> = Record<string, Any>>(
  1535. document: SanityDocumentStub<R>,
  1536. options: AllDocumentsMutationOptions
  1537. ): Promise<SanityDocument<R>[]>
  1538. /**
  1539. * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
  1540. * Returns a promise that resolves to a mutation result object containing the ID of the created document.
  1541. *
  1542. * @param document - Document to create
  1543. * @param options - Mutation options
  1544. */
  1545. create<R extends Record<string, Any> = Record<string, Any>>(
  1546. document: SanityDocumentStub<R>,
  1547. options: FirstDocumentIdMutationOptions
  1548. ): Promise<SingleMutationResult>
  1549. /**
  1550. * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
  1551. * Returns a promise that resolves to a mutation result object containing the ID of the created document.
  1552. *
  1553. * @param document - Document to create
  1554. * @param options - Mutation options
  1555. */
  1556. create<R extends Record<string, Any> = Record<string, Any>>(
  1557. document: SanityDocumentStub<R>,
  1558. options: AllDocumentIdsMutationOptions
  1559. ): Promise<MultipleMutationResult>
  1560. /**
  1561. * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
  1562. * Returns a promise that resolves to the created document.
  1563. *
  1564. * @param document - Document to create
  1565. * @param options - Mutation options
  1566. */
  1567. create<R extends Record<string, Any> = Record<string, Any>>(
  1568. document: SanityDocumentStub<R>,
  1569. options?: BaseMutationOptions
  1570. ): Promise<SanityDocument<R>>
  1571. /**
  1572. * Create a document if no document with the same ID already exists.
  1573. * Returns a promise that resolves to the created document.
  1574. *
  1575. * @param document - Document to create
  1576. * @param options - Mutation options
  1577. */
  1578. createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
  1579. document: IdentifiedSanityDocumentStub<R>,
  1580. options: FirstDocumentMutationOptions
  1581. ): Promise<SanityDocument<R>>
  1582. /**
  1583. * Create a document if no document with the same ID already exists.
  1584. * Returns a promise that resolves to an array containing the created document.
  1585. *
  1586. * @param document - Document to create
  1587. * @param options - Mutation options
  1588. */
  1589. createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
  1590. document: IdentifiedSanityDocumentStub<R>,
  1591. options: AllDocumentsMutationOptions
  1592. ): Promise<SanityDocument<R>[]>
  1593. /**
  1594. * Create a document if no document with the same ID already exists.
  1595. * Returns a promise that resolves to a mutation result object containing the ID of the created document.
  1596. *
  1597. * @param document - Document to create
  1598. * @param options - Mutation options
  1599. */
  1600. createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
  1601. document: IdentifiedSanityDocumentStub<R>,
  1602. options: FirstDocumentIdMutationOptions
  1603. ): Promise<SingleMutationResult>
  1604. /**
  1605. * Create a document if no document with the same ID already exists.
  1606. * Returns a promise that resolves to a mutation result object containing the ID of the created document.
  1607. *
  1608. * @param document - Document to create
  1609. * @param options - Mutation options
  1610. */
  1611. createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
  1612. document: IdentifiedSanityDocumentStub<R>,
  1613. options: AllDocumentIdsMutationOptions
  1614. ): Promise<MultipleMutationResult>
  1615. /**
  1616. * Create a document if no document with the same ID already exists.
  1617. * Returns a promise that resolves to the created document.
  1618. *
  1619. * @param document - Document to create
  1620. * @param options - Mutation options
  1621. */
  1622. createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
  1623. document: IdentifiedSanityDocumentStub<R>,
  1624. options?: BaseMutationOptions
  1625. ): Promise<SanityDocument<R>>
  1626. /**
  1627. * Create a document if it does not exist, or replace a document with the same document ID
  1628. * Returns a promise that resolves to the created document.
  1629. *
  1630. * @param document - Document to either create or replace
  1631. * @param options - Mutation options
  1632. */
  1633. createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
  1634. document: IdentifiedSanityDocumentStub<R>,
  1635. options: FirstDocumentMutationOptions
  1636. ): Promise<SanityDocument<R>>
  1637. /**
  1638. * Create a document if it does not exist, or replace a document with the same document ID
  1639. * Returns a promise that resolves to an array containing the created document.
  1640. *
  1641. * @param document - Document to either create or replace
  1642. * @param options - Mutation options
  1643. */
  1644. createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
  1645. document: IdentifiedSanityDocumentStub<R>,
  1646. options: AllDocumentsMutationOptions
  1647. ): Promise<SanityDocument<R>[]>
  1648. /**
  1649. * Create a document if it does not exist, or replace a document with the same document ID
  1650. * Returns a promise that resolves to a mutation result object containing the ID of the created document.
  1651. *
  1652. * @param document - Document to either create or replace
  1653. * @param options - Mutation options
  1654. */
  1655. createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
  1656. document: IdentifiedSanityDocumentStub<R>,
  1657. options: FirstDocumentIdMutationOptions
  1658. ): Promise<SingleMutationResult>
  1659. /**
  1660. * Create a document if it does not exist, or replace a document with the same document ID
  1661. * Returns a promise that resolves to a mutation result object containing the created document ID.
  1662. *
  1663. * @param document - Document to either create or replace
  1664. * @param options - Mutation options
  1665. */
  1666. createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
  1667. document: IdentifiedSanityDocumentStub<R>,
  1668. options: AllDocumentIdsMutationOptions
  1669. ): Promise<MultipleMutationResult>
  1670. /**
  1671. * Create a document if it does not exist, or replace a document with the same document ID
  1672. * Returns a promise that resolves to the created document.
  1673. *
  1674. * @param document - Document to either create or replace
  1675. * @param options - Mutation options
  1676. */
  1677. createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
  1678. document: IdentifiedSanityDocumentStub<R>,
  1679. options?: BaseMutationOptions
  1680. ): Promise<SanityDocument<R>>
  1681. /**
  1682. * Deletes a document with the given document ID.
  1683. * Returns a promise that resolves to the deleted document.
  1684. *
  1685. * @param id - Document ID to delete
  1686. * @param options - Options for the mutation
  1687. */
  1688. delete<R extends Record<string, Any> = Record<string, Any>>(
  1689. id: string,
  1690. options: FirstDocumentMutationOptions
  1691. ): Promise<SanityDocument<R>>
  1692. /**
  1693. * Deletes a document with the given document ID.
  1694. * Returns a promise that resolves to an array containing the deleted document.
  1695. *
  1696. * @param id - Document ID to delete
  1697. * @param options - Options for the mutation
  1698. */
  1699. delete<R extends Record<string, Any> = Record<string, Any>>(
  1700. id: string,
  1701. options: AllDocumentsMutationOptions
  1702. ): Promise<SanityDocument<R>[]>
  1703. /**
  1704. * Deletes a document with the given document ID.
  1705. * Returns a promise that resolves to a mutation result object containing the deleted document ID.
  1706. *
  1707. * @param id - Document ID to delete
  1708. * @param options - Options for the mutation
  1709. */
  1710. delete(id: string, options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
  1711. /**
  1712. * Deletes a document with the given document ID.
  1713. * Returns a promise that resolves to a mutation result object containing the deleted document ID.
  1714. *
  1715. * @param id - Document ID to delete
  1716. * @param options - Options for the mutation
  1717. */
  1718. delete(id: string, options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
  1719. /**
  1720. * Deletes a document with the given document ID.
  1721. * Returns a promise that resolves to the deleted document.
  1722. *
  1723. * @param id - Document ID to delete
  1724. * @param options - Options for the mutation
  1725. */
  1726. delete<R extends Record<string, Any> = Record<string, Any>>(
  1727. id: string,
  1728. options?: BaseMutationOptions
  1729. ): Promise<SanityDocument<R>>
  1730. /**
  1731. * Deletes one or more documents matching the given query or document ID.
  1732. * Returns a promise that resolves to first deleted document.
  1733. *
  1734. * @param selection - An object with either an `id` or `query` key defining what to delete
  1735. * @param options - Options for the mutation
  1736. */
  1737. delete<R extends Record<string, Any> = Record<string, Any>>(
  1738. selection: MutationSelection,
  1739. options: FirstDocumentMutationOptions
  1740. ): Promise<SanityDocument<R>>
  1741. /**
  1742. * Deletes one or more documents matching the given query or document ID.
  1743. * Returns a promise that resolves to an array containing the deleted documents.
  1744. *
  1745. * @param selection - An object with either an `id` or `query` key defining what to delete
  1746. * @param options - Options for the mutation
  1747. */
  1748. delete<R extends Record<string, Any> = Record<string, Any>>(
  1749. selection: MutationSelection,
  1750. options: AllDocumentsMutationOptions
  1751. ): Promise<SanityDocument<R>[]>
  1752. /**
  1753. * Deletes one or more documents matching the given query or document ID.
  1754. * Returns a promise that resolves to a mutation result object containing the ID of the first deleted document.
  1755. *
  1756. * @param selection - An object with either an `id` or `query` key defining what to delete
  1757. * @param options - Options for the mutation
  1758. */
  1759. delete(
  1760. selection: MutationSelection,
  1761. options: FirstDocumentIdMutationOptions
  1762. ): Promise<SingleMutationResult>
  1763. /**
  1764. * Deletes one or more documents matching the given query or document ID.
  1765. * Returns a promise that resolves to a mutation result object containing the document IDs that were deleted.
  1766. *
  1767. * @param selection - An object with either an `id` or `query` key defining what to delete
  1768. * @param options - Options for the mutation
  1769. */
  1770. delete(
  1771. selection: MutationSelection,
  1772. options: AllDocumentIdsMutationOptions
  1773. ): Promise<MultipleMutationResult>
  1774. /**
  1775. * Deletes one or more documents matching the given query or document ID.
  1776. * Returns a promise that resolves to first deleted document.
  1777. *
  1778. * @param selection - An object with either an `id` or `query` key defining what to delete
  1779. * @param options - Options for the mutation
  1780. */
  1781. delete<R extends Record<string, Any> = Record<string, Any>>(
  1782. selection: MutationSelection,
  1783. options?: BaseMutationOptions
  1784. ): Promise<SanityDocument<R>>
  1785. /**
  1786. * Perform mutation operations against the configured dataset
  1787. * Returns a promise that resolves to the first mutated document.
  1788. *
  1789. * @param operations - Mutation operations to execute
  1790. * @param options - Mutation options
  1791. */
  1792. mutate<R extends Record<string, Any> = Record<string, Any>>(
  1793. operations: Mutation<R>[] | Patch | Transaction,
  1794. options: FirstDocumentMutationOptions
  1795. ): Promise<SanityDocument<R>>
  1796. /**
  1797. * Perform mutation operations against the configured dataset.
  1798. * Returns a promise that resolves to an array of the mutated documents.
  1799. *
  1800. * @param operations - Mutation operations to execute
  1801. * @param options - Mutation options
  1802. */
  1803. mutate<R extends Record<string, Any> = Record<string, Any>>(
  1804. operations: Mutation<R>[] | Patch | Transaction,
  1805. options: AllDocumentsMutationOptions
  1806. ): Promise<SanityDocument<R>[]>
  1807. /**
  1808. * Perform mutation operations against the configured dataset
  1809. * Returns a promise that resolves to a mutation result object containing the document ID of the first mutated document.
  1810. *
  1811. * @param operations - Mutation operations to execute
  1812. * @param options - Mutation options
  1813. */
  1814. mutate<R extends Record<string, Any> = Record<string, Any>>(
  1815. operations: Mutation<R>[] | Patch | Transaction,
  1816. options: FirstDocumentIdMutationOptions
  1817. ): Promise<SingleMutationResult>
  1818. /**
  1819. * Perform mutation operations against the configured dataset
  1820. * Returns a promise that resolves to a mutation result object containing the mutated document IDs.
  1821. *
  1822. * @param operations - Mutation operations to execute
  1823. * @param options - Mutation options
  1824. */
  1825. mutate<R extends Record<string, Any>>(
  1826. operations: Mutation<R>[] | Patch | Transaction,
  1827. options: AllDocumentIdsMutationOptions
  1828. ): Promise<MultipleMutationResult>
  1829. /**
  1830. * Perform mutation operations against the configured dataset
  1831. * Returns a promise that resolves to the first mutated document.
  1832. *
  1833. * @param operations - Mutation operations to execute
  1834. * @param options - Mutation options
  1835. */
  1836. mutate<R extends Record<string, Any> = Record<string, Any>>(
  1837. operations: Mutation<R>[] | Patch | Transaction,
  1838. options?: BaseMutationOptions
  1839. ): Promise<SanityDocument<R>>
  1840. /**
  1841. * Create a new buildable patch of operations to perform
  1842. *
  1843. * @param documentId - Document ID(s)to patch
  1844. * @param operations - Optional object of patch operations to initialize the patch instance with
  1845. */
  1846. patch(documentId: PatchSelection, operations?: PatchOperations): Patch
  1847. /**
  1848. * Create a new transaction of mutations
  1849. *
  1850. * @param operations - Optional array of mutation operations to initialize the transaction instance with
  1851. */
  1852. transaction<R extends Record<string, Any> = Record<string, Any>>(
  1853. operations?: Mutation<R>[]
  1854. ): Transaction
  1855. /**
  1856. * DEPRECATED: Perform an HTTP request against the Sanity API
  1857. *
  1858. * @deprecated Use your own request library!
  1859. * @param options - Request options
  1860. */
  1861. request<R = Any>(options: RawRequestOptions): Promise<R>
  1862. /**
  1863. * DEPRECATED: Perform an HTTP request a `/data` sub-endpoint
  1864. *
  1865. * @deprecated Use your own request library!
  1866. * @param endpoint - Endpoint to hit (mutate, query etc)
  1867. * @param body - Request body
  1868. * @param options - Request options
  1869. */
  1870. dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any>
  1871. /**
  1872. * Get a Sanity API URL for the URI provided
  1873. *
  1874. * @param uri - URI/path to build URL for
  1875. * @param canUseCdn - Whether or not to allow using the API CDN for this route
  1876. */
  1877. getUrl(uri: string, canUseCdn?: boolean): string
  1878. /**
  1879. * Get a Sanity API URL for the data operation and path provided
  1880. *
  1881. * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
  1882. * @param path - Path to append after the operation
  1883. */
  1884. getDataUrl(operation: string, path?: string): string
  1885. }
  1886. /** @internal */
  1887. export declare type SanityDocument<T extends Record<string, Any> = Record<string, Any>> = {
  1888. [P in keyof T]: T[P]
  1889. } & {
  1890. _id: string
  1891. _rev: string
  1892. _type: string
  1893. _createdAt: string
  1894. _updatedAt: string
  1895. }
  1896. /** @public */
  1897. export declare type SanityDocumentStub<T extends Record<string, Any> = Record<string, Any>> = {
  1898. [P in keyof T]: T[P]
  1899. } & {
  1900. _type: string
  1901. }
  1902. /** @internal */
  1903. export declare interface SanityImageAssetDocument extends SanityAssetDocument {
  1904. metadata: {
  1905. _type: 'sanity.imageMetadata'
  1906. hasAlpha: boolean
  1907. isOpaque: boolean
  1908. lqip?: string
  1909. blurHash?: string
  1910. dimensions: {
  1911. _type: 'sanity.imageDimensions'
  1912. aspectRatio: number
  1913. height: number
  1914. width: number
  1915. }
  1916. palette?: {
  1917. _type: 'sanity.imagePalette'
  1918. darkMuted?: SanityImagePalette
  1919. darkVibrant?: SanityImagePalette
  1920. dominant?: SanityImagePalette
  1921. lightMuted?: SanityImagePalette
  1922. lightVibrant?: SanityImagePalette
  1923. muted?: SanityImagePalette
  1924. vibrant?: SanityImagePalette
  1925. }
  1926. image?: {
  1927. _type: 'sanity.imageExifTags'
  1928. [key: string]: Any
  1929. }
  1930. exif?: {
  1931. _type: 'sanity.imageExifMetadata'
  1932. [key: string]: Any
  1933. }
  1934. }
  1935. }
  1936. /** @internal */
  1937. export declare interface SanityImagePalette {
  1938. background: string
  1939. foreground: string
  1940. population: number
  1941. title: string
  1942. }
  1943. /** @internal */
  1944. export declare interface SanityProject {
  1945. id: string
  1946. displayName: string
  1947. studioHost: string | null
  1948. organizationId: string | null
  1949. isBlocked: boolean
  1950. isDisabled: boolean
  1951. isDisabledByUser: boolean
  1952. createdAt: string
  1953. pendingInvites?: number
  1954. maxRetentionDays?: number
  1955. members: SanityProjectMember[]
  1956. metadata: {
  1957. color?: string
  1958. externalStudioHost?: string
  1959. }
  1960. }
  1961. /** @internal */
  1962. export declare interface SanityProjectMember {
  1963. id: string
  1964. role: string
  1965. isRobot: boolean
  1966. isCurrentUser: boolean
  1967. }
  1968. /** @internal */
  1969. export declare interface SanityReference {
  1970. _ref: string
  1971. }
  1972. /** @internal */
  1973. export declare interface SanityUser {
  1974. id: string
  1975. projectId: string
  1976. displayName: string
  1977. familyName: string | null
  1978. givenName: string | null
  1979. middleName: string | null
  1980. imageUrl: string | null
  1981. createdAt: string
  1982. updatedAt: string
  1983. isCurrentUser: boolean
  1984. }
  1985. /** @public */
  1986. export declare class ServerError extends Error {
  1987. response: ErrorProps['response']
  1988. statusCode: ErrorProps['statusCode']
  1989. responseBody: ErrorProps['responseBody']
  1990. details: ErrorProps['details']
  1991. constructor(res: Any)
  1992. }
  1993. /** @internal */
  1994. export declare interface SingleMutationResult {
  1995. transactionId: string
  1996. documentId: string
  1997. results: {
  1998. id: string
  1999. operation: MutationOperation
  2000. }[]
  2001. }
  2002. /** @public */
  2003. export declare class Transaction extends BaseTransaction {
  2004. #private
  2005. constructor(operations?: Mutation[], client?: SanityClient, transactionId?: string)
  2006. /**
  2007. * Clones the transaction
  2008. */
  2009. clone(): Transaction
  2010. /**
  2011. * Commit the transaction, returning a promise that resolves to the first mutated document
  2012. *
  2013. * @param options - Options for the mutation operation
  2014. */
  2015. commit<R extends Record<string, Any>>(
  2016. options: TransactionFirstDocumentMutationOptions
  2017. ): Promise<SanityDocument<R>>
  2018. /**
  2019. * Commit the transaction, returning a promise that resolves to an array of the mutated documents
  2020. *
  2021. * @param options - Options for the mutation operation
  2022. */
  2023. commit<R extends Record<string, Any>>(
  2024. options: TransactionAllDocumentsMutationOptions
  2025. ): Promise<SanityDocument<R>[]>
  2026. /**
  2027. * Commit the transaction, returning a promise that resolves to a mutation result object
  2028. *
  2029. * @param options - Options for the mutation operation
  2030. */
  2031. commit(options: TransactionFirstDocumentIdMutationOptions): Promise<SingleMutationResult>
  2032. /**
  2033. * Commit the transaction, returning a promise that resolves to a mutation result object
  2034. *
  2035. * @param options - Options for the mutation operation
  2036. */
  2037. commit(options: TransactionAllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
  2038. /**
  2039. * Commit the transaction, returning a promise that resolves to a mutation result object
  2040. *
  2041. * @param options - Options for the mutation operation
  2042. */
  2043. commit(options?: BaseMutationOptions): Promise<MultipleMutationResult>
  2044. /**
  2045. * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
  2046. * The operation is added to the current transaction, ready to be commited by `commit()`
  2047. *
  2048. * @param documentId - Document ID to perform the patch operation on
  2049. * @param patchOps - Operations to perform, or a builder function
  2050. */
  2051. patch(documentId: string, patchOps?: PatchBuilder | PatchOperations): this
  2052. /**
  2053. * Adds the given patch instance to the transaction.
  2054. * The operation is added to the current transaction, ready to be commited by `commit()`
  2055. *
  2056. * @param patch - Patch to execute
  2057. */
  2058. patch(patch: Patch): this
  2059. }
  2060. /** @internal */
  2061. export declare type TransactionAllDocumentIdsMutationOptions = BaseMutationOptions & {
  2062. returnFirst?: false
  2063. returnDocuments?: false
  2064. }
  2065. /** @internal */
  2066. export declare type TransactionAllDocumentsMutationOptions = BaseMutationOptions & {
  2067. returnFirst?: false
  2068. returnDocuments: true
  2069. }
  2070. /** @internal */
  2071. export declare type TransactionFirstDocumentIdMutationOptions = BaseMutationOptions & {
  2072. returnFirst: true
  2073. returnDocuments?: false
  2074. }
  2075. /** @internal */
  2076. export declare type TransactionFirstDocumentMutationOptions = BaseMutationOptions & {
  2077. returnFirst: true
  2078. returnDocuments: true
  2079. }
  2080. /** @internal */
  2081. export declare type TransactionMutationOptions =
  2082. | TransactionFirstDocumentMutationOptions
  2083. | TransactionFirstDocumentIdMutationOptions
  2084. | TransactionAllDocumentsMutationOptions
  2085. | TransactionAllDocumentIdsMutationOptions
  2086. /** @internal */
  2087. export declare type UnfilteredResponseQueryOptions = RequestOptions & {
  2088. filterResponse: false
  2089. }
  2090. export {unstable__adapter}
  2091. export {unstable__environment}
  2092. /** @public */
  2093. export declare type UploadBody = File | Blob | Buffer | NodeJS.ReadableStream
  2094. /** @public */
  2095. export declare interface UploadClientConfig {
  2096. /**
  2097. * Optional request tag for the upload
  2098. */
  2099. tag?: string
  2100. /**
  2101. * Whether or not to preserve the original filename (default: true)
  2102. */
  2103. preserveFilename?: boolean
  2104. /**
  2105. * Filename for this file (optional)
  2106. */
  2107. filename?: string
  2108. /**
  2109. * Milliseconds to wait before timing the request out
  2110. */
  2111. timeout?: number
  2112. /**
  2113. * Mime type of the file
  2114. */
  2115. contentType?: string
  2116. /**
  2117. * Array of metadata parts to extract from asset
  2118. */
  2119. extract?: AssetMetadataType[]
  2120. /**
  2121. * Optional freeform label for the asset. Generally not used.
  2122. */
  2123. label?: string
  2124. /**
  2125. * Optional title for the asset
  2126. */
  2127. title?: string
  2128. /**
  2129. * Optional description for the asset
  2130. */
  2131. description?: string
  2132. /**
  2133. * The credit to person(s) and/or organization(s) required by the supplier of the asset to be used when published
  2134. */
  2135. creditLine?: string
  2136. /**
  2137. * Source data (when the asset is from an external service)
  2138. */
  2139. source?: {
  2140. /**
  2141. * The (u)id of the asset within the source, i.e. 'i-f323r1E'
  2142. */
  2143. id: string
  2144. /**
  2145. * The name of the source, i.e. 'unsplash'
  2146. */
  2147. name: string
  2148. /**
  2149. * A url to where to find the asset, or get more info about it in the source
  2150. */
  2151. url?: string
  2152. }
  2153. }
  2154. /** @public */
  2155. export declare class UsersClient {
  2156. #private
  2157. constructor(client: SanityClient, httpRequest: HttpRequest)
  2158. /**
  2159. * Fetch a user by user ID
  2160. *
  2161. * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
  2162. */
  2163. getById<T extends 'me' | string>(id: T): Promise<T extends 'me' ? CurrentSanityUser : SanityUser>
  2164. }
  2165. /** @public */
  2166. export declare type WelcomeEvent = {
  2167. type: 'welcome'
  2168. }
  2169. export {}