@sanity/sdk 2.9.0 → 2.11.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 (73) hide show
  1. package/dist/_chunks-dts/utils.d.ts +295 -69
  2. package/dist/_chunks-es/_internal.js +3 -14
  3. package/dist/_chunks-es/_internal.js.map +1 -1
  4. package/dist/_chunks-es/createGroqSearchFilter.js +129 -59
  5. package/dist/_chunks-es/createGroqSearchFilter.js.map +1 -1
  6. package/dist/_chunks-es/version.js +1 -1
  7. package/dist/_exports/_internal.d.ts +16 -2
  8. package/dist/_exports/_internal.js +3 -1
  9. package/dist/index.d.ts +2 -2
  10. package/dist/index.js +275 -149
  11. package/dist/index.js.map +1 -1
  12. package/package.json +11 -15
  13. package/src/_exports/_internal.ts +1 -0
  14. package/src/_exports/index.ts +33 -2
  15. package/src/agent/agentActions.ts +21 -25
  16. package/src/client/clientStore.test.ts +24 -60
  17. package/src/client/clientStore.ts +49 -56
  18. package/src/comlink/controller/actions/getOrCreateChannel.ts +2 -2
  19. package/src/comlink/node/actions/getOrCreateNode.test.ts +5 -2
  20. package/src/comlink/node/actions/getOrCreateNode.ts +2 -2
  21. package/src/comlink/node/actions/releaseNode.test.ts +3 -3
  22. package/src/config/sanityConfig.ts +72 -13
  23. package/src/document/applyDocumentActions.test.ts +7 -7
  24. package/src/document/applyDocumentActions.ts +5 -5
  25. package/src/document/documentStore.test.ts +68 -62
  26. package/src/document/documentStore.ts +33 -38
  27. package/src/document/processActions.ts +2 -2
  28. package/src/document/reducers.ts +4 -4
  29. package/src/document/sharedListener.ts +5 -7
  30. package/src/organization/organization.test-d.ts +102 -0
  31. package/src/organization/organization.test.ts +138 -0
  32. package/src/organization/organization.ts +166 -0
  33. package/src/organizations/organizations.test-d.ts +77 -0
  34. package/src/organizations/organizations.test.ts +150 -0
  35. package/src/organizations/organizations.ts +132 -0
  36. package/src/presence/bifurTransport.test.ts +46 -6
  37. package/src/presence/bifurTransport.ts +13 -1
  38. package/src/presence/presenceStore.test.ts +101 -5
  39. package/src/presence/presenceStore.ts +96 -24
  40. package/src/preview/getPreviewState.ts +1 -1
  41. package/src/preview/previewProjectionUtils.test.ts +4 -4
  42. package/src/preview/previewProjectionUtils.ts +6 -7
  43. package/src/preview/resolvePreview.ts +5 -1
  44. package/src/project/project.test-d.ts +93 -0
  45. package/src/project/project.test.ts +108 -10
  46. package/src/project/project.ts +152 -26
  47. package/src/projection/getProjectionState.ts +4 -4
  48. package/src/projection/projectionStore.test.ts +2 -2
  49. package/src/projection/resolveProjection.ts +2 -2
  50. package/src/projection/subscribeToStateAndFetchBatches.test.ts +1 -1
  51. package/src/projection/subscribeToStateAndFetchBatches.ts +11 -15
  52. package/src/projects/projects.test-d.ts +38 -0
  53. package/src/projects/projects.test.ts +104 -38
  54. package/src/projects/projects.ts +74 -14
  55. package/src/query/queryStore.test.ts +12 -12
  56. package/src/query/queryStore.ts +10 -11
  57. package/src/query/reducers.ts +3 -3
  58. package/src/releases/getPerspectiveState.ts +5 -5
  59. package/src/releases/releasesStore.test.ts +6 -6
  60. package/src/releases/releasesStore.ts +9 -9
  61. package/src/store/createActionBinder.test.ts +31 -31
  62. package/src/store/createActionBinder.ts +43 -38
  63. package/src/store/createSanityInstance.ts +5 -6
  64. package/src/telemetry/devMode.test.ts +8 -0
  65. package/src/telemetry/devMode.ts +10 -9
  66. package/src/telemetry/initTelemetry.test.ts +0 -17
  67. package/src/telemetry/initTelemetry.ts +2 -12
  68. package/src/users/reducers.ts +3 -4
  69. package/src/utils/createFetcherStore.ts +6 -4
  70. package/src/utils/isImportError.test.ts +72 -0
  71. package/src/utils/isImportError.ts +34 -0
  72. package/src/utils/object.test.ts +95 -0
  73. package/src/utils/object.ts +142 -0
@@ -73,9 +73,14 @@ export interface DatasetHandle<TDataset extends string = string, TProjectId exte
73
73
  dataset?: TDataset
