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

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":"QueryGenerator.js","sources":["../../../src/core/QueryGenerator.ts"],"sourcesContent":["import { CrudQueryBuilder } from '@contember/client'\nimport { PRIMARY_KEY_NAME } from '../bindingTypes'\nimport {\n\tEntityFieldMarkers,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n} from '../markers'\nimport { assertNever, ucfirst } from '../utils'\n\ntype BaseQueryBuilder = Omit<CrudQueryBuilder.CrudQueryBuilder, CrudQueryBuilder.Mutations>\n\ntype ReadBuilder = CrudQueryBuilder.ReadBuilder.Builder<never>\n\nexport class QueryGenerator {\n\tconstructor(private tree: MarkerTreeRoot) {}\n\n\tpublic getReadQuery(): string | undefined {\n\t\ttry {\n\t\t\tlet baseQueryBuilder: BaseQueryBuilder = new CrudQueryBuilder.CrudQueryBuilder()\n\n\t\t\tfor (const [, subTreeMarker] of this.tree.subTrees) {\n\t\t\t\tbaseQueryBuilder = this.addSubQuery(subTreeMarker, baseQueryBuilder)\n\t\t\t}\n\t\t\treturn baseQueryBuilder.getGql()\n\t\t} catch (e) {\n\t\t\treturn undefined\n\t\t}\n\t}\n\n\tprivate addSubQuery(\n\t\tsubTree: EntitySubTreeMarker | EntityListSubTreeMarker,\n\t\tbaseQueryBuilder: BaseQueryBuilder,\n\t): BaseQueryBuilder {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\t// Unconstrained trees, by definition, don't have any queries.\n\t\t\treturn baseQueryBuilder\n\t\t}\n\n\t\tif (subTree instanceof EntityListSubTreeMarker) {\n\t\t\treturn this.addListQuery(baseQueryBuilder, subTree)\n\t\t} else if (subTree instanceof EntitySubTreeMarker) {\n\t\t\treturn this.addGetQuery(baseQueryBuilder, subTree)\n\t\t}\n\n\t\tassertNever(subTree)\n\t}\n\n\tprivate addGetQuery(baseQueryBuilder: BaseQueryBuilder, subTree: EntitySubTreeMarker): BaseQueryBuilder {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\treturn baseQueryBuilder\n\t\t}\n\t\tconst populatedListQueryBuilder = QueryGenerator.registerQueryPart(\n\t\t\tsubTree.fields.markers,\n\t\t\tCrudQueryBuilder.ReadBuilder.instantiate<CrudQueryBuilder.GetQueryArguments>().by(subTree.parameters.where),\n\t\t)\n\t\treturn baseQueryBuilder.get(\n\t\t\tsubTree.entityName,\n\t\t\tCrudQueryBuilder.ReadBuilder.instantiate(\n\t\t\t\tpopulatedListQueryBuilder ? populatedListQueryBuilder.objectBuilder : undefined,\n\t\t\t),\n\t\t\tsubTree.placeholderName,\n\t\t)\n\t}\n\n\tprivate addListQuery(baseQueryBuilder: BaseQueryBuilder, subTree: EntityListSubTreeMarker): BaseQueryBuilder {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\treturn baseQueryBuilder\n\t\t}\n\n\t\tlet finalBuilder: ReadBuilder\n\n\t\tif (subTree.parameters) {\n\t\t\tconst parameters = subTree.parameters\n\t\t\tconst withFilter: CrudQueryBuilder.ReadBuilder.Builder<Exclude<CrudQueryBuilder.ReadArguments, 'filter'>> =\n\t\t\t\tparameters.filter\n\t\t\t\t\t? CrudQueryBuilder.ReadBuilder.instantiate().filter(parameters.filter)\n\t\t\t\t\t: CrudQueryBuilder.ReadBuilder.instantiate()\n\n\t\t\tconst withOrderBy: CrudQueryBuilder.ReadBuilder.Builder<\n\t\t\t\tExclude<CrudQueryBuilder.ReadArguments, 'filter' | 'orderBy'>\n\t\t\t> = parameters.orderBy ? withFilter.orderBy(parameters.orderBy) : withFilter\n\n\t\t\tconst withOffset: CrudQueryBuilder.ReadBuilder.Builder<\n\t\t\t\tExclude<CrudQueryBuilder.ReadArguments, 'filter' | 'orderBy' | 'offset'>\n\t\t\t> = parameters.offset === undefined ? withOrderBy : withOrderBy.offset(parameters.offset)\n\n\t\t\tfinalBuilder = parameters.limit === undefined ? withOffset : withOffset.limit(parameters.limit)\n\t\t} else {\n\t\t\tfinalBuilder = CrudQueryBuilder.ReadBuilder.instantiate()\n\t\t}\n\n\t\t// const fullyPopulated = withAllParams\n\t\t// \t.anyRelation('pageInfo', builder => builder.column('totalCount'))\n\t\t// \t.anyRelation('edges', builder =>\n\t\t// \t\tbuilder.anyRelation('node', builder => QueryGenerator.registerQueryPart(subTree.fields.markers, builder)),\n\t\t// \t)\n\n\t\treturn baseQueryBuilder.list(\n\t\t\tsubTree.entityName,\n\t\t\tQueryGenerator.registerQueryPart(subTree.fields.markers, finalBuilder),\n\t\t\tsubTree.placeholderName,\n\t\t)\n\t}\n\n\tpublic static registerQueryPart(fields: EntityFieldMarkers, builder: ReadBuilder): ReadBuilder {\n\t\tbuilder = builder.column(PRIMARY_KEY_NAME)\n\n\t\tfor (const [, fieldValue] of fields) {\n\t\t\tif (fieldValue instanceof FieldMarker) {\n\t\t\t\tif (fieldValue.fieldName !== PRIMARY_KEY_NAME) {\n\t\t\t\t\tbuilder = builder.column(fieldValue.fieldName)\n\t\t\t\t}\n\t\t\t} else if (fieldValue instanceof HasOneRelationMarker) {\n\t\t\t\tconst relation = fieldValue.parameters\n\t\t\t\tconst builderWithBody = CrudQueryBuilder.ReadBuilder.instantiate(\n\t\t\t\t\tthis.registerQueryPart(fieldValue.fields.markers, CrudQueryBuilder.ReadBuilder.instantiate()).objectBuilder,\n\t\t\t\t)\n\n\t\t\t\tconst filteredBuilder: CrudQueryBuilder.ReadBuilder.Builder<Exclude<CrudQueryBuilder.ReadArguments, 'filter'>> =\n\t\t\t\t\trelation.filter ? builderWithBody.filter(relation.filter) : builderWithBody\n\n\t\t\t\tif (relation.reducedBy) {\n\t\t\t\t\t// Assuming there's exactly one reducer field as enforced by MarkerTreeGenerator\n\t\t\t\t\tconst relationField = `${relation.field}By${ucfirst(Object.keys(relation.reducedBy)[0])}`\n\t\t\t\t\tbuilder = builder.reductionRelation(\n\t\t\t\t\t\trelationField,\n\t\t\t\t\t\tfilteredBuilder.by(relation.reducedBy),\n\t\t\t\t\t\tfieldValue.placeholderName,\n\t\t\t\t\t)\n\t\t\t\t} else {\n\t\t\t\t\tbuilder = builder.hasOneRelation(\n\t\t\t\t\t\trelation.field,\n\t\t\t\t\t\tfilteredBuilder,\n\t\t\t\t\t\t// TODO this will currently always go to the latter condition, resulting in less than ideal queries.\n\t\t\t\t\t\tfieldValue.placeholderName === relation.field ? undefined : fieldValue.placeholderName,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (fieldValue instanceof HasManyRelationMarker) {\n\t\t\t\tconst relation = fieldValue.parameters\n\t\t\t\tconst builderWithBody = CrudQueryBuilder.ReadBuilder.instantiate(\n\t\t\t\t\tthis.registerQueryPart(fieldValue.fields.markers, CrudQueryBuilder.ReadBuilder.instantiate()).objectBuilder,\n\t\t\t\t)\n\n\t\t\t\tconst withFilter: CrudQueryBuilder.ReadBuilder.Builder<Exclude<CrudQueryBuilder.ReadArguments, 'filter'>> =\n\t\t\t\t\trelation.filter ? builderWithBody.filter(relation.filter) : builderWithBody\n\n\t\t\t\tconst withOrderBy: CrudQueryBuilder.ReadBuilder.Builder<\n\t\t\t\t\tExclude<CrudQueryBuilder.ReadArguments, 'filter' | 'orderBy'>\n\t\t\t\t> = relation.orderBy ? withFilter.orderBy(relation.orderBy) : withFilter\n\n\t\t\t\tconst withOffset: CrudQueryBuilder.ReadBuilder.Builder<\n\t\t\t\t\tExclude<CrudQueryBuilder.ReadArguments, 'filter' | 'orderBy' | 'offset'>\n\t\t\t\t> = relation.offset === undefined ? withOrderBy : withOrderBy.offset(relation.offset)\n\n\t\t\t\tconst withLimit = relation.limit === undefined ? withOffset : withOffset.limit(relation.limit)\n\n\t\t\t\tbuilder = builder.anyRelation(\n\t\t\t\t\trelation.field,\n\t\t\t\t\twithLimit,\n\t\t\t\t\tfieldValue.placeholderName === relation.field ? undefined : fieldValue.placeholderName,\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tassertNever(fieldValue)\n\t\t\t}\n\t\t}\n\n\t\treturn builder\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;AAiBO,MAAM,eAAe;AAAA,EAC3B,YAAoB,MAAsB;AAAtB,SAAA,OAAA;AAAA,EAAuB;AAAA,EAEpC,eAAmC;AACrC,QAAA;AACC,UAAA,mBAAqC,IAAI,iBAAiB;AAE9D,iBAAW,CAAA,EAAG,kBAAkB,KAAK,KAAK,UAAU;AAChC,2BAAA,KAAK,YAAY,eAAe,gBAAgB;AAAA,MACpE;AACA,aAAO,iBAAiB;aAChB;AACD,aAAA;AAAA,IACR;AAAA,EACD;AAAA,EAEQ,YACP,SACA,kBACmB;AACf,QAAA,QAAQ,WAAW,YAAY;AAE3B,aAAA;AAAA,IACR;AAEA,QAAI,mBAAmB,yBAAyB;AACxC,aAAA,KAAK,aAAa,kBAAkB,OAAO;AAAA,IAAA,WACxC,mBAAmB,qBAAqB;AAC3C,aAAA,KAAK,YAAY,kBAAkB,OAAO;AAAA,IAClD;AAEA,gBAAmB;AAAA,EACpB;AAAA,EAEQ,YAAY,kBAAoC,SAAgD;AACnG,QAAA,QAAQ,WAAW,YAAY;AAC3B,aAAA;AAAA,IACR;AACA,UAAM,4BAA4B,eAAe,kBAChD,QAAQ,OAAO,SACf,iBAAiB,YAAY,YAAkD,EAAA,GAAG,QAAQ,WAAW,KAAK,CAC3G;AACA,WAAO,iBAAiB,IACvB,QAAQ,YACR,iBAAiB,YAAY,YAC5B,4BAA4B,0BAA0B,gBAAgB,MACvE,GACA,QAAQ,eACT;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AAS,GACrC,WAAW,eACZ;AAAA,QAAA,OACM;AACI,oBAAA,QAAQ,eACjB,SAAS,OACT,iBAEA,WAAW,oBAAoB,SAAS,QAAQ,SAAY,WAAW,eACxE;AAAA,QACD;AAAA,MAAA,WACU,sBAAsB,uBAAuB;AACvD,cAAM,WAAW,WAAW;AAC5B,cAAM,kBAAkB,iBAAiB,YAAY,YACpD,KAAK,kBAAkB,WAAW,OAAO,SAAS,iBAAiB,YAAY,YAAa,CAAA,EAAE,aAC/F;AAEA,cAAM,aACL,SAAS,SAAS,gBAAgB,OAAO,SAAS,MAAM,IAAI;AAE7D,cAAM,cAEF,SAAS,UAAU,WAAW,QAAQ,SAAS,OAAO,IAAI;AAExD,cAAA,aAEF,SAAS,WAAW,SAAY,cAAc,YAAY,OAAO,SAAS,MAAM;AAE9E,cAAA,YAAY,SAAS,UAAU,SAAY,aAAa,WAAW,MAAM,SAAS,KAAK;AAEnF,kBAAA,QAAQ,YACjB,SAAS,OACT,WACA,WAAW,oBAAoB,SAAS,QAAQ,SAAY,WAAW,eACxE;AAAA,MAAA,OACM;AACN,oBAAsB;AAAA,MACvB;AAAA,IACD;AAEO,WAAA;AAAA,EACR;AACD;;"}
1
+ {"version":3,"file":"QueryGenerator.js","sources":["../../../src/core/QueryGenerator.ts"],"sourcesContent":["import { CrudQueryBuilder } from '@contember/client'\nimport { PRIMARY_KEY_NAME } from '../bindingTypes'\nimport {\n\tEntityFieldMarkers,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n} from '../markers'\nimport { assertNever, ucfirst } from '../utils'\n\ntype BaseQueryBuilder = Omit<CrudQueryBuilder.CrudQueryBuilder, CrudQueryBuilder.Mutations>\n\ntype ReadBuilder = CrudQueryBuilder.ReadBuilder.Builder<never>\n\nexport class QueryGenerator {\n\tconstructor(private tree: MarkerTreeRoot) {}\n\n\tpublic getReadQuery(): string | undefined {\n\t\ttry {\n\t\t\tlet baseQueryBuilder: BaseQueryBuilder = new CrudQueryBuilder.CrudQueryBuilder()\n\n\t\t\tfor (const [, subTreeMarker] of this.tree.subTrees) {\n\t\t\t\tbaseQueryBuilder = this.addSubQuery(subTreeMarker, baseQueryBuilder)\n\t\t\t}\n\t\t\treturn baseQueryBuilder.getGql()\n\t\t} catch (e) {\n\t\t\treturn undefined\n\t\t}\n\t}\n\n\tprivate addSubQuery(\n\t\tsubTree: EntitySubTreeMarker | EntityListSubTreeMarker,\n\t\tbaseQueryBuilder: BaseQueryBuilder,\n\t): BaseQueryBuilder {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\t// Unconstrained trees, by definition, don't have any queries.\n\t\t\treturn baseQueryBuilder\n\t\t}\n\n\t\tif (subTree instanceof EntityListSubTreeMarker) {\n\t\t\treturn this.addListQuery(baseQueryBuilder, subTree)\n\t\t} else if (subTree instanceof EntitySubTreeMarker) {\n\t\t\treturn this.addGetQuery(baseQueryBuilder, subTree)\n\t\t}\n\n\t\tassertNever(subTree)\n\t}\n\n\tprivate addGetQuery(baseQueryBuilder: BaseQueryBuilder, subTree: EntitySubTreeMarker): BaseQueryBuilder {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\treturn baseQueryBuilder\n\t\t}\n\t\tconst populatedListQueryBuilder = QueryGenerator.registerQueryPart(\n\t\t\tsubTree.fields.markers,\n\t\t\tCrudQueryBuilder.ReadBuilder.instantiate<CrudQueryBuilder.GetQueryArguments>().by(subTree.parameters.where),\n\t\t)\n\t\treturn baseQueryBuilder.get(\n\t\t\tsubTree.entityName,\n\t\t\tCrudQueryBuilder.ReadBuilder.instantiate(\n\t\t\t\tpopulatedListQueryBuilder ? populatedListQueryBuilder.objectBuilder : undefined,\n\t\t\t),\n\t\t\tsubTree.placeholderName,\n\t\t)\n\t}\n\n\tprivate addListQuery(baseQueryBuilder: BaseQueryBuilder, subTree: EntityListSubTreeMarker): BaseQueryBuilder {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\treturn baseQueryBuilder\n\t\t}\n\n\t\tlet finalBuilder: ReadBuilder\n\n\t\tif (subTree.parameters) {\n\t\t\tconst parameters = subTree.parameters\n\t\t\tconst withFilter: CrudQueryBuilder.ReadBuilder.Builder<Exclude<CrudQueryBuilder.ReadArguments, 'filter'>> =\n\t\t\t\tparameters.filter\n\t\t\t\t\t? CrudQueryBuilder.ReadBuilder.instantiate().filter(parameters.filter)\n\t\t\t\t\t: CrudQueryBuilder.ReadBuilder.instantiate()\n\n\t\t\tconst withOrderBy: CrudQueryBuilder.ReadBuilder.Builder<\n\t\t\t\tExclude<CrudQueryBuilder.ReadArguments, 'filter' | 'orderBy'>\n\t\t\t> = parameters.orderBy ? withFilter.orderBy(parameters.orderBy) : withFilter\n\n\t\t\tconst withOffset: CrudQueryBuilder.ReadBuilder.Builder<\n\t\t\t\tExclude<CrudQueryBuilder.ReadArguments, 'filter' | 'orderBy' | 'offset'>\n\t\t\t> = parameters.offset === undefined ? withOrderBy : withOrderBy.offset(parameters.offset)\n\n\t\t\tfinalBuilder = parameters.limit === undefined ? withOffset : withOffset.limit(parameters.limit)\n\t\t} else {\n\t\t\tfinalBuilder = CrudQueryBuilder.ReadBuilder.instantiate()\n\t\t}\n\n\t\t// const fullyPopulated = withAllParams\n\t\t// \t.anyRelation('pageInfo', builder => builder.column('totalCount'))\n\t\t// \t.anyRelation('edges', builder =>\n\t\t// \t\tbuilder.anyRelation('node', builder => QueryGenerator.registerQueryPart(subTree.fields.markers, builder)),\n\t\t// \t)\n\n\t\treturn baseQueryBuilder.list(\n\t\t\tsubTree.entityName,\n\t\t\tQueryGenerator.registerQueryPart(subTree.fields.markers, finalBuilder),\n\t\t\tsubTree.placeholderName,\n\t\t)\n\t}\n\n\tpublic static registerQueryPart(fields: EntityFieldMarkers, builder: ReadBuilder): ReadBuilder {\n\t\tbuilder = builder.column(PRIMARY_KEY_NAME)\n\n\t\tfor (const [, fieldValue] of fields) {\n\t\t\tif (fieldValue instanceof FieldMarker) {\n\t\t\t\tif (fieldValue.fieldName !== PRIMARY_KEY_NAME) {\n\t\t\t\t\tbuilder = builder.column(fieldValue.fieldName)\n\t\t\t\t}\n\t\t\t} else if (fieldValue instanceof HasOneRelationMarker) {\n\t\t\t\tconst relation = fieldValue.parameters\n\t\t\t\tconst builderWithBody = CrudQueryBuilder.ReadBuilder.instantiate(\n\t\t\t\t\tthis.registerQueryPart(fieldValue.fields.markers, CrudQueryBuilder.ReadBuilder.instantiate()).objectBuilder,\n\t\t\t\t)\n\n\t\t\t\tconst filteredBuilder: CrudQueryBuilder.ReadBuilder.Builder<Exclude<CrudQueryBuilder.ReadArguments, 'filter'>> =\n\t\t\t\t\trelation.filter ? builderWithBody.filter(relation.filter) : builderWithBody\n\n\t\t\t\tif (relation.reducedBy) {\n\t\t\t\t\t// Assuming there's exactly one reducer field as enforced by MarkerTreeGenerator\n\t\t\t\t\tconst relationField = `${relation.field}By${ucfirst(Object.keys(relation.reducedBy)[0])}`\n\t\t\t\t\tbuilder = builder.reductionRelation(\n\t\t\t\t\t\trelationField,\n\t\t\t\t\t\tfilteredBuilder.by(relation.reducedBy),\n\t\t\t\t\t\tfieldValue.placeholderName,\n\t\t\t\t\t)\n\t\t\t\t} else {\n\t\t\t\t\tbuilder = builder.hasOneRelation(\n\t\t\t\t\t\trelation.field,\n\t\t\t\t\t\tfilteredBuilder,\n\t\t\t\t\t\t// TODO this will currently always go to the latter condition, resulting in less than ideal queries.\n\t\t\t\t\t\tfieldValue.placeholderName === relation.field ? undefined : fieldValue.placeholderName,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (fieldValue instanceof HasManyRelationMarker) {\n\t\t\t\tconst relation = fieldValue.parameters\n\t\t\t\tconst builderWithBody = CrudQueryBuilder.ReadBuilder.instantiate(\n\t\t\t\t\tthis.registerQueryPart(fieldValue.fields.markers, CrudQueryBuilder.ReadBuilder.instantiate()).objectBuilder,\n\t\t\t\t)\n\n\t\t\t\tconst withFilter: CrudQueryBuilder.ReadBuilder.Builder<Exclude<CrudQueryBuilder.ReadArguments, 'filter'>> =\n\t\t\t\t\trelation.filter ? builderWithBody.filter(relation.filter) : builderWithBody\n\n\t\t\t\tconst withOrderBy: CrudQueryBuilder.ReadBuilder.Builder<\n\t\t\t\t\tExclude<CrudQueryBuilder.ReadArguments, 'filter' | 'orderBy'>\n\t\t\t\t> = relation.orderBy ? withFilter.orderBy(relation.orderBy) : withFilter\n\n\t\t\t\tconst withOffset: CrudQueryBuilder.ReadBuilder.Builder<\n\t\t\t\t\tExclude<CrudQueryBuilder.ReadArguments, 'filter' | 'orderBy' | 'offset'>\n\t\t\t\t> = relation.offset === undefined ? withOrderBy : withOrderBy.offset(relation.offset)\n\n\t\t\t\tconst withLimit = relation.limit === undefined ? withOffset : withOffset.limit(relation.limit)\n\n\t\t\t\tbuilder = builder.anyRelation(\n\t\t\t\t\trelation.field,\n\t\t\t\t\twithLimit,\n\t\t\t\t\tfieldValue.placeholderName === relation.field ? undefined : fieldValue.placeholderName,\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tassertNever(fieldValue)\n\t\t\t}\n\t\t}\n\n\t\treturn builder\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;AAiBO,MAAM,eAAe;AAAA,EAC3B,YAAoB,MAAsB;AAAtB,SAAA,OAAA;AAAA,EAAuB;AAAA,EAEpC,eAAmC;AACrC,QAAA;AACC,UAAA,mBAAqC,IAAI,iBAAiB;AAE9D,iBAAW,CAAA,EAAG,aAAa,KAAK,KAAK,KAAK,UAAU;AAChC,2BAAA,KAAK,YAAY,eAAe,gBAAgB;AAAA,MACpE;AACA,aAAO,iBAAiB;aAChB;AACD,aAAA;AAAA,IACR;AAAA,EACD;AAAA,EAEQ,YACP,SACA,kBACmB;AACf,QAAA,QAAQ,WAAW,YAAY;AAE3B,aAAA;AAAA,IACR;AAEA,QAAI,mBAAmB,yBAAyB;AACxC,aAAA,KAAK,aAAa,kBAAkB,OAAO;AAAA,IA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Y,WAAW;AAAA,QAAA;AAAA,MACxE,OACM;AACN,oBAAsB;AAAA,MACvB;AAAA,IACD;AAEO,WAAA;AAAA,EACR;AACD;"}
@@ -13,7 +13,9 @@ class RealmKeyGenerator {
13
13
  return candidate.startsWith(`key${GLUE}`) && keyEndRegex.test(candidate);
14
14
  }
15
15
  static generateKey(parent, placeholderName, id, container) {
16
- return `key${GLUE}${this.parentStateIdCache.getOptionalKeyId(parent)}${GLUE}${placeholderName}${id}${GLUE}${this.markerIdCache.getId(container)}`;
16
+ return `key${GLUE}${this.parentStateIdCache.getOptionalKeyId(
17
+ parent
18
+ )}${GLUE}${placeholderName}${id}${GLUE}${this.markerIdCache.getId(container)}`;
17
19
  }
18
20
  static getRealmKey(id, blueprint) {
19
21
  const parent = blueprint.parent;
@@ -27,10 +29,17 @@ class RealmKeyGenerator {
27
29
  } else {
28
30
  return assertNever();
29
31
  }
30
- return this.generateKey(parent, placeholderName, id.value, blueprint.type === "listEntity" ? blueprint.parent.blueprint.marker.fields : blueprint.marker.fields);
32
+ return this.generateKey(
33
+ parent,
34
+ placeholderName,
35
+ id.value,
36
+ blueprint.type === "listEntity" ? blueprint.parent.blueprint.marker.fields : blueprint.marker.fields
37
+ );
31
38
  }
32
39
  }
33
40
  __publicField(RealmKeyGenerator, "parentStateIdCache", new WeakIdCache());
34
41
  __publicField(RealmKeyGenerator, "markerIdCache", new WeakIdCache());
35
- export { RealmKeyGenerator };
42
+ export {
43
+ RealmKeyGenerator
44
+ };
36
45
  //# sourceMappingURL=RealmKeyGenerator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RealmKeyGenerator.js","sources":["../../../src/core/RealmKeyGenerator.ts"],"sourcesContent":["import type { RuntimeId } from '../accessorTree'\nimport type { EntityFieldMarkersContainer } from '../markers'\nimport type { EntityId, EntityRealmKey, PlaceholderName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport type { EntityListState, EntityRealmBlueprint, EntityRealmState } from './state'\nimport { WeakIdCache } from '../structures'\n\nconst GLUE = '--'\nconst keyEndRegex = new RegExp(`${GLUE}\\\\d+$`)\n\nexport class RealmKeyGenerator {\n\t// We're using this id, and not, well, the entity id, because it *SIGNIFICANTLY* reduces the complexity of\n\t// entity id changes.\n\tprivate static parentStateIdCache = new WeakIdCache<EntityRealmState | EntityListState>()\n\tprivate static markerIdCache = new WeakIdCache<EntityFieldMarkersContainer>()\n\n\tpublic static vaguelyAppearsToBeAKey(candidate: string): boolean {\n\t\t// This is just for error messages. No need to be super precise.\n\t\treturn candidate.startsWith(`key${GLUE}`) && keyEndRegex.test(candidate)\n\t}\n\n\tprivate static generateKey(\n\t\tparent: EntityRealmState | EntityListState | undefined,\n\t\tplaceholderName: PlaceholderName,\n\t\tid: EntityId,\n\t\tcontainer: EntityFieldMarkersContainer,\n\t): EntityRealmKey {\n\t\t// The static prefix serves to really emphasize that this is *NOT* just a uuid\n\t\treturn `key${GLUE}${this.parentStateIdCache.getOptionalKeyId(\n\t\t\tparent,\n\t\t)}${GLUE}${placeholderName}${id}${GLUE}${this.markerIdCache.getId(container)}`\n\t}\n\n\tpublic static getRealmKey(id: RuntimeId, blueprint: EntityRealmBlueprint): EntityRealmKey {\n\t\tconst parent = blueprint.parent\n\t\tlet placeholderName: PlaceholderName\n\n\t\tif (blueprint.type === 'subTree') {\n\t\t\tplaceholderName = blueprint.marker.placeholderName\n\t\t} else if (blueprint.type === 'listEntity') {\n\t\t\tplaceholderName = blueprint.parent.blueprint.marker.placeholderName\n\t\t} else if (blueprint.type === 'hasOne') {\n\t\t\tplaceholderName = blueprint.marker.placeholderName\n\t\t} else {\n\t\t\treturn assertNever(blueprint)\n\t\t}\n\t\treturn this.generateKey(\n\t\t\tparent,\n\t\t\tplaceholderName,\n\t\t\tid.value,\n\t\t\tblueprint.type === 'listEntity' ? blueprint.parent.blueprint.marker.fields : blueprint.marker.fields,\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;AAOA,MAAM,OAAO;AACb,MAAM,cAAc,IAAI,OAAO,GAAG,WAAW;AAEtC,MAAM,kBAAkB;AAAA,SAMhB,uBAAuB,WAA4B;AAEhE,WAAO,UAAU,WAAW,MAAM,MAAM,KAAK,YAAY,KAAK,SAAS;AAAA,EACxE;AAAA,SAEe,YACd,QACA,iBACA,IACA,WACiB;AAEjB,WAAO,MAAM,OAAO,KAAK,mBAAmB,iBAC3C,MACD,IAAI,OAAO,kBAAkB,KAAK,OAAO,KAAK,cAAc,MAAM,SAAS;AAAA,EAC5E;AAAA,SAEc,YAAY,IAAe,WAAiD;AACzF,UAAM,SAAS,UAAU;AACrB,QAAA;AAEA,QAAA,UAAU,SAAS,WAAW;AACjC,wBAAkB,UAAU,OAAO;AAAA,IAAA,WACzB,UAAU,SAAS,cAAc;AACzB,wBAAA,UAAU,OAAO,UAAU,OAAO;AAAA,IAAA,WAC1C,UAAU,SAAS,UAAU;AACvC,wBAAkB,UAAU,OAAO;AAAA,IAAA,OAC7B;AACN,aAAO,YAAqB;AAAA,IAC7B;AACA,WAAO,KAAK,YACX,QACA,iBACA,GAAG,OACH,UAAU,SAAS,eAAe,UAAU,OAAO,UAAU,OAAO,SAAS,UAAU,OAAO,MAC/F;AAAA,EACD;AACD;AAxCgB,cAHT,mBAGS,sBAAqB,IAAI;AACzB,cAJT,mBAIS,iBAAgB,IAAI;;"}
1
+ {"version":3,"file":"RealmKeyGenerator.js","sources":["../../../src/core/RealmKeyGenerator.ts"],"sourcesContent":["import type { RuntimeId } from '../accessorTree'\nimport type { EntityFieldMarkersContainer } from '../markers'\nimport type { EntityId, EntityRealmKey, PlaceholderName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport type { EntityListState, EntityRealmBlueprint, EntityRealmState } from './state'\nimport { WeakIdCache } from '../structures'\n\nconst GLUE = '--'\nconst keyEndRegex = new RegExp(`${GLUE}\\\\d+$`)\n\nexport class RealmKeyGenerator {\n\t// We're using this id, and not, well, the entity id, because it *SIGNIFICANTLY* reduces the complexity of\n\t// entity id changes.\n\tprivate static parentStateIdCache = new WeakIdCache<EntityRealmState | EntityListState>()\n\tprivate static markerIdCache = new WeakIdCache<EntityFieldMarkersContainer>()\n\n\tpublic static vaguelyAppearsToBeAKey(candidate: string): boolean {\n\t\t// This is just for error messages. No need to be super precise.\n\t\treturn candidate.startsWith(`key${GLUE}`) && keyEndRegex.test(candidate)\n\t}\n\n\tprivate static generateKey(\n\t\tparent: EntityRealmState | EntityListState | undefined,\n\t\tplaceholderName: PlaceholderName,\n\t\tid: EntityId,\n\t\tcontainer: EntityFieldMarkersContainer,\n\t): EntityRealmKey {\n\t\t// The static prefix serves to really emphasize that this is *NOT* just a uuid\n\t\treturn `key${GLUE}${this.parentStateIdCache.getOptionalKeyId(\n\t\t\tparent,\n\t\t)}${GLUE}${placeholderName}${id}${GLUE}${this.markerIdCache.getId(container)}`\n\t}\n\n\tpublic static getRealmKey(id: RuntimeId, blueprint: EntityRealmBlueprint): EntityRealmKey {\n\t\tconst parent = blueprint.parent\n\t\tlet placeholderName: PlaceholderName\n\n\t\tif (blueprint.type === 'subTree') {\n\t\t\tplaceholderName = blueprint.marker.placeholderName\n\t\t} else if (blueprint.type === 'listEntity') {\n\t\t\tplaceholderName = blueprint.parent.blueprint.marker.placeholderName\n\t\t} else if (blueprint.type === 'hasOne') {\n\t\t\tplaceholderName = blueprint.marker.placeholderName\n\t\t} else {\n\t\t\treturn assertNever(blueprint)\n\t\t}\n\t\treturn this.generateKey(\n\t\t\tparent,\n\t\t\tplaceholderName,\n\t\t\tid.value,\n\t\t\tblueprint.type === 'listEntity' ? blueprint.parent.blueprint.marker.fields : blueprint.marker.fields,\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;AAOA,MAAM,OAAO;AACb,MAAM,cAAc,IAAI,OAAO,GAAG,WAAW;AAEtC,MAAM,kBAAkB;AAAA,EAM9B,OAAc,uBAAuB,WAA4B;AAEhE,WAAO,UAAU,WAAW,MAAM,MAAM,KAAK,YAAY,KAAK,SAAS;AAAA,EACxE;AAAA,EAEA,OAAe,YACd,QACA,iBACA,IACA,WACiB;AAEV,WAAA,MAAM,OAAO,KAAK,mBAAmB;AAAA,MAC3C;AAAA,IACD,IAAI,OAAO,kBAAkB,KAAK,OAAO,KAAK,cAAc,MAAM,SAAS;AAAA,EAC5E;AAAA,EAEA,OAAc,YAAY,IAAe,WAAiD;AACzF,UAAM,SAAS,UAAU;AACrB,QAAA;AAEA,QAAA,UAAU,SAAS,WAAW;AACjC,wBAAkB,UAAU,OAAO;AAAA,IAAA,WACzB,UAAU,SAAS,cAAc;AACzB,wBAAA,UAAU,OAAO,UAAU,OAAO;AAAA,IAAA,WAC1C,UAAU,SAAS,UAAU;AACvC,wBAAkB,UAAU,OAAO;AAAA,IAAA,OAC7B;AACN,aAAO,YAAqB;AAAA,IAC7B;AACA,WAAO,KAAK;AAAA,MACX;AAAA,MACA;AAAA,MACA,GAAG;AAAA,MACH,UAAU,SAAS,eAAe,UAAU,OAAO,UAAU,OAAO,SAAS,UAAU,OAAO;AAAA,IAAA;AAAA,EAEhG;AACD;AAxCC,cAHY,mBAGG,sBAAqB,IAAI;AACxC,cAJY,mBAIG,iBAAgB,IAAI;"}
@@ -119,5 +119,7 @@ class RequestResponseNormalizer {
119
119
  return new ServerId(primaryKey, entityData.__typename);
120
120
  }
121
121
  }
122
- export { RequestResponseNormalizer };
122
+ export {
123
+ RequestResponseNormalizer
124
+ };
123
125
  //# sourceMappingURL=RequestResponseNormalizer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RequestResponseNormalizer.js","sources":["../../../src/core/RequestResponseNormalizer.ts"],"sourcesContent":["import {\n\tNormalizedPersistedData,\n\tPersistedEntityDataStore,\n\tReceivedDataTree,\n\tReceivedEntityData,\n\tServerId,\n} from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport { PRIMARY_KEY_NAME } from '../bindingTypes'\nimport { EntityId } from '../treeParameters'\nimport {\n\tEntityFieldMarkers,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n} from '../markers'\nimport { SubMutationOperation } from './MutationGenerator'\nimport { assertNever } from '../utils'\n\nexport class RequestResponseNormalizer {\n\tpublic static mergeInQueryResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t\tmarkerTree: MarkerTreeRoot,\n\t): void {\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\n\t\tfor (const [placeholder, marker] of markerTree.subTrees) {\n\t\t\tconst data = newPersistedData[placeholder] ?? null\n\t\t\tif (marker instanceof EntitySubTreeMarker) {\n\t\t\t\tif (data === null) {\n\t\t\t\t\tsubTreeDataStore.delete(placeholder)\n\t\t\t\t} else {\n\t\t\t\t\tif (Array.isArray(data)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, data, marker.fields.markers)\n\t\t\t\t\tsubTreeDataStore.set(placeholder, id)\n\t\t\t\t}\n\t\t\t} else if (EntityListSubTreeMarker) {\n\t\t\t\tconst subTreeListIds = new Set<EntityId>()\n\t\t\t\tif (!Array.isArray(data)) {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tfor (const row of data) {\n\t\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, row, marker.fields.markers)\n\t\t\t\t\tsubTreeListIds.add(id.value)\n\t\t\t\t}\n\t\t\t\tsubTreeDataStore.set(placeholder, subTreeListIds)\n\t\t\t} else {\n\t\t\t\tthrow new BindingError()\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static mergeInMutationResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t\toperations: SubMutationOperation[],\n\t): void {\n\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\n\t\tfor (const operation of operations) {\n\t\t\tconst { subTreePlaceholder, subTreeType, alias } = operation\n\n\t\t\tconst receivedData = newPersistedData[alias]\n\t\t\tif (!receivedData || Array.isArray(receivedData)) {\n\t\t\t\tthrow new BindingError()\n\t\t\t}\n\n\t\t\tif (operation.type === 'update' || operation.type === 'create') {\n\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, receivedData, operation.markers)\n\t\t\t\tif (subTreeType === 'single') {\n\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, id)\n\t\t\t\t} else if (subTreeType === 'list') {\n\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\tif (list instanceof Set) {\n\t\t\t\t\t\t// TODO this is somewhat dubious because we're essentially just guessing the order of the entities\n\t\t\t\t\t\t//\t\tand just carelessly put the new one at the end.\n\t\t\t\t\t\tlist.add(id.value)\n\t\t\t\t\t} else if (list === undefined) {\n\t\t\t\t\t\t// That's fine. This is probably just an isCreating sub-tree.\n\t\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, new Set([id.value]))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t}\n\t\t\t} else if (operation.type === 'delete') {\n\t\t\t\tconst id = this.extractId(receivedData)\n\t\t\t\t// TODO there are potentially some references to entityId that this whole process won't quite remove.\n\t\t\t\t//\t\tThat's a memory leak. Probably not particularly severe in most cases but still.\n\t\t\t\tpersistedEntityDataStore.delete(id.uniqueValue)\n\t\t\t\tif (subTreeType === 'single') {\n\t\t\t\t\tsubTreeDataStore.delete(subTreePlaceholder)\n\t\t\t\t} else if (subTreeType === 'list') {\n\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\tif (!(list instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tlist.delete(id.value)\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t\treturn assertNever(operation)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static processEntityData(entityMap: PersistedEntityDataStore, entityData: ReceivedEntityData, fields: EntityFieldMarkers): ServerId {\n\t\tconst id = this.extractId(entityData)\n\t\tconst presentEntityData = entityMap.get(id.uniqueValue) ?? new Map()\n\t\tentityMap.set(id.uniqueValue, presentEntityData)\n\n\t\tfor (const [placeholder, field] of fields) {\n\t\t\tconst value = entityData[placeholder]\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tpresentEntityData.set(placeholder, value)\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tif (value === null) {\n\t\t\t\t\tpresentEntityData.set(placeholder, null)\n\t\t\t\t} else {\n\t\t\t\t\tpresentEntityData.set(placeholder, this.processEntityData(entityMap, value as ReceivedEntityData, field.fields.markers))\n\t\t\t\t}\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\tconst ids = presentEntityData.get(placeholder) ?? new Set()\n\t\t\t\tpresentEntityData.set(placeholder, ids)\n\t\t\t\tif (!(ids instanceof Set)) {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tids.clear()\n\t\t\t\tfor (const row of value as ReceivedEntityData[]) {\n\t\t\t\t\tconst id = this.processEntityData(entityMap, row, field.fields.markers)\n\t\t\t\t\tids.add(id.value)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthrow new Error()\n\t\t\t}\n\t\t}\n\n\t\treturn id\n\t}\n\n\tprivate static extractId(entityData: ReceivedEntityData): ServerId {\n\t\tconst primaryKey: EntityId | undefined = entityData[PRIMARY_KEY_NAME]\n\n\t\tif (primaryKey === undefined) {\n\t\t\tthrow new BindingError(`The server has responded with an entity that lacks a primary key.`)\n\t\t}\n\n\t\treturn new ServerId(primaryKey, entityData.__typename)\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;AAsBO,MAAM,0BAA0B;AAAA,SACxB,qBAC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AA,QACxH;AAAA,MAAA,WACU,iBAAiB,uBAAuB;AAClD,cAAM,MAAM,kBAAkB,IAAI,WAAW,yBAAS;AACpC,0BAAA,IAAI,aAAa,GAAG;AAClC,YAAA,iBAAiB,MAAM;AAC1B,gBAAM,IAAI,aAAa;AAAA,QACxB;AACA,YAAI,MAAM;AACV,mBAAW,OAAO,OAA+B;AAChD,gBAAM,MAAK,KAAK,kBAAkB,WAAW,KAAK,MAAM,OAAO,OAAO;AAClE,cAAA,IAAI,IAAG,KAAK;AAAA,QACjB;AAAA,MAAA,OACM;AACN,cAAM,IAAI,MAAM;AAAA,MACjB;AAAA,IACD;AAEO,WAAA;AAAA,EACR;AAAA,SAEe,UAAU,YAA0C;AAClE,UAAM,aAAmC,WAAW;AAEpD,QAAI,eAAe,QAAW;AACvB,YAAA,IAAI,aAAa,mEAAmE;AAAA,IAC3F;AAEA,WAAO,IAAI,SAAS,YAAY,WAAW,UAAU;AAAA,EACtD;AACD;;"}
1
+ {"version":3,"file":"RequestResponseNormalizer.js","sources":["../../../src/core/RequestResponseNormalizer.ts"],"sourcesContent":["import {\n\tNormalizedPersistedData,\n\tPersistedEntityDataStore,\n\tReceivedDataTree,\n\tReceivedEntityData,\n\tServerId,\n} from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport { PRIMARY_KEY_NAME } from '../bindingTypes'\nimport { EntityId } from '../treeParameters'\nimport {\n\tEntityFieldMarkers,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n} from '../markers'\nimport { SubMutationOperation } from './MutationGenerator'\nimport { assertNever } from '../utils'\n\nexport class RequestResponseNormalizer {\n\tpublic static mergeInQueryResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t\tmarkerTree: MarkerTreeRoot,\n\t): void {\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\n\t\tfor (const [placeholder, marker] of markerTree.subTrees) {\n\t\t\tconst data = newPersistedData[placeholder] ?? null\n\t\t\tif (marker instanceof EntitySubTreeMarker) {\n\t\t\t\tif (data === null) {\n\t\t\t\t\tsubTreeDataStore.delete(placeholder)\n\t\t\t\t} else {\n\t\t\t\t\tif (Array.isArray(data)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, data, marker.fields.markers)\n\t\t\t\t\tsubTreeDataStore.set(placeholder, id)\n\t\t\t\t}\n\t\t\t} else if (EntityListSubTreeMarker) {\n\t\t\t\tconst subTreeListIds = new Set<EntityId>()\n\t\t\t\tif (!Array.isArray(data)) {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tfor (const row of data) {\n\t\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, row, marker.fields.markers)\n\t\t\t\t\tsubTreeListIds.add(id.value)\n\t\t\t\t}\n\t\t\t\tsubTreeDataStore.set(placeholder, subTreeListIds)\n\t\t\t} else {\n\t\t\t\tthrow new BindingError()\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static mergeInMutationResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t\toperations: SubMutationOperation[],\n\t): void {\n\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\n\t\tfor (const operation of operations) {\n\t\t\tconst { subTreePlaceholder, subTreeType, alias } = operation\n\n\t\t\tconst receivedData = newPersistedData[alias]\n\t\t\tif (!receivedData || Array.isArray(receivedData)) {\n\t\t\t\tthrow new BindingError()\n\t\t\t}\n\n\t\t\tif (operation.type === 'update' || operation.type === 'create') {\n\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, receivedData, operation.markers)\n\t\t\t\tif (subTreeType === 'single') {\n\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, id)\n\t\t\t\t} else if (subTreeType === 'list') {\n\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\tif (list instanceof Set) {\n\t\t\t\t\t\t// TODO this is somewhat dubious because we're essentially just guessing the order of the entities\n\t\t\t\t\t\t//\t\tand just carelessly put the new one at the end.\n\t\t\t\t\t\tlist.add(id.value)\n\t\t\t\t\t} else if (list === undefined) {\n\t\t\t\t\t\t// That's fine. This is probably just an isCreating sub-tree.\n\t\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, new Set([id.value]))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t}\n\t\t\t} else if (operation.type === 'delete') {\n\t\t\t\tconst id = this.extractId(receivedData)\n\t\t\t\t// TODO there are potentially some references to entityId that this whole process won't quite remove.\n\t\t\t\t//\t\tThat's a memory leak. Probably not particularly severe in most cases but still.\n\t\t\t\tpersistedEntityDataStore.delete(id.uniqueValue)\n\t\t\t\tif (subTreeType === 'single') {\n\t\t\t\t\tsubTreeDataStore.delete(subTreePlaceholder)\n\t\t\t\t} else if (subTreeType === 'list') {\n\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\tif (!(list instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tlist.delete(id.value)\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t\treturn assertNever(operation)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static processEntityData(entityMap: PersistedEntityDataStore, entityData: ReceivedEntityData, fields: EntityFieldMarkers): ServerId {\n\t\tconst id = this.extractId(entityData)\n\t\tconst presentEntityData = entityMap.get(id.uniqueValue) ?? new Map()\n\t\tentityMap.set(id.uniqueValue, presentEntityData)\n\n\t\tfor (const [placeholder, field] of fields) {\n\t\t\tconst value = entityData[placeholder]\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tpresentEntityData.set(placeholder, value)\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tif (value === null) {\n\t\t\t\t\tpresentEntityData.set(placeholder, null)\n\t\t\t\t} else {\n\t\t\t\t\tpresentEntityData.set(placeholder, this.processEntityData(entityMap, value as ReceivedEntityData, field.fields.markers))\n\t\t\t\t}\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\tconst ids = presentEntityData.get(placeholder) ?? new Set()\n\t\t\t\tpresentEntityData.set(placeholder, ids)\n\t\t\t\tif (!(ids instanceof Set)) {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tids.clear()\n\t\t\t\tfor (const row of value as ReceivedEntityData[]) {\n\t\t\t\t\tconst id = this.processEntityData(entityMap, row, field.fields.markers)\n\t\t\t\t\tids.add(id.value)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthrow new Error()\n\t\t\t}\n\t\t}\n\n\t\treturn id\n\t}\n\n\tprivate static extractId(entityData: ReceivedEntityData): ServerId {\n\t\tconst primaryKey: EntityId | undefined = entityData[PRIMARY_KEY_NAME]\n\n\t\tif (primaryKey === undefined) {\n\t\t\tthrow new BindingError(`The server has responded with an entity that lacks a primary key.`)\n\t\t}\n\n\t\treturn new ServerId(primaryKey, entityData.__typename)\n\t}\n}\n"],"names":["id"],"mappings":";;;;;;;;;AAsBO,MAAM,0BAA0B;AAAA,EACtC,OAAc,qBACb,UACA,kBACA,YACO;AACD,UAAA,EAAE,kBAAkB,yBAA6B,IAAA;AAEvD,eAAW,CAAC,aAAa,MAAM,KAAK,WAAW,UAAU;AAClD,YAAA,OAAO,iBAAiB,gBAAgB;AAC9C,UAAI,kBAAkB,qBAAqB;AAC1C,YAAI,SAAS,MAAM;AAClB,2BAAiB,OAAO,WAAW;AAAA,QAAA,OAC7B;AACF,cAAA,MAAM,QAAQ,IAAI,GAAG;AACxB,kBAAM,IAAI,aAAa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,kBAAkB,WAAW,KAAK,MAAM,OAAO,OAAO;AAClE,cAAA,IAAIA,IAAG,KAAK;AAAA,QACjB;AAAA,MAAA,OACM;AACN,cAAM,IAAI,MAAM;AAAA,MACjB;AAAA,IACD;AAEO,WAAA;AAAA,EACR;AAAA,EAEA,OAAe,UAAU,YAA0C;AAClE,UAAM,aAAmC,WAAW;AAEpD,QAAI,eAAe,QAAW;AACvB,YAAA,IAAI,aAAa,mEAAmE;AAAA,IAC3F;AAEA,WAAO,IAAI,SAAS,YAAY,WAAW,UAAU;AAAA,EACtD;AACD;"}
@@ -38,13 +38,23 @@ class StateInitializer {
38
38
  const persistedRootData = this.treeStore.subTreePersistedData.get(tree.placeholderName);
39
39
  if (tree instanceof EntityListSubTreeMarker) {
40
40
  const persistedEntityIds = persistedRootData instanceof Set ? persistedRootData : /* @__PURE__ */ new Set();
41
- subTreeState = this.initializeEntityListState({ marker: tree, parent: void 0 }, tree.entityName, persistedEntityIds);
41
+ subTreeState = this.initializeEntityListState(
42
+ { marker: tree, parent: void 0 },
43
+ tree.entityName,
44
+ persistedEntityIds
45
+ );
42
46
  } else {
43
- subTreeState = this.materializeEntityRealm(this.initializeEntityRealm(persistedRootData instanceof ServerId ? persistedRootData : new UnpersistedEntityDummyId(), tree.entityName, {
44
- type: "subTree",
45
- marker: tree,
46
- parent: void 0
47
- }));
47
+ subTreeState = this.materializeEntityRealm(
48
+ this.initializeEntityRealm(
49
+ persistedRootData instanceof ServerId ? persistedRootData : new UnpersistedEntityDummyId(),
50
+ tree.entityName,
51
+ {
52
+ type: "subTree",
53
+ marker: tree,
54
+ parent: void 0
55
+ }
56
+ )
57
+ );
48
58
  }
49
59
  return subTreeState;
50
60
  }
@@ -123,7 +133,19 @@ class StateInitializer {
123
133
  getAccessor: () => {
124
134
  if (entityRealm.accessor === void 0) {
125
135
  const entity2 = entityRealm.entity;
126
- entityRealm.accessor = new EntityAccessor(entityRealm, this.entityOperations, entity2.id, entityRealm.realmKey, entity2.entityName, entityRealm.children, this.treeStore.persistedEntityData.get(entity2.id.uniqueValue), entityRealm.unpersistedChangesCount !== 0, entityRealm.errors, getEntityMarker(entityRealm).environment, entityRealm.getAccessor);
136
+ entityRealm.accessor = new EntityAccessor(
137
+ entityRealm,
138
+ this.entityOperations,
139
+ entity2.id,
140
+ entityRealm.realmKey,
141
+ entity2.entityName,
142
+ entityRealm.children,
143
+ this.treeStore.persistedEntityData.get(entity2.id.uniqueValue),
144
+ entityRealm.unpersistedChangesCount !== 0,
145
+ entityRealm.errors,
146
+ getEntityMarker(entityRealm).environment,
147
+ entityRealm.getAccessor
148
+ );
127
149
  }
128
150
  return entityRealm.accessor;
129
151
  }
@@ -208,17 +230,30 @@ class StateInitializer {
208
230
  getAccessor: () => {
209
231
  if (entityListState.accessor === void 0) {
210
232
  const persistedEntityIds = this.treeStore.getEntityListPersistedIds(entityListState);
211
- entityListState.accessor = new EntityListAccessor(entityListState, this.listOperations, entityListState.children, persistedEntityIds, entityListState.unpersistedChangesCount !== 0, entityListState.errors, entityListState.blueprint.marker.environment, entityListState.getAccessor);
233
+ entityListState.accessor = new EntityListAccessor(
234
+ entityListState,
235
+ this.listOperations,
236
+ entityListState.children,
237
+ persistedEntityIds,
238
+ entityListState.unpersistedChangesCount !== 0,
239
+ entityListState.errors,
240
+ entityListState.blueprint.marker.environment,
241
+ entityListState.getAccessor
242
+ );
212
243
  }
213
244
  return entityListState.accessor;
214
245
  }
215
246
  };
216
247
  const initialData = initialEntityIds.size === 0 ? Array.from({ length: blueprint.marker.parameters.initialEntityCount }) : initialEntityIds;
217
248
  for (const entityId of initialData) {
218
- this.initializeEntityRealm(entityId ? new ServerId(entityId, entityName) : new UnpersistedEntityDummyId(), entityListState.entityName, {
219
- type: "listEntity",
220
- parent: entityListState
221
- });
249
+ this.initializeEntityRealm(
250
+ entityId ? new ServerId(entityId, entityName) : new UnpersistedEntityDummyId(),
251
+ entityListState.entityName,
252
+ {
253
+ type: "listEntity",
254
+ parent: entityListState
255
+ }
256
+ );
222
257
  }
223
258
  this.eventManager.registerNewlyInitialized(entityListState);
224
259
  return entityListState;
@@ -239,14 +274,20 @@ class StateInitializer {
239
274
  hasUnpersistedChanges: copyFromState?.hasUnpersistedChanges ?? false,
240
275
  getAccessor: () => {
241
276
  if (fieldState.accessor === void 0) {
242
- const fieldSchema = this.treeStore.schema.getEntityField(parent.entity.entityName, fieldMarker.fieldName);
243
- if (!fieldSchema) {
244
- throw new BindingError(`Unknown field ${parent.entity.entityName}.${fieldMarker.fieldName}.`);
245
- }
246
- if (fieldSchema.__typename !== "_Column") {
247
- throw new BindingError(`Invalid type of field ${parent.entity.entityName}.${fieldMarker.fieldName}. Expected '_Column', '${fieldSchema.__typename}' found.`);
248
- }
249
- fieldState.accessor = new FieldAccessor(fieldState, this.fieldOperations, fieldState.placeholderName, fieldState.value, fieldState.persistedValue === void 0 ? null : fieldState.persistedValue, fieldState.fieldMarker.defaultValue, fieldState.errors, fieldState.hasUnpersistedChanges, fieldState.touchLog, fieldState.getAccessor, fieldSchema);
277
+ const fieldSchema = this.treeStore.schema.getEntityColumn(parent.entity.entityName, fieldMarker.fieldName);
278
+ fieldState.accessor = new FieldAccessor(
279
+ fieldState,
280
+ this.fieldOperations,
281
+ fieldState.placeholderName,
282
+ fieldState.value,
283
+ fieldState.persistedValue === void 0 ? null : fieldState.persistedValue,
284
+ fieldState.fieldMarker.defaultValue,
285
+ fieldState.errors,
286
+ fieldState.hasUnpersistedChanges,
287
+ fieldState.touchLog,
288
+ fieldState.getAccessor,
289
+ fieldSchema
290
+ );
250
291
  }
251
292
  return fieldState.accessor;
252
293
  }
@@ -256,28 +297,42 @@ class StateInitializer {
256
297
  }
257
298
  initializeFromFieldMarker(parent, field, persistedValue, copyFromState) {
258
299
  if (persistedValue instanceof Set) {
259
- throw new BindingError(`Received a collection of referenced entities where a single '${field.fieldName}' field was expected. Perhaps you wanted to use a <Repeater />?`);
300
+ throw new BindingError(
301
+ `Received a collection of referenced entities where a single '${field.fieldName}' field was expected. Perhaps you wanted to use a <Repeater />?`
302
+ );
260
303
  }
261
304
  if (persistedValue instanceof ServerId) {
262
- throw new BindingError(`Received a referenced entity where a single '${field.fieldName}' field was expected. Perhaps you wanted to use <HasOne />?`);
305
+ throw new BindingError(
306
+ `Received a referenced entity where a single '${field.fieldName}' field was expected. Perhaps you wanted to use <HasOne />?`
307
+ );
263
308
  }
264
- parent.children.set(field.placeholderName, this.initializeFieldState(parent, field.placeholderName, field, persistedValue, copyFromState));
309
+ parent.children.set(
310
+ field.placeholderName,
311
+ this.initializeFieldState(parent, field.placeholderName, field, persistedValue, copyFromState)
312
+ );
265
313
  }
266
314
  initializeFromHasOneRelationMarker(parent, field, entityId, copyFrom) {
267
- parent.children.set(field.placeholderName, this.initializeEntityRealm(entityId, this.getRelationTargetEntityName(parent, field), {
268
- type: "hasOne",
269
- parent,
270
- marker: field
271
- }, copyFrom));
315
+ parent.children.set(
316
+ field.placeholderName,
317
+ this.initializeEntityRealm(entityId, this.getRelationTargetEntityName(parent, field), {
318
+ type: "hasOne",
319
+ parent,
320
+ marker: field
321
+ }, copyFrom)
322
+ );
272
323
  }
273
324
  initializeFromHasManyRelationMarker(parent, field, persistedEntityIds) {
274
- parent.children.set(field.placeholderName, this.initializeEntityListState({ marker: field, parent }, this.getRelationTargetEntityName(parent, field), persistedEntityIds));
325
+ parent.children.set(
326
+ field.placeholderName,
327
+ this.initializeEntityListState(
328
+ { marker: field, parent },
329
+ this.getRelationTargetEntityName(parent, field),
330
+ persistedEntityIds
331
+ )
332
+ );
275
333
  }
276
334
  getRelationTargetEntityName(entityRealm, field) {
277
- const targetField = this.treeStore.schema.getEntityField(entityRealm.entity.entityName, field.parameters.field);
278
- if (targetField?.__typename !== "_Relation") {
279
- throw new BindingError();
280
- }
335
+ const targetField = this.treeStore.schema.getEntityRelation(entityRealm.entity.entityName, field.parameters.field);
281
336
  return targetField.targetEntity;
282
337
  }
283
338
  runImmediateUserInitialization(realm, initialize) {
@@ -325,5 +380,7 @@ class StateInitializer {
325
380
  return void 0;
326
381
  }
327
382
  }
328
- export { StateInitializer };
383
+ export {
384
+ StateInitializer
385
+ };
329
386
  //# sourceMappingURL=StateInitializer.js.map
@@ -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,KAAK,YACL;AAAA,QACC,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,QAAQ;AAAA,MAEV,CAAA,CACD;AAAA,IACD;AAEO,WAAA;AAAA,EACR;AAAA,EAEO,sBACN,IACA,YACA,WACA,UAC0C;AAK1C,UAAM,SAAS,KAAK,sBAAsB,IAAI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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,UAAU,qBAAqB,IAAI,KAAK,eAAe;AAEtF,QAAI,gBAAgB,yBAAyB;AAC5C,YAAM,qBAAoC,6BAA6B,MAAM,wCAAwB,IAAI;AACzG,qBAAe,KAAK;AAAA,QACnB,EAAE,QAAQ,MAAM,QAAQ,OAAU;AAAA,QAClC,KAAK;AAA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ummyId, 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