@sanity/sdk 0.0.0-alpha.21 → 0.0.0-alpha.23

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.
Files changed (127) hide show
  1. package/dist/index.d.ts +428 -325
  2. package/dist/index.js +1618 -1553
  3. package/dist/index.js.map +1 -1
  4. package/package.json +6 -7
  5. package/src/_exports/index.ts +31 -30
  6. package/src/auth/authStore.test.ts +149 -104
  7. package/src/auth/authStore.ts +51 -100
  8. package/src/auth/handleAuthCallback.test.ts +67 -34
  9. package/src/auth/handleAuthCallback.ts +8 -7
  10. package/src/auth/logout.test.ts +61 -29
  11. package/src/auth/logout.ts +26 -28
  12. package/src/auth/refreshStampedToken.test.ts +9 -9
  13. package/src/auth/refreshStampedToken.ts +62 -56
  14. package/src/auth/subscribeToStateAndFetchCurrentUser.test.ts +5 -5
  15. package/src/auth/subscribeToStateAndFetchCurrentUser.ts +45 -47
  16. package/src/auth/subscribeToStorageEventsAndSetToken.test.ts +4 -5
  17. package/src/auth/subscribeToStorageEventsAndSetToken.ts +22 -24
  18. package/src/client/clientStore.test.ts +131 -67
  19. package/src/client/clientStore.ts +117 -116
  20. package/src/comlink/controller/actions/destroyController.test.ts +38 -13
  21. package/src/comlink/controller/actions/destroyController.ts +11 -15
  22. package/src/comlink/controller/actions/getOrCreateChannel.test.ts +56 -27
  23. package/src/comlink/controller/actions/getOrCreateChannel.ts +37 -35
  24. package/src/comlink/controller/actions/getOrCreateController.test.ts +27 -16
  25. package/src/comlink/controller/actions/getOrCreateController.ts +23 -22
  26. package/src/comlink/controller/actions/releaseChannel.test.ts +37 -13
  27. package/src/comlink/controller/actions/releaseChannel.ts +22 -21
  28. package/src/comlink/controller/comlinkControllerStore.test.ts +65 -36
  29. package/src/comlink/controller/comlinkControllerStore.ts +44 -5
  30. package/src/comlink/node/actions/getOrCreateNode.test.ts +31 -15
  31. package/src/comlink/node/actions/getOrCreateNode.ts +30 -29
  32. package/src/comlink/node/actions/releaseNode.test.ts +75 -55
  33. package/src/comlink/node/actions/releaseNode.ts +19 -21
  34. package/src/comlink/node/comlinkNodeStore.test.ts +6 -11
  35. package/src/comlink/node/comlinkNodeStore.ts +22 -5
  36. package/src/config/authConfig.ts +79 -0
  37. package/src/config/sanityConfig.ts +48 -0
  38. package/src/datasets/datasets.test.ts +2 -2
  39. package/src/datasets/datasets.ts +18 -5
  40. package/src/document/actions.test.ts +22 -10
  41. package/src/document/actions.ts +44 -56
  42. package/src/document/applyDocumentActions.test.ts +96 -36
  43. package/src/document/applyDocumentActions.ts +140 -99
  44. package/src/document/documentStore.test.ts +103 -155
  45. package/src/document/documentStore.ts +247 -237
  46. package/src/document/listen.ts +56 -55
  47. package/src/document/patchOperations.ts +0 -43
  48. package/src/document/permissions.test.ts +25 -12
  49. package/src/document/permissions.ts +11 -4
  50. package/src/document/processActions.test.ts +41 -8
  51. package/src/document/reducers.test.ts +87 -16
  52. package/src/document/reducers.ts +2 -2
  53. package/src/document/sharedListener.test.ts +34 -16
  54. package/src/document/sharedListener.ts +33 -11
  55. package/src/preview/getPreviewState.test.ts +40 -39
  56. package/src/preview/getPreviewState.ts +68 -56
  57. package/src/preview/previewConstants.ts +43 -0
  58. package/src/preview/previewQuery.test.ts +1 -1
  59. package/src/preview/previewQuery.ts +4 -5
  60. package/src/preview/previewStore.test.ts +13 -58
  61. package/src/preview/previewStore.ts +7 -21
  62. package/src/preview/resolvePreview.test.ts +33 -104
  63. package/src/preview/resolvePreview.ts +11 -21
  64. package/src/preview/subscribeToStateAndFetchBatches.test.ts +96 -97
  65. package/src/preview/subscribeToStateAndFetchBatches.ts +85 -81
  66. package/src/preview/util.ts +1 -0
  67. package/src/project/project.test.ts +3 -3
  68. package/src/project/project.ts +28 -5
  69. package/src/projection/getProjectionState.test.ts +69 -49
  70. package/src/projection/getProjectionState.ts +42 -50
  71. package/src/projection/projectionQuery.ts +1 -1
  72. package/src/projection/projectionStore.test.ts +13 -51
  73. package/src/projection/projectionStore.ts +6 -18
  74. package/src/projection/resolveProjection.test.ts +32 -127
  75. package/src/projection/resolveProjection.ts +15 -28
  76. package/src/projection/subscribeToStateAndFetchBatches.test.ts +105 -90
  77. package/src/projection/subscribeToStateAndFetchBatches.ts +94 -81
  78. package/src/projection/util.ts +2 -0
  79. package/src/projects/projects.test.ts +13 -4
  80. package/src/projects/projects.ts +6 -1
  81. package/src/query/queryStore.test.ts +10 -47
  82. package/src/query/queryStore.ts +151 -133
  83. package/src/query/queryStoreConstants.ts +2 -0
  84. package/src/store/createActionBinder.test.ts +153 -0
  85. package/src/store/createActionBinder.ts +176 -0
  86. package/src/store/createSanityInstance.test.ts +84 -0
  87. package/src/store/createSanityInstance.ts +124 -0
  88. package/src/store/createStateSourceAction.test.ts +196 -0
  89. package/src/store/createStateSourceAction.ts +260 -0
  90. package/src/store/createStoreInstance.test.ts +81 -0
  91. package/src/store/createStoreInstance.ts +80 -0
  92. package/src/store/createStoreState.test.ts +85 -0
  93. package/src/store/createStoreState.ts +92 -0
  94. package/src/store/defineStore.test.ts +18 -0
  95. package/src/store/defineStore.ts +81 -0
  96. package/src/users/reducers.test.ts +318 -0
  97. package/src/users/reducers.ts +88 -0
  98. package/src/users/types.ts +46 -4
  99. package/src/users/usersConstants.ts +4 -0
  100. package/src/users/usersStore.test.ts +350 -223
  101. package/src/users/usersStore.ts +285 -149
  102. package/src/utils/createFetcherStore.test.ts +6 -7
  103. package/src/utils/createFetcherStore.ts +150 -153
  104. package/src/{common/util.test.ts → utils/hashString.test.ts} +1 -1
  105. package/src/auth/fetchLoginUrls.test.ts +0 -163
  106. package/src/auth/fetchLoginUrls.ts +0 -74
  107. package/src/common/createLiveEventSubscriber.test.ts +0 -121
  108. package/src/common/createLiveEventSubscriber.ts +0 -55
  109. package/src/common/types.ts +0 -4
  110. package/src/instance/identity.test.ts +0 -46
  111. package/src/instance/identity.ts +0 -29
  112. package/src/instance/sanityInstance.test.ts +0 -77
  113. package/src/instance/sanityInstance.ts +0 -57
  114. package/src/instance/types.ts +0 -37
  115. package/src/preview/getPreviewProjection.ts +0 -45
  116. package/src/resources/README.md +0 -370
  117. package/src/resources/createAction.test.ts +0 -101
  118. package/src/resources/createAction.ts +0 -44
  119. package/src/resources/createResource.test.ts +0 -112
  120. package/src/resources/createResource.ts +0 -102
  121. package/src/resources/createStateSourceAction.test.ts +0 -114
  122. package/src/resources/createStateSourceAction.ts +0 -83
  123. package/src/resources/createStore.test.ts +0 -67
  124. package/src/resources/createStore.ts +0 -46
  125. package/src/store/createStore.test.ts +0 -108
  126. package/src/store/createStore.ts +0 -106
  127. /package/src/{common/util.ts → utils/hashString.ts} +0 -0
