@contember/binding 1.1.0-alpha.9 → 1.1.0-beta.2

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 (764) hide show
  1. package/dist/development/BindingError.js +4 -1
  2. package/dist/development/BindingError.js.map +1 -1
  3. package/dist/development/accessorPropagation/AccessorProvider.js +20 -7
  4. package/dist/development/accessorPropagation/AccessorProvider.js.map +1 -1
  5. package/dist/development/accessorPropagation/BindingOperationsContext.js +7 -2
  6. package/dist/development/accessorPropagation/BindingOperationsContext.js.map +1 -1
  7. package/dist/development/accessorPropagation/BindingOperationsProvider.js +13 -5
  8. package/dist/development/accessorPropagation/BindingOperationsProvider.js.map +1 -1
  9. package/dist/development/accessorPropagation/EntityKeyContext.js +3 -1
  10. package/dist/development/accessorPropagation/EntityKeyContext.js.map +1 -1
  11. package/dist/development/accessorPropagation/EntityKeyProvider.js +13 -5
  12. package/dist/development/accessorPropagation/EntityKeyProvider.js.map +1 -1
  13. package/dist/development/accessorPropagation/EnvironmentContext.js +66 -2
  14. package/dist/development/accessorPropagation/EnvironmentContext.js.map +1 -1
  15. package/dist/development/accessorPropagation/TreeRootIdContext.js +3 -1
  16. package/dist/development/accessorPropagation/TreeRootIdContext.js.map +1 -1
  17. package/dist/development/accessorPropagation/TreeRootIdProvider.js +13 -5
  18. package/dist/development/accessorPropagation/TreeRootIdProvider.js.map +1 -1
  19. package/dist/development/accessorPropagation/useAccessorUpdateSubscription.js +3 -1
  20. package/dist/development/accessorPropagation/useAccessorUpdateSubscription.js.map +1 -1
  21. package/dist/development/accessorPropagation/useBindingOperations.js +3 -1
  22. package/dist/development/accessorPropagation/useBindingOperations.js.map +1 -1
  23. package/dist/development/accessorPropagation/useDesugaredRelativeEntityList.js +26 -18
  24. package/dist/development/accessorPropagation/useDesugaredRelativeEntityList.js.map +1 -1
  25. package/dist/development/accessorPropagation/useDesugaredRelativeSingleEntity.js +14 -6
  26. package/dist/development/accessorPropagation/useDesugaredRelativeSingleEntity.js.map +1 -1
  27. package/dist/development/accessorPropagation/useDesugaredRelativeSingleField.js +14 -6
  28. package/dist/development/accessorPropagation/useDesugaredRelativeSingleField.js.map +1 -1
  29. package/dist/development/accessorPropagation/useEntity.js +7 -2
  30. package/dist/development/accessorPropagation/useEntity.js.map +1 -1
  31. package/dist/development/accessorPropagation/useEntityKey.js +6 -2
  32. package/dist/development/accessorPropagation/useEntityKey.js.map +1 -1
  33. package/dist/development/accessorPropagation/useEntityList.js +11 -3
  34. package/dist/development/accessorPropagation/useEntityList.js.map +1 -1
  35. package/dist/development/accessorPropagation/useEntityListSubTree.js +7 -2
  36. package/dist/development/accessorPropagation/useEntityListSubTree.js.map +1 -1
  37. package/dist/development/accessorPropagation/useEntityListSubTreeParameters.js +50 -30
  38. package/dist/development/accessorPropagation/useEntityListSubTreeParameters.js.map +1 -1
  39. package/dist/development/accessorPropagation/useEntitySubTree.js +7 -2
  40. package/dist/development/accessorPropagation/useEntitySubTree.js.map +1 -1
  41. package/dist/development/accessorPropagation/useEntitySubTreeParameters.js +27 -16
  42. package/dist/development/accessorPropagation/useEntitySubTreeParameters.js.map +1 -1
  43. package/dist/development/accessorPropagation/useEnvironment.js +3 -1
  44. package/dist/development/accessorPropagation/useEnvironment.js.map +1 -1
  45. package/dist/development/accessorPropagation/useExtendTree.js +7 -2
  46. package/dist/development/accessorPropagation/useExtendTree.js.map +1 -1
  47. package/dist/development/accessorPropagation/useField.js +11 -3
  48. package/dist/development/accessorPropagation/useField.js.map +1 -1
  49. package/dist/development/accessorPropagation/useGetEntityByKey.js +3 -1
  50. package/dist/development/accessorPropagation/useGetEntityByKey.js.map +1 -1
  51. package/dist/development/accessorPropagation/useGetEntityListSubTree.js +7 -2
  52. package/dist/development/accessorPropagation/useGetEntityListSubTree.js.map +1 -1
  53. package/dist/development/accessorPropagation/useGetEntitySubTree.js +7 -2
  54. package/dist/development/accessorPropagation/useGetEntitySubTree.js.map +1 -1
  55. package/dist/development/accessorPropagation/useGetTreeFilters.js +3 -1
  56. package/dist/development/accessorPropagation/useGetTreeFilters.js.map +1 -1
  57. package/dist/development/accessorPropagation/useHasEntity.js +3 -1
  58. package/dist/development/accessorPropagation/useHasEntity.js.map +1 -1
  59. package/dist/development/accessorPropagation/usePersist.js +3 -1
  60. package/dist/development/accessorPropagation/usePersist.js.map +1 -1
  61. package/dist/development/accessorPropagation/useTreeRootId.js +3 -1
  62. package/dist/development/accessorPropagation/useTreeRootId.js.map +1 -1
  63. package/dist/development/accessorSorting/SetOrderFieldOnCreate.js +84 -44
  64. package/dist/development/accessorSorting/SetOrderFieldOnCreate.js.map +1 -1
  65. package/dist/development/accessorSorting/addEntityAtIndex.js +3 -1
  66. package/dist/development/accessorSorting/addEntityAtIndex.js.map +1 -1
  67. package/dist/development/accessorSorting/errors.js +6 -2
  68. package/dist/development/accessorSorting/errors.js.map +1 -1
  69. package/dist/development/accessorSorting/moveEntity.js +4 -1
  70. package/dist/development/accessorSorting/moveEntity.js.map +1 -1
  71. package/dist/development/accessorSorting/repairEntitiesOrder.js +3 -1
  72. package/dist/development/accessorSorting/repairEntitiesOrder.js.map +1 -1
  73. package/dist/development/accessorSorting/sortEntities.js +3 -1
  74. package/dist/development/accessorSorting/sortEntities.js.map +1 -1
  75. package/dist/development/accessorSorting/useSortedEntities.js +61 -23
  76. package/dist/development/accessorSorting/useSortedEntities.js.map +1 -1
  77. package/dist/development/accessorTree/AccessorTree.js +50 -22
  78. package/dist/development/accessorTree/AccessorTree.js.map +1 -1
  79. package/dist/development/accessorTree/AccessorTreeStateContext.js +3 -1
  80. package/dist/development/accessorTree/AccessorTreeStateContext.js.map +1 -1
  81. package/dist/development/accessorTree/DirtinessContext.js +3 -1
  82. package/dist/development/accessorTree/DirtinessContext.js.map +1 -1
  83. package/dist/development/accessorTree/MutationStateContext.js +3 -1
  84. package/dist/development/accessorTree/MutationStateContext.js.map +1 -1
  85. package/dist/development/accessorTree/NormalizedPersistedData.js +3 -1
  86. package/dist/development/accessorTree/NormalizedPersistedData.js.map +1 -1
  87. package/dist/development/accessorTree/RuntimeId.js +8 -2
  88. package/dist/development/accessorTree/RuntimeId.js.map +1 -1
  89. package/dist/development/accessorTree/accessorTreeStateReducer.js +10 -5
  90. package/dist/development/accessorTree/accessorTreeStateReducer.js.map +1 -1
  91. package/dist/development/accessorTree/metadataToRequestError.js +3 -1
  92. package/dist/development/accessorTree/metadataToRequestError.js.map +1 -1
  93. package/dist/development/accessorTree/useAccessorTreeState.js +3 -1
  94. package/dist/development/accessorTree/useAccessorTreeState.js.map +1 -1
  95. package/dist/development/accessorTree/useDataBinding.js +63 -53
  96. package/dist/development/accessorTree/useDataBinding.js.map +1 -1
  97. package/dist/development/accessorTree/useDirtinessState.js +3 -1
  98. package/dist/development/accessorTree/useDirtinessState.js.map +1 -1
  99. package/dist/development/accessorTree/useMutationState.js +3 -1
  100. package/dist/development/accessorTree/useMutationState.js.map +1 -1
  101. package/dist/development/accessors/EntityAccessor.js +35 -14
  102. package/dist/development/accessors/EntityAccessor.js.map +1 -1
  103. package/dist/development/accessors/EntityListAccessor.js +13 -11
  104. package/dist/development/accessors/EntityListAccessor.js.map +1 -1
  105. package/dist/development/accessors/ErrorAccessor.js +3 -1
  106. package/dist/development/accessors/ErrorAccessor.js.map +1 -1
  107. package/dist/development/accessors/FieldAccessor.js +9 -7
  108. package/dist/development/accessors/FieldAccessor.js.map +1 -1
  109. package/dist/development/accessors/TreeRootAccessor.js +3 -1
  110. package/dist/development/accessors/TreeRootAccessor.js.map +1 -1
  111. package/dist/development/bindingTypes.js +5 -1
  112. package/dist/development/bindingTypes.js.map +1 -1
  113. package/dist/development/core/AccessorErrorManager.js +3 -1
  114. package/dist/development/core/AccessorErrorManager.js.map +1 -1
  115. package/dist/development/core/Config.js +4 -4
  116. package/dist/development/core/Config.js.map +1 -1
  117. package/dist/development/core/DataBinding.js +146 -148
  118. package/dist/development/core/DataBinding.js.map +1 -1
  119. package/dist/development/core/DirtinessTracker.js +3 -1
  120. package/dist/development/core/DirtinessTracker.js.map +1 -1
  121. package/dist/development/core/ErrorsPreprocessor.js +12 -4
  122. package/dist/development/core/ErrorsPreprocessor.js.map +1 -1
  123. package/dist/development/core/EventManager.js +22 -8
  124. package/dist/development/core/EventManager.js.map +1 -1
  125. package/dist/development/core/IncrementalMarkerBuilder.js +36 -8
  126. package/dist/development/core/IncrementalMarkerBuilder.js.map +1 -1
  127. package/dist/development/core/MarkerComparator.js +7 -2
  128. package/dist/development/core/MarkerComparator.js.map +1 -1
  129. package/dist/development/core/MarkerMerger.js +60 -17
  130. package/dist/development/core/MarkerMerger.js.map +1 -1
  131. package/dist/development/core/MarkerTreeGenerator.js +11 -3
  132. package/dist/development/core/MarkerTreeGenerator.js.map +1 -1
  133. package/dist/development/core/MutationGenerator.js +127 -28
  134. package/dist/development/core/MutationGenerator.js.map +1 -1
  135. package/dist/development/core/QueryGenerator.js +40 -9
  136. package/dist/development/core/QueryGenerator.js.map +1 -1
  137. package/dist/development/core/RealmKeyGenerator.js +12 -3
  138. package/dist/development/core/RealmKeyGenerator.js.map +1 -1
  139. package/dist/development/core/RequestResponseNormalizer.js +3 -1
  140. package/dist/development/core/RequestResponseNormalizer.js.map +1 -1
  141. package/dist/development/core/StateInitializer.js +91 -34
  142. package/dist/development/core/StateInitializer.js.map +1 -1
  143. package/dist/development/core/TreeAugmenter.js +26 -5
  144. package/dist/development/core/TreeAugmenter.js.map +1 -1
  145. package/dist/development/core/TreeFilterGenerator.js +8 -2
  146. package/dist/development/core/TreeFilterGenerator.js.map +1 -1
  147. package/dist/development/core/TreeParameterMerger.js +25 -7
  148. package/dist/development/core/TreeParameterMerger.js.map +1 -1
  149. package/dist/development/core/TreeStore.js +23 -18
  150. package/dist/development/core/TreeStore.js.map +1 -1
  151. package/dist/development/core/VariableInputTransformer.js +3 -1
  152. package/dist/development/core/VariableInputTransformer.js.map +1 -1
  153. package/dist/development/core/exceptions/ErrorLocator.js +11 -3
  154. package/dist/development/core/exceptions/ErrorLocator.js.map +1 -1
  155. package/dist/development/core/exceptions/LocalizedBindingError.js +3 -1
  156. package/dist/development/core/exceptions/LocalizedBindingError.js.map +1 -1
  157. package/dist/development/core/exceptions/MarkerSugarer.js +8 -2
  158. package/dist/development/core/exceptions/MarkerSugarer.js.map +1 -1
  159. package/dist/development/core/exceptions/TreeParameterSugarer.js +3 -1
  160. package/dist/development/core/exceptions/TreeParameterSugarer.js.map +1 -1
  161. package/dist/development/core/factories/createBatchUpdatesOptions.js +3 -1
  162. package/dist/development/core/factories/createBatchUpdatesOptions.js.map +1 -1
  163. package/dist/development/core/operations/EntityOperations.js +47 -16
  164. package/dist/development/core/operations/EntityOperations.js.map +1 -1
  165. package/dist/development/core/operations/FieldOperations.js +22 -8
  166. package/dist/development/core/operations/FieldOperations.js.map +1 -1
  167. package/dist/development/core/operations/ListOperations.js +22 -9
  168. package/dist/development/core/operations/ListOperations.js.map +1 -1
  169. package/dist/development/core/operations/OperationsHelpers.js +6 -2
  170. package/dist/development/core/operations/OperationsHelpers.js.map +1 -1
  171. package/dist/development/core/requestAliases/MutationAlias.js +3 -1
  172. package/dist/development/core/requestAliases/MutationAlias.js.map +1 -1
  173. package/dist/development/core/schema/Schema.js +30 -4
  174. package/dist/development/core/schema/Schema.js.map +1 -1
  175. package/dist/development/core/schema/SchemaLoader.js +15 -13
  176. package/dist/development/core/schema/SchemaLoader.js.map +1 -1
  177. package/dist/development/core/schema/SchemaPreprocessor.js +3 -1
  178. package/dist/development/core/schema/SchemaPreprocessor.js.map +1 -1
  179. package/dist/development/core/state/StateIterator.js +3 -1
  180. package/dist/development/core/state/StateIterator.js.map +1 -1
  181. package/dist/development/core/state/getEntityMarker.js +3 -1
  182. package/dist/development/core/state/getEntityMarker.js.map +1 -1
  183. package/dist/development/core/utils/getCombinedSignal.js +3 -1
  184. package/dist/development/core/utils/getCombinedSignal.js.map +1 -1
  185. package/dist/development/coreComponents/Component.js +8 -3
  186. package/dist/development/coreComponents/Component.js.map +1 -1
  187. package/dist/development/coreComponents/DataBindingProvider.js +14 -9
  188. package/dist/development/coreComponents/DataBindingProvider.js.map +1 -1
  189. package/dist/development/coreComponents/Entity.js +16 -6
  190. package/dist/development/coreComponents/Entity.js.map +1 -1
  191. package/dist/development/coreComponents/EntityList.js +21 -9
  192. package/dist/development/coreComponents/EntityList.js.map +1 -1
  193. package/dist/development/coreComponents/EntityListSubTree.js +26 -9
  194. package/dist/development/coreComponents/EntityListSubTree.js.map +1 -1
  195. package/dist/development/coreComponents/EntitySubTree.js +37 -14
  196. package/dist/development/coreComponents/EntitySubTree.js.map +1 -1
  197. package/dist/development/coreComponents/Field.js +10 -4
  198. package/dist/development/coreComponents/Field.js.map +1 -1
  199. package/dist/development/coreComponents/HasMany.js +25 -9
  200. package/dist/development/coreComponents/HasMany.js.map +1 -1
  201. package/dist/development/coreComponents/HasOne.js +26 -10
  202. package/dist/development/coreComponents/HasOne.js.map +1 -1
  203. package/dist/development/coreComponents/ParentEntity.js +7 -3
  204. package/dist/development/coreComponents/ParentEntity.js.map +1 -1
  205. package/dist/development/dao/Environment.js +26 -2
  206. package/dist/development/dao/Environment.js.map +1 -1
  207. package/dist/development/dao/TreeNodeEnvironmentFactory.js +14 -14
  208. package/dist/development/dao/TreeNodeEnvironmentFactory.js.map +1 -1
  209. package/dist/development/dao/VariableFieldValue.js +3 -1
  210. package/dist/development/dao/VariableFieldValue.js.map +1 -1
  211. package/dist/development/entityEvents/useDerivedField.js +25 -17
  212. package/dist/development/entityEvents/useDerivedField.js.map +1 -1
  213. package/dist/development/entityEvents/useEntityBeforePersist.js +3 -1
  214. package/dist/development/entityEvents/useEntityBeforePersist.js.map +1 -1
  215. package/dist/development/entityEvents/useEntityBeforeUpdate.js +3 -1
  216. package/dist/development/entityEvents/useEntityBeforeUpdate.js.map +1 -1
  217. package/dist/development/entityEvents/useEntityEvent.js +16 -8
  218. package/dist/development/entityEvents/useEntityEvent.js.map +1 -1
  219. package/dist/development/entityEvents/useEntityPersistError.js +3 -1
  220. package/dist/development/entityEvents/useEntityPersistError.js.map +1 -1
  221. package/dist/development/entityEvents/useEntityPersistSuccess.js +3 -1
  222. package/dist/development/entityEvents/useEntityPersistSuccess.js.map +1 -1
  223. package/dist/development/entityEvents/useOnConnectionUpdate.js +3 -1
  224. package/dist/development/entityEvents/useOnConnectionUpdate.js.map +1 -1
  225. package/dist/development/fieldHelpers/helpers/FieldHelper.js +3 -1
  226. package/dist/development/fieldHelpers/helpers/FieldHelper.js.map +1 -1
  227. package/dist/development/fieldHelpers/helpers/TemporalFieldHelper.js +3 -1
  228. package/dist/development/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -1
  229. package/dist/development/fieldHelpers/helpers/UuidFieldHelper.js +3 -1
  230. package/dist/development/fieldHelpers/helpers/UuidFieldHelper.js.map +1 -1
  231. package/dist/development/helperComponents/DeferredSubTrees.js +46 -13
  232. package/dist/development/helperComponents/DeferredSubTrees.js.map +1 -1
  233. package/dist/development/helperComponents/EntityView.js +7 -3
  234. package/dist/development/helperComponents/EntityView.js.map +1 -1
  235. package/dist/development/helperComponents/FieldView.js +22 -8
  236. package/dist/development/helperComponents/FieldView.js.map +1 -1
  237. package/dist/development/helperComponents/If.js +57 -19
  238. package/dist/development/helperComponents/If.js.map +1 -1
  239. package/dist/development/helperComponents/StaticRender.js +9 -3
  240. package/dist/development/helperComponents/StaticRender.js.map +1 -1
  241. package/dist/development/helperComponents/SugaredField.js +17 -6
  242. package/dist/development/helperComponents/SugaredField.js.map +1 -1
  243. package/dist/development/helperComponents/helpers/FilterEvaluator.js +3 -4
  244. package/dist/development/helperComponents/helpers/FilterEvaluator.js.map +1 -1
  245. package/dist/development/helperComponents/helpers/FilterFieldsCollector.js +3 -4
  246. package/dist/development/helperComponents/helpers/FilterFieldsCollector.js.map +1 -1
  247. package/dist/development/helperComponents/helpers/evaluateCondition.js +3 -1
  248. package/dist/development/helperComponents/helpers/evaluateCondition.js.map +1 -1
  249. package/dist/development/index.js +225 -104
  250. package/dist/development/index.js.map +1 -1
  251. package/dist/development/markers/EntityFieldMarkersContainer.js +3 -1
  252. package/dist/development/markers/EntityFieldMarkersContainer.js.map +1 -1
  253. package/dist/development/markers/EntityFieldsWithHoistablesMarker.js +3 -1
  254. package/dist/development/markers/EntityFieldsWithHoistablesMarker.js.map +1 -1
  255. package/dist/development/markers/EntityListSubTreeMarker.js +3 -1
  256. package/dist/development/markers/EntityListSubTreeMarker.js.map +1 -1
  257. package/dist/development/markers/EntitySubTreeMarker.js +3 -1
  258. package/dist/development/markers/EntitySubTreeMarker.js.map +1 -1
  259. package/dist/development/markers/FieldMarker.js +3 -1
  260. package/dist/development/markers/FieldMarker.js.map +1 -1
  261. package/dist/development/markers/HasManyRelationMarker.js +3 -1
  262. package/dist/development/markers/HasManyRelationMarker.js.map +1 -1
  263. package/dist/development/markers/HasOneRelationMarker.js +3 -1
  264. package/dist/development/markers/HasOneRelationMarker.js.map +1 -1
  265. package/dist/development/markers/MarkerTreeRoot.js +3 -1
  266. package/dist/development/markers/MarkerTreeRoot.js.map +1 -1
  267. package/dist/development/markers/ParentEntityMarker.js +3 -1
  268. package/dist/development/markers/ParentEntityMarker.js.map +1 -1
  269. package/dist/development/markers/PlaceholderGenerator.js +3 -1
  270. package/dist/development/markers/PlaceholderGenerator.js.map +1 -1
  271. package/dist/development/queryLanguage/CacheStore.js +3 -1
  272. package/dist/development/queryLanguage/CacheStore.js.map +1 -1
  273. package/dist/development/queryLanguage/MarkerFactory.js +117 -25
  274. package/dist/development/queryLanguage/MarkerFactory.js.map +1 -1
  275. package/dist/development/queryLanguage/Parser.js +114 -79
  276. package/dist/development/queryLanguage/Parser.js.map +1 -1
  277. package/dist/development/queryLanguage/QueryLanguage.js +73 -20
  278. package/dist/development/queryLanguage/QueryLanguage.js.map +1 -1
  279. package/dist/development/queryLanguage/QueryLanguageError.js +3 -1
  280. package/dist/development/queryLanguage/QueryLanguageError.js.map +1 -1
  281. package/dist/development/queryLanguage/tokenList.js +5 -1
  282. package/dist/development/queryLanguage/tokenList.js.map +1 -1
  283. package/dist/development/structures/BijectiveIndexedMap.js +3 -1
  284. package/dist/development/structures/BijectiveIndexedMap.js.map +1 -1
  285. package/dist/development/structures/LRUCache.js +3 -1
  286. package/dist/development/structures/LRUCache.js.map +1 -1
  287. package/dist/development/structures/WeakIdCache.js +3 -1
  288. package/dist/development/structures/WeakIdCache.js.map +1 -1
  289. package/dist/development/treeParameterHelpers/wrapFilterInHasOnes.js +3 -1
  290. package/dist/development/treeParameterHelpers/wrapFilterInHasOnes.js.map +1 -1
  291. package/dist/development/treeParameters/EntityCreationParameters.js +3 -1
  292. package/dist/development/treeParameters/EntityCreationParameters.js.map +1 -1
  293. package/dist/development/treeParameters/EntityListPreferences.js +3 -1
  294. package/dist/development/treeParameters/EntityListPreferences.js.map +1 -1
  295. package/dist/development/treeParameters/EventListenersStore.js +3 -1
  296. package/dist/development/treeParameters/EventListenersStore.js.map +1 -1
  297. package/dist/development/treeParameters/LeafField.js +3 -1
  298. package/dist/development/treeParameters/LeafField.js.map +1 -1
  299. package/dist/development/treeParameters/QualifiedEntityParameters.js +3 -1
  300. package/dist/development/treeParameters/QualifiedEntityParameters.js.map +1 -1
  301. package/dist/development/treeParameters/Relation.js +3 -1
  302. package/dist/development/treeParameters/Relation.js.map +1 -1
  303. package/dist/development/utils/Hashing.js +3 -1
  304. package/dist/development/utils/Hashing.js.map +1 -1
  305. package/dist/development/utils/assert.js +3 -1
  306. package/dist/development/utils/assert.js.map +1 -1
  307. package/dist/development/utils/assertNever.js +6 -2
  308. package/dist/development/utils/assertNever.js.map +1 -1
  309. package/dist/development/utils/generateEnumerabilityPreventingEntropy.js +3 -1
  310. package/dist/development/utils/generateEnumerabilityPreventingEntropy.js.map +1 -1
  311. package/dist/development/utils/isEmptyObject.js +3 -1
  312. package/dist/development/utils/isEmptyObject.js.map +1 -1
  313. package/dist/development/utils/ucfirst.js +3 -1
  314. package/dist/development/utils/ucfirst.js.map +1 -1
  315. package/dist/production/BindingError.js +4 -1
  316. package/dist/production/BindingError.js.map +1 -1
  317. package/dist/production/accessorPropagation/AccessorProvider.js +11 -7
  318. package/dist/production/accessorPropagation/AccessorProvider.js.map +1 -1
  319. package/dist/production/accessorPropagation/BindingOperationsContext.js +7 -2
  320. package/dist/production/accessorPropagation/BindingOperationsContext.js.map +1 -1
  321. package/dist/production/accessorPropagation/BindingOperationsProvider.js +8 -5
  322. package/dist/production/accessorPropagation/BindingOperationsProvider.js.map +1 -1
  323. package/dist/production/accessorPropagation/EntityKeyContext.js +3 -1
  324. package/dist/production/accessorPropagation/EntityKeyContext.js.map +1 -1
  325. package/dist/production/accessorPropagation/EntityKeyProvider.js +8 -5
  326. package/dist/production/accessorPropagation/EntityKeyProvider.js.map +1 -1
  327. package/dist/production/accessorPropagation/EnvironmentContext.js +53 -2
  328. package/dist/production/accessorPropagation/EnvironmentContext.js.map +1 -1
  329. package/dist/production/accessorPropagation/TreeRootIdContext.js +3 -1
  330. package/dist/production/accessorPropagation/TreeRootIdContext.js.map +1 -1
  331. package/dist/production/accessorPropagation/TreeRootIdProvider.js +8 -5
  332. package/dist/production/accessorPropagation/TreeRootIdProvider.js.map +1 -1
  333. package/dist/production/accessorPropagation/useAccessorUpdateSubscription.js +3 -1
  334. package/dist/production/accessorPropagation/useAccessorUpdateSubscription.js.map +1 -1
  335. package/dist/production/accessorPropagation/useBindingOperations.js +3 -1
  336. package/dist/production/accessorPropagation/useBindingOperations.js.map +1 -1
  337. package/dist/production/accessorPropagation/useDesugaredRelativeEntityList.js +26 -18
  338. package/dist/production/accessorPropagation/useDesugaredRelativeEntityList.js.map +1 -1
  339. package/dist/production/accessorPropagation/useDesugaredRelativeSingleEntity.js +14 -6
  340. package/dist/production/accessorPropagation/useDesugaredRelativeSingleEntity.js.map +1 -1
  341. package/dist/production/accessorPropagation/useDesugaredRelativeSingleField.js +14 -6
  342. package/dist/production/accessorPropagation/useDesugaredRelativeSingleField.js.map +1 -1
  343. package/dist/production/accessorPropagation/useEntity.js +7 -2
  344. package/dist/production/accessorPropagation/useEntity.js.map +1 -1
  345. package/dist/production/accessorPropagation/useEntityKey.js +6 -2
  346. package/dist/production/accessorPropagation/useEntityKey.js.map +1 -1
  347. package/dist/production/accessorPropagation/useEntityList.js +11 -3
  348. package/dist/production/accessorPropagation/useEntityList.js.map +1 -1
  349. package/dist/production/accessorPropagation/useEntityListSubTree.js +7 -2
  350. package/dist/production/accessorPropagation/useEntityListSubTree.js.map +1 -1
  351. package/dist/production/accessorPropagation/useEntityListSubTreeParameters.js +50 -30
  352. package/dist/production/accessorPropagation/useEntityListSubTreeParameters.js.map +1 -1
  353. package/dist/production/accessorPropagation/useEntitySubTree.js +7 -2
  354. package/dist/production/accessorPropagation/useEntitySubTree.js.map +1 -1
  355. package/dist/production/accessorPropagation/useEntitySubTreeParameters.js +27 -16
  356. package/dist/production/accessorPropagation/useEntitySubTreeParameters.js.map +1 -1
  357. package/dist/production/accessorPropagation/useEnvironment.js +3 -1
  358. package/dist/production/accessorPropagation/useEnvironment.js.map +1 -1
  359. package/dist/production/accessorPropagation/useExtendTree.js +7 -2
  360. package/dist/production/accessorPropagation/useExtendTree.js.map +1 -1
  361. package/dist/production/accessorPropagation/useField.js +11 -3
  362. package/dist/production/accessorPropagation/useField.js.map +1 -1
  363. package/dist/production/accessorPropagation/useGetEntityByKey.js +3 -1
  364. package/dist/production/accessorPropagation/useGetEntityByKey.js.map +1 -1
  365. package/dist/production/accessorPropagation/useGetEntityListSubTree.js +7 -2
  366. package/dist/production/accessorPropagation/useGetEntityListSubTree.js.map +1 -1
  367. package/dist/production/accessorPropagation/useGetEntitySubTree.js +7 -2
  368. package/dist/production/accessorPropagation/useGetEntitySubTree.js.map +1 -1
  369. package/dist/production/accessorPropagation/useGetTreeFilters.js +3 -1
  370. package/dist/production/accessorPropagation/useGetTreeFilters.js.map +1 -1
  371. package/dist/production/accessorPropagation/useHasEntity.js +3 -1
  372. package/dist/production/accessorPropagation/useHasEntity.js.map +1 -1
  373. package/dist/production/accessorPropagation/usePersist.js +3 -1
  374. package/dist/production/accessorPropagation/usePersist.js.map +1 -1
  375. package/dist/production/accessorPropagation/useTreeRootId.js +3 -1
  376. package/dist/production/accessorPropagation/useTreeRootId.js.map +1 -1
  377. package/dist/production/accessorSorting/SetOrderFieldOnCreate.js +55 -44
  378. package/dist/production/accessorSorting/SetOrderFieldOnCreate.js.map +1 -1
  379. package/dist/production/accessorSorting/addEntityAtIndex.js +3 -1
  380. package/dist/production/accessorSorting/addEntityAtIndex.js.map +1 -1
  381. package/dist/production/accessorSorting/errors.js +6 -2
  382. package/dist/production/accessorSorting/errors.js.map +1 -1
  383. package/dist/production/accessorSorting/moveEntity.js +4 -1
  384. package/dist/production/accessorSorting/moveEntity.js.map +1 -1
  385. package/dist/production/accessorSorting/repairEntitiesOrder.js +3 -1
  386. package/dist/production/accessorSorting/repairEntitiesOrder.js.map +1 -1
  387. package/dist/production/accessorSorting/sortEntities.js +3 -1
  388. package/dist/production/accessorSorting/sortEntities.js.map +1 -1
  389. package/dist/production/accessorSorting/useSortedEntities.js +61 -23
  390. package/dist/production/accessorSorting/useSortedEntities.js.map +1 -1
  391. package/dist/production/accessorTree/AccessorTree.js +29 -22
  392. package/dist/production/accessorTree/AccessorTree.js.map +1 -1
  393. package/dist/production/accessorTree/AccessorTreeStateContext.js +3 -1
  394. package/dist/production/accessorTree/AccessorTreeStateContext.js.map +1 -1
  395. package/dist/production/accessorTree/DirtinessContext.js +3 -1
  396. package/dist/production/accessorTree/DirtinessContext.js.map +1 -1
  397. package/dist/production/accessorTree/MutationStateContext.js +3 -1
  398. package/dist/production/accessorTree/MutationStateContext.js.map +1 -1
  399. package/dist/production/accessorTree/NormalizedPersistedData.js +3 -1
  400. package/dist/production/accessorTree/NormalizedPersistedData.js.map +1 -1
  401. package/dist/production/accessorTree/RuntimeId.js +8 -2
  402. package/dist/production/accessorTree/RuntimeId.js.map +1 -1
  403. package/dist/production/accessorTree/accessorTreeStateReducer.js +10 -5
  404. package/dist/production/accessorTree/accessorTreeStateReducer.js.map +1 -1
  405. package/dist/production/accessorTree/metadataToRequestError.js +3 -1
  406. package/dist/production/accessorTree/metadataToRequestError.js.map +1 -1
  407. package/dist/production/accessorTree/useAccessorTreeState.js +3 -1
  408. package/dist/production/accessorTree/useAccessorTreeState.js.map +1 -1
  409. package/dist/production/accessorTree/useDataBinding.js +63 -53
  410. package/dist/production/accessorTree/useDataBinding.js.map +1 -1
  411. package/dist/production/accessorTree/useDirtinessState.js +3 -1
  412. package/dist/production/accessorTree/useDirtinessState.js.map +1 -1
  413. package/dist/production/accessorTree/useMutationState.js +3 -1
  414. package/dist/production/accessorTree/useMutationState.js.map +1 -1
  415. package/dist/production/accessors/EntityAccessor.js +35 -14
  416. package/dist/production/accessors/EntityAccessor.js.map +1 -1
  417. package/dist/production/accessors/EntityListAccessor.js +13 -11
  418. package/dist/production/accessors/EntityListAccessor.js.map +1 -1
  419. package/dist/production/accessors/ErrorAccessor.js +3 -1
  420. package/dist/production/accessors/ErrorAccessor.js.map +1 -1
  421. package/dist/production/accessors/FieldAccessor.js +9 -7
  422. package/dist/production/accessors/FieldAccessor.js.map +1 -1
  423. package/dist/production/accessors/TreeRootAccessor.js +3 -1
  424. package/dist/production/accessors/TreeRootAccessor.js.map +1 -1
  425. package/dist/production/bindingTypes.js +5 -1
  426. package/dist/production/bindingTypes.js.map +1 -1
  427. package/dist/production/core/AccessorErrorManager.js +3 -1
  428. package/dist/production/core/AccessorErrorManager.js.map +1 -1
  429. package/dist/production/core/Config.js +4 -4
  430. package/dist/production/core/Config.js.map +1 -1
  431. package/dist/production/core/DataBinding.js +146 -148
  432. package/dist/production/core/DataBinding.js.map +1 -1
  433. package/dist/production/core/DirtinessTracker.js +3 -1
  434. package/dist/production/core/DirtinessTracker.js.map +1 -1
  435. package/dist/production/core/ErrorsPreprocessor.js +12 -4
  436. package/dist/production/core/ErrorsPreprocessor.js.map +1 -1
  437. package/dist/production/core/EventManager.js +10 -4
  438. package/dist/production/core/EventManager.js.map +1 -1
  439. package/dist/production/core/IncrementalMarkerBuilder.js +36 -8
  440. package/dist/production/core/IncrementalMarkerBuilder.js.map +1 -1
  441. package/dist/production/core/MarkerComparator.js +7 -2
  442. package/dist/production/core/MarkerComparator.js.map +1 -1
  443. package/dist/production/core/MarkerMerger.js +60 -17
  444. package/dist/production/core/MarkerMerger.js.map +1 -1
  445. package/dist/production/core/MarkerTreeGenerator.js +11 -3
  446. package/dist/production/core/MarkerTreeGenerator.js.map +1 -1
  447. package/dist/production/core/MutationGenerator.js +127 -28
  448. package/dist/production/core/MutationGenerator.js.map +1 -1
  449. package/dist/production/core/QueryGenerator.js +40 -9
  450. package/dist/production/core/QueryGenerator.js.map +1 -1
  451. package/dist/production/core/RealmKeyGenerator.js +12 -3
  452. package/dist/production/core/RealmKeyGenerator.js.map +1 -1
  453. package/dist/production/core/RequestResponseNormalizer.js +3 -1
  454. package/dist/production/core/RequestResponseNormalizer.js.map +1 -1
  455. package/dist/production/core/StateInitializer.js +91 -34
  456. package/dist/production/core/StateInitializer.js.map +1 -1
  457. package/dist/production/core/TreeAugmenter.js +26 -5
  458. package/dist/production/core/TreeAugmenter.js.map +1 -1
  459. package/dist/production/core/TreeFilterGenerator.js +8 -2
  460. package/dist/production/core/TreeFilterGenerator.js.map +1 -1
  461. package/dist/production/core/TreeParameterMerger.js +25 -7
  462. package/dist/production/core/TreeParameterMerger.js.map +1 -1
  463. package/dist/production/core/TreeStore.js +23 -18
  464. package/dist/production/core/TreeStore.js.map +1 -1
  465. package/dist/production/core/VariableInputTransformer.js +3 -1
  466. package/dist/production/core/VariableInputTransformer.js.map +1 -1
  467. package/dist/production/core/exceptions/ErrorLocator.js +11 -3
  468. package/dist/production/core/exceptions/ErrorLocator.js.map +1 -1
  469. package/dist/production/core/exceptions/LocalizedBindingError.js +3 -1
  470. package/dist/production/core/exceptions/LocalizedBindingError.js.map +1 -1
  471. package/dist/production/core/exceptions/MarkerSugarer.js +8 -2
  472. package/dist/production/core/exceptions/MarkerSugarer.js.map +1 -1
  473. package/dist/production/core/exceptions/TreeParameterSugarer.js +3 -1
  474. package/dist/production/core/exceptions/TreeParameterSugarer.js.map +1 -1
  475. package/dist/production/core/factories/createBatchUpdatesOptions.js +3 -1
  476. package/dist/production/core/factories/createBatchUpdatesOptions.js.map +1 -1
  477. package/dist/production/core/operations/EntityOperations.js +47 -16
  478. package/dist/production/core/operations/EntityOperations.js.map +1 -1
  479. package/dist/production/core/operations/FieldOperations.js +11 -3
  480. package/dist/production/core/operations/FieldOperations.js.map +1 -1
  481. package/dist/production/core/operations/ListOperations.js +22 -9
  482. package/dist/production/core/operations/ListOperations.js.map +1 -1
  483. package/dist/production/core/operations/OperationsHelpers.js +6 -2
  484. package/dist/production/core/operations/OperationsHelpers.js.map +1 -1
  485. package/dist/production/core/requestAliases/MutationAlias.js +3 -1
  486. package/dist/production/core/requestAliases/MutationAlias.js.map +1 -1
  487. package/dist/production/core/schema/Schema.js +30 -4
  488. package/dist/production/core/schema/Schema.js.map +1 -1
  489. package/dist/production/core/schema/SchemaLoader.js +15 -13
  490. package/dist/production/core/schema/SchemaLoader.js.map +1 -1
  491. package/dist/production/core/schema/SchemaPreprocessor.js +3 -1
  492. package/dist/production/core/schema/SchemaPreprocessor.js.map +1 -1
  493. package/dist/production/core/state/StateIterator.js +3 -1
  494. package/dist/production/core/state/StateIterator.js.map +1 -1
  495. package/dist/production/core/state/getEntityMarker.js +3 -1
  496. package/dist/production/core/state/getEntityMarker.js.map +1 -1
  497. package/dist/production/core/utils/getCombinedSignal.js +3 -1
  498. package/dist/production/core/utils/getCombinedSignal.js.map +1 -1
  499. package/dist/production/coreComponents/Component.js +8 -3
  500. package/dist/production/coreComponents/Component.js.map +1 -1
  501. package/dist/production/coreComponents/DataBindingProvider.js +9 -9
  502. package/dist/production/coreComponents/DataBindingProvider.js.map +1 -1
  503. package/dist/production/coreComponents/Entity.js +11 -6
  504. package/dist/production/coreComponents/Entity.js.map +1 -1
  505. package/dist/production/coreComponents/EntityList.js +16 -9
  506. package/dist/production/coreComponents/EntityList.js.map +1 -1
  507. package/dist/production/coreComponents/EntityListSubTree.js +12 -8
  508. package/dist/production/coreComponents/EntityListSubTree.js.map +1 -1
  509. package/dist/production/coreComponents/EntitySubTree.js +19 -13
  510. package/dist/production/coreComponents/EntitySubTree.js.map +1 -1
  511. package/dist/production/coreComponents/Field.js +10 -4
  512. package/dist/production/coreComponents/Field.js.map +1 -1
  513. package/dist/production/coreComponents/HasMany.js +11 -8
  514. package/dist/production/coreComponents/HasMany.js.map +1 -1
  515. package/dist/production/coreComponents/HasOne.js +12 -9
  516. package/dist/production/coreComponents/HasOne.js.map +1 -1
  517. package/dist/production/coreComponents/ParentEntity.js +7 -3
  518. package/dist/production/coreComponents/ParentEntity.js.map +1 -1
  519. package/dist/production/dao/Environment.js +26 -2
  520. package/dist/production/dao/Environment.js.map +1 -1
  521. package/dist/production/dao/TreeNodeEnvironmentFactory.js +14 -14
  522. package/dist/production/dao/TreeNodeEnvironmentFactory.js.map +1 -1
  523. package/dist/production/dao/VariableFieldValue.js +3 -1
  524. package/dist/production/dao/VariableFieldValue.js.map +1 -1
  525. package/dist/production/entityEvents/useDerivedField.js +25 -17
  526. package/dist/production/entityEvents/useDerivedField.js.map +1 -1
  527. package/dist/production/entityEvents/useEntityBeforePersist.js +3 -1
  528. package/dist/production/entityEvents/useEntityBeforePersist.js.map +1 -1
  529. package/dist/production/entityEvents/useEntityBeforeUpdate.js +3 -1
  530. package/dist/production/entityEvents/useEntityBeforeUpdate.js.map +1 -1
  531. package/dist/production/entityEvents/useEntityEvent.js +16 -8
  532. package/dist/production/entityEvents/useEntityEvent.js.map +1 -1
  533. package/dist/production/entityEvents/useEntityPersistError.js +3 -1
  534. package/dist/production/entityEvents/useEntityPersistError.js.map +1 -1
  535. package/dist/production/entityEvents/useEntityPersistSuccess.js +3 -1
  536. package/dist/production/entityEvents/useEntityPersistSuccess.js.map +1 -1
  537. package/dist/production/entityEvents/useOnConnectionUpdate.js +3 -1
  538. package/dist/production/entityEvents/useOnConnectionUpdate.js.map +1 -1
  539. package/dist/production/fieldHelpers/helpers/FieldHelper.js +3 -1
  540. package/dist/production/fieldHelpers/helpers/FieldHelper.js.map +1 -1
  541. package/dist/production/fieldHelpers/helpers/TemporalFieldHelper.js +3 -1
  542. package/dist/production/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -1
  543. package/dist/production/fieldHelpers/helpers/UuidFieldHelper.js +3 -1
  544. package/dist/production/fieldHelpers/helpers/UuidFieldHelper.js.map +1 -1
  545. package/dist/production/helperComponents/DeferredSubTrees.js +37 -13
  546. package/dist/production/helperComponents/DeferredSubTrees.js.map +1 -1
  547. package/dist/production/helperComponents/EntityView.js +7 -3
  548. package/dist/production/helperComponents/EntityView.js.map +1 -1
  549. package/dist/production/helperComponents/FieldView.js +17 -8
  550. package/dist/production/helperComponents/FieldView.js.map +1 -1
  551. package/dist/production/helperComponents/If.js +44 -19
  552. package/dist/production/helperComponents/If.js.map +1 -1
  553. package/dist/production/helperComponents/StaticRender.js +9 -3
  554. package/dist/production/helperComponents/StaticRender.js.map +1 -1
  555. package/dist/production/helperComponents/SugaredField.js +6 -4
  556. package/dist/production/helperComponents/SugaredField.js.map +1 -1
  557. package/dist/production/helperComponents/helpers/FilterEvaluator.js +3 -4
  558. package/dist/production/helperComponents/helpers/FilterEvaluator.js.map +1 -1
  559. package/dist/production/helperComponents/helpers/FilterFieldsCollector.js +3 -4
  560. package/dist/production/helperComponents/helpers/FilterFieldsCollector.js.map +1 -1
  561. package/dist/production/helperComponents/helpers/evaluateCondition.js +3 -1
  562. package/dist/production/helperComponents/helpers/evaluateCondition.js.map +1 -1
  563. package/dist/production/index.js +225 -104
  564. package/dist/production/index.js.map +1 -1
  565. package/dist/production/markers/EntityFieldMarkersContainer.js +3 -1
  566. package/dist/production/markers/EntityFieldMarkersContainer.js.map +1 -1
  567. package/dist/production/markers/EntityFieldsWithHoistablesMarker.js +3 -1
  568. package/dist/production/markers/EntityFieldsWithHoistablesMarker.js.map +1 -1
  569. package/dist/production/markers/EntityListSubTreeMarker.js +3 -1
  570. package/dist/production/markers/EntityListSubTreeMarker.js.map +1 -1
  571. package/dist/production/markers/EntitySubTreeMarker.js +3 -1
  572. package/dist/production/markers/EntitySubTreeMarker.js.map +1 -1
  573. package/dist/production/markers/FieldMarker.js +3 -1
  574. package/dist/production/markers/FieldMarker.js.map +1 -1
  575. package/dist/production/markers/HasManyRelationMarker.js +3 -1
  576. package/dist/production/markers/HasManyRelationMarker.js.map +1 -1
  577. package/dist/production/markers/HasOneRelationMarker.js +3 -1
  578. package/dist/production/markers/HasOneRelationMarker.js.map +1 -1
  579. package/dist/production/markers/MarkerTreeRoot.js +3 -1
  580. package/dist/production/markers/MarkerTreeRoot.js.map +1 -1
  581. package/dist/production/markers/ParentEntityMarker.js +3 -1
  582. package/dist/production/markers/ParentEntityMarker.js.map +1 -1
  583. package/dist/production/markers/PlaceholderGenerator.js +3 -1
  584. package/dist/production/markers/PlaceholderGenerator.js.map +1 -1
  585. package/dist/production/queryLanguage/CacheStore.js +3 -1
  586. package/dist/production/queryLanguage/CacheStore.js.map +1 -1
  587. package/dist/production/queryLanguage/MarkerFactory.js +117 -25
  588. package/dist/production/queryLanguage/MarkerFactory.js.map +1 -1
  589. package/dist/production/queryLanguage/Parser.js +114 -79
  590. package/dist/production/queryLanguage/Parser.js.map +1 -1
  591. package/dist/production/queryLanguage/QueryLanguage.js +73 -20
  592. package/dist/production/queryLanguage/QueryLanguage.js.map +1 -1
  593. package/dist/production/queryLanguage/QueryLanguageError.js +3 -1
  594. package/dist/production/queryLanguage/QueryLanguageError.js.map +1 -1
  595. package/dist/production/queryLanguage/tokenList.js +5 -1
  596. package/dist/production/queryLanguage/tokenList.js.map +1 -1
  597. package/dist/production/structures/BijectiveIndexedMap.js +3 -1
  598. package/dist/production/structures/BijectiveIndexedMap.js.map +1 -1
  599. package/dist/production/structures/LRUCache.js +3 -1
  600. package/dist/production/structures/LRUCache.js.map +1 -1
  601. package/dist/production/structures/WeakIdCache.js +3 -1
  602. package/dist/production/structures/WeakIdCache.js.map +1 -1
  603. package/dist/production/treeParameterHelpers/wrapFilterInHasOnes.js +3 -1
  604. package/dist/production/treeParameterHelpers/wrapFilterInHasOnes.js.map +1 -1
  605. package/dist/production/treeParameters/EntityCreationParameters.js +3 -1
  606. package/dist/production/treeParameters/EntityCreationParameters.js.map +1 -1
  607. package/dist/production/treeParameters/EntityListPreferences.js +3 -1
  608. package/dist/production/treeParameters/EntityListPreferences.js.map +1 -1
  609. package/dist/production/treeParameters/EventListenersStore.js +3 -1
  610. package/dist/production/treeParameters/EventListenersStore.js.map +1 -1
  611. package/dist/production/treeParameters/LeafField.js +3 -1
  612. package/dist/production/treeParameters/LeafField.js.map +1 -1
  613. package/dist/production/treeParameters/QualifiedEntityParameters.js +3 -1
  614. package/dist/production/treeParameters/QualifiedEntityParameters.js.map +1 -1
  615. package/dist/production/treeParameters/Relation.js +3 -1
  616. package/dist/production/treeParameters/Relation.js.map +1 -1
  617. package/dist/production/utils/Hashing.js +3 -1
  618. package/dist/production/utils/Hashing.js.map +1 -1
  619. package/dist/production/utils/assert.js +3 -1
  620. package/dist/production/utils/assert.js.map +1 -1
  621. package/dist/production/utils/assertNever.js +6 -2
  622. package/dist/production/utils/assertNever.js.map +1 -1
  623. package/dist/production/utils/generateEnumerabilityPreventingEntropy.js +3 -1
  624. package/dist/production/utils/generateEnumerabilityPreventingEntropy.js.map +1 -1
  625. package/dist/production/utils/isEmptyObject.js +3 -1
  626. package/dist/production/utils/isEmptyObject.js.map +1 -1
  627. package/dist/production/utils/ucfirst.js +3 -1
  628. package/dist/production/utils/ucfirst.js.map +1 -1
  629. package/dist/types/accessorPropagation/BindingOperationsContext.d.ts +1 -1
  630. package/dist/types/accessorPropagation/BindingOperationsContext.d.ts.map +1 -1
  631. package/dist/types/accessorPropagation/EntityKeyContext.d.ts +1 -1
  632. package/dist/types/accessorPropagation/EntityKeyContext.d.ts.map +1 -1
  633. package/dist/types/accessorPropagation/EnvironmentContext.d.ts +13 -2
  634. package/dist/types/accessorPropagation/EnvironmentContext.d.ts.map +1 -1
  635. package/dist/types/accessorPropagation/TreeRootIdContext.d.ts +1 -1
  636. package/dist/types/accessorPropagation/TreeRootIdContext.d.ts.map +1 -1
  637. package/dist/types/accessorPropagation/useEntityListSubTree.d.ts +2 -1
  638. package/dist/types/accessorPropagation/useEntityListSubTree.d.ts.map +1 -1
  639. package/dist/types/accessorPropagation/useEntitySubTree.d.ts +2 -1
  640. package/dist/types/accessorPropagation/useEntitySubTree.d.ts.map +1 -1
  641. package/dist/types/accessorPropagation/useExtendTree.d.ts +1 -1
  642. package/dist/types/accessorPropagation/useExtendTree.d.ts.map +1 -1
  643. package/dist/types/accessorPropagation/useGetEntityListSubTree.d.ts +2 -1
  644. package/dist/types/accessorPropagation/useGetEntityListSubTree.d.ts.map +1 -1
  645. package/dist/types/accessorPropagation/useGetEntitySubTree.d.ts +2 -1
  646. package/dist/types/accessorPropagation/useGetEntitySubTree.d.ts.map +1 -1
  647. package/dist/types/accessorSorting/SetOrderFieldOnCreate.d.ts +1 -1
  648. package/dist/types/accessorSorting/SetOrderFieldOnCreate.d.ts.map +1 -1
  649. package/dist/types/accessorSorting/addEntityAtIndex.d.ts +1 -1
  650. package/dist/types/accessorSorting/addEntityAtIndex.d.ts.map +1 -1
  651. package/dist/types/accessorTree/AccessorTree.d.ts.map +1 -1
  652. package/dist/types/accessorTree/AccessorTreeState.d.ts +7 -3
  653. package/dist/types/accessorTree/AccessorTreeState.d.ts.map +1 -1
  654. package/dist/types/accessorTree/AccessorTreeStateAction.d.ts +2 -0
  655. package/dist/types/accessorTree/AccessorTreeStateAction.d.ts.map +1 -1
  656. package/dist/types/accessorTree/AccessorTreeStateContext.d.ts +1 -1
  657. package/dist/types/accessorTree/AccessorTreeStateContext.d.ts.map +1 -1
  658. package/dist/types/accessorTree/AccessorTreeStateOptions.d.ts +2 -2
  659. package/dist/types/accessorTree/AccessorTreeStateOptions.d.ts.map +1 -1
  660. package/dist/types/accessorTree/DirtinessContext.d.ts +1 -1
  661. package/dist/types/accessorTree/DirtinessContext.d.ts.map +1 -1
  662. package/dist/types/accessorTree/MutationRequestResponse.d.ts +5 -5
  663. package/dist/types/accessorTree/MutationRequestResponse.d.ts.map +1 -1
  664. package/dist/types/accessorTree/MutationStateContext.d.ts +1 -1
  665. package/dist/types/accessorTree/MutationStateContext.d.ts.map +1 -1
  666. package/dist/types/accessorTree/PersistResult.d.ts +1 -4
  667. package/dist/types/accessorTree/PersistResult.d.ts.map +1 -1
  668. package/dist/types/accessorTree/accessorTreeStateReducer.d.ts.map +1 -1
  669. package/dist/types/accessorTree/useDataBinding.d.ts +1 -1
  670. package/dist/types/accessorTree/useDataBinding.d.ts.map +1 -1
  671. package/dist/types/accessors/BindingConfig.d.ts +0 -2
  672. package/dist/types/accessors/BindingConfig.d.ts.map +1 -1
  673. package/dist/types/accessors/EntityAccessor.d.ts +4 -2
  674. package/dist/types/accessors/EntityAccessor.d.ts.map +1 -1
  675. package/dist/types/accessors/EntityListAccessor.d.ts +2 -2
  676. package/dist/types/accessors/EntityListAccessor.d.ts.map +1 -1
  677. package/dist/types/accessors/FieldAccessor.d.ts +2 -2
  678. package/dist/types/accessors/FieldAccessor.d.ts.map +1 -1
  679. package/dist/types/accessors/PersistErrorOptions.d.ts +0 -2
  680. package/dist/types/accessors/PersistErrorOptions.d.ts.map +1 -1
  681. package/dist/types/core/Config.d.ts.map +1 -1
  682. package/dist/types/core/DataBinding.d.ts +11 -4
  683. package/dist/types/core/DataBinding.d.ts.map +1 -1
  684. package/dist/types/core/MarkerMerger.d.ts.map +1 -1
  685. package/dist/types/core/MutationGenerator.d.ts.map +1 -1
  686. package/dist/types/core/StateInitializer.d.ts.map +1 -1
  687. package/dist/types/core/TreeAugmenter.d.ts +2 -1
  688. package/dist/types/core/TreeAugmenter.d.ts.map +1 -1
  689. package/dist/types/core/TreeStore.d.ts +2 -3
  690. package/dist/types/core/TreeStore.d.ts.map +1 -1
  691. package/dist/types/core/index.d.ts +1 -0
  692. package/dist/types/core/index.d.ts.map +1 -1
  693. package/dist/types/core/schema/Schema.d.ts +13 -3
  694. package/dist/types/core/schema/Schema.d.ts.map +1 -1
  695. package/dist/types/core/schema/SchemaColumn.d.ts +1 -1
  696. package/dist/types/core/schema/SchemaColumn.d.ts.map +1 -1
  697. package/dist/types/core/schema/SchemaLoader.d.ts +2 -1
  698. package/dist/types/core/schema/SchemaLoader.d.ts.map +1 -1
  699. package/dist/types/core/schema/SchemaRelation.d.ts +1 -1
  700. package/dist/types/core/schema/SchemaRelation.d.ts.map +1 -1
  701. package/dist/types/coreComponents/Component.d.ts +9 -4
  702. package/dist/types/coreComponents/Component.d.ts.map +1 -1
  703. package/dist/types/coreComponents/DataBindingProvider.d.ts +2 -6
  704. package/dist/types/coreComponents/DataBindingProvider.d.ts.map +1 -1
  705. package/dist/types/coreComponents/Entity.d.ts +1 -1
  706. package/dist/types/coreComponents/Entity.d.ts.map +1 -1
  707. package/dist/types/coreComponents/EntityListSubTree.d.ts.map +1 -1
  708. package/dist/types/coreComponents/ParentEntity.d.ts +1 -1
  709. package/dist/types/coreComponents/ParentEntity.d.ts.map +1 -1
  710. package/dist/types/dao/Environment.d.ts +10 -2
  711. package/dist/types/dao/Environment.d.ts.map +1 -1
  712. package/dist/types/dao/TreeNodeEnvironmentFactory.d.ts.map +1 -1
  713. package/dist/types/fieldHelpers/helpers/TemporalFieldHelper.d.ts +1 -1
  714. package/dist/types/fieldHelpers/helpers/TemporalFieldHelper.d.ts.map +1 -1
  715. package/dist/types/fieldHelpers/helpers/UuidFieldHelper.d.ts +1 -1
  716. package/dist/types/fieldHelpers/helpers/UuidFieldHelper.d.ts.map +1 -1
  717. package/dist/types/helperComponents/DeferredSubTrees.d.ts +1 -1
  718. package/dist/types/helperComponents/DeferredSubTrees.d.ts.map +1 -1
  719. package/dist/types/helperComponents/If.d.ts +1 -1
  720. package/dist/types/helperComponents/If.d.ts.map +1 -1
  721. package/dist/types/helperComponents/StaticRender.d.ts +1 -1
  722. package/dist/types/helperComponents/StaticRender.d.ts.map +1 -1
  723. package/dist/types/helperComponents/helpers/FilterEvaluator.d.ts.map +1 -1
  724. package/dist/types/helperComponents/helpers/FilterFieldsCollector.d.ts.map +1 -1
  725. package/dist/types/tsconfig.tsbuildinfo +1 -1
  726. package/package.json +9 -9
  727. package/src/accessorPropagation/EnvironmentContext.tsx +44 -0
  728. package/src/accessorTree/AccessorTree.tsx +12 -18
  729. package/src/accessorTree/AccessorTreeState.ts +11 -4
  730. package/src/accessorTree/AccessorTreeStateAction.ts +3 -1
  731. package/src/accessorTree/AccessorTreeStateOptions.ts +2 -2
  732. package/src/accessorTree/MutationRequestResponse.ts +9 -3
  733. package/src/accessorTree/PersistResult.ts +1 -5
  734. package/src/accessorTree/accessorTreeStateReducer.ts +6 -3
  735. package/src/accessorTree/useDataBinding.ts +65 -59
  736. package/src/accessors/BindingConfig.ts +0 -2
  737. package/src/accessors/EntityAccessor.ts +20 -7
  738. package/src/accessors/EntityListAccessor.ts +9 -9
  739. package/src/accessors/FieldAccessor.ts +5 -5
  740. package/src/accessors/PersistErrorOptions.ts +0 -2
  741. package/src/core/Config.ts +0 -2
  742. package/src/core/DataBinding.ts +136 -162
  743. package/src/core/MarkerMerger.ts +7 -5
  744. package/src/core/MutationGenerator.ts +8 -4
  745. package/src/core/StateInitializer.ts +3 -12
  746. package/src/core/TreeAugmenter.ts +4 -1
  747. package/src/core/TreeStore.ts +4 -17
  748. package/src/core/factories/createBatchUpdatesOptions.ts +1 -1
  749. package/src/core/index.ts +1 -0
  750. package/src/core/operations/EntityOperations.ts +1 -1
  751. package/src/core/schema/Schema.ts +38 -4
  752. package/src/core/schema/SchemaColumn.ts +1 -1
  753. package/src/core/schema/SchemaLoader.ts +13 -11
  754. package/src/core/schema/SchemaRelation.ts +1 -1
  755. package/src/coreComponents/Component.tsx +20 -7
  756. package/src/coreComponents/DataBindingProvider.tsx +4 -11
  757. package/src/coreComponents/EntityListSubTree.tsx +2 -3
  758. package/src/dao/Environment.ts +34 -3
  759. package/src/dao/TreeNodeEnvironmentFactory.ts +6 -11
  760. package/src/helperComponents/DeferredSubTrees.tsx +2 -1
  761. package/src/helperComponents/helpers/FilterEvaluator.ts +1 -3
  762. package/src/helperComponents/helpers/FilterFieldsCollector.ts +0 -3
  763. package/src/typings/react-fix.d.ts +12 -0
  764. package/src/accessorPropagation/EnvironmentContext.ts +0 -5
