@sanity/sdk 3.0.0-rc.0 → 3.0.0-rc.1

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 (197) hide show
  1. package/dist/_chunks-dts/createGroqSearchFilter.d.ts +1147 -0
  2. package/dist/_chunks-dts/createGroqSearchFilter.d.ts.map +1 -0
  3. package/dist/_chunks-es/_internal.js +134 -0
  4. package/dist/_chunks-es/_internal.js.map +1 -0
  5. package/dist/_chunks-es/createGroqSearchFilter.js +1864 -0
  6. package/dist/_chunks-es/createGroqSearchFilter.js.map +1 -0
  7. package/dist/_chunks-es/telemetryManager.js +93 -0
  8. package/dist/_chunks-es/telemetryManager.js.map +1 -0
  9. package/dist/_exports/_internal.d.ts +95 -0
  10. package/dist/_exports/_internal.d.ts.map +1 -0
  11. package/dist/_exports/_internal.js +24 -0
  12. package/dist/_exports/_internal.js.map +1 -0
  13. package/dist/index.d.ts +1079 -1076
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +1967 -2302
  16. package/dist/index.js.map +1 -1
  17. package/package.json +48 -47
  18. package/src/_exports/_internal.ts +26 -0
  19. package/src/_exports/index.ts +120 -11
  20. package/src/access/checkPermissions.test.ts +55 -0
  21. package/src/access/checkPermissions.ts +54 -0
  22. package/src/agent/agentActions.test.ts +16 -60
  23. package/src/agent/agentActions.ts +25 -38
  24. package/src/applications/applications.test-d.ts +83 -0
  25. package/src/applications/applications.test.ts +130 -0
  26. package/src/applications/applications.ts +364 -0
  27. package/src/applications/userApplications.test.ts +126 -0
  28. package/src/applications/userApplications.ts +261 -0
  29. package/src/auth/authLogger.ts +30 -0
  30. package/src/auth/authMode.test.ts +25 -0
  31. package/src/auth/authMode.ts +6 -3
  32. package/src/auth/authStore.test.ts +194 -13
  33. package/src/auth/authStore.ts +59 -26
  34. package/src/auth/getOrganizationVerificationState.test.ts +18 -17
  35. package/src/auth/getOrganizationVerificationState.ts +4 -4
  36. package/src/auth/handleAuthCallback.test.ts +35 -1
  37. package/src/auth/handleAuthCallback.ts +25 -6
  38. package/src/auth/logout.test.ts +75 -2
  39. package/src/auth/logout.ts +23 -4
  40. package/src/auth/refreshStampedToken.test.ts +219 -469
  41. package/src/auth/refreshStampedToken.ts +79 -195
  42. package/src/auth/studioAuth.ts +1 -1
  43. package/src/auth/studioModeAuth.ts +2 -1
  44. package/src/auth/subscribeToStateAndFetchCurrentUser.test.ts +146 -13
  45. package/src/auth/subscribeToStateAndFetchCurrentUser.ts +37 -6
  46. package/src/auth/subscribeToStorageEventsAndSetToken.test.ts +2 -0
  47. package/src/client/clientStore.test.ts +62 -37
  48. package/src/client/clientStore.ts +45 -75
  49. package/src/client/liveEvents.test.ts +151 -0
  50. package/src/client/liveEvents.ts +107 -0
  51. package/src/comlink/controller/actions/destroyController.test.ts +4 -1
  52. package/src/comlink/controller/actions/getOrCreateChannel.test.ts +4 -1
  53. package/src/comlink/controller/actions/getOrCreateChannel.ts +2 -2
  54. package/src/comlink/controller/actions/getOrCreateController.test.ts +4 -1
  55. package/src/comlink/controller/actions/releaseChannel.test.ts +1 -1
  56. package/src/comlink/controller/comlinkControllerStore.test.ts +4 -1
  57. package/src/comlink/node/actions/getOrCreateNode.test.ts +9 -3
  58. package/src/comlink/node/actions/getOrCreateNode.ts +2 -2
  59. package/src/comlink/node/actions/releaseNode.test.ts +7 -4
  60. package/src/comlink/node/comlinkNodeStore.test.ts +2 -2
  61. package/src/comlink/node/getNodeState.test.ts +1 -1
  62. package/src/comlink/node/getNodeState.ts +2 -1
  63. package/src/config/__tests__/handles.test.ts +18 -12
  64. package/src/config/handles.ts +25 -7
  65. package/src/config/sanityConfig.ts +109 -79
  66. package/src/datasets/datasets.test.ts +2 -2
  67. package/src/datasets/datasets.ts +10 -4
  68. package/src/document/actions.test.ts +115 -33
  69. package/src/document/actions.ts +212 -15
  70. package/src/document/applyDocumentActions.test.ts +38 -12
  71. package/src/document/applyDocumentActions.ts +30 -9
  72. package/src/document/documentConstants.ts +7 -0
  73. package/src/document/documentStore.concurrency.test.ts +1306 -0
  74. package/src/document/documentStore.test.ts +673 -278
  75. package/src/document/documentStore.ts +162 -71
  76. package/src/document/events.test.ts +57 -2
  77. package/src/document/events.ts +82 -26
  78. package/src/document/listen.test.ts +56 -0
  79. package/src/document/listen.ts +74 -21
  80. package/src/document/listenerEventOperators.test.ts +311 -0
  81. package/src/document/listenerEventOperators.ts +217 -0
  82. package/src/document/patchOperations.test.ts +49 -2
  83. package/src/document/patchOperations.ts +50 -0
  84. package/src/document/permissions.test.ts +105 -60
  85. package/src/document/permissions.ts +44 -19
  86. package/src/document/processActions/create.ts +138 -0
  87. package/src/document/processActions/delete.ts +100 -0
  88. package/src/document/processActions/discard.ts +63 -0
  89. package/src/document/processActions/edit.ts +154 -0
  90. package/src/document/processActions/processActions.ts +218 -0
  91. package/src/document/processActions/publish.ts +120 -0
  92. package/src/document/processActions/releaseArchive.ts +77 -0
  93. package/src/document/processActions/releaseCreate.ts +59 -0
  94. package/src/document/processActions/releaseDelete.ts +65 -0
  95. package/src/document/processActions/releaseEdit.ts +37 -0
  96. package/src/document/processActions/releasePublish.ts +45 -0
  97. package/src/document/processActions/releaseSchedule.ts +87 -0
  98. package/src/document/processActions/releaseUtil.ts +31 -0
  99. package/src/document/processActions/shared.ts +308 -0
  100. package/src/document/processActions/unpublish.ts +85 -0
  101. package/src/document/processActions.test.ts +1129 -121
  102. package/src/document/reducers.test.ts +639 -64
  103. package/src/document/reducers.ts +187 -48
  104. package/src/document/resourceRules.test.ts +178 -0
  105. package/src/document/resourceRules.ts +117 -0
  106. package/src/document/sharedListener.test.ts +16 -14
  107. package/src/document/sharedListener.ts +24 -8
  108. package/src/document/util.ts +14 -0
  109. package/src/favorites/favorites.test.ts +5 -6
  110. package/src/installations/installations.test-d.ts +68 -0
  111. package/src/installations/installations.test.ts +62 -0
  112. package/src/installations/installations.ts +202 -0
  113. package/src/organization/organization.test-d.ts +36 -0
  114. package/src/organization/organization.test.ts +138 -0
  115. package/src/organization/organization.ts +138 -0
  116. package/src/organizations/organizations.test-d.ts +56 -0
  117. package/src/organizations/organizations.test.ts +150 -0
  118. package/src/organizations/organizations.ts +107 -0
  119. package/src/presence/bifurTransport.test.ts +46 -6
  120. package/src/presence/bifurTransport.ts +19 -2
  121. package/src/presence/presenceStore.test.ts +94 -23
  122. package/src/presence/presenceStore.ts +85 -29
  123. package/src/preview/getPreviewState.test.ts +137 -0
  124. package/src/preview/getPreviewState.ts +69 -0
  125. package/src/preview/previewProjectionUtils.test.ts +9 -22
  126. package/src/preview/previewProjectionUtils.ts +7 -3
  127. package/src/preview/resolvePreview.test.ts +64 -0
  128. package/src/preview/resolvePreview.ts +43 -0
  129. package/src/preview/types.ts +10 -0
  130. package/src/project/project.test-d.ts +37 -0
  131. package/src/project/project.test.ts +157 -12
  132. package/src/project/project.ts +138 -25
  133. package/src/projection/getProjectionState.test.ts +18 -20
  134. package/src/projection/getProjectionState.ts +23 -3
  135. package/src/projection/projectionQuery.ts +5 -5
  136. package/src/projection/projectionStore.test.ts +1 -1
  137. package/src/projection/resolveProjection.test.ts +1 -2
  138. package/src/projection/resolveProjection.ts +16 -0
  139. package/src/projection/subscribeToStateAndFetchBatches.test.ts +1 -1
  140. package/src/projection/subscribeToStateAndFetchBatches.ts +32 -23
  141. package/src/projection/types.ts +8 -0
  142. package/src/projects/projects.test-d.ts +32 -0
  143. package/src/projects/projects.test.ts +108 -42
  144. package/src/projects/projects.ts +63 -27
  145. package/src/query/queryStore.test.ts +259 -123
  146. package/src/query/queryStore.ts +78 -63
  147. package/src/query/reducers.test.ts +0 -42
  148. package/src/query/reducers.ts +2 -18
  149. package/src/releases/getPerspectiveState.test.ts +17 -23
  150. package/src/releases/getPerspectiveState.ts +8 -20
  151. package/src/releases/observeReleases.test.ts +127 -0
  152. package/src/releases/observeReleases.ts +102 -0
  153. package/src/releases/releasesStore.test.ts +100 -53
  154. package/src/releases/releasesStore.ts +69 -44
  155. package/src/releases/utils/sortReleases.test.ts +38 -2
  156. package/src/releases/utils/sortReleases.ts +15 -10
  157. package/src/store/createActionBinder.test.ts +87 -90
  158. package/src/store/createActionBinder.ts +79 -25
  159. package/src/store/createSanityInstance.test.ts +83 -13
  160. package/src/store/createSanityInstance.ts +77 -2
  161. package/src/store/createStateSourceAction.test.ts +64 -2
  162. package/src/store/createStateSourceAction.ts +39 -44
  163. package/src/store/createStoreInstance.test.ts +4 -2
  164. package/src/store/fetcherStore.test-d.ts +121 -0
  165. package/src/store/fetcherStore.test.ts +299 -0
  166. package/src/store/fetcherStore.ts +801 -0
  167. package/src/telemetry/environment.test.ts +119 -0
  168. package/src/telemetry/environment.ts +92 -0
  169. package/src/telemetry/events.ts +42 -0
  170. package/src/telemetry/initTelemetry.test.ts +432 -0
  171. package/src/telemetry/initTelemetry.ts +218 -0
  172. package/src/telemetry/telemetryManager.test.ts +327 -0
  173. package/src/telemetry/telemetryManager.ts +199 -0
  174. package/src/users/reducers.test.ts +6 -1
  175. package/src/users/reducers.ts +5 -6
  176. package/src/users/types.ts +4 -4
  177. package/src/users/usersStore.test.ts +16 -12
  178. package/src/users/usersStore.ts +5 -1
  179. package/src/utils/buildQuery.test.ts +14 -0
  180. package/src/utils/buildQuery.ts +17 -0
  181. package/src/utils/createFetcherStore.test.ts +7 -5
  182. package/src/utils/createFetcherStore.ts +8 -5
  183. package/src/utils/getStagingApiHost.test.ts +21 -0
  184. package/src/utils/getStagingApiHost.ts +14 -0
  185. package/src/utils/ids.test.ts +1 -29
  186. package/src/utils/ids.ts +0 -10
  187. package/src/utils/includeShape.ts +36 -0
  188. package/src/utils/isImportError.test.ts +72 -0
  189. package/src/utils/isImportError.ts +34 -0
  190. package/src/utils/logger.test.ts +12 -0
  191. package/src/utils/logger.ts +8 -3
  192. package/src/utils/object.test.ts +95 -0
  193. package/src/utils/object.ts +142 -0
  194. package/src/utils/setCleanupTimeout.ts +37 -0
  195. package/src/document/processActions.ts +0 -707
  196. package/src/utils/defineIntent.test.ts +0 -477
  197. package/src/utils/defineIntent.ts +0 -244