package/dist/index.d.ts CHANGED
@@ -1,9 +1,14 @@
1
+ import {AuthStoreState as AuthStoreState_2} from './authStore'
2
+ import {BoundStoreAction} from '../store/createActionBinder'
3
+ import {BoundStoreAction as BoundStoreAction_2} from '../../store/createActionBinder'
1
4
  import {ChannelInput} from '@sanity/comlink'
2
5
  import {ChannelInstance} from '@sanity/comlink'
3
6
  import {ClientConfig} from '@sanity/client'
4
7
  import {Controller} from '@sanity/comlink'
5
8
  import {CurrentUser} from '@sanity/types'
6
9
  import {DatasetsResponse} from '@sanity/client'
10
+ import {DocumentPermissionsResult as DocumentPermissionsResult_2} from './permissions'
11
+ import {FetcherStoreState as FetcherStoreState_2} from '../_exports'
7
12
  import {IndexTuple} from '@sanity/types'
8
13
  import {ListenEvent} from '@sanity/client'
9
14
  import {Message} from '@sanity/comlink'
@@ -14,13 +19,20 @@ import {Observable} from 'rxjs'
14
19
  import {PatchMutation} from '@sanity/mutate/_unstable_store'
15
20
  import {PatchOperations} from '@sanity/types'
16
21
  import {PathSegment} from '@sanity/types'
22
+ import {PreviewStoreState as PreviewStoreState_2} from './previewStore'
23
+ import {ProjectionStoreState} from './projectionStore'
24
+ import {ProjectionValuePending as ProjectionValuePending_2} from './projectionStore'
17
25
  import {ResponseQueryOptions} from '@sanity/client'
18
26
  import {Role} from '@sanity/types'
19
27
  import {SanityClient} from '@sanity/client'
20
28
  import {SanityDocument} from '@sanity/types'
29
+ import {SanityDocument as SanityDocument_2} from '@sanity/client'
21
30
  import {SanityDocumentLike} from '@sanity/types'
22
31
  import {SanityProject as SanityProject_2} from '@sanity/client'
32
+ import {SanityUser as SanityUser_2} from './types'
33
+ import {StateSource as StateSource_2} from '../_exports'
23
34
  import {Subject} from 'rxjs'
35
+ import {ValuePending as ValuePending_2} from './previewStore'
24
36
 
