@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.
@@ -780,10 +780,6 @@ declare type ClientConfigResource =
780
780
  type: 'dashboard'
781
781
  id: string
782
782
  }
783
- | {
784
- type: 'project'
785
- id: string
786
- }
787
783
 
788
784
  /** @public */
789
785
  export declare class ClientError extends Error {
@@ -4118,6 +4114,9 @@ export declare type ReleaseAction =
4118
4114
  | UnscheduleReleaseAction
4119
4115
  | DeleteReleaseAction
4120
4116
 
4117
+ /** @public */
4118
+ export declare type ReleaseCardinality = 'many' | 'one' | undefined
4119
+
4121
4120
  /** @internal */
4122
4121
  export declare interface ReleaseDocument extends SanityDocument {
4123
4122
  /**
@@ -4154,6 +4153,7 @@ export declare interface ReleaseDocument extends SanityDocument {
4154
4153
  description?: string
4155
4154
  intendedPublishAt?: string
4156
4155
  releaseType: ReleaseType
4156
+ cardinality?: ReleaseCardinality
4157
4157
  }
4158
4158
  }
4159
4159
 
@@ -780,10 +780,6 @@ declare type ClientConfigResource =
780
780
  type: 'dashboard'
781
781
  id: string
782
782
  }
783
- | {
784
- type: 'project'
785
- id: string
786
- }
787
783
 
788
784
  /** @public */
789
785
  export declare class ClientError extends Error {
@@ -4118,6 +4114,9 @@ export declare type ReleaseAction =
4118
4114
  | UnscheduleReleaseAction
4119
4115
  | DeleteReleaseAction
4120
4116
 
4117
+ /** @public */
4118
+ export declare type ReleaseCardinality = 'many' | 'one' | undefined
4119
+
4121
4120
  /** @internal */
4122
4121
  export declare interface ReleaseDocument extends SanityDocument {
4123
4122
  /**
@@ -4154,6 +4153,7 @@ export declare interface ReleaseDocument extends SanityDocument {
4154
4153
  description?: string
4155
4154
  intendedPublishAt?: string
4156
4155
  releaseType: ReleaseType
4156
+ cardinality?: ReleaseCardinality
4157
4157
  }
4158
4158
  }
4159
4159
 
@@ -276,7 +276,6 @@ const VALID_ASSET_TYPES = ["image", "file"], VALID_INSERT_LOCATIONS = ["before",
276
276
  throw new Error('Dataset resource ID must be in the format "project.dataset"');
277
277
  return;
278
278
  }
279
- case "project":
280
279
  case "dashboard":
281
280
  case "media-library":
282
281
  case "canvas":
@@ -1101,24 +1100,10 @@ function _request(client, httpRequest, options) {
1101
1100
  function _getDataUrl(client, operation, path) {
1102
1101
  const config = client.config();
1103
1102
  if (config["~experimental_resource"]) {
1104
- if (resourceConfig(config), operation === "" && path?.startsWith("datasets")) {
1105
- const { type, id } = config["~experimental_resource"];
1106
- if (type === "dataset") {
1107
- const segments = id.split(".");
1108
- if (segments.length !== 2)
1109
- throw new Error('Invalid dataset resource ID. Expected format "project.dataset".');
1110
- const base = `/projects/${segments[0]}`, uri3 = [path].filter(Boolean).join("/");
1111
- return `${base}/${uri3}`.replace(/\/($|\?)/, "$1");
1112
- } else if (type === "project") {
1113
- const base = `/projects/${id}`, uri3 = [path].filter(Boolean).join("/");
1114
- return `${base}/${uri3}`.replace(/\/($|\?)/, "$1");
1115
- }
1116
- }
1117
- const resourceBase = resourceDataBase(config), uri2 = [operation, path].filter(Boolean).join("/");
1103
+ resourceConfig(config);
1104
+ const resourceBase = resourceDataBase(config), uri2 = path !== void 0 ? `${operation}/${path}` : operation;
1118
1105
  return `${resourceBase}/${uri2}`.replace(/\/($|\?)/, "$1");
1119
1106
  }
1120
- if (operation === "")
1121
- return `/${path || ""}`;
1122
1107
  const catalog = hasDataset(config), baseUri = `/${operation}/${catalog}`;
1123
1108
  return `/data${path !== void 0 ? `${baseUri}/${path}` : baseUri}`.replace(/\/($|\?)/, "$1");
1124
1109
  }
@@ -1163,8 +1148,6 @@ const resourceDataBase = (config) => {
1163
1148
  return `/media-libraries/${id}`;
1164
1149
  case "dashboard":
1165
1150
  return `/dashboards/${id}`;
1166
- case "project":
1167
- return `/projects/${id}`;
1168
1151
  default:
1169
1152
  throw new Error(`Unsupported resource type: ${type.toString()}`);
1170
1153
  }
@@ -1335,10 +1318,6 @@ function buildAssetUploadUrl(config, assetType) {
1335
1318
  if (config["~experimental_resource"]) {
1336
1319
  const { type, id } = config["~experimental_resource"];
1337
1320
  switch (type) {
1338
- case "project":
1339
- throw new Error(
1340
- "Assets are not supported for project resources, yet. Configure the client with `{projectId: <projectId>}` instead."
1341
- );
1342
1321
  case "dataset":
1343
1322
  throw new Error(
1344
1323
  "Assets are not supported for dataset resources, yet. Configure the client with `{projectId: <projectId>, dataset: <datasetId>}` instead."
@@ -1556,11 +1535,10 @@ class ObservableDatasetsClient {
1556
1535
  * Fetch a list of datasets for the configured project
1557
1536
  */
1558
1537
  list() {
1559
- const resource = this.#client.config()["~experimental_resource"];
1560
- if (resource && resource.type !== "project")
1561
- throw new Error('`dataset.list()` requires a resource type of "project".');
1562
- const uri = _getDataUrl(this.#client, "", "datasets");
1563
- return _request(this.#client, this.#httpRequest, {
1538
+ resourceGuard("dataset", this.#client.config());
1539
+ const config = this.#client.config(), projectId2 = config.projectId;
1540
+ let uri = "/datasets";
1541
+ return config.useProjectHostname === !1 && (uri = `/projects/${projectId2}/datasets`), _request(this.#client, this.#httpRequest, {
1564
1542
  uri,
1565
1543
  tag: null
1566
1544
  });
@@ -1579,7 +1557,7 @@ class DatasetsClient {
1579
1557
  * @param options - Options for the dataset
1580
1558
  */
1581
1559
  create(name, options) {
1582
- return lastValueFrom(
1560
+ return resourceGuard("dataset", this.#client.config()), lastValueFrom(
1583
1561
  _modify(this.#client, this.#httpRequest, "PUT", name, options)
1584
1562
  );
1585
1563
  }
@@ -1590,7 +1568,7 @@ class DatasetsClient {
1590
1568
  * @param options - New options for the dataset
1591
1569
  */
1592
1570
  edit(name, options) {
1593
- return lastValueFrom(
1571
+ return resourceGuard("dataset", this.#client.config()), lastValueFrom(
1594
1572
  _modify(this.#client, this.#httpRequest, "PATCH", name, options)
1595
1573
  );
1596
1574
  }
@@ -1600,38 +1578,24 @@ class DatasetsClient {
1600
1578
  * @param name - Name of the dataset to delete
1601
1579
  */
1602
1580
  delete(name) {
1603
- return lastValueFrom(_modify(this.#client, this.#httpRequest, "DELETE", name));
1581
+ return resourceGuard("dataset", this.#client.config()), lastValueFrom(_modify(this.#client, this.#httpRequest, "DELETE", name));
1604
1582
  }
1605
1583
  /**
1606
1584
  * Fetch a list of datasets for the configured project
1607
1585
  */
1608
1586
  list() {
1609
- const resource = this.#client.config()["~experimental_resource"];
1610
- if (resource && resource.type !== "project")
1611
- throw new Error('`dataset.list()` requires a resource type of "project".');
1612
- const uri = _getDataUrl(this.#client, "", "datasets");
1613
- return lastValueFrom(
1587
+ resourceGuard("dataset", this.#client.config());
1588
+ const config = this.#client.config(), projectId2 = config.projectId;
1589
+ let uri = "/datasets";
1590
+ return config.useProjectHostname === !1 && (uri = `/projects/${projectId2}/datasets`), lastValueFrom(
1614
1591
  _request(this.#client, this.#httpRequest, { uri, tag: null })
1615
1592
  );
1616
1593
  }
1617
1594
  }
1618
1595
  function _modify(client, httpRequest, method, name, options) {
1619
- dataset(name);
1620
- const resource = client.config()["~experimental_resource"];
1621
- if (resource)
1622
- if (resource.type === "dataset") {
1623
- const segments = resource.id.split(".");
1624
- if (segments.length !== 2)
1625
- throw new Error('Dataset resource ID must be in the format "project.dataset"');
1626
- const datasetName = segments[1];
1627
- if (name !== datasetName)
1628
- throw new Error(`Dataset name "${name}" does not match resource dataset "${datasetName}"`);
1629
- } else
1630
- throw new Error('Dataset create/edit/delete operations require a resource type of "dataset"');
1631
- const uri = _getDataUrl(client, "", `datasets/${name}`);
1632
- return _request(client, httpRequest, {
1596
+ return resourceGuard("dataset", client.config()), dataset(name), _request(client, httpRequest, {
1633
1597
  method,
1634
- uri,
1598
+ uri: `/datasets/${name}`,
1635
1599
  body: options,
1636
1600
  tag: null
1637
1601
  });