@contember/binding 1.0.0-rc.8 → 1.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (535) hide show
  1. package/dist/development/BindingError.js +0 -1
  2. package/dist/development/BindingError.js.map +1 -1
  3. package/dist/development/accessorPropagation/AccessorProvider.js +3 -5
  4. package/dist/development/accessorPropagation/AccessorProvider.js.map +1 -1
  5. package/dist/development/accessorPropagation/BindingOperationsContext.js +2 -4
  6. package/dist/development/accessorPropagation/BindingOperationsContext.js.map +1 -1
  7. package/dist/development/accessorPropagation/BindingOperationsProvider.js +2 -4
  8. package/dist/development/accessorPropagation/BindingOperationsProvider.js.map +1 -1
  9. package/dist/development/accessorPropagation/EntityKeyContext.js +1 -3
  10. package/dist/development/accessorPropagation/EntityKeyContext.js.map +1 -1
  11. package/dist/development/accessorPropagation/EntityKeyProvider.js +2 -4
  12. package/dist/development/accessorPropagation/EntityKeyProvider.js.map +1 -1
  13. package/dist/development/accessorPropagation/EnvironmentContext.js +2 -4
  14. package/dist/development/accessorPropagation/EnvironmentContext.js.map +1 -1
  15. package/dist/development/accessorPropagation/TreeRootIdContext.js +1 -3
  16. package/dist/development/accessorPropagation/TreeRootIdContext.js.map +1 -1
  17. package/dist/development/accessorPropagation/TreeRootIdProvider.js +2 -4
  18. package/dist/development/accessorPropagation/TreeRootIdProvider.js.map +1 -1
  19. package/dist/development/accessorPropagation/useAccessorUpdateSubscription.js +2 -4
  20. package/dist/development/accessorPropagation/useAccessorUpdateSubscription.js.map +1 -1
  21. package/dist/development/accessorPropagation/useBindingOperations.js +2 -4
  22. package/dist/development/accessorPropagation/useBindingOperations.js.map +1 -1
  23. package/dist/development/accessorPropagation/useDesugaredRelativeEntityList.js +3 -5
  24. package/dist/development/accessorPropagation/useDesugaredRelativeEntityList.js.map +1 -1
  25. package/dist/development/accessorPropagation/useDesugaredRelativeSingleEntity.js +3 -5
  26. package/dist/development/accessorPropagation/useDesugaredRelativeSingleEntity.js.map +1 -1
  27. package/dist/development/accessorPropagation/useDesugaredRelativeSingleField.js +3 -5
  28. package/dist/development/accessorPropagation/useDesugaredRelativeSingleField.js.map +1 -1
  29. package/dist/development/accessorPropagation/useEntity.js +7 -9
  30. package/dist/development/accessorPropagation/useEntity.js.map +1 -1
  31. package/dist/development/accessorPropagation/useEntityKey.js +3 -5
  32. package/dist/development/accessorPropagation/useEntityKey.js.map +1 -1
  33. package/dist/development/accessorPropagation/useEntityList.js +7 -9
  34. package/dist/development/accessorPropagation/useEntityList.js.map +1 -1
  35. package/dist/development/accessorPropagation/useEntityListSubTree.js +4 -6
  36. package/dist/development/accessorPropagation/useEntityListSubTree.js.map +1 -1
  37. package/dist/development/accessorPropagation/useEntityListSubTreeParameters.js +2 -4
  38. package/dist/development/accessorPropagation/useEntityListSubTreeParameters.js.map +1 -1
  39. package/dist/development/accessorPropagation/useEntitySubTree.js +4 -6
  40. package/dist/development/accessorPropagation/useEntitySubTree.js.map +1 -1
  41. package/dist/development/accessorPropagation/useEntitySubTreeParameters.js +2 -4
  42. package/dist/development/accessorPropagation/useEntitySubTreeParameters.js.map +1 -1
  43. package/dist/development/accessorPropagation/useEnvironment.js +2 -4
  44. package/dist/development/accessorPropagation/useEnvironment.js.map +1 -1
  45. package/dist/development/accessorPropagation/useField.js +7 -9
  46. package/dist/development/accessorPropagation/useField.js.map +1 -1
  47. package/dist/development/accessorPropagation/useGetEntityByKey.js +1 -3
  48. package/dist/development/accessorPropagation/useGetEntityByKey.js.map +1 -1
  49. package/dist/development/accessorPropagation/useGetEntityListSubTree.js +4 -6
  50. package/dist/development/accessorPropagation/useGetEntityListSubTree.js.map +1 -1
  51. package/dist/development/accessorPropagation/useGetEntitySubTree.js +4 -6
  52. package/dist/development/accessorPropagation/useGetEntitySubTree.js.map +1 -1
  53. package/dist/development/accessorPropagation/useGetTreeFilters.js +1 -3
  54. package/dist/development/accessorPropagation/useGetTreeFilters.js.map +1 -1
  55. package/dist/development/accessorPropagation/useHasEntity.js +2 -4
  56. package/dist/development/accessorPropagation/useHasEntity.js.map +1 -1
  57. package/dist/development/accessorPropagation/usePersist.js +1 -3
  58. package/dist/development/accessorPropagation/usePersist.js.map +1 -1
  59. package/dist/development/accessorPropagation/useTreeRootId.js +2 -4
  60. package/dist/development/accessorPropagation/useTreeRootId.js.map +1 -1
  61. package/dist/development/accessorSorting/SetOrderFieldOnCreate.js +9 -11
  62. package/dist/development/accessorSorting/SetOrderFieldOnCreate.js.map +1 -1
  63. package/dist/development/accessorSorting/addEntityAtIndex.js +2 -4
  64. package/dist/development/accessorSorting/addEntityAtIndex.js.map +1 -1
  65. package/dist/development/accessorSorting/errors.js +1 -3
  66. package/dist/development/accessorSorting/errors.js.map +1 -1
  67. package/dist/development/accessorSorting/moveEntity.js +1 -3
  68. package/dist/development/accessorSorting/moveEntity.js.map +1 -1
  69. package/dist/development/accessorSorting/repairEntitiesOrder.js +0 -1
  70. package/dist/development/accessorSorting/repairEntitiesOrder.js.map +1 -1
  71. package/dist/development/accessorSorting/sortEntities.js +0 -1
  72. package/dist/development/accessorSorting/sortEntities.js.map +1 -1
  73. package/dist/development/accessorSorting/useSortedEntities.js +6 -8
  74. package/dist/development/accessorSorting/useSortedEntities.js.map +1 -1
  75. package/dist/development/accessorTree/AccessorTree.js +4 -6
  76. package/dist/development/accessorTree/AccessorTree.js.map +1 -1
  77. package/dist/development/accessorTree/DirtinessContext.js +1 -3
  78. package/dist/development/accessorTree/DirtinessContext.js.map +1 -1
  79. package/dist/development/accessorTree/MutationStateContext.js +1 -3
  80. package/dist/development/accessorTree/MutationStateContext.js.map +1 -1
  81. package/dist/development/accessorTree/NormalizedPersistedData.js +0 -1
  82. package/dist/development/accessorTree/NormalizedPersistedData.js.map +1 -1
  83. package/dist/development/accessorTree/RuntimeId.js +22 -17
  84. package/dist/development/accessorTree/RuntimeId.js.map +1 -1
  85. package/dist/development/accessorTree/accessorTreeStateReducer.js +0 -1
  86. package/dist/development/accessorTree/accessorTreeStateReducer.js.map +1 -1
  87. package/dist/development/accessorTree/metadataToRequestError.js +0 -1
  88. package/dist/development/accessorTree/metadataToRequestError.js.map +1 -1
  89. package/dist/development/accessorTree/useDataBinding.js +5 -7
  90. package/dist/development/accessorTree/useDataBinding.js.map +1 -1
  91. package/dist/development/accessorTree/useDirtinessState.js +2 -4
  92. package/dist/development/accessorTree/useDirtinessState.js.map +1 -1
  93. package/dist/development/accessorTree/useMutationState.js +2 -4
  94. package/dist/development/accessorTree/useMutationState.js.map +1 -1
  95. package/dist/development/accessors/EntityAccessor.js +5 -7
  96. package/dist/development/accessors/EntityAccessor.js.map +1 -1
  97. package/dist/development/accessors/EntityListAccessor.js +1 -3
  98. package/dist/development/accessors/EntityListAccessor.js.map +1 -1
  99. package/dist/development/accessors/ErrorAccessor.js +0 -1
  100. package/dist/development/accessors/ErrorAccessor.js.map +1 -1
  101. package/dist/development/accessors/FieldAccessor.js +3 -5
  102. package/dist/development/accessors/FieldAccessor.js.map +1 -1
  103. package/dist/development/accessors/TreeRootAccessor.js +0 -1
  104. package/dist/development/accessors/TreeRootAccessor.js.map +1 -1
  105. package/dist/development/bindingTypes.js +0 -1
  106. package/dist/development/bindingTypes.js.map +1 -1
  107. package/dist/development/core/AccessorErrorManager.js +15 -11
  108. package/dist/development/core/AccessorErrorManager.js.map +1 -1
  109. package/dist/development/core/Config.js +18 -12
  110. package/dist/development/core/Config.js.map +1 -1
  111. package/dist/development/core/DataBinding.js +74 -67
  112. package/dist/development/core/DataBinding.js.map +1 -1
  113. package/dist/development/core/DirtinessTracker.js +10 -3
  114. package/dist/development/core/DirtinessTracker.js.map +1 -1
  115. package/dist/development/core/ErrorsPreprocessor.js +3 -5
  116. package/dist/development/core/ErrorsPreprocessor.js.map +1 -1
  117. package/dist/development/core/EventManager.js +20 -16
  118. package/dist/development/core/EventManager.js.map +1 -1
  119. package/dist/development/core/IncrementalMarkerBuilder.js +14 -8
  120. package/dist/development/core/IncrementalMarkerBuilder.js.map +1 -1
  121. package/dist/development/core/MarkerComparator.js +6 -8
  122. package/dist/development/core/MarkerComparator.js.map +1 -1
  123. package/dist/development/core/MarkerMerger.js +18 -19
  124. package/dist/development/core/MarkerMerger.js.map +1 -1
  125. package/dist/development/core/MarkerTreeGenerator.js +18 -13
  126. package/dist/development/core/MarkerTreeGenerator.js.map +1 -1
  127. package/dist/development/core/MutationGenerator.js +13 -15
  128. package/dist/development/core/MutationGenerator.js.map +1 -1
  129. package/dist/development/core/QueryGenerator.js +9 -11
  130. package/dist/development/core/QueryGenerator.js.map +1 -1
  131. package/dist/development/core/RealmKeyGenerator.js +10 -6
  132. package/dist/development/core/RealmKeyGenerator.js.map +1 -1
  133. package/dist/development/core/RequestResponseNormalizer.js +7 -9
  134. package/dist/development/core/RequestResponseNormalizer.js.map +1 -1
  135. package/dist/development/core/StateInitializer.js +28 -26
  136. package/dist/development/core/StateInitializer.js.map +1 -1
  137. package/dist/development/core/TreeAugmenter.js +6 -8
  138. package/dist/development/core/TreeAugmenter.js.map +1 -1
  139. package/dist/development/core/TreeFilterGenerator.js +8 -8
  140. package/dist/development/core/TreeFilterGenerator.js.map +1 -1
  141. package/dist/development/core/TreeParameterMerger.js +2 -4
  142. package/dist/development/core/TreeParameterMerger.js.map +1 -1
  143. package/dist/development/core/TreeStore.js +19 -15
  144. package/dist/development/core/TreeStore.js.map +1 -1
  145. package/dist/development/core/VariableInputTransformer.js +6 -5
  146. package/dist/development/core/VariableInputTransformer.js.map +1 -1
  147. package/dist/development/core/exceptions/ErrorLocator.js +10 -6
  148. package/dist/development/core/exceptions/ErrorLocator.js.map +1 -1
  149. package/dist/development/core/exceptions/LocalizedBindingError.js +1 -3
  150. package/dist/development/core/exceptions/LocalizedBindingError.js.map +1 -1
  151. package/dist/development/core/exceptions/MarkerSugarer.js +7 -9
  152. package/dist/development/core/exceptions/MarkerSugarer.js.map +1 -1
  153. package/dist/development/core/exceptions/TreeParameterSugarer.js +0 -1
  154. package/dist/development/core/exceptions/TreeParameterSugarer.js.map +1 -1
  155. package/dist/development/core/factories/createBatchUpdatesOptions.js +1 -3
  156. package/dist/development/core/factories/createBatchUpdatesOptions.js.map +1 -1
  157. package/dist/development/core/operations/EntityOperations.js +13 -14
  158. package/dist/development/core/operations/EntityOperations.js.map +1 -1
  159. package/dist/development/core/operations/FieldOperations.js +10 -12
  160. package/dist/development/core/operations/FieldOperations.js.map +1 -1
  161. package/dist/development/core/operations/ListOperations.js +12 -14
  162. package/dist/development/core/operations/ListOperations.js.map +1 -1
  163. package/dist/development/core/operations/OperationsHelpers.js +4 -6
  164. package/dist/development/core/operations/OperationsHelpers.js.map +1 -1
  165. package/dist/development/core/requestAliases/MutationAlias.js +2 -4
  166. package/dist/development/core/requestAliases/MutationAlias.js.map +1 -1
  167. package/dist/development/core/requestAliases/mutationOperationSubTreeType.js +0 -1
  168. package/dist/development/core/requestAliases/mutationOperationSubTreeType.js.map +1 -1
  169. package/dist/development/core/requestAliases/mutationOperationType.js +0 -1
  170. package/dist/development/core/requestAliases/mutationOperationType.js.map +1 -1
  171. package/dist/development/core/schema/Schema.js +3 -1
  172. package/dist/development/core/schema/Schema.js.map +1 -1
  173. package/dist/development/core/schema/SchemaLoader.js +9 -5
  174. package/dist/development/core/schema/SchemaLoader.js.map +1 -1
  175. package/dist/development/core/schema/SchemaPreprocessor.js +0 -1
  176. package/dist/development/core/schema/SchemaPreprocessor.js.map +1 -1
  177. package/dist/development/core/state/StateIterator.js +2 -4
  178. package/dist/development/core/state/StateIterator.js.map +1 -1
  179. package/dist/development/core/state/getEntityMarker.js +0 -1
  180. package/dist/development/core/state/getEntityMarker.js.map +1 -1
  181. package/dist/development/core/utils/getCombinedSignal.js +0 -1
  182. package/dist/development/core/utils/getCombinedSignal.js.map +1 -1
  183. package/dist/development/coreComponents/Component.js +2 -4
  184. package/dist/development/coreComponents/Component.js.map +1 -1
  185. package/dist/development/coreComponents/DataBindingProvider.js +3 -5
  186. package/dist/development/coreComponents/DataBindingProvider.js.map +1 -1
  187. package/dist/development/coreComponents/Entity.js +3 -5
  188. package/dist/development/coreComponents/Entity.js.map +1 -1
  189. package/dist/development/coreComponents/EntityList.js +3 -5
  190. package/dist/development/coreComponents/EntityList.js.map +1 -1
  191. package/dist/development/coreComponents/EntityListSubTree.js +13 -23
  192. package/dist/development/coreComponents/EntityListSubTree.js.map +1 -1
  193. package/dist/development/coreComponents/EntitySubTree.js +14 -34
  194. package/dist/development/coreComponents/EntitySubTree.js.map +1 -1
  195. package/dist/development/coreComponents/Field.js +10 -8
  196. package/dist/development/coreComponents/Field.js.map +1 -1
  197. package/dist/development/coreComponents/HasMany.js +10 -14
  198. package/dist/development/coreComponents/HasMany.js.map +1 -1
  199. package/dist/development/coreComponents/HasOne.js +10 -14
  200. package/dist/development/coreComponents/HasOne.js.map +1 -1
  201. package/dist/development/coreComponents/ParentEntity.js +3 -5
  202. package/dist/development/coreComponents/ParentEntity.js.map +1 -1
  203. package/dist/development/dao/Environment.js +147 -89
  204. package/dist/development/dao/Environment.js.map +1 -1
  205. package/dist/development/dao/TreeNodeEnvironmentFactory.js +159 -0
  206. package/dist/development/dao/TreeNodeEnvironmentFactory.js.map +1 -0
  207. package/dist/development/dao/VariableFieldValue.js +0 -1
  208. package/dist/development/dao/VariableFieldValue.js.map +1 -1
  209. package/dist/development/entityEvents/useDerivedField.js +4 -6
  210. package/dist/development/entityEvents/useDerivedField.js.map +1 -1
  211. package/dist/development/entityEvents/useEntityBeforePersist.js +1 -3
  212. package/dist/development/entityEvents/useEntityBeforePersist.js.map +1 -1
  213. package/dist/development/entityEvents/useEntityBeforeUpdate.js +1 -3
  214. package/dist/development/entityEvents/useEntityBeforeUpdate.js.map +1 -1
  215. package/dist/development/entityEvents/useEntityEvent.js +3 -5
  216. package/dist/development/entityEvents/useEntityEvent.js.map +1 -1
  217. package/dist/development/entityEvents/useEntityPersistError.js +1 -3
  218. package/dist/development/entityEvents/useEntityPersistError.js.map +1 -1
  219. package/dist/development/entityEvents/useEntityPersistSuccess.js +1 -3
  220. package/dist/development/entityEvents/useEntityPersistSuccess.js.map +1 -1
  221. package/dist/development/entityEvents/useOnConnectionUpdate.js +1 -3
  222. package/dist/development/entityEvents/useOnConnectionUpdate.js.map +1 -1
  223. package/dist/development/fieldHelpers/helpers/FieldHelper.js +8 -4
  224. package/dist/development/fieldHelpers/helpers/FieldHelper.js.map +1 -1
  225. package/dist/development/fieldHelpers/helpers/TemporalFieldHelper.js +1 -3
  226. package/dist/development/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -1
  227. package/dist/development/fieldHelpers/helpers/UuidFieldHelper.js +2 -4
  228. package/dist/development/fieldHelpers/helpers/UuidFieldHelper.js.map +1 -1
  229. package/dist/development/helperComponents/DeferredSubTrees.js +9 -11
  230. package/dist/development/helperComponents/DeferredSubTrees.js.map +1 -1
  231. package/dist/development/helperComponents/EntityView.js +2 -4
  232. package/dist/development/helperComponents/EntityView.js.map +1 -1
  233. package/dist/development/helperComponents/FieldView.js +7 -9
  234. package/dist/development/helperComponents/FieldView.js.map +1 -1
  235. package/dist/development/helperComponents/StaticRender.js +2 -4
  236. package/dist/development/helperComponents/StaticRender.js.map +1 -1
  237. package/dist/development/helperComponents/SugaredField.js +3 -5
  238. package/dist/development/helperComponents/SugaredField.js.map +1 -1
  239. package/dist/development/index.js +101 -101
  240. package/dist/development/index.js.map +1 -1
  241. package/dist/development/markers/EntityFieldMarkersContainer.js +5 -7
  242. package/dist/development/markers/EntityFieldMarkersContainer.js.map +1 -1
  243. package/dist/development/markers/EntityFieldsWithHoistablesMarker.js +0 -1
  244. package/dist/development/markers/EntityFieldsWithHoistablesMarker.js.map +1 -1
  245. package/dist/development/markers/EntityListSubTreeMarker.js +8 -4
  246. package/dist/development/markers/EntityListSubTreeMarker.js.map +1 -1
  247. package/dist/development/markers/EntitySubTreeMarker.js +8 -4
  248. package/dist/development/markers/EntitySubTreeMarker.js.map +1 -1
  249. package/dist/development/markers/FieldMarker.js +8 -4
  250. package/dist/development/markers/FieldMarker.js.map +1 -1
  251. package/dist/development/markers/HasManyRelationMarker.js +9 -5
  252. package/dist/development/markers/HasManyRelationMarker.js.map +1 -1
  253. package/dist/development/markers/HasOneRelationMarker.js +8 -4
  254. package/dist/development/markers/HasOneRelationMarker.js.map +1 -1
  255. package/dist/development/markers/MarkerTreeRoot.js +0 -1
  256. package/dist/development/markers/MarkerTreeRoot.js.map +1 -1
  257. package/dist/development/markers/ParentEntityMarker.js +0 -1
  258. package/dist/development/markers/ParentEntityMarker.js.map +1 -1
  259. package/dist/development/markers/PlaceholderGenerator.js +1 -3
  260. package/dist/development/markers/PlaceholderGenerator.js.map +1 -1
  261. package/dist/development/queryLanguage/CacheStore.js +10 -4
  262. package/dist/development/queryLanguage/CacheStore.js.map +1 -1
  263. package/dist/development/queryLanguage/MarkerFactory.js +15 -16
  264. package/dist/development/queryLanguage/MarkerFactory.js.map +1 -1
  265. package/dist/development/queryLanguage/Parser.js +572 -547
  266. package/dist/development/queryLanguage/Parser.js.map +1 -1
  267. package/dist/development/queryLanguage/QueryLanguage.js +32 -27
  268. package/dist/development/queryLanguage/QueryLanguage.js.map +1 -1
  269. package/dist/development/queryLanguage/QueryLanguageError.js +0 -1
  270. package/dist/development/queryLanguage/QueryLanguageError.js.map +1 -1
  271. package/dist/development/queryLanguage/tokenList.js +6 -3
  272. package/dist/development/queryLanguage/tokenList.js.map +1 -1
  273. package/dist/development/structures/BijectiveIndexedMap.js +14 -9
  274. package/dist/development/structures/BijectiveIndexedMap.js.map +1 -1
  275. package/dist/development/structures/LRUCache.js +7 -2
  276. package/dist/development/structures/LRUCache.js.map +1 -1
  277. package/dist/development/structures/WeakIdCache.js +11 -4
  278. package/dist/development/structures/WeakIdCache.js.map +1 -1
  279. package/dist/development/treeParameterHelpers/wrapFilterInHasOnes.js +1 -3
  280. package/dist/development/treeParameterHelpers/wrapFilterInHasOnes.js.map +1 -1
  281. package/dist/development/treeParameters/EntityCreationParameters.js +0 -1
  282. package/dist/development/treeParameters/EntityCreationParameters.js.map +1 -1
  283. package/dist/development/treeParameters/EntityListPreferences.js +0 -1
  284. package/dist/development/treeParameters/EntityListPreferences.js.map +1 -1
  285. package/dist/development/treeParameters/EventListenersStore.js +0 -1
  286. package/dist/development/treeParameters/EventListenersStore.js.map +1 -1
  287. package/dist/development/treeParameters/LeafField.js +0 -1
  288. package/dist/development/treeParameters/LeafField.js.map +1 -1
  289. package/dist/development/treeParameters/QualifiedEntityParameters.js +0 -1
  290. package/dist/development/treeParameters/QualifiedEntityParameters.js.map +1 -1
  291. package/dist/development/treeParameters/Relation.js +0 -1
  292. package/dist/development/treeParameters/Relation.js.map +1 -1
  293. package/dist/development/utils/Hashing.js +0 -1
  294. package/dist/development/utils/Hashing.js.map +1 -1
  295. package/dist/development/utils/assert.js +1 -3
  296. package/dist/development/utils/assert.js.map +1 -1
  297. package/dist/development/utils/assertNever.js +2 -4
  298. package/dist/development/utils/assertNever.js.map +1 -1
  299. package/dist/development/utils/generateEnumerabilityPreventingEntropy.js +0 -1
  300. package/dist/development/utils/generateEnumerabilityPreventingEntropy.js.map +1 -1
  301. package/dist/development/utils/isEmptyObject.js +0 -1
  302. package/dist/development/utils/isEmptyObject.js.map +1 -1
  303. package/dist/development/utils/ucfirst.js +0 -1
  304. package/dist/development/utils/ucfirst.js.map +1 -1
  305. package/dist/production/BindingError.js.map +1 -1
  306. package/dist/production/accessorPropagation/AccessorProvider.js.map +1 -1
  307. package/dist/production/accessorPropagation/BindingOperationsContext.js.map +1 -1
  308. package/dist/production/accessorPropagation/BindingOperationsProvider.js.map +1 -1
  309. package/dist/production/accessorPropagation/EntityKeyContext.js.map +1 -1
  310. package/dist/production/accessorPropagation/EntityKeyProvider.js.map +1 -1
  311. package/dist/production/accessorPropagation/EnvironmentContext.js.map +1 -1
  312. package/dist/production/accessorPropagation/TreeRootIdContext.js.map +1 -1
  313. package/dist/production/accessorPropagation/TreeRootIdProvider.js.map +1 -1
  314. package/dist/production/accessorPropagation/useAccessorUpdateSubscription.js.map +1 -1
  315. package/dist/production/accessorPropagation/useBindingOperations.js.map +1 -1
  316. package/dist/production/accessorPropagation/useDesugaredRelativeEntityList.js.map +1 -1
  317. package/dist/production/accessorPropagation/useDesugaredRelativeSingleEntity.js.map +1 -1
  318. package/dist/production/accessorPropagation/useDesugaredRelativeSingleField.js.map +1 -1
  319. package/dist/production/accessorPropagation/useEntity.js.map +1 -1
  320. package/dist/production/accessorPropagation/useEntityKey.js.map +1 -1
  321. package/dist/production/accessorPropagation/useEntityList.js.map +1 -1
  322. package/dist/production/accessorPropagation/useEntityListSubTree.js.map +1 -1
  323. package/dist/production/accessorPropagation/useEntityListSubTreeParameters.js.map +1 -1
  324. package/dist/production/accessorPropagation/useEntitySubTree.js.map +1 -1
  325. package/dist/production/accessorPropagation/useEntitySubTreeParameters.js.map +1 -1
  326. package/dist/production/accessorPropagation/useEnvironment.js.map +1 -1
  327. package/dist/production/accessorPropagation/useField.js.map +1 -1
  328. package/dist/production/accessorPropagation/useGetEntityByKey.js.map +1 -1
  329. package/dist/production/accessorPropagation/useGetEntityListSubTree.js.map +1 -1
  330. package/dist/production/accessorPropagation/useGetEntitySubTree.js.map +1 -1
  331. package/dist/production/accessorPropagation/useGetTreeFilters.js.map +1 -1
  332. package/dist/production/accessorPropagation/useHasEntity.js.map +1 -1
  333. package/dist/production/accessorPropagation/usePersist.js.map +1 -1
  334. package/dist/production/accessorPropagation/useTreeRootId.js.map +1 -1
  335. package/dist/production/accessorSorting/SetOrderFieldOnCreate.js.map +1 -1
  336. package/dist/production/accessorSorting/addEntityAtIndex.js.map +1 -1
  337. package/dist/production/accessorSorting/errors.js.map +1 -1
  338. package/dist/production/accessorSorting/moveEntity.js.map +1 -1
  339. package/dist/production/accessorSorting/repairEntitiesOrder.js.map +1 -1
  340. package/dist/production/accessorSorting/sortEntities.js.map +1 -1
  341. package/dist/production/accessorSorting/useSortedEntities.js.map +1 -1
  342. package/dist/production/accessorTree/AccessorTree.js.map +1 -1
  343. package/dist/production/accessorTree/DirtinessContext.js.map +1 -1
  344. package/dist/production/accessorTree/MutationStateContext.js.map +1 -1
  345. package/dist/production/accessorTree/NormalizedPersistedData.js.map +1 -1
  346. package/dist/production/accessorTree/RuntimeId.js.map +1 -1
  347. package/dist/production/accessorTree/accessorTreeStateReducer.js.map +1 -1
  348. package/dist/production/accessorTree/metadataToRequestError.js.map +1 -1
  349. package/dist/production/accessorTree/useDataBinding.js.map +1 -1
  350. package/dist/production/accessorTree/useDirtinessState.js.map +1 -1
  351. package/dist/production/accessorTree/useMutationState.js.map +1 -1
  352. package/dist/production/accessors/EntityAccessor.js.map +1 -1
  353. package/dist/production/accessors/EntityListAccessor.js.map +1 -1
  354. package/dist/production/accessors/ErrorAccessor.js.map +1 -1
  355. package/dist/production/accessors/FieldAccessor.js.map +1 -1
  356. package/dist/production/accessors/TreeRootAccessor.js.map +1 -1
  357. package/dist/production/bindingTypes.js.map +1 -1
  358. package/dist/production/core/AccessorErrorManager.js.map +1 -1
  359. package/dist/production/core/Config.js.map +1 -1
  360. package/dist/production/core/DataBinding.js +22 -11
  361. package/dist/production/core/DataBinding.js.map +1 -1
  362. package/dist/production/core/DirtinessTracker.js.map +1 -1
  363. package/dist/production/core/ErrorsPreprocessor.js.map +1 -1
  364. package/dist/production/core/EventManager.js.map +1 -1
  365. package/dist/production/core/IncrementalMarkerBuilder.js.map +1 -1
  366. package/dist/production/core/MarkerComparator.js +1 -1
  367. package/dist/production/core/MarkerComparator.js.map +1 -1
  368. package/dist/production/core/MarkerMerger.js +1 -4
  369. package/dist/production/core/MarkerMerger.js.map +1 -1
  370. package/dist/production/core/MarkerTreeGenerator.js.map +1 -1
  371. package/dist/production/core/MutationGenerator.js.map +1 -1
  372. package/dist/production/core/QueryGenerator.js.map +1 -1
  373. package/dist/production/core/RealmKeyGenerator.js.map +1 -1
  374. package/dist/production/core/RequestResponseNormalizer.js.map +1 -1
  375. package/dist/production/core/StateInitializer.js +1 -3
  376. package/dist/production/core/StateInitializer.js.map +1 -1
  377. package/dist/production/core/TreeAugmenter.js.map +1 -1
  378. package/dist/production/core/TreeFilterGenerator.js.map +1 -1
  379. package/dist/production/core/TreeParameterMerger.js.map +1 -1
  380. package/dist/production/core/TreeStore.js.map +1 -1
  381. package/dist/production/core/VariableInputTransformer.js +4 -1
  382. package/dist/production/core/VariableInputTransformer.js.map +1 -1
  383. package/dist/production/core/exceptions/ErrorLocator.js.map +1 -1
  384. package/dist/production/core/exceptions/LocalizedBindingError.js.map +1 -1
  385. package/dist/production/core/exceptions/MarkerSugarer.js.map +1 -1
  386. package/dist/production/core/exceptions/TreeParameterSugarer.js.map +1 -1
  387. package/dist/production/core/factories/createBatchUpdatesOptions.js.map +1 -1
  388. package/dist/production/core/operations/EntityOperations.js +1 -1
  389. package/dist/production/core/operations/EntityOperations.js.map +1 -1
  390. package/dist/production/core/operations/FieldOperations.js.map +1 -1
  391. package/dist/production/core/operations/ListOperations.js.map +1 -1
  392. package/dist/production/core/operations/OperationsHelpers.js.map +1 -1
  393. package/dist/production/core/requestAliases/MutationAlias.js.map +1 -1
  394. package/dist/production/core/requestAliases/mutationOperationSubTreeType.js.map +1 -1
  395. package/dist/production/core/requestAliases/mutationOperationType.js.map +1 -1
  396. package/dist/production/core/schema/Schema.js +3 -0
  397. package/dist/production/core/schema/Schema.js.map +1 -1
  398. package/dist/production/core/schema/SchemaLoader.js.map +1 -1
  399. package/dist/production/core/schema/SchemaPreprocessor.js.map +1 -1
  400. package/dist/production/core/state/StateIterator.js.map +1 -1
  401. package/dist/production/core/state/getEntityMarker.js.map +1 -1
  402. package/dist/production/core/utils/getCombinedSignal.js.map +1 -1
  403. package/dist/production/coreComponents/Component.js.map +1 -1
  404. package/dist/production/coreComponents/DataBindingProvider.js.map +1 -1
  405. package/dist/production/coreComponents/Entity.js.map +1 -1
  406. package/dist/production/coreComponents/EntityList.js.map +1 -1
  407. package/dist/production/coreComponents/EntityListSubTree.js +4 -12
  408. package/dist/production/coreComponents/EntityListSubTree.js.map +1 -1
  409. package/dist/production/coreComponents/EntitySubTree.js +4 -22
  410. package/dist/production/coreComponents/EntitySubTree.js.map +1 -1
  411. package/dist/production/coreComponents/Field.js +5 -1
  412. package/dist/production/coreComponents/Field.js.map +1 -1
  413. package/dist/production/coreComponents/HasMany.js +3 -5
  414. package/dist/production/coreComponents/HasMany.js.map +1 -1
  415. package/dist/production/coreComponents/HasOne.js +3 -5
  416. package/dist/production/coreComponents/HasOne.js.map +1 -1
  417. package/dist/production/coreComponents/ParentEntity.js.map +1 -1
  418. package/dist/production/dao/Environment.js +147 -94
  419. package/dist/production/dao/Environment.js.map +1 -1
  420. package/dist/production/dao/TreeNodeEnvironmentFactory.js +159 -0
  421. package/dist/production/dao/TreeNodeEnvironmentFactory.js.map +1 -0
  422. package/dist/production/dao/VariableFieldValue.js.map +1 -1
  423. package/dist/production/entityEvents/useDerivedField.js.map +1 -1
  424. package/dist/production/entityEvents/useEntityBeforePersist.js.map +1 -1
  425. package/dist/production/entityEvents/useEntityBeforeUpdate.js.map +1 -1
  426. package/dist/production/entityEvents/useEntityEvent.js.map +1 -1
  427. package/dist/production/entityEvents/useEntityPersistError.js.map +1 -1
  428. package/dist/production/entityEvents/useEntityPersistSuccess.js.map +1 -1
  429. package/dist/production/entityEvents/useOnConnectionUpdate.js.map +1 -1
  430. package/dist/production/fieldHelpers/helpers/FieldHelper.js.map +1 -1
  431. package/dist/production/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -1
  432. package/dist/production/fieldHelpers/helpers/UuidFieldHelper.js.map +1 -1
  433. package/dist/production/helperComponents/DeferredSubTrees.js.map +1 -1
  434. package/dist/production/helperComponents/EntityView.js.map +1 -1
  435. package/dist/production/helperComponents/FieldView.js.map +1 -1
  436. package/dist/production/helperComponents/StaticRender.js.map +1 -1
  437. package/dist/production/helperComponents/SugaredField.js.map +1 -1
  438. package/dist/production/index.js +1 -1
  439. package/dist/production/markers/EntityFieldMarkersContainer.js.map +1 -1
  440. package/dist/production/markers/EntityFieldsWithHoistablesMarker.js.map +1 -1
  441. package/dist/production/markers/EntityListSubTreeMarker.js.map +1 -1
  442. package/dist/production/markers/EntitySubTreeMarker.js.map +1 -1
  443. package/dist/production/markers/FieldMarker.js.map +1 -1
  444. package/dist/production/markers/HasManyRelationMarker.js.map +1 -1
  445. package/dist/production/markers/HasOneRelationMarker.js.map +1 -1
  446. package/dist/production/markers/MarkerTreeRoot.js.map +1 -1
  447. package/dist/production/markers/ParentEntityMarker.js.map +1 -1
  448. package/dist/production/markers/PlaceholderGenerator.js.map +1 -1
  449. package/dist/production/queryLanguage/CacheStore.js.map +1 -1
  450. package/dist/production/queryLanguage/MarkerFactory.js +4 -3
  451. package/dist/production/queryLanguage/MarkerFactory.js.map +1 -1
  452. package/dist/production/queryLanguage/Parser.js +24 -7
  453. package/dist/production/queryLanguage/Parser.js.map +1 -1
  454. package/dist/production/queryLanguage/QueryLanguage.js.map +1 -1
  455. package/dist/production/queryLanguage/QueryLanguageError.js.map +1 -1
  456. package/dist/production/queryLanguage/tokenList.js +5 -0
  457. package/dist/production/queryLanguage/tokenList.js.map +1 -1
  458. package/dist/production/structures/BijectiveIndexedMap.js.map +1 -1
  459. package/dist/production/structures/LRUCache.js.map +1 -1
  460. package/dist/production/structures/WeakIdCache.js.map +1 -1
  461. package/dist/production/treeParameterHelpers/wrapFilterInHasOnes.js.map +1 -1
  462. package/dist/production/treeParameters/EntityCreationParameters.js.map +1 -1
  463. package/dist/production/treeParameters/EntityListPreferences.js.map +1 -1
  464. package/dist/production/treeParameters/EventListenersStore.js.map +1 -1
  465. package/dist/production/treeParameters/LeafField.js.map +1 -1
  466. package/dist/production/treeParameters/QualifiedEntityParameters.js.map +1 -1
  467. package/dist/production/treeParameters/Relation.js.map +1 -1
  468. package/dist/production/utils/Hashing.js.map +1 -1
  469. package/dist/production/utils/assert.js.map +1 -1
  470. package/dist/production/utils/assertNever.js +1 -1
  471. package/dist/production/utils/assertNever.js.map +1 -1
  472. package/dist/production/utils/generateEnumerabilityPreventingEntropy.js.map +1 -1
  473. package/dist/production/utils/isEmptyObject.js.map +1 -1
  474. package/dist/production/utils/ucfirst.js.map +1 -1
  475. package/dist/types/accessorTree/MutationRequestResponse.d.ts +4 -0
  476. package/dist/types/accessorTree/MutationRequestResponse.d.ts.map +1 -1
  477. package/dist/types/accessorTree/QueryRequestResponse.d.ts +4 -0
  478. package/dist/types/accessorTree/QueryRequestResponse.d.ts.map +1 -1
  479. package/dist/types/accessorTree/RequestError.d.ts +9 -1
  480. package/dist/types/accessorTree/RequestError.d.ts.map +1 -1
  481. package/dist/types/core/DataBinding.d.ts +1 -0
  482. package/dist/types/core/DataBinding.d.ts.map +1 -1
  483. package/dist/types/core/MarkerMerger.d.ts.map +1 -1
  484. package/dist/types/core/StateInitializer.d.ts.map +1 -1
  485. package/dist/types/core/VariableInputTransformer.d.ts.map +1 -1
  486. package/dist/types/core/schema/Schema.d.ts +2 -0
  487. package/dist/types/core/schema/Schema.d.ts.map +1 -1
  488. package/dist/types/core/schema/index.d.ts +0 -1
  489. package/dist/types/core/schema/index.d.ts.map +1 -1
  490. package/dist/types/coreComponents/EntityListSubTree.d.ts +1 -1
  491. package/dist/types/coreComponents/EntityListSubTree.d.ts.map +1 -1
  492. package/dist/types/coreComponents/EntitySubTree.d.ts +1 -1
  493. package/dist/types/coreComponents/EntitySubTree.d.ts.map +1 -1
  494. package/dist/types/coreComponents/Field.d.ts.map +1 -1
  495. package/dist/types/coreComponents/HasMany.d.ts +1 -1
  496. package/dist/types/coreComponents/HasMany.d.ts.map +1 -1
  497. package/dist/types/coreComponents/HasOne.d.ts +1 -1
  498. package/dist/types/coreComponents/HasOne.d.ts.map +1 -1
  499. package/dist/types/dao/Environment.d.ts +82 -43
  500. package/dist/types/dao/Environment.d.ts.map +1 -1
  501. package/dist/types/dao/TreeNodeEnvironmentFactory.d.ts +19 -0
  502. package/dist/types/dao/TreeNodeEnvironmentFactory.d.ts.map +1 -0
  503. package/dist/types/queryLanguage/MarkerFactory.d.ts.map +1 -1
  504. package/dist/types/queryLanguage/Parser.d.ts +1 -0
  505. package/dist/types/queryLanguage/Parser.d.ts.map +1 -1
  506. package/dist/types/queryLanguage/tokenList.d.ts +1 -0
  507. package/dist/types/queryLanguage/tokenList.d.ts.map +1 -1
  508. package/dist/types/tsconfig.tsbuildinfo +1 -1
  509. package/package.json +13 -10
  510. package/src/accessorTree/MutationRequestResponse.ts +1 -0
  511. package/src/accessorTree/QueryRequestResponse.ts +1 -0
  512. package/src/accessorTree/RequestError.ts +7 -1
  513. package/src/core/DataBinding.ts +27 -28
  514. package/src/core/MarkerMerger.ts +1 -4
  515. package/src/core/StateInitializer.ts +1 -3
  516. package/src/core/VariableInputTransformer.ts +7 -4
  517. package/src/core/schema/Schema.ts +5 -0
  518. package/src/core/schema/index.ts +0 -1
  519. package/src/coreComponents/EntityListSubTree.tsx +5 -16
  520. package/src/coreComponents/EntitySubTree.tsx +17 -32
  521. package/src/coreComponents/Field.tsx +4 -0
  522. package/src/coreComponents/HasMany.tsx +4 -6
  523. package/src/coreComponents/HasOne.tsx +6 -7
  524. package/src/dao/Environment.ts +221 -126
  525. package/src/dao/TreeNodeEnvironmentFactory.ts +228 -0
  526. package/src/queryLanguage/MarkerFactory.ts +5 -3
  527. package/src/queryLanguage/Parser.ts +36 -12
  528. package/src/queryLanguage/tokenList.ts +6 -0
  529. package/src/tsconfig.json +1 -1
  530. package/src/utils/assertNever.ts +1 -1
  531. package/dist/development/core/schema/SchemaValidator.js +0 -118
  532. package/dist/development/core/schema/SchemaValidator.js.map +0 -1
  533. package/dist/types/core/schema/SchemaValidator.d.ts +0 -14
  534. package/dist/types/core/schema/SchemaValidator.d.ts.map +0 -1
  535. package/src/core/schema/SchemaValidator.ts +0 -238
