@contember/binding 1.0.0-rc.0 → 1.0.0-rc.11
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/accessorSorting/moveEntity.js +1 -1
- package/dist/development/accessorSorting/moveEntity.js.map +1 -1
- package/dist/development/accessors/ErrorAccessor.js +1 -1
- package/dist/development/accessors/ErrorAccessor.js.map +1 -1
- package/dist/development/accessors/FieldAccessor.js +3 -2
- package/dist/development/accessors/FieldAccessor.js.map +1 -1
- package/dist/development/core/AccessorErrorManager.js +3 -3
- package/dist/development/core/AccessorErrorManager.js.map +1 -1
- package/dist/development/core/DataBinding.js +8 -4
- package/dist/development/core/DataBinding.js.map +1 -1
- package/dist/development/core/ErrorsPreprocessor.js +6 -6
- package/dist/development/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/development/core/EventManager.js +7 -7
- package/dist/development/core/EventManager.js.map +1 -1
- package/dist/development/core/IncrementalMarkerBuilder.js +1 -1
- package/dist/development/core/IncrementalMarkerBuilder.js.map +1 -1
- package/dist/development/core/MarkerMerger.js +2 -2
- package/dist/development/core/MarkerMerger.js.map +1 -1
- package/dist/development/core/MarkerTreeGenerator.js +2 -2
- package/dist/development/core/MarkerTreeGenerator.js.map +1 -1
- package/dist/development/core/MutationGenerator.js +4 -4
- package/dist/development/core/MutationGenerator.js.map +1 -1
- package/dist/development/core/RequestResponseNormalizer.js +5 -5
- package/dist/development/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/development/core/StateInitializer.js +13 -6
- package/dist/development/core/StateInitializer.js.map +1 -1
- package/dist/development/core/TreeAugmenter.js +2 -2
- package/dist/development/core/TreeAugmenter.js.map +1 -1
- package/dist/development/core/TreeFilterGenerator.js +2 -2
- package/dist/development/core/TreeFilterGenerator.js.map +1 -1
- package/dist/development/core/TreeStore.js +6 -6
- package/dist/development/core/TreeStore.js.map +1 -1
- package/dist/development/core/operations/EntityOperations.js +2 -2
- package/dist/development/core/operations/EntityOperations.js.map +1 -1
- package/dist/development/core/operations/FieldOperations.js +1 -1
- package/dist/development/core/operations/FieldOperations.js.map +1 -1
- package/dist/development/core/operations/ListOperations.js +1 -1
- package/dist/development/core/operations/ListOperations.js.map +1 -1
- package/dist/development/core/schema/SchemaPreprocessor.js +3 -3
- package/dist/development/core/schema/SchemaPreprocessor.js.map +1 -1
- package/dist/development/dao/Environment.js +3 -3
- package/dist/development/dao/Environment.js.map +1 -1
- package/dist/development/fieldHelpers/helpers/TemporalFieldHelper.js +1 -1
- package/dist/development/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -1
- package/dist/development/fieldHelpers/helpers/UuidFieldHelper.js +1 -1
- package/dist/development/fieldHelpers/helpers/UuidFieldHelper.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 +5 -5
- package/dist/development/queryLanguage/MarkerFactory.js.map +1 -1
- package/dist/development/queryLanguage/QueryLanguage.js +2 -2
- package/dist/development/queryLanguage/QueryLanguage.js.map +1 -1
- package/dist/development/queryLanguage/tokenList.js +1 -1
- package/dist/development/queryLanguage/tokenList.js.map +1 -1
- package/dist/development/structures/BijectiveIndexedMap.js +2 -2
- 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 +1 -1
- package/dist/development/structures/WeakIdCache.js.map +1 -1
- package/dist/development/treeParameters/EventListenersStore.js +3 -3
- package/dist/development/treeParameters/EventListenersStore.js.map +1 -1
- package/dist/development/utils/assertNever.js +1 -1
- package/dist/development/utils/assertNever.js.map +1 -1
- package/dist/production/accessorSorting/moveEntity.js +1 -1
- package/dist/production/accessorSorting/moveEntity.js.map +1 -1
- package/dist/production/accessors/ErrorAccessor.js +1 -1
- package/dist/production/accessors/ErrorAccessor.js.map +1 -1
- package/dist/production/accessors/FieldAccessor.js +3 -2
- package/dist/production/accessors/FieldAccessor.js.map +1 -1
- package/dist/production/core/AccessorErrorManager.js +3 -3
- package/dist/production/core/AccessorErrorManager.js.map +1 -1
- package/dist/production/core/DataBinding.js +8 -4
- package/dist/production/core/DataBinding.js.map +1 -1
- package/dist/production/core/ErrorsPreprocessor.js +6 -6
- package/dist/production/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/production/core/EventManager.js +7 -7
- package/dist/production/core/EventManager.js.map +1 -1
- package/dist/production/core/IncrementalMarkerBuilder.js +1 -1
- package/dist/production/core/IncrementalMarkerBuilder.js.map +1 -1
- package/dist/production/core/MarkerMerger.js +2 -2
- package/dist/production/core/MarkerMerger.js.map +1 -1
- package/dist/production/core/MarkerTreeGenerator.js +2 -2
- package/dist/production/core/MarkerTreeGenerator.js.map +1 -1
- package/dist/production/core/MutationGenerator.js +4 -4
- package/dist/production/core/MutationGenerator.js.map +1 -1
- package/dist/production/core/RequestResponseNormalizer.js +5 -5
- package/dist/production/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/production/core/StateInitializer.js +13 -6
- package/dist/production/core/StateInitializer.js.map +1 -1
- package/dist/production/core/TreeAugmenter.js +2 -2
- package/dist/production/core/TreeAugmenter.js.map +1 -1
- package/dist/production/core/TreeFilterGenerator.js +2 -2
- package/dist/production/core/TreeFilterGenerator.js.map +1 -1
- package/dist/production/core/TreeStore.js +6 -6
- package/dist/production/core/TreeStore.js.map +1 -1
- package/dist/production/core/operations/EntityOperations.js +2 -2
- package/dist/production/core/operations/EntityOperations.js.map +1 -1
- package/dist/production/core/operations/FieldOperations.js +1 -1
- package/dist/production/core/operations/FieldOperations.js.map +1 -1
- package/dist/production/core/operations/ListOperations.js +1 -1
- package/dist/production/core/operations/ListOperations.js.map +1 -1
- package/dist/production/core/schema/SchemaPreprocessor.js +3 -3
- package/dist/production/core/schema/SchemaPreprocessor.js.map +1 -1
- package/dist/production/dao/Environment.js +3 -3
- package/dist/production/dao/Environment.js.map +1 -1
- package/dist/production/fieldHelpers/helpers/TemporalFieldHelper.js +1 -1
- package/dist/production/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -1
- package/dist/production/fieldHelpers/helpers/UuidFieldHelper.js +1 -1
- package/dist/production/fieldHelpers/helpers/UuidFieldHelper.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 +5 -5
- package/dist/production/queryLanguage/MarkerFactory.js.map +1 -1
- package/dist/production/queryLanguage/QueryLanguage.js +2 -2
- package/dist/production/queryLanguage/QueryLanguage.js.map +1 -1
- package/dist/production/queryLanguage/tokenList.js +1 -1
- package/dist/production/queryLanguage/tokenList.js.map +1 -1
- package/dist/production/structures/BijectiveIndexedMap.js +2 -2
- 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 +1 -1
- package/dist/production/structures/WeakIdCache.js.map +1 -1
- package/dist/production/treeParameters/EventListenersStore.js +3 -3
- package/dist/production/treeParameters/EventListenersStore.js.map +1 -1
- package/dist/production/utils/assertNever.js +1 -1
- package/dist/production/utils/assertNever.js.map +1 -1
- package/dist/types/BindingError.d.ts +4 -0
- package/dist/types/BindingError.d.ts.map +1 -0
- package/dist/types/accessorPropagation/AccessorProvider.d.ts +8 -0
- package/dist/types/accessorPropagation/AccessorProvider.d.ts.map +1 -0
- package/dist/types/accessorPropagation/BindingOperationsContext.d.ts +5 -0
- package/dist/types/accessorPropagation/BindingOperationsContext.d.ts.map +1 -0
- package/dist/types/accessorPropagation/BindingOperationsProvider.d.ts +8 -0
- package/dist/types/accessorPropagation/BindingOperationsProvider.d.ts.map +1 -0
- package/dist/types/accessorPropagation/EntityKeyContext.d.ts +3 -0
- package/dist/types/accessorPropagation/EntityKeyContext.d.ts.map +1 -0
- package/dist/types/accessorPropagation/EntityKeyProvider.d.ts +7 -0
- package/dist/types/accessorPropagation/EntityKeyProvider.d.ts.map +1 -0
- package/dist/types/accessorPropagation/EnvironmentContext.d.ts +4 -0
- package/dist/types/accessorPropagation/EnvironmentContext.d.ts.map +1 -0
- package/dist/types/accessorPropagation/TreeRootIdContext.d.ts +3 -0
- package/dist/types/accessorPropagation/TreeRootIdContext.d.ts.map +1 -0
- package/dist/types/accessorPropagation/TreeRootIdProvider.d.ts +8 -0
- package/dist/types/accessorPropagation/TreeRootIdProvider.d.ts.map +1 -0
- package/dist/types/accessorPropagation/index.d.ts +27 -0
- package/dist/types/accessorPropagation/index.d.ts.map +1 -0
- package/dist/types/accessorPropagation/useAccessorUpdateSubscription.d.ts +16 -0
- package/dist/types/accessorPropagation/useAccessorUpdateSubscription.d.ts.map +1 -0
- package/dist/types/accessorPropagation/useBindingOperations.d.ts +3 -0
- package/dist/types/accessorPropagation/useBindingOperations.d.ts.map +1 -0
- package/dist/types/accessorPropagation/useDesugaredRelativeEntityList.d.ts +11 -0
- package/dist/types/accessorPropagation/useDesugaredRelativeEntityList.d.ts.map +1 -0
- package/dist/types/accessorPropagation/useDesugaredRelativeSingleEntity.d.ts +11 -0
- package/dist/types/accessorPropagation/useDesugaredRelativeSingleEntity.d.ts.map +1 -0
- package/dist/types/accessorPropagation/useDesugaredRelativeSingleField.d.ts +11 -0
- package/dist/types/accessorPropagation/useDesugaredRelativeSingleField.d.ts.map +1 -0
- package/dist/types/accessorPropagation/useEntity.d.ts +7 -0
- package/dist/types/accessorPropagation/useEntity.d.ts.map +1 -0
- package/dist/types/accessorPropagation/useEntityKey.d.ts +2 -0
- package/dist/types/accessorPropagation/useEntityKey.d.ts.map +1 -0
- package/dist/types/accessorPropagation/useEntityList.d.ts +6 -0
- package/dist/types/accessorPropagation/useEntityList.d.ts.map +1 -0
- package/dist/types/accessorPropagation/useEntityListSubTree.d.ts +4 -0
- package/dist/types/accessorPropagation/useEntityListSubTree.d.ts.map +1 -0
- package/dist/types/accessorPropagation/useEntityListSubTreeParameters.d.ts +5 -0
- package/dist/types/accessorPropagation/useEntityListSubTreeParameters.d.ts.map +1 -0
- package/dist/types/accessorPropagation/useEntitySubTree.d.ts +4 -0
- package/dist/types/accessorPropagation/useEntitySubTree.d.ts.map +1 -0
- package/dist/types/accessorPropagation/useEntitySubTreeParameters.d.ts +5 -0
- package/dist/types/accessorPropagation/useEntitySubTreeParameters.d.ts.map +1 -0
- package/dist/types/accessorPropagation/useEnvironment.d.ts +3 -0
- package/dist/types/accessorPropagation/useEnvironment.d.ts.map +1 -0
- package/dist/types/accessorPropagation/useField.d.ts +6 -0
- package/dist/types/accessorPropagation/useField.d.ts.map +1 -0
- package/dist/types/accessorPropagation/useGetEntityByKey.d.ts +3 -0
- package/dist/types/accessorPropagation/useGetEntityByKey.d.ts.map +1 -0
- package/dist/types/accessorPropagation/useGetEntityListSubTree.d.ts +4 -0
- package/dist/types/accessorPropagation/useGetEntityListSubTree.d.ts.map +1 -0
- package/dist/types/accessorPropagation/useGetEntitySubTree.d.ts +4 -0
- package/dist/types/accessorPropagation/useGetEntitySubTree.d.ts.map +1 -0
- package/dist/types/accessorPropagation/useGetTreeFilters.d.ts +3 -0
- package/dist/types/accessorPropagation/useGetTreeFilters.d.ts.map +1 -0
- package/dist/types/accessorPropagation/useHasEntity.d.ts +2 -0
- package/dist/types/accessorPropagation/useHasEntity.d.ts.map +1 -0
- package/dist/types/accessorPropagation/usePersist.d.ts +3 -0
- package/dist/types/accessorPropagation/usePersist.d.ts.map +1 -0
- package/dist/types/accessorPropagation/useTreeRootId.d.ts +3 -0
- package/dist/types/accessorPropagation/useTreeRootId.d.ts.map +1 -0
- package/dist/types/accessorSorting/SetOrderFieldOnCreate.d.ts +10 -0
- package/dist/types/accessorSorting/SetOrderFieldOnCreate.d.ts.map +1 -0
- package/dist/types/accessorSorting/SortedEntities.d.ts +9 -0
- package/dist/types/accessorSorting/SortedEntities.d.ts.map +1 -0
- package/dist/types/accessorSorting/addEntityAtIndex.d.ts +4 -0
- package/dist/types/accessorSorting/addEntityAtIndex.d.ts.map +1 -0
- package/dist/types/accessorSorting/errors.d.ts +6 -0
- package/dist/types/accessorSorting/errors.d.ts.map +1 -0
- package/dist/types/accessorSorting/index.d.ts +8 -0
- package/dist/types/accessorSorting/index.d.ts.map +1 -0
- package/dist/types/accessorSorting/moveEntity.d.ts +5 -0
- package/dist/types/accessorSorting/moveEntity.d.ts.map +1 -0
- package/dist/types/accessorSorting/repairEntitiesOrder.d.ts +4 -0
- package/dist/types/accessorSorting/repairEntitiesOrder.d.ts.map +1 -0
- package/dist/types/accessorSorting/sortEntities.d.ts +4 -0
- package/dist/types/accessorSorting/sortEntities.d.ts.map +1 -0
- package/dist/types/accessorSorting/useSortedEntities.d.ts +5 -0
- package/dist/types/accessorSorting/useSortedEntities.d.ts.map +1 -0
- package/dist/types/accessorTree/AccessorTree.d.ts +11 -0
- package/dist/types/accessorTree/AccessorTree.d.ts.map +1 -0
- package/dist/types/accessorTree/AccessorTreeState.d.ts +15 -0
- package/dist/types/accessorTree/AccessorTreeState.d.ts.map +1 -0
- package/dist/types/accessorTree/AccessorTreeStateAction.d.ts +12 -0
- package/dist/types/accessorTree/AccessorTreeStateAction.d.ts.map +1 -0
- package/dist/types/accessorTree/AccessorTreeStateMetadata.d.ts +4 -0
- package/dist/types/accessorTree/AccessorTreeStateMetadata.d.ts.map +1 -0
- package/dist/types/accessorTree/AccessorTreeStateOptions.d.ts +7 -0
- package/dist/types/accessorTree/AccessorTreeStateOptions.d.ts.map +1 -0
- package/dist/types/accessorTree/DirtinessContext.d.ts +3 -0
- package/dist/types/accessorTree/DirtinessContext.d.ts.map +1 -0
- package/dist/types/accessorTree/MutationRequestResponse.d.ts +44 -0
- package/dist/types/accessorTree/MutationRequestResponse.d.ts.map +1 -0
- package/dist/types/accessorTree/MutationStateContext.d.ts +3 -0
- package/dist/types/accessorTree/MutationStateContext.d.ts.map +1 -0
- package/dist/types/accessorTree/NormalizedPersistedData.d.ts +13 -0
- package/dist/types/accessorTree/NormalizedPersistedData.d.ts.map +1 -0
- package/dist/types/accessorTree/PersistResult.d.ts +24 -0
- package/dist/types/accessorTree/PersistResult.d.ts.map +1 -0
- package/dist/types/accessorTree/QueryRequestResponse.d.ts +15 -0
- package/dist/types/accessorTree/QueryRequestResponse.d.ts.map +1 -0
- package/dist/types/accessorTree/RequestError.d.ts +13 -0
- package/dist/types/accessorTree/RequestError.d.ts.map +1 -0
- package/dist/types/accessorTree/RuntimeId.d.ts +25 -0
- package/dist/types/accessorTree/RuntimeId.d.ts.map +1 -0
- package/dist/types/accessorTree/accessorTreeStateReducer.d.ts +4 -0
- package/dist/types/accessorTree/accessorTreeStateReducer.d.ts.map +1 -0
- package/dist/types/accessorTree/index.d.ts +19 -0
- package/dist/types/accessorTree/index.d.ts.map +1 -0
- package/dist/types/accessorTree/metadataToRequestError.d.ts +4 -0
- package/dist/types/accessorTree/metadataToRequestError.d.ts.map +1 -0
- package/dist/types/accessorTree/useDataBinding.d.ts +4 -0
- package/dist/types/accessorTree/useDataBinding.d.ts.map +1 -0
- package/dist/types/accessorTree/useDirtinessState.d.ts +2 -0
- package/dist/types/accessorTree/useDirtinessState.d.ts.map +1 -0
- package/dist/types/accessorTree/useMutationState.d.ts +2 -0
- package/dist/types/accessorTree/useMutationState.d.ts.map +1 -0
- package/dist/types/accessors/AsyncBatchUpdatesOptions.d.ts +8 -0
- package/dist/types/accessors/AsyncBatchUpdatesOptions.d.ts.map +1 -0
- package/dist/types/accessors/BatchUpdatesOptions.d.ts +9 -0
- package/dist/types/accessors/BatchUpdatesOptions.d.ts.map +1 -0
- package/dist/types/accessors/BindingConfig.d.ts +8 -0
- package/dist/types/accessors/BindingConfig.d.ts.map +1 -0
- package/dist/types/accessors/BindingOperations.d.ts +12 -0
- package/dist/types/accessors/BindingOperations.d.ts.map +1 -0
- package/dist/types/accessors/EntityAccessor.d.ts +90 -0
- package/dist/types/accessors/EntityAccessor.d.ts.map +1 -0
- package/dist/types/accessors/EntityListAccessor.d.ts +84 -0
- package/dist/types/accessors/EntityListAccessor.d.ts.map +1 -0
- package/dist/types/accessors/ErrorAccessor.d.ts +26 -0
- package/dist/types/accessors/ErrorAccessor.d.ts.map +1 -0
- package/dist/types/accessors/Errorable.d.ts +5 -0
- package/dist/types/accessors/Errorable.d.ts.map +1 -0
- package/dist/types/accessors/ExtendTree.d.ts +9 -0
- package/dist/types/accessors/ExtendTree.d.ts.map +1 -0
- package/dist/types/accessors/FieldAccessor.d.ts +55 -0
- package/dist/types/accessors/FieldAccessor.d.ts.map +1 -0
- package/dist/types/accessors/GetEntityByKey.d.ts +3 -0
- package/dist/types/accessors/GetEntityByKey.d.ts.map +1 -0
- package/dist/types/accessors/GetEntityListSubTree.d.ts +5 -0
- package/dist/types/accessors/GetEntityListSubTree.d.ts.map +1 -0
- package/dist/types/accessors/GetEntitySubTree.d.ts +5 -0
- package/dist/types/accessors/GetEntitySubTree.d.ts.map +1 -0
- package/dist/types/accessors/Persist.d.ts +10 -0
- package/dist/types/accessors/Persist.d.ts.map +1 -0
- package/dist/types/accessors/PersistErrorOptions.d.ts +10 -0
- package/dist/types/accessors/PersistErrorOptions.d.ts.map +1 -0
- package/dist/types/accessors/PersistSuccessOptions.d.ts +5 -0
- package/dist/types/accessors/PersistSuccessOptions.d.ts.map +1 -0
- package/dist/types/accessors/TreeRootAccessor.d.ts +11 -0
- package/dist/types/accessors/TreeRootAccessor.d.ts.map +1 -0
- package/dist/types/accessors/index.d.ts +18 -0
- package/dist/types/accessors/index.d.ts.map +1 -0
- package/dist/types/bindingTypes.d.ts +4 -0
- package/dist/types/bindingTypes.d.ts.map +1 -0
- package/dist/types/core/AccessorErrorManager.d.ts +24 -0
- package/dist/types/core/AccessorErrorManager.d.ts.map +1 -0
- package/dist/types/core/Config.d.ts +9 -0
- package/dist/types/core/Config.d.ts.map +1 -0
- package/dist/types/core/DataBinding.d.ts +37 -0
- package/dist/types/core/DataBinding.d.ts.map +1 -0
- package/dist/types/core/DirtinessTracker.d.ts +12 -0
- package/dist/types/core/DirtinessTracker.d.ts.map +1 -0
- package/dist/types/core/ErrorsPreprocessor.d.ts +33 -0
- package/dist/types/core/ErrorsPreprocessor.d.ts.map +1 -0
- package/dist/types/core/EventManager.d.ts +56 -0
- package/dist/types/core/EventManager.d.ts.map +1 -0
- package/dist/types/core/IncrementalMarkerBuilder.d.ts +7 -0
- package/dist/types/core/IncrementalMarkerBuilder.d.ts.map +1 -0
- package/dist/types/core/MarkerComparator.d.ts +8 -0
- package/dist/types/core/MarkerComparator.d.ts.map +1 -0
- package/dist/types/core/MarkerMerger.d.ts +22 -0
- package/dist/types/core/MarkerMerger.d.ts.map +1 -0
- package/dist/types/core/MarkerTreeGenerator.d.ts +14 -0
- package/dist/types/core/MarkerTreeGenerator.d.ts.map +1 -0
- package/dist/types/core/MutationGenerator.d.ts +18 -0
- package/dist/types/core/MutationGenerator.d.ts.map +1 -0
- package/dist/types/core/QueryGenerator.d.ts +14 -0
- package/dist/types/core/QueryGenerator.d.ts.map +1 -0
- package/dist/types/core/RealmKeyGenerator.d.ts +11 -0
- package/dist/types/core/RealmKeyGenerator.d.ts.map +1 -0
- package/dist/types/core/RequestResponseNormalizer.d.ts +11 -0
- package/dist/types/core/RequestResponseNormalizer.d.ts.map +1 -0
- package/dist/types/core/StateInitializer.d.ts +38 -0
- package/dist/types/core/StateInitializer.d.ts.map +1 -0
- package/dist/types/core/TreeAugmenter.d.ts +20 -0
- package/dist/types/core/TreeAugmenter.d.ts.map +1 -0
- package/dist/types/core/TreeFilterGenerator.d.ts +13 -0
- package/dist/types/core/TreeFilterGenerator.d.ts.map +1 -0
- package/dist/types/core/TreeParameterMerger.d.ts +20 -0
- package/dist/types/core/TreeParameterMerger.d.ts.map +1 -0
- package/dist/types/core/TreeStore.d.ts +32 -0
- package/dist/types/core/TreeStore.d.ts.map +1 -0
- package/dist/types/core/UpdateMetadata.d.ts +4 -0
- package/dist/types/core/UpdateMetadata.d.ts.map +1 -0
- package/dist/types/core/VariableInputTransformer.d.ts +7 -0
- package/dist/types/core/VariableInputTransformer.d.ts.map +1 -0
- package/dist/types/core/exceptions/ErrorLocator.d.ts +8 -0
- package/dist/types/core/exceptions/ErrorLocator.d.ts.map +1 -0
- package/dist/types/core/exceptions/LocalizedBindingError.d.ts +9 -0
- package/dist/types/core/exceptions/LocalizedBindingError.d.ts.map +1 -0
- package/dist/types/core/exceptions/MarkerSugarer.d.ts +10 -0
- package/dist/types/core/exceptions/MarkerSugarer.d.ts.map +1 -0
- package/dist/types/core/exceptions/RawMarkerPath.d.ts +3 -0
- package/dist/types/core/exceptions/RawMarkerPath.d.ts.map +1 -0
- package/dist/types/core/exceptions/TreeParameterSugarer.d.ts +11 -0
- package/dist/types/core/exceptions/TreeParameterSugarer.d.ts.map +1 -0
- package/dist/types/core/exceptions/index.d.ts +6 -0
- package/dist/types/core/exceptions/index.d.ts.map +1 -0
- package/dist/types/core/factories/createBatchUpdatesOptions.d.ts +5 -0
- package/dist/types/core/factories/createBatchUpdatesOptions.d.ts.map +1 -0
- package/dist/types/core/factories/index.d.ts +2 -0
- package/dist/types/core/factories/index.d.ts.map +1 -0
- package/dist/types/core/index.d.ts +6 -0
- package/dist/types/core/index.d.ts.map +1 -0
- package/dist/types/core/operations/EntityOperations.d.ts +26 -0
- package/dist/types/core/operations/EntityOperations.d.ts.map +1 -0
- package/dist/types/core/operations/FieldOperations.d.ts +22 -0
- package/dist/types/core/operations/FieldOperations.d.ts.map +1 -0
- package/dist/types/core/operations/ListOperations.d.ts +32 -0
- package/dist/types/core/operations/ListOperations.d.ts.map +1 -0
- package/dist/types/core/operations/OperationsHelpers.d.ts +14 -0
- package/dist/types/core/operations/OperationsHelpers.d.ts.map +1 -0
- package/dist/types/core/operations/index.d.ts +4 -0
- package/dist/types/core/operations/index.d.ts.map +1 -0
- package/dist/types/core/requestAliases/MutationAlias.d.ts +9 -0
- package/dist/types/core/requestAliases/MutationAlias.d.ts.map +1 -0
- package/dist/types/core/requestAliases/TopLevelMutationOperation.d.ts +11 -0
- package/dist/types/core/requestAliases/TopLevelMutationOperation.d.ts.map +1 -0
- package/dist/types/core/requestAliases/index.d.ts +5 -0
- package/dist/types/core/requestAliases/index.d.ts.map +1 -0
- package/dist/types/core/requestAliases/mutationOperationSubTreeType.d.ts +5 -0
- package/dist/types/core/requestAliases/mutationOperationSubTreeType.d.ts.map +1 -0
- package/dist/types/core/requestAliases/mutationOperationType.d.ts +6 -0
- package/dist/types/core/requestAliases/mutationOperationType.d.ts.map +1 -0
- package/dist/types/core/schema/RawSchema.d.ts +7 -0
- package/dist/types/core/schema/RawSchema.d.ts.map +1 -0
- package/dist/types/core/schema/RawSchemaEntity.d.ts +12 -0
- package/dist/types/core/schema/RawSchemaEntity.d.ts.map +1 -0
- package/dist/types/core/schema/RawSchemaEnum.d.ts +6 -0
- package/dist/types/core/schema/RawSchemaEnum.d.ts.map +1 -0
- package/dist/types/core/schema/Schema.d.ts +9 -0
- package/dist/types/core/schema/Schema.d.ts.map +1 -0
- package/dist/types/core/schema/SchemaColumn.d.ts +12 -0
- package/dist/types/core/schema/SchemaColumn.d.ts.map +1 -0
- package/dist/types/core/schema/SchemaColumnType.d.ts +3 -0
- package/dist/types/core/schema/SchemaColumnType.d.ts.map +1 -0
- package/dist/types/core/schema/SchemaEntities.d.ts +4 -0
- package/dist/types/core/schema/SchemaEntities.d.ts.map +1 -0
- package/dist/types/core/schema/SchemaEntity.d.ts +10 -0
- package/dist/types/core/schema/SchemaEntity.d.ts.map +1 -0
- package/dist/types/core/schema/SchemaEnums.d.ts +4 -0
- package/dist/types/core/schema/SchemaEnums.d.ts.map +1 -0
- package/dist/types/core/schema/SchemaField.d.ts +4 -0
- package/dist/types/core/schema/SchemaField.d.ts.map +1 -0
- package/dist/types/core/schema/SchemaFields.d.ts +4 -0
- package/dist/types/core/schema/SchemaFields.d.ts.map +1 -0
- package/dist/types/core/schema/SchemaLoader.d.ts +7 -0
- package/dist/types/core/schema/SchemaLoader.d.ts.map +1 -0
- package/dist/types/core/schema/SchemaPreprocessor.d.ts +9 -0
- package/dist/types/core/schema/SchemaPreprocessor.d.ts.map +1 -0
- package/dist/types/core/schema/SchemaRelation.d.ts +24 -0
- package/dist/types/core/schema/SchemaRelation.d.ts.map +1 -0
- package/dist/types/core/schema/SchemaRelationOrderBy.d.ts +5 -0
- package/dist/types/core/schema/SchemaRelationOrderBy.d.ts.map +1 -0
- package/dist/types/core/schema/SchemaStore.d.ts +7 -0
- package/dist/types/core/schema/SchemaStore.d.ts.map +1 -0
- package/dist/types/core/schema/SchemaUniqueConstraint.d.ts +5 -0
- package/dist/types/core/schema/SchemaUniqueConstraint.d.ts.map +1 -0
- package/dist/types/core/schema/SchemaValidator.d.ts +14 -0
- package/dist/types/core/schema/SchemaValidator.d.ts.map +1 -0
- package/dist/types/core/schema/index.d.ts +15 -0
- package/dist/types/core/schema/index.d.ts.map +1 -0
- package/dist/types/core/state/EntityListState.d.ts +27 -0
- package/dist/types/core/state/EntityListState.d.ts.map +1 -0
- package/dist/types/core/state/EntityRealmState.d.ts +44 -0
- package/dist/types/core/state/EntityRealmState.d.ts.map +1 -0
- package/dist/types/core/state/EntityState.d.ts +12 -0
- package/dist/types/core/state/EntityState.d.ts.map +1 -0
- package/dist/types/core/state/FieldState.d.ts +19 -0
- package/dist/types/core/state/FieldState.d.ts.map +1 -0
- package/dist/types/core/state/StateIterator.d.ts +14 -0
- package/dist/types/core/state/StateIterator.d.ts.map +1 -0
- package/dist/types/core/state/StateNode.d.ts +8 -0
- package/dist/types/core/state/StateNode.d.ts.map +1 -0
- package/dist/types/core/state/getEntityMarker.d.ts +3 -0
- package/dist/types/core/state/getEntityMarker.d.ts.map +1 -0
- package/dist/types/core/state/index.d.ts +8 -0
- package/dist/types/core/state/index.d.ts.map +1 -0
- package/dist/types/core/utils/getCombinedSignal.d.ts +2 -0
- package/dist/types/core/utils/getCombinedSignal.d.ts.map +1 -0
- package/dist/types/core/utils/index.d.ts +2 -0
- package/dist/types/core/utils/index.d.ts.map +1 -0
- package/dist/types/coreComponents/Component.d.ts +8 -0
- package/dist/types/coreComponents/Component.d.ts.map +1 -0
- package/dist/types/coreComponents/DataBindingProvider.d.ts +17 -0
- package/dist/types/coreComponents/DataBindingProvider.d.ts.map +1 -0
- package/dist/types/coreComponents/Entity.d.ts +9 -0
- package/dist/types/coreComponents/Entity.d.ts.map +1 -0
- package/dist/types/coreComponents/EntityList.d.ts +12 -0
- package/dist/types/coreComponents/EntityList.d.ts.map +1 -0
- package/dist/types/coreComponents/EntityListSubTree.d.ts +16 -0
- package/dist/types/coreComponents/EntityListSubTree.d.ts.map +1 -0
- package/dist/types/coreComponents/EntitySubTree.d.ts +14 -0
- package/dist/types/coreComponents/EntitySubTree.d.ts.map +1 -0
- package/dist/types/coreComponents/Field.d.ts +11 -0
- package/dist/types/coreComponents/Field.d.ts.map +1 -0
- package/dist/types/coreComponents/HasMany.d.ts +13 -0
- package/dist/types/coreComponents/HasMany.d.ts.map +1 -0
- package/dist/types/coreComponents/HasOne.d.ts +9 -0
- package/dist/types/coreComponents/HasOne.d.ts.map +1 -0
- package/dist/types/coreComponents/MarkerProvider.d.ts +21 -0
- package/dist/types/coreComponents/MarkerProvider.d.ts.map +1 -0
- package/dist/types/coreComponents/ParentEntity.d.ts +7 -0
- package/dist/types/coreComponents/ParentEntity.d.ts.map +1 -0
- package/dist/types/coreComponents/index.d.ts +12 -0
- package/dist/types/coreComponents/index.d.ts.map +1 -0
- package/dist/types/dao/Environment.d.ts +55 -0
- package/dist/types/dao/Environment.d.ts.map +1 -0
- package/dist/types/dao/VariableFieldValue.d.ts +5 -0
- package/dist/types/dao/VariableFieldValue.d.ts.map +1 -0
- package/dist/types/dao/index.d.ts +3 -0
- package/dist/types/dao/index.d.ts.map +1 -0
- package/dist/types/entityEvents/index.d.ts +8 -0
- package/dist/types/entityEvents/index.d.ts.map +1 -0
- package/dist/types/entityEvents/useDerivedField.d.ts +9 -0
- package/dist/types/entityEvents/useDerivedField.d.ts.map +1 -0
- package/dist/types/entityEvents/useEntityBeforePersist.d.ts +3 -0
- package/dist/types/entityEvents/useEntityBeforePersist.d.ts.map +1 -0
- package/dist/types/entityEvents/useEntityBeforeUpdate.d.ts +3 -0
- package/dist/types/entityEvents/useEntityBeforeUpdate.d.ts.map +1 -0
- package/dist/types/entityEvents/useEntityEvent.d.ts +9 -0
- package/dist/types/entityEvents/useEntityEvent.d.ts.map +1 -0
- package/dist/types/entityEvents/useEntityPersistError.d.ts +3 -0
- package/dist/types/entityEvents/useEntityPersistError.d.ts.map +1 -0
- package/dist/types/entityEvents/useEntityPersistSuccess.d.ts +3 -0
- package/dist/types/entityEvents/useEntityPersistSuccess.d.ts.map +1 -0
- package/dist/types/entityEvents/useOnConnectionUpdate.d.ts +4 -0
- package/dist/types/entityEvents/useOnConnectionUpdate.d.ts.map +1 -0
- package/dist/types/fieldHelpers/helpers/FieldHelper.d.ts +7 -0
- package/dist/types/fieldHelpers/helpers/FieldHelper.d.ts.map +1 -0
- package/dist/types/fieldHelpers/helpers/TemporalFieldHelper.d.ts +10 -0
- package/dist/types/fieldHelpers/helpers/TemporalFieldHelper.d.ts.map +1 -0
- package/dist/types/fieldHelpers/helpers/UuidFieldHelper.d.ts +10 -0
- package/dist/types/fieldHelpers/helpers/UuidFieldHelper.d.ts.map +1 -0
- package/dist/types/fieldHelpers/helpers/index.d.ts +3 -0
- package/dist/types/fieldHelpers/helpers/index.d.ts.map +1 -0
- package/dist/types/fieldHelpers/index.d.ts +2 -0
- package/dist/types/fieldHelpers/index.d.ts.map +1 -0
- package/dist/types/helperComponents/DeferredSubTrees.d.ts +7 -0
- package/dist/types/helperComponents/DeferredSubTrees.d.ts.map +1 -0
- package/dist/types/helperComponents/EntityView.d.ts +9 -0
- package/dist/types/helperComponents/EntityView.d.ts.map +1 -0
- package/dist/types/helperComponents/FieldView.d.ts +46 -0
- package/dist/types/helperComponents/FieldView.d.ts.map +1 -0
- package/dist/types/helperComponents/StaticRender.d.ts +6 -0
- package/dist/types/helperComponents/StaticRender.d.ts.map +1 -0
- package/dist/types/helperComponents/SugaredField.d.ts +9 -0
- package/dist/types/helperComponents/SugaredField.d.ts.map +1 -0
- package/dist/types/helperComponents/index.d.ts +6 -0
- package/dist/types/helperComponents/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/markers/EntityFieldMarkers.d.ts +7 -0
- package/dist/types/markers/EntityFieldMarkers.d.ts.map +1 -0
- package/dist/types/markers/EntityFieldMarkersContainer.d.ts +13 -0
- package/dist/types/markers/EntityFieldMarkersContainer.d.ts.map +1 -0
- package/dist/types/markers/EntityFieldPlaceholders.d.ts +3 -0
- package/dist/types/markers/EntityFieldPlaceholders.d.ts.map +1 -0
- package/dist/types/markers/EntityFieldsWithHoistablesMarker.d.ts +10 -0
- package/dist/types/markers/EntityFieldsWithHoistablesMarker.d.ts.map +1 -0
- package/dist/types/markers/EntityListSubTreeMarker.d.ts +12 -0
- package/dist/types/markers/EntityListSubTreeMarker.d.ts.map +1 -0
- package/dist/types/markers/EntitySubTreeMarker.d.ts +12 -0
- package/dist/types/markers/EntitySubTreeMarker.d.ts.map +1 -0
- package/dist/types/markers/FieldMarker.d.ts +14 -0
- package/dist/types/markers/FieldMarker.d.ts.map +1 -0
- package/dist/types/markers/HasManyRelationMarker.d.ts +12 -0
- package/dist/types/markers/HasManyRelationMarker.d.ts.map +1 -0
- package/dist/types/markers/HasOneRelationMarker.d.ts +12 -0
- package/dist/types/markers/HasOneRelationMarker.d.ts.map +1 -0
- package/dist/types/markers/MarkerTreeRoot.d.ts +8 -0
- package/dist/types/markers/MarkerTreeRoot.d.ts.map +1 -0
- package/dist/types/markers/MeaningfulMarker.d.ts +7 -0
- package/dist/types/markers/MeaningfulMarker.d.ts.map +1 -0
- package/dist/types/markers/ParentEntityMarker.d.ts +8 -0
- package/dist/types/markers/ParentEntityMarker.d.ts.map +1 -0
- package/dist/types/markers/PlaceholderGenerator.d.ts +9 -0
- package/dist/types/markers/PlaceholderGenerator.d.ts.map +1 -0
- package/dist/types/markers/SubTreeMarkers.d.ts +5 -0
- package/dist/types/markers/SubTreeMarkers.d.ts.map +1 -0
- package/dist/types/markers/index.d.ts +15 -0
- package/dist/types/markers/index.d.ts.map +1 -0
- package/dist/types/queryLanguage/CacheStore.d.ts +9 -0
- package/dist/types/queryLanguage/CacheStore.d.ts.map +1 -0
- package/dist/types/queryLanguage/MarkerFactory.d.ts +21 -0
- package/dist/types/queryLanguage/MarkerFactory.d.ts.map +1 -0
- package/dist/types/queryLanguage/Parser.d.ts +81 -0
- package/dist/types/queryLanguage/Parser.d.ts.map +1 -0
- package/dist/types/queryLanguage/ParserResults.d.ts +63 -0
- package/dist/types/queryLanguage/ParserResults.d.ts.map +1 -0
- package/dist/types/queryLanguage/QueryLanguage.d.ts +44 -0
- package/dist/types/queryLanguage/QueryLanguage.d.ts.map +1 -0
- package/dist/types/queryLanguage/QueryLanguageError.d.ts +3 -0
- package/dist/types/queryLanguage/QueryLanguageError.d.ts.map +1 -0
- package/dist/types/queryLanguage/index.d.ts +6 -0
- package/dist/types/queryLanguage/index.d.ts.map +1 -0
- package/dist/types/queryLanguage/tokenList.d.ts +34 -0
- package/dist/types/queryLanguage/tokenList.d.ts.map +1 -0
- package/dist/types/structures/BijectiveIndexedMap.d.ts +24 -0
- package/dist/types/structures/BijectiveIndexedMap.d.ts.map +1 -0
- package/dist/types/structures/LRUCache.d.ts +9 -0
- package/dist/types/structures/LRUCache.d.ts.map +1 -0
- package/dist/types/structures/WeakIdCache.d.ts +9 -0
- package/dist/types/structures/WeakIdCache.d.ts.map +1 -0
- package/dist/types/structures/index.d.ts +4 -0
- package/dist/types/structures/index.d.ts.map +1 -0
- package/dist/types/treeParameterHelpers/index.d.ts +2 -0
- package/dist/types/treeParameterHelpers/index.d.ts.map +1 -0
- package/dist/types/treeParameterHelpers/wrapFilterInHasOnes.d.ts +3 -0
- package/dist/types/treeParameterHelpers/wrapFilterInHasOnes.d.ts.map +1 -0
- package/dist/types/treeParameters/AnyField.d.ts +8 -0
- package/dist/types/treeParameters/AnyField.d.ts.map +1 -0
- package/dist/types/treeParameters/EntityCreationParameters.d.ts +13 -0
- package/dist/types/treeParameters/EntityCreationParameters.d.ts.map +1 -0
- package/dist/types/treeParameters/EntityListEventListeners.d.ts +15 -0
- package/dist/types/treeParameters/EntityListEventListeners.d.ts.map +1 -0
- package/dist/types/treeParameters/EntityListParameters.d.ts +17 -0
- package/dist/types/treeParameters/EntityListParameters.d.ts.map +1 -0
- package/dist/types/treeParameters/EntityListPreferences.d.ts +8 -0
- package/dist/types/treeParameters/EntityListPreferences.d.ts.map +1 -0
- package/dist/types/treeParameters/EventListenersStore.d.ts +32 -0
- package/dist/types/treeParameters/EventListenersStore.d.ts.map +1 -0
- package/dist/types/treeParameters/FieldEventListeners.d.ts +13 -0
- package/dist/types/treeParameters/FieldEventListeners.d.ts.map +1 -0
- package/dist/types/treeParameters/HasManyRelation.d.ts +10 -0
- package/dist/types/treeParameters/HasManyRelation.d.ts.map +1 -0
- package/dist/types/treeParameters/HasOneRelation.d.ts +13 -0
- package/dist/types/treeParameters/HasOneRelation.d.ts.map +1 -0
- package/dist/types/treeParameters/LeafField.d.ts +14 -0
- package/dist/types/treeParameters/LeafField.d.ts.map +1 -0
- package/dist/types/treeParameters/ParentEntityParameters.d.ts +8 -0
- package/dist/types/treeParameters/ParentEntityParameters.d.ts.map +1 -0
- package/dist/types/treeParameters/QualifiedEntityList.d.ts +19 -0
- package/dist/types/treeParameters/QualifiedEntityList.d.ts.map +1 -0
- package/dist/types/treeParameters/QualifiedEntityParameters.d.ts +17 -0
- package/dist/types/treeParameters/QualifiedEntityParameters.d.ts.map +1 -0
- package/dist/types/treeParameters/QualifiedFieldList.d.ts +17 -0
- package/dist/types/treeParameters/QualifiedFieldList.d.ts.map +1 -0
- package/dist/types/treeParameters/QualifiedSingleEntity.d.ts +20 -0
- package/dist/types/treeParameters/QualifiedSingleEntity.d.ts.map +1 -0
- package/dist/types/treeParameters/QualifiedSingleEntityParameters.d.ts +8 -0
- package/dist/types/treeParameters/QualifiedSingleEntityParameters.d.ts.map +1 -0
- package/dist/types/treeParameters/Relation.d.ts +15 -0
- package/dist/types/treeParameters/Relation.d.ts.map +1 -0
- package/dist/types/treeParameters/RelativeEntityList.d.ts +19 -0
- package/dist/types/treeParameters/RelativeEntityList.d.ts.map +1 -0
- package/dist/types/treeParameters/RelativeSingleEntity.d.ts +13 -0
- package/dist/types/treeParameters/RelativeSingleEntity.d.ts.map +1 -0
- package/dist/types/treeParameters/RelativeSingleField.d.ts +15 -0
- package/dist/types/treeParameters/RelativeSingleField.d.ts.map +1 -0
- package/dist/types/treeParameters/SetOnCreate.d.ts +4 -0
- package/dist/types/treeParameters/SetOnCreate.d.ts.map +1 -0
- package/dist/types/treeParameters/SingleEntityEventListeners.d.ts +16 -0
- package/dist/types/treeParameters/SingleEntityEventListeners.d.ts.map +1 -0
- package/dist/types/treeParameters/SingleEntityParameters.d.ts +8 -0
- package/dist/types/treeParameters/SingleEntityParameters.d.ts.map +1 -0
- package/dist/types/treeParameters/UnconstrainedQualifiedEntityList.d.ts +19 -0
- package/dist/types/treeParameters/UnconstrainedQualifiedEntityList.d.ts.map +1 -0
- package/dist/types/treeParameters/UnconstrainedQualifiedSingleEntity.d.ts +18 -0
- package/dist/types/treeParameters/UnconstrainedQualifiedSingleEntity.d.ts.map +1 -0
- package/dist/types/treeParameters/index.d.ts +27 -0
- package/dist/types/treeParameters/index.d.ts.map +1 -0
- package/dist/types/treeParameters/primitives/Alias.d.ts +2 -0
- package/dist/types/treeParameters/primitives/Alias.d.ts.map +1 -0
- package/dist/types/treeParameters/primitives/EntityId.d.ts +2 -0
- package/dist/types/treeParameters/primitives/EntityId.d.ts.map +1 -0
- package/dist/types/treeParameters/primitives/EntityName.d.ts +2 -0
- package/dist/types/treeParameters/primitives/EntityName.d.ts.map +1 -0
- package/dist/types/treeParameters/primitives/EntityRealmKey.d.ts +2 -0
- package/dist/types/treeParameters/primitives/EntityRealmKey.d.ts.map +1 -0
- package/dist/types/treeParameters/primitives/ExpectedEntityCount.d.ts +2 -0
- package/dist/types/treeParameters/primitives/ExpectedEntityCount.d.ts.map +1 -0
- package/dist/types/treeParameters/primitives/ExpectedQualifiedEntityMutation.d.ts +2 -0
- package/dist/types/treeParameters/primitives/ExpectedQualifiedEntityMutation.d.ts.map +1 -0
- package/dist/types/treeParameters/primitives/ExpectedRelationMutation.d.ts +2 -0
- package/dist/types/treeParameters/primitives/ExpectedRelationMutation.d.ts.map +1 -0
- package/dist/types/treeParameters/primitives/FieldName.d.ts +2 -0
- package/dist/types/treeParameters/primitives/FieldName.d.ts.map +1 -0
- package/dist/types/treeParameters/primitives/FieldValue.d.ts +5 -0
- package/dist/types/treeParameters/primitives/FieldValue.d.ts.map +1 -0
- package/dist/types/treeParameters/primitives/Filter.d.ts +4 -0
- package/dist/types/treeParameters/primitives/Filter.d.ts.map +1 -0
- package/dist/types/treeParameters/primitives/Limit.d.ts +2 -0
- package/dist/types/treeParameters/primitives/Limit.d.ts.map +1 -0
- package/dist/types/treeParameters/primitives/Offset.d.ts +2 -0
- package/dist/types/treeParameters/primitives/Offset.d.ts.map +1 -0
- package/dist/types/treeParameters/primitives/OrderBy.d.ts +4 -0
- package/dist/types/treeParameters/primitives/OrderBy.d.ts.map +1 -0
- package/dist/types/treeParameters/primitives/PlaceholderName.d.ts +2 -0
- package/dist/types/treeParameters/primitives/PlaceholderName.d.ts.map +1 -0
- package/dist/types/treeParameters/primitives/RemovalType.d.ts +2 -0
- package/dist/types/treeParameters/primitives/RemovalType.d.ts.map +1 -0
- package/dist/types/treeParameters/primitives/Scalar.d.ts +2 -0
- package/dist/types/treeParameters/primitives/Scalar.d.ts.map +1 -0
- package/dist/types/treeParameters/primitives/TreeRootId.d.ts +2 -0
- package/dist/types/treeParameters/primitives/TreeRootId.d.ts.map +1 -0
- package/dist/types/treeParameters/primitives/UniqueWhere.d.ts +4 -0
- package/dist/types/treeParameters/primitives/UniqueWhere.d.ts.map +1 -0
- package/dist/types/treeParameters/primitives/index.d.ts +19 -0
- package/dist/types/treeParameters/primitives/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/dist/types/utils/Hashing.d.ts +10 -0
- package/dist/types/utils/Hashing.d.ts.map +1 -0
- package/dist/types/utils/assert.d.ts +2 -0
- package/dist/types/utils/assert.d.ts.map +1 -0
- package/dist/types/utils/assertNever.d.ts +2 -0
- package/dist/types/utils/assertNever.d.ts.map +1 -0
- package/dist/types/utils/generateEnumerabilityPreventingEntropy.d.ts +2 -0
- package/dist/types/utils/generateEnumerabilityPreventingEntropy.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +7 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/isEmptyObject.d.ts +2 -0
- package/dist/types/utils/isEmptyObject.d.ts.map +1 -0
- package/dist/types/utils/ucfirst.d.ts +2 -0
- package/dist/types/utils/ucfirst.d.ts.map +1 -0
- package/package.json +8 -9
- package/src/BindingError.ts +5 -0
- package/src/accessorPropagation/AccessorProvider.tsx +17 -0
- package/src/accessorPropagation/BindingOperationsContext.ts +32 -0
- package/src/accessorPropagation/BindingOperationsProvider.tsx +16 -0
- package/src/accessorPropagation/EntityKeyContext.ts +4 -0
- package/src/accessorPropagation/EntityKeyProvider.tsx +11 -0
- package/src/accessorPropagation/EnvironmentContext.ts +5 -0
- package/src/accessorPropagation/TreeRootIdContext.ts +5 -0
- package/src/accessorPropagation/TreeRootIdProvider.tsx +12 -0
- package/src/accessorPropagation/index.ts +29 -0
- package/src/accessorPropagation/useAccessorUpdateSubscription.ts +107 -0
- package/src/accessorPropagation/useBindingOperations.ts +5 -0
- package/src/accessorPropagation/useDesugaredRelativeEntityList.ts +70 -0
- package/src/accessorPropagation/useDesugaredRelativeSingleEntity.ts +58 -0
- package/src/accessorPropagation/useDesugaredRelativeSingleField.ts +58 -0
- package/src/accessorPropagation/useEntity.ts +56 -0
- package/src/accessorPropagation/useEntityKey.ts +15 -0
- package/src/accessorPropagation/useEntityList.ts +49 -0
- package/src/accessorPropagation/useEntityListSubTree.ts +20 -0
- package/src/accessorPropagation/useEntityListSubTreeParameters.ts +88 -0
- package/src/accessorPropagation/useEntitySubTree.ts +19 -0
- package/src/accessorPropagation/useEntitySubTreeParameters.ts +66 -0
- package/src/accessorPropagation/useEnvironment.ts +7 -0
- package/src/accessorPropagation/useField.ts +51 -0
- package/src/accessorPropagation/useGetEntityByKey.ts +4 -0
- package/src/accessorPropagation/useGetEntityListSubTree.ts +28 -0
- package/src/accessorPropagation/useGetEntitySubTree.ts +28 -0
- package/src/accessorPropagation/useGetTreeFilters.ts +4 -0
- package/src/accessorPropagation/useHasEntity.ts +6 -0
- package/src/accessorPropagation/usePersist.ts +4 -0
- package/src/accessorPropagation/useTreeRootId.ts +5 -0
- package/src/accessorSorting/SetOrderFieldOnCreate.tsx +92 -0
- package/src/accessorSorting/SortedEntities.ts +9 -0
- package/src/accessorSorting/addEntityAtIndex.ts +27 -0
- package/src/accessorSorting/errors.ts +18 -0
- package/src/accessorSorting/index.ts +9 -0
- package/src/accessorSorting/moveEntity.ts +66 -0
- package/src/accessorSorting/repairEntitiesOrder.ts +15 -0
- package/src/accessorSorting/sortEntities.ts +20 -0
- package/src/accessorSorting/useSortedEntities.ts +105 -0
- package/src/accessorTree/AccessorTree.tsx +34 -0
- package/src/accessorTree/AccessorTreeState.ts +18 -0
- package/src/accessorTree/AccessorTreeStateAction.ts +15 -0
- package/src/accessorTree/AccessorTreeStateMetadata.ts +3 -0
- package/src/accessorTree/AccessorTreeStateOptions.ts +7 -0
- package/src/accessorTree/DirtinessContext.ts +4 -0
- package/src/accessorTree/MutationRequestResponse.ts +55 -0
- package/src/accessorTree/MutationStateContext.ts +4 -0
- package/src/accessorTree/NormalizedPersistedData.ts +23 -0
- package/src/accessorTree/PersistResult.ts +30 -0
- package/src/accessorTree/QueryRequestResponse.ts +19 -0
- package/src/accessorTree/RequestError.ts +16 -0
- package/src/accessorTree/RuntimeId.ts +49 -0
- package/src/accessorTree/accessorTreeStateReducer.ts +27 -0
- package/src/accessorTree/index.ts +18 -0
- package/src/accessorTree/metadataToRequestError.ts +14 -0
- package/src/accessorTree/useDataBinding.ts +98 -0
- package/src/accessorTree/useDirtinessState.ts +4 -0
- package/src/accessorTree/useMutationState.ts +4 -0
- package/src/accessors/AsyncBatchUpdatesOptions.ts +8 -0
- package/src/accessors/BatchUpdatesOptions.ts +9 -0
- package/src/accessors/BindingConfig.ts +7 -0
- package/src/accessors/BindingOperations.ts +15 -0
- package/src/accessors/EntityAccessor.ts +259 -0
- package/src/accessors/EntityListAccessor.ts +173 -0
- package/src/accessors/ErrorAccessor.ts +39 -0
- package/src/accessors/Errorable.ts +5 -0
- package/src/accessors/ExtendTree.ts +10 -0
- package/src/accessors/FieldAccessor.ts +102 -0
- package/src/accessors/GetEntityByKey.ts +3 -0
- package/src/accessors/GetEntityListSubTree.ts +14 -0
- package/src/accessors/GetEntitySubTree.ts +14 -0
- package/src/accessors/Persist.ts +11 -0
- package/src/accessors/PersistErrorOptions.ts +12 -0
- package/src/accessors/PersistSuccessOptions.ts +5 -0
- package/src/accessors/TreeRootAccessor.ts +14 -0
- package/src/accessors/index.ts +17 -0
- package/src/ambient.d.ts +1 -0
- package/src/bindingTypes.ts +3 -0
- package/src/core/AccessorErrorManager.ts +231 -0
- package/src/core/Config.ts +29 -0
- package/src/core/DataBinding.ts +454 -0
- package/src/core/DirtinessTracker.ts +33 -0
- package/src/core/ErrorsPreprocessor.ts +240 -0
- package/src/core/EventManager.ts +580 -0
- package/src/core/IncrementalMarkerBuilder.ts +60 -0
- package/src/core/MarkerComparator.ts +102 -0
- package/src/core/MarkerMerger.ts +297 -0
- package/src/core/MarkerTreeGenerator.ts +121 -0
- package/src/core/MutationGenerator.ts +716 -0
- package/src/core/QueryGenerator.ts +173 -0
- package/src/core/RealmKeyGenerator.ts +54 -0
- package/src/core/RequestResponseNormalizer.ts +213 -0
- package/src/core/StateInitializer.ts +571 -0
- package/src/core/TreeAugmenter.ts +262 -0
- package/src/core/TreeFilterGenerator.ts +116 -0
- package/src/core/TreeParameterMerger.ts +374 -0
- package/src/core/TreeStore.ts +260 -0
- package/src/core/UpdateMetadata.ts +3 -0
- package/src/core/VariableInputTransformer.ts +23 -0
- package/src/core/exceptions/ErrorLocator.ts +58 -0
- package/src/core/exceptions/LocalizedBindingError.ts +20 -0
- package/src/core/exceptions/MarkerSugarer.ts +61 -0
- package/src/core/exceptions/RawMarkerPath.ts +3 -0
- package/src/core/exceptions/TreeParameterSugarer.ts +41 -0
- package/src/core/exceptions/index.ts +5 -0
- package/src/core/factories/createBatchUpdatesOptions.ts +38 -0
- package/src/core/factories/index.ts +1 -0
- package/src/core/index.ts +5 -0
- package/src/core/operations/EntityOperations.ts +310 -0
- package/src/core/operations/FieldOperations.ts +127 -0
- package/src/core/operations/ListOperations.ts +207 -0
- package/src/core/operations/OperationsHelpers.ts +150 -0
- package/src/core/operations/index.ts +3 -0
- package/src/core/requestAliases/MutationAlias.ts +66 -0
- package/src/core/requestAliases/TopLevelMutationOperation.ts +11 -0
- package/src/core/requestAliases/index.ts +4 -0
- package/src/core/requestAliases/mutationOperationSubTreeType.ts +4 -0
- package/src/core/requestAliases/mutationOperationType.ts +5 -0
- package/src/core/schema/RawSchema.ts +7 -0
- package/src/core/schema/RawSchemaEntity.ts +13 -0
- package/src/core/schema/RawSchemaEnum.ts +6 -0
- package/src/core/schema/Schema.ts +11 -0
- package/src/core/schema/SchemaColumn.ts +15 -0
- package/src/core/schema/SchemaColumnType.ts +3 -0
- package/src/core/schema/SchemaEntities.ts +4 -0
- package/src/core/schema/SchemaEntity.ts +10 -0
- package/src/core/schema/SchemaEnums.ts +3 -0
- package/src/core/schema/SchemaField.ts +4 -0
- package/src/core/schema/SchemaFields.ts +4 -0
- package/src/core/schema/SchemaLoader.ts +62 -0
- package/src/core/schema/SchemaPreprocessor.ts +51 -0
- package/src/core/schema/SchemaRelation.ts +29 -0
- package/src/core/schema/SchemaRelationOrderBy.ts +4 -0
- package/src/core/schema/SchemaStore.ts +8 -0
- package/src/core/schema/SchemaUniqueConstraint.ts +5 -0
- package/src/core/schema/SchemaValidator.ts +238 -0
- package/src/core/schema/index.ts +14 -0
- package/src/core/state/EntityListState.ts +37 -0
- package/src/core/state/EntityRealmState.ts +63 -0
- package/src/core/state/EntityState.ts +12 -0
- package/src/core/state/FieldState.ts +20 -0
- package/src/core/state/StateIterator.ts +122 -0
- package/src/core/state/StateNode.ts +8 -0
- package/src/core/state/getEntityMarker.ts +4 -0
- package/src/core/state/index.ts +7 -0
- package/src/core/utils/getCombinedSignal.ts +36 -0
- package/src/core/utils/index.ts +1 -0
- package/src/coreComponents/Component.tsx +61 -0
- package/src/coreComponents/DataBindingProvider.tsx +45 -0
- package/src/coreComponents/Entity.tsx +23 -0
- package/src/coreComponents/EntityList.tsx +52 -0
- package/src/coreComponents/EntityListSubTree.tsx +85 -0
- package/src/coreComponents/EntitySubTree.tsx +98 -0
- package/src/coreComponents/Field.tsx +39 -0
- package/src/coreComponents/HasMany.tsx +46 -0
- package/src/coreComponents/HasOne.tsx +39 -0
- package/src/coreComponents/MarkerProvider.ts +59 -0
- package/src/coreComponents/ParentEntity.tsx +17 -0
- package/src/coreComponents/index.ts +11 -0
- package/src/dao/Environment.ts +201 -0
- package/src/dao/VariableFieldValue.ts +3 -0
- package/src/dao/index.ts +2 -0
- package/src/entityEvents/index.ts +7 -0
- package/src/entityEvents/useDerivedField.ts +64 -0
- package/src/entityEvents/useEntityBeforePersist.ts +6 -0
- package/src/entityEvents/useEntityBeforeUpdate.ts +6 -0
- package/src/entityEvents/useEntityEvent.ts +57 -0
- package/src/entityEvents/useEntityPersistError.ts +6 -0
- package/src/entityEvents/useEntityPersistSuccess.ts +6 -0
- package/src/entityEvents/useOnConnectionUpdate.ts +10 -0
- package/src/fieldHelpers/helpers/FieldHelper.ts +10 -0
- package/src/fieldHelpers/helpers/TemporalFieldHelper.ts +21 -0
- package/src/fieldHelpers/helpers/UuidFieldHelper.ts +18 -0
- package/src/fieldHelpers/helpers/index.ts +2 -0
- package/src/fieldHelpers/index.ts +1 -0
- package/src/helperComponents/DeferredSubTrees.tsx +116 -0
- package/src/helperComponents/EntityView.tsx +16 -0
- package/src/helperComponents/FieldView.tsx +129 -0
- package/src/helperComponents/StaticRender.tsx +12 -0
- package/src/helperComponents/SugaredField.tsx +15 -0
- package/src/helperComponents/index.ts +5 -0
- package/src/index.ts +19 -0
- package/src/markers/EntityFieldMarkers.ts +7 -0
- package/src/markers/EntityFieldMarkersContainer.ts +45 -0
- package/src/markers/EntityFieldPlaceholders.ts +3 -0
- package/src/markers/EntityFieldsWithHoistablesMarker.ts +11 -0
- package/src/markers/EntityListSubTreeMarker.ts +20 -0
- package/src/markers/EntitySubTreeMarker.ts +20 -0
- package/src/markers/FieldMarker.ts +19 -0
- package/src/markers/HasManyRelationMarker.ts +27 -0
- package/src/markers/HasOneRelationMarker.ts +21 -0
- package/src/markers/MarkerTreeRoot.ts +9 -0
- package/src/markers/MeaningfulMarker.ts +12 -0
- package/src/markers/ParentEntityMarker.ts +9 -0
- package/src/markers/PlaceholderGenerator.ts +36 -0
- package/src/markers/SubTreeMarkers.ts +5 -0
- package/src/markers/index.ts +14 -0
- package/src/queryLanguage/CacheStore.ts +56 -0
- package/src/queryLanguage/MarkerFactory.ts +300 -0
- package/src/queryLanguage/Parser.ts +848 -0
- package/src/queryLanguage/ParserResults.ts +81 -0
- package/src/queryLanguage/QueryLanguage.ts +730 -0
- package/src/queryLanguage/QueryLanguageError.ts +1 -0
- package/src/queryLanguage/index.ts +5 -0
- package/src/queryLanguage/tokenList.ts +169 -0
- package/src/structures/BijectiveIndexedMap.ts +139 -0
- package/src/structures/LRUCache.ts +29 -0
- package/src/structures/WeakIdCache.ts +25 -0
- package/src/structures/index.ts +3 -0
- package/src/treeParameterHelpers/index.ts +1 -0
- package/src/treeParameterHelpers/wrapFilterInHasOnes.ts +21 -0
- package/src/treeParameters/AnyField.ts +9 -0
- package/src/treeParameters/EntityCreationParameters.ts +34 -0
- package/src/treeParameters/EntityListEventListeners.ts +20 -0
- package/src/treeParameters/EntityListParameters.ts +19 -0
- package/src/treeParameters/EntityListPreferences.ts +11 -0
- package/src/treeParameters/EventListenersStore.ts +81 -0
- package/src/treeParameters/FieldEventListeners.ts +22 -0
- package/src/treeParameters/HasManyRelation.ts +18 -0
- package/src/treeParameters/HasOneRelation.ts +21 -0
- package/src/treeParameters/LeafField.ts +18 -0
- package/src/treeParameters/ParentEntityParameters.ts +10 -0
- package/src/treeParameters/QualifiedEntityList.ts +43 -0
- package/src/treeParameters/QualifiedEntityParameters.ts +20 -0
- package/src/treeParameters/QualifiedFieldList.ts +36 -0
- package/src/treeParameters/QualifiedSingleEntity.ts +46 -0
- package/src/treeParameters/QualifiedSingleEntityParameters.ts +9 -0
- package/src/treeParameters/Relation.ts +17 -0
- package/src/treeParameters/RelativeEntityList.ts +25 -0
- package/src/treeParameters/RelativeSingleEntity.ts +16 -0
- package/src/treeParameters/RelativeSingleField.ts +20 -0
- package/src/treeParameters/SetOnCreate.ts +6 -0
- package/src/treeParameters/SingleEntityEventListeners.ts +24 -0
- package/src/treeParameters/SingleEntityParameters.ts +9 -0
- package/src/treeParameters/UnconstrainedQualifiedEntityList.ts +37 -0
- package/src/treeParameters/UnconstrainedQualifiedSingleEntity.ts +37 -0
- package/src/treeParameters/index.ts +27 -0
- package/src/treeParameters/primitives/Alias.ts +1 -0
- package/src/treeParameters/primitives/EntityId.ts +2 -0
- package/src/treeParameters/primitives/EntityName.ts +4 -0
- package/src/treeParameters/primitives/EntityRealmKey.ts +2 -0
- package/src/treeParameters/primitives/ExpectedEntityCount.ts +1 -0
- package/src/treeParameters/primitives/ExpectedQualifiedEntityMutation.ts +1 -0
- package/src/treeParameters/primitives/ExpectedRelationMutation.ts +1 -0
- package/src/treeParameters/primitives/FieldName.ts +7 -0
- package/src/treeParameters/primitives/FieldValue.ts +6 -0
- package/src/treeParameters/primitives/Filter.ts +7 -0
- package/src/treeParameters/primitives/Limit.ts +1 -0
- package/src/treeParameters/primitives/Offset.ts +1 -0
- package/src/treeParameters/primitives/OrderBy.ts +6 -0
- package/src/treeParameters/primitives/PlaceholderName.ts +4 -0
- package/src/treeParameters/primitives/RemovalType.ts +1 -0
- package/src/treeParameters/primitives/Scalar.ts +1 -0
- package/src/treeParameters/primitives/TreeRootId.ts +1 -0
- package/src/treeParameters/primitives/UniqueWhere.ts +7 -0
- package/src/treeParameters/primitives/index.ts +18 -0
- package/src/tsconfig.json +12 -0
- package/src/utils/Hashing.ts +81 -0
- package/src/utils/assert.ts +7 -0
- package/src/utils/assertNever.ts +10 -0
- package/src/utils/generateEnumerabilityPreventingEntropy.ts +3 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/isEmptyObject.ts +9 -0
- package/src/utils/ucfirst.ts +1 -0
- package/dist/binding.d.ts +0 -2242
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestResponseNormalizer.js","sources":["../../../src/core/RequestResponseNormalizer.ts"],"sourcesContent":["import {\n\tEntityFieldPersistedData,\n\tNormalizedPersistedData,\n\tPersistedEntityDataStore,\n\tReceivedDataTree,\n\tReceivedEntityData,\n\tReceivedFieldData,\n\tServerGeneratedUuid,\n\tSingleEntityPersistedData,\n} from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport { PRIMARY_KEY_NAME } from '../bindingTypes'\nimport { assertNever } from '../utils'\nimport { MutationAlias, mutationOperationSubTreeType, mutationOperationType } from './requestAliases'\n\nexport class RequestResponseNormalizer {\n\tpublic static mergeInQueryResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t): Set<string> {\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\t\tconst presentIds: Set<string> = new Set()\n\n\t\tfor (const placeholderName in newPersistedData) {\n\t\t\tconst treeDatum = newPersistedData[placeholderName]\n\n\t\t\tconst fieldData = this.createFieldData(persistedEntityDataStore, treeDatum)\n\n\t\t\tif (fieldData === null) {\n\t\t\t\tsubTreeDataStore.delete(placeholderName)\n\t\t\t} else if (fieldData instanceof Set || typeof fieldData === 'object') {\n\t\t\t\tsubTreeDataStore.set(placeholderName, fieldData)\n\t\t\t} else {\n\t\t\t\tthis.rejectData()\n\t\t\t}\n\t\t}\n\t\treturn presentIds\n\t}\n\n\tpublic static mergeInMutationResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t): Set<string> {\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\t\tconst presentIds: Set<string> = new Set()\n\n\t\tfor (const operationAlias in newPersistedData) {\n\t\t\tconst operation = MutationAlias.decodeTopLevel(operationAlias)\n\n\t\t\tif (operation === undefined) {\n\t\t\t\treturn this.rejectData()\n\t\t\t}\n\t\t\tconst { type, entityId, subTreeType, subTreePlaceholder } = operation\n\n\t\t\tswitch (type) {\n\t\t\t\tcase mutationOperationType.update:\n\t\t\t\tcase mutationOperationType.create: {\n\t\t\t\t\tconst treeDatum = newPersistedData[operationAlias]\n\t\t\t\t\tconst fieldData = this.createFieldData(persistedEntityDataStore, treeDatum)\n\n\t\t\t\t\tif (subTreeType === mutationOperationSubTreeType.singleEntity) {\n\t\t\t\t\t\tif (fieldData instanceof ServerGeneratedUuid) {\n\t\t\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, fieldData)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\treturn this.rejectData()\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (subTreeType === mutationOperationSubTreeType.entityList) {\n\t\t\t\t\t\tif (fieldData instanceof ServerGeneratedUuid) {\n\t\t\t\t\t\t\tif (type === mutationOperationType.create) {\n\t\t\t\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\t\t\t\tif (list instanceof Set) {\n\t\t\t\t\t\t\t\t\t// TODO this is somewhat dubious because we're essentially just guessing the order of the entities\n\t\t\t\t\t\t\t\t\t//\t\tand just carelessly put the new one at the end.\n\t\t\t\t\t\t\t\t\tlist.add(fieldData.value)\n\t\t\t\t\t\t\t\t} else if (list === undefined) {\n\t\t\t\t\t\t\t\t\t// That's fine. This is probably just an isCreating sub-tree.\n\t\t\t\t\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, new Set([fieldData.value]))\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\treturn this.rejectData()\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\treturn this.rejectData()\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase mutationOperationType.delete: {\n\t\t\t\t\t// TODO there are potentially some references to entityId that this whole process won't quite remove.\n\t\t\t\t\t//\t\tThat's a memory leak. Probably not particularly severe in most cases but still.\n\t\t\t\t\tpersistedEntityDataStore.delete(entityId)\n\t\t\t\t\tif (subTreeType === mutationOperationSubTreeType.singleEntity) {\n\t\t\t\t\t\tsubTreeDataStore.delete(subTreePlaceholder)\n\t\t\t\t\t} else if (subTreeType === mutationOperationSubTreeType.entityList) {\n\t\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\t\tif (!(list instanceof Set)) {\n\t\t\t\t\t\t\treturn this.rejectData()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlist.delete(entityId)\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn assertNever(type)\n\t\t\t}\n\t\t}\n\t\treturn presentIds\n\t}\n\n\tprivate static createFieldData(\n\t\tentityMap: PersistedEntityDataStore,\n\t\tfieldData: ReceivedFieldData,\n\t): EntityFieldPersistedData {\n\t\tif (Array.isArray(fieldData)) {\n\t\t\tconst subTreeListIds = new Set<string>()\n\t\t\tfor (const entityDatum of fieldData) {\n\t\t\t\tsubTreeListIds.add(this.createEntityData(entityMap, entityDatum))\n\t\t\t}\n\t\t\treturn subTreeListIds\n\t\t} else if (fieldData !== null && typeof fieldData === 'object') {\n\t\t\treturn new ServerGeneratedUuid(this.createEntityData(entityMap, fieldData))\n\t\t} else {\n\t\t\treturn fieldData\n\t\t}\n\t}\n\n\tprivate static createEntityData(entityMap: PersistedEntityDataStore, entityData: ReceivedEntityData): string {\n\t\tconst primaryKey: string | undefined = entityData[PRIMARY_KEY_NAME]\n\n\t\tif (primaryKey === undefined) {\n\t\t\tthrow new BindingError(`The server has responded with an entity that lacks a primary key.`)\n\t\t}\n\n\t\tconst presentEntityData = entityMap.get(primaryKey)\n\n\t\tif (presentEntityData === undefined) {\n\t\t\tconst fieldsMap: SingleEntityPersistedData = new Map()\n\t\t\tentityMap.set(primaryKey, fieldsMap)\n\t\t\tfor (const field in entityData) {\n\t\t\t\tconst fieldDatum = entityData[field]\n\n\t\t\t\tfieldsMap.set(field, this.createFieldData(entityMap, fieldDatum))\n\t\t\t}\n\t\t} else {\n\t\t\tthis.mergeInEntityData(entityMap, presentEntityData, entityData)\n\t\t}\n\t\treturn primaryKey\n\t}\n\n\tprivate static mergeInFieldData(\n\t\tentityMap: PersistedEntityDataStore,\n\t\tfromTarget: EntityFieldPersistedData | undefined,\n\t\tnewDatum: ReceivedFieldData,\n\t): EntityFieldPersistedData {\n\t\tif (fromTarget === undefined) {\n\t\t\treturn this.createFieldData(entityMap, newDatum)\n\t\t}\n\t\tif (fromTarget instanceof ServerGeneratedUuid || (fromTarget === null && typeof newDatum === 'object')) {\n\t\t\tif (newDatum === null) {\n\t\t\t\treturn null\n\t\t\t} else if (typeof newDatum === 'object' && !Array.isArray(newDatum)) {\n\t\t\t\tconst newId = newDatum[PRIMARY_KEY_NAME]\n\t\t\t\tconst target = entityMap.get(newId)\n\t\t\t\tif (target === undefined) {\n\t\t\t\t\treturn new ServerGeneratedUuid(this.createEntityData(entityMap, newDatum))\n\t\t\t\t}\n\n\t\t\t\tif (fromTarget?.value === newId) {\n\t\t\t\t\tthis.mergeInEntityData(entityMap, target, newDatum)\n\t\t\t\t\treturn fromTarget\n\t\t\t\t} else {\n\t\t\t\t\treturn new ServerGeneratedUuid(this.createEntityData(entityMap, newDatum))\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (fromTarget instanceof Set) {\n\t\t\tif (Array.isArray(newDatum)) {\n\t\t\t\tfromTarget.clear()\n\t\t\t\tfor (const entityData of newDatum) {\n\t\t\t\t\tfromTarget.add(this.createEntityData(entityMap, entityData))\n\t\t\t\t}\n\t\t\t\treturn fromTarget\n\t\t\t}\n\t\t} else if (!Array.isArray(newDatum) && (newDatum === null || typeof newDatum !== 'object')) {\n\t\t\treturn newDatum\n\t\t}\n\t\treturn this.rejectData()\n\t}\n\n\tprivate static mergeInEntityData(\n\t\tentityMap: PersistedEntityDataStore,\n\t\ttarget: SingleEntityPersistedData,\n\t\tnewData: ReceivedEntityData,\n\t): SingleEntityPersistedData {\n\t\tfor (const field in newData) {\n\t\t\tconst fromTarget = target.get(field)\n\t\t\tconst newDatum = newData[field]\n\n\t\t\ttarget.set(field, this.mergeInFieldData(entityMap, fromTarget, newDatum))\n\t\t}\n\t\treturn target\n\t}\n\n\tprivate static rejectData(extraMessage?: string): never {\n\t\tthrow new BindingError(`Failed to process data received from the API.${extraMessage ? `\\n${extraMessage}` : ''}`)\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;gCAeuC;AAAA,SACxB,qBACb,UACA,kBACc;AACd,UAAM,EAAE,kBAAkB,6BAA6B;AACvD,UAAM,aAA0B,IAAI;AAEpC,eAAW,mBAAmB,kBAAkB;AAC/C,YAAM,YAAY,iBAAiB;AAEnC,YAAM,YAA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AAI,WAAW,QAAW;AACzB,iBAAO,IAAI,oBAAoB,KAAK,iBAAiB,WAAW;AAAA;AAGjE,YAAI,YAAY,UAAU,OAAO;AAChC,eAAK,kBAAkB,WAAW,QAAQ;AAC1C,iBAAO;AAAA,eACD;AACN,iBAAO,IAAI,oBAAoB,KAAK,iBAAiB,WAAW;AAAA;AAAA;AAAA,eAGxD,sBAAsB,KAAK;AACrC,UAAI,MAAM,QAAQ,WAAW;AAC5B,mBAAW;AACX,mBAAW,cAAc,UAAU;AAClC,qBAAW,IAAI,KAAK,iBAAiB,WAAW;AAAA;AAEjD,eAAO;AAAA;AAAA,eAEE,CAAC,MAAM,QAAQ,2BAA2B,QAAQ,OAAO,aAAa,WAAW;AAC3F,aAAO;AAAA;AAER,WAAO,KAAK;AAAA;AAAA,SAGE,kBACd,WACA,QACA,SAC4B;AAC5B,eAAW,SAAS,SAAS;AAC5B,YAAM,aAAa,OAAO,IAAI;AAC9B,YAAM,WAAW,QAAQ;AAEzB,aAAO,IAAI,OAAO,KAAK,iBAAiB,WAAW,YAAY;AAAA;AAEhE,WAAO;AAAA;AAAA,SAGO,WAAW,cAA8B;AACvD,UAAM,IAAI,aAAa,gDAAgD,eAAe;AAAA,EAAK,iBAAiB;AAAA;AAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"RequestResponseNormalizer.js","sources":["../../../src/core/RequestResponseNormalizer.ts"],"sourcesContent":["import {\n\tEntityFieldPersistedData,\n\tNormalizedPersistedData,\n\tPersistedEntityDataStore,\n\tReceivedDataTree,\n\tReceivedEntityData,\n\tReceivedFieldData,\n\tServerGeneratedUuid,\n\tSingleEntityPersistedData,\n} from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport { PRIMARY_KEY_NAME } from '../bindingTypes'\nimport { assertNever } from '../utils'\nimport { MutationAlias, mutationOperationSubTreeType, mutationOperationType } from './requestAliases'\n\nexport class RequestResponseNormalizer {\n\tpublic static mergeInQueryResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t): Set<string> {\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\t\tconst presentIds: Set<string> = new Set()\n\n\t\tfor (const placeholderName in newPersistedData) {\n\t\t\tconst treeDatum = newPersistedData[placeholderName]\n\n\t\t\tconst fieldData = this.createFieldData(persistedEntityDataStore, treeDatum)\n\n\t\t\tif (fieldData === null) {\n\t\t\t\tsubTreeDataStore.delete(placeholderName)\n\t\t\t} else if (fieldData instanceof Set || typeof fieldData === 'object') {\n\t\t\t\tsubTreeDataStore.set(placeholderName, fieldData)\n\t\t\t} else {\n\t\t\t\tthis.rejectData()\n\t\t\t}\n\t\t}\n\t\treturn presentIds\n\t}\n\n\tpublic static mergeInMutationResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t): Set<string> {\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\t\tconst presentIds: Set<string> = new Set()\n\n\t\tfor (const operationAlias in newPersistedData) {\n\t\t\tconst operation = MutationAlias.decodeTopLevel(operationAlias)\n\n\t\t\tif (operation === undefined) {\n\t\t\t\treturn this.rejectData()\n\t\t\t}\n\t\t\tconst { type, entityId, subTreeType, subTreePlaceholder } = operation\n\n\t\t\tswitch (type) {\n\t\t\t\tcase mutationOperationType.update:\n\t\t\t\tcase mutationOperationType.create: {\n\t\t\t\t\tconst treeDatum = newPersistedData[operationAlias]\n\t\t\t\t\tconst fieldData = this.createFieldData(persistedEntityDataStore, treeDatum)\n\n\t\t\t\t\tif (subTreeType === mutationOperationSubTreeType.singleEntity) {\n\t\t\t\t\t\tif (fieldData instanceof ServerGeneratedUuid) {\n\t\t\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, fieldData)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\treturn this.rejectData()\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (subTreeType === mutationOperationSubTreeType.entityList) {\n\t\t\t\t\t\tif (fieldData instanceof ServerGeneratedUuid) {\n\t\t\t\t\t\t\tif (type === mutationOperationType.create) {\n\t\t\t\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\t\t\t\tif (list instanceof Set) {\n\t\t\t\t\t\t\t\t\t// TODO this is somewhat dubious because we're essentially just guessing the order of the entities\n\t\t\t\t\t\t\t\t\t//\t\tand just carelessly put the new one at the end.\n\t\t\t\t\t\t\t\t\tlist.add(fieldData.value)\n\t\t\t\t\t\t\t\t} else if (list === undefined) {\n\t\t\t\t\t\t\t\t\t// That's fine. This is probably just an isCreating sub-tree.\n\t\t\t\t\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, new Set([fieldData.value]))\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\treturn this.rejectData()\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\treturn this.rejectData()\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase mutationOperationType.delete: {\n\t\t\t\t\t// TODO there are potentially some references to entityId that this whole process won't quite remove.\n\t\t\t\t\t//\t\tThat's a memory leak. Probably not particularly severe in most cases but still.\n\t\t\t\t\tpersistedEntityDataStore.delete(entityId)\n\t\t\t\t\tif (subTreeType === mutationOperationSubTreeType.singleEntity) {\n\t\t\t\t\t\tsubTreeDataStore.delete(subTreePlaceholder)\n\t\t\t\t\t} else if (subTreeType === mutationOperationSubTreeType.entityList) {\n\t\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\t\tif (!(list instanceof Set)) {\n\t\t\t\t\t\t\treturn this.rejectData()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlist.delete(entityId)\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn assertNever(type)\n\t\t\t}\n\t\t}\n\t\treturn presentIds\n\t}\n\n\tprivate static createFieldData(\n\t\tentityMap: PersistedEntityDataStore,\n\t\tfieldData: ReceivedFieldData,\n\t): EntityFieldPersistedData {\n\t\tif (Array.isArray(fieldData)) {\n\t\t\tconst subTreeListIds = new Set<string>()\n\t\t\tfor (const entityDatum of fieldData) {\n\t\t\t\tsubTreeListIds.add(this.createEntityData(entityMap, entityDatum))\n\t\t\t}\n\t\t\treturn subTreeListIds\n\t\t} else if (fieldData !== null && typeof fieldData === 'object') {\n\t\t\treturn new ServerGeneratedUuid(this.createEntityData(entityMap, fieldData))\n\t\t} else {\n\t\t\treturn fieldData\n\t\t}\n\t}\n\n\tprivate static createEntityData(entityMap: PersistedEntityDataStore, entityData: ReceivedEntityData): string {\n\t\tconst primaryKey: string | undefined = entityData[PRIMARY_KEY_NAME]\n\n\t\tif (primaryKey === undefined) {\n\t\t\tthrow new BindingError(`The server has responded with an entity that lacks a primary key.`)\n\t\t}\n\n\t\tconst presentEntityData = entityMap.get(primaryKey)\n\n\t\tif (presentEntityData === undefined) {\n\t\t\tconst fieldsMap: SingleEntityPersistedData = new Map()\n\t\t\tentityMap.set(primaryKey, fieldsMap)\n\t\t\tfor (const field in entityData) {\n\t\t\t\tconst fieldDatum = entityData[field]\n\n\t\t\t\tfieldsMap.set(field, this.createFieldData(entityMap, fieldDatum))\n\t\t\t}\n\t\t} else {\n\t\t\tthis.mergeInEntityData(entityMap, presentEntityData, entityData)\n\t\t}\n\t\treturn primaryKey\n\t}\n\n\tprivate static mergeInFieldData(\n\t\tentityMap: PersistedEntityDataStore,\n\t\tfromTarget: EntityFieldPersistedData | undefined,\n\t\tnewDatum: ReceivedFieldData,\n\t): EntityFieldPersistedData {\n\t\tif (fromTarget === undefined) {\n\t\t\treturn this.createFieldData(entityMap, newDatum)\n\t\t}\n\t\tif (fromTarget instanceof ServerGeneratedUuid || (fromTarget === null && typeof newDatum === 'object')) {\n\t\t\tif (newDatum === null) {\n\t\t\t\treturn null\n\t\t\t} else if (typeof newDatum === 'object' && !Array.isArray(newDatum)) {\n\t\t\t\tconst newId = newDatum[PRIMARY_KEY_NAME]\n\t\t\t\tconst target = entityMap.get(newId)\n\t\t\t\tif (target === undefined) {\n\t\t\t\t\treturn new ServerGeneratedUuid(this.createEntityData(entityMap, newDatum))\n\t\t\t\t}\n\n\t\t\t\tif (fromTarget?.value === newId) {\n\t\t\t\t\tthis.mergeInEntityData(entityMap, target, newDatum)\n\t\t\t\t\treturn fromTarget\n\t\t\t\t} else {\n\t\t\t\t\treturn new ServerGeneratedUuid(this.createEntityData(entityMap, newDatum))\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (fromTarget instanceof Set) {\n\t\t\tif (Array.isArray(newDatum)) {\n\t\t\t\tfromTarget.clear()\n\t\t\t\tfor (const entityData of newDatum) {\n\t\t\t\t\tfromTarget.add(this.createEntityData(entityMap, entityData))\n\t\t\t\t}\n\t\t\t\treturn fromTarget\n\t\t\t}\n\t\t} else if (!Array.isArray(newDatum) && (newDatum === null || typeof newDatum !== 'object')) {\n\t\t\treturn newDatum\n\t\t}\n\t\treturn this.rejectData()\n\t}\n\n\tprivate static mergeInEntityData(\n\t\tentityMap: PersistedEntityDataStore,\n\t\ttarget: SingleEntityPersistedData,\n\t\tnewData: ReceivedEntityData,\n\t): SingleEntityPersistedData {\n\t\tfor (const field in newData) {\n\t\t\tconst fromTarget = target.get(field)\n\t\t\tconst newDatum = newData[field]\n\n\t\t\ttarget.set(field, this.mergeInFieldData(entityMap, fromTarget, newDatum))\n\t\t}\n\t\treturn target\n\t}\n\n\tprivate static rejectData(extraMessage?: string): never {\n\t\tthrow new BindingError(`Failed to process data received from the API.${extraMessage ? `\\n${extraMessage}` : ''}`)\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;gCAeuC;AAAA,SACxB,qBACb,UACA,kBACc;A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AAO,aAAa,YAAY,CAAC,MAAM,QAAQ,WAAW;AACpE,cAAM,QAAQ,SAAS;AACvB,cAAM,SAAS,UAAU,IAAI;AAC7B,YAAI,WAAW,QAAW;AACzB,iBAAO,IAAI,oBAAoB,KAAK,iBAAiB,WAAW;AAAA;AAGjE,YAAI,YAAY,UAAU,OAAO;AAChC,eAAK,kBAAkB,WAAW,QAAQ;AAC1C,iBAAO;AAAA,eACD;AACN,iBAAO,IAAI,oBAAoB,KAAK,iBAAiB,WAAW;AAAA;AAAA;AAAA,eAGxD,sBAAsB,KAAK;AACrC,UAAI,MAAM,QAAQ,WAAW;AAC5B,mBAAW;AACX,mBAAW,cAAc,UAAU;AAClC,qBAAW,IAAI,KAAK,iBAAiB,WAAW;AAAA;AAEjD,eAAO;AAAA;AAAA,eAEE,CAAC,MAAM,QAAQ,2BAA2B,QAAQ,OAAO,aAAa,WAAW;AAC3F,aAAO;AAAA;AAER,WAAO,KAAK;AAAA;AAAA,SAGE,kBACd,WACA,QACA,SAC4B;AAC5B,eAAW,SAAS,SAAS;AAC5B,YAAM,aAAa,OAAO,IAAI;AAC9B,YAAM,WAAW,QAAQ;AAEzB,aAAO,IAAI,OAAO,KAAK,iBAAiB,WAAW,YAAY;AAAA;AAEhE,WAAO;AAAA;AAAA,SAGO,WAAW,cAA8B;AACvD,UAAM,IAAI,aAAa,gDAAgD,eAAe;AAAA,EAAK,iBAAiB;AAAA;AAAA;;;;"}
|
|
@@ -35,7 +35,7 @@ class StateInitializer {
|
|
|
35
35
|
let subTreeState;
|
|
36
36
|
const persistedRootData = this.treeStore.subTreePersistedData.get(tree.placeholderName);
|
|
37
37
|
if (tree instanceof EntityListSubTreeMarker) {
|
|
38
|
-
const persistedEntityIds = persistedRootData instanceof Set ? persistedRootData : new Set();
|
|
38
|
+
const persistedEntityIds = persistedRootData instanceof Set ? persistedRootData : /* @__PURE__ */ new Set();
|
|
39
39
|
subTreeState = this.initializeEntityListState({ marker: tree, parent: void 0 }, tree.entityName, persistedEntityIds);
|
|
40
40
|
} else {
|
|
41
41
|
subTreeState = this.materializeEntityRealm(this.initializeEntityRealm(persistedRootData instanceof ServerGeneratedUuid ? persistedRootData : new UnpersistedEntityDummyId(), tree.entityName, {
|
|
@@ -76,7 +76,7 @@ class StateInitializer {
|
|
|
76
76
|
}
|
|
77
77
|
this.initializeFromFieldMarker(realm, field, value.value);
|
|
78
78
|
} else if (field instanceof HasManyRelationMarker) {
|
|
79
|
-
this.initializeFromHasManyRelationMarker(realm, field, new Set());
|
|
79
|
+
this.initializeFromHasManyRelationMarker(realm, field, /* @__PURE__ */ new Set());
|
|
80
80
|
} else if (field instanceof HasOneRelationMarker) {
|
|
81
81
|
let runtimeId;
|
|
82
82
|
let subCopyFrom = void 0;
|
|
@@ -109,7 +109,7 @@ class StateInitializer {
|
|
|
109
109
|
realmKey,
|
|
110
110
|
entity,
|
|
111
111
|
accessor: void 0,
|
|
112
|
-
children: new Map(),
|
|
112
|
+
children: /* @__PURE__ */ new Map(),
|
|
113
113
|
childrenWithPendingUpdates: void 0,
|
|
114
114
|
errors: void 0,
|
|
115
115
|
eventListeners: this.initializeEntityEventListenerStore(blueprint),
|
|
@@ -145,7 +145,7 @@ class StateInitializer {
|
|
|
145
145
|
if (field instanceof FieldMarker) {
|
|
146
146
|
this.initializeFromFieldMarker(entityRealm, field, fieldDatum);
|
|
147
147
|
} else if (field instanceof HasManyRelationMarker) {
|
|
148
|
-
this.initializeFromHasManyRelationMarker(entityRealm, field, fieldDatum instanceof Set ? fieldDatum : new Set());
|
|
148
|
+
this.initializeFromHasManyRelationMarker(entityRealm, field, fieldDatum instanceof Set ? fieldDatum : /* @__PURE__ */ new Set());
|
|
149
149
|
} else if (field instanceof HasOneRelationMarker) {
|
|
150
150
|
let runtimeId;
|
|
151
151
|
if (pathBack?.fieldBackToParent === field.parameters.field) {
|
|
@@ -183,7 +183,7 @@ class StateInitializer {
|
|
|
183
183
|
id,
|
|
184
184
|
isScheduledForDeletion: false,
|
|
185
185
|
maidenId: id instanceof UnpersistedEntityDummyId ? id : void 0,
|
|
186
|
-
realms: new Map()
|
|
186
|
+
realms: /* @__PURE__ */ new Map()
|
|
187
187
|
};
|
|
188
188
|
this.treeStore.entityStore.set(entityId, entityState);
|
|
189
189
|
return entityState;
|
|
@@ -235,7 +235,14 @@ class StateInitializer {
|
|
|
235
235
|
hasUnpersistedChanges: false,
|
|
236
236
|
getAccessor: () => {
|
|
237
237
|
if (fieldState.accessor === void 0) {
|
|
238
|
-
|
|
238
|
+
const fieldSchema = this.treeStore.schema.getEntityField(parent.entity.entityName, fieldMarker.fieldName);
|
|
239
|
+
if (!fieldSchema) {
|
|
240
|
+
throw new BindingError(`Unknown field ${parent.entity.entityName}.${fieldMarker.fieldName}.`);
|
|
241
|
+
}
|
|
242
|
+
if (fieldSchema.__typename !== "_Column") {
|
|
243
|
+
throw new BindingError(`Invalid type of field ${parent.entity.entityName}.${fieldMarker.fieldName}. Expected '_Column', '${fieldSchema.__typename}' found.`);
|
|
244
|
+
}
|
|
245
|
+
fieldState.accessor = new FieldAccessor(fieldState, this.fieldOperations, fieldState.placeholderName, fieldState.value, fieldState.persistedValue === void 0 ? null : fieldState.persistedValue, fieldState.fieldMarker.defaultValue, fieldState.errors, fieldState.hasUnpersistedChanges, fieldState.touchLog, fieldState.getAccessor, fieldSchema);
|
|
239
246
|
}
|
|
240
247
|
return fieldState.accessor;
|
|
241
248
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StateInitializer.js","sources":["../../../src/core/StateInitializer.ts"],"sourcesContent":["import { BatchUpdatesOptions, EntityAccessor, EntityListAccessor, FieldAccessor } from '../accessors'\nimport { EntityFieldPersistedData, RuntimeId, ServerGeneratedUuid, UnpersistedEntityDummyId } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport {\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n} from '../markers'\nimport { BijectiveIndexedMap } from '../structures'\nimport type {\n\tEntityEventListenerStore,\n\tEntityListEventListenerStore,\n\tEntityName,\n\tFieldEventListenerStore,\n\tFieldName,\n\tScalar,\n} from '../treeParameters'\nimport { assertNever } from '../utils'\nimport type { AccessorErrorManager } from './AccessorErrorManager'\nimport type { Config } from './Config'\nimport type { EventManager } from './EventManager'\nimport { EntityOperations, FieldOperations, ListOperations } from './operations'\nimport { RealmKeyGenerator } from './RealmKeyGenerator'\nimport {\n\tEntityListBlueprint,\n\tEntityListState,\n\tEntityRealmBlueprint,\n\tEntityRealmState,\n\tEntityRealmStateStub,\n\tEntityState,\n\tFieldState,\n\tgetEntityMarker,\n\tRootStateNode,\n} from './state'\nimport { TreeParameterMerger } from './TreeParameterMerger'\nimport type { TreeStore } from './TreeStore'\nimport { EventListenersStore } from '../treeParameters'\n\nexport class StateInitializer {\n\tprivate readonly fieldOperations: FieldOperations\n\tprivate readonly entityOperations: EntityOperations\n\tprivate readonly listOperations: ListOperations\n\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly config: Config,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {\n\t\tthis.fieldOperations = new FieldOperations(this.accessorErrorManager, this.eventManager, this, this.treeStore)\n\t\tthis.entityOperations = new EntityOperations(\n\t\t\tthis.accessorErrorManager,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.eventManager,\n\t\t\tthis,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.listOperations = new ListOperations(\n\t\t\tthis.accessorErrorManager,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.eventManager,\n\t\t\tthis,\n\t\t\tthis.treeStore,\n\t\t)\n\t}\n\n\tpublic initializeSubTree(tree: EntitySubTreeMarker | EntityListSubTreeMarker): RootStateNode {\n\t\tlet subTreeState: RootStateNode\n\t\tconst persistedRootData = this.treeStore.subTreePersistedData.get(tree.placeholderName)\n\n\t\tif (tree instanceof EntityListSubTreeMarker) {\n\t\t\tconst persistedEntityIds: Set<string> = persistedRootData instanceof Set ? persistedRootData : new Set()\n\t\t\tsubTreeState = this.initializeEntityListState(\n\t\t\t\t{ marker: tree, parent: undefined },\n\t\t\t\ttree.entityName,\n\t\t\t\tpersistedEntityIds,\n\t\t\t)\n\t\t} else {\n\t\t\tsubTreeState = this.materializeEntityRealm(\n\t\t\t\tthis.initializeEntityRealm(\n\t\t\t\t\tpersistedRootData instanceof ServerGeneratedUuid ? persistedRootData : new UnpersistedEntityDummyId(),\n\t\t\t\t\ttree.entityName,\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'subTree',\n\t\t\t\t\t\tmarker: tree,\n\t\t\t\t\t\tparent: undefined,\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\n\t\treturn subTreeState\n\t}\n\n\tpublic initializeEntityRealm(\n\t\tid: RuntimeId,\n\t\tentityName: EntityName,\n\t\tblueprint: EntityRealmBlueprint,\n\t\tcopyFrom?: EntityRealmState | EntityRealmStateStub,\n\t): EntityRealmState | EntityRealmStateStub {\n\t\t// This is counter-intuitive a bit. The method can also return an EntityRealmState, not just a stub.\n\t\t// The reason is so that each call-site can just default to trying to initialize a stub without having to keep\n\t\t// in mind that the realm might have already been initialized.\n\n\t\tconst entity = this.initializeEntityState(id, entityName)\n\t\tconst realmKey = RealmKeyGenerator.getRealmKey(id, blueprint)\n\n\t\tconst existing = this.treeStore.entityRealmStore.get(realmKey)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\n\t\tif (!copyFrom || copyFrom.type !== 'entityRealm') {\n\t\t\tconst stub: EntityRealmStateStub = {\n\t\t\t\ttype: 'entityRealmStub',\n\n\t\t\t\tblueprint,\n\t\t\t\tentity,\n\t\t\t\trealmKey,\n\t\t\t\tgetAccessor: () => this.materializeEntityRealm(stub).getAccessor(),\n\t\t\t}\n\t\t\tthis.registerEntityRealm(stub)\n\n\t\t\treturn stub\n\t\t}\n\t\tconst realm = this.createEntityRealm(blueprint, realmKey, entity)\n\n\t\tthis.registerEntityRealm(realm)\n\n\t\tconst marker = getEntityMarker(realm)\n\t\tconst pathBack = this.treeStore.getPathBackToParent(realm)\n\n\t\tfor (const [placeholderName, field] of marker.fields.markers) {\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tconst value = copyFrom.children.get(placeholderName)\n\t\t\t\tif (!value || value.type !== 'field') {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tthis.initializeFromFieldMarker(realm, field, value.value)\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\t// todo: get from copyFrom\n\t\t\t\tthis.initializeFromHasManyRelationMarker(realm, field, new Set())\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tlet runtimeId: RuntimeId\n\t\t\t\tlet subCopyFrom: EntityRealmState | undefined = undefined\n\t\t\t\tif (pathBack?.fieldBackToParent === field.parameters.field) {\n\t\t\t\t\truntimeId = pathBack.parent.entity.id\n\t\t\t\t} else {\n\t\t\t\t\tconst value = copyFrom.children.get(placeholderName)\n\t\t\t\t\tif (!value || (value.type !== 'entityRealm' && value.type !== 'entityRealmStub')) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (value.type === 'entityRealm') {\n\t\t\t\t\t\tsubCopyFrom = value\n\t\t\t\t\t\truntimeId = value.entity.id\n\t\t\t\t\t} else {\n\t\t\t\t\t\truntimeId = new UnpersistedEntityDummyId()\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.initializeFromHasOneRelationMarker(realm, field, runtimeId, subCopyFrom)\n\t\t\t} else {\n\t\t\t\tassertNever(field)\n\t\t\t}\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(realm)\n\t\treturn realm\n\t}\n\n\tprivate createEntityRealm(blueprint: EntityRealmBlueprint, realmKey: string, entity: EntityState): EntityRealmState {\n\t\tconst entityRealm: EntityRealmState = {\n\t\t\ttype: 'entityRealm',\n\n\t\t\tblueprint,\n\t\t\trealmKey,\n\t\t\tentity,\n\n\t\t\taccessor: undefined,\n\t\t\tchildren: new Map(),\n\t\t\tchildrenWithPendingUpdates: undefined,\n\t\t\terrors: undefined,\n\t\t\teventListeners: this.initializeEntityEventListenerStore(blueprint),\n\t\t\tfieldsWithPendingConnectionUpdates: undefined,\n\t\t\tplannedHasOneDeletions: undefined,\n\t\t\tunpersistedChangesCount: 0,\n\t\t\tgetAccessor: () => {\n\t\t\t\tif (entityRealm.accessor === undefined) {\n\t\t\t\t\tconst entity = entityRealm.entity\n\t\t\t\t\tentityRealm.accessor = new EntityAccessor(\n\t\t\t\t\t\tentityRealm,\n\t\t\t\t\t\tthis.entityOperations,\n\t\t\t\t\t\tentity.id,\n\t\t\t\t\t\tentityRealm.realmKey,\n\t\t\t\t\t\tentity.entityName,\n\n\t\t\t\t\t\t// We're technically exposing more info in runtime than we'd like but that way we don't have to allocate and\n\t\t\t\t\t\t// keep in sync two copies of the same data. TS hides the extra info anyway.\n\t\t\t\t\t\tentityRealm.children,\n\t\t\t\t\t\tthis.treeStore.persistedEntityData.get(entity.id.value),\n\t\t\t\t\t\tentityRealm.unpersistedChangesCount !== 0,\n\t\t\t\t\t\tentityRealm.errors,\n\t\t\t\t\t\tgetEntityMarker(entityRealm).environment,\n\t\t\t\t\t\tentityRealm.getAccessor,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn entityRealm.accessor\n\t\t\t},\n\t\t}\n\t\treturn entityRealm\n\t}\n\n\tprivate materializeEntityRealm(state: EntityRealmState | EntityRealmStateStub): EntityRealmState {\n\t\tif (state.type === 'entityRealm') {\n\t\t\treturn state\n\t\t}\n\t\tconst { realmKey, entity, blueprint } = state\n\n\t\tconst existing = this.treeStore.entityRealmStore.get(realmKey)\n\t\tif (existing !== undefined && existing.type === 'entityRealm') {\n\t\t\treturn existing\n\t\t}\n\n\t\tconst entityRealm = this.createEntityRealm(blueprint, realmKey, entity)\n\n\t\tthis.registerEntityRealm(entityRealm)\n\n\t\t// if (blueprint.creationParameters.forceCreation && !entity.id.existsOnServer) {\n\t\t// \tentityRealm.unpersistedChangesCount += 1\n\t\t// }\n\n\t\tconst persistedData = this.treeStore.persistedEntityData.get(entity.id.value)\n\n\t\tconst marker = getEntityMarker(state)\n\t\tconst pathBack = this.treeStore.getPathBackToParent(entityRealm)\n\n\t\tfor (const [placeholderName, field] of marker.fields.markers) {\n\t\t\tconst fieldDatum = persistedData?.get(placeholderName)\n\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tthis.initializeFromFieldMarker(entityRealm, field, fieldDatum)\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\t// if (pathBack?.fieldBackToParent === field.parameters.field) {\n\t\t\t\t// \t// TODO this is probably wrong?\n\t\t\t\t// \tconst ids = pathBack.parent.children.get(field.placeholderName)\n\t\t\t\t// \tconst newData = this.treeStore.persistedEntityData.get(pathBack.parent.entity.id.value)\n\t\t\t\t// \tconsole.log('many?', pathBack, field, entityRealm, fieldDatum, ids)\n\t\t\t\t// }\n\t\t\t\tthis.initializeFromHasManyRelationMarker(entityRealm, field, fieldDatum instanceof Set ? fieldDatum : new Set())\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tlet runtimeId: RuntimeId\n\t\t\t\tif (pathBack?.fieldBackToParent === field.parameters.field) {\n\t\t\t\t\truntimeId = pathBack.parent.entity.id\n\t\t\t\t} else {\n\t\t\t\t\truntimeId = fieldDatum instanceof ServerGeneratedUuid ? fieldDatum : new UnpersistedEntityDummyId()\n\t\t\t\t}\n\t\t\t\tthis.initializeFromHasOneRelationMarker(entityRealm, field, runtimeId)\n\t\t\t} else {\n\t\t\t\tassertNever(field)\n\t\t\t}\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(entityRealm)\n\n\t\treturn entityRealm\n\t}\n\n\tprivate registerEntityRealm(entityRealm: EntityRealmState | EntityRealmStateStub) {\n\t\tconst { realmKey, blueprint, entity } = entityRealm\n\n\t\tthis.treeStore.entityRealmStore.set(entityRealm.realmKey, entityRealm)\n\n\t\tif (blueprint.type === 'listEntity') {\n\t\t\tblueprint.parent.children.set(entity.id.value, entityRealm)\n\t\t} else if (blueprint.type === 'hasOne') {\n\t\t\tblueprint.parent.children.set(blueprint.marker.placeholderName, entityRealm)\n\t\t}\n\t\tentity.realms.set(realmKey, entityRealm)\n\t}\n\n\tpublic initializeEntityState(id: RuntimeId, entityName: EntityName): EntityState {\n\t\tconst entityId = id.value\n\n\t\tconst existing = this.treeStore.entityStore.get(entityId)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\n\t\tconst entityState: EntityState = {\n\t\t\tentityName,\n\t\t\thasIdSetInStone: id instanceof ServerGeneratedUuid,\n\t\t\tid,\n\t\t\tisScheduledForDeletion: false,\n\t\t\tmaidenId: id instanceof UnpersistedEntityDummyId ? id : undefined,\n\t\t\trealms: new Map(),\n\t\t}\n\t\tthis.treeStore.entityStore.set(entityId, entityState)\n\n\t\treturn entityState\n\t}\n\n\tprivate initializeEntityListState(\n\t\tblueprint: EntityListBlueprint,\n\t\tentityName: EntityName,\n\t\tinitialEntityIds: Set<string>,\n\t): EntityListState {\n\t\tconst entityListState: EntityListState = {\n\t\t\ttype: 'entityList',\n\t\t\taccessor: undefined,\n\t\t\tblueprint,\n\t\t\tchildren: new BijectiveIndexedMap(realm => realm.entity.id.value),\n\t\t\tchildrenWithPendingUpdates: undefined,\n\t\t\tentityName,\n\t\t\teventListeners: this.initializeEntityListEventListenerStore(blueprint),\n\t\t\tchildEventListeners: this.initializeEntityListChildEventListenerStore(blueprint),\n\t\t\terrors: undefined,\n\t\t\tplannedRemovals: undefined,\n\t\t\tunpersistedChangesCount: 0, // TODO force creation?\n\t\t\tgetAccessor: () => {\n\t\t\t\tif (entityListState.accessor === undefined) {\n\t\t\t\t\tconst persistedEntityIds = this.treeStore.getEntityListPersistedIds(entityListState)\n\t\t\t\t\tentityListState.accessor = new EntityListAccessor(\n\t\t\t\t\t\tentityListState,\n\t\t\t\t\t\tthis.listOperations,\n\t\t\t\t\t\tentityListState.children,\n\t\t\t\t\t\tpersistedEntityIds,\n\t\t\t\t\t\tentityListState.unpersistedChangesCount !== 0,\n\t\t\t\t\t\tentityListState.errors,\n\t\t\t\t\t\tentityListState.blueprint.marker.environment,\n\t\t\t\t\t\tentityListState.getAccessor,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn entityListState.accessor\n\t\t\t},\n\t\t}\n\n\t\tconst initialData: Iterable<string | undefined> =\n\t\t\tinitialEntityIds.size === 0\n\t\t\t\t? Array.from({ length: blueprint.marker.parameters.initialEntityCount })\n\t\t\t\t: initialEntityIds\n\t\tfor (const entityId of initialData) {\n\t\t\tthis.initializeEntityRealm(\n\t\t\t\tentityId ? new ServerGeneratedUuid(entityId) : new UnpersistedEntityDummyId(),\n\t\t\t\tentityListState.entityName,\n\t\t\t\t{\n\t\t\t\t\ttype: 'listEntity',\n\t\t\t\t\tparent: entityListState,\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(entityListState)\n\n\t\treturn entityListState\n\t}\n\n\tprivate initializeFieldState(\n\t\tparent: EntityRealmState,\n\t\tplaceholderName: FieldName,\n\t\tfieldMarker: FieldMarker,\n\t\tpersistedValue: Scalar | undefined,\n\t): FieldState {\n\t\tconst resolvedFieldValue = persistedValue ?? fieldMarker.defaultValue ?? null\n\n\t\tconst fieldState: FieldState = {\n\t\t\ttype: 'field',\n\t\t\taccessor: undefined,\n\t\t\tfieldMarker,\n\t\t\tplaceholderName,\n\t\t\tpersistedValue,\n\t\t\tparent,\n\t\t\tvalue: resolvedFieldValue,\n\t\t\teventListeners: this.initializeFieldEventListenerStore(fieldMarker),\n\t\t\terrors: undefined,\n\t\t\ttouchLog: undefined,\n\t\t\thasUnpersistedChanges: false,\n\t\t\tgetAccessor: () => {\n\t\t\t\tif (fieldState.accessor === undefined) {\n\t\t\t\t\tfieldState.accessor = new FieldAccessor(\n\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\tthis.fieldOperations,\n\t\t\t\t\t\tfieldState.placeholderName,\n\t\t\t\t\t\tfieldState.value,\n\t\t\t\t\t\tfieldState.persistedValue === undefined ? null : fieldState.persistedValue,\n\t\t\t\t\t\tfieldState.fieldMarker.defaultValue,\n\t\t\t\t\t\tfieldState.errors,\n\t\t\t\t\t\tfieldState.hasUnpersistedChanges,\n\t\t\t\t\t\tfieldState.touchLog,\n\t\t\t\t\t\tfieldState.getAccessor,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn fieldState.accessor\n\t\t\t},\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(fieldState)\n\t\treturn fieldState\n\t}\n\n\tprivate initializeFromFieldMarker(\n\t\tparent: EntityRealmState,\n\t\tfield: FieldMarker,\n\t\tfieldDatum: EntityFieldPersistedData | undefined,\n\t) {\n\t\tif (fieldDatum instanceof Set) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Received a collection of referenced entities where a single '${field.fieldName}' field was expected. ` +\n\t\t\t\t\t`Perhaps you wanted to use a <Repeater />?`,\n\t\t\t)\n\t\t}\n\t\tif (fieldDatum instanceof ServerGeneratedUuid) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Received a referenced entity where a single '${field.fieldName}' field was expected. ` +\n\t\t\t\t\t`Perhaps you wanted to use <HasOne />?`,\n\t\t\t)\n\t\t}\n\t\tparent.children.set(\n\t\t\tfield.placeholderName,\n\t\t\tthis.initializeFieldState(parent, field.placeholderName, field, fieldDatum),\n\t\t)\n\t}\n\n\tprivate initializeFromHasOneRelationMarker(\n\t\tparent: EntityRealmState,\n\t\tfield: HasOneRelationMarker,\n\t\tentityId: RuntimeId,\n\t\tcopyFrom?: EntityRealmState | EntityRealmStateStub,\n\t) {\n\t\tparent.children.set(\n\t\t\tfield.placeholderName,\n\t\t\tthis.initializeEntityRealm(entityId, this.getRelationTargetEntityName(parent, field), {\n\t\t\t\ttype: 'hasOne',\n\t\t\t\tparent,\n\t\t\t\tmarker: field,\n\t\t\t}, copyFrom),\n\t\t)\n\t\t// if (fieldDatum instanceof ServerGeneratedUuid || fieldDatum === null || fieldDatum === undefined) {\n\t\t// \tconst entityId = fieldDatum instanceof ServerGeneratedUuid ? fieldDatum : new UnpersistedEntityDummyId()\n\t\t//\n\t\t//\n\t\t// } else if (fieldDatum instanceof Set) {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a collection of entities for field '${relation.field}' where a single entity was expected. ` +\n\t\t// \t\t\t`Perhaps you wanted to use a <Repeater />?`,\n\t\t// \t)\n\t\t// } else {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a scalar value for field '${relation.field}' where a single entity was expected.` +\n\t\t// \t\t\t`Perhaps you meant to use a variant of <Field />?`,\n\t\t// \t)\n\t\t// }\n\t}\n\n\tprivate initializeFromHasManyRelationMarker(\n\t\tparent: EntityRealmState,\n\t\tfield: HasManyRelationMarker,\n\t\tpersistedEntityIds: Set<string>,\n\t) {\n\t\tparent.children.set(\n\t\t\tfield.placeholderName,\n\t\t\tthis.initializeEntityListState(\n\t\t\t\t{ marker: field, parent },\n\t\t\t\tthis.getRelationTargetEntityName(parent, field),\n\t\t\t\tpersistedEntityIds,\n\t\t\t),\n\t\t)\n\t\t// const relation = field.parameters\n\t\t//\n\t\t// if (fieldDatum === undefined || fieldDatum instanceof Set) {\n\t\t//\n\t\t// } else if (typeof fieldDatum === 'object') {\n\t\t// \t// Intentionally allowing `fieldDatum === null` here as well since this should only happen when a *hasOne\n\t\t// \t// relation is unlinked, e.g. a Person does not have a linked Nationality.\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a referenced entity for field '${relation.field}' where a collection of entities was expected.` +\n\t\t// \t\t\t`Perhaps you wanted to use a <HasOne />?`,\n\t\t// \t)\n\t\t// } else {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a scalar value for field '${relation.field}' where a collection of entities was expected.` +\n\t\t// \t\t\t`Perhaps you meant to use a variant of <Field />?`,\n\t\t// \t)\n\t\t// }\n\t}\n\n\tprivate getRelationTargetEntityName(\n\t\tentityRealm: EntityRealmState,\n\t\tfield: HasOneRelationMarker | HasManyRelationMarker,\n\t): EntityName {\n\t\tconst targetField = this.treeStore.schema.getEntityField(entityRealm.entity.entityName, field.parameters.field)\n\n\t\tif (targetField?.__typename !== '_Relation') {\n\t\t\tthrow new BindingError() // This should have been validated elsewhere.\n\t\t}\n\t\treturn targetField.targetEntity\n\t}\n\n\tpublic runImmediateUserInitialization(\n\t\trealm: EntityRealmState | EntityRealmStateStub,\n\t\tinitialize: EntityAccessor.BatchUpdatesHandler | undefined,\n\t) {\n\t\tif (initialize === undefined) {\n\t\t\treturn\n\t\t}\n\t\tconst entityRealm = this.materializeEntityRealm(realm)\n\n\t\trealm.getAccessor().batchUpdates(initialize)\n\n\t\tconst initializeListeners = this.eventManager.getEventListeners(entityRealm, { type: 'initialize' })\n\t\tif (initializeListeners === undefined || initializeListeners.size === 0) {\n\t\t\trealm.entity.hasIdSetInStone = true\n\t\t}\n\t}\n\n\tpublic initializeEntityEventListenerStore(blueprint: EntityRealmBlueprint): EntityEventListenerStore | undefined {\n\t\tif (blueprint.type === 'listEntity') {\n\t\t\tconst blueprintListeners = blueprint.parent.blueprint.marker.parameters.childEventListeners\n\t\t\tconst childInitialize = blueprintListeners?.get({ type: 'initialize' })\n\t\t\tconst store: EntityEventListenerStore = new EventListenersStore(() => blueprint.parent.childEventListeners)\n\n\t\t\tif (childInitialize !== undefined) {\n\t\t\t\tstore.set({ type: 'initialize' }, childInitialize)\n\t\t\t}\n\t\t\treturn store\n\t\t}\n\n\t\tconst blueprintListeners = blueprint.marker.parameters.eventListeners\n\t\tif (blueprintListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn TreeParameterMerger.cloneSingleEntityEventListeners(blueprintListeners)\n\t}\n\n\tprivate initializeEntityListEventListenerStore(\n\t\tblueprint: EntityListBlueprint,\n\t): EntityListEventListenerStore | undefined {\n\t\tconst blueprintListeners = blueprint.marker.parameters.eventListeners\n\n\t\tif (blueprintListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn TreeParameterMerger.cloneEntityListEventListeners(blueprintListeners)\n\t}\n\n\tprivate initializeEntityListChildEventListenerStore(\n\t\tblueprint: EntityListBlueprint,\n\t): EntityEventListenerStore | undefined {\n\t\tconst blueprintListeners = blueprint.marker.parameters.childEventListeners\n\n\t\tif (blueprintListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn TreeParameterMerger.cloneSingleEntityEventListeners(blueprintListeners)\n\t}\n\n\tprivate initializeFieldEventListenerStore(marker: FieldMarker): FieldEventListenerStore | undefined {\n\t\t// TODO !!!\n\t\treturn undefined\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;uBAwC8B;AAAA,EAKtB,YACW,sBACA,qBACA,QACA,cACA,WAChB;AALgB;AACA;AACA;AACA;AACA;AAEjB,SAAK,kBAAkB,IAAI,gBAAgB,KAAK,sBAAsB,KAAK,cAAc,MAAM,KAAK;AACpG,SAAK,mBAAmB,IAAI,iBAC3B,KAAK,sBACL,KAAK,qBACL,KAAK,cACL,MACA,KAAK;AAEN,SAAK,iBAAiB,IAAI,eACzB,KAAK,sBACL,KAAK,qBACL,KAAK,cACL,MACA,KAAK;AAAA;AAAA,EAxBU;AAAA,EACA;AAAA,EACA;AAAA,EA0BV,kBAAkB,MAAoE;AAC5F,QAAI;AACJ,UAAM,oBAAoB,KAAK,UAAU,qBAAqB,IAAI,KAAK;AAEvE,QAAI,gBAAgB,yBAAyB;AAC5C,YAAM,qBAAkC,6BAA6B,MAAM,oBAAoB,IAAI;AACnG,qBAAe,KAAK,0BACnB,EAAE,QAAQ,MAAM,QAAQ,UACxB,KAAK,YACL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BAAkB,aAAa,EAAE,MAAM;AACrF,QAAI,wBAAwB,UAAa,oBAAoB,SAAS,GAAG;AACxE,YAAM,OAAO,kBAAkB;AAAA;AAAA;AAAA,EAI1B,mCAAmC,WAAuE;AAChH,QAAI,UAAU,SAAS,cAAc;AACpC,YAAM,sBAAqB,UAAU,OAAO,UAAU,OAAO,WAAW;AACxE,YAAM,kBAAkB,qBAAoB,IAAI,EAAE,MAAM;AACxD,YAAM,QAAkC,IAAI,oBAAoB,MAAM,UAAU,OAAO;AAEvF,UAAI,oBAAoB,QAAW;AAClC,cAAM,IAAI,EAAE,MAAM,gBAAgB;AAAA;AAEnC,aAAO;AAAA;AAGR,UAAM,qBAAqB,UAAU,OAAO,WAAW;AACvD,QAAI,uBAAuB,QAAW;AACrC,aAAO;AAAA;AAER,WAAO,oBAAoB,gCAAgC;AAAA;AAAA,EAGpD,uCACP,WAC2C;AAC3C,UAAM,qBAAqB,UAAU,OAAO,WAAW;AAEvD,QAAI,uBAAuB,QAAW;AACrC,aAAO;AAAA;AAER,WAAO,oBAAoB,8BAA8B;AAAA;AAAA,EAGlD,4CACP,WACuC;AACvC,UAAM,qBAAqB,UAAU,OAAO,WAAW;AAEvD,QAAI,uBAAuB,QAAW;AACrC,aAAO;AAAA;AAER,WAAO,oBAAoB,gCAAgC;AAAA;AAAA,EAGpD,kCAAkC,QAA0D;AAEnG,WAAO;AAAA;AAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"StateInitializer.js","sources":["../../../src/core/StateInitializer.ts"],"sourcesContent":["import { BatchUpdatesOptions, EntityAccessor, EntityListAccessor, FieldAccessor } from '../accessors'\nimport { EntityFieldPersistedData, RuntimeId, ServerGeneratedUuid, UnpersistedEntityDummyId } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport {\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n} from '../markers'\nimport { BijectiveIndexedMap } from '../structures'\nimport type {\n\tEntityEventListenerStore,\n\tEntityListEventListenerStore,\n\tEntityName,\n\tFieldEventListenerStore,\n\tFieldName,\n\tScalar,\n} from '../treeParameters'\nimport { assertNever } from '../utils'\nimport type { AccessorErrorManager } from './AccessorErrorManager'\nimport type { Config } from './Config'\nimport type { EventManager } from './EventManager'\nimport { EntityOperations, FieldOperations, ListOperations } from './operations'\nimport { RealmKeyGenerator } from './RealmKeyGenerator'\nimport {\n\tEntityListBlueprint,\n\tEntityListState,\n\tEntityRealmBlueprint,\n\tEntityRealmState,\n\tEntityRealmStateStub,\n\tEntityState,\n\tFieldState,\n\tgetEntityMarker,\n\tRootStateNode,\n} from './state'\nimport { TreeParameterMerger } from './TreeParameterMerger'\nimport type { TreeStore } from './TreeStore'\nimport { EventListenersStore } from '../treeParameters'\n\nexport class StateInitializer {\n\tprivate readonly fieldOperations: FieldOperations\n\tprivate readonly entityOperations: EntityOperations\n\tprivate readonly listOperations: ListOperations\n\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly config: Config,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {\n\t\tthis.fieldOperations = new FieldOperations(this.accessorErrorManager, this.eventManager, this, this.treeStore)\n\t\tthis.entityOperations = new EntityOperations(\n\t\t\tthis.accessorErrorManager,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.eventManager,\n\t\t\tthis,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.listOperations = new ListOperations(\n\t\t\tthis.accessorErrorManager,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.eventManager,\n\t\t\tthis,\n\t\t\tthis.treeStore,\n\t\t)\n\t}\n\n\tpublic initializeSubTree(tree: EntitySubTreeMarker | EntityListSubTreeMarker): RootStateNode {\n\t\tlet subTreeState: RootStateNode\n\t\tconst persistedRootData = this.treeStore.subTreePersistedData.get(tree.placeholderName)\n\n\t\tif (tree instanceof EntityListSubTreeMarker) {\n\t\t\tconst persistedEntityIds: Set<string> = persistedRootData instanceof Set ? persistedRootData : new Set()\n\t\t\tsubTreeState = this.initializeEntityListState(\n\t\t\t\t{ marker: tree, parent: undefined },\n\t\t\t\ttree.entityName,\n\t\t\t\tpersistedEntityIds,\n\t\t\t)\n\t\t} else {\n\t\t\tsubTreeState = this.materializeEntityRealm(\n\t\t\t\tthis.initializeEntityRealm(\n\t\t\t\t\tpersistedRootData instanceof ServerGeneratedUuid ? persistedRootData : new UnpersistedEntityDummyId(),\n\t\t\t\t\ttree.entityName,\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'subTree',\n\t\t\t\t\t\tmarker: tree,\n\t\t\t\t\t\tparent: undefined,\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\n\t\treturn subTreeState\n\t}\n\n\tpublic initializeEntityRealm(\n\t\tid: RuntimeId,\n\t\tentityName: EntityName,\n\t\tblueprint: EntityRealmBlueprint,\n\t\tcopyFrom?: EntityRealmState | EntityRealmStateStub,\n\t): EntityRealmState | EntityRealmStateStub {\n\t\t// This is counter-intuitive a bit. The method can also return an EntityRealmState, not just a stub.\n\t\t// The reason is so that each call-site can just default to trying to initialize a stub without having to keep\n\t\t// in mind that the realm might have already been initialized.\n\n\t\tconst entity = this.initializeEntityState(id, entityName)\n\t\tconst realmKey = RealmKeyGenerator.getRealmKey(id, blueprint)\n\n\t\tconst existing = this.treeStore.entityRealmStore.get(realmKey)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\n\t\tif (!copyFrom || copyFrom.type !== 'entityRealm') {\n\t\t\tconst stub: EntityRealmStateStub = {\n\t\t\t\ttype: 'entityRealmStub',\n\n\t\t\t\tblueprint,\n\t\t\t\tentity,\n\t\t\t\trealmKey,\n\t\t\t\tgetAccessor: () => this.materializeEntityRealm(stub).getAccessor(),\n\t\t\t}\n\t\t\tthis.registerEntityRealm(stub)\n\n\t\t\treturn stub\n\t\t}\n\t\tconst realm = this.createEntityRealm(blueprint, realmKey, entity)\n\n\t\tthis.registerEntityRealm(realm)\n\n\t\tconst marker = getEntityMarker(realm)\n\t\tconst pathBack = this.treeStore.getPathBackToParent(realm)\n\n\t\tfor (const [placeholderName, field] of marker.fields.markers) {\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tconst value = copyFrom.children.get(placeholderName)\n\t\t\t\tif (!value || value.type !== 'field') {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tthis.initializeFromFieldMarker(realm, field, value.value)\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\t// todo: get from copyFrom\n\t\t\t\tthis.initializeFromHasManyRelationMarker(realm, field, new Set())\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tlet runtimeId: RuntimeId\n\t\t\t\tlet subCopyFrom: EntityRealmState | undefined = undefined\n\t\t\t\tif (pathBack?.fieldBackToParent === field.parameters.field) {\n\t\t\t\t\truntimeId = pathBack.parent.entity.id\n\t\t\t\t} else {\n\t\t\t\t\tconst value = copyFrom.children.get(placeholderName)\n\t\t\t\t\tif (!value || (value.type !== 'entityRealm' && value.type !== 'entityRealmStub')) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (value.type === 'entityRealm') {\n\t\t\t\t\t\tsubCopyFrom = value\n\t\t\t\t\t\truntimeId = value.entity.id\n\t\t\t\t\t} else {\n\t\t\t\t\t\truntimeId = new UnpersistedEntityDummyId()\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.initializeFromHasOneRelationMarker(realm, field, runtimeId, subCopyFrom)\n\t\t\t} else {\n\t\t\t\tassertNever(field)\n\t\t\t}\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(realm)\n\t\treturn realm\n\t}\n\n\tprivate createEntityRealm(blueprint: EntityRealmBlueprint, realmKey: string, entity: EntityState): EntityRealmState {\n\t\tconst entityRealm: EntityRealmState = {\n\t\t\ttype: 'entityRealm',\n\n\t\t\tblueprint,\n\t\t\trealmKey,\n\t\t\tentity,\n\n\t\t\taccessor: undefined,\n\t\t\tchildren: new Map(),\n\t\t\tchildrenWithPendingUpdates: undefined,\n\t\t\terrors: undefined,\n\t\t\teventListeners: this.initializeEntityEventListenerStore(blueprint),\n\t\t\tfieldsWithPendingConnectionUpdates: undefined,\n\t\t\tplannedHasOneDeletions: undefined,\n\t\t\tunpersistedChangesCount: 0,\n\t\t\tgetAccessor: () => {\n\t\t\t\tif (entityRealm.accessor === undefined) {\n\t\t\t\t\tconst entity = entityRealm.entity\n\t\t\t\t\tentityRealm.accessor = new EntityAccessor(\n\t\t\t\t\t\tentityRealm,\n\t\t\t\t\t\tthis.entityOperations,\n\t\t\t\t\t\tentity.id,\n\t\t\t\t\t\tentityRealm.realmKey,\n\t\t\t\t\t\tentity.entityName,\n\n\t\t\t\t\t\t// We're technically exposing more info in runtime than we'd like but that way we don't have to allocate and\n\t\t\t\t\t\t// keep in sync two copies of the same data. TS hides the extra info anyway.\n\t\t\t\t\t\tentityRealm.children,\n\t\t\t\t\t\tthis.treeStore.persistedEntityData.get(entity.id.value),\n\t\t\t\t\t\tentityRealm.unpersistedChangesCount !== 0,\n\t\t\t\t\t\tentityRealm.errors,\n\t\t\t\t\t\tgetEntityMarker(entityRealm).environment,\n\t\t\t\t\t\tentityRealm.getAccessor,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn entityRealm.accessor\n\t\t\t},\n\t\t}\n\t\treturn entityRealm\n\t}\n\n\tprivate materializeEntityRealm(state: EntityRealmState | EntityRealmStateStub): EntityRealmState {\n\t\tif (state.type === 'entityRealm') {\n\t\t\treturn state\n\t\t}\n\t\tconst { realmKey, entity, blueprint } = state\n\n\t\tconst existing = this.treeStore.entityRealmStore.get(realmKey)\n\t\tif (existing !== undefined && existing.type === 'entityRealm') {\n\t\t\treturn existing\n\t\t}\n\n\t\tconst entityRealm = this.createEntityRealm(blueprint, realmKey, entity)\n\n\t\tthis.registerEntityRealm(entityRealm)\n\n\t\t// if (blueprint.creationParameters.forceCreation && !entity.id.existsOnServer) {\n\t\t// \tentityRealm.unpersistedChangesCount += 1\n\t\t// }\n\n\t\tconst persistedData = this.treeStore.persistedEntityData.get(entity.id.value)\n\n\t\tconst marker = getEntityMarker(state)\n\t\tconst pathBack = this.treeStore.getPathBackToParent(entityRealm)\n\n\t\tfor (const [placeholderName, field] of marker.fields.markers) {\n\t\t\tconst fieldDatum = persistedData?.get(placeholderName)\n\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tthis.initializeFromFieldMarker(entityRealm, field, fieldDatum)\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\t// if (pathBack?.fieldBackToParent === field.parameters.field) {\n\t\t\t\t// \t// TODO this is probably wrong?\n\t\t\t\t// \tconst ids = pathBack.parent.children.get(field.placeholderName)\n\t\t\t\t// \tconst newData = this.treeStore.persistedEntityData.get(pathBack.parent.entity.id.value)\n\t\t\t\t// \tconsole.log('many?', pathBack, field, entityRealm, fieldDatum, ids)\n\t\t\t\t// }\n\t\t\t\tthis.initializeFromHasManyRelationMarker(entityRealm, field, fieldDatum instanceof Set ? fieldDatum : new Set())\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tlet runtimeId: RuntimeId\n\t\t\t\tif (pathBack?.fieldBackToParent === field.parameters.field) {\n\t\t\t\t\truntimeId = pathBack.parent.entity.id\n\t\t\t\t} else {\n\t\t\t\t\truntimeId = fieldDatum instanceof ServerGeneratedUuid ? fieldDatum : new UnpersistedEntityDummyId()\n\t\t\t\t}\n\t\t\t\tthis.initializeFromHasOneRelationMarker(entityRealm, field, runtimeId)\n\t\t\t} else {\n\t\t\t\tassertNever(field)\n\t\t\t}\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(entityRealm)\n\n\t\treturn entityRealm\n\t}\n\n\tprivate registerEntityRealm(entityRealm: EntityRealmState | EntityRealmStateStub) {\n\t\tconst { realmKey, blueprint, entity } = entityRealm\n\n\t\tthis.treeStore.entityRealmStore.set(entityRealm.realmKey, entityRealm)\n\n\t\tif (blueprint.type === 'listEntity') {\n\t\t\tblueprint.parent.children.set(entity.id.value, entityRealm)\n\t\t} else if (blueprint.type === 'hasOne') {\n\t\t\tblueprint.parent.children.set(blueprint.marker.placeholderName, entityRealm)\n\t\t}\n\t\tentity.realms.set(realmKey, entityRealm)\n\t}\n\n\tpublic initializeEntityState(id: RuntimeId, entityName: EntityName): EntityState {\n\t\tconst entityId = id.value\n\n\t\tconst existing = this.treeStore.entityStore.get(entityId)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\n\t\tconst entityState: EntityState = {\n\t\t\tentityName,\n\t\t\thasIdSetInStone: id instanceof ServerGeneratedUuid,\n\t\t\tid,\n\t\t\tisScheduledForDeletion: false,\n\t\t\tmaidenId: id instanceof UnpersistedEntityDummyId ? id : undefined,\n\t\t\trealms: new Map(),\n\t\t}\n\t\tthis.treeStore.entityStore.set(entityId, entityState)\n\n\t\treturn entityState\n\t}\n\n\tprivate initializeEntityListState(\n\t\tblueprint: EntityListBlueprint,\n\t\tentityName: EntityName,\n\t\tinitialEntityIds: Set<string>,\n\t): EntityListState {\n\t\tconst entityListState: EntityListState = {\n\t\t\ttype: 'entityList',\n\t\t\taccessor: undefined,\n\t\t\tblueprint,\n\t\t\tchildren: new BijectiveIndexedMap(realm => realm.entity.id.value),\n\t\t\tchildrenWithPendingUpdates: undefined,\n\t\t\tentityName,\n\t\t\teventListeners: this.initializeEntityListEventListenerStore(blueprint),\n\t\t\tchildEventListeners: this.initializeEntityListChildEventListenerStore(blueprint),\n\t\t\terrors: undefined,\n\t\t\tplannedRemovals: undefined,\n\t\t\tunpersistedChangesCount: 0, // TODO force creation?\n\t\t\tgetAccessor: () => {\n\t\t\t\tif (entityListState.accessor === undefined) {\n\t\t\t\t\tconst persistedEntityIds = this.treeStore.getEntityListPersistedIds(entityListState)\n\t\t\t\t\tentityListState.accessor = new EntityListAccessor(\n\t\t\t\t\t\tentityListState,\n\t\t\t\t\t\tthis.listOperations,\n\t\t\t\t\t\tentityListState.children,\n\t\t\t\t\t\tpersistedEntityIds,\n\t\t\t\t\t\tentityListState.unpersistedChangesCount !== 0,\n\t\t\t\t\t\tentityListState.errors,\n\t\t\t\t\t\tentityListState.blueprint.marker.environment,\n\t\t\t\t\t\tentityListState.getAccessor,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn entityListState.accessor\n\t\t\t},\n\t\t}\n\n\t\tconst initialData: Iterable<string | undefined> =\n\t\t\tinitialEntityIds.size === 0\n\t\t\t\t? Array.from({ length: blueprint.marker.parameters.initialEntityCount })\n\t\t\t\t: initialEntityIds\n\t\tfor (const entityId of initialData) {\n\t\t\tthis.initializeEntityRealm(\n\t\t\t\tentityId ? new ServerGeneratedUuid(entityId) : new UnpersistedEntityDummyId(),\n\t\t\t\tentityListState.entityName,\n\t\t\t\t{\n\t\t\t\t\ttype: 'listEntity',\n\t\t\t\t\tparent: entityListState,\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(entityListState)\n\n\t\treturn entityListState\n\t}\n\n\tprivate initializeFieldState(\n\t\tparent: EntityRealmState,\n\t\tplaceholderName: FieldName,\n\t\tfieldMarker: FieldMarker,\n\t\tpersistedValue: Scalar | undefined,\n\t): FieldState {\n\t\tconst resolvedFieldValue = persistedValue ?? fieldMarker.defaultValue ?? null\n\n\t\tconst fieldState: FieldState = {\n\t\t\ttype: 'field',\n\t\t\taccessor: undefined,\n\t\t\tfieldMarker,\n\t\t\tplaceholderName,\n\t\t\tpersistedValue,\n\t\t\tparent,\n\t\t\tvalue: resolvedFieldValue,\n\t\t\teventListeners: this.initializeFieldEventListenerStore(fieldMarker),\n\t\t\terrors: undefined,\n\t\t\ttouchLog: undefined,\n\t\t\thasUnpersistedChanges: false,\n\n\t\t\tgetAccessor: () => {\n\t\t\t\tif (fieldState.accessor === undefined) {\n\t\t\t\t\tconst fieldSchema = this.treeStore.schema.getEntityField(parent.entity.entityName, fieldMarker.fieldName)\n\t\t\t\t\tif (!fieldSchema) {\n\t\t\t\t\t\tthrow new BindingError(`Unknown field ${parent.entity.entityName}.${fieldMarker.fieldName}.`)\n\t\t\t\t\t}\n\t\t\t\t\tif (fieldSchema.__typename !== '_Column') {\n\t\t\t\t\t\tthrow new BindingError(`Invalid type of field ${parent.entity.entityName}.${fieldMarker.fieldName}. Expected '_Column', '${fieldSchema.__typename}' found.`)\n\t\t\t\t\t}\n\t\t\t\t\tfieldState.accessor = new FieldAccessor(\n\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\tthis.fieldOperations,\n\t\t\t\t\t\tfieldState.placeholderName,\n\t\t\t\t\t\tfieldState.value,\n\t\t\t\t\t\tfieldState.persistedValue === undefined ? null : fieldState.persistedValue,\n\t\t\t\t\t\tfieldState.fieldMarker.defaultValue,\n\t\t\t\t\t\tfieldState.errors,\n\t\t\t\t\t\tfieldState.hasUnpersistedChanges,\n\t\t\t\t\t\tfieldState.touchLog,\n\t\t\t\t\t\tfieldState.getAccessor,\n\t\t\t\t\t\tfieldSchema,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn fieldState.accessor\n\t\t\t},\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(fieldState)\n\t\treturn fieldState\n\t}\n\n\tprivate initializeFromFieldMarker(\n\t\tparent: EntityRealmState,\n\t\tfield: FieldMarker,\n\t\tfieldDatum: EntityFieldPersistedData | undefined,\n\t) {\n\t\tif (fieldDatum instanceof Set) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Received a collection of referenced entities where a single '${field.fieldName}' field was expected. ` +\n\t\t\t\t\t`Perhaps you wanted to use a <Repeater />?`,\n\t\t\t)\n\t\t}\n\t\tif (fieldDatum instanceof ServerGeneratedUuid) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Received a referenced entity where a single '${field.fieldName}' field was expected. ` +\n\t\t\t\t\t`Perhaps you wanted to use <HasOne />?`,\n\t\t\t)\n\t\t}\n\t\tparent.children.set(\n\t\t\tfield.placeholderName,\n\t\t\tthis.initializeFieldState(parent, field.placeholderName, field, fieldDatum),\n\t\t)\n\t}\n\n\tprivate initializeFromHasOneRelationMarker(\n\t\tparent: EntityRealmState,\n\t\tfield: HasOneRelationMarker,\n\t\tentityId: RuntimeId,\n\t\tcopyFrom?: EntityRealmState | EntityRealmStateStub,\n\t) {\n\t\tparent.children.set(\n\t\t\tfield.placeholderName,\n\t\t\tthis.initializeEntityRealm(entityId, this.getRelationTargetEntityName(parent, field), {\n\t\t\t\ttype: 'hasOne',\n\t\t\t\tparent,\n\t\t\t\tmarker: field,\n\t\t\t}, copyFrom),\n\t\t)\n\t\t// if (fieldDatum instanceof ServerGeneratedUuid || fieldDatum === null || fieldDatum === undefined) {\n\t\t// \tconst entityId = fieldDatum instanceof ServerGeneratedUuid ? fieldDatum : new UnpersistedEntityDummyId()\n\t\t//\n\t\t//\n\t\t// } else if (fieldDatum instanceof Set) {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a collection of entities for field '${relation.field}' where a single entity was expected. ` +\n\t\t// \t\t\t`Perhaps you wanted to use a <Repeater />?`,\n\t\t// \t)\n\t\t// } else {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a scalar value for field '${relation.field}' where a single entity was expected.` +\n\t\t// \t\t\t`Perhaps you meant to use a variant of <Field />?`,\n\t\t// \t)\n\t\t// }\n\t}\n\n\tprivate initializeFromHasManyRelationMarker(\n\t\tparent: EntityRealmState,\n\t\tfield: HasManyRelationMarker,\n\t\tpersistedEntityIds: Set<string>,\n\t) {\n\t\tparent.children.set(\n\t\t\tfield.placeholderName,\n\t\t\tthis.initializeEntityListState(\n\t\t\t\t{ marker: field, parent },\n\t\t\t\tthis.getRelationTargetEntityName(parent, field),\n\t\t\t\tpersistedEntityIds,\n\t\t\t),\n\t\t)\n\t\t// const relation = field.parameters\n\t\t//\n\t\t// if (fieldDatum === undefined || fieldDatum instanceof Set) {\n\t\t//\n\t\t// } else if (typeof fieldDatum === 'object') {\n\t\t// \t// Intentionally allowing `fieldDatum === null` here as well since this should only happen when a *hasOne\n\t\t// \t// relation is unlinked, e.g. a Person does not have a linked Nationality.\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a referenced entity for field '${relation.field}' where a collection of entities was expected.` +\n\t\t// \t\t\t`Perhaps you wanted to use a <HasOne />?`,\n\t\t// \t)\n\t\t// } else {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a scalar value for field '${relation.field}' where a collection of entities was expected.` +\n\t\t// \t\t\t`Perhaps you meant to use a variant of <Field />?`,\n\t\t// \t)\n\t\t// }\n\t}\n\n\tprivate getRelationTargetEntityName(\n\t\tentityRealm: EntityRealmState,\n\t\tfield: HasOneRelationMarker | HasManyRelationMarker,\n\t): EntityName {\n\t\tconst targetField = this.treeStore.schema.getEntityField(entityRealm.entity.entityName, field.parameters.field)\n\n\t\tif (targetField?.__typename !== '_Relation') {\n\t\t\tthrow new BindingError() // This should have been validated elsewhere.\n\t\t}\n\t\treturn targetField.targetEntity\n\t}\n\n\tpublic runImmediateUserInitialization(\n\t\trealm: EntityRealmState | EntityRealmStateStub,\n\t\tinitialize: EntityAccessor.BatchUpdatesHandler | undefined,\n\t) {\n\t\tif (initialize === undefined) {\n\t\t\treturn\n\t\t}\n\t\tconst entityRealm = this.materializeEntityRealm(realm)\n\n\t\trealm.getAccessor().batchUpdates(initialize)\n\n\t\tconst initializeListeners = this.eventManager.getEventListeners(entityRealm, { type: 'initialize' })\n\t\tif (initializeListeners === undefined || initializeListeners.size === 0) {\n\t\t\trealm.entity.hasIdSetInStone = true\n\t\t}\n\t}\n\n\tpublic initializeEntityEventListenerStore(blueprint: EntityRealmBlueprint): EntityEventListenerStore | undefined {\n\t\tif (blueprint.type === 'listEntity') {\n\t\t\tconst blueprintListeners = blueprint.parent.blueprint.marker.parameters.childEventListeners\n\t\t\tconst childInitialize = blueprintListeners?.get({ type: 'initialize' })\n\t\t\tconst store: EntityEventListenerStore = new EventListenersStore(() => blueprint.parent.childEventListeners)\n\n\t\t\tif (childInitialize !== undefined) {\n\t\t\t\tstore.set({ type: 'initialize' }, childInitialize)\n\t\t\t}\n\t\t\treturn store\n\t\t}\n\n\t\tconst blueprintListeners = blueprint.marker.parameters.eventListeners\n\t\tif (blueprintListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn TreeParameterMerger.cloneSingleEntityEventListeners(blueprintListeners)\n\t}\n\n\tprivate initializeEntityListEventListenerStore(\n\t\tblueprint: EntityListBlueprint,\n\t): EntityListEventListenerStore | undefined {\n\t\tconst blueprintListeners = blueprint.marker.parameters.eventListeners\n\n\t\tif (blueprintListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn TreeParameterMerger.cloneEntityListEventListeners(blueprintListeners)\n\t}\n\n\tprivate initializeEntityListChildEventListenerStore(\n\t\tblueprint: EntityListBlueprint,\n\t): EntityEventListenerStore | undefined {\n\t\tconst blueprintListeners = blueprint.marker.parameters.childEventListeners\n\n\t\tif (blueprintListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn TreeParameterMerger.cloneSingleEntityEventListeners(blueprintListeners)\n\t}\n\n\tprivate initializeFieldEventListenerStore(marker: FieldMarker): FieldEventListenerStore | undefined {\n\t\t// TODO !!!\n\t\treturn undefined\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;uBAwC8B;AAAA,EAKtB,YACW,sBACA,qBACA,QACA,cACA,WAChB;AALgB;AACA;AACA;AACA;AACA;AAEjB,SAAK,kBAAkB,IAAI,gBAAgB,KAAK,sBAAsB,KAAK,cAAc,MAAM,KAAK;AACpG,SAAK,mBAAmB,IAAI,iBAC3B,KAAK,sBACL,KAAK,qBACL,KAAK,cACL,MACA,KAAK;AAEN,SAAK,iBAAiB,IA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AAO,oBAAoB,8BAA8B;AAAA;AAAA,EAGlD,4CACP,WACuC;AACvC,UAAM,qBAAqB,UAAU,OAAO,WAAW;AAEvD,QAAI,uBAAuB,QAAW;AACrC,aAAO;AAAA;AAER,WAAO,oBAAoB,gCAAgC;AAAA;AAAA,EAGpD,kCAAkC,QAA0D;AAEnG,WAAO;AAAA;AAAA;;;;"}
|
|
@@ -15,7 +15,7 @@ class TreeAugmenter {
|
|
|
15
15
|
this.treeStore.mergeInQueryResponse(newPersistedData);
|
|
16
16
|
}
|
|
17
17
|
extendTreeStates(newTreeId, newMarkerTree) {
|
|
18
|
-
const subTreeStates = new Map();
|
|
18
|
+
const subTreeStates = /* @__PURE__ */ new Map();
|
|
19
19
|
this.treeStore.markerTrees.set(newTreeId, newMarkerTree);
|
|
20
20
|
this.treeStore.subTreeStatesByRoot.set(newTreeId, subTreeStates);
|
|
21
21
|
for (const [placeholderName, newSubTreeMarker] of newMarkerTree.subTrees) {
|
|
@@ -142,7 +142,7 @@ class TreeAugmenter {
|
|
|
142
142
|
if (childData !== void 0 && !(childData instanceof Set)) {
|
|
143
143
|
throw new BindingError();
|
|
144
144
|
}
|
|
145
|
-
this.updateEntityListPersistedData(child, childData ?? new Set());
|
|
145
|
+
this.updateEntityListPersistedData(child, childData ?? /* @__PURE__ */ new Set());
|
|
146
146
|
break;
|
|
147
147
|
}
|
|
148
148
|
default: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeAugmenter.js","sources":["../../../src/core/TreeAugmenter.ts"],"sourcesContent":["import {\n\tClientGeneratedUuid,\n\tEntityListPersistedData,\n\tReceivedDataTree,\n\tRuntimeId,\n\tServerGeneratedUuid,\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'\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) {}\n\n\tpublic extendPersistedData(newPersistedData: ReceivedDataTree) {\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)\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) {\n\t\tthis.treeStore.mergeInMutationResponse(response)\n\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 ServerGeneratedUuid)) {\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: ServerGeneratedUuid | undefined | null,\n\t) {\n\t\tconst currentId = realm.entity.id\n\t\tlet idToChangeTo: RuntimeId | undefined = undefined\n\n\t\tif (currentId instanceof ServerGeneratedUuid) {\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.value) : 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 ServerGeneratedUuid || 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 ServerGeneratedUuid) && 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 ServerGeneratedUuid ||\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 ServerGeneratedUuid(drawnId),\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 ServerGeneratedUuid(childRuntimeId.value),\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 ServerGeneratedUuid(unclaimedPersistedId), 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":";;;;;;;oBAkB2B;AAAA,EACnB,YACW,cACA,kBACA,WAChB;AAHgB;AACA;AACA;AAAA;AAAA,EAGX,oBAAoB,kBAAoC;AAE9D,SAAK,UAAU,qBAAqB;AAAA;AAAA,EAG9B,iBAAiB,WAAmC,eAAqC;AAC/F,UAAM,gBAAqD,IAAI;AAE/D,SAAK,UAAU,YAAY,IAAI,WAAW;AAC1C,SAAK,UAAU,oBAAoB,IAAI,WAAW;AAElD,eAAW,CAAC,iBAAiB,qBAAqB,cAAc,UAAU;AACzE,YAAM,WAAW,KAAK,iBAAiB,kBAAkB;AACzD,oBAAc,IAAI,iBAAiB;AAAA;AAAA;AAAA,EAI9B,oBAAoB,UAA4B;AACtD,SAAK,UAAU,wBAAwB;AAEvC,SAAK,aAAa,gBAAgB,MAAM;AACvC,iBAAW,cAAc,KAAK,UAAU,oBAAoB,UAAU;AAUrE,mBAAW,CAAC,iBAAiB,cAAc,YAAY;AACtD,gBAAM,WAAW,KAAK,UAAU,qBAAqB,IAAI;AAEzD,cAAI,UAAU,SAAS,cAAc;AACpC,gBAAI,sBAAsB,MAAM;AAC/B;AAAA;AAED,iBAAK,8BAA8B,WAAW;AAAA,qBACpC,UAAU,SAAS,eAAe;AAC5C,g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AAA;AAAA;AAAA,EAMf,8BAA8B,OAAwB,iBAA0C;AACvG,UAAM,wBAAoC;AAI1C,eAAW,eAAe,iBAAiB;AAC1C,UAAI,CAAC,MAAM,SAAS,IAAI,cAAc;AACrC,8BAAsB,KAAK;AAAA;AAAA;AAG7B,eAAW,CAAC,SAAS,UAAU,MAAM,UAAU;AAC9C,YAAM,iBAAiB,MAAM,OAAO;AACpC,UAAI,CAAC,gBAAgB,IAAI,UAAU;AAClC,YAGC,0BAA0B,uBAC1B,0BAA0B,uBAE1B,sBAAsB,WAAW,GAChC;AACD,gBAAM,cAAc,iBAAiB,MAAM;AAC3C;AAAA,eACM;AACN,gBAAM,UAAU,sBAAsB;AACtC,4BAAkB,cACjB,KAAK,WACL,KAAK,cACL,KAAK,kBACL,OACA,IAAI,oBAAoB;AAAA;AAAA,iBAGhB,0BAA0B,qBAAqB;AACzD,0BAAkB,cACjB,KAAK,WACL,KAAK,cACL,KAAK,kBACL,OACA,IAAI,oBAAoB,eAAe;AAAA;AAGzC,UAAI,MAAM,SAAS,eAAe;AACjC,aAAK,+BAA+B;AAAA;AAAA;AAGtC,eAAW,wBAAwB,uBAAuB;AACzD,WAAK,iBAAiB,sBAAsB,IAAI,oBAAoB,uBAAuB,MAAM,YAAY;AAAA,QAC5G,MAAM;AAAA,QACN,QAAQ;AAAA;AAAA;AAIV,UAAM,SAAS,eAAe;AAAA;AAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"TreeAugmenter.js","sources":["../../../src/core/TreeAugmenter.ts"],"sourcesContent":["import {\n\tClientGeneratedUuid,\n\tEntityListPersistedData,\n\tReceivedDataTree,\n\tRuntimeId,\n\tServerGeneratedUuid,\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'\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) {}\n\n\tpublic extendPersistedData(newPersistedData: ReceivedDataTree) {\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)\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) {\n\t\tthis.treeStore.mergeInMutationResponse(response)\n\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 ServerGeneratedUuid)) {\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: ServerGeneratedUuid | undefined | null,\n\t) {\n\t\tconst currentId = realm.entity.id\n\t\tlet idToChangeTo: RuntimeId | undefined = undefined\n\n\t\tif (currentId instanceof ServerGeneratedUuid) {\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.value) : 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 ServerGeneratedUuid || 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 ServerGeneratedUuid) && 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 ServerGeneratedUuid ||\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 ServerGeneratedUuid(drawnId),\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 ServerGeneratedUuid(childRuntimeId.value),\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 ServerGeneratedUuid(unclaimedPersistedId), 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":";;;;;;;oBAkB2B;AAAA,EACnB,YACW,cACA,kBACA,WAChB;AAHgB;AACA;AACA;AAAA;AAAA,EAGX,oBAAoB,kBAAoC;AAE9D,SAAK,UAAU,qBAAqB;AAAA;AAAA,EAG9B,iBAAiB,WAAmC,eAAqC;AAC/F,UAAM,oCAAyD;AAE/D,SAAK,UAAU,YAAY,IAAI,WAAW;AAC1C,SAAK,UAAU,oBAAoB,IAAI,WAAW;AAElD,eAAW,CAAC,iBAAiB,qBAAqB,cAAc,UAAU;AACzE,YAAM,WAAW,KAAK,iBAAiB,kBAAkB;AACzD,oBAAc,IAAI,iBAAiB;AAAA;AAAA;AAAA,EAI9B,oBAAoB,UAA4B;AACtD,SAAK,UAAU,wBAAwB;AAEvC,SAAK,aAAa,gBAAgB,MAAM;AACvC,iBAAW,cAAc,KAAK,UAAU,oBAAoB,UAAU;AAUrE,mBAAW,CAAC,iBAAiB,cAAc,YAAY;AACtD,gBAAM,WAAW,KAAK,UAAU,qBAAqB,IAAI;AAEzD,cAAI,UAAU,SAAS,cAAc;AACpC,gBAAI,sBAAsB,MAAM;AAC/B;AAAA;AAED,iBAAK,8BAA8B,WAAW;AAAA,qBACpC,UAAU,SAAS,eAAe;AAC5C,gBAAI,aAAa,UA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AMf,8BAA8B,OAAwB,iBAA0C;AACvG,UAAM,wBAAoC;AAI1C,eAAW,eAAe,iBAAiB;AAC1C,UAAI,CAAC,MAAM,SAAS,IAAI,cAAc;AACrC,8BAAsB,KAAK;AAAA;AAAA;AAG7B,eAAW,CAAC,SAAS,UAAU,MAAM,UAAU;AAC9C,YAAM,iBAAiB,MAAM,OAAO;AACpC,UAAI,CAAC,gBAAgB,IAAI,UAAU;AAClC,YAGC,0BAA0B,uBAC1B,0BAA0B,uBAE1B,sBAAsB,WAAW,GAChC;AACD,gBAAM,cAAc,iBAAiB,MAAM;AAC3C;AAAA,eACM;AACN,gBAAM,UAAU,sBAAsB;AACtC,4BAAkB,cACjB,KAAK,WACL,KAAK,cACL,KAAK,kBACL,OACA,IAAI,oBAAoB;AAAA;AAAA,iBAGhB,0BAA0B,qBAAqB;AACzD,0BAAkB,cACjB,KAAK,WACL,KAAK,cACL,KAAK,kBACL,OACA,IAAI,oBAAoB,eAAe;AAAA;AAGzC,UAAI,MAAM,SAAS,eAAe;AACjC,aAAK,+BAA+B;AAAA;AAAA;AAGtC,eAAW,wBAAwB,uBAAuB;AACzD,WAAK,iBAAiB,sBAAsB,IAAI,oBAAoB,uBAAuB,MAAM,YAAY;AAAA,QAC5G,MAAM;AAAA,QACN,QAAQ;AAAA;AAAA;AAIV,UAAM,SAAS,eAAe;AAAA;AAAA;;;;"}
|
|
@@ -53,7 +53,7 @@ class TreeFilterGenerator {
|
|
|
53
53
|
relations: this.normalizeRawRelationFilters(relations)
|
|
54
54
|
}));
|
|
55
55
|
}
|
|
56
|
-
populateRawRelationFilters(markers, relations = new Map()) {
|
|
56
|
+
populateRawRelationFilters(markers, relations = /* @__PURE__ */ new Map()) {
|
|
57
57
|
for (const [, marker] of markers.markers) {
|
|
58
58
|
if (!(marker instanceof HasOneRelationMarker) && !(marker instanceof HasManyRelationMarker)) {
|
|
59
59
|
continue;
|
|
@@ -65,7 +65,7 @@ class TreeFilterGenerator {
|
|
|
65
65
|
}
|
|
66
66
|
let existingRelation = relations.get(marker.parameters.field);
|
|
67
67
|
if (existingRelation === void 0) {
|
|
68
|
-
relations.set(marker.parameters.field, existingRelation = new Map());
|
|
68
|
+
relations.set(marker.parameters.field, existingRelation = /* @__PURE__ */ new Map());
|
|
69
69
|
}
|
|
70
70
|
this.populateRawRelationFilters(marker.fields, existingRelation);
|
|
71
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeFilterGenerator.js","sources":["../../../src/core/TreeFilterGenerator.ts"],"sourcesContent":["import type { RelationFilter, TreeFilter } from '@contember/client'\nimport { EntityListPersistedData, ServerGeneratedUuid } from '../accessorTree'\nimport {\n\tEntityFieldMarkersContainer,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n} from '../markers'\nimport type { EntityName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport { StateIterator } from './state'\nimport type { TreeStore } from './TreeStore'\n\ntype RawRelationFilters = Map<string, RawRelationFilters>\n\nexport class TreeFilterGenerator {\n\tpublic constructor(private readonly treeStore: TreeStore) {}\n\n\tpublic generateTreeFilter(): TreeFilter[] {\n\t\tconst filters: TreeFilter[][] = []\n\n\t\tfor (const [placeholderName, state] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\tconst blueprint = state.blueprint\n\n\t\t\tif (blueprint.parent || blueprint.marker.parameters.expectedMutation === 'none') {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst marker = blueprint.marker\n\t\t\tfilters.push(this.generateSubTreeFilter(marker, this.treeStore.subTreePersistedData.get(placeholderName)))\n\t\t}\n\t\treturn filters.flat()\n\t}\n\n\tprivate generateSubTreeFilter(\n\t\tsubTree: EntitySubTreeMarker | EntityListSubTreeMarker,\n\t\tpersistedData: ServerGeneratedUuid | EntityListPersistedData | undefined,\n\t): TreeFilter[] {\n\t\tconst filters: TreeFilter[] = []\n\n\t\tif (persistedData === undefined) {\n\t\t\treturn filters // Do nothing\n\t\t}\n\n\t\tif (persistedData instanceof ServerGeneratedUuid) {\n\t\t\tconst filter = this.generateTopLevelEntityFilter(\n\t\t\t\tpersistedData.value,\n\t\t\t\tsubTree.parameters.entityName,\n\t\t\t\tsubTree.fields,\n\t\t\t)\n\t\t\tfilter && filters.push(filter)\n\t\t} else {\n\t\t\tfor (const id of persistedData) {\n\t\t\t\tconst filter = this.generateTopLevelEntityFilter(id, subTree.parameters.entityName, subTree.fields)\n\t\t\t\tfilter && filters.push(filter)\n\t\t\t}\n\t\t}\n\n\t\treturn filters\n\t}\n\n\tprivate generateTopLevelEntityFilter(\n\t\tid: string,\n\t\tentityName: EntityName,\n\t\tfields: EntityFieldMarkersContainer,\n\t): TreeFilter | undefined {\n\t\treturn {\n\t\t\tentity: entityName,\n\t\t\tid: id,\n\t\t\trelations: this.generateEntityRelations(fields),\n\t\t}\n\t}\n\n\tprivate generateEntityRelations(markers: EntityFieldMarkersContainer): RelationFilter[] {\n\t\tconst rawFilter = this.populateRawRelationFilters(markers)\n\t\treturn this.normalizeRawRelationFilters(rawFilter)\n\t}\n\n\tprivate normalizeRawRelationFilters(raw: RawRelationFilters): RelationFilter[] {\n\t\treturn Array.from(raw, ([fieldName, relations]) => ({\n\t\t\tname: fieldName,\n\t\t\trelations: this.normalizeRawRelationFilters(relations),\n\t\t}))\n\t}\n\n\tprivate populateRawRelationFilters(\n\t\tmarkers: EntityFieldMarkersContainer,\n\t\trelations: RawRelationFilters = new Map(),\n\t): RawRelationFilters {\n\t\tfor (const [, marker] of markers.markers) {\n\t\t\tif (!(marker instanceof HasOneRelationMarker) && !(marker instanceof HasManyRelationMarker)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (\n\t\t\t\tmarker.parameters.expectedMutation === 'none' ||\n\t\t\t\tmarker.parameters.expectedMutation === 'connectOrDisconnect'\n\t\t\t) {\n\t\t\t\tcontinue\n\t\t\t} else if (\n\t\t\t\tmarker.parameters.expectedMutation === 'anyMutation' ||\n\t\t\t\tmarker.parameters.expectedMutation === 'createOrDelete'\n\t\t\t) {\n\t\t\t} else {\n\t\t\t\treturn assertNever(marker.parameters.expectedMutation)\n\t\t\t}\n\t\t\tlet existingRelation = relations.get(marker.parameters.field)\n\n\t\t\tif (existingRelation === undefined) {\n\t\t\t\trelations.set(marker.parameters.field, (existingRelation = new Map()))\n\t\t\t}\n\t\t\tthis.populateRawRelationFilters(marker.fields, existingRelation)\n\t\t}\n\n\t\treturn relations\n\t}\n}\n"],"names":[],"mappings":";;;;;;0BAgBiC;AAAA,EACzB,YAA6B,WAAsB;AAAtB;AAAA;AAAA,EAE7B,qBAAmC;AACzC,UAAM,UAA0B;AAEhC,eAAW,CAAC,iBAAiB,UAAU,cAAc,cAAc,KAAK,YAAY;AACnF,YAAM,YAAY,MAAM;AAExB,UAAI,UAAU,UAAU,UAAU,OAAO,WAAW,qBAAqB,QAAQ;AAChF;AAAA;AAED,YAAM,SAAS,UAAU;AACzB,cAAQ,KAAK,KAAK,sBAAsB,QAAQ,KAAK,UAAU,qBAAqB,IAAI;AAAA;AAEzF,WAAO,QAAQ;AAAA;AAAA,EAGR,sBACP,SACA,eACe;AACf,UAAM,UAAwB;AAE9B,QAAI,kBAAkB,QAAW;AAChC,aAAO;AAAA;AAGR,QAAI,yBAAyB,qBAAqB;AACjD,YAAM,SAAS,KAAK,6BACnB,cAAc,OACd,QAAQ,WAAW,YACnB,QAAQ;AAET,gBAAU,QAAQ,KAAK;AAAA,WACjB;AACN,iBAAW,MAAM,eAAe;AAC/B,cAAM,SAAS,KAAK,6BAA6B,IAAI,QAAQ,WAAW,YAAY,QAAQ;AAC5F,kBAAU,QAAQ,KAAK;AAAA;AAAA;AAIzB,WAAO;AAAA;AAAA,EAGA,6BACP,IACA,YACA,QACyB;AACzB,WAAO;AAAA,MACN,QAAQ;AAAA,MACR;AAAA,MACA,WAAW,KAAK,wBAAwB;AAAA;AAAA;AAAA,EAIlC,wBAAwB,SAAwD;AACvF,UAAM,YAAY,KAAK,2BAA2B;AAClD,WAAO,KAAK,4BAA4B;AAAA;AAAA,EAGjC,4BAA4B,KAA2C;AAC9E,WAAO,MAAM,KAAK,KAAK,CAAC,CAAC,WAAW;AAAgB,MACnD,MAAM;AAAA,MACN,WAAW,KAAK,4BAA4B;AAAA;AAAA;AAAA,EAItC,2BACP,SACA,
|
|
1
|
+
{"version":3,"file":"TreeFilterGenerator.js","sources":["../../../src/core/TreeFilterGenerator.ts"],"sourcesContent":["import type { RelationFilter, TreeFilter } from '@contember/client'\nimport { EntityListPersistedData, ServerGeneratedUuid } from '../accessorTree'\nimport {\n\tEntityFieldMarkersContainer,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n} from '../markers'\nimport type { EntityName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport { StateIterator } from './state'\nimport type { TreeStore } from './TreeStore'\n\ntype RawRelationFilters = Map<string, RawRelationFilters>\n\nexport class TreeFilterGenerator {\n\tpublic constructor(private readonly treeStore: TreeStore) {}\n\n\tpublic generateTreeFilter(): TreeFilter[] {\n\t\tconst filters: TreeFilter[][] = []\n\n\t\tfor (const [placeholderName, state] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\tconst blueprint = state.blueprint\n\n\t\t\tif (blueprint.parent || blueprint.marker.parameters.expectedMutation === 'none') {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst marker = blueprint.marker\n\t\t\tfilters.push(this.generateSubTreeFilter(marker, this.treeStore.subTreePersistedData.get(placeholderName)))\n\t\t}\n\t\treturn filters.flat()\n\t}\n\n\tprivate generateSubTreeFilter(\n\t\tsubTree: EntitySubTreeMarker | EntityListSubTreeMarker,\n\t\tpersistedData: ServerGeneratedUuid | EntityListPersistedData | undefined,\n\t): TreeFilter[] {\n\t\tconst filters: TreeFilter[] = []\n\n\t\tif (persistedData === undefined) {\n\t\t\treturn filters // Do nothing\n\t\t}\n\n\t\tif (persistedData instanceof ServerGeneratedUuid) {\n\t\t\tconst filter = this.generateTopLevelEntityFilter(\n\t\t\t\tpersistedData.value,\n\t\t\t\tsubTree.parameters.entityName,\n\t\t\t\tsubTree.fields,\n\t\t\t)\n\t\t\tfilter && filters.push(filter)\n\t\t} else {\n\t\t\tfor (const id of persistedData) {\n\t\t\t\tconst filter = this.generateTopLevelEntityFilter(id, subTree.parameters.entityName, subTree.fields)\n\t\t\t\tfilter && filters.push(filter)\n\t\t\t}\n\t\t}\n\n\t\treturn filters\n\t}\n\n\tprivate generateTopLevelEntityFilter(\n\t\tid: string,\n\t\tentityName: EntityName,\n\t\tfields: EntityFieldMarkersContainer,\n\t): TreeFilter | undefined {\n\t\treturn {\n\t\t\tentity: entityName,\n\t\t\tid: id,\n\t\t\trelations: this.generateEntityRelations(fields),\n\t\t}\n\t}\n\n\tprivate generateEntityRelations(markers: EntityFieldMarkersContainer): RelationFilter[] {\n\t\tconst rawFilter = this.populateRawRelationFilters(markers)\n\t\treturn this.normalizeRawRelationFilters(rawFilter)\n\t}\n\n\tprivate normalizeRawRelationFilters(raw: RawRelationFilters): RelationFilter[] {\n\t\treturn Array.from(raw, ([fieldName, relations]) => ({\n\t\t\tname: fieldName,\n\t\t\trelations: this.normalizeRawRelationFilters(relations),\n\t\t}))\n\t}\n\n\tprivate populateRawRelationFilters(\n\t\tmarkers: EntityFieldMarkersContainer,\n\t\trelations: RawRelationFilters = new Map(),\n\t): RawRelationFilters {\n\t\tfor (const [, marker] of markers.markers) {\n\t\t\tif (!(marker instanceof HasOneRelationMarker) && !(marker instanceof HasManyRelationMarker)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (\n\t\t\t\tmarker.parameters.expectedMutation === 'none' ||\n\t\t\t\tmarker.parameters.expectedMutation === 'connectOrDisconnect'\n\t\t\t) {\n\t\t\t\tcontinue\n\t\t\t} else if (\n\t\t\t\tmarker.parameters.expectedMutation === 'anyMutation' ||\n\t\t\t\tmarker.parameters.expectedMutation === 'createOrDelete'\n\t\t\t) {\n\t\t\t} else {\n\t\t\t\treturn assertNever(marker.parameters.expectedMutation)\n\t\t\t}\n\t\t\tlet existingRelation = relations.get(marker.parameters.field)\n\n\t\t\tif (existingRelation === undefined) {\n\t\t\t\trelations.set(marker.parameters.field, (existingRelation = new Map()))\n\t\t\t}\n\t\t\tthis.populateRawRelationFilters(marker.fields, existingRelation)\n\t\t}\n\n\t\treturn relations\n\t}\n}\n"],"names":[],"mappings":";;;;;;0BAgBiC;AAAA,EACzB,YAA6B,WAAsB;AAAtB;AAAA;AAAA,EAE7B,qBAAmC;AACzC,UAAM,UAA0B;AAEhC,eAAW,CAAC,iBAAiB,UAAU,cAAc,cAAc,KAAK,YAAY;AACnF,YAAM,YAAY,MAAM;AAExB,UAAI,UAAU,UAAU,UAAU,OAAO,WAAW,qBAAqB,QAAQ;AAChF;AAAA;AAED,YAAM,SAAS,UAAU;AACzB,cAAQ,KAAK,KAAK,sBAAsB,QAAQ,KAAK,UAAU,qBAAqB,IAAI;AAAA;AAEzF,WAAO,QAAQ;AAAA;AAAA,EAGR,sBACP,SACA,eACe;AACf,UAAM,UAAwB;AAE9B,QAAI,kBAAkB,QAAW;AAChC,aAAO;AAAA;AAGR,QAAI,yBAAyB,qBAAqB;AACjD,YAAM,SAAS,KAAK,6BACnB,cAAc,OACd,QAAQ,WAAW,YACnB,QAAQ;AAET,gBAAU,QAAQ,KAAK;AAAA,WACjB;AACN,iBAAW,MAAM,eAAe;AAC/B,cAAM,SAAS,KAAK,6BAA6B,IAAI,QAAQ,WAAW,YAAY,QAAQ;AAC5F,kBAAU,QAAQ,KAAK;AAAA;AAAA;AAIzB,WAAO;AAAA;AAAA,EAGA,6BACP,IACA,YACA,QACyB;AACzB,WAAO;AAAA,MACN,QAAQ;AAAA,MACR;AAAA,MACA,WAAW,KAAK,wBAAwB;AAAA;AAAA;AAAA,EAIlC,wBAAwB,SAAwD;AACvF,UAAM,YAAY,KAAK,2BAA2B;AAClD,WAAO,KAAK,4BAA4B;AAAA;AAAA,EAGjC,4BAA4B,KAA2C;AAC9E,WAAO,MAAM,KAAK,KAAK,CAAC,CAAC,WAAW;AAAgB,MACnD,MAAM;AAAA,MACN,WAAW,KAAK,4BAA4B;AAAA;AAAA;AAAA,EAItC,2BACP,SACA,gCAAoC,OACf;AACrB,eAAW,GAAG,WAAW,QAAQ,SAAS;AACzC,UAAI,oBAAoB,yBAAyB,oBAAoB,wBAAwB;AAC5F;AAAA;AAED,UACC,OAAO,WAAW,qBAAqB,UACvC,OAAO,WAAW,qBAAqB,uBACtC;AACD;AAAA,iBAEA,OAAO,WAAW,qBAAqB,iBACvC,OAAO,WAAW,qBAAqB,kBACtC,OACK;AACN,eAAO,YAAY,OAAO,WAAW;AAAA;AAEtC,UAAI,mBAAmB,UAAU,IAAI,OAAO,WAAW;AAEvD,UAAI,qBAAqB,QAAW;AACnC,kBAAU,IAAI,OAAO,WAAW,OAAQ,uCAAuB;AAAA;AAEhE,WAAK,2BAA2B,OAAO,QAAQ;AAAA;AAGhD,WAAO;AAAA;AAAA;;;;"}
|
|
@@ -6,14 +6,14 @@ import { assertNever } from '../utils/assertNever.js';
|
|
|
6
6
|
import { PlaceholderGenerator } from '../markers/PlaceholderGenerator.js';
|
|
7
7
|
import { QueryLanguage } from '../queryLanguage/QueryLanguage.js';
|
|
8
8
|
|
|
9
|
-
const emptyEntityIdSet = new Set();
|
|
9
|
+
const emptyEntityIdSet = /* @__PURE__ */ new Set();
|
|
10
10
|
class TreeStore {
|
|
11
|
-
entityStore = new Map();
|
|
12
|
-
entityRealmStore = new Map();
|
|
13
|
-
markerTrees = new Map();
|
|
14
|
-
subTreeStatesByRoot = new Map();
|
|
11
|
+
entityStore = /* @__PURE__ */ new Map();
|
|
12
|
+
entityRealmStore = /* @__PURE__ */ new Map();
|
|
13
|
+
markerTrees = /* @__PURE__ */ new Map();
|
|
14
|
+
subTreeStatesByRoot = /* @__PURE__ */ new Map();
|
|
15
15
|
_schema;
|
|
16
|
-
persistedData = new NormalizedPersistedData(new Map(), new Map());
|
|
16
|
+
persistedData = new NormalizedPersistedData(/* @__PURE__ */ new Map(), /* @__PURE__ */ new Map());
|
|
17
17
|
constructor() {
|
|
18
18
|
}
|
|
19
19
|
mergeInQueryResponse(response) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeStore.js","sources":["../../../src/core/TreeStore.ts"],"sourcesContent":["import { NormalizedPersistedData, PersistedEntityDataStore, ReceivedDataTree, SubTreeDataStore } 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'\n\nconst emptyEntityIdSet: ReadonlySet<EntityId> = new Set()\n\nexport class TreeStore {\n\tpublic readonly entityStore: Map<EntityId, 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\tprivate _schema: Schema | undefined\n\tpublic readonly persistedData: NormalizedPersistedData = new NormalizedPersistedData(new Map(), new Map())\n\n\tpublic constructor() {}\n\n\tpublic mergeInQueryResponse(response: ReceivedDataTree): void {\n\t\tRequestResponseNormalizer.mergeInQueryResponse(this.persistedData, response)\n\t}\n\n\tpublic mergeInMutationResponse(response: ReceivedDataTree): void {\n\t\tRequestResponseNormalizer.mergeInMutationResponse(this.persistedData, response)\n\t}\n\n\tpublic setSchema(newSchema: Schema): void {\n\t\t// TODO\n\t\tif (this._schema === undefined) {\n\t\t\tthis._schema = newSchema\n\t\t}\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\tif (this._schema === undefined) {\n\t\t\tthrow new BindingError(`Fatal error: failed to load api schema.`)\n\t\t}\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.getEntityField(parentEntityName, relationFromParent)\n\n\t\tif (relationSchema?.__typename !== '_Relation') {\n\t\t\tthrow new BindingError()\n\t\t}\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)\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)\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<string> {\n\t\tconst blueprint = state.blueprint\n\n\t\tif (blueprint.parent) {\n\t\t\tconst entityData = this.persistedEntityData.get(blueprint.parent.entity.id.value)\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.value)\n\t\tthis.persistedEntityData.delete(entity.id.value)\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":";;;;;;;;AAwBA,MAAM,mBAA0C,IAAI;gBAE7B;AAAA,EACN,cAA0C,IAAI;AAAA,EAC9C,mBAAiF,IAAI;AAAA,EAIrF,cAA2D,IAAI;AAAA,EAC/D,sBAAwF,IAAI;AAAA,EAEpG;AAAA,EACQ,gBAAyC,IAAI,wBAAwB,IAAI,OAAO,IAAI;AAAA,EAE7F,cAAc;AAAA;AAAA,EAEd,qBAAqB,UAAkC;AAC7D,8BAA0B,qBAAqB,KAAK,eAAe;AAAA;AAAA,EAG7D,wBAAwB,UAAkC;AAChE,8BAA0B,wBAAwB,KAAK,eAAe;AAAA;AAAA,EAGhE,UAAU,WAAyB;AAEzC,QAAI,KAAK,YAAY,QAAW;AAC/B,WAAK,UAAU;AAAA;AAAA;AAAA,MAIN,sBAAgD;AAC1D,WAAO,KAAK,cAAc;AAAA;AAAA,MAGhB,uBAAyC;AACnD,WAAO,KAAK,cAAc;AAAA;AAAA,MAGhB,SAAiB;AAC3B,QAAI,KAAK,YAAY,QAAW;AAC/B,YAAM,IAAI,aAAa;AAAA;AAExB,WAAO,KAAK;AAAA;AAAA,EAGN,oBAAoB,aAKd;AACZ,UAAM,YAAY,YAAY;AAC9B,QAAI,UAAU,WAAW,QAAW;AACnC,aAAO;AAAA;AAER,QAAI;AACJ,QAAI;AACJ,QAAI;AAEJ,QAAI,UAAU,SAAS,UAAU;AAChC,yBA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Y,UAAU;AAC7C,qBAAW,yBAAyB,KAAK,SAAS,UAAU;AAC3D,kBAAM,WAAW,iBAAiB,kBAAkB,kBAAkB;AACtE,gBAAI,UAAU;AACb;AAAA;AAAA;AAAA;AAIH,eAAO;AAAA;AAER,WAAO;AAAA;AAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"TreeStore.js","sources":["../../../src/core/TreeStore.ts"],"sourcesContent":["import { NormalizedPersistedData, PersistedEntityDataStore, ReceivedDataTree, SubTreeDataStore } 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'\n\nconst emptyEntityIdSet: ReadonlySet<EntityId> = new Set()\n\nexport class TreeStore {\n\tpublic readonly entityStore: Map<EntityId, 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\tprivate _schema: Schema | undefined\n\tpublic readonly persistedData: NormalizedPersistedData = new NormalizedPersistedData(new Map(), new Map())\n\n\tpublic constructor() {}\n\n\tpublic mergeInQueryResponse(response: ReceivedDataTree): void {\n\t\tRequestResponseNormalizer.mergeInQueryResponse(this.persistedData, response)\n\t}\n\n\tpublic mergeInMutationResponse(response: ReceivedDataTree): void {\n\t\tRequestResponseNormalizer.mergeInMutationResponse(this.persistedData, response)\n\t}\n\n\tpublic setSchema(newSchema: Schema): void {\n\t\t// TODO\n\t\tif (this._schema === undefined) {\n\t\t\tthis._schema = newSchema\n\t\t}\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\tif (this._schema === undefined) {\n\t\t\tthrow new BindingError(`Fatal error: failed to load api schema.`)\n\t\t}\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.getEntityField(parentEntityName, relationFromParent)\n\n\t\tif (relationSchema?.__typename !== '_Relation') {\n\t\t\tthrow new BindingError()\n\t\t}\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)\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)\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<string> {\n\t\tconst blueprint = state.blueprint\n\n\t\tif (blueprint.parent) {\n\t\t\tconst entityData = this.persistedEntityData.get(blueprint.parent.entity.id.value)\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.value)\n\t\tthis.persistedEntityData.delete(entity.id.value)\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":";;;;;;;;AAwBA,MAAM,uCAA8C;gBAE7B;AAAA,EACN,kCAA8C;AAAA,EAC9C,uCAAqF;AAAA,EAIrF,kCAA+D;AAAA,EAC/D,0CAA4F;AAAA,EAEpG;AAAA,EACQ,gBAAyC,IAAI,4CAA4B,2BAAW;AAAA,EAE7F,cAAc;AAAA;AAAA,EAEd,qBAAqB,UAAkC;AAC7D,8BAA0B,qBAAqB,KAAK,eAAe;AAAA;AAAA,EAG7D,wBAAwB,UAAkC;AAChE,8BAA0B,wBAAwB,KAAK,eAAe;AAAA;AAAA,EAGhE,UAAU,WAAyB;AAEzC,QAAI,KAAK,YAAY,QAAW;AAC/B,WAAK,UAAU;AAAA;AAAA;AAAA,MAIN,sBAAgD;AAC1D,WAAO,KAAK,cAAc;AAAA;AAAA,MAGhB,uBAAyC;AACnD,WAAO,KAAK,cAAc;AAAA;AAAA,MAGhB,SAAiB;AAC3B,QAAI,KAAK,YAAY,QAAW;AAC/B,YAAM,IAAI,aAAa;AAAA;AAExB,WAAO,KAAK;AAAA;AAAA,EAGN,oBAAoB,aAKd;AACZ,UAAM,YAAY,YAAY;AAC9B,QAAI,UAAU,WAAW,QAAW;AACnC,aAAO;AAAA;AAER,QAAI;AACJ,QAAI;AACJ,QAAI;AAEJ,QAAI,UAAU,SAAS,UAAU;AAChC,yBAAmB,UAAU,OAAO,OAAO;AAC3C,2BAAqB,UA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S,UAAU;AAC3D,kBAAM,WAAW,iBAAiB,kBAAkB,kBAAkB;AACtE,gBAAI,UAAU;AACb;AAAA;AAAA;AAAA;AAIH,eAAO;AAAA;AAER,WAAO;AAAA;AAAA;;;;"}
|
|
@@ -147,7 +147,7 @@ ${error.message}
|
|
|
147
147
|
parent.children.delete(entityId.value);
|
|
148
148
|
if (entityId.existsOnServer) {
|
|
149
149
|
if (parent.plannedRemovals === void 0) {
|
|
150
|
-
parent.plannedRemovals = new Map();
|
|
150
|
+
parent.plannedRemovals = /* @__PURE__ */ new Map();
|
|
151
151
|
}
|
|
152
152
|
changesDelta++;
|
|
153
153
|
parent.plannedRemovals.set(entityId.value, "delete");
|
|
@@ -157,7 +157,7 @@ ${error.message}
|
|
|
157
157
|
const placeholderName = realmToDelete.blueprint.marker.placeholderName;
|
|
158
158
|
if (entityId.existsOnServer) {
|
|
159
159
|
if (parent.plannedHasOneDeletions === void 0) {
|
|
160
|
-
parent.plannedHasOneDeletions = new Map();
|
|
160
|
+
parent.plannedHasOneDeletions = /* @__PURE__ */ new Map();
|
|
161
161
|
}
|
|
162
162
|
changesDelta++;
|
|
163
163
|
parent.plannedHasOneDeletions.set(placeholderName, realmToDelete);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityOperations.js","sources":["../../../../src/core/operations/EntityOperations.ts"],"sourcesContent":["import type { BatchUpdatesOptions, EntityAccessor, ErrorAccessor } from '../../accessors'\nimport { ServerGeneratedUuid, 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.value)\n\n\t\t\tconst entityName = outerState.entity.entityName\n\t\t\tconst fieldSchema = this.treeStore.schema.getEntityField(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 ServerGeneratedUuid) {\n\t\t\t\t\t\tif (persistedId.value === stateToConnect.entity.id.value) {\n\t\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\t} else if (persistedId.value === previouslyConnectedState.entity.id.value) {\n\t\t\t\t\t\t\tchangesDelta++ // We're changing it from the persisted id.\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (!previouslyConnectedState.entity.id.existsOnServer) {\n\t\t\t\t\t\t// This assumes the invariant enforced above that we cannot connect unpersisted entities.\n\t\t\t\t\t\t// Hence the previouslyConnectedState still refers to the entity created initially.\n\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\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)\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.value)\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 ServerGeneratedUuid) {\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":";;;;;;;;;;;;uBAgB8B;AAAA,EACtB,YACW,sBACA,qBACA,cACA,kBACA,WAChB;AALgB;AACA;AACA;AACA;AACA;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AO,gBAAgB,IAAI,SAAS,OAAO;AAAA;AAAA,mBAElC,cAAc,UAAU,SAAS,UAAU;AACrD,mBAAS,cAAc,UAAU;AACjC,gBAAM,kBAAkB,cAAc,UAAU,OAAO;AAEvD,cAAI,SAAS,gBAAgB;AAC5B,gBAAI,OAAO,2BAA2B,QAAW;AAChD,qBAAO,yBAAyB,IAAI;AAAA;AAErC;AACA,mBAAO,uBAAuB,IAAI,iBAAiB;AAAA;AAEpD,eAAK,iBAAiB,sBACrB,IAAI,4BACJ,WAAW,YACX,cAAc;AAGf,eAAK,aAAa,0BAA0B,QAAQ;AAAA,mBAC1C,cAAc,UAAU,SAAS,WAAW;AACtD,gBAAM,IAAI,aAAa;AAAA,eACjB;AACN,iBAAO,YAAY,cAAc;AAAA;AAGlC,YAAI,cAAc,SAAS,eAAe;AAEzC,0BAAgB,cAAc;AAAA;AAE/B,aAAK,aAAa,oBAAoB,QAAQ;AAE9C,YAAI,cAAc,SAAS,eAAe;AACzC,iBAAO,4BAA4B,OAAO;AAAA;AAG3C,aAAK,UAAU,eAAe;AAAA;AAAA;AAAA;AAAA,GAKxB,6BACR,WACA,OACA,SACyC;AACzC,UAAM,eAAe,UAAU,aAAa,IAAI;AAEhD,QAAI,iBAAiB,QAAW;AAC/B;AAAA;AAED,UAAM,yBAAyB,wBAAwB,MAAM,eAAe,CAAC;AAE7E,eAAW,mBAAmB,wBAAwB;AACrD,YAAM,iBAAiB,UAAU,QAAQ,IAAI;AAE7C,UAAI,4BAA4B,uBAAuB;AACtD,cAAM,IAAI,aAAa;AAAA;AAExB,YAAM;AAAA;AAAA;AAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"EntityOperations.js","sources":["../../../../src/core/operations/EntityOperations.ts"],"sourcesContent":["import type { BatchUpdatesOptions, EntityAccessor, ErrorAccessor } from '../../accessors'\nimport { ServerGeneratedUuid, 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.value)\n\n\t\t\tconst entityName = outerState.entity.entityName\n\t\t\tconst fieldSchema = this.treeStore.schema.getEntityField(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 ServerGeneratedUuid) {\n\t\t\t\t\t\tif (persistedId.value === stateToConnect.entity.id.value) {\n\t\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\t} else if (persistedId.value === previouslyConnectedState.entity.id.value) {\n\t\t\t\t\t\t\tchangesDelta++ // We're changing it from the persisted id.\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (!previouslyConnectedState.entity.id.existsOnServer) {\n\t\t\t\t\t\t// This assumes the invariant enforced above that we cannot connect unpersisted entities.\n\t\t\t\t\t\t// Hence the previouslyConnectedState still refers to the entity created initially.\n\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\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)\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.value)\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 ServerGeneratedUuid) {\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":";;;;;;;;;;;;uBAgB8B;AAAA,EACtB,YACW,sBACA,qBACA,cACA,kBACA,WAChB;AALgB;AACA;AACA;AACA;AACA;AAAA;AAAA,EAGX,SAAS,aAA+B,OAAwC;AACtF,WAAO,KAAK,qBAAqB,SAAS,aAAa;AAAA;AAAA,EAGjD,iBACN,OACA,OACA,UACC;AACD,QAAI,MAAM,mBAAmB,QAAW;AACvC,YAAM,iBAAiB,IAAI;AAAA;AAE5B,WAAO,MAAM,eAAe,IAAI,OAAO;AAAA;AAAA,EAGjC,aAAa,OAAyB,gBAAoD;AAChG,SAAK,aAAa,cAAc,MAAM;AACrC,qBAAe,MAAM,aAAa,KAAK;AAAA;AAAA;AAAA,EAIlC,qBAAqB,YAA8B,WAAsB,iBAAiC;AAChH,SAAK,aAAa,cAAc,MAAM;AACrC,YAAM,iBAAiB,kBAAkB,iCAAiC,KAAK,WAAW;AAC1F,YAAM,kBAAkB,gBAAgB,gBAAgB;AACxD,YAAM,gBAAgB,KAAK,UAAU,oBAAoB,IAAI,WAAW,OAAO,GAAG;AAElF,YAAM,aAAa,WAAW,OAAO;AACrC,YAAM,cAAc,KAAK,UAAU,OAAO,eAAe,YAAY;AAErE,UAAI,gBAAgB,QAAW;AAC9B,cAAM,IAAI,aACT,sDAAsD,cAAc;AAAA;AAAA,qBAC7C,aAAa,oBAAoB;AAAA,iBAE/C,YAAY,eAAe,WAAW;AAChD,cAAM,IAAI,aACT,gEAAgE,cAAc;AAAA;AAAA,qBAEvD,aAAa,oBAAoB;AAAA;AAI1D,iBAAW,SAAS,cAAc,iBAAiB,aAAa;AAC/D,cAAM,sBAAsB,KAAK,6BAChC,gBAAgB,OAAO,QACvB,WACA,4BAA4B;AAE7B,mBAAW,sBAAsB,qBAAqB;AACrD,g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