@@ -1 +1 @@
1
- {"version":3,"file":"StateInitializer.js","sources":["../../../src/core/StateInitializer.ts"],"sourcesContent":["import { BatchUpdatesOptions, EntityAccessor, EntityListAccessor, FieldAccessor } from '../accessors'\nimport { EntityFieldPersistedData, RuntimeId, ServerId, UnpersistedEntityDummyId } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport {\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n} from '../markers'\nimport { BijectiveIndexedMap } from '../structures'\nimport type {\n\tEntityEventListenerStore,\n\tEntityId,\n\tEntityListEventListenerStore,\n\tEntityName,\n\tFieldEventListenerStore,\n\tFieldName,\n\tFieldValue,\n} from '../treeParameters'\nimport { EventListenersStore } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport type { AccessorErrorManager } from './AccessorErrorManager'\nimport type { EventManager } from './EventManager'\nimport { EntityOperations, FieldOperations, ListOperations } from './operations'\nimport { RealmKeyGenerator } from './RealmKeyGenerator'\nimport {\n\tEntityListBlueprint,\n\tEntityListState,\n\tEntityRealmBlueprint,\n\tEntityRealmState,\n\tEntityRealmStateStub,\n\tEntityState,\n\tFieldState,\n\tgetEntityMarker,\n\tRootStateNode,\n} from './state'\nimport { TreeParameterMerger } from './TreeParameterMerger'\nimport type { TreeStore } from './TreeStore'\n\nexport class StateInitializer {\n\tprivate readonly fieldOperations: FieldOperations\n\tprivate readonly entityOperations: EntityOperations\n\tprivate readonly listOperations: ListOperations\n\n\tpublic constructor(\n\t\taccessorErrorManager: AccessorErrorManager,\n\t\tbatchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {\n\t\tthis.fieldOperations = new FieldOperations(accessorErrorManager, this.eventManager, this, this.treeStore)\n\t\tthis.entityOperations = new EntityOperations(accessorErrorManager, batchUpdatesOptions, this.eventManager, this, this.treeStore)\n\t\tthis.listOperations = new ListOperations(accessorErrorManager, batchUpdatesOptions, this.eventManager, this, this.treeStore)\n\t}\n\n\tpublic initializeSubTree(tree: EntitySubTreeMarker | EntityListSubTreeMarker): RootStateNode {\n\t\tlet subTreeState: RootStateNode\n\t\tconst persistedRootData = this.treeStore.subTreePersistedData.get(tree.placeholderName)\n\n\t\tif (tree instanceof EntityListSubTreeMarker) {\n\t\t\tconst persistedEntityIds: Set<EntityId> = persistedRootData instanceof Set ? persistedRootData : new Set()\n\t\t\tsubTreeState = this.initializeEntityListState(\n\t\t\t\t{ marker: tree, parent: undefined },\n\t\t\t\ttree.entityName,\n\t\t\t\tpersistedEntityIds,\n\t\t\t)\n\t\t} else {\n\t\t\tsubTreeState = this.materializeEntityRealm(\n\t\t\t\tthis.initializeEntityRealm(\n\t\t\t\t\tpersistedRootData instanceof ServerId ? persistedRootData : new UnpersistedEntityDummyId(),\n\t\t\t\t\ttree.entityName,\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'subTree',\n\t\t\t\t\t\tmarker: tree,\n\t\t\t\t\t\tparent: undefined,\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\n\t\treturn subTreeState\n\t}\n\n\tpublic initializeEntityRealm(\n\t\tid: RuntimeId,\n\t\tentityName: EntityName,\n\t\tblueprint: EntityRealmBlueprint,\n\t\tcopyFrom?: EntityRealmState | EntityRealmStateStub,\n\t): EntityRealmState | EntityRealmStateStub {\n\t\t// This is counter-intuitive a bit. The method can also return an EntityRealmState, not just a stub.\n\t\t// The reason is so that each call-site can just default to trying to initialize a stub without having to keep\n\t\t// in mind that the realm might have already been initialized.\n\n\t\tconst entity = this.initializeEntityState(id, entityName)\n\t\tconst realmKey = RealmKeyGenerator.getRealmKey(id, blueprint)\n\n\t\tconst existing = this.treeStore.entityRealmStore.get(realmKey)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\n\t\tif (!copyFrom || copyFrom.type !== 'entityRealm') {\n\t\t\tconst stub: EntityRealmStateStub = {\n\t\t\t\ttype: 'entityRealmStub',\n\n\t\t\t\tblueprint,\n\t\t\t\tentity,\n\t\t\t\trealmKey,\n\t\t\t\tgetAccessor: () => this.materializeEntityRealm(stub).getAccessor(),\n\t\t\t}\n\t\t\tthis.registerEntityRealm(stub)\n\n\t\t\treturn stub\n\t\t}\n\t\tconst realm = this.createEntityRealm(blueprint, realmKey, entity, copyFrom)\n\n\t\tthis.registerEntityRealm(realm)\n\n\t\tconst marker = getEntityMarker(realm)\n\t\tconst pathBack = this.treeStore.getPathBackToParent(realm)\n\n\t\tfor (const [placeholderName, field] of marker.fields.markers) {\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tconst value = copyFrom.children.get(placeholderName)\n\t\t\t\tif (!value || value.type !== 'field') {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tthis.initializeFromFieldMarker(realm, field, undefined, value)\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\tconst value = copyFrom.children.get(placeholderName)\n\t\t\t\tif (!value || value.type !== 'entityList') {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tthis.initializeFromHasManyRelationMarker(realm, field, new Set(value.children.keys()))\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tlet runtimeId: RuntimeId\n\t\t\t\tlet subCopyFrom: EntityRealmState | undefined = undefined\n\t\t\t\tif (pathBack?.fieldBackToParent === field.parameters.field) {\n\t\t\t\t\truntimeId = pathBack.parent.entity.id\n\t\t\t\t} else {\n\t\t\t\t\tconst value = copyFrom.children.get(placeholderName)\n\t\t\t\t\tif (!value || (value.type !== 'entityRealm' && value.type !== 'entityRealmStub')) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\truntimeId = !(value.entity.id instanceof UnpersistedEntityDummyId) ? value.entity.id : new UnpersistedEntityDummyId()\n\t\t\t\t\tif (value.type === 'entityRealm') {\n\t\t\t\t\t\tsubCopyFrom = value\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.initializeFromHasOneRelationMarker(realm, field, runtimeId, subCopyFrom)\n\t\t\t} else {\n\t\t\t\tassertNever(field)\n\t\t\t}\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(realm)\n\t\treturn realm\n\t}\n\n\tprivate createEntityRealm(\n\t\tblueprint: EntityRealmBlueprint,\n\t\trealmKey: string,\n\t\tentity: EntityState,\n\t\tcopyFrom?: EntityRealmState,\n\t): EntityRealmState {\n\t\tconst entityRealm: EntityRealmState = {\n\t\t\ttype: 'entityRealm',\n\n\t\t\tblueprint,\n\t\t\trealmKey,\n\t\t\tentity,\n\n\t\t\taccessor: undefined,\n\t\t\tchildren: new Map(),\n\t\t\tchildrenWithPendingUpdates: undefined,\n\t\t\terrors: undefined,\n\t\t\teventListeners: this.initializeEntityEventListenerStore(blueprint),\n\t\t\tfieldsWithPendingConnectionUpdates: undefined,\n\t\t\tplannedHasOneDeletions: undefined,\n\t\t\tunpersistedChangesCount: copyFrom?.unpersistedChangesCount ?? 0,\n\t\t\tgetAccessor: () => {\n\t\t\t\tif (entityRealm.accessor === undefined) {\n\t\t\t\t\tconst entity = entityRealm.entity\n\t\t\t\t\tentityRealm.accessor = new EntityAccessor(\n\t\t\t\t\t\tentityRealm,\n\t\t\t\t\t\tthis.entityOperations,\n\t\t\t\t\t\tentity.id,\n\t\t\t\t\t\tentityRealm.realmKey,\n\t\t\t\t\t\tentity.entityName,\n\n\t\t\t\t\t\t// We're technically exposing more info in runtime than we'd like but that way we don't have to allocate and\n\t\t\t\t\t\t// keep in sync two copies of the same data. TS hides the extra info anyway.\n\t\t\t\t\t\tentityRealm.children,\n\t\t\t\t\t\tthis.treeStore.persistedEntityData.get(entity.id.uniqueValue),\n\t\t\t\t\t\tentityRealm.unpersistedChangesCount !== 0,\n\t\t\t\t\t\tentityRealm.errors,\n\t\t\t\t\t\tgetEntityMarker(entityRealm).environment,\n\t\t\t\t\t\tentityRealm.getAccessor,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn entityRealm.accessor\n\t\t\t},\n\t\t}\n\t\treturn entityRealm\n\t}\n\n\tprivate materializeEntityRealm(state: EntityRealmState | EntityRealmStateStub): EntityRealmState {\n\t\tif (state.type === 'entityRealm') {\n\t\t\treturn state\n\t\t}\n\t\tconst { realmKey, entity, blueprint } = state\n\n\t\tconst existing = this.treeStore.entityRealmStore.get(realmKey)\n\t\tif (existing !== undefined && existing.type === 'entityRealm') {\n\t\t\treturn existing\n\t\t}\n\n\t\tconst entityRealm = this.createEntityRealm(blueprint, realmKey, entity)\n\n\t\tthis.registerEntityRealm(entityRealm)\n\n\t\t// if (blueprint.creationParameters.forceCreation && !entity.id.existsOnServer) {\n\t\t// \tentityRealm.unpersistedChangesCount += 1\n\t\t// }\n\n\t\tconst persistedData = this.treeStore.persistedEntityData.get(entity.id.uniqueValue)\n\n\t\tconst marker = getEntityMarker(state)\n\t\tconst pathBack = this.treeStore.getPathBackToParent(entityRealm)\n\n\t\tfor (const [placeholderName, field] of marker.fields.markers) {\n\t\t\tconst fieldDatum = persistedData?.get(placeholderName)\n\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tthis.initializeFromFieldMarker(entityRealm, field, fieldDatum)\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\t// if (pathBack?.fieldBackToParent === field.parameters.field) {\n\t\t\t\t// \t// TODO this is probably wrong?\n\t\t\t\t// \tconst ids = pathBack.parent.children.get(field.placeholderName)\n\t\t\t\t// \tconst newData = this.treeStore.persistedEntityData.get(pathBack.parent.entity.id.value)\n\t\t\t\t// \tconsole.log('many?', pathBack, field, entityRealm, fieldDatum, ids)\n\t\t\t\t// }\n\t\t\t\tthis.initializeFromHasManyRelationMarker(entityRealm, field, fieldDatum instanceof Set ? fieldDatum : new Set())\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tlet runtimeId: RuntimeId\n\t\t\t\tif (pathBack?.fieldBackToParent === field.parameters.field) {\n\t\t\t\t\truntimeId = pathBack.parent.entity.id\n\t\t\t\t} else {\n\t\t\t\t\truntimeId = fieldDatum instanceof ServerId ? fieldDatum : new UnpersistedEntityDummyId()\n\t\t\t\t}\n\t\t\t\tthis.initializeFromHasOneRelationMarker(entityRealm, field, runtimeId)\n\t\t\t} else {\n\t\t\t\tassertNever(field)\n\t\t\t}\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(entityRealm)\n\n\t\treturn entityRealm\n\t}\n\n\tprivate registerEntityRealm(entityRealm: EntityRealmState | EntityRealmStateStub) {\n\t\tconst { realmKey, blueprint, entity } = entityRealm\n\n\t\tthis.treeStore.entityRealmStore.set(entityRealm.realmKey, entityRealm)\n\n\t\tif (blueprint.type === 'listEntity') {\n\t\t\tblueprint.parent.children.set(entity.id.value, entityRealm)\n\t\t} else if (blueprint.type === 'hasOne') {\n\t\t\tblueprint.parent.children.set(blueprint.marker.placeholderName, entityRealm)\n\t\t}\n\t\tentity.realms.set(realmKey, entityRealm)\n\t}\n\n\tpublic initializeEntityState(id: RuntimeId, entityName: EntityName): EntityState {\n\t\tconst entityId = id.uniqueValue\n\n\t\tconst existing = this.treeStore.entityStore.get(entityId)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\n\t\tconst entityState: EntityState = {\n\t\t\tentityName,\n\t\t\thasIdSetInStone: id instanceof ServerId,\n\t\t\tid,\n\t\t\tisScheduledForDeletion: false,\n\t\t\tmaidenId: id instanceof UnpersistedEntityDummyId ? id : undefined,\n\t\t\trealms: new Map(),\n\t\t}\n\t\tthis.treeStore.entityStore.set(entityId, entityState)\n\n\t\treturn entityState\n\t}\n\n\tprivate initializeEntityListState(\n\t\tblueprint: EntityListBlueprint,\n\t\tentityName: EntityName,\n\t\tinitialEntityIds: Set<EntityId>,\n\t): EntityListState {\n\t\tconst entityListState: EntityListState = {\n\t\t\ttype: 'entityList',\n\t\t\taccessor: undefined,\n\t\t\tblueprint,\n\t\t\tchildren: new BijectiveIndexedMap(realm => realm.entity.id.value),\n\t\t\tchildrenWithPendingUpdates: undefined,\n\t\t\tentityName,\n\t\t\teventListeners: this.initializeEntityListEventListenerStore(blueprint),\n\t\t\tchildEventListeners: this.initializeEntityListChildEventListenerStore(blueprint),\n\t\t\terrors: undefined,\n\t\t\tplannedRemovals: undefined,\n\t\t\tunpersistedChangesCount: 0, // TODO force creation?\n\t\t\tgetAccessor: () => {\n\t\t\t\tif (entityListState.accessor === undefined) {\n\t\t\t\t\tconst persistedEntityIds = this.treeStore.getEntityListPersistedIds(entityListState)\n\t\t\t\t\tentityListState.accessor = new EntityListAccessor(\n\t\t\t\t\t\tentityListState,\n\t\t\t\t\t\tthis.listOperations,\n\t\t\t\t\t\tentityListState.children,\n\t\t\t\t\t\tpersistedEntityIds,\n\t\t\t\t\t\tentityListState.unpersistedChangesCount !== 0,\n\t\t\t\t\t\tentityListState.errors,\n\t\t\t\t\t\tentityListState.blueprint.marker.environment,\n\t\t\t\t\t\tentityListState.getAccessor,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn entityListState.accessor\n\t\t\t},\n\t\t}\n\n\t\tconst initialData: Iterable<EntityId | undefined> =\n\t\t\tinitialEntityIds.size === 0\n\t\t\t\t? Array.from({ length: blueprint.marker.parameters.initialEntityCount })\n\t\t\t\t: initialEntityIds\n\t\tfor (const entityId of initialData) {\n\t\t\tthis.initializeEntityRealm(\n\t\t\t\tentityId ? new ServerId(entityId, entityName) : new UnpersistedEntityDummyId(),\n\t\t\t\tentityListState.entityName,\n\t\t\t\t{\n\t\t\t\t\ttype: 'listEntity',\n\t\t\t\t\tparent: entityListState,\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(entityListState)\n\n\t\treturn entityListState\n\t}\n\n\tprivate initializeFieldState(\n\t\tparent: EntityRealmState,\n\t\tplaceholderName: FieldName,\n\t\tfieldMarker: FieldMarker,\n\t\tpersistedValue: FieldValue | undefined,\n\t\tcopyFromState: FieldState | undefined,\n\t): FieldState {\n\t\tconst resolvedFieldValue = copyFromState ? copyFromState.value : (persistedValue ?? fieldMarker.defaultValue ?? null)\n\n\t\tconst fieldState: FieldState = {\n\t\t\ttype: 'field',\n\t\t\taccessor: undefined,\n\t\t\tfieldMarker,\n\t\t\tplaceholderName,\n\t\t\tpersistedValue,\n\t\t\tparent,\n\t\t\tvalue: resolvedFieldValue,\n\t\t\teventListeners: this.initializeFieldEventListenerStore(fieldMarker),\n\t\t\terrors: undefined,\n\t\t\ttouchLog: undefined,\n\t\t\thasUnpersistedChanges: copyFromState?.hasUnpersistedChanges ?? false,\n\n\t\t\tgetAccessor: () => {\n\t\t\t\tif (fieldState.accessor === undefined) {\n\t\t\t\t\tconst fieldSchema = this.treeStore.schema.getEntityField(parent.entity.entityName, fieldMarker.fieldName)\n\t\t\t\t\tif (!fieldSchema) {\n\t\t\t\t\t\tthrow new BindingError(`Unknown field ${parent.entity.entityName}.${fieldMarker.fieldName}.`)\n\t\t\t\t\t}\n\t\t\t\t\tif (fieldSchema.__typename !== '_Column') {\n\t\t\t\t\t\tthrow new BindingError(`Invalid type of field ${parent.entity.entityName}.${fieldMarker.fieldName}. Expected '_Column', '${fieldSchema.__typename}' found.`)\n\t\t\t\t\t}\n\t\t\t\t\tfieldState.accessor = new FieldAccessor(\n\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\tthis.fieldOperations,\n\t\t\t\t\t\tfieldState.placeholderName,\n\t\t\t\t\t\tfieldState.value,\n\t\t\t\t\t\tfieldState.persistedValue === undefined ? null : fieldState.persistedValue,\n\t\t\t\t\t\tfieldState.fieldMarker.defaultValue,\n\t\t\t\t\t\tfieldState.errors,\n\t\t\t\t\t\tfieldState.hasUnpersistedChanges,\n\t\t\t\t\t\tfieldState.touchLog,\n\t\t\t\t\t\tfieldState.getAccessor,\n\t\t\t\t\t\tfieldSchema,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn fieldState.accessor\n\t\t\t},\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(fieldState)\n\t\treturn fieldState\n\t}\n\n\tprivate initializeFromFieldMarker(\n\t\tparent: EntityRealmState,\n\t\tfield: FieldMarker,\n\t\tpersistedValue: EntityFieldPersistedData | undefined,\n\t\tcopyFromState?: FieldState,\n\t) {\n\t\tif (persistedValue instanceof Set) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Received a collection of referenced entities where a single '${field.fieldName}' field was expected. ` +\n\t\t\t\t\t`Perhaps you wanted to use a <Repeater />?`,\n\t\t\t)\n\t\t}\n\t\tif (persistedValue instanceof ServerId) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Received a referenced entity where a single '${field.fieldName}' field was expected. ` +\n\t\t\t\t\t`Perhaps you wanted to use <HasOne />?`,\n\t\t\t)\n\t\t}\n\t\tparent.children.set(\n\t\t\tfield.placeholderName,\n\t\t\tthis.initializeFieldState(parent, field.placeholderName, field, persistedValue, copyFromState),\n\t\t)\n\t}\n\n\tprivate initializeFromHasOneRelationMarker(\n\t\tparent: EntityRealmState,\n\t\tfield: HasOneRelationMarker,\n\t\tentityId: RuntimeId,\n\t\tcopyFrom?: EntityRealmState | EntityRealmStateStub,\n\t) {\n\t\tparent.children.set(\n\t\t\tfield.placeholderName,\n\t\t\tthis.initializeEntityRealm(entityId, this.getRelationTargetEntityName(parent, field), {\n\t\t\t\ttype: 'hasOne',\n\t\t\t\tparent,\n\t\t\t\tmarker: field,\n\t\t\t}, copyFrom),\n\t\t)\n\t\t// if (fieldDatum instanceof ServerGeneratedUuid || fieldDatum === null || fieldDatum === undefined) {\n\t\t// \tconst entityId = fieldDatum instanceof ServerGeneratedUuid ? fieldDatum : new UnpersistedEntityDummyId()\n\t\t//\n\t\t//\n\t\t// } else if (fieldDatum instanceof Set) {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a collection of entities for field '${relation.field}' where a single entity was expected. ` +\n\t\t// \t\t\t`Perhaps you wanted to use a <Repeater />?`,\n\t\t// \t)\n\t\t// } else {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a scalar value for field '${relation.field}' where a single entity was expected.` +\n\t\t// \t\t\t`Perhaps you meant to use a variant of <Field />?`,\n\t\t// \t)\n\t\t// }\n\t}\n\n\tprivate initializeFromHasManyRelationMarker(\n\t\tparent: EntityRealmState,\n\t\tfield: HasManyRelationMarker,\n\t\tpersistedEntityIds: Set<EntityId>,\n\t) {\n\t\tparent.children.set(\n\t\t\tfield.placeholderName,\n\t\t\tthis.initializeEntityListState(\n\t\t\t\t{ marker: field, parent },\n\t\t\t\tthis.getRelationTargetEntityName(parent, field),\n\t\t\t\tpersistedEntityIds,\n\t\t\t),\n\t\t)\n\t\t// const relation = field.parameters\n\t\t//\n\t\t// if (fieldDatum === undefined || fieldDatum instanceof Set) {\n\t\t//\n\t\t// } else if (typeof fieldDatum === 'object') {\n\t\t// \t// Intentionally allowing `fieldDatum === null` here as well since this should only happen when a *hasOne\n\t\t// \t// relation is unlinked, e.g. a Person does not have a linked Nationality.\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a referenced entity for field '${relation.field}' where a collection of entities was expected.` +\n\t\t// \t\t\t`Perhaps you wanted to use a <HasOne />?`,\n\t\t// \t)\n\t\t// } else {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a scalar value for field '${relation.field}' where a collection of entities was expected.` +\n\t\t// \t\t\t`Perhaps you meant to use a variant of <Field />?`,\n\t\t// \t)\n\t\t// }\n\t}\n\n\tprivate getRelationTargetEntityName(\n\t\tentityRealm: EntityRealmState,\n\t\tfield: HasOneRelationMarker | HasManyRelationMarker,\n\t): EntityName {\n\t\tconst targetField = this.treeStore.schema.getEntityField(entityRealm.entity.entityName, field.parameters.field)\n\n\t\tif (targetField?.__typename !== '_Relation') {\n\t\t\tthrow new BindingError() // This should have been validated elsewhere.\n\t\t}\n\t\treturn targetField.targetEntity\n\t}\n\n\tpublic runImmediateUserInitialization(\n\t\trealm: EntityRealmState | EntityRealmStateStub,\n\t\tinitialize: EntityAccessor.BatchUpdatesHandler | undefined,\n\t) {\n\t\tif (initialize === undefined) {\n\t\t\treturn\n\t\t}\n\t\tconst entityRealm = this.materializeEntityRealm(realm)\n\n\t\trealm.getAccessor().batchUpdates(initialize)\n\n\t\tconst initializeListeners = this.eventManager.getEventListeners(entityRealm, { type: 'initialize' })\n\t\tif (initializeListeners === undefined || initializeListeners.size === 0) {\n\t\t\trealm.entity.hasIdSetInStone = true\n\t\t}\n\t}\n\n\tpublic initializeEntityEventListenerStore(blueprint: EntityRealmBlueprint): EntityEventListenerStore | undefined {\n\t\tif (blueprint.type === 'listEntity') {\n\t\t\tconst blueprintListeners = blueprint.parent.blueprint.marker.parameters.childEventListeners\n\t\t\tconst childInitialize = blueprintListeners?.get({ type: 'initialize' })\n\t\t\tconst store: EntityEventListenerStore = new EventListenersStore(() => blueprint.parent.childEventListeners)\n\n\t\t\tif (childInitialize !== undefined) {\n\t\t\t\tstore.set({ type: 'initialize' }, childInitialize)\n\t\t\t}\n\t\t\treturn store\n\t\t}\n\n\t\tconst blueprintListeners = blueprint.marker.parameters.eventListeners\n\t\tif (blueprintListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn TreeParameterMerger.cloneSingleEntityEventListeners(blueprintListeners)\n\t}\n\n\tprivate initializeEntityListEventListenerStore(\n\t\tblueprint: EntityListBlueprint,\n\t): EntityListEventListenerStore | undefined {\n\t\tconst blueprintListeners = blueprint.marker.parameters.eventListeners\n\n\t\tif (blueprintListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn TreeParameterMerger.cloneEntityListEventListeners(blueprintListeners)\n\t}\n\n\tprivate initializeEntityListChildEventListenerStore(\n\t\tblueprint: EntityListBlueprint,\n\t): EntityEventListenerStore | undefined {\n\t\tconst blueprintListeners = blueprint.marker.parameters.childEventListeners\n\n\t\tif (blueprintListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn TreeParameterMerger.cloneSingleEntityEventListeners(blueprintListeners)\n\t}\n\n\tprivate initializeFieldEventListenerStore(marker: FieldMarker): FieldEventListenerStore | undefined {\n\t\t// TODO !!!\n\t\treturn undefined\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAwCO,MAAM,iBAAiB;AAAA,EAKtB,YACN,sBACA,qBACiB,cACA,WAChB;AATe;AACA;AACA;AAKC,SAAA,eAAA;AACA,SAAA,YAAA;AAEZ,SAAA,kBAAkB,IAAI,gBAAgB,sBAAsB,KAAK,cAAc,MAAM,KAAK,SAAS;AACnG,SAAA,mBAAmB,IAAI,iBAAiB,sBAAsB,qBAAqB,KAAK,cAAc,MAAM,KAAK,SAAS;AAC1H,SAAA,iBAAiB,IAAI,eAAe,sBAAsB,qBAAqB,KAAK,cAAc,MAAM,KAAK,SAAS;AAAA,EAC5H;AAAA,EAEO,kBAAkB,MAAoE;AACxF,QAAA;AACJ,UAAM,oBAAoB,KAAK,UAAU,qBAAqB,IAAI,KAAK,eAAe;AAEtF,QAAI,gBAAgB,yBAAyB;AAC5C,YAAM,qBAAoC,6BAA6B,MAAM,wCAAwB,IAAI;AAC1F,qBAAA,KAAK,0BACnB,EAAE,QAAQ,MAAM,QAAQ,OAAU,GAClC,KAAK,YACL,kBACD;AAAA,IAAA,OACM;AACS,qBAAA,KAAK,uBACnB,KAAK,sBACJ,6BAA6B,WAAW,oBAAoB,IAAI,4BAChE,KA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I,wBAAwB,UAAa,oBAAoB,SAAS,GAAG;AACxE,YAAM,OAAO,kBAAkB;AAAA,IAChC;AAAA,EACD;AAAA,EAEO,mCAAmC,WAAuE;AAC5G,QAAA,UAAU,SAAS,cAAc;AACpC,YAAM,sBAAqB,UAAU,OAAO,UAAU,OAAO,WAAW;AACxE,YAAM,kBAAkB,qBAAoB,IAAI,EAAE,MAAM,cAAc;AACtE,YAAM,QAAkC,IAAI,oBAAoB,MAAM,UAAU,OAAO,mBAAmB;AAE1G,UAAI,oBAAoB,QAAW;AAClC,cAAM,IAAI,EAAE,MAAM,gBAAgB,eAAe;AAAA,MAClD;AACO,aAAA;AAAA,IACR;AAEM,UAAA,qBAAqB,UAAU,OAAO,WAAW;AACvD,QAAI,uBAAuB,QAAW;AAC9B,aAAA;AAAA,IACR;AACO,WAAA,oBAAoB,gCAAgC,kBAAkB;AAAA,EAC9E;AAAA,EAEQ,uCACP,WAC2C;AACrC,UAAA,qBAAqB,UAAU,OAAO,WAAW;AAEvD,QAAI,uBAAuB,QAAW;AAC9B,aAAA;AAAA,IACR;AACO,WAAA,oBAAoB,8BAA8B,kBAAkB;AAAA,EAC5E;AAAA,EAEQ,4CACP,WACuC;AACjC,UAAA,qBAAqB,UAAU,OAAO,WAAW;AAEvD,QAAI,uBAAuB,QAAW;AAC9B,aAAA;AAAA,IACR;AACO,WAAA,oBAAoB,gCAAgC,kBAAkB;AAAA,EAC9E;AAAA,EAEQ,kCAAkC,QAA0D;AAE5F,WAAA;AAAA,EACR;AACD;;"}
1
+ {"version":3,"file":"StateInitializer.js","sources":["../../../src/core/StateInitializer.ts"],"sourcesContent":["import { BatchUpdatesOptions, EntityAccessor, EntityListAccessor, FieldAccessor } from '../accessors'\nimport { EntityFieldPersistedData, RuntimeId, ServerId, UnpersistedEntityDummyId } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport {\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n} from '../markers'\nimport { BijectiveIndexedMap } from '../structures'\nimport type {\n\tEntityEventListenerStore,\n\tEntityId,\n\tEntityListEventListenerStore,\n\tEntityName,\n\tFieldEventListenerStore,\n\tFieldName,\n\tFieldValue,\n} from '../treeParameters'\nimport { EventListenersStore } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport type { AccessorErrorManager } from './AccessorErrorManager'\nimport type { EventManager } from './EventManager'\nimport { EntityOperations, FieldOperations, ListOperations } from './operations'\nimport { RealmKeyGenerator } from './RealmKeyGenerator'\nimport {\n\tEntityListBlueprint,\n\tEntityListState,\n\tEntityRealmBlueprint,\n\tEntityRealmState,\n\tEntityRealmStateStub,\n\tEntityState,\n\tFieldState,\n\tgetEntityMarker,\n\tRootStateNode,\n} from './state'\nimport { TreeParameterMerger } from './TreeParameterMerger'\nimport type { TreeStore } from './TreeStore'\n\nexport class StateInitializer {\n\tprivate readonly fieldOperations: FieldOperations\n\tprivate readonly entityOperations: EntityOperations\n\tprivate readonly listOperations: ListOperations\n\n\tpublic constructor(\n\t\taccessorErrorManager: AccessorErrorManager,\n\t\tbatchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {\n\t\tthis.fieldOperations = new FieldOperations(accessorErrorManager, this.eventManager, this, this.treeStore)\n\t\tthis.entityOperations = new EntityOperations(accessorErrorManager, batchUpdatesOptions, this.eventManager, this, this.treeStore)\n\t\tthis.listOperations = new ListOperations(accessorErrorManager, batchUpdatesOptions, this.eventManager, this, this.treeStore)\n\t}\n\n\tpublic initializeSubTree(tree: EntitySubTreeMarker | EntityListSubTreeMarker): RootStateNode {\n\t\tlet subTreeState: RootStateNode\n\t\tconst persistedRootData = this.treeStore.subTreePersistedData.get(tree.placeholderName)\n\n\t\tif (tree instanceof EntityListSubTreeMarker) {\n\t\t\tconst persistedEntityIds: Set<EntityId> = persistedRootData instanceof Set ? persistedRootData : new Set()\n\t\t\tsubTreeState = this.initializeEntityListState(\n\t\t\t\t{ marker: tree, parent: undefined },\n\t\t\t\ttree.entityName,\n\t\t\t\tpersistedEntityIds,\n\t\t\t)\n\t\t} else {\n\t\t\tsubTreeState = this.materializeEntityRealm(\n\t\t\t\tthis.initializeEntityRealm(\n\t\t\t\t\tpersistedRootData instanceof ServerId ? persistedRootData : new UnpersistedEntityDummyId(),\n\t\t\t\t\ttree.entityName,\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'subTree',\n\t\t\t\t\t\tmarker: tree,\n\t\t\t\t\t\tparent: undefined,\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\n\t\treturn subTreeState\n\t}\n\n\tpublic initializeEntityRealm(\n\t\tid: RuntimeId,\n\t\tentityName: EntityName,\n\t\tblueprint: EntityRealmBlueprint,\n\t\tcopyFrom?: EntityRealmState | EntityRealmStateStub,\n\t): EntityRealmState | EntityRealmStateStub {\n\t\t// This is counter-intuitive a bit. The method can also return an EntityRealmState, not just a stub.\n\t\t// The reason is so that each call-site can just default to trying to initialize a stub without having to keep\n\t\t// in mind that the realm might have already been initialized.\n\n\t\tconst entity = this.initializeEntityState(id, entityName)\n\t\tconst realmKey = RealmKeyGenerator.getRealmKey(id, blueprint)\n\n\t\tconst existing = this.treeStore.entityRealmStore.get(realmKey)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\n\t\tif (!copyFrom || copyFrom.type !== 'entityRealm') {\n\t\t\tconst stub: EntityRealmStateStub = {\n\t\t\t\ttype: 'entityRealmStub',\n\n\t\t\t\tblueprint,\n\t\t\t\tentity,\n\t\t\t\trealmKey,\n\t\t\t\tgetAccessor: () => this.materializeEntityRealm(stub).getAccessor(),\n\t\t\t}\n\t\t\tthis.registerEntityRealm(stub)\n\n\t\t\treturn stub\n\t\t}\n\t\tconst realm = this.createEntityRealm(blueprint, realmKey, entity, copyFrom)\n\n\t\tthis.registerEntityRealm(realm)\n\n\t\tconst marker = getEntityMarker(realm)\n\t\tconst pathBack = this.treeStore.getPathBackToParent(realm)\n\n\t\tfor (const [placeholderName, field] of marker.fields.markers) {\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tconst value = copyFrom.children.get(placeholderName)\n\t\t\t\tif (!value || value.type !== 'field') {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tthis.initializeFromFieldMarker(realm, field, undefined, value)\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\tconst value = copyFrom.children.get(placeholderName)\n\t\t\t\tif (!value || value.type !== 'entityList') {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tthis.initializeFromHasManyRelationMarker(realm, field, new Set(value.children.keys()))\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tlet runtimeId: RuntimeId\n\t\t\t\tlet subCopyFrom: EntityRealmState | undefined = undefined\n\t\t\t\tif (pathBack?.fieldBackToParent === field.parameters.field) {\n\t\t\t\t\truntimeId = pathBack.parent.entity.id\n\t\t\t\t} else {\n\t\t\t\t\tconst value = copyFrom.children.get(placeholderName)\n\t\t\t\t\tif (!value || (value.type !== 'entityRealm' && value.type !== 'entityRealmStub')) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\truntimeId = !(value.entity.id instanceof UnpersistedEntityDummyId) ? value.entity.id : new UnpersistedEntityDummyId()\n\t\t\t\t\tif (value.type === 'entityRealm') {\n\t\t\t\t\t\tsubCopyFrom = value\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.initializeFromHasOneRelationMarker(realm, field, runtimeId, subCopyFrom)\n\t\t\t} else {\n\t\t\t\tassertNever(field)\n\t\t\t}\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(realm)\n\t\treturn realm\n\t}\n\n\tprivate createEntityRealm(\n\t\tblueprint: EntityRealmBlueprint,\n\t\trealmKey: string,\n\t\tentity: EntityState,\n\t\tcopyFrom?: EntityRealmState,\n\t): EntityRealmState {\n\t\tconst entityRealm: EntityRealmState = {\n\t\t\ttype: 'entityRealm',\n\n\t\t\tblueprint,\n\t\t\trealmKey,\n\t\t\tentity,\n\n\t\t\taccessor: undefined,\n\t\t\tchildren: new Map(),\n\t\t\tchildrenWithPendingUpdates: undefined,\n\t\t\terrors: undefined,\n\t\t\teventListeners: this.initializeEntityEventListenerStore(blueprint),\n\t\t\tfieldsWithPendingConnectionUpdates: undefined,\n\t\t\tplannedHasOneDeletions: undefined,\n\t\t\tunpersistedChangesCount: copyFrom?.unpersistedChangesCount ?? 0,\n\t\t\tgetAccessor: () => {\n\t\t\t\tif (entityRealm.accessor === undefined) {\n\t\t\t\t\tconst entity = entityRealm.entity\n\t\t\t\t\tentityRealm.accessor = new EntityAccessor(\n\t\t\t\t\t\tentityRealm,\n\t\t\t\t\t\tthis.entityOperations,\n\t\t\t\t\t\tentity.id,\n\t\t\t\t\t\tentityRealm.realmKey,\n\t\t\t\t\t\tentity.entityName,\n\n\t\t\t\t\t\t// We're technically exposing more info in runtime than we'd like but that way we don't have to allocate and\n\t\t\t\t\t\t// keep in sync two copies of the same data. TS hides the extra info anyway.\n\t\t\t\t\t\tentityRealm.children,\n\t\t\t\t\t\tthis.treeStore.persistedEntityData.get(entity.id.uniqueValue),\n\t\t\t\t\t\tentityRealm.unpersistedChangesCount !== 0,\n\t\t\t\t\t\tentityRealm.errors,\n\t\t\t\t\t\tgetEntityMarker(entityRealm).environment,\n\t\t\t\t\t\tentityRealm.getAccessor,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn entityRealm.accessor\n\t\t\t},\n\t\t}\n\t\treturn entityRealm\n\t}\n\n\tprivate materializeEntityRealm(state: EntityRealmState | EntityRealmStateStub): EntityRealmState {\n\t\tif (state.type === 'entityRealm') {\n\t\t\treturn state\n\t\t}\n\t\tconst { realmKey, entity, blueprint } = state\n\n\t\tconst existing = this.treeStore.entityRealmStore.get(realmKey)\n\t\tif (existing !== undefined && existing.type === 'entityRealm') {\n\t\t\treturn existing\n\t\t}\n\n\t\tconst entityRealm = this.createEntityRealm(blueprint, realmKey, entity)\n\n\t\tthis.registerEntityRealm(entityRealm)\n\n\t\t// if (blueprint.creationParameters.forceCreation && !entity.id.existsOnServer) {\n\t\t// \tentityRealm.unpersistedChangesCount += 1\n\t\t// }\n\n\t\tconst persistedData = this.treeStore.persistedEntityData.get(entity.id.uniqueValue)\n\n\t\tconst marker = getEntityMarker(state)\n\t\tconst pathBack = this.treeStore.getPathBackToParent(entityRealm)\n\n\t\tfor (const [placeholderName, field] of marker.fields.markers) {\n\t\t\tconst fieldDatum = persistedData?.get(placeholderName)\n\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tthis.initializeFromFieldMarker(entityRealm, field, fieldDatum)\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\t// if (pathBack?.fieldBackToParent === field.parameters.field) {\n\t\t\t\t// \t// TODO this is probably wrong?\n\t\t\t\t// \tconst ids = pathBack.parent.children.get(field.placeholderName)\n\t\t\t\t// \tconst newData = this.treeStore.persistedEntityData.get(pathBack.parent.entity.id.value)\n\t\t\t\t// \tconsole.log('many?', pathBack, field, entityRealm, fieldDatum, ids)\n\t\t\t\t// }\n\t\t\t\tthis.initializeFromHasManyRelationMarker(entityRealm, field, fieldDatum instanceof Set ? fieldDatum : new Set())\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tlet runtimeId: RuntimeId\n\t\t\t\tif (pathBack?.fieldBackToParent === field.parameters.field) {\n\t\t\t\t\truntimeId = pathBack.parent.entity.id\n\t\t\t\t} else {\n\t\t\t\t\truntimeId = fieldDatum instanceof ServerId ? fieldDatum : new UnpersistedEntityDummyId()\n\t\t\t\t}\n\t\t\t\tthis.initializeFromHasOneRelationMarker(entityRealm, field, runtimeId)\n\t\t\t} else {\n\t\t\t\tassertNever(field)\n\t\t\t}\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(entityRealm)\n\n\t\treturn entityRealm\n\t}\n\n\tprivate registerEntityRealm(entityRealm: EntityRealmState | EntityRealmStateStub) {\n\t\tconst { realmKey, blueprint, entity } = entityRealm\n\n\t\tthis.treeStore.entityRealmStore.set(entityRealm.realmKey, entityRealm)\n\n\t\tif (blueprint.type === 'listEntity') {\n\t\t\tblueprint.parent.children.set(entity.id.value, entityRealm)\n\t\t} else if (blueprint.type === 'hasOne') {\n\t\t\tblueprint.parent.children.set(blueprint.marker.placeholderName, entityRealm)\n\t\t}\n\t\tentity.realms.set(realmKey, entityRealm)\n\t}\n\n\tpublic initializeEntityState(id: RuntimeId, entityName: EntityName): EntityState {\n\t\tconst entityId = id.uniqueValue\n\n\t\tconst existing = this.treeStore.entityStore.get(entityId)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\n\t\tconst entityState: EntityState = {\n\t\t\tentityName,\n\t\t\thasIdSetInStone: id instanceof ServerId,\n\t\t\tid,\n\t\t\tisScheduledForDeletion: false,\n\t\t\tmaidenId: id instanceof UnpersistedEntityDummyId ? id : undefined,\n\t\t\trealms: new Map(),\n\t\t}\n\t\tthis.treeStore.entityStore.set(entityId, entityState)\n\n\t\treturn entityState\n\t}\n\n\tprivate initializeEntityListState(\n\t\tblueprint: EntityListBlueprint,\n\t\tentityName: EntityName,\n\t\tinitialEntityIds: Set<EntityId>,\n\t): EntityListState {\n\t\tconst entityListState: EntityListState = {\n\t\t\ttype: 'entityList',\n\t\t\taccessor: undefined,\n\t\t\tblueprint,\n\t\t\tchildren: new BijectiveIndexedMap(realm => realm.entity.id.value),\n\t\t\tchildrenWithPendingUpdates: undefined,\n\t\t\tentityName,\n\t\t\teventListeners: this.initializeEntityListEventListenerStore(blueprint),\n\t\t\tchildEventListeners: this.initializeEntityListChildEventListenerStore(blueprint),\n\t\t\terrors: undefined,\n\t\t\tplannedRemovals: undefined,\n\t\t\tunpersistedChangesCount: 0, // TODO force creation?\n\t\t\tgetAccessor: () => {\n\t\t\t\tif (entityListState.accessor === undefined) {\n\t\t\t\t\tconst persistedEntityIds = this.treeStore.getEntityListPersistedIds(entityListState)\n\t\t\t\t\tentityListState.accessor = new EntityListAccessor(\n\t\t\t\t\t\tentityListState,\n\t\t\t\t\t\tthis.listOperations,\n\t\t\t\t\t\tentityListState.children,\n\t\t\t\t\t\tpersistedEntityIds,\n\t\t\t\t\t\tentityListState.unpersistedChangesCount !== 0,\n\t\t\t\t\t\tentityListState.errors,\n\t\t\t\t\t\tentityListState.blueprint.marker.environment,\n\t\t\t\t\t\tentityListState.getAccessor,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn entityListState.accessor\n\t\t\t},\n\t\t}\n\n\t\tconst initialData: Iterable<EntityId | undefined> =\n\t\t\tinitialEntityIds.size === 0\n\t\t\t\t? Array.from({ length: blueprint.marker.parameters.initialEntityCount })\n\t\t\t\t: initialEntityIds\n\t\tfor (const entityId of initialData) {\n\t\t\tthis.initializeEntityRealm(\n\t\t\t\tentityId ? new ServerId(entityId, entityName) : new UnpersistedEntityDummyId(),\n\t\t\t\tentityListState.entityName,\n\t\t\t\t{\n\t\t\t\t\ttype: 'listEntity',\n\t\t\t\t\tparent: entityListState,\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(entityListState)\n\n\t\treturn entityListState\n\t}\n\n\tprivate initializeFieldState(\n\t\tparent: EntityRealmState,\n\t\tplaceholderName: FieldName,\n\t\tfieldMarker: FieldMarker,\n\t\tpersistedValue: FieldValue | undefined,\n\t\tcopyFromState: FieldState | undefined,\n\t): FieldState {\n\t\tconst resolvedFieldValue = copyFromState ? copyFromState.value : (persistedValue ?? fieldMarker.defaultValue ?? null)\n\n\t\tconst fieldState: FieldState = {\n\t\t\ttype: 'field',\n\t\t\taccessor: undefined,\n\t\t\tfieldMarker,\n\t\t\tplaceholderName,\n\t\t\tpersistedValue,\n\t\t\tparent,\n\t\t\tvalue: resolvedFieldValue,\n\t\t\teventListeners: this.initializeFieldEventListenerStore(fieldMarker),\n\t\t\terrors: undefined,\n\t\t\ttouchLog: undefined,\n\t\t\thasUnpersistedChanges: copyFromState?.hasUnpersistedChanges ?? false,\n\n\t\t\tgetAccessor: () => {\n\t\t\t\tif (fieldState.accessor === undefined) {\n\t\t\t\t\tconst fieldSchema = this.treeStore.schema.getEntityColumn(parent.entity.entityName, fieldMarker.fieldName)\n\n\t\t\t\t\tfieldState.accessor = new FieldAccessor(\n\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\tthis.fieldOperations,\n\t\t\t\t\t\tfieldState.placeholderName,\n\t\t\t\t\t\tfieldState.value,\n\t\t\t\t\t\tfieldState.persistedValue === undefined ? null : fieldState.persistedValue,\n\t\t\t\t\t\tfieldState.fieldMarker.defaultValue,\n\t\t\t\t\t\tfieldState.errors,\n\t\t\t\t\t\tfieldState.hasUnpersistedChanges,\n\t\t\t\t\t\tfieldState.touchLog,\n\t\t\t\t\t\tfieldState.getAccessor,\n\t\t\t\t\t\tfieldSchema,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn fieldState.accessor\n\t\t\t},\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(fieldState)\n\t\treturn fieldState\n\t}\n\n\tprivate initializeFromFieldMarker(\n\t\tparent: EntityRealmState,\n\t\tfield: FieldMarker,\n\t\tpersistedValue: EntityFieldPersistedData | undefined,\n\t\tcopyFromState?: FieldState,\n\t) {\n\t\tif (persistedValue instanceof Set) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Received a collection of referenced entities where a single '${field.fieldName}' field was expected. ` +\n\t\t\t\t\t`Perhaps you wanted to use a <Repeater />?`,\n\t\t\t)\n\t\t}\n\t\tif (persistedValue instanceof ServerId) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Received a referenced entity where a single '${field.fieldName}' field was expected. ` +\n\t\t\t\t\t`Perhaps you wanted to use <HasOne />?`,\n\t\t\t)\n\t\t}\n\t\tparent.children.set(\n\t\t\tfield.placeholderName,\n\t\t\tthis.initializeFieldState(parent, field.placeholderName, field, persistedValue, copyFromState),\n\t\t)\n\t}\n\n\tprivate initializeFromHasOneRelationMarker(\n\t\tparent: EntityRealmState,\n\t\tfield: HasOneRelationMarker,\n\t\tentityId: RuntimeId,\n\t\tcopyFrom?: EntityRealmState | EntityRealmStateStub,\n\t) {\n\t\tparent.children.set(\n\t\t\tfield.placeholderName,\n\t\t\tthis.initializeEntityRealm(entityId, this.getRelationTargetEntityName(parent, field), {\n\t\t\t\ttype: 'hasOne',\n\t\t\t\tparent,\n\t\t\t\tmarker: field,\n\t\t\t}, copyFrom),\n\t\t)\n\t\t// if (fieldDatum instanceof ServerGeneratedUuid || fieldDatum === null || fieldDatum === undefined) {\n\t\t// \tconst entityId = fieldDatum instanceof ServerGeneratedUuid ? fieldDatum : new UnpersistedEntityDummyId()\n\t\t//\n\t\t//\n\t\t// } else if (fieldDatum instanceof Set) {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a collection of entities for field '${relation.field}' where a single entity was expected. ` +\n\t\t// \t\t\t`Perhaps you wanted to use a <Repeater />?`,\n\t\t// \t)\n\t\t// } else {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a scalar value for field '${relation.field}' where a single entity was expected.` +\n\t\t// \t\t\t`Perhaps you meant to use a variant of <Field />?`,\n\t\t// \t)\n\t\t// }\n\t}\n\n\tprivate initializeFromHasManyRelationMarker(\n\t\tparent: EntityRealmState,\n\t\tfield: HasManyRelationMarker,\n\t\tpersistedEntityIds: Set<EntityId>,\n\t) {\n\t\tparent.children.set(\n\t\t\tfield.placeholderName,\n\t\t\tthis.initializeEntityListState(\n\t\t\t\t{ marker: field, parent },\n\t\t\t\tthis.getRelationTargetEntityName(parent, field),\n\t\t\t\tpersistedEntityIds,\n\t\t\t),\n\t\t)\n\t\t// const relation = field.parameters\n\t\t//\n\t\t// if (fieldDatum === undefined || fieldDatum instanceof Set) {\n\t\t//\n\t\t// } else if (typeof fieldDatum === 'object') {\n\t\t// \t// Intentionally allowing `fieldDatum === null` here as well since this should only happen when a *hasOne\n\t\t// \t// relation is unlinked, e.g. a Person does not have a linked Nationality.\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a referenced entity for field '${relation.field}' where a collection of entities was expected.` +\n\t\t// \t\t\t`Perhaps you wanted to use a <HasOne />?`,\n\t\t// \t)\n\t\t// } else {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a scalar value for field '${relation.field}' where a collection of entities was expected.` +\n\t\t// \t\t\t`Perhaps you meant to use a variant of <Field />?`,\n\t\t// \t)\n\t\t// }\n\t}\n\n\tprivate getRelationTargetEntityName(\n\t\tentityRealm: EntityRealmState,\n\t\tfield: HasOneRelationMarker | HasManyRelationMarker,\n\t): EntityName {\n\t\tconst targetField = this.treeStore.schema.getEntityRelation(entityRealm.entity.entityName, field.parameters.field)\n\t\treturn targetField.targetEntity\n\t}\n\n\tpublic runImmediateUserInitialization(\n\t\trealm: EntityRealmState | EntityRealmStateStub,\n\t\tinitialize: EntityAccessor.BatchUpdatesHandler | undefined,\n\t) {\n\t\tif (initialize === undefined) {\n\t\t\treturn\n\t\t}\n\t\tconst entityRealm = this.materializeEntityRealm(realm)\n\n\t\trealm.getAccessor().batchUpdates(initialize)\n\n\t\tconst initializeListeners = this.eventManager.getEventListeners(entityRealm, { type: 'initialize' })\n\t\tif (initializeListeners === undefined || initializeListeners.size === 0) {\n\t\t\trealm.entity.hasIdSetInStone = true\n\t\t}\n\t}\n\n\tpublic initializeEntityEventListenerStore(blueprint: EntityRealmBlueprint): EntityEventListenerStore | undefined {\n\t\tif (blueprint.type === 'listEntity') {\n\t\t\tconst blueprintListeners = blueprint.parent.blueprint.marker.parameters.childEventListeners\n\t\t\tconst childInitialize = blueprintListeners?.get({ type: 'initialize' })\n\t\t\tconst store: EntityEventListenerStore = new EventListenersStore(() => blueprint.parent.childEventListeners)\n\n\t\t\tif (childInitialize !== undefined) {\n\t\t\t\tstore.set({ type: 'initialize' }, childInitialize)\n\t\t\t}\n\t\t\treturn store\n\t\t}\n\n\t\tconst blueprintListeners = blueprint.marker.parameters.eventListeners\n\t\tif (blueprintListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn TreeParameterMerger.cloneSingleEntityEventListeners(blueprintListeners)\n\t}\n\n\tprivate initializeEntityListEventListenerStore(\n\t\tblueprint: EntityListBlueprint,\n\t): EntityListEventListenerStore | undefined {\n\t\tconst blueprintListeners = blueprint.marker.parameters.eventListeners\n\n\t\tif (blueprintListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn TreeParameterMerger.cloneEntityListEventListeners(blueprintListeners)\n\t}\n\n\tprivate initializeEntityListChildEventListenerStore(\n\t\tblueprint: EntityListBlueprint,\n\t): EntityEventListenerStore | undefined {\n\t\tconst blueprintListeners = blueprint.marker.parameters.childEventListeners\n\n\t\tif (blueprintListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn TreeParameterMerger.cloneSingleEntityEventListeners(blueprintListeners)\n\t}\n\n\tprivate initializeFieldEventListenerStore(marker: FieldMarker): FieldEventListenerStore | undefined {\n\t\t// TODO !!!\n\t\treturn undefined\n\t}\n}\n"],"names":["entity","blueprintListeners"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAwCO,MAAM,iBAAiB;AAAA,EAKtB,YACN,sBACA,qBACiB,cACA,WAChB;AATe;AACA;AACA;AAKC,SAAA,eAAA;AACA,SAAA,YAAA;AAEZ,SAAA,kBAAkB,IAAI,gBAAgB,sBAAsB,KAAK,cAAc,MAAM,KAAK,SAAS;AACnG,SAAA,mBAAmB,IAAI,iBAAiB,sBAAsB,qBAAqB,KAAK,cAAc,MAAM,KAAK,SAAS;AAC1H,SAAA,iBAAiB,IAAI,eAAe,sBAAsB,qBAAqB,KAAK,cAAc,MAAM,KAAK,SAAS;AAAA,EAC5H;AAAA,EAEO,kBAAkB,MAAoE;AACxF,QAAA;AACJ,UAAM,oBAAoB,KAAK,UA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B,aAAA;AAAA,IACR;AACO,WAAA,oBAAoB,gCAAgC,kBAAkB;AAAA,EAC9E;AAAA,EAEQ,kCAAkC,QAA0D;AAE5F,WAAA;AAAA,EACR;AACD;"}
@@ -5,10 +5,11 @@ import { assert } from "../utils/assert.js";
5
5
  import { ServerId, UnpersistedEntityDummyId, ClientGeneratedUuid } from "../accessorTree/RuntimeId.js";
6
6
  import { assertNever } from "../utils/assertNever.js";
7
7
  class TreeAugmenter {
8
- constructor(eventManager, stateInitializer, treeStore) {
8
+ constructor(eventManager, stateInitializer, treeStore, skipStateUpdateAfterPersist = false) {
9
9
  this.eventManager = eventManager;
10
10
  this.stateInitializer = stateInitializer;
11
11
  this.treeStore = treeStore;
12
+ this.skipStateUpdateAfterPersist = skipStateUpdateAfterPersist;
12
13
  }
13
14
  extendPersistedData(newPersistedData, markerTree) {
14
15
  this.treeStore.mergeInQueryResponse(newPersistedData, markerTree);
@@ -24,6 +25,9 @@ class TreeAugmenter {
24
25
  }
25
26
  updatePersistedData(response, operations) {
26
27
  this.treeStore.mergeInMutationResponse(response, operations);
28
+ if (this.skipStateUpdateAfterPersist) {
29
+ return;
30
+ }
27
31
  this.eventManager.syncTransaction(() => {
28
32
  for (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {
29
33
  for (const [rootPlaceholder, rootState] of rootStates) {
@@ -64,7 +68,10 @@ class TreeAugmenter {
64
68
  rootState.childrenWithPendingUpdates?.clear();
65
69
  rootState.errors = void 0;
66
70
  rootState.plannedRemovals?.clear();
67
- this.eventManager.registerJustUpdated(rootState, changesCount ? -1 * changesCount : EventManager.NO_CHANGES_DIFFERENCE);
71
+ this.eventManager.registerJustUpdated(
72
+ rootState,
73
+ changesCount ? -1 * changesCount : EventManager.NO_CHANGES_DIFFERENCE
74
+ );
68
75
  } else if (rootState.type === "entityRealm") {
69
76
  assert(rootState.blueprint.parent === void 0);
70
77
  if (!rootState.blueprint.marker.parameters.isCreating) {
@@ -165,10 +172,22 @@ class TreeAugmenter {
165
172
  continue;
166
173
  } else {
167
174
  const drawnId = persistedWithoutState.shift();
168
- OperationsHelpers.changeRealmId(this.treeStore, this.eventManager, this.stateInitializer, child, new ServerId(drawnId, child.entity.entityName));
175
+ OperationsHelpers.changeRealmId(
176
+ this.treeStore,
177
+ this.eventManager,
178
+ this.stateInitializer,
179
+ child,
180
+ new ServerId(drawnId, child.entity.entityName)
181
+ );
169
182
  }
170
183
  } else if (childRuntimeId instanceof ClientGeneratedUuid) {
171
- OperationsHelpers.changeRealmId(this.treeStore, this.eventManager, this.stateInitializer, child, new ServerId(childRuntimeId.value, child.entity.entityName));
184
+ OperationsHelpers.changeRealmId(
185
+ this.treeStore,
186
+ this.eventManager,
187
+ this.stateInitializer,
188
+ child,
189
+ new ServerId(childRuntimeId.value, child.entity.entityName)
190
+ );
172
191
  }
173
192
  if (child.type === "entityRealm") {
174
193
  this.updateEntityRealmPersistedData(child);
@@ -183,5 +202,7 @@ class TreeAugmenter {
183
202
  state.children.changeKeyOrder(newPersistedIds);
184
203
  }
185
204
  }
186
- export { TreeAugmenter };
205
+ export {
206
+ TreeAugmenter
207
+ };
187
208
  //# sourceMappingURL=TreeAugmenter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TreeAugmenter.js","sources":["../../../src/core/TreeAugmenter.ts"],"sourcesContent":["import {\n\tClientGeneratedUuid,\n\tEntityListPersistedData,\n\tReceivedDataTree,\n\tRuntimeId,\n\tServerId,\n\tUnpersistedEntityDummyId,\n} from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { EntityId, PlaceholderName, TreeRootId } from '../treeParameters'\nimport { assert, assertNever } from '../utils'\nimport { EventManager } from './EventManager'\nimport { OperationsHelpers } from './operations/OperationsHelpers'\nimport type { EntityListState, EntityRealmState, EntityRealmStateStub, RootStateNode } from './state'\nimport type { StateInitializer } from './StateInitializer'\nimport type { TreeStore } from './TreeStore'\nimport { SubMutationOperation } from './MutationGenerator'\n\nexport class TreeAugmenter {\n\tpublic constructor(\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic extendPersistedData(newPersistedData: ReceivedDataTree, markerTree: MarkerTreeRoot) {\n\t\t// TODO this doesn't yet handle updates for entities whose persisted data just gets magically changed without notice.\n\t\tthis.treeStore.mergeInQueryResponse(newPersistedData, markerTree)\n\t}\n\n\tpublic extendTreeStates(newTreeId: TreeRootId | undefined, newMarkerTree: MarkerTreeRoot): void {\n\t\tconst subTreeStates: Map<PlaceholderName, RootStateNode> = new Map()\n\n\t\tthis.treeStore.markerTrees.set(newTreeId, newMarkerTree)\n\t\tthis.treeStore.subTreeStatesByRoot.set(newTreeId, subTreeStates)\n\n\t\tfor (const [placeholderName, newSubTreeMarker] of newMarkerTree.subTrees) {\n\t\t\tconst newState = this.stateInitializer.initializeSubTree(newSubTreeMarker)\n\t\t\tsubTreeStates.set(placeholderName, newState)\n\t\t}\n\t}\n\n\tpublic updatePersistedData(response: ReceivedDataTree, operations: SubMutationOperation[]) {\n\t\tthis.treeStore.mergeInMutationResponse(response, operations)\n\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\t\t// for (const rootPlaceholder in response) {\n\t\t\t\t// \tconst rootState = rootStates.get(rootPlaceholder)\n\t\t\t\t//\n\t\t\t\t// \tif (rootState === undefined) {\n\t\t\t\t// \t\tcontinue\n\t\t\t\t// \t}\n\t\t\t\t// TODO the above would be better, only refreshing roots which participated in the mutation. However, due to\n\t\t\t\t// \thow mutations are currently generated, we cannot assume that only roots present in the response need\n\t\t\t\t// \trefreshed. So we just refresh all.\n\t\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\t\tconst rootData = this.treeStore.subTreePersistedData.get(rootPlaceholder)\n\n\t\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\t\tif (!(rootData instanceof Set)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateEntityListPersistedData(rootState, rootData)\n\t\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\t\tif (rootData !== undefined && !(rootData instanceof ServerId)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateRealmIdIfNecessary(rootState, rootData)\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(rootState)\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn assertNever(rootState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic resetCreatingSubTrees() {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\tassert(rootState.blueprint.parent === undefined)\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst changesCount = rootState.unpersistedChangesCount\n\n\t\t\t\t\t// Just emptying the list. But the list itself can stay.\n\t\t\t\t\tfor (const childState of rootState.children.values()) {\n\t\t\t\t\t\tthis.treeStore.disposeOfRealm(childState)\n\t\t\t\t\t}\n\t\t\t\t\trootState.accessor = undefined\n\t\t\t\t\trootState.children.clear()\n\t\t\t\t\trootState.childrenWithPendingUpdates?.clear()\n\t\t\t\t\trootState.errors = undefined\n\t\t\t\t\trootState.plannedRemovals?.clear()\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(\n\t\t\t\t\t\trootState,\n\t\t\t\t\t\tchangesCount ? -1 * changesCount : EventManager.NO_CHANGES_DIFFERENCE,\n\t\t\t\t\t)\n\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\tassert(rootState.blueprint.parent === undefined)\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst presentListeners = rootState.eventListeners\n\t\t\t\t\tthis.treeStore.disposeOfRealm(rootState)\n\n\t\t\t\t\t// It's crucial to delete the persisted data before we re-initialize so that we get a fresh, new entity.\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst newRootState = this.stateInitializer.initializeSubTree(rootState.blueprint.marker)\n\n\t\t\t\t\t// We preserve the previous listeners but purge some of them.\n\t\t\t\t\tnewRootState.eventListeners = presentListeners\n\t\t\t\t\tOperationsHelpers.purgeStaleListenersAfterIdChange(newRootState as EntityRealmState)\n\n\t\t\t\t\trootStates.set(rootPlaceholder, newRootState)\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(newRootState, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(rootState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateRealmIdIfNecessary(\n\t\trealm: EntityRealmState | EntityRealmStateStub,\n\t\tnewId: ServerId | undefined | null,\n\t) {\n\t\tconst currentId = realm.entity.id\n\t\tlet idToChangeTo: RuntimeId | undefined = undefined\n\n\t\tif (currentId instanceof ServerId) {\n\t\t\tif (newId === undefined || newId === null) {\n\t\t\t\tidToChangeTo = new UnpersistedEntityDummyId()\n\t\t\t} else if (currentId.value !== newId.value) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else if (currentId instanceof ClientGeneratedUuid) {\n\t\t\tidToChangeTo = newId ?? new UnpersistedEntityDummyId()\n\t\t} else if (currentId instanceof UnpersistedEntityDummyId) {\n\t\t\tif (newId) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else {\n\t\t\treturn assertNever(currentId)\n\t\t}\n\t\tif (idToChangeTo) {\n\t\t\tOperationsHelpers.changeRealmId(this.treeStore, this.eventManager, this.stateInitializer, realm, idToChangeTo)\n\t\t}\n\t}\n\n\tprivate updateEntityRealmPersistedData(realm: EntityRealmState) {\n\t\tconst realmId = realm.entity.id\n\t\tconst persistedData = realmId.existsOnServer ? this.treeStore.persistedEntityData.get(realmId.uniqueValue) : undefined\n\n\t\tfor (const [placeholderName, child] of realm.children) {\n\t\t\tconst childData = persistedData?.get(placeholderName)\n\n\t\t\tswitch (child.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (childData instanceof ServerId || childData instanceof Set) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (child.persistedValue !== childData) {\n\t\t\t\t\t\tconst shouldChangeBothValues = child.persistedValue === child.value\n\n\t\t\t\t\t\tchild.persistedValue = childData\n\t\t\t\t\t\tif (shouldChangeBothValues) {\n\t\t\t\t\t\t\tchild.value = childData ?? null\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.eventManager.registerJustUpdated(child, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\tif (!(childData instanceof ServerId) && childData !== undefined && childData !== null) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateRealmIdIfNecessary(child, childData)\n\t\t\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (childData !== undefined && !(childData instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateEntityListPersistedData(child, childData ?? new Set()) // TODO!!\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn assertNever(child)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateEntityListPersistedData(state: EntityListState, newPersistedIds: EntityListPersistedData) {\n\t\tconst persistedWithoutState: EntityId[] = []\n\n\t\t// TODO This isn't particularly efficient. We should probably use something like diff-sequence here.\n\n\t\tfor (const persistedId of newPersistedIds) {\n\t\t\tif (!state.children.has(persistedId)) {\n\t\t\t\tpersistedWithoutState.push(persistedId)\n\t\t\t}\n\t\t}\n\t\tfor (const [stateId, child] of state.children) {\n\t\t\tconst childRuntimeId = child.entity.id\n\t\t\tif (!newPersistedIds.has(stateId)) {\n\t\t\t\tif (\n\t\t\t\t\t// It's a uuid but it's not among the persisted so either it got deleted/disconnected or the client-side\n\t\t\t\t\t// id generation didn't quite pan out.\n\t\t\t\t\tchildRuntimeId instanceof ServerId ||\n\t\t\t\t\tchildRuntimeId instanceof ClientGeneratedUuid ||\n\t\t\t\t\t// No persisted entity id to allocate to this so that's a goodbye.\n\t\t\t\t\tpersistedWithoutState.length === 0\n\t\t\t\t) {\n\t\t\t\t\tstate.getAccessor().disconnectEntity(child.getAccessor())\n\t\t\t\t\tcontinue\n\t\t\t\t} else {\n\t\t\t\t\tconst drawnId = persistedWithoutState.shift()!\n\t\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\t\tthis.treeStore,\n\t\t\t\t\t\tthis.eventManager,\n\t\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\t\tchild,\n\t\t\t\t\t\tnew ServerId(drawnId, child.entity.entityName),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (childRuntimeId instanceof ClientGeneratedUuid) {\n\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\tthis.treeStore,\n\t\t\t\t\tthis.eventManager,\n\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\tchild,\n\t\t\t\t\tnew ServerId(childRuntimeId.value, child.entity.entityName),\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t}\n\t\t}\n\t\tfor (const unclaimedPersistedId of persistedWithoutState) {\n\t\t\tthis.stateInitializer.initializeEntityRealm(new ServerId(unclaimedPersistedId, state.entityName), state.entityName, {\n\t\t\t\ttype: 'listEntity',\n\t\t\t\tparent: state,\n\t\t\t})\n\t\t}\n\t\t// All that remains now is the order.\n\t\tstate.children.changeKeyOrder(newPersistedIds)\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAmBO,MAAM,cAAc;AAAA,EACnB,YACW,cACA,kBACA,WAChB;AAHgB,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AAAA,EACf;AAAA,EAEI,oBAAoB,kBAAoC,YAA4B;AAErF,SAAA,UAAU,qBAAqB,kBAAkB,UAAU;AAAA,EACjE;AAAA,EAEO,iBAAiB,WAAmC,eAAqC;AACzF,UAAA,oCAAyD;AAE/D,SAAK,UAAU,YAAY,IAAI,WAAW,aAAa;AACvD,SAAK,UAAU,oBAAoB,IAAI,WAAW,aAAa;AAE/D,eAAW,CAAC,iBAAiB,qBAAqB,cAAc,UAAU;AACzE,YAAM,WAAW,KAAK,iBAAiB,kBAAkB,gBAAgB;AAC3D,oBAAA,IAAI,iBAAiB,QAAQ;AAAA,IAC5C;AAAA,EACD;AAAA,EAEO,oBAAoB,UAA4B,YAAoC;AACrF,SAAA,UAAU,wBAAwB,UAAU,UAAU;AAEtD,SAAA,aAAa,gBAAgB,MAAM;AACvC,iBAAW,cAAc,KAAK,UAAU,oBAAoB,UAAU;AAU1D,mBAAA,CAAC,iBAAiB,cAAc,YAAY;AACtD,gBAAM,WAAW,KAAK,UAAU,qBAAqB,IAAI,eAAe;AAEpE,cAAA,UAAU,SAAS,cAAc;AAChC,gBAAA,sBAAsB,MAAM;AAC/B;AAAA,YACD;AACK,iBAAA,8BAA8B,WAAW,QAAQ;AAAA,UAAA,WAC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,IACD;AACA,eAAW,wBAAwB,uBAAuB;AACpD,WAAA,iBAAiB,sBAAsB,IAAI,SAAS,sBAAsB,MAAM,UAAU,GAAG,MAAM,YAAY;AAAA,QACnH,MAAM;AAAA,QACN,QAAQ;AAAA,MAAA,CACR;AAAA,IACF;AAEM,UAAA,SAAS,eAAe,eAAe;AAAA,EAC9C;AACD;;"}
1
+ {"version":3,"file":"TreeAugmenter.js","sources":["../../../src/core/TreeAugmenter.ts"],"sourcesContent":["import {\n\tClientGeneratedUuid,\n\tEntityListPersistedData,\n\tReceivedDataTree,\n\tRuntimeId,\n\tServerId,\n\tUnpersistedEntityDummyId,\n} from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { EntityId, PlaceholderName, TreeRootId } from '../treeParameters'\nimport { assert, assertNever } from '../utils'\nimport { EventManager } from './EventManager'\nimport { OperationsHelpers } from './operations/OperationsHelpers'\nimport type { EntityListState, EntityRealmState, EntityRealmStateStub, RootStateNode } from './state'\nimport type { StateInitializer } from './StateInitializer'\nimport type { TreeStore } from './TreeStore'\nimport { SubMutationOperation } from './MutationGenerator'\n\nexport class TreeAugmenter {\n\tpublic constructor(\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly skipStateUpdateAfterPersist: boolean = false,\n\t) {}\n\n\tpublic extendPersistedData(newPersistedData: ReceivedDataTree, markerTree: MarkerTreeRoot) {\n\t\t// TODO this doesn't yet handle updates for entities whose persisted data just gets magically changed without notice.\n\t\tthis.treeStore.mergeInQueryResponse(newPersistedData, markerTree)\n\t}\n\n\tpublic extendTreeStates(newTreeId: TreeRootId | undefined, newMarkerTree: MarkerTreeRoot): void {\n\t\tconst subTreeStates: Map<PlaceholderName, RootStateNode> = new Map()\n\n\t\tthis.treeStore.markerTrees.set(newTreeId, newMarkerTree)\n\t\tthis.treeStore.subTreeStatesByRoot.set(newTreeId, subTreeStates)\n\n\t\tfor (const [placeholderName, newSubTreeMarker] of newMarkerTree.subTrees) {\n\t\t\tconst newState = this.stateInitializer.initializeSubTree(newSubTreeMarker)\n\t\t\tsubTreeStates.set(placeholderName, newState)\n\t\t}\n\t}\n\n\tpublic updatePersistedData(response: ReceivedDataTree, operations: SubMutationOperation[]) {\n\t\tthis.treeStore.mergeInMutationResponse(response, operations)\n\t\tif (this.skipStateUpdateAfterPersist) {\n\t\t\treturn\n\t\t}\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\t\t// for (const rootPlaceholder in response) {\n\t\t\t\t// \tconst rootState = rootStates.get(rootPlaceholder)\n\t\t\t\t//\n\t\t\t\t// \tif (rootState === undefined) {\n\t\t\t\t// \t\tcontinue\n\t\t\t\t// \t}\n\t\t\t\t// TODO the above would be better, only refreshing roots which participated in the mutation. However, due to\n\t\t\t\t// \thow mutations are currently generated, we cannot assume that only roots present in the response need\n\t\t\t\t// \trefreshed. So we just refresh all.\n\t\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\t\tconst rootData = this.treeStore.subTreePersistedData.get(rootPlaceholder)\n\n\t\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\t\tif (!(rootData instanceof Set)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateEntityListPersistedData(rootState, rootData)\n\t\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\t\tif (rootData !== undefined && !(rootData instanceof ServerId)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateRealmIdIfNecessary(rootState, rootData)\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(rootState)\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn assertNever(rootState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic resetCreatingSubTrees() {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\tassert(rootState.blueprint.parent === undefined)\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst changesCount = rootState.unpersistedChangesCount\n\n\t\t\t\t\t// Just emptying the list. But the list itself can stay.\n\t\t\t\t\tfor (const childState of rootState.children.values()) {\n\t\t\t\t\t\tthis.treeStore.disposeOfRealm(childState)\n\t\t\t\t\t}\n\t\t\t\t\trootState.accessor = undefined\n\t\t\t\t\trootState.children.clear()\n\t\t\t\t\trootState.childrenWithPendingUpdates?.clear()\n\t\t\t\t\trootState.errors = undefined\n\t\t\t\t\trootState.plannedRemovals?.clear()\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(\n\t\t\t\t\t\trootState,\n\t\t\t\t\t\tchangesCount ? -1 * changesCount : EventManager.NO_CHANGES_DIFFERENCE,\n\t\t\t\t\t)\n\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\tassert(rootState.blueprint.parent === undefined)\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst presentListeners = rootState.eventListeners\n\t\t\t\t\tthis.treeStore.disposeOfRealm(rootState)\n\n\t\t\t\t\t// It's crucial to delete the persisted data before we re-initialize so that we get a fresh, new entity.\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst newRootState = this.stateInitializer.initializeSubTree(rootState.blueprint.marker)\n\n\t\t\t\t\t// We preserve the previous listeners but purge some of them.\n\t\t\t\t\tnewRootState.eventListeners = presentListeners\n\t\t\t\t\tOperationsHelpers.purgeStaleListenersAfterIdChange(newRootState as EntityRealmState)\n\n\t\t\t\t\trootStates.set(rootPlaceholder, newRootState)\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(newRootState, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(rootState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateRealmIdIfNecessary(\n\t\trealm: EntityRealmState | EntityRealmStateStub,\n\t\tnewId: ServerId | undefined | null,\n\t) {\n\t\tconst currentId = realm.entity.id\n\t\tlet idToChangeTo: RuntimeId | undefined = undefined\n\n\t\tif (currentId instanceof ServerId) {\n\t\t\tif (newId === undefined || newId === null) {\n\t\t\t\tidToChangeTo = new UnpersistedEntityDummyId()\n\t\t\t} else if (currentId.value !== newId.value) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else if (currentId instanceof ClientGeneratedUuid) {\n\t\t\tidToChangeTo = newId ?? new UnpersistedEntityDummyId()\n\t\t} else if (currentId instanceof UnpersistedEntityDummyId) {\n\t\t\tif (newId) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else {\n\t\t\treturn assertNever(currentId)\n\t\t}\n\t\tif (idToChangeTo) {\n\t\t\tOperationsHelpers.changeRealmId(this.treeStore, this.eventManager, this.stateInitializer, realm, idToChangeTo)\n\t\t}\n\t}\n\n\tprivate updateEntityRealmPersistedData(realm: EntityRealmState) {\n\t\tconst realmId = realm.entity.id\n\t\tconst persistedData = realmId.existsOnServer ? this.treeStore.persistedEntityData.get(realmId.uniqueValue) : undefined\n\n\t\tfor (const [placeholderName, child] of realm.children) {\n\t\t\tconst childData = persistedData?.get(placeholderName)\n\n\t\t\tswitch (child.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (childData instanceof ServerId || childData instanceof Set) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (child.persistedValue !== childData) {\n\t\t\t\t\t\tconst shouldChangeBothValues = child.persistedValue === child.value\n\n\t\t\t\t\t\tchild.persistedValue = childData\n\t\t\t\t\t\tif (shouldChangeBothValues) {\n\t\t\t\t\t\t\tchild.value = childData ?? null\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.eventManager.registerJustUpdated(child, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\tif (!(childData instanceof ServerId) && childData !== undefined && childData !== null) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateRealmIdIfNecessary(child, childData)\n\t\t\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (childData !== undefined && !(childData instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateEntityListPersistedData(child, childData ?? new Set()) // TODO!!\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn assertNever(child)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateEntityListPersistedData(state: EntityListState, newPersistedIds: EntityListPersistedData) {\n\t\tconst persistedWithoutState: EntityId[] = []\n\n\t\t// TODO This isn't particularly efficient. We should probably use something like diff-sequence here.\n\n\t\tfor (const persistedId of newPersistedIds) {\n\t\t\tif (!state.children.has(persistedId)) {\n\t\t\t\tpersistedWithoutState.push(persistedId)\n\t\t\t}\n\t\t}\n\t\tfor (const [stateId, child] of state.children) {\n\t\t\tconst childRuntimeId = child.entity.id\n\t\t\tif (!newPersistedIds.has(stateId)) {\n\t\t\t\tif (\n\t\t\t\t\t// It's a uuid but it's not among the persisted so either it got deleted/disconnected or the client-side\n\t\t\t\t\t// id generation didn't quite pan out.\n\t\t\t\t\tchildRuntimeId instanceof ServerId ||\n\t\t\t\t\tchildRuntimeId instanceof ClientGeneratedUuid ||\n\t\t\t\t\t// No persisted entity id to allocate to this so that's a goodbye.\n\t\t\t\t\tpersistedWithoutState.length === 0\n\t\t\t\t) {\n\t\t\t\t\tstate.getAccessor().disconnectEntity(child.getAccessor())\n\t\t\t\t\tcontinue\n\t\t\t\t} else {\n\t\t\t\t\tconst drawnId = persistedWithoutState.shift()!\n\t\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\t\tthis.treeStore,\n\t\t\t\t\t\tthis.eventManager,\n\t\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\t\tchild,\n\t\t\t\t\t\tnew ServerId(drawnId, child.entity.entityName),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (childRuntimeId instanceof ClientGeneratedUuid) {\n\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\tthis.treeStore,\n\t\t\t\t\tthis.eventManager,\n\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\tchild,\n\t\t\t\t\tnew ServerId(childRuntimeId.value, child.entity.entityName),\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t}\n\t\t}\n\t\tfor (const unclaimedPersistedId of persistedWithoutState) {\n\t\t\tthis.stateInitializer.initializeEntityRealm(new ServerId(unclaimedPersistedId, state.entityName), state.entityName, {\n\t\t\t\ttype: 'listEntity',\n\t\t\t\tparent: state,\n\t\t\t})\n\t\t}\n\t\t// All that remains now is the order.\n\t\tstate.children.changeKeyOrder(newPersistedIds)\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAmBO,MAAM,cAAc;AAAA,EACnB,YACW,cACA,kBACA,WACA,8BAAuC,OACvD;AAJgB,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-25,7 +25,11 @@ class TreeFilterGenerator {
25
25
  return filters;
26
26
  }
27
27
  if (persistedData instanceof ServerId) {
28
- const filter = this.generateTopLevelEntityFilter(persistedData.value, subTree.parameters.entityName, subTree.fields);
28
+ const filter = this.generateTopLevelEntityFilter(
29
+ persistedData.value,
30
+ subTree.parameters.entityName,
31
+ subTree.fields
32
+ );
29
33
  filter && filters.push(filter);
30
34
  } else {
31
35
  for (const id of persistedData) {
@@ -73,5 +77,7 @@ class TreeFilterGenerator {
73
77
  return relations;
74
78
  }
75
79
  }
76
- export { TreeFilterGenerator };
80
+ export {
81
+ TreeFilterGenerator
82
+ };
77
83
  //# sourceMappingURL=TreeFilterGenerator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TreeFilterGenerator.js","sources":["../../../src/core/TreeFilterGenerator.ts"],"sourcesContent":["import type { RelationFilter, TreeFilter } from '@contember/client'\nimport { EntityListPersistedData, ServerId } from '../accessorTree'\nimport {\n\tEntityFieldMarkersContainer,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n} from '../markers'\nimport type { EntityId, EntityName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport { StateIterator } from './state'\nimport type { TreeStore } from './TreeStore'\n\ntype RawRelationFilters = Map<string, RawRelationFilters>\n\nexport class TreeFilterGenerator {\n\tpublic constructor(private readonly treeStore: TreeStore) {}\n\n\tpublic generateTreeFilter(): TreeFilter[] {\n\t\tconst filters: TreeFilter[][] = []\n\n\t\tfor (const [placeholderName, state] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\tconst blueprint = state.blueprint\n\n\t\t\tif (blueprint.parent || blueprint.marker.parameters.expectedMutation === 'none') {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst marker = blueprint.marker\n\t\t\tfilters.push(this.generateSubTreeFilter(marker, this.treeStore.subTreePersistedData.get(placeholderName)))\n\t\t}\n\t\treturn filters.flat()\n\t}\n\n\tprivate generateSubTreeFilter(\n\t\tsubTree: EntitySubTreeMarker | EntityListSubTreeMarker,\n\t\tpersistedData: ServerId | EntityListPersistedData | undefined,\n\t): TreeFilter[] {\n\t\tconst filters: TreeFilter[] = []\n\n\t\tif (persistedData === undefined) {\n\t\t\treturn filters // Do nothing\n\t\t}\n\n\t\tif (persistedData instanceof ServerId) {\n\t\t\tconst filter = this.generateTopLevelEntityFilter(\n\t\t\t\tpersistedData.value,\n\t\t\t\tsubTree.parameters.entityName,\n\t\t\t\tsubTree.fields,\n\t\t\t)\n\t\t\tfilter && filters.push(filter)\n\t\t} else {\n\t\t\tfor (const id of persistedData) {\n\t\t\t\tconst filter = this.generateTopLevelEntityFilter(id, subTree.parameters.entityName, subTree.fields)\n\t\t\t\tfilter && filters.push(filter)\n\t\t\t}\n\t\t}\n\n\t\treturn filters\n\t}\n\n\tprivate generateTopLevelEntityFilter(\n\t\tid: EntityId,\n\t\tentityName: EntityName,\n\t\tfields: EntityFieldMarkersContainer,\n\t): TreeFilter | undefined {\n\t\treturn {\n\t\t\tentity: entityName,\n\t\t\tid: id,\n\t\t\trelations: this.generateEntityRelations(fields),\n\t\t}\n\t}\n\n\tprivate generateEntityRelations(markers: EntityFieldMarkersContainer): RelationFilter[] {\n\t\tconst rawFilter = this.populateRawRelationFilters(markers)\n\t\treturn this.normalizeRawRelationFilters(rawFilter)\n\t}\n\n\tprivate normalizeRawRelationFilters(raw: RawRelationFilters): RelationFilter[] {\n\t\treturn Array.from(raw, ([fieldName, relations]) => ({\n\t\t\tname: fieldName,\n\t\t\trelations: this.normalizeRawRelationFilters(relations),\n\t\t}))\n\t}\n\n\tprivate populateRawRelationFilters(\n\t\tmarkers: EntityFieldMarkersContainer,\n\t\trelations: RawRelationFilters = new Map(),\n\t): RawRelationFilters {\n\t\tfor (const [, marker] of markers.markers) {\n\t\t\tif (!(marker instanceof HasOneRelationMarker) && !(marker instanceof HasManyRelationMarker)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (\n\t\t\t\tmarker.parameters.expectedMutation === 'none' ||\n\t\t\t\tmarker.parameters.expectedMutation === 'connectOrDisconnect'\n\t\t\t) {\n\t\t\t\tcontinue\n\t\t\t} else if (\n\t\t\t\tmarker.parameters.expectedMutation === 'anyMutation' ||\n\t\t\t\tmarker.parameters.expectedMutation === 'createOrDelete'\n\t\t\t) {\n\t\t\t} else {\n\t\t\t\treturn assertNever(marker.parameters.expectedMutation)\n\t\t\t}\n\t\t\tlet existingRelation = relations.get(marker.parameters.field)\n\n\t\t\tif (existingRelation === undefined) {\n\t\t\t\trelations.set(marker.parameters.field, (existingRelation = new Map()))\n\t\t\t}\n\t\t\tthis.populateRawRelationFilters(marker.fields, existingRelation)\n\t\t}\n\n\t\treturn relations\n\t}\n}\n"],"names":[],"mappings":";;;;;AAgBO,MAAM,oBAAoB;AAAA,EACzB,YAA6B,WAAsB;AAAtB,SAAA,YAAA;AAAA,EAAuB;AAAA,EAEpD,qBAAmC;AACzC,UAAM,UAA0B,CAAA;AAEhC,eAAW,CAAC,iBAAiB,UAAU,cAAc,cAAc,KAAK,SAAS,GAAG;AACnF,YAAM,YAAY,MAAM;AAExB,UAAI,UAAU,UAAU,UAAU,OAAO,WAAW,qBAAqB,QAAQ;AAChF;AAAA,MACD;AACA,YAAM,SAAS,UAAU;AACjB,cAAA,KAAK,KAAK,sBAAsB,QAAQ,KAAK,UAAU,qBAAqB,IAAI,eAAe,CAAC,CAAC;AAAA,IAC1G;AACA,WAAO,QAAQ;EAChB;AAAA,EAEQ,sBACP,SACA,eACe;AACf,UAAM,UAAwB,CAAA;AAE9B,QAAI,kBAAkB,QAAW;AACzB,aAAA;AAAA,IACR;AAEA,QAAI,yBAAyB,UAAU;AAChC,YAAA,SAAS,KAAK,6BACnB,cAAc,OACd,QAAQ,WAAW,YACnB,QAAQ,MACT;AACU,gBAAA,QAAQ,KAAK,MAAM;AAAA,IAAA,OACvB;AACN,iBAAW,MAAM,eAAe;AACzB,cAAA,SAAS,KAAK,6BAA6B,IAAI,QAAQ,WAAW,YAAY,QAAQ,MAAM;AACxF,kBAAA,QAAQ,KAAK,MAAM;AAAA,MAC9B;AAAA,IACD;AAEO,WAAA;AAAA,EACR;AAAA,EAEQ,6BACP,IACA,YACA,QACyB;AAClB,WAAA;AAAA,MACN,QAAQ;AAAA,MACR;AAAA,MACA,WAAW,KAAK,wBAAwB,MAAM;AAAA,IAAA;AAAA,EAEhD;AAAA,EAEQ,wBAAwB,SAAwD;AACjF,UAAA,YAAY,KAAK,2BAA2B,OAAO;AAClD,WAAA,KAAK,4BAA4B,SAAS;AAAA,EAClD;AAAA,EAEQ,4BAA4B,KAA2C;AAC9E,WAAO,MAAM,KAAK,KAAK,CAAC,CAAC,WAAW,eAAgB;AAAA,MACnD,MAAM;AAAA,MACN,WAAW,KAAK,4BAA4B,SAAS;AAAA,IACpD,EAAA;AAAA,EACH;AAAA,EAEQ,2BACP,SACA,YAAgC,oBAAI,OACf;AACrB,eAAW,CAAG,EAAA,WAAW,QAAQ,SAAS;AACzC,UAAI,CAAE,mBAAkB,yBAAyB,oBAAoB,wBAAwB;AAC5F;AAAA,MACD;AACA,UACC,OAAO,WAAW,qBAAqB,UACvC,OAAO,WAAW,qBAAqB,uBACtC;AACD;AAAA,MAAA,WAEA,OAAO,WAAW,qBAAqB,iBACvC,OAAO,WAAW,qBAAqB;AACtC;AAAA,WACK;AACC,eAAA,YAAY,OAAO,WAAW,gBAAgB;AAAA,MACtD;AACA,UAAI,mBAAmB,UAAU,IAAI,OAAO,WAAW,KAAK;AAE5D,UAAI,qBAAqB,QAAW;AACnC,kBAAU,IAAI,OAAO,WAAW,OAAQ,mBAAmB,oBAAI,KAAM;AAAA,MACtE;AACK,WAAA,2BAA2B,OAAO,QAAQ,gBAAgB;AAAA,IAChE;AAEO,WAAA;AAAA,EACR;AACD;;"}
1
+ {"version":3,"file":"TreeFilterGenerator.js","sources":["../../../src/core/TreeFilterGenerator.ts"],"sourcesContent":["import type { RelationFilter, TreeFilter } from '@contember/client'\nimport { EntityListPersistedData, ServerId } from '../accessorTree'\nimport {\n\tEntityFieldMarkersContainer,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n} from '../markers'\nimport type { EntityId, EntityName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport { StateIterator } from './state'\nimport type { TreeStore } from './TreeStore'\n\ntype RawRelationFilters = Map<string, RawRelationFilters>\n\nexport class TreeFilterGenerator {\n\tpublic constructor(private readonly treeStore: TreeStore) {}\n\n\tpublic generateTreeFilter(): TreeFilter[] {\n\t\tconst filters: TreeFilter[][] = []\n\n\t\tfor (const [placeholderName, state] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\tconst blueprint = state.blueprint\n\n\t\t\tif (blueprint.parent || blueprint.marker.parameters.expectedMutation === 'none') {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst marker = blueprint.marker\n\t\t\tfilters.push(this.generateSubTreeFilter(marker, this.treeStore.subTreePersistedData.get(placeholderName)))\n\t\t}\n\t\treturn filters.flat()\n\t}\n\n\tprivate generateSubTreeFilter(\n\t\tsubTree: EntitySubTreeMarker | EntityListSubTreeMarker,\n\t\tpersistedData: ServerId | EntityListPersistedData | undefined,\n\t): TreeFilter[] {\n\t\tconst filters: TreeFilter[] = []\n\n\t\tif (persistedData === undefined) {\n\t\t\treturn filters // Do nothing\n\t\t}\n\n\t\tif (persistedData instanceof ServerId) {\n\t\t\tconst filter = this.generateTopLevelEntityFilter(\n\t\t\t\tpersistedData.value,\n\t\t\t\tsubTree.parameters.entityName,\n\t\t\t\tsubTree.fields,\n\t\t\t)\n\t\t\tfilter && filters.push(filter)\n\t\t} else {\n\t\t\tfor (const id of persistedData) {\n\t\t\t\tconst filter = this.generateTopLevelEntityFilter(id, subTree.parameters.entityName, subTree.fields)\n\t\t\t\tfilter && filters.push(filter)\n\t\t\t}\n\t\t}\n\n\t\treturn filters\n\t}\n\n\tprivate generateTopLevelEntityFilter(\n\t\tid: EntityId,\n\t\tentityName: EntityName,\n\t\tfields: EntityFieldMarkersContainer,\n\t): TreeFilter | undefined {\n\t\treturn {\n\t\t\tentity: entityName,\n\t\t\tid: id,\n\t\t\trelations: this.generateEntityRelations(fields),\n\t\t}\n\t}\n\n\tprivate generateEntityRelations(markers: EntityFieldMarkersContainer): RelationFilter[] {\n\t\tconst rawFilter = this.populateRawRelationFilters(markers)\n\t\treturn this.normalizeRawRelationFilters(rawFilter)\n\t}\n\n\tprivate normalizeRawRelationFilters(raw: RawRelationFilters): RelationFilter[] {\n\t\treturn Array.from(raw, ([fieldName, relations]) => ({\n\t\t\tname: fieldName,\n\t\t\trelations: this.normalizeRawRelationFilters(relations),\n\t\t}))\n\t}\n\n\tprivate populateRawRelationFilters(\n\t\tmarkers: EntityFieldMarkersContainer,\n\t\trelations: RawRelationFilters = new Map(),\n\t): RawRelationFilters {\n\t\tfor (const [, marker] of markers.markers) {\n\t\t\tif (!(marker instanceof HasOneRelationMarker) && !(marker instanceof HasManyRelationMarker)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (\n\t\t\t\tmarker.parameters.expectedMutation === 'none' ||\n\t\t\t\tmarker.parameters.expectedMutation === 'connectOrDisconnect'\n\t\t\t) {\n\t\t\t\tcontinue\n\t\t\t} else if (\n\t\t\t\tmarker.parameters.expectedMutation === 'anyMutation' ||\n\t\t\t\tmarker.parameters.expectedMutation === 'createOrDelete'\n\t\t\t) {\n\t\t\t} else {\n\t\t\t\treturn assertNever(marker.parameters.expectedMutation)\n\t\t\t}\n\t\t\tlet existingRelation = relations.get(marker.parameters.field)\n\n\t\t\tif (existingRelation === undefined) {\n\t\t\t\trelations.set(marker.parameters.field, (existingRelation = new Map()))\n\t\t\t}\n\t\t\tthis.populateRawRelationFilters(marker.fields, existingRelation)\n\t\t}\n\n\t\treturn relations\n\t}\n}\n"],"names":[],"mappings":";;;;;AAgBO,MAAM,oBAAoB;AAAA,EACzB,YAA6B,WAAs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4B,SAAS;AAAA,IACpD,EAAA;AAAA,EACH;AAAA,EAEQ,2BACP,SACA,YAAgC,oBAAI,OACf;AACrB,eAAW,CAAG,EAAA,MAAM,KAAK,QAAQ,SAAS;AACzC,UAAI,EAAE,kBAAkB,yBAAyB,EAAE,kBAAkB,wBAAwB;AAC5F;AAAA,MACD;AACA,UACC,OAAO,WAAW,qBAAqB,UACvC,OAAO,WAAW,qBAAqB,uBACtC;AACD;AAAA,MAAA,WAEA,OAAO,WAAW,qBAAqB,iBACvC,OAAO,WAAW,qBAAqB;AACtC;AAAA,WACK;AACC,eAAA,YAAY,OAAO,WAAW,gBAAgB;AAAA,MACtD;AACA,UAAI,mBAAmB,UAAU,IAAI,OAAO,WAAW,KAAK;AAE5D,UAAI,qBAAqB,QAAW;AACnC,kBAAU,IAAI,OAAO,WAAW,OAAQ,mBAAmB,oBAAI,KAAM;AAAA,MACtE;AACK,WAAA,2BAA2B,OAAO,QAAQ,gBAAgB;AAAA,IAChE;AAEO,WAAA;AAAA,EACR;AACD;"}
@@ -14,7 +14,9 @@ class TreeParameterMerger {
14
14
  }
15
15
  static mergeHasManyRelationsWithSamePlaceholders(original, fresh) {
16
16
  if (original.initialEntityCount !== fresh.initialEntityCount) {
17
- throw new BindingError(`Detected hasMany relations on the same field '${original.field}' with different preferred initial entity counts: '${original.initialEntityCount}' and '${fresh.initialEntityCount}' respectively.`);
17
+ throw new BindingError(
18
+ `Detected hasMany relations on the same field '${original.field}' with different preferred initial entity counts: '${original.initialEntityCount}' and '${fresh.initialEntityCount}' respectively.`
19
+ );
18
20
  }
19
21
  return {
20
22
  field: original.field,
@@ -26,7 +28,10 @@ class TreeParameterMerger {
26
28
  setOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),
27
29
  isNonbearing: original.isNonbearing && fresh.isNonbearing,
28
30
  initialEntityCount: original.initialEntityCount,
29
- childEventListeners: this.mergeSingleEntityEventListeners(original.childEventListeners, fresh.childEventListeners),
31
+ childEventListeners: this.mergeSingleEntityEventListeners(
32
+ original.childEventListeners,
33
+ fresh.childEventListeners
34
+ ),
30
35
  eventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners)
31
36
  };
32
37
  }
@@ -58,7 +63,9 @@ class TreeParameterMerger {
58
63
  }
59
64
  static mergeEntityListSubTreeParametersWithSamePlaceholders(original, fresh) {
60
65
  if (original.initialEntityCount !== fresh.initialEntityCount) {
61
- throw new BindingError(`Detected sub trees of the same entity '${original.entityName}' with different preferred initial entity counts: '${original.initialEntityCount}' and '${fresh.initialEntityCount}' respectively.`);
66
+ throw new BindingError(
67
+ `Detected sub trees of the same entity '${original.entityName}' with different preferred initial entity counts: '${original.initialEntityCount}' and '${fresh.initialEntityCount}' respectively.`
68
+ );
62
69
  }
63
70
  if (original.isCreating) {
64
71
  return {
@@ -69,7 +76,10 @@ class TreeParameterMerger {
69
76
  expectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),
70
77
  isNonbearing: original.isNonbearing && fresh.isNonbearing,
71
78
  hasOneRelationPath: original.hasOneRelationPath,
72
- childEventListeners: this.mergeSingleEntityEventListeners(original.childEventListeners, fresh.childEventListeners),
79
+ childEventListeners: this.mergeSingleEntityEventListeners(
80
+ original.childEventListeners,
81
+ fresh.childEventListeners
82
+ ),
73
83
  eventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),
74
84
  initialEntityCount: original.initialEntityCount
75
85
  };
@@ -86,7 +96,10 @@ class TreeParameterMerger {
86
96
  expectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),
87
97
  isNonbearing: original.isNonbearing && fresh.isNonbearing,
88
98
  hasOneRelationPath: original.hasOneRelationPath,
89
- childEventListeners: this.mergeSingleEntityEventListeners(original.childEventListeners, fresh.childEventListeners),
99
+ childEventListeners: this.mergeSingleEntityEventListeners(
100
+ original.childEventListeners,
101
+ fresh.childEventListeners
102
+ ),
90
103
  eventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),
91
104
  initialEntityCount: original.initialEntityCount
92
105
  };
@@ -168,7 +181,10 @@ class TreeParameterMerger {
168
181
  return original;
169
182
  }
170
183
  return {
171
- eventListeners: TreeParameterMerger.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners)
184
+ eventListeners: TreeParameterMerger.mergeSingleEntityEventListeners(
185
+ original.eventListeners,
186
+ fresh.eventListeners
187
+ )
172
188
  };
173
189
  }
174
190
  static mergeInParentEntity(original, key, parentEntity) {
@@ -248,5 +264,7 @@ class TreeParameterMerger {
248
264
  return this.mergeSets(original, fresh);
249
265
  }
250
266
  }
251
- export { TreeParameterMerger };
267
+ export {
268
+ TreeParameterMerger
269
+ };
252
270
  //# sourceMappingURL=TreeParameterMerger.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TreeParameterMerger.js","sources":["../../../src/core/TreeParameterMerger.ts"],"sourcesContent":["import { GraphQlBuilder } from '@contember/client'\nimport { BindingError } from '../BindingError'\nimport type {\n\tAlias,\n\tEntityCreationParameters,\n\tEntityEventListenerStore,\n\tEntityListEventListenerStore,\n\tExpectedQualifiedEntityMutation,\n\tExpectedRelationMutation,\n\tHasManyRelation,\n\tHasOneRelation,\n\tParentEntityParameters,\n\tQualifiedEntityList,\n\tQualifiedSingleEntity,\n\tSetOnCreate,\n\tUnconstrainedQualifiedEntityList,\n\tUnconstrainedQualifiedSingleEntity,\n\tUniqueWhere,\n} from '../treeParameters'\n\nexport class TreeParameterMerger {\n\tpublic static mergeHasOneRelationsWithSamePlaceholders(\n\t\toriginal: HasOneRelation,\n\t\tfresh: HasOneRelation,\n\t): HasOneRelation {\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tfield: original.field,\n\t\t\tfilter: original.filter,\n\t\t\treducedBy: original.reducedBy,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\texpectedMutation: this.mergeExpectedRelationMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\t// forceCreation: original.forceCreation || fresh.forceCreation,\n\t\t\teventListeners: this.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeHasManyRelationsWithSamePlaceholders(\n\t\toriginal: HasManyRelation,\n\t\tfresh: HasManyRelation,\n\t): HasManyRelation {\n\t\tif (original.initialEntityCount !== fresh.initialEntityCount) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Detected hasMany relations on the same field '${original.field}' with different preferred initial ` +\n\t\t\t\t\t`entity counts: '${original.initialEntityCount}' and '${fresh.initialEntityCount}' respectively.`,\n\t\t\t)\n\t\t}\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tfield: original.field,\n\t\t\tfilter: original.filter,\n\t\t\torderBy: original.orderBy,\n\t\t\toffset: original.offset,\n\t\t\tlimit: original.limit,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\texpectedMutation: this.mergeExpectedRelationMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t// forceCreation: original.forceCreation || fresh.forceCreation,\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\tinitialEntityCount: original.initialEntityCount, // Handled above\n\t\t\tchildEventListeners: this.mergeSingleEntityEventListeners(\n\t\t\t\toriginal.childEventListeners,\n\t\t\t\tfresh.childEventListeners,\n\t\t\t),\n\t\t\teventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeEntitySubTreeParametersWithSamePlaceholders(\n\t\toriginal: QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity,\n\t\tfresh: QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity,\n\t): QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity {\n\t\tif (original.isCreating) {\n\t\t\treturn {\n\t\t\t\t// Encoded within the placeholder\n\t\t\t\tisCreating: original.isCreating,\n\t\t\t\tentityName: original.entityName,\n\n\t\t\t\t// Not encoded within the placeholder\n\t\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\t\teventListeners: this.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tisCreating: original.isCreating,\n\t\t\twhere: original.where,\n\t\t\tentityName: original.entityName,\n\t\t\tfilter: original.filter,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\teventListeners: this.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeEntityListSubTreeParametersWithSamePlaceholders(\n\t\toriginal: QualifiedEntityList | UnconstrainedQualifiedEntityList,\n\t\tfresh: QualifiedEntityList | UnconstrainedQualifiedEntityList,\n\t): QualifiedEntityList | UnconstrainedQualifiedEntityList {\n\t\tif (original.initialEntityCount !== fresh.initialEntityCount) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Detected sub trees of the same entity '${original.entityName}' with different preferred initial ` +\n\t\t\t\t\t`entity counts: '${original.initialEntityCount}' and '${fresh.initialEntityCount}' respectively.`,\n\t\t\t)\n\t\t}\n\n\t\tif (original.isCreating) {\n\t\t\treturn {\n\t\t\t\t// Encoded within the placeholder\n\t\t\t\tisCreating: original.isCreating,\n\t\t\t\tentityName: original.entityName,\n\n\t\t\t\t// Not encoded within the placeholder\n\t\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\t\tchildEventListeners: this.mergeSingleEntityEventListeners(\n\t\t\t\t\toriginal.childEventListeners,\n\t\t\t\t\tfresh.childEventListeners,\n\t\t\t\t),\n\t\t\t\teventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t\t\tinitialEntityCount: original.initialEntityCount, // Handled above\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tisCreating: original.isCreating,\n\t\t\tentityName: original.entityName,\n\t\t\tfilter: original.filter,\n\t\t\torderBy: original.orderBy,\n\t\t\toffset: original.offset,\n\t\t\tlimit: original.limit,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\tchildEventListeners: this.mergeSingleEntityEventListeners(\n\t\t\t\toriginal.childEventListeners,\n\t\t\t\tfresh.childEventListeners,\n\t\t\t),\n\t\t\teventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t\tinitialEntityCount: original.initialEntityCount, // Handled above\n\t\t}\n\t}\n\n\tpublic static mergeEntityCreationParameters(\n\t\toriginal: EntityCreationParameters,\n\t\tfresh: EntityCreationParameters,\n\t): EntityCreationParameters {\n\t\treturn {\n\t\t\t// forceCreation: original.forceCreation || fresh.forceCreation,\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t}\n\t}\n\n\tpublic static mergeSetOnCreate(original: SetOnCreate, fresh: SetOnCreate): SetOnCreate {\n\t\tif (original === undefined && fresh === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\tconst originalCopy: UniqueWhere = { ...original }\n\n\t\tfor (const field in fresh) {\n\t\t\tif (field in originalCopy) {\n\t\t\t\tconst fromOriginal = originalCopy[field]\n\t\t\t\tconst fromFresh = fresh[field]\n\n\t\t\t\tif (fromOriginal instanceof GraphQlBuilder.GraphQlLiteral) {\n\t\t\t\t\tif (fromFresh instanceof GraphQlBuilder.GraphQlLiteral) {\n\t\t\t\t\t\tif (fromOriginal.value === fromFresh.value) {\n\t\t\t\t\t\t\t// Good, do nothing.\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (typeof fromOriginal === 'object') {\n\t\t\t\t\tif (fromFresh instanceof GraphQlBuilder.GraphQlLiteral) {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t} else if (typeof fromFresh === 'object') {\n\t\t\t\t\t\tconst merged = this.mergeSetOnCreate(fromOriginal, fromFresh)\n\t\t\t\t\t\tif (merged !== undefined) {\n\t\t\t\t\t\t\toriginalCopy[field] = merged\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (typeof fromFresh === 'string' || typeof fromFresh === 'number') {\n\t\t\t\t\tif (fromOriginal === fromFresh) {\n\t\t\t\t\t\t// Good, do nothing.\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t} else {\n\t\t\t\toriginalCopy[field] = fresh[field]\n\t\t\t}\n\t\t}\n\n\t\treturn originalCopy\n\t}\n\n\tprivate static mergeSets<T>(original: Set<T>, fresh: Set<T>): Set<T> {\n\t\tconst combinedSet = new Set(original)\n\t\tfor (const item of fresh) {\n\t\t\tcombinedSet.add(item)\n\t\t}\n\t\treturn combinedSet\n\t}\n\n\tpublic static mergeParentEntityParameters(\n\t\toriginal: ParentEntityParameters | undefined,\n\t\tfresh: ParentEntityParameters | undefined,\n\t): ParentEntityParameters | undefined {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\treturn {\n\t\t\teventListeners: TreeParameterMerger.mergeSingleEntityEventListeners(\n\t\t\t\toriginal.eventListeners,\n\t\t\t\tfresh.eventListeners,\n\t\t\t),\n\t\t}\n\t}\n\n\tpublic static mergeInParentEntity<\n\t\tOriginal extends Record<Key, EntityEventListenerStore | undefined>,\n\t\tKey extends keyof Original,\n\t>(original: Original, key: Key, parentEntity: ParentEntityParameters | undefined): Original {\n\t\tif (!parentEntity) {\n\t\t\treturn original\n\t\t}\n\n\t\treturn {\n\t\t\t...original,\n\t\t\t[key]: TreeParameterMerger.mergeSingleEntityEventListeners(original[key], parentEntity.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeSingleEntityEventListeners(\n\t\toriginal: EntityEventListenerStore | undefined,\n\t\tfresh: EntityEventListenerStore | undefined,\n\t): EntityEventListenerStore | undefined {\n\t\tif (original === undefined) {\n\t\t\tif (fresh === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn this.cloneSingleEntityEventListeners(fresh)\n\t\t}\n\n\t\tif (fresh === undefined) {\n\t\t\treturn this.cloneSingleEntityEventListeners(original)\n\t\t}\n\n\t\tconst store = this.cloneSingleEntityEventListeners(original)\n\t\tstore.append(fresh)\n\t\treturn store\n\t}\n\n\tpublic static mergeEntityListEventListeners(\n\t\toriginal: EntityListEventListenerStore | undefined,\n\t\tfresh: EntityListEventListenerStore | undefined,\n\t): EntityListEventListenerStore | undefined {\n\t\tif (original === undefined) {\n\t\t\tif (fresh === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn this.cloneEntityListEventListeners(fresh)\n\t\t}\n\n\t\tif (fresh === undefined) {\n\t\t\treturn this.cloneEntityListEventListeners(original)\n\t\t}\n\n\t\tconst store = this.cloneEntityListEventListeners(original)\n\t\tstore.append(fresh)\n\t\treturn store\n\t}\n\n\tpublic static cloneSingleEntityEventListeners(store: EntityEventListenerStore): EntityEventListenerStore {\n\t\t// TODO is intentional, that second clone is deep?\n\t\treturn store.clone()\n\t}\n\n\tpublic static cloneEntityListEventListeners(store: EntityListEventListenerStore): EntityListEventListenerStore {\n\t\treturn store.cloneDeep()\n\t}\n\n\tprivate static mergeExpectedRelationMutation(\n\t\toriginal: ExpectedRelationMutation,\n\t\tfresh: ExpectedRelationMutation,\n\t): ExpectedRelationMutation {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === 'none') {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === 'none') {\n\t\t\treturn original\n\t\t}\n\t\treturn 'anyMutation'\n\t}\n\n\tprivate static mergeExpectedQualifiedEntityMutation(\n\t\toriginal: ExpectedQualifiedEntityMutation,\n\t\tfresh: ExpectedQualifiedEntityMutation,\n\t): ExpectedQualifiedEntityMutation {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === 'none') {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === 'none') {\n\t\t\treturn original\n\t\t}\n\t\treturn 'anyMutation'\n\t}\n\n\tprivate static mergeSubTreeAliases(\n\t\toriginal: Set<Alias> | undefined,\n\t\tfresh: Set<Alias> | undefined,\n\t): Set<Alias> | undefined {\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\treturn this.mergeSets(original, fresh)\n\t}\n}\n"],"names":[],"mappings":";;AAoBO,MAAM,oBAAoB;AAAA,SAClB,yCACb,UACA,OACiB;AACV,WAAA;AAAA,MAEN,OAAO,SAAS;AAAA,MAChB,QAAQ,SAAS;AAAA,MACjB,WAAW,SAAS;AAAA,MAGpB,kBAAkB,KAAK,8BAA8B,SAAS,kBAAkB,MAAM,gBAAgB;AAAA,MACtG,aAAa,KAAK,iBAAiB,SAAS,aAAa,MAAM,WAAW;AAAA,MAC1E,cAAc,SAAS,gBAAgB,MAAM;AAAA,MAE7C,gBAAgB,KAAK,gCAAgC,SAAS,gBAAgB,MAAM,cAAc;AAAA,IAAA;AAAA,EAEpG;AAAA,SAEc,0CACb,U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AAC3C,QAAI,aAAa,QAAW;AAC3B,UAAI,UAAU,QAAW;AACjB,eAAA;AAAA,MACR;AACO,aAAA,KAAK,8BAA8B,KAAK;AAAA,IAChD;AAEA,QAAI,UAAU,QAAW;AACjB,aAAA,KAAK,8BAA8B,QAAQ;AAAA,IACnD;AAEM,UAAA,QAAQ,KAAK,8BAA8B,QAAQ;AACzD,UAAM,OAAO,KAAK;AACX,WAAA;AAAA,EACR;AAAA,SAEc,gCAAgC,OAA2D;AAExG,WAAO,MAAM;EACd;AAAA,SAEc,8BAA8B,OAAmE;AAC9G,WAAO,MAAM;EACd;AAAA,SAEe,8BACd,UACA,OAC2B;AAC3B,QAAI,aAAa,OAAO;AAChB,aAAA;AAAA,IACR;AACA,QAAI,aAAa,QAAQ;AACjB,aAAA;AAAA,IACR;AACA,QAAI,UAAU,QAAQ;AACd,aAAA;AAAA,IACR;AACO,WAAA;AAAA,EACR;AAAA,SAEe,qCACd,UACA,OACkC;AAClC,QAAI,aAAa,OAAO;AAChB,aAAA;AAAA,IACR;AACA,QAAI,aAAa,QAAQ;AACjB,aAAA;AAAA,IACR;AACA,QAAI,UAAU,QAAQ;AACd,aAAA;AAAA,IACR;AACO,WAAA;AAAA,EACR;AAAA,SAEe,oBACd,UACA,OACyB;AACzB,QAAI,aAAa,QAAW;AACpB,aAAA;AAAA,IACR;AACA,QAAI,UAAU,QAAW;AACjB,aAAA;AAAA,IACR;AACO,WAAA,KAAK,UAAU,UAAU,KAAK;AAAA,EACtC;AACD;;"}
1
+ {"version":3,"file":"TreeParameterMerger.js","sources":["../../../src/core/TreeParameterMerger.ts"],"sourcesContent":["import { GraphQlBuilder } from '@contember/client'\nimport { BindingError } from '../BindingError'\nimport type {\n\tAlias,\n\tEntityCreationParameters,\n\tEntityEventListenerStore,\n\tEntityListEventListenerStore,\n\tExpectedQualifiedEntityMutation,\n\tExpectedRelationMutation,\n\tHasManyRelation,\n\tHasOneRelation,\n\tParentEntityParameters,\n\tQualifiedEntityList,\n\tQualifiedSingleEntity,\n\tSetOnCreate,\n\tUnconstrainedQualifiedEntityList,\n\tUnconstrainedQualifiedSingleEntity,\n\tUniqueWhere,\n} from '../treeParameters'\n\nexport class TreeParameterMerger {\n\tpublic static mergeHasOneRelationsWithSamePlaceholders(\n\t\toriginal: HasOneRelation,\n\t\tfresh: HasOneRelation,\n\t): HasOneRelation {\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tfield: original.field,\n\t\t\tfilter: original.filter,\n\t\t\treducedBy: original.reducedBy,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\texpectedMutation: this.mergeExpectedRelationMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\t// forceCreation: original.forceCreation || fresh.forceCreation,\n\t\t\teventListeners: this.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeHasManyRelationsWithSamePlaceholders(\n\t\toriginal: HasManyRelation,\n\t\tfresh: HasManyRelation,\n\t): HasManyRelation {\n\t\tif (original.initialEntityCount !== fresh.initialEntityCount) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Detected hasMany relations on the same field '${original.field}' with different preferred initial ` +\n\t\t\t\t\t`entity counts: '${original.initialEntityCount}' and '${fresh.initialEntityCount}' respectively.`,\n\t\t\t)\n\t\t}\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tfield: original.field,\n\t\t\tfilter: original.filter,\n\t\t\torderBy: original.orderBy,\n\t\t\toffset: original.offset,\n\t\t\tlimit: original.limit,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\texpectedMutation: this.mergeExpectedRelationMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t// forceCreation: original.forceCreation || fresh.forceCreation,\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\tinitialEntityCount: original.initialEntityCount, // Handled above\n\t\t\tchildEventListeners: this.mergeSingleEntityEventListeners(\n\t\t\t\toriginal.childEventListeners,\n\t\t\t\tfresh.childEventListeners,\n\t\t\t),\n\t\t\teventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeEntitySubTreeParametersWithSamePlaceholders(\n\t\toriginal: QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity,\n\t\tfresh: QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity,\n\t): QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity {\n\t\tif (original.isCreating) {\n\t\t\treturn {\n\t\t\t\t// Encoded within the placeholder\n\t\t\t\tisCreating: original.isCreating,\n\t\t\t\tentityName: original.entityName,\n\n\t\t\t\t// Not encoded within the placeholder\n\t\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\t\teventListeners: this.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tisCreating: original.isCreating,\n\t\t\twhere: original.where,\n\t\t\tentityName: original.entityName,\n\t\t\tfilter: original.filter,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\teventListeners: this.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeEntityListSubTreeParametersWithSamePlaceholders(\n\t\toriginal: QualifiedEntityList | UnconstrainedQualifiedEntityList,\n\t\tfresh: QualifiedEntityList | UnconstrainedQualifiedEntityList,\n\t): QualifiedEntityList | UnconstrainedQualifiedEntityList {\n\t\tif (original.initialEntityCount !== fresh.initialEntityCount) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Detected sub trees of the same entity '${original.entityName}' with different preferred initial ` +\n\t\t\t\t\t`entity counts: '${original.initialEntityCount}' and '${fresh.initialEntityCount}' respectively.`,\n\t\t\t)\n\t\t}\n\n\t\tif (original.isCreating) {\n\t\t\treturn {\n\t\t\t\t// Encoded within the placeholder\n\t\t\t\tisCreating: original.isCreating,\n\t\t\t\tentityName: original.entityName,\n\n\t\t\t\t// Not encoded within the placeholder\n\t\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\t\tchildEventListeners: this.mergeSingleEntityEventListeners(\n\t\t\t\t\toriginal.childEventListeners,\n\t\t\t\t\tfresh.childEventListeners,\n\t\t\t\t),\n\t\t\t\teventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t\t\tinitialEntityCount: original.initialEntityCount, // Handled above\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tisCreating: original.isCreating,\n\t\t\tentityName: original.entityName,\n\t\t\tfilter: original.filter,\n\t\t\torderBy: original.orderBy,\n\t\t\toffset: original.offset,\n\t\t\tlimit: original.limit,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\tchildEventListeners: this.mergeSingleEntityEventListeners(\n\t\t\t\toriginal.childEventListeners,\n\t\t\t\tfresh.childEventListeners,\n\t\t\t),\n\t\t\teventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t\tinitialEntityCount: original.initialEntityCount, // Handled above\n\t\t}\n\t}\n\n\tpublic static mergeEntityCreationParameters(\n\t\toriginal: EntityCreationParameters,\n\t\tfresh: EntityCreationParameters,\n\t): EntityCreationParameters {\n\t\treturn {\n\t\t\t// forceCreation: original.forceCreation || fresh.forceCreation,\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t}\n\t}\n\n\tpublic static mergeSetOnCreate(original: SetOnCreate, fresh: SetOnCreate): SetOnCreate {\n\t\tif (original === undefined && fresh === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\tconst originalCopy: UniqueWhere = { ...original }\n\n\t\tfor (const field in fresh) {\n\t\t\tif (field in originalCopy) {\n\t\t\t\tconst fromOriginal = originalCopy[field]\n\t\t\t\tconst fromFresh = fresh[field]\n\n\t\t\t\tif (fromOriginal instanceof GraphQlBuilder.GraphQlLiteral) {\n\t\t\t\t\tif (fromFresh instanceof GraphQlBuilder.GraphQlLiteral) {\n\t\t\t\t\t\tif (fromOriginal.value === fromFresh.value) {\n\t\t\t\t\t\t\t// Good, do nothing.\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (typeof fromOriginal === 'object') {\n\t\t\t\t\tif (fromFresh instanceof GraphQlBuilder.GraphQlLiteral) {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t} else if (typeof fromFresh === 'object') {\n\t\t\t\t\t\tconst merged = this.mergeSetOnCreate(fromOriginal, fromFresh)\n\t\t\t\t\t\tif (merged !== undefined) {\n\t\t\t\t\t\t\toriginalCopy[field] = merged\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (typeof fromFresh === 'string' || typeof fromFresh === 'number') {\n\t\t\t\t\tif (fromOriginal === fromFresh) {\n\t\t\t\t\t\t// Good, do nothing.\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t} else {\n\t\t\t\toriginalCopy[field] = fresh[field]\n\t\t\t}\n\t\t}\n\n\t\treturn originalCopy\n\t}\n\n\tprivate static mergeSets<T>(original: Set<T>, fresh: Set<T>): Set<T> {\n\t\tconst combinedSet = new Set(original)\n\t\tfor (const item of fresh) {\n\t\t\tcombinedSet.add(item)\n\t\t}\n\t\treturn combinedSet\n\t}\n\n\tpublic static mergeParentEntityParameters(\n\t\toriginal: ParentEntityParameters | undefined,\n\t\tfresh: ParentEntityParameters | undefined,\n\t): ParentEntityParameters | undefined {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\treturn {\n\t\t\teventListeners: TreeParameterMerger.mergeSingleEntityEventListeners(\n\t\t\t\toriginal.eventListeners,\n\t\t\t\tfresh.eventListeners,\n\t\t\t),\n\t\t}\n\t}\n\n\tpublic static mergeInParentEntity<\n\t\tOriginal extends Record<Key, EntityEventListenerStore | undefined>,\n\t\tKey extends keyof Original,\n\t>(original: Original, key: Key, parentEntity: ParentEntityParameters | undefined): Original {\n\t\tif (!parentEntity) {\n\t\t\treturn original\n\t\t}\n\n\t\treturn {\n\t\t\t...original,\n\t\t\t[key]: TreeParameterMerger.mergeSingleEntityEventListeners(original[key], parentEntity.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeSingleEntityEventListeners(\n\t\toriginal: EntityEventListenerStore | undefined,\n\t\tfresh: EntityEventListenerStore | undefined,\n\t): EntityEventListenerStore | undefined {\n\t\tif (original === undefined) {\n\t\t\tif (fresh === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn this.cloneSingleEntityEventListeners(fresh)\n\t\t}\n\n\t\tif (fresh === undefined) {\n\t\t\treturn this.cloneSingleEntityEventListeners(original)\n\t\t}\n\n\t\tconst store = this.cloneSingleEntityEventListeners(original)\n\t\tstore.append(fresh)\n\t\treturn store\n\t}\n\n\tpublic static mergeEntityListEventListeners(\n\t\toriginal: EntityListEventListenerStore | undefined,\n\t\tfresh: EntityListEventListenerStore | undefined,\n\t): EntityListEventListenerStore | undefined {\n\t\tif (original === undefined) {\n\t\t\tif (fresh === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn this.cloneEntityListEventListeners(fresh)\n\t\t}\n\n\t\tif (fresh === undefined) {\n\t\t\treturn this.cloneEntityListEventListeners(original)\n\t\t}\n\n\t\tconst store = this.cloneEntityListEventListeners(original)\n\t\tstore.append(fresh)\n\t\treturn store\n\t}\n\n\tpublic static cloneSingleEntityEventListeners(store: EntityEventListenerStore): EntityEventListenerStore {\n\t\t// TODO is intentional, that second clone is deep?\n\t\treturn store.clone()\n\t}\n\n\tpublic static cloneEntityListEventListeners(store: EntityListEventListenerStore): EntityListEventListenerStore {\n\t\treturn store.cloneDeep()\n\t}\n\n\tprivate static mergeExpectedRelationMutation(\n\t\toriginal: ExpectedRelationMutation,\n\t\tfresh: ExpectedRelationMutation,\n\t): ExpectedRelationMutation {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === 'none') {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === 'none') {\n\t\t\treturn original\n\t\t}\n\t\treturn 'anyMutation'\n\t}\n\n\tprivate static mergeExpectedQualifiedEntityMutation(\n\t\toriginal: ExpectedQualifiedEntityMutation,\n\t\tfresh: ExpectedQualifiedEntityMutation,\n\t): ExpectedQualifiedEntityMutation {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === 'none') {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === 'none') {\n\t\t\treturn original\n\t\t}\n\t\treturn 'anyMutation'\n\t}\n\n\tprivate static mergeSubTreeAliases(\n\t\toriginal: Set<Alias> | undefined,\n\t\tfresh: Set<Alias> | undefined,\n\t): Set<Alias> | undefined {\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\treturn this.mergeSets(original, fresh)\n\t}\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Aa,OAAO;AAChB,aAAA;AAAA,IACR;AACA,QAAI,aAAa,QAAQ;AACjB,aAAA;AAAA,IACR;AACA,QAAI,UAAU,QAAQ;AACd,aAAA;AAAA,IACR;AACO,WAAA;AAAA,EACR;AAAA,EAEA,OAAe,oBACd,UACA,OACyB;AACzB,QAAI,aAAa,QAAW;AACpB,aAAA;AAAA,IACR;AACA,QAAI,UAAU,QAAW;AACjB,aAAA;AAAA,IACR;AACO,WAAA,KAAK,UAAU,UAAU,KAAK;AAAA,EACtC;AACD;"}
@@ -13,13 +13,13 @@ import { PlaceholderGenerator } from "../markers/PlaceholderGenerator.js";
13
13
  import { QueryLanguage } from "../queryLanguage/QueryLanguage.js";
14
14
  const emptyEntityIdSet = /* @__PURE__ */ new Set();
15
15
  class TreeStore {
16
- constructor() {
16
+ constructor(_schema) {
17
17
  __publicField(this, "entityStore", /* @__PURE__ */ new Map());
18
18
  __publicField(this, "entityRealmStore", /* @__PURE__ */ new Map());
19
19
  __publicField(this, "markerTrees", /* @__PURE__ */ new Map());
20
20
  __publicField(this, "subTreeStatesByRoot", /* @__PURE__ */ new Map());
21
- __publicField(this, "_schema");
22
21
  __publicField(this, "persistedData", new NormalizedPersistedData(/* @__PURE__ */ new Map(), /* @__PURE__ */ new Map()));
22
+ this._schema = _schema;
23
23
  }
24
24
  mergeInQueryResponse(response, markerTree) {
25
25
  RequestResponseNormalizer.mergeInQueryResponse(this.persistedData, response, markerTree);
@@ -27,11 +27,6 @@ class TreeStore {
27
27
  mergeInMutationResponse(response, operations) {
28
28
  RequestResponseNormalizer.mergeInMutationResponse(this.persistedData, response, operations);
29
29
  }
30
- setSchema(newSchema) {
31
- if (this._schema === void 0) {
32
- this._schema = newSchema;
33
- }
34
- }
35
30
  get persistedEntityData() {
36
31
  return this.persistedData.persistedEntityDataStore;
37
32
  }
@@ -39,9 +34,6 @@ class TreeStore {
39
34
  return this.persistedData.subTreeDataStore;
40
35
  }
41
36
  get schema() {
42
- if (this._schema === void 0) {
43
- throw new BindingError(`Fatal error: failed to load api schema.`);
44
- }
45
37
  return this._schema;
46
38
  }
47
39
  getPathBackToParent(entityRealm) {
@@ -67,10 +59,7 @@ class TreeStore {
67
59
  } else {
68
60
  return assertNever();
69
61
  }
70
- const relationSchema = this.schema.getEntityField(parentEntityName, relationFromParent);
71
- if (relationSchema?.__typename !== "_Relation") {
72
- throw new BindingError();
73
- }
62
+ const relationSchema = this.schema.getEntityRelation(parentEntityName, relationFromParent);
74
63
  const fieldBack = (relationSchema.ownedBy || relationSchema.inversedBy) ?? null;
75
64
  if (fieldBack === null) {
76
65
  return void 0;
@@ -85,7 +74,9 @@ class TreeStore {
85
74
  const subTreeStates = this.subTreeStatesByRoot.get(treeRootId);
86
75
  if (subTreeStates === void 0 || markerRoot === void 0) {
87
76
  if (treeRootId) {
88
- throw new BindingError(`Invalid tree id '${treeRootId}'. Make sure you use the one supplied by the correct extendTree call.`);
77
+ throw new BindingError(
78
+ `Invalid tree id '${treeRootId}'. Make sure you use the one supplied by the correct extendTree call.`
79
+ );
89
80
  }
90
81
  throw new BindingError(`Failed to retrieve a sub tree.`);
91
82
  }
@@ -97,9 +88,21 @@ class TreeStore {
97
88
  }
98
89
  placeholderName = placeholderByAlias;
99
90
  } else if (mode === "entityList") {
100
- placeholderName = PlaceholderGenerator.getEntityListSubTreePlaceholder(aliasOrParameters.isCreating ? QueryLanguage.desugarUnconstrainedQualifiedEntityList(aliasOrParameters, environment) : QueryLanguage.desugarQualifiedEntityList(aliasOrParameters, environment), environment);
91
+ placeholderName = PlaceholderGenerator.getEntityListSubTreePlaceholder(
92
+ aliasOrParameters.isCreating ? QueryLanguage.desugarUnconstrainedQualifiedEntityList(
93
+ aliasOrParameters,
94
+ environment
95
+ ) : QueryLanguage.desugarQualifiedEntityList(aliasOrParameters, environment),
96
+ environment
97
+ );
101
98
  } else if (mode === "entity") {
102
- placeholderName = PlaceholderGenerator.getEntitySubTreePlaceholder(aliasOrParameters.isCreating ? QueryLanguage.desugarUnconstrainedQualifiedSingleEntity(aliasOrParameters, environment) : QueryLanguage.desugarQualifiedSingleEntity(aliasOrParameters, environment), environment);
99
+ placeholderName = PlaceholderGenerator.getEntitySubTreePlaceholder(
100
+ aliasOrParameters.isCreating ? QueryLanguage.desugarUnconstrainedQualifiedSingleEntity(
101
+ aliasOrParameters,
102
+ environment
103
+ ) : QueryLanguage.desugarQualifiedSingleEntity(aliasOrParameters, environment),
104
+ environment
105
+ );
103
106
  } else {
104
107
  throw new BindingError();
105
108
  }
@@ -171,5 +174,7 @@ class TreeStore {
171
174
  return true;
172
175
  }
173
176
  }
174
- export { TreeStore };
177
+ export {
178
+ TreeStore
179
+ };
175
180
  //# sourceMappingURL=TreeStore.js.map