@@ -1 +1 @@
1
- {"version":3,"file":"AccessorErrorManager.js","sources":["../../../src/core/AccessorErrorManager.ts"],"sourcesContent":["import { ErrorAccessor } from '../accessors'\nimport type { ExecutionError, MutationDataResponse, ValidationError } from '../accessorTree'\nimport { ErrorsPreprocessor } from './ErrorsPreprocessor'\nimport { EventManager } from './EventManager'\nimport { EntityListState, EntityRealmState, getEntityMarker, StateNode } from './state'\nimport type { TreeStore } from './TreeStore'\n\nexport class AccessorErrorManager {\n\tprivate errorsByState: Map<StateNode, ErrorAccessor.ErrorsById> = new Map()\n\n\tprivate getNewErrorId = (() => {\n\t\tlet errorId = 1\n\n\t\treturn () => errorId++\n\t})()\n\n\tpublic constructor(private readonly eventManager: EventManager, private readonly treeStore: TreeStore) {}\n\n\tpublic hasErrors() {\n\t\treturn !!this.errorsByState.size\n\t}\n\n\tpublic getErrors(): ErrorAccessor.Error[] {\n\t\treturn Array.from(this.errorsByState.values(), it => Array.from(it.values())).flat()\n\t}\n\n\tpublic clearErrors() {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tfor (const [stateNode] of this.errorsByState) {\n\t\t\t\tstateNode.errors = undefined\n\t\t\t\tthis.eventManager.registerJustUpdated(stateNode, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t}\n\t\t\tthis.errorsByState.clear()\n\t\t})\n\t}\n\n\tpublic clearErrorsByState(state: StateNode): void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tif (!this.errorsByState.has(state)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.errorsByState.delete(state)\n\t\t\tstate.errors = undefined\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t})\n\t}\n\n\tpublic replaceErrors(data: MutationDataResponse) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.clearErrors()\n\n\t\t\tconst preprocessor = new ErrorsPreprocessor(data)\n\t\t\tconst errorTreeRoot = preprocessor.preprocess()\n\n\t\t\tthis.setRootStateErrors(errorTreeRoot)\n\n\t\t\tthis.dumpErrorData(data)\n\t\t})\n\t}\n\n\tpublic addError(state: StateNode, error: ErrorAccessor.Error): () => void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tconst errorId = this.getNewErrorId()\n\n\t\t\tlet errorsById: ErrorAccessor.ErrorsById | undefined = this.errorsByState.get(state)\n\t\t\tif (errorsById === undefined) {\n\t\t\t\tthis.errorsByState.set(state, (errorsById = new Map()))\n\t\t\t}\n\t\t\terrorsById.set(errorId, error)\n\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\n\t\t\treturn () =>\n\t\t\t\tthis.eventManager.syncOperation(() => {\n\t\t\t\t\tconst errorsById = this.errorsByState.get(state)\n\t\t\t\t\tif (errorsById === undefined) {\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\terrorsById.delete(errorId)\n\t\t\t\t\tif (errorsById.size) {\n\t\t\t\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstate.errors = undefined\n\t\t\t\t\t\tthis.errorsByState.delete(state)\n\t\t\t\t\t}\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t})\n\t\t})\n\t}\n\n\tprivate addSeveralErrors(state: StateNode, errors: ErrorsPreprocessor.BaseErrorNode) {\n\t\tif (errors.validation) {\n\t\t\tfor (const error of errors.validation) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t\tif (errors.execution) {\n\t\t\tfor (const error of errors.execution) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setRootStateErrors(errorTreeRoot: ErrorsPreprocessor.ErrorTreeRoot) {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [subTreePlaceholder, rootError] of errorTreeRoot) {\n\t\t\t\tconst rootState = rootStates.get(subTreePlaceholder)\n\n\t\t\t\tif (!rootState) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (rootState.type) {\n\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\tthis.setEntityStateErrors(rootState, rootError)\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\tthis.setEntityListStateErrors(rootState, rootError)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityStateErrors(\n\t\tstate: EntityRealmState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, child] of errors.children) {\n\t\t\tif (child.nodeType === 'leaf') {\n\t\t\t\tconst fieldState = state.children.get(childKey)\n\n\t\t\t\tif (fieldState?.type === 'field') {\n\t\t\t\t\tthis.addSeveralErrors(fieldState, child)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Deliberately letting flow get here as well. Leaf errors *CAN* refer to relations as well.\n\n\t\t\tconst fields = getEntityMarker(state).fields\n\t\t\tconst placeholders = fields.placeholders.get(childKey)\n\t\t\tif (placeholders === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst normalizedPlaceholders = typeof placeholders === 'string' ? new Set([placeholders]) : placeholders\n\n\t\t\tfor (const normalizedPlaceholder of normalizedPlaceholders) {\n\t\t\t\tconst fieldState = state.children.get(normalizedPlaceholder)\n\t\t\t\tif (fieldState === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (fieldState.type) {\n\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\t\tthis.setEntityStateErrors(fieldState, child)\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\tthis.setEntityListStateErrors(fieldState, child)\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityListStateErrors(\n\t\tstate: EntityListState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, childError] of errors.children) {\n\t\t\tlet childState = state.children.get(childKey)\n\n\t\t\tif (childState === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (childState.type === 'entityRealmStub') {\n\t\t\t\tchildState.getAccessor() // Force init\n\t\t\t\tchildState = state.children.get(childKey)!\n\t\t\t}\n\n\t\t\tif (childError.nodeType === 'iNode') {\n\t\t\t\tthis.setEntityStateErrors(childState as EntityRealmState, childError)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate dumpErrorData(data: MutationDataResponse) {\n\t\t// TODO this is just temporary\n\t\tfor (const subTreePlaceholder in data) {\n\t\t\tconst treeDatum = data[subTreePlaceholder]\n\t\t\tconst executionErrors: Array<ExecutionError | ValidationError> = treeDatum.errors\n\t\t\tconst allErrors = treeDatum?.validation?.errors\n\t\t\t\t? executionErrors.concat(treeDatum.validation.errors)\n\t\t\t\t: executionErrors\n\t\t\tconst normalizedErrors = allErrors.map((error: ExecutionError | ValidationError) => {\n\t\t\t\treturn {\n\t\t\t\t\tpath: error.path\n\t\t\t\t\t\t.map(pathPart => {\n\t\t\t\t\t\t\tif (pathPart.__typename === '_FieldPathFragment') {\n\t\t\t\t\t\t\t\treturn pathPart.field\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (pathPart.alias) {\n\t\t\t\t\t\t\t\treturn `#${pathPart.index}(${pathPart.alias})`\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn pathPart.index\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.join('.'),\n\t\t\t\t\ttype: 'type' in error ? error.type : undefined,\n\t\t\t\t\tmessage: typeof error.message === 'string' ? error.message : error.message?.text,\n\t\t\t\t}\n\t\t\t})\n\t\t\tif (Object.keys(normalizedErrors).length) {\n\t\t\t\tconsole.table(normalizedErrors)\n\t\t\t}\n\t\t\tif (treeDatum.errorMessage) {\n\t\t\t\tconsole.error(treeDatum.errorMessage)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;2BAOkC;AAAA,EAS1B,YAA6B,cAA6C,WAAsB;AAR/F,6DAA8D;AAE9D,gDAAuB;UAC1B,UAAU;aAEP,MAAM;AAAA;;;;EAKP,YAAY;WACX,CAAC,CAAC,KAAK,cAAc;AAAA;AAAA,EAGtB,YAAmC;WAClC,MAAM,KAAK,KAAK,cAAc,UAAU,QAAM,MAAM,KAAK,GAAG,WAAW;AAAA;AAAA,EAGxE,cAAc;SACf,aAAa,cAAc,MAAM;iBAC1B,CAAC,cAAc,KAAK,eAAe;kBACnC,SAAS;aACd,aAAa,oBAAoB,WAAW,aAAa;AAAA;WAE1D,cAAc;AAAA;AAAA;AAAA,EAId,mBAAmB,OAAwB;WAC1C,KAAK,aAAa,cAAc,MAAM;UACxC,CAAC,KAAK,cAAc,IAAI,QAAQ;;;WAG/B,cAAc,OAAO;YACpB,SAAS;WACV,aAAa,oBAAoB,OAAO,aAAa;AAAA;AAAA;AAAA,EAIrD,cAAc,MAA4B;SAC3C,aAAa,cAAc,MAAM;WAChC;YAEC,eAAe,IAAI,mBAAmB;YACtC,gBAAgB,aAAa;WAE9B,mBAAmB;WAEnB,cAAc;AAAA;AAAA;AAAA,EAId,SAAS,OAAkB,OAAwC;WAClE,KAAK,aAAa,cAAc,MAAM;YACtC,UAAU,KAAK;UAEjB,aAAmD,KAAK,cAAc,IAAI;UAC1E,eAAe,QAAW;aACxB,cAAc,IAAI,OAAQ,iCAAiB;AAAA;iBAEtC,IAAI,SAAS;YAClB,SAAS,IAAI,cAAc,MAAM,KAAK,WAAW;WAClD,aAAa,oBAAoB,OAAO,aA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AiB,OAAO;QAEzB,OAAO,aAAa,SAAS;;;eAItB,CAAC,UAAU,eAAe,OAAO,UAAU;UACjD,aAAa,MAAM,SAAS,IAAI;UAEhC,eAAe,QAAW;;;UAG1B,WAAW,SAAS,mBAAmB;mBAC/B;qBACE,MAAM,SAAS,IAAI;AAAA;UAG7B,WAAW,aAAa,SAAS;aAC/B,qBAAqB,YAAgC;AAAA;AAAA;AAAA;AAAA,EAKrD,cAAc,MAA4B;eAEtC,sBAAsB,MAAM;YAChC,YAAY,KAAK;YACjB,kBAA2D,UAAU;YACrE,YAAY,WAAW,YAAY,SACtC,gBAAgB,OAAO,UAAU,WAAW,UAC5C;YACG,mBAAmB,UAAU,IAAI,CAAC,UAA4C;eAC5E;AAAA,UACN,MAAM,MAAM,KACV,IAAI,cAAY;gBACZ,SAAS,eAAe,sBAAsB;qBAC1C,SAAS;AAAA;gBAEb,SAAS,OAAO;qBACZ,IAAI,SAAS,SAAS,SAAS;AAAA;mBAEhC,SAAS;AAAA,aAEhB,KAAK;AAAA,UACP,MAAM,UAAU,QAAQ,MAAM,OAAO;AAAA,UACrC,SAAS,OAAO,MAAM,YAAY,WAAW,MAAM,UAAU,MAAM,SAAS;AAAA;AAAA;UAG1E,OAAO,KAAK,kBAAkB,QAAQ;gBACjC,MAAM;AAAA;UAEX,UAAU,cAAc;gBACnB,MAAM,UAAU;AAAA;AAAA;AAAA;AAAA;;"}
1
+ {"version":3,"file":"AccessorErrorManager.js","sources":["../../../src/core/AccessorErrorManager.ts"],"sourcesContent":["import { ErrorAccessor } from '../accessors'\nimport type { ExecutionError, MutationDataResponse, ValidationError } from '../accessorTree'\nimport { ErrorsPreprocessor } from './ErrorsPreprocessor'\nimport { EventManager } from './EventManager'\nimport { EntityListState, EntityRealmState, getEntityMarker, StateNode } from './state'\nimport type { TreeStore } from './TreeStore'\n\nexport class AccessorErrorManager {\n\tprivate errorsByState: Map<StateNode, ErrorAccessor.ErrorsById> = new Map()\n\n\tprivate getNewErrorId = (() => {\n\t\tlet errorId = 1\n\n\t\treturn () => errorId++\n\t})()\n\n\tpublic constructor(private readonly eventManager: EventManager, private readonly treeStore: TreeStore) {}\n\n\tpublic hasErrors() {\n\t\treturn !!this.errorsByState.size\n\t}\n\n\tpublic getErrors(): ErrorAccessor.Error[] {\n\t\treturn Array.from(this.errorsByState.values(), it => Array.from(it.values())).flat()\n\t}\n\n\tpublic clearErrors() {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tfor (const [stateNode] of this.errorsByState) {\n\t\t\t\tstateNode.errors = undefined\n\t\t\t\tthis.eventManager.registerJustUpdated(stateNode, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t}\n\t\t\tthis.errorsByState.clear()\n\t\t})\n\t}\n\n\tpublic clearErrorsByState(state: StateNode): void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tif (!this.errorsByState.has(state)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.errorsByState.delete(state)\n\t\t\tstate.errors = undefined\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t})\n\t}\n\n\tpublic replaceErrors(data: MutationDataResponse) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.clearErrors()\n\n\t\t\tconst preprocessor = new ErrorsPreprocessor(data)\n\t\t\tconst errorTreeRoot = preprocessor.preprocess()\n\n\t\t\tthis.setRootStateErrors(errorTreeRoot)\n\n\t\t\tthis.dumpErrorData(data)\n\t\t})\n\t}\n\n\tpublic addError(state: StateNode, error: ErrorAccessor.Error): () => void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tconst errorId = this.getNewErrorId()\n\n\t\t\tlet errorsById: ErrorAccessor.ErrorsById | undefined = this.errorsByState.get(state)\n\t\t\tif (errorsById === undefined) {\n\t\t\t\tthis.errorsByState.set(state, (errorsById = new Map()))\n\t\t\t}\n\t\t\terrorsById.set(errorId, error)\n\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\n\t\t\treturn () =>\n\t\t\t\tthis.eventManager.syncOperation(() => {\n\t\t\t\t\tconst errorsById = this.errorsByState.get(state)\n\t\t\t\t\tif (errorsById === undefined) {\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\terrorsById.delete(errorId)\n\t\t\t\t\tif (errorsById.size) {\n\t\t\t\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstate.errors = undefined\n\t\t\t\t\t\tthis.errorsByState.delete(state)\n\t\t\t\t\t}\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t})\n\t\t})\n\t}\n\n\tprivate addSeveralErrors(state: StateNode, errors: ErrorsPreprocessor.BaseErrorNode) {\n\t\tif (errors.validation) {\n\t\t\tfor (const error of errors.validation) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t\tif (errors.execution) {\n\t\t\tfor (const error of errors.execution) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setRootStateErrors(errorTreeRoot: ErrorsPreprocessor.ErrorTreeRoot) {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [subTreePlaceholder, rootError] of errorTreeRoot) {\n\t\t\t\tconst rootState = rootStates.get(subTreePlaceholder)\n\n\t\t\t\tif (!rootState) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (rootState.type) {\n\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\tthis.setEntityStateErrors(rootState, rootError)\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\tthis.setEntityListStateErrors(rootState, rootError)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityStateErrors(\n\t\tstate: EntityRealmState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, child] of errors.children) {\n\t\t\tif (child.nodeType === 'leaf') {\n\t\t\t\tconst fieldState = state.children.get(childKey)\n\n\t\t\t\tif (fieldState?.type === 'field') {\n\t\t\t\t\tthis.addSeveralErrors(fieldState, child)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Deliberately letting flow get here as well. Leaf errors *CAN* refer to relations as well.\n\n\t\t\tconst fields = getEntityMarker(state).fields\n\t\t\tconst placeholders = fields.placeholders.get(childKey)\n\t\t\tif (placeholders === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst normalizedPlaceholders = typeof placeholders === 'string' ? new Set([placeholders]) : placeholders\n\n\t\t\tfor (const normalizedPlaceholder of normalizedPlaceholders) {\n\t\t\t\tconst fieldState = state.children.get(normalizedPlaceholder)\n\t\t\t\tif (fieldState === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (fieldState.type) {\n\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\t\tthis.setEntityStateErrors(fieldState, child)\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\tthis.setEntityListStateErrors(fieldState, child)\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityListStateErrors(\n\t\tstate: EntityListState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, childError] of errors.children) {\n\t\t\tlet childState = state.children.get(childKey)\n\n\t\t\tif (childState === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (childState.type === 'entityRealmStub') {\n\t\t\t\tchildState.getAccessor() // Force init\n\t\t\t\tchildState = state.children.get(childKey)!\n\t\t\t}\n\n\t\t\tif (childError.nodeType === 'iNode') {\n\t\t\t\tthis.setEntityStateErrors(childState as EntityRealmState, childError)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate dumpErrorData(data: MutationDataResponse) {\n\t\t// TODO this is just temporary\n\t\tfor (const subTreePlaceholder in data) {\n\t\t\tconst treeDatum = data[subTreePlaceholder]\n\t\t\tconst executionErrors: Array<ExecutionError | ValidationError> = treeDatum.errors\n\t\t\tconst allErrors = treeDatum?.validation?.errors\n\t\t\t\t? executionErrors.concat(treeDatum.validation.errors)\n\t\t\t\t: executionErrors\n\t\t\tconst normalizedErrors = allErrors.map((error: ExecutionError | ValidationError) => {\n\t\t\t\treturn {\n\t\t\t\t\tpath: error.path\n\t\t\t\t\t\t.map(pathPart => {\n\t\t\t\t\t\t\tif (pathPart.__typename === '_FieldPathFragment') {\n\t\t\t\t\t\t\t\treturn pathPart.field\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (pathPart.alias) {\n\t\t\t\t\t\t\t\treturn `#${pathPart.index}(${pathPart.alias})`\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn pathPart.index\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.join('.'),\n\t\t\t\t\ttype: 'type' in error ? error.type : undefined,\n\t\t\t\t\tmessage: typeof error.message === 'string' ? error.message : error.message?.text,\n\t\t\t\t}\n\t\t\t})\n\t\t\tif (Object.keys(normalizedErrors).length) {\n\t\t\t\tconsole.table(normalizedErrors)\n\t\t\t}\n\t\t\tif (treeDatum.errorMessage) {\n\t\t\t\tconsole.error(treeDatum.errorMessage)\n\t\t\t}\n\t\t}\n\t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A,WAAW,aAAa,SAAS;AAC/B,aAAA,qBAAqB,YAAgC,UAAU;AAAA,MACrE;AAAA,IACD;AAAA,EACD;AAAA,EAEQ,cAAc,MAA4B;AAEjD,eAAW,sBAAsB,MAAM;AACtC,YAAM,YAAY,KAAK;AACvB,YAAM,kBAA2D,UAAU;AACrE,YAAA,YAAY,WAAW,YAAY,SACtC,gBAAgB,OAAO,UAAU,WAAW,MAAM,IAClD;AACH,YAAM,mBAAmB,UAAU,IAAI,CAAC,UAA4C;AAC5E,eAAA;AAAA,UACN,MAAM,MAAM,KACV,IAAI,CAAY,aAAA;AACZ,gBAAA,SAAS,eAAe,sBAAsB;AACjD,qBAAO,SAAS;AAAA,YACjB;AACA,gBAAI,SAAS,OAAO;AACZ,qBAAA,IAAI,SAAS,SAAS,SAAS;AAAA,YACvC;AACA,mBAAO,SAAS;AAAA,UAAA,CAChB,EACA,KAAK,GAAG;AAAA,UACV,MAAM,UAAU,QAAQ,MAAM,OAAO;AAAA,UACrC,SAAS,OAAO,MAAM,YAAY,WAAW,MAAM,UAAU,MAAM,SAAS;AAAA,QAAA;AAAA,MAC7E,CACA;AACD,UAAI,OAAO,KAAK,gBAAgB,EAAE,QAAQ;AACzC,gBAAQ,MAAM,gBAAgB;AAAA,MAC/B;AACA,UAAI,UAAU,cAAc;AACnB,gBAAA,MAAM,UAAU,YAAY;AAAA,MACrC;AAAA,IACD;AAAA,EACD;AACD;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"Config.js","sources":["../../../src/core/Config.ts"],"sourcesContent":["import type { BindingConfig } from '../accessors'\n\nexport class Config {\n\tprivate static defaultConfig: BindingConfig = {\n\t\tbeforePersistSettleLimit: 20,\n\t\tbeforeUpdateSettleLimit: 20,\n\t\tpersistSuccessSettleLimit: 20,\n\t\tmaxPersistAttempts: 5,\n\t\tmaxSchemaLoadAttempts: 3,\n\t}\n\n\tprivate readonly config: BindingConfig\n\n\tpublic constructor(config: Partial<BindingConfig> = {}) {\n\t\tthis.config = {\n\t\t\t...Config.defaultConfig,\n\t\t\t...config,\n\t\t}\n\t}\n\n\tpublic getValue<Name extends keyof BindingConfig>(name: Name): BindingConfig[Name] {\n\t\treturn this.config[name]\n\t}\n\n\tpublic setValue<Name extends keyof BindingConfig>(name: Name, value: BindingConfig[Name]): this {\n\t\tthis.config[name] = value\n\t\treturn this\n\t}\n}\n"],"names":[],"mappings":";;;;;;sBAEoB;AAAA,EAWZ,YAAY,SAAiC,IAAI;AAFvC;SAGX,SAAS;AAAA,SACV,QAAO;AAAA,SACP;AAAA;AAAA;AAAA,EAIE,SAA2C,MAAiC;WAC3E,KAAK,OAAO;AAAA;AAAA,EAGb,SAA2C,MAAY,OAAkC;SAC1F,OAAO,QAAQ;WACb;AAAA;AAAA;;AAvBO,sBAAA,iBAA+B;AAAA,EAC7C,0BAA0B;AAAA,EAC1B,yBAAyB;AAAA,EACzB,2BAA2B;AAAA,EAC3B,oBAAoB;AAAA,EACpB,uBAAuB;AAAA;;"}
1
+ {"version":3,"file":"Config.js","sources":["../../../src/core/Config.ts"],"sourcesContent":["import type { BindingConfig } from '../accessors'\n\nexport class Config {\n\tprivate static defaultConfig: BindingConfig = {\n\t\tbeforePersistSettleLimit: 20,\n\t\tbeforeUpdateSettleLimit: 20,\n\t\tpersistSuccessSettleLimit: 20,\n\t\tmaxPersistAttempts: 5,\n\t\tmaxSchemaLoadAttempts: 3,\n\t}\n\n\tprivate readonly config: BindingConfig\n\n\tpublic constructor(config: Partial<BindingConfig> = {}) {\n\t\tthis.config = {\n\t\t\t...Config.defaultConfig,\n\t\t\t...config,\n\t\t}\n\t}\n\n\tpublic getValue<Name extends keyof BindingConfig>(name: Name): BindingConfig[Name] {\n\t\treturn this.config[name]\n\t}\n\n\tpublic setValue<Name extends keyof BindingConfig>(name: Name, value: BindingConfig[Name]): this {\n\t\tthis.config[name] = value\n\t\treturn this\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAEO,sBAAa;AAAA,EAWZ,YAAY,SAAiC,IAAI;AAFvC;AAGhB,SAAK,SAAS;AAAA,SACV,QAAO;AAAA,SACP;AAAA,IAAA;AAAA,EAEL;AAAA,EAEO,SAA2C,MAAiC;AAClF,WAAO,KAAK,OAAO;AAAA,EACpB;AAAA,EAEO,SAA2C,MAAY,OAAkC;AAC/F,SAAK,OAAO,QAAQ;AACb,WAAA;AAAA,EACR;AACD;AA1BO;AACS,cADT,QACS,iBAA+B;AAAA,EAC7C,0BAA0B;AAAA,EAC1B,yBAAyB;AAAA,EACzB,2BAA2B;AAAA,EAC3B,oBAAoB;AAAA,EACpB,uBAAuB;AAAA;;"}
@@ -117,6 +117,13 @@ const _DataBinding = class {
117
117
  const mutationResponse = await this.contentApiClient.sendRequest(mutation, {
118
118
  signal
119
119
  });
120
+ if (mutationResponse.errors !== void 0 && mutationResponse.errors.length > 0) {
121
+ this.onError({
122
+ type: "gqlError",
123
+ query: mutation,
124
+ errors: mutationResponse.errors
125
+ });
126
+ }
120
127
  const mutationData = mutationResponse.data?.transaction ?? {};
121
128
  const aliases = Object.keys(mutationData);
122
129
  if (!mutationResponse.data) {
@@ -181,12 +188,12 @@ const _DataBinding = class {
181
188
  }
182
189
  async extendTree(newFragment, options = {}) {
183
190
  if (options.signal?.aborted) {
184
- return Promise.reject();
191
+ return Promise.reject(DataBindingExtendAborted);
185
192
  }
186
- const markerTreeRoot = new MarkerTreeGenerator(newFragment, options.environment ?? this.environment).generate();
193
+ const schema = await this.getOrLoadSchema();
194
+ this.treeStore.setSchema(schema);
195
+ const markerTreeRoot = new MarkerTreeGenerator(newFragment, (options.environment ?? this.environment).withSchema(schema)).generate();
187
196
  if (this.treeStore.effectivelyHasTreeRoot(markerTreeRoot)) {
188
- const schema = await this.getOrLoadSchema();
189
- this.treeStore.setSchema(schema);
190
197
  return this.eventManager.syncOperation(() => {
191
198
  const newTreeRootId = this.getNewTreeRootId();
192
199
  this.treeAugmenter.extendTreeStates(newTreeRootId, markerTreeRoot);
@@ -199,7 +206,7 @@ const _DataBinding = class {
199
206
  newFragment,
200
207
  newTreeRootId: this.getNewTreeRootId(),
201
208
  options,
202
- reject,
209
+ reject: () => reject(DataBindingExtendAborted),
203
210
  resolve
204
211
  });
205
212
  const pendingExtensionsCount = this.pendingExtensions.size;
@@ -230,11 +237,7 @@ const _DataBinding = class {
230
237
  return;
231
238
  }
232
239
  const aggregateSignal = getCombinedSignal(pendingExtensions.map((extension) => extension.options.signal));
233
- const [aggregatePersistedData, schema] = await Promise.all([
234
- this.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal),
235
- this.getOrLoadSchema()
236
- ]);
237
- this.treeStore.setSchema(schema);
240
+ const aggregatePersistedData = await this.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal);
238
241
  if (aggregateSignal?.aborted) {
239
242
  return;
240
243
  }
@@ -260,6 +263,13 @@ const _DataBinding = class {
260
263
  }
261
264
  this.onError(metadataToRequestError(metadata));
262
265
  }
266
+ if (queryResponse && queryResponse.errors !== void 0 && queryResponse.errors.length > 0) {
267
+ this.onError({
268
+ type: "gqlError",
269
+ query: query ?? "unknown query",
270
+ errors: queryResponse.errors
271
+ });
272
+ }
263
273
  return queryResponse;
264
274
  }
265
275
  resetTreeAfterSuccessfulPersist() {
@@ -321,5 +331,6 @@ __publicField(DataBinding, "getNextTreeRootIdSeed", (() => {
321
331
  let seed = 1;
322
332
  return () => seed++;
323
333
  })());
324
- export { DataBinding };
334
+ const DataBindingExtendAborted = Symbol("aborted");
335
+ export { DataBinding, DataBindingExtendAborted };
325
336
  //# sourceMappingURL=DataBinding.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DataBinding.js","sources":["../../../src/core/DataBinding.ts"],"sourcesContent":["import type { GraphQlClient, GraphQlClientFailedRequestMetadata, TreeFilter } from '@contember/client'\nimport type { ReactNode } from 'react'\nimport {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tBindingOperations,\n\tExtendTreeOptions,\n\tPersistErrorOptions,\n\tPersistSuccessOptions,\n\tTreeRootAccessor,\n} from '../accessors'\nimport {\n\tmetadataToRequestError,\n\tMutationRequestResponse,\n\tQueryRequestResponse,\n\tRequestError,\n\tSuccessfulPersistResult,\n} from '../accessorTree'\nimport type { Environment } from '../dao'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { TreeRootId } from '../treeParameters'\nimport { assertNever, generateEnumerabilityPreventingEntropy } from '../utils'\nimport { AccessorErrorManager } from './AccessorErrorManager'\nimport { Config } from './Config'\nimport { DirtinessTracker } from './DirtinessTracker'\nimport { EventManager } from './EventManager'\nimport { createBatchUpdatesOptions } from './factories'\nimport { MarkerMerger } from './MarkerMerger'\nimport { MarkerTreeGenerator } from './MarkerTreeGenerator'\nimport { MutationGenerator } from './MutationGenerator'\nimport { QueryGenerator } from './QueryGenerator'\nimport { Schema, SchemaLoader, SchemaValidator } from './schema'\nimport { StateIterator } from './state'\nimport { StateInitializer } from './StateInitializer'\nimport { TreeAugmenter } from './TreeAugmenter'\nimport { TreeFilterGenerator } from './TreeFilterGenerator'\nimport { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport { getCombinedSignal } from './utils'\n\nexport class DataBinding {\n\tprivate static readonly schemaLoadCache: Map<string, Schema | Promise<Schema>> = new Map()\n\n\tprivate readonly accessorErrorManager: AccessorErrorManager\n\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions\n\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions\n\tprivate readonly bindingOperations: BindingOperations\n\tprivate readonly config: Config\n\tprivate readonly dirtinessTracker: DirtinessTracker\n\tprivate readonly eventManager: EventManager\n\tprivate readonly stateInitializer: StateInitializer\n\tprivate readonly treeAugmenter: TreeAugmenter\n\tprivate readonly treeStore: TreeStore\n\n\t// private treeRootListeners: {\n\t// \teventListeners: {}\n\t// } = {\n\t// \teventListeners: {},\n\t// }\n\n\tpublic constructor(\n\t\tprivate readonly contentApiClient: GraphQlClient,\n\t\tprivate readonly systemApiClient: GraphQlClient,\n\t\tprivate readonly tenantApiClient: GraphQlClient,\n\t\tprivate readonly environment: Environment,\n\t\tprivate readonly onUpdate: (newData: TreeRootAccessor) => void,\n\t\tprivate readonly onError: (error: RequestError) => void,\n\t\tprivate readonly onPersistSuccess: (result: SuccessfulPersistResult) => void,\n\t) {\n\t\tthis.config = new Config()\n\t\tthis.treeStore = new TreeStore()\n\t\tthis.batchUpdatesOptions = createBatchUpdatesOptions(environment, this.treeStore)\n\t\tthis.asyncBatchUpdatesOptions = {\n\t\t\t...this.batchUpdatesOptions,\n\t\t\tcontentClient: contentApiClient,\n\t\t\tsystemClient: systemApiClient,\n\t\t\ttenantClient: tenantApiClient,\n\t\t}\n\t\tthis.dirtinessTracker = new DirtinessTracker()\n\t\tthis.eventManager = new EventManager(\n\t\t\tthis.asyncBatchUpdatesOptions,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.config,\n\t\t\tthis.dirtinessTracker,\n\t\t\tthis.resolvedOnUpdate,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.accessorErrorManager = new AccessorErrorManager(this.eventManager, this.treeStore)\n\t\tthis.stateInitializer = new StateInitializer(\n\t\t\tthis.accessorErrorManager,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.config,\n\t\t\tthis.eventManager,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.treeAugmenter = new TreeAugmenter(this.eventManager, this.stateInitializer, this.treeStore)\n\n\t\t// TODO move this elsewhere\n\t\tthis.bindingOperations = Object.freeze<BindingOperations>({\n\t\t\t...this.asyncBatchUpdatesOptions,\n\t\t\tgetTreeFilters: (): TreeFilter[] => {\n\t\t\t\tconst generator = new TreeFilterGenerator(this.treeStore)\n\t\t\t\treturn generator.generateTreeFilter()\n\t\t\t},\n\t\t\tbatchDeferredUpdates: performUpdates => {\n\t\t\t\tthis.eventManager.syncTransaction(() => performUpdates(this.bindingOperations))\n\t\t\t},\n\t\t\textendTree: async (...args) => await this.extendTree(...args),\n\t\t\tpersist: async ({ signal, onPersistSuccess, onPersistError } = {}) =>\n\t\t\t\tawait this.eventManager.persistOperation(async () => {\n\t\t\t\t\tfor (let attemptNumber = 1; attemptNumber <= this.config.getValue('maxPersistAttempts'); attemptNumber++) {\n\t\t\t\t\t\t// TODO if the tree is in an inconsistent state, wait for lock releases\n\n\t\t\t\t\t\tthis.eventManager.syncTransaction(() => {\n\t\t\t\t\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\t\t\t\t})\n\t\t\t\t\t\tawait this.eventManager.triggerOnBeforePersist()\n\n\t\t\t\t\t\tlet shouldTryAgain = false\n\t\t\t\t\t\tconst proposedBackOffs: number[] = []\n\t\t\t\t\t\tconst persistErrorOptions: PersistErrorOptions = {\n\t\t\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\t\t\ttryAgain: options => {\n\t\t\t\t\t\t\t\tshouldTryAgain = true\n\t\t\t\t\t\t\t\tif (options?.proposedBackoff !== undefined && options.proposedBackoff > 0) {\n\t\t\t\t\t\t\t\t\tproposedBackOffs.push(options.proposedBackoff)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tattemptNumber,\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (this.accessorErrorManager.hasErrors()) {\n\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistError(persistErrorOptions)\n\t\t\t\t\t\t\tawait onPersistError?.(persistErrorOptions)\n\n\t\t\t\t\t\t\tif (shouldTryAgain) {\n\t\t\t\t\t\t\t\tcontinue // Trying again immediately\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tthrow {\n\t\t\t\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst generator = new MutationGenerator(this.treeStore)\n\t\t\t\t\t\tconst mutation = generator.getPersistMutation()\n\n\t\t\t\t\t\tif (mutation === undefined) {\n\t\t\t\t\t\t\tthis.dirtinessTracker.reset() // TODO This ideally shouldn't be necessary but given the current limitations, this makes for better UX.\n\t\t\t\t\t\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\t\t\t\tsuccessType: 'nothingToPersist',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\t\t\t\t\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\ttype: 'nothingToPersist',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst mutationResponse: MutationRequestResponse = await this.contentApiClient.sendRequest(mutation, {\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t})\n\t\t\t\t\t\tconst mutationData = mutationResponse.data?.transaction ?? {}\n\t\t\t\t\t\tconst aliases = Object.keys(mutationData)\n\t\t\t\t\t\tif (!mutationResponse.data) {\n\t\t\t\t\t\t\tthrow {\n\t\t\t\t\t\t\t\terrors: mutationData.errors,\n\t\t\t\t\t\t\t\ttype: 'invalidResponse',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else if (aliases.every(item => mutationData[item].ok)) {\n\t\t\t\t\t\t\tconst persistedEntityIds = aliases.map(alias => mutationData[alias].node?.id).filter(id => id !== undefined)\n\t\t\t\t\t\t\tconst result: SuccessfulPersistResult = {\n\t\t\t\t\t\t\t\ttype: 'justSuccess',\n\t\t\t\t\t\t\t\tpersistedEntityIds,\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tawait this.eventManager.asyncTransaction(async () => {\n\t\t\t\t\t\t\t\t\tthis.resetTreeAfterSuccessfulPersist()\n\t\t\t\t\t\t\t\t\tthis.treeAugmenter.updatePersistedData(\n\t\t\t\t\t\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\t\t\t\t\t\tObject.entries(mutationData).map(([placeholderName, subTreeResponse]) => [\n\t\t\t\t\t\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t\t\t\t\t\tsubTreeResponse.node,\n\t\t\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t\t\t\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\t\t\t\t\t\tsuccessType: result.type,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\t\t\t\t\t\t\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\n\t\t\t\t\t\t\t\t\tthis.treeAugmenter.resetCreatingSubTrees()\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\t\tconsole.error(e)\n\t\t\t\t\t\t\t\tconst resultWithError = {\n\t\t\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\t\t\tafterPersistError: e,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tthis.onPersistSuccess(resultWithError)\n\t\t\t\t\t\t\t\treturn resultWithError\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthis.onPersistSuccess(result)\n\t\t\t\t\t\t\treturn result\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(mutationData))\n\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistError(persistErrorOptions)\n\t\t\t\t\t\t\tawait onPersistError?.(persistErrorOptions)\n\t\t\t\t\t\t\tif (shouldTryAgain) {\n\t\t\t\t\t\t\t\tif (proposedBackOffs.length) {\n\t\t\t\t\t\t\t\t\tconst geometricMean = Math.round(\n\t\t\t\t\t\t\t\t\t\tMath.pow(\n\t\t\t\t\t\t\t\t\t\t\tproposedBackOffs.reduce((a, b) => a * b, 1),\n\t\t\t\t\t\t\t\t\t\t\t1 / proposedBackOffs.length,\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tawait new Promise(resolve => setTimeout(resolve, geometricMean))\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow {\n\t\t\t\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// Max attempts exceeded\n\t\t\t\t\t// TODO fire persist error\n\t\t\t\t\tthrow {\n\t\t\t\t\t\ttype: 'givenUp',\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t})\n\t}\n\n\tprivate resolvedOnUpdate = ({ isMutating }: UpdateMetadata) => {\n\t\tthis.onUpdate(new TreeRootAccessor(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations))\n\t}\n\n\t// This is currently useless but potentially future-compatible\n\t// private readonly addTreeRootEventListener: TreeRootAccessor.AddTreeRootEventListener = this.getAddEventListener(\n\t// \tthis.treeRootListeners,\n\t// )\n\n\tprivate pendingExtensions: Set<{\n\t\tmarkerTreeRoot: MarkerTreeRoot\n\t\tnewFragment: ReactNode\n\t\tnewTreeRootId: TreeRootId | undefined\n\t\toptions: ExtendTreeOptions\n\t\treject: () => void\n\t\tresolve: (newRootId: TreeRootId | undefined) => void\n\t}> = new Set()\n\n\tpublic async extendTree(newFragment: ReactNode, options: ExtendTreeOptions = {}): Promise<TreeRootId | undefined> {\n\t\tif (options.signal?.aborted) {\n\t\t\treturn Promise.reject()\n\t\t}\n\t\tconst markerTreeRoot = new MarkerTreeGenerator(newFragment, options.environment ?? this.environment).generate()\n\n\t\tif (this.treeStore.effectivelyHasTreeRoot(markerTreeRoot)) {\n\t\t\t// This isn't perfectly accurate as theoretically, we could already have all the data necessary but this\n\t\t\t// could still be false.\n\n\t\t\tconst schema = await this.getOrLoadSchema()\n\t\t\tthis.treeStore.setSchema(schema)\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t// For most trees, checking this against the schema should be unnecessary since if we already effectively\n\t\t\t\t// have this tree root, then assuming everything we already have is valid, this should match the schema as well.\n\t\t\t\t// However, we might be dealing with an isCreating tree root which is completely new. Also, we can just lean\n\t\t\t\t// towards the safe side since developer machines can generally handle the potentially unnecessary check anyway.\n\t\t\t\tSchemaValidator.assertTreeValid(schema, markerTreeRoot)\n\t\t\t}\n\n\t\t\treturn this.eventManager.syncOperation(() => {\n\t\t\t\tconst newTreeRootId = this.getNewTreeRootId()\n\t\t\t\tthis.treeAugmenter.extendTreeStates(newTreeRootId, markerTreeRoot)\n\t\t\t\treturn newTreeRootId\n\t\t\t})\n\t\t}\n\n\t\treturn await new Promise((resolve, reject) => {\n\t\t\tthis.pendingExtensions.add({\n\t\t\t\tmarkerTreeRoot,\n\t\t\t\tnewFragment,\n\t\t\t\tnewTreeRootId: this.getNewTreeRootId(),\n\t\t\t\toptions,\n\t\t\t\treject,\n\t\t\t\tresolve,\n\t\t\t})\n\t\t\tconst pendingExtensionsCount = this.pendingExtensions.size\n\n\t\t\tPromise.resolve().then(() => {\n\t\t\t\tif (pendingExtensionsCount < this.pendingExtensions.size) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.flushBatchedTreeExtensions()\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async flushBatchedTreeExtensions() {\n\t\t// This is an async operation so we just take whatever pendingExtensions there are now and let any new ones\n\t\t// accumulate in an empty set.\n\t\tconst pendingExtensions = Array.from(this.pendingExtensions).filter(extension => {\n\t\t\tif (extension.options.signal?.aborted) {\n\t\t\t\textension.reject()\n\t\t\t\treturn false\n\t\t\t}\n\t\t\treturn true\n\t\t})\n\t\tthis.pendingExtensions.clear()\n\n\t\tconst aggregateMarkerTreeRoot = pendingExtensions.reduce<MarkerTreeRoot | undefined>(\n\t\t\t(previousValue, currentValue) => {\n\t\t\t\tif (previousValue === undefined) {\n\t\t\t\t\treturn currentValue.markerTreeRoot\n\t\t\t\t}\n\t\t\t\treturn MarkerMerger.mergeMarkerTreeRoots(previousValue, currentValue.markerTreeRoot)\n\t\t\t},\n\t\t\tundefined,\n\t\t)\n\n\t\tif (aggregateMarkerTreeRoot === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tconst aggregateSignal = getCombinedSignal(pendingExtensions.map(extension => extension.options.signal))\n\n\t\t// Even if we don't have a schema yet, we'll still optimistically fire the request so as to prevent a waterfall\n\t\t// in the most likely case that things will go fine and the query does match the schema. If it doesn't, then we\n\t\t// just get a \"400 Bad Request\" but that's not enough to make us delay the happy path.\n\t\tconst [aggregatePersistedData, schema] = await Promise.all([\n\t\t\tthis.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal),\n\t\t\tthis.getOrLoadSchema(),\n\t\t])\n\t\tthis.treeStore.setSchema(schema)\n\n\t\tif (import.meta.env.DEV) {\n\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\tSchemaValidator.assertTreeValid(schema, extension.markerTreeRoot)\n\t\t\t}\n\t\t}\n\n\t\tif (aggregateSignal?.aborted) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.treeAugmenter.extendPersistedData(aggregatePersistedData?.data ?? {})\n\n\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\tthis.treeAugmenter.extendTreeStates(extension.newTreeRootId, extension.markerTreeRoot)\n\t\t\t\textension.resolve(extension.newTreeRootId)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async fetchPersistedData(\n\t\ttree: MarkerTreeRoot,\n\t\tsignal?: AbortSignal,\n\t): Promise<QueryRequestResponse | undefined> {\n\t\tconst queryGenerator = new QueryGenerator(tree)\n\t\tconst query = queryGenerator.getReadQuery()\n\n\t\tlet queryResponse: QueryRequestResponse | undefined = undefined\n\n\t\ttry {\n\t\t\tqueryResponse =\n\t\t\t\tquery === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: await this.contentApiClient.sendRequest(query, {\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t })\n\t\t} catch (metadata) {\n\t\t\tif (metadata.name === 'AbortError') {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.onError(metadataToRequestError(metadata as GraphQlClientFailedRequestMetadata))\n\t\t}\n\t\treturn queryResponse\n\t}\n\n\tprivate resetTreeAfterSuccessfulPersist() {\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\tthis.dirtinessTracker.reset()\n\n\t\t\tfor (const [, rootState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const state of StateIterator.depthFirstAllNodes(rootState)) {\n\t\t\t\t\tswitch (state.type) {\n\t\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\t\tif (state.hasUnpersistedChanges || state.touchLog?.size) {\n\t\t\t\t\t\t\t\tstate.touchLog?.clear()\n\t\t\t\t\t\t\t\tstate.hasUnpersistedChanges = false\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedRemovals?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedRemovals?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedHasOneDeletions?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedHasOneDeletions?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tassertNever(state)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate getOrLoadSchema(): Schema | Promise<Schema> {\n\t\tconst existing = DataBinding.schemaLoadCache.get(this.contentApiClient.apiUrl)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\n\t\tconst schemaPromise = SchemaLoader.loadSchema(this.contentApiClient, this.config.getValue('maxSchemaLoadAttempts'))\n\t\tschemaPromise.then(schema => {\n\t\t\tDataBinding.schemaLoadCache.set(this.contentApiClient.apiUrl, schema)\n\t\t})\n\t\tDataBinding.schemaLoadCache.set(this.contentApiClient.apiUrl, schemaPromise)\n\t\treturn schemaPromise\n\t}\n\n\tprivate static getNextTreeRootIdSeed = (() => {\n\t\tlet seed = 1\n\t\treturn () => seed++\n\t})()\n\n\tprivate getNewTreeRootId() {\n\t\t// TODO this is an awful, awful hack.\n\t\t// TODO the particular shape of the alias is relied on in MutationAlias. If you change this, change it there too.\n\t\treturn this.treeStore.markerTrees.size === 0\n\t\t\t? undefined\n\t\t\t: `${generateEnumerabilityPreventingEntropy()}-${DataBinding.getNextTreeRootIdSeed()}`\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;2BAwCyB;AAAA,EAoBjB,YACW,kBACA,iBACA,iBACA,aACA,UACA,SACA,kBAChB;AAzBe;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AA6LT,4CAAmB,CAAC,EAAE,iBAAiC;WACzD,SAAS,IAAI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C;UAC7C,WAAW,aAAY,gBAAgB,IAAI,KAAK,iBAAiB;QACnE,aAAa,QAAW;aACpB;AAAA;UAGF,gBAAgB,aAAa,WAAW,KAAK,kBAAkB,KAAK,OAAO,SAAS;kBAC5E,KAAK,YAAU;mBAChB,gBAAgB,IAAI,KAAK,iBAAiB,QAAQ;AAAA;iBAEnD,gBAAgB,IAAI,KAAK,iBAAiB,QAAQ;WACvD;AAAA;AAAA,EAQA,mBAAmB;WAGnB,KAAK,UAAU,YAAY,SAAS,IACxC,SACA,GAAG,4CAA4C,aAAY;AAAA;AAAA;;AA1ZvC,2BAAA,uCAA6D;AAgZtE,2BAAA,gCAA+B;MACzC,OAAO;SACJ,MAAM;AAAA;;"}
1
+ {"version":3,"file":"DataBinding.js","sources":["../../../src/core/DataBinding.ts"],"sourcesContent":["import type { GraphQlClient, GraphQlClientFailedRequestMetadata, TreeFilter } from '@contember/client'\nimport type { ReactNode } from 'react'\nimport {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tBindingOperations,\n\tExtendTreeOptions,\n\tPersistErrorOptions,\n\tPersistSuccessOptions,\n\tTreeRootAccessor,\n} from '../accessors'\nimport {\n\tmetadataToRequestError,\n\tMutationRequestResponse,\n\tQueryRequestResponse,\n\tRequestError,\n\tSuccessfulPersistResult,\n} from '../accessorTree'\nimport type { Environment } from '../dao'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { TreeRootId } from '../treeParameters'\nimport { assertNever, generateEnumerabilityPreventingEntropy } from '../utils'\nimport { AccessorErrorManager } from './AccessorErrorManager'\nimport { Config } from './Config'\nimport { DirtinessTracker } from './DirtinessTracker'\nimport { EventManager } from './EventManager'\nimport { createBatchUpdatesOptions } from './factories'\nimport { MarkerMerger } from './MarkerMerger'\nimport { MarkerTreeGenerator } from './MarkerTreeGenerator'\nimport { MutationGenerator } from './MutationGenerator'\nimport { QueryGenerator } from './QueryGenerator'\nimport { Schema, SchemaLoader } from './schema'\nimport { StateIterator } from './state'\nimport { StateInitializer } from './StateInitializer'\nimport { TreeAugmenter } from './TreeAugmenter'\nimport { TreeFilterGenerator } from './TreeFilterGenerator'\nimport { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport { getCombinedSignal } from './utils'\n\nexport class DataBinding {\n\tprivate static readonly schemaLoadCache: Map<string, Schema | Promise<Schema>> = new Map()\n\n\tprivate readonly accessorErrorManager: AccessorErrorManager\n\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions\n\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions\n\tprivate readonly bindingOperations: BindingOperations\n\tprivate readonly config: Config\n\tprivate readonly dirtinessTracker: DirtinessTracker\n\tprivate readonly eventManager: EventManager\n\tprivate readonly stateInitializer: StateInitializer\n\tprivate readonly treeAugmenter: TreeAugmenter\n\tprivate readonly treeStore: TreeStore\n\n\t// private treeRootListeners: {\n\t// \teventListeners: {}\n\t// } = {\n\t// \teventListeners: {},\n\t// }\n\n\tpublic constructor(\n\t\tprivate readonly contentApiClient: GraphQlClient,\n\t\tprivate readonly systemApiClient: GraphQlClient,\n\t\tprivate readonly tenantApiClient: GraphQlClient,\n\t\tprivate readonly environment: Environment,\n\t\tprivate readonly onUpdate: (newData: TreeRootAccessor) => void,\n\t\tprivate readonly onError: (error: RequestError) => void,\n\t\tprivate readonly onPersistSuccess: (result: SuccessfulPersistResult) => void,\n\t) {\n\t\tthis.config = new Config()\n\t\tthis.treeStore = new TreeStore()\n\t\tthis.batchUpdatesOptions = createBatchUpdatesOptions(environment, this.treeStore)\n\t\tthis.asyncBatchUpdatesOptions = {\n\t\t\t...this.batchUpdatesOptions,\n\t\t\tcontentClient: contentApiClient,\n\t\t\tsystemClient: systemApiClient,\n\t\t\ttenantClient: tenantApiClient,\n\t\t}\n\t\tthis.dirtinessTracker = new DirtinessTracker()\n\t\tthis.eventManager = new EventManager(\n\t\t\tthis.asyncBatchUpdatesOptions,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.config,\n\t\t\tthis.dirtinessTracker,\n\t\t\tthis.resolvedOnUpdate,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.accessorErrorManager = new AccessorErrorManager(this.eventManager, this.treeStore)\n\t\tthis.stateInitializer = new StateInitializer(\n\t\t\tthis.accessorErrorManager,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.config,\n\t\t\tthis.eventManager,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.treeAugmenter = new TreeAugmenter(this.eventManager, this.stateInitializer, this.treeStore)\n\n\t\t// TODO move this elsewhere\n\t\tthis.bindingOperations = Object.freeze<BindingOperations>({\n\t\t\t...this.asyncBatchUpdatesOptions,\n\t\t\tgetTreeFilters: (): TreeFilter[] => {\n\t\t\t\tconst generator = new TreeFilterGenerator(this.treeStore)\n\t\t\t\treturn generator.generateTreeFilter()\n\t\t\t},\n\t\t\tbatchDeferredUpdates: performUpdates => {\n\t\t\t\tthis.eventManager.syncTransaction(() => performUpdates(this.bindingOperations))\n\t\t\t},\n\t\t\textendTree: async (...args) => await this.extendTree(...args),\n\t\t\tpersist: async ({ signal, onPersistSuccess, onPersistError } = {}) =>\n\t\t\t\tawait this.eventManager.persistOperation(async () => {\n\t\t\t\t\tfor (let attemptNumber = 1; attemptNumber <= this.config.getValue('maxPersistAttempts'); attemptNumber++) {\n\t\t\t\t\t\t// TODO if the tree is in an inconsistent state, wait for lock releases\n\n\t\t\t\t\t\tthis.eventManager.syncTransaction(() => {\n\t\t\t\t\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\t\t\t\t})\n\t\t\t\t\t\tawait this.eventManager.triggerOnBeforePersist()\n\n\t\t\t\t\t\tlet shouldTryAgain = false\n\t\t\t\t\t\tconst proposedBackOffs: number[] = []\n\t\t\t\t\t\tconst persistErrorOptions: PersistErrorOptions = {\n\t\t\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\t\t\ttryAgain: options => {\n\t\t\t\t\t\t\t\tshouldTryAgain = true\n\t\t\t\t\t\t\t\tif (options?.proposedBackoff !== undefined && options.proposedBackoff > 0) {\n\t\t\t\t\t\t\t\t\tproposedBackOffs.push(options.proposedBackoff)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tattemptNumber,\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (this.accessorErrorManager.hasErrors()) {\n\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistError(persistErrorOptions)\n\t\t\t\t\t\t\tawait onPersistError?.(persistErrorOptions)\n\n\t\t\t\t\t\t\tif (shouldTryAgain) {\n\t\t\t\t\t\t\t\tcontinue // Trying again immediately\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tthrow {\n\t\t\t\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst generator = new MutationGenerator(this.treeStore)\n\t\t\t\t\t\tconst mutation = generator.getPersistMutation()\n\n\t\t\t\t\t\tif (mutation === undefined) {\n\t\t\t\t\t\t\tthis.dirtinessTracker.reset() // TODO This ideally shouldn't be necessary but given the current limitations, this makes for better UX.\n\t\t\t\t\t\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\t\t\t\tsuccessType: 'nothingToPersist',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\t\t\t\t\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\ttype: 'nothingToPersist',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst mutationResponse: MutationRequestResponse = await this.contentApiClient.sendRequest(mutation, {\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t})\n\n\t\t\t\t\t\tif (mutationResponse.errors !== undefined && mutationResponse.errors.length > 0) {\n\t\t\t\t\t\t\tthis.onError({\n\t\t\t\t\t\t\t\ttype: 'gqlError',\n\t\t\t\t\t\t\t\tquery: mutation,\n\t\t\t\t\t\t\t\terrors: mutationResponse.errors,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst mutationData = mutationResponse.data?.transaction ?? {}\n\t\t\t\t\t\tconst aliases = Object.keys(mutationData)\n\t\t\t\t\t\tif (!mutationResponse.data) {\n\t\t\t\t\t\t\tthrow {\n\t\t\t\t\t\t\t\terrors: mutationData.errors,\n\t\t\t\t\t\t\t\ttype: 'invalidResponse',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else if (aliases.every(item => mutationData[item].ok)) {\n\t\t\t\t\t\t\tconst persistedEntityIds = aliases.map(alias => mutationData[alias].node?.id).filter(id => id !== undefined)\n\t\t\t\t\t\t\tconst result: SuccessfulPersistResult = {\n\t\t\t\t\t\t\t\ttype: 'justSuccess',\n\t\t\t\t\t\t\t\tpersistedEntityIds,\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tawait this.eventManager.asyncTransaction(async () => {\n\t\t\t\t\t\t\t\t\tthis.resetTreeAfterSuccessfulPersist()\n\t\t\t\t\t\t\t\t\tthis.treeAugmenter.updatePersistedData(\n\t\t\t\t\t\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\t\t\t\t\t\tObject.entries(mutationData).map(([placeholderName, subTreeResponse]) => [\n\t\t\t\t\t\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t\t\t\t\t\tsubTreeResponse.node,\n\t\t\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t\t\t\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\t\t\t\t\t\tsuccessType: result.type,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\t\t\t\t\t\t\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\n\t\t\t\t\t\t\t\t\tthis.treeAugmenter.resetCreatingSubTrees()\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\t\tconsole.error(e)\n\t\t\t\t\t\t\t\tconst resultWithError = {\n\t\t\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\t\t\tafterPersistError: e,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tthis.onPersistSuccess(resultWithError)\n\t\t\t\t\t\t\t\treturn resultWithError\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthis.onPersistSuccess(result)\n\t\t\t\t\t\t\treturn result\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(mutationData))\n\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistError(persistErrorOptions)\n\t\t\t\t\t\t\tawait onPersistError?.(persistErrorOptions)\n\t\t\t\t\t\t\tif (shouldTryAgain) {\n\t\t\t\t\t\t\t\tif (proposedBackOffs.length) {\n\t\t\t\t\t\t\t\t\tconst geometricMean = Math.round(\n\t\t\t\t\t\t\t\t\t\tMath.pow(\n\t\t\t\t\t\t\t\t\t\t\tproposedBackOffs.reduce((a, b) => a * b, 1),\n\t\t\t\t\t\t\t\t\t\t\t1 / proposedBackOffs.length,\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tawait new Promise(resolve => setTimeout(resolve, geometricMean))\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow {\n\t\t\t\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// Max attempts exceeded\n\t\t\t\t\t// TODO fire persist error\n\t\t\t\t\tthrow {\n\t\t\t\t\t\ttype: 'givenUp',\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t})\n\t}\n\n\tprivate resolvedOnUpdate = ({ isMutating }: UpdateMetadata) => {\n\t\tthis.onUpdate(new TreeRootAccessor(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations))\n\t}\n\n\t// This is currently useless but potentially future-compatible\n\t// private readonly addTreeRootEventListener: TreeRootAccessor.AddTreeRootEventListener = this.getAddEventListener(\n\t// \tthis.treeRootListeners,\n\t// )\n\n\tprivate pendingExtensions: Set<{\n\t\tmarkerTreeRoot: MarkerTreeRoot\n\t\tnewFragment: ReactNode\n\t\tnewTreeRootId: TreeRootId | undefined\n\t\toptions: ExtendTreeOptions\n\t\treject: () => void\n\t\tresolve: (newRootId: TreeRootId | undefined) => void\n\t}> = new Set()\n\n\tpublic async extendTree(newFragment: ReactNode, options: ExtendTreeOptions = {}): Promise<TreeRootId | undefined> {\n\t\tif (options.signal?.aborted) {\n\t\t\treturn Promise.reject(DataBindingExtendAborted)\n\t\t}\n\t\tconst schema = await this.getOrLoadSchema()\n\t\tthis.treeStore.setSchema(schema)\n\t\tconst markerTreeRoot = new MarkerTreeGenerator(newFragment, (options.environment ?? this.environment).withSchema(schema)).generate()\n\n\t\tif (this.treeStore.effectivelyHasTreeRoot(markerTreeRoot)) {\n\t\t\t// This isn't perfectly accurate as theoretically, we could already have all the data necessary but this\n\t\t\t// could still be false.\n\n\t\t\treturn this.eventManager.syncOperation(() => {\n\t\t\t\tconst newTreeRootId = this.getNewTreeRootId()\n\t\t\t\tthis.treeAugmenter.extendTreeStates(newTreeRootId, markerTreeRoot)\n\t\t\t\treturn newTreeRootId\n\t\t\t})\n\t\t}\n\n\t\treturn await new Promise((resolve, reject) => {\n\t\t\tthis.pendingExtensions.add({\n\t\t\t\tmarkerTreeRoot,\n\t\t\t\tnewFragment,\n\t\t\t\tnewTreeRootId: this.getNewTreeRootId(),\n\t\t\t\toptions,\n\t\t\t\treject: () => reject(DataBindingExtendAborted),\n\t\t\t\tresolve,\n\t\t\t})\n\t\t\tconst pendingExtensionsCount = this.pendingExtensions.size\n\n\t\t\tPromise.resolve().then(() => {\n\t\t\t\tif (pendingExtensionsCount < this.pendingExtensions.size) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.flushBatchedTreeExtensions()\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async flushBatchedTreeExtensions() {\n\t\t// This is an async operation so we just take whatever pendingExtensions there are now and let any new ones\n\t\t// accumulate in an empty set.\n\t\tconst pendingExtensions = Array.from(this.pendingExtensions).filter(extension => {\n\t\t\tif (extension.options.signal?.aborted) {\n\t\t\t\textension.reject()\n\t\t\t\treturn false\n\t\t\t}\n\t\t\treturn true\n\t\t})\n\t\tthis.pendingExtensions.clear()\n\n\t\tconst aggregateMarkerTreeRoot = pendingExtensions.reduce<MarkerTreeRoot | undefined>(\n\t\t\t(previousValue, currentValue) => {\n\t\t\t\tif (previousValue === undefined) {\n\t\t\t\t\treturn currentValue.markerTreeRoot\n\t\t\t\t}\n\t\t\t\treturn MarkerMerger.mergeMarkerTreeRoots(previousValue, currentValue.markerTreeRoot)\n\t\t\t},\n\t\t\tundefined,\n\t\t)\n\n\t\tif (aggregateMarkerTreeRoot === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tconst aggregateSignal = getCombinedSignal(pendingExtensions.map(extension => extension.options.signal))\n\n\t\tconst aggregatePersistedData = await this.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal)\n\n\t\tif (aggregateSignal?.aborted) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.treeAugmenter.extendPersistedData(aggregatePersistedData?.data ?? {})\n\n\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\tthis.treeAugmenter.extendTreeStates(extension.newTreeRootId, extension.markerTreeRoot)\n\t\t\t\textension.resolve(extension.newTreeRootId)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async fetchPersistedData(\n\t\ttree: MarkerTreeRoot,\n\t\tsignal?: AbortSignal,\n\t): Promise<QueryRequestResponse | undefined> {\n\t\tconst queryGenerator = new QueryGenerator(tree)\n\t\tconst query = queryGenerator.getReadQuery()\n\n\t\tlet queryResponse: QueryRequestResponse | undefined = undefined\n\n\t\ttry {\n\t\t\tqueryResponse =\n\t\t\t\tquery === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: await this.contentApiClient.sendRequest(query, {\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t })\n\t\t} catch (metadata) {\n\t\t\tif (metadata.name === 'AbortError') {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.onError(metadataToRequestError(metadata as GraphQlClientFailedRequestMetadata))\n\t\t}\n\n\t\tif (queryResponse && queryResponse.errors !== undefined && queryResponse.errors.length > 0) {\n\t\t\tthis.onError({\n\t\t\t\ttype: 'gqlError',\n\t\t\t\tquery: query ?? 'unknown query',\n\t\t\t\terrors: queryResponse.errors,\n\t\t\t})\n\t\t}\n\n\t\treturn queryResponse\n\t}\n\n\tprivate resetTreeAfterSuccessfulPersist() {\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\tthis.dirtinessTracker.reset()\n\n\t\t\tfor (const [, rootState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const state of StateIterator.depthFirstAllNodes(rootState)) {\n\t\t\t\t\tswitch (state.type) {\n\t\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\t\tif (state.hasUnpersistedChanges || state.touchLog?.size) {\n\t\t\t\t\t\t\t\tstate.touchLog?.clear()\n\t\t\t\t\t\t\t\tstate.hasUnpersistedChanges = false\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedRemovals?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedRemovals?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedHasOneDeletions?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedHasOneDeletions?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tassertNever(state)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate getOrLoadSchema(): Schema | Promise<Schema> {\n\t\tconst existing = DataBinding.schemaLoadCache.get(this.contentApiClient.apiUrl)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\n\t\tconst schemaPromise = SchemaLoader.loadSchema(this.contentApiClient, this.config.getValue('maxSchemaLoadAttempts'))\n\t\tschemaPromise.then(schema => {\n\t\t\tDataBinding.schemaLoadCache.set(this.contentApiClient.apiUrl, schema)\n\t\t})\n\t\tDataBinding.schemaLoadCache.set(this.contentApiClient.apiUrl, schemaPromise)\n\t\treturn schemaPromise\n\t}\n\n\tprivate static getNextTreeRootIdSeed = (() => {\n\t\tlet seed = 1\n\t\treturn () => seed++\n\t})()\n\n\tprivate getNewTreeRootId() {\n\t\t// TODO this is an awful, awful hack.\n\t\t// TODO the particular shape of the alias is relied on in MutationAlias. If you change this, change it there too.\n\t\treturn this.treeStore.markerTrees.size === 0\n\t\t\t? undefined\n\t\t\t: `${generateEnumerabilityPreventingEntropy()}-${DataBinding.getNextTreeRootIdSeed()}`\n\t}\n}\n\nexport const DataBindingExtendAborted = Symbol('aborted')\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAwCO,2BAAkB;AAAA,EAoBjB,YACW,kBACA,iBACA,iBACA,aACA,UACA,SACA,kBAChB;AAzBe;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAsMT,4CAAmB,CAAC,EAAE,iBAAiC;AACzD,WAAA,SAAS,IAAI,iBAAiB,KAAK,iBAAiB,cAAc,YAAY,KAAK,iBAAiB,CAAC;AAAA,IAAA;AAQnG,iEAOC;AA7MS,SAAA,mBAAA;AACA,SAAA,kBAAA;AACA,SAAA,kBAAA;AACA,SAAA,cAAA;AACA,SAAA,WAAA;AACA,SAAA,UAAA;AACA,SAAA,mBAAA;AAEZ,SAAA,SAAS,IAAI;AACb,SAAA,YAAY,IAAI;AACrB,SAAK,sBAAsB,0BAA0B,aAAa,KAAK,SAAS;AAChF,SAAK,2BAA2B;AAAA,SAC5B,KAAK;AAAA,MACR,eAAe;AAAA,MACf,cAAc;AAAA,MACd,cAAc;AAAA,IAAA;AAEV,SAAA,mBAAmB,IAAI;AAC5B,SAAK,eAAe,IAAI,aACvB,KAAK,0BACL,KAAK,qBACL,KAAK,QACL,KAAK,kBACL,KAAK,kBACL,KAAK,SACN;AACA,SAAK,uBAAuB,IAAI,qBAAqB,KAAK,cAAc,KAAK,SAAS;AACtF,SAAK,mBAAmB,IAAI,iBAC3B,KAAK,sBACL,KAAK,qBACL,KAAK,QACL,KAAK,cACL,KAAK,SACN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AAoB,OAAO,aAAa,qBAAqB;AAAA,cAChF;AACA;AAAA,iBACI,eAAe;AACnB,kBAAI,MAAM,0BAA0B,KAAK,MAAM,wBAAwB,MAAM;AAC5E,sBAAM,0BAA0B;AAChC,sBAAM,wBAAwB;AAC9B,qBAAK,aAAa,oBAAoB,OAAO,aAAa,qBAAqB;AAAA,cAChF;AACA;AAAA,YACD;AAAA;AAEC,0BAAiB;AAAA;AAAA,QAEpB;AAAA,MACD;AAAA,IAAA,CACA;AAAA,EACF;AAAA,EAEQ,kBAA4C;AACnD,UAAM,WAAW,aAAY,gBAAgB,IAAI,KAAK,iBAAiB,MAAM;AAC7E,QAAI,aAAa,QAAW;AACpB,aAAA;AAAA,IACR;AAEM,UAAA,gBAAgB,aAAa,WAAW,KAAK,kBAAkB,KAAK,OAAO,SAAS,uBAAuB,CAAC;AAClH,kBAAc,KAAK,CAAU,WAAA;AAC5B,mBAAY,gBAAgB,IAAI,KAAK,iBAAiB,QAAQ,MAAM;AAAA,IAAA,CACpE;AACD,iBAAY,gBAAgB,IAAI,KAAK,iBAAiB,QAAQ,aAAa;AACpE,WAAA;AAAA,EACR;AAAA,EAOQ,mBAAmB;AAGnB,WAAA,KAAK,UAAU,YAAY,SAAS,IACxC,SACA,GAAG,uCAA4C,KAAA,aAAY,sBAAsB;AAAA,EACrF;AACD;AA1ZO;AACkB,cADlB,aACkB,uCAA6D;AA6YtE,cA9YT,aA8YS,yBAA+B,OAAA;AAC7C,MAAI,OAAO;AACX,SAAO,MAAM;AAAA;AAYF,MAAA,2BAA2B,OAAO,SAAS;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"DirtinessTracker.js","sources":["../../../src/core/DirtinessTracker.ts"],"sourcesContent":["export class DirtinessTracker {\n\tprivate changesCount = 0\n\tprivate totalChangesCount = 0\n\n\tpublic getChangesCount() {\n\t\treturn this.changesCount\n\t}\n\n\tpublic getTotalChangesCount() {\n\t\treturn this.totalChangesCount\n\t}\n\n\tpublic hasChanges() {\n\t\treturn this.changesCount > 0\n\t}\n\n\tpublic reset() {\n\t\tthis.changesCount = 0\n\t}\n\n\tpublic increment() {\n\t\tthis.totalChangesCount++\n\t\tthis.changesCount++\n\t}\n\n\tpublic decrement() {\n\t\tthis.changesCount--\n\t}\n\n\tpublic increaseBy(delta: number) {\n\t\tthis.changesCount += delta\n\t}\n}\n"],"names":[],"mappings":";;;;;;uBAA8B;AAAA;AACrB,wCAAe;AACf,6CAAoB;AAAA;AAAA,EAErB,kBAAkB;WACjB,KAAK;AAAA;AAAA,EAGN,uBAAuB;WACtB,KAAK;AAAA;AAAA,EAGN,aAAa;WACZ,KAAK,eAAe;AAAA;AAAA,EAGrB,QAAQ;SACT,eAAe;AAAA;AAAA,EAGd,YAAY;SACb;SACA;AAAA;AAAA,EAGC,YAAY;SACb;AAAA;AAAA,EAGC,WAAW,OAAe;SAC3B,gBAAgB;AAAA;AAAA;;"}
1
+ {"version":3,"file":"DirtinessTracker.js","sources":["../../../src/core/DirtinessTracker.ts"],"sourcesContent":["export class DirtinessTracker {\n\tprivate changesCount = 0\n\tprivate totalChangesCount = 0\n\n\tpublic getChangesCount() {\n\t\treturn this.changesCount\n\t}\n\n\tpublic getTotalChangesCount() {\n\t\treturn this.totalChangesCount\n\t}\n\n\tpublic hasChanges() {\n\t\treturn this.changesCount > 0\n\t}\n\n\tpublic reset() {\n\t\tthis.changesCount = 0\n\t}\n\n\tpublic increment() {\n\t\tthis.totalChangesCount++\n\t\tthis.changesCount++\n\t}\n\n\tpublic decrement() {\n\t\tthis.changesCount--\n\t}\n\n\tpublic increaseBy(delta: number) {\n\t\tthis.changesCount += delta\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAAO,MAAM,iBAAiB;AAAA,EAAvB;AACE,wCAAe;AACf,6CAAoB;AAAA;AAAA,EAErB,kBAAkB;AACxB,WAAO,KAAK;AAAA,EACb;AAAA,EAEO,uBAAuB;AAC7B,WAAO,KAAK;AAAA,EACb;AAAA,EAEO,aAAa;AACnB,WAAO,KAAK,eAAe;AAAA,EAC5B;AAAA,EAEO,QAAQ;AACd,SAAK,eAAe;AAAA,EACrB;AAAA,EAEO,YAAY;AACb,SAAA;AACA,SAAA;AAAA,EACN;AAAA,EAEO,YAAY;AACb,SAAA;AAAA,EACN;AAAA,EAEO,WAAW,OAAe;AAChC,SAAK,gBAAgB;AAAA,EACtB;AACD;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorsPreprocessor.js","sources":["../../../src/core/ErrorsPreprocessor.ts"],"sourcesContent":["import type { ErrorAccessor } from '../accessors'\nimport type { ExecutionError, MutationDataResponse, MutationResponse, ValidationError } from '../accessorTree'\nimport type { PlaceholderName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport { MutationAlias, mutationOperationSubTreeType } from './requestAliases'\n\nclass ErrorsPreprocessor {\n\tpublic constructor(private readonly requestResponse: MutationDataResponse) {}\n\n\tpublic preprocess(): ErrorsPreprocessor.ErrorTreeRoot {\n\t\tconst treeRoot: ErrorsPreprocessor.ErrorTreeRoot = new Map()\n\n\t\tif (this.requestResponse === undefined) {\n\t\t\treturn treeRoot\n\t\t}\n\n\t\tfor (const mutationAlias in this.requestResponse) {\n\t\t\tconst mutationResponse = this.requestResponse[mutationAlias]\n\t\t\tconst processedResponse = this.processMutationResponse(mutationResponse)\n\n\t\t\tif (processedResponse === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst operation = MutationAlias.decodeTopLevel(mutationAlias)\n\n\t\t\tif (operation === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst { subTreeType, subTreePlaceholder, entityId } = operation\n\n\t\t\tif (subTreeType === mutationOperationSubTreeType.singleEntity) {\n\t\t\t\tif (treeRoot.has(subTreePlaceholder)) {\n\t\t\t\t\treturn this.rejectCorruptData()\n\t\t\t\t}\n\t\t\t\ttreeRoot.set(subTreePlaceholder, processedResponse)\n\t\t\t} else if (subTreeType === mutationOperationSubTreeType.entityList) {\n\t\t\t\tconst child = treeRoot.get(subTreePlaceholder)\n\n\t\t\t\tif (child === undefined) {\n\t\t\t\t\ttreeRoot.set(subTreePlaceholder, {\n\t\t\t\t\t\tnodeType: 'iNode',\n\t\t\t\t\t\tchildren: new Map([[entityId, processedResponse]]),\n\t\t\t\t\t\tvalidation: [],\n\t\t\t\t\t\texecution: [],\n\t\t\t\t\t})\n\t\t\t\t} else if (child.nodeType === 'iNode') {\n\t\t\t\t\tchild.children.set(entityId, processedResponse)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn assertNever(subTreeType)\n\t\t\t}\n\t\t}\n\t\treturn treeRoot\n\t}\n\n\tprivate processMutationResponse(mutationResponse: MutationResponse): ErrorsPreprocessor.ErrorNode | undefined {\n\t\tif (mutationResponse.ok && mutationResponse.validation?.valid && mutationResponse.errors.length === 0) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (mutationResponse.validation?.errors.length) {\n\t\t\treturn this.getErrorNode(mutationResponse.validation?.errors)\n\t\t}\n\t\tif (mutationResponse.errors.length) {\n\t\t\treturn this.getErrorNode(mutationResponse.errors)\n\t\t}\n\t\treturn undefined\n\t}\n\n\tprivate getErrorNode(errors: ValidationError[] | ExecutionError[]): ErrorsPreprocessor.ErrorNode {\n\t\tconst [head, ...tail] = errors\n\n\t\tlet rootNode = this.getRootNode(head)\n\n\t\terrorLoop: for (const error of tail) {\n\t\t\tlet currentNode = rootNode\n\n\t\t\tfor (let i = 0, pathLength = error.path.length; i < pathLength; i++) {\n\t\t\t\tconst pathNode = error.path[i]\n\n\t\t\t\tif (currentNode.nodeType === 'leaf') {\n\t\t\t\t\t(currentNode as any as ErrorsPreprocessor.ErrorINode).nodeType = 'iNode'\n\t\t\t\t\t;(currentNode as any as ErrorsPreprocessor.ErrorINode).children = new Map()\n\t\t\t\t}\n\n\t\t\t\tif (pathNode.__typename === '_FieldPathFragment') {\n\t\t\t\t\tif (currentNode.nodeType === 'iNode') {\n\t\t\t\t\t\tlet alias = pathNode.field\n\t\t\t\t\t\tlet nextIndex = i + 1\n\t\t\t\t\t\tif (nextIndex in error.path) {\n\t\t\t\t\t\t\tconst nextPathNode = error.path[nextIndex]\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tnextPathNode.__typename === '_IndexPathFragment' &&\n\t\t\t\t\t\t\t\ttypeof nextPathNode.alias === 'string' &&\n\t\t\t\t\t\t\t\tnextPathNode.alias.startsWith(pathNode.field)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t// We're dealing with a reduced hasMany relation.\n\t\t\t\t\t\t\t\ti++\n\t\t\t\t\t\t\t\tnextIndex++\n\t\t\t\t\t\t\t\talias = nextPathNode.alias\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!(alias in currentNode.children)) {\n\t\t\t\t\t\t\tcurrentNode.children.set(alias, this.getRootNode(error, nextIndex))\n\t\t\t\t\t\t\tif (nextIndex <= error.path.length) {\n\t\t\t\t\t\t\t\t// This path has been handled by getRootNode\n\t\t\t\t\t\t\t\tcontinue errorLoop\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurrentNode = currentNode.children.get(alias)!\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.rejectCorruptData()\n\t\t\t\t\t}\n\t\t\t\t} else if (pathNode.__typename === '_IndexPathFragment') {\n\t\t\t\t\tif (currentNode.nodeType === 'iNode') {\n\t\t\t\t\t\tconst alias = pathNode.alias\n\n\t\t\t\t\t\tif (alias === null) {\n\t\t\t\t\t\t\tthrow new ErrorsPreprocessor.ErrorsPreprocessorError(\n\t\t\t\t\t\t\t\t`Corrupt data: undefined alias for node with index ${pathNode.index}.`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst entityId = MutationAlias.decodeEntityId(alias)\n\n\t\t\t\t\t\tif (!(entityId in currentNode.children)) {\n\t\t\t\t\t\t\tcurrentNode.children.set(entityId, this.getRootNode(error, i + 1))\n\t\t\t\t\t\t\tif (i + 1 <= error.path.length) {\n\t\t\t\t\t\t\t\t// This path has been handled by getRootNode\n\t\t\t\t\t\t\t\tcontinue errorLoop\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurrentNode = currentNode.children.get(entityId)!\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.rejectCorruptData()\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(pathNode)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (this.isExecutionError(error)) {\n\t\t\t\tcurrentNode.execution.push({ type: 'execution', code: error.type, developerMessage: error.message })\n\t\t\t} else {\n\t\t\t\tcurrentNode.validation.push(this.createValidationError(error.message.text))\n\t\t\t}\n\t\t}\n\n\t\treturn rootNode\n\t}\n\n\tprivate getRootNode(error: ValidationError | ExecutionError, startIndex: number = 0): ErrorsPreprocessor.ErrorNode {\n\t\tlet rootNode: ErrorsPreprocessor.ErrorNode = {\n\t\t\tvalidation: this.isExecutionError(error) ? [] : [this.createValidationError(error.message.text)],\n\t\t\texecution: this.isExecutionError(error) ? [{ type: 'execution', code: error.type, developerMessage: error.message }] : [],\n\t\t\tnodeType: 'leaf',\n\t\t}\n\n\t\tfor (let i = error.path.length - 1; i >= startIndex; i--) {\n\t\t\tconst pathNode = error.path[i]\n\t\t\tif (pathNode.__typename === '_FieldPathFragment') {\n\t\t\t\trootNode = {\n\t\t\t\t\tvalidation: [],\n\t\t\t\t\texecution: [],\n\t\t\t\t\tnodeType: 'iNode',\n\t\t\t\t\tchildren: new Map([[pathNode.field, rootNode]]),\n\t\t\t\t}\n\t\t\t} else if (pathNode.__typename === '_IndexPathFragment') {\n\t\t\t\tconst alias = pathNode.alias\n\n\t\t\t\tif (alias === null) {\n\t\t\t\t\tthrow new ErrorsPreprocessor.ErrorsPreprocessorError(\n\t\t\t\t\t\t`Corrupt data: undefined alias for node with index ${pathNode.index}.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\trootNode = {\n\t\t\t\t\tvalidation: [],\n\t\t\t\t\texecution: [],\n\t\t\t\t\tnodeType: 'iNode',\n\t\t\t\t\tchildren: new Map([[MutationAlias.decodeEntityId(alias), rootNode]]),\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tassertNever(pathNode)\n\t\t\t}\n\t\t}\n\n\t\treturn rootNode\n\t}\n\n\tprivate createValidationError(message: string): ErrorAccessor.ValidationError {\n\t\tif (message === 'Field is required') {\n\t\t\t// TODO this is just awful. Validation errors currently don't have error codes which makes it more difficult\n\t\t\t// \tto translate the error messages. This is the most common such error, and so we just make up a code\n\t\t\t// \tin order to facilitate error handling further downstream.\n\t\t\treturn {\n\t\t\t\ttype: 'validation',\n\t\t\t\tcode: 'fieldRequired',\n\t\t\t\tmessage,\n\t\t\t}\n\t\t}\n\t\treturn { type: 'validation', message, code: undefined }\n\t}\n\n\tprivate isExecutionError(error: ValidationError | ExecutionError): error is ExecutionError {\n\t\treturn 'type' in error\n\t}\n\n\tprivate rejectCorruptData(): never {\n\t\tthrow new ErrorsPreprocessor.ErrorsPreprocessorError(\n\t\t\t'Received corrupted data: a node cannot be simultaneously field-indexed and path-indexed.',\n\t\t)\n\t}\n}\n\nnamespace ErrorsPreprocessor {\n\texport interface BaseErrorNode {\n\t\tvalidation: ErrorAccessor.ValidationError[]\n\t\texecution: ErrorAccessor.ExecutionError[]\n\t}\n\n\texport interface LeafErrorNode extends BaseErrorNode {\n\t\tnodeType: 'leaf'\n\t}\n\n\texport interface ErrorINode extends BaseErrorNode {\n\t\tnodeType: 'iNode'\n\t\tchildren: Map<string, ErrorNode>\n\t}\n\n\texport type ErrorNode = ErrorINode | LeafErrorNode\n\n\texport type ErrorTreeRoot = Map<PlaceholderName, ErrorNode>\n\n\texport class ErrorsPreprocessorError extends Error {}\n}\n\nexport { ErrorsPreprocessor }\n"],"names":[],"mappings":";;;AAMA,yBAAyB;AAAA,EACjB,YAA6B,iBAAuC;;;EAEpE,aAA+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YACnD,WAAW,MAAM,KAAK;UACxB,SAAS,eAAe,sBAAsB;mBACtC;AAAA,UACV,YAAY;AAAA,UACZ,WAAW;AAAA,UACX,UAAU;AAAA,UACV,8BAAc,IAAI,CAAC,CAAC,SAAS,OAAO;AAAA;AAAA,iBAE3B,SAAS,eAAe,sBAAsB;cAClD,QAAQ,SAAS;YAEnB,UAAU,MAAM;gBACb,IAAI,mBAAmB,wBAC5B,qDAAqD,SAAS;AAAA;mBAIrD;AAAA,UACV,YAAY;AAAA,UACZ,WAAW;AAAA,UACX,UAAU;AAAA,UACV,8BAAc,IAAI,CAAC,CAAC,cAAc,eAAe,QAAQ;AAAA;AAAA,aAEpD;;;;WAKD;AAAA;AAAA,EAGA,sBAAsB,SAAgD;QACzE,YAAY,qBAAqB;aAI7B;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,QACN;AAAA;AAAA;WAGK,EAAE,MAAM,cAAc,SAAS,MAAM;AAAA;AAAA,EAGrC,iBAAiB,OAAkE;WACnF,UAAU;AAAA;AAAA,EAGV,oBAA2B;UAC5B,IAAI,mBAAmB,wBAC5B;AAAA;AAAA;AAKH,EAAU,wBAAV;wCAmB8C,MAAM;AAAA;sBAAtC;GAnBJ;;"}
1
+ {"version":3,"file":"ErrorsPreprocessor.js","sources":["../../../src/core/ErrorsPreprocessor.ts"],"sourcesContent":["import type { ErrorAccessor } from '../accessors'\nimport type { ExecutionError, MutationDataResponse, MutationResponse, ValidationError } from '../accessorTree'\nimport type { PlaceholderName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport { MutationAlias, mutationOperationSubTreeType } from './requestAliases'\n\nclass ErrorsPreprocessor {\n\tpublic constructor(private readonly requestResponse: MutationDataResponse) {}\n\n\tpublic preprocess(): ErrorsPreprocessor.ErrorTreeRoot {\n\t\tconst treeRoot: ErrorsPreprocessor.ErrorTreeRoot = new Map()\n\n\t\tif (this.requestResponse === undefined) {\n\t\t\treturn treeRoot\n\t\t}\n\n\t\tfor (const mutationAlias in this.requestResponse) {\n\t\t\tconst mutationResponse = this.requestResponse[mutationAlias]\n\t\t\tconst processedResponse = this.processMutationResponse(mutationResponse)\n\n\t\t\tif (processedResponse === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst operation = MutationAlias.decodeTopLevel(mutationAlias)\n\n\t\t\tif (operation === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst { subTreeType, subTreePlaceholder, entityId } = operation\n\n\t\t\tif (subTreeType === mutationOperationSubTreeType.singleEntity) {\n\t\t\t\tif (treeRoot.has(subTreePlaceholder)) {\n\t\t\t\t\treturn this.rejectCorruptData()\n\t\t\t\t}\n\t\t\t\ttreeRoot.set(subTreePlaceholder, processedResponse)\n\t\t\t} else if (subTreeType === mutationOperationSubTreeType.entityList) {\n\t\t\t\tconst child = treeRoot.get(subTreePlaceholder)\n\n\t\t\t\tif (child === undefined) {\n\t\t\t\t\ttreeRoot.set(subTreePlaceholder, {\n\t\t\t\t\t\tnodeType: 'iNode',\n\t\t\t\t\t\tchildren: new Map([[entityId, processedResponse]]),\n\t\t\t\t\t\tvalidation: [],\n\t\t\t\t\t\texecution: [],\n\t\t\t\t\t})\n\t\t\t\t} else if (child.nodeType === 'iNode') {\n\t\t\t\t\tchild.children.set(entityId, processedResponse)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn assertNever(subTreeType)\n\t\t\t}\n\t\t}\n\t\treturn treeRoot\n\t}\n\n\tprivate processMutationResponse(mutationResponse: MutationResponse): ErrorsPreprocessor.ErrorNode | undefined {\n\t\tif (mutationResponse.ok && mutationResponse.validation?.valid && mutationResponse.errors.length === 0) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (mutationResponse.validation?.errors.length) {\n\t\t\treturn this.getErrorNode(mutationResponse.validation?.errors)\n\t\t}\n\t\tif (mutationResponse.errors.length) {\n\t\t\treturn this.getErrorNode(mutationResponse.errors)\n\t\t}\n\t\treturn undefined\n\t}\n\n\tprivate getErrorNode(errors: ValidationError[] | ExecutionError[]): ErrorsPreprocessor.ErrorNode {\n\t\tconst [head, ...tail] = errors\n\n\t\tlet rootNode = this.getRootNode(head)\n\n\t\terrorLoop: for (const error of tail) {\n\t\t\tlet currentNode = rootNode\n\n\t\t\tfor (let i = 0, pathLength = error.path.length; i < pathLength; i++) {\n\t\t\t\tconst pathNode = error.path[i]\n\n\t\t\t\tif (currentNode.nodeType === 'leaf') {\n\t\t\t\t\t(currentNode as any as ErrorsPreprocessor.ErrorINode).nodeType = 'iNode'\n\t\t\t\t\t;(currentNode as any as ErrorsPreprocessor.ErrorINode).children = new Map()\n\t\t\t\t}\n\n\t\t\t\tif (pathNode.__typename === '_FieldPathFragment') {\n\t\t\t\t\tif (currentNode.nodeType === 'iNode') {\n\t\t\t\t\t\tlet alias = pathNode.field\n\t\t\t\t\t\tlet nextIndex = i + 1\n\t\t\t\t\t\tif (nextIndex in error.path) {\n\t\t\t\t\t\t\tconst nextPathNode = error.path[nextIndex]\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tnextPathNode.__typename === '_IndexPathFragment' &&\n\t\t\t\t\t\t\t\ttypeof nextPathNode.alias === 'string' &&\n\t\t\t\t\t\t\t\tnextPathNode.alias.startsWith(pathNode.field)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t// We're dealing with a reduced hasMany relation.\n\t\t\t\t\t\t\t\ti++\n\t\t\t\t\t\t\t\tnextIndex++\n\t\t\t\t\t\t\t\talias = nextPathNode.alias\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!(alias in currentNode.children)) {\n\t\t\t\t\t\t\tcurrentNode.children.set(alias, this.getRootNode(error, nextIndex))\n\t\t\t\t\t\t\tif (nextIndex <= error.path.length) {\n\t\t\t\t\t\t\t\t// This path has been handled by getRootNode\n\t\t\t\t\t\t\t\tcontinue errorLoop\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurrentNode = currentNode.children.get(alias)!\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.rejectCorruptData()\n\t\t\t\t\t}\n\t\t\t\t} else if (pathNode.__typename === '_IndexPathFragment') {\n\t\t\t\t\tif (currentNode.nodeType === 'iNode') {\n\t\t\t\t\t\tconst alias = pathNode.alias\n\n\t\t\t\t\t\tif (alias === null) {\n\t\t\t\t\t\t\tthrow new ErrorsPreprocessor.ErrorsPreprocessorError(\n\t\t\t\t\t\t\t\t`Corrupt data: undefined alias for node with index ${pathNode.index}.`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst entityId = MutationAlias.decodeEntityId(alias)\n\n\t\t\t\t\t\tif (!(entityId in currentNode.children)) {\n\t\t\t\t\t\t\tcurrentNode.children.set(entityId, this.getRootNode(error, i + 1))\n\t\t\t\t\t\t\tif (i + 1 <= error.path.length) {\n\t\t\t\t\t\t\t\t// This path has been handled by getRootNode\n\t\t\t\t\t\t\t\tcontinue errorLoop\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurrentNode = currentNode.children.get(entityId)!\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.rejectCorruptData()\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(pathNode)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (this.isExecutionError(error)) {\n\t\t\t\tcurrentNode.execution.push({ type: 'execution', code: error.type, developerMessage: error.message })\n\t\t\t} else {\n\t\t\t\tcurrentNode.validation.push(this.createValidationError(error.message.text))\n\t\t\t}\n\t\t}\n\n\t\treturn rootNode\n\t}\n\n\tprivate getRootNode(error: ValidationError | ExecutionError, startIndex: number = 0): ErrorsPreprocessor.ErrorNode {\n\t\tlet rootNode: ErrorsPreprocessor.ErrorNode = {\n\t\t\tvalidation: this.isExecutionError(error) ? [] : [this.createValidationError(error.message.text)],\n\t\t\texecution: this.isExecutionError(error) ? [{ type: 'execution', code: error.type, developerMessage: error.message }] : [],\n\t\t\tnodeType: 'leaf',\n\t\t}\n\n\t\tfor (let i = error.path.length - 1; i >= startIndex; i--) {\n\t\t\tconst pathNode = error.path[i]\n\t\t\tif (pathNode.__typename === '_FieldPathFragment') {\n\t\t\t\trootNode = {\n\t\t\t\t\tvalidation: [],\n\t\t\t\t\texecution: [],\n\t\t\t\t\tnodeType: 'iNode',\n\t\t\t\t\tchildren: new Map([[pathNode.field, rootNode]]),\n\t\t\t\t}\n\t\t\t} else if (pathNode.__typename === '_IndexPathFragment') {\n\t\t\t\tconst alias = pathNode.alias\n\n\t\t\t\tif (alias === null) {\n\t\t\t\t\tthrow new ErrorsPreprocessor.ErrorsPreprocessorError(\n\t\t\t\t\t\t`Corrupt data: undefined alias for node with index ${pathNode.index}.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\trootNode = {\n\t\t\t\t\tvalidation: [],\n\t\t\t\t\texecution: [],\n\t\t\t\t\tnodeType: 'iNode',\n\t\t\t\t\tchildren: new Map([[MutationAlias.decodeEntityId(alias), rootNode]]),\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tassertNever(pathNode)\n\t\t\t}\n\t\t}\n\n\t\treturn rootNode\n\t}\n\n\tprivate createValidationError(message: string): ErrorAccessor.ValidationError {\n\t\tif (message === 'Field is required') {\n\t\t\t// TODO this is just awful. Validation errors currently don't have error codes which makes it more difficult\n\t\t\t// \tto translate the error messages. This is the most common such error, and so we just make up a code\n\t\t\t// \tin order to facilitate error handling further downstream.\n\t\t\treturn {\n\t\t\t\ttype: 'validation',\n\t\t\t\tcode: 'fieldRequired',\n\t\t\t\tmessage,\n\t\t\t}\n\t\t}\n\t\treturn { type: 'validation', message, code: undefined }\n\t}\n\n\tprivate isExecutionError(error: ValidationError | ExecutionError): error is ExecutionError {\n\t\treturn 'type' in error\n\t}\n\n\tprivate rejectCorruptData(): never {\n\t\tthrow new ErrorsPreprocessor.ErrorsPreprocessorError(\n\t\t\t'Received corrupted data: a node cannot be simultaneously field-indexed and path-indexed.',\n\t\t)\n\t}\n}\n\nnamespace ErrorsPreprocessor {\n\texport interface BaseErrorNode {\n\t\tvalidation: ErrorAccessor.ValidationError[]\n\t\texecution: ErrorAccessor.ExecutionError[]\n\t}\n\n\texport interface LeafErrorNode extends BaseErrorNode {\n\t\tnodeType: 'leaf'\n\t}\n\n\texport interface ErrorINode extends BaseErrorNode {\n\t\tnodeType: 'iNode'\n\t\tchildren: Map<string, ErrorNode>\n\t}\n\n\texport type ErrorNode = ErrorINode | LeafErrorNode\n\n\texport type ErrorTreeRoot = Map<PlaceholderName, ErrorNode>\n\n\texport class ErrorsPreprocessorError extends Error {}\n}\n\nexport { ErrorsPreprocessor }\n"],"names":[],"mappings":";;;AAMA,MAAM,mBAAmB;AAAA,EACjB,YAA6B,iBAAuC;AAAvC,SAAA,kBAAA;AAAA,EAAwC;AAAA,EAErE,aAA+C;AAC/C,UAAA,+BAAiD;AAEnD,QAAA,KAAK,oBAAoB,QAAW;AAChC,aAAA;AAAA,IACR;AAEW,eAAA,iBAAiB,KAAK,iBAAiB;AAC3C,YAAA,mBAAmB,KAAK,gBAAgB;AACxC,YAAA,oBAAoB,KAAK,wBAAwB,gBAAgB;AAEvE,UAAI,sBAAsB,QAAW;AACpC;AAAA,MACD;AAEM,YAAA,YAAY,cAAc,eAAe,aAAa;AAE5D,UAAI,cAAc,QAAW;AAC5B;AAAA,MACD;AAEM,YAAA,EAAE,aAAa,oBAAoB,aAAa;AAElD,UAAA,gBAAgB,6BAA6B,cAAc;AAC1D,YAAA,SAAS,IAAI,kBAAkB,GAAG;AACrC,iBAAO,KAAK;QACb;AACS,iBAAA,IAAI,oBAAoB,iBAAiB;AAAA,MAAA,WACxC,gBAAgB,6BAA6B,YAAY;AAC7D,cAAA,QAAQ,SAAS,IAAI,kBAAkB;AAE7C,YAAI,UAAU,QAAW;AACxB,mBAAS,IAAI,oBAAoB;AAAA,YAChC,UAAU;AAAA,YACV,8BAAc,IAAI,CAA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AAgC,MAAM;AAAA,EAAC;AAAvC,sBAAA,0BAAA;AAAA,GAnBJ,sBAAA,sBAAA,CAAA,EAAA;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"EventManager.js","sources":["../../../src/core/EventManager.ts"],"sourcesContent":["import * as ReactDOM from 'react-dom'\nimport type {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tEntityAccessor,\n\tEntityListAccessor,\n\tFieldAccessor,\n\tPersistErrorOptions,\n\tPersistSuccessOptions,\n} from '../accessors'\nimport type { SuccessfulPersistResult } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { PlaceholderName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport type { Config } from './Config'\nimport type { DirtinessTracker } from './DirtinessTracker'\nimport {\n\tEntityListState,\n\tEntityRealmState,\n\tFieldState,\n\tgetEntityMarker,\n\tRootStateNode,\n\tStateINode,\n\tStateIterator,\n\tStateNode,\n} from './state'\nimport type { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport type { EventListenersStore } from '../treeParameters'\n\nexport class EventManager {\n\tpublic static readonly NO_CHANGES_DIFFERENCE = 0\n\n\tprivate transactionDepth = 0\n\tprivate isFrozenWhileUpdating = false\n\n\t// This should ideally not exists as it should be synonymous to `this.ongoingPersistOperation !== undefined`\n\t// but it makes persist-related promise juggling significantly more straightforward.\n\tprivate isMutating: boolean = false\n\tprivate ongoingPersistOperation: Promise<SuccessfulPersistResult> | undefined = undefined\n\n\tprivate previousMetadata: UpdateMetadata | undefined = undefined\n\n\tprivate newlyInitializedWithListeners: Set<EntityListState | EntityRealmState | FieldState> = new Set()\n\tprivate pendingWithBeforeUpdate: Set<StateNode> = new Set()\n\tprivate rootsWithPendingUpdates: Set<RootStateNode> = new Set()\n\n\tpublic constructor(\n\t\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly config: Config,\n\t\tprivate readonly dirtinessTracker: DirtinessTracker,\n\t\tprivate readonly onUpdate: (metadata: UpdateMetadata) => void,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic async persistOperation(operation: () => Promise<SuccessfulPersistResult>): Promise<SuccessfulPersistResult> {\n\t\tif (this.transactionDepth > 0) {\n\t\t\tthrow new BindingError(`Cannot trigger a persist whilst batching updates!`)\n\t\t}\n\t\tconst ongoingOperation = this.ongoingPersistOperation\n\t\tif (ongoingOperation !== undefined) {\n\t\t\treturn await ongoingOperation\n\t\t}\n\t\treturn await (this.ongoingPersistOperation = new Promise<SuccessfulPersistResult>(async (resolve, reject) => {\n\t\t\tthis.isMutating = true\n\t\t\tthis.flushUpdates() // Let the world know that we're mutating\n\n\t\t\ttry {\n\t\t\t\tresolve(await this.asyncOperation(operation))\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error('PersistError', e)\n\t\t\t\treject(e)\n\t\t\t} finally {\n\t\t\t\tthis.ongoingPersistOperation = undefined\n\t\t\t\tthis.isMutating = false\n\t\t\t\tthis.flushUpdates()\n\t\t\t}\n\t\t}))\n\t}\n\n\tpublic syncTransaction<T>(transaction: () => T) {\n\t\ttry {\n\t\t\tthis.transactionDepth++\n\t\t\treturn transaction()\n\t\t} finally {\n\t\t\tthis.transactionDepth--\n\t\t}\n\t}\n\tpublic syncOperation<T>(operation: () => T) {\n\t\tconst result = this.syncTransaction(operation)\n\t\tthis.flushUpdates()\n\t\treturn result\n\t}\n\n\tpublic async asyncTransaction<T>(transaction: () => Promise<T>): Promise<T> {\n\t\ttry {\n\t\t\tthis.transactionDepth++\n\t\t\treturn await transaction()\n\t\t} finally {\n\t\t\tthis.transactionDepth--\n\t\t}\n\t}\n\tpublic async asyncOperation<T>(operation: () => Promise<T>): Promise<T> {\n\t\tconst result = await this.asyncTransaction(operation)\n\t\tthis.flushUpdates()\n\t\treturn result\n\t}\n\n\tprivate flushUpdates() {\n\t\tif (this.transactionDepth > 0) {\n\t\t\treturn\n\t\t}\n\n\t\tif (this.isFrozenWhileUpdating) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Trying to perform an update while the whole accessor tree is already updating. This is most likely caused ` +\n\t\t\t\t\t`by updating the accessor tree while rendering or from within the 'update' event handler, which is a no-op. ` +\n\t\t\t\t\t`If you wish to mutate the tree in reaction to other changes, use the 'beforeUpdate' event.`,\n\t\t\t)\n\t\t}\n\n\t\tconst newMetadata = this.getNewUpdateMetadata()\n\n\t\tif (!this.shouldFlushUpdates(newMetadata)) {\n\t\t\treturn\n\t\t}\n\n\t\tReactDOM.unstable_batchedUpdates(() => {\n\t\t\tthis.isFrozenWhileUpdating = true\n\t\t\tthis.triggerBeforeFlushEvents()\n\t\t\tthis.onUpdate(newMetadata)\n\t\t\tthis.flushPendingAccessorUpdates(Array.from(this.rootsWithPendingUpdates))\n\n\t\t\tthis.rootsWithPendingUpdates.clear()\n\t\t\tthis.isFrozenWhileUpdating = false\n\t\t\tthis.previousMetadata = newMetadata\n\t\t})\n\t}\n\n\tprivate getNewUpdateMetadata(): UpdateMetadata {\n\t\treturn {\n\t\t\tisMutating: this.isMutating,\n\t\t}\n\t}\n\n\tprivate shouldFlushUpdates(newMetadata: UpdateMetadata): boolean {\n\t\tif (this.transactionDepth > 0) {\n\t\t\treturn false\n\t\t}\n\t\tif (this.previousMetadata === undefined) {\n\t\t\treturn true\n\t\t}\n\t\tif (this.rootsWithPendingUpdates.size) {\n\t\t\treturn true\n\t\t}\n\t\tfor (const key in newMetadata) {\n\t\t\tconst fromPrevious = this.previousMetadata[key as keyof UpdateMetadata]\n\t\t\tconst fromNew = newMetadata[key as keyof UpdateMetadata]\n\n\t\t\tif (!Object.is(fromPrevious, fromNew)) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n\n\tpublic registerNewlyInitialized(newlyInitialized: StateNode) {\n\t\tconst initializeListeners = this.getEventListeners(newlyInitialized, { type: 'initialize' })\n\n\t\tif (initializeListeners === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.newlyInitializedWithListeners.add(newlyInitialized)\n\n\t\tif (this.transactionDepth === 0) {\n\t\t\tthis.triggerOnInitialize()\n\t\t}\n\t}\n\n\tpublic registerUpdatedConnection(parentState: EntityRealmState, placeholderName: PlaceholderName) {\n\t\tif (parentState.fieldsWithPendingConnectionUpdates === undefined) {\n\t\t\tparentState.fieldsWithPendingConnectionUpdates = new Set()\n\t\t}\n\n\t\tconst marker = getEntityMarker(parentState)\n\t\tplaceholders: for (const [fieldName, placeholdersByField] of marker.fields.placeholders) {\n\t\t\tif (typeof placeholdersByField === 'string') {\n\t\t\t\tif (placeholdersByField === placeholderName) {\n\t\t\t\t\tparentState.fieldsWithPendingConnectionUpdates.add(fieldName)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (const placeholderByFieldName of placeholdersByField) {\n\t\t\t\t\tif (placeholderByFieldName === placeholderName) {\n\t\t\t\t\t\tparentState.fieldsWithPendingConnectionUpdates.add(fieldName)\n\t\t\t\t\t\tcontinue placeholders\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic registerJustUpdated(justUpdated: StateNode, changesDelta: number) {\n\t\tconst beforeUpdateListeners = this.getEventListeners(justUpdated, { type: 'beforeUpdate' })\n\t\tif (beforeUpdateListeners !== undefined) {\n\t\t\tthis.pendingWithBeforeUpdate.add(justUpdated)\n\t\t}\n\t\tjustUpdated.accessor = undefined\n\n\t\tswitch (justUpdated.type) {\n\t\t\tcase 'entityRealm':\n\t\t\tcase 'entityList': {\n\t\t\t\tjustUpdated.unpersistedChangesCount += changesDelta\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tif (justUpdated.unpersistedChangesCount < 0) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`We have *JUST* reached a completely invalid state. From now on, anything can (and likely will) ` +\n\t\t\t\t\t\t\t\t`go wrong. This is definitely a bug. Please try to report whatever led to this situation.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst parent = justUpdated.blueprint.parent\n\n\t\t\t\tif (parent === undefined) {\n\t\t\t\t\tthis.rootsWithPendingUpdates.add(justUpdated)\n\t\t\t\t\tthis.dirtinessTracker.increaseBy(changesDelta)\n\t\t\t\t} else {\n\t\t\t\t\tif (!parent.childrenWithPendingUpdates) {\n\t\t\t\t\t\tparent.childrenWithPendingUpdates = new Set()\n\t\t\t\t\t}\n\t\t\t\t\tparent.childrenWithPendingUpdates.add(justUpdated as any)\n\t\t\t\t\tthis.registerJustUpdated(parent, changesDelta)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'field': {\n\t\t\t\tconst parent = justUpdated.parent\n\t\t\t\tif (!parent.childrenWithPendingUpdates) {\n\t\t\t\t\tparent.childrenWithPendingUpdates = new Set()\n\t\t\t\t}\n\t\t\t\tparent.childrenWithPendingUpdates.add(justUpdated as any)\n\t\t\t\tthis.registerJustUpdated(justUpdated.parent, changesDelta)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate flushPendingAccessorUpdates(rootStates: Array<StateINode>) {\n\t\t// It is *CRUCIAL* that this is a BFS so that we update the components in top-down order.\n\t\tconst agenda: StateNode[] = rootStates\n\n\t\tfor (const state of agenda) {\n\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\tconst updateListeners =\n\t\t\t\tstate.type === 'field'\n\t\t\t\t\t? this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\t\t\t\t\t: state.type === 'entityRealm'\n\t\t\t\t\t? this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\t\t\t\t\t: this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\n\t\t\tif (updateListeners !== undefined) {\n\t\t\t\tfor (const handler of updateListeners) {\n\t\t\t\t\t// TS can't quite handle the polymorphism here but this is fine.\n\t\t\t\t\thandler()\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (state.type === 'entityRealm' && state.fieldsWithPendingConnectionUpdates) {\n\t\t\t\tfor (const updatedField of state.fieldsWithPendingConnectionUpdates) {\n\t\t\t\t\tconst listeners = this.getEventListeners(state, { type: 'connectionUpdate', key: updatedField })\n\t\t\t\t\tif (!listeners) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tlistener(state.getAccessor())\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tswitch (state.type) {\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (state.childrenWithPendingUpdates !== undefined) {\n\t\t\t\t\t\tfor (const childState of state.childrenWithPendingUpdates) {\n\t\t\t\t\t\t\tagenda.push(childState)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstate.childrenWithPendingUpdates.clear()\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'field':\n\t\t\t\t\t// Do nothing\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\tassertNever(state)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async triggerAsyncMutatingEvent(eventType: 'beforePersist', options: AsyncBatchUpdatesOptions): Promise<void>\n\tprivate async triggerAsyncMutatingEvent(eventType: 'persistSuccess', options: PersistSuccessOptions): Promise<void>\n\tprivate async triggerAsyncMutatingEvent(\n\t\teventType: 'beforePersist' | 'persistSuccess',\n\t\toptions: AsyncBatchUpdatesOptions | PersistSuccessOptions,\n\t): Promise<void> {\n\t\tawait this.asyncTransaction(async () => {\n\t\t\t// TODO if an entity from here (or its parent) gets deleted, we need to remove stale handlers from here.\n\t\t\tconst callbackQueue: Array<\n\t\t\t\t[\n\t\t\t\t\t// The typings could be nicer but TS…\n\t\t\t\t\tStateINode,\n\t\t\t\t\t(\n\t\t\t\t\t\t| EntityAccessor.EntityEventListenerMap[typeof eventType]\n\t\t\t\t\t\t| EntityListAccessor.EntityListEventListenerMap[typeof eventType]\n\t\t\t\t\t),\n\t\t\t\t]\n\t\t\t> = []\n\n\t\t\tfor (const [, subTreeState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const iNode of StateIterator.depthFirstINodes(subTreeState)) {\n\t\t\t\t\tconst listeners = this.getEventListeners(iNode, { type: eventType }) ?? []\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tcallbackQueue.push([iNode, listener])\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (\n\t\t\t\tlet waterfallDepth = 0;\n\t\t\t\twaterfallDepth < this.config.getValue(`${eventType}SettleLimit` as const);\n\t\t\t\twaterfallDepth++\n\t\t\t) {\n\t\t\t\tconst promiseReturns: Array<\n\t\t\t\t\tPromise<\n\t\t\t\t\t\t| void\n\t\t\t\t\t\t| EntityAccessor.EntityEventListenerMap[typeof eventType]\n\t\t\t\t\t\t| EntityListAccessor.EntityListEventListenerMap[typeof eventType]\n\t\t\t\t\t>\n\t\t\t\t> = []\n\t\t\t\tconst correspondingStates: Array<StateINode> = []\n\n\t\t\t\tif (callbackQueue.length === 0) {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\n\t\t\t\tfor (const [state, callback] of callbackQueue) {\n\t\t\t\t\tcorrespondingStates.push(state)\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = callback(state.getAccessor as any, options as any) // TS can't quite handle this but this is sound.\n\t\t\t\t\t\tif (result instanceof Promise) {\n\t\t\t\t\t\t\tpromiseReturns.push(result)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tpromiseReturns.push(Promise.resolve(result))\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tpromiseReturns.push(Promise.reject(e))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// TODO timeout\n\n\t\t\t\tconst newCallbacks = await this.executeWithoutChanges(eventType, () => Promise.allSettled(promiseReturns))\n\n\t\t\t\tcallbackQueue.length = 0 // Empties the queue\n\n\t\t\t\t// TODO we're drifting away from the original depth-first order. Let's see if that's ever even an issue.\n\t\t\t\tfor (const newlyInitialized of this.newlyInitializedWithListeners) {\n\t\t\t\t\tif (newlyInitialized.type === 'field') {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst beforePersistHandlers = this.getEventListeners(newlyInitialized, { type: eventType })\n\t\t\t\t\tif (beforePersistHandlers) {\n\t\t\t\t\t\tfor (const listener of beforePersistHandlers) {\n\t\t\t\t\t\t\tcallbackQueue.push([newlyInitialized, listener])\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.triggerBeforeFlushEvents()\n\t\t\t\tthis.handleRejections(eventType, newCallbacks)\n\n\t\t\t\tfor (let i = 0; i < newCallbacks.length; i++) {\n\t\t\t\t\tconst result = newCallbacks[i]\n\t\t\t\t\tconst correspondingState = correspondingStates[i]\n\n\t\t\t\t\tif (result.status === 'fulfilled') {\n\t\t\t\t\t\tif (typeof result.value === 'function') {\n\t\t\t\t\t\t\tcallbackQueue.push([correspondingState, result.value])\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Otherwise do nothing. This is just a handler that albeit async, doesn't appear to\n\t\t\t\t\t\t// interact with data binding.\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\tif (callbackQueue.length) {\n\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t`Exceeded the ${eventType} settle limit. Your code likely contains a deadlock. ` +\n\t\t\t\t\t\t\t`If that's not the case, raise the settle limit from DataBindingProvider.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate triggerBeforeFlushEvents() {\n\t\tthis.syncTransaction(() => {\n\t\t\tconst settleLimit = this.config.getValue('beforeUpdateSettleLimit')\n\n\t\t\tfor (let attemptNumber = 0; attemptNumber < settleLimit; attemptNumber++) {\n\t\t\t\tif (!this.pendingWithBeforeUpdate.size) {\n\t\t\t\t\tthis.triggerOnInitialize()\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst withBeforeUpdate = this.pendingWithBeforeUpdate\n\t\t\t\tthis.pendingWithBeforeUpdate = new Set()\n\n\t\t\t\tfor (const state of withBeforeUpdate) {\n\t\t\t\t\tconst listeners = this.getEventListeners(state, { type: 'beforeUpdate' })\n\t\t\t\t\tif (listeners === undefined) {\n\t\t\t\t\t\t// This can happen if the listener has unsubscribed since we added it to the set.\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tswitch (state.type) {\n\t\t\t\t\t\tcase 'field':\n\t\t\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\t\t\t(listener as FieldAccessor.BeforeUpdateListener)(state.getAccessor())\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\t\t\tstate.getAccessor().batchUpdates(listener as any)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn assertNever(state)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.triggerOnInitialize()\n\t\t\t}\n\t\t\tthrow new BindingError(\n\t\t\t\t`Maximum stabilization limit of updates caused by 'beforeUpdate' exceeded. ` +\n\t\t\t\t\t`This likely means there is an infinite feedback loop in your code.`,\n\t\t\t)\n\t\t})\n\t}\n\n\tprivate triggerOnInitialize() {\n\t\tthis.syncTransaction(() => {\n\t\t\tfor (const state of this.newlyInitializedWithListeners) {\n\t\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\t\tconst listeners =\n\t\t\t\t\tstate.type === 'field'\n\t\t\t\t\t\t? this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\t\t\t\t\t\t: state.type === 'entityRealm'\n\t\t\t\t\t\t? this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\t\t\t\t\t\t: this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\n\t\t\t\tif (listeners) {\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tlistener()\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (state.type === 'entityRealm') {\n\t\t\t\t\tstate.entity.hasIdSetInStone = true\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.newlyInitializedWithListeners.clear()\n\t\t})\n\t}\n\n\tpublic async triggerOnPersistError(options: PersistErrorOptions) {\n\t\tawait this.asyncTransaction(async () => {\n\t\t\tconst handlerPromises: Array<Promise<void>> = []\n\n\t\t\tfor (const [, subTreeState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const iNode of StateIterator.depthFirstINodes(subTreeState)) {\n\t\t\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\t\t\tconst dispatchers =\n\t\t\t\t\t\tiNode.type === 'entityRealm'\n\t\t\t\t\t\t\t? this.getEventDispatchers(iNode, { type: 'persistError' }, [iNode.getAccessor, options])\n\t\t\t\t\t\t\t: this.getEventDispatchers(iNode, { type: 'persistError' }, [iNode.getAccessor, options])\n\t\t\t\t\tif (dispatchers === undefined) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const listener of dispatchers ?? []) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst result = listener()\n\t\t\t\t\t\t\tif (result instanceof Promise) {\n\t\t\t\t\t\t\t\thandlerPromises.push(result)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\thandlerPromises.push(Promise.resolve(result))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\thandlerPromises.push(Promise.reject(e))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// TODO timeout\n\t\t\tconst handlerResults = await Promise.allSettled(handlerPromises)\n\t\t\tthis.handleRejections('persistError', handlerResults)\n\t\t})\n\t}\n\n\tpublic async triggerOnBeforePersist() {\n\t\treturn this.triggerAsyncMutatingEvent('beforePersist', this.asyncBatchUpdatesOptions)\n\t}\n\n\tpublic async triggerOnPersistSuccess(options: PersistSuccessOptions) {\n\t\treturn this.triggerAsyncMutatingEvent('persistSuccess', options)\n\t}\n\n\tpublic getEventListeners<\n\t\tState extends StateNode,\n\t\tEventListenerTypes extends\n\t\t\tExclude<State['eventListeners'], undefined> extends EventListenersStore<infer Keys, infer Map> ? [Keys, Map] : never,\n\t\tEventType extends EventListenerTypes[0],\n\t>(state: State, event: { type: EventType; key?: string }): Set<Exclude<EventListenerTypes[1][EventType], undefined>> | undefined {\n\t\tif (!state.eventListeners) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn (state.eventListeners as EventListenersStore<EventType, EventListenerTypes[1]>).get(event) as Set<\n\t\t\tExclude<EventListenerTypes[1][EventType], undefined>\n\t\t>\n\t}\n\n\tpublic getEventDispatchers<\n\t\tState extends StateNode,\n\t\tEventListenerTypes extends\n\t\t\tExclude<State['eventListeners'], undefined> extends EventListenersStore<infer Keys, infer Map> ? [Keys, Map] : never,\n\t\tEventType extends EventListenerTypes[0],\n\t>(\n\t\tstate: State,\n\t\tevent: { type: EventType; key?: string },\n\t\tlistenerArgs: Parameters<Exclude<EventListenerTypes[1][EventType], undefined>>,\n\t): Array<() => ReturnType<Exclude<EventListenerTypes[1][EventType], undefined>>> | undefined {\n\t\tconst eventListeners = this.getEventListeners(state, event)\n\t\tif (eventListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn Array.from(eventListeners.values(), listener => {\n\t\t\treturn () => listener(...listenerArgs)\n\t\t}) as Array<() => ReturnType<Exclude<EventListenerTypes[1][EventType], undefined>>>\n\t}\n\n\tprivate handleRejections(handler: string, promises: PromiseSettledResult<any>[]) {\n\t\tconst rejections = promises.filter((it): it is PromiseRejectedResult => it.status === 'rejected')\n\t\tif (rejections.length === 0) {\n\t\t\treturn\n\t\t}\n\t\trejections.forEach(it => console.error(it.reason))\n\t\tif (import.meta.env.DEV) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`A ${handler} handler returned a promise that rejected. ` +\n\t\t\t\t\t`This is a no-op that will fail silently in production.`,\n\t\t\t)\n\t\t}\n\t}\n\n\tprivate async executeWithoutChanges<T>(eventType: string, cb: () => Promise<T>): Promise<T> {\n\t\tconst changesCountBefore = this.dirtinessTracker.getTotalChangesCount()\n\t\tconst result = await cb()\n\t\tconst changesCountAfter = this.dirtinessTracker.getTotalChangesCount()\n\t\tif (import.meta.env.DEV) {\n\t\t\tif (changesCountBefore !== changesCountAfter) {\n\t\t\t\t// This isn't bulletproof. They could e.g. undo a change and make another one which would\n\t\t\t\t// slip through this detection. But for most cases, it should be good enough and not too expensive.\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`A ${eventType} event handler cannot be asynchronous and alter the accessor tree at the same time. ` +\n\t\t\t\t\t\t`To achieve this, prepare your data asynchronously but only touch the tree from a returned callback.`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;mBA8B0B;AAAA,EAiBlB,YACW,0BACA,qBACA,QACA,kBACA,UACA,WAChB;AArBM,4CAAmB;AACnB,iDAAwB;AAIxB,sCAAsB;AACtB;AAEA;AAEA,6EAA0F;AAC1F,uEAA8C;AAC9C,uEAAkD;;;;;;;;QAW7C,iBAAiB,WAAqF;QAC9G,KAAK,mBAAmB,GAAG;YACxB,IAAI,aAAa;AAAA;UAElB,mBAAmB,KAAK;QAC1B,qBAAqB,QAAW;aAC5B,MAAM;AAAA;WAEP,YA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../../../src/core/EventManager.ts"],"sourcesContent":["import * as ReactDOM from 'react-dom'\nimport type {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tEntityAccessor,\n\tEntityListAccessor,\n\tFieldAccessor,\n\tPersistErrorOptions,\n\tPersistSuccessOptions,\n} from '../accessors'\nimport type { SuccessfulPersistResult } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { PlaceholderName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport type { Config } from './Config'\nimport type { DirtinessTracker } from './DirtinessTracker'\nimport {\n\tEntityListState,\n\tEntityRealmState,\n\tFieldState,\n\tgetEntityMarker,\n\tRootStateNode,\n\tStateINode,\n\tStateIterator,\n\tStateNode,\n} from './state'\nimport type { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport type { EventListenersStore } from '../treeParameters'\n\nexport class EventManager {\n\tpublic static readonly NO_CHANGES_DIFFERENCE = 0\n\n\tprivate transactionDepth = 0\n\tprivate isFrozenWhileUpdating = false\n\n\t// This should ideally not exists as it should be synonymous to `this.ongoingPersistOperation !== undefined`\n\t// but it makes persist-related promise juggling significantly more straightforward.\n\tprivate isMutating: boolean = false\n\tprivate ongoingPersistOperation: Promise<SuccessfulPersistResult> | undefined = undefined\n\n\tprivate previousMetadata: UpdateMetadata | undefined = undefined\n\n\tprivate newlyInitializedWithListeners: Set<EntityListState | EntityRealmState | FieldState> = new Set()\n\tprivate pendingWithBeforeUpdate: Set<StateNode> = new Set()\n\tprivate rootsWithPendingUpdates: Set<RootStateNode> = new Set()\n\n\tpublic constructor(\n\t\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly config: Config,\n\t\tprivate readonly dirtinessTracker: DirtinessTracker,\n\t\tprivate readonly onUpdate: (metadata: UpdateMetadata) => void,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic async persistOperation(operation: () => Promise<SuccessfulPersistResult>): Promise<SuccessfulPersistResult> {\n\t\tif (this.transactionDepth > 0) {\n\t\t\tthrow new BindingError(`Cannot trigger a persist whilst batching updates!`)\n\t\t}\n\t\tconst ongoingOperation = this.ongoingPersistOperation\n\t\tif (ongoingOperation !== undefined) {\n\t\t\treturn await ongoingOperation\n\t\t}\n\t\treturn await (this.ongoingPersistOperation = new Promise<SuccessfulPersistResult>(async (resolve, reject) => {\n\t\t\tthis.isMutating = true\n\t\t\tthis.flushUpdates() // Let the world know that we're mutating\n\n\t\t\ttry {\n\t\t\t\tresolve(await this.asyncOperation(operation))\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error('PersistError', e)\n\t\t\t\treject(e)\n\t\t\t} finally {\n\t\t\t\tthis.ongoingPersistOperation = undefined\n\t\t\t\tthis.isMutating = false\n\t\t\t\tthis.flushUpdates()\n\t\t\t}\n\t\t}))\n\t}\n\n\tpublic syncTransaction<T>(transaction: () => T) {\n\t\ttry {\n\t\t\tthis.transactionDepth++\n\t\t\treturn transaction()\n\t\t} finally {\n\t\t\tthis.transactionDepth--\n\t\t}\n\t}\n\tpublic syncOperation<T>(operation: () => T) {\n\t\tconst result = this.syncTransaction(operation)\n\t\tthis.flushUpdates()\n\t\treturn result\n\t}\n\n\tpublic async asyncTransaction<T>(transaction: () => Promise<T>): Promise<T> {\n\t\ttry {\n\t\t\tthis.transactionDepth++\n\t\t\treturn await transaction()\n\t\t} finally {\n\t\t\tthis.transactionDepth--\n\t\t}\n\t}\n\tpublic async asyncOperation<T>(operation: () => Promise<T>): Promise<T> {\n\t\tconst result = await this.asyncTransaction(operation)\n\t\tthis.flushUpdates()\n\t\treturn result\n\t}\n\n\tprivate flushUpdates() {\n\t\tif (this.transactionDepth > 0) {\n\t\t\treturn\n\t\t}\n\n\t\tif (this.isFrozenWhileUpdating) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Trying to perform an update while the whole accessor tree is already updating. This is most likely caused ` +\n\t\t\t\t\t`by updating the accessor tree while rendering or from within the 'update' event handler, which is a no-op. ` +\n\t\t\t\t\t`If you wish to mutate the tree in reaction to other changes, use the 'beforeUpdate' event.`,\n\t\t\t)\n\t\t}\n\n\t\tconst newMetadata = this.getNewUpdateMetadata()\n\n\t\tif (!this.shouldFlushUpdates(newMetadata)) {\n\t\t\treturn\n\t\t}\n\n\t\tReactDOM.unstable_batchedUpdates(() => {\n\t\t\tthis.isFrozenWhileUpdating = true\n\t\t\tthis.triggerBeforeFlushEvents()\n\t\t\tthis.onUpdate(newMetadata)\n\t\t\tthis.flushPendingAccessorUpdates(Array.from(this.rootsWithPendingUpdates))\n\n\t\t\tthis.rootsWithPendingUpdates.clear()\n\t\t\tthis.isFrozenWhileUpdating = false\n\t\t\tthis.previousMetadata = newMetadata\n\t\t})\n\t}\n\n\tprivate getNewUpdateMetadata(): UpdateMetadata {\n\t\treturn {\n\t\t\tisMutating: this.isMutating,\n\t\t}\n\t}\n\n\tprivate shouldFlushUpdates(newMetadata: UpdateMetadata): boolean {\n\t\tif (this.transactionDepth > 0) {\n\t\t\treturn false\n\t\t}\n\t\tif (this.previousMetadata === undefined) {\n\t\t\treturn true\n\t\t}\n\t\tif (this.rootsWithPendingUpdates.size) {\n\t\t\treturn true\n\t\t}\n\t\tfor (const key in newMetadata) {\n\t\t\tconst fromPrevious = this.previousMetadata[key as keyof UpdateMetadata]\n\t\t\tconst fromNew = newMetadata[key as keyof UpdateMetadata]\n\n\t\t\tif (!Object.is(fromPrevious, fromNew)) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n\n\tpublic registerNewlyInitialized(newlyInitialized: StateNode) {\n\t\tconst initializeListeners = this.getEventListeners(newlyInitialized, { type: 'initialize' })\n\n\t\tif (initializeListeners === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.newlyInitializedWithListeners.add(newlyInitialized)\n\n\t\tif (this.transactionDepth === 0) {\n\t\t\tthis.triggerOnInitialize()\n\t\t}\n\t}\n\n\tpublic registerUpdatedConnection(parentState: EntityRealmState, placeholderName: PlaceholderName) {\n\t\tif (parentState.fieldsWithPendingConnectionUpdates === undefined) {\n\t\t\tparentState.fieldsWithPendingConnectionUpdates = new Set()\n\t\t}\n\n\t\tconst marker = getEntityMarker(parentState)\n\t\tplaceholders: for (const [fieldName, placeholdersByField] of marker.fields.placeholders) {\n\t\t\tif (typeof placeholdersByField === 'string') {\n\t\t\t\tif (placeholdersByField === placeholderName) {\n\t\t\t\t\tparentState.fieldsWithPendingConnectionUpdates.add(fieldName)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (const placeholderByFieldName of placeholdersByField) {\n\t\t\t\t\tif (placeholderByFieldName === placeholderName) {\n\t\t\t\t\t\tparentState.fieldsWithPendingConnectionUpdates.add(fieldName)\n\t\t\t\t\t\tcontinue placeholders\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic registerJustUpdated(justUpdated: StateNode, changesDelta: number) {\n\t\tconst beforeUpdateListeners = this.getEventListeners(justUpdated, { type: 'beforeUpdate' })\n\t\tif (beforeUpdateListeners !== undefined) {\n\t\t\tthis.pendingWithBeforeUpdate.add(justUpdated)\n\t\t}\n\t\tjustUpdated.accessor = undefined\n\n\t\tswitch (justUpdated.type) {\n\t\t\tcase 'entityRealm':\n\t\t\tcase 'entityList': {\n\t\t\t\tjustUpdated.unpersistedChangesCount += changesDelta\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tif (justUpdated.unpersistedChangesCount < 0) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`We have *JUST* reached a completely invalid state. From now on, anything can (and likely will) ` +\n\t\t\t\t\t\t\t\t`go wrong. This is definitely a bug. Please try to report whatever led to this situation.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst parent = justUpdated.blueprint.parent\n\n\t\t\t\tif (parent === undefined) {\n\t\t\t\t\tthis.rootsWithPendingUpdates.add(justUpdated)\n\t\t\t\t\tthis.dirtinessTracker.increaseBy(changesDelta)\n\t\t\t\t} else {\n\t\t\t\t\tif (!parent.childrenWithPendingUpdates) {\n\t\t\t\t\t\tparent.childrenWithPendingUpdates = new Set()\n\t\t\t\t\t}\n\t\t\t\t\tparent.childrenWithPendingUpdates.add(justUpdated as any)\n\t\t\t\t\tthis.registerJustUpdated(parent, changesDelta)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'field': {\n\t\t\t\tconst parent = justUpdated.parent\n\t\t\t\tif (!parent.childrenWithPendingUpdates) {\n\t\t\t\t\tparent.childrenWithPendingUpdates = new Set()\n\t\t\t\t}\n\t\t\t\tparent.childrenWithPendingUpdates.add(justUpdated as any)\n\t\t\t\tthis.registerJustUpdated(justUpdated.parent, changesDelta)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate flushPendingAccessorUpdates(rootStates: Array<StateINode>) {\n\t\t// It is *CRUCIAL* that this is a BFS so that we update the components in top-down order.\n\t\tconst agenda: StateNode[] = rootStates\n\n\t\tfor (const state of agenda) {\n\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\tconst updateListeners =\n\t\t\t\tstate.type === 'field'\n\t\t\t\t\t? this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\t\t\t\t\t: state.type === 'entityRealm'\n\t\t\t\t\t? this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\t\t\t\t\t: this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\n\t\t\tif (updateListeners !== undefined) {\n\t\t\t\tfor (const handler of updateListeners) {\n\t\t\t\t\t// TS can't quite handle the polymorphism here but this is fine.\n\t\t\t\t\thandler()\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (state.type === 'entityRealm' && state.fieldsWithPendingConnectionUpdates) {\n\t\t\t\tfor (const updatedField of state.fieldsWithPendingConnectionUpdates) {\n\t\t\t\t\tconst listeners = this.getEventListeners(state, { type: 'connectionUpdate', key: updatedField })\n\t\t\t\t\tif (!listeners) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tlistener(state.getAccessor())\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tswitch (state.type) {\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (state.childrenWithPendingUpdates !== undefined) {\n\t\t\t\t\t\tfor (const childState of state.childrenWithPendingUpdates) {\n\t\t\t\t\t\t\tagenda.push(childState)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstate.childrenWithPendingUpdates.clear()\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'field':\n\t\t\t\t\t// Do nothing\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\tassertNever(state)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async triggerAsyncMutatingEvent(eventType: 'beforePersist', options: AsyncBatchUpdatesOptions): Promise<void>\n\tprivate async triggerAsyncMutatingEvent(eventType: 'persistSuccess', options: PersistSuccessOptions): Promise<void>\n\tprivate async triggerAsyncMutatingEvent(\n\t\teventType: 'beforePersist' | 'persistSuccess',\n\t\toptions: AsyncBatchUpdatesOptions | PersistSuccessOptions,\n\t): Promise<void> {\n\t\tawait this.asyncTransaction(async () => {\n\t\t\t// TODO if an entity from here (or its parent) gets deleted, we need to remove stale handlers from here.\n\t\t\tconst callbackQueue: Array<\n\t\t\t\t[\n\t\t\t\t\t// The typings could be nicer but TS…\n\t\t\t\t\tStateINode,\n\t\t\t\t\t(\n\t\t\t\t\t\t| EntityAccessor.EntityEventListenerMap[typeof eventType]\n\t\t\t\t\t\t| EntityListAccessor.EntityListEventListenerMap[typeof eventType]\n\t\t\t\t\t),\n\t\t\t\t]\n\t\t\t> = []\n\n\t\t\tfor (const [, subTreeState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const iNode of StateIterator.depthFirstINodes(subTreeState)) {\n\t\t\t\t\tconst listeners = this.getEventListeners(iNode, { type: eventType }) ?? []\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tcallbackQueue.push([iNode, listener])\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (\n\t\t\t\tlet waterfallDepth = 0;\n\t\t\t\twaterfallDepth < this.config.getValue(`${eventType}SettleLimit` as const);\n\t\t\t\twaterfallDepth++\n\t\t\t) {\n\t\t\t\tconst promiseReturns: Array<\n\t\t\t\t\tPromise<\n\t\t\t\t\t\t| void\n\t\t\t\t\t\t| EntityAccessor.EntityEventListenerMap[typeof eventType]\n\t\t\t\t\t\t| EntityListAccessor.EntityListEventListenerMap[typeof eventType]\n\t\t\t\t\t>\n\t\t\t\t> = []\n\t\t\t\tconst correspondingStates: Array<StateINode> = []\n\n\t\t\t\tif (callbackQueue.length === 0) {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\n\t\t\t\tfor (const [state, callback] of callbackQueue) {\n\t\t\t\t\tcorrespondingStates.push(state)\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = callback(state.getAccessor as any, options as any) // TS can't quite handle this but this is sound.\n\t\t\t\t\t\tif (result instanceof Promise) {\n\t\t\t\t\t\t\tpromiseReturns.push(result)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tpromiseReturns.push(Promise.resolve(result))\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tpromiseReturns.push(Promise.reject(e))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// TODO timeout\n\n\t\t\t\tconst newCallbacks = await this.executeWithoutChanges(eventType, () => Promise.allSettled(promiseReturns))\n\n\t\t\t\tcallbackQueue.length = 0 // Empties the queue\n\n\t\t\t\t// TODO we're drifting away from the original depth-first order. Let's see if that's ever even an issue.\n\t\t\t\tfor (const newlyInitialized of this.newlyInitializedWithListeners) {\n\t\t\t\t\tif (newlyInitialized.type === 'field') {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst beforePersistHandlers = this.getEventListeners(newlyInitialized, { type: eventType })\n\t\t\t\t\tif (beforePersistHandlers) {\n\t\t\t\t\t\tfor (const listener of beforePersistHandlers) {\n\t\t\t\t\t\t\tcallbackQueue.push([newlyInitialized, listener])\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.triggerBeforeFlushEvents()\n\t\t\t\tthis.handleRejections(eventType, newCallbacks)\n\n\t\t\t\tfor (let i = 0; i < newCallbacks.length; i++) {\n\t\t\t\t\tconst result = newCallbacks[i]\n\t\t\t\t\tconst correspondingState = correspondingStates[i]\n\n\t\t\t\t\tif (result.status === 'fulfilled') {\n\t\t\t\t\t\tif (typeof result.value === 'function') {\n\t\t\t\t\t\t\tcallbackQueue.push([correspondingState, result.value])\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Otherwise do nothing. This is just a handler that albeit async, doesn't appear to\n\t\t\t\t\t\t// interact with data binding.\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\tif (callbackQueue.length) {\n\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t`Exceeded the ${eventType} settle limit. Your code likely contains a deadlock. ` +\n\t\t\t\t\t\t\t`If that's not the case, raise the settle limit from DataBindingProvider.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate triggerBeforeFlushEvents() {\n\t\tthis.syncTransaction(() => {\n\t\t\tconst settleLimit = this.config.getValue('beforeUpdateSettleLimit')\n\n\t\t\tfor (let attemptNumber = 0; attemptNumber < settleLimit; attemptNumber++) {\n\t\t\t\tif (!this.pendingWithBeforeUpdate.size) {\n\t\t\t\t\tthis.triggerOnInitialize()\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst withBeforeUpdate = this.pendingWithBeforeUpdate\n\t\t\t\tthis.pendingWithBeforeUpdate = new Set()\n\n\t\t\t\tfor (const state of withBeforeUpdate) {\n\t\t\t\t\tconst listeners = this.getEventListeners(state, { type: 'beforeUpdate' })\n\t\t\t\t\tif (listeners === undefined) {\n\t\t\t\t\t\t// This can happen if the listener has unsubscribed since we added it to the set.\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tswitch (state.type) {\n\t\t\t\t\t\tcase 'field':\n\t\t\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\t\t\t(listener as FieldAccessor.BeforeUpdateListener)(state.getAccessor())\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\t\t\tstate.getAccessor().batchUpdates(listener as any)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn assertNever(state)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.triggerOnInitialize()\n\t\t\t}\n\t\t\tthrow new BindingError(\n\t\t\t\t`Maximum stabilization limit of updates caused by 'beforeUpdate' exceeded. ` +\n\t\t\t\t\t`This likely means there is an infinite feedback loop in your code.`,\n\t\t\t)\n\t\t})\n\t}\n\n\tprivate triggerOnInitialize() {\n\t\tthis.syncTransaction(() => {\n\t\t\tfor (const state of this.newlyInitializedWithListeners) {\n\t\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\t\tconst listeners =\n\t\t\t\t\tstate.type === 'field'\n\t\t\t\t\t\t? this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\t\t\t\t\t\t: state.type === 'entityRealm'\n\t\t\t\t\t\t? this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\t\t\t\t\t\t: this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\n\t\t\t\tif (listeners) {\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tlistener()\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (state.type === 'entityRealm') {\n\t\t\t\t\tstate.entity.hasIdSetInStone = true\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.newlyInitializedWithListeners.clear()\n\t\t})\n\t}\n\n\tpublic async triggerOnPersistError(options: PersistErrorOptions) {\n\t\tawait this.asyncTransaction(async () => {\n\t\t\tconst handlerPromises: Array<Promise<void>> = []\n\n\t\t\tfor (const [, subTreeState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const iNode of StateIterator.depthFirstINodes(subTreeState)) {\n\t\t\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\t\t\tconst dispatchers =\n\t\t\t\t\t\tiNode.type === 'entityRealm'\n\t\t\t\t\t\t\t? this.getEventDispatchers(iNode, { type: 'persistError' }, [iNode.getAccessor, options])\n\t\t\t\t\t\t\t: this.getEventDispatchers(iNode, { type: 'persistError' }, [iNode.getAccessor, options])\n\t\t\t\t\tif (dispatchers === undefined) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const listener of dispatchers ?? []) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst result = listener()\n\t\t\t\t\t\t\tif (result instanceof Promise) {\n\t\t\t\t\t\t\t\thandlerPromises.push(result)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\thandlerPromises.push(Promise.resolve(result))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\thandlerPromises.push(Promise.reject(e))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// TODO timeout\n\t\t\tconst handlerResults = await Promise.allSettled(handlerPromises)\n\t\t\tthis.handleRejections('persistError', handlerResults)\n\t\t})\n\t}\n\n\tpublic async triggerOnBeforePersist() {\n\t\treturn this.triggerAsyncMutatingEvent('beforePersist', this.asyncBatchUpdatesOptions)\n\t}\n\n\tpublic async triggerOnPersistSuccess(options: PersistSuccessOptions) {\n\t\treturn this.triggerAsyncMutatingEvent('persistSuccess', options)\n\t}\n\n\tpublic getEventListeners<\n\t\tState extends StateNode,\n\t\tEventListenerTypes extends\n\t\t\tExclude<State['eventListeners'], undefined> extends EventListenersStore<infer Keys, infer Map> ? [Keys, Map] : never,\n\t\tEventType extends EventListenerTypes[0],\n\t>(state: State, event: { type: EventType; key?: string }): Set<Exclude<EventListenerTypes[1][EventType], undefined>> | undefined {\n\t\tif (!state.eventListeners) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn (state.eventListeners as EventListenersStore<EventType, EventListenerTypes[1]>).get(event) as Set<\n\t\t\tExclude<EventListenerTypes[1][EventType], undefined>\n\t\t>\n\t}\n\n\tpublic getEventDispatchers<\n\t\tState extends StateNode,\n\t\tEventListenerTypes extends\n\t\t\tExclude<State['eventListeners'], undefined> extends EventListenersStore<infer Keys, infer Map> ? [Keys, Map] : never,\n\t\tEventType extends EventListenerTypes[0],\n\t>(\n\t\tstate: State,\n\t\tevent: { type: EventType; key?: string },\n\t\tlistenerArgs: Parameters<Exclude<EventListenerTypes[1][EventType], undefined>>,\n\t): Array<() => ReturnType<Exclude<EventListenerTypes[1][EventType], undefined>>> | undefined {\n\t\tconst eventListeners = this.getEventListeners(state, event)\n\t\tif (eventListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn Array.from(eventListeners.values(), listener => {\n\t\t\treturn () => listener(...listenerArgs)\n\t\t}) as Array<() => ReturnType<Exclude<EventListenerTypes[1][EventType], undefined>>>\n\t}\n\n\tprivate handleRejections(handler: string, promises: PromiseSettledResult<any>[]) {\n\t\tconst rejections = promises.filter((it): it is PromiseRejectedResult => it.status === 'rejected')\n\t\tif (rejections.length === 0) {\n\t\t\treturn\n\t\t}\n\t\trejections.forEach(it => console.error(it.reason))\n\t\tif (import.meta.env.DEV) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`A ${handler} handler returned a promise that rejected. ` +\n\t\t\t\t\t`This is a no-op that will fail silently in production.`,\n\t\t\t)\n\t\t}\n\t}\n\n\tprivate async executeWithoutChanges<T>(eventType: string, cb: () => Promise<T>): Promise<T> {\n\t\tconst changesCountBefore = this.dirtinessTracker.getTotalChangesCount()\n\t\tconst result = await cb()\n\t\tconst changesCountAfter = this.dirtinessTracker.getTotalChangesCount()\n\t\tif (import.meta.env.DEV) {\n\t\t\tif (changesCountBefore !== changesCountAfter) {\n\t\t\t\t// This isn't bulletproof. They could e.g. undo a change and make another one which would\n\t\t\t\t// slip through this detection. But for most cases, it should be good enough and not too expensive.\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`A ${eventType} event handler cannot be asynchronous and alter the accessor tree at the same time. ` +\n\t\t\t\t\t\t`To achieve this, prepare your data asynchronously but only touch the tree from a returned callback.`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;AA8BO,MAAM,aAAa;AAAA,EAiBlB,YACW,0BACA,qBACA,QACA,kBACA,UACA,WAChB;AArBM,4CAAmB;AACnB,iDAAwB;AAIxB,sCAAsB;AACtB;AAEA;AAEA,6EAA0F;AAC1F,uEAA8C;AAC9C,uEAAkD;AAGxC,SAAA,2BAAA;AACA,SAAA,sBAAA;AACA,SAAA,SAAA;AACA,SAAA,mBAAA;AACA,SAAA,WAAA;AACA,SAAA,YAAA;AAAA,EACf;AAAA,QAEU,iBAAiB,WAAqF;AAC9G,QAAA,KAAK,mBAAmB,GAAG;AACxB,YAAA,IAAI,aAAa,mDAAmD;AAAA,IAC3E;AACA,UAAM,mBAAmB,KAAK;AAC9B,QAAI,qBAAqB,QAAW;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C5F,QAAA,WAAW,WAAW,GAAG;AAC5B;AAAA,IACD;AACA,eAAW,QAAQ,CAAM,OAAA,QAAQ,MAAM,GAAG,MAAM,CAAC;AAAA,EAOlD;AAAA,QAEc,sBAAyB,WAAmB,IAAkC;AAChE,SAAK,iBAAiB,qBAAqB;AAChE,UAAA,SAAS,MAAM;AACK,SAAK,iBAAiB,qBAAqB;AAW9D,WAAA;AAAA,EACR;AACD;AApiBwB,cADjB,cACiB,yBAAwB;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"IncrementalMarkerBuilder.js","sources":["../../../src/core/IncrementalMarkerBuilder.ts"],"sourcesContent":["import { EntityFieldMarker, EntityFieldMarkersContainer, EntityFieldsWithHoistablesMarker } from '../markers'\nimport { MarkerFactory } from '../queryLanguage'\nimport { MarkerMerger } from './MarkerMerger'\nimport { TreeParameterMerger } from './TreeParameterMerger'\n\nexport class IncrementalMarkerBuilder {\n\tprivate accumulator: EntityFieldsWithHoistablesMarker | EntityFieldMarkersContainer = new EntityFieldMarkersContainer(\n\t\tfalse,\n\t\tnew Map(),\n\t\tnew Map(),\n\t)\n\n\tpublic mutateIn(addition: EntityFieldMarker | EntityFieldMarkersContainer | EntityFieldsWithHoistablesMarker) {\n\t\tif (addition instanceof EntityFieldMarkersContainer) {\n\t\t\tif (this.accumulator instanceof EntityFieldMarkersContainer) {\n\t\t\t\tthis.accumulator = MarkerMerger.mergeEntityFieldsContainers(this.accumulator, addition)\n\t\t\t} else {\n\t\t\t\tthis.accumulator = new EntityFieldsWithHoistablesMarker(\n\t\t\t\t\tMarkerMerger.mergeEntityFieldsContainers(this.accumulator.fields, addition),\n\t\t\t\t\tthis.accumulator.subTrees,\n\t\t\t\t\tthis.accumulator.parentReference,\n\t\t\t\t)\n\t\t\t}\n\t\t} else if (addition instanceof EntityFieldsWithHoistablesMarker) {\n\t\t\tif (this.accumulator instanceof EntityFieldMarkersContainer) {\n\t\t\t\tthis.accumulator = new EntityFieldsWithHoistablesMarker(\n\t\t\t\t\tMarkerMerger.mergeEntityFieldsContainers(this.accumulator, addition.fields),\n\t\t\t\t\taddition.subTrees,\n\t\t\t\t\taddition.parentReference,\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tthis.accumulator = new EntityFieldsWithHoistablesMarker(\n\t\t\t\t\tMarkerMerger.mergeEntityFieldsContainers(this.accumulator.fields, addition.fields),\n\t\t\t\t\tMarkerMerger.mergeSubTreeMarkers(this.accumulator.subTrees, addition.subTrees),\n\t\t\t\t\tTreeParameterMerger.mergeParentEntityParameters(this.accumulator.parentReference, addition.parentReference),\n\t\t\t\t)\n\t\t\t}\n\t\t} else {\n\t\t\tif (this.accumulator instanceof EntityFieldMarkersContainer) {\n\t\t\t\tthis.accumulator = MarkerMerger.mergeEntityFieldsContainers(\n\t\t\t\t\tthis.accumulator,\n\t\t\t\t\tMarkerFactory.createEntityFieldMarkersContainer(addition),\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tthis.accumulator = new EntityFieldsWithHoistablesMarker(\n\t\t\t\t\tMarkerMerger.mergeEntityFieldsContainers(\n\t\t\t\t\t\tthis.accumulator.fields,\n\t\t\t\t\t\tMarkerFactory.createEntityFieldMarkersContainer(addition),\n\t\t\t\t\t),\n\t\t\t\t\tthis.accumulator.subTrees,\n\t\t\t\t\tthis.accumulator.parentReference,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic getFinalMarker() {\n\t\treturn this.accumulator\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;+BAKsC;AAAA;AAC7B,uCAA8E,IAAI,4BACzF,2BACI,2BACA;AAAA;AAAA,EAGE,SAAS,UAA8F;QACzG,oBAAoB,6BAA6B;UAChD,KAAK,uBAAuB,6BAA6B;aACvD,cAAc,aAAa,4BAA4B,KAAK,aAAa;AAAA,aACxE;aACD,cAAc,IAAI,iCACtB,aAAa,4BAA4B,KAAK,YAAY,QAAQ,WAClE,KAAK,YAAY,UACjB,KAAK,YAAY;AAAA;AAAA,eAGT,oBAAoB,kCAAkC;UAC5D,KAAK,uBAAuB,6BAA6B;aACvD,cAAc,IAAI,iCACtB,aAAa,4BAA4B,KAAK,aAAa,SAAS,SACpE,SAAS,UACT,SAAS;AAAA,aAEJ;aACD,cAAc,IAAI,iCACtB,aAAa,4BAA4B,KAAK,YAAY,QAAQ,SAAS,SAC3E,aAAa,oBAAoB,KAAK,YAAY,UAAU,SAAS,WACrE,oBAAoB,4BAA4B,KAAK,YAAY,iBAAiB,SAAS;AAAA;AAAA,WAGvF;UACF,KAAK,uBAAuB,6BAA6B;aACvD,cAAc,aAAa,4BAC/B,KAAK,aACL,cAAc,kCAAkC;AAAA,aAE3C;aACD,cAAc,IAAI,iCACtB,aAAa,4BACZ,KAAK,YAAY,QACjB,cAAc,kCAAkC,YAEjD,KAAK,YAAY,UACjB,KAAK,YAAY;AAAA;AAAA;AAAA;AAAA,EAMd,iBAAiB;WAChB,KAAK;AAAA;AAAA;;"}
1
+ {"version":3,"file":"IncrementalMarkerBuilder.js","sources":["../../../src/core/IncrementalMarkerBuilder.ts"],"sourcesContent":["import { EntityFieldMarker, EntityFieldMarkersContainer, EntityFieldsWithHoistablesMarker } from '../markers'\nimport { MarkerFactory } from '../queryLanguage'\nimport { MarkerMerger } from './MarkerMerger'\nimport { TreeParameterMerger } from './TreeParameterMerger'\n\nexport class IncrementalMarkerBuilder {\n\tprivate accumulator: EntityFieldsWithHoistablesMarker | EntityFieldMarkersContainer = new EntityFieldMarkersContainer(\n\t\tfalse,\n\t\tnew Map(),\n\t\tnew Map(),\n\t)\n\n\tpublic mutateIn(addition: EntityFieldMarker | EntityFieldMarkersContainer | EntityFieldsWithHoistablesMarker) {\n\t\tif (addition instanceof EntityFieldMarkersContainer) {\n\t\t\tif (this.accumulator instanceof EntityFieldMarkersContainer) {\n\t\t\t\tthis.accumulator = MarkerMerger.mergeEntityFieldsContainers(this.accumulator, addition)\n\t\t\t} else {\n\t\t\t\tthis.accumulator = new EntityFieldsWithHoistablesMarker(\n\t\t\t\t\tMarkerMerger.mergeEntityFieldsContainers(this.accumulator.fields, addition),\n\t\t\t\t\tthis.accumulator.subTrees,\n\t\t\t\t\tthis.accumulator.parentReference,\n\t\t\t\t)\n\t\t\t}\n\t\t} else if (addition instanceof EntityFieldsWithHoistablesMarker) {\n\t\t\tif (this.accumulator instanceof EntityFieldMarkersContainer) {\n\t\t\t\tthis.accumulator = new EntityFieldsWithHoistablesMarker(\n\t\t\t\t\tMarkerMerger.mergeEntityFieldsContainers(this.accumulator, addition.fields),\n\t\t\t\t\taddition.subTrees,\n\t\t\t\t\taddition.parentReference,\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tthis.accumulator = new EntityFieldsWithHoistablesMarker(\n\t\t\t\t\tMarkerMerger.mergeEntityFieldsContainers(this.accumulator.fields, addition.fields),\n\t\t\t\t\tMarkerMerger.mergeSubTreeMarkers(this.accumulator.subTrees, addition.subTrees),\n\t\t\t\t\tTreeParameterMerger.mergeParentEntityParameters(this.accumulator.parentReference, addition.parentReference),\n\t\t\t\t)\n\t\t\t}\n\t\t} else {\n\t\t\tif (this.accumulator instanceof EntityFieldMarkersContainer) {\n\t\t\t\tthis.accumulator = MarkerMerger.mergeEntityFieldsContainers(\n\t\t\t\t\tthis.accumulator,\n\t\t\t\t\tMarkerFactory.createEntityFieldMarkersContainer(addition),\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tthis.accumulator = new EntityFieldsWithHoistablesMarker(\n\t\t\t\t\tMarkerMerger.mergeEntityFieldsContainers(\n\t\t\t\t\t\tthis.accumulator.fields,\n\t\t\t\t\t\tMarkerFactory.createEntityFieldMarkersContainer(addition),\n\t\t\t\t\t),\n\t\t\t\t\tthis.accumulator.subTrees,\n\t\t\t\t\tthis.accumulator.parentReference,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic getFinalMarker() {\n\t\treturn this.accumulator\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAKO,MAAM,yBAAyB;AAAA,EAA/B;AACE,uCAA8E,IAAI,4BACzF,2BACI,OACA,oBAAA,IAAA,CACL;AAAA;AAAA,EAEO,SAAS,UAA8F;AAC7G,QAAI,oBAAoB,6BAA6B;AAChD,UAAA,KAAK,uBAAuB,6BAA6B;AAC5D,aAAK,cAAc,aAAa,4BAA4B,KAAK,aAAa,QAAQ;AAAA,MAAA,OAChF;AACN,aAAK,cAAc,IAAI,iCACtB,aAAa,4BAA4B,KAAK,YAAY,QAAQ,QAAQ,GAC1E,KAAK,YAAY,UACjB,KAAK,YAAY,eAClB;AAAA,MACD;AAAA,IAAA,WACU,oBAAoB,kCAAkC;AAC5D,UAAA,KAAK,uBAAuB,6BAA6B;AAC5D,aAAK,cAAc,IAAI,iCACtB,aAAa,4BAA4B,KAAK,aAAa,SAAS,MAAM,GAC1E,SAAS,UACT,SAAS,eACV;AAAA,MAAA,OACM;AACD,aAAA,cAAc,IAAI,iCACtB,aAAa,4BAA4B,KAAK,YAAY,QAAQ,SAAS,MAAM,GACjF,aAAa,oBAAoB,KAAK,YAAY,UAAU,SAAS,QAAQ,GAC7E,oBAAoB,4BAA4B,KAAK,YAAY,iBAAiB,SAAS,eAAe,CAC3G;AAAA,MACD;AAAA,IAAA,OACM;AACF,UAAA,KAAK,uBAAuB,6BAA6B;AACvD,aAAA,cAAc,aAAa,4BAC/B,KAAK,aACL,cAAc,kCAAkC,QAAQ,CACzD;AAAA,MAAA,OACM;AACN,aAAK,cAAc,IAAI,iCACtB,aAAa,4BACZ,KAAK,YAAY,QACjB,cAAc,kCAAkC,QAAQ,CACzD,GACA,KAAK,YAAY,UACjB,KAAK,YAAY,eAClB;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA,EAEO,iBAAiB;AACvB,WAAO,KAAK;AAAA,EACb;AACD;;"}
@@ -1,6 +1,6 @@
1
1
  import { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from "../bindingTypes.js";
2
- import { FieldMarker } from "../markers/FieldMarker.js";
3
2
  import { LocalizedBindingError } from "./exceptions/LocalizedBindingError.js";
3
+ import { FieldMarker } from "../markers/FieldMarker.js";
4
4
  import { HasOneRelationMarker } from "../markers/HasOneRelationMarker.js";
5
5
  import { HasManyRelationMarker } from "../markers/HasManyRelationMarker.js";
6
6
  import { assertNever } from "../utils/assertNever.js";
@@ -1 +1 @@
1
- {"version":3,"file":"MarkerComparator.js","sources":["../../../src/core/MarkerComparator.ts"],"sourcesContent":["import { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '../bindingTypes'\nimport {\n\tEntityFieldMarkersContainer,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n} from '../markers'\nimport { assertNever } from '../utils'\nimport { LocalizedBindingError } from './exceptions'\n\nexport class MarkerComparator {\n\tpublic static isSubTreeSubsetOf(\n\t\tcandidate: EntitySubTreeMarker | EntityListSubTreeMarker,\n\t\tsuperset: EntitySubTreeMarker | EntityListSubTreeMarker,\n\t): boolean {\n\t\tif (candidate.placeholderName !== superset.placeholderName) {\n\t\t\treturn false\n\t\t}\n\t\treturn this.isSubsetOf(candidate.fields, superset.fields)\n\t}\n\n\tpublic static assertEntityMarkersSubsetOf(\n\t\tcandidate: EntityFieldMarkersContainer,\n\t\tsuperset: EntityFieldMarkersContainer,\n\t) {\n\t\tthis.assertSubsetOf(candidate, superset)\n\t}\n\n\tprivate static assertSubsetOf(candidate: EntityFieldMarkersContainer, superset: EntityFieldMarkersContainer) {\n\t\tfor (const [placeholderName, candidateMarker] of candidate.markers) {\n\t\t\tconst fromSuperset = superset.markers.get(placeholderName)\n\n\t\t\tif (fromSuperset === undefined) {\n\t\t\t\tif (candidateMarker instanceof FieldMarker) {\n\t\t\t\t\tif (candidateMarker.fieldName === PRIMARY_KEY_NAME || candidateMarker.fieldName === TYPENAME_KEY_NAME) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tthrow new LocalizedBindingError(`The field '${candidateMarker.fieldName}' is missing.`, [candidateMarker])\n\t\t\t\t}\n\t\t\t\tif (candidateMarker instanceof HasOneRelationMarker || candidateMarker instanceof HasManyRelationMarker) {\n\t\t\t\t\tconst differentPlaceholders = superset.placeholders.get(candidateMarker.parameters.field)\n\n\t\t\t\t\tif (differentPlaceholders === undefined) {\n\t\t\t\t\t\tthrow new LocalizedBindingError(`The relation '${candidateMarker.parameters.field}' is missing.`, [\n\t\t\t\t\t\t\tcandidateMarker,\n\t\t\t\t\t\t])\n\t\t\t\t\t}\n\t\t\t\t\t// TODO be more specific\n\t\t\t\t\tthrow new LocalizedBindingError(\n\t\t\t\t\t\t`The relation '${candidateMarker.parameters.field}' exists but its parameters don't match exactly. ` +\n\t\t\t\t\t\t\t`Check that all relation parameters are the same.`,\n\t\t\t\t\t\t[candidateMarker],\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tassertNever(candidateMarker)\n\t\t\t}\n\t\t\tif (candidateMarker instanceof FieldMarker) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tif (\n\t\t\t\t\t(candidateMarker instanceof HasOneRelationMarker && fromSuperset instanceof HasOneRelationMarker) ||\n\t\t\t\t\t(candidateMarker instanceof HasManyRelationMarker && fromSuperset instanceof HasManyRelationMarker)\n\t\t\t\t) {\n\t\t\t\t\tthis.assertSubsetOf(candidateMarker.fields, fromSuperset.fields)\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tif (e instanceof LocalizedBindingError) {\n\t\t\t\t\tthrow e.nestedIn(candidateMarker)\n\t\t\t\t}\n\t\t\t\tthrow e\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static isSubsetOf(candidate: EntityFieldMarkersContainer, superset: EntityFieldMarkersContainer): boolean {\n\t\tfor (const [placeholderName, candidateMarker] of candidate.markers) {\n\t\t\tconst fromSuperset = superset.markers.get(placeholderName)\n\n\t\t\tif (fromSuperset === undefined) {\n\t\t\t\tif (\n\t\t\t\t\tcandidateMarker instanceof FieldMarker &&\n\t\t\t\t\t(candidateMarker.fieldName === PRIMARY_KEY_NAME || candidateMarker.fieldName === TYPENAME_KEY_NAME)\n\t\t\t\t) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\treturn false\n\t\t\t}\n\t\t\tif (candidateMarker instanceof FieldMarker || fromSuperset instanceof FieldMarker) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (!this.isSubsetOf(candidateMarker.fields, fromSuperset.fields)) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\n\t//private static assertAreMarkersSubsetOf(): {}\n}\n"],"names":[],"mappings":";;;;;;uBAY8B;AAAA,SACf,kBACb,WACA,UACU;QACN,UAAU,oBAAoB,SAAS,iBAAiB;aACpD;AAAA;WAED,KAAK,WAAW,UAAU,QAAQ,SAAS;AAAA;AAAA,SAGrC,4BACb,WACA,UACC;SACI,eAAe,WAAW;AAAA;AAAA,SAGjB,eAAe,WAAwC,UAAuC;eACjG,CAAC,iBAAiB,oBAAoB,UAAU,SAAS;YAC7D,eAAe,SAAS,QAAQ,IAAI;UAEtC,iBAAiB,QAAW;YAC3B,2BAA2B,aAAa;cACvC,gBAAgB,cAAc,oBAAoB,gBAAgB,cAAc,mBAAmB;;;gBAGjG,IAAI,sBAAsB,cAAc,gBAAgB,0BAA0B,CAAC;AAAA;YAEtF,2BAA2B,wBAAwB,2BAA2B,uBAAuB;gBAClG,wBAAwB,SAAS,aAAa,IAAI,gBAAgB,WAAW;cAE/E,0BAA0B,QAAW;kBAClC,IAAI,sBAAsB,iBAAiB,gBAAgB,WAAW,sBAAsB;AAAA,cACjG;AAAA;AAAA;gBAII,IAAI,sBACT,iBAAiB,gBAAgB,WAAW,0GAE5C,CAAC;AAAA;;;UAKA,2BAA2B,aAAa;;;UAGxC;YAED,2BAA2B,wBAAwB,wBAAwB,wBAC3E,2BAA2B,yBAAyB,wBAAwB,uBAC5E;eACI,eAAe,gBAAgB,QAAQ,aAAa;AAAA;AAAA,eAElD;YACJ,aAAa,uBAAuB;gBACjC,EAAE,SAAS;AAAA;cAEZ;AAAA;AAAA;AAAA;AAAA,SAKM,WAAW,WAAwC,UAAgD;eACtG,CAAC,iBAAiB,oBAAoB,UAAU,SAAS;YAC7D,eAAe,SAAS,QAAQ,IAAI;UAEtC,iBAAiB,QAAW;YAE9B,2BAA2B,gCACV,cAAc,oBAAoB,gBAAgB,cAAc,oBAChF;;;eAGK;AAAA;UAEJ,2BAA2B,eAAe,wBAAwB,aAAa;;;UAG/E,CAAC,KAAK,WAAW,gBAAgB,QAAQ,aAAa,SAAS;eAC3D;AAAA;AAAA;WAGF;AAAA;AAAA;;"}
1
+ {"version":3,"file":"MarkerComparator.js","sources":["../../../src/core/MarkerComparator.ts"],"sourcesContent":["import { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '../bindingTypes'\nimport {\n\tEntityFieldMarkersContainer,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n} from '../markers'\nimport { assertNever } from '../utils'\nimport { LocalizedBindingError } from './exceptions'\n\nexport class MarkerComparator {\n\tpublic static isSubTreeSubsetOf(\n\t\tcandidate: EntitySubTreeMarker | EntityListSubTreeMarker,\n\t\tsuperset: EntitySubTreeMarker | EntityListSubTreeMarker,\n\t): boolean {\n\t\tif (candidate.placeholderName !== superset.placeholderName) {\n\t\t\treturn false\n\t\t}\n\t\treturn this.isSubsetOf(candidate.fields, superset.fields)\n\t}\n\n\tpublic static assertEntityMarkersSubsetOf(\n\t\tcandidate: EntityFieldMarkersContainer,\n\t\tsuperset: EntityFieldMarkersContainer,\n\t) {\n\t\tthis.assertSubsetOf(candidate, superset)\n\t}\n\n\tprivate static assertSubsetOf(candidate: EntityFieldMarkersContainer, superset: EntityFieldMarkersContainer) {\n\t\tfor (const [placeholderName, candidateMarker] of candidate.markers) {\n\t\t\tconst fromSuperset = superset.markers.get(placeholderName)\n\n\t\t\tif (fromSuperset === undefined) {\n\t\t\t\tif (candidateMarker instanceof FieldMarker) {\n\t\t\t\t\tif (candidateMarker.fieldName === PRIMARY_KEY_NAME || candidateMarker.fieldName === TYPENAME_KEY_NAME) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tthrow new LocalizedBindingError(`The field '${candidateMarker.fieldName}' is missing.`, [candidateMarker])\n\t\t\t\t}\n\t\t\t\tif (candidateMarker instanceof HasOneRelationMarker || candidateMarker instanceof HasManyRelationMarker) {\n\t\t\t\t\tconst differentPlaceholders = superset.placeholders.get(candidateMarker.parameters.field)\n\n\t\t\t\t\tif (differentPlaceholders === undefined) {\n\t\t\t\t\t\tthrow new LocalizedBindingError(`The relation '${candidateMarker.parameters.field}' is missing.`, [\n\t\t\t\t\t\t\tcandidateMarker,\n\t\t\t\t\t\t])\n\t\t\t\t\t}\n\t\t\t\t\t// TODO be more specific\n\t\t\t\t\tthrow new LocalizedBindingError(\n\t\t\t\t\t\t`The relation '${candidateMarker.parameters.field}' exists but its parameters don't match exactly. ` +\n\t\t\t\t\t\t\t`Check that all relation parameters are the same.`,\n\t\t\t\t\t\t[candidateMarker],\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tassertNever(candidateMarker)\n\t\t\t}\n\t\t\tif (candidateMarker instanceof FieldMarker) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tif (\n\t\t\t\t\t(candidateMarker instanceof HasOneRelationMarker && fromSuperset instanceof HasOneRelationMarker) ||\n\t\t\t\t\t(candidateMarker instanceof HasManyRelationMarker && fromSuperset instanceof HasManyRelationMarker)\n\t\t\t\t) {\n\t\t\t\t\tthis.assertSubsetOf(candidateMarker.fields, fromSuperset.fields)\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tif (e instanceof LocalizedBindingError) {\n\t\t\t\t\tthrow e.nestedIn(candidateMarker)\n\t\t\t\t}\n\t\t\t\tthrow e\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static isSubsetOf(candidate: EntityFieldMarkersContainer, superset: EntityFieldMarkersContainer): boolean {\n\t\tfor (const [placeholderName, candidateMarker] of candidate.markers) {\n\t\t\tconst fromSuperset = superset.markers.get(placeholderName)\n\n\t\t\tif (fromSuperset === undefined) {\n\t\t\t\tif (\n\t\t\t\t\tcandidateMarker instanceof FieldMarker &&\n\t\t\t\t\t(candidateMarker.fieldName === PRIMARY_KEY_NAME || candidateMarker.fieldName === TYPENAME_KEY_NAME)\n\t\t\t\t) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\treturn false\n\t\t\t}\n\t\t\tif (candidateMarker instanceof FieldMarker || fromSuperset instanceof FieldMarker) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (!this.isSubsetOf(candidateMarker.fields, fromSuperset.fields)) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\n\t//private static assertAreMarkersSubsetOf(): {}\n}\n"],"names":[],"mappings":";;;;;;AAYO,MAAM,iBAAiB;AAAA,SACf,kBACb,WACA,UACU;AACN,QAAA,UAAU,oBAAoB,SAAS,iBAAiB;AACpD,aAAA;AAAA,IACR;AACA,WAAO,KAAK,WAAW,UAAU,QAAQ,SAAS,MAAM;AAAA,EACzD;AAAA,SAEc,4BACb,WACA,UACC;AACI,SAAA,eAAe,WAAW,QAAQ;AAAA,EACxC;AAAA,SAEe,eAAe,WAAwC,UAAuC;AAC5G,eAAW,CAAC,iBAAiB,oBAAoB,UAAU,SAAS;AACnE,YAAM,eAAe,SAAS,QAAQ,IAAI,eAAe;AAEzD,UAAI,iBAAiB,QAAW;AAC/B,YAAI,2BAA2B,aAAa;AAC3C,cAAI,gBAAgB,cAAc,oBAAoB,gBAAgB,cAAc,mBAAmB;AACtG;AAAA,UACD;AACA,gBAAM,IAAI,sBAAsB,cAAc,gBAAgB,0BAA0B,CAAC,eAAe,CAAC;AAAA,QAC1G;AACI,YAAA,2BAA2B,wBAAwB,2BAA2B,uBAAuB;AACxG,gBAAM,wBAAwB,SAAS,aAAa,IAAI,gBAAgB,WAAW,KAAK;AAExF,cAAI,0BAA0B,QAAW;AACxC,kBAAM,IAAI,sBAAsB,iBAAiB,gBAAgB,WAAW,sBAAsB;AAAA,cACjG;AAAA,YAAA,CACA;AAAA,UACF;AAEM,gBAAA,IAAI,sBACT,iBAAiB,gBAAgB,WAAW,0GAE5C,CAAC,eAAe,CACjB;AAAA,QACD;AACA,oBAA2B;AAAA,MAC5B;AACA,UAAI,2BAA2B,aAAa;AAC3C;AAAA,MACD;AACI,UAAA;AACH,YACE,2BAA2B,wBAAwB,wBAAwB,wBAC3E,2BAA2B,yBAAyB,wBAAwB,uBAC5E;AACD,eAAK,eAAe,gBAAgB,QAAQ,aAAa,MAAM;AAAA,QAChE;AAAA,eACQ;AACR,YAAI,aAAa,uBAAuB;AACjC,gBAAA,EAAE,SAAS,eAAe;AAAA,QACjC;AACM,cAAA;AAAA,MACP;AAAA,IACD;AAAA,EACD;AAAA,SAEe,WAAW,WAAwC,UAAgD;AACjH,eAAW,CAAC,iBAAiB,oBAAoB,UAAU,SAAS;AACnE,YAAM,eAAe,SAAS,QAAQ,IAAI,eAAe;AAEzD,UAAI,iBAAiB,QAAW;AAC/B,YACC,2BAA2B,eAC1B,iBAAgB,cAAc,oBAAoB,gBAAgB,cAAc,oBAChF;AACD;AAAA,QACD;AACO,eAAA;AAAA,MACR;AACI,UAAA,2BAA2B,eAAe,wBAAwB,aAAa;AAClF;AAAA,MACD;AACA,UAAI,CAAC,KAAK,WAAW,gBAAgB,QAAQ,aAAa,MAAM,GAAG;AAC3D,eAAA;AAAA,MACR;AAAA,IACD;AACO,WAAA;AAAA,EACR;AAGD;;"}
@@ -198,10 +198,7 @@ class MarkerMerger {
198
198
  return original ? this.mergeEntityFieldsContainers(original, freshFields) : freshFields;
199
199
  }
200
200
  static mergeEnvironments(original, fresh) {
201
- if (original === fresh) {
202
- return original;
203
- }
204
- return original.putDelta(fresh.getAllNames());
201
+ return original.merge(fresh);
205
202
  }
206
203
  static rejectRelationScalarCombo(fieldName) {
207
204
  throw new BindingError(`Cannot combine a relation with a scalar field '${fieldName}'.`);