@contember/binding 1.1.0-beta.4 → 1.1.0-rc.12

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 (359) hide show
  1. package/dist/development/accessorPropagation/AccessorProvider.js +7 -14
  2. package/dist/development/accessorPropagation/AccessorProvider.js.map +1 -1
  3. package/dist/development/accessorPropagation/BindingOperationsProvider.js +3 -7
  4. package/dist/development/accessorPropagation/BindingOperationsProvider.js.map +1 -1
  5. package/dist/development/accessorPropagation/EntityKeyProvider.js +3 -7
  6. package/dist/development/accessorPropagation/EntityKeyProvider.js.map +1 -1
  7. package/dist/development/accessorPropagation/EnvironmentContext.js +39 -56
  8. package/dist/development/accessorPropagation/EnvironmentContext.js.map +1 -1
  9. package/dist/development/accessorPropagation/TreeRootIdProvider.js +3 -7
  10. package/dist/development/accessorPropagation/TreeRootIdProvider.js.map +1 -1
  11. package/dist/development/accessorSorting/SetOrderFieldOnCreate.js +104 -89
  12. package/dist/development/accessorSorting/SetOrderFieldOnCreate.js.map +1 -1
  13. package/dist/development/accessorSorting/errors.js.map +1 -1
  14. package/dist/development/accessorSorting/useSortedEntities.js +15 -18
  15. package/dist/development/accessorSorting/useSortedEntities.js.map +1 -1
  16. package/dist/development/accessorTree/AccessorTree.js +20 -39
  17. package/dist/development/accessorTree/AccessorTree.js.map +1 -1
  18. package/dist/development/accessorTree/RuntimeId.js +1 -1
  19. package/dist/development/accessorTree/RuntimeId.js.map +1 -1
  20. package/dist/development/accessorTree/accessorTreeStateReducer.js.map +1 -1
  21. package/dist/development/core/AccessorErrorManager.js +6 -6
  22. package/dist/development/core/AccessorErrorManager.js.map +1 -1
  23. package/dist/development/core/Config.js.map +1 -1
  24. package/dist/development/core/DataBinding.js +16 -16
  25. package/dist/development/core/DataBinding.js.map +1 -1
  26. package/dist/development/core/DirtinessTracker.js.map +1 -1
  27. package/dist/development/core/EventManager.js +11 -11
  28. package/dist/development/core/EventManager.js.map +1 -1
  29. package/dist/development/core/IncrementalMarkerBuilder.js +5 -5
  30. package/dist/development/core/IncrementalMarkerBuilder.js.map +1 -1
  31. package/dist/development/core/MarkerTreeGenerator.js +6 -6
  32. package/dist/development/core/MarkerTreeGenerator.js.map +1 -1
  33. package/dist/development/core/MutationGenerator.js +18 -12
  34. package/dist/development/core/MutationGenerator.js.map +1 -1
  35. package/dist/development/core/RealmKeyGenerator.js +2 -2
  36. package/dist/development/core/RealmKeyGenerator.js.map +1 -1
  37. package/dist/development/core/StateInitializer.js +8 -8
  38. package/dist/development/core/StateInitializer.js.map +1 -1
  39. package/dist/development/core/TreeAugmenter.js.map +1 -1
  40. package/dist/development/core/TreeParameterMerger.js.map +1 -1
  41. package/dist/development/core/TreeStore.js +7 -7
  42. package/dist/development/core/TreeStore.js.map +1 -1
  43. package/dist/development/core/exceptions/ErrorLocator.js +3 -3
  44. package/dist/development/core/exceptions/ErrorLocator.js.map +1 -1
  45. package/dist/development/core/schema/SchemaLoader.js +2 -2
  46. package/dist/development/core/schema/SchemaLoader.js.map +1 -1
  47. package/dist/development/core/state/StateIterator.js.map +1 -1
  48. package/dist/development/coreComponents/Component.js.map +1 -1
  49. package/dist/development/coreComponents/DataBindingProvider.js +11 -11
  50. package/dist/development/coreComponents/DataBindingProvider.js.map +1 -1
  51. package/dist/development/coreComponents/Entity.js +11 -15
  52. package/dist/development/coreComponents/Entity.js.map +1 -1
  53. package/dist/development/coreComponents/EntityList.js +35 -31
  54. package/dist/development/coreComponents/EntityList.js.map +1 -1
  55. package/dist/development/coreComponents/EntityListSubTree.js +41 -41
  56. package/dist/development/coreComponents/EntityListSubTree.js.map +1 -1
  57. package/dist/development/coreComponents/EntitySubTree.js +63 -51
  58. package/dist/development/coreComponents/EntitySubTree.js.map +1 -1
  59. package/dist/development/coreComponents/Field.js +28 -20
  60. package/dist/development/coreComponents/Field.js.map +1 -1
  61. package/dist/development/coreComponents/HasMany.js +30 -33
  62. package/dist/development/coreComponents/HasMany.js.map +1 -1
  63. package/dist/development/coreComponents/HasOne.js +30 -33
  64. package/dist/development/coreComponents/HasOne.js.map +1 -1
  65. package/dist/development/coreComponents/ParentEntity.js +12 -6
  66. package/dist/development/coreComponents/ParentEntity.js.map +1 -1
  67. package/dist/development/dao/Environment.js +1 -1
  68. package/dist/development/dao/Environment.js.map +1 -1
  69. package/dist/development/fieldHelpers/helpers/FieldHelper.js +1 -1
  70. package/dist/development/fieldHelpers/helpers/FieldHelper.js.map +1 -1
  71. package/dist/development/helperComponents/DeferredSubTrees.js +83 -86
  72. package/dist/development/helperComponents/DeferredSubTrees.js.map +1 -1
  73. package/dist/development/helperComponents/EntityView.js +5 -3
  74. package/dist/development/helperComponents/EntityView.js.map +1 -1
  75. package/dist/development/helperComponents/FieldView.js +50 -36
  76. package/dist/development/helperComponents/FieldView.js.map +1 -1
  77. package/dist/development/helperComponents/If.js +70 -63
  78. package/dist/development/helperComponents/If.js.map +1 -1
  79. package/dist/development/helperComponents/StaticRender.js +9 -5
  80. package/dist/development/helperComponents/StaticRender.js.map +1 -1
  81. package/dist/development/helperComponents/SugaredField.js +6 -13
  82. package/dist/development/helperComponents/SugaredField.js.map +1 -1
  83. package/dist/development/helperComponents/helpers/FilterEvaluator.js.map +1 -1
  84. package/dist/development/markers/EntityListSubTreeMarker.js +2 -2
  85. package/dist/development/markers/EntityListSubTreeMarker.js.map +1 -1
  86. package/dist/development/markers/EntitySubTreeMarker.js +2 -2
  87. package/dist/development/markers/EntitySubTreeMarker.js.map +1 -1
  88. package/dist/development/markers/FieldMarker.js +2 -2
  89. package/dist/development/markers/FieldMarker.js.map +1 -1
  90. package/dist/development/markers/HasManyRelationMarker.js +3 -3
  91. package/dist/development/markers/HasManyRelationMarker.js.map +1 -1
  92. package/dist/development/markers/HasOneRelationMarker.js +2 -2
  93. package/dist/development/markers/HasOneRelationMarker.js.map +1 -1
  94. package/dist/development/queryLanguage/CacheStore.js +1 -1
  95. package/dist/development/queryLanguage/CacheStore.js.map +1 -1
  96. package/dist/development/queryLanguage/Parser.js +7 -7
  97. package/dist/development/queryLanguage/Parser.js.map +1 -1
  98. package/dist/development/queryLanguage/QueryLanguage.js +6 -6
  99. package/dist/development/queryLanguage/QueryLanguage.js.map +1 -1
  100. package/dist/development/structures/BijectiveIndexedMap.js +1 -1
  101. package/dist/development/structures/BijectiveIndexedMap.js.map +1 -1
  102. package/dist/development/structures/LRUCache.js +1 -1
  103. package/dist/development/structures/LRUCache.js.map +1 -1
  104. package/dist/development/structures/WeakIdCache.js.map +1 -1
  105. package/dist/production/accessorPropagation/AccessorProvider.js +2 -8
  106. package/dist/production/accessorPropagation/AccessorProvider.js.map +1 -1
  107. package/dist/production/accessorPropagation/BindingOperationsProvider.js +2 -5
  108. package/dist/production/accessorPropagation/BindingOperationsProvider.js.map +1 -1
  109. package/dist/production/accessorPropagation/EntityKeyProvider.js +2 -5
  110. package/dist/production/accessorPropagation/EntityKeyProvider.js.map +1 -1
  111. package/dist/production/accessorPropagation/EnvironmentContext.js +23 -43
  112. package/dist/production/accessorPropagation/EnvironmentContext.js.map +1 -1
  113. package/dist/production/accessorPropagation/TreeRootIdProvider.js +2 -5
  114. package/dist/production/accessorPropagation/TreeRootIdProvider.js.map +1 -1
  115. package/dist/production/accessorSorting/SetOrderFieldOnCreate.js +62 -62
  116. package/dist/production/accessorSorting/SetOrderFieldOnCreate.js.map +1 -1
  117. package/dist/production/accessorSorting/errors.js.map +1 -1
  118. package/dist/production/accessorSorting/useSortedEntities.js +15 -18
  119. package/dist/production/accessorSorting/useSortedEntities.js.map +1 -1
  120. package/dist/production/accessorTree/AccessorTree.js +3 -21
  121. package/dist/production/accessorTree/AccessorTree.js.map +1 -1
  122. package/dist/production/accessorTree/RuntimeId.js +1 -1
  123. package/dist/production/accessorTree/RuntimeId.js.map +1 -1
  124. package/dist/production/accessorTree/accessorTreeStateReducer.js.map +1 -1
  125. package/dist/production/core/AccessorErrorManager.js +6 -6
  126. package/dist/production/core/AccessorErrorManager.js.map +1 -1
  127. package/dist/production/core/Config.js.map +1 -1
  128. package/dist/production/core/DataBinding.js +16 -16
  129. package/dist/production/core/DataBinding.js.map +1 -1
  130. package/dist/production/core/DirtinessTracker.js.map +1 -1
  131. package/dist/production/core/EventManager.js +11 -11
  132. package/dist/production/core/EventManager.js.map +1 -1
  133. package/dist/production/core/IncrementalMarkerBuilder.js +5 -5
  134. package/dist/production/core/IncrementalMarkerBuilder.js.map +1 -1
  135. package/dist/production/core/MarkerTreeGenerator.js +6 -6
  136. package/dist/production/core/MarkerTreeGenerator.js.map +1 -1
  137. package/dist/production/core/MutationGenerator.js +18 -12
  138. package/dist/production/core/MutationGenerator.js.map +1 -1
  139. package/dist/production/core/RealmKeyGenerator.js +2 -2
  140. package/dist/production/core/RealmKeyGenerator.js.map +1 -1
  141. package/dist/production/core/StateInitializer.js +8 -8
  142. package/dist/production/core/StateInitializer.js.map +1 -1
  143. package/dist/production/core/TreeAugmenter.js.map +1 -1
  144. package/dist/production/core/TreeParameterMerger.js.map +1 -1
  145. package/dist/production/core/TreeStore.js +7 -7
  146. package/dist/production/core/TreeStore.js.map +1 -1
  147. package/dist/production/core/exceptions/ErrorLocator.js +3 -3
  148. package/dist/production/core/exceptions/ErrorLocator.js.map +1 -1
  149. package/dist/production/core/schema/SchemaLoader.js +2 -2
  150. package/dist/production/core/schema/SchemaLoader.js.map +1 -1
  151. package/dist/production/core/state/StateIterator.js.map +1 -1
  152. package/dist/production/coreComponents/Component.js.map +1 -1
  153. package/dist/production/coreComponents/DataBindingProvider.js +10 -9
  154. package/dist/production/coreComponents/DataBindingProvider.js.map +1 -1
  155. package/dist/production/coreComponents/Entity.js +7 -10
  156. package/dist/production/coreComponents/Entity.js.map +1 -1
  157. package/dist/production/coreComponents/EntityList.js +25 -28
  158. package/dist/production/coreComponents/EntityList.js.map +1 -1
  159. package/dist/production/coreComponents/EntityListSubTree.js +29 -28
  160. package/dist/production/coreComponents/EntityListSubTree.js.map +1 -1
  161. package/dist/production/coreComponents/EntitySubTree.js +39 -34
  162. package/dist/production/coreComponents/EntitySubTree.js.map +1 -1
  163. package/dist/production/coreComponents/Field.js +20 -20
  164. package/dist/production/coreComponents/Field.js.map +1 -1
  165. package/dist/production/coreComponents/HasMany.js +18 -20
  166. package/dist/production/coreComponents/HasMany.js.map +1 -1
  167. package/dist/production/coreComponents/HasOne.js +18 -20
  168. package/dist/production/coreComponents/HasOne.js.map +1 -1
  169. package/dist/production/coreComponents/ParentEntity.js +8 -6
  170. package/dist/production/coreComponents/ParentEntity.js.map +1 -1
  171. package/dist/production/dao/Environment.js +1 -1
  172. package/dist/production/dao/Environment.js.map +1 -1
  173. package/dist/production/fieldHelpers/helpers/FieldHelper.js +1 -1
  174. package/dist/production/fieldHelpers/helpers/FieldHelper.js.map +1 -1
  175. package/dist/production/helperComponents/DeferredSubTrees.js +67 -77
  176. package/dist/production/helperComponents/DeferredSubTrees.js.map +1 -1
  177. package/dist/production/helperComponents/EntityView.js +1 -3
  178. package/dist/production/helperComponents/EntityView.js.map +1 -1
  179. package/dist/production/helperComponents/FieldView.js +38 -31
  180. package/dist/production/helperComponents/FieldView.js.map +1 -1
  181. package/dist/production/helperComponents/If.js +40 -52
  182. package/dist/production/helperComponents/If.js.map +1 -1
  183. package/dist/production/helperComponents/StaticRender.js +5 -5
  184. package/dist/production/helperComponents/StaticRender.js.map +1 -1
  185. package/dist/production/helperComponents/SugaredField.js +2 -8
  186. package/dist/production/helperComponents/SugaredField.js.map +1 -1
  187. package/dist/production/helperComponents/helpers/FilterEvaluator.js.map +1 -1
  188. package/dist/production/markers/EntityListSubTreeMarker.js +2 -2
  189. package/dist/production/markers/EntityListSubTreeMarker.js.map +1 -1
  190. package/dist/production/markers/EntitySubTreeMarker.js +2 -2
  191. package/dist/production/markers/EntitySubTreeMarker.js.map +1 -1
  192. package/dist/production/markers/FieldMarker.js +2 -2
  193. package/dist/production/markers/FieldMarker.js.map +1 -1
  194. package/dist/production/markers/HasManyRelationMarker.js +2 -2
  195. package/dist/production/markers/HasManyRelationMarker.js.map +1 -1
  196. package/dist/production/markers/HasOneRelationMarker.js +2 -2
  197. package/dist/production/markers/HasOneRelationMarker.js.map +1 -1
  198. package/dist/production/queryLanguage/CacheStore.js +1 -1
  199. package/dist/production/queryLanguage/CacheStore.js.map +1 -1
  200. package/dist/production/queryLanguage/Parser.js +7 -7
  201. package/dist/production/queryLanguage/Parser.js.map +1 -1
  202. package/dist/production/queryLanguage/QueryLanguage.js +6 -6
  203. package/dist/production/queryLanguage/QueryLanguage.js.map +1 -1
  204. package/dist/production/structures/BijectiveIndexedMap.js +1 -1
  205. package/dist/production/structures/BijectiveIndexedMap.js.map +1 -1
  206. package/dist/production/structures/LRUCache.js +1 -1
  207. package/dist/production/structures/LRUCache.js.map +1 -1
  208. package/dist/production/structures/WeakIdCache.js.map +1 -1
  209. package/dist/types/accessorPropagation/useAccessorUpdateSubscription.d.ts +1 -1
  210. package/dist/types/accessorPropagation/useAccessorUpdateSubscription.d.ts.map +1 -1
  211. package/dist/types/accessorSorting/SortedEntities.d.ts +1 -1
  212. package/dist/types/accessorSorting/SortedEntities.d.ts.map +1 -1
  213. package/dist/types/accessorSorting/errors.d.ts +0 -3
  214. package/dist/types/accessorSorting/errors.d.ts.map +1 -1
  215. package/dist/types/accessorSorting/useSortedEntities.d.ts.map +1 -1
  216. package/dist/types/accessorTree/AccessorTreeState.d.ts +1 -1
  217. package/dist/types/accessorTree/AccessorTreeState.d.ts.map +1 -1
  218. package/dist/types/accessorTree/AccessorTreeStateAction.d.ts +1 -1
  219. package/dist/types/accessorTree/AccessorTreeStateAction.d.ts.map +1 -1
  220. package/dist/types/accessorTree/MutationRequestResponse.d.ts +3 -3
  221. package/dist/types/accessorTree/MutationRequestResponse.d.ts.map +1 -1
  222. package/dist/types/accessorTree/NormalizedPersistedData.d.ts +5 -5
  223. package/dist/types/accessorTree/NormalizedPersistedData.d.ts.map +1 -1
  224. package/dist/types/accessorTree/PersistResult.d.ts +2 -2
  225. package/dist/types/accessorTree/PersistResult.d.ts.map +1 -1
  226. package/dist/types/accessorTree/QueryRequestResponse.d.ts +3 -3
  227. package/dist/types/accessorTree/QueryRequestResponse.d.ts.map +1 -1
  228. package/dist/types/accessorTree/RequestError.d.ts +1 -1
  229. package/dist/types/accessorTree/RequestError.d.ts.map +1 -1
  230. package/dist/types/accessorTree/RuntimeId.d.ts +2 -2
  231. package/dist/types/accessorTree/RuntimeId.d.ts.map +1 -1
  232. package/dist/types/accessors/ExtendTree.d.ts +1 -1
  233. package/dist/types/accessors/ExtendTree.d.ts.map +1 -1
  234. package/dist/types/accessors/GetEntityByKey.d.ts +1 -1
  235. package/dist/types/accessors/GetEntityByKey.d.ts.map +1 -1
  236. package/dist/types/accessors/GetEntityListSubTree.d.ts +1 -1
  237. package/dist/types/accessors/GetEntityListSubTree.d.ts.map +1 -1
  238. package/dist/types/accessors/GetEntitySubTree.d.ts +1 -1
  239. package/dist/types/accessors/GetEntitySubTree.d.ts.map +1 -1
  240. package/dist/types/accessors/Persist.d.ts +1 -1
  241. package/dist/types/accessors/Persist.d.ts.map +1 -1
  242. package/dist/types/accessors/PersistErrorOptions.d.ts +1 -1
  243. package/dist/types/accessors/PersistErrorOptions.d.ts.map +1 -1
  244. package/dist/types/core/MutationGenerator.d.ts +3 -2
  245. package/dist/types/core/MutationGenerator.d.ts.map +1 -1
  246. package/dist/types/core/QueryGenerator.d.ts +1 -1
  247. package/dist/types/core/QueryGenerator.d.ts.map +1 -1
  248. package/dist/types/core/exceptions/RawMarkerPath.d.ts +1 -1
  249. package/dist/types/core/exceptions/RawMarkerPath.d.ts.map +1 -1
  250. package/dist/types/core/schema/RawSchemaEntity.d.ts +1 -1
  251. package/dist/types/core/schema/RawSchemaEntity.d.ts.map +1 -1
  252. package/dist/types/core/schema/SchemaColumnType.d.ts +2 -2
  253. package/dist/types/core/schema/SchemaColumnType.d.ts.map +1 -1
  254. package/dist/types/core/schema/SchemaEntities.d.ts +1 -1
  255. package/dist/types/core/schema/SchemaEntities.d.ts.map +1 -1
  256. package/dist/types/core/schema/SchemaEnums.d.ts +3 -3
  257. package/dist/types/core/schema/SchemaEnums.d.ts.map +1 -1
  258. package/dist/types/core/schema/SchemaField.d.ts +1 -1
  259. package/dist/types/core/schema/SchemaField.d.ts.map +1 -1
  260. package/dist/types/core/schema/SchemaFields.d.ts +1 -1
  261. package/dist/types/core/schema/SchemaFields.d.ts.map +1 -1
  262. package/dist/types/core/schema/SchemaRelation.d.ts +1 -1
  263. package/dist/types/core/schema/SchemaRelation.d.ts.map +1 -1
  264. package/dist/types/core/state/EntityListState.d.ts +1 -1
  265. package/dist/types/core/state/EntityListState.d.ts.map +1 -1
  266. package/dist/types/core/state/EntityRealmState.d.ts +1 -1
  267. package/dist/types/core/state/EntityRealmState.d.ts.map +1 -1
  268. package/dist/types/core/state/StateNode.d.ts +3 -3
  269. package/dist/types/core/state/StateNode.d.ts.map +1 -1
  270. package/dist/types/coreComponents/DataBindingProvider.d.ts +2 -2
  271. package/dist/types/coreComponents/DataBindingProvider.d.ts.map +1 -1
  272. package/dist/types/coreComponents/Entity.d.ts +1 -1
  273. package/dist/types/coreComponents/Entity.d.ts.map +1 -1
  274. package/dist/types/coreComponents/EntityList.d.ts +1 -1
  275. package/dist/types/coreComponents/EntityList.d.ts.map +1 -1
  276. package/dist/types/coreComponents/EntityListSubTree.d.ts +1 -1
  277. package/dist/types/coreComponents/EntityListSubTree.d.ts.map +1 -1
  278. package/dist/types/coreComponents/EntitySubTree.d.ts +2 -2
  279. package/dist/types/coreComponents/EntitySubTree.d.ts.map +1 -1
  280. package/dist/types/coreComponents/HasMany.d.ts +1 -1
  281. package/dist/types/coreComponents/HasMany.d.ts.map +1 -1
  282. package/dist/types/coreComponents/HasOne.d.ts +1 -1
  283. package/dist/types/coreComponents/HasOne.d.ts.map +1 -1
  284. package/dist/types/coreComponents/MarkerProvider.d.ts +3 -3
  285. package/dist/types/coreComponents/MarkerProvider.d.ts.map +1 -1
  286. package/dist/types/helperComponents/FieldView.d.ts +5 -5
  287. package/dist/types/helperComponents/FieldView.d.ts.map +1 -1
  288. package/dist/types/helperComponents/If.d.ts +1 -1
  289. package/dist/types/helperComponents/If.d.ts.map +1 -1
  290. package/dist/types/markers/EntityFieldMarkers.d.ts +2 -2
  291. package/dist/types/markers/EntityFieldMarkers.d.ts.map +1 -1
  292. package/dist/types/markers/EntityFieldPlaceholders.d.ts +1 -1
  293. package/dist/types/markers/EntityFieldPlaceholders.d.ts.map +1 -1
  294. package/dist/types/markers/MeaningfulMarker.d.ts +1 -1
  295. package/dist/types/markers/MeaningfulMarker.d.ts.map +1 -1
  296. package/dist/types/markers/SubTreeMarkers.d.ts +1 -1
  297. package/dist/types/markers/SubTreeMarkers.d.ts.map +1 -1
  298. package/dist/types/queryLanguage/Parser.d.ts.map +1 -1
  299. package/dist/types/queryLanguage/QueryLanguage.d.ts +2 -3
  300. package/dist/types/queryLanguage/QueryLanguage.d.ts.map +1 -1
  301. package/dist/types/treeParameters/EntityListEventListeners.d.ts +4 -4
  302. package/dist/types/treeParameters/EntityListEventListeners.d.ts.map +1 -1
  303. package/dist/types/treeParameters/EventListenersStore.d.ts +1 -1
  304. package/dist/types/treeParameters/EventListenersStore.d.ts.map +1 -1
  305. package/dist/types/treeParameters/FieldEventListeners.d.ts +3 -3
  306. package/dist/types/treeParameters/FieldEventListeners.d.ts.map +1 -1
  307. package/dist/types/treeParameters/SetOnCreate.d.ts +2 -2
  308. package/dist/types/treeParameters/SetOnCreate.d.ts.map +1 -1
  309. package/dist/types/treeParameters/SingleEntityEventListeners.d.ts +3 -3
  310. package/dist/types/treeParameters/SingleEntityEventListeners.d.ts.map +1 -1
  311. package/dist/types/treeParameters/primitives/Alias.d.ts +1 -1
  312. package/dist/types/treeParameters/primitives/Alias.d.ts.map +1 -1
  313. package/dist/types/treeParameters/primitives/EntityId.d.ts +1 -1
  314. package/dist/types/treeParameters/primitives/EntityId.d.ts.map +1 -1
  315. package/dist/types/treeParameters/primitives/EntityName.d.ts +1 -1
  316. package/dist/types/treeParameters/primitives/EntityName.d.ts.map +1 -1
  317. package/dist/types/treeParameters/primitives/EntityRealmKey.d.ts +1 -1
  318. package/dist/types/treeParameters/primitives/EntityRealmKey.d.ts.map +1 -1
  319. package/dist/types/treeParameters/primitives/ExpectedEntityCount.d.ts +1 -1
  320. package/dist/types/treeParameters/primitives/ExpectedEntityCount.d.ts.map +1 -1
  321. package/dist/types/treeParameters/primitives/ExpectedQualifiedEntityMutation.d.ts +1 -1
  322. package/dist/types/treeParameters/primitives/ExpectedQualifiedEntityMutation.d.ts.map +1 -1
  323. package/dist/types/treeParameters/primitives/ExpectedRelationMutation.d.ts +1 -1
  324. package/dist/types/treeParameters/primitives/ExpectedRelationMutation.d.ts.map +1 -1
  325. package/dist/types/treeParameters/primitives/FieldName.d.ts +1 -1
  326. package/dist/types/treeParameters/primitives/FieldName.d.ts.map +1 -1
  327. package/dist/types/treeParameters/primitives/FieldValue.d.ts +2 -2
  328. package/dist/types/treeParameters/primitives/FieldValue.d.ts.map +1 -1
  329. package/dist/types/treeParameters/primitives/Filter.d.ts +2 -2
  330. package/dist/types/treeParameters/primitives/Filter.d.ts.map +1 -1
  331. package/dist/types/treeParameters/primitives/Json.d.ts +1 -1
  332. package/dist/types/treeParameters/primitives/Json.d.ts.map +1 -1
  333. package/dist/types/treeParameters/primitives/Limit.d.ts +1 -1
  334. package/dist/types/treeParameters/primitives/Limit.d.ts.map +1 -1
  335. package/dist/types/treeParameters/primitives/Offset.d.ts +1 -1
  336. package/dist/types/treeParameters/primitives/Offset.d.ts.map +1 -1
  337. package/dist/types/treeParameters/primitives/OrderBy.d.ts +2 -2
  338. package/dist/types/treeParameters/primitives/OrderBy.d.ts.map +1 -1
  339. package/dist/types/treeParameters/primitives/PlaceholderName.d.ts +1 -1
  340. package/dist/types/treeParameters/primitives/PlaceholderName.d.ts.map +1 -1
  341. package/dist/types/treeParameters/primitives/RemovalType.d.ts +1 -1
  342. package/dist/types/treeParameters/primitives/RemovalType.d.ts.map +1 -1
  343. package/dist/types/treeParameters/primitives/Scalar.d.ts +1 -1
  344. package/dist/types/treeParameters/primitives/Scalar.d.ts.map +1 -1
  345. package/dist/types/treeParameters/primitives/TreeRootId.d.ts +1 -1
  346. package/dist/types/treeParameters/primitives/TreeRootId.d.ts.map +1 -1
  347. package/dist/types/treeParameters/primitives/UniqueWhere.d.ts +2 -2
  348. package/dist/types/treeParameters/primitives/UniqueWhere.d.ts.map +1 -1
  349. package/dist/types/tsconfig.tsbuildinfo +1 -1
  350. package/package.json +16 -14
  351. package/src/accessorSorting/SortedEntities.ts +1 -1
  352. package/src/accessorSorting/errors.ts +0 -7
  353. package/src/accessorSorting/useSortedEntities.ts +15 -18
  354. package/src/accessorTree/MutationRequestResponse.ts +1 -1
  355. package/src/core/MutationGenerator.ts +16 -5
  356. package/src/core/TreeParameterMerger.ts +2 -2
  357. package/src/dao/Environment.ts +1 -1
  358. package/src/queryLanguage/Parser.ts +3 -3
  359. package/LICENSE +0 -186
