@sanity/client 6.1.3-perspective.0 → 6.1.3
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 +0 -159
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/types.ts +4 -2
package/README.md
CHANGED
|
@@ -65,9 +65,6 @@ 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
|
-
- [Using perspectives](#using-perspectives)
|
|
69
|
-
- [`published`](#published)
|
|
70
|
-
- [`previewDrafts`](#previewdrafts)
|
|
71
68
|
- [Fetching Content Source Maps](#fetching-content-source-maps)
|
|
72
69
|
- [Listening to queries](#listening-to-queries)
|
|
73
70
|
- [Fetch a single document](#fetch-a-single-document)
|
|
@@ -408,162 +405,6 @@ client.fetch(query, params).then((bikes) => {
|
|
|
408
405
|
|
|
409
406
|
Perform a query using the given parameters (if any).
|
|
410
407
|
|
|
411
|
-
### Using perspectives
|
|
412
|
-
|
|
413
|
-
The `perspective` option can be used to specify special filtering behavior for queries. The default value is `raw`, which means no special filtering is applied, while [`published`](#published) and [`previewDrafts`](#previewdrafts) can be used to optimize for specific use cases.
|
|
414
|
-
|
|
415
|
-
#### `published`
|
|
416
|
-
|
|
417
|
-
Useful for when you want to be sure that draft documents are not returned in production. Pairs well with private datasets.
|
|
418
|
-
|
|
419
|
-
With a dataset that looks like this:
|
|
420
|
-
|
|
421
|
-
```json
|
|
422
|
-
[
|
|
423
|
-
{
|
|
424
|
-
"_type": "author",
|
|
425
|
-
"_id": "ecfef291-60f0-4609-bbfc-263d11a48c43",
|
|
426
|
-
"name": "George Martin"
|
|
427
|
-
},
|
|
428
|
-
{
|
|
429
|
-
"_type": "author",
|
|
430
|
-
"_id": "drafts.ecfef291-60f0-4609-bbfc-263d11a48c43",
|
|
431
|
-
"name": "George R.R. Martin"
|
|
432
|
-
},
|
|
433
|
-
{
|
|
434
|
-
"_type": "author",
|
|
435
|
-
"_id": "drafts.f4898efe-92c4-4dc0-9c8c-f7480aef17e2",
|
|
436
|
-
"name": "Stephen King"
|
|
437
|
-
}
|
|
438
|
-
]
|
|
439
|
-
```
|
|
440
|
-
|
|
441
|
-
And a query like this:
|
|
442
|
-
|
|
443
|
-
```ts
|
|
444
|
-
import {createClient} from '@sanity/client'
|
|
445
|
-
|
|
446
|
-
const client = createClient({
|
|
447
|
-
...config,
|
|
448
|
-
useCdn: true, // set to `false` to bypass the edge cache
|
|
449
|
-
perspective: 'published',
|
|
450
|
-
})
|
|
451
|
-
|
|
452
|
-
const authors = await client.fetch('*[_type == "author"]')
|
|
453
|
-
```
|
|
454
|
-
|
|
455
|
-
Then `authors` will only contain documents that don't have a `drafts.` prefix in their `_id`, in this case just "George Martin":
|
|
456
|
-
|
|
457
|
-
```json
|
|
458
|
-
[
|
|
459
|
-
{
|
|
460
|
-
"_type": "author",
|
|
461
|
-
"_id": "ecfef291-60f0-4609-bbfc-263d11a48c43",
|
|
462
|
-
"name": "George Martin"
|
|
463
|
-
}
|
|
464
|
-
]
|
|
465
|
-
```
|
|
466
|
-
|
|
467
|
-
#### `previewDrafts`
|
|
468
|
-
|
|
469
|
-
Designed to help answer the question "What is our app going to look like after all the draft documents are published?".
|
|
470
|
-
|
|
471
|
-
Given a dataset like this:
|
|
472
|
-
|
|
473
|
-
```json
|
|
474
|
-
[
|
|
475
|
-
{
|
|
476
|
-
"_type": "author",
|
|
477
|
-
"_id": "ecfef291-60f0-4609-bbfc-263d11a48c43",
|
|
478
|
-
"name": "George Martin"
|
|
479
|
-
},
|
|
480
|
-
{
|
|
481
|
-
"_type": "author",
|
|
482
|
-
"_id": "drafts.ecfef291-60f0-4609-bbfc-263d11a48c43",
|
|
483
|
-
"name": "George R.R. Martin"
|
|
484
|
-
},
|
|
485
|
-
{
|
|
486
|
-
"_type": "author",
|
|
487
|
-
"_id": "drafts.f4898efe-92c4-4dc0-9c8c-f7480aef17e2",
|
|
488
|
-
"name": "Stephen King"
|
|
489
|
-
},
|
|
490
|
-
{
|
|
491
|
-
"_type": "author",
|
|
492
|
-
"_id": "6b3792d2-a9e8-4c79-9982-c7e89f2d1e75",
|
|
493
|
-
"name": "Terry Pratchett"
|
|
494
|
-
}
|
|
495
|
-
]
|
|
496
|
-
```
|
|
497
|
-
|
|
498
|
-
And a query like this:
|
|
499
|
-
|
|
500
|
-
```ts
|
|
501
|
-
import {createClient} from '@sanity/client'
|
|
502
|
-
|
|
503
|
-
const client = createClient({
|
|
504
|
-
...config,
|
|
505
|
-
useCdn: false, // the `previewDrafts` perspective requires this to be `false`
|
|
506
|
-
perspective: 'previewDrafts',
|
|
507
|
-
})
|
|
508
|
-
|
|
509
|
-
const authors = await client.fetch('*[_type == "author"]')
|
|
510
|
-
```
|
|
511
|
-
|
|
512
|
-
Then `authors` will look like this. Note that the result dedupes documents with a preference for the draft version:
|
|
513
|
-
|
|
514
|
-
```json
|
|
515
|
-
[
|
|
516
|
-
{
|
|
517
|
-
"_type": "author",
|
|
518
|
-
"_id": "ecfef291-60f0-4609-bbfc-263d11a48c43",
|
|
519
|
-
"_originalId": "drafts.ecfef291-60f0-4609-bbfc-263d11a48c43",
|
|
520
|
-
"name": "George R.R. Martin"
|
|
521
|
-
},
|
|
522
|
-
{
|
|
523
|
-
"_type": "author",
|
|
524
|
-
"_id": "f4898efe-92c4-4dc0-9c8c-f7480aef17e2",
|
|
525
|
-
"_originalId": "drafts.f4898efe-92c4-4dc0-9c8c-f7480aef17e2",
|
|
526
|
-
"name": "Stephen King"
|
|
527
|
-
},
|
|
528
|
-
{
|
|
529
|
-
"_type": "author",
|
|
530
|
-
"_id": "6b3792d2-a9e8-4c79-9982-c7e89f2d1e75",
|
|
531
|
-
"_originalId": "6b3792d2-a9e8-4c79-9982-c7e89f2d1e75",
|
|
532
|
-
"name": "Terry Pratchett"
|
|
533
|
-
}
|
|
534
|
-
]
|
|
535
|
-
```
|
|
536
|
-
|
|
537
|
-
Since the query simulates what the result will be after publishing the drafts, the `_id` doesn't contain the `drafts.` prefix. If you want to check if a document is a draft or not you can use the `_originalId` field, which is only available when using the `previewDrafts` perspective.
|
|
538
|
-
|
|
539
|
-
```ts
|
|
540
|
-
const authors = await client.fetch(`*[_type == "author"]{..., "status": select(
|
|
541
|
-
_originalId in path("drafts.**") => "draft",
|
|
542
|
-
"published"
|
|
543
|
-
)}`)
|
|
544
|
-
```
|
|
545
|
-
|
|
546
|
-
Which changes the result to be:
|
|
547
|
-
|
|
548
|
-
```json
|
|
549
|
-
[
|
|
550
|
-
{
|
|
551
|
-
"_type": "author",
|
|
552
|
-
"_id": "ecfef291-60f0-4609-bbfc-263d11a48c43",
|
|
553
|
-
"_originalId": "drafts.ecfef291-60f0-4609-bbfc-263d11a48c43",
|
|
554
|
-
"name": "George R.R. Martin",
|
|
555
|
-
"status": "draft"
|
|
556
|
-
},
|
|
557
|
-
{
|
|
558
|
-
"_type": "author",
|
|
559
|
-
"_id": "f4898efe-92c4-4dc0-9c8c-f7480aef17e2",
|
|
560
|
-
"_originalId": "f4898efe-92c4-4dc0-9c8c-f7480aef17e2",
|
|
561
|
-
"name": "Stephen King",
|
|
562
|
-
"status": "published"
|
|
563
|
-
}
|
|
564
|
-
]
|
|
565
|
-
```
|
|
566
|
-
|
|
567
408
|
### Fetching Content Source Maps
|
|
568
409
|
|
|
569
410
|
Content Source Maps annotate fragments in your query results with metadata about its origin: the field, document, and dataset it originated from.
|
package/dist/index.cjs
CHANGED
|
@@ -8,7 +8,7 @@ var getIt = require('get-it');
|
|
|
8
8
|
var rxjs = require('rxjs');
|
|
9
9
|
var operators = require('rxjs/operators');
|
|
10
10
|
var name = "@sanity/client";
|
|
11
|
-
var version = "6.1.3
|
|
11
|
+
var version = "6.1.3";
|
|
12
12
|
const middleware = [middleware$1.debug({
|
|
13
13
|
verbose: true,
|
|
14
14
|
namespace: "sanity:client"
|
package/dist/index.d.ts
CHANGED
|
@@ -283,8 +283,7 @@ export declare interface ClientConfig {
|
|
|
283
283
|
/** @defaultValue true */
|
|
284
284
|
useCdn?: boolean
|
|
285
285
|
token?: string
|
|
286
|
-
|
|
287
|
-
perspective?: 'previewDrafts' | 'published' | 'raw'
|
|
286
|
+
perspective?: ClientPerspective
|
|
288
287
|
apiHost?: string
|
|
289
288
|
apiVersion?: string
|
|
290
289
|
proxy?: string
|
|
@@ -327,6 +326,9 @@ export declare class ClientError extends Error {
|
|
|
327
326
|
constructor(res: Any)
|
|
328
327
|
}
|
|
329
328
|
|
|
329
|
+
/** @public */
|
|
330
|
+
export declare type ClientPerspective = 'previewDrafts' | 'published' | 'raw'
|
|
331
|
+
|
|
330
332
|
/** @public */
|
|
331
333
|
export declare interface ContentSourceMap {
|
|
332
334
|
mappings: ContentSourceMapMappings
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ export { adapter as unstable__adapter, environment as unstable__environment } fr
|
|
|
4
4
|
import { Observable, lastValueFrom } from 'rxjs';
|
|
5
5
|
import { map, filter } from 'rxjs/operators';
|
|
6
6
|
var name = "@sanity/client";
|
|
7
|
-
var version = "6.1.3
|
|
7
|
+
var version = "6.1.3";
|
|
8
8
|
const middleware = [debug({
|
|
9
9
|
verbose: true,
|
|
10
10
|
namespace: "sanity:client"
|
package/package.json
CHANGED
package/src/types.ts
CHANGED
|
@@ -28,6 +28,9 @@ export interface RequestOptions {
|
|
|
28
28
|
signal?: AbortSignal
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/** @public */
|
|
32
|
+
export type ClientPerspective = 'previewDrafts' | 'published' | 'raw'
|
|
33
|
+
|
|
31
34
|
/** @public */
|
|
32
35
|
export interface ClientConfig {
|
|
33
36
|
projectId?: string
|
|
@@ -35,8 +38,7 @@ export interface ClientConfig {
|
|
|
35
38
|
/** @defaultValue true */
|
|
36
39
|
useCdn?: boolean
|
|
37
40
|
token?: string
|
|
38
|
-
|
|
39
|
-
perspective?: 'previewDrafts' | 'published' | 'raw'
|
|
41
|
+
perspective?: ClientPerspective
|
|
40
42
|
apiHost?: string
|
|
41
43
|
apiVersion?: string
|
|
42
44
|
proxy?: string
|