@sanity/sdk 0.0.0-alpha.21 → 0.0.0-alpha.23

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 (127) hide show
  1. package/dist/index.d.ts +428 -325
  2. package/dist/index.js +1618 -1553
  3. package/dist/index.js.map +1 -1
  4. package/package.json +6 -7
  5. package/src/_exports/index.ts +31 -30
  6. package/src/auth/authStore.test.ts +149 -104
  7. package/src/auth/authStore.ts +51 -100
  8. package/src/auth/handleAuthCallback.test.ts +67 -34
  9. package/src/auth/handleAuthCallback.ts +8 -7
  10. package/src/auth/logout.test.ts +61 -29
  11. package/src/auth/logout.ts +26 -28
  12. package/src/auth/refreshStampedToken.test.ts +9 -9
  13. package/src/auth/refreshStampedToken.ts +62 -56
  14. package/src/auth/subscribeToStateAndFetchCurrentUser.test.ts +5 -5
  15. package/src/auth/subscribeToStateAndFetchCurrentUser.ts +45 -47
  16. package/src/auth/subscribeToStorageEventsAndSetToken.test.ts +4 -5
  17. package/src/auth/subscribeToStorageEventsAndSetToken.ts +22 -24
  18. package/src/client/clientStore.test.ts +131 -67
  19. package/src/client/clientStore.ts +117 -116
  20. package/src/comlink/controller/actions/destroyController.test.ts +38 -13
  21. package/src/comlink/controller/actions/destroyController.ts +11 -15
  22. package/src/comlink/controller/actions/getOrCreateChannel.test.ts +56 -27
  23. package/src/comlink/controller/actions/getOrCreateChannel.ts +37 -35
  24. package/src/comlink/controller/actions/getOrCreateController.test.ts +27 -16
  25. package/src/comlink/controller/actions/getOrCreateController.ts +23 -22
  26. package/src/comlink/controller/actions/releaseChannel.test.ts +37 -13
  27. package/src/comlink/controller/actions/releaseChannel.ts +22 -21
  28. package/src/comlink/controller/comlinkControllerStore.test.ts +65 -36
  29. package/src/comlink/controller/comlinkControllerStore.ts +44 -5
  30. package/src/comlink/node/actions/getOrCreateNode.test.ts +31 -15
  31. package/src/comlink/node/actions/getOrCreateNode.ts +30 -29
  32. package/src/comlink/node/actions/releaseNode.test.ts +75 -55
  33. package/src/comlink/node/actions/releaseNode.ts +19 -21
  34. package/src/comlink/node/comlinkNodeStore.test.ts +6 -11
  35. package/src/comlink/node/comlinkNodeStore.ts +22 -5
  36. package/src/config/authConfig.ts +79 -0
  37. package/src/config/sanityConfig.ts +48 -0
  38. package/src/datasets/datasets.test.ts +2 -2
  39. package/src/datasets/datasets.ts +18 -5
  40. package/src/document/actions.test.ts +22 -10
  41. package/src/document/actions.ts +44 -56
  42. package/src/document/applyDocumentActions.test.ts +96 -36
  43. package/src/document/applyDocumentActions.ts +140 -99
  44. package/src/document/documentStore.test.ts +103 -155
  45. package/src/document/documentStore.ts +247 -237
  46. package/src/document/listen.ts +56 -55
  47. package/src/document/patchOperations.ts +0 -43
  48. package/src/document/permissions.test.ts +25 -12
  49. package/src/document/permissions.ts +11 -4
  50. package/src/document/processActions.test.ts +41 -8
  51. package/src/document/reducers.test.ts +87 -16
  52. package/src/document/reducers.ts +2 -2
  53. package/src/document/sharedListener.test.ts +34 -16
  54. package/src/document/sharedListener.ts +33 -11
  55. package/src/preview/getPreviewState.test.ts +40 -39
  56. package/src/preview/getPreviewState.ts +68 -56
  57. package/src/preview/previewConstants.ts +43 -0
  58. package/src/preview/previewQuery.test.ts +1 -1
  59. package/src/preview/previewQuery.ts +4 -5
  60. package/src/preview/previewStore.test.ts +13 -58
  61. package/src/preview/previewStore.ts +7 -21
  62. package/src/preview/resolvePreview.test.ts +33 -104
  63. package/src/preview/resolvePreview.ts +11 -21
  64. package/src/preview/subscribeToStateAndFetchBatches.test.ts +96 -97
  65. package/src/preview/subscribeToStateAndFetchBatches.ts +85 -81
  66. package/src/preview/util.ts +1 -0
  67. package/src/project/project.test.ts +3 -3
  68. package/src/project/project.ts +28 -5
  69. package/src/projection/getProjectionState.test.ts +69 -49
  70. package/src/projection/getProjectionState.ts +42 -50
  71. package/src/projection/projectionQuery.ts +1 -1
  72. package/src/projection/projectionStore.test.ts +13 -51
  73. package/src/projection/projectionStore.ts +6 -18
  74. package/src/projection/resolveProjection.test.ts +32 -127
  75. package/src/projection/resolveProjection.ts +15 -28
  76. package/src/projection/subscribeToStateAndFetchBatches.test.ts +105 -90
  77. package/src/projection/subscribeToStateAndFetchBatches.ts +94 -81
  78. package/src/projection/util.ts +2 -0
  79. package/src/projects/projects.test.ts +13 -4
  80. package/src/projects/projects.ts +6 -1
  81. package/src/query/queryStore.test.ts +10 -47
  82. package/src/query/queryStore.ts +151 -133
  83. package/src/query/queryStoreConstants.ts +2 -0
  84. package/src/store/createActionBinder.test.ts +153 -0
  85. package/src/store/createActionBinder.ts +176 -0
  86. package/src/store/createSanityInstance.test.ts +84 -0
  87. package/src/store/createSanityInstance.ts +124 -0
  88. package/src/store/createStateSourceAction.test.ts +196 -0
  89. package/src/store/createStateSourceAction.ts +260 -0
  90. package/src/store/createStoreInstance.test.ts +81 -0
  91. package/src/store/createStoreInstance.ts +80 -0
  92. package/src/store/createStoreState.test.ts +85 -0
  93. package/src/store/createStoreState.ts +92 -0
  94. package/src/store/defineStore.test.ts +18 -0
  95. package/src/store/defineStore.ts +81 -0
  96. package/src/users/reducers.test.ts +318 -0
  97. package/src/users/reducers.ts +88 -0
  98. package/src/users/types.ts +46 -4
  99. package/src/users/usersConstants.ts +4 -0
  100. package/src/users/usersStore.test.ts +350 -223
  101. package/src/users/usersStore.ts +285 -149
  102. package/src/utils/createFetcherStore.test.ts +6 -7
  103. package/src/utils/createFetcherStore.ts +150 -153
  104. package/src/{common/util.test.ts → utils/hashString.test.ts} +1 -1
  105. package/src/auth/fetchLoginUrls.test.ts +0 -163
  106. package/src/auth/fetchLoginUrls.ts +0 -74
  107. package/src/common/createLiveEventSubscriber.test.ts +0 -121
  108. package/src/common/createLiveEventSubscriber.ts +0 -55
  109. package/src/common/types.ts +0 -4
  110. package/src/instance/identity.test.ts +0 -46
  111. package/src/instance/identity.ts +0 -29
  112. package/src/instance/sanityInstance.test.ts +0 -77
  113. package/src/instance/sanityInstance.ts +0 -57
  114. package/src/instance/types.ts +0 -37
  115. package/src/preview/getPreviewProjection.ts +0 -45
  116. package/src/resources/README.md +0 -370
  117. package/src/resources/createAction.test.ts +0 -101
  118. package/src/resources/createAction.ts +0 -44
  119. package/src/resources/createResource.test.ts +0 -112
  120. package/src/resources/createResource.ts +0 -102
  121. package/src/resources/createStateSourceAction.test.ts +0 -114
  122. package/src/resources/createStateSourceAction.ts +0 -83
  123. package/src/resources/createStore.test.ts +0 -67
  124. package/src/resources/createStore.ts +0 -46
  125. package/src/store/createStore.test.ts +0 -108
  126. package/src/store/createStore.ts +0 -106
  127. /package/src/{common/util.ts → utils/hashString.ts} +0 -0
