@sanity/sdk 2.1.0 → 2.1.1-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,2635 +1,1960 @@
1
- import {AuthStoreState as AuthStoreState_2} from './authStore'
2
- import {BoundStoreAction} from '../store/createActionBinder'
3
- import {BoundStoreAction as BoundStoreAction_2} from '../../store/createActionBinder'
4
- import {CanvasResource} from '@sanity/message-protocol'
5
- import {ChannelInput} from '@sanity/comlink'
6
- import {ChannelInstance} from '@sanity/comlink'
7
- import {ClientConfig} from '@sanity/client'
8
- import {ClientPerspective} from '@sanity/client'
9
- import {Controller} from '@sanity/comlink'
10
- import {CurrentUser} from '@sanity/types'
11
- import {DatasetsResponse} from '@sanity/client'
12
- import {DocumentPermissionsResult as DocumentPermissionsResult_2} from './permissions'
13
- import {FetcherStoreState as FetcherStoreState_2} from '../_exports'
14
- import {getIndexForKey} from '@sanity/json-match'
15
- import {getPathDepth} from '@sanity/json-match'
16
- import {joinPaths} from '@sanity/json-match'
17
- import {jsonMatch} from '@sanity/json-match'
18
- import {ListenEvent} from '@sanity/client'
19
- import {MediaResource} from '@sanity/message-protocol'
20
- import {Message} from '@sanity/comlink'
21
- import {Mutation} from '@sanity/types'
22
- import {Node as Node_2} from '@sanity/comlink'
23
- import {NodeInput} from '@sanity/comlink'
24
- import {Observable} from 'rxjs'
25
- import {PatchMutation} from '@sanity/mutate/_unstable_store'
26
- import {PatchOperations} from '@sanity/types'
27
- import {PreviewStoreState as PreviewStoreState_2} from './previewStore'
28
- import {ResponseQueryOptions} from '@sanity/client'
29
- import {Role} from '@sanity/types'
30
- import {SanityClient} from '@sanity/client'
31
- import {SanityDocument} from '@sanity/types'
32
- import {SanityDocument as SanityDocument_2} from 'groq'
33
- import {SanityDocument as SanityDocument_3} from '@sanity/client'
34
- import {SanityDocumentLike} from '@sanity/types'
35
- import {SanityProject as SanityProject_2} from '@sanity/client'
36
- import {SanityProjectionResult} from 'groq'
37
- import {SanityQueryResult} from 'groq'
38
- import {SanityUser as SanityUser_2} from './types'
39
- import {slicePath} from '@sanity/json-match'
40
- import {StackablePerspective} from '@sanity/client'
41
- import {StateSource as StateSource_2} from '../_exports'
42
- import {StateSource as StateSource_3} from '../../_exports'
43
- import {Status} from '@sanity/comlink'
44
- import {stringifyPath} from '@sanity/json-match'
45
- import {StudioResource} from '@sanity/message-protocol'
46
- import {Subject} from 'rxjs'
47
- import {ValuePending as ValuePending_2} from './previewStore'
48
-
49
- declare interface AccessAttributeNode extends BaseNode {
50
- type: 'AccessAttribute'
51
- base?: ExprNode
52
- name: string
53
- }
54
-
55
- declare interface AccessElementNode extends BaseNode {
56
- type: 'AccessElement'
57
- base: ExprNode
58
- index: number
59
- }
60
-
1
+ import * as _sanity_client12 from "@sanity/client";
2
+ import { ClientConfig, ClientPerspective, ListenEvent, ResponseQueryOptions, SanityClient, SanityDocument as SanityDocument$1, SanityProject as SanityProject$1, StackablePerspective } from "@sanity/client";
3
+ import { Observable, Subject } from "rxjs";
4
+ import { CurrentUser, CurrentUser as CurrentUser$1, Mutation, PatchOperations, Role, SanityDocument, SanityDocument as SanityDocument$2, SanityDocumentLike } from "@sanity/types";
5
+ import * as _sanity_comlink3 from "@sanity/comlink";
6
+ import { ChannelInput, ChannelInstance, Controller, Message, Node, NodeInput, Status } from "@sanity/comlink";
7
+ import { PatchMutation } from "@sanity/mutate/_unstable_store";
8
+ import { SanityDocument as SanityDocument$3, SanityProjectionResult, SanityQueryResult } from "groq";
9
+ import { CanvasResource, MediaResource, StudioResource } from "@sanity/message-protocol";
10
+ import { getIndexForKey, getPathDepth, joinPaths, jsonMatch, slicePath, stringifyPath } from "@sanity/json-match";
61
11
  /**
62
- * @beta
63
- * Event emitted when a precondition to applying an action fails.
64
- * (For example: when trying to edit a document that no longer exists.)
12
+ * Represents the various states the authentication type can be in.
13
+ *
14
+ * @public
65
15
  */
