@contember/binding 1.1.0-alpha.0 → 1.1.0-alpha.11

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 (446) hide show
  1. package/dist/development/accessorPropagation/EnvironmentContext.js +28 -2
  2. package/dist/development/accessorPropagation/EnvironmentContext.js.map +1 -1
  3. package/dist/development/accessorPropagation/useEntityListSubTree.js +4 -2
  4. package/dist/development/accessorPropagation/useEntityListSubTree.js.map +1 -1
  5. package/dist/development/accessorPropagation/useEntitySubTree.js +4 -2
  6. package/dist/development/accessorPropagation/useEntitySubTree.js.map +1 -1
  7. package/dist/development/accessorPropagation/useExtendTree.js +27 -0
  8. package/dist/development/accessorPropagation/useExtendTree.js.map +1 -0
  9. package/dist/development/accessorTree/AccessorTree.js +16 -14
  10. package/dist/development/accessorTree/AccessorTree.js.map +1 -1
  11. package/dist/development/accessorTree/AccessorTreeStateContext.js +4 -0
  12. package/dist/development/accessorTree/AccessorTreeStateContext.js.map +1 -0
  13. package/dist/development/accessorTree/NormalizedPersistedData.js.map +1 -1
  14. package/dist/development/accessorTree/RuntimeId.js +17 -4
  15. package/dist/development/accessorTree/RuntimeId.js.map +1 -1
  16. package/dist/development/accessorTree/accessorTreeStateReducer.js +11 -2
  17. package/dist/development/accessorTree/accessorTreeStateReducer.js.map +1 -1
  18. package/dist/development/accessorTree/useAccessorTreeState.js +12 -0
  19. package/dist/development/accessorTree/useAccessorTreeState.js.map +1 -0
  20. package/dist/development/accessorTree/useDataBinding.js +41 -51
  21. package/dist/development/accessorTree/useDataBinding.js.map +1 -1
  22. package/dist/development/accessors/EntityAccessor.js +19 -40
  23. package/dist/development/accessors/EntityAccessor.js.map +1 -1
  24. package/dist/development/accessors/EntityListAccessor.js +11 -11
  25. package/dist/development/accessors/EntityListAccessor.js.map +1 -1
  26. package/dist/development/accessors/FieldAccessor.js +6 -6
  27. package/dist/development/accessors/FieldAccessor.js.map +1 -1
  28. package/dist/development/core/AccessorErrorManager.js +5 -2
  29. package/dist/development/core/AccessorErrorManager.js.map +1 -1
  30. package/dist/development/core/Config.js +1 -2
  31. package/dist/development/core/Config.js.map +1 -1
  32. package/dist/development/core/DataBinding.js +27 -40
  33. package/dist/development/core/DataBinding.js.map +1 -1
  34. package/dist/development/core/DirtinessTracker.js +4 -13
  35. package/dist/development/core/DirtinessTracker.js.map +1 -1
  36. package/dist/development/core/ErrorsPreprocessor.js +9 -13
  37. package/dist/development/core/ErrorsPreprocessor.js.map +1 -1
  38. package/dist/development/core/EventManager.js +13 -8
  39. package/dist/development/core/EventManager.js.map +1 -1
  40. package/dist/development/core/IncrementalMarkerBuilder.js +1 -1
  41. package/dist/development/core/MarkerMerger.js +2 -2
  42. package/dist/development/core/MutationGenerator.js +180 -141
  43. package/dist/development/core/MutationGenerator.js.map +1 -1
  44. package/dist/development/core/RequestResponseNormalizer.js +93 -134
  45. package/dist/development/core/RequestResponseNormalizer.js.map +1 -1
  46. package/dist/development/core/StateInitializer.js +30 -38
  47. package/dist/development/core/StateInitializer.js.map +1 -1
  48. package/dist/development/core/TreeAugmenter.js +14 -14
  49. package/dist/development/core/TreeAugmenter.js.map +1 -1
  50. package/dist/development/core/TreeFilterGenerator.js +2 -2
  51. package/dist/development/core/TreeFilterGenerator.js.map +1 -1
  52. package/dist/development/core/TreeStore.js +12 -23
  53. package/dist/development/core/TreeStore.js.map +1 -1
  54. package/dist/development/core/VariableInputTransformer.js.map +1 -1
  55. package/dist/development/core/operations/EntityOperations.js +14 -13
  56. package/dist/development/core/operations/EntityOperations.js.map +1 -1
  57. package/dist/development/core/operations/FieldOperations.js +2 -2
  58. package/dist/development/core/operations/FieldOperations.js.map +1 -1
  59. package/dist/development/core/operations/ListOperations.js +3 -3
  60. package/dist/development/core/operations/ListOperations.js.map +1 -1
  61. package/dist/development/core/operations/OperationsHelpers.js +2 -2
  62. package/dist/development/core/operations/OperationsHelpers.js.map +1 -1
  63. package/dist/development/core/requestAliases/MutationAlias.js +4 -40
  64. package/dist/development/core/requestAliases/MutationAlias.js.map +1 -1
  65. package/dist/development/core/schema/Schema.js +27 -3
  66. package/dist/development/core/schema/Schema.js.map +1 -1
  67. package/dist/development/core/schema/SchemaLoader.js +12 -12
  68. package/dist/development/core/schema/SchemaLoader.js.map +1 -1
  69. package/dist/development/core/schema/SchemaPreprocessor.js +1 -1
  70. package/dist/development/core/schema/SchemaPreprocessor.js.map +1 -1
  71. package/dist/development/coreComponents/Component.js +5 -2
  72. package/dist/development/coreComponents/Component.js.map +1 -1
  73. package/dist/development/coreComponents/DataBindingProvider.js +0 -1
  74. package/dist/development/coreComponents/DataBindingProvider.js.map +1 -1
  75. package/dist/development/coreComponents/EntityListSubTree.js.map +1 -1
  76. package/dist/development/coreComponents/HasOne.js +1 -1
  77. package/dist/development/dao/Environment.js +35 -3
  78. package/dist/development/dao/Environment.js.map +1 -1
  79. package/dist/development/dao/TreeNodeEnvironmentFactory.js +6 -13
  80. package/dist/development/dao/TreeNodeEnvironmentFactory.js.map +1 -1
  81. package/dist/development/helperComponents/DeferredSubTrees.js +16 -8
  82. package/dist/development/helperComponents/DeferredSubTrees.js.map +1 -1
  83. package/dist/development/helperComponents/If.js +39 -0
  84. package/dist/development/helperComponents/If.js.map +1 -0
  85. package/dist/development/helperComponents/SugaredField.js +1 -1
  86. package/dist/development/helperComponents/helpers/FilterEvaluator.js +35 -0
  87. package/dist/development/helperComponents/helpers/FilterEvaluator.js.map +1 -0
  88. package/dist/development/helperComponents/helpers/FilterFieldsCollector.js +38 -0
  89. package/dist/development/helperComponents/helpers/FilterFieldsCollector.js.map +1 -0
  90. package/dist/development/helperComponents/helpers/evaluateCondition.js +46 -0
  91. package/dist/development/helperComponents/helpers/evaluateCondition.js.map +1 -0
  92. package/dist/development/index.js +7 -2
  93. package/dist/development/index.js.map +1 -1
  94. package/dist/development/markers/EntityListSubTreeMarker.js +1 -1
  95. package/dist/development/markers/EntityListSubTreeMarker.js.map +1 -1
  96. package/dist/development/markers/EntitySubTreeMarker.js +1 -1
  97. package/dist/development/markers/EntitySubTreeMarker.js.map +1 -1
  98. package/dist/development/markers/PlaceholderGenerator.js +4 -4
  99. package/dist/development/markers/PlaceholderGenerator.js.map +1 -1
  100. package/dist/development/queryLanguage/MarkerFactory.js +2 -2
  101. package/dist/development/queryLanguage/QueryLanguage.js +1 -1
  102. package/dist/development/utils/Hashing.js +21 -6
  103. package/dist/development/utils/Hashing.js.map +1 -1
  104. package/dist/production/accessorPropagation/EnvironmentContext.js +28 -2
  105. package/dist/production/accessorPropagation/EnvironmentContext.js.map +1 -1
  106. package/dist/production/accessorPropagation/useEntityListSubTree.js +4 -2
  107. package/dist/production/accessorPropagation/useEntityListSubTree.js.map +1 -1
  108. package/dist/production/accessorPropagation/useEntitySubTree.js +4 -2
  109. package/dist/production/accessorPropagation/useEntitySubTree.js.map +1 -1
  110. package/dist/production/accessorPropagation/useExtendTree.js +27 -0
  111. package/dist/production/accessorPropagation/useExtendTree.js.map +1 -0
  112. package/dist/production/accessorTree/AccessorTree.js +16 -14
  113. package/dist/production/accessorTree/AccessorTree.js.map +1 -1
  114. package/dist/production/accessorTree/AccessorTreeStateContext.js +4 -0
  115. package/dist/production/accessorTree/AccessorTreeStateContext.js.map +1 -0
  116. package/dist/production/accessorTree/NormalizedPersistedData.js.map +1 -1
  117. package/dist/production/accessorTree/RuntimeId.js +17 -4
  118. package/dist/production/accessorTree/RuntimeId.js.map +1 -1
  119. package/dist/production/accessorTree/accessorTreeStateReducer.js +11 -2
  120. package/dist/production/accessorTree/accessorTreeStateReducer.js.map +1 -1
  121. package/dist/production/accessorTree/useAccessorTreeState.js +12 -0
  122. package/dist/production/accessorTree/useAccessorTreeState.js.map +1 -0
  123. package/dist/production/accessorTree/useDataBinding.js +41 -51
  124. package/dist/production/accessorTree/useDataBinding.js.map +1 -1
  125. package/dist/production/accessors/EntityAccessor.js +19 -40
  126. package/dist/production/accessors/EntityAccessor.js.map +1 -1
  127. package/dist/production/accessors/EntityListAccessor.js +11 -11
  128. package/dist/production/accessors/EntityListAccessor.js.map +1 -1
  129. package/dist/production/accessors/FieldAccessor.js +6 -6
  130. package/dist/production/accessors/FieldAccessor.js.map +1 -1
  131. package/dist/production/core/AccessorErrorManager.js +5 -2
  132. package/dist/production/core/AccessorErrorManager.js.map +1 -1
  133. package/dist/production/core/Config.js +1 -2
  134. package/dist/production/core/Config.js.map +1 -1
  135. package/dist/production/core/DataBinding.js +27 -40
  136. package/dist/production/core/DataBinding.js.map +1 -1
  137. package/dist/production/core/DirtinessTracker.js +4 -13
  138. package/dist/production/core/DirtinessTracker.js.map +1 -1
  139. package/dist/production/core/ErrorsPreprocessor.js +9 -13
  140. package/dist/production/core/ErrorsPreprocessor.js.map +1 -1
  141. package/dist/production/core/EventManager.js +12 -7
  142. package/dist/production/core/EventManager.js.map +1 -1
  143. package/dist/production/core/IncrementalMarkerBuilder.js +1 -1
  144. package/dist/production/core/MarkerMerger.js +2 -2
  145. package/dist/production/core/MutationGenerator.js +180 -141
  146. package/dist/production/core/MutationGenerator.js.map +1 -1
  147. package/dist/production/core/RequestResponseNormalizer.js +93 -134
  148. package/dist/production/core/RequestResponseNormalizer.js.map +1 -1
  149. package/dist/production/core/StateInitializer.js +30 -38
  150. package/dist/production/core/StateInitializer.js.map +1 -1
  151. package/dist/production/core/TreeAugmenter.js +14 -14
  152. package/dist/production/core/TreeAugmenter.js.map +1 -1
  153. package/dist/production/core/TreeFilterGenerator.js +2 -2
  154. package/dist/production/core/TreeFilterGenerator.js.map +1 -1
  155. package/dist/production/core/TreeStore.js +12 -23
  156. package/dist/production/core/TreeStore.js.map +1 -1
  157. package/dist/production/core/VariableInputTransformer.js.map +1 -1
  158. package/dist/production/core/operations/EntityOperations.js +14 -13
  159. package/dist/production/core/operations/EntityOperations.js.map +1 -1
  160. package/dist/production/core/operations/FieldOperations.js.map +1 -1
  161. package/dist/production/core/operations/ListOperations.js +3 -3
  162. package/dist/production/core/operations/ListOperations.js.map +1 -1
  163. package/dist/production/core/operations/OperationsHelpers.js +2 -2
  164. package/dist/production/core/operations/OperationsHelpers.js.map +1 -1
  165. package/dist/production/core/requestAliases/MutationAlias.js +4 -33
  166. package/dist/production/core/requestAliases/MutationAlias.js.map +1 -1
  167. package/dist/production/core/schema/Schema.js +27 -3
  168. package/dist/production/core/schema/Schema.js.map +1 -1
  169. package/dist/production/core/schema/SchemaLoader.js +12 -12
  170. package/dist/production/core/schema/SchemaLoader.js.map +1 -1
  171. package/dist/production/core/schema/SchemaPreprocessor.js +1 -1
  172. package/dist/production/core/schema/SchemaPreprocessor.js.map +1 -1
  173. package/dist/production/coreComponents/Component.js +5 -2
  174. package/dist/production/coreComponents/Component.js.map +1 -1
  175. package/dist/production/coreComponents/DataBindingProvider.js +0 -1
  176. package/dist/production/coreComponents/DataBindingProvider.js.map +1 -1
  177. package/dist/production/coreComponents/EntityListSubTree.js.map +1 -1
  178. package/dist/production/coreComponents/HasOne.js +1 -1
  179. package/dist/production/dao/Environment.js +35 -3
  180. package/dist/production/dao/Environment.js.map +1 -1
  181. package/dist/production/dao/TreeNodeEnvironmentFactory.js +6 -13
  182. package/dist/production/dao/TreeNodeEnvironmentFactory.js.map +1 -1
  183. package/dist/production/helperComponents/DeferredSubTrees.js +16 -8
  184. package/dist/production/helperComponents/DeferredSubTrees.js.map +1 -1
  185. package/dist/production/helperComponents/If.js +39 -0
  186. package/dist/production/helperComponents/If.js.map +1 -0
  187. package/dist/production/helperComponents/SugaredField.js +1 -1
  188. package/dist/production/helperComponents/helpers/FilterEvaluator.js +35 -0
  189. package/dist/production/helperComponents/helpers/FilterEvaluator.js.map +1 -0
  190. package/dist/production/helperComponents/helpers/FilterFieldsCollector.js +38 -0
  191. package/dist/production/helperComponents/helpers/FilterFieldsCollector.js.map +1 -0
  192. package/dist/production/helperComponents/helpers/evaluateCondition.js +46 -0
  193. package/dist/production/helperComponents/helpers/evaluateCondition.js.map +1 -0
  194. package/dist/production/index.js +7 -2
  195. package/dist/production/index.js.map +1 -1
  196. package/dist/production/markers/EntityListSubTreeMarker.js +1 -1
  197. package/dist/production/markers/EntityListSubTreeMarker.js.map +1 -1
  198. package/dist/production/markers/EntitySubTreeMarker.js +1 -1
  199. package/dist/production/markers/EntitySubTreeMarker.js.map +1 -1
  200. package/dist/production/markers/PlaceholderGenerator.js +4 -4
  201. package/dist/production/markers/PlaceholderGenerator.js.map +1 -1
  202. package/dist/production/queryLanguage/MarkerFactory.js +2 -2
  203. package/dist/production/queryLanguage/QueryLanguage.js +1 -1
  204. package/dist/production/utils/Hashing.js +21 -6
  205. package/dist/production/utils/Hashing.js.map +1 -1
  206. package/dist/types/accessorPropagation/BindingOperationsContext.d.ts +1 -1
  207. package/dist/types/accessorPropagation/BindingOperationsContext.d.ts.map +1 -1
  208. package/dist/types/accessorPropagation/EntityKeyContext.d.ts +1 -1
  209. package/dist/types/accessorPropagation/EntityKeyContext.d.ts.map +1 -1
  210. package/dist/types/accessorPropagation/EnvironmentContext.d.ts +13 -2
  211. package/dist/types/accessorPropagation/EnvironmentContext.d.ts.map +1 -1
  212. package/dist/types/accessorPropagation/TreeRootIdContext.d.ts +1 -1
  213. package/dist/types/accessorPropagation/TreeRootIdContext.d.ts.map +1 -1
  214. package/dist/types/accessorPropagation/index.d.ts +1 -0
  215. package/dist/types/accessorPropagation/index.d.ts.map +1 -1
  216. package/dist/types/accessorPropagation/useEntityListSubTree.d.ts +2 -1
  217. package/dist/types/accessorPropagation/useEntityListSubTree.d.ts.map +1 -1
  218. package/dist/types/accessorPropagation/useEntitySubTree.d.ts +2 -1
  219. package/dist/types/accessorPropagation/useEntitySubTree.d.ts.map +1 -1
  220. package/dist/types/accessorPropagation/useExtendTree.d.ts +5 -0
  221. package/dist/types/accessorPropagation/useExtendTree.d.ts.map +1 -0
  222. package/dist/types/accessorSorting/SetOrderFieldOnCreate.d.ts +1 -1
  223. package/dist/types/accessorSorting/SetOrderFieldOnCreate.d.ts.map +1 -1
  224. package/dist/types/accessorTree/AccessorTree.d.ts.map +1 -1
  225. package/dist/types/accessorTree/AccessorTreeState.d.ts +8 -0
  226. package/dist/types/accessorTree/AccessorTreeState.d.ts.map +1 -1
  227. package/dist/types/accessorTree/AccessorTreeStateAction.d.ts +6 -0
  228. package/dist/types/accessorTree/AccessorTreeStateAction.d.ts.map +1 -1
  229. package/dist/types/accessorTree/AccessorTreeStateContext.d.ts +4 -0
  230. package/dist/types/accessorTree/AccessorTreeStateContext.d.ts.map +1 -0
  231. package/dist/types/accessorTree/AccessorTreeStateOptions.d.ts +0 -1
  232. package/dist/types/accessorTree/AccessorTreeStateOptions.d.ts.map +1 -1
  233. package/dist/types/accessorTree/DirtinessContext.d.ts +1 -1
  234. package/dist/types/accessorTree/DirtinessContext.d.ts.map +1 -1
  235. package/dist/types/accessorTree/MutationRequestResponse.d.ts +5 -1
  236. package/dist/types/accessorTree/MutationRequestResponse.d.ts.map +1 -1
  237. package/dist/types/accessorTree/MutationStateContext.d.ts +1 -1
  238. package/dist/types/accessorTree/MutationStateContext.d.ts.map +1 -1
  239. package/dist/types/accessorTree/NormalizedPersistedData.d.ts +5 -5
  240. package/dist/types/accessorTree/NormalizedPersistedData.d.ts.map +1 -1
  241. package/dist/types/accessorTree/PersistResult.d.ts +2 -1
  242. package/dist/types/accessorTree/PersistResult.d.ts.map +1 -1
  243. package/dist/types/accessorTree/QueryRequestResponse.d.ts +11 -10
  244. package/dist/types/accessorTree/QueryRequestResponse.d.ts.map +1 -1
  245. package/dist/types/accessorTree/RuntimeId.d.ts +16 -6
  246. package/dist/types/accessorTree/RuntimeId.d.ts.map +1 -1
  247. package/dist/types/accessorTree/accessorTreeStateReducer.d.ts.map +1 -1
  248. package/dist/types/accessorTree/index.d.ts +1 -0
  249. package/dist/types/accessorTree/index.d.ts.map +1 -1
  250. package/dist/types/accessorTree/useAccessorTreeState.d.ts +2 -0
  251. package/dist/types/accessorTree/useAccessorTreeState.d.ts.map +1 -0
  252. package/dist/types/accessorTree/useDataBinding.d.ts +1 -1
  253. package/dist/types/accessorTree/useDataBinding.d.ts.map +1 -1
  254. package/dist/types/accessors/BindingConfig.d.ts +0 -1
  255. package/dist/types/accessors/BindingConfig.d.ts.map +1 -1
  256. package/dist/types/accessors/EntityAccessor.d.ts +5 -5
  257. package/dist/types/accessors/EntityAccessor.d.ts.map +1 -1
  258. package/dist/types/accessors/EntityListAccessor.d.ts +4 -4
  259. package/dist/types/accessors/EntityListAccessor.d.ts.map +1 -1
  260. package/dist/types/accessors/FieldAccessor.d.ts +2 -2
  261. package/dist/types/accessors/FieldAccessor.d.ts.map +1 -1
  262. package/dist/types/core/AccessorErrorManager.d.ts +2 -1
  263. package/dist/types/core/AccessorErrorManager.d.ts.map +1 -1
  264. package/dist/types/core/Config.d.ts.map +1 -1
  265. package/dist/types/core/DataBinding.d.ts +3 -4
  266. package/dist/types/core/DataBinding.d.ts.map +1 -1
  267. package/dist/types/core/DirtinessTracker.d.ts +2 -5
  268. package/dist/types/core/DirtinessTracker.d.ts.map +1 -1
  269. package/dist/types/core/ErrorsPreprocessor.d.ts +5 -3
  270. package/dist/types/core/ErrorsPreprocessor.d.ts.map +1 -1
  271. package/dist/types/core/EventManager.d.ts +1 -1
  272. package/dist/types/core/EventManager.d.ts.map +1 -1
  273. package/dist/types/core/MutationGenerator.d.ts +25 -1
  274. package/dist/types/core/MutationGenerator.d.ts.map +1 -1
  275. package/dist/types/core/RequestResponseNormalizer.d.ts +6 -7
  276. package/dist/types/core/RequestResponseNormalizer.d.ts.map +1 -1
  277. package/dist/types/core/StateInitializer.d.ts +1 -5
  278. package/dist/types/core/StateInitializer.d.ts.map +1 -1
  279. package/dist/types/core/TreeAugmenter.d.ts +3 -2
  280. package/dist/types/core/TreeAugmenter.d.ts.map +1 -1
  281. package/dist/types/core/TreeStore.d.ts +8 -8
  282. package/dist/types/core/TreeStore.d.ts.map +1 -1
  283. package/dist/types/core/VariableInputTransformer.d.ts +2 -2
  284. package/dist/types/core/VariableInputTransformer.d.ts.map +1 -1
  285. package/dist/types/core/index.d.ts +1 -0
  286. package/dist/types/core/index.d.ts.map +1 -1
  287. package/dist/types/core/operations/EntityOperations.d.ts.map +1 -1
  288. package/dist/types/core/operations/ListOperations.d.ts +2 -1
  289. package/dist/types/core/operations/ListOperations.d.ts.map +1 -1
  290. package/dist/types/core/requestAliases/MutationAlias.d.ts +0 -3
  291. package/dist/types/core/requestAliases/MutationAlias.d.ts.map +1 -1
  292. package/dist/types/core/requestAliases/index.d.ts +0 -3
  293. package/dist/types/core/requestAliases/index.d.ts.map +1 -1
  294. package/dist/types/core/schema/RawSchemaEntity.d.ts +3 -2
  295. package/dist/types/core/schema/RawSchemaEntity.d.ts.map +1 -1
  296. package/dist/types/core/schema/Schema.d.ts +13 -3
  297. package/dist/types/core/schema/Schema.d.ts.map +1 -1
  298. package/dist/types/core/schema/SchemaColumn.d.ts +1 -1
  299. package/dist/types/core/schema/SchemaColumn.d.ts.map +1 -1
  300. package/dist/types/core/schema/SchemaEntity.d.ts +1 -1
  301. package/dist/types/core/schema/SchemaEntity.d.ts.map +1 -1
  302. package/dist/types/core/schema/SchemaLoader.d.ts +2 -1
  303. package/dist/types/core/schema/SchemaLoader.d.ts.map +1 -1
  304. package/dist/types/core/schema/SchemaRelation.d.ts +1 -1
  305. package/dist/types/core/schema/SchemaRelation.d.ts.map +1 -1
  306. package/dist/types/core/state/FieldState.d.ts +2 -2
  307. package/dist/types/core/state/FieldState.d.ts.map +1 -1
  308. package/dist/types/coreComponents/Component.d.ts +9 -4
  309. package/dist/types/coreComponents/Component.d.ts.map +1 -1
  310. package/dist/types/coreComponents/DataBindingProvider.d.ts +0 -1
  311. package/dist/types/coreComponents/DataBindingProvider.d.ts.map +1 -1
  312. package/dist/types/coreComponents/Entity.d.ts +1 -1
  313. package/dist/types/coreComponents/Entity.d.ts.map +1 -1
  314. package/dist/types/coreComponents/EntityListSubTree.d.ts.map +1 -1
  315. package/dist/types/coreComponents/Field.d.ts +1 -1
  316. package/dist/types/coreComponents/Field.d.ts.map +1 -1
  317. package/dist/types/coreComponents/ParentEntity.d.ts +1 -1
  318. package/dist/types/coreComponents/ParentEntity.d.ts.map +1 -1
  319. package/dist/types/dao/Environment.d.ts +14 -5
  320. package/dist/types/dao/Environment.d.ts.map +1 -1
  321. package/dist/types/dao/TreeNodeEnvironmentFactory.d.ts.map +1 -1
  322. package/dist/types/entityEvents/useDerivedField.d.ts +2 -2
  323. package/dist/types/entityEvents/useDerivedField.d.ts.map +1 -1
  324. package/dist/types/helperComponents/DeferredSubTrees.d.ts +1 -1
  325. package/dist/types/helperComponents/DeferredSubTrees.d.ts.map +1 -1
  326. package/dist/types/helperComponents/FieldView.d.ts +7 -7
  327. package/dist/types/helperComponents/FieldView.d.ts.map +1 -1
  328. package/dist/types/helperComponents/If.d.ts +14 -0
  329. package/dist/types/helperComponents/If.d.ts.map +1 -0
  330. package/dist/types/helperComponents/StaticRender.d.ts +1 -1
  331. package/dist/types/helperComponents/StaticRender.d.ts.map +1 -1
  332. package/dist/types/helperComponents/SugaredField.d.ts +1 -1
  333. package/dist/types/helperComponents/SugaredField.d.ts.map +1 -1
  334. package/dist/types/helperComponents/helpers/FilterEvaluator.d.ts +9 -0
  335. package/dist/types/helperComponents/helpers/FilterEvaluator.d.ts.map +1 -0
  336. package/dist/types/helperComponents/helpers/FilterFieldsCollector.d.ts +10 -0
  337. package/dist/types/helperComponents/helpers/FilterFieldsCollector.d.ts.map +1 -0
  338. package/dist/types/helperComponents/helpers/evaluateCondition.d.ts +4 -0
  339. package/dist/types/helperComponents/helpers/evaluateCondition.d.ts.map +1 -0
  340. package/dist/types/helperComponents/index.d.ts +1 -0
  341. package/dist/types/helperComponents/index.d.ts.map +1 -1
  342. package/dist/types/markers/FieldMarker.d.ts +3 -3
  343. package/dist/types/markers/FieldMarker.d.ts.map +1 -1
  344. package/dist/types/markers/PlaceholderGenerator.d.ts +3 -2
  345. package/dist/types/markers/PlaceholderGenerator.d.ts.map +1 -1
  346. package/dist/types/treeParameters/primitives/EntityId.d.ts +1 -1
  347. package/dist/types/treeParameters/primitives/EntityId.d.ts.map +1 -1
  348. package/dist/types/treeParameters/primitives/FieldValue.d.ts +2 -2
  349. package/dist/types/treeParameters/primitives/FieldValue.d.ts.map +1 -1
  350. package/dist/types/treeParameters/primitives/Json.d.ts +7 -0
  351. package/dist/types/treeParameters/primitives/Json.d.ts.map +1 -0
  352. package/dist/types/treeParameters/primitives/index.d.ts +1 -0
  353. package/dist/types/treeParameters/primitives/index.d.ts.map +1 -1
  354. package/dist/types/tsconfig.tsbuildinfo +1 -1
  355. package/dist/types/utils/Hashing.d.ts +3 -2
  356. package/dist/types/utils/Hashing.d.ts.map +1 -1
  357. package/package.json +7 -5
  358. package/src/accessorPropagation/EnvironmentContext.tsx +44 -0
  359. package/src/accessorPropagation/index.ts +1 -0
  360. package/src/accessorPropagation/useEntityListSubTree.ts +8 -1
  361. package/src/accessorPropagation/useEntitySubTree.ts +8 -1
  362. package/src/accessorPropagation/useExtendTree.ts +30 -0
  363. package/src/accessorTree/AccessorTree.tsx +18 -18
  364. package/src/accessorTree/AccessorTreeState.ts +12 -1
  365. package/src/accessorTree/AccessorTreeStateAction.ts +7 -1
  366. package/src/accessorTree/AccessorTreeStateContext.ts +4 -0
  367. package/src/accessorTree/AccessorTreeStateOptions.ts +0 -1
  368. package/src/accessorTree/MutationRequestResponse.ts +9 -1
  369. package/src/accessorTree/NormalizedPersistedData.ts +5 -5
  370. package/src/accessorTree/PersistResult.ts +2 -1
  371. package/src/accessorTree/QueryRequestResponse.ts +17 -14
  372. package/src/accessorTree/RuntimeId.ts +27 -6
  373. package/src/accessorTree/accessorTreeStateReducer.ts +10 -1
  374. package/src/accessorTree/index.ts +1 -0
  375. package/src/accessorTree/useAccessorTreeState.ts +11 -0
  376. package/src/accessorTree/useDataBinding.ts +41 -59
  377. package/src/accessors/BindingConfig.ts +0 -1
  378. package/src/accessors/EntityAccessor.ts +22 -58
  379. package/src/accessors/EntityListAccessor.ts +12 -12
  380. package/src/accessors/FieldAccessor.ts +5 -5
  381. package/src/core/AccessorErrorManager.ts +6 -2
  382. package/src/core/Config.ts +0 -1
  383. package/src/core/DataBinding.ts +28 -44
  384. package/src/core/DirtinessTracker.ts +4 -16
  385. package/src/core/ErrorsPreprocessor.ts +16 -18
  386. package/src/core/EventManager.ts +14 -8
  387. package/src/core/MutationGenerator.ts +249 -188
  388. package/src/core/RequestResponseNormalizer.ts +111 -163
  389. package/src/core/StateInitializer.ts +46 -58
  390. package/src/core/TreeAugmenter.ts +16 -15
  391. package/src/core/TreeFilterGenerator.ts +5 -5
  392. package/src/core/TreeStore.ts +23 -27
  393. package/src/core/VariableInputTransformer.ts +2 -2
  394. package/src/core/index.ts +1 -0
  395. package/src/core/operations/EntityOperations.ts +13 -14
  396. package/src/core/operations/FieldOperations.ts +2 -2
  397. package/src/core/operations/ListOperations.ts +6 -5
  398. package/src/core/operations/OperationsHelpers.ts +2 -2
  399. package/src/core/requestAliases/MutationAlias.ts +4 -57
  400. package/src/core/requestAliases/index.ts +0 -3
  401. package/src/core/schema/RawSchemaEntity.ts +1 -2
  402. package/src/core/schema/Schema.ts +38 -4
  403. package/src/core/schema/SchemaColumn.ts +1 -1
  404. package/src/core/schema/SchemaEntity.ts +1 -1
  405. package/src/core/schema/SchemaLoader.ts +13 -11
  406. package/src/core/schema/SchemaPreprocessor.ts +1 -1
  407. package/src/core/schema/SchemaRelation.ts +1 -1
  408. package/src/core/state/FieldState.ts +2 -2
  409. package/src/coreComponents/Component.tsx +20 -7
  410. package/src/coreComponents/DataBindingProvider.tsx +0 -2
  411. package/src/coreComponents/EntityListSubTree.tsx +2 -3
  412. package/src/dao/Environment.ts +48 -7
  413. package/src/dao/TreeNodeEnvironmentFactory.ts +8 -13
  414. package/src/helperComponents/DeferredSubTrees.tsx +20 -13
  415. package/src/helperComponents/If.tsx +71 -0
  416. package/src/helperComponents/helpers/FilterEvaluator.ts +46 -0
  417. package/src/helperComponents/helpers/FilterFieldsCollector.ts +46 -0
  418. package/src/helperComponents/helpers/evaluateCondition.ts +52 -0
  419. package/src/helperComponents/index.ts +1 -0
  420. package/src/markers/EntityListSubTreeMarker.ts +1 -1
  421. package/src/markers/EntitySubTreeMarker.ts +1 -1
  422. package/src/markers/PlaceholderGenerator.ts +5 -2
  423. package/src/treeParameters/primitives/EntityId.ts +1 -1
  424. package/src/treeParameters/primitives/FieldValue.ts +2 -2
  425. package/src/treeParameters/primitives/Json.ts +7 -0
  426. package/src/treeParameters/primitives/index.ts +1 -0
  427. package/src/typings/react-fix.d.ts +12 -0
  428. package/src/utils/Hashing.ts +23 -8
  429. package/dist/development/core/requestAliases/mutationOperationSubTreeType.js +0 -6
  430. package/dist/development/core/requestAliases/mutationOperationSubTreeType.js.map +0 -1
  431. package/dist/development/core/requestAliases/mutationOperationType.js +0 -7
  432. package/dist/development/core/requestAliases/mutationOperationType.js.map +0 -1
  433. package/dist/production/core/requestAliases/mutationOperationSubTreeType.js +0 -6
  434. package/dist/production/core/requestAliases/mutationOperationSubTreeType.js.map +0 -1
  435. package/dist/production/core/requestAliases/mutationOperationType.js +0 -7
  436. package/dist/production/core/requestAliases/mutationOperationType.js.map +0 -1
  437. package/dist/types/core/requestAliases/TopLevelMutationOperation.d.ts +0 -11
  438. package/dist/types/core/requestAliases/TopLevelMutationOperation.d.ts.map +0 -1
  439. package/dist/types/core/requestAliases/mutationOperationSubTreeType.d.ts +0 -5
  440. package/dist/types/core/requestAliases/mutationOperationSubTreeType.d.ts.map +0 -1
  441. package/dist/types/core/requestAliases/mutationOperationType.d.ts +0 -6
  442. package/dist/types/core/requestAliases/mutationOperationType.d.ts.map +0 -1
  443. package/src/accessorPropagation/EnvironmentContext.ts +0 -5
  444. package/src/core/requestAliases/TopLevelMutationOperation.ts +0 -11
  445. package/src/core/requestAliases/mutationOperationSubTreeType.ts +0 -4
  446. package/src/core/requestAliases/mutationOperationType.ts +0 -5
