@contember/binding 1.1.0 → 1.2.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/accessorPropagation/AccessorProvider.js +2 -10
- package/dist/development/accessorPropagation/AccessorProvider.js.map +1 -1
- package/dist/development/accessorPropagation/BindingOperationsProvider.js +2 -6
- package/dist/development/accessorPropagation/BindingOperationsProvider.js.map +1 -1
- package/dist/development/accessorPropagation/EntityKeyProvider.js +2 -6
- package/dist/development/accessorPropagation/EntityKeyProvider.js.map +1 -1
- package/dist/development/accessorPropagation/EnvironmentContext.js +5 -21
- package/dist/development/accessorPropagation/EnvironmentContext.js.map +1 -1
- package/dist/development/accessorPropagation/TreeRootIdProvider.js +2 -6
- package/dist/development/accessorPropagation/TreeRootIdProvider.js.map +1 -1
- package/dist/development/accessorPropagation/useDesugaredRelativeEntityList.js +1 -0
- package/dist/development/accessorPropagation/useDesugaredRelativeEntityList.js.map +1 -1
- package/dist/development/accessorPropagation/useDesugaredRelativeSingleEntity.js +1 -0
- package/dist/development/accessorPropagation/useDesugaredRelativeSingleEntity.js.map +1 -1
- package/dist/development/accessorPropagation/useDesugaredRelativeSingleField.js +1 -0
- package/dist/development/accessorPropagation/useDesugaredRelativeSingleField.js.map +1 -1
- package/dist/development/accessorPropagation/useEntity.js.map +1 -1
- package/dist/development/accessorPropagation/useEntityList.js.map +1 -1
- package/dist/development/accessorPropagation/useEntityListSubTree.js.map +1 -1
- package/dist/development/accessorPropagation/useEntitySubTree.js.map +1 -1
- package/dist/development/accessorPropagation/useField.js.map +1 -1
- package/dist/development/accessorPropagation/useGetEntityListSubTree.js.map +1 -1
- package/dist/development/accessorPropagation/useGetEntitySubTree.js.map +1 -1
- package/dist/development/accessorSorting/SetOrderFieldOnCreate.js +13 -57
- package/dist/development/accessorSorting/SetOrderFieldOnCreate.js.map +1 -1
- package/dist/development/accessorSorting/moveEntity.js.map +1 -1
- package/dist/development/accessorSorting/repairEntitiesOrder.js.map +1 -1
- package/dist/development/accessorTree/AccessorTree.js +4 -24
- package/dist/development/accessorTree/AccessorTree.js.map +1 -1
- package/dist/development/accessorTree/RuntimeId.js +1 -1
- package/dist/development/accessorTree/RuntimeId.js.map +1 -1
- package/dist/development/accessors/EntityAccessor.js +15 -2
- package/dist/development/accessors/EntityAccessor.js.map +1 -1
- package/dist/development/accessors/EntityListAccessor.js +9 -0
- package/dist/development/accessors/EntityListAccessor.js.map +1 -1
- package/dist/development/accessors/FieldAccessor.js +1 -0
- package/dist/development/accessors/FieldAccessor.js.map +1 -1
- package/dist/development/accessors/TreeRootAccessor.js +3 -0
- package/dist/development/accessors/TreeRootAccessor.js.map +1 -1
- package/dist/development/core/AccessorErrorManager.js +6 -6
- package/dist/development/core/AccessorErrorManager.js.map +1 -1
- package/dist/development/core/Config.js.map +1 -1
- package/dist/development/core/DataBinding.js +25 -16
- package/dist/development/core/DataBinding.js.map +1 -1
- package/dist/development/core/DirtinessTracker.js.map +1 -1
- package/dist/development/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/development/core/EventManager.js +14 -38
- package/dist/development/core/EventManager.js.map +1 -1
- package/dist/development/core/IncrementalMarkerBuilder.js +5 -5
- package/dist/development/core/IncrementalMarkerBuilder.js.map +1 -1
- package/dist/development/core/MarkerComparator.js +1 -0
- package/dist/development/core/MarkerComparator.js.map +1 -1
- package/dist/development/core/MarkerMerger.js +1 -0
- package/dist/development/core/MarkerMerger.js.map +1 -1
- package/dist/development/core/MarkerTreeGenerator.js +6 -6
- package/dist/development/core/MarkerTreeGenerator.js.map +1 -1
- package/dist/development/core/MutationGenerator.js +7 -7
- package/dist/development/core/MutationGenerator.js.map +1 -1
- package/dist/development/core/QueryGenerator.js +1 -0
- package/dist/development/core/QueryGenerator.js.map +1 -1
- package/dist/development/core/RealmKeyGenerator.js +4 -2
- package/dist/development/core/RealmKeyGenerator.js.map +1 -1
- package/dist/development/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/development/core/StateInitializer.js +11 -8
- package/dist/development/core/StateInitializer.js.map +1 -1
- package/dist/development/core/TreeAugmenter.js +6 -1
- package/dist/development/core/TreeAugmenter.js.map +1 -1
- package/dist/development/core/TreeParameterMerger.js +26 -0
- package/dist/development/core/TreeParameterMerger.js.map +1 -1
- package/dist/development/core/TreeStore.js +9 -7
- package/dist/development/core/TreeStore.js.map +1 -1
- package/dist/development/core/exceptions/ErrorLocator.js +3 -3
- package/dist/development/core/exceptions/ErrorLocator.js.map +1 -1
- package/dist/development/core/exceptions/TreeParameterSugarer.js +2 -2
- package/dist/development/core/operations/EntityOperations.js +3 -1
- package/dist/development/core/operations/EntityOperations.js.map +1 -1
- package/dist/development/core/operations/FieldOperations.js +1 -21
- package/dist/development/core/operations/FieldOperations.js.map +1 -1
- package/dist/development/core/schema/SchemaLoader.js +2 -2
- package/dist/development/core/schema/SchemaLoader.js.map +1 -1
- package/dist/development/core/state/StateIterator.js +1 -0
- package/dist/development/core/state/StateIterator.js.map +1 -1
- package/dist/development/coreComponents/Component.js.map +1 -1
- package/dist/development/coreComponents/DataBindingProvider.js +2 -6
- package/dist/development/coreComponents/DataBindingProvider.js.map +1 -1
- package/dist/development/coreComponents/Entity.js +5 -6
- package/dist/development/coreComponents/Entity.js.map +1 -1
- package/dist/development/coreComponents/EntityList.js +5 -17
- package/dist/development/coreComponents/EntityList.js.map +1 -1
- package/dist/development/coreComponents/EntityListSubTree.js +5 -17
- package/dist/development/coreComponents/EntityListSubTree.js.map +1 -1
- package/dist/development/coreComponents/EntitySubTree.js +9 -33
- package/dist/development/coreComponents/EntitySubTree.js.map +1 -1
- package/dist/development/coreComponents/Field.js +3 -11
- package/dist/development/coreComponents/Field.js.map +1 -1
- package/dist/development/coreComponents/HasMany.js +5 -17
- package/dist/development/coreComponents/HasMany.js.map +1 -1
- package/dist/development/coreComponents/HasOne.js +5 -17
- package/dist/development/coreComponents/HasOne.js.map +1 -1
- package/dist/development/coreComponents/ParentEntity.js +2 -6
- package/dist/development/coreComponents/ParentEntity.js.map +1 -1
- package/dist/development/dao/Environment.js +3 -0
- package/dist/development/dao/Environment.js.map +1 -1
- package/dist/development/entityEvents/useEntityEvent.js.map +1 -1
- package/dist/development/fieldHelpers/helpers/FieldHelper.js +1 -1
- package/dist/development/fieldHelpers/helpers/FieldHelper.js.map +1 -1
- package/dist/development/fieldHelpers/helpers/TemporalFieldHelper.js +4 -1
- package/dist/development/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -1
- package/dist/development/helperComponents/DeferredSubTrees.js +6 -22
- package/dist/development/helperComponents/DeferredSubTrees.js.map +1 -1
- package/dist/development/helperComponents/EntityView.js +2 -6
- package/dist/development/helperComponents/EntityView.js.map +1 -1
- package/dist/development/helperComponents/FieldView.js +5 -17
- package/dist/development/helperComponents/FieldView.js.map +1 -1
- package/dist/development/helperComponents/If.js +8 -40
- package/dist/development/helperComponents/If.js.map +1 -1
- package/dist/development/helperComponents/StaticRender.js +2 -6
- package/dist/development/helperComponents/StaticRender.js.map +1 -1
- package/dist/development/helperComponents/SugaredField.js +3 -11
- package/dist/development/helperComponents/SugaredField.js.map +1 -1
- package/dist/development/helperComponents/helpers/FilterEvaluator.js.map +1 -1
- package/dist/development/helperComponents/helpers/evaluateCondition.js +1 -0
- package/dist/development/helperComponents/helpers/evaluateCondition.js.map +1 -1
- package/dist/development/markers/EntityFieldMarkersContainer.js +1 -0
- package/dist/development/markers/EntityFieldMarkersContainer.js.map +1 -1
- package/dist/development/markers/EntityListSubTreeMarker.js +2 -2
- package/dist/development/markers/EntityListSubTreeMarker.js.map +1 -1
- package/dist/development/markers/EntitySubTreeMarker.js +2 -2
- package/dist/development/markers/EntitySubTreeMarker.js.map +1 -1
- package/dist/development/markers/FieldMarker.js +2 -2
- package/dist/development/markers/FieldMarker.js.map +1 -1
- package/dist/development/markers/HasManyRelationMarker.js +2 -8
- package/dist/development/markers/HasManyRelationMarker.js.map +1 -1
- package/dist/development/markers/HasOneRelationMarker.js +2 -2
- package/dist/development/markers/HasOneRelationMarker.js.map +1 -1
- package/dist/development/queryLanguage/CacheStore.js +1 -1
- package/dist/development/queryLanguage/CacheStore.js.map +1 -1
- package/dist/development/queryLanguage/MarkerFactory.js.map +1 -1
- package/dist/development/queryLanguage/Parser.js +9 -10
- package/dist/development/queryLanguage/Parser.js.map +1 -1
- package/dist/development/queryLanguage/QueryLanguage.js +19 -11
- package/dist/development/queryLanguage/QueryLanguage.js.map +1 -1
- package/dist/development/structures/BijectiveIndexedMap.js +3 -1
- package/dist/development/structures/BijectiveIndexedMap.js.map +1 -1
- package/dist/development/structures/LRUCache.js +1 -1
- package/dist/development/structures/LRUCache.js.map +1 -1
- package/dist/development/structures/WeakIdCache.js.map +1 -1
- package/dist/development/treeParameterHelpers/wrapFilterInHasOnes.js.map +1 -1
- package/dist/development/treeParameters/EntityCreationParameters.js +1 -0
- package/dist/development/treeParameters/EntityCreationParameters.js.map +1 -1
- package/dist/development/treeParameters/LeafField.js.map +1 -1
- package/dist/development/utils/Hashing.js +1 -0
- package/dist/development/utils/Hashing.js.map +1 -1
- package/dist/production/accessorPropagation/useDesugaredRelativeEntityList.js +1 -0
- package/dist/production/accessorPropagation/useDesugaredRelativeEntityList.js.map +1 -1
- package/dist/production/accessorPropagation/useDesugaredRelativeSingleEntity.js +1 -0
- package/dist/production/accessorPropagation/useDesugaredRelativeSingleEntity.js.map +1 -1
- package/dist/production/accessorPropagation/useDesugaredRelativeSingleField.js +1 -0
- package/dist/production/accessorPropagation/useDesugaredRelativeSingleField.js.map +1 -1
- package/dist/production/accessorPropagation/useEntity.js.map +1 -1
- package/dist/production/accessorPropagation/useEntityList.js.map +1 -1
- package/dist/production/accessorPropagation/useEntityListSubTree.js.map +1 -1
- package/dist/production/accessorPropagation/useEntitySubTree.js.map +1 -1
- package/dist/production/accessorPropagation/useField.js.map +1 -1
- package/dist/production/accessorPropagation/useGetEntityListSubTree.js.map +1 -1
- package/dist/production/accessorPropagation/useGetEntitySubTree.js.map +1 -1
- package/dist/production/accessorSorting/SetOrderFieldOnCreate.js.map +1 -1
- package/dist/production/accessorSorting/moveEntity.js.map +1 -1
- package/dist/production/accessorSorting/repairEntitiesOrder.js.map +1 -1
- package/dist/production/accessorTree/AccessorTree.js +2 -2
- package/dist/production/accessorTree/AccessorTree.js.map +1 -1
- package/dist/production/accessorTree/RuntimeId.js +1 -1
- package/dist/production/accessorTree/RuntimeId.js.map +1 -1
- package/dist/production/accessors/EntityAccessor.js +15 -2
- package/dist/production/accessors/EntityAccessor.js.map +1 -1
- package/dist/production/accessors/EntityListAccessor.js +9 -0
- package/dist/production/accessors/EntityListAccessor.js.map +1 -1
- package/dist/production/accessors/FieldAccessor.js +1 -0
- package/dist/production/accessors/FieldAccessor.js.map +1 -1
- package/dist/production/accessors/TreeRootAccessor.js +3 -0
- package/dist/production/accessors/TreeRootAccessor.js.map +1 -1
- package/dist/production/core/AccessorErrorManager.js +6 -6
- package/dist/production/core/AccessorErrorManager.js.map +1 -1
- package/dist/production/core/Config.js.map +1 -1
- package/dist/production/core/DataBinding.js +25 -16
- package/dist/production/core/DataBinding.js.map +1 -1
- package/dist/production/core/DirtinessTracker.js.map +1 -1
- package/dist/production/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/production/core/EventManager.js +13 -11
- package/dist/production/core/EventManager.js.map +1 -1
- package/dist/production/core/IncrementalMarkerBuilder.js +5 -5
- package/dist/production/core/IncrementalMarkerBuilder.js.map +1 -1
- package/dist/production/core/MarkerComparator.js +1 -0
- package/dist/production/core/MarkerComparator.js.map +1 -1
- package/dist/production/core/MarkerMerger.js +1 -0
- package/dist/production/core/MarkerMerger.js.map +1 -1
- package/dist/production/core/MarkerTreeGenerator.js +6 -6
- package/dist/production/core/MarkerTreeGenerator.js.map +1 -1
- package/dist/production/core/MutationGenerator.js +7 -7
- package/dist/production/core/MutationGenerator.js.map +1 -1
- package/dist/production/core/QueryGenerator.js +1 -0
- package/dist/production/core/QueryGenerator.js.map +1 -1
- package/dist/production/core/RealmKeyGenerator.js +4 -2
- package/dist/production/core/RealmKeyGenerator.js.map +1 -1
- package/dist/production/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/production/core/StateInitializer.js +11 -8
- package/dist/production/core/StateInitializer.js.map +1 -1
- package/dist/production/core/TreeAugmenter.js +6 -1
- package/dist/production/core/TreeAugmenter.js.map +1 -1
- package/dist/production/core/TreeParameterMerger.js +26 -0
- package/dist/production/core/TreeParameterMerger.js.map +1 -1
- package/dist/production/core/TreeStore.js +9 -7
- package/dist/production/core/TreeStore.js.map +1 -1
- package/dist/production/core/exceptions/ErrorLocator.js +3 -3
- package/dist/production/core/exceptions/ErrorLocator.js.map +1 -1
- package/dist/production/core/exceptions/TreeParameterSugarer.js +2 -2
- package/dist/production/core/operations/EntityOperations.js +3 -1
- package/dist/production/core/operations/EntityOperations.js.map +1 -1
- package/dist/production/core/schema/SchemaLoader.js +2 -2
- package/dist/production/core/schema/SchemaLoader.js.map +1 -1
- package/dist/production/core/state/StateIterator.js +1 -0
- package/dist/production/core/state/StateIterator.js.map +1 -1
- package/dist/production/coreComponents/Component.js.map +1 -1
- package/dist/production/coreComponents/DataBindingProvider.js.map +1 -1
- package/dist/production/coreComponents/Entity.js +4 -1
- package/dist/production/coreComponents/Entity.js.map +1 -1
- package/dist/production/coreComponents/EntityList.js.map +1 -1
- package/dist/production/coreComponents/EntityListSubTree.js.map +1 -1
- package/dist/production/coreComponents/EntitySubTree.js.map +1 -1
- package/dist/production/coreComponents/Field.js.map +1 -1
- package/dist/production/coreComponents/HasMany.js.map +1 -1
- package/dist/production/coreComponents/HasOne.js.map +1 -1
- package/dist/production/coreComponents/ParentEntity.js.map +1 -1
- package/dist/production/dao/Environment.js +3 -0
- package/dist/production/dao/Environment.js.map +1 -1
- package/dist/production/entityEvents/useEntityEvent.js.map +1 -1
- package/dist/production/fieldHelpers/helpers/FieldHelper.js +1 -1
- package/dist/production/fieldHelpers/helpers/FieldHelper.js.map +1 -1
- package/dist/production/fieldHelpers/helpers/TemporalFieldHelper.js +4 -1
- package/dist/production/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -1
- package/dist/production/helperComponents/DeferredSubTrees.js.map +1 -1
- package/dist/production/helperComponents/EntityView.js.map +1 -1
- package/dist/production/helperComponents/FieldView.js.map +1 -1
- package/dist/production/helperComponents/If.js.map +1 -1
- package/dist/production/helperComponents/StaticRender.js.map +1 -1
- package/dist/production/helperComponents/SugaredField.js.map +1 -1
- package/dist/production/helperComponents/helpers/FilterEvaluator.js.map +1 -1
- package/dist/production/helperComponents/helpers/evaluateCondition.js +1 -0
- package/dist/production/helperComponents/helpers/evaluateCondition.js.map +1 -1
- package/dist/production/markers/EntityFieldMarkersContainer.js +1 -0
- package/dist/production/markers/EntityFieldMarkersContainer.js.map +1 -1
- package/dist/production/markers/EntityListSubTreeMarker.js +2 -2
- package/dist/production/markers/EntityListSubTreeMarker.js.map +1 -1
- package/dist/production/markers/EntitySubTreeMarker.js +2 -2
- package/dist/production/markers/EntitySubTreeMarker.js.map +1 -1
- package/dist/production/markers/FieldMarker.js +2 -2
- package/dist/production/markers/FieldMarker.js.map +1 -1
- package/dist/production/markers/HasManyRelationMarker.js +2 -2
- package/dist/production/markers/HasManyRelationMarker.js.map +1 -1
- package/dist/production/markers/HasOneRelationMarker.js +2 -2
- package/dist/production/markers/HasOneRelationMarker.js.map +1 -1
- package/dist/production/queryLanguage/CacheStore.js +1 -1
- package/dist/production/queryLanguage/CacheStore.js.map +1 -1
- package/dist/production/queryLanguage/MarkerFactory.js.map +1 -1
- package/dist/production/queryLanguage/Parser.js +9 -7
- package/dist/production/queryLanguage/Parser.js.map +1 -1
- package/dist/production/queryLanguage/QueryLanguage.js +19 -8
- package/dist/production/queryLanguage/QueryLanguage.js.map +1 -1
- package/dist/production/structures/BijectiveIndexedMap.js +3 -1
- package/dist/production/structures/BijectiveIndexedMap.js.map +1 -1
- package/dist/production/structures/LRUCache.js +1 -1
- package/dist/production/structures/LRUCache.js.map +1 -1
- package/dist/production/structures/WeakIdCache.js.map +1 -1
- package/dist/production/treeParameterHelpers/wrapFilterInHasOnes.js.map +1 -1
- package/dist/production/treeParameters/EntityCreationParameters.js +1 -0
- package/dist/production/treeParameters/EntityCreationParameters.js.map +1 -1
- package/dist/production/treeParameters/LeafField.js.map +1 -1
- package/dist/production/utils/Hashing.js +1 -0
- package/dist/production/utils/Hashing.js.map +1 -1
- package/dist/types/accessorPropagation/BindingOperationsContext.d.ts +0 -1
- package/dist/types/accessorPropagation/BindingOperationsContext.d.ts.map +1 -1
- package/dist/types/accessorPropagation/EntityKeyContext.d.ts +0 -1
- package/dist/types/accessorPropagation/EntityKeyContext.d.ts.map +1 -1
- package/dist/types/accessorPropagation/TreeRootIdContext.d.ts +0 -1
- package/dist/types/accessorPropagation/TreeRootIdContext.d.ts.map +1 -1
- package/dist/types/accessorSorting/SetOrderFieldOnCreate.d.ts +0 -1
- package/dist/types/accessorSorting/SetOrderFieldOnCreate.d.ts.map +1 -1
- package/dist/types/accessorTree/AccessorTree.d.ts +7 -4
- package/dist/types/accessorTree/AccessorTree.d.ts.map +1 -1
- package/dist/types/accessorTree/AccessorTreeStateContext.d.ts +0 -1
- package/dist/types/accessorTree/AccessorTreeStateContext.d.ts.map +1 -1
- package/dist/types/accessorTree/DirtinessContext.d.ts +0 -1
- package/dist/types/accessorTree/DirtinessContext.d.ts.map +1 -1
- package/dist/types/accessorTree/MutationStateContext.d.ts +0 -1
- package/dist/types/accessorTree/MutationStateContext.d.ts.map +1 -1
- package/dist/types/coreComponents/DataBindingProvider.d.ts +10 -0
- package/dist/types/coreComponents/DataBindingProvider.d.ts.map +1 -1
- package/dist/types/coreComponents/Entity.d.ts +3 -0
- package/dist/types/coreComponents/Entity.d.ts.map +1 -1
- package/dist/types/coreComponents/EntityList.d.ts +3 -0
- package/dist/types/coreComponents/EntityList.d.ts.map +1 -1
- package/dist/types/coreComponents/EntityListSubTree.d.ts +10 -0
- package/dist/types/coreComponents/EntityListSubTree.d.ts.map +1 -1
- package/dist/types/coreComponents/EntitySubTree.d.ts +10 -0
- package/dist/types/coreComponents/EntitySubTree.d.ts.map +1 -1
- package/dist/types/coreComponents/Field.d.ts +3 -0
- package/dist/types/coreComponents/Field.d.ts.map +1 -1
- package/dist/types/coreComponents/HasMany.d.ts +3 -0
- package/dist/types/coreComponents/HasMany.d.ts.map +1 -1
- package/dist/types/coreComponents/HasOne.d.ts +3 -0
- package/dist/types/coreComponents/HasOne.d.ts.map +1 -1
- package/dist/types/coreComponents/ParentEntity.d.ts +3 -0
- package/dist/types/coreComponents/ParentEntity.d.ts.map +1 -1
- package/dist/types/helperComponents/DeferredSubTrees.d.ts +3 -0
- package/dist/types/helperComponents/DeferredSubTrees.d.ts.map +1 -1
- package/dist/types/helperComponents/EntityView.d.ts +3 -0
- package/dist/types/helperComponents/EntityView.d.ts.map +1 -1
- package/dist/types/helperComponents/FieldView.d.ts +13 -0
- package/dist/types/helperComponents/FieldView.d.ts.map +1 -1
- package/dist/types/helperComponents/If.d.ts +3 -0
- package/dist/types/helperComponents/If.d.ts.map +1 -1
- package/dist/types/helperComponents/StaticRender.d.ts +3 -0
- package/dist/types/helperComponents/StaticRender.d.ts.map +1 -1
- package/dist/types/helperComponents/SugaredField.d.ts +3 -0
- package/dist/types/helperComponents/SugaredField.d.ts.map +1 -1
- package/dist/types/treeParameters/FieldEventListeners.d.ts +5 -2
- package/dist/types/treeParameters/FieldEventListeners.d.ts.map +1 -1
- package/dist/types/treeParameters/LeafField.d.ts +2 -2
- package/dist/types/treeParameters/LeafField.d.ts.map +1 -1
- package/dist/types/treeParameters/QualifiedFieldList.d.ts +7 -8
- package/dist/types/treeParameters/QualifiedFieldList.d.ts.map +1 -1
- package/dist/types/treeParameters/RelativeSingleField.d.ts +8 -8
- package/dist/types/treeParameters/RelativeSingleField.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -6
- package/src/accessorTree/AccessorTree.tsx +4 -1
- package/src/coreComponents/DataBindingProvider.tsx +10 -0
- package/src/coreComponents/Entity.tsx +3 -0
- package/src/coreComponents/EntityList.tsx +3 -0
- package/src/coreComponents/EntityListSubTree.tsx +10 -0
- package/src/coreComponents/EntitySubTree.tsx +10 -0
- package/src/coreComponents/Field.tsx +3 -0
- package/src/coreComponents/HasMany.tsx +3 -0
- package/src/coreComponents/HasOne.tsx +3 -0
- package/src/coreComponents/ParentEntity.tsx +3 -0
- package/src/helperComponents/DeferredSubTrees.tsx +3 -0
- package/src/helperComponents/EntityView.tsx +3 -0
- package/src/helperComponents/FieldView.tsx +13 -0
- package/src/helperComponents/If.tsx +3 -0
- package/src/helperComponents/StaticRender.tsx +3 -0
- package/src/helperComponents/SugaredField.tsx +3 -0
- package/src/helperComponents/helpers/evaluateCondition.ts +1 -1
- package/src/treeParameters/FieldEventListeners.ts +15 -5
- package/src/treeParameters/LeafField.ts +6 -4
- package/src/treeParameters/QualifiedFieldList.ts +24 -17
- package/src/treeParameters/RelativeSingleField.ts +19 -12
- package/src/ambient.d.ts +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeAugmenter.js","sources":["../../../src/core/TreeAugmenter.ts"],"sourcesContent":["import {\n\tClientGeneratedUuid,\n\tEntityListPersistedData,\n\tReceivedDataTree,\n\tRuntimeId,\n\tServerId,\n\tUnpersistedEntityDummyId,\n} from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { EntityId, PlaceholderName, TreeRootId } from '../treeParameters'\nimport { assert, assertNever } from '../utils'\nimport { EventManager } from './EventManager'\nimport { OperationsHelpers } from './operations/OperationsHelpers'\nimport type { EntityListState, EntityRealmState, EntityRealmStateStub, RootStateNode } from './state'\nimport type { StateInitializer } from './StateInitializer'\nimport type { TreeStore } from './TreeStore'\nimport { SubMutationOperation } from './MutationGenerator'\n\nexport class TreeAugmenter {\n\tpublic constructor(\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly skipStateUpdateAfterPersist: boolean = false,\n\t) {}\n\n\tpublic extendPersistedData(newPersistedData: ReceivedDataTree, markerTree: MarkerTreeRoot) {\n\t\t// TODO this doesn't yet handle updates for entities whose persisted data just gets magically changed without notice.\n\t\tthis.treeStore.mergeInQueryResponse(newPersistedData, markerTree)\n\t}\n\n\tpublic extendTreeStates(newTreeId: TreeRootId | undefined, newMarkerTree: MarkerTreeRoot): void {\n\t\tconst subTreeStates: Map<PlaceholderName, RootStateNode> = new Map()\n\n\t\tthis.treeStore.markerTrees.set(newTreeId, newMarkerTree)\n\t\tthis.treeStore.subTreeStatesByRoot.set(newTreeId, subTreeStates)\n\n\t\tfor (const [placeholderName, newSubTreeMarker] of newMarkerTree.subTrees) {\n\t\t\tconst newState = this.stateInitializer.initializeSubTree(newSubTreeMarker)\n\t\t\tsubTreeStates.set(placeholderName, newState)\n\t\t}\n\t}\n\n\tpublic updatePersistedData(response: ReceivedDataTree, operations: SubMutationOperation[]) {\n\t\tthis.treeStore.mergeInMutationResponse(response, operations)\n\t\tif (this.skipStateUpdateAfterPersist) {\n\t\t\treturn\n\t\t}\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\t\t// for (const rootPlaceholder in response) {\n\t\t\t\t// \tconst rootState = rootStates.get(rootPlaceholder)\n\t\t\t\t//\n\t\t\t\t// \tif (rootState === undefined) {\n\t\t\t\t// \t\tcontinue\n\t\t\t\t// \t}\n\t\t\t\t// TODO the above would be better, only refreshing roots which participated in the mutation. However, due to\n\t\t\t\t// \thow mutations are currently generated, we cannot assume that only roots present in the response need\n\t\t\t\t// \trefreshed. So we just refresh all.\n\t\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\t\tconst rootData = this.treeStore.subTreePersistedData.get(rootPlaceholder)\n\n\t\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\t\tif (!(rootData instanceof Set)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateEntityListPersistedData(rootState, rootData)\n\t\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\t\tif (rootData !== undefined && !(rootData instanceof ServerId)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateRealmIdIfNecessary(rootState, rootData)\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(rootState)\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn assertNever(rootState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic resetCreatingSubTrees() {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\tassert(rootState.blueprint.parent === undefined)\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst changesCount = rootState.unpersistedChangesCount\n\n\t\t\t\t\t// Just emptying the list. But the list itself can stay.\n\t\t\t\t\tfor (const childState of rootState.children.values()) {\n\t\t\t\t\t\tthis.treeStore.disposeOfRealm(childState)\n\t\t\t\t\t}\n\t\t\t\t\trootState.accessor = undefined\n\t\t\t\t\trootState.children.clear()\n\t\t\t\t\trootState.childrenWithPendingUpdates?.clear()\n\t\t\t\t\trootState.errors = undefined\n\t\t\t\t\trootState.plannedRemovals?.clear()\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(\n\t\t\t\t\t\trootState,\n\t\t\t\t\t\tchangesCount ? -1 * changesCount : EventManager.NO_CHANGES_DIFFERENCE,\n\t\t\t\t\t)\n\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\tassert(rootState.blueprint.parent === undefined)\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst presentListeners = rootState.eventListeners\n\t\t\t\t\tthis.treeStore.disposeOfRealm(rootState)\n\n\t\t\t\t\t// It's crucial to delete the persisted data before we re-initialize so that we get a fresh, new entity.\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst newRootState = this.stateInitializer.initializeSubTree(rootState.blueprint.marker)\n\n\t\t\t\t\t// We preserve the previous listeners but purge some of them.\n\t\t\t\t\tnewRootState.eventListeners = presentListeners\n\t\t\t\t\tOperationsHelpers.purgeStaleListenersAfterIdChange(newRootState as EntityRealmState)\n\n\t\t\t\t\trootStates.set(rootPlaceholder, newRootState)\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(newRootState, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(rootState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateRealmIdIfNecessary(\n\t\trealm: EntityRealmState | EntityRealmStateStub,\n\t\tnewId: ServerId | undefined | null,\n\t) {\n\t\tconst currentId = realm.entity.id\n\t\tlet idToChangeTo: RuntimeId | undefined = undefined\n\n\t\tif (currentId instanceof ServerId) {\n\t\t\tif (newId === undefined || newId === null) {\n\t\t\t\tidToChangeTo = new UnpersistedEntityDummyId()\n\t\t\t} else if (currentId.value !== newId.value) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else if (currentId instanceof ClientGeneratedUuid) {\n\t\t\tidToChangeTo = newId ?? new UnpersistedEntityDummyId()\n\t\t} else if (currentId instanceof UnpersistedEntityDummyId) {\n\t\t\tif (newId) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else {\n\t\t\treturn assertNever(currentId)\n\t\t}\n\t\tif (idToChangeTo) {\n\t\t\tOperationsHelpers.changeRealmId(this.treeStore, this.eventManager, this.stateInitializer, realm, idToChangeTo)\n\t\t}\n\t}\n\n\tprivate updateEntityRealmPersistedData(realm: EntityRealmState) {\n\t\tconst realmId = realm.entity.id\n\t\tconst persistedData = realmId.existsOnServer ? this.treeStore.persistedEntityData.get(realmId.uniqueValue) : undefined\n\n\t\tfor (const [placeholderName, child] of realm.children) {\n\t\t\tconst childData = persistedData?.get(placeholderName)\n\n\t\t\tswitch (child.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (childData instanceof ServerId || childData instanceof Set) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (child.persistedValue !== childData) {\n\t\t\t\t\t\tconst shouldChangeBothValues = child.persistedValue === child.value\n\n\t\t\t\t\t\tchild.persistedValue = childData\n\t\t\t\t\t\tif (shouldChangeBothValues) {\n\t\t\t\t\t\t\tchild.value = childData ?? null\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.eventManager.registerJustUpdated(child, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\tif (!(childData instanceof ServerId) && childData !== undefined && childData !== null) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateRealmIdIfNecessary(child, childData)\n\t\t\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (childData !== undefined && !(childData instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateEntityListPersistedData(child, childData ?? new Set()) // TODO!!\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn assertNever(child)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateEntityListPersistedData(state: EntityListState, newPersistedIds: EntityListPersistedData) {\n\t\tconst persistedWithoutState: EntityId[] = []\n\n\t\t// TODO This isn't particularly efficient. We should probably use something like diff-sequence here.\n\n\t\tfor (const persistedId of newPersistedIds) {\n\t\t\tif (!state.children.has(persistedId)) {\n\t\t\t\tpersistedWithoutState.push(persistedId)\n\t\t\t}\n\t\t}\n\t\tfor (const [stateId, child] of state.children) {\n\t\t\tconst childRuntimeId = child.entity.id\n\t\t\tif (!newPersistedIds.has(stateId)) {\n\t\t\t\tif (\n\t\t\t\t\t// It's a uuid but it's not among the persisted so either it got deleted/disconnected or the client-side\n\t\t\t\t\t// id generation didn't quite pan out.\n\t\t\t\t\tchildRuntimeId instanceof ServerId ||\n\t\t\t\t\tchildRuntimeId instanceof ClientGeneratedUuid ||\n\t\t\t\t\t// No persisted entity id to allocate to this so that's a goodbye.\n\t\t\t\t\tpersistedWithoutState.length === 0\n\t\t\t\t) {\n\t\t\t\t\tstate.getAccessor().disconnectEntity(child.getAccessor())\n\t\t\t\t\tcontinue\n\t\t\t\t} else {\n\t\t\t\t\tconst drawnId = persistedWithoutState.shift()!\n\t\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\t\tthis.treeStore,\n\t\t\t\t\t\tthis.eventManager,\n\t\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\t\tchild,\n\t\t\t\t\t\tnew ServerId(drawnId, child.entity.entityName),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (childRuntimeId instanceof ClientGeneratedUuid) {\n\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\tthis.treeStore,\n\t\t\t\t\tthis.eventManager,\n\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\tchild,\n\t\t\t\t\tnew ServerId(childRuntimeId.value, child.entity.entityName),\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t}\n\t\t}\n\t\tfor (const unclaimedPersistedId of persistedWithoutState) {\n\t\t\tthis.stateInitializer.initializeEntityRealm(new ServerId(unclaimedPersistedId, state.entityName), state.entityName, {\n\t\t\t\ttype: 'listEntity',\n\t\t\t\tparent: state,\n\t\t\t})\n\t\t}\n\t\t// All that remains now is the order.\n\t\tstate.children.changeKeyOrder(newPersistedIds)\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAmBO,MAAM,cAAc;AAAA,EACnB,YACW,cACA,kBACA,WACA,8BAAuC,OACvD;AAJgB,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AACA,SAAA,8BAAA;AAAA,EACf;AAAA,EAEI,oBAAoB,kBAAoC,YAA4B;AAErF,SAAA,UAAU,qBAAqB,kBAAkB,UAAU;AAAA,EACjE;AAAA,EAEO,iBAAiB,WAAmC,eAAqC;AACzF,UAAA,oCAAyD;AAE/D,SAAK,UAAU,YAAY,IAAI,WAAW,aAAa;AACvD,SAAK,UAAU,oBAAoB,IAAI,WAAW,aAAa;AAE/D,eAAW,CAAC,iBAAiB,gBAAgB,KAAK,cAAc,UAAU;AACzE,YAAM,WAAW,KAAK,iBAAiB,kBAAkB,gBAAgB;AAC3D,oBAAA,IAAI,iBAAiB,QAAQ;AAAA,IAC5C;AAAA,EACD;AAAA,EAEO,oBAAoB,UAA4B,YAAoC;AACrF,SAAA,UAAU,wBAAwB,UAAU,UAAU;AAC3D,QAAI,KAAK,6BAA6B;AACrC;AAAA,IACD;AACK,SAAA,aAAa,gBAAgB,MAAM;AACvC,iBAAW,cAAc,KAAK,UAAU,oBAAoB,UAAU;AAUrE,mBAAW,CAAC,iBAAiB,SAAS,KAAK,YAAY;AACtD,gBAAM,WAAW,KAAK,UAAU,qBAAqB,IAAI,eAAe;AAEpE,cAAA,UAAU,SAAS,cAAc;A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AA0B,qBAAqB;AACvC,0BAAA;AAAA,UACjB,KAAK;AAAA,UACL,KAAK;AAAA,UACL,KAAK;AAAA,UACL;AAAA,UACA,IAAI,SAAS,eAAe,OAAO,MAAM,OAAO,UAAU;AAAA,QAAA;AAAA,MAE5D;AACI,UAAA,MAAM,SAAS,eAAe;AACjC,aAAK,+BAA+B,KAAK;AAAA,MAC1C;AAAA,IACD;AACA,eAAW,wBAAwB,uBAAuB;AACpD,WAAA,iBAAiB,sBAAsB,IAAI,SAAS,sBAAsB,MAAM,UAAU,GAAG,MAAM,YAAY;AAAA,QACnH,MAAM;AAAA,QACN,QAAQ;AAAA,MAAA,CACR;AAAA,IACF;AAEM,UAAA,SAAS,eAAe,eAAe;AAAA,EAC9C;AACD;"}
|
|
1
|
+
{"version":3,"file":"TreeAugmenter.js","sources":["../../../src/core/TreeAugmenter.ts"],"sourcesContent":["import {\n\tClientGeneratedUuid,\n\tEntityListPersistedData,\n\tReceivedDataTree,\n\tRuntimeId,\n\tServerId,\n\tUnpersistedEntityDummyId,\n} from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { EntityId, PlaceholderName, TreeRootId } from '../treeParameters'\nimport { assert, assertNever } from '../utils'\nimport { EventManager } from './EventManager'\nimport { OperationsHelpers } from './operations/OperationsHelpers'\nimport type { EntityListState, EntityRealmState, EntityRealmStateStub, RootStateNode } from './state'\nimport type { StateInitializer } from './StateInitializer'\nimport type { TreeStore } from './TreeStore'\nimport { SubMutationOperation } from './MutationGenerator'\n\nexport class TreeAugmenter {\n\tpublic constructor(\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly skipStateUpdateAfterPersist: boolean = false,\n\t) {}\n\n\tpublic extendPersistedData(newPersistedData: ReceivedDataTree, markerTree: MarkerTreeRoot) {\n\t\t// TODO this doesn't yet handle updates for entities whose persisted data just gets magically changed without notice.\n\t\tthis.treeStore.mergeInQueryResponse(newPersistedData, markerTree)\n\t}\n\n\tpublic extendTreeStates(newTreeId: TreeRootId | undefined, newMarkerTree: MarkerTreeRoot): void {\n\t\tconst subTreeStates: Map<PlaceholderName, RootStateNode> = new Map()\n\n\t\tthis.treeStore.markerTrees.set(newTreeId, newMarkerTree)\n\t\tthis.treeStore.subTreeStatesByRoot.set(newTreeId, subTreeStates)\n\n\t\tfor (const [placeholderName, newSubTreeMarker] of newMarkerTree.subTrees) {\n\t\t\tconst newState = this.stateInitializer.initializeSubTree(newSubTreeMarker)\n\t\t\tsubTreeStates.set(placeholderName, newState)\n\t\t}\n\t}\n\n\tpublic updatePersistedData(response: ReceivedDataTree, operations: SubMutationOperation[]) {\n\t\tthis.treeStore.mergeInMutationResponse(response, operations)\n\t\tif (this.skipStateUpdateAfterPersist) {\n\t\t\treturn\n\t\t}\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\t\t// for (const rootPlaceholder in response) {\n\t\t\t\t// \tconst rootState = rootStates.get(rootPlaceholder)\n\t\t\t\t//\n\t\t\t\t// \tif (rootState === undefined) {\n\t\t\t\t// \t\tcontinue\n\t\t\t\t// \t}\n\t\t\t\t// TODO the above would be better, only refreshing roots which participated in the mutation. However, due to\n\t\t\t\t// \thow mutations are currently generated, we cannot assume that only roots present in the response need\n\t\t\t\t// \trefreshed. So we just refresh all.\n\t\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\t\tconst rootData = this.treeStore.subTreePersistedData.get(rootPlaceholder)\n\n\t\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\t\tif (!(rootData instanceof Set)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateEntityListPersistedData(rootState, rootData)\n\t\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\t\tif (rootData !== undefined && !(rootData instanceof ServerId)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateRealmIdIfNecessary(rootState, rootData)\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(rootState)\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn assertNever(rootState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic resetCreatingSubTrees() {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\tassert(rootState.blueprint.parent === undefined)\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst changesCount = rootState.unpersistedChangesCount\n\n\t\t\t\t\t// Just emptying the list. But the list itself can stay.\n\t\t\t\t\tfor (const childState of rootState.children.values()) {\n\t\t\t\t\t\tthis.treeStore.disposeOfRealm(childState)\n\t\t\t\t\t}\n\t\t\t\t\trootState.accessor = undefined\n\t\t\t\t\trootState.children.clear()\n\t\t\t\t\trootState.childrenWithPendingUpdates?.clear()\n\t\t\t\t\trootState.errors = undefined\n\t\t\t\t\trootState.plannedRemovals?.clear()\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(\n\t\t\t\t\t\trootState,\n\t\t\t\t\t\tchangesCount ? -1 * changesCount : EventManager.NO_CHANGES_DIFFERENCE,\n\t\t\t\t\t)\n\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\tassert(rootState.blueprint.parent === undefined)\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst presentListeners = rootState.eventListeners\n\t\t\t\t\tthis.treeStore.disposeOfRealm(rootState)\n\n\t\t\t\t\t// It's crucial to delete the persisted data before we re-initialize so that we get a fresh, new entity.\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst newRootState = this.stateInitializer.initializeSubTree(rootState.blueprint.marker)\n\n\t\t\t\t\t// We preserve the previous listeners but purge some of them.\n\t\t\t\t\tnewRootState.eventListeners = presentListeners\n\t\t\t\t\tOperationsHelpers.purgeStaleListenersAfterIdChange(newRootState as EntityRealmState)\n\n\t\t\t\t\trootStates.set(rootPlaceholder, newRootState)\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(newRootState, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(rootState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateRealmIdIfNecessary(\n\t\trealm: EntityRealmState | EntityRealmStateStub,\n\t\tnewId: ServerId | undefined | null,\n\t) {\n\t\tconst currentId = realm.entity.id\n\t\tlet idToChangeTo: RuntimeId | undefined = undefined\n\n\t\tif (currentId instanceof ServerId) {\n\t\t\tif (newId === undefined || newId === null) {\n\t\t\t\tidToChangeTo = new UnpersistedEntityDummyId()\n\t\t\t} else if (currentId.value !== newId.value) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else if (currentId instanceof ClientGeneratedUuid) {\n\t\t\tidToChangeTo = newId ?? new UnpersistedEntityDummyId()\n\t\t} else if (currentId instanceof UnpersistedEntityDummyId) {\n\t\t\tif (newId) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else {\n\t\t\treturn assertNever(currentId)\n\t\t}\n\t\tif (idToChangeTo) {\n\t\t\tOperationsHelpers.changeRealmId(this.treeStore, this.eventManager, this.stateInitializer, realm, idToChangeTo)\n\t\t}\n\t}\n\n\tprivate updateEntityRealmPersistedData(realm: EntityRealmState) {\n\t\tconst realmId = realm.entity.id\n\t\tconst persistedData = realmId.existsOnServer ? this.treeStore.persistedEntityData.get(realmId.uniqueValue) : undefined\n\n\t\tfor (const [placeholderName, child] of realm.children) {\n\t\t\tconst childData = persistedData?.get(placeholderName)\n\n\t\t\tswitch (child.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (childData instanceof ServerId || childData instanceof Set) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (child.persistedValue !== childData) {\n\t\t\t\t\t\tconst shouldChangeBothValues = child.persistedValue === child.value\n\n\t\t\t\t\t\tchild.persistedValue = childData\n\t\t\t\t\t\tif (shouldChangeBothValues) {\n\t\t\t\t\t\t\tchild.value = childData ?? null\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.eventManager.registerJustUpdated(child, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\tif (!(childData instanceof ServerId) && childData !== undefined && childData !== null) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateRealmIdIfNecessary(child, childData)\n\t\t\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (childData !== undefined && !(childData instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateEntityListPersistedData(child, childData ?? new Set()) // TODO!!\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn assertNever(child)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateEntityListPersistedData(state: EntityListState, newPersistedIds: EntityListPersistedData) {\n\t\tconst persistedWithoutState: EntityId[] = []\n\n\t\t// TODO This isn't particularly efficient. We should probably use something like diff-sequence here.\n\n\t\tfor (const persistedId of newPersistedIds) {\n\t\t\tif (!state.children.has(persistedId)) {\n\t\t\t\tpersistedWithoutState.push(persistedId)\n\t\t\t}\n\t\t}\n\t\tfor (const [stateId, child] of state.children) {\n\t\t\tconst childRuntimeId = child.entity.id\n\t\t\tif (!newPersistedIds.has(stateId)) {\n\t\t\t\tif (\n\t\t\t\t\t// It's a uuid but it's not among the persisted so either it got deleted/disconnected or the client-side\n\t\t\t\t\t// id generation didn't quite pan out.\n\t\t\t\t\tchildRuntimeId instanceof ServerId ||\n\t\t\t\t\tchildRuntimeId instanceof ClientGeneratedUuid ||\n\t\t\t\t\t// No persisted entity id to allocate to this so that's a goodbye.\n\t\t\t\t\tpersistedWithoutState.length === 0\n\t\t\t\t) {\n\t\t\t\t\tstate.getAccessor().disconnectEntity(child.getAccessor())\n\t\t\t\t\tcontinue\n\t\t\t\t} else {\n\t\t\t\t\tconst drawnId = persistedWithoutState.shift()!\n\t\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\t\tthis.treeStore,\n\t\t\t\t\t\tthis.eventManager,\n\t\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\t\tchild,\n\t\t\t\t\t\tnew ServerId(drawnId, child.entity.entityName),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (childRuntimeId instanceof ClientGeneratedUuid) {\n\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\tthis.treeStore,\n\t\t\t\t\tthis.eventManager,\n\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\tchild,\n\t\t\t\t\tnew ServerId(childRuntimeId.value, child.entity.entityName),\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t}\n\t\t}\n\t\tfor (const unclaimedPersistedId of persistedWithoutState) {\n\t\t\tthis.stateInitializer.initializeEntityRealm(new ServerId(unclaimedPersistedId, state.entityName), state.entityName, {\n\t\t\t\ttype: 'listEntity',\n\t\t\t\tparent: state,\n\t\t\t})\n\t\t}\n\t\t// All that remains now is the order.\n\t\tstate.children.changeKeyOrder(newPersistedIds)\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAmBO,MAAM,cAAc;AAAA,EACnB,YACW,cACA,kBACA,WACA,8BAAuC,OACvD;AAJgB,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AACA,SAAA,8BAAA;AAAA,EACf;AAAA,EAEI,oBAAoB,kBAAoC,YAA4B;AAErF,SAAA,UAAU,qBAAqB,kBAAkB,UAAU;AAAA,EACjE;AAAA,EAEO,iBAAiB,WAAmC,eAAqC;AACzF,UAAA,oCAAyD;AAE/D,SAAK,UAAU,YAAY,IAAI,WAAW,aAAa;AACvD,SAAK,UAAU,oBAAoB,IAAI,WAAW,aAAa;AAE/D,eAAW,CAAC,iBAAiB,gBAAgB,KAAK,cAAc,UAAU;AACzE,YAAM,WAAW,KAAK,iBAAiB,kBAAkB,gBAAgB;AAC3D,oBAAA,IAAI,iBAAiB,QAAQ;AAAA,IAC5C;AAAA,EACD;AAAA,EAEO,oBAAoB,UAA4B,YAAoC;AACrF,SAAA,UAAU,wBAAwB,UAAU,UAAU;AAC3D,QAAI,KAAK,6BAA6B;AACrC;AAAA,IACD;AACK,SAAA,aAAa,gBAAgB,MAAM;AACvC,iBAAW,cAAc,KAAK,UAAU,oBAAoB,UAAU;AAUrE,mBAAW,CAAC,iBAAiB,SAAS,KAAK,YAAY;AACtD,gBAAM,WAAW,KAAK,UAAU,qBAAqB,IAAI,eAAe;AAEpE,cAAA,UAAU,SAAS,cAAc;AAChC,gBAAA,EAAE,oBAAoB,MAAM;AAC/B;AAAA,YACD;AACK,iBAAA,8BAA8B,WAAW,QAAQ;AAAA,UAAA,WAC5C,UAAU,SAAS,eAAe;AAC5C,gBAAI,aAAa,UAAa,EAAE,oBAAoB,WAAW;AAC9D;AAAA,YACD;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AA,MAE5D;AACI,UAAA,MAAM,SAAS,eAAe;AACjC,aAAK,+BAA+B,KAAK;AAAA,MAC1C;AAAA,IACD;AACA,eAAW,wBAAwB,uBAAuB;AACpD,WAAA,iBAAiB,sBAAsB,IAAI,SAAS,sBAAsB,MAAM,UAAU,GAAG,MAAM,YAAY;AAAA,QACnH,MAAM;AAAA,QACN,QAAQ;AAAA,MAAA,CACR;AAAA,IACF;AAEM,UAAA,SAAS,eAAe,eAAe;AAAA,EAC9C;AACD;"}
|
|
@@ -3,12 +3,15 @@ import { BindingError } from "../BindingError.js";
|
|
|
3
3
|
class TreeParameterMerger {
|
|
4
4
|
static mergeHasOneRelationsWithSamePlaceholders(original, fresh) {
|
|
5
5
|
return {
|
|
6
|
+
// Encoded within the placeholder
|
|
6
7
|
field: original.field,
|
|
7
8
|
filter: original.filter,
|
|
8
9
|
reducedBy: original.reducedBy,
|
|
10
|
+
// Not encoded within the placeholder
|
|
9
11
|
expectedMutation: this.mergeExpectedRelationMutation(original.expectedMutation, fresh.expectedMutation),
|
|
10
12
|
setOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),
|
|
11
13
|
isNonbearing: original.isNonbearing && fresh.isNonbearing,
|
|
14
|
+
// forceCreation: original.forceCreation || fresh.forceCreation,
|
|
12
15
|
eventListeners: this.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners)
|
|
13
16
|
};
|
|
14
17
|
}
|
|
@@ -19,15 +22,19 @@ class TreeParameterMerger {
|
|
|
19
22
|
);
|
|
20
23
|
}
|
|
21
24
|
return {
|
|
25
|
+
// Encoded within the placeholder
|
|
22
26
|
field: original.field,
|
|
23
27
|
filter: original.filter,
|
|
24
28
|
orderBy: original.orderBy,
|
|
25
29
|
offset: original.offset,
|
|
26
30
|
limit: original.limit,
|
|
31
|
+
// Not encoded within the placeholder
|
|
27
32
|
expectedMutation: this.mergeExpectedRelationMutation(original.expectedMutation, fresh.expectedMutation),
|
|
28
33
|
setOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),
|
|
34
|
+
// forceCreation: original.forceCreation || fresh.forceCreation,
|
|
29
35
|
isNonbearing: original.isNonbearing && fresh.isNonbearing,
|
|
30
36
|
initialEntityCount: original.initialEntityCount,
|
|
37
|
+
// Handled above
|
|
31
38
|
childEventListeners: this.mergeSingleEntityEventListeners(
|
|
32
39
|
original.childEventListeners,
|
|
33
40
|
fresh.childEventListeners
|
|
@@ -38,26 +45,34 @@ class TreeParameterMerger {
|
|
|
38
45
|
static mergeEntitySubTreeParametersWithSamePlaceholders(original, fresh) {
|
|
39
46
|
if (original.isCreating) {
|
|
40
47
|
return {
|
|
48
|
+
// Encoded within the placeholder
|
|
41
49
|
isCreating: original.isCreating,
|
|
42
50
|
entityName: original.entityName,
|
|
51
|
+
// Not encoded within the placeholder
|
|
43
52
|
alias: this.mergeSubTreeAliases(original.alias, fresh.alias),
|
|
44
53
|
setOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),
|
|
54
|
+
// forceCreation: original.value.forceCreation || fresh.value.forceCreation,
|
|
45
55
|
expectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),
|
|
46
56
|
isNonbearing: original.isNonbearing && fresh.isNonbearing,
|
|
47
57
|
hasOneRelationPath: original.hasOneRelationPath,
|
|
58
|
+
// TODO this is completely wrong.
|
|
48
59
|
eventListeners: this.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners)
|
|
49
60
|
};
|
|
50
61
|
}
|
|
51
62
|
return {
|
|
63
|
+
// Encoded within the placeholder
|
|
52
64
|
isCreating: original.isCreating,
|
|
53
65
|
where: original.where,
|
|
54
66
|
entityName: original.entityName,
|
|
55
67
|
filter: original.filter,
|
|
68
|
+
// Not encoded within the placeholder
|
|
56
69
|
alias: this.mergeSubTreeAliases(original.alias, fresh.alias),
|
|
57
70
|
setOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),
|
|
71
|
+
// forceCreation: original.value.forceCreation || fresh.value.forceCreation,
|
|
58
72
|
expectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),
|
|
59
73
|
isNonbearing: original.isNonbearing && fresh.isNonbearing,
|
|
60
74
|
hasOneRelationPath: original.hasOneRelationPath,
|
|
75
|
+
// TODO this is completely wrong.
|
|
61
76
|
eventListeners: this.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners)
|
|
62
77
|
};
|
|
63
78
|
}
|
|
@@ -69,43 +84,54 @@ class TreeParameterMerger {
|
|
|
69
84
|
}
|
|
70
85
|
if (original.isCreating) {
|
|
71
86
|
return {
|
|
87
|
+
// Encoded within the placeholder
|
|
72
88
|
isCreating: original.isCreating,
|
|
73
89
|
entityName: original.entityName,
|
|
90
|
+
// Not encoded within the placeholder
|
|
74
91
|
alias: this.mergeSubTreeAliases(original.alias, fresh.alias),
|
|
75
92
|
setOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),
|
|
93
|
+
// forceCreation: original.value.forceCreation || fresh.value.forceCreation,
|
|
76
94
|
expectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),
|
|
77
95
|
isNonbearing: original.isNonbearing && fresh.isNonbearing,
|
|
78
96
|
hasOneRelationPath: original.hasOneRelationPath,
|
|
97
|
+
// TODO this is completely wrong.
|
|
79
98
|
childEventListeners: this.mergeSingleEntityEventListeners(
|
|
80
99
|
original.childEventListeners,
|
|
81
100
|
fresh.childEventListeners
|
|
82
101
|
),
|
|
83
102
|
eventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),
|
|
84
103
|
initialEntityCount: original.initialEntityCount
|
|
104
|
+
// Handled above
|
|
85
105
|
};
|
|
86
106
|
}
|
|
87
107
|
return {
|
|
108
|
+
// Encoded within the placeholder
|
|
88
109
|
isCreating: original.isCreating,
|
|
89
110
|
entityName: original.entityName,
|
|
90
111
|
filter: original.filter,
|
|
91
112
|
orderBy: original.orderBy,
|
|
92
113
|
offset: original.offset,
|
|
93
114
|
limit: original.limit,
|
|
115
|
+
// Not encoded within the placeholder
|
|
94
116
|
alias: this.mergeSubTreeAliases(original.alias, fresh.alias),
|
|
95
117
|
setOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),
|
|
118
|
+
// forceCreation: original.value.forceCreation || fresh.value.forceCreation,
|
|
96
119
|
expectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),
|
|
97
120
|
isNonbearing: original.isNonbearing && fresh.isNonbearing,
|
|
98
121
|
hasOneRelationPath: original.hasOneRelationPath,
|
|
122
|
+
// TODO this is completely wrong.
|
|
99
123
|
childEventListeners: this.mergeSingleEntityEventListeners(
|
|
100
124
|
original.childEventListeners,
|
|
101
125
|
fresh.childEventListeners
|
|
102
126
|
),
|
|
103
127
|
eventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),
|
|
104
128
|
initialEntityCount: original.initialEntityCount
|
|
129
|
+
// Handled above
|
|
105
130
|
};
|
|
106
131
|
}
|
|
107
132
|
static mergeEntityCreationParameters(original, fresh) {
|
|
108
133
|
return {
|
|
134
|
+
// forceCreation: original.forceCreation || fresh.forceCreation,
|
|
109
135
|
isNonbearing: original.isNonbearing && fresh.isNonbearing,
|
|
110
136
|
setOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate)
|
|
111
137
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeParameterMerger.js","sources":["../../../src/core/TreeParameterMerger.ts"],"sourcesContent":["import { GraphQlBuilder, Writable } from '@contember/client'\nimport { BindingError } from '../BindingError'\nimport type {\n\tAlias,\n\tEntityCreationParameters,\n\tEntityEventListenerStore,\n\tEntityListEventListenerStore,\n\tExpectedQualifiedEntityMutation,\n\tExpectedRelationMutation,\n\tHasManyRelation,\n\tHasOneRelation,\n\tParentEntityParameters,\n\tQualifiedEntityList,\n\tQualifiedSingleEntity,\n\tSetOnCreate,\n\tUnconstrainedQualifiedEntityList,\n\tUnconstrainedQualifiedSingleEntity,\n\tUniqueWhere,\n} from '../treeParameters'\n\nexport class TreeParameterMerger {\n\tpublic static mergeHasOneRelationsWithSamePlaceholders(\n\t\toriginal: HasOneRelation,\n\t\tfresh: HasOneRelation,\n\t): HasOneRelation {\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tfield: original.field,\n\t\t\tfilter: original.filter,\n\t\t\treducedBy: original.reducedBy,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\texpectedMutation: this.mergeExpectedRelationMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\t// forceCreation: original.forceCreation || fresh.forceCreation,\n\t\t\teventListeners: this.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeHasManyRelationsWithSamePlaceholders(\n\t\toriginal: HasManyRelation,\n\t\tfresh: HasManyRelation,\n\t): HasManyRelation {\n\t\tif (original.initialEntityCount !== fresh.initialEntityCount) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Detected hasMany relations on the same field '${original.field}' with different preferred initial ` +\n\t\t\t\t\t`entity counts: '${original.initialEntityCount}' and '${fresh.initialEntityCount}' respectively.`,\n\t\t\t)\n\t\t}\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tfield: original.field,\n\t\t\tfilter: original.filter,\n\t\t\torderBy: original.orderBy,\n\t\t\toffset: original.offset,\n\t\t\tlimit: original.limit,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\texpectedMutation: this.mergeExpectedRelationMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t// forceCreation: original.forceCreation || fresh.forceCreation,\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\tinitialEntityCount: original.initialEntityCount, // Handled above\n\t\t\tchildEventListeners: this.mergeSingleEntityEventListeners(\n\t\t\t\toriginal.childEventListeners,\n\t\t\t\tfresh.childEventListeners,\n\t\t\t),\n\t\t\teventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeEntitySubTreeParametersWithSamePlaceholders(\n\t\toriginal: QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity,\n\t\tfresh: QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity,\n\t): QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity {\n\t\tif (original.isCreating) {\n\t\t\treturn {\n\t\t\t\t// Encoded within the placeholder\n\t\t\t\tisCreating: original.isCreating,\n\t\t\t\tentityName: original.entityName,\n\n\t\t\t\t// Not encoded within the placeholder\n\t\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\t\teventListeners: this.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tisCreating: original.isCreating,\n\t\t\twhere: original.where,\n\t\t\tentityName: original.entityName,\n\t\t\tfilter: original.filter,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\teventListeners: this.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeEntityListSubTreeParametersWithSamePlaceholders(\n\t\toriginal: QualifiedEntityList | UnconstrainedQualifiedEntityList,\n\t\tfresh: QualifiedEntityList | UnconstrainedQualifiedEntityList,\n\t): QualifiedEntityList | UnconstrainedQualifiedEntityList {\n\t\tif (original.initialEntityCount !== fresh.initialEntityCount) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Detected sub trees of the same entity '${original.entityName}' with different preferred initial ` +\n\t\t\t\t\t`entity counts: '${original.initialEntityCount}' and '${fresh.initialEntityCount}' respectively.`,\n\t\t\t)\n\t\t}\n\n\t\tif (original.isCreating) {\n\t\t\treturn {\n\t\t\t\t// Encoded within the placeholder\n\t\t\t\tisCreating: original.isCreating,\n\t\t\t\tentityName: original.entityName,\n\n\t\t\t\t// Not encoded within the placeholder\n\t\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\t\tchildEventListeners: this.mergeSingleEntityEventListeners(\n\t\t\t\t\toriginal.childEventListeners,\n\t\t\t\t\tfresh.childEventListeners,\n\t\t\t\t),\n\t\t\t\teventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t\t\tinitialEntityCount: original.initialEntityCount, // Handled above\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tisCreating: original.isCreating,\n\t\t\tentityName: original.entityName,\n\t\t\tfilter: original.filter,\n\t\t\torderBy: original.orderBy,\n\t\t\toffset: original.offset,\n\t\t\tlimit: original.limit,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\tchildEventListeners: this.mergeSingleEntityEventListeners(\n\t\t\t\toriginal.childEventListeners,\n\t\t\t\tfresh.childEventListeners,\n\t\t\t),\n\t\t\teventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t\tinitialEntityCount: original.initialEntityCount, // Handled above\n\t\t}\n\t}\n\n\tpublic static mergeEntityCreationParameters(\n\t\toriginal: EntityCreationParameters,\n\t\tfresh: EntityCreationParameters,\n\t): EntityCreationParameters {\n\t\treturn {\n\t\t\t// forceCreation: original.forceCreation || fresh.forceCreation,\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t}\n\t}\n\n\tpublic static mergeSetOnCreate(original: SetOnCreate, fresh: SetOnCreate): SetOnCreate {\n\t\tif (original === undefined && fresh === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\tconst originalCopy: Writable<UniqueWhere> = { ...original }\n\n\t\tfor (const field in fresh) {\n\t\t\tif (field in originalCopy) {\n\t\t\t\tconst fromOriginal = originalCopy[field]\n\t\t\t\tconst fromFresh = fresh[field]\n\n\t\t\t\tif (fromOriginal instanceof GraphQlBuilder.GraphQlLiteral) {\n\t\t\t\t\tif (fromFresh instanceof GraphQlBuilder.GraphQlLiteral) {\n\t\t\t\t\t\tif (fromOriginal.value === fromFresh.value) {\n\t\t\t\t\t\t\t// Good, do nothing.\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (typeof fromOriginal === 'object') {\n\t\t\t\t\tif (fromFresh instanceof GraphQlBuilder.GraphQlLiteral) {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t} else if (typeof fromFresh === 'object') {\n\t\t\t\t\t\tconst merged = this.mergeSetOnCreate(fromOriginal, fromFresh)\n\t\t\t\t\t\tif (merged !== undefined) {\n\t\t\t\t\t\t\toriginalCopy[field] = merged\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (typeof fromFresh === 'string' || typeof fromFresh === 'number') {\n\t\t\t\t\tif (fromOriginal === fromFresh) {\n\t\t\t\t\t\t// Good, do nothing.\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t} else {\n\t\t\t\toriginalCopy[field] = fresh[field]\n\t\t\t}\n\t\t}\n\n\t\treturn originalCopy\n\t}\n\n\tprivate static mergeSets<T>(original: Set<T>, fresh: Set<T>): Set<T> {\n\t\tconst combinedSet = new Set(original)\n\t\tfor (const item of fresh) {\n\t\t\tcombinedSet.add(item)\n\t\t}\n\t\treturn combinedSet\n\t}\n\n\tpublic static mergeParentEntityParameters(\n\t\toriginal: ParentEntityParameters | undefined,\n\t\tfresh: ParentEntityParameters | undefined,\n\t): ParentEntityParameters | undefined {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\treturn {\n\t\t\teventListeners: TreeParameterMerger.mergeSingleEntityEventListeners(\n\t\t\t\toriginal.eventListeners,\n\t\t\t\tfresh.eventListeners,\n\t\t\t),\n\t\t}\n\t}\n\n\tpublic static mergeInParentEntity<\n\t\tOriginal extends Record<Key, EntityEventListenerStore | undefined>,\n\t\tKey extends keyof Original,\n\t>(original: Original, key: Key, parentEntity: ParentEntityParameters | undefined): Original {\n\t\tif (!parentEntity) {\n\t\t\treturn original\n\t\t}\n\n\t\treturn {\n\t\t\t...original,\n\t\t\t[key]: TreeParameterMerger.mergeSingleEntityEventListeners(original[key], parentEntity.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeSingleEntityEventListeners(\n\t\toriginal: EntityEventListenerStore | undefined,\n\t\tfresh: EntityEventListenerStore | undefined,\n\t): EntityEventListenerStore | undefined {\n\t\tif (original === undefined) {\n\t\t\tif (fresh === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn this.cloneSingleEntityEventListeners(fresh)\n\t\t}\n\n\t\tif (fresh === undefined) {\n\t\t\treturn this.cloneSingleEntityEventListeners(original)\n\t\t}\n\n\t\tconst store = this.cloneSingleEntityEventListeners(original)\n\t\tstore.append(fresh)\n\t\treturn store\n\t}\n\n\tpublic static mergeEntityListEventListeners(\n\t\toriginal: EntityListEventListenerStore | undefined,\n\t\tfresh: EntityListEventListenerStore | undefined,\n\t): EntityListEventListenerStore | undefined {\n\t\tif (original === undefined) {\n\t\t\tif (fresh === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn this.cloneEntityListEventListeners(fresh)\n\t\t}\n\n\t\tif (fresh === undefined) {\n\t\t\treturn this.cloneEntityListEventListeners(original)\n\t\t}\n\n\t\tconst store = this.cloneEntityListEventListeners(original)\n\t\tstore.append(fresh)\n\t\treturn store\n\t}\n\n\tpublic static cloneSingleEntityEventListeners(store: EntityEventListenerStore): EntityEventListenerStore {\n\t\t// TODO is intentional, that second clone is deep?\n\t\treturn store.clone()\n\t}\n\n\tpublic static cloneEntityListEventListeners(store: EntityListEventListenerStore): EntityListEventListenerStore {\n\t\treturn store.cloneDeep()\n\t}\n\n\tprivate static mergeExpectedRelationMutation(\n\t\toriginal: ExpectedRelationMutation,\n\t\tfresh: ExpectedRelationMutation,\n\t): ExpectedRelationMutation {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === 'none') {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === 'none') {\n\t\t\treturn original\n\t\t}\n\t\treturn 'anyMutation'\n\t}\n\n\tprivate static mergeExpectedQualifiedEntityMutation(\n\t\toriginal: ExpectedQualifiedEntityMutation,\n\t\tfresh: ExpectedQualifiedEntityMutation,\n\t): ExpectedQualifiedEntityMutation {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === 'none') {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === 'none') {\n\t\t\treturn original\n\t\t}\n\t\treturn 'anyMutation'\n\t}\n\n\tprivate static mergeSubTreeAliases(\n\t\toriginal: Set<Alias> | undefined,\n\t\tfresh: Set<Alias> | undefined,\n\t): Set<Alias> | undefined {\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\treturn this.mergeSets(original, fresh)\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AI,aAAa,OAAO;AAChB,aAAA;AAAA,IACR;AACA,QAAI,aAAa,QAAQ;AACjB,aAAA;AAAA,IACR;AACA,QAAI,UAAU,QAAQ;AACd,aAAA;AAAA,IACR;AACO,WAAA;AAAA,EACR;AAAA,EAEA,OAAe,oBACd,UACA,OACyB;AACzB,QAAI,aAAa,QAAW;AACpB,aAAA;AAAA,IACR;AACA,QAAI,UAAU,QAAW;AACjB,aAAA;AAAA,IACR;AACO,WAAA,KAAK,UAAU,UAAU,KAAK;AAAA,EACtC;AACD;"}
|
|
1
|
+
{"version":3,"file":"TreeParameterMerger.js","sources":["../../../src/core/TreeParameterMerger.ts"],"sourcesContent":["import { GraphQlBuilder, Writable } from '@contember/client'\nimport { BindingError } from '../BindingError'\nimport type {\n\tAlias,\n\tEntityCreationParameters,\n\tEntityEventListenerStore,\n\tEntityListEventListenerStore,\n\tExpectedQualifiedEntityMutation,\n\tExpectedRelationMutation,\n\tHasManyRelation,\n\tHasOneRelation,\n\tParentEntityParameters,\n\tQualifiedEntityList,\n\tQualifiedSingleEntity,\n\tSetOnCreate,\n\tUnconstrainedQualifiedEntityList,\n\tUnconstrainedQualifiedSingleEntity,\n\tUniqueWhere,\n} from '../treeParameters'\n\nexport class TreeParameterMerger {\n\tpublic static mergeHasOneRelationsWithSamePlaceholders(\n\t\toriginal: HasOneRelation,\n\t\tfresh: HasOneRelation,\n\t): HasOneRelation {\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tfield: original.field,\n\t\t\tfilter: original.filter,\n\t\t\treducedBy: original.reducedBy,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\texpectedMutation: this.mergeExpectedRelationMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\t// forceCreation: original.forceCreation || fresh.forceCreation,\n\t\t\teventListeners: this.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeHasManyRelationsWithSamePlaceholders(\n\t\toriginal: HasManyRelation,\n\t\tfresh: HasManyRelation,\n\t): HasManyRelation {\n\t\tif (original.initialEntityCount !== fresh.initialEntityCount) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Detected hasMany relations on the same field '${original.field}' with different preferred initial ` +\n\t\t\t\t\t`entity counts: '${original.initialEntityCount}' and '${fresh.initialEntityCount}' respectively.`,\n\t\t\t)\n\t\t}\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tfield: original.field,\n\t\t\tfilter: original.filter,\n\t\t\torderBy: original.orderBy,\n\t\t\toffset: original.offset,\n\t\t\tlimit: original.limit,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\texpectedMutation: this.mergeExpectedRelationMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t// forceCreation: original.forceCreation || fresh.forceCreation,\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\tinitialEntityCount: original.initialEntityCount, // Handled above\n\t\t\tchildEventListeners: this.mergeSingleEntityEventListeners(\n\t\t\t\toriginal.childEventListeners,\n\t\t\t\tfresh.childEventListeners,\n\t\t\t),\n\t\t\teventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeEntitySubTreeParametersWithSamePlaceholders(\n\t\toriginal: QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity,\n\t\tfresh: QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity,\n\t): QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity {\n\t\tif (original.isCreating) {\n\t\t\treturn {\n\t\t\t\t// Encoded within the placeholder\n\t\t\t\tisCreating: original.isCreating,\n\t\t\t\tentityName: original.entityName,\n\n\t\t\t\t// Not encoded within the placeholder\n\t\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\t\teventListeners: this.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tisCreating: original.isCreating,\n\t\t\twhere: original.where,\n\t\t\tentityName: original.entityName,\n\t\t\tfilter: original.filter,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\teventListeners: this.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeEntityListSubTreeParametersWithSamePlaceholders(\n\t\toriginal: QualifiedEntityList | UnconstrainedQualifiedEntityList,\n\t\tfresh: QualifiedEntityList | UnconstrainedQualifiedEntityList,\n\t): QualifiedEntityList | UnconstrainedQualifiedEntityList {\n\t\tif (original.initialEntityCount !== fresh.initialEntityCount) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Detected sub trees of the same entity '${original.entityName}' with different preferred initial ` +\n\t\t\t\t\t`entity counts: '${original.initialEntityCount}' and '${fresh.initialEntityCount}' respectively.`,\n\t\t\t)\n\t\t}\n\n\t\tif (original.isCreating) {\n\t\t\treturn {\n\t\t\t\t// Encoded within the placeholder\n\t\t\t\tisCreating: original.isCreating,\n\t\t\t\tentityName: original.entityName,\n\n\t\t\t\t// Not encoded within the placeholder\n\t\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\t\tchildEventListeners: this.mergeSingleEntityEventListeners(\n\t\t\t\t\toriginal.childEventListeners,\n\t\t\t\t\tfresh.childEventListeners,\n\t\t\t\t),\n\t\t\t\teventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t\t\tinitialEntityCount: original.initialEntityCount, // Handled above\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tisCreating: original.isCreating,\n\t\t\tentityName: original.entityName,\n\t\t\tfilter: original.filter,\n\t\t\torderBy: original.orderBy,\n\t\t\toffset: original.offset,\n\t\t\tlimit: original.limit,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\tchildEventListeners: this.mergeSingleEntityEventListeners(\n\t\t\t\toriginal.childEventListeners,\n\t\t\t\tfresh.childEventListeners,\n\t\t\t),\n\t\t\teventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t\tinitialEntityCount: original.initialEntityCount, // Handled above\n\t\t}\n\t}\n\n\tpublic static mergeEntityCreationParameters(\n\t\toriginal: EntityCreationParameters,\n\t\tfresh: EntityCreationParameters,\n\t): EntityCreationParameters {\n\t\treturn {\n\t\t\t// forceCreation: original.forceCreation || fresh.forceCreation,\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t}\n\t}\n\n\tpublic static mergeSetOnCreate(original: SetOnCreate, fresh: SetOnCreate): SetOnCreate {\n\t\tif (original === undefined && fresh === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\tconst originalCopy: Writable<UniqueWhere> = { ...original }\n\n\t\tfor (const field in fresh) {\n\t\t\tif (field in originalCopy) {\n\t\t\t\tconst fromOriginal = originalCopy[field]\n\t\t\t\tconst fromFresh = fresh[field]\n\n\t\t\t\tif (fromOriginal instanceof GraphQlBuilder.GraphQlLiteral) {\n\t\t\t\t\tif (fromFresh instanceof GraphQlBuilder.GraphQlLiteral) {\n\t\t\t\t\t\tif (fromOriginal.value === fromFresh.value) {\n\t\t\t\t\t\t\t// Good, do nothing.\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (typeof fromOriginal === 'object') {\n\t\t\t\t\tif (fromFresh instanceof GraphQlBuilder.GraphQlLiteral) {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t} else if (typeof fromFresh === 'object') {\n\t\t\t\t\t\tconst merged = this.mergeSetOnCreate(fromOriginal, fromFresh)\n\t\t\t\t\t\tif (merged !== undefined) {\n\t\t\t\t\t\t\toriginalCopy[field] = merged\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (typeof fromFresh === 'string' || typeof fromFresh === 'number') {\n\t\t\t\t\tif (fromOriginal === fromFresh) {\n\t\t\t\t\t\t// Good, do nothing.\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t} else {\n\t\t\t\toriginalCopy[field] = fresh[field]\n\t\t\t}\n\t\t}\n\n\t\treturn originalCopy\n\t}\n\n\tprivate static mergeSets<T>(original: Set<T>, fresh: Set<T>): Set<T> {\n\t\tconst combinedSet = new Set(original)\n\t\tfor (const item of fresh) {\n\t\t\tcombinedSet.add(item)\n\t\t}\n\t\treturn combinedSet\n\t}\n\n\tpublic static mergeParentEntityParameters(\n\t\toriginal: ParentEntityParameters | undefined,\n\t\tfresh: ParentEntityParameters | undefined,\n\t): ParentEntityParameters | undefined {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\treturn {\n\t\t\teventListeners: TreeParameterMerger.mergeSingleEntityEventListeners(\n\t\t\t\toriginal.eventListeners,\n\t\t\t\tfresh.eventListeners,\n\t\t\t),\n\t\t}\n\t}\n\n\tpublic static mergeInParentEntity<\n\t\tOriginal extends Record<Key, EntityEventListenerStore | undefined>,\n\t\tKey extends keyof Original,\n\t>(original: Original, key: Key, parentEntity: ParentEntityParameters | undefined): Original {\n\t\tif (!parentEntity) {\n\t\t\treturn original\n\t\t}\n\n\t\treturn {\n\t\t\t...original,\n\t\t\t[key]: TreeParameterMerger.mergeSingleEntityEventListeners(original[key], parentEntity.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeSingleEntityEventListeners(\n\t\toriginal: EntityEventListenerStore | undefined,\n\t\tfresh: EntityEventListenerStore | undefined,\n\t): EntityEventListenerStore | undefined {\n\t\tif (original === undefined) {\n\t\t\tif (fresh === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn this.cloneSingleEntityEventListeners(fresh)\n\t\t}\n\n\t\tif (fresh === undefined) {\n\t\t\treturn this.cloneSingleEntityEventListeners(original)\n\t\t}\n\n\t\tconst store = this.cloneSingleEntityEventListeners(original)\n\t\tstore.append(fresh)\n\t\treturn store\n\t}\n\n\tpublic static mergeEntityListEventListeners(\n\t\toriginal: EntityListEventListenerStore | undefined,\n\t\tfresh: EntityListEventListenerStore | undefined,\n\t): EntityListEventListenerStore | undefined {\n\t\tif (original === undefined) {\n\t\t\tif (fresh === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn this.cloneEntityListEventListeners(fresh)\n\t\t}\n\n\t\tif (fresh === undefined) {\n\t\t\treturn this.cloneEntityListEventListeners(original)\n\t\t}\n\n\t\tconst store = this.cloneEntityListEventListeners(original)\n\t\tstore.append(fresh)\n\t\treturn store\n\t}\n\n\tpublic static cloneSingleEntityEventListeners(store: EntityEventListenerStore): EntityEventListenerStore {\n\t\t// TODO is intentional, that second clone is deep?\n\t\treturn store.clone()\n\t}\n\n\tpublic static cloneEntityListEventListeners(store: EntityListEventListenerStore): EntityListEventListenerStore {\n\t\treturn store.cloneDeep()\n\t}\n\n\tprivate static mergeExpectedRelationMutation(\n\t\toriginal: ExpectedRelationMutation,\n\t\tfresh: ExpectedRelationMutation,\n\t): ExpectedRelationMutation {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === 'none') {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === 'none') {\n\t\t\treturn original\n\t\t}\n\t\treturn 'anyMutation'\n\t}\n\n\tprivate static mergeExpectedQualifiedEntityMutation(\n\t\toriginal: ExpectedQualifiedEntityMutation,\n\t\tfresh: ExpectedQualifiedEntityMutation,\n\t): ExpectedQualifiedEntityMutation {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === 'none') {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === 'none') {\n\t\t\treturn original\n\t\t}\n\t\treturn 'anyMutation'\n\t}\n\n\tprivate static mergeSubTreeAliases(\n\t\toriginal: Set<Alias> | undefined,\n\t\tfresh: Set<Alias> | undefined,\n\t): Set<Alias> | undefined {\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\treturn this.mergeSets(original, fresh)\n\t}\n}\n"],"names":[],"mappings":";;AAoBO,MAAM,oBAAoB;AAAA,EAChC,OAAc,yCACb,UACA,OACiB;AACV,WAAA;AAAA;AAAA,MAEN,OAAO,SAAS;AAAA,MAChB,QAAQ,SAAS;AAAA,MACjB,WAAW,SAAS;AAAA;AAAA,MAGpB,kBAAkB,KAAK,8BAA8B,SAAS,kBAAkB,MAAM,gBAAgB;AAAA,MACtG,aAAa,KAAK,iBAAiB,SAAS,aAAa,MAAM,WAAW;AAAA,MAC1E,cAAc,SAAS,gBAAgB,MAAM;AAAA;AAAA,MAE7C,gBAAgB,KAAK,gCAAgC,SAAS,gBAAgB,MAAM,cAAc;AAAA,IAAA;AAAA,EAEpG;AAAA,EAEA,OAAc,0CACb,UACA,OACkB;AACd,QAAA,SAAS,uBAAuB,MAAM,oBAAoB;AAC7D,YAAM,IAAI;AAAA,QACT,iDAAiD,SAAS,2DACtC,SAAS,4BAA4B,MAAM;AAAA,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
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
1
7
|
import { BindingError } from "../BindingError.js";
|
|
2
8
|
import { MarkerComparator } from "./MarkerComparator.js";
|
|
3
9
|
import { RequestResponseNormalizer } from "./RequestResponseNormalizer.js";
|
|
@@ -5,21 +11,17 @@ import { NormalizedPersistedData } from "../accessorTree/NormalizedPersistedData
|
|
|
5
11
|
import { assertNever } from "../utils/assertNever.js";
|
|
6
12
|
import { PlaceholderGenerator } from "../markers/PlaceholderGenerator.js";
|
|
7
13
|
import { QueryLanguage } from "../queryLanguage/QueryLanguage.js";
|
|
8
|
-
var __defProp = Object.defineProperty;
|
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
-
var __publicField = (obj, key, value) => {
|
|
11
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
12
|
-
return value;
|
|
13
|
-
};
|
|
14
14
|
const emptyEntityIdSet = /* @__PURE__ */ new Set();
|
|
15
15
|
class TreeStore {
|
|
16
16
|
constructor(_schema) {
|
|
17
|
-
this._schema = _schema;
|
|
18
17
|
__publicField(this, "entityStore", /* @__PURE__ */ new Map());
|
|
19
18
|
__publicField(this, "entityRealmStore", /* @__PURE__ */ new Map());
|
|
19
|
+
// This is tricky. We allow placeholder name duplicates, only the (TreeRootId, PlaceholderName) tuple is unique.
|
|
20
|
+
// This is useful when the tree is extended to contain a sub-tree with the same placeholder.
|
|
20
21
|
__publicField(this, "markerTrees", /* @__PURE__ */ new Map());
|
|
21
22
|
__publicField(this, "subTreeStatesByRoot", /* @__PURE__ */ new Map());
|
|
22
23
|
__publicField(this, "persistedData", new NormalizedPersistedData(/* @__PURE__ */ new Map(), /* @__PURE__ */ new Map()));
|
|
24
|
+
this._schema = _schema;
|
|
23
25
|
}
|
|
24
26
|
mergeInQueryResponse(response, markerTree) {
|
|
25
27
|
RequestResponseNormalizer.mergeInQueryResponse(this.persistedData, response, markerTree);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeStore.js","sources":["../../../src/core/TreeStore.ts"],"sourcesContent":["import {\n\tNormalizedPersistedData,\n\tPersistedEntityDataStore,\n\tReceivedDataTree,\n\tSubTreeDataStore,\n\tUniqueEntityId,\n} from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { Environment } from '../dao'\nimport { MarkerTreeRoot, PlaceholderGenerator } from '../markers'\nimport { QueryLanguage } from '../queryLanguage'\nimport type {\n\tAlias,\n\tEntityId,\n\tEntityName,\n\tEntityRealmKey,\n\tFieldName,\n\tPlaceholderName,\n\tSugaredQualifiedEntityList,\n\tSugaredQualifiedSingleEntity,\n\tSugaredUnconstrainedQualifiedEntityList,\n\tSugaredUnconstrainedQualifiedSingleEntity,\n\tTreeRootId,\n} from '../treeParameters'\nimport { assertNever } from '../utils'\nimport { MarkerComparator } from './MarkerComparator'\nimport { RequestResponseNormalizer } from './RequestResponseNormalizer'\nimport type { Schema } from './schema'\nimport type { EntityListState, EntityRealmState, EntityRealmStateStub, EntityState, RootStateNode } from './state'\nimport { SubMutationOperation } from './MutationGenerator'\n\nconst emptyEntityIdSet: ReadonlySet<EntityId> = new Set()\n\nexport class TreeStore {\n\tpublic readonly entityStore: Map<UniqueEntityId, EntityState> = new Map()\n\tpublic readonly entityRealmStore: Map<EntityRealmKey, EntityRealmState | EntityRealmStateStub> = new Map()\n\n\t// This is tricky. We allow placeholder name duplicates, only the (TreeRootId, PlaceholderName) tuple is unique.\n\t// This is useful when the tree is extended to contain a sub-tree with the same placeholder.\n\tpublic readonly markerTrees: Map<TreeRootId | undefined, MarkerTreeRoot> = new Map()\n\tpublic readonly subTreeStatesByRoot: Map<TreeRootId | undefined, Map<PlaceholderName, RootStateNode>> = new Map()\n\n\tpublic readonly persistedData: NormalizedPersistedData = new NormalizedPersistedData(new Map(), new Map())\n\n\tpublic constructor(\n\t\tprivate readonly _schema: Schema,\n\t) {}\n\n\tpublic mergeInQueryResponse(response: ReceivedDataTree, markerTree: MarkerTreeRoot): void {\n\t\tRequestResponseNormalizer.mergeInQueryResponse(this.persistedData, response, markerTree)\n\t}\n\n\tpublic mergeInMutationResponse(response: ReceivedDataTree, operations: SubMutationOperation[]): void {\n\t\tRequestResponseNormalizer.mergeInMutationResponse(this.persistedData, response, operations)\n\t}\n\n\tpublic get persistedEntityData(): PersistedEntityDataStore {\n\t\treturn this.persistedData.persistedEntityDataStore\n\t}\n\n\tpublic get subTreePersistedData(): SubTreeDataStore {\n\t\treturn this.persistedData.subTreeDataStore\n\t}\n\n\tpublic get schema(): Schema {\n\t\treturn this._schema\n\t}\n\n\tpublic getPathBackToParent(entityRealm: EntityRealmState | EntityRealmStateStub):\n\t\t| {\n\t\t\t\tfieldBackToParent: FieldName\n\t\t\t\tparent: EntityRealmState\n\t\t }\n\t\t| undefined {\n\t\tconst blueprint = entityRealm.blueprint\n\t\tif (blueprint.parent === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tlet parentEntityName: EntityName\n\t\tlet relationFromParent: FieldName\n\t\tlet parent: EntityRealmState\n\n\t\tif (blueprint.type === 'hasOne') {\n\t\t\tparentEntityName = blueprint.parent.entity.entityName\n\t\t\trelationFromParent = blueprint.marker.parameters.field\n\t\t\tparent = blueprint.parent\n\t\t} else if (blueprint.type === 'listEntity') {\n\t\t\tconst grandparentBlueprint = blueprint.parent.blueprint\n\n\t\t\tif (grandparentBlueprint.parent === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\tparentEntityName = grandparentBlueprint.parent.entity.entityName\n\t\t\trelationFromParent = grandparentBlueprint.marker.parameters.field\n\t\t\tparent = grandparentBlueprint.parent\n\t\t} else {\n\t\t\treturn assertNever(blueprint)\n\t\t}\n\n\t\tconst relationSchema = this.schema.getEntityRelation(parentEntityName, relationFromParent)\n\t\tconst fieldBack = (relationSchema.ownedBy || relationSchema.inversedBy) ?? null\n\n\t\t// console.log(parentEntityName, relationFromParent, entityRealm.entity.entityName, fieldBack)\n\t\tif (fieldBack === null) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn {\n\t\t\tparent,\n\t\t\tfieldBackToParent: fieldBack,\n\t\t}\n\t}\n\n\tpublic getSubTreeState(\n\t\tmode: 'entity',\n\t\ttreeRootId: TreeRootId | undefined,\n\t\taliasOrParameters: Alias | SugaredQualifiedSingleEntity | SugaredUnconstrainedQualifiedSingleEntity,\n\t\tenvironment: Environment,\n\t): EntityRealmState\n\tpublic getSubTreeState(\n\t\tmode: 'entityList',\n\t\ttreeRootId: TreeRootId | undefined,\n\t\taliasOrParameters: Alias | SugaredQualifiedEntityList | SugaredUnconstrainedQualifiedEntityList,\n\t\tenvironment: Environment,\n\t): EntityListState\n\tpublic getSubTreeState(\n\t\tmode: 'entity' | 'entityList',\n\t\ttreeRootId: TreeRootId | undefined,\n\t\taliasOrParameters:\n\t\t\t| Alias\n\t\t\t| SugaredQualifiedSingleEntity\n\t\t\t| SugaredUnconstrainedQualifiedSingleEntity\n\t\t\t| SugaredQualifiedEntityList\n\t\t\t| SugaredUnconstrainedQualifiedEntityList,\n\t\tenvironment: Environment,\n\t): RootStateNode {\n\t\tconst markerRoot = this.markerTrees.get(treeRootId)\n\t\tconst subTreeStates = this.subTreeStatesByRoot.get(treeRootId)\n\n\t\tif (subTreeStates === undefined || markerRoot === undefined) {\n\t\t\tif (treeRootId) {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`Invalid tree id '${treeRootId}'. Make sure you use the one supplied by the correct extendTree call.`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tthrow new BindingError(`Failed to retrieve a sub tree.`)\n\t\t}\n\n\t\tlet placeholderName: string\n\n\t\tif (typeof aliasOrParameters === 'string') {\n\t\t\tconst placeholderByAlias = markerRoot.placeholdersByAliases.get(aliasOrParameters)\n\n\t\t\tif (placeholderByAlias === undefined) {\n\t\t\t\tthrow new BindingError(`Undefined sub-tree alias '${aliasOrParameters}'.`)\n\t\t\t}\n\t\t\tplaceholderName = placeholderByAlias\n\t\t} else if (mode === 'entityList') {\n\t\t\tplaceholderName = PlaceholderGenerator.getEntityListSubTreePlaceholder(\n\t\t\t\taliasOrParameters.isCreating\n\t\t\t\t\t? QueryLanguage.desugarUnconstrainedQualifiedEntityList(\n\t\t\t\t\t\t\taliasOrParameters as SugaredUnconstrainedQualifiedEntityList,\n\t\t\t\t\t\t\tenvironment,\n\t\t\t\t\t )\n\t\t\t\t\t: QueryLanguage.desugarQualifiedEntityList(aliasOrParameters as SugaredQualifiedEntityList, environment),\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else if (mode === 'entity') {\n\t\t\tplaceholderName = PlaceholderGenerator.getEntitySubTreePlaceholder(\n\t\t\t\taliasOrParameters.isCreating\n\t\t\t\t\t? QueryLanguage.desugarUnconstrainedQualifiedSingleEntity(\n\t\t\t\t\t\t\taliasOrParameters as SugaredUnconstrainedQualifiedSingleEntity,\n\t\t\t\t\t\t\tenvironment,\n\t\t\t\t\t )\n\t\t\t\t\t: QueryLanguage.desugarQualifiedSingleEntity(aliasOrParameters as SugaredQualifiedSingleEntity, environment),\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else {\n\t\t\tthrow new BindingError()\n\t\t}\n\t\tconst subTreeState = subTreeStates.get(placeholderName)\n\n\t\tif (subTreeState === undefined) {\n\t\t\tthrow new BindingError(`Trying to retrieve a non-existent sub-tree '${placeholderName}'.`)\n\t\t}\n\t\treturn subTreeState\n\t}\n\n\tpublic getEntityListPersistedIds(state: EntityListState): ReadonlySet<EntityId> {\n\t\tconst blueprint = state.blueprint\n\n\t\tif (blueprint.parent) {\n\t\t\tconst entityData = this.persistedEntityData.get(blueprint.parent.entity.id.uniqueValue)\n\t\t\treturn (entityData?.get(blueprint.marker.placeholderName) as Set<string> | undefined) ?? emptyEntityIdSet\n\t\t} else {\n\t\t\treturn (this.subTreePersistedData.get(blueprint.marker.placeholderName) as Set<string>) ?? emptyEntityIdSet\n\t\t}\n\t}\n\n\tpublic disposeOfRealm(realmToDisposeOf: EntityRealmState | EntityRealmStateStub) {\n\t\tthis.entityRealmStore.delete(realmToDisposeOf.realmKey)\n\t\trealmToDisposeOf.entity.realms.delete(realmToDisposeOf.realmKey)\n\n\t\tif (realmToDisposeOf.type === 'entityRealm') {\n\t\t\trealmToDisposeOf.blueprint.parent?.childrenWithPendingUpdates?.delete(realmToDisposeOf)\n\n\t\t\tfor (const child of realmToDisposeOf.children.values()) {\n\t\t\t\tswitch (child.type) {\n\t\t\t\t\tcase 'field':\n\t\t\t\t\t\tcontinue\n\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\t\tthis.disposeOfRealm(child)\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\tfor (const listChild of child.children.values()) {\n\t\t\t\t\t\t\tthis.disposeOfRealm(listChild)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst entity = realmToDisposeOf.entity\n\t\tif (entity.realms.size === 0) {\n\t\t\tthis.disposeOfEntity(entity)\n\t\t}\n\t}\n\n\tpublic disposeOfEntity(entity: EntityState) {\n\t\tfor (const realm of entity.realms.values()) {\n\t\t\tthis.disposeOfRealm(realm)\n\t\t}\n\t\tthis.entityStore.delete(entity.id.uniqueValue)\n\t\tthis.persistedEntityData.delete(entity.id.uniqueValue)\n\t}\n\n\tpublic effectivelyHasTreeRoot(candidateRoot: MarkerTreeRoot): boolean {\n\t\tcandidateRoots: for (const candidateSubTree of candidateRoot.subTrees.values()) {\n\t\t\tif (candidateSubTree.parameters.isCreating) {\n\t\t\t\t// This, by definition, won't trigger a query.\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tfor (const root of this.markerTrees.values()) {\n\t\t\t\tfor (const alreadyPresentSubTree of root.subTrees.values()) {\n\t\t\t\t\tconst isSubset = MarkerComparator.isSubTreeSubsetOf(candidateSubTree, alreadyPresentSubTree)\n\t\t\t\t\tif (isSubset) {\n\t\t\t\t\t\tcontinue candidateRoots\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false\n\t\t}\n\t\treturn true\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AA+BA,MAAM,uCAA8C;AAE7C,MAAM,UAAU;AAAA,EAWf,YACW,SAChB;AADgB,SAAA,UAAA;AAXF,kBAAA,MAAA,mCAAoD,IAAI,CAAA;AACxD,kBAAA,MAAA,wCAAqF,IAAI,CAAA;AAIzF,kBAAA,MAAA,mCAA+D,IAAI,CAAA;AACnE,kBAAA,MAAA,2CAA4F,IAAI,CAAA;AAEhG,kBAAA,MAAA,iBAAyC,IAAI,wBAAwB,oBAAI,OAAO,oBAAI,IAAK,CAAA,CAAA;AAAA,EAItG;AAAA,EAEI,qBAAqB,UAA4B,YAAkC;AACzF,8BAA0B,qBAAqB,KAAK,eAAe,UAAU,UAAU;AAAA,EACxF;AAAA,EAEO,wBAAwB,UAA4B,YAA0C;AACpG,8BAA0B,wBAAwB,KAAK,eAAe,UAAU,UAAU;AAAA,EAC3F;AAAA,EAEA,IAAW,sBAAgD;AAC1D,WAAO,KAAK,cAAc;AAAA,EAC3B;AAAA,EAEA,IAAW,uBAAyC;AACnD,WAAO,KAAK,cAAc;AAAA,EAC3B;AAAA,EAEA,IAAW,SAAiB;AAC3B,WAAO,KAAK;AAAA,EACb;AAAA,EAEO,oBAAoB,aAKd;AACZ,UAAM,YAAY,YAAY;AAC1B,QAAA,UAAU,WAAW,QAAW;AAC5B,aAAA;AAAA,IACR;AACI,QAAA;AACA,QAAA;AACA,QAAA;AAEA,QAAA,UAAU,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AO,OAAO,SAAS,GAAG;AAC7B,WAAK,gBAAgB,MAAM;AAAA,IAC5B;AAAA,EACD;AAAA,EAEO,gBAAgB,QAAqB;AAC3C,eAAW,SAAS,OAAO,OAAO,OAAA,GAAU;AAC3C,WAAK,eAAe,KAAK;AAAA,IAC1B;AACA,SAAK,YAAY,OAAO,OAAO,GAAG,WAAW;AAC7C,SAAK,oBAAoB,OAAO,OAAO,GAAG,WAAW;AAAA,EACtD;AAAA,EAEO,uBAAuB,eAAwC;AACrE;AAAgB,iBAAW,oBAAoB,cAAc,SAAS,OAAA,GAAU;AAC3E,YAAA,iBAAiB,WAAW,YAAY;AAE3C;AAAA,QACD;AACA,mBAAW,QAAQ,KAAK,YAAY,OAAA,GAAU;AAC7C,qBAAW,yBAAyB,KAAK,SAAS,OAAA,GAAU;AAC3D,kBAAM,WAAW,iBAAiB,kBAAkB,kBAAkB,qBAAqB;AAC3F,gBAAI,UAAU;AACJ,uBAAA;AAAA,YACV;AAAA,UACD;AAAA,QACD;AACO,eAAA;AAAA,MACR;AACO,WAAA;AAAA,EACR;AACD;"}
|
|
1
|
+
{"version":3,"file":"TreeStore.js","sources":["../../../src/core/TreeStore.ts"],"sourcesContent":["import {\n\tNormalizedPersistedData,\n\tPersistedEntityDataStore,\n\tReceivedDataTree,\n\tSubTreeDataStore,\n\tUniqueEntityId,\n} from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { Environment } from '../dao'\nimport { MarkerTreeRoot, PlaceholderGenerator } from '../markers'\nimport { QueryLanguage } from '../queryLanguage'\nimport type {\n\tAlias,\n\tEntityId,\n\tEntityName,\n\tEntityRealmKey,\n\tFieldName,\n\tPlaceholderName,\n\tSugaredQualifiedEntityList,\n\tSugaredQualifiedSingleEntity,\n\tSugaredUnconstrainedQualifiedEntityList,\n\tSugaredUnconstrainedQualifiedSingleEntity,\n\tTreeRootId,\n} from '../treeParameters'\nimport { assertNever } from '../utils'\nimport { MarkerComparator } from './MarkerComparator'\nimport { RequestResponseNormalizer } from './RequestResponseNormalizer'\nimport type { Schema } from './schema'\nimport type { EntityListState, EntityRealmState, EntityRealmStateStub, EntityState, RootStateNode } from './state'\nimport { SubMutationOperation } from './MutationGenerator'\n\nconst emptyEntityIdSet: ReadonlySet<EntityId> = new Set()\n\nexport class TreeStore {\n\tpublic readonly entityStore: Map<UniqueEntityId, EntityState> = new Map()\n\tpublic readonly entityRealmStore: Map<EntityRealmKey, EntityRealmState | EntityRealmStateStub> = new Map()\n\n\t// This is tricky. We allow placeholder name duplicates, only the (TreeRootId, PlaceholderName) tuple is unique.\n\t// This is useful when the tree is extended to contain a sub-tree with the same placeholder.\n\tpublic readonly markerTrees: Map<TreeRootId | undefined, MarkerTreeRoot> = new Map()\n\tpublic readonly subTreeStatesByRoot: Map<TreeRootId | undefined, Map<PlaceholderName, RootStateNode>> = new Map()\n\n\tpublic readonly persistedData: NormalizedPersistedData = new NormalizedPersistedData(new Map(), new Map())\n\n\tpublic constructor(\n\t\tprivate readonly _schema: Schema,\n\t) {}\n\n\tpublic mergeInQueryResponse(response: ReceivedDataTree, markerTree: MarkerTreeRoot): void {\n\t\tRequestResponseNormalizer.mergeInQueryResponse(this.persistedData, response, markerTree)\n\t}\n\n\tpublic mergeInMutationResponse(response: ReceivedDataTree, operations: SubMutationOperation[]): void {\n\t\tRequestResponseNormalizer.mergeInMutationResponse(this.persistedData, response, operations)\n\t}\n\n\tpublic get persistedEntityData(): PersistedEntityDataStore {\n\t\treturn this.persistedData.persistedEntityDataStore\n\t}\n\n\tpublic get subTreePersistedData(): SubTreeDataStore {\n\t\treturn this.persistedData.subTreeDataStore\n\t}\n\n\tpublic get schema(): Schema {\n\t\treturn this._schema\n\t}\n\n\tpublic getPathBackToParent(entityRealm: EntityRealmState | EntityRealmStateStub):\n\t\t| {\n\t\t\t\tfieldBackToParent: FieldName\n\t\t\t\tparent: EntityRealmState\n\t\t }\n\t\t| undefined {\n\t\tconst blueprint = entityRealm.blueprint\n\t\tif (blueprint.parent === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tlet parentEntityName: EntityName\n\t\tlet relationFromParent: FieldName\n\t\tlet parent: EntityRealmState\n\n\t\tif (blueprint.type === 'hasOne') {\n\t\t\tparentEntityName = blueprint.parent.entity.entityName\n\t\t\trelationFromParent = blueprint.marker.parameters.field\n\t\t\tparent = blueprint.parent\n\t\t} else if (blueprint.type === 'listEntity') {\n\t\t\tconst grandparentBlueprint = blueprint.parent.blueprint\n\n\t\t\tif (grandparentBlueprint.parent === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\tparentEntityName = grandparentBlueprint.parent.entity.entityName\n\t\t\trelationFromParent = grandparentBlueprint.marker.parameters.field\n\t\t\tparent = grandparentBlueprint.parent\n\t\t} else {\n\t\t\treturn assertNever(blueprint)\n\t\t}\n\n\t\tconst relationSchema = this.schema.getEntityRelation(parentEntityName, relationFromParent)\n\t\tconst fieldBack = (relationSchema.ownedBy || relationSchema.inversedBy) ?? null\n\n\t\t// console.log(parentEntityName, relationFromParent, entityRealm.entity.entityName, fieldBack)\n\t\tif (fieldBack === null) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn {\n\t\t\tparent,\n\t\t\tfieldBackToParent: fieldBack,\n\t\t}\n\t}\n\n\tpublic getSubTreeState(\n\t\tmode: 'entity',\n\t\ttreeRootId: TreeRootId | undefined,\n\t\taliasOrParameters: Alias | SugaredQualifiedSingleEntity | SugaredUnconstrainedQualifiedSingleEntity,\n\t\tenvironment: Environment,\n\t): EntityRealmState\n\tpublic getSubTreeState(\n\t\tmode: 'entityList',\n\t\ttreeRootId: TreeRootId | undefined,\n\t\taliasOrParameters: Alias | SugaredQualifiedEntityList | SugaredUnconstrainedQualifiedEntityList,\n\t\tenvironment: Environment,\n\t): EntityListState\n\tpublic getSubTreeState(\n\t\tmode: 'entity' | 'entityList',\n\t\ttreeRootId: TreeRootId | undefined,\n\t\taliasOrParameters:\n\t\t\t| Alias\n\t\t\t| SugaredQualifiedSingleEntity\n\t\t\t| SugaredUnconstrainedQualifiedSingleEntity\n\t\t\t| SugaredQualifiedEntityList\n\t\t\t| SugaredUnconstrainedQualifiedEntityList,\n\t\tenvironment: Environment,\n\t): RootStateNode {\n\t\tconst markerRoot = this.markerTrees.get(treeRootId)\n\t\tconst subTreeStates = this.subTreeStatesByRoot.get(treeRootId)\n\n\t\tif (subTreeStates === undefined || markerRoot === undefined) {\n\t\t\tif (treeRootId) {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`Invalid tree id '${treeRootId}'. Make sure you use the one supplied by the correct extendTree call.`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tthrow new BindingError(`Failed to retrieve a sub tree.`)\n\t\t}\n\n\t\tlet placeholderName: string\n\n\t\tif (typeof aliasOrParameters === 'string') {\n\t\t\tconst placeholderByAlias = markerRoot.placeholdersByAliases.get(aliasOrParameters)\n\n\t\t\tif (placeholderByAlias === undefined) {\n\t\t\t\tthrow new BindingError(`Undefined sub-tree alias '${aliasOrParameters}'.`)\n\t\t\t}\n\t\t\tplaceholderName = placeholderByAlias\n\t\t} else if (mode === 'entityList') {\n\t\t\tplaceholderName = PlaceholderGenerator.getEntityListSubTreePlaceholder(\n\t\t\t\taliasOrParameters.isCreating\n\t\t\t\t\t? QueryLanguage.desugarUnconstrainedQualifiedEntityList(\n\t\t\t\t\t\t\taliasOrParameters as SugaredUnconstrainedQualifiedEntityList,\n\t\t\t\t\t\t\tenvironment,\n\t\t\t\t\t )\n\t\t\t\t\t: QueryLanguage.desugarQualifiedEntityList(aliasOrParameters as SugaredQualifiedEntityList, environment),\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else if (mode === 'entity') {\n\t\t\tplaceholderName = PlaceholderGenerator.getEntitySubTreePlaceholder(\n\t\t\t\taliasOrParameters.isCreating\n\t\t\t\t\t? QueryLanguage.desugarUnconstrainedQualifiedSingleEntity(\n\t\t\t\t\t\t\taliasOrParameters as SugaredUnconstrainedQualifiedSingleEntity,\n\t\t\t\t\t\t\tenvironment,\n\t\t\t\t\t )\n\t\t\t\t\t: QueryLanguage.desugarQualifiedSingleEntity(aliasOrParameters as SugaredQualifiedSingleEntity, environment),\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else {\n\t\t\tthrow new BindingError()\n\t\t}\n\t\tconst subTreeState = subTreeStates.get(placeholderName)\n\n\t\tif (subTreeState === undefined) {\n\t\t\tthrow new BindingError(`Trying to retrieve a non-existent sub-tree '${placeholderName}'.`)\n\t\t}\n\t\treturn subTreeState\n\t}\n\n\tpublic getEntityListPersistedIds(state: EntityListState): ReadonlySet<EntityId> {\n\t\tconst blueprint = state.blueprint\n\n\t\tif (blueprint.parent) {\n\t\t\tconst entityData = this.persistedEntityData.get(blueprint.parent.entity.id.uniqueValue)\n\t\t\treturn (entityData?.get(blueprint.marker.placeholderName) as Set<string> | undefined) ?? emptyEntityIdSet\n\t\t} else {\n\t\t\treturn (this.subTreePersistedData.get(blueprint.marker.placeholderName) as Set<string>) ?? emptyEntityIdSet\n\t\t}\n\t}\n\n\tpublic disposeOfRealm(realmToDisposeOf: EntityRealmState | EntityRealmStateStub) {\n\t\tthis.entityRealmStore.delete(realmToDisposeOf.realmKey)\n\t\trealmToDisposeOf.entity.realms.delete(realmToDisposeOf.realmKey)\n\n\t\tif (realmToDisposeOf.type === 'entityRealm') {\n\t\t\trealmToDisposeOf.blueprint.parent?.childrenWithPendingUpdates?.delete(realmToDisposeOf)\n\n\t\t\tfor (const child of realmToDisposeOf.children.values()) {\n\t\t\t\tswitch (child.type) {\n\t\t\t\t\tcase 'field':\n\t\t\t\t\t\tcontinue\n\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\t\tthis.disposeOfRealm(child)\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\tfor (const listChild of child.children.values()) {\n\t\t\t\t\t\t\tthis.disposeOfRealm(listChild)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst entity = realmToDisposeOf.entity\n\t\tif (entity.realms.size === 0) {\n\t\t\tthis.disposeOfEntity(entity)\n\t\t}\n\t}\n\n\tpublic disposeOfEntity(entity: EntityState) {\n\t\tfor (const realm of entity.realms.values()) {\n\t\t\tthis.disposeOfRealm(realm)\n\t\t}\n\t\tthis.entityStore.delete(entity.id.uniqueValue)\n\t\tthis.persistedEntityData.delete(entity.id.uniqueValue)\n\t}\n\n\tpublic effectivelyHasTreeRoot(candidateRoot: MarkerTreeRoot): boolean {\n\t\tcandidateRoots: for (const candidateSubTree of candidateRoot.subTrees.values()) {\n\t\t\tif (candidateSubTree.parameters.isCreating) {\n\t\t\t\t// This, by definition, won't trigger a query.\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tfor (const root of this.markerTrees.values()) {\n\t\t\t\tfor (const alreadyPresentSubTree of root.subTrees.values()) {\n\t\t\t\t\tconst isSubset = MarkerComparator.isSubTreeSubsetOf(candidateSubTree, alreadyPresentSubTree)\n\t\t\t\t\tif (isSubset) {\n\t\t\t\t\t\tcontinue candidateRoots\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false\n\t\t}\n\t\treturn true\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AA+BA,MAAM,uCAA8C;AAE7C,MAAM,UAAU;AAAA,EAWf,YACW,SAChB;AAZc,2DAAoD;AACpD,gEAAqF;AAIrF;AAAA;AAAA,2DAA+D;AAC/D,mEAA4F;AAE5F,yCAAyC,IAAI,wBAAwB,oBAAI,OAAO,oBAAI,KAAK;AAGvF,SAAA,UAAA;AAAA,EACf;AAAA,EAEI,qBAAqB,UAA4B,YAAkC;AACzF,8BAA0B,qBAAqB,KAAK,eAAe,UAAU,UAAU;AAAA,EACxF;AAAA,EAEO,wBAAwB,UAA4B,YAA0C;AACpG,8BAA0B,wBAAwB,KAAK,eAAe,UAAU,UAAU;AAAA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AAiB,SAAS,OAAA,GAAU;AACvD,gBAAQ,MAAM,MAAM;AAAA,UACnB,KAAK;AACJ;AAAA,UACD,KAAK;AAAA,UACL,KAAK,mBAAmB;AACvB,iBAAK,eAAe,KAAK;AACzB;AAAA,UACD;AAAA,UACA,KAAK,cAAc;AAClB,uBAAW,aAAa,MAAM,SAAS,OAAA,GAAU;AAChD,mBAAK,eAAe,SAAS;AAAA,YAC9B;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAEA,UAAM,SAAS,iBAAiB;AAC5B,QAAA,OAAO,OAAO,SAAS,GAAG;AAC7B,WAAK,gBAAgB,MAAM;AAAA,IAC5B;AAAA,EACD;AAAA,EAEO,gBAAgB,QAAqB;AAC3C,eAAW,SAAS,OAAO,OAAO,OAAA,GAAU;AAC3C,WAAK,eAAe,KAAK;AAAA,IAC1B;AACA,SAAK,YAAY,OAAO,OAAO,GAAG,WAAW;AAC7C,SAAK,oBAAoB,OAAO,OAAO,GAAG,WAAW;AAAA,EACtD;AAAA,EAEO,uBAAuB,eAAwC;AACrE;AAAgB,iBAAW,oBAAoB,cAAc,SAAS,OAAA,GAAU;AAC3E,YAAA,iBAAiB,WAAW,YAAY;AAE3C;AAAA,QACD;AACA,mBAAW,QAAQ,KAAK,YAAY,OAAA,GAAU;AAC7C,qBAAW,yBAAyB,KAAK,SAAS,OAAA,GAAU;AAC3D,kBAAM,WAAW,iBAAiB,kBAAkB,kBAAkB,qBAAqB;AAC3F,gBAAI,UAAU;AACJ,uBAAA;AAAA,YACV;AAAA,UACD;AAAA,QACD;AACO,eAAA;AAAA,MACR;AACO,WAAA;AAAA,EACR;AACD;"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { MarkerSugarer } from "./MarkerSugarer.js";
|
|
2
|
-
import { TreeParameterSugarer } from "./TreeParameterSugarer.js";
|
|
3
|
-
import { assertNever } from "../../utils/assertNever.js";
|
|
4
1
|
var __defProp = Object.defineProperty;
|
|
5
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
3
|
var __publicField = (obj, key, value) => {
|
|
7
4
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
5
|
return value;
|
|
9
6
|
};
|
|
7
|
+
import { MarkerSugarer } from "./MarkerSugarer.js";
|
|
8
|
+
import { TreeParameterSugarer } from "./TreeParameterSugarer.js";
|
|
9
|
+
import { assertNever } from "../../utils/assertNever.js";
|
|
10
10
|
class ErrorLocator {
|
|
11
11
|
static locateMarkerPath(path) {
|
|
12
12
|
return path.map((marker) => MarkerSugarer.sugarMarker(marker)).join(this.GLUE);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorLocator.js","sources":["../../../../src/core/exceptions/ErrorLocator.ts"],"sourcesContent":["import { assertNever } from '../../utils'\nimport type { StateNode } from '../state'\nimport { MarkerSugarer } from './MarkerSugarer'\nimport type { RawMarkerPath } from './RawMarkerPath'\nimport { TreeParameterSugarer } from './TreeParameterSugarer'\n\nexport class ErrorLocator {\n\tprivate static readonly GLUE = '.'\n\n\tpublic static locateMarkerPath(path: RawMarkerPath): string {\n\t\treturn path.map(marker => MarkerSugarer.sugarMarker(marker)).join(this.GLUE)\n\t}\n\n\tpublic static locateInternalState(state: StateNode): string {\n\t\tfunction stateToPath(state: StateNode | undefined): string[] {\n\t\t\tif (state === undefined) {\n\t\t\t\treturn []\n\t\t\t}\n\t\t\tswitch (state.type) {\n\t\t\t\tcase 'field':\n\t\t\t\t\treturn [...stateToPath(state.parent), TreeParameterSugarer.sugarField(state.fieldMarker.fieldName)]\n\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\tconst blueprint = state.blueprint\n\t\t\t\t\tif (blueprint.type === 'subTree') {\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tTreeParameterSugarer.sugarRootEntity(\n\t\t\t\t\t\t\t\tstate.entity.entityName,\n\t\t\t\t\t\t\t\tblueprint.marker.parameters.isCreating ? undefined : blueprint.marker.parameters.where,\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\tif (blueprint.type === 'listEntity') {\n\t\t\t\t\t\treturn [...stateToPath(blueprint.parent)]\n\t\t\t\t\t}\n\t\t\t\t\tif (blueprint.type === 'hasOne') {\n\t\t\t\t\t\treturn [...stateToPath(blueprint.parent), MarkerSugarer.sugarHasOneRelationMarker(blueprint.marker)]\n\t\t\t\t\t}\n\t\t\t\t\treturn assertNever(blueprint)\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tconst blueprint = state.blueprint\n\n\t\t\t\t\tif (blueprint.parent === undefined) {\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tTreeParameterSugarer.sugarRootEntityList(\n\t\t\t\t\t\t\t\tstate.entityName,\n\t\t\t\t\t\t\t\tblueprint.marker.parameters.isCreating ? undefined : blueprint.marker.parameters.filter,\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\tconst hasMany = blueprint.marker\n\t\t\t\t\treturn [...stateToPath(blueprint.parent), MarkerSugarer.sugarHasManyRelationMarker(hasMany)]\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn stateToPath(state).join(this.GLUE)\n\t}\n}\n"],"names":["state"],"mappings":";;;;;;;;;AAMO,MAAM,aAAa;AAAA,EAGzB,OAAc,iBAAiB,MAA6B;AACpD,WAAA,KAAK,IAAI,CAAA,WAAU,cAAc,YAAY,MAAM,CAAC,EAAE,KAAK,KAAK,IAAI;AAAA,EAC5E;AAAA,EAEA,OAAc,oBAAoB,OAA0B;AAC3D,aAAS,YAAYA,QAAwC;AAC5D,UAAIA,WAAU,QAAW;AACxB,eAAO;MACR;AACA,cAAQA,OAAM,MAAM;AAAA,QACnB,KAAK;AACG,iBAAA,CAAC,GAAG,YAAYA,OAAM,MAAM,GAAG,qBAAqB,WAAWA,OAAM,YAAY,SAAS,CAAC;AAAA,QACnG,KAAK,eAAe;AACnB,gBAAM,YAAYA,OAAM;AACpB,cAAA,UAAU,SAAS,WAAW;AAC1B,mBAAA;AAAA,cACN,qBAAqB;AAAA,gBACpBA,OAAM,OAAO;AAAA,gBACb,UAAU,OAAO,WAAW,aAAa,SAAY,UAAU,OAAO,WAAW;AAAA,cAClF;AAAA,YAAA;AAAA,UAEF;AACI,cAAA,UAAU,SAAS,cAAc;AACpC,mBAAO,CAAC,GAAG,YAAY,UAAU,MAAM,CAAC;AAAA,UACzC;AACI,cAAA,UAAU,SAAS,UAAU;AACzB,mBAAA,CAAC,GAAG,YAAY,UAAU,MAAM,GAAG,cAAc,0BAA0B,UAAU,MAAM,CAAC;AAAA,UACpG;AACA,iBAAO,YAAqB;AAAA,QAC7B;AAAA,QACA,KAAK,cAAc;AAClB,gBAAM,YAAYA,OAAM;AAEpB,cAAA,UAAU,WAAW,QAAW;AAC5B,mBAAA;AAAA,cACN,qBAAqB;AAAA,gBACpBA,OAAM;AAAA,gBACN,UAAU,OAAO,WAAW,aAAa,SAAY,UAAU,OAAO,WAAW;AAAA,cAClF;AAAA,YAAA;AAAA,UAEF;AACA,gBAAM,UAAU,UAAU;AACnB,iBAAA,CAAC,GAAG,YAAY,UAAU,MAAM,GAAG,cAAc,2BAA2B,OAAO,CAAC;AAAA,QAC5F;AAAA,MACD;AAAA,IACD;AACA,WAAO,YAAY,KAAK,EAAE,KAAK,KAAK,IAAI;AAAA,EACzC;AACD;AAlDC,cADY,cACY,QAAO
|
|
1
|
+
{"version":3,"file":"ErrorLocator.js","sources":["../../../../src/core/exceptions/ErrorLocator.ts"],"sourcesContent":["import { assertNever } from '../../utils'\nimport type { StateNode } from '../state'\nimport { MarkerSugarer } from './MarkerSugarer'\nimport type { RawMarkerPath } from './RawMarkerPath'\nimport { TreeParameterSugarer } from './TreeParameterSugarer'\n\nexport class ErrorLocator {\n\tprivate static readonly GLUE = '.'\n\n\tpublic static locateMarkerPath(path: RawMarkerPath): string {\n\t\treturn path.map(marker => MarkerSugarer.sugarMarker(marker)).join(this.GLUE)\n\t}\n\n\tpublic static locateInternalState(state: StateNode): string {\n\t\tfunction stateToPath(state: StateNode | undefined): string[] {\n\t\t\tif (state === undefined) {\n\t\t\t\treturn []\n\t\t\t}\n\t\t\tswitch (state.type) {\n\t\t\t\tcase 'field':\n\t\t\t\t\treturn [...stateToPath(state.parent), TreeParameterSugarer.sugarField(state.fieldMarker.fieldName)]\n\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\tconst blueprint = state.blueprint\n\t\t\t\t\tif (blueprint.type === 'subTree') {\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tTreeParameterSugarer.sugarRootEntity(\n\t\t\t\t\t\t\t\tstate.entity.entityName,\n\t\t\t\t\t\t\t\tblueprint.marker.parameters.isCreating ? undefined : blueprint.marker.parameters.where,\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\tif (blueprint.type === 'listEntity') {\n\t\t\t\t\t\treturn [...stateToPath(blueprint.parent)]\n\t\t\t\t\t}\n\t\t\t\t\tif (blueprint.type === 'hasOne') {\n\t\t\t\t\t\treturn [...stateToPath(blueprint.parent), MarkerSugarer.sugarHasOneRelationMarker(blueprint.marker)]\n\t\t\t\t\t}\n\t\t\t\t\treturn assertNever(blueprint)\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tconst blueprint = state.blueprint\n\n\t\t\t\t\tif (blueprint.parent === undefined) {\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tTreeParameterSugarer.sugarRootEntityList(\n\t\t\t\t\t\t\t\tstate.entityName,\n\t\t\t\t\t\t\t\tblueprint.marker.parameters.isCreating ? undefined : blueprint.marker.parameters.filter,\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\tconst hasMany = blueprint.marker\n\t\t\t\t\treturn [...stateToPath(blue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AAAA,UAEF;AACA,gBAAM,UAAU,UAAU;AACnB,iBAAA,CAAC,GAAG,YAAY,UAAU,MAAM,GAAG,cAAc,2BAA2B,OAAO,CAAC;AAAA,QAC5F;AAAA,MACD;AAAA,IACD;AACA,WAAO,YAAY,KAAK,EAAE,KAAK,KAAK,IAAI;AAAA,EACzC;AACD;AAlDC,cADY,cACY,QAAO;"}
|
|
@@ -18,13 +18,13 @@ class TreeParameterSugarer {
|
|
|
18
18
|
if (where === void 0) {
|
|
19
19
|
return "";
|
|
20
20
|
}
|
|
21
|
-
return `(
|
|
21
|
+
return `(…)`;
|
|
22
22
|
}
|
|
23
23
|
static sugarFilter(filter) {
|
|
24
24
|
if (filter === void 0) {
|
|
25
25
|
return "";
|
|
26
26
|
}
|
|
27
|
-
return `[
|
|
27
|
+
return `[…]`;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
export {
|
|
@@ -99,7 +99,9 @@ ${error.message}
|
|
|
99
99
|
} else if (persistedId instanceof ServerId && persistedId.value === previouslyConnectedState.entity.id.value) {
|
|
100
100
|
changesDelta++;
|
|
101
101
|
} else if (!previouslyConnectedState.entity.id.existsOnServer) {
|
|
102
|
-
if (persistedId === null ||
|
|
102
|
+
if (persistedId === null || // We're updating.
|
|
103
|
+
persistedId === void 0 && // We're creating.
|
|
104
|
+
(!fieldsToConnect.hasAtLeastOneBearingField || !targetHasOneMarker.parameters.isNonbearing)) {
|
|
103
105
|
changesDelta++;
|
|
104
106
|
}
|
|
105
107
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityOperations.js","sources":["../../../../src/core/operations/EntityOperations.ts"],"sourcesContent":["import type { BatchUpdatesOptions, EntityAccessor, ErrorAccessor } from '../../accessors'\nimport { ServerId, UnpersistedEntityDummyId } from '../../accessorTree'\nimport { BindingError } from '../../BindingError'\nimport { EntityFieldMarkersContainer, HasOneRelationMarker } from '../../markers'\nimport type { FieldName } from '../../treeParameters'\nimport { assertNever } from '../../utils'\nimport type { AccessorErrorManager } from '../AccessorErrorManager'\nimport type { EventManager } from '../EventManager'\nimport { ErrorLocator, LocalizedBindingError } from '../exceptions'\nimport { MarkerComparator } from '../MarkerComparator'\nimport { EntityListState, EntityRealmState, EntityRealmStateStub, getEntityMarker, StateIterator } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\nimport { OperationsHelpers } from './OperationsHelpers'\nimport { EventListenersStore } from '../../treeParameters'\n\nexport class EntityOperations {\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic addError(entityRealm: EntityRealmState, error: ErrorAccessor.Error): () => void {\n\t\treturn this.accessorErrorManager.addError(entityRealm, error)\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityAccessor.RuntimeEntityEventListenerMap>(\n\t\tstate: EntityRealmState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\tif (state.eventListeners === undefined) {\n\t\t\tstate.eventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.eventListeners.add(event, listener)\n\t}\n\n\tpublic batchUpdates(state: EntityRealmState, performUpdates: EntityAccessor.BatchUpdatesHandler) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tperformUpdates(state.getAccessor, this.batchUpdatesOptions)\n\t\t})\n\t}\n\n\tpublic connectEntityAtField(outerState: EntityRealmState, fieldName: FieldName, entityToConnect: EntityAccessor) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst stateToConnect = OperationsHelpers.resolveAndPrepareEntityToConnect(this.treeStore, entityToConnect)\n\t\t\tconst fieldsToConnect = getEntityMarker(stateToConnect).fields\n\t\t\tconst persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)\n\n\t\t\tconst entityName = outerState.entity.entityName\n\t\t\tconst fieldSchema = this.treeStore.schema.getEntityFieldOrUndefined(entityName, fieldName)\n\n\t\t\tif (fieldSchema === undefined) {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`EntityAccessor.connectEntityAtField: Unknown field ${entityName}.${fieldName}.\\n\\n` +\n\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t)\n\t\t\t} else if (fieldSchema.__typename === '_Column') {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`EntityAccessor.connectEntityAtField: Cannot connect at field ${entityName}.${fieldName} because ` +\n\t\t\t\t\t\t`it's not a has-one relation.\\n\\n` +\n\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealm(outerState)) {\n\t\t\t\tconst targetHasOneMarkers = this.resolveHasOneRelationMarkers(\n\t\t\t\t\tgetEntityMarker(state).fields,\n\t\t\t\t\tfieldName,\n\t\t\t\t\t`Cannot connect at field '${fieldName}' as it doesn't refer to a has one relation.`,\n\t\t\t\t)\n\t\t\t\tfor (const targetHasOneMarker of targetHasOneMarkers) {\n\t\t\t\t\tconst previouslyConnectedState = state.children.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviouslyConnectedState === undefined ||\n\t\t\t\t\t\tpreviouslyConnectedState.type === 'field' ||\n\t\t\t\t\t\tpreviouslyConnectedState.type === 'entityList'\n\t\t\t\t\t) {\n\t\t\t\t\t\tOperationsHelpers.rejectInvalidAccessorTree()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (previouslyConnectedState.entity.entityName !== stateToConnect.entity.entityName) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`EntityAccessor.connectEntityAtField: Attempting to connect at field ${entityName}.${fieldName} ` +\n\t\t\t\t\t\t\t\t`an entity of type '${stateToConnect.entity.entityName}' but ` +\n\t\t\t\t\t\t\t\t`'${previouslyConnectedState.entity.entityName}' is expected.\\n\\n` +\n\t\t\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tMarkerComparator.assertEntityMarkersSubsetOf(targetHasOneMarker.fields, fieldsToConnect)\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (error instanceof LocalizedBindingError) {\n\t\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t\t`EntityAccessor: cannot connect entity with key '${entityToConnect.key}' because its fields are` +\n\t\t\t\t\t\t\t\t\t`incompatible with entities found at field '${fieldName}'. Make sure both trees are equivalent.\\n\\n` +\n\t\t\t\t\t\t\t\t\t`${error.message}\\n\\n` +\n\t\t\t\t\t\t\t\t\t(error.markerPath.length > 1\n\t\t\t\t\t\t\t\t\t\t? `Incompatibility found at: ${ErrorLocator.locateMarkerPath(error.markerPath)}.\\n\\n`\n\t\t\t\t\t\t\t\t\t\t: '') +\n\t\t\t\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(state)}.`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow error\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviouslyConnectedState === stateToConnect ||\n\t\t\t\t\t\tpreviouslyConnectedState.entity.id.value === stateToConnect.entity.id.value\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue // Do nothing.\n\t\t\t\t\t}\n\n\t\t\t\t\t// TODO remove from planned deletions if appropriate\n\n\t\t\t\t\tthis.treeStore.disposeOfRealm(previouslyConnectedState)\n\n\t\t\t\t\tlet changesDelta = 0\n\n\t\t\t\t\tif (previouslyConnectedState.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta -= previouslyConnectedState.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\tconst persistedId = persistedData?.get(targetHasOneMarker.placeholderName)\n\t\t\t\t\tif (persistedId instanceof ServerId && persistedId.value === stateToConnect.entity.id.value) {\n\t\t\t\t\t\tchangesDelta-- // It was removed from the list but now we're adding it back.\n\t\t\t\t\t} else if (persistedId instanceof ServerId && persistedId.value === previouslyConnectedState.entity.id.value) {\n\t\t\t\t\t\tchangesDelta++ // We're changing it from the persisted id.\n\t\t\t\t\t} else if (!previouslyConnectedState.entity.id.existsOnServer) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tpersistedId === null || // We're updating.\n\t\t\t\t\t\t\t(persistedId === undefined && // We're creating.\n\t\t\t\t\t\t\t\t(!fieldsToConnect.hasAtLeastOneBearingField || !targetHasOneMarker.parameters.isNonbearing))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (stateToConnect.type === 'entityRealm') {\n\t\t\t\t\t\t\tchangesDelta += stateToConnect.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\t// TODO do something about the existing state…\n\n\t\t\t\t\tthis.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tstateToConnect.entity.id,\n\t\t\t\t\t\tstateToConnect.entity.entityName,\n\t\t\t\t\t\tpreviouslyConnectedState.blueprint,\n\t\t\t\t\t\tstateToConnect,\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName)\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectEntityAtField(\n\t\touterState: EntityRealmState,\n\t\tfieldName: FieldName,\n\t\tinitializeReplacement: EntityAccessor.BatchUpdatesHandler | undefined,\n\t) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealm(outerState)) {\n\t\t\t\tconst targetHasOneMarkers = this.resolveHasOneRelationMarkers(\n\t\t\t\t\tgetEntityMarker(state).fields,\n\t\t\t\t\tfieldName,\n\t\t\t\t\t`Cannot disconnect at field '${fieldName}' as it doesn't refer to a has one relation.`,\n\t\t\t\t)\n\t\t\t\tfor (const targetHasOneMarker of targetHasOneMarkers) {\n\t\t\t\t\tconst stateToDisconnect = state.children.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tstateToDisconnect === undefined ||\n\t\t\t\t\t\t(stateToDisconnect.type !== 'entityRealm' && stateToDisconnect.type !== 'entityRealmStub')\n\t\t\t\t\t) {\n\t\t\t\t\t\tOperationsHelpers.rejectInvalidAccessorTree()\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.disposeOfRealm(stateToDisconnect)\n\n\t\t\t\t\tlet changesDelta = 0\n\n\t\t\t\t\tif (stateToDisconnect.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta -= stateToDisconnect.unpersistedChangesCount\n\t\t\t\t\t}\n\t\t\t\t\tconst persistedId = persistedData?.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (persistedId instanceof ServerId) {\n\t\t\t\t\t\tif (persistedId.value === stateToDisconnect.entity.id.value) {\n\t\t\t\t\t\t\tchangesDelta++ // Disconnecting the persisted entity.\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// Do nothing. The entity that is being disconnected is already different from the one that is persisted,\n\t\t\t\t\t\t\t// and so we must have already accounted for this change.\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (persistedId === undefined || persistedId === null) {\n\t\t\t\t\t\tif (stateToDisconnect.entity.id.existsOnServer) {\n\t\t\t\t\t\t\t// We had connected a persisted entity, which increased the changes count,\n\t\t\t\t\t\t\t// but now are disconnecting it again.\n\t\t\t\t\t\t\tchangesDelta--\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Do nothing. Disconnecting unpersisted entities doesn't change the count.\n\t\t\t\t\t}\n\n\t\t\t\t\tconst newEntity = this.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tnew UnpersistedEntityDummyId(),\n\t\t\t\t\t\tstateToDisconnect.entity.entityName,\n\t\t\t\t\t\tstateToDisconnect.blueprint,\n\t\t\t\t\t)\n\t\t\t\t\tthis.stateInitializer.runImmediateUserInitialization(newEntity, initializeReplacement)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName)\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic deleteEntity(realm: EntityRealmState) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst outerState = realm.entity\n\t\t\touterState.isScheduledForDeletion = true\n\n\t\t\tconst entityId = outerState.id\n\n\t\t\tfor (const realmToDelete of outerState.realms.values()) {\n\t\t\t\tlet parent: EntityRealmState | EntityRealmStateStub | EntityListState\n\t\t\t\tlet changesDelta = 0\n\n\t\t\t\tif (realmToDelete.blueprint.type === 'listEntity') {\n\t\t\t\t\tparent = realmToDelete.blueprint.parent\n\t\t\t\t\tparent.children.delete(entityId.value)\n\n\t\t\t\t\tif (entityId.existsOnServer) {\n\t\t\t\t\t\tif (parent.plannedRemovals === undefined) {\n\t\t\t\t\t\t\tparent.plannedRemovals = new Map()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\tparent.plannedRemovals.set(entityId.value, 'delete')\n\t\t\t\t\t}\n\t\t\t\t} else if (realmToDelete.blueprint.type === 'hasOne') {\n\t\t\t\t\tparent = realmToDelete.blueprint.parent\n\t\t\t\t\tconst placeholderName = realmToDelete.blueprint.marker.placeholderName\n\n\t\t\t\t\tif (entityId.existsOnServer) {\n\t\t\t\t\t\tif (parent.plannedHasOneDeletions === undefined) {\n\t\t\t\t\t\t\tparent.plannedHasOneDeletions = new Map()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\tparent.plannedHasOneDeletions.set(placeholderName, realmToDelete)\n\t\t\t\t\t}\n\t\t\t\t\tthis.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tnew UnpersistedEntityDummyId(),\n\t\t\t\t\t\touterState.entityName,\n\t\t\t\t\t\trealmToDelete.blueprint,\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(parent, placeholderName)\n\t\t\t\t} else if (realmToDelete.blueprint.type === 'subTree') {\n\t\t\t\t\tthrow new BindingError('Deleting top-level entities is not yet implemented.')\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(realmToDelete.blueprint)\n\t\t\t\t}\n\n\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t// Undoing whatever this had caused\n\t\t\t\t\tchangesDelta -= realmToDelete.unpersistedChangesCount\n\t\t\t\t}\n\t\t\t\tthis.eventManager.registerJustUpdated(parent, changesDelta)\n\n\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\tparent.childrenWithPendingUpdates?.delete(realmToDelete)\n\t\t\t\t}\n\n\t\t\t\tthis.treeStore.disposeOfRealm(realmToDelete)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate *resolveHasOneRelationMarkers(\n\t\tcontainer: EntityFieldMarkersContainer,\n\t\tfield: FieldName,\n\t\tmessage: string,\n\t): IterableIterator<HasOneRelationMarker> {\n\t\tconst placeholders = container.placeholders.get(field)\n\n\t\tif (placeholders === undefined) {\n\t\t\treturn\n\t\t}\n\t\tconst normalizedPlaceholders = placeholders instanceof Set ? placeholders : [placeholders]\n\n\t\tfor (const placeholderName of normalizedPlaceholders) {\n\t\t\tconst hasOneRelation = container.markers.get(placeholderName)\n\n\t\t\tif (!(hasOneRelation instanceof HasOneRelationMarker)) {\n\t\t\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I,yBAAyB;AAAA,YAC7B,WAAW;AAAA,YACX,cAAc;AAAA,UAAA;AAGV,eAAA,aAAa,0BAA0B,QAAQ,eAAe;AAAA,QACzD,WAAA,cAAc,UAAU,SAAS,WAAW;AAChD,gBAAA,IAAI,aAAa,qDAAqD;AAAA,QAAA,OACtE;AACC,iBAAA,YAAY,cAAc,SAAS;AAAA,QAC3C;AAEI,YAAA,cAAc,SAAS,eAAe;AAEzC,0BAAgB,cAAc;AAAA,QAC/B;AACK,aAAA,aAAa,oBAAoB,QAAQ,YAAY;AAEtD,YAAA,cAAc,SAAS,eAAe;AAClC,iBAAA,4BAA4B,OAAO,aAAa;AAAA,QACxD;AAEK,aAAA,UAAU,eAAe,aAAa;AAAA,MAC5C;AAAA,IAAA,CACA;AAAA,EACF;AAAA,EAEA,CAAS,6BACR,WACA,OACA,SACyC;AACzC,UAAM,eAAe,UAAU,aAAa,IAAI,KAAK;AAErD,QAAI,iBAAiB,QAAW;AAC/B;AAAA,IACD;AACA,UAAM,yBAAyB,wBAAwB,MAAM,eAAe,CAAC,YAAY;AAEzF,eAAW,mBAAmB,wBAAwB;AACrD,YAAM,iBAAiB,UAAU,QAAQ,IAAI,eAAe;AAExD,UAAA,EAAE,0BAA0B,uBAAuB;AAChD,cAAA,IAAI,aAAa,OAAO;AAAA,MAC/B;AACM,YAAA;AAAA,IACP;AAAA,EACD;AACD;"}
|
|
1
|
+
{"version":3,"file":"EntityOperations.js","sources":["../../../../src/core/operations/EntityOperations.ts"],"sourcesContent":["import type { BatchUpdatesOptions, EntityAccessor, ErrorAccessor } from '../../accessors'\nimport { ServerId, UnpersistedEntityDummyId } from '../../accessorTree'\nimport { BindingError } from '../../BindingError'\nimport { EntityFieldMarkersContainer, HasOneRelationMarker } from '../../markers'\nimport type { FieldName } from '../../treeParameters'\nimport { assertNever } from '../../utils'\nimport type { AccessorErrorManager } from '../AccessorErrorManager'\nimport type { EventManager } from '../EventManager'\nimport { ErrorLocator, LocalizedBindingError } from '../exceptions'\nimport { MarkerComparator } from '../MarkerComparator'\nimport { EntityListState, EntityRealmState, EntityRealmStateStub, getEntityMarker, StateIterator } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\nimport { OperationsHelpers } from './OperationsHelpers'\nimport { EventListenersStore } from '../../treeParameters'\n\nexport class EntityOperations {\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic addError(entityRealm: EntityRealmState, error: ErrorAccessor.Error): () => void {\n\t\treturn this.accessorErrorManager.addError(entityRealm, error)\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityAccessor.RuntimeEntityEventListenerMap>(\n\t\tstate: EntityRealmState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\tif (state.eventListeners === undefined) {\n\t\t\tstate.eventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.eventListeners.add(event, listener)\n\t}\n\n\tpublic batchUpdates(state: EntityRealmState, performUpdates: EntityAccessor.BatchUpdatesHandler) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tperformUpdates(state.getAccessor, this.batchUpdatesOptions)\n\t\t})\n\t}\n\n\tpublic connectEntityAtField(outerState: EntityRealmState, fieldName: FieldName, entityToConnect: EntityAccessor) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst stateToConnect = OperationsHelpers.resolveAndPrepareEntityToConnect(this.treeStore, entityToConnect)\n\t\t\tconst fieldsToConnect = getEntityMarker(stateToConnect).fields\n\t\t\tconst persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)\n\n\t\t\tconst entityName = outerState.entity.entityName\n\t\t\tconst fieldSchema = this.treeStore.schema.getEntityFieldOrUndefined(entityName, fieldName)\n\n\t\t\tif (fieldSchema === undefined) {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`EntityAccessor.connectEntityAtField: Unknown field ${entityName}.${fieldName}.\\n\\n` +\n\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t)\n\t\t\t} else if (fieldSchema.__typename === '_Column') {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`EntityAccessor.connectEntityAtField: Cannot connect at field ${entityName}.${fieldName} because ` +\n\t\t\t\t\t\t`it's not a has-one relation.\\n\\n` +\n\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealm(outerState)) {\n\t\t\t\tconst targetHasOneMarkers = this.resolveHasOneRelationMarkers(\n\t\t\t\t\tgetEntityMarker(state).fields,\n\t\t\t\t\tfieldName,\n\t\t\t\t\t`Cannot connect at field '${fieldName}' as it doesn't refer to a has one relation.`,\n\t\t\t\t)\n\t\t\t\tfor (const targetHasOneMarker of targetHasOneMarkers) {\n\t\t\t\t\tconst previouslyConnectedState = state.children.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviouslyConnectedState === undefined ||\n\t\t\t\t\t\tpreviouslyConnectedState.type === 'field' ||\n\t\t\t\t\t\tpreviouslyConnectedState.type === 'entityList'\n\t\t\t\t\t) {\n\t\t\t\t\t\tOperationsHelpers.rejectInvalidAccessorTree()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (previouslyConnectedState.entity.entityName !== stateToConnect.entity.entityName) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`EntityAccessor.connectEntityAtField: Attempting to connect at field ${entityName}.${fieldName} ` +\n\t\t\t\t\t\t\t\t`an entity of type '${stateToConnect.entity.entityName}' but ` +\n\t\t\t\t\t\t\t\t`'${previouslyConnectedState.entity.entityName}' is expected.\\n\\n` +\n\t\t\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tMarkerComparator.assertEntityMarkersSubsetOf(targetHasOneMarker.fields, fieldsToConnect)\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (error instanceof LocalizedBindingError) {\n\t\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t\t`EntityAccessor: cannot connect entity with key '${entityToConnect.key}' because its fields are` +\n\t\t\t\t\t\t\t\t\t`incompatible with entities found at field '${fieldName}'. Make sure both trees are equivalent.\\n\\n` +\n\t\t\t\t\t\t\t\t\t`${error.message}\\n\\n` +\n\t\t\t\t\t\t\t\t\t(error.markerPath.length > 1\n\t\t\t\t\t\t\t\t\t\t? `Incompatibility found at: ${ErrorLocator.locateMarkerPath(error.markerPath)}.\\n\\n`\n\t\t\t\t\t\t\t\t\t\t: '') +\n\t\t\t\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(state)}.`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow error\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviouslyConnectedState === stateToConnect ||\n\t\t\t\t\t\tpreviouslyConnectedState.entity.id.value === stateToConnect.entity.id.value\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue // Do nothing.\n\t\t\t\t\t}\n\n\t\t\t\t\t// TODO remove from planned deletions if appropriate\n\n\t\t\t\t\tthis.treeStore.disposeOfRealm(previouslyConnectedState)\n\n\t\t\t\t\tlet changesDelta = 0\n\n\t\t\t\t\tif (previouslyConnectedState.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta -= previouslyConnectedState.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\tconst persistedId = persistedData?.get(targetHasOneMarker.placeholderName)\n\t\t\t\t\tif (persistedId instanceof ServerId && persistedId.value === stateToConnect.entity.id.value) {\n\t\t\t\t\t\tchangesDelta-- // It was removed from the list but now we're adding it back.\n\t\t\t\t\t} else if (persistedId instanceof ServerId && persistedId.value === previouslyConnectedState.entity.id.value) {\n\t\t\t\t\t\tchangesDelta++ // We're changing it from the persisted id.\n\t\t\t\t\t} else if (!previouslyConnectedState.entity.id.existsOnServer) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tpersistedId === null || // We're updating.\n\t\t\t\t\t\t\t(persistedId === undefined && // We're creating.\n\t\t\t\t\t\t\t\t(!fieldsToConnect.hasAtLeastOneBearingField || !targetHasOneMarker.parameters.isNonbearing))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (stateToConnect.type === 'entityRealm') {\n\t\t\t\t\t\t\tchangesDelta += stateToConnect.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\t// TODO do something about the existing state…\n\n\t\t\t\t\tthis.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tstateToConnect.entity.id,\n\t\t\t\t\t\tstateToConnect.entity.entityName,\n\t\t\t\t\t\tpreviouslyConnectedState.blueprint,\n\t\t\t\t\t\tstateToConnect,\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName)\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectEntityAtField(\n\t\touterState: EntityRealmState,\n\t\tfieldName: FieldName,\n\t\tinitializeReplacement: EntityAccessor.BatchUpdatesHandler | undefined,\n\t) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealm(outerState)) {\n\t\t\t\tconst targetHasOneMarkers = this.resolveHasOneRelationMarkers(\n\t\t\t\t\tgetEntityMarker(state).fields,\n\t\t\t\t\tfieldName,\n\t\t\t\t\t`Cannot disconnect at field '${fieldName}' as it doesn't refer to a has one relation.`,\n\t\t\t\t)\n\t\t\t\tfor (const targetHasOneMarker of targetHasOneMarkers) {\n\t\t\t\t\tconst stateToDisconnect = state.children.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tstateToDisconnect === undefined ||\n\t\t\t\t\t\t(stateToDisconnect.type !== 'entityRealm' && stateToDisconnect.type !== 'entityRealmStub')\n\t\t\t\t\t) {\n\t\t\t\t\t\tOperationsHelpers.rejectInvalidAccessorTree()\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.disposeOfRealm(stateToDisconnect)\n\n\t\t\t\t\tlet changesDelta = 0\n\n\t\t\t\t\tif (stateToDisconnect.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta -= stateToDisconnect.unpersistedChangesCount\n\t\t\t\t\t}\n\t\t\t\t\tconst persistedId = persistedData?.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (persistedId instanceof ServerId) {\n\t\t\t\t\t\tif (persistedId.value === stateToDisconnect.entity.id.value) {\n\t\t\t\t\t\t\tchangesDelta++ // Disconnecting the persisted entity.\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// Do nothing. The entity that is being disconnected is already different from the one that is persisted,\n\t\t\t\t\t\t\t// and so we must have already accounted for this change.\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (persistedId === undefined || persistedId === null) {\n\t\t\t\t\t\tif (stateToDisconnect.entity.id.existsOnServer) {\n\t\t\t\t\t\t\t// We had connected a persisted entity, which increased the changes count,\n\t\t\t\t\t\t\t// but now are disconnecting it again.\n\t\t\t\t\t\t\tchangesDelta--\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Do nothing. Disconnecting unpersisted entities doesn't change the count.\n\t\t\t\t\t}\n\n\t\t\t\t\tconst newEntity = this.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tnew UnpersistedEntityDummyId(),\n\t\t\t\t\t\tstateToDisconnect.entity.entityName,\n\t\t\t\t\t\tstateToDisconnect.blueprint,\n\t\t\t\t\t)\n\t\t\t\t\tthis.stateInitializer.runImmediateUserInitialization(newEntity, initializeReplacement)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName)\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic deleteEntity(realm: EntityRealmState) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst outerState = realm.entity\n\t\t\touterState.isScheduledForDeletion = true\n\n\t\t\tconst entityId = outerState.id\n\n\t\t\tfor (const realmToDelete of outerState.realms.values()) {\n\t\t\t\tlet parent: EntityRealmState | EntityRealmStateStub | EntityListState\n\t\t\t\tlet changesDelta = 0\n\n\t\t\t\tif (realmToDelete.blueprint.type === 'listEntity') {\n\t\t\t\t\tparent = realmToDelete.blueprint.parent\n\t\t\t\t\tparent.children.delete(entityId.value)\n\n\t\t\t\t\tif (entityId.existsOnServer) {\n\t\t\t\t\t\tif (parent.plannedRemovals === undefined) {\n\t\t\t\t\t\t\tparent.plannedRemovals = new Map()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\tparent.plannedRemovals.set(entityId.value, 'delete')\n\t\t\t\t\t}\n\t\t\t\t} else if (realmToDelete.blueprint.type === 'hasOne') {\n\t\t\t\t\tparent = realmToDelete.blueprint.parent\n\t\t\t\t\tconst placeholderName = realmToDelete.blueprint.marker.placeholderName\n\n\t\t\t\t\tif (entityId.existsOnServer) {\n\t\t\t\t\t\tif (parent.plannedHasOneDeletions === undefined) {\n\t\t\t\t\t\t\tparent.plannedHasOneDeletions = new Map()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\tparent.plannedHasOneDeletions.set(placeholderName, realmToDelete)\n\t\t\t\t\t}\n\t\t\t\t\tthis.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tnew UnpersistedEntityDummyId(),\n\t\t\t\t\t\touterState.entityName,\n\t\t\t\t\t\trealmToDelete.blueprint,\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(parent, placeholderName)\n\t\t\t\t} else if (realmToDelete.blueprint.type === 'subTree') {\n\t\t\t\t\tthrow new BindingError('Deleting top-level entities is not yet implemented.')\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(realmToDelete.blueprint)\n\t\t\t\t}\n\n\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t// Undoing whatever this had caused\n\t\t\t\t\tchangesDelta -= realmToDelete.unpersistedChangesCount\n\t\t\t\t}\n\t\t\t\tthis.eventManager.registerJustUpdated(parent, changesDelta)\n\n\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\tparent.childrenWithPendingUpdates?.delete(realmToDelete)\n\t\t\t\t}\n\n\t\t\t\tthis.treeStore.disposeOfRealm(realmToDelete)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate *resolveHasOneRelationMarkers(\n\t\tcontainer: EntityFieldMarkersContainer,\n\t\tfield: FieldName,\n\t\tmessage: string,\n\t): IterableIterator<HasOneRelationMarker> {\n\t\tconst placeholders = container.placeholders.get(field)\n\n\t\tif (placeholders === undefined) {\n\t\t\treturn\n\t\t}\n\t\tconst normalizedPlaceholders = placeholders instanceof Set ? placeholders : [placeholders]\n\n\t\tfor (const placeholderName of normalizedPlaceholders) {\n\t\t\tconst hasOneRelation = container.markers.get(placeholderName)\n\n\t\t\tif (!(hasOneRelation instanceof HasOneRelationMarker)) {\n\t\t\t\tthrow new BindingError(message)\n\t\t\t}\n\t\t\tyield hasOneRelation\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;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,QAAQ,eAAe;AAAA,QACzD,WAAA,cAAc,UAAU,SAAS,WAAW;AAChD,gBAAA,IAAI,aAAa,qDAAqD;AAAA,QAAA,OACtE;AACC,iBAAA,YAAY,cAAc,SAAS;AAAA,QAC3C;AAEI,YAAA,cAAc,SAAS,eAAe;AAEzC,0BAAgB,cAAc;AAAA,QAC/B;AACK,aAAA,aAAa,oBAAoB,QAAQ,YAAY;AAEtD,YAAA,cAAc,SAAS,eAAe;AAClC,iBAAA,4BAA4B,OAAO,aAAa;AAAA,QACxD;AAEK,aAAA,UAAU,eAAe,aAAa;AAAA,MAC5C;AAAA,IAAA,CACA;AAAA,EACF;AAAA,EAEA,CAAS,6BACR,WACA,OACA,SACyC;AACzC,UAAM,eAAe,UAAU,aAAa,IAAI,KAAK;AAErD,QAAI,iBAAiB,QAAW;AAC/B;AAAA,IACD;AACA,UAAM,yBAAyB,wBAAwB,MAAM,eAAe,CAAC,YAAY;AAEzF,eAAW,mBAAmB,wBAAwB;AACrD,YAAM,iBAAiB,UAAU,QAAQ,IAAI,eAAe;AAExD,UAAA,EAAE,0BAA0B,uBAAuB;AAChD,cAAA,IAAI,aAAa,OAAO;AAAA,MAC/B;AACM,YAAA;AAAA,IACP;AAAA,EACD;AACD;"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { validate } from "uuid";
|
|
2
1
|
import { BindingError } from "../../BindingError.js";
|
|
3
2
|
import { PRIMARY_KEY_NAME } from "../../bindingTypes.js";
|
|
4
3
|
import { EventManager } from "../EventManager.js";
|
|
5
4
|
import { OperationsHelpers } from "./OperationsHelpers.js";
|
|
6
5
|
import { EventListenersStore } from "../../treeParameters/EventListenersStore.js";
|
|
7
|
-
import {
|
|
6
|
+
import { ClientGeneratedUuid } from "../../accessorTree/RuntimeId.js";
|
|
8
7
|
import { StateIterator } from "../state/StateIterator.js";
|
|
9
8
|
import { getEntityMarker } from "../state/getEntityMarker.js";
|
|
10
9
|
import { FieldAccessor } from "../../accessors/FieldAccessor.js";
|
|
@@ -32,25 +31,6 @@ class FieldOperations {
|
|
|
32
31
|
const { placeholderName, parent } = fieldState;
|
|
33
32
|
if (placeholderName === PRIMARY_KEY_NAME) {
|
|
34
33
|
const entity = fieldState.parent.entity;
|
|
35
|
-
{
|
|
36
|
-
if (newValue !== fieldState.value && (fieldState.touchLog !== void 0 || entity.hasIdSetInStone)) {
|
|
37
|
-
throw new BindingError(
|
|
38
|
-
`Trying to set the '${PRIMARY_KEY_NAME}' field for the second time. This is prohibited.
|
|
39
|
-
Once set, it is immutable.`
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
if (typeof newValue !== "string" || !validate(newValue)) {
|
|
43
|
-
throw new BindingError(
|
|
44
|
-
`Invalid value supplied for the '${PRIMARY_KEY_NAME}' field. Expecting a valid uuid but '${newValue}' was given.
|
|
45
|
-
Hint: you may use 'FieldAccessor.asUuid.setToUuid()'.`
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
if (this.treeStore.entityStore.has(ServerId.formatUniqueValue(newValue, entity.entityName))) {
|
|
49
|
-
throw new BindingError(
|
|
50
|
-
`Trying to set the '${PRIMARY_KEY_NAME}' field to '${newValue}' which is a valid uuid but is not unique. It is already in use by an existing entity.`
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
34
|
if (typeof newValue !== "string") {
|
|
55
35
|
throw new BindingError();
|
|
56
36
|
}
|