@contember/binding 1.0.3 → 1.1.0-alpha.2

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 (319) hide show
  1. package/dist/development/accessorPropagation/useEntityListSubTree.js +4 -2
  2. package/dist/development/accessorPropagation/useEntityListSubTree.js.map +1 -1
  3. package/dist/development/accessorPropagation/useEntitySubTree.js +4 -2
  4. package/dist/development/accessorPropagation/useEntitySubTree.js.map +1 -1
  5. package/dist/development/accessorPropagation/useExtendTree.js +25 -0
  6. package/dist/development/accessorPropagation/useExtendTree.js.map +1 -0
  7. package/dist/development/accessorTree/AccessorTree.js +9 -4
  8. package/dist/development/accessorTree/AccessorTree.js.map +1 -1
  9. package/dist/development/accessorTree/AccessorTreeStateContext.js +6 -0
  10. package/dist/development/accessorTree/AccessorTreeStateContext.js.map +1 -0
  11. package/dist/development/accessorTree/NormalizedPersistedData.js.map +1 -1
  12. package/dist/development/accessorTree/RuntimeId.js +17 -4
  13. package/dist/development/accessorTree/RuntimeId.js.map +1 -1
  14. package/dist/development/accessorTree/useAccessorTreeState.js +5 -0
  15. package/dist/development/accessorTree/useAccessorTreeState.js.map +1 -0
  16. package/dist/development/accessors/EntityAccessor.js +0 -32
  17. package/dist/development/accessors/EntityAccessor.js.map +1 -1
  18. package/dist/development/accessors/EntityListAccessor.js +1 -1
  19. package/dist/development/accessors/EntityListAccessor.js.map +1 -1
  20. package/dist/development/core/AccessorErrorManager.js +3 -0
  21. package/dist/development/core/AccessorErrorManager.js.map +1 -1
  22. package/dist/development/core/DataBinding.js +11 -23
  23. package/dist/development/core/DataBinding.js.map +1 -1
  24. package/dist/development/core/DirtinessTracker.js +4 -13
  25. package/dist/development/core/DirtinessTracker.js.map +1 -1
  26. package/dist/development/core/ErrorsPreprocessor.js.map +1 -1
  27. package/dist/development/core/EventManager.js +12 -7
  28. package/dist/development/core/EventManager.js.map +1 -1
  29. package/dist/development/core/MarkerComparator.js +1 -1
  30. package/dist/development/core/MarkerMerger.js +1 -4
  31. package/dist/development/core/MarkerMerger.js.map +1 -1
  32. package/dist/development/core/MutationGenerator.js +100 -94
  33. package/dist/development/core/MutationGenerator.js.map +1 -1
  34. package/dist/development/core/RequestResponseNormalizer.js +27 -31
  35. package/dist/development/core/RequestResponseNormalizer.js.map +1 -1
  36. package/dist/development/core/StateInitializer.js +23 -26
  37. package/dist/development/core/StateInitializer.js.map +1 -1
  38. package/dist/development/core/TreeAugmenter.js +10 -10
  39. package/dist/development/core/TreeAugmenter.js.map +1 -1
  40. package/dist/development/core/TreeFilterGenerator.js +2 -2
  41. package/dist/development/core/TreeFilterGenerator.js.map +1 -1
  42. package/dist/development/core/TreeStore.js +3 -3
  43. package/dist/development/core/TreeStore.js.map +1 -1
  44. package/dist/development/core/VariableInputTransformer.js +4 -1
  45. package/dist/development/core/VariableInputTransformer.js.map +1 -1
  46. package/dist/development/core/operations/EntityOperations.js +13 -12
  47. package/dist/development/core/operations/EntityOperations.js.map +1 -1
  48. package/dist/development/core/operations/FieldOperations.js +2 -2
  49. package/dist/development/core/operations/FieldOperations.js.map +1 -1
  50. package/dist/development/core/operations/ListOperations.js +3 -3
  51. package/dist/development/core/operations/ListOperations.js.map +1 -1
  52. package/dist/development/core/operations/OperationsHelpers.js +2 -2
  53. package/dist/development/core/operations/OperationsHelpers.js.map +1 -1
  54. package/dist/development/core/requestAliases/MutationAlias.js +5 -3
  55. package/dist/development/core/requestAliases/MutationAlias.js.map +1 -1
  56. package/dist/development/core/schema/Schema.js +3 -0
  57. package/dist/development/core/schema/Schema.js.map +1 -1
  58. package/dist/development/core/schema/SchemaPreprocessor.js +1 -1
  59. package/dist/development/core/schema/SchemaPreprocessor.js.map +1 -1
  60. package/dist/development/coreComponents/EntityListSubTree.js +4 -12
  61. package/dist/development/coreComponents/EntityListSubTree.js.map +1 -1
  62. package/dist/development/coreComponents/EntitySubTree.js +4 -22
  63. package/dist/development/coreComponents/EntitySubTree.js.map +1 -1
  64. package/dist/development/coreComponents/Field.js +5 -1
  65. package/dist/development/coreComponents/Field.js.map +1 -1
  66. package/dist/development/coreComponents/HasMany.js +3 -5
  67. package/dist/development/coreComponents/HasMany.js.map +1 -1
  68. package/dist/development/coreComponents/HasOne.js +3 -5
  69. package/dist/development/coreComponents/HasOne.js.map +1 -1
  70. package/dist/development/dao/Environment.js +147 -94
  71. package/dist/development/dao/Environment.js.map +1 -1
  72. package/dist/development/dao/TreeNodeEnvironmentFactory.js +159 -0
  73. package/dist/development/dao/TreeNodeEnvironmentFactory.js.map +1 -0
  74. package/dist/development/helperComponents/If.js +39 -0
  75. package/dist/development/helperComponents/If.js.map +1 -0
  76. package/dist/development/helperComponents/SugaredField.js +1 -1
  77. package/dist/development/helperComponents/helpers/FilterEvaluator.js +38 -0
  78. package/dist/development/helperComponents/helpers/FilterEvaluator.js.map +1 -0
  79. package/dist/development/helperComponents/helpers/FilterFieldsCollector.js +41 -0
  80. package/dist/development/helperComponents/helpers/FilterFieldsCollector.js.map +1 -0
  81. package/dist/development/helperComponents/helpers/evaluateCondition.js +46 -0
  82. package/dist/development/helperComponents/helpers/evaluateCondition.js.map +1 -0
  83. package/dist/development/index.js +4 -1
  84. package/dist/development/index.js.map +1 -1
  85. package/dist/development/queryLanguage/MarkerFactory.js +4 -3
  86. package/dist/development/queryLanguage/MarkerFactory.js.map +1 -1
  87. package/dist/development/queryLanguage/Parser.js +18 -6
  88. package/dist/development/queryLanguage/Parser.js.map +1 -1
  89. package/dist/production/accessorPropagation/useEntityListSubTree.js +4 -2
  90. package/dist/production/accessorPropagation/useEntityListSubTree.js.map +1 -1
  91. package/dist/production/accessorPropagation/useEntitySubTree.js +4 -2
  92. package/dist/production/accessorPropagation/useEntitySubTree.js.map +1 -1
  93. package/dist/production/accessorPropagation/useExtendTree.js +25 -0
  94. package/dist/production/accessorPropagation/useExtendTree.js.map +1 -0
  95. package/dist/production/accessorTree/AccessorTree.js +9 -4
  96. package/dist/production/accessorTree/AccessorTree.js.map +1 -1
  97. package/dist/production/accessorTree/AccessorTreeStateContext.js +6 -0
  98. package/dist/production/accessorTree/AccessorTreeStateContext.js.map +1 -0
  99. package/dist/production/accessorTree/NormalizedPersistedData.js.map +1 -1
  100. package/dist/production/accessorTree/RuntimeId.js +17 -4
  101. package/dist/production/accessorTree/RuntimeId.js.map +1 -1
  102. package/dist/production/accessorTree/useAccessorTreeState.js +5 -0
  103. package/dist/production/accessorTree/useAccessorTreeState.js.map +1 -0
  104. package/dist/production/accessors/EntityAccessor.js +0 -32
  105. package/dist/production/accessors/EntityAccessor.js.map +1 -1
  106. package/dist/production/accessors/EntityListAccessor.js +1 -1
  107. package/dist/production/accessors/EntityListAccessor.js.map +1 -1
  108. package/dist/production/core/AccessorErrorManager.js +3 -0
  109. package/dist/production/core/AccessorErrorManager.js.map +1 -1
  110. package/dist/production/core/DataBinding.js +11 -14
  111. package/dist/production/core/DataBinding.js.map +1 -1
  112. package/dist/production/core/DirtinessTracker.js +4 -13
  113. package/dist/production/core/DirtinessTracker.js.map +1 -1
  114. package/dist/production/core/ErrorsPreprocessor.js.map +1 -1
  115. package/dist/production/core/EventManager.js +11 -6
  116. package/dist/production/core/EventManager.js.map +1 -1
  117. package/dist/production/core/MarkerComparator.js +1 -1
  118. package/dist/production/core/MarkerMerger.js +1 -4
  119. package/dist/production/core/MarkerMerger.js.map +1 -1
  120. package/dist/production/core/MutationGenerator.js +100 -94
  121. package/dist/production/core/MutationGenerator.js.map +1 -1
  122. package/dist/production/core/RequestResponseNormalizer.js +27 -31
  123. package/dist/production/core/RequestResponseNormalizer.js.map +1 -1
  124. package/dist/production/core/StateInitializer.js +23 -26
  125. package/dist/production/core/StateInitializer.js.map +1 -1
  126. package/dist/production/core/TreeAugmenter.js +10 -10
  127. package/dist/production/core/TreeAugmenter.js.map +1 -1
  128. package/dist/production/core/TreeFilterGenerator.js +2 -2
  129. package/dist/production/core/TreeFilterGenerator.js.map +1 -1
  130. package/dist/production/core/TreeStore.js +3 -3
  131. package/dist/production/core/TreeStore.js.map +1 -1
  132. package/dist/production/core/VariableInputTransformer.js +4 -1
  133. package/dist/production/core/VariableInputTransformer.js.map +1 -1
  134. package/dist/production/core/operations/EntityOperations.js +13 -12
  135. package/dist/production/core/operations/EntityOperations.js.map +1 -1
  136. package/dist/production/core/operations/FieldOperations.js.map +1 -1
  137. package/dist/production/core/operations/ListOperations.js +3 -3
  138. package/dist/production/core/operations/ListOperations.js.map +1 -1
  139. package/dist/production/core/operations/OperationsHelpers.js +2 -2
  140. package/dist/production/core/operations/OperationsHelpers.js.map +1 -1
  141. package/dist/production/core/requestAliases/MutationAlias.js +5 -3
  142. package/dist/production/core/requestAliases/MutationAlias.js.map +1 -1
  143. package/dist/production/core/schema/Schema.js +3 -0
  144. package/dist/production/core/schema/Schema.js.map +1 -1
  145. package/dist/production/core/schema/SchemaPreprocessor.js +1 -1
  146. package/dist/production/core/schema/SchemaPreprocessor.js.map +1 -1
  147. package/dist/production/coreComponents/EntityListSubTree.js +4 -12
  148. package/dist/production/coreComponents/EntityListSubTree.js.map +1 -1
  149. package/dist/production/coreComponents/EntitySubTree.js +4 -22
  150. package/dist/production/coreComponents/EntitySubTree.js.map +1 -1
  151. package/dist/production/coreComponents/Field.js +5 -1
  152. package/dist/production/coreComponents/Field.js.map +1 -1
  153. package/dist/production/coreComponents/HasMany.js +3 -5
  154. package/dist/production/coreComponents/HasMany.js.map +1 -1
  155. package/dist/production/coreComponents/HasOne.js +3 -5
  156. package/dist/production/coreComponents/HasOne.js.map +1 -1
  157. package/dist/production/dao/Environment.js +147 -94
  158. package/dist/production/dao/Environment.js.map +1 -1
  159. package/dist/production/dao/TreeNodeEnvironmentFactory.js +159 -0
  160. package/dist/production/dao/TreeNodeEnvironmentFactory.js.map +1 -0
  161. package/dist/production/helperComponents/If.js +39 -0
  162. package/dist/production/helperComponents/If.js.map +1 -0
  163. package/dist/production/helperComponents/SugaredField.js +1 -1
  164. package/dist/production/helperComponents/helpers/FilterEvaluator.js +38 -0
  165. package/dist/production/helperComponents/helpers/FilterEvaluator.js.map +1 -0
  166. package/dist/production/helperComponents/helpers/FilterFieldsCollector.js +41 -0
  167. package/dist/production/helperComponents/helpers/FilterFieldsCollector.js.map +1 -0
  168. package/dist/production/helperComponents/helpers/evaluateCondition.js +46 -0
  169. package/dist/production/helperComponents/helpers/evaluateCondition.js.map +1 -0
  170. package/dist/production/index.js +4 -1
  171. package/dist/production/index.js.map +1 -1
  172. package/dist/production/queryLanguage/MarkerFactory.js +4 -3
  173. package/dist/production/queryLanguage/MarkerFactory.js.map +1 -1
  174. package/dist/production/queryLanguage/Parser.js +15 -6
  175. package/dist/production/queryLanguage/Parser.js.map +1 -1
  176. package/dist/types/accessorPropagation/index.d.ts +1 -0
  177. package/dist/types/accessorPropagation/index.d.ts.map +1 -1
  178. package/dist/types/accessorPropagation/useEntityListSubTree.d.ts +2 -1
  179. package/dist/types/accessorPropagation/useEntityListSubTree.d.ts.map +1 -1
  180. package/dist/types/accessorPropagation/useEntitySubTree.d.ts +2 -1
  181. package/dist/types/accessorPropagation/useEntitySubTree.d.ts.map +1 -1
  182. package/dist/types/accessorPropagation/useExtendTree.d.ts +5 -0
  183. package/dist/types/accessorPropagation/useExtendTree.d.ts.map +1 -0
  184. package/dist/types/accessorTree/AccessorTree.d.ts.map +1 -1
  185. package/dist/types/accessorTree/AccessorTreeStateContext.d.ts +4 -0
  186. package/dist/types/accessorTree/AccessorTreeStateContext.d.ts.map +1 -0
  187. package/dist/types/accessorTree/MutationRequestResponse.d.ts +5 -1
  188. package/dist/types/accessorTree/MutationRequestResponse.d.ts.map +1 -1
  189. package/dist/types/accessorTree/NormalizedPersistedData.d.ts +4 -4
  190. package/dist/types/accessorTree/NormalizedPersistedData.d.ts.map +1 -1
  191. package/dist/types/accessorTree/PersistResult.d.ts +2 -1
  192. package/dist/types/accessorTree/PersistResult.d.ts.map +1 -1
  193. package/dist/types/accessorTree/QueryRequestResponse.d.ts +11 -10
  194. package/dist/types/accessorTree/QueryRequestResponse.d.ts.map +1 -1
  195. package/dist/types/accessorTree/RuntimeId.d.ts +16 -6
  196. package/dist/types/accessorTree/RuntimeId.d.ts.map +1 -1
  197. package/dist/types/accessorTree/index.d.ts +1 -0
  198. package/dist/types/accessorTree/index.d.ts.map +1 -1
  199. package/dist/types/accessorTree/useAccessorTreeState.d.ts +2 -0
  200. package/dist/types/accessorTree/useAccessorTreeState.d.ts.map +1 -0
  201. package/dist/types/accessors/EntityAccessor.d.ts +1 -3
  202. package/dist/types/accessors/EntityAccessor.d.ts.map +1 -1
  203. package/dist/types/accessors/EntityListAccessor.d.ts +2 -2
  204. package/dist/types/accessors/EntityListAccessor.d.ts.map +1 -1
  205. package/dist/types/core/AccessorErrorManager.d.ts.map +1 -1
  206. package/dist/types/core/DataBinding.d.ts.map +1 -1
  207. package/dist/types/core/DirtinessTracker.d.ts +2 -5
  208. package/dist/types/core/DirtinessTracker.d.ts.map +1 -1
  209. package/dist/types/core/ErrorsPreprocessor.d.ts +2 -2
  210. package/dist/types/core/ErrorsPreprocessor.d.ts.map +1 -1
  211. package/dist/types/core/EventManager.d.ts +1 -1
  212. package/dist/types/core/EventManager.d.ts.map +1 -1
  213. package/dist/types/core/MarkerMerger.d.ts.map +1 -1
  214. package/dist/types/core/MutationGenerator.d.ts.map +1 -1
  215. package/dist/types/core/RequestResponseNormalizer.d.ts.map +1 -1
  216. package/dist/types/core/StateInitializer.d.ts +1 -5
  217. package/dist/types/core/StateInitializer.d.ts.map +1 -1
  218. package/dist/types/core/TreeStore.d.ts +3 -3
  219. package/dist/types/core/TreeStore.d.ts.map +1 -1
  220. package/dist/types/core/VariableInputTransformer.d.ts.map +1 -1
  221. package/dist/types/core/operations/EntityOperations.d.ts.map +1 -1
  222. package/dist/types/core/operations/ListOperations.d.ts +2 -1
  223. package/dist/types/core/operations/ListOperations.d.ts.map +1 -1
  224. package/dist/types/core/requestAliases/MutationAlias.d.ts.map +1 -1
  225. package/dist/types/core/schema/RawSchemaEntity.d.ts +3 -2
  226. package/dist/types/core/schema/RawSchemaEntity.d.ts.map +1 -1
  227. package/dist/types/core/schema/Schema.d.ts +2 -0
  228. package/dist/types/core/schema/Schema.d.ts.map +1 -1
  229. package/dist/types/core/schema/SchemaEntity.d.ts +1 -1
  230. package/dist/types/core/schema/SchemaEntity.d.ts.map +1 -1
  231. package/dist/types/core/schema/index.d.ts +0 -1
  232. package/dist/types/core/schema/index.d.ts.map +1 -1
  233. package/dist/types/coreComponents/EntityListSubTree.d.ts +1 -1
  234. package/dist/types/coreComponents/EntityListSubTree.d.ts.map +1 -1
  235. package/dist/types/coreComponents/EntitySubTree.d.ts +1 -1
  236. package/dist/types/coreComponents/EntitySubTree.d.ts.map +1 -1
  237. package/dist/types/coreComponents/Field.d.ts.map +1 -1
  238. package/dist/types/coreComponents/HasMany.d.ts +1 -1
  239. package/dist/types/coreComponents/HasMany.d.ts.map +1 -1
  240. package/dist/types/coreComponents/HasOne.d.ts +1 -1
  241. package/dist/types/coreComponents/HasOne.d.ts.map +1 -1
  242. package/dist/types/dao/Environment.d.ts +81 -42
  243. package/dist/types/dao/Environment.d.ts.map +1 -1
  244. package/dist/types/dao/TreeNodeEnvironmentFactory.d.ts +19 -0
  245. package/dist/types/dao/TreeNodeEnvironmentFactory.d.ts.map +1 -0
  246. package/dist/types/helperComponents/If.d.ts +14 -0
  247. package/dist/types/helperComponents/If.d.ts.map +1 -0
  248. package/dist/types/helperComponents/helpers/FilterEvaluator.d.ts +9 -0
  249. package/dist/types/helperComponents/helpers/FilterEvaluator.d.ts.map +1 -0
  250. package/dist/types/helperComponents/helpers/FilterFieldsCollector.d.ts +10 -0
  251. package/dist/types/helperComponents/helpers/FilterFieldsCollector.d.ts.map +1 -0
  252. package/dist/types/helperComponents/helpers/evaluateCondition.d.ts +4 -0
  253. package/dist/types/helperComponents/helpers/evaluateCondition.d.ts.map +1 -0
  254. package/dist/types/helperComponents/index.d.ts +1 -0
  255. package/dist/types/helperComponents/index.d.ts.map +1 -1
  256. package/dist/types/queryLanguage/MarkerFactory.d.ts.map +1 -1
  257. package/dist/types/queryLanguage/Parser.d.ts.map +1 -1
  258. package/dist/types/treeParameters/primitives/EntityId.d.ts +1 -1
  259. package/dist/types/treeParameters/primitives/EntityId.d.ts.map +1 -1
  260. package/dist/types/tsconfig.tsbuildinfo +1 -1
  261. package/package.json +9 -6
  262. package/src/accessorPropagation/index.ts +1 -0
  263. package/src/accessorPropagation/useEntityListSubTree.ts +8 -1
  264. package/src/accessorPropagation/useEntitySubTree.ts +8 -1
  265. package/src/accessorPropagation/useExtendTree.ts +28 -0
  266. package/src/accessorTree/AccessorTree.tsx +18 -12
  267. package/src/accessorTree/AccessorTreeStateContext.ts +6 -0
  268. package/src/accessorTree/MutationRequestResponse.ts +3 -1
  269. package/src/accessorTree/NormalizedPersistedData.ts +4 -4
  270. package/src/accessorTree/PersistResult.ts +2 -1
  271. package/src/accessorTree/QueryRequestResponse.ts +17 -14
  272. package/src/accessorTree/RuntimeId.ts +27 -6
  273. package/src/accessorTree/index.ts +1 -0
  274. package/src/accessorTree/useAccessorTreeState.ts +4 -0
  275. package/src/accessors/EntityAccessor.ts +2 -51
  276. package/src/accessors/EntityListAccessor.ts +3 -3
  277. package/src/core/AccessorErrorManager.ts +3 -0
  278. package/src/core/DataBinding.ts +11 -33
  279. package/src/core/DirtinessTracker.ts +4 -16
  280. package/src/core/ErrorsPreprocessor.ts +2 -2
  281. package/src/core/EventManager.ts +14 -8
  282. package/src/core/MarkerMerger.ts +1 -4
  283. package/src/core/MutationGenerator.ts +137 -130
  284. package/src/core/RequestResponseNormalizer.ts +37 -38
  285. package/src/core/StateInitializer.ts +35 -42
  286. package/src/core/TreeAugmenter.ts +11 -11
  287. package/src/core/TreeFilterGenerator.ts +5 -5
  288. package/src/core/TreeStore.ts +12 -6
  289. package/src/core/VariableInputTransformer.ts +7 -4
  290. package/src/core/operations/EntityOperations.ts +12 -13
  291. package/src/core/operations/FieldOperations.ts +2 -2
  292. package/src/core/operations/ListOperations.ts +6 -5
  293. package/src/core/operations/OperationsHelpers.ts +2 -2
  294. package/src/core/requestAliases/MutationAlias.ts +5 -3
  295. package/src/core/schema/RawSchemaEntity.ts +1 -2
  296. package/src/core/schema/Schema.ts +5 -0
  297. package/src/core/schema/SchemaEntity.ts +1 -1
  298. package/src/core/schema/SchemaPreprocessor.ts +1 -1
  299. package/src/core/schema/index.ts +0 -1
  300. package/src/coreComponents/EntityListSubTree.tsx +5 -16
  301. package/src/coreComponents/EntitySubTree.tsx +17 -32
  302. package/src/coreComponents/Field.tsx +4 -0
  303. package/src/coreComponents/HasMany.tsx +4 -6
  304. package/src/coreComponents/HasOne.tsx +6 -7
  305. package/src/dao/Environment.ts +221 -126
  306. package/src/dao/TreeNodeEnvironmentFactory.ts +228 -0
  307. package/src/helperComponents/If.tsx +71 -0
  308. package/src/helperComponents/helpers/FilterEvaluator.ts +48 -0
  309. package/src/helperComponents/helpers/FilterFieldsCollector.ts +49 -0
  310. package/src/helperComponents/helpers/evaluateCondition.ts +52 -0
  311. package/src/helperComponents/index.ts +1 -0
  312. package/src/queryLanguage/MarkerFactory.ts +5 -3
  313. package/src/queryLanguage/Parser.ts +24 -11
  314. package/src/treeParameters/primitives/EntityId.ts +1 -1
  315. package/dist/development/core/schema/SchemaValidator.js +0 -116
  316. package/dist/development/core/schema/SchemaValidator.js.map +0 -1
  317. package/dist/types/core/schema/SchemaValidator.d.ts +0 -14
  318. package/dist/types/core/schema/SchemaValidator.d.ts.map +0 -1
  319. package/src/core/schema/SchemaValidator.ts +0 -238
