@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,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,iBAAiB;AACnC,gBAAM,YAAY,KAAK,gBAAgB,0BAA0B,SAAS;AAEtE,cAAA,gBAAgB,6BAA6B,cAAc;AAC9D,gBAAI,qBAAqB,qBAAqB;AAC5B,+BAAA,IAAI,oBAAoB,SAAS;AAAA,YAAA,OAC5C;AACN,qBAAO,KAAK;YACb;AAAA,UAAA,WACU,gBAAgB,6BAA6B,YAAY;AACnE,gBAAI,qBAAqB,qBAAqB;AACzC,kBAAA,SAAS,sBAAsB,QAAQ;AACpC,sBAAA,OAAO,iBAAiB,IAAI,kBAAkB;AAEpD,oBAAI,gBAAgB,KAAK;AA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b;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,WAAW;AAAA,QAAA,OAC7B;AACF,cAAA,MAAM,QAAQ,IAAI,GAAG;AACxB,kBAAM,IAAI,aAAa;AAAA,UACxB;AACA,gBAAM,KAAK,KAAK,kBAAkB,0BAA0B,MAAM,OAAO,OAAO,OAAO;AACtE,2BAAA,IAAI,aAAa,EAAE;AAAA,QACrC;AAAA,iBACU,yBAAyB;AAC7B,cAAA,qCAAqB;AAC3B,YAAI,CAAC,MAAM,QAAQ,IAAI,GAAG;AACzB,gBAAM,IAAI,aAAa;AAAA,QACxB;AACA,mBAAW,OAAO,MAAM;AACvB,gBAAM,KAAK,K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;AAAA,EACtD;AACD;;"}
@@ -14,7 +14,7 @@ import { EntityAccessor } from "../accessors/EntityAccessor.js";
14
14
  import { BijectiveIndexedMap } from "../structures/BijectiveIndexedMap.js";
15
15
  import { EntityListAccessor } from "../accessors/EntityListAccessor.js";
16
16
  import { EntityListSubTreeMarker } from "../markers/EntityListSubTreeMarker.js";
17
- import { ServerGeneratedUuid, UnpersistedEntityDummyId } from "../accessorTree/RuntimeId.js";
17
+ import { ServerId, UnpersistedEntityDummyId } from "../accessorTree/RuntimeId.js";
18
18
  import { getEntityMarker } from "./state/getEntityMarker.js";
19
19
  import { FieldMarker } from "../markers/FieldMarker.js";
20
20
  import { HasManyRelationMarker } from "../markers/HasManyRelationMarker.js";
@@ -23,18 +23,15 @@ import { assertNever } from "../utils/assertNever.js";
23
23
  import { FieldAccessor } from "../accessors/FieldAccessor.js";
24
24
  import { EventListenersStore } from "../treeParameters/EventListenersStore.js";
