@contember/binding 1.1.0-rc.5 → 1.2.0-alpha.0

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 (268) hide show
  1. package/dist/development/accessorPropagation/AccessorProvider.js +2 -17
  2. package/dist/development/accessorPropagation/AccessorProvider.js.map +1 -1
  3. package/dist/development/accessorPropagation/BindingOperationsProvider.js +2 -10
  4. package/dist/development/accessorPropagation/BindingOperationsProvider.js.map +1 -1
  5. package/dist/development/accessorPropagation/EntityKeyProvider.js +2 -10
  6. package/dist/development/accessorPropagation/EntityKeyProvider.js.map +1 -1
  7. package/dist/development/accessorPropagation/EnvironmentContext.js +23 -56
  8. package/dist/development/accessorPropagation/EnvironmentContext.js.map +1 -1
  9. package/dist/development/accessorPropagation/TreeRootIdProvider.js +2 -10
  10. package/dist/development/accessorPropagation/TreeRootIdProvider.js.map +1 -1
  11. package/dist/development/accessorPropagation/useDesugaredRelativeEntityList.js +1 -0
  12. package/dist/development/accessorPropagation/useDesugaredRelativeEntityList.js.map +1 -1
  13. package/dist/development/accessorPropagation/useDesugaredRelativeSingleEntity.js +1 -0
  14. package/dist/development/accessorPropagation/useDesugaredRelativeSingleEntity.js.map +1 -1
  15. package/dist/development/accessorPropagation/useDesugaredRelativeSingleField.js +1 -0
  16. package/dist/development/accessorPropagation/useDesugaredRelativeSingleField.js.map +1 -1
  17. package/dist/development/accessorPropagation/useEntity.js.map +1 -1
  18. package/dist/development/accessorPropagation/useEntityList.js.map +1 -1
  19. package/dist/development/accessorPropagation/useEntityListSubTree.js.map +1 -1
  20. package/dist/development/accessorPropagation/useEntitySubTree.js.map +1 -1
  21. package/dist/development/accessorPropagation/useField.js.map +1 -1
  22. package/dist/development/accessorPropagation/useGetEntityListSubTree.js.map +1 -1
  23. package/dist/development/accessorPropagation/useGetEntitySubTree.js.map +1 -1
  24. package/dist/development/accessorSorting/SetOrderFieldOnCreate.js +62 -91
  25. package/dist/development/accessorSorting/SetOrderFieldOnCreate.js.map +1 -1
  26. package/dist/development/accessorSorting/moveEntity.js.map +1 -1
  27. package/dist/development/accessorSorting/repairEntitiesOrder.js.map +1 -1
  28. package/dist/development/accessorTree/AccessorTree.js +3 -42
  29. package/dist/development/accessorTree/AccessorTree.js.map +1 -1
  30. package/dist/development/accessorTree/accessorTreeStateReducer.js.map +1 -1
  31. package/dist/development/accessors/EntityAccessor.js +15 -2
  32. package/dist/development/accessors/EntityAccessor.js.map +1 -1
  33. package/dist/development/accessors/EntityListAccessor.js +9 -0
  34. package/dist/development/accessors/EntityListAccessor.js.map +1 -1
  35. package/dist/development/accessors/FieldAccessor.js +1 -0
  36. package/dist/development/accessors/FieldAccessor.js.map +1 -1
  37. package/dist/development/accessors/TreeRootAccessor.js +3 -0
  38. package/dist/development/accessors/TreeRootAccessor.js.map +1 -1
  39. package/dist/development/core/AccessorErrorManager.js.map +1 -1
  40. package/dist/development/core/Config.js.map +1 -1
  41. package/dist/development/core/DataBinding.js +9 -0
  42. package/dist/development/core/DataBinding.js.map +1 -1
  43. package/dist/development/core/ErrorsPreprocessor.js.map +1 -1
  44. package/dist/development/core/EventManager.js +3 -27
  45. package/dist/development/core/EventManager.js.map +1 -1
  46. package/dist/development/core/MarkerComparator.js +1 -0
  47. package/dist/development/core/MarkerComparator.js.map +1 -1
  48. package/dist/development/core/MarkerMerger.js +1 -0
  49. package/dist/development/core/MarkerMerger.js.map +1 -1
  50. package/dist/development/core/MutationGenerator.js.map +1 -1
  51. package/dist/development/core/QueryGenerator.js +1 -0
  52. package/dist/development/core/QueryGenerator.js.map +1 -1
  53. package/dist/development/core/RealmKeyGenerator.js +2 -0
  54. package/dist/development/core/RealmKeyGenerator.js.map +1 -1
  55. package/dist/development/core/RequestResponseNormalizer.js.map +1 -1
  56. package/dist/development/core/StateInitializer.js +3 -0
  57. package/dist/development/core/StateInitializer.js.map +1 -1
  58. package/dist/development/core/TreeAugmenter.js +6 -1
  59. package/dist/development/core/TreeAugmenter.js.map +1 -1
  60. package/dist/development/core/TreeParameterMerger.js +26 -0
  61. package/dist/development/core/TreeParameterMerger.js.map +1 -1
  62. package/dist/development/core/TreeStore.js +2 -0
  63. package/dist/development/core/TreeStore.js.map +1 -1
  64. package/dist/development/core/exceptions/ErrorLocator.js.map +1 -1
  65. package/dist/development/core/exceptions/TreeParameterSugarer.js +2 -2
  66. package/dist/development/core/operations/EntityOperations.js +3 -1
  67. package/dist/development/core/operations/EntityOperations.js.map +1 -1
  68. package/dist/development/core/operations/FieldOperations.js +1 -21
  69. package/dist/development/core/operations/FieldOperations.js.map +1 -1
  70. package/dist/development/core/state/StateIterator.js +1 -0
  71. package/dist/development/core/state/StateIterator.js.map +1 -1
  72. package/dist/development/coreComponents/Component.js.map +1 -1
  73. package/dist/development/coreComponents/DataBindingProvider.js +10 -14
  74. package/dist/development/coreComponents/DataBindingProvider.js.map +1 -1
  75. package/dist/development/coreComponents/Entity.js +10 -15
  76. package/dist/development/coreComponents/Entity.js.map +1 -1
  77. package/dist/development/coreComponents/EntityList.js +25 -33
  78. package/dist/development/coreComponents/EntityList.js.map +1 -1
  79. package/dist/development/coreComponents/EntityListSubTree.js +29 -41
  80. package/dist/development/coreComponents/EntityListSubTree.js.map +1 -1
  81. package/dist/development/coreComponents/EntitySubTree.js +39 -51
  82. package/dist/development/coreComponents/EntitySubTree.js.map +1 -1
  83. package/dist/development/coreComponents/Field.js +20 -20
  84. package/dist/development/coreComponents/Field.js.map +1 -1
  85. package/dist/development/coreComponents/HasMany.js +18 -33
  86. package/dist/development/coreComponents/HasMany.js.map +1 -1
  87. package/dist/development/coreComponents/HasOne.js +18 -33
  88. package/dist/development/coreComponents/HasOne.js.map +1 -1
  89. package/dist/development/coreComponents/ParentEntity.js +8 -6
  90. package/dist/development/coreComponents/ParentEntity.js.map +1 -1
  91. package/dist/development/dao/Environment.js +3 -0
  92. package/dist/development/dao/Environment.js.map +1 -1
  93. package/dist/development/entityEvents/useEntityEvent.js.map +1 -1
  94. package/dist/development/fieldHelpers/helpers/TemporalFieldHelper.js +4 -1
  95. package/dist/development/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -1
  96. package/dist/development/helperComponents/DeferredSubTrees.js +67 -86
  97. package/dist/development/helperComponents/DeferredSubTrees.js.map +1 -1
  98. package/dist/development/helperComponents/EntityView.js +2 -4
  99. package/dist/development/helperComponents/EntityView.js.map +1 -1
  100. package/dist/development/helperComponents/FieldView.js +38 -36
  101. package/dist/development/helperComponents/FieldView.js.map +1 -1
  102. package/dist/development/helperComponents/If.js +40 -65
  103. package/dist/development/helperComponents/If.js.map +1 -1
  104. package/dist/development/helperComponents/StaticRender.js +6 -6
  105. package/dist/development/helperComponents/StaticRender.js.map +1 -1
  106. package/dist/development/helperComponents/SugaredField.js +3 -18
  107. package/dist/development/helperComponents/SugaredField.js.map +1 -1
  108. package/dist/development/helperComponents/helpers/FilterEvaluator.js.map +1 -1
  109. package/dist/development/helperComponents/helpers/evaluateCondition.js +1 -0
  110. package/dist/development/helperComponents/helpers/evaluateCondition.js.map +1 -1
  111. package/dist/development/markers/EntityFieldMarkersContainer.js +1 -0
  112. package/dist/development/markers/EntityFieldMarkersContainer.js.map +1 -1
  113. package/dist/development/markers/HasManyRelationMarker.js +0 -6
  114. package/dist/development/markers/HasManyRelationMarker.js.map +1 -1
  115. package/dist/development/queryLanguage/CacheStore.js.map +1 -1
  116. package/dist/development/queryLanguage/MarkerFactory.js.map +1 -1
  117. package/dist/development/queryLanguage/Parser.js +2 -3
  118. package/dist/development/queryLanguage/Parser.js.map +1 -1
  119. package/dist/development/queryLanguage/QueryLanguage.js +13 -5
  120. package/dist/development/queryLanguage/QueryLanguage.js.map +1 -1
  121. package/dist/development/structures/BijectiveIndexedMap.js +2 -0
  122. package/dist/development/structures/BijectiveIndexedMap.js.map +1 -1
  123. package/dist/development/treeParameterHelpers/wrapFilterInHasOnes.js.map +1 -1
  124. package/dist/development/treeParameters/EntityCreationParameters.js +1 -0
  125. package/dist/development/treeParameters/EntityCreationParameters.js.map +1 -1
  126. package/dist/development/utils/Hashing.js +1 -0
  127. package/dist/development/utils/Hashing.js.map +1 -1
  128. package/dist/production/accessorPropagation/AccessorProvider.js +2 -8
  129. package/dist/production/accessorPropagation/AccessorProvider.js.map +1 -1
  130. package/dist/production/accessorPropagation/BindingOperationsProvider.js +2 -5
  131. package/dist/production/accessorPropagation/BindingOperationsProvider.js.map +1 -1
  132. package/dist/production/accessorPropagation/EntityKeyProvider.js +2 -5
  133. package/dist/production/accessorPropagation/EntityKeyProvider.js.map +1 -1
  134. package/dist/production/accessorPropagation/EnvironmentContext.js +23 -43
  135. package/dist/production/accessorPropagation/EnvironmentContext.js.map +1 -1
  136. package/dist/production/accessorPropagation/TreeRootIdProvider.js +2 -5
  137. package/dist/production/accessorPropagation/TreeRootIdProvider.js.map +1 -1
  138. package/dist/production/accessorPropagation/useDesugaredRelativeEntityList.js +1 -0
  139. package/dist/production/accessorPropagation/useDesugaredRelativeEntityList.js.map +1 -1
  140. package/dist/production/accessorPropagation/useDesugaredRelativeSingleEntity.js +1 -0
  141. package/dist/production/accessorPropagation/useDesugaredRelativeSingleEntity.js.map +1 -1
  142. package/dist/production/accessorPropagation/useDesugaredRelativeSingleField.js +1 -0
  143. package/dist/production/accessorPropagation/useDesugaredRelativeSingleField.js.map +1 -1
  144. package/dist/production/accessorPropagation/useEntity.js.map +1 -1
  145. package/dist/production/accessorPropagation/useEntityList.js.map +1 -1
  146. package/dist/production/accessorPropagation/useEntityListSubTree.js.map +1 -1
  147. package/dist/production/accessorPropagation/useEntitySubTree.js.map +1 -1
  148. package/dist/production/accessorPropagation/useField.js.map +1 -1
  149. package/dist/production/accessorPropagation/useGetEntityListSubTree.js.map +1 -1
  150. package/dist/production/accessorPropagation/useGetEntitySubTree.js.map +1 -1
  151. package/dist/production/accessorSorting/SetOrderFieldOnCreate.js +62 -62
  152. package/dist/production/accessorSorting/SetOrderFieldOnCreate.js.map +1 -1
  153. package/dist/production/accessorSorting/moveEntity.js.map +1 -1
  154. package/dist/production/accessorSorting/repairEntitiesOrder.js.map +1 -1
  155. package/dist/production/accessorTree/AccessorTree.js +3 -21
  156. package/dist/production/accessorTree/AccessorTree.js.map +1 -1
  157. package/dist/production/accessorTree/accessorTreeStateReducer.js.map +1 -1
  158. package/dist/production/accessors/EntityAccessor.js +15 -2
  159. package/dist/production/accessors/EntityAccessor.js.map +1 -1
  160. package/dist/production/accessors/EntityListAccessor.js +9 -0
  161. package/dist/production/accessors/EntityListAccessor.js.map +1 -1
  162. package/dist/production/accessors/FieldAccessor.js +1 -0
  163. package/dist/production/accessors/FieldAccessor.js.map +1 -1
  164. package/dist/production/accessors/TreeRootAccessor.js +3 -0
  165. package/dist/production/accessors/TreeRootAccessor.js.map +1 -1
  166. package/dist/production/core/AccessorErrorManager.js.map +1 -1
  167. package/dist/production/core/Config.js.map +1 -1
  168. package/dist/production/core/DataBinding.js +9 -0
  169. package/dist/production/core/DataBinding.js.map +1 -1
  170. package/dist/production/core/ErrorsPreprocessor.js.map +1 -1
  171. package/dist/production/core/EventManager.js +2 -0
  172. package/dist/production/core/EventManager.js.map +1 -1
  173. package/dist/production/core/MarkerComparator.js +1 -0
  174. package/dist/production/core/MarkerComparator.js.map +1 -1
  175. package/dist/production/core/MarkerMerger.js +1 -0
  176. package/dist/production/core/MarkerMerger.js.map +1 -1
  177. package/dist/production/core/MutationGenerator.js.map +1 -1
  178. package/dist/production/core/QueryGenerator.js +1 -0
  179. package/dist/production/core/QueryGenerator.js.map +1 -1
  180. package/dist/production/core/RealmKeyGenerator.js +2 -0
  181. package/dist/production/core/RealmKeyGenerator.js.map +1 -1
  182. package/dist/production/core/RequestResponseNormalizer.js.map +1 -1
  183. package/dist/production/core/StateInitializer.js +3 -0
  184. package/dist/production/core/StateInitializer.js.map +1 -1
  185. package/dist/production/core/TreeAugmenter.js +6 -1
  186. package/dist/production/core/TreeAugmenter.js.map +1 -1
  187. package/dist/production/core/TreeParameterMerger.js +26 -0
  188. package/dist/production/core/TreeParameterMerger.js.map +1 -1
  189. package/dist/production/core/TreeStore.js +2 -0
  190. package/dist/production/core/TreeStore.js.map +1 -1
  191. package/dist/production/core/exceptions/ErrorLocator.js.map +1 -1
  192. package/dist/production/core/exceptions/TreeParameterSugarer.js +2 -2
  193. package/dist/production/core/operations/EntityOperations.js +3 -1
  194. package/dist/production/core/operations/EntityOperations.js.map +1 -1
  195. package/dist/production/core/state/StateIterator.js +1 -0
  196. package/dist/production/core/state/StateIterator.js.map +1 -1
  197. package/dist/production/coreComponents/Component.js.map +1 -1
  198. package/dist/production/coreComponents/DataBindingProvider.js +10 -9
  199. package/dist/production/coreComponents/DataBindingProvider.js.map +1 -1
  200. package/dist/production/coreComponents/Entity.js +10 -10
  201. package/dist/production/coreComponents/Entity.js.map +1 -1
  202. package/dist/production/coreComponents/EntityList.js +25 -28
  203. package/dist/production/coreComponents/EntityList.js.map +1 -1
  204. package/dist/production/coreComponents/EntityListSubTree.js +29 -28
  205. package/dist/production/coreComponents/EntityListSubTree.js.map +1 -1
  206. package/dist/production/coreComponents/EntitySubTree.js +39 -34
  207. package/dist/production/coreComponents/EntitySubTree.js.map +1 -1
  208. package/dist/production/coreComponents/Field.js +20 -20
  209. package/dist/production/coreComponents/Field.js.map +1 -1
  210. package/dist/production/coreComponents/HasMany.js +18 -20
  211. package/dist/production/coreComponents/HasMany.js.map +1 -1
  212. package/dist/production/coreComponents/HasOne.js +18 -20
  213. package/dist/production/coreComponents/HasOne.js.map +1 -1
  214. package/dist/production/coreComponents/ParentEntity.js +8 -6
  215. package/dist/production/coreComponents/ParentEntity.js.map +1 -1
  216. package/dist/production/dao/Environment.js +3 -0
  217. package/dist/production/dao/Environment.js.map +1 -1
  218. package/dist/production/entityEvents/useEntityEvent.js.map +1 -1
  219. package/dist/production/fieldHelpers/helpers/TemporalFieldHelper.js +4 -1
  220. package/dist/production/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -1
  221. package/dist/production/helperComponents/DeferredSubTrees.js +67 -77
  222. package/dist/production/helperComponents/DeferredSubTrees.js.map +1 -1
  223. package/dist/production/helperComponents/EntityView.js +1 -3
  224. package/dist/production/helperComponents/EntityView.js.map +1 -1
  225. package/dist/production/helperComponents/FieldView.js +38 -31
  226. package/dist/production/helperComponents/FieldView.js.map +1 -1
  227. package/dist/production/helperComponents/If.js +40 -52
  228. package/dist/production/helperComponents/If.js.map +1 -1
  229. package/dist/production/helperComponents/StaticRender.js +5 -5
  230. package/dist/production/helperComponents/StaticRender.js.map +1 -1
  231. package/dist/production/helperComponents/SugaredField.js +2 -8
  232. package/dist/production/helperComponents/SugaredField.js.map +1 -1
  233. package/dist/production/helperComponents/helpers/FilterEvaluator.js.map +1 -1
  234. package/dist/production/helperComponents/helpers/evaluateCondition.js +1 -0
  235. package/dist/production/helperComponents/helpers/evaluateCondition.js.map +1 -1
  236. package/dist/production/markers/EntityFieldMarkersContainer.js +1 -0
  237. package/dist/production/markers/EntityFieldMarkersContainer.js.map +1 -1
  238. package/dist/production/queryLanguage/CacheStore.js.map +1 -1
  239. package/dist/production/queryLanguage/MarkerFactory.js.map +1 -1
  240. package/dist/production/queryLanguage/Parser.js +2 -0
  241. package/dist/production/queryLanguage/Parser.js.map +1 -1
  242. package/dist/production/queryLanguage/QueryLanguage.js +13 -2
  243. package/dist/production/queryLanguage/QueryLanguage.js.map +1 -1
  244. package/dist/production/structures/BijectiveIndexedMap.js +2 -0
  245. package/dist/production/structures/BijectiveIndexedMap.js.map +1 -1
  246. package/dist/production/treeParameterHelpers/wrapFilterInHasOnes.js.map +1 -1
  247. package/dist/production/treeParameters/EntityCreationParameters.js +1 -0
  248. package/dist/production/treeParameters/EntityCreationParameters.js.map +1 -1
  249. package/dist/production/utils/Hashing.js +1 -0
  250. package/dist/production/utils/Hashing.js.map +1 -1
  251. package/dist/types/accessorPropagation/BindingOperationsContext.d.ts +0 -1
  252. package/dist/types/accessorPropagation/BindingOperationsContext.d.ts.map +1 -1
  253. package/dist/types/accessorPropagation/EntityKeyContext.d.ts +0 -1
  254. package/dist/types/accessorPropagation/EntityKeyContext.d.ts.map +1 -1
  255. package/dist/types/accessorPropagation/TreeRootIdContext.d.ts +0 -1
  256. package/dist/types/accessorPropagation/TreeRootIdContext.d.ts.map +1 -1
  257. package/dist/types/accessorSorting/SetOrderFieldOnCreate.d.ts +0 -1
  258. package/dist/types/accessorSorting/SetOrderFieldOnCreate.d.ts.map +1 -1
  259. package/dist/types/accessorTree/AccessorTreeStateContext.d.ts +0 -1
  260. package/dist/types/accessorTree/AccessorTreeStateContext.d.ts.map +1 -1
  261. package/dist/types/accessorTree/DirtinessContext.d.ts +0 -1
  262. package/dist/types/accessorTree/DirtinessContext.d.ts.map +1 -1
  263. package/dist/types/accessorTree/MutationStateContext.d.ts +0 -1
  264. package/dist/types/accessorTree/MutationStateContext.d.ts.map +1 -1
  265. package/dist/types/tsconfig.tsbuildinfo +1 -1
  266. package/package.json +14 -13
  267. package/LICENSE +0 -186
  268. package/src/ambient.d.ts +0 -1
