@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.js
CHANGED
|
@@ -4,7 +4,7 @@ export { adapter as unstable__adapter, environment as unstable__environment } fr
|
|
|
4
4
|
import { Observable, lastValueFrom } from 'rxjs';
|
|
5
5
|
import { map, filter } from 'rxjs/operators';
|
|
6
6
|
var name = "@sanity/client";
|
|
7
|
-
var version = "6.2.0
|
|
7
|
+
var version = "6.2.0";
|
|
8
8
|
const middleware = [debug({
|
|
9
9
|
verbose: true,
|
|
10
10
|
namespace: "sanity:client"
|
|
@@ -211,26 +211,26 @@ const validateObject = (op, val) => {
|
|
|
211
211
|
};
|
|
212
212
|
const validateDocumentId = (op, id) => {
|
|
213
213
|
if (typeof id !== "string" || !/^[a-z0-9_][a-z0-9_.-]{0,127}$/i.test(id) || id.includes("..")) {
|
|
214
|
-
throw new Error("".concat(op,
|
|
214
|
+
throw new Error("".concat(op, '(): "').concat(id, '" is not a valid document ID'));
|
|
215
215
|
}
|
|
216
216
|
};
|
|
217
217
|
const requireDocumentId = (op, doc) => {
|
|
218
218
|
if (!doc._id) {
|
|
219
|
-
throw new Error("".concat(op,
|
|
219
|
+
throw new Error("".concat(op, '() requires that the document contains an ID ("_id" property)'));
|
|
220
220
|
}
|
|
221
221
|
validateDocumentId(op, doc._id);
|
|
222
222
|
};
|
|
223
223
|
const validateInsert = (at, selector, items) => {
|
|
224
224
|
const signature = "insert(at, selector, items)";
|
|
225
225
|
if (VALID_INSERT_LOCATIONS.indexOf(at) === -1) {
|
|
226
|
-
const valid = VALID_INSERT_LOCATIONS.map(loc => "
|
|
227
|
-
throw new Error("".concat(signature,
|
|
226
|
+
const valid = VALID_INSERT_LOCATIONS.map(loc => '"'.concat(loc, '"')).join(", ");
|
|
227
|
+
throw new Error("".concat(signature, ' takes an "at"-argument which is one of: ').concat(valid));
|
|
228
228
|
}
|
|
229
229
|
if (typeof selector !== "string") {
|
|
230
|
-
throw new Error("".concat(signature,
|
|
230
|
+
throw new Error("".concat(signature, ' takes a "selector"-argument which must be a string'));
|
|
231
231
|
}
|
|
232
232
|
if (!Array.isArray(items)) {
|
|
233
|
-
throw new Error("".concat(signature,
|
|
233
|
+
throw new Error("".concat(signature, ' takes an "items"-argument which must be an array'));
|
|
234
234
|
}
|
|
235
235
|
};
|
|
236
236
|
const hasDataset = config => {
|
|
@@ -898,7 +898,7 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
898
898
|
...options.query
|
|
899
899
|
};
|
|
900
900
|
}
|
|
901
|
-
if (["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/query/") === 0) {
|
|
901
|
+
if (["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/query/") === 0) {
|
|
902
902
|
if (config.resultSourceMap) {
|
|
903
903
|
options.query = {
|
|
904
904
|
resultSourceMap: true,
|
|
@@ -915,9 +915,7 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
915
915
|
const reqOptions = requestOptions(config, Object.assign({}, options, {
|
|
916
916
|
url: _getUrl(client, uri, useCdn)
|
|
917
917
|
}));
|
|
918
|
-
const request = new Observable(subscriber =>
|
|
919
|
-
// 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
|
|
920
|
-
httpRequest(reqOptions, config.requester).subscribe(subscriber));
|
|
918
|
+
const request = new Observable(subscriber => httpRequest(reqOptions, config.requester).subscribe(subscriber));
|
|
921
919
|
return options.signal ? request.pipe(_withAbortSignal(options.signal)) : request;
|
|
922
920
|
}
|
|
923
921
|
function _request(client, httpRequest, options) {
|
|
@@ -1110,6 +1108,16 @@ const validateApiVersion = function validateApiVersion2(apiVersion) {
|
|
|
1110
1108
|
throw new Error("Invalid API version string, expected `1` or date in format `YYYY-MM-DD`");
|
|
1111
1109
|
}
|
|
1112
1110
|
};
|
|
1111
|
+
const validateApiPerspective = function validateApiPerspective2(perspective) {
|
|
1112
|
+
switch (perspective) {
|
|
1113
|
+
case "previewDrafts":
|
|
1114
|
+
case "published":
|
|
1115
|
+
case "raw":
|
|
1116
|
+
return;
|
|
1117
|
+
default:
|
|
1118
|
+
throw new TypeError("Invalid API perspective string, expected `published`, `previewDrafts` or `raw`");
|
|
1119
|
+
}
|
|
1120
|
+
};
|
|
1113
1121
|
const initConfig = (config, prevConfig) => {
|
|
1114
1122
|
const specifiedConfig = Object.assign({}, prevConfig, config);
|
|
1115
1123
|
if (!specifiedConfig.apiVersion) {
|
|
@@ -1124,6 +1132,9 @@ const initConfig = (config, prevConfig) => {
|
|
|
1124
1132
|
if (projectBased && !newConfig.projectId) {
|
|
1125
1133
|
throw new Error("Configuration must contain `projectId`");
|
|
1126
1134
|
}
|
|
1135
|
+
if (typeof newConfig.perspective === "string") {
|
|
1136
|
+
validateApiPerspective(newConfig.perspective);
|
|
1137
|
+
}
|
|
1127
1138
|
if ("encodeSourceMapAtPath" in newConfig || "encodeSourceMap" in newConfig || "studioUrl" in newConfig || "logger" in newConfig) {
|
|
1128
1139
|
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.");
|
|
1129
1140
|
}
|