@sanity/client 6.27.2 → 6.27.3-canary.1

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.d.cts CHANGED
@@ -405,7 +405,7 @@ export declare type ClientPerspective =
405
405
  | 'published'
406
406
  | 'drafts'
407
407
  | 'raw'
408
- | ('published' | 'drafts' | ReleaseId)[]
408
+ | StackablePerspective[]
409
409
 
410
410
  /** @public */
411
411
  export declare type ClientReturn<
@@ -2219,7 +2219,10 @@ export declare type ReconnectEvent = {
2219
2219
  type: 'reconnect'
2220
2220
  }
2221
2221
 
2222
- /** @public */
2222
+ /**
2223
+ * @public
2224
+ * @deprecated – The `r`-prefix is not required, use `string` instead
2225
+ */
2223
2226
  export declare type ReleaseId = `r${string}`
2224
2227
 
2225
2228
  /**
@@ -2994,6 +2997,9 @@ export declare interface SingleMutationResult {
2994
2997
  }[]
2995
2998
  }
2996
2999
 
3000
+ /** @public */
3001
+ export declare type StackablePerspective = ('published' | 'drafts' | string) & {}
3002
+
2997
3003
  /** @public */
2998
3004
  export declare interface StegaConfig {
2999
3005
  /**
package/dist/index.d.ts CHANGED
@@ -405,7 +405,7 @@ export declare type ClientPerspective =
405
405
  | 'published'
406
406
  | 'drafts'
407
407
  | 'raw'
408
- | ('published' | 'drafts' | ReleaseId)[]
408
+ | StackablePerspective[]
409
409
 
410
410
  /** @public */
411
411
  export declare type ClientReturn<
@@ -2219,7 +2219,10 @@ export declare type ReconnectEvent = {
2219
2219
  type: 'reconnect'
2220
2220
  }
2221
2221
 
2222
- /** @public */
2222
+ /**
2223
+ * @public
2224
+ * @deprecated – The `r`-prefix is not required, use `string` instead
2225
+ */
2223
2226
  export declare type ReleaseId = `r${string}`
2224
2227
 
2225
2228
  /**
@@ -2994,6 +2997,9 @@ export declare interface SingleMutationResult {
2994
2997
  }[]
2995
2998
  }
2996
2999
 
3000
+ /** @public */
3001
+ export declare type StackablePerspective = ('published' | 'drafts' | string) & {}
3002
+
2997
3003
  /** @public */
2998
3004
  export declare interface StegaConfig {
2999
3005
  /**
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
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, EMPTY } from "rxjs";
4
+ import { Observable, defer, isObservable, of, mergeMap, from, lastValueFrom, shareReplay, catchError, concat, timer, throwError, tap, finalize, share, merge, EMPTY } from "rxjs";
5
5
  import { stegaClean } from "./_chunks-es/stegaClean.js";
6
- import { combineLatestWith, map, filter } from "rxjs/operators";
6
+ import { combineLatestWith, map, filter, finalize as finalize$1 } from "rxjs/operators";
7
7
  import { validateObject, validateInsert, requireDocumentId, validateDocumentId, requestTag, validateApiPerspective, printCdnPreviewDraftsWarning, hasDataset, validateAssetType, dataset, defaultConfig, initConfig, printNoDefaultExport } from "./_chunks-es/config.js";
8
8
  class ClientError extends Error {
9
9
  response;
@@ -360,9 +360,9 @@ class BasePatch {
360
360
  reset() {
361
361
  return this.operations = {}, this;
362
362
  }
363
- _assign(op, props, merge = !0) {
363
+ _assign(op, props, merge2 = !0) {
364
364
  return validateObject(op, props), this.operations = Object.assign({}, this.operations, {
365
- [op]: Object.assign({}, merge && this.operations[op] || {}, props)
365
+ [op]: Object.assign({}, merge2 && this.operations[op] || {}, props)
366
366
  }), this;
367
367
  }
368
368
  _set(op, props) {
@@ -879,6 +879,28 @@ function _listen(query, params, opts = {}) {
879
879
  )
880
880
  );
881
881
  }
882
+ function shareReplayLatest(configOrPredicate, config) {
883
+ return _shareReplayLatest(
884
+ typeof configOrPredicate == "function" ? { predicate: configOrPredicate, ...config } : configOrPredicate
885
+ );
886
+ }
887
+ function _shareReplayLatest(config) {
888
+ return (source) => {
889
+ let latest, emitted = !1;
890
+ const { predicate, ...shareConfig } = config, wrapped = source.pipe(
891
+ tap((value) => {
892
+ config.predicate(value) && (emitted = !0, latest = value);
893
+ }),
894
+ finalize(() => {
895
+ emitted = !1, latest = void 0;
896
+ }),
897
+ share(shareConfig)
898
+ ), emitLatest = new Observable((subscriber) => {
899
+ emitted && subscriber.next(latest), subscriber.complete();
900
+ });
901
+ return merge(wrapped, emitLatest);
902
+ };
903
+ }
882
904
  const requiredApiVersion = "2021-03-25";
883
905
  class LiveClient {
884
906
  #client;
@@ -913,6 +935,9 @@ class LiveClient {
913
935
  includeDrafts && token && (esOptions.headers = {
914
936
  Authorization: `Bearer ${token}`
915
937
  }), includeDrafts && withCredentials && (esOptions.withCredentials = !0);
938
+ const key = `${url.href}::${JSON.stringify(esOptions)}`, existing = eventsCache.get(key);
939
+ if (existing)
940
+ return existing;
916
941
  const events = connectEventSource(() => (
917
942
  // use polyfill if there is no global EventSource or if we need to set headers
918
943
  (typeof EventSource > "u" || esOptions.headers ? eventSourcePolyfill : of(EventSource)).pipe(map((EventSource2) => new EventSource2(url.href, esOptions)))
@@ -940,8 +965,13 @@ class LiveClient {
940
965
  catchError(() => {
941
966
  throw new CorsOriginError({ projectId });
942
967
  })
968
+ ), observable2 = concat(checkCors, events).pipe(
969
+ finalize$1(() => eventsCache.delete(key)),
970
+ shareReplayLatest({
971
+ predicate: (event) => event.type === "welcome"
972
+ })
943
973
  );
944
- return concat(checkCors, events);
974
+ return eventsCache.set(key, observable2), observable2;
945
975
  }
946
976
  }
947
977
  function fetchObservable(url, init) {
@@ -957,6 +987,7 @@ function fetchObservable(url, init) {
957
987
  ), () => controller.abort();
958
988
  });
959
989
  }
990
+ const eventsCache = /* @__PURE__ */ new Map();
960
991
  class ObservableDatasetsClient {
961
992
  #client;
962
993
  #httpRequest;
@@ -1475,7 +1506,7 @@ function defineDeprecatedCreateClient(createClient2) {
1475
1506
  return printNoDefaultExport(), createClient2(config);
1476
1507
  };
1477
1508
  }
1478
- var name = "@sanity/client", version = "6.27.2";
1509
+ var name = "@sanity/client", version = "6.27.3-canary.1";
1479
1510
  const middleware = [
1480
1511
  debug({ verbose: !0, namespace: "sanity:client" }),
1481
1512
  headers({ "User-Agent": `${name} ${version}` }),