@sanity/client 5.0.0-esm.2 → 5.0.0-esm.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,21 +2,13 @@ import {lastValueFrom, Observable} from 'rxjs'
2
2
 
3
3
  import {AssetsClient, ObservableAssetsClient} from './assets/AssetsClient'
4
4
  import {AuthClient, ObservableAuthClient} from './auth/AuthClient'
5
- import {initConfig} from './config'
5
+ import {defaultConfig, initConfig} from './config'
6
6
  import * as dataMethods from './data/dataMethods'
7
7
  import {_listen} from './data/listen'
8
8
  import {ObservablePatch, Patch} from './data/patch'
9
9
  import {ObservableTransaction, Transaction} from './data/transaction'
10
- import {
11
- BaseDatasetsClient,
12
- DatasetsClient,
13
- ObservableDatasetsClient,
14
- } from './datasets/DatasetsClient'
15
- import {
16
- BaseProjectsClient,
17
- ObservableProjectsClient,
18
- ProjectsClient,
19
- } from './projects/ProjectsClient'
10
+ import {DatasetsClient, ObservableDatasetsClient} from './datasets/DatasetsClient'
11
+ import {ObservableProjectsClient, ProjectsClient} from './projects/ProjectsClient'
20
12
  import type {
21
13
  AllDocumentIdsMutationOptions,
22
14
  AllDocumentsMutationOptions,
@@ -32,6 +24,7 @@ import type {
32
24
  Mutation,
33
25
  MutationSelection,
34
26
  PatchOperations,
27
+ PatchSelection,
35
28
  QueryParams,
36
29
  RawQueryResponse,
37
30
  RawRequestOptions,
@@ -40,16 +33,12 @@ import type {
40
33
  SingleMutationResult,
41
34
  UnfilteredResponseQueryOptions,
42
35
  } from './types'
43
- import {BaseUsersClient, ObservableUsersClient, UsersClient} from './users/UsersClient'
44
- import * as validators from './validators'
36
+ import {ObservableUsersClient, UsersClient} from './users/UsersClient'
45
37
 
46
38
  export type {
47
39
  _listen,
48
40
  AssetsClient,
49
41
  AuthClient,
50
- BaseDatasetsClient,
51
- BaseProjectsClient,
52
- BaseUsersClient,
53
42
  DatasetsClient,
54
43
  ObservableAssetsClient,
55
44
  ObservableAuthClient,
@@ -60,6 +49,7 @@ export type {
60
49
  UsersClient,
61
50
  }
62
51
 
52
+ /** @public */
63
53
  export class ObservableSanityClient {
64
54
  assets: ObservableAssetsClient
65
55
  auth: ObservableAuthClient
@@ -73,16 +63,16 @@ export class ObservableSanityClient {
73
63
  #clientConfig: InitializedClientConfig
74
64
  #httpRequest: HttpRequest
75
65
 
76
- constructor(httpRequest: HttpRequest, config: ClientConfig) {
66
+ constructor(httpRequest: HttpRequest, config: ClientConfig = defaultConfig) {
77
67
  this.config(config)
78
68
 
79
69
  this.#httpRequest = httpRequest
80
70
 
81
71
  this.assets = new ObservableAssetsClient(this, this.#httpRequest)
82
72
  this.auth = new ObservableAuthClient(this, this.#httpRequest)
83
- this.datasets = new ObservableDatasetsClient(this)
84
- this.projects = new ObservableProjectsClient(this)
85
- this.users = new ObservableUsersClient(this)
73
+ this.datasets = new ObservableDatasetsClient(this, this.#httpRequest)
74
+ this.projects = new ObservableProjectsClient(this, this.#httpRequest)
75
+ this.users = new ObservableUsersClient(this, this.#httpRequest)
86
76
  }
87
77
 
88
78
  /**
@@ -118,7 +108,7 @@ export class ObservableSanityClient {
118
108
  /**
119
109
  * Clone the client with a new (partial) configuration.
120
110
  *
121
- * @param newConfig New client configuration properties, shallowly merged with existing configuration
111
+ * @param newConfig - New client configuration properties, shallowly merged with existing configuration
122
112
  */
123
113
  withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityClient {
124
114
  return new ObservableSanityClient(this.#httpRequest, {...this.config(), ...newConfig})
@@ -127,22 +117,22 @@ export class ObservableSanityClient {
127
117
  /**
128
118
  * Perform a GROQ-query against the configured dataset.
129
119
  *
130
- * @param query GROQ-query to perform
120
+ * @param query - GROQ-query to perform
131
121
  */
132
122
  fetch<R = any>(query: string): Observable<R>
133
123
  /**
134
124
  * Perform a GROQ-query against the configured dataset.
135
125
  *
136
- * @param query GROQ-query to perform
137
- * @param params Query parameters
126
+ * @param query - GROQ-query to perform
127
+ * @param params - Query parameters
138
128
  */
139
129
  fetch<R = any>(query: string, params: QueryParams): Observable<R>
140
130
  /**
141
131
  * Perform a GROQ-query against the configured dataset.
142
132
  *
143
- * @param query GROQ-query to perform
144
- * @param params Query parameters
145
- * @param options Request options
133
+ * @param query - GROQ-query to perform
134
+ * @param params - Query parameters
135
+ * @param options - Request options
146
136
  */
147
137
  fetch<R = any>(
148
138
  query: string,
@@ -152,9 +142,9 @@ export class ObservableSanityClient {
152
142
  /**
153
143
  * Perform a GROQ-query against the configured dataset.
154
144
  *
155
- * @param query GROQ-query to perform
156
- * @param params Query parameters
157
- * @param options Request options
145
+ * @param query - GROQ-query to perform
146
+ * @param params - Query parameters
147
+ * @param options - Request options
158
148
  */
159
149
  fetch<R = any>(
160
150
  query: string,
@@ -172,8 +162,8 @@ export class ObservableSanityClient {
172
162
  /**
173
163
  * Fetch a single document with the given ID.
174
164
  *
175
- * @param id Document ID to fetch
176
- * @param options Request options
165
+ * @param id - Document ID to fetch
166
+ * @param options - Request options
177
167
  */
178
168
  getDocument<R extends Record<string, any> = Record<string, any>>(
179
169
  id: string,
@@ -188,8 +178,8 @@ export class ObservableSanityClient {
188
178
  * The order/position of documents is preserved based on the original array of IDs.
189
179
  * If a any of the documents are missing, they will be replaced by a `null` entry in the returned array
190
180
  *
191
- * @param ids Document IDs to fetch
192
- * @param options Request options
181
+ * @param ids - Document IDs to fetch
182
+ * @param options - Request options
193
183
  */
194
184
  getDocuments<R extends Record<string, any> = Record<string, any>>(
195
185
  ids: string[],
@@ -202,8 +192,8 @@ export class ObservableSanityClient {
202
192
  * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
203
193
  * Returns an observable that resolves to the created document.
204
194
  *
205
- * @param document Document to create
206
- * @param options Mutation options
195
+ * @param document - Document to create
196
+ * @param options - Mutation options
207
197
  */
208
198
  create<R extends Record<string, any> = Record<string, any>>(
209
199
  document: SanityDocumentStub<R>,
@@ -213,8 +203,8 @@ export class ObservableSanityClient {
213
203
  * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
214
204
  * Returns an observable that resolves to an array containing the created document.
215
205
  *
216
- * @param document Document to create
217
- * @param options Mutation options
206
+ * @param document - Document to create
207
+ * @param options - Mutation options
218
208
  */
219
209
  create<R extends Record<string, any> = Record<string, any>>(
220
210
  document: SanityDocumentStub<R>,
@@ -224,8 +214,8 @@ export class ObservableSanityClient {
224
214
  * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
225
215
  * Returns an observable that resolves to a mutation result object containing the ID of the created document.
226
216
  *
227
- * @param document Document to create
228
- * @param options Mutation options
217
+ * @param document - Document to create
218
+ * @param options - Mutation options
229
219
  */
230
220
  create<R extends Record<string, any> = Record<string, any>>(
231
221
  document: SanityDocumentStub<R>,
@@ -235,8 +225,8 @@ export class ObservableSanityClient {
235
225
  * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
236
226
  * Returns an observable that resolves to a mutation result object containing the ID of the created document.
237
227
  *
238
- * @param document Document to create
239
- * @param options Mutation options
228
+ * @param document - Document to create
229
+ * @param options - Mutation options
240
230
  */
241
231
  create<R extends Record<string, any> = Record<string, any>>(
242
232
  document: SanityDocumentStub<R>,
@@ -246,8 +236,8 @@ export class ObservableSanityClient {
246
236
  * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
247
237
  * Returns an observable that resolves to the created document.
248
238
  *
249
- * @param document Document to create
250
- * @param options Mutation options
239
+ * @param document - Document to create
240
+ * @param options - Mutation options
251
241
  */
252
242
  create<R extends Record<string, any> = Record<string, any>>(
253
243
  document: SanityDocumentStub<R>,
@@ -271,8 +261,8 @@ export class ObservableSanityClient {
271
261
  * Create a document if no document with the same ID already exists.
272
262
  * Returns an observable that resolves to the created document.
273
263
  *
274
- * @param document Document to create
275
- * @param options Mutation options
264
+ * @param document - Document to create
265
+ * @param options - Mutation options
276
266
  */
277
267
  createIfNotExists<R extends Record<string, any> = Record<string, any>>(
278
268
  document: IdentifiedSanityDocumentStub<R>,
@@ -282,8 +272,8 @@ export class ObservableSanityClient {
282
272
  * Create a document if no document with the same ID already exists.
283
273
  * Returns an observable that resolves to an array containing the created document.
284
274
  *
285
- * @param document Document to create
286
- * @param options Mutation options
275
+ * @param document - Document to create
276
+ * @param options - Mutation options
287
277
  */
288
278
  createIfNotExists<R extends Record<string, any> = Record<string, any>>(
289
279
  document: IdentifiedSanityDocumentStub<R>,
@@ -293,8 +283,8 @@ export class ObservableSanityClient {
293
283
  * Create a document if no document with the same ID already exists.
294
284
  * Returns an observable that resolves to a mutation result object containing the ID of the created document.
295
285
  *
296
- * @param document Document to create
297
- * @param options Mutation options
286
+ * @param document - Document to create
287
+ * @param options - Mutation options
298
288
  */
299
289
  createIfNotExists<R extends Record<string, any> = Record<string, any>>(
300
290
  document: IdentifiedSanityDocumentStub<R>,
@@ -304,8 +294,8 @@ export class ObservableSanityClient {
304
294
  * Create a document if no document with the same ID already exists.
305
295
  * Returns an observable that resolves to a mutation result object containing the ID of the created document.
306
296
  *
307
- * @param document Document to create
308
- * @param options Mutation options
297
+ * @param document - Document to create
298
+ * @param options - Mutation options
309
299
  */
310
300
  createIfNotExists<R extends Record<string, any> = Record<string, any>>(
311
301
  document: IdentifiedSanityDocumentStub<R>,
@@ -315,8 +305,8 @@ export class ObservableSanityClient {
315
305
  * Create a document if no document with the same ID already exists.
316
306
  * Returns an observable that resolves to the created document.
317
307
  *
318
- * @param document Document to create
319
- * @param options Mutation options
308
+ * @param document - Document to create
309
+ * @param options - Mutation options
320
310
  */
321
311
  createIfNotExists<R extends Record<string, any> = Record<string, any>>(
322
312
  document: IdentifiedSanityDocumentStub<R>,
@@ -340,8 +330,8 @@ export class ObservableSanityClient {
340
330
  * Create a document if it does not exist, or replace a document with the same document ID
341
331
  * Returns an observable that resolves to the created document.
342
332
  *
343
- * @param document Document to either create or replace
344
- * @param options Mutation options
333
+ * @param document - Document to either create or replace
334
+ * @param options - Mutation options
345
335
  */
346
336
  createOrReplace<R extends Record<string, any> = Record<string, any>>(
347
337
  document: IdentifiedSanityDocumentStub<R>,
@@ -351,8 +341,8 @@ export class ObservableSanityClient {
351
341
  * Create a document if it does not exist, or replace a document with the same document ID
352
342
  * Returns an observable that resolves to an array containing the created document.
353
343
  *
354
- * @param document Document to either create or replace
355
- * @param options Mutation options
344
+ * @param document - Document to either create or replace
345
+ * @param options - Mutation options
356
346
  */
357
347
  createOrReplace<R extends Record<string, any> = Record<string, any>>(
358
348
  document: IdentifiedSanityDocumentStub<R>,
@@ -362,8 +352,8 @@ export class ObservableSanityClient {
362
352
  * Create a document if it does not exist, or replace a document with the same document ID
363
353
  * Returns an observable that resolves to a mutation result object containing the ID of the created document.
364
354
  *
365
- * @param document Document to either create or replace
366
- * @param options Mutation options
355
+ * @param document - Document to either create or replace
356
+ * @param options - Mutation options
367
357
  */
368
358
  createOrReplace<R extends Record<string, any> = Record<string, any>>(
369
359
  document: IdentifiedSanityDocumentStub<R>,
@@ -373,8 +363,8 @@ export class ObservableSanityClient {
373
363
  * Create a document if it does not exist, or replace a document with the same document ID
374
364
  * Returns an observable that resolves to a mutation result object containing the created document ID.
375
365
  *
376
- * @param document Document to either create or replace
377
- * @param options Mutation options
366
+ * @param document - Document to either create or replace
367
+ * @param options - Mutation options
378
368
  */
379
369
  createOrReplace<R extends Record<string, any> = Record<string, any>>(
380
370
  document: IdentifiedSanityDocumentStub<R>,
@@ -384,8 +374,8 @@ export class ObservableSanityClient {
384
374
  * Create a document if it does not exist, or replace a document with the same document ID
385
375
  * Returns an observable that resolves to the created document.
386
376
  *
387
- * @param document Document to either create or replace
388
- * @param options Mutation options
377
+ * @param document - Document to either create or replace
378
+ * @param options - Mutation options
389
379
  */
390
380
  createOrReplace<R extends Record<string, any> = Record<string, any>>(
391
381
  document: IdentifiedSanityDocumentStub<R>,
@@ -409,8 +399,8 @@ export class ObservableSanityClient {
409
399
  * Deletes a document with the given document ID.
410
400
  * Returns an observable that resolves to the deleted document.
411
401
  *
412
- * @param id Document ID to delete
413
- * @param options Options for the mutation
402
+ * @param id - Document ID to delete
403
+ * @param options - Options for the mutation
414
404
  */
415
405
  delete<R extends Record<string, any> = Record<string, any>>(
416
406
  id: string,
@@ -420,8 +410,8 @@ export class ObservableSanityClient {
420
410
  * Deletes a document with the given document ID.
421
411
  * Returns an observable that resolves to an array containing the deleted document.
422
412
  *
423
- * @param id Document ID to delete
424
- * @param options Options for the mutation
413
+ * @param id - Document ID to delete
414
+ * @param options - Options for the mutation
425
415
  */
426
416
  delete<R extends Record<string, any> = Record<string, any>>(
427
417
  id: string,
@@ -431,24 +421,24 @@ export class ObservableSanityClient {
431
421
  * Deletes a document with the given document ID.
432
422
  * Returns an observable that resolves to a mutation result object containing the deleted document ID.
433
423
  *
434
- * @param id Document ID to delete
435
- * @param options Options for the mutation
424
+ * @param id - Document ID to delete
425
+ * @param options - Options for the mutation
436
426
  */
437
427
  delete(id: string, options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
438
428
  /**
439
429
  * Deletes a document with the given document ID.
440
430
  * Returns an observable that resolves to a mutation result object containing the deleted document ID.
441
431
  *
442
- * @param id Document ID to delete
443
- * @param options Options for the mutation
432
+ * @param id - Document ID to delete
433
+ * @param options - Options for the mutation
444
434
  */
445
435
  delete(id: string, options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
446
436
  /**
447
437
  * Deletes a document with the given document ID.
448
438
  * Returns an observable that resolves to the deleted document.
449
439
  *
450
- * @param id Document ID to delete
451
- * @param options Options for the mutation
440
+ * @param id - Document ID to delete
441
+ * @param options - Options for the mutation
452
442
  */
453
443
  delete<R extends Record<string, any> = Record<string, any>>(
454
444
  id: string,
@@ -458,8 +448,8 @@ export class ObservableSanityClient {
458
448
  * Deletes one or more documents matching the given query or document ID.
459
449
  * Returns an observable that resolves to first deleted document.
460
450
  *
461
- * @param selection An object with either an `id` or `query` key defining what to delete
462
- * @param options Options for the mutation
451
+ * @param selection - An object with either an `id` or `query` key defining what to delete
452
+ * @param options - Options for the mutation
463
453
  */
464
454
  delete<R extends Record<string, any> = Record<string, any>>(
465
455
  selection: MutationSelection,
@@ -469,8 +459,8 @@ export class ObservableSanityClient {
469
459
  * Deletes one or more documents matching the given query or document ID.
470
460
  * Returns an observable that resolves to an array containing the deleted documents.
471
461
  *
472
- * @param selection An object with either an `id` or `query` key defining what to delete
473
- * @param options Options for the mutation
462
+ * @param selection - An object with either an `id` or `query` key defining what to delete
463
+ * @param options - Options for the mutation
474
464
  */
475
465
  delete<R extends Record<string, any> = Record<string, any>>(
476
466
  selection: MutationSelection,
@@ -480,8 +470,8 @@ export class ObservableSanityClient {
480
470
  * Deletes one or more documents matching the given query or document ID.
481
471
  * Returns an observable that resolves to a mutation result object containing the ID of the first deleted document.
482
472
  *
483
- * @param selection An object with either an `id` or `query` key defining what to delete
484
- * @param options Options for the mutation
473
+ * @param selection - An object with either an `id` or `query` key defining what to delete
474
+ * @param options - Options for the mutation
485
475
  */
486
476
  delete(
487
477
  selection: MutationSelection,
@@ -491,8 +481,8 @@ export class ObservableSanityClient {
491
481
  * Deletes one or more documents matching the given query or document ID.
492
482
  * Returns an observable that resolves to a mutation result object containing the document IDs that were deleted.
493
483
  *
494
- * @param selection An object with either an `id` or `query` key defining what to delete
495
- * @param options Options for the mutation
484
+ * @param selection - An object with either an `id` or `query` key defining what to delete
485
+ * @param options - Options for the mutation
496
486
  */
497
487
  delete(
498
488
  selection: MutationSelection,
@@ -502,8 +492,8 @@ export class ObservableSanityClient {
502
492
  * Deletes one or more documents matching the given query or document ID.
503
493
  * Returns an observable that resolves to first deleted document.
504
494
  *
505
- * @param selection An object with either an `id` or `query` key defining what to delete
506
- * @param options Options for the mutation
495
+ * @param selection - An object with either an `id` or `query` key defining what to delete
496
+ * @param options - Options for the mutation
507
497
  */
508
498
  delete<R extends Record<string, any> = Record<string, any>>(
509
499
  selection: MutationSelection,
@@ -527,8 +517,8 @@ export class ObservableSanityClient {
527
517
  * Perform mutation operations against the configured dataset
528
518
  * Returns an observable that resolves to the first mutated document.
529
519
  *
530
- * @param operations Mutation operations to execute
531
- * @param options Mutation options
520
+ * @param operations - Mutation operations to execute
521
+ * @param options - Mutation options
532
522
  */
533
523
  mutate<R extends Record<string, any> = Record<string, any>>(
534
524
  operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
@@ -538,8 +528,8 @@ export class ObservableSanityClient {
538
528
  * Perform mutation operations against the configured dataset.
539
529
  * Returns an observable that resolves to an array of the mutated documents.
540
530
  *
541
- * @param operations Mutation operations to execute
542
- * @param options Mutation options
531
+ * @param operations - Mutation operations to execute
532
+ * @param options - Mutation options
543
533
  */
544
534
  mutate<R extends Record<string, any> = Record<string, any>>(
545
535
  operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
@@ -549,8 +539,8 @@ export class ObservableSanityClient {
549
539
  * Perform mutation operations against the configured dataset
550
540
  * Returns an observable that resolves to a mutation result object containing the document ID of the first mutated document.
551
541
  *
552
- * @param operations Mutation operations to execute
553
- * @param options Mutation options
542
+ * @param operations - Mutation operations to execute
543
+ * @param options - Mutation options
554
544
  */
555
545
  mutate<R extends Record<string, any> = Record<string, any>>(
556
546
  operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
@@ -560,8 +550,8 @@ export class ObservableSanityClient {
560
550
  * Perform mutation operations against the configured dataset
561
551
  * Returns an observable that resolves to a mutation result object containing the mutated document IDs.
562
552
  *
563
- * @param operations Mutation operations to execute
564
- * @param options Mutation options
553
+ * @param operations - Mutation operations to execute
554
+ * @param options - Mutation options
565
555
  */
566
556
  mutate<R extends Record<string, any> = Record<string, any>>(
567
557
  operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
@@ -571,8 +561,8 @@ export class ObservableSanityClient {
571
561
  * Perform mutation operations against the configured dataset
572
562
  * Returns an observable that resolves to the first mutated document.
573
563
  *
574
- * @param operations Mutation operations to execute
575
- * @param options Mutation options
564
+ * @param operations - Mutation operations to execute
565
+ * @param options - Mutation options
576
566
  */
577
567
  mutate<R extends Record<string, any> = Record<string, any>>(
578
568
  operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
@@ -595,17 +585,17 @@ export class ObservableSanityClient {
595
585
  /**
596
586
  * Create a new buildable patch of operations to perform
597
587
  *
598
- * @param documentId Document ID to patch
599
- * @param operations Optional object of patch operations to initialize the patch instance with
588
+ * @param documentId - Document ID(s) to patch
589
+ * @param operations - Optional object of patch operations to initialize the patch instance with
600
590
  */
601
- patch(documentId: string | MutationSelection, operations?: PatchOperations): ObservablePatch {
591
+ patch(documentId: PatchSelection, operations?: PatchOperations): ObservablePatch {
602
592
  return new ObservablePatch(documentId, operations, this)
603
593
  }
604
594
 
605
595
  /**
606
596
  * Create a new transaction of mutations
607
597
  *
608
- * @param operations Optional array of mutation operations to initialize the transaction instance with
598
+ * @param operations - Optional array of mutation operations to initialize the transaction instance with
609
599
  */
610
600
  transaction<R extends Record<string, any> = Record<string, any>>(
611
601
  operations?: Mutation<R>[]
@@ -617,40 +607,14 @@ export class ObservableSanityClient {
617
607
  * DEPRECATED: Perform an HTTP request against the Sanity API
618
608
  *
619
609
  * @deprecated Use your own request library!
620
- * @param options Request options
610
+ * @param options - Request options
621
611
  */
622
612
  request<R = any>(options: RawRequestOptions): Observable<R> {
623
613
  return dataMethods._request(this, this.#httpRequest, options)
624
614
  }
625
-
626
- /**
627
- * DEPRECATED: Get a Sanity API URL for the URI provided
628
- *
629
- * @deprecated Should be an internal concern
630
- * @param uri URI/path to build URL for
631
- * @param canUseCdn Whether or not to allow using the API CDN for this route
632
- */
633
- getUrl(uri: string, canUseCdn = false) {
634
- const base = canUseCdn ? this.#clientConfig.cdnUrl : this.#clientConfig.url
635
- return `${base}/${uri.replace(/^\//, '')}`
636
- }
637
-
638
- /**
639
- * DEPRECATED: Get a Sanity API URL for the data operation and path provided
640
- *
641
- * @deprecated Should be an internal concern
642
- * @param operation Data operation
643
- * @param path Path to append
644
- */
645
- getDataUrl(operation: string, path?: string): string {
646
- const config = this.config()
647
- const catalog = validators.hasDataset(config)
648
- const baseUri = `/${operation}/${catalog}`
649
- const uri = path ? `${baseUri}/${path}` : baseUri
650
- return `/data${uri}`.replace(/\/($|\?)/, '$1')
651
- }
652
615
  }
653
616
 
617
+ /** @public */
654
618
  export class SanityClient {
655
619
  assets: AssetsClient
656
620
  auth: AuthClient
@@ -674,18 +638,18 @@ export class SanityClient {
674
638
  */
675
639
  listen = _listen
676
640
 
677
- constructor(httpRequest: HttpRequest, config: ClientConfig) {
678
- this.observable = new ObservableSanityClient(httpRequest, config)
679
-
641
+ constructor(httpRequest: HttpRequest, config: ClientConfig = defaultConfig) {
680
642
  this.config(config)
681
643
 
682
644
  this.#httpRequest = httpRequest
683
645
 
684
646
  this.assets = new AssetsClient(this, this.#httpRequest)
685
647
  this.auth = new AuthClient(this, this.#httpRequest)
686
- this.datasets = new DatasetsClient(this)
687
- this.projects = new ProjectsClient(this)
688
- this.users = new UsersClient(this)
648
+ this.datasets = new DatasetsClient(this, this.#httpRequest)
649
+ this.projects = new ProjectsClient(this, this.#httpRequest)
650
+ this.users = new UsersClient(this, this.#httpRequest)
651
+
652
+ this.observable = new ObservableSanityClient(httpRequest, config)
689
653
  }
690
654
 
691
655
  /**
@@ -714,7 +678,9 @@ export class SanityClient {
714
678
  )
715
679
  }
716
680
 
717
- this.observable.config(newConfig)
681
+ if (this.observable) {
682
+ this.observable.config(newConfig)
683
+ }
718
684
 
719
685
  this.#clientConfig = initConfig(newConfig, this.#clientConfig || {})
720
686
  return this
@@ -723,7 +689,7 @@ export class SanityClient {
723
689
  /**
724
690
  * Clone the client with a new (partial) configuration.
725
691
  *
726
- * @param newConfig New client configuration properties, shallowly merged with existing configuration
692
+ * @param newConfig - New client configuration properties, shallowly merged with existing configuration
727
693
  */
728
694
  withConfig(newConfig?: Partial<ClientConfig>): SanityClient {
729
695
  return new SanityClient(this.#httpRequest, {...this.config(), ...newConfig})
@@ -732,22 +698,22 @@ export class SanityClient {
732
698
  /**
733
699
  * Perform a GROQ-query against the configured dataset.
734
700
  *
735
- * @param query GROQ-query to perform
701
+ * @param query - GROQ-query to perform
736
702
  */
737
703
  fetch<R = any>(query: string): Promise<R>
738
704
  /**
739
705
  * Perform a GROQ-query against the configured dataset.
740
706
  *
741
- * @param query GROQ-query to perform
742
- * @param params Optional query parameters
707
+ * @param query - GROQ-query to perform
708
+ * @param params - Optional query parameters
743
709
  */
744
710
  fetch<R = any>(query: string, params: QueryParams): Promise<R>
745
711
  /**
746
712
  * Perform a GROQ-query against the configured dataset.
747
713
  *
748
- * @param query GROQ-query to perform
749
- * @param params Optional query parameters
750
- * @param options Request options
714
+ * @param query - GROQ-query to perform
715
+ * @param params - Optional query parameters
716
+ * @param options - Request options
751
717
  */
752
718
  fetch<R = any>(
753
719
  query: string,
@@ -757,9 +723,9 @@ export class SanityClient {
757
723
  /**
758
724
  * Perform a GROQ-query against the configured dataset.
759
725
  *
760
- * @param query GROQ-query to perform
761
- * @param params Optional query parameters
762
- * @param options Request options
726
+ * @param query - GROQ-query to perform
727
+ * @param params - Optional query parameters
728
+ * @param options - Request options
763
729
  */
764
730
  fetch<R = any>(
765
731
  query: string,
@@ -777,8 +743,8 @@ export class SanityClient {
777
743
  /**
778
744
  * Fetch a single document with the given ID.
779
745
  *
780
- * @param id Document ID to fetch
781
- * @param options Request options
746
+ * @param id - Document ID to fetch
747
+ * @param options - Request options
782
748
  */
783
749
  getDocument<R extends Record<string, any> = Record<string, any>>(
784
750
  id: string,
@@ -793,8 +759,8 @@ export class SanityClient {
793
759
  * The order/position of documents is preserved based on the original array of IDs.
794
760
  * If a any of the documents are missing, they will be replaced by a `null` entry in the returned array
795
761
  *
796
- * @param ids Document IDs to fetch
797
- * @param options Request options
762
+ * @param ids - Document IDs to fetch
763
+ * @param options - Request options
798
764
  */
799
765
  getDocuments<R extends Record<string, any> = Record<string, any>>(
800
766
  ids: string[],
@@ -807,8 +773,8 @@ export class SanityClient {
807
773
  * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
808
774
  * Returns a promise that resolves to the created document.
809
775
  *
810
- * @param document Document to create
811
- * @param options Mutation options
776
+ * @param document - Document to create
777
+ * @param options - Mutation options
812
778
  */
813
779
  create<R extends Record<string, any> = Record<string, any>>(
814
780
  document: SanityDocumentStub<R>,
@@ -818,8 +784,8 @@ export class SanityClient {
818
784
  * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
819
785
  * Returns a promise that resolves to an array containing the created document.
820
786
  *
821
- * @param document Document to create
822
- * @param options Mutation options
787
+ * @param document - Document to create
788
+ * @param options - Mutation options
823
789
  */
824
790
  create<R extends Record<string, any> = Record<string, any>>(
825
791
  document: SanityDocumentStub<R>,
@@ -829,8 +795,8 @@ export class SanityClient {
829
795
  * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
830
796
  * Returns a promise that resolves to a mutation result object containing the ID of the created document.
831
797
  *
832
- * @param document Document to create
833
- * @param options Mutation options
798
+ * @param document - Document to create
799
+ * @param options - Mutation options
834
800
  */
835
801
  create<R extends Record<string, any> = Record<string, any>>(
836
802
  document: SanityDocumentStub<R>,
@@ -840,8 +806,8 @@ export class SanityClient {
840
806
  * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
841
807
  * Returns a promise that resolves to a mutation result object containing the ID of the created document.
842
808
  *
843
- * @param document Document to create
844
- * @param options Mutation options
809
+ * @param document - Document to create
810
+ * @param options - Mutation options
845
811
  */
846
812
  create<R extends Record<string, any> = Record<string, any>>(
847
813
  document: SanityDocumentStub<R>,
@@ -851,8 +817,8 @@ export class SanityClient {
851
817
  * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
852
818
  * Returns a promise that resolves to the created document.
853
819
  *
854
- * @param document Document to create
855
- * @param options Mutation options
820
+ * @param document - Document to create
821
+ * @param options - Mutation options
856
822
  */
857
823
  create<R extends Record<string, any> = Record<string, any>>(
858
824
  document: SanityDocumentStub<R>,
@@ -878,8 +844,8 @@ export class SanityClient {
878
844
  * Create a document if no document with the same ID already exists.
879
845
  * Returns a promise that resolves to the created document.
880
846
  *
881
- * @param document Document to create
882
- * @param options Mutation options
847
+ * @param document - Document to create
848
+ * @param options - Mutation options
883
849
  */
884
850
  createIfNotExists<R extends Record<string, any> = Record<string, any>>(
885
851
  document: IdentifiedSanityDocumentStub<R>,
@@ -889,8 +855,8 @@ export class SanityClient {
889
855
  * Create a document if no document with the same ID already exists.
890
856
  * Returns a promise that resolves to an array containing the created document.
891
857
  *
892
- * @param document Document to create
893
- * @param options Mutation options
858
+ * @param document - Document to create
859
+ * @param options - Mutation options
894
860
  */
895
861
  createIfNotExists<R extends Record<string, any> = Record<string, any>>(
896
862
  document: IdentifiedSanityDocumentStub<R>,
@@ -900,8 +866,8 @@ export class SanityClient {
900
866
  * Create a document if no document with the same ID already exists.
901
867
  * Returns a promise that resolves to a mutation result object containing the ID of the created document.
902
868
  *
903
- * @param document Document to create
904
- * @param options Mutation options
869
+ * @param document - Document to create
870
+ * @param options - Mutation options
905
871
  */
906
872
  createIfNotExists<R extends Record<string, any> = Record<string, any>>(
907
873
  document: IdentifiedSanityDocumentStub<R>,
@@ -911,8 +877,8 @@ export class SanityClient {
911
877
  * Create a document if no document with the same ID already exists.
912
878
  * Returns a promise that resolves to a mutation result object containing the ID of the created document.
913
879
  *
914
- * @param document Document to create
915
- * @param options Mutation options
880
+ * @param document - Document to create
881
+ * @param options - Mutation options
916
882
  */
917
883
  createIfNotExists<R extends Record<string, any> = Record<string, any>>(
918
884
  document: IdentifiedSanityDocumentStub<R>,
@@ -922,8 +888,8 @@ export class SanityClient {
922
888
  * Create a document if no document with the same ID already exists.
923
889
  * Returns a promise that resolves to the created document.
924
890
  *
925
- * @param document Document to create
926
- * @param options Mutation options
891
+ * @param document - Document to create
892
+ * @param options - Mutation options
927
893
  */
928
894
  createIfNotExists<R extends Record<string, any> = Record<string, any>>(
929
895
  document: IdentifiedSanityDocumentStub<R>,
@@ -949,8 +915,8 @@ export class SanityClient {
949
915
  * Create a document if it does not exist, or replace a document with the same document ID
950
916
  * Returns a promise that resolves to the created document.
951
917
  *
952
- * @param document Document to either create or replace
953
- * @param options Mutation options
918
+ * @param document - Document to either create or replace
919
+ * @param options - Mutation options
954
920
  */
955
921
  createOrReplace<R extends Record<string, any> = Record<string, any>>(
956
922
  document: IdentifiedSanityDocumentStub<R>,
@@ -960,8 +926,8 @@ export class SanityClient {
960
926
  * Create a document if it does not exist, or replace a document with the same document ID
961
927
  * Returns a promise that resolves to an array containing the created document.
962
928
  *
963
- * @param document Document to either create or replace
964
- * @param options Mutation options
929
+ * @param document - Document to either create or replace
930
+ * @param options - Mutation options
965
931
  */
966
932
  createOrReplace<R extends Record<string, any> = Record<string, any>>(
967
933
  document: IdentifiedSanityDocumentStub<R>,
@@ -971,8 +937,8 @@ export class SanityClient {
971
937
  * Create a document if it does not exist, or replace a document with the same document ID
972
938
  * Returns a promise that resolves to a mutation result object containing the ID of the created document.
973
939
  *
974
- * @param document Document to either create or replace
975
- * @param options Mutation options
940
+ * @param document - Document to either create or replace
941
+ * @param options - Mutation options
976
942
  */
977
943
  createOrReplace<R extends Record<string, any> = Record<string, any>>(
978
944
  document: IdentifiedSanityDocumentStub<R>,
@@ -982,8 +948,8 @@ export class SanityClient {
982
948
  * Create a document if it does not exist, or replace a document with the same document ID
983
949
  * Returns a promise that resolves to a mutation result object containing the created document ID.
984
950
  *
985
- * @param document Document to either create or replace
986
- * @param options Mutation options
951
+ * @param document - Document to either create or replace
952
+ * @param options - Mutation options
987
953
  */
988
954
  createOrReplace<R extends Record<string, any> = Record<string, any>>(
989
955
  document: IdentifiedSanityDocumentStub<R>,
@@ -993,8 +959,8 @@ export class SanityClient {
993
959
  * Create a document if it does not exist, or replace a document with the same document ID
994
960
  * Returns a promise that resolves to the created document.
995
961
  *
996
- * @param document Document to either create or replace
997
- * @param options Mutation options
962
+ * @param document - Document to either create or replace
963
+ * @param options - Mutation options
998
964
  */
999
965
  createOrReplace<R extends Record<string, any> = Record<string, any>>(
1000
966
  document: IdentifiedSanityDocumentStub<R>,
@@ -1020,8 +986,8 @@ export class SanityClient {
1020
986
  * Deletes a document with the given document ID.
1021
987
  * Returns a promise that resolves to the deleted document.
1022
988
  *
1023
- * @param id Document ID to delete
1024
- * @param options Options for the mutation
989
+ * @param id - Document ID to delete
990
+ * @param options - Options for the mutation
1025
991
  */
1026
992
  delete<R extends Record<string, any> = Record<string, any>>(
1027
993
  id: string,
@@ -1031,8 +997,8 @@ export class SanityClient {
1031
997
  * Deletes a document with the given document ID.
1032
998
  * Returns a promise that resolves to an array containing the deleted document.
1033
999
  *
1034
- * @param id Document ID to delete
1035
- * @param options Options for the mutation
1000
+ * @param id - Document ID to delete
1001
+ * @param options - Options for the mutation
1036
1002
  */
1037
1003
  delete<R extends Record<string, any> = Record<string, any>>(
1038
1004
  id: string,
@@ -1042,24 +1008,24 @@ export class SanityClient {
1042
1008
  * Deletes a document with the given document ID.
1043
1009
  * Returns a promise that resolves to a mutation result object containing the deleted document ID.
1044
1010
  *
1045
- * @param id Document ID to delete
1046
- * @param options Options for the mutation
1011
+ * @param id - Document ID to delete
1012
+ * @param options - Options for the mutation
1047
1013
  */
1048
1014
  delete(id: string, options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
1049
1015
  /**
1050
1016
  * Deletes a document with the given document ID.
1051
1017
  * Returns a promise that resolves to a mutation result object containing the deleted document ID.
1052
1018
  *
1053
- * @param id Document ID to delete
1054
- * @param options Options for the mutation
1019
+ * @param id - Document ID to delete
1020
+ * @param options - Options for the mutation
1055
1021
  */
1056
1022
  delete(id: string, options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
1057
1023
  /**
1058
1024
  * Deletes a document with the given document ID.
1059
1025
  * Returns a promise that resolves to the deleted document.
1060
1026
  *
1061
- * @param id Document ID to delete
1062
- * @param options Options for the mutation
1027
+ * @param id - Document ID to delete
1028
+ * @param options - Options for the mutation
1063
1029
  */
1064
1030
  delete<R extends Record<string, any> = Record<string, any>>(
1065
1031
  id: string,
@@ -1069,8 +1035,8 @@ export class SanityClient {
1069
1035
  * Deletes one or more documents matching the given query or document ID.
1070
1036
  * Returns a promise that resolves to first deleted document.
1071
1037
  *
1072
- * @param selection An object with either an `id` or `query` key defining what to delete
1073
- * @param options Options for the mutation
1038
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1039
+ * @param options - Options for the mutation
1074
1040
  */
1075
1041
  delete<R extends Record<string, any> = Record<string, any>>(
1076
1042
  selection: MutationSelection,
@@ -1080,8 +1046,8 @@ export class SanityClient {
1080
1046
  * Deletes one or more documents matching the given query or document ID.
1081
1047
  * Returns a promise that resolves to an array containing the deleted documents.
1082
1048
  *
1083
- * @param selection An object with either an `id` or `query` key defining what to delete
1084
- * @param options Options for the mutation
1049
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1050
+ * @param options - Options for the mutation
1085
1051
  */
1086
1052
  delete<R extends Record<string, any> = Record<string, any>>(
1087
1053
  selection: MutationSelection,
@@ -1091,8 +1057,8 @@ export class SanityClient {
1091
1057
  * Deletes one or more documents matching the given query or document ID.
1092
1058
  * Returns a promise that resolves to a mutation result object containing the ID of the first deleted document.
1093
1059
  *
1094
- * @param selection An object with either an `id` or `query` key defining what to delete
1095
- * @param options Options for the mutation
1060
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1061
+ * @param options - Options for the mutation
1096
1062
  */
1097
1063
  delete(
1098
1064
  selection: MutationSelection,
@@ -1102,8 +1068,8 @@ export class SanityClient {
1102
1068
  * Deletes one or more documents matching the given query or document ID.
1103
1069
  * Returns a promise that resolves to a mutation result object containing the document IDs that were deleted.
1104
1070
  *
1105
- * @param selection An object with either an `id` or `query` key defining what to delete
1106
- * @param options Options for the mutation
1071
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1072
+ * @param options - Options for the mutation
1107
1073
  */
1108
1074
  delete(
1109
1075
  selection: MutationSelection,
@@ -1113,8 +1079,8 @@ export class SanityClient {
1113
1079
  * Deletes one or more documents matching the given query or document ID.
1114
1080
  * Returns a promise that resolves to first deleted document.
1115
1081
  *
1116
- * @param selection An object with either an `id` or `query` key defining what to delete
1117
- * @param options Options for the mutation
1082
+ * @param selection - An object with either an `id` or `query` key defining what to delete
1083
+ * @param options - Options for the mutation
1118
1084
  */
1119
1085
  delete<R extends Record<string, any> = Record<string, any>>(
1120
1086
  selection: MutationSelection,
@@ -1138,8 +1104,8 @@ export class SanityClient {
1138
1104
  * Perform mutation operations against the configured dataset
1139
1105
  * Returns a promise that resolves to the first mutated document.
1140
1106
  *
1141
- * @param operations Mutation operations to execute
1142
- * @param options Mutation options
1107
+ * @param operations - Mutation operations to execute
1108
+ * @param options - Mutation options
1143
1109
  */
1144
1110
  mutate<R extends Record<string, any> = Record<string, any>>(
1145
1111
  operations: Mutation<R>[] | Patch | Transaction,
@@ -1149,8 +1115,8 @@ export class SanityClient {
1149
1115
  * Perform mutation operations against the configured dataset.
1150
1116
  * Returns a promise that resolves to an array of the mutated documents.
1151
1117
  *
1152
- * @param operations Mutation operations to execute
1153
- * @param options Mutation options
1118
+ * @param operations - Mutation operations to execute
1119
+ * @param options - Mutation options
1154
1120
  */
1155
1121
  mutate<R extends Record<string, any> = Record<string, any>>(
1156
1122
  operations: Mutation<R>[] | Patch | Transaction,
@@ -1160,8 +1126,8 @@ export class SanityClient {
1160
1126
  * Perform mutation operations against the configured dataset
1161
1127
  * Returns a promise that resolves to a mutation result object containing the document ID of the first mutated document.
1162
1128
  *
1163
- * @param operations Mutation operations to execute
1164
- * @param options Mutation options
1129
+ * @param operations - Mutation operations to execute
1130
+ * @param options - Mutation options
1165
1131
  */
1166
1132
  mutate<R extends Record<string, any> = Record<string, any>>(
1167
1133
  operations: Mutation<R>[] | Patch | Transaction,
@@ -1171,8 +1137,8 @@ export class SanityClient {
1171
1137
  * Perform mutation operations against the configured dataset
1172
1138
  * Returns a promise that resolves to a mutation result object containing the mutated document IDs.
1173
1139
  *
1174
- * @param operations Mutation operations to execute
1175
- * @param options Mutation options
1140
+ * @param operations - Mutation operations to execute
1141
+ * @param options - Mutation options
1176
1142
  */
1177
1143
  mutate<R extends Record<string, any>>(
1178
1144
  operations: Mutation<R>[] | Patch | Transaction,
@@ -1182,8 +1148,8 @@ export class SanityClient {
1182
1148
  * Perform mutation operations against the configured dataset
1183
1149
  * Returns a promise that resolves to the first mutated document.
1184
1150
  *
1185
- * @param operations Mutation operations to execute
1186
- * @param options Mutation options
1151
+ * @param operations - Mutation operations to execute
1152
+ * @param options - Mutation options
1187
1153
  */
1188
1154
  mutate<R extends Record<string, any> = Record<string, any>>(
1189
1155
  operations: Mutation<R>[] | Patch | Transaction,
@@ -1206,17 +1172,17 @@ export class SanityClient {
1206
1172
  /**
1207
1173
  * Create a new buildable patch of operations to perform
1208
1174
  *
1209
- * @param documentId Document ID to patch
1210
- * @param operations Optional object of patch operations to initialize the patch instance with
1175
+ * @param documentId - Document ID(s)to patch
1176
+ * @param operations - Optional object of patch operations to initialize the patch instance with
1211
1177
  */
1212
- patch(documentId: string | MutationSelection, operations?: PatchOperations): Patch {
1178
+ patch(documentId: PatchSelection, operations?: PatchOperations): Patch {
1213
1179
  return new Patch(documentId, operations, this)
1214
1180
  }
1215
1181
 
1216
1182
  /**
1217
1183
  * Create a new transaction of mutations
1218
1184
  *
1219
- * @param operations Optional array of mutation operations to initialize the transaction instance with
1185
+ * @param operations - Optional array of mutation operations to initialize the transaction instance with
1220
1186
  */
1221
1187
  transaction<R extends Record<string, any> = Record<string, any>>(
1222
1188
  operations?: Mutation<R>[]
@@ -1228,7 +1194,7 @@ export class SanityClient {
1228
1194
  * DEPRECATED: Perform an HTTP request against the Sanity API
1229
1195
  *
1230
1196
  * @deprecated Use your own request library!
1231
- * @param options Request options
1197
+ * @param options - Request options
1232
1198
  */
1233
1199
  request<R = any>(options: RawRequestOptions): Promise<R> {
1234
1200
  return lastValueFrom(dataMethods._request<R>(this, this.#httpRequest, options))
@@ -1238,38 +1204,11 @@ export class SanityClient {
1238
1204
  * DEPRECATED: Perform an HTTP request a `/data` sub-endpoint
1239
1205
  *
1240
1206
  * @deprecated Use your own request library!
1241
- * @param endpoint Endpoint to hit (mutate, query etc)
1242
- * @param body Request body
1243
- * @param options Request options
1207
+ * @param endpoint - Endpoint to hit (mutate, query etc)
1208
+ * @param body - Request body
1209
+ * @param options - Request options
1244
1210
  */
1245
1211
  dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<any> {
1246
1212
  return lastValueFrom(dataMethods._dataRequest(this, this.#httpRequest, endpoint, body, options))
1247
1213
  }
1248
-
1249
- /**
1250
- * DEPRECATED: Get a Sanity API URL for the URI provided
1251
- *
1252
- * @deprecated Should be an internal concern
1253
- * @param uri URI/path to build URL for
1254
- * @param canUseCdn Whether or not to allow using the API CDN for this route
1255
- */
1256
- getUrl(uri: string, canUseCdn = false) {
1257
- const base = canUseCdn ? this.#clientConfig.cdnUrl : this.#clientConfig.url
1258
- return `${base}/${uri.replace(/^\//, '')}`
1259
- }
1260
-
1261
- /**
1262
- * DEPRECATED: Get a Sanity API URL for the data operation and path provided
1263
- *
1264
- * @deprecated Should be an internal concern
1265
- * @param operation Data operation
1266
- * @param path Path to append
1267
- */
1268
- getDataUrl(operation: string, path?: string): string {
1269
- const config = this.config()
1270
- const catalog = validators.hasDataset(config)
1271
- const baseUri = `/${operation}/${catalog}`
1272
- const uri = path ? `${baseUri}/${path}` : baseUri
1273
- return `/data${uri}`.replace(/\/($|\?)/, '$1')
1274
- }
1275
1214
  }