@sanity/sdk 2.7.0 → 3.0.0-rc.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.
Files changed (99) hide show
  1. package/dist/index.d.ts +228 -239
  2. package/dist/index.js +287 -454
  3. package/dist/index.js.map +1 -1
  4. package/package.json +4 -4
  5. package/src/_exports/index.ts +16 -17
  6. package/src/agent/agentActions.test.ts +60 -16
  7. package/src/agent/agentActions.ts +29 -20
  8. package/src/auth/authMode.test.ts +0 -25
  9. package/src/auth/authMode.ts +3 -6
  10. package/src/auth/authStore.test.ts +129 -66
  11. package/src/auth/authStore.ts +9 -11
  12. package/src/auth/dashboardAuth.ts +2 -2
  13. package/src/auth/getOrganizationVerificationState.test.ts +10 -11
  14. package/src/auth/handleAuthCallback.test.ts +0 -12
  15. package/src/auth/handleAuthCallback.ts +9 -3
  16. package/src/auth/logout.test.ts +0 -6
  17. package/src/auth/refreshStampedToken.test.ts +121 -17
  18. package/src/auth/standaloneAuth.ts +9 -3
  19. package/src/auth/studioAuth.ts +35 -8
  20. package/src/auth/subscribeToStateAndFetchCurrentUser.test.ts +9 -3
  21. package/src/auth/subscribeToStateAndFetchCurrentUser.ts +1 -1
  22. package/src/auth/subscribeToStorageEventsAndSetToken.test.ts +0 -2
  23. package/src/auth/subscribeToStorageEventsAndSetToken.ts +2 -2
  24. package/src/auth/utils.ts +33 -0
  25. package/src/client/clientStore.test.ts +14 -61
  26. package/src/client/clientStore.ts +52 -28
  27. package/src/comlink/controller/actions/destroyController.test.ts +1 -4
  28. package/src/comlink/controller/actions/getOrCreateChannel.test.ts +1 -4
  29. package/src/comlink/controller/actions/getOrCreateController.test.ts +1 -4
  30. package/src/comlink/controller/actions/releaseChannel.test.ts +1 -1
  31. package/src/comlink/controller/comlinkControllerStore.test.ts +1 -4
  32. package/src/comlink/node/actions/getOrCreateNode.test.ts +1 -4
  33. package/src/comlink/node/actions/releaseNode.test.ts +1 -4
  34. package/src/comlink/node/comlinkNodeStore.test.ts +2 -2
  35. package/src/comlink/node/getNodeState.test.ts +1 -1
  36. package/src/config/__tests__/handles.test.ts +12 -18
  37. package/src/config/handles.ts +7 -25
  38. package/src/config/sanityConfig.ts +99 -52
  39. package/src/datasets/datasets.test.ts +2 -2
  40. package/src/datasets/datasets.ts +4 -10
  41. package/src/document/actions.test.ts +33 -4
  42. package/src/document/actions.ts +3 -10
  43. package/src/document/applyDocumentActions.test.ts +17 -18
  44. package/src/document/applyDocumentActions.ts +9 -12
  45. package/src/document/documentStore.test.ts +303 -133
  46. package/src/document/documentStore.ts +70 -61
  47. package/src/document/permissions.test.ts +44 -8
  48. package/src/document/processActions.test.ts +77 -7
  49. package/src/document/reducers.test.ts +35 -3
  50. package/src/document/sharedListener.test.ts +13 -13
  51. package/src/document/sharedListener.ts +8 -3
  52. package/src/favorites/favorites.test.ts +10 -2
  53. package/src/presence/presenceStore.test.ts +34 -9
  54. package/src/presence/presenceStore.ts +29 -13
  55. package/src/preview/previewProjectionUtils.test.ts +192 -0
  56. package/src/preview/previewProjectionUtils.ts +88 -0
  57. package/src/preview/{previewStore.ts → types.ts} +6 -25
  58. package/src/project/project.test.ts +1 -1
  59. package/src/project/project.ts +14 -20
  60. package/src/projection/getProjectionState.test.ts +4 -2
  61. package/src/projection/getProjectionState.ts +2 -21
  62. package/src/projection/projectionQuery.ts +2 -3
  63. package/src/projection/projectionStore.test.ts +3 -3
  64. package/src/projection/resolveProjection.test.ts +2 -1
  65. package/src/projection/resolveProjection.ts +2 -18
  66. package/src/projection/subscribeToStateAndFetchBatches.test.ts +2 -2
  67. package/src/projection/subscribeToStateAndFetchBatches.ts +23 -36
  68. package/src/projection/types.ts +1 -9
  69. package/src/projects/projects.test.ts +1 -1
  70. package/src/query/queryStore.test.ts +86 -28
  71. package/src/query/queryStore.ts +23 -38
  72. package/src/releases/getPerspectiveState.test.ts +14 -13
  73. package/src/releases/getPerspectiveState.ts +6 -6
  74. package/src/releases/releasesStore.test.ts +21 -6
  75. package/src/releases/releasesStore.ts +18 -8
  76. package/src/store/createActionBinder.test.ts +114 -111
  77. package/src/store/createActionBinder.ts +52 -101
  78. package/src/store/createSanityInstance.test.ts +13 -83
  79. package/src/store/createSanityInstance.ts +2 -78
  80. package/src/store/createStateSourceAction.test.ts +2 -2
  81. package/src/store/createStateSourceAction.ts +5 -5
  82. package/src/store/createStoreInstance.test.ts +2 -4
  83. package/src/users/reducers.test.ts +1 -6
  84. package/src/users/reducers.ts +2 -2
  85. package/src/users/types.ts +4 -4
  86. package/src/users/usersStore.test.ts +12 -15
  87. package/src/utils/createFetcherStore.test.ts +1 -1
  88. package/src/utils/logger.test.ts +0 -12
  89. package/src/utils/logger.ts +3 -8
  90. package/src/preview/getPreviewState.test.ts +0 -120
  91. package/src/preview/getPreviewState.ts +0 -91
  92. package/src/preview/previewQuery.test.ts +0 -236
  93. package/src/preview/previewQuery.ts +0 -153
  94. package/src/preview/previewStore.test.ts +0 -36
  95. package/src/preview/resolvePreview.test.ts +0 -47
  96. package/src/preview/resolvePreview.ts +0 -20
  97. package/src/preview/subscribeToStateAndFetchBatches.test.ts +0 -221
  98. package/src/preview/subscribeToStateAndFetchBatches.ts +0 -112
  99. package/src/preview/util.ts +0 -13
