@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.
@@ -981,6 +981,35 @@ function _getDocuments(client, httpRequest, ids, opts = {}) {
981
981
  })
982
982
  );
983
983
  }
984
+ const DOCUMENTS_EXISTS_BATCH_SIZE = 100;
985
+ function _documentsExists(client, httpRequest, ids, opts = {}) {
986
+ if (ids.length === 0)
987
+ return rxjs.of(/* @__PURE__ */ new Set());
988
+ const batches = [];
989
+ for (let i = 0; i < ids.length; i += DOCUMENTS_EXISTS_BATCH_SIZE)
990
+ batches.push(ids.slice(i, i + DOCUMENTS_EXISTS_BATCH_SIZE));
991
+ const fetchBatch = (batchIds) => _requestObservable(client, httpRequest, {
992
+ uri: _getDataUrl(client, "doc", batchIds.map(encodeURIComponent).join(",")),
993
+ tag: opts.tag,
994
+ signal: opts.signal,
995
+ query: { excludeContent: !0 }
996
+ }).pipe(
997
+ operators.filter(isResponse),
998
+ operators.map((event) => {
999
+ const missing = /* @__PURE__ */ new Set();
1000
+ for (const omitted of event.body.omitted || [])
1001
+ omitted.reason === "existence" && missing.add(omitted.id);
1002
+ return new Set(batchIds.filter((id) => !missing.has(id)));
1003
+ })
1004
+ );
1005
+ return rxjs.from(batches).pipe(
1006
+ operators.concatMap(fetchBatch),
1007
+ operators.reduce((acc, set) => {
1008
+ for (const id of set) acc.add(id);
1009
+ return acc;
1010
+ }, /* @__PURE__ */ new Set())
1011
+ );
1012
+ }
984
1013
  function _getReleaseDocuments(client, httpRequest, releaseId, opts = {}) {
985
1014
  return _dataRequest(
986
1015
  client,
@@ -1117,7 +1146,7 @@ const hasDataConfig = (client) => {
1117
1146
  return config.dataset !== void 0 && config.projectId !== void 0 || config.resource !== void 0;
1118
1147
  }, 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);
1119
1148
  function _requestObservable(client, httpRequest, options) {
1120
- const uri = options.url || options.uri, config = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isData(client, uri) : options.canUseCdn;
1149
+ const callSiteStack = new Error(), uri = options.url || options.uri, config = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isData(client, uri) : options.canUseCdn;
1121
1150
  let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn;
1122
1151
  const tag = options.tag && config.requestTagPrefix ? [config.requestTagPrefix, options.tag].join(".") : options.tag || config.requestTagPrefix;
1123
1152
  if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && isQuery(client, uri)) {
@@ -1133,7 +1162,8 @@ function _requestObservable(client, httpRequest, options) {
1133
1162
  const reqOptions = requestOptions(
1134
1163
  config,
1135
1164
  Object.assign({}, options, {
1136
- url: _getUrl(client, uri, useCdn)
1165
+ url: _getUrl(client, uri, useCdn),
1166
+ callSiteStack
1137
1167
  })
1138
1168
  ), request = new rxjs.Observable(
1139
1169
  (subscriber) => httpRequest(reqOptions, config.requester).subscribe(subscriber)
@@ -2487,6 +2517,16 @@ class ObservableSanityClient {
2487
2517
  getDocuments(ids, options) {
2488
2518
  return _getDocuments(this, this.#httpRequest, ids, options);
2489
2519
  }
2520
+ /**
2521
+ * Convenient and bandwidth efficient method of checking wether a set of document IDs exists.
2522
+ * Returns a set of the IDs that exist.
2523
+ *
2524
+ * @param ids - Document IDs to check
2525
+ * @param options - Request options
2526
+ */
2527
+ documentsExists(ids, options) {
2528
+ return _documentsExists(this, this.#httpRequest, ids, options);
2529
+ }
2490
2530
  create(document, options) {
2491
2531
  return _create(this, this.#httpRequest, document, "create", options);
2492
2532
  }
@@ -2764,6 +2804,16 @@ class SanityClient {
2764
2804
  getDocuments(ids, options) {
2765
2805
  return rxjs.lastValueFrom(_getDocuments(this, this.#httpRequest, ids, options));
2766
2806
  }
2807
+ /**
2808
+ * Convenient and bandwidth efficient method of checking wether a set of document IDs exists.
2809
+ * Returns a set of the IDs that exist.
2810
+ *
2811
+ * @param ids - Document IDs to check
2812
+ * @param options - Request options
2813
+ */
2814
+ documentsExists(ids, options) {
2815
+ return rxjs.lastValueFrom(_documentsExists(this, this.#httpRequest, ids, options));
2816
+ }
2767
2817
  create(document, options) {
2768
2818
  return rxjs.lastValueFrom(
2769
2819
  _create(this, this.#httpRequest, document, "create", options)