@sanity/client 6.27.2 → 6.27.3-canary.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.browser.cjs +32 -1
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +36 -5
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +33 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +37 -6
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/data/live.ts +19 -2
- package/src/types.ts +0 -1
- package/src/util/shareReplayLatest.ts +71 -0
- package/umd/sanityClient.js +103 -3
- package/umd/sanityClient.min.js +2 -2
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,
|
|
363
|
+
_assign(op, props, merge2 = !0) {
|
|
364
364
|
return validateObject(op, props), this.operations = Object.assign({}, this.operations, {
|
|
365
|
-
[op]: Object.assign({},
|
|
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
|
+
shareReplayLatest({
|
|
970
|
+
predicate: (event) => event.type === "welcome"
|
|
971
|
+
}),
|
|
972
|
+
finalize$1(() => eventsCache.delete(key))
|
|
943
973
|
);
|
|
944
|
-
return
|
|
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.
|
|
1509
|
+
var name = "@sanity/client", version = "6.27.3-canary.0";
|
|
1479
1510
|
const middleware = [
|
|
1480
1511
|
debug({ verbose: !0, namespace: "sanity:client" }),
|
|
1481
1512
|
headers({ "User-Agent": `${name} ${version}` }),
|