@sanity/sdk 0.0.0-alpha.13 → 0.0.0-alpha.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/index.d.ts +106 -18
- package/dist/index.js +254 -71
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/_exports/index.ts +6 -0
- package/src/auth/authStore.test.ts +1 -4
- package/src/auth/authStore.ts +9 -15
- package/src/auth/fetchLoginUrls.ts +3 -9
- package/src/auth/handleCallback.test.ts +2 -6
- package/src/auth/handleCallback.ts +3 -6
- package/src/auth/logout.test.ts +1 -3
- package/src/auth/logout.ts +3 -7
- package/src/auth/subscribeToStateAndFetchCurrentUser.test.ts +2 -6
- package/src/auth/subscribeToStateAndFetchCurrentUser.ts +3 -6
- package/src/{preview/subscribeToLiveAndSetLastLiveEventId.test.ts → common/createLiveEventSubscriber.test.ts} +13 -10
- package/src/common/createLiveEventSubscriber.ts +55 -0
- package/src/common/types.ts +4 -0
- package/src/common/util.ts +17 -0
- package/src/document/actions.test.ts +2 -2
- package/src/document/actions.ts +28 -12
- package/src/document/documentStore.ts +3 -4
- package/src/document/patchOperations.ts +25 -0
- package/src/documentList/documentListStore.test.ts +3 -3
- package/src/documentList/documentListStore.ts +4 -2
- package/src/documentList/subscribeToLiveClientAndSetLastLiveEventId.test.ts +1 -1
- package/src/documentList/subscribeToStateAndFetchResults.test.ts +6 -6
- package/src/documentList/subscribeToStateAndFetchResults.ts +1 -1
- package/src/instance/identity.ts +1 -0
- package/src/instance/types.ts +2 -0
- package/src/preview/previewQuery.ts +2 -1
- package/src/preview/previewStore.test.ts +26 -8
- package/src/preview/previewStore.ts +6 -6
- package/src/preview/subscribeToStateAndFetchBatches.ts +1 -1
- package/src/preview/util.ts +0 -18
- package/src/projection/getProjectionState.test.ts +123 -0
- package/src/projection/getProjectionState.ts +105 -0
- package/src/projection/projectionQuery.test.ts +148 -0
- package/src/projection/projectionQuery.ts +96 -0
- package/src/projection/projectionStore.test.ts +75 -0
- package/src/projection/projectionStore.ts +55 -0
- package/src/projection/resolveProjection.test.ts +144 -0
- package/src/projection/resolveProjection.ts +36 -0
- package/src/projection/subscribeToStateAndFetchBatches.test.ts +224 -0
- package/src/projection/subscribeToStateAndFetchBatches.ts +104 -0
- package/src/projection/util.test.ts +44 -0
- package/src/projection/util.ts +17 -0
- package/src/resources/createResource.ts +7 -3
- package/src/preview/subscribeToLiveAndSetLastLiveEventId.ts +0 -36
- /package/src/{preview → common}/util.test.ts +0 -0
package/README.md
CHANGED
|
@@ -7,20 +7,20 @@
|
|
|
7
7
|
|
|
8
8
|
Core utilities for creating Sanity applications.
|
|
9
9
|
|
|
10
|
-
## Installation
|
|
10
|
+
## 💻 Installation
|
|
11
11
|
|
|
12
12
|
```bash
|
|
13
13
|
npm i @sanity/sdk
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
## SDK Documentation
|
|
16
|
+
## 📚 SDK Documentation
|
|
17
17
|
|
|
18
18
|
See the [SDK Documentation](https://sdk-docs.sanity.dev) for more information.
|
|
19
19
|
|
|
20
|
-
## Implementations
|
|
20
|
+
## 🧑💻 Implementations
|
|
21
21
|
|
|
22
22
|
- [React](https://www.npmjs.com/package/@sanity/sdk-react)
|
|
23
23
|
|
|
24
|
-
## License
|
|
24
|
+
## 📄 License
|
|
25
25
|
|
|
26
26
|
MIT © Sanity.io
|
package/dist/index.d.ts
CHANGED
|
@@ -240,13 +240,6 @@ export declare interface AuthConfig {
|
|
|
240
240
|
* ignoring any storage or callback handling.
|
|
241
241
|
*/
|
|
242
242
|
token?: string
|
|
243
|
-
/**
|
|
244
|
-
* The authentication scope.
|
|
245
|
-
* If set to 'project', requests are scoped to the project-level.
|
|
246
|
-
* If set to 'global', requests are scoped to the user access level.
|
|
247
|
-
* Defaults to 'project'.
|
|
248
|
-
*/
|
|
249
|
-
authScope?: 'project' | 'global'
|
|
250
243
|
}
|
|
251
244
|
|
|
252
245
|
/**
|
|
@@ -305,7 +298,6 @@ export declare interface AuthStoreState {
|
|
|
305
298
|
initialLocationHref: string
|
|
306
299
|
clientFactory: (config: ClientConfig) => SanityClient
|
|
307
300
|
customProviders: AuthConfig['providers']
|
|
308
|
-
authScope: 'project' | 'global'
|
|
309
301
|
storageKey: string
|
|
310
302
|
storageArea: Storage | undefined
|
|
311
303
|
apiHost: string | undefined
|
|
@@ -422,6 +414,7 @@ export declare interface CreateDocumentAction<
|
|
|
422
414
|
> {
|
|
423
415
|
type: 'document.create'
|
|
424
416
|
documentId?: string
|
|
417
|
+
resourceId?: DocumentResourceId
|
|
425
418
|
documentType: TDocument['_type']
|
|
426
419
|
}
|
|
427
420
|
|
|
@@ -533,7 +526,7 @@ declare type DeepGet<T, TParts extends readonly unknown[]> = TParts extends [
|
|
|
533
526
|
|
|
534
527
|
/** @beta */
|
|
535
528
|
export declare function deleteDocument<TDocument extends SanityDocumentLike>(
|
|
536
|
-
doc:
|
|
529
|
+
doc: DocumentHandle<TDocument>,
|
|
537
530
|
): DeleteDocumentAction<TDocument>
|
|
538
531
|
|
|
539
532
|
/** @beta */
|
|
@@ -542,6 +535,7 @@ export declare interface DeleteDocumentAction<
|
|
|
542
535
|
> {
|
|
543
536
|
type: 'document.delete'
|
|
544
537
|
documentId: string
|
|
538
|
+
resourceId?: DocumentResourceId
|
|
545
539
|
}
|
|
546
540
|
|
|
547
541
|
declare type DereferenceFunction = (obj: {
|
|
@@ -568,7 +562,7 @@ export declare const destroyController: (
|
|
|
568
562
|
|
|
569
563
|
/** @beta */
|
|
570
564
|
export declare function discardDocument<TDocument extends SanityDocumentLike>(
|
|
571
|
-
doc:
|
|
565
|
+
doc: DocumentHandle<TDocument>,
|
|
572
566
|
): DiscardDocumentAction<TDocument>
|
|
573
567
|
|
|
574
568
|
/** @beta */
|
|
@@ -577,6 +571,7 @@ export declare interface DiscardDocumentAction<
|
|
|
577
571
|
> {
|
|
578
572
|
type: 'document.discard'
|
|
579
573
|
documentId: string
|
|
574
|
+
resourceId?: DocumentResourceId
|
|
580
575
|
}
|
|
581
576
|
|
|
582
577
|
declare type Document_2 = {
|
|
@@ -657,6 +652,7 @@ export declare type DocumentEvent =
|
|
|
657
652
|
export declare interface DocumentHandle<TDocument extends SanityDocumentLike = SanityDocumentLike> {
|
|
658
653
|
_id: string
|
|
659
654
|
_type: TDocument['_type']
|
|
655
|
+
resourceId?: DocumentResourceId
|
|
660
656
|
}
|
|
661
657
|
|
|
662
658
|
/**
|
|
@@ -674,11 +670,13 @@ declare interface DocumentHandle_2 {
|
|
|
674
670
|
* @public
|
|
675
671
|
*/
|
|
676
672
|
export declare interface DocumentListOptions {
|
|
673
|
+
/** The resourceId of the Sanity instance to use for this list. */
|
|
674
|
+
resourceId?: string
|
|
677
675
|
/** GROQ filter expression to query specific documents */
|
|
678
676
|
filter?: string
|
|
679
677
|
/** Array of sort ordering specifications to determine the order of results */
|
|
680
678
|
sort?: SortOrderingItem[]
|
|
681
|
-
/** The Content Lake perspective to use for this list. Defaults to `
|
|
679
|
+
/** The Content Lake perspective to use for this list. Defaults to `drafts`. */
|
|
682
680
|
perspective?: string
|
|
683
681
|
}
|
|
684
682
|
|
|
@@ -717,6 +715,12 @@ declare interface DocumentRebaseErrorEvent {
|
|
|
717
715
|
error: unknown
|
|
718
716
|
}
|
|
719
717
|
|
|
718
|
+
/**
|
|
719
|
+
* @beta
|
|
720
|
+
* A resource identifier for a document, in the format of `document:${projectId}.${dataset}:${documentId}`
|
|
721
|
+
*/
|
|
722
|
+
export declare type DocumentResourceId = `document:${string}.${string}:${string}`
|
|
723
|
+
|
|
720
724
|
/**
|
|
721
725
|
* Represents a set of document that will go into `applyMutations`. Before
|
|
722
726
|
* applying a mutation, it's expected that all relevant documents that the
|
|
@@ -784,6 +788,7 @@ export declare interface DocumentTypeHandle<
|
|
|
784
788
|
> {
|
|
785
789
|
_id?: string
|
|
786
790
|
_type: TDocument['_type']
|
|
791
|
+
resourceId?: DocumentResourceId
|
|
787
792
|
}
|
|
788
793
|
|
|
789
794
|
/**
|
|
@@ -803,7 +808,7 @@ export declare function editDocument<TDocument extends SanityDocumentLike>(
|
|
|
803
808
|
|
|
804
809
|
/** @beta */
|
|
805
810
|
export declare function editDocument<TDocument extends SanityDocumentLike>(
|
|
806
|
-
doc:
|
|
811
|
+
doc: DocumentHandle<TDocument>,
|
|
807
812
|
patches?: PatchOperations | PatchOperations[],
|
|
808
813
|
): EditDocumentAction<TDocument>
|
|
809
814
|
|
|
@@ -813,6 +818,7 @@ export declare interface EditDocumentAction<
|
|
|
813
818
|
> {
|
|
814
819
|
type: 'document.edit'
|
|
815
820
|
documentId: string
|
|
821
|
+
resourceId?: DocumentResourceId
|
|
816
822
|
patches?: PatchOperations[]
|
|
817
823
|
}
|
|
818
824
|
|
|
@@ -1010,7 +1016,7 @@ export declare function getDocumentState(
|
|
|
1010
1016
|
/** @beta */
|
|
1011
1017
|
export declare const getDocumentSyncStatus: ResourceAction<
|
|
1012
1018
|
DocumentStoreState,
|
|
1013
|
-
[doc:
|
|
1019
|
+
[doc: DocumentHandle<SanityDocumentLike>],
|
|
1014
1020
|
StateSource<boolean | undefined>
|
|
1015
1021
|
>
|
|
1016
1022
|
|
|
@@ -1080,6 +1086,27 @@ export declare interface GetPreviewStateOptions {
|
|
|
1080
1086
|
document: DocumentHandle_2
|
|
1081
1087
|
}
|
|
1082
1088
|
|
|
1089
|
+
/**
|
|
1090
|
+
* @beta
|
|
1091
|
+
*/
|
|
1092
|
+
export declare function getProjectionState<TResult extends object>(
|
|
1093
|
+
instance: SanityInstance | ActionContext<ProjectionStoreState>,
|
|
1094
|
+
options: GetProjectionStateOptions,
|
|
1095
|
+
): StateSource<ProjectionValuePending<TResult>>
|
|
1096
|
+
|
|
1097
|
+
/**
|
|
1098
|
+
* @beta
|
|
1099
|
+
*/
|
|
1100
|
+
export declare function getProjectionState(
|
|
1101
|
+
instance: SanityInstance | ActionContext<ProjectionStoreState>,
|
|
1102
|
+
options: GetProjectionStateOptions,
|
|
1103
|
+
): StateSource<ProjectionValuePending<Record<string, unknown>>>
|
|
1104
|
+
|
|
1105
|
+
declare interface GetProjectionStateOptions {
|
|
1106
|
+
document: DocumentHandle_2
|
|
1107
|
+
projection: ValidProjection
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1083
1110
|
/** @public */
|
|
1084
1111
|
export declare const getProjectsState: ResourceAction<
|
|
1085
1112
|
FetcherStoreState<[], Omit<SanityProject_2, 'members'>[]>,
|
|
@@ -1094,6 +1121,14 @@ export declare const getProjectState: ResourceAction<
|
|
|
1094
1121
|
StateSource<SanityProject_2 | undefined>
|
|
1095
1122
|
>
|
|
1096
1123
|
|
|
1124
|
+
/**
|
|
1125
|
+
* @beta
|
|
1126
|
+
* Get the resource ID from a document resource ID
|
|
1127
|
+
*/
|
|
1128
|
+
export declare function getResourceId(
|
|
1129
|
+
documentResourceId: DocumentResourceId | undefined,
|
|
1130
|
+
): ResourceId | undefined
|
|
1131
|
+
|
|
1097
1132
|
/**
|
|
1098
1133
|
* @public
|
|
1099
1134
|
*/
|
|
@@ -1224,6 +1259,11 @@ export declare function jsonMatch<TValue>(input: unknown, path: string): MatchEn
|
|
|
1224
1259
|
*/
|
|
1225
1260
|
export declare type JsonMatchPath<_TDocument extends SanityDocumentLike> = string
|
|
1226
1261
|
|
|
1262
|
+
declare interface LiveEventAwareState {
|
|
1263
|
+
lastLiveEventId: string | null
|
|
1264
|
+
syncTags: Record<string, true>
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1227
1267
|
/**
|
|
1228
1268
|
* Logged-in state from the auth state.
|
|
1229
1269
|
* @public
|
|
@@ -1497,7 +1537,7 @@ declare interface PosNode extends BaseNode {
|
|
|
1497
1537
|
/**
|
|
1498
1538
|
* @public
|
|
1499
1539
|
*/
|
|
1500
|
-
export declare interface PreviewStoreState {
|
|
1540
|
+
export declare interface PreviewStoreState extends LiveEventAwareState {
|
|
1501
1541
|
values: {
|
|
1502
1542
|
[TDocumentId in string]?: ValuePending<PreviewValue>
|
|
1503
1543
|
}
|
|
@@ -1509,8 +1549,6 @@ export declare interface PreviewStoreState {
|
|
|
1509
1549
|
[TSubscriptionId in string]?: true
|
|
1510
1550
|
}
|
|
1511
1551
|
}
|
|
1512
|
-
syncTags: Record<SyncTag, true>
|
|
1513
|
-
lastLiveEventId: string | null
|
|
1514
1552
|
}
|
|
1515
1553
|
|
|
1516
1554
|
/**
|
|
@@ -1554,9 +1592,31 @@ declare interface ProjectionNode extends BaseNode {
|
|
|
1554
1592
|
expr: ExprNode
|
|
1555
1593
|
}
|
|
1556
1594
|
|
|
1595
|
+
declare interface ProjectionStoreState<TValue extends object = object> extends LiveEventAwareState {
|
|
1596
|
+
values: {
|
|
1597
|
+
[TDocumentId in string]?: ProjectionValuePending<TValue>
|
|
1598
|
+
}
|
|
1599
|
+
documentProjections: {
|
|
1600
|
+
[TDocumentId in string]?: ValidProjection
|
|
1601
|
+
}
|
|
1602
|
+
subscriptions: {
|
|
1603
|
+
[TDocumentId in string]?: {
|
|
1604
|
+
[TSubscriptionId in string]?: true
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
/**
|
|
1610
|
+
* @beta
|
|
1611
|
+
*/
|
|
1612
|
+
export declare interface ProjectionValuePending<TValue extends object> {
|
|
1613
|
+
results: TValue | null
|
|
1614
|
+
isPending: boolean
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1557
1617
|
/** @beta */
|
|
1558
1618
|
export declare function publishDocument<TDocument extends SanityDocumentLike>(
|
|
1559
|
-
doc:
|
|
1619
|
+
doc: DocumentHandle<TDocument>,
|
|
1560
1620
|
): PublishDocumentAction<TDocument>
|
|
1561
1621
|
|
|
1562
1622
|
/** @beta */
|
|
@@ -1565,6 +1625,7 @@ export declare interface PublishDocumentAction<
|
|
|
1565
1625
|
> {
|
|
1566
1626
|
type: 'document.publish'
|
|
1567
1627
|
documentId: string
|
|
1628
|
+
resourceId?: DocumentResourceId
|
|
1568
1629
|
}
|
|
1569
1630
|
|
|
1570
1631
|
/**
|
|
@@ -1651,6 +1712,20 @@ export declare const resolveProject: ResourceAction<
|
|
|
1651
1712
|
Promise<SanityProject_2>
|
|
1652
1713
|
>
|
|
1653
1714
|
|
|
1715
|
+
/**
|
|
1716
|
+
* @beta
|
|
1717
|
+
*/
|
|
1718
|
+
export declare const resolveProjection: ResourceAction<
|
|
1719
|
+
ProjectionStoreState<object>,
|
|
1720
|
+
[ResolveProjectionOptions],
|
|
1721
|
+
Promise<ProjectionValuePending<Record<string, unknown>>>
|
|
1722
|
+
>
|
|
1723
|
+
|
|
1724
|
+
declare interface ResolveProjectionOptions {
|
|
1725
|
+
document: DocumentHandle_2
|
|
1726
|
+
projection: ValidProjection
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1654
1729
|
/** @public */
|
|
1655
1730
|
export declare const resolveProjects: ResourceAction<
|
|
1656
1731
|
FetcherStoreState<[], Omit<SanityProject_2, 'members'>[]>,
|
|
@@ -1666,6 +1741,12 @@ export declare type ResourceAction<TState, TParams extends unknown[], TReturn> =
|
|
|
1666
1741
|
...params: TParams
|
|
1667
1742
|
) => TReturn
|
|
1668
1743
|
|
|
1744
|
+
/**
|
|
1745
|
+
* @public
|
|
1746
|
+
* A resource identifier for a document, in the format of `projectId.dataset`
|
|
1747
|
+
*/
|
|
1748
|
+
export declare type ResourceId = `${string}.${string}`
|
|
1749
|
+
|
|
1669
1750
|
/**
|
|
1670
1751
|
* @public
|
|
1671
1752
|
*/
|
|
@@ -1760,6 +1841,7 @@ export declare interface SdkIdentity {
|
|
|
1760
1841
|
readonly id: string
|
|
1761
1842
|
readonly projectId: string
|
|
1762
1843
|
readonly dataset: string
|
|
1844
|
+
readonly resourceId: ResourceId
|
|
1763
1845
|
}
|
|
1764
1846
|
|
|
1765
1847
|
declare interface SelectAlternativeNode extends BaseNode {
|
|
@@ -1873,7 +1955,7 @@ declare interface TupleNode extends BaseNode {
|
|
|
1873
1955
|
|
|
1874
1956
|
/** @beta */
|
|
1875
1957
|
export declare function unpublishDocument<TDocument extends SanityDocumentLike>(
|
|
1876
|
-
doc:
|
|
1958
|
+
doc: DocumentHandle<TDocument>,
|
|
1877
1959
|
): UnpublishDocumentAction<TDocument>
|
|
1878
1960
|
|
|
1879
1961
|
/** @beta */
|
|
@@ -1882,6 +1964,7 @@ export declare interface UnpublishDocumentAction<
|
|
|
1882
1964
|
> {
|
|
1883
1965
|
type: 'document.unpublish'
|
|
1884
1966
|
documentId: string
|
|
1967
|
+
resourceId?: DocumentResourceId
|
|
1885
1968
|
}
|
|
1886
1969
|
|
|
1887
1970
|
declare interface UnverifiedDocumentRevision {
|
|
@@ -1929,6 +2012,11 @@ export declare interface UsersStoreState {
|
|
|
1929
2012
|
}
|
|
1930
2013
|
}
|
|
1931
2014
|
|
|
2015
|
+
/**
|
|
2016
|
+
* @beta
|
|
2017
|
+
*/
|
|
2018
|
+
export declare type ValidProjection = `{${string}}`
|
|
2019
|
+
|
|
1932
2020
|
/**
|
|
1933
2021
|
* The result of an expression.
|
|
1934
2022
|
*/
|