@contember/binding-legacy 2.1.0-beta.2 → 2.2.0-alpha.2
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/src/accessors/EntityAccessorImpl.cjs.map +1 -1
- package/dist/development/src/accessors/EntityAccessorImpl.js.map +1 -1
- package/dist/development/src/accessors/EntityListAccessorImpl.cjs.map +1 -1
- package/dist/development/src/accessors/EntityListAccessorImpl.js.map +1 -1
- package/dist/development/src/accessors/FieldAccessorImpl.cjs.map +1 -1
- package/dist/development/src/accessors/FieldAccessorImpl.js.map +1 -1
- package/dist/development/src/core/AccessorErrorManager.cjs.map +1 -1
- package/dist/development/src/core/AccessorErrorManager.js.map +1 -1
- package/dist/development/src/core/Config.cjs.map +1 -1
- package/dist/development/src/core/Config.js.map +1 -1
- package/dist/development/src/core/DataBinding.cjs.map +1 -1
- package/dist/development/src/core/DataBinding.js.map +1 -1
- package/dist/development/src/core/ErrorsPreprocessor.cjs.map +1 -1
- package/dist/development/src/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/development/src/core/EventManager.cjs.map +1 -1
- package/dist/development/src/core/EventManager.js.map +1 -1
- package/dist/development/src/core/MutationGenerator.cjs.map +1 -1
- package/dist/development/src/core/MutationGenerator.js.map +1 -1
- package/dist/development/src/core/RealmKeyGenerator.cjs.map +1 -1
- package/dist/development/src/core/RealmKeyGenerator.js.map +1 -1
- package/dist/development/src/core/RequestResponseNormalizer.cjs.map +1 -1
- package/dist/development/src/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/development/src/core/StateInitializer.cjs.map +1 -1
- package/dist/development/src/core/StateInitializer.js.map +1 -1
- package/dist/development/src/core/TreeAugmenter.cjs.map +1 -1
- package/dist/development/src/core/TreeAugmenter.js.map +1 -1
- package/dist/development/src/core/TreeStore.cjs.map +1 -1
- package/dist/development/src/core/TreeStore.js.map +1 -1
- package/dist/development/src/core/exceptions/ErrorLocator.cjs.map +1 -1
- package/dist/development/src/core/exceptions/ErrorLocator.js.map +1 -1
- package/dist/development/src/core/exceptions/MarkerSugarer.cjs.map +1 -1
- package/dist/development/src/core/exceptions/MarkerSugarer.js.map +1 -1
- package/dist/development/src/core/factories/createBatchUpdatesOptions.cjs.map +1 -1
- package/dist/development/src/core/factories/createBatchUpdatesOptions.js.map +1 -1
- package/dist/development/src/core/operations/EntityOperations.cjs.map +1 -1
- package/dist/development/src/core/operations/EntityOperations.js.map +1 -1
- package/dist/development/src/core/operations/FieldOperations.cjs.map +1 -1
- package/dist/development/src/core/operations/FieldOperations.js.map +1 -1
- package/dist/development/src/core/operations/ListOperations.cjs.map +1 -1
- package/dist/development/src/core/operations/ListOperations.js.map +1 -1
- package/dist/development/src/core/operations/OperationsHelpers.cjs.map +1 -1
- package/dist/development/src/core/operations/OperationsHelpers.js.map +1 -1
- package/dist/development/src/core/state/StateIterator.cjs.map +1 -1
- package/dist/development/src/core/state/StateIterator.js.map +1 -1
- package/dist/development/src/core/state/getEntityMarker.cjs.map +1 -1
- package/dist/development/src/core/state/getEntityMarker.js.map +1 -1
- package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.cjs.map +1 -1
- package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -1
- package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.cjs.map +1 -1
- package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.js.map +1 -1
- package/dist/production/src/accessors/EntityAccessorImpl.cjs.map +1 -1
- package/dist/production/src/accessors/EntityAccessorImpl.js.map +1 -1
- package/dist/production/src/accessors/EntityListAccessorImpl.cjs.map +1 -1
- package/dist/production/src/accessors/EntityListAccessorImpl.js.map +1 -1
- package/dist/production/src/accessors/FieldAccessorImpl.cjs.map +1 -1
- package/dist/production/src/accessors/FieldAccessorImpl.js.map +1 -1
- package/dist/production/src/core/AccessorErrorManager.cjs.map +1 -1
- package/dist/production/src/core/AccessorErrorManager.js.map +1 -1
- package/dist/production/src/core/Config.cjs.map +1 -1
- package/dist/production/src/core/Config.js.map +1 -1
- package/dist/production/src/core/DataBinding.cjs.map +1 -1
- package/dist/production/src/core/DataBinding.js.map +1 -1
- package/dist/production/src/core/ErrorsPreprocessor.cjs.map +1 -1
- package/dist/production/src/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/production/src/core/EventManager.cjs.map +1 -1
- package/dist/production/src/core/EventManager.js.map +1 -1
- package/dist/production/src/core/MutationGenerator.cjs.map +1 -1
- package/dist/production/src/core/MutationGenerator.js.map +1 -1
- package/dist/production/src/core/RealmKeyGenerator.cjs.map +1 -1
- package/dist/production/src/core/RealmKeyGenerator.js.map +1 -1
- package/dist/production/src/core/RequestResponseNormalizer.cjs.map +1 -1
- package/dist/production/src/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/production/src/core/StateInitializer.cjs.map +1 -1
- package/dist/production/src/core/StateInitializer.js.map +1 -1
- package/dist/production/src/core/TreeAugmenter.cjs.map +1 -1
- package/dist/production/src/core/TreeAugmenter.js.map +1 -1
- package/dist/production/src/core/TreeStore.cjs.map +1 -1
- package/dist/production/src/core/TreeStore.js.map +1 -1
- package/dist/production/src/core/exceptions/ErrorLocator.cjs.map +1 -1
- package/dist/production/src/core/exceptions/ErrorLocator.js.map +1 -1
- package/dist/production/src/core/exceptions/MarkerSugarer.cjs.map +1 -1
- package/dist/production/src/core/exceptions/MarkerSugarer.js.map +1 -1
- package/dist/production/src/core/factories/createBatchUpdatesOptions.cjs.map +1 -1
- package/dist/production/src/core/factories/createBatchUpdatesOptions.js.map +1 -1
- package/dist/production/src/core/operations/EntityOperations.cjs.map +1 -1
- package/dist/production/src/core/operations/EntityOperations.js.map +1 -1
- package/dist/production/src/core/operations/FieldOperations.cjs.map +1 -1
- package/dist/production/src/core/operations/FieldOperations.js.map +1 -1
- package/dist/production/src/core/operations/ListOperations.cjs.map +1 -1
- package/dist/production/src/core/operations/ListOperations.js.map +1 -1
- package/dist/production/src/core/operations/OperationsHelpers.cjs.map +1 -1
- package/dist/production/src/core/operations/OperationsHelpers.js.map +1 -1
- package/dist/production/src/core/state/StateIterator.cjs.map +1 -1
- package/dist/production/src/core/state/StateIterator.js.map +1 -1
- package/dist/production/src/core/state/getEntityMarker.cjs.map +1 -1
- package/dist/production/src/core/state/getEntityMarker.js.map +1 -1
- package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.cjs.map +1 -1
- package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -1
- package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.cjs.map +1 -1
- package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.js.map +1 -1
- package/dist/types/accessorTree/index.d.ts +1 -1
- package/dist/types/accessorTree/index.d.ts.map +1 -1
- package/dist/types/accessors/EntityAccessorImpl.d.ts +3 -3
- package/dist/types/accessors/EntityAccessorImpl.d.ts.map +1 -1
- package/dist/types/accessors/EntityListAccessorImpl.d.ts +2 -2
- package/dist/types/accessors/EntityListAccessorImpl.d.ts.map +1 -1
- package/dist/types/accessors/FieldAccessorImpl.d.ts +3 -3
- package/dist/types/accessors/FieldAccessorImpl.d.ts.map +1 -1
- package/dist/types/accessors/index.d.ts +4 -4
- package/dist/types/accessors/index.d.ts.map +1 -1
- package/dist/types/core/AccessorErrorManager.d.ts +4 -4
- package/dist/types/core/AccessorErrorManager.d.ts.map +1 -1
- package/dist/types/core/Config.d.ts +1 -1
- package/dist/types/core/Config.d.ts.map +1 -1
- package/dist/types/core/DataBinding.d.ts +1 -1
- package/dist/types/core/DataBinding.d.ts.map +1 -1
- package/dist/types/core/ErrorsPreprocessor.d.ts +1 -1
- package/dist/types/core/ErrorsPreprocessor.d.ts.map +1 -1
- package/dist/types/core/EventManager.d.ts +5 -5
- package/dist/types/core/EventManager.d.ts.map +1 -1
- package/dist/types/core/MutationGenerator.d.ts +1 -1
- package/dist/types/core/MutationGenerator.d.ts.map +1 -1
- package/dist/types/core/RealmKeyGenerator.d.ts +1 -1
- package/dist/types/core/RealmKeyGenerator.d.ts.map +1 -1
- package/dist/types/core/RequestResponseNormalizer.d.ts +2 -2
- package/dist/types/core/RequestResponseNormalizer.d.ts.map +1 -1
- package/dist/types/core/StateInitializer.d.ts +4 -4
- package/dist/types/core/StateInitializer.d.ts.map +1 -1
- package/dist/types/core/TreeAugmenter.d.ts +4 -4
- package/dist/types/core/TreeAugmenter.d.ts.map +1 -1
- package/dist/types/core/TreeStore.d.ts +3 -3
- package/dist/types/core/TreeStore.d.ts.map +1 -1
- package/dist/types/core/exceptions/ErrorLocator.d.ts +1 -1
- package/dist/types/core/exceptions/ErrorLocator.d.ts.map +1 -1
- package/dist/types/core/factories/createBatchUpdatesOptions.d.ts +1 -1
- package/dist/types/core/factories/createBatchUpdatesOptions.d.ts.map +1 -1
- package/dist/types/core/factories/index.d.ts +1 -1
- package/dist/types/core/factories/index.d.ts.map +1 -1
- package/dist/types/core/index.d.ts +8 -8
- package/dist/types/core/index.d.ts.map +1 -1
- package/dist/types/core/operations/EntityOperations.d.ts +5 -5
- package/dist/types/core/operations/EntityOperations.d.ts.map +1 -1
- package/dist/types/core/operations/FieldOperations.d.ts +5 -5
- package/dist/types/core/operations/FieldOperations.d.ts.map +1 -1
- package/dist/types/core/operations/ListOperations.d.ts +5 -5
- package/dist/types/core/operations/ListOperations.d.ts.map +1 -1
- package/dist/types/core/operations/OperationsHelpers.d.ts +4 -4
- package/dist/types/core/operations/OperationsHelpers.d.ts.map +1 -1
- package/dist/types/core/operations/index.d.ts +3 -3
- package/dist/types/core/operations/index.d.ts.map +1 -1
- package/dist/types/core/requestAliases/index.d.ts +1 -1
- package/dist/types/core/requestAliases/index.d.ts.map +1 -1
- package/dist/types/core/state/EntityListState.d.ts +1 -1
- package/dist/types/core/state/EntityListState.d.ts.map +1 -1
- package/dist/types/core/state/EntityRealmState.d.ts +3 -3
- package/dist/types/core/state/EntityRealmState.d.ts.map +1 -1
- package/dist/types/core/state/EntityState.d.ts +1 -1
- package/dist/types/core/state/EntityState.d.ts.map +1 -1
- package/dist/types/core/state/FieldState.d.ts +1 -1
- package/dist/types/core/state/FieldState.d.ts.map +1 -1
- package/dist/types/core/state/StateIterator.d.ts +5 -5
- package/dist/types/core/state/StateIterator.d.ts.map +1 -1
- package/dist/types/core/state/StateNode.d.ts +3 -3
- package/dist/types/core/state/StateNode.d.ts.map +1 -1
- package/dist/types/core/state/getEntityMarker.d.ts +1 -1
- package/dist/types/core/state/getEntityMarker.d.ts.map +1 -1
- package/dist/types/core/state/index.d.ts +7 -7
- package/dist/types/core/state/index.d.ts.map +1 -1
- package/dist/types/core/utils/index.d.ts +1 -1
- package/dist/types/core/utils/index.d.ts.map +1 -1
- package/dist/types/fieldHelpers/helpers/TemporalFieldHelper.d.ts +1 -1
- package/dist/types/fieldHelpers/helpers/TemporalFieldHelper.d.ts.map +1 -1
- package/dist/types/fieldHelpers/helpers/UuidFieldHelper.d.ts +1 -1
- package/dist/types/fieldHelpers/helpers/UuidFieldHelper.d.ts.map +1 -1
- package/dist/types/fieldHelpers/helpers/index.d.ts +2 -2
- package/dist/types/fieldHelpers/helpers/index.d.ts.map +1 -1
- package/dist/types/fieldHelpers/index.d.ts +1 -1
- package/dist/types/fieldHelpers/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/utils/index.d.ts +3 -3
- package/dist/types/utils/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/accessorTree/index.ts +1 -1
- package/src/accessors/EntityAccessorImpl.ts +3 -3
- package/src/accessors/EntityListAccessorImpl.ts +2 -2
- package/src/accessors/FieldAccessorImpl.ts +3 -3
- package/src/accessors/index.ts +4 -4
- package/src/core/AccessorErrorManager.ts +5 -5
- package/src/core/Config.ts +1 -1
- package/src/core/DataBinding.ts +14 -14
- package/src/core/ErrorsPreprocessor.ts +2 -2
- package/src/core/EventManager.ts +5 -5
- package/src/core/MutationGenerator.ts +6 -6
- package/src/core/RealmKeyGenerator.ts +1 -1
- package/src/core/RequestResponseNormalizer.ts +2 -2
- package/src/core/StateInitializer.ts +8 -8
- package/src/core/TreeAugmenter.ts +7 -7
- package/src/core/TreeStore.ts +4 -4
- package/src/core/exceptions/ErrorLocator.ts +3 -3
- package/src/core/exceptions/MarkerSugarer.ts +1 -1
- package/src/core/factories/createBatchUpdatesOptions.ts +1 -1
- package/src/core/factories/index.ts +1 -1
- package/src/core/index.ts +8 -8
- package/src/core/operations/EntityOperations.ts +7 -7
- package/src/core/operations/FieldOperations.ts +6 -6
- package/src/core/operations/ListOperations.ts +8 -8
- package/src/core/operations/OperationsHelpers.ts +5 -5
- package/src/core/operations/index.ts +3 -3
- package/src/core/requestAliases/index.ts +1 -1
- package/src/core/state/EntityListState.ts +1 -1
- package/src/core/state/EntityRealmState.ts +3 -3
- package/src/core/state/EntityState.ts +1 -1
- package/src/core/state/FieldState.ts +1 -1
- package/src/core/state/StateIterator.ts +6 -6
- package/src/core/state/StateNode.ts +3 -3
- package/src/core/state/getEntityMarker.ts +1 -1
- package/src/core/state/index.ts +7 -7
- package/src/core/utils/index.ts +1 -1
- package/src/fieldHelpers/helpers/TemporalFieldHelper.ts +1 -1
- package/src/fieldHelpers/helpers/UuidFieldHelper.ts +1 -1
- package/src/fieldHelpers/helpers/index.ts +2 -2
- package/src/fieldHelpers/index.ts +1 -1
- package/src/index.ts +3 -3
- package/src/utils/index.ts +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MutationGenerator.cjs","sources":["../../../../../packages/binding-legacy/src/core/MutationGenerator.ts"],"sourcesContent":["import { ContentMutation, ContentQueryBuilder, Input } from '@contember/client'\nimport { ClientGeneratedUuid, ReceivedEntityData, ServerId } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '@contember/binding-common'\nimport { EntityFieldMarkers, FieldMarker, HasManyRelationMarker, HasOneRelationMarker } from '@contember/binding-common'\nimport type { EntityId, EntityName, PlaceholderName, UniqueWhere } from '@contember/binding-common'\nimport { isEmptyObject } from '../utils'\nimport { assertNever } from '@contember/binding-common'\nimport { QueryGenerator } from './QueryGenerator'\nimport { MutationAlias } from './requestAliases'\nimport { EntityListState, EntityRealmState, EntityRealmStateStub, EntityState, FieldState, getEntityMarker, StateIterator } from './state'\nimport type { TreeStore } from './TreeStore'\nimport { EntityFieldPersistedData, EntityFieldPersistedValue } from '../accessorTree'\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\tmutations: Record<string, ContentMutation<ReceivedEntityData>>\n\toperations: SubMutationOperation[]\n}\n\n// TODO enforce correct expected mutations in dev mode.\nexport class MutationGenerator {\n\tprivate aliasCounter = 1\n\tprivate processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity = new Map()\n\tprivate processedDeletes = new Set<string>()\n\n\tprivate constructor(\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly qb: ContentQueryBuilder,\n\t) {\n\t}\n\n\tpublic static getPersistMutation(treeStore: TreeStore, qb: ContentQueryBuilder): PersistMutationResult {\n\t\treturn new MutationGenerator(treeStore, qb).getPersistMutation()\n\t}\n\n\tprivate getPersistMutation(): PersistMutationResult {\n\t\tconst mutations: Record<string, ContentMutation<any>> = {}\n\t\tconst operations: SubMutationOperation[] = []\n\n\t\tfor (const [treeRootId, rootStates] of this.treeStore.subTreeStatesByRoot.entries()) {\n\t\t\tfor (const [placeholderName, subTreeState] of Array.from(rootStates.entries()).reverse()) {\n\t\t\t\tif (subTreeState.unpersistedChangesCount <= 0) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (subTreeState.type === 'entityRealm') {\n\t\t\t\t\tif (\n\t\t\t\t\t\tsubTreeState.blueprint.type === 'subTree' && subTreeState.blueprint.marker.parameters.isCreating\n\t\t\t\t\t\t&& subTreeState.blueprint.marker.parameters.isUnpersisted\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst subMutation = this.createMutation(\n\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t'single',\n\t\t\t\t\t\tsubTreeState.entity.id.value,\n\t\t\t\t\t\tsubTreeState,\n\t\t\t\t\t)\n\t\t\t\t\tif (subMutation) {\n\t\t\t\t\t\tmutations[subMutation[1].alias] = subMutation[0]\n\t\t\t\t\t\toperations.push(subMutation[1])\n\t\t\t\t\t}\n\t\t\t\t} else if (subTreeState.type === 'entityList') {\n\t\t\t\t\tif (\n\t\t\t\t\t\tsubTreeState.blueprint.type === 'subTree' && subTreeState.blueprint.marker.parameters.isCreating\n\t\t\t\t\t\t&& subTreeState.blueprint.marker.parameters.isUnpersisted\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const childState of subTreeState.children.values()) {\n\t\t\t\t\t\tif (childState.type === 'entityRealmStub') {\n\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\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst subMutation = this.createMutation(\n\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t'list',\n\t\t\t\t\t\t\tchildState.entity.id.value,\n\t\t\t\t\t\t\tchildState,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tif (subMutation) {\n\t\t\t\t\t\t\tmutations[subMutation[1].alias] = 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}\n\t\t\t\t\tif (subTreeState.plannedRemovals) {\n\t\t\t\t\t\tfor (const [removedId, removalType] of subTreeState.plannedRemovals) {\n\t\t\t\t\t\t\tif (removalType === 'disconnect') {\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\t\t\t\tconst key = `${subTreeState.entityName}#${removedId}`\n\t\t\t\t\t\t\t\tif (this.processedDeletes.has(key)) {\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\tthis.processedDeletes.add(key)\n\t\t\t\t\t\t\t\tconst alias = this.createAlias()\n\t\t\t\t\t\t\t\tmutations[alias] = this.createDeleteMutation(\n\t\t\t\t\t\t\t\t\tsubTreeState.entityName,\n\t\t\t\t\t\t\t\t\tremovedId,\n\t\t\t\t\t\t\t\t)\n\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} else {\n\t\t\t\t\t\t\t\tassertNever(removalType)\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} else {\n\t\t\t\t\tassertNever(subTreeState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { mutations, operations }\n\t}\n\n\tprivate createMutation(\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: 'list' | 'single',\n\t\tentityId: EntityId,\n\t\trealmState: EntityRealmState,\n\t): [ContentMutation<any>, 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 mutation = this.createDeleteMutation(\n\t\t\t\trealmState.entity.entityName,\n\t\t\t\tentityId,\n\t\t\t)\n\t\t\treturn [\n\t\t\t\tmutation,\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.createCreateMutation(\n\t\t\t\trealmState,\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\t\t\t]\n\t\t}\n\t\tconst builder = this.createUpdateMutation(\n\t\t\trealmState,\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 createDeleteMutation(\n\t\tentityName: EntityName,\n\t\tdeletedId: EntityId,\n\t): ContentMutation<any> {\n\t\treturn this.qb.delete(entityName, {\n\t\t\tby: { [PRIMARY_KEY_NAME]: deletedId },\n\t\t}, it => it.$(PRIMARY_KEY_NAME).$('__typename'))\n\t}\n\n\tprivate createUpdateMutation(\n\t\tentityRealm: EntityRealmState,\n\t\tfieldMarkers: EntityFieldMarkers,\n\t): ContentMutation<any> | undefined {\n\t\tconst input = this.getUpdateDataInput(entityRealm)\n\n\t\tif (input === undefined) {\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\treturn this.qb.update(entityRealm.entity.entityName, {\n\t\t\tby: {\n\t\t\t\t[PRIMARY_KEY_NAME]: runtimeId.value,\n\t\t\t},\n\t\t\tdata: input,\n\t\t}, it => QueryGenerator.registerQueryPart(fieldMarkers, it).$(PRIMARY_KEY_NAME).$('__typename'))\n\t}\n\n\tprivate createCreateMutation(\n\t\tentityRealm: EntityRealmState,\n\t\tfieldMarkers: EntityFieldMarkers,\n\t): ContentMutation<any> | undefined {\n\t\tconst input = this.getCreateDataInput(entityRealm)\n\t\tif (input === undefined) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn this.qb.create(entityRealm.entity.entityName, {\n\t\t\tdata: input,\n\t\t}, it => QueryGenerator.registerQueryPart(fieldMarkers, it).$(PRIMARY_KEY_NAME).$('__typename'))\n\t}\n\n\tprivate getCreateDataInput(\n\t\tcurrentState: EntityRealmState | EntityRealmStateStub,\n\t): Input.CreateDataInput | undefined {\n\t\tlet processedPlaceholders = this.processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tthis.processedPlaceholdersByEntity.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 undefined\n\t\t}\n\n\t\tconst result: Input.CreateDataInput = {}\n\t\tfor (const siblingState of StateIterator.eachSiblingRealm(currentState)) {\n\t\t\tconst pathBack = this.treeStore.getPathBackToParent(siblingState)\n\n\t\t\tconst nonbearingFields: Array<\n\t\t\t\t| { 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\t\t\t> = []\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\tconst accessor = fieldState.getAccessor()\n\t\t\t\t\t\tconst value = accessor.value ?? accessor.defaultValue ?? null\n\t\t\t\t\t\tif (value !== undefined && value !== null) {\n\t\t\t\t\t\t\tresult[marker.fieldName] = value\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase '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\tconst input = this.getCreateOneRelationInput(fieldState, marker)\n\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\tif (Array.isArray(input) && Array.isArray(current)) {\n\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = input\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase '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\tconst input = this.getCreateManyRelationInput(fieldState)\n\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = input\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ((!isEmptyObject(result)) || !getEntityMarker(siblingState).fields.hasAtLeastOneBearingField) {\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\tconst accessor = field.fieldState.getAccessor()\n\t\t\t\t\t\t\tconst value = accessor.value ?? accessor.defaultValue ?? null\n\t\t\t\t\t\t\tif (value !== undefined) {\n\t\t\t\t\t\t\t\tresult[field.marker.fieldName] = value\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 'hasOne': {\n\t\t\t\t\t\t\tconst input = this.getCreateOneRelationInput(\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)\n\t\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\t\tconst current = result[field.marker.parameters.field]\n\t\t\t\t\t\t\t\tif (Array.isArray(input) && Array.isArray(current)) {\n\t\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tresult[field.marker.parameters.field] = input\n\t\t\t\t\t\t\t\t}\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\tconst input = this.getCreateManyRelationInput(\n\t\t\t\t\t\t\t\tfield.fieldState,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\t\tconst current = result[field.marker.parameters.field]\n\t\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tresult[field.marker.parameters.field] = input\n\t\t\t\t\t\t\t\t}\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 && !isEmptyObject(result)) {\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\t|| typeof field === 'number'\n\t\t\t\t\t\t|| field === null\n\t\t\t\t\t) {\n\t\t\t\t\t\tresult[key] = field\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult[key] = { connect: field }\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn isEmptyObject(result) ? undefined : result\n\t}\n\n\tprivate getCreateOneRelationInput(\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tmarker: HasOneRelationMarker,\n\t): Input.CreateOneRelationInput | Input.CreateManyRelationInput | undefined {\n\t\tconst reducedBy = marker.parameters.reducedBy\n\t\tconst runtimeId = fieldState.entity.id\n\n\t\tif (reducedBy === undefined) {\n\t\t\tif (this.shouldConnectInsteadOfCreate(fieldState)) {\n\t\t\t\treturn { connect: { [PRIMARY_KEY_NAME]: runtimeId.value } }\n\t\t\t}\n\n\t\t\tconst createData = this.getCreateDataInput(fieldState)\n\t\t\tif (createData === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn { create: createData }\n\t\t}\n\n\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\t\tif (this.shouldConnectInsteadOfCreate(fieldState)) {\n\t\t\t// TODO also potentially update\n\t\t\treturn [{ connect: { [PRIMARY_KEY_NAME]: runtimeId.value }, alias }]\n\t\t}\n\t\tconst createData = this.getCreateDataInput(fieldState)\n\t\tif (createData === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn [{ create: createData, alias }]\n\t}\n\n\tprivate getCreateManyRelationInput(fieldState: EntityListState): Input.CreateManyRelationInput | undefined {\n\t\tconst result: Input.CreateManyRelationInput = []\n\t\tfor (const entityRealm of fieldState.children.values()) {\n\t\t\tconst runtimeId = entityRealm.entity.id\n\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\t\t\tif (this.shouldConnectInsteadOfCreate(entityRealm)) {\n\t\t\t\tresult.push({\n\t\t\t\t\talias,\n\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\tconst createData = this.getCreateDataInput(entityRealm)\n\t\t\t\tif (createData === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tresult.push({\n\t\t\t\t\talias,\n\t\t\t\t\tcreate: createData,\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\treturn result.length === 0 ? undefined : result\n\t}\n\n\tprivate shouldConnectInsteadOfCreate(currentState: EntityRealmState | EntityRealmStateStub): boolean {\n\t\tconst runtimeId = currentState.entity.id\n\t\tconst processedPlaceholders = this.processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\treturn runtimeId.existsOnServer || (runtimeId instanceof ClientGeneratedUuid && (processedPlaceholders?.has(PRIMARY_KEY_NAME) ?? false))\n\t}\n\n\tprivate getUpdateDataInput(currentState: EntityRealmState): Input.UpdateDataInput | undefined {\n\t\tlet processedPlaceholders = this.processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tthis.processedPlaceholdersByEntity.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\tconst result: Input.UpdateDataInput = {}\n\n\t\tfor (const siblingState of StateIterator.eachSiblingRealm(currentState)) {\n\t\t\tfor (const [placeholderName, fieldState] of siblingState.children) {\n\t\t\t\tif (placeholderName === PRIMARY_KEY_NAME || placeholderName === TYPENAME_KEY_NAME) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\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\tif (fieldState.persistedValue !== undefined) {\n\t\t\t\t\t\t\tconst accessor = fieldState.getAccessor()\n\t\t\t\t\t\t\tconst resolvedValue = accessor.value ?? accessor.defaultValue ?? null\n\t\t\t\t\t\t\tif (fieldState.persistedValue !== resolvedValue) {\n\t\t\t\t\t\t\t\tresult[placeholderName] = resolvedValue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase '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\tconst reducedBy = marker.parameters.reducedBy\n\n\t\t\t\t\t\tconst persistedValue = entityData?.get?.(placeholderName)?.value\n\t\t\t\t\t\tif (reducedBy === undefined) {\n\t\t\t\t\t\t\tconst relationData = this.getUpdateOneRelationInput(currentState, fieldState, persistedValue, placeholderName)\n\t\t\t\t\t\t\tif (relationData !== undefined) {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = relationData\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst relationData = this.getUpdateManyRelationForReducedInput(currentState, fieldState, persistedValue, placeholderName, reducedBy)\n\t\t\t\t\t\t\tif (relationData !== undefined) {\n\t\t\t\t\t\t\t\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\t\tcurrent.push(...relationData)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tresult[marker.parameters.field] = relationData\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\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\tconst persistedEntityIds = entityData?.get?.(placeholderName)?.value ?? new Set()\n\n\t\t\t\t\t\tif (!(persistedEntityIds instanceof Set)) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst relationData = this.getUpdateManyRelationInput(fieldState, persistedEntityIds)\n\t\t\t\t\t\tif (relationData !== undefined) {\n\t\t\t\t\t\t\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\tcurrent.push(...relationData)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = relationData\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn isEmptyObject(result) ? undefined : result\n\t}\n\n\tprivate getUpdateOneRelationInput(\n\t\tcurrentState: EntityRealmState,\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tpersistedValue: EntityFieldPersistedValue | undefined,\n\t\tplaceholderName: PlaceholderName,\n\t): Input.UpdateOneRelationInput | undefined {\n\t\tconst runtimeId = fieldState.entity.id\n\t\tif (persistedValue instanceof ServerId) {\n\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\t// The persisted and currently referenced ids match, and so this is an update.\n\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\treturn undefined // …unless we're dealing with a stub. There cannot be any updates there.\n\t\t\t\t}\n\t\t\t\tconst input = this.getUpdateDataInput(fieldState)\n\t\t\t\tif (input === undefined) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tupdate: input,\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// There was a referenced entity but currently, there is a different one. Let's investigate:\n\n\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\tconst key = `${persistedValue.entityName}#${persistedValue.value}`\n\t\t\t\tif (this.processedDeletes.has(key)) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tthis.processedDeletes.add(key)\n\n\t\t\t\t// It's planned for deletion.\n\t\t\t\t// TODO also potentially do something about the current entity\n\t\t\t\treturn {\n\t\t\t\t\tdelete: true,\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (runtimeId.existsOnServer) {\n\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// TODO also potentially update\n\t\t\t\treturn {\n\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t}\n\t\t\t}\n\t\t\t// The currently present entity doesn't exist on the server. Try if creating yields anything…\n\t\t\tconst createInput = this.getCreateDataInput(fieldState)\n\t\t\tif (createInput !== undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tcreate: createInput,\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// …but if it doesn't, we just disconnect.\n\t\t\t\treturn {\n\t\t\t\t\tdisconnect: true,\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (runtimeId.existsOnServer) {\n\t\t\t// There isn't a linked entity on the server but we're seeing one that exists there.\n\t\t\t// Thus this is a connect.\n\t\t\t// TODO also potentially update\n\t\t\treturn {\n\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t}\n\t\t} else {\n\t\t\tconst input = this.getCreateDataInput(fieldState)\n\t\t\tif (input === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcreate: input,\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getUpdateManyRelationForReducedInput(\n\t\tcurrentState: EntityRealmState,\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tpersistedValue: EntityFieldPersistedValue | undefined,\n\t\tplaceholderName: PlaceholderName,\n\t\treducedBy: UniqueWhere,\n\t): Input.UpdateManyRelationInput | undefined {\n\t\tconst runtimeId = fieldState.entity.id\n\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\tif (persistedValue instanceof ServerId) {\n\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tconst updateData = this.getUpdateDataInput(fieldState)\n\t\t\t\tif (updateData === undefined) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\treturn [{\n\t\t\t\t\talias,\n\t\t\t\t\tupdate: {\n\t\t\t\t\t\tby: reducedBy,\n\t\t\t\t\t\tdata: updateData,\n\t\t\t\t\t},\n\t\t\t\t}]\n\t\t\t}\n\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\tconst key = `${persistedValue.entityName}#${persistedValue.value}`\n\t\t\t\tif (this.processedDeletes.has(key)) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tthis.processedDeletes.add(key)\n\t\t\t\treturn [{\n\t\t\t\t\talias,\n\t\t\t\t\tdelete: reducedBy,\n\t\t\t\t}]\n\t\t\t}\n\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t// TODO will re-using the alias like this work?\n\t\t\t\t// TODO also potentially update\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tdisconnect: reducedBy,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t}\n\t\t\tconst createInput = this.getCreateDataInput(fieldState)\n\n\t\t\tif (createInput === undefined) {\n\t\t\t\treturn [{\n\t\t\t\t\talias,\n\t\t\t\t\tdisconnect: reducedBy,\n\t\t\t\t}]\n\t\t\t}\n\t\t\treturn [{\n\t\t\t\talias,\n\t\t\t\tcreate: createInput,\n\t\t\t}]\n\t\t} else if (runtimeId.existsOnServer) {\n\t\t\treturn [{\n\t\t\t\talias,\n\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t}]\n\t\t} else {\n\t\t\tconst createInput = this.getCreateDataInput(fieldState)\n\t\t\tif (createInput === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn [{\n\t\t\t\talias,\n\t\t\t\tcreate: createInput,\n\t\t\t}]\n\t\t}\n\t}\n\n\tprivate getUpdateManyRelationInput(\n\t\tfieldState: EntityListState,\n\t\tpersistedEntityIds: Set<EntityId>,\n\t): Input.UpdateManyRelationInput | undefined {\n\t\tconst input: Input.UpdateManyRelationInput = []\n\t\tfor (const childState of fieldState.children.values()) {\n\t\t\tconst runtimeId = childState.entity.id\n\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\tif (persistedEntityIds.has(runtimeId.value)) {\n\t\t\t\t\tif (childState.type !== 'entityRealmStub') {\n\t\t\t\t\t\tconst dataInput = this.getUpdateDataInput(childState)\n\n\t\t\t\t\t\tif (dataInput !== undefined) {\n\t\t\t\t\t\t\tinput.push({\n\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\tupdate: {\n\t\t\t\t\t\t\t\t\tby: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t\t\t\t\tdata: dataInput,\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}\n\t\t\t\t} else {\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst dataInput = this.getCreateDataInput(childState)\n\t\t\t\tif (dataInput !== undefined) {\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tcreate: dataInput,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (fieldState.plannedRemovals) {\n\t\t\tfor (const [removedId, removalType] of fieldState.plannedRemovals) {\n\t\t\t\tconst alias = MutationAlias.encodeEntityId(new ServerId(removedId, fieldState.entityName))\n\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\tconst key = `${fieldState.entityName}#${removedId}`\n\t\t\t\t\tif (this.processedDeletes.has(key)) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tthis.processedDeletes.add(key)\n\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tdelete: { [PRIMARY_KEY_NAME]: removedId },\n\t\t\t\t\t})\n\t\t\t\t} else if (removalType === 'disconnect') {\n\t\t\t\t\t// TODO also potentially update\n\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tdisconnect: { [PRIMARY_KEY_NAME]: removedId },\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(removalType)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn input.length === 0 ? undefined : input\n\t}\n\n\tprivate createAlias(): string {\n\t\treturn `op_${this.aliasCounter++}`\n\t}\n}\n"],"names":["assertNever","getEntityMarker","builder","PRIMARY_KEY_NAME","QueryGenerator","StateIterator","placeholderName","TYPENAME_KEY_NAME","ClientGeneratedUuid","HasOneRelationMarker","BindingError","HasManyRelationMarker","isEmptyObject","createData","MutationAlias","ServerId"],"mappings":";;;;;;;;;;;AAkCO,MAAM,kBAAkB;AAAA,EAKtB,YACU,WACA,IAChB;AAFgB,SAAA,YAAA;AACA,SAAA,KAAA;AANlB,kBAAA,MAAQ,gBAAe,CAAA;AACvB,kBAAA,MAAQ,qDAAmE,IAAA,CAAI;AAC/E,kBAAA,MAAQ,wCAAuB,IAAA,CAAY;AAAA,EAM3C;AAAA,EAEA,OAAc,mBAAmB,WAAsB,IAAgD;AACtG,WAAO,IAAI,kBAAkB,WAAW,EAAE,EAAE,mBAAA;AAAA,EAC7C;AAAA,EAEQ,qBAA4C;AACnD,UAAM,YAAkD,CAAA;AACxD,UAAM,aAAqC,CAAA;AAE3C,eAAW,CAAC,YAAY,UAAU,KAAK,KAAK,UAAU,oBAAoB,WAAW;AACpF,iBAAW,CAAC,iBAAiB,YAAY,KAAK,MAAM,KAAK,WAAW,QAAA,CAAS,EAAE,WAAW;AACzF,YAAI,aAAa,2BAA2B,GAAG;AAC9C;AAAA,QACD;AACA,YAAI,aAAa,SAAS,eAAe;AACxC,cACC,aAAa,UAAU,SAAS,aAAa,aAAa,UAAU,OAAO,WA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B;AAClE,cAAM,QAAQW,cAAAA,cAAc,eAAe,IAAIC,cAAAA,SAAS,WAAW,WAAW,UAAU,CAAC;AACzF,YAAI,gBAAgB,UAAU;AAC7B,gBAAM,MAAM,GAAG,WAAW,UAAU,IAAI,SAAS;AACjD,cAAI,KAAK,iBAAiB,IAAI,GAAG,GAAG;AACnC;AAAA,UACD;AACA,eAAK,iBAAiB,IAAI,GAAG;AAE7B,gBAAM,KAAK;AAAA,YACV;AAAA,YACA,QAAQ,EAAE,CAACZ,cAAAA,gBAAgB,GAAG,UAAA;AAAA,UAAU,CACxC;AAAA,QACF,WAAW,gBAAgB,cAAc;AAGxC,gBAAM,KAAK;AAAA,YACV;AAAA,YACA,YAAY,EAAE,CAACA,cAAAA,gBAAgB,GAAG,UAAA;AAAA,UAAU,CAC5C;AAAA,QACF,OAAO;AACNH,wBAAAA,YAAY,WAAW;AAAA,QACxB;AAAA,MACD;AAAA,IACD;AAEA,WAAO,MAAM,WAAW,IAAI,SAAY;AAAA,EACzC;AAAA,EAEQ,cAAsB;AAC7B,WAAO,MAAM,KAAK,cAAc;AAAA,EACjC;AACD;;"}
|
|
1
|
+
{"version":3,"file":"MutationGenerator.cjs","sources":["../../../../../packages/binding-legacy/src/core/MutationGenerator.ts"],"sourcesContent":["import { ContentMutation, ContentQueryBuilder, Input } from '@contember/client'\nimport { ClientGeneratedUuid, ReceivedEntityData, ServerId } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '@contember/binding-common'\nimport { EntityFieldMarkers, FieldMarker, HasManyRelationMarker, HasOneRelationMarker } from '@contember/binding-common'\nimport type { EntityId, EntityName, PlaceholderName, UniqueWhere } from '@contember/binding-common'\nimport { isEmptyObject } from '../utils/index.js'\nimport { assertNever } from '@contember/binding-common'\nimport { QueryGenerator } from './QueryGenerator.js'\nimport { MutationAlias } from './requestAliases/index.js'\nimport { EntityListState, EntityRealmState, EntityRealmStateStub, EntityState, FieldState, getEntityMarker, StateIterator } from './state/index.js'\nimport type { TreeStore } from './TreeStore.js'\nimport { EntityFieldPersistedData, EntityFieldPersistedValue } from '../accessorTree/index.js'\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\tmutations: Record<string, ContentMutation<ReceivedEntityData>>\n\toperations: SubMutationOperation[]\n}\n\n// TODO enforce correct expected mutations in dev mode.\nexport class MutationGenerator {\n\tprivate aliasCounter = 1\n\tprivate processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity = new Map()\n\tprivate processedDeletes = new Set<string>()\n\n\tprivate constructor(\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly qb: ContentQueryBuilder,\n\t) {\n\t}\n\n\tpublic static getPersistMutation(treeStore: TreeStore, qb: ContentQueryBuilder): PersistMutationResult {\n\t\treturn new MutationGenerator(treeStore, qb).getPersistMutation()\n\t}\n\n\tprivate getPersistMutation(): PersistMutationResult {\n\t\tconst mutations: Record<string, ContentMutation<any>> = {}\n\t\tconst operations: SubMutationOperation[] = []\n\n\t\tfor (const [treeRootId, rootStates] of this.treeStore.subTreeStatesByRoot.entries()) {\n\t\t\tfor (const [placeholderName, subTreeState] of Array.from(rootStates.entries()).reverse()) {\n\t\t\t\tif (subTreeState.unpersistedChangesCount <= 0) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (subTreeState.type === 'entityRealm') {\n\t\t\t\t\tif (\n\t\t\t\t\t\tsubTreeState.blueprint.type === 'subTree' && subTreeState.blueprint.marker.parameters.isCreating\n\t\t\t\t\t\t&& subTreeState.blueprint.marker.parameters.isUnpersisted\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst subMutation = this.createMutation(\n\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t'single',\n\t\t\t\t\t\tsubTreeState.entity.id.value,\n\t\t\t\t\t\tsubTreeState,\n\t\t\t\t\t)\n\t\t\t\t\tif (subMutation) {\n\t\t\t\t\t\tmutations[subMutation[1].alias] = subMutation[0]\n\t\t\t\t\t\toperations.push(subMutation[1])\n\t\t\t\t\t}\n\t\t\t\t} else if (subTreeState.type === 'entityList') {\n\t\t\t\t\tif (\n\t\t\t\t\t\tsubTreeState.blueprint.type === 'subTree' && subTreeState.blueprint.marker.parameters.isCreating\n\t\t\t\t\t\t&& subTreeState.blueprint.marker.parameters.isUnpersisted\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const childState of subTreeState.children.values()) {\n\t\t\t\t\t\tif (childState.type === 'entityRealmStub') {\n\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\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst subMutation = this.createMutation(\n\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t'list',\n\t\t\t\t\t\t\tchildState.entity.id.value,\n\t\t\t\t\t\t\tchildState,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tif (subMutation) {\n\t\t\t\t\t\t\tmutations[subMutation[1].alias] = 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}\n\t\t\t\t\tif (subTreeState.plannedRemovals) {\n\t\t\t\t\t\tfor (const [removedId, removalType] of subTreeState.plannedRemovals) {\n\t\t\t\t\t\t\tif (removalType === 'disconnect') {\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\t\t\t\tconst key = `${subTreeState.entityName}#${removedId}`\n\t\t\t\t\t\t\t\tif (this.processedDeletes.has(key)) {\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\tthis.processedDeletes.add(key)\n\t\t\t\t\t\t\t\tconst alias = this.createAlias()\n\t\t\t\t\t\t\t\tmutations[alias] = this.createDeleteMutation(\n\t\t\t\t\t\t\t\t\tsubTreeState.entityName,\n\t\t\t\t\t\t\t\t\tremovedId,\n\t\t\t\t\t\t\t\t)\n\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} else {\n\t\t\t\t\t\t\t\tassertNever(removalType)\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} else {\n\t\t\t\t\tassertNever(subTreeState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { mutations, operations }\n\t}\n\n\tprivate createMutation(\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: 'list' | 'single',\n\t\tentityId: EntityId,\n\t\trealmState: EntityRealmState,\n\t): [ContentMutation<any>, 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 mutation = this.createDeleteMutation(\n\t\t\t\trealmState.entity.entityName,\n\t\t\t\tentityId,\n\t\t\t)\n\t\t\treturn [\n\t\t\t\tmutation,\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.createCreateMutation(\n\t\t\t\trealmState,\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\t\t\t]\n\t\t}\n\t\tconst builder = this.createUpdateMutation(\n\t\t\trealmState,\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 createDeleteMutation(\n\t\tentityName: EntityName,\n\t\tdeletedId: EntityId,\n\t): ContentMutation<any> {\n\t\treturn this.qb.delete(entityName, {\n\t\t\tby: { [PRIMARY_KEY_NAME]: deletedId },\n\t\t}, it => it.$(PRIMARY_KEY_NAME).$('__typename'))\n\t}\n\n\tprivate createUpdateMutation(\n\t\tentityRealm: EntityRealmState,\n\t\tfieldMarkers: EntityFieldMarkers,\n\t): ContentMutation<any> | undefined {\n\t\tconst input = this.getUpdateDataInput(entityRealm)\n\n\t\tif (input === undefined) {\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\treturn this.qb.update(entityRealm.entity.entityName, {\n\t\t\tby: {\n\t\t\t\t[PRIMARY_KEY_NAME]: runtimeId.value,\n\t\t\t},\n\t\t\tdata: input,\n\t\t}, it => QueryGenerator.registerQueryPart(fieldMarkers, it).$(PRIMARY_KEY_NAME).$('__typename'))\n\t}\n\n\tprivate createCreateMutation(\n\t\tentityRealm: EntityRealmState,\n\t\tfieldMarkers: EntityFieldMarkers,\n\t): ContentMutation<any> | undefined {\n\t\tconst input = this.getCreateDataInput(entityRealm)\n\t\tif (input === undefined) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn this.qb.create(entityRealm.entity.entityName, {\n\t\t\tdata: input,\n\t\t}, it => QueryGenerator.registerQueryPart(fieldMarkers, it).$(PRIMARY_KEY_NAME).$('__typename'))\n\t}\n\n\tprivate getCreateDataInput(\n\t\tcurrentState: EntityRealmState | EntityRealmStateStub,\n\t): Input.CreateDataInput | undefined {\n\t\tlet processedPlaceholders = this.processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tthis.processedPlaceholdersByEntity.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 undefined\n\t\t}\n\n\t\tconst result: Input.CreateDataInput = {}\n\t\tfor (const siblingState of StateIterator.eachSiblingRealm(currentState)) {\n\t\t\tconst pathBack = this.treeStore.getPathBackToParent(siblingState)\n\n\t\t\tconst nonbearingFields: Array<\n\t\t\t\t| { 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\t\t\t> = []\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\tconst accessor = fieldState.getAccessor()\n\t\t\t\t\t\tconst value = accessor.value ?? accessor.defaultValue ?? null\n\t\t\t\t\t\tif (value !== undefined && value !== null) {\n\t\t\t\t\t\t\tresult[marker.fieldName] = value\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase '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\tconst input = this.getCreateOneRelationInput(fieldState, marker)\n\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\tif (Array.isArray(input) && Array.isArray(current)) {\n\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = input\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase '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\tconst input = this.getCreateManyRelationInput(fieldState)\n\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = input\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ((!isEmptyObject(result)) || !getEntityMarker(siblingState).fields.hasAtLeastOneBearingField) {\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\tconst accessor = field.fieldState.getAccessor()\n\t\t\t\t\t\t\tconst value = accessor.value ?? accessor.defaultValue ?? null\n\t\t\t\t\t\t\tif (value !== undefined) {\n\t\t\t\t\t\t\t\tresult[field.marker.fieldName] = value\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 'hasOne': {\n\t\t\t\t\t\t\tconst input = this.getCreateOneRelationInput(\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)\n\t\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\t\tconst current = result[field.marker.parameters.field]\n\t\t\t\t\t\t\t\tif (Array.isArray(input) && Array.isArray(current)) {\n\t\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tresult[field.marker.parameters.field] = input\n\t\t\t\t\t\t\t\t}\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\tconst input = this.getCreateManyRelationInput(\n\t\t\t\t\t\t\t\tfield.fieldState,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\t\tconst current = result[field.marker.parameters.field]\n\t\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tresult[field.marker.parameters.field] = input\n\t\t\t\t\t\t\t\t}\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 && !isEmptyObject(result)) {\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\t|| typeof field === 'number'\n\t\t\t\t\t\t|| field === null\n\t\t\t\t\t) {\n\t\t\t\t\t\tresult[key] = field\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult[key] = { connect: field }\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn isEmptyObject(result) ? undefined : result\n\t}\n\n\tprivate getCreateOneRelationInput(\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tmarker: HasOneRelationMarker,\n\t): Input.CreateOneRelationInput | Input.CreateManyRelationInput | undefined {\n\t\tconst reducedBy = marker.parameters.reducedBy\n\t\tconst runtimeId = fieldState.entity.id\n\n\t\tif (reducedBy === undefined) {\n\t\t\tif (this.shouldConnectInsteadOfCreate(fieldState)) {\n\t\t\t\treturn { connect: { [PRIMARY_KEY_NAME]: runtimeId.value } }\n\t\t\t}\n\n\t\t\tconst createData = this.getCreateDataInput(fieldState)\n\t\t\tif (createData === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn { create: createData }\n\t\t}\n\n\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\t\tif (this.shouldConnectInsteadOfCreate(fieldState)) {\n\t\t\t// TODO also potentially update\n\t\t\treturn [{ connect: { [PRIMARY_KEY_NAME]: runtimeId.value }, alias }]\n\t\t}\n\t\tconst createData = this.getCreateDataInput(fieldState)\n\t\tif (createData === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn [{ create: createData, alias }]\n\t}\n\n\tprivate getCreateManyRelationInput(fieldState: EntityListState): Input.CreateManyRelationInput | undefined {\n\t\tconst result: Input.CreateManyRelationInput = []\n\t\tfor (const entityRealm of fieldState.children.values()) {\n\t\t\tconst runtimeId = entityRealm.entity.id\n\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\t\t\tif (this.shouldConnectInsteadOfCreate(entityRealm)) {\n\t\t\t\tresult.push({\n\t\t\t\t\talias,\n\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\tconst createData = this.getCreateDataInput(entityRealm)\n\t\t\t\tif (createData === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tresult.push({\n\t\t\t\t\talias,\n\t\t\t\t\tcreate: createData,\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\treturn result.length === 0 ? undefined : result\n\t}\n\n\tprivate shouldConnectInsteadOfCreate(currentState: EntityRealmState | EntityRealmStateStub): boolean {\n\t\tconst runtimeId = currentState.entity.id\n\t\tconst processedPlaceholders = this.processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\treturn runtimeId.existsOnServer || (runtimeId instanceof ClientGeneratedUuid && (processedPlaceholders?.has(PRIMARY_KEY_NAME) ?? false))\n\t}\n\n\tprivate getUpdateDataInput(currentState: EntityRealmState): Input.UpdateDataInput | undefined {\n\t\tlet processedPlaceholders = this.processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tthis.processedPlaceholdersByEntity.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\tconst result: Input.UpdateDataInput = {}\n\n\t\tfor (const siblingState of StateIterator.eachSiblingRealm(currentState)) {\n\t\t\tfor (const [placeholderName, fieldState] of siblingState.children) {\n\t\t\t\tif (placeholderName === PRIMARY_KEY_NAME || placeholderName === TYPENAME_KEY_NAME) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\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\tif (fieldState.persistedValue !== undefined) {\n\t\t\t\t\t\t\tconst accessor = fieldState.getAccessor()\n\t\t\t\t\t\t\tconst resolvedValue = accessor.value ?? accessor.defaultValue ?? null\n\t\t\t\t\t\t\tif (fieldState.persistedValue !== resolvedValue) {\n\t\t\t\t\t\t\t\tresult[placeholderName] = resolvedValue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase '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\tconst reducedBy = marker.parameters.reducedBy\n\n\t\t\t\t\t\tconst persistedValue = entityData?.get?.(placeholderName)?.value\n\t\t\t\t\t\tif (reducedBy === undefined) {\n\t\t\t\t\t\t\tconst relationData = this.getUpdateOneRelationInput(currentState, fieldState, persistedValue, placeholderName)\n\t\t\t\t\t\t\tif (relationData !== undefined) {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = relationData\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst relationData = this.getUpdateManyRelationForReducedInput(currentState, fieldState, persistedValue, placeholderName, reducedBy)\n\t\t\t\t\t\t\tif (relationData !== undefined) {\n\t\t\t\t\t\t\t\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\t\tcurrent.push(...relationData)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tresult[marker.parameters.field] = relationData\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\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\tconst persistedEntityIds = entityData?.get?.(placeholderName)?.value ?? new Set()\n\n\t\t\t\t\t\tif (!(persistedEntityIds instanceof Set)) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst relationData = this.getUpdateManyRelationInput(fieldState, persistedEntityIds)\n\t\t\t\t\t\tif (relationData !== undefined) {\n\t\t\t\t\t\t\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\tcurrent.push(...relationData)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = relationData\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn isEmptyObject(result) ? undefined : result\n\t}\n\n\tprivate getUpdateOneRelationInput(\n\t\tcurrentState: EntityRealmState,\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tpersistedValue: EntityFieldPersistedValue | undefined,\n\t\tplaceholderName: PlaceholderName,\n\t): Input.UpdateOneRelationInput | undefined {\n\t\tconst runtimeId = fieldState.entity.id\n\t\tif (persistedValue instanceof ServerId) {\n\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\t// The persisted and currently referenced ids match, and so this is an update.\n\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\treturn undefined // …unless we're dealing with a stub. There cannot be any updates there.\n\t\t\t\t}\n\t\t\t\tconst input = this.getUpdateDataInput(fieldState)\n\t\t\t\tif (input === undefined) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tupdate: input,\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// There was a referenced entity but currently, there is a different one. Let's investigate:\n\n\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\tconst key = `${persistedValue.entityName}#${persistedValue.value}`\n\t\t\t\tif (this.processedDeletes.has(key)) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tthis.processedDeletes.add(key)\n\n\t\t\t\t// It's planned for deletion.\n\t\t\t\t// TODO also potentially do something about the current entity\n\t\t\t\treturn {\n\t\t\t\t\tdelete: true,\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (runtimeId.existsOnServer) {\n\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// TODO also potentially update\n\t\t\t\treturn {\n\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t}\n\t\t\t}\n\t\t\t// The currently present entity doesn't exist on the server. Try if creating yields anything…\n\t\t\tconst createInput = this.getCreateDataInput(fieldState)\n\t\t\tif (createInput !== undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tcreate: createInput,\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// …but if it doesn't, we just disconnect.\n\t\t\t\treturn {\n\t\t\t\t\tdisconnect: true,\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (runtimeId.existsOnServer) {\n\t\t\t// There isn't a linked entity on the server but we're seeing one that exists there.\n\t\t\t// Thus this is a connect.\n\t\t\t// TODO also potentially update\n\t\t\treturn {\n\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t}\n\t\t} else {\n\t\t\tconst input = this.getCreateDataInput(fieldState)\n\t\t\tif (input === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcreate: input,\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getUpdateManyRelationForReducedInput(\n\t\tcurrentState: EntityRealmState,\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tpersistedValue: EntityFieldPersistedValue | undefined,\n\t\tplaceholderName: PlaceholderName,\n\t\treducedBy: UniqueWhere,\n\t): Input.UpdateManyRelationInput | undefined {\n\t\tconst runtimeId = fieldState.entity.id\n\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\tif (persistedValue instanceof ServerId) {\n\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tconst updateData = this.getUpdateDataInput(fieldState)\n\t\t\t\tif (updateData === undefined) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\treturn [{\n\t\t\t\t\talias,\n\t\t\t\t\tupdate: {\n\t\t\t\t\t\tby: reducedBy,\n\t\t\t\t\t\tdata: updateData,\n\t\t\t\t\t},\n\t\t\t\t}]\n\t\t\t}\n\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\tconst key = `${persistedValue.entityName}#${persistedValue.value}`\n\t\t\t\tif (this.processedDeletes.has(key)) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tthis.processedDeletes.add(key)\n\t\t\t\treturn [{\n\t\t\t\t\talias,\n\t\t\t\t\tdelete: reducedBy,\n\t\t\t\t}]\n\t\t\t}\n\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t// TODO will re-using the alias like this work?\n\t\t\t\t// TODO also potentially update\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tdisconnect: reducedBy,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t}\n\t\t\tconst createInput = this.getCreateDataInput(fieldState)\n\n\t\t\tif (createInput === undefined) {\n\t\t\t\treturn [{\n\t\t\t\t\talias,\n\t\t\t\t\tdisconnect: reducedBy,\n\t\t\t\t}]\n\t\t\t}\n\t\t\treturn [{\n\t\t\t\talias,\n\t\t\t\tcreate: createInput,\n\t\t\t}]\n\t\t} else if (runtimeId.existsOnServer) {\n\t\t\treturn [{\n\t\t\t\talias,\n\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t}]\n\t\t} else {\n\t\t\tconst createInput = this.getCreateDataInput(fieldState)\n\t\t\tif (createInput === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn [{\n\t\t\t\talias,\n\t\t\t\tcreate: createInput,\n\t\t\t}]\n\t\t}\n\t}\n\n\tprivate getUpdateManyRelationInput(\n\t\tfieldState: EntityListState,\n\t\tpersistedEntityIds: Set<EntityId>,\n\t): Input.UpdateManyRelationInput | undefined {\n\t\tconst input: Input.UpdateManyRelationInput = []\n\t\tfor (const childState of fieldState.children.values()) {\n\t\t\tconst runtimeId = childState.entity.id\n\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\tif (persistedEntityIds.has(runtimeId.value)) {\n\t\t\t\t\tif (childState.type !== 'entityRealmStub') {\n\t\t\t\t\t\tconst dataInput = this.getUpdateDataInput(childState)\n\n\t\t\t\t\t\tif (dataInput !== undefined) {\n\t\t\t\t\t\t\tinput.push({\n\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\tupdate: {\n\t\t\t\t\t\t\t\t\tby: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t\t\t\t\tdata: dataInput,\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}\n\t\t\t\t} else {\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst dataInput = this.getCreateDataInput(childState)\n\t\t\t\tif (dataInput !== undefined) {\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tcreate: dataInput,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (fieldState.plannedRemovals) {\n\t\t\tfor (const [removedId, removalType] of fieldState.plannedRemovals) {\n\t\t\t\tconst alias = MutationAlias.encodeEntityId(new ServerId(removedId, fieldState.entityName))\n\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\tconst key = `${fieldState.entityName}#${removedId}`\n\t\t\t\t\tif (this.processedDeletes.has(key)) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tthis.processedDeletes.add(key)\n\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tdelete: { [PRIMARY_KEY_NAME]: removedId },\n\t\t\t\t\t})\n\t\t\t\t} else if (removalType === 'disconnect') {\n\t\t\t\t\t// TODO also potentially update\n\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tdisconnect: { [PRIMARY_KEY_NAME]: removedId },\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(removalType)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn input.length === 0 ? undefined : input\n\t}\n\n\tprivate createAlias(): string {\n\t\treturn `op_${this.aliasCounter++}`\n\t}\n}\n"],"names":["assertNever","getEntityMarker","builder","PRIMARY_KEY_NAME","QueryGenerator","StateIterator","placeholderName","TYPENAME_KEY_NAME","ClientGeneratedUuid","HasOneRelationMarker","BindingError","HasManyRelationMarker","isEmptyObject","createData","MutationAlias","ServerId"],"mappings":";;;;;;;;;;;AAkCO,MAAM,kBAAkB;AAAA,EAKtB,YACU,WACA,IAChB;AAFgB,SAAA,YAAA;AACA,SAAA,KAAA;AANlB,kBAAA,MAAQ,gBAAe,CAAA;AACvB,kBAAA,MAAQ,qDAAmE,IAAA,CAAI;AAC/E,kBAAA,MAAQ,wCAAuB,IAAA,CAAY;AAAA,EAM3C;AAAA,EAEA,OAAc,mBAAmB,WAAsB,IAAgD;AACtG,WAAO,IAAI,kBAAkB,WAAW,EAAE,EAAE,mBAAA;AAAA,EAC7C;AAAA,EAEQ,qBAA4C;AACnD,UAAM,YAAkD,CAAA;AACxD,UAAM,aAAqC,CAAA;AAE3C,eAAW,CAAC,YAAY,UAAU,KAAK,KAAK,UAAU,oBAAoB,WAAW;AACpF,iBAAW,CAAC,iBAAiB,YAAY,KAAK,MAAM,KAAK,WAAW,QAAA,CAAS,EAAE,WAAW;AACzF,YAAI,aAAa,2BAA2B,GAAG;AAC9C;AAAA,QACD;AACA,YAAI,aAAa,SAAS,eAAe;AACxC,cACC,aAAa,UAAU,SAAS,aAAa,aAAa,UAAU,OAAO,WAAW,cACnF,aAAa,UAAU,OAAO,WAAW,eAC3C;AACD;AAAA,UACD;AACA,gBAAM,cAAc,KAAK;AAAA,YACxB;AAAA,YACA;AAAA,YACA,aAAa,OAAO,GAAG;AAAA,YACvB;AAAA,UAAA;AAED,cAAI,aAAa;AA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AAK,iBAAiB,IAAI,GAAG,GAAG;AACnC;AAAA,UACD;AACA,eAAK,iBAAiB,IAAI,GAAG;AAE7B,gBAAM,KAAK;AAAA,YACV;AAAA,YACA,QAAQ,EAAE,CAACZ,cAAAA,gBAAgB,GAAG,UAAA;AAAA,UAAU,CACxC;AAAA,QACF,WAAW,gBAAgB,cAAc;AAGxC,gBAAM,KAAK;AAAA,YACV;AAAA,YACA,YAAY,EAAE,CAACA,cAAAA,gBAAgB,GAAG,UAAA;AAAA,UAAU,CAC5C;AAAA,QACF,OAAO;AACNH,wBAAAA,YAAY,WAAW;AAAA,QACxB;AAAA,MACD;AAAA,IACD;AAEA,WAAO,MAAM,WAAW,IAAI,SAAY;AAAA,EACzC;AAAA,EAEQ,cAAsB;AAC7B,WAAO,MAAM,KAAK,cAAc;AAAA,EACjC;AACD;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MutationGenerator.js","sources":["../../../../../packages/binding-legacy/src/core/MutationGenerator.ts"],"sourcesContent":["import { ContentMutation, ContentQueryBuilder, Input } from '@contember/client'\nimport { ClientGeneratedUuid, ReceivedEntityData, ServerId } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '@contember/binding-common'\nimport { EntityFieldMarkers, FieldMarker, HasManyRelationMarker, HasOneRelationMarker } from '@contember/binding-common'\nimport type { EntityId, EntityName, PlaceholderName, UniqueWhere } from '@contember/binding-common'\nimport { isEmptyObject } from '../utils'\nimport { assertNever } from '@contember/binding-common'\nimport { QueryGenerator } from './QueryGenerator'\nimport { MutationAlias } from './requestAliases'\nimport { EntityListState, EntityRealmState, EntityRealmStateStub, EntityState, FieldState, getEntityMarker, StateIterator } from './state'\nimport type { TreeStore } from './TreeStore'\nimport { EntityFieldPersistedData, EntityFieldPersistedValue } from '../accessorTree'\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\tmutations: Record<string, ContentMutation<ReceivedEntityData>>\n\toperations: SubMutationOperation[]\n}\n\n// TODO enforce correct expected mutations in dev mode.\nexport class MutationGenerator {\n\tprivate aliasCounter = 1\n\tprivate processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity = new Map()\n\tprivate processedDeletes = new Set<string>()\n\n\tprivate constructor(\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly qb: ContentQueryBuilder,\n\t) {\n\t}\n\n\tpublic static getPersistMutation(treeStore: TreeStore, qb: ContentQueryBuilder): PersistMutationResult {\n\t\treturn new MutationGenerator(treeStore, qb).getPersistMutation()\n\t}\n\n\tprivate getPersistMutation(): PersistMutationResult {\n\t\tconst mutations: Record<string, ContentMutation<any>> = {}\n\t\tconst operations: SubMutationOperation[] = []\n\n\t\tfor (const [treeRootId, rootStates] of this.treeStore.subTreeStatesByRoot.entries()) {\n\t\t\tfor (const [placeholderName, subTreeState] of Array.from(rootStates.entries()).reverse()) {\n\t\t\t\tif (subTreeState.unpersistedChangesCount <= 0) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (subTreeState.type === 'entityRealm') {\n\t\t\t\t\tif (\n\t\t\t\t\t\tsubTreeState.blueprint.type === 'subTree' && subTreeState.blueprint.marker.parameters.isCreating\n\t\t\t\t\t\t&& subTreeState.blueprint.marker.parameters.isUnpersisted\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst subMutation = this.createMutation(\n\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t'single',\n\t\t\t\t\t\tsubTreeState.entity.id.value,\n\t\t\t\t\t\tsubTreeState,\n\t\t\t\t\t)\n\t\t\t\t\tif (subMutation) {\n\t\t\t\t\t\tmutations[subMutation[1].alias] = subMutation[0]\n\t\t\t\t\t\toperations.push(subMutation[1])\n\t\t\t\t\t}\n\t\t\t\t} else if (subTreeState.type === 'entityList') {\n\t\t\t\t\tif (\n\t\t\t\t\t\tsubTreeState.blueprint.type === 'subTree' && subTreeState.blueprint.marker.parameters.isCreating\n\t\t\t\t\t\t&& subTreeState.blueprint.marker.parameters.isUnpersisted\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const childState of subTreeState.children.values()) {\n\t\t\t\t\t\tif (childState.type === 'entityRealmStub') {\n\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\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst subMutation = this.createMutation(\n\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t'list',\n\t\t\t\t\t\t\tchildState.entity.id.value,\n\t\t\t\t\t\t\tchildState,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tif (subMutation) {\n\t\t\t\t\t\t\tmutations[subMutation[1].alias] = 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}\n\t\t\t\t\tif (subTreeState.plannedRemovals) {\n\t\t\t\t\t\tfor (const [removedId, removalType] of subTreeState.plannedRemovals) {\n\t\t\t\t\t\t\tif (removalType === 'disconnect') {\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\t\t\t\tconst key = `${subTreeState.entityName}#${removedId}`\n\t\t\t\t\t\t\t\tif (this.processedDeletes.has(key)) {\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\tthis.processedDeletes.add(key)\n\t\t\t\t\t\t\t\tconst alias = this.createAlias()\n\t\t\t\t\t\t\t\tmutations[alias] = this.createDeleteMutation(\n\t\t\t\t\t\t\t\t\tsubTreeState.entityName,\n\t\t\t\t\t\t\t\t\tremovedId,\n\t\t\t\t\t\t\t\t)\n\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} else {\n\t\t\t\t\t\t\t\tassertNever(removalType)\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} else {\n\t\t\t\t\tassertNever(subTreeState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { mutations, operations }\n\t}\n\n\tprivate createMutation(\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: 'list' | 'single',\n\t\tentityId: EntityId,\n\t\trealmState: EntityRealmState,\n\t): [ContentMutation<any>, 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 mutation = this.createDeleteMutation(\n\t\t\t\trealmState.entity.entityName,\n\t\t\t\tentityId,\n\t\t\t)\n\t\t\treturn [\n\t\t\t\tmutation,\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.createCreateMutation(\n\t\t\t\trealmState,\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\t\t\t]\n\t\t}\n\t\tconst builder = this.createUpdateMutation(\n\t\t\trealmState,\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 createDeleteMutation(\n\t\tentityName: EntityName,\n\t\tdeletedId: EntityId,\n\t): ContentMutation<any> {\n\t\treturn this.qb.delete(entityName, {\n\t\t\tby: { [PRIMARY_KEY_NAME]: deletedId },\n\t\t}, it => it.$(PRIMARY_KEY_NAME).$('__typename'))\n\t}\n\n\tprivate createUpdateMutation(\n\t\tentityRealm: EntityRealmState,\n\t\tfieldMarkers: EntityFieldMarkers,\n\t): ContentMutation<any> | undefined {\n\t\tconst input = this.getUpdateDataInput(entityRealm)\n\n\t\tif (input === undefined) {\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\treturn this.qb.update(entityRealm.entity.entityName, {\n\t\t\tby: {\n\t\t\t\t[PRIMARY_KEY_NAME]: runtimeId.value,\n\t\t\t},\n\t\t\tdata: input,\n\t\t}, it => QueryGenerator.registerQueryPart(fieldMarkers, it).$(PRIMARY_KEY_NAME).$('__typename'))\n\t}\n\n\tprivate createCreateMutation(\n\t\tentityRealm: EntityRealmState,\n\t\tfieldMarkers: EntityFieldMarkers,\n\t): ContentMutation<any> | undefined {\n\t\tconst input = this.getCreateDataInput(entityRealm)\n\t\tif (input === undefined) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn this.qb.create(entityRealm.entity.entityName, {\n\t\t\tdata: input,\n\t\t}, it => QueryGenerator.registerQueryPart(fieldMarkers, it).$(PRIMARY_KEY_NAME).$('__typename'))\n\t}\n\n\tprivate getCreateDataInput(\n\t\tcurrentState: EntityRealmState | EntityRealmStateStub,\n\t): Input.CreateDataInput | undefined {\n\t\tlet processedPlaceholders = this.processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tthis.processedPlaceholdersByEntity.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 undefined\n\t\t}\n\n\t\tconst result: Input.CreateDataInput = {}\n\t\tfor (const siblingState of StateIterator.eachSiblingRealm(currentState)) {\n\t\t\tconst pathBack = this.treeStore.getPathBackToParent(siblingState)\n\n\t\t\tconst nonbearingFields: Array<\n\t\t\t\t| { 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\t\t\t> = []\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\tconst accessor = fieldState.getAccessor()\n\t\t\t\t\t\tconst value = accessor.value ?? accessor.defaultValue ?? null\n\t\t\t\t\t\tif (value !== undefined && value !== null) {\n\t\t\t\t\t\t\tresult[marker.fieldName] = value\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase '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\tconst input = this.getCreateOneRelationInput(fieldState, marker)\n\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\tif (Array.isArray(input) && Array.isArray(current)) {\n\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = input\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase '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\tconst input = this.getCreateManyRelationInput(fieldState)\n\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = input\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ((!isEmptyObject(result)) || !getEntityMarker(siblingState).fields.hasAtLeastOneBearingField) {\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\tconst accessor = field.fieldState.getAccessor()\n\t\t\t\t\t\t\tconst value = accessor.value ?? accessor.defaultValue ?? null\n\t\t\t\t\t\t\tif (value !== undefined) {\n\t\t\t\t\t\t\t\tresult[field.marker.fieldName] = value\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 'hasOne': {\n\t\t\t\t\t\t\tconst input = this.getCreateOneRelationInput(\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)\n\t\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\t\tconst current = result[field.marker.parameters.field]\n\t\t\t\t\t\t\t\tif (Array.isArray(input) && Array.isArray(current)) {\n\t\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tresult[field.marker.parameters.field] = input\n\t\t\t\t\t\t\t\t}\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\tconst input = this.getCreateManyRelationInput(\n\t\t\t\t\t\t\t\tfield.fieldState,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\t\tconst current = result[field.marker.parameters.field]\n\t\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tresult[field.marker.parameters.field] = input\n\t\t\t\t\t\t\t\t}\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 && !isEmptyObject(result)) {\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\t|| typeof field === 'number'\n\t\t\t\t\t\t|| field === null\n\t\t\t\t\t) {\n\t\t\t\t\t\tresult[key] = field\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult[key] = { connect: field }\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn isEmptyObject(result) ? undefined : result\n\t}\n\n\tprivate getCreateOneRelationInput(\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tmarker: HasOneRelationMarker,\n\t): Input.CreateOneRelationInput | Input.CreateManyRelationInput | undefined {\n\t\tconst reducedBy = marker.parameters.reducedBy\n\t\tconst runtimeId = fieldState.entity.id\n\n\t\tif (reducedBy === undefined) {\n\t\t\tif (this.shouldConnectInsteadOfCreate(fieldState)) {\n\t\t\t\treturn { connect: { [PRIMARY_KEY_NAME]: runtimeId.value } }\n\t\t\t}\n\n\t\t\tconst createData = this.getCreateDataInput(fieldState)\n\t\t\tif (createData === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn { create: createData }\n\t\t}\n\n\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\t\tif (this.shouldConnectInsteadOfCreate(fieldState)) {\n\t\t\t// TODO also potentially update\n\t\t\treturn [{ connect: { [PRIMARY_KEY_NAME]: runtimeId.value }, alias }]\n\t\t}\n\t\tconst createData = this.getCreateDataInput(fieldState)\n\t\tif (createData === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn [{ create: createData, alias }]\n\t}\n\n\tprivate getCreateManyRelationInput(fieldState: EntityListState): Input.CreateManyRelationInput | undefined {\n\t\tconst result: Input.CreateManyRelationInput = []\n\t\tfor (const entityRealm of fieldState.children.values()) {\n\t\t\tconst runtimeId = entityRealm.entity.id\n\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\t\t\tif (this.shouldConnectInsteadOfCreate(entityRealm)) {\n\t\t\t\tresult.push({\n\t\t\t\t\talias,\n\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\tconst createData = this.getCreateDataInput(entityRealm)\n\t\t\t\tif (createData === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tresult.push({\n\t\t\t\t\talias,\n\t\t\t\t\tcreate: createData,\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\treturn result.length === 0 ? undefined : result\n\t}\n\n\tprivate shouldConnectInsteadOfCreate(currentState: EntityRealmState | EntityRealmStateStub): boolean {\n\t\tconst runtimeId = currentState.entity.id\n\t\tconst processedPlaceholders = this.processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\treturn runtimeId.existsOnServer || (runtimeId instanceof ClientGeneratedUuid && (processedPlaceholders?.has(PRIMARY_KEY_NAME) ?? false))\n\t}\n\n\tprivate getUpdateDataInput(currentState: EntityRealmState): Input.UpdateDataInput | undefined {\n\t\tlet processedPlaceholders = this.processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tthis.processedPlaceholdersByEntity.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\tconst result: Input.UpdateDataInput = {}\n\n\t\tfor (const siblingState of StateIterator.eachSiblingRealm(currentState)) {\n\t\t\tfor (const [placeholderName, fieldState] of siblingState.children) {\n\t\t\t\tif (placeholderName === PRIMARY_KEY_NAME || placeholderName === TYPENAME_KEY_NAME) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\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\tif (fieldState.persistedValue !== undefined) {\n\t\t\t\t\t\t\tconst accessor = fieldState.getAccessor()\n\t\t\t\t\t\t\tconst resolvedValue = accessor.value ?? accessor.defaultValue ?? null\n\t\t\t\t\t\t\tif (fieldState.persistedValue !== resolvedValue) {\n\t\t\t\t\t\t\t\tresult[placeholderName] = resolvedValue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase '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\tconst reducedBy = marker.parameters.reducedBy\n\n\t\t\t\t\t\tconst persistedValue = entityData?.get?.(placeholderName)?.value\n\t\t\t\t\t\tif (reducedBy === undefined) {\n\t\t\t\t\t\t\tconst relationData = this.getUpdateOneRelationInput(currentState, fieldState, persistedValue, placeholderName)\n\t\t\t\t\t\t\tif (relationData !== undefined) {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = relationData\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst relationData = this.getUpdateManyRelationForReducedInput(currentState, fieldState, persistedValue, placeholderName, reducedBy)\n\t\t\t\t\t\t\tif (relationData !== undefined) {\n\t\t\t\t\t\t\t\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\t\tcurrent.push(...relationData)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tresult[marker.parameters.field] = relationData\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\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\tconst persistedEntityIds = entityData?.get?.(placeholderName)?.value ?? new Set()\n\n\t\t\t\t\t\tif (!(persistedEntityIds instanceof Set)) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst relationData = this.getUpdateManyRelationInput(fieldState, persistedEntityIds)\n\t\t\t\t\t\tif (relationData !== undefined) {\n\t\t\t\t\t\t\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\tcurrent.push(...relationData)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = relationData\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn isEmptyObject(result) ? undefined : result\n\t}\n\n\tprivate getUpdateOneRelationInput(\n\t\tcurrentState: EntityRealmState,\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tpersistedValue: EntityFieldPersistedValue | undefined,\n\t\tplaceholderName: PlaceholderName,\n\t): Input.UpdateOneRelationInput | undefined {\n\t\tconst runtimeId = fieldState.entity.id\n\t\tif (persistedValue instanceof ServerId) {\n\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\t// The persisted and currently referenced ids match, and so this is an update.\n\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\treturn undefined // …unless we're dealing with a stub. There cannot be any updates there.\n\t\t\t\t}\n\t\t\t\tconst input = this.getUpdateDataInput(fieldState)\n\t\t\t\tif (input === undefined) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tupdate: input,\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// There was a referenced entity but currently, there is a different one. Let's investigate:\n\n\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\tconst key = `${persistedValue.entityName}#${persistedValue.value}`\n\t\t\t\tif (this.processedDeletes.has(key)) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tthis.processedDeletes.add(key)\n\n\t\t\t\t// It's planned for deletion.\n\t\t\t\t// TODO also potentially do something about the current entity\n\t\t\t\treturn {\n\t\t\t\t\tdelete: true,\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (runtimeId.existsOnServer) {\n\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// TODO also potentially update\n\t\t\t\treturn {\n\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t}\n\t\t\t}\n\t\t\t// The currently present entity doesn't exist on the server. Try if creating yields anything…\n\t\t\tconst createInput = this.getCreateDataInput(fieldState)\n\t\t\tif (createInput !== undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tcreate: createInput,\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// …but if it doesn't, we just disconnect.\n\t\t\t\treturn {\n\t\t\t\t\tdisconnect: true,\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (runtimeId.existsOnServer) {\n\t\t\t// There isn't a linked entity on the server but we're seeing one that exists there.\n\t\t\t// Thus this is a connect.\n\t\t\t// TODO also potentially update\n\t\t\treturn {\n\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t}\n\t\t} else {\n\t\t\tconst input = this.getCreateDataInput(fieldState)\n\t\t\tif (input === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcreate: input,\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getUpdateManyRelationForReducedInput(\n\t\tcurrentState: EntityRealmState,\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tpersistedValue: EntityFieldPersistedValue | undefined,\n\t\tplaceholderName: PlaceholderName,\n\t\treducedBy: UniqueWhere,\n\t): Input.UpdateManyRelationInput | undefined {\n\t\tconst runtimeId = fieldState.entity.id\n\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\tif (persistedValue instanceof ServerId) {\n\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tconst updateData = this.getUpdateDataInput(fieldState)\n\t\t\t\tif (updateData === undefined) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\treturn [{\n\t\t\t\t\talias,\n\t\t\t\t\tupdate: {\n\t\t\t\t\t\tby: reducedBy,\n\t\t\t\t\t\tdata: updateData,\n\t\t\t\t\t},\n\t\t\t\t}]\n\t\t\t}\n\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\tconst key = `${persistedValue.entityName}#${persistedValue.value}`\n\t\t\t\tif (this.processedDeletes.has(key)) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tthis.processedDeletes.add(key)\n\t\t\t\treturn [{\n\t\t\t\t\talias,\n\t\t\t\t\tdelete: reducedBy,\n\t\t\t\t}]\n\t\t\t}\n\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t// TODO will re-using the alias like this work?\n\t\t\t\t// TODO also potentially update\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tdisconnect: reducedBy,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t}\n\t\t\tconst createInput = this.getCreateDataInput(fieldState)\n\n\t\t\tif (createInput === undefined) {\n\t\t\t\treturn [{\n\t\t\t\t\talias,\n\t\t\t\t\tdisconnect: reducedBy,\n\t\t\t\t}]\n\t\t\t}\n\t\t\treturn [{\n\t\t\t\talias,\n\t\t\t\tcreate: createInput,\n\t\t\t}]\n\t\t} else if (runtimeId.existsOnServer) {\n\t\t\treturn [{\n\t\t\t\talias,\n\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t}]\n\t\t} else {\n\t\t\tconst createInput = this.getCreateDataInput(fieldState)\n\t\t\tif (createInput === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn [{\n\t\t\t\talias,\n\t\t\t\tcreate: createInput,\n\t\t\t}]\n\t\t}\n\t}\n\n\tprivate getUpdateManyRelationInput(\n\t\tfieldState: EntityListState,\n\t\tpersistedEntityIds: Set<EntityId>,\n\t): Input.UpdateManyRelationInput | undefined {\n\t\tconst input: Input.UpdateManyRelationInput = []\n\t\tfor (const childState of fieldState.children.values()) {\n\t\t\tconst runtimeId = childState.entity.id\n\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\tif (persistedEntityIds.has(runtimeId.value)) {\n\t\t\t\t\tif (childState.type !== 'entityRealmStub') {\n\t\t\t\t\t\tconst dataInput = this.getUpdateDataInput(childState)\n\n\t\t\t\t\t\tif (dataInput !== undefined) {\n\t\t\t\t\t\t\tinput.push({\n\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\tupdate: {\n\t\t\t\t\t\t\t\t\tby: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t\t\t\t\tdata: dataInput,\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}\n\t\t\t\t} else {\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst dataInput = this.getCreateDataInput(childState)\n\t\t\t\tif (dataInput !== undefined) {\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tcreate: dataInput,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (fieldState.plannedRemovals) {\n\t\t\tfor (const [removedId, removalType] of fieldState.plannedRemovals) {\n\t\t\t\tconst alias = MutationAlias.encodeEntityId(new ServerId(removedId, fieldState.entityName))\n\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\tconst key = `${fieldState.entityName}#${removedId}`\n\t\t\t\t\tif (this.processedDeletes.has(key)) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tthis.processedDeletes.add(key)\n\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tdelete: { [PRIMARY_KEY_NAME]: removedId },\n\t\t\t\t\t})\n\t\t\t\t} else if (removalType === 'disconnect') {\n\t\t\t\t\t// TODO also potentially update\n\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tdisconnect: { [PRIMARY_KEY_NAME]: removedId },\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(removalType)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn input.length === 0 ? undefined : input\n\t}\n\n\tprivate createAlias(): string {\n\t\treturn `op_${this.alias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A;AAAA,YACF;AAAA,UACD;AAAA,QACD,OAAO;AACN,gBAAM,KAAK;AAAA,YACV;AAAA,YACA,SAAS,EAAE,CAAC,gBAAgB,GAAG,UAAU,MAAA;AAAA,UAAM,CAC/C;AAAA,QACF;AAAA,MACD,OAAO;AACN,cAAM,YAAY,KAAK,mBAAmB,UAAU;AACpD,YAAI,cAAc,QAAW;AAC5B,gBAAM,KAAK;AAAA,YACV;AAAA,YACA,QAAQ;AAAA,UAAA,CACR;AAAA,QACF;AAAA,MACD;AAAA,IACD;AACA,QAAI,WAAW,iBAAiB;AAC/B,iBAAW,CAAC,WAAW,WAAW,KAAK,WAAW,iBAAiB;AAClE,cAAM,QAAQ,cAAc,eAAe,IAAI,SAAS,WAAW,WAAW,UAAU,CAAC;AACzF,YAAI,gBAAgB,UAAU;AAC7B,gBAAM,MAAM,GAAG,WAAW,UAAU,IAAI,SAAS;AACjD,cAAI,KAAK,iBAAiB,IAAI,GAAG,GAAG;AACnC;AAAA,UACD;AACA,eAAK,iBAAiB,IAAI,GAAG;AAE7B,gBAAM,KAAK;AAAA,YACV;AAAA,YACA,QAAQ,EAAE,CAAC,gBAAgB,GAAG,UAAA;AAAA,UAAU,CACxC;AAAA,QACF,WAAW,gBAAgB,cAAc;AAGxC,gBAAM,KAAK;AAAA,YACV;AAAA,YACA,YAAY,EAAE,CAAC,gBAAgB,GAAG,UAAA;AAAA,UAAU,CAC5C;AAAA,QACF,OAAO;AACN,sBAAY,WAAW;AAAA,QACxB;AAAA,MACD;AAAA,IACD;AAEA,WAAO,MAAM,WAAW,IAAI,SAAY;AAAA,EACzC;AAAA,EAEQ,cAAsB;AAC7B,WAAO,MAAM,KAAK,cAAc;AAAA,EACjC;AACD;"}
|
|
1
|
+
{"version":3,"file":"MutationGenerator.js","sources":["../../../../../packages/binding-legacy/src/core/MutationGenerator.ts"],"sourcesContent":["import { ContentMutation, ContentQueryBuilder, Input } from '@contember/client'\nimport { ClientGeneratedUuid, ReceivedEntityData, ServerId } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '@contember/binding-common'\nimport { EntityFieldMarkers, FieldMarker, HasManyRelationMarker, HasOneRelationMarker } from '@contember/binding-common'\nimport type { EntityId, EntityName, PlaceholderName, UniqueWhere } from '@contember/binding-common'\nimport { isEmptyObject } from '../utils/index.js'\nimport { assertNever } from '@contember/binding-common'\nimport { QueryGenerator } from './QueryGenerator.js'\nimport { MutationAlias } from './requestAliases/index.js'\nimport { EntityListState, EntityRealmState, EntityRealmStateStub, EntityState, FieldState, getEntityMarker, StateIterator } from './state/index.js'\nimport type { TreeStore } from './TreeStore.js'\nimport { EntityFieldPersistedData, EntityFieldPersistedValue } from '../accessorTree/index.js'\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\tmutations: Record<string, ContentMutation<ReceivedEntityData>>\n\toperations: SubMutationOperation[]\n}\n\n// TODO enforce correct expected mutations in dev mode.\nexport class MutationGenerator {\n\tprivate aliasCounter = 1\n\tprivate processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity = new Map()\n\tprivate processedDeletes = new Set<string>()\n\n\tprivate constructor(\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly qb: ContentQueryBuilder,\n\t) {\n\t}\n\n\tpublic static getPersistMutation(treeStore: TreeStore, qb: ContentQueryBuilder): PersistMutationResult {\n\t\treturn new MutationGenerator(treeStore, qb).getPersistMutation()\n\t}\n\n\tprivate getPersistMutation(): PersistMutationResult {\n\t\tconst mutations: Record<string, ContentMutation<any>> = {}\n\t\tconst operations: SubMutationOperation[] = []\n\n\t\tfor (const [treeRootId, rootStates] of this.treeStore.subTreeStatesByRoot.entries()) {\n\t\t\tfor (const [placeholderName, subTreeState] of Array.from(rootStates.entries()).reverse()) {\n\t\t\t\tif (subTreeState.unpersistedChangesCount <= 0) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (subTreeState.type === 'entityRealm') {\n\t\t\t\t\tif (\n\t\t\t\t\t\tsubTreeState.blueprint.type === 'subTree' && subTreeState.blueprint.marker.parameters.isCreating\n\t\t\t\t\t\t&& subTreeState.blueprint.marker.parameters.isUnpersisted\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst subMutation = this.createMutation(\n\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t'single',\n\t\t\t\t\t\tsubTreeState.entity.id.value,\n\t\t\t\t\t\tsubTreeState,\n\t\t\t\t\t)\n\t\t\t\t\tif (subMutation) {\n\t\t\t\t\t\tmutations[subMutation[1].alias] = subMutation[0]\n\t\t\t\t\t\toperations.push(subMutation[1])\n\t\t\t\t\t}\n\t\t\t\t} else if (subTreeState.type === 'entityList') {\n\t\t\t\t\tif (\n\t\t\t\t\t\tsubTreeState.blueprint.type === 'subTree' && subTreeState.blueprint.marker.parameters.isCreating\n\t\t\t\t\t\t&& subTreeState.blueprint.marker.parameters.isUnpersisted\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const childState of subTreeState.children.values()) {\n\t\t\t\t\t\tif (childState.type === 'entityRealmStub') {\n\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\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst subMutation = this.createMutation(\n\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t'list',\n\t\t\t\t\t\t\tchildState.entity.id.value,\n\t\t\t\t\t\t\tchildState,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tif (subMutation) {\n\t\t\t\t\t\t\tmutations[subMutation[1].alias] = 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}\n\t\t\t\t\tif (subTreeState.plannedRemovals) {\n\t\t\t\t\t\tfor (const [removedId, removalType] of subTreeState.plannedRemovals) {\n\t\t\t\t\t\t\tif (removalType === 'disconnect') {\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\t\t\t\tconst key = `${subTreeState.entityName}#${removedId}`\n\t\t\t\t\t\t\t\tif (this.processedDeletes.has(key)) {\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\tthis.processedDeletes.add(key)\n\t\t\t\t\t\t\t\tconst alias = this.createAlias()\n\t\t\t\t\t\t\t\tmutations[alias] = this.createDeleteMutation(\n\t\t\t\t\t\t\t\t\tsubTreeState.entityName,\n\t\t\t\t\t\t\t\t\tremovedId,\n\t\t\t\t\t\t\t\t)\n\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} else {\n\t\t\t\t\t\t\t\tassertNever(removalType)\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} else {\n\t\t\t\t\tassertNever(subTreeState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { mutations, operations }\n\t}\n\n\tprivate createMutation(\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: 'list' | 'single',\n\t\tentityId: EntityId,\n\t\trealmState: EntityRealmState,\n\t): [ContentMutation<any>, 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 mutation = this.createDeleteMutation(\n\t\t\t\trealmState.entity.entityName,\n\t\t\t\tentityId,\n\t\t\t)\n\t\t\treturn [\n\t\t\t\tmutation,\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.createCreateMutation(\n\t\t\t\trealmState,\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\t\t\t]\n\t\t}\n\t\tconst builder = this.createUpdateMutation(\n\t\t\trealmState,\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 createDeleteMutation(\n\t\tentityName: EntityName,\n\t\tdeletedId: EntityId,\n\t): ContentMutation<any> {\n\t\treturn this.qb.delete(entityName, {\n\t\t\tby: { [PRIMARY_KEY_NAME]: deletedId },\n\t\t}, it => it.$(PRIMARY_KEY_NAME).$('__typename'))\n\t}\n\n\tprivate createUpdateMutation(\n\t\tentityRealm: EntityRealmState,\n\t\tfieldMarkers: EntityFieldMarkers,\n\t): ContentMutation<any> | undefined {\n\t\tconst input = this.getUpdateDataInput(entityRealm)\n\n\t\tif (input === undefined) {\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\treturn this.qb.update(entityRealm.entity.entityName, {\n\t\t\tby: {\n\t\t\t\t[PRIMARY_KEY_NAME]: runtimeId.value,\n\t\t\t},\n\t\t\tdata: input,\n\t\t}, it => QueryGenerator.registerQueryPart(fieldMarkers, it).$(PRIMARY_KEY_NAME).$('__typename'))\n\t}\n\n\tprivate createCreateMutation(\n\t\tentityRealm: EntityRealmState,\n\t\tfieldMarkers: EntityFieldMarkers,\n\t): ContentMutation<any> | undefined {\n\t\tconst input = this.getCreateDataInput(entityRealm)\n\t\tif (input === undefined) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn this.qb.create(entityRealm.entity.entityName, {\n\t\t\tdata: input,\n\t\t}, it => QueryGenerator.registerQueryPart(fieldMarkers, it).$(PRIMARY_KEY_NAME).$('__typename'))\n\t}\n\n\tprivate getCreateDataInput(\n\t\tcurrentState: EntityRealmState | EntityRealmStateStub,\n\t): Input.CreateDataInput | undefined {\n\t\tlet processedPlaceholders = this.processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tthis.processedPlaceholdersByEntity.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 undefined\n\t\t}\n\n\t\tconst result: Input.CreateDataInput = {}\n\t\tfor (const siblingState of StateIterator.eachSiblingRealm(currentState)) {\n\t\t\tconst pathBack = this.treeStore.getPathBackToParent(siblingState)\n\n\t\t\tconst nonbearingFields: Array<\n\t\t\t\t| { 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\t\t\t> = []\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\tconst accessor = fieldState.getAccessor()\n\t\t\t\t\t\tconst value = accessor.value ?? accessor.defaultValue ?? null\n\t\t\t\t\t\tif (value !== undefined && value !== null) {\n\t\t\t\t\t\t\tresult[marker.fieldName] = value\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase '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\tconst input = this.getCreateOneRelationInput(fieldState, marker)\n\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\tif (Array.isArray(input) && Array.isArray(current)) {\n\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = input\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase '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\tconst input = this.getCreateManyRelationInput(fieldState)\n\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = input\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ((!isEmptyObject(result)) || !getEntityMarker(siblingState).fields.hasAtLeastOneBearingField) {\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\tconst accessor = field.fieldState.getAccessor()\n\t\t\t\t\t\t\tconst value = accessor.value ?? accessor.defaultValue ?? null\n\t\t\t\t\t\t\tif (value !== undefined) {\n\t\t\t\t\t\t\t\tresult[field.marker.fieldName] = value\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 'hasOne': {\n\t\t\t\t\t\t\tconst input = this.getCreateOneRelationInput(\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)\n\t\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\t\tconst current = result[field.marker.parameters.field]\n\t\t\t\t\t\t\t\tif (Array.isArray(input) && Array.isArray(current)) {\n\t\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tresult[field.marker.parameters.field] = input\n\t\t\t\t\t\t\t\t}\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\tconst input = this.getCreateManyRelationInput(\n\t\t\t\t\t\t\t\tfield.fieldState,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\t\tconst current = result[field.marker.parameters.field]\n\t\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tresult[field.marker.parameters.field] = input\n\t\t\t\t\t\t\t\t}\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 && !isEmptyObject(result)) {\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\t|| typeof field === 'number'\n\t\t\t\t\t\t|| field === null\n\t\t\t\t\t) {\n\t\t\t\t\t\tresult[key] = field\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult[key] = { connect: field }\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn isEmptyObject(result) ? undefined : result\n\t}\n\n\tprivate getCreateOneRelationInput(\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tmarker: HasOneRelationMarker,\n\t): Input.CreateOneRelationInput | Input.CreateManyRelationInput | undefined {\n\t\tconst reducedBy = marker.parameters.reducedBy\n\t\tconst runtimeId = fieldState.entity.id\n\n\t\tif (reducedBy === undefined) {\n\t\t\tif (this.shouldConnectInsteadOfCreate(fieldState)) {\n\t\t\t\treturn { connect: { [PRIMARY_KEY_NAME]: runtimeId.value } }\n\t\t\t}\n\n\t\t\tconst createData = this.getCreateDataInput(fieldState)\n\t\t\tif (createData === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn { create: createData }\n\t\t}\n\n\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\t\tif (this.shouldConnectInsteadOfCreate(fieldState)) {\n\t\t\t// TODO also potentially update\n\t\t\treturn [{ connect: { [PRIMARY_KEY_NAME]: runtimeId.value }, alias }]\n\t\t}\n\t\tconst createData = this.getCreateDataInput(fieldState)\n\t\tif (createData === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn [{ create: createData, alias }]\n\t}\n\n\tprivate getCreateManyRelationInput(fieldState: EntityListState): Input.CreateManyRelationInput | undefined {\n\t\tconst result: Input.CreateManyRelationInput = []\n\t\tfor (const entityRealm of fieldState.children.values()) {\n\t\t\tconst runtimeId = entityRealm.entity.id\n\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\t\t\tif (this.shouldConnectInsteadOfCreate(entityRealm)) {\n\t\t\t\tresult.push({\n\t\t\t\t\talias,\n\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\tconst createData = this.getCreateDataInput(entityRealm)\n\t\t\t\tif (createData === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tresult.push({\n\t\t\t\t\talias,\n\t\t\t\t\tcreate: createData,\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\treturn result.length === 0 ? undefined : result\n\t}\n\n\tprivate shouldConnectInsteadOfCreate(currentState: EntityRealmState | EntityRealmStateStub): boolean {\n\t\tconst runtimeId = currentState.entity.id\n\t\tconst processedPlaceholders = this.processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\treturn runtimeId.existsOnServer || (runtimeId instanceof ClientGeneratedUuid && (processedPlaceholders?.has(PRIMARY_KEY_NAME) ?? false))\n\t}\n\n\tprivate getUpdateDataInput(currentState: EntityRealmState): Input.UpdateDataInput | undefined {\n\t\tlet processedPlaceholders = this.processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tthis.processedPlaceholdersByEntity.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\tconst result: Input.UpdateDataInput = {}\n\n\t\tfor (const siblingState of StateIterator.eachSiblingRealm(currentState)) {\n\t\t\tfor (const [placeholderName, fieldState] of siblingState.children) {\n\t\t\t\tif (placeholderName === PRIMARY_KEY_NAME || placeholderName === TYPENAME_KEY_NAME) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\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\tif (fieldState.persistedValue !== undefined) {\n\t\t\t\t\t\t\tconst accessor = fieldState.getAccessor()\n\t\t\t\t\t\t\tconst resolvedValue = accessor.value ?? accessor.defaultValue ?? null\n\t\t\t\t\t\t\tif (fieldState.persistedValue !== resolvedValue) {\n\t\t\t\t\t\t\t\tresult[placeholderName] = resolvedValue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase '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\tconst reducedBy = marker.parameters.reducedBy\n\n\t\t\t\t\t\tconst persistedValue = entityData?.get?.(placeholderName)?.value\n\t\t\t\t\t\tif (reducedBy === undefined) {\n\t\t\t\t\t\t\tconst relationData = this.getUpdateOneRelationInput(currentState, fieldState, persistedValue, placeholderName)\n\t\t\t\t\t\t\tif (relationData !== undefined) {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = relationData\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst relationData = this.getUpdateManyRelationForReducedInput(currentState, fieldState, persistedValue, placeholderName, reducedBy)\n\t\t\t\t\t\t\tif (relationData !== undefined) {\n\t\t\t\t\t\t\t\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\t\tcurrent.push(...relationData)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tresult[marker.parameters.field] = relationData\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\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\tconst persistedEntityIds = entityData?.get?.(placeholderName)?.value ?? new Set()\n\n\t\t\t\t\t\tif (!(persistedEntityIds instanceof Set)) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst relationData = this.getUpdateManyRelationInput(fieldState, persistedEntityIds)\n\t\t\t\t\t\tif (relationData !== undefined) {\n\t\t\t\t\t\t\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\tcurrent.push(...relationData)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = relationData\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn isEmptyObject(result) ? undefined : result\n\t}\n\n\tprivate getUpdateOneRelationInput(\n\t\tcurrentState: EntityRealmState,\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tpersistedValue: EntityFieldPersistedValue | undefined,\n\t\tplaceholderName: PlaceholderName,\n\t): Input.UpdateOneRelationInput | undefined {\n\t\tconst runtimeId = fieldState.entity.id\n\t\tif (persistedValue instanceof ServerId) {\n\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\t// The persisted and currently referenced ids match, and so this is an update.\n\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\treturn undefined // …unless we're dealing with a stub. There cannot be any updates there.\n\t\t\t\t}\n\t\t\t\tconst input = this.getUpdateDataInput(fieldState)\n\t\t\t\tif (input === undefined) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tupdate: input,\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// There was a referenced entity but currently, there is a different one. Let's investigate:\n\n\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\tconst key = `${persistedValue.entityName}#${persistedValue.value}`\n\t\t\t\tif (this.processedDeletes.has(key)) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tthis.processedDeletes.add(key)\n\n\t\t\t\t// It's planned for deletion.\n\t\t\t\t// TODO also potentially do something about the current entity\n\t\t\t\treturn {\n\t\t\t\t\tdelete: true,\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (runtimeId.existsOnServer) {\n\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// TODO also potentially update\n\t\t\t\treturn {\n\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t}\n\t\t\t}\n\t\t\t// The currently present entity doesn't exist on the server. Try if creating yields anything…\n\t\t\tconst createInput = this.getCreateDataInput(fieldState)\n\t\t\tif (createInput !== undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tcreate: createInput,\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// …but if it doesn't, we just disconnect.\n\t\t\t\treturn {\n\t\t\t\t\tdisconnect: true,\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (runtimeId.existsOnServer) {\n\t\t\t// There isn't a linked entity on the server but we're seeing one that exists there.\n\t\t\t// Thus this is a connect.\n\t\t\t// TODO also potentially update\n\t\t\treturn {\n\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t}\n\t\t} else {\n\t\t\tconst input = this.getCreateDataInput(fieldState)\n\t\t\tif (input === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcreate: input,\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getUpdateManyRelationForReducedInput(\n\t\tcurrentState: EntityRealmState,\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tpersistedValue: EntityFieldPersistedValue | undefined,\n\t\tplaceholderName: PlaceholderName,\n\t\treducedBy: UniqueWhere,\n\t): Input.UpdateManyRelationInput | undefined {\n\t\tconst runtimeId = fieldState.entity.id\n\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\tif (persistedValue instanceof ServerId) {\n\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tconst updateData = this.getUpdateDataInput(fieldState)\n\t\t\t\tif (updateData === undefined) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\treturn [{\n\t\t\t\t\talias,\n\t\t\t\t\tupdate: {\n\t\t\t\t\t\tby: reducedBy,\n\t\t\t\t\t\tdata: updateData,\n\t\t\t\t\t},\n\t\t\t\t}]\n\t\t\t}\n\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\tconst key = `${persistedValue.entityName}#${persistedValue.value}`\n\t\t\t\tif (this.processedDeletes.has(key)) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tthis.processedDeletes.add(key)\n\t\t\t\treturn [{\n\t\t\t\t\talias,\n\t\t\t\t\tdelete: reducedBy,\n\t\t\t\t}]\n\t\t\t}\n\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t// TODO will re-using the alias like this work?\n\t\t\t\t// TODO also potentially update\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tdisconnect: reducedBy,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t}\n\t\t\tconst createInput = this.getCreateDataInput(fieldState)\n\n\t\t\tif (createInput === undefined) {\n\t\t\t\treturn [{\n\t\t\t\t\talias,\n\t\t\t\t\tdisconnect: reducedBy,\n\t\t\t\t}]\n\t\t\t}\n\t\t\treturn [{\n\t\t\t\talias,\n\t\t\t\tcreate: createInput,\n\t\t\t}]\n\t\t} else if (runtimeId.existsOnServer) {\n\t\t\treturn [{\n\t\t\t\talias,\n\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t}]\n\t\t} else {\n\t\t\tconst createInput = this.getCreateDataInput(fieldState)\n\t\t\tif (createInput === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn [{\n\t\t\t\talias,\n\t\t\t\tcreate: createInput,\n\t\t\t}]\n\t\t}\n\t}\n\n\tprivate getUpdateManyRelationInput(\n\t\tfieldState: EntityListState,\n\t\tpersistedEntityIds: Set<EntityId>,\n\t): Input.UpdateManyRelationInput | undefined {\n\t\tconst input: Input.UpdateManyRelationInput = []\n\t\tfor (const childState of fieldState.children.values()) {\n\t\t\tconst runtimeId = childState.entity.id\n\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\tif (persistedEntityIds.has(runtimeId.value)) {\n\t\t\t\t\tif (childState.type !== 'entityRealmStub') {\n\t\t\t\t\t\tconst dataInput = this.getUpdateDataInput(childState)\n\n\t\t\t\t\t\tif (dataInput !== undefined) {\n\t\t\t\t\t\t\tinput.push({\n\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\tupdate: {\n\t\t\t\t\t\t\t\t\tby: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t\t\t\t\tdata: dataInput,\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}\n\t\t\t\t} else {\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst dataInput = this.getCreateDataInput(childState)\n\t\t\t\tif (dataInput !== undefined) {\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tcreate: dataInput,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (fieldState.plannedRemovals) {\n\t\t\tfor (const [removedId, removalType] of fieldState.plannedRemovals) {\n\t\t\t\tconst alias = MutationAlias.encodeEntityId(new ServerId(removedId, fieldState.entityName))\n\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\tconst key = `${fieldState.entityName}#${removedId}`\n\t\t\t\t\tif (this.processedDeletes.has(key)) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tthis.processedDeletes.add(key)\n\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tdelete: { [PRIMARY_KEY_NAME]: removedId },\n\t\t\t\t\t})\n\t\t\t\t} else if (removalType === 'disconnect') {\n\t\t\t\t\t// TODO also potentially update\n\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tdisconnect: { [PRIMARY_KEY_NAME]: removedId },\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(removalType)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn input.length === 0 ? undefined : input\n\t}\n\n\tprivate createAlias(): string {\n\t\treturn `op_${this.aliasCounter++}`\n\t}\n}\n"],"names":["builder","placeholderName","createData"],"mappings":";;;;;;;;;AAkCO,MAAM,kBAAkB;AAAA,EAKtB,YACU,WACA,IAChB;AAFgB,SAAA,YAAA;AACA,SAAA,KAAA;AANlB,kBAAA,MAAQ,gBAAe,CAAA;AACvB,kBAAA,MAAQ,qDAAmE,IAAA,CAAI;AAC/E,kBAAA,MAAQ,wCAAuB,IAAA,CAAY;AAAA,EAM3C;AAAA,EAEA,OAAc,mBAAmB,WAAsB,IAAgD;AACtG,WAAO,IAAI,kBAAkB,WAAW,EAAE,EAAE,mBAAA;AAAA,EAC7C;AAAA,EAEQ,qBAA4C;AACnD,UAAM,YAAkD,CAAA;AACxD,UAAM,aAAqC,CAAA;AAE3C,eAAW,CAAC,YAAY,UAAU,KAAK,KAAK,UAAU,oBAAoB,WAAW;AACpF,iBAAW,CAAC,iBAAiB,YAAY,KAAK,MAAM,KAAK,WAAW,QAAA,CAAS,EAAE,WAAW;AACzF,YAAI,aAAa,2BAA2B,GAAG;AAC9C;AAAA,QACD;AACA,YAAI,aAAa,SAAS,eAAe;AACxC,cAC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A,QAAQ,EAAE,CAAC,gBAAgB,GAAG,UAAA;AAAA,UAAU,CACxC;AAAA,QACF,WAAW,gBAAgB,cAAc;AAGxC,gBAAM,KAAK;AAAA,YACV;AAAA,YACA,YAAY,EAAE,CAAC,gBAAgB,GAAG,UAAA;AAAA,UAAU,CAC5C;AAAA,QACF,OAAO;AACN,sBAAY,WAAW;AAAA,QACxB;AAAA,MACD;AAAA,IACD;AAEA,WAAO,MAAM,WAAW,IAAI,SAAY;AAAA,EACzC;AAAA,EAEQ,cAAsB;AAC7B,WAAO,MAAM,KAAK,cAAc;AAAA,EACjC;AACD;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RealmKeyGenerator.cjs","sources":["../../../../../packages/binding-legacy/src/core/RealmKeyGenerator.ts"],"sourcesContent":["import { ClientGeneratedUuid, EntityFieldMarkersContainer, EntityId, EntityRealmKey, PlaceholderName, RuntimeId } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport type { EntityListState, EntityRealmBlueprint, EntityRealmState } from './state'\nimport { WeakIdCache } from '@contember/utilities'\n\nconst GLUE = '--'\nconst keyEndRegex = new RegExp(`${GLUE}\\\\d+$`)\n\nexport class RealmKeyGenerator {\n\t// We're using this id, and not, well, the entity id, because it *SIGNIFICANTLY* reduces the complexity of\n\t// entity id changes.\n\tprivate static parentStateIdCache = new WeakIdCache<EntityRealmState | EntityListState>()\n\tprivate static markerIdCache = new WeakIdCache<EntityFieldMarkersContainer>()\n\n\tpublic static vaguelyAppearsToBeAKey(candidate: string): boolean {\n\t\t// This is just for error messages. No need to be super precise.\n\t\treturn candidate.startsWith(`key${GLUE}`) && keyEndRegex.test(candidate)\n\t}\n\n\tprivate static generateKey(\n\t\tparent: EntityRealmState | EntityListState | undefined,\n\t\tplaceholderName: PlaceholderName,\n\t\tid: string,\n\t\tcontainer: EntityFieldMarkersContainer,\n\t): EntityRealmKey {\n\t\t// The static prefix serves to really emphasize that this is *NOT* just a uuid\n\t\treturn `key${GLUE}${\n\t\t\tthis.parentStateIdCache.getOptionalKeyId(\n\t\t\t\tparent,\n\t\t\t)\n\t\t}${GLUE}${placeholderName}${id}${GLUE}${this.markerIdCache.getId(container)}`\n\t}\n\n\tpublic static getRealmKey(id: RuntimeId, blueprint: EntityRealmBlueprint): EntityRealmKey {\n\t\tconst parent = blueprint.parent\n\t\tlet placeholderName: PlaceholderName\n\n\t\tif (blueprint.type === 'subTree') {\n\t\t\tplaceholderName = blueprint.marker.placeholderName\n\t\t} else if (blueprint.type === 'listEntity') {\n\t\t\tplaceholderName = blueprint.parent.blueprint.marker.placeholderName\n\t\t} else if (blueprint.type === 'hasOne') {\n\t\t\tplaceholderName = blueprint.marker.placeholderName\n\t\t} else {\n\t\t\treturn assertNever(blueprint)\n\t\t}\n\t\treturn this.generateKey(\n\t\t\tparent,\n\t\t\tplaceholderName,\n\t\t\t(id instanceof ClientGeneratedUuid ? 'C-' : '') + id.value.toString(),\n\t\t\tblueprint.type === 'listEntity' ? blueprint.parent.blueprint.marker.fields : blueprint.marker.fields,\n\t\t)\n\t}\n}\n"],"names":["assertNever","ClientGeneratedUuid","WeakIdCache"],"mappings":";;;;;;;AAKA,MAAM,OAAO;AACb,MAAM,cAAc,IAAI,OAAO,GAAG,IAAI,OAAO;AAEtC,MAAM,kBAAkB;AAAA,EAM9B,OAAc,uBAAuB,WAA4B;AAEhE,WAAO,UAAU,WAAW,MAAM,IAAI,EAAE,KAAK,YAAY,KAAK,SAAS;AAAA,EACxE;AAAA,EAEA,OAAe,YACd,QACA,iBACA,IACA,WACiB;AAEjB,WAAO,MAAM,IAAI,GAChB,KAAK,mBAAmB;AAAA,MACvB;AAAA,IAAA,CAEF,GAAG,IAAI,GAAG,eAAe,GAAG,EAAE,GAAG,IAAI,GAAG,KAAK,cAAc,MAAM,SAAS,CAAC;AAAA,EAC5E;AAAA,EAEA,OAAc,YAAY,IAAe,WAAiD;AACzF,UAAM,SAAS,UAAU;AACzB,QAAI;AAEJ,QAAI,UAAU,SAAS,WAAW;AACjC,wBAAkB,UAAU,OAAO;AAAA,IACpC,WAAW,UAAU,SAAS,cAAc;AAC3C,wBAAkB,UAAU,OAAO,UAAU,OAAO;AAAA,IACrD,WAAW,UAAU,SAAS,UAAU;AACvC,wBAAkB,UAAU,OAAO;AAAA,IACpC,OAAO;AACN,aAAOA,cAAAA,YAAY,SAAS;AAAA,IAC7B;AACA,WAAO,KAAK;AAAA,MACX;AAAA,MACA;AAAA,OACC,cAAcC,cAAAA,sBAAsB,OAAO,MAAM,GAAG,MAAM,SAAA;AAAA,MAC3D,UAAU,SAAS,eAAe,UAAU,OAAO,UAAU,OAAO,SAAS,UAAU,OAAO;AAAA,IAAA;AAAA,EAEhG;AACD;AA1CC,cAHY,mBAGG,sBAAqB,IAAIC,UAAAA,aAAgD;AACxF,cAJY,mBAIG,iBAAgB,IAAIA,UAAAA,aAAyC;;"}
|
|
1
|
+
{"version":3,"file":"RealmKeyGenerator.cjs","sources":["../../../../../packages/binding-legacy/src/core/RealmKeyGenerator.ts"],"sourcesContent":["import { ClientGeneratedUuid, EntityFieldMarkersContainer, EntityId, EntityRealmKey, PlaceholderName, RuntimeId } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport type { EntityListState, EntityRealmBlueprint, EntityRealmState } from './state/index.js'\nimport { WeakIdCache } from '@contember/utilities'\n\nconst GLUE = '--'\nconst keyEndRegex = new RegExp(`${GLUE}\\\\d+$`)\n\nexport class RealmKeyGenerator {\n\t// We're using this id, and not, well, the entity id, because it *SIGNIFICANTLY* reduces the complexity of\n\t// entity id changes.\n\tprivate static parentStateIdCache = new WeakIdCache<EntityRealmState | EntityListState>()\n\tprivate static markerIdCache = new WeakIdCache<EntityFieldMarkersContainer>()\n\n\tpublic static vaguelyAppearsToBeAKey(candidate: string): boolean {\n\t\t// This is just for error messages. No need to be super precise.\n\t\treturn candidate.startsWith(`key${GLUE}`) && keyEndRegex.test(candidate)\n\t}\n\n\tprivate static generateKey(\n\t\tparent: EntityRealmState | EntityListState | undefined,\n\t\tplaceholderName: PlaceholderName,\n\t\tid: string,\n\t\tcontainer: EntityFieldMarkersContainer,\n\t): EntityRealmKey {\n\t\t// The static prefix serves to really emphasize that this is *NOT* just a uuid\n\t\treturn `key${GLUE}${\n\t\t\tthis.parentStateIdCache.getOptionalKeyId(\n\t\t\t\tparent,\n\t\t\t)\n\t\t}${GLUE}${placeholderName}${id}${GLUE}${this.markerIdCache.getId(container)}`\n\t}\n\n\tpublic static getRealmKey(id: RuntimeId, blueprint: EntityRealmBlueprint): EntityRealmKey {\n\t\tconst parent = blueprint.parent\n\t\tlet placeholderName: PlaceholderName\n\n\t\tif (blueprint.type === 'subTree') {\n\t\t\tplaceholderName = blueprint.marker.placeholderName\n\t\t} else if (blueprint.type === 'listEntity') {\n\t\t\tplaceholderName = blueprint.parent.blueprint.marker.placeholderName\n\t\t} else if (blueprint.type === 'hasOne') {\n\t\t\tplaceholderName = blueprint.marker.placeholderName\n\t\t} else {\n\t\t\treturn assertNever(blueprint)\n\t\t}\n\t\treturn this.generateKey(\n\t\t\tparent,\n\t\t\tplaceholderName,\n\t\t\t(id instanceof ClientGeneratedUuid ? 'C-' : '') + id.value.toString(),\n\t\t\tblueprint.type === 'listEntity' ? blueprint.parent.blueprint.marker.fields : blueprint.marker.fields,\n\t\t)\n\t}\n}\n"],"names":["assertNever","ClientGeneratedUuid","WeakIdCache"],"mappings":";;;;;;;AAKA,MAAM,OAAO;AACb,MAAM,cAAc,IAAI,OAAO,GAAG,IAAI,OAAO;AAEtC,MAAM,kBAAkB;AAAA,EAM9B,OAAc,uBAAuB,WAA4B;AAEhE,WAAO,UAAU,WAAW,MAAM,IAAI,EAAE,KAAK,YAAY,KAAK,SAAS;AAAA,EACxE;AAAA,EAEA,OAAe,YACd,QACA,iBACA,IACA,WACiB;AAEjB,WAAO,MAAM,IAAI,GAChB,KAAK,mBAAmB;AAAA,MACvB;AAAA,IAAA,CAEF,GAAG,IAAI,GAAG,eAAe,GAAG,EAAE,GAAG,IAAI,GAAG,KAAK,cAAc,MAAM,SAAS,CAAC;AAAA,EAC5E;AAAA,EAEA,OAAc,YAAY,IAAe,WAAiD;AACzF,UAAM,SAAS,UAAU;AACzB,QAAI;AAEJ,QAAI,UAAU,SAAS,WAAW;AACjC,wBAAkB,UAAU,OAAO;AAAA,IACpC,WAAW,UAAU,SAAS,cAAc;AAC3C,wBAAkB,UAAU,OAAO,UAAU,OAAO;AAAA,IACrD,WAAW,UAAU,SAAS,UAAU;AACvC,wBAAkB,UAAU,OAAO;AAAA,IACpC,OAAO;AACN,aAAOA,cAAAA,YAAY,SAAS;AAAA,IAC7B;AACA,WAAO,KAAK;AAAA,MACX;AAAA,MACA;AAAA,OACC,cAAcC,cAAAA,sBAAsB,OAAO,MAAM,GAAG,MAAM,SAAA;AAAA,MAC3D,UAAU,SAAS,eAAe,UAAU,OAAO,UAAU,OAAO,SAAS,UAAU,OAAO;AAAA,IAAA;AAAA,EAEhG;AACD;AA1CC,cAHY,mBAGG,sBAAqB,IAAIC,UAAAA,aAAgD;AACxF,cAJY,mBAIG,iBAAgB,IAAIA,UAAAA,aAAyC;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RealmKeyGenerator.js","sources":["../../../../../packages/binding-legacy/src/core/RealmKeyGenerator.ts"],"sourcesContent":["import { ClientGeneratedUuid, EntityFieldMarkersContainer, EntityId, EntityRealmKey, PlaceholderName, RuntimeId } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport type { EntityListState, EntityRealmBlueprint, EntityRealmState } from './state'\nimport { WeakIdCache } from '@contember/utilities'\n\nconst GLUE = '--'\nconst keyEndRegex = new RegExp(`${GLUE}\\\\d+$`)\n\nexport class RealmKeyGenerator {\n\t// We're using this id, and not, well, the entity id, because it *SIGNIFICANTLY* reduces the complexity of\n\t// entity id changes.\n\tprivate static parentStateIdCache = new WeakIdCache<EntityRealmState | EntityListState>()\n\tprivate static markerIdCache = new WeakIdCache<EntityFieldMarkersContainer>()\n\n\tpublic static vaguelyAppearsToBeAKey(candidate: string): boolean {\n\t\t// This is just for error messages. No need to be super precise.\n\t\treturn candidate.startsWith(`key${GLUE}`) && keyEndRegex.test(candidate)\n\t}\n\n\tprivate static generateKey(\n\t\tparent: EntityRealmState | EntityListState | undefined,\n\t\tplaceholderName: PlaceholderName,\n\t\tid: string,\n\t\tcontainer: EntityFieldMarkersContainer,\n\t): EntityRealmKey {\n\t\t// The static prefix serves to really emphasize that this is *NOT* just a uuid\n\t\treturn `key${GLUE}${\n\t\t\tthis.parentStateIdCache.getOptionalKeyId(\n\t\t\t\tparent,\n\t\t\t)\n\t\t}${GLUE}${placeholderName}${id}${GLUE}${this.markerIdCache.getId(container)}`\n\t}\n\n\tpublic static getRealmKey(id: RuntimeId, blueprint: EntityRealmBlueprint): EntityRealmKey {\n\t\tconst parent = blueprint.parent\n\t\tlet placeholderName: PlaceholderName\n\n\t\tif (blueprint.type === 'subTree') {\n\t\t\tplaceholderName = blueprint.marker.placeholderName\n\t\t} else if (blueprint.type === 'listEntity') {\n\t\t\tplaceholderName = blueprint.parent.blueprint.marker.placeholderName\n\t\t} else if (blueprint.type === 'hasOne') {\n\t\t\tplaceholderName = blueprint.marker.placeholderName\n\t\t} else {\n\t\t\treturn assertNever(blueprint)\n\t\t}\n\t\treturn this.generateKey(\n\t\t\tparent,\n\t\t\tplaceholderName,\n\t\t\t(id instanceof ClientGeneratedUuid ? 'C-' : '') + id.value.toString(),\n\t\t\tblueprint.type === 'listEntity' ? blueprint.parent.blueprint.marker.fields : blueprint.marker.fields,\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";;;;;AAKA,MAAM,OAAO;AACb,MAAM,cAAc,IAAI,OAAO,GAAG,IAAI,OAAO;AAEtC,MAAM,kBAAkB;AAAA,EAM9B,OAAc,uBAAuB,WAA4B;AAEhE,WAAO,UAAU,WAAW,MAAM,IAAI,EAAE,KAAK,YAAY,KAAK,SAAS;AAAA,EACxE;AAAA,EAEA,OAAe,YACd,QACA,iBACA,IACA,WACiB;AAEjB,WAAO,MAAM,IAAI,GAChB,KAAK,mBAAmB;AAAA,MACvB;AAAA,IAAA,CAEF,GAAG,IAAI,GAAG,eAAe,GAAG,EAAE,GAAG,IAAI,GAAG,KAAK,cAAc,MAAM,SAAS,CAAC;AAAA,EAC5E;AAAA,EAEA,OAAc,YAAY,IAAe,WAAiD;AACzF,UAAM,SAAS,UAAU;AACzB,QAAI;AAEJ,QAAI,UAAU,SAAS,WAAW;AACjC,wBAAkB,UAAU,OAAO;AAAA,IACpC,WAAW,UAAU,SAAS,cAAc;AAC3C,wBAAkB,UAAU,OAAO,UAAU,OAAO;AAAA,IACrD,WAAW,UAAU,SAAS,UAAU;AACvC,wBAAkB,UAAU,OAAO;AAAA,IACpC,OAAO;AACN,aAAO,YAAY,SAAS;AAAA,IAC7B;AACA,WAAO,KAAK;AAAA,MACX;AAAA,MACA;AAAA,OACC,cAAc,sBAAsB,OAAO,MAAM,GAAG,MAAM,SAAA;AAAA,MAC3D,UAAU,SAAS,eAAe,UAAU,OAAO,UAAU,OAAO,SAAS,UAAU,OAAO;AAAA,IAAA;AAAA,EAEhG;AACD;AA1CC,cAHY,mBAGG,sBAAqB,IAAI,aAAgD;AACxF,cAJY,mBAIG,iBAAgB,IAAI,aAAyC;"}
|
|
1
|
+
{"version":3,"file":"RealmKeyGenerator.js","sources":["../../../../../packages/binding-legacy/src/core/RealmKeyGenerator.ts"],"sourcesContent":["import { ClientGeneratedUuid, EntityFieldMarkersContainer, EntityId, EntityRealmKey, PlaceholderName, RuntimeId } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport type { EntityListState, EntityRealmBlueprint, EntityRealmState } from './state/index.js'\nimport { WeakIdCache } from '@contember/utilities'\n\nconst GLUE = '--'\nconst keyEndRegex = new RegExp(`${GLUE}\\\\d+$`)\n\nexport class RealmKeyGenerator {\n\t// We're using this id, and not, well, the entity id, because it *SIGNIFICANTLY* reduces the complexity of\n\t// entity id changes.\n\tprivate static parentStateIdCache = new WeakIdCache<EntityRealmState | EntityListState>()\n\tprivate static markerIdCache = new WeakIdCache<EntityFieldMarkersContainer>()\n\n\tpublic static vaguelyAppearsToBeAKey(candidate: string): boolean {\n\t\t// This is just for error messages. No need to be super precise.\n\t\treturn candidate.startsWith(`key${GLUE}`) && keyEndRegex.test(candidate)\n\t}\n\n\tprivate static generateKey(\n\t\tparent: EntityRealmState | EntityListState | undefined,\n\t\tplaceholderName: PlaceholderName,\n\t\tid: string,\n\t\tcontainer: EntityFieldMarkersContainer,\n\t): EntityRealmKey {\n\t\t// The static prefix serves to really emphasize that this is *NOT* just a uuid\n\t\treturn `key${GLUE}${\n\t\t\tthis.parentStateIdCache.getOptionalKeyId(\n\t\t\t\tparent,\n\t\t\t)\n\t\t}${GLUE}${placeholderName}${id}${GLUE}${this.markerIdCache.getId(container)}`\n\t}\n\n\tpublic static getRealmKey(id: RuntimeId, blueprint: EntityRealmBlueprint): EntityRealmKey {\n\t\tconst parent = blueprint.parent\n\t\tlet placeholderName: PlaceholderName\n\n\t\tif (blueprint.type === 'subTree') {\n\t\t\tplaceholderName = blueprint.marker.placeholderName\n\t\t} else if (blueprint.type === 'listEntity') {\n\t\t\tplaceholderName = blueprint.parent.blueprint.marker.placeholderName\n\t\t} else if (blueprint.type === 'hasOne') {\n\t\t\tplaceholderName = blueprint.marker.placeholderName\n\t\t} else {\n\t\t\treturn assertNever(blueprint)\n\t\t}\n\t\treturn this.generateKey(\n\t\t\tparent,\n\t\t\tplaceholderName,\n\t\t\t(id instanceof ClientGeneratedUuid ? 'C-' : '') + id.value.toString(),\n\t\t\tblueprint.type === 'listEntity' ? blueprint.parent.blueprint.marker.fields : blueprint.marker.fields,\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";;;;;AAKA,MAAM,OAAO;AACb,MAAM,cAAc,IAAI,OAAO,GAAG,IAAI,OAAO;AAEtC,MAAM,kBAAkB;AAAA,EAM9B,OAAc,uBAAuB,WAA4B;AAEhE,WAAO,UAAU,WAAW,MAAM,IAAI,EAAE,KAAK,YAAY,KAAK,SAAS;AAAA,EACxE;AAAA,EAEA,OAAe,YACd,QACA,iBACA,IACA,WACiB;AAEjB,WAAO,MAAM,IAAI,GAChB,KAAK,mBAAmB;AAAA,MACvB;AAAA,IAAA,CAEF,GAAG,IAAI,GAAG,eAAe,GAAG,EAAE,GAAG,IAAI,GAAG,KAAK,cAAc,MAAM,SAAS,CAAC;AAAA,EAC5E;AAAA,EAEA,OAAc,YAAY,IAAe,WAAiD;AACzF,UAAM,SAAS,UAAU;AACzB,QAAI;AAEJ,QAAI,UAAU,SAAS,WAAW;AACjC,wBAAkB,UAAU,OAAO;AAAA,IACpC,WAAW,UAAU,SAAS,cAAc;AAC3C,wBAAkB,UAAU,OAAO,UAAU,OAAO;AAAA,IACrD,WAAW,UAAU,SAAS,UAAU;AACvC,wBAAkB,UAAU,OAAO;AAAA,IACpC,OAAO;AACN,aAAO,YAAY,SAAS;AAAA,IAC7B;AACA,WAAO,KAAK;AAAA,MACX;AAAA,MACA;AAAA,OACC,cAAc,sBAAsB,OAAO,MAAM,GAAG,MAAM,SAAA;AAAA,MAC3D,UAAU,SAAS,eAAe,UAAU,OAAO,UAAU,OAAO,SAAS,UAAU,OAAO;AAAA,IAAA;AAAA,EAEhG;AACD;AA1CC,cAHY,mBAGG,sBAAqB,IAAI,aAAgD;AACxF,cAJY,mBAIG,iBAAgB,IAAI,aAAyC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestResponseNormalizer.cjs","sources":["../../../../../packages/binding-legacy/src/core/RequestResponseNormalizer.ts"],"sourcesContent":["import { ReceivedDataTree, ReceivedEntityData, ServerId } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { PRIMARY_KEY_NAME } from '@contember/binding-common'\nimport { EntityId } from '@contember/binding-common'\nimport {\n\tEntityFieldMarkers,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n} from '@contember/binding-common'\nimport { SubMutationOperation } from './MutationGenerator'\nimport { assertNever } from '@contember/binding-common'\nimport { NormalizedPersistedData, PersistedEntityDataStore, SingleEntityPersistedData } from '../accessorTree'\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 (marker instanceof 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\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\n\t\t\t// probably multiple operations removing same entity, resulting in no data for some of them\n\t\t\tif (!receivedData) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (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\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: SingleEntityPersistedData = 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\tconst metaFlags = {\n\t\t\t\treadable: entityData._meta?.[field.parameters.field]?.readable ?? undefined,\n\t\t\t\tupdatable: entityData._meta?.[field.parameters.field]?.updatable ?? undefined,\n\t\t\t}\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\tvalue,\n\t\t\t\t\t...metaFlags,\n\t\t\t\t})\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tif (value === null) {\n\t\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\t\tvalue: null,\n\t\t\t\t\t\t...metaFlags,\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\t\tvalue: this.processEntityData(entityMap, value as ReceivedEntityData, field.fields.markers),\n\t\t\t\t\t\t...metaFlags,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\tconst ids = presentEntityData.get(placeholder)?.value ?? new Set()\n\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\tvalue: ids,\n\t\t\t\t\t...metaFlags,\n\t\t\t\t})\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":["EntitySubTreeMarker","BindingError","EntityListSubTreeMarker","assertNever","FieldMarker","HasOneRelationMarker","HasManyRelationMarker","id","PRIMARY_KEY_NAME","ServerId"],"mappings":";;;AAiBO,MAAM,0BAA0B;AAAA,EACtC,OAAc,qBACb,UACA,kBACA,YACO;AACP,UAAM,EAAE,kBAAkB,yBAAA,IAA6B;AAEvD,eAAW,CAAC,aAAa,MAAM,KAAK,WAAW,UAAU;AACxD,YAAM,OAAO,iBAAiB,WAAW,KAAK;AAC9C,UAAI,kBAAkBA,cAAAA,qBAAqB;AAC1C,YAAI,SAAS,MAAM;AAClB,2BAAiB,OAAO,WAAW;AAAA,QACpC,OAAO;AACN,cAAI,MAAM,QAAQ,IAAI,GAAG;AACxB,kBAAM,IAAIC,cAAAA,aAAA;AAAA,UACX;AACA,gBAAM,KAAK,KAAK,kBAAkB,0BAA0B,MAAM,OAAO,OAAO,OAAO;AACvF,2BAAiB,IAAI,aAAa,EAAE;AAAA,QACrC;AAAA,MACD,WAAW,kBAAkBC,uCAAyB;AACrD,cAAM,qCAAqB,IAAA;AAC3B,YAAI,CAAC,MAAM,QAAQ,IAAI,GAAG;AACzB,gBAAM,IAAID,cAAAA,aAAA;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B,IAAI,WAAW,GAAG,6BAAa,IAAA;AAC7D,0BAAkB,IAAI,aAAa;AAAA,UAClC,OAAO;AAAA,UACP,GAAG;AAAA,QAAA,CACH;AACD,YAAI,EAAE,eAAe,MAAM;AAC1B,gBAAM,IAAIL,cAAAA,aAAA;AAAA,QACX;AACA,YAAI,MAAA;AACJ,mBAAW,OAAO,OAA+B;AAChD,gBAAMM,MAAK,KAAK,kBAAkB,WAAW,KAAK,MAAM,OAAO,OAAO;AACtE,cAAI,IAAIA,IAAG,KAAK;AAAA,QACjB;AAAA,MACD,OAAO;AACN,cAAM,IAAI,MAAA;AAAA,MACX;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AAAA,EAEA,OAAe,UAAU,YAA0C;AAClE,UAAM,aAAmC,WAAWC,8BAAgB;AAEpE,QAAI,eAAe,QAAW;AAC7B,YAAM,IAAIP,cAAAA,aAAa,mEAAmE;AAAA,IAC3F;AAEA,WAAO,IAAIQ,cAAAA,SAAS,YAAY,WAAW,UAAU;AAAA,EACtD;AACD;;"}
|
|
1
|
+
{"version":3,"file":"RequestResponseNormalizer.cjs","sources":["../../../../../packages/binding-legacy/src/core/RequestResponseNormalizer.ts"],"sourcesContent":["import { ReceivedDataTree, ReceivedEntityData, ServerId } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { PRIMARY_KEY_NAME } from '@contember/binding-common'\nimport { EntityId } from '@contember/binding-common'\nimport {\n\tEntityFieldMarkers,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n} from '@contember/binding-common'\nimport { SubMutationOperation } from './MutationGenerator.js'\nimport { assertNever } from '@contember/binding-common'\nimport { NormalizedPersistedData, PersistedEntityDataStore, SingleEntityPersistedData } from '../accessorTree/index.js'\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 (marker instanceof 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\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\n\t\t\t// probably multiple operations removing same entity, resulting in no data for some of them\n\t\t\tif (!receivedData) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (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\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: SingleEntityPersistedData = 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\tconst metaFlags = {\n\t\t\t\treadable: entityData._meta?.[field.parameters.field]?.readable ?? undefined,\n\t\t\t\tupdatable: entityData._meta?.[field.parameters.field]?.updatable ?? undefined,\n\t\t\t}\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\tvalue,\n\t\t\t\t\t...metaFlags,\n\t\t\t\t})\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tif (value === null) {\n\t\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\t\tvalue: null,\n\t\t\t\t\t\t...metaFlags,\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\t\tvalue: this.processEntityData(entityMap, value as ReceivedEntityData, field.fields.markers),\n\t\t\t\t\t\t...metaFlags,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\tconst ids = presentEntityData.get(placeholder)?.value ?? new Set()\n\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\tvalue: ids,\n\t\t\t\t\t...metaFlags,\n\t\t\t\t})\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":["EntitySubTreeMarker","BindingError","EntityListSubTreeMarker","assertNever","FieldMarker","HasOneRelationMarker","HasManyRelationMarker","id","PRIMARY_KEY_NAME","ServerId"],"mappings":";;;AAiBO,MAAM,0BAA0B;AAAA,EACtC,OAAc,qBACb,UACA,kBACA,YACO;AACP,UAAM,EAAE,kBAAkB,yBAAA,IAA6B;AAEvD,eAAW,CAAC,aAAa,MAAM,KAAK,WAAW,UAAU;AACxD,YAAM,OAAO,iBAAiB,WAAW,KAAK;AAC9C,UAAI,kBAAkBA,cAAAA,qBAAqB;AAC1C,YAAI,SAAS,MAAM;AAClB,2BAAiB,OAAO,WAAW;AAAA,QACpC,OAAO;AACN,cAAI,MAAM,QAAQ,IAAI,GAAG;AACxB,kBAAM,IAAIC,cAAAA,aAAA;AAAA,UACX;AACA,gBAAM,KAAK,KAAK,kBAAkB,0BAA0B,MAAM,OAAO,OAAO,OAAO;AACvF,2BAAiB,IAAI,aAAa,EAAE;AAAA,QACrC;AAAA,MACD,WAAW,kBAAkBC,uCAAyB;AACrD,cAAM,qCAAqB,IAAA;AAC3B,YAAI,CAAC,MAAM,QAAQ,IAAI,GAAG;AACzB,gBAAM,IAAID,cAAAA,aAAA;AAAA,QACX;AACA,mBAAW,OAAO,MAAM;AACvB,gBAAM,KAAK,KAAK,kBAAkB,0BAA0B,KAAK,OAAO,OAAO,OAAO;AACtF,yBAAe,IAAI,GAAG,KAAK;AAAA,QAC5B;AACA,yBAAiB,IAAI,aAAa,cAAc;AAAA,MACjD,OAAO;AACN,cAAM,IAAIA,cAAAA,aAAA;AAAA,MACX;AAAA,IACD;AAAA,EACD;AAAA,EAEA,OAAc,wBACb,UAC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AAO,OAAO;AACtE,cAAI,IAAIA,IAAG,KAAK;AAAA,QACjB;AAAA,MACD,OAAO;AACN,cAAM,IAAI,MAAA;AAAA,MACX;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AAAA,EAEA,OAAe,UAAU,YAA0C;AAClE,UAAM,aAAmC,WAAWC,8BAAgB;AAEpE,QAAI,eAAe,QAAW;AAC7B,YAAM,IAAIP,cAAAA,aAAa,mEAAmE;AAAA,IAC3F;AAEA,WAAO,IAAIQ,cAAAA,SAAS,YAAY,WAAW,UAAU;AAAA,EACtD;AACD;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestResponseNormalizer.js","sources":["../../../../../packages/binding-legacy/src/core/RequestResponseNormalizer.ts"],"sourcesContent":["import { ReceivedDataTree, ReceivedEntityData, ServerId } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { PRIMARY_KEY_NAME } from '@contember/binding-common'\nimport { EntityId } from '@contember/binding-common'\nimport {\n\tEntityFieldMarkers,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n} from '@contember/binding-common'\nimport { SubMutationOperation } from './MutationGenerator'\nimport { assertNever } from '@contember/binding-common'\nimport { NormalizedPersistedData, PersistedEntityDataStore, SingleEntityPersistedData } from '../accessorTree'\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 (marker instanceof 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\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\n\t\t\t// probably multiple operations removing same entity, resulting in no data for some of them\n\t\t\tif (!receivedData) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (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\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: SingleEntityPersistedData = 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\tconst metaFlags = {\n\t\t\t\treadable: entityData._meta?.[field.parameters.field]?.readable ?? undefined,\n\t\t\t\tupdatable: entityData._meta?.[field.parameters.field]?.updatable ?? undefined,\n\t\t\t}\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\tvalue,\n\t\t\t\t\t...metaFlags,\n\t\t\t\t})\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tif (value === null) {\n\t\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\t\tvalue: null,\n\t\t\t\t\t\t...metaFlags,\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\t\tvalue: this.processEntityData(entityMap, value as ReceivedEntityData, field.fields.markers),\n\t\t\t\t\t\t...metaFlags,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\tconst ids = presentEntityData.get(placeholder)?.value ?? new Set()\n\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\tvalue: ids,\n\t\t\t\t\t...metaFlags,\n\t\t\t\t})\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":["id"],"mappings":";AAiBO,MAAM,0BAA0B;AAAA,EACtC,OAAc,qBACb,UACA,kBACA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KAAK,GAAG,aAAa;AAAA,MAAA;AAErE,UAAI,iBAAiB,aAAa;AACjC,0BAAkB,IAAI,aAAa;AAAA,UAClC;AAAA,UACA,GAAG;AAAA,QAAA,CACH;AAAA,MACF,WAAW,iBAAiB,sBAAsB;AACjD,YAAI,UAAU,MAAM;AACnB,4BAAkB,IAAI,aAAa;AAAA,YAClC,OAAO;AAAA,YACP,GAAG;AAAA,UAAA,CACH;AAAA,QACF,OAAO;AACN,4BAAkB,IAAI,aAAa;AAAA,YAClC,OAAO,KAAK,kBAAkB,WAAW,OAA6B,MAAM,OAAO,OAAO;AAAA,YAC1F,GAAG;AAAA,UAAA,CACH;AAAA,QACF;AAAA,MACD,WAAW,iBAAiB,uBAAuB;AAClD,cAAM,MAAM,kBAAkB,IAAI,WAAW,GAAG,6BAAa,IAAA;AAC7D,0BAAkB,IAAI,aAAa;AAAA,UAClC,OAAO;AAAA,UACP,GAAG;AAAA,QAAA,CACH;AACD,YAAI,EAAE,eAAe,MAAM;AAC1B,gBAAM,IAAI,aAAA;AAAA,QACX;AACA,YAAI,MAAA;AACJ,mBAAW,OAAO,OAA+B;AAChD,gBAAMA,MAAK,KAAK,kBAAkB,WAAW,KAAK,MAAM,OAAO,OAAO;AACtE,cAAI,IAAIA,IAAG,KAAK;AAAA,QACjB;AAAA,MACD,OAAO;AACN,cAAM,IAAI,MAAA;AAAA,MACX;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AAAA,EAEA,OAAe,UAAU,YAA0C;AAClE,UAAM,aAAmC,WAAW,gBAAgB;AAEpE,QAAI,eAAe,QAAW;AAC7B,YAAM,IAAI,aAAa,mEAAmE;AAAA,IAC3F;AAEA,WAAO,IAAI,SAAS,YAAY,WAAW,UAAU;AAAA,EACtD;AACD;"}
|
|
1
|
+
{"version":3,"file":"RequestResponseNormalizer.js","sources":["../../../../../packages/binding-legacy/src/core/RequestResponseNormalizer.ts"],"sourcesContent":["import { ReceivedDataTree, ReceivedEntityData, ServerId } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { PRIMARY_KEY_NAME } from '@contember/binding-common'\nimport { EntityId } from '@contember/binding-common'\nimport {\n\tEntityFieldMarkers,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n} from '@contember/binding-common'\nimport { SubMutationOperation } from './MutationGenerator.js'\nimport { assertNever } from '@contember/binding-common'\nimport { NormalizedPersistedData, PersistedEntityDataStore, SingleEntityPersistedData } from '../accessorTree/index.js'\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 (marker instanceof 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\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\n\t\t\t// probably multiple operations removing same entity, resulting in no data for some of them\n\t\t\tif (!receivedData) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (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\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: SingleEntityPersistedData = 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\tconst metaFlags = {\n\t\t\t\treadable: entityData._meta?.[field.parameters.field]?.readable ?? undefined,\n\t\t\t\tupdatable: entityData._meta?.[field.parameters.field]?.updatable ?? undefined,\n\t\t\t}\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\tvalue,\n\t\t\t\t\t...metaFlags,\n\t\t\t\t})\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tif (value === null) {\n\t\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\t\tvalue: null,\n\t\t\t\t\t\t...metaFlags,\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\t\tvalue: this.processEntityData(entityMap, value as ReceivedEntityData, field.fields.markers),\n\t\t\t\t\t\t...metaFlags,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\tconst ids = presentEntityData.get(placeholder)?.value ?? new Set()\n\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\tvalue: ids,\n\t\t\t\t\t...metaFlags,\n\t\t\t\t})\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":["id"],"mappings":";AAiBO,MAAM,0BAA0B;AAAA,EACtC,OAAc,qBACb,UACA,kBACA,YACO;AACP,UAAM,EAAE,kBAAkB,yBAAA,IAA6B;AAEvD,eAAW,CAAC,aAAa,MAAM,KAAK,WAAW,UAAU;AACxD,YAAM,OAAO,iBAAiB,WAAW,KAAK;AAC9C,UAAI,kBAAkB,qBAAqB;AAC1C,YAAI,SAAS,MAAM;AAClB,2BAAiB,OAAO,WAAW;AAAA,QACpC,OAAO;AACN,cAAI,MAAM,QAAQ,IAAI,GAAG;AACxB,kBAAM,IAAI,aAAA;AAAA,UACX;AACA,gBAAM,KAAK,KAAK,kBAAkB,0BAA0B,MAAM,OAAO,OAAO,OAAO;AACvF,2BAAiB,IAAI,aAAa,EAAE;AAAA,QACrC;AAAA,MACD,WAAW,kBAAkB,yBAAyB;AACrD,cAAM,qCAAqB,IAAA;AAC3B,YAAI,CAAC,MAAM,QAAQ,IAAI,G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