@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.
- package/dist/index.d.ts +428 -325
- package/dist/index.js +1618 -1553
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
- package/src/_exports/index.ts +31 -30
- package/src/auth/authStore.test.ts +149 -104
- package/src/auth/authStore.ts +51 -100
- package/src/auth/handleAuthCallback.test.ts +67 -34
- package/src/auth/handleAuthCallback.ts +8 -7
- package/src/auth/logout.test.ts +61 -29
- package/src/auth/logout.ts +26 -28
- package/src/auth/refreshStampedToken.test.ts +9 -9
- package/src/auth/refreshStampedToken.ts +62 -56
- package/src/auth/subscribeToStateAndFetchCurrentUser.test.ts +5 -5
- package/src/auth/subscribeToStateAndFetchCurrentUser.ts +45 -47
- package/src/auth/subscribeToStorageEventsAndSetToken.test.ts +4 -5
- package/src/auth/subscribeToStorageEventsAndSetToken.ts +22 -24
- package/src/client/clientStore.test.ts +131 -67
- package/src/client/clientStore.ts +117 -116
- package/src/comlink/controller/actions/destroyController.test.ts +38 -13
- package/src/comlink/controller/actions/destroyController.ts +11 -15
- package/src/comlink/controller/actions/getOrCreateChannel.test.ts +56 -27
- package/src/comlink/controller/actions/getOrCreateChannel.ts +37 -35
- package/src/comlink/controller/actions/getOrCreateController.test.ts +27 -16
- package/src/comlink/controller/actions/getOrCreateController.ts +23 -22
- package/src/comlink/controller/actions/releaseChannel.test.ts +37 -13
- package/src/comlink/controller/actions/releaseChannel.ts +22 -21
- package/src/comlink/controller/comlinkControllerStore.test.ts +65 -36
- package/src/comlink/controller/comlinkControllerStore.ts +44 -5
- package/src/comlink/node/actions/getOrCreateNode.test.ts +31 -15
- package/src/comlink/node/actions/getOrCreateNode.ts +30 -29
- package/src/comlink/node/actions/releaseNode.test.ts +75 -55
- package/src/comlink/node/actions/releaseNode.ts +19 -21
- package/src/comlink/node/comlinkNodeStore.test.ts +6 -11
- package/src/comlink/node/comlinkNodeStore.ts +22 -5
- package/src/config/authConfig.ts +79 -0
- package/src/config/sanityConfig.ts +48 -0
- package/src/datasets/datasets.test.ts +2 -2
- package/src/datasets/datasets.ts +18 -5
- package/src/document/actions.test.ts +22 -10
- package/src/document/actions.ts +44 -56
- package/src/document/applyDocumentActions.test.ts +96 -36
- package/src/document/applyDocumentActions.ts +140 -99
- package/src/document/documentStore.test.ts +103 -155
- package/src/document/documentStore.ts +247 -237
- package/src/document/listen.ts +56 -55
- package/src/document/patchOperations.ts +0 -43
- package/src/document/permissions.test.ts +25 -12
- package/src/document/permissions.ts +11 -4
- package/src/document/processActions.test.ts +41 -8
- package/src/document/reducers.test.ts +87 -16
- package/src/document/reducers.ts +2 -2
- package/src/document/sharedListener.test.ts +34 -16
- package/src/document/sharedListener.ts +33 -11
- package/src/preview/getPreviewState.test.ts +40 -39
- package/src/preview/getPreviewState.ts +68 -56
- package/src/preview/previewConstants.ts +43 -0
- package/src/preview/previewQuery.test.ts +1 -1
- package/src/preview/previewQuery.ts +4 -5
- package/src/preview/previewStore.test.ts +13 -58
- package/src/preview/previewStore.ts +7 -21
- package/src/preview/resolvePreview.test.ts +33 -104
- package/src/preview/resolvePreview.ts +11 -21
- package/src/preview/subscribeToStateAndFetchBatches.test.ts +96 -97
- package/src/preview/subscribeToStateAndFetchBatches.ts +85 -81
- package/src/preview/util.ts +1 -0
- package/src/project/project.test.ts +3 -3
- package/src/project/project.ts +28 -5
- package/src/projection/getProjectionState.test.ts +69 -49
- package/src/projection/getProjectionState.ts +42 -50
- package/src/projection/projectionQuery.ts +1 -1
- package/src/projection/projectionStore.test.ts +13 -51
- package/src/projection/projectionStore.ts +6 -18
- package/src/projection/resolveProjection.test.ts +32 -127
- package/src/projection/resolveProjection.ts +15 -28
- package/src/projection/subscribeToStateAndFetchBatches.test.ts +105 -90
- package/src/projection/subscribeToStateAndFetchBatches.ts +94 -81
- package/src/projection/util.ts +2 -0
- package/src/projects/projects.test.ts +13 -4
- package/src/projects/projects.ts +6 -1
- package/src/query/queryStore.test.ts +10 -47
- package/src/query/queryStore.ts +151 -133
- package/src/query/queryStoreConstants.ts +2 -0
- package/src/store/createActionBinder.test.ts +153 -0
- package/src/store/createActionBinder.ts +176 -0
- package/src/store/createSanityInstance.test.ts +84 -0
- package/src/store/createSanityInstance.ts +124 -0
- package/src/store/createStateSourceAction.test.ts +196 -0
- package/src/store/createStateSourceAction.ts +260 -0
- package/src/store/createStoreInstance.test.ts +81 -0
- package/src/store/createStoreInstance.ts +80 -0
- package/src/store/createStoreState.test.ts +85 -0
- package/src/store/createStoreState.ts +92 -0
- package/src/store/defineStore.test.ts +18 -0
- package/src/store/defineStore.ts +81 -0
- package/src/users/reducers.test.ts +318 -0
- package/src/users/reducers.ts +88 -0
- package/src/users/types.ts +46 -4
- package/src/users/usersConstants.ts +4 -0
- package/src/users/usersStore.test.ts +350 -223
- package/src/users/usersStore.ts +285 -149
- package/src/utils/createFetcherStore.test.ts +6 -7
- package/src/utils/createFetcherStore.ts +150 -153
- package/src/{common/util.test.ts → utils/hashString.test.ts} +1 -1
- package/src/auth/fetchLoginUrls.test.ts +0 -163
- package/src/auth/fetchLoginUrls.ts +0 -74
- package/src/common/createLiveEventSubscriber.test.ts +0 -121
- package/src/common/createLiveEventSubscriber.ts +0 -55
- package/src/common/types.ts +0 -4
- package/src/instance/identity.test.ts +0 -46
- package/src/instance/identity.ts +0 -29
- package/src/instance/sanityInstance.test.ts +0 -77
- package/src/instance/sanityInstance.ts +0 -57
- package/src/instance/types.ts +0 -37
- package/src/preview/getPreviewProjection.ts +0 -45
- package/src/resources/README.md +0 -370
- package/src/resources/createAction.test.ts +0 -101
- package/src/resources/createAction.ts +0 -44
- package/src/resources/createResource.test.ts +0 -112
- package/src/resources/createResource.ts +0 -102
- package/src/resources/createStateSourceAction.test.ts +0 -114
- package/src/resources/createStateSourceAction.ts +0 -83
- package/src/resources/createStore.test.ts +0 -67
- package/src/resources/createStore.ts +0 -46
- package/src/store/createStore.test.ts +0 -108
- package/src/store/createStore.ts +0 -106
- /package/src/{common/util.ts → utils/hashString.ts} +0 -0
package/src/document/listen.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
} from 'rxjs'
|
|
17
17
|
import {mergeMap, scan} from 'rxjs/operators'
|
|
18
18
|
|
|
19
|
-
import {type
|
|
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 =
|
|
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
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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
|
-
|
|
246
|
+
const {previousRev, transactionId, timestamp} = next
|
|
245
247
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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[] = [
|
|
130
|
-
|
|
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[] = [
|
|
154
|
-
|
|
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[] = [
|
|
191
|
-
|
|
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
|
-
(
|
|
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
|
|
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
|
-
[
|
|
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[] = [
|
|
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[] = [
|
|
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[] = [
|
|
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[] = [
|
|
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[] = [
|
|
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',
|
|
683
|
-
{
|
|
684
|
-
|
|
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,
|