@sanity/client 5.0.0-esm.9 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  /// <reference types="node" />
2
2
 
3
- import {BaseError} from 'make-error'
4
3
  import {Observable} from 'rxjs'
5
4
  import {Requester} from 'get-it'
6
5
 
@@ -33,7 +32,7 @@ export declare class AssetsClient {
33
32
  /**
34
33
  * Uploads a file asset to the configured dataset
35
34
  *
36
- * @param assetType - Asset type (file/image)
35
+ * @param assetType - Asset type (file)
37
36
  * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
38
37
  * @param options - Options to use for the upload
39
38
  */
@@ -45,7 +44,7 @@ export declare class AssetsClient {
45
44
  /**
46
45
  * Uploads an image asset to the configured dataset
47
46
  *
48
- * @param assetType - Asset type (file/image)
47
+ * @param assetType - Asset type (image)
49
48
  * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
50
49
  * @param options - Options to use for the upload
51
50
  */
@@ -54,6 +53,18 @@ export declare class AssetsClient {
54
53
  body: File | Blob | Buffer | NodeJS.ReadableStream,
55
54
  options?: UploadClientConfig
56
55
  ): Promise<SanityImageAssetDocument>
56
+ /**
57
+ * Uploads a file or an image asset to the configured dataset
58
+ *
59
+ * @param assetType - Asset type (file/image)
60
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
61
+ * @param options - Options to use for the upload
62
+ */
63
+ upload(
64
+ assetType: 'file' | 'image',
65
+ body: File | Blob | Buffer | NodeJS.ReadableStream,
66
+ options?: UploadClientConfig
67
+ ): Promise<SanityAssetDocument | SanityImageAssetDocument>
57
68
  }
58
69
 
59
70
  /** @internal */
@@ -61,20 +72,6 @@ export declare type AttributeSet = {
61
72
  [key: string]: FIXME
62
73
  }
63
74
 
64
- /** @internal */
65
- export declare class AuthClient {
66
- #private
67
- constructor(client: SanityClient, httpRequest: HttpRequest)
68
- /**
69
- * Fetch available login providers
70
- */
71
- getLoginProviders(): Promise<AuthProviderResponse>
72
- /**
73
- * Revoke the configured session/token
74
- */
75
- logout(): Promise<void>
76
- }
77
-
78
75
  /** @internal */
79
76
  export declare interface AuthProvider {
80
77
  name: string
@@ -102,14 +99,6 @@ export declare class BasePatch {
102
99
  protected selection: PatchSelection
103
100
  protected operations: PatchOperations
104
101
  constructor(selection: PatchSelection, operations?: PatchOperations)
105
- /**
106
- * DEPRECATED: Don't use.
107
- * The operation is added to the current patch, ready to be commited by `commit()`
108
- *
109
- * @deprecated - Don't use.
110
- * @param attrs - Attributes to replace
111
- */
112
- replace(attrs: AttributeSet): this
113
102
  /**
114
103
  * Sets the given attributes to the document. Does NOT merge objects.
115
104
  * The operation is added to the current patch, ready to be commited by `commit()`
@@ -178,7 +167,7 @@ export declare class BasePatch {
178
167
  * @param selector - Attribute or JSONPath expression for array
179
168
  * @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
180
169
  * @param deleteCount - An integer indicating the number of old array elements to remove.
181
- * @param items - The elements to add to the array, beginning at the start index. If you don't specify FIXME elements, splice() will only remove elements from the array.
170
+ * @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.
182
171
  */
183
172
  splice(selector: string, start: number, deleteCount?: number, items?: FIXME[]): this
184
173
  /**
@@ -296,7 +285,7 @@ export declare interface ClientConfig {
296
285
  }
297
286
 
298
287
  /** @public */
299
- export declare class ClientError extends BaseError {
288
+ export declare class ClientError extends Error {
300
289
  response: ErrorProps['response']
301
290
  statusCode: ErrorProps['statusCode']
302
291
  responseBody: ErrorProps['responseBody']
@@ -473,7 +462,7 @@ export declare type InsertPatch =
473
462
  * @internal
474
463
  */
475
464
  export declare function _listen<R extends Record<string, FIXME> = Record<string, FIXME>>(
476
- this: SanityClient,
465
+ this: SanityClient | ObservableSanityClient,
477
466
  query: string,
478
467
  params?: QueryParams
479
468
  ): Observable<MutationEvent_2<R>>
@@ -487,7 +476,7 @@ export declare function _listen<R extends Record<string, FIXME> = Record<string,
487
476
  * @internal
488
477
  */
489
478
  export declare function _listen<R extends Record<string, FIXME> = Record<string, FIXME>>(
490
- this: SanityClient,
479
+ this: SanityClient | ObservableSanityClient,
491
480
  query: string,
492
481
  params?: QueryParams,
493
482
  options?: ListenOptions
@@ -584,7 +573,7 @@ export declare class ObservableAssetsClient {
584
573
  /**
585
574
  * Uploads a file asset to the configured dataset
586
575
  *
587
- * @param assetType - Asset type (file/image)
576
+ * @param assetType - Asset type (file)
588
577
  * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
589
578
  * @param options - Options to use for the upload
590
579
  */
@@ -600,7 +589,7 @@ export declare class ObservableAssetsClient {
600
589
  /**
601
590
  * Uploads an image asset to the configured dataset
602
591
  *
603
- * @param assetType - Asset type (file/image)
592
+ * @param assetType - Asset type (image)
604
593
  * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
605
594
  * @param options - Options to use for the upload
606
595
  */
@@ -613,20 +602,22 @@ export declare class ObservableAssetsClient {
613
602
  document: SanityImageAssetDocument
614
603
  }>
615
604
  >
616
- }
617
-
618
- /** @internal */
619
- export declare class ObservableAuthClient {
620
- #private
621
- constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
622
- /**
623
- * Fetch available login providers
624
- */
625
- getLoginProviders(): Observable<AuthProviderResponse>
626
605
  /**
627
- * Revoke the configured session/token
606
+ * Uploads a file or an image asset to the configured dataset
607
+ *
608
+ * @param assetType - Asset type (file/image)
609
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
610
+ * @param options - Options to use for the upload
628
611
  */
629
- logout(): Observable<void>
612
+ upload(
613
+ assetType: 'file' | 'image',
614
+ body: File | Blob | Buffer | NodeJS.ReadableStream,
615
+ options?: UploadClientConfig
616
+ ): Observable<
617
+ HttpRequestEvent<{
618
+ document: SanityAssetDocument | SanityImageAssetDocument
619
+ }>
620
+ >
630
621
  }
631
622
 
632
623
  /** @internal */
@@ -744,10 +735,13 @@ export declare class ObservableProjectsClient {
744
735
  export declare class ObservableSanityClient {
745
736
  #private
746
737
  assets: ObservableAssetsClient
747
- auth: ObservableAuthClient
748
738
  datasets: ObservableDatasetsClient
749
739
  projects: ObservableProjectsClient
750
740
  users: ObservableUsersClient
741
+ /**
742
+ * Instance properties
743
+ */
744
+ listen: typeof _listen
751
745
  constructor(httpRequest: HttpRequest, config?: ClientConfig)
752
746
  /**
753
747
  * Clone the client - returns a new instance
@@ -779,7 +773,7 @@ export declare class ObservableSanityClient {
779
773
  * @param query - GROQ-query to perform
780
774
  * @param params - Query parameters
781
775
  */
782
- fetch<R = FIXME>(query: string, params: QueryParams): Observable<R>
776
+ fetch<R = FIXME, Q = QueryParams>(query: string, params: Q): Observable<R>
783
777
  /**
784
778
  * Perform a GROQ-query against the configured dataset.
785
779
  *
@@ -787,9 +781,9 @@ export declare class ObservableSanityClient {
787
781
  * @param params - Query parameters
788
782
  * @param options - Request options
789
783
  */
790
- fetch<R = FIXME>(
784
+ fetch<R = FIXME, Q = QueryParams>(
791
785
  query: string,
792
- params: QueryParams | undefined,
786
+ params: Q | undefined,
793
787
  options: FilteredResponseQueryOptions
794
788
  ): Observable<R>
795
789
  /**
@@ -799,9 +793,9 @@ export declare class ObservableSanityClient {
799
793
  * @param params - Query parameters
800
794
  * @param options - Request options
801
795
  */
802
- fetch<R = FIXME>(
796
+ fetch<R = FIXME, Q = QueryParams>(
803
797
  query: string,
804
- params: QueryParams | undefined,
798
+ params: Q | undefined,
805
799
  options: UnfilteredResponseQueryOptions
806
800
  ): Observable<RawQueryResponse<R>>
807
801
  /**
@@ -820,7 +814,7 @@ export declare class ObservableSanityClient {
820
814
  * Fetch multiple documents in one request.
821
815
  * Should be used sparingly - performing a query is usually a better option.
822
816
  * The order/position of documents is preserved based on the original array of IDs.
823
- * If a FIXME of the documents are missing, they will be replaced by a `null` entry in the returned array
817
+ * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
824
818
  *
825
819
  * @param ids - Document IDs to fetch
826
820
  * @param options - Request options
@@ -1445,7 +1439,6 @@ export declare interface SanityAssetDocument extends SanityDocument {
1445
1439
  export declare class SanityClient {
1446
1440
  #private
1447
1441
  assets: AssetsClient
1448
- auth: AuthClient
1449
1442
  datasets: DatasetsClient
1450
1443
  projects: ProjectsClient
1451
1444
  users: UsersClient
@@ -1488,7 +1481,7 @@ export declare class SanityClient {
1488
1481
  * @param query - GROQ-query to perform
1489
1482
  * @param params - Optional query parameters
1490
1483
  */
1491
- fetch<R = FIXME>(query: string, params: QueryParams): Promise<R>
1484
+ fetch<R = FIXME, Q = QueryParams>(query: string, params: Q): Promise<R>
1492
1485
  /**
1493
1486
  * Perform a GROQ-query against the configured dataset.
1494
1487
  *
@@ -1496,9 +1489,9 @@ export declare class SanityClient {
1496
1489
  * @param params - Optional query parameters
1497
1490
  * @param options - Request options
1498
1491
  */
1499
- fetch<R = FIXME>(
1492
+ fetch<R = FIXME, Q = QueryParams>(
1500
1493
  query: string,
1501
- params: QueryParams | undefined,
1494
+ params: Q | undefined,
1502
1495
  options: FilteredResponseQueryOptions
1503
1496
  ): Promise<R>
1504
1497
  /**
@@ -1508,9 +1501,9 @@ export declare class SanityClient {
1508
1501
  * @param params - Optional query parameters
1509
1502
  * @param options - Request options
1510
1503
  */
1511
- fetch<R = FIXME>(
1504
+ fetch<R = FIXME, Q = QueryParams>(
1512
1505
  query: string,
1513
- params: QueryParams | undefined,
1506
+ params: Q | undefined,
1514
1507
  options: UnfilteredResponseQueryOptions
1515
1508
  ): Promise<RawQueryResponse<R>>
1516
1509
  /**
@@ -1529,7 +1522,7 @@ export declare class SanityClient {
1529
1522
  * Fetch multiple documents in one request.
1530
1523
  * Should be used sparingly - performing a query is usually a better option.
1531
1524
  * The order/position of documents is preserved based on the original array of IDs.
1532
- * If a FIXME of the documents are missing, they will be replaced by a `null` entry in the returned array
1525
+ * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
1533
1526
  *
1534
1527
  * @param ids - Document IDs to fetch
1535
1528
  * @param options - Request options
@@ -2005,7 +1998,7 @@ export declare interface SanityUser {
2005
1998
  }
2006
1999
 
2007
2000
  /** @public */
2008
- export declare class ServerError extends BaseError {
2001
+ export declare class ServerError extends Error {
2009
2002
  response: ErrorProps['response']
2010
2003
  statusCode: ErrorProps['statusCode']
2011
2004
  responseBody: ErrorProps['responseBody']