@sanity/client 6.27.2-resources.2 → 6.27.2

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.cjs CHANGED
@@ -164,7 +164,7 @@ function connectWithESInstance(es, events) {
164
164
  return new rxjs.Observable((observer) => {
165
165
  const emitOpen = events.includes("open"), emitReconnect = events.includes("reconnect");
166
166
  function onError(evt) {
167
- if (console.log("Eventsource onError", evt, es.url), "data" in evt) {
167
+ if ("data" in evt) {
168
168
  const [parseError, event] = parseEvent(evt);
169
169
  observer.error(
170
170
  parseError ? new MessageParseError("Unable to parse EventSource error message", { cause: event }) : new MessageError((event?.data).message, event)
@@ -737,20 +737,11 @@ function _create(client, httpRequest, doc, op, options = {}) {
737
737
  const mutation = { [op]: doc }, opts = Object.assign({ returnFirst: !0, returnDocuments: !0 }, options);
738
738
  return _dataRequest(client, httpRequest, "mutate", { mutations: [mutation] }, opts);
739
739
  }
740
- function _resourceBase(resource) {
741
- return `/${resource.type}/${resource.id}`;
742
- }
743
- function isDataRequestUri(uri, resource) {
744
- return resource ? uri.indexOf(`/${_resourceBase(resource)}/data/`) === 0 : uri.indexOf("/data/") === 0;
745
- }
746
- function isDataQueryRequestUri(uri, resource) {
747
- return resource ? uri.indexOf(`/${_resourceBase(resource)}/data/query`) === 0 : uri.indexOf("/data/query") === 0;
748
- }
749
740
  function _requestObservable(client, httpRequest, options) {
750
- const uri = options.url || options.uri, config$1 = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isDataRequestUri(uri, config$1.experimental_resource) : options.canUseCdn;
741
+ const uri = options.url || options.uri, config$1 = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/") === 0 : options.canUseCdn;
751
742
  let useCdn = (options.useCdn ?? config$1.useCdn) && canUseCdn;
752
743
  const tag = options.tag && config$1.requestTagPrefix ? [config$1.requestTagPrefix, options.tag].join(".") : options.tag || config$1.requestTagPrefix;
753
- if (tag && options.tag !== null && (options.query = { tag: config.requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && isDataQueryRequestUri(uri, config$1.experimental_resource)) {
744
+ if (tag && options.tag !== null && (options.query = { tag: config.requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/query/") === 0) {
754
745
  const resultSourceMap = options.resultSourceMap ?? config$1.resultSourceMap;
755
746
  resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
756
747
  const perspectiveOption = options.perspective || config$1.perspective;
@@ -776,18 +767,12 @@ function _request(client, httpRequest, options) {
776
767
  );
777
768
  }
778
769
  function _getDataUrl(client, operation, path) {
779
- const config$1 = client.config();
780
- if (config$1.experimental_resource) {
781
- const baseUri2 = `/${operation}`;
782
- return (path ? `${baseUri2}/${path}` : baseUri2).replace(/\/($|\?)/, "$1");
783
- }
784
- const catalog = config.hasDataset(config$1), baseUri = `/${operation}/${catalog}`;
770
+ const config$1 = client.config(), catalog = config.hasDataset(config$1), baseUri = `/${operation}/${catalog}`;
785
771
  return `/data${path ? `${baseUri}/${path}` : baseUri}`.replace(/\/($|\?)/, "$1");
786
772
  }
787
773
  function _getUrl(client, uri, canUseCdn = !1) {
788
- const { url, cdnUrl, experimental_resource } = client.config();
789
- let base = canUseCdn ? cdnUrl : url;
790
- return experimental_resource && uri.indexOf("/users") !== -1 && (base = base.replace(_resourceBase(experimental_resource), "")), `${base}/${uri.replace(/^\//, "")}`;
774
+ const { url, cdnUrl } = client.config();
775
+ return `${canUseCdn ? cdnUrl : url}/${uri.replace(/^\//, "")}`;
791
776
  }
792
777
  function _withAbortSignal(signal) {
793
778
  return (input) => new rxjs.Observable((observer) => {
@@ -841,7 +826,7 @@ function _upload(client, httpRequest, assetType, body, opts = {}) {
841
826
  config.validateAssetType(assetType);
842
827
  let meta = opts.extract || void 0;
843
828
  meta && !meta.length && (meta = ["none"]);
844
- const config$1 = client.config(), dataset = config$1.experimental_resource ? void 0 : config.hasDataset(config$1), assetEndpoint = assetType === "image" ? "images" : "files", options = optionsFromFile(opts, body), { tag, label, title, description, creditLine, filename, source } = options, query = {
829
+ const dataset = config.hasDataset(client.config()), assetEndpoint = assetType === "image" ? "images" : "files", options = optionsFromFile(opts, body), { tag, label, title, description, creditLine, filename, source } = options, query = {
845
830
  label,
846
831
  title,
847
832
  description,
@@ -853,7 +838,7 @@ function _upload(client, httpRequest, assetType, body, opts = {}) {
853
838
  tag,
854
839
  method: "POST",
855
840
  timeout: options.timeout || 0,
856
- uri: dataset ? `/assets/${assetEndpoint}/${dataset}` : `/assets/${assetEndpoint}`,
841
+ uri: `/assets/${assetEndpoint}/${dataset}`,
857
842
  headers: options.contentType ? { "Content-Type": options.contentType } : {},
858
843
  query,
859
844
  body
@@ -1076,23 +1061,6 @@ class DatasetsClient {
1076
1061
  );
1077
1062
  }
1078
1063
  }
1079
- class ThrowingDatasetsClient extends DatasetsClient {
1080
- constructor(client, httpRequest) {
1081
- super(client, httpRequest);
1082
- }
1083
- create() {
1084
- throw new Error("cannot create dataset with the current client configuration");
1085
- }
1086
- edit() {
1087
- throw new Error("cannot edit dataset with the current client configuration");
1088
- }
1089
- delete() {
1090
- throw new Error("cannot delete dataset with the current client configuration");
1091
- }
1092
- list() {
1093
- throw new Error("cannot list dataset with the current client configuration");
1094
- }
1095
- }
1096
1064
  function _modify(client, httpRequest, method, name2, options) {
1097
1065
  return config.dataset(name2), _request(client, httpRequest, {
1098
1066
  method,
@@ -1348,7 +1316,7 @@ class SanityClient {
1348
1316
  */
1349
1317
  listen = _listen;
1350
1318
  constructor(httpRequest, config$1 = config.defaultConfig) {
1351
- this.config(config$1), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = this.#clientConfig.experimental_resource ? new ThrowingDatasetsClient(this, this.#httpRequest) : new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config$1);
1319
+ this.config(config$1), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config$1);
1352
1320
  }
1353
1321
  /**
1354
1322
  * Clone the client - returns a new instance
@@ -1524,7 +1492,7 @@ function defineDeprecatedCreateClient(createClient2) {
1524
1492
  return config.printNoDefaultExport(), createClient2(config$1);
1525
1493
  };
1526
1494
  }
1527
- var name = "@sanity/client", version = "6.27.2-resources.2";
1495
+ var name = "@sanity/client", version = "6.27.2";
1528
1496
  const middleware = [
1529
1497
  middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
1530
1498
  middleware$1.headers({ "User-Agent": `${name} ${version}` }),