@@ -1,34 +1,16 @@
1
+ import { jsx } from "react/jsx-runtime";
1
2
  import { AccessorTreeStateContext } from "./AccessorTreeStateContext.js";
2
3
  import { DirtinessContext } from "./DirtinessContext.js";
3
4
  import { MutationStateContext } from "./MutationStateContext.js";
4
- import { jsx } from "react/jsx-runtime";
5
5
  import { EnvironmentContext } from "../accessorPropagation/EnvironmentContext.js";
6
6
  import { BindingOperationsProvider } from "../accessorPropagation/BindingOperationsProvider.js";
7
- function AccessorTree({
8
- state,
9
- children
10
- }) {
7
+ function AccessorTree({ state, children }) {
11
8
  const stateData = state.name === "initialized" ? state.data : {
12
9
  hasUnpersistedChanges: false,
13
10
  isMutating: false,
14
11
  bindingOperations: void 0
15
12
  };
16
- return /* @__PURE__ */ jsx(EnvironmentContext.Provider, {
17
- value: state.environment,
18
- children: /* @__PURE__ */ jsx(AccessorTreeStateContext.Provider, {
19
- value: state,
20
- children: /* @__PURE__ */ jsx(DirtinessContext.Provider, {
21
- value: stateData.hasUnpersistedChanges,
22
- children: /* @__PURE__ */ jsx(MutationStateContext.Provider, {
23
- value: stateData.isMutating,
24
- children: /* @__PURE__ */ jsx(BindingOperationsProvider, {
25
- bindingOperations: stateData.bindingOperations,
26
- children
27
- })
28
- })
29
- })
30
- })
31
- });
13
+ return /* @__PURE__ */ jsx(EnvironmentContext.Provider, { value: state.environment, children: /* @__PURE__ */ jsx(AccessorTreeStateContext.Provider, { value: state, children: /* @__PURE__ */ jsx(DirtinessContext.Provider, { value: stateData.hasUnpersistedChanges, children: /* @__PURE__ */ jsx(MutationStateContext.Provider, { value: stateData.isMutating, children: /* @__PURE__ */ jsx(BindingOperationsProvider, { bindingOperations: stateData.bindingOperations, children }) }) }) }) });
32
14
  }
33
15
  AccessorTree.displayName = "AccessorTree";
34
16
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"AccessorTree.js","sources":["../../../src/accessorTree/AccessorTree.tsx"],"sourcesContent":["import type { ReactNode } from 'react'\nimport { BindingOperationsProvider, EnvironmentContext } from '../accessorPropagation'\nimport type { AccessorTreeState } from './AccessorTreeState'\nimport { AccessorTreeStateContext } from './AccessorTreeStateContext'\nimport { DirtinessContext } from './DirtinessContext'\nimport { MutationStateContext } from './MutationStateContext'\n\nexport interface AccessorTreeProps {\n\tstate: AccessorTreeState\n\tchildren: ReactNode\n}\n\nexport function AccessorTree({ state, children }: AccessorTreeProps) {\n\tconst stateData = state.name === 'initialized' ? state.data : {\n\t\thasUnpersistedChanges: false,\n\t\tisMutating: false,\n\t\tbindingOperations: undefined,\n\t}\n\treturn (\n\t\t<EnvironmentContext.Provider value={state.environment}>\n\t\t\t<AccessorTreeStateContext.Provider value={state}>\n\t\t\t\t<DirtinessContext.Provider value={stateData.hasUnpersistedChanges}>\n\t\t\t\t\t<MutationStateContext.Provider value={stateData.isMutating}>\n\t\t\t\t\t\t<BindingOperationsProvider bindingOperations={stateData.bindingOperations}>\n\t\t\t\t\t\t\t{children}\n\t\t\t\t\t\t</BindingOperationsProvider>\n\t\t\t\t\t</MutationStateContext.Provider>\n\t\t\t\t</DirtinessContext.Provider>\n\t\t\t</AccessorTreeStateContext.Provider>\n\t\t</EnvironmentContext.Provider>\n\t)\n}\n\nAccessorTree.displayName = 'AccessorTree'\n"],"names":["AccessorTree","state","children","stateData","name","data","hasUnpersistedChanges","isMutating","bindingOperations","undefined","_jsx","environment","displayName"],"mappings":";;;;;;AAYO,SAASA,aAAa;AAAA,EAAEC;AAAAA,EAAOC;AAA4B,GAAG;AACpE,QAAMC,YAAYF,MAAMG,SAAS,gBAAgBH,MAAMI,OAAO;AAAA,IAC7DC,uBAAuB;AAAA,IACvBC,YAAY;AAAA,IACZC,mBAAmBC;AAAAA,EAAAA;AAGnB,SAAAC,oBAAC,mBAAmB,UAAQ;AAAA,IAAC,OAAOT,MAAMU;AAAAA,IAAY,UACpDD,oBAAA,yBAAyB,UAAQ;AAAA,MAAC,OAAOT;AAAAA,MAAM,UAC9CS,oBAAA,iBAAiB,UAAQ;AAAA,QAAC,OAAOP,UAAUG;AAAAA,QAAsB,UAChEI,oBAAA,qBAAqB,UAAQ;AAAA,UAAC,OAAOP,UAAUI;AAAAA,UAAW,8BACzD,2BAAyB;AAAA,YAAC,mBAAmBJ,UAAUK;AAAAA,YAAkB;AAAA,UAAA,CAChE;AAAA,QAAA,CACkB;AAAA,MAAA,CACG;AAAA,IAAA,CACL;AAAA,EAAA,CAEA;AAEhC;AAEAR,aAAaY,cAAc;"}
1
+ {"version":3,"file":"AccessorTree.js","sources":["../../../src/accessorTree/AccessorTree.tsx"],"sourcesContent":["import type { ReactNode } from 'react'\nimport { BindingOperationsProvider, EnvironmentContext } from '../accessorPropagation'\nimport type { AccessorTreeState } from './AccessorTreeState'\nimport { AccessorTreeStateContext } from './AccessorTreeStateContext'\nimport { DirtinessContext } from './DirtinessContext'\nimport { MutationStateContext } from './MutationStateContext'\n\nexport interface AccessorTreeProps {\n\tstate: AccessorTreeState\n\tchildren: ReactNode\n}\n\nexport function AccessorTree({ state, children }: AccessorTreeProps) {\n\tconst stateData = state.name === 'initialized' ? state.data : {\n\t\thasUnpersistedChanges: false,\n\t\tisMutating: false,\n\t\tbindingOperations: undefined,\n\t}\n\treturn (\n\t\t<EnvironmentContext.Provider value={state.environment}>\n\t\t\t<AccessorTreeStateContext.Provider value={state}>\n\t\t\t\t<DirtinessContext.Provider value={stateData.hasUnpersistedChanges}>\n\t\t\t\t\t<MutationStateContext.Provider value={stateData.isMutating}>\n\t\t\t\t\t\t<BindingOperationsProvider bindingOperations={stateData.bindingOperations}>\n\t\t\t\t\t\t\t{children}\n\t\t\t\t\t\t</BindingOperationsProvider>\n\t\t\t\t\t</MutationStateContext.Provider>\n\t\t\t\t</DirtinessContext.Provider>\n\t\t\t</AccessorTreeStateContext.Provider>\n\t\t</EnvironmentContext.Provider>\n\t)\n}\n\nAccessorTree.displayName = 'AccessorTree'\n"],"names":[],"mappings":";;;;;;AAYO,SAAS,aAAa,EAAE,OAAO,YAA+B;AACpE,QAAM,YAAY,MAAM,SAAS,gBAAgB,MAAM,OAAO;AAAA,IAC7D,uBAAuB;AAAA,IACvB,YAAY;AAAA,IACZ,mBAAmB;AAAA,EAAA;AAEpB,6BACE,mBAAmB,UAAnB,EAA4B,OAAO,MAAM,aACzC,UAAA,oBAAC,yBAAyB,UAAzB,EAAkC,OAAO,OACzC,UAAC,oBAAA,iBAAiB,UAAjB,EAA0B,OAAO,UAAU,uBAC3C,8BAAC,qBAAqB,UAArB,EAA8B,OAAO,UAAU,YAC/C,UAAA,oBAAC,2BAA0B,EAAA,mBAAmB,UAAU,mBACtD,SAAA,CACF,EACD,CAAA,EACD,CAAA,GACD,EACD,CAAA;AAEF;AAEA,aAAa,cAAc;"}
@@ -1 +1 @@
1
- {"version":3,"file":"accessorTreeStateReducer.js","sources":["../../../src/accessorTree/accessorTreeStateReducer.ts"],"sourcesContent":["import type { AccessorTreeState } from './AccessorTreeState'\nimport type { AccessorTreeStateAction } from './AccessorTreeStateAction'\n\nexport const accessorTreeStateReducer = (\n\tpreviousState: AccessorTreeState,\n\taction: AccessorTreeStateAction,\n): AccessorTreeState => {\n\tswitch (action.type) {\n\t\tcase 'setData':\n\t\t\tif (previousState.name === 'error' || previousState.binding !== action.binding) {\n\t\t\t\treturn previousState\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tname: 'initialized',\n\t\t\t\tenvironment: previousState.environment,\n\t\t\t\tbinding: previousState.binding,\n\t\t\t\tdata: action.data,\n\t\t\t}\n\t\tcase 'failWithError':\n\t\t\tif (previousState.binding !== action.binding) {\n\t\t\t\treturn previousState\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tname: 'error',\n\t\t\t\tenvironment: previousState.environment,\n\t\t\t\tbinding: previousState.binding,\n\t\t\t\terror: action.error,\n\t\t\t}\n\t\tcase 'reset':\n\t\t\treturn {\n\t\t\t\tname: 'initializing',\n\t\t\t\tenvironment: action.environment,\n\t\t\t\tbinding: action.binding,\n\t\t\t}\n\t}\n}\n"],"names":[],"mappings":"AAGa,MAAA,2BAA2B,CACvC,eACA,WACuB;AACvB,UAAQ,OAAO;AAAA,SACT;AACJ,UAAI,cAAc,SAAS,WAAW,cAAc,YAAY,OAAO,SAAS;AACxE,eAAA;AAAA,MACR;AACO,aAAA;AAAA,QACN,MAAM;AAAA,QACN,aAAa,cAAc;AAAA,QAC3B,SAAS,cAAc;AAAA,QACvB,MAAM,OAAO;AAAA,MAAA;AAAA,SAEV;AACA,UAAA,cAAc,YAAY,OAAO,SAAS;AACtC,eAAA;AAAA,MACR;AACO,aAAA;AAAA,QACN,MAAM;AAAA,QACN,aAAa,cAAc;AAAA,QAC3B,SAAS,cAAc;AAAA,QACvB,OAAO,OAAO;AAAA,MAAA;AAAA,SAEX;AACG,aAAA;AAAA,QACN,MAAM;AAAA,QACN,aAAa,OAAO;AAAA,QACpB,SAAS,OAAO;AAAA,MAAA;AAAA;AAGpB;"}
1
+ {"version":3,"file":"accessorTreeStateReducer.js","sources":["../../../src/accessorTree/accessorTreeStateReducer.ts"],"sourcesContent":["import type { AccessorTreeState } from './AccessorTreeState'\nimport type { AccessorTreeStateAction } from './AccessorTreeStateAction'\n\nexport const accessorTreeStateReducer = (\n\tpreviousState: AccessorTreeState,\n\taction: AccessorTreeStateAction,\n): AccessorTreeState => {\n\tswitch (action.type) {\n\t\tcase 'setData':\n\t\t\tif (previousState.name === 'error' || previousState.binding !== action.binding) {\n\t\t\t\treturn previousState\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tname: 'initialized',\n\t\t\t\tenvironment: previousState.environment,\n\t\t\t\tbinding: previousState.binding,\n\t\t\t\tdata: action.data,\n\t\t\t}\n\t\tcase 'failWithError':\n\t\t\tif (previousState.binding !== action.binding) {\n\t\t\t\treturn previousState\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tname: 'error',\n\t\t\t\tenvironment: previousState.environment,\n\t\t\t\tbinding: previousState.binding,\n\t\t\t\terror: action.error,\n\t\t\t}\n\t\tcase 'reset':\n\t\t\treturn {\n\t\t\t\tname: 'initializing',\n\t\t\t\tenvironment: action.environment,\n\t\t\t\tbinding: action.binding,\n\t\t\t}\n\t}\n}\n"],"names":[],"mappings":"AAGa,MAAA,2BAA2B,CACvC,eACA,WACuB;AACvB,UAAQ,OAAO,MAAM;AAAA,IACpB,KAAK;AACJ,UAAI,cAAc,SAAS,WAAW,cAAc,YAAY,OAAO,SAAS;AACxE,eAAA;AAAA,MACR;AACO,aAAA;AAAA,QACN,MAAM;AAAA,QACN,aAAa,cAAc;AAAA,QAC3B,SAAS,cAAc;AAAA,QACvB,MAAM,OAAO;AAAA,MAAA;AAAA,IAEf,KAAK;AACA,UAAA,cAAc,YAAY,OAAO,SAAS;AACtC,eAAA;AAAA,MACR;AACO,aAAA;AAAA,QACN,MAAM;AAAA,QACN,aAAa,cAAc;AAAA,QAC3B,SAAS,cAAc;AAAA,QACvB,OAAO,OAAO;AAAA,MAAA;AAAA,IAEhB,KAAK;AACG,aAAA;AAAA,QACN,MAAM;AAAA,QACN,aAAa,OAAO;AAAA,QACpB,SAAS,OAAO;AAAA,MAAA;AAAA,EAEnB;AACD;"}
@@ -20,12 +20,16 @@ class EntityAccessor {
20
20
  get idOnServer() {
21
21
  return this.runtimeId.existsOnServer ? this.runtimeId.value : void 0;
22
22
  }
23
+ /**
24
+ * Note that for entities that don't yet exist on server this will return a dummy id.
25
+ */
23
26
  get id() {
24
27
  return this.runtimeId.value;
25
28
  }
26
29
  get existsOnServer() {
27
30
  return this.runtimeId.existsOnServer;
28
31
  }
32
+ //
29
33
  addError(error) {
30
34
  return this.operations.addError(this.state, ErrorAccessor.normalizeError(error));
31
35
  }
@@ -44,6 +48,7 @@ class EntityAccessor {
44
48
  deleteEntity() {
45
49
  this.operations.deleteEntity(this.state);
46
50
  }
51
+ //
47
52
  updateValues(fieldValuePairs) {
48
53
  this.batchUpdates((getAccessor) => {
49
54
  const entries = Array.isArray(fieldValuePairs) ? fieldValuePairs : Object.entries(fieldValuePairs);
@@ -52,6 +57,10 @@ class EntityAccessor {
52
57
  }
53
58
  });
54
59
  }
60
+ /**
61
+ * Please keep in mind that this method signature is literally impossible to implement safely. The generic parameter
62
+ * is really just a way to succinctly write a type cast. Nothing more, really.
63
+ */
55
64
  getField(field) {
56
65
  return this.getRelativeSingleField(QueryLanguage.desugarRelativeSingleField(field, this.environment));
57
66
  }
@@ -61,6 +70,10 @@ class EntityAccessor {
61
70
  getEntityList(entityList) {
62
71
  return this.getRelativeEntityList(QueryLanguage.desugarRelativeEntityList(entityList, this.environment));
63
72
  }
73
+ //
74
+ /**
75
+ * @see EntityAccessor.getField
76
+ */
64
77
  getRelativeSingleField(field) {
65
78
  return this.getRelativeSingleEntity(field).getAccessorByPlaceholder(
66
79
  PlaceholderGenerator.getFieldPlaceholder(field.field)
@@ -95,8 +108,8 @@ class EntityAccessor {
95
108
  if (record === void 0) {
96
109
  throw new BindingError(
97
110
  `EntityAccessor: unknown field placeholder '${placeholderName} on ${this.name}'. Unless this is just a typo, this is typically caused by one of the following:
98
- \u2022 Trying to access a field that has not been registered during static render, and thus lacks a marker and an accessor.
99
- \u2022 Misusing an EntityAccessor getter. If you used one of the getRelative[\u2026] family, please make sure all parameters match the marker tree exactly.
111
+ • Trying to access a field that has not been registered during static render, and thus lacks a marker and an accessor.
112
+ • Misusing an EntityAccessor getter. If you used one of the getRelative[…] family, please make sure all parameters match the marker tree exactly.
100
113
 
101
114
  For more information, please consult the documentation.
102
115
 
@@ -1 +1 @@
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,EAEH,IAAW,aAAmC;AAC7C,WAAO,KAAK,UAAU,iBAAiB,KAAK,UAAU,QAAQ;AAAA,EAC/D;AAAA,EAKA,IAAW,KAAe;AACzB,WAAO,KAAK,UAAU;AAAA,EACvB;AAAA,EAEA,IAAW,iBAA0B;AACpC,WAAO,KAAK,UAAU;AAAA,EACvB;AAAA,EAIO,SAAS,OAAiD;AACzD,WAAA,KAAK,WAAW,SAAS,KAAK,OAAO,cAAc,eAAe,KAAK,CAAC;AAAA,EAChF;AAAA,EAEO,iBACN,OACA,UACa;AACb,WAAO,KAAK,WAAW,iBAAiB,KAAK,OAAO,OAAO,QAAQ;AAAA,EACpE;AAAA,EAEO,aAAa,gBA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O,sBAAsB,YAAoD;AACzE,WAAA,KAAK,wBAAwB,UAAU,EAAE;AAAA,MAC/C,qBAAqB,8BAA8B,WAAW,eAAe;AAAA,IAAA;AAAA,EAE/E;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;AAAA,QACT,8CAA8C,sBAAsB,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAA;AAAA,IAO3E;AACA,WAAO,OAAO;EACf;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,EAEH,IAAW,aAAmC;AAC7C,WAAO,KAAK,UAAU,iBAAiB,KAAK,UAAU,QAAQ;AAAA,EAC/D;AAAA;AAAA;AAAA;AAAA,EAKA,IAAW,KAAe;AACzB,WAAO,KAAK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,EACxG;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,uBAA8D,OAAkD;AAC/G,WAAA,KAAK,wBAAwB,KAAK,EAAE;AAAA,MAC1C,qBAAqB,oBAAoB,MAAM,KAAK;AAAA,IAAA;AAAA,EAEtD;AAAA,EAEO,wBAAwB,sBAA4D;AAC1F,QAAI,aAA6B;AAEtB,eAAA,kBAAkB,qBAAqB,oBAAoB;AACrE,mBAAa,WAAW;AAAA,QACvB,qBAAqB,6BAA6B,cAAc;AAAA,MAAA;AAAA,IAElE;AACO,WAAA;AAAA,EACR;AAAA,EAEO,sBAAsB,YAAoD;AACzE,WAAA,KAAK,wBAAwB,UAAU,EAAE;AAAA,MAC/C,qBAAqB,8BAA8B,WAAW,eAAe;AAAA,IAAA;AAAA,EAE/E;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;AAAA,QACT,8CAA8C,sBAAsB,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAA;AAAA,IAO3E;AACA,WAAO,OAAO;EACf;AACD;"}
@@ -10,6 +10,11 @@ class EntityListAccessor {
10
10
  this.environment = environment;
11
11
  this.getAccessor = getAccessor;
12
12
  }
13
+ /**
14
+ * Returns all entity keys that are on the list.
15
+ * **KEYS ARE NOT IDS!**
16
+ * @see EntityAccessor.key
17
+ */
13
18
  *keys() {
14
19
  for (const accessor of this) {
15
20
  yield accessor.key;
@@ -18,6 +23,10 @@ class EntityListAccessor {
18
23
  *ids() {
19
24
  return this._children.keys();
20
25
  }
26
+ /**
27
+ * This will only contain the ids that the server knows about. Not necessarily the ids that have been added on
28
+ * the list since the last server query.
29
+ */
21
30
  get idsPersistedOnServer() {
22
31
  return new Set(this._idsPersistedOnServer);
23
32
  }
@@ -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 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,EAOH,CAAQ,OAAyC;AAChD,eAAW,YAAY,MAAM;AAC5B,YAAM,SAAS;AAAA,IAChB;AAAA,EACD;AAAA,EAEA,CAAQ,MAAkC;AAClC,WAAA,KAAK,UAAU;EACvB;AAAA,EAMA,IAAW,uBAAsC;AACzC,WAAA,IAAI,IAAI,KAAK,qBAAqB;AAAA,EAC1C;AAAA,EAEA,EAAS,OAAO,YAA8C;AAC7D,eAAW,EAAE,YAAY,KAAK,KAAK,UAAU,UAAU;AACtD,YAAM,YAAY;AAAA,IACnB;AAAA,EACD;AAAA,EAEO,YAAY,IAAuB;AAClC,WAAA,KAAK,UAAU,IAAI,EAAE;AAAA,EAC7B;AAAA,EAEO,UAAmB;AACzB,WAAO,KAAK,WAAW;AAAA,EACxB;AAAA,EAEA,IAAW,SAAiB;AAC3B,WAAO,KAAK,UAAU;AAAA,EACvB;AAAA,EAEO,kBAAkB,eAAmD;AAC3E,QAAI,OAAO,kBAAkB,YAAY,OAAO,kBAAkB,UAAU;AACpE,aAAA,KAAK,qBAAqB,IAAI,aAAa;AAAA,IACnD;AACA,UAAM,aAAa,cAAc;AACjC,QAAI,eAAe,QAAW;AACtB,aAAA;AAAA,IACR;AACO,WAAA,KAAK,qBAAqB,IAAI,UAAU;AAAA,EAChD;AAAA,EAEO,YAAkB;AACxB,SAAK,aAAa,CAAe,gBAAA;AAChC,YAAM,OAAO;AACb,iBAAW,UAAU,MAAM;AAC1B,eAAO,aAAa;AAAA,MACrB;AAAA,IAAA,CACA;AAAA,EACF;AAAA,EAEO,gBAAsB;AAC5B,SAAK,aAAa,CAAe,gBAAA;AAChC,YAAM,OAAO;AACb,iBAAW,UAAU,MAAM;AAC1B,aAAK,iBAAiB,MAAM;AAAA,MAC7B;AAAA,IAAA,CACA;AAAA,EACF;AAAA,EAEO,SAAS,OAAiD;AACzD,WAAA,KAAK,WAAW,SAAS,KAAK,OAAO,cAAc,eAAe,KAAK,CAAC;AAAA,EAChF;AAAA,EAEO,iBACN,OACA,UACC;AACD,WAAO,KAAK,WAAW,iBAAiB,KAAK,OAAO,OAAO,QAAQ;AAAA,EACpE;AAAA,EAEO,sBACN,OACA,OACA,UACC;AACD,WAAO,KAAK,WAAW,sBAAsB,KAAK,OAAO,OAAO,QAAQ;AAAA,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;"}
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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AK,aAAa,CAAe,gBAAA;AAChC,YAAM,OAAO;AACb,iBAAW,UAAU,MAAM;AAC1B,aAAK,iBAAiB,MAAM;AAAA,MAC7B;AAAA,IAAA,CACA;AAAA,EACF;AAAA,EAEO,SAAS,OAAiD;AACzD,WAAA,KAAK,WAAW,SAAS,KAAK,OAAO,cAAc,eAAe,KAAK,CAAC;AAAA,EAChF;AAAA,EAEO,iBACN,OACA,UACC;AACD,WAAO,KAAK,WAAW,iBAAiB,KAAK,OAAO,OAAO,QAAQ;AAAA,EACpE;AAAA,EAEO,sBACN,OACA,OACA,UACC;AACD,WAAO,KAAK,WAAW,sBAAsB,KAAK,OAAO,OAAO,QAAQ;AAAA,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;"}
@@ -42,6 +42,7 @@ class FieldAccessor {
42
42
  }
43
43
  return this.value === null ? this.defaultValue : this.value;
44
44
  }
45
+ // helpers
45
46
  get asTemporal() {
46
47
  return new TemporalFieldHelper(this.getAccessor);
47
48
  }
@@ -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 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":["FieldAccessor"],"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,EAEA,IAAW,YAAY;AACf,WAAA,KAAK,YAAY,cAAc,SAAS;AAAA,EAChD;AAAA,EAEA,IAAW,gBAAgB;AACtB,QAAA,KAAK,iBAAiB,QAAW;AACpC,aAAO,KAAK;AAAA,IACb;AACA,WAAO,KAAK,UAAU,OAAO,KAAK,eAAe,KAAK;AAAA,EACvD;AAAA,EAIA,IAAW,aAAkC;AACrC,WAAA,IAAI,oBAAoB,KAAK,WAAkD;AAAA,EACvF;AAAA,EAEA,IAAW,SAA0B;AAC7B,WAAA,IAAI,gBAAgB,KAAK,WAAkD;AAAA,EACnF;AACD;AAAA,CACA,CAAUA,mBAAV;AACcA,iBAAA,YAAY;AAAA,GADhB,kBAAA,gBAAA,CAAA,EAAA;"}
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 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":["FieldAccessor"],"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,EAEA,IAAW,YAAY;AACf,WAAA,KAAK,YAAY,cAAc,SAAS;AAAA,EAChD;AAAA,EAEA,IAAW,gBAAgB;AACtB,QAAA,KAAK,iBAAiB,QAAW;AACpC,aAAO,KAAK;AAAA,IACb;AACA,WAAO,KAAK,UAAU,OAAO,KAAK,eAAe,KAAK;AAAA,EACvD;AAAA;AAAA,EAIA,IAAW,aAAkC;AACrC,WAAA,IAAI,oBAAoB,KAAK,WAAkD;AAAA,EACvF;AAAA,EAEA,IAAW,SAA0B;AAC7B,WAAA,IAAI,gBAAgB,KAAK,WAAkD;AAAA,EACnF;AACD;AAAA,CACA,CAAUA,mBAAV;AACcA,iBAAA,YAAY;AAAA,GADhB,kBAAA,gBAAA,CAAA,EAAA;"}
@@ -1,4 +1,7 @@
1
1
  class TreeRootAccessor {
2
+ /**
3
+ * Whenever an update occurs, a new instance of this class is created.
4
+ */
2
5
  constructor(hasUnpersistedChanges, isMutating, bindingOperations) {
3
6
  this.hasUnpersistedChanges = hasUnpersistedChanges;
4
7
  this.isMutating = isMutating;
@@ -1 +1 @@
1
- {"version":3,"file":"TreeRootAccessor.js","sources":["../../../src/accessors/TreeRootAccessor.ts"],"sourcesContent":["import type { BindingOperations } from './BindingOperations'\n\n// This allows us to have several parallel sub-trees without one having to be the main tree\n// and all the other ones subordinate.\nexport class TreeRootAccessor {\n\t/**\n\t * Whenever an update occurs, a new instance of this class is created.\n\t */\n\tpublic constructor(\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tpublic readonly isMutating: boolean,\n\t\tpublic readonly bindingOperations: BindingOperations,\n\t) {}\n}\n"],"names":[],"mappings":"AAIO,MAAM,iBAAiB;AAAA,EAItB,YACU,uBACA,YACA,mBACf;AAHe,SAAA,wBAAA;AACA,SAAA,aAAA;AACA,SAAA,oBAAA;AAAA,EACd;AACJ;"}
1
+ {"version":3,"file":"TreeRootAccessor.js","sources":["../../../src/accessors/TreeRootAccessor.ts"],"sourcesContent":["import type { BindingOperations } from './BindingOperations'\n\n// This allows us to have several parallel sub-trees without one having to be the main tree\n// and all the other ones subordinate.\nexport class TreeRootAccessor {\n\t/**\n\t * Whenever an update occurs, a new instance of this class is created.\n\t */\n\tpublic constructor(\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tpublic readonly isMutating: boolean,\n\t\tpublic readonly bindingOperations: BindingOperations,\n\t) {}\n}\n"],"names":[],"mappings":"AAIO,MAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAItB,YACU,uBACA,YACA,mBACf;AAHe,SAAA,wBAAA;AACA,SAAA,aAAA;AACA,SAAA,oBAAA;AAAA,EACd;AACJ;"}
@@ -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'\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":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AAC1C,mBAAW,YAAY;AACV,qBAAA,MAAM,SAAS,IAAI,QAAQ;AAAA,MACzC;AAEI,UAAA,WAAW,aAAa,SAAS;AAC/B,aAAA,qBAAqB,YAAgC,UAAU;AAAA,MACrE;AAAA,IACD;AAAA,EACD;AAAA,EAEQ,cAAc,MAA4B;AAEjD,eAAW,sBAAsB,MAAM;AACtC,YAAM,YAAY,KAAK;AACvB,YAAM,kBAA2D,UAAU;AACrE,YAAA,YAAY,WAAW,YAAY,SACtC,gBAAgB,OAAO,UAAU,WAAW,MAAM,IAClD;AACH,YAAM,mBAAmB,UAAU,IAAI,CAAC,UAA4C;AAC5E,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;"}
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":["errorsById"],"mappings":";;;;;;;;;;AAQO,MAAM,qBAAqB;AAAA,EAS1B,YAA6B,cAA6C,WAAsB;AAR/F,6DAA8D;AAE9D,0CAAiB,MAAM;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;AACrC,iBAAW,CAAC,SAAS,KAAK,KAAK,eAAe;AAC7C,kBAAU,SAAS;AACnB,aAAK,aAAa,oBAAoB,WAAW,aAAa,qBAAqB;AAAA,MACpF;AACA,WAAK,cAAc;IAAM,CACzB;AAAA,EACF;AAAA,EAEO,mBAAmB,OAAwB;AAC1C,WAAA,KAAK,aAAa,cAAc,MAAM;AAC5C,UAAI,CAAC,KAAK,cAAc,IAAI,KAAK,GAAG;AACnC;AAAA,MACD;AACK,WAAA,cAAc,OAAO,KAAK;AAC/B,YAAM,SAAS;AACf,WAAK,aAAa,oBAAoB,OAAO,aAAa,qBAAqB;AAAA,IAAA,CAC/E;AAAA,EACF;AAAA,EAEO,cAAc,MAA4B,YAAoC;AAC/E,SAAA,aAAa,cAAc,MAAM;AACrC,WAAK,YAAY;AAEjB,YAAM,eAAe,IAAI,mBAAmB,MAAM,UAAU;AACt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+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}\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,MAAM,UAAN,MAAa;AAAA,EASZ,YAAY,SAAiC,IAAI;AAFvC;AAGhB,SAAK,SAAS;AAAA,MACb,GAAG,QAAO;AAAA,MACV,GAAG;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;AAxBO,IAAM,SAAN;AACN,cADY,QACG,iBAA+B;AAAA,EAC7C,0BAA0B;AAAA,EAC1B,yBAAyB;AAAA,EACzB,2BAA2B;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}\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,MAAM,UAAN,MAAa;AAAA,EASZ,YAAY,SAAiC,IAAI;AAFvC;AAGhB,SAAK,SAAS;AAAA,MACb,GAAG,QAAO;AAAA,MACV,GAAG;AAAA,IAAA;AAAA,EAEL;AAAA,EAEO,SAA2C,MAAiC;AAC3E,WAAA,KAAK,OAAO,IAAI;AAAA,EACxB;AAAA,EAEO,SAA2C,MAAY,OAAkC;AAC1F,SAAA,OAAO,IAAI,IAAI;AACb,WAAA;AAAA,EACR;AACD;AAxBO,IAAM,SAAN;AACN,cADY,QACG,iBAA+B;AAAA,EAC7C,0BAA0B;AAAA,EAC1B,yBAAyB;AAAA,EACzB,2BAA2B;AAAA;"}
@@ -23,6 +23,11 @@ import { StateIterator } from "./state/StateIterator.js";
23
23
  import { assertNever } from "../utils/assertNever.js";
24
24
  import { generateEnumerabilityPreventingEntropy } from "../utils/generateEnumerabilityPreventingEntropy.js";
25
25
  const _DataBinding = class {
26
+ // private treeRootListeners: {
27
+ // eventListeners: {}
28
+ // } = {
29
+ // eventListeners: {},
30
+ // }
26
31
  constructor(contentApiClient, systemApiClient, tenantApiClient, treeStore, environment, onUpdate, onError, onPersistSuccess, options) {
27
32
  __publicField(this, "accessorErrorManager");
28
33
  __publicField(this, "batchUpdatesOptions");
@@ -36,6 +41,10 @@ const _DataBinding = class {
36
41
  __publicField(this, "resolvedOnUpdate", ({ isMutating }) => {
37
42
  this.onUpdate(new TreeRootAccessor(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations), this);
38
43
  });
44
+ // This is currently useless but potentially future-compatible
45
+ // private readonly addTreeRootEventListener: TreeRootAccessor.AddTreeRootEventListener = this.getAddEventListener(
46
+ // this.treeRootListeners,
47
+ // )
39
48
  __publicField(this, "pendingExtensions", /* @__PURE__ */ new Set());
40
49
  this.contentApiClient = contentApiClient;
41
50
  this.systemApiClient = systemApiClient;
@@ -1 +1 @@
1
- {"version":3,"file":"DataBinding.js","sources":["../../../src/core/DataBinding.ts"],"sourcesContent":["import type { GraphQlClient, GraphQlClientFailedRequestMetadata, TreeFilter } from '@contember/client'\nimport type { ReactNode } from 'react'\nimport {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tBindingOperations,\n\tExtendTreeOptions,\n\tPersistErrorOptions, PersistOptions,\n\tPersistSuccessOptions,\n\tTreeRootAccessor,\n} from '../accessors'\nimport {\n\tErrorPersistResult,\n\tmetadataToRequestError, MutationDataResponse,\n\tMutationRequestResponse,\n\tQueryRequestResponse,\n\tRequestError,\n\tSuccessfulPersistResult,\n} from '../accessorTree'\nimport type { Environment } from '../dao'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { TreeRootId } from '../treeParameters'\nimport { assertNever, generateEnumerabilityPreventingEntropy } from '../utils'\nimport { AccessorErrorManager } from './AccessorErrorManager'\nimport { Config } from './Config'\nimport { DirtinessTracker } from './DirtinessTracker'\nimport { EventManager } from './EventManager'\nimport { createBatchUpdatesOptions } from './factories'\nimport { MarkerMerger } from './MarkerMerger'\nimport { MarkerTreeGenerator } from './MarkerTreeGenerator'\nimport { MutationGenerator, SubMutationOperation } from './MutationGenerator'\nimport { QueryGenerator } from './QueryGenerator'\nimport { StateIterator } from './state'\nimport { StateInitializer } from './StateInitializer'\nimport { TreeAugmenter } from './TreeAugmenter'\nimport { TreeFilterGenerator } from './TreeFilterGenerator'\nimport { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport { getCombinedSignal } from './utils'\n\nexport class DataBinding {\n\tprivate readonly accessorErrorManager: AccessorErrorManager\n\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions\n\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions\n\tprivate readonly bindingOperations: BindingOperations\n\tprivate readonly config: Config\n\tprivate readonly dirtinessTracker: DirtinessTracker\n\tprivate readonly eventManager: EventManager\n\tprivate readonly stateInitializer: StateInitializer\n\tprivate readonly treeAugmenter: TreeAugmenter\n\n\t// private treeRootListeners: {\n\t// \teventListeners: {}\n\t// } = {\n\t// \teventListeners: {},\n\t// }\n\n\tpublic constructor(\n\t\tprivate readonly contentApiClient: GraphQlClient,\n\t\tprivate readonly systemApiClient: GraphQlClient,\n\t\tprivate readonly tenantApiClient: GraphQlClient,\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly environment: Environment,\n\t\tprivate readonly onUpdate: (newData: TreeRootAccessor, binding: DataBinding) => void,\n\t\tprivate readonly onError: (error: RequestError, binding: DataBinding) => void,\n\t\tprivate readonly onPersistSuccess: (result: SuccessfulPersistResult, binding: DataBinding) => void,\n\t\tprivate readonly options: {\n\t\t\tskipStateUpdateAfterPersist: boolean\n\t\t},\n\t) {\n\t\tthis.config = new Config()\n\t\tthis.batchUpdatesOptions = createBatchUpdatesOptions(environment, this.treeStore)\n\t\tthis.asyncBatchUpdatesOptions = {\n\t\t\t...this.batchUpdatesOptions,\n\t\t\tcontentClient: contentApiClient,\n\t\t\tsystemClient: systemApiClient,\n\t\t\ttenantClient: tenantApiClient,\n\t\t}\n\t\tthis.dirtinessTracker = new DirtinessTracker()\n\t\tthis.eventManager = new EventManager(\n\t\t\tthis.asyncBatchUpdatesOptions,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.config,\n\t\t\tthis.dirtinessTracker,\n\t\t\tthis.resolvedOnUpdate,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.accessorErrorManager = new AccessorErrorManager(this.eventManager, this.treeStore)\n\t\tthis.stateInitializer = new StateInitializer(\n\t\t\tthis.accessorErrorManager,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.eventManager,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.treeAugmenter = new TreeAugmenter(this.eventManager, this.stateInitializer, this.treeStore, options.skipStateUpdateAfterPersist)\n\n\t\t// TODO move this elsewhere\n\t\tthis.bindingOperations = Object.freeze<BindingOperations>({\n\t\t\t...this.asyncBatchUpdatesOptions,\n\t\t\tgetTreeFilters: (): TreeFilter[] => {\n\t\t\t\tconst generator = new TreeFilterGenerator(this.treeStore)\n\t\t\t\treturn generator.generateTreeFilter()\n\t\t\t},\n\t\t\tbatchDeferredUpdates: performUpdates => {\n\t\t\t\tthis.eventManager.syncTransaction(() => performUpdates(this.bindingOperations))\n\t\t\t},\n\t\t\textendTree: async (...args) => await this.extendTree(...args),\n\t\t\tpersist: async options => await this.persist(options),\n\t\t})\n\t}\n\n\tprivate async persist({ onPersistError, onPersistSuccess, signal }: PersistOptions = {}) {\n\t\treturn await this.eventManager.persistOperation(async () => {\n\t\t\t// TODO if the tree is in an inconsistent state, wait for lock releases\n\n\t\t\tthis.eventManager.syncTransaction(() => {\n\t\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\t})\n\t\t\tawait this.eventManager.triggerOnBeforePersist()\n\n\t\t\tawait this.checkErrorsBeforePersist(onPersistError)\n\n\t\t\tconst generator = new MutationGenerator(this.treeStore)\n\t\t\tconst mutationResult = generator.getPersistMutation()\n\n\t\t\tif (mutationResult === undefined) {\n\t\t\t\tawait this.processEmptyPersistMutation(onPersistSuccess)\n\t\t\t\treturn {\n\t\t\t\t\ttype: 'nothingToPersist',\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst { query, operations } = mutationResult\n\n\t\t\tconst mutationResponse: MutationRequestResponse = await this.contentApiClient.sendRequest(query, {\n\t\t\t\tsignal,\n\t\t\t})\n\n\t\t\tif (mutationResponse.errors !== undefined && mutationResponse.errors.length > 0) {\n\t\t\t\tthis.onError({\n\t\t\t\t\ttype: 'gqlError',\n\t\t\t\t\tquery,\n\t\t\t\t\terrors: mutationResponse.errors,\n\t\t\t\t}, this)\n\t\t\t}\n\n\t\t\tif (!mutationResponse.data?.transaction) {\n\t\t\t\tthis.persistFail({\n\t\t\t\t\terrors: [],\n\t\t\t\t\ttype: 'invalidResponse',\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tconst { __typename, ok, errorMessage, ...mutationData } = mutationResponse.data.transaction\n\t\t\tif (Object.values(mutationData).every(it => it.ok)) {\n\t\t\t\treturn await this.processSuccessfulPersistResult(mutationData, operations, onPersistSuccess)\n\t\t\t} else {\n\t\t\t\tif (errorMessage) {\n\t\t\t\t\tconsole.error(errorMessage)\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(mutationData, operations))\n\n\t\t\t\tawait this.eventManager.triggerOnPersistError(this.bindingOperations)\n\t\t\t\tawait onPersistError?.(this.bindingOperations)\n\t\t\t\tthis.persistFail({\n\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t})\n\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async checkErrorsBeforePersist(onPersistError: PersistOptions['onPersistError']) {\n\t\tif (this.accessorErrorManager.hasErrors()) {\n\t\t\tawait this.eventManager.triggerOnPersistError(this.bindingOperations)\n\t\t\tawait onPersistError?.(this.bindingOperations)\n\t\t\tthis.persistFail({\n\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t}\n\n\tprivate async processEmptyPersistMutation(onPersistSuccess: PersistOptions['onPersistSuccess']): Promise<void> {\n\t\tthis.dirtinessTracker.reset() // TODO This ideally shouldn't be necessary but given the current limitations, this makes for better UX.\n\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t...this.bindingOperations,\n\t\t\tsuccessType: 'nothingToPersist',\n\t\t}\n\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\t}\n\n\tprivate async processSuccessfulPersistResult(mutationData: MutationDataResponse, operations: SubMutationOperation[], onPersistSuccess: PersistOptions['onPersistSuccess']) {\n\t\tconst persistedEntityIds = Object.values(mutationData).map(it => it.node?.id).filter(id => id !== undefined)\n\t\tconst result: SuccessfulPersistResult = {\n\t\t\ttype: 'justSuccess',\n\t\t\tpersistedEntityIds,\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.eventManager.asyncTransaction(async () => {\n\t\t\t\tthis.resetTreeAfterSuccessfulPersist()\n\t\t\t\tthis.treeAugmenter.updatePersistedData(\n\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\tObject.entries(mutationData).map(([placeholderName, subTreeResponse]) => [\n\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\tsubTreeResponse.node,\n\t\t\t\t\t\t]),\n\t\t\t\t\t),\n\t\t\t\t\toperations,\n\t\t\t\t)\n\t\t\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\tsuccessType: result.type,\n\t\t\t\t}\n\t\t\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\t\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\n\t\t\t\tthis.treeAugmenter.resetCreatingSubTrees()\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\tconst resultWithError = {\n\t\t\t\t...result,\n\t\t\t\tafterPersistError: e,\n\t\t\t}\n\t\t\tthis.onPersistSuccess(resultWithError, this)\n\t\t\treturn resultWithError\n\t\t}\n\t\tthis.onPersistSuccess(result, this)\n\t\treturn result\n\t}\n\n\tprivate persistFail(error: ErrorPersistResult): never {\n\t\tthrow error\n\t}\n\n\tprivate resolvedOnUpdate = ({ isMutating }: UpdateMetadata) => {\n\t\tthis.onUpdate(new TreeRootAccessor(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations), this)\n\t}\n\n\t// This is currently useless but potentially future-compatible\n\t// private readonly addTreeRootEventListener: TreeRootAccessor.AddTreeRootEventListener = this.getAddEventListener(\n\t// \tthis.treeRootListeners,\n\t// )\n\n\tprivate pendingExtensions: Set<{\n\t\tmarkerTreeRoot: MarkerTreeRoot\n\t\tnewFragment: ReactNode\n\t\tnewTreeRootId: TreeRootId | undefined\n\t\toptions: ExtendTreeOptions\n\t\treject: () => void\n\t\tresolve: (newRootId: TreeRootId | undefined) => void\n\t}> = new Set()\n\n\tpublic async extendTree(newFragment: ReactNode, options: ExtendTreeOptions = {}): Promise<TreeRootId | undefined> {\n\t\tif (options.signal?.aborted) {\n\t\t\treturn Promise.reject(DataBindingExtendAborted)\n\t\t}\n\t\tconst markerTreeRoot = new MarkerTreeGenerator(newFragment, options.environment ?? this.environment).generate()\n\n\t\tif (this.treeStore.effectivelyHasTreeRoot(markerTreeRoot)) {\n\t\t\t// This isn't perfectly accurate as theoretically, we could already have all the data necessary but this\n\t\t\t// could still be false.\n\n\t\t\treturn this.eventManager.syncOperation(() => {\n\t\t\t\tconst newTreeRootId = this.getNewTreeRootId()\n\t\t\t\tthis.treeAugmenter.extendTreeStates(newTreeRootId, markerTreeRoot)\n\t\t\t\treturn newTreeRootId\n\t\t\t})\n\t\t}\n\n\t\treturn await new Promise((resolve, reject) => {\n\t\t\tthis.pendingExtensions.add({\n\t\t\t\tmarkerTreeRoot,\n\t\t\t\tnewFragment,\n\t\t\t\tnewTreeRootId: this.getNewTreeRootId(),\n\t\t\t\toptions,\n\t\t\t\treject: () => reject(DataBindingExtendAborted),\n\t\t\t\tresolve,\n\t\t\t})\n\t\t\tconst pendingExtensionsCount = this.pendingExtensions.size\n\n\t\t\tPromise.resolve().then(() => {\n\t\t\t\tif (pendingExtensionsCount < this.pendingExtensions.size) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.flushBatchedTreeExtensions()\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async flushBatchedTreeExtensions() {\n\t\t// This is an async operation so we just take whatever pendingExtensions there are now and let any new ones\n\t\t// accumulate in an empty set.\n\t\tconst pendingExtensions = Array.from(this.pendingExtensions).filter(extension => {\n\t\t\tif (extension.options.signal?.aborted) {\n\t\t\t\textension.reject()\n\t\t\t\treturn false\n\t\t\t}\n\t\t\treturn true\n\t\t})\n\t\tthis.pendingExtensions.clear()\n\n\t\tconst aggregateMarkerTreeRoot = pendingExtensions.reduce<MarkerTreeRoot | undefined>(\n\t\t\t(previousValue, currentValue) => {\n\t\t\t\tif (previousValue === undefined) {\n\t\t\t\t\treturn currentValue.markerTreeRoot\n\t\t\t\t}\n\t\t\t\treturn MarkerMerger.mergeMarkerTreeRoots(previousValue, currentValue.markerTreeRoot)\n\t\t\t},\n\t\t\tundefined,\n\t\t)\n\n\t\tif (aggregateMarkerTreeRoot === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tconst aggregateSignal = getCombinedSignal(pendingExtensions.map(extension => extension.options.signal))\n\n\t\tconst aggregatePersistedData = await this.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal)\n\n\t\tif (aggregateSignal?.aborted || aggregatePersistedData === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.treeAugmenter.extendPersistedData(aggregatePersistedData.data, aggregateMarkerTreeRoot)\n\n\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\tthis.treeAugmenter.extendTreeStates(extension.newTreeRootId, extension.markerTreeRoot)\n\t\t\t\textension.resolve(extension.newTreeRootId)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async fetchPersistedData(\n\t\ttree: MarkerTreeRoot,\n\t\tsignal?: AbortSignal,\n\t): Promise<QueryRequestResponse | undefined> {\n\t\tconst queryGenerator = new QueryGenerator(tree)\n\t\tconst query = queryGenerator.getReadQuery()\n\n\t\tlet queryResponse: QueryRequestResponse | undefined = undefined\n\n\t\ttry {\n\t\t\tqueryResponse =\n\t\t\t\tquery === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: await this.contentApiClient.sendRequest(query, {\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t })\n\t\t} catch (metadata) {\n\t\t\tif (typeof metadata === 'object' && metadata !== null && (metadata as { name?: unknown }).name === 'AbortError') {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.onError(metadataToRequestError(metadata as GraphQlClientFailedRequestMetadata), this)\n\t\t}\n\n\t\tif (queryResponse && queryResponse.errors !== undefined && queryResponse.errors.length > 0) {\n\t\t\tthis.onError({\n\t\t\t\ttype: 'gqlError',\n\t\t\t\tquery: query ?? 'unknown query',\n\t\t\t\terrors: queryResponse.errors,\n\t\t\t}, this)\n\t\t}\n\n\t\treturn queryResponse\n\t}\n\n\tprivate resetTreeAfterSuccessfulPersist() {\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\tthis.dirtinessTracker.reset()\n\n\t\t\tfor (const [, rootState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const state of StateIterator.depthFirstAllNodes(rootState)) {\n\t\t\t\t\tswitch (state.type) {\n\t\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\t\tif (state.hasUnpersistedChanges || state.touchLog?.size) {\n\t\t\t\t\t\t\t\tstate.touchLog?.clear()\n\t\t\t\t\t\t\t\tstate.hasUnpersistedChanges = false\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedRemovals?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedRemovals?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedHasOneDeletions?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedHasOneDeletions?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tassertNever(state)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate static getNextTreeRootIdSeed = (() => {\n\t\tlet seed = 1\n\t\treturn () => seed++\n\t})()\n\n\tprivate getNewTreeRootId() {\n\t\t// TODO this is an awful, awful hack.\n\t\t// TODO the particular shape of the alias is relied on in MutationAlias. If you change this, change it there too.\n\t\treturn this.treeStore.markerTrees.size === 0\n\t\t\t? undefined\n\t\t\t: `${generateEnumerabilityPreventingEntropy()}-${DataBinding.getNextTreeRootIdSeed()}`\n\t}\n}\n\nexport const DataBindingExtendAborted = Symbol('aborted')\n"],"names":["options"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAwCO,MAAM,eAAN,MAAkB;AAAA,EAiBjB,YACW,kBACA,iBACA,iBACA,WACA,aACA,UACA,SACA,kBACA,SAGhB;AA5Be;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAgMT,4CAAmB,CAAC,EAAE,iBAAiC;AACzD,WAAA,SAAS,IAAI,iBAAiB,KAAK,iBAAiB,WAAW,GAAG,YAAY,KAAK,iBAAiB,GAAG,IAAI;AAAA,IAAA;AAQzG,iEAOC;AAvMS,SAAA,mBAAA;AACA,SAAA,kBAAA;AACA,SAAA,kBAAA;AACA,SAAA,YAAA;AACA,SAAA,cAAA;AACA,SAAA,WAAA;AACA,S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AgB,MAAM;AACvC,WAAK,qBAAqB;AAC1B,WAAK,iBAAiB;AAEX,iBAAA,CAAG,EAAA,SAAS,KAAK,cAAc,cAAc,KAAK,SAAS,GAAG;AACxE,mBAAW,SAAS,cAAc,mBAAmB,SAAS,GAAG;AAChE,kBAAQ,MAAM;AAAA,iBACR,SAAS;AACb,kBAAI,MAAM,yBAAyB,MAAM,UAAU,MAAM;AACxD,sBAAM,UAAU;AAChB,sBAAM,wBAAwB;AAC9B,qBAAK,aAAa,oBAAoB,OAAO,aAAa,qBAAqB;AAAA,cAChF;AACA;AAAA,YACD;AAAA,iBACK;AACJ,kBAAI,MAAM,0BAA0B,KAAK,MAAM,iBAAiB,MAAM;AACrE,sBAAM,0BAA0B;AAChC,sBAAM,iBAAiB;AACvB,qBAAK,aAAa,oBAAoB,OAAO,aAAa,qBAAqB;AAAA,cAChF;AACA;AAAA,iBACI,eAAe;AACnB,kBAAI,MAAM,0BAA0B,KAAK,MAAM,wBAAwB,MAAM;AAC5E,sBAAM,0BAA0B;AAChC,sBAAM,wBAAwB;AAC9B,qBAAK,aAAa,oBAAoB,OAAO,aAAa,qBAAqB;AAAA,cAChF;AACA;AAAA,YACD;AAAA;AAEC,0BAAiB;AAAA;AAAA,QAEpB;AAAA,MACD;AAAA,IAAA,CACA;AAAA,EACF;AAAA,EAOQ,mBAAmB;AAGnB,WAAA,KAAK,UAAU,YAAY,SAAS,IACxC,SACA,GAAG,uCAA4C,KAAA,aAAY,sBAAsB;AAAA,EACrF;AACD;AAjYO,IAAM,cAAN;AAqXN,cArXY,aAqXG,0BAAyB,MAAM;AAC7C,MAAI,OAAO;AACX,SAAO,MAAM;AAAA;AAYF,MAAA,2BAA2B,OAAO,SAAS;"}
1
+ {"version":3,"file":"DataBinding.js","sources":["../../../src/core/DataBinding.ts"],"sourcesContent":["import type { GraphQlClient, GraphQlClientFailedRequestMetadata, TreeFilter } from '@contember/client'\nimport type { ReactNode } from 'react'\nimport {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tBindingOperations,\n\tExtendTreeOptions,\n\tPersistErrorOptions, PersistOptions,\n\tPersistSuccessOptions,\n\tTreeRootAccessor,\n} from '../accessors'\nimport {\n\tErrorPersistResult,\n\tmetadataToRequestError, MutationDataResponse,\n\tMutationRequestResponse,\n\tQueryRequestResponse,\n\tRequestError,\n\tSuccessfulPersistResult,\n} from '../accessorTree'\nimport type { Environment } from '../dao'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { TreeRootId } from '../treeParameters'\nimport { assertNever, generateEnumerabilityPreventingEntropy } from '../utils'\nimport { AccessorErrorManager } from './AccessorErrorManager'\nimport { Config } from './Config'\nimport { DirtinessTracker } from './DirtinessTracker'\nimport { EventManager } from './EventManager'\nimport { createBatchUpdatesOptions } from './factories'\nimport { MarkerMerger } from './MarkerMerger'\nimport { MarkerTreeGenerator } from './MarkerTreeGenerator'\nimport { MutationGenerator, SubMutationOperation } from './MutationGenerator'\nimport { QueryGenerator } from './QueryGenerator'\nimport { StateIterator } from './state'\nimport { StateInitializer } from './StateInitializer'\nimport { TreeAugmenter } from './TreeAugmenter'\nimport { TreeFilterGenerator } from './TreeFilterGenerator'\nimport { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport { getCombinedSignal } from './utils'\n\nexport class DataBinding {\n\tprivate readonly accessorErrorManager: AccessorErrorManager\n\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions\n\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions\n\tprivate readonly bindingOperations: BindingOperations\n\tprivate readonly config: Config\n\tprivate readonly dirtinessTracker: DirtinessTracker\n\tprivate readonly eventManager: EventManager\n\tprivate readonly stateInitializer: StateInitializer\n\tprivate readonly treeAugmenter: TreeAugmenter\n\n\t// private treeRootListeners: {\n\t// \teventListeners: {}\n\t// } = {\n\t// \teventListeners: {},\n\t// }\n\n\tpublic constructor(\n\t\tprivate readonly contentApiClient: GraphQlClient,\n\t\tprivate readonly systemApiClient: GraphQlClient,\n\t\tprivate readonly tenantApiClient: GraphQlClient,\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly environment: Environment,\n\t\tprivate readonly onUpdate: (newData: TreeRootAccessor, binding: DataBinding) => void,\n\t\tprivate readonly onError: (error: RequestError, binding: DataBinding) => void,\n\t\tprivate readonly onPersistSuccess: (result: SuccessfulPersistResult, binding: DataBinding) => void,\n\t\tprivate readonly options: {\n\t\t\tskipStateUpdateAfterPersist: boolean\n\t\t},\n\t) {\n\t\tthis.config = new Config()\n\t\tthis.batchUpdatesOptions = createBatchUpdatesOptions(environment, this.treeStore)\n\t\tthis.asyncBatchUpdatesOptions = {\n\t\t\t...this.batchUpdatesOptions,\n\t\t\tcontentClient: contentApiClient,\n\t\t\tsystemClient: systemApiClient,\n\t\t\ttenantClient: tenantApiClient,\n\t\t}\n\t\tthis.dirtinessTracker = new DirtinessTracker()\n\t\tthis.eventManager = new EventManager(\n\t\t\tthis.asyncBatchUpdatesOptions,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.config,\n\t\t\tthis.dirtinessTracker,\n\t\t\tthis.resolvedOnUpdate,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.accessorErrorManager = new AccessorErrorManager(this.eventManager, this.treeStore)\n\t\tthis.stateInitializer = new StateInitializer(\n\t\t\tthis.accessorErrorManager,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.eventManager,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.treeAugmenter = new TreeAugmenter(this.eventManager, this.stateInitializer, this.treeStore, options.skipStateUpdateAfterPersist)\n\n\t\t// TODO move this elsewhere\n\t\tthis.bindingOperations = Object.freeze<BindingOperations>({\n\t\t\t...this.asyncBatchUpdatesOptions,\n\t\t\tgetTreeFilters: (): TreeFilter[] => {\n\t\t\t\tconst generator = new TreeFilterGenerator(this.treeStore)\n\t\t\t\treturn generator.generateTreeFilter()\n\t\t\t},\n\t\t\tbatchDeferredUpdates: performUpdates => {\n\t\t\t\tthis.eventManager.syncTransaction(() => performUpdates(this.bindingOperations))\n\t\t\t},\n\t\t\textendTree: async (...args) => await this.extendTree(...args),\n\t\t\tpersist: async options => await this.persist(options),\n\t\t})\n\t}\n\n\tprivate async persist({ onPersistError, onPersistSuccess, signal }: PersistOptions = {}) {\n\t\treturn await this.eventManager.persistOperation(async () => {\n\t\t\t// TODO if the tree is in an inconsistent state, wait for lock releases\n\n\t\t\tthis.eventManager.syncTransaction(() => {\n\t\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\t})\n\t\t\tawait this.eventManager.triggerOnBeforePersist()\n\n\t\t\tawait this.checkErrorsBeforePersist(onPersistError)\n\n\t\t\tconst generator = new MutationGenerator(this.treeStore)\n\t\t\tconst mutationResult = generator.getPersistMutation()\n\n\t\t\tif (mutationResult === undefined) {\n\t\t\t\tawait this.processEmptyPersistMutation(onPersistSuccess)\n\t\t\t\treturn {\n\t\t\t\t\ttype: 'nothingToPersist',\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst { query, operations } = mutationResult\n\n\t\t\tconst mutationResponse: MutationRequestResponse = await this.contentApiClient.sendRequest(query, {\n\t\t\t\tsignal,\n\t\t\t})\n\n\t\t\tif (mutationResponse.errors !== undefined && mutationResponse.errors.length > 0) {\n\t\t\t\tthis.onError({\n\t\t\t\t\ttype: 'gqlError',\n\t\t\t\t\tquery,\n\t\t\t\t\terrors: mutationResponse.errors,\n\t\t\t\t}, this)\n\t\t\t}\n\n\t\t\tif (!mutationResponse.data?.transaction) {\n\t\t\t\tthis.persistFail({\n\t\t\t\t\terrors: [],\n\t\t\t\t\ttype: 'invalidResponse',\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tconst { __typename, ok, errorMessage, ...mutationData } = mutationResponse.data.transaction\n\t\t\tif (Object.values(mutationData).every(it => it.ok)) {\n\t\t\t\treturn await this.processSuccessfulPersistResult(mutationData, operations, onPersistSuccess)\n\t\t\t} else {\n\t\t\t\tif (errorMessage) {\n\t\t\t\t\tconsole.error(errorMessage)\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(mutationData, operations))\n\n\t\t\t\tawait this.eventManager.triggerOnPersistError(this.bindingOperations)\n\t\t\t\tawait onPersistError?.(this.bindingOperations)\n\t\t\t\tthis.persistFail({\n\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t})\n\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async checkErrorsBeforePersist(onPersistError: PersistOptions['onPersistError']) {\n\t\tif (this.accessorErrorManager.hasErrors()) {\n\t\t\tawait this.eventManager.triggerOnPersistError(this.bindingOperations)\n\t\t\tawait onPersistError?.(this.bindingOperations)\n\t\t\tthis.persistFail({\n\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t}\n\n\tprivate async processEmptyPersistMutation(onPersistSuccess: PersistOptions['onPersistSuccess']): Promise<void> {\n\t\tthis.dirtinessTracker.reset() // TODO This ideally shouldn't be necessary but given the current limitations, this makes for better UX.\n\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t...this.bindingOperations,\n\t\t\tsuccessType: 'nothingToPersist',\n\t\t}\n\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\t}\n\n\tprivate async processSuccessfulPersistResult(mutationData: MutationDataResponse, operations: SubMutationOperation[], onPersistSuccess: PersistOptions['onPersistSuccess']) {\n\t\tconst persistedEntityIds = Object.values(mutationData).map(it => it.node?.id).filter(id => id !== undefined)\n\t\tconst result: SuccessfulPersistResult = {\n\t\t\ttype: 'justSuccess',\n\t\t\tpersistedEntityIds,\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.eventManager.asyncTransaction(async () => {\n\t\t\t\tthis.resetTreeAfterSuccessfulPersist()\n\t\t\t\tthis.treeAugmenter.updatePersistedData(\n\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\tObject.entries(mutationData).map(([placeholderName, subTreeResponse]) => [\n\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\tsubTreeResponse.node,\n\t\t\t\t\t\t]),\n\t\t\t\t\t),\n\t\t\t\t\toperations,\n\t\t\t\t)\n\t\t\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\tsuccessType: result.type,\n\t\t\t\t}\n\t\t\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\t\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\n\t\t\t\tthis.treeAugmenter.resetCreatingSubTrees()\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\tconst resultWithError = {\n\t\t\t\t...result,\n\t\t\t\tafterPersistError: e,\n\t\t\t}\n\t\t\tthis.onPersistSuccess(resultWithError, this)\n\t\t\treturn resultWithError\n\t\t}\n\t\tthis.onPersistSuccess(result, this)\n\t\treturn result\n\t}\n\n\tprivate persistFail(error: ErrorPersistResult): never {\n\t\tthrow error\n\t}\n\n\tprivate resolvedOnUpdate = ({ isMutating }: UpdateMetadata) => {\n\t\tthis.onUpdate(new TreeRootAccessor(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations), this)\n\t}\n\n\t// This is currently useless but potentially future-compatible\n\t// private readonly addTreeRootEventListener: TreeRootAccessor.AddTreeRootEventListener = this.getAddEventListener(\n\t// \tthis.treeRootListeners,\n\t// )\n\n\tprivate pendingExtensions: Set<{\n\t\tmarkerTreeRoot: MarkerTreeRoot\n\t\tnewFragment: ReactNode\n\t\tnewTreeRootId: TreeRootId | undefined\n\t\toptions: ExtendTreeOptions\n\t\treject: () => void\n\t\tresolve: (newRootId: TreeRootId | undefined) => void\n\t}> = new Set()\n\n\tpublic async extendTree(newFragment: ReactNode, options: ExtendTreeOptions = {}): Promise<TreeRootId | undefined> {\n\t\tif (options.signal?.aborted) {\n\t\t\treturn Promise.reject(DataBindingExtendAborted)\n\t\t}\n\t\tconst markerTreeRoot = new MarkerTreeGenerator(newFragment, options.environment ?? this.environment).generate()\n\n\t\tif (this.treeStore.effectivelyHasTreeRoot(markerTreeRoot)) {\n\t\t\t// This isn't perfectly accurate as theoretically, we could already have all the data necessary but this\n\t\t\t// could still be false.\n\n\t\t\treturn this.eventManager.syncOperation(() => {\n\t\t\t\tconst newTreeRootId = this.getNewTreeRootId()\n\t\t\t\tthis.treeAugmenter.extendTreeStates(newTreeRootId, markerTreeRoot)\n\t\t\t\treturn newTreeRootId\n\t\t\t})\n\t\t}\n\n\t\treturn await new Promise((resolve, reject) => {\n\t\t\tthis.pendingExtensions.add({\n\t\t\t\tmarkerTreeRoot,\n\t\t\t\tnewFragment,\n\t\t\t\tnewTreeRootId: this.getNewTreeRootId(),\n\t\t\t\toptions,\n\t\t\t\treject: () => reject(DataBindingExtendAborted),\n\t\t\t\tresolve,\n\t\t\t})\n\t\t\tconst pendingExtensionsCount = this.pendingExtensions.size\n\n\t\t\tPromise.resolve().then(() => {\n\t\t\t\tif (pendingExtensionsCount < this.pendingExtensions.size) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.flushBatchedTreeExtensions()\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async flushBatchedTreeExtensions() {\n\t\t// This is an async operation so we just take whatever pendingExtensions there are now and let any new ones\n\t\t// accumulate in an empty set.\n\t\tconst pendingExtensions = Array.from(this.pendingExtensions).filter(extension => {\n\t\t\tif (extension.options.signal?.aborted) {\n\t\t\t\textension.reject()\n\t\t\t\treturn false\n\t\t\t}\n\t\t\treturn true\n\t\t})\n\t\tthis.pendingExtensions.clear()\n\n\t\tconst aggregateMarkerTreeRoot = pendingExtensions.reduce<MarkerTreeRoot | undefined>(\n\t\t\t(previousValue, currentValue) => {\n\t\t\t\tif (previousValue === undefined) {\n\t\t\t\t\treturn currentValue.markerTreeRoot\n\t\t\t\t}\n\t\t\t\treturn MarkerMerger.mergeMarkerTreeRoots(previousValue, currentValue.markerTreeRoot)\n\t\t\t},\n\t\t\tundefined,\n\t\t)\n\n\t\tif (aggregateMarkerTreeRoot === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tconst aggregateSignal = getCombinedSignal(pendingExtensions.map(extension => extension.options.signal))\n\n\t\tconst aggregatePersistedData = await this.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal)\n\n\t\tif (aggregateSignal?.aborted || aggregatePersistedData === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.treeAugmenter.extendPersistedData(aggregatePersistedData.data, aggregateMarkerTreeRoot)\n\n\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\tthis.treeAugmenter.extendTreeStates(extension.newTreeRootId, extension.markerTreeRoot)\n\t\t\t\textension.resolve(extension.newTreeRootId)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async fetchPersistedData(\n\t\ttree: MarkerTreeRoot,\n\t\tsignal?: AbortSignal,\n\t): Promise<QueryRequestResponse | undefined> {\n\t\tconst queryGenerator = new QueryGenerator(tree)\n\t\tconst query = queryGenerator.getReadQuery()\n\n\t\tlet queryResponse: QueryRequestResponse | undefined = undefined\n\n\t\ttry {\n\t\t\tqueryResponse =\n\t\t\t\tquery === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: await this.contentApiClient.sendRequest(query, {\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t })\n\t\t} catch (metadata) {\n\t\t\tif (typeof metadata === 'object' && metadata !== null && (metadata as { name?: unknown }).name === 'AbortError') {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.onError(metadataToRequestError(metadata as GraphQlClientFailedRequestMetadata), this)\n\t\t}\n\n\t\tif (queryResponse && queryResponse.errors !== undefined && queryResponse.errors.length > 0) {\n\t\t\tthis.onError({\n\t\t\t\ttype: 'gqlError',\n\t\t\t\tquery: query ?? 'unknown query',\n\t\t\t\terrors: queryResponse.errors,\n\t\t\t}, this)\n\t\t}\n\n\t\treturn queryResponse\n\t}\n\n\tprivate resetTreeAfterSuccessfulPersist() {\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\tthis.dirtinessTracker.reset()\n\n\t\t\tfor (const [, rootState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const state of StateIterator.depthFirstAllNodes(rootState)) {\n\t\t\t\t\tswitch (state.type) {\n\t\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\t\tif (state.hasUnpersistedChanges || state.touchLog?.size) {\n\t\t\t\t\t\t\t\tstate.touchLog?.clear()\n\t\t\t\t\t\t\t\tstate.hasUnpersistedChanges = false\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedRemovals?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedRemovals?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedHasOneDeletions?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedHasOneDeletions?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tassertNever(state)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate static getNextTreeRootIdSeed = (() => {\n\t\tlet seed = 1\n\t\treturn () => seed++\n\t})()\n\n\tprivate getNewTreeRootId() {\n\t\t// TODO this is an awful, awful hack.\n\t\t// TODO the particular shape of the alias is relied on in MutationAlias. If you change this, change it there too.\n\t\treturn this.treeStore.markerTrees.size === 0\n\t\t\t? undefined\n\t\t\t: `${generateEnumerabilityPreventingEntropy()}-${DataBinding.getNextTreeRootIdSeed()}`\n\t}\n}\n\nexport const DataBindingExtendAborted = Symbol('aborted')\n"],"names":["options"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAwCO,MAAM,eAAN,MAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBjB,YACW,kBACA,iBACA,iBACA,WACA,aACA,UACA,SACA,kBACA,SAGhB;AA5Be;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAgMT,4CAAmB,CAAC,EAAE,iBAAiC;AACzD,WAAA,SAAS,IAAI,iBAAiB,KAAK,iBAAiB,WAAW,GAAG,YAAY,KAAK,iBAAiB,GAAG,IAAI;AAAA,IAAA;AAQzG;AAAA;AAAA;AAAA;AAAA,iEAOC;AAvMS,SAAA,mBAAA;AACA,SAAA,kBAAA;AACA,SAAA,kBAAA;AACA,SAAA,YAAA;AACA,SAAA,cAAA;AACA,SAAA,WAAA;AACA,SAAA,UAAA;AACA,SAAA,mBAAA;AACA,SAAA,UAAA;AAIZ,SAAA,SAAS,IAAI;AAClB,SAAK,sBAAsB,0BAA0B,aAAa,KAAK,SAAS;AAChF,SAAK,2BAA2B;AAAA,MAC/B,GAAG,KAAK;AAAA,MACR,eAAe;AAAA,MACf,cAAc;AAAA,MACd,cAAc;AAAA,IAAA;AAEV,SAAA,mBAAmB,IAAI;AAC5B,SAAK,eAAe,IAAI;AAA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U;AAChB,sBAAM,wBAAwB;AAC9B,qBAAK,aAAa,oBAAoB,OAAO,aAAa,qBAAqB;AAAA,cAChF;AACA;AAAA,YACD;AAAA,YACA,KAAK;AACJ,kBAAI,MAAM,0BAA0B,KAAK,MAAM,iBAAiB,MAAM;AACrE,sBAAM,0BAA0B;AAChC,sBAAM,iBAAiB;AACvB,qBAAK,aAAa,oBAAoB,OAAO,aAAa,qBAAqB;AAAA,cAChF;AACA;AAAA,YACD,KAAK,eAAe;AACnB,kBAAI,MAAM,0BAA0B,KAAK,MAAM,wBAAwB,MAAM;AAC5E,sBAAM,0BAA0B;AAChC,sBAAM,wBAAwB;AAC9B,qBAAK,aAAa,oBAAoB,OAAO,aAAa,qBAAqB;AAAA,cAChF;AACA;AAAA,YACD;AAAA,YACA;AACC,0BAAiB;AAAA,UACnB;AAAA,QACD;AAAA,MACD;AAAA,IAAA,CACA;AAAA,EACF;AAAA,EAOQ,mBAAmB;AAGnB,WAAA,KAAK,UAAU,YAAY,SAAS,IACxC,SACA,GAAG,uCAA4C,KAAA,aAAY,sBAAsB;AAAA,EACrF;AACD;AAjYO,IAAM,cAAN;AAqXN,cArXY,aAqXG,0BAAyB,MAAM;AAC7C,MAAI,OAAO;AACX,SAAO,MAAM;AAAA;AAYF,MAAA,2BAA2B,OAAO,SAAS;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorsPreprocessor.js","sources":["../../../src/core/ErrorsPreprocessor.ts"],"sourcesContent":["import type { ErrorAccessor } from '../accessors'\nimport type { ExecutionError, MutationDataResponse, MutationResponse, ValidationError } from '../accessorTree'\nimport type { EntityId, FieldName, PlaceholderName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport { MutationAlias } from './requestAliases'\nimport { SubMutationOperation } from './MutationGenerator'\n\nclass ErrorsPreprocessor {\n\tpublic constructor(\n\t\tprivate readonly requestResponse: MutationDataResponse,\n\t\tprivate readonly operations: SubMutationOperation[],\n\t) {}\n\n\tpublic preprocess(): ErrorsPreprocessor.ErrorTreeRoot {\n\t\tconst treeRoot: ErrorsPreprocessor.ErrorTreeRoot = new Map()\n\n\t\tif (this.requestResponse === undefined) {\n\t\t\treturn treeRoot\n\t\t}\n\n\t\tfor (const operation of this.operations) {\n\t\t\tconst mutationResponse = this.requestResponse[operation.alias]\n\t\t\tconst processedResponse = this.processMutationResponse(mutationResponse)\n\n\t\t\tif (processedResponse === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst { subTreeType, subTreePlaceholder, id } = operation\n\n\t\t\tif (subTreeType === 'single') {\n\t\t\t\tif (treeRoot.has(subTreePlaceholder)) {\n\t\t\t\t\treturn this.rejectCorruptData()\n\t\t\t\t}\n\t\t\t\ttreeRoot.set(subTreePlaceholder, processedResponse)\n\t\t\t} else if (subTreeType === 'list') {\n\t\t\t\tconst child = treeRoot.get(subTreePlaceholder)\n\n\t\t\t\tif (child === undefined) {\n\t\t\t\t\ttreeRoot.set(subTreePlaceholder, {\n\t\t\t\t\t\tnodeType: 'iNode',\n\t\t\t\t\t\tchildren: new Map([[id, processedResponse]]),\n\t\t\t\t\t\tvalidation: [],\n\t\t\t\t\t\texecution: [],\n\t\t\t\t\t})\n\t\t\t\t} else if (child.nodeType === 'iNode') {\n\t\t\t\t\tchild.children.set(id, processedResponse)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn assertNever(subTreeType)\n\t\t\t}\n\n\t\t}\n\t\treturn treeRoot\n\t}\n\n\tprivate processMutationResponse(mutationResponse: MutationResponse): ErrorsPreprocessor.ErrorNode | undefined {\n\t\tif (mutationResponse.ok && mutationResponse.validation?.valid && mutationResponse.errors.length === 0) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (mutationResponse.validation?.errors.length) {\n\t\t\treturn this.getErrorNode(mutationResponse.validation?.errors)\n\t\t}\n\t\tif (mutationResponse.errors.length) {\n\t\t\treturn this.getErrorNode(mutationResponse.errors)\n\t\t}\n\t\treturn undefined\n\t}\n\n\tprivate getErrorNode(errors: ValidationError[] | ExecutionError[]): ErrorsPreprocessor.ErrorNode {\n\t\tconst [head, ...tail] = errors\n\n\t\tlet rootNode = this.getRootNode(head)\n\n\t\terrorLoop: for (const error of tail) {\n\t\t\tlet currentNode = rootNode\n\n\t\t\tfor (let i = 0, pathLength = error.path.length; i < pathLength; i++) {\n\t\t\t\tconst pathNode = error.path[i]\n\n\t\t\t\tif (currentNode.nodeType === 'leaf') {\n\t\t\t\t\t(currentNode as any as ErrorsPreprocessor.ErrorINode).nodeType = 'iNode'\n\t\t\t\t\t;(currentNode as any as ErrorsPreprocessor.ErrorINode).children = new Map()\n\t\t\t\t}\n\n\t\t\t\tif (pathNode.__typename === '_FieldPathFragment') {\n\t\t\t\t\tif (currentNode.nodeType === 'iNode') {\n\t\t\t\t\t\tlet alias = pathNode.field\n\t\t\t\t\t\tlet nextIndex = i + 1\n\t\t\t\t\t\tif (nextIndex in error.path) {\n\t\t\t\t\t\t\tconst nextPathNode = error.path[nextIndex]\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tnextPathNode.__typename === '_IndexPathFragment' &&\n\t\t\t\t\t\t\t\ttypeof nextPathNode.alias === 'string' &&\n\t\t\t\t\t\t\t\tnextPathNode.alias.startsWith(pathNode.field)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t// We're dealing with a reduced hasMany relation.\n\t\t\t\t\t\t\t\ti++\n\t\t\t\t\t\t\t\tnextIndex++\n\t\t\t\t\t\t\t\talias = nextPathNode.alias\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!(alias in currentNode.children)) {\n\t\t\t\t\t\t\tcurrentNode.children.set(alias, this.getRootNode(error, nextIndex))\n\t\t\t\t\t\t\tif (nextIndex <= error.path.length) {\n\t\t\t\t\t\t\t\t// This path has been handled by getRootNode\n\t\t\t\t\t\t\t\tcontinue errorLoop\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurrentNode = currentNode.children.get(alias)!\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.rejectCorruptData()\n\t\t\t\t\t}\n\t\t\t\t} else if (pathNode.__typename === '_IndexPathFragment') {\n\t\t\t\t\tif (currentNode.nodeType === 'iNode') {\n\t\t\t\t\t\tconst alias = pathNode.alias\n\n\t\t\t\t\t\tif (alias === null) {\n\t\t\t\t\t\t\tthrow new ErrorsPreprocessor.ErrorsPreprocessorError(\n\t\t\t\t\t\t\t\t`Corrupt data: undefined alias for node with index ${pathNode.index}.`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst entityId = MutationAlias.decodeEntityId(alias)\n\n\t\t\t\t\t\tif (!(entityId in currentNode.children)) {\n\t\t\t\t\t\t\tcurrentNode.children.set(entityId, this.getRootNode(error, i + 1))\n\t\t\t\t\t\t\tif (i + 1 <= error.path.length) {\n\t\t\t\t\t\t\t\t// This path has been handled by getRootNode\n\t\t\t\t\t\t\t\tcontinue errorLoop\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurrentNode = currentNode.children.get(entityId)!\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.rejectCorruptData()\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(pathNode)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (this.isExecutionError(error)) {\n\t\t\t\tcurrentNode.execution.push({ type: 'execution', code: error.type, developerMessage: error.message })\n\t\t\t} else {\n\t\t\t\tcurrentNode.validation.push(this.createValidationError(error.message.text))\n\t\t\t}\n\t\t}\n\n\t\treturn rootNode\n\t}\n\n\tprivate getRootNode(error: ValidationError | ExecutionError, startIndex: number = 0): ErrorsPreprocessor.ErrorNode {\n\t\tlet rootNode: ErrorsPreprocessor.ErrorNode = {\n\t\t\tvalidation: this.isExecutionError(error) ? [] : [this.createValidationError(error.message.text)],\n\t\t\texecution: this.isExecutionError(error) ? [{ type: 'execution', code: error.type, developerMessage: error.message }] : [],\n\t\t\tnodeType: 'leaf',\n\t\t}\n\n\t\tfor (let i = error.path.length - 1; i >= startIndex; i--) {\n\t\t\tconst pathNode = error.path[i]\n\t\t\tif (pathNode.__typename === '_FieldPathFragment') {\n\t\t\t\trootNode = {\n\t\t\t\t\tvalidation: [],\n\t\t\t\t\texecution: [],\n\t\t\t\t\tnodeType: 'iNode',\n\t\t\t\t\tchildren: new Map([[pathNode.field, rootNode]]),\n\t\t\t\t}\n\t\t\t} else if (pathNode.__typename === '_IndexPathFragment') {\n\t\t\t\tconst alias = pathNode.alias\n\n\t\t\t\tif (alias === null) {\n\t\t\t\t\tthrow new ErrorsPreprocessor.ErrorsPreprocessorError(\n\t\t\t\t\t\t`Corrupt data: undefined alias for node with index ${pathNode.index}.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\trootNode = {\n\t\t\t\t\tvalidation: [],\n\t\t\t\t\texecution: [],\n\t\t\t\t\tnodeType: 'iNode',\n\t\t\t\t\tchildren: new Map([[MutationAlias.decodeEntityId(alias), rootNode]]),\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tassertNever(pathNode)\n\t\t\t}\n\t\t}\n\n\t\treturn rootNode\n\t}\n\n\tprivate createValidationError(message: string): ErrorAccessor.ValidationError {\n\t\tif (message === 'Field is required') {\n\t\t\t// TODO this is just awful. Validation errors currently don't have error codes which makes it more difficult\n\t\t\t// \tto translate the error messages. This is the most common such error, and so we just make up a code\n\t\t\t// \tin order to facilitate error handling further downstream.\n\t\t\treturn {\n\t\t\t\ttype: 'validation',\n\t\t\t\tcode: 'fieldRequired',\n\t\t\t\tmessage,\n\t\t\t}\n\t\t}\n\t\treturn { type: 'validation', message, code: undefined }\n\t}\n\n\tprivate isExecutionError(error: ValidationError | ExecutionError): error is ExecutionError {\n\t\treturn 'type' in error\n\t}\n\n\tprivate rejectCorruptData(): never {\n\t\tthrow new ErrorsPreprocessor.ErrorsPreprocessorError(\n\t\t\t'Received corrupted data: a node cannot be simultaneously field-indexed and path-indexed.',\n\t\t)\n\t}\n}\n\nnamespace ErrorsPreprocessor {\n\texport interface BaseErrorNode {\n\t\tvalidation: ErrorAccessor.ValidationError[]\n\t\texecution: ErrorAccessor.ExecutionError[]\n\t}\n\n\texport interface LeafErrorNode extends BaseErrorNode {\n\t\tnodeType: 'leaf'\n\t}\n\n\texport interface ErrorINode extends BaseErrorNode {\n\t\tnodeType: 'iNode'\n\t\tchildren: Map<FieldName | EntityId, ErrorNode>\n\t}\n\n\texport type ErrorNode = ErrorINode | LeafErrorNode\n\n\texport type ErrorTreeRoot = Map<PlaceholderName, ErrorNode>\n\n\texport class ErrorsPreprocessorError extends Error {}\n}\n\nexport { ErrorsPreprocessor }\n"],"names":["ErrorsPreprocessor"],"mappings":";;AAOA,MAAM,mBAAmB;AAAA,EACjB,YACW,iBACA,YAChB;AAFgB,SAAA,kBAAA;AACA,SAAA,aAAA;AAAA,EACf;AAAA,EAEI,aAA+C;AAC/C,UAAA,+BAAiD;AAEnD,QAAA,KAAK,oBAAoB,QAAW;AAChC,aAAA;AAAA,IACR;AAEW,eAAA,aAAa,KAAK,YAAY;AAClC,YAAA,mBAAmB,KAAK,gBAAgB,UAAU;AAClD,YAAA,oBAAoB,KAAK,wBAAwB,gBAAgB;AAEvE,UAAI,sBAAsB,QAAW;AACpC;AAAA,MACD;AACA,YAAM,EAAE,aAAa,oBAAoB,GAAA,IAAO;AAEhD,UAAI,gBAAgB,UAAU;AACzB,YAAA,SAAS,IAAI,kBAAkB,GAAG;AACrC,iBAAO,KAAK;QACb;AACS,iBAAA,IAAI,oBAAoB,iBAAiB;AAAA,MAAA,WACxC,gBAAgB,QAAQ;AAC5B,cAAA,QAAQ,SAAS,IAAI,kBAAkB;AAE7C,YAAI,UAAU,QAAW;AACxB,mBAAS,IAAI,oBAAoB;AAAA,YAChC,UAAU;AAAA,YACV,8BAAc,IAAI,CAAC,CAAC,IAAI,iBAAiB,CAAC,CAAC;AAAA,YAC3C,YAAY,CAAC;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gC,MAAM;AAAA,EAAC;AAA7CA,sBAAM,0BAAA;AAAA,GAnBJ,uBAAA,qBAAA,CAAA,EAAA;"}
1
+ {"version":3,"file":"ErrorsPreprocessor.js","sources":["../../../src/core/ErrorsPreprocessor.ts"],"sourcesContent":["import type { ErrorAccessor } from '../accessors'\nimport type { ExecutionError, MutationDataResponse, MutationResponse, ValidationError } from '../accessorTree'\nimport type { EntityId, FieldName, PlaceholderName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport { MutationAlias } from './requestAliases'\nimport { SubMutationOperation } from './MutationGenerator'\n\nclass ErrorsPreprocessor {\n\tpublic constructor(\n\t\tprivate readonly requestResponse: MutationDataResponse,\n\t\tprivate readonly operations: SubMutationOperation[],\n\t) {}\n\n\tpublic preprocess(): ErrorsPreprocessor.ErrorTreeRoot {\n\t\tconst treeRoot: ErrorsPreprocessor.ErrorTreeRoot = new Map()\n\n\t\tif (this.requestResponse === undefined) {\n\t\t\treturn treeRoot\n\t\t}\n\n\t\tfor (const operation of this.operations) {\n\t\t\tconst mutationResponse = this.requestResponse[operation.alias]\n\t\t\tconst processedResponse = this.processMutationResponse(mutationResponse)\n\n\t\t\tif (processedResponse === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst { subTreeType, subTreePlaceholder, id } = operation\n\n\t\t\tif (subTreeType === 'single') {\n\t\t\t\tif (treeRoot.has(subTreePlaceholder)) {\n\t\t\t\t\treturn this.rejectCorruptData()\n\t\t\t\t}\n\t\t\t\ttreeRoot.set(subTreePlaceholder, processedResponse)\n\t\t\t} else if (subTreeType === 'list') {\n\t\t\t\tconst child = treeRoot.get(subTreePlaceholder)\n\n\t\t\t\tif (child === undefined) {\n\t\t\t\t\ttreeRoot.set(subTreePlaceholder, {\n\t\t\t\t\t\tnodeType: 'iNode',\n\t\t\t\t\t\tchildren: new Map([[id, processedResponse]]),\n\t\t\t\t\t\tvalidation: [],\n\t\t\t\t\t\texecution: [],\n\t\t\t\t\t})\n\t\t\t\t} else if (child.nodeType === 'iNode') {\n\t\t\t\t\tchild.children.set(id, processedResponse)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn assertNever(subTreeType)\n\t\t\t}\n\n\t\t}\n\t\treturn treeRoot\n\t}\n\n\tprivate processMutationResponse(mutationResponse: MutationResponse): ErrorsPreprocessor.ErrorNode | undefined {\n\t\tif (mutationResponse.ok && mutationResponse.validation?.valid && mutationResponse.errors.length === 0) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (mutationResponse.validation?.errors.length) {\n\t\t\treturn this.getErrorNode(mutationResponse.validation?.errors)\n\t\t}\n\t\tif (mutationResponse.errors.length) {\n\t\t\treturn this.getErrorNode(mutationResponse.errors)\n\t\t}\n\t\treturn undefined\n\t}\n\n\tprivate getErrorNode(errors: ValidationError[] | ExecutionError[]): ErrorsPreprocessor.ErrorNode {\n\t\tconst [head, ...tail] = errors\n\n\t\tlet rootNode = this.getRootNode(head)\n\n\t\terrorLoop: for (const error of tail) {\n\t\t\tlet currentNode = rootNode\n\n\t\t\tfor (let i = 0, pathLength = error.path.length; i < pathLength; i++) {\n\t\t\t\tconst pathNode = error.path[i]\n\n\t\t\t\tif (currentNode.nodeType === 'leaf') {\n\t\t\t\t\t(currentNode as any as ErrorsPreprocessor.ErrorINode).nodeType = 'iNode'\n\t\t\t\t\t;(currentNode as any as ErrorsPreprocessor.ErrorINode).children = new Map()\n\t\t\t\t}\n\n\t\t\t\tif (pathNode.__typename === '_FieldPathFragment') {\n\t\t\t\t\tif (currentNode.nodeType === 'iNode') {\n\t\t\t\t\t\tlet alias = pathNode.field\n\t\t\t\t\t\tlet nextIndex = i + 1\n\t\t\t\t\t\tif (nextIndex in error.path) {\n\t\t\t\t\t\t\tconst nextPathNode = error.path[nextIndex]\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tnextPathNode.__typename === '_IndexPathFragment' &&\n\t\t\t\t\t\t\t\ttypeof nextPathNode.alias === 'string' &&\n\t\t\t\t\t\t\t\tnextPathNode.alias.startsWith(pathNode.field)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t// We're dealing with a reduced hasMany relation.\n\t\t\t\t\t\t\t\ti++\n\t\t\t\t\t\t\t\tnextIndex++\n\t\t\t\t\t\t\t\talias = nextPathNode.alias\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!(alias in currentNode.children)) {\n\t\t\t\t\t\t\tcurrentNode.children.set(alias, this.getRootNode(error, nextIndex))\n\t\t\t\t\t\t\tif (nextIndex <= error.path.length) {\n\t\t\t\t\t\t\t\t// This path has been handled by getRootNode\n\t\t\t\t\t\t\t\tcontinue errorLoop\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurrentNode = currentNode.children.get(alias)!\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.rejectCorruptData()\n\t\t\t\t\t}\n\t\t\t\t} else if (pathNode.__typename === '_IndexPathFragment') {\n\t\t\t\t\tif (currentNode.nodeType === 'iNode') {\n\t\t\t\t\t\tconst alias = pathNode.alias\n\n\t\t\t\t\t\tif (alias === null) {\n\t\t\t\t\t\t\tthrow new ErrorsPreprocessor.ErrorsPreprocessorError(\n\t\t\t\t\t\t\t\t`Corrupt data: undefined alias for node with index ${pathNode.index}.`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst entityId = MutationAlias.decodeEntityId(alias)\n\n\t\t\t\t\t\tif (!(entityId in currentNode.children)) {\n\t\t\t\t\t\t\tcurrentNode.children.set(entityId, this.getRootNode(error, i + 1))\n\t\t\t\t\t\t\tif (i + 1 <= error.path.length) {\n\t\t\t\t\t\t\t\t// This path has been handled by getRootNode\n\t\t\t\t\t\t\t\tcontinue errorLoop\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurrentNode = currentNode.children.get(entityId)!\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.rejectCorruptData()\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(pathNode)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (this.isExecutionError(error)) {\n\t\t\t\tcurrentNode.execution.push({ type: 'execution', code: error.type, developerMessage: error.message })\n\t\t\t} else {\n\t\t\t\tcurrentNode.validation.push(this.createValidationError(error.message.text))\n\t\t\t}\n\t\t}\n\n\t\treturn rootNode\n\t}\n\n\tprivate getRootNode(error: ValidationError | ExecutionError, startIndex: number = 0): ErrorsPreprocessor.ErrorNode {\n\t\tlet rootNode: ErrorsPreprocessor.ErrorNode = {\n\t\t\tvalidation: this.isExecutionError(error) ? [] : [this.createValidationError(error.message.text)],\n\t\t\texecution: this.isExecutionError(error) ? [{ type: 'execution', code: error.type, developerMessage: error.message }] : [],\n\t\t\tnodeType: 'leaf',\n\t\t}\n\n\t\tfor (let i = error.path.length - 1; i >= startIndex; i--) {\n\t\t\tconst pathNode = error.path[i]\n\t\t\tif (pathNode.__typename === '_FieldPathFragment') {\n\t\t\t\trootNode = {\n\t\t\t\t\tvalidation: [],\n\t\t\t\t\texecution: [],\n\t\t\t\t\tnodeType: 'iNode',\n\t\t\t\t\tchildren: new Map([[pathNode.field, rootNode]]),\n\t\t\t\t}\n\t\t\t} else if (pathNode.__typename === '_IndexPathFragment') {\n\t\t\t\tconst alias = pathNode.alias\n\n\t\t\t\tif (alias === null) {\n\t\t\t\t\tthrow new ErrorsPreprocessor.ErrorsPreprocessorError(\n\t\t\t\t\t\t`Corrupt data: undefined alias for node with index ${pathNode.index}.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\trootNode = {\n\t\t\t\t\tvalidation: [],\n\t\t\t\t\texecution: [],\n\t\t\t\t\tnodeType: 'iNode',\n\t\t\t\t\tchildren: new Map([[MutationAlias.decodeEntityId(alias), rootNode]]),\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tassertNever(pathNode)\n\t\t\t}\n\t\t}\n\n\t\treturn rootNode\n\t}\n\n\tprivate createValidationError(message: string): ErrorAccessor.ValidationError {\n\t\tif (message === 'Field is required') {\n\t\t\t// TODO this is just awful. Validation errors currently don't have error codes which makes it more difficult\n\t\t\t// \tto translate the error messages. This is the most common such error, and so we just make up a code\n\t\t\t// \tin order to facilitate error handling further downstream.\n\t\t\treturn {\n\t\t\t\ttype: 'validation',\n\t\t\t\tcode: 'fieldRequired',\n\t\t\t\tmessage,\n\t\t\t}\n\t\t}\n\t\treturn { type: 'validation', message, code: undefined }\n\t}\n\n\tprivate isExecutionError(error: ValidationError | ExecutionError): error is ExecutionError {\n\t\treturn 'type' in error\n\t}\n\n\tprivate rejectCorruptData(): never {\n\t\tthrow new ErrorsPreprocessor.ErrorsPreprocessorError(\n\t\t\t'Received corrupted data: a node cannot be simultaneously field-indexed and path-indexed.',\n\t\t)\n\t}\n}\n\nnamespace ErrorsPreprocessor {\n\texport interface BaseErrorNode {\n\t\tvalidation: ErrorAccessor.ValidationError[]\n\t\texecution: ErrorAccessor.ExecutionError[]\n\t}\n\n\texport interface LeafErrorNode extends BaseErrorNode {\n\t\tnodeType: 'leaf'\n\t}\n\n\texport interface ErrorINode extends BaseErrorNode {\n\t\tnodeType: 'iNode'\n\t\tchildren: Map<FieldName | EntityId, ErrorNode>\n\t}\n\n\texport type ErrorNode = ErrorINode | LeafErrorNode\n\n\texport type ErrorTreeRoot = Map<PlaceholderName, ErrorNode>\n\n\texport class ErrorsPreprocessorError extends Error {}\n}\n\nexport { ErrorsPreprocessor }\n"],"names":["ErrorsPreprocessor"],"mappings":";;AAOA,MAAM,mBAAmB;AAAA,EACjB,YACW,iBACA,YAChB;AAFgB,SAAA,kBAAA;AACA,SAAA,aAAA;AAAA,EACf;AAAA,EAEI,aAA+C;AAC/C,UAAA,+BAAiD;AAEnD,QAAA,KAAK,oBAAoB,QAAW;AAChC,aAAA;AAAA,IACR;AAEW,eAAA,aAAa,KAAK,YAAY;AACxC,YAAM,mBAAmB,KAAK,gBAAgB,UAAU,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CAAC,cAAc,eAAe,KAAK,GAAG,QAAQ,CAAC,CAAC;AAAA,QAAA;AAAA,MACpE,OACM;AACN,oBAAoB;AAAA,MACrB;AAAA,IACD;AAEO,WAAA;AAAA,EACR;AAAA,EAEQ,sBAAsB,SAAgD;AAC7E,QAAI,YAAY,qBAAqB;AAI7B,aAAA;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,QACN;AAAA,MAAA;AAAA,IAEF;AACA,WAAO,EAAE,MAAM,cAAc,SAAS,MAAM;EAC7C;AAAA,EAEQ,iBAAiB,OAAkE;AAC1F,WAAO,UAAU;AAAA,EAClB;AAAA,EAEQ,oBAA2B;AAClC,UAAM,IAAI,mBAAmB;AAAA,MAC5B;AAAA,IAAA;AAAA,EAEF;AACD;AAAA,CAEA,CAAUA,wBAAV;AAmBQ,QAAM,gCAAgC,MAAM;AAAA,EAAC;AAA7CA,sBAAM,0BAAA;AAAA,GAnBJ,uBAAA,qBAAA,CAAA,EAAA;"}
@@ -13,6 +13,8 @@ class EventManager {
13
13
  constructor(asyncBatchUpdatesOptions, batchUpdatesOptions, config, dirtinessTracker, onUpdate, treeStore) {
14
14
  __publicField(this, "transactionDepth", 0);
15
15
  __publicField(this, "isFrozenWhileUpdating", false);
16
+ // This should ideally not exists as it should be synonymous to `this.ongoingPersistOperation !== undefined`
17
+ // but it makes persist-related promise juggling significantly more straightforward.
16
18
  __publicField(this, "isMutating", false);
17
19
  __publicField(this, "ongoingPersistOperation");
18
20
  __publicField(this, "previousMetadata");