@contember/binding-legacy 2.1.0-alpha.30 → 2.1.0-alpha.36
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/package.json +10 -5
- package/src/accessorTree/NormalizedPersistedData.ts +1 -1
- package/src/accessors/EntityAccessorImpl.ts +13 -11
- package/src/accessors/EntityListAccessorImpl.ts +16 -7
- package/src/core/AccessorErrorManager.ts +2 -2
- package/src/core/DataBinding.ts +24 -15
- package/src/core/ErrorsPreprocessor.ts +4 -5
- package/src/core/EventManager.ts +34 -46
- package/src/core/MutationGenerator.ts +23 -27
- package/src/core/QueryGenerator.ts +4 -5
- package/src/core/RealmKeyGenerator.ts +5 -3
- package/src/core/RequestResponseNormalizer.ts +3 -8
- package/src/core/StateInitializer.ts +10 -18
- package/src/core/TreeAugmenter.ts +8 -15
- package/src/core/TreeStore.ts +5 -4
- package/src/core/operations/EntityOperations.ts +25 -25
- package/src/core/operations/FieldOperations.ts +15 -17
- package/src/core/operations/ListOperations.ts +15 -15
- package/src/core/operations/OperationsHelpers.ts +2 -2
- package/src/core/state/EntityListState.ts +3 -9
- package/src/fieldHelpers/helpers/TemporalFieldHelper.ts +3 -3
- package/src/utils/assertNever.ts +4 -4
- package/tests/example.test.ts +2 -2
- package/dist/development/index.cjs +0 -34
- package/dist/development/index.cjs.map +0 -1
- package/dist/development/index.js +0 -28
- package/dist/development/index.js.map +0 -1
- package/dist/development/src/accessorTree/NormalizedPersistedData.cjs +0 -10
- package/dist/development/src/accessorTree/NormalizedPersistedData.cjs.map +0 -1
- package/dist/development/src/accessorTree/NormalizedPersistedData.js +0 -10
- package/dist/development/src/accessorTree/NormalizedPersistedData.js.map +0 -1
- package/dist/development/src/accessors/EntityAccessorImpl.cjs +0 -179
- package/dist/development/src/accessors/EntityAccessorImpl.cjs.map +0 -1
- package/dist/development/src/accessors/EntityAccessorImpl.js +0 -179
- package/dist/development/src/accessors/EntityAccessorImpl.js.map +0 -1
- package/dist/development/src/accessors/EntityListAccessorImpl.cjs +0 -112
- package/dist/development/src/accessors/EntityListAccessorImpl.cjs.map +0 -1
- package/dist/development/src/accessors/EntityListAccessorImpl.js +0 -112
- package/dist/development/src/accessors/EntityListAccessorImpl.js.map +0 -1
- package/dist/development/src/accessors/FieldAccessorImpl.cjs +0 -54
- package/dist/development/src/accessors/FieldAccessorImpl.cjs.map +0 -1
- package/dist/development/src/accessors/FieldAccessorImpl.js +0 -54
- package/dist/development/src/accessors/FieldAccessorImpl.js.map +0 -1
- package/dist/development/src/core/AccessorErrorManager.cjs +0 -200
- package/dist/development/src/core/AccessorErrorManager.cjs.map +0 -1
- package/dist/development/src/core/AccessorErrorManager.js +0 -200
- package/dist/development/src/core/AccessorErrorManager.js.map +0 -1
- package/dist/development/src/core/Config.cjs +0 -29
- package/dist/development/src/core/Config.cjs.map +0 -1
- package/dist/development/src/core/Config.js +0 -29
- package/dist/development/src/core/Config.js.map +0 -1
- package/dist/development/src/core/DataBinding.cjs +0 -354
- package/dist/development/src/core/DataBinding.cjs.map +0 -1
- package/dist/development/src/core/DataBinding.js +0 -354
- package/dist/development/src/core/DataBinding.js.map +0 -1
- package/dist/development/src/core/DirtinessTracker.cjs +0 -26
- package/dist/development/src/core/DirtinessTracker.cjs.map +0 -1
- package/dist/development/src/core/DirtinessTracker.js +0 -26
- package/dist/development/src/core/DirtinessTracker.js.map +0 -1
- package/dist/development/src/core/ErrorsPreprocessor.cjs +0 -180
- package/dist/development/src/core/ErrorsPreprocessor.cjs.map +0 -1
- package/dist/development/src/core/ErrorsPreprocessor.js +0 -180
- package/dist/development/src/core/ErrorsPreprocessor.js.map +0 -1
- package/dist/development/src/core/EventManager.cjs +0 -439
- package/dist/development/src/core/EventManager.cjs.map +0 -1
- package/dist/development/src/core/EventManager.js +0 -439
- package/dist/development/src/core/EventManager.js.map +0 -1
- package/dist/development/src/core/MutationGenerator.cjs +0 -670
- package/dist/development/src/core/MutationGenerator.cjs.map +0 -1
- package/dist/development/src/core/MutationGenerator.js +0 -670
- package/dist/development/src/core/MutationGenerator.js.map +0 -1
- package/dist/development/src/core/QueryGenerator.cjs +0 -110
- package/dist/development/src/core/QueryGenerator.cjs.map +0 -1
- package/dist/development/src/core/QueryGenerator.js +0 -110
- package/dist/development/src/core/QueryGenerator.js.map +0 -1
- package/dist/development/src/core/RealmKeyGenerator.cjs +0 -42
- package/dist/development/src/core/RealmKeyGenerator.cjs.map +0 -1
- package/dist/development/src/core/RealmKeyGenerator.js +0 -42
- package/dist/development/src/core/RealmKeyGenerator.js.map +0 -1
- package/dist/development/src/core/RequestResponseNormalizer.cjs +0 -136
- package/dist/development/src/core/RequestResponseNormalizer.cjs.map +0 -1
- package/dist/development/src/core/RequestResponseNormalizer.js +0 -136
- package/dist/development/src/core/RequestResponseNormalizer.js.map +0 -1
- package/dist/development/src/core/StateInitializer.cjs +0 -379
- package/dist/development/src/core/StateInitializer.cjs.map +0 -1
- package/dist/development/src/core/StateInitializer.js +0 -379
- package/dist/development/src/core/StateInitializer.js.map +0 -1
- package/dist/development/src/core/TreeAugmenter.cjs +0 -354
- package/dist/development/src/core/TreeAugmenter.cjs.map +0 -1
- package/dist/development/src/core/TreeAugmenter.js +0 -354
- package/dist/development/src/core/TreeAugmenter.js.map +0 -1
- package/dist/development/src/core/TreeStore.cjs +0 -172
- package/dist/development/src/core/TreeStore.cjs.map +0 -1
- package/dist/development/src/core/TreeStore.js +0 -172
- package/dist/development/src/core/TreeStore.js.map +0 -1
- package/dist/development/src/core/exceptions/ErrorLocator.cjs +0 -59
- package/dist/development/src/core/exceptions/ErrorLocator.cjs.map +0 -1
- package/dist/development/src/core/exceptions/ErrorLocator.js +0 -59
- package/dist/development/src/core/exceptions/ErrorLocator.js.map +0 -1
- package/dist/development/src/core/exceptions/MarkerSugarer.cjs +0 -51
- package/dist/development/src/core/exceptions/MarkerSugarer.cjs.map +0 -1
- package/dist/development/src/core/exceptions/MarkerSugarer.js +0 -51
- package/dist/development/src/core/exceptions/MarkerSugarer.js.map +0 -1
- package/dist/development/src/core/exceptions/TreeParameterSugarer.cjs +0 -33
- package/dist/development/src/core/exceptions/TreeParameterSugarer.cjs.map +0 -1
- package/dist/development/src/core/exceptions/TreeParameterSugarer.js +0 -33
- package/dist/development/src/core/exceptions/TreeParameterSugarer.js.map +0 -1
- package/dist/development/src/core/factories/createBatchUpdatesOptions.cjs +0 -23
- package/dist/development/src/core/factories/createBatchUpdatesOptions.cjs.map +0 -1
- package/dist/development/src/core/factories/createBatchUpdatesOptions.js +0 -23
- package/dist/development/src/core/factories/createBatchUpdatesOptions.js.map +0 -1
- package/dist/development/src/core/operations/EntityOperations.cjs +0 -226
- package/dist/development/src/core/operations/EntityOperations.cjs.map +0 -1
- package/dist/development/src/core/operations/EntityOperations.js +0 -226
- package/dist/development/src/core/operations/EntityOperations.js.map +0 -1
- package/dist/development/src/core/operations/FieldOperations.cjs +0 -92
- package/dist/development/src/core/operations/FieldOperations.cjs.map +0 -1
- package/dist/development/src/core/operations/FieldOperations.js +0 -92
- package/dist/development/src/core/operations/FieldOperations.js.map +0 -1
- package/dist/development/src/core/operations/ListOperations.cjs +0 -158
- package/dist/development/src/core/operations/ListOperations.cjs.map +0 -1
- package/dist/development/src/core/operations/ListOperations.js +0 -158
- package/dist/development/src/core/operations/ListOperations.js.map +0 -1
- package/dist/development/src/core/operations/OperationsHelpers.cjs +0 -87
- package/dist/development/src/core/operations/OperationsHelpers.cjs.map +0 -1
- package/dist/development/src/core/operations/OperationsHelpers.js +0 -87
- package/dist/development/src/core/operations/OperationsHelpers.js.map +0 -1
- package/dist/development/src/core/requestAliases/MutationAlias.cjs +0 -14
- package/dist/development/src/core/requestAliases/MutationAlias.cjs.map +0 -1
- package/dist/development/src/core/requestAliases/MutationAlias.js +0 -14
- package/dist/development/src/core/requestAliases/MutationAlias.js.map +0 -1
- package/dist/development/src/core/state/StateIterator.cjs +0 -100
- package/dist/development/src/core/state/StateIterator.cjs.map +0 -1
- package/dist/development/src/core/state/StateIterator.js +0 -100
- package/dist/development/src/core/state/StateIterator.js.map +0 -1
- package/dist/development/src/core/state/getEntityMarker.cjs +0 -5
- package/dist/development/src/core/state/getEntityMarker.cjs.map +0 -1
- package/dist/development/src/core/state/getEntityMarker.js +0 -5
- package/dist/development/src/core/state/getEntityMarker.js.map +0 -1
- package/dist/development/src/core/utils/getCombinedSignal.cjs +0 -33
- package/dist/development/src/core/utils/getCombinedSignal.cjs.map +0 -1
- package/dist/development/src/core/utils/getCombinedSignal.js +0 -33
- package/dist/development/src/core/utils/getCombinedSignal.js.map +0 -1
- package/dist/development/src/fieldHelpers/helpers/FieldHelper.cjs +0 -13
- package/dist/development/src/fieldHelpers/helpers/FieldHelper.cjs.map +0 -1
- package/dist/development/src/fieldHelpers/helpers/FieldHelper.js +0 -13
- package/dist/development/src/fieldHelpers/helpers/FieldHelper.js.map +0 -1
- package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.cjs +0 -18
- package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.cjs.map +0 -1
- package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.js +0 -18
- package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.js.map +0 -1
- package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.cjs +0 -16
- package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.cjs.map +0 -1
- package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.js +0 -16
- package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.js.map +0 -1
- package/dist/development/src/utils/generateEnumerabilityPreventingEntropy.cjs +0 -7
- package/dist/development/src/utils/generateEnumerabilityPreventingEntropy.cjs.map +0 -1
- package/dist/development/src/utils/generateEnumerabilityPreventingEntropy.js +0 -7
- package/dist/development/src/utils/generateEnumerabilityPreventingEntropy.js.map +0 -1
- package/dist/development/src/utils/isEmptyObject.cjs +0 -12
- package/dist/development/src/utils/isEmptyObject.cjs.map +0 -1
- package/dist/development/src/utils/isEmptyObject.js +0 -12
- package/dist/development/src/utils/isEmptyObject.js.map +0 -1
- package/dist/production/index.cjs +0 -34
- package/dist/production/index.cjs.map +0 -1
- package/dist/production/index.js +0 -28
- package/dist/production/index.js.map +0 -1
- package/dist/production/src/accessorTree/NormalizedPersistedData.cjs +0 -10
- package/dist/production/src/accessorTree/NormalizedPersistedData.cjs.map +0 -1
- package/dist/production/src/accessorTree/NormalizedPersistedData.js +0 -10
- package/dist/production/src/accessorTree/NormalizedPersistedData.js.map +0 -1
- package/dist/production/src/accessors/EntityAccessorImpl.cjs +0 -179
- package/dist/production/src/accessors/EntityAccessorImpl.cjs.map +0 -1
- package/dist/production/src/accessors/EntityAccessorImpl.js +0 -179
- package/dist/production/src/accessors/EntityAccessorImpl.js.map +0 -1
- package/dist/production/src/accessors/EntityListAccessorImpl.cjs +0 -112
- package/dist/production/src/accessors/EntityListAccessorImpl.cjs.map +0 -1
- package/dist/production/src/accessors/EntityListAccessorImpl.js +0 -112
- package/dist/production/src/accessors/EntityListAccessorImpl.js.map +0 -1
- package/dist/production/src/accessors/FieldAccessorImpl.cjs +0 -54
- package/dist/production/src/accessors/FieldAccessorImpl.cjs.map +0 -1
- package/dist/production/src/accessors/FieldAccessorImpl.js +0 -54
- package/dist/production/src/accessors/FieldAccessorImpl.js.map +0 -1
- package/dist/production/src/core/AccessorErrorManager.cjs +0 -200
- package/dist/production/src/core/AccessorErrorManager.cjs.map +0 -1
- package/dist/production/src/core/AccessorErrorManager.js +0 -200
- package/dist/production/src/core/AccessorErrorManager.js.map +0 -1
- package/dist/production/src/core/Config.cjs +0 -29
- package/dist/production/src/core/Config.cjs.map +0 -1
- package/dist/production/src/core/Config.js +0 -29
- package/dist/production/src/core/Config.js.map +0 -1
- package/dist/production/src/core/DataBinding.cjs +0 -354
- package/dist/production/src/core/DataBinding.cjs.map +0 -1
- package/dist/production/src/core/DataBinding.js +0 -354
- package/dist/production/src/core/DataBinding.js.map +0 -1
- package/dist/production/src/core/DirtinessTracker.cjs +0 -26
- package/dist/production/src/core/DirtinessTracker.cjs.map +0 -1
- package/dist/production/src/core/DirtinessTracker.js +0 -26
- package/dist/production/src/core/DirtinessTracker.js.map +0 -1
- package/dist/production/src/core/ErrorsPreprocessor.cjs +0 -180
- package/dist/production/src/core/ErrorsPreprocessor.cjs.map +0 -1
- package/dist/production/src/core/ErrorsPreprocessor.js +0 -180
- package/dist/production/src/core/ErrorsPreprocessor.js.map +0 -1
- package/dist/production/src/core/EventManager.cjs +0 -413
- package/dist/production/src/core/EventManager.cjs.map +0 -1
- package/dist/production/src/core/EventManager.js +0 -413
- package/dist/production/src/core/EventManager.js.map +0 -1
- package/dist/production/src/core/MutationGenerator.cjs +0 -670
- package/dist/production/src/core/MutationGenerator.cjs.map +0 -1
- package/dist/production/src/core/MutationGenerator.js +0 -670
- package/dist/production/src/core/MutationGenerator.js.map +0 -1
- package/dist/production/src/core/QueryGenerator.cjs +0 -110
- package/dist/production/src/core/QueryGenerator.cjs.map +0 -1
- package/dist/production/src/core/QueryGenerator.js +0 -110
- package/dist/production/src/core/QueryGenerator.js.map +0 -1
- package/dist/production/src/core/RealmKeyGenerator.cjs +0 -42
- package/dist/production/src/core/RealmKeyGenerator.cjs.map +0 -1
- package/dist/production/src/core/RealmKeyGenerator.js +0 -42
- package/dist/production/src/core/RealmKeyGenerator.js.map +0 -1
- package/dist/production/src/core/RequestResponseNormalizer.cjs +0 -136
- package/dist/production/src/core/RequestResponseNormalizer.cjs.map +0 -1
- package/dist/production/src/core/RequestResponseNormalizer.js +0 -136
- package/dist/production/src/core/RequestResponseNormalizer.js.map +0 -1
- package/dist/production/src/core/StateInitializer.cjs +0 -379
- package/dist/production/src/core/StateInitializer.cjs.map +0 -1
- package/dist/production/src/core/StateInitializer.js +0 -379
- package/dist/production/src/core/StateInitializer.js.map +0 -1
- package/dist/production/src/core/TreeAugmenter.cjs +0 -354
- package/dist/production/src/core/TreeAugmenter.cjs.map +0 -1
- package/dist/production/src/core/TreeAugmenter.js +0 -354
- package/dist/production/src/core/TreeAugmenter.js.map +0 -1
- package/dist/production/src/core/TreeStore.cjs +0 -172
- package/dist/production/src/core/TreeStore.cjs.map +0 -1
- package/dist/production/src/core/TreeStore.js +0 -172
- package/dist/production/src/core/TreeStore.js.map +0 -1
- package/dist/production/src/core/exceptions/ErrorLocator.cjs +0 -59
- package/dist/production/src/core/exceptions/ErrorLocator.cjs.map +0 -1
- package/dist/production/src/core/exceptions/ErrorLocator.js +0 -59
- package/dist/production/src/core/exceptions/ErrorLocator.js.map +0 -1
- package/dist/production/src/core/exceptions/MarkerSugarer.cjs +0 -51
- package/dist/production/src/core/exceptions/MarkerSugarer.cjs.map +0 -1
- package/dist/production/src/core/exceptions/MarkerSugarer.js +0 -51
- package/dist/production/src/core/exceptions/MarkerSugarer.js.map +0 -1
- package/dist/production/src/core/exceptions/TreeParameterSugarer.cjs +0 -33
- package/dist/production/src/core/exceptions/TreeParameterSugarer.cjs.map +0 -1
- package/dist/production/src/core/exceptions/TreeParameterSugarer.js +0 -33
- package/dist/production/src/core/exceptions/TreeParameterSugarer.js.map +0 -1
- package/dist/production/src/core/factories/createBatchUpdatesOptions.cjs +0 -23
- package/dist/production/src/core/factories/createBatchUpdatesOptions.cjs.map +0 -1
- package/dist/production/src/core/factories/createBatchUpdatesOptions.js +0 -23
- package/dist/production/src/core/factories/createBatchUpdatesOptions.js.map +0 -1
- package/dist/production/src/core/operations/EntityOperations.cjs +0 -226
- package/dist/production/src/core/operations/EntityOperations.cjs.map +0 -1
- package/dist/production/src/core/operations/EntityOperations.js +0 -226
- package/dist/production/src/core/operations/EntityOperations.js.map +0 -1
- package/dist/production/src/core/operations/FieldOperations.cjs +0 -73
- package/dist/production/src/core/operations/FieldOperations.cjs.map +0 -1
- package/dist/production/src/core/operations/FieldOperations.js +0 -73
- package/dist/production/src/core/operations/FieldOperations.js.map +0 -1
- package/dist/production/src/core/operations/ListOperations.cjs +0 -158
- package/dist/production/src/core/operations/ListOperations.cjs.map +0 -1
- package/dist/production/src/core/operations/ListOperations.js +0 -158
- package/dist/production/src/core/operations/ListOperations.js.map +0 -1
- package/dist/production/src/core/operations/OperationsHelpers.cjs +0 -87
- package/dist/production/src/core/operations/OperationsHelpers.cjs.map +0 -1
- package/dist/production/src/core/operations/OperationsHelpers.js +0 -87
- package/dist/production/src/core/operations/OperationsHelpers.js.map +0 -1
- package/dist/production/src/core/requestAliases/MutationAlias.cjs +0 -14
- package/dist/production/src/core/requestAliases/MutationAlias.cjs.map +0 -1
- package/dist/production/src/core/requestAliases/MutationAlias.js +0 -14
- package/dist/production/src/core/requestAliases/MutationAlias.js.map +0 -1
- package/dist/production/src/core/state/StateIterator.cjs +0 -100
- package/dist/production/src/core/state/StateIterator.cjs.map +0 -1
- package/dist/production/src/core/state/StateIterator.js +0 -100
- package/dist/production/src/core/state/StateIterator.js.map +0 -1
- package/dist/production/src/core/state/getEntityMarker.cjs +0 -5
- package/dist/production/src/core/state/getEntityMarker.cjs.map +0 -1
- package/dist/production/src/core/state/getEntityMarker.js +0 -5
- package/dist/production/src/core/state/getEntityMarker.js.map +0 -1
- package/dist/production/src/core/utils/getCombinedSignal.cjs +0 -33
- package/dist/production/src/core/utils/getCombinedSignal.cjs.map +0 -1
- package/dist/production/src/core/utils/getCombinedSignal.js +0 -33
- package/dist/production/src/core/utils/getCombinedSignal.js.map +0 -1
- package/dist/production/src/fieldHelpers/helpers/FieldHelper.cjs +0 -13
- package/dist/production/src/fieldHelpers/helpers/FieldHelper.cjs.map +0 -1
- package/dist/production/src/fieldHelpers/helpers/FieldHelper.js +0 -13
- package/dist/production/src/fieldHelpers/helpers/FieldHelper.js.map +0 -1
- package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.cjs +0 -18
- package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.cjs.map +0 -1
- package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.js +0 -18
- package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.js.map +0 -1
- package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.cjs +0 -16
- package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.cjs.map +0 -1
- package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.js +0 -16
- package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.js.map +0 -1
- package/dist/production/src/utils/generateEnumerabilityPreventingEntropy.cjs +0 -7
- package/dist/production/src/utils/generateEnumerabilityPreventingEntropy.cjs.map +0 -1
- package/dist/production/src/utils/generateEnumerabilityPreventingEntropy.js +0 -7
- package/dist/production/src/utils/generateEnumerabilityPreventingEntropy.js.map +0 -1
- package/dist/production/src/utils/isEmptyObject.cjs +0 -12
- package/dist/production/src/utils/isEmptyObject.cjs.map +0 -1
- package/dist/production/src/utils/isEmptyObject.js +0 -12
- package/dist/production/src/utils/isEmptyObject.js.map +0 -1
- package/dist/types/accessorTree/NormalizedPersistedData.d.ts +0 -18
- package/dist/types/accessorTree/NormalizedPersistedData.d.ts.map +0 -1
- package/dist/types/accessorTree/index.d.ts +0 -2
- package/dist/types/accessorTree/index.d.ts.map +0 -1
- package/dist/types/accessors/BindingConfig.d.ts +0 -6
- package/dist/types/accessors/BindingConfig.d.ts.map +0 -1
- package/dist/types/accessors/EntityAccessorImpl.d.ts +0 -56
- package/dist/types/accessors/EntityAccessorImpl.d.ts.map +0 -1
- package/dist/types/accessors/EntityListAccessorImpl.d.ts +0 -57
- package/dist/types/accessors/EntityListAccessorImpl.d.ts.map +0 -1
- package/dist/types/accessors/FieldAccessorImpl.d.ts +0 -32
- package/dist/types/accessors/FieldAccessorImpl.d.ts.map +0 -1
- package/dist/types/accessors/index.d.ts +0 -5
- package/dist/types/accessors/index.d.ts.map +0 -1
- package/dist/types/core/AccessorErrorManager.d.ts +0 -25
- package/dist/types/core/AccessorErrorManager.d.ts.map +0 -1
- package/dist/types/core/Config.d.ts +0 -9
- package/dist/types/core/Config.d.ts.map +0 -1
- package/dist/types/core/DataBinding.d.ts +0 -54
- package/dist/types/core/DataBinding.d.ts.map +0 -1
- package/dist/types/core/DirtinessTracker.d.ts +0 -9
- package/dist/types/core/DirtinessTracker.d.ts.map +0 -1
- package/dist/types/core/ErrorsPreprocessor.d.ts +0 -34
- package/dist/types/core/ErrorsPreprocessor.d.ts.map +0 -1
- package/dist/types/core/EventManager.d.ts +0 -57
- package/dist/types/core/EventManager.d.ts.map +0 -1
- package/dist/types/core/MutationGenerator.d.ts +0 -49
- package/dist/types/core/MutationGenerator.d.ts.map +0 -1
- package/dist/types/core/QueryGenerator.d.ts +0 -13
- package/dist/types/core/QueryGenerator.d.ts.map +0 -1
- package/dist/types/core/RealmKeyGenerator.d.ts +0 -10
- package/dist/types/core/RealmKeyGenerator.d.ts.map +0 -1
- package/dist/types/core/RequestResponseNormalizer.d.ts +0 -11
- package/dist/types/core/RequestResponseNormalizer.d.ts.map +0 -1
- package/dist/types/core/StateInitializer.d.ts +0 -34
- package/dist/types/core/StateInitializer.d.ts.map +0 -1
- package/dist/types/core/TreeAugmenter.d.ts +0 -25
- package/dist/types/core/TreeAugmenter.d.ts.map +0 -1
- package/dist/types/core/TreeStore.d.ts +0 -30
- package/dist/types/core/TreeStore.d.ts.map +0 -1
- package/dist/types/core/UpdateMetadata.d.ts +0 -4
- package/dist/types/core/UpdateMetadata.d.ts.map +0 -1
- package/dist/types/core/exceptions/ErrorLocator.d.ts +0 -8
- package/dist/types/core/exceptions/ErrorLocator.d.ts.map +0 -1
- package/dist/types/core/exceptions/MarkerSugarer.d.ts +0 -10
- package/dist/types/core/exceptions/MarkerSugarer.d.ts.map +0 -1
- package/dist/types/core/exceptions/TreeParameterSugarer.d.ts +0 -11
- package/dist/types/core/exceptions/TreeParameterSugarer.d.ts.map +0 -1
- package/dist/types/core/factories/createBatchUpdatesOptions.d.ts +0 -5
- package/dist/types/core/factories/createBatchUpdatesOptions.d.ts.map +0 -1
- package/dist/types/core/factories/index.d.ts +0 -2
- package/dist/types/core/factories/index.d.ts.map +0 -1
- package/dist/types/core/index.d.ts +0 -9
- package/dist/types/core/index.d.ts.map +0 -1
- package/dist/types/core/operations/EntityOperations.d.ts +0 -26
- package/dist/types/core/operations/EntityOperations.d.ts.map +0 -1
- package/dist/types/core/operations/FieldOperations.d.ts +0 -22
- package/dist/types/core/operations/FieldOperations.d.ts.map +0 -1
- package/dist/types/core/operations/ListOperations.d.ts +0 -32
- package/dist/types/core/operations/ListOperations.d.ts.map +0 -1
- package/dist/types/core/operations/OperationsHelpers.d.ts +0 -14
- package/dist/types/core/operations/OperationsHelpers.d.ts.map +0 -1
- package/dist/types/core/operations/index.d.ts +0 -4
- package/dist/types/core/operations/index.d.ts.map +0 -1
- package/dist/types/core/requestAliases/MutationAlias.d.ts +0 -6
- package/dist/types/core/requestAliases/MutationAlias.d.ts.map +0 -1
- package/dist/types/core/requestAliases/index.d.ts +0 -2
- package/dist/types/core/requestAliases/index.d.ts.map +0 -1
- package/dist/types/core/state/EntityListState.d.ts +0 -29
- package/dist/types/core/state/EntityListState.d.ts.map +0 -1
- package/dist/types/core/state/EntityRealmState.d.ts +0 -44
- package/dist/types/core/state/EntityRealmState.d.ts.map +0 -1
- package/dist/types/core/state/EntityState.d.ts +0 -11
- package/dist/types/core/state/EntityState.d.ts.map +0 -1
- package/dist/types/core/state/FieldState.d.ts +0 -19
- package/dist/types/core/state/FieldState.d.ts.map +0 -1
- package/dist/types/core/state/StateIterator.d.ts +0 -14
- package/dist/types/core/state/StateIterator.d.ts.map +0 -1
- package/dist/types/core/state/StateNode.d.ts +0 -8
- package/dist/types/core/state/StateNode.d.ts.map +0 -1
- package/dist/types/core/state/getEntityMarker.d.ts +0 -3
- package/dist/types/core/state/getEntityMarker.d.ts.map +0 -1
- package/dist/types/core/state/index.d.ts +0 -8
- package/dist/types/core/state/index.d.ts.map +0 -1
- package/dist/types/core/utils/getCombinedSignal.d.ts +0 -2
- package/dist/types/core/utils/getCombinedSignal.d.ts.map +0 -1
- package/dist/types/core/utils/index.d.ts +0 -2
- package/dist/types/core/utils/index.d.ts.map +0 -1
- package/dist/types/fieldHelpers/helpers/FieldHelper.d.ts +0 -7
- package/dist/types/fieldHelpers/helpers/FieldHelper.d.ts.map +0 -1
- package/dist/types/fieldHelpers/helpers/TemporalFieldHelper.d.ts +0 -10
- package/dist/types/fieldHelpers/helpers/TemporalFieldHelper.d.ts.map +0 -1
- package/dist/types/fieldHelpers/helpers/UuidFieldHelper.d.ts +0 -10
- package/dist/types/fieldHelpers/helpers/UuidFieldHelper.d.ts.map +0 -1
- package/dist/types/fieldHelpers/helpers/index.d.ts +0 -3
- package/dist/types/fieldHelpers/helpers/index.d.ts.map +0 -1
- package/dist/types/fieldHelpers/index.d.ts +0 -2
- package/dist/types/fieldHelpers/index.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -5
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/tsconfig.tsbuildinfo +0 -1
- package/dist/types/utils/assertNever.d.ts +0 -2
- package/dist/types/utils/assertNever.d.ts.map +0 -1
- package/dist/types/utils/generateEnumerabilityPreventingEntropy.d.ts +0 -2
- package/dist/types/utils/generateEnumerabilityPreventingEntropy.d.ts.map +0 -1
- package/dist/types/utils/index.d.ts +0 -4
- package/dist/types/utils/index.d.ts.map +0 -1
- package/dist/types/utils/isEmptyObject.d.ts +0 -2
- package/dist/types/utils/isEmptyObject.d.ts.map +0 -1
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
import { ServerId, assertNever, BindingError, UnpersistedEntityDummyId, ClientGeneratedUuid, HasOneRelationMarker } from "@contember/binding-common";
|
|
2
|
-
import { EventManager } from "./EventManager.js";
|
|
3
|
-
import { OperationsHelpers } from "./operations/OperationsHelpers.js";
|
|
4
|
-
import { getEntityMarker } from "./state/getEntityMarker.js";
|
|
5
|
-
class TreeAugmenter {
|
|
6
|
-
constructor(eventManager, stateInitializer, treeStore, skipStateUpdateAfterPersist = false) {
|
|
7
|
-
this.eventManager = eventManager;
|
|
8
|
-
this.stateInitializer = stateInitializer;
|
|
9
|
-
this.treeStore = treeStore;
|
|
10
|
-
this.skipStateUpdateAfterPersist = skipStateUpdateAfterPersist;
|
|
11
|
-
}
|
|
12
|
-
extendPersistedData(newPersistedData, markerTree) {
|
|
13
|
-
this.treeStore.mergeInQueryResponse(newPersistedData, markerTree);
|
|
14
|
-
}
|
|
15
|
-
extendTreeStates(newTreeId, newMarkerTree) {
|
|
16
|
-
const subTreeStates = /* @__PURE__ */ new Map();
|
|
17
|
-
this.treeStore.markerTrees.set(newTreeId, newMarkerTree);
|
|
18
|
-
this.treeStore.subTreeStatesByRoot.set(newTreeId, subTreeStates);
|
|
19
|
-
for (const [placeholderName, newSubTreeMarker] of newMarkerTree.subTrees) {
|
|
20
|
-
const newState = this.stateInitializer.initializeSubTree(newSubTreeMarker);
|
|
21
|
-
subTreeStates.set(placeholderName, newState);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
updatePersistedData(response, operations) {
|
|
25
|
-
this.treeStore.mergeInMutationResponse(response, operations);
|
|
26
|
-
if (this.skipStateUpdateAfterPersist) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
this.eventManager.syncTransaction(() => {
|
|
30
|
-
for (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {
|
|
31
|
-
for (const [rootPlaceholder, rootState] of rootStates) {
|
|
32
|
-
const rootData = this.treeStore.subTreePersistedData.get(rootPlaceholder);
|
|
33
|
-
if (rootState.type === "entityList") {
|
|
34
|
-
if (!(rootData instanceof Set)) {
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
this.updateEntityListPersistedData(rootState, rootData);
|
|
38
|
-
} else if (rootState.type === "entityRealm") {
|
|
39
|
-
if (rootData !== void 0 && !(rootData instanceof ServerId)) {
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
this.updateRealmIdIfNecessary(rootState, rootData);
|
|
43
|
-
this.updateEntityRealmPersistedData(rootState);
|
|
44
|
-
} else {
|
|
45
|
-
return assertNever(rootState);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
resetCreatingSubTrees() {
|
|
52
|
-
for (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {
|
|
53
|
-
for (const [rootPlaceholder, rootState] of rootStates) {
|
|
54
|
-
if (rootState.type === "entityList") {
|
|
55
|
-
if (rootState.blueprint.parent !== void 0) {
|
|
56
|
-
throw new BindingError("Entity list root should not have a parent.");
|
|
57
|
-
}
|
|
58
|
-
if (!rootState.blueprint.marker.parameters.isCreating) {
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
this.treeStore.subTreePersistedData.delete(rootPlaceholder);
|
|
62
|
-
const changesCount = rootState.unpersistedChangesCount;
|
|
63
|
-
for (const childState of rootState.children.values()) {
|
|
64
|
-
this.treeStore.disposeOfRealm(childState);
|
|
65
|
-
}
|
|
66
|
-
rootState.accessor = void 0;
|
|
67
|
-
rootState.children.clear();
|
|
68
|
-
rootState.childrenWithPendingUpdates?.clear();
|
|
69
|
-
rootState.errors = void 0;
|
|
70
|
-
rootState.plannedRemovals?.clear();
|
|
71
|
-
this.eventManager.registerJustUpdated(
|
|
72
|
-
rootState,
|
|
73
|
-
changesCount ? -1 * changesCount : EventManager.NO_CHANGES_DIFFERENCE
|
|
74
|
-
);
|
|
75
|
-
} else if (rootState.type === "entityRealm") {
|
|
76
|
-
if (rootState.blueprint.parent !== void 0) {
|
|
77
|
-
throw new BindingError("Entity realm root should not have a parent.");
|
|
78
|
-
}
|
|
79
|
-
if (!rootState.blueprint.marker.parameters.isCreating) {
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
const presentListeners = rootState.eventListeners;
|
|
83
|
-
this.treeStore.disposeOfRealm(rootState);
|
|
84
|
-
this.treeStore.subTreePersistedData.delete(rootPlaceholder);
|
|
85
|
-
const newRootState = this.stateInitializer.initializeSubTree(rootState.blueprint.marker);
|
|
86
|
-
newRootState.eventListeners = presentListeners;
|
|
87
|
-
OperationsHelpers.purgeStaleListenersAfterIdChange(newRootState);
|
|
88
|
-
rootStates.set(rootPlaceholder, newRootState);
|
|
89
|
-
this.eventManager.registerJustUpdated(newRootState, EventManager.NO_CHANGES_DIFFERENCE);
|
|
90
|
-
} else {
|
|
91
|
-
assertNever(rootState);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
updateRealmIdIfNecessary(realm, newId) {
|
|
97
|
-
const currentId = realm.entity.id;
|
|
98
|
-
let idToChangeTo = void 0;
|
|
99
|
-
if (currentId instanceof ServerId) {
|
|
100
|
-
if (newId === void 0 || newId === null) {
|
|
101
|
-
idToChangeTo = new UnpersistedEntityDummyId();
|
|
102
|
-
} else if (currentId.value !== newId.value) {
|
|
103
|
-
idToChangeTo = newId;
|
|
104
|
-
}
|
|
105
|
-
} else if (currentId instanceof ClientGeneratedUuid) {
|
|
106
|
-
idToChangeTo = newId ?? new UnpersistedEntityDummyId();
|
|
107
|
-
} else if (currentId instanceof UnpersistedEntityDummyId) {
|
|
108
|
-
if (newId) {
|
|
109
|
-
idToChangeTo = newId;
|
|
110
|
-
}
|
|
111
|
-
} else {
|
|
112
|
-
return assertNever(currentId);
|
|
113
|
-
}
|
|
114
|
-
if (idToChangeTo) {
|
|
115
|
-
OperationsHelpers.changeRealmId(this.treeStore, this.eventManager, this.stateInitializer, realm, idToChangeTo);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
updateEntityRealmPersistedData(realm) {
|
|
119
|
-
const realmId = realm.entity.id;
|
|
120
|
-
const persistedData = realmId.existsOnServer ? this.treeStore.persistedEntityData.get(realmId.uniqueValue) : void 0;
|
|
121
|
-
for (const [placeholderName, child] of realm.children) {
|
|
122
|
-
const childData = persistedData?.get(placeholderName)?.value;
|
|
123
|
-
switch (child.type) {
|
|
124
|
-
case "field": {
|
|
125
|
-
if (childData instanceof ServerId || childData instanceof Set) {
|
|
126
|
-
throw new BindingError();
|
|
127
|
-
}
|
|
128
|
-
if (child.persistedValue !== childData) {
|
|
129
|
-
const shouldChangeBothValues = (child.persistedValue ?? null) === child.value;
|
|
130
|
-
child.persistedValue = childData;
|
|
131
|
-
if (shouldChangeBothValues) {
|
|
132
|
-
child.value = childData ?? null;
|
|
133
|
-
}
|
|
134
|
-
this.eventManager.registerJustUpdated(child, EventManager.NO_CHANGES_DIFFERENCE);
|
|
135
|
-
}
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
case "entityRealm":
|
|
139
|
-
case "entityRealmStub": {
|
|
140
|
-
if (!(childData instanceof ServerId) && childData !== void 0 && childData !== null) {
|
|
141
|
-
throw new BindingError();
|
|
142
|
-
}
|
|
143
|
-
this.updateRealmIdIfNecessary(child, childData);
|
|
144
|
-
if (child.type === "entityRealm") {
|
|
145
|
-
this.updateEntityRealmPersistedData(child);
|
|
146
|
-
}
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
case "entityList": {
|
|
150
|
-
if (childData !== void 0 && !(childData instanceof Set)) {
|
|
151
|
-
throw new BindingError();
|
|
152
|
-
}
|
|
153
|
-
this.updateEntityListPersistedData(child, childData ?? /* @__PURE__ */ new Set());
|
|
154
|
-
break;
|
|
155
|
-
}
|
|
156
|
-
default: {
|
|
157
|
-
return assertNever(child);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
updateEntityListPersistedData(state, newPersistedIds) {
|
|
163
|
-
const persistedWithoutState = /* @__PURE__ */ new Set();
|
|
164
|
-
for (const persistedId of newPersistedIds) {
|
|
165
|
-
if (!state.children.has(persistedId)) {
|
|
166
|
-
persistedWithoutState.add(persistedId);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
for (const [stateId, child] of state.children) {
|
|
170
|
-
const childRuntimeId = child.entity.id;
|
|
171
|
-
if (!newPersistedIds.has(stateId)) {
|
|
172
|
-
if (
|
|
173
|
-
// It's a uuid but it's not among the persisted so either it got deleted/disconnected or the client-side
|
|
174
|
-
// id generation didn't quite pan out.
|
|
175
|
-
childRuntimeId instanceof ServerId || childRuntimeId instanceof ClientGeneratedUuid || // No persisted entity id to allocate to this so that's a goodbye.
|
|
176
|
-
persistedWithoutState.size === 0 || // not a persisted entity
|
|
177
|
-
child.type === "entityRealmStub" || // We couldn't find a matching persisted entity
|
|
178
|
-
!this.tryAssignIdToMatching(child, persistedWithoutState)
|
|
179
|
-
) {
|
|
180
|
-
state.getAccessor().disconnectEntity(child.getAccessor());
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
} else if (childRuntimeId instanceof ClientGeneratedUuid) {
|
|
184
|
-
OperationsHelpers.changeRealmId(
|
|
185
|
-
this.treeStore,
|
|
186
|
-
this.eventManager,
|
|
187
|
-
this.stateInitializer,
|
|
188
|
-
child,
|
|
189
|
-
new ServerId(childRuntimeId.value, child.entity.entityName)
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
if (child.type === "entityRealm") {
|
|
193
|
-
this.updateEntityRealmPersistedData(child);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
for (const unclaimedPersistedId of persistedWithoutState) {
|
|
197
|
-
this.stateInitializer.initializeEntityRealm(new ServerId(unclaimedPersistedId, state.entityName), state.entityName, {
|
|
198
|
-
type: "listEntity",
|
|
199
|
-
parent: state
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
state.children.changeKeyOrder(newPersistedIds);
|
|
203
|
-
}
|
|
204
|
-
tryAssignIdToMatching(realm, ids) {
|
|
205
|
-
for (const candidateId of ids) {
|
|
206
|
-
if (this.isEntityMatching(realm, candidateId)) {
|
|
207
|
-
OperationsHelpers.changeRealmId(
|
|
208
|
-
this.treeStore,
|
|
209
|
-
this.eventManager,
|
|
210
|
-
this.stateInitializer,
|
|
211
|
-
realm,
|
|
212
|
-
new ServerId(candidateId, realm.entity.entityName)
|
|
213
|
-
);
|
|
214
|
-
ids.delete(candidateId);
|
|
215
|
-
return true;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return false;
|
|
219
|
-
}
|
|
220
|
-
isEntityMatching(realm, id) {
|
|
221
|
-
const uniqueId = ServerId.formatUniqueValue(id, realm.entity.entityName);
|
|
222
|
-
const persistedData = this.treeStore.persistedEntityData.get(uniqueId);
|
|
223
|
-
const pathBack = this.treeStore.getPathBackToParent(realm);
|
|
224
|
-
for (const [placeholderName, child] of realm.children) {
|
|
225
|
-
const childData = persistedData?.get(placeholderName)?.value;
|
|
226
|
-
switch (child.type) {
|
|
227
|
-
case "field": {
|
|
228
|
-
if (childData instanceof ServerId || childData instanceof Set) {
|
|
229
|
-
throw new BindingError();
|
|
230
|
-
}
|
|
231
|
-
const value = child.value ?? child.fieldMarker.defaultValue ?? null;
|
|
232
|
-
if (value !== null && childData !== value) {
|
|
233
|
-
return false;
|
|
234
|
-
}
|
|
235
|
-
break;
|
|
236
|
-
}
|
|
237
|
-
case "entityRealm":
|
|
238
|
-
case "entityRealmStub": {
|
|
239
|
-
if (!(childData instanceof ServerId) && childData !== void 0 && childData !== null) {
|
|
240
|
-
throw new BindingError();
|
|
241
|
-
}
|
|
242
|
-
if (child.entity.id.existsOnServer || child.entity.id instanceof ClientGeneratedUuid) {
|
|
243
|
-
if (child.entity.id.value !== childData?.value) {
|
|
244
|
-
return false;
|
|
245
|
-
}
|
|
246
|
-
} else if (childData) {
|
|
247
|
-
const marker = getEntityMarker(child);
|
|
248
|
-
if (!(marker instanceof HasOneRelationMarker)) {
|
|
249
|
-
throw new BindingError();
|
|
250
|
-
}
|
|
251
|
-
if (pathBack?.fieldBackToParent === marker.parameters.field) {
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
if (child.type !== "entityRealm" || !this.isEntityMatching(child, childData.value)) {
|
|
255
|
-
return false;
|
|
256
|
-
}
|
|
257
|
-
} else if (child.type === "entityRealmStub") {
|
|
258
|
-
break;
|
|
259
|
-
} else {
|
|
260
|
-
if (!this.isEmptyEntity(child)) {
|
|
261
|
-
return false;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
break;
|
|
265
|
-
}
|
|
266
|
-
case "entityList": {
|
|
267
|
-
if (childData !== void 0 && !(childData instanceof Set)) {
|
|
268
|
-
throw new BindingError();
|
|
269
|
-
}
|
|
270
|
-
if (!childData) {
|
|
271
|
-
break;
|
|
272
|
-
}
|
|
273
|
-
if (childData?.size !== child.children.size) {
|
|
274
|
-
return false;
|
|
275
|
-
}
|
|
276
|
-
const remainingIds = new Set(childData);
|
|
277
|
-
for (const childItem of child.children.values()) {
|
|
278
|
-
if (childItem.entity.id.existsOnServer || childItem.entity.id instanceof ClientGeneratedUuid) {
|
|
279
|
-
if (!childData.has(childItem.entity.id.value)) {
|
|
280
|
-
return false;
|
|
281
|
-
}
|
|
282
|
-
remainingIds.delete(childItem.entity.id.value);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
for (const childItem of child.children.values()) {
|
|
286
|
-
if (!(childItem.entity.id.existsOnServer || childItem.entity.id instanceof ClientGeneratedUuid) && childItem.type === "entityRealm") {
|
|
287
|
-
let hasMatch = false;
|
|
288
|
-
for (const id2 of remainingIds) {
|
|
289
|
-
if (this.isEntityMatching(childItem, id2)) {
|
|
290
|
-
remainingIds.delete(id2);
|
|
291
|
-
hasMatch = true;
|
|
292
|
-
break;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
if (!hasMatch) {
|
|
296
|
-
return false;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
if (remainingIds.size !== 0) {
|
|
301
|
-
return false;
|
|
302
|
-
}
|
|
303
|
-
break;
|
|
304
|
-
}
|
|
305
|
-
default: {
|
|
306
|
-
return assertNever(child);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
return true;
|
|
311
|
-
}
|
|
312
|
-
isEmptyEntity(entity) {
|
|
313
|
-
const pathBack = this.treeStore.getPathBackToParent(entity);
|
|
314
|
-
for (const [placeholderName, child] of entity.children) {
|
|
315
|
-
if (child.type === "field") {
|
|
316
|
-
if (child.fieldMarker.isNonbearing) {
|
|
317
|
-
continue;
|
|
318
|
-
}
|
|
319
|
-
if (child.value !== null || child.fieldMarker.defaultValue !== null) {
|
|
320
|
-
return false;
|
|
321
|
-
}
|
|
322
|
-
} else if (child.type === "entityRealm") {
|
|
323
|
-
const marker = getEntityMarker(child);
|
|
324
|
-
const isNonBearing = marker.parameters.isNonbearing;
|
|
325
|
-
if (isNonBearing) {
|
|
326
|
-
continue;
|
|
327
|
-
}
|
|
328
|
-
if (!(marker instanceof HasOneRelationMarker)) {
|
|
329
|
-
throw new BindingError();
|
|
330
|
-
}
|
|
331
|
-
if (pathBack?.fieldBackToParent === marker.parameters.field) {
|
|
332
|
-
continue;
|
|
333
|
-
}
|
|
334
|
-
if (!this.isEmptyEntity(child)) {
|
|
335
|
-
return false;
|
|
336
|
-
}
|
|
337
|
-
} else if (child.type === "entityList") {
|
|
338
|
-
if (child.blueprint.marker.parameters.isNonbearing) {
|
|
339
|
-
continue;
|
|
340
|
-
}
|
|
341
|
-
for (const childItem of child.children.values()) {
|
|
342
|
-
if (childItem.type === "entityRealm" && !this.isEmptyEntity(childItem)) {
|
|
343
|
-
return false;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
return true;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
export {
|
|
352
|
-
TreeAugmenter
|
|
353
|
-
};
|
|
354
|
-
//# sourceMappingURL=TreeAugmenter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TreeAugmenter.js","sources":["../../../../../packages/binding-legacy/src/core/TreeAugmenter.ts"],"sourcesContent":["import {\n\tClientGeneratedUuid,\n\tHasOneRelationMarker,\n\tReceivedDataTree,\n\tRuntimeId,\n\tServerId,\n\tUnpersistedEntityDummyId,\n} from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport type { MarkerTreeRoot } from '@contember/binding-common'\nimport type { EntityId, PlaceholderName, TreeRootId } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport { EventManager } from './EventManager'\nimport { OperationsHelpers } from './operations/OperationsHelpers'\nimport { EntityListState, EntityRealmState, EntityRealmStateStub, getEntityMarker, RootStateNode } from './state'\nimport type { StateInitializer } from './StateInitializer'\nimport type { TreeStore } from './TreeStore'\nimport { SubMutationOperation } from './MutationGenerator'\nimport { EntityListPersistedData } from '../accessorTree'\n\nexport class TreeAugmenter {\n\tpublic constructor(\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly skipStateUpdateAfterPersist: boolean = false,\n\t) {}\n\n\tpublic extendPersistedData(newPersistedData: ReceivedDataTree, markerTree: MarkerTreeRoot) {\n\t\t// TODO this doesn't yet handle updates for entities whose persisted data just gets magically changed without notice.\n\t\tthis.treeStore.mergeInQueryResponse(newPersistedData, markerTree)\n\t}\n\n\tpublic extendTreeStates(newTreeId: TreeRootId | undefined, newMarkerTree: MarkerTreeRoot): void {\n\t\tconst subTreeStates: Map<PlaceholderName, RootStateNode> = new Map()\n\n\t\tthis.treeStore.markerTrees.set(newTreeId, newMarkerTree)\n\t\tthis.treeStore.subTreeStatesByRoot.set(newTreeId, subTreeStates)\n\n\t\tfor (const [placeholderName, newSubTreeMarker] of newMarkerTree.subTrees) {\n\t\t\tconst newState = this.stateInitializer.initializeSubTree(newSubTreeMarker)\n\t\t\tsubTreeStates.set(placeholderName, newState)\n\t\t}\n\t}\n\n\tpublic updatePersistedData(response: ReceivedDataTree, operations: SubMutationOperation[]) {\n\t\tthis.treeStore.mergeInMutationResponse(response, operations)\n\t\tif (this.skipStateUpdateAfterPersist) {\n\t\t\treturn\n\t\t}\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\t\t// for (const rootPlaceholder in response) {\n\t\t\t\t// \tconst rootState = rootStates.get(rootPlaceholder)\n\t\t\t\t//\n\t\t\t\t// \tif (rootState === undefined) {\n\t\t\t\t// \t\tcontinue\n\t\t\t\t// \t}\n\t\t\t\t// TODO the above would be better, only refreshing roots which participated in the mutation. However, due to\n\t\t\t\t// \thow mutations are currently generated, we cannot assume that only roots present in the response need\n\t\t\t\t// \trefreshed. So we just refresh all.\n\t\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\t\tconst rootData = this.treeStore.subTreePersistedData.get(rootPlaceholder)\n\n\t\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\t\tif (!(rootData instanceof Set)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateEntityListPersistedData(rootState, rootData)\n\t\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\t\tif (rootData !== undefined && !(rootData instanceof ServerId)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateRealmIdIfNecessary(rootState, rootData)\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(rootState)\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn assertNever(rootState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic resetCreatingSubTrees() {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\tif (rootState.blueprint.parent !== undefined) {\n\t\t\t\t\t\tthrow new BindingError('Entity list root should not have a parent.')\n\t\t\t\t\t}\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst changesCount = rootState.unpersistedChangesCount\n\n\t\t\t\t\t// Just emptying the list. But the list itself can stay.\n\t\t\t\t\tfor (const childState of rootState.children.values()) {\n\t\t\t\t\t\tthis.treeStore.disposeOfRealm(childState)\n\t\t\t\t\t}\n\t\t\t\t\trootState.accessor = undefined\n\t\t\t\t\trootState.children.clear()\n\t\t\t\t\trootState.childrenWithPendingUpdates?.clear()\n\t\t\t\t\trootState.errors = undefined\n\t\t\t\t\trootState.plannedRemovals?.clear()\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(\n\t\t\t\t\t\trootState,\n\t\t\t\t\t\tchangesCount ? -1 * changesCount : EventManager.NO_CHANGES_DIFFERENCE,\n\t\t\t\t\t)\n\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\tif (rootState.blueprint.parent !== undefined) {\n\t\t\t\t\t\tthrow new BindingError('Entity realm root should not have a parent.')\n\t\t\t\t\t}\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst presentListeners = rootState.eventListeners\n\t\t\t\t\tthis.treeStore.disposeOfRealm(rootState)\n\n\t\t\t\t\t// It's crucial to delete the persisted data before we re-initialize so that we get a fresh, new entity.\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst newRootState = this.stateInitializer.initializeSubTree(rootState.blueprint.marker)\n\n\t\t\t\t\t// We preserve the previous listeners but purge some of them.\n\t\t\t\t\tnewRootState.eventListeners = presentListeners\n\t\t\t\t\tOperationsHelpers.purgeStaleListenersAfterIdChange(newRootState as EntityRealmState)\n\n\t\t\t\t\trootStates.set(rootPlaceholder, newRootState)\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(newRootState, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(rootState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateRealmIdIfNecessary(\n\t\trealm: EntityRealmState | EntityRealmStateStub,\n\t\tnewId: ServerId | undefined | null,\n\t) {\n\t\tconst currentId = realm.entity.id\n\t\tlet idToChangeTo: RuntimeId | undefined = undefined\n\n\t\tif (currentId instanceof ServerId) {\n\t\t\tif (newId === undefined || newId === null) {\n\t\t\t\tidToChangeTo = new UnpersistedEntityDummyId()\n\t\t\t} else if (currentId.value !== newId.value) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else if (currentId instanceof ClientGeneratedUuid) {\n\t\t\tidToChangeTo = newId ?? new UnpersistedEntityDummyId()\n\t\t} else if (currentId instanceof UnpersistedEntityDummyId) {\n\t\t\tif (newId) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else {\n\t\t\treturn assertNever(currentId)\n\t\t}\n\t\tif (idToChangeTo) {\n\t\t\tOperationsHelpers.changeRealmId(this.treeStore, this.eventManager, this.stateInitializer, realm, idToChangeTo)\n\t\t}\n\t}\n\n\tprivate updateEntityRealmPersistedData(realm: EntityRealmState) {\n\t\tconst realmId = realm.entity.id\n\t\tconst persistedData = realmId.existsOnServer ? this.treeStore.persistedEntityData.get(realmId.uniqueValue) : undefined\n\n\t\tfor (const [placeholderName, child] of realm.children) {\n\t\t\tconst childData = persistedData?.get(placeholderName)?.value\n\n\t\t\tswitch (child.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (childData instanceof ServerId || childData instanceof Set) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (child.persistedValue !== childData) {\n\t\t\t\t\t\tconst shouldChangeBothValues = (child.persistedValue ?? null) === child.value\n\n\t\t\t\t\t\tchild.persistedValue = childData\n\t\t\t\t\t\tif (shouldChangeBothValues) {\n\t\t\t\t\t\t\tchild.value = childData ?? null\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.eventManager.registerJustUpdated(child, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\tif (!(childData instanceof ServerId) && childData !== undefined && childData !== null) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateRealmIdIfNecessary(child, childData)\n\t\t\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (childData !== undefined && !(childData instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateEntityListPersistedData(child, childData ?? new Set()) // TODO!!\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn assertNever(child)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateEntityListPersistedData(state: EntityListState, newPersistedIds: EntityListPersistedData) {\n\t\tconst persistedWithoutState = new Set<EntityId>()\n\n\t\tfor (const persistedId of newPersistedIds) {\n\t\t\tif (!state.children.has(persistedId)) {\n\t\t\t\tpersistedWithoutState.add(persistedId)\n\t\t\t}\n\t\t}\n\t\tfor (const [stateId, child] of state.children) {\n\t\t\tconst childRuntimeId = child.entity.id\n\t\t\tif (!newPersistedIds.has(stateId)) {\n\t\t\t\tif (\n\t\t\t\t\t// It's a uuid but it's not among the persisted so either it got deleted/disconnected or the client-side\n\t\t\t\t\t// id generation didn't quite pan out.\n\t\t\t\t\tchildRuntimeId instanceof ServerId ||\n\t\t\t\t\tchildRuntimeId instanceof ClientGeneratedUuid ||\n\t\t\t\t\t// No persisted entity id to allocate to this so that's a goodbye.\n\t\t\t\t\tpersistedWithoutState.size === 0 ||\n\t\t\t\t\t// not a persisted entity\n\t\t\t\t\tchild.type === 'entityRealmStub' ||\n\t\t\t\t\t// We couldn't find a matching persisted entity\n\t\t\t\t\t!this.tryAssignIdToMatching(child, persistedWithoutState)\n\t\t\t\t) {\n\t\t\t\t\tstate.getAccessor().disconnectEntity(child.getAccessor())\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t} else if (childRuntimeId instanceof ClientGeneratedUuid) {\n\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\tthis.treeStore,\n\t\t\t\t\tthis.eventManager,\n\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\tchild,\n\t\t\t\t\tnew ServerId(childRuntimeId.value, child.entity.entityName),\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t}\n\t\t}\n\t\tfor (const unclaimedPersistedId of persistedWithoutState) {\n\t\t\tthis.stateInitializer.initializeEntityRealm(new ServerId(unclaimedPersistedId, state.entityName), state.entityName, {\n\t\t\t\ttype: 'listEntity',\n\t\t\t\tparent: state,\n\t\t\t})\n\t\t}\n\t\t// All that remains now is the order.\n\t\tstate.children.changeKeyOrder(newPersistedIds)\n\t}\n\n\tprivate tryAssignIdToMatching(realm: EntityRealmState, ids: Set<EntityId>) {\n\t\tfor (const candidateId of ids) {\n\t\t\tif (this.isEntityMatching(realm, candidateId)) {\n\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\tthis.treeStore,\n\t\t\t\t\tthis.eventManager,\n\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\trealm,\n\t\t\t\t\tnew ServerId(candidateId, realm.entity.entityName),\n\t\t\t\t)\n\t\t\t\tids.delete(candidateId)\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n\n\tprivate isEntityMatching(realm: EntityRealmState, id: EntityId) {\n\t\tconst uniqueId = ServerId.formatUniqueValue(id, realm.entity.entityName)\n\t\tconst persistedData = this.treeStore.persistedEntityData.get(uniqueId)\n\t\tconst pathBack = this.treeStore.getPathBackToParent(realm)\n\t\tfor (const [placeholderName, child] of realm.children) {\n\t\t\tconst childData = persistedData?.get(placeholderName)?.value\n\n\t\t\tswitch (child.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (childData instanceof ServerId || childData instanceof Set) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tconst value = child.value ?? child.fieldMarker.defaultValue ?? null\n\t\t\t\t\tif (value !== null && childData !== value) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\tif (!(childData instanceof ServerId) && childData !== undefined && childData !== null) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (child.entity.id.existsOnServer || child.entity.id instanceof ClientGeneratedUuid) {\n\t\t\t\t\t\tif (child.entity.id.value !== childData?.value) {\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (childData) {\n\t\t\t\t\t\tconst marker = getEntityMarker(child)\n\t\t\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (child.type !== 'entityRealm' || !this.isEntityMatching(child, childData.value)) {\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (child.type === 'entityRealmStub') {\n\t\t\t\t\t\tbreak\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (!this.isEmptyEntity(child)) {\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (childData !== undefined && !(childData instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (!childData){\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tif (childData?.size !== child.children.size) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t\tconst remainingIds = new Set(childData)\n\n\t\t\t\t\t// first check items with known ids\n\t\t\t\t\tfor (const childItem of child.children.values()) {\n\t\t\t\t\t\tif ((childItem.entity.id.existsOnServer || childItem.entity.id instanceof ClientGeneratedUuid)) {\n\t\t\t\t\t\t\tif (!childData.has(childItem.entity.id.value)) {\n\t\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tremainingIds.delete(childItem.entity.id.value)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// then check items with unknown ids\n\t\t\t\t\tfor (const childItem of child.children.values()) {\n\t\t\t\t\t\tif (!(childItem.entity.id.existsOnServer || childItem.entity.id instanceof ClientGeneratedUuid) && childItem.type === 'entityRealm') {\n\t\t\t\t\t\t\tlet hasMatch = false\n\t\t\t\t\t\t\tfor (const id of remainingIds) {\n\t\t\t\t\t\t\t\tif (this.isEntityMatching(childItem, id)) {\n\t\t\t\t\t\t\t\t\tremainingIds.delete(id)\n\t\t\t\t\t\t\t\t\thasMatch = true\n\t\t\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (!hasMatch) {\n\t\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (remainingIds.size !== 0) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn assertNever(child)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\n\tprivate isEmptyEntity(entity: EntityRealmState) {\n\t\tconst pathBack = this.treeStore.getPathBackToParent(entity)\n\t\tfor (const [placeholderName, child] of entity.children) {\n\t\t\tif (child.type === 'field') {\n\t\t\t\tif (child.fieldMarker.isNonbearing) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif ((child.value !== null || child.fieldMarker.defaultValue !== null)) {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t} else if (child.type === 'entityRealm') {\n\t\t\t\tconst marker = getEntityMarker(child)\n\t\t\t\tconst isNonBearing = marker.parameters.isNonbearing\n\t\t\t\tif (isNonBearing) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (!this.isEmptyEntity(child)) {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t} else if (child.type === 'entityList') {\n\t\t\t\tif (child.blueprint.marker.parameters.isNonbearing) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tfor (const childItem of child.children.values()) {\n\t\t\t\t\tif (childItem.type === 'entityRealm' && !this.isEmptyEntity(childItem)) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n}\n"],"names":["id"],"mappings":";;;;AAoBO,MAAM,cAAc;AAAA,EACnB,YACW,cACA,kBACA,WACA,8BAAuC,OACvD;AAJgB,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AACA,SAAA,8BAAA;AAAA,EAAA;AAAA,EAGX,oBAAoB,kBAAoC,YAA4B;AAErF,SAAA,UAAU,qBAAqB,kBAAkB,UAAU;AAAA,EAAA;AAAA,EAG1D,iBA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AACrB,mBAAA;AAAA,UAAA;AAER;AAAA,QAAA;AAAA,QAED,SAAS;AACR,iBAAO,YAAY,KAAK;AAAA,QAAA;AAAA,MACzB;AAAA,IACD;AAEM,WAAA;AAAA,EAAA;AAAA,EAGA,cAAc,QAA0B;AAC/C,UAAM,WAAW,KAAK,UAAU,oBAAoB,MAAM;AAC1D,eAAW,CAAC,iBAAiB,KAAK,KAAK,OAAO,UAAU;AACnD,UAAA,MAAM,SAAS,SAAS;AACvB,YAAA,MAAM,YAAY,cAAc;AACnC;AAAA,QAAA;AAED,YAAK,MAAM,UAAU,QAAQ,MAAM,YAAY,iBAAiB,MAAO;AAC/D,iBAAA;AAAA,QAAA;AAAA,MACR,WACU,MAAM,SAAS,eAAe;AAClC,cAAA,SAAS,gBAAgB,KAAK;AAC9B,cAAA,eAAe,OAAO,WAAW;AACvC,YAAI,cAAc;AACjB;AAAA,QAAA;AAGG,YAAA,EAAE,kBAAkB,uBAAuB;AAC9C,gBAAM,IAAI,aAAa;AAAA,QAAA;AAExB,YAAI,UAAU,sBAAsB,OAAO,WAAW,OAAO;AAC5D;AAAA,QAAA;AAED,YAAI,CAAC,KAAK,cAAc,KAAK,GAAG;AACxB,iBAAA;AAAA,QAAA;AAAA,MACR,WACU,MAAM,SAAS,cAAc;AACvC,YAAI,MAAM,UAAU,OAAO,WAAW,cAAc;AACnD;AAAA,QAAA;AAED,mBAAW,aAAa,MAAM,SAAS,OAAA,GAAU;AAChD,cAAI,UAAU,SAAS,iBAAiB,CAAC,KAAK,cAAc,SAAS,GAAG;AAChE,mBAAA;AAAA,UAAA;AAAA,QACR;AAAA,MACD;AAAA,IACD;AAEM,WAAA;AAAA,EAAA;AAET;"}
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const bindingCommon = require("@contember/binding-common");
|
|
4
|
-
const RequestResponseNormalizer = require("./RequestResponseNormalizer.cjs");
|
|
5
|
-
const NormalizedPersistedData = require("../accessorTree/NormalizedPersistedData.cjs");
|
|
6
|
-
var __defProp = Object.defineProperty;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
9
|
-
const emptyEntityIdSet = /* @__PURE__ */ new Set();
|
|
10
|
-
class TreeStore {
|
|
11
|
-
constructor(_schema) {
|
|
12
|
-
this._schema = _schema;
|
|
13
|
-
__publicField(this, "entityStore", /* @__PURE__ */ new Map());
|
|
14
|
-
__publicField(this, "entityRealmStore", /* @__PURE__ */ new Map());
|
|
15
|
-
__publicField(this, "markerTrees", /* @__PURE__ */ new Map());
|
|
16
|
-
__publicField(this, "subTreeStatesByRoot", /* @__PURE__ */ new Map());
|
|
17
|
-
__publicField(this, "persistedData", new NormalizedPersistedData.NormalizedPersistedData(/* @__PURE__ */ new Map(), /* @__PURE__ */ new Map()));
|
|
18
|
-
}
|
|
19
|
-
mergeInQueryResponse(response, markerTree) {
|
|
20
|
-
RequestResponseNormalizer.RequestResponseNormalizer.mergeInQueryResponse(this.persistedData, response, markerTree);
|
|
21
|
-
}
|
|
22
|
-
mergeInMutationResponse(response, operations) {
|
|
23
|
-
RequestResponseNormalizer.RequestResponseNormalizer.mergeInMutationResponse(this.persistedData, response, operations);
|
|
24
|
-
}
|
|
25
|
-
get persistedEntityData() {
|
|
26
|
-
return this.persistedData.persistedEntityDataStore;
|
|
27
|
-
}
|
|
28
|
-
get subTreePersistedData() {
|
|
29
|
-
return this.persistedData.subTreeDataStore;
|
|
30
|
-
}
|
|
31
|
-
get schema() {
|
|
32
|
-
return this._schema;
|
|
33
|
-
}
|
|
34
|
-
getPathBackToParent(entityRealm) {
|
|
35
|
-
const blueprint = entityRealm.blueprint;
|
|
36
|
-
if (blueprint.parent === void 0) {
|
|
37
|
-
return void 0;
|
|
38
|
-
}
|
|
39
|
-
let parentEntityName;
|
|
40
|
-
let relationFromParent;
|
|
41
|
-
let parent;
|
|
42
|
-
if (blueprint.type === "hasOne") {
|
|
43
|
-
parentEntityName = blueprint.parent.entity.entityName;
|
|
44
|
-
relationFromParent = blueprint.marker.parameters.field;
|
|
45
|
-
parent = blueprint.parent;
|
|
46
|
-
} else if (blueprint.type === "listEntity") {
|
|
47
|
-
const grandparentBlueprint = blueprint.parent.blueprint;
|
|
48
|
-
if (grandparentBlueprint.parent === void 0) {
|
|
49
|
-
return void 0;
|
|
50
|
-
}
|
|
51
|
-
parentEntityName = grandparentBlueprint.parent.entity.entityName;
|
|
52
|
-
relationFromParent = grandparentBlueprint.marker.parameters.field;
|
|
53
|
-
parent = grandparentBlueprint.parent;
|
|
54
|
-
} else {
|
|
55
|
-
return bindingCommon.assertNever(blueprint);
|
|
56
|
-
}
|
|
57
|
-
const relationSchema = this.schema.getEntityRelation(parentEntityName, relationFromParent);
|
|
58
|
-
const fieldBack = (relationSchema.ownedBy || relationSchema.inversedBy) ?? null;
|
|
59
|
-
if (fieldBack === null) {
|
|
60
|
-
return void 0;
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
parent,
|
|
64
|
-
fieldBackToParent: fieldBack
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
getSubTreeState(mode, treeRootId, aliasOrParameters, environment) {
|
|
68
|
-
const markerRoot = this.markerTrees.get(treeRootId);
|
|
69
|
-
const subTreeStates = this.subTreeStatesByRoot.get(treeRootId);
|
|
70
|
-
if (subTreeStates === void 0 || markerRoot === void 0) {
|
|
71
|
-
if (treeRootId) {
|
|
72
|
-
throw new bindingCommon.BindingError(
|
|
73
|
-
`Invalid tree id '${treeRootId}'. Make sure you use the one supplied by the correct extendTree call.`
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
throw new bindingCommon.BindingError(`Failed to retrieve a sub tree.`);
|
|
77
|
-
}
|
|
78
|
-
let placeholderName;
|
|
79
|
-
if (typeof aliasOrParameters === "string") {
|
|
80
|
-
const placeholderByAlias = markerRoot.placeholdersByAliases.get(aliasOrParameters);
|
|
81
|
-
if (placeholderByAlias === void 0) {
|
|
82
|
-
throw new bindingCommon.BindingError(`Undefined sub-tree alias '${aliasOrParameters}'.`);
|
|
83
|
-
}
|
|
84
|
-
placeholderName = placeholderByAlias;
|
|
85
|
-
} else if (mode === "entityList") {
|
|
86
|
-
placeholderName = bindingCommon.PlaceholderGenerator.getEntityListSubTreePlaceholder(
|
|
87
|
-
aliasOrParameters.isCreating ? bindingCommon.QueryLanguage.desugarUnconstrainedQualifiedEntityList(
|
|
88
|
-
aliasOrParameters,
|
|
89
|
-
environment
|
|
90
|
-
) : bindingCommon.QueryLanguage.desugarQualifiedEntityList(aliasOrParameters, environment),
|
|
91
|
-
environment
|
|
92
|
-
);
|
|
93
|
-
} else if (mode === "entity") {
|
|
94
|
-
placeholderName = bindingCommon.PlaceholderGenerator.getEntitySubTreePlaceholder(
|
|
95
|
-
aliasOrParameters.isCreating ? bindingCommon.QueryLanguage.desugarUnconstrainedQualifiedSingleEntity(
|
|
96
|
-
aliasOrParameters,
|
|
97
|
-
environment
|
|
98
|
-
) : bindingCommon.QueryLanguage.desugarQualifiedSingleEntity(aliasOrParameters, environment),
|
|
99
|
-
environment
|
|
100
|
-
);
|
|
101
|
-
} else {
|
|
102
|
-
throw new bindingCommon.BindingError();
|
|
103
|
-
}
|
|
104
|
-
const subTreeState = subTreeStates.get(placeholderName);
|
|
105
|
-
if (subTreeState === void 0) {
|
|
106
|
-
throw new bindingCommon.BindingError(`Trying to retrieve a non-existent sub-tree '${placeholderName}'.`);
|
|
107
|
-
}
|
|
108
|
-
return subTreeState;
|
|
109
|
-
}
|
|
110
|
-
getEntityListPersistedIds(state) {
|
|
111
|
-
const blueprint = state.blueprint;
|
|
112
|
-
if (blueprint.parent) {
|
|
113
|
-
const entityData = this.persistedEntityData.get(blueprint.parent.entity.id.uniqueValue);
|
|
114
|
-
return entityData?.get(blueprint.marker.placeholderName)?.value ?? emptyEntityIdSet;
|
|
115
|
-
} else {
|
|
116
|
-
return this.subTreePersistedData.get(blueprint.marker.placeholderName) ?? emptyEntityIdSet;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
disposeOfRealm(realmToDisposeOf) {
|
|
120
|
-
this.entityRealmStore.delete(realmToDisposeOf.realmKey);
|
|
121
|
-
realmToDisposeOf.entity.realms.delete(realmToDisposeOf.realmKey);
|
|
122
|
-
if (realmToDisposeOf.type === "entityRealm") {
|
|
123
|
-
realmToDisposeOf.blueprint.parent?.childrenWithPendingUpdates?.delete(realmToDisposeOf);
|
|
124
|
-
for (const child of realmToDisposeOf.children.values()) {
|
|
125
|
-
switch (child.type) {
|
|
126
|
-
case "field":
|
|
127
|
-
continue;
|
|
128
|
-
case "entityRealm":
|
|
129
|
-
case "entityRealmStub": {
|
|
130
|
-
this.disposeOfRealm(child);
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
case "entityList": {
|
|
134
|
-
for (const listChild of child.children.values()) {
|
|
135
|
-
this.disposeOfRealm(listChild);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
const entity = realmToDisposeOf.entity;
|
|
142
|
-
if (entity.realms.size === 0) {
|
|
143
|
-
this.disposeOfEntity(entity);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
disposeOfEntity(entity) {
|
|
147
|
-
for (const realm of entity.realms.values()) {
|
|
148
|
-
this.disposeOfRealm(realm);
|
|
149
|
-
}
|
|
150
|
-
this.entityStore.delete(entity.id.uniqueValue);
|
|
151
|
-
this.persistedEntityData.delete(entity.id.uniqueValue);
|
|
152
|
-
}
|
|
153
|
-
effectivelyHasTreeRoot(candidateRoot) {
|
|
154
|
-
candidateRoots: for (const candidateSubTree of candidateRoot.subTrees.values()) {
|
|
155
|
-
if (candidateSubTree.parameters.isCreating) {
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
for (const root of this.markerTrees.values()) {
|
|
159
|
-
for (const alreadyPresentSubTree of root.subTrees.values()) {
|
|
160
|
-
const isSubset = bindingCommon.MarkerComparator.isSubTreeSubsetOf(candidateSubTree, alreadyPresentSubTree);
|
|
161
|
-
if (isSubset) {
|
|
162
|
-
continue candidateRoots;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
return true;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
exports.TreeStore = TreeStore;
|
|
172
|
-
//# sourceMappingURL=TreeStore.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TreeStore.cjs","sources":["../../../../../packages/binding-legacy/src/core/TreeStore.ts"],"sourcesContent":["import { NormalizedPersistedData, PersistedEntityDataStore, SubTreeDataStore } from '../accessorTree'\nimport type {\n\tAlias,\n\tEntityId,\n\tEntityName,\n\tEntityRealmKey,\n\tEnvironment,\n\tFieldName,\n\tPlaceholderName,\n\tReceivedDataTree,\n\tSchema,\n\tSugaredQualifiedEntityList,\n\tSugaredQualifiedSingleEntity,\n\tSugaredUnconstrainedQualifiedEntityList,\n\tSugaredUnconstrainedQualifiedSingleEntity,\n\tTreeRootId,\n\tUniqueEntityId,\n} from '@contember/binding-common'\nimport { BindingError, MarkerComparator, MarkerTreeRoot, PlaceholderGenerator, QueryLanguage } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport { RequestResponseNormalizer } from './RequestResponseNormalizer'\nimport type { EntityListState, EntityRealmState, EntityRealmStateStub, EntityState, RootStateNode } from './state'\nimport { SubMutationOperation } from './MutationGenerator'\n\nconst emptyEntityIdSet: ReadonlySet<EntityId> = new Set()\n\nexport class TreeStore {\n\tpublic readonly entityStore: Map<UniqueEntityId, EntityState> = new Map()\n\tpublic readonly entityRealmStore: Map<EntityRealmKey, EntityRealmState | EntityRealmStateStub> = new Map()\n\n\t// This is tricky. We allow placeholder name duplicates, only the (TreeRootId, PlaceholderName) tuple is unique.\n\t// This is useful when the tree is extended to contain a sub-tree with the same placeholder.\n\tpublic readonly markerTrees: Map<TreeRootId | undefined, MarkerTreeRoot> = new Map()\n\tpublic readonly subTreeStatesByRoot: Map<TreeRootId | undefined, Map<PlaceholderName, RootStateNode>> = new Map()\n\n\tpublic readonly persistedData: NormalizedPersistedData = new NormalizedPersistedData(new Map(), new Map())\n\n\tpublic constructor(\n\t\tprivate readonly _schema: Schema,\n\t) {}\n\n\tpublic mergeInQueryResponse(response: ReceivedDataTree, markerTree: MarkerTreeRoot): void {\n\t\tRequestResponseNormalizer.mergeInQueryResponse(this.persistedData, response, markerTree)\n\t}\n\n\tpublic mergeInMutationResponse(response: ReceivedDataTree, operations: SubMutationOperation[]): void {\n\t\tRequestResponseNormalizer.mergeInMutationResponse(this.persistedData, response, operations)\n\t}\n\n\tpublic get persistedEntityData(): PersistedEntityDataStore {\n\t\treturn this.persistedData.persistedEntityDataStore\n\t}\n\n\tpublic get subTreePersistedData(): SubTreeDataStore {\n\t\treturn this.persistedData.subTreeDataStore\n\t}\n\n\tpublic get schema(): Schema {\n\t\treturn this._schema\n\t}\n\n\tpublic getPathBackToParent(entityRealm: EntityRealmState | EntityRealmStateStub):\n\t\t| {\n\t\t\tfieldBackToParent: FieldName\n\t\t\tparent: EntityRealmState\n\t\t }\n\t\t| undefined {\n\t\tconst blueprint = entityRealm.blueprint\n\t\tif (blueprint.parent === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tlet parentEntityName: EntityName\n\t\tlet relationFromParent: FieldName\n\t\tlet parent: EntityRealmState\n\n\t\tif (blueprint.type === 'hasOne') {\n\t\t\tparentEntityName = blueprint.parent.entity.entityName\n\t\t\trelationFromParent = blueprint.marker.parameters.field\n\t\t\tparent = blueprint.parent\n\t\t} else if (blueprint.type === 'listEntity') {\n\t\t\tconst grandparentBlueprint = blueprint.parent.blueprint\n\n\t\t\tif (grandparentBlueprint.parent === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\tparentEntityName = grandparentBlueprint.parent.entity.entityName\n\t\t\trelationFromParent = grandparentBlueprint.marker.parameters.field\n\t\t\tparent = grandparentBlueprint.parent\n\t\t} else {\n\t\t\treturn assertNever(blueprint)\n\t\t}\n\n\t\tconst relationSchema = this.schema.getEntityRelation(parentEntityName, relationFromParent)\n\t\tconst fieldBack = (relationSchema.ownedBy || relationSchema.inversedBy) ?? null\n\n\t\t// console.log(parentEntityName, relationFromParent, entityRealm.entity.entityName, fieldBack)\n\t\tif (fieldBack === null) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn {\n\t\t\tparent,\n\t\t\tfieldBackToParent: fieldBack,\n\t\t}\n\t}\n\n\tpublic getSubTreeState(\n\t\tmode: 'entity',\n\t\ttreeRootId: TreeRootId | undefined,\n\t\taliasOrParameters: Alias | SugaredQualifiedSingleEntity | SugaredUnconstrainedQualifiedSingleEntity,\n\t\tenvironment: Environment,\n\t): EntityRealmState\n\tpublic getSubTreeState(\n\t\tmode: 'entityList',\n\t\ttreeRootId: TreeRootId | undefined,\n\t\taliasOrParameters: Alias | SugaredQualifiedEntityList | SugaredUnconstrainedQualifiedEntityList,\n\t\tenvironment: Environment,\n\t): EntityListState\n\tpublic getSubTreeState(\n\t\tmode: 'entity' | 'entityList',\n\t\ttreeRootId: TreeRootId | undefined,\n\t\taliasOrParameters:\n\t\t\t| Alias\n\t\t\t| SugaredQualifiedSingleEntity\n\t\t\t| SugaredUnconstrainedQualifiedSingleEntity\n\t\t\t| SugaredQualifiedEntityList\n\t\t\t| SugaredUnconstrainedQualifiedEntityList,\n\t\tenvironment: Environment,\n\t): RootStateNode {\n\t\tconst markerRoot = this.markerTrees.get(treeRootId)\n\t\tconst subTreeStates = this.subTreeStatesByRoot.get(treeRootId)\n\n\t\tif (subTreeStates === undefined || markerRoot === undefined) {\n\t\t\tif (treeRootId) {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`Invalid tree id '${treeRootId}'. Make sure you use the one supplied by the correct extendTree call.`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tthrow new BindingError(`Failed to retrieve a sub tree.`)\n\t\t}\n\n\t\tlet placeholderName: string\n\n\t\tif (typeof aliasOrParameters === 'string') {\n\t\t\tconst placeholderByAlias = markerRoot.placeholdersByAliases.get(aliasOrParameters)\n\n\t\t\tif (placeholderByAlias === undefined) {\n\t\t\t\tthrow new BindingError(`Undefined sub-tree alias '${aliasOrParameters}'.`)\n\t\t\t}\n\t\t\tplaceholderName = placeholderByAlias\n\t\t} else if (mode === 'entityList') {\n\t\t\tplaceholderName = PlaceholderGenerator.getEntityListSubTreePlaceholder(\n\t\t\t\taliasOrParameters.isCreating\n\t\t\t\t\t? QueryLanguage.desugarUnconstrainedQualifiedEntityList(\n\t\t\t\t\t\taliasOrParameters as SugaredUnconstrainedQualifiedEntityList,\n\t\t\t\t\t\tenvironment,\n\t\t\t\t\t )\n\t\t\t\t\t: QueryLanguage.desugarQualifiedEntityList(aliasOrParameters as SugaredQualifiedEntityList, environment),\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else if (mode === 'entity') {\n\t\t\tplaceholderName = PlaceholderGenerator.getEntitySubTreePlaceholder(\n\t\t\t\taliasOrParameters.isCreating\n\t\t\t\t\t? QueryLanguage.desugarUnconstrainedQualifiedSingleEntity(\n\t\t\t\t\t\taliasOrParameters as SugaredUnconstrainedQualifiedSingleEntity,\n\t\t\t\t\t\tenvironment,\n\t\t\t\t\t )\n\t\t\t\t\t: QueryLanguage.desugarQualifiedSingleEntity(aliasOrParameters as SugaredQualifiedSingleEntity, environment),\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else {\n\t\t\tthrow new BindingError()\n\t\t}\n\t\tconst subTreeState = subTreeStates.get(placeholderName)\n\n\t\tif (subTreeState === undefined) {\n\t\t\tthrow new BindingError(`Trying to retrieve a non-existent sub-tree '${placeholderName}'.`)\n\t\t}\n\t\treturn subTreeState\n\t}\n\n\tpublic getEntityListPersistedIds(state: EntityListState): ReadonlySet<EntityId> {\n\t\tconst blueprint = state.blueprint\n\n\t\tif (blueprint.parent) {\n\t\t\tconst entityData = this.persistedEntityData.get(blueprint.parent.entity.id.uniqueValue)\n\t\t\treturn (entityData?.get(blueprint.marker.placeholderName)?.value as Set<string> | undefined) ?? emptyEntityIdSet\n\t\t} else {\n\t\t\treturn (this.subTreePersistedData.get(blueprint.marker.placeholderName) as Set<string>) ?? emptyEntityIdSet\n\t\t}\n\t}\n\n\tpublic disposeOfRealm(realmToDisposeOf: EntityRealmState | EntityRealmStateStub) {\n\t\tthis.entityRealmStore.delete(realmToDisposeOf.realmKey)\n\t\trealmToDisposeOf.entity.realms.delete(realmToDisposeOf.realmKey)\n\n\t\tif (realmToDisposeOf.type === 'entityRealm') {\n\t\t\trealmToDisposeOf.blueprint.parent?.childrenWithPendingUpdates?.delete(realmToDisposeOf)\n\n\t\t\tfor (const child of realmToDisposeOf.children.values()) {\n\t\t\t\tswitch (child.type) {\n\t\t\t\t\tcase 'field':\n\t\t\t\t\t\tcontinue\n\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\t\tthis.disposeOfRealm(child)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'entityList': {\n\t\t\t\t\t\tfor (const listChild of child.children.values()) {\n\t\t\t\t\t\t\tthis.disposeOfRealm(listChild)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst entity = realmToDisposeOf.entity\n\t\tif (entity.realms.size === 0) {\n\t\t\tthis.disposeOfEntity(entity)\n\t\t}\n\t}\n\n\tpublic disposeOfEntity(entity: EntityState) {\n\t\tfor (const realm of entity.realms.values()) {\n\t\t\tthis.disposeOfRealm(realm)\n\t\t}\n\t\tthis.entityStore.delete(entity.id.uniqueValue)\n\t\tthis.persistedEntityData.delete(entity.id.uniqueValue)\n\t}\n\n\tpublic effectivelyHasTreeRoot(candidateRoot: MarkerTreeRoot): boolean {\n\t\tcandidateRoots: for (const candidateSubTree of candidateRoot.subTrees.values()) {\n\t\t\tif (candidateSubTree.parameters.isCreating) {\n\t\t\t\t// This, by definition, won't trigger a query.\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tfor (const root of this.markerTrees.values()) {\n\t\t\t\tfor (const alreadyPresentSubTree of root.subTrees.values()) {\n\t\t\t\t\tconst isSubset = MarkerComparator.isSubTreeSubsetOf(candidateSubTree, alreadyPresentSubTree)\n\t\t\t\t\tif (isSubset) {\n\t\t\t\t\t\tcontinue candidateRoots\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false\n\t\t}\n\t\treturn true\n\t}\n}\n"],"names":["NormalizedPersistedData","RequestResponseNormalizer","assertNever","BindingError","PlaceholderGenerator","QueryLanguage","MarkerComparator"],"mappings":";;;;;;;;AAwBA,MAAM,uCAA8C,IAAI;AAEjD,MAAM,UAAU;AAAA,EAWf,YACW,SAChB;AADgB,SAAA,UAAA;AAXF,kBAAA,MAAA,mCAAoD,IAAI,CAAA;AACxD,kBAAA,MAAA,wCAAqF,IAAI,CAAA;AAIzF,kBAAA,MAAA,mCAA+D,IAAI,CAAA;AACnE,kBAAA,MAAA,2CAA4F,IAAI,CAAA;AAEhG,kBAAA,MAAA,iBAAyC,IAAIA,wBAAAA,wBAAwB,oBAAI,IAAO,GAAA,oBAAI,KAAK,CAAA;AAAA,EAAA;AAAA,EAMlG,qBAAqB,UAA4B,YAAkC;AACzFC,8BAAAA,0BAA0B,qBAAqB,KAAK,eAAe,UAAU,UAAU;AAAA,EAAA;AAAA,EAGjF,wBAAwB,UAA4B,YAA0C;AACpGA,8BAAAA,0BAA0B,wBAAwB,KAAK,eAAe,UAAU,UAAU;AAAA,EAAA;AAAA,EAG3F,IAAW,sBAAgD;AAC1D,WAAO,KAAK,cAAc;AAAA,EA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