@contember/binding 1.1.0-alpha.5 → 1.1.0-alpha.8
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 +5 -1
- package/dist/development/core/StateInitializer.js.map +1 -1
- package/dist/development/core/TreeAugmenter.js +4 -4
- package/dist/development/core/TreeAugmenter.js.map +1 -1
- package/dist/development/core/TreeStore.js +4 -4
- package/dist/development/core/TreeStore.js.map +1 -1
- package/dist/development/core/VariableInputTransformer.js.map +1 -1
- package/dist/development/core/requestAliases/MutationAlias.js +2 -40
- package/dist/development/core/requestAliases/MutationAlias.js.map +1 -1
- package/dist/development/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/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 +5 -1
- package/dist/production/core/StateInitializer.js.map +1 -1
- package/dist/production/core/TreeAugmenter.js +4 -4
- package/dist/production/core/TreeAugmenter.js.map +1 -1
- package/dist/production/core/TreeStore.js +4 -4
- package/dist/production/core/TreeStore.js.map +1 -1
- package/dist/production/core/VariableInputTransformer.js.map +1 -1
- package/dist/production/core/requestAliases/MutationAlias.js +2 -33
- package/dist/production/core/requestAliases/MutationAlias.js.map +1 -1
- package/dist/production/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/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 +10 -6
- package/src/core/TreeAugmenter.ts +5 -4
- package/src/core/TreeStore.ts +5 -4
- package/src/core/VariableInputTransformer.ts +2 -2
- package/src/core/requestAliases/MutationAlias.ts +2 -57
- package/src/core/requestAliases/index.ts +0 -3
- package/src/core/state/FieldState.ts +2 -2
- package/src/coreComponents/Entity.tsx +1 -1
- package/src/coreComponents/EntityList.tsx +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
|
@@ -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, 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,iBA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"],"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 { EntityFieldMarkers, FieldMarker, HasManyRelationMarker, HasOneRelationMarker } from '../markers'\nimport type { EntityId, EntityName, FieldValue, PlaceholderName } from '../treeParameters'\nimport { assertNever, isEmptyObject } from '../utils'\nimport { QueryGenerator } from './QueryGenerator'\nimport { MutationAlias } from './requestAliases'\nimport {\n\tEntityListState,\n\tEntityRealmState,\n\tEntityRealmStateStub,\n\tEntityState,\n\tFieldState,\n\tgetEntityMarker,\n\tStateIterator,\n} from './state'\nimport type { TreeStore } from './TreeStore'\n\ntype QueryBuilder = Omit<CrudQueryBuilder.CrudQueryBuilder, CrudQueryBuilder.Queries>\n\ntype ProcessedPlaceholdersByEntity = Map<EntityState, Set<PlaceholderName>>\n\nexport type SubMutationOperation =\n\t& {\n\t\talias: string,\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: 'list' | 'single'\n\t}\n\t& (\n\t\t| { type: 'delete', id: EntityId }\n\t\t| { type: 'update', markers: EntityFieldMarkers, id: EntityId }\n\t\t| { type: 'create', markers: EntityFieldMarkers, id: EntityId }\n\t)\n\nexport type PersistMutationResult = {\n\tquery: string\n\toperations: SubMutationOperation[]\n}\n\n// TODO enforce correct expected mutations in dev mode.\nexport class MutationGenerator {\n\n\tprivate aliasCounter = 1\n\n\tpublic constructor(private readonly treeStore: TreeStore) {\n\t}\n\n\tpublic getPersistMutation(): PersistMutationResult | undefined {\n\t\ttry {\n\t\t\tlet builder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder()\n\t\t\tconst operations: SubMutationOperation[] = []\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\tconst subMutation = this.addSubMutation(\n\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t'single',\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\tif (subMutation) {\n\t\t\t\t\t\t\tbuilder = subMutation[0]\n\t\t\t\t\t\t\toperations.push(subMutation[1])\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\tconst subMutation = this.addSubMutation(\n\t\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t\t'list',\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\tif (subMutation) {\n\t\t\t\t\t\t\t\tbuilder = subMutation[0]\n\t\t\t\t\t\t\t\toperations.push(subMutation[1])\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\tconst alias = this.createAlias()\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\talias,\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\toperations.push({ alias, subTreePlaceholder: placeholderName, subTreeType: 'list', type: 'delete', id: removedId })\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\tconst query = builder.inTransaction(undefined, { deferForeignKeyConstraints: true }).getGql()\n\t\t\treturn { query, operations }\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\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: 'list' | 'single',\n\t\tentityId: EntityId,\n\t\trealmState: EntityRealmState,\n\t\tqueryBuilder: QueryBuilder,\n\t): [QueryBuilder, SubMutationOperation] | undefined {\n\t\tif (realmState.unpersistedChangesCount === 0) {\n\t\t\t// Bail out early\n\t\t\treturn undefined\n\t\t}\n\t\tconst fieldMarkers = getEntityMarker(realmState).fields.markers\n\n\t\tconst alias = this.createAlias()\n\n\t\tif (realmState.entity.isScheduledForDeletion) {\n\t\t\tconst builder = this.addDeleteMutation(\n\t\t\t\trealmState.entity.entityName,\n\t\t\t\tentityId,\n\t\t\t\talias,\n\t\t\t\tqueryBuilder,\n\t\t\t)\n\t\t\treturn [\n\t\t\t\tbuilder,\n\t\t\t\t{\n\t\t\t\t\talias,\n\t\t\t\t\tsubTreePlaceholder,\n\t\t\t\t\tsubTreeType,\n\t\t\t\t\ttype: 'delete',\n\t\t\t\t\tid: entityId,\n\t\t\t\t},\n\t\t\t]\n\t\t} else if (!realmState.entity.id.existsOnServer) {\n\t\t\tconst builder = this.addCreateMutation(\n\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\trealmState,\n\t\t\t\talias,\n\t\t\t\tthis.getNodeFragmentName(subTreePlaceholder, subTreeType, realmState),\n\t\t\t\tqueryBuilder,\n\t\t\t\tfieldMarkers,\n\t\t\t)\n\t\t\tif (!builder) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn [\n\t\t\t\tbuilder,\n\t\t\t\t{\n\t\t\t\t\talias,\n\t\t\t\t\tsubTreePlaceholder,\n\t\t\t\t\tsubTreeType,\n\t\t\t\t\ttype: 'create',\n\t\t\t\t\tmarkers: fieldMarkers,\n\t\t\t\t\tid: entityId,\n\t\t\t\t},\n]\n\t\t}\n\t\tconst builder = this.addUpdateMutation(\n\t\t\tprocessedPlaceholdersByEntity,\n\t\t\trealmState,\n\t\t\talias,\n\t\t\tthis.getNodeFragmentName(subTreePlaceholder, subTreeType, realmState),\n\t\t\tqueryBuilder,\n\t\t\tfieldMarkers,\n\t\t)\n\t\tif (!builder) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn [\n\t\t\tbuilder,\n\t\t\t{\n\t\t\t\talias,\n\t\t\t\tsubTreePlaceholder,\n\t\t\t\tsubTreeType,\n\t\t\t\ttype: 'update',\n\t\t\t\tid: entityId,\n\t\t\t\tmarkers: fieldMarkers,\n\t\t\t},\n\t\t]\n\t}\n\n\tprivate getNodeFragmentName(\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: 'single' | 'list',\n\t\trealmState: EntityRealmState,\n\t): string | undefined {\n\t\tif (subTreeType !== 'list') {\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\tfieldMarkers: EntityFieldMarkers,\n\t): QueryBuilder | undefined {\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 undefined\n\t\t}\n\n\t\tconst runtimeId = entityRealm.entity.id\n\n\t\tif (!runtimeId.existsOnServer) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst readBuilder = QueryGenerator.registerQueryPart(\n\t\t\tfieldMarkers,\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\tfieldMarkers: EntityFieldMarkers,\n\t): QueryBuilder | undefined {\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 undefined\n\t\t}\n\t\tconst readBuilder = QueryGenerator.registerQueryPart(\n\t\t\tfieldMarkers,\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\tprivate createAlias(): string {\n\t\treturn `op_${this.aliasCounter++}`\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AA4CO,MAAM,kBAAkB;AAAA,EAIvB,YAA6B,WAAsB;AAFlD,wCAAe;AAEa,SAAA,YAAA;AAAA,EACpC;AAAA,EAEO,qBAAwD;AAC1D,QAAA;AACC,UAAA,UAAwB,IAAI,iBAAiB;AACjD,YAAM,aAAqC,CAAA;AACrC,YAAA,oDAAmE;AAGzE,iBAAW,CAAC,YAAY,eAAe,KAAK,UAAU,oBAAoB,WAAW;AACzE,mBAAA,CAAC,iBAAiB,iBAAiB,MAAM,KAAK,WAAW,QAAQ,CAAC,EAAE,WAAW;AACrF,cAAA,aAAa,2BAA2B,GAAG;AAC9C;AAAA,UACD;AACI,cAAA,aAAa,SAAS,eAAe;AAClC,kBAAA,cAAc,KAAK,eACxB,+BACA,iBACA,UACA,aAAa,OAAO,GAAG,OACvB,cACA,OACD;AACA,gBAAI,aAAa;AAChB,wBAAU,YAAY;AACX,yBAAA,KAAK,YAAY,EAAE;AAAA,YAC/B;AAAA,UAAA,WACU,aAAa,SAAS,cAAc;AAC9C,uBAAW,cAAc,aAAa,SAAS,OAAA,GAAU;AACpD,kBAAA,WAAW,SAAS,mBAAmB;AAE1C;AA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|
3
|
+
import { EntitySubTreeMarker } from "../markers/EntitySubTreeMarker.js";
|
|
4
|
+
import { EntityListSubTreeMarker } from "../markers/EntityListSubTreeMarker.js";
|
|
5
5
|
import { assertNever } from "../utils/assertNever.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { FieldMarker } from "../markers/FieldMarker.js";
|
|
7
|
+
import { HasOneRelationMarker } from "../markers/HasOneRelationMarker.js";
|
|
8
|
+
import { HasManyRelationMarker } from "../markers/HasManyRelationMarker.js";
|
|
9
|
+
import { ServerId } from "../accessorTree/RuntimeId.js";
|
|
8
10
|
class RequestResponseNormalizer {
|
|
9
|
-
static mergeInQueryResponse(original, newPersistedData) {
|
|
11
|
+
static mergeInQueryResponse(original, newPersistedData, markerTree) {
|
|
10
12
|
const { subTreeDataStore, persistedEntityDataStore } = original;
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
for (const [placeholder, marker] of markerTree.subTrees) {
|
|
14
|
+
const data = newPersistedData[placeholder] ?? null;
|
|
15
|
+
if (marker instanceof EntitySubTreeMarker) {
|
|
16
|
+
if (data === null) {
|
|
17
|
+
subTreeDataStore.delete(placeholder);
|
|
18
|
+
} else {
|
|
19
|
+
if (Array.isArray(data)) {
|
|
20
|
+
throw new BindingError();
|
|
21
|
+
}
|
|
22
|
+
const id = this.processEntityData(persistedEntityDataStore, data, marker.fields.markers);
|
|
23
|
+
subTreeDataStore.set(placeholder, id);
|
|
24
|
+
}
|
|
25
|
+
} else if (EntityListSubTreeMarker) {
|
|
26
|
+
const subTreeListIds = /* @__PURE__ */ new Set();
|
|
27
|
+
if (!Array.isArray(data)) {
|
|
28
|
+
throw new BindingError();
|
|
29
|
+
}
|
|
30
|
+
for (const row of data) {
|
|
31
|
+
const id = this.processEntityData(persistedEntityDataStore, row, marker.fields.markers);
|
|
32
|
+
subTreeListIds.add(id.value);
|
|
33
|
+
}
|
|
34
|
+
subTreeDataStore.set(placeholder, subTreeListIds);
|
|
19
35
|
} else {
|
|
20
|
-
|
|
36
|
+
throw new BindingError();
|
|
21
37
|
}
|
|
22
38
|
}
|
|
23
|
-
return presentIds;
|
|
24
39
|
}
|
|
25
|
-
static mergeInMutationResponse(original, newPersistedData) {
|
|
40
|
+
static mergeInMutationResponse(original, newPersistedData, operations) {
|
|
26
41
|
const { subTreeDataStore, persistedEntityDataStore } = original;
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
31
|
-
|
|
42
|
+
for (const operation of operations) {
|
|
43
|
+
const { subTreePlaceholder, subTreeType, alias } = operation;
|
|
44
|
+
const receivedData = newPersistedData[alias];
|
|
45
|
+
if (!receivedData || Array.isArray(receivedData)) {
|
|
46
|
+
throw new BindingError();
|
|
32
47
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
subTreeDataStore.set(subTreePlaceholder, fieldData);
|
|
44
|
-
} else if (subTreeType === mutationOperationSubTreeType.entityList) {
|
|
45
|
-
if (type === mutationOperationType.create) {
|
|
46
|
-
const list = subTreeDataStore.get(subTreePlaceholder);
|
|
47
|
-
if (list instanceof Set) {
|
|
48
|
-
list.add(fieldData.value);
|
|
49
|
-
} else if (list === void 0) {
|
|
50
|
-
subTreeDataStore.set(subTreePlaceholder, /* @__PURE__ */ new Set([fieldData.value]));
|
|
51
|
-
} else {
|
|
52
|
-
return this.rejectData();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
48
|
+
if (operation.type === "update" || operation.type === "create") {
|
|
49
|
+
const id = this.processEntityData(persistedEntityDataStore, receivedData, operation.markers);
|
|
50
|
+
if (subTreeType === "single") {
|
|
51
|
+
subTreeDataStore.set(subTreePlaceholder, id);
|
|
52
|
+
} else if (subTreeType === "list") {
|
|
53
|
+
const list = subTreeDataStore.get(subTreePlaceholder);
|
|
54
|
+
if (list instanceof Set) {
|
|
55
|
+
list.add(id.value);
|
|
56
|
+
} else if (list === void 0) {
|
|
57
|
+
subTreeDataStore.set(subTreePlaceholder, /* @__PURE__ */ new Set([id.value]));
|
|
55
58
|
} else {
|
|
56
|
-
|
|
59
|
+
throw new BindingError();
|
|
57
60
|
}
|
|
58
|
-
|
|
61
|
+
} else {
|
|
62
|
+
return assertNever();
|
|
59
63
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
list.delete(entityId);
|
|
70
|
-
} else {
|
|
71
|
-
return assertNever();
|
|
64
|
+
} else if (operation.type === "delete") {
|
|
65
|
+
const id = this.extractId(receivedData);
|
|
66
|
+
persistedEntityDataStore.delete(id.uniqueValue);
|
|
67
|
+
if (subTreeType === "single") {
|
|
68
|
+
subTreeDataStore.delete(subTreePlaceholder);
|
|
69
|
+
} else if (subTreeType === "list") {
|
|
70
|
+
const list = subTreeDataStore.get(subTreePlaceholder);
|
|
71
|
+
if (!(list instanceof Set)) {
|
|
72
|
+
throw new BindingError();
|
|
72
73
|
}
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
default:
|
|
74
|
+
list.delete(id.value);
|
|
75
|
+
} else {
|
|
76
76
|
return assertNever();
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
return assertNever();
|
|
77
80
|
}
|
|
78
81
|
}
|
|
79
|
-
return presentIds;
|
|
80
|
-
}
|
|
81
|
-
static createFieldData(entityMap, fieldData) {
|
|
82
|
-
if (Array.isArray(fieldData)) {
|
|
83
|
-
const subTreeListIds = /* @__PURE__ */ new Set();
|
|
84
|
-
for (const entityDatum of fieldData) {
|
|
85
|
-
subTreeListIds.add(this.createEntityData(entityMap, entityDatum).value);
|
|
86
|
-
}
|
|
87
|
-
return subTreeListIds;
|
|
88
|
-
} else if (fieldData !== null && typeof fieldData === "object") {
|
|
89
|
-
return this.createEntityData(entityMap, fieldData);
|
|
90
|
-
} else {
|
|
91
|
-
return fieldData;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
static createEntityData(entityMap, entityData) {
|
|
95
|
-
const primaryKey = entityData[PRIMARY_KEY_NAME];
|
|
96
|
-
if (primaryKey === void 0) {
|
|
97
|
-
throw new BindingError(`The server has responded with an entity that lacks a primary key.`);
|
|
98
|
-
}
|
|
99
|
-
const id = new ServerId(primaryKey, entityData.__typename);
|
|
100
|
-
const presentEntityData = entityMap.get(id.uniqueValue);
|
|
101
|
-
if (presentEntityData === void 0) {
|
|
102
|
-
const fieldsMap = /* @__PURE__ */ new Map();
|
|
103
|
-
entityMap.set(id.uniqueValue, fieldsMap);
|
|
104
|
-
for (const field in entityData) {
|
|
105
|
-
const fieldDatum = entityData[field];
|
|
106
|
-
fieldsMap.set(field, this.createFieldData(entityMap, fieldDatum));
|
|
107
|
-
}
|
|
108
|
-
} else {
|
|
109
|
-
this.mergeInEntityData(entityMap, presentEntityData, entityData);
|
|
110
|
-
}
|
|
111
|
-
return id;
|
|
112
82
|
}
|
|
113
|
-
static
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return this.createEntityData(entityMap, newDatum);
|
|
125
|
-
}
|
|
126
|
-
if (fromTarget?.value === newId) {
|
|
127
|
-
this.mergeInEntityData(entityMap, target, newDatum);
|
|
128
|
-
return fromTarget;
|
|
83
|
+
static processEntityData(entityMap, entityData, fields) {
|
|
84
|
+
const id = this.extractId(entityData);
|
|
85
|
+
const presentEntityData = entityMap.get(id.uniqueValue) ?? /* @__PURE__ */ new Map();
|
|
86
|
+
entityMap.set(id.uniqueValue, presentEntityData);
|
|
87
|
+
for (const [placeholder, field] of fields) {
|
|
88
|
+
const value = entityData[placeholder];
|
|
89
|
+
if (field instanceof FieldMarker) {
|
|
90
|
+
presentEntityData.set(placeholder, value);
|
|
91
|
+
} else if (field instanceof HasOneRelationMarker) {
|
|
92
|
+
if (value === null) {
|
|
93
|
+
presentEntityData.set(placeholder, null);
|
|
129
94
|
} else {
|
|
130
|
-
|
|
95
|
+
presentEntityData.set(placeholder, this.processEntityData(entityMap, value, field.fields.markers));
|
|
131
96
|
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
97
|
+
} else if (field instanceof HasManyRelationMarker) {
|
|
98
|
+
const ids = presentEntityData.get(placeholder) ?? /* @__PURE__ */ new Set();
|
|
99
|
+
presentEntityData.set(placeholder, ids);
|
|
100
|
+
if (!(ids instanceof Set)) {
|
|
101
|
+
throw new BindingError();
|
|
102
|
+
}
|
|
103
|
+
ids.clear();
|
|
104
|
+
for (const row of value) {
|
|
105
|
+
const id2 = this.processEntityData(entityMap, row, field.fields.markers);
|
|
106
|
+
ids.add(id2.value);
|
|
138
107
|
}
|
|
139
|
-
|
|
108
|
+
} else {
|
|
109
|
+
throw new Error();
|
|
140
110
|
}
|
|
141
|
-
} else if (!Array.isArray(newDatum) && (newDatum === null || typeof newDatum !== "object")) {
|
|
142
|
-
return newDatum;
|
|
143
111
|
}
|
|
144
|
-
return
|
|
112
|
+
return id;
|
|
145
113
|
}
|
|
146
|
-
static
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
target.set(field, this.mergeInFieldData(entityMap, fromTarget, newDatum));
|
|
114
|
+
static extractId(entityData) {
|
|
115
|
+
const primaryKey = entityData[PRIMARY_KEY_NAME];
|
|
116
|
+
if (primaryKey === void 0) {
|
|
117
|
+
throw new BindingError(`The server has responded with an entity that lacks a primary key.`);
|
|
151
118
|
}
|
|
152
|
-
return
|
|
153
|
-
}
|
|
154
|
-
static rejectData(extraMessage) {
|
|
155
|
-
throw new BindingError(`Failed to process data received from the API.${extraMessage ? `
|
|
156
|
-
${extraMessage}` : ""}`);
|
|
119
|
+
return new ServerId(primaryKey, entityData.__typename);
|
|
157
120
|
}
|
|
158
121
|
}
|
|
159
122
|
export { RequestResponseNormalizer };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestResponseNormalizer.js","sources":["../../../src/core/RequestResponseNormalizer.ts"],"sourcesContent":["import {\n\tEntityFieldPersistedData,\n\tNormalizedPersistedData,\n\tPersistedEntityDataStore,\n\tReceivedDataTree,\n\tReceivedEntityData,\n\tReceivedFieldData,\n\tServerId,\n\tSingleEntityPersistedData,\n} from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport { PRIMARY_KEY_NAME } from '../bindingTypes'\nimport { assertNever } from '../utils'\nimport { MutationAlias, mutationOperationSubTreeType, mutationOperationType } from './requestAliases'\nimport { EntityId } from '../treeParameters'\n\nexport class RequestResponseNormalizer {\n\tpublic static mergeInQueryResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t): Set<string> {\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\t\tconst presentIds: Set<string> = new Set()\n\n\t\tfor (const placeholderName in newPersistedData) {\n\t\t\tconst treeDatum = newPersistedData[placeholderName]\n\n\t\t\tconst fieldData = this.createFieldData(persistedEntityDataStore, treeDatum)\n\n\t\t\tif (fieldData === null) {\n\t\t\t\tsubTreeDataStore.delete(placeholderName)\n\t\t\t} else if (fieldData instanceof Set || typeof fieldData === 'object') {\n\t\t\t\tsubTreeDataStore.set(placeholderName, fieldData)\n\t\t\t} else {\n\t\t\t\tthis.rejectData()\n\t\t\t}\n\t\t}\n\t\treturn presentIds\n\t}\n\n\tpublic static mergeInMutationResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t): Set<string> {\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\t\tconst presentIds: Set<string> = new Set()\n\n\t\tfor (const operationAlias in newPersistedData) {\n\t\t\tconst operation = MutationAlias.decodeTopLevel(operationAlias)\n\n\t\t\tif (operation === undefined) {\n\t\t\t\treturn this.rejectData()\n\t\t\t}\n\t\t\tconst { type, entityId, subTreeType, subTreePlaceholder } = operation\n\n\t\t\tconst treeDatum = newPersistedData[operationAlias]\n\t\t\tconst fieldData = this.createFieldData(persistedEntityDataStore, treeDatum)\n\t\t\tif (!(fieldData instanceof ServerId)) {\n\t\t\t\treturn this.rejectData()\n\t\t\t}\n\n\t\t\tswitch (type) {\n\t\t\t\tcase mutationOperationType.update:\n\t\t\t\tcase mutationOperationType.create: {\n\n\t\t\t\t\tif (subTreeType === mutationOperationSubTreeType.singleEntity) {\n\t\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, fieldData)\n\t\t\t\t\t} else if (subTreeType === mutationOperationSubTreeType.entityList) {\n\t\t\t\t\t\tif (type === mutationOperationType.create) {\n\t\t\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\t\t\tif (list instanceof Set) {\n\t\t\t\t\t\t\t\t// TODO this is somewhat dubious because we're essentially just guessing the order of the entities\n\t\t\t\t\t\t\t\t//\t\tand just carelessly put the new one at the end.\n\t\t\t\t\t\t\t\tlist.add(fieldData.value)\n\t\t\t\t\t\t\t} else if (list === undefined) {\n\t\t\t\t\t\t\t\t// That's fine. This is probably just an isCreating sub-tree.\n\t\t\t\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, new Set([fieldData.value]))\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\treturn this.rejectData()\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\treturn assertNever(subTreeType)\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase mutationOperationType.delete: {\n\t\t\t\t\t// TODO there are potentially some references to entityId that this whole process won't quite remove.\n\t\t\t\t\t//\t\tThat's a memory leak. Probably not particularly severe in most cases but still.\n\t\t\t\t\tpersistedEntityDataStore.delete(fieldData.uniqueValue)\n\t\t\t\t\tif (subTreeType === mutationOperationSubTreeType.singleEntity) {\n\t\t\t\t\t\tsubTreeDataStore.delete(subTreePlaceholder)\n\t\t\t\t\t} else if (subTreeType === mutationOperationSubTreeType.entityList) {\n\t\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\t\tif (!(list instanceof Set)) {\n\t\t\t\t\t\t\treturn this.rejectData()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlist.delete(entityId)\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn assertNever(subTreeType)\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(type)\n\t\t\t}\n\t\t}\n\t\treturn presentIds\n\t}\n\n\tprivate static createFieldData(\n\t\tentityMap: PersistedEntityDataStore,\n\t\tfieldData: ReceivedFieldData,\n\t): EntityFieldPersistedData {\n\t\tif (Array.isArray(fieldData)) {\n\t\t\tconst subTreeListIds = new Set<EntityId>()\n\t\t\tfor (const entityDatum of fieldData) {\n\t\t\t\tsubTreeListIds.add(this.createEntityData(entityMap, entityDatum).value)\n\t\t\t}\n\t\t\treturn subTreeListIds\n\t\t} else if (fieldData !== null && typeof fieldData === 'object') {\n\t\t\treturn this.createEntityData(entityMap, fieldData)\n\t\t} else {\n\t\t\treturn fieldData\n\t\t}\n\t}\n\n\tprivate static createEntityData(entityMap: PersistedEntityDataStore, entityData: ReceivedEntityData): ServerId {\n\t\tconst primaryKey: EntityId | undefined = entityData[PRIMARY_KEY_NAME]\n\n\t\tif (primaryKey === undefined) {\n\t\t\tthrow new BindingError(`The server has responded with an entity that lacks a primary key.`)\n\t\t}\n\n\t\tconst id = new ServerId(primaryKey, entityData.__typename)\n\n\t\tconst presentEntityData = entityMap.get(id.uniqueValue)\n\n\t\tif (presentEntityData === undefined) {\n\t\t\tconst fieldsMap: SingleEntityPersistedData = new Map()\n\t\t\tentityMap.set(id.uniqueValue, fieldsMap)\n\t\t\tfor (const field in entityData) {\n\t\t\t\tconst fieldDatum = entityData[field]\n\n\t\t\t\tfieldsMap.set(field, this.createFieldData(entityMap, fieldDatum))\n\t\t\t}\n\t\t} else {\n\t\t\tthis.mergeInEntityData(entityMap, presentEntityData, entityData)\n\t\t}\n\t\treturn id\n\t}\n\n\tprivate static mergeInFieldData(\n\t\tentityMap: PersistedEntityDataStore,\n\t\tfromTarget: EntityFieldPersistedData | undefined,\n\t\tnewDatum: ReceivedFieldData,\n\t): EntityFieldPersistedData {\n\t\tif (fromTarget === undefined) {\n\t\t\treturn this.createFieldData(entityMap, newDatum)\n\t\t}\n\t\tif (fromTarget instanceof ServerId || (fromTarget === null && typeof newDatum === 'object')) {\n\t\t\tif (newDatum === null) {\n\t\t\t\treturn null\n\t\t\t} else if (typeof newDatum === 'object' && !Array.isArray(newDatum)) {\n\t\t\t\tconst newId = newDatum[PRIMARY_KEY_NAME]\n\t\t\t\tconst target = entityMap.get(ServerId.formatUniqueValue(newId, newDatum.__typename))\n\t\t\t\tif (target === undefined) {\n\t\t\t\t\treturn this.createEntityData(entityMap, newDatum)\n\t\t\t\t}\n\n\t\t\t\tif (fromTarget?.value === newId) {\n\t\t\t\t\tthis.mergeInEntityData(entityMap, target, newDatum)\n\t\t\t\t\treturn fromTarget\n\t\t\t\t} else {\n\t\t\t\t\treturn this.createEntityData(entityMap, newDatum)\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (fromTarget instanceof Set) {\n\t\t\tif (Array.isArray(newDatum)) {\n\t\t\t\tfromTarget.clear()\n\t\t\t\tfor (const entityData of newDatum) {\n\t\t\t\t\tfromTarget.add(this.createEntityData(entityMap, entityData).value)\n\t\t\t\t}\n\t\t\t\treturn fromTarget\n\t\t\t}\n\t\t} else if (!Array.isArray(newDatum) && (newDatum === null || typeof newDatum !== 'object')) {\n\t\t\treturn newDatum\n\t\t}\n\t\treturn this.rejectData()\n\t}\n\n\tprivate static mergeInEntityData(\n\t\tentityMap: PersistedEntityDataStore,\n\t\ttarget: SingleEntityPersistedData,\n\t\tnewData: ReceivedEntityData,\n\t): SingleEntityPersistedData {\n\t\tfor (const field in newData) {\n\t\t\tconst fromTarget = target.get(field)\n\t\t\tconst newDatum = newData[field]\n\n\t\t\ttarget.set(field, this.mergeInFieldData(entityMap, fromTarget, newDatum))\n\t\t}\n\t\treturn target\n\t}\n\n\tprivate static rejectData(extraMessage?: string): never {\n\t\tthrow new BindingError(`Failed to process data received from the API.${extraMessage ? `\\n${extraMessage}` : ''}`)\n\t}\n}\n"],"names":[],"mappings":";;;;;;;AAgBO,MAAM,0BAA0B;AAAA,SACxB,qBACb,UACA,kBACc;AACR,UAAA,EAAE,kBAAkB,6BAA6B;AACjD,UAAA,iCAA8B;AAEpC,eAAW,mBAAmB,kBAAkB;AAC/C,YAAM,YAAY,iBAAiB;AAEnC,YAAM,YAAY,KAAK,gBAAgB,0BAA0B,SAAS;AAE1E,UAAI,cAAc,MAAM;AACvB,yBAAiB,OAAO,eAAe;AAAA,MAC7B,WAAA,qBAAqB,OAAO,OAAO,cAAc,UAAU;AACpD,yBAAA,IAAI,iBAAiB,SAAS;AAAA,MAAA,OACzC;AACN,aAAK,WAAW;AAAA,MACjB;AAAA,IACD;AACO,WAAA;AAAA,EACR;AAAA,SAEc,wBACb,UACA,kBACc;AACR,UAAA,EAAE,kBAAkB,6BAA6B;AACjD,UAAA,iCAA8B;AAEpC,eAAW,kBAAkB,kBAAkB;AACxC,YAAA,YAAY,cAAc,eAAe,cAAc;AAE7D,UAAI,cAAc,QAAW;AAC5B,eAAO,KAAK;MACb;AACA,YAAM,EAAE,MAAM,UAAU,aAAa,uBAAuB;AAE5D,YAAM,YAAY,iBAAiB;AACnC,YAAM,YAAY,KAAK,gBAAgB,0BAA0B,SAAS;AACtE,UAAA,uBAAuB,WAAW;AACrC,eAAO,KAAK;MACb;AAEQ,cA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AAQ,GAAG;AAC5B,mBAAW,MAAM;AACjB,mBAAW,cAAc,UAAU;AAClC,qBAAW,IAAI,KAAK,iBAAiB,WAAW,UAAU,EAAE,KAAK;AAAA,QAClE;AACO,eAAA;AAAA,MACR;AAAA,IAAA,WACU,CAAC,MAAM,QAAQ,QAAQ,KAAmB,cAAA,QAAQ,OAAO,aAAa,WAAW;AACpF,aAAA;AAAA,IACR;AACA,WAAO,KAAK;EACb;AAAA,SAEe,kBACd,WACA,QACA,SAC4B;AAC5B,eAAW,SAAS,SAAS;AACtB,YAAA,aAAa,OAAO,IAAI,KAAK;AACnC,YAAM,WAAW,QAAQ;AAEzB,aAAO,IAAI,OAAO,KAAK,iBAAiB,WAAW,YAAY,QAAQ,CAAC;AAAA,IACzE;AACO,WAAA;AAAA,EACR;AAAA,SAEe,WAAW,cAA8B;AACjD,UAAA,IAAI,aAAa,gDAAgD,eAAe;AAAA,EAAK,iBAAiB,IAAI;AAAA,EACjH;AACD;;"}
|
|
1
|
+
{"version":3,"file":"RequestResponseNormalizer.js","sources":["../../../src/core/RequestResponseNormalizer.ts"],"sourcesContent":["import {\n\tNormalizedPersistedData,\n\tPersistedEntityDataStore,\n\tReceivedDataTree,\n\tReceivedEntityData,\n\tServerId,\n} from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport { PRIMARY_KEY_NAME } from '../bindingTypes'\nimport { EntityId } from '../treeParameters'\nimport {\n\tEntityFieldMarkers,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n} from '../markers'\nimport { SubMutationOperation } from './MutationGenerator'\nimport { assertNever } from '../utils'\n\nexport class RequestResponseNormalizer {\n\tpublic static mergeInQueryResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t\tmarkerTree: MarkerTreeRoot,\n\t): void {\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\n\t\tfor (const [placeholder, marker] of markerTree.subTrees) {\n\t\t\tconst data = newPersistedData[placeholder] ?? null\n\t\t\tif (marker instanceof EntitySubTreeMarker) {\n\t\t\t\tif (data === null) {\n\t\t\t\t\tsubTreeDataStore.delete(placeholder)\n\t\t\t\t} else {\n\t\t\t\t\tif (Array.isArray(data)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, data, marker.fields.markers)\n\t\t\t\t\tsubTreeDataStore.set(placeholder, id)\n\t\t\t\t}\n\t\t\t} else if (EntityListSubTreeMarker) {\n\t\t\t\tconst subTreeListIds = new Set<EntityId>()\n\t\t\t\tif (!Array.isArray(data)) {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tfor (const row of data) {\n\t\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, row, marker.fields.markers)\n\t\t\t\t\tsubTreeListIds.add(id.value)\n\t\t\t\t}\n\t\t\t\tsubTreeDataStore.set(placeholder, subTreeListIds)\n\t\t\t} else {\n\t\t\t\tthrow new BindingError()\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static mergeInMutationResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t\toperations: SubMutationOperation[],\n\t): void {\n\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\n\t\tfor (const operation of operations) {\n\t\t\tconst { subTreePlaceholder, subTreeType, alias } = operation\n\n\t\t\tconst receivedData = newPersistedData[alias]\n\t\t\tif (!receivedData || Array.isArray(receivedData)) {\n\t\t\t\tthrow new BindingError()\n\t\t\t}\n\n\t\t\tif (operation.type === 'update' || operation.type === 'create') {\n\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, receivedData, operation.markers)\n\t\t\t\tif (subTreeType === 'single') {\n\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, id)\n\t\t\t\t} else if (subTreeType === 'list') {\n\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\tif (list instanceof Set) {\n\t\t\t\t\t\t// TODO this is somewhat dubious because we're essentially just guessing the order of the entities\n\t\t\t\t\t\t//\t\tand just carelessly put the new one at the end.\n\t\t\t\t\t\tlist.add(id.value)\n\t\t\t\t\t} else if (list === undefined) {\n\t\t\t\t\t\t// That's fine. This is probably just an isCreating sub-tree.\n\t\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, new Set([id.value]))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t}\n\t\t\t} else if (operation.type === 'delete') {\n\t\t\t\tconst id = this.extractId(receivedData)\n\t\t\t\t// TODO there are potentially some references to entityId that this whole process won't quite remove.\n\t\t\t\t//\t\tThat's a memory leak. Probably not particularly severe in most cases but still.\n\t\t\t\tpersistedEntityDataStore.delete(id.uniqueValue)\n\t\t\t\tif (subTreeType === 'single') {\n\t\t\t\t\tsubTreeDataStore.delete(subTreePlaceholder)\n\t\t\t\t} else if (subTreeType === 'list') {\n\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\tif (!(list instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tlist.delete(id.value)\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t\treturn assertNever(operation)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static processEntityData(entityMap: PersistedEntityDataStore, entityData: ReceivedEntityData, fields: EntityFieldMarkers): ServerId {\n\t\tconst id = this.extractId(entityData)\n\t\tconst presentEntityData = entityMap.get(id.uniqueValue) ?? new Map()\n\t\tentityMap.set(id.uniqueValue, presentEntityData)\n\n\t\tfor (const [placeholder, field] of fields) {\n\t\t\tconst value = entityData[placeholder]\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tpresentEntityData.set(placeholder, value)\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tif (value === null) {\n\t\t\t\t\tpresentEntityData.set(placeholder, null)\n\t\t\t\t} else {\n\t\t\t\t\tpresentEntityData.set(placeholder, this.processEntityData(entityMap, value as ReceivedEntityData, field.fields.markers))\n\t\t\t\t}\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\tconst ids = presentEntityData.get(placeholder) ?? new Set()\n\t\t\t\tpresentEntityData.set(placeholder, ids)\n\t\t\t\tif (!(ids instanceof Set)) {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tids.clear()\n\t\t\t\tfor (const row of value as ReceivedEntityData[]) {\n\t\t\t\t\tconst id = this.processEntityData(entityMap, row, field.fields.markers)\n\t\t\t\t\tids.add(id.value)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthrow new Error()\n\t\t\t}\n\t\t}\n\n\t\treturn id\n\t}\n\n\tprivate static extractId(entityData: ReceivedEntityData): ServerId {\n\t\tconst primaryKey: EntityId | undefined = entityData[PRIMARY_KEY_NAME]\n\n\t\tif (primaryKey === undefined) {\n\t\t\tthrow new BindingError(`The server has responded with an entity that lacks a primary key.`)\n\t\t}\n\n\t\treturn new ServerId(primaryKey, entityData.__typename)\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;AAsBO,MAAM,0BAA0B;AAAA,SACxB,qBACb,UACA,kBACA,YACO;AACD,UAAA,EAAE,kBAAkB,6BAA6B;AAEvD,eAAW,CAAC,aAAa,WAAW,WAAW,UAAU;AAClD,YAAA,OAAO,iBAAiB,gBAAgB;AAC9C,UAAI,kBAAkB,qBAAqB;AAC1C,YAAI,SAAS,MAAM;AAClB,2BAAiB,OAAO,WAAW;AAAA,QAAA,OAC7B;AACF,cAAA,MAAM,QAAQ,IAAI,GAAG;AACxB,kBAAM,IAAI,aAAa;AAAA,UAC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A,IAAI,IAAG,KAAK;AAAA,QACjB;AAAA,MAAA,OACM;AACN,cAAM,IAAI,MAAM;AAAA,MACjB;AAAA,IACD;AAEO,WAAA;AAAA,EACR;AAAA,SAEe,UAAU,YAA0C;AAClE,UAAM,aAAmC,WAAW;AAEpD,QAAI,eAAe,QAAW;AACvB,YAAA,IAAI,aAAa,mEAAmE;AAAA,IAC3F;AAEA,WAAO,IAAI,SAAS,YAAY,WAAW,UAAU;AAAA,EACtD;AACD;;"}
|
|
@@ -78,7 +78,11 @@ class StateInitializer {
|
|
|
78
78
|
}
|
|
79
79
|
this.initializeFromFieldMarker(realm, field, void 0, value);
|
|
80
80
|
} else if (field instanceof HasManyRelationMarker) {
|
|
81
|
-
|
|
81
|
+
const value = copyFrom.children.get(placeholderName);
|
|
82
|
+
if (!value || value.type !== "entityList") {
|
|
83
|
+
throw new BindingError();
|
|
84
|
+
}
|
|
85
|
+
this.initializeFromHasManyRelationMarker(realm, field, new Set(value.children.keys()));
|
|
82
86
|
} else if (field instanceof HasOneRelationMarker) {
|
|
83
87
|
let runtimeId;
|
|
84
88
|
let subCopyFrom = void 0;
|