@@ -0,0 +1,1147 @@
1
+ import { ClientConfig, ClientError, ClientPerspective, ResponseQueryOptions, SanityClient, StackablePerspective } from "@sanity/client";
2
+ import { CurrentUser } from "@sanity/types";
3
+ import { Observable } from "rxjs";
4
+ import "zustand/middleware";
5
+ import { SanityQueryResult } from "groq";
6
+ /**
7
+ * Configuration for an authentication provider
8
+ * @public
9
+ */
10
+ interface AuthProvider {
11
+ /**
12
+ * Unique identifier for the auth provider (e.g., 'google', 'github')
13
+ */
14
+ name: string;
15
+ /**
16
+ * Display name for the auth provider in the UI
17
+ */
18
+ title: string;
19
+ /**
20
+ * Complete authentication URL including callback and token parameters
21
+ */
22
+ url: string;
23
+ /**
24
+ * Optional URL for direct sign-up flow
25
+ */
26
+ signUpUrl?: string;
27
+ }
28
+ /**
29
+ * Configuration options for creating an auth store.
30
+ *
31
+ * @public
32
+ */
33
+ interface AuthConfig {
34
+ /**
35
+ * The initial location href to use when handling auth callbacks.
36
+ * Defaults to the current window location if available.
37
+ */
38
+ initialLocationHref?: string;
39
+ /**
40
+ * Factory function to create a SanityClient instance.
41
+ * Defaults to the standard Sanity client factory if not provided.
42
+ */
43
+ clientFactory?: (config: ClientConfig) => SanityClient;
44
+ /**
45
+ * Custom authentication providers to use instead of or in addition to the default ones.
46
+ * Can be an array of providers or a function that takes the default providers and returns
47
+ * a modified array or a Promise resolving to one.
48
+ */
49
+ providers?: AuthProvider[] | ((prev: AuthProvider[]) => AuthProvider[] | Promise<AuthProvider[]>);
50
+ /**
51
+ * The API hostname for requests. Usually leave this undefined, but it can be set
52
+ * if using a custom domain or CNAME for the API endpoint.
53
+ */
54
+ apiHost?: string;
55
+ /**
56
+ * Storage implementation to persist authentication state.
57
+ * Defaults to `localStorage` if available.
58
+ */
59
+ storageArea?: Storage;
60
+ /**
61
+ * A callback URL for your application.
62
+ * If none is provided, the auth API will redirect back to the current location (`location.href`).
63
+ * When handling callbacks, this URL's pathname is checked to ensure it matches the callback.
64
+ */
65
+ callbackUrl?: string;
66
+ /**
67
+ * A static authentication token to use instead of handling the OAuth flow.
68
+ * When provided, the auth store will remain in a logged-in state with this token,
69
+ * ignoring any storage or callback handling.
70
+ */
71
+ token?: string;
72
+ }
73
+ /**
74
+ * A minimal Observable-compatible interface for subscribing to token changes.
75
+ * Any object with a `subscribe` method that follows this contract will work,
76
+ * including RxJS Observables. This avoids coupling the SDK to a specific
77
+ * reactive library.
78
+ *
79
+ * @public
80
+ */
81
+ interface TokenSource {
82
+ /** Subscribe to token emissions. Emits `null` when logged out. */
83
+ subscribe(observer: {
84
+ next: (token: string | null) => void;
85
+ }): {
86
+ unsubscribe(): void;
87
+ };
88
+ }
89
+ /**
90
+ * Studio-specific configuration for the SDK.
91
+ * When present, the SDK operates in studio mode and derives auth from the
92
+ * provided token source instead of discovering tokens independently.
93
+ *
94
+ * @public
95
+ */
96
+ interface StudioConfig {
97
+ /**
98
+ * Whether the Studio has already determined the user is authenticated.
99
+ * When `true` and the token source emits `null`, the SDK infers
100
+ * cookie-based auth is in use rather than transitioning to logged-out.
101
+ */
102
+ authenticated?: boolean;
103
+ /** Reactive auth token source from the Studio's auth store. */
104
+ auth?: {
105
+ /**
106
+ * A reactive token source. The SDK subscribes and stays in sync — the
107
+ * Studio is the single authority for auth and handles token refresh.
108
+ *
109
+ * Optional because older Studios may not expose it. When absent, the
110
+ * SDK falls back to localStorage/cookie discovery.
111
+ */
112
+ token?: TokenSource;
113
+ };
114
+ }
115
+ /**
116
+ * Represents the minimal configuration required to identify a Sanity project.
117
+ * @public
118
+ */
119
+ interface ProjectHandle<TProjectId extends string = string> {
120
+ projectId?: TProjectId;
121
+ }
122
+ /**
123
+ * @public
124
+ */
125
+ type ReleasePerspective = {
126
+ releaseName: string;
127
+ excludedPerspectives?: StackablePerspective[];
128
+ };
129
+ /**
130
+ * @public
131
+ */
132
+ interface PerspectiveHandle {
133
+ perspective?: ClientPerspective | ReleasePerspective;
134
+ }
135
+ /**
136
+ * @public
137
+ */
138
+ interface DatasetHandle<TDataset extends string = string, TProjectId extends string = string> extends ProjectHandle<TProjectId>, PerspectiveHandle {
139
+ dataset?: TDataset;
140
+ /**
141
+ * @beta
142
+ * Explicit resource object to use for this operation.
143
+ */
144
+ resource?: DocumentResource;
145
+ /**
146
+ * @deprecated Use `resource` instead.
147
+ * @beta
148
+ */
149
+ source?: DocumentResource;
150
+ }
151
+ /**
152
+ * Identifies a specific document type within a Sanity dataset and project.
153
+ * Includes `projectId`, `dataset`, and `documentType`.
154
+ * Optionally includes a `documentId` and `liveEdit` flag.
155
+ * @public
156
+ */
157
+ interface DocumentTypeHandle<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string> extends DatasetHandle<TDataset, TProjectId> {
158
+ documentId?: string;
159
+ documentType: TDocumentType;
160
+ /**
161
+ * Indicates whether this document uses liveEdit mode.
162
+ * When `true`, the document does not use the draft/published model and edits are applied directly to the document.
163
+ * @see https://www.sanity.io/docs/content-lake/drafts#ca0663a8f002
164
+ */
165
+ liveEdit?: boolean;
166
+ }
167
+ /**
168
+ * Uniquely identifies a specific document within a Sanity dataset and project.
169
+ * Includes `projectId`, `dataset`, `documentType`, and the required `documentId`.
170
+ * Commonly used by document-related hooks and components to reference a document without fetching its full content initially.
171
+ * @public
172
+ */
173
+ interface DocumentHandle<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string> extends DocumentTypeHandle<TDocumentType, TDataset, TProjectId> {
174
+ documentId: string;
175
+ }
176
+ /**
177
+ * Identifies a release within a Sanity dataset and project. `releaseId` is the
178
+ * `name` parameter on the release document (e.g. `{name: 'r41035a4'}`).
179
+ * The underlying release document ID is `_.releases.<releaseId>`.
180
+ * It's also the `id` parameter sent to the Actions API.
181
+ * (This type doesn't need to have ProjectId / Dataset generics since it's always the same shape)
182
+ * @beta
183
+ */
184
+ interface ReleaseHandle extends DatasetHandle {
185
+ releaseId: string;
186
+ }
187
+ /**
188
+ * Represents the complete configuration for a Sanity SDK instance
189
+ * @public
190
+ */
191
+ interface SanityConfig extends DatasetHandle, PerspectiveHandle {
192
+ /**
193
+ * Authentication configuration for the instance
194
+ */
195
+ auth?: AuthConfig;
196
+ /**
197
+ * Studio configuration provided by a Sanity Studio workspace.
198
+ * When present, the SDK operates in studio mode and derives auth from the
199
+ * workspace's reactive token source — no manual configuration needed.
200
+ *
201
+ * @remarks Typically set automatically by `SanityApp` when it detects an
202
+ * `SDKStudioContext` provider. Can also be set explicitly for programmatic use.
203
+ */
204
+ studio?: StudioConfig;
205
+ /**
206
+ * Studio mode configuration for use of the SDK in a Sanity Studio.
207
+ * @remarks Controls whether studio mode features are enabled.
208
+ * @deprecated Use `studio` instead, which provides richer integration
209
+ * with the Studio's workspace (auth token sync, etc.).
210
+ */
211
+ studioMode?: {
212
+ enabled: boolean;
213
+ };
214
+ /**
215
+ * @beta
216
+ * A list of named resources to use for this instance.
217
+ */
218
+ resources?: Record<string, DocumentResource>;
219
+ /**
220
+ * @deprecated Use `resources` instead.
221
+ * @beta
222
+ */
223
+ sources?: Record<string, DocumentResource>;
224
+ }
225
+ /**
226
+ * A document resource can be used for querying.
227
+ * This will soon be the default way to identify where you are querying from.
228
+ *
229
+ * @beta
230
+ */
231
+ type DocumentResource = DatasetResource | MediaLibraryResource | CanvasResource;
232
+ /**
233
+ * @beta
234
+ */
235
+ type DatasetResource = {
236
+ projectId: string;
237
+ dataset: string;
238
+ };
239
+ /**
240
+ * @beta
241
+ */
242
+ type MediaLibraryResource = {
243
+ mediaLibraryId: string;
244
+ };
245
+ /**
246
+ * @beta
247
+ */
248
+ type CanvasResource = {
249
+ canvasId: string;
250
+ };
251
+ /**
252
+ * @beta
253
+ */
254
+ declare function isDatasetResource(resource: DocumentResource): resource is DatasetResource;
255
+ /**
256
+ * @beta
257
+ */
258
+ declare function isMediaLibraryResource(resource: DocumentResource): resource is MediaLibraryResource;
259
+ /**
260
+ * @beta
261
+ */
262
+ declare function isCanvasResource(resource: DocumentResource): resource is CanvasResource;
263
+ /**
264
+ * @deprecated Use `DocumentResource` instead.
265
+ * @beta
266
+ */
267
+ type DocumentSource = DocumentResource;
268
+ /**
269
+ * @deprecated Use `DatasetResource` instead.
270
+ * @beta
271
+ */
272
+ type DatasetSource = DatasetResource;
273
+ /**
274
+ * @deprecated Use `MediaLibraryResource` instead.
275
+ * @beta
276
+ */
277
+ type MediaLibrarySource = MediaLibraryResource;
278
+ /**
279
+ * @deprecated Use `CanvasResource` instead.
280
+ * @beta
281
+ */
282
+ type CanvasSource = CanvasResource;
283
+ /**
284
+ * @deprecated Use `isDatasetResource` instead.
285
+ * @beta
286
+ */
287
+ declare function isDatasetSource(source: DocumentSource): source is DatasetSource;
288
+ /**
289
+ * @deprecated Use `isMediaLibraryResource` instead.
290
+ * @beta
291
+ */
292
+ declare function isMediaLibrarySource(source: DocumentSource): source is MediaLibrarySource;
293
+ /**
294
+ * @deprecated Use `isCanvasResource` instead.
295
+ * @beta
296
+ */
297
+ declare function isCanvasSource(source: DocumentSource): source is CanvasSource;
298
+ /**
299
+ * Returns `true` when the config indicates the SDK is running inside a Studio.
300
+ * Checks the new `studio` field first, then falls back to the deprecated
301
+ * `studioMode.enabled` for backwards compatibility.
302
+ *
303
+ * @internal
304
+ */
305
+ declare function isStudioConfig(config: SanityConfig): boolean;
306
+ /**
307
+ * Represents a Sanity.io resource instance with its own configuration and lifecycle
308
+ *
309
+ * @public
310
+ */
311
+ interface SanityInstance {
312
+ /**
313
+ * Unique identifier for this instance
314
+ * @remarks Generated using crypto.randomUUID()
315
+ */
316
+ readonly instanceId: string;
317
+ /**
318
+ * Resolved configuration for this instance
319
+ */
320
+ readonly config: SanityConfig;
321
+ /**
322
+ * Checks if the instance has been disposed
323
+ * @returns true if dispose() has been called
324
+ */
325
+ isDisposed(): boolean;
326
+ /**
327
+ * Disposes the instance and cleans up associated resources
328
+ * @remarks Triggers all registered onDispose callbacks
329
+ */
330
+ dispose(): void;
331
+ /**
332
+ * Registers a callback to be invoked when the instance is disposed
333
+ * @param cb - Callback to execute on disposal
334
+ * @returns Function to unsubscribe the callback
335
+ */
336
+ onDispose(cb: () => void): () => void;
337
+ /**
338
+ * Gets the parent instance in the hierarchy
339
+ * @returns Parent instance or undefined if this is the root
340
+ * @deprecated The parent/child instance hierarchy is deprecated. Use a single SanityInstance instead.
341
+ */
342
+ getParent(): SanityInstance | undefined;
343
+ /**
344
+ * Creates a child instance with merged configuration
345
+ * @param config - Configuration to merge with parent values
346
+ * @deprecated The parent/child instance hierarchy is deprecated. Use a single SanityInstance instead.
347
+ */
348
+ createChild(config: SanityConfig): SanityInstance;
349
+ /**
350
+ * Traverses the instance hierarchy to find the first instance whose configuration
351
+ * matches the given target config using a shallow comparison.
352
+ * @param targetConfig - A partial configuration object containing key-value pairs to match.
353
+ * @returns The first matching instance or undefined if no match is found.
354
+ * @deprecated The parent/child instance hierarchy is deprecated. Use a single SanityInstance instead.
355
+ */
356
+ match(targetConfig: Partial<SanityConfig>): SanityInstance | undefined;
357
+ }
358
+ /**
359
+ * Creates a new Sanity resource instance
360
+ * @param config - Configuration for the instance (optional)
361
+ * @returns A configured SanityInstance
362
+ * @remarks When creating child instances, configurations are merged with parent values
363
+ *
364
+ * @public
365
+ */
366
+ declare function createSanityInstance(config?: SanityConfig): SanityInstance;
367
+ /**
368
+ * Represents a reactive store state container with multiple access patterns
369
+ */
370
+ interface StoreState<TState> {
371
+ /**
372
+ * Gets the current state value
373
+ *
374
+ * @remarks
375
+ * This is a direct synchronous accessor that doesn't trigger subscriptions
376
+ */
377
+ get: () => TState;
378
+ /**
379
+ * Updates the store state
380
+ * @param name - Action name for devtools tracking
381
+ * @param updatedState - New state value or updater function
382
+ *
383
+ * @remarks
384
+ * When providing a partial object, previous top-level keys not included in
385
+ * the update will be preserved.
386
+ */
387
+ set: (name: string, updatedState: Partial<TState> | ((s: TState) => Partial<TState>)) => void;
388
+ /**
389
+ * Observable stream of state changes
390
+ * @remarks
391
+ * - Emits immediately with current state on subscription
392
+ * - Shares underlying subscription between observers
393
+ * - Only emits when state reference changes
394
+ * - Completes when store is disposed
395
+ */
396
+ observable: Observable<TState>;
397
+ }
398
+ /**
399
+ * Context object provided to store initialization functions
400
+ */
401
+ interface StoreContext<TState, TKey = unknown> {
402
+ /**
403
+ * Sanity instance associated with this store
404
+ *
405
+ * @remarks
406
+ * Provides access to the Sanity configuration and instance lifecycle methods
407
+ */
408
+ instance: SanityInstance;
409
+ /**
410
+ * Reactive store state management utilities
411
+ *
412
+ * @remarks
413
+ * Contains methods for getting/setting state and observing changes
414
+ */
415
+ state: StoreState<TState>;
416
+ /**
417
+ * The key used to instantiate the store.
418
+ */
419
+ key: TKey;
420
+ }
421
+ /**
422
+ * Defines a store action that operates on a specific state type
423
+ */
424
+ type StoreAction<TState, TParams extends unknown[], TReturn, TKey = unknown> = (context: StoreContext<TState, TKey>, ...params: TParams) => TReturn;
425
+ /**
426
+ * Represents a store action that has been bound to a specific store instance
427
+ */
428
+ type BoundStoreAction<_TState, TParams extends unknown[], TReturn> = (instance: SanityInstance, ...params: TParams) => TReturn;
429
+ /**
430
+ * Represents the various states the authentication type can be in.
431
+ *
432
+ * @public
433
+ */
434
+ declare enum AuthStateType {
435
+ LOGGED_IN = "logged-in",
436
+ LOGGING_IN = "logging-in",
437
+ ERROR = "error",
438
+ LOGGED_OUT = "logged-out"
439
+ }
440
+ /**
441
+ * Represents the various states the authentication can be in.
442
+ *
443
+ * @public
444
+ */
445
+ type AuthState = LoggedInAuthState | LoggedOutAuthState | LoggingInAuthState | ErrorAuthState;
446
+ /**
447
+ * Logged-in state from the auth state.
448
+ * @public
449
+ */
450
+ type LoggedInAuthState = {
451
+ type: AuthStateType.LOGGED_IN;
452
+ token: string;
453
+ currentUser: CurrentUser | null;
454
+ lastTokenRefresh?: number;
455
+ };
456
+ /**
457
+ * Logged-out state from the auth state.
458
+ * @public
459
+ */
460
+ type LoggedOutAuthState = {
461
+ type: AuthStateType.LOGGED_OUT;
462
+ isDestroyingSession: boolean;
463
+ };
464
+ /**
465
+ * Logging-in state from the auth state.
466
+ * @public
467
+ */
468
+ type LoggingInAuthState = {
469
+ type: AuthStateType.LOGGING_IN;
470
+ isExchangingToken: boolean;
471
+ };
472
+ /**
473
+ * Error state from the auth state.
474
+ * @public
475
+ */
476
+ type ErrorAuthState = {
477
+ type: AuthStateType.ERROR;
478
+ error: unknown;
479
+ };
480
+ /**
481
+ * Represents the various states the authentication can be in.
482
+ *
483
+ * @public
484
+ */
485
+ interface DashboardContext {
486
+ mode?: string;
487
+ env?: string;
488
+ orgId?: string;
489
+ }
490
+ /**
491
+ * The method of authentication used.
492
+ * @internal
493
+ */
494
+ type AuthMethodOptions = 'localstorage' | 'cookie' | undefined;
495
+ /**
496
+ * @public
497
+ */
498
+ interface AuthStoreState {
499
+ authState: AuthState;
500
+ providers?: AuthProvider[];
501
+ options: {
502
+ initialLocationHref: string;
503
+ clientFactory: (config: ClientConfig) => SanityClient;
504
+ customProviders: AuthConfig['providers'];
505
+ storageKey: string;
506
+ storageArea: Storage | undefined;
507
+ apiHost: string | undefined;
508
+ loginUrl: string;
509
+ callbackUrl: string | undefined;
510
+ providedToken: string | undefined;
511
+ authMethod: AuthMethodOptions;
512
+ };
513
+ dashboardContext?: DashboardContext;
514
+ }
515
+ /**
516
+ * @public
517
+ */
518
+ declare const getCurrentUserState: BoundStoreAction<AuthStoreState, [], import("../_exports").StateSource<CurrentUser | null>>;
519
+ /**
520
+ * @public
521
+ */
522
+ declare const getTokenState: BoundStoreAction<AuthStoreState, [], import("../_exports").StateSource<string | null>>;
523
+ /**
524
+ * @public
525
+ */
526
+ declare const getLoginUrlState: BoundStoreAction<AuthStoreState, [], import("../_exports").StateSource<string>>;
527
+ /**
528
+ * @public
529
+ */
530
+ declare const getAuthState: BoundStoreAction<AuthStoreState, [], import("../_exports").StateSource<AuthState>>;
531
+ /**
532
+ * @public
533
+ */
534
+ declare const getDashboardOrganizationId: BoundStoreAction<AuthStoreState, [], import("../_exports").StateSource<string | undefined>>;
535
+ /**
536
+ * Returns a state source indicating if the SDK is running within a dashboard context.
537
+ * @public
538
+ */
539
+ declare const getIsInDashboardState: BoundStoreAction<AuthStoreState, [], import("../_exports").StateSource<boolean>>;
540
+ /**
541
+ * Action to explicitly set the authentication token.
542
+ * Used internally by the Comlink token refresh.
543
+ * @internal
544
+ */
545
+ declare const setAuthToken: BoundStoreAction<AuthStoreState, [token: string | null], void>;
546
+ /** @internal */
547
+ type ApiErrorBody = {
548
+ error?: {
549
+ type?: string;
550
+ description?: string;
551
+ };
552
+ type?: string;
553
+ description?: string;
554
+ message?: string;
555
+ };
556
+ /** @internal Extracts the structured API error body from a ClientError, if present. */
557
+ declare function getClientErrorApiBody(error: ClientError): ApiErrorBody | undefined;
558
+ /** @internal Returns the error type string from an API error body, if available. */
559
+ declare function getClientErrorApiType(error: ClientError): string | undefined;
560
+ /** @internal Returns the error description string from an API error body, if available. */
561
+ declare function getClientErrorApiDescription(error: ClientError): string | undefined;
562
+ /** @internal True if the error represents a projectUserNotFoundError. */
563
+ declare function isProjectUserNotFoundClientError(error: ClientError): boolean;
564
+ /**
565
+ * Generates a GROQ projection for preview data without requiring a schema.
566
+ * Uses common field names to make educated guesses about which fields to use.
567
+ *
568
+ * @internal
569
+ */
570
+ declare const PREVIEW_PROJECTION: string;
571
+ /**
572
+ * @public
573
+ * The result of a projection query
574
+ */
575
+ interface ProjectionValuePending<TValue extends object> {
576
+ data: TValue | null;
577
+ isPending: boolean;
578
+ }
579
+ /**
580
+ * @public
581
+ * @deprecated
582
+ * Template literals are a bit too limited, so this type is deprecated.
583
+ * Use `string` instead. Projection strings are validated at runtime.
584
+ */
585
+ type ValidProjection = string;
586
+ interface DocumentStatus {
587
+ lastEditedDraftAt?: string;
588
+ lastEditedPublishedAt?: string;
589
+ lastEditedVersionAt?: string;
590
+ }
591
+ /**
592
+ *
593
+ * @internal
594
+ */
595
+ interface PreviewQueryResult {
596
+ _id: string;
597
+ _type: string;
598
+ _updatedAt: string;
599
+ titleCandidates: Record<string, unknown>;
600
+ subtitleCandidates: Record<string, unknown>;
601
+ media?: PreviewMedia | null;
602
+ _status?: DocumentStatus;
603
+ }
604
+ /**
605
+ * Represents a media asset in a preview.
606
+ *
607
+ * @public
608
+ */
609
+ interface PreviewMedia {
610
+ type: 'image-asset';
611
+ _ref: string;
612
+ url: string;
613
+ }
614
+ /**
615
+ * Represents the set of values displayed as a preview for a given Sanity document.
616
+ * This includes a primary title, a secondary subtitle, an optional piece of media associated
617
+ * with the document, and the document's status.
618
+ *
619
+ * @public
620
+ */
621
+ interface PreviewValue {
622
+ /**
623
+ * The primary text displayed for the document preview.
624
+ */
625
+ title: string;
626
+ /**
627
+ * A secondary line of text providing additional context about the document.
628
+ */
629
+ subtitle?: string;
630
+ /**
631
+ * An optional piece of media representing the document within its preview.
632
+ * Currently, only image assets are available.
633
+ */
634
+ media?: PreviewMedia | null;
635
+ /**
636
+ * The status of the document.
637
+ */
638
+ _status?: {
639
+ /** The date of the last published edit */
640
+ lastEditedPublishedAt?: string;
641
+ /** The date of the last draft edit */
642
+ lastEditedDraftAt?: string;
643
+ };
644
+ }
645
+ /**
646
+ * Represents the current state of a preview value along with a flag indicating whether
647
+ * the preview data is still being fetched or is fully resolved.
648
+ *
649
+ * The tuple contains a preview value or null, and a boolean indicating if the data is
650
+ * pending. A `true` value means a fetch is ongoing; `false` indicates that the
651
+ * currently provided preview value is up-to-date.
652
+ *
653
+ * @public
654
+ */
655
+ type ValuePending<T> = {
656
+ data: T | null;
657
+ isPending: boolean;
658
+ };
659
+ /**
660
+ * @public
661
+ * @deprecated This interface is kept for backwards compatibility but is no longer used internally.
662
+ * Preview state is now stored in the projection store.
663
+ */
664
+ interface PreviewStoreState {
665
+ values: { [TDocumentId in string]?: ValuePending<PreviewValue>; };
666
+ subscriptions: { [TDocumentId in string]?: { [TSubscriptionId in string]?: true; }; };
667
+ }
668
+ /**
669
+ * Transforms a projection result (with titleCandidates, subtitleCandidates, media)
670
+ * into a PreviewValue (with title, subtitle, media).
671
+ *
672
+ * @param projectionResult - The raw projection result from GROQ
673
+ * @param instance - The Sanity instance to use for client configuration
674
+ * @param resource - Data resource for the preview
675
+ * @internal
676
+ */
677
+ declare function transformProjectionToPreview(instance: SanityInstance, projectionResult: PreviewQueryResult, resource?: DocumentResource): PreviewValue;
678
+ /**
679
+ * Represents a reactive state source that provides synchronized access to store data
680
+ *
681
+ * @remarks
682
+ * Designed to work with React's useSyncExternalStore hook. Provides three ways to access data:
683
+ * 1. `getCurrent()` for synchronous current value access
684
+ * 2. `subscribe()` for imperative change notifications
685
+ * 3. `observable` for reactive stream access
686
+ *
687
+ * @public
688
+ */
689
+ interface StateSource<T> {
690
+ /**
691
+ * Subscribes to state changes with optional callback
692
+ * @param onStoreChanged - Called whenever relevant state changes occur
693
+ * @returns Unsubscribe function to clean up the subscription
694
+ */
695
+ subscribe: (onStoreChanged?: () => void) => () => void;
696
+ /**
697
+ * Gets the current derived state value
698
+ *
699
+ * @remarks
700
+ * Safe to call without subscription. Will always return the latest value
701
+ * based on the current store state and selector parameters.
702
+ */
703
+ getCurrent: () => T;
704
+ /**
705
+ * Observable stream of state values
706
+ *
707
+ * @remarks
708
+ * Shares a single underlying subscription between all observers. Emits:
709
+ * - Immediately with current value on subscription
710
+ * - On every relevant state change
711
+ * - Errors if selector throws
712
+ */
713
+ observable: Observable<T>;
714
+ }
715
+ /**
716
+ * Context passed to selectors when deriving state
717
+ *
718
+ * @remarks
719
+ * Provides access to both the current state value and the Sanity instance,
720
+ * allowing selectors to use configuration values when computing derived state.
721
+ * The context is memoized for each state object and instance combination
722
+ * to optimize performance and prevent unnecessary recalculations.
723
+ *
724
+ * @example
725
+ * ```ts
726
+ * // Using both state and instance in a selector (psuedo example)
727
+ * const getUserByProjectId = createStateSourceAction(
728
+ * ({ state, instance }: SelectorContext<UsersState>, options?: ProjectHandle) => {
729
+ * const allUsers = state.users
730
+ * const projectId = options?.projectId ?? instance.config.projectId
731
+ * return allUsers.filter(user => user.projectId === projectId)
732
+ * }
733
+ * )
734
+ * ```
735
+ */
736
+ interface SelectorContext<TState> {
737
+ /**
738
+ * The current state object from the store
739
+ */
740
+ state: TState;
741
+ /**
742
+ * The Sanity instance associated with this state
743
+ */
744
+ instance: SanityInstance;
745
+ }
746
+ /**
747
+ * Function type for selecting derived state from store state and parameters
748
+ * @public
749
+ */
750
+ type Selector<TState, TParams extends unknown[], TReturn> = (context: SelectorContext<TState>, ...params: TParams) => TReturn;
751
+ /**
752
+ * @beta
753
+ */
754
+ interface QueryOptions<TQuery extends string = string, TDataset extends string = string, TProjectId extends string = string> extends Pick<ResponseQueryOptions, 'useCdn' | 'cache' | 'next' | 'cacheMode' | 'tag'>, DatasetHandle<TDataset, TProjectId> {
755
+ query: TQuery;
756
+ params?: Record<string, unknown>;
757
+ }
758
+ /**
759
+ * @beta
760
+ */
761
+ interface ResolveQueryOptions<TQuery extends string = string, TDataset extends string = string, TProjectId extends string = string> extends QueryOptions<TQuery, TDataset, TProjectId> {
762
+ signal?: AbortSignal;
763
+ }
764
+ /** @beta */
765
+ declare const getQueryKey: (options: QueryOptions) => string;
766
+ /** @beta */
767
+ declare const parseQueryKey: (key: string) => QueryOptions;
768
+ /**
769
+ * Returns the state source for a query.
770
+ *
771
+ * This function returns a state source that represents the current result of a GROQ query.
772
+ * Subscribing to the state source will instruct the SDK to fetch the query (if not already fetched)
773
+ * and will keep the query live using the Live content API (considering sync tags) to provide up-to-date results.
774
+ * When the last subscriber is removed, the query state is automatically cleaned up from the store.
775
+ *
776
+ * Note: This functionality is for advanced users who want to build their own framework integrations.
777
+ * Our SDK also provides a React integration (useQuery hook) for convenient usage.
778
+ *
779
+ * Note: Automatic cleanup can interfere with React Suspense because if a component suspends while being the only subscriber,
780
+ * cleanup might occur unexpectedly. In such cases, consider using `resolveQuery` instead.
781
+ *
782
+ * @beta
783
+ */
784
+ declare function getQueryState<TQuery extends string = string, TDataset extends string = string, TProjectId extends string = string>(instance: SanityInstance, queryOptions: QueryOptions<TQuery, TDataset, TProjectId>): StateSource<SanityQueryResult<TQuery, `${TProjectId}.${TDataset}`> | undefined>;
785
+ /** @beta */
786
+ declare function getQueryState<TData>(instance: SanityInstance, queryOptions: QueryOptions): StateSource<TData | undefined>;
787
+ /** @beta */
788
+ declare function getQueryState(instance: SanityInstance, queryOptions: QueryOptions): StateSource<unknown>;
789
+ /**
790
+ * Resolves the result of a query without registering a lasting subscriber.
791
+ *
792
+ * This function fetches the result of a GROQ query and returns a promise that resolves with the query result.
793
+ * It registers a temporary subscriber for the lifetime of the resolution (released shortly after the promise
794
+ * settles), so the query state participates in normal cleanup even when no lasting subscriber ever attaches —
795
+ * e.g. when a suspended component errors before committing. This makes it ideal for use with React Suspense,
796
+ * where the returned promise is thrown to delay rendering until the query result becomes available.
797
+ * Once the promise resolves, it is expected that a real subscriber will be added via `getQueryState` to manage ongoing updates.
798
+ *
799
+ * Additionally, an optional AbortSignal can be provided to cancel the query and immediately clear the associated state
800
+ * if there are no other active subscribers.
801
+ *
802
+ * @beta
803
+ */
804
+ declare function resolveQuery<TQuery extends string = string, TDataset extends string = string, TProjectId extends string = string>(instance: SanityInstance, queryOptions: ResolveQueryOptions<TQuery, TDataset, TProjectId>): Promise<SanityQueryResult<TQuery, `${TProjectId}.${TDataset}`>>;
805
+ /** @beta */
806
+ declare function resolveQuery<TData>(instance: SanityInstance, queryOptions: ResolveQueryOptions): Promise<TData>;
807
+ /**
808
+ * Identifies cached data for invalidation, matched across the whole store.
809
+ * A fetcher declares the tags each of its entries carries (via
810
+ * {@link FetcherDefinition.tags}); a mutation declares the tags it invalidates
811
+ * (via {@link MutationDefinition.invalidates}).
812
+ *
813
+ * When invalidating,`{type: 'organization'}` matches every entry carrying any `organization` tag;
814
+ * `{type: 'organization', id: 'abc'}` matches only entries carrying that exact pair.
815
+ * List entries carry a `{type, id: 'LIST'}` sentinel plus one tag per item, so a
816
+ * "create" mutation can refetch lists without touching unrelated detail entries.
817
+ *
818
+ * @internal
819
+ */
820
+ interface CacheTag {
821
+ type: string;
822
+ /** Specific id, or the `'LIST'` sentinel for list entries */
823
+ id?: string | number;
824
+ }
825
+ /**
826
+ * The reactive value of one cache entry, as exposed by
827
+ * {@link Fetcher.getState}. React hooks consume this envelope directly.
828
+ * Discriminated on `status`, so narrowing gives correctly-typed `data`:
829
+ * `'success'` is the only arm carrying data, and a background failure while
830
+ * data still renders surfaces on the `'success'` arm's `error`.
831
+ *
832
+ * `isFetching` is common to all arms: a fetch for this entry is in flight
833
+ * (initial load, revalidation, or poll).
834
+ *
835
+ * @internal
836
+ */
837
+ type FetcherSnapshot<TData> = {
838
+ /** No data yet — initial fetch in flight or not started */
839
+ status: 'pending';
840
+ data: undefined;
841
+ error: undefined;
842
+ isFetching: boolean;
843
+ dataUpdatedAt: undefined;
844
+ } | {
845
+ /** Data available — possibly stale, possibly revalidating */
846
+ status: 'success';
847
+ data: TData;
848
+ /** Most recent background-fetch failure, cleared by the next successful fetch */
849
+ error: unknown;
850
+ isFetching: boolean;
851
+ /** Epoch ms of the fetch that produced `data` */
852
+ dataUpdatedAt: number;
853
+ } | {
854
+ /** The last fetch failed and no data exists to serve */
855
+ status: 'error';
856
+ data: undefined;
857
+ error: unknown;
858
+ isFetching: boolean;
859
+ dataUpdatedAt: undefined;
860
+ };
861
+ /**
862
+ * A typed description of one cached, parameterised read of an API response —
863
+ * here is a single cache per {@link SanityInstance}; every definition registers
864
+ * into it and its `name` namespaces its keys. A list and a detail read are two
865
+ * definitions over the one cache, not two caches.
866
+ *
867
+ * Entry lifecycle: fresh → stale → collected. Fresh entries are served from
868
+ * cache with no fetch; stale entries are served immediately and revalidated in
869
+ * the background (stale-while-revalidate); collected entries are removed once
870
+ * their `gcTime` elapses after the last unsubscribe, so the next subscriber
871
+ * suspends.
872
+ *
873
+ * @internal
874
+ */
875
+ interface FetcherDefinition<TParams extends unknown[], TData> {
876
+ /** Namespaces this fetcher's keys in the shared cache; used for devtools and request-tag derivation */
877
+ name: string;
878
+ /**
879
+ * Fetches the data once. Return an observable that emits the result and
880
+ * completes.
881
+ */
882
+ fetch: (instance: SanityInstance) => (...params: TParams) => Observable<TData>;
883
+ /** Converts params into the cache key that identifies an entry (unique within `name`) */
884
+ getKey: (instance: SanityInstance, ...params: TParams) => string;
885
+ /**
886
+ * Cache tags each entry carries, for cache-wide invalidation. A static array,
887
+ * or a function of the fetched data when tags depend on the response (e.g. one
888
+ * tag per list item).
889
+ */
890
+ tags?: CacheTag[] | ((data: TData, ...params: TParams) => CacheTag[]);
891
+ /**
892
+ * How long fetched data is fresh, in ms. Fresh entries never refetch;
893
+ * stale entries serve cached data and revalidate in the background.
894
+ * @defaultValue 30_000
895
+ */
896
+ staleTime?: number;
897
+ /**
898
+ * How long an entry survives after its last unsubscribe before it is garbage
899
+ * collected, in ms. The clock starts at the last unsubscribe — entries with
900
+ * active subscribers are never collected.
901
+ * @defaultValue 300_000
902
+ */
903
+ gcTime?: number;
904
+ /**
905
+ * Refetch on this interval (ms) while the entry has at least one subscriber,
906
+ * independent of staleness. Ticks are skipped while `document.hidden`. Off by default.
907
+ */
908
+ refetchInterval?: number;
909
+ /**
910
+ * Consulted once, when an entry is being created and no cached data exists for
911
+ * it. Return data pulled from another fetcher in the same cache — read via its
912
+ * ordinary `getState(instance, ...).getCurrent()`, e.g. a detail entry pulling
913
+ * its item out of the cached list — to skip or soften the initial fetch.
914
+ * `dataUpdatedAt` must be when the source data was fetched, not "now": staleness
915
+ * is measured from it. Return `undefined` to fetch as normal.
916
+ */
917
+ initialData?: (instance: SanityInstance, ...params: TParams) => {
918
+ data: TData;
919
+ dataUpdatedAt: number;
920
+ } | undefined;
921
+ }
922
+ /**
923
+ * A typed handle over the shared fetcher cache, returned by
924
+ * {@link defineFetcher}. It is a view onto the entries under its definition's
925
+ * `name`, not a cache of its own.
926
+ *
927
+ * @internal
928
+ */
929
+ interface Fetcher<TParams extends unknown[], TData> {
930
+ /** Reactive envelope for one entry. Subscribing triggers fetching per staleness rules. */
931
+ getState: (instance: SanityInstance, ...params: TParams) => StateSource<FetcherSnapshot<TData>>;
932
+ /**
933
+ * Resolves with the entry's first available data — the promise a suspending
934
+ * component throws. Rejects if the initial fetch fails.
935
+ */
936
+ resolveState: (instance: SanityInstance, ...params: TParams) => Promise<TData>;
937
+ /**
938
+ * Marks the entry stale. If it has active subscribers it refetches immediately;
939
+ * otherwise it refetches on next subscribe.
940
+ */
941
+ invalidate: (instance: SanityInstance, ...params: TParams) => void;
942
+ /** {@link Fetcher.invalidate} for every entry under this fetcher's `name`. */
943
+ invalidateAll: (instance: SanityInstance) => void;
944
+ /**
945
+ * Imperative fetch, bypassing staleness. Dedupes against an in-flight fetch.
946
+ * Resolves with the entry's data as held by the cache once the fetch settles.
947
+ */
948
+ refetch: (instance: SanityInstance, ...params: TParams) => Promise<TData>;
949
+ /**
950
+ * Writes an entry's data directly. Returns an undo handle — inside a
951
+ * mutation's `onMutate` these writes are recorded and rolled back automatically
952
+ * on failure.
953
+ */
954
+ setData: (instance: SanityInstance, params: TParams, updater: TData | ((current: TData | undefined) => TData)) => {
955
+ undo: () => void;
956
+ };
957
+ }
958
+ /**
959
+ * Writes an entry's data in any fetcher. Passed to {@link MutationDefinition}
960
+ * callbacks — mutations are the only holders of arbitrary write access; read
961
+ * fetchers pull their data (see {@link FetcherDefinition.initialData}). Inside
962
+ * `onMutate`, every write is recorded and undone automatically if the mutation
963
+ * fails.
964
+ *
965
+ * @internal
966
+ */
967
+ type CacheWriter = <TParams extends unknown[], TData>(fetcher: Fetcher<TParams, TData>, params: TParams, updater: TData | ((current: TData | undefined) => TData)) => void;
968
+ /**
969
+ * Resolves when the mutation settles on the server. `invalidated` tracks the
970
+ * background reconciliation — the refetches triggered by
971
+ * {@link MutationDefinition.invalidates} — for the rare caller that must wait for
972
+ * full reconvergence rather than server settlement.
973
+ *
974
+ * @internal
975
+ */
976
+ interface MutationResult<TResult> {
977
+ /** The server response */
978
+ data: TResult;
979
+ /** Settles when the refetches of matched active entries complete */
980
+ invalidated: Promise<void>;
981
+ }
982
+ /**
983
+ * Defines a mutation with optimistic cache updates. Lifecycle:
984
+ *
985
+ * 1. `onMutate` applies optimistic writes synchronously — the UI updates before
986
+ * the request leaves. Each entry carries a version counter that increments on
987
+ * every write. An optimistic write bumps the counter, so a revalidation already
988
+ * in flight lands "out of date" and is discarded rather than clobbering the
989
+ * optimistic write.
990
+ * 2. The request runs. On failure, recorded writes are rolled back automatically
991
+ * — the cache is restored exactly, so failure ends the lifecycle here.
992
+ * 3. On success, `onSuccess` may write the server response into the cache directly.
993
+ * 4. On success, `invalidates` tags mark matching entries across the cache
994
+ * stale (active entries refetch), so the cache reconverges on server truth
995
+ * even if the optimistic shape was wrong.
996
+ *
997
+ * @internal
998
+ */
999
+ interface MutationDefinition<TInput, TResult> {
1000
+ /** Unique mutation name, used for devtools and request-tag derivation */
1001
+ name: string;
1002
+ /** Creates the observable that performs the server mutation */
1003
+ mutationFn: (instance: SanityInstance) => (input: TInput) => Observable<TResult>;
1004
+ /** Optimistic cache writes, applied synchronously before the request */
1005
+ onMutate?: (write: CacheWriter, input: TInput) => void;
1006
+ /** Reconcile the cache with the server response, avoiding a refetch round-trip */
1007
+ onSuccess?: (write: CacheWriter, result: TResult, input: TInput) => void;
1008
+ /**
1009
+ * Cache tags to invalidate on success. Failure invalidates nothing: recorded
1010
+ * optimistic writes roll back to the exact pre-mutation cache, and any
1011
+ * server-side ambiguity (e.g. timeout after commit) heals via `staleTime`.
1012
+ * A static array, or a function of the result/input.
1013
+ */
1014
+ invalidates?: CacheTag[] | ((result: TResult, input: TInput) => CacheTag[]);
1015
+ }
1016
+ /**
1017
+ * Registers a fetcher definition against the shared cache and returns its typed
1018
+ * handle.
1019
+ *
1020
+ * @internal
1021
+ */
1022
+ declare function defineFetcher<TParams extends unknown[], TData>(definition: FetcherDefinition<TParams, TData>): Fetcher<TParams, TData>;
1023
+ /**
1024
+ * Creates a bound mutation from its definition. The returned action resolves at
1025
+ * server settlement — not after invalidation refetches, which run as background
1026
+ * reconciliation (see {@link MutationResult.invalidated}).
1027
+ *
1028
+ * @internal
1029
+ */
1030
+ declare function defineMutation<TInput, TResult>(definition: MutationDefinition<TInput, TResult>): (instance: SanityInstance, input: TInput) => Promise<MutationResult<TResult>>;
1031
+ /**
1032
+ * @public
1033
+ */
1034
+ interface SanityUser {
1035
+ sanityUserId: string;
1036
+ profile: UserProfile;
1037
+ memberships: Membership[];
1038
+ }
1039
+ /**
1040
+ * @public
1041
+ */
1042
+ interface Membership {
1043
+ addedAt?: string;
1044
+ resourceType: string;
1045
+ resourceId: string;
1046
+ roleNames: Array<string>;
1047
+ lastSeenAt?: string | null;
1048
+ }
1049
+ /**
1050
+ * @public
1051
+ */
1052
+ interface UserProfile {
1053
+ id: string;
1054
+ displayName: string;
1055
+ email: string;
1056
+ familyName?: string;
1057
+ givenName?: string;
1058
+ middleName?: string | null;
1059
+ imageUrl?: string;
1060
+ provider: string;
1061
+ tosAcceptedAt?: string;
1062
+ createdAt: string;
1063
+ updatedAt?: string;
1064
+ isCurrentUser?: boolean;
1065
+ providerId?: string;
1066
+ }
1067
+ /**
1068
+ * @public
1069
+ */
1070
+ interface GetUsersOptions extends ProjectHandle {
1071
+ resourceType?: 'organization' | 'project';
1072
+ batchSize?: number;
1073
+ organizationId?: string;
1074
+ userId?: string;
1075
+ }
1076
+ /**
1077
+ * @public
1078
+ */
1079
+ interface UsersGroupState {
1080
+ subscriptions: string[];
1081
+ totalCount?: number;
1082
+ nextCursor?: string | null;
1083
+ lastLoadMoreRequest?: string;
1084
+ users?: SanityUser[];
1085
+ error?: unknown;
1086
+ }
1087
+ /**
1088
+ * @public
1089
+ */
1090
+ interface SanityUserResponse {
1091
+ data: SanityUser[];
1092
+ totalCount: number;
1093
+ nextCursor: string | null;
1094
+ }
1095
+ /**
1096
+ * @public
1097
+ */
1098
+ interface UsersStoreState {
1099
+ users: { [TUsersKey in string]?: UsersGroupState; };
1100
+ error?: unknown;
1101
+ }
1102
+ /**
1103
+ * @public
1104
+ */
1105
+ interface ResolveUsersOptions extends GetUsersOptions {
1106
+ signal?: AbortSignal;
1107
+ }
1108
+ /**
1109
+ * @public
1110
+ */
1111
+ interface GetUserOptions extends ProjectHandle {
1112
+ userId: string;
1113
+ resourceType?: 'organization' | 'project';
1114
+ organizationId?: string;
1115
+ }
1116
+ /**
1117
+ * @public
1118
+ */
1119
+ interface ResolveUserOptions extends GetUserOptions {
1120
+ signal?: AbortSignal;
1121
+ }
1122
+ /** @internal */
1123
+ declare const getUsersKey: (instance: SanityInstance, { resourceType, organizationId, batchSize, projectId, userId }?: GetUsersOptions) => string;
1124
+ /** @internal */
1125
+ declare const parseUsersKey: (key: string) => {
1126
+ batchSize: number;
1127
+ resourceType?: "organization" | "project";
1128
+ projectId?: string;
1129
+ organizationId?: string;
1130
+ userId?: string;
1131
+ };
1132
+ /**
1133
+ * Creates a GROQ search filter string (`[@] match text::query("...")`)
1134
+ * from a raw search query string.
1135
+ *
1136
+ * It applies wildcard ('*') logic to the last eligible token and escapes
1137
+ * double quotes within the search term.
1138
+ *
1139
+ * If the input query is empty or only whitespace, it returns an empty string.
1140
+ *
1141
+ * @param query - The raw input search string.
1142
+ * @returns The GROQ search filter string, or an empty string.
1143
+ * @internal
1144
+ */
1145
+ declare function createGroqSearchFilter(query: string): string;
1146
+ export { getIsInDashboardState as $, transformProjectionToPreview as A, isDatasetSource as At, getClientErrorApiBody as B, QueryOptions as C, ReleasePerspective as Ct, resolveQuery as D, isCanvasResource as Dt, parseQueryKey as E, TokenSource as Et, ValuePending as F, AuthStoreState as G, getClientErrorApiType as H, ProjectionValuePending as I, LoggedOutAuthState as J, ErrorAuthState as K, ValidProjection as L, PreviewQueryResult as M, isMediaLibrarySource as Mt, PreviewStoreState as N, AuthConfig as Nt, Selector as O, isCanvasSource as Ot, PreviewValue as P, AuthProvider as Pt, getDashboardOrganizationId as Q, PREVIEW_PROJECTION as R, defineMutation as S, ReleaseHandle as St, getQueryState as T, StudioConfig as Tt, isProjectUserNotFoundClientError as U, getClientErrorApiDescription as V, AuthState as W, getAuthState as X, LoggingInAuthState as Y, getCurrentUserState as Z, FetcherDefinition as _, DocumentTypeHandle as _t, GetUsersOptions as a, StoreAction as at, MutationResult as b, PerspectiveHandle as bt, ResolveUsersOptions as c, isStudioConfig as ct, UserProfile as d, DatasetHandle as dt, getLoginUrlState as et, UsersGroupState as f, DatasetResource as ft, Fetcher as g, DocumentSource as gt, CacheWriter as h, DocumentResource as ht, GetUserOptions as i, BoundStoreAction as it, PreviewMedia as j, isMediaLibraryResource as jt, StateSource as k, isDatasetResource as kt, SanityUser as l, CanvasResource as lt, CacheTag as m, DocumentHandle as mt, getUsersKey as n, setAuthToken as nt, Membership as o, SanityInstance as ot, UsersStoreState as p, DatasetSource as pt, LoggedInAuthState as q, parseUsersKey as r, AuthStateType as rt, ResolveUserOptions as s, createSanityInstance as st, createGroqSearchFilter as t, getTokenState as tt, SanityUserResponse as u, CanvasSource as ut, FetcherSnapshot as v, MediaLibraryResource as vt, getQueryKey as w, SanityConfig as wt, defineFetcher as x, ProjectHandle as xt, MutationDefinition as y, MediaLibrarySource as yt, ApiErrorBody as z };
1147
+ //# sourceMappingURL=createGroqSearchFilter.d.ts.map