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