74
74
  /**
75
75
  * @beta
76
- * Explicit source object to use for this operation.
76
+ * Explicit resource object to use for this operation.
77
77
  */
78
- source?: DocumentSource
78
+ resource?: DocumentResource
79
+ /**
80
+ * @deprecated Use `resource` instead.
81
+ * @beta
82
+ */
83
+ source?: DocumentResource
79
84
  }
80
85
 
81
86
  /**
@@ -120,7 +125,6 @@ export interface DocumentHandle<
120
125
  export interface SanityConfig extends DatasetHandle, PerspectiveHandle {
121
126
  /**
122
127
  * Authentication configuration for the instance
123
- * @remarks Merged with parent configurations when using createChild
124
128
  */
125
129
  auth?: AuthConfig
126
130
  /**
@@ -145,51 +149,106 @@ export interface SanityConfig extends DatasetHandle, PerspectiveHandle {
145
149
 
146
150
  /**
147
151
  * @beta
148
- * A list of named sources to use for this instance.
152
+ * A list of named resources to use for this instance.
153
+ */
154
+ resources?: Record<string, DocumentResource>
155
+ /**
156
+ * @deprecated Use `resources` instead.
157
+ * @beta
149
158
  */
150
- sources?: Record<string, DocumentSource>
159
+ sources?: Record<string, DocumentResource>
151
160
  }
152
161
 
153
162
  /**
154
- * A document source can be used for querying.
163
+ * A document resource can be used for querying.
155
164
  * This will soon be the default way to identify where you are querying from.
156
165
  *
157
166
  * @beta
158
167
  */
159
- export type DocumentSource = DatasetSource | MediaLibrarySource | CanvasSource
168
+ export type DocumentResource = DatasetResource | MediaLibraryResource | CanvasResource
169
+
170
+ /**
171
+ * @beta
172
+ */
173
+ export type DatasetResource = {projectId: string; dataset: string}
174
+
175
+ /**
176
+ * @beta
177
+ */
178
+ export type MediaLibraryResource = {mediaLibraryId: string}
179
+
180
+ /**
181
+ * @beta
182
+ */
183
+ export type CanvasResource = {canvasId: string}
184
+
185
+ /**
186
+ * @beta
187
+ */
188
+ export function isDatasetResource(resource: DocumentResource): resource is DatasetResource {
189
+ return 'projectId' in resource && 'dataset' in resource
190
+ }
191
+
192
+ /**
193
+ * @beta
194
+ */
195
+ export function isMediaLibraryResource(
196
+ resource: DocumentResource,
197
+ ): resource is MediaLibraryResource {
198
+ return 'mediaLibraryId' in resource
199
+ }
200
+
201
+ /**
202
+ * @beta
203
+ */
204
+ export function isCanvasResource(resource: DocumentResource): resource is CanvasResource {
205
+ return 'canvasId' in resource
206
+ }
207
+
208
+ /**
209
+ * @deprecated Use `DocumentResource` instead.
210
+ * @beta
211
+ */
212
+ export type DocumentSource = DocumentResource
160
213
 
161
214
  /**
215
+ * @deprecated Use `DatasetResource` instead.
162
216
  * @beta
163
217
  */
164
- export type DatasetSource = {projectId: string; dataset: string}
218
+ export type DatasetSource = DatasetResource
165
219
 
166
220
  /**
221
+ * @deprecated Use `MediaLibraryResource` instead.
167
222
  * @beta
168
223
  */
169
- export type MediaLibrarySource = {mediaLibraryId: string}
224
+ export type MediaLibrarySource = MediaLibraryResource
170
225
 
171
226
  /**
227
+ * @deprecated Use `CanvasResource` instead.
172
228
  * @beta
173
229
  */
174
- export type CanvasSource = {canvasId: string}
230
+ export type CanvasSource = CanvasResource
175
231
 
176
232
  /**
233
+ * @deprecated Use `isDatasetResource` instead.
177
234
  * @beta
178
235
  */
179
236
  export function isDatasetSource(source: DocumentSource): source is DatasetSource {
180
- return 'projectId' in source && 'dataset' in source
237
+ return isDatasetResource(source)
181
238
  }
182
239
 
183
240
  /**
241
+ * @deprecated Use `isMediaLibraryResource` instead.
184
242
  * @beta
185
243
  */
186
244
  export function isMediaLibrarySource(source: DocumentSource): source is MediaLibrarySource {
187
- return 'mediaLibraryId' in source
245
+ return isMediaLibraryResource(source)
188
246
  }
189
247
 
190
248
  /**
249
+ * @deprecated Use `isCanvasResource` instead.
191
250
  * @beta
192
251
  */
