@sanity/client 7.8.2-datasets.0 → 7.9.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.cjs CHANGED
@@ -945,24 +945,10 @@ function _request(client, httpRequest, options) {
945
945
  function _getDataUrl(client, operation, path) {
946
946
  const config$1 = client.config();
947
947
  if (config$1["~experimental_resource"]) {
948
- if (config.resourceConfig(config$1), operation === "" && path?.startsWith("datasets")) {
949
- const { type, id } = config$1["~experimental_resource"];
950
- if (type === "dataset") {
951
- const segments = id.split(".");
952
- if (segments.length !== 2)
953
- throw new Error('Invalid dataset resource ID. Expected format "project.dataset".');
954
- const base = `/projects/${segments[0]}`, uri3 = [path].filter(Boolean).join("/");
955
- return `${base}/${uri3}`.replace(/\/($|\?)/, "$1");
956
- } else if (type === "project") {
957
- const base = `/projects/${id}`, uri3 = [path].filter(Boolean).join("/");
958
- return `${base}/${uri3}`.replace(/\/($|\?)/, "$1");
959
- }
960
- }
961
- const resourceBase = resourceDataBase(config$1), uri2 = [operation, path].filter(Boolean).join("/");
948
+ config.resourceConfig(config$1);
949
+ const resourceBase = resourceDataBase(config$1), uri2 = path !== void 0 ? `${operation}/${path}` : operation;
962
950
  return `${resourceBase}/${uri2}`.replace(/\/($|\?)/, "$1");
963
951
  }
964
- if (operation === "")
965
- return `/${path || ""}`;
966
952
  const catalog = config.hasDataset(config$1), baseUri = `/${operation}/${catalog}`;
967
953
  return `/data${path !== void 0 ? `${baseUri}/${path}` : baseUri}`.replace(/\/($|\?)/, "$1");
968
954
  }
@@ -1007,8 +993,6 @@ const resourceDataBase = (config2) => {
1007
993
  return `/media-libraries/${id}`;
1008
994
  case "dashboard":
1009
995
  return `/dashboards/${id}`;
1010
- case "project":
1011
- return `/projects/${id}`;
1012
996
  default:
1013
997
  throw new Error(`Unsupported resource type: ${type.toString()}`);
1014
998
  }
@@ -1179,10 +1163,6 @@ function buildAssetUploadUrl(config$1, assetType) {
1179
1163
  if (config$1["~experimental_resource"]) {
1180
1164
  const { type, id } = config$1["~experimental_resource"];
1181
1165
  switch (type) {
1182
- case "project":
1183
- throw new Error(
1184
- "Assets are not supported for project resources, yet. Configure the client with `{projectId: <projectId>}` instead."
1185
- );
1186
1166
  case "dataset":
1187
1167
  throw new Error(
1188
1168
  "Assets are not supported for dataset resources, yet. Configure the client with `{projectId: <projectId>, dataset: <datasetId>}` instead."
@@ -1400,11 +1380,10 @@ class ObservableDatasetsClient {
1400
1380
  * Fetch a list of datasets for the configured project
1401
1381
  */
1402
1382
  list() {
1403
- const resource = this.#client.config()["~experimental_resource"];
1404
- if (resource && resource.type !== "project")
1405
- throw new Error('`dataset.list()` requires a resource type of "project".');
1406
- const uri = _getDataUrl(this.#client, "", "datasets");
1407
- return _request(this.#client, this.#httpRequest, {
1383
+ config.resourceGuard("dataset", this.#client.config());
1384
+ const config$1 = this.#client.config(), projectId = config$1.projectId;
1385
+ let uri = "/datasets";
1386
+ return config$1.useProjectHostname === !1 && (uri = `/projects/${projectId}/datasets`), _request(this.#client, this.#httpRequest, {
1408
1387
  uri,
1409
1388
  tag: null
1410
1389
  });
@@ -1423,7 +1402,7 @@ class DatasetsClient {
1423
1402
  * @param options - Options for the dataset
1424
1403
  */
1425
1404
  create(name2, options) {
1426
- return rxjs.lastValueFrom(
1405
+ return config.resourceGuard("dataset", this.#client.config()), rxjs.lastValueFrom(
1427
1406
  _modify(this.#client, this.#httpRequest, "PUT", name2, options)
1428
1407
  );
1429
1408
  }
@@ -1434,7 +1413,7 @@ class DatasetsClient {
1434
1413
  * @param options - New options for the dataset
1435
1414
  */
1436
1415
  edit(name2, options) {
1437
- return rxjs.lastValueFrom(
1416
+ return config.resourceGuard("dataset", this.#client.config()), rxjs.lastValueFrom(
1438
1417
  _modify(this.#client, this.#httpRequest, "PATCH", name2, options)
1439
1418
  );
1440
1419
  }
@@ -1444,38 +1423,24 @@ class DatasetsClient {
1444
1423
  * @param name - Name of the dataset to delete
1445
1424
  */
1446
1425
  delete(name2) {
1447
- return rxjs.lastValueFrom(_modify(this.#client, this.#httpRequest, "DELETE", name2));
1426
+ return config.resourceGuard("dataset", this.#client.config()), rxjs.lastValueFrom(_modify(this.#client, this.#httpRequest, "DELETE", name2));
1448
1427
  }
1449
1428
  /**
1450
1429
  * Fetch a list of datasets for the configured project
1451
1430
  */
1452
1431
  list() {
1453
- const resource = this.#client.config()["~experimental_resource"];
1454
- if (resource && resource.type !== "project")
1455
- throw new Error('`dataset.list()` requires a resource type of "project".');
1456
- const uri = _getDataUrl(this.#client, "", "datasets");
1457
- return rxjs.lastValueFrom(
1432
+ config.resourceGuard("dataset", this.#client.config());
1433
+ const config$1 = this.#client.config(), projectId = config$1.projectId;
1434
+ let uri = "/datasets";
1435
+ return config$1.useProjectHostname === !1 && (uri = `/projects/${projectId}/datasets`), rxjs.lastValueFrom(
1458
1436
  _request(this.#client, this.#httpRequest, { uri, tag: null })
1459
1437
  );
1460
1438
  }
1461
1439
  }
1462
1440
  function _modify(client, httpRequest, method, name2, options) {
1463
- config.dataset(name2);
1464
- const resource = client.config()["~experimental_resource"];
1465
- if (resource)
1466
- if (resource.type === "dataset") {
1467
- const segments = resource.id.split(".");
1468
- if (segments.length !== 2)
1469
- throw new Error('Dataset resource ID must be in the format "project.dataset"');
1470
- const datasetName = segments[1];
1471
- if (name2 !== datasetName)
1472
- throw new Error(`Dataset name "${name2}" does not match resource dataset "${datasetName}"`);
1473
- } else
1474
- throw new Error('Dataset create/edit/delete operations require a resource type of "dataset"');
1475
- const uri = _getDataUrl(client, "", `datasets/${name2}`);
1476
- return _request(client, httpRequest, {
1441
+ return config.resourceGuard("dataset", client.config()), config.dataset(name2), _request(client, httpRequest, {
1477
1442
  method,
1478
- uri,
1443
+ uri: `/datasets/${name2}`,
1479
1444
  body: options,
1480
1445
  tag: null
1481
1446
  });
@@ -2613,7 +2578,7 @@ function defineDeprecatedCreateClient(createClient2) {
2613
2578
  return config.printNoDefaultExport(), createClient2(config$1);
2614
2579
  };
2615
2580
  }
2616
- var name = "@sanity/client", version = "7.8.2-datasets.0";
2581
+ var name = "@sanity/client", version = "7.9.0";
2617
2582
  const middleware = [
2618
2583
  middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
2619
2584
  middleware$1.headers({ "User-Agent": `${name} ${version}` }),