@sanity/client 5.1.0 → 5.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/README.md CHANGED
@@ -48,7 +48,7 @@ export async function updateDocumentTitle(_id, title) {
48
48
  }
49
49
  ```
50
50
 
51
- # Table of contents<!-- omit in toc -->
51
+ # Table of contents
52
52
 
53
53
  - [QuickStart](#quickstart)
54
54
  - [Requirements](#requirements)
@@ -88,6 +88,7 @@ export async function updateDocumentTitle(_id, title) {
88
88
  - [Examples: Specify image metadata to extract](#examples-specify-image-metadata-to-extract)
89
89
  - [Deleting an asset](#deleting-an-asset)
90
90
  - [Mutation options](#mutation-options)
91
+ - [Aborting a request](#aborting-a-request)
91
92
  - [Get client configuration](#get-client-configuration)
92
93
  - [Set client configuration](#set-client-configuration)
93
94
  - [Release new version](#release-new-version)
@@ -925,15 +926,15 @@ MIT © [Sanity.io](https://www.sanity.io/)
925
926
 
926
927
  ## From `v4`
927
928
 
928
- ### No longer shipping `ES5`<!-- omit in toc -->
929
+ ### No longer shipping `ES5`
929
930
 
930
931
  The target is changed to [modern browsers] that supports `ES6` `class`, `{...rest}` syntax and more. You may need to update your bundler to a recent major version. Or you could configure your bundler to transpile `@sanity/client`, and `get-it`, which is the engine that powers `@sanity/client` and uses the same output target.
931
932
 
932
- ### Node.js `v12` no longer supported<!-- omit in toc -->
933
+ ### Node.js `v12` no longer supported
933
934
 
934
935
  Upgrade to the [LTS release, or one of the Maintenance releases](https://github.com/nodejs/release#release-schedule).
935
936
 
936
- ### The `default` export is replaced with the named export `createClient`<!-- omit in toc -->
937
+ ### The `default` export is replaced with the named export `createClient`
937
938
 
938
939
  Before:
939
940
 
@@ -954,7 +955,7 @@ import {createClient} from '@sanity/client'
954
955
  const client = createClient()
955
956
  ```
956
957
 
957
- ### `client.assets.delete` is removed<!-- omit in toc -->
958
+ ### `client.assets.delete` is removed
958
959
 
959
960
  Before:
960
961
 
@@ -970,7 +971,7 @@ After:
970
971
  client.delete('image-abc123_foobar-123x123-png')
971
972
  ```
972
973
 
973
- ### `client.assets.getImageUrl` is removed, replace with [`@sanity/image-url`](https://github.com/sanity-io/image-url)<!-- omit in toc -->
974
+ ### `client.assets.getImageUrl` is removed, replace with [`@sanity/image-url`](https://github.com/sanity-io/image-url)
974
975
 
975
976
  Before:
976
977
 
@@ -1001,7 +1002,7 @@ urlFor({_ref: 'image-abc123_foobar-123x123-png'}).url()
1001
1002
  urlFor({_ref: 'image-abc123_foobar-123x123-png'}).auto('format').url()
1002
1003
  ```
1003
1004
 
1004
- ### `SanityClient` static properties moved to named exports<!-- omit in toc -->
1005
+ ### `SanityClient` static properties moved to named exports
1005
1006
 
1006
1007
  Before:
1007
1008
 
@@ -1017,7 +1018,7 @@ After:
1017
1018
  import {Patch, Transaction, ClientError, ServerError, requester} from '@sanity/client'
1018
1019
  ```
1019
1020
 
1020
- ### `client.clientConfig` is removed, replace with `client.config()`<!-- omit in toc -->
1021
+ ### `client.clientConfig` is removed, replace with `client.config()`
1021
1022
 
1022
1023
  Before:
1023
1024
 
@@ -1037,64 +1038,7 @@ const client = createClient()
1037
1038
  console.log(client.config().projectId)
1038
1039
  ```
