@contember/binding 1.1.0-alpha.4 → 1.1.0-alpha.7
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/NormalizedPersistedData.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 +8 -7
- 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.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/coreComponents/Entity.js +1 -1
- package/dist/development/coreComponents/Entity.js.map +1 -1
- package/dist/development/coreComponents/EntityList.js +1 -1
- package/dist/development/coreComponents/EntityList.js.map +1 -1
- package/dist/development/dao/TreeNodeEnvironmentFactory.js +1 -1
- package/dist/development/dao/TreeNodeEnvironmentFactory.js.map +1 -1
- package/dist/development/helperComponents/helpers/evaluateCondition.js.map +1 -1
- package/dist/production/accessorTree/NormalizedPersistedData.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 +8 -7
- 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.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/coreComponents/Entity.js +1 -1
- package/dist/production/coreComponents/Entity.js.map +1 -1
- package/dist/production/coreComponents/EntityList.js +1 -1
- package/dist/production/coreComponents/EntityList.js.map +1 -1
- package/dist/production/dao/TreeNodeEnvironmentFactory.js +1 -1
- package/dist/production/dao/TreeNodeEnvironmentFactory.js.map +1 -1
- package/dist/production/helperComponents/helpers/evaluateCondition.js.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/core/AccessorErrorManager.d.ts +2 -1
- package/dist/types/core/AccessorErrorManager.d.ts.map +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/NormalizedPersistedData.ts +2 -2
- package/src/accessorTree/QueryRequestResponse.ts +2 -2
- package/src/core/AccessorErrorManager.ts +3 -2
- package/src/core/DataBinding.ts +8 -6
- 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 +5 -4
- 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/coreComponents/Entity.tsx +1 -1
- package/src/coreComponents/EntityList.tsx +1 -1
- package/src/dao/TreeNodeEnvironmentFactory.ts +1 -1
- 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.7",
|
|
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.7",
|
|
23
|
+
"@contember/react-client": "1.1.0-alpha.7",
|
|
24
|
+
"@contember/react-multipass-rendering": "1.1.0-alpha.7",
|
|
25
|
+
"@contember/react-utils": "1.1.0-alpha.7",
|
|
26
26
|
"chevrotain": "6.5.0",
|
|
27
27
|
"fast-deep-equal": "^3.1.3",
|
|
28
28
|
"js-levenshtein": "1.1.6",
|
|
@@ -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
|
& {
|
|
@@ -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
|
@@ -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,15 +158,16 @@ 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
|
})
|
|
172
173
|
}
|
|
@@ -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,
|
|
@@ -217,7 +219,7 @@ export class DataBinding {
|
|
|
217
219
|
this.onPersistSuccess(result)
|
|
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) {
|
|
@@ -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)
|
|
@@ -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
|
}
|
|
@@ -4,18 +4,19 @@ import { CrudQueryBuilder, GraphQlBuilder } from '@contember/client'
|
|
|
4
4
|
import { ClientGeneratedUuid, ServerId } from '../accessorTree'
|
|
5
5
|
import { BindingError } from '../BindingError'
|
|
6
6
|
import { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '../bindingTypes'
|
|
7
|
-
import { FieldMarker, HasManyRelationMarker, HasOneRelationMarker } from '../markers'
|
|
8
|
-
import type { EntityId, EntityName, FieldValue, PlaceholderName
|
|
7
|
+
import { EntityFieldMarkers, FieldMarker, HasManyRelationMarker, HasOneRelationMarker } from '../markers'
|
|
8
|
+
import type { EntityId, EntityName, FieldValue, PlaceholderName } from '../treeParameters'
|
|
9
9
|
import { assertNever, isEmptyObject } from '../utils'
|
|
10
10
|
import { QueryGenerator } from './QueryGenerator'
|
|
11
|
-
import { MutationAlias
|
|
11
|
+
import { MutationAlias } from './requestAliases'
|
|
12
12
|
import {
|
|
13
13
|
EntityListState,
|
|
14
14
|
EntityRealmState,
|
|
15
15
|
EntityRealmStateStub,
|
|
16
16
|
EntityState,
|
|
17
17
|
FieldState,
|
|
18
|
-
getEntityMarker,
|
|
18
|
+
getEntityMarker,
|
|
19
|
+
StateIterator,
|
|
19
20
|
} from './state'
|
|
20
21
|
import type { TreeStore } from './TreeStore'
|
|
21
22
|
|
|
@@ -23,14 +24,35 @@ type QueryBuilder = Omit<CrudQueryBuilder.CrudQueryBuilder, CrudQueryBuilder.Que
|
|
|
23
24
|
|
|
24
25
|
type ProcessedPlaceholdersByEntity = Map<EntityState, Set<PlaceholderName>>
|
|
25
26
|
|
|
27
|
+
export type SubMutationOperation =
|
|
28
|
+
& {
|
|
29
|
+
alias: string,
|
|
30
|
+
subTreePlaceholder: PlaceholderName,
|
|
31
|
+
subTreeType: 'list' | 'single'
|
|
32
|
+
}
|
|
33
|
+
& (
|
|
34
|
+
| { type: 'delete', id: EntityId }
|
|
35
|
+
| { type: 'update', markers: EntityFieldMarkers, id: EntityId }
|
|
36
|
+
| { type: 'create', markers: EntityFieldMarkers, id: EntityId }
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
export type PersistMutationResult = {
|
|
40
|
+
query: string
|
|
41
|
+
operations: SubMutationOperation[]
|
|
42
|
+
}
|
|
43
|
+
|
|
26
44
|
// TODO enforce correct expected mutations in dev mode.
|
|
27
45
|
export class MutationGenerator {
|
|
46
|
+
|
|
47
|
+
private aliasCounter = 1
|
|
48
|
+
|
|
28
49
|
public constructor(private readonly treeStore: TreeStore) {
|
|
29
50
|
}
|
|
30
51
|
|
|
31
|
-
public getPersistMutation():
|
|
52
|
+
public getPersistMutation(): PersistMutationResult | undefined {
|
|
32
53
|
try {
|
|
33
54
|
let builder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder()
|
|
55
|
+
const operations: SubMutationOperation[] = []
|
|
34
56
|
const processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity = new Map()
|
|
35
57
|
|
|
36
58
|
|
|
@@ -40,30 +62,36 @@ export class MutationGenerator {
|
|
|
40
62
|
continue
|
|
41
63
|
}
|
|
42
64
|
if (subTreeState.type === 'entityRealm') {
|
|
43
|
-
|
|
65
|
+
const subMutation = this.addSubMutation(
|
|
44
66
|
processedPlaceholdersByEntity,
|
|
45
|
-
treeRootId,
|
|
46
67
|
placeholderName,
|
|
47
|
-
|
|
68
|
+
'single',
|
|
48
69
|
subTreeState.entity.id.value,
|
|
49
70
|
subTreeState,
|
|
50
71
|
builder,
|
|
51
72
|
)
|
|
73
|
+
if (subMutation) {
|
|
74
|
+
builder = subMutation[0]
|
|
75
|
+
operations.push(subMutation[1])
|
|
76
|
+
}
|
|
52
77
|
} else if (subTreeState.type === 'entityList') {
|
|
53
78
|
for (const childState of subTreeState.children.values()) {
|
|
54
79
|
if (childState.type === 'entityRealmStub') {
|
|
55
80
|
// TODO there can be a forceCreate somewhere in there that we're hereby ignoring.
|
|
56
81
|
continue
|
|
57
82
|
}
|
|
58
|
-
|
|
83
|
+
const subMutation = this.addSubMutation(
|
|
59
84
|
processedPlaceholdersByEntity,
|
|
60
|
-
treeRootId,
|
|
61
85
|
placeholderName,
|
|
62
|
-
|
|
86
|
+
'list',
|
|
63
87
|
childState.entity.id.value,
|
|
64
88
|
childState,
|
|
65
89
|
builder,
|
|
66
90
|
)
|
|
91
|
+
if (subMutation) {
|
|
92
|
+
builder = subMutation[0]
|
|
93
|
+
operations.push(subMutation[1])
|
|
94
|
+
}
|
|
67
95
|
}
|
|
68
96
|
if (subTreeState.plannedRemovals) {
|
|
69
97
|
for (const [removedId, removalType] of subTreeState.plannedRemovals) {
|
|
@@ -71,18 +99,14 @@ export class MutationGenerator {
|
|
|
71
99
|
continue
|
|
72
100
|
}
|
|
73
101
|
if (removalType === 'delete') {
|
|
102
|
+
const alias = this.createAlias()
|
|
74
103
|
builder = this.addDeleteMutation(
|
|
75
104
|
subTreeState.entityName,
|
|
76
105
|
removedId,
|
|
77
|
-
|
|
78
|
-
treeRootId,
|
|
79
|
-
subTreePlaceholder: placeholderName,
|
|
80
|
-
type: mutationOperationType.delete,
|
|
81
|
-
subTreeType: mutationOperationSubTreeType.entityList,
|
|
82
|
-
entityId: removedId,
|
|
83
|
-
}),
|
|
106
|
+
alias,
|
|
84
107
|
builder,
|
|
85
108
|
)
|
|
109
|
+
operations.push({ alias, subTreePlaceholder: placeholderName, subTreeType: 'list', type: 'delete', id: removedId })
|
|
86
110
|
} else {
|
|
87
111
|
assertNever(removalType)
|
|
88
112
|
}
|
|
@@ -94,7 +118,8 @@ export class MutationGenerator {
|
|
|
94
118
|
}
|
|
95
119
|
}
|
|
96
120
|
|
|
97
|
-
|
|
121
|
+
const query = builder.inTransaction(undefined, { deferForeignKeyConstraints: true }).getGql()
|
|
122
|
+
return { query, operations }
|
|
98
123
|
} catch (e) {
|
|
99
124
|
return undefined
|
|
100
125
|
}
|
|
@@ -102,66 +127,91 @@ export class MutationGenerator {
|
|
|
102
127
|
|
|
103
128
|
private addSubMutation(
|
|
104
129
|
processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,
|
|
105
|
-
treeRootId: TreeRootId | undefined,
|
|
106
130
|
subTreePlaceholder: PlaceholderName,
|
|
107
|
-
subTreeType:
|
|
131
|
+
subTreeType: 'list' | 'single',
|
|
108
132
|
entityId: EntityId,
|
|
109
133
|
realmState: EntityRealmState,
|
|
110
134
|
queryBuilder: QueryBuilder,
|
|
111
|
-
): QueryBuilder {
|
|
135
|
+
): [QueryBuilder, SubMutationOperation] | undefined {
|
|
112
136
|
if (realmState.unpersistedChangesCount === 0) {
|
|
113
137
|
// Bail out early
|
|
114
|
-
return
|
|
138
|
+
return undefined
|
|
115
139
|
}
|
|
140
|
+
const fieldMarkers = getEntityMarker(realmState).fields.markers
|
|
141
|
+
|
|
142
|
+
const alias = this.createAlias()
|
|
143
|
+
|
|
116
144
|
if (realmState.entity.isScheduledForDeletion) {
|
|
117
|
-
|
|
145
|
+
const builder = this.addDeleteMutation(
|
|
118
146
|
realmState.entity.entityName,
|
|
119
147
|
entityId,
|
|
120
|
-
|
|
121
|
-
treeRootId,
|
|
122
|
-
subTreePlaceholder,
|
|
123
|
-
type: mutationOperationType.delete,
|
|
124
|
-
subTreeType,
|
|
125
|
-
entityId,
|
|
126
|
-
}),
|
|
148
|
+
alias,
|
|
127
149
|
queryBuilder,
|
|
128
150
|
)
|
|
151
|
+
return [
|
|
152
|
+
builder,
|
|
153
|
+
{
|
|
154
|
+
alias,
|
|
155
|
+
subTreePlaceholder,
|
|
156
|
+
subTreeType,
|
|
157
|
+
type: 'delete',
|
|
158
|
+
id: entityId,
|
|
159
|
+
},
|
|
160
|
+
]
|
|
129
161
|
} else if (!realmState.entity.id.existsOnServer) {
|
|
130
|
-
|
|
162
|
+
const builder = this.addCreateMutation(
|
|
131
163
|
processedPlaceholdersByEntity,
|
|
132
164
|
realmState,
|
|
133
|
-
|
|
134
|
-
treeRootId,
|
|
135
|
-
subTreePlaceholder,
|
|
136
|
-
type: mutationOperationType.create,
|
|
137
|
-
subTreeType,
|
|
138
|
-
entityId,
|
|
139
|
-
}),
|
|
165
|
+
alias,
|
|
140
166
|
this.getNodeFragmentName(subTreePlaceholder, subTreeType, realmState),
|
|
141
167
|
queryBuilder,
|
|
168
|
+
fieldMarkers,
|
|
142
169
|
)
|
|
170
|
+
if (!builder) {
|
|
171
|
+
return undefined
|
|
172
|
+
}
|
|
173
|
+
return [
|
|
174
|
+
builder,
|
|
175
|
+
{
|
|
176
|
+
alias,
|
|
177
|
+
subTreePlaceholder,
|
|
178
|
+
subTreeType,
|
|
179
|
+
type: 'create',
|
|
180
|
+
markers: fieldMarkers,
|
|
181
|
+
id: entityId,
|
|
182
|
+
},
|
|
183
|
+
]
|
|
143
184
|
}
|
|
144
|
-
|
|
185
|
+
const builder = this.addUpdateMutation(
|
|
145
186
|
processedPlaceholdersByEntity,
|
|
146
187
|
realmState,
|
|
147
|
-
|
|
148
|
-
treeRootId,
|
|
149
|
-
subTreePlaceholder,
|
|
150
|
-
type: mutationOperationType.update,
|
|
151
|
-
subTreeType,
|
|
152
|
-
entityId,
|
|
153
|
-
}),
|
|
188
|
+
alias,
|
|
154
189
|
this.getNodeFragmentName(subTreePlaceholder, subTreeType, realmState),
|
|
155
190
|
queryBuilder,
|
|
191
|
+
fieldMarkers,
|
|
156
192
|
)
|
|
193
|
+
if (!builder) {
|
|
194
|
+
return undefined
|
|
195
|
+
}
|
|
196
|
+
return [
|
|
197
|
+
builder,
|
|
198
|
+
{
|
|
199
|
+
alias,
|
|
200
|
+
subTreePlaceholder,
|
|
201
|
+
subTreeType,
|
|
202
|
+
type: 'update',
|
|
203
|
+
id: entityId,
|
|
204
|
+
markers: fieldMarkers,
|
|
205
|
+
},
|
|
206
|
+
]
|
|
157
207
|
}
|
|
158
208
|
|
|
159
209
|
private getNodeFragmentName(
|
|
160
210
|
subTreePlaceholder: PlaceholderName,
|
|
161
|
-
subTreeType:
|
|
211
|
+
subTreeType: 'single' | 'list',
|
|
162
212
|
realmState: EntityRealmState,
|
|
163
213
|
): string | undefined {
|
|
164
|
-
if (subTreeType !==
|
|
214
|
+
if (subTreeType !== 'list') {
|
|
165
215
|
return undefined
|
|
166
216
|
}
|
|
167
217
|
return `${realmState.entity.entityName}_${subTreePlaceholder}`
|
|
@@ -192,7 +242,8 @@ export class MutationGenerator {
|
|
|
192
242
|
alias: string,
|
|
193
243
|
nodeFragmentName: string | undefined,
|
|
194
244
|
queryBuilder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder(),
|
|
195
|
-
|
|
245
|
+
fieldMarkers: EntityFieldMarkers,
|
|
246
|
+
): QueryBuilder | undefined {
|
|
196
247
|
const updateBuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Update> =
|
|
197
248
|
this.registerUpdateMutationPart(
|
|
198
249
|
processedPlaceholdersByEntity,
|
|
@@ -200,17 +251,17 @@ export class MutationGenerator {
|
|
|
200
251
|
new CrudQueryBuilder.WriteDataBuilder(),
|
|
201
252
|
)
|
|
202
253
|
if (updateBuilder.data === undefined || isEmptyObject(updateBuilder.data)) {
|
|
203
|
-
return
|
|
254
|
+
return undefined
|
|
204
255
|
}
|
|
205
256
|
|
|
206
257
|
const runtimeId = entityRealm.entity.id
|
|
207
258
|
|
|
208
259
|
if (!runtimeId.existsOnServer) {
|
|
209
|
-
return
|
|
260
|
+
return undefined
|
|
210
261
|
}
|
|
211
262
|
|
|
212
263
|
const readBuilder = QueryGenerator.registerQueryPart(
|
|
213
|
-
|
|
264
|
+
fieldMarkers,
|
|
214
265
|
CrudQueryBuilder.ReadBuilder.instantiate(),
|
|
215
266
|
)
|
|
216
267
|
|
|
@@ -239,7 +290,8 @@ export class MutationGenerator {
|
|
|
239
290
|
alias: string,
|
|
240
291
|
nodeFragmentName: string | undefined,
|
|
241
292
|
queryBuilder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder(),
|
|
242
|
-
|
|
293
|
+
fieldMarkers: EntityFieldMarkers,
|
|
294
|
+
): QueryBuilder | undefined {
|
|
243
295
|
const createBuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create> =
|
|
244
296
|
this.registerCreateMutationPart(
|
|
245
297
|
processedPlaceholdersByEntity,
|
|
@@ -247,10 +299,10 @@ export class MutationGenerator {
|
|
|
247
299
|
new CrudQueryBuilder.WriteDataBuilder(),
|
|
248
300
|
)
|
|
249
301
|
if (createBuilder.data === undefined || isEmptyObject(createBuilder.data)) {
|
|
250
|
-
return
|
|
302
|
+
return undefined
|
|
251
303
|
}
|
|
252
304
|
const readBuilder = QueryGenerator.registerQueryPart(
|
|
253
|
-
|
|
305
|
+
fieldMarkers,
|
|
254
306
|
CrudQueryBuilder.ReadBuilder.instantiate(),
|
|
255
307
|
)
|
|
256
308
|
if (nodeFragmentName) {
|
|
@@ -720,4 +772,8 @@ export class MutationGenerator {
|
|
|
720
772
|
}
|
|
721
773
|
return fieldSchema.enumName === null ? value : new GraphQlBuilder.GraphQlLiteral(value)
|
|
722
774
|
}
|
|
775
|
+
|
|
776
|
+
private createAlias(): string {
|
|
777
|
+
return `op_${this.aliasCounter++}`
|
|
778
|
+
}
|
|
723
779
|
}
|