@sanity/sdk 0.0.0-alpha.14 → 0.0.0-alpha.15
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.d.ts +115 -67
- package/dist/index.js +1118 -1059
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/_exports/index.ts +12 -4
- package/src/client/clientStore.ts +6 -0
- package/src/document/documentConstants.ts +1 -0
- package/src/document/documentStore.test.ts +8 -4
- package/src/document/documentStore.ts +1 -2
- package/src/preview/getPreviewState.ts +3 -3
- package/src/preview/resolvePreview.ts +3 -3
- package/src/projection/getProjectionState.ts +1 -1
- package/src/projection/resolveProjection.ts +1 -1
- package/src/projection/subscribeToStateAndFetchBatches.ts +1 -1
- package/src/query/queryStore.test.ts +379 -0
- package/src/query/queryStore.ts +306 -0
- package/src/query/queryStoreConstants.ts +8 -0
- package/src/query/reducers.test.ts +152 -0
- package/src/query/reducers.ts +75 -0
- package/src/utils/getEnv.ts +1 -1
- package/src/version.ts +8 -0
- package/src/documentList/documentListConstants.ts +0 -2
- package/src/documentList/documentListStore.test.ts +0 -202
- package/src/documentList/documentListStore.ts +0 -113
- package/src/documentList/subscribeToLiveClientAndSetLastLiveEventId.test.ts +0 -109
- package/src/documentList/subscribeToLiveClientAndSetLastLiveEventId.ts +0 -26
- package/src/documentList/subscribeToStateAndFetchResults.test.ts +0 -210
- package/src/documentList/subscribeToStateAndFetchResults.ts +0 -70
package/dist/index.d.ts
CHANGED
|
@@ -14,15 +14,14 @@ import {Observable} from 'rxjs'
|
|
|
14
14
|
import {PatchMutation} from '@sanity/mutate/_unstable_store'
|
|
15
15
|
import {PatchOperations} from '@sanity/types'
|
|
16
16
|
import {PathSegment} from '@sanity/types'
|
|
17
|
+
import {ResponseQueryOptions} from '@sanity/client'
|
|
17
18
|
import {Role} from '@sanity/types'
|
|
18
19
|
import {SanityClient} from '@sanity/client'
|
|
19
20
|
import {SanityDocument} from '@sanity/types'
|
|
20
21
|
import {SanityDocumentLike} from '@sanity/types'
|
|
21
22
|
import {SanityProject as SanityProject_2} from '@sanity/client'
|
|
22
23
|
import {SchemaTypeDefinition} from '@sanity/types'
|
|
23
|
-
import {SortOrderingItem} from '@sanity/types'
|
|
24
24
|
import {Subject} from 'rxjs'
|
|
25
|
-
import {SyncTag} from '@sanity/client'
|
|
26
25
|
|
|
27
26
|
declare interface AccessAttributeNode extends BaseNode {
|
|
28
27
|
type: 'AccessAttribute'
|
|
@@ -357,6 +356,10 @@ export declare interface ClientOptions extends ClientConfig {
|
|
|
357
356
|
* A required string indicating the API version for the client.
|
|
358
357
|
*/
|
|
359
358
|
apiVersion: string
|
|
359
|
+
/**
|
|
360
|
+
* A resource identifier for a document, in the format of `projectId.dataset`
|
|
361
|
+
*/
|
|
362
|
+
resourceId?: ResourceId
|
|
360
363
|
}
|
|
361
364
|
|
|
362
365
|
/**
|
|
@@ -403,6 +406,12 @@ declare interface ContextNode extends BaseNode {
|
|
|
403
406
|
key: string
|
|
404
407
|
}
|
|
405
408
|
|
|
409
|
+
/**
|
|
410
|
+
* This version is provided by pkg-utils at build time
|
|
411
|
+
* @internal
|
|
412
|
+
*/
|
|
413
|
+
export declare const CORE_SDK_VERSION: {}
|
|
414
|
+
|
|
406
415
|
/** @beta */
|
|
407
416
|
export declare function createDocument<TDocument extends SanityDocumentLike>(
|
|
408
417
|
doc: DocumentTypeHandle<TDocument> | DocumentHandle<TDocument>,
|
|
@@ -418,25 +427,6 @@ export declare interface CreateDocumentAction<
|
|
|
418
427
|
documentType: TDocument['_type']
|
|
419
428
|
}
|
|
420
429
|
|
|
421
|
-
/**
|
|
422
|
-
* @public
|
|
423
|
-
*/
|
|
424
|
-
export declare const createDocumentListStore: (instance: SanityInstance | ActionContext<any>) => {
|
|
425
|
-
dispose: () => void
|
|
426
|
-
} & {
|
|
427
|
-
getState: BoundResourceAction<
|
|
428
|
-
[],
|
|
429
|
-
StateSource<{
|
|
430
|
-
results: DocumentHandle_2[]
|
|
431
|
-
isPending: boolean
|
|
432
|
-
count: number
|
|
433
|
-
hasMore: boolean
|
|
434
|
-
}>
|
|
435
|
-
>
|
|
436
|
-
loadMore: BoundResourceAction<[], void>
|
|
437
|
-
setOptions: BoundResourceAction<[options: DocumentListOptions], void>
|
|
438
|
-
}
|
|
439
|
-
|
|
440
430
|
/**
|
|
441
431
|
* Returns a new instance of dependencies required for SanitySDK.
|
|
442
432
|
*
|
|
@@ -655,44 +645,6 @@ export declare interface DocumentHandle<TDocument extends SanityDocumentLike = S
|
|
|
655
645
|
resourceId?: DocumentResourceId
|
|
656
646
|
}
|
|
657
647
|
|
|
658
|
-
/**
|
|
659
|
-
* Represents an identifier to a Sanity document, containing its `_id` to pull
|
|
660
|
-
* the document from content lake and its `_type` to look up its schema type.
|
|
661
|
-
* @public
|
|
662
|
-
*/
|
|
663
|
-
declare interface DocumentHandle_2 {
|
|
664
|
-
_id: string
|
|
665
|
-
_type: string
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
/**
|
|
669
|
-
* Configuration options for filtering and sorting documents in a document list.
|
|
670
|
-
* @public
|
|
671
|
-
*/
|
|
672
|
-
export declare interface DocumentListOptions {
|
|
673
|
-
/** The resourceId of the Sanity instance to use for this list. */
|
|
674
|
-
resourceId?: string
|
|
675
|
-
/** GROQ filter expression to query specific documents */
|
|
676
|
-
filter?: string
|
|
677
|
-
/** Array of sort ordering specifications to determine the order of results */
|
|
678
|
-
sort?: SortOrderingItem[]
|
|
679
|
-
/** The Content Lake perspective to use for this list. Defaults to `drafts`. */
|
|
680
|
-
perspective?: string
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
/**
|
|
684
|
-
* @public
|
|
685
|
-
*/
|
|
686
|
-
export declare interface DocumentListState {
|
|
687
|
-
options: DocumentListOptions
|
|
688
|
-
lastLiveEventId?: string
|
|
689
|
-
syncTags: SyncTag[]
|
|
690
|
-
limit: number
|
|
691
|
-
count: number
|
|
692
|
-
results: DocumentHandle_2[]
|
|
693
|
-
isPending: boolean
|
|
694
|
-
}
|
|
695
|
-
|
|
696
648
|
/**
|
|
697
649
|
* @beta
|
|
698
650
|
* Event emitted when a document is published.
|
|
@@ -1071,7 +1023,7 @@ export declare const getPermissionsState: ResourceAction<
|
|
|
1071
1023
|
>
|
|
1072
1024
|
|
|
1073
1025
|
/**
|
|
1074
|
-
* @
|
|
1026
|
+
* @beta
|
|
1075
1027
|
*/
|
|
1076
1028
|
export declare const getPreviewState: ResourceAction<
|
|
1077
1029
|
PreviewStoreState,
|
|
@@ -1080,10 +1032,10 @@ export declare const getPreviewState: ResourceAction<
|
|
|
1080
1032
|
>
|
|
1081
1033
|
|
|
1082
1034
|
/**
|
|
1083
|
-
* @
|
|
1035
|
+
* @beta
|
|
1084
1036
|
*/
|
|
1085
1037
|
export declare interface GetPreviewStateOptions {
|
|
1086
|
-
document:
|
|
1038
|
+
document: DocumentHandle
|
|
1087
1039
|
}
|
|
1088
1040
|
|
|
1089
1041
|
/**
|
|
@@ -1103,7 +1055,7 @@ export declare function getProjectionState(
|
|
|
1103
1055
|
): StateSource<ProjectionValuePending<Record<string, unknown>>>
|
|
1104
1056
|
|
|
1105
1057
|
declare interface GetProjectionStateOptions {
|
|
1106
|
-
document:
|
|
1058
|
+
document: DocumentHandle
|
|
1107
1059
|
projection: ValidProjection
|
|
1108
1060
|
}
|
|
1109
1061
|
|
|
@@ -1121,6 +1073,38 @@ export declare const getProjectState: ResourceAction<
|
|
|
1121
1073
|
StateSource<SanityProject_2 | undefined>
|
|
1122
1074
|
>
|
|
1123
1075
|
|
|
1076
|
+
/** @beta */
|
|
1077
|
+
export declare const getQueryKey: (query: string, options?: QueryOptions) => string
|
|
1078
|
+
|
|
1079
|
+
/**
|
|
1080
|
+
* Returns the state source for a query.
|
|
1081
|
+
*
|
|
1082
|
+
* This function returns a state source that represents the current result of a GROQ query.
|
|
1083
|
+
* Subscribing to the state source will instruct the SDK to fetch the query (if not already fetched)
|
|
1084
|
+
* and will keep the query live using the Live content API (considering sync tags) to provide up-to-date results.
|
|
1085
|
+
* When the last subscriber is removed, the query state is automatically cleaned up from the store.
|
|
1086
|
+
*
|
|
1087
|
+
* Note: This functionality is for advanced users who want to build their own framework integrations.
|
|
1088
|
+
* Our SDK also provides a React integration (useQuery hook) for convenient usage.
|
|
1089
|
+
*
|
|
1090
|
+
* Note: Automatic cleanup can interfere with React Suspense because if a component suspends while being the only subscriber,
|
|
1091
|
+
* cleanup might occur unexpectedly. In such cases, consider using `resolveQuery` instead.
|
|
1092
|
+
*
|
|
1093
|
+
* @beta
|
|
1094
|
+
*/
|
|
1095
|
+
export declare function getQueryState<T>(
|
|
1096
|
+
instance: SanityInstance | ActionContext<QueryStoreState>,
|
|
1097
|
+
query: string,
|
|
1098
|
+
options?: QueryOptions,
|
|
1099
|
+
): StateSource<T | undefined>
|
|
1100
|
+
|
|
1101
|
+
/** @beta */
|
|
1102
|
+
export declare function getQueryState(
|
|
1103
|
+
instance: SanityInstance | ActionContext<QueryStoreState>,
|
|
1104
|
+
query: string,
|
|
1105
|
+
options?: QueryOptions,
|
|
1106
|
+
): StateSource<unknown>
|
|
1107
|
+
|
|
1124
1108
|
/**
|
|
1125
1109
|
* @beta
|
|
1126
1110
|
* Get the resource ID from a document resource ID
|
|
@@ -1448,6 +1432,12 @@ declare type ParseBracket<TInput extends string> = TInput extends `[${infer TPar
|
|
|
1448
1432
|
? [ToNumber<TPart>, ...ParseSegment<TRest>]
|
|
1449
1433
|
: []
|
|
1450
1434
|
|
|
1435
|
+
/** @beta */
|
|
1436
|
+
export declare const parseQueryKey: (key: string) => {
|
|
1437
|
+
query: string
|
|
1438
|
+
options: QueryOptions
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1451
1441
|
/**
|
|
1452
1442
|
* Parse a single “segment” that may include bracket parts.
|
|
1453
1443
|
*
|
|
@@ -1628,6 +1618,30 @@ export declare interface PublishDocumentAction<
|
|
|
1628
1618
|
resourceId?: DocumentResourceId
|
|
1629
1619
|
}
|
|
1630
1620
|
|
|
1621
|
+
/**
|
|
1622
|
+
* @beta
|
|
1623
|
+
*/
|
|
1624
|
+
export declare interface QueryOptions
|
|
1625
|
+
extends Pick<ResponseQueryOptions, 'perspective' | 'useCdn' | 'cache' | 'next' | 'cacheMode'>,
|
|
1626
|
+
Pick<ClientOptions, 'scope' | 'resourceId'> {
|
|
1627
|
+
params?: Record<string, unknown>
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
declare interface QueryState {
|
|
1631
|
+
syncTags?: string[]
|
|
1632
|
+
result?: unknown
|
|
1633
|
+
error?: unknown
|
|
1634
|
+
lastLiveEventId?: string
|
|
1635
|
+
subscribers: string[]
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
declare interface QueryStoreState {
|
|
1639
|
+
queries: {
|
|
1640
|
+
[key: string]: QueryState | undefined
|
|
1641
|
+
}
|
|
1642
|
+
error?: unknown
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1631
1645
|
/**
|
|
1632
1646
|
* Represents a transaction that is queued to be applied but has not yet been
|
|
1633
1647
|
* applied. A transaction will remain in a queued state until all required
|
|
@@ -1690,7 +1704,7 @@ export declare const resolvePermissions: ResourceAction<
|
|
|
1690
1704
|
>
|
|
1691
1705
|
|
|
1692
1706
|
/**
|
|
1693
|
-
* @
|
|
1707
|
+
* @beta
|
|
1694
1708
|
*/
|
|
1695
1709
|
export declare const resolvePreview: ResourceAction<
|
|
1696
1710
|
PreviewStoreState,
|
|
@@ -1699,10 +1713,10 @@ export declare const resolvePreview: ResourceAction<
|
|
|
1699
1713
|
>
|
|
1700
1714
|
|
|
1701
1715
|
/**
|
|
1702
|
-
* @
|
|
1716
|
+
* @beta
|
|
1703
1717
|
*/
|
|
1704
1718
|
export declare interface ResolvePreviewOptions {
|
|
1705
|
-
document:
|
|
1719
|
+
document: DocumentHandle
|
|
1706
1720
|
}
|
|
1707
1721
|
|
|
1708
1722
|
/** @public */
|
|
@@ -1722,7 +1736,7 @@ export declare const resolveProjection: ResourceAction<
|
|
|
1722
1736
|
>
|
|
1723
1737
|
|
|
1724
1738
|
declare interface ResolveProjectionOptions {
|
|
1725
|
-
document:
|
|
1739
|
+
document: DocumentHandle
|
|
1726
1740
|
projection: ValidProjection
|
|
1727
1741
|
}
|
|
1728
1742
|
|
|
@@ -1733,6 +1747,40 @@ export declare const resolveProjects: ResourceAction<
|
|
|
1733
1747
|
Promise<Omit<SanityProject_2, 'members'>[]>
|
|
1734
1748
|
>
|
|
1735
1749
|
|
|
1750
|
+
/**
|
|
1751
|
+
* Resolves the result of a query without registering a lasting subscriber.
|
|
1752
|
+
*
|
|
1753
|
+
* This function fetches the result of a GROQ query and returns a promise that resolves with the query result.
|
|
1754
|
+
* Unlike `getQueryState`, which registers subscribers to keep the query live and performs automatic cleanup,
|
|
1755
|
+
* `resolveQuery` does not track subscribers. This makes it ideal for use with React Suspense, where the returned
|
|
1756
|
+
* promise is thrown to delay rendering until the query result becomes available.
|
|
1757
|
+
* Once the promise resolves, it is expected that a real subscriber will be added via `getQueryState` to manage ongoing updates.
|
|
1758
|
+
*
|
|
1759
|
+
* Additionally, an optional AbortSignal can be provided to cancel the query and immediately clear the associated state
|
|
1760
|
+
* if there are no active subscribers.
|
|
1761
|
+
*
|
|
1762
|
+
* @beta
|
|
1763
|
+
*/
|
|
1764
|
+
export declare function resolveQuery<T>(
|
|
1765
|
+
instance: SanityInstance | ActionContext<QueryStoreState>,
|
|
1766
|
+
query: string,
|
|
1767
|
+
options?: ResolveQueryOptions,
|
|
1768
|
+
): Promise<T>
|
|
1769
|
+
|
|
1770
|
+
/** @beta */
|
|
1771
|
+
export declare function resolveQuery(
|
|
1772
|
+
instance: SanityInstance | ActionContext<QueryStoreState>,
|
|
1773
|
+
query: string,
|
|
1774
|
+
options?: ResolveQueryOptions,
|
|
1775
|
+
): Promise<unknown>
|
|
1776
|
+
|
|
1777
|
+
/**
|
|
1778
|
+
* @beta
|
|
1779
|
+
*/
|
|
1780
|
+
declare interface ResolveQueryOptions extends QueryOptions {
|
|
1781
|
+
signal?: AbortSignal
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1736
1784
|
/**
|
|
1737
1785
|
* @public
|
|
1738
1786
|
*/
|