@sanity/client 6.17.0 → 6.17.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "6.17.0",
3
+ "version": "6.17.1",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "keywords": [
6
6
  "sanity",
@@ -118,7 +118,7 @@
118
118
  },
119
119
  "dependencies": {
120
120
  "@sanity/eventsource": "^5.0.2",
121
- "get-it": "^8.4.27",
121
+ "get-it": "^8.4.28",
122
122
  "rxjs": "^7.0.0"
123
123
  },
124
124
  "devDependencies": {
@@ -131,7 +131,7 @@
131
131
  "@types/node": "^20.8.8",
132
132
  "@typescript-eslint/eslint-plugin": "^7.8.0",
133
133
  "@typescript-eslint/parser": "^7.8.0",
134
- "@vercel/stega": "0.1.1",
134
+ "@vercel/stega": "0.1.2",
135
135
  "@vitest/coverage-v8": "1.5.3",
136
136
  "eslint": "^8.57.0",
137
137
  "eslint-config-prettier": "^9.1.0",
@@ -85,16 +85,13 @@ export function _listen<R extends Record<string, Any> = Record<string, Any>>(
85
85
 
86
86
  return new Observable((observer) => {
87
87
  let es: InstanceType<typeof import('@sanity/eventsource')>
88
- getEventSource()
89
- .then((eventSource) => {
90
- es = eventSource
91
- })
92
- .catch((reason) => {
93
- observer.error(reason)
94
- stop()
95
- })
96
88
  let reconnectTimer: NodeJS.Timeout
97
89
  let stopped = false
90
+ // Unsubscribe differs from stopped in that we will never reopen.
91
+ // Once it is`true`, it will never be `false` again.
92
+ let unsubscribed = false
93
+
94
+ open()
98
95
 
99
96
  function onError() {
100
97
  if (stopped) {
@@ -150,8 +147,17 @@ export function _listen<R extends Record<string, Any> = Record<string, Any>>(
150
147
  }
151
148
  }
152
149
 
153
- async function getEventSource(): Promise<InstanceType<typeof import('@sanity/eventsource')>> {
150
+ async function getEventSource(): Promise<InstanceType<
151
+ typeof import('@sanity/eventsource')
152
+ > | void> {
154
153
  const {default: EventSource} = await import('@sanity/eventsource')
154
+
155
+ // If the listener has been unsubscribed from before we managed to load the module,
156
+ // do not set up the EventSource.
157
+ if (unsubscribed) {
158
+ return
159
+ }
160
+
155
161
  const evs = new EventSource(uri, esOptions)
156
162
  evs.addEventListener('error', onError)
157
163
  evs.addEventListener('channelError', onChannelError)
@@ -163,7 +169,9 @@ export function _listen<R extends Record<string, Any> = Record<string, Any>>(
163
169
  function open() {
164
170
  getEventSource()
165
171
  .then((eventSource) => {
166
- es = eventSource
172
+ if (eventSource) {
173
+ es = eventSource
174
+ }
167
175
  })
168
176
  .catch((reason) => {
169
177
  observer.error(reason)
@@ -174,6 +182,7 @@ export function _listen<R extends Record<string, Any> = Record<string, Any>>(
174
182
  function stop() {
175
183
  stopped = true
176
184
  unsubscribe()
185
+ unsubscribed = true
177
186
  }
178
187
 
179
188
  return stop
@@ -28,9 +28,9 @@
28
28
  const qIndex = url.indexOf("?");
29
29
  if (qIndex === -1)
30
30
  return { url, searchParams: new URLSearchParams() };
31
- const base = url.slice(0, qIndex), qs = url.slice(qIndex + 1), searchParams = new URLSearchParams(qs);
32
- if (typeof searchParams.set == "function")
33
- return { url: base, searchParams };
31
+ const base = url.slice(0, qIndex), qs = url.slice(qIndex + 1);
32
+ if (!isReactNative)
33
+ return { url: base, searchParams: new URLSearchParams(qs) };
34
34
  if (typeof decodeURIComponent != "function")
35
35
  throw new Error(
36
36
  "Broken `URLSearchParams` implementation, and `decodeURIComponent` is not defined"
@@ -1778,10 +1778,10 @@
1778
1778
  return combineLatest.apply(void 0, __spreadArray([], __read(otherSources)));
1779
1779
  }
1780
1780
 
1781
- var s = { 0: 8203, 1: 8204, 2: 8205, 3: 8290, 4: 8291, 5: 8288, 6: 65279, 7: 8289, 8: 119155, 9: 119156, a: 119157, b: 119158, c: 119159, d: 119160, e: 119161, f: 119162 }, c = { 0: 8203, 1: 8204, 2: 8205, 3: 65279 }, d = new Array(4).fill(String.fromCodePoint(c[0])).join("");
1781
+ var s = { 0: 8203, 1: 8204, 2: 8205, 3: 8290, 4: 8291, 5: 8288, 6: 65279, 7: 8289, 8: 119155, 9: 119156, a: 119157, b: 119158, c: 119159, d: 119160, e: 119161, f: 119162 }, c = { 0: 8203, 1: 8204, 2: 8205, 3: 65279 }, u = new Array(4).fill(String.fromCodePoint(c[0])).join("");
1782
1782
  function E(t) {
1783
1783
  let e = JSON.stringify(t);
1784
- return `${d}${Array.from(e).map((r) => {
1784
+ return `${u}${Array.from(e).map((r) => {
1785
1785
  let n = r.charCodeAt(0);
1786
1786
  if (n > 255)
1787
1787
  throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${e} on character ${r} (${n})`);
@@ -1789,9 +1789,9 @@
1789
1789
  }).join("")}`;
1790
1790
  }
1791
1791
  function I(t) {
1792
- return Number.isNaN(Number(t)) ? !!Date.parse(t) : !1;
1792
+ return !Number.isNaN(Number(t)) || /[a-z]/i.test(t) && !/\d+(?:[-:\/]\d+){2}(?:T\d+(?:[-:\/]\d+){1,2}(\.\d+)?Z?)?/.test(t) ? !1 : !!Date.parse(t);
1793
1793
  }
1794
- function x(t) {
1794
+ function T(t) {
1795
1795
  try {
1796
1796
  new URL(t, t.startsWith("/") ? "https://acme.com" : void 0);
1797
1797
  } catch {
@@ -1800,17 +1800,17 @@
1800
1800
  return !0;
1801
1801
  }
1802
1802
  function C(t, e, r = "auto") {
1803
- return r === !0 || r === "auto" && (I(t) || x(t)) ? t : `${t}${E(e)}`;
1803
+ return r === !0 || r === "auto" && (I(t) || T(t)) ? t : `${t}${E(e)}`;
1804
1804
  }
1805
1805
  Object.fromEntries(Object.entries(c).map((t) => t.reverse()));
1806
1806
  Object.fromEntries(Object.entries(s).map((t) => t.reverse()));
1807
- var T = `${Object.values(s).map((t) => `\\u{${t.toString(16)}}`).join("")}`, f = new RegExp(`[${T}]{4,}`, "gu");
1807
+ var S = `${Object.values(s).map((t) => `\\u{${t.toString(16)}}`).join("")}`, f = new RegExp(`[${S}]{4,}`, "gu");
1808
1808
  function _(t) {
1809
1809
  var e;
1810
1810
  return { cleaned: t.replace(f, ""), encoded: ((e = t.match(f)) == null ? void 0 : e[0]) || "" };
1811
1811
  }
1812
1812
  function O(t) {
1813
- return JSON.parse(_(JSON.stringify(t)).cleaned);
1813
+ return t && JSON.parse(_(JSON.stringify(t)).cleaned);
1814
1814
  }
1815
1815
  function stegaClean(result) {
1816
1816
  try {
@@ -2672,13 +2672,8 @@ ${selectionOpts}`);
2672
2672
  return (token || withCredentials) && (esOptions.withCredentials = !0), token && (esOptions.headers = {
2673
2673
  Authorization: `Bearer ${token}`
2674
2674
  }), new Observable((observer) => {
2675
- let es;
2676
- getEventSource().then((eventSource) => {
2677
- es = eventSource;
2678
- }).catch((reason) => {
2679
- observer.error(reason), stop();
2680
- });
2681
- let reconnectTimer, stopped = !1;
2675
+ let es, reconnectTimer, stopped = !1, unsubscribed = !1;
2676
+ open();
2682
2677
  function onError() {
2683
2678
  stopped || (emitReconnect(), !stopped && es.readyState === es.CLOSED && (unsubscribe(), clearTimeout(reconnectTimer), reconnectTimer = setTimeout(open, 100)));
2684
2679
  }
@@ -2699,18 +2694,21 @@ ${selectionOpts}`);
2699
2694
  shouldEmitReconnect && observer.next({ type: "reconnect" });
2700
2695
  }
2701
2696
  async function getEventSource() {
2702
- const { default: EventSource } = await Promise.resolve().then(function () { return browser$2; }), evs = new EventSource(uri, esOptions);
2697
+ const { default: EventSource } = await Promise.resolve().then(function () { return browser$2; });
2698
+ if (unsubscribed)
2699
+ return;
2700
+ const evs = new EventSource(uri, esOptions);
2703
2701
  return evs.addEventListener("error", onError), evs.addEventListener("channelError", onChannelError), evs.addEventListener("disconnect", onDisconnect), listenFor.forEach((type) => evs.addEventListener(type, onMessage)), evs;
2704
2702
  }
2705
2703
  function open() {
2706
2704
  getEventSource().then((eventSource) => {
2707
- es = eventSource;
2705
+ eventSource && (es = eventSource);
2708
2706
  }).catch((reason) => {
2709
2707
  observer.error(reason), stop();
2710
2708
  });
2711
2709
  }
2712
2710
  function stop() {
2713
- stopped = !0, unsubscribe();
2711
+ stopped = !0, unsubscribe(), unsubscribed = !0;
2714
2712
  }
2715
2713
  return stop;
2716
2714
  });