@sanity/client 6.17.3-canary.7 → 6.17.3
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 +46 -121
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +0 -33
- package/dist/index.browser.d.ts +0 -33
- package/dist/index.browser.js +46 -121
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +47 -122
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -33
- package/dist/index.d.ts +0 -33
- package/dist/index.js +47 -122
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/SanityClient.ts +0 -6
- package/src/data/dataMethods.ts +1 -6
- package/src/data/listen.ts +1 -5
- package/src/types.ts +0 -20
- package/umd/sanityClient.js +60 -135
- package/umd/sanityClient.min.js +3 -3
- package/src/data/live.ts +0 -130
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$6 = (obj, member, msg) => {
|
|
163
163
|
if (!member.has(obj))
|
|
164
164
|
throw TypeError("Cannot " + msg);
|
|
165
|
-
}, __privateGet$
|
|
165
|
+
}, __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) => {
|
|
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$6 = (obj, member, value, setter) => (__accessCheck$6(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$5;
|
|
304
304
|
const _ObservablePatch = class _ObservablePatch2 extends BasePatch {
|
|
305
305
|
constructor(selection, operations, client) {
|
|
306
|
-
super(selection, operations), __privateAdd$
|
|
306
|
+
super(selection, operations), __privateAdd$6(this, _client$5, void 0), __privateSet$6(this, _client$5, 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$6(this, _client$5));
|
|
313
313
|
}
|
|
314
314
|
commit(options) {
|
|
315
|
-
if (!__privateGet$
|
|
315
|
+
if (!__privateGet$6(this, _client$5))
|
|
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$6(this, _client$5).mutate({ patch: this.serialize() }, opts);
|
|
321
321
|
}
|
|
322
322
|
};
|
|
323
|
-
_client$
|
|
323
|
+
_client$5 = /* @__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$6(this, _client2$5, void 0), __privateSet$6(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$6(this, _client2$5));
|
|
335
335
|
}
|
|
336
336
|
commit(options) {
|
|
337
|
-
if (!__privateGet$
|
|
337
|
+
if (!__privateGet$6(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$6(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$5 = (obj, member, msg) => {
|
|
348
348
|
if (!member.has(obj))
|
|
349
349
|
throw TypeError("Cannot " + msg);
|
|
350
|
-
}, __privateGet$
|
|
350
|
+
}, __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) => {
|
|
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$5 = (obj, member, value, setter) => (__accessCheck$5(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$4;
|
|
424
424
|
const _Transaction = class _Transaction2 extends BaseTransaction {
|
|
425
425
|
constructor(operations, client, transactionId) {
|
|
426
|
-
super(operations, transactionId), __privateAdd$
|
|
426
|
+
super(operations, transactionId), __privateAdd$5(this, _client$4, void 0), __privateSet$5(this, _client$4, 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$5(this, _client$4), this.trxId);
|
|
433
433
|
}
|
|
434
434
|
commit(options) {
|
|
435
|
-
if (!__privateGet$
|
|
435
|
+
if (!__privateGet$5(this, _client$4))
|
|
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$5(this, _client$4).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$5(this, _client$4)));
|
|
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$4 = /* @__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$5(this, _client2$4, void 0), __privateSet$5(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$5(this, _client2$4), this.trxId);
|
|
469
469
|
}
|
|
470
470
|
commit(options) {
|
|
471
|
-
if (!__privateGet$
|
|
471
|
+
if (!__privateGet$5(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$5(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$5(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
|
|
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 = {
|
|
696
696
|
method: useGet ? "GET" : "POST",
|
|
697
697
|
uri,
|
|
698
698
|
json: !0,
|
|
@@ -705,7 +705,6 @@ 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,
|
|
709
708
|
canUseCdn: isQuery,
|
|
710
709
|
signal: options.signal,
|
|
711
710
|
fetch: options.fetch,
|
|
@@ -743,7 +742,7 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
743
742
|
const resultSourceMap = (_b = options.resultSourceMap) != null ? _b : config.resultSourceMap;
|
|
744
743
|
resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
|
|
745
744
|
const perspective = options.perspective || config.perspective;
|
|
746
|
-
typeof perspective == "string" && perspective !== "raw" && (validateApiPerspective(perspective), options.query = { perspective, ...options.query }, perspective === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())), options.
|
|
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 });
|
|
747
746
|
}
|
|
748
747
|
const reqOptions = requestOptions(
|
|
749
748
|
config,
|
|
@@ -790,30 +789,30 @@ function _createAbortError(signal) {
|
|
|
790
789
|
const error = new Error((_b = signal == null ? void 0 : signal.reason) != null ? _b : "The operation was aborted.");
|
|
791
790
|
return error.name = "AbortError", error;
|
|
792
791
|
}
|
|
793
|
-
var __accessCheck$
|
|
792
|
+
var __accessCheck$4 = (obj, member, msg) => {
|
|
794
793
|
if (!member.has(obj))
|
|
795
794
|
throw TypeError("Cannot " + msg);
|
|
796
|
-
}, __privateGet$
|
|
795
|
+
}, __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) => {
|
|
797
796
|
if (member.has(obj))
|
|
798
797
|
throw TypeError("Cannot add the same private member more than once");
|
|
799
798
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
800
|
-
}, __privateSet$
|
|
799
|
+
}, __privateSet$4 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), member.set(obj, value), value), _client$3, _httpRequest$4;
|
|
801
800
|
class ObservableAssetsClient {
|
|
802
801
|
constructor(client, httpRequest) {
|
|
803
|
-
__privateAdd$
|
|
802
|
+
__privateAdd$4(this, _client$3, void 0), __privateAdd$4(this, _httpRequest$4, void 0), __privateSet$4(this, _client$3, client), __privateSet$4(this, _httpRequest$4, httpRequest);
|
|
804
803
|
}
|
|
805
804
|
upload(assetType, body, options) {
|
|
806
|
-
return _upload(__privateGet$
|
|
805
|
+
return _upload(__privateGet$4(this, _client$3), __privateGet$4(this, _httpRequest$4), assetType, body, options);
|
|
807
806
|
}
|
|
808
807
|
}
|
|
809
|
-
_client$
|
|
808
|
+
_client$3 = /* @__PURE__ */ new WeakMap(), _httpRequest$4 = /* @__PURE__ */ new WeakMap();
|
|
810
809
|
var _client2$3, _httpRequest2$4;
|
|
811
810
|
class AssetsClient {
|
|
812
811
|
constructor(client, httpRequest) {
|
|
813
|
-
__privateAdd$
|
|
812
|
+
__privateAdd$4(this, _client2$3, void 0), __privateAdd$4(this, _httpRequest2$4, void 0), __privateSet$4(this, _client2$3, client), __privateSet$4(this, _httpRequest2$4, httpRequest);
|
|
814
813
|
}
|
|
815
814
|
upload(assetType, body, options) {
|
|
816
|
-
const observable = _upload(__privateGet$
|
|
815
|
+
const observable = _upload(__privateGet$4(this, _client2$3), __privateGet$4(this, _httpRequest2$4), assetType, body, options);
|
|
817
816
|
return rxjs.lastValueFrom(
|
|
818
817
|
observable.pipe(
|
|
819
818
|
operators.filter((event) => event.type === "response"),
|
|
@@ -883,7 +882,7 @@ function _listen(query, params, opts = {}) {
|
|
|
883
882
|
observer.error(cooerceError(err));
|
|
884
883
|
}
|
|
885
884
|
function onMessage(evt) {
|
|
886
|
-
const event = parseEvent
|
|
885
|
+
const event = parseEvent(evt);
|
|
887
886
|
return event instanceof Error ? observer.error(event) : observer.next(event);
|
|
888
887
|
}
|
|
889
888
|
function onDisconnect() {
|
|
@@ -896,15 +895,15 @@ function _listen(query, params, opts = {}) {
|
|
|
896
895
|
shouldEmitReconnect && observer.next({ type: "reconnect" });
|
|
897
896
|
}
|
|
898
897
|
async function getEventSource() {
|
|
899
|
-
const { default:
|
|
898
|
+
const { default: EventSource } = await import("@sanity/eventsource");
|
|
900
899
|
if (unsubscribed)
|
|
901
900
|
return;
|
|
902
|
-
const evs = new
|
|
901
|
+
const evs = new EventSource(uri, esOptions);
|
|
903
902
|
return evs.addEventListener("error", onError), evs.addEventListener("channelError", onChannelError), evs.addEventListener("disconnect", onDisconnect), listenFor.forEach((type) => evs.addEventListener(type, onMessage)), evs;
|
|
904
903
|
}
|
|
905
904
|
function open() {
|
|
906
905
|
getEventSource().then((eventSource) => {
|
|
907
|
-
eventSource && (es = eventSource
|
|
906
|
+
eventSource && (es = eventSource);
|
|
908
907
|
}).catch((reason) => {
|
|
909
908
|
observer.error(reason), stop();
|
|
910
909
|
});
|
|
@@ -915,7 +914,7 @@ function _listen(query, params, opts = {}) {
|
|
|
915
914
|
return stop;
|
|
916
915
|
});
|
|
917
916
|
}
|
|
918
|
-
function parseEvent
|
|
917
|
+
function parseEvent(event) {
|
|
919
918
|
try {
|
|
920
919
|
const data = event.data && JSON.parse(event.data) || {};
|
|
921
920
|
return Object.assign({ type: event.type }, data);
|
|
@@ -926,86 +925,12 @@ function parseEvent$1(event) {
|
|
|
926
925
|
function cooerceError(err) {
|
|
927
926
|
if (err instanceof Error)
|
|
928
927
|
return err;
|
|
929
|
-
const evt = parseEvent
|
|
928
|
+
const evt = parseEvent(err);
|
|
930
929
|
return evt instanceof Error ? evt : new Error(extractErrorMessage(evt));
|
|
931
930
|
}
|
|
932
931
|
function extractErrorMessage(err) {
|
|
933
932
|
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";
|
|
934
933
|
}
|
|
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
|
-
try {
|
|
956
|
-
const event = parseEvent(evt);
|
|
957
|
-
observer.error(new Error(event.message, { cause: event }));
|
|
958
|
-
} catch (err) {
|
|
959
|
-
observer.error(err);
|
|
960
|
-
}
|
|
961
|
-
es.readyState === es.CLOSED && (unsubscribe(), clearTimeout(reconnectTimer), reconnectTimer = setTimeout(open, 100));
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
function onMessage(evt) {
|
|
965
|
-
const event = parseEvent(evt);
|
|
966
|
-
return event instanceof Error ? observer.error(event) : observer.next(event);
|
|
967
|
-
}
|
|
968
|
-
function unsubscribe() {
|
|
969
|
-
if (es) {
|
|
970
|
-
es.removeEventListener("error", onError);
|
|
971
|
-
for (const type of listenFor)
|
|
972
|
-
es.removeEventListener(type, onMessage);
|
|
973
|
-
es.close();
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
async function getEventSource() {
|
|
977
|
-
const EventSourceImplementation = typeof EventSource > "u" ? (await import("@sanity/eventsource")).default : EventSource;
|
|
978
|
-
if (unsubscribed)
|
|
979
|
-
return;
|
|
980
|
-
const evs = new EventSourceImplementation(url.toString());
|
|
981
|
-
evs.addEventListener("error", onError);
|
|
982
|
-
for (const type of listenFor)
|
|
983
|
-
evs.addEventListener(type, onMessage);
|
|
984
|
-
return evs;
|
|
985
|
-
}
|
|
986
|
-
function open() {
|
|
987
|
-
getEventSource().then((eventSource) => {
|
|
988
|
-
eventSource && (es = eventSource, unsubscribed && unsubscribe());
|
|
989
|
-
}).catch((reason) => {
|
|
990
|
-
observer.error(reason), stop();
|
|
991
|
-
});
|
|
992
|
-
}
|
|
993
|
-
function stop() {
|
|
994
|
-
stopped = !0, unsubscribe(), unsubscribed = !0;
|
|
995
|
-
}
|
|
996
|
-
return stop;
|
|
997
|
-
});
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
_client$3 = /* @__PURE__ */ new WeakMap();
|
|
1001
|
-
function parseEvent(event) {
|
|
1002
|
-
try {
|
|
1003
|
-
const data = event.data && JSON.parse(event.data) || {};
|
|
1004
|
-
return { type: event.type, id: event.lastEventId, ...data };
|
|
1005
|
-
} catch (err) {
|
|
1006
|
-
return err;
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
1009
934
|
var __accessCheck$3 = (obj, member, msg) => {
|
|
1010
935
|
if (!member.has(obj))
|
|
1011
936
|
throw TypeError("Cannot " + msg);
|
|
@@ -1210,7 +1135,7 @@ var __defProp2 = Object.defineProperty, __defNormalProp = (obj, key, value) => k
|
|
|
1210
1135
|
}, __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value), _clientConfig, _httpRequest;
|
|
1211
1136
|
const _ObservableSanityClient = class _ObservableSanityClient2 {
|
|
1212
1137
|
constructor(httpRequest, config = defaultConfig) {
|
|
1213
|
-
__publicField(this, "assets"), __publicField(this, "datasets"), __publicField(this, "
|
|
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));
|
|
1214
1139
|
}
|
|
1215
1140
|
/**
|
|
1216
1141
|
* Clone the client - returns a new instance
|
|
@@ -1339,7 +1264,7 @@ let ObservableSanityClient = _ObservableSanityClient;
|
|
|
1339
1264
|
var _clientConfig2, _httpRequest2;
|
|
1340
1265
|
const _SanityClient = class _SanityClient2 {
|
|
1341
1266
|
constructor(httpRequest, config = defaultConfig) {
|
|
1342
|
-
__publicField(this, "assets"), __publicField(this, "datasets"), __publicField(this, "
|
|
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);
|
|
1343
1268
|
}
|
|
1344
1269
|
/**
|
|
1345
1270
|
* Clone the client - returns a new instance
|