@contember/binding-legacy 2.0.0-alpha.17
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/api-extractor.json +3 -0
- package/dist/development/index.cjs +34 -0
- package/dist/development/index.cjs.map +1 -0
- package/dist/development/index.js +28 -0
- package/dist/development/index.js.map +1 -0
- package/dist/development/src/accessorTree/NormalizedPersistedData.cjs +10 -0
- package/dist/development/src/accessorTree/NormalizedPersistedData.cjs.map +1 -0
- package/dist/development/src/accessorTree/NormalizedPersistedData.js +10 -0
- package/dist/development/src/accessorTree/NormalizedPersistedData.js.map +1 -0
- package/dist/development/src/accessors/EntityAccessorImpl.cjs +172 -0
- package/dist/development/src/accessors/EntityAccessorImpl.cjs.map +1 -0
- package/dist/development/src/accessors/EntityAccessorImpl.js +172 -0
- package/dist/development/src/accessors/EntityAccessorImpl.js.map +1 -0
- package/dist/development/src/accessors/EntityListAccessorImpl.cjs +112 -0
- package/dist/development/src/accessors/EntityListAccessorImpl.cjs.map +1 -0
- package/dist/development/src/accessors/EntityListAccessorImpl.js +112 -0
- package/dist/development/src/accessors/EntityListAccessorImpl.js.map +1 -0
- package/dist/development/src/accessors/FieldAccessorImpl.cjs +54 -0
- package/dist/development/src/accessors/FieldAccessorImpl.cjs.map +1 -0
- package/dist/development/src/accessors/FieldAccessorImpl.js +54 -0
- package/dist/development/src/accessors/FieldAccessorImpl.js.map +1 -0
- package/dist/development/src/core/AccessorErrorManager.cjs +203 -0
- package/dist/development/src/core/AccessorErrorManager.cjs.map +1 -0
- package/dist/development/src/core/AccessorErrorManager.js +203 -0
- package/dist/development/src/core/AccessorErrorManager.js.map +1 -0
- package/dist/development/src/core/Config.cjs +29 -0
- package/dist/development/src/core/Config.cjs.map +1 -0
- package/dist/development/src/core/Config.js +29 -0
- package/dist/development/src/core/Config.js.map +1 -0
- package/dist/development/src/core/DataBinding.cjs +355 -0
- package/dist/development/src/core/DataBinding.cjs.map +1 -0
- package/dist/development/src/core/DataBinding.js +355 -0
- package/dist/development/src/core/DataBinding.js.map +1 -0
- package/dist/development/src/core/DirtinessTracker.cjs +26 -0
- package/dist/development/src/core/DirtinessTracker.cjs.map +1 -0
- package/dist/development/src/core/DirtinessTracker.js +26 -0
- package/dist/development/src/core/DirtinessTracker.js.map +1 -0
- package/dist/development/src/core/ErrorsPreprocessor.cjs +180 -0
- package/dist/development/src/core/ErrorsPreprocessor.cjs.map +1 -0
- package/dist/development/src/core/ErrorsPreprocessor.js +180 -0
- package/dist/development/src/core/ErrorsPreprocessor.js.map +1 -0
- package/dist/development/src/core/EventManager.cjs +433 -0
- package/dist/development/src/core/EventManager.cjs.map +1 -0
- package/dist/development/src/core/EventManager.js +433 -0
- package/dist/development/src/core/EventManager.js.map +1 -0
- package/dist/development/src/core/MutationGenerator.cjs +660 -0
- package/dist/development/src/core/MutationGenerator.cjs.map +1 -0
- package/dist/development/src/core/MutationGenerator.js +660 -0
- package/dist/development/src/core/MutationGenerator.js.map +1 -0
- package/dist/development/src/core/QueryGenerator.cjs +107 -0
- package/dist/development/src/core/QueryGenerator.cjs.map +1 -0
- package/dist/development/src/core/QueryGenerator.js +107 -0
- package/dist/development/src/core/QueryGenerator.js.map +1 -0
- package/dist/development/src/core/RealmKeyGenerator.cjs +42 -0
- package/dist/development/src/core/RealmKeyGenerator.cjs.map +1 -0
- package/dist/development/src/core/RealmKeyGenerator.js +42 -0
- package/dist/development/src/core/RealmKeyGenerator.js.map +1 -0
- package/dist/development/src/core/RequestResponseNormalizer.cjs +120 -0
- package/dist/development/src/core/RequestResponseNormalizer.cjs.map +1 -0
- package/dist/development/src/core/RequestResponseNormalizer.js +120 -0
- package/dist/development/src/core/RequestResponseNormalizer.js.map +1 -0
- package/dist/development/src/core/StateInitializer.cjs +379 -0
- package/dist/development/src/core/StateInitializer.cjs.map +1 -0
- package/dist/development/src/core/StateInitializer.js +379 -0
- package/dist/development/src/core/StateInitializer.js.map +1 -0
- package/dist/development/src/core/TreeAugmenter.cjs +214 -0
- package/dist/development/src/core/TreeAugmenter.cjs.map +1 -0
- package/dist/development/src/core/TreeAugmenter.js +214 -0
- package/dist/development/src/core/TreeAugmenter.js.map +1 -0
- package/dist/development/src/core/TreeFilterGenerator.cjs +79 -0
- package/dist/development/src/core/TreeFilterGenerator.cjs.map +1 -0
- package/dist/development/src/core/TreeFilterGenerator.js +79 -0
- package/dist/development/src/core/TreeFilterGenerator.js.map +1 -0
- package/dist/development/src/core/TreeStore.cjs +172 -0
- package/dist/development/src/core/TreeStore.cjs.map +1 -0
- package/dist/development/src/core/TreeStore.js +172 -0
- package/dist/development/src/core/TreeStore.js.map +1 -0
- package/dist/development/src/core/exceptions/ErrorLocator.cjs +59 -0
- package/dist/development/src/core/exceptions/ErrorLocator.cjs.map +1 -0
- package/dist/development/src/core/exceptions/ErrorLocator.js +59 -0
- package/dist/development/src/core/exceptions/ErrorLocator.js.map +1 -0
- package/dist/development/src/core/exceptions/MarkerSugarer.cjs +51 -0
- package/dist/development/src/core/exceptions/MarkerSugarer.cjs.map +1 -0
- package/dist/development/src/core/exceptions/MarkerSugarer.js +51 -0
- package/dist/development/src/core/exceptions/MarkerSugarer.js.map +1 -0
- package/dist/development/src/core/exceptions/TreeParameterSugarer.cjs +33 -0
- package/dist/development/src/core/exceptions/TreeParameterSugarer.cjs.map +1 -0
- package/dist/development/src/core/exceptions/TreeParameterSugarer.js +33 -0
- package/dist/development/src/core/exceptions/TreeParameterSugarer.js.map +1 -0
- package/dist/development/src/core/factories/createBatchUpdatesOptions.cjs +23 -0
- package/dist/development/src/core/factories/createBatchUpdatesOptions.cjs.map +1 -0
- package/dist/development/src/core/factories/createBatchUpdatesOptions.js +23 -0
- package/dist/development/src/core/factories/createBatchUpdatesOptions.js.map +1 -0
- package/dist/development/src/core/operations/EntityOperations.cjs +226 -0
- package/dist/development/src/core/operations/EntityOperations.cjs.map +1 -0
- package/dist/development/src/core/operations/EntityOperations.js +226 -0
- package/dist/development/src/core/operations/EntityOperations.js.map +1 -0
- package/dist/development/src/core/operations/FieldOperations.cjs +92 -0
- package/dist/development/src/core/operations/FieldOperations.cjs.map +1 -0
- package/dist/development/src/core/operations/FieldOperations.js +92 -0
- package/dist/development/src/core/operations/FieldOperations.js.map +1 -0
- package/dist/development/src/core/operations/ListOperations.cjs +155 -0
- package/dist/development/src/core/operations/ListOperations.cjs.map +1 -0
- package/dist/development/src/core/operations/ListOperations.js +155 -0
- package/dist/development/src/core/operations/ListOperations.js.map +1 -0
- package/dist/development/src/core/operations/OperationsHelpers.cjs +87 -0
- package/dist/development/src/core/operations/OperationsHelpers.cjs.map +1 -0
- package/dist/development/src/core/operations/OperationsHelpers.js +87 -0
- package/dist/development/src/core/operations/OperationsHelpers.js.map +1 -0
- package/dist/development/src/core/requestAliases/MutationAlias.cjs +14 -0
- package/dist/development/src/core/requestAliases/MutationAlias.cjs.map +1 -0
- package/dist/development/src/core/requestAliases/MutationAlias.js +14 -0
- package/dist/development/src/core/requestAliases/MutationAlias.js.map +1 -0
- package/dist/development/src/core/state/StateIterator.cjs +100 -0
- package/dist/development/src/core/state/StateIterator.cjs.map +1 -0
- package/dist/development/src/core/state/StateIterator.js +100 -0
- package/dist/development/src/core/state/StateIterator.js.map +1 -0
- package/dist/development/src/core/state/getEntityMarker.cjs +5 -0
- package/dist/development/src/core/state/getEntityMarker.cjs.map +1 -0
- package/dist/development/src/core/state/getEntityMarker.js +5 -0
- package/dist/development/src/core/state/getEntityMarker.js.map +1 -0
- package/dist/development/src/core/utils/getCombinedSignal.cjs +33 -0
- package/dist/development/src/core/utils/getCombinedSignal.cjs.map +1 -0
- package/dist/development/src/core/utils/getCombinedSignal.js +33 -0
- package/dist/development/src/core/utils/getCombinedSignal.js.map +1 -0
- package/dist/development/src/fieldHelpers/helpers/FieldHelper.cjs +13 -0
- package/dist/development/src/fieldHelpers/helpers/FieldHelper.cjs.map +1 -0
- package/dist/development/src/fieldHelpers/helpers/FieldHelper.js +13 -0
- package/dist/development/src/fieldHelpers/helpers/FieldHelper.js.map +1 -0
- package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.cjs +18 -0
- package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.cjs.map +1 -0
- package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.js +18 -0
- package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -0
- package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.cjs +16 -0
- package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.cjs.map +1 -0
- package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.js +16 -0
- package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.js.map +1 -0
- package/dist/development/src/utils/generateEnumerabilityPreventingEntropy.cjs +7 -0
- package/dist/development/src/utils/generateEnumerabilityPreventingEntropy.cjs.map +1 -0
- package/dist/development/src/utils/generateEnumerabilityPreventingEntropy.js +7 -0
- package/dist/development/src/utils/generateEnumerabilityPreventingEntropy.js.map +1 -0
- package/dist/development/src/utils/isEmptyObject.cjs +12 -0
- package/dist/development/src/utils/isEmptyObject.cjs.map +1 -0
- package/dist/development/src/utils/isEmptyObject.js +12 -0
- package/dist/development/src/utils/isEmptyObject.js.map +1 -0
- package/dist/production/index.cjs +34 -0
- package/dist/production/index.cjs.map +1 -0
- package/dist/production/index.js +28 -0
- package/dist/production/index.js.map +1 -0
- package/dist/production/src/accessorTree/NormalizedPersistedData.cjs +10 -0
- package/dist/production/src/accessorTree/NormalizedPersistedData.cjs.map +1 -0
- package/dist/production/src/accessorTree/NormalizedPersistedData.js +10 -0
- package/dist/production/src/accessorTree/NormalizedPersistedData.js.map +1 -0
- package/dist/production/src/accessors/EntityAccessorImpl.cjs +172 -0
- package/dist/production/src/accessors/EntityAccessorImpl.cjs.map +1 -0
- package/dist/production/src/accessors/EntityAccessorImpl.js +172 -0
- package/dist/production/src/accessors/EntityAccessorImpl.js.map +1 -0
- package/dist/production/src/accessors/EntityListAccessorImpl.cjs +112 -0
- package/dist/production/src/accessors/EntityListAccessorImpl.cjs.map +1 -0
- package/dist/production/src/accessors/EntityListAccessorImpl.js +112 -0
- package/dist/production/src/accessors/EntityListAccessorImpl.js.map +1 -0
- package/dist/production/src/accessors/FieldAccessorImpl.cjs +54 -0
- package/dist/production/src/accessors/FieldAccessorImpl.cjs.map +1 -0
- package/dist/production/src/accessors/FieldAccessorImpl.js +54 -0
- package/dist/production/src/accessors/FieldAccessorImpl.js.map +1 -0
- package/dist/production/src/core/AccessorErrorManager.cjs +203 -0
- package/dist/production/src/core/AccessorErrorManager.cjs.map +1 -0
- package/dist/production/src/core/AccessorErrorManager.js +203 -0
- package/dist/production/src/core/AccessorErrorManager.js.map +1 -0
- package/dist/production/src/core/Config.cjs +29 -0
- package/dist/production/src/core/Config.cjs.map +1 -0
- package/dist/production/src/core/Config.js +29 -0
- package/dist/production/src/core/Config.js.map +1 -0
- package/dist/production/src/core/DataBinding.cjs +355 -0
- package/dist/production/src/core/DataBinding.cjs.map +1 -0
- package/dist/production/src/core/DataBinding.js +355 -0
- package/dist/production/src/core/DataBinding.js.map +1 -0
- package/dist/production/src/core/DirtinessTracker.cjs +26 -0
- package/dist/production/src/core/DirtinessTracker.cjs.map +1 -0
- package/dist/production/src/core/DirtinessTracker.js +26 -0
- package/dist/production/src/core/DirtinessTracker.js.map +1 -0
- package/dist/production/src/core/ErrorsPreprocessor.cjs +180 -0
- package/dist/production/src/core/ErrorsPreprocessor.cjs.map +1 -0
- package/dist/production/src/core/ErrorsPreprocessor.js +180 -0
- package/dist/production/src/core/ErrorsPreprocessor.js.map +1 -0
- package/dist/production/src/core/EventManager.cjs +407 -0
- package/dist/production/src/core/EventManager.cjs.map +1 -0
- package/dist/production/src/core/EventManager.js +407 -0
- package/dist/production/src/core/EventManager.js.map +1 -0
- package/dist/production/src/core/MutationGenerator.cjs +660 -0
- package/dist/production/src/core/MutationGenerator.cjs.map +1 -0
- package/dist/production/src/core/MutationGenerator.js +660 -0
- package/dist/production/src/core/MutationGenerator.js.map +1 -0
- package/dist/production/src/core/QueryGenerator.cjs +107 -0
- package/dist/production/src/core/QueryGenerator.cjs.map +1 -0
- package/dist/production/src/core/QueryGenerator.js +107 -0
- package/dist/production/src/core/QueryGenerator.js.map +1 -0
- package/dist/production/src/core/RealmKeyGenerator.cjs +42 -0
- package/dist/production/src/core/RealmKeyGenerator.cjs.map +1 -0
- package/dist/production/src/core/RealmKeyGenerator.js +42 -0
- package/dist/production/src/core/RealmKeyGenerator.js.map +1 -0
- package/dist/production/src/core/RequestResponseNormalizer.cjs +120 -0
- package/dist/production/src/core/RequestResponseNormalizer.cjs.map +1 -0
- package/dist/production/src/core/RequestResponseNormalizer.js +120 -0
- package/dist/production/src/core/RequestResponseNormalizer.js.map +1 -0
- package/dist/production/src/core/StateInitializer.cjs +379 -0
- package/dist/production/src/core/StateInitializer.cjs.map +1 -0
- package/dist/production/src/core/StateInitializer.js +379 -0
- package/dist/production/src/core/StateInitializer.js.map +1 -0
- package/dist/production/src/core/TreeAugmenter.cjs +214 -0
- package/dist/production/src/core/TreeAugmenter.cjs.map +1 -0
- package/dist/production/src/core/TreeAugmenter.js +214 -0
- package/dist/production/src/core/TreeAugmenter.js.map +1 -0
- package/dist/production/src/core/TreeFilterGenerator.cjs +79 -0
- package/dist/production/src/core/TreeFilterGenerator.cjs.map +1 -0
- package/dist/production/src/core/TreeFilterGenerator.js +79 -0
- package/dist/production/src/core/TreeFilterGenerator.js.map +1 -0
- package/dist/production/src/core/TreeStore.cjs +172 -0
- package/dist/production/src/core/TreeStore.cjs.map +1 -0
- package/dist/production/src/core/TreeStore.js +172 -0
- package/dist/production/src/core/TreeStore.js.map +1 -0
- package/dist/production/src/core/exceptions/ErrorLocator.cjs +59 -0
- package/dist/production/src/core/exceptions/ErrorLocator.cjs.map +1 -0
- package/dist/production/src/core/exceptions/ErrorLocator.js +59 -0
- package/dist/production/src/core/exceptions/ErrorLocator.js.map +1 -0
- package/dist/production/src/core/exceptions/MarkerSugarer.cjs +51 -0
- package/dist/production/src/core/exceptions/MarkerSugarer.cjs.map +1 -0
- package/dist/production/src/core/exceptions/MarkerSugarer.js +51 -0
- package/dist/production/src/core/exceptions/MarkerSugarer.js.map +1 -0
- package/dist/production/src/core/exceptions/TreeParameterSugarer.cjs +33 -0
- package/dist/production/src/core/exceptions/TreeParameterSugarer.cjs.map +1 -0
- package/dist/production/src/core/exceptions/TreeParameterSugarer.js +33 -0
- package/dist/production/src/core/exceptions/TreeParameterSugarer.js.map +1 -0
- package/dist/production/src/core/factories/createBatchUpdatesOptions.cjs +23 -0
- package/dist/production/src/core/factories/createBatchUpdatesOptions.cjs.map +1 -0
- package/dist/production/src/core/factories/createBatchUpdatesOptions.js +23 -0
- package/dist/production/src/core/factories/createBatchUpdatesOptions.js.map +1 -0
- package/dist/production/src/core/operations/EntityOperations.cjs +226 -0
- package/dist/production/src/core/operations/EntityOperations.cjs.map +1 -0
- package/dist/production/src/core/operations/EntityOperations.js +226 -0
- package/dist/production/src/core/operations/EntityOperations.js.map +1 -0
- package/dist/production/src/core/operations/FieldOperations.cjs +73 -0
- package/dist/production/src/core/operations/FieldOperations.cjs.map +1 -0
- package/dist/production/src/core/operations/FieldOperations.js +73 -0
- package/dist/production/src/core/operations/FieldOperations.js.map +1 -0
- package/dist/production/src/core/operations/ListOperations.cjs +155 -0
- package/dist/production/src/core/operations/ListOperations.cjs.map +1 -0
- package/dist/production/src/core/operations/ListOperations.js +155 -0
- package/dist/production/src/core/operations/ListOperations.js.map +1 -0
- package/dist/production/src/core/operations/OperationsHelpers.cjs +87 -0
- package/dist/production/src/core/operations/OperationsHelpers.cjs.map +1 -0
- package/dist/production/src/core/operations/OperationsHelpers.js +87 -0
- package/dist/production/src/core/operations/OperationsHelpers.js.map +1 -0
- package/dist/production/src/core/requestAliases/MutationAlias.cjs +14 -0
- package/dist/production/src/core/requestAliases/MutationAlias.cjs.map +1 -0
- package/dist/production/src/core/requestAliases/MutationAlias.js +14 -0
- package/dist/production/src/core/requestAliases/MutationAlias.js.map +1 -0
- package/dist/production/src/core/state/StateIterator.cjs +100 -0
- package/dist/production/src/core/state/StateIterator.cjs.map +1 -0
- package/dist/production/src/core/state/StateIterator.js +100 -0
- package/dist/production/src/core/state/StateIterator.js.map +1 -0
- package/dist/production/src/core/state/getEntityMarker.cjs +5 -0
- package/dist/production/src/core/state/getEntityMarker.cjs.map +1 -0
- package/dist/production/src/core/state/getEntityMarker.js +5 -0
- package/dist/production/src/core/state/getEntityMarker.js.map +1 -0
- package/dist/production/src/core/utils/getCombinedSignal.cjs +33 -0
- package/dist/production/src/core/utils/getCombinedSignal.cjs.map +1 -0
- package/dist/production/src/core/utils/getCombinedSignal.js +33 -0
- package/dist/production/src/core/utils/getCombinedSignal.js.map +1 -0
- package/dist/production/src/fieldHelpers/helpers/FieldHelper.cjs +13 -0
- package/dist/production/src/fieldHelpers/helpers/FieldHelper.cjs.map +1 -0
- package/dist/production/src/fieldHelpers/helpers/FieldHelper.js +13 -0
- package/dist/production/src/fieldHelpers/helpers/FieldHelper.js.map +1 -0
- package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.cjs +18 -0
- package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.cjs.map +1 -0
- package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.js +18 -0
- package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -0
- package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.cjs +16 -0
- package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.cjs.map +1 -0
- package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.js +16 -0
- package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.js.map +1 -0
- package/dist/production/src/utils/generateEnumerabilityPreventingEntropy.cjs +7 -0
- package/dist/production/src/utils/generateEnumerabilityPreventingEntropy.cjs.map +1 -0
- package/dist/production/src/utils/generateEnumerabilityPreventingEntropy.js +7 -0
- package/dist/production/src/utils/generateEnumerabilityPreventingEntropy.js.map +1 -0
- package/dist/production/src/utils/isEmptyObject.cjs +12 -0
- package/dist/production/src/utils/isEmptyObject.cjs.map +1 -0
- package/dist/production/src/utils/isEmptyObject.js +12 -0
- package/dist/production/src/utils/isEmptyObject.js.map +1 -0
- package/dist/types/accessorTree/NormalizedPersistedData.d.ts +13 -0
- package/dist/types/accessorTree/NormalizedPersistedData.d.ts.map +1 -0
- package/dist/types/accessorTree/index.d.ts +2 -0
- package/dist/types/accessorTree/index.d.ts.map +1 -0
- package/dist/types/accessors/BindingConfig.d.ts +6 -0
- package/dist/types/accessors/BindingConfig.d.ts.map +1 -0
- package/dist/types/accessors/EntityAccessorImpl.d.ts +52 -0
- package/dist/types/accessors/EntityAccessorImpl.d.ts.map +1 -0
- package/dist/types/accessors/EntityListAccessorImpl.d.ts +57 -0
- package/dist/types/accessors/EntityListAccessorImpl.d.ts.map +1 -0
- package/dist/types/accessors/FieldAccessorImpl.d.ts +32 -0
- package/dist/types/accessors/FieldAccessorImpl.d.ts.map +1 -0
- package/dist/types/accessors/index.d.ts +5 -0
- package/dist/types/accessors/index.d.ts.map +1 -0
- package/dist/types/core/AccessorErrorManager.d.ts +25 -0
- package/dist/types/core/AccessorErrorManager.d.ts.map +1 -0
- package/dist/types/core/Config.d.ts +9 -0
- package/dist/types/core/Config.d.ts.map +1 -0
- package/dist/types/core/DataBinding.d.ts +52 -0
- package/dist/types/core/DataBinding.d.ts.map +1 -0
- package/dist/types/core/DirtinessTracker.d.ts +9 -0
- package/dist/types/core/DirtinessTracker.d.ts.map +1 -0
- package/dist/types/core/ErrorsPreprocessor.d.ts +34 -0
- package/dist/types/core/ErrorsPreprocessor.d.ts.map +1 -0
- package/dist/types/core/EventManager.d.ts +57 -0
- package/dist/types/core/EventManager.d.ts.map +1 -0
- package/dist/types/core/MutationGenerator.d.ts +46 -0
- package/dist/types/core/MutationGenerator.d.ts.map +1 -0
- package/dist/types/core/QueryGenerator.d.ts +12 -0
- package/dist/types/core/QueryGenerator.d.ts.map +1 -0
- package/dist/types/core/RealmKeyGenerator.d.ts +10 -0
- package/dist/types/core/RealmKeyGenerator.d.ts.map +1 -0
- package/dist/types/core/RequestResponseNormalizer.d.ts +11 -0
- package/dist/types/core/RequestResponseNormalizer.d.ts.map +1 -0
- package/dist/types/core/StateInitializer.d.ts +34 -0
- package/dist/types/core/StateInitializer.d.ts.map +1 -0
- package/dist/types/core/TreeAugmenter.d.ts +22 -0
- package/dist/types/core/TreeAugmenter.d.ts.map +1 -0
- package/dist/types/core/TreeFilterGenerator.d.ts +13 -0
- package/dist/types/core/TreeFilterGenerator.d.ts.map +1 -0
- package/dist/types/core/TreeStore.d.ts +30 -0
- package/dist/types/core/TreeStore.d.ts.map +1 -0
- package/dist/types/core/UpdateMetadata.d.ts +4 -0
- package/dist/types/core/UpdateMetadata.d.ts.map +1 -0
- package/dist/types/core/exceptions/ErrorLocator.d.ts +8 -0
- package/dist/types/core/exceptions/ErrorLocator.d.ts.map +1 -0
- package/dist/types/core/exceptions/MarkerSugarer.d.ts +10 -0
- package/dist/types/core/exceptions/MarkerSugarer.d.ts.map +1 -0
- package/dist/types/core/exceptions/TreeParameterSugarer.d.ts +11 -0
- package/dist/types/core/exceptions/TreeParameterSugarer.d.ts.map +1 -0
- package/dist/types/core/factories/createBatchUpdatesOptions.d.ts +5 -0
- package/dist/types/core/factories/createBatchUpdatesOptions.d.ts.map +1 -0
- package/dist/types/core/factories/index.d.ts +2 -0
- package/dist/types/core/factories/index.d.ts.map +1 -0
- package/dist/types/core/index.d.ts +9 -0
- package/dist/types/core/index.d.ts.map +1 -0
- package/dist/types/core/operations/EntityOperations.d.ts +26 -0
- package/dist/types/core/operations/EntityOperations.d.ts.map +1 -0
- package/dist/types/core/operations/FieldOperations.d.ts +22 -0
- package/dist/types/core/operations/FieldOperations.d.ts.map +1 -0
- package/dist/types/core/operations/ListOperations.d.ts +32 -0
- package/dist/types/core/operations/ListOperations.d.ts.map +1 -0
- package/dist/types/core/operations/OperationsHelpers.d.ts +14 -0
- package/dist/types/core/operations/OperationsHelpers.d.ts.map +1 -0
- package/dist/types/core/operations/index.d.ts +4 -0
- package/dist/types/core/operations/index.d.ts.map +1 -0
- package/dist/types/core/requestAliases/MutationAlias.d.ts +6 -0
- package/dist/types/core/requestAliases/MutationAlias.d.ts.map +1 -0
- package/dist/types/core/requestAliases/index.d.ts +2 -0
- package/dist/types/core/requestAliases/index.d.ts.map +1 -0
- package/dist/types/core/state/EntityListState.d.ts +29 -0
- package/dist/types/core/state/EntityListState.d.ts.map +1 -0
- package/dist/types/core/state/EntityRealmState.d.ts +44 -0
- package/dist/types/core/state/EntityRealmState.d.ts.map +1 -0
- package/dist/types/core/state/EntityState.d.ts +11 -0
- package/dist/types/core/state/EntityState.d.ts.map +1 -0
- package/dist/types/core/state/FieldState.d.ts +19 -0
- package/dist/types/core/state/FieldState.d.ts.map +1 -0
- package/dist/types/core/state/StateIterator.d.ts +14 -0
- package/dist/types/core/state/StateIterator.d.ts.map +1 -0
- package/dist/types/core/state/StateNode.d.ts +8 -0
- package/dist/types/core/state/StateNode.d.ts.map +1 -0
- package/dist/types/core/state/getEntityMarker.d.ts +3 -0
- package/dist/types/core/state/getEntityMarker.d.ts.map +1 -0
- package/dist/types/core/state/index.d.ts +8 -0
- package/dist/types/core/state/index.d.ts.map +1 -0
- package/dist/types/core/utils/getCombinedSignal.d.ts +2 -0
- package/dist/types/core/utils/getCombinedSignal.d.ts.map +1 -0
- package/dist/types/core/utils/index.d.ts +2 -0
- package/dist/types/core/utils/index.d.ts.map +1 -0
- package/dist/types/fieldHelpers/helpers/FieldHelper.d.ts +7 -0
- package/dist/types/fieldHelpers/helpers/FieldHelper.d.ts.map +1 -0
- package/dist/types/fieldHelpers/helpers/TemporalFieldHelper.d.ts +10 -0
- package/dist/types/fieldHelpers/helpers/TemporalFieldHelper.d.ts.map +1 -0
- package/dist/types/fieldHelpers/helpers/UuidFieldHelper.d.ts +10 -0
- package/dist/types/fieldHelpers/helpers/UuidFieldHelper.d.ts.map +1 -0
- package/dist/types/fieldHelpers/helpers/index.d.ts +3 -0
- package/dist/types/fieldHelpers/helpers/index.d.ts.map +1 -0
- package/dist/types/fieldHelpers/index.d.ts +2 -0
- package/dist/types/fieldHelpers/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/dist/types/utils/assertNever.d.ts +2 -0
- package/dist/types/utils/assertNever.d.ts.map +1 -0
- package/dist/types/utils/generateEnumerabilityPreventingEntropy.d.ts +2 -0
- package/dist/types/utils/generateEnumerabilityPreventingEntropy.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +4 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/isEmptyObject.d.ts +2 -0
- package/dist/types/utils/isEmptyObject.d.ts.map +1 -0
- package/package.json +40 -0
- package/src/accessorTree/NormalizedPersistedData.ts +23 -0
- package/src/accessorTree/index.ts +1 -0
- package/src/accessors/BindingConfig.ts +5 -0
- package/src/accessors/EntityAccessorImpl.ts +247 -0
- package/src/accessors/EntityListAccessorImpl.ts +138 -0
- package/src/accessors/FieldAccessorImpl.ts +64 -0
- package/src/accessors/index.ts +4 -0
- package/src/core/AccessorErrorManager.ts +243 -0
- package/src/core/Config.ts +27 -0
- package/src/core/DataBinding.ts +442 -0
- package/src/core/DirtinessTracker.ts +21 -0
- package/src/core/ErrorsPreprocessor.ts +238 -0
- package/src/core/EventManager.ts +589 -0
- package/src/core/MutationGenerator.ts +828 -0
- package/src/core/QueryGenerator.ts +128 -0
- package/src/core/RealmKeyGenerator.ts +52 -0
- package/src/core/RequestResponseNormalizer.ts +165 -0
- package/src/core/StateInitializer.ts +559 -0
- package/src/core/TreeAugmenter.ts +270 -0
- package/src/core/TreeFilterGenerator.ts +117 -0
- package/src/core/TreeStore.ts +249 -0
- package/src/core/UpdateMetadata.ts +3 -0
- package/src/core/exceptions/ErrorLocator.ts +58 -0
- package/src/core/exceptions/MarkerSugarer.ts +61 -0
- package/src/core/exceptions/TreeParameterSugarer.ts +41 -0
- package/src/core/factories/createBatchUpdatesOptions.ts +41 -0
- package/src/core/factories/index.ts +1 -0
- package/src/core/index.ts +8 -0
- package/src/core/operations/EntityOperations.ts +311 -0
- package/src/core/operations/FieldOperations.ts +131 -0
- package/src/core/operations/ListOperations.ts +213 -0
- package/src/core/operations/OperationsHelpers.ts +153 -0
- package/src/core/operations/index.ts +3 -0
- package/src/core/requestAliases/MutationAlias.ts +13 -0
- package/src/core/requestAliases/index.ts +1 -0
- package/src/core/state/EntityListState.ts +39 -0
- package/src/core/state/EntityRealmState.ts +63 -0
- package/src/core/state/EntityState.ts +11 -0
- package/src/core/state/FieldState.ts +20 -0
- package/src/core/state/StateIterator.ts +121 -0
- package/src/core/state/StateNode.ts +8 -0
- package/src/core/state/getEntityMarker.ts +4 -0
- package/src/core/state/index.ts +7 -0
- package/src/core/utils/getCombinedSignal.ts +36 -0
- package/src/core/utils/index.ts +1 -0
- package/src/fieldHelpers/helpers/FieldHelper.ts +10 -0
- package/src/fieldHelpers/helpers/TemporalFieldHelper.ts +21 -0
- package/src/fieldHelpers/helpers/UuidFieldHelper.ts +18 -0
- package/src/fieldHelpers/helpers/index.ts +2 -0
- package/src/fieldHelpers/index.ts +1 -0
- package/src/index.ts +7 -0
- package/src/tsconfig.json +14 -0
- package/src/utils/assertNever.ts +10 -0
- package/src/utils/generateEnumerabilityPreventingEntropy.ts +3 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/isEmptyObject.ts +9 -0
- package/tests/example.test.ts +5 -0
- package/tests/tsconfig.json +10 -0
- package/tsconfig.json +8 -0
- package/tsdoc.json +6 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeAugmenter.cjs","sources":["../../../../../packages/binding-legacy/src/core/TreeAugmenter.ts"],"sourcesContent":["import {\n\tClientGeneratedUuid,\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 type { EntityListState, EntityRealmState, EntityRealmStateStub, 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)\n\n\t\t\tswitch (child.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (childData instanceof ServerId || childData instanceof Set) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (child.persistedValue !== childData) {\n\t\t\t\t\t\tconst shouldChangeBothValues = child.persistedValue === child.value\n\n\t\t\t\t\t\tchild.persistedValue = childData\n\t\t\t\t\t\tif (shouldChangeBothValues) {\n\t\t\t\t\t\t\tchild.value = childData ?? null\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.eventManager.registerJustUpdated(child, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\tif (!(childData instanceof ServerId) && childData !== undefined && childData !== null) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateRealmIdIfNecessary(child, childData)\n\t\t\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (childData !== undefined && !(childData instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateEntityListPersistedData(child, childData ?? new Set()) // TODO!!\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn assertNever(child)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateEntityListPersistedData(state: EntityListState, newPersistedIds: EntityListPersistedData) {\n\t\tconst persistedWithoutState: EntityId[] = []\n\n\t\t// TODO This isn't particularly efficient. We should probably use something like diff-sequence here.\n\n\t\tfor (const persistedId of newPersistedIds) {\n\t\t\tif (!state.children.has(persistedId)) {\n\t\t\t\tpersistedWithoutState.push(persistedId)\n\t\t\t}\n\t\t}\n\t\tfor (const [stateId, child] of state.children) {\n\t\t\tconst childRuntimeId = child.entity.id\n\t\t\tif (!newPersistedIds.has(stateId)) {\n\t\t\t\tif (\n\t\t\t\t\t// It's a uuid but it's not among the persisted so either it got deleted/disconnected or the client-side\n\t\t\t\t\t// id generation didn't quite pan out.\n\t\t\t\t\tchildRuntimeId instanceof ServerId ||\n\t\t\t\t\tchildRuntimeId instanceof ClientGeneratedUuid ||\n\t\t\t\t\t// No persisted entity id to allocate to this so that's a goodbye.\n\t\t\t\t\tpersistedWithoutState.length === 0\n\t\t\t\t) {\n\t\t\t\t\tstate.getAccessor().disconnectEntity(child.getAccessor())\n\t\t\t\t\tcontinue\n\t\t\t\t} else {\n\t\t\t\t\tconst drawnId = persistedWithoutState.shift()!\n\t\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\t\tthis.treeStore,\n\t\t\t\t\t\tthis.eventManager,\n\t\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\t\tchild,\n\t\t\t\t\t\tnew ServerId(drawnId, child.entity.entityName),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (childRuntimeId instanceof ClientGeneratedUuid) {\n\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\tthis.treeStore,\n\t\t\t\t\tthis.eventManager,\n\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\tchild,\n\t\t\t\t\tnew ServerId(childRuntimeId.value, child.entity.entityName),\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t}\n\t\t}\n\t\tfor (const unclaimedPersistedId of persistedWithoutState) {\n\t\t\tthis.stateInitializer.initializeEntityRealm(new ServerId(unclaimedPersistedId, state.entityName), state.entityName, {\n\t\t\t\ttype: 'listEntity',\n\t\t\t\tparent: state,\n\t\t\t})\n\t\t}\n\t\t// All that remains now is the order.\n\t\tstate.children.changeKeyOrder(newPersistedIds)\n\t}\n}\n"],"names":["ServerId","assertNever","BindingError","EventManager","OperationsHelpers","UnpersistedEntityDummyId","ClientGeneratedUuid"],"mappings":";;;;;AAmBO,MAAM,cAAc;AAAA,EACnB,YACW,cACA,kBACA,WACA,8BAAuC,OACvD;AAJgB,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AACA,SAAA,8BAAA;AAAA,EACf;AAAA,EAEI,oBAAoB,kBAAoC,YAA4B;AAErF,SAAA,UAAU,qBAAqB,kBAAkB,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;AACA,eAAW,wBAAwB,uBAAuB;AACpD,WAAA,iBAAiB,sBAAsB,IAAIA,cAAA,SAAS,sBAAsB,MAAM,UAAU,GAAG,MAAM,YAAY;AAAA,QACnH,MAAM;AAAA,QACN,QAAQ;AAAA,MAAA,CACR;AAAA,IACF;AAEM,UAAA,SAAS,eAAe,eAAe;AAAA,EAC9C;AACD;;"}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { ServerId, assertNever, BindingError, UnpersistedEntityDummyId, ClientGeneratedUuid } from "@contember/binding-common";
|
|
2
|
+
import { EventManager } from "./EventManager.js";
|
|
3
|
+
import { OperationsHelpers } from "./operations/OperationsHelpers.js";
|
|
4
|
+
class TreeAugmenter {
|
|
5
|
+
constructor(eventManager, stateInitializer, treeStore, skipStateUpdateAfterPersist = false) {
|
|
6
|
+
this.eventManager = eventManager;
|
|
7
|
+
this.stateInitializer = stateInitializer;
|
|
8
|
+
this.treeStore = treeStore;
|
|
9
|
+
this.skipStateUpdateAfterPersist = skipStateUpdateAfterPersist;
|
|
10
|
+
}
|
|
11
|
+
extendPersistedData(newPersistedData, markerTree) {
|
|
12
|
+
this.treeStore.mergeInQueryResponse(newPersistedData, markerTree);
|
|
13
|
+
}
|
|
14
|
+
extendTreeStates(newTreeId, newMarkerTree) {
|
|
15
|
+
const subTreeStates = /* @__PURE__ */ new Map();
|
|
16
|
+
this.treeStore.markerTrees.set(newTreeId, newMarkerTree);
|
|
17
|
+
this.treeStore.subTreeStatesByRoot.set(newTreeId, subTreeStates);
|
|
18
|
+
for (const [placeholderName, newSubTreeMarker] of newMarkerTree.subTrees) {
|
|
19
|
+
const newState = this.stateInitializer.initializeSubTree(newSubTreeMarker);
|
|
20
|
+
subTreeStates.set(placeholderName, newState);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
updatePersistedData(response, operations) {
|
|
24
|
+
this.treeStore.mergeInMutationResponse(response, operations);
|
|
25
|
+
if (this.skipStateUpdateAfterPersist) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
this.eventManager.syncTransaction(() => {
|
|
29
|
+
for (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {
|
|
30
|
+
for (const [rootPlaceholder, rootState] of rootStates) {
|
|
31
|
+
const rootData = this.treeStore.subTreePersistedData.get(rootPlaceholder);
|
|
32
|
+
if (rootState.type === "entityList") {
|
|
33
|
+
if (!(rootData instanceof Set)) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
this.updateEntityListPersistedData(rootState, rootData);
|
|
37
|
+
} else if (rootState.type === "entityRealm") {
|
|
38
|
+
if (rootData !== void 0 && !(rootData instanceof ServerId)) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
this.updateRealmIdIfNecessary(rootState, rootData);
|
|
42
|
+
this.updateEntityRealmPersistedData(rootState);
|
|
43
|
+
} else {
|
|
44
|
+
return assertNever(rootState);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
resetCreatingSubTrees() {
|
|
51
|
+
for (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {
|
|
52
|
+
for (const [rootPlaceholder, rootState] of rootStates) {
|
|
53
|
+
if (rootState.type === "entityList") {
|
|
54
|
+
if (rootState.blueprint.parent !== void 0) {
|
|
55
|
+
throw new BindingError("Entity list root should not have a parent.");
|
|
56
|
+
}
|
|
57
|
+
if (!rootState.blueprint.marker.parameters.isCreating) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
this.treeStore.subTreePersistedData.delete(rootPlaceholder);
|
|
61
|
+
const changesCount = rootState.unpersistedChangesCount;
|
|
62
|
+
for (const childState of rootState.children.values()) {
|
|
63
|
+
this.treeStore.disposeOfRealm(childState);
|
|
64
|
+
}
|
|
65
|
+
rootState.accessor = void 0;
|
|
66
|
+
rootState.children.clear();
|
|
67
|
+
rootState.childrenWithPendingUpdates?.clear();
|
|
68
|
+
rootState.errors = void 0;
|
|
69
|
+
rootState.plannedRemovals?.clear();
|
|
70
|
+
this.eventManager.registerJustUpdated(
|
|
71
|
+
rootState,
|
|
72
|
+
changesCount ? -1 * changesCount : EventManager.NO_CHANGES_DIFFERENCE
|
|
73
|
+
);
|
|
74
|
+
} else if (rootState.type === "entityRealm") {
|
|
75
|
+
if (rootState.blueprint.parent !== void 0) {
|
|
76
|
+
throw new BindingError("Entity realm root should not have a parent.");
|
|
77
|
+
}
|
|
78
|
+
if (!rootState.blueprint.marker.parameters.isCreating) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const presentListeners = rootState.eventListeners;
|
|
82
|
+
this.treeStore.disposeOfRealm(rootState);
|
|
83
|
+
this.treeStore.subTreePersistedData.delete(rootPlaceholder);
|
|
84
|
+
const newRootState = this.stateInitializer.initializeSubTree(rootState.blueprint.marker);
|
|
85
|
+
newRootState.eventListeners = presentListeners;
|
|
86
|
+
OperationsHelpers.purgeStaleListenersAfterIdChange(newRootState);
|
|
87
|
+
rootStates.set(rootPlaceholder, newRootState);
|
|
88
|
+
this.eventManager.registerJustUpdated(newRootState, EventManager.NO_CHANGES_DIFFERENCE);
|
|
89
|
+
} else {
|
|
90
|
+
assertNever(rootState);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
updateRealmIdIfNecessary(realm, newId) {
|
|
96
|
+
const currentId = realm.entity.id;
|
|
97
|
+
let idToChangeTo = void 0;
|
|
98
|
+
if (currentId instanceof ServerId) {
|
|
99
|
+
if (newId === void 0 || newId === null) {
|
|
100
|
+
idToChangeTo = new UnpersistedEntityDummyId();
|
|
101
|
+
} else if (currentId.value !== newId.value) {
|
|
102
|
+
idToChangeTo = newId;
|
|
103
|
+
}
|
|
104
|
+
} else if (currentId instanceof ClientGeneratedUuid) {
|
|
105
|
+
idToChangeTo = newId ?? new UnpersistedEntityDummyId();
|
|
106
|
+
} else if (currentId instanceof UnpersistedEntityDummyId) {
|
|
107
|
+
if (newId) {
|
|
108
|
+
idToChangeTo = newId;
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
return assertNever(currentId);
|
|
112
|
+
}
|
|
113
|
+
if (idToChangeTo) {
|
|
114
|
+
OperationsHelpers.changeRealmId(this.treeStore, this.eventManager, this.stateInitializer, realm, idToChangeTo);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
updateEntityRealmPersistedData(realm) {
|
|
118
|
+
const realmId = realm.entity.id;
|
|
119
|
+
const persistedData = realmId.existsOnServer ? this.treeStore.persistedEntityData.get(realmId.uniqueValue) : void 0;
|
|
120
|
+
for (const [placeholderName, child] of realm.children) {
|
|
121
|
+
const childData = persistedData?.get(placeholderName);
|
|
122
|
+
switch (child.type) {
|
|
123
|
+
case "field": {
|
|
124
|
+
if (childData instanceof ServerId || childData instanceof Set) {
|
|
125
|
+
throw new BindingError();
|
|
126
|
+
}
|
|
127
|
+
if (child.persistedValue !== childData) {
|
|
128
|
+
const shouldChangeBothValues = child.persistedValue === child.value;
|
|
129
|
+
child.persistedValue = childData;
|
|
130
|
+
if (shouldChangeBothValues) {
|
|
131
|
+
child.value = childData ?? null;
|
|
132
|
+
}
|
|
133
|
+
this.eventManager.registerJustUpdated(child, EventManager.NO_CHANGES_DIFFERENCE);
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
case "entityRealm":
|
|
138
|
+
case "entityRealmStub": {
|
|
139
|
+
if (!(childData instanceof ServerId) && childData !== void 0 && childData !== null) {
|
|
140
|
+
throw new BindingError();
|
|
141
|
+
}
|
|
142
|
+
this.updateRealmIdIfNecessary(child, childData);
|
|
143
|
+
if (child.type === "entityRealm") {
|
|
144
|
+
this.updateEntityRealmPersistedData(child);
|
|
145
|
+
}
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
case "entityList": {
|
|
149
|
+
if (childData !== void 0 && !(childData instanceof Set)) {
|
|
150
|
+
throw new BindingError();
|
|
151
|
+
}
|
|
152
|
+
this.updateEntityListPersistedData(child, childData ?? /* @__PURE__ */ new Set());
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
default: {
|
|
156
|
+
return assertNever(child);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
updateEntityListPersistedData(state, newPersistedIds) {
|
|
162
|
+
const persistedWithoutState = [];
|
|
163
|
+
for (const persistedId of newPersistedIds) {
|
|
164
|
+
if (!state.children.has(persistedId)) {
|
|
165
|
+
persistedWithoutState.push(persistedId);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
for (const [stateId, child] of state.children) {
|
|
169
|
+
const childRuntimeId = child.entity.id;
|
|
170
|
+
if (!newPersistedIds.has(stateId)) {
|
|
171
|
+
if (
|
|
172
|
+
// It's a uuid but it's not among the persisted so either it got deleted/disconnected or the client-side
|
|
173
|
+
// id generation didn't quite pan out.
|
|
174
|
+
childRuntimeId instanceof ServerId || childRuntimeId instanceof ClientGeneratedUuid || // No persisted entity id to allocate to this so that's a goodbye.
|
|
175
|
+
persistedWithoutState.length === 0
|
|
176
|
+
) {
|
|
177
|
+
state.getAccessor().disconnectEntity(child.getAccessor());
|
|
178
|
+
continue;
|
|
179
|
+
} else {
|
|
180
|
+
const drawnId = persistedWithoutState.shift();
|
|
181
|
+
OperationsHelpers.changeRealmId(
|
|
182
|
+
this.treeStore,
|
|
183
|
+
this.eventManager,
|
|
184
|
+
this.stateInitializer,
|
|
185
|
+
child,
|
|
186
|
+
new ServerId(drawnId, child.entity.entityName)
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
} else if (childRuntimeId instanceof ClientGeneratedUuid) {
|
|
190
|
+
OperationsHelpers.changeRealmId(
|
|
191
|
+
this.treeStore,
|
|
192
|
+
this.eventManager,
|
|
193
|
+
this.stateInitializer,
|
|
194
|
+
child,
|
|
195
|
+
new ServerId(childRuntimeId.value, child.entity.entityName)
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
if (child.type === "entityRealm") {
|
|
199
|
+
this.updateEntityRealmPersistedData(child);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
for (const unclaimedPersistedId of persistedWithoutState) {
|
|
203
|
+
this.stateInitializer.initializeEntityRealm(new ServerId(unclaimedPersistedId, state.entityName), state.entityName, {
|
|
204
|
+
type: "listEntity",
|
|
205
|
+
parent: state
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
state.children.changeKeyOrder(newPersistedIds);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
export {
|
|
212
|
+
TreeAugmenter
|
|
213
|
+
};
|
|
214
|
+
//# sourceMappingURL=TreeAugmenter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeAugmenter.js","sources":["../../../../../packages/binding-legacy/src/core/TreeAugmenter.ts"],"sourcesContent":["import {\n\tClientGeneratedUuid,\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 type { EntityListState, EntityRealmState, EntityRealmStateStub, 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)\n\n\t\t\tswitch (child.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (childData instanceof ServerId || childData instanceof Set) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (child.persistedValue !== childData) {\n\t\t\t\t\t\tconst shouldChangeBothValues = child.persistedValue === child.value\n\n\t\t\t\t\t\tchild.persistedValue = childData\n\t\t\t\t\t\tif (shouldChangeBothValues) {\n\t\t\t\t\t\t\tchild.value = childData ?? null\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.eventManager.registerJustUpdated(child, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\tif (!(childData instanceof ServerId) && childData !== undefined && childData !== null) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateRealmIdIfNecessary(child, childData)\n\t\t\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (childData !== undefined && !(childData instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateEntityListPersistedData(child, childData ?? new Set()) // TODO!!\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn assertNever(child)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateEntityListPersistedData(state: EntityListState, newPersistedIds: EntityListPersistedData) {\n\t\tconst persistedWithoutState: EntityId[] = []\n\n\t\t// TODO This isn't particularly efficient. We should probably use something like diff-sequence here.\n\n\t\tfor (const persistedId of newPersistedIds) {\n\t\t\tif (!state.children.has(persistedId)) {\n\t\t\t\tpersistedWithoutState.push(persistedId)\n\t\t\t}\n\t\t}\n\t\tfor (const [stateId, child] of state.children) {\n\t\t\tconst childRuntimeId = child.entity.id\n\t\t\tif (!newPersistedIds.has(stateId)) {\n\t\t\t\tif (\n\t\t\t\t\t// It's a uuid but it's not among the persisted so either it got deleted/disconnected or the client-side\n\t\t\t\t\t// id generation didn't quite pan out.\n\t\t\t\t\tchildRuntimeId instanceof ServerId ||\n\t\t\t\t\tchildRuntimeId instanceof ClientGeneratedUuid ||\n\t\t\t\t\t// No persisted entity id to allocate to this so that's a goodbye.\n\t\t\t\t\tpersistedWithoutState.length === 0\n\t\t\t\t) {\n\t\t\t\t\tstate.getAccessor().disconnectEntity(child.getAccessor())\n\t\t\t\t\tcontinue\n\t\t\t\t} else {\n\t\t\t\t\tconst drawnId = persistedWithoutState.shift()!\n\t\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\t\tthis.treeStore,\n\t\t\t\t\t\tthis.eventManager,\n\t\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\t\tchild,\n\t\t\t\t\t\tnew ServerId(drawnId, child.entity.entityName),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (childRuntimeId instanceof ClientGeneratedUuid) {\n\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\tthis.treeStore,\n\t\t\t\t\tthis.eventManager,\n\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\tchild,\n\t\t\t\t\tnew ServerId(childRuntimeId.value, child.entity.entityName),\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t}\n\t\t}\n\t\tfor (const unclaimedPersistedId of persistedWithoutState) {\n\t\t\tthis.stateInitializer.initializeEntityRealm(new ServerId(unclaimedPersistedId, state.entityName), state.entityName, {\n\t\t\t\ttype: 'listEntity',\n\t\t\t\tparent: state,\n\t\t\t})\n\t\t}\n\t\t// All that remains now is the order.\n\t\tstate.children.changeKeyOrder(newPersistedIds)\n\t}\n}\n"],"names":[],"mappings":";;;AAmBO,MAAM,cAAc;AAAA,EACnB,YACW,cACA,kBACA,WACA,8BAAuC,OACvD;AAJgB,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AACA,SAAA,8BAAA;AAAA,EACf;AAAA,EAEI,oBAAoB,kBAAoC,YAA4B;AAErF,SAAA,UAAU,qBAAqB,kBAAkB,UAAU;AAAA,EACjE;AAAA,EAEO,iBAAiB,WAAmC,eAAqC;AACzF,UAAA,oCAAyD;AAE/D,SAAK,UAAU,YAAY,IAAI,WAAW,aAAa;AACvD,SAAK,UAAU,oBAAoB,IAAI,WAAW,aAAa;AAE/D,eAAW,CAAC,iBAAiB,gBAAgB,KAAK,cAAc,UAAU;AACzE,YAAM,WAAW,KAAK,iBAAiB,kBAAkB,gBAAgB;AAC3D,oBAAA,IAAI,iBAAiB,QAAQ;AAAA,IAC5C;AAAA,EACD;AAAA,EAEO,oBAAoB,UAA4B,YAAoC;AACrF,SAAA,UAAU,wBAAwB,UAAU,UAAU;AAC3D,QAAI,KAAK,6BAA6B;AACrC;AAAA,IACD;AACK,SAAA,aAAa,gBAAgB,MAAM;AACvC,iBAAW,cAAc,KAAK,UAAU,oBAAoB,UAAU;AAUrE,mBAAW,CAAC,iBAAiB,SAAS,KAAK,YAAY;AACtD,gBAAM,WAAW,KAAK,UAAU,qBAAqB,IAAI,eAAe;AAEpE,cAAA,UAAU,SAAS,cAAc;AAChC,gBAAA,EAA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A,YACL,KAAK;AAAA,YACL;AAAA,YACA,IAAI,SAAS,SAAS,MAAM,OAAO,UAAU;AAAA,UAAA;AAAA,QAE/C;AAAA,MAAA,WACU,0BAA0B,qBAAqB;AACvC,0BAAA;AAAA,UACjB,KAAK;AAAA,UACL,KAAK;AAAA,UACL,KAAK;AAAA,UACL;AAAA,UACA,IAAI,SAAS,eAAe,OAAO,MAAM,OAAO,UAAU;AAAA,QAAA;AAAA,MAE5D;AACI,UAAA,MAAM,SAAS,eAAe;AACjC,aAAK,+BAA+B,KAAK;AAAA,MAC1C;AAAA,IACD;AACA,eAAW,wBAAwB,uBAAuB;AACpD,WAAA,iBAAiB,sBAAsB,IAAI,SAAS,sBAAsB,MAAM,UAAU,GAAG,MAAM,YAAY;AAAA,QACnH,MAAM;AAAA,QACN,QAAQ;AAAA,MAAA,CACR;AAAA,IACF;AAEM,UAAA,SAAS,eAAe,eAAe;AAAA,EAC9C;AACD;"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const bindingCommon = require("@contember/binding-common");
|
|
4
|
+
const StateIterator = require("./state/StateIterator.cjs");
|
|
5
|
+
class TreeFilterGenerator {
|
|
6
|
+
constructor(treeStore) {
|
|
7
|
+
this.treeStore = treeStore;
|
|
8
|
+
}
|
|
9
|
+
generateTreeFilter() {
|
|
10
|
+
const filters = [];
|
|
11
|
+
for (const [placeholderName, state] of StateIterator.StateIterator.eachRootState(this.treeStore)) {
|
|
12
|
+
const blueprint = state.blueprint;
|
|
13
|
+
if (blueprint.parent || blueprint.marker.parameters.expectedMutation === "none") {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
const marker = blueprint.marker;
|
|
17
|
+
filters.push(this.generateSubTreeFilter(marker, this.treeStore.subTreePersistedData.get(placeholderName)));
|
|
18
|
+
}
|
|
19
|
+
return filters.flat();
|
|
20
|
+
}
|
|
21
|
+
generateSubTreeFilter(subTree, persistedData) {
|
|
22
|
+
const filters = [];
|
|
23
|
+
if (persistedData === void 0) {
|
|
24
|
+
return filters;
|
|
25
|
+
}
|
|
26
|
+
if (persistedData instanceof bindingCommon.ServerId) {
|
|
27
|
+
const filter = this.generateTopLevelEntityFilter(
|
|
28
|
+
persistedData.value,
|
|
29
|
+
subTree.parameters.entityName,
|
|
30
|
+
subTree.fields
|
|
31
|
+
);
|
|
32
|
+
filter && filters.push(filter);
|
|
33
|
+
} else {
|
|
34
|
+
for (const id of persistedData) {
|
|
35
|
+
const filter = this.generateTopLevelEntityFilter(id, subTree.parameters.entityName, subTree.fields);
|
|
36
|
+
filter && filters.push(filter);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return filters;
|
|
40
|
+
}
|
|
41
|
+
generateTopLevelEntityFilter(id, entityName, fields) {
|
|
42
|
+
return {
|
|
43
|
+
entity: entityName,
|
|
44
|
+
id,
|
|
45
|
+
relations: this.generateEntityRelations(fields)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
generateEntityRelations(markers) {
|
|
49
|
+
const rawFilter = this.populateRawRelationFilters(markers);
|
|
50
|
+
return this.normalizeRawRelationFilters(rawFilter);
|
|
51
|
+
}
|
|
52
|
+
normalizeRawRelationFilters(raw) {
|
|
53
|
+
return Array.from(raw, ([fieldName, relations]) => ({
|
|
54
|
+
name: fieldName,
|
|
55
|
+
relations: this.normalizeRawRelationFilters(relations)
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
populateRawRelationFilters(markers, relations = /* @__PURE__ */ new Map()) {
|
|
59
|
+
for (const [, marker] of markers.markers) {
|
|
60
|
+
if (!(marker instanceof bindingCommon.HasOneRelationMarker) && !(marker instanceof bindingCommon.HasManyRelationMarker)) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (marker.parameters.expectedMutation === "none" || marker.parameters.expectedMutation === "connectOrDisconnect") {
|
|
64
|
+
continue;
|
|
65
|
+
} else if (marker.parameters.expectedMutation === "anyMutation" || marker.parameters.expectedMutation === "createOrDelete") ;
|
|
66
|
+
else {
|
|
67
|
+
return bindingCommon.assertNever(marker.parameters.expectedMutation);
|
|
68
|
+
}
|
|
69
|
+
let existingRelation = relations.get(marker.parameters.field);
|
|
70
|
+
if (existingRelation === void 0) {
|
|
71
|
+
relations.set(marker.parameters.field, existingRelation = /* @__PURE__ */ new Map());
|
|
72
|
+
}
|
|
73
|
+
this.populateRawRelationFilters(marker.fields, existingRelation);
|
|
74
|
+
}
|
|
75
|
+
return relations;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.TreeFilterGenerator = TreeFilterGenerator;
|
|
79
|
+
//# sourceMappingURL=TreeFilterGenerator.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeFilterGenerator.cjs","sources":["../../../../../packages/binding-legacy/src/core/TreeFilterGenerator.ts"],"sourcesContent":["import type { RelationFilter, TreeFilter } from '@contember/client'\nimport { EntityListPersistedData } from '../accessorTree'\nimport {\n\tEntityFieldMarkersContainer,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tServerId,\n} from '@contember/binding-common'\nimport type { EntityId, EntityName } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport { StateIterator } from './state'\nimport type { TreeStore } from './TreeStore'\n\ntype RawRelationFilters = Map<string, RawRelationFilters>\n\nexport class TreeFilterGenerator {\n\tpublic constructor(private readonly treeStore: TreeStore) {}\n\n\tpublic generateTreeFilter(): TreeFilter[] {\n\t\tconst filters: TreeFilter[][] = []\n\n\t\tfor (const [placeholderName, state] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\tconst blueprint = state.blueprint\n\n\t\t\tif (blueprint.parent || blueprint.marker.parameters.expectedMutation === 'none') {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst marker = blueprint.marker\n\t\t\tfilters.push(this.generateSubTreeFilter(marker, this.treeStore.subTreePersistedData.get(placeholderName)))\n\t\t}\n\t\treturn filters.flat()\n\t}\n\n\tprivate generateSubTreeFilter(\n\t\tsubTree: EntitySubTreeMarker | EntityListSubTreeMarker,\n\t\tpersistedData: ServerId | EntityListPersistedData | undefined,\n\t): TreeFilter[] {\n\t\tconst filters: TreeFilter[] = []\n\n\t\tif (persistedData === undefined) {\n\t\t\treturn filters // Do nothing\n\t\t}\n\n\t\tif (persistedData instanceof ServerId) {\n\t\t\tconst filter = this.generateTopLevelEntityFilter(\n\t\t\t\tpersistedData.value,\n\t\t\t\tsubTree.parameters.entityName,\n\t\t\t\tsubTree.fields,\n\t\t\t)\n\t\t\tfilter && filters.push(filter)\n\t\t} else {\n\t\t\tfor (const id of persistedData) {\n\t\t\t\tconst filter = this.generateTopLevelEntityFilter(id, subTree.parameters.entityName, subTree.fields)\n\t\t\t\tfilter && filters.push(filter)\n\t\t\t}\n\t\t}\n\n\t\treturn filters\n\t}\n\n\tprivate generateTopLevelEntityFilter(\n\t\tid: EntityId,\n\t\tentityName: EntityName,\n\t\tfields: EntityFieldMarkersContainer,\n\t): TreeFilter | undefined {\n\t\treturn {\n\t\t\tentity: entityName,\n\t\t\tid: id,\n\t\t\trelations: this.generateEntityRelations(fields),\n\t\t}\n\t}\n\n\tprivate generateEntityRelations(markers: EntityFieldMarkersContainer): RelationFilter[] {\n\t\tconst rawFilter = this.populateRawRelationFilters(markers)\n\t\treturn this.normalizeRawRelationFilters(rawFilter)\n\t}\n\n\tprivate normalizeRawRelationFilters(raw: RawRelationFilters): RelationFilter[] {\n\t\treturn Array.from(raw, ([fieldName, relations]) => ({\n\t\t\tname: fieldName,\n\t\t\trelations: this.normalizeRawRelationFilters(relations),\n\t\t}))\n\t}\n\n\tprivate populateRawRelationFilters(\n\t\tmarkers: EntityFieldMarkersContainer,\n\t\trelations: RawRelationFilters = new Map(),\n\t): RawRelationFilters {\n\t\tfor (const [, marker] of markers.markers) {\n\t\t\tif (!(marker instanceof HasOneRelationMarker) && !(marker instanceof HasManyRelationMarker)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (\n\t\t\t\tmarker.parameters.expectedMutation === 'none' ||\n\t\t\t\tmarker.parameters.expectedMutation === 'connectOrDisconnect'\n\t\t\t) {\n\t\t\t\tcontinue\n\t\t\t} else if (\n\t\t\t\tmarker.parameters.expectedMutation === 'anyMutation' ||\n\t\t\t\tmarker.parameters.expectedMutation === 'createOrDelete'\n\t\t\t) {\n\t\t\t} else {\n\t\t\t\treturn assertNever(marker.parameters.expectedMutation)\n\t\t\t}\n\t\t\tlet existingRelation = relations.get(marker.parameters.field)\n\n\t\t\tif (existingRelation === undefined) {\n\t\t\t\trelations.set(marker.parameters.field, (existingRelation = new Map()))\n\t\t\t}\n\t\t\tthis.populateRawRelationFilters(marker.fields, existingRelation)\n\t\t}\n\n\t\treturn relations\n\t}\n}\n"],"names":["StateIterator","ServerId","HasOneRelationMarker","HasManyRelationMarker","assertNever"],"mappings":";;;;AAiBO,MAAM,oBAAoB;AAAA,EACzB,YAA6B,WAAsB;AAAtB,SAAA,YAAA;AAAA,EAAuB;AAAA,EAEpD,qBAAmC;AACzC,UAAM,UAA0B,CAAA;AAErB,eAAA,CAAC,iBAAiB,KAAK,KAAKA,4BAAc,cAAc,KAAK,SAAS,GAAG;AACnF,YAAM,YAAY,MAAM;AAExB,UAAI,UAAU,UAAU,UAAU,OAAO,WAAW,qBAAqB,QAAQ;AAChF;AAAA,MACD;AACA,YAAM,SAAS,UAAU;AACjB,cAAA,KAAK,KAAK,sBAAsB,QAAQ,KAAK,UAAU,qBAAqB,IAAI,eAAe,CAAC,CAAC;AAAA,IAC1G;AACA,WAAO,QAAQ;EAChB;AAAA,EAEQ,sBACP,SACA,eACe;AACf,UAAM,UAAwB,CAAA;AAE9B,QAAI,kBAAkB,QAAW;AACzB,aAAA;AAAA,IACR;AAEA,QAAI,yBAAyBC,cAAAA,UAAU;AACtC,YAAM,SAAS,KAA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AmB,oBAAI,KAAM;AAAA,MACtE;AACK,WAAA,2BAA2B,OAAO,QAAQ,gBAAgB;AAAA,IAChE;AAEO,WAAA;AAAA,EACR;AACD;;"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ServerId, HasOneRelationMarker, HasManyRelationMarker, assertNever } from "@contember/binding-common";
|
|
2
|
+
import { StateIterator } from "./state/StateIterator.js";
|
|
3
|
+
class TreeFilterGenerator {
|
|
4
|
+
constructor(treeStore) {
|
|
5
|
+
this.treeStore = treeStore;
|
|
6
|
+
}
|
|
7
|
+
generateTreeFilter() {
|
|
8
|
+
const filters = [];
|
|
9
|
+
for (const [placeholderName, state] of StateIterator.eachRootState(this.treeStore)) {
|
|
10
|
+
const blueprint = state.blueprint;
|
|
11
|
+
if (blueprint.parent || blueprint.marker.parameters.expectedMutation === "none") {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
const marker = blueprint.marker;
|
|
15
|
+
filters.push(this.generateSubTreeFilter(marker, this.treeStore.subTreePersistedData.get(placeholderName)));
|
|
16
|
+
}
|
|
17
|
+
return filters.flat();
|
|
18
|
+
}
|
|
19
|
+
generateSubTreeFilter(subTree, persistedData) {
|
|
20
|
+
const filters = [];
|
|
21
|
+
if (persistedData === void 0) {
|
|
22
|
+
return filters;
|
|
23
|
+
}
|
|
24
|
+
if (persistedData instanceof ServerId) {
|
|
25
|
+
const filter = this.generateTopLevelEntityFilter(
|
|
26
|
+
persistedData.value,
|
|
27
|
+
subTree.parameters.entityName,
|
|
28
|
+
subTree.fields
|
|
29
|
+
);
|
|
30
|
+
filter && filters.push(filter);
|
|
31
|
+
} else {
|
|
32
|
+
for (const id of persistedData) {
|
|
33
|
+
const filter = this.generateTopLevelEntityFilter(id, subTree.parameters.entityName, subTree.fields);
|
|
34
|
+
filter && filters.push(filter);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return filters;
|
|
38
|
+
}
|
|
39
|
+
generateTopLevelEntityFilter(id, entityName, fields) {
|
|
40
|
+
return {
|
|
41
|
+
entity: entityName,
|
|
42
|
+
id,
|
|
43
|
+
relations: this.generateEntityRelations(fields)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
generateEntityRelations(markers) {
|
|
47
|
+
const rawFilter = this.populateRawRelationFilters(markers);
|
|
48
|
+
return this.normalizeRawRelationFilters(rawFilter);
|
|
49
|
+
}
|
|
50
|
+
normalizeRawRelationFilters(raw) {
|
|
51
|
+
return Array.from(raw, ([fieldName, relations]) => ({
|
|
52
|
+
name: fieldName,
|
|
53
|
+
relations: this.normalizeRawRelationFilters(relations)
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
populateRawRelationFilters(markers, relations = /* @__PURE__ */ new Map()) {
|
|
57
|
+
for (const [, marker] of markers.markers) {
|
|
58
|
+
if (!(marker instanceof HasOneRelationMarker) && !(marker instanceof HasManyRelationMarker)) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (marker.parameters.expectedMutation === "none" || marker.parameters.expectedMutation === "connectOrDisconnect") {
|
|
62
|
+
continue;
|
|
63
|
+
} else if (marker.parameters.expectedMutation === "anyMutation" || marker.parameters.expectedMutation === "createOrDelete") ;
|
|
64
|
+
else {
|
|
65
|
+
return assertNever(marker.parameters.expectedMutation);
|
|
66
|
+
}
|
|
67
|
+
let existingRelation = relations.get(marker.parameters.field);
|
|
68
|
+
if (existingRelation === void 0) {
|
|
69
|
+
relations.set(marker.parameters.field, existingRelation = /* @__PURE__ */ new Map());
|
|
70
|
+
}
|
|
71
|
+
this.populateRawRelationFilters(marker.fields, existingRelation);
|
|
72
|
+
}
|
|
73
|
+
return relations;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
TreeFilterGenerator
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=TreeFilterGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeFilterGenerator.js","sources":["../../../../../packages/binding-legacy/src/core/TreeFilterGenerator.ts"],"sourcesContent":["import type { RelationFilter, TreeFilter } from '@contember/client'\nimport { EntityListPersistedData } from '../accessorTree'\nimport {\n\tEntityFieldMarkersContainer,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tServerId,\n} from '@contember/binding-common'\nimport type { EntityId, EntityName } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport { StateIterator } from './state'\nimport type { TreeStore } from './TreeStore'\n\ntype RawRelationFilters = Map<string, RawRelationFilters>\n\nexport class TreeFilterGenerator {\n\tpublic constructor(private readonly treeStore: TreeStore) {}\n\n\tpublic generateTreeFilter(): TreeFilter[] {\n\t\tconst filters: TreeFilter[][] = []\n\n\t\tfor (const [placeholderName, state] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\tconst blueprint = state.blueprint\n\n\t\t\tif (blueprint.parent || blueprint.marker.parameters.expectedMutation === 'none') {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst marker = blueprint.marker\n\t\t\tfilters.push(this.generateSubTreeFilter(marker, this.treeStore.subTreePersistedData.get(placeholderName)))\n\t\t}\n\t\treturn filters.flat()\n\t}\n\n\tprivate generateSubTreeFilter(\n\t\tsubTree: EntitySubTreeMarker | EntityListSubTreeMarker,\n\t\tpersistedData: ServerId | EntityListPersistedData | undefined,\n\t): TreeFilter[] {\n\t\tconst filters: TreeFilter[] = []\n\n\t\tif (persistedData === undefined) {\n\t\t\treturn filters // Do nothing\n\t\t}\n\n\t\tif (persistedData instanceof ServerId) {\n\t\t\tconst filter = this.generateTopLevelEntityFilter(\n\t\t\t\tpersistedData.value,\n\t\t\t\tsubTree.parameters.entityName,\n\t\t\t\tsubTree.fields,\n\t\t\t)\n\t\t\tfilter && filters.push(filter)\n\t\t} else {\n\t\t\tfor (const id of persistedData) {\n\t\t\t\tconst filter = this.generateTopLevelEntityFilter(id, subTree.parameters.entityName, subTree.fields)\n\t\t\t\tfilter && filters.push(filter)\n\t\t\t}\n\t\t}\n\n\t\treturn filters\n\t}\n\n\tprivate generateTopLevelEntityFilter(\n\t\tid: EntityId,\n\t\tentityName: EntityName,\n\t\tfields: EntityFieldMarkersContainer,\n\t): TreeFilter | undefined {\n\t\treturn {\n\t\t\tentity: entityName,\n\t\t\tid: id,\n\t\t\trelations: this.generateEntityRelations(fields),\n\t\t}\n\t}\n\n\tprivate generateEntityRelations(markers: EntityFieldMarkersContainer): RelationFilter[] {\n\t\tconst rawFilter = this.populateRawRelationFilters(markers)\n\t\treturn this.normalizeRawRelationFilters(rawFilter)\n\t}\n\n\tprivate normalizeRawRelationFilters(raw: RawRelationFilters): RelationFilter[] {\n\t\treturn Array.from(raw, ([fieldName, relations]) => ({\n\t\t\tname: fieldName,\n\t\t\trelations: this.normalizeRawRelationFilters(relations),\n\t\t}))\n\t}\n\n\tprivate populateRawRelationFilters(\n\t\tmarkers: EntityFieldMarkersContainer,\n\t\trelations: RawRelationFilters = new Map(),\n\t): RawRelationFilters {\n\t\tfor (const [, marker] of markers.markers) {\n\t\t\tif (!(marker instanceof HasOneRelationMarker) && !(marker instanceof HasManyRelationMarker)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (\n\t\t\t\tmarker.parameters.expectedMutation === 'none' ||\n\t\t\t\tmarker.parameters.expectedMutation === 'connectOrDisconnect'\n\t\t\t) {\n\t\t\t\tcontinue\n\t\t\t} else if (\n\t\t\t\tmarker.parameters.expectedMutation === 'anyMutation' ||\n\t\t\t\tmarker.parameters.expectedMutation === 'createOrDelete'\n\t\t\t) {\n\t\t\t} else {\n\t\t\t\treturn assertNever(marker.parameters.expectedMutation)\n\t\t\t}\n\t\t\tlet existingRelation = relations.get(marker.parameters.field)\n\n\t\t\tif (existingRelation === undefined) {\n\t\t\t\trelations.set(marker.parameters.field, (existingRelation = new Map()))\n\t\t\t}\n\t\t\tthis.populateRawRelationFilters(marker.fields, existingRelation)\n\t\t}\n\n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K,KAAK,CAAC,CAAC,WAAW,SAAS,OAAO;AAAA,MACnD,MAAM;AAAA,MACN,WAAW,KAAK,4BAA4B,SAAS;AAAA,IACpD,EAAA;AAAA,EACH;AAAA,EAEQ,2BACP,SACA,YAAgC,oBAAI,OACf;AACrB,eAAW,CAAG,EAAA,MAAM,KAAK,QAAQ,SAAS;AACzC,UAAI,EAAE,kBAAkB,yBAAyB,EAAE,kBAAkB,wBAAwB;AAC5F;AAAA,MACD;AACA,UACC,OAAO,WAAW,qBAAqB,UACvC,OAAO,WAAW,qBAAqB,uBACtC;AACD;AAAA,MAAA,WAEA,OAAO,WAAW,qBAAqB,iBACvC,OAAO,WAAW,qBAAqB,iBACtC;AAAA,WACK;AACC,eAAA,YAAY,OAAO,WAAW,gBAAgB;AAAA,MACtD;AACA,UAAI,mBAAmB,UAAU,IAAI,OAAO,WAAW,KAAK;AAE5D,UAAI,qBAAqB,QAAW;AACnC,kBAAU,IAAI,OAAO,WAAW,OAAQ,mBAAmB,oBAAI,KAAM;AAAA,MACtE;AACK,WAAA,2BAA2B,OAAO,QAAQ,gBAAgB;AAAA,IAChE;AAEO,WAAA;AAAA,EACR;AACD;"}
|
|
@@ -0,0 +1,172 @@
|
|
|
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) ?? 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
|