@sanity/client 7.22.1 → 7.23.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.cjs CHANGED
@@ -797,6 +797,35 @@ function _getDocuments(client, httpRequest, ids, opts = {}) {
797
797
  })
798
798
  );
799
799
  }
800
+ const DOCUMENTS_EXISTS_BATCH_SIZE = 100;
801
+ function _documentsExists(client, httpRequest, ids, opts = {}) {
802
+ if (ids.length === 0)
803
+ return rxjs.of(/* @__PURE__ */ new Set());
804
+ const batches = [];
805
+ for (let i = 0; i < ids.length; i += DOCUMENTS_EXISTS_BATCH_SIZE)
806
+ batches.push(ids.slice(i, i + DOCUMENTS_EXISTS_BATCH_SIZE));
807
+ const fetchBatch = (batchIds) => _requestObservable(client, httpRequest, {
808
+ uri: _getDataUrl(client, "doc", batchIds.map(encodeURIComponent).join(",")),
809
+ tag: opts.tag,
810
+ signal: opts.signal,
811
+ query: { excludeContent: !0 }
812
+ }).pipe(
813
+ operators.filter(isResponse),
814
+ operators.map((event) => {
815
+ const missing = /* @__PURE__ */ new Set();
816
+ for (const omitted of event.body.omitted || [])
817
+ omitted.reason === "existence" && missing.add(omitted.id);
818
+ return new Set(batchIds.filter((id) => !missing.has(id)));
819
+ })
820
+ );
821
+ return rxjs.from(batches).pipe(
822
+ operators.concatMap(fetchBatch),
823
+ operators.reduce((acc, set) => {
824
+ for (const id of set) acc.add(id);
825
+ return acc;
826
+ }, /* @__PURE__ */ new Set())
827
+ );
828
+ }
800
829
  function _getReleaseDocuments(client, httpRequest, releaseId, opts = {}) {
801
830
  return _dataRequest(
802
831
  client,
@@ -933,7 +962,7 @@ const hasDataConfig = (client) => {
933
962
  return config2.dataset !== void 0 && config2.projectId !== void 0 || config2.resource !== void 0;
934
963
  }, isQuery = (client, uri) => hasDataConfig(client) && uri.startsWith(_getDataUrl(client, "query")), isMutate = (client, uri) => hasDataConfig(client) && uri.startsWith(_getDataUrl(client, "mutate")), isDoc = (client, uri) => hasDataConfig(client) && uri.startsWith(_getDataUrl(client, "doc", "")), isListener = (client, uri) => hasDataConfig(client) && uri.startsWith(_getDataUrl(client, "listen")), isHistory = (client, uri) => hasDataConfig(client) && uri.startsWith(_getDataUrl(client, "history", "")), isData = (client, uri) => uri.startsWith("/data/") || isQuery(client, uri) || isMutate(client, uri) || isDoc(client, uri) || isListener(client, uri) || isHistory(client, uri);
935
964
  function _requestObservable(client, httpRequest, options) {
936
- const uri = options.url || options.uri, config$1 = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isData(client, uri) : options.canUseCdn;
965
+ const callSiteStack = new Error(), uri = options.url || options.uri, config$1 = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isData(client, uri) : options.canUseCdn;
937
966
  let useCdn = (options.useCdn ?? config$1.useCdn) && canUseCdn;
938
967
  const tag = options.tag && config$1.requestTagPrefix ? [config$1.requestTagPrefix, options.tag].join(".") : options.tag || config$1.requestTagPrefix;
939
968
  if (tag && options.tag !== null && (options.query = { tag: config.requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && isQuery(client, uri)) {
@@ -949,7 +978,8 @@ function _requestObservable(client, httpRequest, options) {
949
978
  const reqOptions = requestOptions(
950
979
  config$1,
951
980
  Object.assign({}, options, {
952
- url: _getUrl(client, uri, useCdn)
981
+ url: _getUrl(client, uri, useCdn),
982
+ callSiteStack
953
983
  })
954
984
  ), request = new rxjs.Observable(
955
985
  (subscriber) => httpRequest(reqOptions, config$1.requester).subscribe(subscriber)
@@ -2303,6 +2333,16 @@ class ObservableSanityClient {
2303
2333
  getDocuments(ids, options) {
2304
2334
  return _getDocuments(this, this.#httpRequest, ids, options);
2305
2335
  }
2336
+ /**
2337
+ * Convenient and bandwidth efficient method of checking wether a set of document IDs exists.
2338
+ * Returns a set of the IDs that exist.
2339
+ *
2340
+ * @param ids - Document IDs to check
2341
+ * @param options - Request options
2342
+ */
2343
+ documentsExists(ids, options) {
2344
+ return _documentsExists(this, this.#httpRequest, ids, options);
2345
+ }
2306
2346
  create(document, options) {
2307
2347
  return _create(this, this.#httpRequest, document, "create", options);
2308
2348
  }
@@ -2580,6 +2620,16 @@ class SanityClient {
2580
2620
  getDocuments(ids, options) {
2581
2621
  return rxjs.lastValueFrom(_getDocuments(this, this.#httpRequest, ids, options));
2582
2622
  }
2623
+ /**
2624
+ * Convenient and bandwidth efficient method of checking wether a set of document IDs exists.
2625
+ * Returns a set of the IDs that exist.
2626
+ *
2627
+ * @param ids - Document IDs to check
2628
+ * @param options - Request options
2629
+ */
2630
+ documentsExists(ids, options) {
2631
+ return rxjs.lastValueFrom(_documentsExists(this, this.#httpRequest, ids, options));
2632
+ }
2583
2633
  create(document, options) {
2584
2634
  return rxjs.lastValueFrom(
2585
2635
  _create(this, this.#httpRequest, document, "create", options)
@@ -2802,7 +2852,7 @@ function defineDeprecatedCreateClient(createClient2) {
2802
2852
  return config.printNoDefaultExport(), createClient2(config$1);
2803
2853
  };
2804
2854
  }
2805
- var name = "@sanity/client", version = "7.22.1";
2855
+ var name = "@sanity/client", version = "7.23.0";
2806
2856
  const middleware = [
2807
2857
  middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
2808
2858
  middleware$1.headers({ "User-Agent": `${name} ${version}` }),