@@ -2,10 +2,12 @@ import { useCallback } from "react";
2
2
  import { useAccessorUpdateSubscription } from "./useAccessorUpdateSubscription.js";
3
3
  import { useEntityListSubTreeParameters } from "./useEntityListSubTreeParameters.js";
4
4
  import { useGetEntityListSubTree } from "./useGetEntityListSubTree.js";
5
- const useEntityListSubTree = (qualifiedEntityList) => {
5
+ const useEntityListSubTree = (qualifiedEntityList, ...treeId) => {
6
6
  const getSubTree = useGetEntityListSubTree();
7
7
  const parameters = useEntityListSubTreeParameters(qualifiedEntityList);
8
- const getAccessor = useCallback(() => getSubTree(parameters), [getSubTree, parameters]);
8
+ const hasTreeId = treeId.length > 0;
9
+ const treeIdVal = treeId[0];
10
+ const getAccessor = useCallback(() => getSubTree(parameters, ...hasTreeId ? [treeIdVal] : []), [getSubTree, hasTreeId, parameters, treeIdVal]);
9
11
  return useAccessorUpdateSubscription(getAccessor);
10
12
  };
11
13
  export { useEntityListSubTree };
@@ -1 +1 @@
1
- {"version":3,"file":"useEntityListSubTree.js","sources":["../../../src/accessorPropagation/useEntityListSubTree.ts"],"sourcesContent":["import { useCallback } from 'react'\nimport type { EntityListAccessor } from '../accessors'\nimport type { Alias, SugaredQualifiedEntityList, SugaredUnconstrainedQualifiedEntityList } from '../treeParameters'\nimport { useAccessorUpdateSubscription } from './useAccessorUpdateSubscription'\nimport { useEntityListSubTreeParameters } from './useEntityListSubTreeParameters'\nimport { useGetEntityListSubTree } from './useGetEntityListSubTree'\n\nexport const useEntityListSubTree = (\n\tqualifiedEntityList: Alias | SugaredQualifiedEntityList | SugaredUnconstrainedQualifiedEntityList,\n): EntityListAccessor => {\n\tconst getSubTree = useGetEntityListSubTree()\n\tconst parameters = useEntityListSubTreeParameters(qualifiedEntityList)\n\tconst getAccessor = useCallback(() => getSubTree(parameters), [getSubTree, parameters])\n\n\t// if (typeof parameters !== 'string' && parameters.value.hasOneRelationPath.length) {\n\t// \tthrow new BindingError(`useEntityListSubTree: cannot use hasOneRelationPath!`)\n\t// }\n\n\treturn useAccessorUpdateSubscription(getAccessor)\n}\n"],"names":[],"mappings":";;;;AAOa,MAAA,uBAAuB,CACnC,wBACwB;AACxB,QAAM,aAAa;AACb,QAAA,aAAa,+BAA+B,mBAAmB;AAC/D,QAAA,cAAc,YAAY,MAAM,WAAW,UAAU,GAAG,CAAC,YAAY,UAAU,CAAC;AAMtF,SAAO,8BAA8B,WAAW;AACjD;;"}
1
+ {"version":3,"file":"useEntityListSubTree.js","sources":["../../../src/accessorPropagation/useEntityListSubTree.ts"],"sourcesContent":["import { useCallback } from 'react'\nimport type { EntityListAccessor } from '../accessors'\nimport type { Alias, SugaredQualifiedEntityList, SugaredUnconstrainedQualifiedEntityList } from '../treeParameters'\nimport { useAccessorUpdateSubscription } from './useAccessorUpdateSubscription'\nimport { useEntityListSubTreeParameters } from './useEntityListSubTreeParameters'\nimport { useGetEntityListSubTree } from './useGetEntityListSubTree'\nimport { TreeRootId } from '../treeParameters'\n\nexport const useEntityListSubTree = (\n\tqualifiedEntityList: Alias | SugaredQualifiedEntityList | SugaredUnconstrainedQualifiedEntityList,\n\t...treeId: [TreeRootId | undefined] | []\n): EntityListAccessor => {\n\tconst getSubTree = useGetEntityListSubTree()\n\tconst parameters = useEntityListSubTreeParameters(qualifiedEntityList)\n\tconst hasTreeId = treeId.length > 0\n\tconst treeIdVal = treeId[0]\n\tconst getAccessor = useCallback(\n\t\t() => getSubTree(parameters, ...(hasTreeId ? [treeIdVal] : [])),\n\t\t[getSubTree, hasTreeId, parameters, treeIdVal],\n\t)\n\n\t// if (typeof parameters !== 'string' && parameters.value.hasOneRelationPath.length) {\n\t// \tthrow new BindingError(`useEntityListSubTree: cannot use hasOneRelationPath!`)\n\t// }\n\n\treturn useAccessorUpdateSubscription(getAccessor)\n}\n"],"names":[],"mappings":";;;;AAQa,MAAA,uBAAuB,CACnC,wBACG,WACqB;AACxB,QAAM,aAAa;AACb,QAAA,aAAa,+BAA+B,mBAAmB;AAC/D,QAAA,YAAY,OAAO,SAAS;AAClC,QAAM,YAAY,OAAO;AACzB,QAAM,cAAc,YACnB,MAAM,WAAW,YAAY,GAAI,YAAY,CAAC,SAAS,IAAI,CAAG,CAAA,GAC9D,CAAC,YAAY,WAAW,YAAY,SAAS,CAC9C;AAMA,SAAO,8BAA8B,WAAW;AACjD;;"}
@@ -2,10 +2,12 @@ import { useCallback } from "react";
2
2
  import { useAccessorUpdateSubscription } from "./useAccessorUpdateSubscription.js";
3
3
  import { useEntitySubTreeParameters } from "./useEntitySubTreeParameters.js";
4
4
  import { useGetEntitySubTree } from "./useGetEntitySubTree.js";
5
- const useEntitySubTree = (qualifiedSingleEntity) => {
5
+ const useEntitySubTree = (qualifiedSingleEntity, ...treeId) => {
6
6
  const getSubTree = useGetEntitySubTree();
7
7
  const parameters = useEntitySubTreeParameters(qualifiedSingleEntity);
8
- const getAccessor = useCallback(() => getSubTree(parameters), [getSubTree, parameters]);
8
+ const hasTreeId = treeId.length > 0;
9
+ const treeIdVal = treeId[0];
10
+ const getAccessor = useCallback(() => getSubTree(parameters, ...hasTreeId ? [treeIdVal] : []), [getSubTree, hasTreeId, parameters, treeIdVal]);
9
11
  return useAccessorUpdateSubscription(getAccessor);
10
12
  };
11
13
  export { useEntitySubTree };
@@ -1 +1 @@
1
- {"version":3,"file":"useEntitySubTree.js","sources":["../../../src/accessorPropagation/useEntitySubTree.ts"],"sourcesContent":["import { useCallback } from 'react'\nimport type { EntityAccessor } from '../accessors'\nimport type { Alias, SugaredQualifiedSingleEntity, SugaredUnconstrainedQualifiedSingleEntity } from '../treeParameters'\nimport { useAccessorUpdateSubscription } from './useAccessorUpdateSubscription'\nimport { useEntitySubTreeParameters } from './useEntitySubTreeParameters'\nimport { useGetEntitySubTree } from './useGetEntitySubTree'\n\nexport const useEntitySubTree = (\n\tqualifiedSingleEntity: Alias | SugaredQualifiedSingleEntity | SugaredUnconstrainedQualifiedSingleEntity,\n): EntityAccessor => {\n\tconst getSubTree = useGetEntitySubTree()\n\tconst parameters = useEntitySubTreeParameters(qualifiedSingleEntity)\n\tconst getAccessor = useCallback(() => getSubTree(parameters), [getSubTree, parameters])\n\n\t// if (typeof parameters !== 'string' && parameters.hasOneRelationPath.length) {\n\t// \tthrow new BindingError(`useEntitySubTree: cannot use hasOneRelationPath!`)\n\t// }\n\treturn useAccessorUpdateSubscription(getAccessor)\n}\n"],"names":[],"mappings":";;;;AAOa,MAAA,mBAAmB,CAC/B,0BACoB;AACpB,QAAM,aAAa;AACb,QAAA,aAAa,2BAA2B,qBAAqB;AAC7D,QAAA,cAAc,YAAY,MAAM,WAAW,UAAU,GAAG,CAAC,YAAY,UAAU,CAAC;AAKtF,SAAO,8BAA8B,WAAW;AACjD;;"}
1
+ {"version":3,"file":"useEntitySubTree.js","sources":["../../../src/accessorPropagation/useEntitySubTree.ts"],"sourcesContent":["import { useCallback } from 'react'\nimport type { EntityAccessor } from '../accessors'\nimport type { Alias, SugaredQualifiedSingleEntity, SugaredUnconstrainedQualifiedSingleEntity } from '../treeParameters'\nimport { useAccessorUpdateSubscription } from './useAccessorUpdateSubscription'\nimport { useEntitySubTreeParameters } from './useEntitySubTreeParameters'\nimport { useGetEntitySubTree } from './useGetEntitySubTree'\nimport { TreeRootId } from '../treeParameters'\n\nexport const useEntitySubTree = (\n\tqualifiedSingleEntity: Alias | SugaredQualifiedSingleEntity | SugaredUnconstrainedQualifiedSingleEntity,\n\t...treeId: [TreeRootId | undefined] | []\n): EntityAccessor => {\n\tconst getSubTree = useGetEntitySubTree()\n\tconst parameters = useEntitySubTreeParameters(qualifiedSingleEntity)\n\tconst hasTreeId = treeId.length > 0\n\tconst treeIdVal = treeId[0]\n\tconst getAccessor = useCallback(\n\t\t() => getSubTree(parameters, ...(hasTreeId ? [treeIdVal] : [])),\n\t\t[getSubTree, hasTreeId, parameters, treeIdVal],\n\t)\n\n\t// if (typeof parameters !== 'string' && parameters.hasOneRelationPath.length) {\n\t// \tthrow new BindingError(`useEntitySubTree: cannot use hasOneRelationPath!`)\n\t// }\n\treturn useAccessorUpdateSubscription(getAccessor)\n}\n"],"names":[],"mappings":";;;;AAQa,MAAA,mBAAmB,CAC/B,0BACG,WACiB;AACpB,QAAM,aAAa;AACb,QAAA,aAAa,2BAA2B,qBAAqB;AAC7D,QAAA,YAAY,OAAO,SAAS;AAClC,QAAM,YAAY,OAAO;AACzB,QAAM,cAAc,YACnB,MAAM,WAAW,YAAY,GAAI,YAAY,CAAC,SAAS,IAAI,CAAG,CAAA,GAC9D,CAAC,YAAY,WAAW,YAAY,SAAS,CAC9C;AAKA,SAAO,8BAA8B,WAAW;AACjD;;"}
@@ -0,0 +1,25 @@
1
+ import { useCallback } from "react";
2
+ import { useAbortController, useIsMounted } from "@contember/react-utils";
3
+ import { useBindingOperations } from "./useBindingOperations.js";
4
+ import { DataBindingExtendAborted } from "../core/DataBinding.js";
5
+ const useExtendTree = () => {
6
+ const abort = useAbortController();
7
+ const { extendTree } = useBindingOperations();
8
+ const isMountedRef = useIsMounted();
9
+ return useCallback(async (newFragment, options) => {
10
+ try {
11
+ const newTreeRootId = await extendTree(newFragment, { ...options, signal: abort() });
12
+ if (!isMountedRef.current) {
13
+ return;
14
+ }
15
+ return newTreeRootId;
16
+ } catch (e) {
17
+ if (e === DataBindingExtendAborted) {
18
+ return;
19
+ }
20
+ throw e;
21
+ }
22
+ }, [abort, extendTree, isMountedRef]);
23
+ };
24
+ export { useExtendTree };
25
+ //# sourceMappingURL=useExtendTree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useExtendTree.js","sources":["../../../src/accessorPropagation/useExtendTree.ts"],"sourcesContent":["import { ReactNode, useCallback } from 'react'\nimport { useAbortController, useIsMounted } from '@contember/react-utils'\nimport { useBindingOperations } from './useBindingOperations'\nimport { TreeRootId } from '../treeParameters'\nimport { ExtendTreeOptions } from '../accessors'\nimport { DataBindingExtendAborted } from '../core'\n\nexport const useExtendTree = () => {\n\tconst abort = useAbortController()\n\tconst { extendTree } = useBindingOperations()\n\tconst isMountedRef = useIsMounted()\n\treturn useCallback(async (newFragment: ReactNode, options?: Omit<ExtendTreeOptions, 'signal'>): Promise<TreeRootId | undefined> => {\n\t\ttry {\n\t\t\tconst newTreeRootId = await extendTree(newFragment,\n\t\t\t\t{ ...options, signal: abort() },\n\t\t\t)\n\t\t\tif (!isMountedRef.current) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\treturn newTreeRootId\n\t\t} catch (e) {\n\t\t\tif (e === DataBindingExtendAborted) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthrow e\n\t\t}\n\t}, [abort, extendTree, isMountedRef])\n}\n"],"names":[],"mappings":";;;;AAOO,MAAM,gBAAgB,MAAM;AAClC,QAAM,QAAQ;AACR,QAAA,EAAE,eAAe;AACvB,QAAM,eAAe;AACd,SAAA,YAAY,OAAO,aAAwB,YAAiF;AAC9H,QAAA;AACG,YAAA,gBAAgB,MAAM,WAAW,aACtC,KAAK,SAAS,QAAQ,MAAM,EAAA,CAC7B;AACI,UAAA,CAAC,aAAa,SAAS;AAC1B;AAAA,MACD;AACO,aAAA;AAAA,aACC;AACR,UAAI,MAAM,0BAA0B;AACnC;AAAA,MACD;AACM,YAAA;AAAA,IACP;AAAA,EACE,GAAA,CAAC,OAAO,YAAY,YAAY,CAAC;AACrC;;"}
@@ -1,24 +1,29 @@
1
1
  import { createElement } from "react";
2
+ import { AccessorTreeStateContext } from "./AccessorTreeStateContext.js";
2
3
  import { DirtinessContext } from "./DirtinessContext.js";
3
4
  import { MutationStateContext } from "./MutationStateContext.js";
4
5
  import { BindingOperationsProvider } from "../accessorPropagation/BindingOperationsProvider.js";
5
6
  function AccessorTree({ state, children }) {
6
7
  if (state.name === "initialized") {
7
- return /* @__PURE__ */ createElement(DirtinessContext.Provider, {
8
+ return /* @__PURE__ */ createElement(AccessorTreeStateContext.Provider, {
9
+ value: state
10
+ }, /* @__PURE__ */ createElement(DirtinessContext.Provider, {
8
11
  value: state.data.hasUnpersistedChanges
9
12
  }, /* @__PURE__ */ createElement(MutationStateContext.Provider, {
10
13
  value: state.data.isMutating
11
14
  }, /* @__PURE__ */ createElement(BindingOperationsProvider, {
12
15
  bindingOperations: state.data.bindingOperations
13
- }, children)));
16
+ }, children))));
14
17
  }
15
- return /* @__PURE__ */ createElement(DirtinessContext.Provider, {
18
+ return /* @__PURE__ */ createElement(AccessorTreeStateContext.Provider, {
19
+ value: state
20
+ }, /* @__PURE__ */ createElement(DirtinessContext.Provider, {
16
21
  value: false
17
22
  }, /* @__PURE__ */ createElement(MutationStateContext.Provider, {
18
23
  value: false
19
24
  }, /* @__PURE__ */ createElement(BindingOperationsProvider, {
20
25
  bindingOperations: void 0
21
- }, children)));
26
+ }, children))));
22
27
  }