@@ -1 +1 @@
1
- {"version":3,"file":"EventManager.js","sources":["../../../src/core/EventManager.ts"],"sourcesContent":["import * as ReactDOM from 'react-dom'\nimport type {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tEntityAccessor,\n\tEntityListAccessor,\n\tFieldAccessor,\n\tPersistErrorOptions,\n\tPersistSuccessOptions,\n} from '../accessors'\nimport type { SuccessfulPersistResult } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { PlaceholderName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport type { Config } from './Config'\nimport type { DirtinessTracker } from './DirtinessTracker'\nimport {\n\tEntityListState,\n\tEntityRealmState,\n\tFieldState,\n\tgetEntityMarker,\n\tRootStateNode,\n\tStateINode,\n\tStateIterator,\n\tStateNode,\n} from './state'\nimport type { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport type { EventListenersStore } from '../treeParameters'\n\nexport class EventManager {\n\tpublic static readonly NO_CHANGES_DIFFERENCE = 0\n\n\tprivate transactionDepth = 0\n\tprivate isFrozenWhileUpdating = false\n\n\t// This should ideally not exists as it should be synonymous to `this.ongoingPersistOperation !== undefined`\n\t// but it makes persist-related promise juggling significantly more straightforward.\n\tprivate isMutating: boolean = false\n\tprivate ongoingPersistOperation: Promise<SuccessfulPersistResult> | undefined = undefined\n\n\tprivate previousMetadata: UpdateMetadata | undefined = undefined\n\n\tprivate newlyInitializedWithListeners: Set<EntityListState | EntityRealmState | FieldState> = new Set()\n\tprivate pendingWithBeforeUpdate: Set<StateNode> = new Set()\n\tprivate rootsWithPendingUpdates: Set<RootStateNode> = new Set()\n\n\tpublic constructor(\n\t\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly config: Config,\n\t\tprivate readonly dirtinessTracker: DirtinessTracker,\n\t\tprivate readonly onUpdate: (metadata: UpdateMetadata) => void,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic async persistOperation(operation: () => Promise<SuccessfulPersistResult>): Promise<SuccessfulPersistResult> {\n\t\tif (this.transactionDepth > 0) {\n\t\t\tthrow new BindingError(`Cannot trigger a persist whilst batching updates!`)\n\t\t}\n\t\tconst ongoingOperation = this.ongoingPersistOperation\n\t\tif (ongoingOperation !== undefined) {\n\t\t\treturn await ongoingOperation\n\t\t}\n\t\treturn await (this.ongoingPersistOperation = new Promise<SuccessfulPersistResult>(async (resolve, reject) => {\n\t\t\tthis.isMutating = true\n\t\t\tthis.flushUpdates() // Let the world know that we're mutating\n\n\t\t\ttry {\n\t\t\t\tresolve(await this.asyncOperation(operation))\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error('PersistError', e)\n\t\t\t\treject(e)\n\t\t\t} finally {\n\t\t\t\tthis.ongoingPersistOperation = undefined\n\t\t\t\tthis.isMutating = false\n\t\t\t\tthis.flushUpdates()\n\t\t\t}\n\t\t}))\n\t}\n\n\tpublic syncTransaction<T>(transaction: () => T) {\n\t\ttry {\n\t\t\tthis.transactionDepth++\n\t\t\treturn transaction()\n\t\t} finally {\n\t\t\tthis.transactionDepth--\n\t\t}\n\t}\n\tpublic syncOperation<T>(operation: () => T) {\n\t\tconst result = this.syncTransaction(operation)\n\t\tthis.flushUpdates()\n\t\treturn result\n\t}\n\n\tpublic async asyncTransaction<T>(transaction: () => Promise<T>): Promise<T> {\n\t\ttry {\n\t\t\tthis.transactionDepth++\n\t\t\treturn await transaction()\n\t\t} finally {\n\t\t\tthis.transactionDepth--\n\t\t}\n\t}\n\tpublic async asyncOperation<T>(operation: () => Promise<T>): Promise<T> {\n\t\tconst result = await this.asyncTransaction(operation)\n\t\tthis.flushUpdates()\n\t\treturn result\n\t}\n\n\tprivate flushUpdates() {\n\t\tif (this.transactionDepth > 0) {\n\t\t\treturn\n\t\t}\n\n\t\tif (this.isFrozenWhileUpdating) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Trying to perform an update while the whole accessor tree is already updating. This is most likely caused ` +\n\t\t\t\t\t`by updating the accessor tree while rendering or from within the 'update' event handler, which is a no-op. ` +\n\t\t\t\t\t`If you wish to mutate the tree in reaction to other changes, use the 'beforeUpdate' event.`,\n\t\t\t)\n\t\t}\n\n\t\tconst newMetadata = this.getNewUpdateMetadata()\n\n\t\tif (!this.shouldFlushUpdates(newMetadata)) {\n\t\t\treturn\n\t\t}\n\n\t\tReactDOM.unstable_batchedUpdates(() => {\n\t\t\tthis.isFrozenWhileUpdating = true\n\t\t\tthis.triggerBeforeFlushEvents()\n\t\t\tthis.onUpdate(newMetadata)\n\t\t\tthis.flushPendingAccessorUpdates(Array.from(this.rootsWithPendingUpdates))\n\n\t\t\tthis.rootsWithPendingUpdates.clear()\n\t\t\tthis.isFrozenWhileUpdating = false\n\t\t\tthis.previousMetadata = newMetadata\n\t\t})\n\t}\n\n\tprivate getNewUpdateMetadata(): UpdateMetadata {\n\t\treturn {\n\t\t\tisMutating: this.isMutating,\n\t\t}\n\t}\n\n\tprivate shouldFlushUpdates(newMetadata: UpdateMetadata): boolean {\n\t\tif (this.transactionDepth > 0) {\n\t\t\treturn false\n\t\t}\n\t\tif (this.previousMetadata === undefined) {\n\t\t\treturn true\n\t\t}\n\t\tif (this.rootsWithPendingUpdates.size) {\n\t\t\treturn true\n\t\t}\n\t\tfor (const key in newMetadata) {\n\t\t\tconst fromPrevious = this.previousMetadata[key as keyof UpdateMetadata]\n\t\t\tconst fromNew = newMetadata[key as keyof UpdateMetadata]\n\n\t\t\tif (!Object.is(fromPrevious, fromNew)) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n\n\tpublic registerNewlyInitialized(newlyInitialized: StateNode) {\n\t\tconst initializeListeners = this.getEventListeners(newlyInitialized, { type: 'initialize' })\n\n\t\tif (initializeListeners === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.newlyInitializedWithListeners.add(newlyInitialized)\n\n\t\tif (this.transactionDepth === 0) {\n\t\t\tthis.triggerOnInitialize()\n\t\t}\n\t}\n\n\tpublic registerUpdatedConnection(parentState: EntityRealmState, placeholderName: PlaceholderName) {\n\t\tif (parentState.fieldsWithPendingConnectionUpdates === undefined) {\n\t\t\tparentState.fieldsWithPendingConnectionUpdates = new Set()\n\t\t}\n\n\t\tconst marker = getEntityMarker(parentState)\n\t\tplaceholders: for (const [fieldName, placeholdersByField] of marker.fields.placeholders) {\n\t\t\tif (typeof placeholdersByField === 'string') {\n\t\t\t\tif (placeholdersByField === placeholderName) {\n\t\t\t\t\tparentState.fieldsWithPendingConnectionUpdates.add(fieldName)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (const placeholderByFieldName of placeholdersByField) {\n\t\t\t\t\tif (placeholderByFieldName === placeholderName) {\n\t\t\t\t\t\tparentState.fieldsWithPendingConnectionUpdates.add(fieldName)\n\t\t\t\t\t\tcontinue placeholders\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic registerJustUpdated(justUpdated: StateNode, changesDelta: number) {\n\t\tconst beforeUpdateListeners = this.getEventListeners(justUpdated, { type: 'beforeUpdate' })\n\t\tif (beforeUpdateListeners !== undefined) {\n\t\t\tthis.pendingWithBeforeUpdate.add(justUpdated)\n\t\t}\n\t\tjustUpdated.accessor = undefined\n\n\t\tswitch (justUpdated.type) {\n\t\t\tcase 'entityRealm':\n\t\t\tcase 'entityList': {\n\t\t\t\tjustUpdated.unpersistedChangesCount += changesDelta\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tif (justUpdated.unpersistedChangesCount < 0) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`We have *JUST* reached a completely invalid state. From now on, anything can (and likely will) ` +\n\t\t\t\t\t\t\t\t`go wrong. This is definitely a bug. Please try to report whatever led to this situation.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst parent = justUpdated.blueprint.parent\n\n\t\t\t\tif (parent === undefined) {\n\t\t\t\t\tthis.rootsWithPendingUpdates.add(justUpdated)\n\t\t\t\t\tthis.dirtinessTracker.increaseBy(changesDelta)\n\t\t\t\t} else {\n\t\t\t\t\tif (!parent.childrenWithPendingUpdates) {\n\t\t\t\t\t\tparent.childrenWithPendingUpdates = new Set()\n\t\t\t\t\t}\n\t\t\t\t\tparent.childrenWithPendingUpdates.add(justUpdated as any)\n\t\t\t\t\tthis.registerJustUpdated(parent, changesDelta)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'field': {\n\t\t\t\tconst parent = justUpdated.parent\n\t\t\t\tif (!parent.childrenWithPendingUpdates) {\n\t\t\t\t\tparent.childrenWithPendingUpdates = new Set()\n\t\t\t\t}\n\t\t\t\tparent.childrenWithPendingUpdates.add(justUpdated as any)\n\t\t\t\tthis.registerJustUpdated(justUpdated.parent, changesDelta)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate flushPendingAccessorUpdates(rootStates: Array<StateINode>) {\n\t\t// It is *CRUCIAL* that this is a BFS so that we update the components in top-down order.\n\t\tconst agenda: StateNode[] = rootStates\n\n\t\tfor (const state of agenda) {\n\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\tconst updateListeners =\n\t\t\t\tstate.type === 'field'\n\t\t\t\t\t? this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\t\t\t\t\t: state.type === 'entityRealm'\n\t\t\t\t\t? this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\t\t\t\t\t: this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\n\t\t\tif (updateListeners !== undefined) {\n\t\t\t\tfor (const handler of updateListeners) {\n\t\t\t\t\t// TS can't quite handle the polymorphism here but this is fine.\n\t\t\t\t\thandler()\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (state.type === 'entityRealm' && state.fieldsWithPendingConnectionUpdates) {\n\t\t\t\tfor (const updatedField of state.fieldsWithPendingConnectionUpdates) {\n\t\t\t\t\tconst listeners = this.getEventListeners(state, { type: 'connectionUpdate', key: updatedField })\n\t\t\t\t\tif (!listeners) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tlistener(state.getAccessor())\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tswitch (state.type) {\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (state.childrenWithPendingUpdates !== undefined) {\n\t\t\t\t\t\tfor (const childState of state.childrenWithPendingUpdates) {\n\t\t\t\t\t\t\tagenda.push(childState)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstate.childrenWithPendingUpdates.clear()\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'field':\n\t\t\t\t\t// Do nothing\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\tassertNever(state)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async triggerAsyncMutatingEvent(eventType: 'beforePersist', options: AsyncBatchUpdatesOptions): Promise<void>\n\tprivate async triggerAsyncMutatingEvent(eventType: 'persistSuccess', options: PersistSuccessOptions): Promise<void>\n\tprivate async triggerAsyncMutatingEvent(\n\t\teventType: 'beforePersist' | 'persistSuccess',\n\t\toptions: AsyncBatchUpdatesOptions | PersistSuccessOptions,\n\t): Promise<void> {\n\t\tawait this.asyncTransaction(async () => {\n\t\t\t// TODO if an entity from here (or its parent) gets deleted, we need to remove stale handlers from here.\n\t\t\tconst callbackQueue: Array<\n\t\t\t\t[\n\t\t\t\t\t// The typings could be nicer but TS…\n\t\t\t\t\tStateINode,\n\t\t\t\t\t(\n\t\t\t\t\t\t| EntityAccessor.EntityEventListenerMap[typeof eventType]\n\t\t\t\t\t\t| EntityListAccessor.EntityListEventListenerMap[typeof eventType]\n\t\t\t\t\t),\n\t\t\t\t]\n\t\t\t> = []\n\n\t\t\tfor (const [, subTreeState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const iNode of StateIterator.depthFirstINodes(subTreeState)) {\n\t\t\t\t\tconst listeners = this.getEventListeners(iNode, { type: eventType }) ?? []\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tcallbackQueue.push([iNode, listener])\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (\n\t\t\t\tlet waterfallDepth = 0;\n\t\t\t\twaterfallDepth < this.config.getValue(`${eventType}SettleLimit` as const);\n\t\t\t\twaterfallDepth++\n\t\t\t) {\n\t\t\t\tconst promiseReturns: Array<\n\t\t\t\t\tPromise<\n\t\t\t\t\t\t| void\n\t\t\t\t\t\t| EntityAccessor.EntityEventListenerMap[typeof eventType]\n\t\t\t\t\t\t| EntityListAccessor.EntityListEventListenerMap[typeof eventType]\n\t\t\t\t\t>\n\t\t\t\t> = []\n\t\t\t\tconst correspondingStates: Array<StateINode> = []\n\n\t\t\t\tif (callbackQueue.length === 0) {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\n\t\t\t\tfor (const [state, callback] of callbackQueue) {\n\t\t\t\t\tcorrespondingStates.push(state)\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = callback(state.getAccessor as any, options as any) // TS can't quite handle this but this is sound.\n\t\t\t\t\t\tif (result instanceof Promise) {\n\t\t\t\t\t\t\tpromiseReturns.push(result)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tpromiseReturns.push(Promise.resolve(result))\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tpromiseReturns.push(Promise.reject(e))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// TODO timeout\n\n\t\t\t\tconst newCallbacks = await this.executeWithoutChanges(eventType, () => Promise.allSettled(promiseReturns))\n\n\t\t\t\tcallbackQueue.length = 0 // Empties the queue\n\n\t\t\t\t// TODO we're drifting away from the original depth-first order. Let's see if that's ever even an issue.\n\t\t\t\tfor (const newlyInitialized of this.newlyInitializedWithListeners) {\n\t\t\t\t\tif (newlyInitialized.type === 'field') {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst beforePersistHandlers = this.getEventListeners(newlyInitialized, { type: eventType })\n\t\t\t\t\tif (beforePersistHandlers) {\n\t\t\t\t\t\tfor (const listener of beforePersistHandlers) {\n\t\t\t\t\t\t\tcallbackQueue.push([newlyInitialized, listener])\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.triggerBeforeFlushEvents()\n\t\t\t\tthis.handleRejections(eventType, newCallbacks)\n\n\t\t\t\tfor (let i = 0; i < newCallbacks.length; i++) {\n\t\t\t\t\tconst result = newCallbacks[i]\n\t\t\t\t\tconst correspondingState = correspondingStates[i]\n\n\t\t\t\t\tif (result.status === 'fulfilled') {\n\t\t\t\t\t\tif (typeof result.value === 'function') {\n\t\t\t\t\t\t\tcallbackQueue.push([correspondingState, result.value])\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Otherwise do nothing. This is just a handler that albeit async, doesn't appear to\n\t\t\t\t\t\t// interact with data binding.\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\tif (callbackQueue.length) {\n\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t`Exceeded the ${eventType} settle limit. Your code likely contains a deadlock. ` +\n\t\t\t\t\t\t\t`If that's not the case, raise the settle limit from DataBindingProvider.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate triggerBeforeFlushEvents() {\n\t\tthis.syncTransaction(() => {\n\t\t\tconst settleLimit = this.config.getValue('beforeUpdateSettleLimit')\n\n\t\t\tfor (let attemptNumber = 0; attemptNumber < settleLimit; attemptNumber++) {\n\t\t\t\tif (!this.pendingWithBeforeUpdate.size) {\n\t\t\t\t\tthis.triggerOnInitialize()\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst withBeforeUpdate = this.pendingWithBeforeUpdate\n\t\t\t\tthis.pendingWithBeforeUpdate = new Set()\n\n\t\t\t\tfor (const state of withBeforeUpdate) {\n\t\t\t\t\tconst listeners = this.getEventListeners(state, { type: 'beforeUpdate' })\n\t\t\t\t\tif (listeners === undefined) {\n\t\t\t\t\t\t// This can happen if the listener has unsubscribed since we added it to the set.\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tswitch (state.type) {\n\t\t\t\t\t\tcase 'field':\n\t\t\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\t\t\t(listener as FieldAccessor.BeforeUpdateListener)(state.getAccessor())\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\t\t\tstate.getAccessor().batchUpdates(listener as any)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn assertNever(state)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.triggerOnInitialize()\n\t\t\t}\n\t\t\tthrow new BindingError(\n\t\t\t\t`Maximum stabilization limit of updates caused by 'beforeUpdate' exceeded. ` +\n\t\t\t\t\t`This likely means there is an infinite feedback loop in your code.`,\n\t\t\t)\n\t\t})\n\t}\n\n\tprivate triggerOnInitialize() {\n\t\tthis.syncTransaction(() => {\n\t\t\tfor (const state of this.newlyInitializedWithListeners) {\n\t\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\t\tconst listeners =\n\t\t\t\t\tstate.type === 'field'\n\t\t\t\t\t\t? this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\t\t\t\t\t\t: state.type === 'entityRealm'\n\t\t\t\t\t\t? this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\t\t\t\t\t\t: this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\n\t\t\t\tif (listeners) {\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tlistener()\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (state.type === 'entityRealm') {\n\t\t\t\t\tstate.entity.hasIdSetInStone = true\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.newlyInitializedWithListeners.clear()\n\t\t})\n\t}\n\n\tpublic async triggerOnPersistError(options: PersistErrorOptions) {\n\t\tawait this.asyncTransaction(async () => {\n\t\t\tconst handlerPromises: Array<Promise<void>> = []\n\n\t\t\tfor (const [, subTreeState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const iNode of StateIterator.depthFirstINodes(subTreeState)) {\n\t\t\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\t\t\tconst dispatchers =\n\t\t\t\t\t\tiNode.type === 'entityRealm'\n\t\t\t\t\t\t\t? this.getEventDispatchers(iNode, { type: 'persistError' }, [iNode.getAccessor, options])\n\t\t\t\t\t\t\t: this.getEventDispatchers(iNode, { type: 'persistError' }, [iNode.getAccessor, options])\n\t\t\t\t\tif (dispatchers === undefined) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const listener of dispatchers ?? []) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst result = listener()\n\t\t\t\t\t\t\tif (result instanceof Promise) {\n\t\t\t\t\t\t\t\thandlerPromises.push(result)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\thandlerPromises.push(Promise.resolve(result))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\thandlerPromises.push(Promise.reject(e))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// TODO timeout\n\t\t\tconst handlerResults = await Promise.allSettled(handlerPromises)\n\t\t\tthis.handleRejections('persistError', handlerResults)\n\t\t})\n\t}\n\n\tpublic async triggerOnBeforePersist() {\n\t\treturn this.triggerAsyncMutatingEvent('beforePersist', this.asyncBatchUpdatesOptions)\n\t}\n\n\tpublic async triggerOnPersistSuccess(options: PersistSuccessOptions) {\n\t\treturn this.triggerAsyncMutatingEvent('persistSuccess', options)\n\t}\n\n\tpublic getEventListeners<\n\t\tState extends StateNode,\n\t\tEventListenerTypes extends\n\t\t\tExclude<State['eventListeners'], undefined> extends EventListenersStore<infer Keys, infer Map> ? [Keys, Map] : never,\n\t\tEventType extends EventListenerTypes[0],\n\t>(state: State, event: { type: EventType; key?: string }): Set<Exclude<EventListenerTypes[1][EventType], undefined>> | undefined {\n\t\tif (!state.eventListeners) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn (state.eventListeners as EventListenersStore<EventType, EventListenerTypes[1]>).get(event) as Set<\n\t\t\tExclude<EventListenerTypes[1][EventType], undefined>\n\t\t>\n\t}\n\n\tpublic getEventDispatchers<\n\t\tState extends StateNode,\n\t\tEventListenerTypes extends\n\t\t\tExclude<State['eventListeners'], undefined> extends EventListenersStore<infer Keys, infer Map> ? [Keys, Map] : never,\n\t\tEventType extends EventListenerTypes[0],\n\t>(\n\t\tstate: State,\n\t\tevent: { type: EventType; key?: string },\n\t\tlistenerArgs: Parameters<Exclude<EventListenerTypes[1][EventType], undefined>>,\n\t): Array<() => ReturnType<Exclude<EventListenerTypes[1][EventType], undefined>>> | undefined {\n\t\tconst eventListeners = this.getEventListeners(state, event)\n\t\tif (eventListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn Array.from(eventListeners.values(), listener => {\n\t\t\treturn () => listener(...listenerArgs)\n\t\t}) as Array<() => ReturnType<Exclude<EventListenerTypes[1][EventType], undefined>>>\n\t}\n\n\tprivate handleRejections(handler: string, promises: PromiseSettledResult<any>[]) {\n\t\tconst rejections = promises.filter((it): it is PromiseRejectedResult => it.status === 'rejected')\n\t\tif (rejections.length === 0) {\n\t\t\treturn\n\t\t}\n\t\trejections.forEach(it => console.error(it.reason))\n\t\tif (import.meta.env.DEV) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`A ${handler} handler returned a promise that rejected. ` +\n\t\t\t\t\t`This is a no-op that will fail silently in production.`,\n\t\t\t)\n\t\t}\n\t}\n\n\tprivate async executeWithoutChanges<T>(eventType: string, cb: () => Promise<T>): Promise<T> {\n\t\tconst changesCountBefore = this.dirtinessTracker.getTotalChangesCount()\n\t\tconst result = await cb()\n\t\tconst changesCountAfter = this.dirtinessTracker.getTotalChangesCount()\n\t\tif (import.meta.env.DEV) {\n\t\t\tif (changesCountBefore !== changesCountAfter) {\n\t\t\t\t// This isn't bulletproof. They could e.g. undo a change and make another one which would\n\t\t\t\t// slip through this detection. But for most cases, it should be good enough and not too expensive.\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`A ${eventType} event handler cannot be asynchronous and alter the accessor tree at the same time. ` +\n\t\t\t\t\t\t`To achieve this, prepare your data asynchronously but only touch the tree from a returned callback.`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;AA8BO,MAAM,aAAa;AAAA,EAiBlB,YACW,0BACA,qBACA,QACA,kBACA,UACA,WAChB;AArBM,4CAAmB;AACnB,iDAAwB;AAIxB,sCAAsB;AACtB;AAEA;AAEA,6EAA0F;AAC1F,uEAA8C;AAC9C,uEAAkD;AAGxC,SAAA,2BAAA;AACA,SAAA,sBAAA;AACA,SAAA,SAAA;AACA,SAAA,mBAAA;AACA,SAAA,WAAA;AACA,SAAA,YAAA;AAAA,EACf;AAAA,QAEU,iBAAiB,WAAqF;AAC9G,QAAA,KAAK,mBAAmB,GAAG;AACxB,YAAA,IAAI,aAAa,mDAAmD;AAAA,IAC3E;AACA,UAAM,mBAAmB,KAAK;AAC9B,QAAI,qBAAqB,QAAW;AACnC,aAAO,MAAM;AAAA,IACd;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AAC5B;AAAA,IACD;AACA,eAAW,QAAQ,CAAM,OAAA,QAAQ,MAAM,GAAG,MAAM,CAAC;AAAA,EAOlD;AAAA,QAEc,sBAAyB,WAAmB,IAAkC;AAChE,SAAK,iBAAiB,qBAAqB;AAChE,UAAA,SAAS,MAAM;AACK,SAAK,iBAAiB,qBAAqB;AAW9D,WAAA;AAAA,EACR;AACD;AApiBwB,cADjB,cACiB,yBAAwB;;"}
1
+ {"version":3,"file":"EventManager.js","sources":["../../../src/core/EventManager.ts"],"sourcesContent":["import * as ReactDOM from 'react-dom'\nimport type {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tEntityAccessor,\n\tEntityListAccessor,\n\tFieldAccessor,\n\tPersistErrorOptions,\n\tPersistSuccessOptions,\n} from '../accessors'\nimport type { SuccessfulPersistResult } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { PlaceholderName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport type { Config } from './Config'\nimport type { DirtinessTracker } from './DirtinessTracker'\nimport {\n\tEntityListState,\n\tEntityRealmState,\n\tFieldState,\n\tgetEntityMarker,\n\tRootStateNode,\n\tStateINode,\n\tStateIterator,\n\tStateNode,\n} from './state'\nimport type { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport type { EventListenersStore } from '../treeParameters'\n\nexport class EventManager {\n\tpublic static readonly NO_CHANGES_DIFFERENCE = 0\n\n\tprivate transactionDepth = 0\n\tprivate isFrozenWhileUpdating = false\n\n\t// This should ideally not exists as it should be synonymous to `this.ongoingPersistOperation !== undefined`\n\t// but it makes persist-related promise juggling significantly more straightforward.\n\tprivate isMutating: boolean = false\n\tprivate ongoingPersistOperation: Promise<SuccessfulPersistResult> | undefined = undefined\n\n\tprivate previousMetadata: UpdateMetadata | undefined = undefined\n\n\tprivate newlyInitializedWithListeners: Set<EntityListState | EntityRealmState | FieldState> = new Set()\n\tprivate pendingWithBeforeUpdate: Set<StateNode> = new Set()\n\tprivate rootsWithPendingUpdates: Set<RootStateNode> = new Set()\n\n\tpublic constructor(\n\t\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly config: Config,\n\t\tprivate readonly dirtinessTracker: DirtinessTracker,\n\t\tprivate readonly onUpdate: (metadata: UpdateMetadata) => void,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic async persistOperation(operation: () => Promise<SuccessfulPersistResult>): Promise<SuccessfulPersistResult> {\n\t\tif (this.transactionDepth > 0) {\n\t\t\tthrow new BindingError(`Cannot trigger a persist whilst batching updates!`)\n\t\t}\n\t\tconst ongoingOperation = this.ongoingPersistOperation\n\t\tif (ongoingOperation !== undefined) {\n\t\t\treturn await ongoingOperation\n\t\t}\n\t\treturn await (this.ongoingPersistOperation = new Promise<SuccessfulPersistResult>(async (resolve, reject) => {\n\t\t\tthis.isMutating = true\n\t\t\tthis.flushUpdates() // Let the world know that we're mutating\n\n\t\t\ttry {\n\t\t\t\tresolve(await this.asyncOperation(operation))\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error('PersistError', e)\n\t\t\t\treject(e)\n\t\t\t} finally {\n\t\t\t\tthis.ongoingPersistOperation = undefined\n\t\t\t\tthis.isMutating = false\n\t\t\t\tthis.flushUpdates()\n\t\t\t}\n\t\t}))\n\t}\n\n\tpublic syncTransaction<T>(transaction: () => T) {\n\t\ttry {\n\t\t\tthis.transactionDepth++\n\t\t\treturn transaction()\n\t\t} finally {\n\t\t\tthis.transactionDepth--\n\t\t}\n\t}\n\tpublic syncOperation<T>(operation: () => T) {\n\t\tconst result = this.syncTransaction(operation)\n\t\tthis.flushUpdates()\n\t\treturn result\n\t}\n\n\tpublic async asyncTransaction<T>(transaction: () => Promise<T>): Promise<T> {\n\t\ttry {\n\t\t\tthis.transactionDepth++\n\t\t\treturn await transaction()\n\t\t} finally {\n\t\t\tthis.transactionDepth--\n\t\t}\n\t}\n\tpublic async asyncOperation<T>(operation: () => Promise<T>): Promise<T> {\n\t\tconst result = await this.asyncTransaction(operation)\n\t\tthis.flushUpdates()\n\t\treturn result\n\t}\n\n\tprivate flushUpdates() {\n\t\tif (this.transactionDepth > 0) {\n\t\t\treturn\n\t\t}\n\n\t\tif (this.isFrozenWhileUpdating) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Trying to perform an update while the whole accessor tree is already updating. This is most likely caused ` +\n\t\t\t\t\t`by updating the accessor tree while rendering or from within the 'update' event handler, which is a no-op. ` +\n\t\t\t\t\t`If you wish to mutate the tree in reaction to other changes, use the 'beforeUpdate' event.`,\n\t\t\t)\n\t\t}\n\n\t\tconst newMetadata = this.getNewUpdateMetadata()\n\n\t\tif (!this.shouldFlushUpdates(newMetadata)) {\n\t\t\treturn\n\t\t}\n\n\t\tReactDOM.unstable_batchedUpdates(() => {\n\t\t\tthis.isFrozenWhileUpdating = true\n\t\t\tthis.triggerBeforeFlushEvents()\n\t\t\tthis.onUpdate(newMetadata)\n\t\t\tthis.flushPendingAccessorUpdates(Array.from(this.rootsWithPendingUpdates))\n\n\t\t\tthis.rootsWithPendingUpdates.clear()\n\t\t\tthis.isFrozenWhileUpdating = false\n\t\t\tthis.previousMetadata = newMetadata\n\t\t})\n\t}\n\n\tprivate getNewUpdateMetadata(): UpdateMetadata {\n\t\treturn {\n\t\t\tisMutating: this.isMutating,\n\t\t}\n\t}\n\n\tprivate shouldFlushUpdates(newMetadata: UpdateMetadata): boolean {\n\t\tif (this.transactionDepth > 0) {\n\t\t\treturn false\n\t\t}\n\t\tif (this.previousMetadata === undefined) {\n\t\t\treturn true\n\t\t}\n\t\tif (this.rootsWithPendingUpdates.size) {\n\t\t\treturn true\n\t\t}\n\t\tfor (const key in newMetadata) {\n\t\t\tconst fromPrevious = this.previousMetadata[key as keyof UpdateMetadata]\n\t\t\tconst fromNew = newMetadata[key as keyof UpdateMetadata]\n\n\t\t\tif (!Object.is(fromPrevious, fromNew)) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n\n\tpublic registerNewlyInitialized(newlyInitialized: StateNode) {\n\t\tconst initializeListeners = this.getEventListeners(newlyInitialized, { type: 'initialize' })\n\n\t\tif (initializeListeners === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.newlyInitializedWithListeners.add(newlyInitialized)\n\n\t\tif (this.transactionDepth === 0) {\n\t\t\tthis.triggerOnInitialize()\n\t\t}\n\t}\n\n\tpublic registerUpdatedConnection(parentState: EntityRealmState, placeholderName: PlaceholderName) {\n\t\tif (parentState.fieldsWithPendingConnectionUpdates === undefined) {\n\t\t\tparentState.fieldsWithPendingConnectionUpdates = new Set()\n\t\t}\n\n\t\tconst marker = getEntityMarker(parentState)\n\t\tplaceholders: for (const [fieldName, placeholdersByField] of marker.fields.placeholders) {\n\t\t\tif (typeof placeholdersByField === 'string') {\n\t\t\t\tif (placeholdersByField === placeholderName) {\n\t\t\t\t\tparentState.fieldsWithPendingConnectionUpdates.add(fieldName)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (const placeholderByFieldName of placeholdersByField) {\n\t\t\t\t\tif (placeholderByFieldName === placeholderName) {\n\t\t\t\t\t\tparentState.fieldsWithPendingConnectionUpdates.add(fieldName)\n\t\t\t\t\t\tcontinue placeholders\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic registerJustUpdated(justUpdated: StateNode, changesDelta: number) {\n\t\tconst beforeUpdateListeners = this.getEventListeners(justUpdated, { type: 'beforeUpdate' })\n\t\tif (beforeUpdateListeners !== undefined) {\n\t\t\tthis.pendingWithBeforeUpdate.add(justUpdated)\n\t\t}\n\t\tjustUpdated.accessor = undefined\n\n\t\tswitch (justUpdated.type) {\n\t\t\tcase 'entityRealm':\n\t\t\tcase 'entityList': {\n\t\t\t\tjustUpdated.unpersistedChangesCount += changesDelta\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tif (justUpdated.unpersistedChangesCount < 0) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`We have *JUST* reached a completely invalid state. From now on, anything can (and likely will) ` +\n\t\t\t\t\t\t\t\t`go wrong. This is definitely a bug. Please try to report whatever led to this situation.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst parent = justUpdated.blueprint.parent\n\n\t\t\t\tif (parent === undefined) {\n\t\t\t\t\tthis.rootsWithPendingUpdates.add(justUpdated)\n\t\t\t\t\tthis.dirtinessTracker.increaseBy(changesDelta)\n\t\t\t\t} else {\n\t\t\t\t\tif (!parent.childrenWithPendingUpdates) {\n\t\t\t\t\t\tparent.childrenWithPendingUpdates = new Set()\n\t\t\t\t\t}\n\t\t\t\t\tparent.childrenWithPendingUpdates.add(justUpdated as any)\n\t\t\t\t\tthis.registerJustUpdated(parent, changesDelta)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'field': {\n\t\t\t\tconst parent = justUpdated.parent\n\t\t\t\tif (!parent.childrenWithPendingUpdates) {\n\t\t\t\t\tparent.childrenWithPendingUpdates = new Set()\n\t\t\t\t}\n\t\t\t\tparent.childrenWithPendingUpdates.add(justUpdated as any)\n\t\t\t\tthis.registerJustUpdated(justUpdated.parent, changesDelta)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate flushPendingAccessorUpdates(rootStates: Array<StateINode>) {\n\t\t// It is *CRUCIAL* that this is a BFS so that we update the components in top-down order.\n\t\tconst agenda: StateNode[] = rootStates\n\n\t\tfor (const state of agenda) {\n\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\tconst updateListeners =\n\t\t\t\tstate.type === 'field'\n\t\t\t\t\t? this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\t\t\t\t\t: state.type === 'entityRealm'\n\t\t\t\t\t? this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\t\t\t\t\t: this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\n\t\t\tif (updateListeners !== undefined) {\n\t\t\t\tfor (const handler of updateListeners) {\n\t\t\t\t\t// TS can't quite handle the polymorphism here but this is fine.\n\t\t\t\t\thandler()\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (state.type === 'entityRealm' && state.fieldsWithPendingConnectionUpdates) {\n\t\t\t\tfor (const updatedField of state.fieldsWithPendingConnectionUpdates) {\n\t\t\t\t\tconst listeners = this.getEventListeners(state, { type: 'connectionUpdate', key: updatedField })\n\t\t\t\t\tif (!listeners) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tlistener(state.getAccessor())\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tswitch (state.type) {\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (state.childrenWithPendingUpdates !== undefined) {\n\t\t\t\t\t\tfor (const childState of state.childrenWithPendingUpdates) {\n\t\t\t\t\t\t\tagenda.push(childState)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstate.childrenWithPendingUpdates.clear()\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'field':\n\t\t\t\t\t// Do nothing\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\tassertNever(state)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async triggerAsyncMutatingEvent(eventType: 'beforePersist', options: AsyncBatchUpdatesOptions): Promise<void>\n\tprivate async triggerAsyncMutatingEvent(eventType: 'persistSuccess', options: PersistSuccessOptions): Promise<void>\n\tprivate async triggerAsyncMutatingEvent(\n\t\teventType: 'beforePersist' | 'persistSuccess',\n\t\toptions: AsyncBatchUpdatesOptions | PersistSuccessOptions,\n\t): Promise<void> {\n\t\tawait this.asyncTransaction(async () => {\n\t\t\t// TODO if an entity from here (or its parent) gets deleted, we need to remove stale handlers from here.\n\t\t\tconst callbackQueue: Array<\n\t\t\t\t[\n\t\t\t\t\t// The typings could be nicer but TS…\n\t\t\t\t\tStateINode,\n\t\t\t\t\t(\n\t\t\t\t\t\t| EntityAccessor.EntityEventListenerMap[typeof eventType]\n\t\t\t\t\t\t| EntityListAccessor.EntityListEventListenerMap[typeof eventType]\n\t\t\t\t\t),\n\t\t\t\t]\n\t\t\t> = []\n\n\t\t\tfor (const [, subTreeState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const iNode of StateIterator.depthFirstINodes(subTreeState)) {\n\t\t\t\t\tconst listeners = this.getEventListeners(iNode, { type: eventType }) ?? []\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tcallbackQueue.push([iNode, listener])\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (\n\t\t\t\tlet waterfallDepth = 0;\n\t\t\t\twaterfallDepth < this.config.getValue(`${eventType}SettleLimit` as const);\n\t\t\t\twaterfallDepth++\n\t\t\t) {\n\t\t\t\tconst promiseReturns: Array<\n\t\t\t\t\tPromise<\n\t\t\t\t\t\t| void\n\t\t\t\t\t\t| EntityAccessor.EntityEventListenerMap[typeof eventType]\n\t\t\t\t\t\t| EntityListAccessor.EntityListEventListenerMap[typeof eventType]\n\t\t\t\t\t>\n\t\t\t\t> = []\n\t\t\t\tconst correspondingStates: Array<StateINode> = []\n\n\t\t\t\tif (callbackQueue.length === 0) {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\n\t\t\t\tfor (const [state, callback] of callbackQueue) {\n\t\t\t\t\tcorrespondingStates.push(state)\n\t\t\t\t\tconst changesCountBefore = this.dirtinessTracker.getTotalTouchCount()\n\t\t\t\t\tlet validateChanges = false\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = callback(state.getAccessor as any, options as any) // TS can't quite handle this but this is sound.\n\t\t\t\t\t\tif (result instanceof Promise) {\n\t\t\t\t\t\t\tvalidateChanges = true\n\t\t\t\t\t\t\tpromiseReturns.push(result)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tpromiseReturns.push(Promise.resolve(result))\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tpromiseReturns.push(Promise.reject(e))\n\t\t\t\t\t}\n\t\t\t\t\tif (validateChanges) {\n\t\t\t\t\t\tthis.validateWithoutChanges(changesCountBefore, eventType)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// TODO timeout\n\n\t\t\t\tconst changesCountBefore = this.dirtinessTracker.getTotalTouchCount()\n\t\t\t\tconst newCallbacks = await Promise.allSettled(promiseReturns)\n\t\t\t\tthis.validateWithoutChanges(changesCountBefore, eventType)\n\n\t\t\t\tcallbackQueue.length = 0 // Empties the queue\n\n\t\t\t\t// TODO we're drifting away from the original depth-first order. Let's see if that's ever even an issue.\n\t\t\t\tfor (const newlyInitialized of this.newlyInitializedWithListeners) {\n\t\t\t\t\tif (newlyInitialized.type === 'field') {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst beforePersistHandlers = this.getEventListeners(newlyInitialized, { type: eventType })\n\t\t\t\t\tif (beforePersistHandlers) {\n\t\t\t\t\t\tfor (const listener of beforePersistHandlers) {\n\t\t\t\t\t\t\tcallbackQueue.push([newlyInitialized, listener])\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.triggerBeforeFlushEvents()\n\t\t\t\tthis.handleRejections(eventType, newCallbacks)\n\n\t\t\t\tfor (let i = 0; i < newCallbacks.length; i++) {\n\t\t\t\t\tconst result = newCallbacks[i]\n\t\t\t\t\tconst correspondingState = correspondingStates[i]\n\n\t\t\t\t\tif (result.status === 'fulfilled') {\n\t\t\t\t\t\tif (typeof result.value === 'function') {\n\t\t\t\t\t\t\tcallbackQueue.push([correspondingState, result.value])\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Otherwise do nothing. This is just a handler that albeit async, doesn't appear to\n\t\t\t\t\t\t// interact with data binding.\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\tif (callbackQueue.length) {\n\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t`Exceeded the ${eventType} settle limit. Your code likely contains a deadlock. ` +\n\t\t\t\t\t\t\t`If that's not the case, raise the settle limit from DataBindingProvider.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate triggerBeforeFlushEvents() {\n\t\tthis.syncTransaction(() => {\n\t\t\tconst settleLimit = this.config.getValue('beforeUpdateSettleLimit')\n\n\t\t\tfor (let attemptNumber = 0; attemptNumber < settleLimit; attemptNumber++) {\n\t\t\t\tif (!this.pendingWithBeforeUpdate.size) {\n\t\t\t\t\tthis.triggerOnInitialize()\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst withBeforeUpdate = this.pendingWithBeforeUpdate\n\t\t\t\tthis.pendingWithBeforeUpdate = new Set()\n\n\t\t\t\tfor (const state of withBeforeUpdate) {\n\t\t\t\t\tconst listeners = this.getEventListeners(state, { type: 'beforeUpdate' })\n\t\t\t\t\tif (listeners === undefined) {\n\t\t\t\t\t\t// This can happen if the listener has unsubscribed since we added it to the set.\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tswitch (state.type) {\n\t\t\t\t\t\tcase 'field':\n\t\t\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\t\t\t(listener as FieldAccessor.BeforeUpdateListener)(state.getAccessor())\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\t\t\tstate.getAccessor().batchUpdates(listener as any)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn assertNever(state)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.triggerOnInitialize()\n\t\t\t}\n\t\t\tthrow new BindingError(\n\t\t\t\t`Maximum stabilization limit of updates caused by 'beforeUpdate' exceeded. ` +\n\t\t\t\t\t`This likely means there is an infinite feedback loop in your code.`,\n\t\t\t)\n\t\t})\n\t}\n\n\tprivate triggerOnInitialize() {\n\t\tthis.syncTransaction(() => {\n\t\t\tfor (const state of this.newlyInitializedWithListeners) {\n\t\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\t\tconst listeners =\n\t\t\t\t\tstate.type === 'field'\n\t\t\t\t\t\t? this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\t\t\t\t\t\t: state.type === 'entityRealm'\n\t\t\t\t\t\t? this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\t\t\t\t\t\t: this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\n\t\t\t\tif (listeners) {\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tlistener()\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (state.type === 'entityRealm') {\n\t\t\t\t\tstate.entity.hasIdSetInStone = true\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.newlyInitializedWithListeners.clear()\n\t\t})\n\t}\n\n\tpublic async triggerOnPersistError(options: PersistErrorOptions) {\n\t\tawait this.asyncTransaction(async () => {\n\t\t\tconst handlerPromises: Array<Promise<void>> = []\n\n\t\t\tfor (const [, subTreeState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const iNode of StateIterator.depthFirstINodes(subTreeState)) {\n\t\t\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\t\t\tconst dispatchers =\n\t\t\t\t\t\tiNode.type === 'entityRealm'\n\t\t\t\t\t\t\t? this.getEventDispatchers(iNode, { type: 'persistError' }, [iNode.getAccessor, options])\n\t\t\t\t\t\t\t: this.getEventDispatchers(iNode, { type: 'persistError' }, [iNode.getAccessor, options])\n\t\t\t\t\tif (dispatchers === undefined) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const listener of dispatchers ?? []) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst result = listener()\n\t\t\t\t\t\t\tif (result instanceof Promise) {\n\t\t\t\t\t\t\t\thandlerPromises.push(result)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\thandlerPromises.push(Promise.resolve(result))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\thandlerPromises.push(Promise.reject(e))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// TODO timeout\n\t\t\tconst handlerResults = await Promise.allSettled(handlerPromises)\n\t\t\tthis.handleRejections('persistError', handlerResults)\n\t\t})\n\t}\n\n\tpublic async triggerOnBeforePersist() {\n\t\treturn this.triggerAsyncMutatingEvent('beforePersist', this.asyncBatchUpdatesOptions)\n\t}\n\n\tpublic async triggerOnPersistSuccess(options: PersistSuccessOptions) {\n\t\treturn this.triggerAsyncMutatingEvent('persistSuccess', options)\n\t}\n\n\tpublic getEventListeners<\n\t\tState extends StateNode,\n\t\tEventListenerTypes extends\n\t\t\tExclude<State['eventListeners'], undefined> extends EventListenersStore<infer Keys, infer Map> ? [Keys, Map] : never,\n\t\tEventType extends EventListenerTypes[0],\n\t>(state: State, event: { type: EventType; key?: string }): Set<Exclude<EventListenerTypes[1][EventType], undefined>> | undefined {\n\t\tif (!state.eventListeners) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn (state.eventListeners as EventListenersStore<EventType, EventListenerTypes[1]>).get(event) as Set<\n\t\t\tExclude<EventListenerTypes[1][EventType], undefined>\n\t\t>\n\t}\n\n\tpublic getEventDispatchers<\n\t\tState extends StateNode,\n\t\tEventListenerTypes extends\n\t\t\tExclude<State['eventListeners'], undefined> extends EventListenersStore<infer Keys, infer Map> ? [Keys, Map] : never,\n\t\tEventType extends EventListenerTypes[0],\n\t>(\n\t\tstate: State,\n\t\tevent: { type: EventType; key?: string },\n\t\tlistenerArgs: Parameters<Exclude<EventListenerTypes[1][EventType], undefined>>,\n\t): Array<() => ReturnType<Exclude<EventListenerTypes[1][EventType], undefined>>> | undefined {\n\t\tconst eventListeners = this.getEventListeners(state, event)\n\t\tif (eventListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn Array.from(eventListeners.values(), listener => {\n\t\t\treturn () => listener(...listenerArgs)\n\t\t}) as Array<() => ReturnType<Exclude<EventListenerTypes[1][EventType], undefined>>>\n\t}\n\n\tprivate handleRejections(handler: string, promises: PromiseSettledResult<any>[]) {\n\t\tconst rejections = promises.filter((it): it is PromiseRejectedResult => it.status === 'rejected')\n\t\tif (rejections.length === 0) {\n\t\t\treturn\n\t\t}\n\t\trejections.forEach(it => console.error(it.reason))\n\t\tif (import.meta.env.DEV) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`A ${handler} handler returned a promise that rejected. ` +\n\t\t\t\t\t`This is a no-op that will fail silently in production.`,\n\t\t\t)\n\t\t}\n\t}\n\n\n\tprivate validateWithoutChanges(initialCount: number, eventType: string): void {\n\t\tconst changesCountAfter = this.dirtinessTracker.getTotalTouchCount()\n\t\tif (import.meta.env.DEV) {\n\t\t\tif (initialCount !== changesCountAfter) {\n\t\t\t\t// This isn't bulletproof. They could e.g. undo a change and make another one which would\n\t\t\t\t// slip through this detection. But for most cases, it should be good enough and not too expensive.\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`A ${eventType} event handler cannot be asynchronous and alter the accessor tree at the same time. ` +\n\t\t\t\t\t`To achieve this, prepare your data asynchronously but only touch the tree from a returned callback.`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":[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AAA,EACF;AAAA,QAEa,yBAAyB;AACrC,WAAO,KAAK,0BAA0B,iBAAiB,KAAK,wBAAwB;AAAA,EACrF;AAAA,QAEa,wBAAwB,SAAgC;AAC7D,WAAA,KAAK,0BAA0B,kBAAkB,OAAO;AAAA,EAChE;AAAA,EAEO,kBAKL,OAAc,OAAiH;AAC5H,QAAA,CAAC,MAAM,gBAAgB;AACnB,aAAA;AAAA,IACR;AACQ,WAAA,MAAM,eAAyE,IAAI,KAAK;AAAA,EAGjG;AAAA,EAEO,oBAMN,OACA,OACA,cAC4F;AAC5F,UAAM,iBAAiB,KAAK,kBAAkB,OAAO,KAAK;AAC1D,QAAI,mBAAmB,QAAW;AAC1B,aAAA;AAAA,IACR;AACA,WAAO,MAAM,KAAK,eAAe,UAAU,CAAY,aAAA;AAC/C,aAAA,MAAM,SAAS,GAAG,YAAY;AAAA,IAAA,CACrC;AAAA,EACF;AAAA,EAEQ,iBAAiB,SAAiB,UAAuC;AAChF,UAAM,aAAa,SAAS,OAAO,CAAC,OAAoC,GAAG,WAAW,UAAU;AAC5F,QAAA,WAAW,WAAW,GAAG;AAC5B;AAAA,IACD;AACA,eAAW,QAAQ,CAAM,OAAA,QAAQ,MAAM,GAAG,MAAM,CAAC;AAAA,EAOlD;AAAA,EAGQ,uBAAuB,cAAsB,WAAyB;AACnD,SAAK,iBAAiB,mBAAmB;AAAA,EAWpE;AACD;AA1iBwB,cADjB,cACiB,yBAAwB;;"}
@@ -6,9 +6,9 @@ var __publicField = (obj, key, value) => {
6
6
  };
7
7
  import { MarkerMerger } from "./MarkerMerger.js";
8
8
  import { TreeParameterMerger } from "./TreeParameterMerger.js";
9
- import { EntityFieldsWithHoistablesMarker } from "../markers/EntityFieldsWithHoistablesMarker.js";
10
9
  import { MarkerFactory } from "../queryLanguage/MarkerFactory.js";
11
10
  import { EntityFieldMarkersContainer } from "../markers/EntityFieldMarkersContainer.js";
11
+ import { EntityFieldsWithHoistablesMarker } from "../markers/EntityFieldsWithHoistablesMarker.js";
12
12
  class IncrementalMarkerBuilder {
13
13
  constructor() {
14
14
  __publicField(this, "accumulator", new EntityFieldMarkersContainer(false, /* @__PURE__ */ new Map(), /* @__PURE__ */ new Map()));
@@ -1,14 +1,14 @@
1
1
  import { BindingError } from "../BindingError.js";
2
2
  import { PRIMARY_KEY_NAME } from "../bindingTypes.js";
3
3
  import { TreeParameterMerger } from "./TreeParameterMerger.js";
4
+ import { MarkerTreeRoot } from "../markers/MarkerTreeRoot.js";
4
5
  import { FieldMarker } from "../markers/FieldMarker.js";
5
6
  import { HasOneRelationMarker } from "../markers/HasOneRelationMarker.js";
6
7
  import { HasManyRelationMarker } from "../markers/HasManyRelationMarker.js";
7
8
  import { EntitySubTreeMarker } from "../markers/EntitySubTreeMarker.js";
8
9
  import { EntityListSubTreeMarker } from "../markers/EntityListSubTreeMarker.js";
9
- import { MarkerTreeRoot } from "../markers/MarkerTreeRoot.js";
10
- import { EntityFieldMarkersContainer } from "../markers/EntityFieldMarkersContainer.js";
11
10
  import { assertNever } from "../utils/assertNever.js";
11
+ import { EntityFieldMarkersContainer } from "../markers/EntityFieldMarkersContainer.js";
12
12
  class MarkerMerger {
13
13
  static mergeMarkers(original, fresh) {
14
14
  if (original === fresh) {
@@ -1,34 +1,52 @@
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
+ };
1
7
  import { CrudQueryBuilder, GraphQlBuilder } from "@contember/client";
2
8
  import { BindingError } from "../BindingError.js";
3
9
  import { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from "../bindingTypes.js";
4
10
  import { QueryGenerator } from "./QueryGenerator.js";
5
- import { mutationOperationType } from "./requestAliases/mutationOperationType.js";
6
11
  import { isEmptyObject } from "../utils/isEmptyObject.js";
7
- import { ClientGeneratedUuid, ServerGeneratedUuid } from "../accessorTree/RuntimeId.js";
8
- import { mutationOperationSubTreeType } from "./requestAliases/mutationOperationSubTreeType.js";
9
- import { MutationAlias } from "./requestAliases/MutationAlias.js";
12
+ import { ClientGeneratedUuid, ServerId } from "../accessorTree/RuntimeId.js";
10
13
  import { assertNever } from "../utils/assertNever.js";
11
14
  import { getEntityMarker } from "./state/getEntityMarker.js";
15
+ import { StateIterator } from "./state/StateIterator.js";
12
16
  import { HasManyRelationMarker } from "../markers/HasManyRelationMarker.js";
13
17
  import { HasOneRelationMarker } from "../markers/HasOneRelationMarker.js";
18
+ import { MutationAlias } from "./requestAliases/MutationAlias.js";
14
19
  class MutationGenerator {
15
20
  constructor(treeStore) {
21
+ __publicField(this, "aliasCounter", 1);
16
22
  this.treeStore = treeStore;
17
23
  }
18
24
  getPersistMutation() {
19
25
  try {
20
26
  let builder = new CrudQueryBuilder.CrudQueryBuilder();
27
+ const operations = [];
21
28
  const processedPlaceholdersByEntity = /* @__PURE__ */ new Map();
22
- for (const [treeRootId, rootStates] of this.treeStore.subTreeStatesByRoot) {
23
- for (const [placeholderName, subTreeState] of rootStates) {
29
+ for (const [treeRootId, rootStates] of this.treeStore.subTreeStatesByRoot.entries()) {
30
+ for (const [placeholderName, subTreeState] of Array.from(rootStates.entries()).reverse()) {
31
+ if (subTreeState.unpersistedChangesCount <= 0) {
32
+ continue;
33
+ }
24
34
  if (subTreeState.type === "entityRealm") {
25
- builder = this.addSubMutation(processedPlaceholdersByEntity, treeRootId, placeholderName, mutationOperationSubTreeType.singleEntity, subTreeState.entity.id.value, subTreeState, builder);
35
+ const subMutation = this.addSubMutation(processedPlaceholdersByEntity, placeholderName, "single", subTreeState.entity.id.value, subTreeState, builder);
36
+ if (subMutation) {
37
+ builder = subMutation[0];
38
+ operations.push(subMutation[1]);
39
+ }
26
40
  } else if (subTreeState.type === "entityList") {
27
41
  for (const childState of subTreeState.children.values()) {
28
42
  if (childState.type === "entityRealmStub") {
29
43
  continue;
30
44
  }
31
- builder = this.addSubMutation(processedPlaceholdersByEntity, treeRootId, placeholderName, mutationOperationSubTreeType.entityList, childState.entity.id.value, childState, builder);
45
+ const subMutation = this.addSubMutation(processedPlaceholdersByEntity, placeholderName, "list", childState.entity.id.value, childState, builder);
46
+ if (subMutation) {
47
+ builder = subMutation[0];
48
+ operations.push(subMutation[1]);
49
+ }
32
50
  }
33
51
  if (subTreeState.plannedRemovals) {
34
52
  for (const [removedId, removalType] of subTreeState.plannedRemovals) {
@@ -36,13 +54,9 @@ class MutationGenerator {
36
54
  continue;
37
55
  }
38
56
  if (removalType === "delete") {
39
- builder = this.addDeleteMutation(subTreeState.entityName, removedId, MutationAlias.encodeTopLevel({
40
- treeRootId,
41
- subTreePlaceholder: placeholderName,
42
- type: mutationOperationType.delete,
43
- subTreeType: mutationOperationSubTreeType.entityList,
44
- entityId: removedId
45
- }), builder);
57
+ const alias = this.createAlias();
58
+ builder = this.addDeleteMutation(subTreeState.entityName, removedId, alias, builder);
59
+ operations.push({ alias, subTreePlaceholder: placeholderName, subTreeType: "list", type: "delete", id: removedId });
46
60
  } else {
47
61
  assertNever(removalType);
48
62
  }
@@ -53,42 +67,65 @@ class MutationGenerator {
53
67
  }
54
68
  }
55
69
  }
56
- return builder.inTransaction(void 0, { deferForeignKeyConstraints: true }).getGql();
70
+ const query = builder.inTransaction(void 0, { deferForeignKeyConstraints: true }).getGql();
71
+ return { query, operations };
57
72
  } catch (e) {
58
73
  return void 0;
59
74
  }
60
75
  }
61
- addSubMutation(processedPlaceholdersByEntity, treeRootId, subTreePlaceholder, subTreeType, entityId, realmState, queryBuilder) {
76
+ addSubMutation(processedPlaceholdersByEntity, subTreePlaceholder, subTreeType, entityId, realmState, queryBuilder) {
62
77
  if (realmState.unpersistedChangesCount === 0) {
63
- return queryBuilder;
78
+ return void 0;
64
79
  }
80
+ const fieldMarkers = getEntityMarker(realmState).fields.markers;
81
+ const alias = this.createAlias();
65
82
  if (realmState.entity.isScheduledForDeletion) {
66
- return this.addDeleteMutation(realmState.entity.entityName, entityId, MutationAlias.encodeTopLevel({
67
- treeRootId,
68
- subTreePlaceholder,
69
- type: mutationOperationType.delete,
70
- subTreeType,
71
- entityId
72
- }), queryBuilder);
83
+ const builder2 = this.addDeleteMutation(realmState.entity.entityName, entityId, alias, queryBuilder);
84
+ return [
85
+ builder2,
86
+ {
87
+ alias,
88
+ subTreePlaceholder,
89
+ subTreeType,
90
+ type: "delete",
91
+ id: entityId
92
+ }
93
+ ];
73
94
  } else if (!realmState.entity.id.existsOnServer) {
74
- return this.addCreateMutation(processedPlaceholdersByEntity, realmState, MutationAlias.encodeTopLevel({
75
- treeRootId,
95
+ const builder2 = this.addCreateMutation(processedPlaceholdersByEntity, realmState, alias, this.getNodeFragmentName(subTreePlaceholder, subTreeType, realmState), queryBuilder, fieldMarkers);
96
+ if (!builder2) {
97
+ return void 0;
98
+ }
99
+ return [
100
+ builder2,
101
+ {
102
+ alias,
103
+ subTreePlaceholder,
104
+ subTreeType,
105
+ type: "create",
106
+ markers: fieldMarkers,
107
+ id: entityId
108
+ }
109
+ ];
110
+ }
111
+ const builder = this.addUpdateMutation(processedPlaceholdersByEntity, realmState, alias, this.getNodeFragmentName(subTreePlaceholder, subTreeType, realmState), queryBuilder, fieldMarkers);
112
+ if (!builder) {
113
+ return void 0;
114
+ }
115
+ return [
116
+ builder,
117
+ {
118
+ alias,
76
119
  subTreePlaceholder,
77
- type: mutationOperationType.create,
78
120
  subTreeType,
79
- entityId
80
- }), this.getNodeFragmentName(subTreePlaceholder, subTreeType, realmState), queryBuilder);
81
- }
82
- return this.addUpdateMutation(processedPlaceholdersByEntity, realmState, MutationAlias.encodeTopLevel({
83
- treeRootId,
84
- subTreePlaceholder,
85
- type: mutationOperationType.update,
86
- subTreeType,
87
- entityId
88
- }), this.getNodeFragmentName(subTreePlaceholder, subTreeType, realmState), queryBuilder);
121
+ type: "update",
122
+ id: entityId,
123
+ markers: fieldMarkers
124
+ }
125
+ ];
89
126
  }
90
127
  getNodeFragmentName(subTreePlaceholder, subTreeType, realmState) {
91
- if (subTreeType !== mutationOperationSubTreeType.entityList) {
128
+ if (subTreeType !== "list") {
92
129
  return void 0;
93
130
  }
94
131
  return `${realmState.entity.entityName}_${subTreePlaceholder}`;
@@ -96,27 +133,27 @@ class MutationGenerator {
96
133
  addDeleteMutation(entityName, deletedId, alias, queryBuilder = new CrudQueryBuilder.CrudQueryBuilder()) {
97
134
  return queryBuilder.delete(entityName, (builder) => builder.ok().node((builder2) => builder2.column(PRIMARY_KEY_NAME)).by({ [PRIMARY_KEY_NAME]: deletedId }).errors().errorMessage(), alias);
98
135
  }
99
- addUpdateMutation(processedPlaceholdersByEntity, entityRealm, alias, nodeFragmentName, queryBuilder = new CrudQueryBuilder.CrudQueryBuilder()) {
136
+ addUpdateMutation(processedPlaceholdersByEntity, entityRealm, alias, nodeFragmentName, queryBuilder = new CrudQueryBuilder.CrudQueryBuilder(), fieldMarkers) {
100
137
  const updateBuilder = this.registerUpdateMutationPart(processedPlaceholdersByEntity, entityRealm, new CrudQueryBuilder.WriteDataBuilder());
101
138
  if (updateBuilder.data === void 0 || isEmptyObject(updateBuilder.data)) {
102
- return queryBuilder;
139
+ return void 0;
103
140
  }
104
141
  const runtimeId = entityRealm.entity.id;
105
142
  if (!runtimeId.existsOnServer) {
106
- return queryBuilder;
143
+ return void 0;
107
144
  }
108
- const readBuilder = QueryGenerator.registerQueryPart(getEntityMarker(entityRealm).fields.markers, CrudQueryBuilder.ReadBuilder.instantiate());
145
+ const readBuilder = QueryGenerator.registerQueryPart(fieldMarkers, CrudQueryBuilder.ReadBuilder.instantiate());
109
146
  if (nodeFragmentName) {
110
147
  queryBuilder = queryBuilder.fragment(nodeFragmentName, entityRealm.entity.entityName, readBuilder);
111
148
  }
112
149
  return queryBuilder.update(entityRealm.entity.entityName, (builder) => builder.node(nodeFragmentName ? (builder2) => builder2.applyFragment(nodeFragmentName) : readBuilder).data(updateBuilder).by({ [PRIMARY_KEY_NAME]: runtimeId.value }).ok().validation().errors().errorMessage(), alias);
113
150
  }
114
- addCreateMutation(processedPlaceholdersByEntity, entityRealm, alias, nodeFragmentName, queryBuilder = new CrudQueryBuilder.CrudQueryBuilder()) {
151
+ addCreateMutation(processedPlaceholdersByEntity, entityRealm, alias, nodeFragmentName, queryBuilder = new CrudQueryBuilder.CrudQueryBuilder(), fieldMarkers) {
115
152
  const createBuilder = this.registerCreateMutationPart(processedPlaceholdersByEntity, entityRealm, new CrudQueryBuilder.WriteDataBuilder());
116
153
  if (createBuilder.data === void 0 || isEmptyObject(createBuilder.data)) {
117
- return queryBuilder;
154
+ return void 0;
118
155
  }
119
- const readBuilder = QueryGenerator.registerQueryPart(getEntityMarker(entityRealm).fields.markers, CrudQueryBuilder.ReadBuilder.instantiate());
156
+ const readBuilder = QueryGenerator.registerQueryPart(fieldMarkers, CrudQueryBuilder.ReadBuilder.instantiate());
120
157
  if (nodeFragmentName) {
121
158
  queryBuilder = queryBuilder.fragment(nodeFragmentName, entityRealm.entity.entityName, readBuilder);
122
159
  }
@@ -132,103 +169,105 @@ class MutationGenerator {
132
169
  if (currentState.type === "entityRealmStub") {
133
170
  return builder;
134
171
  }
135
- const pathBack = this.treeStore.getPathBackToParent(currentState);
136
- const nonbearingFields = [];
137
- for (const [placeholderName, fieldState] of currentState.children) {
138
- if (processedPlaceholders.has(placeholderName)) {
139
- continue;
140
- }
141
- processedPlaceholders.add(placeholderName);
142
- switch (fieldState.type) {
143
- case "field": {
144
- const marker = fieldState.fieldMarker;
145
- const placeholderName2 = marker.placeholderName;
146
- if (placeholderName2 === TYPENAME_KEY_NAME || placeholderName2 === PRIMARY_KEY_NAME && !(currentState.entity.id instanceof ClientGeneratedUuid)) {
147
- continue;
148
- }
149
- if (marker.isNonbearing) {
150
- nonbearingFields.push({
151
- type: "field",
152
- marker,
153
- fieldState
154
- });
155
- continue;
156
- }
157
- builder = this.registerCreateFieldPart(fieldState, marker, builder);
158
- break;
159
- }
160
- case "entityRealmStub":
161
- case "entityRealm": {
162
- const marker = getEntityMarker(fieldState);
163
- if (!(marker instanceof HasOneRelationMarker)) {
164
- throw new BindingError();
165
- }
166
- if (pathBack?.fieldBackToParent === marker.parameters.field) {
167
- continue;
168
- }
169
- if (marker.parameters.isNonbearing) {
170
- nonbearingFields.push({
171
- type: "hasOne",
172
- marker,
173
- fieldState
174
- });
175
- continue;
176
- }
177
- builder = this.registerCreateEntityPart(processedPlaceholdersByEntity, fieldState, marker, builder);
178
- break;
179
- }
180
- case "entityList": {
181
- const marker = fieldState.blueprint.marker;
182
- if (!(marker instanceof HasManyRelationMarker)) {
183
- throw new BindingError();
184
- }
185
- if (pathBack?.fieldBackToParent === marker.parameters.field) {
186
- continue;
187
- }
188
- if (marker.parameters.isNonbearing) {
189
- nonbearingFields.push({
190
- type: "hasMany",
191
- marker,
192
- fieldState
193
- });
194
- continue;
195
- }
196
- builder = this.registerCreateEntityListPart(processedPlaceholdersByEntity, fieldState, marker, builder);
197
- break;
198
- }
199
- default: {
200
- return assertNever();
172
+ for (const siblingState of StateIterator.eachSiblingRealm(currentState)) {
173
+ const pathBack = this.treeStore.getPathBackToParent(siblingState);
174
+ const nonbearingFields = [];
175
+ for (const [placeholderName, fieldState] of siblingState.children) {
176
+ if (processedPlaceholders.has(placeholderName)) {
177
+ continue;
201
178
  }
202
- }
203
- }
204
- if (builder.data !== void 0 && !isEmptyObject(builder.data) || !getEntityMarker(currentState).fields.hasAtLeastOneBearingField) {
205
- for (const field of nonbearingFields) {
206
- switch (field.type) {
179
+ processedPlaceholders.add(placeholderName);
180
+ switch (fieldState.type) {
207
181
  case "field": {
208
- builder = this.registerCreateFieldPart(field.fieldState, field.marker, builder);
182
+ const marker = fieldState.fieldMarker;
183
+ const placeholderName2 = marker.placeholderName;
184
+ if (placeholderName2 === TYPENAME_KEY_NAME || placeholderName2 === PRIMARY_KEY_NAME && !(siblingState.entity.id instanceof ClientGeneratedUuid)) {
185
+ continue;
186
+ }
187
+ if (marker.isNonbearing) {
188
+ nonbearingFields.push({
189
+ type: "field",
190
+ marker,
191
+ fieldState
192
+ });
193
+ continue;
194
+ }
195
+ builder = this.registerCreateFieldPart(fieldState, marker, builder);
209
196
  break;
210
197
  }
211
- case "hasOne": {
212
- builder = this.registerCreateEntityPart(processedPlaceholdersByEntity, field.fieldState, field.marker, builder);
198
+ case "entityRealmStub":
199
+ case "entityRealm": {
200
+ const marker = getEntityMarker(fieldState);
201
+ if (!(marker instanceof HasOneRelationMarker)) {
202
+ throw new BindingError();
203
+ }
204
+ if (pathBack?.fieldBackToParent === marker.parameters.field) {
205
+ continue;
206
+ }
207
+ if (marker.parameters.isNonbearing) {
208
+ nonbearingFields.push({
209
+ type: "hasOne",
210
+ marker,
211
+ fieldState
212
+ });
213
+ continue;
214
+ }
215
+ builder = this.registerCreateEntityPart(processedPlaceholdersByEntity, fieldState, marker, builder);
213
216
  break;
214
217
  }
215
- case "hasMany": {
216
- builder = this.registerCreateEntityListPart(processedPlaceholdersByEntity, field.fieldState, field.marker, builder);
218
+ case "entityList": {
219
+ const marker = fieldState.blueprint.marker;
220
+ if (!(marker instanceof HasManyRelationMarker)) {
221
+ throw new BindingError();
222
+ }
223
+ if (pathBack?.fieldBackToParent === marker.parameters.field) {
224
+ continue;
225
+ }
226
+ if (marker.parameters.isNonbearing) {
227
+ nonbearingFields.push({
228
+ type: "hasMany",
229
+ marker,
230
+ fieldState
231
+ });
232
+ continue;
233
+ }
234
+ builder = this.registerCreateEntityListPart(processedPlaceholdersByEntity, fieldState, marker, builder);
217
235
  break;
218
236
  }
219
- default:
220
- assertNever();
237
+ default: {
238
+ return assertNever();
239
+ }
221
240
  }
222
241
  }
223
- }
224
- const setOnCreate = getEntityMarker(currentState).parameters.setOnCreate;
225
- if (setOnCreate && builder.data !== void 0 && !isEmptyObject(builder.data)) {
226
- for (const key in setOnCreate) {
227
- const field = setOnCreate[key];
228
- if (typeof field === "string" || typeof field === "number" || field === null || field instanceof GraphQlBuilder.GraphQlLiteral) {
229
- builder = builder.set(key, field);
230
- } else {
231
- builder = builder.one(key, (builder2) => builder2.connect(field));
242
+ if (builder.data !== void 0 && !isEmptyObject(builder.data) || !getEntityMarker(siblingState).fields.hasAtLeastOneBearingField) {
243
+ for (const field of nonbearingFields) {
244
+ switch (field.type) {
245
+ case "field": {
246
+ builder = this.registerCreateFieldPart(field.fieldState, field.marker, builder);
247
+ break;
248
+ }
249
+ case "hasOne": {
250
+ builder = this.registerCreateEntityPart(processedPlaceholdersByEntity, field.fieldState, field.marker, builder);
251
+ break;
252
+ }
253
+ case "hasMany": {
254
+ builder = this.registerCreateEntityListPart(processedPlaceholdersByEntity, field.fieldState, field.marker, builder);
255
+ break;
256
+ }
257
+ default:
258
+ assertNever();
259
+ }
260
+ }
261
+ }
262
+ const setOnCreate = getEntityMarker(siblingState).parameters.setOnCreate;
263
+ if (setOnCreate && builder.data !== void 0 && !isEmptyObject(builder.data)) {
264
+ for (const key in setOnCreate) {
265
+ const field = setOnCreate[key];
266
+ if (typeof field === "string" || typeof field === "number" || field === null || field instanceof GraphQlBuilder.GraphQlLiteral) {
267
+ builder = builder.set(key, field);
268
+ } else {
269
+ builder = builder.one(key, (builder2) => builder2.connect(field));
270
+ }
232
271
  }
233
272
  }
234
273
  }
@@ -279,7 +318,7 @@ class MutationGenerator {
279
318
  processedPlaceholdersByEntity.set(currentState.entity, processedPlaceholders = /* @__PURE__ */ new Set());
280
319
  }
281
320
  const pathBack = this.treeStore.getPathBackToParent(currentState);
282
- const entityData = this.treeStore.persistedEntityData.get(currentState.entity.id.value);
321
+ const entityData = this.treeStore.persistedEntityData.get(currentState.entity.id.uniqueValue);
283
322
  for (const [placeholderName, fieldState] of currentState.children) {
284
323
  if (placeholderName === PRIMARY_KEY_NAME || placeholderName === TYPENAME_KEY_NAME) {
285
324
  continue;
@@ -312,7 +351,7 @@ class MutationGenerator {
312
351
  if (reducedBy === void 0) {
313
352
  const subBuilder = ((builder2) => {
314
353
  const persistedValue = entityData?.get?.(placeholderName);
315
- if (persistedValue instanceof ServerGeneratedUuid) {
354
+ if (persistedValue instanceof ServerId) {
316
355
  if (persistedValue.value === runtimeId.value) {
317
356
  if (fieldState.type === "entityRealmStub") {
318
357
  return builder2;
@@ -348,7 +387,7 @@ class MutationGenerator {
348
387
  builder = builder.many(marker.parameters.field, (builder2) => {
349
388
  const persistedValue = entityData?.get?.(placeholderName);
350
389
  const alias = MutationAlias.encodeEntityId(runtimeId);
351
- if (persistedValue instanceof ServerGeneratedUuid) {
390
+ if (persistedValue instanceof ServerId) {
352
391
  if (persistedValue.value === runtimeId.value) {
353
392
  if (fieldState.type === "entityRealmStub") {
354
393
  return builder2;
@@ -406,7 +445,7 @@ class MutationGenerator {
406
445
  }
407
446
  if (fieldState.plannedRemovals) {
408
447
  for (const [removedId, removalType] of fieldState.plannedRemovals) {
409
- const alias = MutationAlias.encodeEntityId(new ServerGeneratedUuid(removedId));
448
+ const alias = MutationAlias.encodeEntityId(new ServerId(removedId, fieldState.entityName));
410
449
  if (removalType === "delete") {
411
450
  builder2 = builder2.delete({ [PRIMARY_KEY_NAME]: removedId }, alias);
412
451
  } else if (removalType === "disconnect") {
@@ -430,12 +469,12 @@ class MutationGenerator {
430
469
  if (typeof value !== "string") {
431
470
  return value;
432
471
  }
433
- const fieldSchema = this.treeStore.schema.getEntityField(fieldState.parent.entity.entityName, fieldState.fieldMarker.fieldName);
434
- if (fieldSchema === void 0 || fieldSchema.__typename !== "_Column") {
435
- throw new BindingError();
436
- }
472
+ const fieldSchema = this.treeStore.schema.getEntityColumn(fieldState.parent.entity.entityName, fieldState.fieldMarker.fieldName);
437
473
  return fieldSchema.enumName === null ? value : new GraphQlBuilder.GraphQlLiteral(value);
438
474
  }
475
+ createAlias() {
476
+ return `op_${this.aliasCounter++}`;
477
+ }
439
478
  }
440
479
  export { MutationGenerator };
441
480
  //# sourceMappingURL=MutationGenerator.js.map