@@ -1 +1 @@
1
- {"version":3,"file":"MutationGenerator.js","sources":["../../../src/core/MutationGenerator.ts"],"sourcesContent":["// noinspection JSVoidFunctionReturnValueUsed // IntelliJ seems to be super confused througouht this file.\n\nimport { CrudQueryBuilder, GraphQlBuilder } from '@contember/client'\nimport { ClientGeneratedUuid, ServerId } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '../bindingTypes'\nimport { EntityFieldMarkers, FieldMarker, HasManyRelationMarker, HasOneRelationMarker } from '../markers'\nimport type { EntityId, EntityName, FieldValue, PlaceholderName } from '../treeParameters'\nimport { assertNever, isEmptyObject } from '../utils'\nimport { QueryGenerator } from './QueryGenerator'\nimport { MutationAlias } from './requestAliases'\nimport {\n\tEntityListState,\n\tEntityRealmState,\n\tEntityRealmStateStub,\n\tEntityState,\n\tFieldState,\n\tgetEntityMarker,\n\tStateIterator,\n} from './state'\nimport type { TreeStore } from './TreeStore'\n\ntype QueryBuilder = Omit<CrudQueryBuilder.CrudQueryBuilder, CrudQueryBuilder.Queries>\n\ntype ProcessedPlaceholdersByEntity = Map<EntityState, Set<PlaceholderName>>\n\nexport type SubMutationOperation =\n\t& {\n\t\talias: string,\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: 'list' | 'single'\n\t}\n\t& (\n\t\t| { type: 'delete', id: EntityId }\n\t\t| { type: 'update', markers: EntityFieldMarkers, id: EntityId }\n\t\t| { type: 'create', markers: EntityFieldMarkers, id: EntityId }\n\t)\n\nexport type PersistMutationResult = {\n\tquery: string\n\toperations: SubMutationOperation[]\n}\n\n// TODO enforce correct expected mutations in dev mode.\nexport class MutationGenerator {\n\n\tprivate aliasCounter = 1\n\n\tpublic constructor(private readonly treeStore: TreeStore) {\n\t}\n\n\tpublic getPersistMutation(): PersistMutationResult | undefined {\n\t\ttry {\n\t\t\tlet builder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder()\n\t\t\tconst operations: SubMutationOperation[] = []\n\t\t\tconst processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity = new Map()\n\t\t\tconst processedDeletes = new Set<string>()\n\n\n\t\t\tfor (const [treeRootId, rootStates] of this.treeStore.subTreeStatesByRoot.entries()) {\n\t\t\t\tfor (const [placeholderName, subTreeState] of Array.from(rootStates.entries()).reverse()) {\n\t\t\t\t\tif (subTreeState.unpersistedChangesCount <= 0) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif (subTreeState.type === 'entityRealm') {\n\t\t\t\t\t\tconst subMutation = this.addSubMutation(\n\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t'single',\n\t\t\t\t\t\t\tsubTreeState.entity.id.value,\n\t\t\t\t\t\t\tsubTreeState,\n\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tif (subMutation) {\n\t\t\t\t\t\t\tbuilder = subMutation[0]\n\t\t\t\t\t\t\toperations.push(subMutation[1])\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (subTreeState.type === 'entityList') {\n\t\t\t\t\t\tfor (const childState of subTreeState.children.values()) {\n\t\t\t\t\t\t\tif (childState.type === 'entityRealmStub') {\n\t\t\t\t\t\t\t\t// TODO there can be a forceCreate somewhere in there that we're hereby ignoring.\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst subMutation = this.addSubMutation(\n\t\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t\t'list',\n\t\t\t\t\t\t\t\tchildState.entity.id.value,\n\t\t\t\t\t\t\t\tchildState,\n\t\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tif (subMutation) {\n\t\t\t\t\t\t\t\tbuilder = subMutation[0]\n\t\t\t\t\t\t\t\toperations.push(subMutation[1])\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (subTreeState.plannedRemovals) {\n\t\t\t\t\t\t\tfor (const [removedId, removalType] of subTreeState.plannedRemovals) {\n\t\t\t\t\t\t\t\tif (removalType === 'disconnect') {\n\t\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\t\t\t\t\tconst key = `${subTreeState.entityName}#${removedId}`\n\t\t\t\t\t\t\t\t\tif (processedDeletes.has(key)) {\n\t\t\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tprocessedDeletes.add(key)\n\t\t\t\t\t\t\t\t\tconst alias = this.createAlias()\n\t\t\t\t\t\t\t\t\tbuilder = this.addDeleteMutation(\n\t\t\t\t\t\t\t\t\t\tsubTreeState.entityName,\n\t\t\t\t\t\t\t\t\t\tremovedId,\n\t\t\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\toperations.push({ alias, subTreePlaceholder: placeholderName, subTreeType: 'list', type: 'delete', id: removedId })\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tassertNever(removalType)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tassertNever(subTreeState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst query = builder.inTransaction(undefined, { deferForeignKeyConstraints: true }).getGql()\n\t\t\treturn { query, operations }\n\t\t} catch (e) {\n\t\t\treturn undefined\n\t\t}\n\t}\n\n\tprivate addSubMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: 'list' | 'single',\n\t\tentityId: EntityId,\n\t\trealmState: EntityRealmState,\n\t\tqueryBuilder: QueryBuilder,\n\t): [QueryBuilder, SubMutationOperation] | undefined {\n\t\tif (realmState.unpersistedChangesCount === 0) {\n\t\t\t// Bail out early\n\t\t\treturn undefined\n\t\t}\n\t\tconst fieldMarkers = getEntityMarker(realmState).fields.markers\n\n\t\tconst alias = this.createAlias()\n\n\t\tif (realmState.entity.isScheduledForDeletion) {\n\t\t\tconst builder = this.addDeleteMutation(\n\t\t\t\trealmState.entity.entityName,\n\t\t\t\tentityId,\n\t\t\t\talias,\n\t\t\t\tqueryBuilder,\n\t\t\t)\n\t\t\treturn [\n\t\t\t\tbuilder,\n\t\t\t\t{\n\t\t\t\t\talias,\n\t\t\t\t\tsubTreePlaceholder,\n\t\t\t\t\tsubTreeType,\n\t\t\t\t\ttype: 'delete',\n\t\t\t\t\tid: entityId,\n\t\t\t\t},\n\t\t\t]\n\t\t} else if (!realmState.entity.id.existsOnServer) {\n\t\t\tconst builder = this.addCreateMutation(\n\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\trealmState,\n\t\t\t\talias,\n\t\t\t\tthis.getNodeFragmentName(subTreePlaceholder, subTreeType, realmState),\n\t\t\t\tqueryBuilder,\n\t\t\t\tfieldMarkers,\n\t\t\t)\n\t\t\tif (!builder) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn [\n\t\t\t\tbuilder,\n\t\t\t\t{\n\t\t\t\t\talias,\n\t\t\t\t\tsubTreePlaceholder,\n\t\t\t\t\tsubTreeType,\n\t\t\t\t\ttype: 'create',\n\t\t\t\t\tmarkers: fieldMarkers,\n\t\t\t\t\tid: entityId,\n\t\t\t\t},\n]\n\t\t}\n\t\tconst builder = this.addUpdateMutation(\n\t\t\tprocessedPlaceholdersByEntity,\n\t\t\trealmState,\n\t\t\talias,\n\t\t\tthis.getNodeFragmentName(subTreePlaceholder, subTreeType, realmState),\n\t\t\tqueryBuilder,\n\t\t\tfieldMarkers,\n\t\t)\n\t\tif (!builder) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn [\n\t\t\tbuilder,\n\t\t\t{\n\t\t\t\talias,\n\t\t\t\tsubTreePlaceholder,\n\t\t\t\tsubTreeType,\n\t\t\t\ttype: 'update',\n\t\t\t\tid: entityId,\n\t\t\t\tmarkers: fieldMarkers,\n\t\t\t},\n\t\t]\n\t}\n\n\tprivate getNodeFragmentName(\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: 'single' | 'list',\n\t\trealmState: EntityRealmState,\n\t): string | undefined {\n\t\tif (subTreeType !== 'list') {\n\t\t\treturn undefined\n\t\t}\n\t\treturn `${realmState.entity.entityName}_${subTreePlaceholder}`\n\t}\n\n\tprivate addDeleteMutation(\n\t\tentityName: EntityName,\n\t\tdeletedId: EntityId,\n\t\talias: string,\n\t\tqueryBuilder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder(),\n\t): QueryBuilder {\n\t\treturn queryBuilder.delete(\n\t\t\tentityName,\n\t\t\tbuilder =>\n\t\t\t\tbuilder\n\t\t\t\t\t.ok()\n\t\t\t\t\t.node(builder => builder.column(PRIMARY_KEY_NAME))\n\t\t\t\t\t.by({ [PRIMARY_KEY_NAME]: deletedId })\n\t\t\t\t\t.errors()\n\t\t\t\t\t.errorMessage(),\n\t\t\talias,\n\t\t)\n\t}\n\n\tprivate addUpdateMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tentityRealm: EntityRealmState,\n\t\talias: string,\n\t\tnodeFragmentName: string | undefined,\n\t\tqueryBuilder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder(),\n\t\tfieldMarkers: EntityFieldMarkers,\n\t): QueryBuilder | undefined {\n\t\tconst updateBuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Update> =\n\t\t\tthis.registerUpdateMutationPart(\n\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\tentityRealm,\n\t\t\t\tnew CrudQueryBuilder.WriteDataBuilder(),\n\t\t\t)\n\t\tif (updateBuilder.data === undefined || isEmptyObject(updateBuilder.data)) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst runtimeId = entityRealm.entity.id\n\n\t\tif (!runtimeId.existsOnServer) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst readBuilder = QueryGenerator.registerQueryPart(\n\t\t\tfieldMarkers,\n\t\t\tCrudQueryBuilder.ReadBuilder.instantiate(),\n\t\t)\n\n\t\tif (nodeFragmentName) {\n\t\t\tqueryBuilder = queryBuilder.fragment(nodeFragmentName, entityRealm.entity.entityName, readBuilder)\n\t\t}\n\n\t\treturn queryBuilder.update(\n\t\t\tentityRealm.entity.entityName,\n\t\t\tbuilder =>\n\t\t\t\tbuilder\n\t\t\t\t\t.node(nodeFragmentName ? builder => builder.applyFragment(nodeFragmentName) : readBuilder)\n\t\t\t\t\t.data(updateBuilder)\n\t\t\t\t\t.by({ [PRIMARY_KEY_NAME]: runtimeId.value })\n\t\t\t\t\t.ok()\n\t\t\t\t\t.validation()\n\t\t\t\t\t.errors()\n\t\t\t\t\t.errorMessage(),\n\t\t\talias,\n\t\t)\n\t}\n\n\tprivate addCreateMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tentityRealm: EntityRealmState,\n\t\talias: string,\n\t\tnodeFragmentName: string | undefined,\n\t\tqueryBuilder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder(),\n\t\tfieldMarkers: EntityFieldMarkers,\n\t): QueryBuilder | undefined {\n\t\tconst createBuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create> =\n\t\t\tthis.registerCreateMutationPart(\n\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\tentityRealm,\n\t\t\t\tnew CrudQueryBuilder.WriteDataBuilder(),\n\t\t\t)\n\t\tif (createBuilder.data === undefined || isEmptyObject(createBuilder.data)) {\n\t\t\treturn undefined\n\t\t}\n\t\tconst readBuilder = QueryGenerator.registerQueryPart(\n\t\t\tfieldMarkers,\n\t\t\tCrudQueryBuilder.ReadBuilder.instantiate(),\n\t\t)\n\t\tif (nodeFragmentName) {\n\t\t\tqueryBuilder = queryBuilder.fragment(nodeFragmentName, entityRealm.entity.entityName, readBuilder)\n\t\t}\n\n\t\treturn queryBuilder.create(\n\t\t\tentityRealm.entity.entityName,\n\t\t\tbuilder => {\n\t\t\t\t// if (where && writeBuilder.data !== undefined && !isEmptyObject(writeBuilder.data)) {\n\t\t\t\t// \t// Shallow cloning the parameters like this IS too naïve but it will likely last surprisingly long before we\n\t\t\t\t// \t// run into issues.\n\t\t\t\t// \twriteBuilder = new CrudQueryBuilder.WriteDataBuilder({ ...writeBuilder.data, ...where })\n\t\t\t\t// }\n\t\t\t\treturn builder\n\t\t\t\t\t.node(nodeFragmentName ? builder => builder.applyFragment(nodeFragmentName) : readBuilder)\n\t\t\t\t\t.data(createBuilder)\n\t\t\t\t\t.ok()\n\t\t\t\t\t.validation()\n\t\t\t\t\t.errors()\n\t\t\t\t\t.errorMessage()\n\t\t\t},\n\t\t\talias,\n\t\t)\n\t}\n\n\tprivate registerCreateMutationPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tcurrentState: EntityRealmState | EntityRealmStateStub,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create> = new CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>(),\n\t): CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create> {\n\t\tlet processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tprocessedPlaceholdersByEntity.set(currentState.entity, (processedPlaceholders = new Set()))\n\t\t}\n\n\t\tif (currentState.type === 'entityRealmStub') {\n\t\t\t// TODO If there's a forceCreate, this is wrong.\n\t\t\treturn builder\n\t\t}\n\n\t\tfor (const siblingState of StateIterator.eachSiblingRealm(currentState)) {\n\n\t\t\tconst pathBack = this.treeStore.getPathBackToParent(siblingState)\n\n\t\t\tconst nonbearingFields: Array<| { type: 'field'; marker: FieldMarker; fieldState: FieldState }\n\t\t\t\t| { type: 'hasOne'; marker: HasOneRelationMarker; fieldState: EntityRealmState | EntityRealmStateStub }\n\t\t\t\t| { type: 'hasMany'; marker: HasManyRelationMarker; fieldState: EntityListState }> = []\n\n\t\t\tfor (const [placeholderName, fieldState] of siblingState.children) {\n\t\t\t\tif (processedPlaceholders.has(placeholderName)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tprocessedPlaceholders.add(placeholderName)\n\n\t\t\t\tswitch (fieldState.type) {\n\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\tconst marker = fieldState.fieldMarker\n\t\t\t\t\t\tconst placeholderName = marker.placeholderName\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tplaceholderName === TYPENAME_KEY_NAME ||\n\t\t\t\t\t\t\t(placeholderName === PRIMARY_KEY_NAME && !(siblingState.entity.id instanceof ClientGeneratedUuid))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (marker.isNonbearing) {\n\t\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\t\ttype: 'field',\n\t\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbuilder = this.registerCreateFieldPart(fieldState, marker, builder)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'entityRealmStub':\n\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\tconst marker = getEntityMarker(fieldState)\n\t\t\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (marker.parameters.isNonbearing) {\n\t\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\t\ttype: 'hasOne',\n\t\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbuilder = this.registerCreateEntityPart(processedPlaceholdersByEntity, fieldState, marker, builder)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'entityList': {\n\t\t\t\t\t\tconst marker = fieldState.blueprint.marker\n\t\t\t\t\t\tif (!(marker instanceof HasManyRelationMarker)) {\n\t\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (marker.parameters.isNonbearing) {\n\t\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\t\ttype: 'hasMany',\n\t\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbuilder = this.registerCreateEntityListPart(processedPlaceholdersByEntity, fieldState, marker, builder)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// if (\n\t\t\t// \tcurrentState.blueprint.creationParameters.forceCreation &&\n\t\t\t// \t(builder.data === undefined || isEmptyObject(builder.data))\n\t\t\t// ) {\n\t\t\t// \tbuilder = builder.set('_dummy_field_', true)\n\t\t\t// }\n\n\t\t\tif (\n\t\t\t\t(builder.data !== undefined && !isEmptyObject(builder.data)) ||\n\t\t\t\t!getEntityMarker(siblingState).fields.hasAtLeastOneBearingField\n\t\t\t) {\n\t\t\t\tfor (const field of nonbearingFields) {\n\t\t\t\t\tswitch (field.type) {\n\t\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\t\tbuilder = this.registerCreateFieldPart(field.fieldState, field.marker, builder)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'hasOne': {\n\t\t\t\t\t\t\tbuilder = this.registerCreateEntityPart(\n\t\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\t\tfield.fieldState,\n\t\t\t\t\t\t\t\tfield.marker,\n\t\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'hasMany': {\n\t\t\t\t\t\t\tbuilder = this.registerCreateEntityListPart(\n\t\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\t\tfield.fieldState,\n\t\t\t\t\t\t\t\tfield.marker,\n\t\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tassertNever(field)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst setOnCreate = getEntityMarker(siblingState).parameters.setOnCreate\n\t\t\tif (setOnCreate && builder.data !== undefined && !isEmptyObject(builder.data)) {\n\t\t\t\tfor (const key in setOnCreate) {\n\t\t\t\t\tconst field = setOnCreate[key]\n\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof field === 'string' ||\n\t\t\t\t\t\ttypeof field === 'number' ||\n\t\t\t\t\t\tfield === null ||\n\t\t\t\t\t\tfield instanceof GraphQlBuilder.GraphQlLiteral\n\t\t\t\t\t) {\n\t\t\t\t\t\tbuilder = builder.set(key, field)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbuilder = builder.one(key, builder => builder.connect(field))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn builder\n\t}\n\n\tprivate registerCreateFieldPart(\n\t\tfieldState: FieldState,\n\t\tmarker: FieldMarker,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>,\n\t) {\n\t\tconst resolvedValue = fieldState.getAccessor().resolvedValue\n\n\t\tif (resolvedValue !== undefined && resolvedValue !== null) {\n\t\t\treturn builder.set(marker.fieldName, this.transformFieldValue(fieldState, resolvedValue))\n\t\t}\n\t\treturn builder\n\t}\n\n\tprivate registerCreateEntityPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tmarker: HasOneRelationMarker,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>,\n\t) {\n\t\tconst reducedBy = marker.parameters.reducedBy\n\t\tconst runtimeId = fieldState.entity.id\n\n\t\tif (reducedBy === undefined) {\n\t\t\treturn builder.one(marker.parameters.field, builder => {\n\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\treturn builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value })\n\t\t\t\t}\n\t\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState))\n\t\t\t})\n\t\t}\n\t\treturn builder.many(marker.parameters.field, builder => {\n\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t// TODO also potentially update\n\t\t\t\treturn builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t}\n\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState), alias)\n\t\t})\n\t}\n\n\tprivate registerCreateEntityListPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tfieldState: EntityListState,\n\t\tmarker: HasManyRelationMarker,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>,\n\t) {\n\t\treturn builder.many(marker.parameters.field, builder => {\n\t\t\tfor (const entityRealm of fieldState.children.values()) {\n\t\t\t\tconst alias = MutationAlias.encodeEntityId(entityRealm.entity.id)\n\t\t\t\tif (entityRealm.entity.id.existsOnServer) {\n\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\tbuilder = builder.connect({ [PRIMARY_KEY_NAME]: entityRealm.entity.id.value }, alias)\n\t\t\t\t} else {\n\t\t\t\t\tbuilder = builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, entityRealm), alias)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn builder\n\t\t})\n\t}\n\n\tprivate registerUpdateMutationPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tcurrentState: EntityRealmState,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Update>,\n\t): CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Update> {\n\t\tlet processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tprocessedPlaceholdersByEntity.set(currentState.entity, (processedPlaceholders = new Set()))\n\t\t}\n\n\t\tconst pathBack = this.treeStore.getPathBackToParent(currentState)\n\t\tconst entityData = this.treeStore.persistedEntityData.get(currentState.entity.id.uniqueValue)\n\n\t\tfor (const [placeholderName, fieldState] of currentState.children) {\n\t\t\tif (placeholderName === PRIMARY_KEY_NAME || placeholderName === TYPENAME_KEY_NAME) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (processedPlaceholders.has(placeholderName)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tprocessedPlaceholders.add(placeholderName)\n\n\t\t\tswitch (fieldState.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (fieldState.persistedValue !== undefined) {\n\t\t\t\t\t\tconst resolvedValue = fieldState.getAccessor().resolvedValue\n\t\t\t\t\t\tif (fieldState.persistedValue !== resolvedValue) {\n\t\t\t\t\t\t\tbuilder = builder.set(placeholderName, this.transformFieldValue(fieldState, resolvedValue))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealmStub':\n\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\tconst marker = getEntityMarker(fieldState)\n\t\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst runtimeId = fieldState.entity.id\n\t\t\t\t\tconst reducedBy = marker.parameters.reducedBy\n\n\t\t\t\t\tif (reducedBy === undefined) {\n\t\t\t\t\t\tconst subBuilder = ((\n\t\t\t\t\t\t\tbuilder: CrudQueryBuilder.WriteOneRelationBuilder<CrudQueryBuilder.WriteOperation.Update>,\n\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\tconst persistedValue = entityData?.get?.(placeholderName)\n\n\t\t\t\t\t\t\tif (persistedValue instanceof ServerId) {\n\t\t\t\t\t\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\t\t\t\t\t\t// The persisted and currently referenced ids match, and so this is an update.\n\t\t\t\t\t\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\t\t\t\t\t\treturn builder // …unless we're dealing with a stub. There cannot be any updates there.\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn builder.update(builder =>\n\t\t\t\t\t\t\t\t\t\tthis.registerUpdateMutationPart(processedPlaceholdersByEntity, fieldState, builder),\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// There was a referenced entity but currently, there is a different one. Let's investigate:\n\n\t\t\t\t\t\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\t\t\t\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\t\t\t\t\t\t// It's planned for deletion.\n\t\t\t\t\t\t\t\t\t// TODO also potentially do something about the current entity\n\t\t\t\t\t\t\t\t\treturn builder.delete()\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\t\t// This isn't the persisted entity but it does exist on the server. Thus this is a connect.\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\treturn builder.connect({\n\t\t\t\t\t\t\t\t\t\t[PRIMARY_KEY_NAME]: runtimeId.value,\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// The currently present entity doesn't exist on the server. Try if creating yields anything…\n\t\t\t\t\t\t\t\tconst subBuilder = builder.create(\n\t\t\t\t\t\t\t\t\tthis.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tif (isEmptyObject(subBuilder.data)) {\n\t\t\t\t\t\t\t\t\t// …and if it doesn't, we just disconnect.\n\t\t\t\t\t\t\t\t\treturn builder.disconnect()\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// …but if it does, we return the create, disconnecting implicitly.\n\t\t\t\t\t\t\t\treturn subBuilder\n\t\t\t\t\t\t\t} else if (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\t// There isn't a linked entity on the server but we're seeing one that exists there.\n\t\t\t\t\t\t\t\t// Thus this is a connect.\n\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\treturn builder.connect({\n\t\t\t\t\t\t\t\t\t[PRIMARY_KEY_NAME]: runtimeId.value,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})(CrudQueryBuilder.WriteOneRelationBuilder.instantiate<CrudQueryBuilder.WriteOperation.Update>())\n\n\t\t\t\t\t\tif (subBuilder.data) {\n\t\t\t\t\t\t\tbuilder = builder.one(marker.parameters.field, subBuilder.data)\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// This is a reduced has many relation.\n\t\t\t\t\t\tbuilder = builder.many(marker.parameters.field, builder => {\n\t\t\t\t\t\t\tconst persistedValue = entityData?.get?.(placeholderName)\n\t\t\t\t\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\t\t\t\t\t\tif (persistedValue instanceof ServerId) {\n\t\t\t\t\t\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\t\t\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\t\t\t\t\t\treturn builder\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn builder.update(\n\t\t\t\t\t\t\t\t\t\treducedBy,\n\t\t\t\t\t\t\t\t\t\tbuilder => this.registerUpdateMutationPart(processedPlaceholdersByEntity, fieldState, builder),\n\t\t\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\t\t\t\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\t\t\t\t\t\t// TODO also potentially do something about the current entity\n\t\t\t\t\t\t\t\t\treturn builder.delete(reducedBy, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\t\t// TODO will re-using the alias like this work?\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\treturn builder.disconnect(reducedBy, alias).connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst subBuilder = builder.create(\n\t\t\t\t\t\t\t\t\tthis.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tif (isEmptyObject(subBuilder.data)) {\n\t\t\t\t\t\t\t\t\treturn builder.disconnect(reducedBy, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn subBuilder\n\t\t\t\t\t\t\t} else if (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\treturn builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tconst marker = fieldState.blueprint.marker\n\t\t\t\t\tif (!(marker instanceof HasManyRelationMarker)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst persistedEntityIds = entityData?.get?.(placeholderName) ?? new Set()\n\n\t\t\t\t\tif (!(persistedEntityIds instanceof Set)) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tbuilder = builder.many(marker.parameters.field, builder => {\n\t\t\t\t\t\tfor (const childState of fieldState.children.values()) {\n\t\t\t\t\t\t\tconst runtimeId = childState.entity.id\n\t\t\t\t\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\t\t\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\tif (persistedEntityIds.has(runtimeId.value)) {\n\t\t\t\t\t\t\t\t\tif (childState.type !== 'entityRealmStub') {\n\t\t\t\t\t\t\t\t\t\t// A stub cannot have any pending changes.\n\t\t\t\t\t\t\t\t\t\tbuilder = builder.update(\n\t\t\t\t\t\t\t\t\t\t\t{ [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t\t\t\t\t\t\tbuilder => this.registerUpdateMutationPart(processedPlaceholdersByEntity, childState, builder),\n\t\t\t\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\tbuilder = builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tbuilder = builder.create(\n\t\t\t\t\t\t\t\t\tthis.registerCreateMutationPart(processedPlaceholdersByEntity, childState),\n\t\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (fieldState.plannedRemovals) {\n\t\t\t\t\t\t\tfor (const [removedId, removalType] of fieldState.plannedRemovals) {\n\t\t\t\t\t\t\t\tconst alias = MutationAlias.encodeEntityId(new ServerId(removedId, fieldState.entityName))\n\t\t\t\t\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\t\t\t\t\tbuilder = builder.delete({ [PRIMARY_KEY_NAME]: removedId }, alias)\n\t\t\t\t\t\t\t\t} else if (removalType === 'disconnect') {\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\tbuilder = builder.disconnect({ [PRIMARY_KEY_NAME]: removedId }, alias)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tassertNever(removalType)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn builder\n\t\t\t\t\t})\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t}\n\t\t}\n\n\t\treturn builder\n\t}\n\n\tprivate transformFieldValue(fieldState: FieldState, value: FieldValue): FieldValue | GraphQlBuilder.GraphQlLiteral {\n\t\tif (typeof value !== 'string') {\n\t\t\treturn value\n\t\t}\n\t\tconst fieldSchema = this.treeStore.schema.getEntityColumn(\n\t\t\tfieldState.parent.entity.entityName,\n\t\t\tfieldState.fieldMarker.fieldName,\n\t\t)\n\n\t\treturn fieldSchema.enumName === null ? value : new GraphQlBuilder.GraphQlLiteral(value)\n\t}\n\n\tprivate createAlias(): string {\n\t\treturn `op_${this.aliasCounter++}`\n\t}\n}\n"],"names":["builder","placeholderName","subBuilder"],"mappings":";;;;;;;;;;;;;;;;;;AA4CO,MAAM,kBAAkB;AAAA,EAIvB,YAA6B,WAAsB;AAFlD,wCAAe;AAEa,SAAA,YAAA;AAAA,EACpC;AAAA,EAEO,qBAAwD;AAC1D,QAAA;AACC,UAAA,UAAwB,IAAI,iBAAiB;AACjD,YAAM,aAAqC,CAAA;AACrC,YAAA,oDAAmE;AACnE,YAAA,uCAAuB;AAGlB,iBAAA,CAAC,YAAY,UAAU,KAAK,KAAK,UAAU,oBAAoB,WAAW;AACzE,mBAAA,CAAC,iBAAiB,YAAY,KAAK,MAAM,KAAK,WAAW,QAAQ,CAAC,EAAE,WAAW;AACrF,cAAA,aAAa,2BAA2B,GAAG;AAC9C;AAAA,UACD;AACI,cAAA,aAAa,SAAS,eAAe;AACxC,kBAAM,cAAc,KAAK;AAAA,cACxB;AAAA,cACA;AAAA,cACA;AAAA,cACA,aAAa,OAAO,GAAG;AAAA,cACvB;AAAA,cACA;AAAA,YAAA;AAED,gBAAI,aAAa;AAChB,wBAAU,YAAY;AACX,yBAAA,KAAK,YAAY,EAAE;AAAA,YAC/B;AAAA,UAAA,WACU,aAAa,SAAS,cAAc;AAC9C,uBAAW,cAAc,aAAa,SAAS,OAAA,GAAU;AACpD,kBAAA,WAAW,SAAS,mBAAmB;AAE1C;AAAA,cACD;AACA,oBAAM,cAAc,KAAK;AAAA,gBACxB;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA,WAAW,OAAO,GAAG;AAAA,gBACrB;AAAA,gBACA;AAAA,cAAA;AAED,kBAAI,aAAa;AAChB,0BAAU,YAAY;AACX,2BAAA,KAAK,YAAY,EAAE;AAAA,cAC/B;AAAA,YACD;AACA,gBAAI,aAAa,iBAAiB;AACjC,yBAAW,CAAC,WAAW,WAAW,KAAK,aAAa,iBAAiB;AACpE,oBA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D;AAAA,YACD;AACOA,mBAAAA;AAAAA,UAAA,CACP;AACD;AAAA,QACD;AAAA;AAEC,iBAAO,YAAsB;AAAA;AAAA,IAEhC;AAEO,WAAA;AAAA,EACR;AAAA,EAEQ,oBAAoB,YAAwB,OAA+D;AAC9G,QAAA,OAAO,UAAU,UAAU;AACvB,aAAA;AAAA,IACR;AACM,UAAA,cAAc,KAAK,UAAU,OAAO;AAAA,MACzC,WAAW,OAAO,OAAO;AAAA,MACzB,WAAW,YAAY;AAAA,IAAA;AAGxB,WAAO,YAAY,aAAa,OAAO,QAAQ,IAAI,eAAe,eAAe,KAAK;AAAA,EACvF;AAAA,EAEQ,cAAsB;AAC7B,WAAO,MAAM,KAAK;AAAA,EACnB;AACD;"}
1
+ {"version":3,"file":"MutationGenerator.js","sources":["../../../src/core/MutationGenerator.ts"],"sourcesContent":["// noinspection JSVoidFunctionReturnValueUsed // IntelliJ seems to be super confused througouht this file.\n\nimport { CrudQueryBuilder, GraphQlBuilder } from '@contember/client'\nimport { ClientGeneratedUuid, ServerId } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '../bindingTypes'\nimport { EntityFieldMarkers, FieldMarker, HasManyRelationMarker, HasOneRelationMarker } from '../markers'\nimport type { EntityId, EntityName, FieldValue, PlaceholderName } from '../treeParameters'\nimport { assertNever, isEmptyObject } from '../utils'\nimport { QueryGenerator } from './QueryGenerator'\nimport { MutationAlias } from './requestAliases'\nimport {\n\tEntityListState,\n\tEntityRealmState,\n\tEntityRealmStateStub,\n\tEntityState,\n\tFieldState,\n\tgetEntityMarker,\n\tStateIterator,\n} from './state'\nimport type { TreeStore } from './TreeStore'\n\ntype QueryBuilder = Omit<CrudQueryBuilder.CrudQueryBuilder, CrudQueryBuilder.Queries>\n\ntype ProcessedPlaceholdersByEntity = Map<EntityState, Set<PlaceholderName>>\n\nexport type SubMutationOperation =\n\t& {\n\t\talias: string,\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: 'list' | 'single'\n\t}\n\t& (\n\t\t| { type: 'delete', id: EntityId }\n\t\t| { type: 'update', markers: EntityFieldMarkers, id: EntityId }\n\t\t| { type: 'create', markers: EntityFieldMarkers, id: EntityId }\n\t)\n\nexport type PersistMutationResult = {\n\tquery: string\n\toperations: SubMutationOperation[]\n}\n\n// TODO enforce correct expected mutations in dev mode.\nexport class MutationGenerator {\n\n\tprivate aliasCounter = 1\n\n\tpublic constructor(private readonly treeStore: TreeStore) {\n\t}\n\n\tpublic getPersistMutation(): PersistMutationResult | undefined {\n\t\ttry {\n\t\t\tlet builder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder()\n\t\t\tconst operations: SubMutationOperation[] = []\n\t\t\tconst processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity = new Map()\n\t\t\tconst processedDeletes = new Set<string>()\n\n\n\t\t\tfor (const [treeRootId, rootStates] of this.treeStore.subTreeStatesByRoot.entries()) {\n\t\t\t\tfor (const [placeholderName, subTreeState] of Array.from(rootStates.entries()).reverse()) {\n\t\t\t\t\tif (subTreeState.unpersistedChangesCount <= 0) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif (subTreeState.type === 'entityRealm') {\n\t\t\t\t\t\tconst subMutation = this.addSubMutation(\n\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t'single',\n\t\t\t\t\t\t\tsubTreeState.entity.id.value,\n\t\t\t\t\t\t\tsubTreeState,\n\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tif (subMutation) {\n\t\t\t\t\t\t\tbuilder = subMutation[0]\n\t\t\t\t\t\t\toperations.push(subMutation[1])\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (subTreeState.type === 'entityList') {\n\t\t\t\t\t\tfor (const childState of subTreeState.children.values()) {\n\t\t\t\t\t\t\tif (childState.type === 'entityRealmStub') {\n\t\t\t\t\t\t\t\t// TODO there can be a forceCreate somewhere in there that we're hereby ignoring.\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst subMutation = this.addSubMutation(\n\t\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t\t'list',\n\t\t\t\t\t\t\t\tchildState.entity.id.value,\n\t\t\t\t\t\t\t\tchildState,\n\t\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tif (subMutation) {\n\t\t\t\t\t\t\t\tbuilder = subMutation[0]\n\t\t\t\t\t\t\t\toperations.push(subMutation[1])\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (subTreeState.plannedRemovals) {\n\t\t\t\t\t\t\tfor (const [removedId, removalType] of subTreeState.plannedRemovals) {\n\t\t\t\t\t\t\t\tif (removalType === 'disconnect') {\n\t\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\t\t\t\t\tconst key = `${subTreeState.entityName}#${removedId}`\n\t\t\t\t\t\t\t\t\tif (processedDeletes.has(key)) {\n\t\t\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tprocessedDeletes.add(key)\n\t\t\t\t\t\t\t\t\tconst alias = this.createAlias()\n\t\t\t\t\t\t\t\t\tbuilder = this.addDeleteMutation(\n\t\t\t\t\t\t\t\t\t\tsubTreeState.entityName,\n\t\t\t\t\t\t\t\t\t\tremovedId,\n\t\t\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\toperations.push({ alias, subTreePlaceholder: placeholderName, subTreeType: 'list', type: 'delete', id: removedId })\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tassertNever(removalType)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tassertNever(subTreeState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst query = builder.inTransaction(undefined, { deferForeignKeyConstraints: true }).getGql()\n\t\t\treturn { query, operations }\n\t\t} catch (e) {\n\t\t\treturn undefined\n\t\t}\n\t}\n\n\tprivate addSubMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: 'list' | 'single',\n\t\tentityId: EntityId,\n\t\trealmState: EntityRealmState,\n\t\tqueryBuilder: QueryBuilder,\n\t): [QueryBuilder, SubMutationOperation] | undefined {\n\t\tif (realmState.unpersistedChangesCount === 0) {\n\t\t\t// Bail out early\n\t\t\treturn undefined\n\t\t}\n\t\tconst fieldMarkers = getEntityMarker(realmState).fields.markers\n\n\t\tconst alias = this.createAlias()\n\n\t\tif (realmState.entity.isScheduledForDeletion) {\n\t\t\tconst builder = this.addDeleteMutation(\n\t\t\t\trealmState.entity.entityName,\n\t\t\t\tentityId,\n\t\t\t\talias,\n\t\t\t\tqueryBuilder,\n\t\t\t)\n\t\t\treturn [\n\t\t\t\tbuilder,\n\t\t\t\t{\n\t\t\t\t\talias,\n\t\t\t\t\tsubTreePlaceholder,\n\t\t\t\t\tsubTreeType,\n\t\t\t\t\ttype: 'delete',\n\t\t\t\t\tid: entityId,\n\t\t\t\t},\n\t\t\t]\n\t\t} else if (!realmState.entity.id.existsOnServer) {\n\t\t\tconst builder = this.addCreateMutation(\n\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\trealmState,\n\t\t\t\talias,\n\t\t\t\tthis.getNodeFragmentName(subTreePlaceholder, subTreeType, realmState),\n\t\t\t\tqueryBuilder,\n\t\t\t\tfieldMarkers,\n\t\t\t)\n\t\t\tif (!builder) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn [\n\t\t\t\tbuilder,\n\t\t\t\t{\n\t\t\t\t\talias,\n\t\t\t\t\tsubTreePlaceholder,\n\t\t\t\t\tsubTreeType,\n\t\t\t\t\ttype: 'create',\n\t\t\t\t\tmarkers: fieldMarkers,\n\t\t\t\t\tid: entityId,\n\t\t\t\t},\n]\n\t\t}\n\t\tconst builder = this.addUpdateMutation(\n\t\t\tprocessedPlaceholdersByEntity,\n\t\t\trealmState,\n\t\t\talias,\n\t\t\tthis.getNodeFragmentName(subTreePlaceholder, subTreeType, realmState),\n\t\t\tqueryBuilder,\n\t\t\tfieldMarkers,\n\t\t)\n\t\tif (!builder) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn [\n\t\t\tbuilder,\n\t\t\t{\n\t\t\t\talias,\n\t\t\t\tsubTreePlaceholder,\n\t\t\t\tsubTreeType,\n\t\t\t\ttype: 'update',\n\t\t\t\tid: entityId,\n\t\t\t\tmarkers: fieldMarkers,\n\t\t\t},\n\t\t]\n\t}\n\n\tprivate getNodeFragmentName(\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: 'single' | 'list',\n\t\trealmState: EntityRealmState,\n\t): string | undefined {\n\t\tif (subTreeType !== 'list') {\n\t\t\treturn undefined\n\t\t}\n\t\treturn `${realmState.entity.entityName}_${subTreePlaceholder}`\n\t}\n\n\tprivate addDeleteMutation(\n\t\tentityName: EntityName,\n\t\tdeletedId: EntityId,\n\t\talias: string,\n\t\tqueryBuilder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder(),\n\t): QueryBuilder {\n\t\treturn queryBuilder.delete(\n\t\t\tentityName,\n\t\t\tbuilder =>\n\t\t\t\tbuilder\n\t\t\t\t\t.ok()\n\t\t\t\t\t.node(builder => builder.column(PRIMARY_KEY_NAME))\n\t\t\t\t\t.by({ [PRIMARY_KEY_NAME]: deletedId })\n\t\t\t\t\t.errors()\n\t\t\t\t\t.errorMessage(),\n\t\t\talias,\n\t\t)\n\t}\n\n\tprivate addUpdateMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tentityRealm: EntityRealmState,\n\t\talias: string,\n\t\tnodeFragmentName: string | undefined,\n\t\tqueryBuilder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder(),\n\t\tfieldMarkers: EntityFieldMarkers,\n\t): QueryBuilder | undefined {\n\t\tconst updateBuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Update> =\n\t\t\tthis.registerUpdateMutationPart(\n\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\tentityRealm,\n\t\t\t\tnew CrudQueryBuilder.WriteDataBuilder(),\n\t\t\t)\n\t\tif (updateBuilder.data === undefined || isEmptyObject(updateBuilder.data)) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst runtimeId = entityRealm.entity.id\n\n\t\tif (!runtimeId.existsOnServer) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst readBuilder = QueryGenerator.registerQueryPart(\n\t\t\tfieldMarkers,\n\t\t\tCrudQueryBuilder.ReadBuilder.instantiate(),\n\t\t)\n\n\t\tif (nodeFragmentName) {\n\t\t\tqueryBuilder = queryBuilder.fragment(nodeFragmentName, entityRealm.entity.entityName, readBuilder)\n\t\t}\n\n\t\treturn queryBuilder.update(\n\t\t\tentityRealm.entity.entityName,\n\t\t\tbuilder =>\n\t\t\t\tbuilder\n\t\t\t\t\t.node(nodeFragmentName ? builder => builder.applyFragment(nodeFragmentName) : readBuilder)\n\t\t\t\t\t.data(updateBuilder)\n\t\t\t\t\t.by({ [PRIMARY_KEY_NAME]: runtimeId.value })\n\t\t\t\t\t.ok()\n\t\t\t\t\t.validation()\n\t\t\t\t\t.errors()\n\t\t\t\t\t.errorMessage(),\n\t\t\talias,\n\t\t)\n\t}\n\n\tprivate addCreateMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tentityRealm: EntityRealmState,\n\t\talias: string,\n\t\tnodeFragmentName: string | undefined,\n\t\tqueryBuilder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder(),\n\t\tfieldMarkers: EntityFieldMarkers,\n\t): QueryBuilder | undefined {\n\t\tconst createBuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create> =\n\t\t\tthis.registerCreateMutationPart(\n\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\tentityRealm,\n\t\t\t\tnew CrudQueryBuilder.WriteDataBuilder(),\n\t\t\t)\n\t\tif (createBuilder.data === undefined || isEmptyObject(createBuilder.data)) {\n\t\t\treturn undefined\n\t\t}\n\t\tconst readBuilder = QueryGenerator.registerQueryPart(\n\t\t\tfieldMarkers,\n\t\t\tCrudQueryBuilder.ReadBuilder.instantiate(),\n\t\t)\n\t\tif (nodeFragmentName) {\n\t\t\tqueryBuilder = queryBuilder.fragment(nodeFragmentName, entityRealm.entity.entityName, readBuilder)\n\t\t}\n\n\t\treturn queryBuilder.create(\n\t\t\tentityRealm.entity.entityName,\n\t\t\tbuilder => {\n\t\t\t\t// if (where && writeBuilder.data !== undefined && !isEmptyObject(writeBuilder.data)) {\n\t\t\t\t// \t// Shallow cloning the parameters like this IS too naïve but it will likely last surprisingly long before we\n\t\t\t\t// \t// run into issues.\n\t\t\t\t// \twriteBuilder = new CrudQueryBuilder.WriteDataBuilder({ ...writeBuilder.data, ...where })\n\t\t\t\t// }\n\t\t\t\treturn builder\n\t\t\t\t\t.node(nodeFragmentName ? builder => builder.applyFragment(nodeFragmentName) : readBuilder)\n\t\t\t\t\t.data(createBuilder)\n\t\t\t\t\t.ok()\n\t\t\t\t\t.validation()\n\t\t\t\t\t.errors()\n\t\t\t\t\t.errorMessage()\n\t\t\t},\n\t\t\talias,\n\t\t)\n\t}\n\n\tprivate registerCreateMutationPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tcurrentState: EntityRealmState | EntityRealmStateStub,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create> = new CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>(),\n\t): CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create> {\n\t\tlet processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tprocessedPlaceholdersByEntity.set(currentState.entity, (processedPlaceholders = new Set()))\n\t\t}\n\n\t\tif (currentState.type === 'entityRealmStub') {\n\t\t\t// TODO If there's a forceCreate, this is wrong.\n\t\t\treturn builder\n\t\t}\n\n\t\tfor (const siblingState of StateIterator.eachSiblingRealm(currentState)) {\n\n\t\t\tconst pathBack = this.treeStore.getPathBackToParent(siblingState)\n\n\t\t\tconst nonbearingFields: Array<| { type: 'field'; marker: FieldMarker; fieldState: FieldState }\n\t\t\t\t| { type: 'hasOne'; marker: HasOneRelationMarker; fieldState: EntityRealmState | EntityRealmStateStub }\n\t\t\t\t| { type: 'hasMany'; marker: HasManyRelationMarker; fieldState: EntityListState }> = []\n\n\t\t\tfor (const [placeholderName, fieldState] of siblingState.children) {\n\t\t\t\tif (processedPlaceholders.has(placeholderName)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tprocessedPlaceholders.add(placeholderName)\n\n\t\t\t\tswitch (fieldState.type) {\n\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\tconst marker = fieldState.fieldMarker\n\t\t\t\t\t\tconst placeholderName = marker.placeholderName\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tplaceholderName === TYPENAME_KEY_NAME ||\n\t\t\t\t\t\t\t(placeholderName === PRIMARY_KEY_NAME && !(siblingState.entity.id instanceof ClientGeneratedUuid))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (marker.isNonbearing) {\n\t\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\t\ttype: 'field',\n\t\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbuilder = this.registerCreateFieldPart(fieldState, marker, builder)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'entityRealmStub':\n\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\tconst marker = getEntityMarker(fieldState)\n\t\t\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (marker.parameters.isNonbearing) {\n\t\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\t\ttype: 'hasOne',\n\t\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbuilder = this.registerCreateEntityPart(processedPlaceholdersByEntity, fieldState, marker, builder)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'entityList': {\n\t\t\t\t\t\tconst marker = fieldState.blueprint.marker\n\t\t\t\t\t\tif (!(marker instanceof HasManyRelationMarker)) {\n\t\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (marker.parameters.isNonbearing) {\n\t\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\t\ttype: 'hasMany',\n\t\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbuilder = this.registerCreateEntityListPart(processedPlaceholdersByEntity, fieldState, marker, builder)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// if (\n\t\t\t// \tcurrentState.blueprint.creationParameters.forceCreation &&\n\t\t\t// \t(builder.data === undefined || isEmptyObject(builder.data))\n\t\t\t// ) {\n\t\t\t// \tbuilder = builder.set('_dummy_field_', true)\n\t\t\t// }\n\n\t\t\tif (\n\t\t\t\t(builder.data !== undefined && !isEmptyObject(builder.data)) ||\n\t\t\t\t!getEntityMarker(siblingState).fields.hasAtLeastOneBearingField\n\t\t\t) {\n\t\t\t\tfor (const field of nonbearingFields) {\n\t\t\t\t\tswitch (field.type) {\n\t\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\t\tbuilder = this.registerCreateFieldPart(field.fieldState, field.marker, builder)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'hasOne': {\n\t\t\t\t\t\t\tbuilder = this.registerCreateEntityPart(\n\t\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\t\tfield.fieldState,\n\t\t\t\t\t\t\t\tfield.marker,\n\t\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'hasMany': {\n\t\t\t\t\t\t\tbuilder = this.registerCreateEntityListPart(\n\t\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\t\tfield.fieldState,\n\t\t\t\t\t\t\t\tfield.marker,\n\t\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tassertNever(field)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst setOnCreate = getEntityMarker(siblingState).parameters.setOnCreate\n\t\t\tif (setOnCreate && builder.data !== undefined && !isEmptyObject(builder.data)) {\n\t\t\t\tfor (const key in setOnCreate) {\n\t\t\t\t\tconst field = setOnCreate[key]\n\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof field === 'string' ||\n\t\t\t\t\t\ttypeof field === 'number' ||\n\t\t\t\t\t\tfield === null ||\n\t\t\t\t\t\tfield instanceof GraphQlBuilder.GraphQlLiteral\n\t\t\t\t\t) {\n\t\t\t\t\t\tbuilder = builder.set(key, field)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbuilder = builder.one(key, builder => builder.connect(field))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn builder\n\t}\n\n\tprivate registerCreateFieldPart(\n\t\tfieldState: FieldState,\n\t\tmarker: FieldMarker,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>,\n\t) {\n\t\tconst resolvedValue = fieldState.getAccessor().resolvedValue\n\n\t\tif (resolvedValue !== undefined && resolvedValue !== null) {\n\t\t\treturn builder.set(marker.fieldName, this.transformFieldValue(fieldState, resolvedValue))\n\t\t}\n\t\treturn builder\n\t}\n\n\tprivate registerCreateEntityPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tmarker: HasOneRelationMarker,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>,\n\t) {\n\t\tconst reducedBy = marker.parameters.reducedBy\n\t\tconst runtimeId = fieldState.entity.id\n\n\t\tif (reducedBy === undefined) {\n\t\t\treturn builder.one(marker.parameters.field, builder => {\n\t\t\t\tif (this.shouldConnectInsteadOfCreate(processedPlaceholdersByEntity, fieldState)) {\n\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\treturn builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value })\n\t\t\t\t}\n\t\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState))\n\t\t\t})\n\t\t}\n\t\treturn builder.many(marker.parameters.field, builder => {\n\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\t\t\tif (this.shouldConnectInsteadOfCreate(processedPlaceholdersByEntity, fieldState)) {\n\t\t\t\t// TODO also potentially update\n\t\t\t\treturn builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t}\n\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState), alias)\n\t\t})\n\t}\n\n\tprivate registerCreateEntityListPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tfieldState: EntityListState,\n\t\tmarker: HasManyRelationMarker,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>,\n\t) {\n\t\treturn builder.many(marker.parameters.field, builder => {\n\t\t\tfor (const entityRealm of fieldState.children.values()) {\n\t\t\t\tconst runtimeId = entityRealm.entity.id\n\t\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\t\t\t\tif (this.shouldConnectInsteadOfCreate(processedPlaceholdersByEntity, entityRealm)) {\n\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\tbuilder = builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t\t} else {\n\t\t\t\t\tbuilder = builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, entityRealm), alias)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn builder\n\t\t})\n\t}\n\n\tprivate shouldConnectInsteadOfCreate(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tcurrentState: EntityRealmState | EntityRealmStateStub,\n\t): boolean {\n\t\tconst runtimeId = currentState.entity.id\n\t\tconst processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\treturn runtimeId.existsOnServer || (runtimeId instanceof ClientGeneratedUuid && (processedPlaceholders?.has(PRIMARY_KEY_NAME) ?? false))\n\t}\n\n\tprivate registerUpdateMutationPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tcurrentState: EntityRealmState,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Update>,\n\t): CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Update> {\n\t\tlet processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tprocessedPlaceholdersByEntity.set(currentState.entity, (processedPlaceholders = new Set()))\n\t\t}\n\n\t\tconst pathBack = this.treeStore.getPathBackToParent(currentState)\n\t\tconst entityData = this.treeStore.persistedEntityData.get(currentState.entity.id.uniqueValue)\n\n\t\tfor (const [placeholderName, fieldState] of currentState.children) {\n\t\t\tif (placeholderName === PRIMARY_KEY_NAME || placeholderName === TYPENAME_KEY_NAME) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (processedPlaceholders.has(placeholderName)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tprocessedPlaceholders.add(placeholderName)\n\n\t\t\tswitch (fieldState.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (fieldState.persistedValue !== undefined) {\n\t\t\t\t\t\tconst resolvedValue = fieldState.getAccessor().resolvedValue\n\t\t\t\t\t\tif (fieldState.persistedValue !== resolvedValue) {\n\t\t\t\t\t\t\tbuilder = builder.set(placeholderName, this.transformFieldValue(fieldState, resolvedValue))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealmStub':\n\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\tconst marker = getEntityMarker(fieldState)\n\t\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst runtimeId = fieldState.entity.id\n\t\t\t\t\tconst reducedBy = marker.parameters.reducedBy\n\n\t\t\t\t\tif (reducedBy === undefined) {\n\t\t\t\t\t\tconst subBuilder = ((\n\t\t\t\t\t\t\tbuilder: CrudQueryBuilder.WriteOneRelationBuilder<CrudQueryBuilder.WriteOperation.Update>,\n\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\tconst persistedValue = entityData?.get?.(placeholderName)\n\n\t\t\t\t\t\t\tif (persistedValue instanceof ServerId) {\n\t\t\t\t\t\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\t\t\t\t\t\t// The persisted and currently referenced ids match, and so this is an update.\n\t\t\t\t\t\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\t\t\t\t\t\treturn builder // …unless we're dealing with a stub. There cannot be any updates there.\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn builder.update(builder =>\n\t\t\t\t\t\t\t\t\t\tthis.registerUpdateMutationPart(processedPlaceholdersByEntity, fieldState, builder),\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// There was a referenced entity but currently, there is a different one. Let's investigate:\n\n\t\t\t\t\t\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\t\t\t\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\t\t\t\t\t\t// It's planned for deletion.\n\t\t\t\t\t\t\t\t\t// TODO also potentially do something about the current entity\n\t\t\t\t\t\t\t\t\treturn builder.delete()\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\t\t// This isn't the persisted entity but it does exist on the server. Thus this is a connect.\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\treturn builder.connect({\n\t\t\t\t\t\t\t\t\t\t[PRIMARY_KEY_NAME]: runtimeId.value,\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// The currently present entity doesn't exist on the server. Try if creating yields anything…\n\t\t\t\t\t\t\t\tconst subBuilder = builder.create(\n\t\t\t\t\t\t\t\t\tthis.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tif (isEmptyObject(subBuilder.data)) {\n\t\t\t\t\t\t\t\t\t// …and if it doesn't, we just disconnect.\n\t\t\t\t\t\t\t\t\treturn builder.disconnect()\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// …but if it does, we return the create, disconnecting implicitly.\n\t\t\t\t\t\t\t\treturn subBuilder\n\t\t\t\t\t\t\t} else if (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\t// There isn't a linked entity on the server but we're seeing one that exists there.\n\t\t\t\t\t\t\t\t// Thus this is a connect.\n\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\treturn builder.connect({\n\t\t\t\t\t\t\t\t\t[PRIMARY_KEY_NAME]: runtimeId.value,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})(CrudQueryBuilder.WriteOneRelationBuilder.instantiate<CrudQueryBuilder.WriteOperation.Update>())\n\n\t\t\t\t\t\tif (subBuilder.data) {\n\t\t\t\t\t\t\tbuilder = builder.one(marker.parameters.field, subBuilder.data)\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// This is a reduced has many relation.\n\t\t\t\t\t\tbuilder = builder.many(marker.parameters.field, builder => {\n\t\t\t\t\t\t\tconst persistedValue = entityData?.get?.(placeholderName)\n\t\t\t\t\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\t\t\t\t\t\tif (persistedValue instanceof ServerId) {\n\t\t\t\t\t\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\t\t\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\t\t\t\t\t\treturn builder\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn builder.update(\n\t\t\t\t\t\t\t\t\t\treducedBy,\n\t\t\t\t\t\t\t\t\t\tbuilder => this.registerUpdateMutationPart(processedPlaceholdersByEntity, fieldState, builder),\n\t\t\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\t\t\t\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\t\t\t\t\t\t// TODO also potentially do something about the current entity\n\t\t\t\t\t\t\t\t\treturn builder.delete(reducedBy, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\t\t// TODO will re-using the alias like this work?\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\treturn builder.disconnect(reducedBy, alias).connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst subBuilder = builder.create(\n\t\t\t\t\t\t\t\t\tthis.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tif (isEmptyObject(subBuilder.data)) {\n\t\t\t\t\t\t\t\t\treturn builder.disconnect(reducedBy, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn subBuilder\n\t\t\t\t\t\t\t} else if (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\treturn builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tconst marker = fieldState.blueprint.marker\n\t\t\t\t\tif (!(marker instanceof HasManyRelationMarker)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst persistedEntityIds = entityData?.get?.(placeholderName) ?? new Set()\n\n\t\t\t\t\tif (!(persistedEntityIds instanceof Set)) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tbuilder = builder.many(marker.parameters.field, builder => {\n\t\t\t\t\t\tfor (const childState of fieldState.children.values()) {\n\t\t\t\t\t\t\tconst runtimeId = childState.entity.id\n\t\t\t\t\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\t\t\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\tif (persistedEntityIds.has(runtimeId.value)) {\n\t\t\t\t\t\t\t\t\tif (childState.type !== 'entityRealmStub') {\n\t\t\t\t\t\t\t\t\t\t// A stub cannot have any pending changes.\n\t\t\t\t\t\t\t\t\t\tbuilder = builder.update(\n\t\t\t\t\t\t\t\t\t\t\t{ [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t\t\t\t\t\t\tbuilder => this.registerUpdateMutationPart(processedPlaceholdersByEntity, childState, builder),\n\t\t\t\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\tbuilder = builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tbuilder = builder.create(\n\t\t\t\t\t\t\t\t\tthis.registerCreateMutationPart(processedPlaceholdersByEntity, childState),\n\t\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (fieldState.plannedRemovals) {\n\t\t\t\t\t\t\tfor (const [removedId, removalType] of fieldState.plannedRemovals) {\n\t\t\t\t\t\t\t\tconst alias = MutationAlias.encodeEntityId(new ServerId(removedId, fieldState.entityName))\n\t\t\t\t\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\t\t\t\t\tbuilder = builder.delete({ [PRIMARY_KEY_NAME]: removedId }, alias)\n\t\t\t\t\t\t\t\t} else if (removalType === 'disconnect') {\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\tbuilder = builder.disconnect({ [PRIMARY_KEY_NAME]: removedId }, alias)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tassertNever(removalType)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn builder\n\t\t\t\t\t})\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t}\n\t\t}\n\n\t\treturn builder\n\t}\n\n\tprivate transformFieldValue(fieldState: FieldState, value: FieldValue): FieldValue | GraphQlBuilder.GraphQlLiteral {\n\t\tif (typeof value !== 'string') {\n\t\t\treturn value\n\t\t}\n\t\tconst fieldSchema = this.treeStore.schema.getEntityColumn(\n\t\t\tfieldState.parent.entity.entityName,\n\t\t\tfieldState.fieldMarker.fieldName,\n\t\t)\n\n\t\treturn fieldSchema.enumName === null ? value : new GraphQlBuilder.GraphQlLiteral(value)\n\t}\n\n\tprivate createAlias(): string {\n\t\treturn `op_${this.aliasCounter++}`\n\t}\n}\n"],"names":["builder","placeholderName","subBuilder"],"mappings":";;;;;;;;;;;;;;;;;;AA4CO,MAAM,kBAAkB;AAAA,EAIvB,YAA6B,WAAsB;AAAtB,SAAA,YAAA;AAFpC,kBAAA,MAAQ,gBAAe,CAAA;AAAA,EAGvB;AAAA,EAEO,qBAAwD;AAC1D,QAAA;AACC,UAAA,UAAwB,IAAI,iBAAiB;AACjD,YAAM,aAAqC,CAAA;AACrC,YAAA,oDAAmE;AACnE,YAAA,uCAAuB;AAGlB,iBAAA,CAAC,YAAY,UAAU,KAAK,KAAK,UAAU,oBAAoB,WAAW;AACzE,mBAAA,CAAC,iBAAiB,YAAY,KAAK,MAAM,KAAK,WAAW,QAAQ,CAAC,EAAE,WAAW;AACrF,cAAA,aAAa,2BAA2B,GAAG;AAC9C;AAAA,UACD;AACI,cAAA,aAAa,SAAS,eAAe;AACxC,kBAAM,cAAc,KAAK;AAAA,cACxB;AAAA,cACA;AAAA,cACA;AAAA,cACA,aAAa,OAAO,GAAG;AAAA,cACvB;AAAA,cACA;AAAA,YAAA;AAED,gBAAI,aAAa;AAChB,wBAAU,YAAY;AACX,yBAAA,KAAK,YAAY,EAAE;AAAA,YAC/B;AAAA,UAAA,WACU,aAAa,SAAS,cAAc;AAC9C,uBAAW,cAAc,aAAa,SAAS,OAAA,GAAU;AACpD,kBAAA,WAAW,SAAS,mBAAmB;AAE1C;AAAA,cACD;AACA,oBAAM,cAAc,KAAK;AAAA,gBACxB;A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A,6BAAUA,SAAQ,QAAQ,EAAE,CAAC,mBAAmB,UAAU,SAAS,KAAK;AAAA,gBACzE;AAAA,cAAA,OACM;AACNA,2BAAUA,SAAQ;AAAA,kBACjB,KAAK,2BAA2B,+BAA+B,UAAU;AAAA,kBACzE;AAAA,gBAAA;AAAA,cAEF;AAAA,YACD;AACA,gBAAI,WAAW,iBAAiB;AAC/B,yBAAW,CAAC,WAAW,WAAW,KAAK,WAAW,iBAAiB;AAC5D,sBAAA,QAAQ,cAAc,eAAe,IAAI,SAAS,WAAW,WAAW,UAAU,CAAC;AACzF,oBAAI,gBAAgB,UAAU;AAC7BA,6BAAUA,SAAQ,OAAO,EAAE,CAAC,mBAAmB,UAAA,GAAa,KAAK;AAAA,gBAAA,WACvD,gBAAgB,cAAc;AAExCA,6BAAUA,SAAQ,WAAW,EAAE,CAAC,mBAAmB,UAAA,GAAa,KAAK;AAAA,gBAAA,OAC/D;AACN,8BAAuB;AAAA,gBACxB;AAAA,cACD;AAAA,YACD;AACOA,mBAAAA;AAAAA,UAAA,CACP;AACD;AAAA,QACD;AAAA,QACA;AACC,iBAAO,YAAsB;AAAA,MAC/B;AAAA,IACD;AAEO,WAAA;AAAA,EACR;AAAA,EAEQ,oBAAoB,YAAwB,OAA+D;AAC9G,QAAA,OAAO,UAAU,UAAU;AACvB,aAAA;AAAA,IACR;AACM,UAAA,cAAc,KAAK,UAAU,OAAO;AAAA,MACzC,WAAW,OAAO,OAAO;AAAA,MACzB,WAAW,YAAY;AAAA,IAAA;AAGxB,WAAO,YAAY,aAAa,OAAO,QAAQ,IAAI,eAAe,eAAe,KAAK;AAAA,EACvF;AAAA,EAEQ,cAAsB;AAC7B,WAAO,MAAM,KAAK;AAAA,EACnB;AACD;"}
@@ -1,11 +1,11 @@
1
+ import { WeakIdCache } from "../structures/WeakIdCache.js";
2
+ import { assertNever } from "../utils/assertNever.js";
1
3
  var __defProp = Object.defineProperty;