23
28
  AccessorTree.displayName = "AccessorTree";
24
29
  export { AccessorTree };
@@ -1 +1 @@
1
- {"version":3,"file":"AccessorTree.js","sources":["../../../src/accessorTree/AccessorTree.tsx"],"sourcesContent":["import type { ReactNode } from 'react'\nimport { BindingOperationsProvider } from '../accessorPropagation'\nimport type { AccessorTreeState } from './AccessorTreeState'\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\t// It is *CRUCIAL* that both branches differ only in props, not structurally. Otherwise there would be far too many\n\t// remounts.\n\tif (state.name === 'initialized') {\n\t\treturn (\n\t\t\t<DirtinessContext.Provider value={state.data.hasUnpersistedChanges}>\n\t\t\t\t<MutationStateContext.Provider value={state.data.isMutating}>\n\t\t\t\t\t<BindingOperationsProvider bindingOperations={state.data.bindingOperations}>\n\t\t\t\t\t\t{children}\n\t\t\t\t\t</BindingOperationsProvider>\n\t\t\t\t</MutationStateContext.Provider>\n\t\t\t</DirtinessContext.Provider>\n\t\t)\n\t}\n\treturn (\n\t\t<DirtinessContext.Provider value={false}>\n\t\t\t<MutationStateContext.Provider value={false}>\n\t\t\t\t<BindingOperationsProvider bindingOperations={undefined}>{children}</BindingOperationsProvider>\n\t\t\t</MutationStateContext.Provider>\n\t\t</DirtinessContext.Provider>\n\t)\n}\nAccessorTree.displayName = 'AccessorTree'\n"],"names":["_jsx"],"mappings":";;;;AAW6B,sBAAA,EAAE,OAAO,YAA+B;AAGhE,MAAA,MAAM,SAAS,eAAe;AAEhC,WAAAA,8BAAC,iBAAiB,UAAjB;AAAA,MAA0B,OAAO,MAAM,KAAK;AAAA,IAAA,GAC5CA,8BAAC,qBAAqB,UAArB;AAAA,MAA8B,OAAO,MAAM,KAAK;AAAA,IAAA,GAC/CA,8BAAA,2BAAA;AAAA,MAA0B,mBAAmB,MAAM,KAAK;AAAA,IAAA,GACvD,QACF,CACD,CACD;AAAA,EAEF;AAEC,SAAAA,8BAAC,iBAAiB,UAAjB;AAAA,IAA0B,OAAO;AAAA,EAAA,GACjCA,8BAAC,qBAAqB,UAArB;AAAA,IAA8B,OAAO;AAAA,EAAA,GACpCA,8BAAA,2BAAA;AAAA,IAA0B,mBAAmB;AAAA,EAAA,GAAY,QAAS,CACpE,CACD;AAEF;AACA,aAAa,cAAc;;"}
1
+ {"version":3,"file":"AccessorTree.js","sources":["../../../src/accessorTree/AccessorTree.tsx"],"sourcesContent":["import type { ReactNode } from 'react'\nimport { BindingOperationsProvider } 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\t// It is *CRUCIAL* that both branches differ only in props, not structurally. Otherwise there would be far too many\n\t// remounts.\n\tif (state.name === 'initialized') {\n\t\treturn (\n\t\t\t<AccessorTreeStateContext.Provider value={state}>\n\t\t\t\t<DirtinessContext.Provider value={state.data.hasUnpersistedChanges}>\n\t\t\t\t\t<MutationStateContext.Provider value={state.data.isMutating}>\n\t\t\t\t\t\t<BindingOperationsProvider bindingOperations={state.data.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)\n\t}\n\treturn (\n\t\t<AccessorTreeStateContext.Provider value={state}>\n\t\t\t<DirtinessContext.Provider value={false}>\n\t\t\t\t<MutationStateContext.Provider value={false}>\n\t\t\t\t\t<BindingOperationsProvider bindingOperations={undefined}>{children}</BindingOperationsProvider>\n\t\t\t\t</MutationStateContext.Provider>\n\t\t\t</DirtinessContext.Provider>\n\t\t</AccessorTreeStateContext.Provider>\n\t)\n}\n\nAccessorTree.displayName = 'AccessorTree'\n"],"names":["_jsx"],"mappings":";;;;;AAY6B,sBAAA,EAAE,OAAO,YAA+B;AAGhE,MAAA,MAAM,SAAS,eAAe;AAEhC,WAAAA,8BAAC,yBAAyB,UAAzB;AAAA,MAAkC,OAAO;AAAA,IAAA,GACzCA,8BAAC,iBAAiB,UAAjB;AAAA,MAA0B,OAAO,MAAM,KAAK;AAAA,IAAA,GAC5CA,8BAAC,qBAAqB,UAArB;AAAA,MAA8B,OAAO,MAAM,KAAK;AAAA,IAAA,GAC/CA,8BAAA,2BAAA;AAAA,MAA0B,mBAAmB,MAAM,KAAK;AAAA,IAAA,GACvD,QACF,CACD,CACD,CACD;AAAA,EAEF;AAEC,SAAAA,8BAAC,yBAAyB,UAAzB;AAAA,IAAkC,OAAO;AAAA,EAAA,GACzCA,8BAAC,iBAAiB,UAAjB;AAAA,IAA0B,OAAO;AAAA,EAAA,GACjCA,8BAAC,qBAAqB,UAArB;AAAA,IAA8B,OAAO;AAAA,EAAA,GACpCA,8BAAA,2BAAA;AAAA,IAA0B,mBAAmB;AAAA,EAAA,GAAY,QAAS,CACpE,CACD,CACD;AAEF;AAEA,aAAa,cAAc;;"}
@@ -0,0 +1,6 @@
1
+ import { createContext } from "react";
2
+ const AccessorTreeStateContext = createContext({
3
+ name: "initializing"
4
+ });
5
+ export { AccessorTreeStateContext };
6
+ //# sourceMappingURL=AccessorTreeStateContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccessorTreeStateContext.js","sources":["../../../src/accessorTree/AccessorTreeStateContext.ts"],"sourcesContent":["import { createContext } from 'react'\nimport { AccessorTreeState } from './AccessorTreeState'\n\nexport const AccessorTreeStateContext = createContext<AccessorTreeState>({\n\tname: 'initializing',\n})\n"],"names":[],"mappings":";AAGO,MAAM,2BAA2B,cAAiC;AAAA,EACxE,MAAM;AACP,CAAC;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"NormalizedPersistedData.js","sources":["../../../src/accessorTree/NormalizedPersistedData.ts"],"sourcesContent":["import type { EntityId, PlaceholderName, Scalar } from '../treeParameters'\nimport type { ServerGeneratedUuid } from './RuntimeId'\n\n// HasMany relations are encoded as sets of entity ids.\n// HasOne relations are encoded as BoxedSingleEntityId just to make them different from actual strings.\n//\t\tNot sure whether that is a reasonable precaution or just pure overhead.\nexport type EntityFieldPersistedData = Scalar | ServerGeneratedUuid | EntityListPersistedData\n\nexport type SingleEntityPersistedData = Map<PlaceholderName, EntityFieldPersistedData>\n\nexport type EntityListPersistedData = Set<EntityId>\n\nexport type PersistedEntityDataStore = Map<EntityId, SingleEntityPersistedData>\n\n// The key is the subTree placeholder name\nexport type SubTreeDataStore = Map<PlaceholderName, ServerGeneratedUuid | EntityListPersistedData>\n\nexport class NormalizedPersistedData {\n\tpublic constructor(\n\t\tpublic readonly subTreeDataStore: SubTreeDataStore,\n\t\tpublic readonly persistedEntityDataStore: PersistedEntityDataStore,\n\t) {}\n}\n"],"names":[],"mappings":"AAiBO,MAAM,wBAAwB;AAAA,EAC7B,YACU,kBACA,0BACf;AAFe,SAAA,mBAAA;AACA,SAAA,2BAAA;AAAA,EACd;AACJ;;"}
1
+ {"version":3,"file":"NormalizedPersistedData.js","sources":["../../../src/accessorTree/NormalizedPersistedData.ts"],"sourcesContent":["import type { EntityId, PlaceholderName, Scalar } from '../treeParameters'\nimport type { ServerId, UniqueEntityId } from './RuntimeId'\n\n// HasMany relations are encoded as sets of entity ids.\n// HasOne relations are encoded as BoxedSingleEntityId just to make them different from actual strings.\n//\t\tNot sure whether that is a reasonable precaution or just pure overhead.\nexport type EntityFieldPersistedData = Scalar | ServerId | EntityListPersistedData\n\nexport type SingleEntityPersistedData = Map<PlaceholderName, EntityFieldPersistedData>\n\nexport type EntityListPersistedData = Set<EntityId>\n\nexport type PersistedEntityDataStore = Map<UniqueEntityId, SingleEntityPersistedData>\n\n// The key is the subTree placeholder name\nexport type SubTreeDataStore = Map<PlaceholderName, ServerId | EntityListPersistedData>\n\nexport class NormalizedPersistedData {\n\tpublic constructor(\n\t\tpublic readonly subTreeDataStore: SubTreeDataStore,\n\t\tpublic readonly persistedEntityDataStore: PersistedEntityDataStore,\n\t) {}\n}\n"],"names":[],"mappings":"AAiBO,MAAM,wBAAwB;AAAA,EAC7B,YACU,kBACA,0BACf;AAFe,SAAA,mBAAA;AACA,SAAA,2BAAA;AAAA,EACd;AACJ;;"}
@@ -5,13 +5,20 @@ var __publicField = (obj, key, value) => {
5
5
  return value;
6
6
  };