25
37
  declare interface AccessAttributeNode extends BaseNode {
26
38
  type: 'AccessAttribute'
@@ -34,12 +46,6 @@ declare interface AccessElementNode extends BaseNode {
34
46
  index: number
35
47
  }
36
48
 
37
- /** @public */
38
- export declare interface ActionContext<TState> {
39
- instance: SanityInstance
40
- state: ResourceState<TState>
41
- }
42
-
43
49
  /**
44
50
  * @beta
45
51
  * Event emitted when a precondition to applying an action fails.
@@ -76,6 +82,20 @@ export declare interface ActionsResult<TDocument extends SanityDocument = Sanity
76
82
  submitted: () => ReturnType<SanityClient['action']>
77
83
  }
78
84
 
85
+ declare type AllowedClientConfigKey =
86
+ | 'useCdn'
87
+ | 'token'
88
+ | 'perspective'
89
+ | 'apiHost'
90
+ | 'proxy'
91
+ | 'withCredentials'
92
+ | 'timeout'
93
+ | 'maxRetries'
94
+ | 'dataset'
95
+ | 'projectId'
96
+ | 'requestTagPrefix'
97
+ | 'useProjectHostname'
98
+
79
99
  declare interface AndNode extends BaseNode {
80
100
  type: 'And'
81
101
  left: ExprNode
@@ -147,14 +167,14 @@ declare interface AppliedTransaction extends QueuedTransaction {
147
167
 
148
168
  /** @beta */
149
169
  export declare function applyDocumentActions<TDocument extends SanityDocument>(
150
- instance: SanityInstance | ActionContext<DocumentStoreState>,
170
+ instance: SanityInstance,
151
171
  action: DocumentAction<TDocument> | DocumentAction<TDocument>[],
152
172
  options?: ApplyDocumentActionsOptions,
153
173
  ): Promise<ActionsResult<TDocument>>
154
174
 
155
175
  /** @beta */
156
176
  export declare function applyDocumentActions(
157
- instance: SanityInstance | ActionContext<DocumentStoreState>,
177
+ instance: SanityInstance,
158
178
  action: DocumentAction | DocumentAction[],
159
179
  options?: ApplyDocumentActionsOptions,
160
180
  ): Promise<ActionsResult>
@@ -299,6 +319,7 @@ export declare interface AuthStoreState {
299
319
  storageKey: string
300
320
  storageArea: Storage | undefined
301
321
  apiHost: string | undefined
322
+ loginUrl: string
302
323
  callbackUrl: string | undefined
303
324
  providedToken: string | undefined
304
325
  }
@@ -313,9 +334,10 @@ declare interface BaseNode {
313
334
  declare type BooleanValue = StaticValue<boolean, 'boolean'>
314
335
 
315
336
  /**
316
- * @public
337
+ * Represents a store action that has been bound to a specific store instance
317
338
  */
318
- export declare type BoundResourceAction<TParams extends unknown[], TReturn> = (
339
+ declare type BoundStoreAction_3<_TState, TParams extends unknown[], TReturn> = (
340
+ instance: SanityInstance,
319
341
  ...params: TParams
320
342
  ) => TReturn
321
343
 
@@ -339,27 +361,25 @@ declare interface ChannelEntry {
339
361
  * ('project') and the global client ('global'). When set to `'global'`, the
340
362
  * global client is used.
341
363
  *
342
- * These options are utilized by `getClient` and `getClientState` to return a memoized
343
- * client instance, ensuring that clients are reused for identical configurations and that
344
- * updates (such as auth token changes) propagate correctly.
364
+ * These options are utilized by `getClient` and `getClientState` to configure and
365
+ * return appropriate client instances that automatically handle authentication
366
+ * updates and configuration changes.
345
367
  *
346
368
  * @public
347
369
  */
348
- export declare interface ClientOptions extends ClientConfig {
370
+ export declare interface ClientOptions
371
+ extends Pick<ClientConfig, AllowedClientConfigKey>,
372
+ DatasetHandle {
349
373
  /**
350
- * An optional flag to choose between the project-specific client ('project')
374
+ * An optional flag to choose between the default client (typically project-level)
351
375
  * and the global client ('global'). When set to `'global'`, the global client
352
376
  * is used.
353
377
  */
354
- scope?: 'project' | 'global'
378
+ scope?: 'default' | 'global'
355
379
  /**
356
380
  * A required string indicating the API version for the client.
357
381
  */
358
382
  apiVersion: string
359
- /**
360
- * A resource identifier for a document, in the format of `projectId.dataset`
361
- */
362
- resourceId?: ResourceId
363
383
  }
364
384
 
365
385
  /**
@@ -367,8 +387,10 @@ export declare interface ClientOptions extends ClientConfig {
367
387
  * @public
368
388
  */
369
389
  export declare interface ClientState {
370
- defaultClient: SanityClient
371
- defaultGlobalClient: SanityClient
390
+ token: string | null
391
+ clients: {
392
+ [TKey in string]?: SanityClient
393
+ }
372
394
  }
373
395
 
374
396
  /**
@@ -414,70 +436,25 @@ export declare const CORE_SDK_VERSION: {}
414
436
 
415
437
  /** @beta */
416
438
  export declare function createDocument<TDocument extends SanityDocumentLike>(
417
- doc: DocumentTypeHandle<TDocument> | DocumentHandle<TDocument>,
439
+ doc: DocumentTypeHandle<TDocument>,
418
440
  ): CreateDocumentAction<TDocument>
419
441
 
420
442
  /** @beta */
421
443
  export declare interface CreateDocumentAction<
422
444
  TDocument extends SanityDocumentLike = SanityDocumentLike,
423
- > {
445
+ > extends DocumentTypeHandle<TDocument> {
424
446
  type: 'document.create'
425
- documentId?: string
426
- resourceId?: DocumentResourceId
427
- documentType: TDocument['_type']
428
447
  }
429
448
 
430
449
  /**
431
- * Returns a new instance of dependencies required for SanitySDK.
450
+ * Creates a new Sanity resource instance
451
+ * @param config - Configuration for the instance (optional)
452
+ * @returns A configured SanityInstance
453
+ * @remarks When creating child instances, configurations are merged with parent values
432
454
  *
433
455
  * @public
434
- *
435
- * @param config - The configuration for this instance
436
- *
437
- * @returns A new "instance" of a Sanity SDK, used to bind resources/configuration to it
438
456
  */
439
- export declare function createSanityInstance({
440
- projectId,
441
- dataset,
442
- ...config
443
- }: SanityConfig): SanityInstance
444
-
445
- /**
446
- * @public
447
- */
448
- export declare const createUsersStore: (instance: SanityInstance | ActionContext<any>) => {
449
- dispose: () => void
450
- } & {
451
- getState: BoundResourceAction<
452
- [],
453
- StateSource<{
454
- users: SanityUser[]
455
- totalCount: number
456
- nextCursor: string | null
457
- hasMore: boolean
458
- options: {
459
- resourceType: ResourceType
460
- resourceId: string
461
- /**
462
- * The maximum number of users to fetch. [Default: 100]
463
- */
464
- limit?: number
465
- }
466
- initialFetchCompleted: boolean
467
- }>
468
- >
469
- loadMore: BoundResourceAction<[], Promise<void>>
470
- resolveUsers: BoundResourceAction<[], Promise<SanityUserResponse>>
471
- setOptions: BoundResourceAction<
472
- [
473
- options: {
474
- resourceType: 'organization' | 'project'
475
- resourceId: string
476
- },
477
- ],
478
- void
479
- >
480
- }
457
+ export declare function createSanityInstance(config?: SanityConfig): SanityInstance
481
458
 
482
459
  export {CurrentUser}
483
460
 
@@ -492,6 +469,13 @@ declare interface DashboardContext {
492
469
  orgId?: string
493
470
  }
494
471
 
472
+ /**
473
+ * @public
474
+ */
475
+ export declare interface DatasetHandle extends ProjectHandle {
476
+ dataset?: string | undefined
477
+ }
478
+
495
479
  declare class DateTime {
496
480
  date: Date
497
481
  constructor(date: Date)
@@ -532,11 +516,9 @@ export declare function deleteDocument<TDocument extends SanityDocumentLike>(
532
516
 
533
517
  /** @beta */
534
518
  export declare interface DeleteDocumentAction<
535
- _TDocument extends SanityDocumentLike = SanityDocumentLike,
536
- > {
519
+ TDocument extends SanityDocumentLike = SanityDocumentLike,
520
+ > extends DocumentHandle<TDocument> {
537
521
  type: 'document.delete'
538
- documentId: string
539
- resourceId?: DocumentResourceId
540
522
  }
541
523
 
542
524
  declare type DereferenceFunction = (obj: {
@@ -557,9 +539,7 @@ declare interface DescNode extends BaseNode {
557
539
  * Calls the destroy method on the controller and resets the controller state.
558
540
  * @public
559
541
  */
560
- export declare const destroyController: (
561
- actionContext: ActionContext<ComlinkControllerState>,
562
- ) => void
542
+ export declare const destroyController: BoundStoreAction_2<ComlinkControllerState, [], void>
563
543
 
564
544
  /** @beta */
565
545
  export declare function discardDocument<TDocument extends SanityDocumentLike>(
@@ -568,11 +548,9 @@ export declare function discardDocument<TDocument extends SanityDocumentLike>(
568
548
 
569
549
  /** @beta */
570
550
  export declare interface DiscardDocumentAction<
571
- _TDocument extends SanityDocumentLike = SanityDocumentLike,
572
- > {
551
+ TDocument extends SanityDocumentLike = SanityDocumentLike,
552
+ > extends DocumentHandle<TDocument> {
573
553
  type: 'document.discard'
574
- documentId: string
575
- resourceId?: DocumentResourceId
576
554
  }
577
555
 
578
556
  declare type Document_2 = {
@@ -644,16 +622,15 @@ export declare type DocumentEvent =
644
622
  | DocumentDiscardedEvent
645
623
 
646
624
  /**
647
- * @beta
625
+ * @public
648
626
  * A minimal set of metadata for a given document, comprising the document's ID and type.
649
627
  * Used by most document-related hooks (such as {@link usePreview}, {@link useDocument}, and {@link useEditDocument})
650
628
  * to reference a particular document without fetching the entire document upfront.
651
629
  * @category Types
652
630
  */
653
- export declare interface DocumentHandle<TDocument extends SanityDocumentLike = SanityDocumentLike> {
654
- _id: string
655
- _type: TDocument['_type']
656
- resourceId?: DocumentResourceId
631
+ export declare interface DocumentHandle<TDocument extends SanityDocumentLike = SanityDocumentLike>
632
+ extends DocumentTypeHandle<TDocument> {
633
+ documentId: string
657
634
  }
658
635
 
659
636
  /** @beta */
@@ -691,12 +668,6 @@ declare interface DocumentRebaseErrorEvent {
691
668
  error: unknown
692
669
  }
693
670
 
694
- /**
695
- * @beta
696
- * A resource identifier for a document, in the format of `document:${projectId}.${dataset}:${documentId}`
697
- */
698
- export declare type DocumentResourceId = `document:${string}.${string}:${string}`
699
-
700
671
  /**
701
672
  * Represents a set of document that will go into `applyMutations`. Before
702
673
  * applying a mutation, it's expected that all relevant documents that the
@@ -753,18 +724,17 @@ declare interface DocumentStoreState {
753
724
  outgoing?: OutgoingTransaction
754
725
  grants?: Record<Grant, ExprNode>
755
726
  error?: unknown
756
- sharedListener: Observable<ListenEvent<SanityDocument>>
727
+ sharedListener: SharedListener
757
728
  fetchDocument: (documentId: string) => Observable<SanityDocument | null>
758
729
  events: Subject<DocumentEvent>
759
730
  }
760
731
 
761
- /** @beta */
732
+ /** @public */
762
733
  export declare interface DocumentTypeHandle<
763
734
  TDocument extends SanityDocumentLike = SanityDocumentLike,
764
- > {
765
- _id?: string
766
- _type: TDocument['_type']
767
- resourceId?: DocumentResourceId
735
+ > extends DatasetHandle {
736
+ documentId?: string
737
+ documentType: TDocument['_type']
768
738
  }
769
739
 
770
740
  /**
@@ -779,6 +749,7 @@ export declare interface DocumentUnpublishedEvent {
779
749
 
780
750
  /** @beta */
781
751
  export declare function editDocument<TDocument extends SanityDocumentLike>(
752
+ doc: DocumentHandle<TDocument>,
782
753
  sanityMutatePatch: PatchMutation,
783
754
  ): EditDocumentAction<TDocument>
784
755
 
@@ -790,11 +761,9 @@ export declare function editDocument<TDocument extends SanityDocumentLike>(
790
761
 
791
762
  /** @beta */
792
763
  export declare interface EditDocumentAction<
793
- _TDocument extends SanityDocumentLike = SanityDocumentLike,
794
- > {
764
+ TDocument extends SanityDocumentLike = SanityDocumentLike,
765
+ > extends DocumentHandle<TDocument> {
795
766
  type: 'document.edit'
796
- documentId: string
797
- resourceId?: DocumentResourceId
798
767
  patches?: PatchOperations[]
799
768
  }
800
769
 
@@ -856,12 +825,12 @@ declare type ExprNode =
856
825
  * @public
857
826
  */
858
827
  export declare interface FetcherStore<TParams extends unknown[], TData> {
859
- getState: ResourceAction<
828
+ getState: BoundStoreAction_3<
860
829
  FetcherStoreState<TParams, TData>,
861
830
  TParams,
862
831
  StateSource<TData | undefined>
863
832
  >
864
- resolveState: ResourceAction<FetcherStoreState<TParams, TData>, TParams, Promise<TData>>
833
+ resolveState: BoundStoreAction_3<FetcherStoreState<TParams, TData>, TParams, Promise<TData>>
865
834
  }
866
835
 
867
836
  /**
@@ -875,21 +844,6 @@ export declare interface FetcherStoreState<TParams extends unknown[], TData> {
875
844
  error?: unknown
876
845
  }
877
846
 
878
- /**
879
- * @public
880
- */
881
- export declare const fetchLoginUrls: ResourceAction<
882
- AuthStoreState,
883
- [],
884
- Promise<
885
- {
886
- url: string
887
- name: string
888
- title: string
889
- }[]
890
- >
891
- >
892
-
893
847
  declare interface FilterNode extends BaseNode {
894
848
  type: 'Filter'
895
849
  base: ExprNode
@@ -919,60 +873,63 @@ declare interface FuncCallNode extends BaseNode {
919
873
  /**
920
874
  * @public
921
875
  */
922
- export declare const getAuthState: ResourceAction<AuthStoreState, [], StateSource<AuthState>>
876
+ export declare const getAuthState: BoundStoreAction<AuthStoreState, [], StateSource_2<AuthState>>
923
877
 
924
878
  /**
925
- * Retrieves a memoized Sanity client instance configured with the provided options.
879
+ * Retrieves a Sanity client instance configured with the provided options.
926
880
  *
927
- * This function uses a memoized selector to return a client instance from the
928
- * client store, based on the default project or global client. The selector
929
- * leverages a WeakMap-based cache and reselect to ensure that clients with the
930
- * same configuration are reused, and that updates, such as authentication token
931
- * changes, propagate automatically.
881
+ * This function returns a client instance configured for the project or as a
882
+ * global client based on the options provided. It ensures efficient reuse of
883
+ * client instances by returning the same instance for the same options.
884
+ * For automatic handling of authentication token updates, consider using
885
+ * `getClientState`.
932
886
  *
933
887
  * @public
934
888
  */
935
- export declare const getClient: ResourceAction<ClientState, [options: ClientOptions], SanityClient>
889
+ export declare const getClient: BoundStoreAction<
890
+ ClientState,
891
+ [options: ClientOptions],
892
+ SanityClient
893
+ >
936
894
 
937
895
  /**
938
896
  * Returns a state source for the Sanity client instance.
939
897
  *
940
898
  * This function provides a subscribable state source that emits updated client
941
- * instances whenever the client configuration changes (for example, due to
942
- * token updates). It leverages the underlying client store and memoized selector
943
- * to ensure that subscribers receive the most current client configuration.
899
+ * instances whenever relevant configurations change (such as authentication tokens).
900
+ * Use this when you need to react to client configuration changes in your application.
944
901
  *
945
902
  * @public
946
903
  */
947
- export declare const getClientState: ResourceAction<
904
+ export declare const getClientState: BoundStoreAction<
948
905
  ClientState,
949
906
  [options: ClientOptions],
950
- StateSource<SanityClient>
907
+ StateSource_2<SanityClient>
951
908
  >
952
909
 
953
910
  /**
954
911
  * @public
955
912
  */
956
- export declare const getCurrentUserState: ResourceAction<
913
+ export declare const getCurrentUserState: BoundStoreAction<
957
914
  AuthStoreState,
958
915
  [],
959
- StateSource<CurrentUser | null>
916
+ StateSource_2<CurrentUser | null>
960
917
  >
961
918
 
962
919
  /**
963
920
  * @public
964
921
  */
965
- export declare const getDashboardOrganizationId: ResourceAction<
922
+ export declare const getDashboardOrganizationId: BoundStoreAction<
966
923
  AuthStoreState,
967
924
  [],
968
- StateSource<string | undefined>
925
+ StateSource_2<string | undefined>
969
926
  >
970
927
 
971
928
  /** @public */
972
- export declare const getDatasetsState: ResourceAction<
973
- FetcherStoreState<[], DatasetsResponse>,
974
- [],
975
- StateSource<DatasetsResponse | undefined>
929
+ export declare const getDatasetsState: BoundStoreAction<
930
+ FetcherStoreState_2<[options?: ProjectHandle | undefined], DatasetsResponse>,
931
+ [options?: ProjectHandle | undefined],
932
+ StateSource_2<DatasetsResponse | undefined>
976
933
  >
977
934
 
978
935
  /** @beta */
@@ -980,26 +937,26 @@ export declare function getDocumentState<
980
937
  TDocument extends SanityDocument,
981
938
  TPath extends JsonMatchPath<TDocument>,
982
939
  >(
983
- instance: SanityInstance | ActionContext<DocumentStoreState>,
940
+ instance: SanityInstance,
984
941
  doc: string | DocumentHandle<TDocument>,
985
942
  path: TPath,
986
943
  ): StateSource<JsonMatch<TDocument, TPath> | undefined>
987
944
 
988
945
  /** @beta */
989
946
  export declare function getDocumentState<TDocument extends SanityDocument>(
990
- instance: SanityInstance | ActionContext<DocumentStoreState>,
947
+ instance: SanityInstance,
991
948
  doc: string | DocumentHandle<TDocument>,
992
949
  ): StateSource<TDocument | null>
993
950
 
994
951
  /** @beta */
995
952
  export declare function getDocumentState(
996
- instance: SanityInstance | ActionContext<DocumentStoreState>,
953
+ instance: SanityInstance,
997
954
  doc: string | DocumentHandle,
998
955
  path?: string,
999
956
  ): StateSource<unknown>
1000
957
 
1001
958
  /** @beta */
1002
- export declare const getDocumentSyncStatus: ResourceAction<
959
+ export declare const getDocumentSyncStatus: BoundStoreAction<
1003
960
  DocumentStoreState,
1004
961
  [doc: DocumentHandle<SanityDocumentLike>],
1005
962
  StateSource<boolean | undefined>
@@ -1008,18 +965,14 @@ export declare const getDocumentSyncStatus: ResourceAction<
1008
965
  /**
1009
966
  * @public
1010
967
  */
1011
- export declare const getLoginUrlsState: ResourceAction<
1012
- AuthStoreState,
1013
- [],
1014
- StateSource<AuthProvider[] | null>
1015
- >
968
+ export declare const getLoginUrlState: BoundStoreAction<AuthStoreState, [], StateSource_2<string>>
1016
969
 
1017
970
  /**
1018
971
  * Retrieve or create a channel to be used for communication between
1019
972
  * an application and the controller.
1020
973
  * @public
1021
974
  */
1022
- export declare const getOrCreateChannel: ResourceAction<
975
+ export declare const getOrCreateChannel: BoundStoreAction_2<
1023
976
  ComlinkControllerState,
1024
977
  [options: ChannelInput],
1025
978
  ChannelInstance<Message, Message>
@@ -1030,7 +983,7 @@ export declare const getOrCreateChannel: ResourceAction<
1030
983
  * between an application and iframes.
1031
984
  * @public
1032
985
  */
1033
- export declare const getOrCreateController: ResourceAction<
986
+ export declare const getOrCreateController: BoundStoreAction_2<
1034
987
  ComlinkControllerState,
1035
988
  [targetOrigin: string],
1036
989
  Controller
@@ -1042,40 +995,45 @@ export declare const getOrCreateController: ResourceAction<
1042
995
  * be created within a frame / window to communicate with the controller.
1043
996
  * @public
1044
997
  */
1045
- export declare const getOrCreateNode: ResourceAction<
998
+ export declare const getOrCreateNode: BoundStoreAction_2<
1046
999
  ComlinkNodeState,
1047
1000
  [options: NodeInput],
1048
1001
  Node_2<Message, Message>
1049
1002
  >
1050
1003
 
1051
1004
  /** @beta */
1052
- export declare const getPermissionsState: ResourceAction<
1005
+ export declare const getPermissionsState: BoundStoreAction<
1053
1006
  DocumentStoreState,
1054
- [actions: DocumentAction | DocumentAction[]],
1055
- StateSource<DocumentPermissionsResult | undefined>
1007
+ [DocumentAction | DocumentAction[]],
1008
+ StateSource<DocumentPermissionsResult_2 | undefined>
1056
1009
  >
1057
1010
 
1058
1011
  /**
1059
1012
  * @beta
1060
1013
  */
1061
- export declare const getPreviewState: ResourceAction<
1062
- PreviewStoreState,
1063
- [GetPreviewStateOptions],
1064
- StateSource<ValuePending<PreviewValue>>
1065
- >
1014
+ export declare function getPreviewState<TResult extends object>(
1015
+ instance: SanityInstance,
1016
+ options: GetPreviewStateOptions,
1017
+ ): StateSource<ValuePending<TResult>>
1066
1018
 
1067
1019
  /**
1068
1020
  * @beta
1069
1021
  */
1070
- export declare interface GetPreviewStateOptions {
1071
- document: DocumentHandle
1072
- }
1022
+ export declare function getPreviewState(
1023
+ instance: SanityInstance,
1024
+ options: GetPreviewStateOptions,
1025
+ ): StateSource<ValuePending<PreviewValue>>
1026
+
1027
+ /**
1028
+ * @beta
1029
+ */
1030
+ export declare type GetPreviewStateOptions = DocumentHandle
1073
1031
 
1074
1032
  /**
1075
1033
  * @beta
1076
1034
  */
1077
1035
  export declare function getProjectionState<TResult extends object>(
1078
- instance: SanityInstance | ActionContext<ProjectionStoreState>,
1036
+ instance: SanityInstance,
1079
1037
  options: GetProjectionStateOptions,
1080
1038
  ): StateSource<ProjectionValuePending<TResult>>
1081
1039
 
@@ -1083,27 +1041,26 @@ export declare function getProjectionState<TResult extends object>(
1083
1041
  * @beta
1084
1042
  */
1085
1043
  export declare function getProjectionState(
1086
- instance: SanityInstance | ActionContext<ProjectionStoreState>,
1044
+ instance: SanityInstance,
1087
1045
  options: GetProjectionStateOptions,
1088
1046
  ): StateSource<ProjectionValuePending<Record<string, unknown>>>
1089
1047
 
1090
- declare interface GetProjectionStateOptions {
1091
- document: DocumentHandle
1048
+ declare interface GetProjectionStateOptions extends DocumentHandle {
1092
1049
  projection: ValidProjection
1093
1050
  }
1094
1051
 
1095
1052
  /** @public */
1096
- export declare const getProjectsState: ResourceAction<
1097
- FetcherStoreState<[], Omit<SanityProject_2, 'members'>[]>,
1053
+ export declare const getProjectsState: BoundStoreAction<
1054
+ FetcherStoreState_2<[], Omit<SanityProject_2, 'members'>[]>,
1098
1055
  [],
1099
- StateSource<Omit<SanityProject_2, 'members'>[] | undefined>
1056
+ StateSource_2<Omit<SanityProject_2, 'members'>[] | undefined>
1100
1057
  >
1101
1058
 
1102
1059
  /** @public */
1103
- export declare const getProjectState: ResourceAction<
1104
- FetcherStoreState<[projectId: string], SanityProject_2>,
1105
- [projectId: string],
1106
- StateSource<SanityProject_2 | undefined>
1060
+ export declare const getProjectState: BoundStoreAction<
1061
+ FetcherStoreState_2<[options?: ProjectHandle | undefined], SanityProject_2>,
1062
+ [options?: ProjectHandle | undefined],
1063
+ StateSource_2<SanityProject_2 | undefined>
1107
1064
  >
1108
1065
 
1109
1066
  /** @beta */
@@ -1126,30 +1083,67 @@ export declare const getQueryKey: (query: string, options?: QueryOptions) => str
1126
1083
  * @beta
1127
1084
  */
1128
1085
  export declare function getQueryState<T>(
1129
- instance: SanityInstance | ActionContext<QueryStoreState>,
1086
+ instance: SanityInstance,
1130
1087
  query: string,
1131
1088
  options?: QueryOptions,
1132
1089
  ): StateSource<T | undefined>
1133
1090
 
1134
1091
  /** @beta */
1135
1092
  export declare function getQueryState(
1136
- instance: SanityInstance | ActionContext<QueryStoreState>,
1093
+ instance: SanityInstance,
1137
1094
  query: string,
1138
1095
  options?: QueryOptions,
1139
1096
  ): StateSource<unknown>
1140
1097
 
1141
1098
  /**
1142
- * @beta
1143
- * Get the resource ID from a document resource ID
1099
+ * @public
1144
1100
  */
1145
- export declare function getResourceId(
1146
- documentResourceId: DocumentResourceId | undefined,
1147
- ): ResourceId | undefined
1101
+ export declare const getTokenState: BoundStoreAction<
1102
+ AuthStoreState,
1103
+ [],
1104
+ StateSource_2<string | null>
1105
+ >
1106
+
1107
+ /** @internal */
1108
+ export declare const getUsersKey: (
1109
+ instance: SanityInstance,
1110
+ {resourceType, organizationId, batchSize, projectId}?: GetUsersOptions,
1111
+ ) => string
1148
1112
 
1149
1113
  /**
1150
1114
  * @public
1151
1115
  */
1152
- export declare const getTokenState: ResourceAction<AuthStoreState, [], StateSource<string | null>>
1116
+ export declare interface GetUsersOptions extends ProjectHandle {
1117
+ resourceType?: 'organization' | 'project'
1118
+ batchSize?: number
1119
+ organizationId?: string
1120
+ }
1121
+
1122
+ /**
1123
+ * Returns the state source for users associated with a specific resource.
1124
+ *
1125
+ * This function returns a state source that represents the current list of users for a given
1126
+ * resource. Subscribing to the state source will instruct the SDK to fetch the users (if not
1127
+ * already fetched) and will load more from this state source as well. When the last subscriber is
1128
+ * removed, the users state is automatically cleaned up from the store after a delay.
1129
+ *
1130
+ * Note: This functionality is for advanced users who want to build their own framework
1131
+ * integrations. Our SDK also provides a React integration for convenient usage.
1132
+ *
1133
+ * @beta
1134
+ */
1135
+ export declare const getUsersState: BoundStoreAction<
1136
+ UsersStoreState,
1137
+ [options?: GetUsersOptions | undefined],
1138
+ StateSource_2<
1139
+ | {
1140
+ data: SanityUser_2[]
1141
+ totalCount: number
1142
+ hasMore: boolean
1143
+ }
1144
+ | undefined
1145
+ >
1146
+ >
1153
1147
 
1154
1148
  declare type Grant = 'read' | 'update' | 'create' | 'history'
1155
1149
 
@@ -1191,7 +1185,7 @@ declare interface GroupNode extends BaseNode {
1191
1185
  /**
1192
1186
  * @public
1193
1187
  */
1194
- export declare const handleAuthCallback: ResourceAction<
1188
+ export declare const handleAuthCallback: BoundStoreAction<
1195
1189
  AuthStoreState,
1196
1190
  [locationHref?: string | undefined],
1197
1191
  Promise<string | false>
@@ -1276,10 +1270,27 @@ export declare function jsonMatch<TValue>(input: unknown, path: string): MatchEn
1276
1270
  */
1277
1271
  export declare type JsonMatchPath<_TDocument extends SanityDocumentLike> = string
1278
1272
 
1279
- declare interface LiveEventAwareState {
1280
- lastLiveEventId: string | null
1281
- syncTags: Record<string, true>
1282
- }
1273
+ /**
1274
+ * Loads more users for a specific resource.
1275
+ *
1276
+ * This function triggers a request to fetch the next page of users for a given resource. It
1277
+ * requires that users have already been loaded for the resource (via `resolveUsers` or
1278
+ * `getUsersState`), and that there are more users available to load (as indicated by the `hasMore`
1279
+ * property).
1280
+ *
1281
+ * The function returns a promise that resolves when the next page of users has been loaded.
1282
+ *
1283
+ * @beta
1284
+ */
1285
+ export declare const loadMoreUsers: BoundStoreAction<
1286
+ UsersStoreState,
1287
+ [options?: GetUsersOptions | undefined],
1288
+ Promise<{
1289
+ data: SanityUser_2[]
1290
+ totalCount: number
1291
+ hasMore: boolean
1292
+ }>
1293
+ >
1283
1294
 
1284
1295
  /**
1285
1296
  * Logged-in state from the auth state.
@@ -1312,7 +1323,7 @@ export declare type LoggingInAuthState = {
1312
1323
  /**
1313
1324
  * @public
1314
1325
  */
1315
- export declare const logout: ResourceAction<AuthStoreState, [], Promise<void>>
1326
+ export declare const logout: BoundStoreAction<AuthStoreState_2, [], Promise<void>>
1316
1327
 
1317
1328
  declare interface MapNode extends BaseNode {
1318
1329
  type: 'Map'
@@ -1494,6 +1505,14 @@ declare type ParseSegment<TInput extends string> = TInput extends `${infer TProp
1494
1505
  ? []
1495
1506
  : [TInput]
1496
1507
 
1508
+ /** @internal */
1509
+ export declare const parseUsersKey: (key: string) => {
1510
+ batchSize: number
1511
+ resourceType?: 'organization' | 'project'
1512
+ projectId?: string
1513
+ organizationId?: string
1514
+ }
1515
+
1497
1516
  declare class Path {
1498
1517
  private pattern
1499
1518
  private patternRe
@@ -1558,13 +1577,10 @@ declare interface PreviewMedia {
1558
1577
  /**
1559
1578
  * @public
1560
1579
  */
1561
- export declare interface PreviewStoreState extends LiveEventAwareState {
1580
+ export declare interface PreviewStoreState {
1562
1581
  values: {
1563
1582
  [TDocumentId in string]?: ValuePending<PreviewValue>
1564
1583
  }
1565
- documentTypes: {
1566
- [TDocumentId in string]?: string
1567
- }
1568
1584
  subscriptions: {
1569
1585
  [TDocumentId in string]?: {
1570
1586
  [TSubscriptionId in string]?: true
@@ -1575,7 +1591,7 @@ export declare interface PreviewStoreState extends LiveEventAwareState {
1575
1591
  /**
1576
1592
  * Represents the set of values displayed as a preview for a given Sanity document.
1577
1593
  * This includes a primary title, a secondary subtitle, an optional piece of media associated
1578
- * with the document, and the documents status.
1594
+ * with the document, and the document's status.
1579
1595
  *
1580
1596
  * @public
1581
1597
  */
@@ -1604,26 +1620,19 @@ export declare interface PreviewValue {
1604
1620
  }
1605
1621
  }
1606
1622
 
1623
+ /**
1624
+ * @public
1625
+ */
1626
+ export declare interface ProjectHandle {
1627
+ projectId?: string | undefined
1628
+ }
1629
+
1607
1630
  declare interface ProjectionNode extends BaseNode {
1608
1631
  type: 'Projection'
1609
1632
  base: ExprNode
1610
1633
  expr: ExprNode
1611
1634
  }
1612
1635
 
1613
- declare interface ProjectionStoreState<TValue extends object = object> extends LiveEventAwareState {
1614
- values: {
1615
- [TDocumentId in string]?: ProjectionValuePending<TValue>
1616
- }
1617
- documentProjections: {
1618
- [TDocumentId in string]?: ValidProjection
1619
- }
1620
- subscriptions: {
1621
- [TDocumentId in string]?: {
1622
- [TSubscriptionId in string]?: true
1623
- }
1624
- }
1625
- }
1626
-
1627
1636
  /**
1628
1637
  * @beta
1629
1638
  */
@@ -1639,37 +1648,23 @@ export declare function publishDocument<TDocument extends SanityDocumentLike>(
1639
1648
 
1640
1649
  /** @beta */
1641
1650
  export declare interface PublishDocumentAction<
1642
- _TDocument extends SanityDocumentLike = SanityDocumentLike,
1643
- > {
1651
+ TDocument extends SanityDocumentLike = SanityDocumentLike,
1652
+ > extends DocumentHandle<TDocument> {
1644
1653
  type: 'document.publish'
1645
- documentId: string
1646
- resourceId?: DocumentResourceId
1647
1654
  }
1648
1655
 
1649
1656
  /**
1650
1657
  * @beta
1651
1658
  */
1652
1659
  export declare interface QueryOptions
1653
- extends Pick<ResponseQueryOptions, 'perspective' | 'useCdn' | 'cache' | 'next' | 'cacheMode'>,
1654
- Pick<ClientOptions, 'scope' | 'resourceId'> {
1660
+ extends Pick<
1661
+ ResponseQueryOptions,
1662
+ 'perspective' | 'useCdn' | 'cache' | 'next' | 'cacheMode' | 'tag'
1663
+ >,
1664
+ DatasetHandle {
1655
1665
  params?: Record<string, unknown>
1656
1666
  }
1657
1667
 
1658
- declare interface QueryState {
1659
- syncTags?: string[]
1660
- result?: unknown
1661
- error?: unknown
1662
- lastLiveEventId?: string
1663
- subscribers: string[]
1664
- }
1665
-
1666
- declare interface QueryStoreState {
1667
- queries: {
1668
- [key: string]: QueryState | undefined
1669
- }
1670
- error?: unknown
1671
- }
1672
-
1673
1668
  /**
1674
1669
  * Represents a transaction that is queued to be applied but has not yet been
1675
1670
  * applied. A transaction will remain in a queued state until all required
@@ -1697,80 +1692,81 @@ declare interface QueuedTransaction {
1697
1692
  * Signals to the store that the consumer has stopped using the channel
1698
1693
  * @public
1699
1694
  */
1700
- export declare const releaseChannel: ResourceAction<ComlinkControllerState, [name: string], void>
1695
+ export declare const releaseChannel: BoundStoreAction_2<
1696
+ ComlinkControllerState,
1697
+ [name: string],
1698
+ void
1699
+ >
1701
1700
 
1702
1701
  /**
1703
1702
  * Signals to the store that the consumer has stopped using the node
1704
1703
  * @public
1705
1704
  */
1706
- export declare const releaseNode: ResourceAction<ComlinkNodeState, [name: string], void>
1705
+ export declare const releaseNode: BoundStoreAction_2<ComlinkNodeState, [name: string], void>
1707
1706
 
1708
1707
  /** @public */
1709
- export declare const resolveDatasets: ResourceAction<
1710
- FetcherStoreState<[], DatasetsResponse>,
1711
- [],
1708
+ export declare const resolveDatasets: BoundStoreAction<
1709
+ FetcherStoreState_2<[options?: ProjectHandle | undefined], DatasetsResponse>,
1710
+ [options?: ProjectHandle | undefined],
1712
1711
  Promise<DatasetsResponse>
1713
1712
  >
1714
1713
 
1715
1714
  /** @beta */
1716
1715
  export declare function resolveDocument<TDocument extends SanityDocument>(
1717
- instance: SanityInstance | ActionContext<DocumentStoreState>,
1716
+ instance: SanityInstance,
1718
1717
  doc: string | DocumentHandle<TDocument>,
1719
1718
  ): Promise<TDocument | null>
1720
1719
 
1721
1720
  /** @beta */
1722
1721
  export declare function resolveDocument(
1723
- instance: SanityInstance | ActionContext<DocumentStoreState>,
1722
+ instance: SanityInstance,
1724
1723
  doc: string | DocumentHandle,
1725
1724
  ): Promise<SanityDocument | null>
1726
1725
 
1727
1726
  /** @beta */
1728
- export declare const resolvePermissions: ResourceAction<
1727
+ export declare const resolvePermissions: BoundStoreAction<
1729
1728
  DocumentStoreState,
1730
1729
  [actions: DocumentAction | DocumentAction[]],
1731
- Promise<DocumentPermissionsResult>
1730
+ Promise<DocumentPermissionsResult_2>
1732
1731
  >
1733
1732
 
1734
1733
  /**
1735
1734
  * @beta
1736
1735
  */
1737
- export declare const resolvePreview: ResourceAction<
1738
- PreviewStoreState,
1739
- [ResolvePreviewOptions],
1740
- Promise<ValuePending<PreviewValue>>
1736
+ export declare const resolvePreview: BoundStoreAction<
1737
+ PreviewStoreState_2,
1738
+ [docHandle: ResolvePreviewOptions],
1739
+ Promise<ValuePending_2<object>>
1741
1740
  >
1742
1741
 
1743
1742
  /**
1744
1743
  * @beta
1745
1744
  */
1746
- export declare interface ResolvePreviewOptions {
1747
- document: DocumentHandle
1748
- }
1745
+ export declare type ResolvePreviewOptions = DocumentHandle
1749
1746
 
1750
1747
  /** @public */
1751
- export declare const resolveProject: ResourceAction<
1752
- FetcherStoreState<[projectId: string], SanityProject_2>,
1753
- [projectId: string],
1748
+ export declare const resolveProject: BoundStoreAction<
1749
+ FetcherStoreState_2<[options?: ProjectHandle | undefined], SanityProject_2>,
1750
+ [options?: ProjectHandle | undefined],
1754
1751
  Promise<SanityProject_2>
1755
1752
  >
1756
1753
 
1757
1754
  /**
1758
1755
  * @beta
1759
1756
  */
1760
- export declare const resolveProjection: ResourceAction<
1757
+ export declare const resolveProjection: BoundStoreAction<
1761
1758
  ProjectionStoreState<object>,
1762
1759
  [ResolveProjectionOptions],
1763
- Promise<ProjectionValuePending<Record<string, unknown>>>
1760
+ Promise<ProjectionValuePending_2<object>>
1764
1761
  >
1765
1762
 
1766
- declare interface ResolveProjectionOptions {
1767
- document: DocumentHandle
1763
+ declare interface ResolveProjectionOptions extends DocumentHandle {
1768
1764
  projection: ValidProjection
1769
1765
  }
1770
1766
 
1771
1767
  /** @public */
1772
- export declare const resolveProjects: ResourceAction<
1773
- FetcherStoreState<[], Omit<SanityProject_2, 'members'>[]>,
1768
+ export declare const resolveProjects: BoundStoreAction<
1769
+ FetcherStoreState_2<[], Omit<SanityProject_2, 'members'>[]>,
1774
1770
  [],
1775
1771
  Promise<Omit<SanityProject_2, 'members'>[]>
1776
1772
  >
@@ -1790,14 +1786,14 @@ export declare const resolveProjects: ResourceAction<
1790
1786
  * @beta
1791
1787
  */
1792
1788
  export declare function resolveQuery<T>(
1793
- instance: SanityInstance | ActionContext<QueryStoreState>,
1789
+ instance: SanityInstance,
1794
1790
  query: string,
1795
1791
  options?: ResolveQueryOptions,
1796
1792
  ): Promise<T>
1797
1793
 
1798
1794
  /** @beta */
1799
1795
  export declare function resolveQuery(
1800
- instance: SanityInstance | ActionContext<QueryStoreState>,
1796
+ instance: SanityInstance,
1801
1797
  query: string,
1802
1798
  options?: ResolveQueryOptions,
1803
1799
  ): Promise<unknown>
@@ -1810,41 +1806,48 @@ declare interface ResolveQueryOptions extends QueryOptions {
1810
1806
  }
1811
1807
 
1812
1808
  /**
1813
- * @public
1814
- */
1815
- export declare type ResourceAction<TState, TParams extends unknown[], TReturn> = (
1816
- dependencies: SanityInstance | ActionContext<TState>,
1817
- ...params: TParams
1818
- ) => TReturn
1819
-
1820
- /**
1821
- * @public
1822
- * A resource identifier for a document, in the format of `projectId.dataset`
1809
+ * Resolves the users for a specific resource without registering a lasting subscriber.
1810
+ *
1811
+ * This function fetches the users for a given resource and returns a promise that resolves with
1812
+ * the users result. Unlike `getUsersState`, which registers subscribers to keep the data live and
1813
+ * performs automatic cleanup, `resolveUsers` does not track subscribers. This makes it ideal for
1814
+ * use with React Suspense, where the returned promise is thrown to delay rendering until the users
1815
+ * result becomes available. Once the promise resolves, it is expected that a real subscriber will
1816
+ * be added via `getUsersState` to manage ongoing updates.
1817
+ *
1818
+ * Additionally, an optional AbortSignal can be provided to cancel the request and immediately
1819
+ * clear the associated state if there are no active subscribers.
1820
+ *
1821
+ * @beta
1823
1822
  */
1824
- export declare type ResourceId = `${string}.${string}`
1823
+ export declare const resolveUsers: BoundStoreAction<
1824
+ UsersStoreState,
1825
+ [ResolveUsersOptions],
1826
+ Promise<{
1827
+ data: SanityUser_2[]
1828
+ totalCount: number
1829
+ hasMore: boolean
1830
+ }>
1831
+ >
1825
1832
 
1826
1833
  /**
1827
1834
  * @public
1828
1835
  */
1829
- export declare type ResourceState<TState> = {
1830
- get: () => TState
1831
- set: (name: string, state: Partial<TState> | ((s: TState) => Partial<TState>)) => void
1832
- observable: Observable<TState>
1836
+ export declare interface ResolveUsersOptions extends GetUsersOptions {
1837
+ signal?: AbortSignal
1833
1838
  }
1834
1839
 
1835
- /**
1836
- * @public
1837
- */
1838
- export declare type ResourceType = 'organization' | 'project'
1839
-
1840
1840
  export {Role}
1841
1841
 
1842
1842
  /**
1843
+ * Represents the complete configuration for a Sanity SDK instance
1843
1844
  * @public
1844
1845
  */
1845
- export declare interface SanityConfig {
1846
- projectId: string
1847
- dataset: string
1846
+ export declare interface SanityConfig extends DatasetHandle {
1847
+ /**
1848
+ * Authentication configuration for the instance
1849
+ * @remarks Merged with parent configurations when using createChild
1850
+ */
1848
1851
  auth?: AuthConfig
1849
1852
  }
1850
1853
 
@@ -1852,17 +1855,57 @@ export {SanityDocument}
1852
1855
 
1853
1856
  export {SanityDocumentLike}
1854
1857
 
1855
- /** @public */
1858
+ /**
1859
+ * Represents a Sanity.io resource instance with its own configuration and lifecycle
1860
+ * @remarks Instances form a hierarchy through parent/child relationships
1861
+ *
1862
+ * @public
1863
+ */
1856
1864
  export declare interface SanityInstance {
1857
1865
  /**
1858
- * The following is used to look up resources associated with this instance,
1859
- * and can be used to retrieve an "id" for the instance - useful in debugging.
1860
- *
1861
- * @public
1866
+ * Unique identifier for this instance
1867
+ * @remarks Generated using crypto.randomUUID()
1862
1868
  */
1863
- readonly identity: SdkIdentity
1864
- config: Omit<SanityConfig, 'projectId' | 'dataset'>
1865
- dispose: () => void
1869
+ readonly instanceId: string
1870
+ /**
1871
+ * Resolved configuration for this instance
1872
+ * @remarks Merges values from parent instances where appropriate
1873
+ */
1874
+ readonly config: SanityConfig
1875
+ /**
1876
+ * Checks if the instance has been disposed
1877
+ * @returns true if dispose() has been called
1878
+ */
1879
+ isDisposed(): boolean
1880
+ /**
1881
+ * Disposes the instance and cleans up associated resources
1882
+ * @remarks Triggers all registered onDispose callbacks
1883
+ */
1884
+ dispose(): void
1885
+ /**
1886
+ * Registers a callback to be invoked when the instance is disposed
1887
+ * @param cb - Callback to execute on disposal
1888
+ * @returns Function to unsubscribe the callback
1889
+ */
1890
+ onDispose(cb: () => void): () => void
1891
+ /**
1892
+ * Gets the parent instance in the hierarchy
1893
+ * @returns Parent instance or undefined if this is the root
1894
+ */
1895
+ getParent(): SanityInstance | undefined
1896
+ /**
1897
+ * Creates a child instance with merged configuration
1898
+ * @param config - Configuration to merge with parent values
1899
+ * @remarks Child instances inherit parent configuration but can override values
1900
+ */
1901
+ createChild(config: SanityConfig): SanityInstance
1902
+ /**
1903
+ * Traverses the instance hierarchy to find the first instance whose configuration
1904
+ * matches the given target config using a shallow comparison.
1905
+ * @param targetConfig - A partial configuration object containing key-value pairs to match.
1906
+ * @returns The first matching instance or undefined if no match is found.
1907
+ */
1908
+ match(targetConfig: Partial<SanityConfig>): SanityInstance | undefined
1866
1909
  }
1867
1910
 
1868
1911
  /**
@@ -1879,15 +1922,6 @@ export declare interface SanityUser {
1879
1922
  memberships: Membership[]
1880
1923
  }
1881
1924
 
1882
- /**
1883
- * @public
1884
- */
1885
- declare interface SanityUserResponse {
1886
- data: SanityUser[]
1887
- totalCount: number
1888
- nextCursor: string | null
1889
- }
1890
-
1891
1925
  declare class Scope {
1892
1926
  params: Record<string, unknown>
1893
1927
  source: Value
@@ -1906,14 +1940,6 @@ declare class Scope {
1906
1940
  createHidden(value: Value): Scope
1907
1941
  }
1908
1942
 
1909
- /** @public */
1910
- export declare interface SdkIdentity {
1911
- readonly id: string
1912
- readonly projectId: string
1913
- readonly dataset: string
1914
- readonly resourceId: ResourceId
1915
- }
1916
-
1917
1943
  declare interface SelectAlternativeNode extends BaseNode {
1918
1944
  type: 'SelectAlternative'
1919
1945
  condition: ExprNode
@@ -1926,10 +1952,56 @@ declare interface SelectNode extends BaseNode {
1926
1952
  fallback?: ExprNode
1927
1953
  }
1928
1954
 
1955
+ /**
1956
+ * Function type for selecting derived state from store state and parameters
1957
+ * @public
1958
+ */
1959
+ export declare type Selector<TState, TParams extends unknown[], TReturn> = (
1960
+ context: SelectorContext<TState>,
1961
+ ...params: TParams
1962
+ ) => TReturn
1963
+
1964
+ /**
1965
+ * Context passed to selectors when deriving state
1966
+ *
1967
+ * @remarks
1968
+ * Provides access to both the current state value and the Sanity instance,
1969
+ * allowing selectors to use configuration values when computing derived state.
1970
+ * The context is memoized for each state object and instance combination
1971
+ * to optimize performance and prevent unnecessary recalculations.
1972
+ *
1973
+ * @example
1974
+ * ```ts
1975
+ * // Using both state and instance in a selector (psuedo example)
1976
+ * const getUserByProjectId = createStateSourceAction(
1977
+ * ({ state, instance }: SelectorContext<UsersState>, options?: ProjectHandle) => {
1978
+ * const allUsers = state.users
1979
+ * const projectId = options?.projectId ?? instance.config.projectId
1980
+ * return allUsers.filter(user => user.projectId === projectId)
1981
+ * }
1982
+ * )
1983
+ * ```
1984
+ */
1985
+ declare interface SelectorContext<TState> {
1986
+ /**
1987
+ * The current state object from the store
1988
+ */
1989
+ state: TState
1990
+ /**
1991
+ * The Sanity instance associated with this state
1992
+ */
1993
+ instance: SanityInstance
1994
+ }
1995
+
1929
1996
  declare interface SelectorNode extends BaseNode {
1930
1997
  type: 'Selector'
1931
1998
  }
1932
1999
 
2000
+ declare interface SharedListener {
2001
+ events: Observable<ListenEvent<SanityDocument_2>>
2002
+ dispose: () => void
2003
+ }
2004
+
1933
2005
  declare type SingleValuePath = Exclude<PathSegment, IndexTuple>[]
1934
2006
 
1935
2007
  declare interface SliceNode extends BaseNode {
@@ -1941,11 +2013,40 @@ declare interface SliceNode extends BaseNode {
1941
2013
  }
1942
2014
 
1943
2015
  /**
2016
+ * Represents a reactive state source that provides synchronized access to store data
2017
+ *
2018
+ * @remarks
2019
+ * Designed to work with React's useSyncExternalStore hook. Provides three ways to access data:
2020
+ * 1. `getCurrent()` for synchronous current value access
2021
+ * 2. `subscribe()` for imperative change notifications
2022
+ * 3. `observable` for reactive stream access
2023
+ *
1944
2024
  * @public
1945
2025
  */
1946
2026
  export declare interface StateSource<T> {
2027
+ /**
2028
+ * Subscribes to state changes with optional callback
2029
+ * @param onStoreChanged - Called whenever relevant state changes occur
2030
+ * @returns Unsubscribe function to clean up the subscription
2031
+ */
1947
2032
  subscribe: (onStoreChanged?: () => void) => () => void
2033
+ /**
2034
+ * Gets the current derived state value
2035
+ *
2036
+ * @remarks
2037
+ * Safe to call without subscription. Will always return the latest value
2038
+ * based on the current store state and selector parameters.
2039
+ */
1948
2040
  getCurrent: () => T
2041
+ /**
2042
+ * Observable stream of state values
2043
+ *
2044
+ * @remarks
2045
+ * Shares a single underlying subscription between all observers. Emits:
2046
+ * - Immediately with current value on subscription
2047
+ * - On every relevant state change
2048
+ * - Errors if selector throws
2049
+ */
1949
2050
  observable: Observable<T>
1950
2051
  }
1951
2052
 
@@ -1960,6 +2061,7 @@ declare class StaticValue<P, T extends GroqType> {
1960
2061
 
1961
2062
  declare interface StoreEntry<TParams extends unknown[], TData> {
1962
2063
  params: TParams
2064
+ instance: SanityInstance
1963
2065
  key: string
1964
2066
  data?: TData
1965
2067
  error?: unknown
@@ -1983,7 +2085,7 @@ declare class StreamValue {
1983
2085
  declare type StringValue = StaticValue<string, 'string'>
1984
2086
 
1985
2087
  /** @beta */
1986
- export declare const subscribeDocumentEvents: ResourceAction<
2088
+ export declare const subscribeDocumentEvents: BoundStoreAction<
1987
2089
  DocumentStoreState,
1988
2090
  [eventHandler: (e: DocumentEvent) => void],
1989
2091
  () => void
@@ -2030,11 +2132,9 @@ export declare function unpublishDocument<TDocument extends SanityDocumentLike>(
2030
2132
 
2031
2133
  /** @beta */
2032
2134
  export declare interface UnpublishDocumentAction<
2033
- _TDocument extends SanityDocumentLike = SanityDocumentLike,
2034
- > {
2135
+ TDocument extends SanityDocumentLike = SanityDocumentLike,
2136
+ > extends DocumentHandle<TDocument> {
2035
2137
  type: 'document.unpublish'
2036
- documentId: string
2037
- resourceId?: DocumentResourceId
2038
2138
  }
2039
2139
 
2040
2140
  declare interface UnverifiedDocumentRevision {
@@ -2066,20 +2166,23 @@ export declare interface UserProfile {
2066
2166
  /**
2067
2167
  * @public
2068
2168
  */
2069
- export declare interface UsersStoreState {
2070
- users: SanityUser[]
2071
- totalCount: number
2072
- nextCursor: string | null
2073
- hasMore: boolean
2074
- initialFetchCompleted: boolean
2075
- options: {
2076
- resourceType: ResourceType
2077
- resourceId: string
2078
- /**
2079
- * The maximum number of users to fetch. [Default: 100]
2080
- */
2081
- limit?: number
2169
+ declare interface UsersGroupState {
2170
+ subscriptions: string[]
2171
+ totalCount?: number
2172
+ nextCursor?: string | null
2173
+ lastLoadMoreRequest?: string
2174
+ users?: SanityUser[]
2175
+ error?: unknown
2176
+ }
2177
+
2178
+ /**
2179
+ * @public
2180
+ */
2181
+ declare interface UsersStoreState {
2182
+ users: {
2183
+ [TUsersKey in string]?: UsersGroupState
2082
2184
  }
2185
+ error?: unknown
2083
2186
  }
2084
2187
 
2085
2188
  /**