@sanity/client 6.27.3-canary.2 → 6.28.0-instruct.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.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { getIt } from "get-it";
2
2
  import { adapter, environment } from "get-it";
3
3
  import { retry, jsonRequest, jsonResponse, progress, observable, debug, headers, agent } from "get-it/middleware";
4
- import { Observable, defer, isObservable, of, mergeMap, from, lastValueFrom, shareReplay, catchError, concat, timer, throwError, tap, finalize, share, merge, EMPTY } from "rxjs";
4
+ import { Observable, defer, of, isObservable, mergeMap, from, lastValueFrom, shareReplay, catchError, concat, throwError, timer, tap, finalize, share, merge, EMPTY } from "rxjs";
5
5
  import { stegaClean } from "./_chunks-es/stegaClean.js";
6
6
  import { combineLatestWith, map, filter, finalize as finalize$1 } from "rxjs/operators";
7
- import { validateObject, validateInsert, requireDocumentId, validateDocumentId, requestTag, validateApiPerspective, printCdnPreviewDraftsWarning, hasDataset, validateAssetType, dataset, defaultConfig, initConfig, printNoDefaultExport } from "./_chunks-es/config.js";
7
+ import { validateObject, validateInsert, requireDocumentId, validateDocumentId, hasDataset, requestTag, printPreviewDraftsDeprecationWarning, validateApiPerspective, printCdnPreviewDraftsWarning, validateAssetType, dataset, defaultConfig, initConfig, printNoDefaultExport } from "./_chunks-es/config.js";
8
8
  class ClientError extends Error {
9
9
  response;
10
10
  statusCode = 400;
@@ -728,10 +728,11 @@ function _requestObservable(client, httpRequest, options) {
728
728
  const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
729
729
  resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
730
730
  const perspectiveOption = options.perspective || config.perspective;
731
- typeof perspectiveOption < "u" && (validateApiPerspective(perspectiveOption), options.query = {
731
+ typeof perspectiveOption < "u" && (perspectiveOption === "previewDrafts" && printPreviewDraftsDeprecationWarning(), validateApiPerspective(perspectiveOption), options.query = {
732
732
  perspective: Array.isArray(perspectiveOption) ? perspectiveOption.join(",") : perspectiveOption,
733
733
  ...options.query
734
- }, perspectiveOption === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query }), useCdn && options.cacheMode == "noStale" && (options.query = { cacheMode: "noStale", ...options.query });
734
+ }, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
735
+ perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query }), useCdn && options.cacheMode == "noStale" && (options.query = { cacheMode: "noStale", ...options.query });
735
736
  }
736
737
  const reqOptions = requestOptions(
737
738
  config,
@@ -836,6 +837,42 @@ function optionsFromFile(opts, file) {
836
837
  opts
837
838
  );
838
839
  }
840
+ function _instruct(client, httpRequest, request) {
841
+ const dataset2 = hasDataset(client.config());
842
+ return _request(client, httpRequest, {
843
+ method: "POST",
844
+ uri: `/assist/tasks/instruct/${dataset2}`,
845
+ body: request
846
+ });
847
+ }
848
+ class ObservableAssistClient {
849
+ #client;
850
+ #httpRequest;
851
+ constructor(client, httpRequest) {
852
+ this.#client = client, this.#httpRequest = httpRequest;
853
+ }
854
+ /**
855
+ * Run an ad-hoc instruction for a target document.
856
+ * @param request instruction request
857
+ */
858
+ instruct(request) {
859
+ return _instruct(this.#client, this.#httpRequest, request);
860
+ }
861
+ }
862
+ class AssistClient {
863
+ #client;
864
+ #httpRequest;
865
+ constructor(client, httpRequest) {
866
+ this.#client = client, this.#httpRequest = httpRequest;
867
+ }
868
+ /**
869
+ * Run an ad-hoc instruction for a target document.
870
+ * @param request instruction request
871
+ */
872
+ instruct(request) {
873
+ return lastValueFrom(_instruct(this.#client, this.#httpRequest, request));
874
+ }
875
+ }
839
876
  var defaults = (obj, defaults2) => Object.keys(defaults2).concat(Object.keys(obj)).reduce((target, prop) => (target[prop] = typeof obj[prop] > "u" ? defaults2[prop] : obj[prop], target), {});
840
877
  const pick = (obj, props) => props.reduce((selection, prop) => (typeof obj[prop] > "u" || (selection[prop] = obj[prop]), selection), {}), eventSourcePolyfill = defer(() => import("@sanity/eventsource")).pipe(
841
878
  map(({ default: EventSource2 }) => EventSource2),
@@ -1168,6 +1205,7 @@ class ObservableSanityClient {
1168
1205
  live;
1169
1206
  projects;
1170
1207
  users;
1208
+ assist;
1171
1209
  /**
1172
1210
  * Private properties
1173
1211
  */
@@ -1178,7 +1216,7 @@ class ObservableSanityClient {
1178
1216
  */
1179
1217
  listen = _listen;
1180
1218
  constructor(httpRequest, config = defaultConfig) {
1181
- 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);
1219
+ 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), this.assist = new ObservableAssistClient(this, this.#httpRequest);
1182
1220
  }
1183
1221
  /**
1184
1222
  * Clone the client - returns a new instance
@@ -1317,6 +1355,7 @@ class SanityClient {
1317
1355
  live;
1318
1356
  projects;
1319
1357
  users;
1358
+ assist;
1320
1359
  /**
1321
1360
  * Observable version of the Sanity client, with the same configuration as the promise-based one
1322
1361
  */
@@ -1331,7 +1370,7 @@ class SanityClient {
1331
1370
  */
1332
1371
  listen = _listen;
1333
1372
  constructor(httpRequest, config = defaultConfig) {
1334
- 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);
1373
+ 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.assist = new AssistClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config);
1335
1374
  }
1336
1375
  /**
1337
1376
  * Clone the client - returns a new instance
@@ -1507,7 +1546,7 @@ function defineDeprecatedCreateClient(createClient2) {
1507
1546
  return printNoDefaultExport(), createClient2(config);
1508
1547
  };
1509
1548
  }
1510
- var name = "@sanity/client", version = "6.27.3-canary.2";
1549
+ var name = "@sanity/client", version = "6.28.0-instruct.0";
1511
1550
  const middleware = [
1512
1551
  debug({ verbose: !0, namespace: "sanity:client" }),
1513
1552
  headers({ "User-Agent": `${name} ${version}` }),