@sanity/client 7.15.0 → 7.16.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.
@@ -2,7 +2,15 @@ import {lastValueFrom, type Observable} from 'rxjs'
2
2
 
3
3
  import {_request} from '../data/dataMethods'
4
4
  import type {ObservableSanityClient, SanityClient} from '../SanityClient'
5
- import type {DatasetAclMode, DatasetResponse, DatasetsResponse, HttpRequest} from '../types'
5
+ import type {
6
+ DatasetCreateOptions,
7
+ DatasetEditOptions,
8
+ DatasetResponse,
9
+ DatasetsResponse,
10
+ EmbeddingsSettings,
11
+ EmbeddingsSettingsBody,
12
+ HttpRequest,
13
+ } from '../types'
6
14
  import * as validate from '../validators'
7
15
 
8
16
  /** @internal */
@@ -18,9 +26,9 @@ export class ObservableDatasetsClient {
18
26
  * Create a new dataset with the given name
19
27
  *
20
28
  * @param name - Name of the dataset to create
21
- * @param options - Options for the dataset
29
+ * @param options - Options for the dataset, including optional embeddings configuration
22
30
  */
23
- create(name: string, options?: {aclMode?: DatasetAclMode}): Observable<DatasetResponse> {
31
+ create(name: string, options?: DatasetCreateOptions): Observable<DatasetResponse> {
24
32
  return _modify<DatasetResponse>(this.#client, this.#httpRequest, 'PUT', name, options)
25
33
  }
26
34
 
@@ -30,7 +38,7 @@ export class ObservableDatasetsClient {
30
38
  * @param name - Name of the dataset to edit
31
39
  * @param options - New options for the dataset
32
40
  */
33
- edit(name: string, options?: {aclMode?: DatasetAclMode}): Observable<DatasetResponse> {
41
+ edit(name: string, options?: DatasetEditOptions): Observable<DatasetResponse> {
34
42
  return _modify<DatasetResponse>(this.#client, this.#httpRequest, 'PATCH', name, options)
35
43
  }
36
44
 
@@ -60,6 +68,37 @@ export class ObservableDatasetsClient {
60
68
  tag: null,
61
69
  })
62
70
  }
71
+
72
+ /**
73
+ * Get embeddings settings for a dataset
74
+ *
75
+ * @param name - Name of the dataset
76
+ */
77
+ getEmbeddingsSettings(name: string): Observable<EmbeddingsSettings> {
78
+ validate.resourceGuard('dataset', this.#client.config())
79
+ validate.dataset(name)
80
+ return _request<EmbeddingsSettings>(this.#client, this.#httpRequest, {
81
+ uri: _embeddingsSettingsUri(this.#client, name),
82
+ tag: null,
83
+ })
84
+ }
85
+
86
+ /**
87
+ * Edit embeddings settings for a dataset
88
+ *
89
+ * @param name - Name of the dataset
90
+ * @param settings - Embeddings settings to apply
91
+ */
92
+ editEmbeddingsSettings(name: string, settings: EmbeddingsSettingsBody): Observable<void> {
93
+ validate.resourceGuard('dataset', this.#client.config())
94
+ validate.dataset(name)
95
+ return _request<void>(this.#client, this.#httpRequest, {
96
+ method: 'PUT',
97
+ uri: _embeddingsSettingsUri(this.#client, name),
98
+ body: settings,
99
+ tag: null,
100
+ })
101
+ }
63
102
  }
64
103
 
65
104
  /** @internal */
@@ -75,9 +114,9 @@ export class DatasetsClient {
75
114
  * Create a new dataset with the given name
76
115
  *
77
116
  * @param name - Name of the dataset to create
78
- * @param options - Options for the dataset
117
+ * @param options - Options for the dataset, including optional embeddings configuration
79
118
  */
80
- create(name: string, options?: {aclMode?: DatasetAclMode}): Promise<DatasetResponse> {
119
+ create(name: string, options?: DatasetCreateOptions): Promise<DatasetResponse> {
81
120
  validate.resourceGuard('dataset', this.#client.config())
82
121
  return lastValueFrom(
83
122
  _modify<DatasetResponse>(this.#client, this.#httpRequest, 'PUT', name, options),
@@ -90,7 +129,7 @@ export class DatasetsClient {
90
129
  * @param name - Name of the dataset to edit
91
130
  * @param options - New options for the dataset
92
131
  */
93
- edit(name: string, options?: {aclMode?: DatasetAclMode}): Promise<DatasetResponse> {
132
+ edit(name: string, options?: DatasetEditOptions): Promise<DatasetResponse> {
94
133
  validate.resourceGuard('dataset', this.#client.config())
95
134
  return lastValueFrom(
96
135
  _modify<DatasetResponse>(this.#client, this.#httpRequest, 'PATCH', name, options),
@@ -123,6 +162,52 @@ export class DatasetsClient {
123
162
  _request<DatasetsResponse>(this.#client, this.#httpRequest, {uri, tag: null}),
124
163
  )
125
164
  }
165
+
166
+ /**
167
+ * Get embeddings settings for a dataset
168
+ *
169
+ * @param name - Name of the dataset
170
+ */
171
+ getEmbeddingsSettings(name: string): Promise<EmbeddingsSettings> {
172
+ validate.resourceGuard('dataset', this.#client.config())
173
+ validate.dataset(name)
174
+ return lastValueFrom(
175
+ _request<EmbeddingsSettings>(this.#client, this.#httpRequest, {
176
+ uri: _embeddingsSettingsUri(this.#client, name),
177
+ tag: null,
178
+ }),
179
+ )
180
+ }
181
+
182
+ /**
183
+ * Edit embeddings settings for a dataset
184
+ *
185
+ * @param name - Name of the dataset
186
+ * @param settings - Embeddings settings to apply
187
+ */
188
+ editEmbeddingsSettings(name: string, settings: EmbeddingsSettingsBody): Promise<void> {
189
+ validate.resourceGuard('dataset', this.#client.config())
190
+ validate.dataset(name)
191
+ return lastValueFrom(
192
+ _request<void>(this.#client, this.#httpRequest, {
193
+ method: 'PUT',
194
+ uri: _embeddingsSettingsUri(this.#client, name),
195
+ body: settings,
196
+ tag: null,
197
+ }),
198
+ )
199
+ }
200
+ }
201
+
202
+ function _embeddingsSettingsUri(
203
+ client: SanityClient | ObservableSanityClient,
204
+ name: string,
205
+ ): string {
206
+ const config = client.config()
207
+ if (config.useProjectHostname === false) {
208
+ return `/projects/${config.projectId}/datasets/${name}/settings/embeddings`
209
+ }
210
+ return `/datasets/${name}/settings/embeddings`
126
211
  }
127
212
 
128
213
  function _modify<R = unknown>(
@@ -130,7 +215,7 @@ function _modify<R = unknown>(
130
215
  httpRequest: HttpRequest,
131
216
  method: 'DELETE' | 'PATCH' | 'PUT',
132
217
  name: string,
133
- options?: {aclMode?: DatasetAclMode},
218
+ options?: DatasetCreateOptions | DatasetEditOptions,
134
219
  ) {
135
220
  validate.resourceGuard('dataset', client.config())
136
221
  validate.dataset(name)
package/src/types.ts CHANGED
@@ -463,6 +463,33 @@ export type AuthProviderResponse = {providers: AuthProvider[]}
463
463
  /** @public */
464
464
  export type DatasetAclMode = 'public' | 'private' | 'custom'
465
465
 
466
+ /** @public */
467
+ export type DatasetCreateOptions = {
468
+ aclMode?: DatasetAclMode
469
+ embeddings?: {
470
+ enabled: boolean
471
+ projection?: string
472
+ }
473
+ }
474
+
475
+ /** @public */
476
+ export type DatasetEditOptions = {
477
+ aclMode?: DatasetAclMode
478
+ }
479
+
480
+ /** @public */
481
+ export type EmbeddingsSettings = {
482
+ enabled: boolean
483
+ projection?: string
484
+ status: string
485
+ }
486
+
487
+ /** @public */
488
+ export type EmbeddingsSettingsBody = {
489
+ enabled: boolean
490
+ projection?: string
491
+ }
492
+
466
493
  /** @public */
467
494
  export type DatasetResponse = {datasetName: string; aclMode: DatasetAclMode}
468
495
  /** @public */
@@ -3495,7 +3495,7 @@ ${selectionOpts}`);
3495
3495
  * Create a new dataset with the given name
3496
3496
  *
3497
3497
  * @param name - Name of the dataset to create
3498
- * @param options - Options for the dataset
3498
+ * @param options - Options for the dataset, including optional embeddings configuration
3499
3499
  */
3500
3500
  create(name, options) {
3501
3501
  return _modify(this.#client, this.#httpRequest, "PUT", name, options);
@@ -3529,6 +3529,31 @@ ${selectionOpts}`);
3529
3529
  tag: null
3530
3530
  });
3531
3531
  }
3532
+ /**
3533
+ * Get embeddings settings for a dataset
3534
+ *
3535
+ * @param name - Name of the dataset
3536
+ */
3537
+ getEmbeddingsSettings(name) {
3538
+ return resourceGuard("dataset", this.#client.config()), dataset(name), _request(this.#client, this.#httpRequest, {
3539
+ uri: _embeddingsSettingsUri(this.#client, name),
3540
+ tag: null
3541
+ });
3542
+ }
3543
+ /**
3544
+ * Edit embeddings settings for a dataset
3545
+ *
3546
+ * @param name - Name of the dataset
3547
+ * @param settings - Embeddings settings to apply
3548
+ */
3549
+ editEmbeddingsSettings(name, settings) {
3550
+ return resourceGuard("dataset", this.#client.config()), dataset(name), _request(this.#client, this.#httpRequest, {
3551
+ method: "PUT",
3552
+ uri: _embeddingsSettingsUri(this.#client, name),
3553
+ body: settings,
3554
+ tag: null
3555
+ });
3556
+ }
3532
3557
  }
3533
3558
  class DatasetsClient {
3534
3559
  #client;
@@ -3540,7 +3565,7 @@ ${selectionOpts}`);
3540
3565
  * Create a new dataset with the given name
3541
3566
  *
3542
3567
  * @param name - Name of the dataset to create
3543
- * @param options - Options for the dataset
3568
+ * @param options - Options for the dataset, including optional embeddings configuration
3544
3569
  */
3545
3570
  create(name, options) {
3546
3571
  return resourceGuard("dataset", this.#client.config()), lastValueFrom(
@@ -3577,6 +3602,39 @@ ${selectionOpts}`);
3577
3602
  _request(this.#client, this.#httpRequest, { uri, tag: null })
3578
3603
  );
3579
3604
  }
3605
+ /**
3606
+ * Get embeddings settings for a dataset
3607
+ *
3608
+ * @param name - Name of the dataset
3609
+ */
3610
+ getEmbeddingsSettings(name) {
3611
+ return resourceGuard("dataset", this.#client.config()), dataset(name), lastValueFrom(
3612
+ _request(this.#client, this.#httpRequest, {
3613
+ uri: _embeddingsSettingsUri(this.#client, name),
3614
+ tag: null
3615
+ })
3616
+ );
3617
+ }
3618
+ /**
3619
+ * Edit embeddings settings for a dataset
3620
+ *
3621
+ * @param name - Name of the dataset
3622
+ * @param settings - Embeddings settings to apply
3623
+ */
3624
+ editEmbeddingsSettings(name, settings) {
3625
+ return resourceGuard("dataset", this.#client.config()), dataset(name), lastValueFrom(
3626
+ _request(this.#client, this.#httpRequest, {
3627
+ method: "PUT",
3628
+ uri: _embeddingsSettingsUri(this.#client, name),
3629
+ body: settings,
3630
+ tag: null
3631
+ })
3632
+ );
3633
+ }
3634
+ }
3635
+ function _embeddingsSettingsUri(client, name) {
3636
+ const config = client.config();
3637
+ return config.useProjectHostname === false ? `/projects/${config.projectId}/datasets/${name}/settings/embeddings` : `/datasets/${name}/settings/embeddings`;
3580
3638
  }
3581
3639
  function _modify(client, httpRequest, method, name, options) {
3582
3640
  return resourceGuard("dataset", client.config()), dataset(name), _request(client, httpRequest, {