@contember/binding 1.1.0-alpha.1 → 1.1.0-alpha.4
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/accessorPropagation/useEntityListSubTree.js +4 -2
- package/dist/development/accessorPropagation/useEntityListSubTree.js.map +1 -1
- package/dist/development/accessorPropagation/useEntitySubTree.js +4 -2
- package/dist/development/accessorPropagation/useEntitySubTree.js.map +1 -1
- package/dist/development/accessorPropagation/useExtendTree.js +27 -0
- package/dist/development/accessorPropagation/useExtendTree.js.map +1 -0
- package/dist/development/accessorTree/AccessorTree.js +9 -4
- package/dist/development/accessorTree/AccessorTree.js.map +1 -1
- package/dist/development/accessorTree/AccessorTreeStateContext.js +6 -0
- package/dist/development/accessorTree/AccessorTreeStateContext.js.map +1 -0
- package/dist/development/accessorTree/useAccessorTreeState.js +5 -0
- package/dist/development/accessorTree/useAccessorTreeState.js.map +1 -0
- package/dist/development/core/DataBinding.js +1 -1
- package/dist/development/core/DataBinding.js.map +1 -1
- package/dist/development/core/DirtinessTracker.js +4 -13
- package/dist/development/core/DirtinessTracker.js.map +1 -1
- package/dist/development/core/EventManager.js +12 -7
- package/dist/development/core/EventManager.js.map +1 -1
- package/dist/development/core/MutationGenerator.js +95 -89
- package/dist/development/core/MutationGenerator.js.map +1 -1
- package/dist/development/core/StateInitializer.js +15 -18
- package/dist/development/core/StateInitializer.js.map +1 -1
- package/dist/development/core/TreeStore.js +2 -2
- package/dist/development/core/TreeStore.js.map +1 -1
- package/dist/development/core/operations/EntityOperations.js +8 -7
- package/dist/development/core/operations/EntityOperations.js.map +1 -1
- package/dist/development/core/operations/ListOperations.js +1 -1
- package/dist/development/core/operations/ListOperations.js.map +1 -1
- package/dist/development/core/schema/SchemaPreprocessor.js +1 -1
- package/dist/development/core/schema/SchemaPreprocessor.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/Environment.js +11 -1
- package/dist/development/dao/Environment.js.map +1 -1
- package/dist/development/dao/TreeNodeEnvironmentFactory.js +2 -2
- package/dist/development/dao/TreeNodeEnvironmentFactory.js.map +1 -1
- package/dist/development/helperComponents/DeferredSubTrees.js +16 -8
- package/dist/development/helperComponents/DeferredSubTrees.js.map +1 -1
- package/dist/development/helperComponents/If.js +39 -0
- package/dist/development/helperComponents/If.js.map +1 -0
- package/dist/development/helperComponents/SugaredField.js +1 -1
- package/dist/development/helperComponents/helpers/FilterEvaluator.js +38 -0
- package/dist/development/helperComponents/helpers/FilterEvaluator.js.map +1 -0
- package/dist/development/helperComponents/helpers/FilterFieldsCollector.js +41 -0
- package/dist/development/helperComponents/helpers/FilterFieldsCollector.js.map +1 -0
- package/dist/development/helperComponents/helpers/evaluateCondition.js +46 -0
- package/dist/development/helperComponents/helpers/evaluateCondition.js.map +1 -0
- package/dist/development/index.js +3 -0
- package/dist/development/index.js.map +1 -1
- package/dist/development/markers/EntityListSubTreeMarker.js +1 -1
- package/dist/development/markers/EntityListSubTreeMarker.js.map +1 -1
- package/dist/development/markers/EntitySubTreeMarker.js +1 -1
- package/dist/development/markers/EntitySubTreeMarker.js.map +1 -1
- package/dist/development/markers/PlaceholderGenerator.js +4 -4
- package/dist/development/markers/PlaceholderGenerator.js.map +1 -1
- package/dist/development/utils/Hashing.js +21 -6
- package/dist/development/utils/Hashing.js.map +1 -1
- package/dist/production/accessorPropagation/useEntityListSubTree.js +4 -2
- package/dist/production/accessorPropagation/useEntityListSubTree.js.map +1 -1
- package/dist/production/accessorPropagation/useEntitySubTree.js +4 -2
- package/dist/production/accessorPropagation/useEntitySubTree.js.map +1 -1
- package/dist/production/accessorPropagation/useExtendTree.js +27 -0
- package/dist/production/accessorPropagation/useExtendTree.js.map +1 -0
- package/dist/production/accessorTree/AccessorTree.js +9 -4
- package/dist/production/accessorTree/AccessorTree.js.map +1 -1
- package/dist/production/accessorTree/AccessorTreeStateContext.js +6 -0
- package/dist/production/accessorTree/AccessorTreeStateContext.js.map +1 -0
- package/dist/production/accessorTree/useAccessorTreeState.js +5 -0
- package/dist/production/accessorTree/useAccessorTreeState.js.map +1 -0
- package/dist/production/core/DataBinding.js +1 -1
- package/dist/production/core/DataBinding.js.map +1 -1
- package/dist/production/core/DirtinessTracker.js +4 -13
- package/dist/production/core/DirtinessTracker.js.map +1 -1
- package/dist/production/core/EventManager.js +11 -6
- package/dist/production/core/EventManager.js.map +1 -1
- package/dist/production/core/MutationGenerator.js +95 -89
- package/dist/production/core/MutationGenerator.js.map +1 -1
- package/dist/production/core/StateInitializer.js +15 -18
- package/dist/production/core/StateInitializer.js.map +1 -1
- package/dist/production/core/TreeStore.js +2 -2
- package/dist/production/core/TreeStore.js.map +1 -1
- package/dist/production/core/operations/EntityOperations.js +8 -7
- package/dist/production/core/operations/EntityOperations.js.map +1 -1
- package/dist/production/core/operations/ListOperations.js +1 -1
- package/dist/production/core/operations/ListOperations.js.map +1 -1
- package/dist/production/core/schema/SchemaPreprocessor.js +1 -1
- package/dist/production/core/schema/SchemaPreprocessor.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/Environment.js +11 -1
- package/dist/production/dao/Environment.js.map +1 -1
- package/dist/production/dao/TreeNodeEnvironmentFactory.js +2 -2
- package/dist/production/dao/TreeNodeEnvironmentFactory.js.map +1 -1
- package/dist/production/helperComponents/DeferredSubTrees.js +16 -8
- package/dist/production/helperComponents/DeferredSubTrees.js.map +1 -1
- package/dist/production/helperComponents/If.js +39 -0
- package/dist/production/helperComponents/If.js.map +1 -0
- package/dist/production/helperComponents/SugaredField.js +1 -1
- package/dist/production/helperComponents/helpers/FilterEvaluator.js +38 -0
- package/dist/production/helperComponents/helpers/FilterEvaluator.js.map +1 -0
- package/dist/production/helperComponents/helpers/FilterFieldsCollector.js +41 -0
- package/dist/production/helperComponents/helpers/FilterFieldsCollector.js.map +1 -0
- package/dist/production/helperComponents/helpers/evaluateCondition.js +46 -0
- package/dist/production/helperComponents/helpers/evaluateCondition.js.map +1 -0
- package/dist/production/index.js +3 -0
- package/dist/production/index.js.map +1 -1
- package/dist/production/markers/EntityListSubTreeMarker.js +1 -1
- package/dist/production/markers/EntityListSubTreeMarker.js.map +1 -1
- package/dist/production/markers/EntitySubTreeMarker.js +1 -1
- package/dist/production/markers/EntitySubTreeMarker.js.map +1 -1
- package/dist/production/markers/PlaceholderGenerator.js +4 -4
- package/dist/production/markers/PlaceholderGenerator.js.map +1 -1
- package/dist/production/utils/Hashing.js +21 -6
- package/dist/production/utils/Hashing.js.map +1 -1
- package/dist/types/accessorPropagation/index.d.ts +1 -0
- package/dist/types/accessorPropagation/index.d.ts.map +1 -1
- package/dist/types/accessorPropagation/useEntityListSubTree.d.ts +2 -1
- package/dist/types/accessorPropagation/useEntityListSubTree.d.ts.map +1 -1
- package/dist/types/accessorPropagation/useEntitySubTree.d.ts +2 -1
- package/dist/types/accessorPropagation/useEntitySubTree.d.ts.map +1 -1
- package/dist/types/accessorPropagation/useExtendTree.d.ts +5 -0
- package/dist/types/accessorPropagation/useExtendTree.d.ts.map +1 -0
- package/dist/types/accessorTree/AccessorTree.d.ts.map +1 -1
- package/dist/types/accessorTree/AccessorTreeStateContext.d.ts +4 -0
- package/dist/types/accessorTree/AccessorTreeStateContext.d.ts.map +1 -0
- package/dist/types/accessorTree/index.d.ts +1 -0
- package/dist/types/accessorTree/index.d.ts.map +1 -1
- package/dist/types/accessorTree/useAccessorTreeState.d.ts +2 -0
- package/dist/types/accessorTree/useAccessorTreeState.d.ts.map +1 -0
- package/dist/types/core/DataBinding.d.ts.map +1 -1
- package/dist/types/core/DirtinessTracker.d.ts +2 -5
- package/dist/types/core/DirtinessTracker.d.ts.map +1 -1
- package/dist/types/core/EventManager.d.ts +1 -1
- package/dist/types/core/EventManager.d.ts.map +1 -1
- package/dist/types/core/MutationGenerator.d.ts.map +1 -1
- package/dist/types/core/StateInitializer.d.ts +1 -5
- package/dist/types/core/StateInitializer.d.ts.map +1 -1
- package/dist/types/core/TreeStore.d.ts.map +1 -1
- package/dist/types/core/operations/EntityOperations.d.ts.map +1 -1
- package/dist/types/core/operations/ListOperations.d.ts.map +1 -1
- package/dist/types/core/schema/RawSchemaEntity.d.ts +3 -2
- package/dist/types/core/schema/RawSchemaEntity.d.ts.map +1 -1
- package/dist/types/core/schema/SchemaEntity.d.ts +1 -1
- package/dist/types/core/schema/SchemaEntity.d.ts.map +1 -1
- package/dist/types/dao/Environment.d.ts +2 -0
- package/dist/types/dao/Environment.d.ts.map +1 -1
- package/dist/types/helperComponents/DeferredSubTrees.d.ts.map +1 -1
- package/dist/types/helperComponents/If.d.ts +14 -0
- package/dist/types/helperComponents/If.d.ts.map +1 -0
- package/dist/types/helperComponents/helpers/FilterEvaluator.d.ts +9 -0
- package/dist/types/helperComponents/helpers/FilterEvaluator.d.ts.map +1 -0
- package/dist/types/helperComponents/helpers/FilterFieldsCollector.d.ts +10 -0
- package/dist/types/helperComponents/helpers/FilterFieldsCollector.d.ts.map +1 -0
- package/dist/types/helperComponents/helpers/evaluateCondition.d.ts +4 -0
- package/dist/types/helperComponents/helpers/evaluateCondition.d.ts.map +1 -0
- package/dist/types/helperComponents/index.d.ts +1 -0
- package/dist/types/helperComponents/index.d.ts.map +1 -1
- package/dist/types/markers/PlaceholderGenerator.d.ts +3 -2
- package/dist/types/markers/PlaceholderGenerator.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/utils/Hashing.d.ts +3 -2
- package/dist/types/utils/Hashing.d.ts.map +1 -1
- package/package.json +7 -5
- package/src/accessorPropagation/index.ts +1 -0
- package/src/accessorPropagation/useEntityListSubTree.ts +8 -1
- package/src/accessorPropagation/useEntitySubTree.ts +8 -1
- package/src/accessorPropagation/useExtendTree.ts +30 -0
- package/src/accessorTree/AccessorTree.tsx +18 -12
- package/src/accessorTree/AccessorTreeStateContext.ts +6 -0
- package/src/accessorTree/index.ts +1 -0
- package/src/accessorTree/useAccessorTreeState.ts +4 -0
- package/src/core/DataBinding.ts +0 -1
- package/src/core/DirtinessTracker.ts +4 -16
- package/src/core/EventManager.ts +14 -8
- package/src/core/MutationGenerator.ts +132 -125
- package/src/core/StateInitializer.ts +22 -29
- package/src/core/TreeStore.ts +2 -0
- package/src/core/operations/EntityOperations.ts +8 -9
- package/src/core/operations/ListOperations.ts +2 -1
- package/src/core/schema/RawSchemaEntity.ts +1 -2
- package/src/core/schema/SchemaEntity.ts +1 -1
- package/src/core/schema/SchemaPreprocessor.ts +1 -1
- package/src/coreComponents/Entity.tsx +1 -1
- package/src/coreComponents/EntityList.tsx +1 -1
- package/src/dao/Environment.ts +12 -1
- package/src/dao/TreeNodeEnvironmentFactory.ts +2 -2
- package/src/helperComponents/DeferredSubTrees.tsx +19 -13
- package/src/helperComponents/If.tsx +71 -0
- package/src/helperComponents/helpers/FilterEvaluator.ts +48 -0
- package/src/helperComponents/helpers/FilterFieldsCollector.ts +49 -0
- package/src/helperComponents/helpers/evaluateCondition.ts +52 -0
- package/src/helperComponents/index.ts +1 -0
- package/src/markers/EntityListSubTreeMarker.ts +1 -1
- package/src/markers/EntitySubTreeMarker.ts +1 -1
- package/src/markers/PlaceholderGenerator.ts +5 -2
- package/src/utils/Hashing.ts +23 -8
|
@@ -9,6 +9,7 @@ import { mutationOperationSubTreeType } from "./requestAliases/mutationOperation
|
|
|
9
9
|
import { MutationAlias } from "./requestAliases/MutationAlias.js";
|
|
10
10
|
import { assertNever } from "../utils/assertNever.js";
|
|
11
11
|
import { getEntityMarker } from "./state/getEntityMarker.js";
|
|
12
|
+
import { StateIterator } from "./state/StateIterator.js";
|
|
12
13
|
import { HasManyRelationMarker } from "../markers/HasManyRelationMarker.js";
|
|
13
14
|
import { HasOneRelationMarker } from "../markers/HasOneRelationMarker.js";
|
|
14
15
|
class MutationGenerator {
|
|
@@ -19,8 +20,11 @@ class MutationGenerator {
|
|
|
19
20
|
try {
|
|
20
21
|
let builder = new CrudQueryBuilder.CrudQueryBuilder();
|
|
21
22
|
const processedPlaceholdersByEntity = /* @__PURE__ */ new Map();
|
|
22
|
-
for (const [treeRootId, rootStates] of this.treeStore.subTreeStatesByRoot) {
|
|
23
|
-
for (const [placeholderName, subTreeState] of rootStates) {
|
|
23
|
+
for (const [treeRootId, rootStates] of this.treeStore.subTreeStatesByRoot.entries()) {
|
|
24
|
+
for (const [placeholderName, subTreeState] of Array.from(rootStates.entries()).reverse()) {
|
|
25
|
+
if (subTreeState.unpersistedChangesCount <= 0) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
24
28
|
if (subTreeState.type === "entityRealm") {
|
|
25
29
|
builder = this.addSubMutation(processedPlaceholdersByEntity, treeRootId, placeholderName, mutationOperationSubTreeType.singleEntity, subTreeState.entity.id.value, subTreeState, builder);
|
|
26
30
|
} else if (subTreeState.type === "entityList") {
|
|
@@ -132,103 +136,105 @@ class MutationGenerator {
|
|
|
132
136
|
if (currentState.type === "entityRealmStub") {
|
|
133
137
|
return builder;
|
|
134
138
|
}
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
processedPlaceholders.add(placeholderName);
|
|
142
|
-
switch (fieldState.type) {
|
|
143
|
-
case "field": {
|
|
144
|
-
const marker = fieldState.fieldMarker;
|
|
145
|
-
const placeholderName2 = marker.placeholderName;
|
|
146
|
-
if (placeholderName2 === TYPENAME_KEY_NAME || placeholderName2 === PRIMARY_KEY_NAME && !(currentState.entity.id instanceof ClientGeneratedUuid)) {
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
if (marker.isNonbearing) {
|
|
150
|
-
nonbearingFields.push({
|
|
151
|
-
type: "field",
|
|
152
|
-
marker,
|
|
153
|
-
fieldState
|
|
154
|
-
});
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
builder = this.registerCreateFieldPart(fieldState, marker, builder);
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
case "entityRealmStub":
|
|
161
|
-
case "entityRealm": {
|
|
162
|
-
const marker = getEntityMarker(fieldState);
|
|
163
|
-
if (!(marker instanceof HasOneRelationMarker)) {
|
|
164
|
-
throw new BindingError();
|
|
165
|
-
}
|
|
166
|
-
if (pathBack?.fieldBackToParent === marker.parameters.field) {
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
if (marker.parameters.isNonbearing) {
|
|
170
|
-
nonbearingFields.push({
|
|
171
|
-
type: "hasOne",
|
|
172
|
-
marker,
|
|
173
|
-
fieldState
|
|
174
|
-
});
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
builder = this.registerCreateEntityPart(processedPlaceholdersByEntity, fieldState, marker, builder);
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
case "entityList": {
|
|
181
|
-
const marker = fieldState.blueprint.marker;
|
|
182
|
-
if (!(marker instanceof HasManyRelationMarker)) {
|
|
183
|
-
throw new BindingError();
|
|
184
|
-
}
|
|
185
|
-
if (pathBack?.fieldBackToParent === marker.parameters.field) {
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
188
|
-
if (marker.parameters.isNonbearing) {
|
|
189
|
-
nonbearingFields.push({
|
|
190
|
-
type: "hasMany",
|
|
191
|
-
marker,
|
|
192
|
-
fieldState
|
|
193
|
-
});
|
|
194
|
-
continue;
|
|
195
|
-
}
|
|
196
|
-
builder = this.registerCreateEntityListPart(processedPlaceholdersByEntity, fieldState, marker, builder);
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
default: {
|
|
200
|
-
return assertNever();
|
|
139
|
+
for (const siblingState of StateIterator.eachSiblingRealm(currentState)) {
|
|
140
|
+
const pathBack = this.treeStore.getPathBackToParent(siblingState);
|
|
141
|
+
const nonbearingFields = [];
|
|
142
|
+
for (const [placeholderName, fieldState] of siblingState.children) {
|
|
143
|
+
if (processedPlaceholders.has(placeholderName)) {
|
|
144
|
+
continue;
|
|
201
145
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (builder.data !== void 0 && !isEmptyObject(builder.data) || !getEntityMarker(currentState).fields.hasAtLeastOneBearingField) {
|
|
205
|
-
for (const field of nonbearingFields) {
|
|
206
|
-
switch (field.type) {
|
|
146
|
+
processedPlaceholders.add(placeholderName);
|
|
147
|
+
switch (fieldState.type) {
|
|
207
148
|
case "field": {
|
|
208
|
-
|
|
149
|
+
const marker = fieldState.fieldMarker;
|
|
150
|
+
const placeholderName2 = marker.placeholderName;
|
|
151
|
+
if (placeholderName2 === TYPENAME_KEY_NAME || placeholderName2 === PRIMARY_KEY_NAME && !(siblingState.entity.id instanceof ClientGeneratedUuid)) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (marker.isNonbearing) {
|
|
155
|
+
nonbearingFields.push({
|
|
156
|
+
type: "field",
|
|
157
|
+
marker,
|
|
158
|
+
fieldState
|
|
159
|
+
});
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
builder = this.registerCreateFieldPart(fieldState, marker, builder);
|
|
209
163
|
break;
|
|
210
164
|
}
|
|
211
|
-
case "
|
|
212
|
-
|
|
165
|
+
case "entityRealmStub":
|
|
166
|
+
case "entityRealm": {
|
|
167
|
+
const marker = getEntityMarker(fieldState);
|
|
168
|
+
if (!(marker instanceof HasOneRelationMarker)) {
|
|
169
|
+
throw new BindingError();
|
|
170
|
+
}
|
|
171
|
+
if (pathBack?.fieldBackToParent === marker.parameters.field) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (marker.parameters.isNonbearing) {
|
|
175
|
+
nonbearingFields.push({
|
|
176
|
+
type: "hasOne",
|
|
177
|
+
marker,
|
|
178
|
+
fieldState
|
|
179
|
+
});
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
builder = this.registerCreateEntityPart(processedPlaceholdersByEntity, fieldState, marker, builder);
|
|
213
183
|
break;
|
|
214
184
|
}
|
|
215
|
-
case "
|
|
216
|
-
|
|
185
|
+
case "entityList": {
|
|
186
|
+
const marker = fieldState.blueprint.marker;
|
|
187
|
+
if (!(marker instanceof HasManyRelationMarker)) {
|
|
188
|
+
throw new BindingError();
|
|
189
|
+
}
|
|
190
|
+
if (pathBack?.fieldBackToParent === marker.parameters.field) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (marker.parameters.isNonbearing) {
|
|
194
|
+
nonbearingFields.push({
|
|
195
|
+
type: "hasMany",
|
|
196
|
+
marker,
|
|
197
|
+
fieldState
|
|
198
|
+
});
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
builder = this.registerCreateEntityListPart(processedPlaceholdersByEntity, fieldState, marker, builder);
|
|
217
202
|
break;
|
|
218
203
|
}
|
|
219
|
-
default:
|
|
220
|
-
assertNever();
|
|
204
|
+
default: {
|
|
205
|
+
return assertNever();
|
|
206
|
+
}
|
|
221
207
|
}
|
|
222
208
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
209
|
+
if (builder.data !== void 0 && !isEmptyObject(builder.data) || !getEntityMarker(siblingState).fields.hasAtLeastOneBearingField) {
|
|
210
|
+
for (const field of nonbearingFields) {
|
|
211
|
+
switch (field.type) {
|
|
212
|
+
case "field": {
|
|
213
|
+
builder = this.registerCreateFieldPart(field.fieldState, field.marker, builder);
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
case "hasOne": {
|
|
217
|
+
builder = this.registerCreateEntityPart(processedPlaceholdersByEntity, field.fieldState, field.marker, builder);
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
case "hasMany": {
|
|
221
|
+
builder = this.registerCreateEntityListPart(processedPlaceholdersByEntity, field.fieldState, field.marker, builder);
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
default:
|
|
225
|
+
assertNever();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const setOnCreate = getEntityMarker(siblingState).parameters.setOnCreate;
|
|
230
|
+
if (setOnCreate && builder.data !== void 0 && !isEmptyObject(builder.data)) {
|
|
231
|
+
for (const key in setOnCreate) {
|
|
232
|
+
const field = setOnCreate[key];
|
|
233
|
+
if (typeof field === "string" || typeof field === "number" || field === null || field instanceof GraphQlBuilder.GraphQlLiteral) {
|
|
234
|
+
builder = builder.set(key, field);
|
|
235
|
+
} else {
|
|
236
|
+
builder = builder.one(key, (builder2) => builder2.connect(field));
|
|
237
|
+
}
|
|
232
238
|
}
|
|
233
239
|
}
|
|
234
240
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MutationGenerator.js","sources":["../../../src/core/MutationGenerator.ts"],"sourcesContent":["// noinspection JSVoidFunctionReturnValueUsed // IntelliJ seems to be super confused througouht this file.\n\nimport { CrudQueryBuilder, GraphQlBuilder } from '@contember/client'\nimport { ClientGeneratedUuid, ServerId } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '../bindingTypes'\nimport { FieldMarker, HasManyRelationMarker, HasOneRelationMarker } from '../markers'\nimport type { EntityId, EntityName, FieldValue, PlaceholderName, TreeRootId } from '../treeParameters'\nimport { assertNever, isEmptyObject } from '../utils'\nimport { QueryGenerator } from './QueryGenerator'\nimport { MutationAlias, mutationOperationSubTreeType, mutationOperationType } from './requestAliases'\nimport {\n\tEntityListState,\n\tEntityRealmState,\n\tEntityRealmStateStub,\n\tEntityState,\n\tFieldState,\n\tgetEntityMarker,\n} from './state'\nimport type { TreeStore } from './TreeStore'\n\ntype QueryBuilder = Omit<CrudQueryBuilder.CrudQueryBuilder, CrudQueryBuilder.Queries>\n\ntype ProcessedPlaceholdersByEntity = Map<EntityState, Set<PlaceholderName>>\n\n// TODO enforce correct expected mutations in dev mode.\nexport class MutationGenerator {\n\tpublic constructor(private readonly treeStore: TreeStore) {}\n\n\tpublic getPersistMutation(): string | undefined {\n\t\ttry {\n\t\t\tlet builder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder()\n\t\t\tconst processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity = new Map()\n\n\t\t\tfor (const [treeRootId, rootStates] of this.treeStore.subTreeStatesByRoot) {\n\t\t\t\tfor (const [placeholderName, subTreeState] of rootStates) {\n\t\t\t\t\tif (subTreeState.type === 'entityRealm') {\n\t\t\t\t\t\tbuilder = this.addSubMutation(\n\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\ttreeRootId,\n\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\tmutationOperationSubTreeType.singleEntity,\n\t\t\t\t\t\t\tsubTreeState.entity.id.value,\n\t\t\t\t\t\t\tsubTreeState,\n\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t)\n\t\t\t\t\t} else if (subTreeState.type === 'entityList') {\n\t\t\t\t\t\tfor (const childState of subTreeState.children.values()) {\n\t\t\t\t\t\t\tif (childState.type === 'entityRealmStub') {\n\t\t\t\t\t\t\t\t// TODO there can be a forceCreate somewhere in there that we're hereby ignoring.\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbuilder = this.addSubMutation(\n\t\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\t\ttreeRootId,\n\t\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t\tmutationOperationSubTreeType.entityList,\n\t\t\t\t\t\t\t\tchildState.entity.id.value,\n\t\t\t\t\t\t\t\tchildState,\n\t\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (subTreeState.plannedRemovals) {\n\t\t\t\t\t\t\tfor (const [removedId, removalType] of subTreeState.plannedRemovals) {\n\t\t\t\t\t\t\t\tif (removalType === 'disconnect') {\n\t\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\t\t\t\t\tbuilder = this.addDeleteMutation(\n\t\t\t\t\t\t\t\t\t\tsubTreeState.entityName,\n\t\t\t\t\t\t\t\t\t\tremovedId,\n\t\t\t\t\t\t\t\t\t\tMutationAlias.encodeTopLevel({\n\t\t\t\t\t\t\t\t\t\t\ttreeRootId,\n\t\t\t\t\t\t\t\t\t\t\tsubTreePlaceholder: placeholderName,\n\t\t\t\t\t\t\t\t\t\t\ttype: mutationOperationType.delete,\n\t\t\t\t\t\t\t\t\t\t\tsubTreeType: mutationOperationSubTreeType.entityList,\n\t\t\t\t\t\t\t\t\t\t\tentityId: removedId,\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tassertNever(removalType)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tassertNever(subTreeState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn builder.inTransaction(undefined, { deferForeignKeyConstraints: true }).getGql()\n\t\t} catch (e) {\n\t\t\treturn undefined\n\t\t}\n\t}\n\n\tprivate addSubMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\ttreeRootId: TreeRootId | undefined,\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: typeof mutationOperationSubTreeType[keyof typeof mutationOperationSubTreeType],\n\t\tentityId: EntityId,\n\t\trealmState: EntityRealmState,\n\t\tqueryBuilder: QueryBuilder,\n\t): QueryBuilder {\n\t\tif (realmState.unpersistedChangesCount === 0) {\n\t\t\t// Bail out early\n\t\t\treturn queryBuilder\n\t\t}\n\t\tif (realmState.entity.isScheduledForDeletion) {\n\t\t\treturn this.addDeleteMutation(\n\t\t\t\trealmState.entity.entityName,\n\t\t\t\tentityId,\n\t\t\t\tMutationAlias.encodeTopLevel({\n\t\t\t\t\ttreeRootId,\n\t\t\t\t\tsubTreePlaceholder,\n\t\t\t\t\ttype: mutationOperationType.delete,\n\t\t\t\t\tsubTreeType,\n\t\t\t\t\tentityId,\n\t\t\t\t}),\n\t\t\t\tqueryBuilder,\n\t\t\t)\n\t\t} else if (!realmState.entity.id.existsOnServer) {\n\t\t\treturn this.addCreateMutation(\n\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\trealmState,\n\t\t\t\tMutationAlias.encodeTopLevel({\n\t\t\t\t\ttreeRootId,\n\t\t\t\t\tsubTreePlaceholder,\n\t\t\t\t\ttype: mutationOperationType.create,\n\t\t\t\t\tsubTreeType,\n\t\t\t\t\tentityId,\n\t\t\t\t}),\n\t\t\t\tthis.getNodeFragmentName(subTreePlaceholder, subTreeType, realmState),\n\t\t\t\tqueryBuilder,\n\t\t\t)\n\t\t}\n\t\treturn this.addUpdateMutation(\n\t\t\tprocessedPlaceholdersByEntity,\n\t\t\trealmState,\n\t\t\tMutationAlias.encodeTopLevel({\n\t\t\t\ttreeRootId,\n\t\t\t\tsubTreePlaceholder,\n\t\t\t\ttype: mutationOperationType.update,\n\t\t\t\tsubTreeType,\n\t\t\t\tentityId,\n\t\t\t}),\n\t\t\tthis.getNodeFragmentName(subTreePlaceholder, subTreeType, realmState),\n\t\t\tqueryBuilder,\n\t\t)\n\t}\n\n\tprivate getNodeFragmentName(\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: typeof mutationOperationSubTreeType[keyof typeof mutationOperationSubTreeType],\n\t\trealmState: EntityRealmState,\n\t): string | undefined {\n\t\tif (subTreeType !== mutationOperationSubTreeType.entityList) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn `${realmState.entity.entityName}_${subTreePlaceholder}`\n\t}\n\n\tprivate addDeleteMutation(\n\t\tentityName: EntityName,\n\t\tdeletedId: EntityId,\n\t\talias: string,\n\t\tqueryBuilder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder(),\n\t): QueryBuilder {\n\t\treturn queryBuilder.delete(\n\t\t\tentityName,\n\t\t\tbuilder =>\n\t\t\t\tbuilder\n\t\t\t\t\t.ok()\n\t\t\t\t\t.node(builder => builder.column(PRIMARY_KEY_NAME))\n\t\t\t\t\t.by({ [PRIMARY_KEY_NAME]: deletedId })\n\t\t\t\t\t.errors()\n\t\t\t\t\t.errorMessage(),\n\t\t\talias,\n\t\t)\n\t}\n\n\tprivate addUpdateMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tentityRealm: EntityRealmState,\n\t\talias: string,\n\t\tnodeFragmentName: string | undefined,\n\t\tqueryBuilder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder(),\n\t): QueryBuilder {\n\t\tconst updateBuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Update> =\n\t\t\tthis.registerUpdateMutationPart(\n\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\tentityRealm,\n\t\t\t\tnew CrudQueryBuilder.WriteDataBuilder(),\n\t\t\t)\n\t\tif (updateBuilder.data === undefined || isEmptyObject(updateBuilder.data)) {\n\t\t\treturn queryBuilder\n\t\t}\n\n\t\tconst runtimeId = entityRealm.entity.id\n\n\t\tif (!runtimeId.existsOnServer) {\n\t\t\treturn queryBuilder\n\t\t}\n\n\t\tconst readBuilder = QueryGenerator.registerQueryPart(\n\t\t\tgetEntityMarker(entityRealm).fields.markers,\n\t\t\tCrudQueryBuilder.ReadBuilder.instantiate(),\n\t\t)\n\n\t\tif (nodeFragmentName) {\n\t\t\tqueryBuilder = queryBuilder.fragment(nodeFragmentName, entityRealm.entity.entityName, readBuilder)\n\t\t}\n\n\t\treturn queryBuilder.update(\n\t\t\tentityRealm.entity.entityName,\n\t\t\tbuilder =>\n\t\t\t\tbuilder\n\t\t\t\t\t.node(nodeFragmentName ? builder => builder.applyFragment(nodeFragmentName) : readBuilder)\n\t\t\t\t\t.data(updateBuilder)\n\t\t\t\t\t.by({ [PRIMARY_KEY_NAME]: runtimeId.value })\n\t\t\t\t\t.ok()\n\t\t\t\t\t.validation()\n\t\t\t\t\t.errors()\n\t\t\t\t\t.errorMessage(),\n\t\t\talias,\n\t\t)\n\t}\n\n\tprivate addCreateMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tentityRealm: EntityRealmState,\n\t\talias: string,\n\t\tnodeFragmentName: string | undefined,\n\t\tqueryBuilder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder(),\n\t): QueryBuilder {\n\t\tconst createBuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create> =\n\t\t\tthis.registerCreateMutationPart(\n\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\tentityRealm,\n\t\t\t\tnew CrudQueryBuilder.WriteDataBuilder(),\n\t\t\t)\n\t\tif (createBuilder.data === undefined || isEmptyObject(createBuilder.data)) {\n\t\t\treturn queryBuilder\n\t\t}\n\t\tconst readBuilder = QueryGenerator.registerQueryPart(\n\t\t\tgetEntityMarker(entityRealm).fields.markers,\n\t\t\tCrudQueryBuilder.ReadBuilder.instantiate(),\n\t\t)\n\t\tif (nodeFragmentName) {\n\t\t\tqueryBuilder = queryBuilder.fragment(nodeFragmentName, entityRealm.entity.entityName, readBuilder)\n\t\t}\n\n\t\treturn queryBuilder.create(\n\t\t\tentityRealm.entity.entityName,\n\t\t\tbuilder => {\n\t\t\t\t// if (where && writeBuilder.data !== undefined && !isEmptyObject(writeBuilder.data)) {\n\t\t\t\t// \t// Shallow cloning the parameters like this IS too naïve but it will likely last surprisingly long before we\n\t\t\t\t// \t// run into issues.\n\t\t\t\t// \twriteBuilder = new CrudQueryBuilder.WriteDataBuilder({ ...writeBuilder.data, ...where })\n\t\t\t\t// }\n\t\t\t\treturn builder\n\t\t\t\t\t.node(nodeFragmentName ? builder => builder.applyFragment(nodeFragmentName) : readBuilder)\n\t\t\t\t\t.data(createBuilder)\n\t\t\t\t\t.ok()\n\t\t\t\t\t.validation()\n\t\t\t\t\t.errors()\n\t\t\t\t\t.errorMessage()\n\t\t\t},\n\t\t\talias,\n\t\t)\n\t}\n\n\tprivate registerCreateMutationPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tcurrentState: EntityRealmState | EntityRealmStateStub,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create> = new CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>(),\n\t): CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create> {\n\t\tlet processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tprocessedPlaceholdersByEntity.set(currentState.entity, (processedPlaceholders = new Set()))\n\t\t}\n\n\t\tif (currentState.type === 'entityRealmStub') {\n\t\t\t// TODO If there's a forceCreate, this is wrong.\n\t\t\treturn builder\n\t\t}\n\n\t\tconst pathBack = this.treeStore.getPathBackToParent(currentState)\n\n\t\tconst nonbearingFields: Array<\n\t\t\t| { type: 'field'; marker: FieldMarker; fieldState: FieldState }\n\t\t\t| { type: 'hasOne'; marker: HasOneRelationMarker; fieldState: EntityRealmState | EntityRealmStateStub }\n\t\t\t| { type: 'hasMany'; marker: HasManyRelationMarker; fieldState: EntityListState }\n\t\t> = []\n\n\t\tfor (const [placeholderName, fieldState] of currentState.children) {\n\t\t\tif (processedPlaceholders.has(placeholderName)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tprocessedPlaceholders.add(placeholderName)\n\n\t\t\tswitch (fieldState.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tconst marker = fieldState.fieldMarker\n\t\t\t\t\tconst placeholderName = marker.placeholderName\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tplaceholderName === TYPENAME_KEY_NAME ||\n\t\t\t\t\t\t(placeholderName === PRIMARY_KEY_NAME && !(currentState.entity.id instanceof ClientGeneratedUuid))\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif (marker.isNonbearing) {\n\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\ttype: 'field',\n\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tbuilder = this.registerCreateFieldPart(fieldState, marker, builder)\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealmStub':\n\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\tconst marker = getEntityMarker(fieldState)\n\t\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif (marker.parameters.isNonbearing) {\n\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\ttype: 'hasOne',\n\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tbuilder = this.registerCreateEntityPart(processedPlaceholdersByEntity, fieldState, marker, builder)\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tconst marker = fieldState.blueprint.marker\n\t\t\t\t\tif (!(marker instanceof HasManyRelationMarker)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif (marker.parameters.isNonbearing) {\n\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\ttype: 'hasMany',\n\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tbuilder = this.registerCreateEntityListPart(processedPlaceholdersByEntity, fieldState, marker, builder)\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// if (\n\t\t// \tcurrentState.blueprint.creationParameters.forceCreation &&\n\t\t// \t(builder.data === undefined || isEmptyObject(builder.data))\n\t\t// ) {\n\t\t// \tbuilder = builder.set('_dummy_field_', true)\n\t\t// }\n\n\t\tif (\n\t\t\t(builder.data !== undefined && !isEmptyObject(builder.data)) ||\n\t\t\t!getEntityMarker(currentState).fields.hasAtLeastOneBearingField\n\t\t) {\n\t\t\tfor (const field of nonbearingFields) {\n\t\t\t\tswitch (field.type) {\n\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\tbuilder = this.registerCreateFieldPart(field.fieldState, field.marker, builder)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'hasOne': {\n\t\t\t\t\t\tbuilder = this.registerCreateEntityPart(\n\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\tfield.fieldState,\n\t\t\t\t\t\t\tfield.marker,\n\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'hasMany': {\n\t\t\t\t\t\tbuilder = this.registerCreateEntityListPart(\n\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\tfield.fieldState,\n\t\t\t\t\t\t\tfield.marker,\n\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tassertNever(field)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst setOnCreate = getEntityMarker(currentState).parameters.setOnCreate\n\t\tif (setOnCreate && builder.data !== undefined && !isEmptyObject(builder.data)) {\n\t\t\tfor (const key in setOnCreate) {\n\t\t\t\tconst field = setOnCreate[key]\n\n\t\t\t\tif (\n\t\t\t\t\ttypeof field === 'string' ||\n\t\t\t\t\ttypeof field === 'number' ||\n\t\t\t\t\tfield === null ||\n\t\t\t\t\tfield instanceof GraphQlBuilder.GraphQlLiteral\n\t\t\t\t) {\n\t\t\t\t\tbuilder = builder.set(key, field)\n\t\t\t\t} else {\n\t\t\t\t\tbuilder = builder.one(key, builder => builder.connect(field))\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn builder\n\t}\n\n\tprivate registerCreateFieldPart(\n\t\tfieldState: FieldState,\n\t\tmarker: FieldMarker,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>,\n\t) {\n\t\tconst resolvedValue = fieldState.getAccessor().resolvedValue\n\n\t\tif (resolvedValue !== undefined && resolvedValue !== null) {\n\t\t\treturn builder.set(marker.fieldName, this.transformFieldValue(fieldState, resolvedValue))\n\t\t}\n\t\treturn builder\n\t}\n\n\tprivate registerCreateEntityPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tmarker: HasOneRelationMarker,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>,\n\t) {\n\t\tconst reducedBy = marker.parameters.reducedBy\n\t\tconst runtimeId = fieldState.entity.id\n\n\t\tif (reducedBy === undefined) {\n\t\t\treturn builder.one(marker.parameters.field, builder => {\n\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\treturn builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value })\n\t\t\t\t}\n\t\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState))\n\t\t\t})\n\t\t}\n\t\treturn builder.many(marker.parameters.field, builder => {\n\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t// TODO also potentially update\n\t\t\t\treturn builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t}\n\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState), alias)\n\t\t})\n\t}\n\n\tprivate registerCreateEntityListPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tfieldState: EntityListState,\n\t\tmarker: HasManyRelationMarker,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>,\n\t) {\n\t\treturn builder.many(marker.parameters.field, builder => {\n\t\t\tfor (const entityRealm of fieldState.children.values()) {\n\t\t\t\tconst alias = MutationAlias.encodeEntityId(entityRealm.entity.id)\n\t\t\t\tif (entityRealm.entity.id.existsOnServer) {\n\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\tbuilder = builder.connect({ [PRIMARY_KEY_NAME]: entityRealm.entity.id.value }, alias)\n\t\t\t\t} else {\n\t\t\t\t\tbuilder = builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, entityRealm), alias)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn builder\n\t\t})\n\t}\n\n\tprivate registerUpdateMutationPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tcurrentState: EntityRealmState,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Update>,\n\t): CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Update> {\n\t\tlet processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tprocessedPlaceholdersByEntity.set(currentState.entity, (processedPlaceholders = new Set()))\n\t\t}\n\n\t\tconst pathBack = this.treeStore.getPathBackToParent(currentState)\n\t\tconst entityData = this.treeStore.persistedEntityData.get(currentState.entity.id.uniqueValue)\n\n\t\tfor (const [placeholderName, fieldState] of currentState.children) {\n\t\t\tif (placeholderName === PRIMARY_KEY_NAME || placeholderName === TYPENAME_KEY_NAME) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (processedPlaceholders.has(placeholderName)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tprocessedPlaceholders.add(placeholderName)\n\n\t\t\tswitch (fieldState.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (fieldState.persistedValue !== undefined) {\n\t\t\t\t\t\tconst resolvedValue = fieldState.getAccessor().resolvedValue\n\t\t\t\t\t\tif (fieldState.persistedValue !== resolvedValue) {\n\t\t\t\t\t\t\tbuilder = builder.set(placeholderName, this.transformFieldValue(fieldState, resolvedValue))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealmStub':\n\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\tconst marker = getEntityMarker(fieldState)\n\t\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst runtimeId = fieldState.entity.id\n\t\t\t\t\tconst reducedBy = marker.parameters.reducedBy\n\n\t\t\t\t\tif (reducedBy === undefined) {\n\t\t\t\t\t\tconst subBuilder = ((\n\t\t\t\t\t\t\tbuilder: CrudQueryBuilder.WriteOneRelationBuilder<CrudQueryBuilder.WriteOperation.Update>,\n\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\tconst persistedValue = entityData?.get?.(placeholderName)\n\n\t\t\t\t\t\t\tif (persistedValue instanceof ServerId) {\n\t\t\t\t\t\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\t\t\t\t\t\t// The persisted and currently referenced ids match, and so this is an update.\n\t\t\t\t\t\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\t\t\t\t\t\treturn builder // …unless we're dealing with a stub. There cannot be any updates there.\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn builder.update(builder =>\n\t\t\t\t\t\t\t\t\t\tthis.registerUpdateMutationPart(processedPlaceholdersByEntity, fieldState, builder),\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// There was a referenced entity but currently, there is a different one. Let's investigate:\n\n\t\t\t\t\t\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\t\t\t\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\t\t\t\t\t\t// It's planned for deletion.\n\t\t\t\t\t\t\t\t\t// TODO also potentially do something about the current entity\n\t\t\t\t\t\t\t\t\treturn builder.delete()\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\t\t// This isn't the persisted entity but it does exist on the server. Thus this is a connect.\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\treturn builder.connect({\n\t\t\t\t\t\t\t\t\t\t[PRIMARY_KEY_NAME]: runtimeId.value,\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// The currently present entity doesn't exist on the server. Try if creating yields anything…\n\t\t\t\t\t\t\t\tconst subBuilder = builder.create(\n\t\t\t\t\t\t\t\t\tthis.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tif (isEmptyObject(subBuilder.data)) {\n\t\t\t\t\t\t\t\t\t// …and if it doesn't, we just disconnect.\n\t\t\t\t\t\t\t\t\treturn builder.disconnect()\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// …but if it does, we return the create, disconnecting implicitly.\n\t\t\t\t\t\t\t\treturn subBuilder\n\t\t\t\t\t\t\t} else if (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\t// There isn't a linked entity on the server but we're seeing one that exists there.\n\t\t\t\t\t\t\t\t// Thus this is a connect.\n\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\treturn builder.connect({\n\t\t\t\t\t\t\t\t\t[PRIMARY_KEY_NAME]: runtimeId.value,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})(CrudQueryBuilder.WriteOneRelationBuilder.instantiate<CrudQueryBuilder.WriteOperation.Update>())\n\n\t\t\t\t\t\tif (subBuilder.data) {\n\t\t\t\t\t\t\tbuilder = builder.one(marker.parameters.field, subBuilder.data)\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// This is a reduced has many relation.\n\t\t\t\t\t\tbuilder = builder.many(marker.parameters.field, builder => {\n\t\t\t\t\t\t\tconst persistedValue = entityData?.get?.(placeholderName)\n\t\t\t\t\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\t\t\t\t\t\tif (persistedValue instanceof ServerId) {\n\t\t\t\t\t\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\t\t\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\t\t\t\t\t\treturn builder\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn builder.update(\n\t\t\t\t\t\t\t\t\t\treducedBy,\n\t\t\t\t\t\t\t\t\t\tbuilder => this.registerUpdateMutationPart(processedPlaceholdersByEntity, fieldState, builder),\n\t\t\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\t\t\t\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\t\t\t\t\t\t// TODO also potentially do something about the current entity\n\t\t\t\t\t\t\t\t\treturn builder.delete(reducedBy, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\t\t// TODO will re-using the alias like this work?\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\treturn builder.disconnect(reducedBy, alias).connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst subBuilder = builder.create(\n\t\t\t\t\t\t\t\t\tthis.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tif (isEmptyObject(subBuilder.data)) {\n\t\t\t\t\t\t\t\t\treturn builder.disconnect(reducedBy, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn subBuilder\n\t\t\t\t\t\t\t} else if (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\treturn builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tconst marker = fieldState.blueprint.marker\n\t\t\t\t\tif (!(marker instanceof HasManyRelationMarker)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst persistedEntityIds = entityData?.get?.(placeholderName) ?? new Set()\n\n\t\t\t\t\tif (!(persistedEntityIds instanceof Set)) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tbuilder = builder.many(marker.parameters.field, builder => {\n\t\t\t\t\t\tfor (const childState of fieldState.children.values()) {\n\t\t\t\t\t\t\tconst runtimeId = childState.entity.id\n\t\t\t\t\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\t\t\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\tif (persistedEntityIds.has(runtimeId.value)) {\n\t\t\t\t\t\t\t\t\tif (childState.type !== 'entityRealmStub') {\n\t\t\t\t\t\t\t\t\t\t// A stub cannot have any pending changes.\n\t\t\t\t\t\t\t\t\t\tbuilder = builder.update(\n\t\t\t\t\t\t\t\t\t\t\t{ [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t\t\t\t\t\t\tbuilder => this.registerUpdateMutationPart(processedPlaceholdersByEntity, childState, builder),\n\t\t\t\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\tbuilder = builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tbuilder = builder.create(\n\t\t\t\t\t\t\t\t\tthis.registerCreateMutationPart(processedPlaceholdersByEntity, childState),\n\t\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (fieldState.plannedRemovals) {\n\t\t\t\t\t\t\tfor (const [removedId, removalType] of fieldState.plannedRemovals) {\n\t\t\t\t\t\t\t\tconst alias = MutationAlias.encodeEntityId(new ServerId(removedId, fieldState.entityName))\n\t\t\t\t\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\t\t\t\t\tbuilder = builder.delete({ [PRIMARY_KEY_NAME]: removedId }, alias)\n\t\t\t\t\t\t\t\t} else if (removalType === 'disconnect') {\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\tbuilder = builder.disconnect({ [PRIMARY_KEY_NAME]: removedId }, alias)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tassertNever(removalType)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn builder\n\t\t\t\t\t})\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t}\n\t\t}\n\n\t\treturn builder\n\t}\n\n\tprivate transformFieldValue(fieldState: FieldState, value: FieldValue): FieldValue | GraphQlBuilder.GraphQlLiteral {\n\t\tif (typeof value !== 'string') {\n\t\t\treturn value\n\t\t}\n\t\tconst fieldSchema = this.treeStore.schema.getEntityField(\n\t\t\tfieldState.parent.entity.entityName,\n\t\t\tfieldState.fieldMarker.fieldName,\n\t\t)\n\t\tif (fieldSchema === undefined || fieldSchema.__typename !== '_Column') {\n\t\t\tthrow new BindingError()\n\t\t}\n\t\treturn fieldSchema.enumName === null ? value : new GraphQlBuilder.GraphQlLiteral(value)\n\t}\n}\n"],"names":[],"mappings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JSVoidFunctionReturnValueUsed // IntelliJ seems to be super confused througouht this file.\n\nimport { CrudQueryBuilder, GraphQlBuilder } from '@contember/client'\nimport { ClientGeneratedUuid, ServerId } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '../bindingTypes'\nimport { FieldMarker, HasManyRelationMarker, HasOneRelationMarker } from '../markers'\nimport type { EntityId, EntityName, FieldValue, PlaceholderName, TreeRootId } from '../treeParameters'\nimport { assertNever, isEmptyObject } from '../utils'\nimport { QueryGenerator } from './QueryGenerator'\nimport { MutationAlias, mutationOperationSubTreeType, mutationOperationType } from './requestAliases'\nimport {\n\tEntityListState,\n\tEntityRealmState,\n\tEntityRealmStateStub,\n\tEntityState,\n\tFieldState,\n\tgetEntityMarker, RootStateNode, StateIterator,\n} from './state'\nimport type { TreeStore } from './TreeStore'\n\ntype QueryBuilder = Omit<CrudQueryBuilder.CrudQueryBuilder, CrudQueryBuilder.Queries>\n\ntype ProcessedPlaceholdersByEntity = Map<EntityState, Set<PlaceholderName>>\n\n// TODO enforce correct expected mutations in dev mode.\nexport class MutationGenerator {\n\tpublic constructor(private readonly treeStore: TreeStore) {\n\t}\n\n\tpublic getPersistMutation(): string | undefined {\n\t\ttry {\n\t\t\tlet builder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder()\n\t\t\tconst processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity = new Map()\n\n\n\t\t\tfor (const [treeRootId, rootStates] of this.treeStore.subTreeStatesByRoot.entries()) {\n\t\t\t\tfor (const [placeholderName, subTreeState] of Array.from(rootStates.entries()).reverse()) {\n\t\t\t\t\tif (subTreeState.unpersistedChangesCount <= 0) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif (subTreeState.type === 'entityRealm') {\n\t\t\t\t\t\tbuilder = this.addSubMutation(\n\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\ttreeRootId,\n\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\tmutationOperationSubTreeType.singleEntity,\n\t\t\t\t\t\t\tsubTreeState.entity.id.value,\n\t\t\t\t\t\t\tsubTreeState,\n\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t)\n\t\t\t\t\t} else if (subTreeState.type === 'entityList') {\n\t\t\t\t\t\tfor (const childState of subTreeState.children.values()) {\n\t\t\t\t\t\t\tif (childState.type === 'entityRealmStub') {\n\t\t\t\t\t\t\t\t// TODO there can be a forceCreate somewhere in there that we're hereby ignoring.\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbuilder = this.addSubMutation(\n\t\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\t\ttreeRootId,\n\t\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t\tmutationOperationSubTreeType.entityList,\n\t\t\t\t\t\t\t\tchildState.entity.id.value,\n\t\t\t\t\t\t\t\tchildState,\n\t\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (subTreeState.plannedRemovals) {\n\t\t\t\t\t\t\tfor (const [removedId, removalType] of subTreeState.plannedRemovals) {\n\t\t\t\t\t\t\t\tif (removalType === 'disconnect') {\n\t\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\t\t\t\t\tbuilder = this.addDeleteMutation(\n\t\t\t\t\t\t\t\t\t\tsubTreeState.entityName,\n\t\t\t\t\t\t\t\t\t\tremovedId,\n\t\t\t\t\t\t\t\t\t\tMutationAlias.encodeTopLevel({\n\t\t\t\t\t\t\t\t\t\t\ttreeRootId,\n\t\t\t\t\t\t\t\t\t\t\tsubTreePlaceholder: placeholderName,\n\t\t\t\t\t\t\t\t\t\t\ttype: mutationOperationType.delete,\n\t\t\t\t\t\t\t\t\t\t\tsubTreeType: mutationOperationSubTreeType.entityList,\n\t\t\t\t\t\t\t\t\t\t\tentityId: removedId,\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tassertNever(removalType)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tassertNever(subTreeState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn builder.inTransaction(undefined, { deferForeignKeyConstraints: true }).getGql()\n\t\t} catch (e) {\n\t\t\treturn undefined\n\t\t}\n\t}\n\n\tprivate addSubMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\ttreeRootId: TreeRootId | undefined,\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: typeof mutationOperationSubTreeType[keyof typeof mutationOperationSubTreeType],\n\t\tentityId: EntityId,\n\t\trealmState: EntityRealmState,\n\t\tqueryBuilder: QueryBuilder,\n\t): QueryBuilder {\n\t\tif (realmState.unpersistedChangesCount === 0) {\n\t\t\t// Bail out early\n\t\t\treturn queryBuilder\n\t\t}\n\t\tif (realmState.entity.isScheduledForDeletion) {\n\t\t\treturn this.addDeleteMutation(\n\t\t\t\trealmState.entity.entityName,\n\t\t\t\tentityId,\n\t\t\t\tMutationAlias.encodeTopLevel({\n\t\t\t\t\ttreeRootId,\n\t\t\t\t\tsubTreePlaceholder,\n\t\t\t\t\ttype: mutationOperationType.delete,\n\t\t\t\t\tsubTreeType,\n\t\t\t\t\tentityId,\n\t\t\t\t}),\n\t\t\t\tqueryBuilder,\n\t\t\t)\n\t\t} else if (!realmState.entity.id.existsOnServer) {\n\t\t\treturn this.addCreateMutation(\n\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\trealmState,\n\t\t\t\tMutationAlias.encodeTopLevel({\n\t\t\t\t\ttreeRootId,\n\t\t\t\t\tsubTreePlaceholder,\n\t\t\t\t\ttype: mutationOperationType.create,\n\t\t\t\t\tsubTreeType,\n\t\t\t\t\tentityId,\n\t\t\t\t}),\n\t\t\t\tthis.getNodeFragmentName(subTreePlaceholder, subTreeType, realmState),\n\t\t\t\tqueryBuilder,\n\t\t\t)\n\t\t}\n\t\treturn this.addUpdateMutation(\n\t\t\tprocessedPlaceholdersByEntity,\n\t\t\trealmState,\n\t\t\tMutationAlias.encodeTopLevel({\n\t\t\t\ttreeRootId,\n\t\t\t\tsubTreePlaceholder,\n\t\t\t\ttype: mutationOperationType.update,\n\t\t\t\tsubTreeType,\n\t\t\t\tentityId,\n\t\t\t}),\n\t\t\tthis.getNodeFragmentName(subTreePlaceholder, subTreeType, realmState),\n\t\t\tqueryBuilder,\n\t\t)\n\t}\n\n\tprivate getNodeFragmentName(\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: typeof mutationOperationSubTreeType[keyof typeof mutationOperationSubTreeType],\n\t\trealmState: EntityRealmState,\n\t): string | undefined {\n\t\tif (subTreeType !== mutationOperationSubTreeType.entityList) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn `${realmState.entity.entityName}_${subTreePlaceholder}`\n\t}\n\n\tprivate addDeleteMutation(\n\t\tentityName: EntityName,\n\t\tdeletedId: EntityId,\n\t\talias: string,\n\t\tqueryBuilder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder(),\n\t): QueryBuilder {\n\t\treturn queryBuilder.delete(\n\t\t\tentityName,\n\t\t\tbuilder =>\n\t\t\t\tbuilder\n\t\t\t\t\t.ok()\n\t\t\t\t\t.node(builder => builder.column(PRIMARY_KEY_NAME))\n\t\t\t\t\t.by({ [PRIMARY_KEY_NAME]: deletedId })\n\t\t\t\t\t.errors()\n\t\t\t\t\t.errorMessage(),\n\t\t\talias,\n\t\t)\n\t}\n\n\tprivate addUpdateMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tentityRealm: EntityRealmState,\n\t\talias: string,\n\t\tnodeFragmentName: string | undefined,\n\t\tqueryBuilder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder(),\n\t): QueryBuilder {\n\t\tconst updateBuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Update> =\n\t\t\tthis.registerUpdateMutationPart(\n\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\tentityRealm,\n\t\t\t\tnew CrudQueryBuilder.WriteDataBuilder(),\n\t\t\t)\n\t\tif (updateBuilder.data === undefined || isEmptyObject(updateBuilder.data)) {\n\t\t\treturn queryBuilder\n\t\t}\n\n\t\tconst runtimeId = entityRealm.entity.id\n\n\t\tif (!runtimeId.existsOnServer) {\n\t\t\treturn queryBuilder\n\t\t}\n\n\t\tconst readBuilder = QueryGenerator.registerQueryPart(\n\t\t\tgetEntityMarker(entityRealm).fields.markers,\n\t\t\tCrudQueryBuilder.ReadBuilder.instantiate(),\n\t\t)\n\n\t\tif (nodeFragmentName) {\n\t\t\tqueryBuilder = queryBuilder.fragment(nodeFragmentName, entityRealm.entity.entityName, readBuilder)\n\t\t}\n\n\t\treturn queryBuilder.update(\n\t\t\tentityRealm.entity.entityName,\n\t\t\tbuilder =>\n\t\t\t\tbuilder\n\t\t\t\t\t.node(nodeFragmentName ? builder => builder.applyFragment(nodeFragmentName) : readBuilder)\n\t\t\t\t\t.data(updateBuilder)\n\t\t\t\t\t.by({ [PRIMARY_KEY_NAME]: runtimeId.value })\n\t\t\t\t\t.ok()\n\t\t\t\t\t.validation()\n\t\t\t\t\t.errors()\n\t\t\t\t\t.errorMessage(),\n\t\t\talias,\n\t\t)\n\t}\n\n\tprivate addCreateMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tentityRealm: EntityRealmState,\n\t\talias: string,\n\t\tnodeFragmentName: string | undefined,\n\t\tqueryBuilder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder(),\n\t): QueryBuilder {\n\t\tconst createBuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create> =\n\t\t\tthis.registerCreateMutationPart(\n\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\tentityRealm,\n\t\t\t\tnew CrudQueryBuilder.WriteDataBuilder(),\n\t\t\t)\n\t\tif (createBuilder.data === undefined || isEmptyObject(createBuilder.data)) {\n\t\t\treturn queryBuilder\n\t\t}\n\t\tconst readBuilder = QueryGenerator.registerQueryPart(\n\t\t\tgetEntityMarker(entityRealm).fields.markers,\n\t\t\tCrudQueryBuilder.ReadBuilder.instantiate(),\n\t\t)\n\t\tif (nodeFragmentName) {\n\t\t\tqueryBuilder = queryBuilder.fragment(nodeFragmentName, entityRealm.entity.entityName, readBuilder)\n\t\t}\n\n\t\treturn queryBuilder.create(\n\t\t\tentityRealm.entity.entityName,\n\t\t\tbuilder => {\n\t\t\t\t// if (where && writeBuilder.data !== undefined && !isEmptyObject(writeBuilder.data)) {\n\t\t\t\t// \t// Shallow cloning the parameters like this IS too naïve but it will likely last surprisingly long before we\n\t\t\t\t// \t// run into issues.\n\t\t\t\t// \twriteBuilder = new CrudQueryBuilder.WriteDataBuilder({ ...writeBuilder.data, ...where })\n\t\t\t\t// }\n\t\t\t\treturn builder\n\t\t\t\t\t.node(nodeFragmentName ? builder => builder.applyFragment(nodeFragmentName) : readBuilder)\n\t\t\t\t\t.data(createBuilder)\n\t\t\t\t\t.ok()\n\t\t\t\t\t.validation()\n\t\t\t\t\t.errors()\n\t\t\t\t\t.errorMessage()\n\t\t\t},\n\t\t\talias,\n\t\t)\n\t}\n\n\tprivate registerCreateMutationPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tcurrentState: EntityRealmState | EntityRealmStateStub,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create> = new CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>(),\n\t): CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create> {\n\t\tlet processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tprocessedPlaceholdersByEntity.set(currentState.entity, (processedPlaceholders = new Set()))\n\t\t}\n\n\t\tif (currentState.type === 'entityRealmStub') {\n\t\t\t// TODO If there's a forceCreate, this is wrong.\n\t\t\treturn builder\n\t\t}\n\n\t\tfor (const siblingState of StateIterator.eachSiblingRealm(currentState)) {\n\n\t\t\tconst pathBack = this.treeStore.getPathBackToParent(siblingState)\n\n\t\t\tconst nonbearingFields: Array<| { type: 'field'; marker: FieldMarker; fieldState: FieldState }\n\t\t\t\t| { type: 'hasOne'; marker: HasOneRelationMarker; fieldState: EntityRealmState | EntityRealmStateStub }\n\t\t\t\t| { type: 'hasMany'; marker: HasManyRelationMarker; fieldState: EntityListState }> = []\n\n\t\t\tfor (const [placeholderName, fieldState] of siblingState.children) {\n\t\t\t\tif (processedPlaceholders.has(placeholderName)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tprocessedPlaceholders.add(placeholderName)\n\n\t\t\t\tswitch (fieldState.type) {\n\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\tconst marker = fieldState.fieldMarker\n\t\t\t\t\t\tconst placeholderName = marker.placeholderName\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tplaceholderName === TYPENAME_KEY_NAME ||\n\t\t\t\t\t\t\t(placeholderName === PRIMARY_KEY_NAME && !(siblingState.entity.id instanceof ClientGeneratedUuid))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (marker.isNonbearing) {\n\t\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\t\ttype: 'field',\n\t\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbuilder = this.registerCreateFieldPart(fieldState, marker, builder)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'entityRealmStub':\n\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\tconst marker = getEntityMarker(fieldState)\n\t\t\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (marker.parameters.isNonbearing) {\n\t\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\t\ttype: 'hasOne',\n\t\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbuilder = this.registerCreateEntityPart(processedPlaceholdersByEntity, fieldState, marker, builder)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'entityList': {\n\t\t\t\t\t\tconst marker = fieldState.blueprint.marker\n\t\t\t\t\t\tif (!(marker instanceof HasManyRelationMarker)) {\n\t\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (marker.parameters.isNonbearing) {\n\t\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\t\ttype: 'hasMany',\n\t\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbuilder = this.registerCreateEntityListPart(processedPlaceholdersByEntity, fieldState, marker, builder)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// if (\n\t\t\t// \tcurrentState.blueprint.creationParameters.forceCreation &&\n\t\t\t// \t(builder.data === undefined || isEmptyObject(builder.data))\n\t\t\t// ) {\n\t\t\t// \tbuilder = builder.set('_dummy_field_', true)\n\t\t\t// }\n\n\t\t\tif (\n\t\t\t\t(builder.data !== undefined && !isEmptyObject(builder.data)) ||\n\t\t\t\t!getEntityMarker(siblingState).fields.hasAtLeastOneBearingField\n\t\t\t) {\n\t\t\t\tfor (const field of nonbearingFields) {\n\t\t\t\t\tswitch (field.type) {\n\t\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\t\tbuilder = this.registerCreateFieldPart(field.fieldState, field.marker, builder)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'hasOne': {\n\t\t\t\t\t\t\tbuilder = this.registerCreateEntityPart(\n\t\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\t\tfield.fieldState,\n\t\t\t\t\t\t\t\tfield.marker,\n\t\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'hasMany': {\n\t\t\t\t\t\t\tbuilder = this.registerCreateEntityListPart(\n\t\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\t\tfield.fieldState,\n\t\t\t\t\t\t\t\tfield.marker,\n\t\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tassertNever(field)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst setOnCreate = getEntityMarker(siblingState).parameters.setOnCreate\n\t\t\tif (setOnCreate && builder.data !== undefined && !isEmptyObject(builder.data)) {\n\t\t\t\tfor (const key in setOnCreate) {\n\t\t\t\t\tconst field = setOnCreate[key]\n\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof field === 'string' ||\n\t\t\t\t\t\ttypeof field === 'number' ||\n\t\t\t\t\t\tfield === null ||\n\t\t\t\t\t\tfield instanceof GraphQlBuilder.GraphQlLiteral\n\t\t\t\t\t) {\n\t\t\t\t\t\tbuilder = builder.set(key, field)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbuilder = builder.one(key, builder => builder.connect(field))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn builder\n\t}\n\n\tprivate registerCreateFieldPart(\n\t\tfieldState: FieldState,\n\t\tmarker: FieldMarker,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>,\n\t) {\n\t\tconst resolvedValue = fieldState.getAccessor().resolvedValue\n\n\t\tif (resolvedValue !== undefined && resolvedValue !== null) {\n\t\t\treturn builder.set(marker.fieldName, this.transformFieldValue(fieldState, resolvedValue))\n\t\t}\n\t\treturn builder\n\t}\n\n\tprivate registerCreateEntityPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tmarker: HasOneRelationMarker,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>,\n\t) {\n\t\tconst reducedBy = marker.parameters.reducedBy\n\t\tconst runtimeId = fieldState.entity.id\n\n\t\tif (reducedBy === undefined) {\n\t\t\treturn builder.one(marker.parameters.field, builder => {\n\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\treturn builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value })\n\t\t\t\t}\n\t\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState))\n\t\t\t})\n\t\t}\n\t\treturn builder.many(marker.parameters.field, builder => {\n\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t// TODO also potentially update\n\t\t\t\treturn builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t}\n\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState), alias)\n\t\t})\n\t}\n\n\tprivate registerCreateEntityListPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tfieldState: EntityListState,\n\t\tmarker: HasManyRelationMarker,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>,\n\t) {\n\t\treturn builder.many(marker.parameters.field, builder => {\n\t\t\tfor (const entityRealm of fieldState.children.values()) {\n\t\t\t\tconst alias = MutationAlias.encodeEntityId(entityRealm.entity.id)\n\t\t\t\tif (entityRealm.entity.id.existsOnServer) {\n\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\tbuilder = builder.connect({ [PRIMARY_KEY_NAME]: entityRealm.entity.id.value }, alias)\n\t\t\t\t} else {\n\t\t\t\t\tbuilder = builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, entityRealm), alias)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn builder\n\t\t})\n\t}\n\n\tprivate registerUpdateMutationPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tcurrentState: EntityRealmState,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Update>,\n\t): CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Update> {\n\t\tlet processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tprocessedPlaceholdersByEntity.set(currentState.entity, (processedPlaceholders = new Set()))\n\t\t}\n\n\t\tconst pathBack = this.treeStore.getPathBackToParent(currentState)\n\t\tconst entityData = this.treeStore.persistedEntityData.get(currentState.entity.id.uniqueValue)\n\n\t\tfor (const [placeholderName, fieldState] of currentState.children) {\n\t\t\tif (placeholderName === PRIMARY_KEY_NAME || placeholderName === TYPENAME_KEY_NAME) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (processedPlaceholders.has(placeholderName)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tprocessedPlaceholders.add(placeholderName)\n\n\t\t\tswitch (fieldState.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (fieldState.persistedValue !== undefined) {\n\t\t\t\t\t\tconst resolvedValue = fieldState.getAccessor().resolvedValue\n\t\t\t\t\t\tif (fieldState.persistedValue !== resolvedValue) {\n\t\t\t\t\t\t\tbuilder = builder.set(placeholderName, this.transformFieldValue(fieldState, resolvedValue))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealmStub':\n\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\tconst marker = getEntityMarker(fieldState)\n\t\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst runtimeId = fieldState.entity.id\n\t\t\t\t\tconst reducedBy = marker.parameters.reducedBy\n\n\t\t\t\t\tif (reducedBy === undefined) {\n\t\t\t\t\t\tconst subBuilder = ((\n\t\t\t\t\t\t\tbuilder: CrudQueryBuilder.WriteOneRelationBuilder<CrudQueryBuilder.WriteOperation.Update>,\n\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\tconst persistedValue = entityData?.get?.(placeholderName)\n\n\t\t\t\t\t\t\tif (persistedValue instanceof ServerId) {\n\t\t\t\t\t\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\t\t\t\t\t\t// The persisted and currently referenced ids match, and so this is an update.\n\t\t\t\t\t\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\t\t\t\t\t\treturn builder // …unless we're dealing with a stub. There cannot be any updates there.\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn builder.update(builder =>\n\t\t\t\t\t\t\t\t\t\tthis.registerUpdateMutationPart(processedPlaceholdersByEntity, fieldState, builder),\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// There was a referenced entity but currently, there is a different one. Let's investigate:\n\n\t\t\t\t\t\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\t\t\t\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\t\t\t\t\t\t// It's planned for deletion.\n\t\t\t\t\t\t\t\t\t// TODO also potentially do something about the current entity\n\t\t\t\t\t\t\t\t\treturn builder.delete()\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\t\t// This isn't the persisted entity but it does exist on the server. Thus this is a connect.\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\treturn builder.connect({\n\t\t\t\t\t\t\t\t\t\t[PRIMARY_KEY_NAME]: runtimeId.value,\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// The currently present entity doesn't exist on the server. Try if creating yields anything…\n\t\t\t\t\t\t\t\tconst subBuilder = builder.create(\n\t\t\t\t\t\t\t\t\tthis.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tif (isEmptyObject(subBuilder.data)) {\n\t\t\t\t\t\t\t\t\t// …and if it doesn't, we just disconnect.\n\t\t\t\t\t\t\t\t\treturn builder.disconnect()\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// …but if it does, we return the create, disconnecting implicitly.\n\t\t\t\t\t\t\t\treturn subBuilder\n\t\t\t\t\t\t\t} else if (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\t// There isn't a linked entity on the server but we're seeing one that exists there.\n\t\t\t\t\t\t\t\t// Thus this is a connect.\n\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\treturn builder.connect({\n\t\t\t\t\t\t\t\t\t[PRIMARY_KEY_NAME]: runtimeId.value,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})(CrudQueryBuilder.WriteOneRelationBuilder.instantiate<CrudQueryBuilder.WriteOperation.Update>())\n\n\t\t\t\t\t\tif (subBuilder.data) {\n\t\t\t\t\t\t\tbuilder = builder.one(marker.parameters.field, subBuilder.data)\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// This is a reduced has many relation.\n\t\t\t\t\t\tbuilder = builder.many(marker.parameters.field, builder => {\n\t\t\t\t\t\t\tconst persistedValue = entityData?.get?.(placeholderName)\n\t\t\t\t\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\t\t\t\t\t\tif (persistedValue instanceof ServerId) {\n\t\t\t\t\t\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\t\t\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\t\t\t\t\t\treturn builder\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn builder.update(\n\t\t\t\t\t\t\t\t\t\treducedBy,\n\t\t\t\t\t\t\t\t\t\tbuilder => this.registerUpdateMutationPart(processedPlaceholdersByEntity, fieldState, builder),\n\t\t\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\t\t\t\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\t\t\t\t\t\t// TODO also potentially do something about the current entity\n\t\t\t\t\t\t\t\t\treturn builder.delete(reducedBy, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\t\t// TODO will re-using the alias like this work?\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\treturn builder.disconnect(reducedBy, alias).connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst subBuilder = builder.create(\n\t\t\t\t\t\t\t\t\tthis.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tif (isEmptyObject(subBuilder.data)) {\n\t\t\t\t\t\t\t\t\treturn builder.disconnect(reducedBy, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn subBuilder\n\t\t\t\t\t\t\t} else if (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\treturn builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tconst marker = fieldState.blueprint.marker\n\t\t\t\t\tif (!(marker instanceof HasManyRelationMarker)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst persistedEntityIds = entityData?.get?.(placeholderName) ?? new Set()\n\n\t\t\t\t\tif (!(persistedEntityIds instanceof Set)) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tbuilder = builder.many(marker.parameters.field, builder => {\n\t\t\t\t\t\tfor (const childState of fieldState.children.values()) {\n\t\t\t\t\t\t\tconst runtimeId = childState.entity.id\n\t\t\t\t\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\t\t\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\tif (persistedEntityIds.has(runtimeId.value)) {\n\t\t\t\t\t\t\t\t\tif (childState.type !== 'entityRealmStub') {\n\t\t\t\t\t\t\t\t\t\t// A stub cannot have any pending changes.\n\t\t\t\t\t\t\t\t\t\tbuilder = builder.update(\n\t\t\t\t\t\t\t\t\t\t\t{ [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t\t\t\t\t\t\tbuilder => this.registerUpdateMutationPart(processedPlaceholdersByEntity, childState, builder),\n\t\t\t\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\tbuilder = builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tbuilder = builder.create(\n\t\t\t\t\t\t\t\t\tthis.registerCreateMutationPart(processedPlaceholdersByEntity, childState),\n\t\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (fieldState.plannedRemovals) {\n\t\t\t\t\t\t\tfor (const [removedId, removalType] of fieldState.plannedRemovals) {\n\t\t\t\t\t\t\t\tconst alias = MutationAlias.encodeEntityId(new ServerId(removedId, fieldState.entityName))\n\t\t\t\t\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\t\t\t\t\tbuilder = builder.delete({ [PRIMARY_KEY_NAME]: removedId }, alias)\n\t\t\t\t\t\t\t\t} else if (removalType === 'disconnect') {\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\tbuilder = builder.disconnect({ [PRIMARY_KEY_NAME]: removedId }, alias)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tassertNever(removalType)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn builder\n\t\t\t\t\t})\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t}\n\t\t}\n\n\t\treturn builder\n\t}\n\n\tprivate transformFieldValue(fieldState: FieldState, value: FieldValue): FieldValue | GraphQlBuilder.GraphQlLiteral {\n\t\tif (typeof value !== 'string') {\n\t\t\treturn value\n\t\t}\n\t\tconst fieldSchema = this.treeStore.schema.getEntityField(\n\t\t\tfieldState.parent.entity.entityName,\n\t\t\tfieldState.fieldMarker.fieldName,\n\t\t)\n\t\tif (fieldSchema === undefined || fieldSchema.__typename !== '_Column') {\n\t\t\tthrow new BindingError()\n\t\t}\n\t\treturn fieldSchema.enumName === null ? value : new GraphQlBuilder.GraphQlLiteral(value)\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AA0BO,MAAM,kBAAkB;AAAA,EACvB,YAA6B,WAAsB;AAAtB,SAAA,YAAA;AAAA,EACpC;AAAA,EAEO,qBAAyC;AAC3C,QAAA;AACC,UAAA,UAAwB,IAAI,iBAAiB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{ FieldAccessor } from "../accessors/FieldAccessor.js";
|
|
24
24
|
import { EventListenersStore } from "../treeParameters/EventListenersStore.js";
|
|
25
25
|
class StateInitializer {
|
|
26
|
-
constructor(accessorErrorManager, batchUpdatesOptions,
|
|
26
|
+
constructor(accessorErrorManager, batchUpdatesOptions, eventManager, treeStore) {
|
|
27
27
|
__publicField(this, "fieldOperations");
|
|
28
28
|
__publicField(this, "entityOperations");
|
|
29
29
|
__publicField(this, "listOperations");
|
|
30
|
-
this.accessorErrorManager = accessorErrorManager;
|
|
31
|
-
this.batchUpdatesOptions = batchUpdatesOptions;
|
|
32
|
-
this.config = config;
|
|
33
30
|
this.eventManager = eventManager;
|
|
34
31
|
this.treeStore = treeStore;
|
|
35
|
-
this.fieldOperations = new FieldOperations(
|
|
36
|
-
this.entityOperations = new EntityOperations(
|
|
37
|
-
this.listOperations = new ListOperations(
|
|
32
|
+
this.fieldOperations = new FieldOperations(accessorErrorManager, this.eventManager, this, this.treeStore);
|
|
33
|
+
this.entityOperations = new EntityOperations(accessorErrorManager, batchUpdatesOptions, this.eventManager, this, this.treeStore);
|
|
34
|
+
this.listOperations = new ListOperations(accessorErrorManager, batchUpdatesOptions, this.eventManager, this, this.treeStore);
|
|
38
35
|
}
|
|
39
36
|
initializeSubTree(tree) {
|
|
40
37
|
let subTreeState;
|
|
@@ -69,7 +66,7 @@ class StateInitializer {
|
|
|
69
66
|
this.registerEntityRealm(stub);
|
|
70
67
|
return stub;
|
|
71
68
|
}
|
|
72
|
-
const realm = this.createEntityRealm(blueprint, realmKey, entity);
|
|
69
|
+
const realm = this.createEntityRealm(blueprint, realmKey, entity, copyFrom);
|
|
73
70
|
this.registerEntityRealm(realm);
|
|
74
71
|
const marker = getEntityMarker(realm);
|
|
75
72
|
const pathBack = this.treeStore.getPathBackToParent(realm);
|
|
@@ -79,7 +76,7 @@ class StateInitializer {
|
|
|
79
76
|
if (!value || value.type !== "field") {
|
|
80
77
|
throw new BindingError();
|
|
81
78
|
}
|
|
82
|
-
this.initializeFromFieldMarker(realm, field, value
|
|
79
|
+
this.initializeFromFieldMarker(realm, field, void 0, value);
|
|
83
80
|
} else if (field instanceof HasManyRelationMarker) {
|
|
84
81
|
this.initializeFromHasManyRelationMarker(realm, field, /* @__PURE__ */ new Set());
|
|
85
82
|
} else if (field instanceof HasOneRelationMarker) {
|
|
@@ -105,7 +102,7 @@ class StateInitializer {
|
|
|
105
102
|
this.eventManager.registerNewlyInitialized(realm);
|
|
106
103
|
return realm;
|
|
107
104
|
}
|
|
108
|
-
createEntityRealm(blueprint, realmKey, entity) {
|
|
105
|
+
createEntityRealm(blueprint, realmKey, entity, copyFrom) {
|
|
109
106
|
const entityRealm = {
|
|
110
107
|
type: "entityRealm",
|
|
111
108
|
blueprint,
|
|
@@ -118,7 +115,7 @@ class StateInitializer {
|
|
|
118
115
|
eventListeners: this.initializeEntityEventListenerStore(blueprint),
|
|
119
116
|
fieldsWithPendingConnectionUpdates: void 0,
|
|
120
117
|
plannedHasOneDeletions: void 0,
|
|
121
|
-
unpersistedChangesCount: 0,
|
|
118
|
+
unpersistedChangesCount: copyFrom?.unpersistedChangesCount ?? 0,
|
|
122
119
|
getAccessor: () => {
|
|
123
120
|
if (entityRealm.accessor === void 0) {
|
|
124
121
|
const entity2 = entityRealm.entity;
|
|
@@ -222,8 +219,8 @@ class StateInitializer {
|
|
|
222
219
|
this.eventManager.registerNewlyInitialized(entityListState);
|
|
223
220
|
return entityListState;
|
|
224
221
|
}
|
|
225
|
-
initializeFieldState(parent, placeholderName, fieldMarker, persistedValue) {
|
|
226
|
-
const resolvedFieldValue = persistedValue ?? fieldMarker.defaultValue ?? null;
|
|
222
|
+
initializeFieldState(parent, placeholderName, fieldMarker, persistedValue, copyFromState) {
|
|
223
|
+
const resolvedFieldValue = copyFromState ? copyFromState.value : persistedValue ?? fieldMarker.defaultValue ?? null;
|
|
227
224
|
const fieldState = {
|
|
228
225
|
type: "field",
|
|
229
226
|
accessor: void 0,
|
|
@@ -235,7 +232,7 @@ class StateInitializer {
|
|
|
235
232
|
eventListeners: this.initializeFieldEventListenerStore(fieldMarker),
|
|
236
233
|
errors: void 0,
|
|
237
234
|
touchLog: void 0,
|
|
238
|
-
hasUnpersistedChanges: false,
|
|
235
|
+
hasUnpersistedChanges: copyFromState?.hasUnpersistedChanges ?? false,
|
|
239
236
|
getAccessor: () => {
|
|
240
237
|
if (fieldState.accessor === void 0) {
|
|
241
238
|
const fieldSchema = this.treeStore.schema.getEntityField(parent.entity.entityName, fieldMarker.fieldName);
|
|
@@ -253,14 +250,14 @@ class StateInitializer {
|
|
|
253
250
|
this.eventManager.registerNewlyInitialized(fieldState);
|
|
254
251
|
return fieldState;
|
|
255
252
|
}
|
|
256
|
-
initializeFromFieldMarker(parent, field,
|
|
257
|
-
if (
|
|
253
|
+
initializeFromFieldMarker(parent, field, persistedValue, copyFromState) {
|
|
254
|
+
if (persistedValue instanceof Set) {
|
|
258
255
|
throw new BindingError(`Received a collection of referenced entities where a single '${field.fieldName}' field was expected. Perhaps you wanted to use a <Repeater />?`);
|
|
259
256
|
}
|
|
260
|
-
if (
|
|
257
|
+
if (persistedValue instanceof ServerId) {
|
|
261
258
|
throw new BindingError(`Received a referenced entity where a single '${field.fieldName}' field was expected. Perhaps you wanted to use <HasOne />?`);
|
|
262
259
|
}
|
|
263
|
-
parent.children.set(field.placeholderName, this.initializeFieldState(parent, field.placeholderName, field,
|
|
260
|
+
parent.children.set(field.placeholderName, this.initializeFieldState(parent, field.placeholderName, field, persistedValue, copyFromState));
|
|
264
261
|
}
|
|
265
262
|
initializeFromHasOneRelationMarker(parent, field, entityId, copyFrom) {
|
|
266
263
|
parent.children.set(field.placeholderName, this.initializeEntityRealm(entityId, this.getRelationTargetEntityName(parent, field), {
|