66
- export declare interface ActionErrorEvent {
67
- type: 'error'
68
- documentId: string
69
- transactionId: string
70
- message: string
71
- error: unknown
72
- }
73
-
74
- declare type ActionMap = {
75
- create: 'sanity.action.document.version.create'
76
- discard: 'sanity.action.document.version.discard'
77
- unpublish: 'sanity.action.document.unpublish'
78
- delete: 'sanity.action.document.delete'
79
- edit: 'sanity.action.document.edit'
80
- publish: 'sanity.action.document.publish'
81
- }
82
-
83
- /** @beta */
84
- export declare interface ActionsResult<TDocument extends SanityDocument_2 = SanityDocument_2> {
85
- transactionId: string
86
- documents: DocumentSet<TDocument>
87
- previous: DocumentSet<TDocument>
88
- previousRevs: {
89
- [documentId: string]: string | undefined
90
- }
91
- appeared: string[]
92
- updated: string[]
93
- disappeared: string[]
94
- submitted: () => ReturnType<SanityClient['action']>
95
- }
96
-
97
- declare type AllowedClientConfigKey =
98
- | 'useCdn'
99
- | 'token'
100
- | 'perspective'
101
- | 'apiHost'
102
- | 'proxy'
103
- | 'withCredentials'
104
- | 'timeout'
105
- | 'maxRetries'
106
- | 'dataset'
107
- | 'projectId'
108
- | 'requestTagPrefix'
109
- | 'useProjectHostname'
110
-
111
- declare interface AndNode extends BaseNode {
112
- type: 'And'
113
- left: ExprNode
114
- right: ExprNode
16
+ declare enum AuthStateType {
17
+ LOGGED_IN = "logged-in",
18
+ LOGGING_IN = "logging-in",
19
+ ERROR = "error",
20
+ LOGGED_OUT = "logged-out",
115
21
  }
116
-
117
- declare type AnyStaticValue =
118
- | StringValue
119
- | NumberValue
120
- | NullValue
121
- | BooleanValue
122
- | DateTimeValue
123
- | ObjectValue
124
- | ArrayValue
125
- | PathValue
126
-
127
22
  /**
128
- * Represents a transaction that has been applied locally but has not been
129
- * committed/transitioned-to-outgoing. These transactions are visible to the
130
- * user but may be rebased upon a new working document set. Applied transactions
131
- * also contain the resulting `outgoingActions` that will be submitted to
132
- * Content Lake. These `outgoingActions` depend on the state of the working
133
- * documents so they are recomputed on rebase and are only relevant to applied
134
- * actions (we cannot compute `outgoingActions` for queued transactions because
135
- * we haven't resolved the set of documents the actions are dependent on yet).
136
- *
137
- * In order to support better conflict resolution, the original `previous` set
138
- * is saved as the `base` set.
23
+ * Configuration for an authentication provider
24
+ * @public
139
25
  */
140
- declare interface AppliedTransaction extends QueuedTransaction {
141
- /**
142
- * the resulting set of documents after the actions have been applied
143
- */
144
- working: DocumentSet
145
- /**
146
- * the previous set of documents before the action was applied
147
- */
148
- previous: DocumentSet
149
- /**
150
- * the original `previous` document set captured when this action was
151
- * originally applied. this is used as a reference point to do a 3-way merge
152
- * if this applied transaction ever needs to be reapplied on a different
153
- * set of documents.
154
- */
155
- base: DocumentSet
156
- /**
157
- * the `_rev`s from `previous` document set
158
- */
159
- previousRevs: {
160
- [TDocumentId in string]?: string
161
- }
162
- /**
163
- * a timestamp for when this transaction was applied locally
164
- */
165
- timestamp: string
26
+ interface AuthProvider {
166
27
  /**
167
- * the resulting HTTP actions derived from the state of the `working` document
168
- * set. these are sent to Content Lake as-is when this transaction is batched
169
- * and transitioned into an outgoing transaction.
28
+ * Unique identifier for the auth provider (e.g., 'google', 'github')
170
29
  */
171
- outgoingActions: HttpAction[]
30
+ name: string;
172
31
  /**
173
- * similar to `outgoingActions` but comprised of mutations instead of action.
174
- * this left here for debugging purposes but could be used to send mutations
175
- * to Content Lake instead of actions.
32
+ * Display name for the auth provider in the UI
176
33
  */
177
- outgoingMutations: Mutation[]
178
- }
179
-
180
- /** @beta */
181
- export declare function applyDocumentActions<
182
- TDocumentType extends string = string,
183
- TDataset extends string = string,
184
- TProjectId extends string = string,
185
- >(
186
- instance: SanityInstance,
187
- action:
188
- | DocumentAction<TDocumentType, TDataset, TProjectId>
189
- | DocumentAction<TDocumentType, TDataset, TProjectId>[],
190
- options?: ApplyDocumentActionsOptions,
191
- ): Promise<ActionsResult<SanityDocument_2<TDocumentType, `${TProjectId}.${TDataset}`>>>
192
-
193
- /** @beta */
194
- export declare function applyDocumentActions(
195
- instance: SanityInstance,
196
- action: DocumentAction | DocumentAction[],
197
- options?: ApplyDocumentActionsOptions,
198
- ): Promise<ActionsResult>
199
-
200
- /** @beta */
201
- export declare interface ApplyDocumentActionsOptions {
34
+ title: string;
202
35
  /**
203
- * Optionally provide an ID to be used as this transaction ID
36
+ * Complete authentication URL including callback and token parameters
204
37
  */
205
- transactionId?: string
38
+ url: string;
206
39
  /**
207
- * Set this to true to prevent this action from being batched with others.
40
+ * Optional URL for direct sign-up flow
208
41
  */
209
- disableBatching?: boolean
210
- }
211
-
212
- declare interface ArrayCoerceNode extends BaseNode {
213
- type: 'ArrayCoerce'
214
- base: ExprNode
215
- }
216
-
217
- declare interface ArrayElementNode extends BaseNode {
218
- type: 'ArrayElement'
219
- value: ExprNode
220
- isSplat: boolean
221
- }
222
-
223
- declare interface ArrayNode extends BaseNode {
224
- type: 'Array'
225
- elements: ArrayElementNode[]
226
- }
227
-
228
- declare type ArrayValue = StaticValue<unknown[], 'array'>
229
-
230
- declare interface AscNode extends BaseNode {
231
- type: 'Asc'
232
- base: ExprNode
42
+ signUpUrl?: string;
233
43
  }
234
-
235
44
  /**
236
45
  * Configuration options for creating an auth store.
237
46
  *
238
47
  * @public
239
48
  */
240
- export declare interface AuthConfig {
49
+ interface AuthConfig {
241
50
  /**
242
51
  * The initial location href to use when handling auth callbacks.
243
52
  * Defaults to the current window location if available.
244
53
  */
245
- initialLocationHref?: string
54
+ initialLocationHref?: string;
246
55
  /**
247
56
  * Factory function to create a SanityClient instance.
248
57
  * Defaults to the standard Sanity client factory if not provided.
249
58
  */
250
- clientFactory?: (config: ClientConfig) => SanityClient
59
+ clientFactory?: (config: ClientConfig) => SanityClient;
251
60
  /**
252
61
  * Custom authentication providers to use instead of or in addition to the default ones.
253
62
  * Can be an array of providers or a function that takes the default providers and returns
254
63
  * a modified array or a Promise resolving to one.
255
64
  */
256
- providers?: AuthProvider[] | ((prev: AuthProvider[]) => AuthProvider[] | Promise<AuthProvider[]>)
65
+ providers?: AuthProvider[] | ((prev: AuthProvider[]) => AuthProvider[] | Promise<AuthProvider[]>);
257
66
  /**
258
67
  * The API hostname for requests. Usually leave this undefined, but it can be set
259
68
  * if using a custom domain or CNAME for the API endpoint.
260
69
  */
261
- apiHost?: string
70
+ apiHost?: string;
262
71
  /**
263
72
  * Storage implementation to persist authentication state.
264
73
  * Defaults to `localStorage` if available.
265
74
  */
266
- storageArea?: Storage
75
+ storageArea?: Storage;
267
76
  /**
268
77
  * A callback URL for your application.
269
78
  * If none is provided, the auth API will redirect back to the current location (`location.href`).
270
79
  * When handling callbacks, this URL's pathname is checked to ensure it matches the callback.
271
80
  */
272
- callbackUrl?: string
81
+ callbackUrl?: string;
273
82
  /**
274
83
  * A static authentication token to use instead of handling the OAuth flow.
275
84
  * When provided, the auth store will remain in a logged-in state with this token,
276
85
  * ignoring any storage or callback handling.
277
86
  */
278
- token?: string
87
+ token?: string;
279
88
  }
280
-
281
- declare type AuthMethodOptions = 'localstorage' | 'cookie' | undefined
282
-
283
89
  /**
284
- * Configuration for an authentication provider
90
+ * Represents the minimal configuration required to identify a Sanity project.
285
91
  * @public
286
92
  */
287
- export declare interface AuthProvider {
288
- /**
289
- * Unique identifier for the auth provider (e.g., 'google', 'github')
290
- */
291
- name: string
292
- /**
293
- * Display name for the auth provider in the UI
294
- */
295
- title: string
296
- /**
297
- * Complete authentication URL including callback and token parameters
298
- */
299
- url: string
300
- /**
301
- * Optional URL for direct sign-up flow
302
- */
303
- signUpUrl?: string
93
+ interface ProjectHandle<TProjectId extends string = string> {
94
+ projectId?: TProjectId;
304
95
  }
305
-
306
96
  /**
307
- * Represents the various states the authentication can be in.
308
- *
309
97
  * @public
310
98
  */
311
- export declare type AuthState =
312
- | LoggedInAuthState
313
- | LoggedOutAuthState
314
- | LoggingInAuthState
315
- | ErrorAuthState
316
-
99
+ type ReleasePerspective = {
100
+ releaseName: string;
101
+ excludedPerspectives?: StackablePerspective[];
102
+ };
317
103
  /**
318
- * Represents the various states the authentication type can be in.
319
- *
320
104
  * @public
321
105
  */
322
- export declare enum AuthStateType {
323
- LOGGED_IN = 'logged-in',
324
- LOGGING_IN = 'logging-in',
325
- ERROR = 'error',
326
- LOGGED_OUT = 'logged-out',
106
+ interface PerspectiveHandle {
107
+ perspective?: ClientPerspective | ReleasePerspective;
327
108
  }
328
-
329
109
  /**
330
110
  * @public
331
111
  */
332
- export declare interface AuthStoreState {
333
- authState: AuthState
334
- providers?: AuthProvider[]
335
- options: {
336
- initialLocationHref: string
337
- clientFactory: (config: ClientConfig) => SanityClient
338
- customProviders: AuthConfig['providers']
339
- storageKey: string
340
- storageArea: Storage | undefined
341
- apiHost: string | undefined
342
- loginUrl: string
343
- callbackUrl: string | undefined
344
- providedToken: string | undefined
345
- authMethod: AuthMethodOptions
346
- }
347
- dashboardContext?: DashboardContext
112
+ interface DatasetHandle<TDataset extends string = string, TProjectId extends string = string> extends ProjectHandle<TProjectId>, PerspectiveHandle {
113
+ dataset?: TDataset;
348
114
  }
349
-
350
- /** The base interface for SyntaxNode. */
351
- declare interface BaseNode {
352
- type: string
115
+ /**
116
+ * Identifies a specific document type within a Sanity dataset and project.
117
+ * Includes `projectId`, `dataset`, and `documentType`.
118
+ * Optionally includes a `documentId`, useful for referencing a specific document type context, potentially without a specific document ID.
119
+ * @public
120
+ */
121
+ interface DocumentTypeHandle<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string> extends DatasetHandle<TDataset, TProjectId> {
122
+ documentId?: string;
123
+ documentType: TDocumentType;
353
124
  }
354
-
355
- declare type BooleanValue = StaticValue<boolean, 'boolean'>
356
-
357
125
  /**
358
- * Represents a store action that has been bound to a specific store instance
126
+ * Uniquely identifies a specific document within a Sanity dataset and project.
127
+ * Includes `projectId`, `dataset`, `documentType`, and the required `documentId`.
128
+ * Commonly used by document-related hooks and components to reference a document without fetching its full content initially.
129
+ * @public
359
130
  */
360
- declare type BoundStoreAction_3<_TState, TParams extends unknown[], TReturn> = (
361
- instance: SanityInstance,
362
- ...params: TParams
363
- ) => TReturn
364
-
131
+ interface DocumentHandle<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string> extends DocumentTypeHandle<TDocumentType, TDataset, TProjectId> {
132
+ documentId: string;
133
+ }
365
134
  /**
366
- * Individual channel with its relevant options
135
+ * Represents the complete configuration for a Sanity SDK instance
367
136
  * @public
368
137
  */
369
- declare interface ChannelEntry {
370
- channel: ChannelInstance<FrameMessage, WindowMessage>
371
- options: ChannelInput
372
- refCount: number
138
+ interface SanityConfig extends DatasetHandle, PerspectiveHandle {
139
+ /**
140
+ * Authentication configuration for the instance
141
+ * @remarks Merged with parent configurations when using createChild
142
+ */
143
+ auth?: AuthConfig;
144
+ /**
145
+ * Studio mode configuration for use of the SDK in a Sanity Studio
146
+ * @remarks Controls whether studio mode features are enabled
147
+ */
148
+ studioMode?: {
149
+ enabled: boolean;
150
+ };
373
151
  }
374
-
375
152
  /**
376
- * Options used when retrieving a client instance from the client store.
377
- *
378
- * This interface extends the base {@link ClientConfig} and adds:
379
- *
380
- * - **apiVersion:** A required string indicating the API version for the client.
381
- * - **scope:** An optional flag to choose between the project-specific client
382
- * ('project') and the global client ('global'). When set to `'global'`, the
383
- * global client is used.
384
- *
385
- * These options are utilized by `getClient` and `getClientState` to configure and
386
- * return appropriate client instances that automatically handle authentication
387
- * updates and configuration changes.
153
+ * Represents a Sanity.io resource instance with its own configuration and lifecycle
154
+ * @remarks Instances form a hierarchy through parent/child relationships
388
155
  *
389
156
  * @public
390
157
  */
391
- export declare interface ClientOptions extends Pick<ClientConfig, AllowedClientConfigKey> {
158
+ interface SanityInstance {
392
159
  /**
393
- * An optional flag to choose between the default client (typically project-level)
394
- * and the global client ('global'). When set to `'global'`, the global client
395
- * is used.
160
+ * Unique identifier for this instance
161
+ * @remarks Generated using crypto.randomUUID()
396
162
  */
397
- 'scope'?: 'default' | 'global'
163
+ readonly instanceId: string;
398
164
  /**
399
- * A required string indicating the API version for the client.
165
+ * Resolved configuration for this instance
166
+ * @remarks Merges values from parent instances where appropriate
400
167
  */
401
- 'apiVersion': string
168
+ readonly config: SanityConfig;
402
169
  /**
403
- * @internal
170
+ * Checks if the instance has been disposed
171
+ * @returns true if dispose() has been called
172
+ */
173
+ isDisposed(): boolean;
174
+ /**
175
+ * Disposes the instance and cleans up associated resources
176
+ * @remarks Triggers all registered onDispose callbacks
177
+ */
178
+ dispose(): void;
179
+ /**
180
+ * Registers a callback to be invoked when the instance is disposed
181
+ * @param cb - Callback to execute on disposal
182
+ * @returns Function to unsubscribe the callback
183
+ */
184
+ onDispose(cb: () => void): () => void;
185
+ /**
186
+ * Gets the parent instance in the hierarchy
187
+ * @returns Parent instance or undefined if this is the root
188
+ */
189
+ getParent(): SanityInstance | undefined;
190
+ /**
191
+ * Creates a child instance with merged configuration
192
+ * @param config - Configuration to merge with parent values
193
+ * @remarks Child instances inherit parent configuration but can override values
194
+ */
195
+ createChild(config: SanityConfig): SanityInstance;
196
+ /**
197
+ * Traverses the instance hierarchy to find the first instance whose configuration
198
+ * matches the given target config using a shallow comparison.
199
+ * @param targetConfig - A partial configuration object containing key-value pairs to match.
200
+ * @returns The first matching instance or undefined if no match is found.
404
201
  */
405
- '~experimental_resource'?: ClientConfig['~experimental_resource']
202
+ match(targetConfig: Partial<SanityConfig>): SanityInstance | undefined;
406
203
  }
407
-
408
204
  /**
409
- * States tracked by the client store
205
+ * Creates a new Sanity resource instance
206
+ * @param config - Configuration for the instance (optional)
207
+ * @returns A configured SanityInstance
208
+ * @remarks When creating child instances, configurations are merged with parent values
209
+ *
410
210
  * @public
411
211
  */
412
- export declare interface ClientState {
413
- token: string | null
414
- clients: {
415
- [TKey in string]?: SanityClient
416
- }
417
- authMethod?: 'localstorage' | 'cookie'
418
- }
419
-
212
+ declare function createSanityInstance(config?: SanityConfig): SanityInstance;
420
213
  /**
421
- * Internal state tracking comlink connections
214
+ * Represents a store action that has been bound to a specific store instance
215
+ */
216
+ type BoundStoreAction<_TState, TParams extends unknown[], TReturn> = (instance: SanityInstance, ...params: TParams) => TReturn;
217
+ /**
218
+ * Creates an action binder function that uses the provided key function
219
+ * to determine how store instances are shared between Sanity instances
220
+ *
221
+ * @param keyFn - Function that generates a key from a Sanity config
222
+ * @returns A function that binds store actions to Sanity instances
223
+ *
224
+ * @remarks
225
+ * Action binders determine how store instances are shared across multiple
226
+ * Sanity instances. The key function determines which instances share state.
227
+ *
228
+ * @example
229
+ * ```ts
230
+ * // Create a custom binder that uses a tenant ID for isolation
231
+ * const bindActionByTenant = createActionBinder(config => config.tenantId || 'default')
232
+ *
233
+ * // Use the custom binder with a store definition
234
+ * const getTenantUsers = bindActionByTenant(
235
+ * userStore,
236
+ * ({state}) => state.get().users
237
+ * )
238
+ * ```
239
+ */
240
+ /**
241
+ * Represents the various states the authentication can be in.
242
+ *
422
243
  * @public
423
244
  */
424
- export declare interface ComlinkControllerState {
425
- controller: Controller | null
426
- controllerOrigin: string | null
427
- channels: Map<string, ChannelEntry>
428
- }
429
-
245
+ type AuthState = LoggedInAuthState | LoggedOutAuthState | LoggingInAuthState | ErrorAuthState;
430
246
  /**
431
- * Internal state tracking comlink connections
247
+ * Logged-in state from the auth state.
432
248
  * @public
433
249
  */
434
- export declare interface ComlinkNodeState {
435
- nodes: Map<string, NodeEntry>
436
- subscriptions: Map<string, Set<symbol>>
437
- }
438
-
439
- declare interface Context {
440
- timestamp: Date
441
- identity: string
442
- before: Value | null
443
- after: Value | null
444
- sanity?: {
445
- projectId: string
446
- dataset: string
447
- }
448
- dereference?: DereferenceFunction
449
- }
450
-
451
- declare interface ContextNode extends BaseNode {
452
- type: 'Context'
453
- key: string
454
- }
455
-
250
+ type LoggedInAuthState = {
251
+ type: AuthStateType.LOGGED_IN;
252
+ token: string;
253
+ currentUser: CurrentUser$1 | null;
254
+ };
456
255
  /**
457
- * This version is provided by pkg-utils at build time
458
- * @internal
256
+ * Logged-out state from the auth state.
257
+ * @public
459
258
  */
460
- export declare const CORE_SDK_VERSION: {}
461
-
259
+ type LoggedOutAuthState = {
260
+ type: AuthStateType.LOGGED_OUT;
261
+ isDestroyingSession: boolean;
262
+ };
462
263
  /**
463
- * Creates or validates a `DatasetHandle` object.
464
- * Ensures the provided object conforms to the `DatasetHandle` interface.
465
- * @param handle - The object containing dataset identification properties.
466
- * @returns The validated `DatasetHandle` object.
264
+ * Logging-in state from the auth state.
467
265
  * @public
468
266
  */
469
- export declare function createDatasetHandle<
470
- TDataset extends string = string,
471
- TProjectId extends string = string,
472
- >(handle: DatasetHandle<TDataset, TProjectId>): DatasetHandle<TDataset, TProjectId>
473
-
267
+ type LoggingInAuthState = {
268
+ type: AuthStateType.LOGGING_IN;
269
+ isExchangingToken: boolean;
270
+ };
474
271
  /**
475
- * Creates a `CreateDocumentAction` object.
476
- * @param doc - A handle identifying the document type, dataset, and project. An optional `documentId` can be provided.
477
- * @returns A `CreateDocumentAction` object ready for dispatch.
478
- * @beta
272
+ * Error state from the auth state.
273
+ * @public
479
274
  */
480
- export declare function createDocument<
481
- TDocumentType extends string = string,
482
- TDataset extends string = string,
483
- TProjectId extends string = string,
484
- >(
485
- doc: DocumentTypeHandle<TDocumentType, TDataset, TProjectId>,
486
- ): CreateDocumentAction<TDocumentType, TDataset, TProjectId>
487
-
275
+ type ErrorAuthState = {
276
+ type: AuthStateType.ERROR;
277
+ error: unknown;
278
+ };
488
279
  /**
489
- * Represents an action to create a new document.
490
- * Specifies the document type and optionally a document ID (which will be treated as the published ID).
491
- * @beta
280
+ * Represents the various states the authentication can be in.
281
+ *
282
+ * @public
492
283
  */
493
- export declare interface CreateDocumentAction<
494
- TDocumentType extends string = string,
495
- TDataset extends string = string,
496
- TProjectId extends string = string,
497
- > extends DocumentTypeHandle<TDocumentType, TDataset, TProjectId> {
498
- type: 'document.create'
284
+ interface DashboardContext {
285
+ mode?: string;
286
+ env?: string;
287
+ orgId?: string;
499
288
  }
500
-
289
+ type AuthMethodOptions = 'localstorage' | 'cookie' | undefined;
501
290
  /**
502
- * Creates or validates a `DocumentHandle` object.
503
- * Ensures the provided object conforms to the `DocumentHandle` interface.
504
- * @param handle - The object containing document identification properties.
505
- * @returns The validated `DocumentHandle` object.
506
291
  * @public
507
292
  */
508
- export declare function createDocumentHandle<
509
- TDocumentType extends string = string,
510
- TDataset extends string = string,
511
- TProjectId extends string = string,
512
- >(
513
- handle: DocumentHandle<TDocumentType, TDataset, TProjectId>,
514
- ): DocumentHandle<TDocumentType, TDataset, TProjectId>
515
-
293
+ interface AuthStoreState {
294
+ authState: AuthState;
295
+ providers?: AuthProvider[];
296
+ options: {
297
+ initialLocationHref: string;
298
+ clientFactory: (config: ClientConfig) => SanityClient;
299
+ customProviders: AuthConfig['providers'];
300
+ storageKey: string;
301
+ storageArea: Storage | undefined;
302
+ apiHost: string | undefined;
303
+ loginUrl: string;
304
+ callbackUrl: string | undefined;
305
+ providedToken: string | undefined;
306
+ authMethod: AuthMethodOptions;
307
+ };
308
+ dashboardContext?: DashboardContext;
309
+ }
516
310
  /**
517
- * Creates or validates a `DocumentTypeHandle` object.
518
- * Ensures the provided object conforms to the `DocumentTypeHandle` interface.
519
- * @param handle - The object containing document type identification properties.
520
- * @returns The validated `DocumentTypeHandle` object.
521
311
  * @public
522
312
  */
523
- export declare function createDocumentTypeHandle<
524
- TDocumentType extends string = string,
525
- TDataset extends string = string,
526
- TProjectId extends string = string,
527
- >(
528
- handle: DocumentTypeHandle<TDocumentType, TDataset, TProjectId>,
529
- ): DocumentTypeHandle<TDocumentType, TDataset, TProjectId>
530
-
313
+ declare const getCurrentUserState: BoundStoreAction<AuthStoreState, [], StateSource<CurrentUser$1 | null>>;
314
+ /**
315
+ * @public
316
+ */
317
+ declare const getTokenState: BoundStoreAction<AuthStoreState, [], StateSource<string | null>>;
531
318
  /**
532
- * Creates a GROQ search filter string (`[@] match text::query("...")`)
533
- * from a raw search query string.
534
- *
535
- * It applies wildcard ('*') logic to the last eligible token and escapes
536
- * double quotes within the search term.
537
- *
538
- * If the input query is empty or only whitespace, it returns an empty string.
539
- *
540
- * @param query - The raw input search string.
541
- * @returns The GROQ search filter string, or an empty string.
542
319
  * @internal
543
320
  */
544
- export declare function createGroqSearchFilter(query: string): string
545
321
 
546
322
  /**
547
- * Creates or validates a `ProjectHandle` object.
548
- * Ensures the provided object conforms to the `ProjectHandle` interface.
549
- * @param handle - The object containing project identification properties.
550
- * @returns The validated `ProjectHandle` object.
551
323
  * @public
552
324
  */
553
- export declare function createProjectHandle<TProjectId extends string = string>(
554
- handle: ProjectHandle<TProjectId>,
555
- ): ProjectHandle<TProjectId>
556
-
325
+ declare const getLoginUrlState: BoundStoreAction<AuthStoreState, [], StateSource<string>>;
557
326
  /**
558
- * Creates a new Sanity resource instance
559
- * @param config - Configuration for the instance (optional)
560
- * @returns A configured SanityInstance
561
- * @remarks When creating child instances, configurations are merged with parent values
562
- *
563
327
  * @public
564
328
  */
565
- export declare function createSanityInstance(config?: SanityConfig): SanityInstance
566
-
567
- export {CurrentUser}
568
-
329
+ declare const getAuthState: BoundStoreAction<AuthStoreState, [], StateSource<AuthState>>;
569
330
  /**
570
- * Represents the various states the authentication can be in.
571
- *
572
331
  * @public
573
332
  */
574
- declare interface DashboardContext {
575
- mode?: string
576
- env?: string
577
- orgId?: string
578
- }
579
-
333
+ declare const getDashboardOrganizationId: BoundStoreAction<AuthStoreState, [], StateSource<string | undefined>>;
580
334
  /**
335
+ * Returns a state source indicating if the SDK is running within a dashboard context.
581
336
  * @public
582
337
  */
583
- export declare interface DatasetHandle<
584
- TDataset extends string = string,
585
- TProjectId extends string = string,
586
- > extends ProjectHandle<TProjectId>,
587
- PerspectiveHandle {
588
- dataset?: TDataset
589
- }
590
-
591
- declare class DateTime {
592
- date: Date
593
- constructor(date: Date)
594
- static parseToValue(str: string): Value
595
- equals(other: DateTime): boolean
596
- add(secs: number): DateTime
597
- difference(other: DateTime): number
598
- compareTo(other: DateTime): number
599
- toString(): string
600
- toJSON(): string
338
+ declare const getIsInDashboardState: BoundStoreAction<AuthStoreState, [], StateSource<boolean>>;
339
+ /**
340
+ * Action to explicitly set the authentication token.
341
+ * Used internally by the Comlink token refresh.
342
+ * @internal
343
+ */
344
+ declare const setAuthToken: BoundStoreAction<AuthStoreState, [token: string | null], void>;
345
+ /**
346
+ * Error message returned by the organization verification
347
+ * @public
348
+ */
349
+ interface OrgVerificationResult {
350
+ error: string | null;
601
351
  }
602
-
603
- declare type DateTimeValue = StaticValue<DateTime, 'datetime'>
604
-
605
352
  /**
606
- * Given a type T and an array of "access keys" Parts, recursively index into T.
607
- *
608
- * If a part is a key, it looks up that property.
609
- * If T is an array and the part is a number, it "indexes" into the element type.
353
+ * Compares a project's actual organization ID with the expected organization ID.
354
+ * @public
610
355
  */
611
- declare type DeepGet<TValue, TPath extends readonly (string | number)[]> = TPath extends []
612
- ? TValue
613
- : TPath extends readonly [infer THead, ...infer TTail]
614
- ? DeepGet<
615
- TValue extends undefined | null
616
- ? undefined
617
- : THead extends keyof TValue
618
- ? TValue[THead]
619
- : THead extends number
620
- ? TValue extends readonly (infer TElement)[]
621
- ? TElement | undefined
622
- : undefined
623
- : undefined, // Key/index doesn't exist
624
- TTail extends readonly (string | number)[] ? TTail : []
625
- >
626
- : never
627
-
628
356
  /**
629
- * Creates a `DeleteDocumentAction` object.
630
- * @param doc - A handle uniquely identifying the document to be deleted.
631
- * @returns A `DeleteDocumentAction` object ready for dispatch.
632
- * @beta
357
+ * Creates an observable that emits the organization verification state for a given instance.
358
+ * It combines the dashboard organization ID (from auth context) with the
359
+ * project's actual organization ID (fetched via getProjectState) and compares them.
360
+ * @public
633
361
  */
634
- export declare function deleteDocument<
635
- TDocumentType extends string = string,
636
- TDataset extends string = string,
637
- TProjectId extends string = string,
638
- >(
639
- doc: DocumentHandle<TDocumentType, TDataset, TProjectId>,
640
- ): DeleteDocumentAction<TDocumentType, TDataset, TProjectId>
641
-
362
+ declare function observeOrganizationVerificationState(instance: SanityInstance, projectIds: string[]): Observable<OrgVerificationResult>;
642
363
  /**
643
- * Represents an action to delete an existing document.
644
- * Requires the full document handle including the document ID.
645
- * @beta
364
+ * @public
646
365
  */
647
- export declare interface DeleteDocumentAction<
648
- TDocumentType extends string = string,
649
- TDataset extends string = string,
650
- TProjectId extends string = string,
651
- > extends DocumentHandle<TDocumentType, TDataset, TProjectId> {
652
- type: 'document.delete'
653
- }
654
-
655
- declare type DereferenceFunction = (obj: {
656
- _ref: string
657
- }) => PromiseLike<Document_2 | null | undefined>
658
-
659
- declare interface DerefNode extends BaseNode {
660
- type: 'Deref'
661
- base: ExprNode
366
+ declare const handleAuthCallback: BoundStoreAction<AuthStoreState, [locationHref?: string | undefined], Promise<string | false>>;
367
+ /**
368
+ * @public
369
+ */
370
+ declare const logout: BoundStoreAction<AuthStoreState, [], Promise<void>>;
371
+ type AllowedClientConfigKey = 'useCdn' | 'token' | 'perspective' | 'apiHost' | 'proxy' | 'withCredentials' | 'timeout' | 'maxRetries' | 'dataset' | 'projectId' | 'requestTagPrefix' | 'useProjectHostname';
372
+ /**
373
+ * States tracked by the client store
374
+ * @public
375
+ */
376
+ interface ClientStoreState {
377
+ token: string | null;
378
+ clients: { [TKey in string]?: SanityClient };
379
+ authMethod?: 'localstorage' | 'cookie';
662
380
  }
663
-
664
- declare interface DescNode extends BaseNode {
665
- type: 'Desc'
666
- base: ExprNode
381
+ /**
382
+ * Options used when retrieving a client instance from the client store.
383
+ *
384
+ * This interface extends the base {@link ClientConfig} and adds:
385
+ *
386
+ * - **apiVersion:** A required string indicating the API version for the client.
387
+ * - **scope:** An optional flag to choose between the project-specific client
388
+ * ('project') and the global client ('global'). When set to `'global'`, the
389
+ * global client is used.
390
+ *
391
+ * These options are utilized by `getClient` and `getClientState` to configure and
392
+ * return appropriate client instances that automatically handle authentication
393
+ * updates and configuration changes.
394
+ *
395
+ * @public
396
+ */
397
+ interface ClientOptions extends Pick<ClientConfig, AllowedClientConfigKey> {
398
+ /**
399
+ * An optional flag to choose between the default client (typically project-level)
400
+ * and the global client ('global'). When set to `'global'`, the global client
401
+ * is used.
402
+ */
403
+ 'scope'?: 'default' | 'global';
404
+ /**
405
+ * A required string indicating the API version for the client.
406
+ */
407
+ 'apiVersion': string;
408
+ /**
409
+ * @internal
410
+ */
411
+ '~experimental_resource'?: ClientConfig['~experimental_resource'];
667
412
  }
668
-
669
413
  /**
670
- * Calls the destroy method on the controller and resets the controller state.
414
+ * Retrieves a Sanity client instance configured with the provided options.
415
+ *
416
+ * This function returns a client instance configured for the project or as a
417
+ * global client based on the options provided. It ensures efficient reuse of
418
+ * client instances by returning the same instance for the same options.
419
+ * For automatic handling of authentication token updates, consider using
420
+ * `getClientState`.
421
+ *
671
422
  * @public
672
423
  */
673
- export declare const destroyController: BoundStoreAction_2<ComlinkControllerState, [], void>
674
-
424
+ declare const getClient: BoundStoreAction<ClientStoreState, [options: ClientOptions], SanityClient>;
675
425
  /**
676
- * Creates a `DiscardDocumentAction` object.
677
- * @param doc - A handle uniquely identifying the document whose draft changes are to be discarded.
678
- * @returns A `DiscardDocumentAction` object ready for dispatch.
679
- * @beta
426
+ * Returns a state source for the Sanity client instance.
427
+ *
428
+ * This function provides a subscribable state source that emits updated client
429
+ * instances whenever relevant configurations change (such as authentication tokens).
430
+ * Use this when you need to react to client configuration changes in your application.
431
+ *
432
+ * @public
680
433
  */
681
- export declare function discardDocument<
682
- TDocumentType extends string = string,
683
- TDataset extends string = string,
684
- TProjectId extends string = string,
685
- >(
686
- doc: DocumentHandle<TDocumentType, TDataset, TProjectId>,
687
- ): DiscardDocumentAction<TDocumentType, TDataset, TProjectId>
688
-
434
+ declare const getClientState: BoundStoreAction<ClientStoreState, [options: ClientOptions], StateSource<SanityClient>>;
689
435
  /**
690
- * Represents an action to discard the draft changes of a document.
691
- * Requires the full document handle.
692
- * @beta
436
+ * Message sent from a containing app to an iframe
437
+ * @public
693
438
  */
694
- export declare interface DiscardDocumentAction<
695
- TDocumentType extends string = string,
696
- TDataset extends string = string,
697
- TProjectId extends string = string,
698
- > extends DocumentHandle<TDocumentType, TDataset, TProjectId> {
699
- type: 'document.discard'
700
- }
701
-
702
- declare type Document_2 = {
703
- _id?: string
704
- _type?: string
705
- [T: string]: unknown
706
- }
707
-
439
+ type FrameMessage = Message;
708
440
  /**
709
- * Union type representing all possible document actions within the SDK.
710
- * @beta
441
+ * Message sent from an iframe to a containing app
442
+ * @public
711
443
  */
712
- export declare type DocumentAction<
713
- TDocumentType extends string = string,
714
- TDataset extends string = string,
715
- TProjectId extends string = string,
716
- > =
717
- | CreateDocumentAction<TDocumentType, TDataset, TProjectId>
718
- | DeleteDocumentAction<TDocumentType, TDataset, TProjectId>
719
- | EditDocumentAction<TDocumentType, TDataset, TProjectId>
720
- | PublishDocumentAction<TDocumentType, TDataset, TProjectId>
721
- | UnpublishDocumentAction<TDocumentType, TDataset, TProjectId>
722
- | DiscardDocumentAction<TDocumentType, TDataset, TProjectId>
723
-
444
+ type WindowMessage = Message;
724
445
  /**
725
- * @beta
726
- * Event emitted when a document is created.
446
+ * Message from SDK (iframe) to Parent (dashboard) to request a new token
447
+ * @internal
727
448
  */
728
- export declare interface DocumentCreatedEvent {
729
- type: 'created'
730
- documentId: string
731
- outgoing: OutgoingTransaction
732
- }
733
-
449
+ type RequestNewTokenMessage = {
450
+ type: 'dashboard/v1/auth/tokens/create';
451
+ payload?: undefined;
452
+ };
734
453
  /**
735
- * @beta
736
- * Event emitted when a document is deleted.
454
+ * Message from Parent (dashboard) to SDK (iframe) with the new token
455
+ * @internal
737
456
  */
738
- export declare interface DocumentDeletedEvent {
739
- type: 'deleted'
740
- documentId: string
741
- outgoing: OutgoingTransaction
742
- }
743
-
457
+ type NewTokenResponseMessage = {
458
+ type: 'dashboard/v1/auth/tokens/create';
459
+ payload: {
460
+ token: string | null;
461
+ error?: string;
462
+ };
463
+ };
744
464
  /**
745
- * @beta
746
- * Event emitted when a document version is discarded.
465
+ * Individual channel with its relevant options
466
+ * @public
747
467
  */
748
- export declare interface DocumentDiscardedEvent {
749
- type: 'discarded'
750
- documentId: string
751
- outgoing: OutgoingTransaction
468
+ interface ChannelEntry {
469
+ channel: ChannelInstance<FrameMessage, WindowMessage>;
470
+ options: ChannelInput;
471
+ refCount: number;
752
472
  }
753
-
754
473
  /**
755
- * @beta
756
- * Event emitted when a document is edited.
474
+ * Internal state tracking comlink connections
475
+ * @public
757
476
  */
758
- export declare interface DocumentEditedEvent {
759
- type: 'edited'
760
- documentId: string
761
- outgoing: OutgoingTransaction
477
+ interface ComlinkControllerState {
478
+ controller: Controller | null;
479
+ controllerOrigin: string | null;
480
+ channels: Map<string, ChannelEntry>;
762
481
  }
763
-
764
- /** @beta */
765
- export declare type DocumentEvent =
766
- | ActionErrorEvent
767
- | TransactionRevertedEvent
768
- | TransactionAcceptedEvent
769
- | DocumentRebaseErrorEvent
770
- | DocumentEditedEvent
771
- | DocumentCreatedEvent
772
- | DocumentDeletedEvent
773
- | DocumentPublishedEvent
774
- | DocumentUnpublishedEvent
775
- | DocumentDiscardedEvent
776
-
777
482
  /**
778
- * Uniquely identifies a specific document within a Sanity dataset and project.
779
- * Includes `projectId`, `dataset`, `documentType`, and the required `documentId`.
780
- * Commonly used by document-related hooks and components to reference a document without fetching its full content initially.
483
+ * Calls the destroy method on the controller and resets the controller state.
781
484
  * @public
782
485
  */
783
- export declare interface DocumentHandle<
784
- TDocumentType extends string = string,
785
- TDataset extends string = string,
786
- TProjectId extends string = string,
787
- > extends DocumentTypeHandle<TDocumentType, TDataset, TProjectId> {
788
- documentId: string
789
- }
790
-
486
+ declare const destroyController: BoundStoreAction<ComlinkControllerState, [], void>;
791
487
  /**
792
- * @beta
793
- * Options for specifying a document and optionally a path within it.
488
+ * Retrieve or create a channel to be used for communication between
489
+ * an application and the controller.
490
+ * @public
794
491
  */
795
- export declare interface DocumentOptions<
796
- TPath extends string | undefined = undefined,
797
- TDocumentType extends string = string,
798
- TDataset extends string = string,
799
- TProjectId extends string = string,
800
- > extends DocumentHandle<TDocumentType, TDataset, TProjectId> {
801
- path?: TPath
802
- }
803
-
804
- /** @beta */
805
- export declare type DocumentPermissionsResult =
806
- | {
807
- allowed: false
808
- message: string
809
- reasons: PermissionDeniedReason[]
810
- }
811
- | {
812
- allowed: true
813
- message?: undefined
814
- reasons?: undefined
815
- }
816
-
492
+ declare const getOrCreateChannel: BoundStoreAction<ComlinkControllerState, [options: ChannelInput], ChannelInstance<_sanity_comlink3.Message, _sanity_comlink3.Message>>;
817
493
  /**
818
- * @beta
819
- * Event emitted when a document is published.
494
+ * Initializes or fetches a controller to handle communication
495
+ * between an application and iframes.
496
+ * @public
820
497
  */
821
- export declare interface DocumentPublishedEvent {
822
- type: 'published'
823
- documentId: string
824
- outgoing: OutgoingTransaction
825
- }
826
-
498
+ declare const getOrCreateController: BoundStoreAction<ComlinkControllerState, [targetOrigin: string], Controller>;
827
499
  /**
828
- * @beta
829
- * Event emitted when an attempt to apply local changes to a modified remote document fails.
500
+ * Signals to the store that the consumer has stopped using the channel
501
+ * @public
830
502
  */
831
- declare interface DocumentRebaseErrorEvent {
832
- type: 'rebase-error'
833
- documentId: string
834
- transactionId: string
835
- message: string
836
- error: unknown
837
- }
838
-
503
+ declare const releaseChannel: BoundStoreAction<ComlinkControllerState, [name: string], void>;
839
504
  /**
840
- * Represents a set of document that will go into `applyMutations`. Before
841
- * applying a mutation, it's expected that all relevant documents that the
842
- * mutations affect are included, including those that do not exist yet.
843
- * Documents that don't exist have a `null` value.
505
+ * Individual node with its relevant options
506
+ * @public
844
507
  */
845
- declare type DocumentSet<TDocument extends SanityDocument = SanityDocument> = {
846
- [TDocumentId in string]?: TDocument | null
847
- }
848
-
849
- declare interface DocumentState {
850
- id: string
851
- /**
852
- * the "remote" local copy that matches the server. represents the last known
853
- * server state. this gets updated every time we confirm remote patches
854
- */
855
- remote?: SanityDocument_2 | null
856
- /**
857
- * the current ephemeral working copy that includes local optimistic changes
858
- * that have not yet been confirmed by the server
859
- */
860
- local?: SanityDocument_2 | null
861
- /**
862
- * the revision that our remote document is at
863
- */
864
- remoteRev?: string | null
865
- /**
866
- * Array of subscription IDs. This document state will be deleted if there are
867
- * no subscribers.
868
- */
869
- subscriptions: string[]
870
- /**
871
- * An object keyed by transaction ID of revisions sent out but that have not
872
- * yet been verified yet. When an applied transaction is transitioned to an
873
- * outgoing transaction, it also adds unverified revisions for each document
874
- * that is part of that outgoing transaction. Transactions are submitted to
875
- * the server with a locally generated transaction ID. This way we can observe
876
- * when our transaction comes back through the shared listener. Each listener
877
- * event that comes back contains a `previousRev`. If we see our own
878
- * transaction with a different `previousRev` than expected, we can rebase our
879
- * local transactions on top of this new remote.
880
- */
881
- unverifiedRevisions?: {
882
- [TTransactionId in string]?: UnverifiedDocumentRevision
883
- }
884
- }
885
-
886
- declare interface DocumentStoreState {
887
- documentStates: {
888
- [TDocumentId in string]?: DocumentState
889
- }
890
- queued: QueuedTransaction[]
891
- applied: AppliedTransaction[]
892
- outgoing?: OutgoingTransaction
893
- grants?: Record<Grant, ExprNode>
894
- error?: unknown
895
- sharedListener: SharedListener
896
- fetchDocument: (documentId: string) => Observable<SanityDocument_2 | null>
897
- events: Subject<DocumentEvent>
508
+ interface NodeEntry {
509
+ node: Node<WindowMessage, FrameMessage>;
510
+ options: NodeInput;
511
+ status: Status;
512
+ statusUnsub?: () => void;
898
513
  }
899
-
900
514
  /**
901
- * Identifies a specific document type within a Sanity dataset and project.
902
- * Includes `projectId`, `dataset`, and `documentType`.
903
- * Optionally includes a `documentId`, useful for referencing a specific document type context, potentially without a specific document ID.
515
+ * Internal state tracking comlink connections
904
516
  * @public
905
517
  */
906
- export declare interface DocumentTypeHandle<
907
- TDocumentType extends string = string,
908
- TDataset extends string = string,
909
- TProjectId extends string = string,
910
- > extends DatasetHandle<TDataset, TProjectId> {
911
- documentId?: string
912
- documentType: TDocumentType
518
+ interface ComlinkNodeState {
519
+ nodes: Map<string, NodeEntry>;
520
+ subscriptions: Map<string, Set<symbol>>;
913
521
  }
914
-
915
522
  /**
916
- * @beta
917
- * Event emitted when a document is unpublished.
523
+ * Signals to the store that the consumer has stopped using the node
524
+ * @public
918
525
  */
919
- export declare interface DocumentUnpublishedEvent {
920
- type: 'unpublished'
921
- documentId: string
922
- outgoing: OutgoingTransaction
923
- }
924
-
925
- /**
926
- * Creates an `EditDocumentAction` object with patches for modifying a document.
927
- * Accepts patches in either the standard `PatchOperations` format or as a `SanityMutatePatchMutation` from `@sanity/mutate`.
928
- *
929
- * @param doc - A handle uniquely identifying the document to be edited.
930
- * @param sanityMutatePatch - A patch mutation object from `@sanity/mutate`.
931
- * @returns An `EditDocumentAction` object ready for dispatch.
932
- * @beta
933
- */
934
- export declare function editDocument<
935
- TDocumentType extends string = string,
936
- TDataset extends string = string,
937
- TProjectId extends string = string,
938
- >(
939
- doc: DocumentHandle<TDocumentType, TDataset, TProjectId>,
940
- sanityMutatePatch: PatchMutation,
941
- ): EditDocumentAction<TDocumentType, TDataset, TProjectId>
942
-
943
- /**
944
- * Creates an `EditDocumentAction` object with patches for modifying a document.
945
- *
946
- * @param doc - A handle uniquely identifying the document to be edited.
947
- * @param patches - A single patch operation or an array of patch operations.
948
- * @returns An `EditDocumentAction` object ready for dispatch.
949
- * @beta
950
- */
951
- export declare function editDocument<
952
- TDocumentType extends string = string,
953
- TDataset extends string = string,
954
- TProjectId extends string = string,
955
- >(
956
- doc: DocumentHandle<TDocumentType, TDataset, TProjectId>,
957
- patches?: PatchOperations | PatchOperations[],
958
- ): EditDocumentAction<TDocumentType, TDataset, TProjectId>
959
-
960
- /**
961
- * Represents an action to edit an existing document using patches.
962
- * Requires the full document handle and an array of patch operations.
963
- * @beta
964
- */
965
- export declare interface EditDocumentAction<
966
- TDocumentType extends string = string,
967
- TDataset extends string = string,
968
- TProjectId extends string = string,
969
- > extends DocumentHandle<TDocumentType, TDataset, TProjectId> {
970
- type: 'document.edit'
971
- patches?: PatchOperations[]
972
- }
973
-
974
- /**
975
- * Error state from the auth state.
976
- * @public
977
- */
978
- export declare type ErrorAuthState = {
979
- type: AuthStateType.ERROR
980
- error: unknown
981
- }
982
-
983
- declare interface EverythingNode extends BaseNode {
984
- type: 'Everything'
985
- }
986
-
987
- declare type Executor<N = ExprNode> = (node: N, scope: Scope) => Value | PromiseLike<Value>
988
-
989
- /**
990
- * A node which can be evaluated into a value.
991
- * @public
992
- */
993
- declare type ExprNode =
994
- | AccessAttributeNode
995
- | AccessElementNode
996
- | AndNode
997
- | ArrayNode
998
- | ArrayCoerceNode
999
- | AscNode
1000
- | ContextNode
1001
- | DerefNode
1002
- | DescNode
1003
- | EverythingNode
1004
- | FilterNode
1005
- | FlatMapNode
1006
- | FuncCallNode
1007
- | GroupNode
1008
- | InRangeNode
1009
- | MapNode
1010
- | NegNode
1011
- | NotNode
1012
- | ObjectNode
1013
- | OpCallNode
1014
- | OrNode
1015
- | ParameterNode
1016
- | ParentNode_2
1017
- | PipeFuncCallNode
1018
- | PosNode
1019
- | ProjectionNode
1020
- | SelectNode
1021
- | SelectorNode
1022
- | SliceNode
1023
- | ThisNode
1024
- | TupleNode
1025
- | ValueNode
1026
-
526
+ declare const releaseNode: BoundStoreAction<ComlinkNodeState, [name: string], void>;
1027
527
  /**
528
+ * Retrieve or create a node to be used for communication between
529
+ * an application and the controller -- specifically, a node should
530
+ * be created within a frame / window to communicate with the controller.
1028
531
  * @public
1029
532
  */
1030
- declare interface FavoriteDocumentContext extends DocumentHandle {
1031
- resourceId: string
1032
- resourceType: StudioResource['type'] | MediaResource['type'] | CanvasResource['type']
1033
- schemaName?: string
1034
- }
1035
-
533
+ declare const getOrCreateNode: BoundStoreAction<ComlinkNodeState, [options: NodeInput], Node<_sanity_comlink3.Message, _sanity_comlink3.Message>>;
1036
534
  /**
1037
535
  * @public
1038
536
  */
1039
- export declare interface FavoriteStatusResponse {
1040
- isFavorited: boolean
537
+ interface NodeState {
538
+ node: Node<WindowMessage, FrameMessage>;
539
+ status: Status | undefined;
1041
540
  }
1042
-
1043
541
  /**
1044
- * Internal helper type
1045
- * @public
1046
- */
1047
- export declare interface FetcherStore<TParams extends unknown[], TData> {
1048
- getState: BoundStoreAction_3<
1049
- FetcherStoreState<TParams, TData>,
1050
- TParams,
1051
- StateSource<TData | undefined>
1052
- >
1053
- resolveState: BoundStoreAction_3<FetcherStoreState<TParams, TData>, TParams, Promise<TData>>
1054
- }
542
+ * Provides a subscribable state source for a node by name
543
+ * @param instance - The Sanity instance to get the node state for
544
+ * @param nodeInput - The configuration for the node to get the state for
1055
545
 
1056
- /**
1057
- * Internal helper type
546
+ * @returns A subscribable state source for the node
1058
547
  * @public
1059
548
  */
1060
- export declare interface FetcherStoreState<TParams extends unknown[], TData> {
1061
- stateByParams: {
1062
- [TSerializedKey in string]?: StoreEntry<TParams, TData>
1063
- }
1064
- error?: unknown
1065
- }
1066
-
1067
- declare interface FilterNode extends BaseNode {
1068
- type: 'Filter'
1069
- base: ExprNode
1070
- expr: ExprNode
1071
- }
1072
-
1073
- declare interface FlatMapNode extends BaseNode {
1074
- type: 'FlatMap'
1075
- base: ExprNode
1076
- expr: ExprNode
1077
- }
1078
-
549
+ declare const getNodeState: BoundStoreAction<ComlinkNodeState, [NodeInput], StateSource<NodeState | undefined>>;
1079
550
  /**
1080
- * Message sent from a containing app to an iframe
551
+ * Creates or validates a `DocumentHandle` object.
552
+ * Ensures the provided object conforms to the `DocumentHandle` interface.
553
+ * @param handle - The object containing document identification properties.
554
+ * @returns The validated `DocumentHandle` object.
1081
555
  * @public
1082
556
  */
1083
- export declare type FrameMessage = Message
1084
-
1085
- declare interface FuncCallNode extends BaseNode {
1086
- type: 'FuncCall'
1087
- func: GroqFunction
1088
- namespace: string
1089
- name: string
1090
- args: ExprNode[]
1091
- }
1092
-
1093
- /**
1094
- * Get the active releases from the store.
1095
- * @internal
1096
- */
1097
- export declare const getActiveReleasesState: BoundStoreAction<
1098
- ReleasesStoreState,
1099
- [],
1100
- StateSource_2<ReleaseDocument[] | undefined>
1101
- >
1102
-
557
+ declare function createDocumentHandle<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(handle: DocumentHandle<TDocumentType, TDataset, TProjectId>): DocumentHandle<TDocumentType, TDataset, TProjectId>;
1103
558
  /**
559
+ * Creates or validates a `DocumentTypeHandle` object.
560
+ * Ensures the provided object conforms to the `DocumentTypeHandle` interface.
561
+ * @param handle - The object containing document type identification properties.
562
+ * @returns The validated `DocumentTypeHandle` object.
1104
563
  * @public
1105
564
  */
1106
- export declare const getAuthState: BoundStoreAction<AuthStoreState, [], StateSource_2<AuthState>>
1107
-
565
+ declare function createDocumentTypeHandle<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(handle: DocumentTypeHandle<TDocumentType, TDataset, TProjectId>): DocumentTypeHandle<TDocumentType, TDataset, TProjectId>;
1108
566
  /**
1109
- * Retrieves a Sanity client instance configured with the provided options.
1110
- *
1111
- * This function returns a client instance configured for the project or as a
1112
- * global client based on the options provided. It ensures efficient reuse of
1113
- * client instances by returning the same instance for the same options.
1114
- * For automatic handling of authentication token updates, consider using
1115
- * `getClientState`.
1116
- *
567
+ * Creates or validates a `ProjectHandle` object.
568
+ * Ensures the provided object conforms to the `ProjectHandle` interface.
569
+ * @param handle - The object containing project identification properties.
570
+ * @returns The validated `ProjectHandle` object.
1117
571
  * @public
1118
572
  */
1119
- export declare const getClient: BoundStoreAction<
1120
- ClientState,
1121
- [options: ClientOptions],
1122
- SanityClient
1123
- >
1124
-
573
+ declare function createProjectHandle<TProjectId extends string = string>(handle: ProjectHandle<TProjectId>): ProjectHandle<TProjectId>;
1125
574
  /**
1126
- * Returns a state source for the Sanity client instance.
1127
- *
1128
- * This function provides a subscribable state source that emits updated client
1129
- * instances whenever relevant configurations change (such as authentication tokens).
1130
- * Use this when you need to react to client configuration changes in your application.
1131
- *
575
+ * Creates or validates a `DatasetHandle` object.
576
+ * Ensures the provided object conforms to the `DatasetHandle` interface.
577
+ * @param handle - The object containing dataset identification properties.
578
+ * @returns The validated `DatasetHandle` object.
1132
579
  * @public
1133
580
  */
1134
- export declare const getClientState: BoundStoreAction<
1135
- ClientState,
1136
- [options: ClientOptions],
1137
- StateSource_2<SanityClient>
1138
- >
1139
-
581
+ declare function createDatasetHandle<TDataset extends string = string, TProjectId extends string = string>(handle: DatasetHandle<TDataset, TProjectId>): DatasetHandle<TDataset, TProjectId>;
582
+ /** @public */
583
+ declare const getDatasetsState: BoundStoreAction<FetcherStoreState<[options?: ProjectHandle<string> | undefined], _sanity_client12.DatasetsResponse>, [options?: ProjectHandle<string> | undefined], StateSource<_sanity_client12.DatasetsResponse | undefined>>;
584
+ /** @public */
585
+ declare const resolveDatasets: BoundStoreAction<FetcherStoreState<[options?: ProjectHandle<string> | undefined], _sanity_client12.DatasetsResponse>, [options?: ProjectHandle<string> | undefined], Promise<_sanity_client12.DatasetsResponse>>;
1140
586
  /**
1141
- * @public
587
+ * Represents an action to create a new document.
588
+ * Specifies the document type and optionally a document ID (which will be treated as the published ID).
589
+ * @beta
1142
590
  */
1143
- export declare const getCurrentUserState: BoundStoreAction<
1144
- AuthStoreState,
1145
- [],
1146
- StateSource_2<CurrentUser | null>
1147
- >
1148
-
591
+ interface CreateDocumentAction<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string> extends DocumentTypeHandle<TDocumentType, TDataset, TProjectId> {
592
+ type: 'document.create';
593
+ }
1149
594
  /**
1150
- * @public
595
+ * Represents an action to delete an existing document.
596
+ * Requires the full document handle including the document ID.
597
+ * @beta
1151
598
  */
1152
- export declare const getDashboardOrganizationId: BoundStoreAction<
1153
- AuthStoreState,
1154
- [],
1155
- StateSource_2<string | undefined>
1156
- >
1157
-
1158
- /** @public */
1159
- export declare const getDatasetsState: BoundStoreAction<
1160
- FetcherStoreState_2<[options?: ProjectHandle<string> | undefined], DatasetsResponse>,
1161
- [options?: ProjectHandle<string> | undefined],
1162
- StateSource_2<DatasetsResponse | undefined>
1163
- >
1164
-
1165
- /** @beta */
1166
- export declare function getDocumentState<
1167
- TDocumentType extends string = string,
1168
- TDataset extends string = string,
1169
- TProjectId extends string = string,
1170
- >(
1171
- instance: SanityInstance,
1172
- options: DocumentOptions<undefined, TDocumentType, TDataset, TProjectId>,
1173
- ): StateSource<SanityDocument_2<TDocumentType, `${TProjectId}.${TDataset}`> | undefined | null>
1174
-
1175
- /** @beta */
1176
- export declare function getDocumentState<
1177
- TPath extends string = string,
1178
- TDocumentType extends string = string,
1179
- TDataset extends string = string,
1180
- TProjectId extends string = string,
1181
- >(
1182
- instance: SanityInstance,
1183
- options: DocumentOptions<TPath, TDocumentType, TDataset, TProjectId>,
1184
- ): StateSource<
1185
- JsonMatch<SanityDocument_2<TDocumentType, `${TProjectId}.${TDataset}`>, TPath> | undefined
1186
- >
1187
-
1188
- /** @beta */
1189
- export declare function getDocumentState<TData>(
1190
- instance: SanityInstance,
1191
- options: DocumentOptions<string | undefined>,
1192
- ): StateSource<TData | undefined | null>
1193
-
1194
- /** @beta */
1195
- export declare const getDocumentSyncStatus: BoundStoreAction<
1196
- DocumentStoreState,
1197
- [doc: DocumentHandle<string, string, string>],
1198
- StateSource<boolean | undefined>
1199
- >
1200
-
599
+ interface DeleteDocumentAction<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string> extends DocumentHandle<TDocumentType, TDataset, TProjectId> {
600
+ type: 'document.delete';
601
+ }
1201
602
  /**
1202
- * Gets a StateSource for the favorite status of a document.
1203
- * @param instance - The Sanity instance.
1204
- * @param context - The document context including ID, type, and resource information.
1205
- * @returns A StateSource emitting `{ isFavorited: boolean }`.
1206
- * @public
603
+ * Represents an action to edit an existing document using patches.
604
+ * Requires the full document handle and an array of patch operations.
605
+ * @beta
1207
606
  */
1208
- export declare const getFavoritesState: BoundStoreAction<
1209
- FetcherStoreState_2<[FavoriteDocumentContext], FavoriteStatusResponse>,
1210
- [FavoriteDocumentContext],
1211
- StateSource_2<FavoriteStatusResponse | undefined>
1212
- >
1213
-
1214
- export {getIndexForKey}
1215
-
607
+ interface EditDocumentAction<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string> extends DocumentHandle<TDocumentType, TDataset, TProjectId> {
608
+ type: 'document.edit';
609
+ patches?: PatchOperations[];
610
+ }
1216
611
  /**
1217
- * Returns a state source indicating if the SDK is running within a dashboard context.
1218
- * @public
612
+ * Represents an action to publish the draft version of a document.
613
+ * Requires the full document handle.
614
+ * @beta
1219
615
  */
1220
- export declare const getIsInDashboardState: BoundStoreAction<
1221
- AuthStoreState,
1222
- [],
1223
- StateSource_2<boolean>
1224
- >
1225
-
616
+ interface PublishDocumentAction<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string> extends DocumentHandle<TDocumentType, TDataset, TProjectId> {
617
+ type: 'document.publish';
618
+ }
1226
619
  /**
1227
- * @public
620
+ * Represents an action to unpublish a document, moving its published content to a draft.
621
+ * Requires the full document handle.
622
+ * @beta
1228
623
  */
1229
- export declare const getLoginUrlState: BoundStoreAction<AuthStoreState, [], StateSource_2<string>>
1230
-
624
+ interface UnpublishDocumentAction<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string> extends DocumentHandle<TDocumentType, TDataset, TProjectId> {
625
+ type: 'document.unpublish';
626
+ }
1231
627
  /**
1232
- * Provides a subscribable state source for a node by name
1233
- * @param instance - The Sanity instance to get the node state for
1234
- * @param nodeInput - The configuration for the node to get the state for
1235
-
1236
- * @returns A subscribable state source for the node
1237
- * @public
628
+ * Represents an action to discard the draft changes of a document.
629
+ * Requires the full document handle.
630
+ * @beta
1238
631
  */
1239
- export declare const getNodeState: BoundStoreAction_2<
1240
- ComlinkNodeState,
1241
- [NodeInput],
1242
- StateSource_3<NodeState | undefined>
1243
- >
1244
-
632
+ interface DiscardDocumentAction<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string> extends DocumentHandle<TDocumentType, TDataset, TProjectId> {
633
+ type: 'document.discard';
634
+ }
1245
635
  /**
1246
- * Retrieve or create a channel to be used for communication between
1247
- * an application and the controller.
1248
- * @public
636
+ * Union type representing all possible document actions within the SDK.
637
+ * @beta
1249
638
  */
1250
- export declare const getOrCreateChannel: BoundStoreAction_2<
1251
- ComlinkControllerState,
1252
- [options: ChannelInput],
1253
- ChannelInstance<Message, Message>
1254
- >
1255
-
639
+ type DocumentAction<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string> = CreateDocumentAction<TDocumentType, TDataset, TProjectId> | DeleteDocumentAction<TDocumentType, TDataset, TProjectId> | EditDocumentAction<TDocumentType, TDataset, TProjectId> | PublishDocumentAction<TDocumentType, TDataset, TProjectId> | UnpublishDocumentAction<TDocumentType, TDataset, TProjectId> | DiscardDocumentAction<TDocumentType, TDataset, TProjectId>;
1256
640
  /**
1257
- * Initializes or fetches a controller to handle communication
1258
- * between an application and iframes.
1259
- * @public
641
+ * Creates a `CreateDocumentAction` object.
642
+ * @param doc - A handle identifying the document type, dataset, and project. An optional `documentId` can be provided.
643
+ * @returns A `CreateDocumentAction` object ready for dispatch.
644
+ * @beta
1260
645
  */
1261
- export declare const getOrCreateController: BoundStoreAction_2<
1262
- ComlinkControllerState,
1263
- [targetOrigin: string],
1264
- Controller
1265
- >
1266
-
646
+ declare function createDocument<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(doc: DocumentTypeHandle<TDocumentType, TDataset, TProjectId>): CreateDocumentAction<TDocumentType, TDataset, TProjectId>;
1267
647
  /**
1268
- * Retrieve or create a node to be used for communication between
1269
- * an application and the controller -- specifically, a node should
1270
- * be created within a frame / window to communicate with the controller.
1271
- * @public
648
+ * Creates a `DeleteDocumentAction` object.
649
+ * @param doc - A handle uniquely identifying the document to be deleted.
650
+ * @returns A `DeleteDocumentAction` object ready for dispatch.
651
+ * @beta
1272
652
  */
1273
- export declare const getOrCreateNode: BoundStoreAction_2<
1274
- ComlinkNodeState,
1275
- [options: NodeInput],
1276
- Node_2<Message, Message>
1277
- >
1278
-
1279
- export {getPathDepth}
1280
-
1281
- /** @beta */
1282
- export declare const getPermissionsState: BoundStoreAction<
1283
- DocumentStoreState,
1284
- [DocumentAction | DocumentAction[]],
1285
- StateSource<DocumentPermissionsResult_2 | undefined>
1286
- >
1287
-
653
+ declare function deleteDocument<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(doc: DocumentHandle<TDocumentType, TDataset, TProjectId>): DeleteDocumentAction<TDocumentType, TDataset, TProjectId>;
1288
654
  /**
1289
- * Provides a subscribable state source for a "perspective" for the Sanity client,
1290
- * which is used to fetch documents as though certain Content Releases are active.
1291
- *
1292
- * @param instance - The Sanity instance to get the perspective for
1293
- * @param options - The options for the perspective -- usually a release name
1294
- *
1295
- * @returns A subscribable perspective value, usually a list of applicable release names,
1296
- * or a single release name / default perspective (such as 'drafts').
655
+ * Creates an `EditDocumentAction` object with patches for modifying a document.
656
+ * Accepts patches in either the standard `PatchOperations` format or as a `SanityMutatePatchMutation` from `@sanity/mutate`.
1297
657
  *
1298
- * @public
1299
- */
1300
- export declare const getPerspectiveState: BoundStoreAction<
1301
- ReleasesStoreState,
1302
- [options?: PerspectiveHandle | undefined],
1303
- StateSource_2<string[] | 'published' | 'drafts' | 'previewDrafts' | 'raw' | undefined>
1304
- >
1305
-
1306
- /**
658
+ * @param doc - A handle uniquely identifying the document to be edited.
659
+ * @param sanityMutatePatch - A patch mutation object from `@sanity/mutate`.
660
+ * @returns An `EditDocumentAction` object ready for dispatch.
1307
661
  * @beta
1308
662
  */
1309
- export declare function getPreviewState<TResult extends object>(
1310
- instance: SanityInstance,
1311
- options: GetPreviewStateOptions,
1312
- ): StateSource<ValuePending<TResult>>
1313
-
663
+ declare function editDocument<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(doc: DocumentHandle<TDocumentType, TDataset, TProjectId>, sanityMutatePatch: PatchMutation): EditDocumentAction<TDocumentType, TDataset, TProjectId>;
1314
664
  /**
665
+ * Creates an `EditDocumentAction` object with patches for modifying a document.
666
+ *
667
+ * @param doc - A handle uniquely identifying the document to be edited.
668
+ * @param patches - A single patch operation or an array of patch operations.
669
+ * @returns An `EditDocumentAction` object ready for dispatch.
1315
670
  * @beta
1316
671
  */
1317
- export declare function getPreviewState(
1318
- instance: SanityInstance,
1319
- options: GetPreviewStateOptions,
1320
- ): StateSource<ValuePending<PreviewValue>>
1321
-
672
+ declare function editDocument<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(doc: DocumentHandle<TDocumentType, TDataset, TProjectId>, patches?: PatchOperations | PatchOperations[]): EditDocumentAction<TDocumentType, TDataset, TProjectId>;
1322
673
  /**
674
+ * Creates a `PublishDocumentAction` object.
675
+ * @param doc - A handle uniquely identifying the document to be published.
676
+ * @returns A `PublishDocumentAction` object ready for dispatch.
1323
677
  * @beta
1324
678
  */
1325
- export declare type GetPreviewStateOptions = DocumentHandle
1326
-
679
+ declare function publishDocument<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(doc: DocumentHandle<TDocumentType, TDataset, TProjectId>): PublishDocumentAction<TDocumentType, TDataset, TProjectId>;
1327
680
  /**
681
+ * Creates an `UnpublishDocumentAction` object.
682
+ * @param doc - A handle uniquely identifying the document to be unpublished.
683
+ * @returns An `UnpublishDocumentAction` object ready for dispatch.
1328
684
  * @beta
1329
685
  */
1330
- export declare function getProjectionState<
1331
- TProjection extends ValidProjection = ValidProjection,
1332
- TDocumentType extends string = string,
1333
- TDataset extends string = string,
1334
- TProjectId extends string = string,
1335
- >(
1336
- instance: SanityInstance,
1337
- options: ProjectionOptions<TProjection, TDocumentType, TDataset, TProjectId>,
1338
- ): StateSource<
1339
- | ProjectionValuePending<
1340
- SanityProjectionResult<TProjection, TDocumentType, `${TProjectId}.${TDataset}`>
1341
- >
1342
- | undefined
1343
- >
1344
-
686
+ declare function unpublishDocument<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(doc: DocumentHandle<TDocumentType, TDataset, TProjectId>): UnpublishDocumentAction<TDocumentType, TDataset, TProjectId>;
1345
687
  /**
688
+ * Creates a `DiscardDocumentAction` object.
689
+ * @param doc - A handle uniquely identifying the document whose draft changes are to be discarded.
690
+ * @returns A `DiscardDocumentAction` object ready for dispatch.
1346
691
  * @beta
1347
692
  */
1348
- export declare function getProjectionState<TData extends object>(
1349
- instance: SanityInstance,
1350
- options: ProjectionOptions,
1351
- ): StateSource<ProjectionValuePending<TData> | undefined>
1352
-
693
+ declare function discardDocument<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(doc: DocumentHandle<TDocumentType, TDataset, TProjectId>): DiscardDocumentAction<TDocumentType, TDataset, TProjectId>;
1353
694
  /**
1354
- * @beta
695
+ * Represents a set of document that will go into `applyMutations`. Before
696
+ * applying a mutation, it's expected that all relevant documents that the
697
+ * mutations affect are included, including those that do not exist yet.
698
+ * Documents that don't exist have a `null` value.
1355
699
  */
1356
- export declare function getProjectionState(
1357
- instance: SanityInstance,
1358
- options: ProjectionOptions,
1359
- ): StateSource<ProjectionValuePending<Record<string, unknown>> | undefined>
1360
-
1361
- /** @public */
1362
- export declare const getProjectsState: BoundStoreAction<
1363
- FetcherStoreState_2<[], Omit<SanityProject_2, 'members'>[]>,
1364
- [],
1365
- StateSource_2<Omit<SanityProject_2, 'members'>[] | undefined>
1366
- >
1367
-
1368
- /** @public */
1369
- export declare const getProjectState: BoundStoreAction<
1370
- FetcherStoreState_2<[options?: ProjectHandle<string> | undefined], SanityProject_2>,
1371
- [options?: ProjectHandle<string> | undefined],
1372
- StateSource_2<SanityProject_2 | undefined>
1373
- >
1374
-
1375
- /** @beta */
1376
- export declare const getQueryKey: (options: QueryOptions) => string
1377
-
700
+ type DocumentSet<TDocument extends SanityDocument$2 = SanityDocument$2> = { [TDocumentId in string]?: TDocument | null };
1378
701
  /**
1379
- * Returns the state source for a query.
1380
- *
1381
- * This function returns a state source that represents the current result of a GROQ query.
1382
- * Subscribing to the state source will instruct the SDK to fetch the query (if not already fetched)
1383
- * and will keep the query live using the Live content API (considering sync tags) to provide up-to-date results.
1384
- * When the last subscriber is removed, the query state is automatically cleaned up from the store.
702
+ * Implements ID generation:
1385
703
  *
1386
- * Note: This functionality is for advanced users who want to build their own framework integrations.
1387
- * Our SDK also provides a React integration (useQuery hook) for convenient usage.
704
+ * A create mutation creates a new document. It takes the literal document
705
+ * content as its argument. The rules for the new document's identifier are as
706
+ * follows:
1388
707
  *
1389
- * Note: Automatic cleanup can interfere with React Suspense because if a component suspends while being the only subscriber,
1390
- * cleanup might occur unexpectedly. In such cases, consider using `resolveQuery` instead.
708
+ * - If the `_id` attribute is missing, then a new, random, unique ID is
709
+ * generated.
710
+ * - If the `_id` attribute is present but ends with `.`, then it is used as a
711
+ * prefix for a new, random, unique ID.
712
+ * - If the _id attribute is present, it is used as-is.
1391
713
  *
1392
- * @beta
714
+ * [- source](https://www.sanity.io/docs/http-mutations#c732f27330a4)
1393
715
  */
1394
- export declare function getQueryState<
1395
- TQuery extends string = string,
1396
- TDataset extends string = string,
1397
- TProjectId extends string = string,
1398
- >(
1399
- instance: SanityInstance,
1400
- queryOptions: QueryOptions<TQuery, TDataset, TProjectId>,
1401
- ): StateSource<SanityQueryResult<TQuery, `${TProjectId}.${TDataset}`> | undefined>
1402
-
1403
716
  /** @beta */
1404
- export declare function getQueryState<TData>(
1405
- instance: SanityInstance,
1406
- queryOptions: QueryOptions,
1407
- ): StateSource<TData | undefined>
1408
-
717
+ interface ActionsResult<TDocument extends SanityDocument$3 = SanityDocument$3> {
718
+ transactionId: string;
719
+ documents: DocumentSet<TDocument>;
720
+ previous: DocumentSet<TDocument>;
721
+ previousRevs: {
722
+ [documentId: string]: string | undefined;
723
+ };
724
+ appeared: string[];
725
+ updated: string[];
726
+ disappeared: string[];
727
+ submitted: () => ReturnType<SanityClient['action']>;
728
+ }
1409
729
  /** @beta */
1410
- export declare function getQueryState(
1411
- instance: SanityInstance,
1412
- queryOptions: QueryOptions,
1413
- ): StateSource<unknown>
1414
-
1415
- /**
1416
- * @public
1417
- */
1418
- export declare const getTokenState: BoundStoreAction<
1419
- AuthStoreState,
1420
- [],
1421
- StateSource_2<string | null>
1422
- >
1423
-
1424
- /** @internal */
1425
- export declare const getUsersKey: (
1426
- instance: SanityInstance,
1427
- {resourceType, organizationId, batchSize, projectId}?: GetUsersOptions,
1428
- ) => string
1429
-
1430
- /**
1431
- * @public
1432
- */
1433
- export declare interface GetUsersOptions extends ProjectHandle {
1434
- resourceType?: 'organization' | 'project'
1435
- batchSize?: number
1436
- organizationId?: string
730
+ interface ApplyDocumentActionsOptions {
731
+ /**
732
+ * Optionally provide an ID to be used as this transaction ID
733
+ */
734
+ transactionId?: string;
735
+ /**
736
+ * Set this to true to prevent this action from being batched with others.
737
+ */
738
+ disableBatching?: boolean;
1437
739
  }
1438
-
1439
- /**
1440
- * Returns the state source for users associated with a specific resource.
1441
- *
1442
- * This function returns a state source that represents the current list of users for a given
1443
- * resource. Subscribing to the state source will instruct the SDK to fetch the users (if not
1444
- * already fetched) and will load more from this state source as well. When the last subscriber is
1445
- * removed, the users state is automatically cleaned up from the store after a delay.
1446
- *
1447
- * Note: This functionality is for advanced users who want to build their own framework
1448
- * integrations. Our SDK also provides a React integration for convenient usage.
1449
- *
1450
- * @beta
1451
- */
1452
- export declare const getUsersState: BoundStoreAction<
1453
- UsersStoreState,
1454
- [options?: GetUsersOptions | undefined],
1455
- StateSource_2<
1456
- | {
1457
- data: SanityUser_2[]
1458
- totalCount: number
1459
- hasMore: boolean
1460
- }
1461
- | undefined
1462
- >
1463
- >
1464
-
1465
- declare type Grant = 'read' | 'update' | 'create' | 'history'
1466
-
1467
- /** @public */
1468
- declare type GroqFunction = (
1469
- args: GroqFunctionArg[],
1470
- scope: Scope,
1471
- execute: Executor,
1472
- ) => PromiseLike<Value>
1473
-
1474
- /** @public */
1475
- declare type GroqFunctionArg = ExprNode
1476
-
1477
- declare type GroqPipeFunction = (
1478
- base: Value,
1479
- args: ExprNode[],
1480
- scope: Scope,
1481
- execute: Executor,
1482
- ) => PromiseLike<Value>
1483
-
1484
- /**
1485
- * A type of a value in GROQ.
1486
- */
1487
- declare type GroqType =
1488
- | 'null'
1489
- | 'boolean'
1490
- | 'number'
1491
- | 'string'
1492
- | 'array'
1493
- | 'object'
1494
- | 'path'
1495
- | 'datetime'
1496
-
1497
- declare interface GroupNode extends BaseNode {
1498
- type: 'Group'
1499
- base: ExprNode
740
+ /** @beta */
741
+ declare function applyDocumentActions<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(instance: SanityInstance, action: DocumentAction<TDocumentType, TDataset, TProjectId> | DocumentAction<TDocumentType, TDataset, TProjectId>[], options?: ApplyDocumentActionsOptions): Promise<ActionsResult<SanityDocument$3<TDocumentType, `${TProjectId}.${TDataset}`>>>;
742
+ /** @beta */
743
+ declare function applyDocumentActions(instance: SanityInstance, action: DocumentAction | DocumentAction[], options?: ApplyDocumentActionsOptions): Promise<ActionsResult>;
744
+ declare interface AccessAttributeNode extends BaseNode {
745
+ type: 'AccessAttribute';
746
+ base?: ExprNode;
747
+ name: string;
748
+ }
749
+ declare interface AccessElementNode extends BaseNode {
750
+ type: 'AccessElement';
751
+ base: ExprNode;
752
+ index: number;
753
+ }
754
+ declare interface AndNode extends BaseNode {
755
+ type: 'And';
756
+ left: ExprNode;
757
+ right: ExprNode;
758
+ }
759
+ declare type AnyStaticValue = StringValue | NumberValue | NullValue | BooleanValue | DateTimeValue | ObjectValue | ArrayValue | PathValue;
760
+ declare interface ArrayCoerceNode extends BaseNode {
761
+ type: 'ArrayCoerce';
762
+ base: ExprNode;
763
+ }
764
+ declare interface ArrayElementNode extends BaseNode {
765
+ type: 'ArrayElement';
766
+ value: ExprNode;
767
+ isSplat: boolean;
768
+ }
769
+ declare interface ArrayNode extends BaseNode {
770
+ type: 'Array';
771
+ elements: ArrayElementNode[];
1500
772
  }
1501
773
 
1502
- /**
1503
- * @public
1504
- */
1505
- export declare const handleAuthCallback: BoundStoreAction<
1506
- AuthStoreState,
1507
- [locationHref?: string | undefined],
1508
- Promise<string | false>
1509
- >
1510
-
1511
- declare type HttpAction =
1512
- | {
1513
- actionType: ActionMap['create']
1514
- publishedId: string
1515
- attributes: SanityDocumentLike
1516
- }
1517
- | {
1518
- actionType: ActionMap['discard']
1519
- versionId: string
1520
- purge?: boolean
1521
- }
1522
- | {
1523
- actionType: ActionMap['unpublish']
1524
- draftId: string
1525
- publishedId: string
1526
- }
1527
- | {
1528
- actionType: ActionMap['delete']
1529
- publishedId: string
1530
- includeDrafts?: string[]
1531
- }
1532
- | {
1533
- actionType: ActionMap['edit']
1534
- draftId: string
1535
- publishedId: string
1536
- patch: PatchOperations
1537
- }
1538
- | ({
1539
- actionType: ActionMap['publish']
1540
- draftId: string
1541
- publishedId: string
1542
- } & OptimisticLock)
774
+ /** Describes a type node for array values. */
1543
775
 
1544
- declare interface InRangeNode extends BaseNode {
1545
- type: 'InRange'
1546
- base: ExprNode
1547
- left: ExprNode
1548
- right: ExprNode
1549
- isInclusive: boolean
776
+ declare type ArrayValue = StaticValue<unknown[], 'array'>;
777
+ declare interface AscNode extends BaseNode {
778
+ type: 'Asc';
779
+ base: ExprNode;
1550
780
  }
1551
781
 
1552
- export {joinPaths}
782
+ /** The base interface for SyntaxNode. */
783
+ declare interface BaseNode {
784
+ type: string;
785
+ }
1553
786
 
1554
- /**
1555
- * Given a document type TDocument and a JSON Match path string TPath,
1556
- * compute the type found at that path.
1557
- * @beta
1558
- */
1559
- export declare type JsonMatch<TDocument, TPath extends string> = DeepGet<
1560
- TDocument,
1561
- PathParts<TPath>
1562
- >
787
+ /** Describes a type node for boolean values, optionally including a value. If a value is provided it will always be the given boolean value. */
1563
788
 
1564
- export {jsonMatch}
789
+ declare type BooleanValue = StaticValue<boolean, 'boolean'>;
790
+ declare interface Context {
791
+ timestamp: Date;
792
+ identity: string;
793
+ before: Value | null;
794
+ after: Value | null;
795
+ sanity?: {
796
+ projectId: string;
797
+ dataset: string;
798
+ };
799
+ dereference?: DereferenceFunction;
800
+ }
801
+ declare interface ContextNode extends BaseNode {
802
+ type: 'Context';
803
+ key: string;
804
+ }
1565
805
 
1566
806
  /**
1567
- * Loads more users for a specific resource.
1568
- *
1569
- * This function triggers a request to fetch the next page of users for a given resource. It
1570
- * requires that users have already been loaded for the resource (via `resolveUsers` or
1571
- * `getUsersState`), and that there are more users available to load (as indicated by the `hasMore`
1572
- * property).
1573
- *
1574
- * The function returns a promise that resolves when the next page of users has been loaded.
1575
- *
1576
- * @beta
807
+ * createReferenceTypeNode creates a ObjectTypeNode representing a reference type
808
+ * it adds required attributes for a reference type.
809
+ * @param name - The name of the reference type
810
+ * @param inArray - Whether the reference is in an array
811
+ * @returns A ObjectTypeNode representing a reference type
812
+ * @internal
1577
813
  */
1578
- export declare const loadMoreUsers: BoundStoreAction<
1579
- UsersStoreState,
1580
- [options?: GetUsersOptions | undefined],
1581
- Promise<{
1582
- data: SanityUser_2[]
1583
- totalCount: number
1584
- hasMore: boolean
1585
- }>
1586
- >
1587
814
 
1588
- /**
1589
- * Logged-in state from the auth state.
1590
- * @public
1591
- */
1592
- export declare type LoggedInAuthState = {
1593
- type: AuthStateType.LOGGED_IN
1594
- token: string
1595
- currentUser: CurrentUser | null
815
+ declare class DateTime {
816
+ date: Date;
817
+ constructor(date: Date);
818
+ static parseToValue(str: string): Value;
819
+ equals(other: DateTime): boolean;
820
+ add(secs: number): DateTime;
821
+ difference(other: DateTime): number;
822
+ compareTo(other: DateTime): number;
823
+ toString(): string;
824
+ toJSON(): string;
825
+ }
826
+ declare type DateTimeValue = StaticValue<DateTime, 'datetime'>;
827
+ declare type DereferenceFunction = (obj: {
828
+ _ref: string;
829
+ }) => PromiseLike<Document_2 | null | undefined>;
830
+ declare interface DerefNode extends BaseNode {
831
+ type: 'Deref';
832
+ base: ExprNode;
1596
833
  }
1597
-
1598
- /**
1599
- * Logged-out state from the auth state.
1600
- * @public
1601
- */
1602
- export declare type LoggedOutAuthState = {
1603
- type: AuthStateType.LOGGED_OUT
1604
- isDestroyingSession: boolean
834
+ declare interface DescNode extends BaseNode {
835
+ type: 'Desc';
836
+ base: ExprNode;
837
+ }
838
+ declare type Document_2 = {
839
+ _id?: string;
840
+ _type?: string;
841
+ [T: string]: unknown;
842
+ };
843
+ declare interface EverythingNode extends BaseNode {
844
+ type: 'Everything';
1605
845
  }
846
+ declare type Executor<N = ExprNode> = (node: N, scope: Scope) => Value | PromiseLike<Value>;
1606
847
 
1607
848
  /**
1608
- * Logging-in state from the auth state.
849
+ * A node which can be evaluated into a value.
1609
850
  * @public
1610
851
  */
1611
- export declare type LoggingInAuthState = {
1612
- type: AuthStateType.LOGGING_IN
1613
- isExchangingToken: boolean
852
+ declare type ExprNode = AccessAttributeNode | AccessElementNode | AndNode | ArrayNode | ArrayCoerceNode | AscNode | ContextNode | DerefNode | DescNode | EverythingNode | FilterNode | FlatMapNode | FuncCallNode | GroupNode | InRangeNode | MapNode | NegNode | NotNode | ObjectNode | OpCallNode | OrNode | ParameterNode | ParentNode_2 | PipeFuncCallNode | PosNode | ProjectionNode | SelectNode | SelectorNode | SliceNode | ThisNode | TupleNode | ValueNode;
853
+ declare interface FilterNode extends BaseNode {
854
+ type: 'Filter';
855
+ base: ExprNode;
856
+ expr: ExprNode;
857
+ }
858
+ declare interface FlatMapNode extends BaseNode {
859
+ type: 'FlatMap';
860
+ base: ExprNode;
861
+ expr: ExprNode;
862
+ }
863
+ declare interface FuncCallNode extends BaseNode {
864
+ type: 'FuncCall';
865
+ func: GroqFunction;
866
+ namespace: string;
867
+ name: string;
868
+ args: ExprNode[];
1614
869
  }
1615
870
 
1616
- /**
1617
- * @public
1618
- */
1619
- export declare const logout: BoundStoreAction<AuthStoreState_2, [], Promise<void>>
871
+ /** @public */
872
+ declare type GroqFunction = (args: GroqFunctionArg[], scope: Scope, execute: Executor) => PromiseLike<Value>;
1620
873
 
1621
- declare interface MapNode extends BaseNode {
1622
- type: 'Map'
1623
- base: ExprNode
1624
- expr: ExprNode
1625
- }
874
+ /** @public */
875
+ declare type GroqFunctionArg = ExprNode;
876
+ declare type GroqPipeFunction = (base: Value, args: ExprNode[], scope: Scope, execute: Executor) => PromiseLike<Value>;
1626
877
 
1627
878
  /**
1628
- * @public
879
+ * A type of a value in GROQ.
1629
880
  */
1630
- export declare interface Membership {
1631
- addedAt?: string
1632
- resourceType: string
1633
- resourceId: string
1634
- roleNames: Array<string>
1635
- lastSeenAt?: string | null
881
+ declare type GroqType = 'null' | 'boolean' | 'number' | 'string' | 'array' | 'object' | 'path' | 'datetime';
882
+ declare interface GroupNode extends BaseNode {
883
+ type: 'Group';
884
+ base: ExprNode;
1636
885
  }
1637
886
 
1638
- declare interface NegNode extends BaseNode {
1639
- type: 'Neg'
1640
- base: ExprNode
1641
- }
887
+ /** Describes a type node for inline values, including a name that references another type. */
1642
888
 
1643
- /**
1644
- * Message from Parent (dashboard) to SDK (iframe) with the new token
1645
- * @internal
1646
- */
1647
- export declare type NewTokenResponseMessage = {
1648
- type: 'dashboard/v1/auth/tokens/create'
1649
- payload: {
1650
- token: string | null
1651
- error?: string
1652
- }
889
+ declare interface InRangeNode extends BaseNode {
890
+ type: 'InRange';
891
+ base: ExprNode;
892
+ left: ExprNode;
893
+ right: ExprNode;
894
+ isInclusive: boolean;
1653
895
  }
1654
-
1655
- /**
1656
- * Individual node with its relevant options
1657
- * @public
1658
- */
1659
- declare interface NodeEntry {
1660
- node: Node_2<WindowMessage, FrameMessage>
1661
- options: NodeInput
1662
- status: Status
1663
- statusUnsub?: () => void
896
+ declare interface MapNode extends BaseNode {
897
+ type: 'Map';
898
+ base: ExprNode;
899
+ expr: ExprNode;
1664
900
  }
1665
-
1666
- /**
1667
- * @public
1668
- */
1669
- export declare interface NodeState {
1670
- node: Node_2<WindowMessage, FrameMessage>
1671
- status: Status | undefined
901
+ declare interface NegNode extends BaseNode {
902
+ type: 'Neg';
903
+ base: ExprNode;
1672
904
  }
1673
-
1674
905
  declare interface NotNode extends BaseNode {
1675
- type: 'Not'
1676
- base: ExprNode
906
+ type: 'Not';
907
+ base: ExprNode;
1677
908
  }
1678
909
 
1679
- declare type NullValue = StaticValue<null, 'null'>
910
+ /** Describes a type node for null values, always being the null value. */
911
+
912
+ declare type NullValue = StaticValue<null, 'null'>;
913
+
914
+ /** Describes a type node for number values, optionally including a value. If a value is provided it will always be the given numeric value.*/
1680
915
 
1681
- declare type NumberValue = StaticValue<number, 'number'>
916
+ declare type NumberValue = StaticValue<number, 'number'>;
1682
917
 
1683
- declare type ObjectAttributeNode =
1684
- | ObjectAttributeValueNode
1685
- | ObjectConditionalSplatNode
1686
- | ObjectSplatNode
918
+ /** Describes a type node for object attributes, including a type and an optional flag for being optional. */
1687
919
 
920
+ declare type ObjectAttributeNode = ObjectAttributeValueNode | ObjectConditionalSplatNode | ObjectSplatNode;
1688
921
  declare interface ObjectAttributeValueNode extends BaseNode {
1689
- type: 'ObjectAttributeValue'
1690
- name: string
1691
- value: ExprNode
922
+ type: 'ObjectAttributeValue';
923
+ name: string;
924
+ value: ExprNode;
1692
925
  }
1693
-
1694
926
  declare interface ObjectConditionalSplatNode extends BaseNode {
1695
- type: 'ObjectConditionalSplat'
1696
- condition: ExprNode
1697
- value: ExprNode
927
+ type: 'ObjectConditionalSplat';
928
+ condition: ExprNode;
929
+ value: ExprNode;
1698
930
  }
1699
-
1700
931
  declare interface ObjectNode extends BaseNode {
1701
- type: 'Object'
1702
- attributes: ObjectAttributeNode[]
932
+ type: 'Object';
933
+ attributes: ObjectAttributeNode[];
1703
934
  }
1704
-
1705
935
  declare interface ObjectSplatNode extends BaseNode {
1706
- type: 'ObjectSplat'
1707
- value: ExprNode
936
+ type: 'ObjectSplat';
937
+ value: ExprNode;
1708
938
  }
1709
939
 
1710
- declare type ObjectValue = StaticValue<Record<string, unknown>, 'object'>
1711
-
1712
940
  /**
1713
- * Creates an observable that emits the organization verification state for a given instance.
1714
- * It combines the dashboard organization ID (from auth context) with the
1715
- * project's actual organization ID (fetched via getProjectState) and compares them.
1716
- * @public
941
+ * Describes a type node for object values, including a collection of attributes and an optional rest value.
942
+ * The rest value can be another ObjectTypeNode, an UnknownTypeNode, or an InlineTypeNode.
943
+ * If the rest value is an ObjectTypeNode, it means that the object can have additional attributes.
944
+ * If the rest value is an UnknownTypeNode, the entire object is unknown.
945
+ * If the rest value is an InlineTypeNode, it means that the object has additional attributes from the referenced type.
1717
946
  */
1718
- export declare function observeOrganizationVerificationState(
1719
- instance: SanityInstance,
1720
- projectIds: string[],
1721
- ): Observable<OrgVerificationResult>
1722
-
1723
- declare type OpCall =
1724
- | '=='
1725
- | '!='
1726
- | '>'
1727
- | '>='
1728
- | '<'
1729
- | '<='
1730
- | '+'
1731
- | '-'
1732
- | '*'
1733
- | '/'
1734
- | '%'
1735
- | '**'
1736
- | 'in'
1737
- | 'match'
1738
947
 
948
+ declare type ObjectValue = StaticValue<Record<string, unknown>, 'object'>;
949
+ declare type OpCall = '==' | '!=' | '>' | '>=' | '<' | '<=' | '+' | '-' | '*' | '/' | '%' | '**' | 'in' | 'match';
1739
950
  declare interface OpCallNode extends BaseNode {
1740
- type: 'OpCall'
1741
- op: OpCall
1742
- left: ExprNode
1743
- right: ExprNode
1744
- }
1745
-
1746
- declare type OptimisticLock = {
1747
- ifDraftRevisionId?: string
1748
- ifPublishedRevisionId?: string
1749
- }
1750
-
1751
- /**
1752
- * Error message returned by the organization verification
1753
- * @public
1754
- */
1755
- export declare interface OrgVerificationResult {
1756
- error: string | null
951
+ type: 'OpCall';
952
+ op: OpCall;
953
+ left: ExprNode;
954
+ right: ExprNode;
1757
955
  }
1758
-
1759
956
  declare interface OrNode extends BaseNode {
1760
- type: 'Or'
1761
- left: ExprNode
1762
- right: ExprNode
1763
- }
1764
-
1765
- /**
1766
- * Represents a set of applied transactions batched into a single outgoing
1767
- * transaction. An outgoing transaction is the result of batching many applied
1768
- * actions. An outgoing transaction may be reverted locally if the server
1769
- * does not accept it.
1770
- */
1771
- declare interface OutgoingTransaction extends AppliedTransaction {
1772
- disableBatching: boolean
1773
- batchedTransactionIds: string[]
957
+ type: 'Or';
958
+ left: ExprNode;
959
+ right: ExprNode;
1774
960
  }
1775
-
1776
961
  declare interface ParameterNode extends BaseNode {
1777
- type: 'Parameter'
1778
- name: string
962
+ type: 'Parameter';
963
+ name: string;
1779
964
  }
1780
-
1781
965
  declare interface ParentNode_2 extends BaseNode {
1782
- type: 'Parent'
1783
- n: number
966
+ type: 'Parent';
967
+ n: number;
968
+ }
969
+ declare class Path {
970
+ private pattern;
971
+ private patternRe;
972
+ constructor(pattern: string);
973
+ matches(str: string): boolean;
974
+ toJSON(): string;
975
+ }
976
+ declare type PathValue = StaticValue<Path, 'path'>;
977
+ declare interface PipeFuncCallNode extends BaseNode {
978
+ type: 'PipeFuncCall';
979
+ func: GroqPipeFunction;
980
+ base: ExprNode;
981
+ name: string;
982
+ args: ExprNode[];
983
+ }
984
+ declare interface PosNode extends BaseNode {
985
+ type: 'Pos';
986
+ base: ExprNode;
1784
987
  }
1785
988
 
1786
- /** @beta */
1787
- export declare const parseQueryKey: (key: string) => QueryOptions
989
+ /** Union of any primitive type nodes. */
1788
990
 
1789
- /** @internal */
1790
- export declare const parseUsersKey: (key: string) => {
1791
- batchSize: number
1792
- resourceType?: 'organization' | 'project'
1793
- projectId?: string
1794
- organizationId?: string
991
+ declare interface ProjectionNode extends BaseNode {
992
+ type: 'Projection';
993
+ base: ExprNode;
994
+ expr: ExprNode;
1795
995
  }
1796
996
 
1797
- declare class Path {
1798
- private pattern
1799
- private patternRe
1800
- constructor(pattern: string)
1801
- matches(str: string): boolean
1802
- toJSON(): string
1803
- }
997
+ /** A schema consisting of a list of Document or TypeDeclaration items, allowing for complex type definitions. */
1804
998
 
1805
- /**
1806
- * Split the entire path string on dots "outside" of any brackets.
1807
- *
1808
- * For example:
1809
- * ```
1810
- * "friends[0].name"
1811
- * ```
1812
- *
1813
- * becomes:
1814
- *
1815
- * ```
1816
- * [...ParseSegment<"friends[0]">, ...ParseSegment<"name">]
1817
- * ```
1818
- *
1819
- * (We use a simple recursion that splits on the first dot.)
1820
- */
1821
- declare type PathParts<TPath extends string> = TPath extends `${infer Head}.${infer Tail}`
1822
- ? [Head, ...PathParts<Tail>]
1823
- : TPath extends ''
1824
- ? []
1825
- : [TPath]
999
+ declare class Scope {
1000
+ params: Record<string, unknown>;
1001
+ source: Value;
1002
+ value: Value;
1003
+ parent: Scope | null;
1004
+ context: Context;
1005
+ isHidden: boolean;
1006
+ constructor(params: Record<string, unknown>, source: Value, value: Value, context: Context, parent: Scope | null);
1007
+ createNested(value: Value): Scope;
1008
+ createHidden(value: Value): Scope;
1009
+ }
1010
+ declare interface SelectAlternativeNode extends BaseNode {
1011
+ type: 'SelectAlternative';
1012
+ condition: ExprNode;
1013
+ value: ExprNode;
1014
+ }
1015
+ declare interface SelectNode extends BaseNode {
1016
+ type: 'Select';
1017
+ alternatives: SelectAlternativeNode[];
1018
+ fallback?: ExprNode;
1019
+ }
1020
+ declare interface SelectorNode extends BaseNode {
1021
+ type: 'Selector';
1022
+ }
1023
+ declare interface SliceNode extends BaseNode {
1024
+ type: 'Slice';
1025
+ base: ExprNode;
1026
+ left: number;
1027
+ right: number;
1028
+ isInclusive: boolean;
1029
+ }
1030
+ declare class StaticValue<P, T extends GroqType> {
1031
+ data: P;
1032
+ type: T;
1033
+ constructor(data: P, type: T);
1034
+ isArray(): boolean;
1035
+ get(): Promise<any>;
1036
+ [Symbol.asyncIterator](): Generator<Value, void, unknown>;
1037
+ }
1038
+ declare class StreamValue {
1039
+ type: 'stream';
1040
+ private generator;
1041
+ private ticker;
1042
+ private isDone;
1043
+ private data;
1044
+ constructor(generator: () => AsyncGenerator<Value, void, unknown>);
1045
+ isArray(): boolean;
1046
+ get(): Promise<any>;
1047
+ [Symbol.asyncIterator](): AsyncGenerator<Value, void, unknown>;
1048
+ _nextTick(): Promise<void>;
1049
+ }
1826
1050
 
1827
- declare type PathValue = StaticValue<Path, 'path'>
1051
+ /** Describes a type node for string values, optionally including a value. If a value is provided it will always be the given string value. */
1828
1052
 
1829
- /** @beta */
1830
- export declare interface PermissionDeniedReason {
1831
- type: 'precondition' | 'access'
1832
- message: string
1833
- documentId?: string
1834
- }
1053
+ declare type StringValue = StaticValue<string, 'string'>;
1835
1054
 
1836
- /**
1837
- * @public
1838
- */
1839
- export declare interface PerspectiveHandle {
1840
- perspective?: ClientPerspective | ReleasePerspective
1841
- }
1055
+ /** Any sort of node which appears as syntax */
1842
1056
 
1843
- declare interface PipeFuncCallNode extends BaseNode {
1844
- type: 'PipeFuncCall'
1845
- func: GroqPipeFunction
1846
- base: ExprNode
1847
- name: string
1848
- args: ExprNode[]
1057
+ declare interface ThisNode extends BaseNode {
1058
+ type: 'This';
1849
1059
  }
1850
-
1851
- declare interface PosNode extends BaseNode {
1852
- type: 'Pos'
1853
- base: ExprNode
1060
+ declare interface TupleNode extends BaseNode {
1061
+ type: 'Tuple';
1062
+ members: Array<ExprNode>;
1854
1063
  }
1855
1064
 
1856
- /**
1857
- * Represents a media asset in a preview.
1858
- *
1859
- * @public
1860
- */
1861
- declare interface PreviewMedia {
1862
- type: 'image-asset'
1863
- _ref: string
1864
- url: string
1865
- }
1065
+ /** Defines a type declaration with a specific name and a value that describes the structure of the type using a TypeNode. */
1866
1066
 
1867
1067
  /**
1868
- * @public
1068
+ * The result of an expression.
1869
1069
  */
1870
- export declare interface PreviewStoreState {
1871
- values: {
1872
- [TDocumentId in string]?: ValuePending<PreviewValue>
1873
- }
1874
- subscriptions: {
1875
- [TDocumentId in string]?: {
1876
- [TSubscriptionId in string]?: true
1877
- }
1878
- }
1070
+ declare type Value = AnyStaticValue | StreamValue;
1071
+ declare interface ValueNode<P = any> {
1072
+ type: 'Value';
1073
+ value: P;
1879
1074
  }
1880
-
1881
1075
  /**
1882
- * Represents the set of values displayed as a preview for a given Sanity document.
1883
- * This includes a primary title, a secondary subtitle, an optional piece of media associated
1884
- * with the document, and the document's status.
1076
+ * Represents a reactive state source that provides synchronized access to store data
1077
+ *
1078
+ * @remarks
1079
+ * Designed to work with React's useSyncExternalStore hook. Provides three ways to access data:
1080
+ * 1. `getCurrent()` for synchronous current value access
1081
+ * 2. `subscribe()` for imperative change notifications
1082
+ * 3. `observable` for reactive stream access
1885
1083
  *
1886
1084
  * @public
1887
1085
  */
1888
- export declare interface PreviewValue {
1086
+ interface StateSource<T> {
1889
1087
  /**
1890
- * The primary text displayed for the document preview.
1891
- */
1892
- title: string
1893
- /**
1894
- * A secondary line of text providing additional context about the document.
1088
+ * Subscribes to state changes with optional callback
1089
+ * @param onStoreChanged - Called whenever relevant state changes occur
1090
+ * @returns Unsubscribe function to clean up the subscription
1895
1091
  */
1896
- subtitle?: string
1092
+ subscribe: (onStoreChanged?: () => void) => () => void;
1897
1093
  /**
1898
- * An optional piece of media representing the document within its preview.
1899
- * Currently, only image assets are available.
1094
+ * Gets the current derived state value
1095
+ *
1096
+ * @remarks
1097
+ * Safe to call without subscription. Will always return the latest value
1098
+ * based on the current store state and selector parameters.
1900
1099
  */
1901
- media?: PreviewMedia | null
1100
+ getCurrent: () => T;
1902
1101
  /**
1903
- * The status of the document.
1904
- */
1905
- _status?: {
1906
- /** The date of the last published edit */
1907
- lastEditedPublishedAt?: string
1908
- /** The date of the last draft edit */
1909
- lastEditedDraftAt?: string
1910
- }
1102
+ * Observable stream of state values
1103
+ *
1104
+ * @remarks
1105
+ * Shares a single underlying subscription between all observers. Emits:
1106
+ * - Immediately with current value on subscription
1107
+ * - On every relevant state change
1108
+ * - Errors if selector throws
1109
+ */
1110
+ observable: Observable<T>;
1911
1111
  }
1912
-
1913
1112
  /**
1914
- * Represents the minimal configuration required to identify a Sanity project.
1915
- * @public
1113
+ * Context passed to selectors when deriving state
1114
+ *
1115
+ * @remarks
1116
+ * Provides access to both the current state value and the Sanity instance,
1117
+ * allowing selectors to use configuration values when computing derived state.
1118
+ * The context is memoized for each state object and instance combination
1119
+ * to optimize performance and prevent unnecessary recalculations.
1120
+ *
1121
+ * @example
1122
+ * ```ts
1123
+ * // Using both state and instance in a selector (psuedo example)
1124
+ * const getUserByProjectId = createStateSourceAction(
1125
+ * ({ state, instance }: SelectorContext<UsersState>, options?: ProjectHandle) => {
1126
+ * const allUsers = state.users
1127
+ * const projectId = options?.projectId ?? instance.config.projectId
1128
+ * return allUsers.filter(user => user.projectId === projectId)
1129
+ * }
1130
+ * )
1131
+ * ```
1916
1132
  */
1917
- export declare interface ProjectHandle<TProjectId extends string = string> {
1918
- projectId?: TProjectId
1919
- }
1920
-
1921
- declare interface ProjectionNode extends BaseNode {
1922
- type: 'Projection'
1923
- base: ExprNode
1924
- expr: ExprNode
1925
- }
1926
-
1927
- declare interface ProjectionOptions<
1928
- TProjection extends ValidProjection = ValidProjection,
1929
- TDocumentType extends string = string,
1930
- TDataset extends string = string,
1931
- TProjectId extends string = string,
1932
- > extends DocumentHandle<TDocumentType, TDataset, TProjectId> {
1933
- projection: TProjection
1133
+ interface SelectorContext<TState> {
1134
+ /**
1135
+ * The current state object from the store
1136
+ */
1137
+ state: TState;
1138
+ /**
1139
+ * The Sanity instance associated with this state
1140
+ */
1141
+ instance: SanityInstance;
1934
1142
  }
1935
-
1936
1143
  /**
1144
+ * Function type for selecting derived state from store state and parameters
1937
1145
  * @public
1938
- * The result of a projection query
1939
- */
1940
- export declare interface ProjectionValuePending<TValue extends object> {
1941
- data: TValue | null
1942
- isPending: boolean
1943
- }
1944
-
1945
- /**
1946
- * Creates a `PublishDocumentAction` object.
1947
- * @param doc - A handle uniquely identifying the document to be published.
1948
- * @returns A `PublishDocumentAction` object ready for dispatch.
1949
- * @beta
1950
- */
1951
- export declare function publishDocument<
1952
- TDocumentType extends string = string,
1953
- TDataset extends string = string,
1954
- TProjectId extends string = string,
1955
- >(
1956
- doc: DocumentHandle<TDocumentType, TDataset, TProjectId>,
1957
- ): PublishDocumentAction<TDocumentType, TDataset, TProjectId>
1958
-
1959
- /**
1960
- * Represents an action to publish the draft version of a document.
1961
- * Requires the full document handle.
1962
- * @beta
1963
- */
1964
- export declare interface PublishDocumentAction<
1965
- TDocumentType extends string = string,
1966
- TDataset extends string = string,
1967
- TProjectId extends string = string,
1968
- > extends DocumentHandle<TDocumentType, TDataset, TProjectId> {
1969
- type: 'document.publish'
1970
- }
1971
-
1972
- /**
1973
- * @beta
1974
1146
  */
1975
- export declare interface QueryOptions<
1976
- TQuery extends string = string,
1977
- TDataset extends string = string,
1978
- TProjectId extends string = string,
1979
- > extends Pick<ResponseQueryOptions, 'useCdn' | 'cache' | 'next' | 'cacheMode' | 'tag'>,
1980
- DatasetHandle<TDataset, TProjectId> {
1981
- query: TQuery
1982
- params?: Record<string, unknown>
1983
- }
1984
-
1147
+ type Selector<TState, TParams extends unknown[], TReturn> = (context: SelectorContext<TState>, ...params: TParams) => TReturn;
1148
+ /**
1149
+ * Configuration options for creating a state source action
1150
+ */
1151
+ type ActionMap = {
1152
+ create: 'sanity.action.document.version.create';
1153
+ discard: 'sanity.action.document.version.discard';
1154
+ unpublish: 'sanity.action.document.unpublish';
1155
+ delete: 'sanity.action.document.delete';
1156
+ edit: 'sanity.action.document.edit';
1157
+ publish: 'sanity.action.document.publish';
1158
+ };
1159
+ type OptimisticLock = {
1160
+ ifDraftRevisionId?: string;
1161
+ ifPublishedRevisionId?: string;
1162
+ };
1163
+ type HttpAction = {
1164
+ actionType: ActionMap['create'];
1165
+ publishedId: string;
1166
+ attributes: SanityDocumentLike;
1167
+ } | {
1168
+ actionType: ActionMap['discard'];
1169
+ versionId: string;
1170
+ purge?: boolean;
1171
+ } | {
1172
+ actionType: ActionMap['unpublish'];
1173
+ draftId: string;
1174
+ publishedId: string;
1175
+ } | {
1176
+ actionType: ActionMap['delete'];
1177
+ publishedId: string;
1178
+ includeDrafts?: string[];
1179
+ } | {
1180
+ actionType: ActionMap['edit'];
1181
+ draftId: string;
1182
+ publishedId: string;
1183
+ patch: PatchOperations;
1184
+ } | ({
1185
+ actionType: ActionMap['publish'];
1186
+ draftId: string;
1187
+ publishedId: string;
1188
+ } & OptimisticLock);
1985
1189
  /**
1986
1190
  * Represents a transaction that is queued to be applied but has not yet been
1987
1191
  * applied. A transaction will remain in a queued state until all required
1988
1192
  * documents for the transactions are available locally.
1989
1193
  */
1990
- declare interface QueuedTransaction {
1194
+ interface QueuedTransaction {
1991
1195
  /**
1992
1196
  * the ID of this transaction. this is generated client-side.
1993
1197
  */
1994
- transactionId: string
1198
+ transactionId: string;
1995
1199
  /**
1996
1200
  * the high-level actions associated with this transaction. note that these
1997
1201
  * actions don't mention draft IDs and is meant to abstract away the draft
1998
1202
  * model from users.
1999
1203
  */
2000
- actions: DocumentAction[]
1204
+ actions: DocumentAction[];
2001
1205
  /**
2002
1206
  * An optional flag set to disable this transaction from being batched with
2003
1207
  * other transactions.
2004
1208
  */
2005
- disableBatching?: boolean
1209
+ disableBatching?: boolean;
2006
1210
  }
2007
-
2008
1211
  /**
2009
- * Signals to the store that the consumer has stopped using the channel
2010
- * @public
1212
+ * Represents a transaction that has been applied locally but has not been
1213
+ * committed/transitioned-to-outgoing. These transactions are visible to the
1214
+ * user but may be rebased upon a new working document set. Applied transactions
1215
+ * also contain the resulting `outgoingActions` that will be submitted to
1216
+ * Content Lake. These `outgoingActions` depend on the state of the working
1217
+ * documents so they are recomputed on rebase and are only relevant to applied
1218
+ * actions (we cannot compute `outgoingActions` for queued transactions because
1219
+ * we haven't resolved the set of documents the actions are dependent on yet).
1220
+ *
1221
+ * In order to support better conflict resolution, the original `previous` set
1222
+ * is saved as the `base` set.
2011
1223
  */
2012
- export declare const releaseChannel: BoundStoreAction_2<
2013
- ComlinkControllerState,
2014
- [name: string],
2015
- void
2016
- >
2017
-
1224
+ interface AppliedTransaction extends QueuedTransaction {
1225
+ /**
1226
+ * the resulting set of documents after the actions have been applied
1227
+ */
1228
+ working: DocumentSet;
1229
+ /**
1230
+ * the previous set of documents before the action was applied
1231
+ */
1232
+ previous: DocumentSet;
1233
+ /**
1234
+ * the original `previous` document set captured when this action was
1235
+ * originally applied. this is used as a reference point to do a 3-way merge
1236
+ * if this applied transaction ever needs to be reapplied on a different
1237
+ * set of documents.
1238
+ */
1239
+ base: DocumentSet;
1240
+ /**
1241
+ * the `_rev`s from `previous` document set
1242
+ */
1243
+ previousRevs: { [TDocumentId in string]?: string };
1244
+ /**
1245
+ * a timestamp for when this transaction was applied locally
1246
+ */
1247
+ timestamp: string;
1248
+ /**
1249
+ * the resulting HTTP actions derived from the state of the `working` document
1250
+ * set. these are sent to Content Lake as-is when this transaction is batched
1251
+ * and transitioned into an outgoing transaction.
1252
+ */
1253
+ outgoingActions: HttpAction[];
1254
+ /**
1255
+ * similar to `outgoingActions` but comprised of mutations instead of action.
1256
+ * this left here for debugging purposes but could be used to send mutations
1257
+ * to Content Lake instead of actions.
1258
+ */
1259
+ outgoingMutations: Mutation[];
1260
+ }
2018
1261
  /**
2019
- * Represents a document in a Sanity dataset that represents release options.
2020
- * @internal
1262
+ * Represents a set of applied transactions batched into a single outgoing
1263
+ * transaction. An outgoing transaction is the result of batching many applied
1264
+ * actions. An outgoing transaction may be reverted locally if the server
1265
+ * does not accept it.
2021
1266
  */
2022
- export declare type ReleaseDocument = SanityDocument & {
2023
- name: string
2024
- publishAt?: string
2025
- state: 'active' | 'scheduled'
2026
- metadata: {
2027
- title: string
2028
- releaseType: 'asap' | 'scheduled' | 'undecided'
2029
- intendedPublishAt?: string
2030
- description?: string
2031
- }
1267
+ interface OutgoingTransaction extends AppliedTransaction {
1268
+ disableBatching: boolean;
1269
+ batchedTransactionIds: string[];
2032
1270
  }
2033
-
1271
+ interface UnverifiedDocumentRevision {
1272
+ transactionId: string;
1273
+ documentId: string;
1274
+ previousRev: string | undefined;
1275
+ timestamp: string;
1276
+ }
1277
+ type Grant = 'read' | 'update' | 'create' | 'history';
1278
+ /** @beta */
1279
+ interface PermissionDeniedReason {
1280
+ type: 'precondition' | 'access';
1281
+ message: string;
1282
+ documentId?: string;
1283
+ }
1284
+ /** @beta */
1285
+ type DocumentPermissionsResult = {
1286
+ allowed: false;
1287
+ message: string;
1288
+ reasons: PermissionDeniedReason[];
1289
+ } | {
1290
+ allowed: true;
1291
+ message?: undefined;
1292
+ reasons?: undefined;
1293
+ };
1294
+ /** @beta */
1295
+ type DocumentEvent = ActionErrorEvent | TransactionRevertedEvent | TransactionAcceptedEvent | DocumentRebaseErrorEvent | DocumentEditedEvent | DocumentCreatedEvent | DocumentDeletedEvent | DocumentPublishedEvent | DocumentUnpublishedEvent | DocumentDiscardedEvent;
2034
1296
  /**
2035
- * Signals to the store that the consumer has stopped using the node
2036
- * @public
1297
+ * @beta
1298
+ * Event emitted when a precondition to applying an action fails.
1299
+ * (For example: when trying to edit a document that no longer exists.)
2037
1300
  */
2038
- export declare const releaseNode: BoundStoreAction_2<ComlinkNodeState, [name: string], void>
2039
-
1301
+ interface ActionErrorEvent {
1302
+ type: 'error';
1303
+ documentId: string;
1304
+ transactionId: string;
1305
+ message: string;
1306
+ error: unknown;
1307
+ }
2040
1308
  /**
2041
- * @public
1309
+ * @beta
1310
+ * Event emitted when a transaction is accepted.
2042
1311
  */
2043
- export declare type ReleasePerspective = {
2044
- releaseName: string
2045
- excludedPerspectives?: StackablePerspective[]
1312
+ interface TransactionAcceptedEvent {
1313
+ type: 'accepted';
1314
+ outgoing: OutgoingTransaction;
1315
+ result: Awaited<ReturnType<SanityClient['action']>>;
2046
1316
  }
2047
-
2048
- declare interface ReleasesStoreState {
2049
- activeReleases?: ReleaseDocument[]
2050
- error?: unknown
1317
+ /**
1318
+ * @beta
1319
+ * Event emitted when a transaction is reverted.
1320
+ */
1321
+ interface TransactionRevertedEvent {
1322
+ type: 'reverted';
1323
+ message: string;
1324
+ error: unknown;
1325
+ outgoing: OutgoingTransaction;
2051
1326
  }
2052
-
2053
1327
  /**
2054
- * Message from SDK (iframe) to Parent (dashboard) to request a new token
2055
- * @internal
1328
+ * @beta
1329
+ * Event emitted when an attempt to apply local changes to a modified remote document fails.
2056
1330
  */
2057
- export declare type RequestNewTokenMessage = {
2058
- type: 'dashboard/v1/auth/tokens/create'
2059
- payload?: undefined
1331
+ interface DocumentRebaseErrorEvent {
1332
+ type: 'rebase-error';
1333
+ documentId: string;
1334
+ transactionId: string;
1335
+ message: string;
1336
+ error: unknown;
2060
1337
  }
2061
-
2062
- /** @public */
2063
- export declare const resolveDatasets: BoundStoreAction<
2064
- FetcherStoreState_2<[options?: ProjectHandle<string> | undefined], DatasetsResponse>,
2065
- [options?: ProjectHandle<string> | undefined],
2066
- Promise<DatasetsResponse>
2067
- >
2068
-
2069
- /** @beta */
2070
- export declare function resolveDocument<
2071
- TDocumentType extends string = string,
2072
- TDataset extends string = string,
2073
- TProjectId extends string = string,
2074
- >(
2075
- instance: SanityInstance,
2076
- docHandle: DocumentHandle<TDocumentType, TDataset, TProjectId>,
2077
- ): Promise<SanityDocument_2<TDocumentType, `${TProjectId}.${TDataset}`> | null>
2078
-
2079
- /** @beta */
2080
- export declare function resolveDocument<TData extends SanityDocument_2>(
2081
- instance: SanityInstance,
2082
- docHandle: DocumentHandle<string, string, string>,
2083
- ): Promise<TData | null>
2084
-
2085
1338
  /**
2086
- * Resolves the favorite status for a document.
2087
- * @param instance - The Sanity instance.
2088
- * @param context - The document context including ID, type, and resource information.
2089
- * @returns A Promise resolving to `{ isFavorited: boolean }`.
2090
- * @public
1339
+ * @beta
1340
+ * Event emitted when a document is edited.
2091
1341
  */
2092
- export declare const resolveFavoritesState: BoundStoreAction<
2093
- FetcherStoreState_2<[FavoriteDocumentContext], FavoriteStatusResponse>,
2094
- [FavoriteDocumentContext],
2095
- Promise<FavoriteStatusResponse>
2096
- >
2097
-
2098
- /** @beta */
2099
- export declare const resolvePermissions: BoundStoreAction<
2100
- DocumentStoreState,
2101
- [actions: DocumentAction | DocumentAction[]],
2102
- Promise<DocumentPermissionsResult_2>
2103
- >
2104
-
1342
+ interface DocumentEditedEvent {
1343
+ type: 'edited';
1344
+ documentId: string;
1345
+ outgoing: OutgoingTransaction;
1346
+ }
2105
1347
  /**
2106
1348
  * @beta
1349
+ * Event emitted when a document is created.
2107
1350
  */
2108
- export declare const resolvePreview: BoundStoreAction<
2109
- PreviewStoreState_2,
2110
- [docHandle: ResolvePreviewOptions],
2111
- Promise<ValuePending_2<object>>
2112
- >
2113
-
1351
+ interface DocumentCreatedEvent {
1352
+ type: 'created';
1353
+ documentId: string;
1354
+ outgoing: OutgoingTransaction;
1355
+ }
2114
1356
  /**
2115
1357
  * @beta
1358
+ * Event emitted when a document is deleted.
2116
1359
  */
2117
- export declare type ResolvePreviewOptions = DocumentHandle
2118
-
2119
- /** @public */
2120
- export declare const resolveProject: BoundStoreAction<
2121
- FetcherStoreState_2<[options?: ProjectHandle<string> | undefined], SanityProject_2>,
2122
- [options?: ProjectHandle<string> | undefined],
2123
- Promise<SanityProject_2>
2124
- >
2125
-
2126
- /** @beta */
2127
- export declare function resolveProjection<
2128
- TProjection extends ValidProjection = ValidProjection,
2129
- TDocumentType extends string = string,
2130
- TDataset extends string = string,
2131
- TProjectId extends string = string,
2132
- >(
2133
- instance: SanityInstance,
2134
- options: ProjectionOptions<TProjection, TDocumentType, TDataset, TProjectId>,
2135
- ): Promise<
2136
- ProjectionValuePending<
2137
- SanityProjectionResult<TProjection, TDocumentType, `${TProjectId}.${TDataset}`>
2138
- >
2139
- >
2140
-
2141
- /** @beta */
2142
- export declare function resolveProjection<TData extends object>(
2143
- instance: SanityInstance,
2144
- options: ProjectionOptions,
2145
- ): Promise<ProjectionValuePending<TData>>
2146
-
2147
- /** @public */
2148
- export declare const resolveProjects: BoundStoreAction<
2149
- FetcherStoreState_2<[], Omit<SanityProject_2, 'members'>[]>,
2150
- [],
2151
- Promise<Omit<SanityProject_2, 'members'>[]>
2152
- >
2153
-
1360
+ interface DocumentDeletedEvent {
1361
+ type: 'deleted';
1362
+ documentId: string;
1363
+ outgoing: OutgoingTransaction;
1364
+ }
2154
1365
  /**
2155
- * Resolves the result of a query without registering a lasting subscriber.
2156
- *
2157
- * This function fetches the result of a GROQ query and returns a promise that resolves with the query result.
2158
- * Unlike `getQueryState`, which registers subscribers to keep the query live and performs automatic cleanup,
2159
- * `resolveQuery` does not track subscribers. This makes it ideal for use with React Suspense, where the returned
2160
- * promise is thrown to delay rendering until the query result becomes available.
2161
- * Once the promise resolves, it is expected that a real subscriber will be added via `getQueryState` to manage ongoing updates.
2162
- *
2163
- * Additionally, an optional AbortSignal can be provided to cancel the query and immediately clear the associated state
2164
- * if there are no active subscribers.
2165
- *
2166
1366
  * @beta
1367
+ * Event emitted when a document is published.
2167
1368
  */
2168
- export declare function resolveQuery<
2169
- TQuery extends string = string,
2170
- TDataset extends string = string,
2171
- TProjectId extends string = string,
2172
- >(
2173
- instance: SanityInstance,
2174
- queryOptions: ResolveQueryOptions<TQuery, TDataset, TProjectId>,
2175
- ): Promise<SanityQueryResult<TQuery, `${TProjectId}.${TDataset}`>>
2176
-
2177
- /** @beta */
2178
- export declare function resolveQuery<TData>(
2179
- instance: SanityInstance,
2180
- queryOptions: ResolveQueryOptions,
2181
- ): Promise<TData>
2182
-
1369
+ interface DocumentPublishedEvent {
1370
+ type: 'published';
1371
+ documentId: string;
1372
+ outgoing: OutgoingTransaction;
1373
+ }
2183
1374
  /**
2184
1375
  * @beta
1376
+ * Event emitted when a document is unpublished.
2185
1377
  */
2186
- declare interface ResolveQueryOptions<
2187
- TQuery extends string = string,
2188
- TDataset extends string = string,
2189
- TProjectId extends string = string,
2190
- > extends QueryOptions<TQuery, TDataset, TProjectId> {
2191
- signal?: AbortSignal
1378
+ interface DocumentUnpublishedEvent {
1379
+ type: 'unpublished';
1380
+ documentId: string;
1381
+ outgoing: OutgoingTransaction;
2192
1382
  }
2193
-
2194
1383
  /**
2195
- * Resolves the users for a specific resource without registering a lasting subscriber.
1384
+ * @beta
1385
+ * Event emitted when a document version is discarded.
1386
+ */
1387
+ interface DocumentDiscardedEvent {
1388
+ type: 'discarded';
1389
+ documentId: string;
1390
+ outgoing: OutgoingTransaction;
1391
+ }
1392
+ /**
1393
+ * Split the entire path string on dots "outside" of any brackets.
2196
1394
  *
2197
- * This function fetches the users for a given resource and returns a promise that resolves with
2198
- * the users result. Unlike `getUsersState`, which registers subscribers to keep the data live and
2199
- * performs automatic cleanup, `resolveUsers` does not track subscribers. This makes it ideal for
2200
- * use with React Suspense, where the returned promise is thrown to delay rendering until the users
2201
- * result becomes available. Once the promise resolves, it is expected that a real subscriber will
2202
- * be added via `getUsersState` to manage ongoing updates.
1395
+ * For example:
1396
+ * ```
1397
+ * "friends[0].name"
1398
+ * ```
2203
1399
  *
2204
- * Additionally, an optional AbortSignal can be provided to cancel the request and immediately
2205
- * clear the associated state if there are no active subscribers.
1400
+ * becomes:
2206
1401
  *
2207
- * @beta
1402
+ * ```
1403
+ * [...ParseSegment<"friends[0]">, ...ParseSegment<"name">]
1404
+ * ```
1405
+ *
1406
+ * (We use a simple recursion that splits on the first dot.)
2208
1407
  */
2209
- export declare const resolveUsers: BoundStoreAction<
2210
- UsersStoreState,
2211
- [ResolveUsersOptions],
2212
- Promise<{
2213
- data: SanityUser_2[]
2214
- totalCount: number
2215
- hasMore: boolean
2216
- }>
2217
- >
2218
-
1408
+ type PathParts<TPath extends string> = TPath extends `${infer Head}.${infer Tail}` ? [Head, ...PathParts<Tail>] : TPath extends '' ? [] : [TPath];
2219
1409
  /**
2220
- * @public
1410
+ * Given a type T and an array of "access keys" Parts, recursively index into T.
1411
+ *
1412
+ * If a part is a key, it looks up that property.
1413
+ * If T is an array and the part is a number, it "indexes" into the element type.
2221
1414
  */
2222
- export declare interface ResolveUsersOptions extends GetUsersOptions {
2223
- signal?: AbortSignal
2224
- }
2225
-
2226
- export {Role}
2227
-
1415
+ type DeepGet<TValue, TPath extends readonly (string | number)[]> = TPath extends [] ? TValue : TPath extends readonly [infer THead, ...infer TTail] ? DeepGet<TValue extends undefined | null ? undefined : THead extends keyof TValue ? TValue[THead] : THead extends number ? TValue extends readonly (infer TElement)[] ? TElement | undefined : undefined : undefined,
1416
+ // Key/index doesn't exist
1417
+ TTail extends readonly (string | number)[] ? TTail : []> : never;
2228
1418
  /**
2229
- * Represents the complete configuration for a Sanity SDK instance
2230
- * @public
1419
+ * Given a document type TDocument and a JSON Match path string TPath,
1420
+ * compute the type found at that path.
1421
+ * @beta
2231
1422
  */
2232
- export declare interface SanityConfig extends DatasetHandle, PerspectiveHandle {
1423
+ type JsonMatch<TDocument, TPath extends string> = DeepGet<TDocument, PathParts<TPath>>;
1424
+ /**
1425
+ * Recursively traverse a value. When an array is encountered, ensure that
1426
+ * each object item has a _key property. Memoized such that sub-objects that
1427
+ * have not changed aren't re-computed.
1428
+ */
1429
+ interface SharedListener {
1430
+ events: Observable<ListenEvent<SanityDocument$1>>;
1431
+ dispose: () => void;
1432
+ }
1433
+ interface DocumentStoreState {
1434
+ documentStates: { [TDocumentId in string]?: DocumentState };
1435
+ queued: QueuedTransaction[];
1436
+ applied: AppliedTransaction[];
1437
+ outgoing?: OutgoingTransaction;
1438
+ grants?: Record<Grant, ExprNode>;
1439
+ error?: unknown;
1440
+ sharedListener: SharedListener;
1441
+ fetchDocument: (documentId: string) => Observable<SanityDocument$3 | null>;
1442
+ events: Subject<DocumentEvent>;
1443
+ }
1444
+ interface DocumentState {
1445
+ id: string;
2233
1446
  /**
2234
- * Authentication configuration for the instance
2235
- * @remarks Merged with parent configurations when using createChild
1447
+ * the "remote" local copy that matches the server. represents the last known
1448
+ * server state. this gets updated every time we confirm remote patches
2236
1449
  */
2237
- auth?: AuthConfig
1450
+ remote?: SanityDocument$3 | null;
2238
1451
  /**
2239
- * Studio mode configuration for use of the SDK in a Sanity Studio
2240
- * @remarks Controls whether studio mode features are enabled
1452
+ * the current ephemeral working copy that includes local optimistic changes
1453
+ * that have not yet been confirmed by the server
2241
1454
  */
2242
- studioMode?: {
2243
- enabled: boolean
2244
- }
2245
- }
2246
-
2247
- export {SanityDocument}
2248
-
2249
- /**
2250
- * Represents a Sanity.io resource instance with its own configuration and lifecycle
2251
- * @remarks Instances form a hierarchy through parent/child relationships
2252
- *
2253
- * @public
2254
- */
2255
- export declare interface SanityInstance {
1455
+ local?: SanityDocument$3 | null;
2256
1456
  /**
2257
- * Unique identifier for this instance
2258
- * @remarks Generated using crypto.randomUUID()
1457
+ * the revision that our remote document is at
2259
1458
  */
2260
- readonly instanceId: string
1459
+ remoteRev?: string | null;
2261
1460
  /**
2262
- * Resolved configuration for this instance
2263
- * @remarks Merges values from parent instances where appropriate
2264
- */
2265
- readonly config: SanityConfig
2266
- /**
2267
- * Checks if the instance has been disposed
2268
- * @returns true if dispose() has been called
2269
- */
2270
- isDisposed(): boolean
2271
- /**
2272
- * Disposes the instance and cleans up associated resources
2273
- * @remarks Triggers all registered onDispose callbacks
2274
- */
2275
- dispose(): void
2276
- /**
2277
- * Registers a callback to be invoked when the instance is disposed
2278
- * @param cb - Callback to execute on disposal
2279
- * @returns Function to unsubscribe the callback
2280
- */
2281
- onDispose(cb: () => void): () => void
2282
- /**
2283
- * Gets the parent instance in the hierarchy
2284
- * @returns Parent instance or undefined if this is the root
2285
- */
2286
- getParent(): SanityInstance | undefined
2287
- /**
2288
- * Creates a child instance with merged configuration
2289
- * @param config - Configuration to merge with parent values
2290
- * @remarks Child instances inherit parent configuration but can override values
1461
+ * Array of subscription IDs. This document state will be deleted if there are
1462
+ * no subscribers.
2291
1463
  */
2292
- createChild(config: SanityConfig): SanityInstance
1464
+ subscriptions: string[];
2293
1465
  /**
2294
- * Traverses the instance hierarchy to find the first instance whose configuration
2295
- * matches the given target config using a shallow comparison.
2296
- * @param targetConfig - A partial configuration object containing key-value pairs to match.
2297
- * @returns The first matching instance or undefined if no match is found.
1466
+ * An object keyed by transaction ID of revisions sent out but that have not
1467
+ * yet been verified yet. When an applied transaction is transitioned to an
1468
+ * outgoing transaction, it also adds unverified revisions for each document
1469
+ * that is part of that outgoing transaction. Transactions are submitted to
1470
+ * the server with a locally generated transaction ID. This way we can observe
1471
+ * when our transaction comes back through the shared listener. Each listener
1472
+ * event that comes back contains a `previousRev`. If we see our own
1473
+ * transaction with a different `previousRev` than expected, we can rebase our
1474
+ * local transactions on top of this new remote.
2298
1475
  */
2299
- match(targetConfig: Partial<SanityConfig>): SanityInstance | undefined
1476
+ unverifiedRevisions?: { [TTransactionId in string]?: UnverifiedDocumentRevision };
2300
1477
  }
2301
-
2302
1478
  /**
2303
- * @public
1479
+ * @beta
1480
+ * Options for specifying a document and optionally a path within it.
2304
1481
  */
2305
- export declare type SanityProject = SanityProject_2
2306
-
1482
+ interface DocumentOptions<TPath extends string | undefined = undefined, TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string> extends DocumentHandle<TDocumentType, TDataset, TProjectId> {
1483
+ path?: TPath;
1484
+ }
1485
+ /** @beta */
1486
+ declare function getDocumentState<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(instance: SanityInstance, options: DocumentOptions<undefined, TDocumentType, TDataset, TProjectId>): StateSource<SanityDocument$3<TDocumentType, `${TProjectId}.${TDataset}`> | undefined | null>;
1487
+ /** @beta */
1488
+ declare function getDocumentState<TPath extends string = string, TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(instance: SanityInstance, options: DocumentOptions<TPath, TDocumentType, TDataset, TProjectId>): StateSource<JsonMatch<SanityDocument$3<TDocumentType, `${TProjectId}.${TDataset}`>, TPath> | undefined>;
1489
+ /** @beta */
1490
+ declare function getDocumentState<TData>(instance: SanityInstance, options: DocumentOptions<string | undefined>): StateSource<TData | undefined | null>;
1491
+ /** @beta */
1492
+ declare function resolveDocument<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(instance: SanityInstance, docHandle: DocumentHandle<TDocumentType, TDataset, TProjectId>): Promise<SanityDocument$3<TDocumentType, `${TProjectId}.${TDataset}`> | null>;
1493
+ /** @beta */
1494
+ declare function resolveDocument<TData extends SanityDocument$3>(instance: SanityInstance, docHandle: DocumentHandle<string, string, string>): Promise<TData | null>;
1495
+ /** @beta */
1496
+ declare const getDocumentSyncStatus: BoundStoreAction<DocumentStoreState, [doc: DocumentHandle<string, string, string>], StateSource<boolean | undefined>>;
1497
+ /** @beta */
1498
+ declare const getPermissionsState: BoundStoreAction<DocumentStoreState, [DocumentAction | DocumentAction[]], StateSource<DocumentPermissionsResult | undefined>>;
1499
+ /** @beta */
1500
+ declare const resolvePermissions: BoundStoreAction<DocumentStoreState, [actions: DocumentAction | DocumentAction[]], Promise<DocumentPermissionsResult>>;
1501
+ /** @beta */
1502
+ declare const subscribeDocumentEvents: BoundStoreAction<DocumentStoreState, [eventHandler: (e: DocumentEvent) => void], () => void>;
2307
1503
  /**
2308
1504
  * @public
2309
1505
  */
2310
- export declare interface SanityUser {
2311
- sanityUserId: string
2312
- profile: UserProfile
2313
- memberships: Membership[]
2314
- }
2315
-
2316
- declare class Scope {
2317
- params: Record<string, unknown>
2318
- source: Value
2319
- value: Value
2320
- parent: Scope | null
2321
- context: Context
2322
- isHidden: boolean
2323
- constructor(
2324
- params: Record<string, unknown>,
2325
- source: Value,
2326
- value: Value,
2327
- context: Context,
2328
- parent: Scope | null,
2329
- )
2330
- createNested(value: Value): Scope
2331
- createHidden(value: Value): Scope
2332
- }
2333
-
2334
- declare interface SelectAlternativeNode extends BaseNode {
2335
- type: 'SelectAlternative'
2336
- condition: ExprNode
2337
- value: ExprNode
1506
+ interface FavoriteStatusResponse {
1507
+ isFavorited: boolean;
2338
1508
  }
2339
-
2340
- declare interface SelectNode extends BaseNode {
2341
- type: 'Select'
2342
- alternatives: SelectAlternativeNode[]
2343
- fallback?: ExprNode
1509
+ /**
1510
+ * @public
1511
+ */
1512
+ interface FavoriteDocumentContext extends DocumentHandle {
1513
+ resourceId: string;
1514
+ resourceType: StudioResource['type'] | MediaResource['type'] | CanvasResource['type'];
1515
+ schemaName?: string;
2344
1516
  }
2345
-
2346
1517
  /**
2347
- * Function type for selecting derived state from store state and parameters
1518
+ * Gets a StateSource for the favorite status of a document.
1519
+ * @param instance - The Sanity instance.
1520
+ * @param context - The document context including ID, type, and resource information.
1521
+ * @returns A StateSource emitting `{ isFavorited: boolean }`.
2348
1522
  * @public
2349
1523
  */
2350
- export declare type Selector<TState, TParams extends unknown[], TReturn> = (
2351
- context: SelectorContext<TState>,
2352
- ...params: TParams
2353
- ) => TReturn
2354
-
1524
+ declare const getFavoritesState: BoundStoreAction<FetcherStoreState<[FavoriteDocumentContext], FavoriteStatusResponse>, [FavoriteDocumentContext], StateSource<FavoriteStatusResponse | undefined>>;
2355
1525
  /**
2356
- * Context passed to selectors when deriving state
2357
- *
2358
- * @remarks
2359
- * Provides access to both the current state value and the Sanity instance,
2360
- * allowing selectors to use configuration values when computing derived state.
2361
- * The context is memoized for each state object and instance combination
2362
- * to optimize performance and prevent unnecessary recalculations.
2363
- *
2364
- * @example
2365
- * ```ts
2366
- * // Using both state and instance in a selector (psuedo example)
2367
- * const getUserByProjectId = createStateSourceAction(
2368
- * ({ state, instance }: SelectorContext<UsersState>, options?: ProjectHandle) => {
2369
- * const allUsers = state.users
2370
- * const projectId = options?.projectId ?? instance.config.projectId
2371
- * return allUsers.filter(user => user.projectId === projectId)
2372
- * }
2373
- * )
2374
- * ```
1526
+ * Resolves the favorite status for a document.
1527
+ * @param instance - The Sanity instance.
1528
+ * @param context - The document context including ID, type, and resource information.
1529
+ * @returns A Promise resolving to `{ isFavorited: boolean }`.
1530
+ * @public
2375
1531
  */
2376
- declare interface SelectorContext<TState> {
2377
- /**
2378
- * The current state object from the store
2379
- */
2380
- state: TState
2381
- /**
2382
- * The Sanity instance associated with this state
2383
- */
2384
- instance: SanityInstance
2385
- }
2386
-
2387
- declare interface SelectorNode extends BaseNode {
2388
- type: 'Selector'
2389
- }
2390
-
1532
+ declare const resolveFavoritesState: BoundStoreAction<FetcherStoreState<[FavoriteDocumentContext], FavoriteStatusResponse>, [FavoriteDocumentContext], Promise<FavoriteStatusResponse>>;
2391
1533
  /**
2392
- * Action to explicitly set the authentication token.
2393
- * Used internally by the Comlink token refresh.
2394
- * @internal
1534
+ * Represents a media asset in a preview.
1535
+ *
1536
+ * @public
2395
1537
  */
2396
- export declare const setAuthToken: BoundStoreAction<AuthStoreState, [token: string | null], void>
2397
-
2398
- declare interface SharedListener {
2399
- events: Observable<ListenEvent<SanityDocument_3>>
2400
- dispose: () => void
1538
+ interface PreviewMedia {
1539
+ type: 'image-asset';
1540
+ _ref: string;
1541
+ url: string;
2401
1542
  }
2402
-
2403
- declare interface SliceNode extends BaseNode {
2404
- type: 'Slice'
2405
- base: ExprNode
2406
- left: number
2407
- right: number
2408
- isInclusive: boolean
2409
- }
2410
-
2411
- export {slicePath}
2412
-
2413
1543
  /**
2414
- * Represents a reactive state source that provides synchronized access to store data
2415
- *
2416
- * @remarks
2417
- * Designed to work with React's useSyncExternalStore hook. Provides three ways to access data:
2418
- * 1. `getCurrent()` for synchronous current value access
2419
- * 2. `subscribe()` for imperative change notifications
2420
- * 3. `observable` for reactive stream access
1544
+ * Represents the set of values displayed as a preview for a given Sanity document.
1545
+ * This includes a primary title, a secondary subtitle, an optional piece of media associated
1546
+ * with the document, and the document's status.
2421
1547
  *
2422
1548
  * @public
2423
1549
  */
2424
- export declare interface StateSource<T> {
1550
+ interface PreviewValue {
2425
1551
  /**
2426
- * Subscribes to state changes with optional callback
2427
- * @param onStoreChanged - Called whenever relevant state changes occur
2428
- * @returns Unsubscribe function to clean up the subscription
1552
+ * The primary text displayed for the document preview.
2429
1553
  */
2430
- subscribe: (onStoreChanged?: () => void) => () => void
1554
+ title: string;
2431
1555
  /**
2432
- * Gets the current derived state value
2433
- *
2434
- * @remarks
2435
- * Safe to call without subscription. Will always return the latest value
2436
- * based on the current store state and selector parameters.
1556
+ * A secondary line of text providing additional context about the document.
2437
1557
  */
2438
- getCurrent: () => T
1558
+ subtitle?: string;
2439
1559
  /**
2440
- * Observable stream of state values
2441
- *
2442
- * @remarks
2443
- * Shares a single underlying subscription between all observers. Emits:
2444
- * - Immediately with current value on subscription
2445
- * - On every relevant state change
2446
- * - Errors if selector throws
1560
+ * An optional piece of media representing the document within its preview.
1561
+ * Currently, only image assets are available.
1562
+ */
1563
+ media?: PreviewMedia | null;
1564
+ /**
1565
+ * The status of the document.
2447
1566
  */
2448
- observable: Observable<T>
1567
+ _status?: {
1568
+ /** The date of the last published edit */
1569
+ lastEditedPublishedAt?: string;
1570
+ /** The date of the last draft edit */
1571
+ lastEditedDraftAt?: string;
1572
+ };
2449
1573
  }
2450
-
2451
- declare class StaticValue<P, T extends GroqType> {
2452
- data: P
2453
- type: T
2454
- constructor(data: P, type: T)
2455
- isArray(): boolean
2456
- get(): Promise<any>
2457
- [Symbol.asyncIterator](): Generator<Value, void, unknown>
1574
+ /**
1575
+ * Represents the current state of a preview value along with a flag indicating whether
1576
+ * the preview data is still being fetched or is fully resolved.
1577
+ *
1578
+ * The tuple contains a preview value or null, and a boolean indicating if the data is
1579
+ * pending. A `true` value means a fetch is ongoing; `false` indicates that the
1580
+ * currently provided preview value is up-to-date.
1581
+ *
1582
+ * @public
1583
+ */
1584
+ type ValuePending<T> = {
1585
+ data: T | null;
1586
+ isPending: boolean;
1587
+ };
1588
+ /**
1589
+ * @public
1590
+ */
1591
+ interface PreviewStoreState {
1592
+ values: { [TDocumentId in string]?: ValuePending<PreviewValue> };
1593
+ subscriptions: { [TDocumentId in string]?: { [TSubscriptionId in string]?: true } };
2458
1594
  }
2459
-
2460
- declare interface StoreEntry<TParams extends unknown[], TData> {
2461
- params: TParams
2462
- instance: SanityInstance
2463
- key: string
2464
- data?: TData
2465
- error?: unknown
2466
- subscriptions: string[]
2467
- lastFetchInitiatedAt?: string
1595
+ /**
1596
+ * @beta
1597
+ */
1598
+ type GetPreviewStateOptions = DocumentHandle;
1599
+ /**
1600
+ * @beta
1601
+ */
1602
+ declare function getPreviewState<TResult extends object>(instance: SanityInstance, options: GetPreviewStateOptions): StateSource<ValuePending<TResult>>;
1603
+ /**
1604
+ * @beta
1605
+ */
1606
+ declare function getPreviewState(instance: SanityInstance, options: GetPreviewStateOptions): StateSource<ValuePending<PreviewValue>>;
1607
+ /**
1608
+ * @beta
1609
+ */
1610
+ /**
1611
+ * @beta
1612
+ */
1613
+ type ResolvePreviewOptions = DocumentHandle;
1614
+ /**
1615
+ * @beta
1616
+ */
1617
+ declare const resolvePreview: BoundStoreAction<PreviewStoreState, [docHandle: ResolvePreviewOptions], Promise<ValuePending<object>>>;
1618
+ /** @public */
1619
+ declare const getProjectState: BoundStoreAction<FetcherStoreState<[options?: ProjectHandle<string> | undefined], _sanity_client12.SanityProject>, [options?: ProjectHandle<string> | undefined], StateSource<_sanity_client12.SanityProject | undefined>>;
1620
+ /** @public */
1621
+ declare const resolveProject: BoundStoreAction<FetcherStoreState<[options?: ProjectHandle<string> | undefined], _sanity_client12.SanityProject>, [options?: ProjectHandle<string> | undefined], Promise<_sanity_client12.SanityProject>>;
1622
+ /**
1623
+ * @public
1624
+ */
1625
+ type ValidProjection = `{${string}}`;
1626
+ /**
1627
+ * @public
1628
+ * The result of a projection query
1629
+ */
1630
+ interface ProjectionValuePending<TValue extends object> {
1631
+ data: TValue | null;
1632
+ isPending: boolean;
2468
1633
  }
2469
-
2470
- declare class StreamValue {
2471
- type: 'stream'
2472
- private generator
2473
- private ticker
2474
- private isDone
2475
- private data
2476
- constructor(generator: () => AsyncGenerator<Value, void, unknown>)
2477
- isArray(): boolean
2478
- get(): Promise<any>
2479
- [Symbol.asyncIterator](): AsyncGenerator<Value, void, unknown>
2480
- _nextTick(): Promise<void>
1634
+ interface ProjectionOptions<TProjection extends ValidProjection = ValidProjection, TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string> extends DocumentHandle<TDocumentType, TDataset, TProjectId> {
1635
+ projection: TProjection;
2481
1636
  }
2482
-
2483
- export {stringifyPath}
2484
-
2485
- declare type StringValue = StaticValue<string, 'string'>
2486
-
1637
+ /**
1638
+ * @beta
1639
+ */
1640
+ declare function getProjectionState<TProjection extends ValidProjection = ValidProjection, TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(instance: SanityInstance, options: ProjectionOptions<TProjection, TDocumentType, TDataset, TProjectId>): StateSource<ProjectionValuePending<SanityProjectionResult<TProjection, TDocumentType, `${TProjectId}.${TDataset}`>> | undefined>;
1641
+ /**
1642
+ * @beta
1643
+ */
1644
+ declare function getProjectionState<TData extends object>(instance: SanityInstance, options: ProjectionOptions): StateSource<ProjectionValuePending<TData> | undefined>;
1645
+ /**
1646
+ * @beta
1647
+ */
1648
+ declare function getProjectionState(instance: SanityInstance, options: ProjectionOptions): StateSource<ProjectionValuePending<Record<string, unknown>> | undefined>;
1649
+ /**
1650
+ * @beta
1651
+ */
2487
1652
  /** @beta */
2488
- export declare const subscribeDocumentEvents: BoundStoreAction<
2489
- DocumentStoreState,
2490
- [eventHandler: (e: DocumentEvent) => void],
2491
- () => void
2492
- >
2493
-
2494
- declare interface ThisNode extends BaseNode {
2495
- type: 'This'
2496
- }
2497
-
1653
+ declare function resolveProjection<TProjection extends ValidProjection = ValidProjection, TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(instance: SanityInstance, options: ProjectionOptions<TProjection, TDocumentType, TDataset, TProjectId>): Promise<ProjectionValuePending<SanityProjectionResult<TProjection, TDocumentType, `${TProjectId}.${TDataset}`>>>;
1654
+ /** @beta */
1655
+ declare function resolveProjection<TData extends object>(instance: SanityInstance, options: ProjectionOptions): Promise<ProjectionValuePending<TData>>;
1656
+ /** @public */
1657
+ declare const getProjectsState: BoundStoreAction<FetcherStoreState<[], Omit<_sanity_client12.SanityProject, "members">[]>, [], StateSource<Omit<_sanity_client12.SanityProject, "members">[] | undefined>>;
1658
+ /** @public */
1659
+ declare const resolveProjects: BoundStoreAction<FetcherStoreState<[], Omit<_sanity_client12.SanityProject, "members">[]>, [], Promise<Omit<_sanity_client12.SanityProject, "members">[]>>;
2498
1660
  /**
2499
1661
  * @beta
2500
- * Event emitted when a transaction is accepted.
2501
1662
  */
2502
- export declare interface TransactionAcceptedEvent {
2503
- type: 'accepted'
2504
- outgoing: OutgoingTransaction
2505
- result: Awaited<ReturnType<SanityClient['action']>>
1663
+ 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> {
1664
+ query: TQuery;
1665
+ params?: Record<string, unknown>;
2506
1666
  }
2507
-
2508
1667
  /**
2509
1668
  * @beta
2510
- * Event emitted when a transaction is reverted.
2511
1669
  */
2512
- export declare interface TransactionRevertedEvent {
2513
- type: 'reverted'
2514
- message: string
2515
- error: unknown
2516
- outgoing: OutgoingTransaction
2517
- }
2518
-
2519
- declare interface TupleNode extends BaseNode {
2520
- type: 'Tuple'
2521
- members: Array<ExprNode>
1670
+ interface ResolveQueryOptions<TQuery extends string = string, TDataset extends string = string, TProjectId extends string = string> extends QueryOptions<TQuery, TDataset, TProjectId> {
1671
+ signal?: AbortSignal;
2522
1672
  }
2523
-
1673
+ /** @beta */
1674
+ declare const getQueryKey: (options: QueryOptions) => string;
1675
+ /** @beta */
1676
+ declare const parseQueryKey: (key: string) => QueryOptions;
2524
1677
  /**
2525
- * Creates an `UnpublishDocumentAction` object.
2526
- * @param doc - A handle uniquely identifying the document to be unpublished.
2527
- * @returns An `UnpublishDocumentAction` object ready for dispatch.
1678
+ * Returns the state source for a query.
1679
+ *
1680
+ * This function returns a state source that represents the current result of a GROQ query.
1681
+ * Subscribing to the state source will instruct the SDK to fetch the query (if not already fetched)
1682
+ * and will keep the query live using the Live content API (considering sync tags) to provide up-to-date results.
1683
+ * When the last subscriber is removed, the query state is automatically cleaned up from the store.
1684
+ *
1685
+ * Note: This functionality is for advanced users who want to build their own framework integrations.
1686
+ * Our SDK also provides a React integration (useQuery hook) for convenient usage.
1687
+ *
1688
+ * Note: Automatic cleanup can interfere with React Suspense because if a component suspends while being the only subscriber,
1689
+ * cleanup might occur unexpectedly. In such cases, consider using `resolveQuery` instead.
1690
+ *
2528
1691
  * @beta
2529
1692
  */
2530
- export declare function unpublishDocument<
2531
- TDocumentType extends string = string,
2532
- TDataset extends string = string,
2533
- TProjectId extends string = string,
2534
- >(
2535
- doc: DocumentHandle<TDocumentType, TDataset, TProjectId>,
2536
- ): UnpublishDocumentAction<TDocumentType, TDataset, TProjectId>
2537
-
1693
+ 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>;
1694
+ /** @beta */
1695
+ declare function getQueryState<TData>(instance: SanityInstance, queryOptions: QueryOptions): StateSource<TData | undefined>;
1696
+ /** @beta */
1697
+ declare function getQueryState(instance: SanityInstance, queryOptions: QueryOptions): StateSource<unknown>;
2538
1698
  /**
2539
- * Represents an action to unpublish a document, moving its published content to a draft.
2540
- * Requires the full document handle.
1699
+ * Resolves the result of a query without registering a lasting subscriber.
1700
+ *
1701
+ * This function fetches the result of a GROQ query and returns a promise that resolves with the query result.
1702
+ * Unlike `getQueryState`, which registers subscribers to keep the query live and performs automatic cleanup,
1703
+ * `resolveQuery` does not track subscribers. This makes it ideal for use with React Suspense, where the returned
1704
+ * promise is thrown to delay rendering until the query result becomes available.
1705
+ * Once the promise resolves, it is expected that a real subscriber will be added via `getQueryState` to manage ongoing updates.
1706
+ *
1707
+ * Additionally, an optional AbortSignal can be provided to cancel the query and immediately clear the associated state
1708
+ * if there are no active subscribers.
1709
+ *
2541
1710
  * @beta
2542
1711
  */
2543
- export declare interface UnpublishDocumentAction<
2544
- TDocumentType extends string = string,
2545
- TDataset extends string = string,
2546
- TProjectId extends string = string,
2547
- > extends DocumentHandle<TDocumentType, TDataset, TProjectId> {
2548
- type: 'document.unpublish'
1712
+ 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}`>>;
1713
+ /** @beta */
1714
+ declare function resolveQuery<TData>(instance: SanityInstance, queryOptions: ResolveQueryOptions): Promise<TData>;
1715
+ /**
1716
+ * Represents a document in a Sanity dataset that represents release options.
1717
+ * @internal
1718
+ */
1719
+ type ReleaseDocument = SanityDocument$2 & {
1720
+ name: string;
1721
+ publishAt?: string;
1722
+ state: 'active' | 'scheduled';
1723
+ metadata: {
1724
+ title: string;
1725
+ releaseType: 'asap' | 'scheduled' | 'undecided';
1726
+ intendedPublishAt?: string;
1727
+ description?: string;
1728
+ };
1729
+ };
1730
+ interface ReleasesStoreState {
1731
+ activeReleases?: ReleaseDocument[];
1732
+ error?: unknown;
2549
1733
  }
2550
-
2551
- declare interface UnverifiedDocumentRevision {
2552
- transactionId: string
2553
- documentId: string
2554
- previousRev: string | undefined
2555
- timestamp: string
1734
+ /**
1735
+ * Get the active releases from the store.
1736
+ * @internal
1737
+ */
1738
+ declare const getActiveReleasesState: BoundStoreAction<ReleasesStoreState, [], StateSource<ReleaseDocument[] | undefined>>;
1739
+ /**
1740
+ * Provides a subscribable state source for a "perspective" for the Sanity client,
1741
+ * which is used to fetch documents as though certain Content Releases are active.
1742
+ *
1743
+ * @param instance - The Sanity instance to get the perspective for
1744
+ * @param options - The options for the perspective -- usually a release name
1745
+ *
1746
+ * @returns A subscribable perspective value, usually a list of applicable release names,
1747
+ * or a single release name / default perspective (such as 'drafts').
1748
+ *
1749
+ * @public
1750
+ */
1751
+ declare const getPerspectiveState: BoundStoreAction<ReleasesStoreState, [options?: PerspectiveHandle | undefined], StateSource<string[] | "previewDrafts" | "published" | "drafts" | "raw" | undefined>>;
1752
+ /**
1753
+ * @public
1754
+ */
1755
+ interface SanityUser {
1756
+ sanityUserId: string;
1757
+ profile: UserProfile;
1758
+ memberships: Membership[];
2556
1759
  }
2557
-
2558
1760
  /**
2559
1761
  * @public
2560
1762
  */
2561
- export declare interface UserProfile {
2562
- id: string
2563
- displayName: string
2564
- email: string
2565
- familyName?: string
2566
- givenName?: string
2567
- middleName?: string | null
2568
- imageUrl?: string
2569
- provider: string
2570
- tosAcceptedAt?: string
2571
- createdAt: string
2572
- updatedAt?: string
2573
- isCurrentUser?: boolean
2574
- providerId?: string
1763
+ interface Membership {
1764
+ addedAt?: string;
1765
+ resourceType: string;
1766
+ resourceId: string;
1767
+ roleNames: Array<string>;
1768
+ lastSeenAt?: string | null;
2575
1769
  }
2576
-
2577
1770
  /**
2578
1771
  * @public
2579
1772
  */
2580
- declare interface UsersGroupState {
2581
- subscriptions: string[]
2582
- totalCount?: number
2583
- nextCursor?: string | null
2584
- lastLoadMoreRequest?: string
2585
- users?: SanityUser[]
2586
- error?: unknown
1773
+ interface UserProfile {
1774
+ id: string;
1775
+ displayName: string;
1776
+ email: string;
1777
+ familyName?: string;
1778
+ givenName?: string;
1779
+ middleName?: string | null;
1780
+ imageUrl?: string;
1781
+ provider: string;
1782
+ tosAcceptedAt?: string;
1783
+ createdAt: string;
1784
+ updatedAt?: string;
1785
+ isCurrentUser?: boolean;
1786
+ providerId?: string;
2587
1787
  }
2588
-
2589
1788
  /**
2590
1789
  * @public
2591
1790
  */
2592
- declare interface UsersStoreState {
2593
- users: {
2594
- [TUsersKey in string]?: UsersGroupState
2595
- }
2596
- error?: unknown
1791
+ interface GetUsersOptions extends ProjectHandle {
1792
+ resourceType?: 'organization' | 'project';
1793
+ batchSize?: number;
1794
+ organizationId?: string;
2597
1795
  }
2598
-
2599
1796
  /**
2600
1797
  * @public
2601
1798
  */
2602
- export declare type ValidProjection = `{${string}}`
2603
-
1799
+ interface UsersGroupState {
1800
+ subscriptions: string[];
1801
+ totalCount?: number;
1802
+ nextCursor?: string | null;
1803
+ lastLoadMoreRequest?: string;
1804
+ users?: SanityUser[];
1805
+ error?: unknown;
1806
+ }
2604
1807
  /**
2605
- * The result of an expression.
1808
+ * @public
2606
1809
  */
2607
- declare type Value = AnyStaticValue | StreamValue
2608
1810
 
2609
- declare interface ValueNode<P = any> {
2610
- type: 'Value'
2611
- value: P
1811
+ /**
1812
+ * @public
1813
+ */
1814
+ interface UsersStoreState {
1815
+ users: { [TUsersKey in string]?: UsersGroupState };
1816
+ error?: unknown;
2612
1817
  }
2613
-
2614
1818
  /**
2615
- * Represents the current state of a preview value along with a flag indicating whether
2616
- * the preview data is still being fetched or is fully resolved.
1819
+ * @public
1820
+ */
1821
+ interface ResolveUsersOptions extends GetUsersOptions {
1822
+ signal?: AbortSignal;
1823
+ }
1824
+ /** @internal */
1825
+ declare const getUsersKey: (instance: SanityInstance, {
1826
+ resourceType,
1827
+ organizationId,
1828
+ batchSize,
1829
+ projectId
1830
+ }?: GetUsersOptions) => string;
1831
+ /** @internal */
1832
+ declare const parseUsersKey: (key: string) => {
1833
+ batchSize: number;
1834
+ resourceType?: "organization" | "project";
1835
+ projectId?: string;
1836
+ organizationId?: string;
1837
+ };
1838
+ /**
1839
+ * Returns the state source for users associated with a specific resource.
2617
1840
  *
2618
- * The tuple contains a preview value or null, and a boolean indicating if the data is
2619
- * pending. A `true` value means a fetch is ongoing; `false` indicates that the
2620
- * currently provided preview value is up-to-date.
1841
+ * This function returns a state source that represents the current list of users for a given
1842
+ * resource. Subscribing to the state source will instruct the SDK to fetch the users (if not
1843
+ * already fetched) and will load more from this state source as well. When the last subscriber is
1844
+ * removed, the users state is automatically cleaned up from the store after a delay.
1845
+ *
1846
+ * Note: This functionality is for advanced users who want to build their own framework
1847
+ * integrations. Our SDK also provides a React integration for convenient usage.
1848
+ *
1849
+ * @beta
1850
+ */
1851
+ declare const getUsersState: BoundStoreAction<UsersStoreState, [options?: GetUsersOptions], StateSource<{
1852
+ data: SanityUser[];
1853
+ totalCount: number;
1854
+ hasMore: boolean;
1855
+ } | undefined>>;
1856
+ /**
1857
+ * Resolves the users for a specific resource without registering a lasting subscriber.
1858
+ *
1859
+ * This function fetches the users for a given resource and returns a promise that resolves with
1860
+ * the users result. Unlike `getUsersState`, which registers subscribers to keep the data live and
1861
+ * performs automatic cleanup, `resolveUsers` does not track subscribers. This makes it ideal for
1862
+ * use with React Suspense, where the returned promise is thrown to delay rendering until the users
1863
+ * result becomes available. Once the promise resolves, it is expected that a real subscriber will
1864
+ * be added via `getUsersState` to manage ongoing updates.
1865
+ *
1866
+ * Additionally, an optional AbortSignal can be provided to cancel the request and immediately
1867
+ * clear the associated state if there are no active subscribers.
2621
1868
  *
1869
+ * @beta
1870
+ */
1871
+ declare const resolveUsers: BoundStoreAction<UsersStoreState, [ResolveUsersOptions], Promise<{
1872
+ data: SanityUser[];
1873
+ totalCount: number;
1874
+ hasMore: boolean;
1875
+ }>>;
1876
+ /**
1877
+ * Loads more users for a specific resource.
1878
+ *
1879
+ * This function triggers a request to fetch the next page of users for a given resource. It
1880
+ * requires that users have already been loaded for the resource (via `resolveUsers` or
1881
+ * `getUsersState`), and that there are more users available to load (as indicated by the `hasMore`
1882
+ * property).
1883
+ *
1884
+ * The function returns a promise that resolves when the next page of users has been loaded.
1885
+ *
1886
+ * @beta
1887
+ */
1888
+ declare const loadMoreUsers: BoundStoreAction<UsersStoreState, [options?: GetUsersOptions | undefined], Promise<{
1889
+ data: SanityUser[];
1890
+ totalCount: number;
1891
+ hasMore: boolean;
1892
+ }>>;
1893
+ interface StoreEntry<TParams extends unknown[], TData> {
1894
+ params: TParams;
1895
+ instance: SanityInstance;
1896
+ key: string;
1897
+ data?: TData;
1898
+ error?: unknown;
1899
+ subscriptions: string[];
1900
+ lastFetchInitiatedAt?: string;
1901
+ }
1902
+ /**
1903
+ * Internal helper type
2622
1904
  * @public
2623
1905
  */
2624
- export declare type ValuePending<T> = {
2625
- data: T | null
2626
- isPending: boolean
1906
+ interface FetcherStoreState<TParams extends unknown[], TData> {
1907
+ stateByParams: { [TSerializedKey in string]?: StoreEntry<TParams, TData> };
1908
+ error?: unknown;
2627
1909
  }
2628
-
2629
1910
  /**
2630
- * Message sent from an iframe to a containing app
1911
+ * Internal helper type
2631
1912
  * @public
2632
1913
  */
2633
- export declare type WindowMessage = Message
2634
-
2635
- export {}
1914
+ interface FetcherStore<TParams extends unknown[], TData> {
1915
+ getState: BoundStoreAction<FetcherStoreState<TParams, TData>, TParams, StateSource<TData | undefined>>;
1916
+ resolveState: BoundStoreAction<FetcherStoreState<TParams, TData>, TParams, Promise<TData>>;
1917
+ }
1918
+ /**
1919
+ * Creates a store from a function that returns an observable that fetches data
1920
+ * that supports parameterized state caching.
1921
+ *
1922
+ * This function creates a resource store keyed by parameter values (using the
1923
+ * provided `getKey` function) and returns a state source (via `getState`)
1924
+ * that components can subscribe to. When a new subscription is added, and if
1925
+ * enough time has passed since the last fetch (controlled by
1926
+ * `fetchThrottleInternal`), it invokes the observable factory (via
1927
+ * `getObservable`) to fetch fresh data. The data is stored in state and can be
1928
+ * accessed reactively.
1929
+ *
1930
+ * Additionally, the store provides a `resolveState` function that returns a
1931
+ * Promise resolving with the next non-undefined value from the state source.
1932
+ *
1933
+ * State expiration is implemented: after the last subscription for a key is
1934
+ * removed, its state is cleared after `stateExpirationDelay` ms, causing
1935
+ * components to suspend until fresh data is fetched.
1936
+ */
1937
+ /**
1938
+ * Creates a GROQ search filter string (`[@] match text::query("...")`)
1939
+ * from a raw search query string.
1940
+ *
1941
+ * It applies wildcard ('*') logic to the last eligible token and escapes
1942
+ * double quotes within the search term.
1943
+ *
1944
+ * If the input query is empty or only whitespace, it returns an empty string.
1945
+ *
1946
+ * @param query - The raw input search string.
1947
+ * @returns The GROQ search filter string, or an empty string.
1948
+ * @internal
1949
+ */
1950
+ declare function createGroqSearchFilter(query: string): string;
1951
+ /**
1952
+ * This version is provided by pkg-utils at build time
1953
+ * @internal
1954
+ */
1955
+ declare const CORE_SDK_VERSION: {};
1956
+ /**
1957
+ * @public
1958
+ */
1959
+ type SanityProject = SanityProject$1;
1960
+ export { type ActionErrorEvent, type ActionsResult, type ApplyDocumentActionsOptions, type AuthConfig, type AuthProvider, type AuthState, AuthStateType, type AuthStoreState, CORE_SDK_VERSION, type ClientOptions, type ClientStoreState as ClientState, type ComlinkControllerState, type ComlinkNodeState, type CreateDocumentAction, type CurrentUser, type DatasetHandle, type DeleteDocumentAction, type DiscardDocumentAction, type DocumentAction, type DocumentCreatedEvent, type DocumentDeletedEvent, type DocumentDiscardedEvent, type DocumentEditedEvent, type DocumentEvent, type DocumentHandle, type DocumentOptions, type DocumentPermissionsResult, type DocumentPublishedEvent, type DocumentTypeHandle, type DocumentUnpublishedEvent, type EditDocumentAction, type ErrorAuthState, type FavoriteStatusResponse, type FetcherStore, type FetcherStoreState, type FrameMessage, type GetPreviewStateOptions, type GetUsersOptions, type JsonMatch, type LoggedInAuthState, type LoggedOutAuthState, type LoggingInAuthState, type Membership, type NewTokenResponseMessage, type NodeState, type OrgVerificationResult, type PermissionDeniedReason, type PerspectiveHandle, type PreviewStoreState, type PreviewValue, type ProjectHandle, type ProjectionValuePending, type PublishDocumentAction, type QueryOptions, type ReleaseDocument, type ReleasePerspective, type RequestNewTokenMessage, type ResolvePreviewOptions, type ResolveUsersOptions, type Role, type SanityConfig, type SanityDocument, type SanityInstance, SanityProject, type SanityUser, type Selector, type StateSource, type TransactionAcceptedEvent, type TransactionRevertedEvent, type UnpublishDocumentAction, type UserProfile, type ValidProjection, type ValuePending, type WindowMessage, applyDocumentActions, createDatasetHandle, createDocument, createDocumentHandle, createDocumentTypeHandle, createGroqSearchFilter, createProjectHandle, createSanityInstance, deleteDocument, destroyController, discardDocument, editDocument, getActiveReleasesState, getAuthState, getClient, getClientState, getCurrentUserState, getDashboardOrganizationId, getDatasetsState, getDocumentState, getDocumentSyncStatus, getFavoritesState, getIndexForKey, getIsInDashboardState, getLoginUrlState, getNodeState, getOrCreateChannel, getOrCreateController, getOrCreateNode, getPathDepth, getPermissionsState, getPerspectiveState, getPreviewState, getProjectState, getProjectionState, getProjectsState, getQueryKey, getQueryState, getTokenState, getUsersKey, getUsersState, handleAuthCallback, joinPaths, jsonMatch, loadMoreUsers, logout, observeOrganizationVerificationState, parseQueryKey, parseUsersKey, publishDocument, releaseChannel, releaseNode, resolveDatasets, resolveDocument, resolveFavoritesState, resolvePermissions, resolvePreview, resolveProject, resolveProjection, resolveProjects, resolveQuery, resolveUsers, setAuthToken, slicePath, stringifyPath, subscribeDocumentEvents, unpublishDocument };