@sanity/client 7.0.1-canary.2 → 7.1.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.browser.cjs +102 -4
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +1352 -1654
- package/dist/index.browser.d.ts +1352 -1654
- package/dist/index.browser.js +102 -4
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +103 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1352 -1654
- package/dist/index.d.ts +1352 -1654
- package/dist/index.js +103 -5
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +1375 -1677
- package/dist/stega.browser.d.ts +1375 -1677
- package/dist/stega.d.cts +1375 -1677
- package/dist/stega.d.ts +1375 -1677
- package/package.json +2 -1
- package/src/SanityClient.ts +34 -1102
- package/src/agent/actions/AgentActionsClient.ts +111 -0
- package/src/agent/actions/commonTypes.ts +336 -0
- package/src/agent/actions/generate.ts +274 -0
- package/src/agent/actions/transform.ts +215 -0
- package/src/agent/actions/translate.ts +165 -0
- package/src/assets/AssetsClient.ts +2 -86
- package/src/data/dataMethods.ts +1 -1
- package/src/data/transaction.ts +1 -1
- package/src/datasets/DatasetsClient.ts +2 -64
- package/src/projects/ProjectsClient.ts +4 -46
- package/src/types.ts +30 -1
- package/src/users/UsersClient.ts +2 -24
- package/umd/sanityClient.js +102 -4
- package/umd/sanityClient.min.js +2 -2
package/src/SanityClient.ts
CHANGED
|
@@ -1,29 +1,15 @@
|
|
|
1
1
|
import {lastValueFrom, Observable} from 'rxjs'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
type AssetsClientType,
|
|
6
|
-
ObservableAssetsClient,
|
|
7
|
-
type ObservableAssetsClientType,
|
|
8
|
-
} from './assets/AssetsClient'
|
|
3
|
+
import {AgentActionsClient, ObservableAgentsActionClient} from './agent/actions/AgentActionsClient'
|
|
4
|
+
import {AssetsClient, ObservableAssetsClient} from './assets/AssetsClient'
|
|
9
5
|
import {defaultConfig, initConfig} from './config'
|
|
10
6
|
import * as dataMethods from './data/dataMethods'
|
|
11
7
|
import {_listen} from './data/listen'
|
|
12
8
|
import {LiveClient} from './data/live'
|
|
13
9
|
import {ObservablePatch, Patch} from './data/patch'
|
|
14
10
|
import {ObservableTransaction, Transaction} from './data/transaction'
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
type DatasetsClientType,
|
|
18
|
-
ObservableDatasetsClient,
|
|
19
|
-
type ObservableDatasetsClientType,
|
|
20
|
-
} from './datasets/DatasetsClient'
|
|
21
|
-
import {
|
|
22
|
-
ObservableProjectsClient,
|
|
23
|
-
type ObservableProjectsClientType,
|
|
24
|
-
ProjectsClient,
|
|
25
|
-
type ProjectsClientType,
|
|
26
|
-
} from './projects/ProjectsClient'
|
|
11
|
+
import {DatasetsClient, ObservableDatasetsClient} from './datasets/DatasetsClient'
|
|
12
|
+
import {ObservableProjectsClient, ProjectsClient} from './projects/ProjectsClient'
|
|
27
13
|
import type {
|
|
28
14
|
Action,
|
|
29
15
|
AllDocumentIdsMutationOptions,
|
|
@@ -58,12 +44,7 @@ import type {
|
|
|
58
44
|
UnfilteredResponseQueryOptions,
|
|
59
45
|
UnfilteredResponseWithoutQuery,
|
|
60
46
|
} from './types'
|
|
61
|
-
import {
|
|
62
|
-
ObservableUsersClient,
|
|
63
|
-
type ObservableUsersClientType,
|
|
64
|
-
UsersClient,
|
|
65
|
-
type UsersClientType,
|
|
66
|
-
} from './users/UsersClient'
|
|
47
|
+
import {ObservableUsersClient, UsersClient} from './users/UsersClient'
|
|
67
48
|
|
|
68
49
|
export type {
|
|
69
50
|
_listen,
|
|
@@ -79,16 +60,25 @@ export type {
|
|
|
79
60
|
}
|
|
80
61
|
|
|
81
62
|
/** @public */
|
|
82
|
-
export class ObservableSanityClient
|
|
63
|
+
export class ObservableSanityClient {
|
|
83
64
|
assets: ObservableAssetsClient
|
|
84
65
|
datasets: ObservableDatasetsClient
|
|
85
66
|
live: LiveClient
|
|
86
67
|
projects: ObservableProjectsClient
|
|
87
68
|
users: ObservableUsersClient
|
|
69
|
+
agent: {
|
|
70
|
+
action: ObservableAgentsActionClient
|
|
71
|
+
}
|
|
88
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Private properties
|
|
75
|
+
*/
|
|
89
76
|
#clientConfig: InitializedClientConfig
|
|
90
77
|
#httpRequest: HttpRequest
|
|
91
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Instance properties
|
|
81
|
+
*/
|
|
92
82
|
listen = _listen
|
|
93
83
|
|
|
94
84
|
constructor(httpRequest: HttpRequest, config: ClientConfig = defaultConfig) {
|
|
@@ -101,6 +91,9 @@ export class ObservableSanityClient implements ObservableSanityClientType {
|
|
|
101
91
|
this.live = new LiveClient(this)
|
|
102
92
|
this.projects = new ObservableProjectsClient(this, this.#httpRequest)
|
|
103
93
|
this.users = new ObservableUsersClient(this, this.#httpRequest)
|
|
94
|
+
this.agent = {
|
|
95
|
+
action: new ObservableAgentsActionClient(this, this.#httpRequest),
|
|
96
|
+
}
|
|
104
97
|
}
|
|
105
98
|
|
|
106
99
|
/**
|
|
@@ -190,7 +183,7 @@ export class ObservableSanityClient implements ObservableSanityClientType {
|
|
|
190
183
|
Q extends QueryWithoutParams | QueryParams = QueryParams,
|
|
191
184
|
const G extends string = string,
|
|
192
185
|
>(
|
|
193
|
-
query:
|
|
186
|
+
query: string,
|
|
194
187
|
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
195
188
|
options: UnfilteredResponseQueryOptions,
|
|
196
189
|
): Observable<RawQueryResponse<ClientReturn<G, R>>>
|
|
@@ -741,21 +734,30 @@ export class ObservableSanityClient implements ObservableSanityClientType {
|
|
|
741
734
|
}
|
|
742
735
|
|
|
743
736
|
/** @public */
|
|
744
|
-
export class SanityClient
|
|
737
|
+
export class SanityClient {
|
|
745
738
|
assets: AssetsClient
|
|
746
739
|
datasets: DatasetsClient
|
|
747
740
|
live: LiveClient
|
|
748
741
|
projects: ProjectsClient
|
|
749
742
|
users: UsersClient
|
|
743
|
+
agent: {
|
|
744
|
+
action: AgentActionsClient
|
|
745
|
+
}
|
|
750
746
|
|
|
751
747
|
/**
|
|
752
748
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
753
749
|
*/
|
|
754
750
|
observable: ObservableSanityClient
|
|
755
751
|
|
|
752
|
+
/**
|
|
753
|
+
* Private properties
|
|
754
|
+
*/
|
|
756
755
|
#clientConfig: InitializedClientConfig
|
|
757
756
|
#httpRequest: HttpRequest
|
|
758
757
|
|
|
758
|
+
/**
|
|
759
|
+
* Instance properties
|
|
760
|
+
*/
|
|
759
761
|
listen = _listen
|
|
760
762
|
|
|
761
763
|
constructor(httpRequest: HttpRequest, config: ClientConfig = defaultConfig) {
|
|
@@ -768,6 +770,9 @@ export class SanityClient implements SanityClientType {
|
|
|
768
770
|
this.live = new LiveClient(this)
|
|
769
771
|
this.projects = new ProjectsClient(this, this.#httpRequest)
|
|
770
772
|
this.users = new UsersClient(this, this.#httpRequest)
|
|
773
|
+
this.agent = {
|
|
774
|
+
action: new AgentActionsClient(this, this.#httpRequest),
|
|
775
|
+
}
|
|
771
776
|
|
|
772
777
|
this.observable = new ObservableSanityClient(httpRequest, config)
|
|
773
778
|
}
|
|
@@ -1363,8 +1368,8 @@ export class SanityClient implements SanityClientType {
|
|
|
1363
1368
|
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
1364
1369
|
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
1365
1370
|
*/
|
|
1366
|
-
patch(
|
|
1367
|
-
return new Patch(
|
|
1371
|
+
patch(documentId: PatchSelection, operations?: PatchOperations): Patch {
|
|
1372
|
+
return new Patch(documentId, operations, this)
|
|
1368
1373
|
}
|
|
1369
1374
|
|
|
1370
1375
|
/**
|
|
@@ -1437,1076 +1442,3 @@ export class SanityClient implements SanityClientType {
|
|
|
1437
1442
|
return dataMethods._getDataUrl(this, operation, path)
|
|
1438
1443
|
}
|
|
1439
1444
|
}
|
|
1440
|
-
|
|
1441
|
-
/**
|
|
1442
|
-
* Shared base type for the `SanityClient` and `ObservableSanityClient` classes.
|
|
1443
|
-
* TODO: refactor the Promise and Observable differences to use generics so we no longer suffer from all this duplication in TS docs
|
|
1444
|
-
*/
|
|
1445
|
-
interface SanityClientBase {
|
|
1446
|
-
live: LiveClient
|
|
1447
|
-
listen: typeof _listen
|
|
1448
|
-
|
|
1449
|
-
/**
|
|
1450
|
-
* Get a Sanity API URL for the URI provided
|
|
1451
|
-
*
|
|
1452
|
-
* @param uri - URI/path to build URL for
|
|
1453
|
-
* @param canUseCdn - Whether or not to allow using the API CDN for this route
|
|
1454
|
-
*/
|
|
1455
|
-
getUrl(uri: string, canUseCdn?: boolean): string
|
|
1456
|
-
|
|
1457
|
-
/**
|
|
1458
|
-
* Get a Sanity API URL for the data operation and path provided
|
|
1459
|
-
*
|
|
1460
|
-
* @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
|
|
1461
|
-
* @param path - Path to append after the operation
|
|
1462
|
-
*/
|
|
1463
|
-
getDataUrl(operation: string, path?: string): string
|
|
1464
|
-
}
|
|
1465
|
-
|
|
1466
|
-
/**
|
|
1467
|
-
* The interface implemented by the `ObservableSanityClient` class.
|
|
1468
|
-
* When writing code that wants to take an instance of `ObservableSanityClient` as input it's better to use this type,
|
|
1469
|
-
* as the `ObservableSanityClient` class has private properties and thus TypeScrict will consider the type incompatible
|
|
1470
|
-
* in cases where you might have multiple `@sanity/client` instances in your node_modules.
|
|
1471
|
-
* @public
|
|
1472
|
-
*/
|
|
1473
|
-
export interface ObservableSanityClientType extends SanityClientBase {
|
|
1474
|
-
assets: ObservableAssetsClientType
|
|
1475
|
-
datasets: ObservableDatasetsClientType
|
|
1476
|
-
projects: ObservableProjectsClientType
|
|
1477
|
-
users: ObservableUsersClientType
|
|
1478
|
-
|
|
1479
|
-
/**
|
|
1480
|
-
* Clone the client - returns a new instance
|
|
1481
|
-
*/
|
|
1482
|
-
clone(): ObservableSanityClientType
|
|
1483
|
-
|
|
1484
|
-
/**
|
|
1485
|
-
* Returns the current client configuration
|
|
1486
|
-
*/
|
|
1487
|
-
config(): InitializedClientConfig
|
|
1488
|
-
/**
|
|
1489
|
-
* Reconfigure the client. Note that this _mutates_ the current client.
|
|
1490
|
-
*/
|
|
1491
|
-
config(newConfig?: Partial<ClientConfig>): ObservableSanityClientType
|
|
1492
|
-
|
|
1493
|
-
/**
|
|
1494
|
-
* Clone the client with a new (partial) configuration.
|
|
1495
|
-
*
|
|
1496
|
-
* @param newConfig - New client configuration properties, shallowly merged with existing configuration
|
|
1497
|
-
*/
|
|
1498
|
-
withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityClientType
|
|
1499
|
-
|
|
1500
|
-
/**
|
|
1501
|
-
* Perform a GROQ-query against the configured dataset.
|
|
1502
|
-
*
|
|
1503
|
-
* @param query - GROQ-query to perform
|
|
1504
|
-
*/
|
|
1505
|
-
fetch<
|
|
1506
|
-
R = Any,
|
|
1507
|
-
Q extends QueryWithoutParams = QueryWithoutParams,
|
|
1508
|
-
const G extends string = string,
|
|
1509
|
-
>(
|
|
1510
|
-
query: G,
|
|
1511
|
-
params?: Q | QueryWithoutParams,
|
|
1512
|
-
): Observable<ClientReturn<G, R>>
|
|
1513
|
-
/**
|
|
1514
|
-
* Perform a GROQ-query against the configured dataset.
|
|
1515
|
-
*
|
|
1516
|
-
* @param query - GROQ-query to perform
|
|
1517
|
-
* @param params - Optional query parameters
|
|
1518
|
-
* @param options - Optional request options
|
|
1519
|
-
*/
|
|
1520
|
-
fetch<
|
|
1521
|
-
R = Any,
|
|
1522
|
-
Q extends QueryWithoutParams | QueryParams = QueryParams,
|
|
1523
|
-
const G extends string = string,
|
|
1524
|
-
>(
|
|
1525
|
-
query: G,
|
|
1526
|
-
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
1527
|
-
options?: FilteredResponseQueryOptions,
|
|
1528
|
-
): Observable<ClientReturn<G, R>>
|
|
1529
|
-
/**
|
|
1530
|
-
* Perform a GROQ-query against the configured dataset.
|
|
1531
|
-
*
|
|
1532
|
-
* @param query - GROQ-query to perform
|
|
1533
|
-
* @param params - Optional query parameters
|
|
1534
|
-
* @param options - Request options
|
|
1535
|
-
*/
|
|
1536
|
-
fetch<
|
|
1537
|
-
R = Any,
|
|
1538
|
-
Q extends QueryWithoutParams | QueryParams = QueryParams,
|
|
1539
|
-
const G extends string = string,
|
|
1540
|
-
>(
|
|
1541
|
-
query: G,
|
|
1542
|
-
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
1543
|
-
options: UnfilteredResponseQueryOptions,
|
|
1544
|
-
): Observable<RawQueryResponse<ClientReturn<G, R>>>
|
|
1545
|
-
/**
|
|
1546
|
-
* Perform a GROQ-query against the configured dataset.
|
|
1547
|
-
*
|
|
1548
|
-
* @param query - GROQ-query to perform
|
|
1549
|
-
* @param params - Optional query parameters
|
|
1550
|
-
* @param options - Request options
|
|
1551
|
-
*/
|
|
1552
|
-
fetch<
|
|
1553
|
-
R = Any,
|
|
1554
|
-
Q extends QueryWithoutParams | QueryParams = QueryParams,
|
|
1555
|
-
const G extends string = string,
|
|
1556
|
-
>(
|
|
1557
|
-
query: G,
|
|
1558
|
-
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
1559
|
-
options: UnfilteredResponseWithoutQuery,
|
|
1560
|
-
): Observable<RawQuerylessQueryResponse<ClientReturn<G, R>>>
|
|
1561
|
-
|
|
1562
|
-
/**
|
|
1563
|
-
* Fetch a single document with the given ID.
|
|
1564
|
-
*
|
|
1565
|
-
* @param id - Document ID to fetch
|
|
1566
|
-
* @param options - Request options
|
|
1567
|
-
*/
|
|
1568
|
-
getDocument<R extends Record<string, Any> = Record<string, Any>>(
|
|
1569
|
-
id: string,
|
|
1570
|
-
options?: {tag?: string},
|
|
1571
|
-
): Observable<SanityDocument<R> | undefined>
|
|
1572
|
-
|
|
1573
|
-
/**
|
|
1574
|
-
* Fetch multiple documents in one request.
|
|
1575
|
-
* Should be used sparingly - performing a query is usually a better option.
|
|
1576
|
-
* The order/position of documents is preserved based on the original array of IDs.
|
|
1577
|
-
* If any of the documents are missing, they will be replaced by a `null` entry in the returned array
|
|
1578
|
-
*
|
|
1579
|
-
* @param ids - Document IDs to fetch
|
|
1580
|
-
* @param options - Request options
|
|
1581
|
-
*/
|
|
1582
|
-
getDocuments<R extends Record<string, Any> = Record<string, Any>>(
|
|
1583
|
-
ids: string[],
|
|
1584
|
-
options?: {tag?: string},
|
|
1585
|
-
): Observable<(SanityDocument<R> | null)[]>
|
|
1586
|
-
|
|
1587
|
-
/**
|
|
1588
|
-
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
1589
|
-
* Returns an observable that resolves to the created document.
|
|
1590
|
-
*
|
|
1591
|
-
* @param document - Document to create
|
|
1592
|
-
* @param options - Mutation options
|
|
1593
|
-
*/
|
|
1594
|
-
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
1595
|
-
document: SanityDocumentStub<R>,
|
|
1596
|
-
options: FirstDocumentMutationOptions,
|
|
1597
|
-
): Observable<SanityDocument<R>>
|
|
1598
|
-
/**
|
|
1599
|
-
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
1600
|
-
* Returns an observable that resolves to an array containing the created document.
|
|
1601
|
-
*
|
|
1602
|
-
* @param document - Document to create
|
|
1603
|
-
* @param options - Mutation options
|
|
1604
|
-
*/
|
|
1605
|
-
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
1606
|
-
document: SanityDocumentStub<R>,
|
|
1607
|
-
options: AllDocumentsMutationOptions,
|
|
1608
|
-
): Observable<SanityDocument<R>[]>
|
|
1609
|
-
/**
|
|
1610
|
-
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
1611
|
-
* Returns an observable that resolves to a mutation result object containing the ID of the created document.
|
|
1612
|
-
*
|
|
1613
|
-
* @param document - Document to create
|
|
1614
|
-
* @param options - Mutation options
|
|
1615
|
-
*/
|
|
1616
|
-
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
1617
|
-
document: SanityDocumentStub<R>,
|
|
1618
|
-
options: FirstDocumentIdMutationOptions,
|
|
1619
|
-
): Observable<SingleMutationResult>
|
|
1620
|
-
/**
|
|
1621
|
-
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
1622
|
-
* Returns an observable that resolves to a mutation result object containing the ID of the created document.
|
|
1623
|
-
*
|
|
1624
|
-
* @param document - Document to create
|
|
1625
|
-
* @param options - Mutation options
|
|
1626
|
-
*/
|
|
1627
|
-
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
1628
|
-
document: SanityDocumentStub<R>,
|
|
1629
|
-
options: AllDocumentIdsMutationOptions,
|
|
1630
|
-
): Observable<MultipleMutationResult>
|
|
1631
|
-
/**
|
|
1632
|
-
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
1633
|
-
* Returns an observable that resolves to the created document.
|
|
1634
|
-
*
|
|
1635
|
-
* @param document - Document to create
|
|
1636
|
-
* @param options - Mutation options
|
|
1637
|
-
*/
|
|
1638
|
-
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
1639
|
-
document: SanityDocumentStub<R>,
|
|
1640
|
-
options?: BaseMutationOptions,
|
|
1641
|
-
): Observable<SanityDocument<R>>
|
|
1642
|
-
|
|
1643
|
-
/**
|
|
1644
|
-
* Create a document if no document with the same ID already exists.
|
|
1645
|
-
* Returns an observable that resolves to the created document.
|
|
1646
|
-
*
|
|
1647
|
-
* @param document - Document to create
|
|
1648
|
-
* @param options - Mutation options
|
|
1649
|
-
*/
|
|
1650
|
-
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
1651
|
-
document: IdentifiedSanityDocumentStub<R>,
|
|
1652
|
-
options: FirstDocumentMutationOptions,
|
|
1653
|
-
): Observable<SanityDocument<R>>
|
|
1654
|
-
/**
|
|
1655
|
-
* Create a document if no document with the same ID already exists.
|
|
1656
|
-
* Returns an observable that resolves to an array containing the created document.
|
|
1657
|
-
*
|
|
1658
|
-
* @param document - Document to create
|
|
1659
|
-
* @param options - Mutation options
|
|
1660
|
-
*/
|
|
1661
|
-
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
1662
|
-
document: IdentifiedSanityDocumentStub<R>,
|
|
1663
|
-
options: AllDocumentsMutationOptions,
|
|
1664
|
-
): Observable<SanityDocument<R>[]>
|
|
1665
|
-
/**
|
|
1666
|
-
* Create a document if no document with the same ID already exists.
|
|
1667
|
-
* Returns an observable that resolves to a mutation result object containing the ID of the created document.
|
|
1668
|
-
*
|
|
1669
|
-
* @param document - Document to create
|
|
1670
|
-
* @param options - Mutation options
|
|
1671
|
-
*/
|
|
1672
|
-
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
1673
|
-
document: IdentifiedSanityDocumentStub<R>,
|
|
1674
|
-
options: FirstDocumentIdMutationOptions,
|
|
1675
|
-
): Observable<SingleMutationResult>
|
|
1676
|
-
/**
|
|
1677
|
-
* Create a document if no document with the same ID already exists.
|
|
1678
|
-
* Returns an observable that resolves to a mutation result object containing the ID of the created document.
|
|
1679
|
-
*
|
|
1680
|
-
* @param document - Document to create
|
|
1681
|
-
* @param options - Mutation options
|
|
1682
|
-
*/
|
|
1683
|
-
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
1684
|
-
document: IdentifiedSanityDocumentStub<R>,
|
|
1685
|
-
options: AllDocumentIdsMutationOptions,
|
|
1686
|
-
): Observable<MultipleMutationResult>
|
|
1687
|
-
/**
|
|
1688
|
-
* Create a document if no document with the same ID already exists.
|
|
1689
|
-
* Returns an observable that resolves to the created document.
|
|
1690
|
-
*
|
|
1691
|
-
* @param document - Document to create
|
|
1692
|
-
* @param options - Mutation options
|
|
1693
|
-
*/
|
|
1694
|
-
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
1695
|
-
document: IdentifiedSanityDocumentStub<R>,
|
|
1696
|
-
options?: BaseMutationOptions,
|
|
1697
|
-
): Observable<SanityDocument<R>>
|
|
1698
|
-
|
|
1699
|
-
/**
|
|
1700
|
-
* Create a document if it does not exist, or replace a document with the same document ID
|
|
1701
|
-
* Returns an observable that resolves to the created document.
|
|
1702
|
-
*
|
|
1703
|
-
* @param document - Document to either create or replace
|
|
1704
|
-
* @param options - Mutation options
|
|
1705
|
-
*/
|
|
1706
|
-
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
1707
|
-
document: IdentifiedSanityDocumentStub<R>,
|
|
1708
|
-
options: FirstDocumentMutationOptions,
|
|
1709
|
-
): Observable<SanityDocument<R>>
|
|
1710
|
-
/**
|
|
1711
|
-
* Create a document if it does not exist, or replace a document with the same document ID
|
|
1712
|
-
* Returns an observable that resolves to an array containing the created document.
|
|
1713
|
-
*
|
|
1714
|
-
* @param document - Document to either create or replace
|
|
1715
|
-
* @param options - Mutation options
|
|
1716
|
-
*/
|
|
1717
|
-
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
1718
|
-
document: IdentifiedSanityDocumentStub<R>,
|
|
1719
|
-
options: AllDocumentsMutationOptions,
|
|
1720
|
-
): Observable<SanityDocument<R>[]>
|
|
1721
|
-
/**
|
|
1722
|
-
* Create a document if it does not exist, or replace a document with the same document ID
|
|
1723
|
-
* Returns an observable that resolves to a mutation result object containing the ID of the created document.
|
|
1724
|
-
*
|
|
1725
|
-
* @param document - Document to either create or replace
|
|
1726
|
-
* @param options - Mutation options
|
|
1727
|
-
*/
|
|
1728
|
-
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
1729
|
-
document: IdentifiedSanityDocumentStub<R>,
|
|
1730
|
-
options: FirstDocumentIdMutationOptions,
|
|
1731
|
-
): Observable<SingleMutationResult>
|
|
1732
|
-
/**
|
|
1733
|
-
* Create a document if it does not exist, or replace a document with the same document ID
|
|
1734
|
-
* Returns an observable that resolves to a mutation result object containing the created document ID.
|
|
1735
|
-
*
|
|
1736
|
-
* @param document - Document to either create or replace
|
|
1737
|
-
* @param options - Mutation options
|
|
1738
|
-
*/
|
|
1739
|
-
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
1740
|
-
document: IdentifiedSanityDocumentStub<R>,
|
|
1741
|
-
options: AllDocumentIdsMutationOptions,
|
|
1742
|
-
): Observable<MultipleMutationResult>
|
|
1743
|
-
/**
|
|
1744
|
-
* Create a document if it does not exist, or replace a document with the same document ID
|
|
1745
|
-
* Returns an observable that resolves to the created document.
|
|
1746
|
-
*
|
|
1747
|
-
* @param document - Document to either create or replace
|
|
1748
|
-
* @param options - Mutation options
|
|
1749
|
-
*/
|
|
1750
|
-
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
1751
|
-
document: IdentifiedSanityDocumentStub<R>,
|
|
1752
|
-
options?: BaseMutationOptions,
|
|
1753
|
-
): Observable<SanityDocument<R>>
|
|
1754
|
-
|
|
1755
|
-
/**
|
|
1756
|
-
* Deletes a document with the given document ID.
|
|
1757
|
-
* Returns an observable that resolves to the deleted document.
|
|
1758
|
-
*
|
|
1759
|
-
* @param id - Document ID to delete
|
|
1760
|
-
* @param options - Options for the mutation
|
|
1761
|
-
*/
|
|
1762
|
-
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1763
|
-
id: string,
|
|
1764
|
-
options: FirstDocumentMutationOptions,
|
|
1765
|
-
): Observable<SanityDocument<R>>
|
|
1766
|
-
/**
|
|
1767
|
-
* Deletes a document with the given document ID.
|
|
1768
|
-
* Returns an observable that resolves to an array containing the deleted document.
|
|
1769
|
-
*
|
|
1770
|
-
* @param id - Document ID to delete
|
|
1771
|
-
* @param options - Options for the mutation
|
|
1772
|
-
*/
|
|
1773
|
-
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1774
|
-
id: string,
|
|
1775
|
-
options: AllDocumentsMutationOptions,
|
|
1776
|
-
): Observable<SanityDocument<R>[]>
|
|
1777
|
-
/**
|
|
1778
|
-
* Deletes a document with the given document ID.
|
|
1779
|
-
* Returns an observable that resolves to a mutation result object containing the deleted document ID.
|
|
1780
|
-
*
|
|
1781
|
-
* @param id - Document ID to delete
|
|
1782
|
-
* @param options - Options for the mutation
|
|
1783
|
-
*/
|
|
1784
|
-
delete(id: string, options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
|
|
1785
|
-
/**
|
|
1786
|
-
* Deletes a document with the given document ID.
|
|
1787
|
-
* Returns an observable that resolves to a mutation result object containing the deleted document ID.
|
|
1788
|
-
*
|
|
1789
|
-
* @param id - Document ID to delete
|
|
1790
|
-
* @param options - Options for the mutation
|
|
1791
|
-
*/
|
|
1792
|
-
delete(id: string, options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
|
|
1793
|
-
/**
|
|
1794
|
-
* Deletes a document with the given document ID.
|
|
1795
|
-
* Returns an observable that resolves to the deleted document.
|
|
1796
|
-
*
|
|
1797
|
-
* @param id - Document ID to delete
|
|
1798
|
-
* @param options - Options for the mutation
|
|
1799
|
-
*/
|
|
1800
|
-
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1801
|
-
id: string,
|
|
1802
|
-
options?: BaseMutationOptions,
|
|
1803
|
-
): Observable<SanityDocument<R>>
|
|
1804
|
-
/**
|
|
1805
|
-
* Deletes one or more documents matching the given query or document ID.
|
|
1806
|
-
* Returns an observable that resolves to first deleted document.
|
|
1807
|
-
*
|
|
1808
|
-
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
1809
|
-
* @param options - Options for the mutation
|
|
1810
|
-
*/
|
|
1811
|
-
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1812
|
-
selection: MutationSelection,
|
|
1813
|
-
options: FirstDocumentMutationOptions,
|
|
1814
|
-
): Observable<SanityDocument<R>>
|
|
1815
|
-
/**
|
|
1816
|
-
* Deletes one or more documents matching the given query or document ID.
|
|
1817
|
-
* Returns an observable that resolves to an array containing the deleted documents.
|
|
1818
|
-
*
|
|
1819
|
-
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
1820
|
-
* @param options - Options for the mutation
|
|
1821
|
-
*/
|
|
1822
|
-
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1823
|
-
selection: MutationSelection,
|
|
1824
|
-
options: AllDocumentsMutationOptions,
|
|
1825
|
-
): Observable<SanityDocument<R>[]>
|
|
1826
|
-
/**
|
|
1827
|
-
* Deletes one or more documents matching the given query or document ID.
|
|
1828
|
-
* Returns an observable that resolves to a mutation result object containing the ID of the first deleted document.
|
|
1829
|
-
*
|
|
1830
|
-
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
1831
|
-
* @param options - Options for the mutation
|
|
1832
|
-
*/
|
|
1833
|
-
delete(
|
|
1834
|
-
selection: MutationSelection,
|
|
1835
|
-
options: FirstDocumentIdMutationOptions,
|
|
1836
|
-
): Observable<SingleMutationResult>
|
|
1837
|
-
/**
|
|
1838
|
-
* Deletes one or more documents matching the given query or document ID.
|
|
1839
|
-
* Returns an observable that resolves to a mutation result object containing the document IDs that were deleted.
|
|
1840
|
-
*
|
|
1841
|
-
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
1842
|
-
* @param options - Options for the mutation
|
|
1843
|
-
*/
|
|
1844
|
-
delete(
|
|
1845
|
-
selection: MutationSelection,
|
|
1846
|
-
options: AllDocumentIdsMutationOptions,
|
|
1847
|
-
): Observable<MultipleMutationResult>
|
|
1848
|
-
/**
|
|
1849
|
-
* Deletes one or more documents matching the given query or document ID.
|
|
1850
|
-
* Returns an observable that resolves to first deleted document.
|
|
1851
|
-
*
|
|
1852
|
-
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
1853
|
-
* @param options - Options for the mutation
|
|
1854
|
-
*/
|
|
1855
|
-
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1856
|
-
selection: MutationSelection,
|
|
1857
|
-
options?: BaseMutationOptions,
|
|
1858
|
-
): Observable<SanityDocument<R>>
|
|
1859
|
-
|
|
1860
|
-
/**
|
|
1861
|
-
* Perform mutation operations against the configured dataset
|
|
1862
|
-
* Returns an observable that resolves to the first mutated document.
|
|
1863
|
-
*
|
|
1864
|
-
* @param operations - Mutation operations to execute
|
|
1865
|
-
* @param options - Mutation options
|
|
1866
|
-
*/
|
|
1867
|
-
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1868
|
-
operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
|
|
1869
|
-
options: FirstDocumentMutationOptions,
|
|
1870
|
-
): Observable<SanityDocument<R>>
|
|
1871
|
-
/**
|
|
1872
|
-
* Perform mutation operations against the configured dataset.
|
|
1873
|
-
* Returns an observable that resolves to an array of the mutated documents.
|
|
1874
|
-
*
|
|
1875
|
-
* @param operations - Mutation operations to execute
|
|
1876
|
-
* @param options - Mutation options
|
|
1877
|
-
*/
|
|
1878
|
-
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1879
|
-
operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
|
|
1880
|
-
options: AllDocumentsMutationOptions,
|
|
1881
|
-
): Observable<SanityDocument<R>[]>
|
|
1882
|
-
/**
|
|
1883
|
-
* Perform mutation operations against the configured dataset
|
|
1884
|
-
* Returns an observable that resolves to a mutation result object containing the document ID of the first mutated document.
|
|
1885
|
-
*
|
|
1886
|
-
* @param operations - Mutation operations to execute
|
|
1887
|
-
* @param options - Mutation options
|
|
1888
|
-
*/
|
|
1889
|
-
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1890
|
-
operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
|
|
1891
|
-
options: FirstDocumentIdMutationOptions,
|
|
1892
|
-
): Observable<SingleMutationResult>
|
|
1893
|
-
/**
|
|
1894
|
-
* Perform mutation operations against the configured dataset
|
|
1895
|
-
* Returns an observable that resolves to a mutation result object containing the mutated document IDs.
|
|
1896
|
-
*
|
|
1897
|
-
* @param operations - Mutation operations to execute
|
|
1898
|
-
* @param options - Mutation options
|
|
1899
|
-
*/
|
|
1900
|
-
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1901
|
-
operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
|
|
1902
|
-
options: AllDocumentIdsMutationOptions,
|
|
1903
|
-
): Observable<MultipleMutationResult>
|
|
1904
|
-
/**
|
|
1905
|
-
* Perform mutation operations against the configured dataset
|
|
1906
|
-
* Returns an observable that resolves to the first mutated document.
|
|
1907
|
-
*
|
|
1908
|
-
* @param operations - Mutation operations to execute
|
|
1909
|
-
* @param options - Mutation options
|
|
1910
|
-
*/
|
|
1911
|
-
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1912
|
-
operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
|
|
1913
|
-
options?: BaseMutationOptions,
|
|
1914
|
-
): Observable<SanityDocument<R>>
|
|
1915
|
-
|
|
1916
|
-
/**
|
|
1917
|
-
* Create a new buildable patch of operations to perform
|
|
1918
|
-
*
|
|
1919
|
-
* @param documentId - Document ID to patch
|
|
1920
|
-
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
1921
|
-
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
1922
|
-
*/
|
|
1923
|
-
patch(documentId: string, operations?: PatchOperations): ObservablePatch
|
|
1924
|
-
|
|
1925
|
-
/**
|
|
1926
|
-
* Create a new buildable patch of operations to perform
|
|
1927
|
-
*
|
|
1928
|
-
* @param documentIds - Array of document IDs to patch
|
|
1929
|
-
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
1930
|
-
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
1931
|
-
*/
|
|
1932
|
-
patch(documentIds: string[], operations?: PatchOperations): ObservablePatch
|
|
1933
|
-
|
|
1934
|
-
/**
|
|
1935
|
-
* Create a new buildable patch of operations to perform
|
|
1936
|
-
*
|
|
1937
|
-
* @param selection - An object with `query` and optional `params`, defining which document(s) to patch
|
|
1938
|
-
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
1939
|
-
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
1940
|
-
*/
|
|
1941
|
-
patch(selection: MutationSelection, operations?: PatchOperations): ObservablePatch
|
|
1942
|
-
|
|
1943
|
-
/**
|
|
1944
|
-
* Create a new buildable patch of operations to perform
|
|
1945
|
-
*
|
|
1946
|
-
* @param selection - Document ID, an array of document IDs, or an object with `query` and optional `params`, defining which document(s) to patch
|
|
1947
|
-
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
1948
|
-
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
1949
|
-
*/
|
|
1950
|
-
patch(selection: PatchSelection, operations?: PatchOperations): ObservablePatch
|
|
1951
|
-
|
|
1952
|
-
/**
|
|
1953
|
-
* Create a new transaction of mutations
|
|
1954
|
-
*
|
|
1955
|
-
* @param operations - Optional array of mutation operations to initialize the transaction instance with
|
|
1956
|
-
*/
|
|
1957
|
-
transaction<R extends Record<string, Any> = Record<string, Any>>(
|
|
1958
|
-
operations?: Mutation<R>[],
|
|
1959
|
-
): ObservableTransaction
|
|
1960
|
-
|
|
1961
|
-
/**
|
|
1962
|
-
* Perform action operations against the configured dataset
|
|
1963
|
-
*
|
|
1964
|
-
* @param operations - Action operation(s) to execute
|
|
1965
|
-
* @param options - Action options
|
|
1966
|
-
*/
|
|
1967
|
-
action(
|
|
1968
|
-
operations: Action | Action[],
|
|
1969
|
-
options?: BaseActionOptions,
|
|
1970
|
-
): Observable<SingleActionResult | MultipleActionResult>
|
|
1971
|
-
|
|
1972
|
-
/**
|
|
1973
|
-
* Perform an HTTP request against the Sanity API
|
|
1974
|
-
*
|
|
1975
|
-
* @param options - Request options
|
|
1976
|
-
*/
|
|
1977
|
-
request<R = Any>(options: RawRequestOptions): Observable<R>
|
|
1978
|
-
}
|
|
1979
|
-
|
|
1980
|
-
/**
|
|
1981
|
-
* The interface implemented by the `SanityClient` class.
|
|
1982
|
-
* When writing code that wants to take an instance of `SanityClient` as input it's better to use this type,
|
|
1983
|
-
* as the `SanityClient` class has private properties and thus TypeScrict will consider the type incompatible
|
|
1984
|
-
* in cases where you might have multiple `@sanity/client` instances in your node_modules.
|
|
1985
|
-
* @public
|
|
1986
|
-
*/
|
|
1987
|
-
export interface SanityClientType extends SanityClientBase {
|
|
1988
|
-
assets: AssetsClientType
|
|
1989
|
-
datasets: DatasetsClientType
|
|
1990
|
-
projects: ProjectsClientType
|
|
1991
|
-
users: UsersClientType
|
|
1992
|
-
|
|
1993
|
-
/**
|
|
1994
|
-
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
1995
|
-
*/
|
|
1996
|
-
observable: ObservableSanityClientType
|
|
1997
|
-
|
|
1998
|
-
/**
|
|
1999
|
-
* Clone the client - returns a new instance
|
|
2000
|
-
*/
|
|
2001
|
-
clone(): SanityClientType
|
|
2002
|
-
|
|
2003
|
-
/**
|
|
2004
|
-
* Returns the current client configuration
|
|
2005
|
-
*/
|
|
2006
|
-
config(): InitializedClientConfig
|
|
2007
|
-
/**
|
|
2008
|
-
* Reconfigure the client. Note that this _mutates_ the current client.
|
|
2009
|
-
*/
|
|
2010
|
-
config(newConfig?: Partial<ClientConfig>): SanityClientType
|
|
2011
|
-
|
|
2012
|
-
/**
|
|
2013
|
-
* Clone the client with a new (partial) configuration.
|
|
2014
|
-
*
|
|
2015
|
-
* @param newConfig - New client configuration properties, shallowly merged with existing configuration
|
|
2016
|
-
*/
|
|
2017
|
-
withConfig(newConfig?: Partial<ClientConfig>): SanityClientType
|
|
2018
|
-
|
|
2019
|
-
/**
|
|
2020
|
-
* Perform a GROQ-query against the configured dataset.
|
|
2021
|
-
*
|
|
2022
|
-
* @param query - GROQ-query to perform
|
|
2023
|
-
*/
|
|
2024
|
-
fetch<
|
|
2025
|
-
R = Any,
|
|
2026
|
-
Q extends QueryWithoutParams = QueryWithoutParams,
|
|
2027
|
-
const G extends string = string,
|
|
2028
|
-
>(
|
|
2029
|
-
query: G,
|
|
2030
|
-
params?: Q | QueryWithoutParams,
|
|
2031
|
-
): Promise<ClientReturn<G, R>>
|
|
2032
|
-
/**
|
|
2033
|
-
* Perform a GROQ-query against the configured dataset.
|
|
2034
|
-
*
|
|
2035
|
-
* @param query - GROQ-query to perform
|
|
2036
|
-
* @param params - Optional query parameters
|
|
2037
|
-
* @param options - Optional request options
|
|
2038
|
-
*/
|
|
2039
|
-
fetch<
|
|
2040
|
-
R = Any,
|
|
2041
|
-
Q extends QueryWithoutParams | QueryParams = QueryParams,
|
|
2042
|
-
const G extends string = string,
|
|
2043
|
-
>(
|
|
2044
|
-
query: G,
|
|
2045
|
-
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
2046
|
-
options?: FilteredResponseQueryOptions,
|
|
2047
|
-
): Promise<ClientReturn<G, R>>
|
|
2048
|
-
/**
|
|
2049
|
-
* Perform a GROQ-query against the configured dataset.
|
|
2050
|
-
*
|
|
2051
|
-
* @param query - GROQ-query to perform
|
|
2052
|
-
* @param params - Optional query parameters
|
|
2053
|
-
* @param options - Request options
|
|
2054
|
-
*/
|
|
2055
|
-
fetch<
|
|
2056
|
-
R = Any,
|
|
2057
|
-
Q extends QueryWithoutParams | QueryParams = QueryParams,
|
|
2058
|
-
const G extends string = string,
|
|
2059
|
-
>(
|
|
2060
|
-
query: G,
|
|
2061
|
-
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
2062
|
-
options: UnfilteredResponseQueryOptions,
|
|
2063
|
-
): Promise<RawQueryResponse<ClientReturn<G, R>>>
|
|
2064
|
-
/**
|
|
2065
|
-
* Perform a GROQ-query against the configured dataset.
|
|
2066
|
-
*
|
|
2067
|
-
* @param query - GROQ-query to perform
|
|
2068
|
-
* @param params - Optional query parameters
|
|
2069
|
-
* @param options - Request options
|
|
2070
|
-
*/
|
|
2071
|
-
fetch<
|
|
2072
|
-
R = Any,
|
|
2073
|
-
Q extends QueryWithoutParams | QueryParams = QueryParams,
|
|
2074
|
-
const G extends string = string,
|
|
2075
|
-
>(
|
|
2076
|
-
query: G,
|
|
2077
|
-
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
2078
|
-
options: UnfilteredResponseWithoutQuery,
|
|
2079
|
-
): Promise<RawQuerylessQueryResponse<ClientReturn<G, R>>>
|
|
2080
|
-
|
|
2081
|
-
/**
|
|
2082
|
-
* Fetch a single document with the given ID.
|
|
2083
|
-
*
|
|
2084
|
-
* @param id - Document ID to fetch
|
|
2085
|
-
* @param options - Request options
|
|
2086
|
-
*/
|
|
2087
|
-
getDocument<R extends Record<string, Any> = Record<string, Any>>(
|
|
2088
|
-
id: string,
|
|
2089
|
-
options?: {signal?: AbortSignal; tag?: string},
|
|
2090
|
-
): Promise<SanityDocument<R> | undefined>
|
|
2091
|
-
|
|
2092
|
-
/**
|
|
2093
|
-
* Fetch multiple documents in one request.
|
|
2094
|
-
* Should be used sparingly - performing a query is usually a better option.
|
|
2095
|
-
* The order/position of documents is preserved based on the original array of IDs.
|
|
2096
|
-
* If any of the documents are missing, they will be replaced by a `null` entry in the returned array
|
|
2097
|
-
*
|
|
2098
|
-
* @param ids - Document IDs to fetch
|
|
2099
|
-
* @param options - Request options
|
|
2100
|
-
*/
|
|
2101
|
-
getDocuments<R extends Record<string, Any> = Record<string, Any>>(
|
|
2102
|
-
ids: string[],
|
|
2103
|
-
options?: {signal?: AbortSignal; tag?: string},
|
|
2104
|
-
): Promise<(SanityDocument<R> | null)[]>
|
|
2105
|
-
|
|
2106
|
-
/**
|
|
2107
|
-
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
2108
|
-
* Returns a promise that resolves to the created document.
|
|
2109
|
-
*
|
|
2110
|
-
* @param document - Document to create
|
|
2111
|
-
* @param options - Mutation options
|
|
2112
|
-
*/
|
|
2113
|
-
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
2114
|
-
document: SanityDocumentStub<R>,
|
|
2115
|
-
options: FirstDocumentMutationOptions,
|
|
2116
|
-
): Promise<SanityDocument<R>>
|
|
2117
|
-
/**
|
|
2118
|
-
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
2119
|
-
* Returns a promise that resolves to an array containing the created document.
|
|
2120
|
-
*
|
|
2121
|
-
* @param document - Document to create
|
|
2122
|
-
* @param options - Mutation options
|
|
2123
|
-
*/
|
|
2124
|
-
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
2125
|
-
document: SanityDocumentStub<R>,
|
|
2126
|
-
options: AllDocumentsMutationOptions,
|
|
2127
|
-
): Promise<SanityDocument<R>[]>
|
|
2128
|
-
/**
|
|
2129
|
-
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
2130
|
-
* Returns a promise that resolves to a mutation result object containing the ID of the created document.
|
|
2131
|
-
*
|
|
2132
|
-
* @param document - Document to create
|
|
2133
|
-
* @param options - Mutation options
|
|
2134
|
-
*/
|
|
2135
|
-
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
2136
|
-
document: SanityDocumentStub<R>,
|
|
2137
|
-
options: FirstDocumentIdMutationOptions,
|
|
2138
|
-
): Promise<SingleMutationResult>
|
|
2139
|
-
/**
|
|
2140
|
-
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
2141
|
-
* Returns a promise that resolves to a mutation result object containing the ID of the created document.
|
|
2142
|
-
*
|
|
2143
|
-
* @param document - Document to create
|
|
2144
|
-
* @param options - Mutation options
|
|
2145
|
-
*/
|
|
2146
|
-
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
2147
|
-
document: SanityDocumentStub<R>,
|
|
2148
|
-
options: AllDocumentIdsMutationOptions,
|
|
2149
|
-
): Promise<MultipleMutationResult>
|
|
2150
|
-
/**
|
|
2151
|
-
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
2152
|
-
* Returns a promise that resolves to the created document.
|
|
2153
|
-
*
|
|
2154
|
-
* @param document - Document to create
|
|
2155
|
-
* @param options - Mutation options
|
|
2156
|
-
*/
|
|
2157
|
-
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
2158
|
-
document: SanityDocumentStub<R>,
|
|
2159
|
-
options?: BaseMutationOptions,
|
|
2160
|
-
): Promise<SanityDocument<R>>
|
|
2161
|
-
|
|
2162
|
-
/**
|
|
2163
|
-
* Create a document if no document with the same ID already exists.
|
|
2164
|
-
* Returns a promise that resolves to the created document.
|
|
2165
|
-
*
|
|
2166
|
-
* @param document - Document to create
|
|
2167
|
-
* @param options - Mutation options
|
|
2168
|
-
*/
|
|
2169
|
-
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
2170
|
-
document: IdentifiedSanityDocumentStub<R>,
|
|
2171
|
-
options: FirstDocumentMutationOptions,
|
|
2172
|
-
): Promise<SanityDocument<R>>
|
|
2173
|
-
/**
|
|
2174
|
-
* Create a document if no document with the same ID already exists.
|
|
2175
|
-
* Returns a promise that resolves to an array containing the created document.
|
|
2176
|
-
*
|
|
2177
|
-
* @param document - Document to create
|
|
2178
|
-
* @param options - Mutation options
|
|
2179
|
-
*/
|
|
2180
|
-
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
2181
|
-
document: IdentifiedSanityDocumentStub<R>,
|
|
2182
|
-
options: AllDocumentsMutationOptions,
|
|
2183
|
-
): Promise<SanityDocument<R>[]>
|
|
2184
|
-
/**
|
|
2185
|
-
* Create a document if no document with the same ID already exists.
|
|
2186
|
-
* Returns a promise that resolves to a mutation result object containing the ID of the created document.
|
|
2187
|
-
*
|
|
2188
|
-
* @param document - Document to create
|
|
2189
|
-
* @param options - Mutation options
|
|
2190
|
-
*/
|
|
2191
|
-
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
2192
|
-
document: IdentifiedSanityDocumentStub<R>,
|
|
2193
|
-
options: FirstDocumentIdMutationOptions,
|
|
2194
|
-
): Promise<SingleMutationResult>
|
|
2195
|
-
/**
|
|
2196
|
-
* Create a document if no document with the same ID already exists.
|
|
2197
|
-
* Returns a promise that resolves to a mutation result object containing the ID of the created document.
|
|
2198
|
-
*
|
|
2199
|
-
* @param document - Document to create
|
|
2200
|
-
* @param options - Mutation options
|
|
2201
|
-
*/
|
|
2202
|
-
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
2203
|
-
document: IdentifiedSanityDocumentStub<R>,
|
|
2204
|
-
options: AllDocumentIdsMutationOptions,
|
|
2205
|
-
): Promise<MultipleMutationResult>
|
|
2206
|
-
/**
|
|
2207
|
-
* Create a document if no document with the same ID already exists.
|
|
2208
|
-
* Returns a promise that resolves to the created document.
|
|
2209
|
-
*
|
|
2210
|
-
* @param document - Document to create
|
|
2211
|
-
* @param options - Mutation options
|
|
2212
|
-
*/
|
|
2213
|
-
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
2214
|
-
document: IdentifiedSanityDocumentStub<R>,
|
|
2215
|
-
options?: BaseMutationOptions,
|
|
2216
|
-
): Promise<SanityDocument<R>>
|
|
2217
|
-
|
|
2218
|
-
/**
|
|
2219
|
-
* Create a document if it does not exist, or replace a document with the same document ID
|
|
2220
|
-
* Returns a promise that resolves to the created document.
|
|
2221
|
-
*
|
|
2222
|
-
* @param document - Document to either create or replace
|
|
2223
|
-
* @param options - Mutation options
|
|
2224
|
-
*/
|
|
2225
|
-
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
2226
|
-
document: IdentifiedSanityDocumentStub<R>,
|
|
2227
|
-
options: FirstDocumentMutationOptions,
|
|
2228
|
-
): Promise<SanityDocument<R>>
|
|
2229
|
-
/**
|
|
2230
|
-
* Create a document if it does not exist, or replace a document with the same document ID
|
|
2231
|
-
* Returns a promise that resolves to an array containing the created document.
|
|
2232
|
-
*
|
|
2233
|
-
* @param document - Document to either create or replace
|
|
2234
|
-
* @param options - Mutation options
|
|
2235
|
-
*/
|
|
2236
|
-
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
2237
|
-
document: IdentifiedSanityDocumentStub<R>,
|
|
2238
|
-
options: AllDocumentsMutationOptions,
|
|
2239
|
-
): Promise<SanityDocument<R>[]>
|
|
2240
|
-
/**
|
|
2241
|
-
* Create a document if it does not exist, or replace a document with the same document ID
|
|
2242
|
-
* Returns a promise that resolves to a mutation result object containing the ID of the created document.
|
|
2243
|
-
*
|
|
2244
|
-
* @param document - Document to either create or replace
|
|
2245
|
-
* @param options - Mutation options
|
|
2246
|
-
*/
|
|
2247
|
-
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
2248
|
-
document: IdentifiedSanityDocumentStub<R>,
|
|
2249
|
-
options: FirstDocumentIdMutationOptions,
|
|
2250
|
-
): Promise<SingleMutationResult>
|
|
2251
|
-
/**
|
|
2252
|
-
* Create a document if it does not exist, or replace a document with the same document ID
|
|
2253
|
-
* Returns a promise that resolves to a mutation result object containing the created document ID.
|
|
2254
|
-
*
|
|
2255
|
-
* @param document - Document to either create or replace
|
|
2256
|
-
* @param options - Mutation options
|
|
2257
|
-
*/
|
|
2258
|
-
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
2259
|
-
document: IdentifiedSanityDocumentStub<R>,
|
|
2260
|
-
options: AllDocumentIdsMutationOptions,
|
|
2261
|
-
): Promise<MultipleMutationResult>
|
|
2262
|
-
/**
|
|
2263
|
-
* Create a document if it does not exist, or replace a document with the same document ID
|
|
2264
|
-
* Returns a promise that resolves to the created document.
|
|
2265
|
-
*
|
|
2266
|
-
* @param document - Document to either create or replace
|
|
2267
|
-
* @param options - Mutation options
|
|
2268
|
-
*/
|
|
2269
|
-
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
2270
|
-
document: IdentifiedSanityDocumentStub<R>,
|
|
2271
|
-
options?: BaseMutationOptions,
|
|
2272
|
-
): Promise<SanityDocument<R>>
|
|
2273
|
-
|
|
2274
|
-
/**
|
|
2275
|
-
* Deletes a document with the given document ID.
|
|
2276
|
-
* Returns a promise that resolves to the deleted document.
|
|
2277
|
-
*
|
|
2278
|
-
* @param id - Document ID to delete
|
|
2279
|
-
* @param options - Options for the mutation
|
|
2280
|
-
*/
|
|
2281
|
-
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
2282
|
-
id: string,
|
|
2283
|
-
options: FirstDocumentMutationOptions,
|
|
2284
|
-
): Promise<SanityDocument<R>>
|
|
2285
|
-
/**
|
|
2286
|
-
* Deletes a document with the given document ID.
|
|
2287
|
-
* Returns a promise that resolves to an array containing the deleted document.
|
|
2288
|
-
*
|
|
2289
|
-
* @param id - Document ID to delete
|
|
2290
|
-
* @param options - Options for the mutation
|
|
2291
|
-
*/
|
|
2292
|
-
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
2293
|
-
id: string,
|
|
2294
|
-
options: AllDocumentsMutationOptions,
|
|
2295
|
-
): Promise<SanityDocument<R>[]>
|
|
2296
|
-
/**
|
|
2297
|
-
* Deletes a document with the given document ID.
|
|
2298
|
-
* Returns a promise that resolves to a mutation result object containing the deleted document ID.
|
|
2299
|
-
*
|
|
2300
|
-
* @param id - Document ID to delete
|
|
2301
|
-
* @param options - Options for the mutation
|
|
2302
|
-
*/
|
|
2303
|
-
delete(id: string, options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
|
|
2304
|
-
/**
|
|
2305
|
-
* Deletes a document with the given document ID.
|
|
2306
|
-
* Returns a promise that resolves to a mutation result object containing the deleted document ID.
|
|
2307
|
-
*
|
|
2308
|
-
* @param id - Document ID to delete
|
|
2309
|
-
* @param options - Options for the mutation
|
|
2310
|
-
*/
|
|
2311
|
-
delete(id: string, options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
|
|
2312
|
-
/**
|
|
2313
|
-
* Deletes a document with the given document ID.
|
|
2314
|
-
* Returns a promise that resolves to the deleted document.
|
|
2315
|
-
*
|
|
2316
|
-
* @param id - Document ID to delete
|
|
2317
|
-
* @param options - Options for the mutation
|
|
2318
|
-
*/
|
|
2319
|
-
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
2320
|
-
id: string,
|
|
2321
|
-
options?: BaseMutationOptions,
|
|
2322
|
-
): Promise<SanityDocument<R>>
|
|
2323
|
-
/**
|
|
2324
|
-
* Deletes one or more documents matching the given query or document ID.
|
|
2325
|
-
* Returns a promise that resolves to first deleted document.
|
|
2326
|
-
*
|
|
2327
|
-
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
2328
|
-
* @param options - Options for the mutation
|
|
2329
|
-
*/
|
|
2330
|
-
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
2331
|
-
selection: MutationSelection,
|
|
2332
|
-
options: FirstDocumentMutationOptions,
|
|
2333
|
-
): Promise<SanityDocument<R>>
|
|
2334
|
-
/**
|
|
2335
|
-
* Deletes one or more documents matching the given query or document ID.
|
|
2336
|
-
* Returns a promise that resolves to an array containing the deleted documents.
|
|
2337
|
-
*
|
|
2338
|
-
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
2339
|
-
* @param options - Options for the mutation
|
|
2340
|
-
*/
|
|
2341
|
-
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
2342
|
-
selection: MutationSelection,
|
|
2343
|
-
options: AllDocumentsMutationOptions,
|
|
2344
|
-
): Promise<SanityDocument<R>[]>
|
|
2345
|
-
/**
|
|
2346
|
-
* Deletes one or more documents matching the given query or document ID.
|
|
2347
|
-
* Returns a promise that resolves to a mutation result object containing the ID of the first deleted document.
|
|
2348
|
-
*
|
|
2349
|
-
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
2350
|
-
* @param options - Options for the mutation
|
|
2351
|
-
*/
|
|
2352
|
-
delete(
|
|
2353
|
-
selection: MutationSelection,
|
|
2354
|
-
options: FirstDocumentIdMutationOptions,
|
|
2355
|
-
): Promise<SingleMutationResult>
|
|
2356
|
-
/**
|
|
2357
|
-
* Deletes one or more documents matching the given query or document ID.
|
|
2358
|
-
* Returns a promise that resolves to a mutation result object containing the document IDs that were deleted.
|
|
2359
|
-
*
|
|
2360
|
-
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
2361
|
-
* @param options - Options for the mutation
|
|
2362
|
-
*/
|
|
2363
|
-
delete(
|
|
2364
|
-
selection: MutationSelection,
|
|
2365
|
-
options: AllDocumentIdsMutationOptions,
|
|
2366
|
-
): Promise<MultipleMutationResult>
|
|
2367
|
-
/**
|
|
2368
|
-
* Deletes one or more documents matching the given query or document ID.
|
|
2369
|
-
* Returns a promise that resolves to first deleted document.
|
|
2370
|
-
*
|
|
2371
|
-
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
2372
|
-
* @param options - Options for the mutation
|
|
2373
|
-
*/
|
|
2374
|
-
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
2375
|
-
selection: MutationSelection,
|
|
2376
|
-
options?: BaseMutationOptions,
|
|
2377
|
-
): Promise<SanityDocument<R>>
|
|
2378
|
-
|
|
2379
|
-
/**
|
|
2380
|
-
* Perform mutation operations against the configured dataset
|
|
2381
|
-
* Returns a promise that resolves to the first mutated document.
|
|
2382
|
-
*
|
|
2383
|
-
* @param operations - Mutation operations to execute
|
|
2384
|
-
* @param options - Mutation options
|
|
2385
|
-
*/
|
|
2386
|
-
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
2387
|
-
operations: Mutation<R>[] | Patch | Transaction,
|
|
2388
|
-
options: FirstDocumentMutationOptions,
|
|
2389
|
-
): Promise<SanityDocument<R>>
|
|
2390
|
-
/**
|
|
2391
|
-
* Perform mutation operations against the configured dataset.
|
|
2392
|
-
* Returns a promise that resolves to an array of the mutated documents.
|
|
2393
|
-
*
|
|
2394
|
-
* @param operations - Mutation operations to execute
|
|
2395
|
-
* @param options - Mutation options
|
|
2396
|
-
*/
|
|
2397
|
-
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
2398
|
-
operations: Mutation<R>[] | Patch | Transaction,
|
|
2399
|
-
options: AllDocumentsMutationOptions,
|
|
2400
|
-
): Promise<SanityDocument<R>[]>
|
|
2401
|
-
/**
|
|
2402
|
-
* Perform mutation operations against the configured dataset
|
|
2403
|
-
* Returns a promise that resolves to a mutation result object containing the document ID of the first mutated document.
|
|
2404
|
-
*
|
|
2405
|
-
* @param operations - Mutation operations to execute
|
|
2406
|
-
* @param options - Mutation options
|
|
2407
|
-
*/
|
|
2408
|
-
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
2409
|
-
operations: Mutation<R>[] | Patch | Transaction,
|
|
2410
|
-
options: FirstDocumentIdMutationOptions,
|
|
2411
|
-
): Promise<SingleMutationResult>
|
|
2412
|
-
/**
|
|
2413
|
-
* Perform mutation operations against the configured dataset
|
|
2414
|
-
* Returns a promise that resolves to a mutation result object containing the mutated document IDs.
|
|
2415
|
-
*
|
|
2416
|
-
* @param operations - Mutation operations to execute
|
|
2417
|
-
* @param options - Mutation options
|
|
2418
|
-
*/
|
|
2419
|
-
mutate<R extends Record<string, Any>>(
|
|
2420
|
-
operations: Mutation<R>[] | Patch | Transaction,
|
|
2421
|
-
options: AllDocumentIdsMutationOptions,
|
|
2422
|
-
): Promise<MultipleMutationResult>
|
|
2423
|
-
/**
|
|
2424
|
-
* Perform mutation operations against the configured dataset
|
|
2425
|
-
* Returns a promise that resolves to the first mutated document.
|
|
2426
|
-
*
|
|
2427
|
-
* @param operations - Mutation operations to execute
|
|
2428
|
-
* @param options - Mutation options
|
|
2429
|
-
*/
|
|
2430
|
-
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
2431
|
-
operations: Mutation<R>[] | Patch | Transaction,
|
|
2432
|
-
options?: BaseMutationOptions,
|
|
2433
|
-
): Promise<SanityDocument<R>>
|
|
2434
|
-
|
|
2435
|
-
/**
|
|
2436
|
-
* Create a new buildable patch of operations to perform
|
|
2437
|
-
*
|
|
2438
|
-
* @param documentId - Document ID to patch
|
|
2439
|
-
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
2440
|
-
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
2441
|
-
*/
|
|
2442
|
-
patch(documentId: string, operations?: PatchOperations): Patch
|
|
2443
|
-
|
|
2444
|
-
/**
|
|
2445
|
-
* Create a new buildable patch of operations to perform
|
|
2446
|
-
*
|
|
2447
|
-
* @param documentIds - Array of document IDs to patch
|
|
2448
|
-
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
2449
|
-
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
2450
|
-
*/
|
|
2451
|
-
patch(documentIds: string[], operations?: PatchOperations): Patch
|
|
2452
|
-
|
|
2453
|
-
/**
|
|
2454
|
-
* Create a new buildable patch of operations to perform
|
|
2455
|
-
*
|
|
2456
|
-
* @param selection - An object with `query` and optional `params`, defining which document(s) to patch
|
|
2457
|
-
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
2458
|
-
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
2459
|
-
*/
|
|
2460
|
-
patch(selection: MutationSelection, operations?: PatchOperations): Patch
|
|
2461
|
-
|
|
2462
|
-
/**
|
|
2463
|
-
* Create a new buildable patch of operations to perform
|
|
2464
|
-
*
|
|
2465
|
-
* @param selection - Document ID, an array of document IDs, or an object with `query` and optional `params`, defining which document(s) to patch
|
|
2466
|
-
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
2467
|
-
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
2468
|
-
*/
|
|
2469
|
-
patch(selection: PatchSelection, operations?: PatchOperations): Patch
|
|
2470
|
-
|
|
2471
|
-
/**
|
|
2472
|
-
* Create a new transaction of mutations
|
|
2473
|
-
*
|
|
2474
|
-
* @param operations - Optional array of mutation operations to initialize the transaction instance with
|
|
2475
|
-
*/
|
|
2476
|
-
transaction<R extends Record<string, Any> = Record<string, Any>>(
|
|
2477
|
-
operations?: Mutation<R>[],
|
|
2478
|
-
): Transaction
|
|
2479
|
-
|
|
2480
|
-
/**
|
|
2481
|
-
* Perform action operations against the configured dataset
|
|
2482
|
-
* Returns a promise that resolves to the transaction result
|
|
2483
|
-
*
|
|
2484
|
-
* @param operations - Action operation(s) to execute
|
|
2485
|
-
* @param options - Action options
|
|
2486
|
-
*/
|
|
2487
|
-
action(
|
|
2488
|
-
operations: Action | Action[],
|
|
2489
|
-
options?: BaseActionOptions,
|
|
2490
|
-
): Promise<SingleActionResult | MultipleActionResult>
|
|
2491
|
-
|
|
2492
|
-
/**
|
|
2493
|
-
* Perform a request against the Sanity API
|
|
2494
|
-
* NOTE: Only use this for Sanity API endpoints, not for your own APIs!
|
|
2495
|
-
*
|
|
2496
|
-
* @param options - Request options
|
|
2497
|
-
* @returns Promise resolving to the response body
|
|
2498
|
-
*/
|
|
2499
|
-
request<R = Any>(options: RawRequestOptions): Promise<R>
|
|
2500
|
-
|
|
2501
|
-
/**
|
|
2502
|
-
* Perform an HTTP request a `/data` sub-endpoint
|
|
2503
|
-
* NOTE: Considered internal, thus marked as deprecated. Use `request` instead.
|
|
2504
|
-
*
|
|
2505
|
-
* @deprecated - Use `request()` or your own HTTP library instead
|
|
2506
|
-
* @param endpoint - Endpoint to hit (mutate, query etc)
|
|
2507
|
-
* @param body - Request body
|
|
2508
|
-
* @param options - Request options
|
|
2509
|
-
* @internal
|
|
2510
|
-
*/
|
|
2511
|
-
dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any>
|
|
2512
|
-
}
|