@sanity/client 6.27.3-canary.1 → 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),
@@ -852,6 +889,7 @@ const MAX_URL_LENGTH = 14800, possibleOptions = [
852
889
  "includePreviousRevision",
853
890
  "includeResult",
854
891
  "includeMutations",
892
+ "includeAllVersions",
855
893
  "visibility",
856
894
  "effectFormat",
857
895
  "tag"
@@ -1167,6 +1205,7 @@ class ObservableSanityClient {
1167
1205
  live;
1168
1206
  projects;
1169
1207
  users;
1208
+ assist;
1170
1209
  /**
1171
1210
  * Private properties
1172
1211
  */
@@ -1177,7 +1216,7 @@ class ObservableSanityClient {
1177
1216
  */
1178
1217
  listen = _listen;
1179
1218
  constructor(httpRequest, config = defaultConfig) {
1180
- 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);
1181
1220
  }
1182
1221
  /**
1183
1222
  * Clone the client - returns a new instance
@@ -1316,6 +1355,7 @@ class SanityClient {
1316
1355
  live;
1317
1356
  projects;
1318
1357
  users;
1358
+ assist;
1319
1359
  /**
1320
1360
  * Observable version of the Sanity client, with the same configuration as the promise-based one
1321
1361
  */
@@ -1330,7 +1370,7 @@ class SanityClient {
1330
1370
  */
1331
1371
  listen = _listen;
1332
1372
  constructor(httpRequest, config = defaultConfig) {
1333
- 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);
1334
1374
  }
1335
1375
  /**
1336
1376
  * Clone the client - returns a new instance
@@ -1506,7 +1546,7 @@ function defineDeprecatedCreateClient(createClient2) {
1506
1546
  return printNoDefaultExport(), createClient2(config);
1507
1547
  };
1508
1548
  }
1509
- var name = "@sanity/client", version = "6.27.3-canary.1";
1549
+ var name = "@sanity/client", version = "6.28.0-instruct.0";
1510
1550
  const middleware = [
1511
1551
  debug({ verbose: !0, namespace: "sanity:client" }),
1512
1552
  headers({ "User-Agent": `${name} ${version}` }),