@contember/binding 1.1.0-alpha.6 → 1.1.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/accessorTree/AccessorTreeStateContext.js +1 -3
- package/dist/development/accessorTree/AccessorTreeStateContext.js.map +1 -1
- package/dist/development/accessorTree/NormalizedPersistedData.js.map +1 -1
- package/dist/development/accessorTree/accessorTreeStateReducer.js +7 -1
- package/dist/development/accessorTree/accessorTreeStateReducer.js.map +1 -1
- package/dist/development/accessorTree/useAccessorTreeState.js +8 -1
- package/dist/development/accessorTree/useAccessorTreeState.js.map +1 -1
- package/dist/development/accessorTree/useDataBinding.js +18 -16
- package/dist/development/accessorTree/useDataBinding.js.map +1 -1
- package/dist/development/core/AccessorErrorManager.js +2 -2
- package/dist/development/core/AccessorErrorManager.js.map +1 -1
- package/dist/development/core/DataBinding.js +14 -13
- package/dist/development/core/DataBinding.js.map +1 -1
- package/dist/development/core/ErrorsPreprocessor.js +9 -13
- package/dist/development/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/development/core/MutationGenerator.js +79 -43
- package/dist/development/core/MutationGenerator.js.map +1 -1
- package/dist/development/core/RequestResponseNormalizer.js +93 -130
- package/dist/development/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/development/core/StateInitializer.js +5 -1
- package/dist/development/core/StateInitializer.js.map +1 -1
- package/dist/development/core/TreeAugmenter.js +4 -4
- package/dist/development/core/TreeAugmenter.js.map +1 -1
- package/dist/development/core/TreeStore.js +4 -4
- package/dist/development/core/TreeStore.js.map +1 -1
- package/dist/development/core/VariableInputTransformer.js.map +1 -1
- package/dist/development/core/requestAliases/MutationAlias.js +2 -40
- package/dist/development/core/requestAliases/MutationAlias.js.map +1 -1
- package/dist/development/helperComponents/helpers/evaluateCondition.js.map +1 -1
- package/dist/production/accessorTree/AccessorTreeStateContext.js +1 -3
- package/dist/production/accessorTree/AccessorTreeStateContext.js.map +1 -1
- package/dist/production/accessorTree/NormalizedPersistedData.js.map +1 -1
- package/dist/production/accessorTree/accessorTreeStateReducer.js +7 -1
- package/dist/production/accessorTree/accessorTreeStateReducer.js.map +1 -1
- package/dist/production/accessorTree/useAccessorTreeState.js +8 -1
- package/dist/production/accessorTree/useAccessorTreeState.js.map +1 -1
- package/dist/production/accessorTree/useDataBinding.js +18 -16
- package/dist/production/accessorTree/useDataBinding.js.map +1 -1
- package/dist/production/core/AccessorErrorManager.js +2 -2
- package/dist/production/core/AccessorErrorManager.js.map +1 -1
- package/dist/production/core/DataBinding.js +14 -13
- package/dist/production/core/DataBinding.js.map +1 -1
- package/dist/production/core/ErrorsPreprocessor.js +9 -13
- package/dist/production/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/production/core/MutationGenerator.js +79 -43
- package/dist/production/core/MutationGenerator.js.map +1 -1
- package/dist/production/core/RequestResponseNormalizer.js +93 -130
- package/dist/production/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/production/core/StateInitializer.js +5 -1
- package/dist/production/core/StateInitializer.js.map +1 -1
- package/dist/production/core/TreeAugmenter.js +4 -4
- package/dist/production/core/TreeAugmenter.js.map +1 -1
- package/dist/production/core/TreeStore.js +4 -4
- package/dist/production/core/TreeStore.js.map +1 -1
- package/dist/production/core/VariableInputTransformer.js.map +1 -1
- package/dist/production/core/requestAliases/MutationAlias.js +2 -33
- package/dist/production/core/requestAliases/MutationAlias.js.map +1 -1
- package/dist/production/helperComponents/helpers/evaluateCondition.js.map +1 -1
- package/dist/types/accessorTree/AccessorTreeState.d.ts +4 -0
- package/dist/types/accessorTree/AccessorTreeState.d.ts.map +1 -1
- package/dist/types/accessorTree/AccessorTreeStateAction.d.ts +4 -0
- package/dist/types/accessorTree/AccessorTreeStateAction.d.ts.map +1 -1
- package/dist/types/accessorTree/AccessorTreeStateContext.d.ts +1 -1
- package/dist/types/accessorTree/AccessorTreeStateContext.d.ts.map +1 -1
- package/dist/types/accessorTree/NormalizedPersistedData.d.ts +2 -2
- package/dist/types/accessorTree/NormalizedPersistedData.d.ts.map +1 -1
- package/dist/types/accessorTree/QueryRequestResponse.d.ts +2 -2
- package/dist/types/accessorTree/QueryRequestResponse.d.ts.map +1 -1
- package/dist/types/accessorTree/accessorTreeStateReducer.d.ts.map +1 -1
- package/dist/types/accessorTree/useAccessorTreeState.d.ts.map +1 -1
- package/dist/types/accessorTree/useDataBinding.d.ts.map +1 -1
- package/dist/types/core/AccessorErrorManager.d.ts +2 -1
- package/dist/types/core/AccessorErrorManager.d.ts.map +1 -1
- package/dist/types/core/DataBinding.d.ts +1 -1
- package/dist/types/core/DataBinding.d.ts.map +1 -1
- package/dist/types/core/ErrorsPreprocessor.d.ts +3 -1
- package/dist/types/core/ErrorsPreprocessor.d.ts.map +1 -1
- package/dist/types/core/MutationGenerator.d.ts +25 -1
- package/dist/types/core/MutationGenerator.d.ts.map +1 -1
- package/dist/types/core/RequestResponseNormalizer.d.ts +6 -7
- package/dist/types/core/RequestResponseNormalizer.d.ts.map +1 -1
- package/dist/types/core/StateInitializer.d.ts.map +1 -1
- package/dist/types/core/TreeAugmenter.d.ts +3 -2
- package/dist/types/core/TreeAugmenter.d.ts.map +1 -1
- package/dist/types/core/TreeStore.d.ts +3 -2
- package/dist/types/core/TreeStore.d.ts.map +1 -1
- package/dist/types/core/VariableInputTransformer.d.ts +2 -2
- package/dist/types/core/VariableInputTransformer.d.ts.map +1 -1
- package/dist/types/core/requestAliases/MutationAlias.d.ts +0 -3
- package/dist/types/core/requestAliases/MutationAlias.d.ts.map +1 -1
- package/dist/types/core/requestAliases/index.d.ts +0 -3
- package/dist/types/core/requestAliases/index.d.ts.map +1 -1
- package/dist/types/core/state/FieldState.d.ts +2 -2
- package/dist/types/core/state/FieldState.d.ts.map +1 -1
- package/dist/types/coreComponents/Field.d.ts +1 -1
- package/dist/types/coreComponents/Field.d.ts.map +1 -1
- package/dist/types/entityEvents/useDerivedField.d.ts +2 -2
- package/dist/types/entityEvents/useDerivedField.d.ts.map +1 -1
- package/dist/types/helperComponents/FieldView.d.ts +7 -7
- package/dist/types/helperComponents/FieldView.d.ts.map +1 -1
- package/dist/types/helperComponents/SugaredField.d.ts +1 -1
- package/dist/types/helperComponents/SugaredField.d.ts.map +1 -1
- package/dist/types/helperComponents/helpers/evaluateCondition.d.ts +2 -2
- package/dist/types/helperComponents/helpers/evaluateCondition.d.ts.map +1 -1
- package/dist/types/markers/FieldMarker.d.ts +3 -3
- package/dist/types/markers/FieldMarker.d.ts.map +1 -1
- package/dist/types/treeParameters/primitives/FieldValue.d.ts +2 -2
- package/dist/types/treeParameters/primitives/FieldValue.d.ts.map +1 -1
- package/dist/types/treeParameters/primitives/Json.d.ts +7 -0
- package/dist/types/treeParameters/primitives/Json.d.ts.map +1 -0
- package/dist/types/treeParameters/primitives/index.d.ts +1 -0
- package/dist/types/treeParameters/primitives/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/accessorTree/AccessorTreeState.ts +4 -0
- package/src/accessorTree/AccessorTreeStateAction.ts +4 -0
- package/src/accessorTree/AccessorTreeStateContext.ts +1 -3
- package/src/accessorTree/NormalizedPersistedData.ts +2 -2
- package/src/accessorTree/QueryRequestResponse.ts +2 -2
- package/src/accessorTree/accessorTreeStateReducer.ts +7 -1
- package/src/accessorTree/useAccessorTreeState.ts +8 -1
- package/src/accessorTree/useDataBinding.ts +15 -15
- package/src/core/AccessorErrorManager.ts +3 -2
- package/src/core/DataBinding.ts +17 -15
- package/src/core/ErrorsPreprocessor.ts +14 -16
- package/src/core/MutationGenerator.ts +112 -56
- package/src/core/RequestResponseNormalizer.ts +110 -161
- package/src/core/StateInitializer.ts +10 -6
- package/src/core/TreeAugmenter.ts +5 -4
- package/src/core/TreeStore.ts +5 -4
- package/src/core/VariableInputTransformer.ts +2 -2
- package/src/core/requestAliases/MutationAlias.ts +2 -57
- package/src/core/requestAliases/index.ts +0 -3
- package/src/core/state/FieldState.ts +2 -2
- package/src/helperComponents/helpers/evaluateCondition.ts +2 -2
- package/src/treeParameters/primitives/FieldValue.ts +2 -2
- package/src/treeParameters/primitives/Json.ts +7 -0
- package/src/treeParameters/primitives/index.ts +1 -0
- package/dist/development/core/requestAliases/mutationOperationSubTreeType.js +0 -6
- package/dist/development/core/requestAliases/mutationOperationSubTreeType.js.map +0 -1
- package/dist/development/core/requestAliases/mutationOperationType.js +0 -7
- package/dist/development/core/requestAliases/mutationOperationType.js.map +0 -1
- package/dist/production/core/requestAliases/mutationOperationSubTreeType.js +0 -6
- package/dist/production/core/requestAliases/mutationOperationSubTreeType.js.map +0 -1
- package/dist/production/core/requestAliases/mutationOperationType.js +0 -7
- package/dist/production/core/requestAliases/mutationOperationType.js.map +0 -1
- package/dist/types/core/requestAliases/TopLevelMutationOperation.d.ts +0 -11
- package/dist/types/core/requestAliases/TopLevelMutationOperation.d.ts.map +0 -1
- package/dist/types/core/requestAliases/mutationOperationSubTreeType.d.ts +0 -5
- package/dist/types/core/requestAliases/mutationOperationSubTreeType.d.ts.map +0 -1
- package/dist/types/core/requestAliases/mutationOperationType.d.ts +0 -6
- package/dist/types/core/requestAliases/mutationOperationType.d.ts.map +0 -1
- package/src/core/requestAliases/TopLevelMutationOperation.ts +0 -11
- package/src/core/requestAliases/mutationOperationSubTreeType.ts +0 -4
- package/src/core/requestAliases/mutationOperationType.ts +0 -5
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/binding",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "1.1.0-alpha.
|
|
4
|
+
"version": "1.1.0-alpha.9",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/production/index.js",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
],
|
|
20
20
|
"typings": "./dist/types/index.d.ts",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@contember/client": "1.1.0-alpha.
|
|
23
|
-
"@contember/react-client": "1.1.0-alpha.
|
|
24
|
-
"@contember/react-multipass-rendering": "1.1.0-alpha.
|
|
25
|
-
"@contember/react-utils": "1.1.0-alpha.
|
|
22
|
+
"@contember/client": "1.1.0-alpha.9",
|
|
23
|
+
"@contember/react-client": "1.1.0-alpha.9",
|
|
24
|
+
"@contember/react-multipass-rendering": "1.1.0-alpha.9",
|
|
25
|
+
"@contember/react-utils": "1.1.0-alpha.9",
|
|
26
26
|
"chevrotain": "6.5.0",
|
|
27
27
|
"fast-deep-equal": "^3.1.3",
|
|
28
28
|
"js-levenshtein": "1.1.6",
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import type { TreeRootAccessor } from '../accessors'
|
|
2
2
|
import type { RequestError } from './RequestError'
|
|
3
|
+
import { DataBinding } from '../core'
|
|
3
4
|
|
|
4
5
|
export interface InitializingAccessorTreeState {
|
|
6
|
+
binding: DataBinding
|
|
5
7
|
name: 'initializing'
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
export interface InitializedAccessorTreeState {
|
|
11
|
+
binding: DataBinding
|
|
9
12
|
name: 'initialized'
|
|
10
13
|
data: TreeRootAccessor
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
export interface ErrorAccessorTreeState {
|
|
17
|
+
binding: DataBinding
|
|
14
18
|
name: 'error'
|
|
15
19
|
error: RequestError
|
|
16
20
|
}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import type { TreeRootAccessor } from '../accessors'
|
|
2
2
|
import type { RequestError } from './RequestError'
|
|
3
|
+
import { DataBinding } from '../core'
|
|
3
4
|
|
|
4
5
|
export type AccessorTreeStateAction =
|
|
5
6
|
| {
|
|
6
7
|
type: 'setData'
|
|
7
8
|
data: TreeRootAccessor
|
|
9
|
+
binding: DataBinding
|
|
8
10
|
}
|
|
9
11
|
| {
|
|
10
12
|
type: 'failWithError'
|
|
11
13
|
error: RequestError
|
|
14
|
+
binding: DataBinding
|
|
12
15
|
}
|
|
13
16
|
| {
|
|
14
17
|
type: 'reset'
|
|
18
|
+
binding: DataBinding
|
|
15
19
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { createContext } from 'react'
|
|
2
2
|
import { AccessorTreeState } from './AccessorTreeState'
|
|
3
3
|
|
|
4
|
-
export const AccessorTreeStateContext = createContext<AccessorTreeState>(
|
|
5
|
-
name: 'initializing',
|
|
6
|
-
})
|
|
4
|
+
export const AccessorTreeStateContext = createContext<AccessorTreeState | undefined>(undefined)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { EntityId,
|
|
1
|
+
import type { EntityId, FieldValue, PlaceholderName } from '../treeParameters'
|
|
2
2
|
import type { ServerId, UniqueEntityId } from './RuntimeId'
|
|
3
3
|
|
|
4
4
|
// HasMany relations are encoded as sets of entity ids.
|
|
5
5
|
// HasOne relations are encoded as BoxedSingleEntityId just to make them different from actual strings.
|
|
6
6
|
// Not sure whether that is a reasonable precaution or just pure overhead.
|
|
7
|
-
export type EntityFieldPersistedData =
|
|
7
|
+
export type EntityFieldPersistedData = FieldValue | ServerId | EntityListPersistedData
|
|
8
8
|
|
|
9
9
|
export type SingleEntityPersistedData = Map<PlaceholderName, EntityFieldPersistedData>
|
|
10
10
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { EntityId,
|
|
1
|
+
import type { EntityId, FieldValue } from '../treeParameters'
|
|
2
2
|
|
|
3
|
-
export type ReceivedFieldData =
|
|
3
|
+
export type ReceivedFieldData = FieldValue | ReceivedEntityData | Array<ReceivedEntityData>
|
|
4
4
|
|
|
5
5
|
export type ReceivedEntityData =
|
|
6
6
|
& {
|
|
@@ -7,20 +7,26 @@ export const accessorTreeStateReducer = (
|
|
|
7
7
|
): AccessorTreeState => {
|
|
8
8
|
switch (action.type) {
|
|
9
9
|
case 'setData':
|
|
10
|
-
if (previousState.name === 'error') {
|
|
10
|
+
if (previousState.name === 'error' || previousState.binding !== action.binding) {
|
|
11
11
|
return previousState
|
|
12
12
|
}
|
|
13
13
|
return {
|
|
14
|
+
binding: previousState.binding,
|
|
14
15
|
name: 'initialized',
|
|
15
16
|
data: action.data,
|
|
16
17
|
}
|
|
17
18
|
case 'failWithError':
|
|
19
|
+
if (previousState.binding !== action.binding) {
|
|
20
|
+
return previousState
|
|
21
|
+
}
|
|
18
22
|
return {
|
|
23
|
+
binding: previousState.binding,
|
|
19
24
|
name: 'error',
|
|
20
25
|
error: action.error,
|
|
21
26
|
}
|
|
22
27
|
case 'reset':
|
|
23
28
|
return {
|
|
29
|
+
binding: action.binding,
|
|
24
30
|
name: 'initializing',
|
|
25
31
|
}
|
|
26
32
|
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { useContext } from 'react'
|
|
2
2
|
import { AccessorTreeStateContext } from './AccessorTreeStateContext'
|
|
3
|
+
import { BindingError } from '../BindingError'
|
|
3
4
|
|
|
4
|
-
export const useAccessorTreeState = () =>
|
|
5
|
+
export const useAccessorTreeState = () => {
|
|
6
|
+
const state = useContext(AccessorTreeStateContext)
|
|
7
|
+
if (!state) {
|
|
8
|
+
throw new BindingError()
|
|
9
|
+
}
|
|
10
|
+
return state
|
|
11
|
+
}
|
|
@@ -12,10 +12,6 @@ import type { AccessorTreeStateOptions } from './AccessorTreeStateOptions'
|
|
|
12
12
|
import { accessorTreeStateReducer } from './accessorTreeStateReducer'
|
|
13
13
|
import type { RequestError } from './RequestError'
|
|
14
14
|
|
|
15
|
-
const initialState: AccessorTreeState = {
|
|
16
|
-
name: 'initializing',
|
|
17
|
-
}
|
|
18
|
-
|
|
19
15
|
export const useDataBinding = ({
|
|
20
16
|
nodeTree,
|
|
21
17
|
refreshOnEnvironmentChange = true,
|
|
@@ -26,27 +22,28 @@ export const useDataBinding = ({
|
|
|
26
22
|
const tenantClient = useTenantGraphQlClient()
|
|
27
23
|
const environment = useEnvironment()
|
|
28
24
|
|
|
29
|
-
const [state, dispatch] = useReducer(accessorTreeStateReducer, initialState)
|
|
30
25
|
|
|
31
26
|
const isFirstRenderRef = useRef(true)
|
|
32
27
|
const isMountedRef = useRef(true)
|
|
33
28
|
|
|
34
|
-
const onUpdate = useCallback((accessor: TreeRootAccessor) => {
|
|
29
|
+
const onUpdate = useCallback((accessor: TreeRootAccessor, binding: DataBinding) => {
|
|
35
30
|
if (!isMountedRef.current) {
|
|
36
31
|
return
|
|
37
32
|
}
|
|
38
33
|
dispatch({
|
|
39
34
|
type: 'setData',
|
|
40
35
|
data: accessor,
|
|
36
|
+
binding,
|
|
41
37
|
})
|
|
42
38
|
}, [])
|
|
43
|
-
const onError = useCallback((error: RequestError) => {
|
|
39
|
+
const onError = useCallback((error: RequestError, binding: DataBinding) => {
|
|
44
40
|
if (!isMountedRef.current) {
|
|
45
41
|
return
|
|
46
42
|
}
|
|
47
43
|
dispatch({
|
|
48
44
|
type: 'failWithError',
|
|
49
45
|
error,
|
|
46
|
+
binding,
|
|
50
47
|
})
|
|
51
48
|
}, [])
|
|
52
49
|
|
|
@@ -56,15 +53,18 @@ export const useDataBinding = ({
|
|
|
56
53
|
if (!isMountedRef.current || !refreshOnPersist) {
|
|
57
54
|
return
|
|
58
55
|
}
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
const binding = create()
|
|
57
|
+
dispatch({ type: 'reset', binding })
|
|
61
58
|
})
|
|
62
59
|
return create()
|
|
63
60
|
},
|
|
64
61
|
[contentClient, systemClient, tenantClient, environment, onUpdate, onError, refreshOnPersist],
|
|
65
62
|
)
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
const [initialState] = useState(() => ({
|
|
64
|
+
binding: createDataBinding(),
|
|
65
|
+
name: 'initializing' as const,
|
|
66
|
+
}))
|
|
67
|
+
const [state, dispatch] = useReducer(accessorTreeStateReducer, initialState)
|
|
68
68
|
|
|
69
69
|
useEffect(() => {
|
|
70
70
|
if (state.name !== 'initializing') {
|
|
@@ -74,16 +74,16 @@ export const useDataBinding = ({
|
|
|
74
74
|
// To make their lives a bit easier, we do this.
|
|
75
75
|
return
|
|
76
76
|
}
|
|
77
|
-
|
|
78
|
-
}, [nodeTree,
|
|
77
|
+
state.binding.extendTree(nodeTree)
|
|
78
|
+
}, [nodeTree, state.binding, state.name])
|
|
79
79
|
|
|
80
80
|
useEffect(() => {
|
|
81
81
|
if (isFirstRenderRef.current || !refreshOnEnvironmentChange) {
|
|
82
82
|
return
|
|
83
83
|
}
|
|
84
|
-
dispatch({ type: 'reset' })
|
|
85
84
|
// This essentially just reacts to new environments.
|
|
86
|
-
|
|
85
|
+
const binding = createDataBinding()
|
|
86
|
+
dispatch({ type: 'reset', binding })
|
|
87
87
|
}, [createDataBinding, refreshOnEnvironmentChange])
|
|
88
88
|
|
|
89
89
|
useEffect(() => {
|
|
@@ -4,6 +4,7 @@ import { ErrorsPreprocessor } from './ErrorsPreprocessor'
|
|
|
4
4
|
import { EventManager } from './EventManager'
|
|
5
5
|
import { EntityListState, EntityRealmState, getEntityMarker, StateNode } from './state'
|
|
6
6
|
import type { TreeStore } from './TreeStore'
|
|
7
|
+
import { SubMutationOperation } from './MutationGenerator'
|
|
7
8
|
|
|
8
9
|
export class AccessorErrorManager {
|
|
9
10
|
private errorsByState: Map<StateNode, ErrorAccessor.ErrorsById> = new Map()
|
|
@@ -45,11 +46,11 @@ export class AccessorErrorManager {
|
|
|
45
46
|
})
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
public replaceErrors(data: MutationDataResponse) {
|
|
49
|
+
public replaceErrors(data: MutationDataResponse, operations: SubMutationOperation[]) {
|
|
49
50
|
this.eventManager.syncOperation(() => {
|
|
50
51
|
this.clearErrors()
|
|
51
52
|
|
|
52
|
-
const preprocessor = new ErrorsPreprocessor(data)
|
|
53
|
+
const preprocessor = new ErrorsPreprocessor(data, operations)
|
|
53
54
|
const errorTreeRoot = preprocessor.preprocess()
|
|
54
55
|
|
|
55
56
|
this.setRootStateErrors(errorTreeRoot)
|
package/src/core/DataBinding.ts
CHANGED
|
@@ -63,9 +63,9 @@ export class DataBinding {
|
|
|
63
63
|
private readonly systemApiClient: GraphQlClient,
|
|
64
64
|
private readonly tenantApiClient: GraphQlClient,
|
|
65
65
|
private readonly environment: Environment,
|
|
66
|
-
private readonly onUpdate: (newData: TreeRootAccessor) => void,
|
|
67
|
-
private readonly onError: (error: RequestError) => void,
|
|
68
|
-
private readonly onPersistSuccess: (result: SuccessfulPersistResult) => void,
|
|
66
|
+
private readonly onUpdate: (newData: TreeRootAccessor, binding: DataBinding) => void,
|
|
67
|
+
private readonly onError: (error: RequestError, binding: DataBinding) => void,
|
|
68
|
+
private readonly onPersistSuccess: (result: SuccessfulPersistResult, binding: DataBinding) => void,
|
|
69
69
|
) {
|
|
70
70
|
this.config = new Config()
|
|
71
71
|
this.treeStore = new TreeStore()
|
|
@@ -143,9 +143,9 @@ export class DataBinding {
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
const generator = new MutationGenerator(this.treeStore)
|
|
146
|
-
const
|
|
146
|
+
const mutationResult = generator.getPersistMutation()
|
|
147
147
|
|
|
148
|
-
if (
|
|
148
|
+
if (mutationResult === undefined) {
|
|
149
149
|
this.dirtinessTracker.reset() // TODO This ideally shouldn't be necessary but given the current limitations, this makes for better UX.
|
|
150
150
|
const persistSuccessOptions: PersistSuccessOptions = {
|
|
151
151
|
...this.bindingOperations,
|
|
@@ -158,17 +158,18 @@ export class DataBinding {
|
|
|
158
158
|
type: 'nothingToPersist',
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
|
+
const { query, operations } = mutationResult
|
|
161
162
|
|
|
162
|
-
const mutationResponse: MutationRequestResponse = await this.contentApiClient.sendRequest(
|
|
163
|
+
const mutationResponse: MutationRequestResponse = await this.contentApiClient.sendRequest(query, {
|
|
163
164
|
signal,
|
|
164
165
|
})
|
|
165
166
|
|
|
166
167
|
if (mutationResponse.errors !== undefined && mutationResponse.errors.length > 0) {
|
|
167
168
|
this.onError({
|
|
168
169
|
type: 'gqlError',
|
|
169
|
-
query
|
|
170
|
+
query,
|
|
170
171
|
errors: mutationResponse.errors,
|
|
171
|
-
})
|
|
172
|
+
}, this)
|
|
172
173
|
}
|
|
173
174
|
if (!mutationResponse.data?.transaction) {
|
|
174
175
|
throw {
|
|
@@ -195,6 +196,7 @@ export class DataBinding {
|
|
|
195
196
|
subTreeResponse.node,
|
|
196
197
|
]),
|
|
197
198
|
),
|
|
199
|
+
operations,
|
|
198
200
|
)
|
|
199
201
|
const persistSuccessOptions: PersistSuccessOptions = {
|
|
200
202
|
...this.bindingOperations,
|
|
@@ -211,13 +213,13 @@ export class DataBinding {
|
|
|
211
213
|
...result,
|
|
212
214
|
afterPersistError: e,
|
|
213
215
|
}
|
|
214
|
-
this.onPersistSuccess(resultWithError)
|
|
216
|
+
this.onPersistSuccess(resultWithError, this)
|
|
215
217
|
return resultWithError
|
|
216
218
|
}
|
|
217
|
-
this.onPersistSuccess(result)
|
|
219
|
+
this.onPersistSuccess(result, this)
|
|
218
220
|
return result
|
|
219
221
|
} else {
|
|
220
|
-
this.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(mutationData))
|
|
222
|
+
this.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(mutationData, operations))
|
|
221
223
|
await this.eventManager.triggerOnPersistError(persistErrorOptions)
|
|
222
224
|
await onPersistError?.(persistErrorOptions)
|
|
223
225
|
if (shouldTryAgain) {
|
|
@@ -248,7 +250,7 @@ export class DataBinding {
|
|
|
248
250
|
}
|
|
249
251
|
|
|
250
252
|
private resolvedOnUpdate = ({ isMutating }: UpdateMetadata) => {
|
|
251
|
-
this.onUpdate(new TreeRootAccessor(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations))
|
|
253
|
+
this.onUpdate(new TreeRootAccessor(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations), this)
|
|
252
254
|
}
|
|
253
255
|
|
|
254
256
|
// This is currently useless but potentially future-compatible
|
|
@@ -339,7 +341,7 @@ export class DataBinding {
|
|
|
339
341
|
}
|
|
340
342
|
|
|
341
343
|
this.eventManager.syncOperation(() => {
|
|
342
|
-
this.treeAugmenter.extendPersistedData(aggregatePersistedData?.data ?? {})
|
|
344
|
+
this.treeAugmenter.extendPersistedData(aggregatePersistedData?.data ?? {}, aggregateMarkerTreeRoot)
|
|
343
345
|
|
|
344
346
|
for (const extension of pendingExtensions) {
|
|
345
347
|
this.treeAugmenter.extendTreeStates(extension.newTreeRootId, extension.markerTreeRoot)
|
|
@@ -368,7 +370,7 @@ export class DataBinding {
|
|
|
368
370
|
if (metadata.name === 'AbortError') {
|
|
369
371
|
return
|
|
370
372
|
}
|
|
371
|
-
this.onError(metadataToRequestError(metadata as GraphQlClientFailedRequestMetadata))
|
|
373
|
+
this.onError(metadataToRequestError(metadata as GraphQlClientFailedRequestMetadata), this)
|
|
372
374
|
}
|
|
373
375
|
|
|
374
376
|
if (queryResponse && queryResponse.errors !== undefined && queryResponse.errors.length > 0) {
|
|
@@ -376,7 +378,7 @@ export class DataBinding {
|
|
|
376
378
|
type: 'gqlError',
|
|
377
379
|
query: query ?? 'unknown query',
|
|
378
380
|
errors: queryResponse.errors,
|
|
379
|
-
})
|
|
381
|
+
}, this)
|
|
380
382
|
}
|
|
381
383
|
|
|
382
384
|
return queryResponse
|
|
@@ -2,10 +2,14 @@ import type { ErrorAccessor } from '../accessors'
|
|
|
2
2
|
import type { ExecutionError, MutationDataResponse, MutationResponse, ValidationError } from '../accessorTree'
|
|
3
3
|
import type { EntityId, FieldName, PlaceholderName } from '../treeParameters'
|
|
4
4
|
import { assertNever } from '../utils'
|
|
5
|
-
import { MutationAlias
|
|
5
|
+
import { MutationAlias } from './requestAliases'
|
|
6
|
+
import { SubMutationOperation } from './MutationGenerator'
|
|
6
7
|
|
|
7
8
|
class ErrorsPreprocessor {
|
|
8
|
-
public constructor(
|
|
9
|
+
public constructor(
|
|
10
|
+
private readonly requestResponse: MutationDataResponse,
|
|
11
|
+
private readonly operations: SubMutationOperation[],
|
|
12
|
+
) {}
|
|
9
13
|
|
|
10
14
|
public preprocess(): ErrorsPreprocessor.ErrorTreeRoot {
|
|
11
15
|
const treeRoot: ErrorsPreprocessor.ErrorTreeRoot = new Map()
|
|
@@ -14,43 +18,37 @@ class ErrorsPreprocessor {
|
|
|
14
18
|
return treeRoot
|
|
15
19
|
}
|
|
16
20
|
|
|
17
|
-
for (const
|
|
18
|
-
const mutationResponse = this.requestResponse[
|
|
21
|
+
for (const operation of this.operations) {
|
|
22
|
+
const mutationResponse = this.requestResponse[operation.alias]
|
|
19
23
|
const processedResponse = this.processMutationResponse(mutationResponse)
|
|
20
24
|
|
|
21
25
|
if (processedResponse === undefined) {
|
|
22
26
|
continue
|
|
23
27
|
}
|
|
28
|
+
const { subTreeType, subTreePlaceholder, id } = operation
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (operation === undefined) {
|
|
28
|
-
continue
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const { subTreeType, subTreePlaceholder, entityId } = operation
|
|
32
|
-
|
|
33
|
-
if (subTreeType === mutationOperationSubTreeType.singleEntity) {
|
|
30
|
+
if (subTreeType === 'single') {
|
|
34
31
|
if (treeRoot.has(subTreePlaceholder)) {
|
|
35
32
|
return this.rejectCorruptData()
|
|
36
33
|
}
|
|
37
34
|
treeRoot.set(subTreePlaceholder, processedResponse)
|
|
38
|
-
} else if (subTreeType ===
|
|
35
|
+
} else if (subTreeType === 'list') {
|
|
39
36
|
const child = treeRoot.get(subTreePlaceholder)
|
|
40
37
|
|
|
41
38
|
if (child === undefined) {
|
|
42
39
|
treeRoot.set(subTreePlaceholder, {
|
|
43
40
|
nodeType: 'iNode',
|
|
44
|
-
children: new Map([[
|
|
41
|
+
children: new Map([[id, processedResponse]]),
|
|
45
42
|
validation: [],
|
|
46
43
|
execution: [],
|
|
47
44
|
})
|
|
48
45
|
} else if (child.nodeType === 'iNode') {
|
|
49
|
-
child.children.set(
|
|
46
|
+
child.children.set(id, processedResponse)
|
|
50
47
|
}
|
|
51
48
|
} else {
|
|
52
49
|
return assertNever(subTreeType)
|
|
53
50
|
}
|
|
51
|
+
|
|
54
52
|
}
|
|
55
53
|
return treeRoot
|
|
56
54
|
}
|