25
25
  class StateInitializer {
26
- constructor(accessorErrorManager, batchUpdatesOptions, config, eventManager, treeStore) {
26
+ constructor(accessorErrorManager, batchUpdatesOptions, eventManager, treeStore) {
27
27
  __publicField(this, "fieldOperations");
28
28
  __publicField(this, "entityOperations");
29
29
  __publicField(this, "listOperations");
30
- this.accessorErrorManager = accessorErrorManager;
31
- this.batchUpdatesOptions = batchUpdatesOptions;
32
- this.config = config;
33
30
  this.eventManager = eventManager;
34
31
  this.treeStore = treeStore;
35
- this.fieldOperations = new FieldOperations(this.accessorErrorManager, this.eventManager, this, this.treeStore);
36
- this.entityOperations = new EntityOperations(this.accessorErrorManager, this.batchUpdatesOptions, this.eventManager, this, this.treeStore);
37
- this.listOperations = new ListOperations(this.accessorErrorManager, this.batchUpdatesOptions, this.eventManager, this, this.treeStore);
32
+ this.fieldOperations = new FieldOperations(accessorErrorManager, this.eventManager, this, this.treeStore);
33
+ this.entityOperations = new EntityOperations(accessorErrorManager, batchUpdatesOptions, this.eventManager, this, this.treeStore);
34
+ this.listOperations = new ListOperations(accessorErrorManager, batchUpdatesOptions, this.eventManager, this, this.treeStore);
38
35
  }
39
36
  initializeSubTree(tree) {
40
37
  let subTreeState;
@@ -43,7 +40,7 @@ class StateInitializer {
43
40
  const persistedEntityIds = persistedRootData instanceof Set ? persistedRootData : /* @__PURE__ */ new Set();
44
41
  subTreeState = this.initializeEntityListState({ marker: tree, parent: void 0 }, tree.entityName, persistedEntityIds);
45
42
  } else {
46
- subTreeState = this.materializeEntityRealm(this.initializeEntityRealm(persistedRootData instanceof ServerGeneratedUuid ? persistedRootData : new UnpersistedEntityDummyId(), tree.entityName, {
43
+ subTreeState = this.materializeEntityRealm(this.initializeEntityRealm(persistedRootData instanceof ServerId ? persistedRootData : new UnpersistedEntityDummyId(), tree.entityName, {
47
44
  type: "subTree",
48
45
  marker: tree,
49
46
  parent: void 0
@@ -69,7 +66,7 @@ class StateInitializer {
69
66
  this.registerEntityRealm(stub);
70
67
  return stub;
71
68
  }
72
- const realm = this.createEntityRealm(blueprint, realmKey, entity);
69
+ const realm = this.createEntityRealm(blueprint, realmKey, entity, copyFrom);
73
70
  this.registerEntityRealm(realm);
74
71
  const marker = getEntityMarker(realm);
75
72
  const pathBack = this.treeStore.getPathBackToParent(realm);
@@ -79,9 +76,13 @@ class StateInitializer {
79
76
  if (!value || value.type !== "field") {
80
77
  throw new BindingError();
81
78
  }
82
- this.initializeFromFieldMarker(realm, field, value.value);
79
+ this.initializeFromFieldMarker(realm, field, void 0, value);
83
80
  } else if (field instanceof HasManyRelationMarker) {
84
- this.initializeFromHasManyRelationMarker(realm, field, /* @__PURE__ */ new Set());
81
+ const value = copyFrom.children.get(placeholderName);
82
+ if (!value || value.type !== "entityList") {
83
+ throw new BindingError();
84
+ }
85
+ this.initializeFromHasManyRelationMarker(realm, field, new Set(value.children.keys()));
85
86
  } else if (field instanceof HasOneRelationMarker) {
86
87
  let runtimeId;
87
88
  let subCopyFrom = void 0;
@@ -105,7 +106,7 @@ class StateInitializer {
105
106
  this.eventManager.registerNewlyInitialized(realm);
106
107
  return realm;
107
108
  }
108
- createEntityRealm(blueprint, realmKey, entity) {
109
+ createEntityRealm(blueprint, realmKey, entity, copyFrom) {
109
110
  const entityRealm = {
110
111
  type: "entityRealm",
111
112
  blueprint,
@@ -118,11 +119,11 @@ class StateInitializer {
118
119
  eventListeners: this.initializeEntityEventListenerStore(blueprint),
119
120
  fieldsWithPendingConnectionUpdates: void 0,
120
121
  plannedHasOneDeletions: void 0,
121
- unpersistedChangesCount: 0,
122
+ unpersistedChangesCount: copyFrom?.unpersistedChangesCount ?? 0,
122
123
  getAccessor: () => {
123
124
  if (entityRealm.accessor === void 0) {
124
125
  const entity2 = entityRealm.entity;
125
- entityRealm.accessor = new EntityAccessor(entityRealm, this.entityOperations, entity2.id, entityRealm.realmKey, entity2.entityName, entityRealm.children, this.treeStore.persistedEntityData.get(entity2.id.value), entityRealm.unpersistedChangesCount !== 0, entityRealm.errors, getEntityMarker(entityRealm).environment, entityRealm.getAccessor);
126
+ entityRealm.accessor = new EntityAccessor(entityRealm, this.entityOperations, entity2.id, entityRealm.realmKey, entity2.entityName, entityRealm.children, this.treeStore.persistedEntityData.get(entity2.id.uniqueValue), entityRealm.unpersistedChangesCount !== 0, entityRealm.errors, getEntityMarker(entityRealm).environment, entityRealm.getAccessor);
126
127
  }
127
128
  return entityRealm.accessor;
128
129
  }
@@ -140,7 +141,7 @@ class StateInitializer {
140
141
  }
141
142
  const entityRealm = this.createEntityRealm(blueprint, realmKey, entity);
142
143
  this.registerEntityRealm(entityRealm);
143
- const persistedData = this.treeStore.persistedEntityData.get(entity.id.value);
144
+ const persistedData = this.treeStore.persistedEntityData.get(entity.id.uniqueValue);
144
145
  const marker = getEntityMarker(state);
145
146
  const pathBack = this.treeStore.getPathBackToParent(entityRealm);
146
147
  for (const [placeholderName, field] of marker.fields.markers) {
@@ -154,7 +155,7 @@ class StateInitializer {
154
155
  if (pathBack?.fieldBackToParent === field.parameters.field) {
155
156
  runtimeId = pathBack.parent.entity.id;
156
157
  } else {
157
- runtimeId = fieldDatum instanceof ServerGeneratedUuid ? fieldDatum : new UnpersistedEntityDummyId();
158
+ runtimeId = fieldDatum instanceof ServerId ? fieldDatum : new UnpersistedEntityDummyId();
158
159
  }
159
160
  this.initializeFromHasOneRelationMarker(entityRealm, field, runtimeId);
160
161
  } else {
@@ -175,14 +176,14 @@ class StateInitializer {
175
176
  entity.realms.set(realmKey, entityRealm);
176
177
  }
177
178
  initializeEntityState(id, entityName) {
178
- const entityId = id.value;
179
+ const entityId = id.uniqueValue;
179
180
  const existing = this.treeStore.entityStore.get(entityId);
180
181
  if (existing !== void 0) {
181
182
  return existing;
182
183
  }
183
184
  const entityState = {
184
185
  entityName,
185
- hasIdSetInStone: id instanceof ServerGeneratedUuid,
186
+ hasIdSetInStone: id instanceof ServerId,
186
187
  id,
187
188
  isScheduledForDeletion: false,
188
189
  maidenId: id instanceof UnpersistedEntityDummyId ? id : void 0,
@@ -214,7 +215,7 @@ class StateInitializer {
214
215
  };
215
216
  const initialData = initialEntityIds.size === 0 ? Array.from({ length: blueprint.marker.parameters.initialEntityCount }) : initialEntityIds;
216
217
  for (const entityId of initialData) {
217
- this.initializeEntityRealm(entityId ? new ServerGeneratedUuid(entityId) : new UnpersistedEntityDummyId(), entityListState.entityName, {
218
+ this.initializeEntityRealm(entityId ? new ServerId(entityId, entityName) : new UnpersistedEntityDummyId(), entityListState.entityName, {
218
219
  type: "listEntity",
219
220
  parent: entityListState
220
221
  });
@@ -222,8 +223,8 @@ class StateInitializer {
222
223
  this.eventManager.registerNewlyInitialized(entityListState);
223
224
  return entityListState;
224
225
  }
225
- initializeFieldState(parent, placeholderName, fieldMarker, persistedValue) {
226
- const resolvedFieldValue = persistedValue ?? fieldMarker.defaultValue ?? null;
226
+ initializeFieldState(parent, placeholderName, fieldMarker, persistedValue, copyFromState) {
227
+ const resolvedFieldValue = copyFromState ? copyFromState.value : persistedValue ?? fieldMarker.defaultValue ?? null;
227
228
  const fieldState = {
228
229
  type: "field",
229
230
  accessor: void 0,
@@ -235,16 +236,10 @@ class StateInitializer {
235
236
  eventListeners: this.initializeFieldEventListenerStore(fieldMarker),
236
237
  errors: void 0,
237
238
  touchLog: void 0,
238
- hasUnpersistedChanges: false,
239
+ hasUnpersistedChanges: copyFromState?.hasUnpersistedChanges ?? false,
239
240
  getAccessor: () => {
240
241
  if (fieldState.accessor === void 0) {
241
- const fieldSchema = this.treeStore.schema.getEntityField(parent.entity.entityName, fieldMarker.fieldName);
242
- if (!fieldSchema) {
243
- throw new BindingError(`Unknown field ${parent.entity.entityName}.${fieldMarker.fieldName}.`);
244
- }
245
- if (fieldSchema.__typename !== "_Column") {
246
- throw new BindingError(`Invalid type of field ${parent.entity.entityName}.${fieldMarker.fieldName}. Expected '_Column', '${fieldSchema.__typename}' found.`);
247
- }
242
+ const fieldSchema = this.treeStore.schema.getEntityColumn(parent.entity.entityName, fieldMarker.fieldName);
248
243
  fieldState.accessor = new FieldAccessor(fieldState, this.fieldOperations, fieldState.placeholderName, fieldState.value, fieldState.persistedValue === void 0 ? null : fieldState.persistedValue, fieldState.fieldMarker.defaultValue, fieldState.errors, fieldState.hasUnpersistedChanges, fieldState.touchLog, fieldState.getAccessor, fieldSchema);
249
244
  }
250
245
  return fieldState.accessor;
@@ -253,14 +248,14 @@ class StateInitializer {
253
248
  this.eventManager.registerNewlyInitialized(fieldState);
254
249
  return fieldState;
255
250
  }
256
- initializeFromFieldMarker(parent, field, fieldDatum) {
257
- if (fieldDatum instanceof Set) {
251
+ initializeFromFieldMarker(parent, field, persistedValue, copyFromState) {
252
+ if (persistedValue instanceof Set) {
258
253
  throw new BindingError(`Received a collection of referenced entities where a single '${field.fieldName}' field was expected. Perhaps you wanted to use a <Repeater />?`);
259
254
  }
260
- if (fieldDatum instanceof ServerGeneratedUuid) {
255
+ if (persistedValue instanceof ServerId) {
261
256
  throw new BindingError(`Received a referenced entity where a single '${field.fieldName}' field was expected. Perhaps you wanted to use <HasOne />?`);
262
257
  }
263
- parent.children.set(field.placeholderName, this.initializeFieldState(parent, field.placeholderName, field, fieldDatum));
258
+ parent.children.set(field.placeholderName, this.initializeFieldState(parent, field.placeholderName, field, persistedValue, copyFromState));
264
259
  }
265
260
  initializeFromHasOneRelationMarker(parent, field, entityId, copyFrom) {
266
261
  parent.children.set(field.placeholderName, this.initializeEntityRealm(entityId, this.getRelationTargetEntityName(parent, field), {
@@ -273,10 +268,7 @@ class StateInitializer {
273
268
  parent.children.set(field.placeholderName, this.initializeEntityListState({ marker: field, parent }, this.getRelationTargetEntityName(parent, field), persistedEntityIds));
274
269
  }
275
270
  getRelationTargetEntityName(entityRealm, field) {
276
- const targetField = this.treeStore.schema.getEntityField(entityRealm.entity.entityName, field.parameters.field);
277
- if (targetField?.__typename !== "_Relation") {
278
- throw new BindingError();
279
- }
271
+ const targetField = this.treeStore.schema.getEntityRelation(entityRealm.entity.entityName, field.parameters.field);
280
272
  return targetField.targetEntity;
281
273
  }
282
274
  runImmediateUserInitialization(realm, initialize) {