@sanity/sdk 2.3.1 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +173 -105
- package/dist/index.js +354 -122
- package/dist/index.js.map +1 -1
- package/package.json +12 -11
- package/src/_exports/index.ts +30 -0
- package/src/agent/agentActions.test.ts +81 -0
- package/src/agent/agentActions.ts +139 -0
- package/src/auth/authStore.test.ts +13 -13
- package/src/auth/refreshStampedToken.test.ts +16 -16
- package/src/auth/subscribeToStateAndFetchCurrentUser.test.ts +6 -6
- package/src/auth/subscribeToStorageEventsAndSetToken.test.ts +4 -4
- package/src/auth/utils.ts +36 -0
- package/src/client/clientStore.test.ts +151 -0
- package/src/client/clientStore.ts +39 -1
- package/src/comlink/controller/actions/destroyController.test.ts +2 -2
- package/src/comlink/controller/actions/getOrCreateChannel.test.ts +6 -6
- package/src/comlink/controller/actions/getOrCreateController.test.ts +5 -5
- package/src/comlink/controller/actions/getOrCreateController.ts +1 -1
- package/src/comlink/controller/actions/releaseChannel.test.ts +3 -2
- package/src/comlink/controller/comlinkControllerStore.test.ts +4 -4
- package/src/comlink/node/actions/getOrCreateNode.test.ts +7 -7
- package/src/comlink/node/actions/releaseNode.test.ts +2 -2
- package/src/comlink/node/comlinkNodeStore.test.ts +4 -3
- package/src/config/sanityConfig.ts +49 -3
- package/src/document/actions.test.ts +34 -0
- package/src/document/actions.ts +31 -7
- package/src/document/applyDocumentActions.test.ts +9 -6
- package/src/document/applyDocumentActions.ts +9 -49
- package/src/document/documentStore.test.ts +148 -107
- package/src/document/documentStore.ts +40 -10
- package/src/document/permissions.test.ts +9 -9
- package/src/document/permissions.ts +17 -7
- package/src/document/processActions.test.ts +345 -0
- package/src/document/processActions.ts +185 -2
- package/src/document/reducers.ts +13 -6
- package/src/presence/presenceStore.ts +13 -7
- package/src/preview/previewStore.test.ts +10 -2
- package/src/preview/previewStore.ts +2 -1
- package/src/preview/subscribeToStateAndFetchBatches.test.ts +8 -5
- package/src/preview/subscribeToStateAndFetchBatches.ts +9 -3
- package/src/projection/projectionStore.test.ts +18 -2
- package/src/projection/projectionStore.ts +2 -1
- package/src/projection/subscribeToStateAndFetchBatches.test.ts +6 -5
- package/src/projection/subscribeToStateAndFetchBatches.ts +9 -3
- package/src/query/queryStore.ts +7 -4
- package/src/releases/getPerspectiveState.ts +2 -2
- package/src/releases/releasesStore.ts +10 -4
- package/src/store/createActionBinder.test.ts +8 -6
- package/src/store/createActionBinder.ts +50 -14
- package/src/store/createStateSourceAction.test.ts +12 -11
- package/src/store/createStateSourceAction.ts +6 -6
- package/src/store/createStoreInstance.test.ts +29 -16
- package/src/store/createStoreInstance.ts +6 -5
- package/src/store/defineStore.test.ts +1 -1
- package/src/store/defineStore.ts +12 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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";
|
|
2
|
+
import { ClientConfig, ClientError, ClientPerspective, ListenEvent, ResponseQueryOptions, SanityClient, SanityDocument as SanityDocument$1, SanityProject as SanityProject$1, StackablePerspective } from "@sanity/client";
|
|
3
3
|
import { Observable, Subject } from "rxjs";
|
|
4
4
|
import { CurrentUser, CurrentUser as CurrentUser$1, Mutation, PatchOperations, Role, SanityDocument, SanityDocument as SanityDocument$2, SanityDocumentLike } from "@sanity/types";
|
|
5
5
|
import * as _sanity_comlink3 from "@sanity/comlink";
|
|
@@ -9,17 +9,6 @@ import { SanityDocument as SanityDocument$3, SanityProjectionResult, SanityQuery
|
|
|
9
9
|
import { ExprNode } from "groq-js";
|
|
10
10
|
import { CanvasResource, MediaResource, StudioResource } from "@sanity/message-protocol";
|
|
11
11
|
import { getIndexForKey, getPathDepth, joinPaths, jsonMatch, slicePath, stringifyPath } from "@sanity/json-match";
|
|
12
|
-
/**
|
|
13
|
-
* Represents the various states the authentication type can be in.
|
|
14
|
-
*
|
|
15
|
-
* @public
|
|
16
|
-
*/
|
|
17
|
-
declare enum AuthStateType {
|
|
18
|
-
LOGGED_IN = "logged-in",
|
|
19
|
-
LOGGING_IN = "logging-in",
|
|
20
|
-
ERROR = "error",
|
|
21
|
-
LOGGED_OUT = "logged-out",
|
|
22
|
-
}
|
|
23
12
|
/**
|
|
24
13
|
* Configuration for an authentication provider
|
|
25
14
|
* @public
|
|
@@ -116,12 +105,18 @@ interface DatasetHandle<TDataset extends string = string, TProjectId extends str
|
|
|
116
105
|
/**
|
|
117
106
|
* Identifies a specific document type within a Sanity dataset and project.
|
|
118
107
|
* Includes `projectId`, `dataset`, and `documentType`.
|
|
119
|
-
* Optionally includes a `documentId
|
|
108
|
+
* Optionally includes a `documentId` and `liveEdit` flag.
|
|
120
109
|
* @public
|
|
121
110
|
*/
|
|
122
111
|
interface DocumentTypeHandle<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string> extends DatasetHandle<TDataset, TProjectId> {
|
|
123
112
|
documentId?: string;
|
|
124
113
|
documentType: TDocumentType;
|
|
114
|
+
/**
|
|
115
|
+
* Indicates whether this document uses liveEdit mode.
|
|
116
|
+
* When `true`, the document does not use the draft/published model and edits are applied directly to the document.
|
|
117
|
+
* @see https://www.sanity.io/docs/content-lake/drafts#ca0663a8f002
|
|
118
|
+
*/
|
|
119
|
+
liveEdit?: boolean;
|
|
125
120
|
}
|
|
126
121
|
/**
|
|
127
122
|
* Uniquely identifies a specific document within a Sanity dataset and project.
|
|
@@ -150,6 +145,39 @@ interface SanityConfig extends DatasetHandle, PerspectiveHandle {
|
|
|
150
145
|
enabled: boolean;
|
|
151
146
|
};
|
|
152
147
|
}
|
|
148
|
+
declare const SOURCE_ID = "__sanity_internal_sourceId";
|
|
149
|
+
/**
|
|
150
|
+
* A document source can be used for querying.
|
|
151
|
+
*
|
|
152
|
+
* @beta
|
|
153
|
+
* @see datasetSource Construct a document source for a given projectId and dataset.
|
|
154
|
+
* @see mediaLibrarySource Construct a document source for a mediaLibraryId.
|
|
155
|
+
* @see canvasSource Construct a document source for a canvasId.
|
|
156
|
+
*/
|
|
157
|
+
type DocumentSource = {
|
|
158
|
+
[SOURCE_ID]: ['media-library', string] | ['canvas', string] | {
|
|
159
|
+
projectId: string;
|
|
160
|
+
dataset: string;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Returns a document source for a projectId and dataset.
|
|
165
|
+
*
|
|
166
|
+
* @beta
|
|
167
|
+
*/
|
|
168
|
+
declare function datasetSource(projectId: string, dataset: string): DocumentSource;
|
|
169
|
+
/**
|
|
170
|
+
* Returns a document source for a Media Library.
|
|
171
|
+
*
|
|
172
|
+
* @beta
|
|
173
|
+
*/
|
|
174
|
+
declare function mediaLibrarySource(id: string): DocumentSource;
|
|
175
|
+
/**
|
|
176
|
+
* Returns a document source for a Canvas.
|
|
177
|
+
*
|
|
178
|
+
* @beta
|
|
179
|
+
*/
|
|
180
|
+
declare function canvasSource(id: string): DocumentSource;
|
|
153
181
|
/**
|
|
154
182
|
* Represents a Sanity.io resource instance with its own configuration and lifecycle
|
|
155
183
|
* @remarks Instances form a hierarchy through parent/child relationships
|
|
@@ -211,33 +239,81 @@ interface SanityInstance {
|
|
|
211
239
|
* @public
|
|
212
240
|
*/
|
|
213
241
|
declare function createSanityInstance(config?: SanityConfig): SanityInstance;
|
|
242
|
+
/** @alpha */
|
|
243
|
+
type AgentGenerateOptions = Parameters<SanityClient['observable']['agent']['action']['generate']>[0];
|
|
244
|
+
/** @alpha */
|
|
245
|
+
type AgentTransformOptions = Parameters<SanityClient['observable']['agent']['action']['transform']>[0];
|
|
246
|
+
/** @alpha */
|
|
247
|
+
type AgentTranslateOptions = Parameters<SanityClient['observable']['agent']['action']['translate']>[0];
|
|
248
|
+
/** @alpha */
|
|
249
|
+
type AgentPromptOptions = Parameters<SanityClient['agent']['action']['prompt']>[0];
|
|
250
|
+
/** @alpha */
|
|
251
|
+
type AgentPatchOptions = Parameters<SanityClient['agent']['action']['patch']>[0];
|
|
252
|
+
/** @alpha */
|
|
253
|
+
type AgentGenerateResult = Awaited<ReturnType<SanityClient['observable']['agent']['action']['generate']>>;
|
|
254
|
+
/** @alpha */
|
|
255
|
+
type AgentTransformResult = Awaited<ReturnType<SanityClient['observable']['agent']['action']['transform']>>;
|
|
256
|
+
/** @alpha */
|
|
257
|
+
type AgentTranslateResult = Awaited<ReturnType<SanityClient['observable']['agent']['action']['translate']>>;
|
|
258
|
+
/** @alpha */
|
|
259
|
+
type AgentPromptResult = Awaited<ReturnType<SanityClient['agent']['action']['prompt']>>;
|
|
260
|
+
/** @alpha */
|
|
261
|
+
type AgentPatchResult = Awaited<ReturnType<SanityClient['agent']['action']['patch']>>;
|
|
262
|
+
/**
|
|
263
|
+
* Generates a new document using the agent.
|
|
264
|
+
* @param instance - The Sanity instance.
|
|
265
|
+
* @param options - The options for the agent generate action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.
|
|
266
|
+
* @returns An Observable emitting the result of the agent generate action.
|
|
267
|
+
* @alpha
|
|
268
|
+
*/
|
|
269
|
+
declare function agentGenerate(instance: SanityInstance, options: AgentGenerateOptions): AgentGenerateResult;
|
|
214
270
|
/**
|
|
215
|
-
*
|
|
271
|
+
* Transforms a document using the agent.
|
|
272
|
+
* @param instance - The Sanity instance.
|
|
273
|
+
* @param options - The options for the agent transform action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.
|
|
274
|
+
* @returns An Observable emitting the result of the agent transform action.
|
|
275
|
+
* @alpha
|
|
216
276
|
*/
|
|
217
|
-
|
|
277
|
+
declare function agentTransform(instance: SanityInstance, options: AgentTransformOptions): AgentTransformResult;
|
|
218
278
|
/**
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
* @
|
|
223
|
-
* @
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
* @
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
|
|
279
|
+
* Translates a document using the agent.
|
|
280
|
+
* @param instance - The Sanity instance.
|
|
281
|
+
* @param options - The options for the agent translate action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.
|
|
282
|
+
* @returns An Observable emitting the result of the agent translate action.
|
|
283
|
+
* @alpha
|
|
284
|
+
*/
|
|
285
|
+
declare function agentTranslate(instance: SanityInstance, options: AgentTranslateOptions): AgentTranslateResult;
|
|
286
|
+
/**
|
|
287
|
+
* Prompts the agent using the same instruction template format as the other actions, but returns text or json instead of acting on a document.
|
|
288
|
+
* @param instance - The Sanity instance.
|
|
289
|
+
* @param options - The options for the agent prompt action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.
|
|
290
|
+
* @returns An Observable emitting the result of the agent prompt action.
|
|
291
|
+
* @alpha
|
|
292
|
+
*/
|
|
293
|
+
declare function agentPrompt(instance: SanityInstance, options: AgentPromptOptions): Observable<AgentPromptResult>;
|
|
294
|
+
/**
|
|
295
|
+
* Patches a document using the agent.
|
|
296
|
+
* @param instance - The Sanity instance.
|
|
297
|
+
* @param options - The options for the agent patch action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.
|
|
298
|
+
* @returns An Observable emitting the result of the agent patch action.
|
|
299
|
+
* @alpha
|
|
300
|
+
*/
|
|
301
|
+
declare function agentPatch(instance: SanityInstance, options: AgentPatchOptions): Observable<AgentPatchResult>;
|
|
302
|
+
/**
|
|
303
|
+
* Represents the various states the authentication type can be in.
|
|
233
304
|
*
|
|
234
|
-
*
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
305
|
+
* @public
|
|
306
|
+
*/
|
|
307
|
+
declare enum AuthStateType {
|
|
308
|
+
LOGGED_IN = "logged-in",
|
|
309
|
+
LOGGING_IN = "logging-in",
|
|
310
|
+
ERROR = "error",
|
|
311
|
+
LOGGED_OUT = "logged-out",
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Represents a store action that has been bound to a specific store instance
|
|
240
315
|
*/
|
|
316
|
+
type BoundStoreAction<_TState, TParams extends unknown[], TReturn> = (instance: SanityInstance, ...params: TParams) => TReturn;
|
|
241
317
|
/**
|
|
242
318
|
* Represents the various states the authentication can be in.
|
|
243
319
|
*
|
|
@@ -321,10 +397,6 @@ declare const getCurrentUserState: BoundStoreAction<AuthStoreState, [], StateSou
|
|
|
321
397
|
* @public
|
|
322
398
|
*/
|
|
323
399
|
declare const getTokenState: BoundStoreAction<AuthStoreState, [], StateSource<string | null>>;
|
|
324
|
-
/**
|
|
325
|
-
* @internal
|
|
326
|
-
*/
|
|
327
|
-
|
|
328
400
|
/**
|
|
329
401
|
* @public
|
|
330
402
|
*/
|
|
@@ -355,10 +427,6 @@ declare const setAuthToken: BoundStoreAction<AuthStoreState, [token: string | nu
|
|
|
355
427
|
interface OrgVerificationResult {
|
|
356
428
|
error: string | null;
|
|
357
429
|
}
|
|
358
|
-
/**
|
|
359
|
-
* Compares a project's actual organization ID with the expected organization ID.
|
|
360
|
-
* @public
|
|
361
|
-
*/
|
|
362
430
|
/**
|
|
363
431
|
* Creates an observable that emits the organization verification state for a given instance.
|
|
364
432
|
* It combines the dashboard organization ID (from auth context) with the
|
|
@@ -374,6 +442,24 @@ declare const handleAuthCallback: BoundStoreAction<AuthStoreState, [locationHref
|
|
|
374
442
|
* @public
|
|
375
443
|
*/
|
|
376
444
|
declare const logout: BoundStoreAction<AuthStoreState, [], Promise<void>>;
|
|
445
|
+
/** @internal */
|
|
446
|
+
type ApiErrorBody = {
|
|
447
|
+
error?: {
|
|
448
|
+
type?: string;
|
|
449
|
+
description?: string;
|
|
450
|
+
};
|
|
451
|
+
type?: string;
|
|
452
|
+
description?: string;
|
|
453
|
+
message?: string;
|
|
454
|
+
};
|
|
455
|
+
/** @internal Extracts the structured API error body from a ClientError, if present. */
|
|
456
|
+
declare function getClientErrorApiBody(error: ClientError): ApiErrorBody | undefined;
|
|
457
|
+
/** @internal Returns the error type string from an API error body, if available. */
|
|
458
|
+
declare function getClientErrorApiType(error: ClientError): string | undefined;
|
|
459
|
+
/** @internal Returns the error description string from an API error body, if available. */
|
|
460
|
+
declare function getClientErrorApiDescription(error: ClientError): string | undefined;
|
|
461
|
+
/** @internal True if the error represents a projectUserNotFoundError. */
|
|
462
|
+
declare function isProjectUserNotFoundClientError(error: ClientError): boolean;
|
|
377
463
|
type AllowedClientConfigKey = 'useCdn' | 'token' | 'perspective' | 'apiHost' | 'proxy' | 'withCredentials' | 'timeout' | 'maxRetries' | 'dataset' | 'projectId' | 'requestTagPrefix' | 'useProjectHostname';
|
|
378
464
|
/**
|
|
379
465
|
* States tracked by the client store
|
|
@@ -415,6 +501,10 @@ interface ClientOptions extends Pick<ClientConfig, AllowedClientConfigKey> {
|
|
|
415
501
|
* @internal
|
|
416
502
|
*/
|
|
417
503
|
'~experimental_resource'?: ClientConfig['~experimental_resource'];
|
|
504
|
+
/**
|
|
505
|
+
* @internal
|
|
506
|
+
*/
|
|
507
|
+
'source'?: DocumentSource;
|
|
418
508
|
}
|
|
419
509
|
/**
|
|
420
510
|
* Retrieves a Sanity client instance configured with the provided options.
|
|
@@ -596,6 +686,12 @@ declare const resolveDatasets: BoundStoreAction<FetcherStoreState<[options?: Pro
|
|
|
596
686
|
*/
|
|
597
687
|
interface CreateDocumentAction<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string> extends DocumentTypeHandle<TDocumentType, TDataset, TProjectId> {
|
|
598
688
|
type: 'document.create';
|
|
689
|
+
/**
|
|
690
|
+
* Optional initial field values for the document.
|
|
691
|
+
* These values will be set when the document is created.
|
|
692
|
+
* System fields (_id, _type, _rev, _createdAt, _updatedAt) are omitted as they are set automatically.
|
|
693
|
+
*/
|
|
694
|
+
initialValue?: Partial<Omit<SanityDocument$3<TDocumentType, `${TProjectId}.${TDataset}`>, '_id' | '_type' | '_rev' | '_createdAt' | '_updatedAt'>>;
|
|
599
695
|
}
|
|
600
696
|
/**
|
|
601
697
|
* Represents an action to delete an existing document.
|
|
@@ -646,10 +742,11 @@ type DocumentAction<TDocumentType extends string = string, TDataset extends stri
|
|
|
646
742
|
/**
|
|
647
743
|
* Creates a `CreateDocumentAction` object.
|
|
648
744
|
* @param doc - A handle identifying the document type, dataset, and project. An optional `documentId` can be provided.
|
|
745
|
+
* @param initialValue - Optional initial field values for the document. (System fields are omitted as they are set automatically.)
|
|
649
746
|
* @returns A `CreateDocumentAction` object ready for dispatch.
|
|
650
747
|
* @beta
|
|
651
748
|
*/
|
|
652
|
-
declare function createDocument<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(doc: DocumentTypeHandle<TDocumentType, TDataset, TProjectId
|
|
749
|
+
declare function createDocument<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(doc: DocumentTypeHandle<TDocumentType, TDataset, TProjectId>, initialValue?: Partial<Omit<SanityDocument$3<TDocumentType, `${TProjectId}.${TDataset}`>, '_id' | '_type' | '_rev' | '_createdAt' | '_updatedAt'>>): CreateDocumentAction<TDocumentType, TDataset, TProjectId>;
|
|
653
750
|
/**
|
|
654
751
|
* Creates a `DeleteDocumentAction` object.
|
|
655
752
|
* @param doc - A handle uniquely identifying the document to be deleted.
|
|
@@ -704,21 +801,6 @@ declare function discardDocument<TDocumentType extends string = string, TDataset
|
|
|
704
801
|
* Documents that don't exist have a `null` value.
|
|
705
802
|
*/
|
|
706
803
|
type DocumentSet<TDocument extends SanityDocument$2 = SanityDocument$2> = { [TDocumentId in string]?: TDocument | null };
|
|
707
|
-
/**
|
|
708
|
-
* Implements ID generation:
|
|
709
|
-
*
|
|
710
|
-
* A create mutation creates a new document. It takes the literal document
|
|
711
|
-
* content as its argument. The rules for the new document's identifier are as
|
|
712
|
-
* follows:
|
|
713
|
-
*
|
|
714
|
-
* - If the `_id` attribute is missing, then a new, random, unique ID is
|
|
715
|
-
* generated.
|
|
716
|
-
* - If the `_id` attribute is present but ends with `.`, then it is used as a
|
|
717
|
-
* prefix for a new, random, unique ID.
|
|
718
|
-
* - If the _id attribute is present, it is used as-is.
|
|
719
|
-
*
|
|
720
|
-
* [- source](https://www.sanity.io/docs/http-mutations#c732f27330a4)
|
|
721
|
-
*/
|
|
722
804
|
/** @beta */
|
|
723
805
|
interface ActionsResult<TDocument extends SanityDocument$3 = SanityDocument$3> {
|
|
724
806
|
transactionId: string;
|
|
@@ -734,6 +816,10 @@ interface ActionsResult<TDocument extends SanityDocument$3 = SanityDocument$3> {
|
|
|
734
816
|
}
|
|
735
817
|
/** @beta */
|
|
736
818
|
interface ApplyDocumentActionsOptions {
|
|
819
|
+
/**
|
|
820
|
+
* List of actions to apply.
|
|
821
|
+
*/
|
|
822
|
+
actions: DocumentAction[];
|
|
737
823
|
/**
|
|
738
824
|
* Optionally provide an ID to be used as this transaction ID
|
|
739
825
|
*/
|
|
@@ -744,9 +830,9 @@ interface ApplyDocumentActionsOptions {
|
|
|
744
830
|
disableBatching?: boolean;
|
|
745
831
|
}
|
|
746
832
|
/** @beta */
|
|
747
|
-
declare function applyDocumentActions<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(instance: SanityInstance,
|
|
833
|
+
declare function applyDocumentActions<TDocumentType extends string = string, TDataset extends string = string, TProjectId extends string = string>(instance: SanityInstance, options: ApplyDocumentActionsOptions): Promise<ActionsResult<SanityDocument$3<TDocumentType, `${TProjectId}.${TDataset}`>>>;
|
|
748
834
|
/** @beta */
|
|
749
|
-
declare function applyDocumentActions(instance: SanityInstance,
|
|
835
|
+
declare function applyDocumentActions(instance: SanityInstance, options: ApplyDocumentActionsOptions): Promise<ActionsResult>;
|
|
750
836
|
/**
|
|
751
837
|
* Represents a reactive state source that provides synchronized access to store data
|
|
752
838
|
*
|
|
@@ -820,11 +906,9 @@ interface SelectorContext<TState> {
|
|
|
820
906
|
* @public
|
|
821
907
|
*/
|
|
822
908
|
type Selector<TState, TParams extends unknown[], TReturn> = (context: SelectorContext<TState>, ...params: TParams) => TReturn;
|
|
823
|
-
/**
|
|
824
|
-
* Configuration options for creating a state source action
|
|
825
|
-
*/
|
|
826
909
|
type ActionMap = {
|
|
827
910
|
create: 'sanity.action.document.version.create';
|
|
911
|
+
createLiveEdit: 'sanity.action.document.create';
|
|
828
912
|
discard: 'sanity.action.document.version.discard';
|
|
829
913
|
unpublish: 'sanity.action.document.unpublish';
|
|
830
914
|
delete: 'sanity.action.document.delete';
|
|
@@ -839,6 +923,10 @@ type HttpAction = {
|
|
|
839
923
|
actionType: ActionMap['create'];
|
|
840
924
|
publishedId: string;
|
|
841
925
|
attributes: SanityDocumentLike;
|
|
926
|
+
} | {
|
|
927
|
+
actionType: ActionMap['createLiveEdit'];
|
|
928
|
+
publishedId: string;
|
|
929
|
+
attributes: SanityDocumentLike;
|
|
842
930
|
} | {
|
|
843
931
|
actionType: ActionMap['discard'];
|
|
844
932
|
versionId: string;
|
|
@@ -1096,11 +1184,6 @@ TTail extends readonly (string | number)[] ? TTail : []> : never;
|
|
|
1096
1184
|
* @beta
|
|
1097
1185
|
*/
|
|
1098
1186
|
type JsonMatch<TDocument, TPath extends string> = DeepGet<TDocument, PathParts<TPath>>;
|
|
1099
|
-
/**
|
|
1100
|
-
* Recursively traverse a value. When an array is encountered, ensure that
|
|
1101
|
-
* each object item has a _key property. Memoized such that sub-objects that
|
|
1102
|
-
* have not changed aren't re-computed.
|
|
1103
|
-
*/
|
|
1104
1187
|
interface SharedListener {
|
|
1105
1188
|
events: Observable<ListenEvent<SanityDocument$1>>;
|
|
1106
1189
|
dispose: () => void;
|
|
@@ -1169,10 +1252,13 @@ declare function resolveDocument<TDocumentType extends string = string, TDataset
|
|
|
1169
1252
|
declare function resolveDocument<TData extends SanityDocument$3>(instance: SanityInstance, docHandle: DocumentHandle<string, string, string>): Promise<TData | null>;
|
|
1170
1253
|
/** @beta */
|
|
1171
1254
|
declare const getDocumentSyncStatus: BoundStoreAction<DocumentStoreState, [doc: DocumentHandle<string, string, string>], StateSource<boolean | undefined>>;
|
|
1255
|
+
type PermissionsStateOptions = {
|
|
1256
|
+
actions: DocumentAction[];
|
|
1257
|
+
};
|
|
1172
1258
|
/** @beta */
|
|
1173
|
-
declare const getPermissionsState: BoundStoreAction<DocumentStoreState, [
|
|
1259
|
+
declare const getPermissionsState: BoundStoreAction<DocumentStoreState, [PermissionsStateOptions], StateSource<DocumentPermissionsResult | undefined>>;
|
|
1174
1260
|
/** @beta */
|
|
1175
|
-
declare const resolvePermissions: BoundStoreAction<DocumentStoreState, [
|
|
1261
|
+
declare const resolvePermissions: BoundStoreAction<DocumentStoreState, [options: PermissionsStateOptions], Promise<DocumentPermissionsResult>>;
|
|
1176
1262
|
/** @beta */
|
|
1177
1263
|
declare const subscribeDocumentEvents: BoundStoreAction<DocumentStoreState, [eventHandler: (e: DocumentEvent) => void], () => void>;
|
|
1178
1264
|
/**
|
|
@@ -1309,8 +1395,6 @@ interface UserPresence {
|
|
|
1309
1395
|
locations: PresenceLocation[];
|
|
1310
1396
|
sessionId: string;
|
|
1311
1397
|
}
|
|
1312
|
-
/** @public */
|
|
1313
|
-
|
|
1314
1398
|
/** @public */
|
|
1315
1399
|
type TransportEvent = RollCallEvent | StateEvent | DisconnectEvent;
|
|
1316
1400
|
/** @public */
|
|
@@ -1334,7 +1418,6 @@ interface DisconnectEvent {
|
|
|
1334
1418
|
sessionId: string;
|
|
1335
1419
|
timestamp: string;
|
|
1336
1420
|
}
|
|
1337
|
-
/** @public */
|
|
1338
1421
|
type PresenceStoreState = {
|
|
1339
1422
|
locations: Map<string, {
|
|
1340
1423
|
userId: string;
|
|
@@ -1345,7 +1428,10 @@ type PresenceStoreState = {
|
|
|
1345
1428
|
/** @public */
|
|
1346
1429
|
|
|
1347
1430
|
/** @public */
|
|
1348
|
-
declare const getPresence: BoundStoreAction<PresenceStoreState, [
|
|
1431
|
+
declare const getPresence: BoundStoreAction<PresenceStoreState, [((object & {
|
|
1432
|
+
projectId?: string;
|
|
1433
|
+
dataset?: string;
|
|
1434
|
+
}) | undefined)?, ...unknown[]], StateSource<UserPresence[]>>;
|
|
1349
1435
|
/**
|
|
1350
1436
|
* Represents a media asset in a preview.
|
|
1351
1437
|
*
|
|
@@ -1420,9 +1506,6 @@ declare function getPreviewState<TResult extends object>(instance: SanityInstanc
|
|
|
1420
1506
|
* @beta
|
|
1421
1507
|
*/
|
|
1422
1508
|
declare function getPreviewState(instance: SanityInstance, options: GetPreviewStateOptions): StateSource<ValuePending<PreviewValue>>;
|
|
1423
|
-
/**
|
|
1424
|
-
* @beta
|
|
1425
|
-
*/
|
|
1426
1509
|
/**
|
|
1427
1510
|
* @beta
|
|
1428
1511
|
*/
|
|
@@ -1465,9 +1548,6 @@ declare function getProjectionState<TData extends object>(instance: SanityInstan
|
|
|
1465
1548
|
* @beta
|
|
1466
1549
|
*/
|
|
1467
1550
|
declare function getProjectionState(instance: SanityInstance, options: ProjectionOptions): StateSource<ProjectionValuePending<Record<string, unknown>> | undefined>;
|
|
1468
|
-
/**
|
|
1469
|
-
* @beta
|
|
1470
|
-
*/
|
|
1471
1551
|
/** @beta */
|
|
1472
1552
|
declare function resolveProjection<TProjection extends string = string, 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}`>>>;
|
|
1473
1553
|
/** @beta */
|
|
@@ -1494,6 +1574,7 @@ declare const resolveProjects: BoundStoreAction<FetcherStoreState<[options?: {
|
|
|
1494
1574
|
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> {
|
|
1495
1575
|
query: TQuery;
|
|
1496
1576
|
params?: Record<string, unknown>;
|
|
1577
|
+
source?: DocumentSource;
|
|
1497
1578
|
}
|
|
1498
1579
|
/**
|
|
1499
1580
|
* @beta
|
|
@@ -1566,7 +1647,10 @@ interface ReleasesStoreState {
|
|
|
1566
1647
|
* Get the active releases from the store.
|
|
1567
1648
|
* @internal
|
|
1568
1649
|
*/
|
|
1569
|
-
declare const getActiveReleasesState: BoundStoreAction<ReleasesStoreState, [
|
|
1650
|
+
declare const getActiveReleasesState: BoundStoreAction<ReleasesStoreState, [((object & {
|
|
1651
|
+
projectId?: string;
|
|
1652
|
+
dataset?: string;
|
|
1653
|
+
}) | undefined)?, ...unknown[]], StateSource<ReleaseDocument[] | undefined>>;
|
|
1570
1654
|
/**
|
|
1571
1655
|
* Provides a subscribable state source for a "perspective" for the Sanity client,
|
|
1572
1656
|
* which is used to fetch documents as though certain Content Releases are active.
|
|
@@ -1579,7 +1663,10 @@ declare const getActiveReleasesState: BoundStoreAction<ReleasesStoreState, [], S
|
|
|
1579
1663
|
*
|
|
1580
1664
|
* @public
|
|
1581
1665
|
*/
|
|
1582
|
-
declare const getPerspectiveState: BoundStoreAction<ReleasesStoreState, [
|
|
1666
|
+
declare const getPerspectiveState: BoundStoreAction<ReleasesStoreState, [_?: (PerspectiveHandle & {
|
|
1667
|
+
projectId?: string;
|
|
1668
|
+
dataset?: string;
|
|
1669
|
+
}) | undefined], StateSource<string[] | "raw" | "previewDrafts" | "published" | "drafts" | undefined>>;
|
|
1583
1670
|
/** @internal */
|
|
1584
1671
|
declare const getUsersKey: (instance: SanityInstance, {
|
|
1585
1672
|
resourceType,
|
|
@@ -1609,7 +1696,7 @@ declare const parseUsersKey: (key: string) => {
|
|
|
1609
1696
|
*
|
|
1610
1697
|
* @beta
|
|
1611
1698
|
*/
|
|
1612
|
-
declare const getUsersState: BoundStoreAction<UsersStoreState, [options?: GetUsersOptions], StateSource<{
|
|
1699
|
+
declare const getUsersState: BoundStoreAction<UsersStoreState, [options?: GetUsersOptions | undefined], StateSource<{
|
|
1613
1700
|
data: SanityUser[];
|
|
1614
1701
|
totalCount: number;
|
|
1615
1702
|
hasMore: boolean;
|
|
@@ -1658,7 +1745,7 @@ declare const getUserState: BoundStoreAction<UsersStoreState, [GetUserOptions],
|
|
|
1658
1745
|
/**
|
|
1659
1746
|
* @beta
|
|
1660
1747
|
*/
|
|
1661
|
-
declare const resolveUser: BoundStoreAction<UsersStoreState, [ResolveUserOptions], Promise<SanityUser
|
|
1748
|
+
declare const resolveUser: BoundStoreAction<UsersStoreState, [ResolveUserOptions], Promise<SanityUser>>;
|
|
1662
1749
|
interface StoreEntry<TParams extends unknown[], TData> {
|
|
1663
1750
|
params: TParams;
|
|
1664
1751
|
instance: SanityInstance;
|
|
@@ -1684,25 +1771,6 @@ interface FetcherStore<TParams extends unknown[], TData> {
|
|
|
1684
1771
|
getState: BoundStoreAction<FetcherStoreState<TParams, TData>, TParams, StateSource<TData | undefined>>;
|
|
1685
1772
|
resolveState: BoundStoreAction<FetcherStoreState<TParams, TData>, TParams, Promise<TData>>;
|
|
1686
1773
|
}
|
|
1687
|
-
/**
|
|
1688
|
-
* Creates a store from a function that returns an observable that fetches data
|
|
1689
|
-
* that supports parameterized state caching.
|
|
1690
|
-
*
|
|
1691
|
-
* This function creates a resource store keyed by parameter values (using the
|
|
1692
|
-
* provided `getKey` function) and returns a state source (via `getState`)
|
|
1693
|
-
* that components can subscribe to. When a new subscription is added, and if
|
|
1694
|
-
* enough time has passed since the last fetch (controlled by
|
|
1695
|
-
* `fetchThrottleInternal`), it invokes the observable factory (via
|
|
1696
|
-
* `getObservable`) to fetch fresh data. The data is stored in state and can be
|
|
1697
|
-
* accessed reactively.
|
|
1698
|
-
*
|
|
1699
|
-
* Additionally, the store provides a `resolveState` function that returns a
|
|
1700
|
-
* Promise resolving with the next non-undefined value from the state source.
|
|
1701
|
-
*
|
|
1702
|
-
* State expiration is implemented: after the last subscription for a key is
|
|
1703
|
-
* removed, its state is cleared after `stateExpirationDelay` ms, causing
|
|
1704
|
-
* components to suspend until fresh data is fetched.
|
|
1705
|
-
*/
|
|
1706
1774
|
/**
|
|
1707
1775
|
* Creates a GROQ search filter string (`[@] match text::query("...")`)
|
|
1708
1776
|
* from a raw search query string.
|
|
@@ -1870,4 +1938,4 @@ declare const CORE_SDK_VERSION: {};
|
|
|
1870
1938
|
* @public
|
|
1871
1939
|
*/
|
|
1872
1940
|
type SanityProject = SanityProject$1;
|
|
1873
|
-
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, getCorsErrorProjectId, 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 };
|
|
1941
|
+
export { type ActionErrorEvent, type ActionsResult, type AgentGenerateOptions, type AgentGenerateResult, type AgentPatchOptions, type AgentPatchResult, type AgentPromptOptions, type AgentPromptResult, type AgentTransformOptions, type AgentTransformResult, type AgentTranslateOptions, type AgentTranslateResult, type ApiErrorBody, 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 DocumentSource, 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, agentGenerate, agentPatch, agentPrompt, agentTransform, agentTranslate, applyDocumentActions, canvasSource, createDatasetHandle, createDocument, createDocumentHandle, createDocumentTypeHandle, createGroqSearchFilter, createProjectHandle, createSanityInstance, datasetSource, defineIntent, deleteDocument, destroyController, discardDocument, editDocument, getActiveReleasesState, getAuthState, getClient, getClientErrorApiBody, getClientErrorApiDescription, getClientErrorApiType, getClientState, getCorsErrorProjectId, 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, isProjectUserNotFoundClientError, joinPaths, jsonMatch, loadMoreUsers, logout, mediaLibrarySource, observeOrganizationVerificationState, parseQueryKey, parseUsersKey, publishDocument, releaseChannel, releaseNode, resolveDatasets, resolveDocument, resolveFavoritesState, resolvePermissions, resolvePreview, resolveProject, resolveProjection, resolveProjects, resolveQuery, resolveUser, resolveUsers, setAuthToken, slicePath, stringifyPath, subscribeDocumentEvents, unpublishDocument };
|