@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":"EntityAccessor.js","sources":["../../../src/accessors/EntityAccessor.ts"],"sourcesContent":["import { RuntimeId, ServerGeneratedUuid, SingleEntityPersistedData } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { EntityOperations } from '../core/operations'\nimport type { Environment } from '../dao'\nimport { PlaceholderGenerator } from '../markers'\nimport { QueryLanguage } from '../queryLanguage'\nimport type {\n\tEntityId,\n\tEntityName,\n\tEntityRealmKey,\n\tFieldName,\n\tFieldValue,\n\tRelativeEntityList,\n\tRelativeSingleEntity,\n\tRelativeSingleField,\n\tSugaredRelativeEntityList,\n\tSugaredRelativeSingleEntity,\n\tSugaredRelativeSingleField,\n} from '../treeParameters'\nimport type { AsyncBatchUpdatesOptions } from './AsyncBatchUpdatesOptions'\nimport type { BatchUpdatesOptions } from './BatchUpdatesOptions'\nimport type { EntityListAccessor } from './EntityListAccessor'\nimport type { Errorable } from './Errorable'\nimport { ErrorAccessor } from './ErrorAccessor'\nimport type { FieldAccessor } from './FieldAccessor'\nimport type { PersistErrorOptions } from './PersistErrorOptions'\nimport type { PersistSuccessOptions } from './PersistSuccessOptions'\nimport type { EntityRealmState } from '../core/state'\n\nclass EntityAccessor implements Errorable {\n\tpublic constructor(\n\t\tprivate readonly stateKey: EntityRealmState,\n\t\tprivate readonly operations: EntityOperations,\n\t\tprivate readonly runtimeId: RuntimeId,\n\t\tpublic readonly key: EntityRealmKey, // ⚠️ This is *NOT* the id! ⚠️\n\t\tpublic readonly name: EntityName,\n\t\tprivate readonly fieldData: EntityAccessor.FieldData,\n\t\tprivate readonly dataFromServer: SingleEntityPersistedData | undefined,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly environment: Environment,\n\t\tpublic readonly getAccessor: EntityAccessor.GetEntityAccessor,\n\t) {}\n\n\tpublic get idOnServer(): string | undefined {\n\t\treturn this.runtimeId.existsOnServer ? this.runtimeId.value : undefined\n\t}\n\n\t/**\n\t * Note that for entities that don't yet exist on server this will return a dummy id.\n\t */\n\tpublic get id(): EntityId {\n\t\treturn this.runtimeId.value\n\t}\n\n\tpublic get existsOnServer(): boolean {\n\t\treturn this.runtimeId.existsOnServer\n\t}\n\n\t//\n\n\tpublic addError(error: ErrorAccessor.Error | string): () => void {\n\t\treturn this.operations.addError(this.stateKey, ErrorAccessor.normalizeError(error))\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityAccessor.RuntimeEntityEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t): () => void {\n\t\treturn this.operations.addEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic batchUpdates(performUpdates: EntityAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.batchUpdates(this.stateKey, performUpdates)\n\t}\n\n\tpublic connectEntityAtField(field: FieldName, entityToConnect: EntityAccessor): void {\n\t\tthis.operations.connectEntityAtField(this.stateKey, field, entityToConnect)\n\t}\n\n\tpublic disconnectEntityAtField(field: FieldName, initializeReplacement?: EntityAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.disconnectEntityAtField(this.stateKey, field, initializeReplacement)\n\t}\n\n\tpublic deleteEntity(): void {\n\t\tthis.operations.deleteEntity(this.stateKey)\n\t}\n\n\t//\n\n\tpublic updateValues(fieldValuePairs: EntityAccessor.FieldValuePairs): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst entries = Array.isArray(fieldValuePairs) ? fieldValuePairs : Object.entries(fieldValuePairs)\n\n\t\t\tfor (const [field, value] of entries) {\n\t\t\t\tgetAccessor().getField(field).updateValue(value)\n\t\t\t}\n\t\t})\n\t}\n\n\t/**\n\t * Please keep in mind that this method signature is literally impossible to implement safely. The generic parameter\n\t * is really just a way to succinctly write a type cast. Nothing more, really.\n\t */\n\tpublic getField<Value extends FieldValue = FieldValue>(\n\t\tfield: SugaredRelativeSingleField | string,\n\t): FieldAccessor<Value> {\n\t\treturn this.getRelativeSingleField<Value>(QueryLanguage.desugarRelativeSingleField(field, this.environment))\n\t}\n\n\tpublic getEntity(entity: SugaredRelativeSingleEntity | string): EntityAccessor {\n\t\treturn this.getRelativeSingleEntity(QueryLanguage.desugarRelativeSingleEntity(entity, this.environment))\n\t}\n\n\tpublic getEntityList(entityList: SugaredRelativeEntityList | string): EntityListAccessor {\n\t\treturn this.getRelativeEntityList(QueryLanguage.desugarRelativeEntityList(entityList, this.environment))\n\t}\n\n\tpublic getKeyConnectedOnServer(entity: SugaredRelativeSingleEntity | string): string | null {\n\t\tconst desugared = QueryLanguage.desugarRelativeSingleEntity(entity, this.environment)\n\t\tconst lastHasOne = desugared.hasOneRelationPath[desugared.hasOneRelationPath.length - 1]\n\t\tconst lastHasOnePlaceholder = PlaceholderGenerator.getHasOneRelationPlaceholder(lastHasOne)\n\n\t\tlet containingAccessor: EntityAccessor = this\n\n\t\tif (desugared.hasOneRelationPath.length > 1) {\n\t\t\tcontainingAccessor = this.getRelativeSingleEntity({\n\t\t\t\thasOneRelationPath: desugared.hasOneRelationPath.slice(0, -1),\n\t\t\t})\n\t\t}\n\t\treturn containingAccessor.getPersistedKeyByPlaceholder(lastHasOnePlaceholder)\n\t}\n\n\t//\n\n\t/**\n\t * @see EntityAccessor.getField\n\t */\n\tpublic getRelativeSingleField<Value extends FieldValue = FieldValue>(field: RelativeSingleField): FieldAccessor<Value> {\n\t\treturn this.getRelativeSingleEntity(field).getAccessorByPlaceholder(\n\t\t\tPlaceholderGenerator.getFieldPlaceholder(field.field),\n\t\t) as unknown as FieldAccessor<Value>\n\t}\n\n\tpublic getRelativeSingleEntity(relativeSingleEntity: RelativeSingleEntity): EntityAccessor {\n\t\tlet relativeTo: EntityAccessor = this\n\n\t\tfor (const hasOneRelation of relativeSingleEntity.hasOneRelationPath) {\n\t\t\trelativeTo = relativeTo.getAccessorByPlaceholder(\n\t\t\t\tPlaceholderGenerator.getHasOneRelationPlaceholder(hasOneRelation),\n\t\t\t) as EntityAccessor\n\t\t}\n\t\treturn relativeTo\n\t}\n\n\tpublic getRelativeEntityList(entityList: RelativeEntityList): EntityListAccessor {\n\t\treturn this.getRelativeSingleEntity(entityList).getAccessorByPlaceholder(\n\t\t\tPlaceholderGenerator.getHasManyRelationPlaceholder(entityList.hasManyRelation),\n\t\t) as EntityListAccessor\n\t}\n\n\tprivate getAccessorByPlaceholder(placeholderName: FieldName): EntityAccessor.NestedAccessor {\n\t\tconst record = this.fieldData.get(placeholderName)\n\t\tif (record === undefined) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`EntityAccessor: unknown field placeholder '${placeholderName} on ${this.name}'. Unless this is just a typo, this is ` +\n\t\t\t\t\t`typically caused by one of the following:\\n` +\n\t\t\t\t\t`\\t• Trying to access a field that has not been registered during static render, and thus lacks a marker and an accessor.\\n` +\n\t\t\t\t\t`\\t• Misusing an EntityAccessor getter. If you used one of the getRelative[…] family, please make sure all ` +\n\t\t\t\t\t`parameters match the marker tree exactly.` +\n\t\t\t\t\t`\\n\\nFor more information, please consult the documentation.\\n\\n`,\n\t\t\t)\n\t\t}\n\t\treturn record.getAccessor()\n\t}\n\n\tprivate getPersistedKeyByPlaceholder(placeholderName: string): string | null {\n\t\tif (this.dataFromServer === undefined) {\n\t\t\treturn null\n\t\t}\n\t\tconst key = this.dataFromServer.get(placeholderName)\n\n\t\tif (key instanceof ServerGeneratedUuid) {\n\t\t\treturn key.value\n\t\t}\n\t\tif (key === null) {\n\t\t\t// TODO this also returns null and fails to throw when placeholderName points to a regular scalar field that\n\t\t\t// \thappens to be also null.\n\t\t\treturn null\n\t\t}\n\n\t\t// From now on, we're past the happy path, way into error land.\n\t\tif (key === undefined) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`EntityAccessor.getKeyConnectedOnServer: unknown placeholder '${placeholderName}'. Unless this is just ` +\n\t\t\t\t\t`a typo, this typically happens when a has-one relation hasn't been registered during static render.`,\n\t\t\t)\n\t\t}\n\t\tif (key instanceof Set) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`EntityAccessor.getKeyConnectedOnServer: the placeholder '${placeholderName}' refers to a has-many relation, ` +\n\t\t\t\t\t`not a has-one. This method is meant exclusively for has-one relations.`,\n\t\t\t)\n\t\t}\n\t\tthrow new BindingError(\n\t\t\t`EntityAccessor.getKeyConnectedOnServer: the placeholder '${placeholderName}' refers to a scalar field, not a` +\n\t\t\t\t`has-one relation. This method is meant exclusively for has-one relations.`,\n\t\t)\n\t}\n}\n\nnamespace EntityAccessor {\n\texport interface FieldDatum {\n\t\tgetAccessor(): NestedAccessor\n\t}\n\texport type NestedAccessor = EntityAccessor | EntityListAccessor | FieldAccessor\n\n\texport type FieldValuePairs =\n\t\t| {\n\t\t\t\t[field: string]: FieldValue\n\t\t }\n\t\t| Iterable<[SugaredRelativeSingleField | string, FieldValue]>\n\n\texport type FieldData = Map<FieldName, FieldDatum>\n\n\texport type GetEntityAccessor = () => EntityAccessor\n\texport type BatchUpdatesHandler = (getAccessor: GetEntityAccessor, options: BatchUpdatesOptions) => void\n\texport type UpdateListener = (accessor: EntityAccessor) => void\n\n\texport type BeforePersistHandler = (\n\t\tgetAccessor: GetEntityAccessor,\n\t\toptions: AsyncBatchUpdatesOptions,\n\t) => void | Promise<void | BeforePersistHandler>\n\n\texport type PersistErrorHandler = (\n\t\tgetAccessor: GetEntityAccessor,\n\t\toptions: PersistErrorOptions,\n\t) => void | Promise<void>\n\n\texport type PersistSuccessHandler = (\n\t\tgetAccessor: GetEntityAccessor,\n\t\toptions: PersistSuccessOptions,\n\t) => void | Promise<void | PersistSuccessHandler>\n\n\texport interface RuntimeEntityEventListenerMap {\n\t\tbeforePersist: BeforePersistHandler\n\t\tbeforeUpdate: BatchUpdatesHandler\n\t\tconnectionUpdate: UpdateListener\n\t\tpersistError: PersistErrorHandler\n\t\tpersistSuccess: PersistSuccessHandler\n\t\tupdate: UpdateListener\n\t}\n\texport interface EntityEventListenerMap extends RuntimeEntityEventListenerMap {\n\t\tinitialize: BatchUpdatesHandler\n\t}\n\texport type EntityEventType = keyof EntityEventListenerMap\n}\n\nexport { Entity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EAEQ,yBAAyB,iBAA2D;AAC3F,UAAM,SAAS,KAAK,UAAU,IAAI,eAAe;AACjD,QAAI,WAAW,QAAW;AACzB,YAAM,IAAI,aACT,8CAA8C,sBAAsB,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAM1E;AAAA,IACD;AACA,WAAO,OAAO;EACf;AAAA,EAEQ,6BAA6B,iBAAwC;AACxE,QAAA,KAAK,mBAAmB,QAAW;AAC/B,aAAA;AAAA,IACR;AACA,UAAM,MAAM,KAAK,eAAe,IAAI,eAAe;AAEnD,QAAI,eAAe,qBAAqB;AACvC,aAAO,IAAI;AAAA,IACZ;AACA,QAAI,QAAQ,MAAM;AAGV,aAAA;AAAA,IACR;AAGA,QAAI,QAAQ,QAAW;AAChB,YAAA,IAAI,aACT,gEAAgE,2IAEjE;AAAA,IACD;AACA,QAAI,eAAe,KAAK;AACjB,YAAA,IAAI,aACT,4DAA4D,wHAE7D;AAAA,IACD;AACM,UAAA,IAAI,aACT,4DAA4D,2HAE7D;AAAA,EACD;AACD;;"}
1
+ {"version":3,"file":"EntityAccessor.js","sources":["../../../src/accessors/EntityAccessor.ts"],"sourcesContent":["import { RuntimeId, SingleEntityPersistedData } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { EntityOperations } from '../core/operations'\nimport type { Environment } from '../dao'\nimport { PlaceholderGenerator } from '../markers'\nimport { QueryLanguage } from '../queryLanguage'\nimport type {\n\tEntityId,\n\tEntityName,\n\tEntityRealmKey,\n\tFieldName,\n\tFieldValue,\n\tRelativeEntityList,\n\tRelativeSingleEntity,\n\tRelativeSingleField,\n\tSugaredRelativeEntityList,\n\tSugaredRelativeSingleEntity,\n\tSugaredRelativeSingleField,\n} from '../treeParameters'\nimport type { AsyncBatchUpdatesOptions } from './AsyncBatchUpdatesOptions'\nimport type { BatchUpdatesOptions } from './BatchUpdatesOptions'\nimport type { EntityListAccessor } from './EntityListAccessor'\nimport type { Errorable } from './Errorable'\nimport { ErrorAccessor } from './ErrorAccessor'\nimport type { FieldAccessor } from './FieldAccessor'\nimport type { PersistErrorOptions } from './PersistErrorOptions'\nimport type { PersistSuccessOptions } from './PersistSuccessOptions'\nimport type { EntityRealmState } from '../core/state'\nimport { getEntityMarker } from '../core/state'\n\nclass EntityAccessor implements Errorable {\n\tpublic constructor(\n\t\tprivate readonly state: EntityRealmState,\n\t\tprivate readonly operations: EntityOperations,\n\t\tprivate readonly runtimeId: RuntimeId,\n\t\tpublic readonly key: EntityRealmKey, // ⚠️ This is *NOT* the id! ⚠️\n\t\tpublic readonly name: EntityName,\n\t\tprivate readonly fieldData: EntityAccessor.FieldData,\n\t\tprivate readonly dataFromServer: SingleEntityPersistedData | undefined,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly environment: Environment,\n\t\tpublic readonly getAccessor: EntityAccessor.GetEntityAccessor,\n\t) {}\n\n\tpublic get idOnServer(): EntityId | undefined {\n\t\treturn this.runtimeId.existsOnServer ? this.runtimeId.value : undefined\n\t}\n\n\t/**\n\t * Note that for entities that don't yet exist on server this will return a dummy id.\n\t */\n\tpublic get id(): EntityId {\n\t\treturn this.runtimeId.value\n\t}\n\n\tpublic get existsOnServer(): boolean {\n\t\treturn this.runtimeId.existsOnServer\n\t}\n\n\t//\n\n\tpublic addError(error: ErrorAccessor.Error | string): () => void {\n\t\treturn this.operations.addError(this.state, ErrorAccessor.normalizeError(error))\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityAccessor.RuntimeEntityEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t): () => void {\n\t\treturn this.operations.addEventListener(this.state, event, listener)\n\t}\n\n\tpublic batchUpdates(performUpdates: EntityAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.batchUpdates(this.state, performUpdates)\n\t}\n\n\tpublic connectEntityAtField(field: FieldName, entityToConnect: EntityAccessor): void {\n\t\tthis.operations.connectEntityAtField(this.state, field, entityToConnect)\n\t}\n\n\tpublic disconnectEntityAtField(field: FieldName, initializeReplacement?: EntityAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.disconnectEntityAtField(this.state, field, initializeReplacement)\n\t}\n\n\tpublic deleteEntity(): void {\n\t\tthis.operations.deleteEntity(this.state)\n\t}\n\n\t//\n\n\tpublic updateValues(fieldValuePairs: EntityAccessor.FieldValuePairs): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst entries = Array.isArray(fieldValuePairs) ? fieldValuePairs : Object.entries(fieldValuePairs)\n\n\t\t\tfor (const [field, value] of entries) {\n\t\t\t\tgetAccessor().getField(field).updateValue(value)\n\t\t\t}\n\t\t})\n\t}\n\n\t/**\n\t * Please keep in mind that this method signature is literally impossible to implement safely. The generic parameter\n\t * is really just a way to succinctly write a type cast. Nothing more, really.\n\t */\n\tpublic getField<Value extends FieldValue = FieldValue>(\n\t\tfield: SugaredRelativeSingleField | string,\n\t): FieldAccessor<Value> {\n\t\treturn this.getRelativeSingleField<Value>(QueryLanguage.desugarRelativeSingleField(field, this.environment))\n\t}\n\n\tpublic getEntity(entity: SugaredRelativeSingleEntity | string): EntityAccessor {\n\t\treturn this.getRelativeSingleEntity(QueryLanguage.desugarRelativeSingleEntity(entity, this.environment))\n\t}\n\n\tpublic getEntityList(entityList: SugaredRelativeEntityList | string): EntityListAccessor {\n\t\treturn this.getRelativeEntityList(QueryLanguage.desugarRelativeEntityList(entityList, this.environment))\n\t}\n\n\t//\n\n\t/**\n\t * @see EntityAccessor.getField\n\t */\n\tpublic getRelativeSingleField<Value extends FieldValue = FieldValue>(field: RelativeSingleField): FieldAccessor<Value> {\n\t\treturn this.getRelativeSingleEntity(field).getAccessorByPlaceholder(\n\t\t\tPlaceholderGenerator.getFieldPlaceholder(field.field),\n\t\t) as unknown as FieldAccessor<Value>\n\t}\n\n\tpublic getRelativeSingleEntity(relativeSingleEntity: RelativeSingleEntity): EntityAccessor {\n\t\tlet relativeTo: EntityAccessor = this\n\n\t\tfor (const hasOneRelation of relativeSingleEntity.hasOneRelationPath) {\n\t\t\trelativeTo = relativeTo.getAccessorByPlaceholder(\n\t\t\t\tPlaceholderGenerator.getHasOneRelationPlaceholder(hasOneRelation),\n\t\t\t) as EntityAccessor\n\t\t}\n\t\treturn relativeTo\n\t}\n\n\tpublic getRelativeEntityList(entityList: RelativeEntityList): EntityListAccessor {\n\t\treturn this.getRelativeSingleEntity(entityList).getAccessorByPlaceholder(\n\t\t\tPlaceholderGenerator.getHasManyRelationPlaceholder(entityList.hasManyRelation),\n\t\t) as EntityListAccessor\n\t}\n\n\tpublic getParent(): EntityAccessor | EntityListAccessor | undefined {\n\t\tconst blueprint = this.state.blueprint\n\t\tif (blueprint.type === 'subTree') {\n\t\t\treturn undefined\n\t\t}\n\t\treturn blueprint.parent.getAccessor()\n\t}\n\n\tpublic getMarker() {\n\t\treturn getEntityMarker(this.state)\n\t}\n\n\tprivate getAccessorByPlaceholder(placeholderName: FieldName): EntityAccessor.NestedAccessor {\n\t\tconst record = this.fieldData.get(placeholderName)\n\t\tif (record === undefined) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`EntityAccessor: unknown field placeholder '${placeholderName} on ${this.name}'. Unless this is just a typo, this is ` +\n\t\t\t\t\t`typically caused by one of the following:\\n` +\n\t\t\t\t\t`\\t• Trying to access a field that has not been registered during static render, and thus lacks a marker and an accessor.\\n` +\n\t\t\t\t\t`\\t• Misusing an EntityAccessor getter. If you used one of the getRelative[…] family, please make sure all ` +\n\t\t\t\t\t`parameters match the marker tree exactly.` +\n\t\t\t\t\t`\\n\\nFor more information, please consult the documentation.\\n\\n`,\n\t\t\t)\n\t\t}\n\t\treturn record.getAccessor()\n\t}\n}\n\nnamespace EntityAccessor {\n\texport interface FieldDatum {\n\t\tgetAccessor(): NestedAccessor\n\t}\n\texport type NestedAccessor = EntityAccessor | EntityListAccessor | FieldAccessor\n\n\texport type FieldValuePairs =\n\t\t| {\n\t\t\t\t[field: string]: FieldValue\n\t\t }\n\t\t| Iterable<[SugaredRelativeSingleField | string, FieldValue]>\n\n\texport type FieldData = Map<FieldName, FieldDatum>\n\n\texport type GetEntityAccessor = () => EntityAccessor\n\texport type BatchUpdatesHandler = (getAccessor: GetEntityAccessor, options: BatchUpdatesOptions) => void\n\texport type UpdateListener = (accessor: EntityAccessor) => void\n\n\texport type BeforePersistHandler = (\n\t\tgetAccessor: GetEntityAccessor,\n\t\toptions: AsyncBatchUpdatesOptions,\n\t) => void | Promise<void | BeforePersistHandler>\n\n\texport type PersistErrorHandler = (\n\t\tgetAccessor: GetEntityAccessor,\n\t\toptions: PersistErrorOptions,\n\t) => void | Promise<void>\n\n\texport type PersistSuccessHandler = (\n\t\tgetAccessor: GetEntityAccessor,\n\t\toptions: PersistSuccessOptions,\n\t) => void | Promise<void | PersistSuccessHandler>\n\n\texport interface RuntimeEntityEventListenerMap {\n\t\tbeforePersist: BeforePersistHandler\n\t\tbeforeUpdate: BatchUpdatesHandler\n\t\tconnectionUpdate: UpdateListener\n\t\tpersistError: PersistErrorHandler\n\t\tpersistSuccess: PersistSuccessHandler\n\t\tupdate: UpdateListener\n\t}\n\texport interface EntityEventListenerMap extends RuntimeEntityEventListenerMap {\n\t\tinitialize: BatchUpdatesHandler\n\t}\n\texport type EntityEventType = keyof EntityEventListenerMap\n}\n\nexport { EntityAccessor }\n"],"names":[],"mappings":";;;;;AA8BA,MAAM,eAAoC;AAAA,EAClC,YACW,OACA,YACA,WACD,KACA,MACC,WACA,gBACD,uBACA,QACA,aACA,aACf;AAXgB,SAAA,QAAA;AACA,SAAA,aAAA;AACA,SAAA,YAAA;AACD,SAAA,MAAA;AACA,SAAA,OAAA;AACC,SAAA,YAAA;AACA,SAAA,iBAAA;AACD,SAAA,wBAAA;AACA,SAAA,SAAA;AACA,SAAA,cAAA;AACA,SAAA,cAAA;AAAA,EACd;AAAA,MAEQ,aAAmC;AAC7C,WAAO,KAAK,UAAU,iBAAiB,KA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WAAW,CAAC;AAAA,EACxG;AAAA,EAOO,uBAA8D,OAAkD;AAC/G,WAAA,KAAK,wBAAwB,KAAK,EAAE,yBAC1C,qBAAqB,oBAAoB,MAAM,KAAK,CACrD;AAAA,EACD;AAAA,EAEO,wBAAwB,sBAA4D;AAC1F,QAAI,aAA6B;AAEtB,eAAA,kBAAkB,qBAAqB,oBAAoB;AACrE,mBAAa,WAAW,yBACvB,qBAAqB,6BAA6B,cAAc,CACjE;AAAA,IACD;AACO,WAAA;AAAA,EACR;AAAA,EAEO,sBAAsB,YAAoD;AACzE,WAAA,KAAK,wBAAwB,UAAU,EAAE,yBAC/C,qBAAqB,8BAA8B,WAAW,eAAe,CAC9E;AAAA,EACD;AAAA,EAEO,YAA6D;AAC7D,UAAA,YAAY,KAAK,MAAM;AACzB,QAAA,UAAU,SAAS,WAAW;AAC1B,aAAA;AAAA,IACR;AACO,WAAA,UAAU,OAAO;EACzB;AAAA,EAEO,YAAY;AACX,WAAA,gBAAgB,KAAK,KAAK;AAAA,EAClC;AAAA,EAEQ,yBAAyB,iBAA2D;AAC3F,UAAM,SAAS,KAAK,UAAU,IAAI,eAAe;AACjD,QAAI,WAAW,QAAW;AACzB,YAAM,IAAI,aACT,8CAA8C,sBAAsB,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAM1E;AAAA,IACD;AACA,WAAO,OAAO;EACf;AACD;;"}
@@ -1,7 +1,7 @@
1
1
  import { ErrorAccessor } from "./ErrorAccessor.js";
2
2
  class EntityListAccessor {
3
- constructor(stateKey, operations, _children, _idsPersistedOnServer, hasUnpersistedChanges, errors, environment, getAccessor) {
4
- this.stateKey = stateKey;
3
+ constructor(state, operations, _children, _idsPersistedOnServer, hasUnpersistedChanges, errors, environment, getAccessor) {
4
+ this.state = state;
5
5
  this.operations = operations;
6
6
  this._children = _children;
7
7
  this._idsPersistedOnServer = _idsPersistedOnServer;
@@ -36,7 +36,7 @@ class EntityListAccessor {
36
36
  return this._children.size;
37
37
  }
38
38
  hasEntityOnServer(entityOrItsId) {
39
- if (typeof entityOrItsId === "string") {
39
+ if (typeof entityOrItsId === "string" || typeof entityOrItsId === "number") {
40
40
  return this.idsPersistedOnServer.has(entityOrItsId);
41
41
  }
42
42
  const idOnServer = entityOrItsId.idOnServer;
@@ -62,28 +62,28 @@ class EntityListAccessor {
62
62
  });
63
63
  }
64
64
  addError(error) {
65
- return this.operations.addError(this.stateKey, ErrorAccessor.normalizeError(error));
65
+ return this.operations.addError(this.state, ErrorAccessor.normalizeError(error));
66
66
  }
67
67
  addEventListener(event, listener) {
68
- return this.operations.addEventListener(this.stateKey, event, listener);
68
+ return this.operations.addEventListener(this.state, event, listener);
69
69
  }
70
70
  addChildEventListener(state, event, listener) {
71
- return this.operations.addChildEventListener(this.stateKey, event, listener);
71
+ return this.operations.addChildEventListener(this.state, event, listener);
72
72
  }
73
73
  batchUpdates(performUpdates) {
74
- this.operations.batchUpdates(this.stateKey, performUpdates);
74
+ this.operations.batchUpdates(this.state, performUpdates);
75
75
  }
76
76
  connectEntity(entityToConnect) {
77
- this.operations.connectEntity(this.stateKey, entityToConnect);
77
+ this.operations.connectEntity(this.state, entityToConnect);
78
78
  }
79
79
  createNewEntity(initialize) {
80
- return this.operations.createNewEntity(this.stateKey, initialize);
80
+ return this.operations.createNewEntity(this.state, initialize);
81
81
  }
82
82
  disconnectEntity(childEntity, options = {}) {
83
- this.operations.disconnectEntity(this.stateKey, childEntity, options);
83
+ this.operations.disconnectEntity(this.state, childEntity, options);
84
84
  }
85
85
  getChildEntityById(id) {
86
- return this.operations.getChildEntityById(this.stateKey, id);
86
+ return this.operations.getChildEntityById(this.state, id);
87
87
  }
88
88
  }
89
89
  export { EntityListAccessor };
@@ -1 +1 @@
1
- {"version":3,"file":"EntityListAccessor.js","sources":["../../../src/accessors/EntityListAccessor.ts"],"sourcesContent":["import type { ListOperations } from '../core/operations'\nimport type { Environment } from '../dao'\nimport type { EntityId, EntityRealmKey } from '../treeParameters'\nimport type { AsyncBatchUpdatesOptions } from './AsyncBatchUpdatesOptions'\nimport type { BatchUpdatesOptions } from './BatchUpdatesOptions'\nimport type { EntityAccessor } from './EntityAccessor'\nimport type { Errorable } from './Errorable'\nimport { ErrorAccessor } from './ErrorAccessor'\nimport type { PersistErrorOptions } from './PersistErrorOptions'\nimport type { PersistSuccessOptions } from './PersistSuccessOptions'\nimport type { EntityListState } from '../core/state'\nimport { RuntimeId } from '../accessorTree'\n\nclass EntityListAccessor implements Errorable {\n\tpublic constructor(\n\t\tprivate readonly stateKey: EntityListState,\n\t\tprivate readonly operations: ListOperations,\n\t\tprivate readonly _children: ReadonlyMap<EntityId, { getAccessor: EntityAccessor.GetEntityAccessor }>,\n\t\tprivate readonly _idsPersistedOnServer: ReadonlySet<string>,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly environment: Environment,\n\t\tpublic readonly getAccessor: EntityListAccessor.GetEntityListAccessor,\n\t) {}\n\n\t/**\n\t * Returns all entity keys that are on the list.\n\t * **KEYS ARE NOT IDS!**\n\t * @see EntityAccessor.key\n\t */\n\tpublic *keys(): IterableIterator<EntityRealmKey> {\n\t\tfor (const accessor of this) {\n\t\t\tyield accessor.key\n\t\t}\n\t}\n\n\tpublic *ids(): IterableIterator<EntityId> {\n\t\treturn this._children.keys()\n\t}\n\n\t/**\n\t * This will only contain the ids that the server knows about. Not necessarily the ids that have been added on\n\t * the list since the last server query.\n\t */\n\tpublic get idsPersistedOnServer(): Set<string> {\n\t\treturn new Set(this._idsPersistedOnServer)\n\t}\n\n\tpublic *[Symbol.iterator](): IterableIterator<EntityAccessor> {\n\t\tfor (const { getAccessor } of this._children.values()) {\n\t\t\tyield getAccessor()\n\t\t}\n\t}\n\n\tpublic hasEntityId(id: EntityId): boolean {\n\t\treturn this._children.has(id)\n\t}\n\n\tpublic isEmpty(): boolean {\n\t\treturn this.length === 0\n\t}\n\n\tpublic get length(): number {\n\t\treturn this._children.size\n\t}\n\n\tpublic hasEntityOnServer(entityOrItsId: EntityAccessor | EntityId): boolean {\n\t\tif (typeof entityOrItsId === 'string') {\n\t\t\treturn this.idsPersistedOnServer.has(entityOrItsId)\n\t\t}\n\t\tconst idOnServer = entityOrItsId.idOnServer\n\t\tif (idOnServer === undefined) {\n\t\t\treturn false\n\t\t}\n\t\treturn this.idsPersistedOnServer.has(idOnServer)\n\t}\n\n\tpublic deleteAll(): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst list = getAccessor()\n\t\t\tfor (const entity of list) {\n\t\t\t\tentity.deleteEntity()\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectAll(): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst list = getAccessor()\n\t\t\tfor (const entity of list) {\n\t\t\t\tlist.disconnectEntity(entity)\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic addError(error: ErrorAccessor.Error | string): () => void {\n\t\treturn this.operations.addError(this.stateKey, ErrorAccessor.normalizeError(error))\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityListAccessor.RuntimeEntityListEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityListAccessor.RuntimeEntityListEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic addChildEventListener<Type extends keyof EntityAccessor.EntityEventListenerMap>(\n\t\tstate: EntityListState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addChildEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic batchUpdates(performUpdates: EntityListAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.batchUpdates(this.stateKey, performUpdates)\n\t}\n\n\tpublic connectEntity(entityToConnect: EntityAccessor): void {\n\t\tthis.operations.connectEntity(this.stateKey, entityToConnect)\n\t}\n\n\tpublic createNewEntity(initialize?: EntityAccessor.BatchUpdatesHandler): RuntimeId {\n\t\treturn this.operations.createNewEntity(this.stateKey, initialize)\n\t}\n\tpublic disconnectEntity(childEntity: EntityAccessor, options: { noPersist?: boolean } = {}): void {\n\t\tthis.operations.disconnectEntity(this.stateKey, childEntity, options)\n\t}\n\tpublic getChildEntityById(id: EntityId): EntityAccessor {\n\t\treturn this.operations.getChildEntityById(this.stateKey, id)\n\t}\n}\n\nnamespace EntityListAccessor {\n\texport type GetEntityListAccessor = () => EntityListAccessor\n\texport type BatchUpdatesHandler = (getAccessor: GetEntityListAccessor, options: BatchUpdatesOptions) => void\n\n\texport type UpdateListener = (accessor: EntityListAccessor) => void\n\n\texport type BeforePersistHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: AsyncBatchUpdatesOptions,\n\t) => void | Promise<void | BeforePersistHandler>\n\n\texport type PersistErrorHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: PersistErrorOptions,\n\t) => void | Promise<void>\n\n\texport type PersistSuccessHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: PersistSuccessOptions,\n\t) => void | Promise<void | PersistSuccessHandler>\n\n\texport type ChildEventListenerMap = {\n\t\t[EventType in keyof Pick<EntityAccessor.EntityEventListenerMap, 'beforeUpdate' | 'initialize' | 'update'> &\n\t\t\tstring as `child${Capitalize<EventType>}`]: EntityAccessor.EntityEventListenerMap[EventType]\n\t}\n\n\texport interface RuntimeEntityListEventListenerMap {\n\t\tbeforePersist: BeforePersistHandler\n\t\tbeforeUpdate: BatchUpdatesHandler\n\t\tpersistError: PersistErrorHandler\n\t\tpersistSuccess: PersistSuccessHandler\n\t\tupdate: UpdateListener\n\t}\n\texport interface EntityListEventListenerMap extends RuntimeEntityListEventListenerMap {\n\t\tinitialize: BatchUpdatesHandler\n\t}\n\texport type EntityListEventType = keyof EntityListEventListenerMap\n}\n\nexport { EntityListAccessor }\n"],"names":[],"mappings":";AAaA,MAAM,mBAAwC;AAAA,EACtC,YACW,UACA,Y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ACF;AAAA,EAEO,SAAS,OAAiD;AACzD,WAAA,KAAK,WAAW,SAAS,KAAK,UAAU,cAAc,eAAe,KAAK,CAAC;AAAA,EACnF;AAAA,EAEO,iBACN,OACA,UACC;AACD,WAAO,KAAK,WAAW,iBAAiB,KAAK,UAAU,OAAO,QAAQ;AAAA,EACvE;AAAA,EAEO,sBACN,OACA,OACA,UACC;AACD,WAAO,KAAK,WAAW,sBAAsB,KAAK,UAAU,OAAO,QAAQ;AAAA,EAC5E;AAAA,EAEO,aAAa,gBAA8D;AACjF,SAAK,WAAW,aAAa,KAAK,UAAU,cAAc;AAAA,EAC3D;AAAA,EAEO,cAAc,iBAAuC;AAC3D,SAAK,WAAW,cAAc,KAAK,UAAU,eAAe;AAAA,EAC7D;AAAA,EAEO,gBAAgB,YAA4D;AAClF,WAAO,KAAK,WAAW,gBAAgB,KAAK,UAAU,UAAU;AAAA,EACjE;AAAA,EACO,iBAAiB,aAA6B,UAAmC,IAAU;AACjG,SAAK,WAAW,iBAAiB,KAAK,UAAU,aAAa,OAAO;AAAA,EACrE;AAAA,EACO,mBAAmB,IAA8B;AACvD,WAAO,KAAK,WAAW,mBAAmB,KAAK,UAAU,EAAE;AAAA,EAC5D;AACD;;"}
1
+ {"version":3,"file":"EntityListAccessor.js","sources":["../../../src/accessors/EntityListAccessor.ts"],"sourcesContent":["import type { ListOperations } from '../core/operations'\nimport type { Environment } from '../dao'\nimport type { EntityId, EntityRealmKey } from '../treeParameters'\nimport type { AsyncBatchUpdatesOptions } from './AsyncBatchUpdatesOptions'\nimport type { BatchUpdatesOptions } from './BatchUpdatesOptions'\nimport type { EntityAccessor } from './EntityAccessor'\nimport type { Errorable } from './Errorable'\nimport { ErrorAccessor } from './ErrorAccessor'\nimport type { PersistErrorOptions } from './PersistErrorOptions'\nimport type { PersistSuccessOptions } from './PersistSuccessOptions'\nimport type { EntityListState } from '../core/state'\nimport { RuntimeId } from '../accessorTree'\n\nclass EntityListAccessor implements Errorable {\n\tpublic constructor(\n\t\tprivate readonly state: EntityListState,\n\t\tprivate readonly operations: ListOperations,\n\t\tprivate readonly _children: ReadonlyMap<EntityId, { getAccessor: EntityAccessor.GetEntityAccessor }>,\n\t\tprivate readonly _idsPersistedOnServer: ReadonlySet<EntityId>,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly environment: Environment,\n\t\tpublic readonly getAccessor: EntityListAccessor.GetEntityListAccessor,\n\t) {}\n\n\t/**\n\t * Returns all entity keys that are on the list.\n\t * **KEYS ARE NOT IDS!**\n\t * @see EntityAccessor.key\n\t */\n\tpublic *keys(): IterableIterator<EntityRealmKey> {\n\t\tfor (const accessor of this) {\n\t\t\tyield accessor.key\n\t\t}\n\t}\n\n\tpublic *ids(): IterableIterator<EntityId> {\n\t\treturn this._children.keys()\n\t}\n\n\t/**\n\t * This will only contain the ids that the server knows about. Not necessarily the ids that have been added on\n\t * the list since the last server query.\n\t */\n\tpublic get idsPersistedOnServer(): Set<EntityId> {\n\t\treturn new Set(this._idsPersistedOnServer)\n\t}\n\n\tpublic *[Symbol.iterator](): IterableIterator<EntityAccessor> {\n\t\tfor (const { getAccessor } of this._children.values()) {\n\t\t\tyield getAccessor()\n\t\t}\n\t}\n\n\tpublic hasEntityId(id: EntityId): boolean {\n\t\treturn this._children.has(id)\n\t}\n\n\tpublic isEmpty(): boolean {\n\t\treturn this.length === 0\n\t}\n\n\tpublic get length(): number {\n\t\treturn this._children.size\n\t}\n\n\tpublic hasEntityOnServer(entityOrItsId: EntityAccessor | EntityId): boolean {\n\t\tif (typeof entityOrItsId === 'string' || typeof entityOrItsId === 'number') {\n\t\t\treturn this.idsPersistedOnServer.has(entityOrItsId)\n\t\t}\n\t\tconst idOnServer = entityOrItsId.idOnServer\n\t\tif (idOnServer === undefined) {\n\t\t\treturn false\n\t\t}\n\t\treturn this.idsPersistedOnServer.has(idOnServer)\n\t}\n\n\tpublic deleteAll(): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst list = getAccessor()\n\t\t\tfor (const entity of list) {\n\t\t\t\tentity.deleteEntity()\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectAll(): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst list = getAccessor()\n\t\t\tfor (const entity of list) {\n\t\t\t\tlist.disconnectEntity(entity)\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic addError(error: ErrorAccessor.Error | string): () => void {\n\t\treturn this.operations.addError(this.state, ErrorAccessor.normalizeError(error))\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityListAccessor.RuntimeEntityListEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityListAccessor.RuntimeEntityListEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addEventListener(this.state, event, listener)\n\t}\n\n\tpublic addChildEventListener<Type extends keyof EntityAccessor.EntityEventListenerMap>(\n\t\tstate: EntityListState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addChildEventListener(this.state, event, listener)\n\t}\n\n\tpublic batchUpdates(performUpdates: EntityListAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.batchUpdates(this.state, performUpdates)\n\t}\n\n\tpublic connectEntity(entityToConnect: EntityAccessor): void {\n\t\tthis.operations.connectEntity(this.state, entityToConnect)\n\t}\n\n\tpublic createNewEntity(initialize?: EntityAccessor.BatchUpdatesHandler): RuntimeId {\n\t\treturn this.operations.createNewEntity(this.state, initialize)\n\t}\n\tpublic disconnectEntity(childEntity: EntityAccessor, options: { noPersist?: boolean } = {}): void {\n\t\tthis.operations.disconnectEntity(this.state, childEntity, options)\n\t}\n\tpublic getChildEntityById(id: EntityId): EntityAccessor {\n\t\treturn this.operations.getChildEntityById(this.state, id)\n\t}\n}\n\nnamespace EntityListAccessor {\n\texport type GetEntityListAccessor = () => EntityListAccessor\n\texport type BatchUpdatesHandler = (getAccessor: GetEntityListAccessor, options: BatchUpdatesOptions) => void\n\n\texport type UpdateListener = (accessor: EntityListAccessor) => void\n\n\texport type BeforePersistHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: AsyncBatchUpdatesOptions,\n\t) => void | Promise<void | BeforePersistHandler>\n\n\texport type PersistErrorHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: PersistErrorOptions,\n\t) => void | Promise<void>\n\n\texport type PersistSuccessHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: PersistSuccessOptions,\n\t) => void | Promise<void | PersistSuccessHandler>\n\n\texport type ChildEventListenerMap = {\n\t\t[EventType in keyof Pick<EntityAccessor.EntityEventListenerMap, 'beforeUpdate' | 'initialize' | 'update'> &\n\t\t\tstring as `child${Capitalize<EventType>}`]: EntityAccessor.EntityEventListenerMap[EventType]\n\t}\n\n\texport interface RuntimeEntityListEventListenerMap {\n\t\tbeforePersist: BeforePersistHandler\n\t\tbeforeUpdate: BatchUpdatesHandler\n\t\tpersistError: PersistErrorHandler\n\t\tpersistSuccess: PersistSuccessHandler\n\t\tupdate: UpdateListener\n\t}\n\texport interface EntityListEventListenerMap extends RuntimeEntityListEventListenerMap {\n\t\tinitialize: BatchUpdatesHandler\n\t}\n\texport type EntityListEventType = keyof EntityListEventListenerMap\n}\n\nexport { EntityListAccessor }\n"],"names":[],"mappings":";AAaA,MAAM,mBAAwC;AAAA,EACtC,YACW,OACA,YACA,WACA,uBACD,uBACA,QACA,aACA,aACf;AARgB,SAAA,QAAA;AACA,SAAA,aAAA;AACA,SAAA,YAAA;AACA,SAAA,wBAAA;AACD,SAAA,wBAAA;AACA,SAAA,SAAA;AACA,SAAA,cAAA;AACA,SAAA,cAAA;AAAA,EACd;AAAA,GAOK,OAAyC;AAChD,eAAW,YAAY,MAAM;AAC5B,YAAM,SAAS;AAAA,IAChB;AAAA,EACD;AAAA,GAEQ,MAAkC;AAClC,WAAA,KAAK,UAAU;EACvB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EACzE;AAAA,EAEO,aAAa,gBAA8D;AACjF,SAAK,WAAW,aAAa,KAAK,OAAO,cAAc;AAAA,EACxD;AAAA,EAEO,cAAc,iBAAuC;AAC3D,SAAK,WAAW,cAAc,KAAK,OAAO,eAAe;AAAA,EAC1D;AAAA,EAEO,gBAAgB,YAA4D;AAClF,WAAO,KAAK,WAAW,gBAAgB,KAAK,OAAO,UAAU;AAAA,EAC9D;AAAA,EACO,iBAAiB,aAA6B,UAAmC,IAAU;AACjG,SAAK,WAAW,iBAAiB,KAAK,OAAO,aAAa,OAAO;AAAA,EAClE;AAAA,EACO,mBAAmB,IAA8B;AACvD,WAAO,KAAK,WAAW,mBAAmB,KAAK,OAAO,EAAE;AAAA,EACzD;AACD;;"}
@@ -2,8 +2,8 @@ import { ErrorAccessor } from "./ErrorAccessor.js";
2
2
  import { TemporalFieldHelper } from "../fieldHelpers/helpers/TemporalFieldHelper.js";
3
3
  import { UuidFieldHelper } from "../fieldHelpers/helpers/UuidFieldHelper.js";
4
4
  class FieldAccessor {
5
- constructor(stateKey, operations, fieldName, value, valueOnServer, defaultValue, errors, hasUnpersistedChanges, touchLog, getAccessor, schema) {
6
- this.stateKey = stateKey;
5
+ constructor(state, operations, fieldName, value, valueOnServer, defaultValue, errors, hasUnpersistedChanges, touchLog, getAccessor, schema) {
6
+ this.state = state;
7
7
  this.operations = operations;
8
8
  this.fieldName = fieldName;
9
9
  this.value = value;
@@ -16,16 +16,16 @@ class FieldAccessor {
16
16
  this.schema = schema;
17
17
  }
18
18
  addError(error) {
19
- return this.operations.addError(this.stateKey, ErrorAccessor.normalizeError(error));
19
+ return this.operations.addError(this.state, ErrorAccessor.normalizeError(error));
20
20
  }
21
21
  clearErrors() {
22
- this.operations.clearErrors(this.stateKey);
22
+ this.operations.clearErrors(this.state);
23
23
  }
24
24
  addEventListener(event, listener) {
25
- return this.operations.addEventListener(this.stateKey, event, listener);
25
+ return this.operations.addEventListener(this.state, event, listener);
26
26
  }
27
27
  updateValue(newValue, options) {
28
- this.operations.updateValue(this.stateKey, newValue, options);
28
+ this.operations.updateValue(this.state, newValue, options);
29
29
  }
30
30
  hasValue(candidate) {
31
31
  return this.value === candidate;
@@ -1 +1 @@
1
- {"version":3,"file":"FieldAccessor.js","sources":["../../../src/accessors/FieldAccessor.ts"],"sourcesContent":["import type { FieldOperations } from '../core/operations'\nimport type { FieldState } from '../core/state'\nimport { TemporalFieldHelper, UuidFieldHelper } from '../fieldHelpers'\nimport type { FieldName, FieldValue } from '../treeParameters'\nimport type { BatchUpdatesOptions } from './BatchUpdatesOptions'\nimport type { Errorable } from './Errorable'\nimport { ErrorAccessor } from './ErrorAccessor'\nimport type { SchemaColumn } from '../core/schema/SchemaColumn'\n\nclass FieldAccessor<Value extends FieldValue = FieldValue> implements Errorable {\n\tconstructor(\n\t\tprivate readonly stateKey: FieldState<Value>,\n\t\tprivate readonly operations: FieldOperations,\n\t\tpublic readonly fieldName: FieldName,\n\t\tpublic readonly value: Value | null,\n\t\tpublic readonly valueOnServer: Value | null,\n\t\tpublic readonly defaultValue: Value | undefined,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tprivate readonly touchLog: ReadonlySet<string> | undefined,\n\t\tpublic readonly getAccessor: FieldAccessor.GetFieldAccessor<Value>,\n\t\tpublic readonly schema: SchemaColumn,\n\t) {}\n\n\tpublic addError(error: ErrorAccessor.Error | string): () => void {\n\t\treturn this.operations.addError(this.stateKey, ErrorAccessor.normalizeError(error))\n\t}\n\n\tpublic clearErrors(): void {\n\t\tthis.operations.clearErrors(this.stateKey)\n\t}\n\n\tpublic addEventListener<Type extends keyof FieldAccessor.FieldEventListenerMap<Value>>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: FieldAccessor.FieldEventListenerMap<Value>[Type],\n\t): () => void {\n\t\treturn this.operations.addEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic updateValue(newValue: Value | null, options?: FieldAccessor.UpdateOptions): void {\n\t\tthis.operations.updateValue(this.stateKey, newValue, options)\n\t}\n\n\tpublic hasValue(candidate: this['value']): boolean {\n\t\treturn this.value === candidate\n\t}\n\n\tpublic isTouchedBy(agent: string) {\n\t\treturn this.touchLog?.has(agent) ?? false\n\t}\n\n\tpublic get isTouched() {\n\t\treturn this.isTouchedBy(FieldAccessor.userAgent)\n\t}\n\n\tpublic get resolvedValue() {\n\t\tif (this.defaultValue === undefined) {\n\t\t\treturn this.value\n\t\t}\n\t\treturn this.value === null ? this.defaultValue : this.value\n\t}\n\n\t// helpers\n\n\tpublic get asTemporal(): TemporalFieldHelper {\n\t\treturn new TemporalFieldHelper(this.getAccessor as FieldAccessor.GetFieldAccessor<any>)\n\t}\n\n\tpublic get asUuid(): UuidFieldHelper {\n\t\treturn new UuidFieldHelper(this.getAccessor as FieldAccessor.GetFieldAccessor<any>)\n\t}\n}\nnamespace FieldAccessor {\n\texport const userAgent = 'user'\n\n\texport interface UpdateOptions {\n\t\tagent?: string\n\t}\n\n\texport type GetFieldAccessor<Value extends FieldValue = FieldValue> = () => FieldAccessor<Value>\n\n\texport type BeforeUpdateListener<Value extends FieldValue = FieldValue> = (\n\t\tupdatedAccessor: FieldAccessor<Value>,\n\t) => void\n\texport type InitializeListener<Value extends FieldValue = FieldValue> = (\n\t\tgetAccessor: GetFieldAccessor<Value>,\n\t\toptions: BatchUpdatesOptions,\n\t) => void\n\texport type UpdateListener<Value extends FieldValue = FieldValue> = (accessor: FieldAccessor<Value>) => void\n\n\texport interface RuntimeFieldEventListenerMap<Value extends FieldValue = FieldValue> {\n\t\tbeforeUpdate: BeforeUpdateListener<Value>\n\t\tupdate: UpdateListener<Value>\n\t}\n\texport interface FieldEventListenerMap<Value extends FieldValue = FieldValue>\n\t\textends RuntimeFieldEventListenerMap<Value> {\n\t\tinitialize: InitializeListener<Value>\n\t}\n\texport type FieldEventType = keyof FieldEventListenerMap\n}\n\nexport { FieldAccessor }\n"],"names":[],"mappings":";;;AASA,MAAM,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":3,"file":"FieldAccessor.js","sources":["../../../src/accessors/FieldAccessor.ts"],"sourcesContent":["import type { FieldOperations } from '../core/operations'\nimport type { FieldState } from '../core/state'\nimport { TemporalFieldHelper, UuidFieldHelper } from '../fieldHelpers'\nimport type { FieldName, FieldValue } from '../treeParameters'\nimport type { BatchUpdatesOptions } from './BatchUpdatesOptions'\nimport type { Errorable } from './Errorable'\nimport { ErrorAccessor } from './ErrorAccessor'\nimport type { SchemaColumn } from '../core/schema/SchemaColumn'\n\nclass FieldAccessor<Value extends FieldValue = FieldValue> implements Errorable {\n\tconstructor(\n\t\tprivate readonly state: FieldState<Value>,\n\t\tprivate readonly operations: FieldOperations,\n\t\tpublic readonly fieldName: FieldName,\n\t\tpublic readonly value: Value | null,\n\t\tpublic readonly valueOnServer: Value | null,\n\t\tpublic readonly defaultValue: Value | undefined,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tprivate readonly touchLog: ReadonlySet<string> | undefined,\n\t\tpublic readonly getAccessor: FieldAccessor.GetFieldAccessor<Value>,\n\t\tpublic readonly schema: SchemaColumn,\n\t) {}\n\n\tpublic addError(error: ErrorAccessor.Error | string): () => void {\n\t\treturn this.operations.addError(this.state, ErrorAccessor.normalizeError(error))\n\t}\n\n\tpublic clearErrors(): void {\n\t\tthis.operations.clearErrors(this.state)\n\t}\n\n\tpublic addEventListener<Type extends keyof FieldAccessor.FieldEventListenerMap<Value>>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: FieldAccessor.FieldEventListenerMap<Value>[Type],\n\t): () => void {\n\t\treturn this.operations.addEventListener(this.state, event, listener)\n\t}\n\n\tpublic updateValue(newValue: Value | null, options?: FieldAccessor.UpdateOptions): void {\n\t\tthis.operations.updateValue(this.state, newValue, options)\n\t}\n\n\tpublic hasValue(candidate: this['value']): boolean {\n\t\treturn this.value === candidate\n\t}\n\n\tpublic isTouchedBy(agent: string) {\n\t\treturn this.touchLog?.has(agent) ?? false\n\t}\n\n\tpublic get isTouched() {\n\t\treturn this.isTouchedBy(FieldAccessor.userAgent)\n\t}\n\n\tpublic get resolvedValue() {\n\t\tif (this.defaultValue === undefined) {\n\t\t\treturn this.value\n\t\t}\n\t\treturn this.value === null ? this.defaultValue : this.value\n\t}\n\n\t// helpers\n\n\tpublic get asTemporal(): TemporalFieldHelper {\n\t\treturn new TemporalFieldHelper(this.getAccessor as FieldAccessor.GetFieldAccessor<any>)\n\t}\n\n\tpublic get asUuid(): UuidFieldHelper {\n\t\treturn new UuidFieldHelper(this.getAccessor as FieldAccessor.GetFieldAccessor<any>)\n\t}\n}\nnamespace FieldAccessor {\n\texport const userAgent = 'user'\n\n\texport interface UpdateOptions {\n\t\tagent?: string\n\t}\n\n\texport type GetFieldAccessor<Value extends FieldValue = FieldValue> = () => FieldAccessor<Value>\n\n\texport type BeforeUpdateListener<Value extends FieldValue = FieldValue> = (\n\t\tupdatedAccessor: FieldAccessor<Value>,\n\t) => void\n\texport type InitializeListener<Value extends FieldValue = FieldValue> = (\n\t\tgetAccessor: GetFieldAccessor<Value>,\n\t\toptions: BatchUpdatesOptions,\n\t) => void\n\texport type UpdateListener<Value extends FieldValue = FieldValue> = (accessor: FieldAccessor<Value>) => void\n\n\texport interface RuntimeFieldEventListenerMap<Value extends FieldValue = FieldValue> {\n\t\tbeforeUpdate: BeforeUpdateListener<Value>\n\t\tupdate: UpdateListener<Value>\n\t}\n\texport interface FieldEventListenerMap<Value extends FieldValue = FieldValue>\n\t\textends RuntimeFieldEventListenerMap<Value> {\n\t\tinitialize: InitializeListener<Value>\n\t}\n\texport type FieldEventType = keyof FieldEventListenerMap\n}\n\nexport { FieldAccessor }\n"],"names":[],"mappings":";;;AASA,MAAM,cAA0E;AAAA,EAC/E,YACkB,OACA,YACD,WACA,OACA,eACA,cACA,QACA,uBACC,UACD,aACA,QACf;AAXgB,SAAA,QAAA;AACA,SAAA,aAAA;AACD,SAAA,YAAA;AACA,SAAA,QAAA;AACA,SAAA,gBAAA;AACA,SAAA,eAAA;AACA,SAAA,SAAA;AACA,SAAA,wBAAA;AACC,SAAA,WAAA;AACD,SAAA,cAAA;AACA,SAAA,SAAA;AAAA,EACd;AAAA,EAEI,SAAS,OAAiD;AACzD,WAAA,KAAK,WAAW,SAAS,KAAK,OAAO,cAAc,eAAe,KAAK,CAAC;AAAA,EAChF;AAAA,EAEO,cAAoB;AACrB,SAAA,WAAW,YAAY,KAAK,KAAK;AAAA,EACvC;AAAA,EAEO,iBACN,OACA,UACa;AACb,WAAO,KAAK,WAAW,iBAAiB,KAAK,OAAO,OAAO,QAAQ;AAAA,EACpE;AAAA,EAEO,YAAY,UAAwB,SAA6C;AACvF,SAAK,WAAW,YAAY,KAAK,OAAO,UAAU,OAAO;AAAA,EAC1D;AAAA,EAEO,SAAS,WAAmC;AAClD,WAAO,KAAK,UAAU;AAAA,EACvB;AAAA,EAEO,YAAY,OAAe;AACjC,WAAO,KAAK,UAAU,IAAI,KAAK,KAAK;AAAA,EACrC;AAAA,MAEW,YAAY;AACf,WAAA,KAAK,YAAY,cAAc,SAAS;AAAA,EAChD;AAAA,MAEW,gBAAgB;AACtB,QAAA,KAAK,iBAAiB,QAAW;AACpC,aAAO,KAAK;AAAA,IACb;AACA,WAAO,KAAK,UAAU,OAAO,KAAK,eAAe,KAAK;AAAA,EACvD;AAAA,MAIW,aAAkC;AACrC,WAAA,IAAI,oBAAoB,KAAK,WAAkD;AAAA,EACvF;AAAA,MAEW,SAA0B;AAC7B,WAAA,IAAI,gBAAgB,KAAK,WAAkD;AAAA,EACnF;AACD;AACA,AAAA,EAAU,mBAAV;AACc,iBAAY,YAAA;AAAA,GADhB,iBAAA,iBAAA,CAAA,EAAA;;"}
@@ -43,10 +43,10 @@ class AccessorErrorManager {
43
43
  this.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE);
44
44
  });
45
45
  }
46
- replaceErrors(data) {
46
+ replaceErrors(data, operations) {
47
47
  this.eventManager.syncOperation(() => {
48
48
  this.clearErrors();
49
- const preprocessor = new ErrorsPreprocessor(data);
49
+ const preprocessor = new ErrorsPreprocessor(data, operations);
50
50
  const errorTreeRoot = preprocessor.preprocess();
51
51
  this.setRootStateErrors(errorTreeRoot);
52
52
  this.dumpErrorData(data);
@@ -116,6 +116,9 @@ class AccessorErrorManager {
116
116
  return;
117
117
  }
118
118
  for (const [childKey, child] of errors.children) {
119
+ if (typeof childKey !== "string") {
120
+ continue;
121
+ }
119
122
  if (child.nodeType === "leaf") {
120
123
  const fieldState = state.children.get(childKey);
121
124
  if (fieldState?.type === "field") {
@@ -1 +1 @@
1
- {"version":3,"file":"AccessorErrorManager.js","sources":["../../../src/core/AccessorErrorManager.ts"],"sourcesContent":["import { ErrorAccessor } from '../accessors'\nimport type { ExecutionError, MutationDataResponse, ValidationError } from '../accessorTree'\nimport { ErrorsPreprocessor } from './ErrorsPreprocessor'\nimport { EventManager } from './EventManager'\nimport { EntityListState, EntityRealmState, getEntityMarker, StateNode } from './state'\nimport type { TreeStore } from './TreeStore'\n\nexport class AccessorErrorManager {\n\tprivate errorsByState: Map<StateNode, ErrorAccessor.ErrorsById> = new Map()\n\n\tprivate getNewErrorId = (() => {\n\t\tlet errorId = 1\n\n\t\treturn () => errorId++\n\t})()\n\n\tpublic constructor(private readonly eventManager: EventManager, private readonly treeStore: TreeStore) {}\n\n\tpublic hasErrors() {\n\t\treturn !!this.errorsByState.size\n\t}\n\n\tpublic getErrors(): ErrorAccessor.Error[] {\n\t\treturn Array.from(this.errorsByState.values(), it => Array.from(it.values())).flat()\n\t}\n\n\tpublic clearErrors() {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tfor (const [stateNode] of this.errorsByState) {\n\t\t\t\tstateNode.errors = undefined\n\t\t\t\tthis.eventManager.registerJustUpdated(stateNode, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t}\n\t\t\tthis.errorsByState.clear()\n\t\t})\n\t}\n\n\tpublic clearErrorsByState(state: StateNode): void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tif (!this.errorsByState.has(state)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.errorsByState.delete(state)\n\t\t\tstate.errors = undefined\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t})\n\t}\n\n\tpublic replaceErrors(data: MutationDataResponse) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.clearErrors()\n\n\t\t\tconst preprocessor = new ErrorsPreprocessor(data)\n\t\t\tconst errorTreeRoot = preprocessor.preprocess()\n\n\t\t\tthis.setRootStateErrors(errorTreeRoot)\n\n\t\t\tthis.dumpErrorData(data)\n\t\t})\n\t}\n\n\tpublic addError(state: StateNode, error: ErrorAccessor.Error): () => void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tconst errorId = this.getNewErrorId()\n\n\t\t\tlet errorsById: ErrorAccessor.ErrorsById | undefined = this.errorsByState.get(state)\n\t\t\tif (errorsById === undefined) {\n\t\t\t\tthis.errorsByState.set(state, (errorsById = new Map()))\n\t\t\t}\n\t\t\terrorsById.set(errorId, error)\n\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\n\t\t\treturn () =>\n\t\t\t\tthis.eventManager.syncOperation(() => {\n\t\t\t\t\tconst errorsById = this.errorsByState.get(state)\n\t\t\t\t\tif (errorsById === undefined) {\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\terrorsById.delete(errorId)\n\t\t\t\t\tif (errorsById.size) {\n\t\t\t\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstate.errors = undefined\n\t\t\t\t\t\tthis.errorsByState.delete(state)\n\t\t\t\t\t}\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t})\n\t\t})\n\t}\n\n\tprivate addSeveralErrors(state: StateNode, errors: ErrorsPreprocessor.BaseErrorNode) {\n\t\tif (errors.validation) {\n\t\t\tfor (const error of errors.validation) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t\tif (errors.execution) {\n\t\t\tfor (const error of errors.execution) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setRootStateErrors(errorTreeRoot: ErrorsPreprocessor.ErrorTreeRoot) {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [subTreePlaceholder, rootError] of errorTreeRoot) {\n\t\t\t\tconst rootState = rootStates.get(subTreePlaceholder)\n\n\t\t\t\tif (!rootState) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (rootState.type) {\n\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\tthis.setEntityStateErrors(rootState, rootError)\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\tthis.setEntityListStateErrors(rootState, rootError)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityStateErrors(\n\t\tstate: EntityRealmState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, child] of errors.children) {\n\t\t\tif (child.nodeType === 'leaf') {\n\t\t\t\tconst fieldState = state.children.get(childKey)\n\n\t\t\t\tif (fieldState?.type === 'field') {\n\t\t\t\t\tthis.addSeveralErrors(fieldState, child)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Deliberately letting flow get here as well. Leaf errors *CAN* refer to relations as well.\n\n\t\t\tconst fields = getEntityMarker(state).fields\n\t\t\tconst placeholders = fields.placeholders.get(childKey)\n\t\t\tif (placeholders === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst normalizedPlaceholders = typeof placeholders === 'string' ? new Set([placeholders]) : placeholders\n\n\t\t\tfor (const normalizedPlaceholder of normalizedPlaceholders) {\n\t\t\t\tconst fieldState = state.children.get(normalizedPlaceholder)\n\t\t\t\tif (fieldState === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (fieldState.type) {\n\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\t\tthis.setEntityStateErrors(fieldState, child)\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\tthis.setEntityListStateErrors(fieldState, child)\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityListStateErrors(\n\t\tstate: EntityListState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, childError] of errors.children) {\n\t\t\tlet childState = state.children.get(childKey)\n\n\t\t\tif (childState === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (childState.type === 'entityRealmStub') {\n\t\t\t\tchildState.getAccessor() // Force init\n\t\t\t\tchildState = state.children.get(childKey)!\n\t\t\t}\n\n\t\t\tif (childError.nodeType === 'iNode') {\n\t\t\t\tthis.setEntityStateErrors(childState as EntityRealmState, childError)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate dumpErrorData(data: MutationDataResponse) {\n\t\t// TODO this is just temporary\n\t\tfor (const subTreePlaceholder in data) {\n\t\t\tconst treeDatum = data[subTreePlaceholder]\n\t\t\tconst executionErrors: Array<ExecutionError | ValidationError> = treeDatum.errors\n\t\t\tconst allErrors = treeDatum?.validation?.errors\n\t\t\t\t? executionErrors.concat(treeDatum.validation.errors)\n\t\t\t\t: executionErrors\n\t\t\tconst normalizedErrors = allErrors.map((error: ExecutionError | ValidationError) => {\n\t\t\t\treturn {\n\t\t\t\t\tpath: error.path\n\t\t\t\t\t\t.map(pathPart => {\n\t\t\t\t\t\t\tif (pathPart.__typename === '_FieldPathFragment') {\n\t\t\t\t\t\t\t\treturn pathPart.field\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (pathPart.alias) {\n\t\t\t\t\t\t\t\treturn `#${pathPart.index}(${pathPart.alias})`\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn pathPart.index\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.join('.'),\n\t\t\t\t\ttype: 'type' in error ? error.type : undefined,\n\t\t\t\t\tmessage: typeof error.message === 'string' ? error.message : error.message?.text,\n\t\t\t\t}\n\t\t\t})\n\t\t\tif (Object.keys(normalizedErrors).length) {\n\t\t\t\tconsole.table(normalizedErrors)\n\t\t\t}\n\t\t\tif (treeDatum.errorMessage) {\n\t\t\t\tconsole.error(treeDatum.errorMessage)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;AAOO,MAAM,qBAAqB;AAAA,EAS1B,YAA6B,cAA6C,WAAsB;AAR/F,6DAA8D;AAE9D,yCAAuB,OAAA;AAC9B,UAAI,UAAU;AAEd,aAAO,MAAM;AAAA,IAAA;AAGsB,SAAA,eAAA;AAA6C,SAAA,YAAA;AAAA,EAAuB;AAAA,EAEjG,YAAY;AACX,WAAA,CAAC,CAAC,KAAK,cAAc;AAAA,EAC7B;AAAA,EAEO,YAAmC;AACzC,WAAO,MAAM,KAAK,KAAK,cAAc,OAAU,GAAA,CAAA,OAAM,MAAM,KAAK,GAAG,OAAQ,CAAA,CAAC,EAAE,KAAK;AAAA,EACpF;AAAA,EAEO,cAAc;AACf,SAAA,aAAa,cAAc,MAAM;AAC1B,i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,SAAS;AAAA,YACvC;AACA,mBAAO,SAAS;AAAA,UAAA,CAChB,EACA,KAAK,GAAG;AAAA,UACV,MAAM,UAAU,QAAQ,MAAM,OAAO;AAAA,UACrC,SAAS,OAAO,MAAM,YAAY,WAAW,MAAM,UAAU,MAAM,SAAS;AAAA,QAAA;AAAA,MAC7E,CACA;AACD,UAAI,OAAO,KAAK,gBAAgB,EAAE,QAAQ;AACzC,gBAAQ,MAAM,gBAAgB;AAAA,MAC/B;AACA,UAAI,UAAU,cAAc;AACnB,gBAAA,MAAM,UAAU,YAAY;AAAA,MACrC;AAAA,IACD;AAAA,EACD;AACD;;"}
1
+ {"version":3,"file":"AccessorErrorManager.js","sources":["../../../src/core/AccessorErrorManager.ts"],"sourcesContent":["import { ErrorAccessor } from '../accessors'\nimport type { ExecutionError, MutationDataResponse, ValidationError } from '../accessorTree'\nimport { ErrorsPreprocessor } from './ErrorsPreprocessor'\nimport { EventManager } from './EventManager'\nimport { EntityListState, EntityRealmState, getEntityMarker, StateNode } from './state'\nimport type { TreeStore } from './TreeStore'\nimport { SubMutationOperation } from './MutationGenerator'\n\nexport class AccessorErrorManager {\n\tprivate errorsByState: Map<StateNode, ErrorAccessor.ErrorsById> = new Map()\n\n\tprivate getNewErrorId = (() => {\n\t\tlet errorId = 1\n\n\t\treturn () => errorId++\n\t})()\n\n\tpublic constructor(private readonly eventManager: EventManager, private readonly treeStore: TreeStore) {}\n\n\tpublic hasErrors() {\n\t\treturn !!this.errorsByState.size\n\t}\n\n\tpublic getErrors(): ErrorAccessor.Error[] {\n\t\treturn Array.from(this.errorsByState.values(), it => Array.from(it.values())).flat()\n\t}\n\n\tpublic clearErrors() {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tfor (const [stateNode] of this.errorsByState) {\n\t\t\t\tstateNode.errors = undefined\n\t\t\t\tthis.eventManager.registerJustUpdated(stateNode, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t}\n\t\t\tthis.errorsByState.clear()\n\t\t})\n\t}\n\n\tpublic clearErrorsByState(state: StateNode): void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tif (!this.errorsByState.has(state)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.errorsByState.delete(state)\n\t\t\tstate.errors = undefined\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t})\n\t}\n\n\tpublic replaceErrors(data: MutationDataResponse, operations: SubMutationOperation[]) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.clearErrors()\n\n\t\t\tconst preprocessor = new ErrorsPreprocessor(data, operations)\n\t\t\tconst errorTreeRoot = preprocessor.preprocess()\n\n\t\t\tthis.setRootStateErrors(errorTreeRoot)\n\n\t\t\tthis.dumpErrorData(data)\n\t\t})\n\t}\n\n\tpublic addError(state: StateNode, error: ErrorAccessor.Error): () => void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tconst errorId = this.getNewErrorId()\n\n\t\t\tlet errorsById: ErrorAccessor.ErrorsById | undefined = this.errorsByState.get(state)\n\t\t\tif (errorsById === undefined) {\n\t\t\t\tthis.errorsByState.set(state, (errorsById = new Map()))\n\t\t\t}\n\t\t\terrorsById.set(errorId, error)\n\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\n\t\t\treturn () =>\n\t\t\t\tthis.eventManager.syncOperation(() => {\n\t\t\t\t\tconst errorsById = this.errorsByState.get(state)\n\t\t\t\t\tif (errorsById === undefined) {\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\terrorsById.delete(errorId)\n\t\t\t\t\tif (errorsById.size) {\n\t\t\t\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstate.errors = undefined\n\t\t\t\t\t\tthis.errorsByState.delete(state)\n\t\t\t\t\t}\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t})\n\t\t})\n\t}\n\n\tprivate addSeveralErrors(state: StateNode, errors: ErrorsPreprocessor.BaseErrorNode) {\n\t\tif (errors.validation) {\n\t\t\tfor (const error of errors.validation) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t\tif (errors.execution) {\n\t\t\tfor (const error of errors.execution) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setRootStateErrors(errorTreeRoot: ErrorsPreprocessor.ErrorTreeRoot) {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [subTreePlaceholder, rootError] of errorTreeRoot) {\n\t\t\t\tconst rootState = rootStates.get(subTreePlaceholder)\n\n\t\t\t\tif (!rootState) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (rootState.type) {\n\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\tthis.setEntityStateErrors(rootState, rootError)\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\tthis.setEntityListStateErrors(rootState, rootError)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityStateErrors(\n\t\tstate: EntityRealmState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, child] of errors.children) {\n\t\t\tif (typeof childKey !== 'string') {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (child.nodeType === 'leaf') {\n\t\t\t\tconst fieldState = state.children.get(childKey)\n\n\t\t\t\tif (fieldState?.type === 'field') {\n\t\t\t\t\tthis.addSeveralErrors(fieldState, child)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Deliberately letting flow get here as well. Leaf errors *CAN* refer to relations as well.\n\n\t\t\tconst fields = getEntityMarker(state).fields\n\t\t\tconst placeholders = fields.placeholders.get(childKey)\n\t\t\tif (placeholders === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst normalizedPlaceholders = typeof placeholders === 'string' ? new Set([placeholders]) : placeholders\n\n\t\t\tfor (const normalizedPlaceholder of normalizedPlaceholders) {\n\t\t\t\tconst fieldState = state.children.get(normalizedPlaceholder)\n\t\t\t\tif (fieldState === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (fieldState.type) {\n\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\t\tthis.setEntityStateErrors(fieldState, child)\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\tthis.setEntityListStateErrors(fieldState, child)\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityListStateErrors(\n\t\tstate: EntityListState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, childError] of errors.children) {\n\t\t\tlet childState = state.children.get(childKey)\n\n\t\t\tif (childState === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (childState.type === 'entityRealmStub') {\n\t\t\t\tchildState.getAccessor() // Force init\n\t\t\t\tchildState = state.children.get(childKey)!\n\t\t\t}\n\n\t\t\tif (childError.nodeType === 'iNode') {\n\t\t\t\tthis.setEntityStateErrors(childState as EntityRealmState, childError)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate dumpErrorData(data: MutationDataResponse) {\n\t\t// TODO this is just temporary\n\t\tfor (const subTreePlaceholder in data) {\n\t\t\tconst treeDatum = data[subTreePlaceholder]\n\t\t\tconst executionErrors: Array<ExecutionError | ValidationError> = treeDatum.errors\n\t\t\tconst allErrors = treeDatum?.validation?.errors\n\t\t\t\t? executionErrors.concat(treeDatum.validation.errors)\n\t\t\t\t: executionErrors\n\t\t\tconst normalizedErrors = allErrors.map((error: ExecutionError | ValidationError) => {\n\t\t\t\treturn {\n\t\t\t\t\tpath: error.path\n\t\t\t\t\t\t.map(pathPart => {\n\t\t\t\t\t\t\tif (pathPart.__typename === '_FieldPathFragment') {\n\t\t\t\t\t\t\t\treturn pathPart.field\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (pathPart.alias) {\n\t\t\t\t\t\t\t\treturn `#${pathPart.index}(${pathPart.alias})`\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn pathPart.index\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.join('.'),\n\t\t\t\t\ttype: 'type' in error ? error.type : undefined,\n\t\t\t\t\tmessage: typeof error.message === 'string' ? error.message : error.message?.text,\n\t\t\t\t}\n\t\t\t})\n\t\t\tif (Object.keys(normalizedErrors).length) {\n\t\t\t\tconsole.table(normalizedErrors)\n\t\t\t}\n\t\t\tif (treeDatum.errorMessage) {\n\t\t\t\tconsole.error(treeDatum.errorMessage)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;AAQO,MAAM,qBAAqB;AAAA,EAS1B,YAA6B,cAA6C,WAAsB;AAR/F,6DAA8D;AAE9D,yCAAuB,OAAA;AAC9B,UAAI,UAAU;AAEd,aAAO,MAAM;AAAA,IAAA;AAGsB,SAAA,eAAA;AAA6C,SAAA,YAAA;AAAA,EAAuB;AAAA,EAEjG,YAAY;AACX,WAAA,CAAC,CAAC,KAAK,cAAc;AAAA,EAC7B;AAAA,EAEO,YAAmC;AACzC,WAAO,MAAM,KAAK,KAAK,cAAc,OAAU,GAAA,CAAA,OAAM,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C5E,eAAA;AAAA,UACN,MAAM,MAAM,KACV,IAAI,CAAY,aAAA;AACZ,gBAAA,SAAS,eAAe,sBAAsB;AACjD,qBAAO,SAAS;AAAA,YACjB;AACA,gBAAI,SAAS,OAAO;AACZ,qBAAA,IAAI,SAAS,SAAS,SAAS;AAAA,YACvC;AACA,mBAAO,SAAS;AAAA,UAAA,CAChB,EACA,KAAK,GAAG;AAAA,UACV,MAAM,UAAU,QAAQ,MAAM,OAAO;AAAA,UACrC,SAAS,OAAO,MAAM,YAAY,WAAW,MAAM,UAAU,MAAM,SAAS;AAAA,QAAA;AAAA,MAC7E,CACA;AACD,UAAI,OAAO,KAAK,gBAAgB,EAAE,QAAQ;AACzC,gBAAQ,MAAM,gBAAgB;AAAA,MAC/B;AACA,UAAI,UAAU,cAAc;AACnB,gBAAA,MAAM,UAAU,YAAY;AAAA,MACrC;AAAA,IACD;AAAA,EACD;AACD;;"}
@@ -25,8 +25,7 @@ __publicField(Config, "defaultConfig", {
25
25
  beforePersistSettleLimit: 20,
26
26
  beforeUpdateSettleLimit: 20,
27
27
  persistSuccessSettleLimit: 20,
28
- maxPersistAttempts: 5,
29
- maxSchemaLoadAttempts: 3
28
+ maxPersistAttempts: 5
30
29
  });
31
30
  export { Config };
32
31
  //# sourceMappingURL=Config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Config.js","sources":["../../../src/core/Config.ts"],"sourcesContent":["import type { BindingConfig } from '../accessors'\n\nexport class Config {\n\tprivate static defaultConfig: BindingConfig = {\n\t\tbeforePersistSettleLimit: 20,\n\t\tbeforeUpdateSettleLimit: 20,\n\t\tpersistSuccessSettleLimit: 20,\n\t\tmaxPersistAttempts: 5,\n\t\tmaxSchemaLoadAttempts: 3,\n\t}\n\n\tprivate readonly config: BindingConfig\n\n\tpublic constructor(config: Partial<BindingConfig> = {}) {\n\t\tthis.config = {\n\t\t\t...Config.defaultConfig,\n\t\t\t...config,\n\t\t}\n\t}\n\n\tpublic getValue<Name extends keyof BindingConfig>(name: Name): BindingConfig[Name] {\n\t\treturn this.config[name]\n\t}\n\n\tpublic setValue<Name extends keyof BindingConfig>(name: Name, value: BindingConfig[Name]): this {\n\t\tthis.config[name] = value\n\t\treturn this\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAEO,sBAAa;AAAA,EAWZ,YAAY,SAAiC,IAAI;AAFvC;AAGhB,SAAK,SAAS;AAAA,SACV,QAAO;AAAA,SACP;AAAA,IAAA;AAAA,EAEL;AAAA,EAEO,SAA2C,MAAiC;AAClF,WAAO,KAAK,OAAO;AAAA,EACpB;AAAA,EAEO,SAA2C,MAAY,OAAkC;AAC/F,SAAK,OAAO,QAAQ;AACb,WAAA;AAAA,EACR;AACD;AA1BO;AACS,cADT,QACS,iBAA+B;AAAA,EAC7C,0BAA0B;AAAA,EAC1B,yBAAyB;AAAA,EACzB,2BAA2B;AAAA,EAC3B,oBAAoB;AAAA,EACpB,uBAAuB;AAAA;;"}
1
+ {"version":3,"file":"Config.js","sources":["../../../src/core/Config.ts"],"sourcesContent":["import type { BindingConfig } from '../accessors'\n\nexport class Config {\n\tprivate static defaultConfig: BindingConfig = {\n\t\tbeforePersistSettleLimit: 20,\n\t\tbeforeUpdateSettleLimit: 20,\n\t\tpersistSuccessSettleLimit: 20,\n\t\tmaxPersistAttempts: 5,\n\t}\n\n\tprivate readonly config: BindingConfig\n\n\tpublic constructor(config: Partial<BindingConfig> = {}) {\n\t\tthis.config = {\n\t\t\t...Config.defaultConfig,\n\t\t\t...config,\n\t\t}\n\t}\n\n\tpublic getValue<Name extends keyof BindingConfig>(name: Name): BindingConfig[Name] {\n\t\treturn this.config[name]\n\t}\n\n\tpublic setValue<Name extends keyof BindingConfig>(name: Name, value: BindingConfig[Name]): this {\n\t\tthis.config[name] = value\n\t\treturn this\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAEO,sBAAa;AAAA,EAUZ,YAAY,SAAiC,IAAI;AAFvC;AAGhB,SAAK,SAAS;AAAA,SACV,QAAO;AAAA,SACP;AAAA,IAAA;AAAA,EAEL;AAAA,EAEO,SAA2C,MAAiC;AAClF,WAAO,KAAK,OAAO;AAAA,EACpB;AAAA,EAEO,SAA2C,MAAY,OAAkC;AAC/F,SAAK,OAAO,QAAQ;AACb,WAAA;AAAA,EACR;AACD;AAzBO;AACS,cADT,QACS,iBAA+B;AAAA,EAC7C,0BAA0B;AAAA,EAC1B,yBAAyB;AAAA,EACzB,2BAA2B;AAAA,EAC3B,oBAAoB;AAAA;;"}
@@ -15,17 +15,15 @@ import { QueryGenerator } from "./QueryGenerator.js";
15
15
  import { StateInitializer } from "./StateInitializer.js";
16
16
  import { TreeAugmenter } from "./TreeAugmenter.js";
17
17
  import { TreeFilterGenerator } from "./TreeFilterGenerator.js";
18
- import { TreeStore } from "./TreeStore.js";
19
18
  import { createBatchUpdatesOptions } from "./factories/createBatchUpdatesOptions.js";
20
19
  import { TreeRootAccessor } from "../accessors/TreeRootAccessor.js";
21
20
  import { getCombinedSignal } from "./utils/getCombinedSignal.js";
22
21
  import { metadataToRequestError } from "../accessorTree/metadataToRequestError.js";
23
- import { SchemaLoader } from "./schema/SchemaLoader.js";
24
22
  import { StateIterator } from "./state/StateIterator.js";
25
23
  import { assertNever } from "../utils/assertNever.js";
26
24
  import { generateEnumerabilityPreventingEntropy } from "../utils/generateEnumerabilityPreventingEntropy.js";
27
25
  const _DataBinding = class {
28
- constructor(contentApiClient, systemApiClient, tenantApiClient, environment, onUpdate, onError, onPersistSuccess) {
26
+ constructor(contentApiClient, systemApiClient, tenantApiClient, treeStore, environment, onUpdate, onError, onPersistSuccess) {
29
27
  __publicField(this, "accessorErrorManager");
30
28
  __publicField(this, "batchUpdatesOptions");
31
29
  __publicField(this, "asyncBatchUpdatesOptions");
@@ -35,20 +33,19 @@ const _DataBinding = class {
35
33
  __publicField(this, "eventManager");
36
34
  __publicField(this, "stateInitializer");
37
35
  __publicField(this, "treeAugmenter");
38
- __publicField(this, "treeStore");
39
36
  __publicField(this, "resolvedOnUpdate", ({ isMutating }) => {
40
- this.onUpdate(new TreeRootAccessor(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations));
37
+ this.onUpdate(new TreeRootAccessor(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations), this);
41
38
  });
42
39
  __publicField(this, "pendingExtensions", /* @__PURE__ */ new Set());
43
40
  this.contentApiClient = contentApiClient;
44
41
  this.systemApiClient = systemApiClient;
45
42
  this.tenantApiClient = tenantApiClient;
43
+ this.treeStore = treeStore;
46
44
  this.environment = environment;
47
45
  this.onUpdate = onUpdate;
48
46
  this.onError = onError;
49
47
  this.onPersistSuccess = onPersistSuccess;
50
48
  this.config = new Config();
51
- this.treeStore = new TreeStore();
52
49
  this.batchUpdatesOptions = createBatchUpdatesOptions(environment, this.treeStore);
53
50
  this.asyncBatchUpdatesOptions = {
54
51
  ...this.batchUpdatesOptions,
@@ -59,7 +56,7 @@ const _DataBinding = class {
59
56
  this.dirtinessTracker = new DirtinessTracker();
60
57
  this.eventManager = new EventManager(this.asyncBatchUpdatesOptions, this.batchUpdatesOptions, this.config, this.dirtinessTracker, this.resolvedOnUpdate, this.treeStore);
61
58
  this.accessorErrorManager = new AccessorErrorManager(this.eventManager, this.treeStore);
62
- this.stateInitializer = new StateInitializer(this.accessorErrorManager, this.batchUpdatesOptions, this.config, this.eventManager, this.treeStore);
59
+ this.stateInitializer = new StateInitializer(this.accessorErrorManager, this.batchUpdatesOptions, this.eventManager, this.treeStore);
63
60
  this.treeAugmenter = new TreeAugmenter(this.eventManager, this.stateInitializer, this.treeStore);
64
61
  this.bindingOperations = Object.freeze({
65
62
  ...this.asyncBatchUpdatesOptions,
@@ -101,8 +98,8 @@ const _DataBinding = class {
101
98
  };
102
99
  }
103
100
  const generator = new MutationGenerator(this.treeStore);
104
- const mutation = generator.getPersistMutation();
105
- if (mutation === void 0) {
101
+ const mutationResult = generator.getPersistMutation();
102
+ if (mutationResult === void 0) {
106
103
  this.dirtinessTracker.reset();
107
104
  const persistSuccessOptions = {
108
105
  ...this.bindingOperations,
@@ -114,24 +111,26 @@ const _DataBinding = class {
114
111
  type: "nothingToPersist"
115
112
  };
116
113
  }
117
- const mutationResponse = await this.contentApiClient.sendRequest(mutation, {
114
+ const { query, operations } = mutationResult;
115
+ const mutationResponse = await this.contentApiClient.sendRequest(query, {
118
116
  signal
119
117
  });
120
118
  if (mutationResponse.errors !== void 0 && mutationResponse.errors.length > 0) {
121
119
  this.onError({
122
120
  type: "gqlError",
123
- query: mutation,
121
+ query,
124
122
  errors: mutationResponse.errors
125
- });
123
+ }, this);
126
124
  }
127
- const mutationData = mutationResponse.data?.transaction ?? {};
128
- const aliases = Object.keys(mutationData);
129
- if (!mutationResponse.data) {
125
+ if (!mutationResponse.data?.transaction) {
130
126
  throw {
131
- errors: mutationData.errors,
127
+ errors: [],
132
128
  type: "invalidResponse"
133
129
  };
134
- } else if (aliases.every((item) => mutationData[item].ok)) {
130
+ }
131
+ const { __typename, ok, errorMessage, ...mutationData } = mutationResponse.data.transaction;
132
+ const aliases = Object.keys(mutationData);
133
+ if (aliases.every((item) => mutationData[item].ok)) {
135
134
  const persistedEntityIds = aliases.map((alias) => mutationData[alias].node?.id).filter((id) => id !== void 0);
136
135
  const result = {
137
136
  type: "justSuccess",
@@ -143,7 +142,7 @@ const _DataBinding = class {
143
142
  this.treeAugmenter.updatePersistedData(Object.fromEntries(Object.entries(mutationData).map(([placeholderName, subTreeResponse]) => [
144
143
  placeholderName,
145
144
  subTreeResponse.node
146
- ])));
145
+ ])), operations);
147
146
  const persistSuccessOptions = {
148
147
  ...this.bindingOperations,
149
148
  successType: result.type
@@ -158,13 +157,16 @@ const _DataBinding = class {
158
157
  ...result,
159
158
  afterPersistError: e
160
159
  };
161
- this.onPersistSuccess(resultWithError);
160
+ this.onPersistSuccess(resultWithError, this);
162
161
  return resultWithError;
163
162
  }
164
- this.onPersistSuccess(result);
163
+ this.onPersistSuccess(result, this);
165
164
  return result;
166
165
  } else {
167
- this.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(mutationData));
166
+ if (errorMessage) {
167
+ console.error(errorMessage);
168
+ }
169
+ this.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(mutationData, operations));
168
170
  await this.eventManager.triggerOnPersistError(persistErrorOptions);
169
171
  await onPersistError?.(persistErrorOptions);
170
172
  if (shouldTryAgain) {
@@ -190,9 +192,7 @@ const _DataBinding = class {
190
192
  if (options.signal?.aborted) {
191
193
  return Promise.reject(DataBindingExtendAborted);
192
194
  }
193
- const schema = await this.getOrLoadSchema();
194
- this.treeStore.setSchema(schema);
195
- const markerTreeRoot = new MarkerTreeGenerator(newFragment, (options.environment ?? this.environment).withSchema(schema)).generate();
195
+ const markerTreeRoot = new MarkerTreeGenerator(newFragment, options.environment ?? this.environment).generate();
196
196
  if (this.treeStore.effectivelyHasTreeRoot(markerTreeRoot)) {
197
197
  return this.eventManager.syncOperation(() => {
198
198
  const newTreeRootId = this.getNewTreeRootId();
@@ -242,7 +242,7 @@ const _DataBinding = class {
242
242
  return;
243
243
  }
244
244
  this.eventManager.syncOperation(() => {
245
- this.treeAugmenter.extendPersistedData(aggregatePersistedData?.data ?? {});
245
+ this.treeAugmenter.extendPersistedData(aggregatePersistedData?.data ?? {}, aggregateMarkerTreeRoot);
246
246
  for (const extension of pendingExtensions) {
247
247
  this.treeAugmenter.extendTreeStates(extension.newTreeRootId, extension.markerTreeRoot);
248
248
  extension.resolve(extension.newTreeRootId);
@@ -261,14 +261,14 @@ const _DataBinding = class {
261
261
  if (metadata.name === "AbortError") {
262
262
  return;
263
263
  }
264
- this.onError(metadataToRequestError(metadata));
264
+ this.onError(metadataToRequestError(metadata), this);
265
265
  }
266
266
  if (queryResponse && queryResponse.errors !== void 0 && queryResponse.errors.length > 0) {
267
267
  this.onError({
268
268
  type: "gqlError",
269
269
  query: query ?? "unknown query",
270
270
  errors: queryResponse.errors
271
- });
271
+ }, this);
272
272
  }
273
273
  return queryResponse;
274
274
  }
@@ -309,24 +309,11 @@ const _DataBinding = class {
309
309
  }
310
310
  });
311
311
  }
312
- getOrLoadSchema() {
313
- const existing = _DataBinding.schemaLoadCache.get(this.contentApiClient.apiUrl);
314
- if (existing !== void 0) {
315
- return existing;
316
- }
317
- const schemaPromise = SchemaLoader.loadSchema(this.contentApiClient, this.config.getValue("maxSchemaLoadAttempts"));
318
- schemaPromise.then((schema) => {
319
- _DataBinding.schemaLoadCache.set(this.contentApiClient.apiUrl, schema);
320
- });
321
- _DataBinding.schemaLoadCache.set(this.contentApiClient.apiUrl, schemaPromise);
322
- return schemaPromise;
323
- }
324
312
  getNewTreeRootId() {
325
313
  return this.treeStore.markerTrees.size === 0 ? void 0 : `${generateEnumerabilityPreventingEntropy()}-${_DataBinding.getNextTreeRootIdSeed()}`;
326
314
  }
327
315
  };
328
316
  let DataBinding = _DataBinding;
329
- __publicField(DataBinding, "schemaLoadCache", /* @__PURE__ */ new Map());
330
317
  __publicField(DataBinding, "getNextTreeRootIdSeed", (() => {
331
318
  let seed = 1;
332
319
  return () => seed++;