@contember/binding 1.0.0-rc.9 → 1.0.0
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/BindingError.js +0 -1
- package/dist/development/BindingError.js.map +1 -1
- package/dist/development/accessorPropagation/AccessorProvider.js +3 -5
- package/dist/development/accessorPropagation/AccessorProvider.js.map +1 -1
- package/dist/development/accessorPropagation/BindingOperationsContext.js +2 -4
- package/dist/development/accessorPropagation/BindingOperationsContext.js.map +1 -1
- package/dist/development/accessorPropagation/BindingOperationsProvider.js +2 -4
- package/dist/development/accessorPropagation/BindingOperationsProvider.js.map +1 -1
- package/dist/development/accessorPropagation/EntityKeyContext.js +1 -3
- package/dist/development/accessorPropagation/EntityKeyContext.js.map +1 -1
- package/dist/development/accessorPropagation/EntityKeyProvider.js +2 -4
- package/dist/development/accessorPropagation/EntityKeyProvider.js.map +1 -1
- package/dist/development/accessorPropagation/EnvironmentContext.js +2 -4
- package/dist/development/accessorPropagation/EnvironmentContext.js.map +1 -1
- package/dist/development/accessorPropagation/TreeRootIdContext.js +1 -3
- package/dist/development/accessorPropagation/TreeRootIdContext.js.map +1 -1
- package/dist/development/accessorPropagation/TreeRootIdProvider.js +2 -4
- package/dist/development/accessorPropagation/TreeRootIdProvider.js.map +1 -1
- package/dist/development/accessorPropagation/useAccessorUpdateSubscription.js +2 -4
- package/dist/development/accessorPropagation/useAccessorUpdateSubscription.js.map +1 -1
- package/dist/development/accessorPropagation/useBindingOperations.js +2 -4
- package/dist/development/accessorPropagation/useBindingOperations.js.map +1 -1
- package/dist/development/accessorPropagation/useDesugaredRelativeEntityList.js +3 -5
- package/dist/development/accessorPropagation/useDesugaredRelativeEntityList.js.map +1 -1
- package/dist/development/accessorPropagation/useDesugaredRelativeSingleEntity.js +3 -5
- package/dist/development/accessorPropagation/useDesugaredRelativeSingleEntity.js.map +1 -1
- package/dist/development/accessorPropagation/useDesugaredRelativeSingleField.js +3 -5
- package/dist/development/accessorPropagation/useDesugaredRelativeSingleField.js.map +1 -1
- package/dist/development/accessorPropagation/useEntity.js +7 -9
- package/dist/development/accessorPropagation/useEntity.js.map +1 -1
- package/dist/development/accessorPropagation/useEntityKey.js +3 -5
- package/dist/development/accessorPropagation/useEntityKey.js.map +1 -1
- package/dist/development/accessorPropagation/useEntityList.js +7 -9
- package/dist/development/accessorPropagation/useEntityList.js.map +1 -1
- package/dist/development/accessorPropagation/useEntityListSubTree.js +4 -6
- package/dist/development/accessorPropagation/useEntityListSubTree.js.map +1 -1
- package/dist/development/accessorPropagation/useEntityListSubTreeParameters.js +2 -4
- package/dist/development/accessorPropagation/useEntityListSubTreeParameters.js.map +1 -1
- package/dist/development/accessorPropagation/useEntitySubTree.js +4 -6
- package/dist/development/accessorPropagation/useEntitySubTree.js.map +1 -1
- package/dist/development/accessorPropagation/useEntitySubTreeParameters.js +2 -4
- package/dist/development/accessorPropagation/useEntitySubTreeParameters.js.map +1 -1
- package/dist/development/accessorPropagation/useEnvironment.js +2 -4
- package/dist/development/accessorPropagation/useEnvironment.js.map +1 -1
- package/dist/development/accessorPropagation/useField.js +7 -9
- package/dist/development/accessorPropagation/useField.js.map +1 -1
- package/dist/development/accessorPropagation/useGetEntityByKey.js +1 -3
- package/dist/development/accessorPropagation/useGetEntityByKey.js.map +1 -1
- package/dist/development/accessorPropagation/useGetEntityListSubTree.js +4 -6
- package/dist/development/accessorPropagation/useGetEntityListSubTree.js.map +1 -1
- package/dist/development/accessorPropagation/useGetEntitySubTree.js +4 -6
- package/dist/development/accessorPropagation/useGetEntitySubTree.js.map +1 -1
- package/dist/development/accessorPropagation/useGetTreeFilters.js +1 -3
- package/dist/development/accessorPropagation/useGetTreeFilters.js.map +1 -1
- package/dist/development/accessorPropagation/useHasEntity.js +2 -4
- package/dist/development/accessorPropagation/useHasEntity.js.map +1 -1
- package/dist/development/accessorPropagation/usePersist.js +1 -3
- package/dist/development/accessorPropagation/usePersist.js.map +1 -1
- package/dist/development/accessorPropagation/useTreeRootId.js +2 -4
- package/dist/development/accessorPropagation/useTreeRootId.js.map +1 -1
- package/dist/development/accessorSorting/SetOrderFieldOnCreate.js +9 -11
- package/dist/development/accessorSorting/SetOrderFieldOnCreate.js.map +1 -1
- package/dist/development/accessorSorting/addEntityAtIndex.js +2 -4
- package/dist/development/accessorSorting/addEntityAtIndex.js.map +1 -1
- package/dist/development/accessorSorting/errors.js +1 -3
- package/dist/development/accessorSorting/errors.js.map +1 -1
- package/dist/development/accessorSorting/moveEntity.js +1 -3
- package/dist/development/accessorSorting/moveEntity.js.map +1 -1
- package/dist/development/accessorSorting/repairEntitiesOrder.js +0 -1
- package/dist/development/accessorSorting/repairEntitiesOrder.js.map +1 -1
- package/dist/development/accessorSorting/sortEntities.js +0 -1
- package/dist/development/accessorSorting/sortEntities.js.map +1 -1
- package/dist/development/accessorSorting/useSortedEntities.js +6 -8
- package/dist/development/accessorSorting/useSortedEntities.js.map +1 -1
- package/dist/development/accessorTree/AccessorTree.js +4 -6
- package/dist/development/accessorTree/AccessorTree.js.map +1 -1
- package/dist/development/accessorTree/DirtinessContext.js +1 -3
- package/dist/development/accessorTree/DirtinessContext.js.map +1 -1
- package/dist/development/accessorTree/MutationStateContext.js +1 -3
- package/dist/development/accessorTree/MutationStateContext.js.map +1 -1
- package/dist/development/accessorTree/NormalizedPersistedData.js +0 -1
- package/dist/development/accessorTree/NormalizedPersistedData.js.map +1 -1
- package/dist/development/accessorTree/RuntimeId.js +22 -17
- package/dist/development/accessorTree/RuntimeId.js.map +1 -1
- package/dist/development/accessorTree/accessorTreeStateReducer.js +0 -1
- package/dist/development/accessorTree/accessorTreeStateReducer.js.map +1 -1
- package/dist/development/accessorTree/metadataToRequestError.js +0 -1
- package/dist/development/accessorTree/metadataToRequestError.js.map +1 -1
- package/dist/development/accessorTree/useDataBinding.js +5 -7
- package/dist/development/accessorTree/useDataBinding.js.map +1 -1
- package/dist/development/accessorTree/useDirtinessState.js +2 -4
- package/dist/development/accessorTree/useDirtinessState.js.map +1 -1
- package/dist/development/accessorTree/useMutationState.js +2 -4
- package/dist/development/accessorTree/useMutationState.js.map +1 -1
- package/dist/development/accessors/EntityAccessor.js +5 -7
- package/dist/development/accessors/EntityAccessor.js.map +1 -1
- package/dist/development/accessors/EntityListAccessor.js +1 -3
- package/dist/development/accessors/EntityListAccessor.js.map +1 -1
- package/dist/development/accessors/ErrorAccessor.js +0 -1
- package/dist/development/accessors/ErrorAccessor.js.map +1 -1
- package/dist/development/accessors/FieldAccessor.js +3 -5
- package/dist/development/accessors/FieldAccessor.js.map +1 -1
- package/dist/development/accessors/TreeRootAccessor.js +0 -1
- package/dist/development/accessors/TreeRootAccessor.js.map +1 -1
- package/dist/development/bindingTypes.js +0 -1
- package/dist/development/bindingTypes.js.map +1 -1
- package/dist/development/core/AccessorErrorManager.js +15 -11
- package/dist/development/core/AccessorErrorManager.js.map +1 -1
- package/dist/development/core/Config.js +18 -12
- package/dist/development/core/Config.js.map +1 -1
- package/dist/development/core/DataBinding.js +57 -51
- package/dist/development/core/DataBinding.js.map +1 -1
- package/dist/development/core/DirtinessTracker.js +10 -3
- package/dist/development/core/DirtinessTracker.js.map +1 -1
- package/dist/development/core/ErrorsPreprocessor.js +3 -5
- package/dist/development/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/development/core/EventManager.js +20 -16
- package/dist/development/core/EventManager.js.map +1 -1
- package/dist/development/core/IncrementalMarkerBuilder.js +14 -8
- package/dist/development/core/IncrementalMarkerBuilder.js.map +1 -1
- package/dist/development/core/MarkerComparator.js +6 -8
- package/dist/development/core/MarkerComparator.js.map +1 -1
- package/dist/development/core/MarkerMerger.js +17 -15
- package/dist/development/core/MarkerMerger.js.map +1 -1
- package/dist/development/core/MarkerTreeGenerator.js +18 -13
- package/dist/development/core/MarkerTreeGenerator.js.map +1 -1
- package/dist/development/core/MutationGenerator.js +13 -15
- package/dist/development/core/MutationGenerator.js.map +1 -1
- package/dist/development/core/QueryGenerator.js +9 -11
- package/dist/development/core/QueryGenerator.js.map +1 -1
- package/dist/development/core/RealmKeyGenerator.js +10 -6
- package/dist/development/core/RealmKeyGenerator.js.map +1 -1
- package/dist/development/core/RequestResponseNormalizer.js +7 -9
- package/dist/development/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/development/core/StateInitializer.js +27 -23
- package/dist/development/core/StateInitializer.js.map +1 -1
- package/dist/development/core/TreeAugmenter.js +6 -8
- package/dist/development/core/TreeAugmenter.js.map +1 -1
- package/dist/development/core/TreeFilterGenerator.js +8 -8
- package/dist/development/core/TreeFilterGenerator.js.map +1 -1
- package/dist/development/core/TreeParameterMerger.js +2 -4
- package/dist/development/core/TreeParameterMerger.js.map +1 -1
- package/dist/development/core/TreeStore.js +19 -15
- package/dist/development/core/TreeStore.js.map +1 -1
- package/dist/development/core/VariableInputTransformer.js +2 -4
- package/dist/development/core/VariableInputTransformer.js.map +1 -1
- package/dist/development/core/exceptions/ErrorLocator.js +10 -6
- package/dist/development/core/exceptions/ErrorLocator.js.map +1 -1
- package/dist/development/core/exceptions/LocalizedBindingError.js +1 -3
- package/dist/development/core/exceptions/LocalizedBindingError.js.map +1 -1
- package/dist/development/core/exceptions/MarkerSugarer.js +7 -9
- package/dist/development/core/exceptions/MarkerSugarer.js.map +1 -1
- package/dist/development/core/exceptions/TreeParameterSugarer.js +0 -1
- package/dist/development/core/exceptions/TreeParameterSugarer.js.map +1 -1
- package/dist/development/core/factories/createBatchUpdatesOptions.js +1 -3
- package/dist/development/core/factories/createBatchUpdatesOptions.js.map +1 -1
- package/dist/development/core/operations/EntityOperations.js +13 -14
- package/dist/development/core/operations/EntityOperations.js.map +1 -1
- package/dist/development/core/operations/FieldOperations.js +10 -12
- package/dist/development/core/operations/FieldOperations.js.map +1 -1
- package/dist/development/core/operations/ListOperations.js +12 -14
- package/dist/development/core/operations/ListOperations.js.map +1 -1
- package/dist/development/core/operations/OperationsHelpers.js +4 -6
- package/dist/development/core/operations/OperationsHelpers.js.map +1 -1
- package/dist/development/core/requestAliases/MutationAlias.js +2 -4
- package/dist/development/core/requestAliases/MutationAlias.js.map +1 -1
- package/dist/development/core/requestAliases/mutationOperationSubTreeType.js +0 -1
- package/dist/development/core/requestAliases/mutationOperationSubTreeType.js.map +1 -1
- package/dist/development/core/requestAliases/mutationOperationType.js +0 -1
- package/dist/development/core/requestAliases/mutationOperationType.js.map +1 -1
- package/dist/development/core/schema/Schema.js +0 -1
- package/dist/development/core/schema/Schema.js.map +1 -1
- package/dist/development/core/schema/SchemaLoader.js +9 -5
- package/dist/development/core/schema/SchemaLoader.js.map +1 -1
- package/dist/development/core/schema/SchemaPreprocessor.js +0 -1
- package/dist/development/core/schema/SchemaPreprocessor.js.map +1 -1
- package/dist/development/core/schema/SchemaValidator.js +9 -11
- package/dist/development/core/schema/SchemaValidator.js.map +1 -1
- package/dist/development/core/state/StateIterator.js +2 -4
- package/dist/development/core/state/StateIterator.js.map +1 -1
- package/dist/development/core/state/getEntityMarker.js +0 -1
- package/dist/development/core/state/getEntityMarker.js.map +1 -1
- package/dist/development/core/utils/getCombinedSignal.js +0 -1
- package/dist/development/core/utils/getCombinedSignal.js.map +1 -1
- package/dist/development/coreComponents/Component.js +2 -4
- package/dist/development/coreComponents/Component.js.map +1 -1
- package/dist/development/coreComponents/DataBindingProvider.js +3 -5
- package/dist/development/coreComponents/DataBindingProvider.js.map +1 -1
- package/dist/development/coreComponents/Entity.js +3 -5
- package/dist/development/coreComponents/Entity.js.map +1 -1
- package/dist/development/coreComponents/EntityList.js +3 -5
- package/dist/development/coreComponents/EntityList.js.map +1 -1
- package/dist/development/coreComponents/EntityListSubTree.js +12 -14
- package/dist/development/coreComponents/EntityListSubTree.js.map +1 -1
- package/dist/development/coreComponents/EntitySubTree.js +14 -16
- package/dist/development/coreComponents/EntitySubTree.js.map +1 -1
- package/dist/development/coreComponents/Field.js +5 -7
- package/dist/development/coreComponents/Field.js.map +1 -1
- package/dist/development/coreComponents/HasMany.js +8 -10
- package/dist/development/coreComponents/HasMany.js.map +1 -1
- package/dist/development/coreComponents/HasOne.js +8 -10
- package/dist/development/coreComponents/HasOne.js.map +1 -1
- package/dist/development/coreComponents/ParentEntity.js +3 -5
- package/dist/development/coreComponents/ParentEntity.js.map +1 -1
- package/dist/development/dao/Environment.js +7 -2
- package/dist/development/dao/Environment.js.map +1 -1
- package/dist/development/dao/VariableFieldValue.js +0 -1
- package/dist/development/dao/VariableFieldValue.js.map +1 -1
- package/dist/development/entityEvents/useDerivedField.js +4 -6
- package/dist/development/entityEvents/useDerivedField.js.map +1 -1
- package/dist/development/entityEvents/useEntityBeforePersist.js +1 -3
- package/dist/development/entityEvents/useEntityBeforePersist.js.map +1 -1
- package/dist/development/entityEvents/useEntityBeforeUpdate.js +1 -3
- package/dist/development/entityEvents/useEntityBeforeUpdate.js.map +1 -1
- package/dist/development/entityEvents/useEntityEvent.js +3 -5
- package/dist/development/entityEvents/useEntityEvent.js.map +1 -1
- package/dist/development/entityEvents/useEntityPersistError.js +1 -3
- package/dist/development/entityEvents/useEntityPersistError.js.map +1 -1
- package/dist/development/entityEvents/useEntityPersistSuccess.js +1 -3
- package/dist/development/entityEvents/useEntityPersistSuccess.js.map +1 -1
- package/dist/development/entityEvents/useOnConnectionUpdate.js +1 -3
- package/dist/development/entityEvents/useOnConnectionUpdate.js.map +1 -1
- package/dist/development/fieldHelpers/helpers/FieldHelper.js +8 -4
- package/dist/development/fieldHelpers/helpers/FieldHelper.js.map +1 -1
- package/dist/development/fieldHelpers/helpers/TemporalFieldHelper.js +1 -3
- package/dist/development/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -1
- package/dist/development/fieldHelpers/helpers/UuidFieldHelper.js +2 -4
- package/dist/development/fieldHelpers/helpers/UuidFieldHelper.js.map +1 -1
- package/dist/development/helperComponents/DeferredSubTrees.js +9 -11
- package/dist/development/helperComponents/DeferredSubTrees.js.map +1 -1
- package/dist/development/helperComponents/EntityView.js +2 -4
- package/dist/development/helperComponents/EntityView.js.map +1 -1
- package/dist/development/helperComponents/FieldView.js +7 -9
- package/dist/development/helperComponents/FieldView.js.map +1 -1
- package/dist/development/helperComponents/StaticRender.js +2 -4
- package/dist/development/helperComponents/StaticRender.js.map +1 -1
- package/dist/development/helperComponents/SugaredField.js +3 -5
- package/dist/development/helperComponents/SugaredField.js.map +1 -1
- package/dist/development/index.js +101 -101
- package/dist/development/index.js.map +1 -1
- package/dist/development/markers/EntityFieldMarkersContainer.js +5 -7
- package/dist/development/markers/EntityFieldMarkersContainer.js.map +1 -1
- package/dist/development/markers/EntityFieldsWithHoistablesMarker.js +0 -1
- package/dist/development/markers/EntityFieldsWithHoistablesMarker.js.map +1 -1
- package/dist/development/markers/EntityListSubTreeMarker.js +8 -4
- package/dist/development/markers/EntityListSubTreeMarker.js.map +1 -1
- package/dist/development/markers/EntitySubTreeMarker.js +8 -4
- package/dist/development/markers/EntitySubTreeMarker.js.map +1 -1
- package/dist/development/markers/FieldMarker.js +8 -4
- package/dist/development/markers/FieldMarker.js.map +1 -1
- package/dist/development/markers/HasManyRelationMarker.js +9 -5
- package/dist/development/markers/HasManyRelationMarker.js.map +1 -1
- package/dist/development/markers/HasOneRelationMarker.js +8 -4
- package/dist/development/markers/HasOneRelationMarker.js.map +1 -1
- package/dist/development/markers/MarkerTreeRoot.js +0 -1
- package/dist/development/markers/MarkerTreeRoot.js.map +1 -1
- package/dist/development/markers/ParentEntityMarker.js +0 -1
- package/dist/development/markers/ParentEntityMarker.js.map +1 -1
- package/dist/development/markers/PlaceholderGenerator.js +1 -3
- package/dist/development/markers/PlaceholderGenerator.js.map +1 -1
- package/dist/development/queryLanguage/CacheStore.js +10 -4
- package/dist/development/queryLanguage/CacheStore.js.map +1 -1
- package/dist/development/queryLanguage/MarkerFactory.js +11 -13
- package/dist/development/queryLanguage/MarkerFactory.js.map +1 -1
- package/dist/development/queryLanguage/Parser.js +561 -548
- package/dist/development/queryLanguage/Parser.js.map +1 -1
- package/dist/development/queryLanguage/QueryLanguage.js +32 -27
- package/dist/development/queryLanguage/QueryLanguage.js.map +1 -1
- package/dist/development/queryLanguage/QueryLanguageError.js +0 -1
- package/dist/development/queryLanguage/QueryLanguageError.js.map +1 -1
- package/dist/development/queryLanguage/tokenList.js +6 -3
- package/dist/development/queryLanguage/tokenList.js.map +1 -1
- package/dist/development/structures/BijectiveIndexedMap.js +14 -9
- package/dist/development/structures/BijectiveIndexedMap.js.map +1 -1
- package/dist/development/structures/LRUCache.js +7 -2
- package/dist/development/structures/LRUCache.js.map +1 -1
- package/dist/development/structures/WeakIdCache.js +11 -4
- package/dist/development/structures/WeakIdCache.js.map +1 -1
- package/dist/development/treeParameterHelpers/wrapFilterInHasOnes.js +1 -3
- package/dist/development/treeParameterHelpers/wrapFilterInHasOnes.js.map +1 -1
- package/dist/development/treeParameters/EntityCreationParameters.js +0 -1
- package/dist/development/treeParameters/EntityCreationParameters.js.map +1 -1
- package/dist/development/treeParameters/EntityListPreferences.js +0 -1
- package/dist/development/treeParameters/EntityListPreferences.js.map +1 -1
- package/dist/development/treeParameters/EventListenersStore.js +0 -1
- package/dist/development/treeParameters/EventListenersStore.js.map +1 -1
- package/dist/development/treeParameters/LeafField.js +0 -1
- package/dist/development/treeParameters/LeafField.js.map +1 -1
- package/dist/development/treeParameters/QualifiedEntityParameters.js +0 -1
- package/dist/development/treeParameters/QualifiedEntityParameters.js.map +1 -1
- package/dist/development/treeParameters/Relation.js +0 -1
- package/dist/development/treeParameters/Relation.js.map +1 -1
- package/dist/development/utils/Hashing.js +0 -1
- package/dist/development/utils/Hashing.js.map +1 -1
- package/dist/development/utils/assert.js +1 -3
- package/dist/development/utils/assert.js.map +1 -1
- package/dist/development/utils/assertNever.js +2 -4
- package/dist/development/utils/assertNever.js.map +1 -1
- package/dist/development/utils/generateEnumerabilityPreventingEntropy.js +0 -1
- package/dist/development/utils/generateEnumerabilityPreventingEntropy.js.map +1 -1
- package/dist/development/utils/isEmptyObject.js +0 -1
- package/dist/development/utils/isEmptyObject.js.map +1 -1
- package/dist/development/utils/ucfirst.js +0 -1
- package/dist/development/utils/ucfirst.js.map +1 -1
- package/dist/production/BindingError.js.map +1 -1
- package/dist/production/accessorPropagation/AccessorProvider.js.map +1 -1
- package/dist/production/accessorPropagation/BindingOperationsContext.js.map +1 -1
- package/dist/production/accessorPropagation/BindingOperationsProvider.js.map +1 -1
- package/dist/production/accessorPropagation/EntityKeyContext.js.map +1 -1
- package/dist/production/accessorPropagation/EntityKeyProvider.js.map +1 -1
- package/dist/production/accessorPropagation/EnvironmentContext.js.map +1 -1
- package/dist/production/accessorPropagation/TreeRootIdContext.js.map +1 -1
- package/dist/production/accessorPropagation/TreeRootIdProvider.js.map +1 -1
- package/dist/production/accessorPropagation/useAccessorUpdateSubscription.js.map +1 -1
- package/dist/production/accessorPropagation/useBindingOperations.js.map +1 -1
- package/dist/production/accessorPropagation/useDesugaredRelativeEntityList.js.map +1 -1
- package/dist/production/accessorPropagation/useDesugaredRelativeSingleEntity.js.map +1 -1
- package/dist/production/accessorPropagation/useDesugaredRelativeSingleField.js.map +1 -1
- package/dist/production/accessorPropagation/useEntity.js.map +1 -1
- package/dist/production/accessorPropagation/useEntityKey.js.map +1 -1
- package/dist/production/accessorPropagation/useEntityList.js.map +1 -1
- package/dist/production/accessorPropagation/useEntityListSubTree.js.map +1 -1
- package/dist/production/accessorPropagation/useEntityListSubTreeParameters.js.map +1 -1
- package/dist/production/accessorPropagation/useEntitySubTree.js.map +1 -1
- package/dist/production/accessorPropagation/useEntitySubTreeParameters.js.map +1 -1
- package/dist/production/accessorPropagation/useEnvironment.js.map +1 -1
- package/dist/production/accessorPropagation/useField.js.map +1 -1
- package/dist/production/accessorPropagation/useGetEntityByKey.js.map +1 -1
- package/dist/production/accessorPropagation/useGetEntityListSubTree.js.map +1 -1
- package/dist/production/accessorPropagation/useGetEntitySubTree.js.map +1 -1
- package/dist/production/accessorPropagation/useGetTreeFilters.js.map +1 -1
- package/dist/production/accessorPropagation/useHasEntity.js.map +1 -1
- package/dist/production/accessorPropagation/usePersist.js.map +1 -1
- package/dist/production/accessorPropagation/useTreeRootId.js.map +1 -1
- package/dist/production/accessorSorting/SetOrderFieldOnCreate.js.map +1 -1
- package/dist/production/accessorSorting/addEntityAtIndex.js.map +1 -1
- package/dist/production/accessorSorting/errors.js.map +1 -1
- package/dist/production/accessorSorting/moveEntity.js.map +1 -1
- package/dist/production/accessorSorting/repairEntitiesOrder.js.map +1 -1
- package/dist/production/accessorSorting/sortEntities.js.map +1 -1
- package/dist/production/accessorSorting/useSortedEntities.js.map +1 -1
- package/dist/production/accessorTree/AccessorTree.js.map +1 -1
- package/dist/production/accessorTree/DirtinessContext.js.map +1 -1
- package/dist/production/accessorTree/MutationStateContext.js.map +1 -1
- package/dist/production/accessorTree/NormalizedPersistedData.js.map +1 -1
- package/dist/production/accessorTree/RuntimeId.js.map +1 -1
- package/dist/production/accessorTree/accessorTreeStateReducer.js.map +1 -1
- package/dist/production/accessorTree/metadataToRequestError.js.map +1 -1
- package/dist/production/accessorTree/useDataBinding.js.map +1 -1
- package/dist/production/accessorTree/useDirtinessState.js.map +1 -1
- package/dist/production/accessorTree/useMutationState.js.map +1 -1
- package/dist/production/accessors/EntityAccessor.js.map +1 -1
- package/dist/production/accessors/EntityListAccessor.js.map +1 -1
- package/dist/production/accessors/ErrorAccessor.js.map +1 -1
- package/dist/production/accessors/FieldAccessor.js.map +1 -1
- package/dist/production/accessors/TreeRootAccessor.js.map +1 -1
- package/dist/production/bindingTypes.js.map +1 -1
- package/dist/production/core/AccessorErrorManager.js.map +1 -1
- package/dist/production/core/Config.js.map +1 -1
- package/dist/production/core/DataBinding.js +4 -3
- package/dist/production/core/DataBinding.js.map +1 -1
- package/dist/production/core/DirtinessTracker.js.map +1 -1
- package/dist/production/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/production/core/EventManager.js.map +1 -1
- package/dist/production/core/IncrementalMarkerBuilder.js.map +1 -1
- package/dist/production/core/MarkerComparator.js.map +1 -1
- package/dist/production/core/MarkerMerger.js.map +1 -1
- package/dist/production/core/MarkerTreeGenerator.js.map +1 -1
- package/dist/production/core/MutationGenerator.js.map +1 -1
- package/dist/production/core/QueryGenerator.js.map +1 -1
- package/dist/production/core/RealmKeyGenerator.js.map +1 -1
- package/dist/production/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/production/core/StateInitializer.js.map +1 -1
- package/dist/production/core/TreeAugmenter.js.map +1 -1
- package/dist/production/core/TreeFilterGenerator.js.map +1 -1
- package/dist/production/core/TreeParameterMerger.js.map +1 -1
- package/dist/production/core/TreeStore.js.map +1 -1
- package/dist/production/core/VariableInputTransformer.js.map +1 -1
- package/dist/production/core/exceptions/ErrorLocator.js.map +1 -1
- package/dist/production/core/exceptions/LocalizedBindingError.js.map +1 -1
- package/dist/production/core/exceptions/MarkerSugarer.js.map +1 -1
- package/dist/production/core/exceptions/TreeParameterSugarer.js.map +1 -1
- package/dist/production/core/factories/createBatchUpdatesOptions.js.map +1 -1
- package/dist/production/core/operations/EntityOperations.js.map +1 -1
- package/dist/production/core/operations/FieldOperations.js.map +1 -1
- package/dist/production/core/operations/ListOperations.js.map +1 -1
- package/dist/production/core/operations/OperationsHelpers.js.map +1 -1
- package/dist/production/core/requestAliases/MutationAlias.js.map +1 -1
- package/dist/production/core/requestAliases/mutationOperationSubTreeType.js.map +1 -1
- package/dist/production/core/requestAliases/mutationOperationType.js.map +1 -1
- package/dist/production/core/schema/Schema.js.map +1 -1
- package/dist/production/core/schema/SchemaLoader.js.map +1 -1
- package/dist/production/core/schema/SchemaPreprocessor.js.map +1 -1
- package/dist/production/core/state/StateIterator.js.map +1 -1
- package/dist/production/core/state/getEntityMarker.js.map +1 -1
- package/dist/production/core/utils/getCombinedSignal.js.map +1 -1
- package/dist/production/coreComponents/Component.js.map +1 -1
- package/dist/production/coreComponents/DataBindingProvider.js.map +1 -1
- package/dist/production/coreComponents/Entity.js.map +1 -1
- package/dist/production/coreComponents/EntityList.js.map +1 -1
- package/dist/production/coreComponents/EntityListSubTree.js.map +1 -1
- package/dist/production/coreComponents/EntitySubTree.js.map +1 -1
- package/dist/production/coreComponents/Field.js.map +1 -1
- package/dist/production/coreComponents/HasMany.js.map +1 -1
- package/dist/production/coreComponents/HasOne.js.map +1 -1
- package/dist/production/coreComponents/ParentEntity.js.map +1 -1
- package/dist/production/dao/Environment.js.map +1 -1
- package/dist/production/dao/VariableFieldValue.js.map +1 -1
- package/dist/production/entityEvents/useDerivedField.js.map +1 -1
- package/dist/production/entityEvents/useEntityBeforePersist.js.map +1 -1
- package/dist/production/entityEvents/useEntityBeforeUpdate.js.map +1 -1
- package/dist/production/entityEvents/useEntityEvent.js.map +1 -1
- package/dist/production/entityEvents/useEntityPersistError.js.map +1 -1
- package/dist/production/entityEvents/useEntityPersistSuccess.js.map +1 -1
- package/dist/production/entityEvents/useOnConnectionUpdate.js.map +1 -1
- package/dist/production/fieldHelpers/helpers/FieldHelper.js.map +1 -1
- package/dist/production/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -1
- package/dist/production/fieldHelpers/helpers/UuidFieldHelper.js.map +1 -1
- package/dist/production/helperComponents/DeferredSubTrees.js.map +1 -1
- package/dist/production/helperComponents/EntityView.js.map +1 -1
- package/dist/production/helperComponents/FieldView.js.map +1 -1
- package/dist/production/helperComponents/StaticRender.js.map +1 -1
- package/dist/production/helperComponents/SugaredField.js.map +1 -1
- package/dist/production/index.js +1 -1
- package/dist/production/markers/EntityFieldMarkersContainer.js.map +1 -1
- package/dist/production/markers/EntityFieldsWithHoistablesMarker.js.map +1 -1
- package/dist/production/markers/EntityListSubTreeMarker.js.map +1 -1
- package/dist/production/markers/EntitySubTreeMarker.js.map +1 -1
- package/dist/production/markers/FieldMarker.js.map +1 -1
- package/dist/production/markers/HasManyRelationMarker.js.map +1 -1
- package/dist/production/markers/HasOneRelationMarker.js.map +1 -1
- package/dist/production/markers/MarkerTreeRoot.js.map +1 -1
- package/dist/production/markers/ParentEntityMarker.js.map +1 -1
- package/dist/production/markers/PlaceholderGenerator.js.map +1 -1
- package/dist/production/queryLanguage/CacheStore.js.map +1 -1
- package/dist/production/queryLanguage/MarkerFactory.js.map +1 -1
- package/dist/production/queryLanguage/Parser.js +9 -1
- package/dist/production/queryLanguage/Parser.js.map +1 -1
- package/dist/production/queryLanguage/QueryLanguage.js.map +1 -1
- package/dist/production/queryLanguage/QueryLanguageError.js.map +1 -1
- package/dist/production/queryLanguage/tokenList.js +5 -0
- package/dist/production/queryLanguage/tokenList.js.map +1 -1
- package/dist/production/structures/BijectiveIndexedMap.js.map +1 -1
- package/dist/production/structures/LRUCache.js.map +1 -1
- package/dist/production/structures/WeakIdCache.js.map +1 -1
- package/dist/production/treeParameterHelpers/wrapFilterInHasOnes.js.map +1 -1
- package/dist/production/treeParameters/EntityCreationParameters.js.map +1 -1
- package/dist/production/treeParameters/EntityListPreferences.js.map +1 -1
- package/dist/production/treeParameters/EventListenersStore.js.map +1 -1
- package/dist/production/treeParameters/LeafField.js.map +1 -1
- package/dist/production/treeParameters/QualifiedEntityParameters.js.map +1 -1
- package/dist/production/treeParameters/Relation.js.map +1 -1
- package/dist/production/utils/Hashing.js.map +1 -1
- package/dist/production/utils/assert.js.map +1 -1
- package/dist/production/utils/assertNever.js +1 -1
- package/dist/production/utils/assertNever.js.map +1 -1
- package/dist/production/utils/generateEnumerabilityPreventingEntropy.js.map +1 -1
- package/dist/production/utils/isEmptyObject.js.map +1 -1
- package/dist/production/utils/ucfirst.js.map +1 -1
- package/dist/types/core/DataBinding.d.ts +1 -0
- package/dist/types/core/DataBinding.d.ts.map +1 -1
- package/dist/types/queryLanguage/Parser.d.ts +1 -0
- package/dist/types/queryLanguage/Parser.d.ts.map +1 -1
- package/dist/types/queryLanguage/tokenList.d.ts +1 -0
- package/dist/types/queryLanguage/tokenList.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/src/core/DataBinding.ts +4 -2
- package/src/queryLanguage/Parser.ts +12 -1
- package/src/queryLanguage/tokenList.ts +6 -0
- package/src/tsconfig.json +1 -1
- package/src/utils/assertNever.ts +1 -1
|
@@ -1,27 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import { AccessorErrorManager } from "./AccessorErrorManager.js";
|
|
8
|
+
import { Config } from "./Config.js";
|
|
9
|
+
import { DirtinessTracker } from "./DirtinessTracker.js";
|
|
10
|
+
import { EventManager } from "./EventManager.js";
|
|
11
|
+
import { MarkerMerger } from "./MarkerMerger.js";
|
|
12
|
+
import { MarkerTreeGenerator } from "./MarkerTreeGenerator.js";
|
|
13
|
+
import { MutationGenerator } from "./MutationGenerator.js";
|
|
14
|
+
import { QueryGenerator } from "./QueryGenerator.js";
|
|
15
|
+
import { StateInitializer } from "./StateInitializer.js";
|
|
16
|
+
import { TreeAugmenter } from "./TreeAugmenter.js";
|
|
17
|
+
import { TreeFilterGenerator } from "./TreeFilterGenerator.js";
|
|
18
|
+
import { TreeStore } from "./TreeStore.js";
|
|
19
|
+
import { createBatchUpdatesOptions } from "./factories/createBatchUpdatesOptions.js";
|
|
20
|
+
import { TreeRootAccessor } from "../accessors/TreeRootAccessor.js";
|
|
21
|
+
import { SchemaValidator } from "./schema/SchemaValidator.js";
|
|
22
|
+
import { getCombinedSignal } from "./utils/getCombinedSignal.js";
|
|
23
|
+
import { metadataToRequestError } from "../accessorTree/metadataToRequestError.js";
|
|
24
|
+
import { SchemaLoader } from "./schema/SchemaLoader.js";
|
|
25
|
+
import { StateIterator } from "./state/StateIterator.js";
|
|
26
|
+
import { assertNever } from "../utils/assertNever.js";
|
|
27
|
+
import { generateEnumerabilityPreventingEntropy } from "../utils/generateEnumerabilityPreventingEntropy.js";
|
|
28
|
+
const _DataBinding = class {
|
|
24
29
|
constructor(contentApiClient, systemApiClient, tenantApiClient, environment, onUpdate, onError, onPersistSuccess) {
|
|
30
|
+
__publicField(this, "accessorErrorManager");
|
|
31
|
+
__publicField(this, "batchUpdatesOptions");
|
|
32
|
+
__publicField(this, "asyncBatchUpdatesOptions");
|
|
33
|
+
__publicField(this, "bindingOperations");
|
|
34
|
+
__publicField(this, "config");
|
|
35
|
+
__publicField(this, "dirtinessTracker");
|
|
36
|
+
__publicField(this, "eventManager");
|
|
37
|
+
__publicField(this, "stateInitializer");
|
|
38
|
+
__publicField(this, "treeAugmenter");
|
|
39
|
+
__publicField(this, "treeStore");
|
|
40
|
+
__publicField(this, "resolvedOnUpdate", ({ isMutating }) => {
|
|
41
|
+
this.onUpdate(new TreeRootAccessor(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations));
|
|
42
|
+
});
|
|
43
|
+
__publicField(this, "pendingExtensions", /* @__PURE__ */ new Set());
|
|
25
44
|
this.contentApiClient = contentApiClient;
|
|
26
45
|
this.systemApiClient = systemApiClient;
|
|
27
46
|
this.tenantApiClient = tenantApiClient;
|
|
@@ -161,24 +180,9 @@ class DataBinding {
|
|
|
161
180
|
})
|
|
162
181
|
});
|
|
163
182
|
}
|
|
164
|
-
static schemaLoadCache = /* @__PURE__ */ new Map();
|
|
165
|
-
accessorErrorManager;
|
|
166
|
-
batchUpdatesOptions;
|
|
167
|
-
asyncBatchUpdatesOptions;
|
|
168
|
-
bindingOperations;
|
|
169
|
-
config;
|
|
170
|
-
dirtinessTracker;
|
|
171
|
-
eventManager;
|
|
172
|
-
stateInitializer;
|
|
173
|
-
treeAugmenter;
|
|
174
|
-
treeStore;
|
|
175
|
-
resolvedOnUpdate = ({ isMutating }) => {
|
|
176
|
-
this.onUpdate(new TreeRootAccessor(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations));
|
|
177
|
-
};
|
|
178
|
-
pendingExtensions = /* @__PURE__ */ new Set();
|
|
179
183
|
async extendTree(newFragment, options = {}) {
|
|
180
184
|
if (options.signal?.aborted) {
|
|
181
|
-
return Promise.reject();
|
|
185
|
+
return Promise.reject(DataBindingExtendAborted);
|
|
182
186
|
}
|
|
183
187
|
const markerTreeRoot = new MarkerTreeGenerator(newFragment, options.environment ?? this.environment).generate();
|
|
184
188
|
if (this.treeStore.effectivelyHasTreeRoot(markerTreeRoot)) {
|
|
@@ -199,7 +203,7 @@ class DataBinding {
|
|
|
199
203
|
newFragment,
|
|
200
204
|
newTreeRootId: this.getNewTreeRootId(),
|
|
201
205
|
options,
|
|
202
|
-
reject,
|
|
206
|
+
reject: () => reject(DataBindingExtendAborted),
|
|
203
207
|
resolve
|
|
204
208
|
});
|
|
205
209
|
const pendingExtensionsCount = this.pendingExtensions.size;
|
|
@@ -305,25 +309,27 @@ class DataBinding {
|
|
|
305
309
|
});
|
|
306
310
|
}
|
|
307
311
|
getOrLoadSchema() {
|
|
308
|
-
const existing =
|
|
312
|
+
const existing = _DataBinding.schemaLoadCache.get(this.contentApiClient.apiUrl);
|
|
309
313
|
if (existing !== void 0) {
|
|
310
314
|
return existing;
|
|
311
315
|
}
|
|
312
316
|
const schemaPromise = SchemaLoader.loadSchema(this.contentApiClient, this.config.getValue("maxSchemaLoadAttempts"));
|
|
313
317
|
schemaPromise.then((schema) => {
|
|
314
|
-
|
|
318
|
+
_DataBinding.schemaLoadCache.set(this.contentApiClient.apiUrl, schema);
|
|
315
319
|
});
|
|
316
|
-
|
|
320
|
+
_DataBinding.schemaLoadCache.set(this.contentApiClient.apiUrl, schemaPromise);
|
|
317
321
|
return schemaPromise;
|
|
318
322
|
}
|
|
319
|
-
static getNextTreeRootIdSeed = (() => {
|
|
320
|
-
let seed = 1;
|
|
321
|
-
return () => seed++;
|
|
322
|
-
})();
|
|
323
323
|
getNewTreeRootId() {
|
|
324
|
-
return this.treeStore.markerTrees.size === 0 ? void 0 : `${generateEnumerabilityPreventingEntropy()}-${
|
|
324
|
+
return this.treeStore.markerTrees.size === 0 ? void 0 : `${generateEnumerabilityPreventingEntropy()}-${_DataBinding.getNextTreeRootIdSeed()}`;
|
|
325
325
|
}
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
|
|
326
|
+
};
|
|
327
|
+
let DataBinding = _DataBinding;
|
|
328
|
+
__publicField(DataBinding, "schemaLoadCache", /* @__PURE__ */ new Map());
|
|
329
|
+
__publicField(DataBinding, "getNextTreeRootIdSeed", (() => {
|
|
330
|
+
let seed = 1;
|
|
331
|
+
return () => seed++;
|
|
332
|
+
})());
|
|
333
|
+
const DataBindingExtendAborted = Symbol("aborted");
|
|
334
|
+
export { DataBinding, DataBindingExtendAborted };
|
|
329
335
|
//# sourceMappingURL=DataBinding.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataBinding.js","sources":["../../../src/core/DataBinding.ts"],"sourcesContent":["import type { GraphQlClient, GraphQlClientFailedRequestMetadata, TreeFilter } from '@contember/client'\nimport type { ReactNode } from 'react'\nimport {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tBindingOperations,\n\tExtendTreeOptions,\n\tPersistErrorOptions,\n\tPersistSuccessOptions,\n\tTreeRootAccessor,\n} from '../accessors'\nimport {\n\tmetadataToRequestError,\n\tMutationRequestResponse,\n\tQueryRequestResponse,\n\tRequestError,\n\tSuccessfulPersistResult,\n} from '../accessorTree'\nimport type { Environment } from '../dao'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { TreeRootId } from '../treeParameters'\nimport { assertNever, generateEnumerabilityPreventingEntropy } from '../utils'\nimport { AccessorErrorManager } from './AccessorErrorManager'\nimport { Config } from './Config'\nimport { DirtinessTracker } from './DirtinessTracker'\nimport { EventManager } from './EventManager'\nimport { createBatchUpdatesOptions } from './factories'\nimport { MarkerMerger } from './MarkerMerger'\nimport { MarkerTreeGenerator } from './MarkerTreeGenerator'\nimport { MutationGenerator } from './MutationGenerator'\nimport { QueryGenerator } from './QueryGenerator'\nimport { Schema, SchemaLoader, SchemaValidator } from './schema'\nimport { StateIterator } from './state'\nimport { StateInitializer } from './StateInitializer'\nimport { TreeAugmenter } from './TreeAugmenter'\nimport { TreeFilterGenerator } from './TreeFilterGenerator'\nimport { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport { getCombinedSignal } from './utils'\n\nexport class DataBinding {\n\tprivate static readonly schemaLoadCache: Map<string, Schema | Promise<Schema>> = new Map()\n\n\tprivate readonly accessorErrorManager: AccessorErrorManager\n\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions\n\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions\n\tprivate readonly bindingOperations: BindingOperations\n\tprivate readonly config: Config\n\tprivate readonly dirtinessTracker: DirtinessTracker\n\tprivate readonly eventManager: EventManager\n\tprivate readonly stateInitializer: StateInitializer\n\tprivate readonly treeAugmenter: TreeAugmenter\n\tprivate readonly treeStore: TreeStore\n\n\t// private treeRootListeners: {\n\t// \teventListeners: {}\n\t// } = {\n\t// \teventListeners: {},\n\t// }\n\n\tpublic constructor(\n\t\tprivate readonly contentApiClient: GraphQlClient,\n\t\tprivate readonly systemApiClient: GraphQlClient,\n\t\tprivate readonly tenantApiClient: GraphQlClient,\n\t\tprivate readonly environment: Environment,\n\t\tprivate readonly onUpdate: (newData: TreeRootAccessor) => void,\n\t\tprivate readonly onError: (error: RequestError) => void,\n\t\tprivate readonly onPersistSuccess: (result: SuccessfulPersistResult) => void,\n\t) {\n\t\tthis.config = new Config()\n\t\tthis.treeStore = new TreeStore()\n\t\tthis.batchUpdatesOptions = createBatchUpdatesOptions(environment, this.treeStore)\n\t\tthis.asyncBatchUpdatesOptions = {\n\t\t\t...this.batchUpdatesOptions,\n\t\t\tcontentClient: contentApiClient,\n\t\t\tsystemClient: systemApiClient,\n\t\t\ttenantClient: tenantApiClient,\n\t\t}\n\t\tthis.dirtinessTracker = new DirtinessTracker()\n\t\tthis.eventManager = new EventManager(\n\t\t\tthis.asyncBatchUpdatesOptions,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.config,\n\t\t\tthis.dirtinessTracker,\n\t\t\tthis.resolvedOnUpdate,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.accessorErrorManager = new AccessorErrorManager(this.eventManager, this.treeStore)\n\t\tthis.stateInitializer = new StateInitializer(\n\t\t\tthis.accessorErrorManager,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.config,\n\t\t\tthis.eventManager,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.treeAugmenter = new TreeAugmenter(this.eventManager, this.stateInitializer, this.treeStore)\n\n\t\t// TODO move this elsewhere\n\t\tthis.bindingOperations = Object.freeze<BindingOperations>({\n\t\t\t...this.asyncBatchUpdatesOptions,\n\t\t\tgetTreeFilters: (): TreeFilter[] => {\n\t\t\t\tconst generator = new TreeFilterGenerator(this.treeStore)\n\t\t\t\treturn generator.generateTreeFilter()\n\t\t\t},\n\t\t\tbatchDeferredUpdates: performUpdates => {\n\t\t\t\tthis.eventManager.syncTransaction(() => performUpdates(this.bindingOperations))\n\t\t\t},\n\t\t\textendTree: async (...args) => await this.extendTree(...args),\n\t\t\tpersist: async ({ signal, onPersistSuccess, onPersistError } = {}) =>\n\t\t\t\tawait this.eventManager.persistOperation(async () => {\n\t\t\t\t\tfor (let attemptNumber = 1; attemptNumber <= this.config.getValue('maxPersistAttempts'); attemptNumber++) {\n\t\t\t\t\t\t// TODO if the tree is in an inconsistent state, wait for lock releases\n\n\t\t\t\t\t\tthis.eventManager.syncTransaction(() => {\n\t\t\t\t\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\t\t\t\t})\n\t\t\t\t\t\tawait this.eventManager.triggerOnBeforePersist()\n\n\t\t\t\t\t\tlet shouldTryAgain = false\n\t\t\t\t\t\tconst proposedBackOffs: number[] = []\n\t\t\t\t\t\tconst persistErrorOptions: PersistErrorOptions = {\n\t\t\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\t\t\ttryAgain: options => {\n\t\t\t\t\t\t\t\tshouldTryAgain = true\n\t\t\t\t\t\t\t\tif (options?.proposedBackoff !== undefined && options.proposedBackoff > 0) {\n\t\t\t\t\t\t\t\t\tproposedBackOffs.push(options.proposedBackoff)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tattemptNumber,\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (this.accessorErrorManager.hasErrors()) {\n\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistError(persistErrorOptions)\n\t\t\t\t\t\t\tawait onPersistError?.(persistErrorOptions)\n\n\t\t\t\t\t\t\tif (shouldTryAgain) {\n\t\t\t\t\t\t\t\tcontinue // Trying again immediately\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tthrow {\n\t\t\t\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst generator = new MutationGenerator(this.treeStore)\n\t\t\t\t\t\tconst mutation = generator.getPersistMutation()\n\n\t\t\t\t\t\tif (mutation === undefined) {\n\t\t\t\t\t\t\tthis.dirtinessTracker.reset() // TODO This ideally shouldn't be necessary but given the current limitations, this makes for better UX.\n\t\t\t\t\t\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\t\t\t\tsuccessType: 'nothingToPersist',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\t\t\t\t\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\ttype: 'nothingToPersist',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst mutationResponse: MutationRequestResponse = await this.contentApiClient.sendRequest(mutation, {\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t})\n\t\t\t\t\t\tconst mutationData = mutationResponse.data?.transaction ?? {}\n\t\t\t\t\t\tconst aliases = Object.keys(mutationData)\n\t\t\t\t\t\tif (!mutationResponse.data) {\n\t\t\t\t\t\t\tthrow {\n\t\t\t\t\t\t\t\terrors: mutationData.errors,\n\t\t\t\t\t\t\t\ttype: 'invalidResponse',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else if (aliases.every(item => mutationData[item].ok)) {\n\t\t\t\t\t\t\tconst persistedEntityIds = aliases.map(alias => mutationData[alias].node?.id).filter(id => id !== undefined)\n\t\t\t\t\t\t\tconst result: SuccessfulPersistResult = {\n\t\t\t\t\t\t\t\ttype: 'justSuccess',\n\t\t\t\t\t\t\t\tpersistedEntityIds,\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tawait this.eventManager.asyncTransaction(async () => {\n\t\t\t\t\t\t\t\t\tthis.resetTreeAfterSuccessfulPersist()\n\t\t\t\t\t\t\t\t\tthis.treeAugmenter.updatePersistedData(\n\t\t\t\t\t\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\t\t\t\t\t\tObject.entries(mutationData).map(([placeholderName, subTreeResponse]) => [\n\t\t\t\t\t\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t\t\t\t\t\tsubTreeResponse.node,\n\t\t\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t\t\t\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\t\t\t\t\t\tsuccessType: result.type,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\t\t\t\t\t\t\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\n\t\t\t\t\t\t\t\t\tthis.treeAugmenter.resetCreatingSubTrees()\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\t\tconsole.error(e)\n\t\t\t\t\t\t\t\tconst resultWithError = {\n\t\t\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\t\t\tafterPersistError: e,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tthis.onPersistSuccess(resultWithError)\n\t\t\t\t\t\t\t\treturn resultWithError\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthis.onPersistSuccess(result)\n\t\t\t\t\t\t\treturn result\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(mutationData))\n\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistError(persistErrorOptions)\n\t\t\t\t\t\t\tawait onPersistError?.(persistErrorOptions)\n\t\t\t\t\t\t\tif (shouldTryAgain) {\n\t\t\t\t\t\t\t\tif (proposedBackOffs.length) {\n\t\t\t\t\t\t\t\t\tconst geometricMean = Math.round(\n\t\t\t\t\t\t\t\t\t\tMath.pow(\n\t\t\t\t\t\t\t\t\t\t\tproposedBackOffs.reduce((a, b) => a * b, 1),\n\t\t\t\t\t\t\t\t\t\t\t1 / proposedBackOffs.length,\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tawait new Promise(resolve => setTimeout(resolve, geometricMean))\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow {\n\t\t\t\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// Max attempts exceeded\n\t\t\t\t\t// TODO fire persist error\n\t\t\t\t\tthrow {\n\t\t\t\t\t\ttype: 'givenUp',\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t})\n\t}\n\n\tprivate resolvedOnUpdate = ({ isMutating }: UpdateMetadata) => {\n\t\tthis.onUpdate(new TreeRootAccessor(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations))\n\t}\n\n\t// This is currently useless but potentially future-compatible\n\t// private readonly addTreeRootEventListener: TreeRootAccessor.AddTreeRootEventListener = this.getAddEventListener(\n\t// \tthis.treeRootListeners,\n\t// )\n\n\tprivate pendingExtensions: Set<{\n\t\tmarkerTreeRoot: MarkerTreeRoot\n\t\tnewFragment: ReactNode\n\t\tnewTreeRootId: TreeRootId | undefined\n\t\toptions: ExtendTreeOptions\n\t\treject: () => void\n\t\tresolve: (newRootId: TreeRootId | undefined) => void\n\t}> = new Set()\n\n\tpublic async extendTree(newFragment: ReactNode, options: ExtendTreeOptions = {}): Promise<TreeRootId | undefined> {\n\t\tif (options.signal?.aborted) {\n\t\t\treturn Promise.reject()\n\t\t}\n\t\tconst markerTreeRoot = new MarkerTreeGenerator(newFragment, options.environment ?? this.environment).generate()\n\n\t\tif (this.treeStore.effectivelyHasTreeRoot(markerTreeRoot)) {\n\t\t\t// This isn't perfectly accurate as theoretically, we could already have all the data necessary but this\n\t\t\t// could still be false.\n\n\t\t\tconst schema = await this.getOrLoadSchema()\n\t\t\tthis.treeStore.setSchema(schema)\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t// For most trees, checking this against the schema should be unnecessary since if we already effectively\n\t\t\t\t// have this tree root, then assuming everything we already have is valid, this should match the schema as well.\n\t\t\t\t// However, we might be dealing with an isCreating tree root which is completely new. Also, we can just lean\n\t\t\t\t// towards the safe side since developer machines can generally handle the potentially unnecessary check anyway.\n\t\t\t\tSchemaValidator.assertTreeValid(schema, markerTreeRoot)\n\t\t\t}\n\n\t\t\treturn this.eventManager.syncOperation(() => {\n\t\t\t\tconst newTreeRootId = this.getNewTreeRootId()\n\t\t\t\tthis.treeAugmenter.extendTreeStates(newTreeRootId, markerTreeRoot)\n\t\t\t\treturn newTreeRootId\n\t\t\t})\n\t\t}\n\n\t\treturn await new Promise((resolve, reject) => {\n\t\t\tthis.pendingExtensions.add({\n\t\t\t\tmarkerTreeRoot,\n\t\t\t\tnewFragment,\n\t\t\t\tnewTreeRootId: this.getNewTreeRootId(),\n\t\t\t\toptions,\n\t\t\t\treject,\n\t\t\t\tresolve,\n\t\t\t})\n\t\t\tconst pendingExtensionsCount = this.pendingExtensions.size\n\n\t\t\tPromise.resolve().then(() => {\n\t\t\t\tif (pendingExtensionsCount < this.pendingExtensions.size) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.flushBatchedTreeExtensions()\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async flushBatchedTreeExtensions() {\n\t\t// This is an async operation so we just take whatever pendingExtensions there are now and let any new ones\n\t\t// accumulate in an empty set.\n\t\tconst pendingExtensions = Array.from(this.pendingExtensions).filter(extension => {\n\t\t\tif (extension.options.signal?.aborted) {\n\t\t\t\textension.reject()\n\t\t\t\treturn false\n\t\t\t}\n\t\t\treturn true\n\t\t})\n\t\tthis.pendingExtensions.clear()\n\n\t\tconst aggregateMarkerTreeRoot = pendingExtensions.reduce<MarkerTreeRoot | undefined>(\n\t\t\t(previousValue, currentValue) => {\n\t\t\t\tif (previousValue === undefined) {\n\t\t\t\t\treturn currentValue.markerTreeRoot\n\t\t\t\t}\n\t\t\t\treturn MarkerMerger.mergeMarkerTreeRoots(previousValue, currentValue.markerTreeRoot)\n\t\t\t},\n\t\t\tundefined,\n\t\t)\n\n\t\tif (aggregateMarkerTreeRoot === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tconst aggregateSignal = getCombinedSignal(pendingExtensions.map(extension => extension.options.signal))\n\n\t\t// Even if we don't have a schema yet, we'll still optimistically fire the request so as to prevent a waterfall\n\t\t// in the most likely case that things will go fine and the query does match the schema. If it doesn't, then we\n\t\t// just get a \"400 Bad Request\" but that's not enough to make us delay the happy path.\n\t\tconst [aggregatePersistedData, schema] = await Promise.all([\n\t\t\tthis.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal),\n\t\t\tthis.getOrLoadSchema(),\n\t\t])\n\t\tthis.treeStore.setSchema(schema)\n\n\t\tif (import.meta.env.DEV) {\n\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\tSchemaValidator.assertTreeValid(schema, extension.markerTreeRoot)\n\t\t\t}\n\t\t}\n\n\t\tif (aggregateSignal?.aborted) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.treeAugmenter.extendPersistedData(aggregatePersistedData?.data ?? {})\n\n\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\tthis.treeAugmenter.extendTreeStates(extension.newTreeRootId, extension.markerTreeRoot)\n\t\t\t\textension.resolve(extension.newTreeRootId)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async fetchPersistedData(\n\t\ttree: MarkerTreeRoot,\n\t\tsignal?: AbortSignal,\n\t): Promise<QueryRequestResponse | undefined> {\n\t\tconst queryGenerator = new QueryGenerator(tree)\n\t\tconst query = queryGenerator.getReadQuery()\n\n\t\tlet queryResponse: QueryRequestResponse | undefined = undefined\n\n\t\ttry {\n\t\t\tqueryResponse =\n\t\t\t\tquery === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: await this.contentApiClient.sendRequest(query, {\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t })\n\t\t} catch (metadata) {\n\t\t\tif (metadata.name === 'AbortError') {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.onError(metadataToRequestError(metadata as GraphQlClientFailedRequestMetadata))\n\t\t}\n\t\treturn queryResponse\n\t}\n\n\tprivate resetTreeAfterSuccessfulPersist() {\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\tthis.dirtinessTracker.reset()\n\n\t\t\tfor (const [, rootState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const state of StateIterator.depthFirstAllNodes(rootState)) {\n\t\t\t\t\tswitch (state.type) {\n\t\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\t\tif (state.hasUnpersistedChanges || state.touchLog?.size) {\n\t\t\t\t\t\t\t\tstate.touchLog?.clear()\n\t\t\t\t\t\t\t\tstate.hasUnpersistedChanges = false\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedRemovals?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedRemovals?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedHasOneDeletions?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedHasOneDeletions?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tassertNever(state)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate getOrLoadSchema(): Schema | Promise<Schema> {\n\t\tconst existing = DataBinding.schemaLoadCache.get(this.contentApiClient.apiUrl)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\n\t\tconst schemaPromise = SchemaLoader.loadSchema(this.contentApiClient, this.config.getValue('maxSchemaLoadAttempts'))\n\t\tschemaPromise.then(schema => {\n\t\t\tDataBinding.schemaLoadCache.set(this.contentApiClient.apiUrl, schema)\n\t\t})\n\t\tDataBinding.schemaLoadCache.set(this.contentApiClient.apiUrl, schemaPromise)\n\t\treturn schemaPromise\n\t}\n\n\tprivate static getNextTreeRootIdSeed = (() => {\n\t\tlet seed = 1\n\t\treturn () => seed++\n\t})()\n\n\tprivate getNewTreeRootId() {\n\t\t// TODO this is an awful, awful hack.\n\t\t// TODO the particular shape of the alias is relied on in MutationAlias. If you change this, change it there too.\n\t\treturn this.treeStore.markerTrees.size === 0\n\t\t\t? undefined\n\t\t\t: `${generateEnumerabilityPreventingEntropy()}-${DataBinding.getNextTreeRootIdSeed()}`\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;kBAwCyB;AAAA,EAoBjB,YACW,kBACA,iBACA,iBACA,aACA,UACA,SACA,kBAChB;AAPgB;AACA;AACA;AACA;AACA;AACA;AACA;AAEjB,SAAK,SAAS,IAAI;AAClB,SAAK,YAAY,IAAI;AACrB,SAAK,sBAAsB,0BAA0B,aAAa,KAAK;AACvE,SAAK,2BAA2B;AAAA,SAC5B,KAAK;AAAA,MACR,eAAe;AAAA,MACf,cAAc;AAAA,MACd,cAAc;AAAA;AAEf,SAAK,mBAAmB,IAAI;AAC5B,SAAK,e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AAU;AAC5B,kBAAY,gBAAgB,IAAI,KAAK,iBAAiB,QAAQ;AAAA;AAE/D,gBAAY,gBAAgB,IAAI,KAAK,iBAAiB,QAAQ;AAC9D,WAAO;AAAA;AAAA,SAGO,wBAAyB,OAAM;AAC7C,QAAI,OAAO;AACX,WAAO,MAAM;AAAA;AAAA,EAGN,mBAAmB;AAG1B,WAAO,KAAK,UAAU,YAAY,SAAS,IACxC,SACA,GAAG,4CAA4C,YAAY;AAAA;AAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"DataBinding.js","sources":["../../../src/core/DataBinding.ts"],"sourcesContent":["import type { GraphQlClient, GraphQlClientFailedRequestMetadata, TreeFilter } from '@contember/client'\nimport type { ReactNode } from 'react'\nimport {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tBindingOperations,\n\tExtendTreeOptions,\n\tPersistErrorOptions,\n\tPersistSuccessOptions,\n\tTreeRootAccessor,\n} from '../accessors'\nimport {\n\tmetadataToRequestError,\n\tMutationRequestResponse,\n\tQueryRequestResponse,\n\tRequestError,\n\tSuccessfulPersistResult,\n} from '../accessorTree'\nimport type { Environment } from '../dao'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { TreeRootId } from '../treeParameters'\nimport { assertNever, generateEnumerabilityPreventingEntropy } from '../utils'\nimport { AccessorErrorManager } from './AccessorErrorManager'\nimport { Config } from './Config'\nimport { DirtinessTracker } from './DirtinessTracker'\nimport { EventManager } from './EventManager'\nimport { createBatchUpdatesOptions } from './factories'\nimport { MarkerMerger } from './MarkerMerger'\nimport { MarkerTreeGenerator } from './MarkerTreeGenerator'\nimport { MutationGenerator } from './MutationGenerator'\nimport { QueryGenerator } from './QueryGenerator'\nimport { Schema, SchemaLoader, SchemaValidator } from './schema'\nimport { StateIterator } from './state'\nimport { StateInitializer } from './StateInitializer'\nimport { TreeAugmenter } from './TreeAugmenter'\nimport { TreeFilterGenerator } from './TreeFilterGenerator'\nimport { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport { getCombinedSignal } from './utils'\n\nexport class DataBinding {\n\tprivate static readonly schemaLoadCache: Map<string, Schema | Promise<Schema>> = new Map()\n\n\tprivate readonly accessorErrorManager: AccessorErrorManager\n\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions\n\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions\n\tprivate readonly bindingOperations: BindingOperations\n\tprivate readonly config: Config\n\tprivate readonly dirtinessTracker: DirtinessTracker\n\tprivate readonly eventManager: EventManager\n\tprivate readonly stateInitializer: StateInitializer\n\tprivate readonly treeAugmenter: TreeAugmenter\n\tprivate readonly treeStore: TreeStore\n\n\t// private treeRootListeners: {\n\t// \teventListeners: {}\n\t// } = {\n\t// \teventListeners: {},\n\t// }\n\n\tpublic constructor(\n\t\tprivate readonly contentApiClient: GraphQlClient,\n\t\tprivate readonly systemApiClient: GraphQlClient,\n\t\tprivate readonly tenantApiClient: GraphQlClient,\n\t\tprivate readonly environment: Environment,\n\t\tprivate readonly onUpdate: (newData: TreeRootAccessor) => void,\n\t\tprivate readonly onError: (error: RequestError) => void,\n\t\tprivate readonly onPersistSuccess: (result: SuccessfulPersistResult) => void,\n\t) {\n\t\tthis.config = new Config()\n\t\tthis.treeStore = new TreeStore()\n\t\tthis.batchUpdatesOptions = createBatchUpdatesOptions(environment, this.treeStore)\n\t\tthis.asyncBatchUpdatesOptions = {\n\t\t\t...this.batchUpdatesOptions,\n\t\t\tcontentClient: contentApiClient,\n\t\t\tsystemClient: systemApiClient,\n\t\t\ttenantClient: tenantApiClient,\n\t\t}\n\t\tthis.dirtinessTracker = new DirtinessTracker()\n\t\tthis.eventManager = new EventManager(\n\t\t\tthis.asyncBatchUpdatesOptions,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.config,\n\t\t\tthis.dirtinessTracker,\n\t\t\tthis.resolvedOnUpdate,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.accessorErrorManager = new AccessorErrorManager(this.eventManager, this.treeStore)\n\t\tthis.stateInitializer = new StateInitializer(\n\t\t\tthis.accessorErrorManager,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.config,\n\t\t\tthis.eventManager,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.treeAugmenter = new TreeAugmenter(this.eventManager, this.stateInitializer, this.treeStore)\n\n\t\t// TODO move this elsewhere\n\t\tthis.bindingOperations = Object.freeze<BindingOperations>({\n\t\t\t...this.asyncBatchUpdatesOptions,\n\t\t\tgetTreeFilters: (): TreeFilter[] => {\n\t\t\t\tconst generator = new TreeFilterGenerator(this.treeStore)\n\t\t\t\treturn generator.generateTreeFilter()\n\t\t\t},\n\t\t\tbatchDeferredUpdates: performUpdates => {\n\t\t\t\tthis.eventManager.syncTransaction(() => performUpdates(this.bindingOperations))\n\t\t\t},\n\t\t\textendTree: async (...args) => await this.extendTree(...args),\n\t\t\tpersist: async ({ signal, onPersistSuccess, onPersistError } = {}) =>\n\t\t\t\tawait this.eventManager.persistOperation(async () => {\n\t\t\t\t\tfor (let attemptNumber = 1; attemptNumber <= this.config.getValue('maxPersistAttempts'); attemptNumber++) {\n\t\t\t\t\t\t// TODO if the tree is in an inconsistent state, wait for lock releases\n\n\t\t\t\t\t\tthis.eventManager.syncTransaction(() => {\n\t\t\t\t\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\t\t\t\t})\n\t\t\t\t\t\tawait this.eventManager.triggerOnBeforePersist()\n\n\t\t\t\t\t\tlet shouldTryAgain = false\n\t\t\t\t\t\tconst proposedBackOffs: number[] = []\n\t\t\t\t\t\tconst persistErrorOptions: PersistErrorOptions = {\n\t\t\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\t\t\ttryAgain: options => {\n\t\t\t\t\t\t\t\tshouldTryAgain = true\n\t\t\t\t\t\t\t\tif (options?.proposedBackoff !== undefined && options.proposedBackoff > 0) {\n\t\t\t\t\t\t\t\t\tproposedBackOffs.push(options.proposedBackoff)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tattemptNumber,\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (this.accessorErrorManager.hasErrors()) {\n\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistError(persistErrorOptions)\n\t\t\t\t\t\t\tawait onPersistError?.(persistErrorOptions)\n\n\t\t\t\t\t\t\tif (shouldTryAgain) {\n\t\t\t\t\t\t\t\tcontinue // Trying again immediately\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tthrow {\n\t\t\t\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst generator = new MutationGenerator(this.treeStore)\n\t\t\t\t\t\tconst mutation = generator.getPersistMutation()\n\n\t\t\t\t\t\tif (mutation === undefined) {\n\t\t\t\t\t\t\tthis.dirtinessTracker.reset() // TODO This ideally shouldn't be necessary but given the current limitations, this makes for better UX.\n\t\t\t\t\t\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\t\t\t\tsuccessType: 'nothingToPersist',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\t\t\t\t\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\ttype: 'nothingToPersist',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst mutationResponse: MutationRequestResponse = await this.contentApiClient.sendRequest(mutation, {\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t})\n\t\t\t\t\t\tconst mutationData = mutationResponse.data?.transaction ?? {}\n\t\t\t\t\t\tconst aliases = Object.keys(mutationData)\n\t\t\t\t\t\tif (!mutationResponse.data) {\n\t\t\t\t\t\t\tthrow {\n\t\t\t\t\t\t\t\terrors: mutationData.errors,\n\t\t\t\t\t\t\t\ttype: 'invalidResponse',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else if (aliases.every(item => mutationData[item].ok)) {\n\t\t\t\t\t\t\tconst persistedEntityIds = aliases.map(alias => mutationData[alias].node?.id).filter(id => id !== undefined)\n\t\t\t\t\t\t\tconst result: SuccessfulPersistResult = {\n\t\t\t\t\t\t\t\ttype: 'justSuccess',\n\t\t\t\t\t\t\t\tpersistedEntityIds,\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tawait this.eventManager.asyncTransaction(async () => {\n\t\t\t\t\t\t\t\t\tthis.resetTreeAfterSuccessfulPersist()\n\t\t\t\t\t\t\t\t\tthis.treeAugmenter.updatePersistedData(\n\t\t\t\t\t\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\t\t\t\t\t\tObject.entries(mutationData).map(([placeholderName, subTreeResponse]) => [\n\t\t\t\t\t\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t\t\t\t\t\tsubTreeResponse.node,\n\t\t\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t\t\t\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\t\t\t\t\t\tsuccessType: result.type,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\t\t\t\t\t\t\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\n\t\t\t\t\t\t\t\t\tthis.treeAugmenter.resetCreatingSubTrees()\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\t\tconsole.error(e)\n\t\t\t\t\t\t\t\tconst resultWithError = {\n\t\t\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\t\t\tafterPersistError: e,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tthis.onPersistSuccess(resultWithError)\n\t\t\t\t\t\t\t\treturn resultWithError\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthis.onPersistSuccess(result)\n\t\t\t\t\t\t\treturn result\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(mutationData))\n\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistError(persistErrorOptions)\n\t\t\t\t\t\t\tawait onPersistError?.(persistErrorOptions)\n\t\t\t\t\t\t\tif (shouldTryAgain) {\n\t\t\t\t\t\t\t\tif (proposedBackOffs.length) {\n\t\t\t\t\t\t\t\t\tconst geometricMean = Math.round(\n\t\t\t\t\t\t\t\t\t\tMath.pow(\n\t\t\t\t\t\t\t\t\t\t\tproposedBackOffs.reduce((a, b) => a * b, 1),\n\t\t\t\t\t\t\t\t\t\t\t1 / proposedBackOffs.length,\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tawait new Promise(resolve => setTimeout(resolve, geometricMean))\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow {\n\t\t\t\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// Max attempts exceeded\n\t\t\t\t\t// TODO fire persist error\n\t\t\t\t\tthrow {\n\t\t\t\t\t\ttype: 'givenUp',\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t})\n\t}\n\n\tprivate resolvedOnUpdate = ({ isMutating }: UpdateMetadata) => {\n\t\tthis.onUpdate(new TreeRootAccessor(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations))\n\t}\n\n\t// This is currently useless but potentially future-compatible\n\t// private readonly addTreeRootEventListener: TreeRootAccessor.AddTreeRootEventListener = this.getAddEventListener(\n\t// \tthis.treeRootListeners,\n\t// )\n\n\tprivate pendingExtensions: Set<{\n\t\tmarkerTreeRoot: MarkerTreeRoot\n\t\tnewFragment: ReactNode\n\t\tnewTreeRootId: TreeRootId | undefined\n\t\toptions: ExtendTreeOptions\n\t\treject: () => void\n\t\tresolve: (newRootId: TreeRootId | undefined) => void\n\t}> = new Set()\n\n\tpublic async extendTree(newFragment: ReactNode, options: ExtendTreeOptions = {}): Promise<TreeRootId | undefined> {\n\t\tif (options.signal?.aborted) {\n\t\t\treturn Promise.reject(DataBindingExtendAborted)\n\t\t}\n\t\tconst markerTreeRoot = new MarkerTreeGenerator(newFragment, options.environment ?? this.environment).generate()\n\n\t\tif (this.treeStore.effectivelyHasTreeRoot(markerTreeRoot)) {\n\t\t\t// This isn't perfectly accurate as theoretically, we could already have all the data necessary but this\n\t\t\t// could still be false.\n\n\t\t\tconst schema = await this.getOrLoadSchema()\n\t\t\tthis.treeStore.setSchema(schema)\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t// For most trees, checking this against the schema should be unnecessary since if we already effectively\n\t\t\t\t// have this tree root, then assuming everything we already have is valid, this should match the schema as well.\n\t\t\t\t// However, we might be dealing with an isCreating tree root which is completely new. Also, we can just lean\n\t\t\t\t// towards the safe side since developer machines can generally handle the potentially unnecessary check anyway.\n\t\t\t\tSchemaValidator.assertTreeValid(schema, markerTreeRoot)\n\t\t\t}\n\n\t\t\treturn this.eventManager.syncOperation(() => {\n\t\t\t\tconst newTreeRootId = this.getNewTreeRootId()\n\t\t\t\tthis.treeAugmenter.extendTreeStates(newTreeRootId, markerTreeRoot)\n\t\t\t\treturn newTreeRootId\n\t\t\t})\n\t\t}\n\n\t\treturn await new Promise((resolve, reject) => {\n\t\t\tthis.pendingExtensions.add({\n\t\t\t\tmarkerTreeRoot,\n\t\t\t\tnewFragment,\n\t\t\t\tnewTreeRootId: this.getNewTreeRootId(),\n\t\t\t\toptions,\n\t\t\t\treject: () => reject(DataBindingExtendAborted),\n\t\t\t\tresolve,\n\t\t\t})\n\t\t\tconst pendingExtensionsCount = this.pendingExtensions.size\n\n\t\t\tPromise.resolve().then(() => {\n\t\t\t\tif (pendingExtensionsCount < this.pendingExtensions.size) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.flushBatchedTreeExtensions()\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async flushBatchedTreeExtensions() {\n\t\t// This is an async operation so we just take whatever pendingExtensions there are now and let any new ones\n\t\t// accumulate in an empty set.\n\t\tconst pendingExtensions = Array.from(this.pendingExtensions).filter(extension => {\n\t\t\tif (extension.options.signal?.aborted) {\n\t\t\t\textension.reject()\n\t\t\t\treturn false\n\t\t\t}\n\t\t\treturn true\n\t\t})\n\t\tthis.pendingExtensions.clear()\n\n\t\tconst aggregateMarkerTreeRoot = pendingExtensions.reduce<MarkerTreeRoot | undefined>(\n\t\t\t(previousValue, currentValue) => {\n\t\t\t\tif (previousValue === undefined) {\n\t\t\t\t\treturn currentValue.markerTreeRoot\n\t\t\t\t}\n\t\t\t\treturn MarkerMerger.mergeMarkerTreeRoots(previousValue, currentValue.markerTreeRoot)\n\t\t\t},\n\t\t\tundefined,\n\t\t)\n\n\t\tif (aggregateMarkerTreeRoot === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tconst aggregateSignal = getCombinedSignal(pendingExtensions.map(extension => extension.options.signal))\n\n\t\t// Even if we don't have a schema yet, we'll still optimistically fire the request so as to prevent a waterfall\n\t\t// in the most likely case that things will go fine and the query does match the schema. If it doesn't, then we\n\t\t// just get a \"400 Bad Request\" but that's not enough to make us delay the happy path.\n\t\tconst [aggregatePersistedData, schema] = await Promise.all([\n\t\t\tthis.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal),\n\t\t\tthis.getOrLoadSchema(),\n\t\t])\n\t\tthis.treeStore.setSchema(schema)\n\n\t\tif (import.meta.env.DEV) {\n\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\tSchemaValidator.assertTreeValid(schema, extension.markerTreeRoot)\n\t\t\t}\n\t\t}\n\n\t\tif (aggregateSignal?.aborted) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.treeAugmenter.extendPersistedData(aggregatePersistedData?.data ?? {})\n\n\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\tthis.treeAugmenter.extendTreeStates(extension.newTreeRootId, extension.markerTreeRoot)\n\t\t\t\textension.resolve(extension.newTreeRootId)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async fetchPersistedData(\n\t\ttree: MarkerTreeRoot,\n\t\tsignal?: AbortSignal,\n\t): Promise<QueryRequestResponse | undefined> {\n\t\tconst queryGenerator = new QueryGenerator(tree)\n\t\tconst query = queryGenerator.getReadQuery()\n\n\t\tlet queryResponse: QueryRequestResponse | undefined = undefined\n\n\t\ttry {\n\t\t\tqueryResponse =\n\t\t\t\tquery === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: await this.contentApiClient.sendRequest(query, {\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t })\n\t\t} catch (metadata) {\n\t\t\tif (metadata.name === 'AbortError') {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.onError(metadataToRequestError(metadata as GraphQlClientFailedRequestMetadata))\n\t\t}\n\t\treturn queryResponse\n\t}\n\n\tprivate resetTreeAfterSuccessfulPersist() {\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\tthis.dirtinessTracker.reset()\n\n\t\t\tfor (const [, rootState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const state of StateIterator.depthFirstAllNodes(rootState)) {\n\t\t\t\t\tswitch (state.type) {\n\t\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\t\tif (state.hasUnpersistedChanges || state.touchLog?.size) {\n\t\t\t\t\t\t\t\tstate.touchLog?.clear()\n\t\t\t\t\t\t\t\tstate.hasUnpersistedChanges = false\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedRemovals?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedRemovals?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedHasOneDeletions?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedHasOneDeletions?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tassertNever(state)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate getOrLoadSchema(): Schema | Promise<Schema> {\n\t\tconst existing = DataBinding.schemaLoadCache.get(this.contentApiClient.apiUrl)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\n\t\tconst schemaPromise = SchemaLoader.loadSchema(this.contentApiClient, this.config.getValue('maxSchemaLoadAttempts'))\n\t\tschemaPromise.then(schema => {\n\t\t\tDataBinding.schemaLoadCache.set(this.contentApiClient.apiUrl, schema)\n\t\t})\n\t\tDataBinding.schemaLoadCache.set(this.contentApiClient.apiUrl, schemaPromise)\n\t\treturn schemaPromise\n\t}\n\n\tprivate static getNextTreeRootIdSeed = (() => {\n\t\tlet seed = 1\n\t\treturn () => seed++\n\t})()\n\n\tprivate getNewTreeRootId() {\n\t\t// TODO this is an awful, awful hack.\n\t\t// TODO the particular shape of the alias is relied on in MutationAlias. If you change this, change it there too.\n\t\treturn this.treeStore.markerTrees.size === 0\n\t\t\t? undefined\n\t\t\t: `${generateEnumerabilityPreventingEntropy()}-${DataBinding.getNextTreeRootIdSeed()}`\n\t}\n}\n\nexport const DataBindingExtendAborted = Symbol('aborted')\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCO,2BAAkB;AAAA,EAoBjB,YACW,kBACA,iBACA,iBACA,aACA,UACA,SACA,kBAChB;AAzBe;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AA6LT,4CAAmB,CAAC,EAAE,iBAAiC;AACzD,WAAA,SAAS,IAAI,iBAAiB,KAAK,iBAAiB,cAAc,YAAY,KAAK,iBAAiB,CAAC;AAAA,IAAA;AAQnG,iEAOC;AApMS,SAAA,mBAAA;AACA,SAAA,kBAAA;AACA,SAAA,kBAAA;AACA,SAAA,cAAA;AACA,SAAA,WAAA;AACA,SAAA,UAAA;AACA,SAAA,mBAAA;AAEZ,SAAA,SAAS,IAAI;AACb,SAAA,YAAY,IAAI;AACrB,SAAK,sBAAsB,0BAA0B,aAAa,KAAK,SAAS;AAChF,SAAK,2BAA2B;AAAA,SAC5B,KAAK;AAAA,MACR,eAAe;AAAA,MACf,cAAc;AAAA,MACd,cAAc;AAAA,IAAA;AAEV,SAAA,mBAAmB,IAAI;AAC5B,SAAK,eAAe,IAAI,aACvB,KAAK,0BACL,KAAK,qBACL,KAAK,QACL,KAAK,kBACL,KAAK,kBACL,KAAK,SACN;AACA,SAAK,uBAAuB,IAAI,qBAAqB,KAAK,cAAc,KAA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AAa,qBAAqB;AAAA,cAChF;AACA;AAAA,iBACI,eAAe;AACnB,kBAAI,MAAM,0BAA0B,KAAK,MAAM,wBAAwB,MAAM;AAC5E,sBAAM,0BAA0B;AAChC,sBAAM,wBAAwB;AAC9B,qBAAK,aAAa,oBAAoB,OAAO,aAAa,qBAAqB;AAAA,cAChF;AACA;AAAA,YACD;AAAA;AAEC,0BAAiB;AAAA;AAAA,QAEpB;AAAA,MACD;AAAA,IAAA,CACA;AAAA,EACF;AAAA,EAEQ,kBAA4C;AACnD,UAAM,WAAW,aAAY,gBAAgB,IAAI,KAAK,iBAAiB,MAAM;AAC7E,QAAI,aAAa,QAAW;AACpB,aAAA;AAAA,IACR;AAEM,UAAA,gBAAgB,aAAa,WAAW,KAAK,kBAAkB,KAAK,OAAO,SAAS,uBAAuB,CAAC;AAClH,kBAAc,KAAK,CAAU,WAAA;AAC5B,mBAAY,gBAAgB,IAAI,KAAK,iBAAiB,QAAQ,MAAM;AAAA,IAAA,CACpE;AACD,iBAAY,gBAAgB,IAAI,KAAK,iBAAiB,QAAQ,aAAa;AACpE,WAAA;AAAA,EACR;AAAA,EAOQ,mBAAmB;AAGnB,WAAA,KAAK,UAAU,YAAY,SAAS,IACxC,SACA,GAAG,uCAA4C,KAAA,aAAY,sBAAsB;AAAA,EACrF;AACD;AA7ZO;AACkB,cADlB,aACkB,uCAA6D;AAgZtE,cAjZT,aAiZS,yBAA+B,OAAA;AAC7C,MAAI,OAAO;AACX,SAAO,MAAM;AAAA;AAYF,MAAA,2BAA2B,OAAO,SAAS;;"}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
1
7
|
class DirtinessTracker {
|
|
2
|
-
|
|
3
|
-
|
|
8
|
+
constructor() {
|
|
9
|
+
__publicField(this, "changesCount", 0);
|
|
10
|
+
__publicField(this, "totalChangesCount", 0);
|
|
11
|
+
}
|
|
4
12
|
getChangesCount() {
|
|
5
13
|
return this.changesCount;
|
|
6
14
|
}
|
|
@@ -24,6 +32,5 @@ class DirtinessTracker {
|
|
|
24
32
|
this.changesCount += delta;
|
|
25
33
|
}
|
|
26
34
|
}
|
|
27
|
-
|
|
28
35
|
export { DirtinessTracker };
|
|
29
36
|
//# sourceMappingURL=DirtinessTracker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DirtinessTracker.js","sources":["../../../src/core/DirtinessTracker.ts"],"sourcesContent":["export class DirtinessTracker {\n\tprivate changesCount = 0\n\tprivate totalChangesCount = 0\n\n\tpublic getChangesCount() {\n\t\treturn this.changesCount\n\t}\n\n\tpublic getTotalChangesCount() {\n\t\treturn this.totalChangesCount\n\t}\n\n\tpublic hasChanges() {\n\t\treturn this.changesCount > 0\n\t}\n\n\tpublic reset() {\n\t\tthis.changesCount = 0\n\t}\n\n\tpublic increment() {\n\t\tthis.totalChangesCount++\n\t\tthis.changesCount++\n\t}\n\n\tpublic decrement() {\n\t\tthis.changesCount--\n\t}\n\n\tpublic increaseBy(delta: number) {\n\t\tthis.changesCount += delta\n\t}\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DirtinessTracker.js","sources":["../../../src/core/DirtinessTracker.ts"],"sourcesContent":["export class DirtinessTracker {\n\tprivate changesCount = 0\n\tprivate totalChangesCount = 0\n\n\tpublic getChangesCount() {\n\t\treturn this.changesCount\n\t}\n\n\tpublic getTotalChangesCount() {\n\t\treturn this.totalChangesCount\n\t}\n\n\tpublic hasChanges() {\n\t\treturn this.changesCount > 0\n\t}\n\n\tpublic reset() {\n\t\tthis.changesCount = 0\n\t}\n\n\tpublic increment() {\n\t\tthis.totalChangesCount++\n\t\tthis.changesCount++\n\t}\n\n\tpublic decrement() {\n\t\tthis.changesCount--\n\t}\n\n\tpublic increaseBy(delta: number) {\n\t\tthis.changesCount += delta\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAAO,MAAM,iBAAiB;AAAA,EAAvB;AACE,wCAAe;AACf,6CAAoB;AAAA;AAAA,EAErB,kBAAkB;AACxB,WAAO,KAAK;AAAA,EACb;AAAA,EAEO,uBAAuB;AAC7B,WAAO,KAAK;AAAA,EACb;AAAA,EAEO,aAAa;AACnB,WAAO,KAAK,eAAe;AAAA,EAC5B;AAAA,EAEO,QAAQ;AACd,SAAK,eAAe;AAAA,EACrB;AAAA,EAEO,YAAY;AACb,SAAA;AACA,SAAA;AAAA,EACN;AAAA,EAEO,YAAY;AACb,SAAA;AAAA,EACN;AAAA,EAEO,WAAW,OAAe;AAChC,SAAK,gBAAgB;AAAA,EACtB;AACD;;"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { MutationAlias } from
|
|
2
|
-
import { mutationOperationSubTreeType } from
|
|
3
|
-
import { assertNever } from
|
|
4
|
-
|
|
1
|
+
import { MutationAlias } from "./requestAliases/MutationAlias.js";
|
|
2
|
+
import { mutationOperationSubTreeType } from "./requestAliases/mutationOperationSubTreeType.js";
|
|
3
|
+
import { assertNever } from "../utils/assertNever.js";
|
|
5
4
|
class ErrorsPreprocessor {
|
|
6
5
|
constructor(requestResponse) {
|
|
7
6
|
this.requestResponse = requestResponse;
|
|
@@ -174,6 +173,5 @@ class ErrorsPreprocessor {
|
|
|
174
173
|
}
|
|
175
174
|
ErrorsPreprocessor2.ErrorsPreprocessorError = ErrorsPreprocessorError;
|
|
176
175
|
})(ErrorsPreprocessor || (ErrorsPreprocessor = {}));
|
|
177
|
-
|
|
178
176
|
export { ErrorsPreprocessor };
|
|
179
177
|
//# sourceMappingURL=ErrorsPreprocessor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorsPreprocessor.js","sources":["../../../src/core/ErrorsPreprocessor.ts"],"sourcesContent":["import type { ErrorAccessor } from '../accessors'\nimport type { ExecutionError, MutationDataResponse, MutationResponse, ValidationError } from '../accessorTree'\nimport type { PlaceholderName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport { MutationAlias, mutationOperationSubTreeType } from './requestAliases'\n\nclass ErrorsPreprocessor {\n\tpublic constructor(private readonly requestResponse: MutationDataResponse) {}\n\n\tpublic preprocess(): ErrorsPreprocessor.ErrorTreeRoot {\n\t\tconst treeRoot: ErrorsPreprocessor.ErrorTreeRoot = new Map()\n\n\t\tif (this.requestResponse === undefined) {\n\t\t\treturn treeRoot\n\t\t}\n\n\t\tfor (const mutationAlias in this.requestResponse) {\n\t\t\tconst mutationResponse = this.requestResponse[mutationAlias]\n\t\t\tconst processedResponse = this.processMutationResponse(mutationResponse)\n\n\t\t\tif (processedResponse === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst operation = MutationAlias.decodeTopLevel(mutationAlias)\n\n\t\t\tif (operation === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst { subTreeType, subTreePlaceholder, entityId } = operation\n\n\t\t\tif (subTreeType === mutationOperationSubTreeType.singleEntity) {\n\t\t\t\tif (treeRoot.has(subTreePlaceholder)) {\n\t\t\t\t\treturn this.rejectCorruptData()\n\t\t\t\t}\n\t\t\t\ttreeRoot.set(subTreePlaceholder, processedResponse)\n\t\t\t} else if (subTreeType === mutationOperationSubTreeType.entityList) {\n\t\t\t\tconst child = treeRoot.get(subTreePlaceholder)\n\n\t\t\t\tif (child === undefined) {\n\t\t\t\t\ttreeRoot.set(subTreePlaceholder, {\n\t\t\t\t\t\tnodeType: 'iNode',\n\t\t\t\t\t\tchildren: new Map([[entityId, processedResponse]]),\n\t\t\t\t\t\tvalidation: [],\n\t\t\t\t\t\texecution: [],\n\t\t\t\t\t})\n\t\t\t\t} else if (child.nodeType === 'iNode') {\n\t\t\t\t\tchild.children.set(entityId, processedResponse)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn assertNever(subTreeType)\n\t\t\t}\n\t\t}\n\t\treturn treeRoot\n\t}\n\n\tprivate processMutationResponse(mutationResponse: MutationResponse): ErrorsPreprocessor.ErrorNode | undefined {\n\t\tif (mutationResponse.ok && mutationResponse.validation?.valid && mutationResponse.errors.length === 0) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (mutationResponse.validation?.errors.length) {\n\t\t\treturn this.getErrorNode(mutationResponse.validation?.errors)\n\t\t}\n\t\tif (mutationResponse.errors.length) {\n\t\t\treturn this.getErrorNode(mutationResponse.errors)\n\t\t}\n\t\treturn undefined\n\t}\n\n\tprivate getErrorNode(errors: ValidationError[] | ExecutionError[]): ErrorsPreprocessor.ErrorNode {\n\t\tconst [head, ...tail] = errors\n\n\t\tlet rootNode = this.getRootNode(head)\n\n\t\terrorLoop: for (const error of tail) {\n\t\t\tlet currentNode = rootNode\n\n\t\t\tfor (let i = 0, pathLength = error.path.length; i < pathLength; i++) {\n\t\t\t\tconst pathNode = error.path[i]\n\n\t\t\t\tif (currentNode.nodeType === 'leaf') {\n\t\t\t\t\t(currentNode as any as ErrorsPreprocessor.ErrorINode).nodeType = 'iNode'\n\t\t\t\t\t;(currentNode as any as ErrorsPreprocessor.ErrorINode).children = new Map()\n\t\t\t\t}\n\n\t\t\t\tif (pathNode.__typename === '_FieldPathFragment') {\n\t\t\t\t\tif (currentNode.nodeType === 'iNode') {\n\t\t\t\t\t\tlet alias = pathNode.field\n\t\t\t\t\t\tlet nextIndex = i + 1\n\t\t\t\t\t\tif (nextIndex in error.path) {\n\t\t\t\t\t\t\tconst nextPathNode = error.path[nextIndex]\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tnextPathNode.__typename === '_IndexPathFragment' &&\n\t\t\t\t\t\t\t\ttypeof nextPathNode.alias === 'string' &&\n\t\t\t\t\t\t\t\tnextPathNode.alias.startsWith(pathNode.field)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t// We're dealing with a reduced hasMany relation.\n\t\t\t\t\t\t\t\ti++\n\t\t\t\t\t\t\t\tnextIndex++\n\t\t\t\t\t\t\t\talias = nextPathNode.alias\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!(alias in currentNode.children)) {\n\t\t\t\t\t\t\tcurrentNode.children.set(alias, this.getRootNode(error, nextIndex))\n\t\t\t\t\t\t\tif (nextIndex <= error.path.length) {\n\t\t\t\t\t\t\t\t// This path has been handled by getRootNode\n\t\t\t\t\t\t\t\tcontinue errorLoop\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurrentNode = currentNode.children.get(alias)!\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.rejectCorruptData()\n\t\t\t\t\t}\n\t\t\t\t} else if (pathNode.__typename === '_IndexPathFragment') {\n\t\t\t\t\tif (currentNode.nodeType === 'iNode') {\n\t\t\t\t\t\tconst alias = pathNode.alias\n\n\t\t\t\t\t\tif (alias === null) {\n\t\t\t\t\t\t\tthrow new ErrorsPreprocessor.ErrorsPreprocessorError(\n\t\t\t\t\t\t\t\t`Corrupt data: undefined alias for node with index ${pathNode.index}.`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst entityId = MutationAlias.decodeEntityId(alias)\n\n\t\t\t\t\t\tif (!(entityId in currentNode.children)) {\n\t\t\t\t\t\t\tcurrentNode.children.set(entityId, this.getRootNode(error, i + 1))\n\t\t\t\t\t\t\tif (i + 1 <= error.path.length) {\n\t\t\t\t\t\t\t\t// This path has been handled by getRootNode\n\t\t\t\t\t\t\t\tcontinue errorLoop\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurrentNode = currentNode.children.get(entityId)!\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.rejectCorruptData()\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(pathNode)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (this.isExecutionError(error)) {\n\t\t\t\tcurrentNode.execution.push({ type: 'execution', code: error.type, developerMessage: error.message })\n\t\t\t} else {\n\t\t\t\tcurrentNode.validation.push(this.createValidationError(error.message.text))\n\t\t\t}\n\t\t}\n\n\t\treturn rootNode\n\t}\n\n\tprivate getRootNode(error: ValidationError | ExecutionError, startIndex: number = 0): ErrorsPreprocessor.ErrorNode {\n\t\tlet rootNode: ErrorsPreprocessor.ErrorNode = {\n\t\t\tvalidation: this.isExecutionError(error) ? [] : [this.createValidationError(error.message.text)],\n\t\t\texecution: this.isExecutionError(error) ? [{ type: 'execution', code: error.type, developerMessage: error.message }] : [],\n\t\t\tnodeType: 'leaf',\n\t\t}\n\n\t\tfor (let i = error.path.length - 1; i >= startIndex; i--) {\n\t\t\tconst pathNode = error.path[i]\n\t\t\tif (pathNode.__typename === '_FieldPathFragment') {\n\t\t\t\trootNode = {\n\t\t\t\t\tvalidation: [],\n\t\t\t\t\texecution: [],\n\t\t\t\t\tnodeType: 'iNode',\n\t\t\t\t\tchildren: new Map([[pathNode.field, rootNode]]),\n\t\t\t\t}\n\t\t\t} else if (pathNode.__typename === '_IndexPathFragment') {\n\t\t\t\tconst alias = pathNode.alias\n\n\t\t\t\tif (alias === null) {\n\t\t\t\t\tthrow new ErrorsPreprocessor.ErrorsPreprocessorError(\n\t\t\t\t\t\t`Corrupt data: undefined alias for node with index ${pathNode.index}.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\trootNode = {\n\t\t\t\t\tvalidation: [],\n\t\t\t\t\texecution: [],\n\t\t\t\t\tnodeType: 'iNode',\n\t\t\t\t\tchildren: new Map([[MutationAlias.decodeEntityId(alias), rootNode]]),\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tassertNever(pathNode)\n\t\t\t}\n\t\t}\n\n\t\treturn rootNode\n\t}\n\n\tprivate createValidationError(message: string): ErrorAccessor.ValidationError {\n\t\tif (message === 'Field is required') {\n\t\t\t// TODO this is just awful. Validation errors currently don't have error codes which makes it more difficult\n\t\t\t// \tto translate the error messages. This is the most common such error, and so we just make up a code\n\t\t\t// \tin order to facilitate error handling further downstream.\n\t\t\treturn {\n\t\t\t\ttype: 'validation',\n\t\t\t\tcode: 'fieldRequired',\n\t\t\t\tmessage,\n\t\t\t}\n\t\t}\n\t\treturn { type: 'validation', message, code: undefined }\n\t}\n\n\tprivate isExecutionError(error: ValidationError | ExecutionError): error is ExecutionError {\n\t\treturn 'type' in error\n\t}\n\n\tprivate rejectCorruptData(): never {\n\t\tthrow new ErrorsPreprocessor.ErrorsPreprocessorError(\n\t\t\t'Received corrupted data: a node cannot be simultaneously field-indexed and path-indexed.',\n\t\t)\n\t}\n}\n\nnamespace ErrorsPreprocessor {\n\texport interface BaseErrorNode {\n\t\tvalidation: ErrorAccessor.ValidationError[]\n\t\texecution: ErrorAccessor.ExecutionError[]\n\t}\n\n\texport interface LeafErrorNode extends BaseErrorNode {\n\t\tnodeType: 'leaf'\n\t}\n\n\texport interface ErrorINode extends BaseErrorNode {\n\t\tnodeType: 'iNode'\n\t\tchildren: Map<string, ErrorNode>\n\t}\n\n\texport type ErrorNode = ErrorINode | LeafErrorNode\n\n\texport type ErrorTreeRoot = Map<PlaceholderName, ErrorNode>\n\n\texport class ErrorsPreprocessorError extends Error {}\n}\n\nexport { ErrorsPreprocessor }\n"],"names":[],"mappings":";;;;AAMA,yBAAyB;AAAA,EACjB,YAA6B,iBAAuC;AAAvC;AAAA;AAAA,EAE7B,aAA+C;AACrD,UAAM,+BAAiD;AAEvD,QAAI,KAAK,oBAAoB,QAAW;AACvC,aAAO;AAAA;AAGR,eAAW,iBAAiB,KAAK,iBAAiB;AACjD,YAAM,mBAAmB,KAAK,gBAAgB;AAC9C,YAAM,oBAAoB,KAAK,wBAAwB;AAEvD,UAAI,sBAAsB,QAAW;AACpC;AAAA;AAGD,YAAM,YAAY,cAAc,eAAe;AAE/C,UAAI,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;AAAA,MAC1F,WAAW,KAAK,iBAAiB,SAAS,CAAC,EAAE,MAAM,aAAa,MAAM,MAAM,MAAM,kBAAkB,MAAM,aAAa;AAAA,MACvH,UAAU;AAAA;AAGX,aAAS,IAAI,MAAM,KAAK,SAAS,GAAG,KAAK,YAAY,KAAK;AACzD,YAAM,WAAW,MAAM,KAAK;AAC5B,UAAI,SAAS,eAAe,sBAAsB;AACjD,mBAAW;AAAA,UACV,YAAY;AAAA,UACZ,WAAW;AAAA,UACX,UAAU;AAAA,UACV,8BAAc,IAAI,CAAC,CAAC,SAAS,OAAO;AAAA;AAAA,iBAE3B,SAAS,eAAe,sBAAsB;AACxD,cAAM,QAAQ,SAAS;AAEvB,YAAI,UAAU,MAAM;AACnB,gBAAM,IAAI,mBAAmB,wBAC5B,qDAAqD,SAAS;AAAA;AAIhE,mBAAW;AAAA,UACV,YAAY;AAAA,UACZ,WAAW;AAAA,UACX,UAAU;AAAA,UACV,8BAAc,IAAI,CAAC,CAAC,cAAc,eAAe,QAAQ;AAAA;AAAA,aAEpD;AACN;AAAY;AAAA;AAId,WAAO;AAAA;AAAA,EAGA,sBAAsB,SAAgD;AAC7E,QAAI,YAAY,qBAAqB;AAIpC,aAAO;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,QACN;AAAA;AAAA;AAGF,WAAO,EAAE,MAAM,cAAc,SAAS,MAAM;AAAA;AAAA,EAGrC,iBAAiB,OAAkE;AAC1F,WAAO,UAAU;AAAA;AAAA,EAGV,oBAA2B;AAClC,UAAM,IAAI,mBAAmB,wBAC5B;AAAA;AAAA;AAKH,EAAU,wBAAV;AAmBQ,wCAAsC,MAAM;AAAA;AAA5C,sBAAM;AAAA,GAnBJ;;;;"}
|
|
1
|
+
{"version":3,"file":"ErrorsPreprocessor.js","sources":["../../../src/core/ErrorsPreprocessor.ts"],"sourcesContent":["import type { ErrorAccessor } from '../accessors'\nimport type { ExecutionError, MutationDataResponse, MutationResponse, ValidationError } from '../accessorTree'\nimport type { PlaceholderName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport { MutationAlias, mutationOperationSubTreeType } from './requestAliases'\n\nclass ErrorsPreprocessor {\n\tpublic constructor(private readonly requestResponse: MutationDataResponse) {}\n\n\tpublic preprocess(): ErrorsPreprocessor.ErrorTreeRoot {\n\t\tconst treeRoot: ErrorsPreprocessor.ErrorTreeRoot = new Map()\n\n\t\tif (this.requestResponse === undefined) {\n\t\t\treturn treeRoot\n\t\t}\n\n\t\tfor (const mutationAlias in this.requestResponse) {\n\t\t\tconst mutationResponse = this.requestResponse[mutationAlias]\n\t\t\tconst processedResponse = this.processMutationResponse(mutationResponse)\n\n\t\t\tif (processedResponse === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst operation = MutationAlias.decodeTopLevel(mutationAlias)\n\n\t\t\tif (operation === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst { subTreeType, subTreePlaceholder, entityId } = operation\n\n\t\t\tif (subTreeType === mutationOperationSubTreeType.singleEntity) {\n\t\t\t\tif (treeRoot.has(subTreePlaceholder)) {\n\t\t\t\t\treturn this.rejectCorruptData()\n\t\t\t\t}\n\t\t\t\ttreeRoot.set(subTreePlaceholder, processedResponse)\n\t\t\t} else if (subTreeType === mutationOperationSubTreeType.entityList) {\n\t\t\t\tconst child = treeRoot.get(subTreePlaceholder)\n\n\t\t\t\tif (child === undefined) {\n\t\t\t\t\ttreeRoot.set(subTreePlaceholder, {\n\t\t\t\t\t\tnodeType: 'iNode',\n\t\t\t\t\t\tchildren: new Map([[entityId, processedResponse]]),\n\t\t\t\t\t\tvalidation: [],\n\t\t\t\t\t\texecution: [],\n\t\t\t\t\t})\n\t\t\t\t} else if (child.nodeType === 'iNode') {\n\t\t\t\t\tchild.children.set(entityId, processedResponse)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn assertNever(subTreeType)\n\t\t\t}\n\t\t}\n\t\treturn treeRoot\n\t}\n\n\tprivate processMutationResponse(mutationResponse: MutationResponse): ErrorsPreprocessor.ErrorNode | undefined {\n\t\tif (mutationResponse.ok && mutationResponse.validation?.valid && mutationResponse.errors.length === 0) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (mutationResponse.validation?.errors.length) {\n\t\t\treturn this.getErrorNode(mutationResponse.validation?.errors)\n\t\t}\n\t\tif (mutationResponse.errors.length) {\n\t\t\treturn this.getErrorNode(mutationResponse.errors)\n\t\t}\n\t\treturn undefined\n\t}\n\n\tprivate getErrorNode(errors: ValidationError[] | ExecutionError[]): ErrorsPreprocessor.ErrorNode {\n\t\tconst [head, ...tail] = errors\n\n\t\tlet rootNode = this.getRootNode(head)\n\n\t\terrorLoop: for (const error of tail) {\n\t\t\tlet currentNode = rootNode\n\n\t\t\tfor (let i = 0, pathLength = error.path.length; i < pathLength; i++) {\n\t\t\t\tconst pathNode = error.path[i]\n\n\t\t\t\tif (currentNode.nodeType === 'leaf') {\n\t\t\t\t\t(currentNode as any as ErrorsPreprocessor.ErrorINode).nodeType = 'iNode'\n\t\t\t\t\t;(currentNode as any as ErrorsPreprocessor.ErrorINode).children = new Map()\n\t\t\t\t}\n\n\t\t\t\tif (pathNode.__typename === '_FieldPathFragment') {\n\t\t\t\t\tif (currentNode.nodeType === 'iNode') {\n\t\t\t\t\t\tlet alias = pathNode.field\n\t\t\t\t\t\tlet nextIndex = i + 1\n\t\t\t\t\t\tif (nextIndex in error.path) {\n\t\t\t\t\t\t\tconst nextPathNode = error.path[nextIndex]\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tnextPathNode.__typename === '_IndexPathFragment' &&\n\t\t\t\t\t\t\t\ttypeof nextPathNode.alias === 'string' &&\n\t\t\t\t\t\t\t\tnextPathNode.alias.startsWith(pathNode.field)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t// We're dealing with a reduced hasMany relation.\n\t\t\t\t\t\t\t\ti++\n\t\t\t\t\t\t\t\tnextIndex++\n\t\t\t\t\t\t\t\talias = nextPathNode.alias\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!(alias in currentNode.children)) {\n\t\t\t\t\t\t\tcurrentNode.children.set(alias, this.getRootNode(error, nextIndex))\n\t\t\t\t\t\t\tif (nextIndex <= error.path.length) {\n\t\t\t\t\t\t\t\t// This path has been handled by getRootNode\n\t\t\t\t\t\t\t\tcontinue errorLoop\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurrentNode = currentNode.children.get(alias)!\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.rejectCorruptData()\n\t\t\t\t\t}\n\t\t\t\t} else if (pathNode.__typename === '_IndexPathFragment') {\n\t\t\t\t\tif (currentNode.nodeType === 'iNode') {\n\t\t\t\t\t\tconst alias = pathNode.alias\n\n\t\t\t\t\t\tif (alias === null) {\n\t\t\t\t\t\t\tthrow new ErrorsPreprocessor.ErrorsPreprocessorError(\n\t\t\t\t\t\t\t\t`Corrupt data: undefined alias for node with index ${pathNode.index}.`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst entityId = MutationAlias.decodeEntityId(alias)\n\n\t\t\t\t\t\tif (!(entityId in currentNode.children)) {\n\t\t\t\t\t\t\tcurrentNode.children.set(entityId, this.getRootNode(error, i + 1))\n\t\t\t\t\t\t\tif (i + 1 <= error.path.length) {\n\t\t\t\t\t\t\t\t// This path has been handled by getRootNode\n\t\t\t\t\t\t\t\tcontinue errorLoop\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurrentNode = currentNode.children.get(entityId)!\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.rejectCorruptData()\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(pathNode)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (this.isExecutionError(error)) {\n\t\t\t\tcurrentNode.execution.push({ type: 'execution', code: error.type, developerMessage: error.message })\n\t\t\t} else {\n\t\t\t\tcurrentNode.validation.push(this.createValidationError(error.message.text))\n\t\t\t}\n\t\t}\n\n\t\treturn rootNode\n\t}\n\n\tprivate getRootNode(error: ValidationError | ExecutionError, startIndex: number = 0): ErrorsPreprocessor.ErrorNode {\n\t\tlet rootNode: ErrorsPreprocessor.ErrorNode = {\n\t\t\tvalidation: this.isExecutionError(error) ? [] : [this.createValidationError(error.message.text)],\n\t\t\texecution: this.isExecutionError(error) ? [{ type: 'execution', code: error.type, developerMessage: error.message }] : [],\n\t\t\tnodeType: 'leaf',\n\t\t}\n\n\t\tfor (let i = error.path.length - 1; i >= startIndex; i--) {\n\t\t\tconst pathNode = error.path[i]\n\t\t\tif (pathNode.__typename === '_FieldPathFragment') {\n\t\t\t\trootNode = {\n\t\t\t\t\tvalidation: [],\n\t\t\t\t\texecution: [],\n\t\t\t\t\tnodeType: 'iNode',\n\t\t\t\t\tchildren: new Map([[pathNode.field, rootNode]]),\n\t\t\t\t}\n\t\t\t} else if (pathNode.__typename === '_IndexPathFragment') {\n\t\t\t\tconst alias = pathNode.alias\n\n\t\t\t\tif (alias === null) {\n\t\t\t\t\tthrow new ErrorsPreprocessor.ErrorsPreprocessorError(\n\t\t\t\t\t\t`Corrupt data: undefined alias for node with index ${pathNode.index}.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\trootNode = {\n\t\t\t\t\tvalidation: [],\n\t\t\t\t\texecution: [],\n\t\t\t\t\tnodeType: 'iNode',\n\t\t\t\t\tchildren: new Map([[MutationAlias.decodeEntityId(alias), rootNode]]),\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tassertNever(pathNode)\n\t\t\t}\n\t\t}\n\n\t\treturn rootNode\n\t}\n\n\tprivate createValidationError(message: string): ErrorAccessor.ValidationError {\n\t\tif (message === 'Field is required') {\n\t\t\t// TODO this is just awful. Validation errors currently don't have error codes which makes it more difficult\n\t\t\t// \tto translate the error messages. This is the most common such error, and so we just make up a code\n\t\t\t// \tin order to facilitate error handling further downstream.\n\t\t\treturn {\n\t\t\t\ttype: 'validation',\n\t\t\t\tcode: 'fieldRequired',\n\t\t\t\tmessage,\n\t\t\t}\n\t\t}\n\t\treturn { type: 'validation', message, code: undefined }\n\t}\n\n\tprivate isExecutionError(error: ValidationError | ExecutionError): error is ExecutionError {\n\t\treturn 'type' in error\n\t}\n\n\tprivate rejectCorruptData(): never {\n\t\tthrow new ErrorsPreprocessor.ErrorsPreprocessorError(\n\t\t\t'Received corrupted data: a node cannot be simultaneously field-indexed and path-indexed.',\n\t\t)\n\t}\n}\n\nnamespace ErrorsPreprocessor {\n\texport interface BaseErrorNode {\n\t\tvalidation: ErrorAccessor.ValidationError[]\n\t\texecution: ErrorAccessor.ExecutionError[]\n\t}\n\n\texport interface LeafErrorNode extends BaseErrorNode {\n\t\tnodeType: 'leaf'\n\t}\n\n\texport interface ErrorINode extends BaseErrorNode {\n\t\tnodeType: 'iNode'\n\t\tchildren: Map<string, ErrorNode>\n\t}\n\n\texport type ErrorNode = ErrorINode | LeafErrorNode\n\n\texport type ErrorTreeRoot = Map<PlaceholderName, ErrorNode>\n\n\texport class ErrorsPreprocessorError extends Error {}\n}\n\nexport { ErrorsPreprocessor }\n"],"names":[],"mappings":";;;AAMA,MAAM,mBAAmB;AAAA,EACjB,YAA6B,iBAAuC;AAAvC,SAAA,kBAAA;AAAA,EAAwC;AAAA,EAErE,aAA+C;AAC/C,UAAA,+BAAiD;AAEnD,QAAA,KAAK,oBAAoB,QAAW;AAChC,aAAA;AAAA,IACR;AAEW,eAAA,iBAAiB,KAAK,iBAAiB;AAC3C,YAAA,mBAAmB,KAAK,gBAAgB;AACxC,YAAA,oBAAoB,KAAK,wBAAwB,gBAAgB;AAEvE,UAAI,sBAAsB,QAAW;AACpC;AAAA,MACD;AAEM,YAAA,YAAY,cAAc,eAAe,aAAa;AAE5D,UAAI,cAAc,QAAW;AAC5B;AAAA,MACD;AAEM,YAAA,EAAE,aAAa,oBAAoB,aAAa;AA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AAI7B,aAAA;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,QACN;AAAA,MAAA;AAAA,IAEF;AACA,WAAO,EAAE,MAAM,cAAc,SAAS,MAAM;EAC7C;AAAA,EAEQ,iBAAiB,OAAkE;AAC1F,WAAO,UAAU;AAAA,EAClB;AAAA,EAEQ,oBAA2B;AAC5B,UAAA,IAAI,mBAAmB,wBAC5B,0FACD;AAAA,EACD;AACD;AAEA,AAAA,EAAU,wBAAV;AAmBQ,QAAM,gCAAgC,MAAM;AAAA,EAAC;AAAvC,sBAAA,0BAAA;AAAA,GAnBJ,sBAAA,sBAAA,CAAA,EAAA;;"}
|
|
@@ -1,11 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import * as ReactDOM from "react-dom";
|
|
8
|
+
import { BindingError } from "../BindingError.js";
|
|
9
|
+
import { getEntityMarker } from "./state/getEntityMarker.js";
|
|
10
|
+
import { StateIterator } from "./state/StateIterator.js";
|
|
11
|
+
import { assertNever } from "../utils/assertNever.js";
|
|
7
12
|
class EventManager {
|
|
8
13
|
constructor(asyncBatchUpdatesOptions, batchUpdatesOptions, config, dirtinessTracker, onUpdate, treeStore) {
|
|
14
|
+
__publicField(this, "transactionDepth", 0);
|
|
15
|
+
__publicField(this, "isFrozenWhileUpdating", false);
|
|
16
|
+
__publicField(this, "isMutating", false);
|
|
17
|
+
__publicField(this, "ongoingPersistOperation");
|
|
18
|
+
__publicField(this, "previousMetadata");
|
|
19
|
+
__publicField(this, "newlyInitializedWithListeners", /* @__PURE__ */ new Set());
|
|
20
|
+
__publicField(this, "pendingWithBeforeUpdate", /* @__PURE__ */ new Set());
|
|
21
|
+
__publicField(this, "rootsWithPendingUpdates", /* @__PURE__ */ new Set());
|
|
9
22
|
this.asyncBatchUpdatesOptions = asyncBatchUpdatesOptions;
|
|
10
23
|
this.batchUpdatesOptions = batchUpdatesOptions;
|
|
11
24
|
this.config = config;
|
|
@@ -13,15 +26,6 @@ class EventManager {
|
|
|
13
26
|
this.onUpdate = onUpdate;
|
|
14
27
|
this.treeStore = treeStore;
|
|
15
28
|
}
|
|
16
|
-
static NO_CHANGES_DIFFERENCE = 0;
|
|
17
|
-
transactionDepth = 0;
|
|
18
|
-
isFrozenWhileUpdating = false;
|
|
19
|
-
isMutating = false;
|
|
20
|
-
ongoingPersistOperation = void 0;
|
|
21
|
-
previousMetadata = void 0;
|
|
22
|
-
newlyInitializedWithListeners = /* @__PURE__ */ new Set();
|
|
23
|
-
pendingWithBeforeUpdate = /* @__PURE__ */ new Set();
|
|
24
|
-
rootsWithPendingUpdates = /* @__PURE__ */ new Set();
|
|
25
29
|
async persistOperation(operation) {
|
|
26
30
|
if (this.transactionDepth > 0) {
|
|
27
31
|
throw new BindingError(`Cannot trigger a persist whilst batching updates!`);
|
|
@@ -408,6 +412,6 @@ class EventManager {
|
|
|
408
412
|
return result;
|
|
409
413
|
}
|
|
410
414
|
}
|
|
411
|
-
|
|
415
|
+
__publicField(EventManager, "NO_CHANGES_DIFFERENCE", 0);
|
|
412
416
|
export { EventManager };
|
|
413
417
|
//# sourceMappingURL=EventManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventManager.js","sources":["../../../src/core/EventManager.ts"],"sourcesContent":["import * as ReactDOM from 'react-dom'\nimport type {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tEntityAccessor,\n\tEntityListAccessor,\n\tFieldAccessor,\n\tPersistErrorOptions,\n\tPersistSuccessOptions,\n} from '../accessors'\nimport type { SuccessfulPersistResult } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { PlaceholderName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport type { Config } from './Config'\nimport type { DirtinessTracker } from './DirtinessTracker'\nimport {\n\tEntityListState,\n\tEntityRealmState,\n\tFieldState,\n\tgetEntityMarker,\n\tRootStateNode,\n\tStateINode,\n\tStateIterator,\n\tStateNode,\n} from './state'\nimport type { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport type { EventListenersStore } from '../treeParameters'\n\nexport class EventManager {\n\tpublic static readonly NO_CHANGES_DIFFERENCE = 0\n\n\tprivate transactionDepth = 0\n\tprivate isFrozenWhileUpdating = false\n\n\t// This should ideally not exists as it should be synonymous to `this.ongoingPersistOperation !== undefined`\n\t// but it makes persist-related promise juggling significantly more straightforward.\n\tprivate isMutating: boolean = false\n\tprivate ongoingPersistOperation: Promise<SuccessfulPersistResult> | undefined = undefined\n\n\tprivate previousMetadata: UpdateMetadata | undefined = undefined\n\n\tprivate newlyInitializedWithListeners: Set<EntityListState | EntityRealmState | FieldState> = new Set()\n\tprivate pendingWithBeforeUpdate: Set<StateNode> = new Set()\n\tprivate rootsWithPendingUpdates: Set<RootStateNode> = new Set()\n\n\tpublic constructor(\n\t\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly config: Config,\n\t\tprivate readonly dirtinessTracker: DirtinessTracker,\n\t\tprivate readonly onUpdate: (metadata: UpdateMetadata) => void,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic async persistOperation(operation: () => Promise<SuccessfulPersistResult>): Promise<SuccessfulPersistResult> {\n\t\tif (this.transactionDepth > 0) {\n\t\t\tthrow new BindingError(`Cannot trigger a persist whilst batching updates!`)\n\t\t}\n\t\tconst ongoingOperation = this.ongoingPersistOperation\n\t\tif (ongoingOperation !== undefined) {\n\t\t\treturn await ongoingOperation\n\t\t}\n\t\treturn await (this.ongoingPersistOperation = new Promise<SuccessfulPersistResult>(async (resolve, reject) => {\n\t\t\tthis.isMutating = true\n\t\t\tthis.flushUpdates() // Let the world know that we're mutating\n\n\t\t\ttry {\n\t\t\t\tresolve(await this.asyncOperation(operation))\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error('PersistError', e)\n\t\t\t\treject(e)\n\t\t\t} finally {\n\t\t\t\tthis.ongoingPersistOperation = undefined\n\t\t\t\tthis.isMutating = false\n\t\t\t\tthis.flushUpdates()\n\t\t\t}\n\t\t}))\n\t}\n\n\tpublic syncTransaction<T>(transaction: () => T) {\n\t\ttry {\n\t\t\tthis.transactionDepth++\n\t\t\treturn transaction()\n\t\t} finally {\n\t\t\tthis.transactionDepth--\n\t\t}\n\t}\n\tpublic syncOperation<T>(operation: () => T) {\n\t\tconst result = this.syncTransaction(operation)\n\t\tthis.flushUpdates()\n\t\treturn result\n\t}\n\n\tpublic async asyncTransaction<T>(transaction: () => Promise<T>): Promise<T> {\n\t\ttry {\n\t\t\tthis.transactionDepth++\n\t\t\treturn await transaction()\n\t\t} finally {\n\t\t\tthis.transactionDepth--\n\t\t}\n\t}\n\tpublic async asyncOperation<T>(operation: () => Promise<T>): Promise<T> {\n\t\tconst result = await this.asyncTransaction(operation)\n\t\tthis.flushUpdates()\n\t\treturn result\n\t}\n\n\tprivate flushUpdates() {\n\t\tif (this.transactionDepth > 0) {\n\t\t\treturn\n\t\t}\n\n\t\tif (this.isFrozenWhileUpdating) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Trying to perform an update while the whole accessor tree is already updating. This is most likely caused ` +\n\t\t\t\t\t`by updating the accessor tree while rendering or from within the 'update' event handler, which is a no-op. ` +\n\t\t\t\t\t`If you wish to mutate the tree in reaction to other changes, use the 'beforeUpdate' event.`,\n\t\t\t)\n\t\t}\n\n\t\tconst newMetadata = this.getNewUpdateMetadata()\n\n\t\tif (!this.shouldFlushUpdates(newMetadata)) {\n\t\t\treturn\n\t\t}\n\n\t\tReactDOM.unstable_batchedUpdates(() => {\n\t\t\tthis.isFrozenWhileUpdating = true\n\t\t\tthis.triggerBeforeFlushEvents()\n\t\t\tthis.onUpdate(newMetadata)\n\t\t\tthis.flushPendingAccessorUpdates(Array.from(this.rootsWithPendingUpdates))\n\n\t\t\tthis.rootsWithPendingUpdates.clear()\n\t\t\tthis.isFrozenWhileUpdating = false\n\t\t\tthis.previousMetadata = newMetadata\n\t\t})\n\t}\n\n\tprivate getNewUpdateMetadata(): UpdateMetadata {\n\t\treturn {\n\t\t\tisMutating: this.isMutating,\n\t\t}\n\t}\n\n\tprivate shouldFlushUpdates(newMetadata: UpdateMetadata): boolean {\n\t\tif (this.transactionDepth > 0) {\n\t\t\treturn false\n\t\t}\n\t\tif (this.previousMetadata === undefined) {\n\t\t\treturn true\n\t\t}\n\t\tif (this.rootsWithPendingUpdates.size) {\n\t\t\treturn true\n\t\t}\n\t\tfor (const key in newMetadata) {\n\t\t\tconst fromPrevious = this.previousMetadata[key as keyof UpdateMetadata]\n\t\t\tconst fromNew = newMetadata[key as keyof UpdateMetadata]\n\n\t\t\tif (!Object.is(fromPrevious, fromNew)) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n\n\tpublic registerNewlyInitialized(newlyInitialized: StateNode) {\n\t\tconst initializeListeners = this.getEventListeners(newlyInitialized, { type: 'initialize' })\n\n\t\tif (initializeListeners === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.newlyInitializedWithListeners.add(newlyInitialized)\n\n\t\tif (this.transactionDepth === 0) {\n\t\t\tthis.triggerOnInitialize()\n\t\t}\n\t}\n\n\tpublic registerUpdatedConnection(parentState: EntityRealmState, placeholderName: PlaceholderName) {\n\t\tif (parentState.fieldsWithPendingConnectionUpdates === undefined) {\n\t\t\tparentState.fieldsWithPendingConnectionUpdates = new Set()\n\t\t}\n\n\t\tconst marker = getEntityMarker(parentState)\n\t\tplaceholders: for (const [fieldName, placeholdersByField] of marker.fields.placeholders) {\n\t\t\tif (typeof placeholdersByField === 'string') {\n\t\t\t\tif (placeholdersByField === placeholderName) {\n\t\t\t\t\tparentState.fieldsWithPendingConnectionUpdates.add(fieldName)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (const placeholderByFieldName of placeholdersByField) {\n\t\t\t\t\tif (placeholderByFieldName === placeholderName) {\n\t\t\t\t\t\tparentState.fieldsWithPendingConnectionUpdates.add(fieldName)\n\t\t\t\t\t\tcontinue placeholders\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic registerJustUpdated(justUpdated: StateNode, changesDelta: number) {\n\t\tconst beforeUpdateListeners = this.getEventListeners(justUpdated, { type: 'beforeUpdate' })\n\t\tif (beforeUpdateListeners !== undefined) {\n\t\t\tthis.pendingWithBeforeUpdate.add(justUpdated)\n\t\t}\n\t\tjustUpdated.accessor = undefined\n\n\t\tswitch (justUpdated.type) {\n\t\t\tcase 'entityRealm':\n\t\t\tcase 'entityList': {\n\t\t\t\tjustUpdated.unpersistedChangesCount += changesDelta\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tif (justUpdated.unpersistedChangesCount < 0) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`We have *JUST* reached a completely invalid state. From now on, anything can (and likely will) ` +\n\t\t\t\t\t\t\t\t`go wrong. This is definitely a bug. Please try to report whatever led to this situation.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst parent = justUpdated.blueprint.parent\n\n\t\t\t\tif (parent === undefined) {\n\t\t\t\t\tthis.rootsWithPendingUpdates.add(justUpdated)\n\t\t\t\t\tthis.dirtinessTracker.increaseBy(changesDelta)\n\t\t\t\t} else {\n\t\t\t\t\tif (!parent.childrenWithPendingUpdates) {\n\t\t\t\t\t\tparent.childrenWithPendingUpdates = new Set()\n\t\t\t\t\t}\n\t\t\t\t\tparent.childrenWithPendingUpdates.add(justUpdated as any)\n\t\t\t\t\tthis.registerJustUpdated(parent, changesDelta)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'field': {\n\t\t\t\tconst parent = justUpdated.parent\n\t\t\t\tif (!parent.childrenWithPendingUpdates) {\n\t\t\t\t\tparent.childrenWithPendingUpdates = new Set()\n\t\t\t\t}\n\t\t\t\tparent.childrenWithPendingUpdates.add(justUpdated as any)\n\t\t\t\tthis.registerJustUpdated(justUpdated.parent, changesDelta)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate flushPendingAccessorUpdates(rootStates: Array<StateINode>) {\n\t\t// It is *CRUCIAL* that this is a BFS so that we update the components in top-down order.\n\t\tconst agenda: StateNode[] = rootStates\n\n\t\tfor (const state of agenda) {\n\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\tconst updateListeners =\n\t\t\t\tstate.type === 'field'\n\t\t\t\t\t? this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\t\t\t\t\t: state.type === 'entityRealm'\n\t\t\t\t\t? this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\t\t\t\t\t: this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\n\t\t\tif (updateListeners !== undefined) {\n\t\t\t\tfor (const handler of updateListeners) {\n\t\t\t\t\t// TS can't quite handle the polymorphism here but this is fine.\n\t\t\t\t\thandler()\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (state.type === 'entityRealm' && state.fieldsWithPendingConnectionUpdates) {\n\t\t\t\tfor (const updatedField of state.fieldsWithPendingConnectionUpdates) {\n\t\t\t\t\tconst listeners = this.getEventListeners(state, { type: 'connectionUpdate', key: updatedField })\n\t\t\t\t\tif (!listeners) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tlistener(state.getAccessor())\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tswitch (state.type) {\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (state.childrenWithPendingUpdates !== undefined) {\n\t\t\t\t\t\tfor (const childState of state.childrenWithPendingUpdates) {\n\t\t\t\t\t\t\tagenda.push(childState)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstate.childrenWithPendingUpdates.clear()\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'field':\n\t\t\t\t\t// Do nothing\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\tassertNever(state)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async triggerAsyncMutatingEvent(eventType: 'beforePersist', options: AsyncBatchUpdatesOptions): Promise<void>\n\tprivate async triggerAsyncMutatingEvent(eventType: 'persistSuccess', options: PersistSuccessOptions): Promise<void>\n\tprivate async triggerAsyncMutatingEvent(\n\t\teventType: 'beforePersist' | 'persistSuccess',\n\t\toptions: AsyncBatchUpdatesOptions | PersistSuccessOptions,\n\t): Promise<void> {\n\t\tawait this.asyncTransaction(async () => {\n\t\t\t// TODO if an entity from here (or its parent) gets deleted, we need to remove stale handlers from here.\n\t\t\tconst callbackQueue: Array<\n\t\t\t\t[\n\t\t\t\t\t// The typings could be nicer but TS…\n\t\t\t\t\tStateINode,\n\t\t\t\t\t(\n\t\t\t\t\t\t| EntityAccessor.EntityEventListenerMap[typeof eventType]\n\t\t\t\t\t\t| EntityListAccessor.EntityListEventListenerMap[typeof eventType]\n\t\t\t\t\t),\n\t\t\t\t]\n\t\t\t> = []\n\n\t\t\tfor (const [, subTreeState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const iNode of StateIterator.depthFirstINodes(subTreeState)) {\n\t\t\t\t\tconst listeners = this.getEventListeners(iNode, { type: eventType }) ?? []\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tcallbackQueue.push([iNode, listener])\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (\n\t\t\t\tlet waterfallDepth = 0;\n\t\t\t\twaterfallDepth < this.config.getValue(`${eventType}SettleLimit` as const);\n\t\t\t\twaterfallDepth++\n\t\t\t) {\n\t\t\t\tconst promiseReturns: Array<\n\t\t\t\t\tPromise<\n\t\t\t\t\t\t| void\n\t\t\t\t\t\t| EntityAccessor.EntityEventListenerMap[typeof eventType]\n\t\t\t\t\t\t| EntityListAccessor.EntityListEventListenerMap[typeof eventType]\n\t\t\t\t\t>\n\t\t\t\t> = []\n\t\t\t\tconst correspondingStates: Array<StateINode> = []\n\n\t\t\t\tif (callbackQueue.length === 0) {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\n\t\t\t\tfor (const [state, callback] of callbackQueue) {\n\t\t\t\t\tcorrespondingStates.push(state)\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = callback(state.getAccessor as any, options as any) // TS can't quite handle this but this is sound.\n\t\t\t\t\t\tif (result instanceof Promise) {\n\t\t\t\t\t\t\tpromiseReturns.push(result)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tpromiseReturns.push(Promise.resolve(result))\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tpromiseReturns.push(Promise.reject(e))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// TODO timeout\n\n\t\t\t\tconst newCallbacks = await this.executeWithoutChanges(eventType, () => Promise.allSettled(promiseReturns))\n\n\t\t\t\tcallbackQueue.length = 0 // Empties the queue\n\n\t\t\t\t// TODO we're drifting away from the original depth-first order. Let's see if that's ever even an issue.\n\t\t\t\tfor (const newlyInitialized of this.newlyInitializedWithListeners) {\n\t\t\t\t\tif (newlyInitialized.type === 'field') {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst beforePersistHandlers = this.getEventListeners(newlyInitialized, { type: eventType })\n\t\t\t\t\tif (beforePersistHandlers) {\n\t\t\t\t\t\tfor (const listener of beforePersistHandlers) {\n\t\t\t\t\t\t\tcallbackQueue.push([newlyInitialized, listener])\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.triggerBeforeFlushEvents()\n\t\t\t\tthis.handleRejections(eventType, newCallbacks)\n\n\t\t\t\tfor (let i = 0; i < newCallbacks.length; i++) {\n\t\t\t\t\tconst result = newCallbacks[i]\n\t\t\t\t\tconst correspondingState = correspondingStates[i]\n\n\t\t\t\t\tif (result.status === 'fulfilled') {\n\t\t\t\t\t\tif (typeof result.value === 'function') {\n\t\t\t\t\t\t\tcallbackQueue.push([correspondingState, result.value])\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Otherwise do nothing. This is just a handler that albeit async, doesn't appear to\n\t\t\t\t\t\t// interact with data binding.\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\tif (callbackQueue.length) {\n\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t`Exceeded the ${eventType} settle limit. Your code likely contains a deadlock. ` +\n\t\t\t\t\t\t\t`If that's not the case, raise the settle limit from DataBindingProvider.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate triggerBeforeFlushEvents() {\n\t\tthis.syncTransaction(() => {\n\t\t\tconst settleLimit = this.config.getValue('beforeUpdateSettleLimit')\n\n\t\t\tfor (let attemptNumber = 0; attemptNumber < settleLimit; attemptNumber++) {\n\t\t\t\tif (!this.pendingWithBeforeUpdate.size) {\n\t\t\t\t\tthis.triggerOnInitialize()\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst withBeforeUpdate = this.pendingWithBeforeUpdate\n\t\t\t\tthis.pendingWithBeforeUpdate = new Set()\n\n\t\t\t\tfor (const state of withBeforeUpdate) {\n\t\t\t\t\tconst listeners = this.getEventListeners(state, { type: 'beforeUpdate' })\n\t\t\t\t\tif (listeners === undefined) {\n\t\t\t\t\t\t// This can happen if the listener has unsubscribed since we added it to the set.\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tswitch (state.type) {\n\t\t\t\t\t\tcase 'field':\n\t\t\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\t\t\t(listener as FieldAccessor.BeforeUpdateListener)(state.getAccessor())\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\t\t\tstate.getAccessor().batchUpdates(listener as any)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn assertNever(state)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.triggerOnInitialize()\n\t\t\t}\n\t\t\tthrow new BindingError(\n\t\t\t\t`Maximum stabilization limit of updates caused by 'beforeUpdate' exceeded. ` +\n\t\t\t\t\t`This likely means there is an infinite feedback loop in your code.`,\n\t\t\t)\n\t\t})\n\t}\n\n\tprivate triggerOnInitialize() {\n\t\tthis.syncTransaction(() => {\n\t\t\tfor (const state of this.newlyInitializedWithListeners) {\n\t\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\t\tconst listeners =\n\t\t\t\t\tstate.type === 'field'\n\t\t\t\t\t\t? this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\t\t\t\t\t\t: state.type === 'entityRealm'\n\t\t\t\t\t\t? this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\t\t\t\t\t\t: this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\n\t\t\t\tif (listeners) {\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tlistener()\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (state.type === 'entityRealm') {\n\t\t\t\t\tstate.entity.hasIdSetInStone = true\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.newlyInitializedWithListeners.clear()\n\t\t})\n\t}\n\n\tpublic async triggerOnPersistError(options: PersistErrorOptions) {\n\t\tawait this.asyncTransaction(async () => {\n\t\t\tconst handlerPromises: Array<Promise<void>> = []\n\n\t\t\tfor (const [, subTreeState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const iNode of StateIterator.depthFirstINodes(subTreeState)) {\n\t\t\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\t\t\tconst dispatchers =\n\t\t\t\t\t\tiNode.type === 'entityRealm'\n\t\t\t\t\t\t\t? this.getEventDispatchers(iNode, { type: 'persistError' }, [iNode.getAccessor, options])\n\t\t\t\t\t\t\t: this.getEventDispatchers(iNode, { type: 'persistError' }, [iNode.getAccessor, options])\n\t\t\t\t\tif (dispatchers === undefined) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const listener of dispatchers ?? []) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst result = listener()\n\t\t\t\t\t\t\tif (result instanceof Promise) {\n\t\t\t\t\t\t\t\thandlerPromises.push(result)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\thandlerPromises.push(Promise.resolve(result))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\thandlerPromises.push(Promise.reject(e))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// TODO timeout\n\t\t\tconst handlerResults = await Promise.allSettled(handlerPromises)\n\t\t\tthis.handleRejections('persistError', handlerResults)\n\t\t})\n\t}\n\n\tpublic async triggerOnBeforePersist() {\n\t\treturn this.triggerAsyncMutatingEvent('beforePersist', this.asyncBatchUpdatesOptions)\n\t}\n\n\tpublic async triggerOnPersistSuccess(options: PersistSuccessOptions) {\n\t\treturn this.triggerAsyncMutatingEvent('persistSuccess', options)\n\t}\n\n\tpublic getEventListeners<\n\t\tState extends StateNode,\n\t\tEventListenerTypes extends\n\t\t\tExclude<State['eventListeners'], undefined> extends EventListenersStore<infer Keys, infer Map> ? [Keys, Map] : never,\n\t\tEventType extends EventListenerTypes[0],\n\t>(state: State, event: { type: EventType; key?: string }): Set<Exclude<EventListenerTypes[1][EventType], undefined>> | undefined {\n\t\tif (!state.eventListeners) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn (state.eventListeners as EventListenersStore<EventType, EventListenerTypes[1]>).get(event) as Set<\n\t\t\tExclude<EventListenerTypes[1][EventType], undefined>\n\t\t>\n\t}\n\n\tpublic getEventDispatchers<\n\t\tState extends StateNode,\n\t\tEventListenerTypes extends\n\t\t\tExclude<State['eventListeners'], undefined> extends EventListenersStore<infer Keys, infer Map> ? [Keys, Map] : never,\n\t\tEventType extends EventListenerTypes[0],\n\t>(\n\t\tstate: State,\n\t\tevent: { type: EventType; key?: string },\n\t\tlistenerArgs: Parameters<Exclude<EventListenerTypes[1][EventType], undefined>>,\n\t): Array<() => ReturnType<Exclude<EventListenerTypes[1][EventType], undefined>>> | undefined {\n\t\tconst eventListeners = this.getEventListeners(state, event)\n\t\tif (eventListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn Array.from(eventListeners.values(), listener => {\n\t\t\treturn () => listener(...listenerArgs)\n\t\t}) as Array<() => ReturnType<Exclude<EventListenerTypes[1][EventType], undefined>>>\n\t}\n\n\tprivate handleRejections(handler: string, promises: PromiseSettledResult<any>[]) {\n\t\tconst rejections = promises.filter((it): it is PromiseRejectedResult => it.status === 'rejected')\n\t\tif (rejections.length === 0) {\n\t\t\treturn\n\t\t}\n\t\trejections.forEach(it => console.error(it.reason))\n\t\tif (import.meta.env.DEV) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`A ${handler} handler returned a promise that rejected. ` +\n\t\t\t\t\t`This is a no-op that will fail silently in production.`,\n\t\t\t)\n\t\t}\n\t}\n\n\tprivate async executeWithoutChanges<T>(eventType: string, cb: () => Promise<T>): Promise<T> {\n\t\tconst changesCountBefore = this.dirtinessTracker.getTotalChangesCount()\n\t\tconst result = await cb()\n\t\tconst changesCountAfter = this.dirtinessTracker.getTotalChangesCount()\n\t\tif (import.meta.env.DEV) {\n\t\t\tif (changesCountBefore !== changesCountAfter) {\n\t\t\t\t// This isn't bulletproof. They could e.g. undo a change and make another one which would\n\t\t\t\t// slip through this detection. But for most cases, it should be good enough and not too expensive.\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`A ${eventType} event handler cannot be asynchronous and alter the accessor tree at the same time. ` +\n\t\t\t\t\t\t`To achieve this, prepare your data asynchronously but only touch the tree from a returned callback.`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n}\n"],"names":[],"mappings":";;;;;;mBA8B0B;AAAA,EAiBlB,YACW,0BACA,qBACA,QACA,kBACA,UACA,WAChB;AANgB;AACA;AACA;AACA;AACA;AACA;AAAA;AAAA,SAtBK,wBAAwB;AAAA,EAEvC,mBAAmB;AAAA,EACnB,wBAAwB;AAAA,EAIxB,aAAsB;AAAA,EACtB,0BAAwE;AAAA,EAExE,mBAA+C;AAAA,EAE/C,oDAA0F;AAAA,EAC1F,8CAA8C;AAAA,EAC9C,8CAAkD;AAAA,QAW7C,iBAAiB,WAAqF;AAClH,QAAI,KAAK,mBAAmB,GAAG;AAC9B,YAAM,IAAI,aAAa;AAAA;AAExB,UAAM,mBAAmB,KAAK;AAC9B,QAAI,qBAAqB,QAAW;AACnC,aAAO,MAAM;AAAA;AAEd,WAAO,YAAY,0BAA0B,IAAI,QAAiC,OAAO,SAAS,WAAW;AAC5G,WAAK,aAAa;AAClB,WAAK;AAEL,UAAI;AACH,gBAAQ,MAAM,KAAK,eAAe;AAAA,eAC1B,GAAP;AACD,gBAAQ,MAAM,gBAAgB;AAC9B,e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,QAAQ,QAAM,QAAQ,MAAM,GAAG;AAC1C,IAAyB;AACxB,YAAM,IAAI,aACT,KAAK;AAAA;AAAA;AAAA,QAMM,sBAAyB,WAAmB,IAAkC;AAC3F,UAAM,qBAAqB,KAAK,iBAAiB;AACjD,UAAM,SAAS,MAAM;AACrB,UAAM,oBAAoB,KAAK,iBAAiB;AAChD,IAAyB;AACxB,UAAI,uBAAuB,mBAAmB;AAG7C,cAAM,IAAI,aACT,KAAK;AAAA;AAAA;AAKR,WAAO;AAAA;AAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"EventManager.js","sources":["../../../src/core/EventManager.ts"],"sourcesContent":["import * as ReactDOM from 'react-dom'\nimport type {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tEntityAccessor,\n\tEntityListAccessor,\n\tFieldAccessor,\n\tPersistErrorOptions,\n\tPersistSuccessOptions,\n} from '../accessors'\nimport type { SuccessfulPersistResult } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { PlaceholderName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport type { Config } from './Config'\nimport type { DirtinessTracker } from './DirtinessTracker'\nimport {\n\tEntityListState,\n\tEntityRealmState,\n\tFieldState,\n\tgetEntityMarker,\n\tRootStateNode,\n\tStateINode,\n\tStateIterator,\n\tStateNode,\n} from './state'\nimport type { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport type { EventListenersStore } from '../treeParameters'\n\nexport class EventManager {\n\tpublic static readonly NO_CHANGES_DIFFERENCE = 0\n\n\tprivate transactionDepth = 0\n\tprivate isFrozenWhileUpdating = false\n\n\t// This should ideally not exists as it should be synonymous to `this.ongoingPersistOperation !== undefined`\n\t// but it makes persist-related promise juggling significantly more straightforward.\n\tprivate isMutating: boolean = false\n\tprivate ongoingPersistOperation: Promise<SuccessfulPersistResult> | undefined = undefined\n\n\tprivate previousMetadata: UpdateMetadata | undefined = undefined\n\n\tprivate newlyInitializedWithListeners: Set<EntityListState | EntityRealmState | FieldState> = new Set()\n\tprivate pendingWithBeforeUpdate: Set<StateNode> = new Set()\n\tprivate rootsWithPendingUpdates: Set<RootStateNode> = new Set()\n\n\tpublic constructor(\n\t\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly config: Config,\n\t\tprivate readonly dirtinessTracker: DirtinessTracker,\n\t\tprivate readonly onUpdate: (metadata: UpdateMetadata) => void,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic async persistOperation(operation: () => Promise<SuccessfulPersistResult>): Promise<SuccessfulPersistResult> {\n\t\tif (this.transactionDepth > 0) {\n\t\t\tthrow new BindingError(`Cannot trigger a persist whilst batching updates!`)\n\t\t}\n\t\tconst ongoingOperation = this.ongoingPersistOperation\n\t\tif (ongoingOperation !== undefined) {\n\t\t\treturn await ongoingOperation\n\t\t}\n\t\treturn await (this.ongoingPersistOperation = new Promise<SuccessfulPersistResult>(async (resolve, reject) => {\n\t\t\tthis.isMutating = true\n\t\t\tthis.flushUpdates() // Let the world know that we're mutating\n\n\t\t\ttry {\n\t\t\t\tresolve(await this.asyncOperation(operation))\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error('PersistError', e)\n\t\t\t\treject(e)\n\t\t\t} finally {\n\t\t\t\tthis.ongoingPersistOperation = undefined\n\t\t\t\tthis.isMutating = false\n\t\t\t\tthis.flushUpdates()\n\t\t\t}\n\t\t}))\n\t}\n\n\tpublic syncTransaction<T>(transaction: () => T) {\n\t\ttry {\n\t\t\tthis.transactionDepth++\n\t\t\treturn transaction()\n\t\t} finally {\n\t\t\tthis.transactionDepth--\n\t\t}\n\t}\n\tpublic syncOperation<T>(operation: () => T) {\n\t\tconst result = this.syncTransaction(operation)\n\t\tthis.flushUpdates()\n\t\treturn result\n\t}\n\n\tpublic async asyncTransaction<T>(transaction: () => Promise<T>): Promise<T> {\n\t\ttry {\n\t\t\tthis.transactionDepth++\n\t\t\treturn await transaction()\n\t\t} finally {\n\t\t\tthis.transactionDepth--\n\t\t}\n\t}\n\tpublic async asyncOperation<T>(operation: () => Promise<T>): Promise<T> {\n\t\tconst result = await this.asyncTransaction(operation)\n\t\tthis.flushUpdates()\n\t\treturn result\n\t}\n\n\tprivate flushUpdates() {\n\t\tif (this.transactionDepth > 0) {\n\t\t\treturn\n\t\t}\n\n\t\tif (this.isFrozenWhileUpdating) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Trying to perform an update while the whole accessor tree is already updating. This is most likely caused ` +\n\t\t\t\t\t`by updating the accessor tree while rendering or from within the 'update' event handler, which is a no-op. ` +\n\t\t\t\t\t`If you wish to mutate the tree in reaction to other changes, use the 'beforeUpdate' event.`,\n\t\t\t)\n\t\t}\n\n\t\tconst newMetadata = this.getNewUpdateMetadata()\n\n\t\tif (!this.shouldFlushUpdates(newMetadata)) {\n\t\t\treturn\n\t\t}\n\n\t\tReactDOM.unstable_batchedUpdates(() => {\n\t\t\tthis.isFrozenWhileUpdating = true\n\t\t\tthis.triggerBeforeFlushEvents()\n\t\t\tthis.onUpdate(newMetadata)\n\t\t\tthis.flushPendingAccessorUpdates(Array.from(this.rootsWithPendingUpdates))\n\n\t\t\tthis.rootsWithPendingUpdates.clear()\n\t\t\tthis.isFrozenWhileUpdating = false\n\t\t\tthis.previousMetadata = newMetadata\n\t\t})\n\t}\n\n\tprivate getNewUpdateMetadata(): UpdateMetadata {\n\t\treturn {\n\t\t\tisMutating: this.isMutating,\n\t\t}\n\t}\n\n\tprivate shouldFlushUpdates(newMetadata: UpdateMetadata): boolean {\n\t\tif (this.transactionDepth > 0) {\n\t\t\treturn false\n\t\t}\n\t\tif (this.previousMetadata === undefined) {\n\t\t\treturn true\n\t\t}\n\t\tif (this.rootsWithPendingUpdates.size) {\n\t\t\treturn true\n\t\t}\n\t\tfor (const key in newMetadata) {\n\t\t\tconst fromPrevious = this.previousMetadata[key as keyof UpdateMetadata]\n\t\t\tconst fromNew = newMetadata[key as keyof UpdateMetadata]\n\n\t\t\tif (!Object.is(fromPrevious, fromNew)) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n\n\tpublic registerNewlyInitialized(newlyInitialized: StateNode) {\n\t\tconst initializeListeners = this.getEventListeners(newlyInitialized, { type: 'initialize' })\n\n\t\tif (initializeListeners === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.newlyInitializedWithListeners.add(newlyInitialized)\n\n\t\tif (this.transactionDepth === 0) {\n\t\t\tthis.triggerOnInitialize()\n\t\t}\n\t}\n\n\tpublic registerUpdatedConnection(parentState: EntityRealmState, placeholderName: PlaceholderName) {\n\t\tif (parentState.fieldsWithPendingConnectionUpdates === undefined) {\n\t\t\tparentState.fieldsWithPendingConnectionUpdates = new Set()\n\t\t}\n\n\t\tconst marker = getEntityMarker(parentState)\n\t\tplaceholders: for (const [fieldName, placeholdersByField] of marker.fields.placeholders) {\n\t\t\tif (typeof placeholdersByField === 'string') {\n\t\t\t\tif (placeholdersByField === placeholderName) {\n\t\t\t\t\tparentState.fieldsWithPendingConnectionUpdates.add(fieldName)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (const placeholderByFieldName of placeholdersByField) {\n\t\t\t\t\tif (placeholderByFieldName === placeholderName) {\n\t\t\t\t\t\tparentState.fieldsWithPendingConnectionUpdates.add(fieldName)\n\t\t\t\t\t\tcontinue placeholders\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic registerJustUpdated(justUpdated: StateNode, changesDelta: number) {\n\t\tconst beforeUpdateListeners = this.getEventListeners(justUpdated, { type: 'beforeUpdate' })\n\t\tif (beforeUpdateListeners !== undefined) {\n\t\t\tthis.pendingWithBeforeUpdate.add(justUpdated)\n\t\t}\n\t\tjustUpdated.accessor = undefined\n\n\t\tswitch (justUpdated.type) {\n\t\t\tcase 'entityRealm':\n\t\t\tcase 'entityList': {\n\t\t\t\tjustUpdated.unpersistedChangesCount += changesDelta\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tif (justUpdated.unpersistedChangesCount < 0) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`We have *JUST* reached a completely invalid state. From now on, anything can (and likely will) ` +\n\t\t\t\t\t\t\t\t`go wrong. This is definitely a bug. Please try to report whatever led to this situation.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst parent = justUpdated.blueprint.parent\n\n\t\t\t\tif (parent === undefined) {\n\t\t\t\t\tthis.rootsWithPendingUpdates.add(justUpdated)\n\t\t\t\t\tthis.dirtinessTracker.increaseBy(changesDelta)\n\t\t\t\t} else {\n\t\t\t\t\tif (!parent.childrenWithPendingUpdates) {\n\t\t\t\t\t\tparent.childrenWithPendingUpdates = new Set()\n\t\t\t\t\t}\n\t\t\t\t\tparent.childrenWithPendingUpdates.add(justUpdated as any)\n\t\t\t\t\tthis.registerJustUpdated(parent, changesDelta)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'field': {\n\t\t\t\tconst parent = justUpdated.parent\n\t\t\t\tif (!parent.childrenWithPendingUpdates) {\n\t\t\t\t\tparent.childrenWithPendingUpdates = new Set()\n\t\t\t\t}\n\t\t\t\tparent.childrenWithPendingUpdates.add(justUpdated as any)\n\t\t\t\tthis.registerJustUpdated(justUpdated.parent, changesDelta)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate flushPendingAccessorUpdates(rootStates: Array<StateINode>) {\n\t\t// It is *CRUCIAL* that this is a BFS so that we update the components in top-down order.\n\t\tconst agenda: StateNode[] = rootStates\n\n\t\tfor (const state of agenda) {\n\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\tconst updateListeners =\n\t\t\t\tstate.type === 'field'\n\t\t\t\t\t? this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\t\t\t\t\t: state.type === 'entityRealm'\n\t\t\t\t\t? this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\t\t\t\t\t: this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\n\t\t\tif (updateListeners !== undefined) {\n\t\t\t\tfor (const handler of updateListeners) {\n\t\t\t\t\t// TS can't quite handle the polymorphism here but this is fine.\n\t\t\t\t\thandler()\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (state.type === 'entityRealm' && state.fieldsWithPendingConnectionUpdates) {\n\t\t\t\tfor (const updatedField of state.fieldsWithPendingConnectionUpdates) {\n\t\t\t\t\tconst listeners = this.getEventListeners(state, { type: 'connectionUpdate', key: updatedField })\n\t\t\t\t\tif (!listeners) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tlistener(state.getAccessor())\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tswitch (state.type) {\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (state.childrenWithPendingUpdates !== undefined) {\n\t\t\t\t\t\tfor (const childState of state.childrenWithPendingUpdates) {\n\t\t\t\t\t\t\tagenda.push(childState)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstate.childrenWithPendingUpdates.clear()\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'field':\n\t\t\t\t\t// Do nothing\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\tassertNever(state)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async triggerAsyncMutatingEvent(eventType: 'beforePersist', options: AsyncBatchUpdatesOptions): Promise<void>\n\tprivate async triggerAsyncMutatingEvent(eventType: 'persistSuccess', options: PersistSuccessOptions): Promise<void>\n\tprivate async triggerAsyncMutatingEvent(\n\t\teventType: 'beforePersist' | 'persistSuccess',\n\t\toptions: AsyncBatchUpdatesOptions | PersistSuccessOptions,\n\t): Promise<void> {\n\t\tawait this.asyncTransaction(async () => {\n\t\t\t// TODO if an entity from here (or its parent) gets deleted, we need to remove stale handlers from here.\n\t\t\tconst callbackQueue: Array<\n\t\t\t\t[\n\t\t\t\t\t// The typings could be nicer but TS…\n\t\t\t\t\tStateINode,\n\t\t\t\t\t(\n\t\t\t\t\t\t| EntityAccessor.EntityEventListenerMap[typeof eventType]\n\t\t\t\t\t\t| EntityListAccessor.EntityListEventListenerMap[typeof eventType]\n\t\t\t\t\t),\n\t\t\t\t]\n\t\t\t> = []\n\n\t\t\tfor (const [, subTreeState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const iNode of StateIterator.depthFirstINodes(subTreeState)) {\n\t\t\t\t\tconst listeners = this.getEventListeners(iNode, { type: eventType }) ?? []\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tcallbackQueue.push([iNode, listener])\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (\n\t\t\t\tlet waterfallDepth = 0;\n\t\t\t\twaterfallDepth < this.config.getValue(`${eventType}SettleLimit` as const);\n\t\t\t\twaterfallDepth++\n\t\t\t) {\n\t\t\t\tconst promiseReturns: Array<\n\t\t\t\t\tPromise<\n\t\t\t\t\t\t| void\n\t\t\t\t\t\t| EntityAccessor.EntityEventListenerMap[typeof eventType]\n\t\t\t\t\t\t| EntityListAccessor.EntityListEventListenerMap[typeof eventType]\n\t\t\t\t\t>\n\t\t\t\t> = []\n\t\t\t\tconst correspondingStates: Array<StateINode> = []\n\n\t\t\t\tif (callbackQueue.length === 0) {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\n\t\t\t\tfor (const [state, callback] of callbackQueue) {\n\t\t\t\t\tcorrespondingStates.push(state)\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = callback(state.getAccessor as any, options as any) // TS can't quite handle this but this is sound.\n\t\t\t\t\t\tif (result instanceof Promise) {\n\t\t\t\t\t\t\tpromiseReturns.push(result)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tpromiseReturns.push(Promise.resolve(result))\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tpromiseReturns.push(Promise.reject(e))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// TODO timeout\n\n\t\t\t\tconst newCallbacks = await this.executeWithoutChanges(eventType, () => Promise.allSettled(promiseReturns))\n\n\t\t\t\tcallbackQueue.length = 0 // Empties the queue\n\n\t\t\t\t// TODO we're drifting away from the original depth-first order. Let's see if that's ever even an issue.\n\t\t\t\tfor (const newlyInitialized of this.newlyInitializedWithListeners) {\n\t\t\t\t\tif (newlyInitialized.type === 'field') {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst beforePersistHandlers = this.getEventListeners(newlyInitialized, { type: eventType })\n\t\t\t\t\tif (beforePersistHandlers) {\n\t\t\t\t\t\tfor (const listener of beforePersistHandlers) {\n\t\t\t\t\t\t\tcallbackQueue.push([newlyInitialized, listener])\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.triggerBeforeFlushEvents()\n\t\t\t\tthis.handleRejections(eventType, newCallbacks)\n\n\t\t\t\tfor (let i = 0; i < newCallbacks.length; i++) {\n\t\t\t\t\tconst result = newCallbacks[i]\n\t\t\t\t\tconst correspondingState = correspondingStates[i]\n\n\t\t\t\t\tif (result.status === 'fulfilled') {\n\t\t\t\t\t\tif (typeof result.value === 'function') {\n\t\t\t\t\t\t\tcallbackQueue.push([correspondingState, result.value])\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Otherwise do nothing. This is just a handler that albeit async, doesn't appear to\n\t\t\t\t\t\t// interact with data binding.\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\tif (callbackQueue.length) {\n\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t`Exceeded the ${eventType} settle limit. Your code likely contains a deadlock. ` +\n\t\t\t\t\t\t\t`If that's not the case, raise the settle limit from DataBindingProvider.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate triggerBeforeFlushEvents() {\n\t\tthis.syncTransaction(() => {\n\t\t\tconst settleLimit = this.config.getValue('beforeUpdateSettleLimit')\n\n\t\t\tfor (let attemptNumber = 0; attemptNumber < settleLimit; attemptNumber++) {\n\t\t\t\tif (!this.pendingWithBeforeUpdate.size) {\n\t\t\t\t\tthis.triggerOnInitialize()\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst withBeforeUpdate = this.pendingWithBeforeUpdate\n\t\t\t\tthis.pendingWithBeforeUpdate = new Set()\n\n\t\t\t\tfor (const state of withBeforeUpdate) {\n\t\t\t\t\tconst listeners = this.getEventListeners(state, { type: 'beforeUpdate' })\n\t\t\t\t\tif (listeners === undefined) {\n\t\t\t\t\t\t// This can happen if the listener has unsubscribed since we added it to the set.\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tswitch (state.type) {\n\t\t\t\t\t\tcase 'field':\n\t\t\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\t\t\t(listener as FieldAccessor.BeforeUpdateListener)(state.getAccessor())\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\t\t\tstate.getAccessor().batchUpdates(listener as any)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn assertNever(state)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.triggerOnInitialize()\n\t\t\t}\n\t\t\tthrow new BindingError(\n\t\t\t\t`Maximum stabilization limit of updates caused by 'beforeUpdate' exceeded. ` +\n\t\t\t\t\t`This likely means there is an infinite feedback loop in your code.`,\n\t\t\t)\n\t\t})\n\t}\n\n\tprivate triggerOnInitialize() {\n\t\tthis.syncTransaction(() => {\n\t\t\tfor (const state of this.newlyInitializedWithListeners) {\n\t\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\t\tconst listeners =\n\t\t\t\t\tstate.type === 'field'\n\t\t\t\t\t\t? this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\t\t\t\t\t\t: state.type === 'entityRealm'\n\t\t\t\t\t\t? this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\t\t\t\t\t\t: this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\n\t\t\t\tif (listeners) {\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tlistener()\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (state.type === 'entityRealm') {\n\t\t\t\t\tstate.entity.hasIdSetInStone = true\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.newlyInitializedWithListeners.clear()\n\t\t})\n\t}\n\n\tpublic async triggerOnPersistError(options: PersistErrorOptions) {\n\t\tawait this.asyncTransaction(async () => {\n\t\t\tconst handlerPromises: Array<Promise<void>> = []\n\n\t\t\tfor (const [, subTreeState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const iNode of StateIterator.depthFirstINodes(subTreeState)) {\n\t\t\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\t\t\tconst dispatchers =\n\t\t\t\t\t\tiNode.type === 'entityRealm'\n\t\t\t\t\t\t\t? this.getEventDispatchers(iNode, { type: 'persistError' }, [iNode.getAccessor, options])\n\t\t\t\t\t\t\t: this.getEventDispatchers(iNode, { type: 'persistError' }, [iNode.getAccessor, options])\n\t\t\t\t\tif (dispatchers === undefined) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const listener of dispatchers ?? []) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst result = listener()\n\t\t\t\t\t\t\tif (result instanceof Promise) {\n\t\t\t\t\t\t\t\thandlerPromises.push(result)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\thandlerPromises.push(Promise.resolve(result))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\thandlerPromises.push(Promise.reject(e))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// TODO timeout\n\t\t\tconst handlerResults = await Promise.allSettled(handlerPromises)\n\t\t\tthis.handleRejections('persistError', handlerResults)\n\t\t})\n\t}\n\n\tpublic async triggerOnBeforePersist() {\n\t\treturn this.triggerAsyncMutatingEvent('beforePersist', this.asyncBatchUpdatesOptions)\n\t}\n\n\tpublic async triggerOnPersistSuccess(options: PersistSuccessOptions) {\n\t\treturn this.triggerAsyncMutatingEvent('persistSuccess', options)\n\t}\n\n\tpublic getEventListeners<\n\t\tState extends StateNode,\n\t\tEventListenerTypes extends\n\t\t\tExclude<State['eventListeners'], undefined> extends EventListenersStore<infer Keys, infer Map> ? [Keys, Map] : never,\n\t\tEventType extends EventListenerTypes[0],\n\t>(state: State, event: { type: EventType; key?: string }): Set<Exclude<EventListenerTypes[1][EventType], undefined>> | undefined {\n\t\tif (!state.eventListeners) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn (state.eventListeners as EventListenersStore<EventType, EventListenerTypes[1]>).get(event) as Set<\n\t\t\tExclude<EventListenerTypes[1][EventType], undefined>\n\t\t>\n\t}\n\n\tpublic getEventDispatchers<\n\t\tState extends StateNode,\n\t\tEventListenerTypes extends\n\t\t\tExclude<State['eventListeners'], undefined> extends EventListenersStore<infer Keys, infer Map> ? [Keys, Map] : never,\n\t\tEventType extends EventListenerTypes[0],\n\t>(\n\t\tstate: State,\n\t\tevent: { type: EventType; key?: string },\n\t\tlistenerArgs: Parameters<Exclude<EventListenerTypes[1][EventType], undefined>>,\n\t): Array<() => ReturnType<Exclude<EventListenerTypes[1][EventType], undefined>>> | undefined {\n\t\tconst eventListeners = this.getEventListeners(state, event)\n\t\tif (eventListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn Array.from(eventListeners.values(), listener => {\n\t\t\treturn () => listener(...listenerArgs)\n\t\t}) as Array<() => ReturnType<Exclude<EventListenerTypes[1][EventType], undefined>>>\n\t}\n\n\tprivate handleRejections(handler: string, promises: PromiseSettledResult<any>[]) {\n\t\tconst rejections = promises.filter((it): it is PromiseRejectedResult => it.status === 'rejected')\n\t\tif (rejections.length === 0) {\n\t\t\treturn\n\t\t}\n\t\trejections.forEach(it => console.error(it.reason))\n\t\tif (import.meta.env.DEV) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`A ${handler} handler returned a promise that rejected. ` +\n\t\t\t\t\t`This is a no-op that will fail silently in production.`,\n\t\t\t)\n\t\t}\n\t}\n\n\tprivate async executeWithoutChanges<T>(eventType: string, cb: () => Promise<T>): Promise<T> {\n\t\tconst changesCountBefore = this.dirtinessTracker.getTotalChangesCount()\n\t\tconst result = await cb()\n\t\tconst changesCountAfter = this.dirtinessTracker.getTotalChangesCount()\n\t\tif (import.meta.env.DEV) {\n\t\t\tif (changesCountBefore !== changesCountAfter) {\n\t\t\t\t// This isn't bulletproof. They could e.g. undo a change and make another one which would\n\t\t\t\t// slip through this detection. But for most cases, it should be good enough and not too expensive.\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`A ${eventType} event handler cannot be asynchronous and alter the accessor tree at the same time. ` +\n\t\t\t\t\t\t`To achieve this, prepare your data asynchronously but only touch the tree from a returned callback.`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;AA8BO,MAAM,aAAa;AAAA,EAiBlB,YACW,0BACA,qBACA,QACA,kBACA,UACA,WAChB;AArBM,4C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,SAAgC;AAC7D,WAAA,KAAK,0BAA0B,kBAAkB,OAAO;AAAA,EAChE;AAAA,EAEO,kBAKL,OAAc,OAAiH;AAC5H,QAAA,CAAC,MAAM,gBAAgB;AACnB,aAAA;AAAA,IACR;AACQ,WAAA,MAAM,eAAyE,IAAI,KAAK;AAAA,EAGjG;AAAA,EAEO,oBAMN,OACA,OACA,cAC4F;AAC5F,UAAM,iBAAiB,KAAK,kBAAkB,OAAO,KAAK;AAC1D,QAAI,mBAAmB,QAAW;AAC1B,aAAA;AAAA,IACR;AACA,WAAO,MAAM,KAAK,eAAe,UAAU,CAAY,aAAA;AAC/C,aAAA,MAAM,SAAS,GAAG,YAAY;AAAA,IAAA,CACrC;AAAA,EACF;AAAA,EAEQ,iBAAiB,SAAiB,UAAuC;AAChF,UAAM,aAAa,SAAS,OAAO,CAAC,OAAoC,GAAG,WAAW,UAAU;AAC5F,QAAA,WAAW,WAAW,GAAG;AAC5B;AAAA,IACD;AACA,eAAW,QAAQ,CAAM,OAAA,QAAQ,MAAM,GAAG,MAAM,CAAC;AACxB;AAClB,YAAA,IAAI,aACT,KAAK,0GAEN;AAAA,IACD;AAAA,EACD;AAAA,QAEc,sBAAyB,WAAmB,IAAkC;AACrF,UAAA,qBAAqB,KAAK,iBAAiB,qBAAqB;AAChE,UAAA,SAAS,MAAM;AACf,UAAA,oBAAoB,KAAK,iBAAiB,qBAAqB;AAC5C;AACxB,UAAI,uBAAuB,mBAAmB;AAGvC,cAAA,IAAI,aACT,KAAK,kMAEN;AAAA,MACD;AAAA,IACD;AACO,WAAA;AAAA,EACR;AACD;AApiBwB,cADjB,cACiB,yBAAwB;;"}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import { MarkerMerger } from "./MarkerMerger.js";
|
|
8
|
+
import { TreeParameterMerger } from "./TreeParameterMerger.js";
|
|
9
|
+
import { EntityFieldsWithHoistablesMarker } from "../markers/EntityFieldsWithHoistablesMarker.js";
|
|
10
|
+
import { MarkerFactory } from "../queryLanguage/MarkerFactory.js";
|
|
11
|
+
import { EntityFieldMarkersContainer } from "../markers/EntityFieldMarkersContainer.js";
|
|
7
12
|
class IncrementalMarkerBuilder {
|
|
8
|
-
|
|
13
|
+
constructor() {
|
|
14
|
+
__publicField(this, "accumulator", new EntityFieldMarkersContainer(false, /* @__PURE__ */ new Map(), /* @__PURE__ */ new Map()));
|
|
15
|
+
}
|
|
9
16
|
mutateIn(addition) {
|
|
10
17
|
if (addition instanceof EntityFieldMarkersContainer) {
|
|
11
18
|
if (this.accumulator instanceof EntityFieldMarkersContainer) {
|
|
@@ -31,6 +38,5 @@ class IncrementalMarkerBuilder {
|
|
|
31
38
|
return this.accumulator;
|
|
32
39
|
}
|
|
33
40
|
}
|
|
34
|
-
|
|
35
41
|
export { IncrementalMarkerBuilder };
|
|
36
42
|
//# sourceMappingURL=IncrementalMarkerBuilder.js.map
|