@sanity/client 6.2.0-fetch.5 → 6.2.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 +21 -10
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +21 -10
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +22 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +93 -93
- package/dist/index.js +22 -11
- package/dist/index.js.map +1 -1
- package/package.json +25 -21
- package/src/SanityClient.ts +83 -83
- package/src/assets/AssetsClient.ts +13 -13
- package/src/config.ts +20 -4
- package/src/data/dataMethods.ts +24 -22
- package/src/data/listen.ts +3 -3
- package/src/data/patch.ts +11 -11
- package/src/data/transaction.ts +13 -13
- package/src/datasets/DatasetsClient.ts +4 -4
- package/src/http/request.ts +1 -1
- package/src/http/requestOptions.ts +1 -1
- package/src/index.browser.ts +1 -1
- package/src/index.ts +1 -1
- package/src/projects/ProjectsClient.ts +2 -2
- package/src/users/UsersClient.ts +4 -4
- package/src/validators.ts +2 -2
- package/src/warnings.ts +1 -1
- package/umd/sanityClient.js +65 -21
- package/umd/sanityClient.min.js +3 -3
package/dist/index.cjs
CHANGED
|
@@ -8,7 +8,7 @@ var getIt = require('get-it');
|
|
|
8
8
|
var rxjs = require('rxjs');
|
|
9
9
|
var operators = require('rxjs/operators');
|
|
10
10
|
var name = "@sanity/client";
|
|
11
|
-
var version = "6.2.0
|
|
11
|
+
var version = "6.2.0";
|
|
12
12
|
const middleware = [middleware$1.debug({
|
|
13
13
|
verbose: true,
|
|
14
14
|
namespace: "sanity:client"
|
|
@@ -215,26 +215,26 @@ const validateObject = (op, val) => {
|
|
|
215
215
|
};
|
|
216
216
|
const validateDocumentId = (op, id) => {
|
|
217
217
|
if (typeof id !== "string" || !/^[a-z0-9_][a-z0-9_.-]{0,127}$/i.test(id) || id.includes("..")) {
|
|
218
|
-
throw new Error("".concat(op,
|
|
218
|
+
throw new Error("".concat(op, '(): "').concat(id, '" is not a valid document ID'));
|
|
219
219
|
}
|
|
220
220
|
};
|
|
221
221
|
const requireDocumentId = (op, doc) => {
|
|
222
222
|
if (!doc._id) {
|
|
223
|
-
throw new Error("".concat(op,
|
|
223
|
+
throw new Error("".concat(op, '() requires that the document contains an ID ("_id" property)'));
|
|
224
224
|
}
|
|
225
225
|
validateDocumentId(op, doc._id);
|
|
226
226
|
};
|
|
227
227
|
const validateInsert = (at, selector, items) => {
|
|
228
228
|
const signature = "insert(at, selector, items)";
|
|
229
229
|
if (VALID_INSERT_LOCATIONS.indexOf(at) === -1) {
|
|
230
|
-
const valid = VALID_INSERT_LOCATIONS.map(loc => "
|
|
231
|
-
throw new Error("".concat(signature,
|
|
230
|
+
const valid = VALID_INSERT_LOCATIONS.map(loc => '"'.concat(loc, '"')).join(", ");
|
|
231
|
+
throw new Error("".concat(signature, ' takes an "at"-argument which is one of: ').concat(valid));
|
|
232
232
|
}
|
|
233
233
|
if (typeof selector !== "string") {
|
|
234
|
-
throw new Error("".concat(signature,
|
|
234
|
+
throw new Error("".concat(signature, ' takes a "selector"-argument which must be a string'));
|
|
235
235
|
}
|
|
236
236
|
if (!Array.isArray(items)) {
|
|
237
|
-
throw new Error("".concat(signature,
|
|
237
|
+
throw new Error("".concat(signature, ' takes an "items"-argument which must be an array'));
|
|
238
238
|
}
|
|
239
239
|
};
|
|
240
240
|
const hasDataset = config => {
|
|
@@ -902,7 +902,7 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
902
902
|
...options.query
|
|
903
903
|
};
|
|
904
904
|
}
|
|
905
|
-
if (["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/query/") === 0) {
|
|
905
|
+
if (["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/query/") === 0) {
|
|
906
906
|
if (config.resultSourceMap) {
|
|
907
907
|
options.query = {
|
|
908
908
|
resultSourceMap: true,
|
|
@@ -919,9 +919,7 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
919
919
|
const reqOptions = requestOptions(config, Object.assign({}, options, {
|
|
920
920
|
url: _getUrl(client, uri, useCdn)
|
|
921
921
|
}));
|
|
922
|
-
const request = new rxjs.Observable(subscriber =>
|
|
923
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- the typings thinks it's optional because it's not required to specify it when calling createClient, but it's always defined in practice since SanityClient provides a default
|
|
924
|
-
httpRequest(reqOptions, config.requester).subscribe(subscriber));
|
|
922
|
+
const request = new rxjs.Observable(subscriber => httpRequest(reqOptions, config.requester).subscribe(subscriber));
|
|
925
923
|
return options.signal ? request.pipe(_withAbortSignal(options.signal)) : request;
|
|
926
924
|
}
|
|
927
925
|
function _request(client, httpRequest, options) {
|
|
@@ -1114,6 +1112,16 @@ const validateApiVersion = function validateApiVersion2(apiVersion) {
|
|
|
1114
1112
|
throw new Error("Invalid API version string, expected `1` or date in format `YYYY-MM-DD`");
|
|
1115
1113
|
}
|
|
1116
1114
|
};
|
|
1115
|
+
const validateApiPerspective = function validateApiPerspective2(perspective) {
|
|
1116
|
+
switch (perspective) {
|
|
1117
|
+
case "previewDrafts":
|
|
1118
|
+
case "published":
|
|
1119
|
+
case "raw":
|
|
1120
|
+
return;
|
|
1121
|
+
default:
|
|
1122
|
+
throw new TypeError("Invalid API perspective string, expected `published`, `previewDrafts` or `raw`");
|
|
1123
|
+
}
|
|
1124
|
+
};
|
|
1117
1125
|
const initConfig = (config, prevConfig) => {
|
|
1118
1126
|
const specifiedConfig = Object.assign({}, prevConfig, config);
|
|
1119
1127
|
if (!specifiedConfig.apiVersion) {
|
|
@@ -1128,6 +1136,9 @@ const initConfig = (config, prevConfig) => {
|
|
|
1128
1136
|
if (projectBased && !newConfig.projectId) {
|
|
1129
1137
|
throw new Error("Configuration must contain `projectId`");
|
|
1130
1138
|
}
|
|
1139
|
+
if (typeof newConfig.perspective === "string") {
|
|
1140
|
+
validateApiPerspective(newConfig.perspective);
|
|
1141
|
+
}
|
|
1131
1142
|
if ("encodeSourceMapAtPath" in newConfig || "encodeSourceMap" in newConfig || "studioUrl" in newConfig || "logger" in newConfig) {
|
|
1132
1143
|
throw new Error("It looks like you're using options meant for '@sanity/preview-kit/client', such as 'encodeSourceMapAtPath', 'encodeSourceMap', 'studioUrl' and 'logger'. Make sure you're using the right import.");
|
|
1133
1144
|
}
|