@@ -16,7 +16,7 @@ import {
16
16
  } from 'rxjs'
17
17
  import {mergeMap, scan} from 'rxjs/operators'
18
18
 
19
- import {type ActionContext, createInternalAction} from '../resources/createAction'
19
+ import {type StoreContext} from '../store/defineStore'
20
20
  import {type DocumentStoreState} from './documentStore'
21
21
  import {processMutations} from './processMutations'
22
22
 
@@ -193,65 +193,66 @@ export function sortListenerEvents(options?: SortListenerEventsOptions) {
193
193
  }
194
194
  }
195
195
 
196
- export const listen = createInternalAction(({state}: ActionContext<DocumentStoreState>) => {
196
+ export const listen = (
197
+ {state}: StoreContext<DocumentStoreState>,
198
+ documentId: string,
199
+ ): Observable<RemoteDocument> => {
197
200
  const {sharedListener, fetchDocument} = state.get()
198
201
 
199
- return function (documentId: string) {
200
- return sharedListener.pipe(
201
- concatMap((e) => {
202
- if (e.type === 'welcome') {
203
- return fetchDocument(documentId).pipe(
204
- map((document): SyncEvent => ({type: 'sync', document})),
205
- )
206
- }
207
- if (e.type === 'mutation' && e.documentId === documentId) return of(e)
208
- return EMPTY
209
- }),
210
- sortListenerEvents(),
211
- withLatestFrom(
212
- state.observable.pipe(
213
- map((s) => s.documentStates[documentId]),
214
- filter(Boolean),
215
- distinctUntilChanged(),
216
- ),
202
+ return sharedListener.events.pipe(
203
+ concatMap((e) => {
204
+ if (e.type === 'welcome') {
205
+ return fetchDocument(documentId).pipe(
206
+ map((document): SyncEvent => ({type: 'sync', document})),
207
+ )
208
+ }
209
+ if (e.type === 'mutation' && e.documentId === documentId) return of(e)
210
+ return EMPTY
211
+ }),
212
+ sortListenerEvents(),
213
+ withLatestFrom(
214
+ state.observable.pipe(
215
+ map((s) => s.documentStates[documentId]),
216
+ filter(Boolean),
217
+ distinctUntilChanged(),
217
218
  ),
218
- map(([next, documentState]): RemoteDocument => {
219
- if (next.type === 'sync') {
220
- return {
221
- type: 'sync',
222
- documentId,
223
- document: next.document,
224
- revision: next.document?._rev,
225
- timestamp: next.document?._updatedAt ?? new Date().toISOString(),
226
- }
219
+ ),
220
+ map(([next, documentState]): RemoteDocument => {
221
+ if (next.type === 'sync') {
222
+ return {
223
+ type: 'sync',
224
+ documentId,
225
+ document: next.document,
226
+ revision: next.document?._rev,
227
+ timestamp: next.document?._updatedAt ?? new Date().toISOString(),
227
228
  }
229
+ }
228
230
 
229
- // TODO: from manual testing, mendoza patches seem to be applying
230
- // let document
231
- // if (next.effects?.apply) {
232
- // document = applyPatch(omit(documentState.remote, '_rev'), next.effects?.apply)
233
- // }
231
+ // TODO: from manual testing, mendoza patches seem to be applying
232
+ // let document
233
+ // if (next.effects?.apply) {
234
+ // document = applyPatch(omit(documentState.remote, '_rev'), next.effects?.apply)
235
+ // }
234
236
 
235
- const [document] = Object.values(
236
- processMutations({
237
- documents: {[documentId]: documentState.remote},
238
- mutations: next.mutations as Mutation[],
239
- transactionId: next.transactionId,
240
- timestamp: next.timestamp,
241
- }),
242
- )
237
+ const [document] = Object.values(
238
+ processMutations({
239
+ documents: {[documentId]: documentState.remote},
240
+ mutations: next.mutations as Mutation[],
241
+ transactionId: next.transactionId,
242
+ timestamp: next.timestamp,
243
+ }),
244
+ )
243
245
 
244
- const {previousRev, transactionId, timestamp} = next
246
+ const {previousRev, transactionId, timestamp} = next
245
247
 
246
- return {
247
- type: 'mutation',
248
- documentId,
249
- document: document ?? null,
250
- revision: transactionId,
251
- timestamp,
252
- ...(previousRev && {previousRev}),
253
- }
254
- }),
255
- )
256
- }
257
- })
248
+ return {
249
+ type: 'mutation',
250
+ documentId,
251
+ document: document ?? null,
252
+ revision: transactionId,
253
+ timestamp,
254
+ ...(previousRev && {previousRev}),
255
+ }
256
+ }),
257
+ )
258
+ }
@@ -12,49 +12,6 @@ import {
12
12
 
13
13
  type SingleValuePath = Exclude<PathSegment, IndexTuple>[]
14
14
 
15
- /**
16
- * @beta
17
- * A minimal set of metadata for a given document, comprising the document's ID and type.
18
- * Used by most document-related hooks (such as {@link usePreview}, {@link useDocument}, and {@link useEditDocument})
19
- * to reference a particular document without fetching the entire document upfront.
20
- * @category Types
21
- */
22
- export interface DocumentHandle<TDocument extends SanityDocumentLike = SanityDocumentLike> {
23
- _id: string
24
- _type: TDocument['_type']
25
- resourceId?: DocumentResourceId
26
- }
27
-
28
- /**
29
- * @beta
30
- * A resource identifier for a document, in the format of `document:${projectId}.${dataset}:${documentId}`
31
- */
32
- export type DocumentResourceId = `document:${string}.${string}:${string}`
33
-
34
- /**
35
- * @public
36
- * A resource identifier for a document, in the format of `projectId.dataset`
37
- */
38
- export type ResourceId = `${string}.${string}`
39
-
40
- /**
41
- * @beta
42
- * Get the resource ID from a document resource ID
43
- */
44
- export function getResourceId(
45
- documentResourceId: DocumentResourceId | undefined,
46
- ): ResourceId | undefined {
47
- if (!documentResourceId) return undefined
48
- return documentResourceId.split(':')[1] as ResourceId
49
- }
50
-
51
- /** @beta */
52
- export interface DocumentTypeHandle<TDocument extends SanityDocumentLike = SanityDocumentLike> {
53
- _id?: string
54
- _type: TDocument['_type']
55
- resourceId?: DocumentResourceId
56
- }
57
-
58
15
  type ToNumber<TInput extends string> = TInput extends `${infer TNumber extends number}`
59
16
  ? TNumber
60
17
  : TInput
@@ -2,12 +2,19 @@ import {type SanityDocument} from '@sanity/types'
2
2
  import {type ExprNode} from 'groq-js'
3
3
  import {describe, expect, it} from 'vitest'
4
4
 
5
+ import {createSanityInstance} from '../store/createSanityInstance'
5
6
  import {getDraftId, getPublishedId} from '../utils/ids'
6
7
  import {evaluateSync, parse} from './_synchronous-groq-js.mjs'
7
8
  import {type DocumentAction} from './actions'
8
9
  import {calculatePermissions, createGrantsLookup, type DatasetAcl, type Grant} from './permissions'
9
10
  import {type SyncTransactionState} from './reducers'
10
11
 
12
+ const instance = createSanityInstance({projectId: 'p', dataset: 'd'})
13
+
14
+ afterAll(() => {
15
+ instance.dispose()
16
+ })
17
+
11
18
  // Helper: Create a sample document that conforms to SanityDocument.
12
19
  const createDoc = (id: string, title: string, rev: string = 'initial'): SanityDocument => ({
13
20
  _id: id,
@@ -69,7 +76,7 @@ describe('calculatePermissions', () => {
69
76
  const actions: DocumentAction[] = [
70
77
  {documentId: 'doc1', type: 'document.create', documentType: 'article'},
71
78
  ]
72
- const result = calculatePermissions(state, actions)
79
+ const result = calculatePermissions({instance, state}, actions)
73
80
  expect(result).toEqual({allowed: true})
74
81
  })
75
82
 
@@ -85,7 +92,7 @@ describe('calculatePermissions', () => {
85
92
  const actions: DocumentAction[] = [
86
93
  {documentId: 'doc1', type: 'document.create', documentType: 'article'},
87
94
  ]
88
- expect(calculatePermissions(state, actions)).toBeUndefined()
95
+ expect(calculatePermissions({instance, state}, actions)).toBeUndefined()
89
96
  })
90
97
 
91
98
  it('should catch PermissionActionError from processActions and return allowed false with a reason', () => {
@@ -101,7 +108,7 @@ describe('calculatePermissions', () => {
101
108
  const actions: DocumentAction[] = [
102
109
  {documentId: 'doc1', type: 'document.create', documentType: 'article'},
103
110
  ]
104
- const result = calculatePermissions(state, actions)
111
+ const result = calculatePermissions({instance, state}, actions)
105
112
  expect(result).toBeDefined()
106
113
  expect(result?.allowed).toBe(false)
107
114
  expect(result?.reasons).toEqual(
@@ -126,8 +133,10 @@ describe('calculatePermissions', () => {
126
133
  },
127
134
  defaultGrants,
128
135
  )
129
- const actions: DocumentAction[] = [{documentId: 'doc1', type: 'document.edit'}]
130
- const result = calculatePermissions(state, actions)
136
+ const actions: DocumentAction[] = [
137
+ {documentId: 'doc1', documentType: 'book', type: 'document.edit'},
138
+ ]
139
+ const result = calculatePermissions({instance, state}, actions)
131
140
  expect(result).toBeDefined()
132
141
  expect(result?.allowed).toBe(false)
133
142
  expect(result?.reasons).toEqual(
@@ -150,8 +159,10 @@ describe('calculatePermissions', () => {
150
159
  },
151
160
  deniedGrants,
152
161
  )
153
- const actions: DocumentAction[] = [{documentId: 'doc1', type: 'document.edit'}]
154
- const result = calculatePermissions(state, actions)
162
+ const actions: DocumentAction[] = [
163
+ {documentId: 'doc1', documentType: 'book', type: 'document.edit'},
164
+ ]
165
+ const result = calculatePermissions({instance, state}, actions)
155
166
  expect(result).toBeDefined()
156
167
  expect(result?.allowed).toBe(false)
157
168
  expect(result?.reasons).toEqual(
@@ -175,7 +186,7 @@ describe('calculatePermissions', () => {
175
186
  const actions: DocumentAction[] = [
176
187
  {documentId: 'doc1', type: 'document.create', documentType: 'article'},
177
188
  ]
178
- expect(calculatePermissions(state, actions)).toBeUndefined()
189
+ expect(calculatePermissions({instance, state}, actions)).toBeUndefined()
179
190
  })
180
191
 
181
192
  it('should catch ActionError from processActions and return a precondition error reason', () => {
@@ -187,8 +198,10 @@ describe('calculatePermissions', () => {
187
198
  },
188
199
  defaultGrants,
189
200
  )
190
- const actions: DocumentAction[] = [{documentId: 'doc1', type: 'document.delete'}]
191
- const result = calculatePermissions(state, actions)
201
+ const actions: DocumentAction[] = [
202
+ {documentId: 'doc1', documentType: 'book', type: 'document.delete'},
203
+ ]
204
+ const result = calculatePermissions({instance, state}, actions)
192
205
  expect(result).toBeDefined()
193
206
  expect(result?.allowed).toBe(false)
194
207
  expect(result?.reasons).toEqual(
@@ -216,8 +229,8 @@ describe('calculatePermissions', () => {
216
229
  documentType: 'article',
217
230
  }
218
231
  // notice how the action is a copy
219
- const result1 = calculatePermissions(state, [{...action}])
220
- const result2 = calculatePermissions(state, [{...action}])
232
+ const result1 = calculatePermissions({instance, state}, [{...action}])
233
+ const result2 = calculatePermissions({instance, state}, [{...action}])
221
234
  expect(result1).toBe(result2)
222
235
  })
223
236
  })
@@ -2,6 +2,7 @@ import {type SanityDocument} from '@sanity/types'
2
2
  import {type ExprNode} from 'groq-js'
3
3
  import {createSelector} from 'reselect'
4
4
 
5
+ import {type SelectorContext} from '../store/createStateSourceAction'
5
6
  import {getDraftId, getPublishedId} from '../utils/ids'
6
7
  import {MultiKeyWeakMap} from '../utils/MultiKeyWeakMap'
7
8
  import {evaluateSync, parse} from './_synchronous-groq-js.mjs'
@@ -57,8 +58,9 @@ const nullReplacer: object = {}
57
58
  // (If the same documents are computed, the MultiKeyWeakMap will return the same instance.)
58
59
  const documentsSelector = createSelector(
59
60
  [
60
- ({documentStates}: SyncTransactionState) => documentStates,
61
- (_state: SyncTransactionState, actions: DocumentAction | DocumentAction[]) => actions,
61
+ ({state: {documentStates}}: SelectorContext<SyncTransactionState>) => documentStates,
62
+ (_context: SelectorContext<SyncTransactionState>, actions: DocumentAction | DocumentAction[]) =>
63
+ actions,
62
64
  ],
63
65
  (documentStates, actions) => {
64
66
  const documentIds = new Set(
@@ -98,7 +100,8 @@ const documentsSelector = createSelector(
98
100
  const memoizedActionsSelector = createSelector(
99
101
  [
100
102
  documentsSelector,
101
- (_state: SyncTransactionState, actions: DocumentAction | DocumentAction[]) => actions,
103
+ (_state: SelectorContext<SyncTransactionState>, actions: DocumentAction | DocumentAction[]) =>
104
+ actions,
102
105
  ],
103
106
  (documents, actions) => {
104
107
  if (!documents) return undefined
@@ -146,7 +149,11 @@ export type DocumentPermissionsResult =
146
149
  const enNarrowConjunction = new Intl.ListFormat('en', {style: 'narrow', type: 'conjunction'})
147
150
 
148
151
  export const calculatePermissions = createSelector(
149
- [({grants}: SyncTransactionState) => grants, documentsSelector, memoizedActionsSelector],
152
+ [
153
+ ({state: {grants}}: SelectorContext<SyncTransactionState>) => grants,
154
+ documentsSelector,
155
+ memoizedActionsSelector,
156
+ ],
150
157
  (
151
158
  grants: Record<Grant, ExprNode> | undefined,
152
159
  documents: DocumentSet | undefined,
@@ -149,6 +149,7 @@ describe('processActions', () => {
149
149
  const actions: DocumentAction[] = [
150
150
  {
151
151
  documentId: 'doc1',
152
+ documentType: 'article',
152
153
  type: 'document.delete',
153
154
  },
154
155
  ]
@@ -184,6 +185,7 @@ describe('processActions', () => {
184
185
  const actions: DocumentAction[] = [
185
186
  {
186
187
  documentId: 'doc1',
188
+ documentType: 'article',
187
189
  type: 'document.delete',
188
190
  },
189
191
  ]
@@ -215,6 +217,7 @@ describe('processActions', () => {
215
217
  const actions: DocumentAction[] = [
216
218
  {
217
219
  documentId: 'doc1',
220
+ documentType: 'article',
218
221
  type: 'document.delete',
219
222
  },
220
223
  ]
@@ -233,6 +236,7 @@ describe('processActions', () => {
233
236
  const actions: DocumentAction[] = [
234
237
  {
235
238
  documentId: 'doc1',
239
+ documentType: 'article',
236
240
  type: 'document.discard',
237
241
  },
238
242
  ]
@@ -261,6 +265,7 @@ describe('processActions', () => {
261
265
  const actions: DocumentAction[] = [
262
266
  {
263
267
  documentId: 'doc1',
268
+ documentType: 'article',
264
269
  type: 'document.discard',
265
270
  },
266
271
  ]
@@ -279,6 +284,7 @@ describe('processActions', () => {
279
284
  const actions: DocumentAction[] = [
280
285
  {
281
286
  documentId: 'doc1',
287
+ documentType: 'article',
282
288
  type: 'document.edit',
283
289
  patches: [{set: {title: 'Edited Title'}}],
284
290
  },
@@ -310,6 +316,7 @@ describe('processActions', () => {
310
316
  const actions: DocumentAction[] = [
311
317
  {
312
318
  documentId: 'doc1',
319
+ documentType: 'article',
313
320
  type: 'document.edit',
314
321
  patches: [{set: {title: 'New Draft Title'}}],
315
322
  },
@@ -337,6 +344,7 @@ describe('processActions', () => {
337
344
  const actions: DocumentAction[] = [
338
345
  {
339
346
  documentId: 'doc1',
347
+ documentType: 'article',
340
348
  type: 'document.edit',
341
349
  patches: [{set: {title: 'Original Cool Title'}}],
342
350
  },
@@ -365,6 +373,7 @@ describe('processActions', () => {
365
373
  const actions: DocumentAction[] = [
366
374
  {
367
375
  documentId: 'doc1',
376
+ documentType: 'article',
368
377
  type: 'document.edit',
369
378
  patches: [{set: {title: 'Should Fail'}}],
370
379
  },
@@ -381,6 +390,7 @@ describe('processActions', () => {
381
390
  const actions: DocumentAction[] = [
382
391
  {
383
392
  documentId: 'doc1',
393
+ documentType: 'article',
384
394
  type: 'document.edit',
385
395
  patches: [{set: {title: 'Edited Title'}}],
386
396
  },
@@ -398,6 +408,7 @@ describe('processActions', () => {
398
408
  const actions: DocumentAction[] = [
399
409
  {
400
410
  documentId: 'doc1',
411
+ documentType: 'article',
401
412
  type: 'document.edit',
402
413
  patches: [{set: {title: 'New Title'}}],
403
414
  },
@@ -417,6 +428,7 @@ describe('processActions', () => {
417
428
  const actions: DocumentAction[] = [
418
429
  {
419
430
  documentId: 'doc1',
431
+ documentType: 'article',
420
432
  type: 'document.publish',
421
433
  },
422
434
  ]
@@ -451,6 +463,7 @@ describe('processActions', () => {
451
463
  const actions: DocumentAction[] = [
452
464
  {
453
465
  documentId: 'doc1',
466
+ documentType: 'article',
454
467
  type: 'document.publish',
455
468
  },
456
469
  ]
@@ -468,6 +481,7 @@ describe('processActions', () => {
468
481
  const actions: DocumentAction[] = [
469
482
  {
470
483
  documentId: 'doc1',
484
+ documentType: 'article',
471
485
  type: 'document.publish',
472
486
  },
473
487
  ]
@@ -480,7 +494,9 @@ describe('processActions', () => {
480
494
  const draft = createDoc('drafts.doc1', 'Draft Title', '1')
481
495
  const base: DocumentSet = {'drafts.doc1': draft}
482
496
  const working: DocumentSet = {'drafts.doc1': draft}
483
- const actions: DocumentAction[] = [{documentId: 'doc1', type: 'document.publish'}]
497
+ const actions: DocumentAction[] = [
498
+ {documentId: 'doc1', documentType: 'article', type: 'document.publish'},
499
+ ]
484
500
  const grants = {...defaultGrants, update: alwaysDeny}
485
501
  expect(() =>
486
502
  processActions({actions, transactionId, base, working, timestamp, grants}),
@@ -492,7 +508,9 @@ describe('processActions', () => {
492
508
  const published = createDoc('doc1', 'Published Title', '1')
493
509
  const base: DocumentSet = {'drafts.doc1': draft, 'doc1': published}
494
510
  const working: DocumentSet = {'drafts.doc1': draft, 'doc1': published}
495
- const actions: DocumentAction[] = [{documentId: 'doc1', type: 'document.publish'}]
511
+ const actions: DocumentAction[] = [
512
+ {documentId: 'doc1', documentType: 'article', type: 'document.publish'},
513
+ ]
496
514
  const grants = {
497
515
  ...defaultGrants,
498
516
  update: parse(`$document {"_": _id in path("drafts.**")}._`),
@@ -509,7 +527,9 @@ describe('processActions', () => {
509
527
  // simulate case where there is no published version
510
528
  const base: DocumentSet = {'drafts.doc1': draft}
511
529
  const working: DocumentSet = {'drafts.doc1': draft}
512
- const actions: DocumentAction[] = [{documentId: 'doc1', type: 'document.publish'}]
530
+ const actions: DocumentAction[] = [
531
+ {documentId: 'doc1', documentType: 'article', type: 'document.publish'},
532
+ ]
513
533
  const grants = {...defaultGrants, create: alwaysDeny}
514
534
  expect(() =>
515
535
  processActions({actions, transactionId, base, working, timestamp, grants}),
@@ -542,6 +562,7 @@ describe('processActions', () => {
542
562
  const actions: DocumentAction[] = [
543
563
  {
544
564
  documentId: 'doc1',
565
+ documentType: 'article',
545
566
  type: 'document.publish',
546
567
  },
547
568
  ]
@@ -573,6 +594,7 @@ describe('processActions', () => {
573
594
  const actions: DocumentAction[] = [
574
595
  {
575
596
  documentId: 'doc1',
597
+ documentType: 'article',
576
598
  type: 'document.unpublish',
577
599
  },
578
600
  ]
@@ -606,6 +628,7 @@ describe('processActions', () => {
606
628
  const actions: DocumentAction[] = [
607
629
  {
608
630
  documentId: 'doc1',
631
+ documentType: 'article',
609
632
  type: 'document.unpublish',
610
633
  },
611
634
  ]
@@ -623,6 +646,7 @@ describe('processActions', () => {
623
646
  const actions: DocumentAction[] = [
624
647
  {
625
648
  documentId: 'doc1',
649
+ documentType: 'article',
626
650
  type: 'document.unpublish',
627
651
  },
628
652
  ]
@@ -654,7 +678,9 @@ describe('processActions', () => {
654
678
  const published = createDoc('doc1', 'Published Title')
655
679
  const base: DocumentSet = {doc1: published}
656
680
  const working: DocumentSet = {doc1: published}
657
- const actions: DocumentAction[] = [{documentId: 'doc1', type: 'document.unpublish'}]
681
+ const actions: DocumentAction[] = [
682
+ {documentId: 'doc1', documentType: 'article', type: 'document.unpublish'},
683
+ ]
658
684
  const grants = {...defaultGrants, update: alwaysDeny}
659
685
  expect(() =>
660
686
  processActions({actions, transactionId, base, working, timestamp, grants}),
@@ -665,7 +691,9 @@ describe('processActions', () => {
665
691
  const published = createDoc('doc1', 'Published Title')
666
692
  const base: DocumentSet = {doc1: published}
667
693
  const working: DocumentSet = {doc1: published}
668
- const actions: DocumentAction[] = [{documentId: 'doc1', type: 'document.unpublish'}]
694
+ const actions: DocumentAction[] = [
695
+ {documentId: 'doc1', documentType: 'article', type: 'document.unpublish'},
696
+ ]
669
697
  const grants = {...defaultGrants, create: alwaysDeny}
670
698
  expect(() =>
671
699
  processActions({actions, transactionId, base, working, timestamp, grants}),
@@ -679,9 +707,14 @@ describe('processActions', () => {
679
707
  const base: DocumentSet = {doc1: published}
680
708
  const working: DocumentSet = {doc1: published}
681
709
  const actions: DocumentAction[] = [
682
- {documentId: 'doc1', type: 'document.create', documentType: 'article'},
683
- {documentId: 'doc1', type: 'document.edit', patches: [{set: {title: 'Edited Title'}}]},
684
- {documentId: 'doc1', type: 'document.publish'},
710
+ {documentId: 'doc1', documentType: 'article', type: 'document.create'},
711
+ {
712
+ documentId: 'doc1',
713
+ documentType: 'article',
714
+ type: 'document.edit',
715
+ patches: [{set: {title: 'Edited Title'}}],
716
+ },
717
+ {documentId: 'doc1', documentType: 'article', type: 'document.publish'},
685
718
  ]
686
719
  const result = processActions({
687
720
  actions,