@contember/binding 1.1.0-alpha.0 → 1.1.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/accessorPropagation/EnvironmentContext.js +28 -2
- package/dist/development/accessorPropagation/EnvironmentContext.js.map +1 -1
- package/dist/development/accessorPropagation/useEntityListSubTree.js +4 -2
- package/dist/development/accessorPropagation/useEntityListSubTree.js.map +1 -1
- package/dist/development/accessorPropagation/useEntitySubTree.js +4 -2
- package/dist/development/accessorPropagation/useEntitySubTree.js.map +1 -1
- package/dist/development/accessorPropagation/useExtendTree.js +27 -0
- package/dist/development/accessorPropagation/useExtendTree.js.map +1 -0
- package/dist/development/accessorTree/AccessorTree.js +16 -14
- package/dist/development/accessorTree/AccessorTree.js.map +1 -1
- package/dist/development/accessorTree/AccessorTreeStateContext.js +4 -0
- package/dist/development/accessorTree/AccessorTreeStateContext.js.map +1 -0
- package/dist/development/accessorTree/NormalizedPersistedData.js.map +1 -1
- package/dist/development/accessorTree/RuntimeId.js +17 -4
- package/dist/development/accessorTree/RuntimeId.js.map +1 -1
- package/dist/development/accessorTree/accessorTreeStateReducer.js +11 -2
- package/dist/development/accessorTree/accessorTreeStateReducer.js.map +1 -1
- package/dist/development/accessorTree/useAccessorTreeState.js +12 -0
- package/dist/development/accessorTree/useAccessorTreeState.js.map +1 -0
- package/dist/development/accessorTree/useDataBinding.js +41 -51
- package/dist/development/accessorTree/useDataBinding.js.map +1 -1
- package/dist/development/accessors/EntityAccessor.js +19 -40
- package/dist/development/accessors/EntityAccessor.js.map +1 -1
- package/dist/development/accessors/EntityListAccessor.js +11 -11
- package/dist/development/accessors/EntityListAccessor.js.map +1 -1
- package/dist/development/accessors/FieldAccessor.js +6 -6
- package/dist/development/accessors/FieldAccessor.js.map +1 -1
- package/dist/development/core/AccessorErrorManager.js +5 -2
- package/dist/development/core/AccessorErrorManager.js.map +1 -1
- package/dist/development/core/Config.js +1 -2
- package/dist/development/core/Config.js.map +1 -1
- package/dist/development/core/DataBinding.js +27 -40
- package/dist/development/core/DataBinding.js.map +1 -1
- package/dist/development/core/DirtinessTracker.js +4 -13
- package/dist/development/core/DirtinessTracker.js.map +1 -1
- package/dist/development/core/ErrorsPreprocessor.js +9 -13
- package/dist/development/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/development/core/EventManager.js +13 -8
- package/dist/development/core/EventManager.js.map +1 -1
- package/dist/development/core/IncrementalMarkerBuilder.js +1 -1
- package/dist/development/core/MarkerMerger.js +2 -2
- package/dist/development/core/MutationGenerator.js +180 -141
- package/dist/development/core/MutationGenerator.js.map +1 -1
- package/dist/development/core/RequestResponseNormalizer.js +93 -134
- package/dist/development/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/development/core/StateInitializer.js +30 -38
- package/dist/development/core/StateInitializer.js.map +1 -1
- package/dist/development/core/TreeAugmenter.js +14 -14
- package/dist/development/core/TreeAugmenter.js.map +1 -1
- package/dist/development/core/TreeFilterGenerator.js +2 -2
- package/dist/development/core/TreeFilterGenerator.js.map +1 -1
- package/dist/development/core/TreeStore.js +12 -23
- package/dist/development/core/TreeStore.js.map +1 -1
- package/dist/development/core/VariableInputTransformer.js.map +1 -1
- package/dist/development/core/operations/EntityOperations.js +14 -13
- package/dist/development/core/operations/EntityOperations.js.map +1 -1
- package/dist/development/core/operations/FieldOperations.js +2 -2
- package/dist/development/core/operations/FieldOperations.js.map +1 -1
- package/dist/development/core/operations/ListOperations.js +3 -3
- package/dist/development/core/operations/ListOperations.js.map +1 -1
- package/dist/development/core/operations/OperationsHelpers.js +2 -2
- package/dist/development/core/operations/OperationsHelpers.js.map +1 -1
- package/dist/development/core/requestAliases/MutationAlias.js +4 -40
- package/dist/development/core/requestAliases/MutationAlias.js.map +1 -1
- package/dist/development/core/schema/Schema.js +27 -3
- package/dist/development/core/schema/Schema.js.map +1 -1
- package/dist/development/core/schema/SchemaLoader.js +12 -12
- package/dist/development/core/schema/SchemaLoader.js.map +1 -1
- package/dist/development/core/schema/SchemaPreprocessor.js +1 -1
- package/dist/development/core/schema/SchemaPreprocessor.js.map +1 -1
- package/dist/development/coreComponents/Component.js +5 -2
- package/dist/development/coreComponents/Component.js.map +1 -1
- package/dist/development/coreComponents/DataBindingProvider.js +0 -1
- package/dist/development/coreComponents/DataBindingProvider.js.map +1 -1
- package/dist/development/coreComponents/EntityListSubTree.js.map +1 -1
- package/dist/development/coreComponents/HasOne.js +1 -1
- package/dist/development/dao/Environment.js +35 -3
- package/dist/development/dao/Environment.js.map +1 -1
- package/dist/development/dao/TreeNodeEnvironmentFactory.js +6 -13
- package/dist/development/dao/TreeNodeEnvironmentFactory.js.map +1 -1
- package/dist/development/helperComponents/DeferredSubTrees.js +16 -8
- package/dist/development/helperComponents/DeferredSubTrees.js.map +1 -1
- package/dist/development/helperComponents/If.js +39 -0
- package/dist/development/helperComponents/If.js.map +1 -0
- package/dist/development/helperComponents/SugaredField.js +1 -1
- package/dist/development/helperComponents/helpers/FilterEvaluator.js +35 -0
- package/dist/development/helperComponents/helpers/FilterEvaluator.js.map +1 -0
- package/dist/development/helperComponents/helpers/FilterFieldsCollector.js +38 -0
- package/dist/development/helperComponents/helpers/FilterFieldsCollector.js.map +1 -0
- package/dist/development/helperComponents/helpers/evaluateCondition.js +46 -0
- package/dist/development/helperComponents/helpers/evaluateCondition.js.map +1 -0
- package/dist/development/index.js +7 -2
- package/dist/development/index.js.map +1 -1
- package/dist/development/markers/EntityListSubTreeMarker.js +1 -1
- package/dist/development/markers/EntityListSubTreeMarker.js.map +1 -1
- package/dist/development/markers/EntitySubTreeMarker.js +1 -1
- package/dist/development/markers/EntitySubTreeMarker.js.map +1 -1
- package/dist/development/markers/PlaceholderGenerator.js +4 -4
- package/dist/development/markers/PlaceholderGenerator.js.map +1 -1
- package/dist/development/queryLanguage/MarkerFactory.js +2 -2
- package/dist/development/queryLanguage/QueryLanguage.js +1 -1
- package/dist/development/utils/Hashing.js +21 -6
- package/dist/development/utils/Hashing.js.map +1 -1
- package/dist/production/accessorPropagation/EnvironmentContext.js +28 -2
- package/dist/production/accessorPropagation/EnvironmentContext.js.map +1 -1
- package/dist/production/accessorPropagation/useEntityListSubTree.js +4 -2
- package/dist/production/accessorPropagation/useEntityListSubTree.js.map +1 -1
- package/dist/production/accessorPropagation/useEntitySubTree.js +4 -2
- package/dist/production/accessorPropagation/useEntitySubTree.js.map +1 -1
- package/dist/production/accessorPropagation/useExtendTree.js +27 -0
- package/dist/production/accessorPropagation/useExtendTree.js.map +1 -0
- package/dist/production/accessorTree/AccessorTree.js +16 -14
- package/dist/production/accessorTree/AccessorTree.js.map +1 -1
- package/dist/production/accessorTree/AccessorTreeStateContext.js +4 -0
- package/dist/production/accessorTree/AccessorTreeStateContext.js.map +1 -0
- package/dist/production/accessorTree/NormalizedPersistedData.js.map +1 -1
- package/dist/production/accessorTree/RuntimeId.js +17 -4
- package/dist/production/accessorTree/RuntimeId.js.map +1 -1
- package/dist/production/accessorTree/accessorTreeStateReducer.js +11 -2
- package/dist/production/accessorTree/accessorTreeStateReducer.js.map +1 -1
- package/dist/production/accessorTree/useAccessorTreeState.js +12 -0
- package/dist/production/accessorTree/useAccessorTreeState.js.map +1 -0
- package/dist/production/accessorTree/useDataBinding.js +41 -51
- package/dist/production/accessorTree/useDataBinding.js.map +1 -1
- package/dist/production/accessors/EntityAccessor.js +19 -40
- package/dist/production/accessors/EntityAccessor.js.map +1 -1
- package/dist/production/accessors/EntityListAccessor.js +11 -11
- package/dist/production/accessors/EntityListAccessor.js.map +1 -1
- package/dist/production/accessors/FieldAccessor.js +6 -6
- package/dist/production/accessors/FieldAccessor.js.map +1 -1
- package/dist/production/core/AccessorErrorManager.js +5 -2
- package/dist/production/core/AccessorErrorManager.js.map +1 -1
- package/dist/production/core/Config.js +1 -2
- package/dist/production/core/Config.js.map +1 -1
- package/dist/production/core/DataBinding.js +27 -40
- package/dist/production/core/DataBinding.js.map +1 -1
- package/dist/production/core/DirtinessTracker.js +4 -13
- package/dist/production/core/DirtinessTracker.js.map +1 -1
- package/dist/production/core/ErrorsPreprocessor.js +9 -13
- package/dist/production/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/production/core/EventManager.js +12 -7
- package/dist/production/core/EventManager.js.map +1 -1
- package/dist/production/core/IncrementalMarkerBuilder.js +1 -1
- package/dist/production/core/MarkerMerger.js +2 -2
- package/dist/production/core/MutationGenerator.js +180 -141
- package/dist/production/core/MutationGenerator.js.map +1 -1
- package/dist/production/core/RequestResponseNormalizer.js +93 -134
- package/dist/production/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/production/core/StateInitializer.js +30 -38
- package/dist/production/core/StateInitializer.js.map +1 -1
- package/dist/production/core/TreeAugmenter.js +14 -14
- package/dist/production/core/TreeAugmenter.js.map +1 -1
- package/dist/production/core/TreeFilterGenerator.js +2 -2
- package/dist/production/core/TreeFilterGenerator.js.map +1 -1
- package/dist/production/core/TreeStore.js +12 -23
- package/dist/production/core/TreeStore.js.map +1 -1
- package/dist/production/core/VariableInputTransformer.js.map +1 -1
- package/dist/production/core/operations/EntityOperations.js +14 -13
- 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 +3 -3
- package/dist/production/core/operations/ListOperations.js.map +1 -1
- package/dist/production/core/operations/OperationsHelpers.js +2 -2
- package/dist/production/core/operations/OperationsHelpers.js.map +1 -1
- package/dist/production/core/requestAliases/MutationAlias.js +4 -33
- package/dist/production/core/requestAliases/MutationAlias.js.map +1 -1
- package/dist/production/core/schema/Schema.js +27 -3
- package/dist/production/core/schema/Schema.js.map +1 -1
- package/dist/production/core/schema/SchemaLoader.js +12 -12
- package/dist/production/core/schema/SchemaLoader.js.map +1 -1
- package/dist/production/core/schema/SchemaPreprocessor.js +1 -1
- package/dist/production/core/schema/SchemaPreprocessor.js.map +1 -1
- package/dist/production/coreComponents/Component.js +5 -2
- package/dist/production/coreComponents/Component.js.map +1 -1
- package/dist/production/coreComponents/DataBindingProvider.js +0 -1
- package/dist/production/coreComponents/DataBindingProvider.js.map +1 -1
- package/dist/production/coreComponents/EntityListSubTree.js.map +1 -1
- package/dist/production/coreComponents/HasOne.js +1 -1
- package/dist/production/dao/Environment.js +35 -3
- package/dist/production/dao/Environment.js.map +1 -1
- package/dist/production/dao/TreeNodeEnvironmentFactory.js +6 -13
- package/dist/production/dao/TreeNodeEnvironmentFactory.js.map +1 -1
- package/dist/production/helperComponents/DeferredSubTrees.js +16 -8
- package/dist/production/helperComponents/DeferredSubTrees.js.map +1 -1
- package/dist/production/helperComponents/If.js +39 -0
- package/dist/production/helperComponents/If.js.map +1 -0
- package/dist/production/helperComponents/SugaredField.js +1 -1
- package/dist/production/helperComponents/helpers/FilterEvaluator.js +35 -0
- package/dist/production/helperComponents/helpers/FilterEvaluator.js.map +1 -0
- package/dist/production/helperComponents/helpers/FilterFieldsCollector.js +38 -0
- package/dist/production/helperComponents/helpers/FilterFieldsCollector.js.map +1 -0
- package/dist/production/helperComponents/helpers/evaluateCondition.js +46 -0
- package/dist/production/helperComponents/helpers/evaluateCondition.js.map +1 -0
- package/dist/production/index.js +7 -2
- package/dist/production/index.js.map +1 -1
- package/dist/production/markers/EntityListSubTreeMarker.js +1 -1
- package/dist/production/markers/EntityListSubTreeMarker.js.map +1 -1
- package/dist/production/markers/EntitySubTreeMarker.js +1 -1
- package/dist/production/markers/EntitySubTreeMarker.js.map +1 -1
- package/dist/production/markers/PlaceholderGenerator.js +4 -4
- package/dist/production/markers/PlaceholderGenerator.js.map +1 -1
- package/dist/production/queryLanguage/MarkerFactory.js +2 -2
- package/dist/production/queryLanguage/QueryLanguage.js +1 -1
- package/dist/production/utils/Hashing.js +21 -6
- package/dist/production/utils/Hashing.js.map +1 -1
- package/dist/types/accessorPropagation/BindingOperationsContext.d.ts +1 -1
- package/dist/types/accessorPropagation/BindingOperationsContext.d.ts.map +1 -1
- package/dist/types/accessorPropagation/EntityKeyContext.d.ts +1 -1
- package/dist/types/accessorPropagation/EntityKeyContext.d.ts.map +1 -1
- package/dist/types/accessorPropagation/EnvironmentContext.d.ts +13 -2
- package/dist/types/accessorPropagation/EnvironmentContext.d.ts.map +1 -1
- package/dist/types/accessorPropagation/TreeRootIdContext.d.ts +1 -1
- package/dist/types/accessorPropagation/TreeRootIdContext.d.ts.map +1 -1
- package/dist/types/accessorPropagation/index.d.ts +1 -0
- package/dist/types/accessorPropagation/index.d.ts.map +1 -1
- package/dist/types/accessorPropagation/useEntityListSubTree.d.ts +2 -1
- package/dist/types/accessorPropagation/useEntityListSubTree.d.ts.map +1 -1
- package/dist/types/accessorPropagation/useEntitySubTree.d.ts +2 -1
- package/dist/types/accessorPropagation/useEntitySubTree.d.ts.map +1 -1
- package/dist/types/accessorPropagation/useExtendTree.d.ts +5 -0
- package/dist/types/accessorPropagation/useExtendTree.d.ts.map +1 -0
- package/dist/types/accessorSorting/SetOrderFieldOnCreate.d.ts +1 -1
- package/dist/types/accessorSorting/SetOrderFieldOnCreate.d.ts.map +1 -1
- package/dist/types/accessorTree/AccessorTree.d.ts.map +1 -1
- package/dist/types/accessorTree/AccessorTreeState.d.ts +8 -0
- package/dist/types/accessorTree/AccessorTreeState.d.ts.map +1 -1
- package/dist/types/accessorTree/AccessorTreeStateAction.d.ts +6 -0
- package/dist/types/accessorTree/AccessorTreeStateAction.d.ts.map +1 -1
- package/dist/types/accessorTree/AccessorTreeStateContext.d.ts +4 -0
- package/dist/types/accessorTree/AccessorTreeStateContext.d.ts.map +1 -0
- package/dist/types/accessorTree/AccessorTreeStateOptions.d.ts +0 -1
- package/dist/types/accessorTree/AccessorTreeStateOptions.d.ts.map +1 -1
- package/dist/types/accessorTree/DirtinessContext.d.ts +1 -1
- package/dist/types/accessorTree/DirtinessContext.d.ts.map +1 -1
- package/dist/types/accessorTree/MutationRequestResponse.d.ts +5 -1
- package/dist/types/accessorTree/MutationRequestResponse.d.ts.map +1 -1
- package/dist/types/accessorTree/MutationStateContext.d.ts +1 -1
- package/dist/types/accessorTree/MutationStateContext.d.ts.map +1 -1
- package/dist/types/accessorTree/NormalizedPersistedData.d.ts +5 -5
- package/dist/types/accessorTree/NormalizedPersistedData.d.ts.map +1 -1
- package/dist/types/accessorTree/PersistResult.d.ts +2 -1
- package/dist/types/accessorTree/PersistResult.d.ts.map +1 -1
- package/dist/types/accessorTree/QueryRequestResponse.d.ts +11 -10
- package/dist/types/accessorTree/QueryRequestResponse.d.ts.map +1 -1
- package/dist/types/accessorTree/RuntimeId.d.ts +16 -6
- package/dist/types/accessorTree/RuntimeId.d.ts.map +1 -1
- package/dist/types/accessorTree/accessorTreeStateReducer.d.ts.map +1 -1
- package/dist/types/accessorTree/index.d.ts +1 -0
- package/dist/types/accessorTree/index.d.ts.map +1 -1
- package/dist/types/accessorTree/useAccessorTreeState.d.ts +2 -0
- package/dist/types/accessorTree/useAccessorTreeState.d.ts.map +1 -0
- package/dist/types/accessorTree/useDataBinding.d.ts +1 -1
- package/dist/types/accessorTree/useDataBinding.d.ts.map +1 -1
- package/dist/types/accessors/BindingConfig.d.ts +0 -1
- package/dist/types/accessors/BindingConfig.d.ts.map +1 -1
- package/dist/types/accessors/EntityAccessor.d.ts +5 -5
- package/dist/types/accessors/EntityAccessor.d.ts.map +1 -1
- package/dist/types/accessors/EntityListAccessor.d.ts +4 -4
- package/dist/types/accessors/EntityListAccessor.d.ts.map +1 -1
- package/dist/types/accessors/FieldAccessor.d.ts +2 -2
- package/dist/types/accessors/FieldAccessor.d.ts.map +1 -1
- package/dist/types/core/AccessorErrorManager.d.ts +2 -1
- package/dist/types/core/AccessorErrorManager.d.ts.map +1 -1
- package/dist/types/core/Config.d.ts.map +1 -1
- package/dist/types/core/DataBinding.d.ts +3 -4
- package/dist/types/core/DataBinding.d.ts.map +1 -1
- package/dist/types/core/DirtinessTracker.d.ts +2 -5
- package/dist/types/core/DirtinessTracker.d.ts.map +1 -1
- package/dist/types/core/ErrorsPreprocessor.d.ts +5 -3
- package/dist/types/core/ErrorsPreprocessor.d.ts.map +1 -1
- package/dist/types/core/EventManager.d.ts +1 -1
- package/dist/types/core/EventManager.d.ts.map +1 -1
- package/dist/types/core/MutationGenerator.d.ts +25 -1
- package/dist/types/core/MutationGenerator.d.ts.map +1 -1
- package/dist/types/core/RequestResponseNormalizer.d.ts +6 -7
- package/dist/types/core/RequestResponseNormalizer.d.ts.map +1 -1
- package/dist/types/core/StateInitializer.d.ts +1 -5
- package/dist/types/core/StateInitializer.d.ts.map +1 -1
- package/dist/types/core/TreeAugmenter.d.ts +3 -2
- package/dist/types/core/TreeAugmenter.d.ts.map +1 -1
- package/dist/types/core/TreeStore.d.ts +8 -8
- package/dist/types/core/TreeStore.d.ts.map +1 -1
- package/dist/types/core/VariableInputTransformer.d.ts +2 -2
- package/dist/types/core/VariableInputTransformer.d.ts.map +1 -1
- package/dist/types/core/index.d.ts +1 -0
- package/dist/types/core/index.d.ts.map +1 -1
- package/dist/types/core/operations/EntityOperations.d.ts.map +1 -1
- package/dist/types/core/operations/ListOperations.d.ts +2 -1
- package/dist/types/core/operations/ListOperations.d.ts.map +1 -1
- package/dist/types/core/requestAliases/MutationAlias.d.ts +0 -3
- package/dist/types/core/requestAliases/MutationAlias.d.ts.map +1 -1
- package/dist/types/core/requestAliases/index.d.ts +0 -3
- package/dist/types/core/requestAliases/index.d.ts.map +1 -1
- package/dist/types/core/schema/RawSchemaEntity.d.ts +3 -2
- package/dist/types/core/schema/RawSchemaEntity.d.ts.map +1 -1
- package/dist/types/core/schema/Schema.d.ts +13 -3
- package/dist/types/core/schema/Schema.d.ts.map +1 -1
- package/dist/types/core/schema/SchemaColumn.d.ts +1 -1
- package/dist/types/core/schema/SchemaColumn.d.ts.map +1 -1
- package/dist/types/core/schema/SchemaEntity.d.ts +1 -1
- package/dist/types/core/schema/SchemaEntity.d.ts.map +1 -1
- package/dist/types/core/schema/SchemaLoader.d.ts +2 -1
- package/dist/types/core/schema/SchemaLoader.d.ts.map +1 -1
- package/dist/types/core/schema/SchemaRelation.d.ts +1 -1
- package/dist/types/core/schema/SchemaRelation.d.ts.map +1 -1
- package/dist/types/core/state/FieldState.d.ts +2 -2
- package/dist/types/core/state/FieldState.d.ts.map +1 -1
- package/dist/types/coreComponents/Component.d.ts +9 -4
- package/dist/types/coreComponents/Component.d.ts.map +1 -1
- package/dist/types/coreComponents/DataBindingProvider.d.ts +0 -1
- package/dist/types/coreComponents/DataBindingProvider.d.ts.map +1 -1
- package/dist/types/coreComponents/Entity.d.ts +1 -1
- package/dist/types/coreComponents/Entity.d.ts.map +1 -1
- package/dist/types/coreComponents/EntityListSubTree.d.ts.map +1 -1
- package/dist/types/coreComponents/Field.d.ts +1 -1
- package/dist/types/coreComponents/Field.d.ts.map +1 -1
- package/dist/types/coreComponents/ParentEntity.d.ts +1 -1
- package/dist/types/coreComponents/ParentEntity.d.ts.map +1 -1
- package/dist/types/dao/Environment.d.ts +14 -5
- package/dist/types/dao/Environment.d.ts.map +1 -1
- package/dist/types/dao/TreeNodeEnvironmentFactory.d.ts.map +1 -1
- package/dist/types/entityEvents/useDerivedField.d.ts +2 -2
- package/dist/types/entityEvents/useDerivedField.d.ts.map +1 -1
- package/dist/types/helperComponents/DeferredSubTrees.d.ts +1 -1
- package/dist/types/helperComponents/DeferredSubTrees.d.ts.map +1 -1
- package/dist/types/helperComponents/FieldView.d.ts +7 -7
- package/dist/types/helperComponents/FieldView.d.ts.map +1 -1
- package/dist/types/helperComponents/If.d.ts +14 -0
- package/dist/types/helperComponents/If.d.ts.map +1 -0
- package/dist/types/helperComponents/StaticRender.d.ts +1 -1
- package/dist/types/helperComponents/StaticRender.d.ts.map +1 -1
- package/dist/types/helperComponents/SugaredField.d.ts +1 -1
- package/dist/types/helperComponents/SugaredField.d.ts.map +1 -1
- package/dist/types/helperComponents/helpers/FilterEvaluator.d.ts +9 -0
- package/dist/types/helperComponents/helpers/FilterEvaluator.d.ts.map +1 -0
- package/dist/types/helperComponents/helpers/FilterFieldsCollector.d.ts +10 -0
- package/dist/types/helperComponents/helpers/FilterFieldsCollector.d.ts.map +1 -0
- package/dist/types/helperComponents/helpers/evaluateCondition.d.ts +4 -0
- package/dist/types/helperComponents/helpers/evaluateCondition.d.ts.map +1 -0
- package/dist/types/helperComponents/index.d.ts +1 -0
- package/dist/types/helperComponents/index.d.ts.map +1 -1
- package/dist/types/markers/FieldMarker.d.ts +3 -3
- package/dist/types/markers/FieldMarker.d.ts.map +1 -1
- package/dist/types/markers/PlaceholderGenerator.d.ts +3 -2
- package/dist/types/markers/PlaceholderGenerator.d.ts.map +1 -1
- package/dist/types/treeParameters/primitives/EntityId.d.ts +1 -1
- package/dist/types/treeParameters/primitives/EntityId.d.ts.map +1 -1
- package/dist/types/treeParameters/primitives/FieldValue.d.ts +2 -2
- package/dist/types/treeParameters/primitives/FieldValue.d.ts.map +1 -1
- package/dist/types/treeParameters/primitives/Json.d.ts +7 -0
- package/dist/types/treeParameters/primitives/Json.d.ts.map +1 -0
- package/dist/types/treeParameters/primitives/index.d.ts +1 -0
- package/dist/types/treeParameters/primitives/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/utils/Hashing.d.ts +3 -2
- package/dist/types/utils/Hashing.d.ts.map +1 -1
- package/package.json +7 -5
- package/src/accessorPropagation/EnvironmentContext.tsx +44 -0
- package/src/accessorPropagation/index.ts +1 -0
- package/src/accessorPropagation/useEntityListSubTree.ts +8 -1
- package/src/accessorPropagation/useEntitySubTree.ts +8 -1
- package/src/accessorPropagation/useExtendTree.ts +30 -0
- package/src/accessorTree/AccessorTree.tsx +18 -18
- package/src/accessorTree/AccessorTreeState.ts +12 -1
- package/src/accessorTree/AccessorTreeStateAction.ts +7 -1
- package/src/accessorTree/AccessorTreeStateContext.ts +4 -0
- package/src/accessorTree/AccessorTreeStateOptions.ts +0 -1
- package/src/accessorTree/MutationRequestResponse.ts +9 -1
- package/src/accessorTree/NormalizedPersistedData.ts +5 -5
- package/src/accessorTree/PersistResult.ts +2 -1
- package/src/accessorTree/QueryRequestResponse.ts +17 -14
- package/src/accessorTree/RuntimeId.ts +27 -6
- package/src/accessorTree/accessorTreeStateReducer.ts +10 -1
- package/src/accessorTree/index.ts +1 -0
- package/src/accessorTree/useAccessorTreeState.ts +11 -0
- package/src/accessorTree/useDataBinding.ts +41 -59
- package/src/accessors/BindingConfig.ts +0 -1
- package/src/accessors/EntityAccessor.ts +22 -58
- package/src/accessors/EntityListAccessor.ts +12 -12
- package/src/accessors/FieldAccessor.ts +5 -5
- package/src/core/AccessorErrorManager.ts +6 -2
- package/src/core/Config.ts +0 -1
- package/src/core/DataBinding.ts +28 -44
- package/src/core/DirtinessTracker.ts +4 -16
- package/src/core/ErrorsPreprocessor.ts +16 -18
- package/src/core/EventManager.ts +14 -8
- package/src/core/MutationGenerator.ts +249 -188
- package/src/core/RequestResponseNormalizer.ts +111 -163
- package/src/core/StateInitializer.ts +46 -58
- package/src/core/TreeAugmenter.ts +16 -15
- package/src/core/TreeFilterGenerator.ts +5 -5
- package/src/core/TreeStore.ts +23 -27
- package/src/core/VariableInputTransformer.ts +2 -2
- package/src/core/index.ts +1 -0
- package/src/core/operations/EntityOperations.ts +13 -14
- package/src/core/operations/FieldOperations.ts +2 -2
- package/src/core/operations/ListOperations.ts +6 -5
- package/src/core/operations/OperationsHelpers.ts +2 -2
- package/src/core/requestAliases/MutationAlias.ts +4 -57
- package/src/core/requestAliases/index.ts +0 -3
- package/src/core/schema/RawSchemaEntity.ts +1 -2
- package/src/core/schema/Schema.ts +38 -4
- package/src/core/schema/SchemaColumn.ts +1 -1
- package/src/core/schema/SchemaEntity.ts +1 -1
- package/src/core/schema/SchemaLoader.ts +13 -11
- package/src/core/schema/SchemaPreprocessor.ts +1 -1
- package/src/core/schema/SchemaRelation.ts +1 -1
- package/src/core/state/FieldState.ts +2 -2
- package/src/coreComponents/Component.tsx +20 -7
- package/src/coreComponents/DataBindingProvider.tsx +0 -2
- package/src/coreComponents/EntityListSubTree.tsx +2 -3
- package/src/dao/Environment.ts +48 -7
- package/src/dao/TreeNodeEnvironmentFactory.ts +8 -13
- package/src/helperComponents/DeferredSubTrees.tsx +20 -13
- package/src/helperComponents/If.tsx +71 -0
- package/src/helperComponents/helpers/FilterEvaluator.ts +46 -0
- package/src/helperComponents/helpers/FilterFieldsCollector.ts +46 -0
- package/src/helperComponents/helpers/evaluateCondition.ts +52 -0
- package/src/helperComponents/index.ts +1 -0
- package/src/markers/EntityListSubTreeMarker.ts +1 -1
- package/src/markers/EntitySubTreeMarker.ts +1 -1
- package/src/markers/PlaceholderGenerator.ts +5 -2
- package/src/treeParameters/primitives/EntityId.ts +1 -1
- package/src/treeParameters/primitives/FieldValue.ts +2 -2
- package/src/treeParameters/primitives/Json.ts +7 -0
- package/src/treeParameters/primitives/index.ts +1 -0
- package/src/typings/react-fix.d.ts +12 -0
- package/src/utils/Hashing.ts +23 -8
- package/dist/development/core/requestAliases/mutationOperationSubTreeType.js +0 -6
- package/dist/development/core/requestAliases/mutationOperationSubTreeType.js.map +0 -1
- package/dist/development/core/requestAliases/mutationOperationType.js +0 -7
- package/dist/development/core/requestAliases/mutationOperationType.js.map +0 -1
- package/dist/production/core/requestAliases/mutationOperationSubTreeType.js +0 -6
- package/dist/production/core/requestAliases/mutationOperationSubTreeType.js.map +0 -1
- package/dist/production/core/requestAliases/mutationOperationType.js +0 -7
- package/dist/production/core/requestAliases/mutationOperationType.js.map +0 -1
- package/dist/types/core/requestAliases/TopLevelMutationOperation.d.ts +0 -11
- package/dist/types/core/requestAliases/TopLevelMutationOperation.d.ts.map +0 -1
- package/dist/types/core/requestAliases/mutationOperationSubTreeType.d.ts +0 -5
- package/dist/types/core/requestAliases/mutationOperationSubTreeType.d.ts.map +0 -1
- package/dist/types/core/requestAliases/mutationOperationType.d.ts +0 -6
- package/dist/types/core/requestAliases/mutationOperationType.d.ts.map +0 -1
- package/src/accessorPropagation/EnvironmentContext.ts +0 -5
- package/src/core/requestAliases/TopLevelMutationOperation.ts +0 -11
- package/src/core/requestAliases/mutationOperationSubTreeType.ts +0 -4
- package/src/core/requestAliases/mutationOperationType.ts +0 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityOperations.js","sources":["../../../../src/core/operations/EntityOperations.ts"],"sourcesContent":["import type { BatchUpdatesOptions, EntityAccessor, ErrorAccessor } from '../../accessors'\nimport { ServerGeneratedUuid, UnpersistedEntityDummyId } from '../../accessorTree'\nimport { BindingError } from '../../BindingError'\nimport { EntityFieldMarkersContainer, HasOneRelationMarker } from '../../markers'\nimport type { FieldName } from '../../treeParameters'\nimport { assertNever } from '../../utils'\nimport type { AccessorErrorManager } from '../AccessorErrorManager'\nimport type { EventManager } from '../EventManager'\nimport { ErrorLocator, LocalizedBindingError } from '../exceptions'\nimport { MarkerComparator } from '../MarkerComparator'\nimport { EntityListState, EntityRealmState, EntityRealmStateStub, getEntityMarker, StateIterator } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\nimport { OperationsHelpers } from './OperationsHelpers'\nimport { EventListenersStore } from '../../treeParameters'\n\nexport class EntityOperations {\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic addError(entityRealm: EntityRealmState, error: ErrorAccessor.Error): () => void {\n\t\treturn this.accessorErrorManager.addError(entityRealm, error)\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityAccessor.RuntimeEntityEventListenerMap>(\n\t\tstate: EntityRealmState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\tif (state.eventListeners === undefined) {\n\t\t\tstate.eventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.eventListeners.add(event, listener)\n\t}\n\n\tpublic batchUpdates(state: EntityRealmState, performUpdates: EntityAccessor.BatchUpdatesHandler) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tperformUpdates(state.getAccessor, this.batchUpdatesOptions)\n\t\t})\n\t}\n\n\tpublic connectEntityAtField(outerState: EntityRealmState, fieldName: FieldName, entityToConnect: EntityAccessor) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst stateToConnect = OperationsHelpers.resolveAndPrepareEntityToConnect(this.treeStore, entityToConnect)\n\t\t\tconst fieldsToConnect = getEntityMarker(stateToConnect).fields\n\t\t\tconst persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.value)\n\n\t\t\tconst entityName = outerState.entity.entityName\n\t\t\tconst fieldSchema = this.treeStore.schema.getEntityField(entityName, fieldName)\n\n\t\t\tif (fieldSchema === undefined) {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`EntityAccessor.connectEntityAtField: Unknown field ${entityName}.${fieldName}.\\n\\n` +\n\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t)\n\t\t\t} else if (fieldSchema.__typename === '_Column') {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`EntityAccessor.connectEntityAtField: Cannot connect at field ${entityName}.${fieldName} because ` +\n\t\t\t\t\t\t`it's not a has-one relation.\\n\\n` +\n\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealm(outerState)) {\n\t\t\t\tconst targetHasOneMarkers = this.resolveHasOneRelationMarkers(\n\t\t\t\t\tgetEntityMarker(state).fields,\n\t\t\t\t\tfieldName,\n\t\t\t\t\t`Cannot connect at field '${fieldName}' as it doesn't refer to a has one relation.`,\n\t\t\t\t)\n\t\t\t\tfor (const targetHasOneMarker of targetHasOneMarkers) {\n\t\t\t\t\tconst previouslyConnectedState = state.children.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviouslyConnectedState === undefined ||\n\t\t\t\t\t\tpreviouslyConnectedState.type === 'field' ||\n\t\t\t\t\t\tpreviouslyConnectedState.type === 'entityList'\n\t\t\t\t\t) {\n\t\t\t\t\t\tOperationsHelpers.rejectInvalidAccessorTree()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (previouslyConnectedState.entity.entityName !== stateToConnect.entity.entityName) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`EntityAccessor.connectEntityAtField: Attempting to connect at field ${entityName}.${fieldName} ` +\n\t\t\t\t\t\t\t\t`an entity of type '${stateToConnect.entity.entityName}' but ` +\n\t\t\t\t\t\t\t\t`'${previouslyConnectedState.entity.entityName}' is expected.\\n\\n` +\n\t\t\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tMarkerComparator.assertEntityMarkersSubsetOf(targetHasOneMarker.fields, fieldsToConnect)\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (error instanceof LocalizedBindingError) {\n\t\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t\t`EntityAccessor: cannot connect entity with key '${entityToConnect.key}' because its fields are` +\n\t\t\t\t\t\t\t\t\t`incompatible with entities found at field '${fieldName}'. Make sure both trees are equivalent.\\n\\n` +\n\t\t\t\t\t\t\t\t\t`${error.message}\\n\\n` +\n\t\t\t\t\t\t\t\t\t(error.markerPath.length > 1\n\t\t\t\t\t\t\t\t\t\t? `Incompatibility found at: ${ErrorLocator.locateMarkerPath(error.markerPath)}.\\n\\n`\n\t\t\t\t\t\t\t\t\t\t: '') +\n\t\t\t\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(state)}.`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow error\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviouslyConnectedState === stateToConnect ||\n\t\t\t\t\t\tpreviouslyConnectedState.entity.id.value === stateToConnect.entity.id.value\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue // Do nothing.\n\t\t\t\t\t}\n\n\t\t\t\t\t// TODO remove from planned deletions if appropriate\n\n\t\t\t\t\tthis.treeStore.disposeOfRealm(previouslyConnectedState)\n\n\t\t\t\t\tlet changesDelta = 0\n\n\t\t\t\t\tif (previouslyConnectedState.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta -= previouslyConnectedState.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\tconst persistedId = persistedData?.get(targetHasOneMarker.placeholderName)\n\t\t\t\t\tif (persistedId instanceof ServerGeneratedUuid) {\n\t\t\t\t\t\tif (persistedId.value === stateToConnect.entity.id.value) {\n\t\t\t\t\t\t\tchangesDelta-- // It was removed from the list but now we're adding it back.\n\t\t\t\t\t\t} else if (persistedId.value === previouslyConnectedState.entity.id.value) {\n\t\t\t\t\t\t\tchangesDelta++ // We're changing it from the persisted id.\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (!previouslyConnectedState.entity.id.existsOnServer) {\n\t\t\t\t\t\t// This assumes the invariant enforced above that we cannot connect unpersisted entities.\n\t\t\t\t\t\t// Hence the previouslyConnectedState still refers to the entity created initially.\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tpersistedId === null || // We're updating.\n\t\t\t\t\t\t\t(persistedId === undefined && // We're creating.\n\t\t\t\t\t\t\t\t(!fieldsToConnect.hasAtLeastOneBearingField || !targetHasOneMarker.parameters.isNonbearing))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// TODO do something about the existing state…\n\n\t\t\t\t\tthis.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tstateToConnect.entity.id,\n\t\t\t\t\t\tstateToConnect.entity.entityName,\n\t\t\t\t\t\tpreviouslyConnectedState.blueprint,\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName)\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectEntityAtField(\n\t\touterState: EntityRealmState,\n\t\tfieldName: FieldName,\n\t\tinitializeReplacement: EntityAccessor.BatchUpdatesHandler | undefined,\n\t) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.value)\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealm(outerState)) {\n\t\t\t\tconst targetHasOneMarkers = this.resolveHasOneRelationMarkers(\n\t\t\t\t\tgetEntityMarker(state).fields,\n\t\t\t\t\tfieldName,\n\t\t\t\t\t`Cannot disconnect at field '${fieldName}' as it doesn't refer to a has one relation.`,\n\t\t\t\t)\n\t\t\t\tfor (const targetHasOneMarker of targetHasOneMarkers) {\n\t\t\t\t\tconst stateToDisconnect = state.children.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tstateToDisconnect === undefined ||\n\t\t\t\t\t\t(stateToDisconnect.type !== 'entityRealm' && stateToDisconnect.type !== 'entityRealmStub')\n\t\t\t\t\t) {\n\t\t\t\t\t\tOperationsHelpers.rejectInvalidAccessorTree()\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.disposeOfRealm(stateToDisconnect)\n\n\t\t\t\t\tlet changesDelta = 0\n\n\t\t\t\t\tif (stateToDisconnect.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta -= stateToDisconnect.unpersistedChangesCount\n\t\t\t\t\t}\n\t\t\t\t\tconst persistedId = persistedData?.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (persistedId instanceof ServerGeneratedUuid) {\n\t\t\t\t\t\tif (persistedId.value === stateToDisconnect.entity.id.value) {\n\t\t\t\t\t\t\tchangesDelta++ // Disconnecting the persisted entity.\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// Do nothing. The entity that is being disconnected is already different from the one that is persisted,\n\t\t\t\t\t\t\t// and so we must have already accounted for this change.\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (persistedId === undefined || persistedId === null) {\n\t\t\t\t\t\tif (stateToDisconnect.entity.id.existsOnServer) {\n\t\t\t\t\t\t\t// We had connected a persisted entity, which increased the changes count,\n\t\t\t\t\t\t\t// but now are disconnecting it again.\n\t\t\t\t\t\t\tchangesDelta--\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Do nothing. Disconnecting unpersisted entities doesn't change the count.\n\t\t\t\t\t}\n\n\t\t\t\t\tconst newEntity = this.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tnew UnpersistedEntityDummyId(),\n\t\t\t\t\t\tstateToDisconnect.entity.entityName,\n\t\t\t\t\t\tstateToDisconnect.blueprint,\n\t\t\t\t\t)\n\t\t\t\t\tthis.stateInitializer.runImmediateUserInitialization(newEntity, initializeReplacement)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName)\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic deleteEntity(realm: EntityRealmState) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst outerState = realm.entity\n\t\t\touterState.isScheduledForDeletion = true\n\n\t\t\tconst entityId = outerState.id\n\n\t\t\tfor (const realmToDelete of outerState.realms.values()) {\n\t\t\t\tlet parent: EntityRealmState | EntityRealmStateStub | EntityListState\n\t\t\t\tlet changesDelta = 0\n\n\t\t\t\tif (realmToDelete.blueprint.type === 'listEntity') {\n\t\t\t\t\tparent = realmToDelete.blueprint.parent\n\t\t\t\t\tparent.children.delete(entityId.value)\n\n\t\t\t\t\tif (entityId.existsOnServer) {\n\t\t\t\t\t\tif (parent.plannedRemovals === undefined) {\n\t\t\t\t\t\t\tparent.plannedRemovals = new Map()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\tparent.plannedRemovals.set(entityId.value, 'delete')\n\t\t\t\t\t}\n\t\t\t\t} else if (realmToDelete.blueprint.type === 'hasOne') {\n\t\t\t\t\tparent = realmToDelete.blueprint.parent\n\t\t\t\t\tconst placeholderName = realmToDelete.blueprint.marker.placeholderName\n\n\t\t\t\t\tif (entityId.existsOnServer) {\n\t\t\t\t\t\tif (parent.plannedHasOneDeletions === undefined) {\n\t\t\t\t\t\t\tparent.plannedHasOneDeletions = new Map()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\tparent.plannedHasOneDeletions.set(placeholderName, realmToDelete)\n\t\t\t\t\t}\n\t\t\t\t\tthis.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tnew UnpersistedEntityDummyId(),\n\t\t\t\t\t\touterState.entityName,\n\t\t\t\t\t\trealmToDelete.blueprint,\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(parent, placeholderName)\n\t\t\t\t} else if (realmToDelete.blueprint.type === 'subTree') {\n\t\t\t\t\tthrow new BindingError('Deleting top-level entities is not yet implemented.')\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(realmToDelete.blueprint)\n\t\t\t\t}\n\n\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t// Undoing whatever this had caused\n\t\t\t\t\tchangesDelta -= realmToDelete.unpersistedChangesCount\n\t\t\t\t}\n\t\t\t\tthis.eventManager.registerJustUpdated(parent, changesDelta)\n\n\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\tparent.childrenWithPendingUpdates?.delete(realmToDelete)\n\t\t\t\t}\n\n\t\t\t\tthis.treeStore.disposeOfRealm(realmToDelete)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate *resolveHasOneRelationMarkers(\n\t\tcontainer: EntityFieldMarkersContainer,\n\t\tfield: FieldName,\n\t\tmessage: string,\n\t): IterableIterator<HasOneRelationMarker> {\n\t\tconst placeholders = container.placeholders.get(field)\n\n\t\tif (placeholders === undefined) {\n\t\t\treturn\n\t\t}\n\t\tconst normalizedPlaceholders = placeholders instanceof Set ? placeholders : [placeholders]\n\n\t\tfor (const placeholderName of normalizedPlaceholders) {\n\t\t\tconst hasOneRelation = container.markers.get(placeholderName)\n\n\t\t\tif (!(hasOneRelation instanceof HasOneRelationMarker)) {\n\t\t\t\tthrow new BindingError(message)\n\t\t\t}\n\t\t\tyield hasOneRelation\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAgBO,MAAM,iBAAiB;AAAA,EACtB,YACW,sBACA,qBACA,cACA,kBACA,WAChB;AALgB,SAAA,uBAAA;AACA,SAAA,sBAAA;AACA,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AAAA,EACf;AAAA,EAEI,SAAS,aAA+B,OAAwC;AACtF,WAAO,KAAK,qBAAqB,SAAS,aAAa,KAAK;AAAA,EAC7D;AAAA,EAEO,iBACN,OACA,OACA,UACC;AACG,QAAA,MAAM,mBAAmB,QAAW;AACjC,YAAA,iBAAiB,IAAI;IAC5B;AACA,WAAO,MAAM,eAAe,IAAI,OAAO,QAAQ;AAAA,EAChD;AAAA,EAEO,aAAa,OAAyB,gBAAoD;AAC3F,SAAA,aAAa,cAAc,MAAM;AACtB,qBAAA,MAAM,aAAa,KAAK,mBAAmB;AAAA,IAAA,CAC1D;AAAA,EACF;AAAA,EAEO,qBAAqB,YAA8B,WAAsB,iBAAiC;AAC3G,SAAA,aAAa,cAAc,MAAM;AACrC,YAAM,iBAAiB,kBAAkB,iCAAiC,KAAK,WAAW,eAAe;AACnG,YAAA,kBAAkB,gBAAgB,cAAc,EAAE;AAClD,YAAA,gBAAgB,KAAK,UAAU,oBAAoB,IAAI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gB;AACxB,gBAAA,OAAO,2BAA2B,QAAW;AACzC,qBAAA,6CAA6B;YACrC;AACA;AACO,mBAAA,uBAAuB,IAAI,iBAAiB,aAAa;AAAA,UACjE;AACK,eAAA,iBAAiB,sBACrB,IAAI,yBAAA,GACJ,WAAW,YACX,cAAc,SACf;AAEK,eAAA,aAAa,0BAA0B,QAAQ,eAAe;AAAA,QACzD,WAAA,cAAc,UAAU,SAAS,WAAW;AAChD,gBAAA,IAAI,aAAa,qDAAqD;AAAA,QAAA,OACtE;AACC,iBAAA,YAAY,cAAc,SAAS;AAAA,QAC3C;AAEI,YAAA,cAAc,SAAS,eAAe;AAEzC,0BAAgB,cAAc;AAAA,QAC/B;AACK,aAAA,aAAa,oBAAoB,QAAQ,YAAY;AAEtD,YAAA,cAAc,SAAS,eAAe;AAClC,iBAAA,4BAA4B,OAAO,aAAa;AAAA,QACxD;AAEK,aAAA,UAAU,eAAe,aAAa;AAAA,MAC5C;AAAA,IAAA,CACA;AAAA,EACF;AAAA,GAES,6BACR,WACA,OACA,SACyC;AACzC,UAAM,eAAe,UAAU,aAAa,IAAI,KAAK;AAErD,QAAI,iBAAiB,QAAW;AAC/B;AAAA,IACD;AACA,UAAM,yBAAyB,wBAAwB,MAAM,eAAe,CAAC,YAAY;AAEzF,eAAW,mBAAmB,wBAAwB;AACrD,YAAM,iBAAiB,UAAU,QAAQ,IAAI,eAAe;AAExD,UAAA,4BAA4B,uBAAuB;AAChD,cAAA,IAAI,aAAa,OAAO;AAAA,MAC/B;AACM,YAAA;AAAA,IACP;AAAA,EACD;AACD;;"}
|
|
1
|
+
{"version":3,"file":"EntityOperations.js","sources":["../../../../src/core/operations/EntityOperations.ts"],"sourcesContent":["import type { BatchUpdatesOptions, EntityAccessor, ErrorAccessor } from '../../accessors'\nimport { ServerId, UnpersistedEntityDummyId } from '../../accessorTree'\nimport { BindingError } from '../../BindingError'\nimport { EntityFieldMarkersContainer, HasOneRelationMarker } from '../../markers'\nimport type { FieldName } from '../../treeParameters'\nimport { assertNever } from '../../utils'\nimport type { AccessorErrorManager } from '../AccessorErrorManager'\nimport type { EventManager } from '../EventManager'\nimport { ErrorLocator, LocalizedBindingError } from '../exceptions'\nimport { MarkerComparator } from '../MarkerComparator'\nimport { EntityListState, EntityRealmState, EntityRealmStateStub, getEntityMarker, StateIterator } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\nimport { OperationsHelpers } from './OperationsHelpers'\nimport { EventListenersStore } from '../../treeParameters'\n\nexport class EntityOperations {\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic addError(entityRealm: EntityRealmState, error: ErrorAccessor.Error): () => void {\n\t\treturn this.accessorErrorManager.addError(entityRealm, error)\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityAccessor.RuntimeEntityEventListenerMap>(\n\t\tstate: EntityRealmState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\tif (state.eventListeners === undefined) {\n\t\t\tstate.eventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.eventListeners.add(event, listener)\n\t}\n\n\tpublic batchUpdates(state: EntityRealmState, performUpdates: EntityAccessor.BatchUpdatesHandler) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tperformUpdates(state.getAccessor, this.batchUpdatesOptions)\n\t\t})\n\t}\n\n\tpublic connectEntityAtField(outerState: EntityRealmState, fieldName: FieldName, entityToConnect: EntityAccessor) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst stateToConnect = OperationsHelpers.resolveAndPrepareEntityToConnect(this.treeStore, entityToConnect)\n\t\t\tconst fieldsToConnect = getEntityMarker(stateToConnect).fields\n\t\t\tconst persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)\n\n\t\t\tconst entityName = outerState.entity.entityName\n\t\t\tconst fieldSchema = this.treeStore.schema.getEntityFieldOrUndefined(entityName, fieldName)\n\n\t\t\tif (fieldSchema === undefined) {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`EntityAccessor.connectEntityAtField: Unknown field ${entityName}.${fieldName}.\\n\\n` +\n\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t)\n\t\t\t} else if (fieldSchema.__typename === '_Column') {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`EntityAccessor.connectEntityAtField: Cannot connect at field ${entityName}.${fieldName} because ` +\n\t\t\t\t\t\t`it's not a has-one relation.\\n\\n` +\n\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealm(outerState)) {\n\t\t\t\tconst targetHasOneMarkers = this.resolveHasOneRelationMarkers(\n\t\t\t\t\tgetEntityMarker(state).fields,\n\t\t\t\t\tfieldName,\n\t\t\t\t\t`Cannot connect at field '${fieldName}' as it doesn't refer to a has one relation.`,\n\t\t\t\t)\n\t\t\t\tfor (const targetHasOneMarker of targetHasOneMarkers) {\n\t\t\t\t\tconst previouslyConnectedState = state.children.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviouslyConnectedState === undefined ||\n\t\t\t\t\t\tpreviouslyConnectedState.type === 'field' ||\n\t\t\t\t\t\tpreviouslyConnectedState.type === 'entityList'\n\t\t\t\t\t) {\n\t\t\t\t\t\tOperationsHelpers.rejectInvalidAccessorTree()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (previouslyConnectedState.entity.entityName !== stateToConnect.entity.entityName) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`EntityAccessor.connectEntityAtField: Attempting to connect at field ${entityName}.${fieldName} ` +\n\t\t\t\t\t\t\t\t`an entity of type '${stateToConnect.entity.entityName}' but ` +\n\t\t\t\t\t\t\t\t`'${previouslyConnectedState.entity.entityName}' is expected.\\n\\n` +\n\t\t\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tMarkerComparator.assertEntityMarkersSubsetOf(targetHasOneMarker.fields, fieldsToConnect)\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (error instanceof LocalizedBindingError) {\n\t\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t\t`EntityAccessor: cannot connect entity with key '${entityToConnect.key}' because its fields are` +\n\t\t\t\t\t\t\t\t\t`incompatible with entities found at field '${fieldName}'. Make sure both trees are equivalent.\\n\\n` +\n\t\t\t\t\t\t\t\t\t`${error.message}\\n\\n` +\n\t\t\t\t\t\t\t\t\t(error.markerPath.length > 1\n\t\t\t\t\t\t\t\t\t\t? `Incompatibility found at: ${ErrorLocator.locateMarkerPath(error.markerPath)}.\\n\\n`\n\t\t\t\t\t\t\t\t\t\t: '') +\n\t\t\t\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(state)}.`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow error\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviouslyConnectedState === stateToConnect ||\n\t\t\t\t\t\tpreviouslyConnectedState.entity.id.value === stateToConnect.entity.id.value\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue // Do nothing.\n\t\t\t\t\t}\n\n\t\t\t\t\t// TODO remove from planned deletions if appropriate\n\n\t\t\t\t\tthis.treeStore.disposeOfRealm(previouslyConnectedState)\n\n\t\t\t\t\tlet changesDelta = 0\n\n\t\t\t\t\tif (previouslyConnectedState.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta -= previouslyConnectedState.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\tconst persistedId = persistedData?.get(targetHasOneMarker.placeholderName)\n\t\t\t\t\tif (persistedId instanceof ServerId && persistedId.value === stateToConnect.entity.id.value) {\n\t\t\t\t\t\tchangesDelta-- // It was removed from the list but now we're adding it back.\n\t\t\t\t\t} else if (persistedId instanceof ServerId && persistedId.value === previouslyConnectedState.entity.id.value) {\n\t\t\t\t\t\tchangesDelta++ // We're changing it from the persisted id.\n\t\t\t\t\t} else if (!previouslyConnectedState.entity.id.existsOnServer) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tpersistedId === null || // We're updating.\n\t\t\t\t\t\t\t(persistedId === undefined && // We're creating.\n\t\t\t\t\t\t\t\t(!fieldsToConnect.hasAtLeastOneBearingField || !targetHasOneMarker.parameters.isNonbearing))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (stateToConnect.type === 'entityRealm') {\n\t\t\t\t\t\t\tchangesDelta += stateToConnect.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\t// TODO do something about the existing state…\n\n\t\t\t\t\tthis.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tstateToConnect.entity.id,\n\t\t\t\t\t\tstateToConnect.entity.entityName,\n\t\t\t\t\t\tpreviouslyConnectedState.blueprint,\n\t\t\t\t\t\tstateToConnect,\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName)\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectEntityAtField(\n\t\touterState: EntityRealmState,\n\t\tfieldName: FieldName,\n\t\tinitializeReplacement: EntityAccessor.BatchUpdatesHandler | undefined,\n\t) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealm(outerState)) {\n\t\t\t\tconst targetHasOneMarkers = this.resolveHasOneRelationMarkers(\n\t\t\t\t\tgetEntityMarker(state).fields,\n\t\t\t\t\tfieldName,\n\t\t\t\t\t`Cannot disconnect at field '${fieldName}' as it doesn't refer to a has one relation.`,\n\t\t\t\t)\n\t\t\t\tfor (const targetHasOneMarker of targetHasOneMarkers) {\n\t\t\t\t\tconst stateToDisconnect = state.children.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tstateToDisconnect === undefined ||\n\t\t\t\t\t\t(stateToDisconnect.type !== 'entityRealm' && stateToDisconnect.type !== 'entityRealmStub')\n\t\t\t\t\t) {\n\t\t\t\t\t\tOperationsHelpers.rejectInvalidAccessorTree()\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.disposeOfRealm(stateToDisconnect)\n\n\t\t\t\t\tlet changesDelta = 0\n\n\t\t\t\t\tif (stateToDisconnect.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta -= stateToDisconnect.unpersistedChangesCount\n\t\t\t\t\t}\n\t\t\t\t\tconst persistedId = persistedData?.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (persistedId instanceof ServerId) {\n\t\t\t\t\t\tif (persistedId.value === stateToDisconnect.entity.id.value) {\n\t\t\t\t\t\t\tchangesDelta++ // Disconnecting the persisted entity.\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// Do nothing. The entity that is being disconnected is already different from the one that is persisted,\n\t\t\t\t\t\t\t// and so we must have already accounted for this change.\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (persistedId === undefined || persistedId === null) {\n\t\t\t\t\t\tif (stateToDisconnect.entity.id.existsOnServer) {\n\t\t\t\t\t\t\t// We had connected a persisted entity, which increased the changes count,\n\t\t\t\t\t\t\t// but now are disconnecting it again.\n\t\t\t\t\t\t\tchangesDelta--\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Do nothing. Disconnecting unpersisted entities doesn't change the count.\n\t\t\t\t\t}\n\n\t\t\t\t\tconst newEntity = this.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tnew UnpersistedEntityDummyId(),\n\t\t\t\t\t\tstateToDisconnect.entity.entityName,\n\t\t\t\t\t\tstateToDisconnect.blueprint,\n\t\t\t\t\t)\n\t\t\t\t\tthis.stateInitializer.runImmediateUserInitialization(newEntity, initializeReplacement)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName)\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic deleteEntity(realm: EntityRealmState) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst outerState = realm.entity\n\t\t\touterState.isScheduledForDeletion = true\n\n\t\t\tconst entityId = outerState.id\n\n\t\t\tfor (const realmToDelete of outerState.realms.values()) {\n\t\t\t\tlet parent: EntityRealmState | EntityRealmStateStub | EntityListState\n\t\t\t\tlet changesDelta = 0\n\n\t\t\t\tif (realmToDelete.blueprint.type === 'listEntity') {\n\t\t\t\t\tparent = realmToDelete.blueprint.parent\n\t\t\t\t\tparent.children.delete(entityId.value)\n\n\t\t\t\t\tif (entityId.existsOnServer) {\n\t\t\t\t\t\tif (parent.plannedRemovals === undefined) {\n\t\t\t\t\t\t\tparent.plannedRemovals = new Map()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\tparent.plannedRemovals.set(entityId.value, 'delete')\n\t\t\t\t\t}\n\t\t\t\t} else if (realmToDelete.blueprint.type === 'hasOne') {\n\t\t\t\t\tparent = realmToDelete.blueprint.parent\n\t\t\t\t\tconst placeholderName = realmToDelete.blueprint.marker.placeholderName\n\n\t\t\t\t\tif (entityId.existsOnServer) {\n\t\t\t\t\t\tif (parent.plannedHasOneDeletions === undefined) {\n\t\t\t\t\t\t\tparent.plannedHasOneDeletions = new Map()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\tparent.plannedHasOneDeletions.set(placeholderName, realmToDelete)\n\t\t\t\t\t}\n\t\t\t\t\tthis.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tnew UnpersistedEntityDummyId(),\n\t\t\t\t\t\touterState.entityName,\n\t\t\t\t\t\trealmToDelete.blueprint,\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(parent, placeholderName)\n\t\t\t\t} else if (realmToDelete.blueprint.type === 'subTree') {\n\t\t\t\t\tthrow new BindingError('Deleting top-level entities is not yet implemented.')\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(realmToDelete.blueprint)\n\t\t\t\t}\n\n\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t// Undoing whatever this had caused\n\t\t\t\t\tchangesDelta -= realmToDelete.unpersistedChangesCount\n\t\t\t\t}\n\t\t\t\tthis.eventManager.registerJustUpdated(parent, changesDelta)\n\n\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\tparent.childrenWithPendingUpdates?.delete(realmToDelete)\n\t\t\t\t}\n\n\t\t\t\tthis.treeStore.disposeOfRealm(realmToDelete)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate *resolveHasOneRelationMarkers(\n\t\tcontainer: EntityFieldMarkersContainer,\n\t\tfield: FieldName,\n\t\tmessage: string,\n\t): IterableIterator<HasOneRelationMarker> {\n\t\tconst placeholders = container.placeholders.get(field)\n\n\t\tif (placeholders === undefined) {\n\t\t\treturn\n\t\t}\n\t\tconst normalizedPlaceholders = placeholders instanceof Set ? placeholders : [placeholders]\n\n\t\tfor (const placeholderName of normalizedPlaceholders) {\n\t\t\tconst hasOneRelation = container.markers.get(placeholderName)\n\n\t\t\tif (!(hasOneRelation instanceof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AAqD;AAAA,QAAA,OACtE;AACC,iBAAA,YAAY,cAAc,SAAS;AAAA,QAC3C;AAEI,YAAA,cAAc,SAAS,eAAe;AAEzC,0BAAgB,cAAc;AAAA,QAC/B;AACK,aAAA,aAAa,oBAAoB,QAAQ,YAAY;AAEtD,YAAA,cAAc,SAAS,eAAe;AAClC,iBAAA,4BAA4B,OAAO,aAAa;AAAA,QACxD;AAEK,aAAA,UAAU,eAAe,aAAa;AAAA,MAC5C;AAAA,IAAA,CACA;AAAA,EACF;AAAA,GAES,6BACR,WACA,OACA,SACyC;AACzC,UAAM,eAAe,UAAU,aAAa,IAAI,KAAK;AAErD,QAAI,iBAAiB,QAAW;AAC/B;AAAA,IACD;AACA,UAAM,yBAAyB,wBAAwB,MAAM,eAAe,CAAC,YAAY;AAEzF,eAAW,mBAAmB,wBAAwB;AACrD,YAAM,iBAAiB,UAAU,QAAQ,IAAI,eAAe;AAExD,UAAA,4BAA4B,uBAAuB;AAChD,cAAA,IAAI,aAAa,OAAO;AAAA,MAC/B;AACM,YAAA;AAAA,IACP;AAAA,EACD;AACD;;"}
|
|
@@ -5,7 +5,7 @@ import { EventManager } from "../EventManager.js";
|
|
|
5
5
|
import { OperationsHelpers } from "./OperationsHelpers.js";
|
|
6
6
|
import { EventListenersStore } from "../../treeParameters/EventListenersStore.js";
|
|
7
7
|
import { FieldAccessor } from "../../accessors/FieldAccessor.js";
|
|
8
|
-
import { ClientGeneratedUuid } from "../../accessorTree/RuntimeId.js";
|
|
8
|
+
import { ServerId, ClientGeneratedUuid } from "../../accessorTree/RuntimeId.js";
|
|
9
9
|
import { StateIterator } from "../state/StateIterator.js";
|
|
10
10
|
import { getEntityMarker } from "../state/getEntityMarker.js";
|
|
11
11
|
class FieldOperations {
|
|
@@ -41,7 +41,7 @@ Once set, it is immutable.`);
|
|
|
41
41
|
throw new BindingError(`Invalid value supplied for the '${PRIMARY_KEY_NAME}' field. Expecting a valid uuid but '${newValue}' was given.
|
|
42
42
|
Hint: you may use 'FieldAccessor.asUuid.setToUuid()'.`);
|
|
43
43
|
}
|
|
44
|
-
if (this.treeStore.entityStore.has(newValue)) {
|
|
44
|
+
if (this.treeStore.entityStore.has(ServerId.formatUniqueValue(newValue, entity.entityName))) {
|
|
45
45
|
throw new BindingError(`Trying to set the '${PRIMARY_KEY_NAME}' field to '${newValue}' which is a valid uuid but is not unique. It is already in use by an existing entity.`);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldOperations.js","sources":["../../../../src/core/operations/FieldOperations.ts"],"sourcesContent":["import { validate as uuidValidate } from 'uuid'\nimport { ErrorAccessor, FieldAccessor } from '../../accessors'\nimport { ClientGeneratedUuid } from '../../accessorTree'\nimport { BindingError } from '../../BindingError'\nimport { PRIMARY_KEY_NAME } from '../../bindingTypes'\nimport type { FieldValue } from '../../treeParameters'\nimport type { AccessorErrorManager } from '../AccessorErrorManager'\nimport { EventManager } from '../EventManager'\nimport { FieldState, getEntityMarker, StateIterator } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\nimport { OperationsHelpers } from './OperationsHelpers'\nimport { EventListenersStore } from '../../treeParameters'\n\nexport class FieldOperations {\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic addError(fieldState: FieldState<any>, error: ErrorAccessor.Error): () => void {\n\t\treturn this.accessorErrorManager.addError(fieldState, error)\n\t}\n\n\tpublic clearErrors(fieldState: FieldState<any>): void {\n\t\treturn this.accessorErrorManager.clearErrorsByState(fieldState)\n\t}\n\n\tpublic addEventListener<\n\t\tType extends keyof FieldAccessor.FieldEventListenerMap,\n\t\tValue extends FieldValue = FieldValue,\n\t>(\n\t\tstate: FieldState<Value>,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: FieldAccessor.FieldEventListenerMap<Value>[Type],\n\t): () => void {\n\t\tif (!state.eventListeners) {\n\t\t\tstate.eventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.eventListeners.add(event, listener)\n\t}\n\n\tpublic updateValue<Value extends FieldValue = FieldValue>(\n\t\tfieldState: FieldState<Value>,\n\t\tnewValue: Value | null,\n\t\t{ agent = FieldAccessor.userAgent }: FieldAccessor.UpdateOptions = {},\n\t) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst { placeholderName, parent } = fieldState\n\t\t\tif (placeholderName === PRIMARY_KEY_NAME) {\n\t\t\t\tconst entity = fieldState.parent.entity\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tif (newValue !== fieldState.value && (fieldState.touchLog !== undefined || entity.hasIdSetInStone)) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Trying to set the '${PRIMARY_KEY_NAME}' field for the second time. This is prohibited.\\n` +\n\t\t\t\t\t\t\t\t`Once set, it is immutable.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tif (typeof newValue !== 'string' || !uuidValidate(newValue)) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Invalid value supplied for the '${PRIMARY_KEY_NAME}' field. ` +\n\t\t\t\t\t\t\t\t`Expecting a valid uuid but '${newValue}' was given.\\n` +\n\t\t\t\t\t\t\t\t`Hint: you may use 'FieldAccessor.asUuid.setToUuid()'.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tif (this.treeStore.entityStore.has(newValue)) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Trying to set the '${PRIMARY_KEY_NAME}' field to '${newValue}' which is a valid uuid but is not unique. ` +\n\t\t\t\t\t\t\t\t`It is already in use by an existing entity.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (typeof newValue !== 'string') {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tOperationsHelpers.changeEntityId(\n\t\t\t\t\tthis.treeStore,\n\t\t\t\t\tthis.eventManager,\n\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\tentity,\n\t\t\t\t\tnew ClientGeneratedUuid(newValue),\n\t\t\t\t)\n\t\t\t}\n\t\t\tfor (const field of StateIterator.eachSiblingRealmChild(this.treeStore, fieldState)) {\n\t\t\t\tif (newValue === field.value) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (field.touchLog === undefined) {\n\t\t\t\t\tfield.touchLog = new Set()\n\t\t\t\t}\n\t\t\t\tfield.touchLog.add(agent)\n\t\t\t\tfield.value = newValue\n\n\t\t\t\tconst resolvedValue =\n\t\t\t\t\tfield.fieldMarker.defaultValue === undefined\n\t\t\t\t\t\t? newValue\n\t\t\t\t\t\t: newValue === null\n\t\t\t\t\t\t? field.fieldMarker.defaultValue\n\t\t\t\t\t\t: newValue\n\t\t\t\tconst normalizedPersistedValue = field.persistedValue === undefined ? null : field.persistedValue\n\t\t\t\tconst hadUnpersistedChangesBefore = field.hasUnpersistedChanges\n\t\t\t\tconst hasUnpersistedChangesNow = resolvedValue !== normalizedPersistedValue\n\t\t\t\tfield.hasUnpersistedChanges = hasUnpersistedChangesNow\n\n\t\t\t\tconst shouldInfluenceUpdateCount =\n\t\t\t\t\t!getEntityMarker(parent).fields.hasAtLeastOneBearingField ||\n\t\t\t\t\t!field.fieldMarker.isNonbearing ||\n\t\t\t\t\tfield.persistedValue !== undefined\n\n\t\t\t\tlet changesDelta = EventManager.NO_CHANGES_DIFFERENCE\n\n\t\t\t\tif (shouldInfluenceUpdateCount) {\n\t\t\t\t\tif (!hadUnpersistedChangesBefore && hasUnpersistedChangesNow) {\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t} else if (hadUnpersistedChangesBefore && !hasUnpersistedChangesNow) {\n\t\t\t\t\t\tchangesDelta--\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.registerJustUpdated(field, changesDelta)\n\t\t\t}\n\t\t})\n\t}\n}\n"],"names":["uuidValidate"],"mappings":";;;;;;;;;;AAcO,MAAM,gBAAgB;AAAA,EACrB,YACW,sBACA,cACA,kBACA,WAChB;AAJgB,SAAA,uBAAA;AACA,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AAAA,EACf;AAAA,EAEI,SAAS,YAA6B,OAAwC;AACpF,WAAO,KAAK,qBAAqB,SAAS,YAAY,KAAK;AAAA,EAC5D;AAAA,EAEO,YAAY,YAAmC;AAC9C,WAAA,KAAK,qBAAqB,mBAAmB,UAAU;AAAA,EAC/D;AAAA,EAEO,iBAIN,OACA,OACA,UACa;AACT,QAAA,CAAC,MAAM,gBAAgB;AACpB,YAAA,iBAAiB,IAAI;IAC5B;AACA,WAAO,MAAM,eAAe,IAAI,OAAO,QAAQ;AAAA,EAChD;AAAA,EAEO,YACN,YACA,UACA,EAAE,QAAQ,cAAc,cAA2C,IAClE;AACI,SAAA,aAAa,cAAc,MAAM;AAC/B,YAAA,EAAE,iBAAiB,WAAW;AACpC,UAAI,oBAAoB,kBAAkB;AACnC,cAAA,SAAS,WAAW,OAAO;AAER;AACxB,cAAI,aAAa,WAAW,qBAAqB,aAAa,UAAa,OAAO,kBAAkB;AAC7F,kBAAA,IAAI,aACT,sBAAsB;AAAA,2BAEvB;AAAA,UACD;AACA,cAAI,OAAO,aAAa,YAAY,CAACA,SAAa,QAAQ,GAAG;AACtD,kBAAA,IAAI,aACT,mCAAmC,wDACH;AAAA,sDAEjC;AAAA,UACD;
|
|
1
|
+
{"version":3,"file":"FieldOperations.js","sources":["../../../../src/core/operations/FieldOperations.ts"],"sourcesContent":["import { validate as uuidValidate } from 'uuid'\nimport { ErrorAccessor, FieldAccessor } from '../../accessors'\nimport { ClientGeneratedUuid, ServerId } from '../../accessorTree'\nimport { BindingError } from '../../BindingError'\nimport { PRIMARY_KEY_NAME } from '../../bindingTypes'\nimport type { FieldValue } from '../../treeParameters'\nimport type { AccessorErrorManager } from '../AccessorErrorManager'\nimport { EventManager } from '../EventManager'\nimport { FieldState, getEntityMarker, StateIterator } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\nimport { OperationsHelpers } from './OperationsHelpers'\nimport { EventListenersStore } from '../../treeParameters'\n\nexport class FieldOperations {\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic addError(fieldState: FieldState<any>, error: ErrorAccessor.Error): () => void {\n\t\treturn this.accessorErrorManager.addError(fieldState, error)\n\t}\n\n\tpublic clearErrors(fieldState: FieldState<any>): void {\n\t\treturn this.accessorErrorManager.clearErrorsByState(fieldState)\n\t}\n\n\tpublic addEventListener<\n\t\tType extends keyof FieldAccessor.FieldEventListenerMap,\n\t\tValue extends FieldValue = FieldValue,\n\t>(\n\t\tstate: FieldState<Value>,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: FieldAccessor.FieldEventListenerMap<Value>[Type],\n\t): () => void {\n\t\tif (!state.eventListeners) {\n\t\t\tstate.eventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.eventListeners.add(event, listener)\n\t}\n\n\tpublic updateValue<Value extends FieldValue = FieldValue>(\n\t\tfieldState: FieldState<Value>,\n\t\tnewValue: Value | null,\n\t\t{ agent = FieldAccessor.userAgent }: FieldAccessor.UpdateOptions = {},\n\t) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst { placeholderName, parent } = fieldState\n\t\t\tif (placeholderName === PRIMARY_KEY_NAME) {\n\t\t\t\tconst entity = fieldState.parent.entity\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tif (newValue !== fieldState.value && (fieldState.touchLog !== undefined || entity.hasIdSetInStone)) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Trying to set the '${PRIMARY_KEY_NAME}' field for the second time. This is prohibited.\\n` +\n\t\t\t\t\t\t\t\t`Once set, it is immutable.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tif (typeof newValue !== 'string' || !uuidValidate(newValue)) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Invalid value supplied for the '${PRIMARY_KEY_NAME}' field. ` +\n\t\t\t\t\t\t\t\t`Expecting a valid uuid but '${newValue}' was given.\\n` +\n\t\t\t\t\t\t\t\t`Hint: you may use 'FieldAccessor.asUuid.setToUuid()'.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tif (this.treeStore.entityStore.has(ServerId.formatUniqueValue(newValue, entity.entityName))) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Trying to set the '${PRIMARY_KEY_NAME}' field to '${newValue}' which is a valid uuid but is not unique. ` +\n\t\t\t\t\t\t\t\t`It is already in use by an existing entity.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (typeof newValue !== 'string') {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tOperationsHelpers.changeEntityId(\n\t\t\t\t\tthis.treeStore,\n\t\t\t\t\tthis.eventManager,\n\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\tentity,\n\t\t\t\t\tnew ClientGeneratedUuid(newValue),\n\t\t\t\t)\n\t\t\t}\n\t\t\tfor (const field of StateIterator.eachSiblingRealmChild(this.treeStore, fieldState)) {\n\t\t\t\tif (newValue === field.value) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (field.touchLog === undefined) {\n\t\t\t\t\tfield.touchLog = new Set()\n\t\t\t\t}\n\t\t\t\tfield.touchLog.add(agent)\n\t\t\t\tfield.value = newValue\n\n\t\t\t\tconst resolvedValue =\n\t\t\t\t\tfield.fieldMarker.defaultValue === undefined\n\t\t\t\t\t\t? newValue\n\t\t\t\t\t\t: newValue === null\n\t\t\t\t\t\t? field.fieldMarker.defaultValue\n\t\t\t\t\t\t: newValue\n\t\t\t\tconst normalizedPersistedValue = field.persistedValue === undefined ? null : field.persistedValue\n\t\t\t\tconst hadUnpersistedChangesBefore = field.hasUnpersistedChanges\n\t\t\t\tconst hasUnpersistedChangesNow = resolvedValue !== normalizedPersistedValue\n\t\t\t\tfield.hasUnpersistedChanges = hasUnpersistedChangesNow\n\n\t\t\t\tconst shouldInfluenceUpdateCount =\n\t\t\t\t\t!getEntityMarker(parent).fields.hasAtLeastOneBearingField ||\n\t\t\t\t\t!field.fieldMarker.isNonbearing ||\n\t\t\t\t\tfield.persistedValue !== undefined\n\n\t\t\t\tlet changesDelta = EventManager.NO_CHANGES_DIFFERENCE\n\n\t\t\t\tif (shouldInfluenceUpdateCount) {\n\t\t\t\t\tif (!hadUnpersistedChangesBefore && hasUnpersistedChangesNow) {\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t} else if (hadUnpersistedChangesBefore && !hasUnpersistedChangesNow) {\n\t\t\t\t\t\tchangesDelta--\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.registerJustUpdated(field, changesDelta)\n\t\t\t}\n\t\t})\n\t}\n}\n"],"names":["uuidValidate"],"mappings":";;;;;;;;;;AAcO,MAAM,gBAAgB;AAAA,EACrB,YACW,sBACA,cACA,kBACA,WAChB;AAJgB,SAAA,uBAAA;AACA,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AAAA,EACf;AAAA,EAEI,SAAS,YAA6B,OAAwC;AACpF,WAAO,KAAK,qBAAqB,SAAS,YAAY,KAAK;AAAA,EAC5D;AAAA,EAEO,YAAY,YAAmC;AAC9C,WAAA,KAAK,qBAAqB,mBAAmB,UAAU;AAAA,EAC/D;AAAA,EAEO,iBAIN,OACA,OACA,UACa;AACT,QA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B,kBAAkB;AACnD,cAAM,wBAAwB;AAE9B,cAAM,6BACL,CAAC,gBAAgB,MAAM,EAAE,OAAO,6BAChC,CAAC,MAAM,YAAY,gBACnB,MAAM,mBAAmB;AAE1B,YAAI,eAAe,aAAa;AAEhC,YAAI,4BAA4B;AAC3B,cAAA,CAAC,+BAA+B,0BAA0B;AAC7D;AAAA,UAAA,WACU,+BAA+B,CAAC,0BAA0B;AACpE;AAAA,UACD;AAAA,QACD;AAEK,aAAA,aAAa,oBAAoB,OAAO,YAAY;AAAA,MAC1D;AAAA,IAAA,CACA;AAAA,EACF;AACD;;"}
|
|
@@ -74,7 +74,7 @@ ${error.message}
|
|
|
74
74
|
let changesDelta = 0;
|
|
75
75
|
if (persistedEntityIds.has(idToConnect.value)) {
|
|
76
76
|
changesDelta--;
|
|
77
|
-
} else {
|
|
77
|
+
} else if (idToConnect.existsOnServer) {
|
|
78
78
|
changesDelta++;
|
|
79
79
|
}
|
|
80
80
|
if (stateToConnect.type === "entityRealm") {
|
|
@@ -131,11 +131,11 @@ ${error.message}
|
|
|
131
131
|
getChildEntityById(state, id) {
|
|
132
132
|
const realm = state.children.get(id);
|
|
133
133
|
if (realm === void 0) {
|
|
134
|
-
const isRuntimeId = validate(id) || UnpersistedEntityDummyId.matchesDummyId(id);
|
|
134
|
+
const isRuntimeId = typeof id === "number" || validate(id) || UnpersistedEntityDummyId.matchesDummyId(id);
|
|
135
135
|
if (isRuntimeId) {
|
|
136
136
|
throw new BindingError(`EntityList: cannot retrieve an entity with id '${id}' as it is not on the list.`);
|
|
137
137
|
}
|
|
138
|
-
const looksLikeKey = this.treeStore.entityRealmStore.has(id) || RealmKeyGenerator.vaguelyAppearsToBeAKey(id);
|
|
138
|
+
const looksLikeKey = typeof id === "string" && (this.treeStore.entityRealmStore.has(id) || RealmKeyGenerator.vaguelyAppearsToBeAKey(id));
|
|
139
139
|
throw new BindingError(`EntityList: cannot retrieve an entity with id '${id}' because it's not a valid id.` + (looksLikeKey ? `
|
|
140
140
|
The supplied value appears to be an entity *key*, not an *id*. List accessors are indexed by ids and you can use \`EntityAccessor.id\` to obtain one. Keys, on the other hand, are globally unique and you can use \`getEntityByKey\` to get its EntityAccessor.` : ""));
|
|
141
141
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListOperations.js","sources":["../../../../src/core/operations/ListOperations.ts"],"sourcesContent":["import { validate as uuidValidate } from 'uuid'\nimport type { BatchUpdatesOptions, EntityAccessor, EntityListAccessor, ErrorAccessor } from '../../accessors'\nimport { RuntimeId, UnpersistedEntityDummyId } from '../../accessorTree'\nimport { BindingError } from '../../BindingError'\nimport type { AccessorErrorManager } from '../AccessorErrorManager'\nimport { EventManager } from '../EventManager'\nimport { ErrorLocator, LocalizedBindingError } from '../exceptions'\nimport { MarkerComparator } from '../MarkerComparator'\nimport { RealmKeyGenerator } from '../RealmKeyGenerator'\nimport { EntityListState, getEntityMarker, StateIterator } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\nimport { OperationsHelpers } from './OperationsHelpers'\nimport { EventListenersStore } from '../../treeParameters'\n\nexport class ListOperations {\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic addError(listState: EntityListState, error: ErrorAccessor.Error): () => void {\n\t\treturn this.accessorErrorManager.addError(listState, error)\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityListAccessor.RuntimeEntityListEventListenerMap>(\n\t\tstate: EntityListState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityListAccessor.RuntimeEntityListEventListenerMap[Type],\n\t) {\n\t\tif (state.eventListeners === undefined) {\n\t\t\tstate.eventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.eventListeners.add(event, listener)\n\t}\n\n\tpublic addChildEventListener<Type extends keyof EntityAccessor.EntityEventListenerMap>(\n\t\tstate: EntityListState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\tif (state.childEventListeners === undefined) {\n\t\t\tstate.childEventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.childEventListeners.add(event, listener)\n\t}\n\n\tpublic batchUpdates(state: EntityListState, performUpdates: EntityListAccessor.BatchUpdatesHandler) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tperformUpdates(state.getAccessor, this.batchUpdatesOptions)\n\t\t})\n\t}\n\n\tpublic connectEntity(outerState: EntityListState, entityToConnect: EntityAccessor) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst persistedEntityIds = this.treeStore.getEntityListPersistedIds(outerState)\n\t\t\tconst stateToConnect = OperationsHelpers.resolveAndPrepareEntityToConnect(this.treeStore, entityToConnect)\n\t\t\tconst idToConnect = stateToConnect.entity.id\n\n\t\t\t// TODO disable this at the top-level.\n\t\t\tfor (const state of StateIterator.eachSiblingRealmChild(this.treeStore, outerState)) {\n\t\t\t\tif (state.entityName !== stateToConnect.entity.entityName) {\n\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t`EntityListAccessor.connectEntity: Attempting to connect at an entity of type ` +\n\t\t\t\t\t\t\t`'${stateToConnect.entity.entityName}' but '${state.entityName}' is expected.\\n\\n` +\n\t\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tMarkerComparator.assertEntityMarkersSubsetOf(\n\t\t\t\t\t\tstate.blueprint.marker.fields,\n\t\t\t\t\t\tgetEntityMarker(stateToConnect).fields,\n\t\t\t\t\t)\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (error instanceof LocalizedBindingError) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Entity list: cannot connect entity with key '${entityToConnect.key}' because its fields are ` +\n\t\t\t\t\t\t\t\t`incompatible with entities found on this list. Make sure both trees are equivalent.\\n\\n` +\n\t\t\t\t\t\t\t\t`${error.message}\\n\\n` +\n\t\t\t\t\t\t\t\t(error.markerPath.length > 1\n\t\t\t\t\t\t\t\t\t? `Incompatibility found at: ${ErrorLocator.locateMarkerPath(error.markerPath)}.\\n\\n`\n\t\t\t\t\t\t\t\t\t: '') +\n\t\t\t\t\t\t\t\t`Entity list located at: ${ErrorLocator.locateInternalState(state)}.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tthrow error\n\t\t\t\t}\n\n\t\t\t\tif (state.children.has(idToConnect.value)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tthis.stateInitializer.initializeEntityRealm(idToConnect, state.entityName, {\n\t\t\t\t\ttype: 'listEntity',\n\t\t\t\t\tparent: state,\n\t\t\t\t}, stateToConnect)\n\n\t\t\t\tstate.plannedRemovals?.delete(idToConnect.value)\n\n\t\t\t\tlet changesDelta = 0\n\n\t\t\t\tif (persistedEntityIds.has(idToConnect.value)) {\n\t\t\t\t\t// It was removed from the list but now we're adding it back.\n\t\t\t\t\tchangesDelta--\n\t\t\t\t} else {\n\t\t\t\t\tchangesDelta++\n\t\t\t\t}\n\t\t\t\tif (stateToConnect.type === 'entityRealm') {\n\t\t\t\t\tchangesDelta += stateToConnect.unpersistedChangesCount\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectEntity(listState: EntityListState, childEntity: EntityAccessor, options: {noPersist?: boolean}) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\t// TODO disable this at the top-level.\n\t\t\tconst persistedEntityIds = this.treeStore.getEntityListPersistedIds(listState)\n\t\t\tfor (const state of StateIterator.eachSiblingRealmChild(this.treeStore, listState)) {\n\t\t\t\tconst disconnectedChildIdValue = childEntity.id\n\t\t\t\tconst disconnectedChildRealm = state.children.get(disconnectedChildIdValue)\n\n\t\t\t\tif (disconnectedChildRealm === undefined) {\n\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t`Entity list doesn't include an entity with id '${disconnectedChildIdValue}' and so it cannot remove it.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\tthis.treeStore.disposeOfRealm(disconnectedChildRealm)\n\t\t\t\tlistState.children.delete(disconnectedChildIdValue)\n\n\t\t\t\tlet changesDelta = 0\n\n\t\t\t\tif (persistedEntityIds.has(disconnectedChildIdValue)) {\n\t\t\t\t\tchangesDelta++\n\n\t\t\t\t\tif (state.plannedRemovals === undefined) {\n\t\t\t\t\t\tstate.plannedRemovals = new Map()\n\t\t\t\t\t}\n\t\t\t\t\tif (!options.noPersist) {\n\t\t\t\t\t\tstate.plannedRemovals.set(disconnectedChildIdValue, 'disconnect')\n\t\t\t\t\t}\n\t\t\t\t} else if (disconnectedChildRealm.entity.id.existsOnServer) {\n\t\t\t\t\t// Disconnecting unpersisted entities doesn't constitute a change.\n\n\t\t\t\t\t// It wasn't on the list, then it was, and now we're removing it again.\n\t\t\t\t\tchangesDelta--\n\t\t\t\t}\n\n\t\t\t\tif (disconnectedChildRealm.type === 'entityRealm') {\n\t\t\t\t\t// Undoing whatever changes this child had caused.\n\t\t\t\t\tchangesDelta -= disconnectedChildRealm.unpersistedChangesCount\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic createNewEntity(outerState: EntityListState, initialize: EntityAccessor.BatchUpdatesHandler | undefined): RuntimeId {\n\t\treturn this.eventManager.syncOperation((): RuntimeId => {\n\t\t\t// All siblings need to have the same id.\n\t\t\tconst id = new UnpersistedEntityDummyId()\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealmChild(this.treeStore, outerState)) {\n\t\t\t\tconst newEntity = this.stateInitializer.initializeEntityRealm(id, state.entityName, {\n\t\t\t\t\ttype: 'listEntity',\n\t\t\t\t\tparent: state,\n\t\t\t\t})\n\n\t\t\t\tthis.stateInitializer.runImmediateUserInitialization(newEntity, initialize)\n\n\t\t\t\t// The act of creating the entity doesn't constitute a change unless there's something inside to persist.\n\t\t\t\t// TODO forceCreate\n\t\t\t\t// TODO defaultValue\n\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t}\n\t\t\treturn id\n\t\t})\n\t}\n\n\tpublic getChildEntityById(state: EntityListState, id: string) {\n\t\tconst realm = state.children.get(id)\n\t\tif (realm === undefined) {\n\t\t\tconst isRuntimeId = uuidValidate(id) || UnpersistedEntityDummyId.matchesDummyId(id)\n\t\t\tif (isRuntimeId) {\n\t\t\t\tthrow new BindingError(`EntityList: cannot retrieve an entity with id '${id}' as it is not on the list.`)\n\t\t\t}\n\t\t\tconst looksLikeKey = this.treeStore.entityRealmStore.has(id) || RealmKeyGenerator.vaguelyAppearsToBeAKey(id)\n\t\t\tthrow new BindingError(\n\t\t\t\t`EntityList: cannot retrieve an entity with id '${id}' because it's not a valid id.` +\n\t\t\t\t\t(looksLikeKey\n\t\t\t\t\t\t? `\\nThe supplied value appears to be an entity *key*, not an *id*. List accessors are indexed by ids ` +\n\t\t\t\t\t\t `and you can use \\`EntityAccessor.id\\` to obtain one. Keys, on the other hand, are globally unique and ` +\n\t\t\t\t\t\t `you can use \\`getEntityByKey\\` to get its EntityAccessor.`\n\t\t\t\t\t\t: ''),\n\t\t\t)\n\t\t}\n\t\treturn realm.getAccessor()\n\t}\n}\n"],"names":["uuidValidate"],"mappings":";;;;;;;;;;;;AAeO,MAAM,eAAe;AAAA,EACpB,YACW,sBACA,qBACA,cACA,kBACA,WAChB;AALgB,SAAA,uBAAA;AACA,SAAA,sBAAA;AACA,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AAAA,EACf;AAAA,EAEI,SAAS,WAA4B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,QACxC;AAEK,aAAA,aAAa,oBAAoB,OAAO,YAAY;AAAA,MAC1D;AAAA,IAAA,CACA;AAAA,EACF;AAAA,EAEO,gBAAgB,YAA6B,YAAuE;AACnH,WAAA,KAAK,aAAa,cAAc,MAAiB;AAEjD,YAAA,KAAK,IAAI;AAEf,iBAAW,SAAS,cAAc,sBAAsB,KAAK,WAAW,UAAU,GAAG;AACpF,cAAM,YAAY,KAAK,iBAAiB,sBAAsB,IAAI,MAAM,YAAY;AAAA,UACnF,MAAM;AAAA,UACN,QAAQ;AAAA,QAAA,CACR;AAEI,aAAA,iBAAiB,+BAA+B,WAAW,UAAU;AAK1E,aAAK,aAAa,oBAAoB,OAAO,aAAa,qBAAqB;AAAA,MAChF;AACO,aAAA;AAAA,IAAA,CACP;AAAA,EACF;AAAA,EAEO,mBAAmB,OAAwB,IAAY;AAC7D,UAAM,QAAQ,MAAM,SAAS,IAAI,EAAE;AACnC,QAAI,UAAU,QAAW;AACxB,YAAM,cAAcA,SAAa,EAAE,KAAK,yBAAyB,eAAe,EAAE;AAClF,UAAI,aAAa;AACV,cAAA,IAAI,aAAa,kDAAkD,+BAA+B;AAAA,MACzG;AACM,YAAA,eAAe,KAAK,UAAU,iBAAiB,IAAI,EAAE,KAAK,kBAAkB,uBAAuB,EAAE;AAC3G,YAAM,IAAI,aACT,kDAAkD,qCAE9C,gBAAA;AAAA,oQAGA,GACL;AAAA,IACD;AACA,WAAO,MAAM;EACd;AACD;;"}
|
|
1
|
+
{"version":3,"file":"ListOperations.js","sources":["../../../../src/core/operations/ListOperations.ts"],"sourcesContent":["import { validate as uuidValidate } from 'uuid'\nimport type { BatchUpdatesOptions, EntityAccessor, EntityListAccessor, ErrorAccessor } from '../../accessors'\nimport { RuntimeId, UnpersistedEntityDummyId } from '../../accessorTree'\nimport { BindingError } from '../../BindingError'\nimport type { AccessorErrorManager } from '../AccessorErrorManager'\nimport { EventManager } from '../EventManager'\nimport { ErrorLocator, LocalizedBindingError } from '../exceptions'\nimport { MarkerComparator } from '../MarkerComparator'\nimport { RealmKeyGenerator } from '../RealmKeyGenerator'\nimport { EntityListState, getEntityMarker, StateIterator } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\nimport { OperationsHelpers } from './OperationsHelpers'\nimport { EntityId, EventListenersStore } from '../../treeParameters'\n\nexport class ListOperations {\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic addError(listState: EntityListState, error: ErrorAccessor.Error): () => void {\n\t\treturn this.accessorErrorManager.addError(listState, error)\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityListAccessor.RuntimeEntityListEventListenerMap>(\n\t\tstate: EntityListState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityListAccessor.RuntimeEntityListEventListenerMap[Type],\n\t) {\n\t\tif (state.eventListeners === undefined) {\n\t\t\tstate.eventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.eventListeners.add(event, listener)\n\t}\n\n\tpublic addChildEventListener<Type extends keyof EntityAccessor.EntityEventListenerMap>(\n\t\tstate: EntityListState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\tif (state.childEventListeners === undefined) {\n\t\t\tstate.childEventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.childEventListeners.add(event, listener)\n\t}\n\n\tpublic batchUpdates(state: EntityListState, performUpdates: EntityListAccessor.BatchUpdatesHandler) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tperformUpdates(state.getAccessor, this.batchUpdatesOptions)\n\t\t})\n\t}\n\n\tpublic connectEntity(outerState: EntityListState, entityToConnect: EntityAccessor) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst persistedEntityIds = this.treeStore.getEntityListPersistedIds(outerState)\n\t\t\tconst stateToConnect = OperationsHelpers.resolveAndPrepareEntityToConnect(this.treeStore, entityToConnect)\n\t\t\tconst idToConnect = stateToConnect.entity.id\n\n\t\t\t// TODO disable this at the top-level.\n\t\t\tfor (const state of StateIterator.eachSiblingRealmChild(this.treeStore, outerState)) {\n\t\t\t\tif (state.entityName !== stateToConnect.entity.entityName) {\n\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t`EntityListAccessor.connectEntity: Attempting to connect at an entity of type ` +\n\t\t\t\t\t\t\t`'${stateToConnect.entity.entityName}' but '${state.entityName}' is expected.\\n\\n` +\n\t\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tMarkerComparator.assertEntityMarkersSubsetOf(\n\t\t\t\t\t\tstate.blueprint.marker.fields,\n\t\t\t\t\t\tgetEntityMarker(stateToConnect).fields,\n\t\t\t\t\t)\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (error instanceof LocalizedBindingError) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Entity list: cannot connect entity with key '${entityToConnect.key}' because its fields are ` +\n\t\t\t\t\t\t\t\t`incompatible with entities found on this list. Make sure both trees are equivalent.\\n\\n` +\n\t\t\t\t\t\t\t\t`${error.message}\\n\\n` +\n\t\t\t\t\t\t\t\t(error.markerPath.length > 1\n\t\t\t\t\t\t\t\t\t? `Incompatibility found at: ${ErrorLocator.locateMarkerPath(error.markerPath)}.\\n\\n`\n\t\t\t\t\t\t\t\t\t: '') +\n\t\t\t\t\t\t\t\t`Entity list located at: ${ErrorLocator.locateInternalState(state)}.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tthrow error\n\t\t\t\t}\n\n\t\t\t\tif (state.children.has(idToConnect.value)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tthis.stateInitializer.initializeEntityRealm(idToConnect, state.entityName, {\n\t\t\t\t\ttype: 'listEntity',\n\t\t\t\t\tparent: state,\n\t\t\t\t}, stateToConnect)\n\n\t\t\t\tstate.plannedRemovals?.delete(idToConnect.value)\n\n\t\t\t\tlet changesDelta = 0\n\n\t\t\t\tif (persistedEntityIds.has(idToConnect.value)) {\n\t\t\t\t\t// It was removed from the list but now we're adding it back.\n\t\t\t\t\tchangesDelta--\n\t\t\t\t} else if (idToConnect.existsOnServer) {\n\t\t\t\t\t// ignoring unpersisted entities\n\t\t\t\t\tchangesDelta++\n\t\t\t\t}\n\t\t\t\tif (stateToConnect.type === 'entityRealm') {\n\t\t\t\t\tchangesDelta += stateToConnect.unpersistedChangesCount\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectEntity(listState: EntityListState, childEntity: EntityAccessor, options: {noPersist?: boolean}) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\t// TODO disable this at the top-level.\n\t\t\tconst persistedEntityIds = this.treeStore.getEntityListPersistedIds(listState)\n\t\t\tfor (const state of StateIterator.eachSiblingRealmChild(this.treeStore, listState)) {\n\t\t\t\tconst disconnectedChildIdValue = childEntity.id\n\t\t\t\tconst disconnectedChildRealm = state.children.get(disconnectedChildIdValue)\n\n\t\t\t\tif (disconnectedChildRealm === undefined) {\n\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t`Entity list doesn't include an entity with id '${disconnectedChildIdValue}' and so it cannot remove it.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\tthis.treeStore.disposeOfRealm(disconnectedChildRealm)\n\t\t\t\tlistState.children.delete(disconnectedChildIdValue)\n\n\t\t\t\tlet changesDelta = 0\n\n\t\t\t\tif (persistedEntityIds.has(disconnectedChildIdValue)) {\n\t\t\t\t\tchangesDelta++\n\n\t\t\t\t\tif (state.plannedRemovals === undefined) {\n\t\t\t\t\t\tstate.plannedRemovals = new Map()\n\t\t\t\t\t}\n\t\t\t\t\tif (!options.noPersist) {\n\t\t\t\t\t\tstate.plannedRemovals.set(disconnectedChildIdValue, 'disconnect')\n\t\t\t\t\t}\n\t\t\t\t} else if (disconnectedChildRealm.entity.id.existsOnServer) {\n\t\t\t\t\t// Disconnecting unpersisted entities doesn't constitute a change.\n\n\t\t\t\t\t// It wasn't on the list, then it was, and now we're removing it again.\n\t\t\t\t\tchangesDelta--\n\t\t\t\t}\n\n\t\t\t\tif (disconnectedChildRealm.type === 'entityRealm') {\n\t\t\t\t\t// Undoing whatever changes this child had caused.\n\t\t\t\t\tchangesDelta -= disconnectedChildRealm.unpersistedChangesCount\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic createNewEntity(outerState: EntityListState, initialize: EntityAccessor.BatchUpdatesHandler | undefined): RuntimeId {\n\t\treturn this.eventManager.syncOperation((): RuntimeId => {\n\t\t\t// All siblings need to have the same id.\n\t\t\tconst id = new UnpersistedEntityDummyId()\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealmChild(this.treeStore, outerState)) {\n\t\t\t\tconst newEntity = this.stateInitializer.initializeEntityRealm(id, state.entityName, {\n\t\t\t\t\ttype: 'listEntity',\n\t\t\t\t\tparent: state,\n\t\t\t\t})\n\n\t\t\t\tthis.stateInitializer.runImmediateUserInitialization(newEntity, initialize)\n\n\t\t\t\t// The act of creating the entity doesn't constitute a change unless there's something inside to persist.\n\t\t\t\t// TODO forceCreate\n\t\t\t\t// TODO defaultValue\n\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t}\n\t\t\treturn id\n\t\t})\n\t}\n\n\tpublic getChildEntityById(state: EntityListState, id: EntityId) {\n\t\tconst realm = state.children.get(id)\n\t\tif (realm === undefined) {\n\t\t\tconst isRuntimeId = typeof id === 'number' || uuidValidate(id) || UnpersistedEntityDummyId.matchesDummyId(id)\n\t\t\tif (isRuntimeId) {\n\t\t\t\tthrow new BindingError(`EntityList: cannot retrieve an entity with id '${id}' as it is not on the list.`)\n\t\t\t}\n\t\t\tconst looksLikeKey = typeof id === 'string' && (this.treeStore.entityRealmStore.has(id) || RealmKeyGenerator.vaguelyAppearsToBeAKey(id))\n\t\t\tthrow new BindingError(\n\t\t\t\t`EntityList: cannot retrieve an entity with id '${id}' because it's not a valid id.` +\n\t\t\t\t\t(looksLikeKey\n\t\t\t\t\t\t? `\\nThe supplied value appears to be an entity *key*, not an *id*. List accessors are indexed by ids ` +\n\t\t\t\t\t\t `and you can use \\`EntityAccessor.id\\` to obtain one. Keys, on the other hand, are globally unique and ` +\n\t\t\t\t\t\t `you can use \\`getEntityByKey\\` to get its EntityAccessor.`\n\t\t\t\t\t\t: ''),\n\t\t\t)\n\t\t}\n\t\treturn realm.getAccessor()\n\t}\n}\n"],"names":["uuidValidate"],"mappings":";;;;;;;;;;;;AAeO,MAAM,eAAe;AAAA,EACpB,YACW,sBACA,qBACA,cACA,kBACA,WAChB;AALgB,SAAA,uBAAA;AACA,SAAA,sBAAA;AACA,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AAAA,EACf;AAAA,EAEI,SAAS,WAA4B,OAAwC;AACnF,WAAO,KAAK,qBAAqB,SAAS,WAAW,KAAK;AAAA,EAC3D;AAAA,EAEO,iBACN,OACA,OACA,UACC;AACG,QAAA,MAAM,mBAAmB,QAAW;AACjC,YAAA,iBAAiB,IAAI;IAC5B;AACA,WAAO,MAAM,eAAe,IAAI,OAAO,QAAQ;AAAA,EAChD;AAAA,EAEO,sBACN,OACA,OACA,UACC;AACG,QAAA,MAAM,wBAAwB,QAAW;AACtC,YAAA,sBAAsB,IAAI;IACjC;AACA,WAAO,MAAM,oBAAoB,IAAI,OAAO,QAAQ;AAAA,EACrD;AAAA,EAEO,aAAa,OAAwB,gBAAwD;AAC9F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;AAK1E,aAAK,aAAa,oBAAoB,OAAO,aAAa,qBAAqB;AAAA,MAChF;AACO,aAAA;AAAA,IAAA,CACP;AAAA,EACF;AAAA,EAEO,mBAAmB,OAAwB,IAAc;AAC/D,UAAM,QAAQ,MAAM,SAAS,IAAI,EAAE;AACnC,QAAI,UAAU,QAAW;AAClB,YAAA,cAAc,OAAO,OAAO,YAAYA,SAAa,EAAE,KAAK,yBAAyB,eAAe,EAAE;AAC5G,UAAI,aAAa;AACV,cAAA,IAAI,aAAa,kDAAkD,+BAA+B;AAAA,MACzG;AACA,YAAM,eAAe,OAAO,OAAO,YAAkB,MAAA,UAAU,iBAAiB,IAAI,EAAE,KAAK,kBAAkB,uBAAuB,EAAE;AACtI,YAAM,IAAI,aACT,kDAAkD,qCAE9C,gBAAA;AAAA,oQAGA,GACL;AAAA,IACD;AACA,WAAO,MAAM;EACd;AACD;;"}
|
|
@@ -16,8 +16,8 @@ class OperationsHelpers {
|
|
|
16
16
|
}
|
|
17
17
|
static changeEntityId(treeStore, eventManager, stateInitializer, entity, newId) {
|
|
18
18
|
const previousId = entity.id;
|
|
19
|
-
treeStore.entityStore.delete(previousId.
|
|
20
|
-
treeStore.entityStore.set(newId.
|
|
19
|
+
treeStore.entityStore.delete(previousId.uniqueValue);
|
|
20
|
+
treeStore.entityStore.set(newId.uniqueValue, entity);
|
|
21
21
|
let counter = 0;
|
|
22
22
|
for (const realm of entity.realms.values()) {
|
|
23
23
|
this.changeRealmId(treeStore, eventManager, stateInitializer, realm, newId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OperationsHelpers.js","sources":["../../../../src/core/operations/OperationsHelpers.ts"],"sourcesContent":["import type { EntityAccessor } from '../../accessors'\nimport type { RuntimeId } from '../../accessorTree'\nimport { BindingError } from '../../BindingError'\nimport { PRIMARY_KEY_NAME } from '../../bindingTypes'\nimport { EventManager } from '../EventManager'\nimport { RealmKeyGenerator } from '../RealmKeyGenerator'\nimport type { EntityRealmState, EntityRealmStateStub, EntityState } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\n\nexport class OperationsHelpers {\n\tpublic static rejectInvalidAccessorTree(): never {\n\t\tthrow new BindingError(\n\t\t\t`The accessor tree does not correspond to the MarkerTree. This should absolutely never happen.`,\n\t\t)\n\t}\n\n\tpublic static resolveAndPrepareEntityToConnect(\n\t\ttreeStore: TreeStore,\n\t\tentityToConnect: EntityAccessor,\n\t): EntityRealmState | EntityRealmStateStub {\n\t\tconst entityToConnectKey = entityToConnect.key\n\t\tconst stateToConnect = treeStore.entityRealmStore.get(entityToConnectKey)\n\n\t\tif (stateToConnect === undefined) {\n\t\t\tthrow new BindingError(`Attempting to connect an entity with key '${entityToConnectKey}' but it doesn't exist.`)\n\t\t}\n\t\t// TODO This is commented out for now in order to at least somewhat mitigate the limitations of dealing with\n\t\t//\t\tinverse relations. However, once that has been addressed systemically, this code needs to be re-enabled.\n\t\t// if (!stateToConnect.entity.id.existsOnServer) {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Attempting to connect an entity with key '${stateToConnect.realmKey}' that ` +\n\t\t// \t\t\t`doesn't exist on server. That is currently impossible.`, // At least for now.\n\t\t// \t)\n\t\t// }\n\n\t\t// TODO\n\t\t// if (stateToConnect.entity.isScheduledForDeletion) {\n\t\t// \t// As far as the other realms are concerned, this entity is deleted. We don't want to just make it re-appear\n\t\t// \t// for them just because some other random relation decided to connect it.\n\t\t// \tstateToConnect.entity.realms.clear()\n\t\t// \tstateToConnect.entity.isScheduledForDeletion = false\n\t\t// }\n\n\t\treturn stateToConnect\n\t}\n\n\tpublic static changeEntityId(\n\t\ttreeStore: TreeStore,\n\t\teventManager: EventManager,\n\t\tstateInitializer: StateInitializer,\n\t\tentity: EntityState,\n\t\tnewId: RuntimeId,\n\t) {\n\t\tconst previousId = entity.id\n\n\t\ttreeStore.entityStore.delete(previousId.
|
|
1
|
+
{"version":3,"file":"OperationsHelpers.js","sources":["../../../../src/core/operations/OperationsHelpers.ts"],"sourcesContent":["import type { EntityAccessor } from '../../accessors'\nimport type { RuntimeId } from '../../accessorTree'\nimport { BindingError } from '../../BindingError'\nimport { PRIMARY_KEY_NAME } from '../../bindingTypes'\nimport { EventManager } from '../EventManager'\nimport { RealmKeyGenerator } from '../RealmKeyGenerator'\nimport type { EntityRealmState, EntityRealmStateStub, EntityState } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\n\nexport class OperationsHelpers {\n\tpublic static rejectInvalidAccessorTree(): never {\n\t\tthrow new BindingError(\n\t\t\t`The accessor tree does not correspond to the MarkerTree. This should absolutely never happen.`,\n\t\t)\n\t}\n\n\tpublic static resolveAndPrepareEntityToConnect(\n\t\ttreeStore: TreeStore,\n\t\tentityToConnect: EntityAccessor,\n\t): EntityRealmState | EntityRealmStateStub {\n\t\tconst entityToConnectKey = entityToConnect.key\n\t\tconst stateToConnect = treeStore.entityRealmStore.get(entityToConnectKey)\n\n\t\tif (stateToConnect === undefined) {\n\t\t\tthrow new BindingError(`Attempting to connect an entity with key '${entityToConnectKey}' but it doesn't exist.`)\n\t\t}\n\t\t// TODO This is commented out for now in order to at least somewhat mitigate the limitations of dealing with\n\t\t//\t\tinverse relations. However, once that has been addressed systemically, this code needs to be re-enabled.\n\t\t// if (!stateToConnect.entity.id.existsOnServer) {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Attempting to connect an entity with key '${stateToConnect.realmKey}' that ` +\n\t\t// \t\t\t`doesn't exist on server. That is currently impossible.`, // At least for now.\n\t\t// \t)\n\t\t// }\n\n\t\t// TODO\n\t\t// if (stateToConnect.entity.isScheduledForDeletion) {\n\t\t// \t// As far as the other realms are concerned, this entity is deleted. We don't want to just make it re-appear\n\t\t// \t// for them just because some other random relation decided to connect it.\n\t\t// \tstateToConnect.entity.realms.clear()\n\t\t// \tstateToConnect.entity.isScheduledForDeletion = false\n\t\t// }\n\n\t\treturn stateToConnect\n\t}\n\n\tpublic static changeEntityId(\n\t\ttreeStore: TreeStore,\n\t\teventManager: EventManager,\n\t\tstateInitializer: StateInitializer,\n\t\tentity: EntityState,\n\t\tnewId: RuntimeId,\n\t) {\n\t\tconst previousId = entity.id\n\n\t\ttreeStore.entityStore.delete(previousId.uniqueValue)\n\t\ttreeStore.entityStore.set(newId.uniqueValue, entity)\n\n\t\tlet counter = 0\n\t\tfor (const realm of entity.realms.values()) {\n\t\t\tthis.changeRealmId(treeStore, eventManager, stateInitializer, realm, newId)\n\n\t\t\tif (++counter === entity.realms.size) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tentity.hasIdSetInStone = true\n\t\tentity.id = newId\n\t}\n\n\tpublic static changeRealmId(\n\t\ttreeStore: TreeStore,\n\t\teventManager: EventManager,\n\t\tstateInitializer: StateInitializer,\n\t\trealm: EntityRealmState | EntityRealmStateStub,\n\t\tnewId: RuntimeId,\n\t) {\n\t\tconst oldEntity = realm.entity\n\t\tconst oldRealmKey = realm.realmKey\n\t\tconst oldId = oldEntity.id\n\n\t\tconst realmBlueprint = realm.blueprint\n\n\t\tconst newEntity = stateInitializer.initializeEntityState(newId, oldEntity.entityName)\n\t\tconst newRealmKey = RealmKeyGenerator.getRealmKey(newId, realmBlueprint)\n\n\t\trealm.realmKey = newRealmKey\n\t\trealm.entity = newEntity\n\n\t\t// This may still actually be necessary if we're going from a client to server generated uuid.\n\t\t// They both may have the same value but still be different.\n\t\tnewEntity.id = newId\n\t\toldEntity.realms.delete(oldRealmKey)\n\t\tnewEntity.realms.set(newRealmKey, realm)\n\n\t\tif (realm.type === 'entityRealm') {\n\t\t\tconst childIdState = realm.children.get(PRIMARY_KEY_NAME)\n\t\t\tif (childIdState?.type === 'field') {\n\t\t\t\tchildIdState.value = newId.value\n\t\t\t\teventManager.registerJustUpdated(childIdState, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t}\n\n\t\t\tthis.purgeStaleListenersAfterIdChange(realm)\n\t\t}\n\n\t\tif (oldEntity.realms.size === 0) {\n\t\t\ttreeStore.disposeOfEntity(oldEntity)\n\t\t}\n\n\t\ttreeStore.entityRealmStore.delete(oldRealmKey)\n\t\ttreeStore.entityRealmStore.set(newRealmKey, realm)\n\n\t\tif (realmBlueprint.type === 'listEntity') {\n\t\t\tconst list = realmBlueprint.parent\n\t\t\tlist.children.changeKey(oldId.value, newId.value) // 😎\n\t\t} else if (realmBlueprint.type === 'hasOne') {\n\t\t\teventManager.registerUpdatedConnection(realmBlueprint.parent, realmBlueprint.marker.placeholderName)\n\t\t}\n\t\tconst parent = realmBlueprint.parent\n\t\tif (parent) {\n\t\t\teventManager.registerJustUpdated(parent, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t}\n\t\tif (realm.type === 'entityRealm') {\n\t\t\teventManager.registerJustUpdated(realm, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t}\n\t}\n\n\tpublic static purgeStaleListenersAfterIdChange(realm: EntityRealmState) {\n\t\t// Version 1.\n\t\t// The listeners subscribed to a particular entity key so we no longer want to call these.\n\t\t// The only positionally associated listeners are in the blueprint so we re-initialize those.\n\t\t//realm.eventListeners = stateInitializer.initializeEntityEventListenerStore(realmBlueprint)\n\n\t\t// Version 2.\n\t\t// This is version two of this terrible hack. We want to preserve e.g. persistSuccess handlers.\n\n\t\t// Version 3.\n\t\t// The saga continues. We add a condition to exempt top-level realms. That way they can start\n\t\t// propagating changes from the top.\n\t\tconst listeners = realm.eventListeners\n\t\tif (listeners) {\n\t\t\tif (realm.blueprint.parent) {\n\t\t\t\tlisteners.delete({ type: 'update' })\n\t\t\t}\n\t\t\tlisteners.deleteByType('connectionUpdate')\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;AAUO,MAAM,kBAAkB;AAAA,SAChB,4BAAmC;AAC1C,UAAA,IAAI,aACT,+FACD;AAAA,EACD;AAAA,SAEc,iCACb,WACA,iBAC0C;AAC1C,UAAM,qBAAqB,gBAAgB;AAC3C,UAAM,iBAAiB,UAAU,iBAAi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AE7C,QAAA,eAAe,SAAS,cAAc;AACzC,YAAM,OAAO,eAAe;AAC5B,WAAK,SAAS,UAAU,MAAM,OAAO,MAAM,KAAK;AAAA,IAAA,WACtC,eAAe,SAAS,UAAU;AAC5C,mBAAa,0BAA0B,eAAe,QAAQ,eAAe,OAAO,eAAe;AAAA,IACpG;AACA,UAAM,SAAS,eAAe;AAC9B,QAAI,QAAQ;AACE,mBAAA,oBAAoB,QAAQ,aAAa,qBAAqB;AAAA,IAC5E;AACI,QAAA,MAAM,SAAS,eAAe;AACpB,mBAAA,oBAAoB,OAAO,aAAa,qBAAqB;AAAA,IAC3E;AAAA,EACD;AAAA,SAEc,iCAAiC,OAAyB;AAYvE,UAAM,YAAY,MAAM;AACxB,QAAI,WAAW;AACV,UAAA,MAAM,UAAU,QAAQ;AAC3B,kBAAU,OAAO,EAAE,MAAM,SAAU,CAAA;AAAA,MACpC;AACA,gBAAU,aAAa,kBAAkB;AAAA,IAC1C;AAAA,EACD;AACD;;"}
|
|
@@ -1,47 +1,11 @@
|
|
|
1
|
-
import { BindingError } from "../../BindingError.js";
|
|
2
|
-
import { mutationOperationSubTreeType } from "./mutationOperationSubTreeType.js";
|
|
3
|
-
const mutationAliasRegex = /^(?:(u)|(t)([^t]+)t)(.+)__([cud])([sl])(.+)$/;
|
|
4
|
-
const uuidToAliasRegex = /-/g;
|
|
5
|
-
const uuidToAliasReplacement = "_";
|
|
6
|
-
const aliasToUuidRegex = /_/g;
|
|
7
|
-
const aliasToUuidReplacement = "-";
|
|
8
|
-
const standaloneUuidPrefix = uuidToAliasReplacement;
|
|
9
1
|
class MutationAlias {
|
|
10
|
-
static encodeTopLevel(operation) {
|
|
11
|
-
const treeRootId = operation.treeRootId === void 0 ? "u" : `t${operation.treeRootId.replace("-", "_")}t`;
|
|
12
|
-
const entityId = operation.entityId.replace(uuidToAliasRegex, uuidToAliasReplacement);
|
|
13
|
-
const alias = `${treeRootId}${operation.subTreePlaceholder}__${operation.type}${operation.subTreeType}${entityId}`;
|
|
14
|
-
{
|
|
15
|
-
const matches = alias.match(mutationAliasRegex);
|
|
16
|
-
if (!matches) {
|
|
17
|
-
throw new BindingError();
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return alias;
|
|
21
|
-
}
|
|
22
|
-
static decodeTopLevel(alias) {
|
|
23
|
-
const matches = alias.match(mutationAliasRegex);
|
|
24
|
-
if (!matches) {
|
|
25
|
-
return void 0;
|
|
26
|
-
}
|
|
27
|
-
const treeRootId = matches[1] === "u" ? void 0 : matches[3];
|
|
28
|
-
const subTreePlaceholder = matches[4];
|
|
29
|
-
const type = matches[5];
|
|
30
|
-
const subTreeType = matches[6] === "s" ? mutationOperationSubTreeType.singleEntity : mutationOperationSubTreeType.entityList;
|
|
31
|
-
const entityId = matches[7].replace(aliasToUuidRegex, aliasToUuidReplacement);
|
|
32
|
-
return {
|
|
33
|
-
treeRootId,
|
|
34
|
-
subTreePlaceholder,
|
|
35
|
-
type,
|
|
36
|
-
subTreeType,
|
|
37
|
-
entityId
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
2
|
static encodeEntityId(entityId) {
|
|
41
|
-
return
|
|
3
|
+
return `_${String(entityId.value).replace(/-/g, "_")}`;
|
|
42
4
|
}
|
|
43
5
|
static decodeEntityId(alias) {
|
|
44
|
-
|
|
6
|
+
const stringId = `${alias.substring(1).replace(/_/g, "-")}`;
|
|
7
|
+
const intId = parseInt(stringId);
|
|
8
|
+
return intId.toString() === stringId ? intId : stringId;
|
|
45
9
|
}
|
|
46
10
|
}
|
|
47
11
|
export { MutationAlias };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MutationAlias.js","sources":["../../../../src/core/requestAliases/MutationAlias.ts"],"sourcesContent":["import type { RuntimeId } from '../../accessorTree'\
|
|
1
|
+
{"version":3,"file":"MutationAlias.js","sources":["../../../../src/core/requestAliases/MutationAlias.ts"],"sourcesContent":["import type { RuntimeId } from '../../accessorTree'\n\nexport class MutationAlias {\n\tpublic static encodeEntityId(entityId: RuntimeId): string {\n\t\treturn `_${String(entityId.value).replace(/-/g, '_')}`\n\t}\n\n\tpublic static decodeEntityId(alias: string): RuntimeId['value'] {\n\t\tconst stringId = `${alias.substring(1).replace(/_/g, '-')}`\n\t\tconst intId = parseInt(stringId)\n\t\treturn intId.toString() === stringId ? intId : stringId\n\t}\n}\n"],"names":[],"mappings":"AAEO,MAAM,cAAc;AAAA,SACZ,eAAe,UAA6B;AACzD,WAAO,IAAI,OAAO,SAAS,KAAK,EAAE,QAAQ,MAAM,GAAG;AAAA,EACpD;AAAA,SAEc,eAAe,OAAmC;AACzD,UAAA,WAAW,GAAG,MAAM,UAAU,CAAC,EAAE,QAAQ,MAAM,GAAG;AAClD,UAAA,QAAQ,SAAS,QAAQ;AAC/B,WAAO,MAAM,SAAA,MAAe,WAAW,QAAQ;AAAA,EAChD;AACD;;"}
|
|
@@ -1,12 +1,36 @@
|
|
|
1
|
+
import { BindingError } from "../../BindingError.js";
|
|
1
2
|
class Schema {
|
|
2
3
|
constructor(store) {
|
|
3
4
|
this.store = store;
|
|
4
5
|
}
|
|
5
|
-
|
|
6
|
+
getEnumValues(enumName) {
|
|
7
|
+
return Array.from(this.store.enums.get(enumName) ?? this.throwError(`Missing schema for enum ${enumName}`));
|
|
8
|
+
}
|
|
9
|
+
getEntityOrUndefined(entityName) {
|
|
6
10
|
return this.store.entities.get(entityName);
|
|
7
11
|
}
|
|
8
|
-
|
|
9
|
-
return this.store.entities.
|
|
12
|
+
getEntityNames() {
|
|
13
|
+
return Array.from(this.store.entities.keys());
|
|
14
|
+
}
|
|
15
|
+
getEntity(entityName) {
|
|
16
|
+
return this.getEntityOrUndefined(entityName) ?? this.throwError(`Missing schema for entity ${entityName}`);
|
|
17
|
+
}
|
|
18
|
+
getEntityFieldOrUndefined(entityName, fieldName) {
|
|
19
|
+
return this.store.entities.get(entityName)?.fields.get(fieldName);
|
|
20
|
+
}
|
|
21
|
+
getEntityField(entityName, fieldName) {
|
|
22
|
+
return this.getEntityFieldOrUndefined(entityName, fieldName) ?? this.throwError(`Missing schema for field ${entityName}.${fieldName}`);
|
|
23
|
+
}
|
|
24
|
+
getEntityColumn(entityName, fieldName) {
|
|
25
|
+
const field = this.getEntityField(entityName, fieldName);
|
|
26
|
+
return field.__typename === "_Column" ? field : this.throwError(`Field ${entityName}.${fieldName} is not of type column`);
|
|
27
|
+
}
|
|
28
|
+
getEntityRelation(entityName, fieldName) {
|
|
29
|
+
const field = this.getEntityField(entityName, fieldName);
|
|
30
|
+
return field.__typename === "_Relation" ? field : this.throwError(`Field ${entityName}.${fieldName} is not of type relation`);
|
|
31
|
+
}
|
|
32
|
+
throwError(message) {
|
|
33
|
+
throw new BindingError(message);
|
|
10
34
|
}
|
|
11
35
|
}
|
|
12
36
|
export { Schema };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.js","sources":["../../../../src/core/schema/Schema.ts"],"sourcesContent":["import type { EntityName, FieldName } from '../../treeParameters'\nimport type { SchemaField } from './SchemaField'\nimport type { SchemaStore } from './SchemaStore'\nimport { SchemaEntity } from './SchemaEntity'\n\nexport class Schema {\n\tpublic constructor(
|
|
1
|
+
{"version":3,"file":"Schema.js","sources":["../../../../src/core/schema/Schema.ts"],"sourcesContent":["import type { EntityName, FieldName } from '../../treeParameters'\nimport { BindingError } from '../../BindingError'\nimport type { SchemaField } from './SchemaField'\nimport type { SchemaStore } from './SchemaStore'\nimport { SchemaEntity } from './SchemaEntity'\nimport { SchemaColumn } from './SchemaColumn'\nimport { SchemaRelation } from './SchemaRelation'\nimport { SchemaEnumName } from './SchemaEnums'\n\nexport class Schema {\n\tpublic constructor(private readonly store: SchemaStore) {}\n\n\tpublic getEnumValues(enumName: SchemaEnumName): string[] {\n\t\treturn Array.from(this.store.enums.get(enumName) ?? this.throwError(`Missing schema for enum ${enumName}`))\n\t}\n\n\tpublic getEntityOrUndefined(entityName: EntityName): SchemaEntity | undefined {\n\t\treturn this.store.entities.get(entityName)\n\t}\n\n\tpublic getEntityNames(): string[] {\n\t\treturn Array.from(this.store.entities.keys())\n\t}\n\n\tpublic getEntity(entityName: EntityName): SchemaEntity {\n\t\treturn this.getEntityOrUndefined(entityName) ?? this.throwError(`Missing schema for entity ${entityName}`)\n\t}\n\n\tpublic getEntityFieldOrUndefined(entityName: EntityName, fieldName: FieldName): SchemaField | undefined {\n\t\treturn this.store.entities.get(entityName)?.fields.get(fieldName)\n\t}\n\n\tpublic getEntityField(entityName: EntityName, fieldName: FieldName): SchemaField {\n\t\treturn this.getEntityFieldOrUndefined(entityName, fieldName) ?? this.throwError(`Missing schema for field ${entityName}.${fieldName}`)\n\t}\n\n\tpublic getEntityColumn(entityName: EntityName, fieldName: FieldName): SchemaColumn {\n\t\tconst field = this.getEntityField(entityName, fieldName)\n\t\treturn field.__typename === '_Column' ? field : this.throwError(`Field ${entityName}.${fieldName} is not of type column`)\n\t}\n\n\tpublic getEntityRelation(entityName: EntityName, fieldName: FieldName): SchemaRelation {\n\t\tconst field = this.getEntityField(entityName, fieldName)\n\t\treturn field.__typename === '_Relation' ? field : this.throwError(`Field ${entityName}.${fieldName} is not of type relation`)\n\t}\n\n\tprivate throwError(message: string): never {\n\t\tthrow new BindingError(message)\n\t}\n}\n"],"names":[],"mappings":";AASO,MAAM,OAAO;AAAA,EACZ,YAA6B,OAAoB;AAApB,SAAA,QAAA;AAAA,EAAqB;AAAA,EAElD,cAAc,UAAoC;AACxD,WAAO,MAAM,KAAK,KAAK,MAAM,MAAM,IAAI,QAAQ,KAAK,KAAK,WAAW,2BAA2B,UAAU,CAAC;AAAA,EAC3G;AAAA,EAEO,qBAAqB,YAAkD;AAC7E,WAAO,KAAK,MAAM,SAAS,IAAI,UAAU;AAAA,EAC1C;AAAA,EAEO,iBAA2B;AACjC,WAAO,MAAM,KAAK,KAAK,MAAM,SAAS,MAAM;AAAA,EAC7C;AAAA,EAEO,UAAU,YAAsC;AACtD,WAAO,KAAK,qBAAqB,UAAU,KAAK,KAAK,WAAW,6BAA6B,YAAY;AAAA,EAC1G;AAAA,EAEO,0BAA0B,YAAwB,WAA+C;AAChG,WAAA,KAAK,MAAM,SAAS,IAAI,UAAU,GAAG,OAAO,IAAI,SAAS;AAAA,EACjE;AAAA,EAEO,eAAe,YAAwB,WAAmC;AACzE,WAAA,KAAK,0BAA0B,YAAY,SAAS,KAAK,KAAK,WAAW,4BAA4B,cAAc,WAAW;AAAA,EACtI;AAAA,EAEO,gBAAgB,YAAwB,WAAoC;AAClF,UAAM,QAAQ,KAAK,eAAe,YAAY,SAAS;AAChD,WAAA,MAAM,eAAe,YAAY,QAAQ,KAAK,WAAW,SAAS,cAAc,iCAAiC;AAAA,EACzH;AAAA,EAEO,kBAAkB,YAAwB,WAAsC;AACtF,UAAM,QAAQ,KAAK,eAAe,YAAY,SAAS;AAChD,WAAA,MAAM,eAAe,cAAc,QAAQ,KAAK,WAAW,SAAS,cAAc,mCAAmC;AAAA,EAC7H;AAAA,EAEQ,WAAW,SAAwB;AACpC,UAAA,IAAI,aAAa,OAAO;AAAA,EAC/B;AACD;;"}
|
|
@@ -7,20 +7,20 @@ var __publicField = (obj, key, value) => {
|
|
|
7
7
|
import { Schema } from "./Schema.js";
|
|
8
8
|
import { SchemaPreprocessor } from "./SchemaPreprocessor.js";
|
|
9
9
|
class SchemaLoader {
|
|
10
|
-
static async loadSchema(client,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
10
|
+
static async loadSchema(client, options) {
|
|
11
|
+
const existing = this.schemaLoadCache.get(client.apiUrl);
|
|
12
|
+
if (existing !== void 0) {
|
|
13
|
+
return existing;
|
|
14
|
+
}
|
|
15
|
+
const schemaPromise = (async () => {
|
|
16
|
+
const raw = await client.sendRequest(this.schemaQuery, options);
|
|
17
|
+
return new Schema(SchemaPreprocessor.processRawSchema(raw.data.schema));
|
|
18
|
+
})();
|
|
19
|
+
this.schemaLoadCache.set(client.apiUrl, schemaPromise);
|
|
20
|
+
return await schemaPromise;
|
|
22
21
|
}
|
|
23
22
|
}
|
|
23
|
+
__publicField(SchemaLoader, "schemaLoadCache", /* @__PURE__ */ new Map());
|
|
24
24
|
__publicField(SchemaLoader, "schemaQuery", "query {\n schema {\n enums {\n name\n values\n }\n entities {\n name\n customPrimaryAllowed\n unique {\n fields\n }\n fields {\n __typename\n name\n type\n nullable\n ... on _Column {\n enumName\n defaultValue\n }\n ... on _Relation {\n side\n targetEntity\n ownedBy\n inversedBy\n onDelete\n orphanRemoval\n orderBy {\n path\n direction\n }\n }\n }\n }\n }\n}");
|
|
25
25
|
export { SchemaLoader };
|
|
26
26
|
//# sourceMappingURL=SchemaLoader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaLoader.js","sources":["../../../../src/core/schema/SchemaLoader.ts"],"sourcesContent":["import type { GraphQlClient, GraphQlClientRequestOptions } from '@contember/client'\nimport type { RawSchema } from './RawSchema'\nimport { Schema } from './Schema'\nimport { SchemaPreprocessor } from './SchemaPreprocessor'\n\nexport class SchemaLoader {\n\tprivate static readonly schemaQuery =\n\t\t'query {\\n' +\n\t\t' schema {\\n' +\n\t\t' enums {\\n' +\n\t\t' name\\n' +\n\t\t' values\\n' +\n\t\t' }\\n' +\n\t\t' entities {\\n' +\n\t\t' name\\n' +\n\t\t' customPrimaryAllowed\\n' +\n\t\t' unique {\\n' +\n\t\t' fields\\n' +\n\t\t' }\\n' +\n\t\t' fields {\\n' +\n\t\t' __typename\\n' +\n\t\t' name\\n' +\n\t\t' type\\n' +\n\t\t' nullable\\n' +\n\t\t' ... on _Column {\\n' +\n\t\t' enumName\\n' +\n\t\t' defaultValue\\n' +\n\t\t' }\\n' +\n\t\t' ... on _Relation {\\n' +\n\t\t' side\\n' +\n\t\t' targetEntity\\n' +\n\t\t' ownedBy\\n' +\n\t\t' inversedBy\\n' +\n\t\t' onDelete\\n' +\n\t\t' orphanRemoval\\n' +\n\t\t' orderBy {\\n' +\n\t\t' path\\n' +\n\t\t' direction\\n' +\n\t\t' }\\n' +\n\t\t' }\\n' +\n\t\t' }\\n' +\n\t\t' }\\n' +\n\t\t' }\\n' +\n\t\t'}'\n\n\tpublic static async loadSchema(\n\t\tclient: GraphQlClient,\n\t\
|
|
1
|
+
{"version":3,"file":"SchemaLoader.js","sources":["../../../../src/core/schema/SchemaLoader.ts"],"sourcesContent":["import type { GraphQlClient, GraphQlClientRequestOptions } from '@contember/client'\nimport type { RawSchema } from './RawSchema'\nimport { Schema } from './Schema'\nimport { SchemaPreprocessor } from './SchemaPreprocessor'\n\nexport class SchemaLoader {\n\tprivate static readonly schemaLoadCache: Map<string, Promise<Schema>> = new Map()\n\n\tprivate static readonly schemaQuery =\n\t\t'query {\\n' +\n\t\t' schema {\\n' +\n\t\t' enums {\\n' +\n\t\t' name\\n' +\n\t\t' values\\n' +\n\t\t' }\\n' +\n\t\t' entities {\\n' +\n\t\t' name\\n' +\n\t\t' customPrimaryAllowed\\n' +\n\t\t' unique {\\n' +\n\t\t' fields\\n' +\n\t\t' }\\n' +\n\t\t' fields {\\n' +\n\t\t' __typename\\n' +\n\t\t' name\\n' +\n\t\t' type\\n' +\n\t\t' nullable\\n' +\n\t\t' ... on _Column {\\n' +\n\t\t' enumName\\n' +\n\t\t' defaultValue\\n' +\n\t\t' }\\n' +\n\t\t' ... on _Relation {\\n' +\n\t\t' side\\n' +\n\t\t' targetEntity\\n' +\n\t\t' ownedBy\\n' +\n\t\t' inversedBy\\n' +\n\t\t' onDelete\\n' +\n\t\t' orphanRemoval\\n' +\n\t\t' orderBy {\\n' +\n\t\t' path\\n' +\n\t\t' direction\\n' +\n\t\t' }\\n' +\n\t\t' }\\n' +\n\t\t' }\\n' +\n\t\t' }\\n' +\n\t\t' }\\n' +\n\t\t'}'\n\n\tpublic static async loadSchema(\n\t\tclient: GraphQlClient,\n\t\toptions?: GraphQlClientRequestOptions,\n\t): Promise<Schema> {\n\n\t\tconst existing = this.schemaLoadCache.get(client.apiUrl)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\t\tconst schemaPromise = (async () => {\n\t\t\tconst raw: { data: { schema: RawSchema } } = await client.sendRequest(this.schemaQuery, options)\n\t\t\treturn new Schema(SchemaPreprocessor.processRawSchema(raw.data.schema))\n\t\t})()\n\t\tthis.schemaLoadCache.set(client.apiUrl, schemaPromise)\n\t\treturn await schemaPromise\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;AAKO,MAAM,aAAa;AAAA,eA0CL,WACnB,QACA,SACkB;AAElB,UAAM,WAAW,KAAK,gBAAgB,IAAI,OAAO,MAAM;AACvD,QAAI,aAAa,QAAW;AACpB,aAAA;AAAA,IACR;AACA,UAAM,gBAA6B,aAAA;AAClC,YAAM,MAAuC,MAAM,OAAO,YAAY,KAAK,aAAa,OAAO;AAC/F,aAAO,IAAI,OAAO,mBAAmB,iBAAiB,IAAI,KAAK,MAAM,CAAC;AAAA,IAAA;AAEvE,SAAK,gBAAgB,IAAI,OAAO,QAAQ,aAAa;AACrD,WAAO,MAAM;AAAA,EACd;AACD;AAzDyB,cADlB,cACkB,uCAAoD;AAEpD,cAHlB,cAGkB,eACvB;;"}
|
|
@@ -19,7 +19,7 @@ class SchemaPreprocessor {
|
|
|
19
19
|
customPrimaryAllowed: entity.customPrimaryAllowed,
|
|
20
20
|
fields: this.processRawFields(entity.fields),
|
|
21
21
|
name: entity.name,
|
|
22
|
-
unique: entity.unique
|
|
22
|
+
unique: entity.unique.map((it) => ({ fields: new Set(it.fields) }))
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
return entities;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaPreprocessor.js","sources":["../../../../src/core/schema/SchemaPreprocessor.ts"],"sourcesContent":["import type { RawSchema } from './RawSchema'\nimport type { RawSchemaEntity, RawSchemaFields } from './RawSchemaEntity'\nimport type { RawSchemaEnum } from './RawSchemaEnum'\nimport type { SchemaEntities } from './SchemaEntities'\nimport type { SchemaEnums } from './SchemaEnums'\nimport type { SchemaFields } from './SchemaFields'\nimport type { SchemaStore } from './SchemaStore'\n\nexport class SchemaPreprocessor {\n\tpublic static processRawSchema(rawSchema: RawSchema): SchemaStore {\n\t\treturn {\n\t\t\tenums: this.processRawEnums(rawSchema.enums),\n\t\t\tentities: this.processRawEntities(rawSchema.entities),\n\t\t}\n\t}\n\n\tprivate static processRawEnums(rawEnums: RawSchemaEnum[]): SchemaEnums {\n\t\tconst enums: SchemaEnums = new Map()\n\n\t\tfor (const { name, values } of rawEnums) {\n\t\t\tenums.set(name, new Set(values))\n\t\t}\n\n\t\treturn enums\n\t}\n\n\tprivate static processRawEntities(rawEntities: RawSchemaEntity[]): SchemaEntities {\n\t\tconst entities: SchemaEntities = new Map()\n\n\t\tfor (const entity of rawEntities) {\n\t\t\tentities.set(entity.name, {\n\t\t\t\tcustomPrimaryAllowed: entity.customPrimaryAllowed,\n\t\t\t\tfields: this.processRawFields(entity.fields),\n\t\t\t\tname: entity.name,\n\t\t\t\tunique: entity.unique,\n\t\t\t})\n\t\t}\n\n\t\treturn entities\n\t}\n\n\tprivate static processRawFields(rawFields: RawSchemaFields): SchemaFields {\n\t\tconst fields: SchemaFields = new Map()\n\n\t\tfor (const field of rawFields) {\n\t\t\tfields.set(field.name, field)\n\t\t}\n\n\t\treturn fields\n\t}\n}\n"],"names":[],"mappings":"AAQO,MAAM,mBAAmB;AAAA,SACjB,iBAAiB,WAAmC;AAC1D,WAAA;AAAA,MACN,OAAO,KAAK,gBAAgB,UAAU,KAAK;AAAA,MAC3C,UAAU,KAAK,mBAAmB,UAAU,QAAQ;AAAA,IAAA;AAAA,EAEtD;AAAA,SAEe,gBAAgB,UAAwC;AAChE,UAAA,4BAAyB;AAEpB,eAAA,EAAE,MAAM,YAAY,UAAU;AACxC,YAAM,IAAI,MAAM,IAAI,IAAI,MAAM,CAAC;AAAA,IAChC;AAEO,WAAA;AAAA,EACR;AAAA,SAEe,mBAAmB,aAAgD;AAC3E,UAAA,+BAA+B;AAErC,eAAW,UAAU,aAAa;AACxB,eAAA,IAAI,OAAO,MAAM;AAAA,QACzB,sBAAsB,OAAO;AAAA,QAC7B,QAAQ,KAAK,iBAAiB,OAAO,MAAM;AAAA,QAC3C,MAAM,OAAO;AAAA,QACb,QAAQ,OAAO;AAAA,MAAA,
|
|
1
|
+
{"version":3,"file":"SchemaPreprocessor.js","sources":["../../../../src/core/schema/SchemaPreprocessor.ts"],"sourcesContent":["import type { RawSchema } from './RawSchema'\nimport type { RawSchemaEntity, RawSchemaFields } from './RawSchemaEntity'\nimport type { RawSchemaEnum } from './RawSchemaEnum'\nimport type { SchemaEntities } from './SchemaEntities'\nimport type { SchemaEnums } from './SchemaEnums'\nimport type { SchemaFields } from './SchemaFields'\nimport type { SchemaStore } from './SchemaStore'\n\nexport class SchemaPreprocessor {\n\tpublic static processRawSchema(rawSchema: RawSchema): SchemaStore {\n\t\treturn {\n\t\t\tenums: this.processRawEnums(rawSchema.enums),\n\t\t\tentities: this.processRawEntities(rawSchema.entities),\n\t\t}\n\t}\n\n\tprivate static processRawEnums(rawEnums: RawSchemaEnum[]): SchemaEnums {\n\t\tconst enums: SchemaEnums = new Map()\n\n\t\tfor (const { name, values } of rawEnums) {\n\t\t\tenums.set(name, new Set(values))\n\t\t}\n\n\t\treturn enums\n\t}\n\n\tprivate static processRawEntities(rawEntities: RawSchemaEntity[]): SchemaEntities {\n\t\tconst entities: SchemaEntities = new Map()\n\n\t\tfor (const entity of rawEntities) {\n\t\t\tentities.set(entity.name, {\n\t\t\t\tcustomPrimaryAllowed: entity.customPrimaryAllowed,\n\t\t\t\tfields: this.processRawFields(entity.fields),\n\t\t\t\tname: entity.name,\n\t\t\t\tunique: entity.unique.map(it => ({ fields: new Set(it.fields) })),\n\t\t\t})\n\t\t}\n\n\t\treturn entities\n\t}\n\n\tprivate static processRawFields(rawFields: RawSchemaFields): SchemaFields {\n\t\tconst fields: SchemaFields = new Map()\n\n\t\tfor (const field of rawFields) {\n\t\t\tfields.set(field.name, field)\n\t\t}\n\n\t\treturn fields\n\t}\n}\n"],"names":[],"mappings":"AAQO,MAAM,mBAAmB;AAAA,SACjB,iBAAiB,WAAmC;AAC1D,WAAA;AAAA,MACN,OAAO,KAAK,gBAAgB,UAAU,KAAK;AAAA,MAC3C,UAAU,KAAK,mBAAmB,UAAU,QAAQ;AAAA,IAAA;AAAA,EAEtD;AAAA,SAEe,gBAAgB,UAAwC;AAChE,UAAA,4BAAyB;AAEpB,eAAA,EAAE,MAAM,YAAY,UAAU;AACxC,YAAM,IAAI,MAAM,IAAI,IAAI,MAAM,CAAC;AAAA,IAChC;AAEO,WAAA;AAAA,EACR;AAAA,SAEe,mBAAmB,aAAgD;AAC3E,UAAA,+BAA+B;AAErC,eAAW,UAAU,aAAa;AACxB,eAAA,IAAI,OAAO,MAAM;AAAA,QACzB,sBAAsB,OAAO;AAAA,QAC7B,QAAQ,KAAK,iBAAiB,OAAO,MAAM;AAAA,QAC3C,MAAM,OAAO;AAAA,QACb,QAAQ,OAAO,OAAO,IAAI,CAAO,OAAA,GAAE,QAAQ,IAAI,IAAI,GAAG,MAAM,EAAI,EAAA;AAAA,MAAA,CAChE;AAAA,IACF;AAEO,WAAA;AAAA,EACR;AAAA,SAEe,iBAAiB,WAA0C;AACnE,UAAA,6BAA2B;AAEjC,eAAW,SAAS,WAAW;AACvB,aAAA,IAAI,MAAM,MAAM,KAAK;AAAA,IAC7B;AAEO,WAAA;AAAA,EACR;AACD;;"}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { memo } from "react";
|
|
2
|
+
import { useEnvironment } from "../accessorPropagation/useEnvironment.js";
|
|
2
3
|
import { assertNever } from "../utils/assertNever.js";
|
|
3
4
|
function Component(render, decider, displayName) {
|
|
5
|
+
const RenderWithEnv = (props) => render(props, useEnvironment());
|
|
6
|
+
const renderWithEnv = typeof render !== "function" || render.length < 2 ? render : RenderWithEnv;
|
|
4
7
|
if (decider === void 0 || typeof decider === "string") {
|
|
5
8
|
render.displayName = decider;
|
|
6
|
-
const augmentedRender2 = memo(
|
|
9
|
+
const augmentedRender2 = memo(renderWithEnv);
|
|
7
10
|
augmentedRender2.staticRender = render;
|
|
8
11
|
augmentedRender2.displayName = decider;
|
|
9
12
|
return augmentedRender2;
|
|
10
13
|
}
|
|
11
14
|
render.displayName = displayName;
|
|
12
|
-
const augmentedRender = memo(
|
|
15
|
+
const augmentedRender = memo(renderWithEnv);
|
|
13
16
|
augmentedRender.displayName = displayName;
|
|
14
17
|
if (typeof decider === "function") {
|
|
15
18
|
augmentedRender.staticRender = decider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Component.js","sources":["../../../src/coreComponents/Component.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"Component.js","sources":["../../../src/coreComponents/Component.tsx"],"sourcesContent":["import { memo, NamedExoticComponent, PropsWithChildren, ReactElement } from 'react'\nimport { useEnvironment } from '../accessorPropagation/useEnvironment'\nimport type { Environment } from '../dao'\nimport { assertNever } from '../utils'\nimport type { MarkerProvider, StaticRenderProvider, StaticRenderProviderProps } from './MarkerProvider'\n\ninterface EnvironmentAwareFunctionComponent<P> {\n\t(props: PropsWithChildren<P>, environment: Environment): ReactElement<any, any> | null;\n\tdisplayName?: string | undefined;\n}\n\nfunction Component<Props extends {}>(\n\tstatelessRender: EnvironmentAwareFunctionComponent<Props>,\n\tdisplayName?: string,\n): NamedExoticComponent<Props>\n\nfunction Component<Props extends {}, NonStaticPropNames extends keyof Props = never>(\n\tstatefulRender: EnvironmentAwareFunctionComponent<Props>,\n\tstaticRender: (\n\t\tprops: StaticRenderProviderProps<Props, NonStaticPropNames>,\n\t\tenvironment: Environment,\n\t) => ReactElement | null,\n\tdisplayName?: string,\n): NamedExoticComponent<Props>\n\nfunction Component<Props extends {}, NonStaticPropNames extends keyof Props = never>(\n\tstatefulRender: EnvironmentAwareFunctionComponent<Props>,\n\tmarkerProvisions: MarkerProvider<Props, NonStaticPropNames>,\n\tdisplayName?: string,\n): NamedExoticComponent<Props>\n\nfunction Component<Props extends {}, NonStaticPropNames extends keyof Props = never>(\n\trender: EnvironmentAwareFunctionComponent<Props>,\n\tdecider?:\n\t\t| string\n\t\t| ((props: StaticRenderProviderProps<Props, NonStaticPropNames>, environment: Environment) => ReactElement | null)\n\t\t| MarkerProvider<Props, NonStaticPropNames>,\n\tdisplayName?: string,\n) {\n\tconst RenderWithEnv = (props: Props) => render(props, useEnvironment())\n\tconst renderWithEnv = typeof render !== 'function' || render.length < 2 ? render : RenderWithEnv\n\n\tif (decider === undefined || typeof decider === 'string') {\n\t\trender.displayName = decider\n\t\tconst augmentedRender: NamedExoticComponent<Props> & MarkerProvider<Props> = memo<Props>(renderWithEnv)\n\t\taugmentedRender.staticRender = render as StaticRenderProvider<Props>['staticRender']\n\t\taugmentedRender.displayName = decider\n\n\t\treturn augmentedRender\n\t}\n\n\trender.displayName = displayName\n\tconst augmentedRender: NamedExoticComponent<Props> & MarkerProvider<Props, NonStaticPropNames> = memo<Props>(renderWithEnv)\n\taugmentedRender.displayName = displayName\n\n\tif (typeof decider === 'function') {\n\t\taugmentedRender.staticRender = decider\n\n\t\treturn augmentedRender\n\t}\n\tif (typeof decider === 'object') {\n\t\tfor (const provisionName in decider) {\n\t\t\tconst methodName = provisionName as keyof MarkerProvider<Props, NonStaticPropNames>\n\t\t\t;(augmentedRender[methodName] as MarkerProvider<Props, NonStaticPropNames>[typeof methodName]) =\n\t\t\t\tdecider[methodName]\n\t\t}\n\n\t\treturn augmentedRender\n\t}\n\tassertNever(decider)\n}\n\nexport type { EnvironmentAwareFunctionComponent }\nexport { Component }\n"],"names":[],"mappings":";;;AA+BA,mBACC,QACA,SAIA,aACC;AACD,QAAM,gBAAgB,CAAC,UAAiB,OAAO,OAAO,gBAAgB;AACtE,QAAM,gBAAgB,OAAO,WAAW,cAAc,OAAO,SAAS,IAAI,SAAS;AAEnF,MAAI,YAAY,UAAa,OAAO,YAAY,UAAU;AACzD,WAAO,cAAc;AACf,UAAA,mBAAuE,KAAY,aAAa;AACtG,qBAAgB,eAAe;AAC/B,qBAAgB,cAAc;AAEvB,WAAA;AAAA,EACR;AAEA,SAAO,cAAc;AACf,QAAA,kBAA2F,KAAY,aAAa;AAC1H,kBAAgB,cAAc;AAE1B,MAAA,OAAO,YAAY,YAAY;AAClC,oBAAgB,eAAe;AAExB,WAAA;AAAA,EACR;AACI,MAAA,OAAO,YAAY,UAAU;AAChC,eAAW,iBAAiB,SAAS;AACpC,YAAM,aAAa;AACjB,sBAAgB,cACjB,QAAQ;AAAA,IACV;AAEO,WAAA;AAAA,EACR;AACA,cAAmB;AACpB;;"}
|
|
@@ -4,7 +4,6 @@ import { AccessorTree } from "../accessorTree/AccessorTree.js";
|
|
|
4
4
|
const DataBindingProvider = memo(function DataBindingProvider2(props) {
|
|
5
5
|
const accessorTreeState = useDataBinding({
|
|
6
6
|
nodeTree: props.children,
|
|
7
|
-
refreshOnEnvironmentChange: props.refreshOnEnvironmentChange,
|
|
8
7
|
refreshOnPersist: props.refreshOnPersist ?? false
|
|
9
8
|
});
|
|
10
9
|
const children = "stateComponent" in props && props.stateComponent ? createElement(props.stateComponent, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataBindingProvider.js","sources":["../../../src/coreComponents/DataBindingProvider.tsx"],"sourcesContent":["import { ComponentType, createElement, memo, ReactElement, ReactNode } from 'react'\nimport { AccessorTree, AccessorTreeState, useDataBinding } from '../accessorTree'\n\nexport interface DataBindingProviderBaseProps {\n\tchildren?: ReactNode\n\
|
|
1
|
+
{"version":3,"file":"DataBindingProvider.js","sources":["../../../src/coreComponents/DataBindingProvider.tsx"],"sourcesContent":["import { ComponentType, createElement, memo, ReactElement, ReactNode } from 'react'\nimport { AccessorTree, AccessorTreeState, useDataBinding } from '../accessorTree'\n\nexport interface DataBindingProviderBaseProps {\n\tchildren?: ReactNode\n\trefreshOnPersist?: boolean\n}\n\nexport interface DataBindingStateComponentProps {\n\taccessorTreeState: AccessorTreeState\n\tchildren?: ReactNode\n}\n\nexport type DataBindingProviderProps<StateProps> = DataBindingProviderBaseProps &\n\t(\n\t\t| {}\n\t\t| {\n\t\t\t\tstateComponent: ComponentType<StateProps & DataBindingStateComponentProps>\n\t\t\t\tstateProps?: StateProps\n\t\t }\n\t)\n\nexport const DataBindingProvider = memo(function DataBindingProvider<StateProps extends DataBindingStateComponentProps>(\n\tprops: DataBindingProviderProps<StateProps>,\n) {\n\tconst accessorTreeState = useDataBinding({\n\t\tnodeTree: props.children,\n\t\trefreshOnPersist: props.refreshOnPersist ?? false,\n\t})\n\n\tconst children =\n\t\t'stateComponent' in props && props.stateComponent\n\t\t\t? createElement(\n\t\t\t\t\tprops.stateComponent,\n\t\t\t\t\t{\n\t\t\t\t\t\t...props.stateProps!,\n\t\t\t\t\t\taccessorTreeState: accessorTreeState,\n\t\t\t\t\t},\n\t\t\t\t\tprops.children,\n\t\t\t )\n\t\t\t: props.children\n\treturn <AccessorTree state={accessorTreeState}>{children}</AccessorTree>\n}) as <StateProps>(props: DataBindingProviderProps<StateProps>) => ReactElement\n"],"names":["_jsx"],"mappings":";;;AAsBa,MAAA,sBAAsB,KAAK,8BACvC,OACC;AACD,QAAM,oBAAoB,eAAe;AAAA,IACxC,UAAU,MAAM;AAAA,IAChB,kBAAkB,MAAM,oBAAoB;AAAA,EAAA,CAC5C;AAED,QAAM,WACL,oBAAoB,SAAS,MAAM,iBAChC,cACA,MAAM,gBACN;AAAA,OACI,MAAM;AAAA,IACT;AAAA,EAED,GAAA,MAAM,QACN,IACA,MAAM;AACV,SAAQA,8BAAA,cAAA;AAAA,IAAa,OAAO;AAAA,EAAA,GAAoB,QAAS;AAC1D,CAAC;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityListSubTree.js","sources":["../../../src/coreComponents/EntityListSubTree.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"EntityListSubTree.js","sources":["../../../src/coreComponents/EntityListSubTree.tsx"],"sourcesContent":["import { useConstantValueInvariant } from '@contember/react-utils'\nimport { ComponentType, ReactElement, ReactNode, useCallback } from 'react'\nimport {\n\tuseAccessorUpdateSubscription,\n\tuseEntityListSubTreeParameters,\n\tuseGetEntityListSubTree,\n} from '../accessorPropagation'\nimport { PRIMARY_KEY_NAME } from '../bindingTypes'\nimport { Environment } from '../dao'\nimport { MarkerFactory } from '../queryLanguage'\nimport type { SugaredQualifiedEntityList, SugaredUnconstrainedQualifiedEntityList, TreeRootId } from '../treeParameters'\nimport { Component } from './Component'\nimport { EntityList, EntityListBaseProps } from './EntityList'\nimport { Field } from './Field'\nimport { TreeNodeEnvironmentFactory } from '../dao/TreeNodeEnvironmentFactory'\n\nexport interface EntityListSubTreeAdditionalProps {\n\tvariables?: Environment.ValuesMapWithFactory\n}\n\nexport type EntityListSubTreeProps<ListProps, EntityProps> = {\n\ttreeRootId?: TreeRootId\n\tchildren?: ReactNode\n} & EntityListSubTreeAdditionalProps &\n\t(SugaredQualifiedEntityList | SugaredUnconstrainedQualifiedEntityList) &\n\t(\n\t\t| {}\n\t\t| {\n\t\t\t\tlistComponent: ComponentType<ListProps & EntityListBaseProps>\n\t\t\t\tlistProps?: ListProps\n\t\t }\n\t)\n\nexport const EntityListSubTree = Component(\n\t<ListProps, EntityProps>(props: EntityListSubTreeProps<ListProps, EntityProps>) => {\n\t\tuseConstantValueInvariant(props.isCreating, 'EntityListSubTree: cannot update isCreating')\n\n\t\tconst getSubTree = useGetEntityListSubTree()\n\t\tconst parameters = useEntityListSubTreeParameters(props)\n\t\tconst getAccessor = useCallback(\n\t\t\t() => getSubTree(parameters, props.treeRootId),\n\t\t\t[getSubTree, parameters, props.treeRootId],\n\t\t)\n\t\tconst accessor = useAccessorUpdateSubscription(getAccessor)\n\n\t\t// TODO revive top level hasOneRelationPath\n\t\t// {parameters.value.hasOneRelationPath.length ?\n\t\t// \t<HasOne field={parameters.value.hasOneRelationPath}>{props.children}</HasOne\n\t\t// ) :\n\t\t// \tprops.children\n\t\t// )\n\t\treturn <EntityList {...props} accessor={accessor} />\n\t},\n\t{\n\t\tgenerateBranchMarker: (props, fields, environment) => {\n\t\t\tif ('isCreating' in props && props.isCreating) {\n\t\t\t\treturn MarkerFactory.createUnconstrainedEntityListSubTreeMarker(props, fields, environment)\n\t\t\t}\n\t\t\treturn MarkerFactory.createEntityListSubTreeMarker(props, fields, environment)\n\t\t},\n\t\tstaticRender: props => (\n\t\t\t<EntityList {...props} accessor={0 as any}>\n\t\t\t\t<Field field={PRIMARY_KEY_NAME} />\n\t\t\t\t{props.children}\n\t\t\t</EntityList>\n\t\t),\n\t\tgenerateEnvironment: (props, oldEnvironment) => {\n\t\t\tconst environment = oldEnvironment.withVariables(props.variables)\n\t\t\treturn TreeNodeEnvironmentFactory.createEnvironmentForEntityListSubtree(environment, props)\n\t\t},\n\t},\n\t'EntityListSubTree',\n) as <ListProps, EntityProps>(props: EntityListSubTreeProps<ListProps, EntityProps>) => ReactElement\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;AAiCa,MAAA,oBAAoB,UAChC,CAAyB,UAA0D;AACxD,4BAAA,MAAM,YAAY,6CAA6C;AAEzF,QAAM,aAAa;AACb,QAAA,aAAa,+BAA+B,KAAK;AACvD,QAAM,cAAc,YACnB,MAAM,WAAW,YAAY,MAAM,UAAU,GAC7C,CAAC,YAAY,YAAY,MAAM,UAAU,CAC1C;AACM,QAAA,WAAW,8BAA8B,WAAW;AAQ1D,SAAQA,8BAAA,YAAA;AAAA,OAAe;AAAA,IAAO;AAAA,EAAA,CAAoB;AACnD,GACA;AAAA,EACC,sBAAsB,CAAC,OAAO,QAAQ,gBAAgB;AACjD,QAAA,gBAAgB,SAAS,MAAM,YAAY;AAC9C,aAAO,cAAc,2CAA2C,OAAO,QAAQ,WAAW;AAAA,IAC3F;AACA,WAAO,cAAc,8BAA8B,OAAO,QAAQ,WAAW;AAAA,EAC9E;AAAA,EACA,cAAc,WACZA,8BAAA,YAAA;AAAA,OAAe;AAAA,IAAO,UAAU;AAAA,EAAA,GAC/BA,8BAAA,OAAA;AAAA,IAAM,OAAO;AAAA,EAAA,CAAkB,GAC/B,MAAM,QACR;AAAA,EAED,qBAAqB,CAAC,OAAO,mBAAmB;AAC/C,UAAM,cAAc,eAAe,cAAc,MAAM,SAAS;AACzD,WAAA,2BAA2B,sCAAsC,aAAa,KAAK;AAAA,EAC3F;AACD,GACA,mBACD;;"}
|
|
@@ -4,8 +4,8 @@ import { Component } from "./Component.js";
|
|
|
4
4
|
import { Entity } from "./Entity.js";
|
|
5
5
|
import { Field } from "./Field.js";
|
|
6
6
|
import { TreeNodeEnvironmentFactory } from "../dao/TreeNodeEnvironmentFactory.js";
|
|
7
|
-
import { useEntity } from "../accessorPropagation/useEntity.js";
|
|
8
7
|
import { MarkerFactory } from "../queryLanguage/MarkerFactory.js";
|
|
8
|
+
import { useEntity } from "../accessorPropagation/useEntity.js";
|
|
9
9
|
const HasOne = Component((props) => {
|
|
10
10
|
const entity = useEntity(props);
|
|
11
11
|
return /* @__PURE__ */ createElement(Entity, {
|