@sanity/client 5.4.1 → 5.4.2-dev.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 +69 -12
- package/dist/index.browser.cjs +6 -0
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +6 -0
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +7 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +51 -0
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/src/data/dataMethods.ts +4 -0
- package/src/types.ts +53 -0
- package/umd/sanityClient.js +6 -0
- package/umd/sanityClient.min.js +3 -3
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ export const client = createClient({
|
|
|
27
27
|
projectId: 'your-project-id',
|
|
28
28
|
dataset: 'your-dataset-name',
|
|
29
29
|
useCdn: false, // set to `true` to fetch from edge cache
|
|
30
|
-
apiVersion: '
|
|
30
|
+
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
|
|
31
31
|
// token: process.env.SANITY_SECRET_TOKEN // Only if you want to update content with the client
|
|
32
32
|
})
|
|
33
33
|
|
|
@@ -65,6 +65,7 @@ export async function updateDocumentTitle(_id, title) {
|
|
|
65
65
|
- [UMD](#umd)
|
|
66
66
|
- [Specifying API version](#specifying-api-version)
|
|
67
67
|
- [Performing queries](#performing-queries)
|
|
68
|
+
- [Get started with Content Source Maps](#get-started-with-content-source-maps)
|
|
68
69
|
- [Listening to queries](#listening-to-queries)
|
|
69
70
|
- [Fetch a single document](#fetch-a-single-document)
|
|
70
71
|
- [Fetch multiple documents in one go](#fetch-multiple-documents-in-one-go)
|
|
@@ -130,7 +131,7 @@ const client = createClient({
|
|
|
130
131
|
projectId: 'your-project-id',
|
|
131
132
|
dataset: 'your-dataset-name',
|
|
132
133
|
useCdn: false, // set to `true` to fetch from edge cache
|
|
133
|
-
apiVersion: '
|
|
134
|
+
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
|
|
134
135
|
})
|
|
135
136
|
|
|
136
137
|
const data = await client.fetch(`count(*)`)
|
|
@@ -146,7 +147,7 @@ const client = createClient({
|
|
|
146
147
|
projectId: 'your-project-id',
|
|
147
148
|
dataset: 'your-dataset-name',
|
|
148
149
|
useCdn: false, // set to `true` to fetch from edge cache
|
|
149
|
-
apiVersion: '
|
|
150
|
+
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
|
|
150
151
|
})
|
|
151
152
|
|
|
152
153
|
client
|
|
@@ -164,7 +165,7 @@ const config: ClientConfig = {
|
|
|
164
165
|
projectId: 'your-project-id',
|
|
165
166
|
dataset: 'your-dataset-name',
|
|
166
167
|
useCdn: false, // set to `true` to fetch from edge cache
|
|
167
|
-
apiVersion: '
|
|
168
|
+
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
|
|
168
169
|
}
|
|
169
170
|
const client = createClient(config)
|
|
170
171
|
|
|
@@ -184,7 +185,7 @@ const client = createClient({
|
|
|
184
185
|
projectId: 'your-project-id',
|
|
185
186
|
dataset: 'your-dataset-name',
|
|
186
187
|
useCdn: false, // set to `true` to fetch from edge cache
|
|
187
|
-
apiVersion: '
|
|
188
|
+
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
|
|
188
189
|
})
|
|
189
190
|
|
|
190
191
|
const schema = z.number()
|
|
@@ -211,7 +212,7 @@ const client = createClient({
|
|
|
211
212
|
projectId: 'your-project-id',
|
|
212
213
|
dataset: 'your-dataset-name',
|
|
213
214
|
useCdn: false, // set to `true` to fetch from edge cache
|
|
214
|
-
apiVersion: '
|
|
215
|
+
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
|
|
215
216
|
})
|
|
216
217
|
|
|
217
218
|
const data = await client.fetch<number>(`count(*)`)
|
|
@@ -239,7 +240,7 @@ const client = createClient({
|
|
|
239
240
|
projectId: 'your-project-id',
|
|
240
241
|
dataset: 'your-dataset-name',
|
|
241
242
|
useCdn: false, // set to `true` to fetch from edge cache
|
|
242
|
-
apiVersion: '
|
|
243
|
+
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
|
|
243
244
|
})
|
|
244
245
|
|
|
245
246
|
const data = await client.fetch<number>(`count(*)`)
|
|
@@ -272,7 +273,7 @@ export default async function handler(req: NextRequest) {
|
|
|
272
273
|
projectId: 'your-project-id',
|
|
273
274
|
dataset: 'your-dataset-name',
|
|
274
275
|
useCdn: false, // set to `true` to fetch from edge cache
|
|
275
|
-
apiVersion: '
|
|
276
|
+
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
|
|
276
277
|
})
|
|
277
278
|
|
|
278
279
|
const count = await client.fetch<number>(`count(*)`)
|
|
@@ -303,7 +304,7 @@ Using [esm.sh] you can either load the client using a `<script type="module">` t
|
|
|
303
304
|
projectId: 'your-project-id',
|
|
304
305
|
dataset: 'your-dataset-name',
|
|
305
306
|
useCdn: false, // set to `true` to fetch from edge cache
|
|
306
|
-
apiVersion: '
|
|
307
|
+
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
|
|
307
308
|
})
|
|
308
309
|
|
|
309
310
|
const data = await client.fetch(`count(*)`)
|
|
@@ -322,7 +323,7 @@ const client = createClient({
|
|
|
322
323
|
projectId: 'your-project-id',
|
|
323
324
|
dataset: 'your-dataset-name',
|
|
324
325
|
useCdn: false, // set to `true` to fetch from edge cache
|
|
325
|
-
apiVersion: '
|
|
326
|
+
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
|
|
326
327
|
})
|
|
327
328
|
|
|
328
329
|
const data = await client.fetch(`count(*)`)
|
|
@@ -344,7 +345,7 @@ Loading the UMD script creates a `SanityClient` global that have the same export
|
|
|
344
345
|
projectId: 'your-project-id',
|
|
345
346
|
dataset: 'your-dataset-name',
|
|
346
347
|
useCdn: false, // set to `true` to fetch from edge cache
|
|
347
|
-
apiVersion: '
|
|
348
|
+
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
|
|
348
349
|
})
|
|
349
350
|
|
|
350
351
|
client.fetch(`count(*)`).then((data) => console.log(`Number of documents: ${data}`))
|
|
@@ -365,7 +366,7 @@ The `require-unpkg` library lets you consume `npm` packages from `unpkg.com` sim
|
|
|
365
366
|
projectId: 'your-project-id',
|
|
366
367
|
dataset: 'your-dataset-name',
|
|
367
368
|
useCdn: false, // set to `true` to fetch from edge cache
|
|
368
|
-
apiVersion: '
|
|
369
|
+
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
|
|
369
370
|
})
|
|
370
371
|
|
|
371
372
|
const data = await client.fetch(`count(*)`)
|
|
@@ -402,6 +403,57 @@ client.fetch(query, params).then((bikes) => {
|
|
|
402
403
|
|
|
403
404
|
Perform a query using the given parameters (if any).
|
|
404
405
|
|
|
406
|
+
### Get started with Content Source Maps
|
|
407
|
+
|
|
408
|
+
> **Note**
|
|
409
|
+
>
|
|
410
|
+
> [Content Source Maps][content-source-maps-intro] are available [as an API][content-source-maps] for select Sanity enterprise customers. [Contact our sales team for more information.][content-source-maps-cta]
|
|
411
|
+
|
|
412
|
+
[Visual editing][visual-editing] is available in [`@sanity/preview-kit/client`][preview-kit-client]. It offers both a turn-key solution and a flexible API for custom experiences.
|
|
413
|
+
|
|
414
|
+
This guide is for developers who want to build custom use cases beyond, or in addition to, [visual editing][visual-editing]. Read the [Content Source Maps introduction](https://www.sanity.io/docs/content-source-maps) before diving in, and keep the [Content Source Maps reference](https://www.sanity.io/docs/content-source-maps) handy.
|
|
415
|
+
|
|
416
|
+
Enabling Content Source Maps is a two-step process:
|
|
417
|
+
|
|
418
|
+
1. Update your client configuration with `resultSourceMap`.
|
|
419
|
+
|
|
420
|
+
```js
|
|
421
|
+
import {createClient} from '@sanity/client'
|
|
422
|
+
|
|
423
|
+
const client = createClient({
|
|
424
|
+
projectId: 'your-project-id',
|
|
425
|
+
dataset: 'your-dataset-name',
|
|
426
|
+
useCdn: true, // set to `false` to bypass the edge cache
|
|
427
|
+
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
|
|
428
|
+
resultSourceMap: true, // tells the API to start sending source maps, if available
|
|
429
|
+
})
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
2. On `client.fetch` calls add `{filterResponse: false}` to return the full response on queries.
|
|
433
|
+
|
|
434
|
+
```js
|
|
435
|
+
// Before
|
|
436
|
+
// const result = await client.fetch(query, params)
|
|
437
|
+
|
|
438
|
+
// After adding `filterResponse: false`
|
|
439
|
+
const {result, resultSourceMap} = await client.fetch(query, params, {filterResponse: false})
|
|
440
|
+
// Build something cool with the source map
|
|
441
|
+
console.log(resultSourceMap)
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
Once enabled, the `resultSourceMap` property will always exist on the response, given your `apiVersion` is recent enough. If there is no source map, it will be an empty object. There's also a TypeScript definition for it:
|
|
445
|
+
|
|
446
|
+
```ts
|
|
447
|
+
import type {ContentSourceMapping} from '@sanity/client'
|
|
448
|
+
const {result, resultSourceMap} = await client.fetch(query, params, {filterResponse: false})
|
|
449
|
+
|
|
450
|
+
function useContentSourceMap(resultSourceMap: ContentSourceMapping): unknown {
|
|
451
|
+
// Sky's the limit
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
useContentSourceMap(resultSourceMap)
|
|
455
|
+
```
|
|
456
|
+
|
|
405
457
|
### Listening to queries
|
|
406
458
|
|
|
407
459
|
```js
|
|
@@ -1223,3 +1275,8 @@ await client.request<void>({uri: '/auth/logout', method: 'POST'})
|
|
|
1223
1275
|
[groqd]: https://github.com/FormidableLabs/groqd#readme
|
|
1224
1276
|
[AbortSignal]: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
1225
1277
|
[AbortController]: https://developer.mozilla.org/en-US/docs/Web/API/AbortController
|
|
1278
|
+
[visual-editing]: https://www.sanity.io/docs/vercel-visual-editing
|
|
1279
|
+
[content-source-maps]: https://www.sanity.io/docs/content-source-maps
|
|
1280
|
+
[content-source-maps-intro]: https://www.sanity.io/blog/content-source-maps-announce
|
|
1281
|
+
[content-source-maps-cta]: https://www.sanity.io/contact/sales
|
|
1282
|
+
[preview-kit-client]: https://github.com/sanity-io/preview-kit#sanitypreview-kitclient
|
package/dist/index.browser.cjs
CHANGED
|
@@ -808,6 +808,12 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
808
808
|
...options.query
|
|
809
809
|
};
|
|
810
810
|
}
|
|
811
|
+
if (config.resultSourceMap) {
|
|
812
|
+
options.query = {
|
|
813
|
+
resultSourceMap: true,
|
|
814
|
+
...options.query
|
|
815
|
+
};
|
|
816
|
+
}
|
|
811
817
|
const reqOptions = requestOptions(config, Object.assign({}, options, {
|
|
812
818
|
url: _getUrl(client, uri, useCdn)
|
|
813
819
|
}));
|