@sanity/client 5.3.2 → 5.4.1-lazy-event-source.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/README.md +1 -1
- package/dist/index.browser.cjs +32 -13
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +21 -7
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +33 -14
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +22 -8
- package/dist/index.js.map +1 -1
- package/package.json +13 -12
- package/src/assets/AssetsClient.ts +1 -1
- package/src/data/listen.ts +21 -6
- package/src/index.browser.ts +3 -0
- package/src/index.ts +3 -0
- package/umd/sanityClient.js +1181 -1142
- package/umd/sanityClient.min.js +3 -3
package/README.md
CHANGED
|
@@ -738,7 +738,7 @@ An important note on this approach is that you cannot call `commit()` on transac
|
|
|
738
738
|
Assets can be uploaded using the `client.assets.upload(...)` method.
|
|
739
739
|
|
|
740
740
|
```
|
|
741
|
-
client.assets.upload(type: 'file' | image', body: File | Blob | Buffer |
|
|
741
|
+
client.assets.upload(type: 'file' | image', body: File | Blob | Buffer | NodeJS.ReadableStream, options = {}): Promise<AssetDocument>
|
|
742
742
|
```
|
|
743
743
|
|
|
744
744
|
👉 Read more about [assets in Sanity](https://sanity.io/docs/assets)
|
package/dist/index.browser.cjs
CHANGED
|
@@ -7,13 +7,6 @@ var getIt = require('get-it');
|
|
|
7
7
|
var middleware = require('get-it/middleware');
|
|
8
8
|
var rxjs = require('rxjs');
|
|
9
9
|
var operators = require('rxjs/operators');
|
|
10
|
-
var polyfilledEventSource = require('@sanity/eventsource');
|
|
11
|
-
function _interopDefaultCompat(e) {
|
|
12
|
-
return e && typeof e === 'object' && 'default' in e ? e : {
|
|
13
|
-
default: e
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
var polyfilledEventSource__default = /*#__PURE__*/_interopDefaultCompat(polyfilledEventSource);
|
|
17
10
|
var envMiddleware = [];
|
|
18
11
|
const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
|
|
19
12
|
class ClientError extends Error {
|
|
@@ -959,7 +952,7 @@ function _upload(client, httpRequest, assetType, body) {
|
|
|
959
952
|
});
|
|
960
953
|
}
|
|
961
954
|
function optionsFromFile(opts, file) {
|
|
962
|
-
if (typeof
|
|
955
|
+
if (typeof File === "undefined" || !(file instanceof File)) {
|
|
963
956
|
return opts;
|
|
964
957
|
}
|
|
965
958
|
return Object.assign({
|
|
@@ -1072,7 +1065,6 @@ const pick = (obj, props) => props.reduce((selection, prop) => {
|
|
|
1072
1065
|
return selection;
|
|
1073
1066
|
}, {});
|
|
1074
1067
|
const MAX_URL_LENGTH = 16e3 - 1200;
|
|
1075
|
-
const EventSource = polyfilledEventSource__default.default;
|
|
1076
1068
|
const possibleOptions = ["includePreviousRevision", "includeResult", "visibility", "effectFormat", "tag"];
|
|
1077
1069
|
const defaultOptions = {
|
|
1078
1070
|
includeResult: true
|
|
@@ -1115,7 +1107,13 @@ function _listen(query, params) {
|
|
|
1115
1107
|
};
|
|
1116
1108
|
}
|
|
1117
1109
|
return new rxjs.Observable(observer => {
|
|
1118
|
-
let es
|
|
1110
|
+
let es;
|
|
1111
|
+
getEventSource().then(eventSource => {
|
|
1112
|
+
es = eventSource;
|
|
1113
|
+
}).catch(reason => {
|
|
1114
|
+
observer.error(reason);
|
|
1115
|
+
stop();
|
|
1116
|
+
});
|
|
1119
1117
|
let reconnectTimer;
|
|
1120
1118
|
let stopped = false;
|
|
1121
1119
|
function onError() {
|
|
@@ -1126,7 +1124,7 @@ function _listen(query, params) {
|
|
|
1126
1124
|
if (stopped) {
|
|
1127
1125
|
return;
|
|
1128
1126
|
}
|
|
1129
|
-
if (es.readyState ===
|
|
1127
|
+
if (es.readyState === es.CLOSED) {
|
|
1130
1128
|
unsubscribe();
|
|
1131
1129
|
clearTimeout(reconnectTimer);
|
|
1132
1130
|
reconnectTimer = setTimeout(open, 100);
|
|
@@ -1145,6 +1143,7 @@ function _listen(query, params) {
|
|
|
1145
1143
|
observer.complete();
|
|
1146
1144
|
}
|
|
1147
1145
|
function unsubscribe() {
|
|
1146
|
+
if (!es) return;
|
|
1148
1147
|
es.removeEventListener("error", onError);
|
|
1149
1148
|
es.removeEventListener("channelError", onChannelError);
|
|
1150
1149
|
es.removeEventListener("disconnect", onDisconnect);
|
|
@@ -1158,7 +1157,10 @@ function _listen(query, params) {
|
|
|
1158
1157
|
});
|
|
1159
1158
|
}
|
|
1160
1159
|
}
|
|
1161
|
-
function getEventSource() {
|
|
1160
|
+
async function getEventSource() {
|
|
1161
|
+
const {
|
|
1162
|
+
default: EventSource
|
|
1163
|
+
} = await import('@sanity/eventsource');
|
|
1162
1164
|
const evs = new EventSource(uri, esOptions);
|
|
1163
1165
|
evs.addEventListener("error", onError);
|
|
1164
1166
|
evs.addEventListener("channelError", onChannelError);
|
|
@@ -1167,7 +1169,12 @@ function _listen(query, params) {
|
|
|
1167
1169
|
return evs;
|
|
1168
1170
|
}
|
|
1169
1171
|
function open() {
|
|
1170
|
-
|
|
1172
|
+
getEventSource().then(eventSource => {
|
|
1173
|
+
es = eventSource;
|
|
1174
|
+
}).catch(reason => {
|
|
1175
|
+
observer.error(reason);
|
|
1176
|
+
stop();
|
|
1177
|
+
});
|
|
1171
1178
|
}
|
|
1172
1179
|
function stop() {
|
|
1173
1180
|
stopped = true;
|
|
@@ -1756,6 +1763,18 @@ function deprecatedCreateClient(config) {
|
|
|
1756
1763
|
printNoDefaultExport();
|
|
1757
1764
|
return new SanityClient(httpRequest, config);
|
|
1758
1765
|
}
|
|
1766
|
+
Object.defineProperty(exports, 'unstable__adapter', {
|
|
1767
|
+
enumerable: true,
|
|
1768
|
+
get: function () {
|
|
1769
|
+
return getIt.adapter;
|
|
1770
|
+
}
|
|
1771
|
+
});
|
|
1772
|
+
Object.defineProperty(exports, 'unstable__environment', {
|
|
1773
|
+
enumerable: true,
|
|
1774
|
+
get: function () {
|
|
1775
|
+
return getIt.environment;
|
|
1776
|
+
}
|
|
1777
|
+
});
|
|
1759
1778
|
exports.BasePatch = BasePatch;
|
|
1760
1779
|
exports.BaseTransaction = BaseTransaction;
|
|
1761
1780
|
exports.ClientError = ClientError;
|