@@ -50,6 +50,7 @@ describe('processActions', () => {
50
50
  documentId: 'doc1',
51
51
  type: 'document.create',
52
52
  documentType: 'article',
53
+ resource: {projectId: 'p', dataset: 'd'},
53
54
  },
54
55
  ]
55
56
  const result = processActions({
@@ -96,6 +97,7 @@ describe('processActions', () => {
96
97
  documentId: 'doc1',
97
98
  type: 'document.create',
98
99
  documentType: 'article',
100
+ resource: {projectId: 'p', dataset: 'd'},
99
101
  },
100
102
  ]
101
103
  expect(() =>
@@ -113,6 +115,7 @@ describe('processActions', () => {
113
115
  documentId: 'doc1',
114
116
  type: 'document.create',
115
117
  documentType: 'article',
118
+ resource: {projectId: 'p', dataset: 'd'},
116
119
  },
117
120
  ]
118
121
  const result = processActions({
@@ -141,6 +144,7 @@ describe('processActions', () => {
141
144
  documentId: 'doc1',
142
145
  type: 'document.create',
143
146
  documentType: 'article',
147
+ resource: {projectId: 'p', dataset: 'd'},
144
148
  },
145
149
  ]
146
150
  const grants = {...defaultGrants, create: alwaysDeny}
@@ -162,6 +166,7 @@ describe('processActions', () => {
162
166
  author: 'John Doe',
163
167
  count: 42,
164
168
  },
169
+ resource: {projectId: 'p', dataset: 'd'},
165
170
  },
166
171
  ]
167
172
  const result = processActions({
@@ -198,6 +203,7 @@ describe('processActions', () => {
198
203
  title: 'Overridden Title',
199
204
  newField: 'New Value',
200
205
  },
206
+ resource: {projectId: 'p', dataset: 'd'},
201
207
  },
202
208
  ]
203
209
  const result = processActions({
@@ -227,6 +233,7 @@ describe('processActions', () => {
227
233
  type: 'document.create',
228
234
  documentType: 'article',
229
235
  initialValue: {},
236
+ resource: {projectId: 'p', dataset: 'd'},
230
237
  },
231
238
  ]
232
239
  const result = processActions({
@@ -258,6 +265,7 @@ describe('processActions', () => {
258
265
  documentId: 'doc1',
259
266
  documentType: 'article',
260
267
  type: 'document.delete',
268
+ resource: {projectId: 'p', dataset: 'd'},
261
269
  },
262
270
  ]
263
271
  const result = processActions({
@@ -294,6 +302,7 @@ describe('processActions', () => {
294
302
  documentId: 'doc1',
295
303
  documentType: 'article',
296
304
  type: 'document.delete',
305
+ resource: {projectId: 'p', dataset: 'd'},
297
306
  },
298
307
  ]
299
308
  const result = processActions({
@@ -326,6 +335,7 @@ describe('processActions', () => {
326
335
  documentId: 'doc1',
327
336
  documentType: 'article',
328
337
  type: 'document.delete',
338
+ resource: {projectId: 'p', dataset: 'd'},
329
339
  },
330
340
  ]
331
341
  const grants = {...defaultGrants, update: alwaysDeny}
@@ -345,6 +355,7 @@ describe('processActions', () => {
345
355
  documentId: 'doc1',
346
356
  documentType: 'article',
347
357
  type: 'document.discard',
358
+ resource: {projectId: 'p', dataset: 'd'},
348
359
  },
349
360
  ]
350
361
  const result = processActions({
@@ -374,6 +385,7 @@ describe('processActions', () => {
374
385
  documentId: 'doc1',
375
386
  documentType: 'article',
376
387
  type: 'document.discard',
388
+ resource: {projectId: 'p', dataset: 'd'},
377
389
  },
378
390
  ]
379
391
  const grants = {...defaultGrants, update: alwaysDeny}
@@ -394,6 +406,7 @@ describe('processActions', () => {
394
406
  documentType: 'article',
395
407
  type: 'document.edit',
396
408
  patches: [{set: {title: 'Edited Title'}}],
409
+ resource: {projectId: 'p', dataset: 'd'},
397
410
  },
398
411
  ]
399
412
  const result = processActions({
@@ -426,6 +439,7 @@ describe('processActions', () => {
426
439
  documentType: 'article',
427
440
  type: 'document.edit',
428
441
  patches: [{set: {title: 'New Draft Title'}}],
442
+ resource: {projectId: 'p', dataset: 'd'},
429
443
  },
430
444
  ]
431
445
  const result = processActions({
@@ -454,6 +468,7 @@ describe('processActions', () => {
454
468
  documentType: 'article',
455
469
  type: 'document.edit',
456
470
  patches: [{set: {title: 'Original Cool Title'}}],
471
+ resource: {projectId: 'p', dataset: 'd'},
457
472
  },
458
473
  ]
459
474
  const result = processActions({
@@ -483,6 +498,7 @@ describe('processActions', () => {
483
498
  documentType: 'article',
484
499
  type: 'document.edit',
485
500
  patches: [{set: {title: 'Should Fail'}}],
501
+ resource: {projectId: 'p', dataset: 'd'},
486
502
  },
487
503
  ]
488
504
  expect(() =>
@@ -500,6 +516,7 @@ describe('processActions', () => {
500
516
  documentType: 'article',
501
517
  type: 'document.edit',
502
518
  patches: [{set: {title: 'Edited Title'}}],
519
+ resource: {projectId: 'p', dataset: 'd'},
503
520
  },
504
521
  ]
505
522
  const grants = {...defaultGrants, create: alwaysDeny}
@@ -518,6 +535,7 @@ describe('processActions', () => {
518
535
  documentType: 'article',
519
536
  type: 'document.edit',
520
537
  patches: [{set: {title: 'New Title'}}],
538
+ resource: {projectId: 'p', dataset: 'd'},
521
539
  },
522
540
  ]
523
541
  const grants = {...defaultGrants, update: alwaysDeny}
@@ -537,6 +555,7 @@ describe('processActions', () => {
537
555
  documentId: 'doc1',
538
556
  documentType: 'article',
539
557
  type: 'document.publish',
558
+ resource: {projectId: 'p', dataset: 'd'},
540
559
  },
541
560
  ]
542
561
  const result = processActions({
@@ -572,6 +591,7 @@ describe('processActions', () => {
572
591
  documentId: 'doc1',
573
592
  documentType: 'article',
574
593
  type: 'document.publish',
594
+ resource: {projectId: 'p', dataset: 'd'},
575
595
  },
576
596
  ]
577
597
  expect(() =>
@@ -590,6 +610,7 @@ describe('processActions', () => {
590
610
  documentId: 'doc1',
591
611
  documentType: 'article',
592
612
  type: 'document.publish',
613
+ resource: {projectId: 'p', dataset: 'd'},
593
614
  },
594
615
  ]
595
616
  expect(() =>
@@ -602,7 +623,12 @@ describe('processActions', () => {
602
623
  const base: DocumentSet = {'drafts.doc1': draft}
603
624
  const working: DocumentSet = {'drafts.doc1': draft}
604
625
  const actions: DocumentAction[] = [
605
- {documentId: 'doc1', documentType: 'article', type: 'document.publish'},
626
+ {
627
+ documentId: 'doc1',
628
+ documentType: 'article',
629
+ type: 'document.publish',
630
+ resource: {projectId: 'p', dataset: 'd'},
631
+ },
606
632
  ]
607
633
  const grants = {...defaultGrants, update: alwaysDeny}
608
634
  expect(() =>
@@ -616,7 +642,12 @@ describe('processActions', () => {
616
642
  const base: DocumentSet = {'drafts.doc1': draft, 'doc1': published}
617
643
  const working: DocumentSet = {'drafts.doc1': draft, 'doc1': published}
618
644
  const actions: DocumentAction[] = [
619
- {documentId: 'doc1', documentType: 'article', type: 'document.publish'},
645
+ {
646
+ documentId: 'doc1',
647
+ documentType: 'article',
648
+ type: 'document.publish',
649
+ resource: {projectId: 'p', dataset: 'd'},
650
+ },
620
651
  ]
621
652
  const grants = {
622
653
  ...defaultGrants,
@@ -635,7 +666,12 @@ describe('processActions', () => {
635
666
  const base: DocumentSet = {'drafts.doc1': draft}
636
667
  const working: DocumentSet = {'drafts.doc1': draft}
637
668
  const actions: DocumentAction[] = [
638
- {documentId: 'doc1', documentType: 'article', type: 'document.publish'},
669
+ {
670
+ documentId: 'doc1',
671
+ documentType: 'article',
672
+ type: 'document.publish',
673
+ resource: {projectId: 'p', dataset: 'd'},
674
+ },
639
675
  ]
640
676
  const grants = {...defaultGrants, create: alwaysDeny}
641
677
  expect(() =>
@@ -671,6 +707,7 @@ describe('processActions', () => {
671
707
  documentId: 'doc1',
672
708
  documentType: 'article',
673
709
  type: 'document.publish',
710
+ resource: {projectId: 'p', dataset: 'd'},
674
711
  },
675
712
  ]
676
713
  const result = processActions({
@@ -703,6 +740,7 @@ describe('processActions', () => {
703
740
  documentId: 'doc1',
704
741
  documentType: 'article',
705
742
  type: 'document.unpublish',
743
+ resource: {projectId: 'p', dataset: 'd'},
706
744
  },
707
745
  ]
708
746
  const result = processActions({
@@ -737,6 +775,7 @@ describe('processActions', () => {
737
775
  documentId: 'doc1',
738
776
  documentType: 'article',
739
777
  type: 'document.unpublish',
778
+ resource: {projectId: 'p', dataset: 'd'},
740
779
  },
741
780
  ]
742
781
  expect(() =>
@@ -755,6 +794,7 @@ describe('processActions', () => {
755
794
  documentId: 'doc1',
756
795
  documentType: 'article',
757
796
  type: 'document.unpublish',
797
+ resource: {projectId: 'p', dataset: 'd'},
758
798
  },
759
799
  ]
760
800
  const result = processActions({
@@ -786,7 +826,12 @@ describe('processActions', () => {
786
826
  const base: DocumentSet = {doc1: published}
787
827
  const working: DocumentSet = {doc1: published}
788
828
  const actions: DocumentAction[] = [
789
- {documentId: 'doc1', documentType: 'article', type: 'document.unpublish'},
829
+ {
830
+ documentId: 'doc1',
831
+ documentType: 'article',
832
+ type: 'document.unpublish',
833
+ resource: {projectId: 'p', dataset: 'd'},
834
+ },
790
835
  ]
791
836
  const grants = {...defaultGrants, update: alwaysDeny}
792
837
  expect(() =>
@@ -799,7 +844,12 @@ describe('processActions', () => {
799
844
  const base: DocumentSet = {doc1: published}
800
845
  const working: DocumentSet = {doc1: published}
801
846
  const actions: DocumentAction[] = [
802
- {documentId: 'doc1', documentType: 'article', type: 'document.unpublish'},
847
+ {
848
+ documentId: 'doc1',
849
+ documentType: 'article',
850
+ type: 'document.unpublish',
851
+ resource: {projectId: 'p', dataset: 'd'},
852
+ },
803
853
  ]
804
854
  const grants = {...defaultGrants, create: alwaysDeny}
805
855
  expect(() =>
@@ -814,14 +864,25 @@ describe('processActions', () => {
814
864
  const base: DocumentSet = {doc1: published}
815
865
  const working: DocumentSet = {doc1: published}
816
866
  const actions: DocumentAction[] = [
817
- {documentId: 'doc1', documentType: 'article', type: 'document.create'},
867
+ {
868
+ documentId: 'doc1',
869
+ documentType: 'article',
870
+ type: 'document.create',
871
+ resource: {projectId: 'p', dataset: 'd'},
872
+ },
818
873
  {
819
874
  documentId: 'doc1',
820
875
  documentType: 'article',
821
876
  type: 'document.edit',
822
877
  patches: [{set: {title: 'Edited Title'}}],
878
+ resource: {projectId: 'p', dataset: 'd'},
879
+ },
880
+ {
881
+ documentId: 'doc1',
882
+ documentType: 'article',
883
+ type: 'document.publish',
884
+ resource: {projectId: 'p', dataset: 'd'},
823
885
  },
824
- {documentId: 'doc1', documentType: 'article', type: 'document.publish'},
825
886
  ]
826
887
  const result = processActions({
827
888
  actions,
@@ -867,6 +928,7 @@ describe('processActions', () => {
867
928
  type: 'document.create',
868
929
  documentType: 'liveArticle',
869
930
  liveEdit: true,
931
+ resource: {projectId: 'p', dataset: 'd'},
870
932
  },
871
933
  ]
872
934
 
@@ -908,6 +970,7 @@ describe('processActions', () => {
908
970
  type: 'document.create',
909
971
  documentType: 'liveArticle',
910
972
  liveEdit: true,
973
+ resource: {projectId: 'p', dataset: 'd'},
911
974
  },
912
975
  ]
913
976
 
@@ -929,6 +992,7 @@ describe('processActions', () => {
929
992
  documentType: 'liveArticle',
930
993
  liveEdit: true,
931
994
  patches: [{set: {title: 'Updated Title'}}],
995
+ resource: {projectId: 'p', dataset: 'd'},
932
996
  },
933
997
  ]
934
998
 
@@ -964,6 +1028,7 @@ describe('processActions', () => {
964
1028
  documentType: 'liveArticle',
965
1029
  liveEdit: true,
966
1030
  patches: [{set: {title: 'New Title'}}],
1031
+ resource: {projectId: 'p', dataset: 'd'},
967
1032
  },
968
1033
  ]
969
1034
 
@@ -984,6 +1049,7 @@ describe('processActions', () => {
984
1049
  type: 'document.delete',
985
1050
  documentType: 'liveArticle',
986
1051
  liveEdit: true,
1052
+ resource: {projectId: 'p', dataset: 'd'},
987
1053
  },
988
1054
  ]
989
1055
 
@@ -1015,6 +1081,7 @@ describe('processActions', () => {
1015
1081
  type: 'document.delete',
1016
1082
  documentType: 'liveArticle',
1017
1083
  liveEdit: true,
1084
+ resource: {projectId: 'p', dataset: 'd'},
1018
1085
  },
1019
1086
  ]
1020
1087
 
@@ -1035,6 +1102,7 @@ describe('processActions', () => {
1035
1102
  type: 'document.publish',
1036
1103
  documentType: 'liveArticle',
1037
1104
  liveEdit: true,
1105
+ resource: {projectId: 'p', dataset: 'd'},
1038
1106
  },
1039
1107
  ]
1040
1108
 
@@ -1058,6 +1126,7 @@ describe('processActions', () => {
1058
1126
  type: 'document.unpublish',
1059
1127
  documentType: 'liveArticle',
1060
1128
  liveEdit: true,
1129
+ resource: {projectId: 'p', dataset: 'd'},
1061
1130
  },
1062
1131
  ]
1063
1132
 
@@ -1081,6 +1150,7 @@ describe('processActions', () => {
1081
1150
  type: 'document.discard',
1082
1151
  documentType: 'liveArticle',
1083
1152
  liveEdit: true,
1153
+ resource: {projectId: 'p', dataset: 'd'},
1084
1154
  },
1085
1155
  ]
1086
1156
 
@@ -56,6 +56,7 @@ describe('queueTransaction', () => {
56
56
  documentId: 'doc1',
57
57
  documentType: 'book',
58
58
  patches: [{set: {foo: 'bar'}}],
59
+ resource: {projectId: 'p', dataset: 'd'},
59
60
  },
60
61
  ],
61
62
  }
@@ -90,6 +91,7 @@ describe('removeQueuedTransaction', () => {
90
91
  documentId: 'doc1',
91
92
  documentType: 'book',
92
93
  patches: [{set: {foo: 'bar'}}],
94
+ resource: {projectId: 'p', dataset: 'd'},
93
95
  },
94
96
  ],
95
97
  },
@@ -143,7 +145,14 @@ describe('applyFirstQueuedTransaction', () => {
143
145
  queued: [
144
146
  {
145
147
  transactionId: 'txn2',
146
- actions: [{type: 'document.discard', documentId: 'doc1', documentType: 'book'}],
148
+ actions: [
149
+ {
150
+ type: 'document.discard',
151
+ documentId: 'doc1',
152
+ documentType: 'book',
153
+ resource: {projectId: 'p', dataset: 'd'},
154
+ },
155
+ ],
147
156
  },
148
157
  ],
149
158
  applied: [],
@@ -162,7 +171,14 @@ describe('applyFirstQueuedTransaction', () => {
162
171
  queued: [
163
172
  {
164
173
  transactionId: 'txn-missing-grants',
165
- actions: [{type: 'document.discard', documentId: 'doc1', documentType: 'book'}],
174
+ actions: [
175
+ {
176
+ type: 'document.discard',
177
+ documentId: 'doc1',
178
+ documentType: 'book',
179
+ resource: {projectId: 'p', dataset: 'd'},
180
+ },
181
+ ],
166
182
  },
167
183
  ],
168
184
  applied: [],
@@ -185,7 +201,14 @@ describe('applyFirstQueuedTransaction', () => {
185
201
  queued: [
186
202
  {
187
203
  transactionId: 'txn3',
188
- actions: [{type: 'document.discard', documentId: 'doc1', documentType: 'book'}],
204
+ actions: [
205
+ {
206
+ type: 'document.discard',
207
+ documentId: 'doc1',
208
+ documentType: 'book',
209
+ resource: {projectId: 'p', dataset: 'd'},
210
+ },
211
+ ],
189
212
  },
190
213
  ],
191
214
  applied: [],
@@ -224,12 +247,14 @@ describe('batchAppliedTransactions', () => {
224
247
  documentId: 'doc1',
225
248
  documentType: 'book',
226
249
  patches: [{set: {foo: 'a'}}],
250
+ resource: {projectId: 'p', dataset: 'd'},
227
251
  },
228
252
  {
229
253
  type: 'document.edit',
230
254
  documentId: 'doc1',
231
255
  documentType: 'book',
232
256
  patches: [{set: {bar: 'b'}}],
257
+ resource: {projectId: 'p', dataset: 'd'},
233
258
  },
234
259
  ],
235
260
  disableBatching: false,
@@ -265,6 +290,7 @@ describe('batchAppliedTransactions', () => {
265
290
  documentId: 'doc1',
266
291
  documentType: 'book',
267
292
  patches: [{set: {foo: 'a'}}],
293
+ resource: {projectId: 'p', dataset: 'd'},
268
294
  },
269
295
  ],
270
296
  disableBatching: false,
@@ -291,6 +317,7 @@ describe('batchAppliedTransactions', () => {
291
317
  documentId: 'doc1',
292
318
  documentType: 'book',
293
319
  patches: [{set: {bar: 'b'}}],
320
+ resource: {projectId: 'p', dataset: 'd'},
294
321
  },
295
322
  ],
296
323
  disableBatching: false,
@@ -331,6 +358,7 @@ describe('batchAppliedTransactions', () => {
331
358
  documentId: 'docA',
332
359
  documentType: 'book',
333
360
  patches: [{set: {foo: 'a'}}],
361
+ resource: {projectId: 'p', dataset: 'd'},
334
362
  },
335
363
  ],
336
364
  disableBatching: true, // already set to true
@@ -379,6 +407,7 @@ describe('transitionAppliedTransactionsToOutgoing', () => {
379
407
  documentId: 'doc1',
380
408
  documentType: 'book',
381
409
  patches: [{set: {foo: 'new'}}],
410
+ resource: {projectId: 'p', dataset: 'd'},
382
411
  },
383
412
  ],
384
413
  disableBatching: false,
@@ -439,6 +468,7 @@ describe('cleanupOutgoingTransaction', () => {
439
468
  documentId: 'doc1',
440
469
  documentType: 'book',
441
470
  patches: [{set: {foo: 'x'}}],
471
+ resource: {projectId: 'p', dataset: 'd'},
442
472
  },
443
473
  ],
444
474
  disableBatching: false,
@@ -481,6 +511,7 @@ describe('revertOutgoingTransaction', () => {
481
511
  documentId: 'doc1',
482
512
  documentType: 'book',
483
513
  patches: [{set: {foo: 'reverted'}}],
514
+ resource: {projectId: 'p', dataset: 'd'},
484
515
  },
485
516
  ],
486
517
  disableBatching: false,
@@ -501,6 +532,7 @@ describe('revertOutgoingTransaction', () => {
501
532
  documentId: 'doc1',
502
533
  documentType: 'book',
503
534
  patches: [{set: {foo: 'changed'}}],
535
+ resource: {projectId: 'p', dataset: 'd'},
504
536
  },
505
537
  ],
506
538
  disableBatching: false,
@@ -16,7 +16,7 @@ import {createSanityInstance} from '../store/createSanityInstance'
16
16
  import {type StateSource} from '../store/createStateSourceAction'
17
17
  import {createFetchDocument, createSharedListener} from './sharedListener'
18
18
 
19
- const instance = createSanityInstance({projectId: 'p', dataset: 'd'})
19
+ const instance = createSanityInstance()
20
20
 
21
21
  vi.mock('../client/clientStore.ts', () => ({getClientState: vi.fn()}))
22
22
  vi.mock('@sanity/mutate/_unstable_store', () => ({createDocumentLoaderFromClient: vi.fn()}))
@@ -43,7 +43,7 @@ describe('createSharedListener', () => {
43
43
  })
44
44
 
45
45
  it('should call client.listen with the expected parameters', () => {
46
- createSharedListener(instance).events.subscribe()
46
+ createSharedListener(instance, {projectId: 'p', dataset: 'd'}).events.subscribe()
47
47
  expect(fakeClient.listen).toHaveBeenCalledTimes(1)
48
48
  expect(fakeClient.listen).toHaveBeenCalledWith(
49
49
  '*',
@@ -62,7 +62,7 @@ describe('createSharedListener', () => {
62
62
  const mutationEvent: MutationEvent = {type: 'mutation'} as MutationEvent
63
63
  const reconnectEvent: ReconnectEvent = {type: 'reconnect'} as ReconnectEvent
64
64
 
65
- const sharedListener = createSharedListener(instance)
65
+ const sharedListener = createSharedListener(instance, {projectId: 'p', dataset: 'd'})
66
66
  // Start collecting the emitted events.
67
67
  const eventsPromise = lastValueFrom(sharedListener.events.pipe(toArray()))
68
68
 
@@ -80,7 +80,7 @@ describe('createSharedListener', () => {
80
80
  it('should replay the welcome event for new subscribers', async () => {
81
81
  const welcomeEvent: WelcomeEvent = {type: 'welcome', listenerName: 'listener'}
82
82
 
83
- const sharedListener = createSharedListener(instance)
83
+ const sharedListener = createSharedListener(instance, {projectId: 'p', dataset: 'd'})
84
84
  // First subscription: emit welcome and complete.
85
85
  const firstPromise = lastValueFrom(sharedListener.events.pipe(toArray()))
86
86
  fakeListenSubject.next(welcomeEvent)
@@ -97,7 +97,7 @@ describe('createSharedListener', () => {
97
97
  const mutationEvent = {type: 'mutation'} as MutationEvent
98
98
  const reconnectEvent = {type: 'reconnect'} as ReconnectEvent
99
99
 
100
- const sharedListener = createSharedListener(instance)
100
+ const sharedListener = createSharedListener(instance, {projectId: 'p', dataset: 'd'})
101
101
  const eventsPromise = lastValueFrom(sharedListener.events.pipe(toArray()))
102
102
  fakeListenSubject.next(mutationEvent)
103
103
  fakeListenSubject.next(reconnectEvent)
@@ -110,7 +110,7 @@ describe('createSharedListener', () => {
110
110
  const welcomeEvent = {type: 'welcome'} as WelcomeEvent
111
111
  const mutationEvent = {type: 'mutation'} as MutationEvent
112
112
 
113
- const sharedListener = createSharedListener(instance)
113
+ const sharedListener = createSharedListener(instance, {projectId: 'p', dataset: 'd'})
114
114
 
115
115
  // Subscribe two observers concurrently.
116
116
  const subscriber1 = sharedListener.events.pipe(bufferTime(0))
@@ -133,7 +133,7 @@ describe('createSharedListener', () => {
133
133
 
134
134
  it('should propagate errors from the underlying client.listen observable', async () => {
135
135
  const errorMessage = 'Test error'
136
- const sharedListener = createSharedListener(instance)
136
+ const sharedListener = createSharedListener(instance, {projectId: 'p', dataset: 'd'})
137
137
 
138
138
  const error$ = sharedListener.events.pipe(
139
139
  toArray(),
@@ -149,7 +149,7 @@ describe('createSharedListener', () => {
149
149
  it('should stop emitting events after calling dispose', async () => {
150
150
  const welcomeEvent: WelcomeEvent = {type: 'welcome', listenerName: 'listener'}
151
151
  const mutationEvent: MutationEvent = {type: 'mutation'} as MutationEvent
152
- const sharedListener = createSharedListener(instance)
152
+ const sharedListener = createSharedListener(instance, {projectId: 'p', dataset: 'd'})
153
153
 
154
154
  const events: ListenEvent<SanityDocument>[] = []
155
155
  const subscription = sharedListener.events.subscribe((event) => {
@@ -187,7 +187,7 @@ describe('createFetchDocument', () => {
187
187
  })
188
188
 
189
189
  it('should call createDocumentLoaderFromClient with the fetched client', async () => {
190
- const fetchDocument = createFetchDocument(instance)
190
+ const fetchDocument = createFetchDocument(instance, {projectId: 'p', dataset: 'd'})
191
191
  const accessibleResult = {
192
192
  id: 'doc1',
193
193
  document: {_id: 'doc1', _rev: 'rev1'},
@@ -201,7 +201,7 @@ describe('createFetchDocument', () => {
201
201
  })
202
202
 
203
203
  it('should return the document when it is accessible', async () => {
204
- const fetchDocument = createFetchDocument(instance)
204
+ const fetchDocument = createFetchDocument(instance, {projectId: 'p', dataset: 'd'})
205
205
  const accessibleResult = {
206
206
  id: 'doc1',
207
207
  document: {_id: 'doc1', _rev: 'rev1', title: 'Test Document'},
@@ -214,7 +214,7 @@ describe('createFetchDocument', () => {
214
214
  })
215
215
 
216
216
  it('should return null when the document is inaccessible due to existence', async () => {
217
- const fetchDocument = createFetchDocument(instance)
217
+ const fetchDocument = createFetchDocument(instance, {projectId: 'p', dataset: 'd'})
218
218
  const inaccessibleResult = {
219
219
  accessible: false,
220
220
  id: 'doc1',
@@ -227,7 +227,7 @@ describe('createFetchDocument', () => {
227
227
  })
228
228
 
229
229
  it('should throw an error when the document is inaccessible due to permissions', async () => {
230
- const fetchDocument = createFetchDocument(instance)
230
+ const fetchDocument = createFetchDocument(instance, {projectId: 'p', dataset: 'd'})
231
231
  const inaccessibleResult = {
232
232
  accessible: false,
233
233
  id: 'doc1',
@@ -241,7 +241,7 @@ describe('createFetchDocument', () => {
241
241
  })
242
242
 
243
243
  it('should propagate errors from the loadDocument observable', async () => {
244
- const fetchDocument = createFetchDocument(instance)
244
+ const fetchDocument = createFetchDocument(instance, {projectId: 'p', dataset: 'd'})
245
245
  const errorMessage = 'Load document failed'
246
246
  fakeLoadDocument.mockReturnValue(throwError(() => new Error(errorMessage)))
247
247
 
@@ -14,6 +14,7 @@ import {
14
14
  } from 'rxjs'
15
15
 
16
16
  import {getClientState} from '../client/clientStore'
17
+ import {type DocumentResource} from '../config/sanityConfig'
17
18
  import {type SanityInstance} from '../store/createSanityInstance'
18
19
 
19
20
  const API_VERSION = 'v2025-05-06'
@@ -23,10 +24,14 @@ export interface SharedListener {
23
24
  dispose: () => void
24
25
  }
25
26
 
26
- export function createSharedListener(instance: SanityInstance): SharedListener {
27
+ export function createSharedListener(
28
+ instance: SanityInstance,
29
+ resource: DocumentResource,
30
+ ): SharedListener {
27
31
  const dispose$ = new Subject<void>()
28
32
  const events$ = getClientState(instance, {
29
33
  apiVersion: API_VERSION,
34
+ ...(resource ? {resource} : {}),
30
35
  }).observable.pipe(
31
36
  switchMap((client) =>
32
37
  // TODO: it seems like the client.listen method is not emitting disconnected
@@ -62,9 +67,9 @@ export function createSharedListener(instance: SanityInstance): SharedListener {
62
67
  }
63
68
  }
64
69
 
65
- export function createFetchDocument(instance: SanityInstance) {
70
+ export function createFetchDocument(instance: SanityInstance, resource: DocumentResource) {
66
71
  return function (documentId: string): Observable<SanityDocument | null> {
67
- return getClientState(instance, {apiVersion: API_VERSION}).observable.pipe(
72
+ return getClientState(instance, {apiVersion: API_VERSION, resource}).observable.pipe(
68
73
  switchMap((client) => {
69
74
  // TODO: remove this once the client is updated to v7 the new type is available in @sanity/mutate/_unstable_store
70
75
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -39,6 +39,7 @@ describe('favoritesStore', () => {
39
39
  resourceId: 'res456',
40
40
  resourceType: 'studio' as const,
41
41
  schemaName: 'movieSchema',
42
+ resource: {projectId: 'p', dataset: 'd'},
42
43
  }
43
44
 
44
45
  const mockContextNoSchema = {
@@ -46,12 +47,13 @@ describe('favoritesStore', () => {
46
47
  documentType: 'movie',
47
48
  resourceId: 'res456',
48
49
  resourceType: 'studio' as const,
50
+ resource: {projectId: 'p', dataset: 'd'},
49
51
  }
50
52
 
51
53
  describe('createFavoriteKey', () => {
52
54
  beforeEach(() => {
53
55
  vi.resetAllMocks()
54
- instance = createSanityInstance({projectId: 'p', dataset: 'd'})
56
+ instance = createSanityInstance()
55
57
  setupMockStateSource()
56
58
  })
57
59
 
@@ -99,7 +101,7 @@ describe('favoritesStore', () => {
99
101
  describe('fetcher', () => {
100
102
  beforeEach(() => {
101
103
  vi.resetAllMocks()
102
- instance = createSanityInstance({projectId: 'p', dataset: 'd'})
104
+ instance = createSanityInstance()
103
105
  setupMockStateSource()
104
106
  })
105
107
 
@@ -126,9 +128,15 @@ describe('favoritesStore', () => {
126
128
  })
127
129
 
128
130
  it('handles error and returns default response', async () => {
131
+ const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
129
132
  setupMockStateSource({fetchImpl: vi.fn().mockRejectedValue(new Error('Failed to fetch'))})
130
133
  const result = await resolveFavoritesState(instance!, mockContext)
131
134
  expect(result).toEqual({isFavorited: false})
135
+ expect(consoleErrorSpy).toHaveBeenCalledWith(
136
+ 'Favorites service connection error',
137
+ expect.any(Error),
138
+ )
139
+ consoleErrorSpy.mockRestore()
132
140
  })
133
141
 
134
142
  it('shares observable between multiple subscribers and cleans up', async () => {