@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/umd/sanityClient.js
CHANGED
|
@@ -166,45 +166,45 @@
|
|
|
166
166
|
typeof result[key] > "u" ? result[key] = value : isArray$3(result[key]) ? result[key].push(value) : result[key] = [result[key], value];
|
|
167
167
|
}
|
|
168
168
|
return result;
|
|
169
|
-
}, parseHeaders$1 = /* @__PURE__ */ getDefaultExportFromCjs$1(parseHeaders), __defProp$5 = Object.defineProperty, __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$5 = (obj, key, value) => (__defNormalProp$5(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck$
|
|
169
|
+
}, parseHeaders$1 = /* @__PURE__ */ getDefaultExportFromCjs$1(parseHeaders), __defProp$5 = Object.defineProperty, __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$5 = (obj, key, value) => (__defNormalProp$5(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck$8 = (obj, member, msg) => {
|
|
170
170
|
if (!member.has(obj))
|
|
171
171
|
throw TypeError("Cannot " + msg);
|
|
172
|
-
}, __privateGet$
|
|
172
|
+
}, __privateGet$8 = (obj, member, getter) => (__accessCheck$8(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$8 = (obj, member, value) => {
|
|
173
173
|
if (member.has(obj))
|
|
174
174
|
throw TypeError("Cannot add the same private member more than once");
|
|
175
175
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
176
|
-
}, __privateSet$
|
|
176
|
+
}, __privateSet$8 = (obj, member, value, setter) => (__accessCheck$8(obj, member, "write to private field"), member.set(obj, value), value), _method, _url, _resHeaders, _headers, _controller, _init, _useAbortSignal;
|
|
177
177
|
class FetchXhr {
|
|
178
178
|
constructor() {
|
|
179
|
-
__publicField$5(this, "onabort"), __publicField$5(this, "onerror"), __publicField$5(this, "onreadystatechange"), __publicField$5(this, "ontimeout"), __publicField$5(this, "readyState", 0), __publicField$5(this, "response"), __publicField$5(this, "responseText", ""), __publicField$5(this, "responseType", ""), __publicField$5(this, "status"), __publicField$5(this, "statusText"), __publicField$5(this, "withCredentials"), __privateAdd$
|
|
179
|
+
__publicField$5(this, "onabort"), __publicField$5(this, "onerror"), __publicField$5(this, "onreadystatechange"), __publicField$5(this, "ontimeout"), __publicField$5(this, "readyState", 0), __publicField$5(this, "response"), __publicField$5(this, "responseText", ""), __publicField$5(this, "responseType", ""), __publicField$5(this, "status"), __publicField$5(this, "statusText"), __publicField$5(this, "withCredentials"), __privateAdd$8(this, _method, void 0), __privateAdd$8(this, _url, void 0), __privateAdd$8(this, _resHeaders, void 0), __privateAdd$8(this, _headers, {}), __privateAdd$8(this, _controller, void 0), __privateAdd$8(this, _init, {}), __privateAdd$8(this, _useAbortSignal, void 0);
|
|
180
180
|
}
|
|
181
181
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- _async is only declared for typings compatibility
|
|
182
182
|
open(method, url, _async) {
|
|
183
183
|
var _a;
|
|
184
|
-
__privateSet$
|
|
184
|
+
__privateSet$8(this, _method, method), __privateSet$8(this, _url, url), __privateSet$8(this, _resHeaders, ""), this.readyState = 1, (_a = this.onreadystatechange) == null || _a.call(this), __privateSet$8(this, _controller, void 0);
|
|
185
185
|
}
|
|
186
186
|
abort() {
|
|
187
|
-
__privateGet$
|
|
187
|
+
__privateGet$8(this, _controller) && __privateGet$8(this, _controller).abort();
|
|
188
188
|
}
|
|
189
189
|
getAllResponseHeaders() {
|
|
190
|
-
return __privateGet$
|
|
190
|
+
return __privateGet$8(this, _resHeaders);
|
|
191
191
|
}
|
|
192
192
|
setRequestHeader(name, value) {
|
|
193
|
-
__privateGet$
|
|
193
|
+
__privateGet$8(this, _headers)[name] = value;
|
|
194
194
|
}
|
|
195
195
|
// Allow setting extra fetch init options, needed for runtimes such as Vercel Edge to set `cache` and other options in React Server Components
|
|
196
196
|
setInit(init, useAbortSignal = !0) {
|
|
197
|
-
__privateSet$
|
|
197
|
+
__privateSet$8(this, _init, init), __privateSet$8(this, _useAbortSignal, useAbortSignal);
|
|
198
198
|
}
|
|
199
199
|
send(body) {
|
|
200
200
|
const textBody = this.responseType !== "arraybuffer", options = {
|
|
201
|
-
...__privateGet$
|
|
202
|
-
method: __privateGet$
|
|
203
|
-
headers: __privateGet$
|
|
201
|
+
...__privateGet$8(this, _init),
|
|
202
|
+
method: __privateGet$8(this, _method),
|
|
203
|
+
headers: __privateGet$8(this, _headers),
|
|
204
204
|
body
|
|
205
205
|
};
|
|
206
|
-
typeof AbortController == "function" && __privateGet$
|
|
207
|
-
__privateSet$
|
|
206
|
+
typeof AbortController == "function" && __privateGet$8(this, _useAbortSignal) && (__privateSet$8(this, _controller, new AbortController()), typeof EventTarget < "u" && __privateGet$8(this, _controller).signal instanceof EventTarget && (options.signal = __privateGet$8(this, _controller).signal)), typeof document < "u" && (options.credentials = this.withCredentials ? "include" : "omit"), fetch(__privateGet$8(this, _url), options).then((res) => (res.headers.forEach((value, key) => {
|
|
207
|
+
__privateSet$8(this, _resHeaders, __privateGet$8(this, _resHeaders) + `${key}: ${value}\r
|
|
208
208
|
`);
|
|
209
209
|
}), this.status = res.status, this.statusText = res.statusText, this.readyState = 3, textBody ? res.text() : res.arrayBuffer())).then((resBody) => {
|
|
210
210
|
var _a;
|
|
@@ -1956,14 +1956,14 @@ ${selectionOpts}`);
|
|
|
1956
1956
|
);
|
|
1957
1957
|
return tag;
|
|
1958
1958
|
};
|
|
1959
|
-
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$
|
|
1959
|
+
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) => {
|
|
1960
1960
|
if (!member.has(obj))
|
|
1961
1961
|
throw TypeError("Cannot " + msg);
|
|
1962
|
-
}, __privateGet$
|
|
1962
|
+
}, __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) => {
|
|
1963
1963
|
if (member.has(obj))
|
|
1964
1964
|
throw TypeError("Cannot add the same private member more than once");
|
|
1965
1965
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1966
|
-
}, __privateSet$
|
|
1966
|
+
}, __privateSet$7 = (obj, member, value, setter) => (__accessCheck$7(obj, member, "write to private field"), member.set(obj, value), value);
|
|
1967
1967
|
class BasePatch {
|
|
1968
1968
|
constructor(selection, operations = {}) {
|
|
1969
1969
|
__publicField$2(this, "selection"), __publicField$2(this, "operations"), this.selection = selection, this.operations = operations;
|
|
@@ -2097,58 +2097,58 @@ ${selectionOpts}`);
|
|
|
2097
2097
|
return this._assign(op, props, !1);
|
|
2098
2098
|
}
|
|
2099
2099
|
}
|
|
2100
|
-
var _client$
|
|
2100
|
+
var _client$6;
|
|
2101
2101
|
const _ObservablePatch = class _ObservablePatch2 extends BasePatch {
|
|
2102
2102
|
constructor(selection, operations, client) {
|
|
2103
|
-
super(selection, operations), __privateAdd$
|
|
2103
|
+
super(selection, operations), __privateAdd$7(this, _client$6, void 0), __privateSet$7(this, _client$6, client);
|
|
2104
2104
|
}
|
|
2105
2105
|
/**
|
|
2106
2106
|
* Clones the patch
|
|
2107
2107
|
*/
|
|
2108
2108
|
clone() {
|
|
2109
|
-
return new _ObservablePatch2(this.selection, { ...this.operations }, __privateGet$
|
|
2109
|
+
return new _ObservablePatch2(this.selection, { ...this.operations }, __privateGet$7(this, _client$6));
|
|
2110
2110
|
}
|
|
2111
2111
|
commit(options) {
|
|
2112
|
-
if (!__privateGet$
|
|
2112
|
+
if (!__privateGet$7(this, _client$6))
|
|
2113
2113
|
throw new Error(
|
|
2114
2114
|
"No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method"
|
|
2115
2115
|
);
|
|
2116
2116
|
const returnFirst = typeof this.selection == "string", opts = Object.assign({ returnFirst, returnDocuments: !0 }, options);
|
|
2117
|
-
return __privateGet$
|
|
2117
|
+
return __privateGet$7(this, _client$6).mutate({ patch: this.serialize() }, opts);
|
|
2118
2118
|
}
|
|
2119
2119
|
};
|
|
2120
|
-
_client$
|
|
2120
|
+
_client$6 = /* @__PURE__ */ new WeakMap();
|
|
2121
2121
|
let ObservablePatch = _ObservablePatch;
|
|
2122
2122
|
var _client2$5;
|
|
2123
2123
|
const _Patch = class _Patch2 extends BasePatch {
|
|
2124
2124
|
constructor(selection, operations, client) {
|
|
2125
|
-
super(selection, operations), __privateAdd$
|
|
2125
|
+
super(selection, operations), __privateAdd$7(this, _client2$5, void 0), __privateSet$7(this, _client2$5, client);
|
|
2126
2126
|
}
|
|
2127
2127
|
/**
|
|
2128
2128
|
* Clones the patch
|
|
2129
2129
|
*/
|
|
2130
2130
|
clone() {
|
|
2131
|
-
return new _Patch2(this.selection, { ...this.operations }, __privateGet$
|
|
2131
|
+
return new _Patch2(this.selection, { ...this.operations }, __privateGet$7(this, _client2$5));
|
|
2132
2132
|
}
|
|
2133
2133
|
commit(options) {
|
|
2134
|
-
if (!__privateGet$
|
|
2134
|
+
if (!__privateGet$7(this, _client2$5))
|
|
2135
2135
|
throw new Error(
|
|
2136
2136
|
"No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method"
|
|
2137
2137
|
);
|
|
2138
2138
|
const returnFirst = typeof this.selection == "string", opts = Object.assign({ returnFirst, returnDocuments: !0 }, options);
|
|
2139
|
-
return __privateGet$
|
|
2139
|
+
return __privateGet$7(this, _client2$5).mutate({ patch: this.serialize() }, opts);
|
|
2140
2140
|
}
|
|
2141
2141
|
};
|
|
2142
2142
|
_client2$5 = /* @__PURE__ */ new WeakMap();
|
|
2143
2143
|
let Patch = _Patch;
|
|
2144
|
-
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$
|
|
2144
|
+
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) => {
|
|
2145
2145
|
if (!member.has(obj))
|
|
2146
2146
|
throw TypeError("Cannot " + msg);
|
|
2147
|
-
}, __privateGet$
|
|
2147
|
+
}, __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) => {
|
|
2148
2148
|
if (member.has(obj))
|
|
2149
2149
|
throw TypeError("Cannot add the same private member more than once");
|
|
2150
2150
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
2151
|
-
}, __privateSet$
|
|
2151
|
+
}, __privateSet$6 = (obj, member, value, setter) => (__accessCheck$6(obj, member, "write to private field"), member.set(obj, value), value);
|
|
2152
2152
|
const defaultMutateOptions = { returnDocuments: !1 };
|
|
2153
2153
|
class BaseTransaction {
|
|
2154
2154
|
constructor(operations = [], transactionId) {
|
|
@@ -2217,23 +2217,23 @@ ${selectionOpts}`);
|
|
|
2217
2217
|
return this.operations.push(mut), this;
|
|
2218
2218
|
}
|
|
2219
2219
|
}
|
|
2220
|
-
var _client$
|
|
2220
|
+
var _client$5;
|
|
2221
2221
|
const _Transaction = class _Transaction2 extends BaseTransaction {
|
|
2222
2222
|
constructor(operations, client, transactionId) {
|
|
2223
|
-
super(operations, transactionId), __privateAdd$
|
|
2223
|
+
super(operations, transactionId), __privateAdd$6(this, _client$5, void 0), __privateSet$6(this, _client$5, client);
|
|
2224
2224
|
}
|
|
2225
2225
|
/**
|
|
2226
2226
|
* Clones the transaction
|
|
2227
2227
|
*/
|
|
2228
2228
|
clone() {
|
|
2229
|
-
return new _Transaction2([...this.operations], __privateGet$
|
|
2229
|
+
return new _Transaction2([...this.operations], __privateGet$6(this, _client$5), this.trxId);
|
|
2230
2230
|
}
|
|
2231
2231
|
commit(options) {
|
|
2232
|
-
if (!__privateGet$
|
|
2232
|
+
if (!__privateGet$6(this, _client$5))
|
|
2233
2233
|
throw new Error(
|
|
2234
2234
|
"No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method"
|
|
2235
2235
|
);
|
|
2236
|
-
return __privateGet$
|
|
2236
|
+
return __privateGet$6(this, _client$5).mutate(
|
|
2237
2237
|
this.serialize(),
|
|
2238
2238
|
Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {})
|
|
2239
2239
|
);
|
|
@@ -2243,7 +2243,7 @@ ${selectionOpts}`);
|
|
|
2243
2243
|
if (typeof patchOrDocumentId != "string" && patchOrDocumentId instanceof Patch)
|
|
2244
2244
|
return this._add({ patch: patchOrDocumentId.serialize() });
|
|
2245
2245
|
if (isBuilder) {
|
|
2246
|
-
const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$
|
|
2246
|
+
const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$6(this, _client$5)));
|
|
2247
2247
|
if (!(patch instanceof Patch))
|
|
2248
2248
|
throw new Error("function passed to `patch()` must return the patch");
|
|
2249
2249
|
return this._add({ patch: patch.serialize() });
|
|
@@ -2251,25 +2251,25 @@ ${selectionOpts}`);
|
|
|
2251
2251
|
return this._add({ patch: { id: patchOrDocumentId, ...patchOps } });
|
|
2252
2252
|
}
|
|
2253
2253
|
};
|
|
2254
|
-
_client$
|
|
2254
|
+
_client$5 = /* @__PURE__ */ new WeakMap();
|
|
2255
2255
|
let Transaction = _Transaction;
|
|
2256
2256
|
var _client2$4;
|
|
2257
2257
|
const _ObservableTransaction = class _ObservableTransaction2 extends BaseTransaction {
|
|
2258
2258
|
constructor(operations, client, transactionId) {
|
|
2259
|
-
super(operations, transactionId), __privateAdd$
|
|
2259
|
+
super(operations, transactionId), __privateAdd$6(this, _client2$4, void 0), __privateSet$6(this, _client2$4, client);
|
|
2260
2260
|
}
|
|
2261
2261
|
/**
|
|
2262
2262
|
* Clones the transaction
|
|
2263
2263
|
*/
|
|
2264
2264
|
clone() {
|
|
2265
|
-
return new _ObservableTransaction2([...this.operations], __privateGet$
|
|
2265
|
+
return new _ObservableTransaction2([...this.operations], __privateGet$6(this, _client2$4), this.trxId);
|
|
2266
2266
|
}
|
|
2267
2267
|
commit(options) {
|
|
2268
|
-
if (!__privateGet$
|
|
2268
|
+
if (!__privateGet$6(this, _client2$4))
|
|
2269
2269
|
throw new Error(
|
|
2270
2270
|
"No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method"
|
|
2271
2271
|
);
|
|
2272
|
-
return __privateGet$
|
|
2272
|
+
return __privateGet$6(this, _client2$4).mutate(
|
|
2273
2273
|
this.serialize(),
|
|
2274
2274
|
Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {})
|
|
2275
2275
|
);
|
|
@@ -2279,7 +2279,7 @@ ${selectionOpts}`);
|
|
|
2279
2279
|
if (typeof patchOrDocumentId != "string" && patchOrDocumentId instanceof ObservablePatch)
|
|
2280
2280
|
return this._add({ patch: patchOrDocumentId.serialize() });
|
|
2281
2281
|
if (isBuilder) {
|
|
2282
|
-
const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$
|
|
2282
|
+
const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$6(this, _client2$4)));
|
|
2283
2283
|
if (!(patch instanceof ObservablePatch))
|
|
2284
2284
|
throw new Error("function passed to `patch()` must return the patch");
|
|
2285
2285
|
return this._add({ patch: patch.serialize() });
|
|
@@ -2487,7 +2487,7 @@ ${selectionOpts}`);
|
|
|
2487
2487
|
return _dataRequest(client, httpRequest, "mutate", { mutations: muts, transactionId }, options);
|
|
2488
2488
|
}
|
|
2489
2489
|
function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
2490
|
-
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 = {
|
|
2490
|
+
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 = {
|
|
2491
2491
|
method: useGet ? "GET" : "POST",
|
|
2492
2492
|
uri,
|
|
2493
2493
|
json: !0,
|
|
@@ -2500,6 +2500,7 @@ ${selectionOpts}`);
|
|
|
2500
2500
|
returnQuery,
|
|
2501
2501
|
perspective: options.perspective,
|
|
2502
2502
|
resultSourceMap: options.resultSourceMap,
|
|
2503
|
+
lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
|
|
2503
2504
|
canUseCdn: isQuery,
|
|
2504
2505
|
signal: options.signal,
|
|
2505
2506
|
fetch: options.fetch,
|
|
@@ -2537,7 +2538,7 @@ ${selectionOpts}`);
|
|
|
2537
2538
|
const resultSourceMap = (_b = options.resultSourceMap) != null ? _b : config.resultSourceMap;
|
|
2538
2539
|
resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
|
|
2539
2540
|
const perspective = options.perspective || config.perspective;
|
|
2540
|
-
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 });
|
|
2541
|
+
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 });
|
|
2541
2542
|
}
|
|
2542
2543
|
const reqOptions = requestOptions(
|
|
2543
2544
|
config,
|
|
@@ -2584,30 +2585,30 @@ ${selectionOpts}`);
|
|
|
2584
2585
|
const error = new Error((_b = signal == null ? void 0 : signal.reason) != null ? _b : "The operation was aborted.");
|
|
2585
2586
|
return error.name = "AbortError", error;
|
|
2586
2587
|
}
|
|
2587
|
-
var __accessCheck$
|
|
2588
|
+
var __accessCheck$5 = (obj, member, msg) => {
|
|
2588
2589
|
if (!member.has(obj))
|
|
2589
2590
|
throw TypeError("Cannot " + msg);
|
|
2590
|
-
}, __privateGet$
|
|
2591
|
+
}, __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) => {
|
|
2591
2592
|
if (member.has(obj))
|
|
2592
2593
|
throw TypeError("Cannot add the same private member more than once");
|
|
2593
2594
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
2594
|
-
}, __privateSet$
|
|
2595
|
+
}, __privateSet$5 = (obj, member, value, setter) => (__accessCheck$5(obj, member, "write to private field"), member.set(obj, value), value), _client$4, _httpRequest$4;
|
|
2595
2596
|
class ObservableAssetsClient {
|
|
2596
2597
|
constructor(client, httpRequest) {
|
|
2597
|
-
__privateAdd$
|
|
2598
|
+
__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);
|
|
2598
2599
|
}
|
|
2599
2600
|
upload(assetType, body, options) {
|
|
2600
|
-
return _upload(__privateGet$
|
|
2601
|
+
return _upload(__privateGet$5(this, _client$4), __privateGet$5(this, _httpRequest$4), assetType, body, options);
|
|
2601
2602
|
}
|
|
2602
2603
|
}
|
|
2603
|
-
_client$
|
|
2604
|
+
_client$4 = /* @__PURE__ */ new WeakMap(), _httpRequest$4 = /* @__PURE__ */ new WeakMap();
|
|
2604
2605
|
var _client2$3, _httpRequest2$4;
|
|
2605
2606
|
class AssetsClient {
|
|
2606
2607
|
constructor(client, httpRequest) {
|
|
2607
|
-
__privateAdd$
|
|
2608
|
+
__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);
|
|
2608
2609
|
}
|
|
2609
2610
|
upload(assetType, body, options) {
|
|
2610
|
-
const observable2 = _upload(__privateGet$
|
|
2611
|
+
const observable2 = _upload(__privateGet$5(this, _client2$3), __privateGet$5(this, _httpRequest2$4), assetType, body, options);
|
|
2611
2612
|
return lastValueFrom(
|
|
2612
2613
|
observable2.pipe(
|
|
2613
2614
|
filter((event) => event.type === "response"),
|
|
@@ -2677,7 +2678,7 @@ ${selectionOpts}`);
|
|
|
2677
2678
|
observer.error(cooerceError(err));
|
|
2678
2679
|
}
|
|
2679
2680
|
function onMessage(evt) {
|
|
2680
|
-
const event = parseEvent(evt);
|
|
2681
|
+
const event = parseEvent$1(evt);
|
|
2681
2682
|
return event instanceof Error ? observer.error(event) : observer.next(event);
|
|
2682
2683
|
}
|
|
2683
2684
|
function onDisconnect() {
|
|
@@ -2690,10 +2691,10 @@ ${selectionOpts}`);
|
|
|
2690
2691
|
shouldEmitReconnect && observer.next({ type: "reconnect" });
|
|
2691
2692
|
}
|
|
2692
2693
|
async function getEventSource() {
|
|
2693
|
-
const { default:
|
|
2694
|
+
const { default: EventSource2 } = await Promise.resolve().then(function () { return browser$2; });
|
|
2694
2695
|
if (unsubscribed)
|
|
2695
2696
|
return;
|
|
2696
|
-
const evs = new
|
|
2697
|
+
const evs = new EventSource2(uri, esOptions);
|
|
2697
2698
|
return evs.addEventListener("error", onError), evs.addEventListener("channelError", onChannelError), evs.addEventListener("disconnect", onDisconnect), listenFor.forEach((type) => evs.addEventListener(type, onMessage)), evs;
|
|
2698
2699
|
}
|
|
2699
2700
|
function open() {
|
|
@@ -2709,7 +2710,7 @@ ${selectionOpts}`);
|
|
|
2709
2710
|
return stop;
|
|
2710
2711
|
});
|
|
2711
2712
|
}
|
|
2712
|
-
function parseEvent(event) {
|
|
2713
|
+
function parseEvent$1(event) {
|
|
2713
2714
|
try {
|
|
2714
2715
|
const data = event.data && JSON.parse(event.data) || {};
|
|
2715
2716
|
return Object.assign({ type: event.type }, data);
|
|
@@ -2720,12 +2721,83 @@ ${selectionOpts}`);
|
|
|
2720
2721
|
function cooerceError(err) {
|
|
2721
2722
|
if (err instanceof Error)
|
|
2722
2723
|
return err;
|
|
2723
|
-
const evt = parseEvent(err);
|
|
2724
|
+
const evt = parseEvent$1(err);
|
|
2724
2725
|
return evt instanceof Error ? evt : new Error(extractErrorMessage(evt));
|
|
2725
2726
|
}
|
|
2726
2727
|
function extractErrorMessage(err) {
|
|
2727
2728
|
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";
|
|
2728
2729
|
}
|
|
2730
|
+
var __accessCheck$4 = (obj, member, msg) => {
|
|
2731
|
+
if (!member.has(obj))
|
|
2732
|
+
throw TypeError("Cannot " + msg);
|
|
2733
|
+
}, __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) => {
|
|
2734
|
+
if (member.has(obj))
|
|
2735
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
2736
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
2737
|
+
}, __privateSet$4 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), member.set(obj, value), value), _client$3;
|
|
2738
|
+
class LiveClient {
|
|
2739
|
+
constructor(client) {
|
|
2740
|
+
__privateAdd$4(this, _client$3, void 0), __privateSet$4(this, _client$3, client);
|
|
2741
|
+
}
|
|
2742
|
+
events() {
|
|
2743
|
+
const path = _getDataUrl(__privateGet$4(this, _client$3), "live/events"), url = new URL(__privateGet$4(this, _client$3).getUrl(path, !1)), listenFor = ["restart", "message"];
|
|
2744
|
+
return new Observable((observer) => {
|
|
2745
|
+
let es, reconnectTimer, stopped = !1, unsubscribed = !1;
|
|
2746
|
+
open();
|
|
2747
|
+
function onError(evt) {
|
|
2748
|
+
if (!stopped) {
|
|
2749
|
+
if ("data" in evt) {
|
|
2750
|
+
const event = parseEvent(evt);
|
|
2751
|
+
observer.error(new Error(event.message, { cause: event }));
|
|
2752
|
+
}
|
|
2753
|
+
es.readyState === es.CLOSED && (unsubscribe(), clearTimeout(reconnectTimer), reconnectTimer = setTimeout(open, 100));
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
function onMessage(evt) {
|
|
2757
|
+
const event = parseEvent(evt);
|
|
2758
|
+
return event instanceof Error ? observer.error(event) : observer.next(event);
|
|
2759
|
+
}
|
|
2760
|
+
function unsubscribe() {
|
|
2761
|
+
if (es) {
|
|
2762
|
+
es.removeEventListener("error", onError);
|
|
2763
|
+
for (const type of listenFor)
|
|
2764
|
+
es.removeEventListener(type, onMessage);
|
|
2765
|
+
es.close();
|
|
2766
|
+
}
|
|
2767
|
+
}
|
|
2768
|
+
async function getEventSource() {
|
|
2769
|
+
const EventSourceImplementation = typeof EventSource > "u" ? (await Promise.resolve().then(function () { return browser$2; })).default : EventSource;
|
|
2770
|
+
if (unsubscribed)
|
|
2771
|
+
return;
|
|
2772
|
+
const evs = new EventSourceImplementation(url.toString());
|
|
2773
|
+
evs.addEventListener("error", onError);
|
|
2774
|
+
for (const type of listenFor)
|
|
2775
|
+
evs.addEventListener(type, onMessage);
|
|
2776
|
+
return evs;
|
|
2777
|
+
}
|
|
2778
|
+
function open() {
|
|
2779
|
+
getEventSource().then((eventSource) => {
|
|
2780
|
+
eventSource && (es = eventSource, unsubscribed && unsubscribe());
|
|
2781
|
+
}).catch((reason) => {
|
|
2782
|
+
observer.error(reason), stop();
|
|
2783
|
+
});
|
|
2784
|
+
}
|
|
2785
|
+
function stop() {
|
|
2786
|
+
stopped = !0, unsubscribe(), unsubscribed = !0;
|
|
2787
|
+
}
|
|
2788
|
+
return stop;
|
|
2789
|
+
});
|
|
2790
|
+
}
|
|
2791
|
+
}
|
|
2792
|
+
_client$3 = /* @__PURE__ */ new WeakMap();
|
|
2793
|
+
function parseEvent(event) {
|
|
2794
|
+
try {
|
|
2795
|
+
const data = event.data && JSON.parse(event.data) || {};
|
|
2796
|
+
return { type: event.type, id: event.lastEventId, ...data };
|
|
2797
|
+
} catch (err) {
|
|
2798
|
+
return err;
|
|
2799
|
+
}
|
|
2800
|
+
}
|
|
2729
2801
|
var __accessCheck$3 = (obj, member, msg) => {
|
|
2730
2802
|
if (!member.has(obj))
|
|
2731
2803
|
throw TypeError("Cannot " + msg);
|
|
@@ -2930,7 +3002,7 @@ ${selectionOpts}`);
|
|
|
2930
3002
|
}, __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value), _clientConfig, _httpRequest;
|
|
2931
3003
|
const _ObservableSanityClient = class _ObservableSanityClient2 {
|
|
2932
3004
|
constructor(httpRequest, config = defaultConfig) {
|
|
2933
|
-
__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));
|
|
3005
|
+
__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));
|
|
2934
3006
|
}
|
|
2935
3007
|
/**
|
|
2936
3008
|
* Clone the client - returns a new instance
|
|
@@ -3059,7 +3131,7 @@ ${selectionOpts}`);
|
|
|
3059
3131
|
var _clientConfig2, _httpRequest2;
|
|
3060
3132
|
const _SanityClient = class _SanityClient2 {
|
|
3061
3133
|
constructor(httpRequest, config = defaultConfig) {
|
|
3062
|
-
__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);
|
|
3134
|
+
__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);
|
|
3063
3135
|
}
|
|
3064
3136
|
/**
|
|
3065
3137
|
* Clone the client - returns a new instance
|