@sanity/sdk 0.0.0-alpha.8 → 0.0.0-alpha.9
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 +636 -6
- package/dist/index.js +1535 -22
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
- package/src/_exports/index.ts +45 -6
- package/src/document/actions.test.ts +163 -0
- package/src/document/actions.ts +157 -0
- package/src/document/applyActions.test.ts +133 -0
- package/src/document/applyActions.ts +150 -0
- package/src/document/diffPatch.test.ts +335 -0
- package/src/document/diffPatch.ts +288 -0
- package/src/document/documentConstants.ts +9 -0
- package/src/document/documentStore.test.ts +1044 -0
- package/src/document/documentStore.ts +407 -0
- package/src/document/events.test.ts +51 -0
- package/src/document/events.ts +112 -0
- package/src/document/listen.test.ts +208 -0
- package/src/document/listen.ts +257 -0
- package/src/document/patchOperations.test.ts +969 -0
- package/src/document/patchOperations.ts +994 -0
- package/src/document/processActions.test.ts +558 -0
- package/src/document/processActions.ts +379 -0
- package/src/document/processMutations.test.ts +626 -0
- package/src/document/processMutations.ts +269 -0
- package/src/document/reducers.test.ts +676 -0
- package/src/document/reducers.ts +552 -0
- package/src/document/sharedListener.test.ts +233 -0
- package/src/document/sharedListener.ts +68 -0
- package/src/preview/getPreviewState.test.ts +6 -5
- package/src/preview/getPreviewState.ts +3 -2
- package/src/preview/previewQuery.ts +2 -7
- package/src/preview/resolvePreview.test.ts +8 -7
- package/src/preview/util.test.ts +1 -52
- package/src/preview/util.ts +0 -18
- package/src/resources/createAction.test.ts +36 -15
- package/src/resources/createAction.ts +3 -4
- package/src/resources/createResource.ts +8 -2
- package/src/resources/createStateSourceAction.test.ts +29 -2
- package/src/resources/createStateSourceAction.ts +25 -6
- package/src/utils/ids.test.ts +54 -0
- package/src/utils/ids.ts +13 -0
package/dist/index.d.ts
CHANGED
|
@@ -3,14 +3,23 @@ import {ChannelInstance} from '@sanity/comlink'
|
|
|
3
3
|
import {ClientConfig} from '@sanity/client'
|
|
4
4
|
import {Controller} from '@sanity/comlink'
|
|
5
5
|
import {CurrentUser} from '@sanity/types'
|
|
6
|
+
import {IndexTuple} from '@sanity/types'
|
|
7
|
+
import {ListenEvent} from '@sanity/client'
|
|
6
8
|
import {Message} from '@sanity/comlink'
|
|
9
|
+
import {Mutation} from '@sanity/types'
|
|
7
10
|
import {Node as Node_2} from '@sanity/comlink'
|
|
8
11
|
import {NodeInput} from '@sanity/comlink'
|
|
9
12
|
import {Observable} from 'rxjs'
|
|
13
|
+
import {PatchMutation} from '@sanity/mutate/_unstable_store'
|
|
14
|
+
import {PatchOperations} from '@sanity/types'
|
|
15
|
+
import {PathSegment} from '@sanity/types'
|
|
10
16
|
import {Role} from '@sanity/types'
|
|
11
17
|
import {SanityClient} from '@sanity/client'
|
|
18
|
+
import {SanityDocument} from '@sanity/types'
|
|
19
|
+
import {SanityDocumentLike} from '@sanity/types'
|
|
12
20
|
import {SchemaTypeDefinition} from '@sanity/types'
|
|
13
21
|
import {SortOrderingItem} from '@sanity/types'
|
|
22
|
+
import {Subject} from 'rxjs'
|
|
14
23
|
import {Subscribable} from 'rxjs'
|
|
15
24
|
import {SyncTag} from '@sanity/client'
|
|
16
25
|
|
|
@@ -20,6 +29,117 @@ export declare interface ActionContext<TState> {
|
|
|
20
29
|
state: ResourceState<TState>
|
|
21
30
|
}
|
|
22
31
|
|
|
32
|
+
/** @beta */
|
|
33
|
+
export declare interface ActionErrorEvent {
|
|
34
|
+
type: 'error'
|
|
35
|
+
documentId: string
|
|
36
|
+
transactionId: string
|
|
37
|
+
message: string
|
|
38
|
+
error: unknown
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
declare type ActionMap = {
|
|
42
|
+
create: 'sanity.action.document.version.create'
|
|
43
|
+
discard: 'sanity.action.document.version.discard'
|
|
44
|
+
unpublish: 'sanity.action.document.unpublish'
|
|
45
|
+
delete: 'sanity.action.document.delete'
|
|
46
|
+
edit: 'sanity.action.document.edit'
|
|
47
|
+
publish: 'sanity.action.document.publish'
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** @beta */
|
|
51
|
+
export declare interface ActionsResult<TDocument extends SanityDocument = SanityDocument> {
|
|
52
|
+
transactionId: string
|
|
53
|
+
documents: DocumentSet<TDocument>
|
|
54
|
+
previous: DocumentSet<TDocument>
|
|
55
|
+
previousRevs: {
|
|
56
|
+
[documentId: string]: string | undefined
|
|
57
|
+
}
|
|
58
|
+
appeared: string[]
|
|
59
|
+
updated: string[]
|
|
60
|
+
disappeared: string[]
|
|
61
|
+
submitted: () => ReturnType<SanityClient['action']>
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Represents a transaction that has been applied locally but has not been
|
|
66
|
+
* committed/transitioned-to-outgoing. These transactions are visible to the
|
|
67
|
+
* user but may be rebased upon a new working document set. Applied transactions
|
|
68
|
+
* also contain the resulting `outgoingActions` that will be submitted to
|
|
69
|
+
* Content Lake. These `outgoingActions` depend on the state of the working
|
|
70
|
+
* documents so they are recomputed on rebase and are only relevant to applied
|
|
71
|
+
* actions (we cannot compute `outgoingActions` for queued transactions because
|
|
72
|
+
* we haven't resolved the set of documents the actions are dependent on yet).
|
|
73
|
+
*
|
|
74
|
+
* In order to support better conflict resolution, the original `previous` set
|
|
75
|
+
* is saved as the `base` set.
|
|
76
|
+
*/
|
|
77
|
+
declare interface AppliedTransaction extends QueuedTransaction {
|
|
78
|
+
/**
|
|
79
|
+
* the resulting set of documents after the actions have been applied
|
|
80
|
+
*/
|
|
81
|
+
working: DocumentSet
|
|
82
|
+
/**
|
|
83
|
+
* the previous set of documents before the action was applied
|
|
84
|
+
*/
|
|
85
|
+
previous: DocumentSet
|
|
86
|
+
/**
|
|
87
|
+
* the original `previous` document set captured when this action was
|
|
88
|
+
* originally applied. this is used as a reference point to do a 3-way merge
|
|
89
|
+
* if this applied transaction ever needs to be reapplied on a different
|
|
90
|
+
* set of documents.
|
|
91
|
+
*/
|
|
92
|
+
base: DocumentSet
|
|
93
|
+
/**
|
|
94
|
+
* the `_rev`s from `previous` document set
|
|
95
|
+
*/
|
|
96
|
+
previousRevs: {
|
|
97
|
+
[TDocumentId in string]?: string
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* a timestamp for when this transaction was applied locally
|
|
101
|
+
*/
|
|
102
|
+
timestamp: string
|
|
103
|
+
/**
|
|
104
|
+
* the resulting HTTP actions derived from the state of the `working` document
|
|
105
|
+
* set. these are sent to Content Lake as-is when this transaction is batched
|
|
106
|
+
* and transitioned into an outgoing transaction.
|
|
107
|
+
*/
|
|
108
|
+
outgoingActions: HttpAction[]
|
|
109
|
+
/**
|
|
110
|
+
* similar to `outgoingActions` but comprised of mutations instead of action.
|
|
111
|
+
* this left here for debugging purposes but could be used to send mutations
|
|
112
|
+
* to Content Lake instead of actions.
|
|
113
|
+
*/
|
|
114
|
+
outgoingMutations: Mutation[]
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** @beta */
|
|
118
|
+
export declare function applyActions<TDocument extends SanityDocument>(
|
|
119
|
+
instance: SanityInstance | ActionContext<DocumentStoreState>,
|
|
120
|
+
action: DocumentAction<TDocument> | DocumentAction<TDocument>[],
|
|
121
|
+
options?: ApplyActionsOptions,
|
|
122
|
+
): Promise<ActionsResult<TDocument>>
|
|
123
|
+
|
|
124
|
+
/** @beta */
|
|
125
|
+
export declare function applyActions(
|
|
126
|
+
instance: SanityInstance | ActionContext<DocumentStoreState>,
|
|
127
|
+
action: DocumentAction | DocumentAction[],
|
|
128
|
+
options?: ApplyActionsOptions,
|
|
129
|
+
): Promise<ActionsResult>
|
|
130
|
+
|
|
131
|
+
/** @beta */
|
|
132
|
+
export declare interface ApplyActionsOptions {
|
|
133
|
+
/**
|
|
134
|
+
* Optionally provide an ID to be used as this transaction ID
|
|
135
|
+
*/
|
|
136
|
+
transactionId?: string
|
|
137
|
+
/**
|
|
138
|
+
* Set this to true to prevent this action from being batched with others.
|
|
139
|
+
*/
|
|
140
|
+
disableBatching?: boolean
|
|
141
|
+
}
|
|
142
|
+
|
|
23
143
|
/**
|
|
24
144
|
* Configuration options for creating an auth store.
|
|
25
145
|
*
|
|
@@ -191,6 +311,20 @@ export declare interface ComlinkNodeState {
|
|
|
191
311
|
nodes: Map<string, NodeEntry>
|
|
192
312
|
}
|
|
193
313
|
|
|
314
|
+
/** @beta */
|
|
315
|
+
export declare function createDocument<TDocument extends SanityDocumentLike>(
|
|
316
|
+
doc: DocumentTypeHandle<TDocument> | DocumentHandle<TDocument>,
|
|
317
|
+
): CreateDocumentAction<TDocument>
|
|
318
|
+
|
|
319
|
+
/** @beta */
|
|
320
|
+
export declare interface CreateDocumentAction<
|
|
321
|
+
TDocument extends SanityDocumentLike = SanityDocumentLike,
|
|
322
|
+
> {
|
|
323
|
+
type: 'document.create'
|
|
324
|
+
documentId: string
|
|
325
|
+
documentType: TDocument['_type']
|
|
326
|
+
}
|
|
327
|
+
|
|
194
328
|
/**
|
|
195
329
|
* @public
|
|
196
330
|
*/
|
|
@@ -200,7 +334,7 @@ export declare const createDocumentListStore: (instance: SanityInstance | Action
|
|
|
200
334
|
getState: BoundResourceAction<
|
|
201
335
|
[],
|
|
202
336
|
StateSource<{
|
|
203
|
-
results:
|
|
337
|
+
results: DocumentHandle_2[]
|
|
204
338
|
isPending: boolean
|
|
205
339
|
count: number
|
|
206
340
|
hasMore: boolean
|
|
@@ -227,6 +361,38 @@ export declare function createSanityInstance({
|
|
|
227
361
|
|
|
228
362
|
export {CurrentUser}
|
|
229
363
|
|
|
364
|
+
/**
|
|
365
|
+
* Given a type T and an array of “access keys” Parts, recursively index into T.
|
|
366
|
+
*
|
|
367
|
+
* If a part is a key, it looks up that property.
|
|
368
|
+
* If T is an array and the part is a number, it “indexes” into the element type.
|
|
369
|
+
*/
|
|
370
|
+
declare type DeepGet<T, TParts extends readonly unknown[]> = TParts extends [
|
|
371
|
+
infer Head,
|
|
372
|
+
...infer Tail,
|
|
373
|
+
]
|
|
374
|
+
? Head extends keyof T
|
|
375
|
+
? DeepGet<T[Head], Tail>
|
|
376
|
+
: T extends Array<infer U>
|
|
377
|
+
? Head extends number
|
|
378
|
+
? DeepGet<U, Tail>
|
|
379
|
+
: never
|
|
380
|
+
: never
|
|
381
|
+
: T
|
|
382
|
+
|
|
383
|
+
/** @beta */
|
|
384
|
+
export declare function deleteDocument<TDocument extends SanityDocumentLike>(
|
|
385
|
+
doc: string | DocumentHandle<TDocument>,
|
|
386
|
+
): DeleteDocumentAction<TDocument>
|
|
387
|
+
|
|
388
|
+
/** @beta */
|
|
389
|
+
export declare interface DeleteDocumentAction<
|
|
390
|
+
_TDocument extends SanityDocumentLike = SanityDocumentLike,
|
|
391
|
+
> {
|
|
392
|
+
type: 'document.delete'
|
|
393
|
+
documentId: string
|
|
394
|
+
}
|
|
395
|
+
|
|
230
396
|
/**
|
|
231
397
|
* Calls the destroy method on the controller and resets the controller state.
|
|
232
398
|
* @public
|
|
@@ -235,12 +401,81 @@ export declare const destroyController: (
|
|
|
235
401
|
actionContext: ActionContext<ComlinkControllerState>,
|
|
236
402
|
) => void
|
|
237
403
|
|
|
404
|
+
/** @beta */
|
|
405
|
+
export declare function discardDocument<TDocument extends SanityDocumentLike>(
|
|
406
|
+
doc: string | DocumentHandle<TDocument>,
|
|
407
|
+
): DiscardDocumentAction<TDocument>
|
|
408
|
+
|
|
409
|
+
/** @beta */
|
|
410
|
+
export declare interface DiscardDocumentAction<
|
|
411
|
+
_TDocument extends SanityDocumentLike = SanityDocumentLike,
|
|
412
|
+
> {
|
|
413
|
+
type: 'document.discard'
|
|
414
|
+
documentId: string
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/** @beta */
|
|
418
|
+
export declare type DocumentAction<TDocument extends SanityDocumentLike = SanityDocumentLike> =
|
|
419
|
+
| CreateDocumentAction<TDocument>
|
|
420
|
+
| DeleteDocumentAction<TDocument>
|
|
421
|
+
| EditDocumentAction<TDocument>
|
|
422
|
+
| PublishDocumentAction<TDocument>
|
|
423
|
+
| UnpublishDocumentAction<TDocument>
|
|
424
|
+
| DiscardDocumentAction<TDocument>
|
|
425
|
+
|
|
426
|
+
/** @beta */
|
|
427
|
+
export declare interface DocumentCreatedEvent {
|
|
428
|
+
type: 'created'
|
|
429
|
+
documentId: string
|
|
430
|
+
outgoing: OutgoingTransaction
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/** @beta */
|
|
434
|
+
export declare interface DocumentDeletedEvent {
|
|
435
|
+
type: 'deleted'
|
|
436
|
+
documentId: string
|
|
437
|
+
outgoing: OutgoingTransaction
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/** @beta */
|
|
441
|
+
export declare interface DocumentDiscardedEvent {
|
|
442
|
+
type: 'discarded'
|
|
443
|
+
documentId: string
|
|
444
|
+
outgoing: OutgoingTransaction
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/** @beta */
|
|
448
|
+
export declare interface DocumentEditedEvent {
|
|
449
|
+
type: 'edited'
|
|
450
|
+
documentId: string
|
|
451
|
+
outgoing: OutgoingTransaction
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/** @beta */
|
|
455
|
+
export declare type DocumentEvent =
|
|
456
|
+
| ActionErrorEvent
|
|
457
|
+
| TransactionRevertedEvent
|
|
458
|
+
| TransactionAcceptedEvent
|
|
459
|
+
| DocumentRebaseErrorEvent
|
|
460
|
+
| DocumentEditedEvent
|
|
461
|
+
| DocumentCreatedEvent
|
|
462
|
+
| DocumentDeletedEvent
|
|
463
|
+
| DocumentPublishedEvent
|
|
464
|
+
| DocumentUnpublishedEvent
|
|
465
|
+
| DocumentDiscardedEvent
|
|
466
|
+
|
|
467
|
+
/** @beta */
|
|
468
|
+
export declare interface DocumentHandle<TDocument extends SanityDocumentLike = SanityDocumentLike> {
|
|
469
|
+
_id: string
|
|
470
|
+
_type: TDocument['_type']
|
|
471
|
+
}
|
|
472
|
+
|
|
238
473
|
/**
|
|
239
474
|
* Represents an identifier to a Sanity document, containing its `_id` to pull
|
|
240
475
|
* the document from content lake and its `_type` to look up its schema type.
|
|
241
476
|
* @public
|
|
242
477
|
*/
|
|
243
|
-
|
|
478
|
+
declare interface DocumentHandle_2 {
|
|
244
479
|
_id: string
|
|
245
480
|
_type: string
|
|
246
481
|
}
|
|
@@ -267,10 +502,121 @@ export declare interface DocumentListState {
|
|
|
267
502
|
syncTags: SyncTag[]
|
|
268
503
|
limit: number
|
|
269
504
|
count: number
|
|
270
|
-
results:
|
|
505
|
+
results: DocumentHandle_2[]
|
|
271
506
|
isPending: boolean
|
|
272
507
|
}
|
|
273
508
|
|
|
509
|
+
/** @beta */
|
|
510
|
+
export declare interface DocumentPublishedEvent {
|
|
511
|
+
type: 'published'
|
|
512
|
+
documentId: string
|
|
513
|
+
outgoing: OutgoingTransaction
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/** @beta */
|
|
517
|
+
declare interface DocumentRebaseErrorEvent {
|
|
518
|
+
type: 'rebase-error'
|
|
519
|
+
documentId: string
|
|
520
|
+
transactionId: string
|
|
521
|
+
message: string
|
|
522
|
+
error: unknown
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Represents a set of document that will go into `applyMutations`. Before
|
|
527
|
+
* applying a mutation, it's expected that all relevant documents that the
|
|
528
|
+
* mutations affect are included, including those that do not exist yet.
|
|
529
|
+
* Documents that don't exist have a `null` value.
|
|
530
|
+
*/
|
|
531
|
+
declare type DocumentSet<TDocument extends SanityDocument = SanityDocument> = {
|
|
532
|
+
[TDocumentId in string]?: TDocument | null
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
declare interface DocumentState {
|
|
536
|
+
id: string
|
|
537
|
+
/**
|
|
538
|
+
* the "remote" local copy that matches the server. represents the last known
|
|
539
|
+
* server state. this gets updated every time we confirm remote patches
|
|
540
|
+
*/
|
|
541
|
+
remote?: SanityDocument | null
|
|
542
|
+
/**
|
|
543
|
+
* the current ephemeral working copy that includes local optimistic changes
|
|
544
|
+
* that have not yet been confirmed by the server
|
|
545
|
+
*/
|
|
546
|
+
local?: SanityDocument | null
|
|
547
|
+
/**
|
|
548
|
+
* the revision that our remote document is at
|
|
549
|
+
*/
|
|
550
|
+
remoteRev?: string | null
|
|
551
|
+
/**
|
|
552
|
+
* Array of subscription IDs. This document state will be deleted if there are
|
|
553
|
+
* no subscribers.
|
|
554
|
+
*/
|
|
555
|
+
subscriptions: string[]
|
|
556
|
+
/**
|
|
557
|
+
* An object keyed by transaction ID of revisions sent out but that have not
|
|
558
|
+
* yet been verified yet. When an applied transaction is transitioned to an
|
|
559
|
+
* outgoing transaction, it also adds unverified revisions for each document
|
|
560
|
+
* that is part of that outgoing transaction. Transactions are submitted to
|
|
561
|
+
* the server with a locally generated transaction ID. This way we can observe
|
|
562
|
+
* when our transaction comes back through the shared listener. Each listener
|
|
563
|
+
* event that comes back contains a `previousRev`. If we see our own
|
|
564
|
+
* transaction with a different `previousRev` than expected, we can rebase our
|
|
565
|
+
* local transactions on top of this new remote.
|
|
566
|
+
*/
|
|
567
|
+
unverifiedRevisions?: {
|
|
568
|
+
[TTransactionId in string]?: UnverifiedDocumentRevision
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
declare interface DocumentStoreState {
|
|
573
|
+
documentStates: {
|
|
574
|
+
[TDocumentId in string]?: DocumentState
|
|
575
|
+
}
|
|
576
|
+
queued: QueuedTransaction[]
|
|
577
|
+
applied: AppliedTransaction[]
|
|
578
|
+
outgoing?: OutgoingTransaction
|
|
579
|
+
error?: unknown
|
|
580
|
+
sharedListener: Observable<ListenEvent<SanityDocument>>
|
|
581
|
+
fetchDocument: (documentId: string) => Observable<SanityDocument | null>
|
|
582
|
+
events: Subject<DocumentEvent>
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/** @beta */
|
|
586
|
+
export declare interface DocumentTypeHandle<
|
|
587
|
+
TDocument extends SanityDocumentLike = SanityDocumentLike,
|
|
588
|
+
> {
|
|
589
|
+
_id?: string
|
|
590
|
+
_type: TDocument['_type']
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/** @beta */
|
|
594
|
+
export declare interface DocumentUnpublishedEvent {
|
|
595
|
+
type: 'unpublished'
|
|
596
|
+
documentId: string
|
|
597
|
+
outgoing: OutgoingTransaction
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/** @beta */
|
|
601
|
+
export declare function editDocument<TDocument extends SanityDocumentLike>(
|
|
602
|
+
sanityMutatePatch: PatchMutation,
|
|
603
|
+
): EditDocumentAction<TDocument>
|
|
604
|
+
|
|
605
|
+
/** @beta */
|
|
606
|
+
export declare function editDocument<TDocument extends SanityDocumentLike>(
|
|
607
|
+
doc: string | DocumentHandle<TDocument>,
|
|
608
|
+
patches: PatchOperations | PatchOperations[],
|
|
609
|
+
): EditDocumentAction<TDocument>
|
|
610
|
+
|
|
611
|
+
/** @beta */
|
|
612
|
+
export declare interface EditDocumentAction<
|
|
613
|
+
_TDocument extends SanityDocumentLike = SanityDocumentLike,
|
|
614
|
+
> {
|
|
615
|
+
type: 'document.edit'
|
|
616
|
+
documentId: string
|
|
617
|
+
patches: PatchOperations[]
|
|
618
|
+
}
|
|
619
|
+
|
|
274
620
|
/**
|
|
275
621
|
* Error state from the auth state.
|
|
276
622
|
* @public
|
|
@@ -326,6 +672,36 @@ export declare const getCurrentUserState: ResourceAction<
|
|
|
326
672
|
StateSource<CurrentUser | null>
|
|
327
673
|
>
|
|
328
674
|
|
|
675
|
+
/** @beta */
|
|
676
|
+
export declare function getDocumentState<
|
|
677
|
+
TDocument extends SanityDocument,
|
|
678
|
+
TPath extends JsonMatchPath<TDocument>,
|
|
679
|
+
>(
|
|
680
|
+
instance: SanityInstance | ActionContext<DocumentStoreState>,
|
|
681
|
+
doc: string | DocumentHandle<TDocument>,
|
|
682
|
+
path: TPath,
|
|
683
|
+
): StateSource<JsonMatch<TDocument, TPath> | undefined>
|
|
684
|
+
|
|
685
|
+
/** @beta */
|
|
686
|
+
export declare function getDocumentState<TDocument extends SanityDocument>(
|
|
687
|
+
instance: SanityInstance | ActionContext<DocumentStoreState>,
|
|
688
|
+
doc: string | DocumentHandle<TDocument>,
|
|
689
|
+
): StateSource<TDocument | null>
|
|
690
|
+
|
|
691
|
+
/** @beta */
|
|
692
|
+
export declare function getDocumentState(
|
|
693
|
+
instance: SanityInstance | ActionContext<DocumentStoreState>,
|
|
694
|
+
doc: string | DocumentHandle,
|
|
695
|
+
path?: string,
|
|
696
|
+
): StateSource<unknown>
|
|
697
|
+
|
|
698
|
+
/** @beta */
|
|
699
|
+
export declare const getDocumentSyncStatus: ResourceAction<
|
|
700
|
+
DocumentStoreState,
|
|
701
|
+
[doc: string | DocumentHandle<SanityDocumentLike>],
|
|
702
|
+
StateSource<boolean | undefined>
|
|
703
|
+
>
|
|
704
|
+
|
|
329
705
|
/**
|
|
330
706
|
* Retrieves the global, project-less client.
|
|
331
707
|
* @public
|
|
@@ -388,7 +764,7 @@ export declare const getPreviewState: ResourceAction<
|
|
|
388
764
|
* @public
|
|
389
765
|
*/
|
|
390
766
|
export declare interface GetPreviewStateOptions {
|
|
391
|
-
document:
|
|
767
|
+
document: DocumentHandle_2
|
|
392
768
|
}
|
|
393
769
|
|
|
394
770
|
/**
|
|
@@ -416,6 +792,77 @@ export declare const handleCallback: ResourceAction<
|
|
|
416
792
|
Promise<string | false>
|
|
417
793
|
>
|
|
418
794
|
|
|
795
|
+
declare type HttpAction =
|
|
796
|
+
| {
|
|
797
|
+
actionType: ActionMap['create']
|
|
798
|
+
publishedId: string
|
|
799
|
+
attributes: SanityDocumentLike
|
|
800
|
+
}
|
|
801
|
+
| {
|
|
802
|
+
actionType: ActionMap['discard']
|
|
803
|
+
versionId: string
|
|
804
|
+
purge?: boolean
|
|
805
|
+
}
|
|
806
|
+
| {
|
|
807
|
+
actionType: ActionMap['unpublish']
|
|
808
|
+
draftId: string
|
|
809
|
+
publishedId: string
|
|
810
|
+
}
|
|
811
|
+
| {
|
|
812
|
+
actionType: ActionMap['delete']
|
|
813
|
+
publishedId: string
|
|
814
|
+
includeDrafts?: string[]
|
|
815
|
+
}
|
|
816
|
+
| {
|
|
817
|
+
actionType: ActionMap['edit']
|
|
818
|
+
draftId: string
|
|
819
|
+
publishedId: string
|
|
820
|
+
patch: PatchOperations
|
|
821
|
+
}
|
|
822
|
+
| ({
|
|
823
|
+
actionType: ActionMap['publish']
|
|
824
|
+
draftId: string
|
|
825
|
+
publishedId: string
|
|
826
|
+
} & OptimisticLock)
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* Given a document type TDocument and a JSON Match path string TPath,
|
|
830
|
+
* compute the type found at that path.
|
|
831
|
+
* @beta
|
|
832
|
+
*/
|
|
833
|
+
export declare type JsonMatch<TDocument extends SanityDocumentLike, TPath extends string> = DeepGet<
|
|
834
|
+
TDocument,
|
|
835
|
+
PathParts<TPath>
|
|
836
|
+
>
|
|
837
|
+
|
|
838
|
+
/**
|
|
839
|
+
* A very simplified implementation of [JSONMatch][0] that only supports:
|
|
840
|
+
* - descent e.g. `friend.name`
|
|
841
|
+
* - array index e.g. `items[-1]`
|
|
842
|
+
* - array matching with `_key` e.g. `items[_key=="dd9efe09"]`
|
|
843
|
+
* - array matching with a range e.g. `items[4:]`
|
|
844
|
+
*
|
|
845
|
+
* E.g. `friends[_key=="dd9efe09"].address.zip`
|
|
846
|
+
*
|
|
847
|
+
* [0]: https://www.sanity.io/docs/json-match
|
|
848
|
+
*
|
|
849
|
+
* @beta
|
|
850
|
+
*/
|
|
851
|
+
export declare function jsonMatch<
|
|
852
|
+
TDocument extends SanityDocumentLike,
|
|
853
|
+
TPath extends JsonMatchPath<TDocument>,
|
|
854
|
+
>(input: TDocument, path: TPath): MatchEntry<JsonMatch<TDocument, TPath>>[]
|
|
855
|
+
|
|
856
|
+
/** @beta */
|
|
857
|
+
export declare function jsonMatch<TValue>(input: unknown, path: string): MatchEntry<TValue>[]
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* Computing the full possible paths may be possible but is hard to compute
|
|
861
|
+
* within the type system for complex document types so we use string.
|
|
862
|
+
* @beta
|
|
863
|
+
*/
|
|
864
|
+
export declare type JsonMatchPath<_TDocument extends SanityDocumentLike> = string
|
|
865
|
+
|
|
419
866
|
/**
|
|
420
867
|
* Logged-in state from the auth state.
|
|
421
868
|
* @public
|
|
@@ -449,6 +896,11 @@ export declare type LoggingInAuthState = {
|
|
|
449
896
|
*/
|
|
450
897
|
export declare const logout: ResourceAction<AuthStoreState, [], Promise<void>>
|
|
451
898
|
|
|
899
|
+
declare type MatchEntry<T = unknown> = {
|
|
900
|
+
value: T
|
|
901
|
+
path: SingleValuePath
|
|
902
|
+
}
|
|
903
|
+
|
|
452
904
|
/**
|
|
453
905
|
* Individual node with its relevant options
|
|
454
906
|
* @public
|
|
@@ -459,6 +911,86 @@ declare interface NodeEntry {
|
|
|
459
911
|
refCount: number
|
|
460
912
|
}
|
|
461
913
|
|
|
914
|
+
declare type OptimisticLock = {
|
|
915
|
+
ifDraftRevisionId?: string
|
|
916
|
+
ifPublishedRevisionId?: string
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
/**
|
|
920
|
+
* Represents a set of applied transactions batched into a single outgoing
|
|
921
|
+
* transaction. An outgoing transaction is the result of batching many applied
|
|
922
|
+
* actions. An outgoing transaction may be reverted locally if the server
|
|
923
|
+
* does not accept it.
|
|
924
|
+
*/
|
|
925
|
+
declare interface OutgoingTransaction extends AppliedTransaction {
|
|
926
|
+
disableBatching: boolean
|
|
927
|
+
batchedTransactionIds: string[]
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
/**
|
|
931
|
+
* Parse one or more bracketed parts from a segment.
|
|
932
|
+
*
|
|
933
|
+
* It recursively “peels off” a bracketed part and then continues.
|
|
934
|
+
*
|
|
935
|
+
* For example, given the string:
|
|
936
|
+
*
|
|
937
|
+
* ```
|
|
938
|
+
* "[0][foo]"
|
|
939
|
+
* ```
|
|
940
|
+
*
|
|
941
|
+
* it produces:
|
|
942
|
+
*
|
|
943
|
+
* ```
|
|
944
|
+
* [ToNumber<"0">, "foo"]
|
|
945
|
+
* ```
|
|
946
|
+
*/
|
|
947
|
+
declare type ParseBracket<TInput extends string> = TInput extends `[${infer TPart}]${infer TRest}`
|
|
948
|
+
? [ToNumber<TPart>, ...ParseSegment<TRest>]
|
|
949
|
+
: []
|
|
950
|
+
|
|
951
|
+
/**
|
|
952
|
+
* Parse a single “segment” that may include bracket parts.
|
|
953
|
+
*
|
|
954
|
+
* For example, the literal
|
|
955
|
+
*
|
|
956
|
+
* ```
|
|
957
|
+
* "friends[0][1]"
|
|
958
|
+
* ```
|
|
959
|
+
*
|
|
960
|
+
* is parsed as:
|
|
961
|
+
*
|
|
962
|
+
* ```
|
|
963
|
+
* ["friends", 0, 1]
|
|
964
|
+
* ```
|
|
965
|
+
*/
|
|
966
|
+
declare type ParseSegment<TInput extends string> = TInput extends `${infer TProp}[${infer TRest}`
|
|
967
|
+
? TProp extends ''
|
|
968
|
+
? [...ParseBracket<`[${TRest}`>]
|
|
969
|
+
: [TProp, ...ParseBracket<`[${TRest}`>]
|
|
970
|
+
: TInput extends ''
|
|
971
|
+
? []
|
|
972
|
+
: [TInput]
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* Split the entire path string on dots “outside” of any brackets.
|
|
976
|
+
*
|
|
977
|
+
* For example:
|
|
978
|
+
* ```
|
|
979
|
+
* "friends[0].name"
|
|
980
|
+
* ```
|
|
981
|
+
*
|
|
982
|
+
* becomes:
|
|
983
|
+
*
|
|
984
|
+
* ```
|
|
985
|
+
* [...ParseSegment<"friends[0]">, ...ParseSegment<"name">]
|
|
986
|
+
* ```
|
|
987
|
+
*
|
|
988
|
+
* (We use a simple recursion that splits on the first dot.)
|
|
989
|
+
*/
|
|
990
|
+
declare type PathParts<TPath extends string> = TPath extends `${infer TLeft}.${infer TRight}`
|
|
991
|
+
? [...ParseSegment<TLeft>, ...PathParts<TRight>]
|
|
992
|
+
: ParseSegment<TPath>
|
|
993
|
+
|
|
462
994
|
/**
|
|
463
995
|
* @public
|
|
464
996
|
*/
|
|
@@ -508,6 +1040,42 @@ export declare interface PreviewValue {
|
|
|
508
1040
|
}
|
|
509
1041
|
}
|
|
510
1042
|
|
|
1043
|
+
/** @beta */
|
|
1044
|
+
export declare function publishDocument<TDocument extends SanityDocumentLike>(
|
|
1045
|
+
doc: string | DocumentHandle<TDocument>,
|
|
1046
|
+
): PublishDocumentAction<TDocument>
|
|
1047
|
+
|
|
1048
|
+
/** @beta */
|
|
1049
|
+
export declare interface PublishDocumentAction<
|
|
1050
|
+
_TDocument extends SanityDocumentLike = SanityDocumentLike,
|
|
1051
|
+
> {
|
|
1052
|
+
type: 'document.publish'
|
|
1053
|
+
documentId: string
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* Represents a transaction that is queued to be applied but has not yet been
|
|
1058
|
+
* applied. A transaction will remain in a queued state until all required
|
|
1059
|
+
* documents for the transactions are available locally.
|
|
1060
|
+
*/
|
|
1061
|
+
declare interface QueuedTransaction {
|
|
1062
|
+
/**
|
|
1063
|
+
* the ID of this transaction. this is generated client-side.
|
|
1064
|
+
*/
|
|
1065
|
+
transactionId: string
|
|
1066
|
+
/**
|
|
1067
|
+
* the high-level actions associated with this transaction. note that these
|
|
1068
|
+
* actions don't mention draft IDs and is meant to abstract away the draft
|
|
1069
|
+
* model from users.
|
|
1070
|
+
*/
|
|
1071
|
+
actions: DocumentAction[]
|
|
1072
|
+
/**
|
|
1073
|
+
* An optional flag set to disable this transaction from being batched with
|
|
1074
|
+
* other transactions.
|
|
1075
|
+
*/
|
|
1076
|
+
disableBatching?: boolean
|
|
1077
|
+
}
|
|
1078
|
+
|
|
511
1079
|
/**
|
|
512
1080
|
* Signals to the store that the consumer has stopped using the channel
|
|
513
1081
|
* @public
|
|
@@ -520,6 +1088,18 @@ export declare const releaseChannel: ResourceAction<ComlinkControllerState, [nam
|
|
|
520
1088
|
*/
|
|
521
1089
|
export declare const releaseNode: ResourceAction<ComlinkNodeState, [name: string], void>
|
|
522
1090
|
|
|
1091
|
+
/** @beta */
|
|
1092
|
+
export declare function resolveDocument<TDocument extends SanityDocument>(
|
|
1093
|
+
instance: SanityInstance | ActionContext<DocumentStoreState>,
|
|
1094
|
+
doc: string | DocumentHandle<TDocument>,
|
|
1095
|
+
): Promise<TDocument | null>
|
|
1096
|
+
|
|
1097
|
+
/** @beta */
|
|
1098
|
+
export declare function resolveDocument(
|
|
1099
|
+
instance: SanityInstance | ActionContext<DocumentStoreState>,
|
|
1100
|
+
doc: string | DocumentHandle,
|
|
1101
|
+
): Promise<SanityDocument | null>
|
|
1102
|
+
|
|
523
1103
|
/**
|
|
524
1104
|
* @public
|
|
525
1105
|
*/
|
|
@@ -533,7 +1113,7 @@ export declare const resolvePreview: ResourceAction<
|
|
|
533
1113
|
* @public
|
|
534
1114
|
*/
|
|
535
1115
|
export declare interface ResolvePreviewOptions {
|
|
536
|
-
document:
|
|
1116
|
+
document: DocumentHandle_2
|
|
537
1117
|
}
|
|
538
1118
|
|
|
539
1119
|
/**
|
|
@@ -565,6 +1145,8 @@ export declare interface SanityConfig {
|
|
|
565
1145
|
schema?: SchemaConfig
|
|
566
1146
|
}
|
|
567
1147
|
|
|
1148
|
+
export {SanityDocumentLike}
|
|
1149
|
+
|
|
568
1150
|
/** @public */
|
|
569
1151
|
export declare interface SanityInstance {
|
|
570
1152
|
/**
|
|
@@ -592,15 +1174,63 @@ export declare interface SdkIdentity {
|
|
|
592
1174
|
readonly dataset: string
|
|
593
1175
|
}
|
|
594
1176
|
|
|
1177
|
+
declare type SingleValuePath = Exclude<PathSegment, IndexTuple>[]
|
|
1178
|
+
|
|
595
1179
|
/**
|
|
596
1180
|
* @public
|
|
597
1181
|
*/
|
|
598
1182
|
export declare interface StateSource<T> {
|
|
599
|
-
subscribe: (onStoreChanged
|
|
1183
|
+
subscribe: (onStoreChanged?: () => void) => () => void
|
|
600
1184
|
getCurrent: () => T
|
|
601
1185
|
observable: Observable<T>
|
|
602
1186
|
}
|
|
603
1187
|
|
|
1188
|
+
/** @beta */
|
|
1189
|
+
export declare const subscribeDocumentEvents: ResourceAction<
|
|
1190
|
+
DocumentStoreState,
|
|
1191
|
+
[eventHandler: (e: DocumentEvent) => void],
|
|
1192
|
+
() => void
|
|
1193
|
+
>
|
|
1194
|
+
|
|
1195
|
+
declare type ToNumber<TInput extends string> = TInput extends `${infer TNumber extends number}`
|
|
1196
|
+
? TNumber
|
|
1197
|
+
: TInput
|
|
1198
|
+
|
|
1199
|
+
/** @beta */
|
|
1200
|
+
export declare interface TransactionAcceptedEvent {
|
|
1201
|
+
type: 'accepted'
|
|
1202
|
+
outgoing: OutgoingTransaction
|
|
1203
|
+
result: Awaited<ReturnType<SanityClient['action']>>
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
/** @beta */
|
|
1207
|
+
export declare interface TransactionRevertedEvent {
|
|
1208
|
+
type: 'reverted'
|
|
1209
|
+
message: string
|
|
1210
|
+
error: unknown
|
|
1211
|
+
outgoing: OutgoingTransaction
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
/** @beta */
|
|
1215
|
+
export declare function unpublishDocument<TDocument extends SanityDocumentLike>(
|
|
1216
|
+
doc: string | DocumentHandle<TDocument>,
|
|
1217
|
+
): UnpublishDocumentAction<TDocument>
|
|
1218
|
+
|
|
1219
|
+
/** @beta */
|
|
1220
|
+
export declare interface UnpublishDocumentAction<
|
|
1221
|
+
_TDocument extends SanityDocumentLike = SanityDocumentLike,
|
|
1222
|
+
> {
|
|
1223
|
+
type: 'document.unpublish'
|
|
1224
|
+
documentId: string
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
declare interface UnverifiedDocumentRevision {
|
|
1228
|
+
transactionId: string
|
|
1229
|
+
documentId: string
|
|
1230
|
+
previousRev: string | undefined
|
|
1231
|
+
timestamp: string
|
|
1232
|
+
}
|
|
1233
|
+
|
|
604
1234
|
/**
|
|
605
1235
|
* Represents the current state of a preview value along with a flag indicating whether
|
|
606
1236
|
* the preview data is still being fetched or is fully resolved.
|