@sanity/client 7.0.0 → 7.0.1-canary.1

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.
@@ -16,8 +16,104 @@ import type {
16
16
  } from '../types'
17
17
  import * as validators from '../validators'
18
18
 
19
+ /**
20
+ * The interface implemented by the `ObservableAssetsClient` class.
21
+ * When writing code that wants to take an instance of `ObservableAssetsClient` as input it's better to use this type,
22
+ * as the `ObservableAssetsClient` class has private properties and thus TypeScript will consider the type incompatible
23
+ * in cases where you might have multiple `@sanity/client` instances in your node_modules.
24
+ * @public
25
+ */
26
+ export interface ObservableAssetsClientType {
27
+ /**
28
+ * Uploads a file asset to the configured dataset
29
+ *
30
+ * @param assetType - Asset type (file)
31
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
32
+ * @param options - Options to use for the upload
33
+ */
34
+ upload(
35
+ assetType: 'file',
36
+ body: UploadBody,
37
+ options?: UploadClientConfig,
38
+ ): Observable<HttpRequestEvent<{document: SanityAssetDocument}>>
39
+
40
+ /**
41
+ * Uploads an image asset to the configured dataset
42
+ *
43
+ * @param assetType - Asset type (image)
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: 'image',
49
+ body: UploadBody,
50
+ options?: UploadClientConfig,
51
+ ): Observable<HttpRequestEvent<{document: SanityImageAssetDocument}>>
52
+
53
+ /**
54
+ * Uploads a file or an image asset to the configured dataset
55
+ *
56
+ * @param assetType - Asset type (file/image)
57
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
58
+ * @param options - Options to use for the upload
59
+ */
60
+ upload(
61
+ assetType: 'file' | 'image',
62
+ body: UploadBody,
63
+ options?: UploadClientConfig,
64
+ ): Observable<HttpRequestEvent<{document: SanityAssetDocument | SanityImageAssetDocument}>>
65
+ }
66
+
67
+ /**
68
+ * The interface implemented by the `AssetsClient` class.
69
+ * When writing code that wants to take an instance of `AssetsClient` as input it's better to use this type,
70
+ * as the `AssetsClient` class has private properties and thus TypeScript will consider the type incompatible
71
+ * in cases where you might have multiple `@sanity/client` instances in your node_modules.
72
+ * @public
73
+ */
74
+ export interface AssetsClientType {
75
+ /**
76
+ * Uploads a file asset to the configured dataset
77
+ *
78
+ * @param assetType - Asset type (file)
79
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
80
+ * @param options - Options to use for the upload
81
+ */
82
+ upload(
83
+ assetType: 'file',
84
+ body: UploadBody,
85
+ options?: UploadClientConfig,
86
+ ): Promise<SanityAssetDocument>
87
+
88
+ /**
89
+ * Uploads an image asset to the configured dataset
90
+ *
91
+ * @param assetType - Asset type (image)
92
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
93
+ * @param options - Options to use for the upload
94
+ */
95
+ upload(
96
+ assetType: 'image',
97
+ body: UploadBody,
98
+ options?: UploadClientConfig,
99
+ ): Promise<SanityImageAssetDocument>
100
+
101
+ /**
102
+ * Uploads a file or an image asset to the configured dataset
103
+ *
104
+ * @param assetType - Asset type (file/image)
105
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
106
+ * @param options - Options to use for the upload
107
+ */
108
+ upload(
109
+ assetType: 'file' | 'image',
110
+ body: UploadBody,
111
+ options?: UploadClientConfig,
112
+ ): Promise<SanityAssetDocument | SanityImageAssetDocument>
113
+ }
114
+
19
115
  /** @internal */
20
- export class ObservableAssetsClient {
116
+ export class ObservableAssetsClient implements ObservableAssetsClientType {
21
117
  #client: ObservableSanityClient
22
118
  #httpRequest: HttpRequest
23
119
  constructor(client: ObservableSanityClient, httpRequest: HttpRequest) {
@@ -72,7 +168,7 @@ export class ObservableAssetsClient {
72
168
  }
73
169
 
74
170
  /** @internal */
75
- export class AssetsClient {
171
+ export class AssetsClient implements AssetsClientType {
76
172
  #client: SanityClient
77
173
  #httpRequest: HttpRequest
78
174
  constructor(client: SanityClient, httpRequest: HttpRequest) {
@@ -3291,14 +3291,8 @@ ${selectionOpts}`);
3291
3291
  live;
3292
3292
  projects;
3293
3293
  users;
3294
- /**
3295
- * Private properties
3296
- */
3297
3294
  #clientConfig;
3298
3295
  #httpRequest;
3299
- /**
3300
- * Instance properties
3301
- */
3302
3296
  listen = _listen;
3303
3297
  constructor(httpRequest, config = defaultConfig) {
3304
3298
  this.config(config), this.#httpRequest = httpRequest, this.assets = new ObservableAssetsClient(this, this.#httpRequest), this.datasets = new ObservableDatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ObservableProjectsClient(this, this.#httpRequest), this.users = new ObservableUsersClient(this, this.#httpRequest);
@@ -3444,14 +3438,8 @@ ${selectionOpts}`);
3444
3438
  * Observable version of the Sanity client, with the same configuration as the promise-based one
3445
3439
  */
3446
3440
  observable;
3447
- /**
3448
- * Private properties
3449
- */
3450
3441
  #clientConfig;
3451
3442
  #httpRequest;
3452
- /**
3453
- * Instance properties
3454
- */
3455
3443
  listen = _listen;
3456
3444
  constructor(httpRequest, config = defaultConfig) {
3457
3445
  this.config(config), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config);
@@ -3548,8 +3536,8 @@ ${selectionOpts}`);
3548
3536
  * @param operations - Optional object of patch operations to initialize the patch instance with
3549
3537
  * @returns Patch instance - call `.commit()` to perform the operations defined
3550
3538
  */
3551
- patch(documentId, operations) {
3552
- return new Patch(documentId, operations, this);
3539
+ patch(selection, operations) {
3540
+ return new Patch(selection, operations, this);
3553
3541
  }
3554
3542
  /**
3555
3543
  * Create a new transaction of mutations