@sanity/client 6.17.3 → 6.18.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 +117 -45
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +34 -0
- package/dist/index.browser.d.ts +34 -0
- package/dist/index.browser.js +117 -45
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +118 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +118 -46
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/SanityClient.ts +6 -0
- package/src/data/dataMethods.ts +6 -1
- package/src/data/live.ts +126 -0
- package/src/types.ts +21 -0
- package/umd/sanityClient.js +131 -59
- package/umd/sanityClient.min.js +3 -3
package/dist/index.browser.cjs
CHANGED
|
@@ -159,14 +159,14 @@ const VALID_ASSET_TYPES = ["image", "file"], VALID_INSERT_LOCATIONS = ["before",
|
|
|
159
159
|
);
|
|
160
160
|
return tag;
|
|
161
161
|
};
|
|
162
|
-
var __defProp$2 = Object.defineProperty, __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$2 = (obj, key, value) => (__defNormalProp$2(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck$
|
|
162
|
+
var __defProp$2 = Object.defineProperty, __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$2 = (obj, key, value) => (__defNormalProp$2(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck$7 = (obj, member, msg) => {
|
|
163
163
|
if (!member.has(obj))
|
|
164
164
|
throw TypeError("Cannot " + msg);
|
|
165
|
-
}, __privateGet$
|
|
165
|
+
}, __privateGet$7 = (obj, member, getter) => (__accessCheck$7(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$7 = (obj, member, value) => {
|
|
166
166
|
if (member.has(obj))
|
|
167
167
|
throw TypeError("Cannot add the same private member more than once");
|
|
168
168
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
169
|
-
}, __privateSet$
|
|
169
|
+
}, __privateSet$7 = (obj, member, value, setter) => (__accessCheck$7(obj, member, "write to private field"), member.set(obj, value), value);
|
|
170
170
|
class BasePatch {
|
|
171
171
|
constructor(selection, operations = {}) {
|
|
172
172
|
__publicField$2(this, "selection"), __publicField$2(this, "operations"), this.selection = selection, this.operations = operations;
|
|
@@ -300,58 +300,58 @@ class BasePatch {
|
|
|
300
300
|
return this._assign(op, props, !1);
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
|
-
var _client$
|
|
303
|
+
var _client$6;
|
|
304
304
|
const _ObservablePatch = class _ObservablePatch2 extends BasePatch {
|
|
305
305
|
constructor(selection, operations, client) {
|
|
306
|
-
super(selection, operations), __privateAdd$
|
|
306
|
+
super(selection, operations), __privateAdd$7(this, _client$6, void 0), __privateSet$7(this, _client$6, client);
|
|
307
307
|
}
|
|
308
308
|
/**
|
|
309
309
|
* Clones the patch
|
|
310
310
|
*/
|
|
311
311
|
clone() {
|
|
312
|
-
return new _ObservablePatch2(this.selection, { ...this.operations }, __privateGet$
|
|
312
|
+
return new _ObservablePatch2(this.selection, { ...this.operations }, __privateGet$7(this, _client$6));
|
|
313
313
|
}
|
|
314
314
|
commit(options) {
|
|
315
|
-
if (!__privateGet$
|
|
315
|
+
if (!__privateGet$7(this, _client$6))
|
|
316
316
|
throw new Error(
|
|
317
317
|
"No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method"
|
|
318
318
|
);
|
|
319
319
|
const returnFirst = typeof this.selection == "string", opts = Object.assign({ returnFirst, returnDocuments: !0 }, options);
|
|
320
|
-
return __privateGet$
|
|
320
|
+
return __privateGet$7(this, _client$6).mutate({ patch: this.serialize() }, opts);
|
|
321
321
|
}
|
|
322
322
|
};
|
|
323
|
-
_client$
|
|
323
|
+
_client$6 = /* @__PURE__ */ new WeakMap();
|
|
324
324
|
let ObservablePatch = _ObservablePatch;
|
|
325
325
|
var _client2$5;
|
|
326
326
|
const _Patch = class _Patch2 extends BasePatch {
|
|
327
327
|
constructor(selection, operations, client) {
|
|
328
|
-
super(selection, operations), __privateAdd$
|
|
328
|
+
super(selection, operations), __privateAdd$7(this, _client2$5, void 0), __privateSet$7(this, _client2$5, client);
|
|
329
329
|
}
|
|
330
330
|
/**
|
|
331
331
|
* Clones the patch
|
|
332
332
|
*/
|
|
333
333
|
clone() {
|
|
334
|
-
return new _Patch2(this.selection, { ...this.operations }, __privateGet$
|
|
334
|
+
return new _Patch2(this.selection, { ...this.operations }, __privateGet$7(this, _client2$5));
|
|
335
335
|
}
|
|
336
336
|
commit(options) {
|
|
337
|
-
if (!__privateGet$
|
|
337
|
+
if (!__privateGet$7(this, _client2$5))
|
|
338
338
|
throw new Error(
|
|
339
339
|
"No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method"
|
|
340
340
|
);
|
|
341
341
|
const returnFirst = typeof this.selection == "string", opts = Object.assign({ returnFirst, returnDocuments: !0 }, options);
|
|
342
|
-
return __privateGet$
|
|
342
|
+
return __privateGet$7(this, _client2$5).mutate({ patch: this.serialize() }, opts);
|
|
343
343
|
}
|
|
344
344
|
};
|
|
345
345
|
_client2$5 = /* @__PURE__ */ new WeakMap();
|
|
346
346
|
let Patch = _Patch;
|
|
347
|
-
var __defProp$1 = Object.defineProperty, __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$1 = (obj, key, value) => (__defNormalProp$1(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck$
|
|
347
|
+
var __defProp$1 = Object.defineProperty, __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$1 = (obj, key, value) => (__defNormalProp$1(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck$6 = (obj, member, msg) => {
|
|
348
348
|
if (!member.has(obj))
|
|
349
349
|
throw TypeError("Cannot " + msg);
|
|
350
|
-
}, __privateGet$
|
|
350
|
+
}, __privateGet$6 = (obj, member, getter) => (__accessCheck$6(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$6 = (obj, member, value) => {
|
|
351
351
|
if (member.has(obj))
|
|
352
352
|
throw TypeError("Cannot add the same private member more than once");
|
|
353
353
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
354
|
-
}, __privateSet$
|
|
354
|
+
}, __privateSet$6 = (obj, member, value, setter) => (__accessCheck$6(obj, member, "write to private field"), member.set(obj, value), value);
|
|
355
355
|
const defaultMutateOptions = { returnDocuments: !1 };
|
|
356
356
|
class BaseTransaction {
|
|
357
357
|
constructor(operations = [], transactionId) {
|
|
@@ -420,23 +420,23 @@ class BaseTransaction {
|
|
|
420
420
|
return this.operations.push(mut), this;
|
|
421
421
|
}
|
|
422
422
|
}
|
|
423
|
-
var _client$
|
|
423
|
+
var _client$5;
|
|
424
424
|
const _Transaction = class _Transaction2 extends BaseTransaction {
|
|
425
425
|
constructor(operations, client, transactionId) {
|
|
426
|
-
super(operations, transactionId), __privateAdd$
|
|
426
|
+
super(operations, transactionId), __privateAdd$6(this, _client$5, void 0), __privateSet$6(this, _client$5, client);
|
|
427
427
|
}
|
|
428
428
|
/**
|
|
429
429
|
* Clones the transaction
|
|
430
430
|
*/
|
|
431
431
|
clone() {
|
|
432
|
-
return new _Transaction2([...this.operations], __privateGet$
|
|
432
|
+
return new _Transaction2([...this.operations], __privateGet$6(this, _client$5), this.trxId);
|
|
433
433
|
}
|
|
434
434
|
commit(options) {
|
|
435
|
-
if (!__privateGet$
|
|
435
|
+
if (!__privateGet$6(this, _client$5))
|
|
436
436
|
throw new Error(
|
|
437
437
|
"No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method"
|
|
438
438
|
);
|
|
439
|
-
return __privateGet$
|
|
439
|
+
return __privateGet$6(this, _client$5).mutate(
|
|
440
440
|
this.serialize(),
|
|
441
441
|
Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {})
|
|
442
442
|
);
|
|
@@ -446,7 +446,7 @@ const _Transaction = class _Transaction2 extends BaseTransaction {
|
|
|
446
446
|
if (typeof patchOrDocumentId != "string" && patchOrDocumentId instanceof Patch)
|
|
447
447
|
return this._add({ patch: patchOrDocumentId.serialize() });
|
|
448
448
|
if (isBuilder) {
|
|
449
|
-
const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$
|
|
449
|
+
const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$6(this, _client$5)));
|
|
450
450
|
if (!(patch instanceof Patch))
|
|
451
451
|
throw new Error("function passed to `patch()` must return the patch");
|
|
452
452
|
return this._add({ patch: patch.serialize() });
|
|
@@ -454,25 +454,25 @@ const _Transaction = class _Transaction2 extends BaseTransaction {
|
|
|
454
454
|
return this._add({ patch: { id: patchOrDocumentId, ...patchOps } });
|
|
455
455
|
}
|
|
456
456
|
};
|
|
457
|
-
_client$
|
|
457
|
+
_client$5 = /* @__PURE__ */ new WeakMap();
|
|
458
458
|
let Transaction = _Transaction;
|
|
459
459
|
var _client2$4;
|
|
460
460
|
const _ObservableTransaction = class _ObservableTransaction2 extends BaseTransaction {
|
|
461
461
|
constructor(operations, client, transactionId) {
|
|
462
|
-
super(operations, transactionId), __privateAdd$
|
|
462
|
+
super(operations, transactionId), __privateAdd$6(this, _client2$4, void 0), __privateSet$6(this, _client2$4, client);
|
|
463
463
|
}
|
|
464
464
|
/**
|
|
465
465
|
* Clones the transaction
|
|
466
466
|
*/
|
|
467
467
|
clone() {
|
|
468
|
-
return new _ObservableTransaction2([...this.operations], __privateGet$
|
|
468
|
+
return new _ObservableTransaction2([...this.operations], __privateGet$6(this, _client2$4), this.trxId);
|
|
469
469
|
}
|
|
470
470
|
commit(options) {
|
|
471
|
-
if (!__privateGet$
|
|
471
|
+
if (!__privateGet$6(this, _client2$4))
|
|
472
472
|
throw new Error(
|
|
473
473
|
"No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method"
|
|
474
474
|
);
|
|
475
|
-
return __privateGet$
|
|
475
|
+
return __privateGet$6(this, _client2$4).mutate(
|
|
476
476
|
this.serialize(),
|
|
477
477
|
Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {})
|
|
478
478
|
);
|
|
@@ -482,7 +482,7 @@ const _ObservableTransaction = class _ObservableTransaction2 extends BaseTransac
|
|
|
482
482
|
if (typeof patchOrDocumentId != "string" && patchOrDocumentId instanceof ObservablePatch)
|
|
483
483
|
return this._add({ patch: patchOrDocumentId.serialize() });
|
|
484
484
|
if (isBuilder) {
|
|
485
|
-
const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$
|
|
485
|
+
const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$6(this, _client2$4)));
|
|
486
486
|
if (!(patch instanceof ObservablePatch))
|
|
487
487
|
throw new Error("function passed to `patch()` must return the patch");
|
|
488
488
|
return this._add({ patch: patch.serialize() });
|
|
@@ -692,7 +692,7 @@ function _mutate(client, httpRequest, mutations, options) {
|
|
|
692
692
|
return _dataRequest(client, httpRequest, "mutate", { mutations: muts, transactionId }, options);
|
|
693
693
|
}
|
|
694
694
|
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 } = options, uri = _getDataUrl(client, endpoint, stringQuery), reqOptions = {
|
|
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 = {
|
|
696
696
|
method: useGet ? "GET" : "POST",
|
|
697
697
|
uri,
|
|
698
698
|
json: !0,
|
|
@@ -705,6 +705,7 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
|
705
705
|
returnQuery,
|
|
706
706
|
perspective: options.perspective,
|
|
707
707
|
resultSourceMap: options.resultSourceMap,
|
|
708
|
+
lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
|
|
708
709
|
canUseCdn: isQuery,
|
|
709
710
|
signal: options.signal,
|
|
710
711
|
fetch: options.fetch,
|
|
@@ -742,7 +743,7 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
742
743
|
const resultSourceMap = (_b = options.resultSourceMap) != null ? _b : config.resultSourceMap;
|
|
743
744
|
resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
|
|
744
745
|
const perspective = options.perspective || config.perspective;
|
|
745
|
-
typeof perspective == "string" && perspective !== "raw" && (validateApiPerspective(perspective), options.query = { perspective, ...options.query }, perspective === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query });
|
|
746
|
+
typeof perspective == "string" && perspective !== "raw" && (validateApiPerspective(perspective), options.query = { perspective, ...options.query }, perspective === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query });
|
|
746
747
|
}
|
|
747
748
|
const reqOptions = requestOptions(
|
|
748
749
|
config,
|
|
@@ -789,30 +790,30 @@ function _createAbortError(signal) {
|
|
|
789
790
|
const error = new Error((_b = signal == null ? void 0 : signal.reason) != null ? _b : "The operation was aborted.");
|
|
790
791
|
return error.name = "AbortError", error;
|
|
791
792
|
}
|
|
792
|
-
var __accessCheck$
|
|
793
|
+
var __accessCheck$5 = (obj, member, msg) => {
|
|
793
794
|
if (!member.has(obj))
|
|
794
795
|
throw TypeError("Cannot " + msg);
|
|
795
|
-
}, __privateGet$
|
|
796
|
+
}, __privateGet$5 = (obj, member, getter) => (__accessCheck$5(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$5 = (obj, member, value) => {
|
|
796
797
|
if (member.has(obj))
|
|
797
798
|
throw TypeError("Cannot add the same private member more than once");
|
|
798
799
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
799
|
-
}, __privateSet$
|
|
800
|
+
}, __privateSet$5 = (obj, member, value, setter) => (__accessCheck$5(obj, member, "write to private field"), member.set(obj, value), value), _client$4, _httpRequest$4;
|
|
800
801
|
class ObservableAssetsClient {
|
|
801
802
|
constructor(client, httpRequest) {
|
|
802
|
-
__privateAdd$
|
|
803
|
+
__privateAdd$5(this, _client$4, void 0), __privateAdd$5(this, _httpRequest$4, void 0), __privateSet$5(this, _client$4, client), __privateSet$5(this, _httpRequest$4, httpRequest);
|
|
803
804
|
}
|
|
804
805
|
upload(assetType, body, options) {
|
|
805
|
-
return _upload(__privateGet$
|
|
806
|
+
return _upload(__privateGet$5(this, _client$4), __privateGet$5(this, _httpRequest$4), assetType, body, options);
|
|
806
807
|
}
|
|
807
808
|
}
|
|
808
|
-
_client$
|
|
809
|
+
_client$4 = /* @__PURE__ */ new WeakMap(), _httpRequest$4 = /* @__PURE__ */ new WeakMap();
|
|
809
810
|
var _client2$3, _httpRequest2$4;
|
|
810
811
|
class AssetsClient {
|
|
811
812
|
constructor(client, httpRequest) {
|
|
812
|
-
__privateAdd$
|
|
813
|
+
__privateAdd$5(this, _client2$3, void 0), __privateAdd$5(this, _httpRequest2$4, void 0), __privateSet$5(this, _client2$3, client), __privateSet$5(this, _httpRequest2$4, httpRequest);
|
|
813
814
|
}
|
|
814
815
|
upload(assetType, body, options) {
|
|
815
|
-
const observable = _upload(__privateGet$
|
|
816
|
+
const observable = _upload(__privateGet$5(this, _client2$3), __privateGet$5(this, _httpRequest2$4), assetType, body, options);
|
|
816
817
|
return rxjs.lastValueFrom(
|
|
817
818
|
observable.pipe(
|
|
818
819
|
operators.filter((event) => event.type === "response"),
|
|
@@ -882,7 +883,7 @@ function _listen(query, params, opts = {}) {
|
|
|
882
883
|
observer.error(cooerceError(err));
|
|
883
884
|
}
|
|
884
885
|
function onMessage(evt) {
|
|
885
|
-
const event = parseEvent(evt);
|
|
886
|
+
const event = parseEvent$1(evt);
|
|
886
887
|
return event instanceof Error ? observer.error(event) : observer.next(event);
|
|
887
888
|
}
|
|
888
889
|
function onDisconnect() {
|
|
@@ -895,10 +896,10 @@ function _listen(query, params, opts = {}) {
|
|
|
895
896
|
shouldEmitReconnect && observer.next({ type: "reconnect" });
|
|
896
897
|
}
|
|
897
898
|
async function getEventSource() {
|
|
898
|
-
const { default:
|
|
899
|
+
const { default: EventSource2 } = await import("@sanity/eventsource");
|
|
899
900
|
if (unsubscribed)
|
|
900
901
|
return;
|
|
901
|
-
const evs = new
|
|
902
|
+
const evs = new EventSource2(uri, esOptions);
|
|
902
903
|
return evs.addEventListener("error", onError), evs.addEventListener("channelError", onChannelError), evs.addEventListener("disconnect", onDisconnect), listenFor.forEach((type) => evs.addEventListener(type, onMessage)), evs;
|
|
903
904
|
}
|
|
904
905
|
function open() {
|
|
@@ -914,7 +915,7 @@ function _listen(query, params, opts = {}) {
|
|
|
914
915
|
return stop;
|
|
915
916
|
});
|
|
916
917
|
}
|
|
917
|
-
function parseEvent(event) {
|
|
918
|
+
function parseEvent$1(event) {
|
|
918
919
|
try {
|
|
919
920
|
const data = event.data && JSON.parse(event.data) || {};
|
|
920
921
|
return Object.assign({ type: event.type }, data);
|
|
@@ -925,12 +926,83 @@ function parseEvent(event) {
|
|
|
925
926
|
function cooerceError(err) {
|
|
926
927
|
if (err instanceof Error)
|
|
927
928
|
return err;
|
|
928
|
-
const evt = parseEvent(err);
|
|
929
|
+
const evt = parseEvent$1(err);
|
|
929
930
|
return evt instanceof Error ? evt : new Error(extractErrorMessage(evt));
|
|
930
931
|
}
|
|
931
932
|
function extractErrorMessage(err) {
|
|
932
933
|
return err.error ? err.error.description ? err.error.description : typeof err.error == "string" ? err.error : JSON.stringify(err.error, null, 2) : err.message || "Unknown listener error";
|
|
933
934
|
}
|
|
935
|
+
var __accessCheck$4 = (obj, member, msg) => {
|
|
936
|
+
if (!member.has(obj))
|
|
937
|
+
throw TypeError("Cannot " + msg);
|
|
938
|
+
}, __privateGet$4 = (obj, member, getter) => (__accessCheck$4(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$4 = (obj, member, value) => {
|
|
939
|
+
if (member.has(obj))
|
|
940
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
941
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
942
|
+
}, __privateSet$4 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), member.set(obj, value), value), _client$3;
|
|
943
|
+
class LiveClient {
|
|
944
|
+
constructor(client) {
|
|
945
|
+
__privateAdd$4(this, _client$3, void 0), __privateSet$4(this, _client$3, client);
|
|
946
|
+
}
|
|
947
|
+
events() {
|
|
948
|
+
const path = _getDataUrl(__privateGet$4(this, _client$3), "live/events"), url = new URL(__privateGet$4(this, _client$3).getUrl(path, !1)), listenFor = ["restart", "message"];
|
|
949
|
+
return new rxjs.Observable((observer) => {
|
|
950
|
+
let es, reconnectTimer, stopped = !1, unsubscribed = !1;
|
|
951
|
+
open();
|
|
952
|
+
function onError(evt) {
|
|
953
|
+
if (!stopped) {
|
|
954
|
+
if ("data" in evt) {
|
|
955
|
+
const event = parseEvent(evt);
|
|
956
|
+
observer.error(new Error(event.message, { cause: event }));
|
|
957
|
+
}
|
|
958
|
+
es.readyState === es.CLOSED && (unsubscribe(), clearTimeout(reconnectTimer), reconnectTimer = setTimeout(open, 100));
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
function onMessage(evt) {
|
|
962
|
+
const event = parseEvent(evt);
|
|
963
|
+
return event instanceof Error ? observer.error(event) : observer.next(event);
|
|
964
|
+
}
|
|
965
|
+
function unsubscribe() {
|
|
966
|
+
if (es) {
|
|
967
|
+
es.removeEventListener("error", onError);
|
|
968
|
+
for (const type of listenFor)
|
|
969
|
+
es.removeEventListener(type, onMessage);
|
|
970
|
+
es.close();
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
async function getEventSource() {
|
|
974
|
+
const EventSourceImplementation = typeof EventSource > "u" ? (await import("@sanity/eventsource")).default : EventSource;
|
|
975
|
+
if (unsubscribed)
|
|
976
|
+
return;
|
|
977
|
+
const evs = new EventSourceImplementation(url.toString());
|
|
978
|
+
evs.addEventListener("error", onError);
|
|
979
|
+
for (const type of listenFor)
|
|
980
|
+
evs.addEventListener(type, onMessage);
|
|
981
|
+
return evs;
|
|
982
|
+
}
|
|
983
|
+
function open() {
|
|
984
|
+
getEventSource().then((eventSource) => {
|
|
985
|
+
eventSource && (es = eventSource, unsubscribed && unsubscribe());
|
|
986
|
+
}).catch((reason) => {
|
|
987
|
+
observer.error(reason), stop();
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
function stop() {
|
|
991
|
+
stopped = !0, unsubscribe(), unsubscribed = !0;
|
|
992
|
+
}
|
|
993
|
+
return stop;
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
_client$3 = /* @__PURE__ */ new WeakMap();
|
|
998
|
+
function parseEvent(event) {
|
|
999
|
+
try {
|
|
1000
|
+
const data = event.data && JSON.parse(event.data) || {};
|
|
1001
|
+
return { type: event.type, id: event.lastEventId, ...data };
|
|
1002
|
+
} catch (err) {
|
|
1003
|
+
return err;
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
934
1006
|
var __accessCheck$3 = (obj, member, msg) => {
|
|
935
1007
|
if (!member.has(obj))
|
|
936
1008
|
throw TypeError("Cannot " + msg);
|
|
@@ -1135,7 +1207,7 @@ var __defProp2 = Object.defineProperty, __defNormalProp = (obj, key, value) => k
|
|
|
1135
1207
|
}, __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value), _clientConfig, _httpRequest;
|
|
1136
1208
|
const _ObservableSanityClient = class _ObservableSanityClient2 {
|
|
1137
1209
|
constructor(httpRequest, config = defaultConfig) {
|
|
1138
|
-
__publicField(this, "assets"), __publicField(this, "datasets"), __publicField(this, "projects"), __publicField(this, "users"), __privateAdd(this, _clientConfig, void 0), __privateAdd(this, _httpRequest, void 0), __publicField(this, "listen", _listen), this.config(config), __privateSet(this, _httpRequest, httpRequest), this.assets = new ObservableAssetsClient(this, __privateGet(this, _httpRequest)), this.datasets = new ObservableDatasetsClient(this, __privateGet(this, _httpRequest)), this.projects = new ObservableProjectsClient(this, __privateGet(this, _httpRequest)), this.users = new ObservableUsersClient(this, __privateGet(this, _httpRequest));
|
|
1210
|
+
__publicField(this, "assets"), __publicField(this, "datasets"), __publicField(this, "live"), __publicField(this, "projects"), __publicField(this, "users"), __privateAdd(this, _clientConfig, void 0), __privateAdd(this, _httpRequest, void 0), __publicField(this, "listen", _listen), this.config(config), __privateSet(this, _httpRequest, httpRequest), this.assets = new ObservableAssetsClient(this, __privateGet(this, _httpRequest)), this.datasets = new ObservableDatasetsClient(this, __privateGet(this, _httpRequest)), this.live = new LiveClient(this), this.projects = new ObservableProjectsClient(this, __privateGet(this, _httpRequest)), this.users = new ObservableUsersClient(this, __privateGet(this, _httpRequest));
|
|
1139
1211
|
}
|
|
1140
1212
|
/**
|
|
1141
1213
|
* Clone the client - returns a new instance
|
|
@@ -1264,7 +1336,7 @@ let ObservableSanityClient = _ObservableSanityClient;
|
|
|
1264
1336
|
var _clientConfig2, _httpRequest2;
|
|
1265
1337
|
const _SanityClient = class _SanityClient2 {
|
|
1266
1338
|
constructor(httpRequest, config = defaultConfig) {
|
|
1267
|
-
__publicField(this, "assets"), __publicField(this, "datasets"), __publicField(this, "projects"), __publicField(this, "users"), __publicField(this, "observable"), __privateAdd(this, _clientConfig2, void 0), __privateAdd(this, _httpRequest2, void 0), __publicField(this, "listen", _listen), this.config(config), __privateSet(this, _httpRequest2, httpRequest), this.assets = new AssetsClient(this, __privateGet(this, _httpRequest2)), this.datasets = new DatasetsClient(this, __privateGet(this, _httpRequest2)), this.projects = new ProjectsClient(this, __privateGet(this, _httpRequest2)), this.users = new UsersClient(this, __privateGet(this, _httpRequest2)), this.observable = new ObservableSanityClient(httpRequest, config);
|
|
1339
|
+
__publicField(this, "assets"), __publicField(this, "datasets"), __publicField(this, "live"), __publicField(this, "projects"), __publicField(this, "users"), __publicField(this, "observable"), __privateAdd(this, _clientConfig2, void 0), __privateAdd(this, _httpRequest2, void 0), __publicField(this, "listen", _listen), this.config(config), __privateSet(this, _httpRequest2, httpRequest), this.assets = new AssetsClient(this, __privateGet(this, _httpRequest2)), this.datasets = new DatasetsClient(this, __privateGet(this, _httpRequest2)), this.live = new LiveClient(this), this.projects = new ProjectsClient(this, __privateGet(this, _httpRequest2)), this.users = new UsersClient(this, __privateGet(this, _httpRequest2)), this.observable = new ObservableSanityClient(httpRequest, config);
|
|
1268
1340
|
}
|
|
1269
1341
|
/**
|
|
1270
1342
|
* Clone the client - returns a new instance
|