@sanity/sdk 2.1.0 → 2.1.1

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