7
7
  import { generateEnumerabilityPreventingEntropy } from "../utils/generateEnumerabilityPreventingEntropy.js";
8
- class ServerGeneratedUuid {
9
- constructor(value) {
8
+ class ServerId {
9
+ constructor(value, entityName) {
10
10
  this.value = value;
11
+ this.entityName = entityName;
11
12
  }
12
13
  get existsOnServer() {
13
14
  return true;
14
15
  }
16
+ get uniqueValue() {
17
+ return ServerId.formatUniqueValue(this.value, this.entityName);
18
+ }
19
+ static formatUniqueValue(id, entityName) {
20
+ return `${entityName}_${id}`;
21
+ }
15
22
  }
16
23
  class ClientGeneratedUuid {
17
24
  constructor(value) {
@@ -20,6 +27,9 @@ class ClientGeneratedUuid {
20
27
  get existsOnServer() {
21
28
  return false;
22
29
  }
30
+ get uniqueValue() {
31
+ return this.value;
32
+ }
23
33
  }
24
34
  const _UnpersistedEntityDummyId = class {
25
35
  constructor() {
@@ -31,7 +41,10 @@ const _UnpersistedEntityDummyId = class {
31
41
  return false;
32
42
  }
33
43
  static matchesDummyId(candidate) {
34
- return _UnpersistedEntityDummyId.dummyIdRegex.test(candidate);
44
+ return typeof candidate === "string" && _UnpersistedEntityDummyId.dummyIdRegex.test(candidate);
45
+ }
46
+ get uniqueValue() {
47
+ return this.value;
35
48
  }
36
49
  };
37
50
  let UnpersistedEntityDummyId = _UnpersistedEntityDummyId;
@@ -41,5 +54,5 @@ __publicField(UnpersistedEntityDummyId, "getNextSeed", (() => {
41
54
  })());
42
55
  __publicField(UnpersistedEntityDummyId, "entropyLength", 5);
43
56
  __publicField(UnpersistedEntityDummyId, "dummyIdRegex", new RegExp(`^adminOnlyDummyId-\\d{${_UnpersistedEntityDummyId.entropyLength}}-\\d+$`));
44
- export { ClientGeneratedUuid, ServerGeneratedUuid, UnpersistedEntityDummyId };
57
+ export { ClientGeneratedUuid, ServerId, UnpersistedEntityDummyId };
45
58
  //# sourceMappingURL=RuntimeId.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RuntimeId.js","sources":["../../../src/accessorTree/RuntimeId.ts"],"sourcesContent":["import { generateEnumerabilityPreventingEntropy } from '../utils'\n\nexport interface RuntimeIdSpec {\n\texistsOnServer: boolean\n\tvalue: string\n}\n\nexport class ServerGeneratedUuid implements RuntimeIdSpec {\n\tpublic get existsOnServer(): true {\n\t\treturn true\n\t}\n\tpublic constructor(public readonly value: string) {}\n}\n\nexport class ClientGeneratedUuid implements RuntimeIdSpec {\n\tpublic get existsOnServer(): false {\n\t\treturn false\n\t}\n\tpublic constructor(public readonly value: string) {}\n}\n\nexport class UnpersistedEntityDummyId implements RuntimeIdSpec {\n\tpublic get existsOnServer(): false {\n\t\treturn false\n\t}\n\tpublic readonly value: string\n\n\tprivate static getNextSeed = (() => {\n\t\tlet seed = 0\n\t\treturn () => seed++\n\t})()\n\n\tpublic constructor() {\n\t\tconst enumerabilityPreventingEntropy = generateEnumerabilityPreventingEntropy(\n\t\t\tUnpersistedEntityDummyId.entropyLength,\n\t\t)\n\n\t\t// KEEP THIS IN SYNC WITH THE REGEX BELOW!!!\n\t\tthis.value = `adminOnlyDummyId-${enumerabilityPreventingEntropy}-${UnpersistedEntityDummyId.getNextSeed()}`\n\t}\n\n\tprivate static entropyLength = 5\n\tprivate static dummyIdRegex = new RegExp(`^adminOnlyDummyId-\\\\d{${UnpersistedEntityDummyId.entropyLength}}-\\\\d+$`)\n\tpublic static matchesDummyId(candidate: string): boolean {\n\t\treturn UnpersistedEntityDummyId.dummyIdRegex.test(candidate)\n\t}\n}\n\nexport type RuntimeId = ServerGeneratedUuid | ClientGeneratedUuid | UnpersistedEntityDummyId\n"],"names":[],"mappings":";;;;;;;AAOO,MAAM,oBAA6C;AAAA,EAIlD,YAA4B,OAAe;AAAf,SAAA,QAAA;AAAA,EAAgB;AAAA,MAHxC,iBAAuB;AAC1B,WAAA;AAAA,EACR;AAED;AAEO,MAAM,oBAA6C;AAAA,EAIlD,YAA4B,OAAe;AAAf,SAAA,QAAA;AAAA,EAAgB;AAAA,MAHxC,iBAAwB;AAC3B,WAAA;AAAA,EACR;AAED;AAEO,wCAAwD;AAAA,EAWvD,cAAc;AAPL;AAQT,UAAA,iCAAiC,uCACtC,0BAAyB,aAC1B;AAGA,SAAK,QAAQ,oBAAoB,kCAAkC,0BAAyB,YAAY;AAAA,EACzG;AAAA,MAjBW,iBAAwB;AAC3B,WAAA;AAAA,EACR;AAAA,SAmBc,eAAe,WAA4B;AACjD,WAAA,0BAAyB,aAAa,KAAK,SAAS;AAAA,EAC5D;AACD;AAzBO;AAMS,cANT,0BAMS,eAAqB,OAAA;AACnC,MAAI,OAAO;AACX,SAAO,MAAM;AAAA;AAYC,cApBT,0BAoBS,iBAAgB;AAChB,cArBT,0BAqBS,gBAAe,IAAI,OAAO,yBAAyB,0BAAyB,sBAAsB;;"}
1
+ {"version":3,"file":"RuntimeId.js","sources":["../../../src/accessorTree/RuntimeId.ts"],"sourcesContent":["import { generateEnumerabilityPreventingEntropy } from '../utils'\nimport { EntityId } from '../treeParameters'\n\nexport type UniqueEntityId = string & { __type: 'UniqueEntityId' }\n\nexport interface RuntimeIdSpec {\n\texistsOnServer: boolean\n\tvalue: EntityId\n\tuniqueValue: UniqueEntityId\n}\n\nexport class ServerId implements RuntimeIdSpec {\n\tpublic get existsOnServer(): true {\n\t\treturn true\n\t}\n\tpublic constructor(public readonly value: EntityId, public readonly entityName: string) {\n\t}\n\n\tget uniqueValue() {\n\t\treturn ServerId.formatUniqueValue(this.value, this.entityName)\n\t}\n\n\tstatic formatUniqueValue(id: EntityId, entityName: string): UniqueEntityId {\n\t\treturn `${entityName}_${id}` as UniqueEntityId\n\t}\n}\n\nexport class ClientGeneratedUuid implements RuntimeIdSpec {\n\tpublic get existsOnServer(): false {\n\t\treturn false\n\t}\n\tpublic constructor(public readonly value: string) {}\n\n\tget uniqueValue() {\n\t\treturn this.value as UniqueEntityId\n\t}\n}\n\nexport class UnpersistedEntityDummyId implements RuntimeIdSpec {\n\tpublic get existsOnServer(): false {\n\t\treturn false\n\t}\n\tpublic readonly value: string\n\n\tprivate static getNextSeed = (() => {\n\t\tlet seed = 0\n\t\treturn () => seed++\n\t})()\n\n\tpublic constructor() {\n\t\tconst enumerabilityPreventingEntropy = generateEnumerabilityPreventingEntropy(\n\t\t\tUnpersistedEntityDummyId.entropyLength,\n\t\t)\n\n\t\t// KEEP THIS IN SYNC WITH THE REGEX BELOW!!!\n\t\tthis.value = `adminOnlyDummyId-${enumerabilityPreventingEntropy}-${UnpersistedEntityDummyId.getNextSeed()}`\n\t}\n\n\tprivate static entropyLength = 5\n\tprivate static dummyIdRegex = new RegExp(`^adminOnlyDummyId-\\\\d{${UnpersistedEntityDummyId.entropyLength}}-\\\\d+$`)\n\tpublic static matchesDummyId(candidate: EntityId): boolean {\n\t\treturn typeof candidate === 'string' && UnpersistedEntityDummyId.dummyIdRegex.test(candidate)\n\t}\n\n\tget uniqueValue() {\n\t\treturn this.value as UniqueEntityId\n\t}\n}\n\nexport type RuntimeId = ServerId | ClientGeneratedUuid | UnpersistedEntityDummyId\n"],"names":[],"mappings":";;;;;;;AAWO,MAAM,SAAkC;AAAA,EAIvC,YAA4B,OAAiC,YAAoB;AAArD,SAAA,QAAA;AAAiC,SAAA,aAAA;AAAA,EACpE;AAAA,MAJW,iBAAuB;AAC1B,WAAA;AAAA,EACR;AAAA,MAII,cAAc;AACjB,WAAO,SAAS,kBAAkB,KAAK,OAAO,KAAK,UAAU;AAAA,EAC9D;AAAA,SAEO,kBAAkB,IAAc,YAAoC;AAC1E,WAAO,GAAG,cAAc;AAAA,EACzB;AACD;AAEO,MAAM,oBAA6C;AAAA,EAIlD,YAA4B,OAAe;AAAf,SAAA,QAAA;AAAA,EAAgB;AAAA,MAHxC,iBAAwB;AAC3B,WAAA;AAAA,EACR;AAAA,MAGI,cAAc;AACjB,WAAO,KAAK;AAAA,EACb;AACD;AAEO,wCAAwD;AAAA,EAWvD,cAAc;AAPL;AAQT,UAAA,iCAAiC,uCACtC,0BAAyB,aAC1B;AAGA,SAAK,QAAQ,oBAAoB,kCAAkC,0BAAyB,YAAY;AAAA,EACzG;AAAA,MAjBW,iBAAwB;AAC3B,WAAA;AAAA,EACR;AAAA,SAmBc,eAAe,WAA8B;AAC1D,WAAO,OAAO,cAAc,YAAY,0BAAyB,aAAa,KAAK,SAAS;AAAA,EAC7F;AAAA,MAEI,cAAc;AACjB,WAAO,KAAK;AAAA,EACb;AACD;AA7BO;AAMS,cANT,0BAMS,eAAqB,OAAA;AACnC,MAAI,OAAO;AACX,SAAO,MAAM;AAAA;AAYC,cApBT,0BAoBS,iBAAgB;AAChB,cArBT,0BAqBS,gBAAe,IAAI,OAAO,yBAAyB,0BAAyB,sBAAsB;;"}
@@ -0,0 +1,5 @@
1
+ import { useContext } from "react";
2
+ import { AccessorTreeStateContext } from "./AccessorTreeStateContext.js";
3
+ const useAccessorTreeState = () => useContext(AccessorTreeStateContext);
4
+ export { useAccessorTreeState };
5
+ //# sourceMappingURL=useAccessorTreeState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAccessorTreeState.js","sources":["../../../src/accessorTree/useAccessorTreeState.ts"],"sourcesContent":["import { useContext } from 'react'\nimport { AccessorTreeStateContext } from './AccessorTreeStateContext'\n\nexport const useAccessorTreeState = () => useContext(AccessorTreeStateContext)\n"],"names":[],"mappings":";;AAGa,MAAA,uBAAuB,MAAM,WAAW,wBAAwB;;"}
@@ -2,7 +2,6 @@ import { BindingError } from "../BindingError.js";
2
2
  import { ErrorAccessor } from "./ErrorAccessor.js";
3
3
  import { QueryLanguage } from "../queryLanguage/QueryLanguage.js";
4
4
  import { PlaceholderGenerator } from "../markers/PlaceholderGenerator.js";
5
- import { ServerGeneratedUuid } from "../accessorTree/RuntimeId.js";
6
5
  class EntityAccessor {
7
6
  constructor(stateKey, operations, runtimeId, key, name, fieldData, dataFromServer, hasUnpersistedChanges, errors, environment, getAccessor) {
8
7
  this.stateKey = stateKey;
@@ -61,18 +60,6 @@ class EntityAccessor {
61
60
  getEntityList(entityList) {
62
61
  return this.getRelativeEntityList(QueryLanguage.desugarRelativeEntityList(entityList, this.environment));
63
62
  }
64
- getKeyConnectedOnServer(entity) {
65
- const desugared = QueryLanguage.desugarRelativeSingleEntity(entity, this.environment);
66
- const lastHasOne = desugared.hasOneRelationPath[desugared.hasOneRelationPath.length - 1];
67
- const lastHasOnePlaceholder = PlaceholderGenerator.getHasOneRelationPlaceholder(lastHasOne);
68
- let containingAccessor = this;
69
- if (desugared.hasOneRelationPath.length > 1) {
70
- containingAccessor = this.getRelativeSingleEntity({
71
- hasOneRelationPath: desugared.hasOneRelationPath.slice(0, -1)
72
- });
73
- }
74
- return containingAccessor.getPersistedKeyByPlaceholder(lastHasOnePlaceholder);
75
- }
76
63
  getRelativeSingleField(field) {
77
64
  return this.getRelativeSingleEntity(field).getAccessorByPlaceholder(PlaceholderGenerator.getFieldPlaceholder(field.field));
78
65
  }
@@ -99,25 +86,6 @@ For more information, please consult the documentation.
99
86
  }
100
87
  return record.getAccessor();
101
88
  }
102
- getPersistedKeyByPlaceholder(placeholderName) {
103
- if (this.dataFromServer === void 0) {
104
- return null;
105
- }
106
- const key = this.dataFromServer.get(placeholderName);
107
- if (key instanceof ServerGeneratedUuid) {
108
- return key.value;
109
- }
110
- if (key === null) {
111
- return null;
112
- }
113
- if (key === void 0) {
114
- throw new BindingError(`EntityAccessor.getKeyConnectedOnServer: unknown placeholder '${placeholderName}'. Unless this is just a typo, this typically happens when a has-one relation hasn't been registered during static render.`);
115
- }
116
- if (key instanceof Set) {
117
- throw new BindingError(`EntityAccessor.getKeyConnectedOnServer: the placeholder '${placeholderName}' refers to a has-many relation, not a has-one. This method is meant exclusively for has-one relations.`);
118
- }
119
- throw new BindingError(`EntityAccessor.getKeyConnectedOnServer: the placeholder '${placeholderName}' refers to a scalar field, not ahas-one relation. This method is meant exclusively for has-one relations.`);
120
- }
121
89
  }
122
90
  export { EntityAccessor };
123
91
  //# sourceMappingURL=EntityAccessor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EntityAccessor.js","sources":["../../../src/accessors/EntityAccessor.ts"],"sourcesContent":["import { RuntimeId, ServerGeneratedUuid, SingleEntityPersistedData } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { EntityOperations } from '../core/operations'\nimport type { Environment } from '../dao'\nimport { PlaceholderGenerator } from '../markers'\nimport { QueryLanguage } from '../queryLanguage'\nimport type {\n\tEntityId,\n\tEntityName,\n\tEntityRealmKey,\n\tFieldName,\n\tFieldValue,\n\tRelativeEntityList,\n\tRelativeSingleEntity,\n\tRelativeSingleField,\n\tSugaredRelativeEntityList,\n\tSugaredRelativeSingleEntity,\n\tSugaredRelativeSingleField,\n} from '../treeParameters'\nimport type { AsyncBatchUpdatesOptions } from './AsyncBatchUpdatesOptions'\nimport type { BatchUpdatesOptions } from './BatchUpdatesOptions'\nimport type { EntityListAccessor } from './EntityListAccessor'\nimport type { Errorable } from './Errorable'\nimport { ErrorAccessor } from './ErrorAccessor'\nimport type { FieldAccessor } from './FieldAccessor'\nimport type { PersistErrorOptions } from './PersistErrorOptions'\nimport type { PersistSuccessOptions } from './PersistSuccessOptions'\nimport type { EntityRealmState } from '../core/state'\n\nclass EntityAccessor implements Errorable {\n\tpublic constructor(\n\t\tprivate readonly stateKey: EntityRealmState,\n\t\tprivate readonly operations: EntityOperations,\n\t\tprivate readonly runtimeId: RuntimeId,\n\t\tpublic readonly key: EntityRealmKey, // ⚠️ This is *NOT* the id! ⚠️\n\t\tpublic readonly name: EntityName,\n\t\tprivate readonly fieldData: EntityAccessor.FieldData,\n\t\tprivate readonly dataFromServer: SingleEntityPersistedData | undefined,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly environment: Environment,\n\t\tpublic readonly getAccessor: EntityAccessor.GetEntityAccessor,\n\t) {}\n\n\tpublic get idOnServer(): string | undefined {\n\t\treturn this.runtimeId.existsOnServer ? this.runtimeId.value : undefined\n\t}\n\n\t/**\n\t * Note that for entities that don't yet exist on server this will return a dummy id.\n\t */\n\tpublic get id(): EntityId {\n\t\treturn this.runtimeId.value\n\t}\n\n\tpublic get existsOnServer(): boolean {\n\t\treturn this.runtimeId.existsOnServer\n\t}\n\n\t//\n\n\tpublic addError(error: ErrorAccessor.Error | string): () => void {\n\t\treturn this.operations.addError(this.stateKey, ErrorAccessor.normalizeError(error))\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityAccessor.RuntimeEntityEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t): () => void {\n\t\treturn this.operations.addEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic batchUpdates(performUpdates: EntityAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.batchUpdates(this.stateKey, performUpdates)\n\t}\n\n\tpublic connectEntityAtField(field: FieldName, entityToConnect: EntityAccessor): void {\n\t\tthis.operations.connectEntityAtField(this.stateKey, field, entityToConnect)\n\t}\n\n\tpublic disconnectEntityAtField(field: FieldName, initializeReplacement?: EntityAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.disconnectEntityAtField(this.stateKey, field, initializeReplacement)\n\t}\n\n\tpublic deleteEntity(): void {\n\t\tthis.operations.deleteEntity(this.stateKey)\n\t}\n\n\t//\n\n\tpublic updateValues(fieldValuePairs: EntityAccessor.FieldValuePairs): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst entries = Array.isArray(fieldValuePairs) ? fieldValuePairs : Object.entries(fieldValuePairs)\n\n\t\t\tfor (const [field, value] of entries) {\n\t\t\t\tgetAccessor().getField(field).updateValue(value)\n\t\t\t}\n\t\t})\n\t}\n\n\t/**\n\t * Please keep in mind that this method signature is literally impossible to implement safely. The generic parameter\n\t * is really just a way to succinctly write a type cast. Nothing more, really.\n\t */\n\tpublic getField<Value extends FieldValue = FieldValue>(\n\t\tfield: SugaredRelativeSingleField | string,\n\t): FieldAccessor<Value> {\n\t\treturn this.getRelativeSingleField<Value>(QueryLanguage.desugarRelativeSingleField(field, this.environment))\n\t}\n\n\tpublic getEntity(entity: SugaredRelativeSingleEntity | string): EntityAccessor {\n\t\treturn this.getRelativeSingleEntity(QueryLanguage.desugarRelativeSingleEntity(entity, this.environment))\n\t}\n\n\tpublic getEntityList(entityList: SugaredRelativeEntityList | string): EntityListAccessor {\n\t\treturn this.getRelativeEntityList(QueryLanguage.desugarRelativeEntityList(entityList, this.environment))\n\t}\n\n\tpublic getKeyConnectedOnServer(entity: SugaredRelativeSingleEntity | string): string | null {\n\t\tconst desugared = QueryLanguage.desugarRelativeSingleEntity(entity, this.environment)\n\t\tconst lastHasOne = desugared.hasOneRelationPath[desugared.hasOneRelationPath.length - 1]\n\t\tconst lastHasOnePlaceholder = PlaceholderGenerator.getHasOneRelationPlaceholder(lastHasOne)\n\n\t\tlet containingAccessor: EntityAccessor = this\n\n\t\tif (desugared.hasOneRelationPath.length > 1) {\n\t\t\tcontainingAccessor = this.getRelativeSingleEntity({\n\t\t\t\thasOneRelationPath: desugared.hasOneRelationPath.slice(0, -1),\n\t\t\t})\n\t\t}\n\t\treturn containingAccessor.getPersistedKeyByPlaceholder(lastHasOnePlaceholder)\n\t}\n\n\t//\n\n\t/**\n\t * @see EntityAccessor.getField\n\t */\n\tpublic getRelativeSingleField<Value extends FieldValue = FieldValue>(field: RelativeSingleField): FieldAccessor<Value> {\n\t\treturn this.getRelativeSingleEntity(field).getAccessorByPlaceholder(\n\t\t\tPlaceholderGenerator.getFieldPlaceholder(field.field),\n\t\t) as unknown as FieldAccessor<Value>\n\t}\n\n\tpublic getRelativeSingleEntity(relativeSingleEntity: RelativeSingleEntity): EntityAccessor {\n\t\tlet relativeTo: EntityAccessor = this\n\n\t\tfor (const hasOneRelation of relativeSingleEntity.hasOneRelationPath) {\n\t\t\trelativeTo = relativeTo.getAccessorByPlaceholder(\n\t\t\t\tPlaceholderGenerator.getHasOneRelationPlaceholder(hasOneRelation),\n\t\t\t) as EntityAccessor\n\t\t}\n\t\treturn relativeTo\n\t}\n\n\tpublic getRelativeEntityList(entityList: RelativeEntityList): EntityListAccessor {\n\t\treturn this.getRelativeSingleEntity(entityList).getAccessorByPlaceholder(\n\t\t\tPlaceholderGenerator.getHasManyRelationPlaceholder(entityList.hasManyRelation),\n\t\t) as EntityListAccessor\n\t}\n\n\tprivate getAccessorByPlaceholder(placeholderName: FieldName): EntityAccessor.NestedAccessor {\n\t\tconst record = this.fieldData.get(placeholderName)\n\t\tif (record === undefined) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`EntityAccessor: unknown field placeholder '${placeholderName} on ${this.name}'. Unless this is just a typo, this is ` +\n\t\t\t\t\t`typically caused by one of the following:\\n` +\n\t\t\t\t\t`\\t• Trying to access a field that has not been registered during static render, and thus lacks a marker and an accessor.\\n` +\n\t\t\t\t\t`\\t• Misusing an EntityAccessor getter. If you used one of the getRelative[…] family, please make sure all ` +\n\t\t\t\t\t`parameters match the marker tree exactly.` +\n\t\t\t\t\t`\\n\\nFor more information, please consult the documentation.\\n\\n`,\n\t\t\t)\n\t\t}\n\t\treturn record.getAccessor()\n\t}\n\n\tprivate getPersistedKeyByPlaceholder(placeholderName: string): string | null {\n\t\tif (this.dataFromServer === undefined) {\n\t\t\treturn null\n\t\t}\n\t\tconst key = this.dataFromServer.get(placeholderName)\n\n\t\tif (key instanceof ServerGeneratedUuid) {\n\t\t\treturn key.value\n\t\t}\n\t\tif (key === null) {\n\t\t\t// TODO this also returns null and fails to throw when placeholderName points to a regular scalar field that\n\t\t\t// \thappens to be also null.\n\t\t\treturn null\n\t\t}\n\n\t\t// From now on, we're past the happy path, way into error land.\n\t\tif (key === undefined) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`EntityAccessor.getKeyConnectedOnServer: unknown placeholder '${placeholderName}'. Unless this is just ` +\n\t\t\t\t\t`a typo, this typically happens when a has-one relation hasn't been registered during static render.`,\n\t\t\t)\n\t\t}\n\t\tif (key instanceof Set) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`EntityAccessor.getKeyConnectedOnServer: the placeholder '${placeholderName}' refers to a has-many relation, ` +\n\t\t\t\t\t`not a has-one. This method is meant exclusively for has-one relations.`,\n\t\t\t)\n\t\t}\n\t\tthrow new BindingError(\n\t\t\t`EntityAccessor.getKeyConnectedOnServer: the placeholder '${placeholderName}' refers to a scalar field, not a` +\n\t\t\t\t`has-one relation. This method is meant exclusively for has-one relations.`,\n\t\t)\n\t}\n}\n\nnamespace EntityAccessor {\n\texport interface FieldDatum {\n\t\tgetAccessor(): NestedAccessor\n\t}\n\texport type NestedAccessor = EntityAccessor | EntityListAccessor | FieldAccessor\n\n\texport type FieldValuePairs =\n\t\t| {\n\t\t\t\t[field: string]: FieldValue\n\t\t }\n\t\t| Iterable<[SugaredRelativeSingleField | string, FieldValue]>\n\n\texport type FieldData = Map<FieldName, FieldDatum>\n\n\texport type GetEntityAccessor = () => EntityAccessor\n\texport type BatchUpdatesHandler = (getAccessor: GetEntityAccessor, options: BatchUpdatesOptions) => void\n\texport type UpdateListener = (accessor: EntityAccessor) => void\n\n\texport type BeforePersistHandler = (\n\t\tgetAccessor: GetEntityAccessor,\n\t\toptions: AsyncBatchUpdatesOptions,\n\t) => void | Promise<void | BeforePersistHandler>\n\n\texport type PersistErrorHandler = (\n\t\tgetAccessor: GetEntityAccessor,\n\t\toptions: PersistErrorOptions,\n\t) => void | Promise<void>\n\n\texport type PersistSuccessHandler = (\n\t\tgetAccessor: GetEntityAccessor,\n\t\toptions: PersistSuccessOptions,\n\t) => void | Promise<void | PersistSuccessHandler>\n\n\texport interface RuntimeEntityEventListenerMap {\n\t\tbeforePersist: BeforePersistHandler\n\t\tbeforeUpdate: BatchUpdatesHandler\n\t\tconnectionUpdate: UpdateListener\n\t\tpersistError: PersistErrorHandler\n\t\tpersistSuccess: PersistSuccessHandler\n\t\tupdate: UpdateListener\n\t}\n\texport interface EntityEventListenerMap extends RuntimeEntityEventListenerMap {\n\t\tinitialize: BatchUpdatesHandler\n\t}\n\texport type EntityEventType = keyof EntityEventListenerMap\n}\n\nexport { EntityAccessor }\n"],"names":[],"mappings":";;;;;AA6BA,MAAM,eAAoC;AAAA,EAClC,YACW,UACA,YACA,WACD,KACA,MACC,WACA,gBACD,uBACA,QACA,aACA,aACf;AAXgB,SAAA,WAAA;AACA,SAAA,aAAA;AACA,SAAA,YAAA;AACD,SAAA,MAAA;AACA,SAAA,OAAA;AACC,SAAA,YAAA;AACA,SAAA,iBAAA;AACD,SAAA,wBAAA;AACA,SAAA,SAAA;AACA,SAAA,cAAA;AACA,SAAA,cAAA;AAAA,EACd;AAAA,MAEQ,aAAiC;AAC3C,WAAO,KAAK,UAAU,iBAAiB,KAAK,UAAU,QAAQ;AAAA,EAC/D;AAAA,MAKW,KAAe;AACzB,WAAO,KAAK,UAAU;AAAA,EACvB;AAAA,MAEW,iBAA0B;AACpC,WAAO,KAAK,UAAU;AAAA,EACvB;AAAA,EAIO,SAAS,OAAiD;AACzD,WAAA,KAAK,WAAW,SAAS,KAAK,UAAU,cAAc,eAAe,KAAK,CAAC;AAAA,EACnF;AAAA,EAEO,iBACN,OACA,UACa;AACb,WAAO,KAAK,WAAW,iBAAiB,KAAK,UAAU,OAAO,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ityAccessor.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'\n\nclass EntityAccessor implements Errorable {\n\tpublic constructor(\n\t\tprivate readonly stateKey: EntityRealmState,\n\t\tprivate readonly operations: EntityOperations,\n\t\tprivate readonly runtimeId: RuntimeId,\n\t\tpublic readonly key: EntityRealmKey, // ⚠️ This is *NOT* the id! ⚠️\n\t\tpublic readonly name: EntityName,\n\t\tprivate readonly fieldData: EntityAccessor.FieldData,\n\t\tprivate readonly dataFromServer: SingleEntityPersistedData | undefined,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly environment: Environment,\n\t\tpublic readonly getAccessor: EntityAccessor.GetEntityAccessor,\n\t) {}\n\n\tpublic get idOnServer(): 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.stateKey, ErrorAccessor.normalizeError(error))\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityAccessor.RuntimeEntityEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t): () => void {\n\t\treturn this.operations.addEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic batchUpdates(performUpdates: EntityAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.batchUpdates(this.stateKey, performUpdates)\n\t}\n\n\tpublic connectEntityAtField(field: FieldName, entityToConnect: EntityAccessor): void {\n\t\tthis.operations.connectEntityAtField(this.stateKey, field, entityToConnect)\n\t}\n\n\tpublic disconnectEntityAtField(field: FieldName, initializeReplacement?: EntityAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.disconnectEntityAtField(this.stateKey, field, initializeReplacement)\n\t}\n\n\tpublic deleteEntity(): void {\n\t\tthis.operations.deleteEntity(this.stateKey)\n\t}\n\n\t//\n\n\tpublic updateValues(fieldValuePairs: EntityAccessor.FieldValuePairs): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst entries = Array.isArray(fieldValuePairs) ? fieldValuePairs : Object.entries(fieldValuePairs)\n\n\t\t\tfor (const [field, value] of entries) {\n\t\t\t\tgetAccessor().getField(field).updateValue(value)\n\t\t\t}\n\t\t})\n\t}\n\n\t/**\n\t * Please keep in mind that this method signature is literally impossible to implement safely. The generic parameter\n\t * is really just a way to succinctly write a type cast. Nothing more, really.\n\t */\n\tpublic getField<Value extends FieldValue = FieldValue>(\n\t\tfield: SugaredRelativeSingleField | string,\n\t): FieldAccessor<Value> {\n\t\treturn this.getRelativeSingleField<Value>(QueryLanguage.desugarRelativeSingleField(field, this.environment))\n\t}\n\n\tpublic getEntity(entity: SugaredRelativeSingleEntity | string): EntityAccessor {\n\t\treturn this.getRelativeSingleEntity(QueryLanguage.desugarRelativeSingleEntity(entity, this.environment))\n\t}\n\n\tpublic getEntityList(entityList: SugaredRelativeEntityList | string): EntityListAccessor {\n\t\treturn this.getRelativeEntityList(QueryLanguage.desugarRelativeEntityList(entityList, this.environment))\n\t}\n\n\t//\n\n\t/**\n\t * @see EntityAccessor.getField\n\t */\n\tpublic getRelativeSingleField<Value extends FieldValue = FieldValue>(field: RelativeSingleField): FieldAccessor<Value> {\n\t\treturn this.getRelativeSingleEntity(field).getAccessorByPlaceholder(\n\t\t\tPlaceholderGenerator.getFieldPlaceholder(field.field),\n\t\t) as unknown as FieldAccessor<Value>\n\t}\n\n\tpublic getRelativeSingleEntity(relativeSingleEntity: RelativeSingleEntity): EntityAccessor {\n\t\tlet relativeTo: EntityAccessor = this\n\n\t\tfor (const hasOneRelation of relativeSingleEntity.hasOneRelationPath) {\n\t\t\trelativeTo = relativeTo.getAccessorByPlaceholder(\n\t\t\t\tPlaceholderGenerator.getHasOneRelationPlaceholder(hasOneRelation),\n\t\t\t) as EntityAccessor\n\t\t}\n\t\treturn relativeTo\n\t}\n\n\tpublic getRelativeEntityList(entityList: RelativeEntityList): EntityListAccessor {\n\t\treturn this.getRelativeSingleEntity(entityList).getAccessorByPlaceholder(\n\t\t\tPlaceholderGenerator.getHasManyRelationPlaceholder(entityList.hasManyRelation),\n\t\t) as EntityListAccessor\n\t}\n\n\tprivate getAccessorByPlaceholder(placeholderName: FieldName): EntityAccessor.NestedAccessor {\n\t\tconst record = this.fieldData.get(placeholderName)\n\t\tif (record === undefined) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`EntityAccessor: unknown field placeholder '${placeholderName} on ${this.name}'. Unless this is just a typo, this is ` +\n\t\t\t\t\t`typically caused by one of the following:\\n` +\n\t\t\t\t\t`\\t• Trying to access a field that has not been registered during static render, and thus lacks a marker and an accessor.\\n` +\n\t\t\t\t\t`\\t• Misusing an EntityAccessor getter. If you used one of the getRelative[…] family, please make sure all ` +\n\t\t\t\t\t`parameters match the marker tree exactly.` +\n\t\t\t\t\t`\\n\\nFor more information, please consult the documentation.\\n\\n`,\n\t\t\t)\n\t\t}\n\t\treturn record.getAccessor()\n\t}\n}\n\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":";;;;AA6BA,MAAM,eAA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E,YAAY,KAAK;AAAA,MAChD;AAAA,IAAA,CACA;AAAA,EACF;AAAA,EAMO,SACN,OACuB;AACvB,WAAO,KAAK,uBAA8B,cAAc,2BAA2B,OAAO,KAAK,WAAW,CAAC;AAAA,EAC5G;AAAA,EAEO,UAAU,QAA8D;AAC9E,WAAO,KAAK,wBAAwB,cAAc,4BAA4B,QAAQ,KAAK,WAAW,CAAC;AAAA,EACxG;AAAA,EAEO,cAAc,YAAoE;AACxF,WAAO,KAAK,sBAAsB,cAAc,0BAA0B,YAAY,KAAK,WAAW,CAAC;AAAA,EACxG;AAAA,EAOO,uBAA8D,OAAkD;AAC/G,WAAA,KAAK,wBAAwB,KAAK,EAAE,yBAC1C,qBAAqB,oBAAoB,MAAM,KAAK,CACrD;AAAA,EACD;AAAA,EAEO,wBAAwB,sBAA4D;AAC1F,QAAI,aAA6B;AAEtB,eAAA,kBAAkB,qBAAqB,oBAAoB;AACrE,mBAAa,WAAW,yBACvB,qBAAqB,6BAA6B,cAAc,CACjE;AAAA,IACD;AACO,WAAA;AAAA,EACR;AAAA,EAEO,sBAAsB,YAAoD;AACzE,WAAA,KAAK,wBAAwB,UAAU,EAAE,yBAC/C,qBAAqB,8BAA8B,WAAW,eAAe,CAC9E;AAAA,EACD;AAAA,EAEQ,yBAAyB,iBAA2D;AAC3F,UAAM,SAAS,KAAK,UAAU,IAAI,eAAe;AACjD,QAAI,WAAW,QAAW;AACzB,YAAM,IAAI,aACT,8CAA8C,sBAAsB,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAM1E;AAAA,IACD;AACA,WAAO,OAAO;EACf;AACD;;"}
@@ -36,7 +36,7 @@ class EntityListAccessor {
36
36
  return this._children.size;
37
37
  }
38
38
  hasEntityOnServer(entityOrItsId) {
39
- if (typeof entityOrItsId === "string") {
39
+ if (typeof entityOrItsId === "string" || typeof entityOrItsId === "number") {
40
40
  return this.idsPersistedOnServer.has(entityOrItsId);
41
41
  }
42
42
  const idOnServer = entityOrItsId.idOnServer;
@@ -1 +1 @@
1
- {"version":3,"file":"EntityListAccessor.js","sources":["../../../src/accessors/EntityListAccessor.ts"],"sourcesContent":["import type { ListOperations } from '../core/operations'\nimport type { Environment } from '../dao'\nimport type { EntityId, EntityRealmKey } from '../treeParameters'\nimport type { AsyncBatchUpdatesOptions } from './AsyncBatchUpdatesOptions'\nimport type { BatchUpdatesOptions } from './BatchUpdatesOptions'\nimport type { EntityAccessor } from './EntityAccessor'\nimport type { Errorable } from './Errorable'\nimport { ErrorAccessor } from './ErrorAccessor'\nimport type { PersistErrorOptions } from './PersistErrorOptions'\nimport type { PersistSuccessOptions } from './PersistSuccessOptions'\nimport type { EntityListState } from '../core/state'\nimport { RuntimeId } from '../accessorTree'\n\nclass EntityListAccessor implements Errorable {\n\tpublic constructor(\n\t\tprivate readonly stateKey: EntityListState,\n\t\tprivate readonly operations: ListOperations,\n\t\tprivate readonly _children: ReadonlyMap<EntityId, { getAccessor: EntityAccessor.GetEntityAccessor }>,\n\t\tprivate readonly _idsPersistedOnServer: ReadonlySet<string>,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly environment: Environment,\n\t\tpublic readonly getAccessor: EntityListAccessor.GetEntityListAccessor,\n\t) {}\n\n\t/**\n\t * Returns all entity keys that are on the list.\n\t * **KEYS ARE NOT IDS!**\n\t * @see EntityAccessor.key\n\t */\n\tpublic *keys(): IterableIterator<EntityRealmKey> {\n\t\tfor (const accessor of this) {\n\t\t\tyield accessor.key\n\t\t}\n\t}\n\n\tpublic *ids(): IterableIterator<EntityId> {\n\t\treturn this._children.keys()\n\t}\n\n\t/**\n\t * This will only contain the ids that the server knows about. Not necessarily the ids that have been added on\n\t * the list since the last server query.\n\t */\n\tpublic get idsPersistedOnServer(): Set<string> {\n\t\treturn new Set(this._idsPersistedOnServer)\n\t}\n\n\tpublic *[Symbol.iterator](): IterableIterator<EntityAccessor> {\n\t\tfor (const { getAccessor } of this._children.values()) {\n\t\t\tyield getAccessor()\n\t\t}\n\t}\n\n\tpublic hasEntityId(id: EntityId): boolean {\n\t\treturn this._children.has(id)\n\t}\n\n\tpublic isEmpty(): boolean {\n\t\treturn this.length === 0\n\t}\n\n\tpublic get length(): number {\n\t\treturn this._children.size\n\t}\n\n\tpublic hasEntityOnServer(entityOrItsId: EntityAccessor | EntityId): boolean {\n\t\tif (typeof entityOrItsId === 'string') {\n\t\t\treturn this.idsPersistedOnServer.has(entityOrItsId)\n\t\t}\n\t\tconst idOnServer = entityOrItsId.idOnServer\n\t\tif (idOnServer === undefined) {\n\t\t\treturn false\n\t\t}\n\t\treturn this.idsPersistedOnServer.has(idOnServer)\n\t}\n\n\tpublic deleteAll(): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst list = getAccessor()\n\t\t\tfor (const entity of list) {\n\t\t\t\tentity.deleteEntity()\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectAll(): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst list = getAccessor()\n\t\t\tfor (const entity of list) {\n\t\t\t\tlist.disconnectEntity(entity)\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic addError(error: ErrorAccessor.Error | string): () => void {\n\t\treturn this.operations.addError(this.stateKey, ErrorAccessor.normalizeError(error))\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityListAccessor.RuntimeEntityListEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityListAccessor.RuntimeEntityListEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic addChildEventListener<Type extends keyof EntityAccessor.EntityEventListenerMap>(\n\t\tstate: EntityListState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addChildEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic batchUpdates(performUpdates: EntityListAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.batchUpdates(this.stateKey, performUpdates)\n\t}\n\n\tpublic connectEntity(entityToConnect: EntityAccessor): void {\n\t\tthis.operations.connectEntity(this.stateKey, entityToConnect)\n\t}\n\n\tpublic createNewEntity(initialize?: EntityAccessor.BatchUpdatesHandler): RuntimeId {\n\t\treturn this.operations.createNewEntity(this.stateKey, initialize)\n\t}\n\tpublic disconnectEntity(childEntity: EntityAccessor, options: { noPersist?: boolean } = {}): void {\n\t\tthis.operations.disconnectEntity(this.stateKey, childEntity, options)\n\t}\n\tpublic getChildEntityById(id: EntityId): EntityAccessor {\n\t\treturn this.operations.getChildEntityById(this.stateKey, id)\n\t}\n}\n\nnamespace EntityListAccessor {\n\texport type GetEntityListAccessor = () => EntityListAccessor\n\texport type BatchUpdatesHandler = (getAccessor: GetEntityListAccessor, options: BatchUpdatesOptions) => void\n\n\texport type UpdateListener = (accessor: EntityListAccessor) => void\n\n\texport type BeforePersistHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: AsyncBatchUpdatesOptions,\n\t) => void | Promise<void | BeforePersistHandler>\n\n\texport type PersistErrorHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: PersistErrorOptions,\n\t) => void | Promise<void>\n\n\texport type PersistSuccessHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: PersistSuccessOptions,\n\t) => void | Promise<void | PersistSuccessHandler>\n\n\texport type ChildEventListenerMap = {\n\t\t[EventType in keyof Pick<EntityAccessor.EntityEventListenerMap, 'beforeUpdate' | 'initialize' | 'update'> &\n\t\t\tstring as `child${Capitalize<EventType>}`]: EntityAccessor.EntityEventListenerMap[EventType]\n\t}\n\n\texport interface RuntimeEntityListEventListenerMap {\n\t\tbeforePersist: BeforePersistHandler\n\t\tbeforeUpdate: BatchUpdatesHandler\n\t\tpersistError: PersistErrorHandler\n\t\tpersistSuccess: PersistSuccessHandler\n\t\tupdate: UpdateListener\n\t}\n\texport interface EntityListEventListenerMap extends RuntimeEntityListEventListenerMap {\n\t\tinitialize: BatchUpdatesHandler\n\t}\n\texport type EntityListEventType = keyof EntityListEventListenerMap\n}\n\nexport { EntityListAccessor }\n"],"names":[],"mappings":";AAaA,MAAM,mBAAwC;AAAA,EACtC,YACW,UACA,YACA,WACA,uBACD,uBACA,QACA,aACA,aACf;AARgB,SAAA,WAAA;AACA,SAAA,aAAA;AACA,SAAA,YAAA;AACA,SAAA,wBAAA;AACD,SAAA,wBAAA;AACA,SAAA,SAAA;AACA,SAAA,cAAA;AACA,SAAA,cAAA;AAAA,EACd;AAAA,GAOK,OAAyC;AAChD,eAAW,YAAY,MAAM;AAC5B,YAAM,SAAS;AAAA,IAChB;AAAA,EACD;AAAA,GAEQ,MAAkC;AAClC,WAAA,KAAK,UAAU;EACvB;AAAA,MAMW,uBAAoC;AACvC,WAAA,IAAI,IAAI,KAAK,qBAAqB;AAAA,EAC1C;AAAA,IAES,OAAO,YAA8C;AAC7D,eAAW,EAAE,iBAAiB,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,MAEW,SAAiB;AAC3B,WAAO,KAAK,UAAU;AAAA,EACvB;AAAA,EAEO,kBAAkB,eAAmD;AACvE,QAAA,OAAO,kBAAkB,UAAU;AAC/B,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,UAAU,cAAc,eAAe,KAAK,CAAC;AAAA,EACnF;AAAA,EAEO,iBACN,OACA,UACC;AACD,WAAO,KAAK,WAAW,iBAAiB,KAAK,UAAU,OAAO,QAAQ;AAAA,EACvE;AAAA,EAEO,sBACN,OACA,OACA,UACC;AACD,WAAO,KAAK,WAAW,sBAAsB,KAAK,UAAU,OAAO,QAAQ;AAAA,EAC5E;AAAA,EAEO,aAAa,gBAA8D;AACjF,SAAK,WAAW,aAAa,KAAK,UAAU,cAAc;AAAA,EAC3D;AAAA,EAEO,cAAc,iBAAuC;AAC3D,SAAK,WAAW,cAAc,KAAK,UAAU,eAAe;AAAA,EAC7D;AAAA,EAEO,gBAAgB,YAA4D;AAClF,WAAO,KAAK,WAAW,gBAAgB,KAAK,UAAU,UAAU;AAAA,EACjE;AAAA,EACO,iBAAiB,aAA6B,UAAmC,IAAU;AACjG,SAAK,WAAW,iBAAiB,KAAK,UAAU,aAAa,OAAO;AAAA,EACrE;AAAA,EACO,mBAAmB,IAA8B;AACvD,WAAO,KAAK,WAAW,mBAAmB,KAAK,UAAU,EAAE;AAAA,EAC5D;AACD;;"}
1
+ {"version":3,"file":"EntityListAccessor.js","sources":["../../../src/accessors/EntityListAccessor.ts"],"sourcesContent":["import type { ListOperations } from '../core/operations'\nimport type { Environment } from '../dao'\nimport type { EntityId, EntityRealmKey } from '../treeParameters'\nimport type { AsyncBatchUpdatesOptions } from './AsyncBatchUpdatesOptions'\nimport type { BatchUpdatesOptions } from './BatchUpdatesOptions'\nimport type { EntityAccessor } from './EntityAccessor'\nimport type { Errorable } from './Errorable'\nimport { ErrorAccessor } from './ErrorAccessor'\nimport type { PersistErrorOptions } from './PersistErrorOptions'\nimport type { PersistSuccessOptions } from './PersistSuccessOptions'\nimport type { EntityListState } from '../core/state'\nimport { RuntimeId } from '../accessorTree'\n\nclass EntityListAccessor implements Errorable {\n\tpublic constructor(\n\t\tprivate readonly stateKey: 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.stateKey, ErrorAccessor.normalizeError(error))\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityListAccessor.RuntimeEntityListEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityListAccessor.RuntimeEntityListEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic addChildEventListener<Type extends keyof EntityAccessor.EntityEventListenerMap>(\n\t\tstate: EntityListState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addChildEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic batchUpdates(performUpdates: EntityListAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.batchUpdates(this.stateKey, performUpdates)\n\t}\n\n\tpublic connectEntity(entityToConnect: EntityAccessor): void {\n\t\tthis.operations.connectEntity(this.stateKey, entityToConnect)\n\t}\n\n\tpublic createNewEntity(initialize?: EntityAccessor.BatchUpdatesHandler): RuntimeId {\n\t\treturn this.operations.createNewEntity(this.stateKey, initialize)\n\t}\n\tpublic disconnectEntity(childEntity: EntityAccessor, options: { noPersist?: boolean } = {}): void {\n\t\tthis.operations.disconnectEntity(this.stateKey, childEntity, options)\n\t}\n\tpublic getChildEntityById(id: EntityId): EntityAccessor {\n\t\treturn this.operations.getChildEntityById(this.stateKey, id)\n\t}\n}\n\nnamespace EntityListAccessor {\n\texport type GetEntityListAccessor = () => EntityListAccessor\n\texport type BatchUpdatesHandler = (getAccessor: GetEntityListAccessor, options: BatchUpdatesOptions) => void\n\n\texport type UpdateListener = (accessor: EntityListAccessor) => void\n\n\texport type BeforePersistHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: AsyncBatchUpdatesOptions,\n\t) => void | Promise<void | BeforePersistHandler>\n\n\texport type PersistErrorHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: PersistErrorOptions,\n\t) => void | Promise<void>\n\n\texport type PersistSuccessHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: PersistSuccessOptions,\n\t) => void | Promise<void | PersistSuccessHandler>\n\n\texport type ChildEventListenerMap = {\n\t\t[EventType in keyof Pick<EntityAccessor.EntityEventListenerMap, 'beforeUpdate' | 'initialize' | 'update'> &\n\t\t\tstring as `child${Capitalize<EventType>}`]: EntityAccessor.EntityEventListenerMap[EventType]\n\t}\n\n\texport interface RuntimeEntityListEventListenerMap {\n\t\tbeforePersist: BeforePersistHandler\n\t\tbeforeUpdate: BatchUpdatesHandler\n\t\tpersistError: PersistErrorHandler\n\t\tpersistSuccess: PersistSuccessHandler\n\t\tupdate: UpdateListener\n\t}\n\texport interface EntityListEventListenerMap extends RuntimeEntityListEventListenerMap {\n\t\tinitialize: BatchUpdatesHandler\n\t}\n\texport type EntityListEventType = keyof EntityListEventListenerMap\n}\n\nexport { EntityListAccessor }\n"],"names":[],"mappings":";AAaA,MAAM,mBAAwC;AAAA,EACtC,YACW,UACA,YACA,WACA,uBACD,uBACA,QACA,aACA,aACf;AARgB,SAAA,WAAA;AACA,SAAA,aAAA;AACA,SAAA,YAAA;AACA,SAAA,wBAAA;A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AK,CAAC;AAAA,EACnF;AAAA,EAEO,iBACN,OACA,UACC;AACD,WAAO,KAAK,WAAW,iBAAiB,KAAK,UAAU,OAAO,QAAQ;AAAA,EACvE;AAAA,EAEO,sBACN,OACA,OACA,UACC;AACD,WAAO,KAAK,WAAW,sBAAsB,KAAK,UAAU,OAAO,QAAQ;AAAA,EAC5E;AAAA,EAEO,aAAa,gBAA8D;AACjF,SAAK,WAAW,aAAa,KAAK,UAAU,cAAc;AAAA,EAC3D;AAAA,EAEO,cAAc,iBAAuC;AAC3D,SAAK,WAAW,cAAc,KAAK,UAAU,eAAe;AAAA,EAC7D;AAAA,EAEO,gBAAgB,YAA4D;AAClF,WAAO,KAAK,WAAW,gBAAgB,KAAK,UAAU,UAAU;AAAA,EACjE;AAAA,EACO,iBAAiB,aAA6B,UAAmC,IAAU;AACjG,SAAK,WAAW,iBAAiB,KAAK,UAAU,aAAa,OAAO;AAAA,EACrE;AAAA,EACO,mBAAmB,IAA8B;AACvD,WAAO,KAAK,WAAW,mBAAmB,KAAK,UAAU,EAAE;AAAA,EAC5D;AACD;;"}
@@ -116,6 +116,9 @@ class AccessorErrorManager {
116
116
  return;
117
117
  }
118
118
  for (const [childKey, child] of errors.children) {
119
+ if (typeof childKey !== "string") {
120
+ continue;
121
+ }
119
122
  if (child.nodeType === "leaf") {
120
123
  const fieldState = state.children.get(childKey);
121
124
  if (fieldState?.type === "field") {
@@ -1 +1 @@
1
- {"version":3,"file":"AccessorErrorManager.js","sources":["../../../src/core/AccessorErrorManager.ts"],"sourcesContent":["import { ErrorAccessor } from '../accessors'\nimport type { ExecutionError, MutationDataResponse, ValidationError } from '../accessorTree'\nimport { ErrorsPreprocessor } from './ErrorsPreprocessor'\nimport { EventManager } from './EventManager'\nimport { EntityListState, EntityRealmState, getEntityMarker, StateNode } from './state'\nimport type { TreeStore } from './TreeStore'\n\nexport class AccessorErrorManager {\n\tprivate errorsByState: Map<StateNode, ErrorAccessor.ErrorsById> = new Map()\n\n\tprivate getNewErrorId = (() => {\n\t\tlet errorId = 1\n\n\t\treturn () => errorId++\n\t})()\n\n\tpublic constructor(private readonly eventManager: EventManager, private readonly treeStore: TreeStore) {}\n\n\tpublic hasErrors() {\n\t\treturn !!this.errorsByState.size\n\t}\n\n\tpublic getErrors(): ErrorAccessor.Error[] {\n\t\treturn Array.from(this.errorsByState.values(), it => Array.from(it.values())).flat()\n\t}\n\n\tpublic clearErrors() {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tfor (const [stateNode] of this.errorsByState) {\n\t\t\t\tstateNode.errors = undefined\n\t\t\t\tthis.eventManager.registerJustUpdated(stateNode, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t}\n\t\t\tthis.errorsByState.clear()\n\t\t})\n\t}\n\n\tpublic clearErrorsByState(state: StateNode): void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tif (!this.errorsByState.has(state)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.errorsByState.delete(state)\n\t\t\tstate.errors = undefined\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t})\n\t}\n\n\tpublic replaceErrors(data: MutationDataResponse) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.clearErrors()\n\n\t\t\tconst preprocessor = new ErrorsPreprocessor(data)\n\t\t\tconst errorTreeRoot = preprocessor.preprocess()\n\n\t\t\tthis.setRootStateErrors(errorTreeRoot)\n\n\t\t\tthis.dumpErrorData(data)\n\t\t})\n\t}\n\n\tpublic addError(state: StateNode, error: ErrorAccessor.Error): () => void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tconst errorId = this.getNewErrorId()\n\n\t\t\tlet errorsById: ErrorAccessor.ErrorsById | undefined = this.errorsByState.get(state)\n\t\t\tif (errorsById === undefined) {\n\t\t\t\tthis.errorsByState.set(state, (errorsById = new Map()))\n\t\t\t}\n\t\t\terrorsById.set(errorId, error)\n\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\n\t\t\treturn () =>\n\t\t\t\tthis.eventManager.syncOperation(() => {\n\t\t\t\t\tconst errorsById = this.errorsByState.get(state)\n\t\t\t\t\tif (errorsById === undefined) {\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\terrorsById.delete(errorId)\n\t\t\t\t\tif (errorsById.size) {\n\t\t\t\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstate.errors = undefined\n\t\t\t\t\t\tthis.errorsByState.delete(state)\n\t\t\t\t\t}\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t})\n\t\t})\n\t}\n\n\tprivate addSeveralErrors(state: StateNode, errors: ErrorsPreprocessor.BaseErrorNode) {\n\t\tif (errors.validation) {\n\t\t\tfor (const error of errors.validation) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t\tif (errors.execution) {\n\t\t\tfor (const error of errors.execution) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setRootStateErrors(errorTreeRoot: ErrorsPreprocessor.ErrorTreeRoot) {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [subTreePlaceholder, rootError] of errorTreeRoot) {\n\t\t\t\tconst rootState = rootStates.get(subTreePlaceholder)\n\n\t\t\t\tif (!rootState) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (rootState.type) {\n\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\tthis.setEntityStateErrors(rootState, rootError)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'entityList': {\n\t\t\t\t\t\tthis.setEntityListStateErrors(rootState, rootError)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityStateErrors(\n\t\tstate: EntityRealmState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, child] of errors.children) {\n\t\t\tif (child.nodeType === 'leaf') {\n\t\t\t\tconst fieldState = state.children.get(childKey)\n\n\t\t\t\tif (fieldState?.type === 'field') {\n\t\t\t\t\tthis.addSeveralErrors(fieldState, child)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Deliberately letting flow get here as well. Leaf errors *CAN* refer to relations as well.\n\n\t\t\tconst fields = getEntityMarker(state).fields\n\t\t\tconst placeholders = fields.placeholders.get(childKey)\n\t\t\tif (placeholders === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst normalizedPlaceholders = typeof placeholders === 'string' ? new Set([placeholders]) : placeholders\n\n\t\t\tfor (const normalizedPlaceholder of normalizedPlaceholders) {\n\t\t\t\tconst fieldState = state.children.get(normalizedPlaceholder)\n\t\t\t\tif (fieldState === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (fieldState.type) {\n\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\t\tthis.setEntityStateErrors(fieldState, child)\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\tthis.setEntityListStateErrors(fieldState, child)\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityListStateErrors(\n\t\tstate: EntityListState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, childError] of errors.children) {\n\t\t\tlet childState = state.children.get(childKey)\n\n\t\t\tif (childState === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (childState.type === 'entityRealmStub') {\n\t\t\t\tchildState.getAccessor() // Force init\n\t\t\t\tchildState = state.children.get(childKey)!\n\t\t\t}\n\n\t\t\tif (childError.nodeType === 'iNode') {\n\t\t\t\tthis.setEntityStateErrors(childState as EntityRealmState, childError)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate dumpErrorData(data: MutationDataResponse) {\n\t\t// TODO this is just temporary\n\t\tfor (const subTreePlaceholder in data) {\n\t\t\tconst treeDatum = data[subTreePlaceholder]\n\t\t\tconst executionErrors: Array<ExecutionError | ValidationError> = treeDatum.errors\n\t\t\tconst allErrors = treeDatum?.validation?.errors\n\t\t\t\t? executionErrors.concat(treeDatum.validation.errors)\n\t\t\t\t: executionErrors\n\t\t\tconst normalizedErrors = allErrors.map((error: ExecutionError | ValidationError) => {\n\t\t\t\treturn {\n\t\t\t\t\tpath: error.path\n\t\t\t\t\t\t.map(pathPart => {\n\t\t\t\t\t\t\tif (pathPart.__typename === '_FieldPathFragment') {\n\t\t\t\t\t\t\t\treturn pathPart.field\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (pathPart.alias) {\n\t\t\t\t\t\t\t\treturn `#${pathPart.index}(${pathPart.alias})`\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn pathPart.index\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.join('.'),\n\t\t\t\t\ttype: 'type' in error ? error.type : undefined,\n\t\t\t\t\tmessage: typeof error.message === 'string' ? error.message : error.message?.text,\n\t\t\t\t}\n\t\t\t})\n\t\t\tif (Object.keys(normalizedErrors).length) {\n\t\t\t\tconsole.table(normalizedErrors)\n\t\t\t}\n\t\t\tif (treeDatum.errorMessage) {\n\t\t\t\tconsole.error(treeDatum.errorMessage)\n\t\t\t}\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C;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'\n\nexport class AccessorErrorManager {\n\tprivate errorsByState: Map<StateNode, ErrorAccessor.ErrorsById> = new Map()\n\n\tprivate getNewErrorId = (() => {\n\t\tlet errorId = 1\n\n\t\treturn () => errorId++\n\t})()\n\n\tpublic constructor(private readonly eventManager: EventManager, private readonly treeStore: TreeStore) {}\n\n\tpublic hasErrors() {\n\t\treturn !!this.errorsByState.size\n\t}\n\n\tpublic getErrors(): ErrorAccessor.Error[] {\n\t\treturn Array.from(this.errorsByState.values(), it => Array.from(it.values())).flat()\n\t}\n\n\tpublic clearErrors() {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tfor (const [stateNode] of this.errorsByState) {\n\t\t\t\tstateNode.errors = undefined\n\t\t\t\tthis.eventManager.registerJustUpdated(stateNode, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t}\n\t\t\tthis.errorsByState.clear()\n\t\t})\n\t}\n\n\tpublic clearErrorsByState(state: StateNode): void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tif (!this.errorsByState.has(state)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.errorsByState.delete(state)\n\t\t\tstate.errors = undefined\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t})\n\t}\n\n\tpublic replaceErrors(data: MutationDataResponse) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.clearErrors()\n\n\t\t\tconst preprocessor = new ErrorsPreprocessor(data)\n\t\t\tconst errorTreeRoot = preprocessor.preprocess()\n\n\t\t\tthis.setRootStateErrors(errorTreeRoot)\n\n\t\t\tthis.dumpErrorData(data)\n\t\t})\n\t}\n\n\tpublic addError(state: StateNode, error: ErrorAccessor.Error): () => void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tconst errorId = this.getNewErrorId()\n\n\t\t\tlet errorsById: ErrorAccessor.ErrorsById | undefined = this.errorsByState.get(state)\n\t\t\tif (errorsById === undefined) {\n\t\t\t\tthis.errorsByState.set(state, (errorsById = new Map()))\n\t\t\t}\n\t\t\terrorsById.set(errorId, error)\n\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\n\t\t\treturn () =>\n\t\t\t\tthis.eventManager.syncOperation(() => {\n\t\t\t\t\tconst errorsById = this.errorsByState.get(state)\n\t\t\t\t\tif (errorsById === undefined) {\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\terrorsById.delete(errorId)\n\t\t\t\t\tif (errorsById.size) {\n\t\t\t\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstate.errors = undefined\n\t\t\t\t\t\tthis.errorsByState.delete(state)\n\t\t\t\t\t}\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t})\n\t\t})\n\t}\n\n\tprivate addSeveralErrors(state: StateNode, errors: ErrorsPreprocessor.BaseErrorNode) {\n\t\tif (errors.validation) {\n\t\t\tfor (const error of errors.validation) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t\tif (errors.execution) {\n\t\t\tfor (const error of errors.execution) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setRootStateErrors(errorTreeRoot: ErrorsPreprocessor.ErrorTreeRoot) {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [subTreePlaceholder, rootError] of errorTreeRoot) {\n\t\t\t\tconst rootState = rootStates.get(subTreePlaceholder)\n\n\t\t\t\tif (!rootState) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (rootState.type) {\n\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\tthis.setEntityStateErrors(rootState, rootError)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'entityList': {\n\t\t\t\t\t\tthis.setEntityListStateErrors(rootState, rootError)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityStateErrors(\n\t\tstate: EntityRealmState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, child] of errors.children) {\n\t\t\tif (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\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7B;AAAA,MACD;AACI,UAAA,WAAW,SAAS,mBAAmB;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;;"}
@@ -18,7 +18,6 @@ import { TreeFilterGenerator } from "./TreeFilterGenerator.js";
18
18
  import { TreeStore } from "./TreeStore.js";
19
19
  import { createBatchUpdatesOptions } from "./factories/createBatchUpdatesOptions.js";
20
20
  import { TreeRootAccessor } from "../accessors/TreeRootAccessor.js";
21
- import { SchemaValidator } from "./schema/SchemaValidator.js";
22
21
  import { getCombinedSignal } from "./utils/getCombinedSignal.js";
23
22
  import { metadataToRequestError } from "../accessorTree/metadataToRequestError.js";
24
23
  import { SchemaLoader } from "./schema/SchemaLoader.js";
@@ -60,7 +59,7 @@ const _DataBinding = class {
60
59
  this.dirtinessTracker = new DirtinessTracker();
61
60
  this.eventManager = new EventManager(this.asyncBatchUpdatesOptions, this.batchUpdatesOptions, this.config, this.dirtinessTracker, this.resolvedOnUpdate, this.treeStore);
62
61
  this.accessorErrorManager = new AccessorErrorManager(this.eventManager, this.treeStore);
63
- this.stateInitializer = new StateInitializer(this.accessorErrorManager, this.batchUpdatesOptions, this.config, this.eventManager, this.treeStore);
62
+ this.stateInitializer = new StateInitializer(this.accessorErrorManager, this.batchUpdatesOptions, this.eventManager, this.treeStore);
64
63
  this.treeAugmenter = new TreeAugmenter(this.eventManager, this.stateInitializer, this.treeStore);
65
64
  this.bindingOperations = Object.freeze({
66
65
  ...this.asyncBatchUpdatesOptions,
@@ -125,14 +124,15 @@ const _DataBinding = class {
125
124
  errors: mutationResponse.errors
126
125
  });
127
126
  }
128
- const mutationData = mutationResponse.data?.transaction ?? {};
129
- const aliases = Object.keys(mutationData);
130
- if (!mutationResponse.data) {
127
+ if (!mutationResponse.data?.transaction) {
131
128
  throw {
132
- errors: mutationData.errors,
129
+ errors: [],
133
130
  type: "invalidResponse"
134
131
  };
135
- } else if (aliases.every((item) => mutationData[item].ok)) {
132
+ }
133
+ const { __typename, ...mutationData } = mutationResponse.data.transaction;
134
+ const aliases = Object.keys(mutationData);
135
+ if (aliases.every((item) => mutationData[item].ok)) {
136
136
  const persistedEntityIds = aliases.map((alias) => mutationData[alias].node?.id).filter((id) => id !== void 0);
137
137
  const result = {
138
138
  type: "justSuccess",
@@ -191,13 +191,10 @@ const _DataBinding = class {
191
191
  if (options.signal?.aborted) {
192
192
  return Promise.reject(DataBindingExtendAborted);
193
193
  }
194
- const markerTreeRoot = new MarkerTreeGenerator(newFragment, options.environment ?? this.environment).generate();
194
+ const schema = await this.getOrLoadSchema();
195
+ this.treeStore.setSchema(schema);
196
+ const markerTreeRoot = new MarkerTreeGenerator(newFragment, (options.environment ?? this.environment).withSchema(schema)).generate();
195
197
  if (this.treeStore.effectivelyHasTreeRoot(markerTreeRoot)) {
196
- const schema = await this.getOrLoadSchema();
197
- this.treeStore.setSchema(schema);
198
- {
199
- SchemaValidator.assertTreeValid(schema, markerTreeRoot);
200
- }
201
198
  return this.eventManager.syncOperation(() => {
202
199
  const newTreeRootId = this.getNewTreeRootId();
203
200
  this.treeAugmenter.extendTreeStates(newTreeRootId, markerTreeRoot);
@@ -241,16 +238,7 @@ const _DataBinding = class {
241
238
  return;
242
239
  }
243
240
  const aggregateSignal = getCombinedSignal(pendingExtensions.map((extension) => extension.options.signal));
244
- const [aggregatePersistedData, schema] = await Promise.all([
245
- this.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal),
246
- this.getOrLoadSchema()
247
- ]);
248
- this.treeStore.setSchema(schema);
249
- {
250
- for (const extension of pendingExtensions) {
251
- SchemaValidator.assertTreeValid(schema, extension.markerTreeRoot);
252
- }
253
- }
241
+ const aggregatePersistedData = await this.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal);
254
242
  if (aggregateSignal?.aborted) {
255
243
  return;
256
244
  }