2
4
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
5
  var __publicField = (obj, key, value) => {
4
6
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
7
  return value;
6
8
  };
7
- import { WeakIdCache } from "../structures/WeakIdCache.js";
8
- import { assertNever } from "../utils/assertNever.js";
9
9
  const GLUE = "--";
10
10
  const keyEndRegex = new RegExp(`${GLUE}\\d+$`);
11
11
  class RealmKeyGenerator {
@@ -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,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;"}
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,YAAgD,CAAA;AACxF,cAJY,mBAIG,iBAAgB,IAAI,aAAyC;"}
@@ -1,9 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => {
4
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- return value;
6
- };
7
1
  import { BindingError } from "../BindingError.js";
8
2
  import { RealmKeyGenerator } from "./RealmKeyGenerator.js";
9
3
  import { TreeParameterMerger } from "./TreeParameterMerger.js";
@@ -22,13 +16,19 @@ import { HasOneRelationMarker } from "../markers/HasOneRelationMarker.js";
22
16
  import { assertNever } from "../utils/assertNever.js";
23
17
  import { FieldAccessor } from "../accessors/FieldAccessor.js";
24
18
  import { EventListenersStore } from "../treeParameters/EventListenersStore.js";
19
+ var __defProp = Object.defineProperty;
20
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
21
+ var __publicField = (obj, key, value) => {
22
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
23
+ return value;
24
+ };
25
25
  class StateInitializer {
26
26
  constructor(accessorErrorManager, batchUpdatesOptions, eventManager, treeStore) {
27
+ this.eventManager = eventManager;
28
+ this.treeStore = treeStore;
27
29
  __publicField(this, "fieldOperations");
28
30
  __publicField(this, "entityOperations");
29
31
  __publicField(this, "listOperations");
30
- this.eventManager = eventManager;
31
- this.treeStore = treeStore;
32
32
  this.fieldOperations = new FieldOperations(accessorErrorManager, this.eventManager, this, this.treeStore);
33
33
  this.entityOperations = new EntityOperations(accessorErrorManager, batchUpdatesOptions, this.eventManager, this, this.treeStore);
34
34
  this.listOperations = new ListOperations(accessorErrorManager, batchUpdatesOptions, this.eventManager, this, this.treeStore);
@@ -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.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,gBAAg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,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;AAFgB,SAAA,eAAA;AACA,SAAA,YAAA;AARD,kBAAA,MAAA,iBAAA;AACA,kBAAA,MAAA,kBAAA;AACA,kBAAA,MAAA,gBAAA;AAQX,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;AAAA,QACL;AAAA,MAAA;AAAA,IACD,OACM;AACN,qBAAe,KAAK;AAAA,QACnB,KAAK;AAAA,UACJ,6BAA6B,WAAW,oBAAoB,IAAI,yBAAyB;AAAA,UACzF,KAAK;AAAA,UACL;AAAA,YACC,MAAM;AAAA,YACN,QAAQ;AAAA,YACR,QAAQ;AAAA,UACT;AAAA,QACD;AAAA,MAAA;AAAA,IAEF;AAEO,WAAA;AAAA,EACR;AAA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BAAkB;AAAA,IAChC;AAAA,EACD;AAAA,EAEO,mCAAmC,WAAuE;AAC5G,QAAA,UAAU,SAAS,cAAc;AACpC,YAAMC,sBAAqB,UAAU,OAAO,UAAU,OAAO,WAAW;AACxE,YAAM,kBAAkBA,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 +1 @@
1
- {"version":3,"file":"TreeAugmenter.js","sources":["../../../src/core/TreeAugmenter.ts"],"sourcesContent":["import {\n\tClientGeneratedUuid,\n\tEntityListPersistedData,\n\tReceivedDataTree,\n\tRuntimeId,\n\tServerId,\n\tUnpersistedEntityDummyId,\n} from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { EntityId, PlaceholderName, TreeRootId } from '../treeParameters'\nimport { assert, assertNever } from '../utils'\nimport { EventManager } from './EventManager'\nimport { OperationsHelpers } from './operations/OperationsHelpers'\nimport type { EntityListState, EntityRealmState, EntityRealmStateStub, RootStateNode } from './state'\nimport type { StateInitializer } from './StateInitializer'\nimport type { TreeStore } from './TreeStore'\nimport { SubMutationOperation } from './MutationGenerator'\n\nexport class TreeAugmenter {\n\tpublic constructor(\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly skipStateUpdateAfterPersist: boolean = false,\n\t) {}\n\n\tpublic extendPersistedData(newPersistedData: ReceivedDataTree, markerTree: MarkerTreeRoot) {\n\t\t// TODO this doesn't yet handle updates for entities whose persisted data just gets magically changed without notice.\n\t\tthis.treeStore.mergeInQueryResponse(newPersistedData, markerTree)\n\t}\n\n\tpublic extendTreeStates(newTreeId: TreeRootId | undefined, newMarkerTree: MarkerTreeRoot): void {\n\t\tconst subTreeStates: Map<PlaceholderName, RootStateNode> = new Map()\n\n\t\tthis.treeStore.markerTrees.set(newTreeId, newMarkerTree)\n\t\tthis.treeStore.subTreeStatesByRoot.set(newTreeId, subTreeStates)\n\n\t\tfor (const [placeholderName, newSubTreeMarker] of newMarkerTree.subTrees) {\n\t\t\tconst newState = this.stateInitializer.initializeSubTree(newSubTreeMarker)\n\t\t\tsubTreeStates.set(placeholderName, newState)\n\t\t}\n\t}\n\n\tpublic updatePersistedData(response: ReceivedDataTree, operations: SubMutationOperation[]) {\n\t\tthis.treeStore.mergeInMutationResponse(response, operations)\n\t\tif (this.skipStateUpdateAfterPersist) {\n\t\t\treturn\n\t\t}\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\t\t// for (const rootPlaceholder in response) {\n\t\t\t\t// \tconst rootState = rootStates.get(rootPlaceholder)\n\t\t\t\t//\n\t\t\t\t// \tif (rootState === undefined) {\n\t\t\t\t// \t\tcontinue\n\t\t\t\t// \t}\n\t\t\t\t// TODO the above would be better, only refreshing roots which participated in the mutation. However, due to\n\t\t\t\t// \thow mutations are currently generated, we cannot assume that only roots present in the response need\n\t\t\t\t// \trefreshed. So we just refresh all.\n\t\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\t\tconst rootData = this.treeStore.subTreePersistedData.get(rootPlaceholder)\n\n\t\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\t\tif (!(rootData instanceof Set)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateEntityListPersistedData(rootState, rootData)\n\t\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\t\tif (rootData !== undefined && !(rootData instanceof ServerId)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateRealmIdIfNecessary(rootState, rootData)\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(rootState)\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn assertNever(rootState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic resetCreatingSubTrees() {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\tassert(rootState.blueprint.parent === undefined)\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst changesCount = rootState.unpersistedChangesCount\n\n\t\t\t\t\t// Just emptying the list. But the list itself can stay.\n\t\t\t\t\tfor (const childState of rootState.children.values()) {\n\t\t\t\t\t\tthis.treeStore.disposeOfRealm(childState)\n\t\t\t\t\t}\n\t\t\t\t\trootState.accessor = undefined\n\t\t\t\t\trootState.children.clear()\n\t\t\t\t\trootState.childrenWithPendingUpdates?.clear()\n\t\t\t\t\trootState.errors = undefined\n\t\t\t\t\trootState.plannedRemovals?.clear()\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(\n\t\t\t\t\t\trootState,\n\t\t\t\t\t\tchangesCount ? -1 * changesCount : EventManager.NO_CHANGES_DIFFERENCE,\n\t\t\t\t\t)\n\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\tassert(rootState.blueprint.parent === undefined)\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst presentListeners = rootState.eventListeners\n\t\t\t\t\tthis.treeStore.disposeOfRealm(rootState)\n\n\t\t\t\t\t// It's crucial to delete the persisted data before we re-initialize so that we get a fresh, new entity.\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst newRootState = this.stateInitializer.initializeSubTree(rootState.blueprint.marker)\n\n\t\t\t\t\t// We preserve the previous listeners but purge some of them.\n\t\t\t\t\tnewRootState.eventListeners = presentListeners\n\t\t\t\t\tOperationsHelpers.purgeStaleListenersAfterIdChange(newRootState as EntityRealmState)\n\n\t\t\t\t\trootStates.set(rootPlaceholder, newRootState)\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(newRootState, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(rootState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateRealmIdIfNecessary(\n\t\trealm: EntityRealmState | EntityRealmStateStub,\n\t\tnewId: ServerId | undefined | null,\n\t) {\n\t\tconst currentId = realm.entity.id\n\t\tlet idToChangeTo: RuntimeId | undefined = undefined\n\n\t\tif (currentId instanceof ServerId) {\n\t\t\tif (newId === undefined || newId === null) {\n\t\t\t\tidToChangeTo = new UnpersistedEntityDummyId()\n\t\t\t} else if (currentId.value !== newId.value) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else if (currentId instanceof ClientGeneratedUuid) {\n\t\t\tidToChangeTo = newId ?? new UnpersistedEntityDummyId()\n\t\t} else if (currentId instanceof UnpersistedEntityDummyId) {\n\t\t\tif (newId) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else {\n\t\t\treturn assertNever(currentId)\n\t\t}\n\t\tif (idToChangeTo) {\n\t\t\tOperationsHelpers.changeRealmId(this.treeStore, this.eventManager, this.stateInitializer, realm, idToChangeTo)\n\t\t}\n\t}\n\n\tprivate updateEntityRealmPersistedData(realm: EntityRealmState) {\n\t\tconst realmId = realm.entity.id\n\t\tconst persistedData = realmId.existsOnServer ? this.treeStore.persistedEntityData.get(realmId.uniqueValue) : undefined\n\n\t\tfor (const [placeholderName, child] of realm.children) {\n\t\t\tconst childData = persistedData?.get(placeholderName)\n\n\t\t\tswitch (child.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (childData instanceof ServerId || childData instanceof Set) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (child.persistedValue !== childData) {\n\t\t\t\t\t\tconst shouldChangeBothValues = child.persistedValue === child.value\n\n\t\t\t\t\t\tchild.persistedValue = childData\n\t\t\t\t\t\tif (shouldChangeBothValues) {\n\t\t\t\t\t\t\tchild.value = childData ?? null\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.eventManager.registerJustUpdated(child, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\tif (!(childData instanceof ServerId) && childData !== undefined && childData !== null) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateRealmIdIfNecessary(child, childData)\n\t\t\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (childData !== undefined && !(childData instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateEntityListPersistedData(child, childData ?? new Set()) // TODO!!\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn assertNever(child)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateEntityListPersistedData(state: EntityListState, newPersistedIds: EntityListPersistedData) {\n\t\tconst persistedWithoutState: EntityId[] = []\n\n\t\t// TODO This isn't particularly efficient. We should probably use something like diff-sequence here.\n\n\t\tfor (const persistedId of newPersistedIds) {\n\t\t\tif (!state.children.has(persistedId)) {\n\t\t\t\tpersistedWithoutState.push(persistedId)\n\t\t\t}\n\t\t}\n\t\tfor (const [stateId, child] of state.children) {\n\t\t\tconst childRuntimeId = child.entity.id\n\t\t\tif (!newPersistedIds.has(stateId)) {\n\t\t\t\tif (\n\t\t\t\t\t// It's a uuid but it's not among the persisted so either it got deleted/disconnected or the client-side\n\t\t\t\t\t// id generation didn't quite pan out.\n\t\t\t\t\tchildRuntimeId instanceof ServerId ||\n\t\t\t\t\tchildRuntimeId instanceof ClientGeneratedUuid ||\n\t\t\t\t\t// No persisted entity id to allocate to this so that's a goodbye.\n\t\t\t\t\tpersistedWithoutState.length === 0\n\t\t\t\t) {\n\t\t\t\t\tstate.getAccessor().disconnectEntity(child.getAccessor())\n\t\t\t\t\tcontinue\n\t\t\t\t} else {\n\t\t\t\t\tconst drawnId = persistedWithoutState.shift()!\n\t\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\t\tthis.treeStore,\n\t\t\t\t\t\tthis.eventManager,\n\t\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\t\tchild,\n\t\t\t\t\t\tnew ServerId(drawnId, child.entity.entityName),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (childRuntimeId instanceof ClientGeneratedUuid) {\n\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\tthis.treeStore,\n\t\t\t\t\tthis.eventManager,\n\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\tchild,\n\t\t\t\t\tnew ServerId(childRuntimeId.value, child.entity.entityName),\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t}\n\t\t}\n\t\tfor (const unclaimedPersistedId of persistedWithoutState) {\n\t\t\tthis.stateInitializer.initializeEntityRealm(new ServerId(unclaimedPersistedId, state.entityName), state.entityName, {\n\t\t\t\ttype: 'listEntity',\n\t\t\t\tparent: state,\n\t\t\t})\n\t\t}\n\t\t// All that remains now is the order.\n\t\tstate.children.changeKeyOrder(newPersistedIds)\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAmBO,MAAM,cAAc;AAAA,EACnB,YACW,cACA,kBACA,WACA,8BAAuC,OACvD;AAJgB,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AACA,SAAA,8BAAA;AAAA,EACf;AAAA,EAEI,oBAAoB,kBAAoC,YAA4B;AAErF,SAAA,UAAU,qBAAqB,kBAAkB,UAAU;AAAA,EACjE;AAAA,EAEO,iBAAiB,WAAmC,eAAqC;AACzF,UAAA,oCAAyD;AAE/D,SAAK,UAAU,YAAY,IAAI,WAAW,aAAa;AACvD,SAAK,UAAU,oBAAoB,IAAI,WAAW,aAAa;AAE/D,eAAW,CAAC,iBAAiB,gBAAgB,KAAK,cAAc,UAAU;AACzE,YAAM,WAAW,KAAK,iBAAiB,kBAAkB,gBAAgB;AAC3D,oBAAA,IAAI,iBAAiB,QAAQ;AAAA,IAC5C;AAAA,EACD;AAAA,EAEO,oBAAoB,UAA4B,YAAoC;AACrF,SAAA,UAAU,wBAAwB,UAAU,UAAU;AAC3D,QAAI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A,OACM;AACA,gBAAA,UAAU,sBAAsB;AACpB,4BAAA;AAAA,YACjB,KAAK;AAAA,YACL,KAAK;AAAA,YACL,KAAK;AAAA,YACL;AAAA,YACA,IAAI,SAAS,SAAS,MAAM,OAAO,UAAU;AAAA,UAAA;AAAA,QAE/C;AAAA,MAAA,WACU,0BAA0B,qBAAqB;AACvC,0BAAA;AAAA,UACjB,KAAK;AAAA,UACL,KAAK;AAAA,UACL,KAAK;AAAA,UACL;AAAA,UACA,IAAI,SAAS,eAAe,OAAO,MAAM,OAAO,UAAU;AAAA,QAAA;AAAA,MAE5D;AACI,UAAA,MAAM,SAAS,eAAe;AACjC,aAAK,+BAA+B,KAAK;AAAA,MAC1C;AAAA,IACD;AACA,eAAW,wBAAwB,uBAAuB;AACpD,WAAA,iBAAiB,sBAAsB,IAAI,SAAS,sBAAsB,MAAM,UAAU,GAAG,MAAM,YAAY;AAAA,QACnH,MAAM;AAAA,QACN,QAAQ;AAAA,MAAA,CACR;AAAA,IACF;AAEM,UAAA,SAAS,eAAe,eAAe;AAAA,EAC9C;AACD;"}
1
+ {"version":3,"file":"TreeAugmenter.js","sources":["../../../src/core/TreeAugmenter.ts"],"sourcesContent":["import {\n\tClientGeneratedUuid,\n\tEntityListPersistedData,\n\tReceivedDataTree,\n\tRuntimeId,\n\tServerId,\n\tUnpersistedEntityDummyId,\n} from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { EntityId, PlaceholderName, TreeRootId } from '../treeParameters'\nimport { assert, assertNever } from '../utils'\nimport { EventManager } from './EventManager'\nimport { OperationsHelpers } from './operations/OperationsHelpers'\nimport type { EntityListState, EntityRealmState, EntityRealmStateStub, RootStateNode } from './state'\nimport type { StateInitializer } from './StateInitializer'\nimport type { TreeStore } from './TreeStore'\nimport { SubMutationOperation } from './MutationGenerator'\n\nexport class TreeAugmenter {\n\tpublic constructor(\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly skipStateUpdateAfterPersist: boolean = false,\n\t) {}\n\n\tpublic extendPersistedData(newPersistedData: ReceivedDataTree, markerTree: MarkerTreeRoot) {\n\t\t// TODO this doesn't yet handle updates for entities whose persisted data just gets magically changed without notice.\n\t\tthis.treeStore.mergeInQueryResponse(newPersistedData, markerTree)\n\t}\n\n\tpublic extendTreeStates(newTreeId: TreeRootId | undefined, newMarkerTree: MarkerTreeRoot): void {\n\t\tconst subTreeStates: Map<PlaceholderName, RootStateNode> = new Map()\n\n\t\tthis.treeStore.markerTrees.set(newTreeId, newMarkerTree)\n\t\tthis.treeStore.subTreeStatesByRoot.set(newTreeId, subTreeStates)\n\n\t\tfor (const [placeholderName, newSubTreeMarker] of newMarkerTree.subTrees) {\n\t\t\tconst newState = this.stateInitializer.initializeSubTree(newSubTreeMarker)\n\t\t\tsubTreeStates.set(placeholderName, newState)\n\t\t}\n\t}\n\n\tpublic updatePersistedData(response: ReceivedDataTree, operations: SubMutationOperation[]) {\n\t\tthis.treeStore.mergeInMutationResponse(response, operations)\n\t\tif (this.skipStateUpdateAfterPersist) {\n\t\t\treturn\n\t\t}\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\t\t// for (const rootPlaceholder in response) {\n\t\t\t\t// \tconst rootState = rootStates.get(rootPlaceholder)\n\t\t\t\t//\n\t\t\t\t// \tif (rootState === undefined) {\n\t\t\t\t// \t\tcontinue\n\t\t\t\t// \t}\n\t\t\t\t// TODO the above would be better, only refreshing roots which participated in the mutation. However, due to\n\t\t\t\t// \thow mutations are currently generated, we cannot assume that only roots present in the response need\n\t\t\t\t// \trefreshed. So we just refresh all.\n\t\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\t\tconst rootData = this.treeStore.subTreePersistedData.get(rootPlaceholder)\n\n\t\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\t\tif (!(rootData instanceof Set)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateEntityListPersistedData(rootState, rootData)\n\t\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\t\tif (rootData !== undefined && !(rootData instanceof ServerId)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateRealmIdIfNecessary(rootState, rootData)\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(rootState)\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn assertNever(rootState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic resetCreatingSubTrees() {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\tassert(rootState.blueprint.parent === undefined)\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst changesCount = rootState.unpersistedChangesCount\n\n\t\t\t\t\t// Just emptying the list. But the list itself can stay.\n\t\t\t\t\tfor (const childState of rootState.children.values()) {\n\t\t\t\t\t\tthis.treeStore.disposeOfRealm(childState)\n\t\t\t\t\t}\n\t\t\t\t\trootState.accessor = undefined\n\t\t\t\t\trootState.children.clear()\n\t\t\t\t\trootState.childrenWithPendingUpdates?.clear()\n\t\t\t\t\trootState.errors = undefined\n\t\t\t\t\trootState.plannedRemovals?.clear()\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(\n\t\t\t\t\t\trootState,\n\t\t\t\t\t\tchangesCount ? -1 * changesCount : EventManager.NO_CHANGES_DIFFERENCE,\n\t\t\t\t\t)\n\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\tassert(rootState.blueprint.parent === undefined)\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst presentListeners = rootState.eventListeners\n\t\t\t\t\tthis.treeStore.disposeOfRealm(rootState)\n\n\t\t\t\t\t// It's crucial to delete the persisted data before we re-initialize so that we get a fresh, new entity.\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst newRootState = this.stateInitializer.initializeSubTree(rootState.blueprint.marker)\n\n\t\t\t\t\t// We preserve the previous listeners but purge some of them.\n\t\t\t\t\tnewRootState.eventListeners = presentListeners\n\t\t\t\t\tOperationsHelpers.purgeStaleListenersAfterIdChange(newRootState as EntityRealmState)\n\n\t\t\t\t\trootStates.set(rootPlaceholder, newRootState)\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(newRootState, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(rootState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateRealmIdIfNecessary(\n\t\trealm: EntityRealmState | EntityRealmStateStub,\n\t\tnewId: ServerId | undefined | null,\n\t) {\n\t\tconst currentId = realm.entity.id\n\t\tlet idToChangeTo: RuntimeId | undefined = undefined\n\n\t\tif (currentId instanceof ServerId) {\n\t\t\tif (newId === undefined || newId === null) {\n\t\t\t\tidToChangeTo = new UnpersistedEntityDummyId()\n\t\t\t} else if (currentId.value !== newId.value) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else if (currentId instanceof ClientGeneratedUuid) {\n\t\t\tidToChangeTo = newId ?? new UnpersistedEntityDummyId()\n\t\t} else if (currentId instanceof UnpersistedEntityDummyId) {\n\t\t\tif (newId) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else {\n\t\t\treturn assertNever(currentId)\n\t\t}\n\t\tif (idToChangeTo) {\n\t\t\tOperationsHelpers.changeRealmId(this.treeStore, this.eventManager, this.stateInitializer, realm, idToChangeTo)\n\t\t}\n\t}\n\n\tprivate updateEntityRealmPersistedData(realm: EntityRealmState) {\n\t\tconst realmId = realm.entity.id\n\t\tconst persistedData = realmId.existsOnServer ? this.treeStore.persistedEntityData.get(realmId.uniqueValue) : undefined\n\n\t\tfor (const [placeholderName, child] of realm.children) {\n\t\t\tconst childData = persistedData?.get(placeholderName)\n\n\t\t\tswitch (child.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (childData instanceof ServerId || childData instanceof Set) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (child.persistedValue !== childData) {\n\t\t\t\t\t\tconst shouldChangeBothValues = child.persistedValue === child.value\n\n\t\t\t\t\t\tchild.persistedValue = childData\n\t\t\t\t\t\tif (shouldChangeBothValues) {\n\t\t\t\t\t\t\tchild.value = childData ?? null\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.eventManager.registerJustUpdated(child, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\tif (!(childData instanceof ServerId) && childData !== undefined && childData !== null) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateRealmIdIfNecessary(child, childData)\n\t\t\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (childData !== undefined && !(childData instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateEntityListPersistedData(child, childData ?? new Set()) // TODO!!\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn assertNever(child)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateEntityListPersistedData(state: EntityListState, newPersistedIds: EntityListPersistedData) {\n\t\tconst persistedWithoutState: EntityId[] = []\n\n\t\t// TODO This isn't particularly efficient. We should probably use something like diff-sequence here.\n\n\t\tfor (const persistedId of newPersistedIds) {\n\t\t\tif (!state.children.has(persistedId)) {\n\t\t\t\tpersistedWithoutState.push(persistedId)\n\t\t\t}\n\t\t}\n\t\tfor (const [stateId, child] of state.children) {\n\t\t\tconst childRuntimeId = child.entity.id\n\t\t\tif (!newPersistedIds.has(stateId)) {\n\t\t\t\tif (\n\t\t\t\t\t// It's a uuid but it's not among the persisted so either it got deleted/disconnected or the client-side\n\t\t\t\t\t// id generation didn't quite pan out.\n\t\t\t\t\tchildRuntimeId instanceof ServerId ||\n\t\t\t\t\tchildRuntimeId instanceof ClientGeneratedUuid ||\n\t\t\t\t\t// No persisted entity id to allocate to this so that's a goodbye.\n\t\t\t\t\tpersistedWithoutState.length === 0\n\t\t\t\t) {\n\t\t\t\t\tstate.getAccessor().disconnectEntity(child.getAccessor())\n\t\t\t\t\tcontinue\n\t\t\t\t} else {\n\t\t\t\t\tconst drawnId = persistedWithoutState.shift()!\n\t\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\t\tthis.treeStore,\n\t\t\t\t\t\tthis.eventManager,\n\t\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\t\tchild,\n\t\t\t\t\t\tnew ServerId(drawnId, child.entity.entityName),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (childRuntimeId instanceof ClientGeneratedUuid) {\n\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\tthis.treeStore,\n\t\t\t\t\tthis.eventManager,\n\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\tchild,\n\t\t\t\t\tnew ServerId(childRuntimeId.value, child.entity.entityName),\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t}\n\t\t}\n\t\tfor (const unclaimedPersistedId of persistedWithoutState) {\n\t\t\tthis.stateInitializer.initializeEntityRealm(new ServerId(unclaimedPersistedId, state.entityName), state.entityName, {\n\t\t\t\ttype: 'listEntity',\n\t\t\t\tparent: state,\n\t\t\t})\n\t\t}\n\t\t// All that remains now is the order.\n\t\tstate.children.changeKeyOrder(newPersistedIds)\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAmBO,MAAM,cAAc;AAAA,EACnB,YACW,cACA,kBACA,WACA,8BAAuC,OACvD;AAJgB,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AACA,SAAA,8BAAA;AAAA,EACf;AAAA,EAEI,oBAAoB,kBAAoC,YAA4B;AAErF,SAAA,UAAU,qBAAqB,kBAAkB,UAAU;AAAA,EACjE;AAAA,EAEO,iBAAiB,WAAmC,eAAqC;AACzF,UAAA,oCAAyD;AAE/D,SAAK,UAAU,YAAY,IAAI,WAAW,aAAa;AACvD,SAAK,UAAU,oBAAoB,IAAI,WAAW,aAAa;AAE/D,eAAW,CAAC,iBAAiB,gBAAgB,KAAK,cAAc,UAAU;AACzE,YAAM,WAAW,KAAK,iBAAiB,kBAAkB,gBAAgB;AAC3D,oBAAA,IAAI,iBAAiB,QAAQ;AAAA,IAC5C;AAAA,EACD;AAAA,EAEO,oBAAoB,UAA4B,YAAoC;AACrF,SAAA,UAAU,wBAAwB,UAAU,UAAU;AAC3D,QAAI,KAAK,6BAA6B;AACrC;AAAA,IACD;AACK,SAAA,aAAa,gBAAgB,MAAM;AACvC,iBAAW,cAAc,KAAK,UAAU,oBAAoB,UAAU;AAUrE,mBAAW,CAAC,iBAAiB,SAAS,KAAK,YAAY;AACtD,gBAAM,WAAW,KAAK,UAAU,qBAAqB,IAAI,eAAe;AAEpE,cAAA,UAAU,SAAS,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WACU,0BAA0B,qBAAqB;AACvC,0BAAA;AAAA,UACjB,KAAK;AAAA,UACL,KAAK;AAAA,UACL,KAAK;AAAA,UACL;AAAA,UACA,IAAI,SAAS,eAAe,OAAO,MAAM,OAAO,UAAU;AAAA,QAAA;AAAA,MAE5D;AACI,UAAA,MAAM,SAAS,eAAe;AACjC,aAAK,+BAA+B,KAAK;AAAA,MAC1C;AAAA,IACD;AACA,eAAW,wBAAwB,uBAAuB;AACpD,WAAA,iBAAiB,sBAAsB,IAAI,SAAS,sBAAsB,MAAM,UAAU,GAAG,MAAM,YAAY;AAAA,QACnH,MAAM;AAAA,QACN,QAAQ;AAAA,MAAA,CACR;AAAA,IACF;AAEM,UAAA,SAAS,eAAe,eAAe;AAAA,EAC9C;AACD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"TreeParameterMerger.js","sources":["../../../src/core/TreeParameterMerger.ts"],"sourcesContent":["import { GraphQlBuilder } from '@contember/client'\nimport { BindingError } from '../BindingError'\nimport type {\n\tAlias,\n\tEntityCreationParameters,\n\tEntityEventListenerStore,\n\tEntityListEventListenerStore,\n\tExpectedQualifiedEntityMutation,\n\tExpectedRelationMutation,\n\tHasManyRelation,\n\tHasOneRelation,\n\tParentEntityParameters,\n\tQualifiedEntityList,\n\tQualifiedSingleEntity,\n\tSetOnCreate,\n\tUnconstrainedQualifiedEntityList,\n\tUnconstrainedQualifiedSingleEntity,\n\tUniqueWhere,\n} from '../treeParameters'\n\nexport class TreeParameterMerger {\n\tpublic static mergeHasOneRelationsWithSamePlaceholders(\n\t\toriginal: HasOneRelation,\n\t\tfresh: HasOneRelation,\n\t): HasOneRelation {\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tfield: original.field,\n\t\t\tfilter: original.filter,\n\t\t\treducedBy: original.reducedBy,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\texpectedMutation: this.mergeExpectedRelationMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\t// forceCreation: original.forceCreation || fresh.forceCreation,\n\t\t\teventListeners: this.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeHasManyRelationsWithSamePlaceholders(\n\t\toriginal: HasManyRelation,\n\t\tfresh: HasManyRelation,\n\t): HasManyRelation {\n\t\tif (original.initialEntityCount !== fresh.initialEntityCount) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Detected hasMany relations on the same field '${original.field}' with different preferred initial ` +\n\t\t\t\t\t`entity counts: '${original.initialEntityCount}' and '${fresh.initialEntityCount}' respectively.`,\n\t\t\t)\n\t\t}\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tfield: original.field,\n\t\t\tfilter: original.filter,\n\t\t\torderBy: original.orderBy,\n\t\t\toffset: original.offset,\n\t\t\tlimit: original.limit,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\texpectedMutation: this.mergeExpectedRelationMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t// forceCreation: original.forceCreation || fresh.forceCreation,\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\tinitialEntityCount: original.initialEntityCount, // Handled above\n\t\t\tchildEventListeners: this.mergeSingleEntityEventListeners(\n\t\t\t\toriginal.childEventListeners,\n\t\t\t\tfresh.childEventListeners,\n\t\t\t),\n\t\t\teventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeEntitySubTreeParametersWithSamePlaceholders(\n\t\toriginal: QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity,\n\t\tfresh: QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity,\n\t): QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity {\n\t\tif (original.isCreating) {\n\t\t\treturn {\n\t\t\t\t// Encoded within the placeholder\n\t\t\t\tisCreating: original.isCreating,\n\t\t\t\tentityName: original.entityName,\n\n\t\t\t\t// Not encoded within the placeholder\n\t\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\t\teventListeners: this.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tisCreating: original.isCreating,\n\t\t\twhere: original.where,\n\t\t\tentityName: original.entityName,\n\t\t\tfilter: original.filter,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\teventListeners: this.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeEntityListSubTreeParametersWithSamePlaceholders(\n\t\toriginal: QualifiedEntityList | UnconstrainedQualifiedEntityList,\n\t\tfresh: QualifiedEntityList | UnconstrainedQualifiedEntityList,\n\t): QualifiedEntityList | UnconstrainedQualifiedEntityList {\n\t\tif (original.initialEntityCount !== fresh.initialEntityCount) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Detected sub trees of the same entity '${original.entityName}' with different preferred initial ` +\n\t\t\t\t\t`entity counts: '${original.initialEntityCount}' and '${fresh.initialEntityCount}' respectively.`,\n\t\t\t)\n\t\t}\n\n\t\tif (original.isCreating) {\n\t\t\treturn {\n\t\t\t\t// Encoded within the placeholder\n\t\t\t\tisCreating: original.isCreating,\n\t\t\t\tentityName: original.entityName,\n\n\t\t\t\t// Not encoded within the placeholder\n\t\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\t\tchildEventListeners: this.mergeSingleEntityEventListeners(\n\t\t\t\t\toriginal.childEventListeners,\n\t\t\t\t\tfresh.childEventListeners,\n\t\t\t\t),\n\t\t\t\teventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t\t\tinitialEntityCount: original.initialEntityCount, // Handled above\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tisCreating: original.isCreating,\n\t\t\tentityName: original.entityName,\n\t\t\tfilter: original.filter,\n\t\t\torderBy: original.orderBy,\n\t\t\toffset: original.offset,\n\t\t\tlimit: original.limit,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\tchildEventListeners: this.mergeSingleEntityEventListeners(\n\t\t\t\toriginal.childEventListeners,\n\t\t\t\tfresh.childEventListeners,\n\t\t\t),\n\t\t\teventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t\tinitialEntityCount: original.initialEntityCount, // Handled above\n\t\t}\n\t}\n\n\tpublic static mergeEntityCreationParameters(\n\t\toriginal: EntityCreationParameters,\n\t\tfresh: EntityCreationParameters,\n\t): EntityCreationParameters {\n\t\treturn {\n\t\t\t// forceCreation: original.forceCreation || fresh.forceCreation,\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t}\n\t}\n\n\tpublic static mergeSetOnCreate(original: SetOnCreate, fresh: SetOnCreate): SetOnCreate {\n\t\tif (original === undefined && fresh === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\tconst originalCopy: UniqueWhere = { ...original }\n\n\t\tfor (const field in fresh) {\n\t\t\tif (field in originalCopy) {\n\t\t\t\tconst fromOriginal = originalCopy[field]\n\t\t\t\tconst fromFresh = fresh[field]\n\n\t\t\t\tif (fromOriginal instanceof GraphQlBuilder.GraphQlLiteral) {\n\t\t\t\t\tif (fromFresh instanceof GraphQlBuilder.GraphQlLiteral) {\n\t\t\t\t\t\tif (fromOriginal.value === fromFresh.value) {\n\t\t\t\t\t\t\t// Good, do nothing.\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (typeof fromOriginal === 'object') {\n\t\t\t\t\tif (fromFresh instanceof GraphQlBuilder.GraphQlLiteral) {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t} else if (typeof fromFresh === 'object') {\n\t\t\t\t\t\tconst merged = this.mergeSetOnCreate(fromOriginal, fromFresh)\n\t\t\t\t\t\tif (merged !== undefined) {\n\t\t\t\t\t\t\toriginalCopy[field] = merged\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (typeof fromFresh === 'string' || typeof fromFresh === 'number') {\n\t\t\t\t\tif (fromOriginal === fromFresh) {\n\t\t\t\t\t\t// Good, do nothing.\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t} else {\n\t\t\t\toriginalCopy[field] = fresh[field]\n\t\t\t}\n\t\t}\n\n\t\treturn originalCopy\n\t}\n\n\tprivate static mergeSets<T>(original: Set<T>, fresh: Set<T>): Set<T> {\n\t\tconst combinedSet = new Set(original)\n\t\tfor (const item of fresh) {\n\t\t\tcombinedSet.add(item)\n\t\t}\n\t\treturn combinedSet\n\t}\n\n\tpublic static mergeParentEntityParameters(\n\t\toriginal: ParentEntityParameters | undefined,\n\t\tfresh: ParentEntityParameters | undefined,\n\t): ParentEntityParameters | undefined {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\treturn {\n\t\t\teventListeners: TreeParameterMerger.mergeSingleEntityEventListeners(\n\t\t\t\toriginal.eventListeners,\n\t\t\t\tfresh.eventListeners,\n\t\t\t),\n\t\t}\n\t}\n\n\tpublic static mergeInParentEntity<\n\t\tOriginal extends Record<Key, EntityEventListenerStore | undefined>,\n\t\tKey extends keyof Original,\n\t>(original: Original, key: Key, parentEntity: ParentEntityParameters | undefined): Original {\n\t\tif (!parentEntity) {\n\t\t\treturn original\n\t\t}\n\n\t\treturn {\n\t\t\t...original,\n\t\t\t[key]: TreeParameterMerger.mergeSingleEntityEventListeners(original[key], parentEntity.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeSingleEntityEventListeners(\n\t\toriginal: EntityEventListenerStore | undefined,\n\t\tfresh: EntityEventListenerStore | undefined,\n\t): EntityEventListenerStore | undefined {\n\t\tif (original === undefined) {\n\t\t\tif (fresh === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn this.cloneSingleEntityEventListeners(fresh)\n\t\t}\n\n\t\tif (fresh === undefined) {\n\t\t\treturn this.cloneSingleEntityEventListeners(original)\n\t\t}\n\n\t\tconst store = this.cloneSingleEntityEventListeners(original)\n\t\tstore.append(fresh)\n\t\treturn store\n\t}\n\n\tpublic static mergeEntityListEventListeners(\n\t\toriginal: EntityListEventListenerStore | undefined,\n\t\tfresh: EntityListEventListenerStore | undefined,\n\t): EntityListEventListenerStore | undefined {\n\t\tif (original === undefined) {\n\t\t\tif (fresh === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn this.cloneEntityListEventListeners(fresh)\n\t\t}\n\n\t\tif (fresh === undefined) {\n\t\t\treturn this.cloneEntityListEventListeners(original)\n\t\t}\n\n\t\tconst store = this.cloneEntityListEventListeners(original)\n\t\tstore.append(fresh)\n\t\treturn store\n\t}\n\n\tpublic static cloneSingleEntityEventListeners(store: EntityEventListenerStore): EntityEventListenerStore {\n\t\t// TODO is intentional, that second clone is deep?\n\t\treturn store.clone()\n\t}\n\n\tpublic static cloneEntityListEventListeners(store: EntityListEventListenerStore): EntityListEventListenerStore {\n\t\treturn store.cloneDeep()\n\t}\n\n\tprivate static mergeExpectedRelationMutation(\n\t\toriginal: ExpectedRelationMutation,\n\t\tfresh: ExpectedRelationMutation,\n\t): ExpectedRelationMutation {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === 'none') {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === 'none') {\n\t\t\treturn original\n\t\t}\n\t\treturn 'anyMutation'\n\t}\n\n\tprivate static mergeExpectedQualifiedEntityMutation(\n\t\toriginal: ExpectedQualifiedEntityMutation,\n\t\tfresh: ExpectedQualifiedEntityMutation,\n\t): ExpectedQualifiedEntityMutation {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === 'none') {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === 'none') {\n\t\t\treturn original\n\t\t}\n\t\treturn 'anyMutation'\n\t}\n\n\tprivate static mergeSubTreeAliases(\n\t\toriginal: Set<Alias> | undefined,\n\t\tfresh: Set<Alias> | undefined,\n\t): Set<Alias> | undefined {\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\treturn this.mergeSets(original, fresh)\n\t}\n}\n"],"names":[],"mappings":";;AAoBO,MAAM,oBAAoB;AAAA,EAChC,OAAc,yCACb,UACA,OACiB;AACV,WAAA;AAAA,MAEN,OAAO,SAAS;AAAA,MAChB,QAAQ,SAAS;AAAA,MACjB,WAAW,SAAS;AAAA,MAGpB,kBAAkB,KAAK,8BAA8B,SAAS,kBAAkB,MAAM,gBAAgB;AAAA,MACtG,aAAa,KAAK,iBAAiB,SAAS,aAAa,MAAM,WAAW;AAAA,MAC1E,cAAc,SAAS,gBAAgB,MAAM;AAAA,MAE7C,gBAAgB,KAAK,gCAAgC,SAAS,gBAAgB,MAAM,cAAc;AAAA,IAAA;AAAA,EAEpG;AAAA,EAEA,OAAc,0CACb,UACA,OACkB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gCAAgC,QAAQ;AAAA,IACrD;AAEM,UAAA,QAAQ,KAAK,gCAAgC,QAAQ;AAC3D,UAAM,OAAO,KAAK;AACX,WAAA;AAAA,EACR;AAAA,EAEA,OAAc,8BACb,UACA,OAC2C;AAC3C,QAAI,aAAa,QAAW;AAC3B,UAAI,UAAU,QAAW;AACjB,eAAA;AAAA,MACR;AACO,aAAA,KAAK,8BAA8B,KAAK;AAAA,IAChD;AAEA,QAAI,UAAU,QAAW;AACjB,aAAA,KAAK,8BAA8B,QAAQ;AAAA,IACnD;AAEM,UAAA,QAAQ,KAAK,8BAA8B,QAAQ;AACzD,UAAM,OAAO,KAAK;AACX,WAAA;AAAA,EACR;AAAA,EAEA,OAAc,gCAAgC,OAA2D;AAExG,WAAO,MAAM;EACd;AAAA,EAEA,OAAc,8BAA8B,OAAmE;AAC9G,WAAO,MAAM;EACd;AAAA,EAEA,OAAe,8BACd,UACA,OAC2B;AAC3B,QAAI,aAAa,OAAO;AAChB,aAAA;AAAA,IACR;AACA,QAAI,aAAa,QAAQ;AACjB,aAAA;AAAA,IACR;AACA,QAAI,UAAU,QAAQ;AACd,aAAA;AAAA,IACR;AACO,WAAA;AAAA,EACR;AAAA,EAEA,OAAe,qCACd,UACA,OACkC;AAClC,QAAI,aAAa,OAAO;AAChB,aAAA;AAAA,IACR;AACA,QAAI,aAAa,QAAQ;AACjB,aAAA;AAAA,IACR;AACA,QAAI,UAAU,QAAQ;AACd,aAAA;AAAA,IACR;AACO,WAAA;AAAA,EACR;AAAA,EAEA,OAAe,oBACd,UACA,OACyB;AACzB,QAAI,aAAa,QAAW;AACpB,aAAA;AAAA,IACR;AACA,QAAI,UAAU,QAAW;AACjB,aAAA;AAAA,IACR;AACO,WAAA,KAAK,UAAU,UAAU,KAAK;AAAA,EACtC;AACD;"}
1
+ {"version":3,"file":"TreeParameterMerger.js","sources":["../../../src/core/TreeParameterMerger.ts"],"sourcesContent":["import { GraphQlBuilder, Writable } from '@contember/client'\nimport { BindingError } from '../BindingError'\nimport type {\n\tAlias,\n\tEntityCreationParameters,\n\tEntityEventListenerStore,\n\tEntityListEventListenerStore,\n\tExpectedQualifiedEntityMutation,\n\tExpectedRelationMutation,\n\tHasManyRelation,\n\tHasOneRelation,\n\tParentEntityParameters,\n\tQualifiedEntityList,\n\tQualifiedSingleEntity,\n\tSetOnCreate,\n\tUnconstrainedQualifiedEntityList,\n\tUnconstrainedQualifiedSingleEntity,\n\tUniqueWhere,\n} from '../treeParameters'\n\nexport class TreeParameterMerger {\n\tpublic static mergeHasOneRelationsWithSamePlaceholders(\n\t\toriginal: HasOneRelation,\n\t\tfresh: HasOneRelation,\n\t): HasOneRelation {\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tfield: original.field,\n\t\t\tfilter: original.filter,\n\t\t\treducedBy: original.reducedBy,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\texpectedMutation: this.mergeExpectedRelationMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\t// forceCreation: original.forceCreation || fresh.forceCreation,\n\t\t\teventListeners: this.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeHasManyRelationsWithSamePlaceholders(\n\t\toriginal: HasManyRelation,\n\t\tfresh: HasManyRelation,\n\t): HasManyRelation {\n\t\tif (original.initialEntityCount !== fresh.initialEntityCount) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Detected hasMany relations on the same field '${original.field}' with different preferred initial ` +\n\t\t\t\t\t`entity counts: '${original.initialEntityCount}' and '${fresh.initialEntityCount}' respectively.`,\n\t\t\t)\n\t\t}\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tfield: original.field,\n\t\t\tfilter: original.filter,\n\t\t\torderBy: original.orderBy,\n\t\t\toffset: original.offset,\n\t\t\tlimit: original.limit,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\texpectedMutation: this.mergeExpectedRelationMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t// forceCreation: original.forceCreation || fresh.forceCreation,\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\tinitialEntityCount: original.initialEntityCount, // Handled above\n\t\t\tchildEventListeners: this.mergeSingleEntityEventListeners(\n\t\t\t\toriginal.childEventListeners,\n\t\t\t\tfresh.childEventListeners,\n\t\t\t),\n\t\t\teventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeEntitySubTreeParametersWithSamePlaceholders(\n\t\toriginal: QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity,\n\t\tfresh: QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity,\n\t): QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity {\n\t\tif (original.isCreating) {\n\t\t\treturn {\n\t\t\t\t// Encoded within the placeholder\n\t\t\t\tisCreating: original.isCreating,\n\t\t\t\tentityName: original.entityName,\n\n\t\t\t\t// Not encoded within the placeholder\n\t\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\t\teventListeners: this.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tisCreating: original.isCreating,\n\t\t\twhere: original.where,\n\t\t\tentityName: original.entityName,\n\t\t\tfilter: original.filter,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\teventListeners: this.mergeSingleEntityEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeEntityListSubTreeParametersWithSamePlaceholders(\n\t\toriginal: QualifiedEntityList | UnconstrainedQualifiedEntityList,\n\t\tfresh: QualifiedEntityList | UnconstrainedQualifiedEntityList,\n\t): QualifiedEntityList | UnconstrainedQualifiedEntityList {\n\t\tif (original.initialEntityCount !== fresh.initialEntityCount) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Detected sub trees of the same entity '${original.entityName}' with different preferred initial ` +\n\t\t\t\t\t`entity counts: '${original.initialEntityCount}' and '${fresh.initialEntityCount}' respectively.`,\n\t\t\t)\n\t\t}\n\n\t\tif (original.isCreating) {\n\t\t\treturn {\n\t\t\t\t// Encoded within the placeholder\n\t\t\t\tisCreating: original.isCreating,\n\t\t\t\tentityName: original.entityName,\n\n\t\t\t\t// Not encoded within the placeholder\n\t\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\t\tchildEventListeners: this.mergeSingleEntityEventListeners(\n\t\t\t\t\toriginal.childEventListeners,\n\t\t\t\t\tfresh.childEventListeners,\n\t\t\t\t),\n\t\t\t\teventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t\t\tinitialEntityCount: original.initialEntityCount, // Handled above\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\t// Encoded within the placeholder\n\t\t\tisCreating: original.isCreating,\n\t\t\tentityName: original.entityName,\n\t\t\tfilter: original.filter,\n\t\t\torderBy: original.orderBy,\n\t\t\toffset: original.offset,\n\t\t\tlimit: original.limit,\n\n\t\t\t// Not encoded within the placeholder\n\t\t\talias: this.mergeSubTreeAliases(original.alias, fresh.alias),\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t\t// forceCreation: original.value.forceCreation || fresh.value.forceCreation,\n\t\t\texpectedMutation: this.mergeExpectedQualifiedEntityMutation(original.expectedMutation, fresh.expectedMutation),\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\thasOneRelationPath: original.hasOneRelationPath, // TODO this is completely wrong.\n\t\t\tchildEventListeners: this.mergeSingleEntityEventListeners(\n\t\t\t\toriginal.childEventListeners,\n\t\t\t\tfresh.childEventListeners,\n\t\t\t),\n\t\t\teventListeners: this.mergeEntityListEventListeners(original.eventListeners, fresh.eventListeners),\n\t\t\tinitialEntityCount: original.initialEntityCount, // Handled above\n\t\t}\n\t}\n\n\tpublic static mergeEntityCreationParameters(\n\t\toriginal: EntityCreationParameters,\n\t\tfresh: EntityCreationParameters,\n\t): EntityCreationParameters {\n\t\treturn {\n\t\t\t// forceCreation: original.forceCreation || fresh.forceCreation,\n\t\t\tisNonbearing: original.isNonbearing && fresh.isNonbearing,\n\t\t\tsetOnCreate: this.mergeSetOnCreate(original.setOnCreate, fresh.setOnCreate),\n\t\t}\n\t}\n\n\tpublic static mergeSetOnCreate(original: SetOnCreate, fresh: SetOnCreate): SetOnCreate {\n\t\tif (original === undefined && fresh === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\tconst originalCopy: Writable<UniqueWhere> = { ...original }\n\n\t\tfor (const field in fresh) {\n\t\t\tif (field in originalCopy) {\n\t\t\t\tconst fromOriginal = originalCopy[field]\n\t\t\t\tconst fromFresh = fresh[field]\n\n\t\t\t\tif (fromOriginal instanceof GraphQlBuilder.GraphQlLiteral) {\n\t\t\t\t\tif (fromFresh instanceof GraphQlBuilder.GraphQlLiteral) {\n\t\t\t\t\t\tif (fromOriginal.value === fromFresh.value) {\n\t\t\t\t\t\t\t// Good, do nothing.\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (typeof fromOriginal === 'object') {\n\t\t\t\t\tif (fromFresh instanceof GraphQlBuilder.GraphQlLiteral) {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t} else if (typeof fromFresh === 'object') {\n\t\t\t\t\t\tconst merged = this.mergeSetOnCreate(fromOriginal, fromFresh)\n\t\t\t\t\t\tif (merged !== undefined) {\n\t\t\t\t\t\t\toriginalCopy[field] = merged\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (typeof fromFresh === 'string' || typeof fromFresh === 'number') {\n\t\t\t\t\tif (fromOriginal === fromFresh) {\n\t\t\t\t\t\t// Good, do nothing.\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthrow new BindingError() // TODO msg\n\t\t\t} else {\n\t\t\t\toriginalCopy[field] = fresh[field]\n\t\t\t}\n\t\t}\n\n\t\treturn originalCopy\n\t}\n\n\tprivate static mergeSets<T>(original: Set<T>, fresh: Set<T>): Set<T> {\n\t\tconst combinedSet = new Set(original)\n\t\tfor (const item of fresh) {\n\t\t\tcombinedSet.add(item)\n\t\t}\n\t\treturn combinedSet\n\t}\n\n\tpublic static mergeParentEntityParameters(\n\t\toriginal: ParentEntityParameters | undefined,\n\t\tfresh: ParentEntityParameters | undefined,\n\t): ParentEntityParameters | undefined {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\treturn {\n\t\t\teventListeners: TreeParameterMerger.mergeSingleEntityEventListeners(\n\t\t\t\toriginal.eventListeners,\n\t\t\t\tfresh.eventListeners,\n\t\t\t),\n\t\t}\n\t}\n\n\tpublic static mergeInParentEntity<\n\t\tOriginal extends Record<Key, EntityEventListenerStore | undefined>,\n\t\tKey extends keyof Original,\n\t>(original: Original, key: Key, parentEntity: ParentEntityParameters | undefined): Original {\n\t\tif (!parentEntity) {\n\t\t\treturn original\n\t\t}\n\n\t\treturn {\n\t\t\t...original,\n\t\t\t[key]: TreeParameterMerger.mergeSingleEntityEventListeners(original[key], parentEntity.eventListeners),\n\t\t}\n\t}\n\n\tpublic static mergeSingleEntityEventListeners(\n\t\toriginal: EntityEventListenerStore | undefined,\n\t\tfresh: EntityEventListenerStore | undefined,\n\t): EntityEventListenerStore | undefined {\n\t\tif (original === undefined) {\n\t\t\tif (fresh === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn this.cloneSingleEntityEventListeners(fresh)\n\t\t}\n\n\t\tif (fresh === undefined) {\n\t\t\treturn this.cloneSingleEntityEventListeners(original)\n\t\t}\n\n\t\tconst store = this.cloneSingleEntityEventListeners(original)\n\t\tstore.append(fresh)\n\t\treturn store\n\t}\n\n\tpublic static mergeEntityListEventListeners(\n\t\toriginal: EntityListEventListenerStore | undefined,\n\t\tfresh: EntityListEventListenerStore | undefined,\n\t): EntityListEventListenerStore | undefined {\n\t\tif (original === undefined) {\n\t\t\tif (fresh === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn this.cloneEntityListEventListeners(fresh)\n\t\t}\n\n\t\tif (fresh === undefined) {\n\t\t\treturn this.cloneEntityListEventListeners(original)\n\t\t}\n\n\t\tconst store = this.cloneEntityListEventListeners(original)\n\t\tstore.append(fresh)\n\t\treturn store\n\t}\n\n\tpublic static cloneSingleEntityEventListeners(store: EntityEventListenerStore): EntityEventListenerStore {\n\t\t// TODO is intentional, that second clone is deep?\n\t\treturn store.clone()\n\t}\n\n\tpublic static cloneEntityListEventListeners(store: EntityListEventListenerStore): EntityListEventListenerStore {\n\t\treturn store.cloneDeep()\n\t}\n\n\tprivate static mergeExpectedRelationMutation(\n\t\toriginal: ExpectedRelationMutation,\n\t\tfresh: ExpectedRelationMutation,\n\t): ExpectedRelationMutation {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === 'none') {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === 'none') {\n\t\t\treturn original\n\t\t}\n\t\treturn 'anyMutation'\n\t}\n\n\tprivate static mergeExpectedQualifiedEntityMutation(\n\t\toriginal: ExpectedQualifiedEntityMutation,\n\t\tfresh: ExpectedQualifiedEntityMutation,\n\t): ExpectedQualifiedEntityMutation {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === 'none') {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === 'none') {\n\t\t\treturn original\n\t\t}\n\t\treturn 'anyMutation'\n\t}\n\n\tprivate static mergeSubTreeAliases(\n\t\toriginal: Set<Alias> | undefined,\n\t\tfresh: Set<Alias> | undefined,\n\t): Set<Alias> | undefined {\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\treturn this.mergeSets(original, fresh)\n\t}\n}\n"],"names":[],"mappings":";;AAoBO,MAAM,oBAAoB;AAAA,EAChC,OAAc,yCACb,UACA,OACiB;AACV,WAAA;AAAA,MAEN,OAAO,SAAS;AAAA,MAChB,QAAQ,SAAS;AAAA,MACjB,WAAW,SAAS;AAAA,MAGpB,kBAAkB,KAAK,8BAA8B,SAAS,kBAAkB,MAAM,gBAAgB;AAAA,MACtG,aAAa,KAAK,iBAAiB,SAAS,aAAa,MAAM,WAAW;AAAA,MAC1E,cAAc,SAAS,gBAAgB,MAAM;AAAA,MAE7C,gBAAgB,KAAK,gCAAgC,SAAS,gBAAgB,MAAM,cAAc;AAAA,IAAA;AAAA,EAEpG;AAAA,EAEA,OAAc,0CACb,UACA,OACkB;AACd,QAAA,SAAS,uBAAuB,MAAM,oBAAoB;AAC7D,YAAM,IAAI;AAAA,QACT,iDAAiD,SAAS,2DACtC,SAAS,4BAA4B,MAAM;AAAA,MAAA;AAAA,IAEjE;AACO,WAAA;AAAA,MAEN,OAAO,SAAS;AAAA,MAChB,QAAQ,SAAS;AAAA,MACjB,SAAS,SAAS;AAAA,MAClB,QAAQ,SAAS;AAAA,MACjB,OAAO,SAAS;AAAA,MAGhB,kBAAkB,KAAK,8BAA8B,SAAS,kBAAkB,MAAM,gBAAgB;AAAA,MACtG,aAAa,KAAK,iBAAiB,SAAS,aAAa,MAAM,WAAW;AAAA,MAE1E,cAAc,SAAS,gBAAgB,MAAM;AAAA,MAC7C,oBAAoB,SAAS;AAAA,MAC7B,qBAAqB,KAAK;AAAA,QACzB,SAAS;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MACA,gBAAgB,KAAK,8BAA8B,SAAS,gBAAgB,MAAM,cAAc;A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