1039
1040
 
1040
- ### `client.getUrl()` is removed<!-- omit in toc -->
1041
-
1042
- Before:
1043
-
1044
- ```ts
1045
- import createClient from '@sanity/client'
1046
- const client = createClient({projectId: 'abc123'})
1047
-
1048
- console.log(client.getUrl('/foo/bar') === 'https://abc123.api.sanity.io/v1/foo/bar')
1049
- console.log(client.getUrl('/foo/bar', true) === 'https://abc123.apicdn.sanity.io/v1/foo/bar')
1050
- ```
1051
-
1052
- After:
1053
-
1054
- ```ts
1055
- import {createClient} from '@sanity/client'
1056
- const client = createClient({projectId: 'abc123'})
1057
-
1058
- const getUrl = (uri: string, useCdn = false) => {
1059
- const config = client.config()
1060
- const base = useCdn ? config.cdnUrl : config.url
1061
- return `${base}/${uri.replace(/^\//, '')}`
1062
- }
1063
-
1064
- console.log(getUrl('/foo/bar') === 'https://abc123.api.sanity.io/v1/foo/bar')
1065
- console.log(getUrl('/foo/bar', true) === 'https://abc123.apicdn.sanity.io/v1/foo/bar')
1066
- ```
1067
-
1068
- ### `client.getDataUrl()` is removed<!-- omit in toc -->
1069
-
1070
- Before:
1071
-
1072
- ```ts
1073
- import createClient from '@sanity/client'
1074
- const client = createClient({dataset: 'bikeshop'})
1075
-
1076
- console.log(client.getDataUrl('doc') === '/data/doc/bikeshop')
1077
- console.log(client.getDataUrl('doc', 'bike-123') === '/data/doc/bikeshop/bike-123')
1078
- ```
1079
-
1080
- After:
1081
-
1082
- ```ts
1083
- import {createClient} from '@sanity/client'
1084
- const client = createClient({dataset: 'bikeshop'})
1085
-
1086
- const getDataUrl = (operation: string, path?: string) => {
1087
- const {dataset} = client.config()
1088
- const baseUri = `/${operation}/${dataset}`
1089
- const uri = path ? `${baseUri}/${path}` : baseUri
1090
- return `/data${uri}`.replace(/\/($|\?)/, '$1')
1091
- }
1092
-
1093
- console.log(getDataUrl('doc') === '/data/doc/bikeshop')
1094
- console.log(getDataUrl('doc', 'bike-123') === '/data/doc/bikeshop/bike-123')
1095
- ```
1096
-
1097
- ### `client.isPromiseAPI()` is removed, replace with an `instanceof` check<!-- omit in toc -->
1041
+ ### `client.isPromiseAPI()` is removed, replace with an `instanceof` check
1098
1042
 
1099
1043
  Before:
1100
1044
 
@@ -1116,7 +1060,7 @@ const client = createClient()
1116
1060
  console.log(client instanceof SanityClient)
1117
1061
  ```
1118
1062
 
1119
- ### `client.observable.isObservableAPI()` is removed, replace with an `instanceof` check<!-- omit in toc -->
1063
+ ### `client.observable.isObservableAPI()` is removed, replace with an `instanceof` check
1120
1064
 
1121
1065
  Before:
1122
1066
 
@@ -1136,7 +1080,7 @@ const client = createClient()
1136
1080
  console.log(client.observable instanceof ObservableSanityClient)
1137
1081
  ```
1138
1082
 
1139
- ### `client._requestObservable` is removed, replace with `client.observable.request`<!-- omit in toc -->
1083
+ ### `client._requestObservable` is removed, replace with `client.observable.request`
1140
1084
 
1141
1085
  Before:
1142
1086
 
@@ -1156,7 +1100,7 @@ const client = createClient()
1156
1100
  client.observable.request({uri: '/ping'}).subscribe()
1157
1101
  ```
1158
1102
 
1159
- ### `client._dataRequest` is removed, replace with `client.dataRequest`<!-- omit in toc -->
1103
+ ### `client._dataRequest` is removed, replace with `client.dataRequest`
1160
1104
 
1161
1105
  Before:
1162
1106
 
@@ -1176,7 +1120,7 @@ const client = createClient()
1176
1120
  client.dataRequest(endpoint, body, options)
1177
1121
  ```
1178
1122
 
1179
- ### `client._create_` is removed, replace with one of `client.create`, `client.createIfNotExists` or `client.createOrReplace`<!-- omit in toc -->
1123
+ ### `client._create_` is removed, replace with one of `client.create`, `client.createIfNotExists` or `client.createOrReplace`
1180
1124
 
1181
1125
  Before:
1182
1126
 
@@ -1200,7 +1144,7 @@ client.createIfNotExists(doc, options)
1200
1144
  client.createOrReplace(doc, options)
1201
1145
  ```
1202
1146
 
1203
- ### `client.patch.replace` is removed, replace with `client.createOrReplace`<!-- omit in toc -->
1147
+ ### `client.patch.replace` is removed, replace with `client.createOrReplace`
1204
1148
 
1205
1149
  Before:
1206
1150
 
@@ -1225,7 +1169,7 @@ client.createOrReplace({
1225
1169
  })
1226
1170
  ```
1227
1171
 
1228
- ### `client.auth` is removed, replace with `client.request`<!-- omit in toc -->
1172
+ ### `client.auth` is removed, replace with `client.request`
1229
1173
 
1230
1174
  Before:
1231
1175
 
@@ -1554,6 +1554,24 @@ const _ObservableSanityClient = class {
1554
1554
  request(options) {
1555
1555
  return _request(this, __privateGet(this, _httpRequest), options);
1556
1556
  }
1557
+ /**
1558
+ * Get a Sanity API URL for the URI provided
1559
+ *
1560
+ * @param uri - URI/path to build URL for
1561
+ * @param canUseCdn - Whether or not to allow using the API CDN for this route
1562
+ */
1563
+ getUrl(uri, canUseCdn) {
1564
+ return _getUrl(this, uri, canUseCdn);
1565
+ }
1566
+ /**
1567
+ * Get a Sanity API URL for the data operation and path provided
1568
+ *
1569
+ * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
1570
+ * @param path - Path to append after the operation
1571
+ */
1572
+ getDataUrl(operation, path) {
1573
+ return _getDataUrl(this, operation, path);
1574
+ }
1557
1575
  };
1558
1576
  let ObservableSanityClient = _ObservableSanityClient;
1559
1577
  _clientConfig = new WeakMap();
@@ -1687,6 +1705,24 @@ const _SanityClient = class {
1687
1705
  dataRequest(endpoint, body, options) {
1688
1706
  return rxjs.lastValueFrom(_dataRequest(this, __privateGet(this, _httpRequest2), endpoint, body, options));
1689
1707
  }
1708
+ /**
1709
+ * Get a Sanity API URL for the URI provided
1710
+ *
1711
+ * @param uri - URI/path to build URL for
1712
+ * @param canUseCdn - Whether or not to allow using the API CDN for this route
1713
+ */
1714
+ getUrl(uri, canUseCdn) {
1715
+ return _getUrl(this, uri, canUseCdn);
1716
+ }
1717
+ /**
1718
+ * Get a Sanity API URL for the data operation and path provided
1719
+ *
1720
+ * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
1721
+ * @param path - Path to append after the operation
1722
+ */
1723
+ getDataUrl(operation, path) {
1724
+ return _getDataUrl(this, operation, path);
1725
+ }
1690
1726
  };
1691
1727
  let SanityClient = _SanityClient;
1692
1728
  _clientConfig2 = new WeakMap();