@sanity/client 6.18.2 → 6.19.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/README.md CHANGED
@@ -1260,7 +1260,7 @@ The following options are available for mutations, and can be applied either as
1260
1260
  - `async`: request will return immediately when the changes have been committed, but it might still be a second or more until changes are reflected in a query. Unless you are immediately re-querying for something that includes the mutated data, this is the preferred choice.
1261
1261
  - `deferred`: fastest way to write - bypasses real-time indexing completely, and should be used in cases where you are bulk importing/mutating a large number of documents and don't need to see that data in a query for tens of seconds.
1262
1262
  - `dryRun` (`true|false`) - default `false`. If true, the mutation will be a dry run - the response will be identical to the one returned had this property been omitted or false (including error responses) but no documents will be affected.
1263
- - `autoGenerateArrayKeys` (`true|false`) - default `false`. If true, the mutation API will automatically add `_key` attributes to objects in arrays that is missing them. This makes array operations more robust by having a unique key within the array available for selections, which helps prevent race conditions in real-time, collaborative editing.
1263
+ - `autoGenerateArrayKeys` (`true|false`) - default `false`. If true, the mutation API will automatically add `_key` attributes to objects in arrays that are missing them. This makes array operations more robust by having a unique key within the array available for selections, which helps prevent race conditions in real-time, collaborative editing.
1264
1264
 
1265
1265
  ### Aborting a request
1266
1266
 
@@ -42,7 +42,7 @@ function extractErrorProps(res) {
42
42
  };
43
43
  if (body.error && body.message)
44
44
  return props.message = `${body.error} - ${body.message}`, props;
45
- if (isMutationError(body)) {
45
+ if (isMutationError(body) || isActionError(body)) {
46
46
  const allItems = body.error.items || [], items = allItems.slice(0, 5).map((item) => {
47
47
  var _a;
48
48
  return (_a = item.error) == null ? void 0 : _a.description;
@@ -58,6 +58,9 @@ function extractErrorProps(res) {
58
58
  function isMutationError(body) {
59
59
  return isPlainObject(body) && isPlainObject(body.error) && body.error.type === "mutationError" && typeof body.error.description == "string";
60
60
  }
61
+ function isActionError(body) {
62
+ return isPlainObject(body) && isPlainObject(body.error) && body.error.type === "actionError" && typeof body.error.description == "string";
63
+ }
61
64
  function isPlainObject(obj) {
62
65
  return typeof obj == "object" && obj !== null && !Array.isArray(obj);
63
66
  }
@@ -691,8 +694,18 @@ function _mutate(client, httpRequest, mutations, options) {
691
694
  const muts = Array.isArray(mut) ? mut : [mut], transactionId = options && options.transactionId || void 0;
692
695
  return _dataRequest(client, httpRequest, "mutate", { mutations: muts, transactionId }, options);
693
696
  }
697
+ function _action(client, httpRequest, actions, options) {
698
+ const acts = Array.isArray(actions) ? actions : [actions], transactionId = options && options.transactionId || void 0, skipCrossDatasetReferenceValidation = options && options.skipCrossDatasetReferenceValidation || void 0, dryRun = options && options.dryRun || void 0;
699
+ return _dataRequest(
700
+ client,
701
+ httpRequest,
702
+ "actions",
703
+ { actions: acts, transactionId, skipCrossDatasetReferenceValidation, dryRun },
704
+ options
705
+ );
706
+ }
694
707
  function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
695
- const isMutation = endpoint === "mutate", isQuery = endpoint === "query", strQuery = isMutation ? "" : encodeQueryString(body), useGet = !isMutation && strQuery.length < getQuerySizeLimit, stringQuery = useGet ? strQuery : "", returnFirst = options.returnFirst, { timeout, token, tag, headers, returnQuery, lastLiveEventId } = options, uri = _getDataUrl(client, endpoint, stringQuery), reqOptions = {
708
+ const isMutation = endpoint === "mutate", isAction = endpoint === "actions", isQuery = endpoint === "query", strQuery = isMutation || isAction ? "" : encodeQueryString(body), useGet = !isMutation && !isAction && strQuery.length < getQuerySizeLimit, stringQuery = useGet ? strQuery : "", returnFirst = options.returnFirst, { timeout, token, tag, headers, returnQuery, lastLiveEventId } = options, uri = _getDataUrl(client, endpoint, stringQuery), reqOptions = {
696
709
  method: useGet ? "GET" : "POST",
697
710
  uri,
698
711
  json: !0,
@@ -1304,6 +1317,15 @@ const _ObservableSanityClient = class _ObservableSanityClient2 {
1304
1317
  transaction(operations) {
1305
1318
  return new ObservableTransaction(operations, this);
1306
1319
  }
1320
+ /**
1321
+ * Perform action operations against the configured dataset
1322
+ *
1323
+ * @param operations - Action operation(s) to execute
1324
+ * @param options - Action options
1325
+ */
1326
+ action(operations, options) {
1327
+ return _action(this, __privateGet(this, _httpRequest), operations, options);
1328
+ }
1307
1329
  /**
1308
1330
  * Perform an HTTP request against the Sanity API
1309
1331
  *
@@ -1441,6 +1463,16 @@ const _SanityClient = class _SanityClient2 {
1441
1463
  transaction(operations) {
1442
1464
  return new Transaction(operations, this);
1443
1465
  }
1466
+ /**
1467
+ * Perform action operations against the configured dataset
1468
+ * Returns a promise that resolves to the transaction result
1469
+ *
1470
+ * @param operations - Action operation(s) to execute
1471
+ * @param options - Action options
1472
+ */
1473
+ action(operations, options) {
1474
+ return rxjs.lastValueFrom(_action(this, __privateGet(this, _httpRequest2), operations, options));
1475
+ }
1444
1476
  /**
1445
1477
  * Perform a request against the Sanity API
1446
1478
  * NOTE: Only use this for Sanity API endpoints, not for your own APIs!