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