193
252
  export function isCanvasSource(source: DocumentSource): source is CanvasSource {
194
- return 'canvasId' in source
253
+ return isCanvasResource(source)
195
254
  }
@@ -2,7 +2,7 @@ import {type SanityDocument} from '@sanity/types'
2
2
  import {Subject} from 'rxjs'
3
3
  import {describe, expect, it} from 'vitest'
4
4
 
5
- import {bindActionBySource} from '../store/createActionBinder'
5
+ import {bindActionByResource} from '../store/createActionBinder'
6
6
  import {createSanityInstance, type SanityInstance} from '../store/createSanityInstance'
7
7
  import {createStoreState, type StoreState} from '../store/createStoreState'
8
8
  import {type DocumentAction} from './actions'
@@ -12,7 +12,7 @@ import {type AppliedTransaction, type OutgoingTransaction} from './reducers'
12
12
 
13
13
  vi.mock('../store/createActionBinder', async (importOriginal) => ({
14
14
  ...(await importOriginal<typeof import('../store/createActionBinder')>()),
15
- bindActionBySource: vi.fn(),
15
+ bindActionByResource: vi.fn(),
16
16
  }))
17
17
 
18
18
  type TestState = Pick<
@@ -46,9 +46,9 @@ describe('applyDocumentActions', () => {
46
46
  }
47
47
  state = createStoreState(initialState)
48
48
  instance = createSanityInstance({projectId: 'p', dataset: 'd'})
49
- const key = {name: 'p.d', source: {projectId: 'p', dataset: 'd'}}
49
+ const key = {name: 'p.d', resource: {projectId: 'p', dataset: 'd'}}
50
50
 
51
- vi.mocked(bindActionBySource).mockImplementation(
51
+ vi.mocked(bindActionByResource).mockImplementation(
52
52
  (_storeDef, action) => (instanceParam: SanityInstance, options) =>
53
53
  action({instance: instanceParam, state, key}, options),
54
54
  )
@@ -73,7 +73,7 @@ describe('applyDocumentActions', () => {
73
73
  const applyPromise = applyDocumentActions(instance, {
74
74
  actions: [action],
75
75
  transactionId: 'txn-success',
76
- source: {projectId: 'p', dataset: 'd'},
76
+ resource: {projectId: 'p', dataset: 'd'},
77
77
  })
78
78
 
79
79
  const appliedTx: AppliedTransaction = {
@@ -131,7 +131,7 @@ describe('applyDocumentActions', () => {
131
131
  const applyPromise = applyDocumentActions(instance, {
132
132
  actions: [action],
133
133
  transactionId: 'txn-error',
134
- source: {projectId: 'p', dataset: 'd'},
134
+ resource: {projectId: 'p', dataset: 'd'},
135
135
  })
136
136
 
137
137
  const errorEvent: DocumentEvent = {
@@ -165,7 +165,7 @@ describe('applyDocumentActions', () => {
165
165
  const applyPromise = applyDocumentActions(childInstance, {
166
166
  actions: [action],
167
167
  transactionId: 'txn-child-match',
168
- source: {projectId: 'p', dataset: 'd'},
168
+ resource: {projectId: 'p', dataset: 'd'},
169
169
  })
170
170
 
171
171
  // Simulate an applied transaction on the parent's instance
@@ -1,8 +1,8 @@
1
1
  import {type SanityDocument} from 'groq'
2
2
  import {distinctUntilChanged, filter, first, firstValueFrom, map, race} from 'rxjs'
3
3
 
4
- import {type DocumentSource} from '../config/sanityConfig'
5
- import {bindActionBySource} from '../store/createActionBinder'
4
+ import {type DocumentResource} from '../config/sanityConfig'
5
+ import {bindActionByResource} from '../store/createActionBinder'
6
6
  import {type SanityInstance} from '../store/createSanityInstance'
7
7
  import {type StoreContext} from '../store/defineStore'
8
8
  import {type DocumentAction} from './actions'
@@ -31,9 +31,9 @@ export interface ApplyDocumentActionsOptions {
31
31
  actions: DocumentAction[]
32
32
 
33
33
  /**
34
- * The source to which the documents being acted on belong.
34
+ * The resource to which the documents being acted on belong.
35
35
  */
36
- source?: DocumentSource
36
+ resource?: DocumentResource
37
37
 
38
38
  /**
39
39
  * Optionally provide an ID to be used as this transaction ID
@@ -67,7 +67,7 @@ export function applyDocumentActions(
67
67
  return boundApplyDocumentActions(...args)
68
68
  }
69
69
 
70
- const boundApplyDocumentActions = bindActionBySource(documentStore, _applyDocumentActions)
70
+ const boundApplyDocumentActions = bindActionByResource(documentStore, _applyDocumentActions)
71
71
 
72
72
  /** @internal */
73
73
  async function _applyDocumentActions(