@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":"MutationGenerator.js","sources":["../../../src/core/MutationGenerator.ts"],"sourcesContent":["// noinspection JSVoidFunctionReturnValueUsed // IntelliJ seems to be super confused througouht this file.\n\nimport { CrudQueryBuilder, GraphQlBuilder } from '@contember/client'\nimport { ClientGeneratedUuid, ServerGeneratedUuid } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '../bindingTypes'\nimport { FieldMarker, HasManyRelationMarker, HasOneRelationMarker } from '../markers'\nimport type { EntityId, EntityName, FieldValue, PlaceholderName, TreeRootId } from '../treeParameters'\nimport { assertNever, isEmptyObject } from '../utils'\nimport { QueryGenerator } from './QueryGenerator'\nimport { MutationAlias, mutationOperationSubTreeType, mutationOperationType } from './requestAliases'\nimport {\n\tEntityListState,\n\tEntityRealmState,\n\tEntityRealmStateStub,\n\tEntityState,\n\tFieldState,\n\tgetEntityMarker,\n} from './state'\nimport type { TreeStore } from './TreeStore'\n\ntype QueryBuilder = Omit<CrudQueryBuilder.CrudQueryBuilder, CrudQueryBuilder.Queries>\n\ntype ProcessedPlaceholdersByEntity = Map<EntityState, Set<PlaceholderName>>\n\n// TODO enforce correct expected mutations in dev mode.\nexport class MutationGenerator {\n\tpublic constructor(private readonly treeStore: TreeStore) {}\n\n\tpublic getPersistMutation(): string | undefined {\n\t\ttry {\n\t\t\tlet builder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder()\n\t\t\tconst processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity = new Map()\n\n\t\t\tfor (const [treeRootId, rootStates] of this.treeStore.subTreeStatesByRoot) {\n\t\t\t\tfor (const [placeholderName, subTreeState] of rootStates) {\n\t\t\t\t\tif (subTreeState.type === 'entityRealm') {\n\t\t\t\t\t\tbuilder = this.addSubMutation(\n\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\ttreeRootId,\n\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\tmutationOperationSubTreeType.singleEntity,\n\t\t\t\t\t\t\tsubTreeState.entity.id.value,\n\t\t\t\t\t\t\tsubTreeState,\n\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t)\n\t\t\t\t\t} else if (subTreeState.type === 'entityList') {\n\t\t\t\t\t\tfor (const childState of subTreeState.children.values()) {\n\t\t\t\t\t\t\tif (childState.type === 'entityRealmStub') {\n\t\t\t\t\t\t\t\t// TODO there can be a forceCreate somewhere in there that we're hereby ignoring.\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbuilder = this.addSubMutation(\n\t\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\t\ttreeRootId,\n\t\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t\tmutationOperationSubTreeType.entityList,\n\t\t\t\t\t\t\t\tchildState.entity.id.value,\n\t\t\t\t\t\t\t\tchildState,\n\t\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (subTreeState.plannedRemovals) {\n\t\t\t\t\t\t\tfor (const [removedId, removalType] of subTreeState.plannedRemovals) {\n\t\t\t\t\t\t\t\tif (removalType === 'disconnect') {\n\t\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\t\t\t\t\tbuilder = this.addDeleteMutation(\n\t\t\t\t\t\t\t\t\t\tsubTreeState.entityName,\n\t\t\t\t\t\t\t\t\t\tremovedId,\n\t\t\t\t\t\t\t\t\t\tMutationAlias.encodeTopLevel({\n\t\t\t\t\t\t\t\t\t\t\ttreeRootId,\n\t\t\t\t\t\t\t\t\t\t\tsubTreePlaceholder: placeholderName,\n\t\t\t\t\t\t\t\t\t\t\ttype: mutationOperationType.delete,\n\t\t\t\t\t\t\t\t\t\t\tsubTreeType: mutationOperationSubTreeType.entityList,\n\t\t\t\t\t\t\t\t\t\t\tentityId: removedId,\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tassertNever(removalType)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tassertNever(subTreeState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn builder.inTransaction(undefined, { deferForeignKeyConstraints: true }).getGql()\n\t\t} catch (e) {\n\t\t\treturn undefined\n\t\t}\n\t}\n\n\tprivate addSubMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\ttreeRootId: TreeRootId | undefined,\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: typeof mutationOperationSubTreeType[keyof typeof mutationOperationSubTreeType],\n\t\tentityId: EntityId,\n\t\trealmState: EntityRealmState,\n\t\tqueryBuilder: QueryBuilder,\n\t): QueryBuilder {\n\t\tif (realmState.unpersistedChangesCount === 0) {\n\t\t\t// Bail out early\n\t\t\treturn queryBuilder\n\t\t}\n\t\tif (realmState.entity.isScheduledForDeletion) {\n\t\t\treturn this.addDeleteMutation(\n\t\t\t\trealmState.entity.entityName,\n\t\t\t\tentityId,\n\t\t\t\tMutationAlias.encodeTopLevel({\n\t\t\t\t\ttreeRootId,\n\t\t\t\t\tsubTreePlaceholder,\n\t\t\t\t\ttype: mutationOperationType.delete,\n\t\t\t\t\tsubTreeType,\n\t\t\t\t\tentityId,\n\t\t\t\t}),\n\t\t\t\tqueryBuilder,\n\t\t\t)\n\t\t} else if (!realmState.entity.id.existsOnServer) {\n\t\t\treturn this.addCreateMutation(\n\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\trealmState,\n\t\t\t\tMutationAlias.encodeTopLevel({\n\t\t\t\t\ttreeRootId,\n\t\t\t\t\tsubTreePlaceholder,\n\t\t\t\t\ttype: mutationOperationType.create,\n\t\t\t\t\tsubTreeType,\n\t\t\t\t\tentityId,\n\t\t\t\t}),\n\t\t\t\tthis.getNodeFragmentName(subTreePlaceholder, subTreeType, realmState),\n\t\t\t\tqueryBuilder,\n\t\t\t)\n\t\t}\n\t\treturn this.addUpdateMutation(\n\t\t\tprocessedPlaceholdersByEntity,\n\t\t\trealmState,\n\t\t\tMutationAlias.encodeTopLevel({\n\t\t\t\ttreeRootId,\n\t\t\t\tsubTreePlaceholder,\n\t\t\t\ttype: mutationOperationType.update,\n\t\t\t\tsubTreeType,\n\t\t\t\tentityId,\n\t\t\t}),\n\t\t\tthis.getNodeFragmentName(subTreePlaceholder, subTreeType, realmState),\n\t\t\tqueryBuilder,\n\t\t)\n\t}\n\n\tprivate getNodeFragmentName(\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: typeof mutationOperationSubTreeType[keyof typeof mutationOperationSubTreeType],\n\t\trealmState: EntityRealmState,\n\t): string | undefined {\n\t\tif (subTreeType !== mutationOperationSubTreeType.entityList) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn `${realmState.entity.entityName}_${subTreePlaceholder}`\n\t}\n\n\tprivate addDeleteMutation(\n\t\tentityName: EntityName,\n\t\tdeletedId: EntityId,\n\t\talias: string,\n\t\tqueryBuilder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder(),\n\t): QueryBuilder {\n\t\treturn queryBuilder.delete(\n\t\t\tentityName,\n\t\t\tbuilder =>\n\t\t\t\tbuilder\n\t\t\t\t\t.ok()\n\t\t\t\t\t.node(builder => builder.column(PRIMARY_KEY_NAME))\n\t\t\t\t\t.by({ [PRIMARY_KEY_NAME]: deletedId })\n\t\t\t\t\t.errors()\n\t\t\t\t\t.errorMessage(),\n\t\t\talias,\n\t\t)\n\t}\n\n\tprivate addUpdateMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tentityRealm: EntityRealmState,\n\t\talias: string,\n\t\tnodeFragmentName: string | undefined,\n\t\tqueryBuilder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder(),\n\t): QueryBuilder {\n\t\tconst updateBuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Update> =\n\t\t\tthis.registerUpdateMutationPart(\n\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\tentityRealm,\n\t\t\t\tnew CrudQueryBuilder.WriteDataBuilder(),\n\t\t\t)\n\t\tif (updateBuilder.data === undefined || isEmptyObject(updateBuilder.data)) {\n\t\t\treturn queryBuilder\n\t\t}\n\n\t\tconst runtimeId = entityRealm.entity.id\n\n\t\tif (!runtimeId.existsOnServer) {\n\t\t\treturn queryBuilder\n\t\t}\n\n\t\tconst readBuilder = QueryGenerator.registerQueryPart(\n\t\t\tgetEntityMarker(entityRealm).fields.markers,\n\t\t\tCrudQueryBuilder.ReadBuilder.instantiate(),\n\t\t)\n\n\t\tif (nodeFragmentName) {\n\t\t\tqueryBuilder = queryBuilder.fragment(nodeFragmentName, entityRealm.entity.entityName, readBuilder)\n\t\t}\n\n\t\treturn queryBuilder.update(\n\t\t\tentityRealm.entity.entityName,\n\t\t\tbuilder =>\n\t\t\t\tbuilder\n\t\t\t\t\t.node(nodeFragmentName ? builder => builder.applyFragment(nodeFragmentName) : readBuilder)\n\t\t\t\t\t.data(updateBuilder)\n\t\t\t\t\t.by({ [PRIMARY_KEY_NAME]: runtimeId.value })\n\t\t\t\t\t.ok()\n\t\t\t\t\t.validation()\n\t\t\t\t\t.errors()\n\t\t\t\t\t.errorMessage(),\n\t\t\talias,\n\t\t)\n\t}\n\n\tprivate addCreateMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tentityRealm: EntityRealmState,\n\t\talias: string,\n\t\tnodeFragmentName: string | undefined,\n\t\tqueryBuilder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder(),\n\t): QueryBuilder {\n\t\tconst createBuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create> =\n\t\t\tthis.registerCreateMutationPart(\n\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\tentityRealm,\n\t\t\t\tnew CrudQueryBuilder.WriteDataBuilder(),\n\t\t\t)\n\t\tif (createBuilder.data === undefined || isEmptyObject(createBuilder.data)) {\n\t\t\treturn queryBuilder\n\t\t}\n\t\tconst readBuilder = QueryGenerator.registerQueryPart(\n\t\t\tgetEntityMarker(entityRealm).fields.markers,\n\t\t\tCrudQueryBuilder.ReadBuilder.instantiate(),\n\t\t)\n\t\tif (nodeFragmentName) {\n\t\t\tqueryBuilder = queryBuilder.fragment(nodeFragmentName, entityRealm.entity.entityName, readBuilder)\n\t\t}\n\n\t\treturn queryBuilder.create(\n\t\t\tentityRealm.entity.entityName,\n\t\t\tbuilder => {\n\t\t\t\t// if (where && writeBuilder.data !== undefined && !isEmptyObject(writeBuilder.data)) {\n\t\t\t\t// \t// Shallow cloning the parameters like this IS too naïve but it will likely last surprisingly long before we\n\t\t\t\t// \t// run into issues.\n\t\t\t\t// \twriteBuilder = new CrudQueryBuilder.WriteDataBuilder({ ...writeBuilder.data, ...where })\n\t\t\t\t// }\n\t\t\t\treturn builder\n\t\t\t\t\t.node(nodeFragmentName ? builder => builder.applyFragment(nodeFragmentName) : readBuilder)\n\t\t\t\t\t.data(createBuilder)\n\t\t\t\t\t.ok()\n\t\t\t\t\t.validation()\n\t\t\t\t\t.errors()\n\t\t\t\t\t.errorMessage()\n\t\t\t},\n\t\t\talias,\n\t\t)\n\t}\n\n\tprivate registerCreateMutationPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tcurrentState: EntityRealmState | EntityRealmStateStub,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create> = new CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>(),\n\t): CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create> {\n\t\tlet processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tprocessedPlaceholdersByEntity.set(currentState.entity, (processedPlaceholders = new Set()))\n\t\t}\n\n\t\tif (currentState.type === 'entityRealmStub') {\n\t\t\t// TODO If there's a forceCreate, this is wrong.\n\t\t\treturn builder\n\t\t}\n\n\t\tconst pathBack = this.treeStore.getPathBackToParent(currentState)\n\n\t\tconst nonbearingFields: Array<\n\t\t\t| { type: 'field'; marker: FieldMarker; fieldState: FieldState }\n\t\t\t| { type: 'hasOne'; marker: HasOneRelationMarker; fieldState: EntityRealmState | EntityRealmStateStub }\n\t\t\t| { type: 'hasMany'; marker: HasManyRelationMarker; fieldState: EntityListState }\n\t\t> = []\n\n\t\tfor (const [placeholderName, fieldState] of currentState.children) {\n\t\t\tif (processedPlaceholders.has(placeholderName)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tprocessedPlaceholders.add(placeholderName)\n\n\t\t\tswitch (fieldState.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tconst marker = fieldState.fieldMarker\n\t\t\t\t\tconst placeholderName = marker.placeholderName\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tplaceholderName === TYPENAME_KEY_NAME ||\n\t\t\t\t\t\t(placeholderName === PRIMARY_KEY_NAME && !(currentState.entity.id instanceof ClientGeneratedUuid))\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif (marker.isNonbearing) {\n\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\ttype: 'field',\n\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tbuilder = this.registerCreateFieldPart(fieldState, marker, builder)\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealmStub':\n\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\tconst marker = getEntityMarker(fieldState)\n\t\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif (marker.parameters.isNonbearing) {\n\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\ttype: 'hasOne',\n\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tbuilder = this.registerCreateEntityPart(processedPlaceholdersByEntity, fieldState, marker, builder)\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tconst marker = fieldState.blueprint.marker\n\t\t\t\t\tif (!(marker instanceof HasManyRelationMarker)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif (marker.parameters.isNonbearing) {\n\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\ttype: 'hasMany',\n\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tbuilder = this.registerCreateEntityListPart(processedPlaceholdersByEntity, fieldState, marker, builder)\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// if (\n\t\t// \tcurrentState.blueprint.creationParameters.forceCreation &&\n\t\t// \t(builder.data === undefined || isEmptyObject(builder.data))\n\t\t// ) {\n\t\t// \tbuilder = builder.set('_dummy_field_', true)\n\t\t// }\n\n\t\tif (\n\t\t\t(builder.data !== undefined && !isEmptyObject(builder.data)) ||\n\t\t\t!getEntityMarker(currentState).fields.hasAtLeastOneBearingField\n\t\t) {\n\t\t\tfor (const field of nonbearingFields) {\n\t\t\t\tswitch (field.type) {\n\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\tbuilder = this.registerCreateFieldPart(field.fieldState, field.marker, builder)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'hasOne': {\n\t\t\t\t\t\tbuilder = this.registerCreateEntityPart(\n\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\tfield.fieldState,\n\t\t\t\t\t\t\tfield.marker,\n\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'hasMany': {\n\t\t\t\t\t\tbuilder = this.registerCreateEntityListPart(\n\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\tfield.fieldState,\n\t\t\t\t\t\t\tfield.marker,\n\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tassertNever(field)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst setOnCreate = getEntityMarker(currentState).parameters.setOnCreate\n\t\tif (setOnCreate && builder.data !== undefined && !isEmptyObject(builder.data)) {\n\t\t\tfor (const key in setOnCreate) {\n\t\t\t\tconst field = setOnCreate[key]\n\n\t\t\t\tif (\n\t\t\t\t\ttypeof field === 'string' ||\n\t\t\t\t\ttypeof field === 'number' ||\n\t\t\t\t\tfield === null ||\n\t\t\t\t\tfield instanceof GraphQlBuilder.GraphQlLiteral\n\t\t\t\t) {\n\t\t\t\t\tbuilder = builder.set(key, field)\n\t\t\t\t} else {\n\t\t\t\t\tbuilder = builder.one(key, builder => builder.connect(field))\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn builder\n\t}\n\n\tprivate registerCreateFieldPart(\n\t\tfieldState: FieldState,\n\t\tmarker: FieldMarker,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>,\n\t) {\n\t\tconst resolvedValue = fieldState.getAccessor().resolvedValue\n\n\t\tif (resolvedValue !== undefined && resolvedValue !== null) {\n\t\t\treturn builder.set(marker.fieldName, this.transformFieldValue(fieldState, resolvedValue))\n\t\t}\n\t\treturn builder\n\t}\n\n\tprivate registerCreateEntityPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tmarker: HasOneRelationMarker,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>,\n\t) {\n\t\tconst reducedBy = marker.parameters.reducedBy\n\t\tconst runtimeId = fieldState.entity.id\n\n\t\tif (reducedBy === undefined) {\n\t\t\treturn builder.one(marker.parameters.field, builder => {\n\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\treturn builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value })\n\t\t\t\t}\n\t\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState))\n\t\t\t})\n\t\t}\n\t\treturn builder.many(marker.parameters.field, builder => {\n\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t// TODO also potentially update\n\t\t\t\treturn builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t}\n\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState), alias)\n\t\t})\n\t}\n\n\tprivate registerCreateEntityListPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tfieldState: EntityListState,\n\t\tmarker: HasManyRelationMarker,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>,\n\t) {\n\t\treturn builder.many(marker.parameters.field, builder => {\n\t\t\tfor (const entityRealm of fieldState.children.values()) {\n\t\t\t\tconst alias = MutationAlias.encodeEntityId(entityRealm.entity.id)\n\t\t\t\tif (entityRealm.entity.id.existsOnServer) {\n\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\tbuilder = builder.connect({ [PRIMARY_KEY_NAME]: entityRealm.entity.id.value }, alias)\n\t\t\t\t} else {\n\t\t\t\t\tbuilder = builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, entityRealm), alias)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn builder\n\t\t})\n\t}\n\n\tprivate registerUpdateMutationPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tcurrentState: EntityRealmState,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Update>,\n\t): CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Update> {\n\t\tlet processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tprocessedPlaceholdersByEntity.set(currentState.entity, (processedPlaceholders = new Set()))\n\t\t}\n\n\t\tconst pathBack = this.treeStore.getPathBackToParent(currentState)\n\t\tconst entityData = this.treeStore.persistedEntityData.get(currentState.entity.id.value)\n\n\t\tfor (const [placeholderName, fieldState] of currentState.children) {\n\t\t\tif (placeholderName === PRIMARY_KEY_NAME || placeholderName === TYPENAME_KEY_NAME) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (processedPlaceholders.has(placeholderName)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tprocessedPlaceholders.add(placeholderName)\n\n\t\t\tswitch (fieldState.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (fieldState.persistedValue !== undefined) {\n\t\t\t\t\t\tconst resolvedValue = fieldState.getAccessor().resolvedValue\n\t\t\t\t\t\tif (fieldState.persistedValue !== resolvedValue) {\n\t\t\t\t\t\t\tbuilder = builder.set(placeholderName, this.transformFieldValue(fieldState, resolvedValue))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealmStub':\n\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\tconst marker = getEntityMarker(fieldState)\n\t\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst runtimeId = fieldState.entity.id\n\t\t\t\t\tconst reducedBy = marker.parameters.reducedBy\n\n\t\t\t\t\tif (reducedBy === undefined) {\n\t\t\t\t\t\tconst subBuilder = ((\n\t\t\t\t\t\t\tbuilder: CrudQueryBuilder.WriteOneRelationBuilder<CrudQueryBuilder.WriteOperation.Update>,\n\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\tconst persistedValue = entityData?.get?.(placeholderName)\n\n\t\t\t\t\t\t\tif (persistedValue instanceof ServerGeneratedUuid) {\n\t\t\t\t\t\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\t\t\t\t\t\t// The persisted and currently referenced ids match, and so this is an update.\n\t\t\t\t\t\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\t\t\t\t\t\treturn builder // …unless we're dealing with a stub. There cannot be any updates there.\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn builder.update(builder =>\n\t\t\t\t\t\t\t\t\t\tthis.registerUpdateMutationPart(processedPlaceholdersByEntity, fieldState, builder),\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// There was a referenced entity but currently, there is a different one. Let's investigate:\n\n\t\t\t\t\t\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\t\t\t\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\t\t\t\t\t\t// It's planned for deletion.\n\t\t\t\t\t\t\t\t\t// TODO also potentially do something about the current entity\n\t\t\t\t\t\t\t\t\treturn builder.delete()\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\t\t// This isn't the persisted entity but it does exist on the server. Thus this is a connect.\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\treturn builder.connect({\n\t\t\t\t\t\t\t\t\t\t[PRIMARY_KEY_NAME]: runtimeId.value,\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// The currently present entity doesn't exist on the server. Try if creating yields anything…\n\t\t\t\t\t\t\t\tconst subBuilder = builder.create(\n\t\t\t\t\t\t\t\t\tthis.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tif (isEmptyObject(subBuilder.data)) {\n\t\t\t\t\t\t\t\t\t// …and if it doesn't, we just disconnect.\n\t\t\t\t\t\t\t\t\treturn builder.disconnect()\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// …but if it does, we return the create, disconnecting implicitly.\n\t\t\t\t\t\t\t\treturn subBuilder\n\t\t\t\t\t\t\t} else if (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\t// There isn't a linked entity on the server but we're seeing one that exists there.\n\t\t\t\t\t\t\t\t// Thus this is a connect.\n\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\treturn builder.connect({\n\t\t\t\t\t\t\t\t\t[PRIMARY_KEY_NAME]: runtimeId.value,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})(CrudQueryBuilder.WriteOneRelationBuilder.instantiate<CrudQueryBuilder.WriteOperation.Update>())\n\n\t\t\t\t\t\tif (subBuilder.data) {\n\t\t\t\t\t\t\tbuilder = builder.one(marker.parameters.field, subBuilder.data)\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// This is a reduced has many relation.\n\t\t\t\t\t\tbuilder = builder.many(marker.parameters.field, builder => {\n\t\t\t\t\t\t\tconst persistedValue = entityData?.get?.(placeholderName)\n\t\t\t\t\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\t\t\t\t\t\tif (persistedValue instanceof ServerGeneratedUuid) {\n\t\t\t\t\t\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\t\t\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\t\t\t\t\t\treturn builder\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn builder.update(\n\t\t\t\t\t\t\t\t\t\treducedBy,\n\t\t\t\t\t\t\t\t\t\tbuilder => this.registerUpdateMutationPart(processedPlaceholdersByEntity, fieldState, builder),\n\t\t\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\t\t\t\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\t\t\t\t\t\t// TODO also potentially do something about the current entity\n\t\t\t\t\t\t\t\t\treturn builder.delete(reducedBy, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\t\t// TODO will re-using the alias like this work?\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\treturn builder.disconnect(reducedBy, alias).connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst subBuilder = builder.create(\n\t\t\t\t\t\t\t\t\tthis.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tif (isEmptyObject(subBuilder.data)) {\n\t\t\t\t\t\t\t\t\treturn builder.disconnect(reducedBy, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn subBuilder\n\t\t\t\t\t\t\t} else if (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\treturn builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tconst marker = fieldState.blueprint.marker\n\t\t\t\t\tif (!(marker instanceof HasManyRelationMarker)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst persistedEntityIds = entityData?.get?.(placeholderName) ?? new Set()\n\n\t\t\t\t\tif (!(persistedEntityIds instanceof Set)) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tbuilder = builder.many(marker.parameters.field, builder => {\n\t\t\t\t\t\tfor (const childState of fieldState.children.values()) {\n\t\t\t\t\t\t\tconst runtimeId = childState.entity.id\n\t\t\t\t\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\t\t\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\tif (persistedEntityIds.has(runtimeId.value)) {\n\t\t\t\t\t\t\t\t\tif (childState.type !== 'entityRealmStub') {\n\t\t\t\t\t\t\t\t\t\t// A stub cannot have any pending changes.\n\t\t\t\t\t\t\t\t\t\tbuilder = builder.update(\n\t\t\t\t\t\t\t\t\t\t\t{ [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t\t\t\t\t\t\tbuilder => this.registerUpdateMutationPart(processedPlaceholdersByEntity, childState, builder),\n\t\t\t\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\tbuilder = builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tbuilder = builder.create(\n\t\t\t\t\t\t\t\t\tthis.registerCreateMutationPart(processedPlaceholdersByEntity, childState),\n\t\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (fieldState.plannedRemovals) {\n\t\t\t\t\t\t\tfor (const [removedId, removalType] of fieldState.plannedRemovals) {\n\t\t\t\t\t\t\t\tconst alias = MutationAlias.encodeEntityId(new ServerGeneratedUuid(removedId))\n\t\t\t\t\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\t\t\t\t\tbuilder = builder.delete({ [PRIMARY_KEY_NAME]: removedId }, alias)\n\t\t\t\t\t\t\t\t} else if (removalType === 'disconnect') {\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\tbuilder = builder.disconnect({ [PRIMARY_KEY_NAME]: removedId }, alias)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tassertNever(removalType)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn builder\n\t\t\t\t\t})\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t}\n\t\t}\n\n\t\treturn builder\n\t}\n\n\tprivate transformFieldValue(fieldState: FieldState, value: FieldValue): FieldValue | GraphQlBuilder.GraphQlLiteral {\n\t\tif (typeof value !== 'string') {\n\t\t\treturn value\n\t\t}\n\t\tconst fieldSchema = this.treeStore.schema.getEntityField(\n\t\t\tfieldState.parent.entity.entityName,\n\t\t\tfieldState.fieldMarker.fieldName,\n\t\t)\n\t\tif (fieldSchema === undefined || fieldSchema.__typename !== '_Column') {\n\t\t\tthrow new BindingError()\n\t\t}\n\t\treturn fieldSchema.enumName === null ? value : new GraphQlBuilder.GraphQlLiteral(value)\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AA0BO,MAAM,kBAAkB;AAAA,EACvB,YAA6B,WAAsB;AAAtB,SAAA,YAAA;AAAA,EAAuB;AAAA,EAEpD,qBAAyC;AAC3C,QAAA;AACC,UAAA,UAAwB,IAAI,iBAAiB;AAC3C,YAAA,oDAAmE;AAEzE,iBAAW,CAAC,YAAY,eAAe,KAAK,UAAU,qBAAqB;AAC/D,mBAAA,CAAC,iBAAiB,iBAAiB,YAAY;AACrD,cAAA,aAAa,SAAS,eAAe;AACxC,sBAAU,KAAK,eACd,+BACA,YACA,iBACA,6BAA6B,cAC7B,aAAa,OAAO,GAAG,OACvB,cACA,OACD;AAAA,UAAA,WACU,aAAa,SAAS,cAAc;AAC9C,uBAAW,cAAc,aAAa,SAAS,OAAA,GAAU;AACpD,kBAAA,WAAW,SAAS,mBAAmB;AAE1C;AAAA,cACD;AACA,wBAAU,KAAK,eACd,+BACA,YACA,iBACA,6BAA6B,YAC7B,WAAW,OAAO,GAAG,OACrB,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,UAAA,GAAa,KAAK;AAAA,gBAAA,OAC/D;AACN,8BAAuB;AAAA,gBACxB;AAAA,cACD;AAAA,YACD;AACO,mBAAA;AAAA,UAAA,CACP;AACD;AAAA,QACD;AAAA;AAEC,iBAAO,YAAsB;AAAA;AAAA,IAEhC;AAEO,WAAA;AAAA,EACR;AAAA,EAEQ,oBAAoB,YAAwB,OAA+D;AAC9G,QAAA,OAAO,UAAU,UAAU;AACvB,aAAA;AAAA,IACR;AACM,UAAA,cAAc,KAAK,UAAU,OAAO,eACzC,WAAW,OAAO,OAAO,YACzB,WAAW,YAAY,SACxB;AACA,QAAI,gBAAgB,UAAa,YAAY,eAAe,WAAW;AACtE,YAAM,IAAI,aAAa;AAAA,IACxB;AACA,WAAO,YAAY,aAAa,OAAO,QAAQ,IAAI,eAAe,eAAe,KAAK;AAAA,EACvF;AACD;;"}
1
+ {"version":3,"file":"MutationGenerator.js","sources":["../../../src/core/MutationGenerator.ts"],"sourcesContent":["// noinspection JSVoidFunctionReturnValueUsed // IntelliJ seems to be super confused througouht this file.\n\nimport { CrudQueryBuilder, GraphQlBuilder } from '@contember/client'\nimport { ClientGeneratedUuid, ServerId } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '../bindingTypes'\nimport { EntityFieldMarkers, FieldMarker, HasManyRelationMarker, HasOneRelationMarker } from '../markers'\nimport type { EntityId, EntityName, FieldValue, PlaceholderName } from '../treeParameters'\nimport { assertNever, isEmptyObject } from '../utils'\nimport { QueryGenerator } from './QueryGenerator'\nimport { MutationAlias } from './requestAliases'\nimport {\n\tEntityListState,\n\tEntityRealmState,\n\tEntityRealmStateStub,\n\tEntityState,\n\tFieldState,\n\tgetEntityMarker,\n\tStateIterator,\n} from './state'\nimport type { TreeStore } from './TreeStore'\n\ntype QueryBuilder = Omit<CrudQueryBuilder.CrudQueryBuilder, CrudQueryBuilder.Queries>\n\ntype ProcessedPlaceholdersByEntity = Map<EntityState, Set<PlaceholderName>>\n\nexport type SubMutationOperation =\n\t& {\n\t\talias: string,\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: 'list' | 'single'\n\t}\n\t& (\n\t\t| { type: 'delete', id: EntityId }\n\t\t| { type: 'update', markers: EntityFieldMarkers, id: EntityId }\n\t\t| { type: 'create', markers: EntityFieldMarkers, id: EntityId }\n\t)\n\nexport type PersistMutationResult = {\n\tquery: string\n\toperations: SubMutationOperation[]\n}\n\n// TODO enforce correct expected mutations in dev mode.\nexport class MutationGenerator {\n\n\tprivate aliasCounter = 1\n\n\tpublic constructor(private readonly treeStore: TreeStore) {\n\t}\n\n\tpublic getPersistMutation(): PersistMutationResult | undefined {\n\t\ttry {\n\t\t\tlet builder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder()\n\t\t\tconst operations: SubMutationOperation[] = []\n\t\t\tconst processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity = new Map()\n\n\n\t\t\tfor (const [treeRootId, rootStates] of this.treeStore.subTreeStatesByRoot.entries()) {\n\t\t\t\tfor (const [placeholderName, subTreeState] of Array.from(rootStates.entries()).reverse()) {\n\t\t\t\t\tif (subTreeState.unpersistedChangesCount <= 0) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif (subTreeState.type === 'entityRealm') {\n\t\t\t\t\t\tconst subMutation = this.addSubMutation(\n\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t'single',\n\t\t\t\t\t\t\tsubTreeState.entity.id.value,\n\t\t\t\t\t\t\tsubTreeState,\n\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tif (subMutation) {\n\t\t\t\t\t\t\tbuilder = subMutation[0]\n\t\t\t\t\t\t\toperations.push(subMutation[1])\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (subTreeState.type === 'entityList') {\n\t\t\t\t\t\tfor (const childState of subTreeState.children.values()) {\n\t\t\t\t\t\t\tif (childState.type === 'entityRealmStub') {\n\t\t\t\t\t\t\t\t// TODO there can be a forceCreate somewhere in there that we're hereby ignoring.\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst subMutation = this.addSubMutation(\n\t\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t\t'list',\n\t\t\t\t\t\t\t\tchildState.entity.id.value,\n\t\t\t\t\t\t\t\tchildState,\n\t\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tif (subMutation) {\n\t\t\t\t\t\t\t\tbuilder = subMutation[0]\n\t\t\t\t\t\t\t\toperations.push(subMutation[1])\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (subTreeState.plannedRemovals) {\n\t\t\t\t\t\t\tfor (const [removedId, removalType] of subTreeState.plannedRemovals) {\n\t\t\t\t\t\t\t\tif (removalType === 'disconnect') {\n\t\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\t\t\t\t\tconst alias = this.createAlias()\n\t\t\t\t\t\t\t\t\tbuilder = this.addDeleteMutation(\n\t\t\t\t\t\t\t\t\t\tsubTreeState.entityName,\n\t\t\t\t\t\t\t\t\t\tremovedId,\n\t\t\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\toperations.push({ alias, subTreePlaceholder: placeholderName, subTreeType: 'list', type: 'delete', id: removedId })\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tassertNever(removalType)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tassertNever(subTreeState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst query = builder.inTransaction(undefined, { deferForeignKeyConstraints: true }).getGql()\n\t\t\treturn { query, operations }\n\t\t} catch (e) {\n\t\t\treturn undefined\n\t\t}\n\t}\n\n\tprivate addSubMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: 'list' | 'single',\n\t\tentityId: EntityId,\n\t\trealmState: EntityRealmState,\n\t\tqueryBuilder: QueryBuilder,\n\t): [QueryBuilder, SubMutationOperation] | undefined {\n\t\tif (realmState.unpersistedChangesCount === 0) {\n\t\t\t// Bail out early\n\t\t\treturn undefined\n\t\t}\n\t\tconst fieldMarkers = getEntityMarker(realmState).fields.markers\n\n\t\tconst alias = this.createAlias()\n\n\t\tif (realmState.entity.isScheduledForDeletion) {\n\t\t\tconst builder = this.addDeleteMutation(\n\t\t\t\trealmState.entity.entityName,\n\t\t\t\tentityId,\n\t\t\t\talias,\n\t\t\t\tqueryBuilder,\n\t\t\t)\n\t\t\treturn [\n\t\t\t\tbuilder,\n\t\t\t\t{\n\t\t\t\t\talias,\n\t\t\t\t\tsubTreePlaceholder,\n\t\t\t\t\tsubTreeType,\n\t\t\t\t\ttype: 'delete',\n\t\t\t\t\tid: entityId,\n\t\t\t\t},\n\t\t\t]\n\t\t} else if (!realmState.entity.id.existsOnServer) {\n\t\t\tconst builder = this.addCreateMutation(\n\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\trealmState,\n\t\t\t\talias,\n\t\t\t\tthis.getNodeFragmentName(subTreePlaceholder, subTreeType, realmState),\n\t\t\t\tqueryBuilder,\n\t\t\t\tfieldMarkers,\n\t\t\t)\n\t\t\tif (!builder) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn [\n\t\t\t\tbuilder,\n\t\t\t\t{\n\t\t\t\t\talias,\n\t\t\t\t\tsubTreePlaceholder,\n\t\t\t\t\tsubTreeType,\n\t\t\t\t\ttype: 'create',\n\t\t\t\t\tmarkers: fieldMarkers,\n\t\t\t\t\tid: entityId,\n\t\t\t\t},\n]\n\t\t}\n\t\tconst builder = this.addUpdateMutation(\n\t\t\tprocessedPlaceholdersByEntity,\n\t\t\trealmState,\n\t\t\talias,\n\t\t\tthis.getNodeFragmentName(subTreePlaceholder, subTreeType, realmState),\n\t\t\tqueryBuilder,\n\t\t\tfieldMarkers,\n\t\t)\n\t\tif (!builder) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn [\n\t\t\tbuilder,\n\t\t\t{\n\t\t\t\talias,\n\t\t\t\tsubTreePlaceholder,\n\t\t\t\tsubTreeType,\n\t\t\t\ttype: 'update',\n\t\t\t\tid: entityId,\n\t\t\t\tmarkers: fieldMarkers,\n\t\t\t},\n\t\t]\n\t}\n\n\tprivate getNodeFragmentName(\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: 'single' | 'list',\n\t\trealmState: EntityRealmState,\n\t): string | undefined {\n\t\tif (subTreeType !== 'list') {\n\t\t\treturn undefined\n\t\t}\n\t\treturn `${realmState.entity.entityName}_${subTreePlaceholder}`\n\t}\n\n\tprivate addDeleteMutation(\n\t\tentityName: EntityName,\n\t\tdeletedId: EntityId,\n\t\talias: string,\n\t\tqueryBuilder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder(),\n\t): QueryBuilder {\n\t\treturn queryBuilder.delete(\n\t\t\tentityName,\n\t\t\tbuilder =>\n\t\t\t\tbuilder\n\t\t\t\t\t.ok()\n\t\t\t\t\t.node(builder => builder.column(PRIMARY_KEY_NAME))\n\t\t\t\t\t.by({ [PRIMARY_KEY_NAME]: deletedId })\n\t\t\t\t\t.errors()\n\t\t\t\t\t.errorMessage(),\n\t\t\talias,\n\t\t)\n\t}\n\n\tprivate addUpdateMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tentityRealm: EntityRealmState,\n\t\talias: string,\n\t\tnodeFragmentName: string | undefined,\n\t\tqueryBuilder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder(),\n\t\tfieldMarkers: EntityFieldMarkers,\n\t): QueryBuilder | undefined {\n\t\tconst updateBuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Update> =\n\t\t\tthis.registerUpdateMutationPart(\n\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\tentityRealm,\n\t\t\t\tnew CrudQueryBuilder.WriteDataBuilder(),\n\t\t\t)\n\t\tif (updateBuilder.data === undefined || isEmptyObject(updateBuilder.data)) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst runtimeId = entityRealm.entity.id\n\n\t\tif (!runtimeId.existsOnServer) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst readBuilder = QueryGenerator.registerQueryPart(\n\t\t\tfieldMarkers,\n\t\t\tCrudQueryBuilder.ReadBuilder.instantiate(),\n\t\t)\n\n\t\tif (nodeFragmentName) {\n\t\t\tqueryBuilder = queryBuilder.fragment(nodeFragmentName, entityRealm.entity.entityName, readBuilder)\n\t\t}\n\n\t\treturn queryBuilder.update(\n\t\t\tentityRealm.entity.entityName,\n\t\t\tbuilder =>\n\t\t\t\tbuilder\n\t\t\t\t\t.node(nodeFragmentName ? builder => builder.applyFragment(nodeFragmentName) : readBuilder)\n\t\t\t\t\t.data(updateBuilder)\n\t\t\t\t\t.by({ [PRIMARY_KEY_NAME]: runtimeId.value })\n\t\t\t\t\t.ok()\n\t\t\t\t\t.validation()\n\t\t\t\t\t.errors()\n\t\t\t\t\t.errorMessage(),\n\t\t\talias,\n\t\t)\n\t}\n\n\tprivate addCreateMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tentityRealm: EntityRealmState,\n\t\talias: string,\n\t\tnodeFragmentName: string | undefined,\n\t\tqueryBuilder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder(),\n\t\tfieldMarkers: EntityFieldMarkers,\n\t): QueryBuilder | undefined {\n\t\tconst createBuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create> =\n\t\t\tthis.registerCreateMutationPart(\n\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\tentityRealm,\n\t\t\t\tnew CrudQueryBuilder.WriteDataBuilder(),\n\t\t\t)\n\t\tif (createBuilder.data === undefined || isEmptyObject(createBuilder.data)) {\n\t\t\treturn undefined\n\t\t}\n\t\tconst readBuilder = QueryGenerator.registerQueryPart(\n\t\t\tfieldMarkers,\n\t\t\tCrudQueryBuilder.ReadBuilder.instantiate(),\n\t\t)\n\t\tif (nodeFragmentName) {\n\t\t\tqueryBuilder = queryBuilder.fragment(nodeFragmentName, entityRealm.entity.entityName, readBuilder)\n\t\t}\n\n\t\treturn queryBuilder.create(\n\t\t\tentityRealm.entity.entityName,\n\t\t\tbuilder => {\n\t\t\t\t// if (where && writeBuilder.data !== undefined && !isEmptyObject(writeBuilder.data)) {\n\t\t\t\t// \t// Shallow cloning the parameters like this IS too naïve but it will likely last surprisingly long before we\n\t\t\t\t// \t// run into issues.\n\t\t\t\t// \twriteBuilder = new CrudQueryBuilder.WriteDataBuilder({ ...writeBuilder.data, ...where })\n\t\t\t\t// }\n\t\t\t\treturn builder\n\t\t\t\t\t.node(nodeFragmentName ? builder => builder.applyFragment(nodeFragmentName) : readBuilder)\n\t\t\t\t\t.data(createBuilder)\n\t\t\t\t\t.ok()\n\t\t\t\t\t.validation()\n\t\t\t\t\t.errors()\n\t\t\t\t\t.errorMessage()\n\t\t\t},\n\t\t\talias,\n\t\t)\n\t}\n\n\tprivate registerCreateMutationPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tcurrentState: EntityRealmState | EntityRealmStateStub,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create> = new CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>(),\n\t): CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create> {\n\t\tlet processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tprocessedPlaceholdersByEntity.set(currentState.entity, (processedPlaceholders = new Set()))\n\t\t}\n\n\t\tif (currentState.type === 'entityRealmStub') {\n\t\t\t// TODO If there's a forceCreate, this is wrong.\n\t\t\treturn builder\n\t\t}\n\n\t\tfor (const siblingState of StateIterator.eachSiblingRealm(currentState)) {\n\n\t\t\tconst pathBack = this.treeStore.getPathBackToParent(siblingState)\n\n\t\t\tconst nonbearingFields: Array<| { type: 'field'; marker: FieldMarker; fieldState: FieldState }\n\t\t\t\t| { type: 'hasOne'; marker: HasOneRelationMarker; fieldState: EntityRealmState | EntityRealmStateStub }\n\t\t\t\t| { type: 'hasMany'; marker: HasManyRelationMarker; fieldState: EntityListState }> = []\n\n\t\t\tfor (const [placeholderName, fieldState] of siblingState.children) {\n\t\t\t\tif (processedPlaceholders.has(placeholderName)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tprocessedPlaceholders.add(placeholderName)\n\n\t\t\t\tswitch (fieldState.type) {\n\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\tconst marker = fieldState.fieldMarker\n\t\t\t\t\t\tconst placeholderName = marker.placeholderName\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tplaceholderName === TYPENAME_KEY_NAME ||\n\t\t\t\t\t\t\t(placeholderName === PRIMARY_KEY_NAME && !(siblingState.entity.id instanceof ClientGeneratedUuid))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (marker.isNonbearing) {\n\t\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\t\ttype: 'field',\n\t\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbuilder = this.registerCreateFieldPart(fieldState, marker, builder)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'entityRealmStub':\n\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\tconst marker = getEntityMarker(fieldState)\n\t\t\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (marker.parameters.isNonbearing) {\n\t\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\t\ttype: 'hasOne',\n\t\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbuilder = this.registerCreateEntityPart(processedPlaceholdersByEntity, fieldState, marker, builder)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'entityList': {\n\t\t\t\t\t\tconst marker = fieldState.blueprint.marker\n\t\t\t\t\t\tif (!(marker instanceof HasManyRelationMarker)) {\n\t\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (marker.parameters.isNonbearing) {\n\t\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\t\ttype: 'hasMany',\n\t\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbuilder = this.registerCreateEntityListPart(processedPlaceholdersByEntity, fieldState, marker, builder)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// if (\n\t\t\t// \tcurrentState.blueprint.creationParameters.forceCreation &&\n\t\t\t// \t(builder.data === undefined || isEmptyObject(builder.data))\n\t\t\t// ) {\n\t\t\t// \tbuilder = builder.set('_dummy_field_', true)\n\t\t\t// }\n\n\t\t\tif (\n\t\t\t\t(builder.data !== undefined && !isEmptyObject(builder.data)) ||\n\t\t\t\t!getEntityMarker(siblingState).fields.hasAtLeastOneBearingField\n\t\t\t) {\n\t\t\t\tfor (const field of nonbearingFields) {\n\t\t\t\t\tswitch (field.type) {\n\t\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\t\tbuilder = this.registerCreateFieldPart(field.fieldState, field.marker, builder)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'hasOne': {\n\t\t\t\t\t\t\tbuilder = this.registerCreateEntityPart(\n\t\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\t\tfield.fieldState,\n\t\t\t\t\t\t\t\tfield.marker,\n\t\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'hasMany': {\n\t\t\t\t\t\t\tbuilder = this.registerCreateEntityListPart(\n\t\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\t\tfield.fieldState,\n\t\t\t\t\t\t\t\tfield.marker,\n\t\t\t\t\t\t\t\tbuilder,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tassertNever(field)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst setOnCreate = getEntityMarker(siblingState).parameters.setOnCreate\n\t\t\tif (setOnCreate && builder.data !== undefined && !isEmptyObject(builder.data)) {\n\t\t\t\tfor (const key in setOnCreate) {\n\t\t\t\t\tconst field = setOnCreate[key]\n\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof field === 'string' ||\n\t\t\t\t\t\ttypeof field === 'number' ||\n\t\t\t\t\t\tfield === null ||\n\t\t\t\t\t\tfield instanceof GraphQlBuilder.GraphQlLiteral\n\t\t\t\t\t) {\n\t\t\t\t\t\tbuilder = builder.set(key, field)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbuilder = builder.one(key, builder => builder.connect(field))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn builder\n\t}\n\n\tprivate registerCreateFieldPart(\n\t\tfieldState: FieldState,\n\t\tmarker: FieldMarker,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>,\n\t) {\n\t\tconst resolvedValue = fieldState.getAccessor().resolvedValue\n\n\t\tif (resolvedValue !== undefined && resolvedValue !== null) {\n\t\t\treturn builder.set(marker.fieldName, this.transformFieldValue(fieldState, resolvedValue))\n\t\t}\n\t\treturn builder\n\t}\n\n\tprivate registerCreateEntityPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tmarker: HasOneRelationMarker,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>,\n\t) {\n\t\tconst reducedBy = marker.parameters.reducedBy\n\t\tconst runtimeId = fieldState.entity.id\n\n\t\tif (reducedBy === undefined) {\n\t\t\treturn builder.one(marker.parameters.field, builder => {\n\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\treturn builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value })\n\t\t\t\t}\n\t\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState))\n\t\t\t})\n\t\t}\n\t\treturn builder.many(marker.parameters.field, builder => {\n\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t// TODO also potentially update\n\t\t\t\treturn builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t}\n\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState), alias)\n\t\t})\n\t}\n\n\tprivate registerCreateEntityListPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tfieldState: EntityListState,\n\t\tmarker: HasManyRelationMarker,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Create>,\n\t) {\n\t\treturn builder.many(marker.parameters.field, builder => {\n\t\t\tfor (const entityRealm of fieldState.children.values()) {\n\t\t\t\tconst alias = MutationAlias.encodeEntityId(entityRealm.entity.id)\n\t\t\t\tif (entityRealm.entity.id.existsOnServer) {\n\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\tbuilder = builder.connect({ [PRIMARY_KEY_NAME]: entityRealm.entity.id.value }, alias)\n\t\t\t\t} else {\n\t\t\t\t\tbuilder = builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, entityRealm), alias)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn builder\n\t\t})\n\t}\n\n\tprivate registerUpdateMutationPart(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tcurrentState: EntityRealmState,\n\t\tbuilder: CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Update>,\n\t): CrudQueryBuilder.WriteDataBuilder<CrudQueryBuilder.WriteOperation.Update> {\n\t\tlet processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tprocessedPlaceholdersByEntity.set(currentState.entity, (processedPlaceholders = new Set()))\n\t\t}\n\n\t\tconst pathBack = this.treeStore.getPathBackToParent(currentState)\n\t\tconst entityData = this.treeStore.persistedEntityData.get(currentState.entity.id.uniqueValue)\n\n\t\tfor (const [placeholderName, fieldState] of currentState.children) {\n\t\t\tif (placeholderName === PRIMARY_KEY_NAME || placeholderName === TYPENAME_KEY_NAME) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (processedPlaceholders.has(placeholderName)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tprocessedPlaceholders.add(placeholderName)\n\n\t\t\tswitch (fieldState.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (fieldState.persistedValue !== undefined) {\n\t\t\t\t\t\tconst resolvedValue = fieldState.getAccessor().resolvedValue\n\t\t\t\t\t\tif (fieldState.persistedValue !== resolvedValue) {\n\t\t\t\t\t\t\tbuilder = builder.set(placeholderName, this.transformFieldValue(fieldState, resolvedValue))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealmStub':\n\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\tconst marker = getEntityMarker(fieldState)\n\t\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst runtimeId = fieldState.entity.id\n\t\t\t\t\tconst reducedBy = marker.parameters.reducedBy\n\n\t\t\t\t\tif (reducedBy === undefined) {\n\t\t\t\t\t\tconst subBuilder = ((\n\t\t\t\t\t\t\tbuilder: CrudQueryBuilder.WriteOneRelationBuilder<CrudQueryBuilder.WriteOperation.Update>,\n\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\tconst persistedValue = entityData?.get?.(placeholderName)\n\n\t\t\t\t\t\t\tif (persistedValue instanceof ServerId) {\n\t\t\t\t\t\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\t\t\t\t\t\t// The persisted and currently referenced ids match, and so this is an update.\n\t\t\t\t\t\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\t\t\t\t\t\treturn builder // …unless we're dealing with a stub. There cannot be any updates there.\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn builder.update(builder =>\n\t\t\t\t\t\t\t\t\t\tthis.registerUpdateMutationPart(processedPlaceholdersByEntity, fieldState, builder),\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// There was a referenced entity but currently, there is a different one. Let's investigate:\n\n\t\t\t\t\t\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\t\t\t\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\t\t\t\t\t\t// It's planned for deletion.\n\t\t\t\t\t\t\t\t\t// TODO also potentially do something about the current entity\n\t\t\t\t\t\t\t\t\treturn builder.delete()\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\t\t// This isn't the persisted entity but it does exist on the server. Thus this is a connect.\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\treturn builder.connect({\n\t\t\t\t\t\t\t\t\t\t[PRIMARY_KEY_NAME]: runtimeId.value,\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// The currently present entity doesn't exist on the server. Try if creating yields anything…\n\t\t\t\t\t\t\t\tconst subBuilder = builder.create(\n\t\t\t\t\t\t\t\t\tthis.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tif (isEmptyObject(subBuilder.data)) {\n\t\t\t\t\t\t\t\t\t// …and if it doesn't, we just disconnect.\n\t\t\t\t\t\t\t\t\treturn builder.disconnect()\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// …but if it does, we return the create, disconnecting implicitly.\n\t\t\t\t\t\t\t\treturn subBuilder\n\t\t\t\t\t\t\t} else if (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\t// There isn't a linked entity on the server but we're seeing one that exists there.\n\t\t\t\t\t\t\t\t// Thus this is a connect.\n\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\treturn builder.connect({\n\t\t\t\t\t\t\t\t\t[PRIMARY_KEY_NAME]: runtimeId.value,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})(CrudQueryBuilder.WriteOneRelationBuilder.instantiate<CrudQueryBuilder.WriteOperation.Update>())\n\n\t\t\t\t\t\tif (subBuilder.data) {\n\t\t\t\t\t\t\tbuilder = builder.one(marker.parameters.field, subBuilder.data)\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// This is a reduced has many relation.\n\t\t\t\t\t\tbuilder = builder.many(marker.parameters.field, builder => {\n\t\t\t\t\t\t\tconst persistedValue = entityData?.get?.(placeholderName)\n\t\t\t\t\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\t\t\t\t\t\tif (persistedValue instanceof ServerId) {\n\t\t\t\t\t\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\t\t\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\t\t\t\t\t\treturn builder\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn builder.update(\n\t\t\t\t\t\t\t\t\t\treducedBy,\n\t\t\t\t\t\t\t\t\t\tbuilder => this.registerUpdateMutationPart(processedPlaceholdersByEntity, fieldState, builder),\n\t\t\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\t\t\t\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\t\t\t\t\t\t// TODO also potentially do something about the current entity\n\t\t\t\t\t\t\t\t\treturn builder.delete(reducedBy, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\t\t// TODO will re-using the alias like this work?\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\treturn builder.disconnect(reducedBy, alias).connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst subBuilder = builder.create(\n\t\t\t\t\t\t\t\t\tthis.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tif (isEmptyObject(subBuilder.data)) {\n\t\t\t\t\t\t\t\t\treturn builder.disconnect(reducedBy, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn subBuilder\n\t\t\t\t\t\t\t} else if (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\treturn builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\treturn builder.create(this.registerCreateMutationPart(processedPlaceholdersByEntity, fieldState))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tconst marker = fieldState.blueprint.marker\n\t\t\t\t\tif (!(marker instanceof HasManyRelationMarker)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst persistedEntityIds = entityData?.get?.(placeholderName) ?? new Set()\n\n\t\t\t\t\tif (!(persistedEntityIds instanceof Set)) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tbuilder = builder.many(marker.parameters.field, builder => {\n\t\t\t\t\t\tfor (const childState of fieldState.children.values()) {\n\t\t\t\t\t\t\tconst runtimeId = childState.entity.id\n\t\t\t\t\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\t\t\t\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t\t\t\t\tif (persistedEntityIds.has(runtimeId.value)) {\n\t\t\t\t\t\t\t\t\tif (childState.type !== 'entityRealmStub') {\n\t\t\t\t\t\t\t\t\t\t// A stub cannot have any pending changes.\n\t\t\t\t\t\t\t\t\t\tbuilder = builder.update(\n\t\t\t\t\t\t\t\t\t\t\t{ [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t\t\t\t\t\t\tbuilder => this.registerUpdateMutationPart(processedPlaceholdersByEntity, childState, builder),\n\t\t\t\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\tbuilder = builder.connect({ [PRIMARY_KEY_NAME]: runtimeId.value }, alias)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tbuilder = builder.create(\n\t\t\t\t\t\t\t\t\tthis.registerCreateMutationPart(processedPlaceholdersByEntity, childState),\n\t\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (fieldState.plannedRemovals) {\n\t\t\t\t\t\t\tfor (const [removedId, removalType] of fieldState.plannedRemovals) {\n\t\t\t\t\t\t\t\tconst alias = MutationAlias.encodeEntityId(new ServerId(removedId, fieldState.entityName))\n\t\t\t\t\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\t\t\t\t\tbuilder = builder.delete({ [PRIMARY_KEY_NAME]: removedId }, alias)\n\t\t\t\t\t\t\t\t} else if (removalType === 'disconnect') {\n\t\t\t\t\t\t\t\t\t// TODO also potentially update\n\t\t\t\t\t\t\t\t\tbuilder = builder.disconnect({ [PRIMARY_KEY_NAME]: removedId }, alias)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tassertNever(removalType)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn builder\n\t\t\t\t\t})\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t}\n\t\t}\n\n\t\treturn builder\n\t}\n\n\tprivate transformFieldValue(fieldState: FieldState, value: FieldValue): FieldValue | GraphQlBuilder.GraphQlLiteral {\n\t\tif (typeof value !== 'string') {\n\t\t\treturn value\n\t\t}\n\t\tconst fieldSchema = this.treeStore.schema.getEntityColumn(\n\t\t\tfieldState.parent.entity.entityName,\n\t\t\tfieldState.fieldMarker.fieldName,\n\t\t)\n\n\t\treturn fieldSchema.enumName === null ? value : new GraphQlBuilder.GraphQlLiteral(value)\n\t}\n\n\tprivate createAlias(): string {\n\t\treturn `op_${this.aliasCounter++}`\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AA4CO,MAAM,kBAAkB;AAAA,EAIvB,YAA6B,WAAsB;AAFlD,wCAAe;AAEa,SAAA,YAAA;AAAA,EACpC;AAAA,EAEO,qBAAwD;AAC1D,QAAA;AACC,UAAA,UAAwB,IAAI,iBAAiB;AACjD,YAAM,aAAqC,CAAA;AAC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oBAAoB,YAAwB,OAA+D;AAC9G,QAAA,OAAO,UAAU,UAAU;AACvB,aAAA;AAAA,IACR;AACM,UAAA,cAAc,KAAK,UAAU,OAAO,gBACzC,WAAW,OAAO,OAAO,YACzB,WAAW,YAAY,SACxB;AAEA,WAAO,YAAY,aAAa,OAAO,QAAQ,IAAI,eAAe,eAAe,KAAK;AAAA,EACvF;AAAA,EAEQ,cAAsB;AAC7B,WAAO,MAAM,KAAK;AAAA,EACnB;AACD;;"}
@@ -1,163 +1,122 @@
1
1
  import { BindingError } from "../BindingError.js";
2
2
  import { PRIMARY_KEY_NAME } from "../bindingTypes.js";
3
- import { MutationAlias } from "./requestAliases/MutationAlias.js";
3
+ import { EntitySubTreeMarker } from "../markers/EntitySubTreeMarker.js";
4
+ import { EntityListSubTreeMarker } from "../markers/EntityListSubTreeMarker.js";
4
5
  import { assertNever } from "../utils/assertNever.js";
5
- import { mutationOperationType } from "./requestAliases/mutationOperationType.js";
6
- import { mutationOperationSubTreeType } from "./requestAliases/mutationOperationSubTreeType.js";
7
- import { ServerGeneratedUuid } from "../accessorTree/RuntimeId.js";
6
+ import { FieldMarker } from "../markers/FieldMarker.js";
7
+ import { HasOneRelationMarker } from "../markers/HasOneRelationMarker.js";
8
+ import { HasManyRelationMarker } from "../markers/HasManyRelationMarker.js";
9
+ import { ServerId } from "../accessorTree/RuntimeId.js";
8
10
  class RequestResponseNormalizer {
9
- static mergeInQueryResponse(original, newPersistedData) {
11
+ static mergeInQueryResponse(original, newPersistedData, markerTree) {
10
12
  const { subTreeDataStore, persistedEntityDataStore } = original;
11
- const presentIds = /* @__PURE__ */ new Set();
12
- for (const placeholderName in newPersistedData) {
13
- const treeDatum = newPersistedData[placeholderName];
14
- const fieldData = this.createFieldData(persistedEntityDataStore, treeDatum);
15
- if (fieldData === null) {
16
- subTreeDataStore.delete(placeholderName);
17
- } else if (fieldData instanceof Set || typeof fieldData === "object") {
18
- subTreeDataStore.set(placeholderName, fieldData);
13
+ for (const [placeholder, marker] of markerTree.subTrees) {
14
+ const data = newPersistedData[placeholder] ?? null;
15
+ if (marker instanceof EntitySubTreeMarker) {
16
+ if (data === null) {
17
+ subTreeDataStore.delete(placeholder);
18
+ } else {
19
+ if (Array.isArray(data)) {
20
+ throw new BindingError();
21
+ }
22
+ const id = this.processEntityData(persistedEntityDataStore, data, marker.fields.markers);
23
+ subTreeDataStore.set(placeholder, id);
24
+ }
25
+ } else if (EntityListSubTreeMarker) {
26
+ const subTreeListIds = /* @__PURE__ */ new Set();
27
+ if (!Array.isArray(data)) {
28
+ throw new BindingError();
29
+ }
30
+ for (const row of data) {
31
+ const id = this.processEntityData(persistedEntityDataStore, row, marker.fields.markers);
32
+ subTreeListIds.add(id.value);
33
+ }
34
+ subTreeDataStore.set(placeholder, subTreeListIds);
19
35
  } else {
20
- this.rejectData();
36
+ throw new BindingError();
21
37
  }
22
38
  }
23
- return presentIds;
24
39
  }
25
- static mergeInMutationResponse(original, newPersistedData) {
40
+ static mergeInMutationResponse(original, newPersistedData, operations) {
26
41
  const { subTreeDataStore, persistedEntityDataStore } = original;
27
- const presentIds = /* @__PURE__ */ new Set();
28
- for (const operationAlias in newPersistedData) {
29
- const operation = MutationAlias.decodeTopLevel(operationAlias);
30
- if (operation === void 0) {
31
- return this.rejectData();
42
+ for (const operation of operations) {
43
+ const { subTreePlaceholder, subTreeType, alias } = operation;
44
+ const receivedData = newPersistedData[alias];
45
+ if (!receivedData || Array.isArray(receivedData)) {
46
+ throw new BindingError();
32
47
  }
33
- const { type, entityId, subTreeType, subTreePlaceholder } = operation;
34
- switch (type) {
35
- case mutationOperationType.update:
36
- case mutationOperationType.create: {
37
- const treeDatum = newPersistedData[operationAlias];
38
- const fieldData = this.createFieldData(persistedEntityDataStore, treeDatum);
39
- if (subTreeType === mutationOperationSubTreeType.singleEntity) {
40
- if (fieldData instanceof ServerGeneratedUuid) {
41
- subTreeDataStore.set(subTreePlaceholder, fieldData);
42
- } else {
43
- return this.rejectData();
44
- }
45
- } else if (subTreeType === mutationOperationSubTreeType.entityList) {
46
- if (fieldData instanceof ServerGeneratedUuid) {
47
- if (type === mutationOperationType.create) {
48
- const list = subTreeDataStore.get(subTreePlaceholder);
49
- if (list instanceof Set) {
50
- list.add(fieldData.value);
51
- } else if (list === void 0) {
52
- subTreeDataStore.set(subTreePlaceholder, /* @__PURE__ */ new Set([fieldData.value]));
53
- } else {
54
- return this.rejectData();
55
- }
56
- }
57
- } else {
58
- return this.rejectData();
59
- }
48
+ if (operation.type === "update" || operation.type === "create") {
49
+ const id = this.processEntityData(persistedEntityDataStore, receivedData, operation.markers);
50
+ if (subTreeType === "single") {
51
+ subTreeDataStore.set(subTreePlaceholder, id);
52
+ } else if (subTreeType === "list") {
53
+ const list = subTreeDataStore.get(subTreePlaceholder);
54
+ if (list instanceof Set) {
55
+ list.add(id.value);
56
+ } else if (list === void 0) {
57
+ subTreeDataStore.set(subTreePlaceholder, /* @__PURE__ */ new Set([id.value]));
60
58
  } else {
61
- return assertNever();
59
+ throw new BindingError();
62
60
  }
63
- break;
61
+ } else {
62
+ return assertNever();
64
63
  }
65
- case mutationOperationType.delete: {
66
- persistedEntityDataStore.delete(entityId);
67
- if (subTreeType === mutationOperationSubTreeType.singleEntity) {
68
- subTreeDataStore.delete(subTreePlaceholder);
69
- } else if (subTreeType === mutationOperationSubTreeType.entityList) {
70
- const list = subTreeDataStore.get(subTreePlaceholder);
71
- if (!(list instanceof Set)) {
72
- return this.rejectData();
73
- }
74
- list.delete(entityId);
75
- } else {
76
- return assertNever();
64
+ } else if (operation.type === "delete") {
65
+ const id = this.extractId(receivedData);
66
+ persistedEntityDataStore.delete(id.uniqueValue);
67
+ if (subTreeType === "single") {
68
+ subTreeDataStore.delete(subTreePlaceholder);
69
+ } else if (subTreeType === "list") {
70
+ const list = subTreeDataStore.get(subTreePlaceholder);
71
+ if (!(list instanceof Set)) {
72
+ throw new BindingError();
77
73
  }
78
- break;
79
- }
80
- default:
74
+ list.delete(id.value);
75
+ } else {
81
76
  return assertNever();
77
+ }
78
+ } else {
79
+ return assertNever();
82
80
  }
83
81
  }
84
- return presentIds;
85
- }
86
- static createFieldData(entityMap, fieldData) {
87
- if (Array.isArray(fieldData)) {
88
- const subTreeListIds = /* @__PURE__ */ new Set();
89
- for (const entityDatum of fieldData) {
90
- subTreeListIds.add(this.createEntityData(entityMap, entityDatum));
91
- }
92
- return subTreeListIds;
93
- } else if (fieldData !== null && typeof fieldData === "object") {
94
- return new ServerGeneratedUuid(this.createEntityData(entityMap, fieldData));
95
- } else {
96
- return fieldData;
97
- }
98
- }
99
- static createEntityData(entityMap, entityData) {
100
- const primaryKey = entityData[PRIMARY_KEY_NAME];
101
- if (primaryKey === void 0) {
102
- throw new BindingError(`The server has responded with an entity that lacks a primary key.`);
103
- }
104
- const presentEntityData = entityMap.get(primaryKey);
105
- if (presentEntityData === void 0) {
106
- const fieldsMap = /* @__PURE__ */ new Map();
107
- entityMap.set(primaryKey, fieldsMap);
108
- for (const field in entityData) {
109
- const fieldDatum = entityData[field];
110
- fieldsMap.set(field, this.createFieldData(entityMap, fieldDatum));
111
- }
112
- } else {
113
- this.mergeInEntityData(entityMap, presentEntityData, entityData);
114
- }
115
- return primaryKey;
116
82
  }
117
- static mergeInFieldData(entityMap, fromTarget, newDatum) {
118
- if (fromTarget === void 0) {
119
- return this.createFieldData(entityMap, newDatum);
120
- }
121
- if (fromTarget instanceof ServerGeneratedUuid || fromTarget === null && typeof newDatum === "object") {
122
- if (newDatum === null) {
123
- return null;
124
- } else if (typeof newDatum === "object" && !Array.isArray(newDatum)) {
125
- const newId = newDatum[PRIMARY_KEY_NAME];
126
- const target = entityMap.get(newId);
127
- if (target === void 0) {
128
- return new ServerGeneratedUuid(this.createEntityData(entityMap, newDatum));
129
- }
130
- if (fromTarget?.value === newId) {
131
- this.mergeInEntityData(entityMap, target, newDatum);
132
- return fromTarget;
83
+ static processEntityData(entityMap, entityData, fields) {
84
+ const id = this.extractId(entityData);
85
+ const presentEntityData = entityMap.get(id.uniqueValue) ?? /* @__PURE__ */ new Map();
86
+ entityMap.set(id.uniqueValue, presentEntityData);
87
+ for (const [placeholder, field] of fields) {
88
+ const value = entityData[placeholder];
89
+ if (field instanceof FieldMarker) {
90
+ presentEntityData.set(placeholder, value);
91
+ } else if (field instanceof HasOneRelationMarker) {
92
+ if (value === null) {
93
+ presentEntityData.set(placeholder, null);
133
94
  } else {
134
- return new ServerGeneratedUuid(this.createEntityData(entityMap, newDatum));
95
+ presentEntityData.set(placeholder, this.processEntityData(entityMap, value, field.fields.markers));
135
96
  }
136
- }
137
- } else if (fromTarget instanceof Set) {
138
- if (Array.isArray(newDatum)) {
139
- fromTarget.clear();
140
- for (const entityData of newDatum) {
141
- fromTarget.add(this.createEntityData(entityMap, entityData));
97
+ } else if (field instanceof HasManyRelationMarker) {
98
+ const ids = presentEntityData.get(placeholder) ?? /* @__PURE__ */ new Set();
99
+ presentEntityData.set(placeholder, ids);
100
+ if (!(ids instanceof Set)) {
101
+ throw new BindingError();
102
+ }
103
+ ids.clear();
104
+ for (const row of value) {
105
+ const id2 = this.processEntityData(entityMap, row, field.fields.markers);
106
+ ids.add(id2.value);
142
107
  }
143
- return fromTarget;
108
+ } else {
109
+ throw new Error();
144
110
  }
145
- } else if (!Array.isArray(newDatum) && (newDatum === null || typeof newDatum !== "object")) {
146
- return newDatum;
147
111
  }
148
- return this.rejectData();
112
+ return id;
149
113
  }
150
- static mergeInEntityData(entityMap, target, newData) {
151
- for (const field in newData) {
152
- const fromTarget = target.get(field);
153
- const newDatum = newData[field];
154
- target.set(field, this.mergeInFieldData(entityMap, fromTarget, newDatum));
114
+ static extractId(entityData) {
115
+ const primaryKey = entityData[PRIMARY_KEY_NAME];
116
+ if (primaryKey === void 0) {
117
+ throw new BindingError(`The server has responded with an entity that lacks a primary key.`);
155
118
  }
156
- return target;
157
- }
158
- static rejectData(extraMessage) {
159
- throw new BindingError(`Failed to process data received from the API.${extraMessage ? `
160
- ${extraMessage}` : ""}`);
119
+ return new ServerId(primaryKey, entityData.__typename);
161
120
  }
162
121
  }
163
122
  export { RequestResponseNormalizer };
@@ -1 +1 @@
1
- {"version":3,"file":"RequestResponseNormalizer.js","sources":["../../../src/core/RequestResponseNormalizer.ts"],"sourcesContent":["import {\n\tEntityFieldPersistedData,\n\tNormalizedPersistedData,\n\tPersistedEntityDataStore,\n\tReceivedDataTree,\n\tReceivedEntityData,\n\tReceivedFieldData,\n\tServerGeneratedUuid,\n\tSingleEntityPersistedData,\n} from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport { PRIMARY_KEY_NAME } from '../bindingTypes'\nimport { assertNever } from '../utils'\nimport { MutationAlias, mutationOperationSubTreeType, mutationOperationType } from './requestAliases'\n\nexport class RequestResponseNormalizer {\n\tpublic static mergeInQueryResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t): Set<string> {\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\t\tconst presentIds: Set<string> = new Set()\n\n\t\tfor (const placeholderName in newPersistedData) {\n\t\t\tconst treeDatum = newPersistedData[placeholderName]\n\n\t\t\tconst fieldData = this.createFieldData(persistedEntityDataStore, treeDatum)\n\n\t\t\tif (fieldData === null) {\n\t\t\t\tsubTreeDataStore.delete(placeholderName)\n\t\t\t} else if (fieldData instanceof Set || typeof fieldData === 'object') {\n\t\t\t\tsubTreeDataStore.set(placeholderName, fieldData)\n\t\t\t} else {\n\t\t\t\tthis.rejectData()\n\t\t\t}\n\t\t}\n\t\treturn presentIds\n\t}\n\n\tpublic static mergeInMutationResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t): Set<string> {\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\t\tconst presentIds: Set<string> = new Set()\n\n\t\tfor (const operationAlias in newPersistedData) {\n\t\t\tconst operation = MutationAlias.decodeTopLevel(operationAlias)\n\n\t\t\tif (operation === undefined) {\n\t\t\t\treturn this.rejectData()\n\t\t\t}\n\t\t\tconst { type, entityId, subTreeType, subTreePlaceholder } = operation\n\n\t\t\tswitch (type) {\n\t\t\t\tcase mutationOperationType.update:\n\t\t\t\tcase mutationOperationType.create: {\n\t\t\t\t\tconst treeDatum = newPersistedData[operationAlias]\n\t\t\t\t\tconst fieldData = this.createFieldData(persistedEntityDataStore, treeDatum)\n\n\t\t\t\t\tif (subTreeType === mutationOperationSubTreeType.singleEntity) {\n\t\t\t\t\t\tif (fieldData instanceof ServerGeneratedUuid) {\n\t\t\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, fieldData)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\treturn this.rejectData()\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (subTreeType === mutationOperationSubTreeType.entityList) {\n\t\t\t\t\t\tif (fieldData instanceof ServerGeneratedUuid) {\n\t\t\t\t\t\t\tif (type === mutationOperationType.create) {\n\t\t\t\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\t\t\t\tif (list instanceof Set) {\n\t\t\t\t\t\t\t\t\t// TODO this is somewhat dubious because we're essentially just guessing the order of the entities\n\t\t\t\t\t\t\t\t\t//\t\tand just carelessly put the new one at the end.\n\t\t\t\t\t\t\t\t\tlist.add(fieldData.value)\n\t\t\t\t\t\t\t\t} else if (list === undefined) {\n\t\t\t\t\t\t\t\t\t// That's fine. This is probably just an isCreating sub-tree.\n\t\t\t\t\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, new Set([fieldData.value]))\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\treturn this.rejectData()\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\treturn this.rejectData()\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase mutationOperationType.delete: {\n\t\t\t\t\t// TODO there are potentially some references to entityId that this whole process won't quite remove.\n\t\t\t\t\t//\t\tThat's a memory leak. Probably not particularly severe in most cases but still.\n\t\t\t\t\tpersistedEntityDataStore.delete(entityId)\n\t\t\t\t\tif (subTreeType === mutationOperationSubTreeType.singleEntity) {\n\t\t\t\t\t\tsubTreeDataStore.delete(subTreePlaceholder)\n\t\t\t\t\t} else if (subTreeType === mutationOperationSubTreeType.entityList) {\n\t\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\t\tif (!(list instanceof Set)) {\n\t\t\t\t\t\t\treturn this.rejectData()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlist.delete(entityId)\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn assertNever(type)\n\t\t\t}\n\t\t}\n\t\treturn presentIds\n\t}\n\n\tprivate static createFieldData(\n\t\tentityMap: PersistedEntityDataStore,\n\t\tfieldData: ReceivedFieldData,\n\t): EntityFieldPersistedData {\n\t\tif (Array.isArray(fieldData)) {\n\t\t\tconst subTreeListIds = new Set<string>()\n\t\t\tfor (const entityDatum of fieldData) {\n\t\t\t\tsubTreeListIds.add(this.createEntityData(entityMap, entityDatum))\n\t\t\t}\n\t\t\treturn subTreeListIds\n\t\t} else if (fieldData !== null && typeof fieldData === 'object') {\n\t\t\treturn new ServerGeneratedUuid(this.createEntityData(entityMap, fieldData))\n\t\t} else {\n\t\t\treturn fieldData\n\t\t}\n\t}\n\n\tprivate static createEntityData(entityMap: PersistedEntityDataStore, entityData: ReceivedEntityData): string {\n\t\tconst primaryKey: string | undefined = entityData[PRIMARY_KEY_NAME]\n\n\t\tif (primaryKey === undefined) {\n\t\t\tthrow new BindingError(`The server has responded with an entity that lacks a primary key.`)\n\t\t}\n\n\t\tconst presentEntityData = entityMap.get(primaryKey)\n\n\t\tif (presentEntityData === undefined) {\n\t\t\tconst fieldsMap: SingleEntityPersistedData = new Map()\n\t\t\tentityMap.set(primaryKey, fieldsMap)\n\t\t\tfor (const field in entityData) {\n\t\t\t\tconst fieldDatum = entityData[field]\n\n\t\t\t\tfieldsMap.set(field, this.createFieldData(entityMap, fieldDatum))\n\t\t\t}\n\t\t} else {\n\t\t\tthis.mergeInEntityData(entityMap, presentEntityData, entityData)\n\t\t}\n\t\treturn primaryKey\n\t}\n\n\tprivate static mergeInFieldData(\n\t\tentityMap: PersistedEntityDataStore,\n\t\tfromTarget: EntityFieldPersistedData | undefined,\n\t\tnewDatum: ReceivedFieldData,\n\t): EntityFieldPersistedData {\n\t\tif (fromTarget === undefined) {\n\t\t\treturn this.createFieldData(entityMap, newDatum)\n\t\t}\n\t\tif (fromTarget instanceof ServerGeneratedUuid || (fromTarget === null && typeof newDatum === 'object')) {\n\t\t\tif (newDatum === null) {\n\t\t\t\treturn null\n\t\t\t} else if (typeof newDatum === 'object' && !Array.isArray(newDatum)) {\n\t\t\t\tconst newId = newDatum[PRIMARY_KEY_NAME]\n\t\t\t\tconst target = entityMap.get(newId)\n\t\t\t\tif (target === undefined) {\n\t\t\t\t\treturn new ServerGeneratedUuid(this.createEntityData(entityMap, newDatum))\n\t\t\t\t}\n\n\t\t\t\tif (fromTarget?.value === newId) {\n\t\t\t\t\tthis.mergeInEntityData(entityMap, target, newDatum)\n\t\t\t\t\treturn fromTarget\n\t\t\t\t} else {\n\t\t\t\t\treturn new ServerGeneratedUuid(this.createEntityData(entityMap, newDatum))\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (fromTarget instanceof Set) {\n\t\t\tif (Array.isArray(newDatum)) {\n\t\t\t\tfromTarget.clear()\n\t\t\t\tfor (const entityData of newDatum) {\n\t\t\t\t\tfromTarget.add(this.createEntityData(entityMap, entityData))\n\t\t\t\t}\n\t\t\t\treturn fromTarget\n\t\t\t}\n\t\t} else if (!Array.isArray(newDatum) && (newDatum === null || typeof newDatum !== 'object')) {\n\t\t\treturn newDatum\n\t\t}\n\t\treturn this.rejectData()\n\t}\n\n\tprivate static mergeInEntityData(\n\t\tentityMap: PersistedEntityDataStore,\n\t\ttarget: SingleEntityPersistedData,\n\t\tnewData: ReceivedEntityData,\n\t): SingleEntityPersistedData {\n\t\tfor (const field in newData) {\n\t\t\tconst fromTarget = target.get(field)\n\t\t\tconst newDatum = newData[field]\n\n\t\t\ttarget.set(field, this.mergeInFieldData(entityMap, fromTarget, newDatum))\n\t\t}\n\t\treturn target\n\t}\n\n\tprivate static rejectData(extraMessage?: string): never {\n\t\tthrow new BindingError(`Failed to process data received from the API.${extraMessage ? `\\n${extraMessage}` : ''}`)\n\t}\n}\n"],"names":[],"mappings":";;;;;;;AAeO,MAAM,0BAA0B;AAAA,SACxB,qBACb,UACA,kBACc;AACR,UAAA,EAAE,kBAAkB,6BAA6B;AACjD,UAAA,iCAA8B;AAEpC,eAAW,mBAAmB,kBAAkB;AAC/C,YAAM,YAAY,iBAAiB;AAEnC,YAAM,YAAY,KAAK,gBAAgB,0BAA0B,SAAS;AAE1E,UAAI,cAAc,MAAM;AACvB,yBAAiB,OAAO,eAAe;AAAA,MAC7B,WAAA,qBAAqB,OAAO,OAAO,cAAc,UAAU;AACpD,yBAAA,IAAI,iBAAiB,SAAS;AAAA,MAAA,OACzC;AACN,aAAK,WAAW;AAAA,MACjB;AAAA,IACD;AACO,WAAA;AAAA,EACR;AAAA,SAEc,wBACb,UACA,kBACc;AACR,UAAA,EAAE,kBAAkB,6BAA6B;AACjD,UAAA,iCAA8B;AAEpC,eAAW,kBAAkB,kBAAkB;AACxC,YAAA,YAAY,cAAc,eAAe,cAAc;AAE7D,UAAI,cAAc,QAAW;AAC5B,eAAO,KAAK;MACb;AACA,YAAM,EAAE,MAAM,UAAU,aAAa,uBAAuB;AAEpD,cAAA;AAAA,aACF,sBAAsB;AAAA,aACtB,sBAAsB,QAAQ;AAClC,gBAAM,YAAY,iBAA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AiB,WAAW,QAAQ,CAAC;AAAA,QAC1E;AAAA,MACD;AAAA,IAAA,WACU,sBAAsB,KAAK;AACjC,UAAA,MAAM,QAAQ,QAAQ,GAAG;AAC5B,mBAAW,MAAM;AACjB,mBAAW,cAAc,UAAU;AAClC,qBAAW,IAAI,KAAK,iBAAiB,WAAW,UAAU,CAAC;AAAA,QAC5D;AACO,eAAA;AAAA,MACR;AAAA,IAAA,WACU,CAAC,MAAM,QAAQ,QAAQ,KAAmB,cAAA,QAAQ,OAAO,aAAa,WAAW;AACpF,aAAA;AAAA,IACR;AACA,WAAO,KAAK;EACb;AAAA,SAEe,kBACd,WACA,QACA,SAC4B;AAC5B,eAAW,SAAS,SAAS;AACtB,YAAA,aAAa,OAAO,IAAI,KAAK;AACnC,YAAM,WAAW,QAAQ;AAEzB,aAAO,IAAI,OAAO,KAAK,iBAAiB,WAAW,YAAY,QAAQ,CAAC;AAAA,IACzE;AACO,WAAA;AAAA,EACR;AAAA,SAEe,WAAW,cAA8B;AACjD,UAAA,IAAI,aAAa,gDAAgD,eAAe;AAAA,EAAK,iBAAiB,IAAI;AAAA,EACjH;AACD;;"}
1
+ {"version":3,"file":"RequestResponseNormalizer.js","sources":["../../../src/core/RequestResponseNormalizer.ts"],"sourcesContent":["import {\n\tNormalizedPersistedData,\n\tPersistedEntityDataStore,\n\tReceivedDataTree,\n\tReceivedEntityData,\n\tServerId,\n} from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport { PRIMARY_KEY_NAME } from '../bindingTypes'\nimport { EntityId } from '../treeParameters'\nimport {\n\tEntityFieldMarkers,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n} from '../markers'\nimport { SubMutationOperation } from './MutationGenerator'\nimport { assertNever } from '../utils'\n\nexport class RequestResponseNormalizer {\n\tpublic static mergeInQueryResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t\tmarkerTree: MarkerTreeRoot,\n\t): void {\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\n\t\tfor (const [placeholder, marker] of markerTree.subTrees) {\n\t\t\tconst data = newPersistedData[placeholder] ?? null\n\t\t\tif (marker instanceof EntitySubTreeMarker) {\n\t\t\t\tif (data === null) {\n\t\t\t\t\tsubTreeDataStore.delete(placeholder)\n\t\t\t\t} else {\n\t\t\t\t\tif (Array.isArray(data)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, data, marker.fields.markers)\n\t\t\t\t\tsubTreeDataStore.set(placeholder, id)\n\t\t\t\t}\n\t\t\t} else if (EntityListSubTreeMarker) {\n\t\t\t\tconst subTreeListIds = new Set<EntityId>()\n\t\t\t\tif (!Array.isArray(data)) {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tfor (const row of data) {\n\t\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, row, marker.fields.markers)\n\t\t\t\t\tsubTreeListIds.add(id.value)\n\t\t\t\t}\n\t\t\t\tsubTreeDataStore.set(placeholder, subTreeListIds)\n\t\t\t} else {\n\t\t\t\tthrow new BindingError()\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static mergeInMutationResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t\toperations: SubMutationOperation[],\n\t): void {\n\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\n\t\tfor (const operation of operations) {\n\t\t\tconst { subTreePlaceholder, subTreeType, alias } = operation\n\n\t\t\tconst receivedData = newPersistedData[alias]\n\t\t\tif (!receivedData || Array.isArray(receivedData)) {\n\t\t\t\tthrow new BindingError()\n\t\t\t}\n\n\t\t\tif (operation.type === 'update' || operation.type === 'create') {\n\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, receivedData, operation.markers)\n\t\t\t\tif (subTreeType === 'single') {\n\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, id)\n\t\t\t\t} else if (subTreeType === 'list') {\n\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\tif (list instanceof Set) {\n\t\t\t\t\t\t// TODO this is somewhat dubious because we're essentially just guessing the order of the entities\n\t\t\t\t\t\t//\t\tand just carelessly put the new one at the end.\n\t\t\t\t\t\tlist.add(id.value)\n\t\t\t\t\t} else if (list === undefined) {\n\t\t\t\t\t\t// That's fine. This is probably just an isCreating sub-tree.\n\t\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, new Set([id.value]))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t}\n\t\t\t} else if (operation.type === 'delete') {\n\t\t\t\tconst id = this.extractId(receivedData)\n\t\t\t\t// TODO there are potentially some references to entityId that this whole process won't quite remove.\n\t\t\t\t//\t\tThat's a memory leak. Probably not particularly severe in most cases but still.\n\t\t\t\tpersistedEntityDataStore.delete(id.uniqueValue)\n\t\t\t\tif (subTreeType === 'single') {\n\t\t\t\t\tsubTreeDataStore.delete(subTreePlaceholder)\n\t\t\t\t} else if (subTreeType === 'list') {\n\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\tif (!(list instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tlist.delete(id.value)\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t\treturn assertNever(operation)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static processEntityData(entityMap: PersistedEntityDataStore, entityData: ReceivedEntityData, fields: EntityFieldMarkers): ServerId {\n\t\tconst id = this.extractId(entityData)\n\t\tconst presentEntityData = entityMap.get(id.uniqueValue) ?? new Map()\n\t\tentityMap.set(id.uniqueValue, presentEntityData)\n\n\t\tfor (const [placeholder, field] of fields) {\n\t\t\tconst value = entityData[placeholder]\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tpresentEntityData.set(placeholder, value)\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tif (value === null) {\n\t\t\t\t\tpresentEntityData.set(placeholder, null)\n\t\t\t\t} else {\n\t\t\t\t\tpresentEntityData.set(placeholder, this.processEntityData(entityMap, value as ReceivedEntityData, field.fields.markers))\n\t\t\t\t}\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\tconst ids = presentEntityData.get(placeholder) ?? new Set()\n\t\t\t\tpresentEntityData.set(placeholder, ids)\n\t\t\t\tif (!(ids instanceof Set)) {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tids.clear()\n\t\t\t\tfor (const row of value as ReceivedEntityData[]) {\n\t\t\t\t\tconst id = this.processEntityData(entityMap, row, field.fields.markers)\n\t\t\t\t\tids.add(id.value)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthrow new Error()\n\t\t\t}\n\t\t}\n\n\t\treturn id\n\t}\n\n\tprivate static extractId(entityData: ReceivedEntityData): ServerId {\n\t\tconst primaryKey: EntityId | undefined = entityData[PRIMARY_KEY_NAME]\n\n\t\tif (primaryKey === undefined) {\n\t\t\tthrow new BindingError(`The server has responded with an entity that lacks a primary key.`)\n\t\t}\n\n\t\treturn new ServerId(primaryKey, entityData.__typename)\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;AAsBO,MAAM,0BAA0B;AAAA,SACxB,qBACb,UACA,kBACA,YACO;AACD,UAAA,EAAE,kBAAkB,6BAA6B;AAEvD,eAAW,CAAC,aAAa,WAAW,WAAW,UAAU;AAClD,YAAA,OAAO,iBAAiB,gBAAgB;AAC9C,UAAI,kBAAkB,qBAAqB;AAC1C,YAAI,SAAS,MAAM;AAClB,2BAAiB,OAAO,W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